var Rr=Object.defineProperty;var Tr=(e,t,n)=>t in e?Rr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var j=(e,t,n)=>Tr(e,typeof t!="symbol"?t+"":t,n);import{j as u,u as He,H as $e,P as de,N as Lr,d as Qt,R as Dr,i as Mr,B as Pr,C as Fr,e as oe}from"./reactflow-vendor-BDofclgK.js";import{r as p,c as Ar,g as $r}from"./react-vendor-4ldeB94U.js";import{e as Gr,h as O,b as V,d as U,i as I,j as Jt,k as vt,l as re,P as W,m as Zt,n as z,o as be,S as Vr,D as Wr,p as Br,q as zr,r as en,X as Hr,f as Ge,t as ne,c as tn,v as Ur,w as Yr,x as bt}from"./index-BXctaVea.js";import{c as Y,a as R,F as T,B as pe,I as Xr,S as nn}from"./Stack-DW41pKK2.js";/**
 * @license lucide-react v0.446.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const qr=Gr("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Kr=Y("outline","arrow-back-up","IconArrowBackUp",[["path",{d:"M9 14l-4 -4l4 -4",key:"svg-0"}],["path",{d:"M5 10h11a4 4 0 1 1 0 8h-1",key:"svg-1"}]]);/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Qr=Y("outline","arrow-forward-up","IconArrowForwardUp",[["path",{d:"M15 14l4 -4l-4 -4",key:"svg-0"}],["path",{d:"M19 10h-11a4 4 0 1 0 0 8h1",key:"svg-1"}]]);/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Jr=Y("outline","arrows-diagonal-2","IconArrowsDiagonal2",[["path",{d:"M16 20l4 0l0 -4",key:"svg-0"}],["path",{d:"M14 14l6 6",key:"svg-1"}],["path",{d:"M8 4l-4 0l0 4",key:"svg-2"}],["path",{d:"M4 4l6 6",key:"svg-3"}]]);/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var wt=Y("outline","arrows-split-2","IconArrowsSplit2",[["path",{d:"M21 17h-5.397a5 5 0 0 1 -4.096 -2.133l-.514 -.734a5 5 0 0 0 -4.096 -2.133h-3.897",key:"svg-0"}],["path",{d:"M21 7h-5.395a5 5 0 0 0 -4.098 2.135l-.51 .73a5 5 0 0 1 -4.097 2.135h-3.9",key:"svg-1"}],["path",{d:"M18 10l3 -3l-3 -3",key:"svg-2"}],["path",{d:"M18 20l3 -3l-3 -3",key:"svg-3"}]]);/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Zr=Y("outline","circle-check","IconCircleCheck",[["path",{d:"M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0",key:"svg-0"}],["path",{d:"M9 12l2 2l4 -4",key:"svg-1"}]]);/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var eo=Y("outline","x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var to=Y("outline","xbox-x","IconXboxX",[["path",{d:"M12 21a9 9 0 0 0 9 -9a9 9 0 0 0 -9 -9a9 9 0 0 0 -9 9a9 9 0 0 0 9 9z",key:"svg-0"}],["path",{d:"M9 8l6 8",key:"svg-1"}],["path",{d:"M15 8l-6 8",key:"svg-2"}]]);const rn=p.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:O("flex min-h-[20px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));rn.displayName="Textarea";const Ue=p.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:O("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));Ue.displayName="Input";function no({input:e,nodeID:t}){const{updateValues:n,values:r}=V(U(o=>({values:o.values,updateValues:o.updateValues})));return u.jsx(Ue,{type:"number",value:r[I("input",t,e.id)]??"",onChange:o=>{n({[I("input",t,e.id)]:o.target.value===""?void 0:Number(o.target.value)})},className:"w-full border-zinc-700 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"})}var ro=Ar.useId||(()=>{}),oo=0;function Ce(e){const[t,n]=p.useState(ro());return Jt(()=>{e||n(r=>r??String(oo++))},[e]),e||(t?`radix-${t}`:"")}var _e="focusScope.autoFocusOnMount",je="focusScope.autoFocusOnUnmount",yt={bubbles:!1,cancelable:!0},ao="FocusScope",on=p.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:a,...i}=e,[s,l]=p.useState(null),c=vt(o),d=vt(a),f=p.useRef(null),h=re(t,m=>l(m)),g=p.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;p.useEffect(()=>{if(r){let m=function(N){if(g.paused||!s)return;const x=N.target;s.contains(x)?f.current=x:$(f.current,{select:!0})},b=function(N){if(g.paused||!s)return;const x=N.relatedTarget;x!==null&&(s.contains(x)||$(f.current,{select:!0}))},y=function(N){if(document.activeElement===document.body)for(const E of N)E.removedNodes.length>0&&$(s)};document.addEventListener("focusin",m),document.addEventListener("focusout",b);const k=new MutationObserver(y);return s&&k.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",b),k.disconnect()}}},[r,s,g.paused]),p.useEffect(()=>{if(s){Et.add(g);const m=document.activeElement;if(!s.contains(m)){const y=new CustomEvent(_e,yt);s.addEventListener(_e,c),s.dispatchEvent(y),y.defaultPrevented||(io(fo(an(s)),{select:!0}),document.activeElement===m&&$(s))}return()=>{s.removeEventListener(_e,c),setTimeout(()=>{const y=new CustomEvent(je,yt);s.addEventListener(je,d),s.dispatchEvent(y),y.defaultPrevented||$(m??document.body,{select:!0}),s.removeEventListener(je,d),Et.remove(g)},0)}}},[s,c,d,g]);const v=p.useCallback(m=>{if(!n&&!r||g.paused)return;const b=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,y=document.activeElement;if(b&&y){const k=m.currentTarget,[N,x]=so(k);N&&x?!m.shiftKey&&y===x?(m.preventDefault(),n&&$(N,{select:!0})):m.shiftKey&&y===N&&(m.preventDefault(),n&&$(x,{select:!0})):y===k&&m.preventDefault()}},[n,r,g.paused]);return u.jsx(W.div,{tabIndex:-1,...i,ref:h,onKeyDown:v})});on.displayName=ao;function io(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if($(r,{select:t}),document.activeElement!==n)return}function so(e){const t=an(e),n=xt(t,e),r=xt(t.reverse(),e);return[n,r]}function an(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function xt(e,t){for(const n of e)if(!lo(n,{upTo:t}))return n}function lo(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function co(e){return e instanceof HTMLInputElement&&"select"in e}function $(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&co(e)&&t&&e.select()}}var Et=uo();function uo(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Nt(e,t),e.unshift(t)},remove(t){var n;e=Nt(e,t),(n=e[0])==null||n.resume()}}}function Nt(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function fo(e){return e.filter(t=>t.tagName!=="A")}var Se=0;function ho(){p.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??kt()),document.body.insertAdjacentElement("beforeend",e[1]??kt()),Se++,()=>{Se===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Se--}},[])}function kt(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var F=function(){return F=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},F.apply(this,arguments)};function sn(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function po(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,a;r<o;r++)(a||!(r in t))&&(a||(a=Array.prototype.slice.call(t,0,r)),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var ue="right-scroll-bar-position",fe="width-before-scroll-bar",mo="with-scroll-bars-hidden",go="--removed-body-scroll-bar-size";function Oe(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function vo(e,t){var n=p.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var bo=typeof window<"u"?p.useLayoutEffect:p.useEffect,Ct=new WeakMap;function wo(e,t){var n=vo(null,function(r){return e.forEach(function(o){return Oe(o,r)})});return bo(function(){var r=Ct.get(n);if(r){var o=new Set(r),a=new Set(e),i=n.current;o.forEach(function(s){a.has(s)||Oe(s,null)}),a.forEach(function(s){o.has(s)||Oe(s,i)})}Ct.set(n,e)},[e]),n}function yo(e){return e}function xo(e,t){t===void 0&&(t=yo);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(a){var i=t(a,r);return n.push(i),function(){n=n.filter(function(s){return s!==i})}},assignSyncMedium:function(a){for(r=!0;n.length;){var i=n;n=[],i.forEach(a)}n={push:function(s){return a(s)},filter:function(){return n}}},assignMedium:function(a){r=!0;var i=[];if(n.length){var s=n;n=[],s.forEach(a),i=n}var l=function(){var d=i;i=[],d.forEach(a)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function Eo(e){e===void 0&&(e={});var t=xo(null);return t.options=F({async:!0,ssr:!1},e),t}var ln=function(e){var t=e.sideCar,n=sn(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return p.createElement(r,F({},n))};ln.isSideCarExport=!0;function No(e,t){return e.useMedium(t),ln}var cn=Eo(),Ie=function(){},we=p.forwardRef(function(e,t){var n=p.useRef(null),r=p.useState({onScrollCapture:Ie,onWheelCapture:Ie,onTouchMoveCapture:Ie}),o=r[0],a=r[1],i=e.forwardProps,s=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,g=e.noIsolation,v=e.inert,m=e.allowPinchZoom,b=e.as,y=b===void 0?"div":b,k=e.gapMode,N=sn(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),x=h,E=wo([n,t]),L=F(F({},N),o);return p.createElement(p.Fragment,null,d&&p.createElement(x,{sideCar:cn,removeScrollBar:c,shards:f,noIsolation:g,inert:v,setCallbacks:a,allowPinchZoom:!!m,lockRef:n,gapMode:k}),i?p.cloneElement(p.Children.only(s),F(F({},L),{ref:E})):p.createElement(y,F({},L,{className:l,ref:E}),s))});we.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};we.classNames={fullWidth:fe,zeroRight:ue};var ko=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Co(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=ko();return t&&e.setAttribute("nonce",t),e}function _o(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function jo(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var So=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Co())&&(_o(t,n),jo(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Oo=function(){var e=So();return function(t,n){p.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},dn=function(){var e=Oo(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Io={left:0,top:0,right:0,gap:0},Re=function(e){return parseInt(e||"",10)||0},Ro=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Re(n),Re(r),Re(o)]},To=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Io;var t=Ro(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Lo=dn(),J="data-scroll-locked",Do=function(e,t,n,r){var o=e.left,a=e.top,i=e.right,s=e.gap;return n===void 0&&(n="margin"),`
  .`.concat(mo,` {
   overflow: hidden `).concat(r,`;
   padding-right: `).concat(s,"px ").concat(r,`;
  }
  body[`).concat(J,`] {
    overflow: hidden `).concat(r,`;
    overscroll-behavior: contain;
    `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
    padding-left: `.concat(o,`px;
    padding-top: `).concat(a,`px;
    padding-right: `).concat(i,`px;
    margin-left:0;
    margin-top:0;
    margin-right: `).concat(s,"px ").concat(r,`;
    `),n==="padding"&&"padding-right: ".concat(s,"px ").concat(r,";")].filter(Boolean).join(""),`
  }
  
  .`).concat(ue,` {
    right: `).concat(s,"px ").concat(r,`;
  }
  
  .`).concat(fe,` {
    margin-right: `).concat(s,"px ").concat(r,`;
  }
  
  .`).concat(ue," .").concat(ue,` {
    right: 0 `).concat(r,`;
  }
  
  .`).concat(fe," .").concat(fe,` {
    margin-right: 0 `).concat(r,`;
  }
  
  body[`).concat(J,`] {
    `).concat(go,": ").concat(s,`px;
  }
`)},_t=function(){var e=parseInt(document.body.getAttribute(J)||"0",10);return isFinite(e)?e:0},Mo=function(){p.useEffect(function(){return document.body.setAttribute(J,(_t()+1).toString()),function(){var e=_t()-1;e<=0?document.body.removeAttribute(J):document.body.setAttribute(J,e.toString())}},[])},Po=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Mo();var a=p.useMemo(function(){return To(o)},[o]);return p.createElement(Lo,{styles:Do(a,!t,o,n?"":"!important")})},Ve=!1;if(typeof window<"u")try{var ae=Object.defineProperty({},"passive",{get:function(){return Ve=!0,!0}});window.addEventListener("test",ae,ae),window.removeEventListener("test",ae,ae)}catch{Ve=!1}var q=Ve?{passive:!1}:!1,Fo=function(e){return e.tagName==="TEXTAREA"},un=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Fo(e)&&n[t]==="visible")},Ao=function(e){return un(e,"overflowY")},$o=function(e){return un(e,"overflowX")},jt=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=fn(e,r);if(o){var a=hn(e,r),i=a[1],s=a[2];if(i>s)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Go=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Vo=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},fn=function(e,t){return e==="v"?Ao(t):$o(t)},hn=function(e,t){return e==="v"?Go(t):Vo(t)},Wo=function(e,t){return e==="h"&&t==="rtl"?-1:1},Bo=function(e,t,n,r,o){var a=Wo(e,window.getComputedStyle(t).direction),i=a*r,s=n.target,l=t.contains(s),c=!1,d=i>0,f=0,h=0;do{var g=hn(e,s),v=g[0],m=g[1],b=g[2],y=m-b-a*v;(v||y)&&fn(e,s)&&(f+=y,h+=v),s instanceof ShadowRoot?s=s.host:s=s.parentNode}while(!l&&s!==document.body||l&&(t.contains(s)||t===s));return(d&&(Math.abs(f)<1||!o)||!d&&(Math.abs(h)<1||!o))&&(c=!0),c},ie=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},St=function(e){return[e.deltaX,e.deltaY]},Ot=function(e){return e&&"current"in e?e.current:e},zo=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Ho=function(e){return`
  .block-interactivity-`.concat(e,` {pointer-events: none;}
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
`)},Uo=0,K=[];function Yo(e){var t=p.useRef([]),n=p.useRef([0,0]),r=p.useRef(),o=p.useState(Uo++)[0],a=p.useState(dn)[0],i=p.useRef(e);p.useEffect(function(){i.current=e},[e]),p.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=po([e.lockRef.current],(e.shards||[]).map(Ot),!0).filter(Boolean);return m.forEach(function(b){return b.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var s=p.useCallback(function(m,b){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var y=ie(m),k=n.current,N="deltaX"in m?m.deltaX:k[0]-y[0],x="deltaY"in m?m.deltaY:k[1]-y[1],E,L=m.target,C=Math.abs(N)>Math.abs(x)?"h":"v";if("touches"in m&&C==="h"&&L.type==="range")return!1;var w=jt(C,L);if(!w)return!0;if(w?E=C:(E=C==="v"?"h":"v",w=jt(C,L)),!w)return!1;if(!r.current&&"changedTouches"in m&&(N||x)&&(r.current=E),!E)return!0;var _=r.current||E;return Bo(_,b,m,_==="h"?N:x,!0)},[]),l=p.useCallback(function(m){var b=m;if(!(!K.length||K[K.length-1]!==a)){var y="deltaY"in b?St(b):ie(b),k=t.current.filter(function(E){return E.name===b.type&&(E.target===b.target||b.target===E.shadowParent)&&zo(E.delta,y)})[0];if(k&&k.should){b.cancelable&&b.preventDefault();return}if(!k){var N=(i.current.shards||[]).map(Ot).filter(Boolean).filter(function(E){return E.contains(b.target)}),x=N.length>0?s(b,N[0]):!i.current.noIsolation;x&&b.cancelable&&b.preventDefault()}}},[]),c=p.useCallback(function(m,b,y,k){var N={name:m,delta:b,target:y,should:k,shadowParent:Xo(y)};t.current.push(N),setTimeout(function(){t.current=t.current.filter(function(x){return x!==N})},1)},[]),d=p.useCallback(function(m){n.current=ie(m),r.current=void 0},[]),f=p.useCallback(function(m){c(m.type,St(m),m.target,s(m,e.lockRef.current))},[]),h=p.useCallback(function(m){c(m.type,ie(m),m.target,s(m,e.lockRef.current))},[]);p.useEffect(function(){return K.push(a),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,q),document.addEventListener("touchmove",l,q),document.addEventListener("touchstart",d,q),function(){K=K.filter(function(m){return m!==a}),document.removeEventListener("wheel",l,q),document.removeEventListener("touchmove",l,q),document.removeEventListener("touchstart",d,q)}},[]);var g=e.removeScrollBar,v=e.inert;return p.createElement(p.Fragment,null,v?p.createElement(a,{styles:Ho(o)}):null,g?p.createElement(Po,{gapMode:e.gapMode}):null)}function Xo(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const qo=No(cn,Yo);var pn=p.forwardRef(function(e,t){return p.createElement(we,F({},e,{ref:t,sideCar:qo}))});pn.classNames=we.classNames;var Ko=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Q=new WeakMap,se=new WeakMap,le={},Te=0,mn=function(e){return e&&(e.host||mn(e.parentNode))},Qo=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=mn(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},Jo=function(e,t,n,r){var o=Qo(t,Array.isArray(e)?e:[e]);le[n]||(le[n]=new WeakMap);var a=le[n],i=[],s=new Set,l=new Set(o),c=function(f){!f||s.has(f)||(s.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(s.has(h))d(h);else try{var g=h.getAttribute(r),v=g!==null&&g!=="false",m=(Q.get(h)||0)+1,b=(a.get(h)||0)+1;Q.set(h,m),a.set(h,b),i.push(h),m===1&&v&&se.set(h,!0),b===1&&h.setAttribute(n,"true"),v||h.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",h,y)}})};return d(t),s.clear(),Te++,function(){i.forEach(function(f){var h=Q.get(f)-1,g=a.get(f)-1;Q.set(f,h),a.set(f,g),h||(se.has(f)||f.removeAttribute(r),se.delete(f)),g||f.removeAttribute(n)}),Te--,Te||(Q=new WeakMap,Q=new WeakMap,se=new WeakMap,le={})}},Zo=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Ko(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),Jo(r,o,n,"aria-hidden")):function(){return null}},Ye="Dialog",[gn,Xc]=Zt(Ye),[ea,M]=gn(Ye),vn=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:a,modal:i=!0}=e,s=p.useRef(null),l=p.useRef(null),[c=!1,d]=en({prop:r,defaultProp:o,onChange:a});return u.jsx(ea,{scope:t,triggerRef:s,contentRef:l,contentId:Ce(),titleId:Ce(),descriptionId:Ce(),open:c,onOpenChange:d,onOpenToggle:p.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};vn.displayName=Ye;var bn="DialogTrigger",ta=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=M(bn,n),a=re(t,o.triggerRef);return u.jsx(W.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ke(o.open),...r,ref:a,onClick:z(e.onClick,o.onOpenToggle)})});ta.displayName=bn;var Xe="DialogPortal",[na,wn]=gn(Xe,{forceMount:void 0}),yn=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,a=M(Xe,t);return u.jsx(na,{scope:t,forceMount:n,children:p.Children.map(r,i=>u.jsx(be,{present:n||a.open,children:u.jsx(zr,{asChild:!0,container:o,children:i})}))})};yn.displayName=Xe;var me="DialogOverlay",xn=p.forwardRef((e,t)=>{const n=wn(me,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,a=M(me,e.__scopeDialog);return a.modal?u.jsx(be,{present:r||a.open,children:u.jsx(ra,{...o,ref:t})}):null});xn.displayName=me;var ra=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=M(me,n);return u.jsx(pn,{as:Vr,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(W.div,{"data-state":Ke(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),H="DialogContent",En=p.forwardRef((e,t)=>{const n=wn(H,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,a=M(H,e.__scopeDialog);return u.jsx(be,{present:r||a.open,children:a.modal?u.jsx(oa,{...o,ref:t}):u.jsx(aa,{...o,ref:t})})});En.displayName=H;var oa=p.forwardRef((e,t)=>{const n=M(H,e.__scopeDialog),r=p.useRef(null),o=re(t,n.contentRef,r);return p.useEffect(()=>{const a=r.current;if(a)return Zo(a)},[]),u.jsx(Nn,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:z(e.onCloseAutoFocus,a=>{var i;a.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:z(e.onPointerDownOutside,a=>{const i=a.detail.originalEvent,s=i.button===0&&i.ctrlKey===!0;(i.button===2||s)&&a.preventDefault()}),onFocusOutside:z(e.onFocusOutside,a=>a.preventDefault())})}),aa=p.forwardRef((e,t)=>{const n=M(H,e.__scopeDialog),r=p.useRef(!1),o=p.useRef(!1);return u.jsx(Nn,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var i,s;(i=e.onCloseAutoFocus)==null||i.call(e,a),a.defaultPrevented||(r.current||(s=n.triggerRef.current)==null||s.focus(),a.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:a=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=a.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&o.current&&a.preventDefault()}})}),Nn=p.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:a,...i}=e,s=M(H,n),l=p.useRef(null),c=re(t,l);return ho(),u.jsxs(u.Fragment,{children:[u.jsx(on,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:a,children:u.jsx(Wr,{role:"dialog",id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":Ke(s.open),...i,ref:c,onDismiss:()=>s.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(ia,{titleId:s.titleId}),u.jsx(la,{contentRef:l,descriptionId:s.descriptionId})]})]})}),qe="DialogTitle",kn=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=M(qe,n);return u.jsx(W.h2,{id:o.titleId,...r,ref:t})});kn.displayName=qe;var Cn="DialogDescription",_n=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=M(Cn,n);return u.jsx(W.p,{id:o.descriptionId,...r,ref:t})});_n.displayName=Cn;var jn="DialogClose",Sn=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=M(jn,n);return u.jsx(W.button,{type:"button",...r,ref:t,onClick:z(e.onClick,()=>o.onOpenChange(!1))})});Sn.displayName=jn;function Ke(e){return e?"open":"closed"}var On="DialogTitleWarning",[qc,In]=Br(On,{contentName:H,titleName:qe,docsSlug:"dialog"}),ia=({titleId:e})=>{const t=In(On),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.

If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.

For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return p.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},sa="DialogDescriptionWarning",la=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${In(sa).contentName}}.`;return p.useEffect(()=>{var a;const o=(a=e.current)==null?void 0:a.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},ca=vn,da=yn,Rn=xn,Tn=En,Ln=kn,Dn=_n,ua=Sn;const fa=ca,ha=da,Mn=p.forwardRef(({className:e,...t},n)=>u.jsx(Rn,{ref:n,className:O("fixed inset-0 z-50 bg-black/80  data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Mn.displayName=Rn.displayName;const Pn=p.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ha,{children:[u.jsx(Mn,{}),u.jsxs(Tn,{ref:r,className:O("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[t,u.jsxs(ua,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(Hr,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Pn.displayName=Tn.displayName;const Fn=({className:e,...t})=>u.jsx("div",{className:O("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Fn.displayName="DialogHeader";const pa=p.forwardRef(({className:e,...t},n)=>u.jsx(Ln,{ref:n,className:O("text-lg font-semibold leading-none tracking-tight",e),...t}));pa.displayName=Ln.displayName;const ma=p.forwardRef(({className:e,...t},n)=>u.jsx(Dn,{ref:n,className:O("text-sm text-muted-foreground",e),...t}));ma.displayName=Dn.displayName;function ga({extensions:e,defaultPath:t="",onSelect:n}){const[r,o]=p.useState([]),[a,i]=p.useState("."),[s,l]=p.useState(t);p.useEffect(()=>{Ge("/get_os_sep",{method:"GET"}).then(f=>f.text()).then(f=>{i(f)}),c(s)},[]);const c=f=>{Ge("/file_picker/list_files",{method:"POST",body:JSON.stringify({path:f,extensions:e})}).then(h=>h.json()).then(h=>{l(h.path),o(h.items)})},d=f=>{const h=s.split(a).slice(0,f+1).join(a);c(h)};return u.jsxs(R,{children:[u.jsxs(T,{className:"gap-4 mb-3",children:[u.jsx("p",{className:"text-xl font-semibold",children:"Choose File"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:e==null?void 0:e.join(", ")})]}),u.jsx(T,{children:s.split(a).map((f,h)=>u.jsxs(T,{className:"mb-2",children:[u.jsx(pe,{variant:"link",className:"px-0 text-lg",onClick:()=>d(h),children:f}),u.jsx("span",{className:"px-1",children:h<s.split(a).length-1&&a})]},h))}),u.jsx(R,{className:"overflow-y-auto h-[70vh]",children:r.map(f=>f.type==="file"?u.jsx(ba,{file:f,onClick:()=>n(f)},f.name):u.jsxs(T,{className:"cursor-pointer gap-1 hover:bg-secondary py-[1px]",onClick:()=>c(f.path),children:[u.jsx(Xr,{size:16}),u.jsx("span",{children:f.name})]},f.name))})]})}const va=["jpg","jpeg","png","gif","bmp","tiff","webp"];function ba({file:e,onClick:t}){const n=va.includes(e.name.split(".").pop()||"");return u.jsxs(T,{className:"gap-1 cursor-pointer hover:bg-secondary",onClick:t,children:[n&&u.jsx("img",{src:ne+`/preview_image?path=${encodeURIComponent(e.path)}`,alt:e.name,className:"w-10 h-10 object-contain",style:{width:"50px",height:"50px",objectFit:"contain"}}),u.jsx("span",{children:e.name})]})}function wa({onClose:e,extensions:t,defaultPath:n="",onSelect:r}){return u.jsx(fa,{onOpenChange:e,open:!0,children:u.jsx(Pn,{className:"sm:max-w-[50vw]","aria-describedby":"Choose File",children:u.jsx(Fn,{children:u.jsx(ga,{extensions:t,defaultPath:n,onSelect:r})})})})}const ya=["png","jpg","jpeg","gif","bmp","tiff","webp"];function xa(e){return ya.includes(e.split(".").pop()??"")}function Ea(e){return/[\/\\]([^\/\\]+\.(png|jpg|jpeg|gif|bmp|tiff|webp))$/i.test(e)}function Na({input:e,extensions:t,nodeID:n}){const{updateValues:r,values:o}=V(U(c=>({values:c.values,updateValues:c.updateValues})));He();const[a,i]=p.useState(!1),s=o[I("input",n,e.id)],l=s==null?void 0:s.split(tn.osSep).pop();return u.jsxs(R,{className:"px-1 w-full",children:[u.jsx(pe,{onClick:()=>i(!0),className:"mb-2",children:"Choose file"}),s&&u.jsxs(R,{children:[xa(s)&&u.jsx("img",{src:ne+`/preview_image?path=${encodeURIComponent(s)}`,alt:l,className:"object-contain max-w-[360px] max-h-[360px]",style:{objectFit:"contain"}}),u.jsxs(T,{className:"gap-2",children:[u.jsx("p",{className:"text-sm break-all",children:l}),u.jsx(pe,{variant:"secondary",className:"p-[1px] w-5 h-5",onClick:()=>{r({[I("input",n,e.id)]:void 0})},children:u.jsx(eo,{size:15})})]})]}),a&&u.jsx(wa,{extensions:t,onClose:()=>i(!1),onSelect:c=>{i(!1),r({[I("input",n,e.id)]:c.rel_path})}})]})}function ka(e){const t=p.useRef({value:e,previous:e});return p.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function Ca(e){const[t,n]=p.useState(void 0);return Jt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const a=o[0];let i,s;if("borderBoxSize"in a){const l=a.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,s=c.blockSize}else i=e.offsetWidth,s=e.offsetHeight;n({width:i,height:s})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Qe="Checkbox",[_a,Kc]=Zt(Qe),[ja,Sa]=_a(Qe),An=p.forwardRef((e,t)=>{const{__scopeCheckbox:n,name:r,checked:o,defaultChecked:a,required:i,disabled:s,value:l="on",onCheckedChange:c,form:d,...f}=e,[h,g]=p.useState(null),v=re(t,x=>g(x)),m=p.useRef(!1),b=h?d||!!h.closest("form"):!0,[y=!1,k]=en({prop:o,defaultProp:a,onChange:c}),N=p.useRef(y);return p.useEffect(()=>{const x=h==null?void 0:h.form;if(x){const E=()=>k(N.current);return x.addEventListener("reset",E),()=>x.removeEventListener("reset",E)}},[h,k]),u.jsxs(ja,{scope:n,state:y,disabled:s,children:[u.jsx(W.button,{type:"button",role:"checkbox","aria-checked":G(y)?"mixed":y,"aria-required":i,"data-state":Vn(y),"data-disabled":s?"":void 0,disabled:s,value:l,...f,ref:v,onKeyDown:z(e.onKeyDown,x=>{x.key==="Enter"&&x.preventDefault()}),onClick:z(e.onClick,x=>{k(E=>G(E)?!0:!E),b&&(m.current=x.isPropagationStopped(),m.current||x.stopPropagation())})}),b&&u.jsx(Oa,{control:h,bubbles:!m.current,name:r,value:l,checked:y,required:i,disabled:s,form:d,style:{transform:"translateX(-100%)"},defaultChecked:G(a)?!1:a})]})});An.displayName=Qe;var $n="CheckboxIndicator",Gn=p.forwardRef((e,t)=>{const{__scopeCheckbox:n,forceMount:r,...o}=e,a=Sa($n,n);return u.jsx(be,{present:r||G(a.state)||a.state===!0,children:u.jsx(W.span,{"data-state":Vn(a.state),"data-disabled":a.disabled?"":void 0,...o,ref:t,style:{pointerEvents:"none",...e.style}})})});Gn.displayName=$n;var Oa=e=>{const{control:t,checked:n,bubbles:r=!0,defaultChecked:o,...a}=e,i=p.useRef(null),s=ka(n),l=Ca(t);p.useEffect(()=>{const d=i.current,f=window.HTMLInputElement.prototype,g=Object.getOwnPropertyDescriptor(f,"checked").set;if(s!==n&&g){const v=new Event("click",{bubbles:r});d.indeterminate=G(n),g.call(d,G(n)?!1:n),d.dispatchEvent(v)}},[s,n,r]);const c=p.useRef(G(n)?!1:n);return u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:o??c.current,...a,tabIndex:-1,ref:i,style:{...e.style,...l,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function G(e){return e==="indeterminate"}function Vn(e){return G(e)?"indeterminate":e?"checked":"unchecked"}var Wn=An,Ia=Gn;const Bn=p.forwardRef(({className:e,...t},n)=>u.jsx(Wn,{ref:n,className:O("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...t,children:u.jsx(Ia,{className:O("flex items-center justify-center text-current"),children:u.jsx(qr,{className:"h-4 w-4"})})}));Bn.displayName=Wn.displayName;const It="8",We="000";function zn(e){return u.jsx($e,{style:{width:`${It}px`,height:`${It}px`},...e})}function Ra({input:e,nodeID:t,isConnected:n}){const r=e.type==="int"||e.type==="float",o=e.widget;return u.jsx(R,{className:`flex w-full ${r?"h-10":""}`,children:u.jsxs(T,{className:"gap-2 w-full",children:[!e.hide_handle&&u.jsxs("div",{className:"relative flex items-center gap-1",children:[u.jsx(zn,{type:"target",position:de.Left,id:e.id}),u.jsx("span",{className:"text-sm font-semibold ml-2",children:e.name}),typeof e.type=="string"&&u.jsx("span",{className:"text-[10px] text-zinc-500 italic",children:e.type})]}),o?u.jsx(Ta,{input:e,nodeID:t}):!n&&u.jsx(La,{input:e,nodeID:t})]})},"input"+e.id)}function Ta({input:e,nodeID:t}){var n,r;if(((n=e.widget)==null?void 0:n.type)==="server_file_picker")return u.jsx(Na,{input:e,extensions:(r=e.widget.options)==null?void 0:r.extensions,nodeID:t})}function La({input:e,nodeID:t}){const{updateValues:n,values:r}=V(U(i=>({values:i.values,updateValues:i.updateValues}))),o=p.useRef(null),a=He();if(p.useEffect(()=>{if(e.type!=="str")return;const i=o.current;if(!i)return;const s=()=>{i.style.height="auto",i.style.height=`${i.scrollHeight}px`,a(t)};return s(),i.addEventListener("input",s),()=>{i.removeEventListener("input",s)}},[e.type,t,a,r[I("input",t,e.id)]]),e.type==="int"||e.type==="float")return u.jsx(no,{input:e,nodeID:t});if(e.type==="bool")return u.jsx(Bn,{className:"mx-4",checked:r[I("input",t,e.id)]??!1,onCheckedChange:i=>{console.log("checked",i),n({[I("input",t,e.id)]:i.valueOf()})}});if(Array.isArray(e.type))return u.jsx("select",{id:"countries",value:r[I("input",t,e.id)]??"",onChange:i=>{n({[I("input",t,e.id)]:i.target.value})},className:"bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2 dark:bg-zinc-700 dark:border-zinc-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500",children:e.type.map(i=>u.jsx("option",{value:i,children:i},i))});if(e.type==="str")return u.jsx(rn,{ref:o,value:r[I("input",t,e.id)]??"",className:"border-zinc-700 py-1 flex-1 flex-grow nodrag nopan resize-none",style:{height:"auto",overflow:"hidden"},onChange:i=>{n({[I("input",t,e.id)]:i.target.value})}})}function Da({children:e}){const t=p.useRef(null),[n,r]=p.useState(100);return p.useEffect(()=>{var o;(o=t.current)!=null&&o.offsetHeight&&r(t.current.offsetHeight)},[]),u.jsxs("div",{className:"group h-full",children:[u.jsx(Lr,{className:"!w-3 !h-3 !translate-x-[-30%] !translate-y-[-30%] !bg-transparent !border-none group",minWidth:150,minHeight:n,children:u.jsx(Jr,{size:10,className:"hidden group-hover:block absolute bottom-0 right-0"})}),u.jsx("div",{className:"h-full",ref:t,children:e})]})}var he=(e=>(e.RUNNING="RUNNING",e.SUCCESS="SUCCESS",e.FAIL="FAIL",e))(he||{});function Ma({output:e,nodeID:t,status:n}){const r=n==null?void 0:n.results;return r?u.jsxs(R,{className:"text-left m-2 gap-[1px]",children:[u.jsxs(T,{className:"gap-1 items-center mb-1",children:[u.jsx("p",{className:"text-[10px] text-muted-foreground ",children:"Outputs"}),(n==null?void 0:n.status)===he.RUNNING&&u.jsx(nn,{className:"w-4 h-4"}),(n==null?void 0:n.status)===he.SUCCESS&&u.jsx(Zr,{className:"w-4 h-4 text-green-500"}),(n==null?void 0:n.status)===he.FAIL&&u.jsx(to,{className:"w-4 h-4 text-red-500"})]}),r==null?void 0:r.map((o,a)=>u.jsx(R,{children:u.jsxs(R,{className:"text-sm p-1 gap-1 rounded-md border border-zinc-600 bg-zinc-700",children:[typeof o=="object"?u.jsx("pre",{className:"whitespace-pre-wrap",children:JSON.stringify(o,null,2)}):u.jsx("pre",{className:"whitespace-pre-wrap break-all",children:o}),typeof o=="string"&&Ea(o)&&u.jsxs(R,{className:"gap-1 justify-center items-center",children:[u.jsx("img",{src:ne+`/preview_image?path=${encodeURIComponent(o)}`,alt:"image",className:"object-contain cursor-pointer w-full max-w-[500px] max-h-[500px]",style:{flex:1,objectFit:"contain"},onClick:()=>{window.open(ne+`/preview_image?path=${encodeURIComponent(o)}`,"_blank")}}),u.jsx(pe,{className:"w-full",onClick:()=>{window.open(ne+`/preview_image?path=${encodeURIComponent(o)}&download=1`,"_blank")},children:"Download"})]})]})},a)),(n==null?void 0:n.error)&&u.jsx(R,{children:u.jsx("div",{className:"text-sm p-1 rounded-md border bg-destructive",children:u.jsx("pre",{className:"whitespace-pre-wrap break-all",children:n==null?void 0:n.error})})})]}):null}function Pa({data:e,id:t}){var i,s;const{selectedNodeIDs:n,edges:r,status:o}=V(U(l=>{var c,d;return{selectedNodeIDs:l.selectedNodeIDs,edges:l.edges,status:(d=(c=l.job_status)==null?void 0:c.nodes)==null?void 0:d[t]}})),a=He();return p.useEffect(()=>{a(t)},[o,r,t,a]),u.jsx(Da,{children:u.jsxs("div",{className:"h-full flex flex-col min-w-[120px]",children:[u.jsxs("div",{className:"h-4 flex justify-end",children:[e.import_error&&u.jsxs("p",{className:"text-[10px] font-bold px-2",children:[u.jsx("span",{className:"text-red-500",children:" ❌ Import Failed: "}),u.jsx("span",{children:e.import_error})]}),u.jsxs("p",{className:"text-[10px] text-muted-foreground italic px-2 w-fit text-right",children:["#",t]})]}),u.jsxs(R,{className:`flex-1 bg-zinc-800 rounded-md ${n.includes(t)?"outline outline-[0.8px] outline-zinc-300":(o==null?void 0:o.status)==="RUNNING"?"outline outline-2 outline-purple-500":""}`,children:[u.jsxs(T,{className:`relative py-1 ${e.import_error?"bg-red-500":"bg-gray-700"} rounded-t-md justify-between`,children:[u.jsx($e,{type:"target",position:de.Left,id:"000"}),u.jsx(T,{className:"justify-between  flex-grow",children:u.jsx("p",{className:"px-2 font-semibold",children:e.node_title??e.name})}),u.jsx($e,{type:"source",position:de.Right,id:We})]}),u.jsxs(T,{className:"flex justify-between py-2 h-full",children:[u.jsx("div",{className:"flex flex-col gap-2 h-full w-full pr-2",children:(i=e.input)==null?void 0:i.map(l=>{const c=r.some(d=>d.target===t&&d.targetHandle===l.id);return u.jsx(Ra,{input:l,nodeID:t,isConnected:c},l.id)})}),u.jsx(R,{className:"flex flex-col justify-center ml-2 gap-2",children:(s=e.output)==null?void 0:s.map(l=>{var c;return u.jsxs("div",{className:"relative flex items-center ml-3",children:[u.jsx("p",{className:"text-[10px] text-zinc-500 italic mr-[8px]",children:(c=l.type)==null?void 0:c.split("[")[0]}),u.jsx(zn,{type:"source",position:de.Right,id:l.id})]},"output"+l.id)})})]}),u.jsx(Ma,{nodeID:t,output:e.output??null,status:o??null})]})]})})}var Fa="\0",B="\0",Rt="";let Aa=class{constructor(t){j(this,"_isDirected",!0);j(this,"_isMultigraph",!1);j(this,"_isCompound",!1);j(this,"_label");j(this,"_defaultNodeLabelFn",()=>{});j(this,"_defaultEdgeLabelFn",()=>{});j(this,"_nodes",{});j(this,"_in",{});j(this,"_preds",{});j(this,"_out",{});j(this,"_sucs",{});j(this,"_edgeObjs",{});j(this,"_edgeLabels",{});j(this,"_nodeCount",0);j(this,"_edgeCount",0);j(this,"_parent");j(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[B]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,o=this;return t.forEach(function(a){r.length>1?o.setNode(a,n):o.setNode(a)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=B,this._children[t]={},this._children[B][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=o=>n.removeEdge(n._edgeObjs[o]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(o){n.setParent(o)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=B;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==B)return n}}children(t=B){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===B)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const o=new Set(n);for(var r of this.successors(t))o.add(r);return Array.from(o.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([i,s]){t(i)&&n.setNode(i,s)}),Object.values(this._edgeObjs).forEach(function(i){n.hasNode(i.v)&&n.hasNode(i.w)&&n.setEdge(i,r.edge(i))});var o={};function a(i){var s=r.parent(i);return s===void 0||n.hasNode(s)?(o[i]=s,s):s in o?o[s]:a(s)}return this._isCompound&&n.nodes().forEach(i=>n.setParent(i,a(i))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,o=arguments;return t.reduce(function(a,i){return o.length>1?r.setEdge(a,i,n):r.setEdge(a,i),i}),this}setEdge(){var t,n,r,o,a=!1,i=arguments[0];typeof i=="object"&&i!==null&&"v"in i?(t=i.v,n=i.w,r=i.name,arguments.length===2&&(o=arguments[1],a=!0)):(t=i,n=arguments[1],r=arguments[3],arguments.length>2&&(o=arguments[2],a=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var s=te(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,s))return a&&(this._edgeLabels[s]=o),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[s]=a?o:this._defaultEdgeLabelFn(t,n,r);var l=$a(this._isDirected,t,n,r);return t=l.v,n=l.w,Object.freeze(l),this._edgeObjs[s]=l,Tt(this._preds[n],t),Tt(this._sucs[t],n),this._in[n][s]=l,this._out[t][s]=l,this._edgeCount++,this}edge(t,n,r){var o=arguments.length===1?Le(this._isDirected,arguments[0]):te(this._isDirected,t,n,r);return this._edgeLabels[o]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var o=arguments.length===1?Le(this._isDirected,arguments[0]):te(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,o)}removeEdge(t,n,r){var o=arguments.length===1?Le(this._isDirected,arguments[0]):te(this._isDirected,t,n,r),a=this._edgeObjs[o];return a&&(t=a.v,n=a.w,delete this._edgeLabels[o],delete this._edgeObjs[o],Lt(this._preds[n],t),Lt(this._sucs[t],n),delete this._in[n][o],delete this._out[t][o],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var o=Object.values(r);return n?o.filter(a=>a.v===n):o}}outEdges(t,n){var r=this._out[t];if(r){var o=Object.values(r);return n?o.filter(a=>a.w===n):o}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Tt(e,t){e[t]?e[t]++:e[t]=1}function Lt(e,t){--e[t]||delete e[t]}function te(e,t,n,r){var o=""+t,a=""+n;if(!e&&o>a){var i=o;o=a,a=i}return o+Rt+a+Rt+(r===void 0?Fa:r)}function $a(e,t,n,r){var o=""+t,a=""+n;if(!e&&o>a){var i=o;o=a,a=i}var s={v:o,w:a};return r&&(s.name=r),s}function Le(e,t){return te(e,t.v,t.w,t.name)}var Je=Aa,Ga="2.2.4",Va={Graph:Je,version:Ga},Wa=Je,Ba={write:za,read:Ya};function za(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Ha(e),edges:Ua(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function Ha(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),o={v:t};return n!==void 0&&(o.value=n),r!==void 0&&(o.parent=r),o})}function Ua(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function Ya(e){var t=new Wa(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var Xa=qa;function qa(e){var t={},n=[],r;function o(a){Object.hasOwn(t,a)||(t[a]=!0,r.push(a),e.successors(a).forEach(o),e.predecessors(a).forEach(o))}return e.nodes().forEach(function(a){r=[],o(a),r.length&&n.push(r)}),n}let Ka=class{constructor(){j(this,"_arr",[]);j(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var o=this._arr,a=o.length;return r[t]=a,o.push({key:t,priority:n}),this._decrease(a),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,o=r+1,a=t;r<n.length&&(a=n[r].priority<n[a].priority?r:a,o<n.length&&(a=n[o].priority<n[a].priority?o:a),a!==t&&(this._swap(t,a),this._heapify(a)))}_decrease(t){for(var n=this._arr,r=n[t].priority,o;t!==0&&(o=t>>1,!(n[o].priority<r));)this._swap(t,o),t=o}_swap(t,n){var r=this._arr,o=this._keyIndices,a=r[t],i=r[n];r[t]=i,r[n]=a,o[i.key]=t,o[a.key]=n}};var Hn=Ka,Qa=Hn,Un=Za,Ja=()=>1;function Za(e,t,n,r){return ei(e,String(t),n||Ja,r||function(o){return e.outEdges(o)})}function ei(e,t,n,r){var o={},a=new Qa,i,s,l=function(c){var d=c.v!==i?c.v:c.w,f=o[d],h=n(c),g=s.distance+h;if(h<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+c+" Weight: "+h);g<f.distance&&(f.distance=g,f.predecessor=i,a.decrease(d,g))};for(e.nodes().forEach(function(c){var d=c===t?0:Number.POSITIVE_INFINITY;o[c]={distance:d},a.add(c,d)});a.size()>0&&(i=a.removeMin(),s=o[i],s.distance!==Number.POSITIVE_INFINITY);)r(i).forEach(l);return o}var ti=Un,ni=ri;function ri(e,t,n){return e.nodes().reduce(function(r,o){return r[o]=ti(e,o,t,n),r},{})}var Yn=oi;function oi(e){var t=0,n=[],r={},o=[];function a(i){var s=r[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(d){Object.hasOwn(r,d)?r[d].onStack&&(s.lowlink=Math.min(s.lowlink,r[d].index)):(a(d),s.lowlink=Math.min(s.lowlink,r[d].lowlink))}),s.lowlink===s.index){var l=[],c;do c=n.pop(),r[c].onStack=!1,l.push(c);while(i!==c);o.push(l)}}return e.nodes().forEach(function(i){Object.hasOwn(r,i)||a(i)}),o}var ai=Yn,ii=si;function si(e){return ai(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var li=di,ci=()=>1;function di(e,t,n){return ui(e,t||ci,n||function(r){return e.outEdges(r)})}function ui(e,t,n){var r={},o=e.nodes();return o.forEach(function(a){r[a]={},r[a][a]={distance:0},o.forEach(function(i){a!==i&&(r[a][i]={distance:Number.POSITIVE_INFINITY})}),n(a).forEach(function(i){var s=i.v===a?i.w:i.v,l=t(i);r[a][s]={distance:l,predecessor:a}})}),o.forEach(function(a){var i=r[a];o.forEach(function(s){var l=r[s];o.forEach(function(c){var d=l[a],f=i[c],h=l[c],g=d.distance+f.distance;g<h.distance&&(h.distance=g,h.predecessor=f.predecessor)})})}),r}function Xn(e){var t={},n={},r=[];function o(a){if(Object.hasOwn(n,a))throw new Be;Object.hasOwn(t,a)||(n[a]=!0,t[a]=!0,e.predecessors(a).forEach(o),delete n[a],r.push(a))}if(e.sinks().forEach(o),Object.keys(t).length!==e.nodeCount())throw new Be;return r}class Be extends Error{constructor(){super(...arguments)}}var qn=Xn;Xn.CycleException=Be;var Dt=qn,fi=hi;function hi(e){try{Dt(e)}catch(t){if(t instanceof Dt.CycleException)return!1;throw t}return!0}var Kn=pi;function pi(e,t,n){Array.isArray(t)||(t=[t]);var r=e.isDirected()?s=>e.successors(s):s=>e.neighbors(s),o=n==="post"?mi:gi,a=[],i={};return t.forEach(s=>{if(!e.hasNode(s))throw new Error("Graph does not have node: "+s);o(s,r,i,a)}),a}function mi(e,t,n,r){for(var o=[[e,!1]];o.length>0;){var a=o.pop();a[1]?r.push(a[0]):Object.hasOwn(n,a[0])||(n[a[0]]=!0,o.push([a[0],!0]),Qn(t(a[0]),i=>o.push([i,!1])))}}function gi(e,t,n,r){for(var o=[e];o.length>0;){var a=o.pop();Object.hasOwn(n,a)||(n[a]=!0,r.push(a),Qn(t(a),i=>o.push(i)))}}function Qn(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var vi=Kn,bi=wi;function wi(e,t){return vi(e,t,"post")}var yi=Kn,xi=Ei;function Ei(e,t){return yi(e,t,"pre")}var Ni=Je,ki=Hn,Ci=_i;function _i(e,t){var n=new Ni,r={},o=new ki,a;function i(l){var c=l.v===a?l.w:l.v,d=o.priority(c);if(d!==void 0){var f=t(l);f<d&&(r[c]=a,o.decrease(c,f))}}if(e.nodeCount()===0)return n;e.nodes().forEach(function(l){o.add(l,Number.POSITIVE_INFINITY),n.setNode(l)}),o.decrease(e.nodes()[0],0);for(var s=!1;o.size()>0;){if(a=o.removeMin(),Object.hasOwn(r,a))n.setEdge(a,r[a]);else{if(s)throw new Error("Input graph is not connected: "+e);s=!0}e.nodeEdges(a).forEach(i)}return n}var ji={components:Xa,dijkstra:Un,dijkstraAll:ni,findCycles:ii,floydWarshall:li,isAcyclic:fi,postorder:bi,preorder:xi,prim:Ci,tarjan:Yn,topsort:qn},Mt=Va,P={Graph:Mt.Graph,json:Ba,alg:ji,version:Mt.version};let Si=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Pt(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Pt(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Oi)),r=r._prev;return"["+t.join(", ")+"]"}};function Pt(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Oi(e,t){if(e!=="_next"&&e!=="_prev")return t}var Ii=Si;let Ri=P.Graph,Ti=Ii;var Li=Mi;let Di=()=>1;function Mi(e,t){if(e.nodeCount()<=1)return[];let n=Fi(e,t||Di);return Pi(n.graph,n.buckets,n.zeroIdx).flatMap(o=>e.outEdges(o.v,o.w))}function Pi(e,t,n){let r=[],o=t[t.length-1],a=t[0],i;for(;e.nodeCount();){for(;i=a.dequeue();)De(e,t,n,i);for(;i=o.dequeue();)De(e,t,n,i);if(e.nodeCount()){for(let s=t.length-2;s>0;--s)if(i=t[s].dequeue(),i){r=r.concat(De(e,t,n,i,!0));break}}}return r}function De(e,t,n,r,o){let a=o?[]:void 0;return e.inEdges(r.v).forEach(i=>{let s=e.edge(i),l=e.node(i.v);o&&a.push({v:i.v,w:i.w}),l.out-=s,ze(t,n,l)}),e.outEdges(r.v).forEach(i=>{let s=e.edge(i),l=i.w,c=e.node(l);c.in-=s,ze(t,n,c)}),e.removeNode(r.v),a}function Fi(e,t){let n=new Ri,r=0,o=0;e.nodes().forEach(s=>{n.setNode(s,{v:s,in:0,out:0})}),e.edges().forEach(s=>{let l=n.edge(s.v,s.w)||0,c=t(s),d=l+c;n.setEdge(s.v,s.w,d),o=Math.max(o,n.node(s.v).out+=c),r=Math.max(r,n.node(s.w).in+=c)});let a=Ai(o+r+3).map(()=>new Ti),i=r+1;return n.nodes().forEach(s=>{ze(a,i,n.node(s))}),{graph:n,buckets:a,zeroIdx:i}}function ze(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Ai(e){const t=[];for(let n=0;n<e;n++)t.push(n);return t}let Jn=P.Graph;var S={addBorderNode:Yi,addDummyNode:Zn,applyWithChunking:ye,asNonCompoundGraph:Gi,buildLayerMatrix:zi,intersectRect:Bi,mapValues:es,maxRank:tr,normalizeRanks:Hi,notime:Qi,partition:qi,pick:Zi,predecessorWeights:Wi,range:rr,removeEmptyRanks:Ui,simplify:$i,successorWeights:Vi,time:Ki,uniqueId:nr,zipObject:Ze};function Zn(e,t,n,r){let o;do o=nr(r);while(e.hasNode(o));return n.dummy=t,e.setNode(o,n),o}function $i(e){let t=new Jn().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},o=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+o.weight,minlen:Math.max(r.minlen,o.minlen)})}),t}function Gi(e){let t=new Jn({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Vi(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(o=>{r[o.w]=(r[o.w]||0)+e.edge(o).weight}),r});return Ze(e.nodes(),t)}function Wi(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(o=>{r[o.v]=(r[o.v]||0)+e.edge(o).weight}),r});return Ze(e.nodes(),t)}function Bi(e,t){let n=e.x,r=e.y,o=t.x-n,a=t.y-r,i=e.width/2,s=e.height/2;if(!o&&!a)throw new Error("Not possible to find intersection inside of the rectangle");let l,c;return Math.abs(a)*i>Math.abs(o)*s?(a<0&&(s=-s),l=s*o/a,c=s):(o<0&&(i=-i),l=i,c=i*a/o),{x:n+l,y:r+c}}function zi(e){let t=rr(tr(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),o=r.rank;o!==void 0&&(t[o][r.order]=n)}),t}function Hi(e){let t=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MAX_VALUE:o}),n=ye(Math.min,t);e.nodes().forEach(r=>{let o=e.node(r);Object.hasOwn(o,"rank")&&(o.rank-=n)})}function Ui(e){let t=e.nodes().map(i=>e.node(i).rank),n=ye(Math.min,t),r=[];e.nodes().forEach(i=>{let s=e.node(i).rank-n;r[s]||(r[s]=[]),r[s].push(i)});let o=0,a=e.graph().nodeRankFactor;Array.from(r).forEach((i,s)=>{i===void 0&&s%a!==0?--o:i!==void 0&&o&&i.forEach(l=>e.node(l).rank+=o)})}function Yi(e,t,n,r){let o={width:0,height:0};return arguments.length>=4&&(o.rank=n,o.order=r),Zn(e,"border",o,t)}function Xi(e,t=er){const n=[];for(let r=0;r<e.length;r+=t){const o=e.slice(r,r+t);n.push(o)}return n}const er=65535;function ye(e,t){if(t.length>er){const n=Xi(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function tr(e){const n=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MIN_VALUE:o});return ye(Math.max,n)}function qi(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function Ki(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function Qi(e,t){return t()}let Ji=0;function nr(e){var t=++Ji;return toString(e)+t}function rr(e,t,n=1){t==null&&(t=e,e=0);let r=a=>a<t;n<0&&(r=a=>t<a);const o=[];for(let a=e;r(a);a+=n)o.push(a);return o}function Zi(e,t){const n={};for(const r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function es(e,t){let n=t;return typeof t=="string"&&(n=r=>r[t]),Object.entries(e).reduce((r,[o,a])=>(r[o]=n(a,o),r),{})}function Ze(e,t){return e.reduce((n,r,o)=>(n[r]=t[o],n),{})}let ts=Li,ns=S.uniqueId;var rs={run:os,undo:is};function os(e){(e.graph().acyclicer==="greedy"?ts(e,n(e)):as(e)).forEach(r=>{let o=e.edge(r);e.removeEdge(r),o.forwardName=r.name,o.reversed=!0,e.setEdge(r.w,r.v,o,ns("rev"))});function n(r){return o=>r.edge(o).weight}}function as(e){let t=[],n={},r={};function o(a){Object.hasOwn(r,a)||(r[a]=!0,n[a]=!0,e.outEdges(a).forEach(i=>{Object.hasOwn(n,i.w)?t.push(i):o(i.w)}),delete n[a])}return e.nodes().forEach(o),t}function is(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let ss=S;var ls={run:cs,undo:us};function cs(e){e.graph().dummyChains=[],e.edges().forEach(t=>ds(e,t))}function ds(e,t){let n=t.v,r=e.node(n).rank,o=t.w,a=e.node(o).rank,i=t.name,s=e.edge(t),l=s.labelRank;if(a===r+1)return;e.removeEdge(t);let c,d,f;for(f=0,++r;r<a;++f,++r)s.points=[],d={width:0,height:0,edgeLabel:s,edgeObj:t,rank:r},c=ss.addDummyNode(e,"edge",d,"_d"),r===l&&(d.width=s.width,d.height=s.height,d.dummy="edge-label",d.labelpos=s.labelpos),e.setEdge(n,c,{weight:s.weight},i),f===0&&e.graph().dummyChains.push(c),n=c;e.setEdge(n,o,{weight:s.weight},i)}function us(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,o;for(e.setEdge(n.edgeObj,r);n.dummy;)o=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=o,n=e.node(t)})}const{applyWithChunking:fs}=S;var xe={longestPath:hs,slack:ps};function hs(e){var t={};function n(r){var o=e.node(r);if(Object.hasOwn(t,r))return o.rank;t[r]=!0;let a=e.outEdges(r).map(s=>s==null?Number.POSITIVE_INFINITY:n(s.w)-e.edge(s).minlen);var i=fs(Math.min,a);return i===Number.POSITIVE_INFINITY&&(i=0),o.rank=i}e.sources().forEach(n)}function ps(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var ms=P.Graph,ge=xe.slack,or=gs;function gs(e){var t=new ms({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var o,a;vs(t,e)<r;)o=bs(t,e),a=t.hasNode(o.v)?ge(e,o):-ge(e,o),ws(t,e,a);return t}function vs(e,t){function n(r){t.nodeEdges(r).forEach(o=>{var a=o.v,i=r===a?o.w:a;!e.hasNode(i)&&!ge(t,o)&&(e.setNode(i,{}),e.setEdge(r,i,{}),n(i))})}return e.nodes().forEach(n),e.nodeCount()}function bs(e,t){return t.edges().reduce((r,o)=>{let a=Number.POSITIVE_INFINITY;return e.hasNode(o.v)!==e.hasNode(o.w)&&(a=ge(t,o)),a<r[0]?[a,o]:r},[Number.POSITIVE_INFINITY,null])[1]}function ws(e,t,n){e.nodes().forEach(r=>t.node(r).rank+=n)}var ys=or,Ft=xe.slack,xs=xe.longestPath,Es=P.alg.preorder,Ns=P.alg.postorder,ks=S.simplify,Cs=X;X.initLowLimValues=tt;X.initCutValues=et;X.calcCutValue=ar;X.leaveEdge=sr;X.enterEdge=lr;X.exchangeEdges=cr;function X(e){e=ks(e),xs(e);var t=ys(e);tt(t),et(t,e);for(var n,r;n=sr(t);)r=lr(t,e,n),cr(t,e,n,r)}function et(e,t){var n=Ns(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>_s(e,t,r))}function _s(e,t,n){var r=e.node(n),o=r.parent;e.edge(n,o).cutvalue=ar(e,t,n)}function ar(e,t,n){var r=e.node(n),o=r.parent,a=!0,i=t.edge(n,o),s=0;return i||(a=!1,i=t.edge(o,n)),s=i.weight,t.nodeEdges(n).forEach(l=>{var c=l.v===n,d=c?l.w:l.v;if(d!==o){var f=c===a,h=t.edge(l).weight;if(s+=f?h:-h,Ss(e,n,d)){var g=e.edge(n,d).cutvalue;s+=f?-g:g}}}),s}function tt(e,t){arguments.length<2&&(t=e.nodes()[0]),ir(e,{},1,t)}function ir(e,t,n,r,o){var a=n,i=e.node(r);return t[r]=!0,e.neighbors(r).forEach(s=>{Object.hasOwn(t,s)||(n=ir(e,t,n,s,r))}),i.low=a,i.lim=n++,o?i.parent=o:delete i.parent,n}function sr(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function lr(e,t,n){var r=n.v,o=n.w;t.hasEdge(r,o)||(r=n.w,o=n.v);var a=e.node(r),i=e.node(o),s=a,l=!1;a.lim>i.lim&&(s=i,l=!0);var c=t.edges().filter(d=>l===At(e,e.node(d.v),s)&&l!==At(e,e.node(d.w),s));return c.reduce((d,f)=>Ft(t,f)<Ft(t,d)?f:d)}function cr(e,t,n,r){var o=n.v,a=n.w;e.removeEdge(o,a),e.setEdge(r.v,r.w,{}),tt(e),et(e,t),js(e,t)}function js(e,t){var n=e.nodes().find(o=>!t.node(o).parent),r=Es(e,n);r=r.slice(1),r.forEach(o=>{var a=e.node(o).parent,i=t.edge(o,a),s=!1;i||(i=t.edge(a,o),s=!0),t.node(o).rank=t.node(a).rank+(s?i.minlen:-i.minlen)})}function Ss(e,t,n){return e.hasEdge(t,n)}function At(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Os=xe,dr=Os.longestPath,Is=or,Rs=Cs,Ts=Ls;function Ls(e){switch(e.graph().ranker){case"network-simplex":$t(e);break;case"tight-tree":Ms(e);break;case"longest-path":Ds(e);break;default:$t(e)}}var Ds=dr;function Ms(e){dr(e),Is(e)}function $t(e){Rs(e)}var Ps=Fs;function Fs(e){let t=$s(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),o=r.edgeObj,a=As(e,t,o.v,o.w),i=a.path,s=a.lca,l=0,c=i[l],d=!0;for(;n!==o.w;){if(r=e.node(n),d){for(;(c=i[l])!==s&&e.node(c).maxRank<r.rank;)l++;c===s&&(d=!1)}if(!d){for(;l<i.length-1&&e.node(c=i[l+1]).minRank<=r.rank;)l++;c=i[l]}e.setParent(n,c),n=e.successors(n)[0]}})}function As(e,t,n,r){let o=[],a=[],i=Math.min(t[n].low,t[r].low),s=Math.max(t[n].lim,t[r].lim),l,c;l=n;do l=e.parent(l),o.push(l);while(l&&(t[l].low>i||s>t[l].lim));for(c=l,l=r;(l=e.parent(l))!==c;)a.push(l);return{path:o.concat(a.reverse()),lca:c}}function $s(e){let t={},n=0;function r(o){let a=n;e.children(o).forEach(r),t[o]={low:a,lim:n++}}return e.children().forEach(r),t}let ve=S;var Gs={run:Vs,cleanup:zs};function Vs(e){let t=ve.addDummyNode(e,"root",{},"_root"),n=Ws(e),r=Object.values(n),o=ve.applyWithChunking(Math.max,r)-1,a=2*o+1;e.graph().nestingRoot=t,e.edges().forEach(s=>e.edge(s).minlen*=a);let i=Bs(e)+1;e.children().forEach(s=>ur(e,t,a,i,o,n,s)),e.graph().nodeRankFactor=a}function ur(e,t,n,r,o,a,i){let s=e.children(i);if(!s.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}let l=ve.addBorderNode(e,"_bt"),c=ve.addBorderNode(e,"_bb"),d=e.node(i);e.setParent(l,i),d.borderTop=l,e.setParent(c,i),d.borderBottom=c,s.forEach(f=>{ur(e,t,n,r,o,a,f);let h=e.node(f),g=h.borderTop?h.borderTop:f,v=h.borderBottom?h.borderBottom:f,m=h.borderTop?r:2*r,b=g!==v?1:o-a[i]+1;e.setEdge(l,g,{weight:m,minlen:b,nestingEdge:!0}),e.setEdge(v,c,{weight:m,minlen:b,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,l,{weight:0,minlen:o+a[i]})}function Ws(e){var t={};function n(r,o){var a=e.children(r);a&&a.length&&a.forEach(i=>n(i,o+1)),t[r]=o}return e.children().forEach(r=>n(r,1)),t}function Bs(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function zs(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let Hs=S;var Us=Ys;function Ys(e){function t(n){let r=e.children(n),o=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let a=o.minRank,i=o.maxRank+1;a<i;++a)Gt(e,"borderLeft","_bl",n,o,a),Gt(e,"borderRight","_br",n,o,a)}}e.children().forEach(t)}function Gt(e,t,n,r,o,a){let i={width:0,height:0,rank:a,borderType:t},s=o[t][a-1],l=Hs.addDummyNode(e,"border",i,n);o[t][a]=l,e.setParent(l,r),s&&e.setEdge(s,l,{weight:1})}var Xs={adjust:qs,undo:Ks};function qs(e){let t=e.graph().rankdir.toLowerCase();(t==="lr"||t==="rl")&&fr(e)}function Ks(e){let t=e.graph().rankdir.toLowerCase();(t==="bt"||t==="rl")&&Qs(e),(t==="lr"||t==="rl")&&(Js(e),fr(e))}function fr(e){e.nodes().forEach(t=>Vt(e.node(t))),e.edges().forEach(t=>Vt(e.edge(t)))}function Vt(e){let t=e.width;e.width=e.height,e.height=t}function Qs(e){e.nodes().forEach(t=>Me(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(Me),Object.hasOwn(n,"y")&&Me(n)})}function Me(e){e.y=-e.y}function Js(e){e.nodes().forEach(t=>Pe(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(Pe),Object.hasOwn(n,"x")&&Pe(n)})}function Pe(e){let t=e.x;e.x=e.y,e.y=t}let Wt=S;var Zs=el;function el(e){let t={},n=e.nodes().filter(l=>!e.children(l).length),r=n.map(l=>e.node(l).rank),o=Wt.applyWithChunking(Math.max,r),a=Wt.range(o+1).map(()=>[]);function i(l){if(t[l])return;t[l]=!0;let c=e.node(l);a[c.rank].push(l),e.successors(l).forEach(i)}return n.sort((l,c)=>e.node(l).rank-e.node(c).rank).forEach(i),a}let tl=S.zipObject;var nl=rl;function rl(e,t){let n=0;for(let r=1;r<t.length;++r)n+=ol(e,t[r-1],t[r]);return n}function ol(e,t,n){let r=tl(n,n.map((c,d)=>d)),o=t.flatMap(c=>e.outEdges(c).map(d=>({pos:r[d.w],weight:e.edge(d).weight})).sort((d,f)=>d.pos-f.pos)),a=1;for(;a<n.length;)a<<=1;let i=2*a-1;a-=1;let s=new Array(i).fill(0),l=0;return o.forEach(c=>{let d=c.pos+a;s[d]+=c.weight;let f=0;for(;d>0;)d%2&&(f+=s[d+1]),d=d-1>>1,s[d]+=c.weight;l+=c.weight*f}),l}var al=il;function il(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let o=r.reduce((a,i)=>{let s=e.edge(i),l=e.node(i.v);return{sum:a.sum+s.weight*l.order,weight:a.weight+s.weight}},{sum:0,weight:0});return{v:n,barycenter:o.sum/o.weight,weight:o.weight}}else return{v:n}})}let sl=S;var ll=cl;function cl(e,t){let n={};e.forEach((o,a)=>{let i=n[o.v]={indegree:0,in:[],out:[],vs:[o.v],i:a};o.barycenter!==void 0&&(i.barycenter=o.barycenter,i.weight=o.weight)}),t.edges().forEach(o=>{let a=n[o.v],i=n[o.w];a!==void 0&&i!==void 0&&(i.indegree++,a.out.push(n[o.w]))});let r=Object.values(n).filter(o=>!o.indegree);return dl(r)}function dl(e){let t=[];function n(o){return a=>{a.merged||(a.barycenter===void 0||o.barycenter===void 0||a.barycenter>=o.barycenter)&&ul(o,a)}}function r(o){return a=>{a.in.push(o),--a.indegree===0&&e.push(a)}}for(;e.length;){let o=e.pop();t.push(o),o.in.reverse().forEach(n(o)),o.out.forEach(r(o))}return t.filter(o=>!o.merged).map(o=>sl.pick(o,["vs","i","barycenter","weight"]))}function ul(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let fl=S;var hl=pl;function pl(e,t){let n=fl.partition(e,d=>Object.hasOwn(d,"barycenter")),r=n.lhs,o=n.rhs.sort((d,f)=>f.i-d.i),a=[],i=0,s=0,l=0;r.sort(ml(!!t)),l=Bt(a,o,l),r.forEach(d=>{l+=d.vs.length,a.push(d.vs),i+=d.barycenter*d.weight,s+=d.weight,l=Bt(a,o,l)});let c={vs:a.flat(!0)};return s&&(c.barycenter=i/s,c.weight=s),c}function Bt(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function ml(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}let gl=al,vl=ll,bl=hl;var wl=hr;function hr(e,t,n,r){let o=e.children(t),a=e.node(t),i=a?a.borderLeft:void 0,s=a?a.borderRight:void 0,l={};i&&(o=o.filter(h=>h!==i&&h!==s));let c=gl(e,o);c.forEach(h=>{if(e.children(h.v).length){let g=hr(e,h.v,n,r);l[h.v]=g,Object.hasOwn(g,"barycenter")&&xl(h,g)}});let d=vl(c,n);yl(d,l);let f=bl(d,r);if(i&&(f.vs=[i,f.vs,s].flat(!0),e.predecessors(i).length)){let h=e.node(e.predecessors(i)[0]),g=e.node(e.predecessors(s)[0]);Object.hasOwn(f,"barycenter")||(f.barycenter=0,f.weight=0),f.barycenter=(f.barycenter*f.weight+h.order+g.order)/(f.weight+2),f.weight+=2}return f}function yl(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function xl(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let El=P.Graph,Nl=S;var kl=Cl;function Cl(e,t,n){let r=_l(e),o=new El({compound:!0}).setGraph({root:r}).setDefaultNodeLabel(a=>e.node(a));return e.nodes().forEach(a=>{let i=e.node(a),s=e.parent(a);(i.rank===t||i.minRank<=t&&t<=i.maxRank)&&(o.setNode(a),o.setParent(a,s||r),e[n](a).forEach(l=>{let c=l.v===a?l.w:l.v,d=o.edge(c,a),f=d!==void 0?d.weight:0;o.setEdge(c,a,{weight:e.edge(l).weight+f})}),Object.hasOwn(i,"minRank")&&o.setNode(a,{borderLeft:i.borderLeft[t],borderRight:i.borderRight[t]}))}),o}function _l(e){for(var t;e.hasNode(t=Nl.uniqueId("_root")););return t}var jl=Sl;function Sl(e,t,n){let r={},o;n.forEach(a=>{let i=e.parent(a),s,l;for(;i;){if(s=e.parent(i),s?(l=r[s],r[s]=i):(l=o,o=i),l&&l!==i){t.setEdge(l,i);return}i=s}})}let Ol=Zs,Il=nl,Rl=wl,Tl=kl,Ll=jl,Dl=P.Graph,ce=S;var Ml=pr;function pr(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,pr);return}let n=ce.maxRank(e),r=zt(e,ce.range(1,n+1),"inEdges"),o=zt(e,ce.range(n-1,-1,-1),"outEdges"),a=Ol(e);if(Ht(e,a),t&&t.disableOptimalOrderHeuristic)return;let i=Number.POSITIVE_INFINITY,s;for(let l=0,c=0;c<4;++l,++c){Pl(l%2?r:o,l%4>=2),a=ce.buildLayerMatrix(e);let d=Il(e,a);d<i&&(c=0,s=Object.assign({},a),i=d)}Ht(e,s)}function zt(e,t,n){return t.map(function(r){return Tl(e,r,n)})}function Pl(e,t){let n=new Dl;e.forEach(function(r){let o=r.graph().root,a=Rl(r,o,n,t);a.vs.forEach((i,s)=>r.node(i).order=s),Ll(r,n,a.vs)})}function Ht(e,t){Object.values(t).forEach(n=>n.forEach((r,o)=>e.node(r).order=o))}let Fl=P.Graph,A=S;var Al={positionX:Vl,findType1Conflicts:mr,findType2Conflicts:gr,addConflict:nt,hasConflict:vr,verticalAlignment:br,horizontalCompaction:wr,alignCoordinates:xr,findSmallestWidthAlignment:yr,balance:Er};function mr(e,t){let n={};function r(o,a){let i=0,s=0,l=o.length,c=a[a.length-1];return a.forEach((d,f)=>{let h=$l(e,d),g=h?e.node(h).order:l;(h||d===c)&&(a.slice(s,f+1).forEach(v=>{e.predecessors(v).forEach(m=>{let b=e.node(m),y=b.order;(y<i||g<y)&&!(b.dummy&&e.node(v).dummy)&&nt(n,m,v)})}),s=f+1,i=g)}),a}return t.length&&t.reduce(r),n}function gr(e,t){let n={};function r(a,i,s,l,c){let d;A.range(i,s).forEach(f=>{d=a[f],e.node(d).dummy&&e.predecessors(d).forEach(h=>{let g=e.node(h);g.dummy&&(g.order<l||g.order>c)&&nt(n,h,d)})})}function o(a,i){let s=-1,l,c=0;return i.forEach((d,f)=>{if(e.node(d).dummy==="border"){let h=e.predecessors(d);h.length&&(l=e.node(h[0]).order,r(i,c,f,s,l),c=f,s=l)}r(i,c,i.length,l,a.length)}),i}return t.length&&t.reduce(o),n}function $l(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function nt(e,t,n){if(t>n){let o=t;t=n,n=o}let r=e[t];r||(e[t]=r={}),r[n]=!0}function vr(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function br(e,t,n,r){let o={},a={},i={};return t.forEach(s=>{s.forEach((l,c)=>{o[l]=l,a[l]=l,i[l]=c})}),t.forEach(s=>{let l=-1;s.forEach(c=>{let d=r(c);if(d.length){d=d.sort((h,g)=>i[h]-i[g]);let f=(d.length-1)/2;for(let h=Math.floor(f),g=Math.ceil(f);h<=g;++h){let v=d[h];a[c]===c&&l<i[v]&&!vr(n,c,v)&&(a[v]=c,a[c]=o[c]=o[v],l=i[v])}}})}),{root:o,align:a}}function wr(e,t,n,r,o){let a={},i=Gl(e,t,n,o),s=o?"borderLeft":"borderRight";function l(f,h){let g=i.nodes(),v=g.pop(),m={};for(;v;)m[v]?f(v):(m[v]=!0,g.push(v),g=g.concat(h(v))),v=g.pop()}function c(f){a[f]=i.inEdges(f).reduce((h,g)=>Math.max(h,a[g.v]+i.edge(g)),0)}function d(f){let h=i.outEdges(f).reduce((v,m)=>Math.min(v,a[m.w]-i.edge(m)),Number.POSITIVE_INFINITY),g=e.node(f);h!==Number.POSITIVE_INFINITY&&g.borderType!==s&&(a[f]=Math.max(a[f],h))}return l(c,i.predecessors.bind(i)),l(d,i.successors.bind(i)),Object.keys(r).forEach(f=>a[f]=a[n[f]]),a}function Gl(e,t,n,r){let o=new Fl,a=e.graph(),i=Wl(a.nodesep,a.edgesep,r);return t.forEach(s=>{let l;s.forEach(c=>{let d=n[c];if(o.setNode(d),l){var f=n[l],h=o.edge(f,d);o.setEdge(f,d,Math.max(i(e,c,l),h||0))}l=c})}),o}function yr(e,t){return Object.values(t).reduce((n,r)=>{let o=Number.NEGATIVE_INFINITY,a=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([s,l])=>{let c=Bl(e,s)/2;o=Math.max(l+c,o),a=Math.min(l-c,a)});const i=o-a;return i<n[0]&&(n=[i,r]),n},[Number.POSITIVE_INFINITY,null])[1]}function xr(e,t){let n=Object.values(t),r=A.applyWithChunking(Math.min,n),o=A.applyWithChunking(Math.max,n);["u","d"].forEach(a=>{["l","r"].forEach(i=>{let s=a+i,l=e[s];if(l===t)return;let c=Object.values(l),d=r-A.applyWithChunking(Math.min,c);i!=="l"&&(d=o-A.applyWithChunking(Math.max,c)),d&&(e[s]=A.mapValues(l,f=>f+d))})})}function Er(e,t){return A.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let o=Object.values(e).map(a=>a[r]).sort((a,i)=>a-i);return(o[1]+o[2])/2}})}function Vl(e){let t=A.buildLayerMatrix(e),n=Object.assign(mr(e,t),gr(e,t)),r={},o;["u","d"].forEach(i=>{o=i==="u"?t:Object.values(t).reverse(),["l","r"].forEach(s=>{s==="r"&&(o=o.map(f=>Object.values(f).reverse()));let l=(i==="u"?e.predecessors:e.successors).bind(e),c=br(e,o,n,l),d=wr(e,o,c.root,c.align,s==="r");s==="r"&&(d=A.mapValues(d,f=>-f)),r[i+s]=d})});let a=yr(e,r);return xr(r,a),Er(r,e.graph().align)}function Wl(e,t,n){return(r,o,a)=>{let i=r.node(o),s=r.node(a),l=0,c;if(l+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":c=-i.width/2;break;case"r":c=i.width/2;break}if(c&&(l+=n?c:-c),c=0,l+=(i.dummy?t:e)/2,l+=(s.dummy?t:e)/2,l+=s.width/2,Object.hasOwn(s,"labelpos"))switch(s.labelpos.toLowerCase()){case"l":c=s.width/2;break;case"r":c=-s.width/2;break}return c&&(l+=n?c:-c),c=0,l}}function Bl(e,t){return e.node(t).width}let Nr=S,zl=Al.positionX;var Hl=Ul;function Ul(e){e=Nr.asNonCompoundGraph(e),Yl(e),Object.entries(zl(e)).forEach(([t,n])=>e.node(t).x=n)}function Yl(e){let t=Nr.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(o=>{const a=o.reduce((i,s)=>{const l=e.node(s).height;return i>l?i:l},0);o.forEach(i=>e.node(i).y=r+a/2),r+=a+n})}let Ut=rs,Yt=ls,Xl=Ts,ql=S.normalizeRanks,Kl=Ps,Ql=S.removeEmptyRanks,Xt=Gs,Jl=Us,qt=Xs,Zl=Ml,ec=Hl,D=S,tc=P.Graph;var nc=rc;function rc(e,t){let n=t&&t.debugTiming?D.time:D.notime;n("layout",()=>{let r=n("  buildLayoutGraph",()=>hc(e));n("  runLayout",()=>oc(r,n,t)),n("  updateInputGraph",()=>ac(e,r))})}function oc(e,t,n){t("    makeSpaceForEdgeLabels",()=>pc(e)),t("    removeSelfEdges",()=>Nc(e)),t("    acyclic",()=>Ut.run(e)),t("    nestingGraph.run",()=>Xt.run(e)),t("    rank",()=>Xl(D.asNonCompoundGraph(e))),t("    injectEdgeLabelProxies",()=>mc(e)),t("    removeEmptyRanks",()=>Ql(e)),t("    nestingGraph.cleanup",()=>Xt.cleanup(e)),t("    normalizeRanks",()=>ql(e)),t("    assignRankMinMax",()=>gc(e)),t("    removeEdgeLabelProxies",()=>vc(e)),t("    normalize.run",()=>Yt.run(e)),t("    parentDummyChains",()=>Kl(e)),t("    addBorderSegments",()=>Jl(e)),t("    order",()=>Zl(e,n)),t("    insertSelfEdges",()=>kc(e)),t("    adjustCoordinateSystem",()=>qt.adjust(e)),t("    position",()=>ec(e)),t("    positionSelfEdges",()=>Cc(e)),t("    removeBorderNodes",()=>Ec(e)),t("    normalize.undo",()=>Yt.undo(e)),t("    fixupEdgeLabelCoords",()=>yc(e)),t("    undoCoordinateSystem",()=>qt.undo(e)),t("    translateGraph",()=>bc(e)),t("    assignNodeIntersects",()=>wc(e)),t("    reversePoints",()=>xc(e)),t("    acyclic.undo",()=>Ut.undo(e))}function ac(e,t){e.nodes().forEach(n=>{let r=e.node(n),o=t.node(n);r&&(r.x=o.x,r.y=o.y,r.rank=o.rank,t.children(n).length&&(r.width=o.width,r.height=o.height))}),e.edges().forEach(n=>{let r=e.edge(n),o=t.edge(n);r.points=o.points,Object.hasOwn(o,"x")&&(r.x=o.x,r.y=o.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ic=["nodesep","edgesep","ranksep","marginx","marginy"],sc={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},lc=["acyclicer","ranker","rankdir","align"],cc=["width","height"],Kt={width:0,height:0},dc=["minlen","weight","width","height","labeloffset"],uc={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},fc=["labelpos"];function hc(e){let t=new tc({multigraph:!0,compound:!0}),n=Ae(e.graph());return t.setGraph(Object.assign({},sc,Fe(n,ic),D.pick(n,lc))),e.nodes().forEach(r=>{let o=Ae(e.node(r));const a=Fe(o,cc);Object.keys(Kt).forEach(i=>{a[i]===void 0&&(a[i]=Kt[i])}),t.setNode(r,a),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let o=Ae(e.edge(r));t.setEdge(r,Object.assign({},uc,Fe(o,dc),D.pick(o,fc)))}),t}function pc(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function mc(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),a={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};D.addDummyNode(e,"edge-proxy",a,"_ep")}})}function gc(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function vc(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function bc(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,o=0,a=e.graph(),i=a.marginx||0,s=a.marginy||0;function l(c){let d=c.x,f=c.y,h=c.width,g=c.height;t=Math.min(t,d-h/2),n=Math.max(n,d+h/2),r=Math.min(r,f-g/2),o=Math.max(o,f+g/2)}e.nodes().forEach(c=>l(e.node(c))),e.edges().forEach(c=>{let d=e.edge(c);Object.hasOwn(d,"x")&&l(d)}),t-=i,r-=s,e.nodes().forEach(c=>{let d=e.node(c);d.x-=t,d.y-=r}),e.edges().forEach(c=>{let d=e.edge(c);d.points.forEach(f=>{f.x-=t,f.y-=r}),Object.hasOwn(d,"x")&&(d.x-=t),Object.hasOwn(d,"y")&&(d.y-=r)}),a.width=n-t+i,a.height=o-r+s}function wc(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),o=e.node(t.w),a,i;n.points?(a=n.points[0],i=n.points[n.points.length-1]):(n.points=[],a=o,i=r),n.points.unshift(D.intersectRect(r,a)),n.points.push(D.intersectRect(o,i))})}function yc(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function xc(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Ec(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),o=e.node(n.borderBottom),a=e.node(n.borderLeft[n.borderLeft.length-1]),i=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(i.x-a.x),n.height=Math.abs(o.y-r.y),n.x=a.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function Nc(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function kc(e){var t=D.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((o,a)=>{var i=e.node(o);i.order=a+r,(i.selfEdges||[]).forEach(s=>{D.addDummyNode(e,"selfedge",{width:s.label.width,height:s.label.height,rank:i.rank,order:a+ ++r,e:s.e,label:s.label},"_se")}),delete i.selfEdges})})}function Cc(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),o=r.x+r.width/2,a=r.y,i=n.x-o,s=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:o+2*i/3,y:a-s},{x:o+5*i/6,y:a-s},{x:o+i,y:a},{x:o+5*i/6,y:a+s},{x:o+2*i/3,y:a+s}],n.label.x=n.x,n.label.y=n.y}})}function Fe(e,t){return D.mapValues(D.pick(e,t),Number)}function Ae(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let _c=S,jc=P.Graph;var Sc={debugOrdering:Oc};function Oc(e){let t=_c.buildLayerMatrix(e),n=new jc({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,o)=>{let a="layer"+o;n.setNode(a,{rank:"same"}),r.reduce((i,s)=>(n.setEdge(i,s,{style:"invis"}),s))}),n}var Ic="1.1.4",Rc={graphlib:P,layout:nc,debug:Sc,util:{time:S.time,notime:S.notime},version:Ic};const kr=$r(Rc),ee=new kr.graphlib.Graph().setDefaultEdgeLabel(()=>({})),Tc=(e,t,n="TB")=>{const r=n==="LR";return ee.setGraph({rankdir:n}),e.forEach(a=>{const{width:i=300,height:s=200}=a.measured??{};ee.setNode(a.id,{width:i,height:s})}),t.forEach(a=>{ee.setEdge(a.source,a.target)}),kr.layout(ee),{nodes:e.map(a=>{const{width:i=300,height:s=200}=a.measured??{},l=ee.node(a.id);return{...a,targetPosition:r?"left":"top",sourcePosition:r?"right":"bottom",position:{x:l.x-i/2,y:l.y-s/2}}}),edges:t}};function Lc(e,t){const[n,r]=p.useState(e);return p.useEffect(()=>{const o=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(o)}},[e,t]),n}const Cr=p.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:O("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Cr.displayName="Card";const _r=p.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:O("flex flex-col space-y-1.5 p-6",e),...t}));_r.displayName="CardHeader";const Dc=p.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:O("text-2xl font-semibold leading-none tracking-tight",e),...t}));Dc.displayName="CardTitle";const Mc=p.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:O("text-sm text-muted-foreground",e),...t}));Mc.displayName="CardDescription";const jr=p.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:O("p-6 pt-0",e),...t}));jr.displayName="CardContent";const Pc=p.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:O("flex items-center p-6 pt-0",e),...t}));Pc.displayName="CardFooter";const Sr=p.forwardRef((e,t)=>u.jsx("div",{ref:t,className:O("text-xs rounded-lg bg-zinc-800 px-2 py-1 font-semibold",e.className),...e}));Sr.displayName="Tag";function Fc({showSearch:e}){const{addNode:t,setShowSearch:n,addEdge:r}=V(U(h=>({addNode:h.addNode,setShowSearch:h.setShowSearch,addEdge:h.addEdge}))),[o,a]=p.useState(""),i=Lc(o,300),[s,l]=p.useState([]),[c,d]=p.useState(!1);p.useEffect(()=>{d(!0),Ge("/search_functions?query="+encodeURIComponent(i)).then(h=>h.json()).then(h=>{l(h)}).finally(()=>d(!1))},[i]);const f=h=>{var b,y,k,N,x,E,L,C;const g=t({data:h,position:{x:e.mouseX,y:e.mouseY},type:"astFunction"}),v=((y=(b=g.data.input)==null?void 0:b.filter(w=>{var _;return w.type===((_=e.connectFrom)==null?void 0:_.handleType)&&!w.hide_handle}))==null?void 0:y[0])??((N=(k=g.data.input)==null?void 0:k.filter(w=>!w.hide_handle))==null?void 0:N[0]),m=((E=(x=g.data.output)==null?void 0:x.filter(w=>{var _;return w.type===((_=e.connectFrom)==null?void 0:_.handleType)&&!w.hide_handle}))==null?void 0:E[0])??((C=(L=g.data.output)==null?void 0:L.filter(w=>!w.hide_handle))==null?void 0:C[0]);if(e.connectFrom){const w={source:e.connectFrom.source??g.id,target:e.connectFrom.target??g.id,sourceHandle:e.connectFrom.sourceHandle??(m==null?void 0:m.id)??We,targetHandle:e.connectFrom.targetHandle??(v==null?void 0:v.id)??We};console.log("adding edge",w),r({id:w.source+"_"+w.target+"_"+w.sourceHandle+"_"+w.targetHandle,...w})}n(null)};return u.jsxs(Cr,{className:"sm:w-[60vw] w-[90vw] max-w-[700px]",style:{position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%)"},children:[u.jsxs(_r,{className:"p-2 text-lg mb-2 relative",children:[u.jsx(Ue,{placeholder:"Search for functions and nodes",autoFocus:!0,value:o,onChange:h=>a(h.target.value)}),c&&u.jsx(nn,{className:"w-4 h-4 absolute top-2 right-2"})]}),u.jsxs(jr,{className:"h-[60vh] overflow-y-auto px-3",children:[u.jsx(R,{className:"",children:s.map((h,g)=>h&&u.jsxs(T,{className:"justify-between flex-wrap hover:bg-muted py-2 cursor-pointer",onClick:()=>f(h),children:[u.jsx("p",{children:h.name}),u.jsxs(T,{className:"gap-2",children:[u.jsx("p",{className:"text-muted-foreground text-sm",children:h.file_path??h.module}),u.jsx(Sr,{children:h.type})]})]},`${h.type}-${h.name}-${g}`))}),s.length===0&&u.jsx("p",{children:"No results found"})]})]})}function Ac(e,t){const n=p.useRef(null);return p.useCallback((...r)=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{e(...r)},t)},[e,t])}function $c(){const{screenToFlowPosition:e}=Qt(),t=p.useRef(null),n=p.useRef(),r=Ac(o=>{n.current={x:o.clientX,y:o.clientY}},100);p.useEffect(()=>{const o=a=>{var i,s,l;if(!["INPUT","TEXTAREA"].includes(a.target.nodeName)&&(a.ctrlKey||a.metaKey)&&["c","v"].includes(a.key)){const{nodes:c,addNode:d,selectedNodeIDs:f,values:h}=V.getState();if(a.key==="c"){a.preventDefault();const g=c.find(v=>v.id===f[0]);g&&(t.current={...g,selected:!1})}else if(a.key==="v"&&t.current){a.preventDefault();const g=e({x:((i=n.current)==null?void 0:i.x)??t.current.position.x+100,y:((s=n.current)==null?void 0:s.y)??t.current.position.y+100}),v={...t.current,position:g};(l=v.data.input)==null||l.forEach(m=>{m.default=h[I("input",v.id,m.id)]??null}),delete v.id,d(v)}}};return window.addEventListener("keydown",o),document.addEventListener("mousemove",r),()=>{window.removeEventListener("keydown",o),document.removeEventListener("mousemove",r)}},[])}const Gc=e=>({nodes:e.nodes,edges:e.edges,onNodesChange:e.onNodesChange,onEdgesChange:e.onEdgesChange,setJobStatus:e.setJobStatus,onConnect:e.onConnect,addNode:e.addNode,loadGraph:e.loadGraph,setSelectedNodeIDs:e.setSelectedNodeIDs,setNodes:e.setNodes,setEdges:e.setEdges,setShowSearch:e.setShowSearch}),Vc={astFunction:Pa};function Wc(){const{theme:e}=Ur(),{screenToFlowPosition:t}=Qt(),{dropingNode:n,setDropingNode:r}=Yr(),{nodes:o,edges:a,onNodesChange:i,onEdgesChange:s,onConnect:l,addNode:c,loadGraph:d,setSelectedNodeIDs:f,setJobStatus:h,setNodes:g,setEdges:v,setShowSearch:m}=V(U(Gc));$c(),p.useEffect(()=>{const C=new WebSocket(tn.wsUrl);return C.onopen=()=>{console.log("websocket connected")},C.onmessage=w=>{const _=JSON.parse(w.data);window.dispatchEvent(new CustomEvent("message",{detail:_})),console.log("message",_),_.type==="job_status"&&_.data&&h(_.data)},()=>{C.close()}},[]);const b=p.useCallback(C=>{C.preventDefault(),C.dataTransfer.dropEffect="move"},[]),y=p.useRef(0),k=p.useRef(0),N=p.useCallback(C=>{if(C.preventDefault(),!n)return;const w=t({x:C.clientX,y:C.clientY});c({data:n,position:w,type:"astFunction"}),r(null)},[t,n]),x=p.useCallback(C=>{const w=t({x:C.clientX,y:C.clientY});f([]);const _=Date.now();y.current&&_-y.current<300?m({mouseX:w.x,mouseY:w.y}):_-k.current>300&&m(null),y.current=_},[]),E=p.useCallback((C,w)=>{var rt,ot,at,it,st,lt,ct,dt,ut,ft,ht,pt,mt,gt;if(k.current=Date.now(),w.isValid)return;if(!((rt=w.to)!=null&&rt.x)||!((ot=w.to)!=null&&ot.x))throw new Error("onConnectEnd No position found!");const _=t({x:(at=w.to)==null?void 0:at.x,y:(it=w.to)==null?void 0:it.y}),Ee=(st=w.fromNode)==null?void 0:st.data,Ne=(lt=w.toNode)==null?void 0:lt.data,Or=(dt=(ct=Ee==null?void 0:Ee.output)==null?void 0:ct.find(ke=>{var Z;return ke.id===((Z=w.fromHandle)==null?void 0:Z.id)}))==null?void 0:dt.type,Ir=(ft=(ut=Ne==null?void 0:Ne.input)==null?void 0:ut.find(ke=>{var Z;return ke.id===((Z=w.toHandle)==null?void 0:Z.id)}))==null?void 0:ft.type;console.log("onconnectend",w),m({mouseX:_.x,mouseY:_.y,connectFrom:{source:(ht=w.fromNode)==null?void 0:ht.id,sourceHandle:((pt=w.fromHandle)==null?void 0:pt.id)??void 0,target:(mt=w.toNode)==null?void 0:mt.id,targetHandle:((gt=w.toHandle)==null?void 0:gt.id)??void 0,handleType:Or??Ir}})},[]),L=C=>{const{nodes:w,edges:_}=Tc(o,a,C);g([...w]),v([..._])};return u.jsxs(Mr,{nodes:o,nodeTypes:Vc,edges:a,colorMode:e,onNodesChange:i,onEdgesChange:s,onDrop:N,onDragOver:b,onConnect:l,fitView:!0,fitViewOptions:{padding:.2},defaultEdgeOptions:{style:{strokeWidth:2,stroke:"#9049CF"}},onNodeClick:(C,w)=>{f([w.id])},onPaneClick:x,onConnectEnd:E,zoomOnDoubleClick:!1,children:[u.jsx(Pr,{}),u.jsxs(Fr,{orientation:"horizontal",children:[u.jsx(oe,{onClick:bt.undo,title:"Undo",children:u.jsx(Kr,{size:16,className:"!fill-[none] !max-w-4 !max-h-4"})}),u.jsx(oe,{onClick:bt.redo,title:"Redo",children:u.jsx(Qr,{size:16,className:"!fill-[none] !max-w-4 !max-h-4"})}),u.jsx(oe,{onClick:()=>L("LR"),title:"Layout nodes horizontally",children:u.jsx(wt,{size:16,className:"!fill-[none] !max-w-4 !max-h-4"})}),u.jsx(oe,{onClick:()=>L("TB"),title:"Layout nodes vertically",children:u.jsx(wt,{size:16,className:"!fill-[none] !max-w-4 !max-h-4 rotate-90"})})]})]})}function ed(){const{showSearch:e}=V(U(t=>({showSearch:t.showSearch})));return u.jsxs(Dr,{children:[u.jsx(Wc,{}),e&&u.jsx(Fc,{showSearch:e})]})}export{Wc as FlowCanvas,ed as default};
