agent-dag 1.33.95 → 1.33.96

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.
@@ -56,7 +56,7 @@ Error generating stack: `+w.message+`
56
56
  */var cw;function wR(){if(cw)return Jc;cw=1;var e=oa(),n=yR();function r(h,f){return h===f&&(h!==0||1/h===1/f)||h!==h&&f!==f}var s=typeof Object.is=="function"?Object.is:r,o=n.useSyncExternalStore,l=e.useRef,u=e.useEffect,c=e.useMemo,p=e.useDebugValue;return Jc.useSyncExternalStoreWithSelector=function(h,f,m,y,x){var C=l(null);if(C.current===null){var _={hasValue:!1,value:null};C.current=_}else _=C.current;C=c(function(){function b(M){if(!E){if(E=!0,N=M,M=y(M),x!==void 0&&_.hasValue){var O=_.value;if(x(O,M))return T=O}return T=M}if(O=T,s(N,M))return O;var H=y(M);return x!==void 0&&x(O,H)?(N=M,O):(N=M,T=H)}var E=!1,N,T,I=m===void 0?null:m;return[function(){return b(f())},I===null?void 0:function(){return b(I())}]},[f,m,y,x]);var S=o(h,C[0],C[1]);return u(function(){_.hasValue=!0,_.value=S},[S]),p(S),S},Jc}var dw;function xR(){return dw||(dw=1,Zc.exports=wR()),Zc.exports}var _R=xR();const SR=nv(_R),bR={},fw=e=>{let n;const r=new Set,s=(f,m)=>{const y=typeof f=="function"?f(n):f;if(!Object.is(y,n)){const x=n;n=m??(typeof y!="object"||y===null)?y:Object.assign({},n,y),r.forEach(C=>C(n,x))}},o=()=>n,p={setState:s,getState:o,getInitialState:()=>h,subscribe:f=>(r.add(f),()=>r.delete(f)),destroy:()=>{(bR?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),r.clear()}},h=n=e(s,o,p);return p},kR=e=>e?fw(e):fw,{useDebugValue:ER}=le,{useSyncExternalStoreWithSelector:NR}=SR,CR=e=>e;function Xk(e,n=CR,r){const s=NR(e.subscribe,e.getState,e.getServerState||e.getInitialState,n,r);return ER(s),s}const hw=(e,n)=>{const r=kR(e),s=(o,l=n)=>Xk(r,o,l);return Object.assign(s,r),s},TR=(e,n)=>e?hw(e,n):hw;function kt(e,n){if(Object.is(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;if(e instanceof Map&&n instanceof Map){if(e.size!==n.size)return!1;for(const[s,o]of e)if(!Object.is(o,n.get(s)))return!1;return!0}if(e instanceof Set&&n instanceof Set){if(e.size!==n.size)return!1;for(const s of e)if(!n.has(s))return!1;return!0}const r=Object.keys(e);if(r.length!==Object.keys(n).length)return!1;for(const s of r)if(!Object.prototype.hasOwnProperty.call(n,s)||!Object.is(e[s],n[s]))return!1;return!0}var RR={value:()=>{}};function Ql(){for(var e=0,n=arguments.length,r={},s;e<n;++e){if(!(s=arguments[e]+"")||s in r||/[\s.]/.test(s))throw new Error("illegal type: "+s);r[s]=[]}return new Pl(r)}function Pl(e){this._=e}function jR(e,n){return e.trim().split(/^|\s+/).map(function(r){var s="",o=r.indexOf(".");if(o>=0&&(s=r.slice(o+1),r=r.slice(0,o)),r&&!n.hasOwnProperty(r))throw new Error("unknown type: "+r);return{type:r,name:s}})}Pl.prototype=Ql.prototype={constructor:Pl,on:function(e,n){var r=this._,s=jR(e+"",r),o,l=-1,u=s.length;if(arguments.length<2){for(;++l<u;)if((o=(e=s[l]).type)&&(o=AR(r[o],e.name)))return o;return}if(n!=null&&typeof n!="function")throw new Error("invalid callback: "+n);for(;++l<u;)if(o=(e=s[l]).type)r[o]=pw(r[o],e.name,n);else if(n==null)for(o in r)r[o]=pw(r[o],e.name,null);return this},copy:function(){var e={},n=this._;for(var r in n)e[r]=n[r].slice();return new Pl(e)},call:function(e,n){if((o=arguments.length-2)>0)for(var r=new Array(o),s=0,o,l;s<o;++s)r[s]=arguments[s+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(l=this._[e],s=0,o=l.length;s<o;++s)l[s].value.apply(n,r)},apply:function(e,n,r){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var s=this._[e],o=0,l=s.length;o<l;++o)s[o].value.apply(n,r)}};function AR(e,n){for(var r=0,s=e.length,o;r<s;++r)if((o=e[r]).name===n)return o.value}function pw(e,n,r){for(var s=0,o=e.length;s<o;++s)if(e[s].name===n){e[s]=RR,e=e.slice(0,s).concat(e.slice(s+1));break}return r!=null&&e.push({name:n,value:r}),e}var Mg="http://www.w3.org/1999/xhtml";const mw={svg:"http://www.w3.org/2000/svg",xhtml:Mg,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Zl(e){var n=e+="",r=n.indexOf(":");return r>=0&&(n=e.slice(0,r))!=="xmlns"&&(e=e.slice(r+1)),mw.hasOwnProperty(n)?{space:mw[n],local:e}:e}function IR(e){return function(){var n=this.ownerDocument,r=this.namespaceURI;return r===Mg&&n.documentElement.namespaceURI===Mg?n.createElement(e):n.createElementNS(r,e)}}function MR(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Qk(e){var n=Zl(e);return(n.local?MR:IR)(n)}function PR(){}function rv(e){return e==null?PR:function(){return this.querySelector(e)}}function OR(e){typeof e!="function"&&(e=rv(e));for(var n=this._groups,r=n.length,s=new Array(r),o=0;o<r;++o)for(var l=n[o],u=l.length,c=s[o]=new Array(u),p,h,f=0;f<u;++f)(p=l[f])&&(h=e.call(p,p.__data__,f,l))&&("__data__"in p&&(h.__data__=p.__data__),c[f]=h);return new gn(s,this._parents)}function LR(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function qR(){return[]}function Zk(e){return e==null?qR:function(){return this.querySelectorAll(e)}}function $R(e){return function(){return LR(e.apply(this,arguments))}}function DR(e){typeof e=="function"?e=$R(e):e=Zk(e);for(var n=this._groups,r=n.length,s=[],o=[],l=0;l<r;++l)for(var u=n[l],c=u.length,p,h=0;h<c;++h)(p=u[h])&&(s.push(e.call(p,p.__data__,h,u)),o.push(p));return new gn(s,o)}function Jk(e){return function(){return this.matches(e)}}function eE(e){return function(n){return n.matches(e)}}var FR=Array.prototype.find;function zR(e){return function(){return FR.call(this.children,e)}}function BR(){return this.firstElementChild}function UR(e){return this.select(e==null?BR:zR(typeof e=="function"?e:eE(e)))}var HR=Array.prototype.filter;function WR(){return Array.from(this.children)}function VR(e){return function(){return HR.call(this.children,e)}}function GR(e){return this.selectAll(e==null?WR:VR(typeof e=="function"?e:eE(e)))}function YR(e){typeof e!="function"&&(e=Jk(e));for(var n=this._groups,r=n.length,s=new Array(r),o=0;o<r;++o)for(var l=n[o],u=l.length,c=s[o]=[],p,h=0;h<u;++h)(p=l[h])&&e.call(p,p.__data__,h,l)&&c.push(p);return new gn(s,this._parents)}function tE(e){return new Array(e.length)}function KR(){return new gn(this._enter||this._groups.map(tE),this._parents)}function $l(e,n){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=n}$l.prototype={constructor:$l,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,n){return this._parent.insertBefore(e,n)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function XR(e){return function(){return e}}function QR(e,n,r,s,o,l){for(var u=0,c,p=n.length,h=l.length;u<h;++u)(c=n[u])?(c.__data__=l[u],s[u]=c):r[u]=new $l(e,l[u]);for(;u<p;++u)(c=n[u])&&(o[u]=c)}function ZR(e,n,r,s,o,l,u){var c,p,h=new Map,f=n.length,m=l.length,y=new Array(f),x;for(c=0;c<f;++c)(p=n[c])&&(y[c]=x=u.call(p,p.__data__,c,n)+"",h.has(x)?o[c]=p:h.set(x,p));for(c=0;c<m;++c)x=u.call(e,l[c],c,l)+"",(p=h.get(x))?(s[c]=p,p.__data__=l[c],h.delete(x)):r[c]=new $l(e,l[c]);for(c=0;c<f;++c)(p=n[c])&&h.get(y[c])===p&&(o[c]=p)}function JR(e){return e.__data__}function ej(e,n){if(!arguments.length)return Array.from(this,JR);var r=n?ZR:QR,s=this._parents,o=this._groups;typeof e!="function"&&(e=XR(e));for(var l=o.length,u=new Array(l),c=new Array(l),p=new Array(l),h=0;h<l;++h){var f=s[h],m=o[h],y=m.length,x=tj(e.call(f,f&&f.__data__,h,s)),C=x.length,_=c[h]=new Array(C),S=u[h]=new Array(C),b=p[h]=new Array(y);r(f,m,_,S,b,x,n);for(var E=0,N=0,T,I;E<C;++E)if(T=_[E]){for(E>=N&&(N=E+1);!(I=S[N])&&++N<C;);T._next=I||null}}return u=new gn(u,s),u._enter=c,u._exit=p,u}function tj(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function nj(){return new gn(this._exit||this._groups.map(tE),this._parents)}function rj(e,n,r){var s=this.enter(),o=this,l=this.exit();return typeof e=="function"?(s=e(s),s&&(s=s.selection())):s=s.append(e+""),n!=null&&(o=n(o),o&&(o=o.selection())),r==null?l.remove():r(l),s&&o?s.merge(o).order():o}function ij(e){for(var n=e.selection?e.selection():e,r=this._groups,s=n._groups,o=r.length,l=s.length,u=Math.min(o,l),c=new Array(o),p=0;p<u;++p)for(var h=r[p],f=s[p],m=h.length,y=c[p]=new Array(m),x,C=0;C<m;++C)(x=h[C]||f[C])&&(y[C]=x);for(;p<o;++p)c[p]=r[p];return new gn(c,this._parents)}function sj(){for(var e=this._groups,n=-1,r=e.length;++n<r;)for(var s=e[n],o=s.length-1,l=s[o],u;--o>=0;)(u=s[o])&&(l&&u.compareDocumentPosition(l)^4&&l.parentNode.insertBefore(u,l),l=u);return this}function oj(e){e||(e=aj);function n(m,y){return m&&y?e(m.__data__,y.__data__):!m-!y}for(var r=this._groups,s=r.length,o=new Array(s),l=0;l<s;++l){for(var u=r[l],c=u.length,p=o[l]=new Array(c),h,f=0;f<c;++f)(h=u[f])&&(p[f]=h);p.sort(n)}return new gn(o,this._parents).order()}function aj(e,n){return e<n?-1:e>n?1:e>=n?0:NaN}function lj(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function uj(){return Array.from(this)}function cj(){for(var e=this._groups,n=0,r=e.length;n<r;++n)for(var s=e[n],o=0,l=s.length;o<l;++o){var u=s[o];if(u)return u}return null}function dj(){let e=0;for(const n of this)++e;return e}function fj(){return!this.node()}function hj(e){for(var n=this._groups,r=0,s=n.length;r<s;++r)for(var o=n[r],l=0,u=o.length,c;l<u;++l)(c=o[l])&&e.call(c,c.__data__,l,o);return this}function pj(e){return function(){this.removeAttribute(e)}}function mj(e){return function(){this.removeAttributeNS(e.space,e.local)}}function gj(e,n){return function(){this.setAttribute(e,n)}}function vj(e,n){return function(){this.setAttributeNS(e.space,e.local,n)}}function yj(e,n){return function(){var r=n.apply(this,arguments);r==null?this.removeAttribute(e):this.setAttribute(e,r)}}function wj(e,n){return function(){var r=n.apply(this,arguments);r==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,r)}}function xj(e,n){var r=Zl(e);if(arguments.length<2){var s=this.node();return r.local?s.getAttributeNS(r.space,r.local):s.getAttribute(r)}return this.each((n==null?r.local?mj:pj:typeof n=="function"?r.local?wj:yj:r.local?vj:gj)(r,n))}function nE(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function _j(e){return function(){this.style.removeProperty(e)}}function Sj(e,n,r){return function(){this.style.setProperty(e,n,r)}}function bj(e,n,r){return function(){var s=n.apply(this,arguments);s==null?this.style.removeProperty(e):this.style.setProperty(e,s,r)}}function kj(e,n,r){return arguments.length>1?this.each((n==null?_j:typeof n=="function"?bj:Sj)(e,n,r??"")):Ks(this.node(),e)}function Ks(e,n){return e.style.getPropertyValue(n)||nE(e).getComputedStyle(e,null).getPropertyValue(n)}function Ej(e){return function(){delete this[e]}}function Nj(e,n){return function(){this[e]=n}}function Cj(e,n){return function(){var r=n.apply(this,arguments);r==null?delete this[e]:this[e]=r}}function Tj(e,n){return arguments.length>1?this.each((n==null?Ej:typeof n=="function"?Cj:Nj)(e,n)):this.node()[e]}function rE(e){return e.trim().split(/^|\s+/)}function iv(e){return e.classList||new iE(e)}function iE(e){this._node=e,this._names=rE(e.getAttribute("class")||"")}iE.prototype={add:function(e){var n=this._names.indexOf(e);n<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var n=this._names.indexOf(e);n>=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function sE(e,n){for(var r=iv(e),s=-1,o=n.length;++s<o;)r.add(n[s])}function oE(e,n){for(var r=iv(e),s=-1,o=n.length;++s<o;)r.remove(n[s])}function Rj(e){return function(){sE(this,e)}}function jj(e){return function(){oE(this,e)}}function Aj(e,n){return function(){(n.apply(this,arguments)?sE:oE)(this,e)}}function Ij(e,n){var r=rE(e+"");if(arguments.length<2){for(var s=iv(this.node()),o=-1,l=r.length;++o<l;)if(!s.contains(r[o]))return!1;return!0}return this.each((typeof n=="function"?Aj:n?Rj:jj)(r,n))}function Mj(){this.textContent=""}function Pj(e){return function(){this.textContent=e}}function Oj(e){return function(){var n=e.apply(this,arguments);this.textContent=n??""}}function Lj(e){return arguments.length?this.each(e==null?Mj:(typeof e=="function"?Oj:Pj)(e)):this.node().textContent}function qj(){this.innerHTML=""}function $j(e){return function(){this.innerHTML=e}}function Dj(e){return function(){var n=e.apply(this,arguments);this.innerHTML=n??""}}function Fj(e){return arguments.length?this.each(e==null?qj:(typeof e=="function"?Dj:$j)(e)):this.node().innerHTML}function zj(){this.nextSibling&&this.parentNode.appendChild(this)}function Bj(){return this.each(zj)}function Uj(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Hj(){return this.each(Uj)}function Wj(e){var n=typeof e=="function"?e:Qk(e);return this.select(function(){return this.appendChild(n.apply(this,arguments))})}function Vj(){return null}function Gj(e,n){var r=typeof e=="function"?e:Qk(e),s=n==null?Vj:typeof n=="function"?n:rv(n);return this.select(function(){return this.insertBefore(r.apply(this,arguments),s.apply(this,arguments)||null)})}function Yj(){var e=this.parentNode;e&&e.removeChild(this)}function Kj(){return this.each(Yj)}function Xj(){var e=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function Qj(){var e=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function Zj(e){return this.select(e?Qj:Xj)}function Jj(e){return arguments.length?this.property("__data__",e):this.node().__data__}function e2(e){return function(n){e.call(this,n,this.__data__)}}function t2(e){return e.trim().split(/^|\s+/).map(function(n){var r="",s=n.indexOf(".");return s>=0&&(r=n.slice(s+1),n=n.slice(0,s)),{type:n,name:r}})}function n2(e){return function(){var n=this.__on;if(n){for(var r=0,s=-1,o=n.length,l;r<o;++r)l=n[r],(!e.type||l.type===e.type)&&l.name===e.name?this.removeEventListener(l.type,l.listener,l.options):n[++s]=l;++s?n.length=s:delete this.__on}}}function r2(e,n,r){return function(){var s=this.__on,o,l=e2(n);if(s){for(var u=0,c=s.length;u<c;++u)if((o=s[u]).type===e.type&&o.name===e.name){this.removeEventListener(o.type,o.listener,o.options),this.addEventListener(o.type,o.listener=l,o.options=r),o.value=n;return}}this.addEventListener(e.type,l,r),o={type:e.type,name:e.name,value:n,listener:l,options:r},s?s.push(o):this.__on=[o]}}function i2(e,n,r){var s=t2(e+""),o,l=s.length,u;if(arguments.length<2){var c=this.node().__on;if(c){for(var p=0,h=c.length,f;p<h;++p)for(o=0,f=c[p];o<l;++o)if((u=s[o]).type===f.type&&u.name===f.name)return f.value}return}for(c=n?r2:n2,o=0;o<l;++o)this.each(c(s[o],n,r));return this}function aE(e,n,r){var s=nE(e),o=s.CustomEvent;typeof o=="function"?o=new o(n,r):(o=s.document.createEvent("Event"),r?(o.initEvent(n,r.bubbles,r.cancelable),o.detail=r.detail):o.initEvent(n,!1,!1)),e.dispatchEvent(o)}function s2(e,n){return function(){return aE(this,e,n)}}function o2(e,n){return function(){return aE(this,e,n.apply(this,arguments))}}function a2(e,n){return this.each((typeof n=="function"?o2:s2)(e,n))}function*l2(){for(var e=this._groups,n=0,r=e.length;n<r;++n)for(var s=e[n],o=0,l=s.length,u;o<l;++o)(u=s[o])&&(yield u)}var lE=[null];function gn(e,n){this._groups=e,this._parents=n}function aa(){return new gn([[document.documentElement]],lE)}function u2(){return this}gn.prototype=aa.prototype={constructor:gn,select:OR,selectAll:DR,selectChild:UR,selectChildren:GR,filter:YR,data:ej,enter:KR,exit:nj,join:rj,merge:ij,selection:u2,order:sj,sort:oj,call:lj,nodes:uj,node:cj,size:dj,empty:fj,each:hj,attr:xj,style:kj,property:Tj,classed:Ij,text:Lj,html:Fj,raise:Bj,lower:Hj,append:Wj,insert:Gj,remove:Kj,clone:Zj,datum:Jj,on:i2,dispatch:a2,[Symbol.iterator]:l2};function Tn(e){return typeof e=="string"?new gn([[document.querySelector(e)]],[document.documentElement]):new gn([[e]],lE)}function c2(e){let n;for(;n=e.sourceEvent;)e=n;return e}function Xn(e,n){if(e=c2(e),n===void 0&&(n=e.currentTarget),n){var r=n.ownerSVGElement||n;if(r.createSVGPoint){var s=r.createSVGPoint();return s.x=e.clientX,s.y=e.clientY,s=s.matrixTransform(n.getScreenCTM().inverse()),[s.x,s.y]}if(n.getBoundingClientRect){var o=n.getBoundingClientRect();return[e.clientX-o.left-n.clientLeft,e.clientY-o.top-n.clientTop]}}return[e.pageX,e.pageY]}const d2={passive:!1},Xo={capture:!0,passive:!1};function nd(e){e.stopImmediatePropagation()}function Ws(e){e.preventDefault(),e.stopImmediatePropagation()}function uE(e){var n=e.document.documentElement,r=Tn(e).on("dragstart.drag",Ws,Xo);"onselectstart"in n?r.on("selectstart.drag",Ws,Xo):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function cE(e,n){var r=e.document.documentElement,s=Tn(e).on("dragstart.drag",null);n&&(s.on("click.drag",Ws,Xo),setTimeout(function(){s.on("click.drag",null)},0)),"onselectstart"in r?s.on("selectstart.drag",null):(r.style.MozUserSelect=r.__noselect,delete r.__noselect)}const yl=e=>()=>e;function Pg(e,{sourceEvent:n,subject:r,target:s,identifier:o,active:l,x:u,y:c,dx:p,dy:h,dispatch:f}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},subject:{value:r,enumerable:!0,configurable:!0},target:{value:s,enumerable:!0,configurable:!0},identifier:{value:o,enumerable:!0,configurable:!0},active:{value:l,enumerable:!0,configurable:!0},x:{value:u,enumerable:!0,configurable:!0},y:{value:c,enumerable:!0,configurable:!0},dx:{value:p,enumerable:!0,configurable:!0},dy:{value:h,enumerable:!0,configurable:!0},_:{value:f}})}Pg.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function f2(e){return!e.ctrlKey&&!e.button}function h2(){return this.parentNode}function p2(e,n){return n??{x:e.x,y:e.y}}function m2(){return navigator.maxTouchPoints||"ontouchstart"in this}function g2(){var e=f2,n=h2,r=p2,s=m2,o={},l=Ql("start","drag","end"),u=0,c,p,h,f,m=0;function y(T){T.on("mousedown.drag",x).filter(s).on("touchstart.drag",S).on("touchmove.drag",b,d2).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function x(T,I){if(!(f||!e.call(this,T,I))){var M=N(this,n.call(this,T,I),T,I,"mouse");M&&(Tn(T.view).on("mousemove.drag",C,Xo).on("mouseup.drag",_,Xo),uE(T.view),nd(T),h=!1,c=T.clientX,p=T.clientY,M("start",T))}}function C(T){if(Ws(T),!h){var I=T.clientX-c,M=T.clientY-p;h=I*I+M*M>m}o.mouse("drag",T)}function _(T){Tn(T.view).on("mousemove.drag mouseup.drag",null),cE(T.view,h),Ws(T),o.mouse("end",T)}function S(T,I){if(e.call(this,T,I)){var M=T.changedTouches,O=n.call(this,T,I),H=M.length,L,P;for(L=0;L<H;++L)(P=N(this,O,T,I,M[L].identifier,M[L]))&&(nd(T),P("start",T,M[L]))}}function b(T){var I=T.changedTouches,M=I.length,O,H;for(O=0;O<M;++O)(H=o[I[O].identifier])&&(Ws(T),H("drag",T,I[O]))}function E(T){var I=T.changedTouches,M=I.length,O,H;for(f&&clearTimeout(f),f=setTimeout(function(){f=null},500),O=0;O<M;++O)(H=o[I[O].identifier])&&(nd(T),H("end",T,I[O]))}function N(T,I,M,O,H,L){var P=l.copy(),q=Xn(L||M,I),W,B,j;if((j=r.call(T,new Pg("beforestart",{sourceEvent:M,target:y,identifier:H,active:u,x:q[0],y:q[1],dx:0,dy:0,dispatch:P}),O))!=null)return W=j.x-q[0]||0,B=j.y-q[1]||0,function K(U,ee,J){var F=q,Y;switch(U){case"start":o[H]=K,Y=u++;break;case"end":delete o[H],--u;case"drag":q=Xn(J||ee,I),Y=u;break}P.call(U,T,new Pg(U,{sourceEvent:ee,subject:j,target:y,identifier:H,active:Y,x:q[0]+W,y:q[1]+B,dx:q[0]-F[0],dy:q[1]-F[1],dispatch:P}),O)}}return y.filter=function(T){return arguments.length?(e=typeof T=="function"?T:yl(!!T),y):e},y.container=function(T){return arguments.length?(n=typeof T=="function"?T:yl(T),y):n},y.subject=function(T){return arguments.length?(r=typeof T=="function"?T:yl(T),y):r},y.touchable=function(T){return arguments.length?(s=typeof T=="function"?T:yl(!!T),y):s},y.on=function(){var T=l.on.apply(l,arguments);return T===l?y:T},y.clickDistance=function(T){return arguments.length?(m=(T=+T)*T,y):Math.sqrt(m)},y}function sv(e,n,r){e.prototype=n.prototype=r,r.constructor=e}function dE(e,n){var r=Object.create(e.prototype);for(var s in n)r[s]=n[s];return r}function la(){}var Qo=.7,Dl=1/Qo,Vs="\\s*([+-]?\\d+)\\s*",Zo="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",dr="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",v2=/^#([0-9a-f]{3,8})$/,y2=new RegExp(`^rgb\\(${Vs},${Vs},${Vs}\\)$`),w2=new RegExp(`^rgb\\(${dr},${dr},${dr}\\)$`),x2=new RegExp(`^rgba\\(${Vs},${Vs},${Vs},${Zo}\\)$`),_2=new RegExp(`^rgba\\(${dr},${dr},${dr},${Zo}\\)$`),S2=new RegExp(`^hsl\\(${Zo},${dr},${dr}\\)$`),b2=new RegExp(`^hsla\\(${Zo},${dr},${dr},${Zo}\\)$`),gw={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};sv(la,Jo,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:vw,formatHex:vw,formatHex8:k2,formatHsl:E2,formatRgb:yw,toString:yw});function vw(){return this.rgb().formatHex()}function k2(){return this.rgb().formatHex8()}function E2(){return fE(this).formatHsl()}function yw(){return this.rgb().formatRgb()}function Jo(e){var n,r;return e=(e+"").trim().toLowerCase(),(n=v2.exec(e))?(r=n[1].length,n=parseInt(n[1],16),r===6?ww(n):r===3?new un(n>>8&15|n>>4&240,n>>4&15|n&240,(n&15)<<4|n&15,1):r===8?wl(n>>24&255,n>>16&255,n>>8&255,(n&255)/255):r===4?wl(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|n&240,((n&15)<<4|n&15)/255):null):(n=y2.exec(e))?new un(n[1],n[2],n[3],1):(n=w2.exec(e))?new un(n[1]*255/100,n[2]*255/100,n[3]*255/100,1):(n=x2.exec(e))?wl(n[1],n[2],n[3],n[4]):(n=_2.exec(e))?wl(n[1]*255/100,n[2]*255/100,n[3]*255/100,n[4]):(n=S2.exec(e))?Sw(n[1],n[2]/100,n[3]/100,1):(n=b2.exec(e))?Sw(n[1],n[2]/100,n[3]/100,n[4]):gw.hasOwnProperty(e)?ww(gw[e]):e==="transparent"?new un(NaN,NaN,NaN,0):null}function ww(e){return new un(e>>16&255,e>>8&255,e&255,1)}function wl(e,n,r,s){return s<=0&&(e=n=r=NaN),new un(e,n,r,s)}function N2(e){return e instanceof la||(e=Jo(e)),e?(e=e.rgb(),new un(e.r,e.g,e.b,e.opacity)):new un}function Og(e,n,r,s){return arguments.length===1?N2(e):new un(e,n,r,s??1)}function un(e,n,r,s){this.r=+e,this.g=+n,this.b=+r,this.opacity=+s}sv(un,Og,dE(la,{brighter(e){return e=e==null?Dl:Math.pow(Dl,e),new un(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Qo:Math.pow(Qo,e),new un(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new un(Gi(this.r),Gi(this.g),Gi(this.b),Fl(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:xw,formatHex:xw,formatHex8:C2,formatRgb:_w,toString:_w}));function xw(){return`#${Wi(this.r)}${Wi(this.g)}${Wi(this.b)}`}function C2(){return`#${Wi(this.r)}${Wi(this.g)}${Wi(this.b)}${Wi((isNaN(this.opacity)?1:this.opacity)*255)}`}function _w(){const e=Fl(this.opacity);return`${e===1?"rgb(":"rgba("}${Gi(this.r)}, ${Gi(this.g)}, ${Gi(this.b)}${e===1?")":`, ${e})`}`}function Fl(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Gi(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Wi(e){return e=Gi(e),(e<16?"0":"")+e.toString(16)}function Sw(e,n,r,s){return s<=0?e=n=r=NaN:r<=0||r>=1?e=n=NaN:n<=0&&(e=NaN),new Qn(e,n,r,s)}function fE(e){if(e instanceof Qn)return new Qn(e.h,e.s,e.l,e.opacity);if(e instanceof la||(e=Jo(e)),!e)return new Qn;if(e instanceof Qn)return e;e=e.rgb();var n=e.r/255,r=e.g/255,s=e.b/255,o=Math.min(n,r,s),l=Math.max(n,r,s),u=NaN,c=l-o,p=(l+o)/2;return c?(n===l?u=(r-s)/c+(r<s)*6:r===l?u=(s-n)/c+2:u=(n-r)/c+4,c/=p<.5?l+o:2-l-o,u*=60):c=p>0&&p<1?0:u,new Qn(u,c,p,e.opacity)}function T2(e,n,r,s){return arguments.length===1?fE(e):new Qn(e,n,r,s??1)}function Qn(e,n,r,s){this.h=+e,this.s=+n,this.l=+r,this.opacity=+s}sv(Qn,T2,dE(la,{brighter(e){return e=e==null?Dl:Math.pow(Dl,e),new Qn(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Qo:Math.pow(Qo,e),new Qn(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,n=isNaN(e)||isNaN(this.s)?0:this.s,r=this.l,s=r+(r<.5?r:1-r)*n,o=2*r-s;return new un(rd(e>=240?e-240:e+120,o,s),rd(e,o,s),rd(e<120?e+240:e-120,o,s),this.opacity)},clamp(){return new Qn(bw(this.h),xl(this.s),xl(this.l),Fl(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=Fl(this.opacity);return`${e===1?"hsl(":"hsla("}${bw(this.h)}, ${xl(this.s)*100}%, ${xl(this.l)*100}%${e===1?")":`, ${e})`}`}}));function bw(e){return e=(e||0)%360,e<0?e+360:e}function xl(e){return Math.max(0,Math.min(1,e||0))}function rd(e,n,r){return(e<60?n+(r-n)*e/60:e<180?r:e<240?n+(r-n)*(240-e)/60:n)*255}const hE=e=>()=>e;function R2(e,n){return function(r){return e+r*n}}function j2(e,n,r){return e=Math.pow(e,r),n=Math.pow(n,r)-e,r=1/r,function(s){return Math.pow(e+s*n,r)}}function A2(e){return(e=+e)==1?pE:function(n,r){return r-n?j2(n,r,e):hE(isNaN(n)?r:n)}}function pE(e,n){var r=n-e;return r?R2(e,r):hE(isNaN(e)?n:e)}const kw=(function e(n){var r=A2(n);function s(o,l){var u=r((o=Og(o)).r,(l=Og(l)).r),c=r(o.g,l.g),p=r(o.b,l.b),h=pE(o.opacity,l.opacity);return function(f){return o.r=u(f),o.g=c(f),o.b=p(f),o.opacity=h(f),o+""}}return s.gamma=e,s})(1);function li(e,n){return e=+e,n=+n,function(r){return e*(1-r)+n*r}}var Lg=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,id=new RegExp(Lg.source,"g");function I2(e){return function(){return e}}function M2(e){return function(n){return e(n)+""}}function P2(e,n){var r=Lg.lastIndex=id.lastIndex=0,s,o,l,u=-1,c=[],p=[];for(e=e+"",n=n+"";(s=Lg.exec(e))&&(o=id.exec(n));)(l=o.index)>r&&(l=n.slice(r,l),c[u]?c[u]+=l:c[++u]=l),(s=s[0])===(o=o[0])?c[u]?c[u]+=o:c[++u]=o:(c[++u]=null,p.push({i:u,x:li(s,o)})),r=id.lastIndex;return r<n.length&&(l=n.slice(r),c[u]?c[u]+=l:c[++u]=l),c.length<2?p[0]?M2(p[0].x):I2(n):(n=p.length,function(h){for(var f=0,m;f<n;++f)c[(m=p[f]).i]=m.x(h);return c.join("")})}var Ew=180/Math.PI,qg={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function mE(e,n,r,s,o,l){var u,c,p;return(u=Math.sqrt(e*e+n*n))&&(e/=u,n/=u),(p=e*r+n*s)&&(r-=e*p,s-=n*p),(c=Math.sqrt(r*r+s*s))&&(r/=c,s/=c,p/=c),e*s<n*r&&(e=-e,n=-n,p=-p,u=-u),{translateX:o,translateY:l,rotate:Math.atan2(n,e)*Ew,skewX:Math.atan(p)*Ew,scaleX:u,scaleY:c}}var _l;function O2(e){const n=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return n.isIdentity?qg:mE(n.a,n.b,n.c,n.d,n.e,n.f)}function L2(e){return e==null||(_l||(_l=document.createElementNS("http://www.w3.org/2000/svg","g")),_l.setAttribute("transform",e),!(e=_l.transform.baseVal.consolidate()))?qg:(e=e.matrix,mE(e.a,e.b,e.c,e.d,e.e,e.f))}function gE(e,n,r,s){function o(h){return h.length?h.pop()+" ":""}function l(h,f,m,y,x,C){if(h!==m||f!==y){var _=x.push("translate(",null,n,null,r);C.push({i:_-4,x:li(h,m)},{i:_-2,x:li(f,y)})}else(m||y)&&x.push("translate("+m+n+y+r)}function u(h,f,m,y){h!==f?(h-f>180?f+=360:f-h>180&&(h+=360),y.push({i:m.push(o(m)+"rotate(",null,s)-2,x:li(h,f)})):f&&m.push(o(m)+"rotate("+f+s)}function c(h,f,m,y){h!==f?y.push({i:m.push(o(m)+"skewX(",null,s)-2,x:li(h,f)}):f&&m.push(o(m)+"skewX("+f+s)}function p(h,f,m,y,x,C){if(h!==m||f!==y){var _=x.push(o(x)+"scale(",null,",",null,")");C.push({i:_-4,x:li(h,m)},{i:_-2,x:li(f,y)})}else(m!==1||y!==1)&&x.push(o(x)+"scale("+m+","+y+")")}return function(h,f){var m=[],y=[];return h=e(h),f=e(f),l(h.translateX,h.translateY,f.translateX,f.translateY,m,y),u(h.rotate,f.rotate,m,y),c(h.skewX,f.skewX,m,y),p(h.scaleX,h.scaleY,f.scaleX,f.scaleY,m,y),h=f=null,function(x){for(var C=-1,_=y.length,S;++C<_;)m[(S=y[C]).i]=S.x(x);return m.join("")}}}var q2=gE(O2,"px, ","px)","deg)"),$2=gE(L2,", ",")",")"),D2=1e-12;function Nw(e){return((e=Math.exp(e))+1/e)/2}function F2(e){return((e=Math.exp(e))-1/e)/2}function z2(e){return((e=Math.exp(2*e))-1)/(e+1)}const B2=(function e(n,r,s){function o(l,u){var c=l[0],p=l[1],h=l[2],f=u[0],m=u[1],y=u[2],x=f-c,C=m-p,_=x*x+C*C,S,b;if(_<D2)b=Math.log(y/h)/n,S=function(O){return[c+O*x,p+O*C,h*Math.exp(n*O*b)]};else{var E=Math.sqrt(_),N=(y*y-h*h+s*_)/(2*h*r*E),T=(y*y-h*h-s*_)/(2*y*r*E),I=Math.log(Math.sqrt(N*N+1)-N),M=Math.log(Math.sqrt(T*T+1)-T);b=(M-I)/n,S=function(O){var H=O*b,L=Nw(I),P=h/(r*E)*(L*z2(n*H+I)-F2(I));return[c+P*x,p+P*C,h*L/Nw(n*H+I)]}}return S.duration=b*1e3*n/Math.SQRT2,S}return o.rho=function(l){var u=Math.max(.001,+l),c=u*u,p=c*c;return e(u,c,p)},o})(Math.SQRT2,2,4);var Xs=0,Ho=0,$o=0,vE=1e3,zl,Wo,Bl=0,Ki=0,Jl=0,ea=typeof performance=="object"&&performance.now?performance:Date,yE=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function ov(){return Ki||(yE(U2),Ki=ea.now()+Jl)}function U2(){Ki=0}function Ul(){this._call=this._time=this._next=null}Ul.prototype=wE.prototype={constructor:Ul,restart:function(e,n,r){if(typeof e!="function")throw new TypeError("callback is not a function");r=(r==null?ov():+r)+(n==null?0:+n),!this._next&&Wo!==this&&(Wo?Wo._next=this:zl=this,Wo=this),this._call=e,this._time=r,$g()},stop:function(){this._call&&(this._call=null,this._time=1/0,$g())}};function wE(e,n,r){var s=new Ul;return s.restart(e,n,r),s}function H2(){ov(),++Xs;for(var e=zl,n;e;)(n=Ki-e._time)>=0&&e._call.call(void 0,n),e=e._next;--Xs}function Cw(){Ki=(Bl=ea.now())+Jl,Xs=Ho=0;try{H2()}finally{Xs=0,V2(),Ki=0}}function W2(){var e=ea.now(),n=e-Bl;n>vE&&(Jl-=n,Bl=e)}function V2(){for(var e,n=zl,r,s=1/0;n;)n._call?(s>n._time&&(s=n._time),e=n,n=n._next):(r=n._next,n._next=null,n=e?e._next=r:zl=r);Wo=e,$g(s)}function $g(e){if(!Xs){Ho&&(Ho=clearTimeout(Ho));var n=e-Ki;n>24?(e<1/0&&(Ho=setTimeout(Cw,e-ea.now()-Jl)),$o&&($o=clearInterval($o))):($o||(Bl=ea.now(),$o=setInterval(W2,vE)),Xs=1,yE(Cw))}}function Tw(e,n,r){var s=new Ul;return n=n==null?0:+n,s.restart(o=>{s.stop(),e(o+n)},n,r),s}var G2=Ql("start","end","cancel","interrupt"),Y2=[],xE=0,Rw=1,Dg=2,Ol=3,jw=4,Fg=5,Ll=6;function eu(e,n,r,s,o,l){var u=e.__transition;if(!u)e.__transition={};else if(r in u)return;K2(e,r,{name:n,index:s,group:o,on:G2,tween:Y2,time:l.time,delay:l.delay,duration:l.duration,ease:l.ease,timer:null,state:xE})}function av(e,n){var r=er(e,n);if(r.state>xE)throw new Error("too late; already scheduled");return r}function fr(e,n){var r=er(e,n);if(r.state>Ol)throw new Error("too late; already running");return r}function er(e,n){var r=e.__transition;if(!r||!(r=r[n]))throw new Error("transition not found");return r}function K2(e,n,r){var s=e.__transition,o;s[n]=r,r.timer=wE(l,0,r.time);function l(h){r.state=Rw,r.timer.restart(u,r.delay,r.time),r.delay<=h&&u(h-r.delay)}function u(h){var f,m,y,x;if(r.state!==Rw)return p();for(f in s)if(x=s[f],x.name===r.name){if(x.state===Ol)return Tw(u);x.state===jw?(x.state=Ll,x.timer.stop(),x.on.call("interrupt",e,e.__data__,x.index,x.group),delete s[f]):+f<n&&(x.state=Ll,x.timer.stop(),x.on.call("cancel",e,e.__data__,x.index,x.group),delete s[f])}if(Tw(function(){r.state===Ol&&(r.state=jw,r.timer.restart(c,r.delay,r.time),c(h))}),r.state=Dg,r.on.call("start",e,e.__data__,r.index,r.group),r.state===Dg){for(r.state=Ol,o=new Array(y=r.tween.length),f=0,m=-1;f<y;++f)(x=r.tween[f].value.call(e,e.__data__,r.index,r.group))&&(o[++m]=x);o.length=m+1}}function c(h){for(var f=h<r.duration?r.ease.call(null,h/r.duration):(r.timer.restart(p),r.state=Fg,1),m=-1,y=o.length;++m<y;)o[m].call(e,f);r.state===Fg&&(r.on.call("end",e,e.__data__,r.index,r.group),p())}function p(){r.state=Ll,r.timer.stop(),delete s[n];for(var h in s)return;delete e.__transition}}function ql(e,n){var r=e.__transition,s,o,l=!0,u;if(r){n=n==null?null:n+"";for(u in r){if((s=r[u]).name!==n){l=!1;continue}o=s.state>Dg&&s.state<Fg,s.state=Ll,s.timer.stop(),s.on.call(o?"interrupt":"cancel",e,e.__data__,s.index,s.group),delete r[u]}l&&delete e.__transition}}function X2(e){return this.each(function(){ql(this,e)})}function Q2(e,n){var r,s;return function(){var o=fr(this,e),l=o.tween;if(l!==r){s=r=l;for(var u=0,c=s.length;u<c;++u)if(s[u].name===n){s=s.slice(),s.splice(u,1);break}}o.tween=s}}function Z2(e,n,r){var s,o;if(typeof r!="function")throw new Error;return function(){var l=fr(this,e),u=l.tween;if(u!==s){o=(s=u).slice();for(var c={name:n,value:r},p=0,h=o.length;p<h;++p)if(o[p].name===n){o[p]=c;break}p===h&&o.push(c)}l.tween=o}}function J2(e,n){var r=this._id;if(e+="",arguments.length<2){for(var s=er(this.node(),r).tween,o=0,l=s.length,u;o<l;++o)if((u=s[o]).name===e)return u.value;return null}return this.each((n==null?Q2:Z2)(r,e,n))}function lv(e,n,r){var s=e._id;return e.each(function(){var o=fr(this,s);(o.value||(o.value={}))[n]=r.apply(this,arguments)}),function(o){return er(o,s).value[n]}}function _E(e,n){var r;return(typeof n=="number"?li:n instanceof Jo?kw:(r=Jo(n))?(n=r,kw):P2)(e,n)}function eA(e){return function(){this.removeAttribute(e)}}function tA(e){return function(){this.removeAttributeNS(e.space,e.local)}}function nA(e,n,r){var s,o=r+"",l;return function(){var u=this.getAttribute(e);return u===o?null:u===s?l:l=n(s=u,r)}}function rA(e,n,r){var s,o=r+"",l;return function(){var u=this.getAttributeNS(e.space,e.local);return u===o?null:u===s?l:l=n(s=u,r)}}function iA(e,n,r){var s,o,l;return function(){var u,c=r(this),p;return c==null?void this.removeAttribute(e):(u=this.getAttribute(e),p=c+"",u===p?null:u===s&&p===o?l:(o=p,l=n(s=u,c)))}}function sA(e,n,r){var s,o,l;return function(){var u,c=r(this),p;return c==null?void this.removeAttributeNS(e.space,e.local):(u=this.getAttributeNS(e.space,e.local),p=c+"",u===p?null:u===s&&p===o?l:(o=p,l=n(s=u,c)))}}function oA(e,n){var r=Zl(e),s=r==="transform"?$2:_E;return this.attrTween(e,typeof n=="function"?(r.local?sA:iA)(r,s,lv(this,"attr."+e,n)):n==null?(r.local?tA:eA)(r):(r.local?rA:nA)(r,s,n))}function aA(e,n){return function(r){this.setAttribute(e,n.call(this,r))}}function lA(e,n){return function(r){this.setAttributeNS(e.space,e.local,n.call(this,r))}}function uA(e,n){var r,s;function o(){var l=n.apply(this,arguments);return l!==s&&(r=(s=l)&&lA(e,l)),r}return o._value=n,o}function cA(e,n){var r,s;function o(){var l=n.apply(this,arguments);return l!==s&&(r=(s=l)&&aA(e,l)),r}return o._value=n,o}function dA(e,n){var r="attr."+e;if(arguments.length<2)return(r=this.tween(r))&&r._value;if(n==null)return this.tween(r,null);if(typeof n!="function")throw new Error;var s=Zl(e);return this.tween(r,(s.local?uA:cA)(s,n))}function fA(e,n){return function(){av(this,e).delay=+n.apply(this,arguments)}}function hA(e,n){return n=+n,function(){av(this,e).delay=n}}function pA(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?fA:hA)(n,e)):er(this.node(),n).delay}function mA(e,n){return function(){fr(this,e).duration=+n.apply(this,arguments)}}function gA(e,n){return n=+n,function(){fr(this,e).duration=n}}function vA(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?mA:gA)(n,e)):er(this.node(),n).duration}function yA(e,n){if(typeof n!="function")throw new Error;return function(){fr(this,e).ease=n}}function wA(e){var n=this._id;return arguments.length?this.each(yA(n,e)):er(this.node(),n).ease}function xA(e,n){return function(){var r=n.apply(this,arguments);if(typeof r!="function")throw new Error;fr(this,e).ease=r}}function _A(e){if(typeof e!="function")throw new Error;return this.each(xA(this._id,e))}function SA(e){typeof e!="function"&&(e=Jk(e));for(var n=this._groups,r=n.length,s=new Array(r),o=0;o<r;++o)for(var l=n[o],u=l.length,c=s[o]=[],p,h=0;h<u;++h)(p=l[h])&&e.call(p,p.__data__,h,l)&&c.push(p);return new Ir(s,this._parents,this._name,this._id)}function bA(e){if(e._id!==this._id)throw new Error;for(var n=this._groups,r=e._groups,s=n.length,o=r.length,l=Math.min(s,o),u=new Array(s),c=0;c<l;++c)for(var p=n[c],h=r[c],f=p.length,m=u[c]=new Array(f),y,x=0;x<f;++x)(y=p[x]||h[x])&&(m[x]=y);for(;c<s;++c)u[c]=n[c];return new Ir(u,this._parents,this._name,this._id)}function kA(e){return(e+"").trim().split(/^|\s+/).every(function(n){var r=n.indexOf(".");return r>=0&&(n=n.slice(0,r)),!n||n==="start"})}function EA(e,n,r){var s,o,l=kA(n)?av:fr;return function(){var u=l(this,e),c=u.on;c!==s&&(o=(s=c).copy()).on(n,r),u.on=o}}function NA(e,n){var r=this._id;return arguments.length<2?er(this.node(),r).on.on(e):this.each(EA(r,e,n))}function CA(e){return function(){var n=this.parentNode;for(var r in this.__transition)if(+r!==e)return;n&&n.removeChild(this)}}function TA(){return this.on("end.remove",CA(this._id))}function RA(e){var n=this._name,r=this._id;typeof e!="function"&&(e=rv(e));for(var s=this._groups,o=s.length,l=new Array(o),u=0;u<o;++u)for(var c=s[u],p=c.length,h=l[u]=new Array(p),f,m,y=0;y<p;++y)(f=c[y])&&(m=e.call(f,f.__data__,y,c))&&("__data__"in f&&(m.__data__=f.__data__),h[y]=m,eu(h[y],n,r,y,h,er(f,r)));return new Ir(l,this._parents,n,r)}function jA(e){var n=this._name,r=this._id;typeof e!="function"&&(e=Zk(e));for(var s=this._groups,o=s.length,l=[],u=[],c=0;c<o;++c)for(var p=s[c],h=p.length,f,m=0;m<h;++m)if(f=p[m]){for(var y=e.call(f,f.__data__,m,p),x,C=er(f,r),_=0,S=y.length;_<S;++_)(x=y[_])&&eu(x,n,r,_,y,C);l.push(y),u.push(f)}return new Ir(l,u,n,r)}var AA=aa.prototype.constructor;function IA(){return new AA(this._groups,this._parents)}function MA(e,n){var r,s,o;return function(){var l=Ks(this,e),u=(this.style.removeProperty(e),Ks(this,e));return l===u?null:l===r&&u===s?o:o=n(r=l,s=u)}}function SE(e){return function(){this.style.removeProperty(e)}}function PA(e,n,r){var s,o=r+"",l;return function(){var u=Ks(this,e);return u===o?null:u===s?l:l=n(s=u,r)}}function OA(e,n,r){var s,o,l;return function(){var u=Ks(this,e),c=r(this),p=c+"";return c==null&&(p=c=(this.style.removeProperty(e),Ks(this,e))),u===p?null:u===s&&p===o?l:(o=p,l=n(s=u,c))}}function LA(e,n){var r,s,o,l="style."+n,u="end."+l,c;return function(){var p=fr(this,e),h=p.on,f=p.value[l]==null?c||(c=SE(n)):void 0;(h!==r||o!==f)&&(s=(r=h).copy()).on(u,o=f),p.on=s}}function qA(e,n,r){var s=(e+="")=="transform"?q2:_E;return n==null?this.styleTween(e,MA(e,s)).on("end.style."+e,SE(e)):typeof n=="function"?this.styleTween(e,OA(e,s,lv(this,"style."+e,n))).each(LA(this._id,e)):this.styleTween(e,PA(e,s,n),r).on("end.style."+e,null)}function $A(e,n,r){return function(s){this.style.setProperty(e,n.call(this,s),r)}}function DA(e,n,r){var s,o;function l(){var u=n.apply(this,arguments);return u!==o&&(s=(o=u)&&$A(e,u,r)),s}return l._value=n,l}function FA(e,n,r){var s="style."+(e+="");if(arguments.length<2)return(s=this.tween(s))&&s._value;if(n==null)return this.tween(s,null);if(typeof n!="function")throw new Error;return this.tween(s,DA(e,n,r??""))}function zA(e){return function(){this.textContent=e}}function BA(e){return function(){var n=e(this);this.textContent=n??""}}function UA(e){return this.tween("text",typeof e=="function"?BA(lv(this,"text",e)):zA(e==null?"":e+""))}function HA(e){return function(n){this.textContent=e.call(this,n)}}function WA(e){var n,r;function s(){var o=e.apply(this,arguments);return o!==r&&(n=(r=o)&&HA(o)),n}return s._value=e,s}function VA(e){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(e==null)return this.tween(n,null);if(typeof e!="function")throw new Error;return this.tween(n,WA(e))}function GA(){for(var e=this._name,n=this._id,r=bE(),s=this._groups,o=s.length,l=0;l<o;++l)for(var u=s[l],c=u.length,p,h=0;h<c;++h)if(p=u[h]){var f=er(p,n);eu(p,e,r,h,u,{time:f.time+f.delay+f.duration,delay:0,duration:f.duration,ease:f.ease})}return new Ir(s,this._parents,e,r)}function YA(){var e,n,r=this,s=r._id,o=r.size();return new Promise(function(l,u){var c={value:u},p={value:function(){--o===0&&l()}};r.each(function(){var h=fr(this,s),f=h.on;f!==e&&(n=(e=f).copy(),n._.cancel.push(c),n._.interrupt.push(c),n._.end.push(p)),h.on=n}),o===0&&l()})}var KA=0;function Ir(e,n,r,s){this._groups=e,this._parents=n,this._name=r,this._id=s}function bE(){return++KA}var Tr=aa.prototype;Ir.prototype={constructor:Ir,select:RA,selectAll:jA,selectChild:Tr.selectChild,selectChildren:Tr.selectChildren,filter:SA,merge:bA,selection:IA,transition:GA,call:Tr.call,nodes:Tr.nodes,node:Tr.node,size:Tr.size,empty:Tr.empty,each:Tr.each,on:NA,attr:oA,attrTween:dA,style:qA,styleTween:FA,text:UA,textTween:VA,remove:TA,tween:J2,delay:pA,duration:vA,ease:wA,easeVarying:_A,end:YA,[Symbol.iterator]:Tr[Symbol.iterator]};function XA(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var QA={time:null,delay:0,duration:250,ease:XA};function ZA(e,n){for(var r;!(r=e.__transition)||!(r=r[n]);)if(!(e=e.parentNode))throw new Error(`transition ${n} not found`);return r}function JA(e){var n,r;e instanceof Ir?(n=e._id,e=e._name):(n=bE(),(r=QA).time=ov(),e=e==null?null:e+"");for(var s=this._groups,o=s.length,l=0;l<o;++l)for(var u=s[l],c=u.length,p,h=0;h<c;++h)(p=u[h])&&eu(p,e,n,h,u,r||ZA(p,n));return new Ir(s,this._parents,e,n)}aa.prototype.interrupt=X2;aa.prototype.transition=JA;const Sl=e=>()=>e;function eI(e,{sourceEvent:n,target:r,transform:s,dispatch:o}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},transform:{value:s,enumerable:!0,configurable:!0},_:{value:o}})}function jr(e,n,r){this.k=e,this.x=n,this.y=r}jr.prototype={constructor:jr,scale:function(e){return e===1?this:new jr(this.k*e,this.x,this.y)},translate:function(e,n){return e===0&n===0?this:new jr(this.k,this.x+this.k*e,this.y+this.k*n)},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 Ar=new jr(1,0,0);jr.prototype;function sd(e){e.stopImmediatePropagation()}function Do(e){e.preventDefault(),e.stopImmediatePropagation()}function tI(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function nI(){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 Aw(){return this.__zoom||Ar}function rI(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function iI(){return navigator.maxTouchPoints||"ontouchstart"in this}function sI(e,n,r){var s=e.invertX(n[0][0])-r[0][0],o=e.invertX(n[1][0])-r[1][0],l=e.invertY(n[0][1])-r[0][1],u=e.invertY(n[1][1])-r[1][1];return e.translate(o>s?(s+o)/2:Math.min(0,s)||Math.max(0,o),u>l?(l+u)/2:Math.min(0,l)||Math.max(0,u))}function kE(){var e=tI,n=nI,r=sI,s=rI,o=iI,l=[0,1/0],u=[[-1/0,-1/0],[1/0,1/0]],c=250,p=B2,h=Ql("start","zoom","end"),f,m,y,x=500,C=150,_=0,S=10;function b(j){j.property("__zoom",Aw).on("wheel.zoom",H,{passive:!1}).on("mousedown.zoom",L).on("dblclick.zoom",P).filter(o).on("touchstart.zoom",q).on("touchmove.zoom",W).on("touchend.zoom touchcancel.zoom",B).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}b.transform=function(j,K,U,ee){var J=j.selection?j.selection():j;J.property("__zoom",Aw),j!==J?I(j,K,U,ee):J.interrupt().each(function(){M(this,arguments).event(ee).start().zoom(null,typeof K=="function"?K.apply(this,arguments):K).end()})},b.scaleBy=function(j,K,U,ee){b.scaleTo(j,function(){var J=this.__zoom.k,F=typeof K=="function"?K.apply(this,arguments):K;return J*F},U,ee)},b.scaleTo=function(j,K,U,ee){b.transform(j,function(){var J=n.apply(this,arguments),F=this.__zoom,Y=U==null?T(J):typeof U=="function"?U.apply(this,arguments):U,k=F.invert(Y),$=typeof K=="function"?K.apply(this,arguments):K;return r(N(E(F,$),Y,k),J,u)},U,ee)},b.translateBy=function(j,K,U,ee){b.transform(j,function(){return r(this.__zoom.translate(typeof K=="function"?K.apply(this,arguments):K,typeof U=="function"?U.apply(this,arguments):U),n.apply(this,arguments),u)},null,ee)},b.translateTo=function(j,K,U,ee,J){b.transform(j,function(){var F=n.apply(this,arguments),Y=this.__zoom,k=ee==null?T(F):typeof ee=="function"?ee.apply(this,arguments):ee;return r(Ar.translate(k[0],k[1]).scale(Y.k).translate(typeof K=="function"?-K.apply(this,arguments):-K,typeof U=="function"?-U.apply(this,arguments):-U),F,u)},ee,J)};function E(j,K){return K=Math.max(l[0],Math.min(l[1],K)),K===j.k?j:new jr(K,j.x,j.y)}function N(j,K,U){var ee=K[0]-U[0]*j.k,J=K[1]-U[1]*j.k;return ee===j.x&&J===j.y?j:new jr(j.k,ee,J)}function T(j){return[(+j[0][0]+ +j[1][0])/2,(+j[0][1]+ +j[1][1])/2]}function I(j,K,U,ee){j.on("start.zoom",function(){M(this,arguments).event(ee).start()}).on("interrupt.zoom end.zoom",function(){M(this,arguments).event(ee).end()}).tween("zoom",function(){var J=this,F=arguments,Y=M(J,F).event(ee),k=n.apply(J,F),$=U==null?T(k):typeof U=="function"?U.apply(J,F):U,se=Math.max(k[1][0]-k[0][0],k[1][1]-k[0][1]),D=J.__zoom,Q=typeof K=="function"?K.apply(J,F):K,te=p(D.invert($).concat(se/D.k),Q.invert($).concat(se/Q.k));return function(ae){if(ae===1)ae=Q;else{var ce=te(ae),me=se/ce[2];ae=new jr(me,$[0]-ce[0]*me,$[1]-ce[1]*me)}Y.zoom(null,ae)}})}function M(j,K,U){return!U&&j.__zooming||new O(j,K)}function O(j,K){this.that=j,this.args=K,this.active=0,this.sourceEvent=null,this.extent=n.apply(j,K),this.taps=0}O.prototype={event:function(j){return j&&(this.sourceEvent=j),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(j,K){return this.mouse&&j!=="mouse"&&(this.mouse[1]=K.invert(this.mouse[0])),this.touch0&&j!=="touch"&&(this.touch0[1]=K.invert(this.touch0[0])),this.touch1&&j!=="touch"&&(this.touch1[1]=K.invert(this.touch1[0])),this.that.__zoom=K,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(j){var K=Tn(this.that).datum();h.call(j,this.that,new eI(j,{sourceEvent:this.sourceEvent,target:b,transform:this.that.__zoom,dispatch:h}),K)}};function H(j,...K){if(!e.apply(this,arguments))return;var U=M(this,K).event(j),ee=this.__zoom,J=Math.max(l[0],Math.min(l[1],ee.k*Math.pow(2,s.apply(this,arguments)))),F=Xn(j);if(U.wheel)(U.mouse[0][0]!==F[0]||U.mouse[0][1]!==F[1])&&(U.mouse[1]=ee.invert(U.mouse[0]=F)),clearTimeout(U.wheel);else{if(ee.k===J)return;U.mouse=[F,ee.invert(F)],ql(this),U.start()}Do(j),U.wheel=setTimeout(Y,C),U.zoom("mouse",r(N(E(ee,J),U.mouse[0],U.mouse[1]),U.extent,u));function Y(){U.wheel=null,U.end()}}function L(j,...K){if(y||!e.apply(this,arguments))return;var U=j.currentTarget,ee=M(this,K,!0).event(j),J=Tn(j.view).on("mousemove.zoom",$,!0).on("mouseup.zoom",se,!0),F=Xn(j,U),Y=j.clientX,k=j.clientY;uE(j.view),sd(j),ee.mouse=[F,this.__zoom.invert(F)],ql(this),ee.start();function $(D){if(Do(D),!ee.moved){var Q=D.clientX-Y,te=D.clientY-k;ee.moved=Q*Q+te*te>_}ee.event(D).zoom("mouse",r(N(ee.that.__zoom,ee.mouse[0]=Xn(D,U),ee.mouse[1]),ee.extent,u))}function se(D){J.on("mousemove.zoom mouseup.zoom",null),cE(D.view,ee.moved),Do(D),ee.event(D).end()}}function P(j,...K){if(e.apply(this,arguments)){var U=this.__zoom,ee=Xn(j.changedTouches?j.changedTouches[0]:j,this),J=U.invert(ee),F=U.k*(j.shiftKey?.5:2),Y=r(N(E(U,F),ee,J),n.apply(this,K),u);Do(j),c>0?Tn(this).transition().duration(c).call(I,Y,ee,j):Tn(this).call(b.transform,Y,ee,j)}}function q(j,...K){if(e.apply(this,arguments)){var U=j.touches,ee=U.length,J=M(this,K,j.changedTouches.length===ee).event(j),F,Y,k,$;for(sd(j),Y=0;Y<ee;++Y)k=U[Y],$=Xn(k,this),$=[$,this.__zoom.invert($),k.identifier],J.touch0?!J.touch1&&J.touch0[2]!==$[2]&&(J.touch1=$,J.taps=0):(J.touch0=$,F=!0,J.taps=1+!!f);f&&(f=clearTimeout(f)),F&&(J.taps<2&&(m=$[0],f=setTimeout(function(){f=null},x)),ql(this),J.start())}}function W(j,...K){if(this.__zooming){var U=M(this,K).event(j),ee=j.changedTouches,J=ee.length,F,Y,k,$;for(Do(j),F=0;F<J;++F)Y=ee[F],k=Xn(Y,this),U.touch0&&U.touch0[2]===Y.identifier?U.touch0[0]=k:U.touch1&&U.touch1[2]===Y.identifier&&(U.touch1[0]=k);if(Y=U.that.__zoom,U.touch1){var se=U.touch0[0],D=U.touch0[1],Q=U.touch1[0],te=U.touch1[1],ae=(ae=Q[0]-se[0])*ae+(ae=Q[1]-se[1])*ae,ce=(ce=te[0]-D[0])*ce+(ce=te[1]-D[1])*ce;Y=E(Y,Math.sqrt(ae/ce)),k=[(se[0]+Q[0])/2,(se[1]+Q[1])/2],$=[(D[0]+te[0])/2,(D[1]+te[1])/2]}else if(U.touch0)k=U.touch0[0],$=U.touch0[1];else return;U.zoom("touch",r(N(Y,k,$),U.extent,u))}}function B(j,...K){if(this.__zooming){var U=M(this,K).event(j),ee=j.changedTouches,J=ee.length,F,Y;for(sd(j),y&&clearTimeout(y),y=setTimeout(function(){y=null},x),F=0;F<J;++F)Y=ee[F],U.touch0&&U.touch0[2]===Y.identifier?delete U.touch0:U.touch1&&U.touch1[2]===Y.identifier&&delete U.touch1;if(U.touch1&&!U.touch0&&(U.touch0=U.touch1,delete U.touch1),U.touch0)U.touch0[1]=this.__zoom.invert(U.touch0[0]);else if(U.end(),U.taps===2&&(Y=Xn(Y,this),Math.hypot(m[0]-Y[0],m[1]-Y[1])<S)){var k=Tn(this).on("dblclick.zoom");k&&k.apply(this,arguments)}}}return b.wheelDelta=function(j){return arguments.length?(s=typeof j=="function"?j:Sl(+j),b):s},b.filter=function(j){return arguments.length?(e=typeof j=="function"?j:Sl(!!j),b):e},b.touchable=function(j){return arguments.length?(o=typeof j=="function"?j:Sl(!!j),b):o},b.extent=function(j){return arguments.length?(n=typeof j=="function"?j:Sl([[+j[0][0],+j[0][1]],[+j[1][0],+j[1][1]]]),b):n},b.scaleExtent=function(j){return arguments.length?(l[0]=+j[0],l[1]=+j[1],b):[l[0],l[1]]},b.translateExtent=function(j){return arguments.length?(u[0][0]=+j[0][0],u[1][0]=+j[1][0],u[0][1]=+j[0][1],u[1][1]=+j[1][1],b):[[u[0][0],u[0][1]],[u[1][0],u[1][1]]]},b.constrain=function(j){return arguments.length?(r=j,b):r},b.duration=function(j){return arguments.length?(c=+j,b):c},b.interpolate=function(j){return arguments.length?(p=j,b):p},b.on=function(){var j=h.on.apply(h,arguments);return j===h?b:j},b.clickDistance=function(j){return arguments.length?(_=(j=+j)*j,b):Math.sqrt(_)},b.tapDistance=function(j){return arguments.length?(S=+j,b):S},b}var oI=Kk();const tu=A.createContext(null),aI=tu.Provider,Mr={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,n)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?n.targetHandle:n.sourceHandle}", edge id: ${n.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},EE=Mr.error001();function Ke(e,n){const r=A.useContext(tu);if(r===null)throw new Error(EE);return Xk(r,e,n)}const Et=()=>{const e=A.useContext(tu);if(e===null)throw new Error(EE);return A.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},lI=e=>e.userSelectionActive?"none":"all";function uv({position:e,children:n,className:r,style:s,...o}){const l=Ke(lI),u=`${e}`.split("-");return le.createElement("div",{className:Dt(["react-flow__panel",r,...u]),style:{...s,pointerEvents:l},...o},n)}function uI({proOptions:e,position:n="bottom-right"}){return e!=null&&e.hideAttribution?null:le.createElement(uv,{position:n,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},le.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const cI=({x:e,y:n,label:r,labelStyle:s={},labelShowBg:o=!0,labelBgStyle:l={},labelBgPadding:u=[2,4],labelBgBorderRadius:c=2,children:p,className:h,...f})=>{const m=A.useRef(null),[y,x]=A.useState({x:0,y:0,width:0,height:0}),C=Dt(["react-flow__edge-textwrapper",h]);return A.useEffect(()=>{if(m.current){const _=m.current.getBBox();x({x:_.x,y:_.y,width:_.width,height:_.height})}},[r]),typeof r>"u"||!r?null:le.createElement("g",{transform:`translate(${e-y.width/2} ${n-y.height/2})`,className:C,visibility:y.width?"visible":"hidden",...f},o&&le.createElement("rect",{width:y.width+2*u[0],x:-u[0],y:-u[1],height:y.height+2*u[1],className:"react-flow__edge-textbg",style:l,rx:c,ry:c}),le.createElement("text",{className:"react-flow__edge-text",y:y.height/2,dy:"0.3em",ref:m,style:s},r),p)};var dI=A.memo(cI);const cv=e=>({width:e.offsetWidth,height:e.offsetHeight}),Qs=(e,n=0,r=1)=>Math.min(Math.max(e,n),r),dv=(e={x:0,y:0},n)=>({x:Qs(e.x,n[0][0],n[1][0]),y:Qs(e.y,n[0][1],n[1][1])}),Iw=(e,n,r)=>e<n?Qs(Math.abs(e-n),1,50)/50:e>r?-Qs(Math.abs(e-r),1,50)/50:0,NE=(e,n)=>{const r=Iw(e.x,35,n.width-35)*20,s=Iw(e.y,35,n.height-35)*20;return[r,s]},CE=e=>{var n;return((n=e.getRootNode)==null?void 0:n.call(e))||(window==null?void 0:window.document)},TE=(e,n)=>({x:Math.min(e.x,n.x),y:Math.min(e.y,n.y),x2:Math.max(e.x2,n.x2),y2:Math.max(e.y2,n.y2)}),ta=({x:e,y:n,width:r,height:s})=>({x:e,y:n,x2:e+r,y2:n+s}),RE=({x:e,y:n,x2:r,y2:s})=>({x:e,y:n,width:r-e,height:s-n}),Mw=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),fI=(e,n)=>RE(TE(ta(e),ta(n))),zg=(e,n)=>{const r=Math.max(0,Math.min(e.x+e.width,n.x+n.width)-Math.max(e.x,n.x)),s=Math.max(0,Math.min(e.y+e.height,n.y+n.height)-Math.max(e.y,n.y));return Math.ceil(r*s)},hI=e=>Rn(e.width)&&Rn(e.height)&&Rn(e.x)&&Rn(e.y),Rn=e=>!isNaN(e)&&isFinite(e),mt=Symbol.for("internals"),jE=["Enter"," ","Escape"],pI=(e,n)=>{},mI=e=>"nativeEvent"in e;function Bg(e){var o,l;const n=mI(e)?e.nativeEvent:e,r=((l=(o=n.composedPath)==null?void 0:o.call(n))==null?void 0:l[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(r==null?void 0:r.nodeName)||(r==null?void 0:r.hasAttribute("contenteditable"))||!!(r!=null&&r.closest(".nokey"))}const AE=e=>"clientX"in e,di=(e,n)=>{var l,u;const r=AE(e),s=r?e.clientX:(l=e.touches)==null?void 0:l[0].clientX,o=r?e.clientY:(u=e.touches)==null?void 0:u[0].clientY;return{x:s-((n==null?void 0:n.left)??0),y:o-((n==null?void 0:n.top)??0)}},Hl=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},ua=({id:e,path:n,labelX:r,labelY:s,label:o,labelStyle:l,labelShowBg:u,labelBgStyle:c,labelBgPadding:p,labelBgBorderRadius:h,style:f,markerEnd:m,markerStart:y,interactionWidth:x=20})=>le.createElement(le.Fragment,null,le.createElement("path",{id:e,style:f,d:n,fill:"none",className:"react-flow__edge-path",markerEnd:m,markerStart:y}),x&&le.createElement("path",{d:n,fill:"none",strokeOpacity:0,strokeWidth:x,className:"react-flow__edge-interaction"}),o&&Rn(r)&&Rn(s)?le.createElement(dI,{x:r,y:s,label:o,labelStyle:l,labelShowBg:u,labelBgStyle:c,labelBgPadding:p,labelBgBorderRadius:h}):null);ua.displayName="BaseEdge";function Fo(e,n,r){return r===void 0?r:s=>{const o=n().edges.find(l=>l.id===e);o&&r(s,{...o})}}function IE({sourceX:e,sourceY:n,targetX:r,targetY:s}){const o=Math.abs(r-e)/2,l=r<e?r+o:r-o,u=Math.abs(s-n)/2,c=s<n?s+u:s-u;return[l,c,o,u]}function ME({sourceX:e,sourceY:n,targetX:r,targetY:s,sourceControlX:o,sourceControlY:l,targetControlX:u,targetControlY:c}){const p=e*.125+o*.375+u*.375+r*.125,h=n*.125+l*.375+c*.375+s*.125,f=Math.abs(p-e),m=Math.abs(h-n);return[p,h,f,m]}var Xi;(function(e){e.Strict="strict",e.Loose="loose"})(Xi||(Xi={}));var Vi;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Vi||(Vi={}));var na;(function(e){e.Partial="partial",e.Full="full"})(na||(na={}));var ci;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(ci||(ci={}));var Wl;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Wl||(Wl={}));var Re;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(Re||(Re={}));function Pw({pos:e,x1:n,y1:r,x2:s,y2:o}){return e===Re.Left||e===Re.Right?[.5*(n+s),r]:[n,.5*(r+o)]}function PE({sourceX:e,sourceY:n,sourcePosition:r=Re.Bottom,targetX:s,targetY:o,targetPosition:l=Re.Top}){const[u,c]=Pw({pos:r,x1:e,y1:n,x2:s,y2:o}),[p,h]=Pw({pos:l,x1:s,y1:o,x2:e,y2:n}),[f,m,y,x]=ME({sourceX:e,sourceY:n,targetX:s,targetY:o,sourceControlX:u,sourceControlY:c,targetControlX:p,targetControlY:h});return[`M${e},${n} C${u},${c} ${p},${h} ${s},${o}`,f,m,y,x]}const fv=A.memo(({sourceX:e,sourceY:n,targetX:r,targetY:s,sourcePosition:o=Re.Bottom,targetPosition:l=Re.Top,label:u,labelStyle:c,labelShowBg:p,labelBgStyle:h,labelBgPadding:f,labelBgBorderRadius:m,style:y,markerEnd:x,markerStart:C,interactionWidth:_})=>{const[S,b,E]=PE({sourceX:e,sourceY:n,sourcePosition:o,targetX:r,targetY:s,targetPosition:l});return le.createElement(ua,{path:S,labelX:b,labelY:E,label:u,labelStyle:c,labelShowBg:p,labelBgStyle:h,labelBgPadding:f,labelBgBorderRadius:m,style:y,markerEnd:x,markerStart:C,interactionWidth:_})});fv.displayName="SimpleBezierEdge";const Ow={[Re.Left]:{x:-1,y:0},[Re.Right]:{x:1,y:0},[Re.Top]:{x:0,y:-1},[Re.Bottom]:{x:0,y:1}},gI=({source:e,sourcePosition:n=Re.Bottom,target:r})=>n===Re.Left||n===Re.Right?e.x<r.x?{x:1,y:0}:{x:-1,y:0}:e.y<r.y?{x:0,y:1}:{x:0,y:-1},Lw=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function vI({source:e,sourcePosition:n=Re.Bottom,target:r,targetPosition:s=Re.Top,center:o,offset:l}){const u=Ow[n],c=Ow[s],p={x:e.x+u.x*l,y:e.y+u.y*l},h={x:r.x+c.x*l,y:r.y+c.y*l},f=gI({source:p,sourcePosition:n,target:h}),m=f.x!==0?"x":"y",y=f[m];let x=[],C,_;const S={x:0,y:0},b={x:0,y:0},[E,N,T,I]=IE({sourceX:e.x,sourceY:e.y,targetX:r.x,targetY:r.y});if(u[m]*c[m]===-1){C=o.x??E,_=o.y??N;const O=[{x:C,y:p.y},{x:C,y:h.y}],H=[{x:p.x,y:_},{x:h.x,y:_}];u[m]===y?x=m==="x"?O:H:x=m==="x"?H:O}else{const O=[{x:p.x,y:h.y}],H=[{x:h.x,y:p.y}];if(m==="x"?x=u.x===y?H:O:x=u.y===y?O:H,n===s){const B=Math.abs(e[m]-r[m]);if(B<=l){const j=Math.min(l-1,l-B);u[m]===y?S[m]=(p[m]>e[m]?-1:1)*j:b[m]=(h[m]>r[m]?-1:1)*j}}if(n!==s){const B=m==="x"?"y":"x",j=u[m]===c[B],K=p[B]>h[B],U=p[B]<h[B];(u[m]===1&&(!j&&K||j&&U)||u[m]!==1&&(!j&&U||j&&K))&&(x=m==="x"?O:H)}const L={x:p.x+S.x,y:p.y+S.y},P={x:h.x+b.x,y:h.y+b.y},q=Math.max(Math.abs(L.x-x[0].x),Math.abs(P.x-x[0].x)),W=Math.max(Math.abs(L.y-x[0].y),Math.abs(P.y-x[0].y));q>=W?(C=(L.x+P.x)/2,_=x[0].y):(C=x[0].x,_=(L.y+P.y)/2)}return[[e,{x:p.x+S.x,y:p.y+S.y},...x,{x:h.x+b.x,y:h.y+b.y},r],C,_,T,I]}function yI(e,n,r,s){const o=Math.min(Lw(e,n)/2,Lw(n,r)/2,s),{x:l,y:u}=n;if(e.x===l&&l===r.x||e.y===u&&u===r.y)return`L${l} ${u}`;if(e.y===u){const h=e.x<r.x?-1:1,f=e.y<r.y?1:-1;return`L ${l+o*h},${u}Q ${l},${u} ${l},${u+o*f}`}const c=e.x<r.x?1:-1,p=e.y<r.y?-1:1;return`L ${l},${u+o*p}Q ${l},${u} ${l+o*c},${u}`}function Ug({sourceX:e,sourceY:n,sourcePosition:r=Re.Bottom,targetX:s,targetY:o,targetPosition:l=Re.Top,borderRadius:u=5,centerX:c,centerY:p,offset:h=20}){const[f,m,y,x,C]=vI({source:{x:e,y:n},sourcePosition:r,target:{x:s,y:o},targetPosition:l,center:{x:c,y:p},offset:h});return[f.reduce((S,b,E)=>{let N="";return E>0&&E<f.length-1?N=yI(f[E-1],b,f[E+1],u):N=`${E===0?"M":"L"}${b.x} ${b.y}`,S+=N,S},""),m,y,x,C]}const nu=A.memo(({sourceX:e,sourceY:n,targetX:r,targetY:s,label:o,labelStyle:l,labelShowBg:u,labelBgStyle:c,labelBgPadding:p,labelBgBorderRadius:h,style:f,sourcePosition:m=Re.Bottom,targetPosition:y=Re.Top,markerEnd:x,markerStart:C,pathOptions:_,interactionWidth:S})=>{const[b,E,N]=Ug({sourceX:e,sourceY:n,sourcePosition:m,targetX:r,targetY:s,targetPosition:y,borderRadius:_==null?void 0:_.borderRadius,offset:_==null?void 0:_.offset});return le.createElement(ua,{path:b,labelX:E,labelY:N,label:o,labelStyle:l,labelShowBg:u,labelBgStyle:c,labelBgPadding:p,labelBgBorderRadius:h,style:f,markerEnd:x,markerStart:C,interactionWidth:S})});nu.displayName="SmoothStepEdge";const hv=A.memo(e=>{var n;return le.createElement(nu,{...e,pathOptions:A.useMemo(()=>{var r;return{borderRadius:0,offset:(r=e.pathOptions)==null?void 0:r.offset}},[(n=e.pathOptions)==null?void 0:n.offset])})});hv.displayName="StepEdge";function wI({sourceX:e,sourceY:n,targetX:r,targetY:s}){const[o,l,u,c]=IE({sourceX:e,sourceY:n,targetX:r,targetY:s});return[`M ${e},${n}L ${r},${s}`,o,l,u,c]}const pv=A.memo(({sourceX:e,sourceY:n,targetX:r,targetY:s,label:o,labelStyle:l,labelShowBg:u,labelBgStyle:c,labelBgPadding:p,labelBgBorderRadius:h,style:f,markerEnd:m,markerStart:y,interactionWidth:x})=>{const[C,_,S]=wI({sourceX:e,sourceY:n,targetX:r,targetY:s});return le.createElement(ua,{path:C,labelX:_,labelY:S,label:o,labelStyle:l,labelShowBg:u,labelBgStyle:c,labelBgPadding:p,labelBgBorderRadius:h,style:f,markerEnd:m,markerStart:y,interactionWidth:x})});pv.displayName="StraightEdge";function bl(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function qw({pos:e,x1:n,y1:r,x2:s,y2:o,c:l}){switch(e){case Re.Left:return[n-bl(n-s,l),r];case Re.Right:return[n+bl(s-n,l),r];case Re.Top:return[n,r-bl(r-o,l)];case Re.Bottom:return[n,r+bl(o-r,l)]}}function OE({sourceX:e,sourceY:n,sourcePosition:r=Re.Bottom,targetX:s,targetY:o,targetPosition:l=Re.Top,curvature:u=.25}){const[c,p]=qw({pos:r,x1:e,y1:n,x2:s,y2:o,c:u}),[h,f]=qw({pos:l,x1:s,y1:o,x2:e,y2:n,c:u}),[m,y,x,C]=ME({sourceX:e,sourceY:n,targetX:s,targetY:o,sourceControlX:c,sourceControlY:p,targetControlX:h,targetControlY:f});return[`M${e},${n} C${c},${p} ${h},${f} ${s},${o}`,m,y,x,C]}const Vl=A.memo(({sourceX:e,sourceY:n,targetX:r,targetY:s,sourcePosition:o=Re.Bottom,targetPosition:l=Re.Top,label:u,labelStyle:c,labelShowBg:p,labelBgStyle:h,labelBgPadding:f,labelBgBorderRadius:m,style:y,markerEnd:x,markerStart:C,pathOptions:_,interactionWidth:S})=>{const[b,E,N]=OE({sourceX:e,sourceY:n,sourcePosition:o,targetX:r,targetY:s,targetPosition:l,curvature:_==null?void 0:_.curvature});return le.createElement(ua,{path:b,labelX:E,labelY:N,label:u,labelStyle:c,labelShowBg:p,labelBgStyle:h,labelBgPadding:f,labelBgBorderRadius:m,style:y,markerEnd:x,markerStart:C,interactionWidth:S})});Vl.displayName="BezierEdge";const mv=A.createContext(null),xI=mv.Provider;mv.Consumer;const _I=()=>A.useContext(mv),SI=e=>"id"in e&&"source"in e&&"target"in e,bI=({source:e,sourceHandle:n,target:r,targetHandle:s})=>`reactflow__edge-${e}${n||""}-${r}${s||""}`,Hg=(e,n)=>typeof e>"u"?"":typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(s=>`${s}=${e[s]}`).join("&")}`,kI=(e,n)=>n.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle===e.sourceHandle||!r.sourceHandle&&!e.sourceHandle)&&(r.targetHandle===e.targetHandle||!r.targetHandle&&!e.targetHandle)),EI=(e,n)=>{if(!e.source||!e.target)return n;let r;return SI(e)?r={...e}:r={...e,id:bI(e)},kI(r,n)?n:n.concat(r)},Wg=({x:e,y:n},[r,s,o],l,[u,c])=>{const p={x:(e-r)/o,y:(n-s)/o};return l?{x:u*Math.round(p.x/u),y:c*Math.round(p.y/c)}:p},LE=({x:e,y:n},[r,s,o])=>({x:e*o+r,y:n*o+s}),Yi=(e,n=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const r=(e.width??0)*n[0],s=(e.height??0)*n[1],o={x:e.position.x-r,y:e.position.y-s};return{...o,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-r,y:e.positionAbsolute.y-s}:o}},ru=(e,n=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const r=e.reduce((s,o)=>{const{x:l,y:u}=Yi(o,n).positionAbsolute;return TE(s,ta({x:l,y:u,width:o.width||0,height:o.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return RE(r)},qE=(e,n,[r,s,o]=[0,0,1],l=!1,u=!1,c=[0,0])=>{const p={x:(n.x-r)/o,y:(n.y-s)/o,width:n.width/o,height:n.height/o},h=[];return e.forEach(f=>{const{width:m,height:y,selectable:x=!0,hidden:C=!1}=f;if(u&&!x||C)return!1;const{positionAbsolute:_}=Yi(f,c),S={x:_.x,y:_.y,width:m||0,height:y||0},b=zg(p,S),E=typeof m>"u"||typeof y>"u"||m===null||y===null,N=l&&b>0,T=(m||0)*(y||0);(E||N||b>=T||f.dragging)&&h.push(f)}),h},$E=(e,n)=>{const r=e.map(s=>s.id);return n.filter(s=>r.includes(s.source)||r.includes(s.target))},DE=(e,n,r,s,o,l=.1)=>{const u=n/(e.width*(1+l)),c=r/(e.height*(1+l)),p=Math.min(u,c),h=Qs(p,s,o),f=e.x+e.width/2,m=e.y+e.height/2,y=n/2-f*h,x=r/2-m*h;return{x:y,y:x,zoom:h}},Hi=(e,n=0)=>e.transition().duration(n);function $w(e,n,r,s){return(n[r]||[]).reduce((o,l)=>{var u,c;return`${e.id}-${l.id}-${r}`!==s&&o.push({id:l.id||null,type:r,nodeId:e.id,x:(((u=e.positionAbsolute)==null?void 0:u.x)??0)+l.x+l.width/2,y:(((c=e.positionAbsolute)==null?void 0:c.y)??0)+l.y+l.height/2}),o},[])}function NI(e,n,r,s,o,l){const{x:u,y:c}=di(e),h=n.elementsFromPoint(u,c).find(C=>C.classList.contains("react-flow__handle"));if(h){const C=h.getAttribute("data-nodeid");if(C){const _=gv(void 0,h),S=h.getAttribute("data-handleid"),b=l({nodeId:C,id:S,type:_});if(b){const E=o.find(N=>N.nodeId===C&&N.type===_&&N.id===S);return{handle:{id:S,type:_,nodeId:C,x:(E==null?void 0:E.x)||r.x,y:(E==null?void 0:E.y)||r.y},validHandleResult:b}}}}let f=[],m=1/0;if(o.forEach(C=>{const _=Math.sqrt((C.x-r.x)**2+(C.y-r.y)**2);if(_<=s){const S=l(C);_<=m&&(_<m?f=[{handle:C,validHandleResult:S}]:_===m&&f.push({handle:C,validHandleResult:S}),m=_)}}),!f.length)return{handle:null,validHandleResult:FE()};if(f.length===1)return f[0];const y=f.some(({validHandleResult:C})=>C.isValid),x=f.some(({handle:C})=>C.type==="target");return f.find(({handle:C,validHandleResult:_})=>x?C.type==="target":y?_.isValid:!0)||f[0]}const CI={source:null,target:null,sourceHandle:null,targetHandle:null},FE=()=>({handleDomNode:null,isValid:!1,connection:CI,endHandle:null});function zE(e,n,r,s,o,l,u){const c=o==="target",p=u.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),h={...FE(),handleDomNode:p};if(p){const f=gv(void 0,p),m=p.getAttribute("data-nodeid"),y=p.getAttribute("data-handleid"),x=p.classList.contains("connectable"),C=p.classList.contains("connectableend"),_={source:c?m:r,sourceHandle:c?y:s,target:c?r:m,targetHandle:c?s:y};h.connection=_,x&&C&&(n===Xi.Strict?c&&f==="source"||!c&&f==="target":m!==r||y!==s)&&(h.endHandle={nodeId:m,handleId:y,type:f},h.isValid=l(_))}return h}function TI({nodes:e,nodeId:n,handleId:r,handleType:s}){return e.reduce((o,l)=>{if(l[mt]){const{handleBounds:u}=l[mt];let c=[],p=[];u&&(c=$w(l,u,"source",`${n}-${r}-${s}`),p=$w(l,u,"target",`${n}-${r}-${s}`)),o.push(...c,...p)}return o},[])}function gv(e,n){return e||(n!=null&&n.classList.contains("target")?"target":n!=null&&n.classList.contains("source")?"source":null)}function od(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function RI(e,n){let r=null;return n?r="valid":e&&!n&&(r="invalid"),r}function BE({event:e,handleId:n,nodeId:r,onConnect:s,isTarget:o,getState:l,setState:u,isValidConnection:c,edgeUpdaterType:p,onReconnectEnd:h}){const f=CE(e.target),{connectionMode:m,domNode:y,autoPanOnConnect:x,connectionRadius:C,onConnectStart:_,panBy:S,getNodes:b,cancelConnection:E}=l();let N=0,T;const{x:I,y:M}=di(e),O=f==null?void 0:f.elementFromPoint(I,M),H=gv(p,O),L=y==null?void 0:y.getBoundingClientRect();if(!L||!H)return;let P,q=di(e,L),W=!1,B=null,j=!1,K=null;const U=TI({nodes:b(),nodeId:r,handleId:n,handleType:H}),ee=()=>{if(!x)return;const[Y,k]=NE(q,L);S({x:Y,y:k}),N=requestAnimationFrame(ee)};u({connectionPosition:q,connectionStatus:null,connectionNodeId:r,connectionHandleId:n,connectionHandleType:H,connectionStartHandle:{nodeId:r,handleId:n,type:H},connectionEndHandle:null}),_==null||_(e,{nodeId:r,handleId:n,handleType:H});function J(Y){const{transform:k}=l();q=di(Y,L);const{handle:$,validHandleResult:se}=NI(Y,f,Wg(q,k,!1,[1,1]),C,U,D=>zE(D,m,r,n,o?"target":"source",c,f));if(T=$,W||(ee(),W=!0),K=se.handleDomNode,B=se.connection,j=se.isValid,u({connectionPosition:T&&j?LE({x:T.x,y:T.y},k):q,connectionStatus:RI(!!T,j),connectionEndHandle:se.endHandle}),!T&&!j&&!K)return od(P);B.source!==B.target&&K&&(od(P),P=K,K.classList.add("connecting","react-flow__handle-connecting"),K.classList.toggle("valid",j),K.classList.toggle("react-flow__handle-valid",j))}function F(Y){var k,$;(T||K)&&B&&j&&(s==null||s(B)),($=(k=l()).onConnectEnd)==null||$.call(k,Y),p&&(h==null||h(Y)),od(P),E(),cancelAnimationFrame(N),W=!1,j=!1,B=null,K=null,f.removeEventListener("mousemove",J),f.removeEventListener("mouseup",F),f.removeEventListener("touchmove",J),f.removeEventListener("touchend",F)}f.addEventListener("mousemove",J),f.addEventListener("mouseup",F),f.addEventListener("touchmove",J),f.addEventListener("touchend",F)}const Dw=()=>!0,jI=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),AI=(e,n,r)=>s=>{const{connectionStartHandle:o,connectionEndHandle:l,connectionClickStartHandle:u}=s;return{connecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===n&&(o==null?void 0:o.type)===r||(l==null?void 0:l.nodeId)===e&&(l==null?void 0:l.handleId)===n&&(l==null?void 0:l.type)===r,clickConnecting:(u==null?void 0:u.nodeId)===e&&(u==null?void 0:u.handleId)===n&&(u==null?void 0:u.type)===r}},UE=A.forwardRef(({type:e="source",position:n=Re.Top,isValidConnection:r,isConnectable:s=!0,isConnectableStart:o=!0,isConnectableEnd:l=!0,id:u,onConnect:c,children:p,className:h,onMouseDown:f,onTouchStart:m,...y},x)=>{var L,P;const C=u||null,_=e==="target",S=Et(),b=_I(),{connectOnClick:E,noPanClassName:N}=Ke(jI,kt),{connecting:T,clickConnecting:I}=Ke(AI(b,C,e),kt);b||(P=(L=S.getState()).onError)==null||P.call(L,"010",Mr.error010());const M=q=>{const{defaultEdgeOptions:W,onConnect:B,hasDefaultEdges:j}=S.getState(),K={...W,...q};if(j){const{edges:U,setEdges:ee}=S.getState();ee(EI(K,U))}B==null||B(K),c==null||c(K)},O=q=>{if(!b)return;const W=AE(q);o&&(W&&q.button===0||!W)&&BE({event:q,handleId:C,nodeId:b,onConnect:M,isTarget:_,getState:S.getState,setState:S.setState,isValidConnection:r||S.getState().isValidConnection||Dw}),W?f==null||f(q):m==null||m(q)},H=q=>{const{onClickConnectStart:W,onClickConnectEnd:B,connectionClickStartHandle:j,connectionMode:K,isValidConnection:U}=S.getState();if(!b||!j&&!o)return;if(!j){W==null||W(q,{nodeId:b,handleId:C,handleType:e}),S.setState({connectionClickStartHandle:{nodeId:b,type:e,handleId:C}});return}const ee=CE(q.target),J=r||U||Dw,{connection:F,isValid:Y}=zE({nodeId:b,id:C,type:e},K,j.nodeId,j.handleId||null,j.type,J,ee);Y&&M(F),B==null||B(q),S.setState({connectionClickStartHandle:null})};return le.createElement("div",{"data-handleid":C,"data-nodeid":b,"data-handlepos":n,"data-id":`${b}-${C}-${e}`,className:Dt(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",N,h,{source:!_,target:_,connectable:s,connectablestart:o,connectableend:l,connecting:I,connectionindicator:s&&(o&&!T||l&&T)}]),onMouseDown:O,onTouchStart:O,onClick:E?H:void 0,ref:x,...y},p)});UE.displayName="Handle";var Zs=A.memo(UE);const HE=({data:e,isConnectable:n,targetPosition:r=Re.Top,sourcePosition:s=Re.Bottom})=>le.createElement(le.Fragment,null,le.createElement(Zs,{type:"target",position:r,isConnectable:n}),e==null?void 0:e.label,le.createElement(Zs,{type:"source",position:s,isConnectable:n}));HE.displayName="DefaultNode";var Vg=A.memo(HE);const WE=({data:e,isConnectable:n,sourcePosition:r=Re.Bottom})=>le.createElement(le.Fragment,null,e==null?void 0:e.label,le.createElement(Zs,{type:"source",position:r,isConnectable:n}));WE.displayName="InputNode";var VE=A.memo(WE);const GE=({data:e,isConnectable:n,targetPosition:r=Re.Top})=>le.createElement(le.Fragment,null,le.createElement(Zs,{type:"target",position:r,isConnectable:n}),e==null?void 0:e.label);GE.displayName="OutputNode";var YE=A.memo(GE);const vv=()=>null;vv.displayName="GroupNode";const II=e=>({selectedNodes:e.getNodes().filter(n=>n.selected),selectedEdges:e.edges.filter(n=>n.selected).map(n=>({...n}))}),kl=e=>e.id;function MI(e,n){return kt(e.selectedNodes.map(kl),n.selectedNodes.map(kl))&&kt(e.selectedEdges.map(kl),n.selectedEdges.map(kl))}const KE=A.memo(({onSelectionChange:e})=>{const n=Et(),{selectedNodes:r,selectedEdges:s}=Ke(II,MI);return A.useEffect(()=>{const o={nodes:r,edges:s};e==null||e(o),n.getState().onSelectionChange.forEach(l=>l(o))},[r,s,e]),null});KE.displayName="SelectionListener";const PI=e=>!!e.onSelectionChange;function OI({onSelectionChange:e}){const n=Ke(PI);return e||n?le.createElement(KE,{onSelectionChange:e}):null}const LI=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Ls(e,n){A.useEffect(()=>{typeof e<"u"&&n(e)},[e])}function $e(e,n,r){A.useEffect(()=>{typeof n<"u"&&r({[e]:n})},[n])}const qI=({nodes:e,edges:n,defaultNodes:r,defaultEdges:s,onConnect:o,onConnectStart:l,onConnectEnd:u,onClickConnectStart:c,onClickConnectEnd:p,nodesDraggable:h,nodesConnectable:f,nodesFocusable:m,edgesFocusable:y,edgesUpdatable:x,elevateNodesOnSelect:C,minZoom:_,maxZoom:S,nodeExtent:b,onNodesChange:E,onEdgesChange:N,elementsSelectable:T,connectionMode:I,snapGrid:M,snapToGrid:O,translateExtent:H,connectOnClick:L,defaultEdgeOptions:P,fitView:q,fitViewOptions:W,onNodesDelete:B,onEdgesDelete:j,onNodeDrag:K,onNodeDragStart:U,onNodeDragStop:ee,onSelectionDrag:J,onSelectionDragStart:F,onSelectionDragStop:Y,noPanClassName:k,nodeOrigin:$,rfId:se,autoPanOnConnect:D,autoPanOnNodeDrag:Q,onError:te,connectionRadius:ae,isValidConnection:ce,nodeDragThreshold:me})=>{const{setNodes:ge,setEdges:Pe,setDefaultNodesAndEdges:Se,setMinZoom:Oe,setMaxZoom:Me,setTranslateExtent:be,setNodeExtent:De,reset:ve}=Ke(LI,kt),we=Et();return A.useEffect(()=>{const Ue=s==null?void 0:s.map(ut=>({...ut,...P}));return Se(r,Ue),()=>{ve()}},[]),$e("defaultEdgeOptions",P,we.setState),$e("connectionMode",I,we.setState),$e("onConnect",o,we.setState),$e("onConnectStart",l,we.setState),$e("onConnectEnd",u,we.setState),$e("onClickConnectStart",c,we.setState),$e("onClickConnectEnd",p,we.setState),$e("nodesDraggable",h,we.setState),$e("nodesConnectable",f,we.setState),$e("nodesFocusable",m,we.setState),$e("edgesFocusable",y,we.setState),$e("edgesUpdatable",x,we.setState),$e("elementsSelectable",T,we.setState),$e("elevateNodesOnSelect",C,we.setState),$e("snapToGrid",O,we.setState),$e("snapGrid",M,we.setState),$e("onNodesChange",E,we.setState),$e("onEdgesChange",N,we.setState),$e("connectOnClick",L,we.setState),$e("fitViewOnInit",q,we.setState),$e("fitViewOnInitOptions",W,we.setState),$e("onNodesDelete",B,we.setState),$e("onEdgesDelete",j,we.setState),$e("onNodeDrag",K,we.setState),$e("onNodeDragStart",U,we.setState),$e("onNodeDragStop",ee,we.setState),$e("onSelectionDrag",J,we.setState),$e("onSelectionDragStart",F,we.setState),$e("onSelectionDragStop",Y,we.setState),$e("noPanClassName",k,we.setState),$e("nodeOrigin",$,we.setState),$e("rfId",se,we.setState),$e("autoPanOnConnect",D,we.setState),$e("autoPanOnNodeDrag",Q,we.setState),$e("onError",te,we.setState),$e("connectionRadius",ae,we.setState),$e("isValidConnection",ce,we.setState),$e("nodeDragThreshold",me,we.setState),Ls(e,ge),Ls(n,Pe),Ls(_,Oe),Ls(S,Me),Ls(H,be),Ls(b,De),null},Fw={display:"none"},$I={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},XE="react-flow__node-desc",QE="react-flow__edge-desc",DI="react-flow__aria-live",FI=e=>e.ariaLiveMessage;function zI({rfId:e}){const n=Ke(FI);return le.createElement("div",{id:`${DI}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:$I},n)}function BI({rfId:e,disableKeyboardA11y:n}){return le.createElement(le.Fragment,null,le.createElement("div",{id:`${XE}-${e}`,style:Fw},"Press enter or space to select a node.",!n&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),le.createElement("div",{id:`${QE}-${e}`,style:Fw},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!n&&le.createElement(zI,{rfId:e}))}var ra=(e=null,n={actInsideInputWithModifier:!0})=>{const[r,s]=A.useState(!1),o=A.useRef(!1),l=A.useRef(new Set([])),[u,c]=A.useMemo(()=>{if(e!==null){const h=(Array.isArray(e)?e:[e]).filter(m=>typeof m=="string").map(m=>m.split("+")),f=h.reduce((m,y)=>m.concat(...y),[]);return[h,f]}return[[],[]]},[e]);return A.useEffect(()=>{const p=typeof document<"u"?document:null,h=(n==null?void 0:n.target)||p;if(e!==null){const f=x=>{if(o.current=x.ctrlKey||x.metaKey||x.shiftKey,(!o.current||o.current&&!n.actInsideInputWithModifier)&&Bg(x))return!1;const _=Bw(x.code,c);l.current.add(x[_]),zw(u,l.current,!1)&&(x.preventDefault(),s(!0))},m=x=>{if((!o.current||o.current&&!n.actInsideInputWithModifier)&&Bg(x))return!1;const _=Bw(x.code,c);zw(u,l.current,!0)?(s(!1),l.current.clear()):l.current.delete(x[_]),x.key==="Meta"&&l.current.clear(),o.current=!1},y=()=>{l.current.clear(),s(!1)};return h==null||h.addEventListener("keydown",f),h==null||h.addEventListener("keyup",m),window.addEventListener("blur",y),()=>{h==null||h.removeEventListener("keydown",f),h==null||h.removeEventListener("keyup",m),window.removeEventListener("blur",y)}}},[e,s]),r};function zw(e,n,r){return e.filter(s=>r||s.length===n.size).some(s=>s.every(o=>n.has(o)))}function Bw(e,n){return n.includes(e)?"code":"key"}function ZE(e,n,r,s){var c,p;const o=e.parentNode||e.parentId;if(!o)return r;const l=n.get(o),u=Yi(l,s);return ZE(l,n,{x:(r.x??0)+u.x,y:(r.y??0)+u.y,z:(((c=l[mt])==null?void 0:c.z)??0)>(r.z??0)?((p=l[mt])==null?void 0:p.z)??0:r.z??0},s)}function JE(e,n,r){e.forEach(s=>{var l;const o=s.parentNode||s.parentId;if(o&&!e.has(o))throw new Error(`Parent node ${o} not found`);if(o||r!=null&&r[s.id]){const{x:u,y:c,z:p}=ZE(s,e,{...s.position,z:((l=s[mt])==null?void 0:l.z)??0},n);s.positionAbsolute={x:u,y:c},s[mt].z=p,r!=null&&r[s.id]&&(s[mt].isParent=!0)}})}function ad(e,n,r,s){const o=new Map,l={},u=s?1e3:0;return e.forEach(c=>{var x;const p=(Rn(c.zIndex)?c.zIndex:0)+(c.selected?u:0),h=n.get(c.id),f={...c,positionAbsolute:{x:c.position.x,y:c.position.y}},m=c.parentNode||c.parentId;m&&(l[m]=!0);const y=(h==null?void 0:h.type)&&(h==null?void 0:h.type)!==c.type;Object.defineProperty(f,mt,{enumerable:!1,value:{handleBounds:y||(x=h==null?void 0:h[mt])==null?void 0:x.handleBounds,z:p}}),o.set(c.id,f)}),JE(o,r,l),o}function eN(e,n={}){const{getNodes:r,width:s,height:o,minZoom:l,maxZoom:u,d3Zoom:c,d3Selection:p,fitViewOnInitDone:h,fitViewOnInit:f,nodeOrigin:m}=e(),y=n.initial&&!h&&f;if(c&&p&&(y||!n.initial)){const C=r().filter(S=>{var E;const b=n.includeHiddenNodes?S.width&&S.height:!S.hidden;return(E=n.nodes)!=null&&E.length?b&&n.nodes.some(N=>N.id===S.id):b}),_=C.every(S=>S.width&&S.height);if(C.length>0&&_){const S=ru(C,m),{x:b,y:E,zoom:N}=DE(S,s,o,n.minZoom??l,n.maxZoom??u,n.padding??.1),T=Ar.translate(b,E).scale(N);return typeof n.duration=="number"&&n.duration>0?c.transform(Hi(p,n.duration),T):c.transform(p,T),!0}}return!1}function UI(e,n){return e.forEach(r=>{const s=n.get(r.id);s&&n.set(s.id,{...s,[mt]:s[mt],selected:r.selected})}),new Map(n)}function HI(e,n){return n.map(r=>{const s=e.find(o=>o.id===r.id);return s&&(r.selected=s.selected),r})}function El({changedNodes:e,changedEdges:n,get:r,set:s}){const{nodeInternals:o,edges:l,onNodesChange:u,onEdgesChange:c,hasDefaultNodes:p,hasDefaultEdges:h}=r();e!=null&&e.length&&(p&&s({nodeInternals:UI(e,o)}),u==null||u(e)),n!=null&&n.length&&(h&&s({edges:HI(n,l)}),c==null||c(n))}const qs=()=>{},WI={zoomIn:qs,zoomOut:qs,zoomTo:qs,getZoom:()=>1,setViewport:qs,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:qs,fitBounds:qs,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},VI=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),GI=()=>{const e=Et(),{d3Zoom:n,d3Selection:r}=Ke(VI,kt);return A.useMemo(()=>r&&n?{zoomIn:o=>n.scaleBy(Hi(r,o==null?void 0:o.duration),1.2),zoomOut:o=>n.scaleBy(Hi(r,o==null?void 0:o.duration),1/1.2),zoomTo:(o,l)=>n.scaleTo(Hi(r,l==null?void 0:l.duration),o),getZoom:()=>e.getState().transform[2],setViewport:(o,l)=>{const[u,c,p]=e.getState().transform,h=Ar.translate(o.x??u,o.y??c).scale(o.zoom??p);n.transform(Hi(r,l==null?void 0:l.duration),h)},getViewport:()=>{const[o,l,u]=e.getState().transform;return{x:o,y:l,zoom:u}},fitView:o=>eN(e.getState,o),setCenter:(o,l,u)=>{const{width:c,height:p,maxZoom:h}=e.getState(),f=typeof(u==null?void 0:u.zoom)<"u"?u.zoom:h,m=c/2-o*f,y=p/2-l*f,x=Ar.translate(m,y).scale(f);n.transform(Hi(r,u==null?void 0:u.duration),x)},fitBounds:(o,l)=>{const{width:u,height:c,minZoom:p,maxZoom:h}=e.getState(),{x:f,y:m,zoom:y}=DE(o,u,c,p,h,(l==null?void 0:l.padding)??.1),x=Ar.translate(f,m).scale(y);n.transform(Hi(r,l==null?void 0:l.duration),x)},project:o=>{const{transform:l,snapToGrid:u,snapGrid:c}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),Wg(o,l,u,c)},screenToFlowPosition:o=>{const{transform:l,snapToGrid:u,snapGrid:c,domNode:p}=e.getState();if(!p)return o;const{x:h,y:f}=p.getBoundingClientRect(),m={x:o.x-h,y:o.y-f};return Wg(m,l,u,c)},flowToScreenPosition:o=>{const{transform:l,domNode:u}=e.getState();if(!u)return o;const{x:c,y:p}=u.getBoundingClientRect(),h=LE(o,l);return{x:h.x+c,y:h.y+p}},viewportInitialized:!0}:WI,[n,r])};function ca(){const e=GI(),n=Et(),r=A.useCallback(()=>n.getState().getNodes().map(_=>({..._})),[]),s=A.useCallback(_=>n.getState().nodeInternals.get(_),[]),o=A.useCallback(()=>{const{edges:_=[]}=n.getState();return _.map(S=>({...S}))},[]),l=A.useCallback(_=>{const{edges:S=[]}=n.getState();return S.find(b=>b.id===_)},[]),u=A.useCallback(_=>{const{getNodes:S,setNodes:b,hasDefaultNodes:E,onNodesChange:N}=n.getState(),T=S(),I=typeof _=="function"?_(T):_;if(E)b(I);else if(N){const M=I.length===0?T.map(O=>({type:"remove",id:O.id})):I.map(O=>({item:O,type:"reset"}));N(M)}},[]),c=A.useCallback(_=>{const{edges:S=[],setEdges:b,hasDefaultEdges:E,onEdgesChange:N}=n.getState(),T=typeof _=="function"?_(S):_;if(E)b(T);else if(N){const I=T.length===0?S.map(M=>({type:"remove",id:M.id})):T.map(M=>({item:M,type:"reset"}));N(I)}},[]),p=A.useCallback(_=>{const S=Array.isArray(_)?_:[_],{getNodes:b,setNodes:E,hasDefaultNodes:N,onNodesChange:T}=n.getState();if(N){const M=[...b(),...S];E(M)}else if(T){const I=S.map(M=>({item:M,type:"add"}));T(I)}},[]),h=A.useCallback(_=>{const S=Array.isArray(_)?_:[_],{edges:b=[],setEdges:E,hasDefaultEdges:N,onEdgesChange:T}=n.getState();if(N)E([...b,...S]);else if(T){const I=S.map(M=>({item:M,type:"add"}));T(I)}},[]),f=A.useCallback(()=>{const{getNodes:_,edges:S=[],transform:b}=n.getState(),[E,N,T]=b;return{nodes:_().map(I=>({...I})),edges:S.map(I=>({...I})),viewport:{x:E,y:N,zoom:T}}},[]),m=A.useCallback(({nodes:_,edges:S})=>{const{nodeInternals:b,getNodes:E,edges:N,hasDefaultNodes:T,hasDefaultEdges:I,onNodesDelete:M,onEdgesDelete:O,onNodesChange:H,onEdgesChange:L}=n.getState(),P=(_||[]).map(K=>K.id),q=(S||[]).map(K=>K.id),W=E().reduce((K,U)=>{const ee=U.parentNode||U.parentId,J=!P.includes(U.id)&&ee&&K.find(Y=>Y.id===ee);return(typeof U.deletable=="boolean"?U.deletable:!0)&&(P.includes(U.id)||J)&&K.push(U),K},[]),B=N.filter(K=>typeof K.deletable=="boolean"?K.deletable:!0),j=B.filter(K=>q.includes(K.id));if(W||j){const K=$E(W,B),U=[...j,...K],ee=U.reduce((J,F)=>(J.includes(F.id)||J.push(F.id),J),[]);if((I||T)&&(I&&n.setState({edges:N.filter(J=>!ee.includes(J.id))}),T&&(W.forEach(J=>{b.delete(J.id)}),n.setState({nodeInternals:new Map(b)}))),ee.length>0&&(O==null||O(U),L&&L(ee.map(J=>({id:J,type:"remove"})))),W.length>0&&(M==null||M(W),H)){const J=W.map(F=>({id:F.id,type:"remove"}));H(J)}}},[]),y=A.useCallback(_=>{const S=hI(_),b=S?null:n.getState().nodeInternals.get(_.id);return!S&&!b?[null,null,S]:[S?_:Mw(b),b,S]},[]),x=A.useCallback((_,S=!0,b)=>{const[E,N,T]=y(_);return E?(b||n.getState().getNodes()).filter(I=>{if(!T&&(I.id===N.id||!I.positionAbsolute))return!1;const M=Mw(I),O=zg(M,E);return S&&O>0||O>=E.width*E.height}):[]},[]),C=A.useCallback((_,S,b=!0)=>{const[E]=y(_);if(!E)return!1;const N=zg(E,S);return b&&N>0||N>=E.width*E.height},[]);return A.useMemo(()=>({...e,getNodes:r,getNode:s,getEdges:o,getEdge:l,setNodes:u,setEdges:c,addNodes:p,addEdges:h,toObject:f,deleteElements:m,getIntersectingNodes:x,isNodeIntersecting:C}),[e,r,s,o,l,u,c,p,h,f,m,x,C])}const YI={actInsideInputWithModifier:!1};var KI=({deleteKeyCode:e,multiSelectionKeyCode:n})=>{const r=Et(),{deleteElements:s}=ca(),o=ra(e,YI),l=ra(n);A.useEffect(()=>{if(o){const{edges:u,getNodes:c}=r.getState(),p=c().filter(f=>f.selected),h=u.filter(f=>f.selected);s({nodes:p,edges:h}),r.setState({nodesSelectionActive:!1})}},[o]),A.useEffect(()=>{r.setState({multiSelectionActive:l})},[l])};function XI(e){const n=Et();A.useEffect(()=>{let r;const s=()=>{var l,u;if(!e.current)return;const o=cv(e.current);(o.height===0||o.width===0)&&((u=(l=n.getState()).onError)==null||u.call(l,"004",Mr.error004())),n.setState({width:o.width||500,height:o.height||500})};return s(),window.addEventListener("resize",s),e.current&&(r=new ResizeObserver(()=>s()),r.observe(e.current)),()=>{window.removeEventListener("resize",s),r&&e.current&&r.unobserve(e.current)}},[])}const yv={position:"absolute",width:"100%",height:"100%",top:0,left:0},QI=(e,n)=>e.x!==n.x||e.y!==n.y||e.zoom!==n.k,Nl=e=>({x:e.x,y:e.y,zoom:e.k}),$s=(e,n)=>e.target.closest(`.${n}`),Uw=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),Hw=e=>{const n=e.ctrlKey&&Hl()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n},ZI=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),JI=({onMove:e,onMoveStart:n,onMoveEnd:r,onPaneContextMenu:s,zoomOnScroll:o=!0,zoomOnPinch:l=!0,panOnScroll:u=!1,panOnScrollSpeed:c=.5,panOnScrollMode:p=Vi.Free,zoomOnDoubleClick:h=!0,elementsSelectable:f,panOnDrag:m=!0,defaultViewport:y,translateExtent:x,minZoom:C,maxZoom:_,zoomActivationKeyCode:S,preventScrolling:b=!0,children:E,noWheelClassName:N,noPanClassName:T})=>{const I=A.useRef(),M=Et(),O=A.useRef(!1),H=A.useRef(!1),L=A.useRef(null),P=A.useRef({x:0,y:0,zoom:0}),{d3Zoom:q,d3Selection:W,d3ZoomHandler:B,userSelectionActive:j}=Ke(ZI,kt),K=ra(S),U=A.useRef(0),ee=A.useRef(!1),J=A.useRef();return XI(L),A.useEffect(()=>{if(L.current){const F=L.current.getBoundingClientRect(),Y=kE().scaleExtent([C,_]).translateExtent(x),k=Tn(L.current).call(Y),$=Ar.translate(y.x,y.y).scale(Qs(y.zoom,C,_)),se=[[0,0],[F.width,F.height]],D=Y.constrain()($,se,x);Y.transform(k,D),Y.wheelDelta(Hw),M.setState({d3Zoom:Y,d3Selection:k,d3ZoomHandler:k.on("wheel.zoom"),transform:[D.x,D.y,D.k],domNode:L.current.closest(".react-flow")})}},[]),A.useEffect(()=>{W&&q&&(u&&!K&&!j?W.on("wheel.zoom",F=>{if($s(F,N))return!1;F.preventDefault(),F.stopImmediatePropagation();const Y=W.property("__zoom").k||1;if(F.ctrlKey&&l){const ce=Xn(F),me=Hw(F),ge=Y*Math.pow(2,me);q.scaleTo(W,ge,ce,F);return}const k=F.deltaMode===1?20:1;let $=p===Vi.Vertical?0:F.deltaX*k,se=p===Vi.Horizontal?0:F.deltaY*k;!Hl()&&F.shiftKey&&p!==Vi.Vertical&&($=F.deltaY*k,se=0),q.translateBy(W,-($/Y)*c,-(se/Y)*c,{internal:!0});const D=Nl(W.property("__zoom")),{onViewportChangeStart:Q,onViewportChange:te,onViewportChangeEnd:ae}=M.getState();clearTimeout(J.current),ee.current||(ee.current=!0,n==null||n(F,D),Q==null||Q(D)),ee.current&&(e==null||e(F,D),te==null||te(D),J.current=setTimeout(()=>{r==null||r(F,D),ae==null||ae(D),ee.current=!1},150))},{passive:!1}):typeof B<"u"&&W.on("wheel.zoom",function(F,Y){if(!b&&F.type==="wheel"&&!F.ctrlKey||$s(F,N))return null;F.preventDefault(),B.call(this,F,Y)},{passive:!1}))},[j,u,p,W,q,B,K,l,b,N,n,e,r]),A.useEffect(()=>{q&&q.on("start",F=>{var $,se;if(!F.sourceEvent||F.sourceEvent.internal)return null;U.current=($=F.sourceEvent)==null?void 0:$.button;const{onViewportChangeStart:Y}=M.getState(),k=Nl(F.transform);O.current=!0,P.current=k,((se=F.sourceEvent)==null?void 0:se.type)==="mousedown"&&M.setState({paneDragging:!0}),Y==null||Y(k),n==null||n(F.sourceEvent,k)})},[q,n]),A.useEffect(()=>{q&&(j&&!O.current?q.on("zoom",null):j||q.on("zoom",F=>{var k;const{onViewportChange:Y}=M.getState();if(M.setState({transform:[F.transform.x,F.transform.y,F.transform.k]}),H.current=!!(s&&Uw(m,U.current??0)),(e||Y)&&!((k=F.sourceEvent)!=null&&k.internal)){const $=Nl(F.transform);Y==null||Y($),e==null||e(F.sourceEvent,$)}}))},[j,q,e,m,s]),A.useEffect(()=>{q&&q.on("end",F=>{if(!F.sourceEvent||F.sourceEvent.internal)return null;const{onViewportChangeEnd:Y}=M.getState();if(O.current=!1,M.setState({paneDragging:!1}),s&&Uw(m,U.current??0)&&!H.current&&s(F.sourceEvent),H.current=!1,(r||Y)&&QI(P.current,F.transform)){const k=Nl(F.transform);P.current=k,clearTimeout(I.current),I.current=setTimeout(()=>{Y==null||Y(k),r==null||r(F.sourceEvent,k)},u?150:0)}})},[q,u,m,r,s]),A.useEffect(()=>{q&&q.filter(F=>{const Y=K||o,k=l&&F.ctrlKey;if((m===!0||Array.isArray(m)&&m.includes(1))&&F.button===1&&F.type==="mousedown"&&($s(F,"react-flow__node")||$s(F,"react-flow__edge")))return!0;if(!m&&!Y&&!u&&!h&&!l||j||!h&&F.type==="dblclick"||$s(F,N)&&F.type==="wheel"||$s(F,T)&&(F.type!=="wheel"||u&&F.type==="wheel"&&!K)||!l&&F.ctrlKey&&F.type==="wheel"||!Y&&!u&&!k&&F.type==="wheel"||!m&&(F.type==="mousedown"||F.type==="touchstart")||Array.isArray(m)&&!m.includes(F.button)&&F.type==="mousedown")return!1;const $=Array.isArray(m)&&m.includes(F.button)||!F.button||F.button<=1;return(!F.ctrlKey||F.type==="wheel")&&$})},[j,q,o,l,u,h,m,f,K]),le.createElement("div",{className:"react-flow__renderer",ref:L,style:yv},E)},eM=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function tM(){const{userSelectionActive:e,userSelectionRect:n}=Ke(eM,kt);return e&&n?le.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:n.width,height:n.height,transform:`translate(${n.x}px, ${n.y}px)`}}):null}function Ww(e,n){const r=n.parentNode||n.parentId,s=e.find(o=>o.id===r);if(s){const o=n.position.x+n.width-s.width,l=n.position.y+n.height-s.height;if(o>0||l>0||n.position.x<0||n.position.y<0){if(s.style={...s.style},s.style.width=s.style.width??s.width,s.style.height=s.style.height??s.height,o>0&&(s.style.width+=o),l>0&&(s.style.height+=l),n.position.x<0){const u=Math.abs(n.position.x);s.position.x=s.position.x-u,s.style.width+=u,n.position.x=0}if(n.position.y<0){const u=Math.abs(n.position.y);s.position.y=s.position.y-u,s.style.height+=u,n.position.y=0}s.width=s.style.width,s.height=s.style.height}}}function nM(e,n){if(e.some(s=>s.type==="reset"))return e.filter(s=>s.type==="reset").map(s=>s.item);const r=e.filter(s=>s.type==="add").map(s=>s.item);return n.reduce((s,o)=>{const l=e.filter(c=>c.id===o.id);if(l.length===0)return s.push(o),s;const u={...o};for(const c of l)if(c)switch(c.type){case"select":{u.selected=c.selected;break}case"position":{typeof c.position<"u"&&(u.position=c.position),typeof c.positionAbsolute<"u"&&(u.positionAbsolute=c.positionAbsolute),typeof c.dragging<"u"&&(u.dragging=c.dragging),u.expandParent&&Ww(s,u);break}case"dimensions":{typeof c.dimensions<"u"&&(u.width=c.dimensions.width,u.height=c.dimensions.height),typeof c.updateStyle<"u"&&(u.style={...u.style||{},...c.dimensions}),typeof c.resizing=="boolean"&&(u.resizing=c.resizing),u.expandParent&&Ww(s,u);break}case"remove":return s}return s.push(u),s},r)}function rM(e,n){return nM(e,n)}const ui=(e,n)=>({id:e,type:"select",selected:n});function Bs(e,n){return e.reduce((r,s)=>{const o=n.includes(s.id);return!s.selected&&o?(s.selected=!0,r.push(ui(s.id,!0))):s.selected&&!o&&(s.selected=!1,r.push(ui(s.id,!1))),r},[])}const ld=(e,n)=>r=>{r.target===n.current&&(e==null||e(r))},iM=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),tN=A.memo(({isSelecting:e,selectionMode:n=na.Full,panOnDrag:r,onSelectionStart:s,onSelectionEnd:o,onPaneClick:l,onPaneContextMenu:u,onPaneScroll:c,onPaneMouseEnter:p,onPaneMouseMove:h,onPaneMouseLeave:f,children:m})=>{const y=A.useRef(null),x=Et(),C=A.useRef(0),_=A.useRef(0),S=A.useRef(),{userSelectionActive:b,elementsSelectable:E,dragging:N}=Ke(iM,kt),T=()=>{x.setState({userSelectionActive:!1,userSelectionRect:null}),C.current=0,_.current=0},I=B=>{l==null||l(B),x.getState().resetSelectedElements(),x.setState({nodesSelectionActive:!1})},M=B=>{if(Array.isArray(r)&&(r!=null&&r.includes(2))){B.preventDefault();return}u==null||u(B)},O=c?B=>c(B):void 0,H=B=>{const{resetSelectedElements:j,domNode:K}=x.getState();if(S.current=K==null?void 0:K.getBoundingClientRect(),!E||!e||B.button!==0||B.target!==y.current||!S.current)return;const{x:U,y:ee}=di(B,S.current);j(),x.setState({userSelectionRect:{width:0,height:0,startX:U,startY:ee,x:U,y:ee}}),s==null||s(B)},L=B=>{const{userSelectionRect:j,nodeInternals:K,edges:U,transform:ee,onNodesChange:J,onEdgesChange:F,nodeOrigin:Y,getNodes:k}=x.getState();if(!e||!S.current||!j)return;x.setState({userSelectionActive:!0,nodesSelectionActive:!1});const $=di(B,S.current),se=j.startX??0,D=j.startY??0,Q={...j,x:$.x<se?$.x:se,y:$.y<D?$.y:D,width:Math.abs($.x-se),height:Math.abs($.y-D)},te=k(),ae=qE(K,Q,ee,n===na.Partial,!0,Y),ce=$E(ae,U).map(ge=>ge.id),me=ae.map(ge=>ge.id);if(C.current!==me.length){C.current=me.length;const ge=Bs(te,me);ge.length&&(J==null||J(ge))}if(_.current!==ce.length){_.current=ce.length;const ge=Bs(U,ce);ge.length&&(F==null||F(ge))}x.setState({userSelectionRect:Q})},P=B=>{if(B.button!==0)return;const{userSelectionRect:j}=x.getState();!b&&j&&B.target===y.current&&(I==null||I(B)),x.setState({nodesSelectionActive:C.current>0}),T(),o==null||o(B)},q=B=>{b&&(x.setState({nodesSelectionActive:C.current>0}),o==null||o(B)),T()},W=E&&(e||b);return le.createElement("div",{className:Dt(["react-flow__pane",{dragging:N,selection:e}]),onClick:W?void 0:ld(I,y),onContextMenu:ld(M,y),onWheel:ld(O,y),onMouseEnter:W?void 0:p,onMouseDown:W?H:void 0,onMouseMove:W?L:h,onMouseUp:W?P:void 0,onMouseLeave:W?q:f,ref:y,style:yv},m,le.createElement(tM,null))});tN.displayName="Pane";function nN(e,n){const r=e.parentNode||e.parentId;if(!r)return!1;const s=n.get(r);return s?s.selected?!0:nN(s,n):!1}function Vw(e,n,r){let s=e;do{if(s!=null&&s.matches(n))return!0;if(s===r.current)return!1;s=s.parentElement}while(s);return!1}function sM(e,n,r,s){return Array.from(e.values()).filter(o=>(o.selected||o.id===s)&&(!o.parentNode||o.parentId||!nN(o,e))&&(o.draggable||n&&typeof o.draggable>"u")).map(o=>{var l,u;return{id:o.id,position:o.position||{x:0,y:0},positionAbsolute:o.positionAbsolute||{x:0,y:0},distance:{x:r.x-(((l=o.positionAbsolute)==null?void 0:l.x)??0),y:r.y-(((u=o.positionAbsolute)==null?void 0:u.y)??0)},delta:{x:0,y:0},extent:o.extent,parentNode:o.parentNode||o.parentId,parentId:o.parentNode||o.parentId,width:o.width,height:o.height,expandParent:o.expandParent}})}function oM(e,n){return!n||n==="parent"?n:[n[0],[n[1][0]-(e.width||0),n[1][1]-(e.height||0)]]}function rN(e,n,r,s,o=[0,0],l){const u=oM(e,e.extent||s);let c=u;const p=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(p&&e.width&&e.height){const m=r.get(p),{x:y,y:x}=Yi(m,o).positionAbsolute;c=m&&Rn(y)&&Rn(x)&&Rn(m.width)&&Rn(m.height)?[[y+e.width*o[0],x+e.height*o[1]],[y+m.width-e.width+e.width*o[0],x+m.height-e.height+e.height*o[1]]]:c}else l==null||l("005",Mr.error005()),c=u;else if(e.extent&&p&&e.extent!=="parent"){const m=r.get(p),{x:y,y:x}=Yi(m,o).positionAbsolute;c=[[e.extent[0][0]+y,e.extent[0][1]+x],[e.extent[1][0]+y,e.extent[1][1]+x]]}let h={x:0,y:0};if(p){const m=r.get(p);h=Yi(m,o).positionAbsolute}const f=c&&c!=="parent"?dv(n,c):n;return{position:{x:f.x-h.x,y:f.y-h.y},positionAbsolute:f}}function ud({nodeId:e,dragItems:n,nodeInternals:r}){const s=n.map(o=>({...r.get(o.id),position:o.position,positionAbsolute:o.positionAbsolute}));return[e?s.find(o=>o.id===e):s[0],s]}const Gw=(e,n,r,s)=>{const o=n.querySelectorAll(e);if(!o||!o.length)return null;const l=Array.from(o),u=n.getBoundingClientRect(),c={x:u.width*s[0],y:u.height*s[1]};return l.map(p=>{const h=p.getBoundingClientRect();return{id:p.getAttribute("data-handleid"),position:p.getAttribute("data-handlepos"),x:(h.left-u.left-c.x)/r,y:(h.top-u.top-c.y)/r,...cv(p)}})};function zo(e,n,r){return r===void 0?r:s=>{const o=n().nodeInternals.get(e);o&&r(s,{...o})}}function Gg({id:e,store:n,unselect:r=!1,nodeRef:s}){const{addSelectedNodes:o,unselectNodesAndEdges:l,multiSelectionActive:u,nodeInternals:c,onError:p}=n.getState(),h=c.get(e);if(!h){p==null||p("012",Mr.error012(e));return}n.setState({nodesSelectionActive:!1}),h.selected?(r||h.selected&&u)&&(l({nodes:[h],edges:[]}),requestAnimationFrame(()=>{var f;return(f=s==null?void 0:s.current)==null?void 0:f.blur()})):o([e])}function aM(){const e=Et();return A.useCallback(({sourceEvent:r})=>{const{transform:s,snapGrid:o,snapToGrid:l}=e.getState(),u=r.touches?r.touches[0].clientX:r.clientX,c=r.touches?r.touches[0].clientY:r.clientY,p={x:(u-s[0])/s[2],y:(c-s[1])/s[2]};return{xSnapped:l?o[0]*Math.round(p.x/o[0]):p.x,ySnapped:l?o[1]*Math.round(p.y/o[1]):p.y,...p}},[])}function cd(e){return(n,r,s)=>e==null?void 0:e(n,s)}function iN({nodeRef:e,disabled:n=!1,noDragClassName:r,handleSelector:s,nodeId:o,isSelectable:l,selectNodesOnDrag:u}){const c=Et(),[p,h]=A.useState(!1),f=A.useRef([]),m=A.useRef({x:null,y:null}),y=A.useRef(0),x=A.useRef(null),C=A.useRef({x:0,y:0}),_=A.useRef(null),S=A.useRef(!1),b=A.useRef(!1),E=A.useRef(!1),N=aM();return A.useEffect(()=>{if(e!=null&&e.current){const T=Tn(e.current),I=({x:H,y:L})=>{const{nodeInternals:P,onNodeDrag:q,onSelectionDrag:W,updateNodePositions:B,nodeExtent:j,snapGrid:K,snapToGrid:U,nodeOrigin:ee,onError:J}=c.getState();m.current={x:H,y:L};let F=!1,Y={x:0,y:0,x2:0,y2:0};if(f.current.length>1&&j){const $=ru(f.current,ee);Y=ta($)}if(f.current=f.current.map($=>{const se={x:H-$.distance.x,y:L-$.distance.y};U&&(se.x=K[0]*Math.round(se.x/K[0]),se.y=K[1]*Math.round(se.y/K[1]));const D=[[j[0][0],j[0][1]],[j[1][0],j[1][1]]];f.current.length>1&&j&&!$.extent&&(D[0][0]=$.positionAbsolute.x-Y.x+j[0][0],D[1][0]=$.positionAbsolute.x+($.width??0)-Y.x2+j[1][0],D[0][1]=$.positionAbsolute.y-Y.y+j[0][1],D[1][1]=$.positionAbsolute.y+($.height??0)-Y.y2+j[1][1]);const Q=rN($,se,P,D,ee,J);return F=F||$.position.x!==Q.position.x||$.position.y!==Q.position.y,$.position=Q.position,$.positionAbsolute=Q.positionAbsolute,$}),!F)return;B(f.current,!0,!0),h(!0);const k=o?q:cd(W);if(k&&_.current){const[$,se]=ud({nodeId:o,dragItems:f.current,nodeInternals:P});k(_.current,$,se)}},M=()=>{if(!x.current)return;const[H,L]=NE(C.current,x.current);if(H!==0||L!==0){const{transform:P,panBy:q}=c.getState();m.current.x=(m.current.x??0)-H/P[2],m.current.y=(m.current.y??0)-L/P[2],q({x:H,y:L})&&I(m.current)}y.current=requestAnimationFrame(M)},O=H=>{var ee;const{nodeInternals:L,multiSelectionActive:P,nodesDraggable:q,unselectNodesAndEdges:W,onNodeDragStart:B,onSelectionDragStart:j}=c.getState();b.current=!0;const K=o?B:cd(j);(!u||!l)&&!P&&o&&((ee=L.get(o))!=null&&ee.selected||W()),o&&l&&u&&Gg({id:o,store:c,nodeRef:e});const U=N(H);if(m.current=U,f.current=sM(L,q,U,o),K&&f.current){const[J,F]=ud({nodeId:o,dragItems:f.current,nodeInternals:L});K(H.sourceEvent,J,F)}};if(n)T.on(".drag",null);else{const H=g2().on("start",L=>{const{domNode:P,nodeDragThreshold:q}=c.getState();q===0&&O(L),E.current=!1;const W=N(L);m.current=W,x.current=(P==null?void 0:P.getBoundingClientRect())||null,C.current=di(L.sourceEvent,x.current)}).on("drag",L=>{var B,j;const P=N(L),{autoPanOnNodeDrag:q,nodeDragThreshold:W}=c.getState();if(L.sourceEvent.type==="touchmove"&&L.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!S.current&&b.current&&q&&(S.current=!0,M()),!b.current){const K=P.xSnapped-(((B=m==null?void 0:m.current)==null?void 0:B.x)??0),U=P.ySnapped-(((j=m==null?void 0:m.current)==null?void 0:j.y)??0);Math.sqrt(K*K+U*U)>W&&O(L)}(m.current.x!==P.xSnapped||m.current.y!==P.ySnapped)&&f.current&&b.current&&(_.current=L.sourceEvent,C.current=di(L.sourceEvent,x.current),I(P))}}).on("end",L=>{if(!(!b.current||E.current)&&(h(!1),S.current=!1,b.current=!1,cancelAnimationFrame(y.current),f.current)){const{updateNodePositions:P,nodeInternals:q,onNodeDragStop:W,onSelectionDragStop:B}=c.getState(),j=o?W:cd(B);if(P(f.current,!1,!1),j){const[K,U]=ud({nodeId:o,dragItems:f.current,nodeInternals:q});j(L.sourceEvent,K,U)}}}).filter(L=>{const P=L.target;return!L.button&&(!r||!Vw(P,`.${r}`,e))&&(!s||Vw(P,s,e))});return T.call(H),()=>{T.on(".drag",null)}}}},[e,n,r,s,l,c,o,u,N]),p}function sN(){const e=Et();return A.useCallback(r=>{const{nodeInternals:s,nodeExtent:o,updateNodePositions:l,getNodes:u,snapToGrid:c,snapGrid:p,onError:h,nodesDraggable:f}=e.getState(),m=u().filter(E=>E.selected&&(E.draggable||f&&typeof E.draggable>"u")),y=c?p[0]:5,x=c?p[1]:5,C=r.isShiftPressed?4:1,_=r.x*y*C,S=r.y*x*C,b=m.map(E=>{if(E.positionAbsolute){const N={x:E.positionAbsolute.x+_,y:E.positionAbsolute.y+S};c&&(N.x=p[0]*Math.round(N.x/p[0]),N.y=p[1]*Math.round(N.y/p[1]));const{positionAbsolute:T,position:I}=rN(E,N,s,o,void 0,h);E.position=I,E.positionAbsolute=T}return E});l(b,!0,!1)},[])}const Gs={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bo=e=>{const n=({id:r,type:s,data:o,xPos:l,yPos:u,xPosOrigin:c,yPosOrigin:p,selected:h,onClick:f,onMouseEnter:m,onMouseMove:y,onMouseLeave:x,onContextMenu:C,onDoubleClick:_,style:S,className:b,isDraggable:E,isSelectable:N,isConnectable:T,isFocusable:I,selectNodesOnDrag:M,sourcePosition:O,targetPosition:H,hidden:L,resizeObserver:P,dragHandle:q,zIndex:W,isParent:B,noDragClassName:j,noPanClassName:K,initialized:U,disableKeyboardA11y:ee,ariaLabel:J,rfId:F,hasHandleBounds:Y})=>{const k=Et(),$=A.useRef(null),se=A.useRef(null),D=A.useRef(O),Q=A.useRef(H),te=A.useRef(s),ae=N||E||f||m||y||x,ce=sN(),me=zo(r,k.getState,m),ge=zo(r,k.getState,y),Pe=zo(r,k.getState,x),Se=zo(r,k.getState,C),Oe=zo(r,k.getState,_),Me=ve=>{const{nodeDragThreshold:we}=k.getState();if(N&&(!M||!E||we>0)&&Gg({id:r,store:k,nodeRef:$}),f){const Ue=k.getState().nodeInternals.get(r);Ue&&f(ve,{...Ue})}},be=ve=>{if(!Bg(ve)&&!ee)if(jE.includes(ve.key)&&N){const we=ve.key==="Escape";Gg({id:r,store:k,unselect:we,nodeRef:$})}else E&&h&&Object.prototype.hasOwnProperty.call(Gs,ve.key)&&(k.setState({ariaLiveMessage:`Moved selected node ${ve.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~l}, y: ${~~u}`}),ce({x:Gs[ve.key].x,y:Gs[ve.key].y,isShiftPressed:ve.shiftKey}))};A.useEffect(()=>()=>{se.current&&(P==null||P.unobserve(se.current),se.current=null)},[]),A.useEffect(()=>{if($.current&&!L){const ve=$.current;(!U||!Y||se.current!==ve)&&(se.current&&(P==null||P.unobserve(se.current)),P==null||P.observe(ve),se.current=ve)}},[L,U,Y]),A.useEffect(()=>{const ve=te.current!==s,we=D.current!==O,Ue=Q.current!==H;$.current&&(ve||we||Ue)&&(ve&&(te.current=s),we&&(D.current=O),Ue&&(Q.current=H),k.getState().updateNodeDimensions([{id:r,nodeElement:$.current,forceUpdate:!0}]))},[r,s,O,H]);const De=iN({nodeRef:$,disabled:L||!E,noDragClassName:j,handleSelector:q,nodeId:r,isSelectable:N,selectNodesOnDrag:M});return L?null:le.createElement("div",{className:Dt(["react-flow__node",`react-flow__node-${s}`,{[K]:E},b,{selected:h,selectable:N,parent:B,dragging:De}]),ref:$,style:{zIndex:W,transform:`translate(${c}px,${p}px)`,pointerEvents:ae?"all":"none",visibility:U?"visible":"hidden",...S},"data-id":r,"data-testid":`rf__node-${r}`,onMouseEnter:me,onMouseMove:ge,onMouseLeave:Pe,onContextMenu:Se,onClick:Me,onDoubleClick:Oe,onKeyDown:I?be:void 0,tabIndex:I?0:void 0,role:I?"button":void 0,"aria-describedby":ee?void 0:`${XE}-${F}`,"aria-label":J},le.createElement(xI,{value:r},le.createElement(e,{id:r,data:o,type:s,xPos:l,yPos:u,selected:h,isConnectable:T,sourcePosition:O,targetPosition:H,dragging:De,dragHandle:q,zIndex:W})))};return n.displayName="NodeWrapper",A.memo(n)};const lM=e=>{const n=e.getNodes().filter(r=>r.selected);return{...ru(n,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function uM({onSelectionContextMenu:e,noPanClassName:n,disableKeyboardA11y:r}){const s=Et(),{width:o,height:l,x:u,y:c,transformString:p,userSelectionActive:h}=Ke(lM,kt),f=sN(),m=A.useRef(null);if(A.useEffect(()=>{var C;r||(C=m.current)==null||C.focus({preventScroll:!0})},[r]),iN({nodeRef:m}),h||!o||!l)return null;const y=e?C=>{const _=s.getState().getNodes().filter(S=>S.selected);e(C,_)}:void 0,x=C=>{Object.prototype.hasOwnProperty.call(Gs,C.key)&&f({x:Gs[C.key].x,y:Gs[C.key].y,isShiftPressed:C.shiftKey})};return le.createElement("div",{className:Dt(["react-flow__nodesselection","react-flow__container",n]),style:{transform:p}},le.createElement("div",{ref:m,className:"react-flow__nodesselection-rect",onContextMenu:y,tabIndex:r?void 0:-1,onKeyDown:r?void 0:x,style:{width:o,height:l,top:c,left:u}}))}var cM=A.memo(uM);const dM=e=>e.nodesSelectionActive,oN=({children:e,onPaneClick:n,onPaneMouseEnter:r,onPaneMouseMove:s,onPaneMouseLeave:o,onPaneContextMenu:l,onPaneScroll:u,deleteKeyCode:c,onMove:p,onMoveStart:h,onMoveEnd:f,selectionKeyCode:m,selectionOnDrag:y,selectionMode:x,onSelectionStart:C,onSelectionEnd:_,multiSelectionKeyCode:S,panActivationKeyCode:b,zoomActivationKeyCode:E,elementsSelectable:N,zoomOnScroll:T,zoomOnPinch:I,panOnScroll:M,panOnScrollSpeed:O,panOnScrollMode:H,zoomOnDoubleClick:L,panOnDrag:P,defaultViewport:q,translateExtent:W,minZoom:B,maxZoom:j,preventScrolling:K,onSelectionContextMenu:U,noWheelClassName:ee,noPanClassName:J,disableKeyboardA11y:F})=>{const Y=Ke(dM),k=ra(m),$=ra(b),se=$||P,D=$||M,Q=k||y&&se!==!0;return KI({deleteKeyCode:c,multiSelectionKeyCode:S}),le.createElement(JI,{onMove:p,onMoveStart:h,onMoveEnd:f,onPaneContextMenu:l,elementsSelectable:N,zoomOnScroll:T,zoomOnPinch:I,panOnScroll:D,panOnScrollSpeed:O,panOnScrollMode:H,zoomOnDoubleClick:L,panOnDrag:!k&&se,defaultViewport:q,translateExtent:W,minZoom:B,maxZoom:j,zoomActivationKeyCode:E,preventScrolling:K,noWheelClassName:ee,noPanClassName:J},le.createElement(tN,{onSelectionStart:C,onSelectionEnd:_,onPaneClick:n,onPaneMouseEnter:r,onPaneMouseMove:s,onPaneMouseLeave:o,onPaneContextMenu:l,onPaneScroll:u,panOnDrag:se,isSelecting:!!Q,selectionMode:x},e,Y&&le.createElement(cM,{onSelectionContextMenu:U,noPanClassName:J,disableKeyboardA11y:F})))};oN.displayName="FlowRenderer";var fM=A.memo(oN);function hM(e){return Ke(A.useCallback(r=>e?qE(r.nodeInternals,{x:0,y:0,width:r.width,height:r.height},r.transform,!0):r.getNodes(),[e]))}function pM(e){const n={input:Bo(e.input||VE),default:Bo(e.default||Vg),output:Bo(e.output||YE),group:Bo(e.group||vv)},r={},s=Object.keys(e).filter(o=>!["input","default","output","group"].includes(o)).reduce((o,l)=>(o[l]=Bo(e[l]||Vg),o),r);return{...n,...s}}const mM=({x:e,y:n,width:r,height:s,origin:o})=>!r||!s?{x:e,y:n}:o[0]<0||o[1]<0||o[0]>1||o[1]>1?{x:e,y:n}:{x:e-r*o[0],y:n-s*o[1]},gM=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),aN=e=>{const{nodesDraggable:n,nodesConnectable:r,nodesFocusable:s,elementsSelectable:o,updateNodeDimensions:l,onError:u}=Ke(gM,kt),c=hM(e.onlyRenderVisibleElements),p=A.useRef(),h=A.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const f=new ResizeObserver(m=>{const y=m.map(x=>({id:x.target.getAttribute("data-id"),nodeElement:x.target,forceUpdate:!0}));l(y)});return p.current=f,f},[]);return A.useEffect(()=>()=>{var f;(f=p==null?void 0:p.current)==null||f.disconnect()},[]),le.createElement("div",{className:"react-flow__nodes",style:yv},c.map(f=>{var I,M,O;let m=f.type||"default";e.nodeTypes[m]||(u==null||u("003",Mr.error003(m)),m="default");const y=e.nodeTypes[m]||e.nodeTypes.default,x=!!(f.draggable||n&&typeof f.draggable>"u"),C=!!(f.selectable||o&&typeof f.selectable>"u"),_=!!(f.connectable||r&&typeof f.connectable>"u"),S=!!(f.focusable||s&&typeof f.focusable>"u"),b=e.nodeExtent?dv(f.positionAbsolute,e.nodeExtent):f.positionAbsolute,E=(b==null?void 0:b.x)??0,N=(b==null?void 0:b.y)??0,T=mM({x:E,y:N,width:f.width??0,height:f.height??0,origin:e.nodeOrigin});return le.createElement(y,{key:f.id,id:f.id,className:f.className,style:f.style,type:m,data:f.data,sourcePosition:f.sourcePosition||Re.Bottom,targetPosition:f.targetPosition||Re.Top,hidden:f.hidden,xPos:E,yPos:N,xPosOrigin:T.x,yPosOrigin:T.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!f.selected,isDraggable:x,isSelectable:C,isConnectable:_,isFocusable:S,resizeObserver:h,dragHandle:f.dragHandle,zIndex:((I=f[mt])==null?void 0:I.z)??0,isParent:!!((M=f[mt])!=null&&M.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!f.width&&!!f.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:f.ariaLabel,hasHandleBounds:!!((O=f[mt])!=null&&O.handleBounds)})}))};aN.displayName="NodeRenderer";var vM=A.memo(aN);const yM=(e,n,r)=>r===Re.Left?e-n:r===Re.Right?e+n:e,wM=(e,n,r)=>r===Re.Top?e-n:r===Re.Bottom?e+n:e,Yw="react-flow__edgeupdater",Kw=({position:e,centerX:n,centerY:r,radius:s=10,onMouseDown:o,onMouseEnter:l,onMouseOut:u,type:c})=>le.createElement("circle",{onMouseDown:o,onMouseEnter:l,onMouseOut:u,className:Dt([Yw,`${Yw}-${c}`]),cx:yM(n,s,e),cy:wM(r,s,e),r:s,stroke:"transparent",fill:"transparent"}),xM=()=>!0;var Ds=e=>{const n=({id:r,className:s,type:o,data:l,onClick:u,onEdgeDoubleClick:c,selected:p,animated:h,label:f,labelStyle:m,labelShowBg:y,labelBgStyle:x,labelBgPadding:C,labelBgBorderRadius:_,style:S,source:b,target:E,sourceX:N,sourceY:T,targetX:I,targetY:M,sourcePosition:O,targetPosition:H,elementsSelectable:L,hidden:P,sourceHandleId:q,targetHandleId:W,onContextMenu:B,onMouseEnter:j,onMouseMove:K,onMouseLeave:U,reconnectRadius:ee,onReconnect:J,onReconnectStart:F,onReconnectEnd:Y,markerEnd:k,markerStart:$,rfId:se,ariaLabel:D,isFocusable:Q,isReconnectable:te,pathOptions:ae,interactionWidth:ce,disableKeyboardA11y:me})=>{const ge=A.useRef(null),[Pe,Se]=A.useState(!1),[Oe,Me]=A.useState(!1),be=Et(),De=A.useMemo(()=>`url('#${Hg($,se)}')`,[$,se]),ve=A.useMemo(()=>`url('#${Hg(k,se)}')`,[k,se]);if(P)return null;const we=Xe=>{var zt;const{edges:vt,addSelectedEdges:ft,unselectNodesAndEdges:wt,multiSelectionActive:fn}=be.getState(),Ye=vt.find(Gt=>Gt.id===r);Ye&&(L&&(be.setState({nodesSelectionActive:!1}),Ye.selected&&fn?(wt({nodes:[],edges:[Ye]}),(zt=ge.current)==null||zt.blur()):ft([r])),u&&u(Xe,Ye))},Ue=Fo(r,be.getState,c),ut=Fo(r,be.getState,B),ct=Fo(r,be.getState,j),Ze=Fo(r,be.getState,K),Fe=Fo(r,be.getState,U),Je=(Xe,vt)=>{if(Xe.button!==0)return;const{edges:ft,isValidConnection:wt}=be.getState(),fn=vt?E:b,Ye=(vt?W:q)||null,zt=vt?"target":"source",Gt=wt||xM,pr=vt,In=ft.find(vn=>vn.id===r);Me(!0),F==null||F(Xe,In,zt);const Tt=vn=>{Me(!1),Y==null||Y(vn,In,zt)};BE({event:Xe,handleId:Ye,nodeId:fn,onConnect:vn=>J==null?void 0:J(In,vn),isTarget:pr,getState:be.getState,setState:be.setState,isValidConnection:Gt,edgeUpdaterType:zt,onReconnectEnd:Tt})},dt=Xe=>Je(Xe,!0),Nt=Xe=>Je(Xe,!1),ot=()=>Se(!0),gt=()=>Se(!1),Ct=!L&&!u,Ft=Xe=>{var vt;if(!me&&jE.includes(Xe.key)&&L){const{unselectNodesAndEdges:ft,addSelectedEdges:wt,edges:fn}=be.getState();Xe.key==="Escape"?((vt=ge.current)==null||vt.blur(),ft({edges:[fn.find(zt=>zt.id===r)]})):wt([r])}};return le.createElement("g",{className:Dt(["react-flow__edge",`react-flow__edge-${o}`,s,{selected:p,animated:h,inactive:Ct,updating:Pe}]),onClick:we,onDoubleClick:Ue,onContextMenu:ut,onMouseEnter:ct,onMouseMove:Ze,onMouseLeave:Fe,onKeyDown:Q?Ft:void 0,tabIndex:Q?0:void 0,role:Q?"button":"img","data-testid":`rf__edge-${r}`,"aria-label":D===null?void 0:D||`Edge from ${b} to ${E}`,"aria-describedby":Q?`${QE}-${se}`:void 0,ref:ge},!Oe&&le.createElement(e,{id:r,source:b,target:E,selected:p,animated:h,label:f,labelStyle:m,labelShowBg:y,labelBgStyle:x,labelBgPadding:C,labelBgBorderRadius:_,data:l,style:S,sourceX:N,sourceY:T,targetX:I,targetY:M,sourcePosition:O,targetPosition:H,sourceHandleId:q,targetHandleId:W,markerStart:De,markerEnd:ve,pathOptions:ae,interactionWidth:ce}),te&&le.createElement(le.Fragment,null,(te==="source"||te===!0)&&le.createElement(Kw,{position:O,centerX:N,centerY:T,radius:ee,onMouseDown:dt,onMouseEnter:ot,onMouseOut:gt,type:"source"}),(te==="target"||te===!0)&&le.createElement(Kw,{position:H,centerX:I,centerY:M,radius:ee,onMouseDown:Nt,onMouseEnter:ot,onMouseOut:gt,type:"target"})))};return n.displayName="EdgeWrapper",A.memo(n)};function _M(e){const n={default:Ds(e.default||Vl),straight:Ds(e.bezier||pv),step:Ds(e.step||hv),smoothstep:Ds(e.step||nu),simplebezier:Ds(e.simplebezier||fv)},r={},s=Object.keys(e).filter(o=>!["default","bezier"].includes(o)).reduce((o,l)=>(o[l]=Ds(e[l]||Vl),o),r);return{...n,...s}}function Xw(e,n,r=null){const s=((r==null?void 0:r.x)||0)+n.x,o=((r==null?void 0:r.y)||0)+n.y,l=(r==null?void 0:r.width)||n.width,u=(r==null?void 0:r.height)||n.height;switch(e){case Re.Top:return{x:s+l/2,y:o};case Re.Right:return{x:s+l,y:o+u/2};case Re.Bottom:return{x:s+l/2,y:o+u};case Re.Left:return{x:s,y:o+u/2}}}function Qw(e,n){return e?e.length===1||!n?e[0]:n&&e.find(r=>r.id===n)||null:null}const SM=(e,n,r,s,o,l)=>{const u=Xw(r,e,n),c=Xw(l,s,o);return{sourceX:u.x,sourceY:u.y,targetX:c.x,targetY:c.y}};function bM({sourcePos:e,targetPos:n,sourceWidth:r,sourceHeight:s,targetWidth:o,targetHeight:l,width:u,height:c,transform:p}){const h={x:Math.min(e.x,n.x),y:Math.min(e.y,n.y),x2:Math.max(e.x+r,n.x+o),y2:Math.max(e.y+s,n.y+l)};h.x===h.x2&&(h.x2+=1),h.y===h.y2&&(h.y2+=1);const f=ta({x:(0-p[0])/p[2],y:(0-p[1])/p[2],width:u/p[2],height:c/p[2]}),m=Math.max(0,Math.min(f.x2,h.x2)-Math.max(f.x,h.x)),y=Math.max(0,Math.min(f.y2,h.y2)-Math.max(f.y,h.y));return Math.ceil(m*y)>0}function Zw(e){var s,o,l,u,c;const n=((s=e==null?void 0:e[mt])==null?void 0:s.handleBounds)||null,r=n&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)<"u"&&typeof((l=e==null?void 0:e.positionAbsolute)==null?void 0:l.y)<"u";return[{x:((u=e==null?void 0:e.positionAbsolute)==null?void 0:u.x)||0,y:((c=e==null?void 0:e.positionAbsolute)==null?void 0:c.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},n,!!r]}const kM=[{level:0,isMaxLevel:!0,edges:[]}];function EM(e,n,r=!1){let s=-1;const o=e.reduce((u,c)=>{var f,m;const p=Rn(c.zIndex);let h=p?c.zIndex:0;if(r){const y=n.get(c.target),x=n.get(c.source),C=c.selected||(y==null?void 0:y.selected)||(x==null?void 0:x.selected),_=Math.max(((f=x==null?void 0:x[mt])==null?void 0:f.z)||0,((m=y==null?void 0:y[mt])==null?void 0:m.z)||0,1e3);h=(p?c.zIndex:0)+(C?_:0)}return u[h]?u[h].push(c):u[h]=[c],s=h>s?h:s,u},{}),l=Object.entries(o).map(([u,c])=>{const p=+u;return{edges:c,level:p,isMaxLevel:p===s}});return l.length===0?kM:l}function NM(e,n,r){const s=Ke(A.useCallback(o=>e?o.edges.filter(l=>{const u=n.get(l.source),c=n.get(l.target);return(u==null?void 0:u.width)&&(u==null?void 0:u.height)&&(c==null?void 0:c.width)&&(c==null?void 0:c.height)&&bM({sourcePos:u.positionAbsolute||{x:0,y:0},targetPos:c.positionAbsolute||{x:0,y:0},sourceWidth:u.width,sourceHeight:u.height,targetWidth:c.width,targetHeight:c.height,width:o.width,height:o.height,transform:o.transform})}):o.edges,[e,n]));return EM(s,n,r)}const CM=({color:e="none",strokeWidth:n=1})=>le.createElement("polyline",{style:{stroke:e,strokeWidth:n},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),TM=({color:e="none",strokeWidth:n=1})=>le.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:n},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Jw={[Wl.Arrow]:CM,[Wl.ArrowClosed]:TM};function RM(e){const n=Et();return A.useMemo(()=>{var o,l;return Object.prototype.hasOwnProperty.call(Jw,e)?Jw[e]:((l=(o=n.getState()).onError)==null||l.call(o,"009",Mr.error009(e)),null)},[e])}const jM=({id:e,type:n,color:r,width:s=12.5,height:o=12.5,markerUnits:l="strokeWidth",strokeWidth:u,orient:c="auto-start-reverse"})=>{const p=RM(n);return p?le.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${s}`,markerHeight:`${o}`,viewBox:"-10 -10 20 20",markerUnits:l,orient:c,refX:"0",refY:"0"},le.createElement(p,{color:r,strokeWidth:u})):null},AM=({defaultColor:e,rfId:n})=>r=>{const s=[];return r.edges.reduce((o,l)=>([l.markerStart,l.markerEnd].forEach(u=>{if(u&&typeof u=="object"){const c=Hg(u,n);s.includes(c)||(o.push({id:c,color:u.color||e,...u}),s.push(c))}}),o),[]).sort((o,l)=>o.id.localeCompare(l.id))},lN=({defaultColor:e,rfId:n})=>{const r=Ke(A.useCallback(AM({defaultColor:e,rfId:n}),[e,n]),(s,o)=>!(s.length!==o.length||s.some((l,u)=>l.id!==o[u].id)));return le.createElement("defs",null,r.map(s=>le.createElement(jM,{id:s.id,key:s.id,type:s.type,color:s.color,width:s.width,height:s.height,markerUnits:s.markerUnits,strokeWidth:s.strokeWidth,orient:s.orient})))};lN.displayName="MarkerDefinitions";var IM=A.memo(lN);const MM=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),uN=({defaultMarkerColor:e,onlyRenderVisibleElements:n,elevateEdgesOnSelect:r,rfId:s,edgeTypes:o,noPanClassName:l,onEdgeContextMenu:u,onEdgeMouseEnter:c,onEdgeMouseMove:p,onEdgeMouseLeave:h,onEdgeClick:f,onEdgeDoubleClick:m,onReconnect:y,onReconnectStart:x,onReconnectEnd:C,reconnectRadius:_,children:S,disableKeyboardA11y:b})=>{const{edgesFocusable:E,edgesUpdatable:N,elementsSelectable:T,width:I,height:M,connectionMode:O,nodeInternals:H,onError:L}=Ke(MM,kt),P=NM(n,H,r);return I?le.createElement(le.Fragment,null,P.map(({level:q,edges:W,isMaxLevel:B})=>le.createElement("svg",{key:q,style:{zIndex:q},width:I,height:M,className:"react-flow__edges react-flow__container"},B&&le.createElement(IM,{defaultColor:e,rfId:s}),le.createElement("g",null,W.map(j=>{const[K,U,ee]=Zw(H.get(j.source)),[J,F,Y]=Zw(H.get(j.target));if(!ee||!Y)return null;let k=j.type||"default";o[k]||(L==null||L("011",Mr.error011(k)),k="default");const $=o[k]||o.default,se=O===Xi.Strict?F.target:(F.target??[]).concat(F.source??[]),D=Qw(U.source,j.sourceHandle),Q=Qw(se,j.targetHandle),te=(D==null?void 0:D.position)||Re.Bottom,ae=(Q==null?void 0:Q.position)||Re.Top,ce=!!(j.focusable||E&&typeof j.focusable>"u"),me=j.reconnectable||j.updatable,ge=typeof y<"u"&&(me||N&&typeof me>"u");if(!D||!Q)return L==null||L("008",Mr.error008(D,j)),null;const{sourceX:Pe,sourceY:Se,targetX:Oe,targetY:Me}=SM(K,D,te,J,Q,ae);return le.createElement($,{key:j.id,id:j.id,className:Dt([j.className,l]),type:k,data:j.data,selected:!!j.selected,animated:!!j.animated,hidden:!!j.hidden,label:j.label,labelStyle:j.labelStyle,labelShowBg:j.labelShowBg,labelBgStyle:j.labelBgStyle,labelBgPadding:j.labelBgPadding,labelBgBorderRadius:j.labelBgBorderRadius,style:j.style,source:j.source,target:j.target,sourceHandleId:j.sourceHandle,targetHandleId:j.targetHandle,markerEnd:j.markerEnd,markerStart:j.markerStart,sourceX:Pe,sourceY:Se,targetX:Oe,targetY:Me,sourcePosition:te,targetPosition:ae,elementsSelectable:T,onContextMenu:u,onMouseEnter:c,onMouseMove:p,onMouseLeave:h,onClick:f,onEdgeDoubleClick:m,onReconnect:y,onReconnectStart:x,onReconnectEnd:C,reconnectRadius:_,rfId:s,ariaLabel:j.ariaLabel,isFocusable:ce,isReconnectable:ge,pathOptions:"pathOptions"in j?j.pathOptions:void 0,interactionWidth:j.interactionWidth,disableKeyboardA11y:b})})))),S):null};uN.displayName="EdgeRenderer";var PM=A.memo(uN);const OM=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function LM({children:e}){const n=Ke(OM);return le.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:n}},e)}function qM(e){const n=ca(),r=A.useRef(!1);A.useEffect(()=>{!r.current&&n.viewportInitialized&&e&&(setTimeout(()=>e(n),1),r.current=!0)},[e,n.viewportInitialized])}const $M={[Re.Left]:Re.Right,[Re.Right]:Re.Left,[Re.Top]:Re.Bottom,[Re.Bottom]:Re.Top},cN=({nodeId:e,handleType:n,style:r,type:s=ci.Bezier,CustomComponent:o,connectionStatus:l})=>{var M,O,H;const{fromNode:u,handleId:c,toX:p,toY:h,connectionMode:f}=Ke(A.useCallback(L=>({fromNode:L.nodeInternals.get(e),handleId:L.connectionHandleId,toX:(L.connectionPosition.x-L.transform[0])/L.transform[2],toY:(L.connectionPosition.y-L.transform[1])/L.transform[2],connectionMode:L.connectionMode}),[e]),kt),m=(M=u==null?void 0:u[mt])==null?void 0:M.handleBounds;let y=m==null?void 0:m[n];if(f===Xi.Loose&&(y=y||(m==null?void 0:m[n==="source"?"target":"source"])),!u||!y)return null;const x=c?y.find(L=>L.id===c):y[0],C=x?x.x+x.width/2:(u.width??0)/2,_=x?x.y+x.height/2:u.height??0,S=(((O=u.positionAbsolute)==null?void 0:O.x)??0)+C,b=(((H=u.positionAbsolute)==null?void 0:H.y)??0)+_,E=x==null?void 0:x.position,N=E?$M[E]:null;if(!E||!N)return null;if(o)return le.createElement(o,{connectionLineType:s,connectionLineStyle:r,fromNode:u,fromHandle:x,fromX:S,fromY:b,toX:p,toY:h,fromPosition:E,toPosition:N,connectionStatus:l});let T="";const I={sourceX:S,sourceY:b,sourcePosition:E,targetX:p,targetY:h,targetPosition:N};return s===ci.Bezier?[T]=OE(I):s===ci.Step?[T]=Ug({...I,borderRadius:0}):s===ci.SmoothStep?[T]=Ug(I):s===ci.SimpleBezier?[T]=PE(I):T=`M${S},${b} ${p},${h}`,le.createElement("path",{d:T,fill:"none",className:"react-flow__connection-path",style:r})};cN.displayName="ConnectionLine";const DM=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function FM({containerStyle:e,style:n,type:r,component:s}){const{nodeId:o,handleType:l,nodesConnectable:u,width:c,height:p,connectionStatus:h}=Ke(DM,kt);return!(o&&l&&c&&u)?null:le.createElement("svg",{style:e,width:c,height:p,className:"react-flow__edges react-flow__connectionline react-flow__container"},le.createElement("g",{className:Dt(["react-flow__connection",h])},le.createElement(cN,{nodeId:o,handleType:l,style:n,type:r,CustomComponent:s,connectionStatus:h})))}function ex(e,n){return A.useRef(null),Et(),A.useMemo(()=>n(e),[e])}const dN=({nodeTypes:e,edgeTypes:n,onMove:r,onMoveStart:s,onMoveEnd:o,onInit:l,onNodeClick:u,onEdgeClick:c,onNodeDoubleClick:p,onEdgeDoubleClick:h,onNodeMouseEnter:f,onNodeMouseMove:m,onNodeMouseLeave:y,onNodeContextMenu:x,onSelectionContextMenu:C,onSelectionStart:_,onSelectionEnd:S,connectionLineType:b,connectionLineStyle:E,connectionLineComponent:N,connectionLineContainerStyle:T,selectionKeyCode:I,selectionOnDrag:M,selectionMode:O,multiSelectionKeyCode:H,panActivationKeyCode:L,zoomActivationKeyCode:P,deleteKeyCode:q,onlyRenderVisibleElements:W,elementsSelectable:B,selectNodesOnDrag:j,defaultViewport:K,translateExtent:U,minZoom:ee,maxZoom:J,preventScrolling:F,defaultMarkerColor:Y,zoomOnScroll:k,zoomOnPinch:$,panOnScroll:se,panOnScrollSpeed:D,panOnScrollMode:Q,zoomOnDoubleClick:te,panOnDrag:ae,onPaneClick:ce,onPaneMouseEnter:me,onPaneMouseMove:ge,onPaneMouseLeave:Pe,onPaneScroll:Se,onPaneContextMenu:Oe,onEdgeContextMenu:Me,onEdgeMouseEnter:be,onEdgeMouseMove:De,onEdgeMouseLeave:ve,onReconnect:we,onReconnectStart:Ue,onReconnectEnd:ut,reconnectRadius:ct,noDragClassName:Ze,noWheelClassName:Fe,noPanClassName:Je,elevateEdgesOnSelect:dt,disableKeyboardA11y:Nt,nodeOrigin:ot,nodeExtent:gt,rfId:Ct})=>{const Ft=ex(e,pM),Xe=ex(n,_M);return qM(l),le.createElement(fM,{onPaneClick:ce,onPaneMouseEnter:me,onPaneMouseMove:ge,onPaneMouseLeave:Pe,onPaneContextMenu:Oe,onPaneScroll:Se,deleteKeyCode:q,selectionKeyCode:I,selectionOnDrag:M,selectionMode:O,onSelectionStart:_,onSelectionEnd:S,multiSelectionKeyCode:H,panActivationKeyCode:L,zoomActivationKeyCode:P,elementsSelectable:B,onMove:r,onMoveStart:s,onMoveEnd:o,zoomOnScroll:k,zoomOnPinch:$,zoomOnDoubleClick:te,panOnScroll:se,panOnScrollSpeed:D,panOnScrollMode:Q,panOnDrag:ae,defaultViewport:K,translateExtent:U,minZoom:ee,maxZoom:J,onSelectionContextMenu:C,preventScrolling:F,noDragClassName:Ze,noWheelClassName:Fe,noPanClassName:Je,disableKeyboardA11y:Nt},le.createElement(LM,null,le.createElement(PM,{edgeTypes:Xe,onEdgeClick:c,onEdgeDoubleClick:h,onlyRenderVisibleElements:W,onEdgeContextMenu:Me,onEdgeMouseEnter:be,onEdgeMouseMove:De,onEdgeMouseLeave:ve,onReconnect:we,onReconnectStart:Ue,onReconnectEnd:ut,reconnectRadius:ct,defaultMarkerColor:Y,noPanClassName:Je,elevateEdgesOnSelect:!!dt,disableKeyboardA11y:Nt,rfId:Ct},le.createElement(FM,{style:E,type:b,component:N,containerStyle:T})),le.createElement("div",{className:"react-flow__edgelabel-renderer"}),le.createElement(vM,{nodeTypes:Ft,onNodeClick:u,onNodeDoubleClick:p,onNodeMouseEnter:f,onNodeMouseMove:m,onNodeMouseLeave:y,onNodeContextMenu:x,selectNodesOnDrag:j,onlyRenderVisibleElements:W,noPanClassName:Je,noDragClassName:Ze,disableKeyboardA11y:Nt,nodeOrigin:ot,nodeExtent:gt,rfId:Ct})))};dN.displayName="GraphView";var zM=A.memo(dN);const Yg=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ai={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Yg,nodeExtent:Yg,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:Xi.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:pI,isValidConnection:void 0},BM=()=>TR((e,n)=>({...ai,setNodes:r=>{const{nodeInternals:s,nodeOrigin:o,elevateNodesOnSelect:l}=n();e({nodeInternals:ad(r,s,o,l)})},getNodes:()=>Array.from(n().nodeInternals.values()),setEdges:r=>{const{defaultEdgeOptions:s={}}=n();e({edges:r.map(o=>({...s,...o}))})},setDefaultNodesAndEdges:(r,s)=>{const o=typeof r<"u",l=typeof s<"u",u=o?ad(r,new Map,n().nodeOrigin,n().elevateNodesOnSelect):new Map;e({nodeInternals:u,edges:l?s:[],hasDefaultNodes:o,hasDefaultEdges:l})},updateNodeDimensions:r=>{const{onNodesChange:s,nodeInternals:o,fitViewOnInit:l,fitViewOnInitDone:u,fitViewOnInitOptions:c,domNode:p,nodeOrigin:h}=n(),f=p==null?void 0:p.querySelector(".react-flow__viewport");if(!f)return;const m=window.getComputedStyle(f),{m22:y}=new window.DOMMatrixReadOnly(m.transform),x=r.reduce((_,S)=>{const b=o.get(S.id);if(b!=null&&b.hidden)o.set(b.id,{...b,[mt]:{...b[mt],handleBounds:void 0}});else if(b){const E=cv(S.nodeElement);!!(E.width&&E.height&&(b.width!==E.width||b.height!==E.height||S.forceUpdate))&&(o.set(b.id,{...b,[mt]:{...b[mt],handleBounds:{source:Gw(".source",S.nodeElement,y,h),target:Gw(".target",S.nodeElement,y,h)}},...E}),_.push({id:b.id,type:"dimensions",dimensions:E}))}return _},[]);JE(o,h);const C=u||l&&!u&&eN(n,{initial:!0,...c});e({nodeInternals:new Map(o),fitViewOnInitDone:C}),(x==null?void 0:x.length)>0&&(s==null||s(x))},updateNodePositions:(r,s=!0,o=!1)=>{const{triggerNodeChanges:l}=n(),u=r.map(c=>{const p={id:c.id,type:"position",dragging:o};return s&&(p.positionAbsolute=c.positionAbsolute,p.position=c.position),p});l(u)},triggerNodeChanges:r=>{const{onNodesChange:s,nodeInternals:o,hasDefaultNodes:l,nodeOrigin:u,getNodes:c,elevateNodesOnSelect:p}=n();if(r!=null&&r.length){if(l){const h=rM(r,c()),f=ad(h,o,u,p);e({nodeInternals:f})}s==null||s(r)}},addSelectedNodes:r=>{const{multiSelectionActive:s,edges:o,getNodes:l}=n();let u,c=null;s?u=r.map(p=>ui(p,!0)):(u=Bs(l(),r),c=Bs(o,[])),El({changedNodes:u,changedEdges:c,get:n,set:e})},addSelectedEdges:r=>{const{multiSelectionActive:s,edges:o,getNodes:l}=n();let u,c=null;s?u=r.map(p=>ui(p,!0)):(u=Bs(o,r),c=Bs(l(),[])),El({changedNodes:c,changedEdges:u,get:n,set:e})},unselectNodesAndEdges:({nodes:r,edges:s}={})=>{const{edges:o,getNodes:l}=n(),u=r||l(),c=s||o,p=u.map(f=>(f.selected=!1,ui(f.id,!1))),h=c.map(f=>ui(f.id,!1));El({changedNodes:p,changedEdges:h,get:n,set:e})},setMinZoom:r=>{const{d3Zoom:s,maxZoom:o}=n();s==null||s.scaleExtent([r,o]),e({minZoom:r})},setMaxZoom:r=>{const{d3Zoom:s,minZoom:o}=n();s==null||s.scaleExtent([o,r]),e({maxZoom:r})},setTranslateExtent:r=>{var s;(s=n().d3Zoom)==null||s.translateExtent(r),e({translateExtent:r})},resetSelectedElements:()=>{const{edges:r,getNodes:s}=n(),l=s().filter(c=>c.selected).map(c=>ui(c.id,!1)),u=r.filter(c=>c.selected).map(c=>ui(c.id,!1));El({changedNodes:l,changedEdges:u,get:n,set:e})},setNodeExtent:r=>{const{nodeInternals:s}=n();s.forEach(o=>{o.positionAbsolute=dv(o.position,r)}),e({nodeExtent:r,nodeInternals:new Map(s)})},panBy:r=>{const{transform:s,width:o,height:l,d3Zoom:u,d3Selection:c,translateExtent:p}=n();if(!u||!c||!r.x&&!r.y)return!1;const h=Ar.translate(s[0]+r.x,s[1]+r.y).scale(s[2]),f=[[0,0],[o,l]],m=u==null?void 0:u.constrain()(h,f,p);return u.transform(c,m),s[0]!==m.x||s[1]!==m.y||s[2]!==m.k},cancelConnection:()=>e({connectionNodeId:ai.connectionNodeId,connectionHandleId:ai.connectionHandleId,connectionHandleType:ai.connectionHandleType,connectionStatus:ai.connectionStatus,connectionStartHandle:ai.connectionStartHandle,connectionEndHandle:ai.connectionEndHandle}),reset:()=>e({...ai})}),Object.is),wv=({children:e})=>{const n=A.useRef(null);return n.current||(n.current=BM()),le.createElement(aI,{value:n.current},e)};wv.displayName="ReactFlowProvider";const fN=({children:e})=>A.useContext(tu)?le.createElement(le.Fragment,null,e):le.createElement(wv,null,e);fN.displayName="ReactFlowWrapper";const UM={input:VE,default:Vg,output:YE,group:vv},HM={default:Vl,straight:pv,step:hv,smoothstep:nu,simplebezier:fv},WM=[0,0],VM=[15,15],GM={x:0,y:0,zoom:1},YM={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},hN=A.forwardRef(({nodes:e,edges:n,defaultNodes:r,defaultEdges:s,className:o,nodeTypes:l=UM,edgeTypes:u=HM,onNodeClick:c,onEdgeClick:p,onInit:h,onMove:f,onMoveStart:m,onMoveEnd:y,onConnect:x,onConnectStart:C,onConnectEnd:_,onClickConnectStart:S,onClickConnectEnd:b,onNodeMouseEnter:E,onNodeMouseMove:N,onNodeMouseLeave:T,onNodeContextMenu:I,onNodeDoubleClick:M,onNodeDragStart:O,onNodeDrag:H,onNodeDragStop:L,onNodesDelete:P,onEdgesDelete:q,onSelectionChange:W,onSelectionDragStart:B,onSelectionDrag:j,onSelectionDragStop:K,onSelectionContextMenu:U,onSelectionStart:ee,onSelectionEnd:J,connectionMode:F=Xi.Strict,connectionLineType:Y=ci.Bezier,connectionLineStyle:k,connectionLineComponent:$,connectionLineContainerStyle:se,deleteKeyCode:D="Backspace",selectionKeyCode:Q="Shift",selectionOnDrag:te=!1,selectionMode:ae=na.Full,panActivationKeyCode:ce="Space",multiSelectionKeyCode:me=Hl()?"Meta":"Control",zoomActivationKeyCode:ge=Hl()?"Meta":"Control",snapToGrid:Pe=!1,snapGrid:Se=VM,onlyRenderVisibleElements:Oe=!1,selectNodesOnDrag:Me=!0,nodesDraggable:be,nodesConnectable:De,nodesFocusable:ve,nodeOrigin:we=WM,edgesFocusable:Ue,edgesUpdatable:ut,elementsSelectable:ct,defaultViewport:Ze=GM,minZoom:Fe=.5,maxZoom:Je=2,translateExtent:dt=Yg,preventScrolling:Nt=!0,nodeExtent:ot,defaultMarkerColor:gt="#b1b1b7",zoomOnScroll:Ct=!0,zoomOnPinch:Ft=!0,panOnScroll:Xe=!1,panOnScrollSpeed:vt=.5,panOnScrollMode:ft=Vi.Free,zoomOnDoubleClick:wt=!0,panOnDrag:fn=!0,onPaneClick:Ye,onPaneMouseEnter:zt,onPaneMouseMove:Gt,onPaneMouseLeave:pr,onPaneScroll:In,onPaneContextMenu:Tt,children:Qt,onEdgeContextMenu:vn,onEdgeDoubleClick:ts,onEdgeMouseEnter:pi,onEdgeMouseMove:mi,onEdgeMouseLeave:Mn,onEdgeUpdate:Lr,onEdgeUpdateStart:gi,onEdgeUpdateEnd:yn,onReconnect:qr,onReconnectStart:Pn,onReconnectEnd:Ot,reconnectRadius:wn=10,edgeUpdaterRadius:On=10,onNodesChange:Zt,onEdgesChange:$r,noDragClassName:ns="nodrag",noWheelClassName:so="nowheel",noPanClassName:nr="nopan",fitView:xn=!1,fitViewOptions:vi,connectOnClick:rs=!0,attributionPosition:is,proOptions:yi,defaultEdgeOptions:Dr,elevateNodesOnSelect:Ln=!0,elevateEdgesOnSelect:ss=!1,disableKeyboardA11y:Yt=!1,autoPanOnConnect:wi=!0,autoPanOnNodeDrag:Qe=!0,connectionRadius:os=20,isValidConnection:rr,onError:Fr,style:Jt,id:xi,nodeDragThreshold:_i,...mr},en)=>{const gr=xi||"1";return le.createElement("div",{...mr,style:{...Jt,...YM},ref:en,className:Dt(["react-flow",o]),"data-testid":"rf__wrapper",id:xi},le.createElement(fN,null,le.createElement(zM,{onInit:h,onMove:f,onMoveStart:m,onMoveEnd:y,onNodeClick:c,onEdgeClick:p,onNodeMouseEnter:E,onNodeMouseMove:N,onNodeMouseLeave:T,onNodeContextMenu:I,onNodeDoubleClick:M,nodeTypes:l,edgeTypes:u,connectionLineType:Y,connectionLineStyle:k,connectionLineComponent:$,connectionLineContainerStyle:se,selectionKeyCode:Q,selectionOnDrag:te,selectionMode:ae,deleteKeyCode:D,multiSelectionKeyCode:me,panActivationKeyCode:ce,zoomActivationKeyCode:ge,onlyRenderVisibleElements:Oe,selectNodesOnDrag:Me,defaultViewport:Ze,translateExtent:dt,minZoom:Fe,maxZoom:Je,preventScrolling:Nt,zoomOnScroll:Ct,zoomOnPinch:Ft,zoomOnDoubleClick:wt,panOnScroll:Xe,panOnScrollSpeed:vt,panOnScrollMode:ft,panOnDrag:fn,onPaneClick:Ye,onPaneMouseEnter:zt,onPaneMouseMove:Gt,onPaneMouseLeave:pr,onPaneScroll:In,onPaneContextMenu:Tt,onSelectionContextMenu:U,onSelectionStart:ee,onSelectionEnd:J,onEdgeContextMenu:vn,onEdgeDoubleClick:ts,onEdgeMouseEnter:pi,onEdgeMouseMove:mi,onEdgeMouseLeave:Mn,onReconnect:qr??Lr,onReconnectStart:Pn??gi,onReconnectEnd:Ot??yn,reconnectRadius:wn??On,defaultMarkerColor:gt,noDragClassName:ns,noWheelClassName:so,noPanClassName:nr,elevateEdgesOnSelect:ss,rfId:gr,disableKeyboardA11y:Yt,nodeOrigin:we,nodeExtent:ot}),le.createElement(qI,{nodes:e,edges:n,defaultNodes:r,defaultEdges:s,onConnect:x,onConnectStart:C,onConnectEnd:_,onClickConnectStart:S,onClickConnectEnd:b,nodesDraggable:be,nodesConnectable:De,nodesFocusable:ve,edgesFocusable:Ue,edgesUpdatable:ut,elementsSelectable:ct,elevateNodesOnSelect:Ln,minZoom:Fe,maxZoom:Je,nodeExtent:ot,onNodesChange:Zt,onEdgesChange:$r,snapToGrid:Pe,snapGrid:Se,connectionMode:F,translateExtent:dt,connectOnClick:rs,defaultEdgeOptions:Dr,fitView:xn,fitViewOptions:vi,onNodesDelete:P,onEdgesDelete:q,onNodeDragStart:O,onNodeDrag:H,onNodeDragStop:L,onSelectionDrag:j,onSelectionDragStart:B,onSelectionDragStop:K,noPanClassName:nr,nodeOrigin:we,rfId:gr,autoPanOnConnect:wi,autoPanOnNodeDrag:Qe,onError:Fr,connectionRadius:os,isValidConnection:rr,nodeDragThreshold:_i}),le.createElement(OI,{onSelectionChange:W}),Qt,le.createElement(uI,{proOptions:yi,position:is}),le.createElement(BI,{rfId:gr,disableKeyboardA11y:Yt})))});hN.displayName="ReactFlow";const KM=e=>({x:e.transform[0],y:e.transform[1],zoom:e.transform[2]});function pN(){return Ke(KM,kt)}const mN=({id:e,x:n,y:r,width:s,height:o,style:l,color:u,strokeColor:c,strokeWidth:p,className:h,borderRadius:f,shapeRendering:m,onClick:y,selected:x})=>{const{background:C,backgroundColor:_}=l||{},S=u||C||_;return le.createElement("rect",{className:Dt(["react-flow__minimap-node",{selected:x},h]),x:n,y:r,rx:f,ry:f,width:s,height:o,fill:S,stroke:c,strokeWidth:p,shapeRendering:m,onClick:y?b=>y(b,e):void 0})};mN.displayName="MiniMapNode";var XM=A.memo(mN);const QM=e=>e.nodeOrigin,ZM=e=>e.getNodes().filter(n=>!n.hidden&&n.width&&n.height),dd=e=>e instanceof Function?e:()=>e;function JM({nodeStrokeColor:e="transparent",nodeColor:n="#e2e2e2",nodeClassName:r="",nodeBorderRadius:s=5,nodeStrokeWidth:o=2,nodeComponent:l=XM,onClick:u}){const c=Ke(ZM,kt),p=Ke(QM),h=dd(n),f=dd(e),m=dd(r),y=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return le.createElement(le.Fragment,null,c.map(x=>{const{x:C,y:_}=Yi(x,p).positionAbsolute;return le.createElement(l,{key:x.id,x:C,y:_,width:x.width,height:x.height,style:x.style,selected:x.selected,className:m(x),color:h(x),borderRadius:s,strokeColor:f(x),strokeWidth:o,shapeRendering:y,onClick:u,id:x.id})}))}var eP=A.memo(JM);const tP=200,nP=150,rP=e=>{const n=e.getNodes(),r={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:r,boundingRect:n.length>0?fI(ru(n,e.nodeOrigin),r):r,rfId:e.rfId}},iP="react-flow__minimap-desc";function gN({style:e,className:n,nodeStrokeColor:r="transparent",nodeColor:s="#e2e2e2",nodeClassName:o="",nodeBorderRadius:l=5,nodeStrokeWidth:u=2,nodeComponent:c,maskColor:p="rgb(240, 240, 240, 0.6)",maskStrokeColor:h="none",maskStrokeWidth:f=1,position:m="bottom-right",onClick:y,onNodeClick:x,pannable:C=!1,zoomable:_=!1,ariaLabel:S="React Flow mini map",inversePan:b=!1,zoomStep:E=10,offsetScale:N=5}){const T=Et(),I=A.useRef(null),{boundingRect:M,viewBB:O,rfId:H}=Ke(rP,kt),L=(e==null?void 0:e.width)??tP,P=(e==null?void 0:e.height)??nP,q=M.width/L,W=M.height/P,B=Math.max(q,W),j=B*L,K=B*P,U=N*B,ee=M.x-(j-M.width)/2-U,J=M.y-(K-M.height)/2-U,F=j+U*2,Y=K+U*2,k=`${iP}-${H}`,$=A.useRef(0);$.current=B,A.useEffect(()=>{if(I.current){const Q=Tn(I.current),te=me=>{const{transform:ge,d3Selection:Pe,d3Zoom:Se}=T.getState();if(me.sourceEvent.type!=="wheel"||!Pe||!Se)return;const Oe=-me.sourceEvent.deltaY*(me.sourceEvent.deltaMode===1?.05:me.sourceEvent.deltaMode?1:.002)*E,Me=ge[2]*Math.pow(2,Oe);Se.scaleTo(Pe,Me)},ae=me=>{const{transform:ge,d3Selection:Pe,d3Zoom:Se,translateExtent:Oe,width:Me,height:be}=T.getState();if(me.sourceEvent.type!=="mousemove"||!Pe||!Se)return;const De=$.current*Math.max(1,ge[2])*(b?-1:1),ve={x:ge[0]-me.sourceEvent.movementX*De,y:ge[1]-me.sourceEvent.movementY*De},we=[[0,0],[Me,be]],Ue=Ar.translate(ve.x,ve.y).scale(ge[2]),ut=Se.constrain()(Ue,we,Oe);Se.transform(Pe,ut)},ce=kE().on("zoom",C?ae:null).on("zoom.wheel",_?te:null);return Q.call(ce),()=>{Q.on("zoom",null)}}},[C,_,b,E]);const se=y?Q=>{const te=Xn(Q);y(Q,{x:te[0],y:te[1]})}:void 0,D=x?(Q,te)=>{const ae=T.getState().nodeInternals.get(te);x(Q,ae)}:void 0;return le.createElement(uv,{position:m,style:e,className:Dt(["react-flow__minimap",n]),"data-testid":"rf__minimap"},le.createElement("svg",{width:L,height:P,viewBox:`${ee} ${J} ${F} ${Y}`,role:"img","aria-labelledby":k,ref:I,onClick:se},S&&le.createElement("title",{id:k},S),le.createElement(eP,{onClick:D,nodeColor:s,nodeStrokeColor:r,nodeBorderRadius:l,nodeClassName:o,nodeStrokeWidth:u,nodeComponent:c}),le.createElement("path",{className:"react-flow__minimap-mask",d:`M${ee-U},${J-U}h${F+U*2}v${Y+U*2}h${-F-U*2}z
57
57
  M${O.x},${O.y}h${O.width}v${O.height}h${-O.width}z`,fill:p,fillRule:"evenodd",stroke:h,strokeWidth:f,pointerEvents:"none"})))}gN.displayName="MiniMap";var sP=A.memo(gN);function oP(){return le.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},le.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function aP(){return le.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},le.createElement("path",{d:"M0 0h32v4.2H0z"}))}function lP(){return le.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},le.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function uP(){return le.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},le.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function cP(){return le.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},le.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Us=({children:e,className:n,...r})=>le.createElement("button",{type:"button",className:Dt(["react-flow__controls-button",n]),...r},e);Us.displayName="ControlButton";const dP=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),vN=({style:e,showZoom:n=!0,showFitView:r=!0,showInteractive:s=!0,fitViewOptions:o,onZoomIn:l,onZoomOut:u,onFitView:c,onInteractiveChange:p,className:h,children:f,position:m="bottom-left"})=>{const y=Et(),[x,C]=A.useState(!1),{isInteractive:_,minZoomReached:S,maxZoomReached:b}=Ke(dP,kt),{zoomIn:E,zoomOut:N,fitView:T}=ca();if(A.useEffect(()=>{C(!0)},[]),!x)return null;const I=()=>{E(),l==null||l()},M=()=>{N(),u==null||u()},O=()=>{T(o),c==null||c()},H=()=>{y.setState({nodesDraggable:!_,nodesConnectable:!_,elementsSelectable:!_}),p==null||p(!_)};return le.createElement(uv,{className:Dt(["react-flow__controls",h]),position:m,style:e,"data-testid":"rf__controls"},n&&le.createElement(le.Fragment,null,le.createElement(Us,{onClick:I,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:b},le.createElement(oP,null)),le.createElement(Us,{onClick:M,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:S},le.createElement(aP,null))),r&&le.createElement(Us,{className:"react-flow__controls-fitview",onClick:O,title:"fit view","aria-label":"fit view"},le.createElement(lP,null)),s&&le.createElement(Us,{className:"react-flow__controls-interactive",onClick:H,title:"toggle interactivity","aria-label":"toggle interactivity"},_?le.createElement(cP,null):le.createElement(uP,null)),f)};vN.displayName="Controls";var fP=A.memo(vN),Zn;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Zn||(Zn={}));function hP({color:e,dimensions:n,lineWidth:r}){return le.createElement("path",{stroke:e,strokeWidth:r,d:`M${n[0]/2} 0 V${n[1]} M0 ${n[1]/2} H${n[0]}`})}function pP({color:e,radius:n}){return le.createElement("circle",{cx:n,cy:n,r:n,fill:e})}const mP={[Zn.Dots]:"#91919a",[Zn.Lines]:"#eee",[Zn.Cross]:"#e2e2e2"},gP={[Zn.Dots]:1,[Zn.Lines]:1,[Zn.Cross]:6},vP=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function yN({id:e,variant:n=Zn.Dots,gap:r=20,size:s,lineWidth:o=1,offset:l=2,color:u,style:c,className:p}){const h=A.useRef(null),{transform:f,patternId:m}=Ke(vP,kt),y=u||mP[n],x=s||gP[n],C=n===Zn.Dots,_=n===Zn.Cross,S=Array.isArray(r)?r:[r,r],b=[S[0]*f[2]||1,S[1]*f[2]||1],E=x*f[2],N=_?[E,E]:b,T=C?[E/l,E/l]:[N[0]/l,N[1]/l];return le.createElement("svg",{className:Dt(["react-flow__background",p]),style:{...c,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:h,"data-testid":"rf__background"},le.createElement("pattern",{id:m+e,x:f[0]%b[0],y:f[1]%b[1],width:b[0],height:b[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${T[0]},-${T[1]})`},C?le.createElement(pP,{color:y,radius:E/l}):le.createElement(hP,{dimensions:N,color:y,lineWidth:o})),le.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${m+e})`}))}yN.displayName="Background";var yP=A.memo(yN);function wN(){return{inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreateTokens:0}}function xN(e){const n=e.cache_creation,r=n&&typeof n=="object"?n:e,s=r.ephemeral_1h_input_tokens,o=r.ephemeral_5m_input_tokens;return typeof s!="number"&&typeof o!="number"?{}:{cacheCreate1hTokens:Number(s??0),cacheCreate5mTokens:Number(o??0)}}function _N(e,n=0){if(!e||typeof e!="object"||n>6)return null;const r=e;if(typeof r.input_tokens=="number"||typeof r.output_tokens=="number"||typeof r.cache_read_input_tokens=="number"||typeof r.cache_creation_input_tokens=="number")return{inputTokens:Number(r.input_tokens??0),outputTokens:Number(r.output_tokens??0),cacheReadTokens:Number(r.cache_read_input_tokens??0),cacheCreateTokens:Number(r.cache_creation_input_tokens??0),...xN(r)};for(const s of Object.values(r)){const o=_N(s,n+1);if(o)return o}return null}function wP(e,n){e.inputTokens+=n.inputTokens,e.outputTokens+=n.outputTokens,e.cacheReadTokens+=n.cacheReadTokens,e.cacheCreateTokens+=n.cacheCreateTokens,(n.cacheCreate1hTokens!==void 0||n.cacheCreate5mTokens!==void 0)&&(e.cacheCreate1hTokens=(e.cacheCreate1hTokens??0)+(n.cacheCreate1hTokens??0),e.cacheCreate5mTokens=(e.cacheCreate5mTokens??0)+(n.cacheCreate5mTokens??0))}const xP=/^(?:claude[-_]|gpt[-_]|o\d|codex[-_])/i;function SN(e,n=0){if(!e||typeof e!="object"||n>6)return null;const r=e;if(typeof r.model=="string"&&xP.test(r.model))return r.model;for(const s of Object.values(r)){const o=SN(s,n+1);if(o)return o}return null}function Kg(){return{agents:new Map,toolIndex:new Map,toolOwner:new Map,activeSubagentStack:new Map,lastSeq:0,seqEpoch:null,totalEvents:0}}function fi(e){if(!e)return;const n=e.replace(/\\/g,"/").split("/").filter(Boolean);return n[n.length-1]}function xv(e,n){return`${e}::${n}`}function Gl(e){return e.agent_type??e.subagent_type??"subagent"}function Xg(e){return e.agent_id?e.agent_id:e.parent_tool_use_id?e.parent_tool_use_id:null}function Ko(e,n,r,s){const o=n;let l=e.agents.get(o);return l||(l={id:o,sessionId:n,label:"session",kind:"root",state:"active",startedAt:r,tools:[],prompts:[],toolCount:0,childCount:0,synthetic:s,inFlightTool:null,usage:wN()},e.agents.set(o,l),l)}function bN(e,n,r,s){const o=xv(n,r),l=e.agents.get(o);if(!l)return null;!l.cwd&&s.cwd&&(l.cwd=s.cwd,l.cwdBasename=fi(s.cwd));const u=Gl(s);return u&&(l.label==="subagent"||!l.label)&&(l.label=u),l}function tx(e,n,r){const s=n.session_id??"unknown",o=Xg(n);if(o){const p=bN(e,s,o,n);if(p)return p}const l=e.activeSubagentStack.get(s),u=l&&l.length>0?l[l.length-1]:null;if(u){const p=e.agents.get(xv(s,u));if(p)return!p.cwd&&n.cwd&&(p.cwd=n.cwd,p.cwdBasename=fi(n.cwd)),p}const c=Ko(e,s,r,!1);return c.synthetic&&(c.synthetic=!1,c.startedAt=r),!c.cwd&&n.cwd&&(c.cwd=n.cwd,c.cwdBasename=fi(n.cwd)),c.label==="session"&&n.cwd&&(c.label=fi(n.cwd)??"session"),c}function _P(e,n,r,s,o){const l=xv(n,r),u=Ko(e,n,o,!0);let c=e.agents.get(l);if(c){!c.cwd&&s.cwd&&(c.cwd=s.cwd,c.cwdBasename=fi(s.cwd));const p=Gl(s);return p&&(c.label==="subagent"||!c.label)&&(c.label=p),c}return c={id:l,sessionId:n,label:Gl(s),kind:"subagent",parentId:u.id,state:"active",startedAt:o,tools:[],prompts:[],cwd:s.cwd,cwdBasename:fi(s.cwd),toolCount:0,childCount:0,inFlightTool:null,usage:wN()},e.agents.set(l,c),u.childCount+=1,c}function SP(e,n,r){const s=e.activeSubagentStack.get(n)??[];s.includes(r)||(s.push(r),e.activeSubagentStack.set(n,s))}function bP(e,n,r){const s=e.activeSubagentStack.get(n);if(s){for(let o=s.length-1;o>=0;o--)if(s[o]===r){s.splice(o,1);break}s.length===0&&e.activeSubagentStack.delete(n)}}function Cl(e,n=80){if(e==null)return"";if(typeof e=="string")return e.length>n?e.slice(0,n-1)+"…":e;try{const r=JSON.stringify(e);return r.length>n?r.slice(0,n-1)+"…":r}catch{return String(e)}}function Hs(e){let n=null;for(let r=e.tools.length-1;r>=0;r--){const s=e.tools[r];if(s.endedAt==null){n=s;break}}e.inFlightTool=n}const nx=200,kP=25;function EP(e,n){const r=n.tools;if(r.length>nx){const s=r.splice(0,r.length-nx);let o=!1;for(const l of s)e.toolIndex.delete(l.id)&&(o=!0),e.toolOwner.delete(l.id);o&&Hs(n)}for(let s=r.length-kP-1;s>=0;s--){const o=r[s];if(o.trimmed)break;o.input=void 0,o.response=void 0,o.trimmed=!0}}function NP(e,n,r){const s=e.toolIndex.get(r);if(s)return s;for(let o=n.tools.length-1;o>=0;o--)if(n.tools[o].id===r)return n.tools[o];return null}const rx=2e3;function CP(e,n,r){for(let s=e.prompts.length-1;s>=0;s--){const o=e.prompts[s];if(o.at<n-rx)return!1;if(o.text===r&&o.at<=n+rx)return!0}return!1}function TP(e,n,r,s){if(e.agents.size<=r)return!1;const o=[];for(const[u,c]of e.agents)c.state==="done"&&c.endedAt!=null&&n-c.endedAt>s&&o.push({id:u,endedAt:c.endedAt});if(o.length===0)return!1;o.sort((u,c)=>u.endedAt-c.endedAt);let l=0;for(const u of o){if(e.agents.size<=r)break;e.agents.delete(u.id),l++}return l>0}function RP(e,n,r,s){const o=new Map;for(const[h,f]of e.agents){let m=o.get(f.sessionId);m||(m={ids:[],endedAt:0,live:!1},o.set(f.sessionId,m)),m.ids.push(h),f.state==="done"&&f.endedAt!=null?m.endedAt=Math.max(m.endedAt,f.endedAt):m.live=!0}const l=[...o.values()].filter(h=>!h.live&&h.endedAt>0&&n-h.endedAt>s).sort((h,f)=>h.endedAt-f.endedAt);let c=[...o.values()].filter(h=>!h.live).length-r;if(c<=0)return!1;let p=!1;for(const h of l){if(c<=0)break;for(const f of h.ids)e.agents.delete(f);c--,p=!0}return p}function jP(e,n,r){let s=!1;for(const o of e.agents.values()){let l=!1;for(const u of o.tools)u.endedAt==null&&n-u.startedAt>r&&(u.endedAt=u.startedAt+r,u.ok=!1,u.errorPreview="stale (no PostToolUse received)",e.toolIndex.delete(u.id),e.toolOwner.delete(u.id),l=!0,s=!0);l&&Hs(o)}return s}function ix(e,n){const r=n.epoch??null;if(r!==null&&r!==e.seqEpoch)e.seqEpoch=r,e.lastSeq=0;else if(n.seq<=e.lastSeq)return e;const s=n.payload??{},o=n.receivedAt,l=s.hook_event_name??"Unknown";if(l==="__clear")return{...Kg(),lastSeq:n.seq,seqEpoch:e.seqEpoch};e.totalEvents+=1,e.lastSeq=n.seq;const u=s.session_id??"unknown";if(typeof s.model_context_window=="number"&&s.model_context_window>0){const h=e.agents.get(u);h&&(h.contextWindow=s.model_context_window)}if(l==="ModelObserved"){const h=typeof s.model=="string"?s.model:null;if(h){const m=e.agents.get(u);m&&(m.model=h)}const f=s.subagentModels;if(f&&typeof f=="object")for(const[m,y]of Object.entries(f)){if(typeof y!="string")continue;const x=`${u}::${m}`,C=e.agents.get(x);C&&(C.model=y)}return e}if(l==="ContextObserved"){const h=s.context??null;if(h){const f=e.agents.get(u);f&&(f.context={msgsUser:Number(h.msgsUser??0),msgsAssistant:Number(h.msgsAssistant??0),toolUses:Number(h.toolUses??0),toolResults:Number(h.toolResults??0),systemReminders:Number(h.systemReminders??0),currentContextTokens:Number(h.currentContextTokens??0),claudeMdFiles:Array.isArray(h.claudeMdFiles)?h.claudeMdFiles:[]})}return e}if(l==="UsageObserved"){const h=s.usage??null;if(h){const f=e.agents.get(u);if(f){f.usage.inputTokens=Number(h.input_tokens??0),f.usage.outputTokens=Number(h.output_tokens??0),f.usage.cacheReadTokens=Number(h.cache_read_input_tokens??h.cached_input_tokens??0),f.usage.cacheCreateTokens=Number(h.cache_creation_input_tokens??0);const m=xN(h);f.usage.cacheCreate1hTokens=m.cacheCreate1hTokens,f.usage.cacheCreate5mTokens=m.cacheCreate5mTokens,typeof h.reasoning_output_tokens=="number"&&(f.usage.reasoningOutputTokens=Number(h.reasoning_output_tokens))}}return e}const c=tx(e,s,o);c.provider||(c.provider=s.provider==="codex"?"codex":"claude");const p=SN(s);switch(p&&(c.model=p),l){case"SessionStart":{const h=Ko(e,u,o,!1);h.synthetic=!1,h.state="active",h.startedAt=h.startedAt||o,!h.cwd&&s.cwd&&(h.cwd=s.cwd,h.cwdBasename=fi(s.cwd)),h.label==="session"&&s.cwd&&(h.label=fi(s.cwd)??"session");break}case"UserPromptSubmit":{for(const y of e.agents.values())y.sessionId===u&&y.kind==="subagent"&&y.state==="done"&&y.exitAt==null&&y.endedAt!=null&&y.endedAt<o&&(y.exitAt=o);const h=Ko(e,u,o,!1);h.state="active",h.endedAt=void 0,h.exitAt=void 0;const f=tx(e,s,o);f.state="active",f.exitAt=void 0,f.endedAt=void 0;const m=(typeof s.prompt=="string"?s.prompt:typeof s.message=="string"?s.message:"")??"";m&&!CP(f,o,m)&&(f.prompts.push({at:o,text:m}),f.firstPrompt||(f.firstPrompt=Cl(m,120)));break}case"PreToolUse":{const h=s.tool_use_id?NP(e,c,s.tool_use_id):null;if(h){s.tool_name&&h.name==="?"&&(h.name=s.tool_name),h.endedAt==null&&!h.trimmed&&s.tool_input!==void 0&&(h.input=s.tool_input,h.inputPreview=Cl(s.tool_input));break}const f=s.tool_use_id??`${c.id}:${c.toolCount}`,m={id:f,name:s.tool_name??"?",input:s.tool_input,inputPreview:Cl(s.tool_input),agentId:c.id,startedAt:o};c.tools.push(m),c.toolCount+=1,c.state="active",e.toolIndex.set(f,m),e.toolOwner.set(f,c.id),Hs(c),EP(e,c);break}case"PostToolUse":case"PostToolUseFailure":{const h=s.tool_use_id;if(!h)break;let f=e.toolIndex.get(h),m=!1;if(!f)for(const C of e.agents.values()){const _=C.tools.find(S=>S.id===h);if(_){f=_,m=!0;break}}if(!f)break;f.endedAt=o,f.ok=l==="PostToolUse",f.trimmed||(f.response=s.tool_response),l==="PostToolUseFailure"?f.errorPreview=Cl(s.tool_response):m&&(f.errorPreview=void 0);const y=_N(s.tool_response);y&&(f.usage=y),e.toolIndex.delete(h);const x=e.toolOwner.get(h)??f.agentId;if(e.toolOwner.delete(h),x){const C=e.agents.get(x);C&&(y&&wP(C.usage,y),Hs(C))}break}case"SubagentStart":{const h=Xg(s);if(!h)break;const f=_P(e,u,h,s,o);f.state="active",f.startedAt=f.startedAt||o,f.exitAt=void 0,f.endedAt=void 0;const m=Gl(s);m&&(f.label=m),SP(e,u,h);break}case"SubagentStop":{const h=Xg(s);if(!h)break;const f=bN(e,u,h,s);if(!f)break;f.state="done",f.endedAt=o,Hs(f),bP(e,u,h);break}case"Stop":case"SessionEnd":{const h=Ko(e,u,o,!1);h.state="done",h.endedAt=o,Hs(h),e.activeSubagentStack.delete(u);break}}return e}function _v(e){let n=5381;for(let r=0;r<e.length;r++)n=(n<<5)+n^e.charCodeAt(r);return Math.abs(n)%360}const AP=Date.UTC(2026,8,1);function IP(e){return e<AP?{input:2,output:10,cacheRead:.2,cacheWrite:2.5,cacheWrite1h:4}:{input:3,output:15,cacheRead:.3,cacheWrite:3.75,cacheWrite1h:6}}const MP=[{match:/^claude[-_](fable|mythos)[-_]5\b/i,rates:{input:10,output:50,cacheRead:1,cacheWrite:12.5,cacheWrite1h:20}},{match:/^claude[-_]opus[-_]5\b/i,rates:{input:5,output:25,cacheRead:.5,cacheWrite:6.25,cacheWrite1h:10}},{match:/^claude[-_]sonnet[-_]5\b/i,rates:IP},{match:/^claude[-_]opus[-_]4[-_.](?:5|6|7|8)\b/i,rates:{input:5,output:25,cacheRead:.5,cacheWrite:6.25,cacheWrite1h:10}},{match:/^claude[-_]opus[-_]4(?:[-_.]1)?\b/i,rates:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75,cacheWrite1h:30}},{match:/^claude[-_]sonnet[-_]4[-_.](?:5|6)\b/i,rates:{input:3,output:15,cacheRead:.3,cacheWrite:3.75,cacheWrite1h:6}},{match:/^claude[-_]sonnet[-_]4\b/i,rates:{input:3,output:15,cacheRead:.3,cacheWrite:3.75,cacheWrite1h:6}},{match:/^claude[-_]haiku[-_]4[-_.]5\b/i,rates:{input:1,output:5,cacheRead:.1,cacheWrite:1.25,cacheWrite1h:2}},{match:/^claude[-_]haiku[-_]3[-_.]5\b/i,rates:{input:.8,output:4,cacheRead:.08,cacheWrite:1,cacheWrite1h:1.6}},{match:/^gpt[-_]5[-_.]6[-_]cyber/i,rates:{input:12.5,output:75,cacheRead:1.25,cacheWrite:0}},{match:/^gpt[-_]5[-_.]6[-_]luna/i,rates:{input:.2,output:1.2,cacheRead:.02,cacheWrite:.25}},{match:/^gpt[-_]5[-_.]6[-_]terra/i,rates:{input:2,output:12,cacheRead:.2,cacheWrite:2.5}},{match:/^gpt[-_]5[-_.]6(?:[-_]sol)?\b/i,rates:{input:5,output:30,cacheRead:.5,cacheWrite:6.25}},{match:/^gpt[-_]5[-_.]5[-_]pro/i,rates:{input:30,output:180,cacheRead:30,cacheWrite:0}},{match:/^gpt[-_]5[-_.]5\b/i,rates:{input:5,output:30,cacheRead:.5,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4[-_]pro/i,rates:{input:30,output:180,cacheRead:3,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4[-_]mini/i,rates:{input:.75,output:4.5,cacheRead:.075,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4[-_]nano/i,rates:{input:.2,output:1.25,cacheRead:.02,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4\b/i,rates:{input:2.5,output:15,cacheRead:.25,cacheWrite:0}},{match:/^gpt[-_]5[-_.]3[-_]codex/i,rates:{input:1.75,output:14,cacheRead:.175,cacheWrite:0}},{match:/^gpt[-_]5[-_.]2[-_]pro/i,rates:{input:21,output:168,cacheRead:21,cacheWrite:0}},{match:/^gpt[-_]5[-_.]2\b/i,rates:{input:1.75,output:14,cacheRead:.175,cacheWrite:0}},{match:/^codex[-_]mini/i,rates:{input:1.5,output:6,cacheRead:.375,cacheWrite:0}},{match:/^o1[-_]pro/i,rates:{input:150,output:600,cacheRead:150,cacheWrite:0}},{match:/^o1\b/i,rates:{input:15,output:60,cacheRead:7.5,cacheWrite:0}},{match:/^o3[-_]mini/i,rates:{input:1.1,output:4.4,cacheRead:.55,cacheWrite:0}},{match:/^o3[-_]pro/i,rates:{input:20,output:80,cacheRead:20,cacheWrite:0}},{match:/^o4[-_]mini/i,rates:{input:1.1,output:4.4,cacheRead:.275,cacheWrite:0}},{match:/^o3\b/i,rates:{input:2,output:8,cacheRead:.5,cacheWrite:0}}];function PP(e){return e?/^(?:gpt[-_]|codex[-_]|o\d)/i.test(e):!1}function Sv(e,n=Date.now()){if(!e)return null;for(const r of MP)if(r.match.test(e))return typeof r.rates=="function"?r.rates(n):r.rates;return null}function kN(e,n){const r=Math.max(0,e.cacheCreate1hTokens??0),s=Math.max(0,e.cacheCreate5mTokens??0),o=Math.max(0,e.cacheCreateTokens-r-s),l=s+o,u=n.cacheWrite1h??n.cacheWrite;return{tokens5m:l,tokens1h:r,usd5m:l*n.cacheWrite/1e6,usd1h:r*u/1e6}}function cn(e,n,r=Date.now()){const s=Sv(n,r);if(!s)return{input:0,output:0,cacheRead:0,cacheWrite:0,total:0};const u=(PP(n)?Math.max(0,e.inputTokens-e.cacheReadTokens):e.inputTokens)*s.input/1e6,c=e.outputTokens*s.output/1e6,p=e.cacheReadTokens*s.cacheRead/1e6,h=kN(e,s),f=h.usd5m+h.usd1h;return{input:u,output:c,cacheRead:p,cacheWrite:f,total:u+c+p+f}}const sx=2e5,OP=1e6,LP=[/\[1m\]/i,/^claude[-_]opus[-_]5\b/i,/^claude[-_]sonnet[-_]5\b/i,/^claude[-_]opus[-_]4[-_.](?:5|6|7|8)\b/i,/^claude[-_]sonnet[-_]4[-_.]6\b/i,/^claude[-_](fable|mythos)[-_]5\b/i],qP=[{match:/^gpt[-_]5[-_.]6[-_]cyber/i,window:4e5},{match:/^gpt[-_]5[-_.]6/i,window:105e4},{match:/^gpt[-_]5[-_.]5/i,window:105e4},{match:/^gpt[-_]5[-_.]4[-_](?:mini|nano)/i,window:4e5},{match:/^gpt[-_]5[-_.]4/i,window:105e4},{match:/^gpt[-_]5[-_.]3[-_]codex[-_]spark/i,window:128e3},{match:/^gpt[-_]5[-_.]3[-_]codex/i,window:4e5},{match:/^gpt[-_]5[-_.]2/i,window:4e5},{match:/^gpt[-_]5/i,window:4e5},{match:/^codex[-_]mini/i,window:2e5},{match:/^o\d/i,window:2e5}];function $P(e){if(!e)return sx;for(const n of LP)if(n.test(e))return OP;for(const n of qP)if(n.match.test(e))return n.window;return sx}function EN(e,n){return typeof e=="number"&&e>0?e:$P(n)}function ze(e){if(e<=0)return"—";if(e<.005)return"<1¢";if(e<1){const n=(e*100).toFixed(e<.1?1:0);if(Number(n)<100)return`${n}¢`}return e<100?`$${e.toFixed(2)}`:e<1e4?`$${e.toFixed(0)}`:`$${(e/1e3).toFixed(1)}k`}function Yl(e,n){if(e<=0||n<10)return null;const r=e/n,s=r*60;return s>=.01?`${ze(s)}/min`:`${ze(r*3600)}/hr`}function Cn(e){return e.toLocaleString()}function DP(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function FP({agent:e,onClose:n}){var h;const r=e.context,s=e.usage,o=(r==null?void 0:r.currentContextTokens)??0,l=EN(e.contextWindow,e.model),u=Math.min(100,o/l*100),c=cn(s,e.model),p=s.inputTokens+s.cacheReadTokens+s.cacheCreateTokens;return g.jsx("div",{className:"ctx-modal-backdrop",onClick:n,role:"presentation",children:g.jsxs("div",{className:"ctx-modal",onClick:f=>f.stopPropagation(),role:"dialog","aria-label":"Context breakdown",children:[g.jsxs("header",{className:"ctx-modal-head",children:[g.jsxs("div",{children:[g.jsxs("div",{className:"ctx-modal-title",children:["Context · ",e.label]}),g.jsx("div",{className:"ctx-modal-sub",children:"approximation — CC's /context isn't hook-exposed"})]}),g.jsx("button",{className:"ctx-modal-close",onClick:n,"aria-label":"Close",children:"×"})]}),g.jsxs("section",{className:"ctx-window-row",children:[g.jsx("div",{className:"ctx-window-bar",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(u),children:g.jsx("div",{className:"ctx-window-fill",style:{width:`${u}%`}})}),g.jsxs("div",{className:"ctx-window-meta",children:[g.jsxs("span",{className:"ctx-window-pct",children:[u.toFixed(1),"%"]}),g.jsxs("span",{className:"ctx-window-num",children:[Cn(o)," / ",Cn(l)," tok (current turn)"]})]})]}),g.jsx("h3",{className:"ctx-section-title",children:"Cumulative usage · whole session"}),g.jsxs("div",{className:"ctx-grid",children:[g.jsx(Kn,{label:"input tokens",val:Cn(s.inputTokens)}),g.jsx(Kn,{label:"output tokens",val:Cn(s.outputTokens)}),g.jsx(Kn,{label:"cache reads",val:Cn(s.cacheReadTokens)}),g.jsx(Kn,{label:"cache writes",val:Cn(s.cacheCreateTokens)}),g.jsx(Kn,{label:"cumulative total",val:Cn(p)}),g.jsx(Kn,{label:"estimated cost",val:ze(c.total),accent:!0})]}),g.jsx("h3",{className:"ctx-section-title",children:"Transcript composition"}),g.jsxs("div",{className:"ctx-grid",children:[g.jsx(Kn,{label:"user messages",val:Cn((r==null?void 0:r.msgsUser)??0)}),g.jsx(Kn,{label:"assistant messages",val:Cn((r==null?void 0:r.msgsAssistant)??0)}),g.jsx(Kn,{label:"tool uses",val:Cn((r==null?void 0:r.toolUses)??0)}),g.jsx(Kn,{label:"tool results",val:Cn((r==null?void 0:r.toolResults)??0)}),g.jsx(Kn,{label:"system-reminders",val:Cn((r==null?void 0:r.systemReminders)??0)})]}),g.jsx("h3",{className:"ctx-section-title",children:"CLAUDE.md files in scope"}),(((h=r==null?void 0:r.claudeMdFiles)==null?void 0:h.length)??0)===0?g.jsx("div",{className:"ctx-empty",children:"No CLAUDE.md files found on the path from cwd to ~/.claude."}):g.jsx("ul",{className:"ctx-md-list",children:r.claudeMdFiles.map(f=>g.jsxs("li",{children:[g.jsx("span",{className:"ctx-md-path",title:f.path,children:f.path}),g.jsx("span",{className:"ctx-md-size",children:DP(f.bytes)})]},f.path))})]})})}function Kn({label:e,val:n,accent:r}){return g.jsxs("div",{className:`ctx-row${r?" accent":""}`,children:[g.jsx("span",{className:"ctx-row-label",children:e}),g.jsx("span",{className:"ctx-row-val",children:n})]})}function zP({currentContextTokens:e,modelId:n,contextWindow:r,size:s=26,onClick:o,title:l}){const u=EN(r,n),c=Math.min(1,e/u),p=s/2-3,h=s/2,f=2*Math.PI*p,m=f*c,y=c>.9?"var(--err)":c>.7?"var(--inflight)":"var(--accent)";return g.jsx("button",{type:"button",className:"ctx-donut",onClick:o,title:l??`context: ${e.toLocaleString()} / ${u.toLocaleString()} (${(c*100).toFixed(1)}%)`,"aria-label":"Show context breakdown",children:g.jsxs("svg",{width:s,height:s,viewBox:`0 0 ${s} ${s}`,children:[g.jsx("circle",{cx:h,cy:h,r:p,stroke:"var(--line)",strokeWidth:"2.5",fill:"none"}),g.jsx("circle",{cx:h,cy:h,r:p,stroke:y,strokeWidth:"2.5",fill:"none",strokeDasharray:`${m} ${f-m}`,strokeDashoffset:f/4,strokeLinecap:"round",style:{transition:"stroke-dasharray 400ms ease"}}),g.jsx("text",{x:h,y:h+3,textAnchor:"middle",fontSize:"8",fill:"var(--text)",fontWeight:"600",children:Math.round(c*100)})]})})}function BP(e,n){const r=Sv(n);if(!r)return"no rates for this model";const s=p=>p.toLocaleString(),o=p=>`$${p}/MTok`,l=cn(e,n),u=kN(e,r),c=u.tokens1h>0?[`cache w5m${s(u.tokens5m).padStart(14)} × ${o(r.cacheWrite).padEnd(11)} = ${ze(u.usd5m)}`,`cache w1h${s(u.tokens1h).padStart(14)} × ${o(r.cacheWrite1h??r.cacheWrite).padEnd(11)} = ${ze(u.usd1h)}`]:[`cache w ${s(u.tokens5m).padStart(14)} × ${o(r.cacheWrite).padEnd(11)} = ${ze(u.usd5m)}`];return[`model: ${n}`,`input ${s(e.inputTokens).padStart(14)} × ${o(r.input).padEnd(11)} = ${ze(l.input)}`,`output ${s(e.outputTokens).padStart(14)} × ${o(r.output).padEnd(11)} = ${ze(l.output)}`,`cache r ${s(e.cacheReadTokens).padStart(14)} × ${o(r.cacheRead).padEnd(11)} = ${ze(l.cacheRead)}`,...c,"─────────────────────────────────────────",`total = ${ze(l.total)}`].join(`
58
58
  `)}function UP(e,n,r){const s=(n??r)-e;if(s<1e3)return`${Math.max(0,s)}ms`;const o=Math.floor(s/1e3);if(o<60)return`${o}s`;const l=Math.floor(o/60),u=o%60;return`${l}m ${String(u).padStart(2,"0")}s`}function HP({data:e,selected:n}){var h;const r=e.now??Date.now(),s=["agent-node",`state-${e.state}`,e.synthetic?"synthetic":"",n?"selected":""].filter(Boolean).join(" "),o=e.tools.filter(f=>!f.endedAt).length,u=`hsl(${_v(e.sessionId)} 70% 60%)`,c=((h=e.context)==null?void 0:h.currentContextTokens)??0,p=e.kind==="root"&&c>0;return g.jsxs("div",{className:s,style:{"--accent":u},children:[g.jsx("span",{className:"accent-stripe"}),g.jsx(Zs,{type:"target",position:Re.Left,style:{background:"transparent",border:"none"}}),g.jsxs("div",{className:"head",children:[g.jsxs("div",{className:"title",children:[g.jsx(WP,{state:e.state}),g.jsx("span",{className:"label",title:e.cwd,children:e.label}),e.synthetic&&g.jsx("span",{className:"synth-tag",title:"No SessionStart captured — synthesised",children:"?"})]}),g.jsxs("div",{className:"head-right",children:[p&&e.onOpenContext&&g.jsx(zP,{currentContextTokens:c,modelId:e.model,contextWindow:e.contextWindow,onClick:()=>e.onOpenContext(e.sessionId)}),g.jsx("div",{className:"time",title:`Started ${new Date(e.startedAt).toLocaleTimeString()}`,children:UP(e.startedAt,e.endedAt,r)})]})]}),g.jsxs("div",{className:"sub",children:[e.kind==="root"?"session":"subagent",e.childCount>0&&g.jsxs("span",{className:"spawn-badge",title:`${e.childCount} subagents spawned`,children:["→ ",e.childCount]}),e.cwdBasename&&e.kind==="subagent"?` · ${e.cwdBasename}`:"",e.model&&g.jsx("span",{className:"model-chip",title:e.model,children:da(e.model)})]}),e.tools.length>0&&g.jsx(GP,{tools:e.tools,now:r}),g.jsxs("div",{className:"meta",children:[g.jsxs("span",{children:[g.jsx("b",{children:e.toolCount})," tools"]}),o>0&&g.jsxs("span",{className:"inflight-meta",children:[g.jsx("b",{children:o})," in-flight"]}),e.usage.inputTokens+e.usage.outputTokens>0&&g.jsxs("span",{className:"tokens-meta",title:`in:${e.usage.inputTokens} out:${e.usage.outputTokens} cache-r:${e.usage.cacheReadTokens} cache-c:${e.usage.cacheCreateTokens}${(e.usage.reasoningOutputTokens??0)>0?` reasoning:${e.usage.reasoningOutputTokens}`:""}`,children:[g.jsx("b",{children:VP(e.usage.inputTokens+e.usage.outputTokens)})," tok"]}),e.model&&Sv(e.model)&&(()=>{const f=cn(e.usage,e.model);if(f.total<=0)return null;const m=Math.max(0,((e.endedAt??r)-e.startedAt)/1e3),y=e.state==="active"?Yl(f.total,m):null,x=BP(e.usage,e.model)+(y?`
59
- burn: ${y}`:"");return g.jsxs("span",{className:"cost-meta",title:x,children:[g.jsx("b",{children:ze(f.total)}),y&&g.jsx("span",{className:"cost-rate",children:y})]})})()]}),g.jsx(Zs,{type:"source",position:Re.Right,style:{background:"transparent",border:"none"}})]})}function WP({state:e}){const n=e==="active"?"live":e==="done"?"done":"err";return g.jsx("span",{className:`state-pill state-${e}`,children:n})}function VP(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function GP({tools:e,now:n}){const l=new Array(24).fill(0);let u=0;for(const y of e){const x=n-y.startedAt;if(x<0||x>=6e4)continue;const C=23-Math.floor(x/2500);C>=0&&C<24&&(l[C]+=1,u+=1)}const c=Math.max(1,...l),p=132,h=14,f=p/24,m=c/(2500/1e3);return g.jsxs("div",{className:"tool-spark-row",title:`${u} tool calls in last 60s · peak ${m.toFixed(1)}/s`,children:[g.jsx("svg",{className:"tool-spark",width:p,height:h,viewBox:`0 0 ${p} ${h}`,"aria-hidden":!0,children:l.map((y,x)=>{const C=y===0?1.5:Math.max(1.5,y/c*h),_=x===23&&y>0,b=`tool-spark-bar${y>0?" active":""}${_?" latest":""}`;return g.jsx("rect",{x:x*f+.4,y:h-C,width:Math.max(.5,f-1),height:C,rx:.8,className:b},x)})}),g.jsx("span",{className:"tool-spark-label",children:"60s"})]})}function da(e){const n=e.match(/^claude[-_](opus|sonnet|haiku|fable|mythos)[-_](\d+(?:[-_.]\d+)*)/i);if(n){const o=n[1][0].toUpperCase()+n[1].slice(1).toLowerCase(),l=n[2].replace(/[-_]/g,".");return`${o} ${l}`}const r=e.match(/^gpt[-_](\d+(?:[-_.]\d+)*)[-_]codex\b/i);if(r)return`GPT-${r[1].replace(/[-_]/g,".")} Codex`;const s=e.match(/^gpt[-_](\d+(?:[-_.]\d+)*)/i);return s?`GPT-${s[1].replace(/[-_]/g,".")}`:e}function ox(e){if(e==null)return"(none)";if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function YP(e){if(e.endedAt==null)return"in-flight…";const n=e.endedAt-e.startedAt;return n<1e3?`${n}ms`:`${(n/1e3).toFixed(2)}s`}function KP({tool:e,onClose:n}){A.useEffect(()=>{const s=o=>{o.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]);const r=e.endedAt==null?"inflight":e.ok===!1?"err":"done";return g.jsx("div",{className:"modal-backdrop",onClick:n,role:"dialog","aria-modal":"true",children:g.jsxs("div",{className:"modal",onClick:s=>s.stopPropagation(),children:[g.jsxs("header",{className:"modal-head",children:[g.jsxs("div",{className:"modal-title",children:[g.jsx("span",{className:`status-dot ${r}`}),g.jsx("span",{className:"modal-tool-name",children:e.name}),g.jsxs("span",{className:"modal-tool-id",title:e.id,children:[e.id.slice(0,12),"…"]})]}),g.jsxs("div",{className:"modal-actions",children:[g.jsx("span",{className:"modal-dur",children:YP(e)}),g.jsx("button",{className:"btn icon-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]})]}),g.jsxs("section",{className:"modal-body",children:[e.trimmed&&g.jsx("div",{className:"modal-section",children:g.jsx("p",{className:"modal-note",children:"Full payloads for this call were released to keep memory bounded — only the previews below are still held."})}),g.jsxs("div",{className:"modal-section",children:[g.jsx("h4",{children:"Input"}),g.jsx("pre",{children:ox(e.input??e.inputPreview)})]}),g.jsxs("div",{className:"modal-section",children:[g.jsxs("h4",{children:["Response ",r==="err"&&g.jsx("span",{className:"err-tag",children:"error"})]}),g.jsx("pre",{children:e.endedAt==null?"(waiting…)":ox(e.response??e.errorPreview)})]})]})]})})}const Tl=18,ax=26,XP=12;function QP(e){return ZP(e.nodeInternals.values())}function ZP(e){const n=new Map;for(const o of e){if(o.type!=="agent")continue;const l=o.data;if(!(l!=null&&l.sessionId)||l.exitAt!=null||o.width==null||o.height==null)continue;const u=o.position.x,c=o.position.y,p=u+o.width,h=c+o.height,f=n.get(l.sessionId);f?(f.minX=Math.min(f.minX,u),f.minY=Math.min(f.minY,c),f.maxX=Math.max(f.maxX,p),f.maxY=Math.max(f.maxY,h),l.kind==="root"&&(f.label=lx(l)??f.label)):n.set(l.sessionId,{minX:u,minY:c,maxX:p,maxY:h,label:lx(l)??l.sessionId})}const r=new Map;for(const o of n.values())r.set(o.label,(r.get(o.label)??0)+1);const s=[];for(const[o,l]of n){const c=(r.get(l.label)??0)>1?`${l.label} · ${JP(o)}`:l.label;s.push({sessionId:o,label:c,x:l.minX-Tl,y:l.minY-Tl-ax,w:l.maxX-l.minX+Tl*2,h:l.maxY-l.minY+Tl*2+ax})}return s}function JP(e){const n=e.match(/[a-zA-Z0-9]{4}/);return n?n[0]:e.slice(0,4)}function lx(e){if(e.kind==="root")return e.label}function eO(){const{x:e,y:n,zoom:r}=pN(),s=ca(),o=Ke(QP,tO);if(o.length<=1)return null;const l=u=>{try{const c=s.getNodes().filter(p=>{const h=p.data;return(h==null?void 0:h.sessionId)===u});if(c.length===0)return;s.fitView({padding:.3,duration:500,nodes:c})}catch{}};return g.jsx("div",{className:"session-clusters",children:o.map(u=>{const c=_v(u.sessionId),p={position:"absolute",left:u.x*r+e,top:u.y*r+n,width:u.w*r,height:u.h*r,borderColor:`hsl(${c} 65% 55% / 0.32)`,background:`hsl(${c} 70% 50% / 0.04)`},h={position:"absolute",left:u.x*r+e+16*r,top:(u.y-XP)*r+n,color:`hsl(${c} 70% 78%)`,borderColor:`hsl(${c} 65% 55% / 0.5)`,transform:`scale(${Math.min(1,r)})`,transformOrigin:"left top"};return g.jsxs(le.Fragment,{children:[g.jsx("div",{className:"cluster-card",style:p,"aria-hidden":!0}),g.jsx("button",{type:"button",className:"cluster-label",style:h,title:`Fit view to ${u.label} · drag the wrapper to move the whole session`,onClick:()=>l(u.sessionId),children:u.label})]},u.sessionId)})})}function tO(e,n){if(e.length!==n.length)return!1;for(let r=0;r<e.length;r++){const s=e[r],o=n[r];if(s.sessionId!==o.sessionId||s.label!==o.label||s.x!==o.x||s.y!==o.y||s.w!==o.w||s.h!==o.h)return!1}return!0}function nO({data:e}){return g.jsx("div",{className:"session-group-handle",style:{width:(e==null?void 0:e.w)??0,height:(e==null?void 0:e.h)??0}})}const NN=600,rO=4,iO=36,Qg=16,sO=60,oO=6,ux=220,cx=96,aO=28,lO={Read:"file",Write:"file",Edit:"file",MultiEdit:"file",Glob:"file",Grep:"file",LS:"file",NotebookEdit:"file",Bash:"shell",PowerShell:"shell",shell:"shell",exec_command:"shell",shell_command:"shell",write_stdin:"shell",wait:"shell",apply_patch:"file",update_plan:"task",WebFetch:"web",WebSearch:"web",Task:"agent",Agent:"agent",TodoWrite:"task",TaskCreate:"task",TaskUpdate:"task",TaskList:"task",TaskGet:"task",TaskOutput:"task",TaskStop:"task",EnterPlanMode:"plan",ExitPlanMode:"plan",AskUserQuestion:"plan",Skill:"plan",Workflow:"plan",ScheduleWakeup:"other",CronCreate:"other",CronList:"other",CronDelete:"other",Monitor:"other",PushNotification:"other",RemoteTrigger:"other",ToolSearch:"other"};function uO(e){return e.startsWith("mcp__")?"mcp":lO[e]??"other"}const cO={Read:"📖",Write:"💾",Edit:"✏️",MultiEdit:"🔧",Glob:"🗺️",Grep:"🔎",Bash:"⚡",PowerShell:"💻",shell:"⚡",exec_command:"⚡",shell_command:"⚡",write_stdin:"💻",wait:"⏳",apply_patch:"🩹",update_plan:"📋",LS:"📂",Task:"🤖",Agent:"🤖",TodoWrite:"📋",TaskCreate:"📋",TaskUpdate:"📝",TaskList:"🗂️",TaskGet:"🗂️",TaskOutput:"📤",TaskStop:"🛑",WebFetch:"🌐",WebSearch:"🔭",ToolSearch:"🧰",NotebookEdit:"📓",EnterPlanMode:"🧭",ExitPlanMode:"🏁",AskUserQuestion:"❓",ScheduleWakeup:"⏰",CronCreate:"⏰",CronList:"📅",CronDelete:"🗑️",Skill:"🎯",Workflow:"🎬",Monitor:"📡",PushNotification:"🔔",RemoteTrigger:"📡"};function dx(e){return e.startsWith("mcp__")?"🔌":cO[e]??"✨"}const dO={git:"🐙",gh:"🐙",glab:"🐙",npm:"📦",pnpm:"📦",yarn:"📦",bun:"📦",brew:"🍺",node:"🟢",deno:"🟢",python:"🐍",python3:"🐍",py:"🐍",pip:"🐍",pip3:"🐍",uv:"🐍",ruby:"💎",bundle:"💎",gem:"💎",cargo:"🦀",rustc:"🦀",rustup:"🦀",go:"🐹",docker:"🐳","docker-compose":"🐳",podman:"🐳",kubectl:"☸️",helm:"☸️",k9s:"☸️",grep:"🔎",rg:"🔎",ag:"🔎",ack:"🔎",find:"🔍",fd:"🔍",locate:"🔍",which:"🔍",ls:"📂",dir:"📂",tree:"📂",cat:"📄",head:"📄",tail:"📄",less:"📄",more:"📄",bat:"📄",cp:"📋",mv:"✂️",rm:"🗑️",rmdir:"🗑️",mkdir:"📁",touch:"📁",sed:"✏️",awk:"✏️",tr:"✏️",curl:"🌐",wget:"🌐",http:"🌐",httpie:"🌐",ssh:"🔐",scp:"🔐",rsync:"🔐",ping:"📡",make:"🔨",cmake:"🔨",ninja:"🔨",bazel:"🔨",just:"🔨",terraform:"🏗️",ansible:"📕",pulumi:"🏗️",ps:"📊",top:"📊",htop:"📊",btm:"📊",kill:"💀",pkill:"💀",systemctl:"⚙️",service:"⚙️",tar:"🗜️",zip:"🗜️",unzip:"🗜️",gzip:"🗜️","7z":"🗜️",vim:"📝",nvim:"📝",nano:"📝",emacs:"📝",code:"📝",jq:"🪺",yq:"🪺",echo:"💬",printf:"💬",ffmpeg:"🎞️",ffprobe:"🎞️",imagemagick:"🖼️",convert:"🖼️","Get-ChildItem":"📂","Get-Content":"📄","Set-Content":"💾","Out-File":"💾","Add-Content":"💾","Set-Location":"📍","Get-Location":"📍","Get-Process":"📊","Start-Process":"▶️","Stop-Process":"💀","Invoke-WebRequest":"🌐","Invoke-RestMethod":"🌐","New-Item":"📁","Remove-Item":"🗑️","Copy-Item":"📋","Move-Item":"✂️","Test-Path":"🔍","Where-Object":"🔎","ForEach-Object":"🔁","Select-Object":"🎯","Measure-Object":"📊","Get-Service":"⚙️","Restart-Service":"⚙️","ConvertTo-Json":"🪺","ConvertFrom-Json":"🪺"};function CN(e){if(!e)return null;let n=e.trim();if(!n)return null;const r=n.match(/^(?:bash|sh|zsh|fish|powershell|pwsh)(?:\.exe)?\s+(?:-c|-Command|-NoProfile|-NonInteractive|\s)+["']([^"']+)["']/i);if(r)return CN(r[1]);for(;;){const l=n.match(/^([A-Z_][A-Z0-9_]*=\S*)\s+/);if(!l)break;n=n.slice(l[0].length)}n=n.replace(/^sudo(?:\s+-\S+)*\s+/,""),n=n.replace(/^(?:time|nohup|xargs)\s+/,"");const s=n.match(/^([^\s|;&<>(]+)/);if(!s)return null;let o=s[1];return o=o.replace(/^.*[/\\]/,""),o=o.replace(/\.(exe|cmd|bat|ps1)$/i,""),o||null}function fO(e){if(typeof e=="string")return e;if(!e||typeof e!="object")return null;const n=e;if(typeof n.cmd=="string")return n.cmd;if(typeof n.command=="string")return n.command;if(Array.isArray(n.command)&&n.command.every(r=>typeof r=="string")){const r=n.command;if(/powershell|cmd|bash|sh(\.exe)?$/i.test(r[0]??"")){const s=r.findIndex(o=>/^(-Command|-c)$/i.test(o));if(s>=0&&s+1<r.length)return r[s+1]}return r.join(" ")}return typeof n.script=="string"?n.script:null}const hO=new Set(["Bash","PowerShell","shell","exec_command","shell_command","write_stdin","wait"]),pO=new Set(["shell","exec_command","shell_command","write_stdin","wait","apply_patch","update_plan"]);function mO(e,n){return pO.has(e)||e.startsWith("mcp__")?Math.max(cx,34+n.length*7.5):cx}function gO(e,n){if(!hO.has(e))return null;const r=fO(n);if(!r)return null;const s=CN(r);return s?{emoji:dO[s]??"⚙️",label:s,category:"shell",detail:r}:null}const vO=new Set(["Read","Write","Edit","MultiEdit","NotebookEdit","LS","Glob","apply_patch"]),fx={ts:"🟦",tsx:"🟦",d:"🟦",js:"🟨",jsx:"🟨",mjs:"🟨",cjs:"🟨",py:"🐍",pyi:"🐍",ipynb:"📓",rs:"🦀",go:"🐹",rb:"💎",erb:"💎",java:"☕",kt:"☕",scala:"☕",gradle:"☕",cs:"🔷",fs:"🔷",php:"🐘",swift:"🦅",c:"🇨",cpp:"🇨",cc:"🇨",h:"🇨",hpp:"🇨",md:"📝",mdx:"📝",rst:"📝",json:"🪺",json5:"🪺",jsonl:"🪺",yaml:"⚙️",yml:"⚙️",toml:"⚙️",ini:"⚙️",conf:"⚙️",cfg:"⚙️",xml:"📰",html:"🌐",htm:"🌐",vue:"🌐",svelte:"🌐",css:"🎨",scss:"🎨",sass:"🎨",less:"🎨",sh:"⚡",bash:"⚡",zsh:"⚡",fish:"⚡",ps1:"⚡",txt:"📄",log:"📄",out:"📄",csv:"📊",tsv:"📊",xlsx:"📊",xls:"📊",pdf:"📕",png:"🖼️",jpg:"🖼️",jpeg:"🖼️",gif:"🖼️",webp:"🖼️",svg:"🖼️",ico:"🖼️",mp4:"🎬",mov:"🎬",avi:"🎬",mkv:"🎬",webm:"🎬",mp3:"🎵",wav:"🎵",ogg:"🎵",flac:"🎵",zip:"🗜️",tar:"🗜️",gz:"🗜️",bz2:"🗜️","7z":"🗜️",xz:"🗜️",rar:"🗜️",env:"🔐",lock:"🔐",pem:"🔐",key:"🔐",crt:"🔐",sql:"🗄️",db:"🗄️",sqlite:"🗄️",parquet:"🗄️"},hx={dockerfile:"🐳",makefile:"🔨",rakefile:"💎","package.json":"📦","pnpm-lock.yaml":"📦","yarn.lock":"📦","cargo.toml":"🦀","cargo.lock":"🦀","go.mod":"🐹","go.sum":"🐹","pyproject.toml":"🐍","requirements.txt":"🐍","readme.md":"📖",readme:"📖",license:"📜",".gitignore":"🐙",".gitattributes":"🐙",".env":"🔐",".dockerignore":"🐳"};function yO(e){const r=e.replace(/\\/g,"/").replace(/\/+$/,""),s=r.lastIndexOf("/");return s>=0?r.slice(s+1):r}function wO(e){const n=e.toLowerCase();if(hx[n])return hx[n];if(n.startsWith("dockerfile."))return"🐳";if(/\.(test|spec)\.[a-z]+$/.test(n))return"🧪";const r=n.lastIndexOf(".");if(r>0&&r<n.length-1){const s=n.slice(r+1);if(fx[s])return fx[s]}return"📄"}function xO(e,n){if(!n||typeof n!="object")return null;const r=n;if(e==="apply_patch"&&typeof r.patch=="string"){const s=r.patch.match(/^\*\*\* (?:Update|Add|Delete) File: (.+)$/m);return s?s[1].trim():null}return typeof r.file_path=="string"?r.file_path:typeof r.notebook_path=="string"?r.notebook_path:typeof r.path=="string"?r.path:e==="Glob"&&typeof r.pattern=="string"?r.pattern:null}function _O(e,n){if(!vO.has(e))return null;const r=xO(e,n);if(!r)return null;const s=yO(r);return s?{emoji:e==="LS"?"📂":wO(s),label:s,category:"file",detail:r}:null}const TN={github:{emoji:"🐙",name:"GitHub"},git:{emoji:"🐙",name:"Git"},gitlab:{emoji:"🦊",name:"GitLab"},slack:{emoji:"💬",name:"Slack"},discord:{emoji:"💬",name:"Discord"},linear:{emoji:"📐",name:"Linear"},jira:{emoji:"🅹",name:"Jira"},atlassian:{emoji:"🅰️",name:"Atlassian"},notion:{emoji:"📓",name:"Notion"},asana:{emoji:"📋",name:"Asana"},intercom:{emoji:"💬",name:"Intercom"},figma:{emoji:"🎨",name:"Figma"},gmail:{emoji:"📧",name:"Gmail"},calendar:{emoji:"📅",name:"Calendar"},drive:{emoji:"☁️",name:"Drive"},zoom:{emoji:"📹",name:"Zoom"},spotify:{emoji:"🎵",name:"Spotify"},youtube:{emoji:"📺",name:"YouTube"},ccd_session:{emoji:"📡",name:"Session"},ccd_directory:{emoji:"📂",name:"Directory"},ccd_session_mgmt:{emoji:"📡",name:"Sessions"},mcp_registry:{emoji:"🧰",name:"Registry"},"computer-use":{emoji:"🖱️",name:"Computer"},"claude-in-chrome":{emoji:"🌐",name:"Chrome"},"claude-preview":{emoji:"👀",name:"Preview"},"scheduled-tasks":{emoji:"⏰",name:"Scheduler"},visualize:{emoji:"🎨",name:"Visualize"},"plugin-design-asana":{emoji:"📋",name:"Asana"},"plugin-design-atlassian":{emoji:"🅰️",name:"Atlassian"},"plugin-design-figma":{emoji:"🎨",name:"Figma"},"plugin-design-intercom":{emoji:"💬",name:"Intercom"},"plugin-design-linear":{emoji:"📐",name:"Linear"},"plugin-design-notion":{emoji:"📓",name:"Notion"},"plugin-design-slack":{emoji:"💬",name:"Slack"}};function RN(e){if(!e.startsWith("mcp__"))return null;const n=e.slice(5),r=n.indexOf("__");return r<=0?{server:n,method:""}:{server:n.slice(0,r),method:n.slice(r+2)}}function SO(e){let n=5381;for(let r=0;r<e.length;r++)n=(n<<5)+n^e.charCodeAt(r);return Math.abs(n)%360}function bO(e,n){const r=RN(e);if(!r)return null;const{server:s,method:o}=r;if(!o)return null;const l=TN[s.toLowerCase()];return{emoji:(l==null?void 0:l.emoji)??"🔌",label:o,category:"mcp",detail:l?`${l.name} · ${o}`:`${s} · ${o}`}}function kO(e,n){return gO(e,n)??_O(e,n)??bO(e)}const EO={shell:"Shell",exec_command:"Shell",shell_command:"Shell",write_stdin:"stdin",wait:"wait",apply_patch:"Edit",update_plan:"Plan"};function NO(e){const n=RN(e);if(n){const s=TN[n.server.toLowerCase()];return s?{emoji:s.emoji,label:s.name}:{emoji:"🔌",label:n.server,hue:SO(n.server)}}const r=EO[e];return r?{emoji:dx(e),label:r}:{emoji:dx(e),label:e}}function CO(e){return e.endedAt==null?"inflight":e.ok===!1?"err":"done"}function TO(e,n,r){if(r==null)return 1;const s=n-r;return s<0?1:Math.max(0,1-s/NN)}function RO(e,n){const r=[],s=new Set;for(let o=e.length-1;o>=0&&r.length<n;o--){const l=e[o];s.has(l.id)||(s.add(l.id),r.push(l))}return r.reverse()}function jO(e,n,r,s,o,l){const u=[];for(const c of e.values()){if(!n.has(c.id)||c.exitAt!=null&&l-c.exitAt>NN)continue;const p=s.get(c.id)??r.get(c.id);if(!p)continue;const h=RO(c.tools,rO);if(h.length===0)continue;const f=c.exitAt??null,m=o.get(c.id),y=Math.max((m==null?void 0:m.width)??ux,ux),x=(m==null?void 0:m.height)??130,C=p.x,_=p.y,S=C+y,b=_+x/2;h.forEach((E,N)=>{const T=N*iO,I=C+y+sO,M=_+oO+T,O=TO(E,l,f),H=E.inputPreview??"",L=CO(E),P=O<.999,q=NO(E.name);u.push({id:`${c.id}::${E.id}`,toolId:E.id,agentId:c.id,toolName:E.name,name:q.label,emoji:q.emoji,status:L,category:uO(E.name),mcpHue:q.hue,inputPreview:H,fade:O,fading:P,worldX:I,worldY:M,anchorX:S,anchorY:b,spawnDx:S-I,spawnDy:b-(M+Qg)});const W=kO(E.name,E.input);if(W){const B=mO(E.name,q.label),j=I+B+aO,K=M,U=I+B,ee=M+Qg;u.push({id:`sub:${c.id}::${E.id}`,toolId:E.id,agentId:c.id,toolName:E.name,name:W.label,emoji:W.emoji,isSub:!0,status:L,category:W.category,inputPreview:W.detail??H,fade:O,fading:P,worldX:j,worldY:K,anchorX:U,anchorY:ee,spawnDx:U-j,spawnDy:0})}})}return u}function AO({agents:e,visibleAgentIds:n,positions:r,pinned:s,measured:o,dimUnmatched:l,spotlight:u,hiddenCategories:c,now:p,onOpenTool:h}){const f=jO(e,n,r,s,o,p),m=c&&c.size>0?f.filter(y=>!c.has(y.category)):f;return g.jsx(IO,{bursts:m,dimUnmatched:l,spotlight:u,onOpenTool:h})}function IO({bursts:e,dimUnmatched:n,spotlight:r,onOpenTool:s}){const{x:o,y:l,zoom:u}=pN();return g.jsxs("div",{className:"tool-bursts-layer","aria-hidden":!0,children:[g.jsx("svg",{className:"tool-bursts-svg",children:e.map(c=>{const p=c.anchorX*u+o,h=c.anchorY*u+l,f=(c.worldX+6)*u+o,m=(c.worldY+Qg)*u+l,y=p+(f-p)*.55,x=n!=null&&!n.has(c.agentId),C=r!=null&&!r.has(c.agentId),_=c.fade*(x||C?.14:1);return g.jsx("path",{d:`M ${p} ${h} Q ${y} ${h}, ${f} ${m}`,className:`tool-conn status-${c.status}${c.fading?" fading":""}`,opacity:_},`l:${c.id}`)})}),e.map(c=>{const p=c.worldX*u+o,h=c.worldY*u+l,f={left:`${p}px`,top:`${h}px`,transform:`scale(${u})`,transformOrigin:"left top","--spawn-dx":`${c.spawnDx}px`,"--spawn-dy":`${c.spawnDy}px`},m=c.isSub?`${c.toolName} · ${c.name}`:c.toolName,y=c.inputPreview?`${m} · ${c.inputPreview}`:m,x=s!=null,C=c.mcpHue!=null?{"--cat-accent":`hsl(${c.mcpHue} 65% 65%)`}:{},_=n!=null&&!n.has(c.agentId),S=r!=null&&!r.has(c.agentId),b=_||S?" dim":"";return g.jsx("div",{className:"tool-burst-wrap",style:f,children:g.jsxs("div",{className:`tool-burst cat-${c.category} status-${c.status}${c.fading?" fading":""}${x?" clickable":""}${c.isSub?" sub":""}${b}`,style:C,title:y,role:x?"button":void 0,tabIndex:x?0:void 0,"aria-label":x?`Open ${c.toolName} ${c.status==="inflight"?"in flight":c.status} — click for details`:void 0,onClick:x?()=>s(c.toolId):void 0,onKeyDown:x?E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),s(c.toolId))}:void 0,children:[g.jsx("span",{className:"tb-emoji",children:c.emoji}),g.jsx("span",{className:"tb-name",children:c.name}),c.status==="inflight"&&g.jsx("span",{className:"tb-spin"}),c.status==="done"&&g.jsx("span",{className:"tb-mark done",children:"✓"}),c.status==="err"&&g.jsx("span",{className:"tb-mark err",children:"×"})]})},c.id)})]})}function MO({state:e,sessionId:n,onClose:r}){const s=A.useMemo(()=>OO(e,n),[e,n]);return s?g.jsx("div",{className:"modal-backdrop",onClick:r,role:"presentation",children:g.jsxs("div",{className:"modal session-summary",onClick:o=>o.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"ss-title",children:[g.jsxs("div",{className:"modal-head",children:[g.jsxs("div",{className:"modal-title",children:[g.jsx("span",{className:"state-pill state-done","aria-hidden":!0,children:"done"}),g.jsx("span",{id:"ss-title",className:"modal-tool-name",title:s.cwd??s.sessionId,children:s.label}),g.jsxs("span",{className:"modal-tool-id",children:["· ",s.sessionId.slice(0,8)]})]}),g.jsxs("div",{className:"modal-actions",children:[g.jsx("span",{className:"modal-dur",title:"Total wall time",children:s.durationLabel}),g.jsx("button",{className:"btn",onClick:r,"aria-label":"Close",children:"×"})]})]}),g.jsxs("div",{className:"modal-body",children:[g.jsxs("section",{className:"ss-hero",children:[g.jsxs("div",{className:"ss-hero-left",children:[g.jsx("div",{className:"ss-cost-label",children:"total spend"}),g.jsx("div",{className:"ss-cost",children:ze(s.cost.total)}),s.modelChips.length>0&&g.jsx("div",{className:"ss-models",children:s.modelChips.map(o=>g.jsx("span",{className:"model-chip",title:o,children:da(o)},o))})]}),g.jsx("div",{className:"ss-hero-right",children:s.cost.total>0&&g.jsxs(g.Fragment,{children:[g.jsx(PO,{cost:s.cost}),g.jsxs("div",{className:"ss-cost-legend",children:[g.jsxs("span",{className:"ssl ssl-in",children:["input ",g.jsx("b",{children:ze(s.cost.input)})]}),g.jsxs("span",{className:"ssl ssl-out",children:["output ",g.jsx("b",{children:ze(s.cost.output)})]}),g.jsxs("span",{className:"ssl ssl-cr",children:["cache r ",g.jsx("b",{children:ze(s.cost.cacheRead)})]}),g.jsxs("span",{className:"ssl ssl-cw",children:["cache w ",g.jsx("b",{children:ze(s.cost.cacheWrite)})]})]})]})})]}),g.jsxs("section",{className:"ss-stats",children:[g.jsx(Fs,{label:"agents",value:s.agentCount}),g.jsx(Fs,{label:"subagents",value:s.subagentCount}),g.jsx(Fs,{label:"tool calls",value:s.toolCount}),g.jsx(Fs,{label:"prompts",value:s.promptCount}),g.jsx(Fs,{label:"tokens",value:s.tokensSum.toLocaleString()}),s.errCount>0&&g.jsx(Fs,{label:"errors",value:s.errCount,tone:"err"})]}),s.topTools.length>0&&g.jsxs("section",{className:"modal-section",children:[g.jsx("h4",{children:"Most-used tools"}),g.jsx("div",{className:"ss-top-tools",children:s.topTools.map(([o,l])=>g.jsxs("div",{className:"ss-tt",children:[g.jsx("span",{className:"ss-tt-name",children:o}),g.jsx("span",{className:"ss-tt-bar",children:g.jsx("span",{className:"ss-tt-bar-fill",style:{width:`${l/s.topTools[0][1]*100}%`}})}),g.jsx("span",{className:"ss-tt-count",children:l})]},o))})]}),s.firstPrompt&&g.jsxs("section",{className:"modal-section",children:[g.jsx("h4",{children:"Opening prompt"}),g.jsx("div",{className:"ss-prompt",children:s.firstPrompt})]})]})]})}):null}function Fs({label:e,value:n,tone:r}){return g.jsxs("div",{className:`ss-stat${r?` tone-${r}`:""}`,children:[g.jsx("div",{className:"ss-stat-value",children:n}),g.jsx("div",{className:"ss-stat-label",children:e})]})}function PO({cost:e}){const n=e.total;if(n<=0)return null;const r=(s,o,l)=>{if(s<=0)return null;const u=s/n*100;return g.jsx("span",{className:`cb-seg ${o}`,style:{width:`${u}%`},title:`${l}: ${ze(s)} (${u.toFixed(0)}%)`},o)};return g.jsxs("div",{className:"cost-bar cost-bar-lg","aria-label":"Cost breakdown",children:[r(e.input,"cb-input","input"),r(e.output,"cb-output","output"),r(e.cacheRead,"cb-cache-r","cache read"),r(e.cacheWrite,"cb-cache-w","cache write")]})}function OO(e,n){const r=e.agents.get(n);if(!r)return null;const s=[];for(const N of e.agents.values())N.sessionId===n&&s.push(N);if(s.length===0)return null;const o={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},l=new Set,u=new Map;let c=0,p=0,h=0,f=0,m=0,y,x=1/0,C=0;for(const N of s){const T=cn(N.usage,N.model);o.input+=T.input,o.output+=T.output,o.cacheRead+=T.cacheRead,o.cacheWrite+=T.cacheWrite,o.total+=T.total,N.model&&l.add(N.model),N.kind==="subagent"&&m++,p+=N.prompts.length,!y&&N.prompts.length>0&&(y=N.prompts[0].text),h+=N.usage.inputTokens+N.usage.outputTokens,c+=N.toolCount,x=Math.min(x,N.startedAt),C=Math.max(C,N.endedAt??Date.now());for(const I of N.tools)u.set(I.name,(u.get(I.name)??0)+1),I.ok===!1&&f++}const _=Math.max(0,C-x),S=Math.floor(_/1e3),b=S<60?`${S}s`:S<3600?`${Math.floor(S/60)}m ${String(S%60).padStart(2,"0")}s`:`${Math.floor(S/3600)}h ${Math.floor(S%3600/60)}m`,E=Array.from(u.entries()).sort((N,T)=>T[1]-N[1]).slice(0,5);return{sessionId:n,label:r.label||r.cwdBasename||"session",cwd:r.cwd,durationLabel:b,cost:o,modelChips:Array.from(l),agentCount:s.length,subagentCount:m,toolCount:c,promptCount:p,tokensSum:h,errCount:f,topTools:E,firstPrompt:y}}function LO(e,n){const r=[];for(const s of e.agents.values()){if(s.kind!=="root")continue;let o=s.toolCount,l=cn(s.usage,s.model).total,u=s.endedAt??s.startedAt;for(const c of e.agents.values()){if(c.sessionId!==s.sessionId||c.kind==="root")continue;o+=c.toolCount,l+=cn(c.usage,c.model).total;const p=c.endedAt??c.startedAt;p>u&&(u=p)}r.push({sessionId:s.sessionId,label:s.label||s.cwdBasename||"session",cwdBasename:s.cwdBasename,state:s.state,modelId:s.model,toolCount:o,cost:l,startedAt:s.startedAt,lastActivity:u})}return r.sort((s,o)=>{if(s.state!==o.state){if(s.state==="active")return-1;if(o.state==="active")return 1}return o.lastActivity-s.lastActivity}),r}function qO(e,n,r){const s=(n??r)-e;if(s<1e3)return"<1s";const o=Math.floor(s/1e3);if(o<60)return`${o}s`;const l=Math.floor(o/60);return l<60?`${l}m`:`${Math.floor(l/60)}h ${l%60}m`}function $O({state:e,now:n,selectedIds:r,onSelect:s,onClose:o}){const l=A.useMemo(()=>LO(e),[e,e.lastSeq,n]),u=l.filter(c=>c.state==="active").length;return g.jsxs("aside",{className:"session-list","aria-label":"Sessions",children:[g.jsxs("div",{className:"sl-header",children:[g.jsxs("h3",{children:["Sessions ",g.jsx("span",{className:"sl-count",children:l.length})]}),u>0&&g.jsxs("span",{className:"sl-live-count",children:[u," live"]}),g.jsx("button",{className:"btn icon-btn sl-close",onClick:o,title:"Hide sidebar (L)","aria-label":"Hide session list",children:"‹"})]}),g.jsxs("div",{className:"sl-rows",children:[l.length===0&&g.jsx("div",{className:"sl-empty",children:"No sessions yet."}),l.map(c=>{const p=r.has(c.sessionId);return g.jsxs("button",{type:"button",className:`sl-row state-${c.state}${p?" selected":""}`,onClick:()=>s(c.sessionId),title:`Focus ${c.label}`,children:[g.jsx("span",{className:`sl-dot state-${c.state}`,"aria-hidden":!0}),g.jsxs("div",{className:"sl-row-body",children:[g.jsxs("div",{className:"sl-row-head",children:[g.jsx("span",{className:"sl-label",children:c.label}),c.modelId&&g.jsx("span",{className:"model-chip",title:c.modelId,children:da(c.modelId)})]}),g.jsxs("div",{className:"sl-row-meta",children:[g.jsxs("span",{title:"tool calls",children:[g.jsx("b",{children:c.toolCount})," tools"]}),c.cost>0&&g.jsx("span",{className:"sl-cost",title:"total spend",children:g.jsx("b",{children:ze(c.cost)})}),g.jsx("span",{className:"sl-elapsed",title:`Started ${new Date(c.startedAt).toLocaleString()}`,children:qO(c.startedAt,c.state==="active"?void 0:c.lastActivity,n)})]})]})]},c.sessionId)})]})]})}function px(e,n){if(!e)return null;const r=n-Math.floor(e/1e3);return r<10?"just now":r<60?`${r}s ago`:r<3600?`${Math.floor(r/60)}m ago`:`${Math.floor(r/3600)}h ago`}function DO(e){return e==="claude-swap"?"Read from claude-swap's last collection — costs no request against your usage-endpoint budget":e==="api"?"Fetched from Anthropic's usage endpoint, at most once every 5 minutes":e==="cli"?"Parsed from `claude /usage`, at most once every 5 minutes":"Last update"}function Rr(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function FO({cost:e}){const n=e.total;if(n<=0)return null;const r=(s,o,l)=>{if(s<=0)return null;const u=s/n*100;return g.jsx("span",{className:`cb-seg ${o}`,style:{width:`${u}%`},title:`${l}: ${ze(s)} (${u.toFixed(0)}%)`},o)};return g.jsxs("div",{className:"cost-bar","aria-label":"Cost breakdown",children:[r(e.input,"cb-input","input"),r(e.output,"cb-output","output"),r(e.cacheRead,"cb-cache-r","cache read"),r(e.cacheWrite,"cb-cache-w","cache write")]})}function zO(e,n){const r=e-n;if(r<=0)return null;const s=Math.floor(r/3600),o=Math.floor(r%3600/60);if(s>23){const l=Math.floor(r/86400),u=Math.floor(r%86400/3600);return`${l}d ${u}h`}return s>0?`${s}h ${o}m`:`${o}m`}function BO(e,n,r,s){const o=Math.max(0,n-s),l=Math.max(0,r-o);if(l<120)return null;const u=Math.min(100,l/r*100),c=e-u;if(Math.abs(c)<3)return{label:"on pace",color:"var(--ok)",expectedPct:u,isDeficit:!1};if(c>0){const p=100-e,h=l>0?e/l:0,f=h>0?p/h:1/0,m={label:`${Math.round(c)}% ahead`,color:"var(--warn)",expectedPct:u,isDeficit:!0};if(f<o&&f<86400){const y=Math.floor(f/3600),x=Math.floor(f%3600/60);m.runsOutIn=y>0?`${y}h ${x}m`:`${x}m`}return m}return{label:`${Math.round(-c)}% reserve`,color:"var(--ok)",expectedPct:u,isDeficit:!1}}function Bi({pct:e,label:n,reset:r,resetAt:s,windowSec:o,limitReached:l,nowSec:u}){const c=Math.min(100,Math.max(0,e)),h=l||c>=90?"var(--err)":c>=70?"var(--warn)":"var(--accent)",f=c===0?"< 1%":`${c}%`,m=c===0?2:c,y=s?zO(s,u):null,x=s&&o?BO(c,s,o,u):null;return g.jsxs("div",{className:"qb-row",children:[g.jsxs("div",{className:"qb-meta",children:[g.jsxs("span",{className:"qb-label",children:[n,l&&g.jsx("span",{className:"qb-limit-badge",title:"Rate limit reached",children:"⛔"})]}),g.jsx("span",{className:"qb-pct",style:{color:h},children:f})]}),g.jsxs("div",{className:"qb-track",children:[g.jsx("div",{className:"qb-fill",style:{width:`${m}%`,background:h,opacity:c===0?.4:1}}),x&&g.jsx("div",{className:"qb-pace-marker",style:{left:`${x.expectedPct}%`,background:x.isDeficit?"var(--err)":"var(--ok)"},title:`To last until reset, stay near ${Math.round(x.expectedPct)}% by now`})]}),g.jsxs("div",{className:"qb-reset-row",children:[y?g.jsxs("span",{className:"qb-reset",children:["resets in ",y]}):r?g.jsxs("span",{className:"qb-reset",children:["resets ",r]}):null,x&&g.jsx("span",{className:"qb-pace",style:{color:x.color},children:x.runsOutIn?`runs out in ${x.runsOutIn}`:x.label})]})]})}const UO=6e4;function HO(){const[e,n]=A.useState(null),[r,s]=A.useState(!1),o=A.useRef(null),l=async(c=!1)=>{c&&s(!0);try{const h=await fetch(c?"/api/quota?refresh=1":"/api/quota");h.ok&&n(await h.json())}catch{}finally{c&&s(!1)}};return A.useEffect(()=>(l(!0),o.current=window.setInterval(()=>l(!1),UO),()=>{o.current!=null&&window.clearInterval(o.current)}),[]),{quota:e,loading:r,refresh:()=>l(!0)}}function WO(e){switch(e){case"no_token":return"Run codex login to authenticate.";case"api_key_mode":return"API-key login — ChatGPT quota is only available for codex login.";case"refresh_rejected":return"Codex session expired — run codex login.";case"refresh_failed":return"Couldn't refresh the Codex token — click ↻ to retry.";default:return"ChatGPT API unreachable — click ↻ to retry."}}const jN=6e4;function VO(){const[e,n]=A.useState(null),[r,s]=A.useState(!1),o=A.useRef(null),l=async(c=!1)=>{c&&s(!0);try{const h=await fetch(c?"/api/codex-quota?refresh=1":"/api/codex-quota");h.ok&&n(await h.json())}catch{}finally{c&&s(!1)}};return A.useEffect(()=>(l(!0),o.current=window.setInterval(()=>l(!1),jN),()=>{o.current!=null&&window.clearInterval(o.current)}),[]),{data:e,loading:r,refresh:()=>l(!0)}}function GO(){const[e,n]=A.useState(null),r=A.useRef(null),s=async()=>{try{const o=await fetch("/api/codex-usage");o.ok&&n(await o.json())}catch{}};return A.useEffect(()=>(s(),r.current=window.setInterval(s,jN),()=>{r.current!=null&&window.clearInterval(r.current)}),[]),{data:e}}function YO({state:e,now:n,onClose:r}){var O,H;const{quota:s,loading:o,refresh:l}=HO(),{data:u,loading:c,refresh:p}=VO(),{data:h}=GO(),[f,m]=A.useState(()=>Math.floor(Date.now()/1e3));A.useEffect(()=>{const L=window.setInterval(()=>m(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(L)},[]);const{byModel:y,totalCost:x,totalTokens:C,burnRate:_}=A.useMemo(()=>{const L=new Map,P={total:0,input:0,output:0,cacheRead:0,cacheWrite:0};let q=0,W=0,B=0,j=0;for(const F of e.agents.values()){const Y=F.model??"__unknown__",k=cn(F.usage,F.model),$=L.get(Y);$?($.inputTokens+=F.usage.inputTokens,$.outputTokens+=F.usage.outputTokens,$.cacheReadTokens+=F.usage.cacheReadTokens,$.cacheCreateTokens+=F.usage.cacheCreateTokens,$.cost.total+=k.total,$.cost.input+=k.input,$.cost.output+=k.output,$.cost.cacheRead+=k.cacheRead,$.cost.cacheWrite+=k.cacheWrite,$.agentCount++):L.set(Y,{model:Y,inputTokens:F.usage.inputTokens,outputTokens:F.usage.outputTokens,cacheReadTokens:F.usage.cacheReadTokens,cacheCreateTokens:F.usage.cacheCreateTokens,cost:{...k},agentCount:1}),P.total+=k.total,P.input+=k.input,P.output+=k.output,P.cacheRead+=k.cacheRead,P.cacheWrite+=k.cacheWrite,q+=F.usage.inputTokens,W+=F.usage.outputTokens,B+=F.usage.cacheReadTokens,j+=F.usage.cacheCreateTokens}const K=Array.from(L.values()).sort((F,Y)=>Y.cost.total-F.cost.total);let U=0,ee=0;for(const F of e.agents.values()){if(F.state!=="active")continue;const Y=cn(F.usage,F.model);U+=Y.total,ee=Math.max(ee,((F.endedAt??n)-F.startedAt)/1e3)}const J=ee>0?Yl(U,ee):null;return{byModel:K,totalCost:P,totalTokens:{in:q,out:W,cacheR:B,cacheC:j},burnRate:J}},[e,e.lastSeq,n]),S=A.useMemo(()=>{const L=[];for(const P of e.agents.values()){if(P.kind!=="root")continue;let q=cn(P.usage,P.model).total,W=P.usage.inputTokens,B=P.usage.outputTokens;for(const j of e.agents.values())j.sessionId!==P.sessionId||j.kind==="root"||(q+=cn(j.usage,j.model).total,W+=j.usage.inputTokens,B+=j.usage.outputTokens);L.push({sessionId:P.sessionId,label:P.label||P.cwdBasename||"session",state:P.state,cost:q,inputTokens:W,outputTokens:B})}return L.sort((P,q)=>q.cost-P.cost).slice(0,12)},[e,e.lastSeq]),b=x.total>0,E=C.in+C.out,N=o||c,T=px(s==null?void 0:s.fetchedAt,f),I=px(u==null?void 0:u.fetchedAt,f),M=()=>{l(),p()};return g.jsxs("div",{className:"usage-panel","aria-label":"Usage",children:[g.jsxs("div",{className:"up-header",children:[g.jsx("h3",{children:"Usage"}),_&&g.jsx("span",{className:"up-rate",children:_}),g.jsxs("div",{className:"up-header-right",children:[g.jsx("button",{type:"button",className:"btn up-refresh-btn",onClick:M,disabled:N,title:"Refresh Claude + Codex quota",children:N?"…":"↻"}),g.jsx("button",{type:"button",className:"btn icon-btn up-close",onClick:r,"aria-label":"Close usage panel",title:"Close (U)",children:"×"})]})]}),g.jsxs("section",{className:"up-section up-quota-section",children:[g.jsxs("h4",{className:"up-section-title",children:["Claude quota",T&&!o&&g.jsx("span",{className:"up-section-age",title:DO(s==null?void 0:s.source),children:T})]}),s!=null&&s.ok?g.jsxs("div",{className:"up-quota-bars",children:[s.session5hPct!=null&&g.jsx(Bi,{label:"5-hour window",pct:s.session5hPct,reset:s.session5hReset,resetAt:s.session5hResetAt,windowSec:s.session5hWindowSec,nowSec:f}),s.week7dPct!=null&&g.jsx(Bi,{label:"7-day window",pct:s.week7dPct,reset:s.week7dReset,resetAt:s.week7dResetAt,windowSec:s.week7dWindowSec,nowSec:f}),s.weekSonnetPct!=null&&g.jsx(Bi,{label:"Sonnet (7d)",pct:s.weekSonnetPct,nowSec:f}),s.weekOpusPct!=null&&g.jsx(Bi,{label:"Opus (7d)",pct:s.weekOpusPct,nowSec:f})]}):(s==null?void 0:s.ok)===!1?g.jsxs("div",{className:"up-quota-na",children:[g.jsx("span",{children:"Quota unavailable."}),g.jsxs("span",{className:"up-quota-hint",children:["Run ",g.jsx("code",{children:"/usage"})," in a claude session, then click ↻"]})]}):g.jsx("div",{className:"up-quota-na up-quota-loading",children:"Checking…"})]}),g.jsxs("section",{className:"up-section up-quota-section",children:[g.jsxs("h4",{className:"up-section-title",children:["Codex quota",(u==null?void 0:u.ok)&&u.planLabel&&g.jsx("span",{className:"up-plan-badge",children:u.planLabel}),I&&!c&&g.jsx("span",{className:"up-section-age",title:"Fetched from the Codex usage endpoint",children:I})]}),u!=null&&u.ok?g.jsxs("div",{className:"up-quota-bars",children:[(O=u.windows)==null?void 0:O.map(L=>g.jsx(Bi,{label:L.label,pct:L.pct,reset:L.reset??void 0,resetAt:L.resetAt??void 0,windowSec:L.windowSec??void 0,limitReached:u.limitReached&&L.pct>=100,nowSec:f},L.id)),(H=u.extraWindows)==null?void 0:H.map(L=>g.jsx(Bi,{label:L.label,pct:L.pct,reset:L.reset??void 0,resetAt:L.resetAt??void 0,windowSec:L.windowSec??void 0,nowSec:f},L.id)),u.creditLimit&&g.jsx(Bi,{label:`spend cap · $${Math.round(u.creditLimit.used)} of $${Math.round(u.creditLimit.limit)}`,pct:u.creditLimit.usedPct,reset:u.creditLimit.reset??void 0,resetAt:u.creditLimit.resetAt??void 0,limitReached:u.spendControlReached,nowSec:f}),(h==null?void 0:h.ok)&&h.window7d&&h.window7d.sessionCount>0&&g.jsxs("div",{className:"up-quota-sub",children:[Rr(h.window7d.totalTokens)," tokens · ",h.window7d.sessionCount," session",h.window7d.sessionCount!==1?"s":""," (7d)"]}),u.creditsBalance&&!u.creditsUnlimited&&g.jsxs("div",{className:"up-quota-sub up-credits",children:["credits: $",u.creditsBalance,u.overageReached&&" · overage limit reached"]}),u.creditsUnlimited&&g.jsx("div",{className:"up-quota-sub up-credits",children:"credits: unlimited"}),u.resetCredits&&u.resetCredits.availableCount>0&&g.jsxs("div",{className:"up-quota-sub up-reset-credits",title:"Redeem in the Codex CLI or ChatGPT — agents-deck only reports them",children:[u.resetCredits.availableCount," rate-limit reset",u.resetCredits.availableCount!==1?"s":""," available",u.resetCredits.nextExpiryAt&&` · expires ${new Date(u.resetCredits.nextExpiryAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`]}),u.promo&&g.jsx("div",{className:"up-quota-sub",children:u.promo}),u.partial&&g.jsx("div",{className:"up-quota-sub up-quota-hint",children:"Partial data — OpenAI returned limits this build doesn't recognise."})]}):(u==null?void 0:u.ok)===!1?g.jsxs("div",{className:"up-quota-na",children:[g.jsx("span",{children:"Quota unavailable."}),g.jsx("span",{className:"up-quota-hint",children:WO(u.reason)})]}):g.jsx("div",{className:"up-quota-na up-quota-loading",children:"Checking…"})]}),b?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"up-total",children:[g.jsx("span",{className:"up-total-value",children:ze(x.total)}),g.jsx("span",{className:"up-total-label",children:"total spend"})]}),g.jsx(FO,{cost:x}),E>0&&g.jsxs("div",{className:"up-tokens-row",children:[g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"in"}),Rr(C.in)]}),g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"out"}),Rr(C.out)]}),C.cacheR>0&&g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"cache r"}),Rr(C.cacheR)]}),C.cacheC>0&&g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"cache c"}),Rr(C.cacheC)]})]}),y.filter(L=>L.cost.total>0).length>0&&g.jsxs("section",{className:"up-section",children:[g.jsx("h4",{className:"up-section-title",children:"By model"}),g.jsxs("table",{className:"up-table",children:[g.jsx("thead",{children:g.jsxs("tr",{children:[g.jsx("th",{children:"Model"}),g.jsx("th",{children:"Tokens"}),g.jsx("th",{children:"Cost"})]})}),g.jsx("tbody",{children:y.filter(L=>L.cost.total>0).map(L=>g.jsxs("tr",{children:[g.jsx("td",{className:"up-model-name",title:L.model,children:da(L.model)}),g.jsx("td",{className:"up-num",children:Rr(L.inputTokens+L.outputTokens)}),g.jsx("td",{className:"up-num up-cost-val",children:ze(L.cost.total)})]},L.model))})]})]}),S.filter(L=>L.cost>0).length>0&&g.jsxs("section",{className:"up-section",children:[g.jsx("h4",{className:"up-section-title",children:"By session"}),g.jsx("div",{className:"up-sessions",children:S.filter(L=>L.cost>0).map(L=>g.jsxs("div",{className:"up-session-row",children:[g.jsx("span",{className:`sl-dot state-${L.state}`,"aria-hidden":!0}),g.jsx("span",{className:"up-session-label",children:L.label}),g.jsx("span",{className:"up-session-tokens",children:Rr(L.inputTokens+L.outputTokens)}),g.jsx("span",{className:"up-session-cost",children:ze(L.cost)})]},L.sessionId))})]})]}):E>0?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"up-tokens-row",children:[g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"in"}),Rr(C.in)]}),g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"out"}),Rr(C.out)]})]}),g.jsx("div",{className:"up-hint",children:"Cost appears once a known model is detected."})]}):g.jsxs("div",{className:"up-empty",children:["No usage data yet.",g.jsx("br",{}),"Start a Claude Code or Codex session."]})]})}const mx=18,KO=1100,zs=(e,n)=>{const r=Math.sin(e*12.9898+n*78.233)*43758.5453;return r-Math.floor(r)},XO=Array.from({length:mx},(e,n)=>{const r=-72+144*n/(mx-1)+(zs(n,1)-.5)*9,s=(r-90)*(Math.PI/180),o=(54+32*Math.cos(r*Math.PI/180))*(.74+zs(n,2)*.52);return{dx:Math.cos(s)*o,dy:Math.sin(s)*o,rot:(n%2?1:-1)*(100+zs(n,3)*260),delay:Math.round(zs(n,4)*90),dur:760+Math.round(zs(n,5)*260),scale:.8+zs(n,6)*.45,hue:n%4,round:n%3===0}});function gx({anchor:e,lifetimeMs:n=KO}){var l;const[r,s]=A.useState(null),o=typeof window<"u"&&((l=window.matchMedia)==null?void 0:l.call(window,"(prefers-reduced-motion: reduce)").matches);return A.useEffect(()=>{if(o)return;const u=e.current;if(!u)return;const c=u.getBoundingClientRect();s({x:c.left+c.width/2,y:c.top+c.height/2});const p=window.setTimeout(()=>s(null),n);return()=>window.clearTimeout(p)},[e,n,o]),o||!r?null:oI.createPortal(g.jsx("div",{className:"confetti",style:{left:`${r.x}px`,top:`${r.y}px`},"aria-hidden":!0,children:XO.map((u,c)=>g.jsx("span",{className:`confetti-bit${u.round?" round":""}`,"data-hue":u.hue,style:{"--dx":`${u.dx.toFixed(1)}px`,"--dy":`${u.dy.toFixed(1)}px`,"--rot":`${u.rot}deg`,"--s":u.scale.toFixed(2),animationDelay:`${u.delay}ms`,animationDuration:`${u.dur}ms, ${u.dur}ms`}},c))}),document.body)}const AN=new Set(["awaiting_url","awaiting_code","registering"]);function QO(e){return e!=null&&AN.has(e)}function ZO(e){return e!=null&&e!=="done"&&!AN.has(e)}const JO="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",e3="the sign-in did not complete";function t3({state:e,serverError:n,localError:r}){const s=e==="idle";return{title:s?"Sign-in ended":"Sign-in failed",message:r||n||(s?JO:e3)}}const n3="done";function r3(){let e=!1;return{shouldAnnounce(n){return n!==n3?(e=!1,!1):e?!1:(e=!0,!0)}}}const i3=1500;async function Rl(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const s3={already_running:"a sign-in is already in progress",no_url:"the claude CLI did not offer a sign-in link — is it installed?",not_waiting:"that sign-in is no longer waiting for a code",not_prompted:"the CLI has not asked for a code yet",code_rejected:"that code was not accepted — copy it again from the browser",no_verdict:"the claude CLI has not answered — try the code again",empty_code:"paste the code from the browser first",login_failed:"the code was not accepted",no_identity:"signed in, but the CLI still reports nobody logged in",add_failed:"signed in, but claude-swap could not record the account",not_a_share:"that does not look like a shared account — it should start with ccdeck1:",corrupt:"that share is incomplete — copy the whole thing",wrong_version:"that share was made by a newer agents-deck",expired:"that share has expired — make a new one",import_failed:"claude-swap refused the import"},fd=(e,n)=>(e==null?void 0:e.detail)||(e!=null&&e.reason?s3[e.reason]??e.reason:null)||(e==null?void 0:e.error)||n,Zg=le.forwardRef((e,n)=>g.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:n,children:[g.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),g.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));Zg.displayName="SuccessMark";function o3({onClose:e,onChanged:n}){const[r,s]=A.useState("login"),[o,l]=A.useState(null),[u,c]=A.useState(""),[p,h]=A.useState(""),[f,m]=A.useState(!1),[y,x]=A.useState(null),[C,_]=A.useState(null),S=A.useRef(!1),b=A.useRef(null),E=A.useRef(null),N=A.useRef(null),T=A.useCallback(()=>{S.current&&Rl({action:"login-cancel"}).catch(()=>{}),e()},[e]);A.useEffect(()=>{const B=j=>{j.key==="Escape"&&T()};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[T]);const I=A.useCallback(async()=>{m(!0),x(null),S.current=!0;const B=await Rl({action:"login"}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){x(fd(B,"could not start the sign-in"));return}l(B)},[]);A.useEffect(()=>{if(!QO(o==null?void 0:o.state))return;const B=window.setInterval(async()=>{try{const j=await fetch("/api/claude-accounts/login");j.ok&&l(await j.json())}catch{}},i3);return()=>window.clearInterval(B)},[o]);const M=A.useRef(n);M.current=n;const O=A.useRef(r3());A.useEffect(()=>{var B;(o==null?void 0:o.state)==="awaiting_code"&&((B=b.current)==null||B.focus()),O.current.shouldAnnounce(o==null?void 0:o.state)&&M.current()},[o==null?void 0:o.state]),A.useEffect(()=>{var B;r==="paste"&&((B=E.current)==null||B.focus())},[r]);const H=A.useCallback(async()=>{var j;m(!0),x(null);const B=await Rl({action:"login-code",code:u}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){x(fd(B,"the code was not accepted")),B!=null&&B.state&&l(B),(j=b.current)==null||j.select();return}c(""),l(B)},[u,o]),L=A.useCallback(async()=>{m(!0),x(null);const B=await Rl({action:"import",blob:p}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){x(fd(B,"the import failed"));return}h(""),_({added:B.added===!0,num:B.num??null,email:B.email??null}),n()},[p,n]),P=(o==null?void 0:o.state)==="done"?o.account:null,q=ZO(o==null?void 0:o.state)||!!(y&&S.current&&!f),W=t3({state:o==null?void 0:o.state,serverError:o==null?void 0:o.error,localError:y});return g.jsx("div",{className:"modal-backdrop",onClick:T,role:"presentation",children:g.jsxs("div",{className:"modal aa-modal",onClick:B=>B.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[g.jsxs("header",{className:"modal-head",children:[g.jsx("div",{className:"modal-title",children:g.jsxs("span",{className:"aa-tabs",role:"tablist",children:[g.jsx("button",{type:"button",role:"tab","aria-selected":r==="login",className:`aa-tab${r==="login"?" on":""}`,onClick:()=>s("login"),children:"Sign in"}),g.jsx("button",{type:"button",role:"tab","aria-selected":r==="paste",className:`aa-tab${r==="paste"?" on":""}`,onClick:()=>s("paste"),children:"Paste a share"})]})}),g.jsx("div",{className:"modal-actions",children:g.jsx("button",{type:"button",className:"btn icon-btn",onClick:T,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),g.jsx("section",{className:"modal-body aa-body",children:r==="login"?P?g.jsxs("div",{className:"aa-done",children:[g.jsx(Zg,{ref:N}),g.jsx(gx,{anchor:N}),g.jsx("h4",{children:P.added?`Account ${P.num} added`:"Credentials refreshed"}),g.jsxs("p",{className:"aa-note",children:[g.jsx("strong",{children:P.email}),P.added?" is in the rotation. The account you were using is still active.":" was already managed, so its stored credentials were replaced."]}),g.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"})]}):(o==null?void 0:o.state)==="awaiting_code"||(o==null?void 0:o.state)==="registering"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"1 · Approve in the browser"}),g.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),g.jsx("a",{className:"aa-link",href:o.url??"#",target:"_blank",rel:"noreferrer noopener",children:o.url})]}),g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"2 · Paste the code it gives you"}),g.jsxs("div",{className:"aa-field",children:[g.jsx("input",{ref:b,type:"text",value:u,onChange:B=>c(B.target.value),onKeyDown:B=>{B.key==="Enter"&&u.trim()&&!f&&H()},placeholder:"paste the code here",spellCheck:!1,autoComplete:"off","aria-label":"Sign-in code",disabled:o.state==="registering"}),g.jsx("button",{type:"button",className:"btn primary",disabled:f||!u.trim()||o.state==="registering",onClick:H,children:o.state==="registering"?"registering…":"Continue"})]}),(y||o.error)&&g.jsx("p",{className:"aa-err",children:y??o.error}),g.jsx("p",{className:"aa-note",children:"The code goes straight to the claude CLI on this machine. It is never stored or sent anywhere else."})]})]}):q?g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:W.title}),g.jsx("p",{className:"aa-err",children:W.message}),g.jsx("button",{type:"button",className:"btn",onClick:()=>{S.current=!1,l(null),x(null),I()},children:"Try again"})]}):f||S.current?g.jsx("div",{className:"aa-step",children:g.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):g.jsxs("div",{className:"aa-step aa-primer",children:[g.jsx("h4",{children:"Sign in to Anthropic"}),g.jsx("p",{className:"aa-note",children:"Opens a browser tab where you approve the sign-in, then asks for the code it shows you. claude-swap records the account when it completes, and the account you are using now stays active."}),g.jsx("div",{className:"aa-actions",children:g.jsx("button",{type:"button",className:"btn primary",onClick:I,disabled:f,children:"Open the sign-in page"})})]}):C?g.jsxs("div",{className:"aa-done",children:[g.jsx(Zg,{ref:N}),C.added&&g.jsx(gx,{anchor:N}),g.jsx("h4",{children:C.added?`Account ${C.num} imported`:"Already here"}),g.jsx("p",{className:"aa-note",children:C.added?g.jsxs(g.Fragment,{children:[C.email?g.jsx("strong",{children:C.email}):"That account"," is in the rotation now. Nothing changed on the deck you copied it from."]}):"This deck already holds that account, so nothing changed."}),g.jsxs("div",{className:"aa-actions",children:[g.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"}),g.jsx("button",{type:"button",className:"btn",onClick:()=>_(null),children:"Import another"})]})]}):g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"Paste an account shared from another deck"}),g.jsxs("div",{className:"aa-field",children:[g.jsx("input",{ref:E,type:"text",value:p,onChange:B=>h(B.target.value),onKeyDown:B=>{B.key==="Enter"&&p.trim()&&!f&&L()},placeholder:"ccdeck1:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),g.jsx("button",{type:"button",className:"btn primary",disabled:f||!p.trim(),onClick:L,children:f?"importing…":"Import"})]}),y&&g.jsx("p",{className:"aa-err",children:y}),g.jsxs("p",{className:"aa-note",children:["Use ",g.jsx("strong",{children:"share"})," on an account in the other deck. A share carries a live login and expires ten minutes after it is made."]})]})})]})})}const a3=15e3,l3=[70,80,85,90,95];function u3(e,n){const r=e-n;if(r<=0)return null;const s=Math.floor(r/86400),o=Math.floor(r%86400/3600),l=Math.floor(r%3600/60);return s>0?`${s}d ${o}h`:o>0?`${o}h ${l}m`:`${l}m`}function vx(e,n){const r=n-Math.floor(e/1e3);return r<60?"just now":r<3600?`${Math.floor(r/60)}m ago`:r<86400?`${Math.floor(r/3600)}h ago`:`${Math.floor(r/86400)}d ago`}function c3(e,n){if(!e)return"";const r=Math.floor(e/1e3)-n;return r<=0?" · due":r<60?` · next in ${r}s`:` · next in ${Math.round(r/60)}m`}function d3(e){switch(e){case"invalid_grant":case"no_refresh_token":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fixable:!0};case"http-401":return{text:"re-login needed",hint:"Anthropic refused this account's token.",fixable:!0};case"http-429":return{text:"rate limited",hint:"Anthropic is throttling requests for this account. It clears on its own.",fixable:!1};case"transient":return{text:"temporary error",hint:"A network or server hiccup while reading usage. The next collection retries.",fixable:!1};case"timeout":return{text:"timed out",hint:"Reading this account's usage took too long. The next collection retries.",fixable:!1};case"network":return{text:"unreachable",hint:"Could not reach Anthropic to read this account's usage.",fixable:!1};default:return{text:e,hint:`claude-swap reported "${e}" for this account.`,fixable:!1}}}function f3({lane:e,nowSec:n}){const r=Math.min(100,Math.max(0,e.pct)),s=r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",o=e.resetAt?u3(e.resetAt,n):null;return g.jsxs("div",{className:"ap-lane",children:[g.jsx("span",{className:"ap-lane-label",children:e.label}),g.jsx("div",{className:"ap-lane-track",children:g.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:s,opacity:r===0?.4:1}})}),g.jsxs("span",{className:"ap-lane-pct",style:{color:s},children:[r,"%"]}),g.jsx("span",{className:"ap-lane-reset",children:o?`resets ${o}`:""})]})}function h3(e){const n=e.map(s=>s.num),r=n.length?Math.max(...n):0;return[...new Set([...n,r+1])].sort((s,o)=>s-o)}async function p3(e){var r;let n=!1;try{n=await Promise.race([((r=navigator.clipboard)==null?void 0:r.writeText(e).then(()=>!0))??Promise.resolve(!1),new Promise(s=>window.setTimeout(()=>s(!1),500))])}catch{n=!1}if(n)return!0;try{const s=document.createElement("textarea");s.value=e,s.setAttribute("readonly",""),s.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(s),s.select(),n=document.execCommand("copy"),s.remove()}catch{n=!1}return n}function m3(e,n){const r=Math.round(e/1e3)-n;return r<=0?{text:"expired",tone:"gone"}:r<60?{text:`expires in ${r}s`,tone:"soon"}:{text:`expires in ${Math.round(r/60)}m`,tone:"ok"}}function g3({onClose:e}){var J,F,Y;const[n,r]=A.useState(null),[s,o]=A.useState(null),[l,u]=A.useState(null),[c,p]=A.useState(null),[h,f]=A.useState(null),[m,y]=A.useState(()=>Math.floor(Date.now()/1e3)),x=A.useRef(null),[C,_]=A.useState(null),[S,b]=A.useState(!1),[E,N]=A.useState(""),[T,I]=A.useState(null),[M,O]=A.useState(null),[H,L]=A.useState(!1),P=A.useCallback(async(k=!1)=>{try{const[$,se]=await Promise.all([fetch(`/api/claude-accounts${k?"?refresh=1":""}`),fetch("/api/cswap-auto")]);$.ok&&r(await $.json()),se.ok&&o(await se.json())}catch{}},[]),q=A.useCallback(async(k,$)=>{u($),f(null);try{const D=await(await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)})).json().catch(()=>null);return D!=null&&D.ok||f((D==null?void 0:D.detail)||(D==null?void 0:D.reason)||"command failed"),D}catch{return f("server unreachable"),null}finally{u(null)}},[]),W=A.useCallback(async(k,$)=>{u($),f(null);try{const D=await(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)})).json().catch(()=>null);return D!=null&&D.ok||f((D==null?void 0:D.detail)||(D==null?void 0:D.reason)||"command failed"),D}catch{return f("server unreachable"),null}finally{u(null)}},[]);A.useEffect(()=>(P(!0),x.current=window.setInterval(()=>P(!1),a3),()=>{x.current!=null&&window.clearInterval(x.current)}),[P]),A.useEffect(()=>{const k=window.setInterval(()=>y(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(k)},[]);const B=((J=s==null?void 0:s.settings["autoswitch.threshold"])==null?void 0:J.value)??"90",j=(F=n==null?void 0:n.accounts)==null?void 0:F.find(k=>k.active),K=j!=null&&j.lanes.length?Math.max(...j.lanes.map(k=>k.pct)):null,U=K!=null&&K>=Number(B)-15,ee=async k=>{p(k),f(null);try{const se=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:k})})).json().catch(()=>null);se!=null&&se.ok||f((se==null?void 0:se.output)||(se==null?void 0:se.reason)||"switch failed"),await P(!0)}catch{f("server unreachable")}finally{p(null)}};return g.jsxs("div",{className:"accounts-panel","aria-label":"Claude accounts",children:[g.jsxs("div",{className:"ap-header",children:[g.jsx("h3",{children:"Accounts"}),g.jsxs("div",{className:"ap-header-right",children:[g.jsx("button",{type:"button",className:"btn ap-add",onClick:()=>b(!0),title:"Sign in to another Claude account, or paste one shared from another deck",children:"+"}),g.jsx("button",{type:"button",className:"btn ap-refresh",onClick:()=>P(!0),title:"Reload from claude-swap",children:"↻"}),g.jsx("button",{type:"button",className:"btn icon-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:"×"})]})]}),n==null?g.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?g.jsxs(g.Fragment,{children:[(Y=n.accounts)==null?void 0:Y.map(k=>g.jsxs("div",{className:`ap-account${k.active?" active":""}${k.disabled?" disabled":""}`,children:[g.jsxs("div",{className:"ap-account-head",children:[g.jsx("span",{className:"ap-num",children:k.num}),k.alias&&g.jsx("span",{className:"ap-alias",children:k.alias}),g.jsx("span",{className:"ap-email",title:k.org??void 0,children:k.email}),g.jsx("button",{type:"button",className:`ap-more${C===k.num?" on":""}`,"aria-label":`Manage account ${k.num}`,"aria-expanded":C===k.num,title:"Share, rename, move, remove",onClick:()=>{_(C===k.num?null:k.num),N(k.alias??""),I(null),O(null),L(!1)},children:"⋯"}),k.active?g.jsx("span",{className:"ap-badge-active",children:"● active"}):g.jsx("button",{type:"button",className:"btn ap-switch",disabled:c!=null||k.disabled,onClick:()=>ee(k.num),title:k.disabled?"Held out of rotation":`Switch to ${k.alias??k.email}`,children:c===k.num?"…":"switch"})]}),k.lanes.length>0?k.lanes.map($=>g.jsx(f3,{lane:$,nowSec:m},$.id)):g.jsx("div",{className:"ap-hint",children:"No usage recorded yet."}),g.jsxs("div",{className:"ap-meta",children:[k.error&&(()=>{const $=d3(k.error);return g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"ap-err",title:$.hint,children:$.text}),$.fixable&&g.jsx("button",{type:"button",className:"ap-fix",onClick:()=>b(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"sign in again"})]})})(),((s==null?void 0:s.enabled)||(s==null?void 0:s.external))&&!k.active&&g.jsx("button",{type:"button",className:"ap-rotate",disabled:l!=null,onClick:()=>q({action:"account",account:k.num,enabled:k.disabled},`rot-${k.num}`).then(()=>P(!0)),title:k.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",children:k.disabled?"held out":"in rotation"}),k.fetchedAt?g.jsxs("span",{className:`ap-age${k.stale?" ap-stale":""}`,title:"When claude-swap last read this account's usage, and when it plans to read it again. It sets that interval itself — 3 minutes at the fastest, wider while an account is recovering from a rate limit — and every surface, including `cswap watch`, follows the same plan.",children:["collected ",vx(k.fetchedAt,m),c3(k.nextAt,m)]}):g.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})]}),C===k.num&&g.jsxs("div",{className:"ap-manage",children:[g.jsxs("div",{className:"ap-manage-row",children:[g.jsx("span",{className:"ap-manage-label",children:"name"}),g.jsx("input",{className:"ap-manage-input",type:"text",value:E,onChange:$=>N($.target.value),onKeyDown:$=>{$.key==="Enter"&&W({action:"alias",account:k.num,alias:E},`alias-${k.num}`).then(()=>P(!0))},placeholder:"no alias",spellCheck:!1,"aria-label":`Alias for account ${k.num}`}),g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null||E.trim()===(k.alias??""),onClick:()=>W({action:"alias",account:k.num,alias:E},`alias-${k.num}`).then(()=>P(!0)),title:"A short name to show instead of the email",children:"save"})]}),g.jsxs("div",{className:"ap-manage-row",children:[g.jsx("span",{className:"ap-manage-label",children:"slot"}),g.jsx("span",{className:"ap-field",children:g.jsx("select",{"aria-label":`Slot for account ${k.num}`,value:String(k.num),disabled:l!=null,onChange:$=>W({action:"move",account:k.num,slot:Number($.target.value)},`move-${k.num}`).then(()=>P(!0)),children:h3(n.accounts??[]).map($=>g.jsx("option",{value:$,children:$},$))})}),g.jsx("span",{className:"ap-manage-hint",children:"rotation order"})]}),g.jsxs("div",{className:"ap-manage-row",children:[g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,title:"Copy this account to another agents-deck. The share carries a live login and expires in 10 minutes.",onClick:async()=>{L(!1);const $=await W({action:"share",account:k.num},`share-${k.num}`);$!=null&&$.ok&&O({num:k.num,blob:$.blob,expiresAt:$.expiresAt})},children:"share…"}),g.jsx("button",{type:"button",className:`ap-manage-btn danger${T===k.num?" armed":""}`,disabled:l!=null,title:T===k.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{if(T!==k.num){I(k.num),window.setTimeout(()=>I($=>$===k.num?null:$),4e3);return}I(null),W({action:"remove",account:k.num},`rm-${k.num}`).then(()=>{_(null),P(!0)})},children:T===k.num?"confirm remove":"remove"})]}),(M==null?void 0:M.num)===k.num&&(()=>{const $=m3(M.expiresAt,m),se=$.tone==="gone";return g.jsxs("div",{className:`ap-share${se?" expired":""}`,children:[g.jsx("code",{className:"ap-share-blob",children:M.blob}),g.jsxs("div",{className:"ap-share-foot",children:[g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,onClick:async()=>{if(se){L(!1);const D=await W({action:"share",account:k.num},`share-${k.num}`);D!=null&&D.ok&&O({num:k.num,blob:D.blob,expiresAt:D.expiresAt});return}await p3(M.blob)&&(L(!0),window.setTimeout(()=>L(!1),1800))},children:se?"make a new share":H?"copied":"copy"}),g.jsxs("span",{className:"ap-manage-hint",children:["carries a live login · ",g.jsx("span",{className:`ap-share-expiry ${$.tone}`,children:$.text})]})]})]})})()]})]},k.num)),(s==null?void 0:s.ok)&&g.jsxs("div",{className:"ap-auto",children:[g.jsxs("div",{className:"ap-auto-head",children:[g.jsx("span",{className:"ap-auto-title",children:"Auto-switch"}),g.jsxs("span",{className:"ap-auto-ctl",children:[K!=null&&g.jsxs("span",{className:`ap-auto-now${U?" near":""}`,children:[Math.round(K),"%"]}),g.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:g.jsx("select",{"aria-label":"Switch threshold",value:B,disabled:l!=null,onChange:k=>q({action:"setting",key:"autoswitch.threshold",value:k.target.value},"threshold").then(()=>P(!0)),children:l3.map(k=>g.jsxs("option",{value:k,children:[k,"%"]},k))})}),g.jsxs("button",{type:"button",className:`ap-auto-state toggle${s.enabled?" live":""}`,role:"switch","aria-checked":s.enabled,disabled:l!=null,onClick:()=>q({action:"enable",enabled:!s.enabled},"enable").then(()=>P(!0)),title:s.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:[g.jsx("i",{className:s.enabled?"ap-pulse":"ap-dot","aria-hidden":!0}),s.enabled?"on":"off"]})]})]}),s.external&&g.jsxs("p",{className:"ap-auto-note",children:[g.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",g.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",s.enabled?" — this toggle takes over when you stop it.":"."]}),s.lastTick&&g.jsx("div",{className:"ap-auto-foot",children:g.jsxs("span",{className:"ap-auto-result",children:["checked ",vx(s.lastTick.at,m)]})})]}),h&&g.jsx("div",{className:"ap-failure",children:h}),g.jsx("p",{className:"ap-footnote",title:"Anthropic's usage endpoint allows roughly 28–30 requests per hour per account, shared by every tool on this machine — polling it from here would rate-limit your account. So the deck never fetches: it asks claude-swap to collect while this panel is open, at most once every three minutes, and claude-swap decides whether that touches the network at all.",children:"Collected by claude-swap while this panel is open."})]}):g.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"claude-swap isn't installed."}),g.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&g.jsx("code",{className:"ap-cmd",children:n.hint}),g.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",g.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"No accounts added yet."}),g.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",g.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"Couldn't read the account store."}),g.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})}),S&&g.jsx(o3,{onClose:()=>b(!1),onChanged:()=>P(!0)})]})}const v3=3e4;function y3({bundle:e,running:n,lastTried:r}){return!n||e===n?!1:r!==n}function w3(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function x3({asked:e,reported:n}){return n?n!==e:!1}function _3(e){const n=e.thresholdMs??v3;return!e.enabled||e.kind!=="restart"||!e.canRestart?{idleSince:null,restart:!1}:e.busy?{idleSince:null,restart:!1}:e.idleSince==null?{idleSince:e.now,restart:!1}:e.now<e.idleSince?{idleSince:e.now,restart:!1}:{idleSince:e.idleSince,restart:e.now-e.idleSince>=n}}function S3(e){return e.ctrlKey||e.metaKey||e.altKey}const b3=new Set(["button","checkbox","color","file","image","radio","range","reset","submit"]),k3=new Set(["INPUT","TEXTAREA","SELECT","OPTION","BUTTON","SUMMARY","A"]),E3=new Set(["button","checkbox","combobox","link","listbox","menu","menubar","menuitem","menuitemcheckbox","menuitemradio","option","radio","searchbox","slider","spinbutton","switch","tab","textbox","treeitem"]);function IN(e){return typeof e.tagName=="string"?e.tagName.toUpperCase():""}function MN(e){if(!e)return!1;if(e.isContentEditable)return!0;const n=IN(e);return n==="TEXTAREA"?!0:n!=="INPUT"?!1:!b3.has(String(e.type??"text").toLowerCase())}function N3(e){if(!e)return!1;if(MN(e)||k3.has(IN(e)))return!0;const n=typeof e.role=="string"?e.role.trim().toLowerCase():"";return n!==""&&n.split(/\s+/).some(r=>E3.has(r))}function hd(e,n){if(n.size!==0)for(const r of Array.from(e.keys()))n.has(r)||e.delete(r)}function C3(e){const n=new Set;for(const r of e)n.add(r.id),n.add(`group:${r.sessionId}`);return n}const T3=40,R3=120;function j3(e,n){let r=null,s=0,o=Number.NEGATIVE_INFINITY;const l=()=>{r=null,o=n.now(),e()},u=()=>{r!=null&&(n.clearTimeout(r),r=null)},c=(p,h,f)=>{if(r!=null){if(s<=p)return;u()}const m=Math.min(f,Math.max(0,p-h));s=p,r=n.setTimeout(l,m)};return{live(p=T3){const h=n.now(),f=Math.max(o+p,h);if(f<=h){u(),l();return}c(f,h,p)},replay(p=R3){u(),s=n.now()+p,r=n.setTimeout(l,p)},flush(){u(),l()},cancel(){u()}}}function A3(){let e=!1,n=[];return{get paused(){return e},get size(){return n.length},accept(r){return e?(n.push(r),!1):!0},setPaused(r){if(e=r,r||n.length===0)return[];const s=n;return n=[],s}}}function I3(){let e=0;return{begin(){const n=++e;return()=>n===e},cancel(){e++}}}function M3(e,n=new Date){return new Date(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()-(e-1))).toISOString().slice(0,10).replace(/-/g,"")}function Ui(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:e<1e9?`${(e/1e6).toFixed(2)}M`:`${(e/1e9).toFixed(2)}B`}function yx(e){return e.replace(/^anthropic\./,"").replace(/^claude-/,"").replace(/-\d{8}$/,"")}function jl(e){const n=e.toLowerCase();return n.includes("opus")?"#c4b5fd":n.includes("sonnet")?"#7dd3fc":n.includes("haiku")?"#86efac":n.includes("gpt-5")||n.includes("gpt5")?"#fcd34d":n.includes("gpt")?"#fca5a5":n.includes("gemini")?"#a5b4fc":n.includes("codex")?"#fdba74":"#94a3b8"}const P3=[7,14,30,90];function O3(e){const[n,r]=A.useState(null),[s,o]=A.useState(!1),l=A.useRef(I3()).current,u=(c=!1)=>{const p=l.begin();o(!0);const f=`/api/ccusage?since=${M3(e)}${c?"&refresh=1":""}`;fetch(f).then(m=>m.json()).then(m=>{p()&&r(m)}).catch(()=>{p()&&r({ok:!1,error:"request failed"})}).finally(()=>{p()&&o(!1)})};return A.useEffect(()=>(u(!1),()=>l.cancel()),[e]),{data:n,loading:s,reload:()=>u(!0)}}function L3({onClose:e}){var b,E;const[n,r]=A.useState(30),[s,o]=A.useState(null),{data:l,loading:u,reload:c}=O3(n);A.useEffect(()=>{const N=T=>{T.key==="Escape"&&e()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[e]);const p=l!=null&&l.ok?l.days??[]:[],h=A.useMemo(()=>p.reduce((N,T)=>Math.max(N,T.totalCost),0),[p]),{totalCost:f,totalTok:m,inOut:y,cacheRead:x,modelCosts:C}=A.useMemo(()=>{let N=0,T=0,I=0,M=0;const O=new Map;for(const H of p){N+=H.totalCost,T+=H.totalTokens,I+=H.inputTokens+H.outputTokens,M+=H.cacheReadTokens;for(const L of H.modelBreakdowns)O.set(L.modelName,(O.get(L.modelName)??0)+L.cost)}return{totalCost:N,totalTok:T,inOut:I,cacheRead:M,modelCosts:O}},[p]),_=A.useMemo(()=>Array.from(C.entries()).sort((N,T)=>T[1]-N[1]),[C]),S=s?p.find(N=>N.period===s)??null:null;return g.jsx("div",{className:"uh-backdrop",onClick:e,role:"presentation",children:g.jsxs("div",{className:"uh-modal",onClick:N=>N.stopPropagation(),role:"dialog","aria-label":"Usage history",children:[g.jsxs("header",{className:"uh-head",children:[g.jsxs("div",{className:"uh-titlewrap",children:[g.jsx("div",{className:"uh-title",children:"Usage history"}),g.jsx("div",{className:"uh-sub",children:"via ccusage · local Claude / Codex logs"})]}),g.jsx("div",{className:"uh-range",role:"tablist","aria-label":"Range",children:P3.map(N=>g.jsxs("button",{role:"tab","aria-selected":n===N,className:`uh-range-btn${n===N?" on":""}`,onClick:()=>{r(N),o(null)},children:[N,"d"]},N))}),g.jsx("button",{className:"btn icon-btn uh-reload",onClick:c,title:"Re-run ccusage","aria-label":"Reload",children:"↻"}),g.jsx("button",{className:"uh-close",onClick:e,"aria-label":"Close",children:"×"})]}),u&&p.length===0?g.jsx("div",{className:"uh-status",children:"running ccusage… (first run downloads the package)"}):l&&!l.ok?g.jsxs("div",{className:"uh-status uh-err",children:["ccusage failed: ",l.error]}):p.length===0?g.jsx("div",{className:"uh-status",children:"no usage in this range"}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"uh-totals",children:[g.jsx(Al,{label:"total cost",val:ze(f),accent:!0}),g.jsx(Al,{label:"tokens",val:Ui(m)}),g.jsx(Al,{label:"input+output",val:Ui(y)}),g.jsx(Al,{label:"cache reads",val:Ui(x)})]}),g.jsx("div",{className:"uh-chart",role:"img","aria-label":"Daily cost by model",children:p.map(N=>{const T=h>0?N.totalCost/h*100:0,I=N.period===s;return g.jsxs("button",{className:`uh-bar-col${I?" sel":""}`,onClick:()=>o(I?null:N.period),title:`${N.period} · ${ze(N.totalCost)}`,style:{flexBasis:`${100/p.length}%`},children:[g.jsx("div",{className:"uh-bar",style:{height:`${Math.max(T,N.totalCost>0?2:0)}%`},children:N.modelBreakdowns.slice().sort((M,O)=>O.cost-M.cost).map(M=>{const O=N.totalCost>0?M.cost/N.totalCost*100:0;return g.jsx("div",{className:"uh-bar-seg",style:{height:`${O}%`,background:jl(M.modelName)}},M.modelName)})}),g.jsx("span",{className:"uh-bar-label",children:N.period.slice(5)})]},N.period)})}),g.jsx("div",{className:"uh-legend",children:_.map(([N,T])=>g.jsxs("span",{className:"uh-legend-item",children:[g.jsx("span",{className:"uh-legend-dot",style:{background:jl(N)}}),yx(N)," ",g.jsx("span",{className:"uh-legend-cost",children:ze(T)})]},N))}),S&&g.jsxs("div",{className:"uh-detail",children:[g.jsxs("div",{className:"uh-detail-head",children:[g.jsx("span",{className:"uh-detail-date",children:S.period}),g.jsx("span",{className:"uh-detail-cost",children:ze(S.totalCost)}),(E=(b=S.metadata)==null?void 0:b.agents)!=null&&E.length?g.jsx("span",{className:"uh-detail-agents",children:S.metadata.agents.join(" · ")}):null]}),g.jsxs("div",{className:"uh-detail-mini",children:[g.jsx(Il,{label:"input",val:Ui(S.inputTokens)}),g.jsx(Il,{label:"output",val:Ui(S.outputTokens)}),g.jsx(Il,{label:"cache write",val:Ui(S.cacheCreationTokens)}),g.jsx(Il,{label:"cache read",val:Ui(S.cacheReadTokens)})]}),g.jsx("div",{className:"uh-detail-models",children:S.modelBreakdowns.slice().sort((N,T)=>T.cost-N.cost).map(N=>{const T=S.totalCost>0?N.cost/S.totalCost*100:0;return g.jsxs("div",{className:"uh-model-row",children:[g.jsxs("span",{className:"uh-model-name",children:[g.jsx("span",{className:"uh-legend-dot",style:{background:jl(N.modelName)}}),yx(N.modelName)]}),g.jsx("span",{className:"uh-model-bar",children:g.jsx("span",{className:"uh-model-bar-fill",style:{width:`${T}%`,background:jl(N.modelName)}})}),g.jsx("span",{className:"uh-model-cost",children:ze(N.cost)})]},N.modelName)})})]})]})]})})}function Al({label:e,val:n,accent:r}){return g.jsxs("div",{className:"uh-stat",children:[g.jsx("span",{className:`uh-stat-val${r?" accent":""}`,children:n}),g.jsx("span",{className:"uh-stat-label",children:e})]})}function Il({label:e,val:n}){return g.jsxs("div",{className:"uh-ministat",children:[g.jsx("span",{className:"uh-ministat-val",children:n}),g.jsx("span",{className:"uh-ministat-label",children:e})]})}function bv(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var pd,wx;function q3(){if(wx)return pd;wx=1;function e(){this.__data__=[],this.size=0}return pd=e,pd}var md,xx;function eo(){if(xx)return md;xx=1;function e(n,r){return n===r||n!==n&&r!==r}return md=e,md}var gd,_x;function iu(){if(_x)return gd;_x=1;var e=eo();function n(r,s){for(var o=r.length;o--;)if(e(r[o][0],s))return o;return-1}return gd=n,gd}var vd,Sx;function $3(){if(Sx)return vd;Sx=1;var e=iu(),n=Array.prototype,r=n.splice;function s(o){var l=this.__data__,u=e(l,o);if(u<0)return!1;var c=l.length-1;return u==c?l.pop():r.call(l,u,1),--this.size,!0}return vd=s,vd}var yd,bx;function D3(){if(bx)return yd;bx=1;var e=iu();function n(r){var s=this.__data__,o=e(s,r);return o<0?void 0:s[o][1]}return yd=n,yd}var wd,kx;function F3(){if(kx)return wd;kx=1;var e=iu();function n(r){return e(this.__data__,r)>-1}return wd=n,wd}var xd,Ex;function z3(){if(Ex)return xd;Ex=1;var e=iu();function n(r,s){var o=this.__data__,l=e(o,r);return l<0?(++this.size,o.push([r,s])):o[l][1]=s,this}return xd=n,xd}var _d,Nx;function su(){if(Nx)return _d;Nx=1;var e=q3(),n=$3(),r=D3(),s=F3(),o=z3();function l(u){var c=-1,p=u==null?0:u.length;for(this.clear();++c<p;){var h=u[c];this.set(h[0],h[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=s,l.prototype.set=o,_d=l,_d}var Sd,Cx;function B3(){if(Cx)return Sd;Cx=1;var e=su();function n(){this.__data__=new e,this.size=0}return Sd=n,Sd}var bd,Tx;function U3(){if(Tx)return bd;Tx=1;function e(n){var r=this.__data__,s=r.delete(n);return this.size=r.size,s}return bd=e,bd}var kd,Rx;function H3(){if(Rx)return kd;Rx=1;function e(n){return this.__data__.get(n)}return kd=e,kd}var Ed,jx;function W3(){if(jx)return Ed;jx=1;function e(n){return this.__data__.has(n)}return Ed=e,Ed}var Nd,Ax;function PN(){if(Ax)return Nd;Ax=1;var e=typeof gl=="object"&&gl&&gl.Object===Object&&gl;return Nd=e,Nd}var Cd,Ix;function tr(){if(Ix)return Cd;Ix=1;var e=PN(),n=typeof self=="object"&&self&&self.Object===Object&&self,r=e||n||Function("return this")();return Cd=r,Cd}var Td,Mx;function to(){if(Mx)return Td;Mx=1;var e=tr(),n=e.Symbol;return Td=n,Td}var Rd,Px;function V3(){if(Px)return Rd;Px=1;var e=to(),n=Object.prototype,r=n.hasOwnProperty,s=n.toString,o=e?e.toStringTag:void 0;function l(u){var c=r.call(u,o),p=u[o];try{u[o]=void 0;var h=!0}catch{}var f=s.call(u);return h&&(c?u[o]=p:delete u[o]),f}return Rd=l,Rd}var jd,Ox;function G3(){if(Ox)return jd;Ox=1;var e=Object.prototype,n=e.toString;function r(s){return n.call(s)}return jd=r,jd}var Ad,Lx;function Qi(){if(Lx)return Ad;Lx=1;var e=to(),n=V3(),r=G3(),s="[object Null]",o="[object Undefined]",l=e?e.toStringTag:void 0;function u(c){return c==null?c===void 0?o:s:l&&l in Object(c)?n(c):r(c)}return Ad=u,Ad}var Id,qx;function jn(){if(qx)return Id;qx=1;function e(n){var r=typeof n;return n!=null&&(r=="object"||r=="function")}return Id=e,Id}var Md,$x;function fa(){if($x)return Md;$x=1;var e=Qi(),n=jn(),r="[object AsyncFunction]",s="[object Function]",o="[object GeneratorFunction]",l="[object Proxy]";function u(c){if(!n(c))return!1;var p=e(c);return p==s||p==o||p==r||p==l}return Md=u,Md}var Pd,Dx;function Y3(){if(Dx)return Pd;Dx=1;var e=tr(),n=e["__core-js_shared__"];return Pd=n,Pd}var Od,Fx;function K3(){if(Fx)return Od;Fx=1;var e=Y3(),n=(function(){var s=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return s?"Symbol(src)_1."+s:""})();function r(s){return!!n&&n in s}return Od=r,Od}var Ld,zx;function ON(){if(zx)return Ld;zx=1;var e=Function.prototype,n=e.toString;function r(s){if(s!=null){try{return n.call(s)}catch{}try{return s+""}catch{}}return""}return Ld=r,Ld}var qd,Bx;function X3(){if(Bx)return qd;Bx=1;var e=fa(),n=K3(),r=jn(),s=ON(),o=/[\\^$.*+?()[\]{}|]/g,l=/^\[object .+?Constructor\]$/,u=Function.prototype,c=Object.prototype,p=u.toString,h=c.hasOwnProperty,f=RegExp("^"+p.call(h).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function m(y){if(!r(y)||n(y))return!1;var x=e(y)?f:l;return x.test(s(y))}return qd=m,qd}var $d,Ux;function Q3(){if(Ux)return $d;Ux=1;function e(n,r){return n==null?void 0:n[r]}return $d=e,$d}var Dd,Hx;function Zi(){if(Hx)return Dd;Hx=1;var e=X3(),n=Q3();function r(s,o){var l=n(s,o);return e(l)?l:void 0}return Dd=r,Dd}var Fd,Wx;function kv(){if(Wx)return Fd;Wx=1;var e=Zi(),n=tr(),r=e(n,"Map");return Fd=r,Fd}var zd,Vx;function ou(){if(Vx)return zd;Vx=1;var e=Zi(),n=e(Object,"create");return zd=n,zd}var Bd,Gx;function Z3(){if(Gx)return Bd;Gx=1;var e=ou();function n(){this.__data__=e?e(null):{},this.size=0}return Bd=n,Bd}var Ud,Yx;function J3(){if(Yx)return Ud;Yx=1;function e(n){var r=this.has(n)&&delete this.__data__[n];return this.size-=r?1:0,r}return Ud=e,Ud}var Hd,Kx;function eL(){if(Kx)return Hd;Kx=1;var e=ou(),n="__lodash_hash_undefined__",r=Object.prototype,s=r.hasOwnProperty;function o(l){var u=this.__data__;if(e){var c=u[l];return c===n?void 0:c}return s.call(u,l)?u[l]:void 0}return Hd=o,Hd}var Wd,Xx;function tL(){if(Xx)return Wd;Xx=1;var e=ou(),n=Object.prototype,r=n.hasOwnProperty;function s(o){var l=this.__data__;return e?l[o]!==void 0:r.call(l,o)}return Wd=s,Wd}var Vd,Qx;function nL(){if(Qx)return Vd;Qx=1;var e=ou(),n="__lodash_hash_undefined__";function r(s,o){var l=this.__data__;return this.size+=this.has(s)?0:1,l[s]=e&&o===void 0?n:o,this}return Vd=r,Vd}var Gd,Zx;function rL(){if(Zx)return Gd;Zx=1;var e=Z3(),n=J3(),r=eL(),s=tL(),o=nL();function l(u){var c=-1,p=u==null?0:u.length;for(this.clear();++c<p;){var h=u[c];this.set(h[0],h[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=s,l.prototype.set=o,Gd=l,Gd}var Yd,Jx;function iL(){if(Jx)return Yd;Jx=1;var e=rL(),n=su(),r=kv();function s(){this.size=0,this.__data__={hash:new e,map:new(r||n),string:new e}}return Yd=s,Yd}var Kd,e1;function sL(){if(e1)return Kd;e1=1;function e(n){var r=typeof n;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?n!=="__proto__":n===null}return Kd=e,Kd}var Xd,t1;function au(){if(t1)return Xd;t1=1;var e=sL();function n(r,s){var o=r.__data__;return e(s)?o[typeof s=="string"?"string":"hash"]:o.map}return Xd=n,Xd}var Qd,n1;function oL(){if(n1)return Qd;n1=1;var e=au();function n(r){var s=e(this,r).delete(r);return this.size-=s?1:0,s}return Qd=n,Qd}var Zd,r1;function aL(){if(r1)return Zd;r1=1;var e=au();function n(r){return e(this,r).get(r)}return Zd=n,Zd}var Jd,i1;function lL(){if(i1)return Jd;i1=1;var e=au();function n(r){return e(this,r).has(r)}return Jd=n,Jd}var ef,s1;function uL(){if(s1)return ef;s1=1;var e=au();function n(r,s){var o=e(this,r),l=o.size;return o.set(r,s),this.size+=o.size==l?0:1,this}return ef=n,ef}var tf,o1;function Ev(){if(o1)return tf;o1=1;var e=iL(),n=oL(),r=aL(),s=lL(),o=uL();function l(u){var c=-1,p=u==null?0:u.length;for(this.clear();++c<p;){var h=u[c];this.set(h[0],h[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=s,l.prototype.set=o,tf=l,tf}var nf,a1;function cL(){if(a1)return nf;a1=1;var e=su(),n=kv(),r=Ev(),s=200;function o(l,u){var c=this.__data__;if(c instanceof e){var p=c.__data__;if(!n||p.length<s-1)return p.push([l,u]),this.size=++c.size,this;c=this.__data__=new r(p)}return c.set(l,u),this.size=c.size,this}return nf=o,nf}var rf,l1;function lu(){if(l1)return rf;l1=1;var e=su(),n=B3(),r=U3(),s=H3(),o=W3(),l=cL();function u(c){var p=this.__data__=new e(c);this.size=p.size}return u.prototype.clear=n,u.prototype.delete=r,u.prototype.get=s,u.prototype.has=o,u.prototype.set=l,rf=u,rf}var sf,u1;function Nv(){if(u1)return sf;u1=1;function e(n,r){for(var s=-1,o=n==null?0:n.length;++s<o&&r(n[s],s,n)!==!1;);return n}return sf=e,sf}var of,c1;function LN(){if(c1)return of;c1=1;var e=Zi(),n=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return of=n,of}var af,d1;function uu(){if(d1)return af;d1=1;var e=LN();function n(r,s,o){s=="__proto__"&&e?e(r,s,{configurable:!0,enumerable:!0,value:o,writable:!0}):r[s]=o}return af=n,af}var lf,f1;function cu(){if(f1)return lf;f1=1;var e=uu(),n=eo(),r=Object.prototype,s=r.hasOwnProperty;function o(l,u,c){var p=l[u];(!(s.call(l,u)&&n(p,c))||c===void 0&&!(u in l))&&e(l,u,c)}return lf=o,lf}var uf,h1;function ha(){if(h1)return uf;h1=1;var e=cu(),n=uu();function r(s,o,l,u){var c=!l;l||(l={});for(var p=-1,h=o.length;++p<h;){var f=o[p],m=u?u(l[f],s[f],f,l,s):void 0;m===void 0&&(m=s[f]),c?n(l,f,m):e(l,f,m)}return l}return uf=r,uf}var cf,p1;function dL(){if(p1)return cf;p1=1;function e(n,r){for(var s=-1,o=Array(n);++s<n;)o[s]=r(s);return o}return cf=e,cf}var df,m1;function hr(){if(m1)return df;m1=1;function e(n){return n!=null&&typeof n=="object"}return df=e,df}var ff,g1;function fL(){if(g1)return ff;g1=1;var e=Qi(),n=hr(),r="[object Arguments]";function s(o){return n(o)&&e(o)==r}return ff=s,ff}var hf,v1;function pa(){if(v1)return hf;v1=1;var e=fL(),n=hr(),r=Object.prototype,s=r.hasOwnProperty,o=r.propertyIsEnumerable,l=e((function(){return arguments})())?e:function(u){return n(u)&&s.call(u,"callee")&&!o.call(u,"callee")};return hf=l,hf}var pf,y1;function _t(){if(y1)return pf;y1=1;var e=Array.isArray;return pf=e,pf}var Vo={exports:{}},mf,w1;function hL(){if(w1)return mf;w1=1;function e(){return!1}return mf=e,mf}Vo.exports;var x1;function no(){return x1||(x1=1,(function(e,n){var r=tr(),s=hL(),o=n&&!n.nodeType&&n,l=o&&!0&&e&&!e.nodeType&&e,u=l&&l.exports===o,c=u?r.Buffer:void 0,p=c?c.isBuffer:void 0,h=p||s;e.exports=h})(Vo,Vo.exports)),Vo.exports}var gf,_1;function du(){if(_1)return gf;_1=1;var e=9007199254740991,n=/^(?:0|[1-9]\d*)$/;function r(s,o){var l=typeof s;return o=o??e,!!o&&(l=="number"||l!="symbol"&&n.test(s))&&s>-1&&s%1==0&&s<o}return gf=r,gf}var vf,S1;function Cv(){if(S1)return vf;S1=1;var e=9007199254740991;function n(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return vf=n,vf}var yf,b1;function pL(){if(b1)return yf;b1=1;var e=Qi(),n=Cv(),r=hr(),s="[object Arguments]",o="[object Array]",l="[object Boolean]",u="[object Date]",c="[object Error]",p="[object Function]",h="[object Map]",f="[object Number]",m="[object Object]",y="[object RegExp]",x="[object Set]",C="[object String]",_="[object WeakMap]",S="[object ArrayBuffer]",b="[object DataView]",E="[object Float32Array]",N="[object Float64Array]",T="[object Int8Array]",I="[object Int16Array]",M="[object Int32Array]",O="[object Uint8Array]",H="[object Uint8ClampedArray]",L="[object Uint16Array]",P="[object Uint32Array]",q={};q[E]=q[N]=q[T]=q[I]=q[M]=q[O]=q[H]=q[L]=q[P]=!0,q[s]=q[o]=q[S]=q[l]=q[b]=q[u]=q[c]=q[p]=q[h]=q[f]=q[m]=q[y]=q[x]=q[C]=q[_]=!1;function W(B){return r(B)&&n(B.length)&&!!q[e(B)]}return yf=W,yf}var wf,k1;function fu(){if(k1)return wf;k1=1;function e(n){return function(r){return n(r)}}return wf=e,wf}var Go={exports:{}};Go.exports;var E1;function Tv(){return E1||(E1=1,(function(e,n){var r=PN(),s=n&&!n.nodeType&&n,o=s&&!0&&e&&!e.nodeType&&e,l=o&&o.exports===s,u=l&&r.process,c=(function(){try{var p=o&&o.require&&o.require("util").types;return p||u&&u.binding&&u.binding("util")}catch{}})();e.exports=c})(Go,Go.exports)),Go.exports}var xf,N1;function ma(){if(N1)return xf;N1=1;var e=pL(),n=fu(),r=Tv(),s=r&&r.isTypedArray,o=s?n(s):e;return xf=o,xf}var _f,C1;function qN(){if(C1)return _f;C1=1;var e=dL(),n=pa(),r=_t(),s=no(),o=du(),l=ma(),u=Object.prototype,c=u.hasOwnProperty;function p(h,f){var m=r(h),y=!m&&n(h),x=!m&&!y&&s(h),C=!m&&!y&&!x&&l(h),_=m||y||x||C,S=_?e(h.length,String):[],b=S.length;for(var E in h)(f||c.call(h,E))&&!(_&&(E=="length"||x&&(E=="offset"||E=="parent")||C&&(E=="buffer"||E=="byteLength"||E=="byteOffset")||o(E,b)))&&S.push(E);return S}return _f=p,_f}var Sf,T1;function hu(){if(T1)return Sf;T1=1;var e=Object.prototype;function n(r){var s=r&&r.constructor,o=typeof s=="function"&&s.prototype||e;return r===o}return Sf=n,Sf}var bf,R1;function $N(){if(R1)return bf;R1=1;function e(n,r){return function(s){return n(r(s))}}return bf=e,bf}var kf,j1;function mL(){if(j1)return kf;j1=1;var e=$N(),n=e(Object.keys,Object);return kf=n,kf}var Ef,A1;function Rv(){if(A1)return Ef;A1=1;var e=hu(),n=mL(),r=Object.prototype,s=r.hasOwnProperty;function o(l){if(!e(l))return n(l);var u=[];for(var c in Object(l))s.call(l,c)&&c!="constructor"&&u.push(c);return u}return Ef=o,Ef}var Nf,I1;function Pr(){if(I1)return Nf;I1=1;var e=fa(),n=Cv();function r(s){return s!=null&&n(s.length)&&!e(s)}return Nf=r,Nf}var Cf,M1;function hi(){if(M1)return Cf;M1=1;var e=qN(),n=Rv(),r=Pr();function s(o){return r(o)?e(o):n(o)}return Cf=s,Cf}var Tf,P1;function gL(){if(P1)return Tf;P1=1;var e=ha(),n=hi();function r(s,o){return s&&e(o,n(o),s)}return Tf=r,Tf}var Rf,O1;function vL(){if(O1)return Rf;O1=1;function e(n){var r=[];if(n!=null)for(var s in Object(n))r.push(s);return r}return Rf=e,Rf}var jf,L1;function yL(){if(L1)return jf;L1=1;var e=jn(),n=hu(),r=vL(),s=Object.prototype,o=s.hasOwnProperty;function l(u){if(!e(u))return r(u);var c=n(u),p=[];for(var h in u)h=="constructor"&&(c||!o.call(u,h))||p.push(h);return p}return jf=l,jf}var Af,q1;function Ji(){if(q1)return Af;q1=1;var e=qN(),n=yL(),r=Pr();function s(o){return r(o)?e(o,!0):n(o)}return Af=s,Af}var If,$1;function wL(){if($1)return If;$1=1;var e=ha(),n=Ji();function r(s,o){return s&&e(o,n(o),s)}return If=r,If}var Yo={exports:{}};Yo.exports;var D1;function DN(){return D1||(D1=1,(function(e,n){var r=tr(),s=n&&!n.nodeType&&n,o=s&&!0&&e&&!e.nodeType&&e,l=o&&o.exports===s,u=l?r.Buffer:void 0,c=u?u.allocUnsafe:void 0;function p(h,f){if(f)return h.slice();var m=h.length,y=c?c(m):new h.constructor(m);return h.copy(y),y}e.exports=p})(Yo,Yo.exports)),Yo.exports}var Mf,F1;function FN(){if(F1)return Mf;F1=1;function e(n,r){var s=-1,o=n.length;for(r||(r=Array(o));++s<o;)r[s]=n[s];return r}return Mf=e,Mf}var Pf,z1;function zN(){if(z1)return Pf;z1=1;function e(n,r){for(var s=-1,o=n==null?0:n.length,l=0,u=[];++s<o;){var c=n[s];r(c,s,n)&&(u[l++]=c)}return u}return Pf=e,Pf}var Of,B1;function BN(){if(B1)return Of;B1=1;function e(){return[]}return Of=e,Of}var Lf,U1;function jv(){if(U1)return Lf;U1=1;var e=zN(),n=BN(),r=Object.prototype,s=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,l=o?function(u){return u==null?[]:(u=Object(u),e(o(u),function(c){return s.call(u,c)}))}:n;return Lf=l,Lf}var qf,H1;function xL(){if(H1)return qf;H1=1;var e=ha(),n=jv();function r(s,o){return e(s,n(s),o)}return qf=r,qf}var $f,W1;function Av(){if(W1)return $f;W1=1;function e(n,r){for(var s=-1,o=r.length,l=n.length;++s<o;)n[l+s]=r[s];return n}return $f=e,$f}var Df,V1;function pu(){if(V1)return Df;V1=1;var e=$N(),n=e(Object.getPrototypeOf,Object);return Df=n,Df}var Ff,G1;function UN(){if(G1)return Ff;G1=1;var e=Av(),n=pu(),r=jv(),s=BN(),o=Object.getOwnPropertySymbols,l=o?function(u){for(var c=[];u;)e(c,r(u)),u=n(u);return c}:s;return Ff=l,Ff}var zf,Y1;function _L(){if(Y1)return zf;Y1=1;var e=ha(),n=UN();function r(s,o){return e(s,n(s),o)}return zf=r,zf}var Bf,K1;function HN(){if(K1)return Bf;K1=1;var e=Av(),n=_t();function r(s,o,l){var u=o(s);return n(s)?u:e(u,l(s))}return Bf=r,Bf}var Uf,X1;function WN(){if(X1)return Uf;X1=1;var e=HN(),n=jv(),r=hi();function s(o){return e(o,r,n)}return Uf=s,Uf}var Hf,Q1;function SL(){if(Q1)return Hf;Q1=1;var e=HN(),n=UN(),r=Ji();function s(o){return e(o,r,n)}return Hf=s,Hf}var Wf,Z1;function bL(){if(Z1)return Wf;Z1=1;var e=Zi(),n=tr(),r=e(n,"DataView");return Wf=r,Wf}var Vf,J1;function kL(){if(J1)return Vf;J1=1;var e=Zi(),n=tr(),r=e(n,"Promise");return Vf=r,Vf}var Gf,e_;function VN(){if(e_)return Gf;e_=1;var e=Zi(),n=tr(),r=e(n,"Set");return Gf=r,Gf}var Yf,t_;function EL(){if(t_)return Yf;t_=1;var e=Zi(),n=tr(),r=e(n,"WeakMap");return Yf=r,Yf}var Kf,n_;function ro(){if(n_)return Kf;n_=1;var e=bL(),n=kv(),r=kL(),s=VN(),o=EL(),l=Qi(),u=ON(),c="[object Map]",p="[object Object]",h="[object Promise]",f="[object Set]",m="[object WeakMap]",y="[object DataView]",x=u(e),C=u(n),_=u(r),S=u(s),b=u(o),E=l;return(e&&E(new e(new ArrayBuffer(1)))!=y||n&&E(new n)!=c||r&&E(r.resolve())!=h||s&&E(new s)!=f||o&&E(new o)!=m)&&(E=function(N){var T=l(N),I=T==p?N.constructor:void 0,M=I?u(I):"";if(M)switch(M){case x:return y;case C:return c;case _:return h;case S:return f;case b:return m}return T}),Kf=E,Kf}var Xf,r_;function NL(){if(r_)return Xf;r_=1;var e=Object.prototype,n=e.hasOwnProperty;function r(s){var o=s.length,l=new s.constructor(o);return o&&typeof s[0]=="string"&&n.call(s,"index")&&(l.index=s.index,l.input=s.input),l}return Xf=r,Xf}var Qf,i_;function GN(){if(i_)return Qf;i_=1;var e=tr(),n=e.Uint8Array;return Qf=n,Qf}var Zf,s_;function Iv(){if(s_)return Zf;s_=1;var e=GN();function n(r){var s=new r.constructor(r.byteLength);return new e(s).set(new e(r)),s}return Zf=n,Zf}var Jf,o_;function CL(){if(o_)return Jf;o_=1;var e=Iv();function n(r,s){var o=s?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.byteLength)}return Jf=n,Jf}var eh,a_;function TL(){if(a_)return eh;a_=1;var e=/\w*$/;function n(r){var s=new r.constructor(r.source,e.exec(r));return s.lastIndex=r.lastIndex,s}return eh=n,eh}var th,l_;function RL(){if(l_)return th;l_=1;var e=to(),n=e?e.prototype:void 0,r=n?n.valueOf:void 0;function s(o){return r?Object(r.call(o)):{}}return th=s,th}var nh,u_;function YN(){if(u_)return nh;u_=1;var e=Iv();function n(r,s){var o=s?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.length)}return nh=n,nh}var rh,c_;function jL(){if(c_)return rh;c_=1;var e=Iv(),n=CL(),r=TL(),s=RL(),o=YN(),l="[object Boolean]",u="[object Date]",c="[object Map]",p="[object Number]",h="[object RegExp]",f="[object Set]",m="[object String]",y="[object Symbol]",x="[object ArrayBuffer]",C="[object DataView]",_="[object Float32Array]",S="[object Float64Array]",b="[object Int8Array]",E="[object Int16Array]",N="[object Int32Array]",T="[object Uint8Array]",I="[object Uint8ClampedArray]",M="[object Uint16Array]",O="[object Uint32Array]";function H(L,P,q){var W=L.constructor;switch(P){case x:return e(L);case l:case u:return new W(+L);case C:return n(L,q);case _:case S:case b:case E:case N:case T:case I:case M:case O:return o(L,q);case c:return new W;case p:case m:return new W(L);case h:return r(L);case f:return new W;case y:return s(L)}}return rh=H,rh}var ih,d_;function KN(){if(d_)return ih;d_=1;var e=jn(),n=Object.create,r=(function(){function s(){}return function(o){if(!e(o))return{};if(n)return n(o);s.prototype=o;var l=new s;return s.prototype=void 0,l}})();return ih=r,ih}var sh,f_;function XN(){if(f_)return sh;f_=1;var e=KN(),n=pu(),r=hu();function s(o){return typeof o.constructor=="function"&&!r(o)?e(n(o)):{}}return sh=s,sh}var oh,h_;function AL(){if(h_)return oh;h_=1;var e=ro(),n=hr(),r="[object Map]";function s(o){return n(o)&&e(o)==r}return oh=s,oh}var ah,p_;function IL(){if(p_)return ah;p_=1;var e=AL(),n=fu(),r=Tv(),s=r&&r.isMap,o=s?n(s):e;return ah=o,ah}var lh,m_;function ML(){if(m_)return lh;m_=1;var e=ro(),n=hr(),r="[object Set]";function s(o){return n(o)&&e(o)==r}return lh=s,lh}var uh,g_;function PL(){if(g_)return uh;g_=1;var e=ML(),n=fu(),r=Tv(),s=r&&r.isSet,o=s?n(s):e;return uh=o,uh}var ch,v_;function QN(){if(v_)return ch;v_=1;var e=lu(),n=Nv(),r=cu(),s=gL(),o=wL(),l=DN(),u=FN(),c=xL(),p=_L(),h=WN(),f=SL(),m=ro(),y=NL(),x=jL(),C=XN(),_=_t(),S=no(),b=IL(),E=jn(),N=PL(),T=hi(),I=Ji(),M=1,O=2,H=4,L="[object Arguments]",P="[object Array]",q="[object Boolean]",W="[object Date]",B="[object Error]",j="[object Function]",K="[object GeneratorFunction]",U="[object Map]",ee="[object Number]",J="[object Object]",F="[object RegExp]",Y="[object Set]",k="[object String]",$="[object Symbol]",se="[object WeakMap]",D="[object ArrayBuffer]",Q="[object DataView]",te="[object Float32Array]",ae="[object Float64Array]",ce="[object Int8Array]",me="[object Int16Array]",ge="[object Int32Array]",Pe="[object Uint8Array]",Se="[object Uint8ClampedArray]",Oe="[object Uint16Array]",Me="[object Uint32Array]",be={};be[L]=be[P]=be[D]=be[Q]=be[q]=be[W]=be[te]=be[ae]=be[ce]=be[me]=be[ge]=be[U]=be[ee]=be[J]=be[F]=be[Y]=be[k]=be[$]=be[Pe]=be[Se]=be[Oe]=be[Me]=!0,be[B]=be[j]=be[se]=!1;function De(ve,we,Ue,ut,ct,Ze){var Fe,Je=we&M,dt=we&O,Nt=we&H;if(Ue&&(Fe=ct?Ue(ve,ut,ct,Ze):Ue(ve)),Fe!==void 0)return Fe;if(!E(ve))return ve;var ot=_(ve);if(ot){if(Fe=y(ve),!Je)return u(ve,Fe)}else{var gt=m(ve),Ct=gt==j||gt==K;if(S(ve))return l(ve,Je);if(gt==J||gt==L||Ct&&!ct){if(Fe=dt||Ct?{}:C(ve),!Je)return dt?p(ve,o(Fe,ve)):c(ve,s(Fe,ve))}else{if(!be[gt])return ct?ve:{};Fe=x(ve,gt,Je)}}Ze||(Ze=new e);var Ft=Ze.get(ve);if(Ft)return Ft;Ze.set(ve,Fe),N(ve)?ve.forEach(function(ft){Fe.add(De(ft,we,Ue,ft,ve,Ze))}):b(ve)&&ve.forEach(function(ft,wt){Fe.set(wt,De(ft,we,Ue,wt,ve,Ze))});var Xe=Nt?dt?f:h:dt?I:T,vt=ot?void 0:Xe(ve);return n(vt||ve,function(ft,wt){vt&&(wt=ft,ft=ve[wt]),r(Fe,wt,De(ft,we,Ue,wt,ve,Ze))}),Fe}return ch=De,ch}var dh,y_;function OL(){if(y_)return dh;y_=1;var e=QN(),n=4;function r(s){return e(s,n)}return dh=r,dh}var fh,w_;function Mv(){if(w_)return fh;w_=1;function e(n){return function(){return n}}return fh=e,fh}var hh,x_;function LL(){if(x_)return hh;x_=1;function e(n){return function(r,s,o){for(var l=-1,u=Object(r),c=o(r),p=c.length;p--;){var h=c[n?p:++l];if(s(u[h],h,u)===!1)break}return r}}return hh=e,hh}var ph,__;function Pv(){if(__)return ph;__=1;var e=LL(),n=e();return ph=n,ph}var mh,S_;function Ov(){if(S_)return mh;S_=1;var e=Pv(),n=hi();function r(s,o){return s&&e(s,o,n)}return mh=r,mh}var gh,b_;function qL(){if(b_)return gh;b_=1;var e=Pr();function n(r,s){return function(o,l){if(o==null)return o;if(!e(o))return r(o,l);for(var u=o.length,c=s?u:-1,p=Object(o);(s?c--:++c<u)&&l(p[c],c,p)!==!1;);return o}}return gh=n,gh}var vh,k_;function mu(){if(k_)return vh;k_=1;var e=Ov(),n=qL(),r=n(e);return vh=r,vh}var yh,E_;function es(){if(E_)return yh;E_=1;function e(n){return n}return yh=e,yh}var wh,N_;function ZN(){if(N_)return wh;N_=1;var e=es();function n(r){return typeof r=="function"?r:e}return wh=n,wh}var xh,C_;function JN(){if(C_)return xh;C_=1;var e=Nv(),n=mu(),r=ZN(),s=_t();function o(l,u){var c=s(l)?e:n;return c(l,r(u))}return xh=o,xh}var _h,T_;function eC(){return T_||(T_=1,_h=JN()),_h}var Sh,R_;function $L(){if(R_)return Sh;R_=1;var e=mu();function n(r,s){var o=[];return e(r,function(l,u,c){s(l,u,c)&&o.push(l)}),o}return Sh=n,Sh}var bh,j_;function DL(){if(j_)return bh;j_=1;var e="__lodash_hash_undefined__";function n(r){return this.__data__.set(r,e),this}return bh=n,bh}var kh,A_;function FL(){if(A_)return kh;A_=1;function e(n){return this.__data__.has(n)}return kh=e,kh}var Eh,I_;function tC(){if(I_)return Eh;I_=1;var e=Ev(),n=DL(),r=FL();function s(o){var l=-1,u=o==null?0:o.length;for(this.__data__=new e;++l<u;)this.add(o[l])}return s.prototype.add=s.prototype.push=n,s.prototype.has=r,Eh=s,Eh}var Nh,M_;function zL(){if(M_)return Nh;M_=1;function e(n,r){for(var s=-1,o=n==null?0:n.length;++s<o;)if(r(n[s],s,n))return!0;return!1}return Nh=e,Nh}var Ch,P_;function nC(){if(P_)return Ch;P_=1;function e(n,r){return n.has(r)}return Ch=e,Ch}var Th,O_;function rC(){if(O_)return Th;O_=1;var e=tC(),n=zL(),r=nC(),s=1,o=2;function l(u,c,p,h,f,m){var y=p&s,x=u.length,C=c.length;if(x!=C&&!(y&&C>x))return!1;var _=m.get(u),S=m.get(c);if(_&&S)return _==c&&S==u;var b=-1,E=!0,N=p&o?new e:void 0;for(m.set(u,c),m.set(c,u);++b<x;){var T=u[b],I=c[b];if(h)var M=y?h(I,T,b,c,u,m):h(T,I,b,u,c,m);if(M!==void 0){if(M)continue;E=!1;break}if(N){if(!n(c,function(O,H){if(!r(N,H)&&(T===O||f(T,O,p,h,m)))return N.push(H)})){E=!1;break}}else if(!(T===I||f(T,I,p,h,m))){E=!1;break}}return m.delete(u),m.delete(c),E}return Th=l,Th}var Rh,L_;function BL(){if(L_)return Rh;L_=1;function e(n){var r=-1,s=Array(n.size);return n.forEach(function(o,l){s[++r]=[l,o]}),s}return Rh=e,Rh}var jh,q_;function Lv(){if(q_)return jh;q_=1;function e(n){var r=-1,s=Array(n.size);return n.forEach(function(o){s[++r]=o}),s}return jh=e,jh}var Ah,$_;function UL(){if($_)return Ah;$_=1;var e=to(),n=GN(),r=eo(),s=rC(),o=BL(),l=Lv(),u=1,c=2,p="[object Boolean]",h="[object Date]",f="[object Error]",m="[object Map]",y="[object Number]",x="[object RegExp]",C="[object Set]",_="[object String]",S="[object Symbol]",b="[object ArrayBuffer]",E="[object DataView]",N=e?e.prototype:void 0,T=N?N.valueOf:void 0;function I(M,O,H,L,P,q,W){switch(H){case E:if(M.byteLength!=O.byteLength||M.byteOffset!=O.byteOffset)return!1;M=M.buffer,O=O.buffer;case b:return!(M.byteLength!=O.byteLength||!q(new n(M),new n(O)));case p:case h:case y:return r(+M,+O);case f:return M.name==O.name&&M.message==O.message;case x:case _:return M==O+"";case m:var B=o;case C:var j=L&u;if(B||(B=l),M.size!=O.size&&!j)return!1;var K=W.get(M);if(K)return K==O;L|=c,W.set(M,O);var U=s(B(M),B(O),L,P,q,W);return W.delete(M),U;case S:if(T)return T.call(M)==T.call(O)}return!1}return Ah=I,Ah}var Ih,D_;function HL(){if(D_)return Ih;D_=1;var e=WN(),n=1,r=Object.prototype,s=r.hasOwnProperty;function o(l,u,c,p,h,f){var m=c&n,y=e(l),x=y.length,C=e(u),_=C.length;if(x!=_&&!m)return!1;for(var S=x;S--;){var b=y[S];if(!(m?b in u:s.call(u,b)))return!1}var E=f.get(l),N=f.get(u);if(E&&N)return E==u&&N==l;var T=!0;f.set(l,u),f.set(u,l);for(var I=m;++S<x;){b=y[S];var M=l[b],O=u[b];if(p)var H=m?p(O,M,b,u,l,f):p(M,O,b,l,u,f);if(!(H===void 0?M===O||h(M,O,c,p,f):H)){T=!1;break}I||(I=b=="constructor")}if(T&&!I){var L=l.constructor,P=u.constructor;L!=P&&"constructor"in l&&"constructor"in u&&!(typeof L=="function"&&L instanceof L&&typeof P=="function"&&P instanceof P)&&(T=!1)}return f.delete(l),f.delete(u),T}return Ih=o,Ih}var Mh,F_;function WL(){if(F_)return Mh;F_=1;var e=lu(),n=rC(),r=UL(),s=HL(),o=ro(),l=_t(),u=no(),c=ma(),p=1,h="[object Arguments]",f="[object Array]",m="[object Object]",y=Object.prototype,x=y.hasOwnProperty;function C(_,S,b,E,N,T){var I=l(_),M=l(S),O=I?f:o(_),H=M?f:o(S);O=O==h?m:O,H=H==h?m:H;var L=O==m,P=H==m,q=O==H;if(q&&u(_)){if(!u(S))return!1;I=!0,L=!1}if(q&&!L)return T||(T=new e),I||c(_)?n(_,S,b,E,N,T):r(_,S,O,b,E,N,T);if(!(b&p)){var W=L&&x.call(_,"__wrapped__"),B=P&&x.call(S,"__wrapped__");if(W||B){var j=W?_.value():_,K=B?S.value():S;return T||(T=new e),N(j,K,b,E,T)}}return q?(T||(T=new e),s(_,S,b,E,N,T)):!1}return Mh=C,Mh}var Ph,z_;function iC(){if(z_)return Ph;z_=1;var e=WL(),n=hr();function r(s,o,l,u,c){return s===o?!0:s==null||o==null||!n(s)&&!n(o)?s!==s&&o!==o:e(s,o,l,u,r,c)}return Ph=r,Ph}var Oh,B_;function VL(){if(B_)return Oh;B_=1;var e=lu(),n=iC(),r=1,s=2;function o(l,u,c,p){var h=c.length,f=h,m=!p;if(l==null)return!f;for(l=Object(l);h--;){var y=c[h];if(m&&y[2]?y[1]!==l[y[0]]:!(y[0]in l))return!1}for(;++h<f;){y=c[h];var x=y[0],C=l[x],_=y[1];if(m&&y[2]){if(C===void 0&&!(x in l))return!1}else{var S=new e;if(p)var b=p(C,_,x,l,u,S);if(!(b===void 0?n(_,C,r|s,p,S):b))return!1}}return!0}return Oh=o,Oh}var Lh,U_;function sC(){if(U_)return Lh;U_=1;var e=jn();function n(r){return r===r&&!e(r)}return Lh=n,Lh}var qh,H_;function GL(){if(H_)return qh;H_=1;var e=sC(),n=hi();function r(s){for(var o=n(s),l=o.length;l--;){var u=o[l],c=s[u];o[l]=[u,c,e(c)]}return o}return qh=r,qh}var $h,W_;function oC(){if(W_)return $h;W_=1;function e(n,r){return function(s){return s==null?!1:s[n]===r&&(r!==void 0||n in Object(s))}}return $h=e,$h}var Dh,V_;function YL(){if(V_)return Dh;V_=1;var e=VL(),n=GL(),r=oC();function s(o){var l=n(o);return l.length==1&&l[0][2]?r(l[0][0],l[0][1]):function(u){return u===o||e(u,o,l)}}return Dh=s,Dh}var Fh,G_;function io(){if(G_)return Fh;G_=1;var e=Qi(),n=hr(),r="[object Symbol]";function s(o){return typeof o=="symbol"||n(o)&&e(o)==r}return Fh=s,Fh}var zh,Y_;function qv(){if(Y_)return zh;Y_=1;var e=_t(),n=io(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,s=/^\w*$/;function o(l,u){if(e(l))return!1;var c=typeof l;return c=="number"||c=="symbol"||c=="boolean"||l==null||n(l)?!0:s.test(l)||!r.test(l)||u!=null&&l in Object(u)}return zh=o,zh}var Bh,K_;function KL(){if(K_)return Bh;K_=1;var e=Ev(),n="Expected a function";function r(s,o){if(typeof s!="function"||o!=null&&typeof o!="function")throw new TypeError(n);var l=function(){var u=arguments,c=o?o.apply(this,u):u[0],p=l.cache;if(p.has(c))return p.get(c);var h=s.apply(this,u);return l.cache=p.set(c,h)||p,h};return l.cache=new(r.Cache||e),l}return r.Cache=e,Bh=r,Bh}var Uh,X_;function XL(){if(X_)return Uh;X_=1;var e=KL(),n=500;function r(s){var o=e(s,function(u){return l.size===n&&l.clear(),u}),l=o.cache;return o}return Uh=r,Uh}var Hh,Q_;function QL(){if(Q_)return Hh;Q_=1;var e=XL(),n=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,s=e(function(o){var l=[];return o.charCodeAt(0)===46&&l.push(""),o.replace(n,function(u,c,p,h){l.push(p?h.replace(r,"$1"):c||u)}),l});return Hh=s,Hh}var Wh,Z_;function gu(){if(Z_)return Wh;Z_=1;function e(n,r){for(var s=-1,o=n==null?0:n.length,l=Array(o);++s<o;)l[s]=r(n[s],s,n);return l}return Wh=e,Wh}var Vh,J_;function ZL(){if(J_)return Vh;J_=1;var e=to(),n=gu(),r=_t(),s=io(),o=e?e.prototype:void 0,l=o?o.toString:void 0;function u(c){if(typeof c=="string")return c;if(r(c))return n(c,u)+"";if(s(c))return l?l.call(c):"";var p=c+"";return p=="0"&&1/c==-1/0?"-0":p}return Vh=u,Vh}var Gh,eS;function aC(){if(eS)return Gh;eS=1;var e=ZL();function n(r){return r==null?"":e(r)}return Gh=n,Gh}var Yh,tS;function vu(){if(tS)return Yh;tS=1;var e=_t(),n=qv(),r=QL(),s=aC();function o(l,u){return e(l)?l:n(l,u)?[l]:r(s(l))}return Yh=o,Yh}var Kh,nS;function ga(){if(nS)return Kh;nS=1;var e=io();function n(r){if(typeof r=="string"||e(r))return r;var s=r+"";return s=="0"&&1/r==-1/0?"-0":s}return Kh=n,Kh}var Xh,rS;function yu(){if(rS)return Xh;rS=1;var e=vu(),n=ga();function r(s,o){o=e(o,s);for(var l=0,u=o.length;s!=null&&l<u;)s=s[n(o[l++])];return l&&l==u?s:void 0}return Xh=r,Xh}var Qh,iS;function JL(){if(iS)return Qh;iS=1;var e=yu();function n(r,s,o){var l=r==null?void 0:e(r,s);return l===void 0?o:l}return Qh=n,Qh}var Zh,sS;function eq(){if(sS)return Zh;sS=1;function e(n,r){return n!=null&&r in Object(n)}return Zh=e,Zh}var Jh,oS;function lC(){if(oS)return Jh;oS=1;var e=vu(),n=pa(),r=_t(),s=du(),o=Cv(),l=ga();function u(c,p,h){p=e(p,c);for(var f=-1,m=p.length,y=!1;++f<m;){var x=l(p[f]);if(!(y=c!=null&&h(c,x)))break;c=c[x]}return y||++f!=m?y:(m=c==null?0:c.length,!!m&&o(m)&&s(x,m)&&(r(c)||n(c)))}return Jh=u,Jh}var ep,aS;function uC(){if(aS)return ep;aS=1;var e=eq(),n=lC();function r(s,o){return s!=null&&n(s,o,e)}return ep=r,ep}var tp,lS;function tq(){if(lS)return tp;lS=1;var e=iC(),n=JL(),r=uC(),s=qv(),o=sC(),l=oC(),u=ga(),c=1,p=2;function h(f,m){return s(f)&&o(m)?l(u(f),m):function(y){var x=n(y,f);return x===void 0&&x===m?r(y,f):e(m,x,c|p)}}return tp=h,tp}var np,uS;function cC(){if(uS)return np;uS=1;function e(n){return function(r){return r==null?void 0:r[n]}}return np=e,np}var rp,cS;function nq(){if(cS)return rp;cS=1;var e=yu();function n(r){return function(s){return e(s,r)}}return rp=n,rp}var ip,dS;function rq(){if(dS)return ip;dS=1;var e=cC(),n=nq(),r=qv(),s=ga();function o(l){return r(l)?e(s(l)):n(l)}return ip=o,ip}var sp,fS;function Or(){if(fS)return sp;fS=1;var e=YL(),n=tq(),r=es(),s=_t(),o=rq();function l(u){return typeof u=="function"?u:u==null?r:typeof u=="object"?s(u)?n(u[0],u[1]):e(u):o(u)}return sp=l,sp}var op,hS;function dC(){if(hS)return op;hS=1;var e=zN(),n=$L(),r=Or(),s=_t();function o(l,u){var c=s(l)?e:n;return c(l,r(u,3))}return op=o,op}var ap,pS;function iq(){if(pS)return ap;pS=1;var e=Object.prototype,n=e.hasOwnProperty;function r(s,o){return s!=null&&n.call(s,o)}return ap=r,ap}var lp,mS;function fC(){if(mS)return lp;mS=1;var e=iq(),n=lC();function r(s,o){return s!=null&&n(s,o,e)}return lp=r,lp}var up,gS;function sq(){if(gS)return up;gS=1;var e=Rv(),n=ro(),r=pa(),s=_t(),o=Pr(),l=no(),u=hu(),c=ma(),p="[object Map]",h="[object Set]",f=Object.prototype,m=f.hasOwnProperty;function y(x){if(x==null)return!0;if(o(x)&&(s(x)||typeof x=="string"||typeof x.splice=="function"||l(x)||c(x)||r(x)))return!x.length;var C=n(x);if(C==p||C==h)return!x.size;if(u(x))return!e(x).length;for(var _ in x)if(m.call(x,_))return!1;return!0}return up=y,up}var cp,vS;function hC(){if(vS)return cp;vS=1;function e(n){return n===void 0}return cp=e,cp}var dp,yS;function pC(){if(yS)return dp;yS=1;var e=mu(),n=Pr();function r(s,o){var l=-1,u=n(s)?Array(s.length):[];return e(s,function(c,p,h){u[++l]=o(c,p,h)}),u}return dp=r,dp}var fp,wS;function mC(){if(wS)return fp;wS=1;var e=gu(),n=Or(),r=pC(),s=_t();function o(l,u){var c=s(l)?e:r;return c(l,n(u,3))}return fp=o,fp}var hp,xS;function oq(){if(xS)return hp;xS=1;function e(n,r,s,o){var l=-1,u=n==null?0:n.length;for(o&&u&&(s=n[++l]);++l<u;)s=r(s,n[l],l,n);return s}return hp=e,hp}var pp,_S;function aq(){if(_S)return pp;_S=1;function e(n,r,s,o,l){return l(n,function(u,c,p){s=o?(o=!1,u):r(s,u,c,p)}),s}return pp=e,pp}var mp,SS;function gC(){if(SS)return mp;SS=1;var e=oq(),n=mu(),r=Or(),s=aq(),o=_t();function l(u,c,p){var h=o(u)?e:s,f=arguments.length<3;return h(u,r(c,4),p,f,n)}return mp=l,mp}var gp,bS;function lq(){if(bS)return gp;bS=1;var e=Qi(),n=_t(),r=hr(),s="[object String]";function o(l){return typeof l=="string"||!n(l)&&r(l)&&e(l)==s}return gp=o,gp}var vp,kS;function uq(){if(kS)return vp;kS=1;var e=cC(),n=e("length");return vp=n,vp}var yp,ES;function cq(){if(ES)return yp;ES=1;var e="\\ud800-\\udfff",n="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",s="\\u20d0-\\u20ff",o=n+r+s,l="\\ufe0e\\ufe0f",u="\\u200d",c=RegExp("["+u+e+o+l+"]");function p(h){return c.test(h)}return yp=p,yp}var wp,NS;function dq(){if(NS)return wp;NS=1;var e="\\ud800-\\udfff",n="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",s="\\u20d0-\\u20ff",o=n+r+s,l="\\ufe0e\\ufe0f",u="["+e+"]",c="["+o+"]",p="\\ud83c[\\udffb-\\udfff]",h="(?:"+c+"|"+p+")",f="[^"+e+"]",m="(?:\\ud83c[\\udde6-\\uddff]){2}",y="[\\ud800-\\udbff][\\udc00-\\udfff]",x="\\u200d",C=h+"?",_="["+l+"]?",S="(?:"+x+"(?:"+[f,m,y].join("|")+")"+_+C+")*",b=_+C+S,E="(?:"+[f+c+"?",c,m,y,u].join("|")+")",N=RegExp(p+"(?="+p+")|"+E+b,"g");function T(I){for(var M=N.lastIndex=0;N.test(I);)++M;return M}return wp=T,wp}var xp,CS;function fq(){if(CS)return xp;CS=1;var e=uq(),n=cq(),r=dq();function s(o){return n(o)?r(o):e(o)}return xp=s,xp}var _p,TS;function hq(){if(TS)return _p;TS=1;var e=Rv(),n=ro(),r=Pr(),s=lq(),o=fq(),l="[object Map]",u="[object Set]";function c(p){if(p==null)return 0;if(r(p))return s(p)?o(p):p.length;var h=n(p);return h==l||h==u?p.size:e(p).length}return _p=c,_p}var Sp,RS;function pq(){if(RS)return Sp;RS=1;var e=Nv(),n=KN(),r=Ov(),s=Or(),o=pu(),l=_t(),u=no(),c=fa(),p=jn(),h=ma();function f(m,y,x){var C=l(m),_=C||u(m)||h(m);if(y=s(y,4),x==null){var S=m&&m.constructor;_?x=C?new S:[]:p(m)?x=c(S)?n(o(m)):{}:x={}}return(_?e:r)(m,function(b,E,N){return y(x,b,E,N)}),x}return Sp=f,Sp}var bp,jS;function mq(){if(jS)return bp;jS=1;var e=to(),n=pa(),r=_t(),s=e?e.isConcatSpreadable:void 0;function o(l){return r(l)||n(l)||!!(s&&l&&l[s])}return bp=o,bp}var kp,AS;function $v(){if(AS)return kp;AS=1;var e=Av(),n=mq();function r(s,o,l,u,c){var p=-1,h=s.length;for(l||(l=n),c||(c=[]);++p<h;){var f=s[p];o>0&&l(f)?o>1?r(f,o-1,l,u,c):e(c,f):u||(c[c.length]=f)}return c}return kp=r,kp}var Ep,IS;function gq(){if(IS)return Ep;IS=1;function e(n,r,s){switch(s.length){case 0:return n.call(r);case 1:return n.call(r,s[0]);case 2:return n.call(r,s[0],s[1]);case 3:return n.call(r,s[0],s[1],s[2])}return n.apply(r,s)}return Ep=e,Ep}var Np,MS;function vC(){if(MS)return Np;MS=1;var e=gq(),n=Math.max;function r(s,o,l){return o=n(o===void 0?s.length-1:o,0),function(){for(var u=arguments,c=-1,p=n(u.length-o,0),h=Array(p);++c<p;)h[c]=u[o+c];c=-1;for(var f=Array(o+1);++c<o;)f[c]=u[c];return f[o]=l(h),e(s,this,f)}}return Np=r,Np}var Cp,PS;function vq(){if(PS)return Cp;PS=1;var e=Mv(),n=LN(),r=es(),s=n?function(o,l){return n(o,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:r;return Cp=s,Cp}var Tp,OS;function yq(){if(OS)return Tp;OS=1;var e=800,n=16,r=Date.now;function s(o){var l=0,u=0;return function(){var c=r(),p=n-(c-u);if(u=c,p>0){if(++l>=e)return arguments[0]}else l=0;return o.apply(void 0,arguments)}}return Tp=s,Tp}var Rp,LS;function yC(){if(LS)return Rp;LS=1;var e=vq(),n=yq(),r=n(e);return Rp=r,Rp}var jp,qS;function wu(){if(qS)return jp;qS=1;var e=es(),n=vC(),r=yC();function s(o,l){return r(n(o,l,e),o+"")}return jp=s,jp}var Ap,$S;function wC(){if($S)return Ap;$S=1;function e(n,r,s,o){for(var l=n.length,u=s+(o?1:-1);o?u--:++u<l;)if(r(n[u],u,n))return u;return-1}return Ap=e,Ap}var Ip,DS;function wq(){if(DS)return Ip;DS=1;function e(n){return n!==n}return Ip=e,Ip}var Mp,FS;function xq(){if(FS)return Mp;FS=1;function e(n,r,s){for(var o=s-1,l=n.length;++o<l;)if(n[o]===r)return o;return-1}return Mp=e,Mp}var Pp,zS;function _q(){if(zS)return Pp;zS=1;var e=wC(),n=wq(),r=xq();function s(o,l,u){return l===l?r(o,l,u):e(o,n,u)}return Pp=s,Pp}var Op,BS;function Sq(){if(BS)return Op;BS=1;var e=_q();function n(r,s){var o=r==null?0:r.length;return!!o&&e(r,s,0)>-1}return Op=n,Op}var Lp,US;function bq(){if(US)return Lp;US=1;function e(n,r,s){for(var o=-1,l=n==null?0:n.length;++o<l;)if(s(r,n[o]))return!0;return!1}return Lp=e,Lp}var qp,HS;function kq(){if(HS)return qp;HS=1;function e(){}return qp=e,qp}var $p,WS;function Eq(){if(WS)return $p;WS=1;var e=VN(),n=kq(),r=Lv(),s=1/0,o=e&&1/r(new e([,-0]))[1]==s?function(l){return new e(l)}:n;return $p=o,$p}var Dp,VS;function Nq(){if(VS)return Dp;VS=1;var e=tC(),n=Sq(),r=bq(),s=nC(),o=Eq(),l=Lv(),u=200;function c(p,h,f){var m=-1,y=n,x=p.length,C=!0,_=[],S=_;if(f)C=!1,y=r;else if(x>=u){var b=h?null:o(p);if(b)return l(b);C=!1,y=s,S=new e}else S=h?[]:_;e:for(;++m<x;){var E=p[m],N=h?h(E):E;if(E=f||E!==0?E:0,C&&N===N){for(var T=S.length;T--;)if(S[T]===N)continue e;h&&S.push(N),_.push(E)}else y(S,N,f)||(S!==_&&S.push(N),_.push(E))}return _}return Dp=c,Dp}var Fp,GS;function xC(){if(GS)return Fp;GS=1;var e=Pr(),n=hr();function r(s){return n(s)&&e(s)}return Fp=r,Fp}var zp,YS;function Cq(){if(YS)return zp;YS=1;var e=$v(),n=wu(),r=Nq(),s=xC(),o=n(function(l){return r(e(l,1,s,!0))});return zp=o,zp}var Bp,KS;function Tq(){if(KS)return Bp;KS=1;var e=gu();function n(r,s){return e(s,function(o){return r[o]})}return Bp=n,Bp}var Up,XS;function _C(){if(XS)return Up;XS=1;var e=Tq(),n=hi();function r(s){return s==null?[]:e(s,n(s))}return Up=r,Up}var Hp,QS;function An(){if(QS)return Hp;QS=1;var e;if(typeof bv=="function")try{e={clone:OL(),constant:Mv(),each:eC(),filter:dC(),has:fC(),isArray:_t(),isEmpty:sq(),isFunction:fa(),isUndefined:hC(),keys:hi(),map:mC(),reduce:gC(),size:hq(),transform:pq(),union:Cq(),values:_C()}}catch{}return e||(e=window._),Hp=e,Hp}var Wp,ZS;function Dv(){if(ZS)return Wp;ZS=1;var e=An();Wp=o;var n="\0",r="\0",s="";function o(f){this._isDirected=e.has(f,"directed")?f.directed:!0,this._isMultigraph=e.has(f,"multigraph")?f.multigraph:!1,this._isCompound=e.has(f,"compound")?f.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[r]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}o.prototype._nodeCount=0,o.prototype._edgeCount=0,o.prototype.isDirected=function(){return this._isDirected},o.prototype.isMultigraph=function(){return this._isMultigraph},o.prototype.isCompound=function(){return this._isCompound},o.prototype.setGraph=function(f){return this._label=f,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(f){return e.isFunction(f)||(f=e.constant(f)),this._defaultNodeLabelFn=f,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var f=this;return e.filter(this.nodes(),function(m){return e.isEmpty(f._in[m])})},o.prototype.sinks=function(){var f=this;return e.filter(this.nodes(),function(m){return e.isEmpty(f._out[m])})},o.prototype.setNodes=function(f,m){var y=arguments,x=this;return e.each(f,function(C){y.length>1?x.setNode(C,m):x.setNode(C)}),this},o.prototype.setNode=function(f,m){return e.has(this._nodes,f)?(arguments.length>1&&(this._nodes[f]=m),this):(this._nodes[f]=arguments.length>1?m:this._defaultNodeLabelFn(f),this._isCompound&&(this._parent[f]=r,this._children[f]={},this._children[r][f]=!0),this._in[f]={},this._preds[f]={},this._out[f]={},this._sucs[f]={},++this._nodeCount,this)},o.prototype.node=function(f){return this._nodes[f]},o.prototype.hasNode=function(f){return e.has(this._nodes,f)},o.prototype.removeNode=function(f){var m=this;if(e.has(this._nodes,f)){var y=function(x){m.removeEdge(m._edgeObjs[x])};delete this._nodes[f],this._isCompound&&(this._removeFromParentsChildList(f),delete this._parent[f],e.each(this.children(f),function(x){m.setParent(x)}),delete this._children[f]),e.each(e.keys(this._in[f]),y),delete this._in[f],delete this._preds[f],e.each(e.keys(this._out[f]),y),delete this._out[f],delete this._sucs[f],--this._nodeCount}return this},o.prototype.setParent=function(f,m){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(m))m=r;else{m+="";for(var y=m;!e.isUndefined(y);y=this.parent(y))if(y===f)throw new Error("Setting "+m+" as parent of "+f+" would create a cycle");this.setNode(m)}return this.setNode(f),this._removeFromParentsChildList(f),this._parent[f]=m,this._children[m][f]=!0,this},o.prototype._removeFromParentsChildList=function(f){delete this._children[this._parent[f]][f]},o.prototype.parent=function(f){if(this._isCompound){var m=this._parent[f];if(m!==r)return m}},o.prototype.children=function(f){if(e.isUndefined(f)&&(f=r),this._isCompound){var m=this._children[f];if(m)return e.keys(m)}else{if(f===r)return this.nodes();if(this.hasNode(f))return[]}},o.prototype.predecessors=function(f){var m=this._preds[f];if(m)return e.keys(m)},o.prototype.successors=function(f){var m=this._sucs[f];if(m)return e.keys(m)},o.prototype.neighbors=function(f){var m=this.predecessors(f);if(m)return e.union(m,this.successors(f))},o.prototype.isLeaf=function(f){var m;return this.isDirected()?m=this.successors(f):m=this.neighbors(f),m.length===0},o.prototype.filterNodes=function(f){var m=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});m.setGraph(this.graph());var y=this;e.each(this._nodes,function(_,S){f(S)&&m.setNode(S,_)}),e.each(this._edgeObjs,function(_){m.hasNode(_.v)&&m.hasNode(_.w)&&m.setEdge(_,y.edge(_))});var x={};function C(_){var S=y.parent(_);return S===void 0||m.hasNode(S)?(x[_]=S,S):S in x?x[S]:C(S)}return this._isCompound&&e.each(m.nodes(),function(_){m.setParent(_,C(_))}),m},o.prototype.setDefaultEdgeLabel=function(f){return e.isFunction(f)||(f=e.constant(f)),this._defaultEdgeLabelFn=f,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(f,m){var y=this,x=arguments;return e.reduce(f,function(C,_){return x.length>1?y.setEdge(C,_,m):y.setEdge(C,_),_}),this},o.prototype.setEdge=function(){var f,m,y,x,C=!1,_=arguments[0];typeof _=="object"&&_!==null&&"v"in _?(f=_.v,m=_.w,y=_.name,arguments.length===2&&(x=arguments[1],C=!0)):(f=_,m=arguments[1],y=arguments[3],arguments.length>2&&(x=arguments[2],C=!0)),f=""+f,m=""+m,e.isUndefined(y)||(y=""+y);var S=c(this._isDirected,f,m,y);if(e.has(this._edgeLabels,S))return C&&(this._edgeLabels[S]=x),this;if(!e.isUndefined(y)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(f),this.setNode(m),this._edgeLabels[S]=C?x:this._defaultEdgeLabelFn(f,m,y);var b=p(this._isDirected,f,m,y);return f=b.v,m=b.w,Object.freeze(b),this._edgeObjs[S]=b,l(this._preds[m],f),l(this._sucs[f],m),this._in[m][S]=b,this._out[f][S]=b,this._edgeCount++,this},o.prototype.edge=function(f,m,y){var x=arguments.length===1?h(this._isDirected,arguments[0]):c(this._isDirected,f,m,y);return this._edgeLabels[x]},o.prototype.hasEdge=function(f,m,y){var x=arguments.length===1?h(this._isDirected,arguments[0]):c(this._isDirected,f,m,y);return e.has(this._edgeLabels,x)},o.prototype.removeEdge=function(f,m,y){var x=arguments.length===1?h(this._isDirected,arguments[0]):c(this._isDirected,f,m,y),C=this._edgeObjs[x];return C&&(f=C.v,m=C.w,delete this._edgeLabels[x],delete this._edgeObjs[x],u(this._preds[m],f),u(this._sucs[f],m),delete this._in[m][x],delete this._out[f][x],this._edgeCount--),this},o.prototype.inEdges=function(f,m){var y=this._in[f];if(y){var x=e.values(y);return m?e.filter(x,function(C){return C.v===m}):x}},o.prototype.outEdges=function(f,m){var y=this._out[f];if(y){var x=e.values(y);return m?e.filter(x,function(C){return C.w===m}):x}},o.prototype.nodeEdges=function(f,m){var y=this.inEdges(f,m);if(y)return y.concat(this.outEdges(f,m))};function l(f,m){f[m]?f[m]++:f[m]=1}function u(f,m){--f[m]||delete f[m]}function c(f,m,y,x){var C=""+m,_=""+y;if(!f&&C>_){var S=C;C=_,_=S}return C+s+_+s+(e.isUndefined(x)?n:x)}function p(f,m,y,x){var C=""+m,_=""+y;if(!f&&C>_){var S=C;C=_,_=S}var b={v:C,w:_};return x&&(b.name=x),b}function h(f,m){return c(f,m.v,m.w,m.name)}return Wp}var Vp,JS;function Rq(){return JS||(JS=1,Vp="2.1.8"),Vp}var Gp,eb;function jq(){return eb||(eb=1,Gp={Graph:Dv(),version:Rq()}),Gp}var Yp,tb;function Aq(){if(tb)return Yp;tb=1;var e=An(),n=Dv();Yp={write:r,read:l};function r(u){var c={options:{directed:u.isDirected(),multigraph:u.isMultigraph(),compound:u.isCompound()},nodes:s(u),edges:o(u)};return e.isUndefined(u.graph())||(c.value=e.clone(u.graph())),c}function s(u){return e.map(u.nodes(),function(c){var p=u.node(c),h=u.parent(c),f={v:c};return e.isUndefined(p)||(f.value=p),e.isUndefined(h)||(f.parent=h),f})}function o(u){return e.map(u.edges(),function(c){var p=u.edge(c),h={v:c.v,w:c.w};return e.isUndefined(c.name)||(h.name=c.name),e.isUndefined(p)||(h.value=p),h})}function l(u){var c=new n(u.options).setGraph(u.value);return e.each(u.nodes,function(p){c.setNode(p.v,p.value),p.parent&&c.setParent(p.v,p.parent)}),e.each(u.edges,function(p){c.setEdge({v:p.v,w:p.w,name:p.name},p.value)}),c}return Yp}var Kp,nb;function Iq(){if(nb)return Kp;nb=1;var e=An();Kp=n;function n(r){var s={},o=[],l;function u(c){e.has(s,c)||(s[c]=!0,l.push(c),e.each(r.successors(c),u),e.each(r.predecessors(c),u))}return e.each(r.nodes(),function(c){l=[],u(c),l.length&&o.push(l)}),o}return Kp}var Xp,rb;function SC(){if(rb)return Xp;rb=1;var e=An();Xp=n;function n(){this._arr=[],this._keyIndices={}}return n.prototype.size=function(){return this._arr.length},n.prototype.keys=function(){return this._arr.map(function(r){return r.key})},n.prototype.has=function(r){return e.has(this._keyIndices,r)},n.prototype.priority=function(r){var s=this._keyIndices[r];if(s!==void 0)return this._arr[s].priority},n.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},n.prototype.add=function(r,s){var o=this._keyIndices;if(r=String(r),!e.has(o,r)){var l=this._arr,u=l.length;return o[r]=u,l.push({key:r,priority:s}),this._decrease(u),!0}return!1},n.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var r=this._arr.pop();return delete this._keyIndices[r.key],this._heapify(0),r.key},n.prototype.decrease=function(r,s){var o=this._keyIndices[r];if(s>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+r+" Old: "+this._arr[o].priority+" New: "+s);this._arr[o].priority=s,this._decrease(o)},n.prototype._heapify=function(r){var s=this._arr,o=2*r,l=o+1,u=r;o<s.length&&(u=s[o].priority<s[u].priority?o:u,l<s.length&&(u=s[l].priority<s[u].priority?l:u),u!==r&&(this._swap(r,u),this._heapify(u)))},n.prototype._decrease=function(r){for(var s=this._arr,o=s[r].priority,l;r!==0&&(l=r>>1,!(s[l].priority<o));)this._swap(r,l),r=l},n.prototype._swap=function(r,s){var o=this._arr,l=this._keyIndices,u=o[r],c=o[s];o[r]=c,o[s]=u,l[c.key]=r,l[u.key]=s},Xp}var Qp,ib;function bC(){if(ib)return Qp;ib=1;var e=An(),n=SC();Qp=s;var r=e.constant(1);function s(l,u,c,p){return o(l,String(u),c||r,p||function(h){return l.outEdges(h)})}function o(l,u,c,p){var h={},f=new n,m,y,x=function(C){var _=C.v!==m?C.v:C.w,S=h[_],b=c(C),E=y.distance+b;if(b<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+C+" Weight: "+b);E<S.distance&&(S.distance=E,S.predecessor=m,f.decrease(_,E))};for(l.nodes().forEach(function(C){var _=C===u?0:Number.POSITIVE_INFINITY;h[C]={distance:_},f.add(C,_)});f.size()>0&&(m=f.removeMin(),y=h[m],y.distance!==Number.POSITIVE_INFINITY);)p(m).forEach(x);return h}return Qp}var Zp,sb;function Mq(){if(sb)return Zp;sb=1;var e=bC(),n=An();Zp=r;function r(s,o,l){return n.transform(s.nodes(),function(u,c){u[c]=e(s,c,o,l)},{})}return Zp}var Jp,ob;function kC(){if(ob)return Jp;ob=1;var e=An();Jp=n;function n(r){var s=0,o=[],l={},u=[];function c(p){var h=l[p]={onStack:!0,lowlink:s,index:s++};if(o.push(p),r.successors(p).forEach(function(y){e.has(l,y)?l[y].onStack&&(h.lowlink=Math.min(h.lowlink,l[y].index)):(c(y),h.lowlink=Math.min(h.lowlink,l[y].lowlink))}),h.lowlink===h.index){var f=[],m;do m=o.pop(),l[m].onStack=!1,f.push(m);while(p!==m);u.push(f)}}return r.nodes().forEach(function(p){e.has(l,p)||c(p)}),u}return Jp}var em,ab;function Pq(){if(ab)return em;ab=1;var e=An(),n=kC();em=r;function r(s){return e.filter(n(s),function(o){return o.length>1||o.length===1&&s.hasEdge(o[0],o[0])})}return em}var tm,lb;function Oq(){if(lb)return tm;lb=1;var e=An();tm=r;var n=e.constant(1);function r(o,l,u){return s(o,l||n,u||function(c){return o.outEdges(c)})}function s(o,l,u){var c={},p=o.nodes();return p.forEach(function(h){c[h]={},c[h][h]={distance:0},p.forEach(function(f){h!==f&&(c[h][f]={distance:Number.POSITIVE_INFINITY})}),u(h).forEach(function(f){var m=f.v===h?f.w:f.v,y=l(f);c[h][m]={distance:y,predecessor:h}})}),p.forEach(function(h){var f=c[h];p.forEach(function(m){var y=c[m];p.forEach(function(x){var C=y[h],_=f[x],S=y[x],b=C.distance+_.distance;b<S.distance&&(S.distance=b,S.predecessor=_.predecessor)})})}),c}return tm}var nm,ub;function EC(){if(ub)return nm;ub=1;var e=An();nm=n,n.CycleException=r;function n(s){var o={},l={},u=[];function c(p){if(e.has(l,p))throw new r;e.has(o,p)||(l[p]=!0,o[p]=!0,e.each(s.predecessors(p),c),delete l[p],u.push(p))}if(e.each(s.sinks(),c),e.size(o)!==s.nodeCount())throw new r;return u}function r(){}return r.prototype=new Error,nm}var rm,cb;function Lq(){if(cb)return rm;cb=1;var e=EC();rm=n;function n(r){try{e(r)}catch(s){if(s instanceof e.CycleException)return!1;throw s}return!0}return rm}var im,db;function NC(){if(db)return im;db=1;var e=An();im=n;function n(s,o,l){e.isArray(o)||(o=[o]);var u=(s.isDirected()?s.successors:s.neighbors).bind(s),c=[],p={};return e.each(o,function(h){if(!s.hasNode(h))throw new Error("Graph does not have node: "+h);r(s,h,l==="post",p,u,c)}),c}function r(s,o,l,u,c,p){e.has(u,o)||(u[o]=!0,l||p.push(o),e.each(c(o),function(h){r(s,h,l,u,c,p)}),l&&p.push(o))}return im}var sm,fb;function qq(){if(fb)return sm;fb=1;var e=NC();sm=n;function n(r,s){return e(r,s,"post")}return sm}var om,hb;function $q(){if(hb)return om;hb=1;var e=NC();om=n;function n(r,s){return e(r,s,"pre")}return om}var am,pb;function Dq(){if(pb)return am;pb=1;var e=An(),n=Dv(),r=SC();am=s;function s(o,l){var u=new n,c={},p=new r,h;function f(y){var x=y.v===h?y.w:y.v,C=p.priority(x);if(C!==void 0){var _=l(y);_<C&&(c[x]=h,p.decrease(x,_))}}if(o.nodeCount()===0)return u;e.each(o.nodes(),function(y){p.add(y,Number.POSITIVE_INFINITY),u.setNode(y)}),p.decrease(o.nodes()[0],0);for(var m=!1;p.size()>0;){if(h=p.removeMin(),e.has(c,h))u.setEdge(h,c[h]);else{if(m)throw new Error("Input graph is not connected: "+o);m=!0}o.nodeEdges(h).forEach(f)}return u}return am}var lm,mb;function Fq(){return mb||(mb=1,lm={components:Iq(),dijkstra:bC(),dijkstraAll:Mq(),findCycles:Pq(),floydWarshall:Oq(),isAcyclic:Lq(),postorder:qq(),preorder:$q(),prim:Dq(),tarjan:kC(),topsort:EC()}),lm}var um,gb;function zq(){if(gb)return um;gb=1;var e=jq();return um={Graph:e.Graph,json:Aq(),alg:Fq(),version:e.version},um}var cm,vb;function Jn(){if(vb)return cm;vb=1;var e;if(typeof bv=="function")try{e=zq()}catch{}return e||(e=window.graphlib),cm=e,cm}var dm,yb;function Bq(){if(yb)return dm;yb=1;var e=QN(),n=1,r=4;function s(o){return e(o,n|r)}return dm=s,dm}var fm,wb;function xu(){if(wb)return fm;wb=1;var e=eo(),n=Pr(),r=du(),s=jn();function o(l,u,c){if(!s(c))return!1;var p=typeof u;return(p=="number"?n(c)&&r(u,c.length):p=="string"&&u in c)?e(c[u],l):!1}return fm=o,fm}var hm,xb;function Uq(){if(xb)return hm;xb=1;var e=wu(),n=eo(),r=xu(),s=Ji(),o=Object.prototype,l=o.hasOwnProperty,u=e(function(c,p){c=Object(c);var h=-1,f=p.length,m=f>2?p[2]:void 0;for(m&&r(p[0],p[1],m)&&(f=1);++h<f;)for(var y=p[h],x=s(y),C=-1,_=x.length;++C<_;){var S=x[C],b=c[S];(b===void 0||n(b,o[S])&&!l.call(c,S))&&(c[S]=y[S])}return c});return hm=u,hm}var pm,_b;function Hq(){if(_b)return pm;_b=1;var e=Or(),n=Pr(),r=hi();function s(o){return function(l,u,c){var p=Object(l);if(!n(l)){var h=e(u,3);l=r(l),u=function(m){return h(p[m],m,p)}}var f=o(l,u,c);return f>-1?p[h?l[f]:f]:void 0}}return pm=s,pm}var mm,Sb;function Wq(){if(Sb)return mm;Sb=1;var e=/\s/;function n(r){for(var s=r.length;s--&&e.test(r.charAt(s)););return s}return mm=n,mm}var gm,bb;function Vq(){if(bb)return gm;bb=1;var e=Wq(),n=/^\s+/;function r(s){return s&&s.slice(0,e(s)+1).replace(n,"")}return gm=r,gm}var vm,kb;function Gq(){if(kb)return vm;kb=1;var e=Vq(),n=jn(),r=io(),s=NaN,o=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,u=/^0o[0-7]+$/i,c=parseInt;function p(h){if(typeof h=="number")return h;if(r(h))return s;if(n(h)){var f=typeof h.valueOf=="function"?h.valueOf():h;h=n(f)?f+"":f}if(typeof h!="string")return h===0?h:+h;h=e(h);var m=l.test(h);return m||u.test(h)?c(h.slice(2),m?2:8):o.test(h)?s:+h}return vm=p,vm}var ym,Eb;function CC(){if(Eb)return ym;Eb=1;var e=Gq(),n=1/0,r=17976931348623157e292;function s(o){if(!o)return o===0?o:0;if(o=e(o),o===n||o===-n){var l=o<0?-1:1;return l*r}return o===o?o:0}return ym=s,ym}var wm,Nb;function Yq(){if(Nb)return wm;Nb=1;var e=CC();function n(r){var s=e(r),o=s%1;return s===s?o?s-o:s:0}return wm=n,wm}var xm,Cb;function Kq(){if(Cb)return xm;Cb=1;var e=wC(),n=Or(),r=Yq(),s=Math.max;function o(l,u,c){var p=l==null?0:l.length;if(!p)return-1;var h=c==null?0:r(c);return h<0&&(h=s(p+h,0)),e(l,n(u,3),h)}return xm=o,xm}var _m,Tb;function Xq(){if(Tb)return _m;Tb=1;var e=Hq(),n=Kq(),r=e(n);return _m=r,_m}var Sm,Rb;function TC(){if(Rb)return Sm;Rb=1;var e=$v();function n(r){var s=r==null?0:r.length;return s?e(r,1):[]}return Sm=n,Sm}var bm,jb;function Qq(){if(jb)return bm;jb=1;var e=Pv(),n=ZN(),r=Ji();function s(o,l){return o==null?o:e(o,n(l),r)}return bm=s,bm}var km,Ab;function Zq(){if(Ab)return km;Ab=1;function e(n){var r=n==null?0:n.length;return r?n[r-1]:void 0}return km=e,km}var Em,Ib;function Jq(){if(Ib)return Em;Ib=1;var e=uu(),n=Ov(),r=Or();function s(o,l){var u={};return l=r(l,3),n(o,function(c,p,h){e(u,p,l(c,p,h))}),u}return Em=s,Em}var Nm,Mb;function Fv(){if(Mb)return Nm;Mb=1;var e=io();function n(r,s,o){for(var l=-1,u=r.length;++l<u;){var c=r[l],p=s(c);if(p!=null&&(h===void 0?p===p&&!e(p):o(p,h)))var h=p,f=c}return f}return Nm=n,Nm}var Cm,Pb;function e$(){if(Pb)return Cm;Pb=1;function e(n,r){return n>r}return Cm=e,Cm}var Tm,Ob;function t$(){if(Ob)return Tm;Ob=1;var e=Fv(),n=e$(),r=es();function s(o){return o&&o.length?e(o,r,n):void 0}return Tm=s,Tm}var Rm,Lb;function RC(){if(Lb)return Rm;Lb=1;var e=uu(),n=eo();function r(s,o,l){(l!==void 0&&!n(s[o],l)||l===void 0&&!(o in s))&&e(s,o,l)}return Rm=r,Rm}var jm,qb;function n$(){if(qb)return jm;qb=1;var e=Qi(),n=pu(),r=hr(),s="[object Object]",o=Function.prototype,l=Object.prototype,u=o.toString,c=l.hasOwnProperty,p=u.call(Object);function h(f){if(!r(f)||e(f)!=s)return!1;var m=n(f);if(m===null)return!0;var y=c.call(m,"constructor")&&m.constructor;return typeof y=="function"&&y instanceof y&&u.call(y)==p}return jm=h,jm}var Am,$b;function jC(){if($b)return Am;$b=1;function e(n,r){if(!(r==="constructor"&&typeof n[r]=="function")&&r!="__proto__")return n[r]}return Am=e,Am}var Im,Db;function r$(){if(Db)return Im;Db=1;var e=ha(),n=Ji();function r(s){return e(s,n(s))}return Im=r,Im}var Mm,Fb;function i$(){if(Fb)return Mm;Fb=1;var e=RC(),n=DN(),r=YN(),s=FN(),o=XN(),l=pa(),u=_t(),c=xC(),p=no(),h=fa(),f=jn(),m=n$(),y=ma(),x=jC(),C=r$();function _(S,b,E,N,T,I,M){var O=x(S,E),H=x(b,E),L=M.get(H);if(L){e(S,E,L);return}var P=I?I(O,H,E+"",S,b,M):void 0,q=P===void 0;if(q){var W=u(H),B=!W&&p(H),j=!W&&!B&&y(H);P=H,W||B||j?u(O)?P=O:c(O)?P=s(O):B?(q=!1,P=n(H,!0)):j?(q=!1,P=r(H,!0)):P=[]:m(H)||l(H)?(P=O,l(O)?P=C(O):(!f(O)||h(O))&&(P=o(H))):q=!1}q&&(M.set(H,P),T(P,H,N,I,M),M.delete(H)),e(S,E,P)}return Mm=_,Mm}var Pm,zb;function s$(){if(zb)return Pm;zb=1;var e=lu(),n=RC(),r=Pv(),s=i$(),o=jn(),l=Ji(),u=jC();function c(p,h,f,m,y){p!==h&&r(h,function(x,C){if(y||(y=new e),o(x))s(p,h,C,f,c,m,y);else{var _=m?m(u(p,C),x,C+"",p,h,y):void 0;_===void 0&&(_=x),n(p,C,_)}},l)}return Pm=c,Pm}var Om,Bb;function o$(){if(Bb)return Om;Bb=1;var e=wu(),n=xu();function r(s){return e(function(o,l){var u=-1,c=l.length,p=c>1?l[c-1]:void 0,h=c>2?l[2]:void 0;for(p=s.length>3&&typeof p=="function"?(c--,p):void 0,h&&n(l[0],l[1],h)&&(p=c<3?void 0:p,c=1),o=Object(o);++u<c;){var f=l[u];f&&s(o,f,u,p)}return o})}return Om=r,Om}var Lm,Ub;function a$(){if(Ub)return Lm;Ub=1;var e=s$(),n=o$(),r=n(function(s,o,l){e(s,o,l)});return Lm=r,Lm}var qm,Hb;function AC(){if(Hb)return qm;Hb=1;function e(n,r){return n<r}return qm=e,qm}var $m,Wb;function l$(){if(Wb)return $m;Wb=1;var e=Fv(),n=AC(),r=es();function s(o){return o&&o.length?e(o,r,n):void 0}return $m=s,$m}var Dm,Vb;function u$(){if(Vb)return Dm;Vb=1;var e=Fv(),n=Or(),r=AC();function s(o,l){return o&&o.length?e(o,n(l,2),r):void 0}return Dm=s,Dm}var Fm,Gb;function c$(){if(Gb)return Fm;Gb=1;var e=tr(),n=function(){return e.Date.now()};return Fm=n,Fm}var zm,Yb;function d$(){if(Yb)return zm;Yb=1;var e=cu(),n=vu(),r=du(),s=jn(),o=ga();function l(u,c,p,h){if(!s(u))return u;c=n(c,u);for(var f=-1,m=c.length,y=m-1,x=u;x!=null&&++f<m;){var C=o(c[f]),_=p;if(C==="__proto__"||C==="constructor"||C==="prototype")return u;if(f!=y){var S=x[C];_=h?h(S,C,x):void 0,_===void 0&&(_=s(S)?S:r(c[f+1])?[]:{})}e(x,C,_),x=x[C]}return u}return zm=l,zm}var Bm,Kb;function f$(){if(Kb)return Bm;Kb=1;var e=yu(),n=d$(),r=vu();function s(o,l,u){for(var c=-1,p=l.length,h={};++c<p;){var f=l[c],m=e(o,f);u(m,f)&&n(h,r(f,o),m)}return h}return Bm=s,Bm}var Um,Xb;function h$(){if(Xb)return Um;Xb=1;var e=f$(),n=uC();function r(s,o){return e(s,o,function(l,u){return n(s,u)})}return Um=r,Um}var Hm,Qb;function p$(){if(Qb)return Hm;Qb=1;var e=TC(),n=vC(),r=yC();function s(o){return r(n(o,void 0,e),o+"")}return Hm=s,Hm}var Wm,Zb;function m$(){if(Zb)return Wm;Zb=1;var e=h$(),n=p$(),r=n(function(s,o){return s==null?{}:e(s,o)});return Wm=r,Wm}var Vm,Jb;function g$(){if(Jb)return Vm;Jb=1;var e=Math.ceil,n=Math.max;function r(s,o,l,u){for(var c=-1,p=n(e((o-s)/(l||1)),0),h=Array(p);p--;)h[u?p:++c]=s,s+=l;return h}return Vm=r,Vm}var Gm,ek;function v$(){if(ek)return Gm;ek=1;var e=g$(),n=xu(),r=CC();function s(o){return function(l,u,c){return c&&typeof c!="number"&&n(l,u,c)&&(u=c=void 0),l=r(l),u===void 0?(u=l,l=0):u=r(u),c=c===void 0?l<u?1:-1:r(c),e(l,u,c,o)}}return Gm=s,Gm}var Ym,tk;function y$(){if(tk)return Ym;tk=1;var e=v$(),n=e();return Ym=n,Ym}var Km,nk;function w$(){if(nk)return Km;nk=1;function e(n,r){var s=n.length;for(n.sort(r);s--;)n[s]=n[s].value;return n}return Km=e,Km}var Xm,rk;function x$(){if(rk)return Xm;rk=1;var e=io();function n(r,s){if(r!==s){var o=r!==void 0,l=r===null,u=r===r,c=e(r),p=s!==void 0,h=s===null,f=s===s,m=e(s);if(!h&&!m&&!c&&r>s||c&&p&&f&&!h&&!m||l&&p&&f||!o&&f||!u)return 1;if(!l&&!c&&!m&&r<s||m&&o&&u&&!l&&!c||h&&o&&u||!p&&u||!f)return-1}return 0}return Xm=n,Xm}var Qm,ik;function _$(){if(ik)return Qm;ik=1;var e=x$();function n(r,s,o){for(var l=-1,u=r.criteria,c=s.criteria,p=u.length,h=o.length;++l<p;){var f=e(u[l],c[l]);if(f){if(l>=h)return f;var m=o[l];return f*(m=="desc"?-1:1)}}return r.index-s.index}return Qm=n,Qm}var Zm,sk;function S$(){if(sk)return Zm;sk=1;var e=gu(),n=yu(),r=Or(),s=pC(),o=w$(),l=fu(),u=_$(),c=es(),p=_t();function h(f,m,y){m.length?m=e(m,function(_){return p(_)?function(S){return n(S,_.length===1?_[0]:_)}:_}):m=[c];var x=-1;m=e(m,l(r));var C=s(f,function(_,S,b){var E=e(m,function(N){return N(_)});return{criteria:E,index:++x,value:_}});return o(C,function(_,S){return u(_,S,y)})}return Zm=h,Zm}var Jm,ok;function b$(){if(ok)return Jm;ok=1;var e=$v(),n=S$(),r=wu(),s=xu(),o=r(function(l,u){if(l==null)return[];var c=u.length;return c>1&&s(l,u[0],u[1])?u=[]:c>2&&s(u[0],u[1],u[2])&&(u=[u[0]]),n(l,e(u,1),[])});return Jm=o,Jm}var eg,ak;function k$(){if(ak)return eg;ak=1;var e=aC(),n=0;function r(s){var o=++n;return e(s)+o}return eg=r,eg}var tg,lk;function E$(){if(lk)return tg;lk=1;function e(n,r,s){for(var o=-1,l=n.length,u=r.length,c={};++o<l;){var p=o<u?r[o]:void 0;s(c,n[o],p)}return c}return tg=e,tg}var ng,uk;function N$(){if(uk)return ng;uk=1;var e=cu(),n=E$();function r(s,o){return n(s||[],o||[],e)}return ng=r,ng}var rg,ck;function st(){if(ck)return rg;ck=1;var e;if(typeof bv=="function")try{e={cloneDeep:Bq(),constant:Mv(),defaults:Uq(),each:eC(),filter:dC(),find:Xq(),flatten:TC(),forEach:JN(),forIn:Qq(),has:fC(),isUndefined:hC(),last:Zq(),map:mC(),mapValues:Jq(),max:t$(),merge:a$(),min:l$(),minBy:u$(),now:c$(),pick:m$(),range:y$(),reduce:gC(),sortBy:b$(),uniqueId:k$(),values:_C(),zipObject:N$()}}catch{}return e||(e=window._),rg=e,rg}var ig,dk;function C$(){if(dk)return ig;dk=1,ig=e;function e(){var s={};s._next=s._prev=s,this._sentinel=s}e.prototype.dequeue=function(){var s=this._sentinel,o=s._prev;if(o!==s)return n(o),o},e.prototype.enqueue=function(s){var o=this._sentinel;s._prev&&s._next&&n(s),s._next=o._next,o._next._prev=s,o._next=s,s._prev=o},e.prototype.toString=function(){for(var s=[],o=this._sentinel,l=o._prev;l!==o;)s.push(JSON.stringify(l,r)),l=l._prev;return"["+s.join(", ")+"]"};function n(s){s._prev._next=s._next,s._next._prev=s._prev,delete s._next,delete s._prev}function r(s,o){if(s!=="_next"&&s!=="_prev")return o}return ig}var sg,fk;function T$(){if(fk)return sg;fk=1;var e=st(),n=Jn().Graph,r=C$();sg=o;var s=e.constant(1);function o(h,f){if(h.nodeCount()<=1)return[];var m=c(h,f||s),y=l(m.graph,m.buckets,m.zeroIdx);return e.flatten(e.map(y,function(x){return h.outEdges(x.v,x.w)}),!0)}function l(h,f,m){for(var y=[],x=f[f.length-1],C=f[0],_;h.nodeCount();){for(;_=C.dequeue();)u(h,f,m,_);for(;_=x.dequeue();)u(h,f,m,_);if(h.nodeCount()){for(var S=f.length-2;S>0;--S)if(_=f[S].dequeue(),_){y=y.concat(u(h,f,m,_,!0));break}}}return y}function u(h,f,m,y,x){var C=x?[]:void 0;return e.forEach(h.inEdges(y.v),function(_){var S=h.edge(_),b=h.node(_.v);x&&C.push({v:_.v,w:_.w}),b.out-=S,p(f,m,b)}),e.forEach(h.outEdges(y.v),function(_){var S=h.edge(_),b=_.w,E=h.node(b);E.in-=S,p(f,m,E)}),h.removeNode(y.v),C}function c(h,f){var m=new n,y=0,x=0;e.forEach(h.nodes(),function(S){m.setNode(S,{v:S,in:0,out:0})}),e.forEach(h.edges(),function(S){var b=m.edge(S.v,S.w)||0,E=f(S),N=b+E;m.setEdge(S.v,S.w,N),x=Math.max(x,m.node(S.v).out+=E),y=Math.max(y,m.node(S.w).in+=E)});var C=e.range(x+y+3).map(function(){return new r}),_=y+1;return e.forEach(m.nodes(),function(S){p(C,_,m.node(S))}),{graph:m,buckets:C,zeroIdx:_}}function p(h,f,m){m.out?m.in?h[m.out-m.in+f].enqueue(m):h[h.length-1].enqueue(m):h[0].enqueue(m)}return sg}var og,hk;function R$(){if(hk)return og;hk=1;var e=st(),n=T$();og={run:r,undo:o};function r(l){var u=l.graph().acyclicer==="greedy"?n(l,c(l)):s(l);e.forEach(u,function(p){var h=l.edge(p);l.removeEdge(p),h.forwardName=p.name,h.reversed=!0,l.setEdge(p.w,p.v,h,e.uniqueId("rev"))});function c(p){return function(h){return p.edge(h).weight}}}function s(l){var u=[],c={},p={};function h(f){e.has(p,f)||(p[f]=!0,c[f]=!0,e.forEach(l.outEdges(f),function(m){e.has(c,m.w)?u.push(m):h(m.w)}),delete c[f])}return e.forEach(l.nodes(),h),u}function o(l){e.forEach(l.edges(),function(u){var c=l.edge(u);if(c.reversed){l.removeEdge(u);var p=c.forwardName;delete c.reversed,delete c.forwardName,l.setEdge(u.w,u.v,c,p)}})}return og}var ag,pk;function dn(){if(pk)return ag;pk=1;var e=st(),n=Jn().Graph;ag={addDummyNode:r,simplify:s,asNonCompoundGraph:o,successorWeights:l,predecessorWeights:u,intersectRect:c,buildLayerMatrix:p,normalizeRanks:h,removeEmptyRanks:f,addBorderNode:m,maxRank:y,partition:x,time:C,notime:_};function r(S,b,E,N){var T;do T=e.uniqueId(N);while(S.hasNode(T));return E.dummy=b,S.setNode(T,E),T}function s(S){var b=new n().setGraph(S.graph());return e.forEach(S.nodes(),function(E){b.setNode(E,S.node(E))}),e.forEach(S.edges(),function(E){var N=b.edge(E.v,E.w)||{weight:0,minlen:1},T=S.edge(E);b.setEdge(E.v,E.w,{weight:N.weight+T.weight,minlen:Math.max(N.minlen,T.minlen)})}),b}function o(S){var b=new n({multigraph:S.isMultigraph()}).setGraph(S.graph());return e.forEach(S.nodes(),function(E){S.children(E).length||b.setNode(E,S.node(E))}),e.forEach(S.edges(),function(E){b.setEdge(E,S.edge(E))}),b}function l(S){var b=e.map(S.nodes(),function(E){var N={};return e.forEach(S.outEdges(E),function(T){N[T.w]=(N[T.w]||0)+S.edge(T).weight}),N});return e.zipObject(S.nodes(),b)}function u(S){var b=e.map(S.nodes(),function(E){var N={};return e.forEach(S.inEdges(E),function(T){N[T.v]=(N[T.v]||0)+S.edge(T).weight}),N});return e.zipObject(S.nodes(),b)}function c(S,b){var E=S.x,N=S.y,T=b.x-E,I=b.y-N,M=S.width/2,O=S.height/2;if(!T&&!I)throw new Error("Not possible to find intersection inside of the rectangle");var H,L;return Math.abs(I)*M>Math.abs(T)*O?(I<0&&(O=-O),H=O*T/I,L=O):(T<0&&(M=-M),H=M,L=M*I/T),{x:E+H,y:N+L}}function p(S){var b=e.map(e.range(y(S)+1),function(){return[]});return e.forEach(S.nodes(),function(E){var N=S.node(E),T=N.rank;e.isUndefined(T)||(b[T][N.order]=E)}),b}function h(S){var b=e.min(e.map(S.nodes(),function(E){return S.node(E).rank}));e.forEach(S.nodes(),function(E){var N=S.node(E);e.has(N,"rank")&&(N.rank-=b)})}function f(S){var b=e.min(e.map(S.nodes(),function(I){return S.node(I).rank})),E=[];e.forEach(S.nodes(),function(I){var M=S.node(I).rank-b;E[M]||(E[M]=[]),E[M].push(I)});var N=0,T=S.graph().nodeRankFactor;e.forEach(E,function(I,M){e.isUndefined(I)&&M%T!==0?--N:N&&e.forEach(I,function(O){S.node(O).rank+=N})})}function m(S,b,E,N){var T={width:0,height:0};return arguments.length>=4&&(T.rank=E,T.order=N),r(S,"border",T,b)}function y(S){return e.max(e.map(S.nodes(),function(b){var E=S.node(b).rank;if(!e.isUndefined(E))return E}))}function x(S,b){var E={lhs:[],rhs:[]};return e.forEach(S,function(N){b(N)?E.lhs.push(N):E.rhs.push(N)}),E}function C(S,b){var E=e.now();try{return b()}finally{console.log(S+" time: "+(e.now()-E)+"ms")}}function _(S,b){return b()}return ag}var lg,mk;function j$(){if(mk)return lg;mk=1;var e=st(),n=dn();lg={run:r,undo:o};function r(l){l.graph().dummyChains=[],e.forEach(l.edges(),function(u){s(l,u)})}function s(l,u){var c=u.v,p=l.node(c).rank,h=u.w,f=l.node(h).rank,m=u.name,y=l.edge(u),x=y.labelRank;if(f!==p+1){l.removeEdge(u);var C,_,S;for(S=0,++p;p<f;++S,++p)y.points=[],_={width:0,height:0,edgeLabel:y,edgeObj:u,rank:p},C=n.addDummyNode(l,"edge",_,"_d"),p===x&&(_.width=y.width,_.height=y.height,_.dummy="edge-label",_.labelpos=y.labelpos),l.setEdge(c,C,{weight:y.weight},m),S===0&&l.graph().dummyChains.push(C),c=C;l.setEdge(c,h,{weight:y.weight},m)}}function o(l){e.forEach(l.graph().dummyChains,function(u){var c=l.node(u),p=c.edgeLabel,h;for(l.setEdge(c.edgeObj,p);c.dummy;)h=l.successors(u)[0],l.removeNode(u),p.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(p.x=c.x,p.y=c.y,p.width=c.width,p.height=c.height),u=h,c=l.node(u)})}return lg}var ug,gk;function Kl(){if(gk)return ug;gk=1;var e=st();ug={longestPath:n,slack:r};function n(s){var o={};function l(u){var c=s.node(u);if(e.has(o,u))return c.rank;o[u]=!0;var p=e.min(e.map(s.outEdges(u),function(h){return l(h.w)-s.edge(h).minlen}));return(p===Number.POSITIVE_INFINITY||p===void 0||p===null)&&(p=0),c.rank=p}e.forEach(s.sources(),l)}function r(s,o){return s.node(o.w).rank-s.node(o.v).rank-s.edge(o).minlen}return ug}var cg,vk;function IC(){if(vk)return cg;vk=1;var e=st(),n=Jn().Graph,r=Kl().slack;cg=s;function s(c){var p=new n({directed:!1}),h=c.nodes()[0],f=c.nodeCount();p.setNode(h,{});for(var m,y;o(p,c)<f;)m=l(p,c),y=p.hasNode(m.v)?r(c,m):-r(c,m),u(p,c,y);return p}function o(c,p){function h(f){e.forEach(p.nodeEdges(f),function(m){var y=m.v,x=f===y?m.w:y;!c.hasNode(x)&&!r(p,m)&&(c.setNode(x,{}),c.setEdge(f,x,{}),h(x))})}return e.forEach(c.nodes(),h),c.nodeCount()}function l(c,p){return e.minBy(p.edges(),function(h){if(c.hasNode(h.v)!==c.hasNode(h.w))return r(p,h)})}function u(c,p,h){e.forEach(c.nodes(),function(f){p.node(f).rank+=h})}return cg}var dg,yk;function A$(){if(yk)return dg;yk=1;var e=st(),n=IC(),r=Kl().slack,s=Kl().longestPath,o=Jn().alg.preorder,l=Jn().alg.postorder,u=dn().simplify;dg=c,c.initLowLimValues=m,c.initCutValues=p,c.calcCutValue=f,c.leaveEdge=x,c.enterEdge=C,c.exchangeEdges=_;function c(N){N=u(N),s(N);var T=n(N);m(T),p(T,N);for(var I,M;I=x(T);)M=C(T,N,I),_(T,N,I,M)}function p(N,T){var I=l(N,N.nodes());I=I.slice(0,I.length-1),e.forEach(I,function(M){h(N,T,M)})}function h(N,T,I){var M=N.node(I),O=M.parent;N.edge(I,O).cutvalue=f(N,T,I)}function f(N,T,I){var M=N.node(I),O=M.parent,H=!0,L=T.edge(I,O),P=0;return L||(H=!1,L=T.edge(O,I)),P=L.weight,e.forEach(T.nodeEdges(I),function(q){var W=q.v===I,B=W?q.w:q.v;if(B!==O){var j=W===H,K=T.edge(q).weight;if(P+=j?K:-K,b(N,I,B)){var U=N.edge(I,B).cutvalue;P+=j?-U:U}}}),P}function m(N,T){arguments.length<2&&(T=N.nodes()[0]),y(N,{},1,T)}function y(N,T,I,M,O){var H=I,L=N.node(M);return T[M]=!0,e.forEach(N.neighbors(M),function(P){e.has(T,P)||(I=y(N,T,I,P,M))}),L.low=H,L.lim=I++,O?L.parent=O:delete L.parent,I}function x(N){return e.find(N.edges(),function(T){return N.edge(T).cutvalue<0})}function C(N,T,I){var M=I.v,O=I.w;T.hasEdge(M,O)||(M=I.w,O=I.v);var H=N.node(M),L=N.node(O),P=H,q=!1;H.lim>L.lim&&(P=L,q=!0);var W=e.filter(T.edges(),function(B){return q===E(N,N.node(B.v),P)&&q!==E(N,N.node(B.w),P)});return e.minBy(W,function(B){return r(T,B)})}function _(N,T,I,M){var O=I.v,H=I.w;N.removeEdge(O,H),N.setEdge(M.v,M.w,{}),m(N),p(N,T),S(N,T)}function S(N,T){var I=e.find(N.nodes(),function(O){return!T.node(O).parent}),M=o(N,I);M=M.slice(1),e.forEach(M,function(O){var H=N.node(O).parent,L=T.edge(O,H),P=!1;L||(L=T.edge(H,O),P=!0),T.node(O).rank=T.node(H).rank+(P?L.minlen:-L.minlen)})}function b(N,T,I){return N.hasEdge(T,I)}function E(N,T,I){return I.low<=T.lim&&T.lim<=I.lim}return dg}var fg,wk;function I$(){if(wk)return fg;wk=1;var e=Kl(),n=e.longestPath,r=IC(),s=A$();fg=o;function o(p){switch(p.graph().ranker){case"network-simplex":c(p);break;case"tight-tree":u(p);break;case"longest-path":l(p);break;default:c(p)}}var l=n;function u(p){n(p),r(p)}function c(p){s(p)}return fg}var hg,xk;function M$(){if(xk)return hg;xk=1;var e=st();hg=n;function n(o){var l=s(o);e.forEach(o.graph().dummyChains,function(u){for(var c=o.node(u),p=c.edgeObj,h=r(o,l,p.v,p.w),f=h.path,m=h.lca,y=0,x=f[y],C=!0;u!==p.w;){if(c=o.node(u),C){for(;(x=f[y])!==m&&o.node(x).maxRank<c.rank;)y++;x===m&&(C=!1)}if(!C){for(;y<f.length-1&&o.node(x=f[y+1]).minRank<=c.rank;)y++;x=f[y]}o.setParent(u,x),u=o.successors(u)[0]}})}function r(o,l,u,c){var p=[],h=[],f=Math.min(l[u].low,l[c].low),m=Math.max(l[u].lim,l[c].lim),y,x;y=u;do y=o.parent(y),p.push(y);while(y&&(l[y].low>f||m>l[y].lim));for(x=y,y=c;(y=o.parent(y))!==x;)h.push(y);return{path:p.concat(h.reverse()),lca:x}}function s(o){var l={},u=0;function c(p){var h=u;e.forEach(o.children(p),c),l[p]={low:h,lim:u++}}return e.forEach(o.children(),c),l}return hg}var pg,_k;function P$(){if(_k)return pg;_k=1;var e=st(),n=dn();pg={run:r,cleanup:u};function r(c){var p=n.addDummyNode(c,"root",{},"_root"),h=o(c),f=e.max(e.values(h))-1,m=2*f+1;c.graph().nestingRoot=p,e.forEach(c.edges(),function(x){c.edge(x).minlen*=m});var y=l(c)+1;e.forEach(c.children(),function(x){s(c,p,m,y,f,h,x)}),c.graph().nodeRankFactor=m}function s(c,p,h,f,m,y,x){var C=c.children(x);if(!C.length){x!==p&&c.setEdge(p,x,{weight:0,minlen:h});return}var _=n.addBorderNode(c,"_bt"),S=n.addBorderNode(c,"_bb"),b=c.node(x);c.setParent(_,x),b.borderTop=_,c.setParent(S,x),b.borderBottom=S,e.forEach(C,function(E){s(c,p,h,f,m,y,E);var N=c.node(E),T=N.borderTop?N.borderTop:E,I=N.borderBottom?N.borderBottom:E,M=N.borderTop?f:2*f,O=T!==I?1:m-y[x]+1;c.setEdge(_,T,{weight:M,minlen:O,nestingEdge:!0}),c.setEdge(I,S,{weight:M,minlen:O,nestingEdge:!0})}),c.parent(x)||c.setEdge(p,_,{weight:0,minlen:m+y[x]})}function o(c){var p={};function h(f,m){var y=c.children(f);y&&y.length&&e.forEach(y,function(x){h(x,m+1)}),p[f]=m}return e.forEach(c.children(),function(f){h(f,1)}),p}function l(c){return e.reduce(c.edges(),function(p,h){return p+c.edge(h).weight},0)}function u(c){var p=c.graph();c.removeNode(p.nestingRoot),delete p.nestingRoot,e.forEach(c.edges(),function(h){var f=c.edge(h);f.nestingEdge&&c.removeEdge(h)})}return pg}var mg,Sk;function O$(){if(Sk)return mg;Sk=1;var e=st(),n=dn();mg=r;function r(o){function l(u){var c=o.children(u),p=o.node(u);if(c.length&&e.forEach(c,l),e.has(p,"minRank")){p.borderLeft=[],p.borderRight=[];for(var h=p.minRank,f=p.maxRank+1;h<f;++h)s(o,"borderLeft","_bl",u,p,h),s(o,"borderRight","_br",u,p,h)}}e.forEach(o.children(),l)}function s(o,l,u,c,p,h){var f={width:0,height:0,rank:h,borderType:l},m=p[l][h-1],y=n.addDummyNode(o,"border",f,u);p[l][h]=y,o.setParent(y,c),m&&o.setEdge(m,y,{weight:1})}return mg}var gg,bk;function L$(){if(bk)return gg;bk=1;var e=st();gg={adjust:n,undo:r};function n(h){var f=h.graph().rankdir.toLowerCase();(f==="lr"||f==="rl")&&s(h)}function r(h){var f=h.graph().rankdir.toLowerCase();(f==="bt"||f==="rl")&&l(h),(f==="lr"||f==="rl")&&(c(h),s(h))}function s(h){e.forEach(h.nodes(),function(f){o(h.node(f))}),e.forEach(h.edges(),function(f){o(h.edge(f))})}function o(h){var f=h.width;h.width=h.height,h.height=f}function l(h){e.forEach(h.nodes(),function(f){u(h.node(f))}),e.forEach(h.edges(),function(f){var m=h.edge(f);e.forEach(m.points,u),e.has(m,"y")&&u(m)})}function u(h){h.y=-h.y}function c(h){e.forEach(h.nodes(),function(f){p(h.node(f))}),e.forEach(h.edges(),function(f){var m=h.edge(f);e.forEach(m.points,p),e.has(m,"x")&&p(m)})}function p(h){var f=h.x;h.x=h.y,h.y=f}return gg}var vg,kk;function q$(){if(kk)return vg;kk=1;var e=st();vg=n;function n(r){var s={},o=e.filter(r.nodes(),function(h){return!r.children(h).length}),l=e.max(e.map(o,function(h){return r.node(h).rank})),u=e.map(e.range(l+1),function(){return[]});function c(h){if(!e.has(s,h)){s[h]=!0;var f=r.node(h);u[f.rank].push(h),e.forEach(r.successors(h),c)}}var p=e.sortBy(o,function(h){return r.node(h).rank});return e.forEach(p,c),u}return vg}var yg,Ek;function $$(){if(Ek)return yg;Ek=1;var e=st();yg=n;function n(s,o){for(var l=0,u=1;u<o.length;++u)l+=r(s,o[u-1],o[u]);return l}function r(s,o,l){for(var u=e.zipObject(l,e.map(l,function(y,x){return x})),c=e.flatten(e.map(o,function(y){return e.sortBy(e.map(s.outEdges(y),function(x){return{pos:u[x.w],weight:s.edge(x).weight}}),"pos")}),!0),p=1;p<l.length;)p<<=1;var h=2*p-1;p-=1;var f=e.map(new Array(h),function(){return 0}),m=0;return e.forEach(c.forEach(function(y){var x=y.pos+p;f[x]+=y.weight;for(var C=0;x>0;)x%2&&(C+=f[x+1]),x=x-1>>1,f[x]+=y.weight;m+=y.weight*C})),m}return yg}var wg,Nk;function D$(){if(Nk)return wg;Nk=1;var e=st();wg=n;function n(r,s){return e.map(s,function(o){var l=r.inEdges(o);if(l.length){var u=e.reduce(l,function(c,p){var h=r.edge(p),f=r.node(p.v);return{sum:c.sum+h.weight*f.order,weight:c.weight+h.weight}},{sum:0,weight:0});return{v:o,barycenter:u.sum/u.weight,weight:u.weight}}else return{v:o}})}return wg}var xg,Ck;function F$(){if(Ck)return xg;Ck=1;var e=st();xg=n;function n(o,l){var u={};e.forEach(o,function(p,h){var f=u[p.v]={indegree:0,in:[],out:[],vs:[p.v],i:h};e.isUndefined(p.barycenter)||(f.barycenter=p.barycenter,f.weight=p.weight)}),e.forEach(l.edges(),function(p){var h=u[p.v],f=u[p.w];!e.isUndefined(h)&&!e.isUndefined(f)&&(f.indegree++,h.out.push(u[p.w]))});var c=e.filter(u,function(p){return!p.indegree});return r(c)}function r(o){var l=[];function u(h){return function(f){f.merged||(e.isUndefined(f.barycenter)||e.isUndefined(h.barycenter)||f.barycenter>=h.barycenter)&&s(h,f)}}function c(h){return function(f){f.in.push(h),--f.indegree===0&&o.push(f)}}for(;o.length;){var p=o.pop();l.push(p),e.forEach(p.in.reverse(),u(p)),e.forEach(p.out,c(p))}return e.map(e.filter(l,function(h){return!h.merged}),function(h){return e.pick(h,["vs","i","barycenter","weight"])})}function s(o,l){var u=0,c=0;o.weight&&(u+=o.barycenter*o.weight,c+=o.weight),l.weight&&(u+=l.barycenter*l.weight,c+=l.weight),o.vs=l.vs.concat(o.vs),o.barycenter=u/c,o.weight=c,o.i=Math.min(l.i,o.i),l.merged=!0}return xg}var _g,Tk;function z$(){if(Tk)return _g;Tk=1;var e=st(),n=dn();_g=r;function r(l,u){var c=n.partition(l,function(_){return e.has(_,"barycenter")}),p=c.lhs,h=e.sortBy(c.rhs,function(_){return-_.i}),f=[],m=0,y=0,x=0;p.sort(o(!!u)),x=s(f,h,x),e.forEach(p,function(_){x+=_.vs.length,f.push(_.vs),m+=_.barycenter*_.weight,y+=_.weight,x=s(f,h,x)});var C={vs:e.flatten(f,!0)};return y&&(C.barycenter=m/y,C.weight=y),C}function s(l,u,c){for(var p;u.length&&(p=e.last(u)).i<=c;)u.pop(),l.push(p.vs),c++;return c}function o(l){return function(u,c){return u.barycenter<c.barycenter?-1:u.barycenter>c.barycenter?1:l?c.i-u.i:u.i-c.i}}return _g}var Sg,Rk;function B$(){if(Rk)return Sg;Rk=1;var e=st(),n=D$(),r=F$(),s=z$();Sg=o;function o(c,p,h,f){var m=c.children(p),y=c.node(p),x=y?y.borderLeft:void 0,C=y?y.borderRight:void 0,_={};x&&(m=e.filter(m,function(I){return I!==x&&I!==C}));var S=n(c,m);e.forEach(S,function(I){if(c.children(I.v).length){var M=o(c,I.v,h,f);_[I.v]=M,e.has(M,"barycenter")&&u(I,M)}});var b=r(S,h);l(b,_);var E=s(b,f);if(x&&(E.vs=e.flatten([x,E.vs,C],!0),c.predecessors(x).length)){var N=c.node(c.predecessors(x)[0]),T=c.node(c.predecessors(C)[0]);e.has(E,"barycenter")||(E.barycenter=0,E.weight=0),E.barycenter=(E.barycenter*E.weight+N.order+T.order)/(E.weight+2),E.weight+=2}return E}function l(c,p){e.forEach(c,function(h){h.vs=e.flatten(h.vs.map(function(f){return p[f]?p[f].vs:f}),!0)})}function u(c,p){e.isUndefined(c.barycenter)?(c.barycenter=p.barycenter,c.weight=p.weight):(c.barycenter=(c.barycenter*c.weight+p.barycenter*p.weight)/(c.weight+p.weight),c.weight+=p.weight)}return Sg}var bg,jk;function U$(){if(jk)return bg;jk=1;var e=st(),n=Jn().Graph;bg=r;function r(o,l,u){var c=s(o),p=new n({compound:!0}).setGraph({root:c}).setDefaultNodeLabel(function(h){return o.node(h)});return e.forEach(o.nodes(),function(h){var f=o.node(h),m=o.parent(h);(f.rank===l||f.minRank<=l&&l<=f.maxRank)&&(p.setNode(h),p.setParent(h,m||c),e.forEach(o[u](h),function(y){var x=y.v===h?y.w:y.v,C=p.edge(x,h),_=e.isUndefined(C)?0:C.weight;p.setEdge(x,h,{weight:o.edge(y).weight+_})}),e.has(f,"minRank")&&p.setNode(h,{borderLeft:f.borderLeft[l],borderRight:f.borderRight[l]}))}),p}function s(o){for(var l;o.hasNode(l=e.uniqueId("_root")););return l}return bg}var kg,Ak;function H$(){if(Ak)return kg;Ak=1;var e=st();kg=n;function n(r,s,o){var l={},u;e.forEach(o,function(c){for(var p=r.parent(c),h,f;p;){if(h=r.parent(p),h?(f=l[h],l[h]=p):(f=u,u=p),f&&f!==p){s.setEdge(f,p);return}p=h}})}return kg}var Eg,Ik;function W$(){if(Ik)return Eg;Ik=1;var e=st(),n=q$(),r=$$(),s=B$(),o=U$(),l=H$(),u=Jn().Graph,c=dn();Eg=p;function p(y){var x=c.maxRank(y),C=h(y,e.range(1,x+1),"inEdges"),_=h(y,e.range(x-1,-1,-1),"outEdges"),S=n(y);m(y,S);for(var b=Number.POSITIVE_INFINITY,E,N=0,T=0;T<4;++N,++T){f(N%2?C:_,N%4>=2),S=c.buildLayerMatrix(y);var I=r(y,S);I<b&&(T=0,E=e.cloneDeep(S),b=I)}m(y,E)}function h(y,x,C){return e.map(x,function(_){return o(y,_,C)})}function f(y,x){var C=new u;e.forEach(y,function(_){var S=_.graph().root,b=s(_,S,C,x);e.forEach(b.vs,function(E,N){_.node(E).order=N}),l(_,C,b.vs)})}function m(y,x){e.forEach(x,function(C){e.forEach(C,function(_,S){y.node(_).order=S})})}return Eg}var Ng,Mk;function V$(){if(Mk)return Ng;Mk=1;var e=st(),n=Jn().Graph,r=dn();Ng={positionX:C,findType1Conflicts:s,findType2Conflicts:o,addConflict:u,hasConflict:c,verticalAlignment:p,horizontalCompaction:h,alignCoordinates:y,findSmallestWidthAlignment:m,balance:x};function s(b,E){var N={};function T(I,M){var O=0,H=0,L=I.length,P=e.last(M);return e.forEach(M,function(q,W){var B=l(b,q),j=B?b.node(B).order:L;(B||q===P)&&(e.forEach(M.slice(H,W+1),function(K){e.forEach(b.predecessors(K),function(U){var ee=b.node(U),J=ee.order;(J<O||j<J)&&!(ee.dummy&&b.node(K).dummy)&&u(N,U,K)})}),H=W+1,O=j)}),M}return e.reduce(E,T),N}function o(b,E){var N={};function T(M,O,H,L,P){var q;e.forEach(e.range(O,H),function(W){q=M[W],b.node(q).dummy&&e.forEach(b.predecessors(q),function(B){var j=b.node(B);j.dummy&&(j.order<L||j.order>P)&&u(N,B,q)})})}function I(M,O){var H=-1,L,P=0;return e.forEach(O,function(q,W){if(b.node(q).dummy==="border"){var B=b.predecessors(q);B.length&&(L=b.node(B[0]).order,T(O,P,W,H,L),P=W,H=L)}T(O,P,O.length,L,M.length)}),O}return e.reduce(E,I),N}function l(b,E){if(b.node(E).dummy)return e.find(b.predecessors(E),function(N){return b.node(N).dummy})}function u(b,E,N){if(E>N){var T=E;E=N,N=T}var I=b[E];I||(b[E]=I={}),I[N]=!0}function c(b,E,N){if(E>N){var T=E;E=N,N=T}return e.has(b[E],N)}function p(b,E,N,T){var I={},M={},O={};return e.forEach(E,function(H){e.forEach(H,function(L,P){I[L]=L,M[L]=L,O[L]=P})}),e.forEach(E,function(H){var L=-1;e.forEach(H,function(P){var q=T(P);if(q.length){q=e.sortBy(q,function(U){return O[U]});for(var W=(q.length-1)/2,B=Math.floor(W),j=Math.ceil(W);B<=j;++B){var K=q[B];M[P]===P&&L<O[K]&&!c(N,P,K)&&(M[K]=P,M[P]=I[P]=I[K],L=O[K])}}})}),{root:I,align:M}}function h(b,E,N,T,I){var M={},O=f(b,E,N,I),H=I?"borderLeft":"borderRight";function L(W,B){for(var j=O.nodes(),K=j.pop(),U={};K;)U[K]?W(K):(U[K]=!0,j.push(K),j=j.concat(B(K))),K=j.pop()}function P(W){M[W]=O.inEdges(W).reduce(function(B,j){return Math.max(B,M[j.v]+O.edge(j))},0)}function q(W){var B=O.outEdges(W).reduce(function(K,U){return Math.min(K,M[U.w]-O.edge(U))},Number.POSITIVE_INFINITY),j=b.node(W);B!==Number.POSITIVE_INFINITY&&j.borderType!==H&&(M[W]=Math.max(M[W],B))}return L(P,O.predecessors.bind(O)),L(q,O.successors.bind(O)),e.forEach(T,function(W){M[W]=M[N[W]]}),M}function f(b,E,N,T){var I=new n,M=b.graph(),O=_(M.nodesep,M.edgesep,T);return e.forEach(E,function(H){var L;e.forEach(H,function(P){var q=N[P];if(I.setNode(q),L){var W=N[L],B=I.edge(W,q);I.setEdge(W,q,Math.max(O(b,P,L),B||0))}L=P})}),I}function m(b,E){return e.minBy(e.values(E),function(N){var T=Number.NEGATIVE_INFINITY,I=Number.POSITIVE_INFINITY;return e.forIn(N,function(M,O){var H=S(b,O)/2;T=Math.max(M+H,T),I=Math.min(M-H,I)}),T-I})}function y(b,E){var N=e.values(E),T=e.min(N),I=e.max(N);e.forEach(["u","d"],function(M){e.forEach(["l","r"],function(O){var H=M+O,L=b[H],P;if(L!==E){var q=e.values(L);P=O==="l"?T-e.min(q):I-e.max(q),P&&(b[H]=e.mapValues(L,function(W){return W+P}))}})})}function x(b,E){return e.mapValues(b.ul,function(N,T){if(E)return b[E.toLowerCase()][T];var I=e.sortBy(e.map(b,T));return(I[1]+I[2])/2})}function C(b){var E=r.buildLayerMatrix(b),N=e.merge(s(b,E),o(b,E)),T={},I;e.forEach(["u","d"],function(O){I=O==="u"?E:e.values(E).reverse(),e.forEach(["l","r"],function(H){H==="r"&&(I=e.map(I,function(W){return e.values(W).reverse()}));var L=(O==="u"?b.predecessors:b.successors).bind(b),P=p(b,I,N,L),q=h(b,I,P.root,P.align,H==="r");H==="r"&&(q=e.mapValues(q,function(W){return-W})),T[O+H]=q})});var M=m(b,T);return y(T,M),x(T,b.graph().align)}function _(b,E,N){return function(T,I,M){var O=T.node(I),H=T.node(M),L=0,P;if(L+=O.width/2,e.has(O,"labelpos"))switch(O.labelpos.toLowerCase()){case"l":P=-O.width/2;break;case"r":P=O.width/2;break}if(P&&(L+=N?P:-P),P=0,L+=(O.dummy?E:b)/2,L+=(H.dummy?E:b)/2,L+=H.width/2,e.has(H,"labelpos"))switch(H.labelpos.toLowerCase()){case"l":P=H.width/2;break;case"r":P=-H.width/2;break}return P&&(L+=N?P:-P),P=0,L}}function S(b,E){return b.node(E).width}return Ng}var Cg,Pk;function G$(){if(Pk)return Cg;Pk=1;var e=st(),n=dn(),r=V$().positionX;Cg=s;function s(l){l=n.asNonCompoundGraph(l),o(l),e.forEach(r(l),function(u,c){l.node(c).x=u})}function o(l){var u=n.buildLayerMatrix(l),c=l.graph().ranksep,p=0;e.forEach(u,function(h){var f=e.max(e.map(h,function(m){return l.node(m).height}));e.forEach(h,function(m){l.node(m).y=p+f/2}),p+=f+c})}return Cg}var Tg,Ok;function Y$(){if(Ok)return Tg;Ok=1;var e=st(),n=R$(),r=j$(),s=I$(),o=dn().normalizeRanks,l=M$(),u=dn().removeEmptyRanks,c=P$(),p=O$(),h=L$(),f=W$(),m=G$(),y=dn(),x=Jn().Graph;Tg=C;function C(D,Q){var te=Q&&Q.debugTiming?y.time:y.notime;te("layout",function(){var ae=te(" buildLayoutGraph",function(){return L(D)});te(" runLayout",function(){_(ae,te)}),te(" updateInputGraph",function(){S(D,ae)})})}function _(D,Q){Q(" makeSpaceForEdgeLabels",function(){P(D)}),Q(" removeSelfEdges",function(){F(D)}),Q(" acyclic",function(){n.run(D)}),Q(" nestingGraph.run",function(){c.run(D)}),Q(" rank",function(){s(y.asNonCompoundGraph(D))}),Q(" injectEdgeLabelProxies",function(){q(D)}),Q(" removeEmptyRanks",function(){u(D)}),Q(" nestingGraph.cleanup",function(){c.cleanup(D)}),Q(" normalizeRanks",function(){o(D)}),Q(" assignRankMinMax",function(){W(D)}),Q(" removeEdgeLabelProxies",function(){B(D)}),Q(" normalize.run",function(){r.run(D)}),Q(" parentDummyChains",function(){l(D)}),Q(" addBorderSegments",function(){p(D)}),Q(" order",function(){f(D)}),Q(" insertSelfEdges",function(){Y(D)}),Q(" adjustCoordinateSystem",function(){h.adjust(D)}),Q(" position",function(){m(D)}),Q(" positionSelfEdges",function(){k(D)}),Q(" removeBorderNodes",function(){J(D)}),Q(" normalize.undo",function(){r.undo(D)}),Q(" fixupEdgeLabelCoords",function(){U(D)}),Q(" undoCoordinateSystem",function(){h.undo(D)}),Q(" translateGraph",function(){j(D)}),Q(" assignNodeIntersects",function(){K(D)}),Q(" reversePoints",function(){ee(D)}),Q(" acyclic.undo",function(){n.undo(D)})}function S(D,Q){e.forEach(D.nodes(),function(te){var ae=D.node(te),ce=Q.node(te);ae&&(ae.x=ce.x,ae.y=ce.y,Q.children(te).length&&(ae.width=ce.width,ae.height=ce.height))}),e.forEach(D.edges(),function(te){var ae=D.edge(te),ce=Q.edge(te);ae.points=ce.points,e.has(ce,"x")&&(ae.x=ce.x,ae.y=ce.y)}),D.graph().width=Q.graph().width,D.graph().height=Q.graph().height}var b=["nodesep","edgesep","ranksep","marginx","marginy"],E={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},N=["acyclicer","ranker","rankdir","align"],T=["width","height"],I={width:0,height:0},M=["minlen","weight","width","height","labeloffset"],O={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},H=["labelpos"];function L(D){var Q=new x({multigraph:!0,compound:!0}),te=se(D.graph());return Q.setGraph(e.merge({},E,$(te,b),e.pick(te,N))),e.forEach(D.nodes(),function(ae){var ce=se(D.node(ae));Q.setNode(ae,e.defaults($(ce,T),I)),Q.setParent(ae,D.parent(ae))}),e.forEach(D.edges(),function(ae){var ce=se(D.edge(ae));Q.setEdge(ae,e.merge({},O,$(ce,M),e.pick(ce,H)))}),Q}function P(D){var Q=D.graph();Q.ranksep/=2,e.forEach(D.edges(),function(te){var ae=D.edge(te);ae.minlen*=2,ae.labelpos.toLowerCase()!=="c"&&(Q.rankdir==="TB"||Q.rankdir==="BT"?ae.width+=ae.labeloffset:ae.height+=ae.labeloffset)})}function q(D){e.forEach(D.edges(),function(Q){var te=D.edge(Q);if(te.width&&te.height){var ae=D.node(Q.v),ce=D.node(Q.w),me={rank:(ce.rank-ae.rank)/2+ae.rank,e:Q};y.addDummyNode(D,"edge-proxy",me,"_ep")}})}function W(D){var Q=0;e.forEach(D.nodes(),function(te){var ae=D.node(te);ae.borderTop&&(ae.minRank=D.node(ae.borderTop).rank,ae.maxRank=D.node(ae.borderBottom).rank,Q=e.max(Q,ae.maxRank))}),D.graph().maxRank=Q}function B(D){e.forEach(D.nodes(),function(Q){var te=D.node(Q);te.dummy==="edge-proxy"&&(D.edge(te.e).labelRank=te.rank,D.removeNode(Q))})}function j(D){var Q=Number.POSITIVE_INFINITY,te=0,ae=Number.POSITIVE_INFINITY,ce=0,me=D.graph(),ge=me.marginx||0,Pe=me.marginy||0;function Se(Oe){var Me=Oe.x,be=Oe.y,De=Oe.width,ve=Oe.height;Q=Math.min(Q,Me-De/2),te=Math.max(te,Me+De/2),ae=Math.min(ae,be-ve/2),ce=Math.max(ce,be+ve/2)}e.forEach(D.nodes(),function(Oe){Se(D.node(Oe))}),e.forEach(D.edges(),function(Oe){var Me=D.edge(Oe);e.has(Me,"x")&&Se(Me)}),Q-=ge,ae-=Pe,e.forEach(D.nodes(),function(Oe){var Me=D.node(Oe);Me.x-=Q,Me.y-=ae}),e.forEach(D.edges(),function(Oe){var Me=D.edge(Oe);e.forEach(Me.points,function(be){be.x-=Q,be.y-=ae}),e.has(Me,"x")&&(Me.x-=Q),e.has(Me,"y")&&(Me.y-=ae)}),me.width=te-Q+ge,me.height=ce-ae+Pe}function K(D){e.forEach(D.edges(),function(Q){var te=D.edge(Q),ae=D.node(Q.v),ce=D.node(Q.w),me,ge;te.points?(me=te.points[0],ge=te.points[te.points.length-1]):(te.points=[],me=ce,ge=ae),te.points.unshift(y.intersectRect(ae,me)),te.points.push(y.intersectRect(ce,ge))})}function U(D){e.forEach(D.edges(),function(Q){var te=D.edge(Q);if(e.has(te,"x"))switch((te.labelpos==="l"||te.labelpos==="r")&&(te.width-=te.labeloffset),te.labelpos){case"l":te.x-=te.width/2+te.labeloffset;break;case"r":te.x+=te.width/2+te.labeloffset;break}})}function ee(D){e.forEach(D.edges(),function(Q){var te=D.edge(Q);te.reversed&&te.points.reverse()})}function J(D){e.forEach(D.nodes(),function(Q){if(D.children(Q).length){var te=D.node(Q),ae=D.node(te.borderTop),ce=D.node(te.borderBottom),me=D.node(e.last(te.borderLeft)),ge=D.node(e.last(te.borderRight));te.width=Math.abs(ge.x-me.x),te.height=Math.abs(ce.y-ae.y),te.x=me.x+te.width/2,te.y=ae.y+te.height/2}}),e.forEach(D.nodes(),function(Q){D.node(Q).dummy==="border"&&D.removeNode(Q)})}function F(D){e.forEach(D.edges(),function(Q){if(Q.v===Q.w){var te=D.node(Q.v);te.selfEdges||(te.selfEdges=[]),te.selfEdges.push({e:Q,label:D.edge(Q)}),D.removeEdge(Q)}})}function Y(D){var Q=y.buildLayerMatrix(D);e.forEach(Q,function(te){var ae=0;e.forEach(te,function(ce,me){var ge=D.node(ce);ge.order=me+ae,e.forEach(ge.selfEdges,function(Pe){y.addDummyNode(D,"selfedge",{width:Pe.label.width,height:Pe.label.height,rank:ge.rank,order:me+ ++ae,e:Pe.e,label:Pe.label},"_se")}),delete ge.selfEdges})})}function k(D){e.forEach(D.nodes(),function(Q){var te=D.node(Q);if(te.dummy==="selfedge"){var ae=D.node(te.e.v),ce=ae.x+ae.width/2,me=ae.y,ge=te.x-ce,Pe=ae.height/2;D.setEdge(te.e,te.label),D.removeNode(Q),te.label.points=[{x:ce+2*ge/3,y:me-Pe},{x:ce+5*ge/6,y:me-Pe},{x:ce+ge,y:me},{x:ce+5*ge/6,y:me+Pe},{x:ce+2*ge/3,y:me+Pe}],te.label.x=te.x,te.label.y=te.y}})}function $(D,Q){return e.mapValues(e.pick(D,Q),Number)}function se(D){var Q={};return e.forEach(D,function(te,ae){Q[ae.toLowerCase()]=te}),Q}return Tg}var Rg,Lk;function K$(){if(Lk)return Rg;Lk=1;var e=st(),n=dn(),r=Jn().Graph;Rg={debugOrdering:s};function s(o){var l=n.buildLayerMatrix(o),u=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(c){u.setNode(c,{label:c}),u.setParent(c,"layer"+o.node(c).rank)}),e.forEach(o.edges(),function(c){u.setEdge(c.v,c.w,{},c.name)}),e.forEach(l,function(c,p){var h="layer"+p;u.setNode(h,{rank:"same"}),e.reduce(c,function(f,m){return u.setEdge(f,m,{style:"invis"}),m})}),u}return Rg}var jg,qk;function X$(){return qk||(qk=1,jg="0.8.5"),jg}var Ag,$k;function Q$(){return $k||($k=1,Ag={graphlib:Jn(),layout:Y$(),debug:K$(),util:{time:dn().time,notime:dn().notime},version:X$()}),Ag}var Z$=Q$();const Dk=nv(Z$),Js=240,Xl=130,Ys=74,_u=72,Fk=Ys+_u;function J$(e,n){var s;let r=Js;for(const o of e)r=Math.max(r,((s=n.get(o.id))==null?void 0:s.width)??Js);return r}const MC=420,e4=2;function ia(e){var r;return((r=e.data)==null?void 0:r.sessionId)??"_default"}function t4(e,n){return((n==null?void 0:n.get(e))??0)>0?MC:0}function n4(e,n){const r=(n==null?void 0:n.get(e))??0;return r>0?6+r*36:0}function sa(e,n,r){const s=n.get(e);return{w:((s==null?void 0:s.width)??Js)+t4(e,r),h:Math.max((s==null?void 0:s.height)??Xl,n4(e,r))}}function r4(e){return[...e.keys()].sort().map(n=>`${n}:${e.get(n)}`).join("|")}function i4(e,n,r,s,o,l){const u=new Dk.graphlib.Graph;u.setDefaultEdgeLabel(()=>({})),u.setGraph({rankdir:r,marginx:0,marginy:0,nodesep:70,ranksep:160,edgesep:30});const c=e.filter(b=>!o.has(b)),p=new Set(c);for(const b of c){const{w:E,h:N}=sa(b,s,l);u.setNode(b,{width:E,height:N})}for(const b of n)p.has(b.source)&&p.has(b.target)&&u.setEdge(b.source,b.target);Dk.layout(u);const h=new Map;let f=1/0,m=1/0,y=-1/0,x=-1/0;for(const b of c){const E=u.node(b);if(!E)continue;const N=s.get(b),T=(N==null?void 0:N.width)??Js,I=(N==null?void 0:N.height)??Xl,M=sa(b,s,l),O=E.x-M.w/2,H=E.y-M.h/2;h.set(b,{x:O,y:H}),O<f&&(f=O),H<m&&(m=H),O+T>y&&(y=O+T),H+I>x&&(x=H+I)}if(Number.isFinite(f)&&Number.isFinite(m))for(const[b,E]of h)h.set(b,{x:E.x-f,y:E.y-m});const C=Number.isFinite(y)?y-f:0,_=Number.isFinite(x)?x-m:0;let S=null;for(const b of e){const E=o.get(b);if(!E)continue;const N=s.get(b),T=(N==null?void 0:N.width)??Js,I=(N==null?void 0:N.height)??Xl;S=S===null?{minX:E.x,minY:E.y,maxX:E.x+T,maxY:E.y+I}:{minX:Math.min(S.minX,E.x),minY:Math.min(S.minY,E.y),maxX:Math.max(S.maxX,E.x+T),maxY:Math.max(S.maxY,E.y+I)}}return{positions:h,width:C,height:_,pinnedBox:S}}function s4(e,n,r={}){const s=r.direction??"LR",o=r.pinned??new Map,l=r.measured??new Map,u=r.lanes,c=new Map;for(const b of e){const E=ia(b),N=c.get(E);N?N.push(b.id):c.set(E,[b.id])}const h=Array.from(c.keys()).sort().map(b=>({sid:b,...i4(c.get(b),n,s,l,o,u)})),f=J$(e,l),m=r.availableHeight&&r.availableHeight>0?r.availableHeight:Number.POSITIVE_INFINITY,y=b=>{const E=[[]];let N=0;for(const T of h)E.length<b&&N>0&&N+T.height>m&&(E.push([]),N=0),E[E.length-1].push(T),N+=T.height+Fk;return E},x=b=>b.reduce((E,N)=>Math.max(E,N.width),0)+MC;let C=y(r.availableWidth?e4:1);C.length>1&&C.reduce((E,N)=>E+x(N),0)+f*(C.length-1)>(r.availableWidth??0)&&(C=y(1));const _=new Map;let S=0;for(const b of C){const E=x(b);let N=0;for(const{positions:T,height:I,pinnedBox:M}of b){for(const[H,L]of T)_.set(H,{x:L.x+S,y:L.y+N});let O=N+I;M&&M.maxY>O&&M.minX<S+E&&S<M.maxX&&(O=M.maxY),N=O+Fk}S+=E+f}return e.map(b=>{const E=o.get(b.id);if(E)return{...b,position:E};const N=_.get(b.id);return N?{...b,position:N}:b})}function o4(e,n,r,s,o){const u=Ys+_u,c=60,p=x=>sa(x,s,o),h=new Map(e.map(x=>[x.id,ia(x)])),f=[],m=e.map(x=>({id:x.id,pos:r.get(x.id)??n.get(x.id)})).filter(x=>x.pos!=null).sort((x,C)=>x.pos.y-C.pos.y||x.pos.x-C.pos.x||x.id.localeCompare(C.id)),y=[];for(const{id:x,pos:C}of m){const{w:_,h:S}=p(x),b=h.get(x)??"_default";if(r.has(x)){f.push({x:C.x,y:C.y,w:_,h:S,sid:b});continue}let E=C.y;for(let N=0;N<f.length+1;N++){const T=f.find(I=>{const M=I.sid===b?24:c,O=I.sid===b?24:u;return C.x<I.x+I.w+M&&I.x<C.x+_+M&&E<I.y+I.h+O&&I.y<E+S+O});if(!T)break;E=T.y+T.h+(T.sid===b?24:u)}E!==C.y&&(n.set(x,{x:C.x,y:E}),y.push(x)),f.push({x:C.x,y:E,w:_,h:S,sid:b})}return y}function a4(e,n,r,s,o,l){const u=_=>sa(_,s,l),c=_=>r.get(_)??n.get(_),p=new Map;for(const _ of e){if(!c(_.id))continue;const S=ia(_),b=p.get(S);b?b.push(_):p.set(S,[_])}const h=new Set;for(const[_,S]of p)S.every(b=>o.has(b.id)&&!r.has(b.id))&&h.add(_);const f=new Map,m=[];for(const _ of e){const S=c(_.id);if(!S)continue;const{w:b,h:E}=u(_.id),N=ia(_);h.has(N)?(f.get(N)??f.set(N,[]).get(N)).push(_):m.push({x:S.x,y:S.y,w:b,h:E})}if(f.size===0)return[];const y=Ys+_u,x=(_,S,b,E)=>m.some(N=>_<N.x+N.w+Ys&&N.x<_+b+Ys&&S<N.y+N.h+y&&N.y<S+E+y),C=[];for(const _ of[...f.keys()].sort()){const S=f.get(_);let b=1/0,E=1/0,N=-1/0,T=-1/0;for(const q of S){const W=c(q.id),{w:B,h:j}=u(q.id);b=Math.min(b,W.x),E=Math.min(E,W.y),N=Math.max(N,W.x+B),T=Math.max(T,W.y+j)}const I=N-b,M=T-E,O=[...new Set(m.map(q=>Math.round(q.x)))].sort((q,W)=>q-W),H=O.length?O:[b],L=[0,...m.map(q=>q.y+q.h+y)].sort((q,W)=>q-W);let P=null;e:for(const q of H)for(const W of L){if(W>=E)break;if(!x(q,W,I,M)){P={x:q,y:W};break e}}if(P){const q=P.x-b,W=P.y-E;for(const B of S){const j=c(B.id);n.set(B.id,{x:j.x+q,y:j.y+W})}C.push(_)}for(const q of S){const W=c(q.id),{w:B,h:j}=u(q.id);m.push({x:W.x,y:W.y,w:B,h:j})}}return C}function l4(e,n,r,s,o,l=!1,u){const h=Ys+_u+1,f=8,m=1.75,y=200,x=.7,C=.01,_=P=>sa(P,s,u),S=P=>r.get(P)??n.get(P),b=new Map;for(const P of e){if(!S(P.id))continue;const q=ia(P),W=b.get(q);W?W.push(P):b.set(q,[P])}const E=[],N=new Set,T=new Set,I=o.size===0;for(const P of[...b.keys()].sort()){const q=b.get(P);let W=1/0,B=1/0,j=-1/0,K=-1/0,U=!1;for(const Y of q){const k=S(Y.id),{w:$,h:se}=_(Y.id);W=Math.min(W,k.x),B=Math.min(B,k.y),j=Math.max(j,k.x+$),K=Math.max(K,k.y+se),r.has(Y.id)&&(U=!0)}const ee=j-W,J=K-B;T.add(P);const F=o.get(P);F&&(ee>F.w+f||J>F.h+f)&&N.add(P),o.set(P,{w:ee,h:J}),E.push({sid:P,members:q.map(Y=>Y.id),x:W,y:B,w:ee,h:J,anchored:U,mass:1})}for(const P of[...o.keys()])T.has(P)||o.delete(P);if(l||I)return[];let M=!1;for(let P=0;P<E.length&&!M;P++)for(let q=P+1;q<E.length;q++){const W=E[P],B=E[q];if(!(W.anchored&&B.anchored)&&Math.abs(W.x+W.w/2-(B.x+B.w/2))<(W.w+B.w)/2+61&&Math.abs(W.y+W.h/2-(B.y+B.h/2))<(W.h+B.h)/2+h){M=!0;break}}if(N.size===0&&!M)return[];if(N.size>0)for(const P of E)N.has(P.sid)&&(P.mass=8);else for(const P of E)P.mass=Math.max(1,P.w*P.h/(Js*Xl));const O=new Map(E.map(P=>[P.sid,P.x])),H=new Map(E.map(P=>[P.sid,P.y]));for(let P=0;P<y;P++){const q=new Map,W=new Map;let B=0;for(let j=0;j<E.length;j++)for(let K=j+1;K<E.length;K++){const U=E[j],ee=E[K];if(U.anchored&&ee.anchored)continue;const J=U.x+U.w/2,F=U.y+U.h/2,Y=ee.x+ee.w/2,k=ee.y+ee.h/2,$=(U.w+ee.w)/2+61-Math.abs(J-Y),se=(U.h+ee.h)/2+h-Math.abs(F-k);if($<=0||se<=0)continue;const D=(Fe,Je)=>!Fe.anchored&&!(Je<0&&Fe.x<=0),Q=(Fe,Je)=>!Fe.anchored&&!(Je<0&&Fe.y<=0),te=(Fe,Je,dt)=>{const Nt=Fe===Je,ot=Nt?U.sid<ee.sid?-1:1:Math.sign(Fe-Je);return dt(U,ot)||dt(ee,-ot)?ot:Nt&&(dt(U,-ot)||dt(ee,ot))?-ot:0},ae=te(J,Y,D),ce=te(F,k,Q),me=ae!==0,ge=ce!==0;if(!me&&!ge)continue;const Pe=me&&(!ge||$*m<se),[Se,Oe,Me,be]=Pe?[ae,$,q,D]:[ce,se,W,Q],De=be(U,Se),ve=be(ee,-Se),we=U.mass,Ue=ee.mass,ut=De?ve?Ue/(we+Ue):1:0,ct=ve?De?we/(we+Ue):1:0,Ze=Oe*x;Me.set(U.sid,(Me.get(U.sid)??0)+Se*Ze*ut),Me.set(ee.sid,(Me.get(ee.sid)??0)-Se*Ze*ct),B+=Ze}for(const j of E)j.anchored||(j.x=Math.max(0,j.x+(q.get(j.sid)??0)),j.y=Math.max(0,j.y+(W.get(j.sid)??0)));if(B<C)break}const L=[];for(const P of E){const q=P.x-O.get(P.sid),W=P.y-H.get(P.sid);if(!(Math.abs(q)<1&&Math.abs(W)<1)){for(const B of P.members){if(r.has(B))continue;const j=n.get(B);j&&n.set(B,{x:j.x+q,y:j.y+W})}L.push(P.sid)}}return L}const u4=600;function Jg(e,n){return!(e.exitAt!=null&&n-e.exitAt>u4||e.kind==="root"&&e.state==="done"&&e.tools.length===0&&e.endedAt!=null&&e.endedAt-e.startedAt<3e3)}function c4(e,n){const r=new Set;for(const s of e.agents.values())Jg(s,n)&&r.add(s.id);return r}function d4(e,n,r=0){return e.right+r>n.left&&e.left-r<n.right&&e.bottom+r>n.top&&e.top-r<n.bottom}function f4(e,n,r=0){if(!e)return!1;for(const s of n)if(d4(e,s,r))return!0;return!1}const PC="sessionGroup";function h4(e,n){var s;if(e.type===PC)return"transparent";const r=(s=e.data)==null?void 0:s.state;return n(r==="err"?"--err":r==="active"?"--inflight":"--ok")}const p4="Update checks are off (AGENTS_DECK_NO_UPDATE_CHECK=1).";function m4(e){if(e.checkDisabled)return p4;if(e.checking)return"Asking npm for the newest release…";const n=e.latest?`npm has v${e.latest}`:e.latestPending?`npm's latest tag names v${e.latestPending}, which it cannot serve yet`:"npm not reached yet",r=e.checkedAgo?` · checked ${e.checkedAgo}`:"";return`${n}${r} · re-checked periodically · click to check npm now`}function g4(e){const n=`Version v${e.running}`;return e.checkDisabled?`${n}, update checks are off`:e.checking?`${n}, checking npm for a newer release`:`${n}, check npm for a newer release`}function Uo(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}function v4(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}const y4={agent:HP,sessionGroup:nO},w4=420,Ml=18,x4=9e4,_4=200,S4=5*6e4,b4=6,k4=2*6e4,zv="agent-dag.layout",Bv="agent-dag.viewport",OC="agent-dag.summariesDismissed",LC="agent-dag.sessionListOpen",qC="agent-dag.detailOpen",$C="agent-dag.usagePanelOpen",zk="agent-dag.accountsPanelOpen",Bk="agent-dag.versionNoticeDismissed",E4=15*6e4,Uk={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:"};function N4(e){const n=Math.max(0,Math.floor(e/1e3));return n<60?"just now":n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:`${Math.floor(n/86400)}d ago`}const Hk="agent-dag.autoRestart",Wk="agent-dag.bundleReloadedFor";function C4(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(LC)==="1"}catch{return!1}}function T4(e){if(!(typeof window>"u"))try{window.localStorage.setItem(LC,e?"1":"0")}catch{}}function R4(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(qC)==="1"}catch{return!1}}function j4(e){if(!(typeof window>"u"))try{window.localStorage.setItem(qC,e?"1":"0")}catch{}}function A4(){if(typeof window>"u")return!0;const e=window.localStorage.getItem($C);try{return e===null?!0:e==="1"}catch{return!0}}function I4(e){if(!(typeof window>"u"))try{window.localStorage.setItem($C,e?"1":"0")}catch{}}function M4(){if(typeof window>"u")return new Set;try{const e=window.localStorage.getItem(OC);if(!e)return new Set;const n=JSON.parse(e);return new Set(Array.isArray(n)?n.filter(r=>typeof r=="string"):[])}catch{return new Set}}function Vk(e){if(!(typeof window>"u"))try{const n=Array.from(e),r=n.length>200?n.slice(-200):n;window.localStorage.setItem(OC,JSON.stringify(r))}catch{}}function P4(){const e={positions:[],pins:[]};if(typeof window>"u")return e;try{const n=window.localStorage.getItem(zv);if(!n)return e;const r=JSON.parse(n);if(!("v"in r)){const o=Object.entries(r).filter(([,l])=>l&&typeof l.x=="number"&&typeof l.y=="number");return{positions:o,pins:o.map(([l])=>l)}}return{positions:Object.entries(r.positions??{}).filter(([,o])=>o&&typeof o.x=="number"&&typeof o.y=="number"),pins:Array.isArray(r.pins)?r.pins:[]}}catch{return e}}function Ig(e,n){if(!(typeof window>"u"))try{const r={};for(const[s,o]of e)r[s]=o;for(const[s,o]of n)r[s]=o;window.localStorage.setItem(zv,JSON.stringify({v:2,positions:r,pins:Array.from(n.keys())}))}catch{}}function O4(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Bv);if(!e)return null;const n=JSON.parse(e);return typeof(n==null?void 0:n.x)!="number"||typeof(n==null?void 0:n.y)!="number"||typeof(n==null?void 0:n.zoom)!="number"?null:n}catch{return null}}function L4(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Bv,JSON.stringify(e))}catch{}}function Gk(){if(!(typeof window>"u")){try{window.localStorage.removeItem(zv)}catch{}try{window.localStorage.removeItem(Bv)}catch{}}}function q4(e,n){const r=e.agents.get(n);if(!r)return;const s=[];for(const f of e.agents.values())f.sessionId===n&&s.push(f);const o={schemaVersion:1,exportedAt:new Date().toISOString(),sessionId:n,label:r.label,cwd:r.cwd,startedAt:r.startedAt,endedAt:r.endedAt,model:r.model,agents:s.map(f=>({id:f.id,kind:f.kind,label:f.label,parentId:f.parentId,state:f.state,startedAt:f.startedAt,endedAt:f.endedAt,model:f.model,cwd:f.cwd,usage:f.usage,prompts:f.prompts,tools:f.tools.map(m=>({id:m.id,name:m.name,inputPreview:m.inputPreview,startedAt:m.startedAt,endedAt:m.endedAt,ok:m.ok,errorPreview:m.errorPreview,usage:m.usage}))}))},l=JSON.stringify(o,null,2),u=new Blob([l],{type:"application/json"}),c=URL.createObjectURL(u),p=document.createElement("a"),h=(r.label||"session").replace(/[^a-z0-9._-]/gi,"_");p.href=c,p.download=`agents-deck-${h}-${n.slice(0,8)}.json`,document.body.appendChild(p),p.click(),document.body.removeChild(p),setTimeout(()=>URL.revokeObjectURL(c),1e3)}const ev={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},tv={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},$4={Read:"file",Write:"file",Edit:"file",MultiEdit:"file",Glob:"file",Grep:"file",LS:"file",NotebookEdit:"file",Bash:"shell",PowerShell:"shell",shell:"shell",exec_command:"shell",shell_command:"shell",write_stdin:"shell",wait:"shell",apply_patch:"file",update_plan:"task",WebFetch:"web",WebSearch:"web",Task:"agent",Agent:"agent",TodoWrite:"task",TaskCreate:"task",TaskUpdate:"task",TaskList:"task",TaskGet:"task",TaskOutput:"task",TaskStop:"task",EnterPlanMode:"plan",ExitPlanMode:"plan",AskUserQuestion:"plan",Skill:"plan",Workflow:"plan"};function DC(e){return e.startsWith("mcp__")?"mcp":$4[e]??"other"}function FC(e,n){var s,o,l;if(!n)return!0;const r=n.toLowerCase();if(e.label.toLowerCase().includes(r)||(s=e.cwd)!=null&&s.toLowerCase().includes(r)||(o=e.cwdBasename)!=null&&o.toLowerCase().includes(r)||e.sessionId.toLowerCase().includes(r)||(l=e.firstPrompt)!=null&&l.toLowerCase().includes(r))return!0;for(const u of e.tools)if(u.name.toLowerCase().includes(r))return!0;return!1}function D4(e,n){if(!n)return null;const r=new Set([n]);let s=n;for(;s;){const l=e.agents.get(s);if(!(l!=null&&l.parentId)||r.has(l.parentId))break;r.add(l.parentId),s=l.parentId}let o=!0;for(;o;){o=!1;for(const l of e.agents.values())l.parentId&&r.has(l.parentId)&&!r.has(l.id)&&(r.add(l.id),o=!0)}return r}function F4(e,n,r,s,o,l,u,c,p,h,f,m,y,x,C,_,S,b){const E=[],N=[],T=new Set;if(l)for(const q of e.agents.values())FC(q,l)&&T.add(q.id);for(const q of e.agents.values()){if(!S.has(q.id))continue;const W=l?!T.has(q.id):!1,B=q.exitAt!=null,j=_!=null&&!_.has(q.id),K=[W?"rf-dim":"",B?"rf-exiting":"",j?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,U=u.get(q.id);if(E.push({id:q.id,type:"agent",position:{x:0,y:0},data:{...q,now:n,dim:W,onOpenContext:b},className:K,...U?{width:U.width,height:U.height}:null}),q.parentId&&S.has(q.parentId)){const ee=_v(q.sessionId),J=q.state==="active"?`hsl(${ee} 80% 72%)`:`hsl(${ee} 50% 55%)`,F=l&&!T.has(q.id)&&!T.has(q.parentId),Y=B,k=C.size>0&&(C.has(q.id)||C.has(q.parentId)),$=_!=null&&!_.has(q.id)&&!_.has(q.parentId),se=q.state==="active"?2:1.5,D=k?se+1.5:se,Q=F||Y?.2:$?.12:1,te=[Y?"rf-edge-exiting":"",k?"rf-edge-selected":""].filter(Boolean).join(" ")||void 0;N.push({id:`e:${q.parentId}->${q.id}`,source:q.parentId,target:q.id,animated:(q.state==="active"||k)&&!F&&!Y,type:"smoothstep",style:{stroke:J,strokeWidth:D,opacity:Q,transition:"opacity 500ms ease, stroke-width 200ms ease"},className:te})}}const I=new Map;for(const q of e.agents.values())q.tools.length>0&&I.set(q.id,Math.min(4,q.tools.length));const M=`${y}#lanes:${r4(I)}`,O=E.filter(q=>!o.has(q.id)&&!m.has(q.id));if(O.length>0||M!==x.current){if(O.length>0){const q=s4(E,N,{direction:"LR",pinned:o,measured:u,availableWidth:r,availableHeight:s,lanes:I});for(const W of q)m.has(W.id)||m.set(W.id,W.position);a4(E,m,o,u,new Set(O.map(W=>W.id)),I)}o4(E,m,o,u,I),x.current=M}const H=l4(E,m,o,u,c,!h||f,I);H.length>0&&p(H),hd(m,e.agents),hd(o,e.agents),hd(u,C3(e.agents.values()));const L=[];let P=!1;for(const q of E){let W=o.get(q.id)??m.get(q.id);W||(W={x:0,y:0},m.set(q.id,W),P=!0),L.push({...q,position:W})}return P&&(x.current=""),{nodes:L,edges:N}}function z4(){return g.jsx(wv,{children:g.jsx(B4,{})})}function B4(){var Ri,hs,fo,zn;const e=ca(),n=A.useRef(Kg()),[,r]=A.useState(0),s=A.useCallback(()=>r(V=>V+1),[]),[o,l]=A.useState(()=>new Set),[u,c]=A.useState(null),[p,h]=A.useState(null),f=A.useCallback((V,X)=>{l(oe=>{if(!X)return new Set([V]);const ue=new Set(oe);return ue.has(V)?ue.delete(V):ue.add(V),ue}),c(oe=>X&&oe===V?oe:V)},[]),m=A.useCallback(()=>{l(new Set),c(null)},[]),[y,x]=A.useState(null),[C,_]=A.useState(null),S=A.useCallback(V=>_(V),[]),b=A.useRef(M4()),[E,N]=A.useState(C4);A.useEffect(()=>{T4(E)},[E]);const[T,I]=A.useState(R4);A.useEffect(()=>{j4(T)},[T]);const[M,O]=A.useState(A4);A.useEffect(()=>{I4(M)},[M]);const[H,L]=A.useState(()=>{try{const V=window.localStorage.getItem(zk);return V===null?!0:V==="1"}catch{return!0}});A.useEffect(()=>{try{window.localStorage.setItem(zk,H?"1":"0")}catch{}},[H]);const[P,q]=A.useState(null),[W,B]=A.useState(!1),[j,K]=A.useState(0),[U,ee]=A.useState(0);A.useEffect(()=>{fetch("/api/sound-hook").then(V=>V.ok?V.json():null).then(V=>{V!=null&&V.ok&&(q(V.enabled===!0),K((V.foreign??[]).filter(X=>X.worksHere).length),ee(typeof V.parked=="number"?V.parked:0))}).catch(()=>{})},[]);const J=A.useCallback(async()=>{B(!0);try{const X=await(await fetch("/api/sound-hook",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!P})})).json().catch(()=>null);X!=null&&X.ok&&q(X.enabled===!0),fetch("/api/sound-hook").then(oe=>oe.ok?oe.json():null).then(oe=>{oe!=null&&oe.ok&&(K((oe.foreign??[]).filter(ue=>ue.worksHere).length),ee(typeof oe.parked=="number"?oe.parked:0))}).catch(()=>{})}catch{}finally{B(!1)}},[P]),[F,Y]=A.useState(!1),[k,$]=A.useState(null),[se,D]=A.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(Bk)??""}catch{return""}}),[Q,te]=A.useState(!1),ae=A.useRef(0),[ce,me]=A.useState(!1),ge=A.useCallback((V=!1)=>{V&&(ae.current=Date.now(),me(!0)),fetch(V?"/api/version?refresh=1":"/api/version").then(X=>X.ok?X.json():null).then(X=>{X&&$(X)}).catch(()=>{}).finally(()=>{V&&me(!1)})},[]),Pe=A.useCallback(()=>{ge(Date.now()-ae.current>=E4)},[ge]);A.useEffect(()=>{ge();const V=window.setInterval(Pe,5*6e4),X=()=>{document.visibilityState==="visible"&&Pe()};return document.addEventListener("visibilitychange",X),()=>{window.clearInterval(V),document.removeEventListener("visibilitychange",X)}},[ge,Pe]),A.useEffect(()=>{F&&ge()},[F,ge]);const Se=(k==null?void 0:k.notice)??null,Oe=Se?`${Se.kind}:${Se.to}`:"",Me=Se!=null&&se!==Oe,be=A.useCallback(()=>{if(!Se)return;const V=se===Oe?"":Oe;D(V);try{window.localStorage.setItem(Bk,V)}catch{}},[Se,Oe,se]),De=((Ri=k==null?void 0:k.upgrade)==null?void 0:Ri.state)??"idle",ve=w3(k==null?void 0:k.upgrade),we=A.useCallback(async()=>{try{await fetch("/api/upgrade",{method:"POST"})}catch{}ge()},[ge]);A.useEffect(()=>{if(De!=="running")return;const V=window.setInterval(ge,3e3);return()=>window.clearInterval(V)},[De,ge]);const Ue=A.useCallback(async()=>{var oe;const V=k==null?void 0:k.command;if(!V)return;let X=!1;try{X=await Promise.race([((oe=navigator.clipboard)==null?void 0:oe.writeText(V).then(()=>!0))??Promise.resolve(!1),new Promise(ue=>window.setTimeout(()=>ue(!1),500))])}catch{X=!1}if(!X)try{const ue=document.createElement("textarea");ue.value=V,ue.setAttribute("readonly",""),ue.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(ue),ue.select(),X=document.execCommand("copy"),ue.remove()}catch{X=!1}X&&(te(!0),window.setTimeout(()=>te(!1),1600))},[k==null?void 0:k.command]),ut=A.useCallback(()=>{N(V=>(V||L(!1),!V))},[]),ct=A.useCallback(()=>{L(V=>(V||N(!1),!V))},[]),[Ze,Fe]=A.useState(!1),[Je,dt]=A.useState(0),Nt=A.useRef(null),[ot,gt]=A.useState(!1),Ct=A.useRef(null),[Ft,Xe]=A.useState(0),vt=A.useRef(A3()),[ft,wt]=A.useState(!1),fn=A.useCallback(()=>{const V=vt.current,X=V.setPaused(!V.paused);for(const oe of X)n.current=ix(n.current,oe);wt(V.paused)},[]),[Ye,zt]=A.useState(Date.now()),[Gt,pr]=A.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Hk)!=="0"}catch{return!0}}),In=A.useCallback(()=>{pr(V=>{const X=!V;try{window.localStorage.setItem(Hk,X?"1":"0")}catch{}return X})},[]),[Tt,Qt]=A.useState(!1),[vn,ts]=A.useState("restart"),[pi,mi]=A.useState(null),Mn=A.useRef(!1),Lr=A.useRef(null),gi=A.useRef(0),yn=A.useCallback(async V=>{if(Mn.current)return;const X=(V==null?void 0:V.upgrade)===!0;Mn.current=!0,Lr.current=ve;const oe=++gi.current;ts(X?"npx":"restart"),Qt(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(Se==null?void 0:Se.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:X})})}catch{}window.setTimeout(()=>{if(gi.current===oe&&Mn.current){Mn.current=!1,Qt(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},X?18e4:3e4)},[Se==null?void 0:Se.to,ve]),qr=A.useRef(null);A.useEffect(()=>{let V=!1;for(const oe of n.current.agents.values())if(oe.state==="active"){V=!0;break}const X=_3({enabled:Gt,kind:Se==null?void 0:Se.kind,canRestart:(k==null?void 0:k.canRestart)===!0,busy:V,idleSince:qr.current,now:Ye});qr.current=X.idleSince,X.restart&&yn()},[Gt,Se==null?void 0:Se.kind,k==null?void 0:k.canRestart,Ye,yn]),A.useEffect(()=>{let V=null;try{V=window.sessionStorage.getItem(Wk)}catch{return}if(y3({bundle:"1.33.95",running:k==null?void 0:k.running,lastTried:V})){try{window.sessionStorage.setItem(Wk,(k==null?void 0:k.running)??"")}catch{return}window.location.reload()}},[k==null?void 0:k.running]),A.useEffect(()=>{const V=k==null?void 0:k.running;if(!V)return;let X=null;try{X=window.sessionStorage.getItem("agent-dag.restartPending")}catch{return}if(X==null||X&&X!==V)return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Mn.current=!1,Qt(!1),mi(V);const oe=window.setTimeout(()=>mi(null),6e3);return()=>window.clearTimeout(oe)},[k==null?void 0:k.running]),A.useEffect(()=>{if(Tt&&x3({asked:Lr.current,reported:ve})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Mn.current=!1,Qt(!1)}},[Tt,ve]);const Pn=A.useRef(P4()).current;A.useRef(!1);const Ot=A.useRef(new Map(Pn.positions.filter(([V])=>Pn.pins.includes(V)))),wn=A.useRef(null),On=A.useState(()=>O4())[0],[Zt,$r]=A.useState(""),[ns,so]=A.useState(()=>new Set),[nr,xn]=A.useState(()=>typeof window>"u"?"dark":window.localStorage.getItem("agent-dag.theme")??"dark"),[vi,rs]=A.useState(!1),is=A.useRef(null);A.useEffect(()=>{document.documentElement.dataset.theme=nr;try{window.localStorage.setItem("agent-dag.theme",nr)}catch{}},[nr]),A.useEffect(()=>{if(!On)return;const V=window.setTimeout(()=>{try{e.setViewport(On,{duration:0})}catch{}},60);return()=>window.clearTimeout(V)},[e,On]);const yi=A.useRef(!0);A.useEffect(()=>{const V=new EventSource("/events"),X=j3(s,{now:()=>Date.now(),setTimeout:(oe,ue)=>window.setTimeout(oe,ue),clearTimeout:oe=>window.clearTimeout(oe)});return V.addEventListener("open",()=>{Y(!0),rs(!0)}),V.addEventListener("error",()=>Y(!1)),V.addEventListener("replay-end",()=>{yi.current=!1,X.flush()}),V.addEventListener("hook",oe=>{try{const ue=JSON.parse(oe.data);if(!vt.current.accept(ue))return;n.current=ix(n.current,ue),ue.replay===!0||yi.current||Date.now()-ue.receivedAt>3e4?X.replay():X.live()}catch{}}),()=>{V.close(),X.cancel()}},[s]),A.useEffect(()=>{const V=setInterval(()=>{const X=Date.now();zt(X);let oe=jP(n.current,X,x4);TP(n.current,X,_4,S4)&&(oe=!0),RP(n.current,X,b4,k4)&&(oe=!0),oe&&s()},250);return()=>clearInterval(V)},[s]);const Dr=A.useRef(null),Ln=A.useRef(0),ss=420,Yt=A.useCallback((V=500)=>{try{const ke=document.querySelector(".canvas-wrap"),Ne=Array.from(document.querySelectorAll(".react-flow__node")).filter(ht=>ht.offsetWidth>0);if(!ke||Ne.length===0)return;const Le=ke.getBoundingClientRect(),We=e.getViewport();if(!Number.isFinite(We.zoom)||We.zoom<=0)return;const Ve=ht=>(ht-Le.left-We.x)/We.zoom,rt=ht=>(ht-Le.top-We.y)/We.zoom,tn=Ne.map(ht=>ht.getBoundingClientRect()),yr=Math.min(...tn.map(ht=>Ve(ht.left))),wr=Math.max(...tn.map(ht=>Ve(ht.right))),or=Math.min(...tn.map(ht=>rt(ht.top))),ps=Math.max(...tn.map(ht=>rt(ht.bottom))),Sa=wr-yr,ms=ps-or;if(!(Sa>0&&ms>0))return;const Bn=Math.max(.2,Math.min(1,(Le.width-160)/(Sa+ss)*.86,(Le.height-160)/ms*.86));e.setViewport({x:80-yr*Bn,y:Math.max(80,(Le.height-ms*Bn)/2)-or*Bn,zoom:Bn},{duration:V}),Ln.current=Date.now(),window.setTimeout(()=>{try{const ht={x:80-yr*Bn,y:Math.max(80,(Le.height-ms*Bn)/2)-or*Bn,zoom:Bn},ba=e.getViewport();(Math.abs(ba.zoom-Bn)>.01||Math.abs(ba.x-ht.x)>2)&&e.setViewport(ht,{duration:0})}catch{}},V+60)}catch{}},[e]),wi=A.useRef(""),Qe=A.useRef(null),os=A.useRef(0),rr=A.useCallback(()=>{os.current=Date.now()},[]),Fr="agent-dag.autoFitDisabled",Jt=A.useRef((()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Fr)==="1"}catch{return!1}})()),[xi,_i]=A.useState(Jt.current),mr=A.useCallback(()=>{if(!Jt.current){Jt.current=!0,_i(!0);try{window.localStorage.setItem(Fr,"1")}catch{}}},[]),en=A.useCallback(()=>{Jt.current=!1,_i(!1);try{window.localStorage.removeItem(Fr)}catch{}Yt(400)},[e,Yt]);A.useEffect(()=>{const V=setInterval(()=>{if(Jt.current||Date.now()-os.current<800)return;const X=n.current,oe=Date.now(),ue=[];for(const Ve of X.agents.values())Jg(Ve,oe)&&ue.push({id:Ve.id});if(ue.length===0)return;const ye=e.getViewport(),ke=window.innerWidth-360,Ne=window.innerHeight-52;let Le=!1,We=!1;for(const{id:Ve}of ue){const rt=Rt.current.get(Ve),tn=Ot.current.get(Ve)??jt.current.get(Ve);if(!rt||!tn)continue;We=!0;const yr=tn.x*ye.zoom+ye.x,wr=tn.y*ye.zoom+ye.y,or=(tn.x+rt.width)*ye.zoom+ye.x,ps=(tn.y+rt.height)*ye.zoom+ye.y;if(or>0&&yr<ke&&ps>0&&wr<Ne){Le=!0;break}}We&&!Le&&Yt(600)},1500);return()=>clearInterval(V)},[e]);const gr=A.useRef(!1),Rt=A.useRef(new Map),va=A.useRef(0),Su=A.useCallback(V=>{const X=Rt.current;let oe=!1;for(const ue of V.nodeInternals.values()){const ye=ue.width,ke=ue.height;if(ye==null||ke==null)continue;const Ne=X.get(ue.id);Ne?(Math.abs(Ne.height-ke)>4||Math.abs(Ne.width-ye)>4)&&(X.set(ue.id,{width:ye,height:ke}),oe=!0):(X.set(ue.id,{width:ye,height:ke}),oe=!0)}return oe&&(va.current+=1),va.current},[]),ya=Ke(Su),[Si,as]=A.useState(0);A.useEffect(()=>{let V=0;const X=()=>{const ue=Rt.current;let ye=!1;for(const ke of document.querySelectorAll(".react-flow__node[data-id]")){const Ne=ke.getAttribute("data-id");if(!Ne)continue;const Le=ke.offsetWidth,We=ke.offsetHeight;if(!Le||!We)continue;const Ve=ue.get(Ne);(!Ve||Math.abs(Ve.width-Le)>4||Math.abs(Ve.height-We)>4)&&(ue.set(Ne,{width:Le,height:We}),ye=!0)}ye&&as(ke=>ke+1)};if(gr.current)return;let oe=0;return document.visibilityState==="hidden"?oe=window.setTimeout(X,32):V=requestAnimationFrame(X),()=>{cancelAnimationFrame(V),window.clearTimeout(oe)}});const jt=A.useRef(new Map(Pn.positions)),zr=A.useRef(""),Br=A.useMemo(()=>{const V=[];for(const X of n.current.agents.values())Jg(X,Ye)&&V.push(X.id+(X.parentId?`>${X.parentId}`:""));return V.sort(),`${V.join("|")}#sv${ya}.${Si}`},[n.current,n.current.lastSeq,Ye,ya,Si]),bi=A.useRef(null);A.useEffect(()=>(bi.current!=null&&window.clearTimeout(bi.current),bi.current=window.setTimeout(()=>{Ig(jt.current,Ot.current)},1500),()=>{bi.current!=null&&window.clearTimeout(bi.current)}),[Br]),A.useEffect(()=>{if(wi.current===Br)return;const V=wi.current;if(wi.current=Br,!V||Jt.current)return;Date.now()-Ln.current>1200&&Yt(400),Dr.current&&window.clearTimeout(Dr.current),Dr.current=window.setTimeout(()=>{Jt.current||Yt(500)},280)},[Br,e,Yt]);const ki=A.useMemo(()=>{if(o.size===0)return null;const V=new Set;for(const X of o){const oe=D4(n.current,X);if(oe)for(const ue of oe)V.add(ue)}return V.size>0?V:null},[n.current,n.current.lastSeq,o]),ls=A.useMemo(()=>c4(n.current,Ye),[n.current,n.current.lastSeq,Ye]),us=A.useRef(null),[ir,wa]=A.useState({w:0,h:0});A.useEffect(()=>{const V=us.current;if(!V||typeof ResizeObserver>"u")return;const X=new ResizeObserver(oe=>{var ye;const ue=(ye=oe[0])==null?void 0:ye.contentRect;ue&&wa(ke=>Math.abs(ke.w-ue.width)>40||Math.abs(ke.h-ue.height)>40?{w:ue.width,h:ue.height}:ke)});return X.observe(V),wa({w:V.clientWidth,h:V.clientHeight}),()=>X.disconnect()},[]);const oo=A.useRef(new Map),[He,xa]=A.useState(!1);A.useEffect(()=>{const V=window.setTimeout(()=>xa(!0),2500);return()=>window.clearTimeout(V)},[]);const[_a,Ei]=A.useState(!1),qn=A.useRef(null),[cs,ao]=A.useState(!1),lo=A.useCallback(()=>{qn.current&&(window.clearTimeout(qn.current),qn.current=null),Ei(!1)},[]),ds=A.useCallback(V=>{V.length!==0&&queueMicrotask(()=>{Ei(!0),qn.current&&window.clearTimeout(qn.current),qn.current=window.setTimeout(()=>Ei(!1),w4+80)})},[]);A.useEffect(()=>()=>{qn.current&&window.clearTimeout(qn.current)},[]);const $n=ir.w>0?ir.w*.92:0,Dn=ir.h>0?ir.h:0,{nodes:At,edges:Ni}=A.useMemo(()=>F4(n.current,Ye,$n,Dn,Ot.current,Zt,Rt.current,oo.current,ds,He,cs,jt.current,Br,zr,o,ki,ls,S),[n.current,n.current.lastSeq,Ye,$n,Dn,He,cs,Zt,Br,o,ki,ls,S,Je]),Ur=A.useMemo(()=>{const V=new Map;for(const oe of At){const ue=oe.data;if(!(ue!=null&&ue.sessionId)||ue.exitAt!=null)continue;const ye=oe.width,ke=oe.height;if(ye==null||ke==null)continue;const Ne=oe.position.x,Le=oe.position.y,We=Ne+ye,Ve=Le+ke,rt=V.get(ue.sessionId);rt?(rt.minX=Math.min(rt.minX,Ne),rt.minY=Math.min(rt.minY,Le),rt.maxX=Math.max(rt.maxX,We),rt.maxY=Math.max(rt.maxY,Ve)):V.set(ue.sessionId,{minX:Ne,minY:Le,maxX:We,maxY:Ve})}const X=[];for(const[oe,ue]of V){const ye=ue.maxX-ue.minX+Ml*2,ke=ue.maxY-ue.minY+Ml*2;X.push({id:`group:${oe}`,type:PC,position:{x:ue.minX-Ml,y:ue.minY-Ml},data:{sessionId:oe,w:ye,h:ke},width:ye,height:ke,style:{width:ye,height:ke},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return X},[At,Ye]),sr=A.useMemo(()=>{const V=[...Ur,...At],X=Ct.current;return!X||X.size===0?V:V.map(oe=>{const ue=X.get(oe.id);return ue?{...oe,position:ue}:oe})},[Ur,At,Ft]),bu=A.useMemo(()=>{if(!Zt)return null;const V=new Set;for(const X of n.current.agents.values())FC(X,Zt)&&V.add(X.id);return V},[n.current,n.current.lastSeq,Zt]),Ci=A.useMemo(()=>{const V=new Set;for(const X of n.current.agents.values())for(const oe of X.tools)V.add(DC(oe.name));return Object.keys(ev).filter(X=>V.has(X))},[n.current,n.current.lastSeq]);A.useEffect(()=>{if(Ci.length<=1){gt(!1);return}let V=0;const X=()=>{const oe=Nt.current;if(oe&&!document.hidden){const ue=oe.getBoundingClientRect(),ye=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Ne=>Ne.getBoundingClientRect()),ke=f4(ue,ye,8);gt(Ne=>Ne===ke?Ne:ke)}V=window.setTimeout(X,300)};return X(),()=>window.clearTimeout(V)},[Ci.length]);const Fn=A.useMemo(()=>{const V=new Map;for(const oe of n.current.agents.values())for(const ue of oe.tools){if(!ue.name.startsWith("mcp__"))continue;const ye=ue.name.slice(5),ke=ye.indexOf("__"),Ne=ke>0?ye.slice(0,ke):ye;V.set(Ne,(V.get(Ne)??0)+1)}const X=[];for(const[oe,ue]of V){let ye=5381;for(let ke=0;ke<oe.length;ke++)ye=(ye<<5)+ye^oe.charCodeAt(ke);X.push({server:oe,count:ue,hue:Math.abs(ye)%360})}return X.sort((oe,ue)=>ue.count-oe.count),X},[n.current,n.current.lastSeq]),ku=A.useCallback(V=>{so(X=>{const oe=new Set(X);return oe.has(V)?oe.delete(V):oe.add(V),oe})},[]),Lt=u?n.current.agents.get(u):null,Ti=p?Array.from(n.current.agents.values()).flatMap(V=>V.tools).find(V=>V.id===p)??null:null,fs=A.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}n.current=Kg(),Ot.current.clear(),Rt.current.clear(),jt.current.clear(),zr.current="",Gk(),m(),s()},[s,m]),uo=A.useCallback(()=>{Ot.current.clear(),jt.current.clear(),zr.current="",Gk(),s(),window.setTimeout(()=>Yt(500),80)},[s,e,Yt]),Hr=A.useCallback(()=>Yt(500),[Yt]),Wr=A.useRef(At);Wr.current=At;const vr=A.useRef(u);vr.current=u;const Vr=A.useCallback(V=>{const X=Wr.current;if(X.length===0)return;const oe=X.slice().sort((Le,We)=>Le.position.y-We.position.y||Le.position.x-We.position.x),ue=vr.current,ye=ue?oe.findIndex(Le=>Le.id===ue):-1;let ke;ye===-1?ke=V===1?0:oe.length-1:ke=(ye+V+oe.length)%oe.length;const Ne=oe[ke];Ne&&(f(Ne.id,!1),window.setTimeout(()=>{try{e.fitView({padding:.35,duration:350,nodes:[Ne]})}catch{}Ln.current=Date.now()},30))},[f,e]);A.useEffect(()=>{const V=X=>{var ye,ke;const oe=X.target,ue={tagName:oe==null?void 0:oe.tagName,isContentEditable:oe==null?void 0:oe.isContentEditable,role:(ye=oe==null?void 0:oe.getAttribute)==null?void 0:ye.call(oe,"role"),type:oe==null?void 0:oe.type};if(X.key==="Escape"){MN(ue)?oe==null||oe.blur():m();return}if(!N3(ue)&&!S3(X)){if(X.key==="/"){X.preventDefault(),(ke=is.current)==null||ke.focus();return}X.key===" "&&(X.preventDefault(),fn()),(X.key==="c"||X.key==="C")&&fs(),(X.key==="r"||X.key==="R")&&uo(),(X.key==="f"||X.key==="F")&&Hr(),(X.key==="l"||X.key==="L")&&ut(),(X.key==="h"||X.key==="H")&&Fe(Ne=>!Ne),(X.key==="u"||X.key==="U")&&O(Ne=>!Ne),(X.key==="a"||X.key==="A")&&ct(),(X.key==="j"||X.key==="J")&&Vr(1),(X.key==="k"||X.key==="K")&&Vr(-1),(X.key==="t"||X.key==="T")&&xn(Ne=>Ne==="dark"?"light":"dark")}};return window.addEventListener("keydown",V),()=>window.removeEventListener("keydown",V)},[fs,uo,Hr,m,Vr,fn]);const co=n.current.agents.size,Eu=new Set(Array.from(n.current.agents.values()).map(V=>V.sessionId)).size,Bt=A.useMemo(()=>{let V=0,X=0,oe=0,ue=0,ye=0,ke=0,Ne=0,Le=0,We=0;for(const Ve of n.current.agents.values()){V+=Ve.usage.inputTokens,X+=Ve.usage.outputTokens,oe+=Ve.usage.cacheReadTokens,ue+=Ve.usage.cacheCreateTokens;const rt=cn(Ve.usage,Ve.model);ye+=rt.total,ke+=rt.input,Ne+=rt.output,Le+=rt.cacheRead,We+=rt.cacheWrite}return{inT:V,outT:X,cacheR:oe,cacheC:ue,sum:V+X,cost:{total:ye,input:ke,output:Ne,cacheRead:Le,cacheWrite:We}}},[n.current,n.current.lastSeq]);return g.jsxs("div",{className:"app",children:[g.jsxs("header",{className:"topbar",children:[g.jsxs("div",{className:"brand",children:[g.jsx("span",{className:"logo"}),"agents-deck",Se?g.jsxs("button",{type:"button",className:"v stale",onClick:be,title:Se.kind==="restart"?`Running v${Se.from}; v${Se.to} is installed on disk. Restart to pick it up.`:`Running v${Se.from}; v${Se.to} is on npm.`,children:["v",Se.from,g.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const V={running:(k==null?void 0:k.running)??"1.33.95",latest:k==null?void 0:k.latest,latestPending:k==null?void 0:k.latestPending,checkedAgo:k!=null&&k.checkedAt?N4(Ye-k.checkedAt):null,checkDisabled:k==null?void 0:k.checkDisabled,checking:ce};return g.jsxs("button",{type:"button",className:ce?"v checking":"v",onClick:()=>ge(!0),"aria-busy":ce||void 0,"aria-label":g4(V),title:m4(V),children:["v",V.running]})})()]}),Lt&&(()=>{const V=cn(Lt.usage,Lt.model),X=Math.max(0,((Lt.endedAt??Ye)-Lt.startedAt)/1e3),oe=Lt.state==="active"?Yl(V.total,X):null,ue=o.size-1;return g.jsxs("button",{type:"button",className:"selected-ribbon",title:`Fit view to ${Lt.label}`,onClick:()=>{try{const ye=At.find(ke=>ke.id===Lt.id);ye&&e.fitView({padding:.35,duration:500,nodes:[ye]}),Ln.current=Date.now()}catch{}},children:[g.jsx("span",{className:`state-pill state-${Lt.state}`,children:Lt.state==="active"?"live":Lt.state}),g.jsx("span",{className:"selected-label",children:Lt.label}),V.total>0&&g.jsxs("span",{className:"selected-cost",children:[ze(V.total),oe?g.jsxs("span",{className:"selected-rate",children:[" · ",oe]}):null]}),ue>0&&g.jsxs("span",{className:"selected-extra",children:["+",ue]}),g.jsx("span",{role:"button","aria-label":"Deselect",className:"selected-close",onClick:ye=>{ye.stopPropagation(),m()},children:"×"})]})})(),g.jsxs("div",{className:"actions",children:[g.jsxs("div",{className:"search",children:[g.jsx("span",{className:"search-icon","aria-hidden":!0,children:"⌕"}),g.jsx("input",{ref:is,type:"text",placeholder:"Search agents, cwd, tools…",value:Zt,onChange:V=>$r(V.target.value),spellCheck:!1,"aria-label":"Filter the graph"}),Zt?g.jsx("button",{className:"search-clear","aria-label":"Clear search",onClick:()=>$r(""),children:"×"}):g.jsx("kbd",{className:"search-kbd","aria-hidden":!0,children:"/"})]}),g.jsxs("span",{className:"status",role:"status",children:[g.jsx("span",{className:`pill ${F?"live":"dead"}`,title:F?"Receiving events":"SSE disconnected",children:F?"live":"offline"}),g.jsxs("span",{className:"stat",title:"Distinct CC sessions",children:[g.jsx("span",{className:"count",children:Eu}),g.jsx("span",{className:"lbl",children:"sessions"})]}),g.jsxs("span",{className:"stat",title:"Total agents (root + subagents)",children:[g.jsx("span",{className:"count",children:co}),g.jsx("span",{className:"lbl",children:"agents"})]}),g.jsxs("span",{className:"stat",title:"Total hook events received",children:[g.jsx("span",{className:"count",children:n.current.totalEvents}),g.jsx("span",{className:"lbl",children:"events"})]}),Bt.sum>0&&g.jsxs("span",{className:"stat",title:`in:${Bt.inT.toLocaleString()} out:${Bt.outT.toLocaleString()} cache-r:${Bt.cacheR.toLocaleString()} cache-c:${Bt.cacheC.toLocaleString()}`,children:[g.jsx("span",{className:"count",children:v4(Bt.sum)}),g.jsx("span",{className:"lbl",children:"tokens"})]}),Fn.length>0&&g.jsxs("span",{className:"stat mcp-legend",title:`MCP servers seen this session:
59
+ burn: ${y}`:"");return g.jsxs("span",{className:"cost-meta",title:x,children:[g.jsx("b",{children:ze(f.total)}),y&&g.jsx("span",{className:"cost-rate",children:y})]})})()]}),g.jsx(Zs,{type:"source",position:Re.Right,style:{background:"transparent",border:"none"}})]})}function WP({state:e}){const n=e==="active"?"live":e==="done"?"done":"err";return g.jsx("span",{className:`state-pill state-${e}`,children:n})}function VP(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function GP({tools:e,now:n}){const l=new Array(24).fill(0);let u=0;for(const y of e){const x=n-y.startedAt;if(x<0||x>=6e4)continue;const C=23-Math.floor(x/2500);C>=0&&C<24&&(l[C]+=1,u+=1)}const c=Math.max(1,...l),p=132,h=14,f=p/24,m=c/(2500/1e3);return g.jsxs("div",{className:"tool-spark-row",title:`${u} tool calls in last 60s · peak ${m.toFixed(1)}/s`,children:[g.jsx("svg",{className:"tool-spark",width:p,height:h,viewBox:`0 0 ${p} ${h}`,"aria-hidden":!0,children:l.map((y,x)=>{const C=y===0?1.5:Math.max(1.5,y/c*h),_=x===23&&y>0,b=`tool-spark-bar${y>0?" active":""}${_?" latest":""}`;return g.jsx("rect",{x:x*f+.4,y:h-C,width:Math.max(.5,f-1),height:C,rx:.8,className:b},x)})}),g.jsx("span",{className:"tool-spark-label",children:"60s"})]})}function da(e){const n=e.match(/^claude[-_](opus|sonnet|haiku|fable|mythos)[-_](\d+(?:[-_.]\d+)*)/i);if(n){const o=n[1][0].toUpperCase()+n[1].slice(1).toLowerCase(),l=n[2].replace(/[-_]/g,".");return`${o} ${l}`}const r=e.match(/^gpt[-_](\d+(?:[-_.]\d+)*)[-_]codex\b/i);if(r)return`GPT-${r[1].replace(/[-_]/g,".")} Codex`;const s=e.match(/^gpt[-_](\d+(?:[-_.]\d+)*)/i);return s?`GPT-${s[1].replace(/[-_]/g,".")}`:e}function ox(e){if(e==null)return"(none)";if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function YP(e){if(e.endedAt==null)return"in-flight…";const n=e.endedAt-e.startedAt;return n<1e3?`${n}ms`:`${(n/1e3).toFixed(2)}s`}function KP({tool:e,onClose:n}){A.useEffect(()=>{const s=o=>{o.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]);const r=e.endedAt==null?"inflight":e.ok===!1?"err":"done";return g.jsx("div",{className:"modal-backdrop",onClick:n,role:"dialog","aria-modal":"true",children:g.jsxs("div",{className:"modal",onClick:s=>s.stopPropagation(),children:[g.jsxs("header",{className:"modal-head",children:[g.jsxs("div",{className:"modal-title",children:[g.jsx("span",{className:`status-dot ${r}`}),g.jsx("span",{className:"modal-tool-name",children:e.name}),g.jsxs("span",{className:"modal-tool-id",title:e.id,children:[e.id.slice(0,12),"…"]})]}),g.jsxs("div",{className:"modal-actions",children:[g.jsx("span",{className:"modal-dur",children:YP(e)}),g.jsx("button",{className:"btn icon-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]})]}),g.jsxs("section",{className:"modal-body",children:[e.trimmed&&g.jsx("div",{className:"modal-section",children:g.jsx("p",{className:"modal-note",children:"Full payloads for this call were released to keep memory bounded — only the previews below are still held."})}),g.jsxs("div",{className:"modal-section",children:[g.jsx("h4",{children:"Input"}),g.jsx("pre",{children:ox(e.input??e.inputPreview)})]}),g.jsxs("div",{className:"modal-section",children:[g.jsxs("h4",{children:["Response ",r==="err"&&g.jsx("span",{className:"err-tag",children:"error"})]}),g.jsx("pre",{children:e.endedAt==null?"(waiting…)":ox(e.response??e.errorPreview)})]})]})]})})}const Tl=18,ax=26,XP=12;function QP(e){return ZP(e.nodeInternals.values())}function ZP(e){const n=new Map;for(const o of e){if(o.type!=="agent")continue;const l=o.data;if(!(l!=null&&l.sessionId)||l.exitAt!=null||o.width==null||o.height==null)continue;const u=o.position.x,c=o.position.y,p=u+o.width,h=c+o.height,f=n.get(l.sessionId);f?(f.minX=Math.min(f.minX,u),f.minY=Math.min(f.minY,c),f.maxX=Math.max(f.maxX,p),f.maxY=Math.max(f.maxY,h),l.kind==="root"&&(f.label=lx(l)??f.label)):n.set(l.sessionId,{minX:u,minY:c,maxX:p,maxY:h,label:lx(l)??l.sessionId})}const r=new Map;for(const o of n.values())r.set(o.label,(r.get(o.label)??0)+1);const s=[];for(const[o,l]of n){const c=(r.get(l.label)??0)>1?`${l.label} · ${JP(o)}`:l.label;s.push({sessionId:o,label:c,x:l.minX-Tl,y:l.minY-Tl-ax,w:l.maxX-l.minX+Tl*2,h:l.maxY-l.minY+Tl*2+ax})}return s}function JP(e){const n=e.match(/[a-zA-Z0-9]{4}/);return n?n[0]:e.slice(0,4)}function lx(e){if(e.kind==="root")return e.label}function eO(){const{x:e,y:n,zoom:r}=pN(),s=ca(),o=Ke(QP,tO);if(o.length<=1)return null;const l=u=>{try{const c=s.getNodes().filter(p=>{const h=p.data;return(h==null?void 0:h.sessionId)===u});if(c.length===0)return;s.fitView({padding:.3,duration:500,nodes:c})}catch{}};return g.jsx("div",{className:"session-clusters",children:o.map(u=>{const c=_v(u.sessionId),p={position:"absolute",left:u.x*r+e,top:u.y*r+n,width:u.w*r,height:u.h*r,borderColor:`hsl(${c} 65% 55% / 0.32)`,background:`hsl(${c} 70% 50% / 0.04)`},h={position:"absolute",left:u.x*r+e+16*r,top:(u.y-XP)*r+n,color:`hsl(${c} 70% 78%)`,borderColor:`hsl(${c} 65% 55% / 0.5)`,transform:`scale(${Math.min(1,r)})`,transformOrigin:"left top"};return g.jsxs(le.Fragment,{children:[g.jsx("div",{className:"cluster-card",style:p,"aria-hidden":!0}),g.jsx("button",{type:"button",className:"cluster-label",style:h,title:`Fit view to ${u.label} · drag the wrapper to move the whole session`,onClick:()=>l(u.sessionId),children:u.label})]},u.sessionId)})})}function tO(e,n){if(e.length!==n.length)return!1;for(let r=0;r<e.length;r++){const s=e[r],o=n[r];if(s.sessionId!==o.sessionId||s.label!==o.label||s.x!==o.x||s.y!==o.y||s.w!==o.w||s.h!==o.h)return!1}return!0}function nO({data:e}){return g.jsx("div",{className:"session-group-handle",style:{width:(e==null?void 0:e.w)??0,height:(e==null?void 0:e.h)??0}})}const NN=600,rO=4,iO=36,Qg=16,sO=60,oO=6,ux=220,cx=96,aO=28,lO={Read:"file",Write:"file",Edit:"file",MultiEdit:"file",Glob:"file",Grep:"file",LS:"file",NotebookEdit:"file",Bash:"shell",PowerShell:"shell",shell:"shell",exec_command:"shell",shell_command:"shell",write_stdin:"shell",wait:"shell",apply_patch:"file",update_plan:"task",WebFetch:"web",WebSearch:"web",Task:"agent",Agent:"agent",TodoWrite:"task",TaskCreate:"task",TaskUpdate:"task",TaskList:"task",TaskGet:"task",TaskOutput:"task",TaskStop:"task",EnterPlanMode:"plan",ExitPlanMode:"plan",AskUserQuestion:"plan",Skill:"plan",Workflow:"plan",ScheduleWakeup:"other",CronCreate:"other",CronList:"other",CronDelete:"other",Monitor:"other",PushNotification:"other",RemoteTrigger:"other",ToolSearch:"other"};function uO(e){return e.startsWith("mcp__")?"mcp":lO[e]??"other"}const cO={Read:"📖",Write:"💾",Edit:"✏️",MultiEdit:"🔧",Glob:"🗺️",Grep:"🔎",Bash:"⚡",PowerShell:"💻",shell:"⚡",exec_command:"⚡",shell_command:"⚡",write_stdin:"💻",wait:"⏳",apply_patch:"🩹",update_plan:"📋",LS:"📂",Task:"🤖",Agent:"🤖",TodoWrite:"📋",TaskCreate:"📋",TaskUpdate:"📝",TaskList:"🗂️",TaskGet:"🗂️",TaskOutput:"📤",TaskStop:"🛑",WebFetch:"🌐",WebSearch:"🔭",ToolSearch:"🧰",NotebookEdit:"📓",EnterPlanMode:"🧭",ExitPlanMode:"🏁",AskUserQuestion:"❓",ScheduleWakeup:"⏰",CronCreate:"⏰",CronList:"📅",CronDelete:"🗑️",Skill:"🎯",Workflow:"🎬",Monitor:"📡",PushNotification:"🔔",RemoteTrigger:"📡"};function dx(e){return e.startsWith("mcp__")?"🔌":cO[e]??"✨"}const dO={git:"🐙",gh:"🐙",glab:"🐙",npm:"📦",pnpm:"📦",yarn:"📦",bun:"📦",brew:"🍺",node:"🟢",deno:"🟢",python:"🐍",python3:"🐍",py:"🐍",pip:"🐍",pip3:"🐍",uv:"🐍",ruby:"💎",bundle:"💎",gem:"💎",cargo:"🦀",rustc:"🦀",rustup:"🦀",go:"🐹",docker:"🐳","docker-compose":"🐳",podman:"🐳",kubectl:"☸️",helm:"☸️",k9s:"☸️",grep:"🔎",rg:"🔎",ag:"🔎",ack:"🔎",find:"🔍",fd:"🔍",locate:"🔍",which:"🔍",ls:"📂",dir:"📂",tree:"📂",cat:"📄",head:"📄",tail:"📄",less:"📄",more:"📄",bat:"📄",cp:"📋",mv:"✂️",rm:"🗑️",rmdir:"🗑️",mkdir:"📁",touch:"📁",sed:"✏️",awk:"✏️",tr:"✏️",curl:"🌐",wget:"🌐",http:"🌐",httpie:"🌐",ssh:"🔐",scp:"🔐",rsync:"🔐",ping:"📡",make:"🔨",cmake:"🔨",ninja:"🔨",bazel:"🔨",just:"🔨",terraform:"🏗️",ansible:"📕",pulumi:"🏗️",ps:"📊",top:"📊",htop:"📊",btm:"📊",kill:"💀",pkill:"💀",systemctl:"⚙️",service:"⚙️",tar:"🗜️",zip:"🗜️",unzip:"🗜️",gzip:"🗜️","7z":"🗜️",vim:"📝",nvim:"📝",nano:"📝",emacs:"📝",code:"📝",jq:"🪺",yq:"🪺",echo:"💬",printf:"💬",ffmpeg:"🎞️",ffprobe:"🎞️",imagemagick:"🖼️",convert:"🖼️","Get-ChildItem":"📂","Get-Content":"📄","Set-Content":"💾","Out-File":"💾","Add-Content":"💾","Set-Location":"📍","Get-Location":"📍","Get-Process":"📊","Start-Process":"▶️","Stop-Process":"💀","Invoke-WebRequest":"🌐","Invoke-RestMethod":"🌐","New-Item":"📁","Remove-Item":"🗑️","Copy-Item":"📋","Move-Item":"✂️","Test-Path":"🔍","Where-Object":"🔎","ForEach-Object":"🔁","Select-Object":"🎯","Measure-Object":"📊","Get-Service":"⚙️","Restart-Service":"⚙️","ConvertTo-Json":"🪺","ConvertFrom-Json":"🪺"};function CN(e){if(!e)return null;let n=e.trim();if(!n)return null;const r=n.match(/^(?:bash|sh|zsh|fish|powershell|pwsh)(?:\.exe)?\s+(?:-c|-Command|-NoProfile|-NonInteractive|\s)+["']([^"']+)["']/i);if(r)return CN(r[1]);for(;;){const l=n.match(/^([A-Z_][A-Z0-9_]*=\S*)\s+/);if(!l)break;n=n.slice(l[0].length)}n=n.replace(/^sudo(?:\s+-\S+)*\s+/,""),n=n.replace(/^(?:time|nohup|xargs)\s+/,"");const s=n.match(/^([^\s|;&<>(]+)/);if(!s)return null;let o=s[1];return o=o.replace(/^.*[/\\]/,""),o=o.replace(/\.(exe|cmd|bat|ps1)$/i,""),o||null}function fO(e){if(typeof e=="string")return e;if(!e||typeof e!="object")return null;const n=e;if(typeof n.cmd=="string")return n.cmd;if(typeof n.command=="string")return n.command;if(Array.isArray(n.command)&&n.command.every(r=>typeof r=="string")){const r=n.command;if(/powershell|cmd|bash|sh(\.exe)?$/i.test(r[0]??"")){const s=r.findIndex(o=>/^(-Command|-c)$/i.test(o));if(s>=0&&s+1<r.length)return r[s+1]}return r.join(" ")}return typeof n.script=="string"?n.script:null}const hO=new Set(["Bash","PowerShell","shell","exec_command","shell_command","write_stdin","wait"]),pO=new Set(["shell","exec_command","shell_command","write_stdin","wait","apply_patch","update_plan"]);function mO(e,n){return pO.has(e)||e.startsWith("mcp__")?Math.max(cx,34+n.length*7.5):cx}function gO(e,n){if(!hO.has(e))return null;const r=fO(n);if(!r)return null;const s=CN(r);return s?{emoji:dO[s]??"⚙️",label:s,category:"shell",detail:r}:null}const vO=new Set(["Read","Write","Edit","MultiEdit","NotebookEdit","LS","Glob","apply_patch"]),fx={ts:"🟦",tsx:"🟦",d:"🟦",js:"🟨",jsx:"🟨",mjs:"🟨",cjs:"🟨",py:"🐍",pyi:"🐍",ipynb:"📓",rs:"🦀",go:"🐹",rb:"💎",erb:"💎",java:"☕",kt:"☕",scala:"☕",gradle:"☕",cs:"🔷",fs:"🔷",php:"🐘",swift:"🦅",c:"🇨",cpp:"🇨",cc:"🇨",h:"🇨",hpp:"🇨",md:"📝",mdx:"📝",rst:"📝",json:"🪺",json5:"🪺",jsonl:"🪺",yaml:"⚙️",yml:"⚙️",toml:"⚙️",ini:"⚙️",conf:"⚙️",cfg:"⚙️",xml:"📰",html:"🌐",htm:"🌐",vue:"🌐",svelte:"🌐",css:"🎨",scss:"🎨",sass:"🎨",less:"🎨",sh:"⚡",bash:"⚡",zsh:"⚡",fish:"⚡",ps1:"⚡",txt:"📄",log:"📄",out:"📄",csv:"📊",tsv:"📊",xlsx:"📊",xls:"📊",pdf:"📕",png:"🖼️",jpg:"🖼️",jpeg:"🖼️",gif:"🖼️",webp:"🖼️",svg:"🖼️",ico:"🖼️",mp4:"🎬",mov:"🎬",avi:"🎬",mkv:"🎬",webm:"🎬",mp3:"🎵",wav:"🎵",ogg:"🎵",flac:"🎵",zip:"🗜️",tar:"🗜️",gz:"🗜️",bz2:"🗜️","7z":"🗜️",xz:"🗜️",rar:"🗜️",env:"🔐",lock:"🔐",pem:"🔐",key:"🔐",crt:"🔐",sql:"🗄️",db:"🗄️",sqlite:"🗄️",parquet:"🗄️"},hx={dockerfile:"🐳",makefile:"🔨",rakefile:"💎","package.json":"📦","pnpm-lock.yaml":"📦","yarn.lock":"📦","cargo.toml":"🦀","cargo.lock":"🦀","go.mod":"🐹","go.sum":"🐹","pyproject.toml":"🐍","requirements.txt":"🐍","readme.md":"📖",readme:"📖",license:"📜",".gitignore":"🐙",".gitattributes":"🐙",".env":"🔐",".dockerignore":"🐳"};function yO(e){const r=e.replace(/\\/g,"/").replace(/\/+$/,""),s=r.lastIndexOf("/");return s>=0?r.slice(s+1):r}function wO(e){const n=e.toLowerCase();if(hx[n])return hx[n];if(n.startsWith("dockerfile."))return"🐳";if(/\.(test|spec)\.[a-z]+$/.test(n))return"🧪";const r=n.lastIndexOf(".");if(r>0&&r<n.length-1){const s=n.slice(r+1);if(fx[s])return fx[s]}return"📄"}function xO(e,n){if(!n||typeof n!="object")return null;const r=n;if(e==="apply_patch"&&typeof r.patch=="string"){const s=r.patch.match(/^\*\*\* (?:Update|Add|Delete) File: (.+)$/m);return s?s[1].trim():null}return typeof r.file_path=="string"?r.file_path:typeof r.notebook_path=="string"?r.notebook_path:typeof r.path=="string"?r.path:e==="Glob"&&typeof r.pattern=="string"?r.pattern:null}function _O(e,n){if(!vO.has(e))return null;const r=xO(e,n);if(!r)return null;const s=yO(r);return s?{emoji:e==="LS"?"📂":wO(s),label:s,category:"file",detail:r}:null}const TN={github:{emoji:"🐙",name:"GitHub"},git:{emoji:"🐙",name:"Git"},gitlab:{emoji:"🦊",name:"GitLab"},slack:{emoji:"💬",name:"Slack"},discord:{emoji:"💬",name:"Discord"},linear:{emoji:"📐",name:"Linear"},jira:{emoji:"🅹",name:"Jira"},atlassian:{emoji:"🅰️",name:"Atlassian"},notion:{emoji:"📓",name:"Notion"},asana:{emoji:"📋",name:"Asana"},intercom:{emoji:"💬",name:"Intercom"},figma:{emoji:"🎨",name:"Figma"},gmail:{emoji:"📧",name:"Gmail"},calendar:{emoji:"📅",name:"Calendar"},drive:{emoji:"☁️",name:"Drive"},zoom:{emoji:"📹",name:"Zoom"},spotify:{emoji:"🎵",name:"Spotify"},youtube:{emoji:"📺",name:"YouTube"},ccd_session:{emoji:"📡",name:"Session"},ccd_directory:{emoji:"📂",name:"Directory"},ccd_session_mgmt:{emoji:"📡",name:"Sessions"},mcp_registry:{emoji:"🧰",name:"Registry"},"computer-use":{emoji:"🖱️",name:"Computer"},"claude-in-chrome":{emoji:"🌐",name:"Chrome"},"claude-preview":{emoji:"👀",name:"Preview"},"scheduled-tasks":{emoji:"⏰",name:"Scheduler"},visualize:{emoji:"🎨",name:"Visualize"},"plugin-design-asana":{emoji:"📋",name:"Asana"},"plugin-design-atlassian":{emoji:"🅰️",name:"Atlassian"},"plugin-design-figma":{emoji:"🎨",name:"Figma"},"plugin-design-intercom":{emoji:"💬",name:"Intercom"},"plugin-design-linear":{emoji:"📐",name:"Linear"},"plugin-design-notion":{emoji:"📓",name:"Notion"},"plugin-design-slack":{emoji:"💬",name:"Slack"}};function RN(e){if(!e.startsWith("mcp__"))return null;const n=e.slice(5),r=n.indexOf("__");return r<=0?{server:n,method:""}:{server:n.slice(0,r),method:n.slice(r+2)}}function SO(e){let n=5381;for(let r=0;r<e.length;r++)n=(n<<5)+n^e.charCodeAt(r);return Math.abs(n)%360}function bO(e,n){const r=RN(e);if(!r)return null;const{server:s,method:o}=r;if(!o)return null;const l=TN[s.toLowerCase()];return{emoji:(l==null?void 0:l.emoji)??"🔌",label:o,category:"mcp",detail:l?`${l.name} · ${o}`:`${s} · ${o}`}}function kO(e,n){return gO(e,n)??_O(e,n)??bO(e)}const EO={shell:"Shell",exec_command:"Shell",shell_command:"Shell",write_stdin:"stdin",wait:"wait",apply_patch:"Edit",update_plan:"Plan"};function NO(e){const n=RN(e);if(n){const s=TN[n.server.toLowerCase()];return s?{emoji:s.emoji,label:s.name}:{emoji:"🔌",label:n.server,hue:SO(n.server)}}const r=EO[e];return r?{emoji:dx(e),label:r}:{emoji:dx(e),label:e}}function CO(e){return e.endedAt==null?"inflight":e.ok===!1?"err":"done"}function TO(e,n,r){if(r==null)return 1;const s=n-r;return s<0?1:Math.max(0,1-s/NN)}function RO(e,n){const r=[],s=new Set;for(let o=e.length-1;o>=0&&r.length<n;o--){const l=e[o];s.has(l.id)||(s.add(l.id),r.push(l))}return r.reverse()}function jO(e,n,r,s,o,l){const u=[];for(const c of e.values()){if(!n.has(c.id)||c.exitAt!=null&&l-c.exitAt>NN)continue;const p=s.get(c.id)??r.get(c.id);if(!p)continue;const h=RO(c.tools,rO);if(h.length===0)continue;const f=c.exitAt??null,m=o.get(c.id),y=Math.max((m==null?void 0:m.width)??ux,ux),x=(m==null?void 0:m.height)??130,C=p.x,_=p.y,S=C+y,b=_+x/2;h.forEach((E,N)=>{const T=N*iO,I=C+y+sO,M=_+oO+T,O=TO(E,l,f),H=E.inputPreview??"",L=CO(E),P=O<.999,q=NO(E.name);u.push({id:`${c.id}::${E.id}`,toolId:E.id,agentId:c.id,toolName:E.name,name:q.label,emoji:q.emoji,status:L,category:uO(E.name),mcpHue:q.hue,inputPreview:H,fade:O,fading:P,worldX:I,worldY:M,anchorX:S,anchorY:b,spawnDx:S-I,spawnDy:b-(M+Qg)});const W=kO(E.name,E.input);if(W){const B=mO(E.name,q.label),j=I+B+aO,K=M,U=I+B,ee=M+Qg;u.push({id:`sub:${c.id}::${E.id}`,toolId:E.id,agentId:c.id,toolName:E.name,name:W.label,emoji:W.emoji,isSub:!0,status:L,category:W.category,inputPreview:W.detail??H,fade:O,fading:P,worldX:j,worldY:K,anchorX:U,anchorY:ee,spawnDx:U-j,spawnDy:0})}})}return u}function AO({agents:e,visibleAgentIds:n,positions:r,pinned:s,measured:o,dimUnmatched:l,spotlight:u,hiddenCategories:c,now:p,onOpenTool:h}){const f=jO(e,n,r,s,o,p),m=c&&c.size>0?f.filter(y=>!c.has(y.category)):f;return g.jsx(IO,{bursts:m,dimUnmatched:l,spotlight:u,onOpenTool:h})}function IO({bursts:e,dimUnmatched:n,spotlight:r,onOpenTool:s}){const{x:o,y:l,zoom:u}=pN();return g.jsxs("div",{className:"tool-bursts-layer","aria-hidden":!0,children:[g.jsx("svg",{className:"tool-bursts-svg",children:e.map(c=>{const p=c.anchorX*u+o,h=c.anchorY*u+l,f=(c.worldX+6)*u+o,m=(c.worldY+Qg)*u+l,y=p+(f-p)*.55,x=n!=null&&!n.has(c.agentId),C=r!=null&&!r.has(c.agentId),_=c.fade*(x||C?.14:1);return g.jsx("path",{d:`M ${p} ${h} Q ${y} ${h}, ${f} ${m}`,className:`tool-conn status-${c.status}${c.fading?" fading":""}`,opacity:_},`l:${c.id}`)})}),e.map(c=>{const p=c.worldX*u+o,h=c.worldY*u+l,f={left:`${p}px`,top:`${h}px`,transform:`scale(${u})`,transformOrigin:"left top","--spawn-dx":`${c.spawnDx}px`,"--spawn-dy":`${c.spawnDy}px`},m=c.isSub?`${c.toolName} · ${c.name}`:c.toolName,y=c.inputPreview?`${m} · ${c.inputPreview}`:m,x=s!=null,C=c.mcpHue!=null?{"--cat-accent":`hsl(${c.mcpHue} 65% 65%)`}:{},_=n!=null&&!n.has(c.agentId),S=r!=null&&!r.has(c.agentId),b=_||S?" dim":"";return g.jsx("div",{className:"tool-burst-wrap",style:f,children:g.jsxs("div",{className:`tool-burst cat-${c.category} status-${c.status}${c.fading?" fading":""}${x?" clickable":""}${c.isSub?" sub":""}${b}`,style:C,title:y,role:x?"button":void 0,tabIndex:x?0:void 0,"aria-label":x?`Open ${c.toolName} ${c.status==="inflight"?"in flight":c.status} — click for details`:void 0,onClick:x?()=>s(c.toolId):void 0,onKeyDown:x?E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),s(c.toolId))}:void 0,children:[g.jsx("span",{className:"tb-emoji",children:c.emoji}),g.jsx("span",{className:"tb-name",children:c.name}),c.status==="inflight"&&g.jsx("span",{className:"tb-spin"}),c.status==="done"&&g.jsx("span",{className:"tb-mark done",children:"✓"}),c.status==="err"&&g.jsx("span",{className:"tb-mark err",children:"×"})]})},c.id)})]})}function MO({state:e,sessionId:n,onClose:r}){const s=A.useMemo(()=>OO(e,n),[e,n]);return s?g.jsx("div",{className:"modal-backdrop",onClick:r,role:"presentation",children:g.jsxs("div",{className:"modal session-summary",onClick:o=>o.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"ss-title",children:[g.jsxs("div",{className:"modal-head",children:[g.jsxs("div",{className:"modal-title",children:[g.jsx("span",{className:"state-pill state-done","aria-hidden":!0,children:"done"}),g.jsx("span",{id:"ss-title",className:"modal-tool-name",title:s.cwd??s.sessionId,children:s.label}),g.jsxs("span",{className:"modal-tool-id",children:["· ",s.sessionId.slice(0,8)]})]}),g.jsxs("div",{className:"modal-actions",children:[g.jsx("span",{className:"modal-dur",title:"Total wall time",children:s.durationLabel}),g.jsx("button",{className:"btn",onClick:r,"aria-label":"Close",children:"×"})]})]}),g.jsxs("div",{className:"modal-body",children:[g.jsxs("section",{className:"ss-hero",children:[g.jsxs("div",{className:"ss-hero-left",children:[g.jsx("div",{className:"ss-cost-label",children:"total spend"}),g.jsx("div",{className:"ss-cost",children:ze(s.cost.total)}),s.modelChips.length>0&&g.jsx("div",{className:"ss-models",children:s.modelChips.map(o=>g.jsx("span",{className:"model-chip",title:o,children:da(o)},o))})]}),g.jsx("div",{className:"ss-hero-right",children:s.cost.total>0&&g.jsxs(g.Fragment,{children:[g.jsx(PO,{cost:s.cost}),g.jsxs("div",{className:"ss-cost-legend",children:[g.jsxs("span",{className:"ssl ssl-in",children:["input ",g.jsx("b",{children:ze(s.cost.input)})]}),g.jsxs("span",{className:"ssl ssl-out",children:["output ",g.jsx("b",{children:ze(s.cost.output)})]}),g.jsxs("span",{className:"ssl ssl-cr",children:["cache r ",g.jsx("b",{children:ze(s.cost.cacheRead)})]}),g.jsxs("span",{className:"ssl ssl-cw",children:["cache w ",g.jsx("b",{children:ze(s.cost.cacheWrite)})]})]})]})})]}),g.jsxs("section",{className:"ss-stats",children:[g.jsx(Fs,{label:"agents",value:s.agentCount}),g.jsx(Fs,{label:"subagents",value:s.subagentCount}),g.jsx(Fs,{label:"tool calls",value:s.toolCount}),g.jsx(Fs,{label:"prompts",value:s.promptCount}),g.jsx(Fs,{label:"tokens",value:s.tokensSum.toLocaleString()}),s.errCount>0&&g.jsx(Fs,{label:"errors",value:s.errCount,tone:"err"})]}),s.topTools.length>0&&g.jsxs("section",{className:"modal-section",children:[g.jsx("h4",{children:"Most-used tools"}),g.jsx("div",{className:"ss-top-tools",children:s.topTools.map(([o,l])=>g.jsxs("div",{className:"ss-tt",children:[g.jsx("span",{className:"ss-tt-name",children:o}),g.jsx("span",{className:"ss-tt-bar",children:g.jsx("span",{className:"ss-tt-bar-fill",style:{width:`${l/s.topTools[0][1]*100}%`}})}),g.jsx("span",{className:"ss-tt-count",children:l})]},o))})]}),s.firstPrompt&&g.jsxs("section",{className:"modal-section",children:[g.jsx("h4",{children:"Opening prompt"}),g.jsx("div",{className:"ss-prompt",children:s.firstPrompt})]})]})]})}):null}function Fs({label:e,value:n,tone:r}){return g.jsxs("div",{className:`ss-stat${r?` tone-${r}`:""}`,children:[g.jsx("div",{className:"ss-stat-value",children:n}),g.jsx("div",{className:"ss-stat-label",children:e})]})}function PO({cost:e}){const n=e.total;if(n<=0)return null;const r=(s,o,l)=>{if(s<=0)return null;const u=s/n*100;return g.jsx("span",{className:`cb-seg ${o}`,style:{width:`${u}%`},title:`${l}: ${ze(s)} (${u.toFixed(0)}%)`},o)};return g.jsxs("div",{className:"cost-bar cost-bar-lg","aria-label":"Cost breakdown",children:[r(e.input,"cb-input","input"),r(e.output,"cb-output","output"),r(e.cacheRead,"cb-cache-r","cache read"),r(e.cacheWrite,"cb-cache-w","cache write")]})}function OO(e,n){const r=e.agents.get(n);if(!r)return null;const s=[];for(const N of e.agents.values())N.sessionId===n&&s.push(N);if(s.length===0)return null;const o={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},l=new Set,u=new Map;let c=0,p=0,h=0,f=0,m=0,y,x=1/0,C=0;for(const N of s){const T=cn(N.usage,N.model);o.input+=T.input,o.output+=T.output,o.cacheRead+=T.cacheRead,o.cacheWrite+=T.cacheWrite,o.total+=T.total,N.model&&l.add(N.model),N.kind==="subagent"&&m++,p+=N.prompts.length,!y&&N.prompts.length>0&&(y=N.prompts[0].text),h+=N.usage.inputTokens+N.usage.outputTokens,c+=N.toolCount,x=Math.min(x,N.startedAt),C=Math.max(C,N.endedAt??Date.now());for(const I of N.tools)u.set(I.name,(u.get(I.name)??0)+1),I.ok===!1&&f++}const _=Math.max(0,C-x),S=Math.floor(_/1e3),b=S<60?`${S}s`:S<3600?`${Math.floor(S/60)}m ${String(S%60).padStart(2,"0")}s`:`${Math.floor(S/3600)}h ${Math.floor(S%3600/60)}m`,E=Array.from(u.entries()).sort((N,T)=>T[1]-N[1]).slice(0,5);return{sessionId:n,label:r.label||r.cwdBasename||"session",cwd:r.cwd,durationLabel:b,cost:o,modelChips:Array.from(l),agentCount:s.length,subagentCount:m,toolCount:c,promptCount:p,tokensSum:h,errCount:f,topTools:E,firstPrompt:y}}function LO(e,n){const r=[];for(const s of e.agents.values()){if(s.kind!=="root")continue;let o=s.toolCount,l=cn(s.usage,s.model).total,u=s.endedAt??s.startedAt;for(const c of e.agents.values()){if(c.sessionId!==s.sessionId||c.kind==="root")continue;o+=c.toolCount,l+=cn(c.usage,c.model).total;const p=c.endedAt??c.startedAt;p>u&&(u=p)}r.push({sessionId:s.sessionId,label:s.label||s.cwdBasename||"session",cwdBasename:s.cwdBasename,state:s.state,modelId:s.model,toolCount:o,cost:l,startedAt:s.startedAt,lastActivity:u})}return r.sort((s,o)=>{if(s.state!==o.state){if(s.state==="active")return-1;if(o.state==="active")return 1}return o.lastActivity-s.lastActivity}),r}function qO(e,n,r){const s=(n??r)-e;if(s<1e3)return"<1s";const o=Math.floor(s/1e3);if(o<60)return`${o}s`;const l=Math.floor(o/60);return l<60?`${l}m`:`${Math.floor(l/60)}h ${l%60}m`}function $O({state:e,now:n,selectedIds:r,onSelect:s,onClose:o}){const l=A.useMemo(()=>LO(e),[e,e.lastSeq,n]),u=l.filter(c=>c.state==="active").length;return g.jsxs("aside",{className:"session-list","aria-label":"Sessions",children:[g.jsxs("div",{className:"sl-header",children:[g.jsxs("h3",{children:["Sessions ",g.jsx("span",{className:"sl-count",children:l.length})]}),u>0&&g.jsxs("span",{className:"sl-live-count",children:[u," live"]}),g.jsx("button",{className:"btn icon-btn sl-close",onClick:o,title:"Hide sidebar (L)","aria-label":"Hide session list",children:"‹"})]}),g.jsxs("div",{className:"sl-rows",children:[l.length===0&&g.jsx("div",{className:"sl-empty",children:"No sessions yet."}),l.map(c=>{const p=r.has(c.sessionId);return g.jsxs("button",{type:"button",className:`sl-row state-${c.state}${p?" selected":""}`,onClick:()=>s(c.sessionId),title:`Focus ${c.label}`,children:[g.jsx("span",{className:`sl-dot state-${c.state}`,"aria-hidden":!0}),g.jsxs("div",{className:"sl-row-body",children:[g.jsxs("div",{className:"sl-row-head",children:[g.jsx("span",{className:"sl-label",children:c.label}),c.modelId&&g.jsx("span",{className:"model-chip",title:c.modelId,children:da(c.modelId)})]}),g.jsxs("div",{className:"sl-row-meta",children:[g.jsxs("span",{title:"tool calls",children:[g.jsx("b",{children:c.toolCount})," tools"]}),c.cost>0&&g.jsx("span",{className:"sl-cost",title:"total spend",children:g.jsx("b",{children:ze(c.cost)})}),g.jsx("span",{className:"sl-elapsed",title:`Started ${new Date(c.startedAt).toLocaleString()}`,children:qO(c.startedAt,c.state==="active"?void 0:c.lastActivity,n)})]})]})]},c.sessionId)})]})]})}function px(e,n){if(!e)return null;const r=n-Math.floor(e/1e3);return r<10?"just now":r<60?`${r}s ago`:r<3600?`${Math.floor(r/60)}m ago`:`${Math.floor(r/3600)}h ago`}function DO(e){return e==="claude-swap"?"Read from claude-swap's last collection — costs no request against your usage-endpoint budget":e==="api"?"Fetched from Anthropic's usage endpoint, at most once every 5 minutes":e==="cli"?"Parsed from `claude /usage`, at most once every 5 minutes":"Last update"}function Rr(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function FO({cost:e}){const n=e.total;if(n<=0)return null;const r=(s,o,l)=>{if(s<=0)return null;const u=s/n*100;return g.jsx("span",{className:`cb-seg ${o}`,style:{width:`${u}%`},title:`${l}: ${ze(s)} (${u.toFixed(0)}%)`},o)};return g.jsxs("div",{className:"cost-bar","aria-label":"Cost breakdown",children:[r(e.input,"cb-input","input"),r(e.output,"cb-output","output"),r(e.cacheRead,"cb-cache-r","cache read"),r(e.cacheWrite,"cb-cache-w","cache write")]})}function zO(e,n){const r=e-n;if(r<=0)return null;const s=Math.floor(r/3600),o=Math.floor(r%3600/60);if(s>23){const l=Math.floor(r/86400),u=Math.floor(r%86400/3600);return`${l}d ${u}h`}return s>0?`${s}h ${o}m`:`${o}m`}function BO(e,n,r,s){const o=Math.max(0,n-s),l=Math.max(0,r-o);if(l<120)return null;const u=Math.min(100,l/r*100),c=e-u;if(Math.abs(c)<3)return{label:"on pace",color:"var(--ok)",expectedPct:u,isDeficit:!1};if(c>0){const p=100-e,h=l>0?e/l:0,f=h>0?p/h:1/0,m={label:`${Math.round(c)}% ahead`,color:"var(--warn)",expectedPct:u,isDeficit:!0};if(f<o&&f<86400){const y=Math.floor(f/3600),x=Math.floor(f%3600/60);m.runsOutIn=y>0?`${y}h ${x}m`:`${x}m`}return m}return{label:`${Math.round(-c)}% reserve`,color:"var(--ok)",expectedPct:u,isDeficit:!1}}function Bi({pct:e,label:n,reset:r,resetAt:s,windowSec:o,limitReached:l,nowSec:u}){const c=Math.min(100,Math.max(0,e)),h=l||c>=90?"var(--err)":c>=70?"var(--warn)":"var(--accent)",f=c===0?"< 1%":`${c}%`,m=c===0?2:c,y=s?zO(s,u):null,x=s&&o?BO(c,s,o,u):null;return g.jsxs("div",{className:"qb-row",children:[g.jsxs("div",{className:"qb-meta",children:[g.jsxs("span",{className:"qb-label",children:[n,l&&g.jsx("span",{className:"qb-limit-badge",title:"Rate limit reached",children:"⛔"})]}),g.jsx("span",{className:"qb-pct",style:{color:h},children:f})]}),g.jsxs("div",{className:"qb-track",children:[g.jsx("div",{className:"qb-fill",style:{width:`${m}%`,background:h,opacity:c===0?.4:1}}),x&&g.jsx("div",{className:"qb-pace-marker",style:{left:`${x.expectedPct}%`,background:x.isDeficit?"var(--err)":"var(--ok)"},title:`To last until reset, stay near ${Math.round(x.expectedPct)}% by now`})]}),g.jsxs("div",{className:"qb-reset-row",children:[y?g.jsxs("span",{className:"qb-reset",children:["resets in ",y]}):r?g.jsxs("span",{className:"qb-reset",children:["resets ",r]}):null,x&&g.jsx("span",{className:"qb-pace",style:{color:x.color},children:x.runsOutIn?`runs out in ${x.runsOutIn}`:x.label})]})]})}const UO=6e4;function HO(){const[e,n]=A.useState(null),[r,s]=A.useState(!1),o=A.useRef(null),l=async(c=!1)=>{c&&s(!0);try{const h=await fetch(c?"/api/quota?refresh=1":"/api/quota");h.ok&&n(await h.json())}catch{}finally{c&&s(!1)}};return A.useEffect(()=>(l(!0),o.current=window.setInterval(()=>l(!1),UO),()=>{o.current!=null&&window.clearInterval(o.current)}),[]),{quota:e,loading:r,refresh:()=>l(!0)}}function WO(e){switch(e){case"no_token":return"Run codex login to authenticate.";case"api_key_mode":return"API-key login — ChatGPT quota is only available for codex login.";case"refresh_rejected":return"Codex session expired — run codex login.";case"refresh_failed":return"Couldn't refresh the Codex token — click ↻ to retry.";default:return"ChatGPT API unreachable — click ↻ to retry."}}const jN=6e4;function VO(){const[e,n]=A.useState(null),[r,s]=A.useState(!1),o=A.useRef(null),l=async(c=!1)=>{c&&s(!0);try{const h=await fetch(c?"/api/codex-quota?refresh=1":"/api/codex-quota");h.ok&&n(await h.json())}catch{}finally{c&&s(!1)}};return A.useEffect(()=>(l(!0),o.current=window.setInterval(()=>l(!1),jN),()=>{o.current!=null&&window.clearInterval(o.current)}),[]),{data:e,loading:r,refresh:()=>l(!0)}}function GO(){const[e,n]=A.useState(null),r=A.useRef(null),s=async()=>{try{const o=await fetch("/api/codex-usage");o.ok&&n(await o.json())}catch{}};return A.useEffect(()=>(s(),r.current=window.setInterval(s,jN),()=>{r.current!=null&&window.clearInterval(r.current)}),[]),{data:e}}function YO({state:e,now:n,onClose:r}){var O,H;const{quota:s,loading:o,refresh:l}=HO(),{data:u,loading:c,refresh:p}=VO(),{data:h}=GO(),[f,m]=A.useState(()=>Math.floor(Date.now()/1e3));A.useEffect(()=>{const L=window.setInterval(()=>m(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(L)},[]);const{byModel:y,totalCost:x,totalTokens:C,burnRate:_}=A.useMemo(()=>{const L=new Map,P={total:0,input:0,output:0,cacheRead:0,cacheWrite:0};let q=0,W=0,B=0,j=0;for(const F of e.agents.values()){const Y=F.model??"__unknown__",k=cn(F.usage,F.model),$=L.get(Y);$?($.inputTokens+=F.usage.inputTokens,$.outputTokens+=F.usage.outputTokens,$.cacheReadTokens+=F.usage.cacheReadTokens,$.cacheCreateTokens+=F.usage.cacheCreateTokens,$.cost.total+=k.total,$.cost.input+=k.input,$.cost.output+=k.output,$.cost.cacheRead+=k.cacheRead,$.cost.cacheWrite+=k.cacheWrite,$.agentCount++):L.set(Y,{model:Y,inputTokens:F.usage.inputTokens,outputTokens:F.usage.outputTokens,cacheReadTokens:F.usage.cacheReadTokens,cacheCreateTokens:F.usage.cacheCreateTokens,cost:{...k},agentCount:1}),P.total+=k.total,P.input+=k.input,P.output+=k.output,P.cacheRead+=k.cacheRead,P.cacheWrite+=k.cacheWrite,q+=F.usage.inputTokens,W+=F.usage.outputTokens,B+=F.usage.cacheReadTokens,j+=F.usage.cacheCreateTokens}const K=Array.from(L.values()).sort((F,Y)=>Y.cost.total-F.cost.total);let U=0,ee=0;for(const F of e.agents.values()){if(F.state!=="active")continue;const Y=cn(F.usage,F.model);U+=Y.total,ee=Math.max(ee,((F.endedAt??n)-F.startedAt)/1e3)}const J=ee>0?Yl(U,ee):null;return{byModel:K,totalCost:P,totalTokens:{in:q,out:W,cacheR:B,cacheC:j},burnRate:J}},[e,e.lastSeq,n]),S=A.useMemo(()=>{const L=[];for(const P of e.agents.values()){if(P.kind!=="root")continue;let q=cn(P.usage,P.model).total,W=P.usage.inputTokens,B=P.usage.outputTokens;for(const j of e.agents.values())j.sessionId!==P.sessionId||j.kind==="root"||(q+=cn(j.usage,j.model).total,W+=j.usage.inputTokens,B+=j.usage.outputTokens);L.push({sessionId:P.sessionId,label:P.label||P.cwdBasename||"session",state:P.state,cost:q,inputTokens:W,outputTokens:B})}return L.sort((P,q)=>q.cost-P.cost).slice(0,12)},[e,e.lastSeq]),b=x.total>0,E=C.in+C.out,N=o||c,T=px(s==null?void 0:s.fetchedAt,f),I=px(u==null?void 0:u.fetchedAt,f),M=()=>{l(),p()};return g.jsxs("div",{className:"usage-panel","aria-label":"Usage",children:[g.jsxs("div",{className:"up-header",children:[g.jsx("h3",{children:"Usage"}),_&&g.jsx("span",{className:"up-rate",children:_}),g.jsxs("div",{className:"up-header-right",children:[g.jsx("button",{type:"button",className:"btn up-refresh-btn",onClick:M,disabled:N,title:"Refresh Claude + Codex quota",children:N?"…":"↻"}),g.jsx("button",{type:"button",className:"btn icon-btn up-close",onClick:r,"aria-label":"Close usage panel",title:"Close (U)",children:"×"})]})]}),g.jsxs("section",{className:"up-section up-quota-section",children:[g.jsxs("h4",{className:"up-section-title",children:["Claude quota",T&&!o&&g.jsx("span",{className:"up-section-age",title:DO(s==null?void 0:s.source),children:T})]}),s!=null&&s.ok?g.jsxs("div",{className:"up-quota-bars",children:[s.session5hPct!=null&&g.jsx(Bi,{label:"5-hour window",pct:s.session5hPct,reset:s.session5hReset,resetAt:s.session5hResetAt,windowSec:s.session5hWindowSec,nowSec:f}),s.week7dPct!=null&&g.jsx(Bi,{label:"7-day window",pct:s.week7dPct,reset:s.week7dReset,resetAt:s.week7dResetAt,windowSec:s.week7dWindowSec,nowSec:f}),s.weekSonnetPct!=null&&g.jsx(Bi,{label:"Sonnet (7d)",pct:s.weekSonnetPct,nowSec:f}),s.weekOpusPct!=null&&g.jsx(Bi,{label:"Opus (7d)",pct:s.weekOpusPct,nowSec:f})]}):(s==null?void 0:s.ok)===!1?g.jsxs("div",{className:"up-quota-na",children:[g.jsx("span",{children:"Quota unavailable."}),g.jsxs("span",{className:"up-quota-hint",children:["Run ",g.jsx("code",{children:"/usage"})," in a claude session, then click ↻"]})]}):g.jsx("div",{className:"up-quota-na up-quota-loading",children:"Checking…"})]}),g.jsxs("section",{className:"up-section up-quota-section",children:[g.jsxs("h4",{className:"up-section-title",children:["Codex quota",(u==null?void 0:u.ok)&&u.planLabel&&g.jsx("span",{className:"up-plan-badge",children:u.planLabel}),I&&!c&&g.jsx("span",{className:"up-section-age",title:"Fetched from the Codex usage endpoint",children:I})]}),u!=null&&u.ok?g.jsxs("div",{className:"up-quota-bars",children:[(O=u.windows)==null?void 0:O.map(L=>g.jsx(Bi,{label:L.label,pct:L.pct,reset:L.reset??void 0,resetAt:L.resetAt??void 0,windowSec:L.windowSec??void 0,limitReached:u.limitReached&&L.pct>=100,nowSec:f},L.id)),(H=u.extraWindows)==null?void 0:H.map(L=>g.jsx(Bi,{label:L.label,pct:L.pct,reset:L.reset??void 0,resetAt:L.resetAt??void 0,windowSec:L.windowSec??void 0,nowSec:f},L.id)),u.creditLimit&&g.jsx(Bi,{label:`spend cap · $${Math.round(u.creditLimit.used)} of $${Math.round(u.creditLimit.limit)}`,pct:u.creditLimit.usedPct,reset:u.creditLimit.reset??void 0,resetAt:u.creditLimit.resetAt??void 0,limitReached:u.spendControlReached,nowSec:f}),(h==null?void 0:h.ok)&&h.window7d&&h.window7d.sessionCount>0&&g.jsxs("div",{className:"up-quota-sub",children:[Rr(h.window7d.totalTokens)," tokens · ",h.window7d.sessionCount," session",h.window7d.sessionCount!==1?"s":""," (7d)"]}),u.creditsBalance&&!u.creditsUnlimited&&g.jsxs("div",{className:"up-quota-sub up-credits",children:["credits: $",u.creditsBalance,u.overageReached&&" · overage limit reached"]}),u.creditsUnlimited&&g.jsx("div",{className:"up-quota-sub up-credits",children:"credits: unlimited"}),u.resetCredits&&u.resetCredits.availableCount>0&&g.jsxs("div",{className:"up-quota-sub up-reset-credits",title:"Redeem in the Codex CLI or ChatGPT — agents-deck only reports them",children:[u.resetCredits.availableCount," rate-limit reset",u.resetCredits.availableCount!==1?"s":""," available",u.resetCredits.nextExpiryAt&&` · expires ${new Date(u.resetCredits.nextExpiryAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`]}),u.promo&&g.jsx("div",{className:"up-quota-sub",children:u.promo}),u.partial&&g.jsx("div",{className:"up-quota-sub up-quota-hint",children:"Partial data — OpenAI returned limits this build doesn't recognise."})]}):(u==null?void 0:u.ok)===!1?g.jsxs("div",{className:"up-quota-na",children:[g.jsx("span",{children:"Quota unavailable."}),g.jsx("span",{className:"up-quota-hint",children:WO(u.reason)})]}):g.jsx("div",{className:"up-quota-na up-quota-loading",children:"Checking…"})]}),b?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"up-total",children:[g.jsx("span",{className:"up-total-value",children:ze(x.total)}),g.jsx("span",{className:"up-total-label",children:"total spend"})]}),g.jsx(FO,{cost:x}),E>0&&g.jsxs("div",{className:"up-tokens-row",children:[g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"in"}),Rr(C.in)]}),g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"out"}),Rr(C.out)]}),C.cacheR>0&&g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"cache r"}),Rr(C.cacheR)]}),C.cacheC>0&&g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"cache c"}),Rr(C.cacheC)]})]}),y.filter(L=>L.cost.total>0).length>0&&g.jsxs("section",{className:"up-section",children:[g.jsx("h4",{className:"up-section-title",children:"By model"}),g.jsxs("table",{className:"up-table",children:[g.jsx("thead",{children:g.jsxs("tr",{children:[g.jsx("th",{children:"Model"}),g.jsx("th",{children:"Tokens"}),g.jsx("th",{children:"Cost"})]})}),g.jsx("tbody",{children:y.filter(L=>L.cost.total>0).map(L=>g.jsxs("tr",{children:[g.jsx("td",{className:"up-model-name",title:L.model,children:da(L.model)}),g.jsx("td",{className:"up-num",children:Rr(L.inputTokens+L.outputTokens)}),g.jsx("td",{className:"up-num up-cost-val",children:ze(L.cost.total)})]},L.model))})]})]}),S.filter(L=>L.cost>0).length>0&&g.jsxs("section",{className:"up-section",children:[g.jsx("h4",{className:"up-section-title",children:"By session"}),g.jsx("div",{className:"up-sessions",children:S.filter(L=>L.cost>0).map(L=>g.jsxs("div",{className:"up-session-row",children:[g.jsx("span",{className:`sl-dot state-${L.state}`,"aria-hidden":!0}),g.jsx("span",{className:"up-session-label",children:L.label}),g.jsx("span",{className:"up-session-tokens",children:Rr(L.inputTokens+L.outputTokens)}),g.jsx("span",{className:"up-session-cost",children:ze(L.cost)})]},L.sessionId))})]})]}):E>0?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"up-tokens-row",children:[g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"in"}),Rr(C.in)]}),g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"out"}),Rr(C.out)]})]}),g.jsx("div",{className:"up-hint",children:"Cost appears once a known model is detected."})]}):g.jsxs("div",{className:"up-empty",children:["No usage data yet.",g.jsx("br",{}),"Start a Claude Code or Codex session."]})]})}const mx=18,KO=1100,zs=(e,n)=>{const r=Math.sin(e*12.9898+n*78.233)*43758.5453;return r-Math.floor(r)},XO=Array.from({length:mx},(e,n)=>{const r=-72+144*n/(mx-1)+(zs(n,1)-.5)*9,s=(r-90)*(Math.PI/180),o=(54+32*Math.cos(r*Math.PI/180))*(.74+zs(n,2)*.52);return{dx:Math.cos(s)*o,dy:Math.sin(s)*o,rot:(n%2?1:-1)*(100+zs(n,3)*260),delay:Math.round(zs(n,4)*90),dur:760+Math.round(zs(n,5)*260),scale:.8+zs(n,6)*.45,hue:n%4,round:n%3===0}});function gx({anchor:e,lifetimeMs:n=KO}){var l;const[r,s]=A.useState(null),o=typeof window<"u"&&((l=window.matchMedia)==null?void 0:l.call(window,"(prefers-reduced-motion: reduce)").matches);return A.useEffect(()=>{if(o)return;const u=e.current;if(!u)return;const c=u.getBoundingClientRect();s({x:c.left+c.width/2,y:c.top+c.height/2});const p=window.setTimeout(()=>s(null),n);return()=>window.clearTimeout(p)},[e,n,o]),o||!r?null:oI.createPortal(g.jsx("div",{className:"confetti",style:{left:`${r.x}px`,top:`${r.y}px`},"aria-hidden":!0,children:XO.map((u,c)=>g.jsx("span",{className:`confetti-bit${u.round?" round":""}`,"data-hue":u.hue,style:{"--dx":`${u.dx.toFixed(1)}px`,"--dy":`${u.dy.toFixed(1)}px`,"--rot":`${u.rot}deg`,"--s":u.scale.toFixed(2),animationDelay:`${u.delay}ms`,animationDuration:`${u.dur}ms, ${u.dur}ms`}},c))}),document.body)}const AN=new Set(["awaiting_url","awaiting_code","registering"]);function QO(e){return e!=null&&AN.has(e)}function ZO(e){return e!=null&&e!=="done"&&!AN.has(e)}const JO="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",e3="the sign-in did not complete";function t3({state:e,serverError:n,localError:r}){const s=e==="idle";return{title:s?"Sign-in ended":"Sign-in failed",message:r||n||(s?JO:e3)}}const n3="done";function r3(){let e=!1;return{shouldAnnounce(n){return n!==n3?(e=!1,!1):e?!1:(e=!0,!0)}}}const i3=1500;async function Rl(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const s3={already_running:"a sign-in is already in progress",no_url:"the claude CLI did not offer a sign-in link — is it installed?",not_waiting:"that sign-in is no longer waiting for a code",not_prompted:"the CLI has not asked for a code yet",code_rejected:"that code was not accepted — copy it again from the browser",no_verdict:"the claude CLI has not answered — try the code again",empty_code:"paste the code from the browser first",login_failed:"the code was not accepted",no_identity:"signed in, but the CLI still reports nobody logged in",add_failed:"signed in, but claude-swap could not record the account",not_a_share:"that does not look like a shared account — it should start with ccdeck1:",corrupt:"that share is incomplete — copy the whole thing",wrong_version:"that share was made by a newer agents-deck",expired:"that share has expired — make a new one",import_failed:"claude-swap refused the import"},fd=(e,n)=>(e==null?void 0:e.detail)||(e!=null&&e.reason?s3[e.reason]??e.reason:null)||(e==null?void 0:e.error)||n,Zg=le.forwardRef((e,n)=>g.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:n,children:[g.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),g.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));Zg.displayName="SuccessMark";function o3({onClose:e,onChanged:n}){const[r,s]=A.useState("login"),[o,l]=A.useState(null),[u,c]=A.useState(""),[p,h]=A.useState(""),[f,m]=A.useState(!1),[y,x]=A.useState(null),[C,_]=A.useState(null),S=A.useRef(!1),b=A.useRef(null),E=A.useRef(null),N=A.useRef(null),T=A.useCallback(()=>{S.current&&Rl({action:"login-cancel"}).catch(()=>{}),e()},[e]);A.useEffect(()=>{const B=j=>{j.key==="Escape"&&T()};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[T]);const I=A.useCallback(async()=>{m(!0),x(null),S.current=!0;const B=await Rl({action:"login"}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){x(fd(B,"could not start the sign-in"));return}l(B)},[]);A.useEffect(()=>{if(!QO(o==null?void 0:o.state))return;const B=window.setInterval(async()=>{try{const j=await fetch("/api/claude-accounts/login");j.ok&&l(await j.json())}catch{}},i3);return()=>window.clearInterval(B)},[o]);const M=A.useRef(n);M.current=n;const O=A.useRef(r3());A.useEffect(()=>{var B;(o==null?void 0:o.state)==="awaiting_code"&&((B=b.current)==null||B.focus()),O.current.shouldAnnounce(o==null?void 0:o.state)&&M.current()},[o==null?void 0:o.state]),A.useEffect(()=>{var B;r==="paste"&&((B=E.current)==null||B.focus())},[r]);const H=A.useCallback(async()=>{var j;m(!0),x(null);const B=await Rl({action:"login-code",code:u}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){x(fd(B,"the code was not accepted")),B!=null&&B.state&&l(B),(j=b.current)==null||j.select();return}c(""),l(B)},[u,o]),L=A.useCallback(async()=>{m(!0),x(null);const B=await Rl({action:"import",blob:p}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){x(fd(B,"the import failed"));return}h(""),_({added:B.added===!0,num:B.num??null,email:B.email??null}),n()},[p,n]),P=(o==null?void 0:o.state)==="done"?o.account:null,q=ZO(o==null?void 0:o.state)||!!(y&&S.current&&!f),W=t3({state:o==null?void 0:o.state,serverError:o==null?void 0:o.error,localError:y});return g.jsx("div",{className:"modal-backdrop",onClick:T,role:"presentation",children:g.jsxs("div",{className:"modal aa-modal",onClick:B=>B.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[g.jsxs("header",{className:"modal-head",children:[g.jsx("div",{className:"modal-title",children:g.jsxs("span",{className:"aa-tabs",role:"tablist",children:[g.jsx("button",{type:"button",role:"tab","aria-selected":r==="login",className:`aa-tab${r==="login"?" on":""}`,onClick:()=>s("login"),children:"Sign in"}),g.jsx("button",{type:"button",role:"tab","aria-selected":r==="paste",className:`aa-tab${r==="paste"?" on":""}`,onClick:()=>s("paste"),children:"Paste a share"})]})}),g.jsx("div",{className:"modal-actions",children:g.jsx("button",{type:"button",className:"btn icon-btn",onClick:T,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),g.jsx("section",{className:"modal-body aa-body",children:r==="login"?P?g.jsxs("div",{className:"aa-done",children:[g.jsx(Zg,{ref:N}),g.jsx(gx,{anchor:N}),g.jsx("h4",{children:P.added?`Account ${P.num} added`:"Credentials refreshed"}),g.jsxs("p",{className:"aa-note",children:[g.jsx("strong",{children:P.email}),P.added?" is in the rotation. The account you were using is still active.":" was already managed, so its stored credentials were replaced."]}),g.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"})]}):(o==null?void 0:o.state)==="awaiting_code"||(o==null?void 0:o.state)==="registering"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"1 · Approve in the browser"}),g.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),g.jsx("a",{className:"aa-link",href:o.url??"#",target:"_blank",rel:"noreferrer noopener",children:o.url})]}),g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"2 · Paste the code it gives you"}),g.jsxs("div",{className:"aa-field",children:[g.jsx("input",{ref:b,type:"text",value:u,onChange:B=>c(B.target.value),onKeyDown:B=>{B.key==="Enter"&&u.trim()&&!f&&H()},placeholder:"paste the code here",spellCheck:!1,autoComplete:"off","aria-label":"Sign-in code",disabled:o.state==="registering"}),g.jsx("button",{type:"button",className:"btn primary",disabled:f||!u.trim()||o.state==="registering",onClick:H,children:o.state==="registering"?"registering…":"Continue"})]}),(y||o.error)&&g.jsx("p",{className:"aa-err",children:y??o.error}),g.jsx("p",{className:"aa-note",children:"The code goes straight to the claude CLI on this machine. It is never stored or sent anywhere else."})]})]}):q?g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:W.title}),g.jsx("p",{className:"aa-err",children:W.message}),g.jsx("button",{type:"button",className:"btn",onClick:()=>{S.current=!1,l(null),x(null),I()},children:"Try again"})]}):f||S.current?g.jsx("div",{className:"aa-step",children:g.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):g.jsxs("div",{className:"aa-step aa-primer",children:[g.jsx("h4",{children:"Sign in to Anthropic"}),g.jsx("p",{className:"aa-note",children:"Opens a browser tab where you approve the sign-in, then asks for the code it shows you. claude-swap records the account when it completes, and the account you are using now stays active."}),g.jsx("div",{className:"aa-actions",children:g.jsx("button",{type:"button",className:"btn primary",onClick:I,disabled:f,children:"Open the sign-in page"})})]}):C?g.jsxs("div",{className:"aa-done",children:[g.jsx(Zg,{ref:N}),C.added&&g.jsx(gx,{anchor:N}),g.jsx("h4",{children:C.added?`Account ${C.num} imported`:"Already here"}),g.jsx("p",{className:"aa-note",children:C.added?g.jsxs(g.Fragment,{children:[C.email?g.jsx("strong",{children:C.email}):"That account"," is in the rotation now. Nothing changed on the deck you copied it from."]}):"This deck already holds that account, so nothing changed."}),g.jsxs("div",{className:"aa-actions",children:[g.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"}),g.jsx("button",{type:"button",className:"btn",onClick:()=>_(null),children:"Import another"})]})]}):g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"Paste an account shared from another deck"}),g.jsxs("div",{className:"aa-field",children:[g.jsx("input",{ref:E,type:"text",value:p,onChange:B=>h(B.target.value),onKeyDown:B=>{B.key==="Enter"&&p.trim()&&!f&&L()},placeholder:"ccdeck1:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),g.jsx("button",{type:"button",className:"btn primary",disabled:f||!p.trim(),onClick:L,children:f?"importing…":"Import"})]}),y&&g.jsx("p",{className:"aa-err",children:y}),g.jsxs("p",{className:"aa-note",children:["Use ",g.jsx("strong",{children:"share"})," on an account in the other deck. A share carries a live login and expires ten minutes after it is made."]})]})})]})})}const a3=15e3,l3=[70,80,85,90,95];function u3(e,n){const r=e-n;if(r<=0)return null;const s=Math.floor(r/86400),o=Math.floor(r%86400/3600),l=Math.floor(r%3600/60);return s>0?`${s}d ${o}h`:o>0?`${o}h ${l}m`:`${l}m`}function vx(e,n){const r=n-Math.floor(e/1e3);return r<60?"just now":r<3600?`${Math.floor(r/60)}m ago`:r<86400?`${Math.floor(r/3600)}h ago`:`${Math.floor(r/86400)}d ago`}function c3(e,n){if(!e)return"";const r=Math.floor(e/1e3)-n;return r<=0?" · due":r<60?` · next in ${r}s`:` · next in ${Math.round(r/60)}m`}function d3(e){switch(e){case"invalid_grant":case"no_refresh_token":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fixable:!0};case"http-401":return{text:"re-login needed",hint:"Anthropic refused this account's token.",fixable:!0};case"http-429":return{text:"rate limited",hint:"Anthropic is throttling requests for this account. It clears on its own.",fixable:!1};case"transient":return{text:"temporary error",hint:"A network or server hiccup while reading usage. The next collection retries.",fixable:!1};case"timeout":return{text:"timed out",hint:"Reading this account's usage took too long. The next collection retries.",fixable:!1};case"network":return{text:"unreachable",hint:"Could not reach Anthropic to read this account's usage.",fixable:!1};default:return{text:e,hint:`claude-swap reported "${e}" for this account.`,fixable:!1}}}function f3({lane:e,nowSec:n}){const r=Math.min(100,Math.max(0,e.pct)),s=r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",o=e.resetAt?u3(e.resetAt,n):null;return g.jsxs("div",{className:"ap-lane",children:[g.jsx("span",{className:"ap-lane-label",children:e.label}),g.jsx("div",{className:"ap-lane-track",children:g.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:s,opacity:r===0?.4:1}})}),g.jsxs("span",{className:"ap-lane-pct",style:{color:s},children:[r,"%"]}),g.jsx("span",{className:"ap-lane-reset",children:o?`resets ${o}`:""})]})}function h3(e){const n=e.map(s=>s.num),r=n.length?Math.max(...n):0;return[...new Set([...n,r+1])].sort((s,o)=>s-o)}async function p3(e){var r;let n=!1;try{n=await Promise.race([((r=navigator.clipboard)==null?void 0:r.writeText(e).then(()=>!0))??Promise.resolve(!1),new Promise(s=>window.setTimeout(()=>s(!1),500))])}catch{n=!1}if(n)return!0;try{const s=document.createElement("textarea");s.value=e,s.setAttribute("readonly",""),s.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(s),s.select(),n=document.execCommand("copy"),s.remove()}catch{n=!1}return n}function m3(e,n){const r=Math.round(e/1e3)-n;return r<=0?{text:"expired",tone:"gone"}:r<60?{text:`expires in ${r}s`,tone:"soon"}:{text:`expires in ${Math.round(r/60)}m`,tone:"ok"}}function g3({onClose:e}){var J,F,Y;const[n,r]=A.useState(null),[s,o]=A.useState(null),[l,u]=A.useState(null),[c,p]=A.useState(null),[h,f]=A.useState(null),[m,y]=A.useState(()=>Math.floor(Date.now()/1e3)),x=A.useRef(null),[C,_]=A.useState(null),[S,b]=A.useState(!1),[E,N]=A.useState(""),[T,I]=A.useState(null),[M,O]=A.useState(null),[H,L]=A.useState(!1),P=A.useCallback(async(k=!1)=>{try{const[$,se]=await Promise.all([fetch(`/api/claude-accounts${k?"?refresh=1":""}`),fetch("/api/cswap-auto")]);$.ok&&r(await $.json()),se.ok&&o(await se.json())}catch{}},[]),q=A.useCallback(async(k,$)=>{u($),f(null);try{const D=await(await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)})).json().catch(()=>null);return D!=null&&D.ok||f((D==null?void 0:D.detail)||(D==null?void 0:D.reason)||"command failed"),D}catch{return f("server unreachable"),null}finally{u(null)}},[]),W=A.useCallback(async(k,$)=>{u($),f(null);try{const D=await(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)})).json().catch(()=>null);return D!=null&&D.ok||f((D==null?void 0:D.detail)||(D==null?void 0:D.reason)||"command failed"),D}catch{return f("server unreachable"),null}finally{u(null)}},[]);A.useEffect(()=>(P(!0),x.current=window.setInterval(()=>P(!1),a3),()=>{x.current!=null&&window.clearInterval(x.current)}),[P]),A.useEffect(()=>{const k=window.setInterval(()=>y(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(k)},[]);const B=((J=s==null?void 0:s.settings["autoswitch.threshold"])==null?void 0:J.value)??"90",j=(F=n==null?void 0:n.accounts)==null?void 0:F.find(k=>k.active),K=j!=null&&j.lanes.length?Math.max(...j.lanes.map(k=>k.pct)):null,U=K!=null&&K>=Number(B)-15,ee=async k=>{p(k),f(null);try{const se=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:k})})).json().catch(()=>null);se!=null&&se.ok||f((se==null?void 0:se.output)||(se==null?void 0:se.reason)||"switch failed"),await P(!0)}catch{f("server unreachable")}finally{p(null)}};return g.jsxs("div",{className:"accounts-panel","aria-label":"Claude accounts",children:[g.jsxs("div",{className:"ap-header",children:[g.jsx("h3",{children:"Accounts"}),g.jsxs("div",{className:"ap-header-right",children:[g.jsx("button",{type:"button",className:"btn ap-add",onClick:()=>b(!0),title:"Sign in to another Claude account, or paste one shared from another deck",children:"+"}),g.jsx("button",{type:"button",className:"btn ap-refresh",onClick:()=>P(!0),title:"Reload from claude-swap",children:"↻"}),g.jsx("button",{type:"button",className:"btn icon-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:"×"})]})]}),n==null?g.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?g.jsxs(g.Fragment,{children:[(Y=n.accounts)==null?void 0:Y.map(k=>g.jsxs("div",{className:`ap-account${k.active?" active":""}${k.disabled?" disabled":""}`,children:[g.jsxs("div",{className:"ap-account-head",children:[g.jsx("span",{className:"ap-num",children:k.num}),k.alias&&g.jsx("span",{className:"ap-alias",children:k.alias}),g.jsx("span",{className:"ap-email",title:k.org??void 0,children:k.email}),g.jsx("button",{type:"button",className:`ap-more${C===k.num?" on":""}`,"aria-label":`Manage account ${k.num}`,"aria-expanded":C===k.num,title:"Share, rename, move, remove",onClick:()=>{_(C===k.num?null:k.num),N(k.alias??""),I(null),O(null),L(!1)},children:"⋯"}),k.active?g.jsx("span",{className:"ap-badge-active",children:"● active"}):g.jsx("button",{type:"button",className:"btn ap-switch",disabled:c!=null||k.disabled,onClick:()=>ee(k.num),title:k.disabled?"Held out of rotation":`Switch to ${k.alias??k.email}`,children:c===k.num?"…":"switch"})]}),k.lanes.length>0?k.lanes.map($=>g.jsx(f3,{lane:$,nowSec:m},$.id)):g.jsx("div",{className:"ap-hint",children:"No usage recorded yet."}),g.jsxs("div",{className:"ap-meta",children:[k.error&&(()=>{const $=d3(k.error);return g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"ap-err",title:$.hint,children:$.text}),$.fixable&&g.jsx("button",{type:"button",className:"ap-fix",onClick:()=>b(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"sign in again"})]})})(),((s==null?void 0:s.enabled)||(s==null?void 0:s.external))&&!k.active&&g.jsx("button",{type:"button",className:"ap-rotate",disabled:l!=null,onClick:()=>q({action:"account",account:k.num,enabled:k.disabled},`rot-${k.num}`).then(()=>P(!0)),title:k.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",children:k.disabled?"held out":"in rotation"}),k.fetchedAt?g.jsxs("span",{className:`ap-age${k.stale?" ap-stale":""}`,title:"When claude-swap last read this account's usage, and when it plans to read it again. It sets that interval itself — 3 minutes at the fastest, wider while an account is recovering from a rate limit — and every surface, including `cswap watch`, follows the same plan.",children:["collected ",vx(k.fetchedAt,m),c3(k.nextAt,m)]}):g.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})]}),C===k.num&&g.jsxs("div",{className:"ap-manage",children:[g.jsxs("div",{className:"ap-manage-row",children:[g.jsx("span",{className:"ap-manage-label",children:"name"}),g.jsx("input",{className:"ap-manage-input",type:"text",value:E,onChange:$=>N($.target.value),onKeyDown:$=>{$.key==="Enter"&&W({action:"alias",account:k.num,alias:E},`alias-${k.num}`).then(()=>P(!0))},placeholder:"no alias",spellCheck:!1,"aria-label":`Alias for account ${k.num}`}),g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null||E.trim()===(k.alias??""),onClick:()=>W({action:"alias",account:k.num,alias:E},`alias-${k.num}`).then(()=>P(!0)),title:"A short name to show instead of the email",children:"save"})]}),g.jsxs("div",{className:"ap-manage-row",children:[g.jsx("span",{className:"ap-manage-label",children:"slot"}),g.jsx("span",{className:"ap-field",children:g.jsx("select",{"aria-label":`Slot for account ${k.num}`,value:String(k.num),disabled:l!=null,onChange:$=>W({action:"move",account:k.num,slot:Number($.target.value)},`move-${k.num}`).then(()=>P(!0)),children:h3(n.accounts??[]).map($=>g.jsx("option",{value:$,children:$},$))})}),g.jsx("span",{className:"ap-manage-hint",children:"rotation order"})]}),g.jsxs("div",{className:"ap-manage-row",children:[g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,title:"Copy this account to another agents-deck. The share carries a live login and expires in 10 minutes.",onClick:async()=>{L(!1);const $=await W({action:"share",account:k.num},`share-${k.num}`);$!=null&&$.ok&&O({num:k.num,blob:$.blob,expiresAt:$.expiresAt})},children:"share…"}),g.jsx("button",{type:"button",className:`ap-manage-btn danger${T===k.num?" armed":""}`,disabled:l!=null,title:T===k.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{if(T!==k.num){I(k.num),window.setTimeout(()=>I($=>$===k.num?null:$),4e3);return}I(null),W({action:"remove",account:k.num},`rm-${k.num}`).then(()=>{_(null),P(!0)})},children:T===k.num?"confirm remove":"remove"})]}),(M==null?void 0:M.num)===k.num&&(()=>{const $=m3(M.expiresAt,m),se=$.tone==="gone";return g.jsxs("div",{className:`ap-share${se?" expired":""}`,children:[g.jsx("code",{className:"ap-share-blob",children:M.blob}),g.jsxs("div",{className:"ap-share-foot",children:[g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,onClick:async()=>{if(se){L(!1);const D=await W({action:"share",account:k.num},`share-${k.num}`);D!=null&&D.ok&&O({num:k.num,blob:D.blob,expiresAt:D.expiresAt});return}await p3(M.blob)&&(L(!0),window.setTimeout(()=>L(!1),1800))},children:se?"make a new share":H?"copied":"copy"}),g.jsxs("span",{className:"ap-manage-hint",children:["carries a live login · ",g.jsx("span",{className:`ap-share-expiry ${$.tone}`,children:$.text})]})]})]})})()]})]},k.num)),(s==null?void 0:s.ok)&&g.jsxs("div",{className:"ap-auto",children:[g.jsxs("div",{className:"ap-auto-head",children:[g.jsx("span",{className:"ap-auto-title",children:"Auto-switch"}),g.jsxs("span",{className:"ap-auto-ctl",children:[K!=null&&g.jsxs("span",{className:`ap-auto-now${U?" near":""}`,children:[Math.round(K),"%"]}),g.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:g.jsx("select",{"aria-label":"Switch threshold",value:B,disabled:l!=null,onChange:k=>q({action:"setting",key:"autoswitch.threshold",value:k.target.value},"threshold").then(()=>P(!0)),children:l3.map(k=>g.jsxs("option",{value:k,children:[k,"%"]},k))})}),g.jsxs("button",{type:"button",className:`ap-auto-state toggle${s.enabled?" live":""}`,role:"switch","aria-checked":s.enabled,disabled:l!=null,onClick:()=>q({action:"enable",enabled:!s.enabled},"enable").then(()=>P(!0)),title:s.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:[g.jsx("i",{className:s.enabled?"ap-pulse":"ap-dot","aria-hidden":!0}),s.enabled?"on":"off"]})]})]}),s.external&&g.jsxs("p",{className:"ap-auto-note",children:[g.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",g.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",s.enabled?" — this toggle takes over when you stop it.":"."]}),s.lastTick&&g.jsx("div",{className:"ap-auto-foot",children:g.jsxs("span",{className:"ap-auto-result",children:["checked ",vx(s.lastTick.at,m)]})})]}),h&&g.jsx("div",{className:"ap-failure",children:h}),g.jsx("p",{className:"ap-footnote",title:"Anthropic's usage endpoint allows roughly 28–30 requests per hour per account, shared by every tool on this machine — polling it from here would rate-limit your account. So the deck never fetches: it asks claude-swap to collect while this panel is open, at most once every three minutes, and claude-swap decides whether that touches the network at all.",children:"Collected by claude-swap while this panel is open."})]}):g.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"claude-swap isn't installed."}),g.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&g.jsx("code",{className:"ap-cmd",children:n.hint}),g.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",g.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"No accounts added yet."}),g.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",g.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"Couldn't read the account store."}),g.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})}),S&&g.jsx(o3,{onClose:()=>b(!1),onChanged:()=>P(!0)})]})}const v3=3e4;function y3({bundle:e,running:n,lastTried:r}){return!n||e===n?!1:r!==n}function w3(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function x3({asked:e,reported:n}){return n?n!==e:!1}function _3(e){const n=e.thresholdMs??v3;return!e.enabled||e.kind!=="restart"||!e.canRestart?{idleSince:null,restart:!1}:e.busy?{idleSince:null,restart:!1}:e.idleSince==null?{idleSince:e.now,restart:!1}:e.now<e.idleSince?{idleSince:e.now,restart:!1}:{idleSince:e.idleSince,restart:e.now-e.idleSince>=n}}function S3(e){return e.ctrlKey||e.metaKey||e.altKey}const b3=new Set(["button","checkbox","color","file","image","radio","range","reset","submit"]),k3=new Set(["INPUT","TEXTAREA","SELECT","OPTION","BUTTON","SUMMARY","A"]),E3=new Set(["button","checkbox","combobox","link","listbox","menu","menubar","menuitem","menuitemcheckbox","menuitemradio","option","radio","searchbox","slider","spinbutton","switch","tab","textbox","treeitem"]);function IN(e){return typeof e.tagName=="string"?e.tagName.toUpperCase():""}function MN(e){if(!e)return!1;if(e.isContentEditable)return!0;const n=IN(e);return n==="TEXTAREA"?!0:n!=="INPUT"?!1:!b3.has(String(e.type??"text").toLowerCase())}function N3(e){if(!e)return!1;if(MN(e)||k3.has(IN(e)))return!0;const n=typeof e.role=="string"?e.role.trim().toLowerCase():"";return n!==""&&n.split(/\s+/).some(r=>E3.has(r))}function hd(e,n){if(n.size!==0)for(const r of Array.from(e.keys()))n.has(r)||e.delete(r)}function C3(e){const n=new Set;for(const r of e)n.add(r.id),n.add(`group:${r.sessionId}`);return n}const T3=40,R3=120;function j3(e,n){let r=null,s=0,o=Number.NEGATIVE_INFINITY;const l=()=>{r=null,o=n.now(),e()},u=()=>{r!=null&&(n.clearTimeout(r),r=null)},c=(p,h,f)=>{if(r!=null){if(s<=p)return;u()}const m=Math.min(f,Math.max(0,p-h));s=p,r=n.setTimeout(l,m)};return{live(p=T3){const h=n.now(),f=Math.max(o+p,h);if(f<=h){u(),l();return}c(f,h,p)},replay(p=R3){u(),s=n.now()+p,r=n.setTimeout(l,p)},flush(){u(),l()},cancel(){u()}}}function A3(){let e=!1,n=[];return{get paused(){return e},get size(){return n.length},accept(r){return e?(n.push(r),!1):!0},setPaused(r){if(e=r,r||n.length===0)return[];const s=n;return n=[],s}}}function I3(){let e=0;return{begin(){const n=++e;return()=>n===e},cancel(){e++}}}function M3(e,n=new Date){return new Date(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()-(e-1))).toISOString().slice(0,10).replace(/-/g,"")}function Ui(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:e<1e9?`${(e/1e6).toFixed(2)}M`:`${(e/1e9).toFixed(2)}B`}function yx(e){return e.replace(/^anthropic\./,"").replace(/^claude-/,"").replace(/-\d{8}$/,"")}function jl(e){const n=e.toLowerCase();return n.includes("opus")?"#c4b5fd":n.includes("sonnet")?"#7dd3fc":n.includes("haiku")?"#86efac":n.includes("gpt-5")||n.includes("gpt5")?"#fcd34d":n.includes("gpt")?"#fca5a5":n.includes("gemini")?"#a5b4fc":n.includes("codex")?"#fdba74":"#94a3b8"}const P3=[7,14,30,90];function O3(e){const[n,r]=A.useState(null),[s,o]=A.useState(!1),l=A.useRef(I3()).current,u=(c=!1)=>{const p=l.begin();o(!0);const f=`/api/ccusage?since=${M3(e)}${c?"&refresh=1":""}`;fetch(f).then(m=>m.json()).then(m=>{p()&&r(m)}).catch(()=>{p()&&r({ok:!1,error:"request failed"})}).finally(()=>{p()&&o(!1)})};return A.useEffect(()=>(u(!1),()=>l.cancel()),[e]),{data:n,loading:s,reload:()=>u(!0)}}function L3({onClose:e}){var b,E;const[n,r]=A.useState(30),[s,o]=A.useState(null),{data:l,loading:u,reload:c}=O3(n);A.useEffect(()=>{const N=T=>{T.key==="Escape"&&e()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[e]);const p=l!=null&&l.ok?l.days??[]:[],h=A.useMemo(()=>p.reduce((N,T)=>Math.max(N,T.totalCost),0),[p]),{totalCost:f,totalTok:m,inOut:y,cacheRead:x,modelCosts:C}=A.useMemo(()=>{let N=0,T=0,I=0,M=0;const O=new Map;for(const H of p){N+=H.totalCost,T+=H.totalTokens,I+=H.inputTokens+H.outputTokens,M+=H.cacheReadTokens;for(const L of H.modelBreakdowns)O.set(L.modelName,(O.get(L.modelName)??0)+L.cost)}return{totalCost:N,totalTok:T,inOut:I,cacheRead:M,modelCosts:O}},[p]),_=A.useMemo(()=>Array.from(C.entries()).sort((N,T)=>T[1]-N[1]),[C]),S=s?p.find(N=>N.period===s)??null:null;return g.jsx("div",{className:"uh-backdrop",onClick:e,role:"presentation",children:g.jsxs("div",{className:"uh-modal",onClick:N=>N.stopPropagation(),role:"dialog","aria-label":"Usage history",children:[g.jsxs("header",{className:"uh-head",children:[g.jsxs("div",{className:"uh-titlewrap",children:[g.jsx("div",{className:"uh-title",children:"Usage history"}),g.jsx("div",{className:"uh-sub",children:"via ccusage · local Claude / Codex logs"})]}),g.jsx("div",{className:"uh-range",role:"tablist","aria-label":"Range",children:P3.map(N=>g.jsxs("button",{role:"tab","aria-selected":n===N,className:`uh-range-btn${n===N?" on":""}`,onClick:()=>{r(N),o(null)},children:[N,"d"]},N))}),g.jsx("button",{className:"btn icon-btn uh-reload",onClick:c,title:"Re-run ccusage","aria-label":"Reload",children:"↻"}),g.jsx("button",{className:"uh-close",onClick:e,"aria-label":"Close",children:"×"})]}),u&&p.length===0?g.jsx("div",{className:"uh-status",children:"running ccusage… (first run downloads the package)"}):l&&!l.ok?g.jsxs("div",{className:"uh-status uh-err",children:["ccusage failed: ",l.error]}):p.length===0?g.jsx("div",{className:"uh-status",children:"no usage in this range"}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"uh-totals",children:[g.jsx(Al,{label:"total cost",val:ze(f),accent:!0}),g.jsx(Al,{label:"tokens",val:Ui(m)}),g.jsx(Al,{label:"input+output",val:Ui(y)}),g.jsx(Al,{label:"cache reads",val:Ui(x)})]}),g.jsx("div",{className:"uh-chart",role:"img","aria-label":"Daily cost by model",children:p.map(N=>{const T=h>0?N.totalCost/h*100:0,I=N.period===s;return g.jsxs("button",{className:`uh-bar-col${I?" sel":""}`,onClick:()=>o(I?null:N.period),title:`${N.period} · ${ze(N.totalCost)}`,style:{flexBasis:`${100/p.length}%`},children:[g.jsx("div",{className:"uh-bar",style:{height:`${Math.max(T,N.totalCost>0?2:0)}%`},children:N.modelBreakdowns.slice().sort((M,O)=>O.cost-M.cost).map(M=>{const O=N.totalCost>0?M.cost/N.totalCost*100:0;return g.jsx("div",{className:"uh-bar-seg",style:{height:`${O}%`,background:jl(M.modelName)}},M.modelName)})}),g.jsx("span",{className:"uh-bar-label",children:N.period.slice(5)})]},N.period)})}),g.jsx("div",{className:"uh-legend",children:_.map(([N,T])=>g.jsxs("span",{className:"uh-legend-item",children:[g.jsx("span",{className:"uh-legend-dot",style:{background:jl(N)}}),yx(N)," ",g.jsx("span",{className:"uh-legend-cost",children:ze(T)})]},N))}),S&&g.jsxs("div",{className:"uh-detail",children:[g.jsxs("div",{className:"uh-detail-head",children:[g.jsx("span",{className:"uh-detail-date",children:S.period}),g.jsx("span",{className:"uh-detail-cost",children:ze(S.totalCost)}),(E=(b=S.metadata)==null?void 0:b.agents)!=null&&E.length?g.jsx("span",{className:"uh-detail-agents",children:S.metadata.agents.join(" · ")}):null]}),g.jsxs("div",{className:"uh-detail-mini",children:[g.jsx(Il,{label:"input",val:Ui(S.inputTokens)}),g.jsx(Il,{label:"output",val:Ui(S.outputTokens)}),g.jsx(Il,{label:"cache write",val:Ui(S.cacheCreationTokens)}),g.jsx(Il,{label:"cache read",val:Ui(S.cacheReadTokens)})]}),g.jsx("div",{className:"uh-detail-models",children:S.modelBreakdowns.slice().sort((N,T)=>T.cost-N.cost).map(N=>{const T=S.totalCost>0?N.cost/S.totalCost*100:0;return g.jsxs("div",{className:"uh-model-row",children:[g.jsxs("span",{className:"uh-model-name",children:[g.jsx("span",{className:"uh-legend-dot",style:{background:jl(N.modelName)}}),yx(N.modelName)]}),g.jsx("span",{className:"uh-model-bar",children:g.jsx("span",{className:"uh-model-bar-fill",style:{width:`${T}%`,background:jl(N.modelName)}})}),g.jsx("span",{className:"uh-model-cost",children:ze(N.cost)})]},N.modelName)})})]})]})]})})}function Al({label:e,val:n,accent:r}){return g.jsxs("div",{className:"uh-stat",children:[g.jsx("span",{className:`uh-stat-val${r?" accent":""}`,children:n}),g.jsx("span",{className:"uh-stat-label",children:e})]})}function Il({label:e,val:n}){return g.jsxs("div",{className:"uh-ministat",children:[g.jsx("span",{className:"uh-ministat-val",children:n}),g.jsx("span",{className:"uh-ministat-label",children:e})]})}function bv(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var pd,wx;function q3(){if(wx)return pd;wx=1;function e(){this.__data__=[],this.size=0}return pd=e,pd}var md,xx;function eo(){if(xx)return md;xx=1;function e(n,r){return n===r||n!==n&&r!==r}return md=e,md}var gd,_x;function iu(){if(_x)return gd;_x=1;var e=eo();function n(r,s){for(var o=r.length;o--;)if(e(r[o][0],s))return o;return-1}return gd=n,gd}var vd,Sx;function $3(){if(Sx)return vd;Sx=1;var e=iu(),n=Array.prototype,r=n.splice;function s(o){var l=this.__data__,u=e(l,o);if(u<0)return!1;var c=l.length-1;return u==c?l.pop():r.call(l,u,1),--this.size,!0}return vd=s,vd}var yd,bx;function D3(){if(bx)return yd;bx=1;var e=iu();function n(r){var s=this.__data__,o=e(s,r);return o<0?void 0:s[o][1]}return yd=n,yd}var wd,kx;function F3(){if(kx)return wd;kx=1;var e=iu();function n(r){return e(this.__data__,r)>-1}return wd=n,wd}var xd,Ex;function z3(){if(Ex)return xd;Ex=1;var e=iu();function n(r,s){var o=this.__data__,l=e(o,r);return l<0?(++this.size,o.push([r,s])):o[l][1]=s,this}return xd=n,xd}var _d,Nx;function su(){if(Nx)return _d;Nx=1;var e=q3(),n=$3(),r=D3(),s=F3(),o=z3();function l(u){var c=-1,p=u==null?0:u.length;for(this.clear();++c<p;){var h=u[c];this.set(h[0],h[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=s,l.prototype.set=o,_d=l,_d}var Sd,Cx;function B3(){if(Cx)return Sd;Cx=1;var e=su();function n(){this.__data__=new e,this.size=0}return Sd=n,Sd}var bd,Tx;function U3(){if(Tx)return bd;Tx=1;function e(n){var r=this.__data__,s=r.delete(n);return this.size=r.size,s}return bd=e,bd}var kd,Rx;function H3(){if(Rx)return kd;Rx=1;function e(n){return this.__data__.get(n)}return kd=e,kd}var Ed,jx;function W3(){if(jx)return Ed;jx=1;function e(n){return this.__data__.has(n)}return Ed=e,Ed}var Nd,Ax;function PN(){if(Ax)return Nd;Ax=1;var e=typeof gl=="object"&&gl&&gl.Object===Object&&gl;return Nd=e,Nd}var Cd,Ix;function tr(){if(Ix)return Cd;Ix=1;var e=PN(),n=typeof self=="object"&&self&&self.Object===Object&&self,r=e||n||Function("return this")();return Cd=r,Cd}var Td,Mx;function to(){if(Mx)return Td;Mx=1;var e=tr(),n=e.Symbol;return Td=n,Td}var Rd,Px;function V3(){if(Px)return Rd;Px=1;var e=to(),n=Object.prototype,r=n.hasOwnProperty,s=n.toString,o=e?e.toStringTag:void 0;function l(u){var c=r.call(u,o),p=u[o];try{u[o]=void 0;var h=!0}catch{}var f=s.call(u);return h&&(c?u[o]=p:delete u[o]),f}return Rd=l,Rd}var jd,Ox;function G3(){if(Ox)return jd;Ox=1;var e=Object.prototype,n=e.toString;function r(s){return n.call(s)}return jd=r,jd}var Ad,Lx;function Qi(){if(Lx)return Ad;Lx=1;var e=to(),n=V3(),r=G3(),s="[object Null]",o="[object Undefined]",l=e?e.toStringTag:void 0;function u(c){return c==null?c===void 0?o:s:l&&l in Object(c)?n(c):r(c)}return Ad=u,Ad}var Id,qx;function jn(){if(qx)return Id;qx=1;function e(n){var r=typeof n;return n!=null&&(r=="object"||r=="function")}return Id=e,Id}var Md,$x;function fa(){if($x)return Md;$x=1;var e=Qi(),n=jn(),r="[object AsyncFunction]",s="[object Function]",o="[object GeneratorFunction]",l="[object Proxy]";function u(c){if(!n(c))return!1;var p=e(c);return p==s||p==o||p==r||p==l}return Md=u,Md}var Pd,Dx;function Y3(){if(Dx)return Pd;Dx=1;var e=tr(),n=e["__core-js_shared__"];return Pd=n,Pd}var Od,Fx;function K3(){if(Fx)return Od;Fx=1;var e=Y3(),n=(function(){var s=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return s?"Symbol(src)_1."+s:""})();function r(s){return!!n&&n in s}return Od=r,Od}var Ld,zx;function ON(){if(zx)return Ld;zx=1;var e=Function.prototype,n=e.toString;function r(s){if(s!=null){try{return n.call(s)}catch{}try{return s+""}catch{}}return""}return Ld=r,Ld}var qd,Bx;function X3(){if(Bx)return qd;Bx=1;var e=fa(),n=K3(),r=jn(),s=ON(),o=/[\\^$.*+?()[\]{}|]/g,l=/^\[object .+?Constructor\]$/,u=Function.prototype,c=Object.prototype,p=u.toString,h=c.hasOwnProperty,f=RegExp("^"+p.call(h).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function m(y){if(!r(y)||n(y))return!1;var x=e(y)?f:l;return x.test(s(y))}return qd=m,qd}var $d,Ux;function Q3(){if(Ux)return $d;Ux=1;function e(n,r){return n==null?void 0:n[r]}return $d=e,$d}var Dd,Hx;function Zi(){if(Hx)return Dd;Hx=1;var e=X3(),n=Q3();function r(s,o){var l=n(s,o);return e(l)?l:void 0}return Dd=r,Dd}var Fd,Wx;function kv(){if(Wx)return Fd;Wx=1;var e=Zi(),n=tr(),r=e(n,"Map");return Fd=r,Fd}var zd,Vx;function ou(){if(Vx)return zd;Vx=1;var e=Zi(),n=e(Object,"create");return zd=n,zd}var Bd,Gx;function Z3(){if(Gx)return Bd;Gx=1;var e=ou();function n(){this.__data__=e?e(null):{},this.size=0}return Bd=n,Bd}var Ud,Yx;function J3(){if(Yx)return Ud;Yx=1;function e(n){var r=this.has(n)&&delete this.__data__[n];return this.size-=r?1:0,r}return Ud=e,Ud}var Hd,Kx;function eL(){if(Kx)return Hd;Kx=1;var e=ou(),n="__lodash_hash_undefined__",r=Object.prototype,s=r.hasOwnProperty;function o(l){var u=this.__data__;if(e){var c=u[l];return c===n?void 0:c}return s.call(u,l)?u[l]:void 0}return Hd=o,Hd}var Wd,Xx;function tL(){if(Xx)return Wd;Xx=1;var e=ou(),n=Object.prototype,r=n.hasOwnProperty;function s(o){var l=this.__data__;return e?l[o]!==void 0:r.call(l,o)}return Wd=s,Wd}var Vd,Qx;function nL(){if(Qx)return Vd;Qx=1;var e=ou(),n="__lodash_hash_undefined__";function r(s,o){var l=this.__data__;return this.size+=this.has(s)?0:1,l[s]=e&&o===void 0?n:o,this}return Vd=r,Vd}var Gd,Zx;function rL(){if(Zx)return Gd;Zx=1;var e=Z3(),n=J3(),r=eL(),s=tL(),o=nL();function l(u){var c=-1,p=u==null?0:u.length;for(this.clear();++c<p;){var h=u[c];this.set(h[0],h[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=s,l.prototype.set=o,Gd=l,Gd}var Yd,Jx;function iL(){if(Jx)return Yd;Jx=1;var e=rL(),n=su(),r=kv();function s(){this.size=0,this.__data__={hash:new e,map:new(r||n),string:new e}}return Yd=s,Yd}var Kd,e1;function sL(){if(e1)return Kd;e1=1;function e(n){var r=typeof n;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?n!=="__proto__":n===null}return Kd=e,Kd}var Xd,t1;function au(){if(t1)return Xd;t1=1;var e=sL();function n(r,s){var o=r.__data__;return e(s)?o[typeof s=="string"?"string":"hash"]:o.map}return Xd=n,Xd}var Qd,n1;function oL(){if(n1)return Qd;n1=1;var e=au();function n(r){var s=e(this,r).delete(r);return this.size-=s?1:0,s}return Qd=n,Qd}var Zd,r1;function aL(){if(r1)return Zd;r1=1;var e=au();function n(r){return e(this,r).get(r)}return Zd=n,Zd}var Jd,i1;function lL(){if(i1)return Jd;i1=1;var e=au();function n(r){return e(this,r).has(r)}return Jd=n,Jd}var ef,s1;function uL(){if(s1)return ef;s1=1;var e=au();function n(r,s){var o=e(this,r),l=o.size;return o.set(r,s),this.size+=o.size==l?0:1,this}return ef=n,ef}var tf,o1;function Ev(){if(o1)return tf;o1=1;var e=iL(),n=oL(),r=aL(),s=lL(),o=uL();function l(u){var c=-1,p=u==null?0:u.length;for(this.clear();++c<p;){var h=u[c];this.set(h[0],h[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=s,l.prototype.set=o,tf=l,tf}var nf,a1;function cL(){if(a1)return nf;a1=1;var e=su(),n=kv(),r=Ev(),s=200;function o(l,u){var c=this.__data__;if(c instanceof e){var p=c.__data__;if(!n||p.length<s-1)return p.push([l,u]),this.size=++c.size,this;c=this.__data__=new r(p)}return c.set(l,u),this.size=c.size,this}return nf=o,nf}var rf,l1;function lu(){if(l1)return rf;l1=1;var e=su(),n=B3(),r=U3(),s=H3(),o=W3(),l=cL();function u(c){var p=this.__data__=new e(c);this.size=p.size}return u.prototype.clear=n,u.prototype.delete=r,u.prototype.get=s,u.prototype.has=o,u.prototype.set=l,rf=u,rf}var sf,u1;function Nv(){if(u1)return sf;u1=1;function e(n,r){for(var s=-1,o=n==null?0:n.length;++s<o&&r(n[s],s,n)!==!1;);return n}return sf=e,sf}var of,c1;function LN(){if(c1)return of;c1=1;var e=Zi(),n=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return of=n,of}var af,d1;function uu(){if(d1)return af;d1=1;var e=LN();function n(r,s,o){s=="__proto__"&&e?e(r,s,{configurable:!0,enumerable:!0,value:o,writable:!0}):r[s]=o}return af=n,af}var lf,f1;function cu(){if(f1)return lf;f1=1;var e=uu(),n=eo(),r=Object.prototype,s=r.hasOwnProperty;function o(l,u,c){var p=l[u];(!(s.call(l,u)&&n(p,c))||c===void 0&&!(u in l))&&e(l,u,c)}return lf=o,lf}var uf,h1;function ha(){if(h1)return uf;h1=1;var e=cu(),n=uu();function r(s,o,l,u){var c=!l;l||(l={});for(var p=-1,h=o.length;++p<h;){var f=o[p],m=u?u(l[f],s[f],f,l,s):void 0;m===void 0&&(m=s[f]),c?n(l,f,m):e(l,f,m)}return l}return uf=r,uf}var cf,p1;function dL(){if(p1)return cf;p1=1;function e(n,r){for(var s=-1,o=Array(n);++s<n;)o[s]=r(s);return o}return cf=e,cf}var df,m1;function hr(){if(m1)return df;m1=1;function e(n){return n!=null&&typeof n=="object"}return df=e,df}var ff,g1;function fL(){if(g1)return ff;g1=1;var e=Qi(),n=hr(),r="[object Arguments]";function s(o){return n(o)&&e(o)==r}return ff=s,ff}var hf,v1;function pa(){if(v1)return hf;v1=1;var e=fL(),n=hr(),r=Object.prototype,s=r.hasOwnProperty,o=r.propertyIsEnumerable,l=e((function(){return arguments})())?e:function(u){return n(u)&&s.call(u,"callee")&&!o.call(u,"callee")};return hf=l,hf}var pf,y1;function _t(){if(y1)return pf;y1=1;var e=Array.isArray;return pf=e,pf}var Vo={exports:{}},mf,w1;function hL(){if(w1)return mf;w1=1;function e(){return!1}return mf=e,mf}Vo.exports;var x1;function no(){return x1||(x1=1,(function(e,n){var r=tr(),s=hL(),o=n&&!n.nodeType&&n,l=o&&!0&&e&&!e.nodeType&&e,u=l&&l.exports===o,c=u?r.Buffer:void 0,p=c?c.isBuffer:void 0,h=p||s;e.exports=h})(Vo,Vo.exports)),Vo.exports}var gf,_1;function du(){if(_1)return gf;_1=1;var e=9007199254740991,n=/^(?:0|[1-9]\d*)$/;function r(s,o){var l=typeof s;return o=o??e,!!o&&(l=="number"||l!="symbol"&&n.test(s))&&s>-1&&s%1==0&&s<o}return gf=r,gf}var vf,S1;function Cv(){if(S1)return vf;S1=1;var e=9007199254740991;function n(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return vf=n,vf}var yf,b1;function pL(){if(b1)return yf;b1=1;var e=Qi(),n=Cv(),r=hr(),s="[object Arguments]",o="[object Array]",l="[object Boolean]",u="[object Date]",c="[object Error]",p="[object Function]",h="[object Map]",f="[object Number]",m="[object Object]",y="[object RegExp]",x="[object Set]",C="[object String]",_="[object WeakMap]",S="[object ArrayBuffer]",b="[object DataView]",E="[object Float32Array]",N="[object Float64Array]",T="[object Int8Array]",I="[object Int16Array]",M="[object Int32Array]",O="[object Uint8Array]",H="[object Uint8ClampedArray]",L="[object Uint16Array]",P="[object Uint32Array]",q={};q[E]=q[N]=q[T]=q[I]=q[M]=q[O]=q[H]=q[L]=q[P]=!0,q[s]=q[o]=q[S]=q[l]=q[b]=q[u]=q[c]=q[p]=q[h]=q[f]=q[m]=q[y]=q[x]=q[C]=q[_]=!1;function W(B){return r(B)&&n(B.length)&&!!q[e(B)]}return yf=W,yf}var wf,k1;function fu(){if(k1)return wf;k1=1;function e(n){return function(r){return n(r)}}return wf=e,wf}var Go={exports:{}};Go.exports;var E1;function Tv(){return E1||(E1=1,(function(e,n){var r=PN(),s=n&&!n.nodeType&&n,o=s&&!0&&e&&!e.nodeType&&e,l=o&&o.exports===s,u=l&&r.process,c=(function(){try{var p=o&&o.require&&o.require("util").types;return p||u&&u.binding&&u.binding("util")}catch{}})();e.exports=c})(Go,Go.exports)),Go.exports}var xf,N1;function ma(){if(N1)return xf;N1=1;var e=pL(),n=fu(),r=Tv(),s=r&&r.isTypedArray,o=s?n(s):e;return xf=o,xf}var _f,C1;function qN(){if(C1)return _f;C1=1;var e=dL(),n=pa(),r=_t(),s=no(),o=du(),l=ma(),u=Object.prototype,c=u.hasOwnProperty;function p(h,f){var m=r(h),y=!m&&n(h),x=!m&&!y&&s(h),C=!m&&!y&&!x&&l(h),_=m||y||x||C,S=_?e(h.length,String):[],b=S.length;for(var E in h)(f||c.call(h,E))&&!(_&&(E=="length"||x&&(E=="offset"||E=="parent")||C&&(E=="buffer"||E=="byteLength"||E=="byteOffset")||o(E,b)))&&S.push(E);return S}return _f=p,_f}var Sf,T1;function hu(){if(T1)return Sf;T1=1;var e=Object.prototype;function n(r){var s=r&&r.constructor,o=typeof s=="function"&&s.prototype||e;return r===o}return Sf=n,Sf}var bf,R1;function $N(){if(R1)return bf;R1=1;function e(n,r){return function(s){return n(r(s))}}return bf=e,bf}var kf,j1;function mL(){if(j1)return kf;j1=1;var e=$N(),n=e(Object.keys,Object);return kf=n,kf}var Ef,A1;function Rv(){if(A1)return Ef;A1=1;var e=hu(),n=mL(),r=Object.prototype,s=r.hasOwnProperty;function o(l){if(!e(l))return n(l);var u=[];for(var c in Object(l))s.call(l,c)&&c!="constructor"&&u.push(c);return u}return Ef=o,Ef}var Nf,I1;function Pr(){if(I1)return Nf;I1=1;var e=fa(),n=Cv();function r(s){return s!=null&&n(s.length)&&!e(s)}return Nf=r,Nf}var Cf,M1;function hi(){if(M1)return Cf;M1=1;var e=qN(),n=Rv(),r=Pr();function s(o){return r(o)?e(o):n(o)}return Cf=s,Cf}var Tf,P1;function gL(){if(P1)return Tf;P1=1;var e=ha(),n=hi();function r(s,o){return s&&e(o,n(o),s)}return Tf=r,Tf}var Rf,O1;function vL(){if(O1)return Rf;O1=1;function e(n){var r=[];if(n!=null)for(var s in Object(n))r.push(s);return r}return Rf=e,Rf}var jf,L1;function yL(){if(L1)return jf;L1=1;var e=jn(),n=hu(),r=vL(),s=Object.prototype,o=s.hasOwnProperty;function l(u){if(!e(u))return r(u);var c=n(u),p=[];for(var h in u)h=="constructor"&&(c||!o.call(u,h))||p.push(h);return p}return jf=l,jf}var Af,q1;function Ji(){if(q1)return Af;q1=1;var e=qN(),n=yL(),r=Pr();function s(o){return r(o)?e(o,!0):n(o)}return Af=s,Af}var If,$1;function wL(){if($1)return If;$1=1;var e=ha(),n=Ji();function r(s,o){return s&&e(o,n(o),s)}return If=r,If}var Yo={exports:{}};Yo.exports;var D1;function DN(){return D1||(D1=1,(function(e,n){var r=tr(),s=n&&!n.nodeType&&n,o=s&&!0&&e&&!e.nodeType&&e,l=o&&o.exports===s,u=l?r.Buffer:void 0,c=u?u.allocUnsafe:void 0;function p(h,f){if(f)return h.slice();var m=h.length,y=c?c(m):new h.constructor(m);return h.copy(y),y}e.exports=p})(Yo,Yo.exports)),Yo.exports}var Mf,F1;function FN(){if(F1)return Mf;F1=1;function e(n,r){var s=-1,o=n.length;for(r||(r=Array(o));++s<o;)r[s]=n[s];return r}return Mf=e,Mf}var Pf,z1;function zN(){if(z1)return Pf;z1=1;function e(n,r){for(var s=-1,o=n==null?0:n.length,l=0,u=[];++s<o;){var c=n[s];r(c,s,n)&&(u[l++]=c)}return u}return Pf=e,Pf}var Of,B1;function BN(){if(B1)return Of;B1=1;function e(){return[]}return Of=e,Of}var Lf,U1;function jv(){if(U1)return Lf;U1=1;var e=zN(),n=BN(),r=Object.prototype,s=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,l=o?function(u){return u==null?[]:(u=Object(u),e(o(u),function(c){return s.call(u,c)}))}:n;return Lf=l,Lf}var qf,H1;function xL(){if(H1)return qf;H1=1;var e=ha(),n=jv();function r(s,o){return e(s,n(s),o)}return qf=r,qf}var $f,W1;function Av(){if(W1)return $f;W1=1;function e(n,r){for(var s=-1,o=r.length,l=n.length;++s<o;)n[l+s]=r[s];return n}return $f=e,$f}var Df,V1;function pu(){if(V1)return Df;V1=1;var e=$N(),n=e(Object.getPrototypeOf,Object);return Df=n,Df}var Ff,G1;function UN(){if(G1)return Ff;G1=1;var e=Av(),n=pu(),r=jv(),s=BN(),o=Object.getOwnPropertySymbols,l=o?function(u){for(var c=[];u;)e(c,r(u)),u=n(u);return c}:s;return Ff=l,Ff}var zf,Y1;function _L(){if(Y1)return zf;Y1=1;var e=ha(),n=UN();function r(s,o){return e(s,n(s),o)}return zf=r,zf}var Bf,K1;function HN(){if(K1)return Bf;K1=1;var e=Av(),n=_t();function r(s,o,l){var u=o(s);return n(s)?u:e(u,l(s))}return Bf=r,Bf}var Uf,X1;function WN(){if(X1)return Uf;X1=1;var e=HN(),n=jv(),r=hi();function s(o){return e(o,r,n)}return Uf=s,Uf}var Hf,Q1;function SL(){if(Q1)return Hf;Q1=1;var e=HN(),n=UN(),r=Ji();function s(o){return e(o,r,n)}return Hf=s,Hf}var Wf,Z1;function bL(){if(Z1)return Wf;Z1=1;var e=Zi(),n=tr(),r=e(n,"DataView");return Wf=r,Wf}var Vf,J1;function kL(){if(J1)return Vf;J1=1;var e=Zi(),n=tr(),r=e(n,"Promise");return Vf=r,Vf}var Gf,e_;function VN(){if(e_)return Gf;e_=1;var e=Zi(),n=tr(),r=e(n,"Set");return Gf=r,Gf}var Yf,t_;function EL(){if(t_)return Yf;t_=1;var e=Zi(),n=tr(),r=e(n,"WeakMap");return Yf=r,Yf}var Kf,n_;function ro(){if(n_)return Kf;n_=1;var e=bL(),n=kv(),r=kL(),s=VN(),o=EL(),l=Qi(),u=ON(),c="[object Map]",p="[object Object]",h="[object Promise]",f="[object Set]",m="[object WeakMap]",y="[object DataView]",x=u(e),C=u(n),_=u(r),S=u(s),b=u(o),E=l;return(e&&E(new e(new ArrayBuffer(1)))!=y||n&&E(new n)!=c||r&&E(r.resolve())!=h||s&&E(new s)!=f||o&&E(new o)!=m)&&(E=function(N){var T=l(N),I=T==p?N.constructor:void 0,M=I?u(I):"";if(M)switch(M){case x:return y;case C:return c;case _:return h;case S:return f;case b:return m}return T}),Kf=E,Kf}var Xf,r_;function NL(){if(r_)return Xf;r_=1;var e=Object.prototype,n=e.hasOwnProperty;function r(s){var o=s.length,l=new s.constructor(o);return o&&typeof s[0]=="string"&&n.call(s,"index")&&(l.index=s.index,l.input=s.input),l}return Xf=r,Xf}var Qf,i_;function GN(){if(i_)return Qf;i_=1;var e=tr(),n=e.Uint8Array;return Qf=n,Qf}var Zf,s_;function Iv(){if(s_)return Zf;s_=1;var e=GN();function n(r){var s=new r.constructor(r.byteLength);return new e(s).set(new e(r)),s}return Zf=n,Zf}var Jf,o_;function CL(){if(o_)return Jf;o_=1;var e=Iv();function n(r,s){var o=s?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.byteLength)}return Jf=n,Jf}var eh,a_;function TL(){if(a_)return eh;a_=1;var e=/\w*$/;function n(r){var s=new r.constructor(r.source,e.exec(r));return s.lastIndex=r.lastIndex,s}return eh=n,eh}var th,l_;function RL(){if(l_)return th;l_=1;var e=to(),n=e?e.prototype:void 0,r=n?n.valueOf:void 0;function s(o){return r?Object(r.call(o)):{}}return th=s,th}var nh,u_;function YN(){if(u_)return nh;u_=1;var e=Iv();function n(r,s){var o=s?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.length)}return nh=n,nh}var rh,c_;function jL(){if(c_)return rh;c_=1;var e=Iv(),n=CL(),r=TL(),s=RL(),o=YN(),l="[object Boolean]",u="[object Date]",c="[object Map]",p="[object Number]",h="[object RegExp]",f="[object Set]",m="[object String]",y="[object Symbol]",x="[object ArrayBuffer]",C="[object DataView]",_="[object Float32Array]",S="[object Float64Array]",b="[object Int8Array]",E="[object Int16Array]",N="[object Int32Array]",T="[object Uint8Array]",I="[object Uint8ClampedArray]",M="[object Uint16Array]",O="[object Uint32Array]";function H(L,P,q){var W=L.constructor;switch(P){case x:return e(L);case l:case u:return new W(+L);case C:return n(L,q);case _:case S:case b:case E:case N:case T:case I:case M:case O:return o(L,q);case c:return new W;case p:case m:return new W(L);case h:return r(L);case f:return new W;case y:return s(L)}}return rh=H,rh}var ih,d_;function KN(){if(d_)return ih;d_=1;var e=jn(),n=Object.create,r=(function(){function s(){}return function(o){if(!e(o))return{};if(n)return n(o);s.prototype=o;var l=new s;return s.prototype=void 0,l}})();return ih=r,ih}var sh,f_;function XN(){if(f_)return sh;f_=1;var e=KN(),n=pu(),r=hu();function s(o){return typeof o.constructor=="function"&&!r(o)?e(n(o)):{}}return sh=s,sh}var oh,h_;function AL(){if(h_)return oh;h_=1;var e=ro(),n=hr(),r="[object Map]";function s(o){return n(o)&&e(o)==r}return oh=s,oh}var ah,p_;function IL(){if(p_)return ah;p_=1;var e=AL(),n=fu(),r=Tv(),s=r&&r.isMap,o=s?n(s):e;return ah=o,ah}var lh,m_;function ML(){if(m_)return lh;m_=1;var e=ro(),n=hr(),r="[object Set]";function s(o){return n(o)&&e(o)==r}return lh=s,lh}var uh,g_;function PL(){if(g_)return uh;g_=1;var e=ML(),n=fu(),r=Tv(),s=r&&r.isSet,o=s?n(s):e;return uh=o,uh}var ch,v_;function QN(){if(v_)return ch;v_=1;var e=lu(),n=Nv(),r=cu(),s=gL(),o=wL(),l=DN(),u=FN(),c=xL(),p=_L(),h=WN(),f=SL(),m=ro(),y=NL(),x=jL(),C=XN(),_=_t(),S=no(),b=IL(),E=jn(),N=PL(),T=hi(),I=Ji(),M=1,O=2,H=4,L="[object Arguments]",P="[object Array]",q="[object Boolean]",W="[object Date]",B="[object Error]",j="[object Function]",K="[object GeneratorFunction]",U="[object Map]",ee="[object Number]",J="[object Object]",F="[object RegExp]",Y="[object Set]",k="[object String]",$="[object Symbol]",se="[object WeakMap]",D="[object ArrayBuffer]",Q="[object DataView]",te="[object Float32Array]",ae="[object Float64Array]",ce="[object Int8Array]",me="[object Int16Array]",ge="[object Int32Array]",Pe="[object Uint8Array]",Se="[object Uint8ClampedArray]",Oe="[object Uint16Array]",Me="[object Uint32Array]",be={};be[L]=be[P]=be[D]=be[Q]=be[q]=be[W]=be[te]=be[ae]=be[ce]=be[me]=be[ge]=be[U]=be[ee]=be[J]=be[F]=be[Y]=be[k]=be[$]=be[Pe]=be[Se]=be[Oe]=be[Me]=!0,be[B]=be[j]=be[se]=!1;function De(ve,we,Ue,ut,ct,Ze){var Fe,Je=we&M,dt=we&O,Nt=we&H;if(Ue&&(Fe=ct?Ue(ve,ut,ct,Ze):Ue(ve)),Fe!==void 0)return Fe;if(!E(ve))return ve;var ot=_(ve);if(ot){if(Fe=y(ve),!Je)return u(ve,Fe)}else{var gt=m(ve),Ct=gt==j||gt==K;if(S(ve))return l(ve,Je);if(gt==J||gt==L||Ct&&!ct){if(Fe=dt||Ct?{}:C(ve),!Je)return dt?p(ve,o(Fe,ve)):c(ve,s(Fe,ve))}else{if(!be[gt])return ct?ve:{};Fe=x(ve,gt,Je)}}Ze||(Ze=new e);var Ft=Ze.get(ve);if(Ft)return Ft;Ze.set(ve,Fe),N(ve)?ve.forEach(function(ft){Fe.add(De(ft,we,Ue,ft,ve,Ze))}):b(ve)&&ve.forEach(function(ft,wt){Fe.set(wt,De(ft,we,Ue,wt,ve,Ze))});var Xe=Nt?dt?f:h:dt?I:T,vt=ot?void 0:Xe(ve);return n(vt||ve,function(ft,wt){vt&&(wt=ft,ft=ve[wt]),r(Fe,wt,De(ft,we,Ue,wt,ve,Ze))}),Fe}return ch=De,ch}var dh,y_;function OL(){if(y_)return dh;y_=1;var e=QN(),n=4;function r(s){return e(s,n)}return dh=r,dh}var fh,w_;function Mv(){if(w_)return fh;w_=1;function e(n){return function(){return n}}return fh=e,fh}var hh,x_;function LL(){if(x_)return hh;x_=1;function e(n){return function(r,s,o){for(var l=-1,u=Object(r),c=o(r),p=c.length;p--;){var h=c[n?p:++l];if(s(u[h],h,u)===!1)break}return r}}return hh=e,hh}var ph,__;function Pv(){if(__)return ph;__=1;var e=LL(),n=e();return ph=n,ph}var mh,S_;function Ov(){if(S_)return mh;S_=1;var e=Pv(),n=hi();function r(s,o){return s&&e(s,o,n)}return mh=r,mh}var gh,b_;function qL(){if(b_)return gh;b_=1;var e=Pr();function n(r,s){return function(o,l){if(o==null)return o;if(!e(o))return r(o,l);for(var u=o.length,c=s?u:-1,p=Object(o);(s?c--:++c<u)&&l(p[c],c,p)!==!1;);return o}}return gh=n,gh}var vh,k_;function mu(){if(k_)return vh;k_=1;var e=Ov(),n=qL(),r=n(e);return vh=r,vh}var yh,E_;function es(){if(E_)return yh;E_=1;function e(n){return n}return yh=e,yh}var wh,N_;function ZN(){if(N_)return wh;N_=1;var e=es();function n(r){return typeof r=="function"?r:e}return wh=n,wh}var xh,C_;function JN(){if(C_)return xh;C_=1;var e=Nv(),n=mu(),r=ZN(),s=_t();function o(l,u){var c=s(l)?e:n;return c(l,r(u))}return xh=o,xh}var _h,T_;function eC(){return T_||(T_=1,_h=JN()),_h}var Sh,R_;function $L(){if(R_)return Sh;R_=1;var e=mu();function n(r,s){var o=[];return e(r,function(l,u,c){s(l,u,c)&&o.push(l)}),o}return Sh=n,Sh}var bh,j_;function DL(){if(j_)return bh;j_=1;var e="__lodash_hash_undefined__";function n(r){return this.__data__.set(r,e),this}return bh=n,bh}var kh,A_;function FL(){if(A_)return kh;A_=1;function e(n){return this.__data__.has(n)}return kh=e,kh}var Eh,I_;function tC(){if(I_)return Eh;I_=1;var e=Ev(),n=DL(),r=FL();function s(o){var l=-1,u=o==null?0:o.length;for(this.__data__=new e;++l<u;)this.add(o[l])}return s.prototype.add=s.prototype.push=n,s.prototype.has=r,Eh=s,Eh}var Nh,M_;function zL(){if(M_)return Nh;M_=1;function e(n,r){for(var s=-1,o=n==null?0:n.length;++s<o;)if(r(n[s],s,n))return!0;return!1}return Nh=e,Nh}var Ch,P_;function nC(){if(P_)return Ch;P_=1;function e(n,r){return n.has(r)}return Ch=e,Ch}var Th,O_;function rC(){if(O_)return Th;O_=1;var e=tC(),n=zL(),r=nC(),s=1,o=2;function l(u,c,p,h,f,m){var y=p&s,x=u.length,C=c.length;if(x!=C&&!(y&&C>x))return!1;var _=m.get(u),S=m.get(c);if(_&&S)return _==c&&S==u;var b=-1,E=!0,N=p&o?new e:void 0;for(m.set(u,c),m.set(c,u);++b<x;){var T=u[b],I=c[b];if(h)var M=y?h(I,T,b,c,u,m):h(T,I,b,u,c,m);if(M!==void 0){if(M)continue;E=!1;break}if(N){if(!n(c,function(O,H){if(!r(N,H)&&(T===O||f(T,O,p,h,m)))return N.push(H)})){E=!1;break}}else if(!(T===I||f(T,I,p,h,m))){E=!1;break}}return m.delete(u),m.delete(c),E}return Th=l,Th}var Rh,L_;function BL(){if(L_)return Rh;L_=1;function e(n){var r=-1,s=Array(n.size);return n.forEach(function(o,l){s[++r]=[l,o]}),s}return Rh=e,Rh}var jh,q_;function Lv(){if(q_)return jh;q_=1;function e(n){var r=-1,s=Array(n.size);return n.forEach(function(o){s[++r]=o}),s}return jh=e,jh}var Ah,$_;function UL(){if($_)return Ah;$_=1;var e=to(),n=GN(),r=eo(),s=rC(),o=BL(),l=Lv(),u=1,c=2,p="[object Boolean]",h="[object Date]",f="[object Error]",m="[object Map]",y="[object Number]",x="[object RegExp]",C="[object Set]",_="[object String]",S="[object Symbol]",b="[object ArrayBuffer]",E="[object DataView]",N=e?e.prototype:void 0,T=N?N.valueOf:void 0;function I(M,O,H,L,P,q,W){switch(H){case E:if(M.byteLength!=O.byteLength||M.byteOffset!=O.byteOffset)return!1;M=M.buffer,O=O.buffer;case b:return!(M.byteLength!=O.byteLength||!q(new n(M),new n(O)));case p:case h:case y:return r(+M,+O);case f:return M.name==O.name&&M.message==O.message;case x:case _:return M==O+"";case m:var B=o;case C:var j=L&u;if(B||(B=l),M.size!=O.size&&!j)return!1;var K=W.get(M);if(K)return K==O;L|=c,W.set(M,O);var U=s(B(M),B(O),L,P,q,W);return W.delete(M),U;case S:if(T)return T.call(M)==T.call(O)}return!1}return Ah=I,Ah}var Ih,D_;function HL(){if(D_)return Ih;D_=1;var e=WN(),n=1,r=Object.prototype,s=r.hasOwnProperty;function o(l,u,c,p,h,f){var m=c&n,y=e(l),x=y.length,C=e(u),_=C.length;if(x!=_&&!m)return!1;for(var S=x;S--;){var b=y[S];if(!(m?b in u:s.call(u,b)))return!1}var E=f.get(l),N=f.get(u);if(E&&N)return E==u&&N==l;var T=!0;f.set(l,u),f.set(u,l);for(var I=m;++S<x;){b=y[S];var M=l[b],O=u[b];if(p)var H=m?p(O,M,b,u,l,f):p(M,O,b,l,u,f);if(!(H===void 0?M===O||h(M,O,c,p,f):H)){T=!1;break}I||(I=b=="constructor")}if(T&&!I){var L=l.constructor,P=u.constructor;L!=P&&"constructor"in l&&"constructor"in u&&!(typeof L=="function"&&L instanceof L&&typeof P=="function"&&P instanceof P)&&(T=!1)}return f.delete(l),f.delete(u),T}return Ih=o,Ih}var Mh,F_;function WL(){if(F_)return Mh;F_=1;var e=lu(),n=rC(),r=UL(),s=HL(),o=ro(),l=_t(),u=no(),c=ma(),p=1,h="[object Arguments]",f="[object Array]",m="[object Object]",y=Object.prototype,x=y.hasOwnProperty;function C(_,S,b,E,N,T){var I=l(_),M=l(S),O=I?f:o(_),H=M?f:o(S);O=O==h?m:O,H=H==h?m:H;var L=O==m,P=H==m,q=O==H;if(q&&u(_)){if(!u(S))return!1;I=!0,L=!1}if(q&&!L)return T||(T=new e),I||c(_)?n(_,S,b,E,N,T):r(_,S,O,b,E,N,T);if(!(b&p)){var W=L&&x.call(_,"__wrapped__"),B=P&&x.call(S,"__wrapped__");if(W||B){var j=W?_.value():_,K=B?S.value():S;return T||(T=new e),N(j,K,b,E,T)}}return q?(T||(T=new e),s(_,S,b,E,N,T)):!1}return Mh=C,Mh}var Ph,z_;function iC(){if(z_)return Ph;z_=1;var e=WL(),n=hr();function r(s,o,l,u,c){return s===o?!0:s==null||o==null||!n(s)&&!n(o)?s!==s&&o!==o:e(s,o,l,u,r,c)}return Ph=r,Ph}var Oh,B_;function VL(){if(B_)return Oh;B_=1;var e=lu(),n=iC(),r=1,s=2;function o(l,u,c,p){var h=c.length,f=h,m=!p;if(l==null)return!f;for(l=Object(l);h--;){var y=c[h];if(m&&y[2]?y[1]!==l[y[0]]:!(y[0]in l))return!1}for(;++h<f;){y=c[h];var x=y[0],C=l[x],_=y[1];if(m&&y[2]){if(C===void 0&&!(x in l))return!1}else{var S=new e;if(p)var b=p(C,_,x,l,u,S);if(!(b===void 0?n(_,C,r|s,p,S):b))return!1}}return!0}return Oh=o,Oh}var Lh,U_;function sC(){if(U_)return Lh;U_=1;var e=jn();function n(r){return r===r&&!e(r)}return Lh=n,Lh}var qh,H_;function GL(){if(H_)return qh;H_=1;var e=sC(),n=hi();function r(s){for(var o=n(s),l=o.length;l--;){var u=o[l],c=s[u];o[l]=[u,c,e(c)]}return o}return qh=r,qh}var $h,W_;function oC(){if(W_)return $h;W_=1;function e(n,r){return function(s){return s==null?!1:s[n]===r&&(r!==void 0||n in Object(s))}}return $h=e,$h}var Dh,V_;function YL(){if(V_)return Dh;V_=1;var e=VL(),n=GL(),r=oC();function s(o){var l=n(o);return l.length==1&&l[0][2]?r(l[0][0],l[0][1]):function(u){return u===o||e(u,o,l)}}return Dh=s,Dh}var Fh,G_;function io(){if(G_)return Fh;G_=1;var e=Qi(),n=hr(),r="[object Symbol]";function s(o){return typeof o=="symbol"||n(o)&&e(o)==r}return Fh=s,Fh}var zh,Y_;function qv(){if(Y_)return zh;Y_=1;var e=_t(),n=io(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,s=/^\w*$/;function o(l,u){if(e(l))return!1;var c=typeof l;return c=="number"||c=="symbol"||c=="boolean"||l==null||n(l)?!0:s.test(l)||!r.test(l)||u!=null&&l in Object(u)}return zh=o,zh}var Bh,K_;function KL(){if(K_)return Bh;K_=1;var e=Ev(),n="Expected a function";function r(s,o){if(typeof s!="function"||o!=null&&typeof o!="function")throw new TypeError(n);var l=function(){var u=arguments,c=o?o.apply(this,u):u[0],p=l.cache;if(p.has(c))return p.get(c);var h=s.apply(this,u);return l.cache=p.set(c,h)||p,h};return l.cache=new(r.Cache||e),l}return r.Cache=e,Bh=r,Bh}var Uh,X_;function XL(){if(X_)return Uh;X_=1;var e=KL(),n=500;function r(s){var o=e(s,function(u){return l.size===n&&l.clear(),u}),l=o.cache;return o}return Uh=r,Uh}var Hh,Q_;function QL(){if(Q_)return Hh;Q_=1;var e=XL(),n=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,s=e(function(o){var l=[];return o.charCodeAt(0)===46&&l.push(""),o.replace(n,function(u,c,p,h){l.push(p?h.replace(r,"$1"):c||u)}),l});return Hh=s,Hh}var Wh,Z_;function gu(){if(Z_)return Wh;Z_=1;function e(n,r){for(var s=-1,o=n==null?0:n.length,l=Array(o);++s<o;)l[s]=r(n[s],s,n);return l}return Wh=e,Wh}var Vh,J_;function ZL(){if(J_)return Vh;J_=1;var e=to(),n=gu(),r=_t(),s=io(),o=e?e.prototype:void 0,l=o?o.toString:void 0;function u(c){if(typeof c=="string")return c;if(r(c))return n(c,u)+"";if(s(c))return l?l.call(c):"";var p=c+"";return p=="0"&&1/c==-1/0?"-0":p}return Vh=u,Vh}var Gh,eS;function aC(){if(eS)return Gh;eS=1;var e=ZL();function n(r){return r==null?"":e(r)}return Gh=n,Gh}var Yh,tS;function vu(){if(tS)return Yh;tS=1;var e=_t(),n=qv(),r=QL(),s=aC();function o(l,u){return e(l)?l:n(l,u)?[l]:r(s(l))}return Yh=o,Yh}var Kh,nS;function ga(){if(nS)return Kh;nS=1;var e=io();function n(r){if(typeof r=="string"||e(r))return r;var s=r+"";return s=="0"&&1/r==-1/0?"-0":s}return Kh=n,Kh}var Xh,rS;function yu(){if(rS)return Xh;rS=1;var e=vu(),n=ga();function r(s,o){o=e(o,s);for(var l=0,u=o.length;s!=null&&l<u;)s=s[n(o[l++])];return l&&l==u?s:void 0}return Xh=r,Xh}var Qh,iS;function JL(){if(iS)return Qh;iS=1;var e=yu();function n(r,s,o){var l=r==null?void 0:e(r,s);return l===void 0?o:l}return Qh=n,Qh}var Zh,sS;function eq(){if(sS)return Zh;sS=1;function e(n,r){return n!=null&&r in Object(n)}return Zh=e,Zh}var Jh,oS;function lC(){if(oS)return Jh;oS=1;var e=vu(),n=pa(),r=_t(),s=du(),o=Cv(),l=ga();function u(c,p,h){p=e(p,c);for(var f=-1,m=p.length,y=!1;++f<m;){var x=l(p[f]);if(!(y=c!=null&&h(c,x)))break;c=c[x]}return y||++f!=m?y:(m=c==null?0:c.length,!!m&&o(m)&&s(x,m)&&(r(c)||n(c)))}return Jh=u,Jh}var ep,aS;function uC(){if(aS)return ep;aS=1;var e=eq(),n=lC();function r(s,o){return s!=null&&n(s,o,e)}return ep=r,ep}var tp,lS;function tq(){if(lS)return tp;lS=1;var e=iC(),n=JL(),r=uC(),s=qv(),o=sC(),l=oC(),u=ga(),c=1,p=2;function h(f,m){return s(f)&&o(m)?l(u(f),m):function(y){var x=n(y,f);return x===void 0&&x===m?r(y,f):e(m,x,c|p)}}return tp=h,tp}var np,uS;function cC(){if(uS)return np;uS=1;function e(n){return function(r){return r==null?void 0:r[n]}}return np=e,np}var rp,cS;function nq(){if(cS)return rp;cS=1;var e=yu();function n(r){return function(s){return e(s,r)}}return rp=n,rp}var ip,dS;function rq(){if(dS)return ip;dS=1;var e=cC(),n=nq(),r=qv(),s=ga();function o(l){return r(l)?e(s(l)):n(l)}return ip=o,ip}var sp,fS;function Or(){if(fS)return sp;fS=1;var e=YL(),n=tq(),r=es(),s=_t(),o=rq();function l(u){return typeof u=="function"?u:u==null?r:typeof u=="object"?s(u)?n(u[0],u[1]):e(u):o(u)}return sp=l,sp}var op,hS;function dC(){if(hS)return op;hS=1;var e=zN(),n=$L(),r=Or(),s=_t();function o(l,u){var c=s(l)?e:n;return c(l,r(u,3))}return op=o,op}var ap,pS;function iq(){if(pS)return ap;pS=1;var e=Object.prototype,n=e.hasOwnProperty;function r(s,o){return s!=null&&n.call(s,o)}return ap=r,ap}var lp,mS;function fC(){if(mS)return lp;mS=1;var e=iq(),n=lC();function r(s,o){return s!=null&&n(s,o,e)}return lp=r,lp}var up,gS;function sq(){if(gS)return up;gS=1;var e=Rv(),n=ro(),r=pa(),s=_t(),o=Pr(),l=no(),u=hu(),c=ma(),p="[object Map]",h="[object Set]",f=Object.prototype,m=f.hasOwnProperty;function y(x){if(x==null)return!0;if(o(x)&&(s(x)||typeof x=="string"||typeof x.splice=="function"||l(x)||c(x)||r(x)))return!x.length;var C=n(x);if(C==p||C==h)return!x.size;if(u(x))return!e(x).length;for(var _ in x)if(m.call(x,_))return!1;return!0}return up=y,up}var cp,vS;function hC(){if(vS)return cp;vS=1;function e(n){return n===void 0}return cp=e,cp}var dp,yS;function pC(){if(yS)return dp;yS=1;var e=mu(),n=Pr();function r(s,o){var l=-1,u=n(s)?Array(s.length):[];return e(s,function(c,p,h){u[++l]=o(c,p,h)}),u}return dp=r,dp}var fp,wS;function mC(){if(wS)return fp;wS=1;var e=gu(),n=Or(),r=pC(),s=_t();function o(l,u){var c=s(l)?e:r;return c(l,n(u,3))}return fp=o,fp}var hp,xS;function oq(){if(xS)return hp;xS=1;function e(n,r,s,o){var l=-1,u=n==null?0:n.length;for(o&&u&&(s=n[++l]);++l<u;)s=r(s,n[l],l,n);return s}return hp=e,hp}var pp,_S;function aq(){if(_S)return pp;_S=1;function e(n,r,s,o,l){return l(n,function(u,c,p){s=o?(o=!1,u):r(s,u,c,p)}),s}return pp=e,pp}var mp,SS;function gC(){if(SS)return mp;SS=1;var e=oq(),n=mu(),r=Or(),s=aq(),o=_t();function l(u,c,p){var h=o(u)?e:s,f=arguments.length<3;return h(u,r(c,4),p,f,n)}return mp=l,mp}var gp,bS;function lq(){if(bS)return gp;bS=1;var e=Qi(),n=_t(),r=hr(),s="[object String]";function o(l){return typeof l=="string"||!n(l)&&r(l)&&e(l)==s}return gp=o,gp}var vp,kS;function uq(){if(kS)return vp;kS=1;var e=cC(),n=e("length");return vp=n,vp}var yp,ES;function cq(){if(ES)return yp;ES=1;var e="\\ud800-\\udfff",n="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",s="\\u20d0-\\u20ff",o=n+r+s,l="\\ufe0e\\ufe0f",u="\\u200d",c=RegExp("["+u+e+o+l+"]");function p(h){return c.test(h)}return yp=p,yp}var wp,NS;function dq(){if(NS)return wp;NS=1;var e="\\ud800-\\udfff",n="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",s="\\u20d0-\\u20ff",o=n+r+s,l="\\ufe0e\\ufe0f",u="["+e+"]",c="["+o+"]",p="\\ud83c[\\udffb-\\udfff]",h="(?:"+c+"|"+p+")",f="[^"+e+"]",m="(?:\\ud83c[\\udde6-\\uddff]){2}",y="[\\ud800-\\udbff][\\udc00-\\udfff]",x="\\u200d",C=h+"?",_="["+l+"]?",S="(?:"+x+"(?:"+[f,m,y].join("|")+")"+_+C+")*",b=_+C+S,E="(?:"+[f+c+"?",c,m,y,u].join("|")+")",N=RegExp(p+"(?="+p+")|"+E+b,"g");function T(I){for(var M=N.lastIndex=0;N.test(I);)++M;return M}return wp=T,wp}var xp,CS;function fq(){if(CS)return xp;CS=1;var e=uq(),n=cq(),r=dq();function s(o){return n(o)?r(o):e(o)}return xp=s,xp}var _p,TS;function hq(){if(TS)return _p;TS=1;var e=Rv(),n=ro(),r=Pr(),s=lq(),o=fq(),l="[object Map]",u="[object Set]";function c(p){if(p==null)return 0;if(r(p))return s(p)?o(p):p.length;var h=n(p);return h==l||h==u?p.size:e(p).length}return _p=c,_p}var Sp,RS;function pq(){if(RS)return Sp;RS=1;var e=Nv(),n=KN(),r=Ov(),s=Or(),o=pu(),l=_t(),u=no(),c=fa(),p=jn(),h=ma();function f(m,y,x){var C=l(m),_=C||u(m)||h(m);if(y=s(y,4),x==null){var S=m&&m.constructor;_?x=C?new S:[]:p(m)?x=c(S)?n(o(m)):{}:x={}}return(_?e:r)(m,function(b,E,N){return y(x,b,E,N)}),x}return Sp=f,Sp}var bp,jS;function mq(){if(jS)return bp;jS=1;var e=to(),n=pa(),r=_t(),s=e?e.isConcatSpreadable:void 0;function o(l){return r(l)||n(l)||!!(s&&l&&l[s])}return bp=o,bp}var kp,AS;function $v(){if(AS)return kp;AS=1;var e=Av(),n=mq();function r(s,o,l,u,c){var p=-1,h=s.length;for(l||(l=n),c||(c=[]);++p<h;){var f=s[p];o>0&&l(f)?o>1?r(f,o-1,l,u,c):e(c,f):u||(c[c.length]=f)}return c}return kp=r,kp}var Ep,IS;function gq(){if(IS)return Ep;IS=1;function e(n,r,s){switch(s.length){case 0:return n.call(r);case 1:return n.call(r,s[0]);case 2:return n.call(r,s[0],s[1]);case 3:return n.call(r,s[0],s[1],s[2])}return n.apply(r,s)}return Ep=e,Ep}var Np,MS;function vC(){if(MS)return Np;MS=1;var e=gq(),n=Math.max;function r(s,o,l){return o=n(o===void 0?s.length-1:o,0),function(){for(var u=arguments,c=-1,p=n(u.length-o,0),h=Array(p);++c<p;)h[c]=u[o+c];c=-1;for(var f=Array(o+1);++c<o;)f[c]=u[c];return f[o]=l(h),e(s,this,f)}}return Np=r,Np}var Cp,PS;function vq(){if(PS)return Cp;PS=1;var e=Mv(),n=LN(),r=es(),s=n?function(o,l){return n(o,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:r;return Cp=s,Cp}var Tp,OS;function yq(){if(OS)return Tp;OS=1;var e=800,n=16,r=Date.now;function s(o){var l=0,u=0;return function(){var c=r(),p=n-(c-u);if(u=c,p>0){if(++l>=e)return arguments[0]}else l=0;return o.apply(void 0,arguments)}}return Tp=s,Tp}var Rp,LS;function yC(){if(LS)return Rp;LS=1;var e=vq(),n=yq(),r=n(e);return Rp=r,Rp}var jp,qS;function wu(){if(qS)return jp;qS=1;var e=es(),n=vC(),r=yC();function s(o,l){return r(n(o,l,e),o+"")}return jp=s,jp}var Ap,$S;function wC(){if($S)return Ap;$S=1;function e(n,r,s,o){for(var l=n.length,u=s+(o?1:-1);o?u--:++u<l;)if(r(n[u],u,n))return u;return-1}return Ap=e,Ap}var Ip,DS;function wq(){if(DS)return Ip;DS=1;function e(n){return n!==n}return Ip=e,Ip}var Mp,FS;function xq(){if(FS)return Mp;FS=1;function e(n,r,s){for(var o=s-1,l=n.length;++o<l;)if(n[o]===r)return o;return-1}return Mp=e,Mp}var Pp,zS;function _q(){if(zS)return Pp;zS=1;var e=wC(),n=wq(),r=xq();function s(o,l,u){return l===l?r(o,l,u):e(o,n,u)}return Pp=s,Pp}var Op,BS;function Sq(){if(BS)return Op;BS=1;var e=_q();function n(r,s){var o=r==null?0:r.length;return!!o&&e(r,s,0)>-1}return Op=n,Op}var Lp,US;function bq(){if(US)return Lp;US=1;function e(n,r,s){for(var o=-1,l=n==null?0:n.length;++o<l;)if(s(r,n[o]))return!0;return!1}return Lp=e,Lp}var qp,HS;function kq(){if(HS)return qp;HS=1;function e(){}return qp=e,qp}var $p,WS;function Eq(){if(WS)return $p;WS=1;var e=VN(),n=kq(),r=Lv(),s=1/0,o=e&&1/r(new e([,-0]))[1]==s?function(l){return new e(l)}:n;return $p=o,$p}var Dp,VS;function Nq(){if(VS)return Dp;VS=1;var e=tC(),n=Sq(),r=bq(),s=nC(),o=Eq(),l=Lv(),u=200;function c(p,h,f){var m=-1,y=n,x=p.length,C=!0,_=[],S=_;if(f)C=!1,y=r;else if(x>=u){var b=h?null:o(p);if(b)return l(b);C=!1,y=s,S=new e}else S=h?[]:_;e:for(;++m<x;){var E=p[m],N=h?h(E):E;if(E=f||E!==0?E:0,C&&N===N){for(var T=S.length;T--;)if(S[T]===N)continue e;h&&S.push(N),_.push(E)}else y(S,N,f)||(S!==_&&S.push(N),_.push(E))}return _}return Dp=c,Dp}var Fp,GS;function xC(){if(GS)return Fp;GS=1;var e=Pr(),n=hr();function r(s){return n(s)&&e(s)}return Fp=r,Fp}var zp,YS;function Cq(){if(YS)return zp;YS=1;var e=$v(),n=wu(),r=Nq(),s=xC(),o=n(function(l){return r(e(l,1,s,!0))});return zp=o,zp}var Bp,KS;function Tq(){if(KS)return Bp;KS=1;var e=gu();function n(r,s){return e(s,function(o){return r[o]})}return Bp=n,Bp}var Up,XS;function _C(){if(XS)return Up;XS=1;var e=Tq(),n=hi();function r(s){return s==null?[]:e(s,n(s))}return Up=r,Up}var Hp,QS;function An(){if(QS)return Hp;QS=1;var e;if(typeof bv=="function")try{e={clone:OL(),constant:Mv(),each:eC(),filter:dC(),has:fC(),isArray:_t(),isEmpty:sq(),isFunction:fa(),isUndefined:hC(),keys:hi(),map:mC(),reduce:gC(),size:hq(),transform:pq(),union:Cq(),values:_C()}}catch{}return e||(e=window._),Hp=e,Hp}var Wp,ZS;function Dv(){if(ZS)return Wp;ZS=1;var e=An();Wp=o;var n="\0",r="\0",s="";function o(f){this._isDirected=e.has(f,"directed")?f.directed:!0,this._isMultigraph=e.has(f,"multigraph")?f.multigraph:!1,this._isCompound=e.has(f,"compound")?f.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[r]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}o.prototype._nodeCount=0,o.prototype._edgeCount=0,o.prototype.isDirected=function(){return this._isDirected},o.prototype.isMultigraph=function(){return this._isMultigraph},o.prototype.isCompound=function(){return this._isCompound},o.prototype.setGraph=function(f){return this._label=f,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(f){return e.isFunction(f)||(f=e.constant(f)),this._defaultNodeLabelFn=f,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var f=this;return e.filter(this.nodes(),function(m){return e.isEmpty(f._in[m])})},o.prototype.sinks=function(){var f=this;return e.filter(this.nodes(),function(m){return e.isEmpty(f._out[m])})},o.prototype.setNodes=function(f,m){var y=arguments,x=this;return e.each(f,function(C){y.length>1?x.setNode(C,m):x.setNode(C)}),this},o.prototype.setNode=function(f,m){return e.has(this._nodes,f)?(arguments.length>1&&(this._nodes[f]=m),this):(this._nodes[f]=arguments.length>1?m:this._defaultNodeLabelFn(f),this._isCompound&&(this._parent[f]=r,this._children[f]={},this._children[r][f]=!0),this._in[f]={},this._preds[f]={},this._out[f]={},this._sucs[f]={},++this._nodeCount,this)},o.prototype.node=function(f){return this._nodes[f]},o.prototype.hasNode=function(f){return e.has(this._nodes,f)},o.prototype.removeNode=function(f){var m=this;if(e.has(this._nodes,f)){var y=function(x){m.removeEdge(m._edgeObjs[x])};delete this._nodes[f],this._isCompound&&(this._removeFromParentsChildList(f),delete this._parent[f],e.each(this.children(f),function(x){m.setParent(x)}),delete this._children[f]),e.each(e.keys(this._in[f]),y),delete this._in[f],delete this._preds[f],e.each(e.keys(this._out[f]),y),delete this._out[f],delete this._sucs[f],--this._nodeCount}return this},o.prototype.setParent=function(f,m){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(m))m=r;else{m+="";for(var y=m;!e.isUndefined(y);y=this.parent(y))if(y===f)throw new Error("Setting "+m+" as parent of "+f+" would create a cycle");this.setNode(m)}return this.setNode(f),this._removeFromParentsChildList(f),this._parent[f]=m,this._children[m][f]=!0,this},o.prototype._removeFromParentsChildList=function(f){delete this._children[this._parent[f]][f]},o.prototype.parent=function(f){if(this._isCompound){var m=this._parent[f];if(m!==r)return m}},o.prototype.children=function(f){if(e.isUndefined(f)&&(f=r),this._isCompound){var m=this._children[f];if(m)return e.keys(m)}else{if(f===r)return this.nodes();if(this.hasNode(f))return[]}},o.prototype.predecessors=function(f){var m=this._preds[f];if(m)return e.keys(m)},o.prototype.successors=function(f){var m=this._sucs[f];if(m)return e.keys(m)},o.prototype.neighbors=function(f){var m=this.predecessors(f);if(m)return e.union(m,this.successors(f))},o.prototype.isLeaf=function(f){var m;return this.isDirected()?m=this.successors(f):m=this.neighbors(f),m.length===0},o.prototype.filterNodes=function(f){var m=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});m.setGraph(this.graph());var y=this;e.each(this._nodes,function(_,S){f(S)&&m.setNode(S,_)}),e.each(this._edgeObjs,function(_){m.hasNode(_.v)&&m.hasNode(_.w)&&m.setEdge(_,y.edge(_))});var x={};function C(_){var S=y.parent(_);return S===void 0||m.hasNode(S)?(x[_]=S,S):S in x?x[S]:C(S)}return this._isCompound&&e.each(m.nodes(),function(_){m.setParent(_,C(_))}),m},o.prototype.setDefaultEdgeLabel=function(f){return e.isFunction(f)||(f=e.constant(f)),this._defaultEdgeLabelFn=f,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(f,m){var y=this,x=arguments;return e.reduce(f,function(C,_){return x.length>1?y.setEdge(C,_,m):y.setEdge(C,_),_}),this},o.prototype.setEdge=function(){var f,m,y,x,C=!1,_=arguments[0];typeof _=="object"&&_!==null&&"v"in _?(f=_.v,m=_.w,y=_.name,arguments.length===2&&(x=arguments[1],C=!0)):(f=_,m=arguments[1],y=arguments[3],arguments.length>2&&(x=arguments[2],C=!0)),f=""+f,m=""+m,e.isUndefined(y)||(y=""+y);var S=c(this._isDirected,f,m,y);if(e.has(this._edgeLabels,S))return C&&(this._edgeLabels[S]=x),this;if(!e.isUndefined(y)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(f),this.setNode(m),this._edgeLabels[S]=C?x:this._defaultEdgeLabelFn(f,m,y);var b=p(this._isDirected,f,m,y);return f=b.v,m=b.w,Object.freeze(b),this._edgeObjs[S]=b,l(this._preds[m],f),l(this._sucs[f],m),this._in[m][S]=b,this._out[f][S]=b,this._edgeCount++,this},o.prototype.edge=function(f,m,y){var x=arguments.length===1?h(this._isDirected,arguments[0]):c(this._isDirected,f,m,y);return this._edgeLabels[x]},o.prototype.hasEdge=function(f,m,y){var x=arguments.length===1?h(this._isDirected,arguments[0]):c(this._isDirected,f,m,y);return e.has(this._edgeLabels,x)},o.prototype.removeEdge=function(f,m,y){var x=arguments.length===1?h(this._isDirected,arguments[0]):c(this._isDirected,f,m,y),C=this._edgeObjs[x];return C&&(f=C.v,m=C.w,delete this._edgeLabels[x],delete this._edgeObjs[x],u(this._preds[m],f),u(this._sucs[f],m),delete this._in[m][x],delete this._out[f][x],this._edgeCount--),this},o.prototype.inEdges=function(f,m){var y=this._in[f];if(y){var x=e.values(y);return m?e.filter(x,function(C){return C.v===m}):x}},o.prototype.outEdges=function(f,m){var y=this._out[f];if(y){var x=e.values(y);return m?e.filter(x,function(C){return C.w===m}):x}},o.prototype.nodeEdges=function(f,m){var y=this.inEdges(f,m);if(y)return y.concat(this.outEdges(f,m))};function l(f,m){f[m]?f[m]++:f[m]=1}function u(f,m){--f[m]||delete f[m]}function c(f,m,y,x){var C=""+m,_=""+y;if(!f&&C>_){var S=C;C=_,_=S}return C+s+_+s+(e.isUndefined(x)?n:x)}function p(f,m,y,x){var C=""+m,_=""+y;if(!f&&C>_){var S=C;C=_,_=S}var b={v:C,w:_};return x&&(b.name=x),b}function h(f,m){return c(f,m.v,m.w,m.name)}return Wp}var Vp,JS;function Rq(){return JS||(JS=1,Vp="2.1.8"),Vp}var Gp,eb;function jq(){return eb||(eb=1,Gp={Graph:Dv(),version:Rq()}),Gp}var Yp,tb;function Aq(){if(tb)return Yp;tb=1;var e=An(),n=Dv();Yp={write:r,read:l};function r(u){var c={options:{directed:u.isDirected(),multigraph:u.isMultigraph(),compound:u.isCompound()},nodes:s(u),edges:o(u)};return e.isUndefined(u.graph())||(c.value=e.clone(u.graph())),c}function s(u){return e.map(u.nodes(),function(c){var p=u.node(c),h=u.parent(c),f={v:c};return e.isUndefined(p)||(f.value=p),e.isUndefined(h)||(f.parent=h),f})}function o(u){return e.map(u.edges(),function(c){var p=u.edge(c),h={v:c.v,w:c.w};return e.isUndefined(c.name)||(h.name=c.name),e.isUndefined(p)||(h.value=p),h})}function l(u){var c=new n(u.options).setGraph(u.value);return e.each(u.nodes,function(p){c.setNode(p.v,p.value),p.parent&&c.setParent(p.v,p.parent)}),e.each(u.edges,function(p){c.setEdge({v:p.v,w:p.w,name:p.name},p.value)}),c}return Yp}var Kp,nb;function Iq(){if(nb)return Kp;nb=1;var e=An();Kp=n;function n(r){var s={},o=[],l;function u(c){e.has(s,c)||(s[c]=!0,l.push(c),e.each(r.successors(c),u),e.each(r.predecessors(c),u))}return e.each(r.nodes(),function(c){l=[],u(c),l.length&&o.push(l)}),o}return Kp}var Xp,rb;function SC(){if(rb)return Xp;rb=1;var e=An();Xp=n;function n(){this._arr=[],this._keyIndices={}}return n.prototype.size=function(){return this._arr.length},n.prototype.keys=function(){return this._arr.map(function(r){return r.key})},n.prototype.has=function(r){return e.has(this._keyIndices,r)},n.prototype.priority=function(r){var s=this._keyIndices[r];if(s!==void 0)return this._arr[s].priority},n.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},n.prototype.add=function(r,s){var o=this._keyIndices;if(r=String(r),!e.has(o,r)){var l=this._arr,u=l.length;return o[r]=u,l.push({key:r,priority:s}),this._decrease(u),!0}return!1},n.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var r=this._arr.pop();return delete this._keyIndices[r.key],this._heapify(0),r.key},n.prototype.decrease=function(r,s){var o=this._keyIndices[r];if(s>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+r+" Old: "+this._arr[o].priority+" New: "+s);this._arr[o].priority=s,this._decrease(o)},n.prototype._heapify=function(r){var s=this._arr,o=2*r,l=o+1,u=r;o<s.length&&(u=s[o].priority<s[u].priority?o:u,l<s.length&&(u=s[l].priority<s[u].priority?l:u),u!==r&&(this._swap(r,u),this._heapify(u)))},n.prototype._decrease=function(r){for(var s=this._arr,o=s[r].priority,l;r!==0&&(l=r>>1,!(s[l].priority<o));)this._swap(r,l),r=l},n.prototype._swap=function(r,s){var o=this._arr,l=this._keyIndices,u=o[r],c=o[s];o[r]=c,o[s]=u,l[c.key]=r,l[u.key]=s},Xp}var Qp,ib;function bC(){if(ib)return Qp;ib=1;var e=An(),n=SC();Qp=s;var r=e.constant(1);function s(l,u,c,p){return o(l,String(u),c||r,p||function(h){return l.outEdges(h)})}function o(l,u,c,p){var h={},f=new n,m,y,x=function(C){var _=C.v!==m?C.v:C.w,S=h[_],b=c(C),E=y.distance+b;if(b<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+C+" Weight: "+b);E<S.distance&&(S.distance=E,S.predecessor=m,f.decrease(_,E))};for(l.nodes().forEach(function(C){var _=C===u?0:Number.POSITIVE_INFINITY;h[C]={distance:_},f.add(C,_)});f.size()>0&&(m=f.removeMin(),y=h[m],y.distance!==Number.POSITIVE_INFINITY);)p(m).forEach(x);return h}return Qp}var Zp,sb;function Mq(){if(sb)return Zp;sb=1;var e=bC(),n=An();Zp=r;function r(s,o,l){return n.transform(s.nodes(),function(u,c){u[c]=e(s,c,o,l)},{})}return Zp}var Jp,ob;function kC(){if(ob)return Jp;ob=1;var e=An();Jp=n;function n(r){var s=0,o=[],l={},u=[];function c(p){var h=l[p]={onStack:!0,lowlink:s,index:s++};if(o.push(p),r.successors(p).forEach(function(y){e.has(l,y)?l[y].onStack&&(h.lowlink=Math.min(h.lowlink,l[y].index)):(c(y),h.lowlink=Math.min(h.lowlink,l[y].lowlink))}),h.lowlink===h.index){var f=[],m;do m=o.pop(),l[m].onStack=!1,f.push(m);while(p!==m);u.push(f)}}return r.nodes().forEach(function(p){e.has(l,p)||c(p)}),u}return Jp}var em,ab;function Pq(){if(ab)return em;ab=1;var e=An(),n=kC();em=r;function r(s){return e.filter(n(s),function(o){return o.length>1||o.length===1&&s.hasEdge(o[0],o[0])})}return em}var tm,lb;function Oq(){if(lb)return tm;lb=1;var e=An();tm=r;var n=e.constant(1);function r(o,l,u){return s(o,l||n,u||function(c){return o.outEdges(c)})}function s(o,l,u){var c={},p=o.nodes();return p.forEach(function(h){c[h]={},c[h][h]={distance:0},p.forEach(function(f){h!==f&&(c[h][f]={distance:Number.POSITIVE_INFINITY})}),u(h).forEach(function(f){var m=f.v===h?f.w:f.v,y=l(f);c[h][m]={distance:y,predecessor:h}})}),p.forEach(function(h){var f=c[h];p.forEach(function(m){var y=c[m];p.forEach(function(x){var C=y[h],_=f[x],S=y[x],b=C.distance+_.distance;b<S.distance&&(S.distance=b,S.predecessor=_.predecessor)})})}),c}return tm}var nm,ub;function EC(){if(ub)return nm;ub=1;var e=An();nm=n,n.CycleException=r;function n(s){var o={},l={},u=[];function c(p){if(e.has(l,p))throw new r;e.has(o,p)||(l[p]=!0,o[p]=!0,e.each(s.predecessors(p),c),delete l[p],u.push(p))}if(e.each(s.sinks(),c),e.size(o)!==s.nodeCount())throw new r;return u}function r(){}return r.prototype=new Error,nm}var rm,cb;function Lq(){if(cb)return rm;cb=1;var e=EC();rm=n;function n(r){try{e(r)}catch(s){if(s instanceof e.CycleException)return!1;throw s}return!0}return rm}var im,db;function NC(){if(db)return im;db=1;var e=An();im=n;function n(s,o,l){e.isArray(o)||(o=[o]);var u=(s.isDirected()?s.successors:s.neighbors).bind(s),c=[],p={};return e.each(o,function(h){if(!s.hasNode(h))throw new Error("Graph does not have node: "+h);r(s,h,l==="post",p,u,c)}),c}function r(s,o,l,u,c,p){e.has(u,o)||(u[o]=!0,l||p.push(o),e.each(c(o),function(h){r(s,h,l,u,c,p)}),l&&p.push(o))}return im}var sm,fb;function qq(){if(fb)return sm;fb=1;var e=NC();sm=n;function n(r,s){return e(r,s,"post")}return sm}var om,hb;function $q(){if(hb)return om;hb=1;var e=NC();om=n;function n(r,s){return e(r,s,"pre")}return om}var am,pb;function Dq(){if(pb)return am;pb=1;var e=An(),n=Dv(),r=SC();am=s;function s(o,l){var u=new n,c={},p=new r,h;function f(y){var x=y.v===h?y.w:y.v,C=p.priority(x);if(C!==void 0){var _=l(y);_<C&&(c[x]=h,p.decrease(x,_))}}if(o.nodeCount()===0)return u;e.each(o.nodes(),function(y){p.add(y,Number.POSITIVE_INFINITY),u.setNode(y)}),p.decrease(o.nodes()[0],0);for(var m=!1;p.size()>0;){if(h=p.removeMin(),e.has(c,h))u.setEdge(h,c[h]);else{if(m)throw new Error("Input graph is not connected: "+o);m=!0}o.nodeEdges(h).forEach(f)}return u}return am}var lm,mb;function Fq(){return mb||(mb=1,lm={components:Iq(),dijkstra:bC(),dijkstraAll:Mq(),findCycles:Pq(),floydWarshall:Oq(),isAcyclic:Lq(),postorder:qq(),preorder:$q(),prim:Dq(),tarjan:kC(),topsort:EC()}),lm}var um,gb;function zq(){if(gb)return um;gb=1;var e=jq();return um={Graph:e.Graph,json:Aq(),alg:Fq(),version:e.version},um}var cm,vb;function Jn(){if(vb)return cm;vb=1;var e;if(typeof bv=="function")try{e=zq()}catch{}return e||(e=window.graphlib),cm=e,cm}var dm,yb;function Bq(){if(yb)return dm;yb=1;var e=QN(),n=1,r=4;function s(o){return e(o,n|r)}return dm=s,dm}var fm,wb;function xu(){if(wb)return fm;wb=1;var e=eo(),n=Pr(),r=du(),s=jn();function o(l,u,c){if(!s(c))return!1;var p=typeof u;return(p=="number"?n(c)&&r(u,c.length):p=="string"&&u in c)?e(c[u],l):!1}return fm=o,fm}var hm,xb;function Uq(){if(xb)return hm;xb=1;var e=wu(),n=eo(),r=xu(),s=Ji(),o=Object.prototype,l=o.hasOwnProperty,u=e(function(c,p){c=Object(c);var h=-1,f=p.length,m=f>2?p[2]:void 0;for(m&&r(p[0],p[1],m)&&(f=1);++h<f;)for(var y=p[h],x=s(y),C=-1,_=x.length;++C<_;){var S=x[C],b=c[S];(b===void 0||n(b,o[S])&&!l.call(c,S))&&(c[S]=y[S])}return c});return hm=u,hm}var pm,_b;function Hq(){if(_b)return pm;_b=1;var e=Or(),n=Pr(),r=hi();function s(o){return function(l,u,c){var p=Object(l);if(!n(l)){var h=e(u,3);l=r(l),u=function(m){return h(p[m],m,p)}}var f=o(l,u,c);return f>-1?p[h?l[f]:f]:void 0}}return pm=s,pm}var mm,Sb;function Wq(){if(Sb)return mm;Sb=1;var e=/\s/;function n(r){for(var s=r.length;s--&&e.test(r.charAt(s)););return s}return mm=n,mm}var gm,bb;function Vq(){if(bb)return gm;bb=1;var e=Wq(),n=/^\s+/;function r(s){return s&&s.slice(0,e(s)+1).replace(n,"")}return gm=r,gm}var vm,kb;function Gq(){if(kb)return vm;kb=1;var e=Vq(),n=jn(),r=io(),s=NaN,o=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,u=/^0o[0-7]+$/i,c=parseInt;function p(h){if(typeof h=="number")return h;if(r(h))return s;if(n(h)){var f=typeof h.valueOf=="function"?h.valueOf():h;h=n(f)?f+"":f}if(typeof h!="string")return h===0?h:+h;h=e(h);var m=l.test(h);return m||u.test(h)?c(h.slice(2),m?2:8):o.test(h)?s:+h}return vm=p,vm}var ym,Eb;function CC(){if(Eb)return ym;Eb=1;var e=Gq(),n=1/0,r=17976931348623157e292;function s(o){if(!o)return o===0?o:0;if(o=e(o),o===n||o===-n){var l=o<0?-1:1;return l*r}return o===o?o:0}return ym=s,ym}var wm,Nb;function Yq(){if(Nb)return wm;Nb=1;var e=CC();function n(r){var s=e(r),o=s%1;return s===s?o?s-o:s:0}return wm=n,wm}var xm,Cb;function Kq(){if(Cb)return xm;Cb=1;var e=wC(),n=Or(),r=Yq(),s=Math.max;function o(l,u,c){var p=l==null?0:l.length;if(!p)return-1;var h=c==null?0:r(c);return h<0&&(h=s(p+h,0)),e(l,n(u,3),h)}return xm=o,xm}var _m,Tb;function Xq(){if(Tb)return _m;Tb=1;var e=Hq(),n=Kq(),r=e(n);return _m=r,_m}var Sm,Rb;function TC(){if(Rb)return Sm;Rb=1;var e=$v();function n(r){var s=r==null?0:r.length;return s?e(r,1):[]}return Sm=n,Sm}var bm,jb;function Qq(){if(jb)return bm;jb=1;var e=Pv(),n=ZN(),r=Ji();function s(o,l){return o==null?o:e(o,n(l),r)}return bm=s,bm}var km,Ab;function Zq(){if(Ab)return km;Ab=1;function e(n){var r=n==null?0:n.length;return r?n[r-1]:void 0}return km=e,km}var Em,Ib;function Jq(){if(Ib)return Em;Ib=1;var e=uu(),n=Ov(),r=Or();function s(o,l){var u={};return l=r(l,3),n(o,function(c,p,h){e(u,p,l(c,p,h))}),u}return Em=s,Em}var Nm,Mb;function Fv(){if(Mb)return Nm;Mb=1;var e=io();function n(r,s,o){for(var l=-1,u=r.length;++l<u;){var c=r[l],p=s(c);if(p!=null&&(h===void 0?p===p&&!e(p):o(p,h)))var h=p,f=c}return f}return Nm=n,Nm}var Cm,Pb;function e$(){if(Pb)return Cm;Pb=1;function e(n,r){return n>r}return Cm=e,Cm}var Tm,Ob;function t$(){if(Ob)return Tm;Ob=1;var e=Fv(),n=e$(),r=es();function s(o){return o&&o.length?e(o,r,n):void 0}return Tm=s,Tm}var Rm,Lb;function RC(){if(Lb)return Rm;Lb=1;var e=uu(),n=eo();function r(s,o,l){(l!==void 0&&!n(s[o],l)||l===void 0&&!(o in s))&&e(s,o,l)}return Rm=r,Rm}var jm,qb;function n$(){if(qb)return jm;qb=1;var e=Qi(),n=pu(),r=hr(),s="[object Object]",o=Function.prototype,l=Object.prototype,u=o.toString,c=l.hasOwnProperty,p=u.call(Object);function h(f){if(!r(f)||e(f)!=s)return!1;var m=n(f);if(m===null)return!0;var y=c.call(m,"constructor")&&m.constructor;return typeof y=="function"&&y instanceof y&&u.call(y)==p}return jm=h,jm}var Am,$b;function jC(){if($b)return Am;$b=1;function e(n,r){if(!(r==="constructor"&&typeof n[r]=="function")&&r!="__proto__")return n[r]}return Am=e,Am}var Im,Db;function r$(){if(Db)return Im;Db=1;var e=ha(),n=Ji();function r(s){return e(s,n(s))}return Im=r,Im}var Mm,Fb;function i$(){if(Fb)return Mm;Fb=1;var e=RC(),n=DN(),r=YN(),s=FN(),o=XN(),l=pa(),u=_t(),c=xC(),p=no(),h=fa(),f=jn(),m=n$(),y=ma(),x=jC(),C=r$();function _(S,b,E,N,T,I,M){var O=x(S,E),H=x(b,E),L=M.get(H);if(L){e(S,E,L);return}var P=I?I(O,H,E+"",S,b,M):void 0,q=P===void 0;if(q){var W=u(H),B=!W&&p(H),j=!W&&!B&&y(H);P=H,W||B||j?u(O)?P=O:c(O)?P=s(O):B?(q=!1,P=n(H,!0)):j?(q=!1,P=r(H,!0)):P=[]:m(H)||l(H)?(P=O,l(O)?P=C(O):(!f(O)||h(O))&&(P=o(H))):q=!1}q&&(M.set(H,P),T(P,H,N,I,M),M.delete(H)),e(S,E,P)}return Mm=_,Mm}var Pm,zb;function s$(){if(zb)return Pm;zb=1;var e=lu(),n=RC(),r=Pv(),s=i$(),o=jn(),l=Ji(),u=jC();function c(p,h,f,m,y){p!==h&&r(h,function(x,C){if(y||(y=new e),o(x))s(p,h,C,f,c,m,y);else{var _=m?m(u(p,C),x,C+"",p,h,y):void 0;_===void 0&&(_=x),n(p,C,_)}},l)}return Pm=c,Pm}var Om,Bb;function o$(){if(Bb)return Om;Bb=1;var e=wu(),n=xu();function r(s){return e(function(o,l){var u=-1,c=l.length,p=c>1?l[c-1]:void 0,h=c>2?l[2]:void 0;for(p=s.length>3&&typeof p=="function"?(c--,p):void 0,h&&n(l[0],l[1],h)&&(p=c<3?void 0:p,c=1),o=Object(o);++u<c;){var f=l[u];f&&s(o,f,u,p)}return o})}return Om=r,Om}var Lm,Ub;function a$(){if(Ub)return Lm;Ub=1;var e=s$(),n=o$(),r=n(function(s,o,l){e(s,o,l)});return Lm=r,Lm}var qm,Hb;function AC(){if(Hb)return qm;Hb=1;function e(n,r){return n<r}return qm=e,qm}var $m,Wb;function l$(){if(Wb)return $m;Wb=1;var e=Fv(),n=AC(),r=es();function s(o){return o&&o.length?e(o,r,n):void 0}return $m=s,$m}var Dm,Vb;function u$(){if(Vb)return Dm;Vb=1;var e=Fv(),n=Or(),r=AC();function s(o,l){return o&&o.length?e(o,n(l,2),r):void 0}return Dm=s,Dm}var Fm,Gb;function c$(){if(Gb)return Fm;Gb=1;var e=tr(),n=function(){return e.Date.now()};return Fm=n,Fm}var zm,Yb;function d$(){if(Yb)return zm;Yb=1;var e=cu(),n=vu(),r=du(),s=jn(),o=ga();function l(u,c,p,h){if(!s(u))return u;c=n(c,u);for(var f=-1,m=c.length,y=m-1,x=u;x!=null&&++f<m;){var C=o(c[f]),_=p;if(C==="__proto__"||C==="constructor"||C==="prototype")return u;if(f!=y){var S=x[C];_=h?h(S,C,x):void 0,_===void 0&&(_=s(S)?S:r(c[f+1])?[]:{})}e(x,C,_),x=x[C]}return u}return zm=l,zm}var Bm,Kb;function f$(){if(Kb)return Bm;Kb=1;var e=yu(),n=d$(),r=vu();function s(o,l,u){for(var c=-1,p=l.length,h={};++c<p;){var f=l[c],m=e(o,f);u(m,f)&&n(h,r(f,o),m)}return h}return Bm=s,Bm}var Um,Xb;function h$(){if(Xb)return Um;Xb=1;var e=f$(),n=uC();function r(s,o){return e(s,o,function(l,u){return n(s,u)})}return Um=r,Um}var Hm,Qb;function p$(){if(Qb)return Hm;Qb=1;var e=TC(),n=vC(),r=yC();function s(o){return r(n(o,void 0,e),o+"")}return Hm=s,Hm}var Wm,Zb;function m$(){if(Zb)return Wm;Zb=1;var e=h$(),n=p$(),r=n(function(s,o){return s==null?{}:e(s,o)});return Wm=r,Wm}var Vm,Jb;function g$(){if(Jb)return Vm;Jb=1;var e=Math.ceil,n=Math.max;function r(s,o,l,u){for(var c=-1,p=n(e((o-s)/(l||1)),0),h=Array(p);p--;)h[u?p:++c]=s,s+=l;return h}return Vm=r,Vm}var Gm,ek;function v$(){if(ek)return Gm;ek=1;var e=g$(),n=xu(),r=CC();function s(o){return function(l,u,c){return c&&typeof c!="number"&&n(l,u,c)&&(u=c=void 0),l=r(l),u===void 0?(u=l,l=0):u=r(u),c=c===void 0?l<u?1:-1:r(c),e(l,u,c,o)}}return Gm=s,Gm}var Ym,tk;function y$(){if(tk)return Ym;tk=1;var e=v$(),n=e();return Ym=n,Ym}var Km,nk;function w$(){if(nk)return Km;nk=1;function e(n,r){var s=n.length;for(n.sort(r);s--;)n[s]=n[s].value;return n}return Km=e,Km}var Xm,rk;function x$(){if(rk)return Xm;rk=1;var e=io();function n(r,s){if(r!==s){var o=r!==void 0,l=r===null,u=r===r,c=e(r),p=s!==void 0,h=s===null,f=s===s,m=e(s);if(!h&&!m&&!c&&r>s||c&&p&&f&&!h&&!m||l&&p&&f||!o&&f||!u)return 1;if(!l&&!c&&!m&&r<s||m&&o&&u&&!l&&!c||h&&o&&u||!p&&u||!f)return-1}return 0}return Xm=n,Xm}var Qm,ik;function _$(){if(ik)return Qm;ik=1;var e=x$();function n(r,s,o){for(var l=-1,u=r.criteria,c=s.criteria,p=u.length,h=o.length;++l<p;){var f=e(u[l],c[l]);if(f){if(l>=h)return f;var m=o[l];return f*(m=="desc"?-1:1)}}return r.index-s.index}return Qm=n,Qm}var Zm,sk;function S$(){if(sk)return Zm;sk=1;var e=gu(),n=yu(),r=Or(),s=pC(),o=w$(),l=fu(),u=_$(),c=es(),p=_t();function h(f,m,y){m.length?m=e(m,function(_){return p(_)?function(S){return n(S,_.length===1?_[0]:_)}:_}):m=[c];var x=-1;m=e(m,l(r));var C=s(f,function(_,S,b){var E=e(m,function(N){return N(_)});return{criteria:E,index:++x,value:_}});return o(C,function(_,S){return u(_,S,y)})}return Zm=h,Zm}var Jm,ok;function b$(){if(ok)return Jm;ok=1;var e=$v(),n=S$(),r=wu(),s=xu(),o=r(function(l,u){if(l==null)return[];var c=u.length;return c>1&&s(l,u[0],u[1])?u=[]:c>2&&s(u[0],u[1],u[2])&&(u=[u[0]]),n(l,e(u,1),[])});return Jm=o,Jm}var eg,ak;function k$(){if(ak)return eg;ak=1;var e=aC(),n=0;function r(s){var o=++n;return e(s)+o}return eg=r,eg}var tg,lk;function E$(){if(lk)return tg;lk=1;function e(n,r,s){for(var o=-1,l=n.length,u=r.length,c={};++o<l;){var p=o<u?r[o]:void 0;s(c,n[o],p)}return c}return tg=e,tg}var ng,uk;function N$(){if(uk)return ng;uk=1;var e=cu(),n=E$();function r(s,o){return n(s||[],o||[],e)}return ng=r,ng}var rg,ck;function st(){if(ck)return rg;ck=1;var e;if(typeof bv=="function")try{e={cloneDeep:Bq(),constant:Mv(),defaults:Uq(),each:eC(),filter:dC(),find:Xq(),flatten:TC(),forEach:JN(),forIn:Qq(),has:fC(),isUndefined:hC(),last:Zq(),map:mC(),mapValues:Jq(),max:t$(),merge:a$(),min:l$(),minBy:u$(),now:c$(),pick:m$(),range:y$(),reduce:gC(),sortBy:b$(),uniqueId:k$(),values:_C(),zipObject:N$()}}catch{}return e||(e=window._),rg=e,rg}var ig,dk;function C$(){if(dk)return ig;dk=1,ig=e;function e(){var s={};s._next=s._prev=s,this._sentinel=s}e.prototype.dequeue=function(){var s=this._sentinel,o=s._prev;if(o!==s)return n(o),o},e.prototype.enqueue=function(s){var o=this._sentinel;s._prev&&s._next&&n(s),s._next=o._next,o._next._prev=s,o._next=s,s._prev=o},e.prototype.toString=function(){for(var s=[],o=this._sentinel,l=o._prev;l!==o;)s.push(JSON.stringify(l,r)),l=l._prev;return"["+s.join(", ")+"]"};function n(s){s._prev._next=s._next,s._next._prev=s._prev,delete s._next,delete s._prev}function r(s,o){if(s!=="_next"&&s!=="_prev")return o}return ig}var sg,fk;function T$(){if(fk)return sg;fk=1;var e=st(),n=Jn().Graph,r=C$();sg=o;var s=e.constant(1);function o(h,f){if(h.nodeCount()<=1)return[];var m=c(h,f||s),y=l(m.graph,m.buckets,m.zeroIdx);return e.flatten(e.map(y,function(x){return h.outEdges(x.v,x.w)}),!0)}function l(h,f,m){for(var y=[],x=f[f.length-1],C=f[0],_;h.nodeCount();){for(;_=C.dequeue();)u(h,f,m,_);for(;_=x.dequeue();)u(h,f,m,_);if(h.nodeCount()){for(var S=f.length-2;S>0;--S)if(_=f[S].dequeue(),_){y=y.concat(u(h,f,m,_,!0));break}}}return y}function u(h,f,m,y,x){var C=x?[]:void 0;return e.forEach(h.inEdges(y.v),function(_){var S=h.edge(_),b=h.node(_.v);x&&C.push({v:_.v,w:_.w}),b.out-=S,p(f,m,b)}),e.forEach(h.outEdges(y.v),function(_){var S=h.edge(_),b=_.w,E=h.node(b);E.in-=S,p(f,m,E)}),h.removeNode(y.v),C}function c(h,f){var m=new n,y=0,x=0;e.forEach(h.nodes(),function(S){m.setNode(S,{v:S,in:0,out:0})}),e.forEach(h.edges(),function(S){var b=m.edge(S.v,S.w)||0,E=f(S),N=b+E;m.setEdge(S.v,S.w,N),x=Math.max(x,m.node(S.v).out+=E),y=Math.max(y,m.node(S.w).in+=E)});var C=e.range(x+y+3).map(function(){return new r}),_=y+1;return e.forEach(m.nodes(),function(S){p(C,_,m.node(S))}),{graph:m,buckets:C,zeroIdx:_}}function p(h,f,m){m.out?m.in?h[m.out-m.in+f].enqueue(m):h[h.length-1].enqueue(m):h[0].enqueue(m)}return sg}var og,hk;function R$(){if(hk)return og;hk=1;var e=st(),n=T$();og={run:r,undo:o};function r(l){var u=l.graph().acyclicer==="greedy"?n(l,c(l)):s(l);e.forEach(u,function(p){var h=l.edge(p);l.removeEdge(p),h.forwardName=p.name,h.reversed=!0,l.setEdge(p.w,p.v,h,e.uniqueId("rev"))});function c(p){return function(h){return p.edge(h).weight}}}function s(l){var u=[],c={},p={};function h(f){e.has(p,f)||(p[f]=!0,c[f]=!0,e.forEach(l.outEdges(f),function(m){e.has(c,m.w)?u.push(m):h(m.w)}),delete c[f])}return e.forEach(l.nodes(),h),u}function o(l){e.forEach(l.edges(),function(u){var c=l.edge(u);if(c.reversed){l.removeEdge(u);var p=c.forwardName;delete c.reversed,delete c.forwardName,l.setEdge(u.w,u.v,c,p)}})}return og}var ag,pk;function dn(){if(pk)return ag;pk=1;var e=st(),n=Jn().Graph;ag={addDummyNode:r,simplify:s,asNonCompoundGraph:o,successorWeights:l,predecessorWeights:u,intersectRect:c,buildLayerMatrix:p,normalizeRanks:h,removeEmptyRanks:f,addBorderNode:m,maxRank:y,partition:x,time:C,notime:_};function r(S,b,E,N){var T;do T=e.uniqueId(N);while(S.hasNode(T));return E.dummy=b,S.setNode(T,E),T}function s(S){var b=new n().setGraph(S.graph());return e.forEach(S.nodes(),function(E){b.setNode(E,S.node(E))}),e.forEach(S.edges(),function(E){var N=b.edge(E.v,E.w)||{weight:0,minlen:1},T=S.edge(E);b.setEdge(E.v,E.w,{weight:N.weight+T.weight,minlen:Math.max(N.minlen,T.minlen)})}),b}function o(S){var b=new n({multigraph:S.isMultigraph()}).setGraph(S.graph());return e.forEach(S.nodes(),function(E){S.children(E).length||b.setNode(E,S.node(E))}),e.forEach(S.edges(),function(E){b.setEdge(E,S.edge(E))}),b}function l(S){var b=e.map(S.nodes(),function(E){var N={};return e.forEach(S.outEdges(E),function(T){N[T.w]=(N[T.w]||0)+S.edge(T).weight}),N});return e.zipObject(S.nodes(),b)}function u(S){var b=e.map(S.nodes(),function(E){var N={};return e.forEach(S.inEdges(E),function(T){N[T.v]=(N[T.v]||0)+S.edge(T).weight}),N});return e.zipObject(S.nodes(),b)}function c(S,b){var E=S.x,N=S.y,T=b.x-E,I=b.y-N,M=S.width/2,O=S.height/2;if(!T&&!I)throw new Error("Not possible to find intersection inside of the rectangle");var H,L;return Math.abs(I)*M>Math.abs(T)*O?(I<0&&(O=-O),H=O*T/I,L=O):(T<0&&(M=-M),H=M,L=M*I/T),{x:E+H,y:N+L}}function p(S){var b=e.map(e.range(y(S)+1),function(){return[]});return e.forEach(S.nodes(),function(E){var N=S.node(E),T=N.rank;e.isUndefined(T)||(b[T][N.order]=E)}),b}function h(S){var b=e.min(e.map(S.nodes(),function(E){return S.node(E).rank}));e.forEach(S.nodes(),function(E){var N=S.node(E);e.has(N,"rank")&&(N.rank-=b)})}function f(S){var b=e.min(e.map(S.nodes(),function(I){return S.node(I).rank})),E=[];e.forEach(S.nodes(),function(I){var M=S.node(I).rank-b;E[M]||(E[M]=[]),E[M].push(I)});var N=0,T=S.graph().nodeRankFactor;e.forEach(E,function(I,M){e.isUndefined(I)&&M%T!==0?--N:N&&e.forEach(I,function(O){S.node(O).rank+=N})})}function m(S,b,E,N){var T={width:0,height:0};return arguments.length>=4&&(T.rank=E,T.order=N),r(S,"border",T,b)}function y(S){return e.max(e.map(S.nodes(),function(b){var E=S.node(b).rank;if(!e.isUndefined(E))return E}))}function x(S,b){var E={lhs:[],rhs:[]};return e.forEach(S,function(N){b(N)?E.lhs.push(N):E.rhs.push(N)}),E}function C(S,b){var E=e.now();try{return b()}finally{console.log(S+" time: "+(e.now()-E)+"ms")}}function _(S,b){return b()}return ag}var lg,mk;function j$(){if(mk)return lg;mk=1;var e=st(),n=dn();lg={run:r,undo:o};function r(l){l.graph().dummyChains=[],e.forEach(l.edges(),function(u){s(l,u)})}function s(l,u){var c=u.v,p=l.node(c).rank,h=u.w,f=l.node(h).rank,m=u.name,y=l.edge(u),x=y.labelRank;if(f!==p+1){l.removeEdge(u);var C,_,S;for(S=0,++p;p<f;++S,++p)y.points=[],_={width:0,height:0,edgeLabel:y,edgeObj:u,rank:p},C=n.addDummyNode(l,"edge",_,"_d"),p===x&&(_.width=y.width,_.height=y.height,_.dummy="edge-label",_.labelpos=y.labelpos),l.setEdge(c,C,{weight:y.weight},m),S===0&&l.graph().dummyChains.push(C),c=C;l.setEdge(c,h,{weight:y.weight},m)}}function o(l){e.forEach(l.graph().dummyChains,function(u){var c=l.node(u),p=c.edgeLabel,h;for(l.setEdge(c.edgeObj,p);c.dummy;)h=l.successors(u)[0],l.removeNode(u),p.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(p.x=c.x,p.y=c.y,p.width=c.width,p.height=c.height),u=h,c=l.node(u)})}return lg}var ug,gk;function Kl(){if(gk)return ug;gk=1;var e=st();ug={longestPath:n,slack:r};function n(s){var o={};function l(u){var c=s.node(u);if(e.has(o,u))return c.rank;o[u]=!0;var p=e.min(e.map(s.outEdges(u),function(h){return l(h.w)-s.edge(h).minlen}));return(p===Number.POSITIVE_INFINITY||p===void 0||p===null)&&(p=0),c.rank=p}e.forEach(s.sources(),l)}function r(s,o){return s.node(o.w).rank-s.node(o.v).rank-s.edge(o).minlen}return ug}var cg,vk;function IC(){if(vk)return cg;vk=1;var e=st(),n=Jn().Graph,r=Kl().slack;cg=s;function s(c){var p=new n({directed:!1}),h=c.nodes()[0],f=c.nodeCount();p.setNode(h,{});for(var m,y;o(p,c)<f;)m=l(p,c),y=p.hasNode(m.v)?r(c,m):-r(c,m),u(p,c,y);return p}function o(c,p){function h(f){e.forEach(p.nodeEdges(f),function(m){var y=m.v,x=f===y?m.w:y;!c.hasNode(x)&&!r(p,m)&&(c.setNode(x,{}),c.setEdge(f,x,{}),h(x))})}return e.forEach(c.nodes(),h),c.nodeCount()}function l(c,p){return e.minBy(p.edges(),function(h){if(c.hasNode(h.v)!==c.hasNode(h.w))return r(p,h)})}function u(c,p,h){e.forEach(c.nodes(),function(f){p.node(f).rank+=h})}return cg}var dg,yk;function A$(){if(yk)return dg;yk=1;var e=st(),n=IC(),r=Kl().slack,s=Kl().longestPath,o=Jn().alg.preorder,l=Jn().alg.postorder,u=dn().simplify;dg=c,c.initLowLimValues=m,c.initCutValues=p,c.calcCutValue=f,c.leaveEdge=x,c.enterEdge=C,c.exchangeEdges=_;function c(N){N=u(N),s(N);var T=n(N);m(T),p(T,N);for(var I,M;I=x(T);)M=C(T,N,I),_(T,N,I,M)}function p(N,T){var I=l(N,N.nodes());I=I.slice(0,I.length-1),e.forEach(I,function(M){h(N,T,M)})}function h(N,T,I){var M=N.node(I),O=M.parent;N.edge(I,O).cutvalue=f(N,T,I)}function f(N,T,I){var M=N.node(I),O=M.parent,H=!0,L=T.edge(I,O),P=0;return L||(H=!1,L=T.edge(O,I)),P=L.weight,e.forEach(T.nodeEdges(I),function(q){var W=q.v===I,B=W?q.w:q.v;if(B!==O){var j=W===H,K=T.edge(q).weight;if(P+=j?K:-K,b(N,I,B)){var U=N.edge(I,B).cutvalue;P+=j?-U:U}}}),P}function m(N,T){arguments.length<2&&(T=N.nodes()[0]),y(N,{},1,T)}function y(N,T,I,M,O){var H=I,L=N.node(M);return T[M]=!0,e.forEach(N.neighbors(M),function(P){e.has(T,P)||(I=y(N,T,I,P,M))}),L.low=H,L.lim=I++,O?L.parent=O:delete L.parent,I}function x(N){return e.find(N.edges(),function(T){return N.edge(T).cutvalue<0})}function C(N,T,I){var M=I.v,O=I.w;T.hasEdge(M,O)||(M=I.w,O=I.v);var H=N.node(M),L=N.node(O),P=H,q=!1;H.lim>L.lim&&(P=L,q=!0);var W=e.filter(T.edges(),function(B){return q===E(N,N.node(B.v),P)&&q!==E(N,N.node(B.w),P)});return e.minBy(W,function(B){return r(T,B)})}function _(N,T,I,M){var O=I.v,H=I.w;N.removeEdge(O,H),N.setEdge(M.v,M.w,{}),m(N),p(N,T),S(N,T)}function S(N,T){var I=e.find(N.nodes(),function(O){return!T.node(O).parent}),M=o(N,I);M=M.slice(1),e.forEach(M,function(O){var H=N.node(O).parent,L=T.edge(O,H),P=!1;L||(L=T.edge(H,O),P=!0),T.node(O).rank=T.node(H).rank+(P?L.minlen:-L.minlen)})}function b(N,T,I){return N.hasEdge(T,I)}function E(N,T,I){return I.low<=T.lim&&T.lim<=I.lim}return dg}var fg,wk;function I$(){if(wk)return fg;wk=1;var e=Kl(),n=e.longestPath,r=IC(),s=A$();fg=o;function o(p){switch(p.graph().ranker){case"network-simplex":c(p);break;case"tight-tree":u(p);break;case"longest-path":l(p);break;default:c(p)}}var l=n;function u(p){n(p),r(p)}function c(p){s(p)}return fg}var hg,xk;function M$(){if(xk)return hg;xk=1;var e=st();hg=n;function n(o){var l=s(o);e.forEach(o.graph().dummyChains,function(u){for(var c=o.node(u),p=c.edgeObj,h=r(o,l,p.v,p.w),f=h.path,m=h.lca,y=0,x=f[y],C=!0;u!==p.w;){if(c=o.node(u),C){for(;(x=f[y])!==m&&o.node(x).maxRank<c.rank;)y++;x===m&&(C=!1)}if(!C){for(;y<f.length-1&&o.node(x=f[y+1]).minRank<=c.rank;)y++;x=f[y]}o.setParent(u,x),u=o.successors(u)[0]}})}function r(o,l,u,c){var p=[],h=[],f=Math.min(l[u].low,l[c].low),m=Math.max(l[u].lim,l[c].lim),y,x;y=u;do y=o.parent(y),p.push(y);while(y&&(l[y].low>f||m>l[y].lim));for(x=y,y=c;(y=o.parent(y))!==x;)h.push(y);return{path:p.concat(h.reverse()),lca:x}}function s(o){var l={},u=0;function c(p){var h=u;e.forEach(o.children(p),c),l[p]={low:h,lim:u++}}return e.forEach(o.children(),c),l}return hg}var pg,_k;function P$(){if(_k)return pg;_k=1;var e=st(),n=dn();pg={run:r,cleanup:u};function r(c){var p=n.addDummyNode(c,"root",{},"_root"),h=o(c),f=e.max(e.values(h))-1,m=2*f+1;c.graph().nestingRoot=p,e.forEach(c.edges(),function(x){c.edge(x).minlen*=m});var y=l(c)+1;e.forEach(c.children(),function(x){s(c,p,m,y,f,h,x)}),c.graph().nodeRankFactor=m}function s(c,p,h,f,m,y,x){var C=c.children(x);if(!C.length){x!==p&&c.setEdge(p,x,{weight:0,minlen:h});return}var _=n.addBorderNode(c,"_bt"),S=n.addBorderNode(c,"_bb"),b=c.node(x);c.setParent(_,x),b.borderTop=_,c.setParent(S,x),b.borderBottom=S,e.forEach(C,function(E){s(c,p,h,f,m,y,E);var N=c.node(E),T=N.borderTop?N.borderTop:E,I=N.borderBottom?N.borderBottom:E,M=N.borderTop?f:2*f,O=T!==I?1:m-y[x]+1;c.setEdge(_,T,{weight:M,minlen:O,nestingEdge:!0}),c.setEdge(I,S,{weight:M,minlen:O,nestingEdge:!0})}),c.parent(x)||c.setEdge(p,_,{weight:0,minlen:m+y[x]})}function o(c){var p={};function h(f,m){var y=c.children(f);y&&y.length&&e.forEach(y,function(x){h(x,m+1)}),p[f]=m}return e.forEach(c.children(),function(f){h(f,1)}),p}function l(c){return e.reduce(c.edges(),function(p,h){return p+c.edge(h).weight},0)}function u(c){var p=c.graph();c.removeNode(p.nestingRoot),delete p.nestingRoot,e.forEach(c.edges(),function(h){var f=c.edge(h);f.nestingEdge&&c.removeEdge(h)})}return pg}var mg,Sk;function O$(){if(Sk)return mg;Sk=1;var e=st(),n=dn();mg=r;function r(o){function l(u){var c=o.children(u),p=o.node(u);if(c.length&&e.forEach(c,l),e.has(p,"minRank")){p.borderLeft=[],p.borderRight=[];for(var h=p.minRank,f=p.maxRank+1;h<f;++h)s(o,"borderLeft","_bl",u,p,h),s(o,"borderRight","_br",u,p,h)}}e.forEach(o.children(),l)}function s(o,l,u,c,p,h){var f={width:0,height:0,rank:h,borderType:l},m=p[l][h-1],y=n.addDummyNode(o,"border",f,u);p[l][h]=y,o.setParent(y,c),m&&o.setEdge(m,y,{weight:1})}return mg}var gg,bk;function L$(){if(bk)return gg;bk=1;var e=st();gg={adjust:n,undo:r};function n(h){var f=h.graph().rankdir.toLowerCase();(f==="lr"||f==="rl")&&s(h)}function r(h){var f=h.graph().rankdir.toLowerCase();(f==="bt"||f==="rl")&&l(h),(f==="lr"||f==="rl")&&(c(h),s(h))}function s(h){e.forEach(h.nodes(),function(f){o(h.node(f))}),e.forEach(h.edges(),function(f){o(h.edge(f))})}function o(h){var f=h.width;h.width=h.height,h.height=f}function l(h){e.forEach(h.nodes(),function(f){u(h.node(f))}),e.forEach(h.edges(),function(f){var m=h.edge(f);e.forEach(m.points,u),e.has(m,"y")&&u(m)})}function u(h){h.y=-h.y}function c(h){e.forEach(h.nodes(),function(f){p(h.node(f))}),e.forEach(h.edges(),function(f){var m=h.edge(f);e.forEach(m.points,p),e.has(m,"x")&&p(m)})}function p(h){var f=h.x;h.x=h.y,h.y=f}return gg}var vg,kk;function q$(){if(kk)return vg;kk=1;var e=st();vg=n;function n(r){var s={},o=e.filter(r.nodes(),function(h){return!r.children(h).length}),l=e.max(e.map(o,function(h){return r.node(h).rank})),u=e.map(e.range(l+1),function(){return[]});function c(h){if(!e.has(s,h)){s[h]=!0;var f=r.node(h);u[f.rank].push(h),e.forEach(r.successors(h),c)}}var p=e.sortBy(o,function(h){return r.node(h).rank});return e.forEach(p,c),u}return vg}var yg,Ek;function $$(){if(Ek)return yg;Ek=1;var e=st();yg=n;function n(s,o){for(var l=0,u=1;u<o.length;++u)l+=r(s,o[u-1],o[u]);return l}function r(s,o,l){for(var u=e.zipObject(l,e.map(l,function(y,x){return x})),c=e.flatten(e.map(o,function(y){return e.sortBy(e.map(s.outEdges(y),function(x){return{pos:u[x.w],weight:s.edge(x).weight}}),"pos")}),!0),p=1;p<l.length;)p<<=1;var h=2*p-1;p-=1;var f=e.map(new Array(h),function(){return 0}),m=0;return e.forEach(c.forEach(function(y){var x=y.pos+p;f[x]+=y.weight;for(var C=0;x>0;)x%2&&(C+=f[x+1]),x=x-1>>1,f[x]+=y.weight;m+=y.weight*C})),m}return yg}var wg,Nk;function D$(){if(Nk)return wg;Nk=1;var e=st();wg=n;function n(r,s){return e.map(s,function(o){var l=r.inEdges(o);if(l.length){var u=e.reduce(l,function(c,p){var h=r.edge(p),f=r.node(p.v);return{sum:c.sum+h.weight*f.order,weight:c.weight+h.weight}},{sum:0,weight:0});return{v:o,barycenter:u.sum/u.weight,weight:u.weight}}else return{v:o}})}return wg}var xg,Ck;function F$(){if(Ck)return xg;Ck=1;var e=st();xg=n;function n(o,l){var u={};e.forEach(o,function(p,h){var f=u[p.v]={indegree:0,in:[],out:[],vs:[p.v],i:h};e.isUndefined(p.barycenter)||(f.barycenter=p.barycenter,f.weight=p.weight)}),e.forEach(l.edges(),function(p){var h=u[p.v],f=u[p.w];!e.isUndefined(h)&&!e.isUndefined(f)&&(f.indegree++,h.out.push(u[p.w]))});var c=e.filter(u,function(p){return!p.indegree});return r(c)}function r(o){var l=[];function u(h){return function(f){f.merged||(e.isUndefined(f.barycenter)||e.isUndefined(h.barycenter)||f.barycenter>=h.barycenter)&&s(h,f)}}function c(h){return function(f){f.in.push(h),--f.indegree===0&&o.push(f)}}for(;o.length;){var p=o.pop();l.push(p),e.forEach(p.in.reverse(),u(p)),e.forEach(p.out,c(p))}return e.map(e.filter(l,function(h){return!h.merged}),function(h){return e.pick(h,["vs","i","barycenter","weight"])})}function s(o,l){var u=0,c=0;o.weight&&(u+=o.barycenter*o.weight,c+=o.weight),l.weight&&(u+=l.barycenter*l.weight,c+=l.weight),o.vs=l.vs.concat(o.vs),o.barycenter=u/c,o.weight=c,o.i=Math.min(l.i,o.i),l.merged=!0}return xg}var _g,Tk;function z$(){if(Tk)return _g;Tk=1;var e=st(),n=dn();_g=r;function r(l,u){var c=n.partition(l,function(_){return e.has(_,"barycenter")}),p=c.lhs,h=e.sortBy(c.rhs,function(_){return-_.i}),f=[],m=0,y=0,x=0;p.sort(o(!!u)),x=s(f,h,x),e.forEach(p,function(_){x+=_.vs.length,f.push(_.vs),m+=_.barycenter*_.weight,y+=_.weight,x=s(f,h,x)});var C={vs:e.flatten(f,!0)};return y&&(C.barycenter=m/y,C.weight=y),C}function s(l,u,c){for(var p;u.length&&(p=e.last(u)).i<=c;)u.pop(),l.push(p.vs),c++;return c}function o(l){return function(u,c){return u.barycenter<c.barycenter?-1:u.barycenter>c.barycenter?1:l?c.i-u.i:u.i-c.i}}return _g}var Sg,Rk;function B$(){if(Rk)return Sg;Rk=1;var e=st(),n=D$(),r=F$(),s=z$();Sg=o;function o(c,p,h,f){var m=c.children(p),y=c.node(p),x=y?y.borderLeft:void 0,C=y?y.borderRight:void 0,_={};x&&(m=e.filter(m,function(I){return I!==x&&I!==C}));var S=n(c,m);e.forEach(S,function(I){if(c.children(I.v).length){var M=o(c,I.v,h,f);_[I.v]=M,e.has(M,"barycenter")&&u(I,M)}});var b=r(S,h);l(b,_);var E=s(b,f);if(x&&(E.vs=e.flatten([x,E.vs,C],!0),c.predecessors(x).length)){var N=c.node(c.predecessors(x)[0]),T=c.node(c.predecessors(C)[0]);e.has(E,"barycenter")||(E.barycenter=0,E.weight=0),E.barycenter=(E.barycenter*E.weight+N.order+T.order)/(E.weight+2),E.weight+=2}return E}function l(c,p){e.forEach(c,function(h){h.vs=e.flatten(h.vs.map(function(f){return p[f]?p[f].vs:f}),!0)})}function u(c,p){e.isUndefined(c.barycenter)?(c.barycenter=p.barycenter,c.weight=p.weight):(c.barycenter=(c.barycenter*c.weight+p.barycenter*p.weight)/(c.weight+p.weight),c.weight+=p.weight)}return Sg}var bg,jk;function U$(){if(jk)return bg;jk=1;var e=st(),n=Jn().Graph;bg=r;function r(o,l,u){var c=s(o),p=new n({compound:!0}).setGraph({root:c}).setDefaultNodeLabel(function(h){return o.node(h)});return e.forEach(o.nodes(),function(h){var f=o.node(h),m=o.parent(h);(f.rank===l||f.minRank<=l&&l<=f.maxRank)&&(p.setNode(h),p.setParent(h,m||c),e.forEach(o[u](h),function(y){var x=y.v===h?y.w:y.v,C=p.edge(x,h),_=e.isUndefined(C)?0:C.weight;p.setEdge(x,h,{weight:o.edge(y).weight+_})}),e.has(f,"minRank")&&p.setNode(h,{borderLeft:f.borderLeft[l],borderRight:f.borderRight[l]}))}),p}function s(o){for(var l;o.hasNode(l=e.uniqueId("_root")););return l}return bg}var kg,Ak;function H$(){if(Ak)return kg;Ak=1;var e=st();kg=n;function n(r,s,o){var l={},u;e.forEach(o,function(c){for(var p=r.parent(c),h,f;p;){if(h=r.parent(p),h?(f=l[h],l[h]=p):(f=u,u=p),f&&f!==p){s.setEdge(f,p);return}p=h}})}return kg}var Eg,Ik;function W$(){if(Ik)return Eg;Ik=1;var e=st(),n=q$(),r=$$(),s=B$(),o=U$(),l=H$(),u=Jn().Graph,c=dn();Eg=p;function p(y){var x=c.maxRank(y),C=h(y,e.range(1,x+1),"inEdges"),_=h(y,e.range(x-1,-1,-1),"outEdges"),S=n(y);m(y,S);for(var b=Number.POSITIVE_INFINITY,E,N=0,T=0;T<4;++N,++T){f(N%2?C:_,N%4>=2),S=c.buildLayerMatrix(y);var I=r(y,S);I<b&&(T=0,E=e.cloneDeep(S),b=I)}m(y,E)}function h(y,x,C){return e.map(x,function(_){return o(y,_,C)})}function f(y,x){var C=new u;e.forEach(y,function(_){var S=_.graph().root,b=s(_,S,C,x);e.forEach(b.vs,function(E,N){_.node(E).order=N}),l(_,C,b.vs)})}function m(y,x){e.forEach(x,function(C){e.forEach(C,function(_,S){y.node(_).order=S})})}return Eg}var Ng,Mk;function V$(){if(Mk)return Ng;Mk=1;var e=st(),n=Jn().Graph,r=dn();Ng={positionX:C,findType1Conflicts:s,findType2Conflicts:o,addConflict:u,hasConflict:c,verticalAlignment:p,horizontalCompaction:h,alignCoordinates:y,findSmallestWidthAlignment:m,balance:x};function s(b,E){var N={};function T(I,M){var O=0,H=0,L=I.length,P=e.last(M);return e.forEach(M,function(q,W){var B=l(b,q),j=B?b.node(B).order:L;(B||q===P)&&(e.forEach(M.slice(H,W+1),function(K){e.forEach(b.predecessors(K),function(U){var ee=b.node(U),J=ee.order;(J<O||j<J)&&!(ee.dummy&&b.node(K).dummy)&&u(N,U,K)})}),H=W+1,O=j)}),M}return e.reduce(E,T),N}function o(b,E){var N={};function T(M,O,H,L,P){var q;e.forEach(e.range(O,H),function(W){q=M[W],b.node(q).dummy&&e.forEach(b.predecessors(q),function(B){var j=b.node(B);j.dummy&&(j.order<L||j.order>P)&&u(N,B,q)})})}function I(M,O){var H=-1,L,P=0;return e.forEach(O,function(q,W){if(b.node(q).dummy==="border"){var B=b.predecessors(q);B.length&&(L=b.node(B[0]).order,T(O,P,W,H,L),P=W,H=L)}T(O,P,O.length,L,M.length)}),O}return e.reduce(E,I),N}function l(b,E){if(b.node(E).dummy)return e.find(b.predecessors(E),function(N){return b.node(N).dummy})}function u(b,E,N){if(E>N){var T=E;E=N,N=T}var I=b[E];I||(b[E]=I={}),I[N]=!0}function c(b,E,N){if(E>N){var T=E;E=N,N=T}return e.has(b[E],N)}function p(b,E,N,T){var I={},M={},O={};return e.forEach(E,function(H){e.forEach(H,function(L,P){I[L]=L,M[L]=L,O[L]=P})}),e.forEach(E,function(H){var L=-1;e.forEach(H,function(P){var q=T(P);if(q.length){q=e.sortBy(q,function(U){return O[U]});for(var W=(q.length-1)/2,B=Math.floor(W),j=Math.ceil(W);B<=j;++B){var K=q[B];M[P]===P&&L<O[K]&&!c(N,P,K)&&(M[K]=P,M[P]=I[P]=I[K],L=O[K])}}})}),{root:I,align:M}}function h(b,E,N,T,I){var M={},O=f(b,E,N,I),H=I?"borderLeft":"borderRight";function L(W,B){for(var j=O.nodes(),K=j.pop(),U={};K;)U[K]?W(K):(U[K]=!0,j.push(K),j=j.concat(B(K))),K=j.pop()}function P(W){M[W]=O.inEdges(W).reduce(function(B,j){return Math.max(B,M[j.v]+O.edge(j))},0)}function q(W){var B=O.outEdges(W).reduce(function(K,U){return Math.min(K,M[U.w]-O.edge(U))},Number.POSITIVE_INFINITY),j=b.node(W);B!==Number.POSITIVE_INFINITY&&j.borderType!==H&&(M[W]=Math.max(M[W],B))}return L(P,O.predecessors.bind(O)),L(q,O.successors.bind(O)),e.forEach(T,function(W){M[W]=M[N[W]]}),M}function f(b,E,N,T){var I=new n,M=b.graph(),O=_(M.nodesep,M.edgesep,T);return e.forEach(E,function(H){var L;e.forEach(H,function(P){var q=N[P];if(I.setNode(q),L){var W=N[L],B=I.edge(W,q);I.setEdge(W,q,Math.max(O(b,P,L),B||0))}L=P})}),I}function m(b,E){return e.minBy(e.values(E),function(N){var T=Number.NEGATIVE_INFINITY,I=Number.POSITIVE_INFINITY;return e.forIn(N,function(M,O){var H=S(b,O)/2;T=Math.max(M+H,T),I=Math.min(M-H,I)}),T-I})}function y(b,E){var N=e.values(E),T=e.min(N),I=e.max(N);e.forEach(["u","d"],function(M){e.forEach(["l","r"],function(O){var H=M+O,L=b[H],P;if(L!==E){var q=e.values(L);P=O==="l"?T-e.min(q):I-e.max(q),P&&(b[H]=e.mapValues(L,function(W){return W+P}))}})})}function x(b,E){return e.mapValues(b.ul,function(N,T){if(E)return b[E.toLowerCase()][T];var I=e.sortBy(e.map(b,T));return(I[1]+I[2])/2})}function C(b){var E=r.buildLayerMatrix(b),N=e.merge(s(b,E),o(b,E)),T={},I;e.forEach(["u","d"],function(O){I=O==="u"?E:e.values(E).reverse(),e.forEach(["l","r"],function(H){H==="r"&&(I=e.map(I,function(W){return e.values(W).reverse()}));var L=(O==="u"?b.predecessors:b.successors).bind(b),P=p(b,I,N,L),q=h(b,I,P.root,P.align,H==="r");H==="r"&&(q=e.mapValues(q,function(W){return-W})),T[O+H]=q})});var M=m(b,T);return y(T,M),x(T,b.graph().align)}function _(b,E,N){return function(T,I,M){var O=T.node(I),H=T.node(M),L=0,P;if(L+=O.width/2,e.has(O,"labelpos"))switch(O.labelpos.toLowerCase()){case"l":P=-O.width/2;break;case"r":P=O.width/2;break}if(P&&(L+=N?P:-P),P=0,L+=(O.dummy?E:b)/2,L+=(H.dummy?E:b)/2,L+=H.width/2,e.has(H,"labelpos"))switch(H.labelpos.toLowerCase()){case"l":P=H.width/2;break;case"r":P=-H.width/2;break}return P&&(L+=N?P:-P),P=0,L}}function S(b,E){return b.node(E).width}return Ng}var Cg,Pk;function G$(){if(Pk)return Cg;Pk=1;var e=st(),n=dn(),r=V$().positionX;Cg=s;function s(l){l=n.asNonCompoundGraph(l),o(l),e.forEach(r(l),function(u,c){l.node(c).x=u})}function o(l){var u=n.buildLayerMatrix(l),c=l.graph().ranksep,p=0;e.forEach(u,function(h){var f=e.max(e.map(h,function(m){return l.node(m).height}));e.forEach(h,function(m){l.node(m).y=p+f/2}),p+=f+c})}return Cg}var Tg,Ok;function Y$(){if(Ok)return Tg;Ok=1;var e=st(),n=R$(),r=j$(),s=I$(),o=dn().normalizeRanks,l=M$(),u=dn().removeEmptyRanks,c=P$(),p=O$(),h=L$(),f=W$(),m=G$(),y=dn(),x=Jn().Graph;Tg=C;function C(D,Q){var te=Q&&Q.debugTiming?y.time:y.notime;te("layout",function(){var ae=te(" buildLayoutGraph",function(){return L(D)});te(" runLayout",function(){_(ae,te)}),te(" updateInputGraph",function(){S(D,ae)})})}function _(D,Q){Q(" makeSpaceForEdgeLabels",function(){P(D)}),Q(" removeSelfEdges",function(){F(D)}),Q(" acyclic",function(){n.run(D)}),Q(" nestingGraph.run",function(){c.run(D)}),Q(" rank",function(){s(y.asNonCompoundGraph(D))}),Q(" injectEdgeLabelProxies",function(){q(D)}),Q(" removeEmptyRanks",function(){u(D)}),Q(" nestingGraph.cleanup",function(){c.cleanup(D)}),Q(" normalizeRanks",function(){o(D)}),Q(" assignRankMinMax",function(){W(D)}),Q(" removeEdgeLabelProxies",function(){B(D)}),Q(" normalize.run",function(){r.run(D)}),Q(" parentDummyChains",function(){l(D)}),Q(" addBorderSegments",function(){p(D)}),Q(" order",function(){f(D)}),Q(" insertSelfEdges",function(){Y(D)}),Q(" adjustCoordinateSystem",function(){h.adjust(D)}),Q(" position",function(){m(D)}),Q(" positionSelfEdges",function(){k(D)}),Q(" removeBorderNodes",function(){J(D)}),Q(" normalize.undo",function(){r.undo(D)}),Q(" fixupEdgeLabelCoords",function(){U(D)}),Q(" undoCoordinateSystem",function(){h.undo(D)}),Q(" translateGraph",function(){j(D)}),Q(" assignNodeIntersects",function(){K(D)}),Q(" reversePoints",function(){ee(D)}),Q(" acyclic.undo",function(){n.undo(D)})}function S(D,Q){e.forEach(D.nodes(),function(te){var ae=D.node(te),ce=Q.node(te);ae&&(ae.x=ce.x,ae.y=ce.y,Q.children(te).length&&(ae.width=ce.width,ae.height=ce.height))}),e.forEach(D.edges(),function(te){var ae=D.edge(te),ce=Q.edge(te);ae.points=ce.points,e.has(ce,"x")&&(ae.x=ce.x,ae.y=ce.y)}),D.graph().width=Q.graph().width,D.graph().height=Q.graph().height}var b=["nodesep","edgesep","ranksep","marginx","marginy"],E={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},N=["acyclicer","ranker","rankdir","align"],T=["width","height"],I={width:0,height:0},M=["minlen","weight","width","height","labeloffset"],O={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},H=["labelpos"];function L(D){var Q=new x({multigraph:!0,compound:!0}),te=se(D.graph());return Q.setGraph(e.merge({},E,$(te,b),e.pick(te,N))),e.forEach(D.nodes(),function(ae){var ce=se(D.node(ae));Q.setNode(ae,e.defaults($(ce,T),I)),Q.setParent(ae,D.parent(ae))}),e.forEach(D.edges(),function(ae){var ce=se(D.edge(ae));Q.setEdge(ae,e.merge({},O,$(ce,M),e.pick(ce,H)))}),Q}function P(D){var Q=D.graph();Q.ranksep/=2,e.forEach(D.edges(),function(te){var ae=D.edge(te);ae.minlen*=2,ae.labelpos.toLowerCase()!=="c"&&(Q.rankdir==="TB"||Q.rankdir==="BT"?ae.width+=ae.labeloffset:ae.height+=ae.labeloffset)})}function q(D){e.forEach(D.edges(),function(Q){var te=D.edge(Q);if(te.width&&te.height){var ae=D.node(Q.v),ce=D.node(Q.w),me={rank:(ce.rank-ae.rank)/2+ae.rank,e:Q};y.addDummyNode(D,"edge-proxy",me,"_ep")}})}function W(D){var Q=0;e.forEach(D.nodes(),function(te){var ae=D.node(te);ae.borderTop&&(ae.minRank=D.node(ae.borderTop).rank,ae.maxRank=D.node(ae.borderBottom).rank,Q=e.max(Q,ae.maxRank))}),D.graph().maxRank=Q}function B(D){e.forEach(D.nodes(),function(Q){var te=D.node(Q);te.dummy==="edge-proxy"&&(D.edge(te.e).labelRank=te.rank,D.removeNode(Q))})}function j(D){var Q=Number.POSITIVE_INFINITY,te=0,ae=Number.POSITIVE_INFINITY,ce=0,me=D.graph(),ge=me.marginx||0,Pe=me.marginy||0;function Se(Oe){var Me=Oe.x,be=Oe.y,De=Oe.width,ve=Oe.height;Q=Math.min(Q,Me-De/2),te=Math.max(te,Me+De/2),ae=Math.min(ae,be-ve/2),ce=Math.max(ce,be+ve/2)}e.forEach(D.nodes(),function(Oe){Se(D.node(Oe))}),e.forEach(D.edges(),function(Oe){var Me=D.edge(Oe);e.has(Me,"x")&&Se(Me)}),Q-=ge,ae-=Pe,e.forEach(D.nodes(),function(Oe){var Me=D.node(Oe);Me.x-=Q,Me.y-=ae}),e.forEach(D.edges(),function(Oe){var Me=D.edge(Oe);e.forEach(Me.points,function(be){be.x-=Q,be.y-=ae}),e.has(Me,"x")&&(Me.x-=Q),e.has(Me,"y")&&(Me.y-=ae)}),me.width=te-Q+ge,me.height=ce-ae+Pe}function K(D){e.forEach(D.edges(),function(Q){var te=D.edge(Q),ae=D.node(Q.v),ce=D.node(Q.w),me,ge;te.points?(me=te.points[0],ge=te.points[te.points.length-1]):(te.points=[],me=ce,ge=ae),te.points.unshift(y.intersectRect(ae,me)),te.points.push(y.intersectRect(ce,ge))})}function U(D){e.forEach(D.edges(),function(Q){var te=D.edge(Q);if(e.has(te,"x"))switch((te.labelpos==="l"||te.labelpos==="r")&&(te.width-=te.labeloffset),te.labelpos){case"l":te.x-=te.width/2+te.labeloffset;break;case"r":te.x+=te.width/2+te.labeloffset;break}})}function ee(D){e.forEach(D.edges(),function(Q){var te=D.edge(Q);te.reversed&&te.points.reverse()})}function J(D){e.forEach(D.nodes(),function(Q){if(D.children(Q).length){var te=D.node(Q),ae=D.node(te.borderTop),ce=D.node(te.borderBottom),me=D.node(e.last(te.borderLeft)),ge=D.node(e.last(te.borderRight));te.width=Math.abs(ge.x-me.x),te.height=Math.abs(ce.y-ae.y),te.x=me.x+te.width/2,te.y=ae.y+te.height/2}}),e.forEach(D.nodes(),function(Q){D.node(Q).dummy==="border"&&D.removeNode(Q)})}function F(D){e.forEach(D.edges(),function(Q){if(Q.v===Q.w){var te=D.node(Q.v);te.selfEdges||(te.selfEdges=[]),te.selfEdges.push({e:Q,label:D.edge(Q)}),D.removeEdge(Q)}})}function Y(D){var Q=y.buildLayerMatrix(D);e.forEach(Q,function(te){var ae=0;e.forEach(te,function(ce,me){var ge=D.node(ce);ge.order=me+ae,e.forEach(ge.selfEdges,function(Pe){y.addDummyNode(D,"selfedge",{width:Pe.label.width,height:Pe.label.height,rank:ge.rank,order:me+ ++ae,e:Pe.e,label:Pe.label},"_se")}),delete ge.selfEdges})})}function k(D){e.forEach(D.nodes(),function(Q){var te=D.node(Q);if(te.dummy==="selfedge"){var ae=D.node(te.e.v),ce=ae.x+ae.width/2,me=ae.y,ge=te.x-ce,Pe=ae.height/2;D.setEdge(te.e,te.label),D.removeNode(Q),te.label.points=[{x:ce+2*ge/3,y:me-Pe},{x:ce+5*ge/6,y:me-Pe},{x:ce+ge,y:me},{x:ce+5*ge/6,y:me+Pe},{x:ce+2*ge/3,y:me+Pe}],te.label.x=te.x,te.label.y=te.y}})}function $(D,Q){return e.mapValues(e.pick(D,Q),Number)}function se(D){var Q={};return e.forEach(D,function(te,ae){Q[ae.toLowerCase()]=te}),Q}return Tg}var Rg,Lk;function K$(){if(Lk)return Rg;Lk=1;var e=st(),n=dn(),r=Jn().Graph;Rg={debugOrdering:s};function s(o){var l=n.buildLayerMatrix(o),u=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(c){u.setNode(c,{label:c}),u.setParent(c,"layer"+o.node(c).rank)}),e.forEach(o.edges(),function(c){u.setEdge(c.v,c.w,{},c.name)}),e.forEach(l,function(c,p){var h="layer"+p;u.setNode(h,{rank:"same"}),e.reduce(c,function(f,m){return u.setEdge(f,m,{style:"invis"}),m})}),u}return Rg}var jg,qk;function X$(){return qk||(qk=1,jg="0.8.5"),jg}var Ag,$k;function Q$(){return $k||($k=1,Ag={graphlib:Jn(),layout:Y$(),debug:K$(),util:{time:dn().time,notime:dn().notime},version:X$()}),Ag}var Z$=Q$();const Dk=nv(Z$),Js=240,Xl=130,Ys=74,_u=72,Fk=Ys+_u;function J$(e,n){var s;let r=Js;for(const o of e)r=Math.max(r,((s=n.get(o.id))==null?void 0:s.width)??Js);return r}const MC=420,e4=2;function ia(e){var r;return((r=e.data)==null?void 0:r.sessionId)??"_default"}function t4(e,n){return((n==null?void 0:n.get(e))??0)>0?MC:0}function n4(e,n){const r=(n==null?void 0:n.get(e))??0;return r>0?6+r*36:0}function sa(e,n,r){const s=n.get(e);return{w:((s==null?void 0:s.width)??Js)+t4(e,r),h:Math.max((s==null?void 0:s.height)??Xl,n4(e,r))}}function r4(e){return[...e.keys()].sort().map(n=>`${n}:${e.get(n)}`).join("|")}function i4(e,n,r,s,o,l){const u=new Dk.graphlib.Graph;u.setDefaultEdgeLabel(()=>({})),u.setGraph({rankdir:r,marginx:0,marginy:0,nodesep:70,ranksep:160,edgesep:30});const c=e.filter(b=>!o.has(b)),p=new Set(c);for(const b of c){const{w:E,h:N}=sa(b,s,l);u.setNode(b,{width:E,height:N})}for(const b of n)p.has(b.source)&&p.has(b.target)&&u.setEdge(b.source,b.target);Dk.layout(u);const h=new Map;let f=1/0,m=1/0,y=-1/0,x=-1/0;for(const b of c){const E=u.node(b);if(!E)continue;const N=s.get(b),T=(N==null?void 0:N.width)??Js,I=(N==null?void 0:N.height)??Xl,M=sa(b,s,l),O=E.x-M.w/2,H=E.y-M.h/2;h.set(b,{x:O,y:H}),O<f&&(f=O),H<m&&(m=H),O+T>y&&(y=O+T),H+I>x&&(x=H+I)}if(Number.isFinite(f)&&Number.isFinite(m))for(const[b,E]of h)h.set(b,{x:E.x-f,y:E.y-m});const C=Number.isFinite(y)?y-f:0,_=Number.isFinite(x)?x-m:0;let S=null;for(const b of e){const E=o.get(b);if(!E)continue;const N=s.get(b),T=(N==null?void 0:N.width)??Js,I=(N==null?void 0:N.height)??Xl;S=S===null?{minX:E.x,minY:E.y,maxX:E.x+T,maxY:E.y+I}:{minX:Math.min(S.minX,E.x),minY:Math.min(S.minY,E.y),maxX:Math.max(S.maxX,E.x+T),maxY:Math.max(S.maxY,E.y+I)}}return{positions:h,width:C,height:_,pinnedBox:S}}function s4(e,n,r={}){const s=r.direction??"LR",o=r.pinned??new Map,l=r.measured??new Map,u=r.lanes,c=new Map;for(const b of e){const E=ia(b),N=c.get(E);N?N.push(b.id):c.set(E,[b.id])}const h=Array.from(c.keys()).sort().map(b=>({sid:b,...i4(c.get(b),n,s,l,o,u)})),f=J$(e,l),m=r.availableHeight&&r.availableHeight>0?r.availableHeight:Number.POSITIVE_INFINITY,y=b=>{const E=[[]];let N=0;for(const T of h)E.length<b&&N>0&&N+T.height>m&&(E.push([]),N=0),E[E.length-1].push(T),N+=T.height+Fk;return E},x=b=>b.reduce((E,N)=>Math.max(E,N.width),0)+MC;let C=y(r.availableWidth?e4:1);C.length>1&&C.reduce((E,N)=>E+x(N),0)+f*(C.length-1)>(r.availableWidth??0)&&(C=y(1));const _=new Map;let S=0;for(const b of C){const E=x(b);let N=0;for(const{positions:T,height:I,pinnedBox:M}of b){for(const[H,L]of T)_.set(H,{x:L.x+S,y:L.y+N});let O=N+I;M&&M.maxY>O&&M.minX<S+E&&S<M.maxX&&(O=M.maxY),N=O+Fk}S+=E+f}return e.map(b=>{const E=o.get(b.id);if(E)return{...b,position:E};const N=_.get(b.id);return N?{...b,position:N}:b})}function o4(e,n,r,s,o){const u=Ys+_u,c=60,p=x=>sa(x,s,o),h=new Map(e.map(x=>[x.id,ia(x)])),f=[],m=e.map(x=>({id:x.id,pos:r.get(x.id)??n.get(x.id)})).filter(x=>x.pos!=null).sort((x,C)=>x.pos.y-C.pos.y||x.pos.x-C.pos.x||x.id.localeCompare(C.id)),y=[];for(const{id:x,pos:C}of m){const{w:_,h:S}=p(x),b=h.get(x)??"_default";if(r.has(x)){f.push({x:C.x,y:C.y,w:_,h:S,sid:b});continue}let E=C.y;for(let N=0;N<f.length+1;N++){const T=f.find(I=>{const M=I.sid===b?24:c,O=I.sid===b?24:u;return C.x<I.x+I.w+M&&I.x<C.x+_+M&&E<I.y+I.h+O&&I.y<E+S+O});if(!T)break;E=T.y+T.h+(T.sid===b?24:u)}E!==C.y&&(n.set(x,{x:C.x,y:E}),y.push(x)),f.push({x:C.x,y:E,w:_,h:S,sid:b})}return y}function a4(e,n,r,s,o,l){const u=_=>sa(_,s,l),c=_=>r.get(_)??n.get(_),p=new Map;for(const _ of e){if(!c(_.id))continue;const S=ia(_),b=p.get(S);b?b.push(_):p.set(S,[_])}const h=new Set;for(const[_,S]of p)S.every(b=>o.has(b.id)&&!r.has(b.id))&&h.add(_);const f=new Map,m=[];for(const _ of e){const S=c(_.id);if(!S)continue;const{w:b,h:E}=u(_.id),N=ia(_);h.has(N)?(f.get(N)??f.set(N,[]).get(N)).push(_):m.push({x:S.x,y:S.y,w:b,h:E})}if(f.size===0)return[];const y=Ys+_u,x=(_,S,b,E)=>m.some(N=>_<N.x+N.w+Ys&&N.x<_+b+Ys&&S<N.y+N.h+y&&N.y<S+E+y),C=[];for(const _ of[...f.keys()].sort()){const S=f.get(_);let b=1/0,E=1/0,N=-1/0,T=-1/0;for(const q of S){const W=c(q.id),{w:B,h:j}=u(q.id);b=Math.min(b,W.x),E=Math.min(E,W.y),N=Math.max(N,W.x+B),T=Math.max(T,W.y+j)}const I=N-b,M=T-E,O=[...new Set(m.map(q=>Math.round(q.x)))].sort((q,W)=>q-W),H=O.length?O:[b],L=[0,...m.map(q=>q.y+q.h+y)].sort((q,W)=>q-W);let P=null;e:for(const q of H)for(const W of L){if(W>=E)break;if(!x(q,W,I,M)){P={x:q,y:W};break e}}if(P){const q=P.x-b,W=P.y-E;for(const B of S){const j=c(B.id);n.set(B.id,{x:j.x+q,y:j.y+W})}C.push(_)}for(const q of S){const W=c(q.id),{w:B,h:j}=u(q.id);m.push({x:W.x,y:W.y,w:B,h:j})}}return C}function l4(e,n,r,s,o,l=!1,u){const h=Ys+_u+1,f=8,m=1.75,y=200,x=.7,C=.01,_=P=>sa(P,s,u),S=P=>r.get(P)??n.get(P),b=new Map;for(const P of e){if(!S(P.id))continue;const q=ia(P),W=b.get(q);W?W.push(P):b.set(q,[P])}const E=[],N=new Set,T=new Set,I=o.size===0;for(const P of[...b.keys()].sort()){const q=b.get(P);let W=1/0,B=1/0,j=-1/0,K=-1/0,U=!1;for(const Y of q){const k=S(Y.id),{w:$,h:se}=_(Y.id);W=Math.min(W,k.x),B=Math.min(B,k.y),j=Math.max(j,k.x+$),K=Math.max(K,k.y+se),r.has(Y.id)&&(U=!0)}const ee=j-W,J=K-B;T.add(P);const F=o.get(P);F&&(ee>F.w+f||J>F.h+f)&&N.add(P),o.set(P,{w:ee,h:J}),E.push({sid:P,members:q.map(Y=>Y.id),x:W,y:B,w:ee,h:J,anchored:U,mass:1})}for(const P of[...o.keys()])T.has(P)||o.delete(P);if(l||I)return[];let M=!1;for(let P=0;P<E.length&&!M;P++)for(let q=P+1;q<E.length;q++){const W=E[P],B=E[q];if(!(W.anchored&&B.anchored)&&Math.abs(W.x+W.w/2-(B.x+B.w/2))<(W.w+B.w)/2+61&&Math.abs(W.y+W.h/2-(B.y+B.h/2))<(W.h+B.h)/2+h){M=!0;break}}if(N.size===0&&!M)return[];if(N.size>0)for(const P of E)N.has(P.sid)&&(P.mass=8);else for(const P of E)P.mass=Math.max(1,P.w*P.h/(Js*Xl));const O=new Map(E.map(P=>[P.sid,P.x])),H=new Map(E.map(P=>[P.sid,P.y]));for(let P=0;P<y;P++){const q=new Map,W=new Map;let B=0;for(let j=0;j<E.length;j++)for(let K=j+1;K<E.length;K++){const U=E[j],ee=E[K];if(U.anchored&&ee.anchored)continue;const J=U.x+U.w/2,F=U.y+U.h/2,Y=ee.x+ee.w/2,k=ee.y+ee.h/2,$=(U.w+ee.w)/2+61-Math.abs(J-Y),se=(U.h+ee.h)/2+h-Math.abs(F-k);if($<=0||se<=0)continue;const D=(Fe,Je)=>!Fe.anchored&&!(Je<0&&Fe.x<=0),Q=(Fe,Je)=>!Fe.anchored&&!(Je<0&&Fe.y<=0),te=(Fe,Je,dt)=>{const Nt=Fe===Je,ot=Nt?U.sid<ee.sid?-1:1:Math.sign(Fe-Je);return dt(U,ot)||dt(ee,-ot)?ot:Nt&&(dt(U,-ot)||dt(ee,ot))?-ot:0},ae=te(J,Y,D),ce=te(F,k,Q),me=ae!==0,ge=ce!==0;if(!me&&!ge)continue;const Pe=me&&(!ge||$*m<se),[Se,Oe,Me,be]=Pe?[ae,$,q,D]:[ce,se,W,Q],De=be(U,Se),ve=be(ee,-Se),we=U.mass,Ue=ee.mass,ut=De?ve?Ue/(we+Ue):1:0,ct=ve?De?we/(we+Ue):1:0,Ze=Oe*x;Me.set(U.sid,(Me.get(U.sid)??0)+Se*Ze*ut),Me.set(ee.sid,(Me.get(ee.sid)??0)-Se*Ze*ct),B+=Ze}for(const j of E)j.anchored||(j.x=Math.max(0,j.x+(q.get(j.sid)??0)),j.y=Math.max(0,j.y+(W.get(j.sid)??0)));if(B<C)break}const L=[];for(const P of E){const q=P.x-O.get(P.sid),W=P.y-H.get(P.sid);if(!(Math.abs(q)<1&&Math.abs(W)<1)){for(const B of P.members){if(r.has(B))continue;const j=n.get(B);j&&n.set(B,{x:j.x+q,y:j.y+W})}L.push(P.sid)}}return L}const u4=600;function Jg(e,n){return!(e.exitAt!=null&&n-e.exitAt>u4||e.kind==="root"&&e.state==="done"&&e.tools.length===0&&e.endedAt!=null&&e.endedAt-e.startedAt<3e3)}function c4(e,n){const r=new Set;for(const s of e.agents.values())Jg(s,n)&&r.add(s.id);return r}function d4(e,n,r=0){return e.right+r>n.left&&e.left-r<n.right&&e.bottom+r>n.top&&e.top-r<n.bottom}function f4(e,n,r=0){if(!e)return!1;for(const s of n)if(d4(e,s,r))return!0;return!1}const PC="sessionGroup";function h4(e,n){var s;if(e.type===PC)return"transparent";const r=(s=e.data)==null?void 0:s.state;return n(r==="err"?"--err":r==="active"?"--inflight":"--ok")}const p4="Update checks are off (AGENTS_DECK_NO_UPDATE_CHECK=1).";function m4(e){if(e.checkDisabled)return p4;if(e.checking)return"Asking npm for the newest release…";const n=e.latest?`npm has v${e.latest}`:e.latestPending?`npm's latest tag names v${e.latestPending}, which it cannot serve yet`:"npm not reached yet",r=e.checkedAgo?` · checked ${e.checkedAgo}`:"";return`${n}${r} · re-checked periodically · click to check npm now`}function g4(e){const n=`Version v${e.running}`;return e.checkDisabled?`${n}, update checks are off`:e.checking?`${n}, checking npm for a newer release`:`${n}, check npm for a newer release`}function Uo(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}function v4(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}const y4={agent:HP,sessionGroup:nO},w4=420,Ml=18,x4=9e4,_4=200,S4=5*6e4,b4=6,k4=2*6e4,zv="agent-dag.layout",Bv="agent-dag.viewport",OC="agent-dag.summariesDismissed",LC="agent-dag.sessionListOpen",qC="agent-dag.detailOpen",$C="agent-dag.usagePanelOpen",zk="agent-dag.accountsPanelOpen",Bk="agent-dag.versionNoticeDismissed",E4=15*6e4,Uk={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:"};function N4(e){const n=Math.max(0,Math.floor(e/1e3));return n<60?"just now":n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:`${Math.floor(n/86400)}d ago`}const Hk="agent-dag.autoRestart",Wk="agent-dag.bundleReloadedFor";function C4(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(LC)==="1"}catch{return!1}}function T4(e){if(!(typeof window>"u"))try{window.localStorage.setItem(LC,e?"1":"0")}catch{}}function R4(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(qC)==="1"}catch{return!1}}function j4(e){if(!(typeof window>"u"))try{window.localStorage.setItem(qC,e?"1":"0")}catch{}}function A4(){if(typeof window>"u")return!0;const e=window.localStorage.getItem($C);try{return e===null?!0:e==="1"}catch{return!0}}function I4(e){if(!(typeof window>"u"))try{window.localStorage.setItem($C,e?"1":"0")}catch{}}function M4(){if(typeof window>"u")return new Set;try{const e=window.localStorage.getItem(OC);if(!e)return new Set;const n=JSON.parse(e);return new Set(Array.isArray(n)?n.filter(r=>typeof r=="string"):[])}catch{return new Set}}function Vk(e){if(!(typeof window>"u"))try{const n=Array.from(e),r=n.length>200?n.slice(-200):n;window.localStorage.setItem(OC,JSON.stringify(r))}catch{}}function P4(){const e={positions:[],pins:[]};if(typeof window>"u")return e;try{const n=window.localStorage.getItem(zv);if(!n)return e;const r=JSON.parse(n);if(!("v"in r)){const o=Object.entries(r).filter(([,l])=>l&&typeof l.x=="number"&&typeof l.y=="number");return{positions:o,pins:o.map(([l])=>l)}}return{positions:Object.entries(r.positions??{}).filter(([,o])=>o&&typeof o.x=="number"&&typeof o.y=="number"),pins:Array.isArray(r.pins)?r.pins:[]}}catch{return e}}function Ig(e,n){if(!(typeof window>"u"))try{const r={};for(const[s,o]of e)r[s]=o;for(const[s,o]of n)r[s]=o;window.localStorage.setItem(zv,JSON.stringify({v:2,positions:r,pins:Array.from(n.keys())}))}catch{}}function O4(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Bv);if(!e)return null;const n=JSON.parse(e);return typeof(n==null?void 0:n.x)!="number"||typeof(n==null?void 0:n.y)!="number"||typeof(n==null?void 0:n.zoom)!="number"?null:n}catch{return null}}function L4(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Bv,JSON.stringify(e))}catch{}}function Gk(){if(!(typeof window>"u")){try{window.localStorage.removeItem(zv)}catch{}try{window.localStorage.removeItem(Bv)}catch{}}}function q4(e,n){const r=e.agents.get(n);if(!r)return;const s=[];for(const f of e.agents.values())f.sessionId===n&&s.push(f);const o={schemaVersion:1,exportedAt:new Date().toISOString(),sessionId:n,label:r.label,cwd:r.cwd,startedAt:r.startedAt,endedAt:r.endedAt,model:r.model,agents:s.map(f=>({id:f.id,kind:f.kind,label:f.label,parentId:f.parentId,state:f.state,startedAt:f.startedAt,endedAt:f.endedAt,model:f.model,cwd:f.cwd,usage:f.usage,prompts:f.prompts,tools:f.tools.map(m=>({id:m.id,name:m.name,inputPreview:m.inputPreview,startedAt:m.startedAt,endedAt:m.endedAt,ok:m.ok,errorPreview:m.errorPreview,usage:m.usage}))}))},l=JSON.stringify(o,null,2),u=new Blob([l],{type:"application/json"}),c=URL.createObjectURL(u),p=document.createElement("a"),h=(r.label||"session").replace(/[^a-z0-9._-]/gi,"_");p.href=c,p.download=`agents-deck-${h}-${n.slice(0,8)}.json`,document.body.appendChild(p),p.click(),document.body.removeChild(p),setTimeout(()=>URL.revokeObjectURL(c),1e3)}const ev={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},tv={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},$4={Read:"file",Write:"file",Edit:"file",MultiEdit:"file",Glob:"file",Grep:"file",LS:"file",NotebookEdit:"file",Bash:"shell",PowerShell:"shell",shell:"shell",exec_command:"shell",shell_command:"shell",write_stdin:"shell",wait:"shell",apply_patch:"file",update_plan:"task",WebFetch:"web",WebSearch:"web",Task:"agent",Agent:"agent",TodoWrite:"task",TaskCreate:"task",TaskUpdate:"task",TaskList:"task",TaskGet:"task",TaskOutput:"task",TaskStop:"task",EnterPlanMode:"plan",ExitPlanMode:"plan",AskUserQuestion:"plan",Skill:"plan",Workflow:"plan"};function DC(e){return e.startsWith("mcp__")?"mcp":$4[e]??"other"}function FC(e,n){var s,o,l;if(!n)return!0;const r=n.toLowerCase();if(e.label.toLowerCase().includes(r)||(s=e.cwd)!=null&&s.toLowerCase().includes(r)||(o=e.cwdBasename)!=null&&o.toLowerCase().includes(r)||e.sessionId.toLowerCase().includes(r)||(l=e.firstPrompt)!=null&&l.toLowerCase().includes(r))return!0;for(const u of e.tools)if(u.name.toLowerCase().includes(r))return!0;return!1}function D4(e,n){if(!n)return null;const r=new Set([n]);let s=n;for(;s;){const l=e.agents.get(s);if(!(l!=null&&l.parentId)||r.has(l.parentId))break;r.add(l.parentId),s=l.parentId}let o=!0;for(;o;){o=!1;for(const l of e.agents.values())l.parentId&&r.has(l.parentId)&&!r.has(l.id)&&(r.add(l.id),o=!0)}return r}function F4(e,n,r,s,o,l,u,c,p,h,f,m,y,x,C,_,S,b){const E=[],N=[],T=new Set;if(l)for(const q of e.agents.values())FC(q,l)&&T.add(q.id);for(const q of e.agents.values()){if(!S.has(q.id))continue;const W=l?!T.has(q.id):!1,B=q.exitAt!=null,j=_!=null&&!_.has(q.id),K=[W?"rf-dim":"",B?"rf-exiting":"",j?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,U=u.get(q.id);if(E.push({id:q.id,type:"agent",position:{x:0,y:0},data:{...q,now:n,dim:W,onOpenContext:b},className:K,...U?{width:U.width,height:U.height}:null}),q.parentId&&S.has(q.parentId)){const ee=_v(q.sessionId),J=q.state==="active"?`hsl(${ee} 80% 72%)`:`hsl(${ee} 50% 55%)`,F=l&&!T.has(q.id)&&!T.has(q.parentId),Y=B,k=C.size>0&&(C.has(q.id)||C.has(q.parentId)),$=_!=null&&!_.has(q.id)&&!_.has(q.parentId),se=q.state==="active"?2:1.5,D=k?se+1.5:se,Q=F||Y?.2:$?.12:1,te=[Y?"rf-edge-exiting":"",k?"rf-edge-selected":""].filter(Boolean).join(" ")||void 0;N.push({id:`e:${q.parentId}->${q.id}`,source:q.parentId,target:q.id,animated:(q.state==="active"||k)&&!F&&!Y,type:"smoothstep",style:{stroke:J,strokeWidth:D,opacity:Q,transition:"opacity 500ms ease, stroke-width 200ms ease"},className:te})}}const I=new Map;for(const q of e.agents.values())q.tools.length>0&&I.set(q.id,Math.min(4,q.tools.length));const M=`${y}#lanes:${r4(I)}`,O=E.filter(q=>!o.has(q.id)&&!m.has(q.id));if(O.length>0||M!==x.current){if(O.length>0){const q=s4(E,N,{direction:"LR",pinned:o,measured:u,availableWidth:r,availableHeight:s,lanes:I});for(const W of q)m.has(W.id)||m.set(W.id,W.position);a4(E,m,o,u,new Set(O.map(W=>W.id)),I)}o4(E,m,o,u,I),x.current=M}const H=l4(E,m,o,u,c,!h||f,I);H.length>0&&p(H),hd(m,e.agents),hd(o,e.agents),hd(u,C3(e.agents.values()));const L=[];let P=!1;for(const q of E){let W=o.get(q.id)??m.get(q.id);W||(W={x:0,y:0},m.set(q.id,W),P=!0),L.push({...q,position:W})}return P&&(x.current=""),{nodes:L,edges:N}}function z4(){return g.jsx(wv,{children:g.jsx(B4,{})})}function B4(){var Ri,hs,fo,zn;const e=ca(),n=A.useRef(Kg()),[,r]=A.useState(0),s=A.useCallback(()=>r(V=>V+1),[]),[o,l]=A.useState(()=>new Set),[u,c]=A.useState(null),[p,h]=A.useState(null),f=A.useCallback((V,X)=>{l(oe=>{if(!X)return new Set([V]);const ue=new Set(oe);return ue.has(V)?ue.delete(V):ue.add(V),ue}),c(oe=>X&&oe===V?oe:V)},[]),m=A.useCallback(()=>{l(new Set),c(null)},[]),[y,x]=A.useState(null),[C,_]=A.useState(null),S=A.useCallback(V=>_(V),[]),b=A.useRef(M4()),[E,N]=A.useState(C4);A.useEffect(()=>{T4(E)},[E]);const[T,I]=A.useState(R4);A.useEffect(()=>{j4(T)},[T]);const[M,O]=A.useState(A4);A.useEffect(()=>{I4(M)},[M]);const[H,L]=A.useState(()=>{try{const V=window.localStorage.getItem(zk);return V===null?!0:V==="1"}catch{return!0}});A.useEffect(()=>{try{window.localStorage.setItem(zk,H?"1":"0")}catch{}},[H]);const[P,q]=A.useState(null),[W,B]=A.useState(!1),[j,K]=A.useState(0),[U,ee]=A.useState(0);A.useEffect(()=>{fetch("/api/sound-hook").then(V=>V.ok?V.json():null).then(V=>{V!=null&&V.ok&&(q(V.enabled===!0),K((V.foreign??[]).filter(X=>X.worksHere).length),ee(typeof V.parked=="number"?V.parked:0))}).catch(()=>{})},[]);const J=A.useCallback(async()=>{B(!0);try{const X=await(await fetch("/api/sound-hook",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!P})})).json().catch(()=>null);X!=null&&X.ok&&q(X.enabled===!0),fetch("/api/sound-hook").then(oe=>oe.ok?oe.json():null).then(oe=>{oe!=null&&oe.ok&&(K((oe.foreign??[]).filter(ue=>ue.worksHere).length),ee(typeof oe.parked=="number"?oe.parked:0))}).catch(()=>{})}catch{}finally{B(!1)}},[P]),[F,Y]=A.useState(!1),[k,$]=A.useState(null),[se,D]=A.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(Bk)??""}catch{return""}}),[Q,te]=A.useState(!1),ae=A.useRef(0),[ce,me]=A.useState(!1),ge=A.useCallback((V=!1)=>{V&&(ae.current=Date.now(),me(!0)),fetch(V?"/api/version?refresh=1":"/api/version").then(X=>X.ok?X.json():null).then(X=>{X&&$(X)}).catch(()=>{}).finally(()=>{V&&me(!1)})},[]),Pe=A.useCallback(()=>{ge(Date.now()-ae.current>=E4)},[ge]);A.useEffect(()=>{ge();const V=window.setInterval(Pe,5*6e4),X=()=>{document.visibilityState==="visible"&&Pe()};return document.addEventListener("visibilitychange",X),()=>{window.clearInterval(V),document.removeEventListener("visibilitychange",X)}},[ge,Pe]),A.useEffect(()=>{F&&ge()},[F,ge]);const Se=(k==null?void 0:k.notice)??null,Oe=Se?`${Se.kind}:${Se.to}`:"",Me=Se!=null&&se!==Oe,be=A.useCallback(()=>{if(!Se)return;const V=se===Oe?"":Oe;D(V);try{window.localStorage.setItem(Bk,V)}catch{}},[Se,Oe,se]),De=((Ri=k==null?void 0:k.upgrade)==null?void 0:Ri.state)??"idle",ve=w3(k==null?void 0:k.upgrade),we=A.useCallback(async()=>{try{await fetch("/api/upgrade",{method:"POST"})}catch{}ge()},[ge]);A.useEffect(()=>{if(De!=="running")return;const V=window.setInterval(ge,3e3);return()=>window.clearInterval(V)},[De,ge]);const Ue=A.useCallback(async()=>{var oe;const V=k==null?void 0:k.command;if(!V)return;let X=!1;try{X=await Promise.race([((oe=navigator.clipboard)==null?void 0:oe.writeText(V).then(()=>!0))??Promise.resolve(!1),new Promise(ue=>window.setTimeout(()=>ue(!1),500))])}catch{X=!1}if(!X)try{const ue=document.createElement("textarea");ue.value=V,ue.setAttribute("readonly",""),ue.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(ue),ue.select(),X=document.execCommand("copy"),ue.remove()}catch{X=!1}X&&(te(!0),window.setTimeout(()=>te(!1),1600))},[k==null?void 0:k.command]),ut=A.useCallback(()=>{N(V=>(V||L(!1),!V))},[]),ct=A.useCallback(()=>{L(V=>(V||N(!1),!V))},[]),[Ze,Fe]=A.useState(!1),[Je,dt]=A.useState(0),Nt=A.useRef(null),[ot,gt]=A.useState(!1),Ct=A.useRef(null),[Ft,Xe]=A.useState(0),vt=A.useRef(A3()),[ft,wt]=A.useState(!1),fn=A.useCallback(()=>{const V=vt.current,X=V.setPaused(!V.paused);for(const oe of X)n.current=ix(n.current,oe);wt(V.paused)},[]),[Ye,zt]=A.useState(Date.now()),[Gt,pr]=A.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Hk)!=="0"}catch{return!0}}),In=A.useCallback(()=>{pr(V=>{const X=!V;try{window.localStorage.setItem(Hk,X?"1":"0")}catch{}return X})},[]),[Tt,Qt]=A.useState(!1),[vn,ts]=A.useState("restart"),[pi,mi]=A.useState(null),Mn=A.useRef(!1),Lr=A.useRef(null),gi=A.useRef(0),yn=A.useCallback(async V=>{if(Mn.current)return;const X=(V==null?void 0:V.upgrade)===!0;Mn.current=!0,Lr.current=ve;const oe=++gi.current;ts(X?"npx":"restart"),Qt(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(Se==null?void 0:Se.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:X})})}catch{}window.setTimeout(()=>{if(gi.current===oe&&Mn.current){Mn.current=!1,Qt(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},X?18e4:3e4)},[Se==null?void 0:Se.to,ve]),qr=A.useRef(null);A.useEffect(()=>{let V=!1;for(const oe of n.current.agents.values())if(oe.state==="active"){V=!0;break}const X=_3({enabled:Gt,kind:Se==null?void 0:Se.kind,canRestart:(k==null?void 0:k.canRestart)===!0,busy:V,idleSince:qr.current,now:Ye});qr.current=X.idleSince,X.restart&&yn()},[Gt,Se==null?void 0:Se.kind,k==null?void 0:k.canRestart,Ye,yn]),A.useEffect(()=>{let V=null;try{V=window.sessionStorage.getItem(Wk)}catch{return}if(y3({bundle:"1.33.96",running:k==null?void 0:k.running,lastTried:V})){try{window.sessionStorage.setItem(Wk,(k==null?void 0:k.running)??"")}catch{return}window.location.reload()}},[k==null?void 0:k.running]),A.useEffect(()=>{const V=k==null?void 0:k.running;if(!V)return;let X=null;try{X=window.sessionStorage.getItem("agent-dag.restartPending")}catch{return}if(X==null||X&&X!==V)return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Mn.current=!1,Qt(!1),mi(V);const oe=window.setTimeout(()=>mi(null),6e3);return()=>window.clearTimeout(oe)},[k==null?void 0:k.running]),A.useEffect(()=>{if(Tt&&x3({asked:Lr.current,reported:ve})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Mn.current=!1,Qt(!1)}},[Tt,ve]);const Pn=A.useRef(P4()).current;A.useRef(!1);const Ot=A.useRef(new Map(Pn.positions.filter(([V])=>Pn.pins.includes(V)))),wn=A.useRef(null),On=A.useState(()=>O4())[0],[Zt,$r]=A.useState(""),[ns,so]=A.useState(()=>new Set),[nr,xn]=A.useState(()=>typeof window>"u"?"dark":window.localStorage.getItem("agent-dag.theme")??"dark"),[vi,rs]=A.useState(!1),is=A.useRef(null);A.useEffect(()=>{document.documentElement.dataset.theme=nr;try{window.localStorage.setItem("agent-dag.theme",nr)}catch{}},[nr]),A.useEffect(()=>{if(!On)return;const V=window.setTimeout(()=>{try{e.setViewport(On,{duration:0})}catch{}},60);return()=>window.clearTimeout(V)},[e,On]);const yi=A.useRef(!0);A.useEffect(()=>{const V=new EventSource("/events"),X=j3(s,{now:()=>Date.now(),setTimeout:(oe,ue)=>window.setTimeout(oe,ue),clearTimeout:oe=>window.clearTimeout(oe)});return V.addEventListener("open",()=>{Y(!0),rs(!0)}),V.addEventListener("error",()=>Y(!1)),V.addEventListener("replay-end",()=>{yi.current=!1,X.flush()}),V.addEventListener("hook",oe=>{try{const ue=JSON.parse(oe.data);if(!vt.current.accept(ue))return;n.current=ix(n.current,ue),ue.replay===!0||yi.current||Date.now()-ue.receivedAt>3e4?X.replay():X.live()}catch{}}),()=>{V.close(),X.cancel()}},[s]),A.useEffect(()=>{const V=setInterval(()=>{const X=Date.now();zt(X);let oe=jP(n.current,X,x4);TP(n.current,X,_4,S4)&&(oe=!0),RP(n.current,X,b4,k4)&&(oe=!0),oe&&s()},250);return()=>clearInterval(V)},[s]);const Dr=A.useRef(null),Ln=A.useRef(0),ss=420,Yt=A.useCallback((V=500)=>{try{const ke=document.querySelector(".canvas-wrap"),Ne=Array.from(document.querySelectorAll(".react-flow__node")).filter(ht=>ht.offsetWidth>0);if(!ke||Ne.length===0)return;const Le=ke.getBoundingClientRect(),We=e.getViewport();if(!Number.isFinite(We.zoom)||We.zoom<=0)return;const Ve=ht=>(ht-Le.left-We.x)/We.zoom,rt=ht=>(ht-Le.top-We.y)/We.zoom,tn=Ne.map(ht=>ht.getBoundingClientRect()),yr=Math.min(...tn.map(ht=>Ve(ht.left))),wr=Math.max(...tn.map(ht=>Ve(ht.right))),or=Math.min(...tn.map(ht=>rt(ht.top))),ps=Math.max(...tn.map(ht=>rt(ht.bottom))),Sa=wr-yr,ms=ps-or;if(!(Sa>0&&ms>0))return;const Bn=Math.max(.2,Math.min(1,(Le.width-160)/(Sa+ss)*.86,(Le.height-160)/ms*.86));e.setViewport({x:80-yr*Bn,y:Math.max(80,(Le.height-ms*Bn)/2)-or*Bn,zoom:Bn},{duration:V}),Ln.current=Date.now(),window.setTimeout(()=>{try{const ht={x:80-yr*Bn,y:Math.max(80,(Le.height-ms*Bn)/2)-or*Bn,zoom:Bn},ba=e.getViewport();(Math.abs(ba.zoom-Bn)>.01||Math.abs(ba.x-ht.x)>2)&&e.setViewport(ht,{duration:0})}catch{}},V+60)}catch{}},[e]),wi=A.useRef(""),Qe=A.useRef(null),os=A.useRef(0),rr=A.useCallback(()=>{os.current=Date.now()},[]),Fr="agent-dag.autoFitDisabled",Jt=A.useRef((()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Fr)==="1"}catch{return!1}})()),[xi,_i]=A.useState(Jt.current),mr=A.useCallback(()=>{if(!Jt.current){Jt.current=!0,_i(!0);try{window.localStorage.setItem(Fr,"1")}catch{}}},[]),en=A.useCallback(()=>{Jt.current=!1,_i(!1);try{window.localStorage.removeItem(Fr)}catch{}Yt(400)},[e,Yt]);A.useEffect(()=>{const V=setInterval(()=>{if(Jt.current||Date.now()-os.current<800)return;const X=n.current,oe=Date.now(),ue=[];for(const Ve of X.agents.values())Jg(Ve,oe)&&ue.push({id:Ve.id});if(ue.length===0)return;const ye=e.getViewport(),ke=window.innerWidth-360,Ne=window.innerHeight-52;let Le=!1,We=!1;for(const{id:Ve}of ue){const rt=Rt.current.get(Ve),tn=Ot.current.get(Ve)??jt.current.get(Ve);if(!rt||!tn)continue;We=!0;const yr=tn.x*ye.zoom+ye.x,wr=tn.y*ye.zoom+ye.y,or=(tn.x+rt.width)*ye.zoom+ye.x,ps=(tn.y+rt.height)*ye.zoom+ye.y;if(or>0&&yr<ke&&ps>0&&wr<Ne){Le=!0;break}}We&&!Le&&Yt(600)},1500);return()=>clearInterval(V)},[e]);const gr=A.useRef(!1),Rt=A.useRef(new Map),va=A.useRef(0),Su=A.useCallback(V=>{const X=Rt.current;let oe=!1;for(const ue of V.nodeInternals.values()){const ye=ue.width,ke=ue.height;if(ye==null||ke==null)continue;const Ne=X.get(ue.id);Ne?(Math.abs(Ne.height-ke)>4||Math.abs(Ne.width-ye)>4)&&(X.set(ue.id,{width:ye,height:ke}),oe=!0):(X.set(ue.id,{width:ye,height:ke}),oe=!0)}return oe&&(va.current+=1),va.current},[]),ya=Ke(Su),[Si,as]=A.useState(0);A.useEffect(()=>{let V=0;const X=()=>{const ue=Rt.current;let ye=!1;for(const ke of document.querySelectorAll(".react-flow__node[data-id]")){const Ne=ke.getAttribute("data-id");if(!Ne)continue;const Le=ke.offsetWidth,We=ke.offsetHeight;if(!Le||!We)continue;const Ve=ue.get(Ne);(!Ve||Math.abs(Ve.width-Le)>4||Math.abs(Ve.height-We)>4)&&(ue.set(Ne,{width:Le,height:We}),ye=!0)}ye&&as(ke=>ke+1)};if(gr.current)return;let oe=0;return document.visibilityState==="hidden"?oe=window.setTimeout(X,32):V=requestAnimationFrame(X),()=>{cancelAnimationFrame(V),window.clearTimeout(oe)}});const jt=A.useRef(new Map(Pn.positions)),zr=A.useRef(""),Br=A.useMemo(()=>{const V=[];for(const X of n.current.agents.values())Jg(X,Ye)&&V.push(X.id+(X.parentId?`>${X.parentId}`:""));return V.sort(),`${V.join("|")}#sv${ya}.${Si}`},[n.current,n.current.lastSeq,Ye,ya,Si]),bi=A.useRef(null);A.useEffect(()=>(bi.current!=null&&window.clearTimeout(bi.current),bi.current=window.setTimeout(()=>{Ig(jt.current,Ot.current)},1500),()=>{bi.current!=null&&window.clearTimeout(bi.current)}),[Br]),A.useEffect(()=>{if(wi.current===Br)return;const V=wi.current;if(wi.current=Br,!V||Jt.current)return;Date.now()-Ln.current>1200&&Yt(400),Dr.current&&window.clearTimeout(Dr.current),Dr.current=window.setTimeout(()=>{Jt.current||Yt(500)},280)},[Br,e,Yt]);const ki=A.useMemo(()=>{if(o.size===0)return null;const V=new Set;for(const X of o){const oe=D4(n.current,X);if(oe)for(const ue of oe)V.add(ue)}return V.size>0?V:null},[n.current,n.current.lastSeq,o]),ls=A.useMemo(()=>c4(n.current,Ye),[n.current,n.current.lastSeq,Ye]),us=A.useRef(null),[ir,wa]=A.useState({w:0,h:0});A.useEffect(()=>{const V=us.current;if(!V||typeof ResizeObserver>"u")return;const X=new ResizeObserver(oe=>{var ye;const ue=(ye=oe[0])==null?void 0:ye.contentRect;ue&&wa(ke=>Math.abs(ke.w-ue.width)>40||Math.abs(ke.h-ue.height)>40?{w:ue.width,h:ue.height}:ke)});return X.observe(V),wa({w:V.clientWidth,h:V.clientHeight}),()=>X.disconnect()},[]);const oo=A.useRef(new Map),[He,xa]=A.useState(!1);A.useEffect(()=>{const V=window.setTimeout(()=>xa(!0),2500);return()=>window.clearTimeout(V)},[]);const[_a,Ei]=A.useState(!1),qn=A.useRef(null),[cs,ao]=A.useState(!1),lo=A.useCallback(()=>{qn.current&&(window.clearTimeout(qn.current),qn.current=null),Ei(!1)},[]),ds=A.useCallback(V=>{V.length!==0&&queueMicrotask(()=>{Ei(!0),qn.current&&window.clearTimeout(qn.current),qn.current=window.setTimeout(()=>Ei(!1),w4+80)})},[]);A.useEffect(()=>()=>{qn.current&&window.clearTimeout(qn.current)},[]);const $n=ir.w>0?ir.w*.92:0,Dn=ir.h>0?ir.h:0,{nodes:At,edges:Ni}=A.useMemo(()=>F4(n.current,Ye,$n,Dn,Ot.current,Zt,Rt.current,oo.current,ds,He,cs,jt.current,Br,zr,o,ki,ls,S),[n.current,n.current.lastSeq,Ye,$n,Dn,He,cs,Zt,Br,o,ki,ls,S,Je]),Ur=A.useMemo(()=>{const V=new Map;for(const oe of At){const ue=oe.data;if(!(ue!=null&&ue.sessionId)||ue.exitAt!=null)continue;const ye=oe.width,ke=oe.height;if(ye==null||ke==null)continue;const Ne=oe.position.x,Le=oe.position.y,We=Ne+ye,Ve=Le+ke,rt=V.get(ue.sessionId);rt?(rt.minX=Math.min(rt.minX,Ne),rt.minY=Math.min(rt.minY,Le),rt.maxX=Math.max(rt.maxX,We),rt.maxY=Math.max(rt.maxY,Ve)):V.set(ue.sessionId,{minX:Ne,minY:Le,maxX:We,maxY:Ve})}const X=[];for(const[oe,ue]of V){const ye=ue.maxX-ue.minX+Ml*2,ke=ue.maxY-ue.minY+Ml*2;X.push({id:`group:${oe}`,type:PC,position:{x:ue.minX-Ml,y:ue.minY-Ml},data:{sessionId:oe,w:ye,h:ke},width:ye,height:ke,style:{width:ye,height:ke},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return X},[At,Ye]),sr=A.useMemo(()=>{const V=[...Ur,...At],X=Ct.current;return!X||X.size===0?V:V.map(oe=>{const ue=X.get(oe.id);return ue?{...oe,position:ue}:oe})},[Ur,At,Ft]),bu=A.useMemo(()=>{if(!Zt)return null;const V=new Set;for(const X of n.current.agents.values())FC(X,Zt)&&V.add(X.id);return V},[n.current,n.current.lastSeq,Zt]),Ci=A.useMemo(()=>{const V=new Set;for(const X of n.current.agents.values())for(const oe of X.tools)V.add(DC(oe.name));return Object.keys(ev).filter(X=>V.has(X))},[n.current,n.current.lastSeq]);A.useEffect(()=>{if(Ci.length<=1){gt(!1);return}let V=0;const X=()=>{const oe=Nt.current;if(oe&&!document.hidden){const ue=oe.getBoundingClientRect(),ye=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Ne=>Ne.getBoundingClientRect()),ke=f4(ue,ye,8);gt(Ne=>Ne===ke?Ne:ke)}V=window.setTimeout(X,300)};return X(),()=>window.clearTimeout(V)},[Ci.length]);const Fn=A.useMemo(()=>{const V=new Map;for(const oe of n.current.agents.values())for(const ue of oe.tools){if(!ue.name.startsWith("mcp__"))continue;const ye=ue.name.slice(5),ke=ye.indexOf("__"),Ne=ke>0?ye.slice(0,ke):ye;V.set(Ne,(V.get(Ne)??0)+1)}const X=[];for(const[oe,ue]of V){let ye=5381;for(let ke=0;ke<oe.length;ke++)ye=(ye<<5)+ye^oe.charCodeAt(ke);X.push({server:oe,count:ue,hue:Math.abs(ye)%360})}return X.sort((oe,ue)=>ue.count-oe.count),X},[n.current,n.current.lastSeq]),ku=A.useCallback(V=>{so(X=>{const oe=new Set(X);return oe.has(V)?oe.delete(V):oe.add(V),oe})},[]),Lt=u?n.current.agents.get(u):null,Ti=p?Array.from(n.current.agents.values()).flatMap(V=>V.tools).find(V=>V.id===p)??null:null,fs=A.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}n.current=Kg(),Ot.current.clear(),Rt.current.clear(),jt.current.clear(),zr.current="",Gk(),m(),s()},[s,m]),uo=A.useCallback(()=>{Ot.current.clear(),jt.current.clear(),zr.current="",Gk(),s(),window.setTimeout(()=>Yt(500),80)},[s,e,Yt]),Hr=A.useCallback(()=>Yt(500),[Yt]),Wr=A.useRef(At);Wr.current=At;const vr=A.useRef(u);vr.current=u;const Vr=A.useCallback(V=>{const X=Wr.current;if(X.length===0)return;const oe=X.slice().sort((Le,We)=>Le.position.y-We.position.y||Le.position.x-We.position.x),ue=vr.current,ye=ue?oe.findIndex(Le=>Le.id===ue):-1;let ke;ye===-1?ke=V===1?0:oe.length-1:ke=(ye+V+oe.length)%oe.length;const Ne=oe[ke];Ne&&(f(Ne.id,!1),window.setTimeout(()=>{try{e.fitView({padding:.35,duration:350,nodes:[Ne]})}catch{}Ln.current=Date.now()},30))},[f,e]);A.useEffect(()=>{const V=X=>{var ye,ke;const oe=X.target,ue={tagName:oe==null?void 0:oe.tagName,isContentEditable:oe==null?void 0:oe.isContentEditable,role:(ye=oe==null?void 0:oe.getAttribute)==null?void 0:ye.call(oe,"role"),type:oe==null?void 0:oe.type};if(X.key==="Escape"){MN(ue)?oe==null||oe.blur():m();return}if(!N3(ue)&&!S3(X)){if(X.key==="/"){X.preventDefault(),(ke=is.current)==null||ke.focus();return}X.key===" "&&(X.preventDefault(),fn()),(X.key==="c"||X.key==="C")&&fs(),(X.key==="r"||X.key==="R")&&uo(),(X.key==="f"||X.key==="F")&&Hr(),(X.key==="l"||X.key==="L")&&ut(),(X.key==="h"||X.key==="H")&&Fe(Ne=>!Ne),(X.key==="u"||X.key==="U")&&O(Ne=>!Ne),(X.key==="a"||X.key==="A")&&ct(),(X.key==="j"||X.key==="J")&&Vr(1),(X.key==="k"||X.key==="K")&&Vr(-1),(X.key==="t"||X.key==="T")&&xn(Ne=>Ne==="dark"?"light":"dark")}};return window.addEventListener("keydown",V),()=>window.removeEventListener("keydown",V)},[fs,uo,Hr,m,Vr,fn]);const co=n.current.agents.size,Eu=new Set(Array.from(n.current.agents.values()).map(V=>V.sessionId)).size,Bt=A.useMemo(()=>{let V=0,X=0,oe=0,ue=0,ye=0,ke=0,Ne=0,Le=0,We=0;for(const Ve of n.current.agents.values()){V+=Ve.usage.inputTokens,X+=Ve.usage.outputTokens,oe+=Ve.usage.cacheReadTokens,ue+=Ve.usage.cacheCreateTokens;const rt=cn(Ve.usage,Ve.model);ye+=rt.total,ke+=rt.input,Ne+=rt.output,Le+=rt.cacheRead,We+=rt.cacheWrite}return{inT:V,outT:X,cacheR:oe,cacheC:ue,sum:V+X,cost:{total:ye,input:ke,output:Ne,cacheRead:Le,cacheWrite:We}}},[n.current,n.current.lastSeq]);return g.jsxs("div",{className:"app",children:[g.jsxs("header",{className:"topbar",children:[g.jsxs("div",{className:"brand",children:[g.jsx("span",{className:"logo"}),"agents-deck",Se?g.jsxs("button",{type:"button",className:"v stale",onClick:be,title:Se.kind==="restart"?`Running v${Se.from}; v${Se.to} is installed on disk. Restart to pick it up.`:`Running v${Se.from}; v${Se.to} is on npm.`,children:["v",Se.from,g.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const V={running:(k==null?void 0:k.running)??"1.33.96",latest:k==null?void 0:k.latest,latestPending:k==null?void 0:k.latestPending,checkedAgo:k!=null&&k.checkedAt?N4(Ye-k.checkedAt):null,checkDisabled:k==null?void 0:k.checkDisabled,checking:ce};return g.jsxs("button",{type:"button",className:ce?"v checking":"v",onClick:()=>ge(!0),"aria-busy":ce||void 0,"aria-label":g4(V),title:m4(V),children:["v",V.running]})})()]}),Lt&&(()=>{const V=cn(Lt.usage,Lt.model),X=Math.max(0,((Lt.endedAt??Ye)-Lt.startedAt)/1e3),oe=Lt.state==="active"?Yl(V.total,X):null,ue=o.size-1;return g.jsxs("button",{type:"button",className:"selected-ribbon",title:`Fit view to ${Lt.label}`,onClick:()=>{try{const ye=At.find(ke=>ke.id===Lt.id);ye&&e.fitView({padding:.35,duration:500,nodes:[ye]}),Ln.current=Date.now()}catch{}},children:[g.jsx("span",{className:`state-pill state-${Lt.state}`,children:Lt.state==="active"?"live":Lt.state}),g.jsx("span",{className:"selected-label",children:Lt.label}),V.total>0&&g.jsxs("span",{className:"selected-cost",children:[ze(V.total),oe?g.jsxs("span",{className:"selected-rate",children:[" · ",oe]}):null]}),ue>0&&g.jsxs("span",{className:"selected-extra",children:["+",ue]}),g.jsx("span",{role:"button","aria-label":"Deselect",className:"selected-close",onClick:ye=>{ye.stopPropagation(),m()},children:"×"})]})})(),g.jsxs("div",{className:"actions",children:[g.jsxs("div",{className:"search",children:[g.jsx("span",{className:"search-icon","aria-hidden":!0,children:"⌕"}),g.jsx("input",{ref:is,type:"text",placeholder:"Search agents, cwd, tools…",value:Zt,onChange:V=>$r(V.target.value),spellCheck:!1,"aria-label":"Filter the graph"}),Zt?g.jsx("button",{className:"search-clear","aria-label":"Clear search",onClick:()=>$r(""),children:"×"}):g.jsx("kbd",{className:"search-kbd","aria-hidden":!0,children:"/"})]}),g.jsxs("span",{className:"status",role:"status",children:[g.jsx("span",{className:`pill ${F?"live":"dead"}`,title:F?"Receiving events":"SSE disconnected",children:F?"live":"offline"}),g.jsxs("span",{className:"stat",title:"Distinct CC sessions",children:[g.jsx("span",{className:"count",children:Eu}),g.jsx("span",{className:"lbl",children:"sessions"})]}),g.jsxs("span",{className:"stat",title:"Total agents (root + subagents)",children:[g.jsx("span",{className:"count",children:co}),g.jsx("span",{className:"lbl",children:"agents"})]}),g.jsxs("span",{className:"stat",title:"Total hook events received",children:[g.jsx("span",{className:"count",children:n.current.totalEvents}),g.jsx("span",{className:"lbl",children:"events"})]}),Bt.sum>0&&g.jsxs("span",{className:"stat",title:`in:${Bt.inT.toLocaleString()} out:${Bt.outT.toLocaleString()} cache-r:${Bt.cacheR.toLocaleString()} cache-c:${Bt.cacheC.toLocaleString()}`,children:[g.jsx("span",{className:"count",children:v4(Bt.sum)}),g.jsx("span",{className:"lbl",children:"tokens"})]}),Fn.length>0&&g.jsxs("span",{className:"stat mcp-legend",title:`MCP servers seen this session:
60
60
  ${Fn.map(V=>` ${V.server}: ${V.count} call${V.count===1?"":"s"}`).join(`
61
61
  `)}`,children:[Fn.slice(0,6).map(V=>g.jsx("span",{className:"mcp-dot",style:{background:`hsl(${V.hue} 65% 65%)`}},V.server)),Fn.length>6&&g.jsxs("span",{className:"mcp-more",children:["+",Fn.length-6]}),g.jsx("span",{className:"lbl",children:"mcp"})]}),Bt.cost.total>0&&(()=>{let V=0,X=0;for(const ye of n.current.agents.values()){if(ye.state!=="active")continue;const ke=cn(ye.usage,ye.model);V+=ke.total,X=Math.max(X,((ye.endedAt??Ye)-ye.startedAt)/1e3)}const oe=X>0?Yl(V,X):null,ue=`input ${ze(Bt.cost.input)} + output ${ze(Bt.cost.output)} + cache r ${ze(Bt.cost.cacheRead)} + cache w ${ze(Bt.cost.cacheWrite)}${oe?`
62
62
  active burn: ${oe}`:""}`;return g.jsxs("span",{className:"stat",title:ue,children:[g.jsx("span",{className:"count",children:ze(Bt.cost.total)}),g.jsxs("span",{className:"lbl",children:["cost",oe?` · ${oe}`:""]})]})})()]}),g.jsx("button",{className:`btn ${ft?"warn":""}`,onClick:fn,title:"Pause/resume live updates (Space)",children:ft?`Resume${vt.current.size?` · ${vt.current.size}`:""}`:"Pause"}),g.jsx("button",{className:`btn icon-btn ${M?"primary":""}`,onClick:()=>O(V=>!V),title:`${M?"Hide":"Show"} usage panel (U)`,"aria-label":"Toggle usage panel",children:"$"}),P!==null&&g.jsx("button",{className:`btn icon-btn ${P?"primary":""}`,onClick:V=>{if(V.shiftKey&&U>0){B(!0),fetch("/api/sound-hook",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"restore"})}).then(()=>fetch("/api/sound-hook")).then(X=>X.ok?X.json():null).then(X=>{X!=null&&X.ok&&(q(X.enabled===!0),ee(X.parked??0))}).catch(()=>{}).finally(()=>B(!1));return}J()},disabled:W,title:(P?"Sound on turn finish: on — click to remove the hook":"Sound on turn finish: off — click to add a Stop hook")+(j>0?`