@squeed/flow-sdk 2.0.39 → 2.0.40

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.
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";var jv=Object.create;var Xo=Object.defineProperty;var Ev=Object.getOwnPropertyDescriptor;var _v=Object.getOwnPropertyNames;var kv=Object.getPrototypeOf,Pv=Object.prototype.hasOwnProperty;var Av=(e,r,t)=>r in e?Xo(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var Rv=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of _v(r))!Pv.call(e,o)&&o!==t&&Xo(e,o,{get:()=>r[o],enumerable:!(n=Ev(r,o))||n.enumerable});return e};var dt=(e,r,t)=>(t=e!=null?jv(kv(e)):{},Rv(r||!e||!e.__esModule?Xo(t,"default",{value:e,enumerable:!0}):t,e));var zt=(e,r,t)=>Av(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react"),f=require("react/jsx-runtime"),W=require("@chakra-ui/react"),Wr=require("react-dom"),Q=require("react-icons/pi"),Im=require("@emotion/react"),Mv=require("@emotion/styled"),Tv=require("react-icons/tb"),Iv=require("markdown-to-jsx/react"),Nm=e=>e&&e.__esModule?e:{default:e},xo=Nm(Mv),Nv=Nm(Iv),_t=[];for(let e=0;e<256;++e)_t.push((e+256).toString(16).slice(1));function Ov(e,r=0){return(_t[e[r+0]]+_t[e[r+1]]+_t[e[r+2]]+_t[e[r+3]]+"-"+_t[e[r+4]]+_t[e[r+5]]+"-"+_t[e[r+6]]+_t[e[r+7]]+"-"+_t[e[r+8]]+_t[e[r+9]]+"-"+_t[e[r+10]]+_t[e[r+11]]+_t[e[r+12]]+_t[e[r+13]]+_t[e[r+14]]+_t[e[r+15]]).toLowerCase()}let Yo;const $v=new Uint8Array(16);function qv(){if(!Yo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Yo=crypto.getRandomValues.bind(crypto)}return Yo($v)}const Lv=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Pu={randomUUID:Lv};function Td(e,r,t){var o;if(Pu.randomUUID&&!e)return Pu.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??qv();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ov(n)}var Fv=typeof global=="object"&&global&&global.Object===Object&&global,zv=typeof self=="object"&&self&&self.Object===Object&&self,Bv=Fv||zv||Function("return this")(),rn=Bv.Symbol,Om=Object.prototype,Dv=Om.hasOwnProperty,Wv=Om.toString,wn=rn?rn.toStringTag:void 0;function Vv(e){var r=Dv.call(e,wn),t=e[wn];try{e[wn]=void 0;var n=!0}catch{}var o=Wv.call(e);return n&&(r?e[wn]=t:delete e[wn]),o}var Gv=Object.prototype,Hv=Gv.toString;function Uv(e){return Hv.call(e)}var Kv="[object Null]",Jv="[object Undefined]",Au=rn?rn.toStringTag:void 0;function Zv(e){return e==null?e===void 0?Jv:Kv:Au&&Au in Object(e)?Vv(e):Uv(e)}function Xv(e){return e!=null&&typeof e=="object"}var Yv="[object Symbol]";function Qv(e){return typeof e=="symbol"||Xv(e)&&Zv(e)==Yv}function e0(e,r){for(var t=-1,n=e==null?0:e.length,o=Array(n);++t<n;)o[t]=r(e[t],t,e);return o}var ot=Array.isArray,Ru=rn?rn.prototype:void 0,Mu=Ru?Ru.toString:void 0;function $m(e){if(typeof e=="string")return e;if(ot(e))return e0(e,$m)+"";if(Qv(e))return Mu?Mu.call(e):"";var r=e+"";return r=="0"&&1/e==-1/0?"-0":r}function Id(e){return e==null?"":$m(e)}function t0(e,r,t){var n=-1,o=e.length;r<0&&(r=-r>o?0:o+r),t=t>o?o:t,t<0&&(t+=o),o=r>t?0:t-r>>>0,r>>>=0;for(var i=Array(o);++n<o;)i[n]=e[n+r];return i}function r0(e,r,t){var n=e.length;return t=t===void 0?n:t,!r&&t>=n?e:t0(e,r,t)}var n0="\\ud800-\\udfff",o0="\\u0300-\\u036f",i0="\\ufe20-\\ufe2f",a0="\\u20d0-\\u20ff",s0=o0+i0+a0,c0="\\ufe0e\\ufe0f",l0="\\u200d",d0=RegExp("["+l0+n0+s0+c0+"]");function qm(e){return d0.test(e)}function u0(e){return e.split("")}var Lm="\\ud800-\\udfff",f0="\\u0300-\\u036f",h0="\\ufe20-\\ufe2f",p0="\\u20d0-\\u20ff",g0=f0+h0+p0,y0="\\ufe0e\\ufe0f",m0="["+Lm+"]",wd="["+g0+"]",Cd="\\ud83c[\\udffb-\\udfff]",b0="(?:"+wd+"|"+Cd+")",Fm="[^"+Lm+"]",zm="(?:\\ud83c[\\udde6-\\uddff]){2}",Bm="[\\ud800-\\udbff][\\udc00-\\udfff]",x0="\\u200d",Dm=b0+"?",Wm="["+y0+"]?",v0="(?:"+x0+"(?:"+[Fm,zm,Bm].join("|")+")"+Wm+Dm+")*",w0=Wm+Dm+v0,C0="(?:"+[Fm+wd+"?",wd,zm,Bm,m0].join("|")+")",S0=RegExp(Cd+"(?="+Cd+")|"+C0+w0,"g");function j0(e){return e.match(S0)||[]}function E0(e){return qm(e)?j0(e):u0(e)}function _0(e){return function(r){r=Id(r);var t=qm(r)?E0(r):void 0,n=t?t[0]:r.charAt(0),o=t?r0(t,1).join(""):r.slice(1);return n[e]()+o}}var k0=_0("toUpperCase");function P0(e,r,t,n){for(var o=-1,i=e==null?0:e.length;++o<i;)t=r(t,e[o],o,e);return t}function A0(e){return function(r){return e==null?void 0:e[r]}}var R0={À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"},M0=A0(R0),T0=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,I0="\\u0300-\\u036f",N0="\\ufe20-\\ufe2f",O0="\\u20d0-\\u20ff",$0=I0+N0+O0,q0="["+$0+"]",L0=RegExp(q0,"g");function F0(e){return e=Id(e),e&&e.replace(T0,M0).replace(L0,"")}var z0=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function B0(e){return e.match(z0)||[]}var D0=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function W0(e){return D0.test(e)}var Vm="\\ud800-\\udfff",V0="\\u0300-\\u036f",G0="\\ufe20-\\ufe2f",H0="\\u20d0-\\u20ff",U0=V0+G0+H0,Gm="\\u2700-\\u27bf",Hm="a-z\\xdf-\\xf6\\xf8-\\xff",K0="\\xac\\xb1\\xd7\\xf7",J0="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Z0="\\u2000-\\u206f",X0=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Um="A-Z\\xc0-\\xd6\\xd8-\\xde",Y0="\\ufe0e\\ufe0f",Km=K0+J0+Z0+X0,Jm="['’]",Tu="["+Km+"]",Q0="["+U0+"]",Zm="\\d+",ew="["+Gm+"]",Xm="["+Hm+"]",Ym="[^"+Vm+Km+Zm+Gm+Hm+Um+"]",tw="\\ud83c[\\udffb-\\udfff]",rw="(?:"+Q0+"|"+tw+")",nw="[^"+Vm+"]",Qm="(?:\\ud83c[\\udde6-\\uddff]){2}",eb="[\\ud800-\\udbff][\\udc00-\\udfff]",Xr="["+Um+"]",ow="\\u200d",Iu="(?:"+Xm+"|"+Ym+")",iw="(?:"+Xr+"|"+Ym+")",Nu="(?:"+Jm+"(?:d|ll|m|re|s|t|ve))?",Ou="(?:"+Jm+"(?:D|LL|M|RE|S|T|VE))?",tb=rw+"?",rb="["+Y0+"]?",aw="(?:"+ow+"(?:"+[nw,Qm,eb].join("|")+")"+rb+tb+")*",sw="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",cw="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",lw=rb+tb+aw,dw="(?:"+[ew,Qm,eb].join("|")+")"+lw,uw=RegExp([Xr+"?"+Xm+"+"+Nu+"(?="+[Tu,Xr,"$"].join("|")+")",iw+"+"+Ou+"(?="+[Tu,Xr+Iu,"$"].join("|")+")",Xr+"?"+Iu+"+"+Nu,Xr+"+"+Ou,cw,sw,Zm,dw].join("|"),"g");function fw(e){return e.match(uw)||[]}function hw(e,r,t){return e=Id(e),r=r,r===void 0?W0(e)?fw(e):B0(e):e.match(r)||[]}var pw="['’]",gw=RegExp(pw,"g");function yw(e){return function(r){return P0(hw(F0(r).replace(gw,"")),e,"")}}var Dt=yw(function(e,r,t){return e+(t?" ":"")+k0(r)});const vo={label:"Untitled",description:"",isTask:!1,isLocked:!1},Nd={id:null,type:"text",data:{...vo,viewProps:{width:"max-content !important",maxWidth:700,height:"100%",borderColor:"transparent",borderRadius:25,borderWidth:0,boxShadow:"none",textOverflow:"ellipsis",fontWeight:"bold",textColor:"gray.800",textAlign:"center"}}},$u={id:null,type:"objectView",data:{...vo,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},mw={id:null,type:"arrayView",data:{...vo,viewProps:{width:"max-content !important",maxWidth:700,height:"100%",textAlign:"center",borderRadius:25,fontSize:"5xl",borderWidth:2,textOverflow:"ellipsis",wordBreak:"keep-all",fontWeight:"bold",textColor:"gray.900",placeholder:"Start Typing"}}},qu={id:null,type:"workflowStep",data:{...vo,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},Ot=e=>typeof e=="object",nb=e=>Array.isArray(e),bw=["order","position","selected","locked","grabbed","grabbable","scratch"],Pr=e=>Object.entries(e).reduce((r,[t,n])=>(!Ot(n)&&!t.startsWith("$")&&(r[t]=n),r),{}),Od=(e,r)=>typeof e=="string"&&e.startsWith("$")?Qo(e,r):Ot(e)&&!nb(e)?Object.entries(e).reduce((t,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete t["..."],t[n]={...Qo(o,r),...e}):typeof o=="string"&&o.startsWith("$")?t[n]=Qo(o,r):t[n]=o,t),{}):e,Ar=e=>Object.entries(e).reduce((r,[t,n])=>(Ot(n)&&t&&n&&!t.startsWith("$")&&(bw.includes(t)&&(t=t+"#"),r[t]=n),r),{}),Fr=(e,r,{label:t,parent:n=void 0},o,i=null)=>(i!==null&&(Ot(i)||nb(i))&&(i=JSON.stringify(i,null,2)),{data:{parent:n,...e.data,id:r,text:t||"",label:t,code:i||null,type:e.type,description:o}}),jr=(e,r,t=null,n=null,o=null,i=!1,s=null)=>({data:{id:Td(),source:o?r:e,target:o?e:r,label:n||"",isInverted:o,isEdgeAnimated:i,parent:s}}),Rr=(e,r=[])=>{const t={},n={};let o=[];if(e)for(const[i,s]of Object.entries(e))i.startsWith("$")&&i!=="$"?t[i.slice(1)]=s:i!=="$"?n[i]=s:i==="$"&&(o=s);return{newConfig:t,updatedObject:n,arrayObject:o}},Yr=(e,r)=>{let t=$u;const{view:n,borderColor:o,borderRadius:i,bgColor:s,textColor:a,fontSize:c,stepType:l}=r;e=n||e,l?t={...qu}:e==="object"?t=$u:e==="text"?t=Nd:e==="array"?t=mw:e==="workflowStep"&&(t={...qu});const d=t.data.viewProps;return t.data.viewProps={...d,borderRadius:i||(l?15:53),bgColor:s,borderColor:o,textColor:a,fontSize:c},t.data.config=r,{config:t}},Fn=(e,r)=>(e=r.find(n=>n.data.id===e)?`${e}.#`:e,e),Qo=(e,{ids:r,jsnObjct:t})=>{if(typeof e=="string"&&(e!=null&&e.startsWith("$"))){const n=e.replace("$","").replace("*","");e==null||e.endsWith("*");const o=r.find(a=>a.split(".").slice(-1)[0]===n||n===a);if(!o)return e;const i=xw(o,t);return JSON.stringify(i).includes(e)?e:i||e}return e},xw=(e,r)=>{let t=e.split(".").splice(1);return t=t[t.length-1]==="#"||t[t.length-1].includes("{")?t.slice(0,-2):t,(i=>t.reduce((s,a)=>{a=a.replace("[","").replace("]","");const{arrayObject:c}=Rr(s);return s=c.length?c:s,s[a]},i))(r)};function en(e,r="root",t=[]){try{const{arrayObject:n}=Rr(e);n.length&&(e=n);const o=Pr(e),i=Ar(e);return Ot(e)?(ot(e)||ot(e)&&r==="root"||!ot(e)&&Object.keys(o).length||r==="root")&&t.push(r):t.push(r),Object.keys(i).length&&!ot(e)?Rn({chldPth:null,itrblObjct:i,nodes:t,path:r}):ot(e)&&e.forEach((s,a)=>{const c=Pr(s),l=Ar(s),{newConfig:d,arrayObject:u}=Rr(s);let h=`${r}.${a}`;Ot(s)?Object.keys(c).length?(en(c,h,t),Object.keys(l).length&&!ot(s)&&Rn({chldPth:h,itrblObjct:l,nodes:t,path:r})):Object.keys(l).length&&!ot(s)?Rn({chldPth:h,itrblObjct:l,nodes:t,path:r}):ot(s)&&ob({chldPth:h,item:s,nodes:t,path:r}):t.push(h)}),{nodes:t}}catch{return{nodes:t}}}const Rn=({chldPth:e,itrblObjct:r,nodes:t,path:n})=>Object.entries(r).forEach(([o,i],s)=>{const a=Pr(i),c=Ar(i),{newConfig:l,arrayObject:d}=Rr(i);d.length&&(i=d),n.split(".").slice(0,2).join(".");let u=e?`${e}.${o}`:`${n}.${o}`;if(Ot(i)&&!ot(i)){const h=Object.keys(a).length===0;if(h&&(Yr("array",l),t.push(u)),Object.keys(a).length){const p=ot(i)?`${i.length||""}`:`{${Object.keys(i).length||""}}`;let m=u;h&&(m=`${u}.${p}`),en(i,m,t)}else Object.keys(c).length&&!ot(i)?Rn({chldPth:u,itrblObjct:c,path:u,nodes:t}):en(i,u,t)}else ot(i)&&en(i,u,t)}),ob=({chldPth:e,item:r,nodes:t,path:n})=>r.forEach((o,i)=>{let s=`${e}.${i}`;const a=Ar(o),c=Pr(o);Ot(o)?!ot(o)&&Object.keys(c).length?en(o,s,t):Object.keys(a).length&&!ot(o)?Rn({chldPth:s,itrblObjct:a,path:n,nodes:t}):ot(o)&&ob({chldPth:s,item:o,nodes:t,path:n}):t.push(s)}),Mn=[];let Tn;function Dr(e,r="root",t=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},s={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:t,edges:n};const a=e;if(r==="root"&&(Mn.length=0),!Tn){const{nodes:d}=en(e);Tn={ids:d,jsnObjct:e}}let{hideDefaultObject:c,sprtObjctKy:l}=i;try{r=Fn(r,t);const{newConfig:d,arrayObject:u}=Rr(e),h=Object.keys(s).length>0?s:d;u.length&&(e=u);const p=Pr(e),m=Ar(e),{label:g,collapsed:y,parent:b}=h;if(!Ot(e))t.push(Fr(Nd,r,{label:g||r,parent:b},e,a));else if(ot(e)||ot(e)&&r==="root"){const{config:x}=Yr("array",h),v=ot(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,w=r==="root"?o:`${o} ${v}`;t.push(Fr(x,r,{label:g||w,parent:b},e,ot(a)?{[o]:a}:a))}else if(!ot(e)&&Object.keys(p).length||r==="root"){const{config:x}=Yr(null,h),v=ot(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,w=r.split("."),C=w[w.length-1];let S=isNaN(Number(C))?null:Number(C)+1;const E=isNaN(Number(C))?C:w[w.length-2]+" "+S,M=r==="root"?o:E;let P=!1;Number.isNaN(Number(o))||(P=!0);const T=e;if(g){const{config:k}=Yr("object",h);t.push(Fr(k,r,{label:g||`${g} ${v}`,parent:b},p,T))}else x.data.headerTitle=M,t.push(Fr(x,r,{label:g,parent:b},p,T))}return y||(Object.keys(m).length&&!ot(e)?In({flowConfig:i,chldPth:null,edges:n,isInverted:null,itrblObjct:m,nodes:t,path:r,newConfig:h}):ot(e)&&e.forEach((x,v)=>{x=Od(x,Tn);const w=x,C=Pr(x),S=Ar(x),{newConfig:E,arrayObject:M}=Rr(x);M.length&&(x=M);const{config:P}=Yr(typeof x=="string"?"text":"array",E),{hideConfig:T,sourceLabel:k,label:R,isEdgeAnimated:_,parent:N}=E;c=c||T;const $=r==="root"&&i.isCntr,V=r.split(".").slice(0,2).join("."),I=Mn.includes(V),F=i.isCntr&&I||v%2===0&&$;let oe=`${r}.${v}`;oe=Fn(oe,t),F&&Mn.push(oe),Ot(x)?Object.keys(C).length&&!ot(x)?(n.push(jr(r,oe,null,k,F,_)),Dr(x,oe,t,n,R||v,i,E)):Object.keys(S).length&&!ot(x)?In({flowConfig:i,chldPth:oe,isInverted:F,edges:n,itrblObjct:S,nodes:t,path:r,newConfig:E,forceIsInverted:!0}):ot(x)?ib({flowConfig:i,chldPth:oe,edges:n,isInverted:F,item:x,nodes:t,path:r}):Ot(x)&&In({flowConfig:i,chldPth:oe,isInverted:F,edges:n,itrblObjct:[x],nodes:t,path:r,newConfig:E}):(n.push(jr(r,oe,null,k,F,_)),t.push(Fr(P,oe,{label:R||String(x),parent:N},x,w)))})),{nodes:t,edges:n}}catch{return{nodes:t,edges:n}}}const In=({chldPth:e,flowConfig:r,edges:t,itrblObjct:n,nodes:o,isInverted:i,path:s,newConfig:a,forceIsInverted:c=!1})=>{let{hideDefaultObject:l,sprtObjctKy:d}=r;return Object.entries(n).forEach(([u,h],p)=>{h=Od(h,Tn);const m=h,g=Pr(h),y=Ar(h),{newConfig:b,arrayObject:x}=Rr(h);x.length&&(h=x);const{hideConfig:v,sourceLabel:w,label:C,content:S,target:E,targetLabel:M,collapsed:P,isEdgeAnimated:T,parent:k}=b;l=l||v;const R=s==="root"&&r.isCntr,_=s.split(".").slice(0,2).join("."),N=Mn.includes(_);c||(i=r.isCntr&&N||p%2===0&&R);let $=e?`${e}.${u}`:`${s}.${u}`;if($=Fn($,o),i&&Mn.push($),E&&t.push(jr($,E,null,M,i,T)),Ot(h)&&!ot(h)){t.push(jr(s,$,null,w,i,T));const V=d||Object.keys(g).length===0;if(V){const I=S?"object":"array",{config:F}=Yr(I,b);F.data.headerTitle=S?C:null,o.push(Fr(F,$,{label:C||u,parent:k},h,m))}if(Object.keys(g).length&&!l){const I=ot(h)?` ${h.length||""}`:`{${Object.keys(h).length||""}}`;let F=$;V&&(F=`${$}.${I}`,F=Fn(F,o),t.push(jr($,F,null,w,i,T))),Dr(h,F,o,t,C||u,r,b)}else Object.keys(y).length&&!ot(h)?In({chldPth:$,flowConfig:r,itrblObjct:y,path:$,edges:t,nodes:o,newConfig:b,isInverted:i}):Dr(h,$,o,t,u,r,b)}else ot(h)&&(t.push(jr(s,$,null,w,i,T)),Dr(h,$,o,t,u,r,b))})},ib=({flowConfig:e,chldPth:r,edges:t,isInverted:n,item:o,nodes:i,path:s})=>o.forEach((a,c)=>{let l=`${r}.${c}`;l=Fn(l,i);const d=a;a=Od(a,Tn);const u=Ar(a),h=Pr(a),{newConfig:p}=Rr(a),{collapsed:m,label:g,parent:y,sourceLabel:b,isEdgeAnimated:x,content:v}=p;Ot(a)?!ot(a)&&Object.keys(h).length?(t.push(jr(s,l,null,b,n,x)),Dr(a,l,i,t,c,e,p)):Object.keys(u).length&&!ot(a)&&!m?In({chldPth:l,flowConfig:e,itrblObjct:u,path:s,edges:t,nodes:i,isInverted:n,newConfig:p}):ot(a)&&ib({flowConfig:e,chldPth:l,edges:t,isInverted:n,item:a,nodes:i,path:s}):(t.push(jr(s,l,null,b,n,x)),i.push(Fr(Nd,l,{label:g||String(a),parent:y},a,d)))});function vw(e,r){const t=new Set,n=(l,d="root")=>{if(!(!l||typeof l!="object")){l.$view==="parent"&&t.add(d),typeof l.$parent=="string"&&t.add(l.$parent);for(const[u,h]of Object.entries(l))(!u.startsWith("$")||u==="$")&&n(h,u==="$"?d:`${d}.${u}`)}};if(n(e),!t.size)return r;const o=new Map(r.nodes.map(l=>[l.data.id,l])),i=l=>{var p,m;let d=l.data.id;const u=new Set([l.data.id]);let h=l.data.parent;for(;h&&!u.has(h);)t.has(h)&&o.has(h)&&((p=Oe(e,h))!=null&&p.$collapsed)&&(d=h),u.add(h),h=(m=o.get(h))==null?void 0:m.data.parent;return d},s=new Map(r.nodes.map(l=>[l.data.id,i(l)])),a=r.nodes.filter(l=>s.get(l.data.id)===l.data.id).map(l=>{if(!t.has(l.data.id))return l;const d=Oe(e,l.data.id),u=!!(d!=null&&d.$collapsed);return{...l,data:{...l.data,...u?{type:"arrayView"}:{},config:{...l.data.config,parentContainer:!0,collapsed:u,...u?{labelBelow:!0,icon:(d==null?void 0:d.$icon)||"PiStack"}:{}}}}}),c=new Set(a.map(l=>l.data.id));return{nodes:a,edges:r.edges.flatMap(l=>{const d=s.get(l.data.source),u=s.get(l.data.target);return!d||!u||!c.has(d)||!c.has(u)?[]:d===l.data.source&&u===l.data.target?[l]:d===u?[]:[{...l,data:{...l.data,source:d,target:u,collapsedEndpoints:l.data.collapsedEndpoints??{source:l.data.source,target:l.data.target}}}]})}}function wo(e){if(!Array.isArray(e==null?void 0:e.$connections))return[];const r=new Map;return e.$connections.flatMap((t,n)=>{if(!t||typeof t!="object")return[];const o=t;if(typeof o.target!="string"||!/^root(?:\.|$)/.test(o.target))return[];if(o.sourceProperty!==void 0&&typeof o.sourceProperty!="string")return[];if(o.targetProperty!==void 0&&typeof o.targetProperty!="string")return[];const i=typeof o.id=="string"&&o.id?JSON.stringify(["id",o.id]):JSON.stringify(["ports",o.target,o.sourceProperty??null,o.targetProperty??null]),s=r.get(i)??0;return r.set(i,s+1),[{value:o,key:`${i}#${s}`,index:n}]})}function ab(e,r,t){const n=wo(e).find(c=>c.key===r);if(!n)return e;const o=t(n.value),i=e.$connections.flatMap((c,l)=>l===n.index?o?[o]:[]:[c]);if(i.length)return{...e,$connections:i};const{$connections:s,...a}=e;return a}function ww(e){const r=[],t=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,s)=>t(i,`${o}.${s}`));for(const i of wo(n)){const s=i.value;r.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:s.target,type:typeof s.type=="string"?s.type:void 0,sourceProperty:s.sourceProperty,targetProperty:s.targetProperty,icon:typeof s.icon=="string"?s.icon:void 0,label:typeof s.label=="string"?s.label:void 0,color:typeof s.color=="string"?s.color:void 0,isEdgeDashed:s.style==="dashed",isEdgeAnimated:s.style==="animated",...["dashed","traveling"].includes(s.animationVariant)?{edgeAnimationVariant:s.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,s])=>[i,i==="$"?t(s,o):i.startsWith("$")?s:t(s,`${o}.${i}`)]))};return{json:t(e,"root"),edges:r}}const tn="root";function sb(e,r,t){return!t||Oe(e,r)===void 0||!t.userId||!t.name.trim()||!Number.isFinite(Date.parse(t.at))?e:kt(e,r,"$edited",t)}const Lu=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Kt(e){const r=e.split(".");for(r[0]===tn&&r.shift();r.length&&Lu(r[r.length-1]);)r.pop();return r.filter(t=>!Lu(t))}function Co(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function Oe(e,r){return Kt(r).reduce((t,n)=>{var o;if(t!=null)return(o=Co(t))==null?void 0:o[n]},e)}function Cw(e){return Array.isArray(e)?[...e]:{...e}}function Pt(e,r,t){const n=Kt(r),o=(i,s)=>{if(s===n.length)return t(i);const a=n[s],c=Co(i);if(c==null||typeof c!="object")return i;const l=o(c[a],s+1);if(Object.is(l,c[a]))return i;const d=Cw(c);return d[a]=l,c!==i?{...i,$:d}:d};return o(e,0)}function pr(e,r,t){const n=t===""&&r!=="$content"||t===void 0||t===null;if(Array.isArray(e))return n?e:{[r]:t,$:[...e]};const o=e!=null&&typeof e=="object"?{...e}:{};return e!=null&&typeof e!="object"&&(o.$label=String(e)),n?delete o[r]:o[r]=t,o}function kt(e,r,t,n){return Pt(e,r,o=>t==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:pr(o,t,n))}const uo=(e,r,t)=>kt(e,r,"$collapsed",t);function zr(e){if(e.connection)return{address:e.connection.address,kind:"connection"};const r=e.collapsedEndpoints??e,t=e.isInverted?r.target:r.source,n=e.isInverted?r.source:r.target,o=Kt(t).join("."),i=Kt(n).join(".");return i.startsWith(o?o+".":"")&&i!==o?{address:n,kind:"hierarchy"}:o.startsWith(i?i+".":"")&&o!==i?{address:t,kind:"hierarchy"}:{address:t,kind:"target"}}function Sr(e,r,t,n){if(r.connection){const a=r.connection;return Pt(e,a.address,c=>ab(c,a.key,l=>{if(t==="$edgeIcon")return pr(l,"icon",n);if(t==="$edgeType")return pr(l,"type",n);if(t==="$edgeAnimationVariant")return pr(l,"animationVariant",n);if(t==="$sourceLabel"||t==="$edgeColor")return pr(l,t==="$sourceLabel"?"label":"color",n);const d=t==="$isEdgeAnimated"?"animated":"dashed";return n?{...l,style:d}:l.style===d?pr(l,"style",void 0):l}))}const{address:o,kind:i}=zr(r),s=i==="target"&&t==="$sourceLabel"?"$targetLabel":i==="target"&&t==="$edgeType"?"$targetEdgeType":i==="target"&&t==="$edgeIcon"?"$targetIcon":i==="target"&&t==="$edgeAnimationVariant"?"$targetAnimationVariant":t;return Pt(e,o,a=>pr(a,s,n))}const cb=(e,r,t)=>Sr(Sr(e,r,"$isEdgeAnimated",t==="animated"||void 0),r,"$isEdgeDashed",t==="dashed"||void 0);function $d(e,r,t,n){let o=n||"";const i=Pt(e,r,a=>{const c=Co(a);if(Array.isArray(c)){o=String(c.length);const d=[...c,t];return c===a?d:{...a,$:d}}const l=a!=null&&typeof a=="object"&&!Array.isArray(a)?{...a}:a!=null&&typeof a!="object"?{$label:String(a)}:{};if(!o){let d=1;for(;`node_${d}`in l;)d++;o=`node_${d}`}return l[o]=t,l}),s=Kt(r);return{json:i,address:[tn,...s,o].join(".")}}function lb(e,r){const t=Kt(r);if(!t.length)return e;const n=t[t.length-1],o=[tn,...t.slice(0,-1)].join(".");return Pt(e,o,i=>{const s=Co(i);if(s==null||typeof s!="object"||!Object.prototype.hasOwnProperty.call(s,n))return i;if(Array.isArray(s)){const l=s.filter((d,u)=>String(u)!==n);return s===i?l:{...i,$:l}}const{[n]:a,...c}=i;return c})}const db=(e,r,t,n)=>kt(n?Pt(e,r,o=>pr(o,"$targetLabel",n)):e,r,"$target",t);function qd(e,r,t){const n=Oe(e,r);return wo(n).some(({value:i})=>i.target===t.target&&i.sourceProperty===t.sourceProperty&&i.targetProperty===t.targetProperty)?e:Pt(e,r,i=>pr(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...t,id:t.id||Td()}]))}function ub(e,r){if(r.connection){const i=r.connection;return wo(Oe(e,i.address)).some(s=>s.key===i.key)?{json:Pt(e,i.address,s=>ab(s,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:t,kind:n}=zr(r);return n==="hierarchy"?Oe(e,t)===void 0?{json:e,removed:!1}:{json:Pt(e,t,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:Pt(e,t,i=>{const{$target:s,$targetLabel:a,...c}=i||{};return c}),removed:!0}}function Sd(e,r={}){var x;const t=ww(e),{nodes:n,edges:o}=Dr(t.json,tn,[],[],r.title||"untitled",{hideDefaultObject:!!r.hideDefaultObject,sprtObjctKy:!!r.separateObjectKeys,isCntr:!!r.isCenter}),i=new Set(n.map(v=>v.data.id)),s=new Map;for(const v of n){const w=v.data.id;if(!w.endsWith(".0")||Oe(e,w)!==void 0)continue;const C=w.slice(0,-2),S=Oe(e,C);!i.has(C)&&S&&typeof S=="object"&&!Array.isArray(S)&&typeof S.$label=="string"&&Object.keys(S).every(E=>E.startsWith("$")&&E!=="$")&&s.set(w,C)}const a=v=>s.get(v)??v,c=new Set(n.flatMap(v=>v.data.parent?[a(v.data.parent)]:[])),l=new Map;if(r.isCenter){const v=new Map;for(const{data:w}of o){const C=zr(w);if(C.kind==="hierarchy")l.set(a(C.address),!!w.isInverted);else if(!Array.isArray(e)&&e.$hideRoot===!0){const S=a(w.isInverted?w.source:w.target);if(Kt(S).length!==1)continue;const E=!!w.isInverted;v.set(S,v.has(S)&&v.get(S)!==E?null:E)}}for(const[w]of l){const C=`${tn}.${Kt(w)[0]}`,S=v.get(C);typeof S=="boolean"&&l.set(w,S)}}const d=n.map(v=>{var P;const w=a(v.data.id),C=Oe(e,w),S={...v.data,id:w};l.has(w)&&(S.config={...S.config,isInverted:l.get(w)});const E=C&&typeof C=="object"&&!Array.isArray(C)&&"$"in C?C.$:C;if((Array.isArray(E)?E.length>0:E&&typeof E=="object"&&Object.keys(E).some(T=>!T.startsWith("$")))&&(S.config={...S.config,collapsed:!!C.$collapsed}),c.has(w)||(S.viewProps={...S.viewProps},delete S.viewProps.borderWidth),!C||typeof C!="object"||Array.isArray(C))return{data:S};if(C.$view==="parent"&&(S.type="objectView",S.config={...S.config,typeView:"parent",parentContainer:!0,collapsed:!!C.$collapsed}),C.$view==="grid"){S.type="grid";const T=C.$gridSize;if(T!==void 0&&(!T||![T.width,T.height].every(k=>Number.isFinite(k)&&k>0&&k<=16384)))throw new Error("Invalid grid frame size.");S.config={...S.config,typeView:"grid",documentId:C.$document,gridSize:T},S.viewProps={...S.viewProps,bgColor:C.$bgColor??"transparent",borderRadius:C.$borderRadius??0,borderWidth:C.$borderWidth??0}}if(C.$form&&typeof C.$form=="object"&&(S.config={...S.config,form:C.$form},S.type="objectView"),C.$view==="prompt"&&(S.type="prompt",S.config={...S.config,typeView:"prompt"}),Array.isArray(C.$ports)){const T=C.$ports.filter(k=>k&&typeof k.id=="string"&&["source","target"].includes(k.role)&&["top","right","bottom","left"].includes(k.side));S.config={...S.config,ports:T}}if(S.parent&&(S.parent=a(S.parent)),typeof C.$label=="string"&&(S.label=C.$label,S.headerTitle=C.$label),typeof C.$subtitle=="string"&&(S.config={...S.config,subtitle:C.$subtitle}),C.$edited&&typeof C.$edited=="object"&&(S.config={...S.config,edited:C.$edited},S.description&&(S.description={...S.description},delete S.description.$edited)),typeof C.$outline=="boolean"&&(S.viewProps={...S.viewProps,outline:C.$outline}),["solid","dashed","dotted","double"].includes(C.$borderStyle)&&(S.viewProps={...S.viewProps,borderStyle:C.$borderStyle}),Number.isFinite(C.$borderWidth)&&C.$borderWidth>=0&&(S.viewProps={...S.viewProps,borderWidth:C.$borderWidth}),Number.isFinite(C.$borderRadius)&&C.$borderRadius>=0&&(S.viewProps={...S.viewProps,borderRadius:C.$borderRadius}),typeof C.$isNodeAnimated=="boolean"&&(S.isNodeAnimated=C.$isNodeAnimated),["traveling","pulse"].includes(C.$nodeAnimationVariant)&&(S.nodeAnimationVariant=C.$nodeAnimationVariant),typeof C.$content=="string"||C.$contentFormat==="jsx"&&Array.isArray(C.$content)){S.config={...S.config,content:C.$content};const T=C.$contentFormat??"markdown";if(!["markdown","html","jsx"].includes(T))throw new Error("Invalid content format: expected markdown, html, or jsx.");S.config.contentFormat=T,C.$view||(S.type="objectView")}return(((P=S.config)==null?void 0:P.collapsed)!==void 0||C.$collapsed!==void 0||C.$icon!==void 0)&&(S.config={...S.config||{}},(C.$collapsed!==void 0||S.config.collapsed!==void 0)&&(S.config.collapsed=!!C.$collapsed),C.$icon!==void 0&&(S.config.icon=C.$icon)),{data:S}}),u=new Map,h=o.map(v=>{let w=a(v.data.source),C=a(v.data.target),S=v.data.isInverted;const E=zr(v.data),M=l.get(a(E.address));E.kind==="hierarchy"&&M!==void 0&&M!==!!S&&([w,C]=[C,w],S=M);const P=`${w}->${C}`,T=u.get(P)??0;u.set(P,T+1);const k={...v.data,id:T?`${P}#${T}`:P,source:w,target:C,isInverted:S},R=zr(k),_=Oe(e,R.address);if(_&&typeof _=="object"){const N=_[R.kind==="target"?"$targetEdgeType":"$edgeType"];typeof N=="string"&&(k.type=N);const $=_[R.kind==="target"?"$targetIcon":"$edgeIcon"];typeof $=="string"&&(k.icon=$),_.$isEdgeAnimated!==void 0&&(k.isEdgeAnimated=!!_.$isEdgeAnimated);const V=_[R.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(V)&&(k.edgeAnimationVariant=V),_.$isEdgeDashed!==void 0&&(k.isEdgeDashed=!!_.$isEdgeDashed),_.$edgeColor&&(k.color=_.$edgeColor)}return{data:k}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const v=d.findIndex(w=>w.data.id===tn);v!==-1&&d.splice(v,1)}const p=new Set(d.map(v=>v.data.id));for(let v=h.length-1;v>=0;v--){const w=h[v].data,C=zr(w);(!p.has(w.source)||!p.has(w.target)||C.kind==="hierarchy"&&((x=Oe(e,C.address))==null?void 0:x.$hideParentEdge)===!0)&&h.splice(v,1)}h.push(...t.edges.filter(v=>p.has(v.data.source)&&p.has(v.data.target)));const m=vw(e,{nodes:d,edges:h}),g=m.nodes.filter(v=>{var w;return(w=v.data.config)==null?void 0:w.collapsed}).map(v=>Kt(v.data.id));if(!g.length)return m;const y=m.nodes.filter(v=>{const w=Kt(v.data.id);return!g.some(C=>C.length<w.length&&C.every((S,E)=>S===w[E]))}),b=new Set(y.map(v=>v.data.id));return{nodes:y,edges:m.edges.filter(v=>b.has(v.data.source)&&b.has(v.data.target))}}function Sw(e,r){const t=new Set(e.filter(c=>{var l,d;return(d=(l=c.data)==null?void 0:l.config)==null?void 0:d.collapsed}).map(c=>c.data.id));if(!t.size)return{nodes:e,edges:r};const n=new Map(e.map(c=>[c.data.id,c])),o=new Set(e.map(c=>c.data.parent).filter(Boolean)),i=new Map(e.map(c=>{var h;let l=c.data.id,d=c.data.parent;const u=new Set([l]);for(;d&&!u.has(d);)t.has(d)&&(l=d),u.add(d),d=(h=n.get(d))==null?void 0:h.data.parent;return[c.data.id,l]})),s=new Map;for(const c of r){const l=c.data.isInverted?c.data.target:c.data.source,d=c.data.isInverted?c.data.source:c.data.target;(s.get(l)??s.set(l,[]).get(l)).push(d)}const a=new Set(e.filter(c=>i.get(c.data.id)!==c.data.id).map(c=>c.data.id));for(const c of t){if(o.has(c))continue;const l=[...s.get(c)||[]];for(;l.length;){const d=l.pop();t.has(d)||a.has(d)||(a.add(d),l.push(...s.get(d)||[]))}}return{nodes:e.filter(c=>!a.has(c.data.id)).map(c=>{var l;return t.has(c.data.id)&&o.has(c.data.id)?{...c,data:{...c.data,type:"arrayView",label:c.data.label??c.data.headerTitle,config:{...c.data.config,parentContainer:!0,labelBelow:!0,icon:((l=c.data.config)==null?void 0:l.icon)||"PiStack"}}}:c}),edges:r.flatMap(c=>{const l=i.get(c.data.source)??c.data.source,d=i.get(c.data.target)??c.data.target;return a.has(l)||a.has(d)?[]:l===c.data.source&&d===c.data.target?[c]:l===d?[]:[{...c,data:{...c.data,source:l,target:d,collapsedEndpoints:c.data.collapsedEndpoints??{source:c.data.source,target:c.data.target}}}]})}}const jw=new Intl.RelativeTimeFormat("en",{numeric:"always"});function fb(e,r=Date.now()){if(!e)return;const t=Date.parse(e);if(!Number.isFinite(t))return;const n=Math.max(0,Math.floor((r-t)/1e3));if(n<60)return"just now";const o=[[31536e3,"year"],[2592e3,"month"],[86400,"day"],[3600,"hour"],[60,"minute"]],[i,s]=o.find(([a])=>n>=a);return jw.format(-Math.floor(n/i),s)}let jd=Date.now(),to;const ro=new Set,Ew=e=>(ro.add(e),to||(jd=Date.now(),to=setInterval(()=>{jd=Date.now(),ro.forEach(r=>r())},6e4)),()=>{ro.delete(e),ro.size||(clearInterval(to),to=void 0)}),_w=()=>jd,kw=()=>0;function Pw(e){const r=j.useSyncExternalStore(Ew,_w,kw);return fb(e,r||Date.now())}function Aw(e,r){let t,n,o,i;const s=(l=t)=>!!l&&["completed","failed","cancelled"].includes(l.status),a=()=>{const l=i;i=void 0,l==null||l()},c=l=>{if(!n||n.signal.aborted||!t||l.executionId!==t.executionId||s())return;const{step:d,...u}=l;t={...t,...u,steps:d?{...t.steps,[d.id]:{...t.steps[d.id],...d}}:t.steps},n.state=t,s()&&a(),r(t)};return{getState:()=>t,async run(l,d=crypto.randomUUID()){if(n&&!n.signal.aborted&&!s())throw new Error("An execution is already active.");o==null||o.abort(),a(),o=new AbortController;const u={executionId:d,input:l,signal:o.signal,state:{executionId:d,status:"subscribing",steps:{}}};n=u,t=u.state,r(t);try{const h=await e.subscribe(u,m=>{n===u&&c(m)});if(n!==u||u.signal.aborted||s())return h(),u.state;if(i=h,c({executionId:d,status:"running"}),n!==u||u.signal.aborted||s(u.state))return u.state;const p=await e.execute(u);n===u&&p&&c(p)}catch(h){if(s(u.state))return u.state;throw n===u&&!u.signal.aborted&&c({executionId:d,status:"failed",error:h instanceof Error?h.message:String(h)}),h}return u.state},async cancel(){const l=n;if(!(!l||l.signal.aborted||s())){if(!e.cancel)throw new Error("This adapter does not support cancellation.");await e.cancel(l),n===l&&c({executionId:l.executionId,status:"cancelled"})}},dispose(){o==null||o.abort(),n=void 0,a()}}}function So({edge:e,enabled:r,bounds:t,inside:n=[],threshold:o=80}){const[i,s]=j.useState(!1),[a,c]=j.useState(!1),l=j.useRef(n);return l.current=n,j.useEffect(()=>{if(!r)return;const d=()=>{const h=document.querySelectorAll(':popover-open, dialog[open], [role="dialog"], [role="menu"], [role="listbox"]');c(Array.from(h).some(p=>p.getClientRects().length>0&&!p.closest('[hidden], [aria-hidden="true"], [data-state="closed"]')&&getComputedStyle(p).visibility==="visible"))},u=new MutationObserver(d);return u.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["open","hidden","aria-hidden","data-state"]}),document.addEventListener("toggle",d,!0),d(),()=>{u.disconnect(),document.removeEventListener("toggle",d,!0)}},[r]),j.useEffect(()=>{const d=h=>{var x;const p=(x=t.current)==null?void 0:x.getBoundingClientRect();if(!p)return;const m=h.target instanceof Node?h.target:null,g=!!m&&l.current.some(v=>{var w;return(w=v.current)==null?void 0:w.contains(m)}),y=e==="bottom"?p.bottom-h.clientY:h.clientY-p.top,b=h.clientX>=p.left&&h.clientX<=p.right&&y>=0&&y<=o;s(g||b)},u=()=>s(!1);return document.addEventListener("pointermove",d,!0),document.addEventListener("pointerdown",d,!0),document.documentElement.addEventListener("pointerleave",u),()=>{document.removeEventListener("pointermove",d,!0),document.removeEventListener("pointerdown",d,!0),document.documentElement.removeEventListener("pointerleave",u)}},[e,t,o]),r&&(i||a)}const ln="#c6c6c6";function fo(e,r=.2){const t=e.replace(/^#/,""),n=parseInt(t,16);let o=n>>16&255,i=n>>8&255,s=n&255;return o=Math.max(0,Math.floor(o*(1-r))),i=Math.max(0,Math.floor(i*(1-r))),s=Math.max(0,Math.floor(s*(1-r))),"#"+((1<<24)+(o<<16)+(i<<8)+s).toString(16).slice(1).toUpperCase()}function Fu(e,r,t){const n=a=>{const c=/^#?([0-9a-f]{6})$/i.exec((a==null?void 0:a.trim())??"");return c?parseInt(c[1],16):null},o=n(e),i=n(r);if(o===null||i===null)return null;const s=a=>Math.round((o>>a&255)*(1-t)+(i>>a&255)*t);return"#"+((1<<24)+(s(16)<<16)+(s(8)<<8)+s(0)).toString(16).slice(1).toUpperCase()}const sr=e=>e==="transparent"?{background:"transparent",highlight:"transparent",border:"transparent",property:"gray.900",boolean:"green.800",string:"gray.900",number:"orange.800"}:e!=null&&e.startsWith("#")?{background:e,highlight:fo(e,.1),border:fo(e,.5),property:"gray.900",boolean:"green.200",string:"gray.900",number:"orange.800"}:e==="gray"?{background:"gray.950",highlight:"gray.800",border:"gray.700",property:"gray.200",boolean:"green.400",string:"gray.200",number:"orange.600"}:e==="white"?{background:"white",highlight:"gray.200",border:"gray.400",property:"gray.900",boolean:"green.400",string:"gray.900",number:"orange.600"}:{background:e+".100",highlight:e+".200",border:e+".700",property:"gray.900",boolean:"green.800",string:"gray.900",number:"orange.800"},hb=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let r=e;if(r!=null&&r.startsWith("#"))return{secondary:fo(e)};let t=String(Number(e.slice(-3))+200);t=e.slice(0,-3).concat(t);let n=String(Number(e.slice(-3))-100);return n=e.slice(0,-3).concat(n),{primary:r,secondary:t,light:n}},zu={red:{50:"#FFF5F5",100:"#FED7D7",200:"#FEB2B2",300:"#FC8181",400:"#F56565",500:"#E53E3E",600:"#C53030",700:"#9B2C2C",800:"#822727",900:"#63171B"},orange:{50:"#FFFAF0",100:"#FEEBC8",200:"#FBD38D",300:"#F6AD55",400:"#ED8936",500:"#DD6B20",600:"#C05621",700:"#9C4221",800:"#7B341E",900:"#652B19"},yellow:{50:"#FFFFF0",100:"#FEFCBF",200:"#FAF089",300:"#F6E05E",400:"#ECC94B",500:"#D69E2E",600:"#B7791F",700:"#975A16",800:"#744210",900:"#5F370E"},green:{50:"#F0FFF4",100:"#C6F6D5",200:"#9AE6B4",300:"#68D391",400:"#48BB78",500:"#38A169",600:"#2F855A",700:"#276749",800:"#22543D",900:"#1C4532"},teal:{50:"#E6FFFA",100:"#B2F5EA",200:"#81E6D9",300:"#4FD1C5",400:"#38B2AC",500:"#319795",600:"#2C7A7B",700:"#285E61",800:"#234E52",900:"#1D4044"},blue:{50:"#EBF8FF",100:"#BEE3F8",200:"#90CDF4",300:"#63B3ED",400:"#4299E1",500:"#3182CE",600:"#2B6CB0",700:"#2C5282",800:"#2A4365",900:"#1A365D"},cyan:{50:"#EDFDFD",100:"#C4F1F9",200:"#9DECF9",300:"#76E4F7",400:"#0BC5EA",500:"#00B5D8",600:"#00A3C4",700:"#0987A0",800:"#086F83",900:"#065666"},purple:{50:"#FAF5FF",100:"#E9D8FD",200:"#D6BCFA",300:"#B794F4",400:"#9F7AEA",500:"#805AD5",600:"#6B46C1",700:"#553C9A",800:"#44337A",900:"#322659"},pink:{50:"#FFF5F7",100:"#FED7E2",200:"#FBB6CE",300:"#F687B3",400:"#ED64A6",500:"#D53F8C",600:"#B83280",700:"#97266D",800:"#702459",900:"#521B41"},gray:{50:"#F7FAFC",100:"#EDF2F7",200:"#E2E8F0",300:"#CBD5E0",400:"#A0AEC0",500:"#718096",600:"#4A5568",700:"#2D3748",800:"#1A202C",900:"#171923",950:"#0d1117"}},Me=(e,r)=>{var i;if(e==="transparent"||e!=null&&e.startsWith("#")||e!=null&&e.startsWith("var(--"))return e;if(!e)return"whitesmoke";const t=e.replace(/\./g,"-");try{const a=getComputedStyle(document.documentElement).getPropertyValue(`--chakra-colors-${t}`).trim();if(a&&a!=="")return a}catch{}const[n,o]=e.split(".");return n&&o&&((i=zu[n])!=null&&i[Number(o)])?zu[n][Number(o)]:`var(--chakra-colors-${t})`},Rw=Im.keyframes`
1
+ "use strict";var jv=Object.create;var Xo=Object.defineProperty;var Ev=Object.getOwnPropertyDescriptor;var _v=Object.getOwnPropertyNames;var kv=Object.getPrototypeOf,Pv=Object.prototype.hasOwnProperty;var Av=(e,r,t)=>r in e?Xo(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var Rv=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of _v(r))!Pv.call(e,o)&&o!==t&&Xo(e,o,{get:()=>r[o],enumerable:!(n=Ev(r,o))||n.enumerable});return e};var dt=(e,r,t)=>(t=e!=null?jv(kv(e)):{},Rv(r||!e||!e.__esModule?Xo(t,"default",{value:e,enumerable:!0}):t,e));var zt=(e,r,t)=>Av(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react"),f=require("react/jsx-runtime"),V=require("@chakra-ui/react"),Wr=require("react-dom"),ee=require("react-icons/pi"),Nm=require("@emotion/react"),Mv=require("@emotion/styled"),Tv=require("react-icons/tb"),Iv=require("markdown-to-jsx/react"),Om=e=>e&&e.__esModule?e:{default:e},xo=Om(Mv),Nv=Om(Iv),kt=[];for(let e=0;e<256;++e)kt.push((e+256).toString(16).slice(1));function Ov(e,r=0){return(kt[e[r+0]]+kt[e[r+1]]+kt[e[r+2]]+kt[e[r+3]]+"-"+kt[e[r+4]]+kt[e[r+5]]+"-"+kt[e[r+6]]+kt[e[r+7]]+"-"+kt[e[r+8]]+kt[e[r+9]]+"-"+kt[e[r+10]]+kt[e[r+11]]+kt[e[r+12]]+kt[e[r+13]]+kt[e[r+14]]+kt[e[r+15]]).toLowerCase()}let Yo;const $v=new Uint8Array(16);function qv(){if(!Yo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Yo=crypto.getRandomValues.bind(crypto)}return Yo($v)}const Lv=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Au={randomUUID:Lv};function Td(e,r,t){var o;if(Au.randomUUID&&!e)return Au.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??qv();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ov(n)}var Fv=typeof global=="object"&&global&&global.Object===Object&&global,zv=typeof self=="object"&&self&&self.Object===Object&&self,Bv=Fv||zv||Function("return this")(),rn=Bv.Symbol,$m=Object.prototype,Dv=$m.hasOwnProperty,Wv=$m.toString,wn=rn?rn.toStringTag:void 0;function Vv(e){var r=Dv.call(e,wn),t=e[wn];try{e[wn]=void 0;var n=!0}catch{}var o=Wv.call(e);return n&&(r?e[wn]=t:delete e[wn]),o}var Gv=Object.prototype,Hv=Gv.toString;function Uv(e){return Hv.call(e)}var Kv="[object Null]",Jv="[object Undefined]",Ru=rn?rn.toStringTag:void 0;function Zv(e){return e==null?e===void 0?Jv:Kv:Ru&&Ru in Object(e)?Vv(e):Uv(e)}function Xv(e){return e!=null&&typeof e=="object"}var Yv="[object Symbol]";function Qv(e){return typeof e=="symbol"||Xv(e)&&Zv(e)==Yv}function e0(e,r){for(var t=-1,n=e==null?0:e.length,o=Array(n);++t<n;)o[t]=r(e[t],t,e);return o}var ot=Array.isArray,Mu=rn?rn.prototype:void 0,Tu=Mu?Mu.toString:void 0;function qm(e){if(typeof e=="string")return e;if(ot(e))return e0(e,qm)+"";if(Qv(e))return Tu?Tu.call(e):"";var r=e+"";return r=="0"&&1/e==-1/0?"-0":r}function Id(e){return e==null?"":qm(e)}function t0(e,r,t){var n=-1,o=e.length;r<0&&(r=-r>o?0:o+r),t=t>o?o:t,t<0&&(t+=o),o=r>t?0:t-r>>>0,r>>>=0;for(var i=Array(o);++n<o;)i[n]=e[n+r];return i}function r0(e,r,t){var n=e.length;return t=t===void 0?n:t,!r&&t>=n?e:t0(e,r,t)}var n0="\\ud800-\\udfff",o0="\\u0300-\\u036f",i0="\\ufe20-\\ufe2f",a0="\\u20d0-\\u20ff",s0=o0+i0+a0,c0="\\ufe0e\\ufe0f",l0="\\u200d",d0=RegExp("["+l0+n0+s0+c0+"]");function Lm(e){return d0.test(e)}function u0(e){return e.split("")}var Fm="\\ud800-\\udfff",f0="\\u0300-\\u036f",h0="\\ufe20-\\ufe2f",p0="\\u20d0-\\u20ff",g0=f0+h0+p0,y0="\\ufe0e\\ufe0f",m0="["+Fm+"]",wd="["+g0+"]",Cd="\\ud83c[\\udffb-\\udfff]",b0="(?:"+wd+"|"+Cd+")",zm="[^"+Fm+"]",Bm="(?:\\ud83c[\\udde6-\\uddff]){2}",Dm="[\\ud800-\\udbff][\\udc00-\\udfff]",x0="\\u200d",Wm=b0+"?",Vm="["+y0+"]?",v0="(?:"+x0+"(?:"+[zm,Bm,Dm].join("|")+")"+Vm+Wm+")*",w0=Vm+Wm+v0,C0="(?:"+[zm+wd+"?",wd,Bm,Dm,m0].join("|")+")",S0=RegExp(Cd+"(?="+Cd+")|"+C0+w0,"g");function j0(e){return e.match(S0)||[]}function E0(e){return Lm(e)?j0(e):u0(e)}function _0(e){return function(r){r=Id(r);var t=Lm(r)?E0(r):void 0,n=t?t[0]:r.charAt(0),o=t?r0(t,1).join(""):r.slice(1);return n[e]()+o}}var k0=_0("toUpperCase");function P0(e,r,t,n){for(var o=-1,i=e==null?0:e.length;++o<i;)t=r(t,e[o],o,e);return t}function A0(e){return function(r){return e==null?void 0:e[r]}}var R0={À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"},M0=A0(R0),T0=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,I0="\\u0300-\\u036f",N0="\\ufe20-\\ufe2f",O0="\\u20d0-\\u20ff",$0=I0+N0+O0,q0="["+$0+"]",L0=RegExp(q0,"g");function F0(e){return e=Id(e),e&&e.replace(T0,M0).replace(L0,"")}var z0=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function B0(e){return e.match(z0)||[]}var D0=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function W0(e){return D0.test(e)}var Gm="\\ud800-\\udfff",V0="\\u0300-\\u036f",G0="\\ufe20-\\ufe2f",H0="\\u20d0-\\u20ff",U0=V0+G0+H0,Hm="\\u2700-\\u27bf",Um="a-z\\xdf-\\xf6\\xf8-\\xff",K0="\\xac\\xb1\\xd7\\xf7",J0="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Z0="\\u2000-\\u206f",X0=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Km="A-Z\\xc0-\\xd6\\xd8-\\xde",Y0="\\ufe0e\\ufe0f",Jm=K0+J0+Z0+X0,Zm="['’]",Iu="["+Jm+"]",Q0="["+U0+"]",Xm="\\d+",ew="["+Hm+"]",Ym="["+Um+"]",Qm="[^"+Gm+Jm+Xm+Hm+Um+Km+"]",tw="\\ud83c[\\udffb-\\udfff]",rw="(?:"+Q0+"|"+tw+")",nw="[^"+Gm+"]",eb="(?:\\ud83c[\\udde6-\\uddff]){2}",tb="[\\ud800-\\udbff][\\udc00-\\udfff]",Xr="["+Km+"]",ow="\\u200d",Nu="(?:"+Ym+"|"+Qm+")",iw="(?:"+Xr+"|"+Qm+")",Ou="(?:"+Zm+"(?:d|ll|m|re|s|t|ve))?",$u="(?:"+Zm+"(?:D|LL|M|RE|S|T|VE))?",rb=rw+"?",nb="["+Y0+"]?",aw="(?:"+ow+"(?:"+[nw,eb,tb].join("|")+")"+nb+rb+")*",sw="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",cw="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",lw=nb+rb+aw,dw="(?:"+[ew,eb,tb].join("|")+")"+lw,uw=RegExp([Xr+"?"+Ym+"+"+Ou+"(?="+[Iu,Xr,"$"].join("|")+")",iw+"+"+$u+"(?="+[Iu,Xr+Nu,"$"].join("|")+")",Xr+"?"+Nu+"+"+Ou,Xr+"+"+$u,cw,sw,Xm,dw].join("|"),"g");function fw(e){return e.match(uw)||[]}function hw(e,r,t){return e=Id(e),r=r,r===void 0?W0(e)?fw(e):B0(e):e.match(r)||[]}var pw="['’]",gw=RegExp(pw,"g");function yw(e){return function(r){return P0(hw(F0(r).replace(gw,"")),e,"")}}var Dt=yw(function(e,r,t){return e+(t?" ":"")+k0(r)});const vo={label:"Untitled",description:"",isTask:!1,isLocked:!1},Nd={id:null,type:"text",data:{...vo,viewProps:{width:"max-content !important",maxWidth:700,height:"100%",borderColor:"transparent",borderRadius:25,borderWidth:0,boxShadow:"none",textOverflow:"ellipsis",fontWeight:"bold",textColor:"gray.800",textAlign:"center"}}},qu={id:null,type:"objectView",data:{...vo,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},mw={id:null,type:"arrayView",data:{...vo,viewProps:{width:"max-content !important",maxWidth:700,height:"100%",textAlign:"center",borderRadius:25,fontSize:"5xl",borderWidth:2,textOverflow:"ellipsis",wordBreak:"keep-all",fontWeight:"bold",textColor:"gray.900",placeholder:"Start Typing"}}},Lu={id:null,type:"workflowStep",data:{...vo,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},Ot=e=>typeof e=="object",ob=e=>Array.isArray(e),bw=["order","position","selected","locked","grabbed","grabbable","scratch"],Pr=e=>Object.entries(e).reduce((r,[t,n])=>(!Ot(n)&&!t.startsWith("$")&&(r[t]=n),r),{}),Od=(e,r)=>typeof e=="string"&&e.startsWith("$")?Qo(e,r):Ot(e)&&!ob(e)?Object.entries(e).reduce((t,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete t["..."],t[n]={...Qo(o,r),...e}):typeof o=="string"&&o.startsWith("$")?t[n]=Qo(o,r):t[n]=o,t),{}):e,Ar=e=>Object.entries(e).reduce((r,[t,n])=>(Ot(n)&&t&&n&&!t.startsWith("$")&&(bw.includes(t)&&(t=t+"#"),r[t]=n),r),{}),Fr=(e,r,{label:t,parent:n=void 0},o,i=null)=>(i!==null&&(Ot(i)||ob(i))&&(i=JSON.stringify(i,null,2)),{data:{parent:n,...e.data,id:r,text:t||"",label:t,code:i||null,type:e.type,description:o}}),jr=(e,r,t=null,n=null,o=null,i=!1,s=null)=>({data:{id:Td(),source:o?r:e,target:o?e:r,label:n||"",isInverted:o,isEdgeAnimated:i,parent:s}}),Rr=(e,r=[])=>{const t={},n={};let o=[];if(e)for(const[i,s]of Object.entries(e))i.startsWith("$")&&i!=="$"?t[i.slice(1)]=s:i!=="$"?n[i]=s:i==="$"&&(o=s);return{newConfig:t,updatedObject:n,arrayObject:o}},Yr=(e,r)=>{let t=qu;const{view:n,borderColor:o,borderRadius:i,bgColor:s,textColor:a,fontSize:c,stepType:l}=r;e=n||e,l?t={...Lu}:e==="object"?t=qu:e==="text"?t=Nd:e==="array"?t=mw:e==="workflowStep"&&(t={...Lu});const d=t.data.viewProps;return t.data.viewProps={...d,borderRadius:i||(l?15:53),bgColor:s,borderColor:o,textColor:a,fontSize:c},t.data.config=r,{config:t}},Fn=(e,r)=>(e=r.find(n=>n.data.id===e)?`${e}.#`:e,e),Qo=(e,{ids:r,jsnObjct:t})=>{if(typeof e=="string"&&(e!=null&&e.startsWith("$"))){const n=e.replace("$","").replace("*","");e==null||e.endsWith("*");const o=r.find(a=>a.split(".").slice(-1)[0]===n||n===a);if(!o)return e;const i=xw(o,t);return JSON.stringify(i).includes(e)?e:i||e}return e},xw=(e,r)=>{let t=e.split(".").splice(1);return t=t[t.length-1]==="#"||t[t.length-1].includes("{")?t.slice(0,-2):t,(i=>t.reduce((s,a)=>{a=a.replace("[","").replace("]","");const{arrayObject:c}=Rr(s);return s=c.length?c:s,s[a]},i))(r)};function en(e,r="root",t=[]){try{const{arrayObject:n}=Rr(e);n.length&&(e=n);const o=Pr(e),i=Ar(e);return Ot(e)?(ot(e)||ot(e)&&r==="root"||!ot(e)&&Object.keys(o).length||r==="root")&&t.push(r):t.push(r),Object.keys(i).length&&!ot(e)?Rn({chldPth:null,itrblObjct:i,nodes:t,path:r}):ot(e)&&e.forEach((s,a)=>{const c=Pr(s),l=Ar(s),{newConfig:d,arrayObject:u}=Rr(s);let h=`${r}.${a}`;Ot(s)?Object.keys(c).length?(en(c,h,t),Object.keys(l).length&&!ot(s)&&Rn({chldPth:h,itrblObjct:l,nodes:t,path:r})):Object.keys(l).length&&!ot(s)?Rn({chldPth:h,itrblObjct:l,nodes:t,path:r}):ot(s)&&ib({chldPth:h,item:s,nodes:t,path:r}):t.push(h)}),{nodes:t}}catch{return{nodes:t}}}const Rn=({chldPth:e,itrblObjct:r,nodes:t,path:n})=>Object.entries(r).forEach(([o,i],s)=>{const a=Pr(i),c=Ar(i),{newConfig:l,arrayObject:d}=Rr(i);d.length&&(i=d),n.split(".").slice(0,2).join(".");let u=e?`${e}.${o}`:`${n}.${o}`;if(Ot(i)&&!ot(i)){const h=Object.keys(a).length===0;if(h&&(Yr("array",l),t.push(u)),Object.keys(a).length){const p=ot(i)?`${i.length||""}`:`{${Object.keys(i).length||""}}`;let m=u;h&&(m=`${u}.${p}`),en(i,m,t)}else Object.keys(c).length&&!ot(i)?Rn({chldPth:u,itrblObjct:c,path:u,nodes:t}):en(i,u,t)}else ot(i)&&en(i,u,t)}),ib=({chldPth:e,item:r,nodes:t,path:n})=>r.forEach((o,i)=>{let s=`${e}.${i}`;const a=Ar(o),c=Pr(o);Ot(o)?!ot(o)&&Object.keys(c).length?en(o,s,t):Object.keys(a).length&&!ot(o)?Rn({chldPth:s,itrblObjct:a,path:n,nodes:t}):ot(o)&&ib({chldPth:s,item:o,nodes:t,path:n}):t.push(s)}),Mn=[];let Tn;function Dr(e,r="root",t=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},s={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:t,edges:n};const a=e;if(r==="root"&&(Mn.length=0),!Tn){const{nodes:d}=en(e);Tn={ids:d,jsnObjct:e}}let{hideDefaultObject:c,sprtObjctKy:l}=i;try{r=Fn(r,t);const{newConfig:d,arrayObject:u}=Rr(e),h=Object.keys(s).length>0?s:d;u.length&&(e=u);const p=Pr(e),m=Ar(e),{label:g,collapsed:y,parent:b}=h;if(!Ot(e))t.push(Fr(Nd,r,{label:g||r,parent:b},e,a));else if(ot(e)||ot(e)&&r==="root"){const{config:x}=Yr("array",h),w=ot(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,v=r==="root"?o:`${o} ${w}`;t.push(Fr(x,r,{label:g||v,parent:b},e,ot(a)?{[o]:a}:a))}else if(!ot(e)&&Object.keys(p).length||r==="root"){const{config:x}=Yr(null,h),w=ot(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,v=r.split("."),C=v[v.length-1];let S=isNaN(Number(C))?null:Number(C)+1;const E=isNaN(Number(C))?C:v[v.length-2]+" "+S,R=r==="root"?o:E;let P=!1;Number.isNaN(Number(o))||(P=!0);const I=e;if(g){const{config:M}=Yr("object",h);t.push(Fr(M,r,{label:g||`${g} ${w}`,parent:b},p,I))}else x.data.headerTitle=R,t.push(Fr(x,r,{label:g,parent:b},p,I))}return y||(Object.keys(m).length&&!ot(e)?In({flowConfig:i,chldPth:null,edges:n,isInverted:null,itrblObjct:m,nodes:t,path:r,newConfig:h}):ot(e)&&e.forEach((x,w)=>{x=Od(x,Tn);const v=x,C=Pr(x),S=Ar(x),{newConfig:E,arrayObject:R}=Rr(x);R.length&&(x=R);const{config:P}=Yr(typeof x=="string"?"text":"array",E),{hideConfig:I,sourceLabel:M,label:k,isEdgeAnimated:_,parent:N}=E;c=c||I;const $=r==="root"&&i.isCntr,D=r.split(".").slice(0,2).join("."),T=Mn.includes(D),Z=i.isCntr&&T||w%2===0&&$;let K=`${r}.${w}`;K=Fn(K,t),Z&&Mn.push(K),Ot(x)?Object.keys(C).length&&!ot(x)?(n.push(jr(r,K,null,M,Z,_)),Dr(x,K,t,n,k||w,i,E)):Object.keys(S).length&&!ot(x)?In({flowConfig:i,chldPth:K,isInverted:Z,edges:n,itrblObjct:S,nodes:t,path:r,newConfig:E,forceIsInverted:!0}):ot(x)?ab({flowConfig:i,chldPth:K,edges:n,isInverted:Z,item:x,nodes:t,path:r}):Ot(x)&&In({flowConfig:i,chldPth:K,isInverted:Z,edges:n,itrblObjct:[x],nodes:t,path:r,newConfig:E}):(n.push(jr(r,K,null,M,Z,_)),t.push(Fr(P,K,{label:k||String(x),parent:N},x,v)))})),{nodes:t,edges:n}}catch{return{nodes:t,edges:n}}}const In=({chldPth:e,flowConfig:r,edges:t,itrblObjct:n,nodes:o,isInverted:i,path:s,newConfig:a,forceIsInverted:c=!1})=>{let{hideDefaultObject:l,sprtObjctKy:d}=r;return Object.entries(n).forEach(([u,h],p)=>{h=Od(h,Tn);const m=h,g=Pr(h),y=Ar(h),{newConfig:b,arrayObject:x}=Rr(h);x.length&&(h=x);const{hideConfig:w,sourceLabel:v,label:C,content:S,target:E,targetLabel:R,collapsed:P,isEdgeAnimated:I,parent:M}=b;l=l||w;const k=s==="root"&&r.isCntr,_=s.split(".").slice(0,2).join("."),N=Mn.includes(_);c||(i=r.isCntr&&N||p%2===0&&k);let $=e?`${e}.${u}`:`${s}.${u}`;if($=Fn($,o),i&&Mn.push($),E&&t.push(jr($,E,null,R,i,I)),Ot(h)&&!ot(h)){t.push(jr(s,$,null,v,i,I));const D=d||Object.keys(g).length===0;if(D){const T=S?"object":"array",{config:Z}=Yr(T,b);Z.data.headerTitle=S?C:null,o.push(Fr(Z,$,{label:C||u,parent:M},h,m))}if(Object.keys(g).length&&!l){const T=ot(h)?` ${h.length||""}`:`{${Object.keys(h).length||""}}`;let Z=$;D&&(Z=`${$}.${T}`,Z=Fn(Z,o),t.push(jr($,Z,null,v,i,I))),Dr(h,Z,o,t,C||u,r,b)}else Object.keys(y).length&&!ot(h)?In({chldPth:$,flowConfig:r,itrblObjct:y,path:$,edges:t,nodes:o,newConfig:b,isInverted:i}):Dr(h,$,o,t,u,r,b)}else ot(h)&&(t.push(jr(s,$,null,v,i,I)),Dr(h,$,o,t,u,r,b))})},ab=({flowConfig:e,chldPth:r,edges:t,isInverted:n,item:o,nodes:i,path:s})=>o.forEach((a,c)=>{let l=`${r}.${c}`;l=Fn(l,i);const d=a;a=Od(a,Tn);const u=Ar(a),h=Pr(a),{newConfig:p}=Rr(a),{collapsed:m,label:g,parent:y,sourceLabel:b,isEdgeAnimated:x,content:w}=p;Ot(a)?!ot(a)&&Object.keys(h).length?(t.push(jr(s,l,null,b,n,x)),Dr(a,l,i,t,c,e,p)):Object.keys(u).length&&!ot(a)&&!m?In({chldPth:l,flowConfig:e,itrblObjct:u,path:s,edges:t,nodes:i,isInverted:n,newConfig:p}):ot(a)&&ab({flowConfig:e,chldPth:l,edges:t,isInverted:n,item:a,nodes:i,path:s}):(t.push(jr(s,l,null,b,n,x)),i.push(Fr(Nd,l,{label:g||String(a),parent:y},a,d)))});function vw(e,r){const t=new Set,n=(l,d="root")=>{if(!(!l||typeof l!="object")){l.$view==="parent"&&t.add(d),typeof l.$parent=="string"&&t.add(l.$parent);for(const[u,h]of Object.entries(l))(!u.startsWith("$")||u==="$")&&n(h,u==="$"?d:`${d}.${u}`)}};if(n(e),!t.size)return r;const o=new Map(r.nodes.map(l=>[l.data.id,l])),i=l=>{var p,m;let d=l.data.id;const u=new Set([l.data.id]);let h=l.data.parent;for(;h&&!u.has(h);)t.has(h)&&o.has(h)&&((p=Oe(e,h))!=null&&p.$collapsed)&&(d=h),u.add(h),h=(m=o.get(h))==null?void 0:m.data.parent;return d},s=new Map(r.nodes.map(l=>[l.data.id,i(l)])),a=r.nodes.filter(l=>s.get(l.data.id)===l.data.id).map(l=>{if(!t.has(l.data.id))return l;const d=Oe(e,l.data.id),u=!!(d!=null&&d.$collapsed);return{...l,data:{...l.data,...u?{type:"arrayView"}:{},config:{...l.data.config,parentContainer:!0,collapsed:u,...u?{labelBelow:!0,icon:(d==null?void 0:d.$icon)||"PiStack"}:{}}}}}),c=new Set(a.map(l=>l.data.id));return{nodes:a,edges:r.edges.flatMap(l=>{const d=s.get(l.data.source),u=s.get(l.data.target);return!d||!u||!c.has(d)||!c.has(u)?[]:d===l.data.source&&u===l.data.target?[l]:d===u?[]:[{...l,data:{...l.data,source:d,target:u,collapsedEndpoints:l.data.collapsedEndpoints??{source:l.data.source,target:l.data.target}}}]})}}function wo(e){if(!Array.isArray(e==null?void 0:e.$connections))return[];const r=new Map;return e.$connections.flatMap((t,n)=>{if(!t||typeof t!="object")return[];const o=t;if(typeof o.target!="string"||!/^root(?:\.|$)/.test(o.target))return[];if(o.sourceProperty!==void 0&&typeof o.sourceProperty!="string")return[];if(o.targetProperty!==void 0&&typeof o.targetProperty!="string")return[];const i=typeof o.id=="string"&&o.id?JSON.stringify(["id",o.id]):JSON.stringify(["ports",o.target,o.sourceProperty??null,o.targetProperty??null]),s=r.get(i)??0;return r.set(i,s+1),[{value:o,key:`${i}#${s}`,index:n}]})}function sb(e,r,t){const n=wo(e).find(c=>c.key===r);if(!n)return e;const o=t(n.value),i=e.$connections.flatMap((c,l)=>l===n.index?o?[o]:[]:[c]);if(i.length)return{...e,$connections:i};const{$connections:s,...a}=e;return a}function ww(e){const r=[],t=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,s)=>t(i,`${o}.${s}`));for(const i of wo(n)){const s=i.value;r.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:s.target,type:typeof s.type=="string"?s.type:void 0,sourceProperty:s.sourceProperty,targetProperty:s.targetProperty,icon:typeof s.icon=="string"?s.icon:void 0,label:typeof s.label=="string"?s.label:void 0,color:typeof s.color=="string"?s.color:void 0,isEdgeDashed:s.style==="dashed",isEdgeAnimated:s.style==="animated",...["dashed","traveling"].includes(s.animationVariant)?{edgeAnimationVariant:s.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,s])=>[i,i==="$"?t(s,o):i.startsWith("$")?s:t(s,`${o}.${i}`)]))};return{json:t(e,"root"),edges:r}}const tn="root";function cb(e,r,t){return!t||Oe(e,r)===void 0||!t.userId||!t.name.trim()||!Number.isFinite(Date.parse(t.at))?e:jt(e,r,"$edited",t)}const Fu=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Kt(e){const r=e.split(".");for(r[0]===tn&&r.shift();r.length&&Fu(r[r.length-1]);)r.pop();return r.filter(t=>!Fu(t))}function Co(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function Oe(e,r){return Kt(r).reduce((t,n)=>{var o;if(t!=null)return(o=Co(t))==null?void 0:o[n]},e)}function Cw(e){return Array.isArray(e)?[...e]:{...e}}function Pt(e,r,t){const n=Kt(r),o=(i,s)=>{if(s===n.length)return t(i);const a=n[s],c=Co(i);if(c==null||typeof c!="object")return i;const l=o(c[a],s+1);if(Object.is(l,c[a]))return i;const d=Cw(c);return d[a]=l,c!==i?{...i,$:d}:d};return o(e,0)}function pr(e,r,t){const n=t===""&&r!=="$content"||t===void 0||t===null;if(Array.isArray(e))return n?e:{[r]:t,$:[...e]};const o=e!=null&&typeof e=="object"?{...e}:{};return e!=null&&typeof e!="object"&&(o.$label=String(e)),n?delete o[r]:o[r]=t,o}function jt(e,r,t,n){return Pt(e,r,o=>t==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:pr(o,t,n))}const uo=(e,r,t)=>jt(e,r,"$collapsed",t);function zr(e){if(e.connection)return{address:e.connection.address,kind:"connection"};const r=e.collapsedEndpoints??e,t=e.isInverted?r.target:r.source,n=e.isInverted?r.source:r.target,o=Kt(t).join("."),i=Kt(n).join(".");return i.startsWith(o?o+".":"")&&i!==o?{address:n,kind:"hierarchy"}:o.startsWith(i?i+".":"")&&o!==i?{address:t,kind:"hierarchy"}:{address:t,kind:"target"}}function Sr(e,r,t,n){if(r.connection){const a=r.connection;return Pt(e,a.address,c=>sb(c,a.key,l=>{if(t==="$edgeIcon")return pr(l,"icon",n);if(t==="$edgeType")return pr(l,"type",n);if(t==="$edgeAnimationVariant")return pr(l,"animationVariant",n);if(t==="$sourceLabel"||t==="$edgeColor")return pr(l,t==="$sourceLabel"?"label":"color",n);const d=t==="$isEdgeAnimated"?"animated":"dashed";return n?{...l,style:d}:l.style===d?pr(l,"style",void 0):l}))}const{address:o,kind:i}=zr(r),s=i==="target"&&t==="$sourceLabel"?"$targetLabel":i==="target"&&t==="$edgeType"?"$targetEdgeType":i==="target"&&t==="$edgeIcon"?"$targetIcon":i==="target"&&t==="$edgeAnimationVariant"?"$targetAnimationVariant":t;return Pt(e,o,a=>pr(a,s,n))}const lb=(e,r,t)=>Sr(Sr(e,r,"$isEdgeAnimated",t==="animated"||void 0),r,"$isEdgeDashed",t==="dashed"||void 0);function $d(e,r,t,n){let o=n||"";const i=Pt(e,r,a=>{const c=Co(a);if(Array.isArray(c)){o=String(c.length);const d=[...c,t];return c===a?d:{...a,$:d}}const l=a!=null&&typeof a=="object"&&!Array.isArray(a)?{...a}:a!=null&&typeof a!="object"?{$label:String(a)}:{};if(!o){let d=1;for(;`node_${d}`in l;)d++;o=`node_${d}`}return l[o]=t,l}),s=Kt(r);return{json:i,address:[tn,...s,o].join(".")}}function db(e,r){const t=Kt(r);if(!t.length)return e;const n=t[t.length-1],o=[tn,...t.slice(0,-1)].join(".");return Pt(e,o,i=>{const s=Co(i);if(s==null||typeof s!="object"||!Object.prototype.hasOwnProperty.call(s,n))return i;if(Array.isArray(s)){const l=s.filter((d,u)=>String(u)!==n);return s===i?l:{...i,$:l}}const{[n]:a,...c}=i;return c})}const ub=(e,r,t,n)=>jt(n?Pt(e,r,o=>pr(o,"$targetLabel",n)):e,r,"$target",t);function qd(e,r,t){const n=Oe(e,r);return wo(n).some(({value:i})=>i.target===t.target&&i.sourceProperty===t.sourceProperty&&i.targetProperty===t.targetProperty)?e:Pt(e,r,i=>pr(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...t,id:t.id||Td()}]))}function fb(e,r){if(r.connection){const i=r.connection;return wo(Oe(e,i.address)).some(s=>s.key===i.key)?{json:Pt(e,i.address,s=>sb(s,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:t,kind:n}=zr(r);return n==="hierarchy"?Oe(e,t)===void 0?{json:e,removed:!1}:{json:Pt(e,t,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:Pt(e,t,i=>{const{$target:s,$targetLabel:a,...c}=i||{};return c}),removed:!0}}function Sd(e,r={}){var x;const t=ww(e),{nodes:n,edges:o}=Dr(t.json,tn,[],[],r.title||"untitled",{hideDefaultObject:!!r.hideDefaultObject,sprtObjctKy:!!r.separateObjectKeys,isCntr:!!r.isCenter}),i=new Set(n.map(w=>w.data.id)),s=new Map;for(const w of n){const v=w.data.id;if(!v.endsWith(".0")||Oe(e,v)!==void 0)continue;const C=v.slice(0,-2),S=Oe(e,C);!i.has(C)&&S&&typeof S=="object"&&!Array.isArray(S)&&typeof S.$label=="string"&&Object.keys(S).every(E=>E.startsWith("$")&&E!=="$")&&s.set(v,C)}const a=w=>s.get(w)??w,c=new Set(n.flatMap(w=>w.data.parent?[a(w.data.parent)]:[])),l=new Map;if(r.isCenter){const w=new Map;for(const{data:v}of o){const C=zr(v);if(C.kind==="hierarchy")l.set(a(C.address),!!v.isInverted);else if(!Array.isArray(e)&&e.$hideRoot===!0){const S=a(v.isInverted?v.source:v.target);if(Kt(S).length!==1)continue;const E=!!v.isInverted;w.set(S,w.has(S)&&w.get(S)!==E?null:E)}}for(const[v]of l){const C=`${tn}.${Kt(v)[0]}`,S=w.get(C);typeof S=="boolean"&&l.set(v,S)}}const d=n.map(w=>{var P;const v=a(w.data.id),C=Oe(e,v),S={...w.data,id:v};l.has(v)&&(S.config={...S.config,isInverted:l.get(v)});const E=C&&typeof C=="object"&&!Array.isArray(C)&&"$"in C?C.$:C;if((Array.isArray(E)?E.length>0:E&&typeof E=="object"&&Object.keys(E).some(I=>!I.startsWith("$")))&&(S.config={...S.config,collapsed:!!C.$collapsed}),c.has(v)||(S.viewProps={...S.viewProps},delete S.viewProps.borderWidth),!C||typeof C!="object"||Array.isArray(C))return{data:S};if(C.$view==="parent"&&(S.type="objectView",S.config={...S.config,typeView:"parent",parentContainer:!0,collapsed:!!C.$collapsed}),C.$view==="grid"){S.type="grid";const I=C.$gridSize;if(I!==void 0&&(!I||![I.width,I.height].every(M=>Number.isFinite(M)&&M>0&&M<=16384)))throw new Error("Invalid grid frame size.");S.config={...S.config,typeView:"grid",documentId:C.$document,gridSize:I},S.viewProps={...S.viewProps,bgColor:C.$bgColor??"transparent",borderRadius:C.$borderRadius??0,borderWidth:C.$borderWidth??0}}if(C.$form&&typeof C.$form=="object"&&(S.config={...S.config,form:C.$form},S.type="objectView"),C.$view==="prompt"&&(S.type="prompt",S.config={...S.config,typeView:"prompt"}),Array.isArray(C.$ports)){const I=C.$ports.filter(M=>M&&typeof M.id=="string"&&["source","target"].includes(M.role)&&["top","right","bottom","left"].includes(M.side));S.config={...S.config,ports:I}}if(S.parent&&(S.parent=a(S.parent)),typeof C.$label=="string"&&(S.label=C.$label,S.headerTitle=C.$label),typeof C.$subtitle=="string"&&(S.config={...S.config,subtitle:C.$subtitle}),C.$edited&&typeof C.$edited=="object"&&(S.config={...S.config,edited:C.$edited},S.description&&(S.description={...S.description},delete S.description.$edited)),C.$promptTurn&&typeof C.$promptTurn=="object"&&(S.config={...S.config,promptTurn:C.$promptTurn}),typeof C.$outline=="boolean"&&(S.viewProps={...S.viewProps,outline:C.$outline}),["solid","dashed","dotted","double"].includes(C.$borderStyle)&&(S.viewProps={...S.viewProps,borderStyle:C.$borderStyle}),Number.isFinite(C.$borderWidth)&&C.$borderWidth>=0&&(S.viewProps={...S.viewProps,borderWidth:C.$borderWidth}),Number.isFinite(C.$borderRadius)&&C.$borderRadius>=0&&(S.viewProps={...S.viewProps,borderRadius:C.$borderRadius}),typeof C.$isNodeAnimated=="boolean"&&(S.isNodeAnimated=C.$isNodeAnimated),["traveling","pulse"].includes(C.$nodeAnimationVariant)&&(S.nodeAnimationVariant=C.$nodeAnimationVariant),typeof C.$content=="string"||C.$contentFormat==="jsx"&&Array.isArray(C.$content)){S.config={...S.config,content:C.$content};const I=C.$contentFormat??"markdown";if(!["markdown","html","jsx"].includes(I))throw new Error("Invalid content format: expected markdown, html, or jsx.");S.config.contentFormat=I,C.$view||(S.type="objectView")}return(((P=S.config)==null?void 0:P.collapsed)!==void 0||C.$collapsed!==void 0||C.$icon!==void 0)&&(S.config={...S.config||{}},(C.$collapsed!==void 0||S.config.collapsed!==void 0)&&(S.config.collapsed=!!C.$collapsed),C.$icon!==void 0&&(S.config.icon=C.$icon)),{data:S}}),u=new Map,h=o.map(w=>{let v=a(w.data.source),C=a(w.data.target),S=w.data.isInverted;const E=zr(w.data),R=l.get(a(E.address));E.kind==="hierarchy"&&R!==void 0&&R!==!!S&&([v,C]=[C,v],S=R);const P=`${v}->${C}`,I=u.get(P)??0;u.set(P,I+1);const M={...w.data,id:I?`${P}#${I}`:P,source:v,target:C,isInverted:S},k=zr(M),_=Oe(e,k.address);if(_&&typeof _=="object"){const N=_[k.kind==="target"?"$targetEdgeType":"$edgeType"];typeof N=="string"&&(M.type=N);const $=_[k.kind==="target"?"$targetIcon":"$edgeIcon"];typeof $=="string"&&(M.icon=$),_.$isEdgeAnimated!==void 0&&(M.isEdgeAnimated=!!_.$isEdgeAnimated);const D=_[k.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(D)&&(M.edgeAnimationVariant=D),_.$isEdgeDashed!==void 0&&(M.isEdgeDashed=!!_.$isEdgeDashed),_.$edgeColor&&(M.color=_.$edgeColor)}return{data:M}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const w=d.findIndex(v=>v.data.id===tn);w!==-1&&d.splice(w,1)}const p=new Set(d.map(w=>w.data.id));for(let w=h.length-1;w>=0;w--){const v=h[w].data,C=zr(v);(!p.has(v.source)||!p.has(v.target)||C.kind==="hierarchy"&&((x=Oe(e,C.address))==null?void 0:x.$hideParentEdge)===!0)&&h.splice(w,1)}h.push(...t.edges.filter(w=>p.has(w.data.source)&&p.has(w.data.target)));const m=vw(e,{nodes:d,edges:h}),g=m.nodes.filter(w=>{var v;return(v=w.data.config)==null?void 0:v.collapsed}).map(w=>Kt(w.data.id));if(!g.length)return m;const y=m.nodes.filter(w=>{const v=Kt(w.data.id);return!g.some(C=>C.length<v.length&&C.every((S,E)=>S===v[E]))}),b=new Set(y.map(w=>w.data.id));return{nodes:y,edges:m.edges.filter(w=>b.has(w.data.source)&&b.has(w.data.target))}}function Sw(e,r){const t=new Set(e.filter(c=>{var l,d;return(d=(l=c.data)==null?void 0:l.config)==null?void 0:d.collapsed}).map(c=>c.data.id));if(!t.size)return{nodes:e,edges:r};const n=new Map(e.map(c=>[c.data.id,c])),o=new Set(e.map(c=>c.data.parent).filter(Boolean)),i=new Map(e.map(c=>{var h;let l=c.data.id,d=c.data.parent;const u=new Set([l]);for(;d&&!u.has(d);)t.has(d)&&(l=d),u.add(d),d=(h=n.get(d))==null?void 0:h.data.parent;return[c.data.id,l]})),s=new Map;for(const c of r){const l=c.data.isInverted?c.data.target:c.data.source,d=c.data.isInverted?c.data.source:c.data.target;(s.get(l)??s.set(l,[]).get(l)).push(d)}const a=new Set(e.filter(c=>i.get(c.data.id)!==c.data.id).map(c=>c.data.id));for(const c of t){if(o.has(c))continue;const l=[...s.get(c)||[]];for(;l.length;){const d=l.pop();t.has(d)||a.has(d)||(a.add(d),l.push(...s.get(d)||[]))}}return{nodes:e.filter(c=>!a.has(c.data.id)).map(c=>{var l;return t.has(c.data.id)&&o.has(c.data.id)?{...c,data:{...c.data,type:"arrayView",label:c.data.label??c.data.headerTitle,config:{...c.data.config,parentContainer:!0,labelBelow:!0,icon:((l=c.data.config)==null?void 0:l.icon)||"PiStack"}}}:c}),edges:r.flatMap(c=>{const l=i.get(c.data.source)??c.data.source,d=i.get(c.data.target)??c.data.target;return a.has(l)||a.has(d)?[]:l===c.data.source&&d===c.data.target?[c]:l===d?[]:[{...c,data:{...c.data,source:l,target:d,collapsedEndpoints:c.data.collapsedEndpoints??{source:c.data.source,target:c.data.target}}}]})}}const jw=new Intl.RelativeTimeFormat("en",{numeric:"always"});function hb(e,r=Date.now()){if(!e)return;const t=Date.parse(e);if(!Number.isFinite(t))return;const n=Math.max(0,Math.floor((r-t)/1e3));if(n<60)return"just now";const o=[[31536e3,"year"],[2592e3,"month"],[86400,"day"],[3600,"hour"],[60,"minute"]],[i,s]=o.find(([a])=>n>=a);return jw.format(-Math.floor(n/i),s)}let jd=Date.now(),to;const ro=new Set,Ew=e=>(ro.add(e),to||(jd=Date.now(),to=setInterval(()=>{jd=Date.now(),ro.forEach(r=>r())},6e4)),()=>{ro.delete(e),ro.size||(clearInterval(to),to=void 0)}),_w=()=>jd,kw=()=>0;function Pw(e){const r=j.useSyncExternalStore(Ew,_w,kw);return hb(e,r||Date.now())}function Aw(e,r){let t,n,o,i;const s=(l=t)=>!!l&&["completed","failed","cancelled"].includes(l.status),a=()=>{const l=i;i=void 0,l==null||l()},c=l=>{if(!n||n.signal.aborted||!t||l.executionId!==t.executionId||s())return;const{step:d,...u}=l;t={...t,...u,steps:d?{...t.steps,[d.id]:{...t.steps[d.id],...d}}:t.steps},n.state=t,s()&&a(),r(t)};return{getState:()=>t,async run(l,d=crypto.randomUUID()){if(n&&!n.signal.aborted&&!s())throw new Error("An execution is already active.");o==null||o.abort(),a(),o=new AbortController;const u={executionId:d,input:l,signal:o.signal,state:{executionId:d,status:"subscribing",steps:{}}};n=u,t=u.state,r(t);try{const h=await e.subscribe(u,m=>{n===u&&c(m)});if(n!==u||u.signal.aborted||s())return h(),u.state;if(i=h,c({executionId:d,status:"running"}),n!==u||u.signal.aborted||s(u.state))return u.state;const p=await e.execute(u);n===u&&p&&c(p)}catch(h){if(s(u.state))return u.state;throw n===u&&!u.signal.aborted&&c({executionId:d,status:"failed",error:h instanceof Error?h.message:String(h)}),h}return u.state},async cancel(){const l=n;if(!(!l||l.signal.aborted||s())){if(!e.cancel)throw new Error("This adapter does not support cancellation.");await e.cancel(l),n===l&&c({executionId:l.executionId,status:"cancelled"})}},dispose(){o==null||o.abort(),n=void 0,a()}}}function So({edge:e,enabled:r,bounds:t,inside:n=[],threshold:o=80}){const[i,s]=j.useState(!1),[a,c]=j.useState(!1),l=j.useRef(n);return l.current=n,j.useEffect(()=>{if(!r)return;const d=()=>{const h=document.querySelectorAll(':popover-open, dialog[open], [role="dialog"], [role="menu"], [role="listbox"]');c(Array.from(h).some(p=>p.getClientRects().length>0&&!p.closest('[hidden], [aria-hidden="true"], [data-state="closed"]')&&getComputedStyle(p).visibility==="visible"))},u=new MutationObserver(d);return u.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["open","hidden","aria-hidden","data-state"]}),document.addEventListener("toggle",d,!0),d(),()=>{u.disconnect(),document.removeEventListener("toggle",d,!0)}},[r]),j.useEffect(()=>{const d=h=>{var x;const p=(x=t.current)==null?void 0:x.getBoundingClientRect();if(!p)return;const m=h.target instanceof Node?h.target:null,g=!!m&&l.current.some(w=>{var v;return(v=w.current)==null?void 0:v.contains(m)}),y=e==="bottom"?p.bottom-h.clientY:h.clientY-p.top,b=h.clientX>=p.left&&h.clientX<=p.right&&y>=0&&y<=o;s(g||b)},u=()=>s(!1);return document.addEventListener("pointermove",d,!0),document.addEventListener("pointerdown",d,!0),document.documentElement.addEventListener("pointerleave",u),()=>{document.removeEventListener("pointermove",d,!0),document.removeEventListener("pointerdown",d,!0),document.documentElement.removeEventListener("pointerleave",u)}},[e,t,o]),r&&(i||a)}const ln="#c6c6c6";function fo(e,r=.2){const t=e.replace(/^#/,""),n=parseInt(t,16);let o=n>>16&255,i=n>>8&255,s=n&255;return o=Math.max(0,Math.floor(o*(1-r))),i=Math.max(0,Math.floor(i*(1-r))),s=Math.max(0,Math.floor(s*(1-r))),"#"+((1<<24)+(o<<16)+(i<<8)+s).toString(16).slice(1).toUpperCase()}function zu(e,r,t){const n=a=>{const c=/^#?([0-9a-f]{6})$/i.exec((a==null?void 0:a.trim())??"");return c?parseInt(c[1],16):null},o=n(e),i=n(r);if(o===null||i===null)return null;const s=a=>Math.round((o>>a&255)*(1-t)+(i>>a&255)*t);return"#"+((1<<24)+(s(16)<<16)+(s(8)<<8)+s(0)).toString(16).slice(1).toUpperCase()}const sr=e=>e==="transparent"?{background:"transparent",highlight:"transparent",border:"transparent",property:"gray.900",boolean:"green.800",string:"gray.900",number:"orange.800"}:e!=null&&e.startsWith("#")?{background:e,highlight:fo(e,.1),border:fo(e,.5),property:"gray.900",boolean:"green.200",string:"gray.900",number:"orange.800"}:e==="gray"?{background:"gray.950",highlight:"gray.800",border:"gray.700",property:"gray.200",boolean:"green.400",string:"gray.200",number:"orange.600"}:e==="white"?{background:"white",highlight:"gray.200",border:"gray.400",property:"gray.900",boolean:"green.400",string:"gray.900",number:"orange.600"}:{background:e+".100",highlight:e+".200",border:e+".700",property:"gray.900",boolean:"green.800",string:"gray.900",number:"orange.800"},pb=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let r=e;if(r!=null&&r.startsWith("#"))return{secondary:fo(e)};let t=String(Number(e.slice(-3))+200);t=e.slice(0,-3).concat(t);let n=String(Number(e.slice(-3))-100);return n=e.slice(0,-3).concat(n),{primary:r,secondary:t,light:n}},Bu={red:{50:"#FFF5F5",100:"#FED7D7",200:"#FEB2B2",300:"#FC8181",400:"#F56565",500:"#E53E3E",600:"#C53030",700:"#9B2C2C",800:"#822727",900:"#63171B"},orange:{50:"#FFFAF0",100:"#FEEBC8",200:"#FBD38D",300:"#F6AD55",400:"#ED8936",500:"#DD6B20",600:"#C05621",700:"#9C4221",800:"#7B341E",900:"#652B19"},yellow:{50:"#FFFFF0",100:"#FEFCBF",200:"#FAF089",300:"#F6E05E",400:"#ECC94B",500:"#D69E2E",600:"#B7791F",700:"#975A16",800:"#744210",900:"#5F370E"},green:{50:"#F0FFF4",100:"#C6F6D5",200:"#9AE6B4",300:"#68D391",400:"#48BB78",500:"#38A169",600:"#2F855A",700:"#276749",800:"#22543D",900:"#1C4532"},teal:{50:"#E6FFFA",100:"#B2F5EA",200:"#81E6D9",300:"#4FD1C5",400:"#38B2AC",500:"#319795",600:"#2C7A7B",700:"#285E61",800:"#234E52",900:"#1D4044"},blue:{50:"#EBF8FF",100:"#BEE3F8",200:"#90CDF4",300:"#63B3ED",400:"#4299E1",500:"#3182CE",600:"#2B6CB0",700:"#2C5282",800:"#2A4365",900:"#1A365D"},cyan:{50:"#EDFDFD",100:"#C4F1F9",200:"#9DECF9",300:"#76E4F7",400:"#0BC5EA",500:"#00B5D8",600:"#00A3C4",700:"#0987A0",800:"#086F83",900:"#065666"},purple:{50:"#FAF5FF",100:"#E9D8FD",200:"#D6BCFA",300:"#B794F4",400:"#9F7AEA",500:"#805AD5",600:"#6B46C1",700:"#553C9A",800:"#44337A",900:"#322659"},pink:{50:"#FFF5F7",100:"#FED7E2",200:"#FBB6CE",300:"#F687B3",400:"#ED64A6",500:"#D53F8C",600:"#B83280",700:"#97266D",800:"#702459",900:"#521B41"},gray:{50:"#F7FAFC",100:"#EDF2F7",200:"#E2E8F0",300:"#CBD5E0",400:"#A0AEC0",500:"#718096",600:"#4A5568",700:"#2D3748",800:"#1A202C",900:"#171923",950:"#0d1117"}},Te=(e,r)=>{var i;if(e==="transparent"||e!=null&&e.startsWith("#")||e!=null&&e.startsWith("var(--"))return e;if(!e)return"whitesmoke";const t=e.replace(/\./g,"-");try{const a=getComputedStyle(document.documentElement).getPropertyValue(`--chakra-colors-${t}`).trim();if(a&&a!=="")return a}catch{}const[n,o]=e.split(".");return n&&o&&((i=Bu[n])!=null&&i[Number(o)])?Bu[n][Number(o)]:`var(--chakra-colors-${t})`},Rw=Nm.keyframes`
2
2
  0%, 100% { box-shadow: var(--flow-rest-shadow); }
3
3
  25%, 50% { box-shadow: var(--flow-hover-shadow); }
4
- `,Mw=Im.keyframes`
4
+ `,Mw=Nm.keyframes`
5
5
  from { box-shadow: var(--flow-start-shadow); }
6
6
  to { box-shadow: var(--flow-rest-shadow); }
7
- `;function pb(e,r=!0,t="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,s=`0 0 0 ${r?8:0}px ${o}`,a=`0 0 0 8px ${o}`;return{boxShadow:s,css:{"--flow-rest-shadow":a,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[t]:{boxShadow:a,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${Rw} 1200ms steps(10, end) 600ms`:"none"}}}}}}function gr(e,r){const{boxShadow:t,css:n}=pb(e,!1),o=n["@media (hover: hover)"]["&:hover"];return{borderWidth:"1px",borderStyle:"solid",borderColor:"transparent",boxShadow:t,...n,"--flow-start-shadow":t,"@media (hover: hover)":{"&:hover":{...o,borderColor:r,"@media (prefers-reduced-motion: no-preference)":{animation:`${Mw} 600ms steps(5, end)`}}}}}const gb=j.createContext(null),yb=j.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function Xt(){return j.useContext(yb)}function Ue(){const e=j.useContext(gb);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function mb({config:e,callbacks:r,nodes:t=[],edges:n=[],children:o}){const i=j.useMemo(()=>{var ge,je,Te;const z=new Map;for(const Re of t)(ge=Re.data)!=null&&ge.id&&z.set(Re.data.id,Re);const O=new Map;for(const Re of n)(je=Re.data)!=null&&je.id&&O.set(Re.data.id,Re);const ne=new Set;for(const Re of t)(Te=Re.data)!=null&&Te.parent&&ne.add(Re.data.parent);return{nodeById:z,edgeById:O,parentIds:ne}},[t,n]),s=j.useRef(null),[a,c]=j.useState([]),[l,d]=j.useState(null),[u,h]=j.useState(!0),[p,m]=j.useState(!1),[g,y]=j.useState(!0),[b,x]=j.useState(!1),[v,w]=j.useState(!1),[C,S]=j.useState(!0),[E,M]=j.useState(!1),[P,T]=j.useState(null),k=j.useRef(P),[R,_]=j.useState({gaps:15,fill:!1,padding:0}),[N,$]=j.useState(()=>new Set),[V,I]=j.useState({}),F=j.useCallback((z,O)=>{I(ne=>{const ge={...ne};for(const je of z)O===void 0?delete ge[je]:ge[je]=O;return ge})},[]),oe=j.useCallback(z=>{var O;!!(z!=null&&z.fill)!=!!((O=k.current)!=null&&O.fill)&&$(new Set),k.current=z,z&&_(z),T(z)},[]),[se,H]=j.useState("auto"),[ee,ue]=j.useState(!1),q=e.compactPropertyLayout??ee,[D,K]=j.useState({}),G=e.nodeViewModes??D,ce=[...i.nodeById.values()].filter(z=>{var O;return i.parentIds.has(z.data.id)||((O=z.data.config)==null?void 0:O.parentContainer)||z.data.type==="objectView"||z.data.type==="arrayView"}),re=!!ce.length&&ce.every(z=>{var O,ne,ge;return i.parentIds.has(z.data.id)||(O=z.data.config)!=null&&O.parentContainer?!!((ne=z.data.config)!=null&&ne.collapsed):G[z.data.id]==="icon-label"||((ge=z.data.config)==null?void 0:ge.labelBelow)&&G[z.data.id]!=="properties"}),[Z,ae]=j.useState("normal"),[ye,xe]=j.useState(),fe=e.edgeRadius??ye,U=fe!==void 0&&Number.isFinite(fe)?Math.min(500,Math.max(0,fe)):void 0,[te,de]=j.useState(),Pe=e.spacing??Z,ie=typeof Pe=="number"?Number.isFinite(Pe)?Math.min(2,Math.max(.5,Pe)):1:Pe==="compact"?.5:Pe==="spacious"?2:1,we=e.backgroundVariant??te??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[$e,He]=j.useState(),Ve=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:$e,[tt,me]=j.useState("blue.500"),[Ie,De]=j.useState(!1),be=j.useRef(r);be.current=r;const Xe=j.useMemo(()=>{const z=ge=>(...je)=>{var Te,Re;return(Re=(Te=be.current)==null?void 0:Te[ge])==null?void 0:Re.call(Te,...je)},O=z("onPromptSubmit"),ne=z("onFixedNodePositionsChange");return{getNodeEditMetadata:z("getNodeEditMetadata"),onNodeSelect:z("onNodeSelect"),onNodesCopy:z("onNodesCopy"),onNodesDuplicate:z("onNodesDuplicate"),onBackgroundClick:z("onBackgroundClick"),onBottomBarCollapsedChange:z("onBottomBarCollapsedChange"),onNodeGridZoomOut:z("onNodeGridZoomOut"),onNodeGridFillRequest:z("onNodeGridFillRequest"),onNodeGridModeRequest:z("onNodeGridModeRequest"),onNodeGridDrop:z("onNodeGridDrop"),onNodeDeselect:z("onNodeDeselect"),onNodeDoubleClick:z("onNodeDoubleClick"),onNodeViewToggle:z("onNodeViewToggle"),onNodeTypeViewChange:z("onNodeTypeViewChange"),onNodeCreate:z("onNodeCreate"),onNodeCreateRequest:z("onNodeCreateRequest"),onNodeDelete:z("onNodeDelete"),onNodeLabelChange:z("onNodeLabelChange"),onNodeSubtitleChange:z("onNodeSubtitleChange"),onNodeContentChange:z("onNodeContentChange"),onNodeDimensionChange:z("onNodeDimensionChange"),onNodeParentChange:z("onNodeParentChange"),get onFixedNodePositionsChange(){return be.current.onFixedNodePositionsChange?ne:void 0},get onPromptSubmit(){return be.current.onPromptSubmit?O:void 0},onNodeCollapse:z("onNodeCollapse"),onNodeColorChange:z("onNodeColorChange"),onNodeBorderColorChange:z("onNodeBorderColorChange"),onNodeBorderStyleChange:z("onNodeBorderStyleChange"),onNodeBorderWidthChange:z("onNodeBorderWidthChange"),onNodeBorderRadiusChange:(ge,je)=>{var Te,Re,Ye;(Te=k.current)!=null&&Te.fill&&$(et=>new Set([...et,ge])),(Ye=(Re=be.current).onNodeBorderRadiusChange)==null||Ye.call(Re,ge,je)},onNodeIconChange:z("onNodeIconChange"),onNodeOutlineChange:z("onNodeOutlineChange"),onNodeAnimationChange:z("onNodeAnimationChange"),onNodeAnimationVariantChange:z("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:z("onEdgeAnimationVariantChange"),onNodeHoverAction:z("onNodeHoverAction"),onEdgeCreate:z("onEdgeCreate"),onEdgeSelect:z("onEdgeSelect"),onEdgeDeselect:z("onEdgeDeselect"),onEdgeRemove:z("onEdgeRemove"),onEdgeDelete:z("onEdgeDelete"),onEdgeColorChange:z("onEdgeColorChange"),onEdgeTypeChange:z("onEdgeTypeChange"),onEdgeIconChange:z("onEdgeIconChange"),onEdgeLabelChange:z("onEdgeLabelChange"),onEdgeStyleChange:z("onEdgeStyleChange"),onViewportChange:z("onViewportChange"),onDirectionChange:z("onDirectionChange"),onThemeColorChange:z("onThemeColorChange"),onSpacingChange:z("onSpacingChange"),onEdgeRadiusChange:z("onEdgeRadiusChange"),onBackgroundVariantChange:z("onBackgroundVariantChange"),onEdgeModeChange:z("onEdgeModeChange"),onCompactPropertyLayoutChange:z("onCompactPropertyLayoutChange"),onWorkflowContractChange:z("onWorkflowContractChange"),onWorkflowConfigurationOpen:r.onWorkflowConfigurationOpen?z("onWorkflowConfigurationOpen"):void 0,onArrayModeChange:z("onArrayModeChange"),onInit:z("onInit"),onLayoutComplete:z("onLayoutComplete"),onJsonChange:z("onJsonChange")}},[]),ut=e.themeColor||tt,[Ae,Ke]=j.useState(""),lt=e.edgeColor??Ae,Je=e.colorMode||"light",yt=e.direction||"LR",At=e.nodeAlignment??"center",Jr=e.edgeMode==="workflow"?"nodes":e.edgeMode??se,Tr=e.readOnly??!1,rt=JSON.stringify(e.parentNodeStyle??null),We=j.useMemo(()=>e.parentNodeStyle,[rt]),Qt=e.isZoomMode!==void 0?e.isZoomMode:u,ft=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,qt=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:b,dr=e.isDragMode!==void 0?e.isDragMode:g,Be=j.useRef(e);Be.current=e;const Ht=j.useMemo(()=>({get direction(){return Be.current.direction},get nodeAlignment(){return Be.current.nodeAlignment},get edgeMode(){return Be.current.edgeMode},get compactPropertyLayout(){return Be.current.compactPropertyLayout},get bottomBarCollapsed(){return Be.current.bottomBarCollapsed},get bottomBarNavigation(){return Be.current.bottomBarNavigation},get bottomBarCollision(){return Be.current.bottomBarCollision},get bottomBarFill(){return Be.current.bottomBarFill},get nodeGrid(){return Be.current.nodeGrid},get nodeGridConnections(){return Be.current.nodeGridConnections},get nodeGridSpacing(){return Be.current.nodeGridSpacing},get edgeType(){return Be.current.edgeType},get edgeReveal(){return Be.current.edgeReveal},get customEdgeTypes(){return Be.current.customEdgeTypes},get themeColor(){return Be.current.themeColor},get colorMode(){return Be.current.colorMode},get readOnly(){return Be.current.readOnly},get editable(){return Be.current.editable},get minZoom(){return Be.current.minZoom},get maxZoom(){return Be.current.maxZoom},get backgroundPattern(){return Be.current.backgroundPattern},get edgeColor(){return Be.current.edgeColor},get parentNodeStyle(){return Be.current.parentNodeStyle},get backgroundColor(){return Be.current.backgroundColor},get edgeHandles(){return Be.current.edgeHandles},get initialViewport(){return Be.current.initialViewport},get fixedNodePositions(){return Be.current.fixedNodePositions},get animateViewport(){return Be.current.animateViewport},get disableAnimations(){return Be.current.disableAnimations},get nodeOverlayActions(){return Be.current.nodeOverlayActions},get renderNodeOverlay(){return Be.current.renderNodeOverlay},get renderSelectedNodeToolbar(){return Be.current.renderSelectedNodeToolbar},get renderSelectedEdgeToolbar(){return Be.current.renderSelectedEdgeToolbar},get renderBottomBar(){return Be.current.renderBottomBar},get bottomBarExtra(){return Be.current.bottomBarExtra},get selectionToolbar(){return Be.current.selectionToolbar},get customViews(){return Be.current.customViews},get disableKeyboardShortcuts(){return Be.current.disableKeyboardShortcuts},get isZoomMode(){return Be.current.isZoomMode},get isMultiSelectMode(){return Be.current.isMultiSelectMode},get isEdgeHandlesEnabled(){return Be.current.isEdgeHandlesEnabled},get isDragMode(){return Be.current.isDragMode}}),[]),Lt=j.useCallback((z,O)=>{var ne;if(O!=="default"&&O!=="properties"&&O!=="icon-label")throw new Error("Unknown node view mode.");K(ge=>ge[z]===O?ge:{...ge,[z]:O}),(ne=r.onNodeViewModeChange)==null||ne.call(r,z,O)},[r.onNodeViewModeChange]),ur=j.useMemo(()=>({allNodesIconLabel:re,setAllNodesIconLabel:z=>{var O,ne,ge,je,Te;if(!z)for(const[Re,Ye]of Object.entries(G))Ye==="icon-label"&&!i.nodeById.has(Re)&&Lt(Re,"default");for(const Re of ce)i.parentIds.has(Re.data.id)||(O=Re.data.config)!=null&&O.parentContainer?!Tr&&!!((ne=Re.data.config)!=null&&ne.collapsed)!==z&&((ge=r.onNodeCollapse)==null||ge.call(r,Re.data.id,z)):Lt(Re.data.id,z?"icon-label":(je=Re.data.config)!=null&&je.labelBelow?"properties":"default");(Te=r.onAllNodesIconLabelChange)==null||Te.call(r,z)},nodeViewModes:G,setNodeViewMode:Lt,nodeRadiusPreviews:V,setNodeRadiusPreview:F,spacing:ie,setSpacing:ae,edgeRadius:U,setEdgeRadius:xe,backgroundVariant:we,setBackgroundVariant:de,themeColor:ut,setThemeColor:me,backgroundSelected:Ie,setBackgroundSelected:De,edgeColor:lt,setEdgeColor:z=>{var O;Ke(z),(O=r.onGraphEdgeColorChange)==null||O.call(r,z)},colorMode:Je,direction:yt,nodeAlignment:At,edgeMode:Jr,setEdgeMode:H,compactPropertyLayout:q,setCompactPropertyLayout:ue,workflowContract:Ve,setWorkflowContract:He,parentNodeStyle:We,selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isZoomMode:Qt,setIsZoomMode:h,isMultiSelectMode:ft,setIsMultiSelectMode:m,isDragMode:dr,setIsDragMode:y,isEdgeHandlesEnabled:qt,setIsEdgeHandlesEnabled:x,isArrayNodeMode:v,setIsArrayNodeMode:w,isPinned:C,setIsPinned:S,isPerformanceMode:E,setIsPerformanceMode:M,nodeGridOptions:P,setNodeGridOptions:oe,lastNodeGridOptions:R,fillRadiusEditedIds:N,setFillRadiusEditedIds:$,engineRef:s,callbacks:Xe,config:Ht,readOnly:Tr}),[re,i,Lt,r.onNodeCollapse,r.onAllNodesIconLabelChange,r.onGraphEdgeColorChange,G,V,F,r.onNodeViewModeChange,ut,ie,we,U,e.backgroundColor,Ie,lt,Je,yt,At,Jr,Ve,We,a,l,Qt,ft,dr,qt,v,C,E,P,R,N,Tr,e.edgeHandles,e.edgeType,e.edgeReveal,e.animateViewport,e.disableAnimations,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.bottomBarCollapsed,e.bottomBarNavigation,e.bottomBarCollision,e.bottomBarFill,e.nodeGrid,e.nodeGridSpacing,e.nodeGridConnections,e.fixedNodePositions,r.onFixedNodePositionsChange,r.onPromptSubmit,e.compactPropertyLayout,q,Xe,Ht]);return f.jsx(gb.Provider,{value:ur,children:f.jsx(yb.Provider,{value:i,children:o})})}function Et(e,r,t){return e?t:r}function Gn(e){const[r]=(e==null?void 0:e.split("."))||[],{secondary:t}=hb(e),n=sr(r).background,o=sr(r).highlight,i=sr(r).border,s=sr(r).property,a=sr(r).property;let c=sr(r).background,l=sr(r).highlight;return c=e==="transparent"?e:Me(c)+50,l=e==="transparent"?e:Me(l)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:s,propertyColor:a,secondary:t,bgColorFaint:c,highlightColorFaint:l}}function at(e=null){const{colorMode:r}=Ue(),t=e==null?void 0:e.includes("gray"),n=r==="dark",o=Et(n,"white","gray.900"),i=Et(n,"gray.100","gray.800"),s=Et(n,"gray.200","blackAlpha.400"),a=Et(n,"gray.200","blackAlpha.600"),c=Et(n,"gray.500","gray.700"),l=Et(n,"gray.700","gray.700"),d=Et(n,"gray.900","gray.900"),u=Et(n,"gray.400","gray.500"),h=Et(n,"gray.400","gray.500"),p=Et(n,"gray.900","gray.200"),m=Et(n,t?"gray.900":"gray.200",t?"gray.200":"gray.900"),g=Et(n,"gray.900","gray.200"),y=Et(n,e&&"#000000",e||"#ffffff"),b=Et(n,e||"#ffffff",e?"#000000":"#ffffff"),x=l,v=Et(n,"gray.300","gray.800"),w=Et(n,"white","blackAlpha.400"),C=Et(n,"green.100","green.700");return{canvas:o,background:i,backgroundSecondary:s,darkBackgroundSecondary:a,border:c,darkColor:d,backgroundWhiteColor:w,borderSecondary:l,colorActive:u,colorInactive:h,iconColor:g,moreIconColor:x,colorText:p,themedColorText:m,logoColor:y,logoColorSecondary:b,darkColorActive:v,greenColor:C}}var Sn=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(Sn||{});const Ld=["","icon-label","object","text","grid","parent","prompt"];function bb({label:e,disabled:r=!1}){const t=j.useRef(null),n=j.useRef(),{colorInactive:o}=at(),i=()=>{var c;return(c=t.current)==null?void 0:c.closest("[data-flow-floating-panel]")},s=(c,l)=>{const d=i();if(!d)return;const u=d.getBoundingClientRect();d.style.left=`${Math.max(12,Math.min(c,window.innerWidth-u.width-12))}px`,d.style.top=`${Math.max(12,Math.min(l,window.innerHeight-u.height-12))}px`,d.style.right="auto",d.style.bottom="auto",d.dataset.flowPanelMoved="true"},a=(c=!1)=>{var d;const l=n.current;l&&(c&&s(l.left,l.top),n.current=void 0,(d=t.current)!=null&&d.hasPointerCapture(l.pointerId)&&t.current.releasePointerCapture(l.pointerId),t.current&&(t.current.style.cursor=""))};return j.useEffect(()=>{const c=()=>{const u=i();if(!(u!=null&&u.dataset.flowPanelMoved))return;const h=u.getBoundingClientRect();s(h.left,h.top)},l=u=>{u.key!=="Escape"||!n.current||(u.preventDefault(),u.stopPropagation(),a(!0))},d=()=>a(!0);return window.addEventListener("resize",c),window.addEventListener("keydown",l,!0),window.addEventListener("blur",d),()=>{window.removeEventListener("resize",c),window.removeEventListener("keydown",l,!0),window.removeEventListener("blur",d),a()}},[]),f.jsx(W.chakra.button,{ref:t,type:"button","aria-label":`Drag ${e}`,title:r?"Pin to drag":`Drag ${e}`,disabled:r,"data-panel-drag-handle":"",display:"flex",alignItems:"center",justifyContent:"center",width:"64px",height:"24px",flexShrink:0,marginInline:"auto",border:0,background:"transparent",color:o,cursor:"grab",touchAction:"none",userSelect:"none",_disabled:{opacity:.35,cursor:"default"},onPointerDown:c=>{var d;if(c.button!==0||n.current)return;const l=(d=i())==null?void 0:d.getBoundingClientRect();l&&(c.preventDefault(),c.stopPropagation(),n.current={pointerId:c.pointerId,x:c.clientX,y:c.clientY,left:l.left,top:l.top},c.currentTarget.setPointerCapture(c.pointerId),c.currentTarget.style.cursor="grabbing")},onPointerMove:c=>{const l=n.current;!l||l.pointerId!==c.pointerId||(c.stopPropagation(),s(l.left+c.clientX-l.x,l.top+c.clientY-l.y))},onPointerUp:c=>{var l;((l=n.current)==null?void 0:l.pointerId)===c.pointerId&&a()},onPointerCancel:()=>a(!0),onLostPointerCapture:()=>a(),onKeyDown:c=>{var u;const l=(u=i())==null?void 0:u.getBoundingClientRect();if(!l||!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(c.key))return;c.preventDefault(),c.stopPropagation();const d=c.shiftKey?40:10;s(l.left+(c.key==="ArrowLeft"?-d:c.key==="ArrowRight"?d:0),l.top+(c.key==="ArrowUp"?-d:c.key==="ArrowDown"?d:0))},children:f.jsx(Q.PiDotsSix,{size:20,"aria-hidden":"true"})})}function Tw(){let e,r=null;const t=new Set,n=o=>{r=o,t.forEach(i=>i())};return{subscribe:o=>(t.add(o),()=>{t.delete(o)}),getSnapshot:()=>r,select(o,i){e=o,n(i)},update(o,i){e===o&&n(i)},remove(o){e===o&&(e=void 0,n(null))}}}const nn=j.createContext(null),Iw=()=>j.useState(Tw)[0];function jo(e,r=!0){const t=j.useContext(nn),n=j.useId();return j.useEffect(()=>{r?t==null||t.update(n,e):t==null||t.remove(n)}),j.useEffect(()=>()=>t==null?void 0:t.remove(n),[t,n]),()=>{r&&(t==null||t.select(n,e))}}function Nw({divider:e,visibleActions:r=[]}){const t=j.useContext(nn),n=j.useSyncExternalStore(t.subscribe,t.getSnapshot,()=>null),o=n&&r.includes(n.props["aria-label"]??"");return f.jsx(nn.Provider,{value:null,children:f.jsxs("span",{"data-recent-toolbar-action":"",style:{display:n&&!o?"contents":"none"},children:[n&&!o&&e,!o&&n]})})}function Ge({label:e,children:r}){const t=j.cloneElement(r,{title:r.props.title??e});if(!W.Tooltip.Root){const n=W.Tooltip;return f.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:t})}return f.jsxs(W.Tooltip.Root,{positioning:{placement:"top"},children:[f.jsx(W.Tooltip.Trigger,{asChild:!0,children:t}),f.jsx(W.Portal,{children:f.jsx(W.Tooltip.Positioner,{children:f.jsx(W.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function Nn(){const{border:e}=at(),{colorMode:r}=Ue();return f.jsx(W.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:r==="dark"?e:"gray.300"})}function It({children:e,value:r,onValueChange:t,disabled:n,style:o,title:i,icon:s,popupContent:a,footer:c,pinned:l=!1,draggable:d=!1,open:u,onOpenChange:h,labelCase:p="title","aria-label":m,...g}){var I;const{colorMode:y}=Ue(),{background:b,border:x,colorText:v,colorInactive:w}=at(),C=y==="dark",S=j.useId(),E=j.useRef(null),M=j.useRef(null),[P,T]=j.useState(!1),k=jo(f.jsx(It,{value:r,onValueChange:t,disabled:n,style:o,title:i,icon:s,popupContent:a,footer:c,pinned:l,draggable:d,labelCase:p,"aria-label":m,children:e}),!!s);j.useLayoutEffect(()=>{const F=M.current,oe=F.matches(":popover-open"),se=document.activeElement instanceof HTMLElement&&F.contains(document.activeElement)?document.activeElement:null,H=[F,...F.querySelectorAll("*")].filter(q=>q.scrollTop||q.scrollLeft).map(q=>({element:q,top:q.scrollTop,left:q.scrollLeft})),ee=l?"manual":"auto";if(F.getAttribute("popover")!==ee&&F.setAttribute("popover",ee),oe){F.showPopover(),!l&&F.dataset.flowPanelMoved&&(delete F.dataset.flowPanelMoved,N()),se==null||se.focus({preventScroll:!0});for(const{element:q,top:D,left:K}of H)q.scrollTop=D,q.scrollLeft=K}const ue=q=>{const D=q.newState==="open";T(D),h==null||h(D)};return F.addEventListener("toggle",ue),()=>F.removeEventListener("toggle",ue)},[l,h]);const R=j.Children.toArray(e).filter(j.isValidElement).map(F=>{const oe=F.props;return{value:String(oe.value),label:typeof oe.children=="string"&&p==="title"?Dt(oe.children):oe.children,disabled:oe.disabled}}),_=()=>{var F;return(F=M.current)==null?void 0:F.hidePopover()},N=()=>{var ue,q,D,K,G;const F=(ue=E.current)==null?void 0:ue.getBoundingClientRect(),oe=M.current;if(!F||!oe||l&&oe.dataset.flowPanelMoved)return;if((q=E.current)!=null&&q.closest("[popover]")){const ce=window.innerHeight-F.bottom-16,re=F.top-16;oe.style.maxHeight=`${Math.max(60,ce,re)}px`;const Z=oe.getBoundingClientRect();oe.style.left=`${Math.max(12,Math.min(F.right-Z.width,window.innerWidth-Z.width-12))}px`,oe.style.top=`${Math.max(12,Z.height<=ce?F.bottom+4:F.top-Z.height-4)}px`;return}const se=(G=(K=(D=E.current)==null?void 0:D.closest("[data-flow-toolbar-scroll]"))==null?void 0:K.parentElement)==null?void 0:G.getBoundingClientRect(),H=se??F;oe.style.maxHeight=`${Math.max(60,Math.max(H.top-40,window.innerHeight-H.bottom-40))}px`;const ee=oe.getBoundingClientRect();oe.style.left=`${Math.max(12,Math.min(Math.max((se==null?void 0:se.left)??12,F.right-ee.width),((se==null?void 0:se.right)??window.innerWidth-12)-ee.width,window.innerWidth-ee.width-12))}px`,oe.style.top=`${Math.max(12,H.top>=ee.height+36?H.top-ee.height-24:Math.min(H.bottom+24,window.innerHeight-ee.height-12))}px`},$=()=>{var se,H,ee,ue,q,D;if(n)return;if(M.current&&!M.current.matches(":popover-open")&&delete M.current.dataset.flowPanelMoved,(se=M.current)==null||se.showPopover(),N(),a){(ee=(H=M.current)==null?void 0:H.querySelector("input"))==null||ee.focus({preventScroll:!0});return}const F=(ue=M.current)==null?void 0:ue.querySelectorAll('[role="option"]:not(:disabled)');(D=((q=M.current)==null?void 0:q.querySelector('[aria-selected="true"]:not(:disabled)'))??(F==null?void 0:F[0]))==null||D.focus()};j.useLayoutEffect(()=>{u!==void 0&&(u?$():_())},[u]),j.useEffect(()=>{if(P){if(n){_();return}return window.addEventListener("resize",N),window.addEventListener("scroll",N,!0),()=>{window.removeEventListener("resize",N),window.removeEventListener("scroll",N,!0)}}},[P,n,l]);const V=`var(--chakra-colors-${b.replace(".","-")})`;return f.jsxs(f.Fragment,{children:[f.jsx(Ge,{label:i??m,children:f.jsx(W.chakra.button,{...g,ref:E,type:"button",role:"combobox","data-flow-select-icon":s?"":void 0,"aria-label":m,title:i??m,"aria-haspopup":a?"dialog":"listbox","aria-expanded":P,"aria-controls":S,disabled:n,h:"30px",w:"160px",px:"6px",fontSize:"12px",border:"none",borderRadius:"4px",bg:"transparent",color:s?w:v,display:"flex",alignItems:"center",justifyContent:s?"center":"space-between",gap:2,style:o,onClick:()=>{k(),P?_():$()},onKeyDown:F=>{["ArrowDown","ArrowUp"].includes(F.key)&&(F.preventDefault(),$())},children:s??f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((I=R.find(F=>F.value===r))==null?void 0:I.label)??r}),f.jsx(Q.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),f.jsxs(W.chakra.div,{ref:M,id:S,"data-flow-select-pinned":l?"":void 0,"data-flow-floating-panel":d&&l?"":void 0,role:a?"dialog":"listbox","aria-label":m,position:"fixed",m:0,p:2,minW:"180px",maxW:"calc(100vw - 24px)",gridTemplateColumns:c&&a?"minmax(0, 1fr)":void 0,gridTemplateRows:c&&a?`${d&&l?"auto ":""}minmax(0, 1fr) auto`:void 0,overflowY:c&&a?"hidden":"auto",bg:b,color:v,borderRadius:"30px",css:{"&:popover-open":{display:c&&a?"grid":void 0},scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"},'& [role="option"]':ho,'& details [role="option"]:first-child':{borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},...gr(V,`var(--chakra-colors-${(C?x:"gray.300").replace(".","-")})`)},onKeyDown:F=>{var H,ee,ue;if(a&&!["Escape","Tab"].includes(F.key))return;const oe=[...F.currentTarget.querySelectorAll('[role="option"]:not(:disabled), [data-flow-menu-action]:not(:disabled)')],se=oe.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(F.key)){F.preventDefault();const q=F.key==="Home"?0:F.key==="End"?oe.length-1:(se+(F.key==="ArrowDown"?1:-1)+oe.length)%oe.length;(H=oe[q])==null||H.focus()}else if(F.key==="Escape"||F.key==="Tab"){if(F.key==="Tab"&&l)return;F.key==="Escape"&&(F.preventDefault(),F.stopPropagation()),_(),(ee=E.current)==null||ee.focus()}else F.key.length===1&&F.key!==" "&&((ue=oe.find((q,D)=>{var K;return D>se&&((K=q.textContent)==null?void 0:K.toLowerCase().startsWith(F.key.toLowerCase()))}))==null||ue.focus())},children:[d&&l&&f.jsx(bb,{label:m}),a??R.map(F=>f.jsxs(W.chakra.button,{type:"button",role:"option","aria-selected":F.value===r,disabled:F.disabled,tabIndex:-1,display:"flex",alignItems:"center",gap:3,px:3,py:2,w:"100%",fontSize:"sm",textAlign:"left",bg:"transparent",color:v,_hover:{bg:C?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:C?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var oe;l||(_(),(oe=E.current)==null||oe.focus()),t(F.value)},children:[f.jsx("span",{style:{flex:1},children:F.label}),f.jsx(Q.PiCheck,{size:16,color:`var(--chakra-colors-${v.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:F.value===r?"visible":"hidden"}})]},F.value)),c]})]})}const ho={borderRadius:"4px","&:first-child":{borderTopLeftRadius:"22px",borderTopRightRadius:"22px"},"&:last-child":{borderBottomLeftRadius:"22px",borderBottomRightRadius:"22px"}},Ne=j.forwardRef(function({icon:r,rememberAction:t=!0,...n},o){const{colorMode:i}=Ue(),s=Object.fromEntries(Object.entries(n).filter(([c])=>c!=="id"&&c!=="aria-describedby"&&!c.startsWith("data-")&&!/^on(Pointer|Mouse|Focus|Blur)/.test(c))),a=jo(f.jsx(Ge,{label:n.title??n["aria-label"]??"Last used action",children:f.jsx(Ne,{...s,icon:r})}),t&&!!n.onClick);return f.jsx(W.IconButton,{ref:o,_hover:{bg:i==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:n.title??n["aria-label"],...n,onClick:c=>{var l;a(),(l=n.onClick)==null||l.call(n,c)},children:r})}),dn=j.forwardRef(function(r,t){const{themeColor:n}=Ue();return f.jsx(Ge,{label:"Close",children:f.jsx(Ne,{ref:t,size:"sm",variant:"plain",bg:"transparent",_hover:{bg:"transparent",color:n},color:n,focusRingColor:n,...r,"aria-label":r["aria-label"]??"Close selection tools",icon:f.jsx(Q.PiXLight,{size:20,"aria-hidden":"true"})})})});function xb({onBeforeExpand:e}={}){const{allNodesIconLabel:r,setAllNodesIconLabel:t}=Ue();return f.jsx(on,{label:"Collapse all",hideLabel:!0,checked:r,icon:f.jsx(Q.PiArrowsInLineVertical,{size:20}),onChange:n=>{n||e==null||e(),t(n)}})}function on({label:e,icon:r,checked:t,onChange:n,disabled:o,hideLabel:i=!1,helper:s=e}){const{themeColor:a,readOnly:c}=Ue(),{colorInactive:l}=at();return f.jsx(Ge,{label:s,children:f.jsx(Ne,{"aria-label":e,"aria-pressed":t,icon:f.jsxs(f.Fragment,{children:[r,!i&&f.jsx(W.Text,{as:"span",fontSize:"16px",fontWeight:t?"bold":"normal",whiteSpace:"nowrap",children:e})]}),size:"sm",variant:"ghost",width:"auto",px:2,gap:2,color:t?a:l,disabled:o||c,onClick:()=>n(!t)})})}function vb({label:e="Compact layout"}={}){const{compactPropertyLayout:r,setCompactPropertyLayout:t,callbacks:n}=Ue();return f.jsx(on,{hideLabel:!0,label:e,checked:r,icon:f.jsx(W.Icon,{as:Q.PiArrowsIn,boxSize:5}),onChange:o=>{var i;t(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const Ow=xo.default.input`
7
+ `;function gb(e,r=!0,t="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,s=`0 0 0 ${r?8:0}px ${o}`,a=`0 0 0 8px ${o}`;return{boxShadow:s,css:{"--flow-rest-shadow":a,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[t]:{boxShadow:a,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${Rw} 1200ms steps(10, end) 600ms`:"none"}}}}}}function gr(e,r){const{boxShadow:t,css:n}=gb(e,!1),o=n["@media (hover: hover)"]["&:hover"];return{borderWidth:"1px",borderStyle:"solid",borderColor:"transparent",boxShadow:t,...n,"--flow-start-shadow":t,"@media (hover: hover)":{"&:hover":{...o,borderColor:r,"@media (prefers-reduced-motion: no-preference)":{animation:`${Mw} 600ms steps(5, end)`}}}}}const yb=j.createContext(null),mb=j.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function Xt(){return j.useContext(mb)}function He(){const e=j.useContext(yb);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function bb({config:e,callbacks:r,nodes:t=[],edges:n=[],children:o}){const i=j.useMemo(()=>{var ye,je,Ie;const z=new Map;for(const Me of t)(ye=Me.data)!=null&&ye.id&&z.set(Me.data.id,Me);const O=new Map;for(const Me of n)(je=Me.data)!=null&&je.id&&O.set(Me.data.id,Me);const oe=new Set;for(const Me of t)(Ie=Me.data)!=null&&Ie.parent&&oe.add(Me.data.parent);return{nodeById:z,edgeById:O,parentIds:oe}},[t,n]),s=j.useRef(null),[a,c]=j.useState([]),[l,d]=j.useState(null),[u,h]=j.useState(!0),[p,m]=j.useState(!1),[g,y]=j.useState(!0),[b,x]=j.useState(!1),[w,v]=j.useState(!1),[C,S]=j.useState(!0),[E,R]=j.useState(!1),[P,I]=j.useState(null),M=j.useRef(P),[k,_]=j.useState({gaps:15,fill:!1,padding:0}),[N,$]=j.useState(()=>new Set),[D,T]=j.useState({}),Z=j.useCallback((z,O)=>{T(oe=>{const ye={...oe};for(const je of z)O===void 0?delete ye[je]:ye[je]=O;return ye})},[]),K=j.useCallback(z=>{var O;!!(z!=null&&z.fill)!=!!((O=M.current)!=null&&O.fill)&&$(new Set),M.current=z,z&&_(z),I(z)},[]),[ne,se]=j.useState("auto"),[W,ue]=j.useState(!1),q=e.compactPropertyLayout??W,[F,H]=j.useState({}),G=e.nodeViewModes??F,ce=[...i.nodeById.values()].filter(z=>{var O;return i.parentIds.has(z.data.id)||((O=z.data.config)==null?void 0:O.parentContainer)||z.data.type==="objectView"||z.data.type==="arrayView"}),te=!!ce.length&&ce.every(z=>{var O,oe,ye;return i.parentIds.has(z.data.id)||(O=z.data.config)!=null&&O.parentContainer?!!((oe=z.data.config)!=null&&oe.collapsed):G[z.data.id]==="icon-label"||((ye=z.data.config)==null?void 0:ye.labelBelow)&&G[z.data.id]!=="properties"}),[X,ie]=j.useState("normal"),[me,xe]=j.useState(),fe=e.edgeRadius??me,U=fe!==void 0&&Number.isFinite(fe)?Math.min(500,Math.max(0,fe)):void 0,[re,de]=j.useState(),Pe=e.spacing??X,ae=typeof Pe=="number"?Number.isFinite(Pe)?Math.min(2,Math.max(.5,Pe)):1:Pe==="compact"?.5:Pe==="spacious"?2:1,we=e.backgroundVariant??re??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[$e,Ue]=j.useState(),Ve=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:$e,[tt,ge]=j.useState("blue.500"),[Ae,Le]=j.useState(!1),be=j.useRef(r);be.current=r;const Xe=j.useMemo(()=>{const z=ye=>(...je)=>{var Ie,Me;return(Me=(Ie=be.current)==null?void 0:Ie[ye])==null?void 0:Me.call(Ie,...je)},O=z("onPromptSubmit"),oe=z("onFixedNodePositionsChange");return{getNodeEditMetadata:z("getNodeEditMetadata"),onNodeSelect:z("onNodeSelect"),onNodesCopy:z("onNodesCopy"),onNodesDuplicate:z("onNodesDuplicate"),onBackgroundClick:z("onBackgroundClick"),onBottomBarCollapsedChange:z("onBottomBarCollapsedChange"),onNodeGridZoomOut:z("onNodeGridZoomOut"),onNodeGridFillRequest:z("onNodeGridFillRequest"),onNodeGridModeRequest:z("onNodeGridModeRequest"),onNodeGridDrop:z("onNodeGridDrop"),onNodeDeselect:z("onNodeDeselect"),onNodeDoubleClick:z("onNodeDoubleClick"),onNodeViewToggle:z("onNodeViewToggle"),onNodeTypeViewChange:z("onNodeTypeViewChange"),onNodeCreate:z("onNodeCreate"),onNodeCreateRequest:z("onNodeCreateRequest"),onNodeDelete:z("onNodeDelete"),onNodeLabelChange:z("onNodeLabelChange"),onNodeSubtitleChange:z("onNodeSubtitleChange"),onNodeContentChange:z("onNodeContentChange"),onNodeContentFormatChange:z("onNodeContentFormatChange"),onNodeDimensionChange:z("onNodeDimensionChange"),onNodeParentChange:z("onNodeParentChange"),get onFixedNodePositionsChange(){return be.current.onFixedNodePositionsChange?oe:void 0},get onPromptSubmit(){return be.current.onPromptSubmit?O:void 0},onNodeCollapse:z("onNodeCollapse"),onNodeColorChange:z("onNodeColorChange"),onNodeBorderColorChange:z("onNodeBorderColorChange"),onNodeBorderStyleChange:z("onNodeBorderStyleChange"),onNodeBorderWidthChange:z("onNodeBorderWidthChange"),onNodeBorderRadiusChange:(ye,je)=>{var Ie,Me,Ye;(Ie=M.current)!=null&&Ie.fill&&$(et=>new Set([...et,ye])),(Ye=(Me=be.current).onNodeBorderRadiusChange)==null||Ye.call(Me,ye,je)},onNodeIconChange:z("onNodeIconChange"),onNodeOutlineChange:z("onNodeOutlineChange"),onNodeAnimationChange:z("onNodeAnimationChange"),onNodeAnimationVariantChange:z("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:z("onEdgeAnimationVariantChange"),onNodeHoverAction:z("onNodeHoverAction"),onEdgeCreate:z("onEdgeCreate"),onEdgeSelect:z("onEdgeSelect"),onEdgeDeselect:z("onEdgeDeselect"),onEdgeRemove:z("onEdgeRemove"),onEdgeDelete:z("onEdgeDelete"),onEdgeColorChange:z("onEdgeColorChange"),onEdgeTypeChange:z("onEdgeTypeChange"),onEdgeIconChange:z("onEdgeIconChange"),onEdgeLabelChange:z("onEdgeLabelChange"),onEdgeStyleChange:z("onEdgeStyleChange"),onViewportChange:z("onViewportChange"),onDirectionChange:z("onDirectionChange"),onThemeColorChange:z("onThemeColorChange"),onSpacingChange:z("onSpacingChange"),onEdgeRadiusChange:z("onEdgeRadiusChange"),onBackgroundVariantChange:z("onBackgroundVariantChange"),onEdgeModeChange:z("onEdgeModeChange"),onCompactPropertyLayoutChange:z("onCompactPropertyLayoutChange"),onWorkflowContractChange:z("onWorkflowContractChange"),onWorkflowConfigurationOpen:r.onWorkflowConfigurationOpen?z("onWorkflowConfigurationOpen"):void 0,onArrayModeChange:z("onArrayModeChange"),onInit:z("onInit"),onLayoutComplete:z("onLayoutComplete"),onJsonChange:z("onJsonChange")}},[]),ut=e.themeColor||tt,[Re,Ke]=j.useState(""),lt=e.edgeColor??Re,Je=e.colorMode||"light",mt=e.direction||"LR",At=e.nodeAlignment??"center",Jr=e.edgeMode==="workflow"?"nodes":e.edgeMode??ne,Tr=e.readOnly??!1,rt=JSON.stringify(e.parentNodeStyle??null),We=j.useMemo(()=>e.parentNodeStyle,[rt]),Qt=e.isZoomMode!==void 0?e.isZoomMode:u,ft=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,qt=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:b,dr=e.isDragMode!==void 0?e.isDragMode:g,De=j.useRef(e);De.current=e;const Ht=j.useMemo(()=>({get direction(){return De.current.direction},get nodeAlignment(){return De.current.nodeAlignment},get edgeMode(){return De.current.edgeMode},get compactPropertyLayout(){return De.current.compactPropertyLayout},get bottomBarCollapsed(){return De.current.bottomBarCollapsed},get bottomBarNavigation(){return De.current.bottomBarNavigation},get bottomBarCollision(){return De.current.bottomBarCollision},get bottomBarFill(){return De.current.bottomBarFill},get nodeGrid(){return De.current.nodeGrid},get nodeGridConnections(){return De.current.nodeGridConnections},get nodeGridSpacing(){return De.current.nodeGridSpacing},get edgeType(){return De.current.edgeType},get edgeReveal(){return De.current.edgeReveal},get customEdgeTypes(){return De.current.customEdgeTypes},get themeColor(){return De.current.themeColor},get colorMode(){return De.current.colorMode},get readOnly(){return De.current.readOnly},get editable(){return De.current.editable},get minZoom(){return De.current.minZoom},get maxZoom(){return De.current.maxZoom},get backgroundPattern(){return De.current.backgroundPattern},get edgeColor(){return De.current.edgeColor},get parentNodeStyle(){return De.current.parentNodeStyle},get backgroundColor(){return De.current.backgroundColor},get edgeHandles(){return De.current.edgeHandles},get initialViewport(){return De.current.initialViewport},get fixedNodePositions(){return De.current.fixedNodePositions},get animateViewport(){return De.current.animateViewport},get disableAnimations(){return De.current.disableAnimations},get nodeOverlayActions(){return De.current.nodeOverlayActions},get renderNodeOverlay(){return De.current.renderNodeOverlay},get renderSelectedNodeToolbar(){return De.current.renderSelectedNodeToolbar},get renderSelectedEdgeToolbar(){return De.current.renderSelectedEdgeToolbar},get renderBottomBar(){return De.current.renderBottomBar},get bottomBarExtra(){return De.current.bottomBarExtra},get selectionToolbar(){return De.current.selectionToolbar},get customViews(){return De.current.customViews},get disableKeyboardShortcuts(){return De.current.disableKeyboardShortcuts},get isZoomMode(){return De.current.isZoomMode},get isMultiSelectMode(){return De.current.isMultiSelectMode},get isEdgeHandlesEnabled(){return De.current.isEdgeHandlesEnabled},get isDragMode(){return De.current.isDragMode}}),[]),Lt=j.useCallback((z,O)=>{var oe;if(O!=="default"&&O!=="properties"&&O!=="icon-label")throw new Error("Unknown node view mode.");H(ye=>ye[z]===O?ye:{...ye,[z]:O}),(oe=r.onNodeViewModeChange)==null||oe.call(r,z,O)},[r.onNodeViewModeChange]),ur=j.useMemo(()=>({allNodesIconLabel:te,setAllNodesIconLabel:z=>{var O,oe,ye,je,Ie;if(!z)for(const[Me,Ye]of Object.entries(G))Ye==="icon-label"&&!i.nodeById.has(Me)&&Lt(Me,"default");for(const Me of ce)i.parentIds.has(Me.data.id)||(O=Me.data.config)!=null&&O.parentContainer?!Tr&&!!((oe=Me.data.config)!=null&&oe.collapsed)!==z&&((ye=r.onNodeCollapse)==null||ye.call(r,Me.data.id,z)):Lt(Me.data.id,z?"icon-label":(je=Me.data.config)!=null&&je.labelBelow?"properties":"default");(Ie=r.onAllNodesIconLabelChange)==null||Ie.call(r,z)},nodeViewModes:G,setNodeViewMode:Lt,nodeRadiusPreviews:D,setNodeRadiusPreview:Z,spacing:ae,setSpacing:ie,edgeRadius:U,setEdgeRadius:xe,backgroundVariant:we,setBackgroundVariant:de,themeColor:ut,setThemeColor:ge,backgroundSelected:Ae,setBackgroundSelected:Le,edgeColor:lt,setEdgeColor:z=>{var O;Ke(z),(O=r.onGraphEdgeColorChange)==null||O.call(r,z)},colorMode:Je,direction:mt,nodeAlignment:At,edgeMode:Jr,setEdgeMode:se,compactPropertyLayout:q,setCompactPropertyLayout:ue,workflowContract:Ve,setWorkflowContract:Ue,parentNodeStyle:We,selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isZoomMode:Qt,setIsZoomMode:h,isMultiSelectMode:ft,setIsMultiSelectMode:m,isDragMode:dr,setIsDragMode:y,isEdgeHandlesEnabled:qt,setIsEdgeHandlesEnabled:x,isArrayNodeMode:w,setIsArrayNodeMode:v,isPinned:C,setIsPinned:S,isPerformanceMode:E,setIsPerformanceMode:R,nodeGridOptions:P,setNodeGridOptions:K,lastNodeGridOptions:k,fillRadiusEditedIds:N,setFillRadiusEditedIds:$,engineRef:s,callbacks:Xe,config:Ht,readOnly:Tr}),[te,i,Lt,r.onNodeCollapse,r.onAllNodesIconLabelChange,r.onGraphEdgeColorChange,G,D,Z,r.onNodeViewModeChange,ut,ae,we,U,e.backgroundColor,Ae,lt,Je,mt,At,Jr,Ve,We,a,l,Qt,ft,dr,qt,w,C,E,P,k,N,Tr,e.edgeHandles,e.edgeType,e.edgeReveal,e.animateViewport,e.disableAnimations,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.bottomBarCollapsed,e.bottomBarNavigation,e.bottomBarCollision,e.bottomBarFill,e.nodeGrid,e.nodeGridSpacing,e.nodeGridConnections,e.fixedNodePositions,r.onFixedNodePositionsChange,r.onPromptSubmit,e.compactPropertyLayout,q,Xe,Ht]);return f.jsx(yb.Provider,{value:ur,children:f.jsx(mb.Provider,{value:i,children:o})})}function _t(e,r,t){return e?t:r}function Gn(e){const[r]=(e==null?void 0:e.split("."))||[],{secondary:t}=pb(e),n=sr(r).background,o=sr(r).highlight,i=sr(r).border,s=sr(r).property,a=sr(r).property;let c=sr(r).background,l=sr(r).highlight;return c=e==="transparent"?e:Te(c)+50,l=e==="transparent"?e:Te(l)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:s,propertyColor:a,secondary:t,bgColorFaint:c,highlightColorFaint:l}}function at(e=null){const{colorMode:r}=He(),t=e==null?void 0:e.includes("gray"),n=r==="dark",o=_t(n,"white","gray.900"),i=_t(n,"gray.100","gray.800"),s=_t(n,"gray.200","blackAlpha.400"),a=_t(n,"gray.200","blackAlpha.600"),c=_t(n,"gray.500","gray.700"),l=_t(n,"gray.700","gray.700"),d=_t(n,"gray.900","gray.900"),u=_t(n,"gray.400","gray.500"),h=_t(n,"gray.400","gray.500"),p=_t(n,"gray.900","gray.200"),m=_t(n,t?"gray.900":"gray.200",t?"gray.200":"gray.900"),g=_t(n,"gray.900","gray.200"),y=_t(n,e&&"#000000",e||"#ffffff"),b=_t(n,e||"#ffffff",e?"#000000":"#ffffff"),x=l,w=_t(n,"gray.300","gray.800"),v=_t(n,"white","blackAlpha.400"),C=_t(n,"green.100","green.700");return{canvas:o,background:i,backgroundSecondary:s,darkBackgroundSecondary:a,border:c,darkColor:d,backgroundWhiteColor:v,borderSecondary:l,colorActive:u,colorInactive:h,iconColor:g,moreIconColor:x,colorText:p,themedColorText:m,logoColor:y,logoColorSecondary:b,darkColorActive:w,greenColor:C}}var Sn=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(Sn||{});const Ld=["","icon-label","object","text","grid","parent","prompt"];function xb({label:e,disabled:r=!1}){const t=j.useRef(null),n=j.useRef(),{colorInactive:o}=at(),i=()=>{var d;return(d=t.current)==null?void 0:d.closest("[data-flow-floating-panel]")},s=`flow:panel-position:${e}`,a=()=>{const d=i();if(d!=null&&d.dataset.flowPanelMoved)try{localStorage.setItem(s,JSON.stringify({left:parseFloat(d.style.left),top:parseFloat(d.style.top)}))}catch{}},c=(d,u)=>{const h=i();if(!h)return;const p=h.getBoundingClientRect();h.style.left=`${Math.max(12,Math.min(d,window.innerWidth-p.width-12))}px`,h.style.top=`${Math.max(12,Math.min(u,window.innerHeight-p.height-12))}px`,h.style.right="auto",h.style.bottom="auto",h.dataset.flowPanelMoved="true"};j.useEffect(()=>{const d=i();if(!(!d||d.dataset.flowPanelMoved))try{const u=JSON.parse(localStorage.getItem(s)||"null");u&&Number.isFinite(u.left)&&Number.isFinite(u.top)&&c(u.left,u.top)}catch{}},[s]);const l=(d=!1)=>{var h;const u=n.current;u&&(d?c(u.left,u.top):a(),n.current=void 0,(h=t.current)!=null&&h.hasPointerCapture(u.pointerId)&&t.current.releasePointerCapture(u.pointerId),t.current&&(t.current.style.cursor=""))};return j.useEffect(()=>{const d=()=>{const p=i();if(!(p!=null&&p.dataset.flowPanelMoved))return;const m=p.getBoundingClientRect();c(m.left,m.top)},u=p=>{p.key!=="Escape"||!n.current||(p.preventDefault(),p.stopPropagation(),l(!0))},h=()=>l(!0);return window.addEventListener("resize",d),window.addEventListener("keydown",u,!0),window.addEventListener("blur",h),()=>{window.removeEventListener("resize",d),window.removeEventListener("keydown",u,!0),window.removeEventListener("blur",h),l()}},[]),f.jsx(V.chakra.button,{ref:t,type:"button","aria-label":`Drag ${e}`,title:r?"Pin to drag":`Drag ${e}`,disabled:r,"data-panel-drag-handle":"",display:"flex",alignItems:"center",justifyContent:"center",width:"64px",height:"24px",flexShrink:0,marginInline:"auto",border:0,background:"transparent",color:o,cursor:"grab",touchAction:"none",userSelect:"none",_disabled:{opacity:.35,cursor:"default"},onPointerDown:d=>{var h;if(d.button!==0||n.current)return;const u=(h=i())==null?void 0:h.getBoundingClientRect();u&&(d.preventDefault(),d.stopPropagation(),n.current={pointerId:d.pointerId,x:d.clientX,y:d.clientY,left:u.left,top:u.top},d.currentTarget.setPointerCapture(d.pointerId),d.currentTarget.style.cursor="grabbing")},onPointerMove:d=>{const u=n.current;!u||u.pointerId!==d.pointerId||(d.stopPropagation(),c(u.left+d.clientX-u.x,u.top+d.clientY-u.y))},onPointerUp:d=>{var u;((u=n.current)==null?void 0:u.pointerId)===d.pointerId&&l()},onPointerCancel:()=>l(!0),onLostPointerCapture:()=>l(),onKeyDown:d=>{var p;const u=(p=i())==null?void 0:p.getBoundingClientRect();if(!u||!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(d.key))return;d.preventDefault(),d.stopPropagation();const h=d.shiftKey?40:10;c(u.left+(d.key==="ArrowLeft"?-h:d.key==="ArrowRight"?h:0),u.top+(d.key==="ArrowUp"?-h:d.key==="ArrowDown"?h:0)),a()},children:f.jsx(ee.PiDotsSix,{size:20,"aria-hidden":"true"})})}function Tw(){let e,r=null;const t=new Set,n=o=>{r=o,t.forEach(i=>i())};return{subscribe:o=>(t.add(o),()=>{t.delete(o)}),getSnapshot:()=>r,select(o,i){e=o,n(i)},update(o,i){e===o&&n(i)},remove(o){e===o&&(e=void 0,n(null))}}}const nn=j.createContext(null),Iw=()=>j.useState(Tw)[0];function jo(e,r=!0){const t=j.useContext(nn),n=j.useId();return j.useEffect(()=>{r?t==null||t.update(n,e):t==null||t.remove(n)}),j.useEffect(()=>()=>t==null?void 0:t.remove(n),[t,n]),()=>{r&&(t==null||t.select(n,e))}}function Nw({divider:e,visibleActions:r=[]}){const t=j.useContext(nn),n=j.useSyncExternalStore(t.subscribe,t.getSnapshot,()=>null),o=n&&r.includes(n.props["aria-label"]??"");return f.jsx(nn.Provider,{value:null,children:f.jsxs("span",{"data-recent-toolbar-action":"",style:{display:n&&!o?"contents":"none"},children:[n&&!o&&e,!o&&n]})})}function Ge({label:e,children:r}){const t=j.cloneElement(r,{title:r.props.title??e});if(!V.Tooltip.Root){const n=V.Tooltip;return f.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:t})}return f.jsxs(V.Tooltip.Root,{positioning:{placement:"top"},children:[f.jsx(V.Tooltip.Trigger,{asChild:!0,children:t}),f.jsx(V.Portal,{children:f.jsx(V.Tooltip.Positioner,{children:f.jsx(V.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function Nn(){const{border:e}=at(),{colorMode:r}=He();return f.jsx(V.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:r==="dark"?e:"gray.300"})}function It({children:e,value:r,onValueChange:t,disabled:n,style:o,title:i,icon:s,popupContent:a,footer:c,pinned:l=!1,draggable:d=!1,open:u,onOpenChange:h,labelCase:p="title","aria-label":m,...g}){var Z;const{colorMode:y}=He(),{background:b,border:x,colorText:w,colorInactive:v}=at(),C=y==="dark",S=j.useId(),E=j.useRef(null),R=j.useRef(null),[P,I]=j.useState(!1),M=jo(f.jsx(It,{value:r,onValueChange:t,disabled:n,style:o,title:i,icon:s,popupContent:a,footer:c,pinned:l,draggable:d,labelCase:p,"aria-label":m,children:e}),!!s);j.useLayoutEffect(()=>{const K=R.current,ne=K.matches(":popover-open"),se=document.activeElement instanceof HTMLElement&&K.contains(document.activeElement)?document.activeElement:null,W=[K,...K.querySelectorAll("*")].filter(F=>F.scrollTop||F.scrollLeft).map(F=>({element:F,top:F.scrollTop,left:F.scrollLeft})),ue=l?"manual":"auto";if(K.getAttribute("popover")!==ue&&K.setAttribute("popover",ue),ne){K.showPopover(),!l&&K.dataset.flowPanelMoved&&(delete K.dataset.flowPanelMoved,N()),se==null||se.focus({preventScroll:!0});for(const{element:F,top:H,left:G}of W)F.scrollTop=H,F.scrollLeft=G}const q=F=>{const H=F.newState==="open";I(H),h==null||h(H)};return K.addEventListener("toggle",q),()=>K.removeEventListener("toggle",q)},[l,h]);const k=j.Children.toArray(e).filter(j.isValidElement).map(K=>{const ne=K.props;return{value:String(ne.value),label:typeof ne.children=="string"&&p==="title"?Dt(ne.children):ne.children,disabled:ne.disabled}}),_=()=>{var K;return(K=R.current)==null?void 0:K.hidePopover()},N=()=>{var q,F,H,G,ce;const K=(q=E.current)==null?void 0:q.getBoundingClientRect(),ne=R.current;if(!K||!ne||l&&ne.dataset.flowPanelMoved)return;if(l){ne.style.maxHeight=`${Math.max(60,window.innerHeight-108)}px`,ne.style.left="20px",ne.style.top="84px";return}if((F=E.current)!=null&&F.closest("[popover]")){const te=window.innerHeight-K.bottom-16,X=K.top-16;ne.style.maxHeight=`${Math.max(60,te,X)}px`;const ie=ne.getBoundingClientRect();ne.style.left=`${Math.max(12,Math.min(K.right-ie.width,window.innerWidth-ie.width-12))}px`,ne.style.top=`${Math.max(12,ie.height<=te?K.bottom+4:K.top-ie.height-4)}px`;return}const se=(ce=(G=(H=E.current)==null?void 0:H.closest("[data-flow-toolbar-scroll]"))==null?void 0:G.parentElement)==null?void 0:ce.getBoundingClientRect(),W=se??K;ne.style.maxHeight=`${Math.max(60,Math.max(W.top-40,window.innerHeight-W.bottom-40))}px`;const ue=ne.getBoundingClientRect();ne.style.left=`${Math.max(12,Math.min(Math.max((se==null?void 0:se.left)??12,K.right-ue.width),((se==null?void 0:se.right)??window.innerWidth-12)-ue.width,window.innerWidth-ue.width-12))}px`,ne.style.top=`${Math.max(12,W.top>=ue.height+36?W.top-ue.height-24:Math.min(W.bottom+24,window.innerHeight-ue.height-12))}px`},$=()=>{try{return localStorage.getItem(`flow:panel-position:${m}`)}catch{return null}},D=()=>{var se,W,ue,q,F,H;if(n)return;if(R.current&&!R.current.matches(":popover-open")&&!$()&&delete R.current.dataset.flowPanelMoved,(se=R.current)==null||se.showPopover(),N(),a){(ue=(W=R.current)==null?void 0:W.querySelector("input"))==null||ue.focus({preventScroll:!0});return}const K=(q=R.current)==null?void 0:q.querySelectorAll('[role="option"]:not(:disabled)');(H=((F=R.current)==null?void 0:F.querySelector('[aria-selected="true"]:not(:disabled)'))??(K==null?void 0:K[0]))==null||H.focus()};j.useLayoutEffect(()=>{u!==void 0&&(u?D():_())},[u]),j.useEffect(()=>{if(P){if(n){_();return}return N(),window.addEventListener("resize",N),window.addEventListener("scroll",N,!0),()=>{window.removeEventListener("resize",N),window.removeEventListener("scroll",N,!0)}}},[P,n,l]);const T=`var(--chakra-colors-${b.replace(".","-")})`;return f.jsxs(f.Fragment,{children:[f.jsx(Ge,{label:i??m,children:f.jsx(V.chakra.button,{...g,ref:E,type:"button",role:"combobox","data-flow-select-icon":s?"":void 0,"aria-label":m,title:i??m,"aria-haspopup":a?"dialog":"listbox","aria-expanded":P,"aria-controls":S,disabled:n,h:"30px",w:"160px",px:"6px",fontSize:"12px",border:"none",borderRadius:"4px",bg:"transparent",color:s?v:w,display:"flex",alignItems:"center",justifyContent:s?"center":"space-between",gap:2,style:o,onClick:()=>{M(),P?_():D()},onKeyDown:K=>{["ArrowDown","ArrowUp"].includes(K.key)&&(K.preventDefault(),D())},children:s??f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((Z=k.find(K=>K.value===r))==null?void 0:Z.label)??r}),f.jsx(ee.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),f.jsxs(V.chakra.div,{ref:R,id:S,"data-flow-select-pinned":l?"":void 0,"data-flow-floating-panel":d&&l?"":void 0,role:a?"dialog":"listbox","aria-label":m,position:"fixed",m:0,p:2,minW:"180px",maxW:"calc(100vw - 24px)",gridTemplateColumns:c&&a?"minmax(0, 1fr)":void 0,gridTemplateRows:c&&a?`${d&&l?"auto ":""}minmax(0, 1fr) auto`:void 0,overflowY:c&&a?"hidden":"auto",bg:b,color:w,borderRadius:"30px",css:{"&:popover-open":{display:c&&a?"grid":void 0},scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"},'& [role="option"]':ho,'& details [role="option"]:first-child':{borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},...gr(T,`var(--chakra-colors-${(C?x:"gray.300").replace(".","-")})`)},onKeyDown:K=>{var W,ue,q;if(a&&!["Escape","Tab"].includes(K.key))return;const ne=[...K.currentTarget.querySelectorAll('[role="option"]:not(:disabled), [data-flow-menu-action]:not(:disabled)')],se=ne.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(K.key)){K.preventDefault();const F=K.key==="Home"?0:K.key==="End"?ne.length-1:(se+(K.key==="ArrowDown"?1:-1)+ne.length)%ne.length;(W=ne[F])==null||W.focus()}else if(K.key==="Escape"||K.key==="Tab"){if(K.key==="Tab"&&l)return;K.key==="Escape"&&(K.preventDefault(),K.stopPropagation()),_(),(ue=E.current)==null||ue.focus()}else K.key.length===1&&K.key!==" "&&((q=ne.find((F,H)=>{var G;return H>se&&((G=F.textContent)==null?void 0:G.toLowerCase().startsWith(K.key.toLowerCase()))}))==null||q.focus())},children:[d&&l&&f.jsx(xb,{label:m}),a??k.map(K=>f.jsxs(V.chakra.button,{type:"button",role:"option","aria-selected":K.value===r,disabled:K.disabled,tabIndex:-1,display:"flex",alignItems:"center",gap:3,px:3,py:2,w:"100%",fontSize:"sm",textAlign:"left",bg:"transparent",color:w,_hover:{bg:C?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:C?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var ne;l||(_(),(ne=E.current)==null||ne.focus()),t(K.value)},children:[f.jsx("span",{style:{flex:1},children:K.label}),f.jsx(ee.PiCheck,{size:16,color:`var(--chakra-colors-${w.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:K.value===r?"visible":"hidden"}})]},K.value)),c]})]})}const ho={borderRadius:"4px","&:first-child":{borderTopLeftRadius:"22px",borderTopRightRadius:"22px"},"&:last-child":{borderBottomLeftRadius:"22px",borderBottomRightRadius:"22px"}},Ne=j.forwardRef(function({icon:r,rememberAction:t=!0,...n},o){const{colorMode:i}=He(),s=Object.fromEntries(Object.entries(n).filter(([c])=>c!=="id"&&c!=="aria-describedby"&&!c.startsWith("data-")&&!/^on(Pointer|Mouse|Focus|Blur)/.test(c))),a=jo(f.jsx(Ge,{label:n.title??n["aria-label"]??"Last used action",children:f.jsx(Ne,{...s,icon:r})}),t&&!!n.onClick);return f.jsx(V.IconButton,{ref:o,_hover:{bg:i==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:n.title??n["aria-label"],...n,onClick:c=>{var l;a(),(l=n.onClick)==null||l.call(n,c)},children:r})}),dn=j.forwardRef(function(r,t){const{themeColor:n}=He();return f.jsx(Ge,{label:"Close",children:f.jsx(Ne,{ref:t,size:"sm",variant:"plain",bg:"transparent",_hover:{bg:"transparent",color:n},color:n,focusRingColor:n,...r,"aria-label":r["aria-label"]??"Close selection tools",icon:f.jsx(ee.PiXLight,{size:20,"aria-hidden":"true"})})})});function vb({onBeforeExpand:e}={}){const{allNodesIconLabel:r,setAllNodesIconLabel:t}=He();return f.jsx(on,{label:"Collapse all",hideLabel:!0,checked:r,icon:f.jsx(ee.PiArrowsInLineVertical,{size:20}),onChange:n=>{n||e==null||e(),t(n)}})}function on({label:e,icon:r,checked:t,onChange:n,disabled:o,hideLabel:i=!1,helper:s=e}){const{themeColor:a,readOnly:c}=He(),{colorInactive:l}=at();return f.jsx(Ge,{label:s,children:f.jsx(Ne,{"aria-label":e,"aria-pressed":t,icon:f.jsxs(f.Fragment,{children:[r,!i&&f.jsx(V.Text,{as:"span",fontSize:"16px",fontWeight:t?"bold":"normal",whiteSpace:"nowrap",children:e})]}),size:"sm",variant:"ghost",width:"auto",px:2,gap:2,color:t?a:l,disabled:o||c,onClick:()=>n(!t)})})}function wb({label:e="Compact layout"}={}){const{compactPropertyLayout:r,setCompactPropertyLayout:t,callbacks:n}=He();return f.jsx(on,{hideLabel:!0,label:e,checked:r,icon:f.jsx(V.Icon,{as:ee.PiArrowsIn,boxSize:5}),onChange:o=>{var i;t(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const Ow=xo.default.input`
8
8
  appearance: none;
9
9
  width: 100%;
10
10
  height: 24px;
@@ -55,7 +55,7 @@
55
55
  cursor: default;
56
56
  opacity: 0.5;
57
57
  }
58
- `,Fd=j.forwardRef(function({style:r,...t},n){return f.jsx(Ow,{...t,ref:n,style:{...r,backgroundImage:"none","--flow-range-track":(r==null?void 0:r.backgroundImage)??"none"}})});function Bu({label:e,inputLabel:r,value:t,displayValue:n,min:o,max:i,step:s=5,onChange:a,onChangeEnd:c}){const l=j.useId(),{readOnly:d,themeColor:u}=Ue(),{colorInactive:h}=at(),p=(t-o)/(i-o)*100,m=u.includes(".")?`var(--chakra-colors-${u.replace(".","-")})`:u;return f.jsxs("div",{style:{width:224,maxWidth:"calc(100vw - 64px)",padding:12},children:[f.jsxs("label",{htmlFor:l,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",f.jsx("span",{children:n})]}),f.jsx(Fd,{id:l,"aria-label":r,type:"range",min:o,max:i,step:s,value:t,disabled:d,style:{color:m,accentColor:m,backgroundImage:`linear-gradient(to right, currentColor ${p}%, var(--chakra-colors-${h.replace(".","-")}) ${p}%)`},onChange:g=>a(Number(g.target.value)),onPointerUp:c,onKeyUp:c,onBlur:c})]})}const Du={dot:{label:"Dots",icon:Q.PiDotsNine},grid:{label:"Grid",icon:Q.PiGridFour},steel:{label:"Steel",icon:Q.PiLineSegments},none:{label:"Solid",icon:Q.PiSquareFill},transparent:{label:"Transparent",icon:Q.PiSelection}};function wb(){const{spacing:e,setSpacing:r,edgeRadius:t,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:s,readOnly:a,config:c}=Ue(),l=Du[o].icon;return f.jsxs(f.Fragment,{children:[f.jsx(Nn,{}),f.jsx(It,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:f.jsx(Q.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:a,onValueChange:()=>{},popupContent:f.jsx(Bu,{label:"Spacing",inputLabel:"Node spacing percentage",min:c.nodeGridSpacing==="layout"?0:50,max:200,value:Math.round(e*100),displayValue:`${Math.round(e*100)}%`,onChange:d=>{var u;r(d/100),(u=s.onSpacingChange)==null||u.call(s,d/100)}}),children:f.jsx("option",{value:"spacing",children:"Spacing"})}),f.jsx(Nn,{}),f.jsx(It,{"aria-label":"Edge radius",title:`Edge radius: ${t??"Default"}`,icon:f.jsx(Q.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:a,onValueChange:()=>{},popupContent:f.jsx(Bu,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:t??500,displayValue:t??"Default",onChange:d=>{var u;n(d),(u=s.onEdgeRadiusChange)==null||u.call(s,d)}}),children:f.jsx("option",{value:"radius",children:"Edge radius"})}),f.jsx(Nn,{}),f.jsxs(It,{"aria-label":"Background variant",title:`Background: ${Du[o].label}`,icon:f.jsx(l,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:a,onValueChange:d=>{var u;i(d),(u=s.onBackgroundVariantChange)==null||u.call(s,d)},children:[f.jsx("option",{value:"dot",children:"Dots"}),f.jsx("option",{value:"grid",children:"Grid"}),f.jsx("option",{value:"steel",children:"Steel"}),f.jsx("option",{value:"none",children:"Solid"}),f.jsx("option",{value:"transparent",children:"Transparent"})]})]})}function Cb(){var o;const{engineRef:e,nodeGridOptions:r,readOnly:t}=Ue(),n=!!(r!=null&&r.fill);return f.jsx(on,{label:"Grid adjustment",hideLabel:!0,helper:n?"Grid adjustment":"Enable Collision and Fill to adjust the Grid",icon:f.jsx(Q.PiArrowsHorizontal,{size:20}),checked:n&&!!((o=r==null?void 0:r.adjustment)!=null&&o.enabled),disabled:!n,onChange:i=>{var s;t||!(r!=null&&r.fill)||(s=e.current)==null||s.setNodeGridMode(!0,{...r,adjustment:{...r.adjustment,enabled:i}})}})}function so({fillOnly:e=!1}={}){const{engineRef:r,nodeGridOptions:t,lastNodeGridOptions:n,readOnly:o,themeColor:i,callbacks:s,config:a}=Ue(),{colorText:c,colorInactive:l}=at(),d=t??n,u=typeof d.gaps=="object"?d.gaps.x:d.gaps??d.margin??15,h=Math.max(200,u),p=m=>{var g;return(g=r.current)==null?void 0:g.setNodeGridMode(!0,{...d,...m})};return f.jsxs(f.Fragment,{children:[!e&&a.bottomBarCollision!==!1&&f.jsx(on,{label:"Collision mode",hideLabel:!0,icon:f.jsx(Q.PiGridFour,{size:20}),checked:t!==null,onChange:m=>{var g,y;((g=s.onNodeGridModeRequest)==null?void 0:g.call(s,m,d))!==!0&&((y=r.current)==null||y.setNodeGridMode(m,d))}}),(t||a.bottomBarFill===!0)&&f.jsxs(W.HStack,{role:"group","aria-label":"Collision settings",gap:2,flexShrink:0,children:[!e&&t&&a.nodeGridSpacing!=="layout"&&f.jsxs(f.Fragment,{children:[f.jsx(W.Box,{width:"96px",flexShrink:0,display:"flex",alignItems:"center",children:f.jsx(Fd,{type:"range","aria-label":"Collision gap",title:`Gap: ${u}`,min:0,max:h,step:5,value:u,disabled:o,style:{color:Me(i),backgroundImage:`linear-gradient(to right, currentColor ${u/h*100}%, ${Me(l)} ${u/h*100}%)`},onChange:m=>p({gaps:Number(m.target.value)})})}),f.jsx(W.Text,{fontSize:"xs",color:c,width:"28px",textAlign:"right",fontVariantNumeric:"tabular-nums",children:u})]}),a.bottomBarFill!==!1&&f.jsx(on,{label:"Fill",hideLabel:!0,helper:t?"Fill available canvas space":"Enable Collision mode to use Fill",icon:f.jsx(Q.PiArrowsOut,{size:18}),checked:!!t&&!!d.fill,disabled:!t,onChange:m=>{var g,y;!t&&((g=s.onNodeGridModeRequest)==null?void 0:g.call(s,!0,{...d,fill:m}))===!0||m&&((y=s.onNodeGridFillRequest)==null?void 0:y.call(s,{...d,fill:m}))===!0||p({fill:m})}}),!e&&t&&d.fill&&f.jsx(Cb,{})]})]})}function zd(e,r){const t=JSON.parse(e);let n=512;const o=(s,a=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!s||typeof s!="object"||Array.isArray(s))throw new Error("Expected a JSON Schema object.");const c=new Set(["$schema","$id","$defs","definitions","$ref","title","description","default","examples","type","properties","required","items","enum","const","anyOf","additionalProperties"]);for(const d of Object.keys(s))if(!c.has(d))throw new Error(`Unsupported JSON Schema keyword: ${d}`);const l=["$schema","$id","$defs","definitions","title","description","default","examples"];if(s.$ref){if(Object.keys(s).some(u=>!["$ref","title","description"].includes(u)))throw new Error("Use $ref without sibling constraints.");if(typeof s.$ref!="string"||!s.$ref.startsWith("#/")||a.includes(s.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let d=t;for(const u of s.$ref.slice(2).split("/")){const h=u.replace(/~1/g,"/").replace(/~0/g,"~");if(!d||!Object.prototype.hasOwnProperty.call(d,h))throw new Error(`Unresolved reference: ${s.$ref}`);d=d[h]}return o(d,[...a,s.$ref])}if(s.anyOf){if(!Array.isArray(s.anyOf)||!s.anyOf.length||Object.keys(s).some(d=>d!=="anyOf"&&!l.includes(d)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:s.anyOf.map(d=>o(d,a))}}if(Object.prototype.hasOwnProperty.call(s,"const")||s.enum){if(Object.keys(s).some(h=>![...l,"const","enum","type"].includes(h))||s.enum&&Object.prototype.hasOwnProperty.call(s,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const d=Object.prototype.hasOwnProperty.call(s,"const")?[s.const]:s.enum;if(!Array.isArray(d)||!d.length)throw new Error("Expected a nonempty enum.");return{kind:"union",types:d.map(h=>{if(h!==null&&!["string","number","boolean"].includes(typeof h))throw new Error("Only primitive literals are supported.");const p=h===null?"null":typeof h;if(s.type&&!(Array.isArray(s.type)?s.type:[s.type]).some(m=>m===p||m==="integer"&&Number.isInteger(h)))throw new Error("Literal does not match its declared type.");return{kind:"literal",value:h}})}}if(Array.isArray(s.type)){if(!s.type.length||s.type.some(d=>typeof d!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(s).some(d=>d!=="type"&&!l.includes(d)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:s.type.map(d=>o({type:d},a))}}if((s.properties||s.required||s.additionalProperties!==void 0)&&s.type!=="object"&&s.type!==void 0)throw new Error("Object constraints require an object type.");if(s.items&&s.type!=="array")throw new Error("items requires an array type.");if(s.type==="object"||s.properties){if(s.additionalProperties!==void 0&&s.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!s.properties||typeof s.properties!="object"||Array.isArray(s.properties))throw new Error("Object schemas must declare properties.");if(s.required!==void 0&&(!Array.isArray(s.required)||s.required.some(u=>typeof u!="string"||!Object.prototype.hasOwnProperty.call(s.properties,u))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(s.properties).map(([u,h])=>[u,{type:o(h,a),optional:!(s.required??[]).includes(u)}]))}}if(s.type==="array")return{kind:"array",items:o(s.items,a)};if(["string","number","integer","boolean","null"].includes(s.type))return{kind:s.type};throw new Error("Every property must declare a supported type.")},i=o(t);if(i.kind!=="object")throw new Error("The root schema must be an object keyed by node ID.");if(Object.values(i.properties).some(s=>s.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:r,nodes:i.properties}}async function Bd(e,r,t,n={}){var m;let o=512;const i=await import("typescript"),s=i.createSourceFile(r,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),a=s.parseDiagnostics;if(a!=null&&a.length)throw new Error("Invalid TypeScript syntax.");const c=new Map;for(const g of s.statements){if(!i.isInterfaceDeclaration(g)&&!i.isTypeAliasDeclaration(g))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((m=g.typeParameters)!=null&&m.length||c.has(g.name.text))throw new Error("Generics and duplicate declarations are not supported.");c.set(g.name.text,g)}const l=(g,y)=>{var C;const b={},x=g.find(S=>i.isIndexSignatureDeclaration(S));let v;if(x&&n.allowJson&&i.isIndexSignatureDeclaration(x)){if(g.filter(S=>i.isIndexSignatureDeclaration(S)).length!==1||x.parameters.length!==1||((C=x.parameters[0].type)==null?void 0:C.kind)!==i.SyntaxKind.StringKeyword||!x.type)throw new Error("Only one string-keyed index signature is supported for forms.");v=u(x.type,y)}return{kind:"object",properties:Object.fromEntries(g.filter(S=>S!==x||!v).map(S=>{if(!i.isPropertySignature(S)||!S.type||!S.name||!i.isIdentifier(S.name)&&!i.isStringLiteral(S.name))throw new Error("Only explicitly typed named properties are supported.");const E=u(S.type,y),M=n.allowJson?i.getJSDocTags(S).filter(P=>P.tagName.text==="port"):[];if(M.length>1)throw new Error(`Duplicate port declaration: ${S.name.text}`);if(M.length){const[P,T,k]=String(M[0].comment??"").trim().split(/\s+/);if(P!=="config"||!T||k||!c.has(T))throw new Error(`Config port ${S.name.text} requires @port config ResourceType`);const R=E.kind==="array";if((E.kind==="array"?E.items.kind:E.kind)!=="string")throw new Error(`Config port ${S.name.text} must be a string or string array reference`);b[S.name.text]={kind:"config",resourceType:T,multiple:R}}return[S.name.text,{type:E,optional:!!S.questionToken}]})),...v?{additionalProperties:v}:{},...Object.keys(b).length?{ports:b}:{}}},d=(g,y)=>{var C;if(y.includes(g))throw new Error("Recursive types are not supported.");const b=c.get(g);if(!b)throw new Error(`Unknown type: ${g}`);let x;if(i.isInterfaceDeclaration(b)){if((C=b.heritageClauses)!=null&&C.length)throw new Error("Interface inheritance is not supported; declare properties explicitly.");x=l(b.members,[...y,g])}else x=u(b.type,[...y,g]);const v=n.allowJson?i.getJSDocTags(b).filter(S=>S.tagName.text==="port"):[];if(!v.length)return x;if(x.kind!=="object")throw new Error("Node ports require an object interface");const w={...x.ports};for(const S of v){const[E,M,...P]=String(S.comment??"").trim().split(/\s+/);if(!["input","output","error"].includes(E)||!/^[A-Za-z][\w-]*$/.test(M??""))throw new Error("Node ports require @port input|output|error Name");const T=P.length?JSON.parse(P.join(" ")):void 0;if(T!==void 0&&typeof T!="string")throw new Error("Node port labels must be JSON strings");if(Object.prototype.hasOwnProperty.call(w,M))throw new Error(`Duplicate port declaration: ${M}`);w[M]={kind:E,...typeof T=="string"?{label:T}:{}}}return{...x,ports:w}},u=(g,y)=>{var b,x,v;if(--o<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(g.kind===i.SyntaxKind.StringKeyword)return{kind:"string"};if(g.kind===i.SyntaxKind.NumberKeyword)return{kind:"number"};if(g.kind===i.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[i.SyntaxKind.AnyKeyword,i.SyntaxKind.UnknownKeyword].includes(g.kind))return{kind:"json"};if(i.isParenthesizedTypeNode(g))return u(g.type,y);if(i.isUnionTypeNode(g))return{kind:"union",types:g.types.map(w=>u(w,y))};if(i.isArrayTypeNode(g))return{kind:"array",items:u(g.elementType,y)};if(i.isTypeLiteralNode(g))return l(g.members,y);if(i.isLiteralTypeNode(g)){const w=g.literal;if(i.isStringLiteral(w))return{kind:"literal",value:w.text};if(i.isNumericLiteral(w))return{kind:"literal",value:Number(w.text)};if(w.kind===i.SyntaxKind.NullKeyword)return{kind:"null"};if(w.kind===i.SyntaxKind.TrueKeyword||w.kind===i.SyntaxKind.FalseKeyword)return{kind:"literal",value:w.kind===i.SyntaxKind.TrueKeyword}}if(i.isTypeReferenceNode(g)&&i.isIdentifier(g.typeName)){if(n.allowJson&&g.typeName.text==="Record"&&!c.has("Record")&&((b=g.typeArguments)==null?void 0:b.length)===2&&g.typeArguments[0].kind===i.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:u(g.typeArguments[1],y)};if(g.typeName.text==="Array"&&((x=g.typeArguments)==null?void 0:x.length)===1)return{kind:"array",items:u(g.typeArguments[0],y)};if(!((v=g.typeArguments)!=null&&v.length))return d(g.typeName.text,y)}throw new Error(`Unsupported TypeScript type: ${g.getText(s)}`)},h=t??(c.has("Graph")?"Graph":c.size===1?[...c.keys()][0]:void 0);if(!h)throw new Error("Declare an interface Graph keyed by node ID.");const p=d(h,[]);if(p.kind!=="object")throw new Error("Graph must be an object keyed by node ID.");return p}async function Sb(e,r){const t=await Bd(e,r);if(Object.values(t.properties).some(n=>n.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:r,nodes:t.properties}}function jn(e,r){if(e.kind==="json"||r.kind==="json"||e.kind==="object"&&e.additionalProperties||r.kind==="object"&&r.additionalProperties)return!1;if(e.kind==="union")return e.types.every(t=>jn(t,r));if(r.kind==="union")return r.types.some(t=>jn(e,t));if(e.kind==="literal"){if(r.kind==="literal")return e.value===r.value;const t=e.value===null?"null":typeof e.value;return r.kind===t||r.kind==="integer"&&typeof e.value=="number"&&Number.isInteger(e.value)}return e.kind==="integer"&&r.kind==="number"?!0:e.kind==="array"&&r.kind==="array"?jn(e.items,r.items):e.kind==="object"&&r.kind==="object"?Object.entries(r.properties).every(([t,n])=>{const o=Object.prototype.hasOwnProperty.call(e.properties,t)?e.properties[t]:void 0;return o?(n.optional||!o.optional)&&jn(o.type,n.type):n.optional}):e.kind===r.kind}function Dd(e,r){if(!r.sourceProperty&&!r.targetProperty)return;const t=(s,a)=>{var d;const c=Object.prototype.hasOwnProperty.call(e.nodes,s)?s:s.replace(/^root\./,""),l=Object.prototype.hasOwnProperty.call(e.nodes,c)?(d=e.nodes[c])==null?void 0:d.type:void 0;return a&&(l==null?void 0:l.kind)==="object"&&Object.prototype.hasOwnProperty.call(l.properties,a)?l.properties[a]:void 0},n=t(r.source,r.sourceProperty),o=t(r.target,r.targetProperty);if(!n||!o)return"Unverified: source or target property is missing from the interface.";const i=s=>s.kind==="json"||s.kind==="object"&&(!!s.additionalProperties||Object.values(s.properties).some(a=>i(a.type)))||s.kind==="array"&&i(s.items)||s.kind==="union"&&s.types.some(i);if(i(n.type)||i(o.type))return"Unverified: arbitrary JSON or dictionary fields require runtime validation.";if(n.optional&&!o.optional)return"Optional source cannot supply a required target property.";if(!jn(n.type,o.type))return`Incompatible property types: ${r.sourceProperty} -> ${r.targetProperty}.`}async function jb(e){if(e.size>256*1024)throw new Error("Interface must be 256 KB or smaller.");const r=await e.text();if(/\.json$/i.test(e.name))return zd(r,e.name);if(/\.ts$/i.test(e.name))return Sb(r,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Wu=new WeakMap;function an(e){if(!e||typeof e!="object")return e;const r=Wu.get(e);if(r)return r;const t=()=>{throw new Error("Form callback data is read-only. Return edits instead.")},n=new Proxy(Array.isArray(e)?[]:{},{get:(o,i)=>an(Reflect.get(e,i)),has:(o,i)=>Reflect.has(e,i),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(o,i)=>{const s=Reflect.getOwnPropertyDescriptor(e,i);return s&&{...s,value:an(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:t,deleteProperty:t,defineProperty:t,setPrototypeOf:t,preventExtensions:t});return Wu.set(e,n),n}function un(e,r,t){var o;const n=r.split(".");for(let i=n.length;i>0;i--){const s=n.slice(0,i).join("."),a=(o=Oe(e,s))==null?void 0:o.$form;if(!(a!=null&&a.$type))continue;let c=Object.prototype.hasOwnProperty.call(t,a.$type)?t[a.$type]:void 0;for(const u of n.slice(i))(c==null?void 0:c.kind)==="array"&&/^\d+$/.test(u)?c=c.items:(c==null?void 0:c.kind)==="object"?c=Object.prototype.hasOwnProperty.call(c.properties,u)?c.properties[u].type:void 0:c=void 0;if((c==null?void 0:c.kind)!=="object")return;const l=n.slice(i).join("."),d=Object.fromEntries(Object.entries(a.$fields??{}).filter(([u])=>!l||u.startsWith(`${l}.`)).map(([u,h])=>[l?u.slice(l.length+1):u,h]));return{type:c,fields:d,binding:a}}}async function Wd(e,r){if(e.size>256*1024)throw new Error("Form schema exceeds 256 KB.");const t=await e.text();if(e.name.endsWith(".ts")){if(!r.length||r.length>32)throw new Error("Choose between 1 and 32 form interface names.");const o=[],i=new Set(r);for(const s of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const a=await Bd(t,e.name,s,{allowJson:!0});o.push([s,a]);for(const c of Object.values(a.ports??{}))c.resourceType&&i.add(c.resourceType)}return Object.fromEntries(o)}if(!e.name.endsWith(".json"))throw new Error("Choose a .ts interface or .json schema file.");const n=zd(t,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([o,i])=>[o,i.type]))}function Eo(e,r){return!e||("$in"in e?e.$in.includes(Oe(r,e.$address)):Oe(r,e.$address)===e.$equals)}function On(e){const r=e.kind==="array"?e.items:e,t=r.kind==="union"?r.types:[r];if(t.every(n=>n.kind==="literal"))return t.map(n=>({label:String(n.value),value:n.value}))}function Jt(e,r,t){if(r===void 0||r==="")return t?"Required":void 0;if(e.kind==="json"){const n=new Set,o=i=>{if(i===null||typeof i=="string"||typeof i=="boolean")return!0;if(typeof i=="number")return Number.isFinite(i);if(!i||typeof i!="object"||n.has(i)||!Array.isArray(i)&&![Object.prototype,null].includes(Object.getPrototypeOf(i)))return!1;n.add(i);const s=Object.values(i).every(o);return n.delete(i),s};return o(r)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!Jt(n,r,!0))?void 0:"Choose a valid value";if(e.kind==="literal")return r===e.value?void 0:"Choose a valid value";if(e.kind==="array")return Array.isArray(r)&&r.every(n=>!Jt(e.items,n,!0))?void 0:"Invalid list value";if(e.kind==="object")return!r||typeof r!="object"||Array.isArray(r)?"Expected an object":e.additionalProperties&&Object.entries(r).some(([n,o])=>!Object.prototype.hasOwnProperty.call(e.properties,n)&&Jt(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>Jt(o.type,r[n],!o.optional))?"Invalid object fields":void 0;if(e.kind==="null")return r===null?void 0:"Expected null";if(e.kind==="integer")return Number.isInteger(r)?void 0:"Expected a whole number";if(typeof r!==e.kind||typeof r=="number"&&!Number.isFinite(r))return`Expected ${e.kind}`}function Vu(e,r){const t=r.address.split(".");if(t.shift()!=="root"||!t.length||t.some(a=>!a||["__proto__","prototype","constructor","#"].includes(a)))throw new Error("Invalid form field address.");const n=t.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(t.some(a=>a.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...t].join("."),s=Oe(e,i);if(!s||typeof s!="object")throw new Error(`Missing form parent: ${i}`);if(o){if(r.op==="set"&&typeof r.value!="string")throw new Error("Node colors must be strings.");return kt(e,i,n,r.op==="remove"?void 0:r.value)}return Pt(e,i,a=>{const c=Array.isArray(a.$)?a.$:a;if(r.op==="remove"&&!Object.prototype.hasOwnProperty.call(c,n)||r.op==="set"&&Object.is(c[n],r.value))return a;const l=Array.isArray(c)?[...c]:{...c};if(Array.isArray(l)&&(!/^(0|[1-9]\d*)$/.test(n)||Number(n)>=l.length))throw new Error("Invalid array address.");return r.op==="remove"?Array.isArray(l)?l.splice(Number(n),1):delete l[n]:Object.defineProperty(l,n,{value:structuredClone(r.value),enumerable:!0,writable:!0,configurable:!0}),c===a?l:{...a,$:l}})}function _o(e,r,t){let n=Vu(e,r.value===void 0?{op:"remove",address:r.address}:{op:"set",address:r.address,value:r.value});const o=t==null?void 0:t({...r,previousValue:an(Oe(e,r.address)),data:an(n)});if(o&&!Array.isArray(o))throw new Error("Form change handlers must return edits synchronously.");for(const i of Array.isArray(o)?o:[]){if(i.op!=="set"&&i.op!=="remove")throw new Error("Unsupported form edit.");n=Vu(n,i)}return n}const $n="data:image/svg+xml;base64,";function wr(e){if(e.startsWith($n))return!0;try{const r=new URL(e);return(r.protocol==="https:"||r.protocol==="http:")&&!r.username&&!r.password}catch{return!1}}async function $w(e){if(e.size>256*1024)throw new Error("SVG must be 256 KB or smaller.");const r=await e.text(),t=new DOMParser().parseFromString(r,"image/svg+xml");if(t.doctype||t.querySelector("parsererror")||t.documentElement.localName!=="svg"||t.documentElement.namespaceURI!=="http://www.w3.org/2000/svg")throw new Error("Choose a valid SVG file.");if(t.querySelector("script, foreignObject")||[...t.querySelectorAll("*")].some(i=>[...i.attributes].some(s=>/^on/i.test(s.name))))throw new Error("SVG scripts and event handlers are not allowed.");const n=new TextEncoder().encode(r);let o="";for(const i of n)o+=String.fromCharCode(i);return $n+btoa(o)}const cr=({name:e,svg:r=!1,...t})=>{const[n,o]=j.useState(null),[i,s]=j.useState(!0),[a,c]=j.useState(!1),l=typeof e=="string"&&wr(e);if(j.useEffect(()=>{if(l||!e||e.length<2){o(null),s(!1);return}s(!0),c(!1),(async()=>{try{let u;if(e.startsWith("Md"))u="md";else if(e.startsWith("Fa"))u="fa6";else if(e.startsWith("Io5"))u="io5";else if(e.startsWith("Io"))u="io";else if(e.startsWith("Ti"))u="ti";else if(e.startsWith("Go"))u="go";else if(e.startsWith("Fi"))u="fi";else if(e.startsWith("Di"))u="di";else if(e.startsWith("Ai"))u="ai";else if(e.startsWith("Bs"))u="bs";else if(e.startsWith("Ri"))u="ri";else if(e.startsWith("Fc"))u="fc";else if(e.startsWith("Gi"))u="gi";else if(e.startsWith("Hi2"))u="hi2";else if(e.startsWith("Hi"))u="hi";else if(e.startsWith("Si"))u="si";else if(e.startsWith("Sl"))u="sl";else if(e.startsWith("Im"))u="im";else if(e.startsWith("Bi"))u="bi";else if(e.startsWith("Pi"))u="pi";else if(e.startsWith("Vsc"))u="vsc";else if(e.startsWith("Tb"))u="tb";else if(e.startsWith("Tfi"))u="tfi";else if(e.startsWith("Cg"))u="cg";else if(e.startsWith("Lia"))u="lia";else if(e.startsWith("Lu"))u="lu";else throw new Error(`Unknown library prefix for icon: ${e}`);let h;switch(u){case"md":h=await import("react-icons/md");break;case"fa6":h=await import("react-icons/fa6");break;case"io5":h=await import("react-icons/io5");break;case"io":h=await import("react-icons/io");break;case"ti":h=await import("react-icons/ti");break;case"go":h=await import("react-icons/go");break;case"fi":h=await import("react-icons/fi");break;case"di":h=await import("react-icons/di");break;case"ai":h=await import("react-icons/ai");break;case"bs":h=await import("react-icons/bs");break;case"ri":h=await import("react-icons/ri");break;case"fc":h=await import("react-icons/fc");break;case"gi":h=await import("react-icons/gi");break;case"hi2":h=await import("react-icons/hi2");break;case"hi":h=await import("react-icons/hi");break;case"si":h=await import("react-icons/si");break;case"sl":h=await import("react-icons/sl");break;case"im":h=await import("react-icons/im");break;case"bi":h=await import("react-icons/bi");break;case"pi":h=await import("react-icons/pi");break;case"vsc":h=await import("react-icons/vsc");break;case"tb":h=await import("react-icons/tb");break;case"tfi":h=await import("react-icons/tfi");break;case"cg":h=await import("react-icons/cg");break;case"lia":h=await import("react-icons/lia");break;case"lu":h=await import("react-icons/lu");break;default:throw new Error(`Unsupported library: ${u}`)}const p=h[e];if(!p)throw new Error(`Icon ${e} not found in library ${u}`);o(()=>p)}catch(u){console.warn(`Failed to load icon ${e}:`,u.message),c(!0),o(null)}finally{s(!1)}})()},[e,l]),l){const{size:d=80,style:u,...h}=t;return r?f.jsx("image",{...h,href:e,width:d,height:d,preserveAspectRatio:"xMidYMid meet",style:u}):f.jsx("img",{...h,src:e,alt:"",width:d,height:d,referrerPolicy:"no-referrer",style:{objectFit:"contain",...u}})}return i||!n?null:f.jsx(n,{...t})};function qw(e,r){let t=e;for(const n of r){if(n.op!=="set"&&n.op!=="remove")throw new Error("Unsupported state edit.");const o=n.address.split(".");if(o.some(s=>s.startsWith("$")||["__proto__","prototype","constructor"].includes(s)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;zn(i),t=_o(t,{address:n.address,nodeAddress:o.slice(0,-1).join("."),value:i})}return zn(t),t}function Hn(e,r,t){const n=Object.prototype.hasOwnProperty.call(e,r)?e[r]:void 0;if(!(!n||!t||!Object.prototype.hasOwnProperty.call(t,n.type)))return{address:n.address,type:t[n.type],fields:n.fields??{}}}function zn(e){if(!(!e||typeof e!="object"))for(const[r,t]of Object.entries(e)){if(r.startsWith("$")||["__proto__","prototype","constructor"].includes(r))throw new Error(`Form state cannot contain view metadata or unsafe keys: ${r}`);zn(t)}}function Lw(e,r,t){zn(r.value);const n=_o(e,r,t);return zn(n),n}function Eb(e,r){const t=(n,o="")=>{if(!n||typeof n!="object")return n;if(["$label","$subtitle","$content","$icon","$bgColor","$textColor","$borderColor"].includes(o)&&typeof n.$state=="string"){const s=Oe(r,n.$state);return s==null?"":typeof s=="object"?JSON.stringify(s,null,2):String(s)}let i=n;for(const[s,a]of Object.entries(n)){const c=t(a,s);c!==a&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,s,{value:c,enumerable:!0,writable:!0,configurable:!0}))}return i};return t(e)}const Fw=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),zw=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,En=(e,r)=>JSON.stringify([e,r]);function Bn(e,r){if(e.kind==="union"){const t=e.types.find(n=>n.kind===(Array.isArray(r)?"array":r===null?"null":typeof r)||n.kind==="literal"&&Object.is(n.value,r));return Bn(t??e.types.find(n=>n.kind!=="null")??e.types[0]??{kind:"json"},r)}return e.kind!=="json"?e:Array.isArray(r)?{kind:"array",items:{kind:"json"}}:r!==null&&typeof r=="object"||r===void 0?{kind:"object",properties:{},additionalProperties:{kind:"json"}}:{kind:r===null?"null":typeof r}}function _n(e){const r=Bn(e,void 0);return r.kind==="object"?{}:r.kind==="array"?[]:r.kind==="literal"?r.value:r.kind==="number"||r.kind==="integer"?0:r.kind==="boolean"?!1:r.kind==="null"?null:""}function Gu(e){return e.kind==="json"?[{kind:"string"},{kind:"number"},{kind:"boolean"},{kind:"null"},{kind:"object",properties:{},additionalProperties:{kind:"json"}},{kind:"array",items:{kind:"json"}}]:e.kind==="union"&&!On(e)?e.types:[e]}function Bw(e,r,t){if(r.address===t.address)return;const n=Oe(e,r.address),o=(i,s)=>s===void 0?!1:i.kind==="union"?i.types.some(a=>o(a,s)):i.kind==="array"?Array.isArray(s)&&s.every(a=>o(i.items,a)):i.kind==="object"?!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(i.properties).every(([a,c])=>c.optional&&s[a]===void 0||o(c.type,s[a]))&&Object.entries(s).every(([a,c])=>Object.prototype.hasOwnProperty.call(i.properties,a)||!i.additionalProperties||o(i.additionalProperties,c)):s===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!Jt(i,s,!0);if(o(t.type,n))return structuredClone(n)}function _b(e,r,t,n){var c,l;const o={sourceSchema:t,sourceBindings:r,nodes:[],edges:[],schema:{...t},bindings:{...r},slots:new Map,containers:new Map},i=new Set(n.map(d=>d.data.id)),s=new Map(n.flatMap(d=>{const u=r[d.data.id];return u&&t[u.type]?[[u.address,d.data.id]]:[]})),a=(d,u,h,p,m,g=!1)=>{var E,M,P,T,k;if(m>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const y=Oe(e,u),b=Bn(h,y),x=b.kind!=="object"&&b.kind!=="array";o.containers.set(d,{address:u,type:b,declared:h,scalar:x});const v=`__form:${d}`,w={...(E=o.bindings[d])==null?void 0:E.fields},C={kind:"object",properties:{},ports:{...b.kind==="object"?b.ports:{},...g?{resource:{label:"output",...b.kind==="object"?(M=b.ports)==null?void 0:M.resource:{},kind:"output"}}:{}}},S=b.kind==="object"?{...b.properties,...Object.fromEntries(Object.keys(y??{}).filter(R=>!Object.prototype.hasOwnProperty.call(b.properties,R)&&b.additionalProperties).map(R=>[R,{type:b.additionalProperties,optional:!0}]))}:b.kind==="array"?Object.fromEntries((Array.isArray(y)?y:[]).map((R,_)=>[String(_),{type:b.items,optional:!0}])):{value:{type:On(h)?h:b,optional:!1}};for(const[R,_]of Object.entries(S)){if(!Fw(R))throw new Error(`Unsupported structured property key: ${R}`);const N=x?u:`${u}.${R}`,$=Oe(e,N),V=Bn(_.type,$),I=V.kind==="object"||V.kind==="array",F=(P=C.ports)==null?void 0:P[R],oe=(F==null?void 0:F.kind)==="config"&&(((T=w[R])==null?void 0:T.$options)||On(_.type)),se=_.type.kind==="json"||_.type.kind==="union"&&!On(_.type);if(((k=w[R])==null?void 0:k.$control)==="upload"||!I&&b.kind!=="array"&&(!se||x)||oe){C.properties[R]={..._,type:_.type.kind==="json"?V:_.type};continue}const H=s.get(N)??zw(N),ee=b.kind==="array"?`Item ${Number(R)+1}`:R,ue={address:N,owner:d,field:R,type:_.type,label:ee,nodeId:H,present:$!==void 0};if(o.slots.set(En(d,R),ue),C.ports[R]={kind:"config",resourceType:`__form:${H}`},$===void 0||(o.edges.push({data:{id:`__form-edge:${d}:${R}`,source:H,target:d,sourceProperty:"output:resource",targetProperty:`config:${R}`,isEdgeDashed:!0}}),o.containers.has(H)||s.has(N)))continue;if(i.has(H))throw new Error(`Structured node identity conflict: ${H}`);i.add(H);const q={data:{id:H,type:"objectView",label:ee,headerTitle:ee,description:{},config:{form:!0,icon:V.kind==="array"?"PiListNumbers":I?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push(q),a(H,N,_.type,p,m+1,!0);const D=o.schema[`__form:${H}`];q.data.description=Object.fromEntries(Object.keys(D.properties).map(K=>[K,Oe(e,V.kind==="array"||V.kind==="object"?`${N}.${K}`:N)]).filter(([,K])=>K!==void 0))}o.schema[v]=C,o.bindings[d]={...o.bindings[d],address:u,type:v,fields:w}};for(const d of n){const u=r[d.data.id];if(u!=null&&u.portResources)continue;const h=u&&t[u.type];!u||!h||Oe(e,u.address)===void 0||a(d.data.id,u.address,h,(c=d.data.viewProps)==null?void 0:c.bgColor,0,o.edges.some(p=>p.data.source===d.data.id))}for(const d of o.edges){const u=o.bindings[d.data.source],h=o.schema[u.type].ports;h.resource={...h.resource,kind:"output",label:((l=h.resource)==null?void 0:l.label)??"output"}}return o}const Br=(e="reference")=>({kind:e,text:"",paths:[""]}),kb=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(r=>["__proto__","constructor","prototype"].includes(r));function Dw(e,r){const t=new Set(r.map(s=>s.path)),n=s=>{if(!s.paths.length||s.paths.some(a=>!kb(a)||!t.has(a)))throw new Error("Choose an available reference.");return[...s.paths,...s.fallback===void 0?[]:[JSON.stringify(s.fallback)]].join(" || ")},o=s=>{if(s.includes("{{")||s.includes("}}"))throw new Error("Use a reference part for dynamic values.");return s},i=s=>s.map(a=>{if(a.kind==="text")return o(a.text);if(a.kind==="conditional"){if(a.paths.length!==1||a.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(a)}}}${o(a.text)}{{/if}}`}return`{{${n(a)}}}`}).join("");if(e.mode==="reference"||e.mode==="condition"){if(e.parts.length!==1||e.parts[0].kind!=="reference")throw new Error("Choose one reference binding.");const s=i(e.parts);return e.mode==="condition"?`${s} == ${JSON.stringify(e.comparison)}`:s}if(e.mode==="json"){const s=e.fields.map(a=>a.key);if(!s.length||new Set(s).size!==s.length||s.some(a=>!a||["__proto__","constructor","prototype"].includes(a)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(a=>[a.key,i(a.parts)])))}return i(e.parts)}async function Ww(e){const r=await import("typescript"),t=s=>{const a=r.createSourceFile("binding.ts",`(${s})`,r.ScriptTarget.Latest,!0,r.ScriptKind.TS);if(a.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const c=a.statements[0];if(!c||!r.isExpressionStatement(c))throw new Error("Unsupported reference expression.");const l=Br();l.paths=[];const d=u=>{if(r.isParenthesizedExpression(u))return d(u.expression);if(r.isBinaryExpression(u)&&u.operatorToken.kind===r.SyntaxKind.BarBarToken){d(u.left),d(u.right);return}if(r.isStringLiteral(u)){if(l.fallback!==void 0)throw new Error("Multiple fallback values.");l.fallback=u.text;return}const h=u.getText(a);if(!kb(h)||l.fallback!==void 0)throw new Error("Unsupported reference expression.");l.paths.push(h)};if(d(c.expression),!l.paths.length)throw new Error("A binding needs a reference.");return l},n=s=>{const a=[];let c=0;const l=/\{\{([\s\S]*?)\}\}/g;for(const d of s.matchAll(l)){const u=d.index;if(u<c)continue;u>c&&a.push({...Br("text"),text:s.slice(c,u)});const h=d[1].trim();if(h.startsWith("#if ")){const p=s.indexOf("{{/if}}",u+d[0].length);if(p<0)throw new Error("Unclosed condition.");a.push({...t(h.slice(4)),kind:"conditional",text:s.slice(u+d[0].length,p)}),c=p+7}else a.push(t(h)),c=u+d[0].length}return c<s.length&&a.push({...Br("text"),text:s.slice(c)}),a},o={mode:"reference",parts:[Br()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const s=JSON.parse(e);if(s&&typeof s=="object"&&!Array.isArray(s)&&Object.values(s).every(a=>typeof a=="string"))return{...o,mode:"json",fields:Object.entries(s).map(([a,c])=>({key:a,parts:n(c)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const s=r.createSourceFile("condition.ts",`value ${i[1].text}`,r.ScriptTarget.Latest,!0,r.ScriptKind.TS),a=s.statements[0];if(s.statements.length===1&&r.isExpressionStatement(a)&&r.isBinaryExpression(a.expression)&&a.expression.operatorToken.kind===r.SyntaxKind.EqualsEqualsToken&&r.isStringLiteral(a.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:a.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function Hu({parts:e,references:r,onChange:t,disabled:n}){const o=(i,s)=>t(e.map((a,c)=>c===i?{...a,...s}:a));return f.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,s)=>f.jsxs("fieldset",{"data-binding-part":s,style:{border:0,padding:0,margin:0,minWidth:0},children:[f.jsxs("legend",{children:["Part ",s+1]}),f.jsxs("div",{style:{display:"flex",gap:8},children:[f.jsxs("span",{"data-form-select":"",style:{flex:1},children:[f.jsxs("select",{"aria-label":"Part type",disabled:n,value:i.kind,onChange:a=>o(s,{kind:a.target.value}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"text",children:"Text"}),f.jsx("option",{value:"conditional",children:"Conditional text"})]}),f.jsx(Q.PiCaretDown,{size:16,"aria-hidden":"true"})]}),f.jsx(Ne,{"aria-label":`Remove part ${s+1}`,title:"Remove part",icon:f.jsx(Q.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t(e.filter((a,c)=>c!==s))})]}),i.kind!=="text"&&f.jsxs(f.Fragment,{children:[i.paths.map((a,c)=>f.jsxs("label",{children:["Reference ",c+1,f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":`Reference ${c+1}`,disabled:n,value:a,onChange:l=>o(s,{paths:i.paths.map((d,u)=>u===c?l.target.value:d)}),children:[f.jsx("option",{value:"",children:"Select reference"}),r.map(l=>f.jsx("option",{value:l.path,children:l.label},l.path))]}),f.jsx(Q.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},c)),i.kind==="reference"&&f.jsxs(f.Fragment,{children:[f.jsx(Ne,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:f.jsx(Q.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>o(s,{paths:[...i.paths,""]})}),f.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center"},children:[f.jsx("input",{type:"checkbox","aria-label":"Default value enabled",disabled:n,checked:i.fallback!==void 0,onChange:a=>o(s,{fallback:a.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&f.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:a=>o(s,{fallback:a.target.value})})]})]}),i.kind!=="reference"&&f.jsxs("label",{children:["Text",f.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:a=>o(s,{text:a.target.value})})]})]},s)),f.jsx(Ne,{"aria-label":"Add part",title:"Add part",icon:f.jsx(Q.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t([...e,Br()])})]})}function Vw({label:e,value:r,references:t,disabled:n,onChange:o}){const[i,s]=j.useState(),[a,c]=j.useState(""),[l,d]=j.useState(!1),u=async()=>{d(!0),c("");try{s(await Ww(typeof r=="string"?r:""))}catch(h){c(h instanceof Error?h.message:"Unable to read binding.")}finally{d(!1)}};return f.jsxs("div",{"data-runtime-binding":e,style:{marginBottom:8},children:[f.jsx(Ne,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:f.jsx(Q.PiLink,{size:18}),size:"sm",variant:"ghost",disabled:n||l,onClick:u}),typeof r=="string"&&r.includes("{{")&&f.jsx("span",{children:"Bound value"}),i&&f.jsxs("fieldset",{disabled:n,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Binding mode",f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":"Binding mode",value:i.mode,onChange:h=>s({...i,mode:h.target.value,parts:[Br()]}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"condition",children:"Equals"}),f.jsx("option",{value:"template",children:"Text template"}),f.jsx("option",{value:"json",children:"JSON output"})]}),f.jsx(Q.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),i.mode==="json"?f.jsxs(f.Fragment,{children:[i.fields.map((h,p)=>f.jsxs("fieldset",{"data-output-field":p,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Output field name",f.jsx("input",{"aria-label":"Output field name",value:h.key,onChange:m=>s({...i,fields:i.fields.map((g,y)=>y===p?{...g,key:m.target.value}:g)})})]}),f.jsx(Hu,{parts:h.parts,references:t,disabled:n,onChange:m=>s({...i,fields:i.fields.map((g,y)=>y===p?{...g,parts:m}:g)})}),f.jsx(Ne,{"aria-label":"Remove output field",title:"Remove output field",icon:f.jsx(Q.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:i.fields.filter((m,g)=>g!==p)})})]},p)),f.jsx(Ne,{"aria-label":"Add output field",title:"Add output field",icon:f.jsx(Q.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:[...i.fields,{key:"",parts:[Br()]}]})})]}):f.jsx(Hu,{parts:i.parts,references:t,disabled:n,onChange:h=>s({...i,parts:h})}),i.mode==="condition"&&f.jsxs("label",{children:["Equals",f.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:h=>s({...i,comparison:h.target.value})})]}),f.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[f.jsx(Ne,{"aria-label":"Apply binding",title:"Apply binding",icon:f.jsx(Q.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(Dw(i,t)),s(void 0),c("")}catch(h){c(h instanceof Error?h.message:"Unable to apply binding.")}}}),f.jsx(Ne,{"aria-label":"Cancel binding",title:"Cancel binding",icon:f.jsx(Q.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{s(void 0),c("")}})]})]}),a&&f.jsx("p",{role:"alert",children:a})]})}function Gw({nodeAddress:e,onOpen:r}){const{structured:t,data:n,callbacks:o,editable:i,onFieldCreate:s}=j.useContext($t),a=Ue(),[c,l]=j.useState(""),[d,u]=j.useState("0"),[h,p]=j.useState(""),m=t==null?void 0:t.containers.get(e);if(!m||!n||!t)return null;const g=a.readOnly||a.config.editable===!1||!i,y=Oe(n,m.address),b=Gu(m.declared),x=m.type.kind==="array"?m.type.items:m.type.kind==="object"?m.type.additionalProperties:void 0,v=x?Gu(x):[],w=!!s&&m.type.kind==="object"&&(x==null?void 0:x.kind)==="json",C=_=>_.kind==="literal"?String(_.value):_.kind==="string"?"Text":Dt(_.kind),S=[...t.slots.values()].filter(_=>_.owner===e),E=(_,N)=>{var $;return($=o.onFormChange)==null?void 0:$.call(o,{data:n,nodeAddress:m.address,address:_,previousValue:Oe(n,_),value:N})},M=_=>{var N;a.setSelectedNodeIds([_]),(N=a.engineRef.current)==null||N.focusNode(_,90,!1)},P=(_,N)=>{if(!Array.isArray(y))return;const $=[...y];[$[_],$[_+N]]=[$[_+N],$[_]],E(m.address,$)},T=()=>{const _=v[Number(d)]??v[0];if(_)if(m.type.kind==="array")E(m.address,[...Array.isArray(y)?y:[],_n(_)]);else{if(!c||c.includes(".")||c.startsWith("$")||["__proto__","constructor","prototype"].includes(c)){p("Choose a property name without dots or reserved prefixes.");return}if(Object.prototype.hasOwnProperty.call(y,c)){p("Property already exists.");return}w&&(d==="file"||d==="files")?s==null||s({data:n,nodeAddress:m.address,address:`${m.address}.${c}`,previousValue:void 0,value:d==="files"?[]:""},{$control:"upload"}):E(`${m.address}.${c}`,_n(_)),l(""),p("")}},k=m.type.kind==="object"&&!!m.type.additionalProperties,R=m.type.kind==="array";return f.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[b.length>1&&f.jsxs("label",{children:["Value type",f.jsx("span",{"data-form-select":"",style:{display:"block"},children:f.jsx(It,{"aria-label":"Value type",disabled:g,value:String(b.findIndex(_=>Bn(_,y).kind===m.type.kind)),onValueChange:_=>E(m.address,_n(b[Number(_)])),children:b.map((_,N)=>f.jsx("option",{value:N,children:C(_)},N))})})]}),S.map((_,N)=>f.jsxs("div",{"data-structured-slot":_.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[_.type.kind==="array"?f.jsx(Q.PiListNumbers,{size:20}):f.jsx(Q.PiBracketsCurly,{size:20}),f.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:Dt(_.label)}),f.jsx(Ne,{"aria-label":`${_.present?r?"Edit":"Focus":"Create"} ${Dt(_.label)}`,title:`${_.present?r?"Edit":"Focus":"Create"} ${Dt(_.label)}`,icon:_.present?f.jsx(Q.PiMagnifyingGlass,{size:18}):f.jsx(Q.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:g&&!_.present,onClick:$=>{var V;_.present?r?r(_.nodeId):((V=$.currentTarget.closest("dialog"))==null||V.close(),M(_.nodeId)):E(_.address,_n(_.type))}}),R&&f.jsxs(f.Fragment,{children:[f.jsx(Ne,{"aria-label":`Move item ${N+1} up`,icon:f.jsx(Q.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:g||N===0,onClick:()=>P(N,-1)}),f.jsx(Ne,{"aria-label":`Move item ${N+1} down`,icon:f.jsx(Q.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:g||N===S.length-1,onClick:()=>P(N,1)})]}),_.present&&f.jsx(Ne,{"aria-label":`Remove ${Dt(_.label)}`,icon:f.jsx(Q.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:g,onClick:()=>R?E(m.address,y.filter(($,V)=>V!==N)):E(_.address,void 0)})]},_.address)),(R||k)&&f.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[k&&f.jsxs("label",{style:{flex:"1 1 120px",minWidth:0,display:"grid",gap:8},children:["Property name",f.jsx("input",{"aria-label":"Property name",placeholder:"Required",value:c,disabled:g,onChange:_=>l(_.target.value)})]}),v.length>1&&f.jsxs("label",{style:{flex:"1 1 100px",minWidth:0,display:"grid",gap:8},children:["New value type",f.jsx("span",{"data-form-select":"",style:{display:"block"},children:f.jsxs(It,{"aria-label":"New value type",value:d,disabled:g,onValueChange:u,children:[v.map((_,N)=>f.jsx("option",{value:N,children:C(_)},N)),w&&f.jsx("option",{value:"file",children:"File"}),w&&f.jsx("option",{value:"files",children:"Files"})]})})]}),f.jsx("span",{style:{display:"flex",alignItems:"center",flexShrink:0,...k||v.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:f.jsx(Ne,{"aria-label":R?"Add item":"Add property",icon:f.jsx(Q.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:g,onClick:T})})]}),h&&f.jsx("p",{role:"alert",children:h})]})}const $t=j.createContext({callbacks:{}}),no=xo.default.div`
58
+ `,Fd=j.forwardRef(function({style:r,...t},n){return f.jsx(Ow,{...t,ref:n,style:{...r,backgroundImage:"none","--flow-range-track":(r==null?void 0:r.backgroundImage)??"none"}})});function Du({label:e,inputLabel:r,value:t,displayValue:n,min:o,max:i,step:s=5,onChange:a,onChangeEnd:c}){const l=j.useId(),{readOnly:d,themeColor:u}=He(),{colorInactive:h}=at(),p=(t-o)/(i-o)*100,m=u.includes(".")?`var(--chakra-colors-${u.replace(".","-")})`:u;return f.jsxs("div",{style:{width:224,maxWidth:"calc(100vw - 64px)",padding:12},children:[f.jsxs("label",{htmlFor:l,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",f.jsx("span",{children:n})]}),f.jsx(Fd,{id:l,"aria-label":r,type:"range",min:o,max:i,step:s,value:t,disabled:d,style:{color:m,accentColor:m,backgroundImage:`linear-gradient(to right, currentColor ${p}%, var(--chakra-colors-${h.replace(".","-")}) ${p}%)`},onChange:g=>a(Number(g.target.value)),onPointerUp:c,onKeyUp:c,onBlur:c})]})}const Wu={dot:{label:"Dots",icon:ee.PiDotsNine},grid:{label:"Grid",icon:ee.PiGridFour},steel:{label:"Steel",icon:ee.PiLineSegments},none:{label:"Solid",icon:ee.PiSquareFill},transparent:{label:"Transparent",icon:ee.PiSelection}};function Cb(){const{spacing:e,setSpacing:r,edgeRadius:t,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:s,readOnly:a,config:c}=He(),l=Wu[o].icon;return f.jsxs(f.Fragment,{children:[f.jsx(Nn,{}),f.jsx(It,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:f.jsx(ee.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:a,onValueChange:()=>{},popupContent:f.jsx(Du,{label:"Spacing",inputLabel:"Node spacing percentage",min:c.nodeGridSpacing==="layout"?0:50,max:200,value:Math.round(e*100),displayValue:`${Math.round(e*100)}%`,onChange:d=>{var u;r(d/100),(u=s.onSpacingChange)==null||u.call(s,d/100)}}),children:f.jsx("option",{value:"spacing",children:"Spacing"})}),f.jsx(Nn,{}),f.jsx(It,{"aria-label":"Edge radius",title:`Edge radius: ${t??"Default"}`,icon:f.jsx(ee.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:a,onValueChange:()=>{},popupContent:f.jsx(Du,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:t??500,displayValue:t??"Default",onChange:d=>{var u;n(d),(u=s.onEdgeRadiusChange)==null||u.call(s,d)}}),children:f.jsx("option",{value:"radius",children:"Edge radius"})}),f.jsx(Nn,{}),f.jsxs(It,{"aria-label":"Background variant",title:`Background: ${Wu[o].label}`,icon:f.jsx(l,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:a,onValueChange:d=>{var u;i(d),(u=s.onBackgroundVariantChange)==null||u.call(s,d)},children:[f.jsx("option",{value:"dot",children:"Dots"}),f.jsx("option",{value:"grid",children:"Grid"}),f.jsx("option",{value:"steel",children:"Steel"}),f.jsx("option",{value:"none",children:"Solid"}),f.jsx("option",{value:"transparent",children:"Transparent"})]})]})}function Sb(){var o;const{engineRef:e,nodeGridOptions:r,readOnly:t}=He(),n=!!(r!=null&&r.fill);return f.jsx(on,{label:"Grid adjustment",hideLabel:!0,helper:n?"Grid adjustment":"Enable Collision and Fill to adjust the Grid",icon:f.jsx(ee.PiArrowsHorizontal,{size:20}),checked:n&&!!((o=r==null?void 0:r.adjustment)!=null&&o.enabled),disabled:!n,onChange:i=>{var s;t||!(r!=null&&r.fill)||(s=e.current)==null||s.setNodeGridMode(!0,{...r,adjustment:{...r.adjustment,enabled:i}})}})}function so({fillOnly:e=!1}={}){const{engineRef:r,nodeGridOptions:t,lastNodeGridOptions:n,readOnly:o,themeColor:i,callbacks:s,config:a}=He(),{colorText:c,colorInactive:l}=at(),d=t??n,u=typeof d.gaps=="object"?d.gaps.x:d.gaps??d.margin??15,h=Math.max(200,u),p=m=>{var g;return(g=r.current)==null?void 0:g.setNodeGridMode(!0,{...d,...m})};return f.jsxs(f.Fragment,{children:[!e&&a.bottomBarCollision!==!1&&f.jsx(on,{label:"Collision mode",hideLabel:!0,icon:f.jsx(ee.PiGridFour,{size:20}),checked:t!==null,onChange:m=>{var g,y;((g=s.onNodeGridModeRequest)==null?void 0:g.call(s,m,d))!==!0&&((y=r.current)==null||y.setNodeGridMode(m,d))}}),(t||a.bottomBarFill===!0)&&f.jsxs(V.HStack,{role:"group","aria-label":"Collision settings",gap:2,flexShrink:0,children:[!e&&t&&a.nodeGridSpacing!=="layout"&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{width:"96px",flexShrink:0,display:"flex",alignItems:"center",children:f.jsx(Fd,{type:"range","aria-label":"Collision gap",title:`Gap: ${u}`,min:0,max:h,step:5,value:u,disabled:o,style:{color:Te(i),backgroundImage:`linear-gradient(to right, currentColor ${u/h*100}%, ${Te(l)} ${u/h*100}%)`},onChange:m=>p({gaps:Number(m.target.value)})})}),f.jsx(V.Text,{fontSize:"xs",color:c,width:"28px",textAlign:"right",fontVariantNumeric:"tabular-nums",children:u})]}),a.bottomBarFill!==!1&&f.jsx(on,{label:"Fill",hideLabel:!0,helper:t?"Fill available canvas space":"Enable Collision mode to use Fill",icon:f.jsx(ee.PiArrowsOut,{size:18}),checked:!!t&&!!d.fill,disabled:!t,onChange:m=>{var g,y;!t&&((g=s.onNodeGridModeRequest)==null?void 0:g.call(s,!0,{...d,fill:m}))===!0||m&&((y=s.onNodeGridFillRequest)==null?void 0:y.call(s,{...d,fill:m}))===!0||p({fill:m})}}),!e&&t&&d.fill&&f.jsx(Sb,{})]})]})}function zd(e,r){const t=JSON.parse(e);let n=512;const o=(s,a=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!s||typeof s!="object"||Array.isArray(s))throw new Error("Expected a JSON Schema object.");const c=new Set(["$schema","$id","$defs","definitions","$ref","title","description","default","examples","type","properties","required","items","enum","const","anyOf","additionalProperties"]);for(const d of Object.keys(s))if(!c.has(d))throw new Error(`Unsupported JSON Schema keyword: ${d}`);const l=["$schema","$id","$defs","definitions","title","description","default","examples"];if(s.$ref){if(Object.keys(s).some(u=>!["$ref","title","description"].includes(u)))throw new Error("Use $ref without sibling constraints.");if(typeof s.$ref!="string"||!s.$ref.startsWith("#/")||a.includes(s.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let d=t;for(const u of s.$ref.slice(2).split("/")){const h=u.replace(/~1/g,"/").replace(/~0/g,"~");if(!d||!Object.prototype.hasOwnProperty.call(d,h))throw new Error(`Unresolved reference: ${s.$ref}`);d=d[h]}return o(d,[...a,s.$ref])}if(s.anyOf){if(!Array.isArray(s.anyOf)||!s.anyOf.length||Object.keys(s).some(d=>d!=="anyOf"&&!l.includes(d)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:s.anyOf.map(d=>o(d,a))}}if(Object.prototype.hasOwnProperty.call(s,"const")||s.enum){if(Object.keys(s).some(h=>![...l,"const","enum","type"].includes(h))||s.enum&&Object.prototype.hasOwnProperty.call(s,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const d=Object.prototype.hasOwnProperty.call(s,"const")?[s.const]:s.enum;if(!Array.isArray(d)||!d.length)throw new Error("Expected a nonempty enum.");return{kind:"union",types:d.map(h=>{if(h!==null&&!["string","number","boolean"].includes(typeof h))throw new Error("Only primitive literals are supported.");const p=h===null?"null":typeof h;if(s.type&&!(Array.isArray(s.type)?s.type:[s.type]).some(m=>m===p||m==="integer"&&Number.isInteger(h)))throw new Error("Literal does not match its declared type.");return{kind:"literal",value:h}})}}if(Array.isArray(s.type)){if(!s.type.length||s.type.some(d=>typeof d!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(s).some(d=>d!=="type"&&!l.includes(d)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:s.type.map(d=>o({type:d},a))}}if((s.properties||s.required||s.additionalProperties!==void 0)&&s.type!=="object"&&s.type!==void 0)throw new Error("Object constraints require an object type.");if(s.items&&s.type!=="array")throw new Error("items requires an array type.");if(s.type==="object"||s.properties){if(s.additionalProperties!==void 0&&s.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!s.properties||typeof s.properties!="object"||Array.isArray(s.properties))throw new Error("Object schemas must declare properties.");if(s.required!==void 0&&(!Array.isArray(s.required)||s.required.some(u=>typeof u!="string"||!Object.prototype.hasOwnProperty.call(s.properties,u))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(s.properties).map(([u,h])=>[u,{type:o(h,a),optional:!(s.required??[]).includes(u)}]))}}if(s.type==="array")return{kind:"array",items:o(s.items,a)};if(["string","number","integer","boolean","null"].includes(s.type))return{kind:s.type};throw new Error("Every property must declare a supported type.")},i=o(t);if(i.kind!=="object")throw new Error("The root schema must be an object keyed by node ID.");if(Object.values(i.properties).some(s=>s.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:r,nodes:i.properties}}async function Bd(e,r,t,n={}){var m;let o=512;const i=await import("typescript"),s=i.createSourceFile(r,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),a=s.parseDiagnostics;if(a!=null&&a.length)throw new Error("Invalid TypeScript syntax.");const c=new Map;for(const g of s.statements){if(!i.isInterfaceDeclaration(g)&&!i.isTypeAliasDeclaration(g))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((m=g.typeParameters)!=null&&m.length||c.has(g.name.text))throw new Error("Generics and duplicate declarations are not supported.");c.set(g.name.text,g)}const l=(g,y)=>{var C;const b={},x=g.find(S=>i.isIndexSignatureDeclaration(S));let w;if(x&&n.allowJson&&i.isIndexSignatureDeclaration(x)){if(g.filter(S=>i.isIndexSignatureDeclaration(S)).length!==1||x.parameters.length!==1||((C=x.parameters[0].type)==null?void 0:C.kind)!==i.SyntaxKind.StringKeyword||!x.type)throw new Error("Only one string-keyed index signature is supported for forms.");w=u(x.type,y)}return{kind:"object",properties:Object.fromEntries(g.filter(S=>S!==x||!w).map(S=>{if(!i.isPropertySignature(S)||!S.type||!S.name||!i.isIdentifier(S.name)&&!i.isStringLiteral(S.name))throw new Error("Only explicitly typed named properties are supported.");const E=u(S.type,y),R=n.allowJson?i.getJSDocTags(S).filter(P=>P.tagName.text==="port"):[];if(R.length>1)throw new Error(`Duplicate port declaration: ${S.name.text}`);if(R.length){const[P,I,M]=String(R[0].comment??"").trim().split(/\s+/);if(P!=="config"||!I||M||!c.has(I))throw new Error(`Config port ${S.name.text} requires @port config ResourceType`);const k=E.kind==="array";if((E.kind==="array"?E.items.kind:E.kind)!=="string")throw new Error(`Config port ${S.name.text} must be a string or string array reference`);b[S.name.text]={kind:"config",resourceType:I,multiple:k}}return[S.name.text,{type:E,optional:!!S.questionToken}]})),...w?{additionalProperties:w}:{},...Object.keys(b).length?{ports:b}:{}}},d=(g,y)=>{var C;if(y.includes(g))throw new Error("Recursive types are not supported.");const b=c.get(g);if(!b)throw new Error(`Unknown type: ${g}`);let x;if(i.isInterfaceDeclaration(b)){if((C=b.heritageClauses)!=null&&C.length)throw new Error("Interface inheritance is not supported; declare properties explicitly.");x=l(b.members,[...y,g])}else x=u(b.type,[...y,g]);const w=n.allowJson?i.getJSDocTags(b).filter(S=>S.tagName.text==="port"):[];if(!w.length)return x;if(x.kind!=="object")throw new Error("Node ports require an object interface");const v={...x.ports};for(const S of w){const[E,R,...P]=String(S.comment??"").trim().split(/\s+/);if(!["input","output","error"].includes(E)||!/^[A-Za-z][\w-]*$/.test(R??""))throw new Error("Node ports require @port input|output|error Name");const I=P.length?JSON.parse(P.join(" ")):void 0;if(I!==void 0&&typeof I!="string")throw new Error("Node port labels must be JSON strings");if(Object.prototype.hasOwnProperty.call(v,R))throw new Error(`Duplicate port declaration: ${R}`);v[R]={kind:E,...typeof I=="string"?{label:I}:{}}}return{...x,ports:v}},u=(g,y)=>{var b,x,w;if(--o<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(g.kind===i.SyntaxKind.StringKeyword)return{kind:"string"};if(g.kind===i.SyntaxKind.NumberKeyword)return{kind:"number"};if(g.kind===i.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[i.SyntaxKind.AnyKeyword,i.SyntaxKind.UnknownKeyword].includes(g.kind))return{kind:"json"};if(i.isParenthesizedTypeNode(g))return u(g.type,y);if(i.isUnionTypeNode(g))return{kind:"union",types:g.types.map(v=>u(v,y))};if(i.isArrayTypeNode(g))return{kind:"array",items:u(g.elementType,y)};if(i.isTypeLiteralNode(g))return l(g.members,y);if(i.isLiteralTypeNode(g)){const v=g.literal;if(i.isStringLiteral(v))return{kind:"literal",value:v.text};if(i.isNumericLiteral(v))return{kind:"literal",value:Number(v.text)};if(v.kind===i.SyntaxKind.NullKeyword)return{kind:"null"};if(v.kind===i.SyntaxKind.TrueKeyword||v.kind===i.SyntaxKind.FalseKeyword)return{kind:"literal",value:v.kind===i.SyntaxKind.TrueKeyword}}if(i.isTypeReferenceNode(g)&&i.isIdentifier(g.typeName)){if(n.allowJson&&g.typeName.text==="Record"&&!c.has("Record")&&((b=g.typeArguments)==null?void 0:b.length)===2&&g.typeArguments[0].kind===i.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:u(g.typeArguments[1],y)};if(g.typeName.text==="Array"&&((x=g.typeArguments)==null?void 0:x.length)===1)return{kind:"array",items:u(g.typeArguments[0],y)};if(!((w=g.typeArguments)!=null&&w.length))return d(g.typeName.text,y)}throw new Error(`Unsupported TypeScript type: ${g.getText(s)}`)},h=t??(c.has("Graph")?"Graph":c.size===1?[...c.keys()][0]:void 0);if(!h)throw new Error("Declare an interface Graph keyed by node ID.");const p=d(h,[]);if(p.kind!=="object")throw new Error("Graph must be an object keyed by node ID.");return p}async function jb(e,r){const t=await Bd(e,r);if(Object.values(t.properties).some(n=>n.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:r,nodes:t.properties}}function jn(e,r){if(e.kind==="json"||r.kind==="json"||e.kind==="object"&&e.additionalProperties||r.kind==="object"&&r.additionalProperties)return!1;if(e.kind==="union")return e.types.every(t=>jn(t,r));if(r.kind==="union")return r.types.some(t=>jn(e,t));if(e.kind==="literal"){if(r.kind==="literal")return e.value===r.value;const t=e.value===null?"null":typeof e.value;return r.kind===t||r.kind==="integer"&&typeof e.value=="number"&&Number.isInteger(e.value)}return e.kind==="integer"&&r.kind==="number"?!0:e.kind==="array"&&r.kind==="array"?jn(e.items,r.items):e.kind==="object"&&r.kind==="object"?Object.entries(r.properties).every(([t,n])=>{const o=Object.prototype.hasOwnProperty.call(e.properties,t)?e.properties[t]:void 0;return o?(n.optional||!o.optional)&&jn(o.type,n.type):n.optional}):e.kind===r.kind}function Dd(e,r){if(!r.sourceProperty&&!r.targetProperty)return;const t=(s,a)=>{var d;const c=Object.prototype.hasOwnProperty.call(e.nodes,s)?s:s.replace(/^root\./,""),l=Object.prototype.hasOwnProperty.call(e.nodes,c)?(d=e.nodes[c])==null?void 0:d.type:void 0;return a&&(l==null?void 0:l.kind)==="object"&&Object.prototype.hasOwnProperty.call(l.properties,a)?l.properties[a]:void 0},n=t(r.source,r.sourceProperty),o=t(r.target,r.targetProperty);if(!n||!o)return"Unverified: source or target property is missing from the interface.";const i=s=>s.kind==="json"||s.kind==="object"&&(!!s.additionalProperties||Object.values(s.properties).some(a=>i(a.type)))||s.kind==="array"&&i(s.items)||s.kind==="union"&&s.types.some(i);if(i(n.type)||i(o.type))return"Unverified: arbitrary JSON or dictionary fields require runtime validation.";if(n.optional&&!o.optional)return"Optional source cannot supply a required target property.";if(!jn(n.type,o.type))return`Incompatible property types: ${r.sourceProperty} -> ${r.targetProperty}.`}async function Eb(e){if(e.size>256*1024)throw new Error("Interface must be 256 KB or smaller.");const r=await e.text();if(/\.json$/i.test(e.name))return zd(r,e.name);if(/\.ts$/i.test(e.name))return jb(r,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Vu=new WeakMap;function an(e){if(!e||typeof e!="object")return e;const r=Vu.get(e);if(r)return r;const t=()=>{throw new Error("Form callback data is read-only. Return edits instead.")},n=new Proxy(Array.isArray(e)?[]:{},{get:(o,i)=>an(Reflect.get(e,i)),has:(o,i)=>Reflect.has(e,i),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(o,i)=>{const s=Reflect.getOwnPropertyDescriptor(e,i);return s&&{...s,value:an(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:t,deleteProperty:t,defineProperty:t,setPrototypeOf:t,preventExtensions:t});return Vu.set(e,n),n}function un(e,r,t){var o;const n=r.split(".");for(let i=n.length;i>0;i--){const s=n.slice(0,i).join("."),a=(o=Oe(e,s))==null?void 0:o.$form;if(!(a!=null&&a.$type))continue;let c=Object.prototype.hasOwnProperty.call(t,a.$type)?t[a.$type]:void 0;for(const u of n.slice(i))(c==null?void 0:c.kind)==="array"&&/^\d+$/.test(u)?c=c.items:(c==null?void 0:c.kind)==="object"?c=Object.prototype.hasOwnProperty.call(c.properties,u)?c.properties[u].type:void 0:c=void 0;if((c==null?void 0:c.kind)!=="object")return;const l=n.slice(i).join("."),d=Object.fromEntries(Object.entries(a.$fields??{}).filter(([u])=>!l||u.startsWith(`${l}.`)).map(([u,h])=>[l?u.slice(l.length+1):u,h]));return{type:c,fields:d,binding:a}}}async function Wd(e,r){if(e.size>256*1024)throw new Error("Form schema exceeds 256 KB.");const t=await e.text();if(e.name.endsWith(".ts")){if(!r.length||r.length>32)throw new Error("Choose between 1 and 32 form interface names.");const o=[],i=new Set(r);for(const s of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const a=await Bd(t,e.name,s,{allowJson:!0});o.push([s,a]);for(const c of Object.values(a.ports??{}))c.resourceType&&i.add(c.resourceType)}return Object.fromEntries(o)}if(!e.name.endsWith(".json"))throw new Error("Choose a .ts interface or .json schema file.");const n=zd(t,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([o,i])=>[o,i.type]))}function Eo(e,r){return!e||("$in"in e?e.$in.includes(Oe(r,e.$address)):Oe(r,e.$address)===e.$equals)}function On(e){const r=e.kind==="array"?e.items:e,t=r.kind==="union"?r.types:[r];if(t.every(n=>n.kind==="literal"))return t.map(n=>({label:String(n.value),value:n.value}))}function Jt(e,r,t){if(r===void 0||r==="")return t?"Required":void 0;if(e.kind==="json"){const n=new Set,o=i=>{if(i===null||typeof i=="string"||typeof i=="boolean")return!0;if(typeof i=="number")return Number.isFinite(i);if(!i||typeof i!="object"||n.has(i)||!Array.isArray(i)&&![Object.prototype,null].includes(Object.getPrototypeOf(i)))return!1;n.add(i);const s=Object.values(i).every(o);return n.delete(i),s};return o(r)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!Jt(n,r,!0))?void 0:"Choose a valid value";if(e.kind==="literal")return r===e.value?void 0:"Choose a valid value";if(e.kind==="array")return Array.isArray(r)&&r.every(n=>!Jt(e.items,n,!0))?void 0:"Invalid list value";if(e.kind==="object")return!r||typeof r!="object"||Array.isArray(r)?"Expected an object":e.additionalProperties&&Object.entries(r).some(([n,o])=>!Object.prototype.hasOwnProperty.call(e.properties,n)&&Jt(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>Jt(o.type,r[n],!o.optional))?"Invalid object fields":void 0;if(e.kind==="null")return r===null?void 0:"Expected null";if(e.kind==="integer")return Number.isInteger(r)?void 0:"Expected a whole number";if(typeof r!==e.kind||typeof r=="number"&&!Number.isFinite(r))return`Expected ${e.kind}`}function Gu(e,r){const t=r.address.split(".");if(t.shift()!=="root"||!t.length||t.some(a=>!a||["__proto__","prototype","constructor","#"].includes(a)))throw new Error("Invalid form field address.");const n=t.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(t.some(a=>a.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...t].join("."),s=Oe(e,i);if(!s||typeof s!="object")throw new Error(`Missing form parent: ${i}`);if(o){if(r.op==="set"&&typeof r.value!="string")throw new Error("Node colors must be strings.");return jt(e,i,n,r.op==="remove"?void 0:r.value)}return Pt(e,i,a=>{const c=Array.isArray(a.$)?a.$:a;if(r.op==="remove"&&!Object.prototype.hasOwnProperty.call(c,n)||r.op==="set"&&Object.is(c[n],r.value))return a;const l=Array.isArray(c)?[...c]:{...c};if(Array.isArray(l)&&(!/^(0|[1-9]\d*)$/.test(n)||Number(n)>=l.length))throw new Error("Invalid array address.");return r.op==="remove"?Array.isArray(l)?l.splice(Number(n),1):delete l[n]:Object.defineProperty(l,n,{value:structuredClone(r.value),enumerable:!0,writable:!0,configurable:!0}),c===a?l:{...a,$:l}})}function _o(e,r,t){let n=Gu(e,r.value===void 0?{op:"remove",address:r.address}:{op:"set",address:r.address,value:r.value});const o=t==null?void 0:t({...r,previousValue:an(Oe(e,r.address)),data:an(n)});if(o&&!Array.isArray(o))throw new Error("Form change handlers must return edits synchronously.");for(const i of Array.isArray(o)?o:[]){if(i.op!=="set"&&i.op!=="remove")throw new Error("Unsupported form edit.");n=Gu(n,i)}return n}const $n="data:image/svg+xml;base64,";function wr(e){if(e.startsWith($n))return!0;try{const r=new URL(e);return(r.protocol==="https:"||r.protocol==="http:")&&!r.username&&!r.password}catch{return!1}}async function $w(e){if(e.size>256*1024)throw new Error("SVG must be 256 KB or smaller.");const r=await e.text(),t=new DOMParser().parseFromString(r,"image/svg+xml");if(t.doctype||t.querySelector("parsererror")||t.documentElement.localName!=="svg"||t.documentElement.namespaceURI!=="http://www.w3.org/2000/svg")throw new Error("Choose a valid SVG file.");if(t.querySelector("script, foreignObject")||[...t.querySelectorAll("*")].some(i=>[...i.attributes].some(s=>/^on/i.test(s.name))))throw new Error("SVG scripts and event handlers are not allowed.");const n=new TextEncoder().encode(r);let o="";for(const i of n)o+=String.fromCharCode(i);return $n+btoa(o)}const cr=({name:e,svg:r=!1,...t})=>{const[n,o]=j.useState(null),[i,s]=j.useState(!0),[a,c]=j.useState(!1),l=typeof e=="string"&&wr(e);if(j.useEffect(()=>{if(l||!e||e.length<2){o(null),s(!1);return}s(!0),c(!1),(async()=>{try{let u;if(e.startsWith("Md"))u="md";else if(e.startsWith("Fa"))u="fa6";else if(e.startsWith("Io5"))u="io5";else if(e.startsWith("Io"))u="io";else if(e.startsWith("Ti"))u="ti";else if(e.startsWith("Go"))u="go";else if(e.startsWith("Fi"))u="fi";else if(e.startsWith("Di"))u="di";else if(e.startsWith("Ai"))u="ai";else if(e.startsWith("Bs"))u="bs";else if(e.startsWith("Ri"))u="ri";else if(e.startsWith("Fc"))u="fc";else if(e.startsWith("Gi"))u="gi";else if(e.startsWith("Hi2"))u="hi2";else if(e.startsWith("Hi"))u="hi";else if(e.startsWith("Si"))u="si";else if(e.startsWith("Sl"))u="sl";else if(e.startsWith("Im"))u="im";else if(e.startsWith("Bi"))u="bi";else if(e.startsWith("Pi"))u="pi";else if(e.startsWith("Vsc"))u="vsc";else if(e.startsWith("Tb"))u="tb";else if(e.startsWith("Tfi"))u="tfi";else if(e.startsWith("Cg"))u="cg";else if(e.startsWith("Lia"))u="lia";else if(e.startsWith("Lu"))u="lu";else throw new Error(`Unknown library prefix for icon: ${e}`);let h;switch(u){case"md":h=await import("react-icons/md");break;case"fa6":h=await import("react-icons/fa6");break;case"io5":h=await import("react-icons/io5");break;case"io":h=await import("react-icons/io");break;case"ti":h=await import("react-icons/ti");break;case"go":h=await import("react-icons/go");break;case"fi":h=await import("react-icons/fi");break;case"di":h=await import("react-icons/di");break;case"ai":h=await import("react-icons/ai");break;case"bs":h=await import("react-icons/bs");break;case"ri":h=await import("react-icons/ri");break;case"fc":h=await import("react-icons/fc");break;case"gi":h=await import("react-icons/gi");break;case"hi2":h=await import("react-icons/hi2");break;case"hi":h=await import("react-icons/hi");break;case"si":h=await import("react-icons/si");break;case"sl":h=await import("react-icons/sl");break;case"im":h=await import("react-icons/im");break;case"bi":h=await import("react-icons/bi");break;case"pi":h=await import("react-icons/pi");break;case"vsc":h=await import("react-icons/vsc");break;case"tb":h=await import("react-icons/tb");break;case"tfi":h=await import("react-icons/tfi");break;case"cg":h=await import("react-icons/cg");break;case"lia":h=await import("react-icons/lia");break;case"lu":h=await import("react-icons/lu");break;default:throw new Error(`Unsupported library: ${u}`)}const p=h[e];if(!p)throw new Error(`Icon ${e} not found in library ${u}`);o(()=>p)}catch(u){console.warn(`Failed to load icon ${e}:`,u.message),c(!0),o(null)}finally{s(!1)}})()},[e,l]),l){const{size:d=80,style:u,...h}=t;return r?f.jsx("image",{...h,href:e,width:d,height:d,preserveAspectRatio:"xMidYMid meet",style:u}):f.jsx("img",{...h,src:e,alt:"",width:d,height:d,referrerPolicy:"no-referrer",style:{objectFit:"contain",...u}})}return i||!n?null:f.jsx(n,{...t})};function qw(e,r){let t=e;for(const n of r){if(n.op!=="set"&&n.op!=="remove")throw new Error("Unsupported state edit.");const o=n.address.split(".");if(o.some(s=>s.startsWith("$")||["__proto__","prototype","constructor"].includes(s)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;zn(i),t=_o(t,{address:n.address,nodeAddress:o.slice(0,-1).join("."),value:i})}return zn(t),t}function Hn(e,r,t){const n=Object.prototype.hasOwnProperty.call(e,r)?e[r]:void 0;if(!(!n||!t||!Object.prototype.hasOwnProperty.call(t,n.type)))return{address:n.address,type:t[n.type],fields:n.fields??{}}}function zn(e){if(!(!e||typeof e!="object"))for(const[r,t]of Object.entries(e)){if(r.startsWith("$")||["__proto__","prototype","constructor"].includes(r))throw new Error(`Form state cannot contain view metadata or unsafe keys: ${r}`);zn(t)}}function Lw(e,r,t){zn(r.value);const n=_o(e,r,t);return zn(n),n}function _b(e,r){const t=(n,o="")=>{if(!n||typeof n!="object")return n;if(["$label","$subtitle","$content","$icon","$bgColor","$textColor","$borderColor"].includes(o)&&typeof n.$state=="string"){const s=Oe(r,n.$state);return s==null?"":typeof s=="object"?JSON.stringify(s,null,2):String(s)}let i=n;for(const[s,a]of Object.entries(n)){const c=t(a,s);c!==a&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,s,{value:c,enumerable:!0,writable:!0,configurable:!0}))}return i};return t(e)}const Fw=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),zw=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,En=(e,r)=>JSON.stringify([e,r]);function Bn(e,r){if(e.kind==="union"){const t=e.types.find(n=>n.kind===(Array.isArray(r)?"array":r===null?"null":typeof r)||n.kind==="literal"&&Object.is(n.value,r));return Bn(t??e.types.find(n=>n.kind!=="null")??e.types[0]??{kind:"json"},r)}return e.kind!=="json"?e:Array.isArray(r)?{kind:"array",items:{kind:"json"}}:r!==null&&typeof r=="object"||r===void 0?{kind:"object",properties:{},additionalProperties:{kind:"json"}}:{kind:r===null?"null":typeof r}}function _n(e){const r=Bn(e,void 0);return r.kind==="object"?{}:r.kind==="array"?[]:r.kind==="literal"?r.value:r.kind==="number"||r.kind==="integer"?0:r.kind==="boolean"?!1:r.kind==="null"?null:""}function Hu(e){return e.kind==="json"?[{kind:"string"},{kind:"number"},{kind:"boolean"},{kind:"null"},{kind:"object",properties:{},additionalProperties:{kind:"json"}},{kind:"array",items:{kind:"json"}}]:e.kind==="union"&&!On(e)?e.types:[e]}function Bw(e,r,t){if(r.address===t.address)return;const n=Oe(e,r.address),o=(i,s)=>s===void 0?!1:i.kind==="union"?i.types.some(a=>o(a,s)):i.kind==="array"?Array.isArray(s)&&s.every(a=>o(i.items,a)):i.kind==="object"?!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(i.properties).every(([a,c])=>c.optional&&s[a]===void 0||o(c.type,s[a]))&&Object.entries(s).every(([a,c])=>Object.prototype.hasOwnProperty.call(i.properties,a)||!i.additionalProperties||o(i.additionalProperties,c)):s===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!Jt(i,s,!0);if(o(t.type,n))return structuredClone(n)}function kb(e,r,t,n){var c,l;const o={sourceSchema:t,sourceBindings:r,nodes:[],edges:[],schema:{...t},bindings:{...r},slots:new Map,containers:new Map},i=new Set(n.map(d=>d.data.id)),s=new Map(n.flatMap(d=>{const u=r[d.data.id];return u&&t[u.type]?[[u.address,d.data.id]]:[]})),a=(d,u,h,p,m,g=!1)=>{var E,R,P,I,M;if(m>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const y=Oe(e,u),b=Bn(h,y),x=b.kind!=="object"&&b.kind!=="array";o.containers.set(d,{address:u,type:b,declared:h,scalar:x});const w=`__form:${d}`,v={...(E=o.bindings[d])==null?void 0:E.fields},C={kind:"object",properties:{},ports:{...b.kind==="object"?b.ports:{},...g?{resource:{label:"output",...b.kind==="object"?(R=b.ports)==null?void 0:R.resource:{},kind:"output"}}:{}}},S=b.kind==="object"?{...b.properties,...Object.fromEntries(Object.keys(y??{}).filter(k=>!Object.prototype.hasOwnProperty.call(b.properties,k)&&b.additionalProperties).map(k=>[k,{type:b.additionalProperties,optional:!0}]))}:b.kind==="array"?Object.fromEntries((Array.isArray(y)?y:[]).map((k,_)=>[String(_),{type:b.items,optional:!0}])):{value:{type:On(h)?h:b,optional:!1}};for(const[k,_]of Object.entries(S)){if(!Fw(k))throw new Error(`Unsupported structured property key: ${k}`);const N=x?u:`${u}.${k}`,$=Oe(e,N),D=Bn(_.type,$),T=D.kind==="object"||D.kind==="array",Z=(P=C.ports)==null?void 0:P[k],K=(Z==null?void 0:Z.kind)==="config"&&(((I=v[k])==null?void 0:I.$options)||On(_.type)),ne=_.type.kind==="json"||_.type.kind==="union"&&!On(_.type);if(((M=v[k])==null?void 0:M.$control)==="upload"||!T&&b.kind!=="array"&&(!ne||x)||K){C.properties[k]={..._,type:_.type.kind==="json"?D:_.type};continue}const se=s.get(N)??zw(N),W=b.kind==="array"?`Item ${Number(k)+1}`:k,ue={address:N,owner:d,field:k,type:_.type,label:W,nodeId:se,present:$!==void 0};if(o.slots.set(En(d,k),ue),C.ports[k]={kind:"config",resourceType:`__form:${se}`},$===void 0||(o.edges.push({data:{id:`__form-edge:${d}:${k}`,source:se,target:d,sourceProperty:"output:resource",targetProperty:`config:${k}`,isEdgeDashed:!0}}),o.containers.has(se)||s.has(N)))continue;if(i.has(se))throw new Error(`Structured node identity conflict: ${se}`);i.add(se);const q={data:{id:se,type:"objectView",label:W,headerTitle:W,description:{},config:{form:!0,icon:D.kind==="array"?"PiListNumbers":T?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push(q),a(se,N,_.type,p,m+1,!0);const F=o.schema[`__form:${se}`];q.data.description=Object.fromEntries(Object.keys(F.properties).map(H=>[H,Oe(e,D.kind==="array"||D.kind==="object"?`${N}.${H}`:N)]).filter(([,H])=>H!==void 0))}o.schema[w]=C,o.bindings[d]={...o.bindings[d],address:u,type:w,fields:v}};for(const d of n){const u=r[d.data.id];if(u!=null&&u.portResources)continue;const h=u&&t[u.type];!u||!h||Oe(e,u.address)===void 0||a(d.data.id,u.address,h,(c=d.data.viewProps)==null?void 0:c.bgColor,0,o.edges.some(p=>p.data.source===d.data.id))}for(const d of o.edges){const u=o.bindings[d.data.source],h=o.schema[u.type].ports;h.resource={...h.resource,kind:"output",label:((l=h.resource)==null?void 0:l.label)??"output"}}return o}const Br=(e="reference")=>({kind:e,text:"",paths:[""]}),Pb=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(r=>["__proto__","constructor","prototype"].includes(r));function Dw(e,r){const t=new Set(r.map(s=>s.path)),n=s=>{if(!s.paths.length||s.paths.some(a=>!Pb(a)||!t.has(a)))throw new Error("Choose an available reference.");return[...s.paths,...s.fallback===void 0?[]:[JSON.stringify(s.fallback)]].join(" || ")},o=s=>{if(s.includes("{{")||s.includes("}}"))throw new Error("Use a reference part for dynamic values.");return s},i=s=>s.map(a=>{if(a.kind==="text")return o(a.text);if(a.kind==="conditional"){if(a.paths.length!==1||a.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(a)}}}${o(a.text)}{{/if}}`}return`{{${n(a)}}}`}).join("");if(e.mode==="reference"||e.mode==="condition"){if(e.parts.length!==1||e.parts[0].kind!=="reference")throw new Error("Choose one reference binding.");const s=i(e.parts);return e.mode==="condition"?`${s} == ${JSON.stringify(e.comparison)}`:s}if(e.mode==="json"){const s=e.fields.map(a=>a.key);if(!s.length||new Set(s).size!==s.length||s.some(a=>!a||["__proto__","constructor","prototype"].includes(a)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(a=>[a.key,i(a.parts)])))}return i(e.parts)}async function Ww(e){const r=await import("typescript"),t=s=>{const a=r.createSourceFile("binding.ts",`(${s})`,r.ScriptTarget.Latest,!0,r.ScriptKind.TS);if(a.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const c=a.statements[0];if(!c||!r.isExpressionStatement(c))throw new Error("Unsupported reference expression.");const l=Br();l.paths=[];const d=u=>{if(r.isParenthesizedExpression(u))return d(u.expression);if(r.isBinaryExpression(u)&&u.operatorToken.kind===r.SyntaxKind.BarBarToken){d(u.left),d(u.right);return}if(r.isStringLiteral(u)){if(l.fallback!==void 0)throw new Error("Multiple fallback values.");l.fallback=u.text;return}const h=u.getText(a);if(!Pb(h)||l.fallback!==void 0)throw new Error("Unsupported reference expression.");l.paths.push(h)};if(d(c.expression),!l.paths.length)throw new Error("A binding needs a reference.");return l},n=s=>{const a=[];let c=0;const l=/\{\{([\s\S]*?)\}\}/g;for(const d of s.matchAll(l)){const u=d.index;if(u<c)continue;u>c&&a.push({...Br("text"),text:s.slice(c,u)});const h=d[1].trim();if(h.startsWith("#if ")){const p=s.indexOf("{{/if}}",u+d[0].length);if(p<0)throw new Error("Unclosed condition.");a.push({...t(h.slice(4)),kind:"conditional",text:s.slice(u+d[0].length,p)}),c=p+7}else a.push(t(h)),c=u+d[0].length}return c<s.length&&a.push({...Br("text"),text:s.slice(c)}),a},o={mode:"reference",parts:[Br()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const s=JSON.parse(e);if(s&&typeof s=="object"&&!Array.isArray(s)&&Object.values(s).every(a=>typeof a=="string"))return{...o,mode:"json",fields:Object.entries(s).map(([a,c])=>({key:a,parts:n(c)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const s=r.createSourceFile("condition.ts",`value ${i[1].text}`,r.ScriptTarget.Latest,!0,r.ScriptKind.TS),a=s.statements[0];if(s.statements.length===1&&r.isExpressionStatement(a)&&r.isBinaryExpression(a.expression)&&a.expression.operatorToken.kind===r.SyntaxKind.EqualsEqualsToken&&r.isStringLiteral(a.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:a.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function Uu({parts:e,references:r,onChange:t,disabled:n}){const o=(i,s)=>t(e.map((a,c)=>c===i?{...a,...s}:a));return f.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,s)=>f.jsxs("fieldset",{"data-binding-part":s,style:{border:0,padding:0,margin:0,minWidth:0},children:[f.jsxs("legend",{children:["Part ",s+1]}),f.jsxs("div",{style:{display:"flex",gap:8},children:[f.jsxs("span",{"data-form-select":"",style:{flex:1},children:[f.jsxs("select",{"aria-label":"Part type",disabled:n,value:i.kind,onChange:a=>o(s,{kind:a.target.value}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"text",children:"Text"}),f.jsx("option",{value:"conditional",children:"Conditional text"})]}),f.jsx(ee.PiCaretDown,{size:16,"aria-hidden":"true"})]}),f.jsx(Ne,{"aria-label":`Remove part ${s+1}`,title:"Remove part",icon:f.jsx(ee.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t(e.filter((a,c)=>c!==s))})]}),i.kind!=="text"&&f.jsxs(f.Fragment,{children:[i.paths.map((a,c)=>f.jsxs("label",{children:["Reference ",c+1,f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":`Reference ${c+1}`,disabled:n,value:a,onChange:l=>o(s,{paths:i.paths.map((d,u)=>u===c?l.target.value:d)}),children:[f.jsx("option",{value:"",children:"Select reference"}),r.map(l=>f.jsx("option",{value:l.path,children:l.label},l.path))]}),f.jsx(ee.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},c)),i.kind==="reference"&&f.jsxs(f.Fragment,{children:[f.jsx(Ne,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:f.jsx(ee.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>o(s,{paths:[...i.paths,""]})}),f.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center"},children:[f.jsx("input",{type:"checkbox","aria-label":"Default value enabled",disabled:n,checked:i.fallback!==void 0,onChange:a=>o(s,{fallback:a.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&f.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:a=>o(s,{fallback:a.target.value})})]})]}),i.kind!=="reference"&&f.jsxs("label",{children:["Text",f.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:a=>o(s,{text:a.target.value})})]})]},s)),f.jsx(Ne,{"aria-label":"Add part",title:"Add part",icon:f.jsx(ee.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t([...e,Br()])})]})}function Vw({label:e,value:r,references:t,disabled:n,onChange:o}){const[i,s]=j.useState(),[a,c]=j.useState(""),[l,d]=j.useState(!1),u=async()=>{d(!0),c("");try{s(await Ww(typeof r=="string"?r:""))}catch(h){c(h instanceof Error?h.message:"Unable to read binding.")}finally{d(!1)}};return f.jsxs("div",{"data-runtime-binding":e,style:{marginBottom:8},children:[f.jsx(Ne,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:f.jsx(ee.PiLink,{size:18}),size:"sm",variant:"ghost",disabled:n||l,onClick:u}),typeof r=="string"&&r.includes("{{")&&f.jsx("span",{children:"Bound value"}),i&&f.jsxs("fieldset",{disabled:n,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Binding mode",f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":"Binding mode",value:i.mode,onChange:h=>s({...i,mode:h.target.value,parts:[Br()]}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"condition",children:"Equals"}),f.jsx("option",{value:"template",children:"Text template"}),f.jsx("option",{value:"json",children:"JSON output"})]}),f.jsx(ee.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),i.mode==="json"?f.jsxs(f.Fragment,{children:[i.fields.map((h,p)=>f.jsxs("fieldset",{"data-output-field":p,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Output field name",f.jsx("input",{"aria-label":"Output field name",value:h.key,onChange:m=>s({...i,fields:i.fields.map((g,y)=>y===p?{...g,key:m.target.value}:g)})})]}),f.jsx(Uu,{parts:h.parts,references:t,disabled:n,onChange:m=>s({...i,fields:i.fields.map((g,y)=>y===p?{...g,parts:m}:g)})}),f.jsx(Ne,{"aria-label":"Remove output field",title:"Remove output field",icon:f.jsx(ee.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:i.fields.filter((m,g)=>g!==p)})})]},p)),f.jsx(Ne,{"aria-label":"Add output field",title:"Add output field",icon:f.jsx(ee.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:[...i.fields,{key:"",parts:[Br()]}]})})]}):f.jsx(Uu,{parts:i.parts,references:t,disabled:n,onChange:h=>s({...i,parts:h})}),i.mode==="condition"&&f.jsxs("label",{children:["Equals",f.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:h=>s({...i,comparison:h.target.value})})]}),f.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[f.jsx(Ne,{"aria-label":"Apply binding",title:"Apply binding",icon:f.jsx(ee.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(Dw(i,t)),s(void 0),c("")}catch(h){c(h instanceof Error?h.message:"Unable to apply binding.")}}}),f.jsx(Ne,{"aria-label":"Cancel binding",title:"Cancel binding",icon:f.jsx(ee.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{s(void 0),c("")}})]})]}),a&&f.jsx("p",{role:"alert",children:a})]})}function Gw({nodeAddress:e,onOpen:r}){const{structured:t,data:n,callbacks:o,editable:i,onFieldCreate:s}=j.useContext($t),a=He(),[c,l]=j.useState(""),[d,u]=j.useState("0"),[h,p]=j.useState(""),m=t==null?void 0:t.containers.get(e);if(!m||!n||!t)return null;const g=a.readOnly||a.config.editable===!1||!i,y=Oe(n,m.address),b=Hu(m.declared),x=m.type.kind==="array"?m.type.items:m.type.kind==="object"?m.type.additionalProperties:void 0,w=x?Hu(x):[],v=!!s&&m.type.kind==="object"&&(x==null?void 0:x.kind)==="json",C=_=>_.kind==="literal"?String(_.value):_.kind==="string"?"Text":Dt(_.kind),S=[...t.slots.values()].filter(_=>_.owner===e),E=(_,N)=>{var $;return($=o.onFormChange)==null?void 0:$.call(o,{data:n,nodeAddress:m.address,address:_,previousValue:Oe(n,_),value:N})},R=_=>{var N;a.setSelectedNodeIds([_]),(N=a.engineRef.current)==null||N.focusNode(_,90,!1)},P=(_,N)=>{if(!Array.isArray(y))return;const $=[...y];[$[_],$[_+N]]=[$[_+N],$[_]],E(m.address,$)},I=()=>{const _=w[Number(d)]??w[0];if(_)if(m.type.kind==="array")E(m.address,[...Array.isArray(y)?y:[],_n(_)]);else{if(!c||c.includes(".")||c.startsWith("$")||["__proto__","constructor","prototype"].includes(c)){p("Choose a property name without dots or reserved prefixes.");return}if(Object.prototype.hasOwnProperty.call(y,c)){p("Property already exists.");return}v&&(d==="file"||d==="files")?s==null||s({data:n,nodeAddress:m.address,address:`${m.address}.${c}`,previousValue:void 0,value:d==="files"?[]:""},{$control:"upload"}):E(`${m.address}.${c}`,_n(_)),l(""),p("")}},M=m.type.kind==="object"&&!!m.type.additionalProperties,k=m.type.kind==="array";return f.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[b.length>1&&f.jsxs("label",{children:["Value type",f.jsx("span",{"data-form-select":"",style:{display:"block"},children:f.jsx(It,{"aria-label":"Value type",disabled:g,value:String(b.findIndex(_=>Bn(_,y).kind===m.type.kind)),onValueChange:_=>E(m.address,_n(b[Number(_)])),children:b.map((_,N)=>f.jsx("option",{value:N,children:C(_)},N))})})]}),S.map((_,N)=>f.jsxs("div",{"data-structured-slot":_.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[_.type.kind==="array"?f.jsx(ee.PiListNumbers,{size:20}):f.jsx(ee.PiBracketsCurly,{size:20}),f.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:Dt(_.label)}),f.jsx(Ne,{"aria-label":`${_.present?r?"Edit":"Focus":"Create"} ${Dt(_.label)}`,title:`${_.present?r?"Edit":"Focus":"Create"} ${Dt(_.label)}`,icon:_.present?f.jsx(ee.PiMagnifyingGlass,{size:18}):f.jsx(ee.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:g&&!_.present,onClick:$=>{var D;_.present?r?r(_.nodeId):((D=$.currentTarget.closest("dialog"))==null||D.close(),R(_.nodeId)):E(_.address,_n(_.type))}}),k&&f.jsxs(f.Fragment,{children:[f.jsx(Ne,{"aria-label":`Move item ${N+1} up`,icon:f.jsx(ee.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:g||N===0,onClick:()=>P(N,-1)}),f.jsx(Ne,{"aria-label":`Move item ${N+1} down`,icon:f.jsx(ee.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:g||N===S.length-1,onClick:()=>P(N,1)})]}),_.present&&f.jsx(Ne,{"aria-label":`Remove ${Dt(_.label)}`,icon:f.jsx(ee.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:g,onClick:()=>k?E(m.address,y.filter(($,D)=>D!==N)):E(_.address,void 0)})]},_.address)),(k||M)&&f.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[M&&f.jsxs("label",{style:{flex:"1 1 120px",minWidth:0,display:"grid",gap:8},children:["Property name",f.jsx("input",{"aria-label":"Property name",placeholder:"Required",value:c,disabled:g,onChange:_=>l(_.target.value)})]}),w.length>1&&f.jsxs("label",{style:{flex:"1 1 100px",minWidth:0,display:"grid",gap:8},children:["New value type",f.jsx("span",{"data-form-select":"",style:{display:"block"},children:f.jsxs(It,{"aria-label":"New value type",value:d,disabled:g,onValueChange:u,children:[w.map((_,N)=>f.jsx("option",{value:N,children:C(_)},N)),v&&f.jsx("option",{value:"file",children:"File"}),v&&f.jsx("option",{value:"files",children:"Files"})]})})]}),f.jsx("span",{style:{display:"flex",alignItems:"center",flexShrink:0,...M||w.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:f.jsx(Ne,{"aria-label":k?"Add item":"Add property",icon:f.jsx(ee.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:g,onClick:I})})]}),h&&f.jsx("p",{role:"alert",children:h})]})}const $t=j.createContext({callbacks:{}}),no=xo.default.div`
59
59
  --flow-form-input-radius: 16px;
60
60
  --flow-form-input-background: color-mix(
61
61
  in srgb,
@@ -206,8 +206,8 @@
206
206
  font-size: 14px;
207
207
  margin-top: 8px;
208
208
  }
209
- `;function Uu({request:e,property:r,config:t,value:n,disabled:o}){var fe,U,te,de,Pe;const{callbacks:i,structured:s,references:a}=j.useContext($t),{themeColor:c}=Ue(),{background:l}=at(),d=j.useId(),u=r.type.kind==="object"||r.type.kind==="array"||r.type.kind==="json",h=n===void 0?"":u?JSON.stringify(n,null,2):String(n),[p,m]=j.useState(h),[g,y]=j.useState(""),[b,x]=j.useState(0),v=j.useRef(null),w=j.useRef(),[C,S]=j.useState(!1),[E,M]=j.useState(!1),[P,T]=j.useState(),k=((fe=t.$options)==null?void 0:fe.$source)==="callback",R=i.resolveFormOptions,{data:_,address:N,nodeAddress:$,nodeId:V}=e;j.useEffect(()=>(S(!1),M(!1),()=>{var ie;(ie=w.current)==null||ie.abort(),w.current=void 0}),[N,$,V,o,h,t.$control,(U=t.$upload)==null?void 0:U.accept,(te=t.$upload)==null?void 0:te.maxSizeBytes]);const I=j.useRef(_);I.current=_;const F=JSON.stringify([N,V,(de=t.$options)!=null&&de.$dependsOn?t.$options.$dependsOn.map(ie=>Oe(_,ie)):Oe(_,$)]);j.useEffect(()=>{m(h),y("")},[h,N,V]),j.useEffect(()=>{if(!k)return;const ie=new AbortController;return Promise.resolve().then(()=>{if(!R)throw new Error("No options resolver configured");return R({address:N,nodeAddress:$,nodeId:V,data:an(I.current),signal:ie.signal})}).then(we=>{if(!Array.isArray(we)||we.some($e=>!$e||typeof $e.label!="string"||!["string","number","boolean"].includes(typeof $e.value)&&$e.value!==null))throw new Error("Invalid options response");ie.signal.aborted||T({key:F,options:we})}).catch(we=>{ie.signal.aborted||T({key:F,options:[],error:we instanceof Error?we.message:"Options unavailable"})}),()=>ie.abort()},[k,R,F,N,$,V,b]);const oe=k&&(P==null?void 0:P.key)!==F,se=k?(P==null?void 0:P.key)===F?P.options:[]:r.type.kind==="null"?[{label:"Null",value:null}]:r.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:On(r.type),H=r.type.kind==="array",ee=(t.$control==="upload"?"upload":s&&u||t.$control==="checkbox"?"pills":t.$control)??(se?H||r.type.kind==="boolean"?"pills":"select":r.type.kind==="boolean"?"checkbox":u?"textarea":"input"),ue=!r.optional||!!t.$requiredWhen&&Eo(t.$requiredWhen,_),q=ue?"Required":"Optional",D=ee!=="upload"&&!!(a!=null&&a.length)&&typeof n=="string"&&n.includes("{{"),K=g||k&&(P==null?void 0:P.key)===F&&P.error||!D&&Jt(r.type,n,ue),G=Dt(t.$label??N.split(".").pop()),ce=ie=>{var we;if(!(o||Object.is(ie,n)))try{(we=i.onFormChange)==null||we.call(i,{...e,previousValue:n,value:ie}),y("")}catch($e){y($e instanceof Error?$e.message:"Unable to update field")}},re=j.useRef(ce);j.useLayoutEffect(()=>{re.current=ce});const Z=()=>{if(u){try{const He=p===""&&r.optional?void 0:JSON.parse(p),Ve=Jt(r.type,He,ue);if(Ve){y(Ve);return}ce(He)}catch{y("Enter valid JSON")}return}const ie=r.type.kind==="number"||r.type.kind==="integer",we=p===""&&r.optional?void 0:ie&&p!==""?Number(p):p,$e=Jt(r.type,we,ue);if(ie&&$e&&p!==""){y($e);return}ce(we)},ae=async ie=>{var $e,He,Ve;if(o||w.current||!ie.length)return;const we=new AbortController;w.current=we,y(""),S(!0);try{if(r.type.kind!=="string"&&!(r.type.kind==="array"&&r.type.items.kind==="string"))throw new Error("Uploads require a string or string-array field.");if(!H&&ie.length!==1)throw new Error("Choose one file for this field.");if(!i.uploadFormFile)throw new Error("No file upload handler configured.");const tt=(He=($e=t.$upload)==null?void 0:$e.accept)==null?void 0:He.split(",").map(be=>be.trim().toLowerCase()).filter(Boolean);for(const be of ie){if(((Ve=t.$upload)==null?void 0:Ve.maxSizeBytes)!==void 0&&be.size>t.$upload.maxSizeBytes)throw new Error(`${be.name} exceeds the file size limit.`);if(tt!=null&&tt.length&&!tt.some(Xe=>Xe.startsWith(".")?be.name.toLowerCase().endsWith(Xe):Xe.endsWith("/*")?be.type.toLowerCase().startsWith(Xe.slice(0,-1)):be.type.toLowerCase()===Xe))throw new Error(`${be.name} is not an accepted file type.`)}const me=await Promise.all(ie.map(async be=>{const Xe=await i.uploadFormFile({...e,data:an(_),file:be,signal:we.signal});if(typeof Xe!="string")throw new Error("Upload handler must return an HTTP or HTTPS URL.");let ut;try{ut=new URL(Xe)}catch{throw new Error("Upload handler must return an HTTP or HTTPS URL.")}if(!["http:","https:"].includes(ut.protocol)||ut.username||ut.password)throw new Error("Upload handler must return an HTTP or HTTPS URL.");return Xe}));if(we.signal.aborted||w.current!==we)return;const Ie=H?[...Array.isArray(n)?n:[],...me]:me[0],De=Jt(r.type,Ie,ue);if(De)throw new Error(De);re.current(Ie)}catch(tt){we.signal.aborted||y(tt instanceof Error?tt.message:"Unable to upload file."),we.abort()}finally{w.current===we&&(w.current=void 0,S(!1))}},ye={id:d,disabled:o,"aria-label":G,"aria-required":ue,"aria-invalid":!!K,"aria-describedby":K?`${d}-error`:void 0},xe=Me(c);return f.jsxs("div",{"data-form-field":N,"data-flow-property":N.slice($.length+1),children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[f.jsxs("label",{htmlFor:d,children:[G,ue?" *":""]}),r.optional&&n!==void 0&&f.jsx("button",{type:"button","aria-label":`Reset ${G}`,title:`Reset ${G}`,disabled:o||C,style:{width:24,height:24,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:0,background:"transparent",color:"inherit"},onClick:()=>ce(void 0),children:f.jsx(Q.PiArrowCounterClockwise,{size:14})})]}),!!(a!=null&&a.length)&&!u&&ee!=="upload"&&f.jsx(Vw,{label:G,value:n,references:a,disabled:o,onChange:ce}),ee==="upload"?f.jsxs("div",{"data-form-upload":H?"multiple":"single","aria-busy":C,style:{"--flow-upload-surface":Me(l),outline:E?"2px dashed var(--flow-form-input-background)":void 0,borderRadius:"var(--flow-form-input-radius)"},onDragOver:ie=>{ie.preventDefault(),ie.stopPropagation(),!o&&!C&&(ie.dataTransfer.dropEffect="copy",M(!0))},onDragLeave:ie=>{ie.currentTarget.contains(ie.relatedTarget)||M(!1)},onDrop:ie=>{ie.preventDefault(),ie.stopPropagation(),M(!1),ae(Array.from(ie.dataTransfer.files))},children:[f.jsx("input",{ref:v,type:"file",hidden:!0,"aria-label":`Upload ${G}`,accept:(Pe=t.$upload)==null?void 0:Pe.accept,multiple:H,disabled:o||C,onChange:ie=>{const we=Array.from(ie.target.files??[]);ie.target.value="",ae(we)}}),f.jsxs("div",{"data-upload-items":"",children:[(H?Array.isArray(n)?n:[]:n?[n]:[]).map((ie,we)=>f.jsxs("div",{"data-upload-preview":"",children:[typeof ie=="string"&&wr(ie)&&f.jsxs("a",{href:ie,target:"_blank",rel:"noopener noreferrer","aria-label":`${G} file ${we+1}`,children:[f.jsx(Q.PiFile,{size:32,"aria-hidden":"true"}),f.jsx(cr,{name:ie,size:120,onError:$e=>{$e.currentTarget.style.visibility="hidden"}})]}),f.jsxs("div",{"data-upload-actions":"",children:[!H&&f.jsx(Ne,{"aria-label":`Replace ${G}`,title:`Replace ${G}`,icon:f.jsx(Q.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>{var $e;return($e=v.current)==null?void 0:$e.click()}}),f.jsx(Ne,{"aria-label":`Remove ${G} file ${we+1}`,title:"Remove file",icon:f.jsx(Q.PiTrash,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>ce(H&&Array.isArray(n)?n.filter(($e,He)=>He!==we):"")})]})]},`${we}:${ie}`)),(H||!n)&&f.jsx("button",{...ye,type:"button","data-upload-drop":"",title:`Upload ${G}`,disabled:o||C,onClick:()=>{var ie;return(ie=v.current)==null?void 0:ie.click()},children:f.jsx(Q.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&f.jsx("span",{role:"status",children:"Uploading..."})]}):D?null:ee==="select"?f.jsx("div",{"data-form-select":"",children:f.jsxs(It,{...ye,disabled:o||oe||!!(P!=null&&P.error),labelCase:"preserve",value:String((se==null?void 0:se.findIndex(ie=>Object.is(ie.value,n)))??-1),onValueChange:ie=>{const we=se==null?void 0:se[Number(ie)];we&&ce(we.value)},children:[f.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):q}),se==null?void 0:se.map((ie,we)=>f.jsx("option",{value:we,children:Dt(ie.label)||ie.label},we))]})}):ee==="pills"?f.jsxs("div",{id:d,role:"group","aria-label":G,"aria-describedby":ye["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:[se==null?void 0:se.map((ie,we)=>{const $e=H?Array.isArray(n)&&n.includes(ie.value):Object.is(n,ie.value);return f.jsx("button",{type:"button",disabled:o||oe,"aria-pressed":$e,style:{padding:"8px 16px",borderRadius:24,border:0,color:$e?xe:"inherit",background:$e?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>ce(H?$e?n.filter(He=>He!==ie.value):[...Array.isArray(n)?n:[],ie.value]:ie.value),children:Dt(ie.label)||ie.label},we)}),oe&&f.jsx("span",{role:"status",children:"Loading..."})]}):ee==="textarea"?f.jsx("textarea",{...ye,placeholder:q,value:p,onChange:ie=>m(ie.target.value),onBlur:Z}):f.jsx("input",{...ye,placeholder:q,type:r.type.kind==="number"||r.type.kind==="integer"?"number":"text",step:r.type.kind==="integer"?1:"any",value:p,onChange:ie=>m(ie.target.value),onBlur:Z,onKeyDown:ie=>{ie.key==="Enter"&&Z(),ie.key==="Escape"&&m(n===void 0?"":String(n))}}),K&&f.jsx("div",{role:"alert",id:`${d}-error`,children:K}),k&&(P==null?void 0:P.error)&&f.jsx("button",{type:"button",disabled:o,onClick:()=>{T(void 0),x(b+1)},children:"Retry"})]})}function Vd({nodeAddress:e,structured:r=!1}){return r?f.jsx(Hw,{nodeAddress:e},e):f.jsx(Ed,{nodeAddress:e})}function Hw({nodeAddress:e}){var u,h,p;const r=j.useContext($t),[t,n]=j.useState([]),o=((u=r.structured)==null?void 0:u.sourceSchema)??r.schema,i=((h=r.structured)==null?void 0:h.sourceBindings)??r.bindings,s=j.useMemo(()=>{if(!(!r.data||!o||!i))return _b(r.data,i,o,[{data:{id:e,type:"objectView"}}])},[r.data,i,o,e]);if(!s)return f.jsx(Ed,{nodeAddress:e});const a=t.findIndex(m=>!s.containers.has(m)),c=a<0?t:t.slice(0,a),l=c.at(-1)??e,d=(p=[...s.slots.values()].find(m=>m.nodeId===l))==null?void 0:p.label;return f.jsxs($t.Provider,{value:{...r,structured:s,schema:s.schema,bindings:s.bindings,renderForm:void 0,onFieldCreate:l===e?r.onFieldCreate:void 0},children:[!!c.length&&f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[f.jsx(Ne,{"aria-label":"Back to parent fields",title:"Back to parent fields",icon:f.jsx(Q.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:()=>n(c.slice(0,-1))}),f.jsx("strong",{style:{minWidth:0,overflowWrap:"anywhere"},children:Dt(d)})]}),f.jsx(Ed,{nodeAddress:l,onOpen:m=>n([...c,m])},l)]})}function Ed({nodeAddress:e,onOpen:r}){var S,E;const{data:t,schema:n,callbacks:o,bindings:i,editable:s,renderForm:a,structured:c}=j.useContext($t),{readOnly:l,config:d,colorMode:u}=Ue(),h=a==null?void 0:a(e);if(h!==void 0)return f.jsx("fieldset",{"data-flow-form":e,disabled:l||d.editable===!1||!s,style:{border:0,margin:0,padding:0,minWidth:0},children:h});if(!t)return f.jsx(no,{$colorMode:u,role:"alert",children:"Forms require a JSON document."});const p=i?Hn(i,e,n):void 0,m=i?p:n&&un(t,e,n);if(!m)return f.jsx(no,{$colorMode:u,role:"status",children:"Form schema unavailable."});const g=(p==null?void 0:p.address)??e,y=Oe(t,g),b=(S=c==null?void 0:c.containers.get(e))==null?void 0:S.scalar;if(y===void 0||typeof y!="object"&&!b)return f.jsx(no,{$colorMode:u,role:"alert",children:"Bound form state is unavailable."});const x=Object.entries(m.type.properties).filter(([M])=>{var P;return Eo((P=m.fields[M])==null?void 0:P.$visibleWhen,t)}),v=x.length>8||x.some(([M])=>{var P;return(P=m.fields[M])==null?void 0:P.$section}),w=new Map;for(const M of x){const[P,T]=M,k=v?Dt(((E=m.fields[P])==null?void 0:E.$section)??(T.type.kind==="object"||T.type.kind==="array"?P:T.optional?"Options":"General")):"";w.has(k)||w.set(k,[]),w.get(k).push(M)}const C=([M,P])=>f.jsx(Uu,{request:{data:t,address:b?g:`${g}.${M}`,nodeAddress:g,nodeId:typeof(y==null?void 0:y.id)=="string"?y.id:void 0},property:P,config:m.fields[M]??{},value:b?y:y==null?void 0:y[M],disabled:l||d.editable===!1||!(s??!!o.onJsonChange)},`${(y==null?void 0:y.id)??e}:${M}`);return f.jsxs(no,{$colorMode:u,"data-flow-form":e,onClick:M=>M.stopPropagation(),onDoubleClick:M=>M.stopPropagation(),children:[c&&f.jsx(Gw,{nodeAddress:e,onOpen:r}),!c&&p&&m.type.additionalProperties&&x.length===0&&f.jsx(Uu,{request:{data:t,address:g,nodeAddress:g},property:{type:m.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:y,disabled:l||d.editable===!1||!s}),[...w].map(([M,P])=>v&&P.length>1?f.jsxs("details",{open:!0,children:[f.jsxs("summary",{children:[f.jsx("span",{children:M}),f.jsx(Q.PiCaretDown,{size:16,"aria-hidden":"true"})]}),P.map(C)]},M):P.map(C))]})}function Pb(e){const{viewData:r}=j.useContext($t),{nodeById:t,edgeById:n,parentIds:o}=Xt();if(r){const i=Oe(r,e),s=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(s)?s.length>0:!!s&&typeof s=="object"&&Object.entries(s).some(([a,c])=>!a.startsWith("$")&&c!==null&&typeof c=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const s=i.isInverted?i.target:i.source,a=i.isInverted?i.source:i.target;return s===e&&a!==e&&t.has(a)})}function Dn(e,r){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:r}function Wn(e,r,t,n){return{borderColor:r,borderWidth:Dn(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",...pb(r==="transparent"?"currentColor":r,t,".flow-sdk-node:hover &",!t)}}function Ab({label:e,value:r,options:t,onChange:n,disabled:o}){var i;return f.jsxs(It,{"aria-label":e,title:`Animation: ${((i=t.find(s=>s.value===r))==null?void 0:i.label)??"Mixed"}`,value:r,style:{width:104},disabled:o,onValueChange:s=>{const a=t.find(c=>c.value===s);a&&n(a.value)},children:[r===""&&f.jsx("option",{value:"",disabled:!0,children:"Mixed"}),t.map(s=>f.jsx("option",{value:s.value,children:s.label},s.value))]})}function Gd({nodeId:e,edgeId:r,value:t,open:n,onOpenChange:o}){const{callbacks:i,readOnly:s,themeColor:a,colorMode:c}=Ue(),{background:l,backgroundSecondary:d,border:u,colorText:h,colorInactive:p}=at(),m=c==="dark"?ln:Me(p),g=j.useRef(null),y=j.useRef(null),b=j.useRef(0),[x,v]=j.useState(!1),[w,C]=j.useState("icons"),[S,E]=j.useState([]),[M,P]=j.useState("loading"),[T,k]=j.useState(""),[R,_]=j.useState(0),[N,$]=j.useState(""),[V,I]=j.useState(""),[F,oe]=j.useState(!1);j.useEffect(()=>()=>{b.current++},[]),j.useEffect(()=>{if(!x)return;let G=!0;return import("react-icons/pi").then(ce=>{G&&(E(Object.keys(ce).filter(re=>re.startsWith("Pi")).sort()),P("ready"))}).catch(()=>{G&&P("unavailable")}),()=>{G=!1}},[x]),j.useEffect(()=>{var G;s&&((G=g.current)==null||G.close())},[s]),j.useEffect(()=>{var G,ce,re;if(n!==void 0){if(!n||s){(G=g.current)==null||G.close();return}(ce=g.current)!=null&&ce.open||(I(""),C(t==="PiFileSvg"||t&&wr(t)?"custom":"icons"),$(t&&!t.startsWith($n)&&wr(t)?t:""),v(!0),(re=g.current)==null||re.showModal())}},[n,s,t]);const se=G=>{var ce,re,Z;s||(r?(ce=i.onEdgeIconChange)==null||ce.call(i,r,G):e&&((re=i.onNodeIconChange)==null||re.call(i,e,G)),o==null||o(!1),(Z=g.current)==null||Z.close())},H=S.filter(G=>G.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(T.trim().toLowerCase())),ee=36,ue=Math.max(1,Math.ceil(H.length/ee)),q=Math.min(R,ue-1),D=H.slice(q*ee,(q+1)*ee),K={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${Me(u)}`,borderRadius:30};return f.jsxs(f.Fragment,{children:[n===void 0&&f.jsx(Ge,{label:r?"Choose edge icon":"Choose node icon",children:f.jsx(Ne,{"aria-label":r?"Choose edge icon":"Choose node icon",icon:f.jsx(Q.PiShapes,{size:20}),size:"sm",variant:"ghost",color:Me(a),disabled:s,onClick:()=>{var G;I(""),C(t&&wr(t)?"custom":"icons"),$(t&&!t.startsWith($n)&&wr(t)?t:""),v(!0),(G=g.current)==null||G.showModal()}})}),f.jsx(W.chakra.dialog,{ref:g,"aria-label":r?"Choose edge icon":"Choose node icon",css:gr(Me(l),Me(u)),onClose:()=>{v(!1),o==null||o(!1),b.current++,oe(!1)},onClick:G=>{G.stopPropagation(),G.target===G.currentTarget&&G.currentTarget.close()},onKeyDown:G=>G.stopPropagation(),style:{margin:"auto",padding:12,width:336,maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",borderRadius:30,background:Me(l),color:Me(h)},children:x&&f.jsxs("div",{style:{display:"grid",gap:8},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[f.jsx("strong",{children:r?"Edge icon":"Node icon"}),f.jsxs("div",{style:{display:"flex",alignItems:"center",marginLeft:"auto",gap:4},children:[t&&f.jsx(Ge,{label:"Remove icon",children:f.jsx(Ne,{"aria-label":r?"Remove edge icon":"Remove node icon",icon:f.jsx(Q.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:s||F,onClick:()=>se("")})}),f.jsx(dn,{"aria-label":"Close icon picker",onClick:()=>{var G;return(G=g.current)==null?void 0:G.close()}})]})]}),f.jsxs(W.Tabs.Root,{value:w,onValueChange:({value:G})=>{C(G),I("")},display:"contents",css:{"--indicator-thickness":"1px"},children:[f.jsx(W.Tabs.List,{"aria-label":"Icon source",width:"100%",borderBottomWidth:0,children:["icons","custom"].map(G=>f.jsx(W.Tabs.Trigger,{value:G,flex:1,minW:0,justifyContent:"center",px:3,py:2,fontSize:"13px",_selected:{color:a,borderColor:m,"--indicator-color":m},children:G==="icons"?"React icons":"Custom SVG"},G))}),f.jsx("input",{ref:y,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:F||s,onChange:async G=>{var Z;const ce=(Z=G.target.files)==null?void 0:Z[0];if(G.target.value="",!ce)return;const re=++b.current;oe(!0),I("");try{const ae=await $w(ce);re===b.current&&se(ae)}catch(ae){re===b.current&&I(ae instanceof Error?ae.message:"Unable to read SVG.")}finally{re===b.current&&oe(!1)}}}),f.jsx(W.Tabs.Content,{value:w,p:0,style:{display:"grid",gap:8},children:w==="icons"?f.jsxs(f.Fragment,{children:[f.jsx("input",{"aria-label":"Search icons",placeholder:"Search icons...",value:T,onChange:G=>{k(G.target.value),_(0)},style:K}),f.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[D.map(G=>f.jsx("button",{type:"button","aria-label":`Choose ${G}`,"aria-pressed":t===G,title:G,onClick:()=>se(G),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${t===G?2:1}px solid ${Me(t===G?a:u)}`,background:Me(t===G?l:d),color:"inherit",cursor:"pointer"},children:f.jsx(cr,{name:G,size:24})},G)),D.length===0&&f.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:M==="loading"?"Loading icons...":M==="unavailable"?"React icons unavailable":"No icons found"})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[f.jsxs("span",{role:"status",style:{fontSize:12},children:[H.length," icons · ",q+1," / ",ue]}),f.jsxs("div",{style:{display:"flex",gap:4},children:[f.jsx(Ge,{label:"Previous icons",children:f.jsx(Ne,{"aria-label":"Previous icons",icon:f.jsx(Q.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:q===0,onClick:()=>_(q-1)})}),f.jsx(Ge,{label:"Next icons",children:f.jsx(Ne,{"aria-label":"Next icons",icon:f.jsx(Q.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:q+1>=ue,onClick:()=>_(q+1)})})]})]})]}):f.jsxs(f.Fragment,{children:[t&&wr(t)&&f.jsx(cr,{name:t,size:64}),f.jsxs("button",{type:"button",disabled:F||s,onClick:()=>{var G;return(G=y.current)==null?void 0:G.click()},style:{...K,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[f.jsx(Q.PiUploadSimple,{}),F?"Uploading...":"Upload SVG"]}),f.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:G=>{G.preventDefault(),!(F||s)&&(!wr(N.trim())||N.trim().startsWith($n)?I("Enter an HTTP or HTTPS image URL."):se(N.trim()))},children:[f.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:N,disabled:F||s,onChange:G=>$(G.target.value),style:{...K,flex:1,minWidth:0}}),f.jsx(Ge,{label:"Apply URL",children:f.jsx(Ne,{type:"submit","aria-label":"Apply URL",icon:f.jsx(Q.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:F||s||!N.trim(),style:{flexShrink:0}})})]})]})})]}),V&&f.jsx("div",{role:"alert",style:{fontSize:13},children:V})]})})]})}const po=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500",ln],Rb=["gray.900",ln,"gray.600","gray.200","white"];function Mb(){const{config:e}=Ue(),r=e.selectionToolbar||{},t=new Set(r.hide||[]);return{palette:r.palette||po,show:n=>!t.has(n)}}function Tt(){const{border:e}=at();return f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:e})}function Er({value:e,placeholder:r,ariaLabel:t,width:n="140px",type:o="text",min:i,disabled:s=!1,onCommit:a}){const{colorText:c}=at(),[l,d]=j.useState(e),u=j.useRef(!1);j.useEffect(()=>d(e),[e]);const h=()=>{if(s||u.current)return;u.current=!0;const p=l.trim();if(o==="number"&&p!==""&&(!Number.isFinite(Number(p))||Number(p)<(i??0))){d(e);return}p!==e&&a(p)};return f.jsx(W.Input,{"aria-label":t,type:o,min:i,disabled:s,size:"xs",fontSize:"16px",w:n,value:l,placeholder:r,color:c,borderWidth:0,_focusVisible:{boxShadow:"none",outline:"none"},borderRadius:"8px",onFocus:()=>{u.current=!1},onChange:p=>d(p.target.value),onBlur:h,onKeyDown:p=>{p.key==="Enter"&&(h(),p.target.blur()),p.key==="Escape"&&(u.current=!0,d(e),p.target.blur())}})}function Vr({colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:s,colorText:a}=at(),[c,l]=j.useState(!1),d=j.useId(),u=j.useRef(null),h=r??e[0]??"transparent",p=jo(f.jsx(Vr,{colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i}));return f.jsx(nn.Provider,{value:null,children:f.jsxs(W.HStack,{gap:1,"aria-label":t,role:"group",onClickCapture:p,onKeyDown:m=>{var g;m.key==="Escape"&&(l(!1),(g=u.current)==null||g.focus())},children:[f.jsx(Ge,{label:`${t}: ${h}`,children:f.jsx(W.chakra.button,{ref:u,type:"button","aria-label":`${t} colors`,"aria-expanded":c,"aria-controls":d,w:4,h:4,flexShrink:0,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Me(h),...h==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${Me(a)}`,outlineOffset:"1px",onClick:()=>l(m=>!m)})}),c&&f.jsxs(W.HStack,{id:d,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(m=>{const g=r===m;return f.jsx(Ge,{label:`${t}: ${m}`,children:f.jsx(W.Box,{as:"button","aria-label":`${t} ${m}`,"aria-pressed":g,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Me(m),...m==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:g?`2px solid ${Me(a)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>n(m),onDoubleClick:y=>{var b;y.stopPropagation(),l(!1),(b=u.current)==null||b.focus()}})},m)}),o&&f.jsx(Ge,{label:`Reset ${t.toLowerCase()}`,children:f.jsx(Ne,{"aria-label":`Reset ${t}`,icon:f.jsx(W.Icon,{as:Q.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:s,onClick:()=>{var m;o(),l(!1),(m=u.current)==null||m.focus()}})})]})]})})}function Tb({edgeId:e,onClose:r}){var p;const{callbacks:t,themeColor:n,config:o}=Ue(),{colorInactive:i}=at(),{edgeById:s}=Xt(),{palette:a,show:c}=Mb(),l=(p=s.get(e))==null?void 0:p.data,d=[...new Set(["rounded-orthogonal","orthogonal","straight","bezier",...Object.keys(o.customEdgeTypes??{}),...l!=null&&l.type?[l.type]:[]])],u=l!=null&&l.isEdgeAnimated?"animated":l!=null&&l.isEdgeDashed?"dashed":"solid",h=[{key:"solid",icon:Q.PiLineSegment,label:"Solid"},{key:"dashed",icon:Q.PiLineSegments,label:"Dashed"},{key:"animated",icon:Q.PiFastForward,label:"Animated"}];return f.jsxs(f.Fragment,{children:[f.jsx(dn,{onClick:r}),c("label")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Er,{ariaLabel:"Edge label",placeholder:"Edge label",value:(l==null?void 0:l.label)||"",onCommit:m=>{var g;return(g=t.onEdgeLabelChange)==null?void 0:g.call(t,e,m)}})]}),c("style")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),h.map(m=>f.jsx(Ge,{label:m.label,children:f.jsx(Ne,{"aria-label":`Edge style ${m.key}`,"aria-pressed":u===m.key,icon:f.jsx(W.Icon,{as:m.icon,boxSize:5}),size:"sm",variant:"ghost",color:u===m.key?n:i,onClick:()=>{var g;return(g=t.onEdgeStyleChange)==null?void 0:g.call(t,e,m.key)}})},m.key)),u==="animated"&&f.jsx(Ab,{label:"Edge animation",value:(l==null?void 0:l.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:o.readOnly,onChange:m=>{var g;return(g=t.onEdgeAnimationVariantChange)==null?void 0:g.call(t,e,m)}}),f.jsxs(It,{"aria-label":"Edge shape",title:`Edge shape: ${(l==null?void 0:l.type)??"Default"}`,icon:f.jsx(Q.PiBezierCurve,{size:20}),style:{width:36},value:(l==null?void 0:l.type)??"",disabled:o.readOnly,onValueChange:m=>{var g;return(g=t.onEdgeTypeChange)==null?void 0:g.call(t,e,m||void 0)},children:[f.jsx("option",{value:"",children:"Default"}),d.map(m=>f.jsx("option",{value:m,children:m},m))]})]}),c("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Gd,{edgeId:e,value:l==null?void 0:l.icon},e),f.jsx(Er,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(l==null?void 0:l.icon)??"",onCommit:m=>{var g;return(g=t.onEdgeIconChange)==null?void 0:g.call(t,e,m)}})]}),c("color")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Vr,{label:"Edge color",colors:a,value:l==null?void 0:l.color,onPick:m=>{var g;return(g=t.onEdgeColorChange)==null?void 0:g.call(t,e,m)},onReset:()=>{var m;return(m=t.onEdgeColorChange)==null?void 0:m.call(t,e,"")}})]}),c("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:"Delete edge",children:f.jsx(Ne,{"aria-label":"Delete edge",icon:f.jsx(W.Icon,{as:Q.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var m;(m=t.onEdgeDelete)==null||m.call(t,e,l),r()}})})]})]})}function Ib({ids:e,showDivider:r=!0}){const{callbacks:t,config:n,nodeGridOptions:o,fillRadiusEditedIds:i}=Ue(),{colorInactive:s}=at(),{nodeById:a}=Xt(),[c,l]=j.useState(!1),d=e.map(y=>{var b,x;return o!=null&&o.fill&&!i.has(y)?0:(x=(b=a.get(y))==null?void 0:b.data.viewProps)==null?void 0:x.borderRadius}),u=!d.every(y=>y===d[0]),h=u?"mixed":String(d[0]??""),p=["0","8","16","30","53","100"],m=c||!u&&h!==""&&!p.includes(h),g=y=>e.forEach(b=>{var x;return(x=t.onNodeBorderRadiusChange)==null?void 0:x.call(t,b,y)});return f.jsxs(f.Fragment,{children:[r&&f.jsx(Tt,{}),f.jsx(W.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:f.jsxs(It,{icon:f.jsx(W.Icon,{as:Tv.TbBorderRadius,boxSize:5,color:s,"aria-hidden":"true"}),"aria-label":"Node border radius",title:`Border radius: ${u?"Mixed":d[0]===void 0?"Default":`${d[0]}px`}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",cursor:"pointer"},value:m?"custom":h,disabled:n.readOnly,onValueChange:y=>{l(y==="custom"),y!=="custom"&&g(y===""?void 0:Number(y))},children:[f.jsx("option",{value:"",children:"Default radius"}),u&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed radii"}),p.map(y=>f.jsxs("option",{value:y,children:[y,"px radius"]},y)),f.jsx("option",{value:"custom",children:"Custom radius"})]})}),m&&f.jsx(Er,{ariaLabel:"Custom border radius",placeholder:u?"Mixed":"Auto",type:"number",min:0,width:"72px",value:u?"":h,onCommit:y=>g(y===""?void 0:Number(y))})]})}function Nb({ids:e,onClose:r,afterLabel:t}){var G,ce,re,Z,ae,ye,xe,fe;const{callbacks:n,colorMode:o,themeColor:i,config:s,setNodeViewMode:a}=Ue(),{colorText:c,colorInactive:l}=at(),{nodeById:d,parentIds:u}=Xt(),{palette:h,show:p}=Mb(),m=e.length===1,[g,y]=j.useState(""),b=m?(G=d.get(e[0]))==null?void 0:G.data:void 0,x=e.map(U=>{var te,de;return((de=(te=d.get(U))==null?void 0:te.data.config)==null?void 0:de.typeView)??""}),v=x.some(U=>U!==x[0]),w=v?"mixed":x[0]??"",C=[{value:"text",label:"Text",view:"text",icon:Q.PiTextT},{value:"icon-label",label:"Icon Label",view:"icon-label",icon:Q.PiShapes},{value:"object",label:"Object",view:"object",icon:Q.PiBracketsCurly},{value:"grid",label:"Grid",view:"grid",icon:Q.PiGridFour},{value:"parent",label:"Parent",view:"parent",icon:Q.PiStack},{value:"media",label:"Media",view:"icon-label",icon:Q.PiFileSvg},{value:"content",label:"Content",view:"object",icon:Q.PiTextAlignLeft},{value:"prompt",label:"Prompt",view:"prompt",icon:Q.PiTextAlignLeft}].filter(U=>U.view!=="prompt"||!!n.onPromptSubmit),S=e.some(U=>{var de,Pe;const te=(de=d.get(U))==null?void 0:de.data;return te&&(u.has(U)||((Pe=te.config)==null?void 0:Pe.parentContainer)||Object.prototype.hasOwnProperty.call(s.customViews??{},te.type))}),E=(ce=b==null?void 0:b.config)==null?void 0:ce.collapsed,M=Pb(e[0]),P=U=>{var te,de,Pe;return(((de=(te=d.get(U))==null?void 0:te.data.viewProps)==null?void 0:de.outline)??(u.has(U)?(Pe=s.parentNodeStyle)==null?void 0:Pe.outline:!1))===!0},T=e.every(P),k=!T&&e.some(P),R=U=>{var te;return((te=d.get(U))==null?void 0:te.data.isNodeAnimated)===!0},_=e.every(R),N=!_&&e.some(R),$=e.map(U=>{var te;return((te=d.get(U))==null?void 0:te.data.nodeAnimationVariant)??"traveling"}),V=$.every(U=>U===$[0])?$[0]:"",I=U=>e.forEach(U),[F,oe]=j.useState(!1),se=F&&p("color")&&p("borderColor"),H=U=>{var te,de,Pe;return(((de=(te=d.get(U))==null?void 0:te.data.viewProps)==null?void 0:de.borderStyle)??(u.has(U)?(Pe=s.parentNodeStyle)==null?void 0:Pe.borderStyle:"solid"))==="dashed"},ee=e.every(H),ue=!ee&&e.some(H),q=e.map(U=>{var Pe,ie,we;const te=(Pe=d.get(U))==null?void 0:Pe.data,de=u.has(U)?Dn((ie=s.parentNodeStyle)==null?void 0:ie.borderWidth,6):(te==null?void 0:te.type)==="objectView"?3:2;return Dn((we=te==null?void 0:te.viewProps)==null?void 0:we.borderWidth,de)}),D=q.every(U=>U===q[0])?String(q[0]??""):"",K=U=>I(te=>{var de,Pe;se?(de=n.onNodeBorderColorChange)==null||de.call(n,te,U):(Pe=n.onNodeColorChange)==null||Pe.call(n,te,"bg",U)});return f.jsxs(f.Fragment,{children:[f.jsx(dn,{onClick:r}),f.jsx(Tt,{}),m&&p("label")?f.jsx(Er,{ariaLabel:"Node label",placeholder:"Node label",value:(b==null?void 0:b.label)??(b==null?void 0:b.headerTitle)??"",onCommit:U=>{var te;return(te=n.onNodeLabelChange)==null?void 0:te.call(n,e[0],U)}}):f.jsxs(W.Text,{fontSize:"xs",color:c,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),t,p("typeView")&&f.jsxs(It,{"aria-label":"Type view",title:S?"Type view is managed by the custom renderer or container":`Type view: ${w||"None (default)"}`,icon:f.jsx(Q.PiCards,{size:20}),style:{width:36},value:w,disabled:s.readOnly||s.editable===!1||S,onValueChange:U=>{var de;const te=(de=C.find(Pe=>Pe.value===U))==null?void 0:de.view;te&&I(Pe=>{var ie,we;(ie=n.onNodeTypeViewChange)==null||ie.call(n,Pe,te),a(Pe,"default"),(we=n.onNodeViewToggle)==null||we.call(n,Pe)})},children:[v&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),C.map(U=>f.jsx("option",{value:U.value,children:f.jsxs(W.HStack,{gap:"12px",children:[f.jsx(U.icon,{size:20,"aria-hidden":"true",style:{flexShrink:0}}),f.jsx("span",{children:U.label})]})},U.value))]}),p("style")&&f.jsx(Ib,{ids:e},e.join("\0")),p("outline")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:T?"Restore node fill":"Remove node fill",children:f.jsx(Ne,{"aria-label":"Toggle node outline","aria-pressed":k?"mixed":T,icon:f.jsx(W.Icon,{as:T?Q.PiSquare:Q.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:T?i:l,onClick:()=>I(U=>{var te;return(te=n.onNodeOutlineChange)==null?void 0:te.call(n,U,!T)})})})]}),p("color")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),p("borderColor")&&f.jsx(Ge,{label:se?"Edit node colors":"Edit node border",children:f.jsx(Ne,{"aria-label":"Edit node border","aria-pressed":se,icon:f.jsx(W.Icon,{as:Q.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:se?i:l,bg:se?o==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>oe(U=>!U)})}),f.jsx(Vr,{label:se?"Border color":"Background",colors:h,value:se?((re=b==null?void 0:b.viewProps)==null?void 0:re.borderColor)??(m&&u.has(e[0])?(Z=s.parentNodeStyle)==null?void 0:Z.borderColor:void 0):(ae=b==null?void 0:b.viewProps)==null?void 0:ae.bgColor,onPick:K,onReset:()=>K("")}),se&&p("style")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:ee?"Solid border":"Dashed border",children:f.jsx(Ne,{"aria-label":"Toggle dashed border","aria-pressed":ue?"mixed":ee,icon:f.jsx(W.Icon,{as:ee?Q.PiLineSegments:Q.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:ee?i:l,onClick:()=>I(U=>{var te;return(te=n.onNodeBorderStyleChange)==null?void 0:te.call(n,U,ee?"solid":"dashed")})})}),f.jsx(Er,{ariaLabel:"Border thickness",placeholder:m?"Auto":"Mixed",width:"64px",type:"number",min:0,value:D,onCommit:U=>I(te=>{var de;return(de=n.onNodeBorderWidthChange)==null?void 0:de.call(n,te,U===""?void 0:Number(U))})})]})]}),p("animation")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:_?"Stop border animation":"Animate node border",children:f.jsx(Ne,{"aria-label":"Toggle node animation","aria-pressed":N?"mixed":_,icon:f.jsx(W.Icon,{as:Q.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:_?i:l,onClick:()=>I(U=>{var te;return(te=n.onNodeAnimationChange)==null?void 0:te.call(n,U,!_)})})}),(_||N)&&f.jsx(Ab,{label:"Node animation",value:V,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:s.readOnly,onChange:U=>I(te=>{var de;return(de=n.onNodeAnimationVariantChange)==null?void 0:de.call(n,te,U)})})]}),!se&&p("textColor")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Vr,{label:"Text color",colors:Rb,value:(ye=b==null?void 0:b.viewProps)==null?void 0:ye.textColor,onPick:U=>I(te=>{var de;return(de=n.onNodeColorChange)==null?void 0:de.call(n,te,"text",U)}),onReset:()=>I(U=>{var te;return(te=n.onNodeColorChange)==null?void 0:te.call(n,U,"text","")})})]}),m&&p("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Gd,{nodeId:e[0],value:(xe=b==null?void 0:b.config)==null?void 0:xe.icon},e[0]),f.jsx(Er,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((fe=b==null?void 0:b.config)==null?void 0:fe.icon)||"",onCommit:U=>{var te;return(te=n.onNodeIconChange)==null?void 0:te.call(n,e[0],U)}})]}),m&&M&&p("collapse")&&E!==void 0&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:E?"Expand":"Collapse",children:f.jsx(Ne,{"aria-label":E?"Expand node":"Collapse node",icon:f.jsx(W.Icon,{as:E?Q.PiArrowsOutLineVertical:Q.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:l,onClick:()=>{var U;return(U=n.onNodeCollapse)==null?void 0:U.call(n,e[0],!E)}})})]}),p("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:m?"Delete node":`Delete ${e.length} nodes`,children:f.jsx(Ne,{"aria-label":"Delete selected nodes",icon:f.jsx(W.Icon,{as:Q.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:o==="dark"?"red.300":"red.500",onClick:()=>{I(U=>{var te,de;return(de=n.onNodeDelete)==null?void 0:de.call(n,U,((te=d.get(U))==null?void 0:te.data)||{id:U})}),r()}})})]}),f.jsx(Ge,{label:"Copy selection",children:f.jsx(Ne,{"aria-label":"Copy selection",icon:f.jsx(Q.PiCopy,{size:20}),size:"sm",variant:"ghost",color:l,onClick:async()=>{var U;try{await((U=n.onNodesCopy)==null?void 0:U.call(n,e)),y("")}catch(te){y(String(te))}}})}),f.jsx(Ge,{label:"Duplicate selection",children:f.jsx(Ne,{"aria-label":"Duplicate selection",icon:f.jsx(Q.PiCopySimple,{size:20}),size:"sm",variant:"ghost",color:l,disabled:s.readOnly||s.editable===!1,onClick:()=>{var U;try{(U=n.onNodesDuplicate)==null||U.call(n,e),y("")}catch(te){y(String(te))}}})}),g&&f.jsx(W.Text,{role:"alert",fontSize:"xs",children:g})]})}async function Ob(e){const{toSvg:r}=await Promise.resolve().then(()=>require("./index-sHQXTNv9.cjs"));await document.fonts.ready;const t=await r(e,{filter:o=>!(o instanceof Element)||!o.matches("button, iframe, [role=tooltip], .flow-sdk-handle, .flow-sdk-property-port, .flow-sdk-edge-hit, .flow-sdk-ghost, .flow-sdk-node-animation")}),n=new DOMParser().parseFromString(decodeURIComponent(t.slice(t.indexOf(",")+1)),"image/svg+xml");return n.querySelectorAll(".flow-sdk-edge-hit, .flow-sdk-handle, .flow-sdk-property-port, .flow-sdk-ghost").forEach(o=>o.remove()),n.querySelectorAll("[data-flow-preview-source]").forEach(o=>{o.setAttribute("style","display:block;white-space:pre-wrap;font:16px/1.5 monospace;overflow-wrap:anywhere")}),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(n))}`}async function $b(e,r="squeed.svg"){const t=document.createElement("a");t.href=await Ob(e),t.download=r.endsWith(".svg")?r:`${r}.svg`,t.click()}function qb(){const{themeColor:e}=Ue(),[r,t]=j.useState(!1),[n,o]=j.useState("");return f.jsxs(f.Fragment,{children:[f.jsx(Ge,{label:"Download SVG (current view)",children:f.jsx(Ne,{"aria-label":"Download SVG",icon:f.jsx(Q.PiDownloadSimpleFill,{size:20}),disabled:r,borderRadius:"30%",color:e,variant:"ghost",onClick:async i=>{var a;const s=(a=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:a.querySelector("[data-flow-background]");if(!s){o("Diagram not available for export.");return}t(!0),o("");try{await $b(s)}catch(c){o(c instanceof Error?c.message:"Unable to export SVG.")}finally{t(!1)}}})}),n&&f.jsx("span",{role:"alert",style:{fontSize:12,maxWidth:220},children:n})]})}function ko({children:e,background:r,border:t,endElement:n,startElement:o,startElementWidth:i=44,framed:s=!0}){const a=j.useRef(null),[c,l]=j.useState({left:!1,right:!1});j.useLayoutEffect(()=>{const u=a.current;let h=u.parentElement.offsetWidth;const p=()=>{const y=u.parentElement.offsetWidth;if(y>0&&y!==h){const v=h/y;h=y,v>0&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches&&u.parentElement.animate({transform:[`scaleX(${v})`,"scaleX(1)"],transformOrigin:[n?"right center":"left center",n?"right center":"left center"]},{duration:180,easing:"ease-out",id:"flow-toolbar-grow"})}const b=u.scrollLeft>1,x=u.scrollWidth-u.clientWidth-u.scrollLeft>1;l(v=>v.left===b&&v.right===x?v:{left:b,right:x})},m=y=>{const b=y.target instanceof Element?y.target:null;if((b==null?void 0:b.closest("[data-flow-toolbar-scroll]"))!==u||b.closest("[popover], [data-flow-floating-panel]")!==u.closest("[popover], [data-flow-floating-panel]")||y.defaultPrevented||y.ctrlKey||s&&y.deltaX!==0||!(y.deltaX||y.deltaY)||u.scrollWidth<=u.clientWidth)return;y.preventDefault();const x=y.deltaMode===WheelEvent.DOM_DELTA_LINE?16:y.deltaMode===WheelEvent.DOM_DELTA_PAGE?u.clientWidth:1;u.scrollLeft+=(y.deltaX||y.deltaY)*x},g=new ResizeObserver(p);return g.observe(u),u.firstElementChild&&g.observe(u.firstElementChild),u.addEventListener("scroll",p,{passive:!0}),u.addEventListener("wheel",m,{passive:!1}),p(),()=>{g.disconnect(),u.removeEventListener("scroll",p),u.removeEventListener("wheel",m)}},[]);const d=`var(--chakra-colors-${r.replace(".","-")})`;return f.jsxs(W.Box,{position:"relative",bg:s?r:"transparent",minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:s?"30px":0,css:{...s?gr(d,`var(--chakra-colors-${t.replace(".","-")})`):{},...s||o?{"--flow-toolbar-start-width":o?`${i}px`:"0px"}:{}},children:[f.jsx(W.Box,{ref:a,"data-flow-toolbar-scroll":"",h:50,minH:50,alignContent:"center",overflowX:"auto",overflowY:"hidden",mr:n?"44px":void 0,ml:o?`${i}px`:void 0,borderRadius:"inherit",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e}),["left","right"].map(u=>f.jsx(W.Box,{"data-flow-toolbar-fade":u,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",borderRadius:u==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[u]:u==="right"&&n?44:u==="left"&&o?i:0,opacity:c[u]?1:0,background:`linear-gradient(to ${u==="left"?"right":"left"}, ${d}, transparent)`}},u)),n&&f.jsx(W.Box,{position:"absolute",right:"6px",top:0,h:"50px",w:"32px",display:"flex",alignItems:"center",justifyContent:"center",children:n}),o&&f.jsx(W.Box,{position:"absolute",left:"6px",top:0,h:"50px",w:`${i-12}px`,display:"flex",alignItems:"center",justifyContent:"center",children:o})]})}async function Uw(e,r){const t=new Set,n=[],o=(a,c)=>{var d,u,h;if(!a||typeof a!="object")return;const l=a;n.push(c),typeof((d=l.$form)==null?void 0:d.$type)=="string"&&t.add(l.$form.$type),typeof((h=(u=l.$form)==null?void 0:u.$create)==null?void 0:h.$type)=="string"&&t.add(l.$form.$create.$type);for(const[p,m]of Object.entries(l))p==="$"?o(m,c):p.startsWith("$")||o(m,`${c}.${p}`)};if(o(r,"root"),!t.size)return{contract:await jb(e)};const i=await Wd(e,[...t]);for(const a of t)if(!Object.prototype.hasOwnProperty.call(i,a))throw new Error(`Missing form type: ${a}`);const s={};for(const a of n){const c=un(r,a,i);c&&(s[a]={type:c.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:s}}}function Lb({message:e,onDismiss:r}){const{background:t,colorText:n,border:o}=at();return!e||typeof document>"u"?null:Wr.createPortal(f.jsxs(W.chakra.div,{role:"alert","aria-atomic":"true",css:gr(Me(t),Me(o)),onPointerDown:i=>i.stopPropagation(),onClick:i=>i.stopPropagation(),style:{position:"fixed",top:20,right:20,zIndex:1e4,width:360,maxWidth:"calc(100vw - 40px)",boxSizing:"border-box",display:"flex",alignItems:"flex-start",gap:10,padding:16,borderRadius:8,background:Me(t),color:Me(n),fontSize:14,lineHeight:1.5},children:[f.jsx(Q.PiWarningCircle,{size:20,"aria-hidden":"true",style:{flexShrink:0,color:"#ef4444"}}),f.jsxs("div",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:[f.jsx("strong",{children:"Interface upload failed"}),f.jsx("div",{children:e})]}),f.jsx(dn,{type:"button","aria-label":"Dismiss upload error",title:"Dismiss upload error",onClick:r,flexShrink:0,width:"24px",height:"24px",minWidth:"24px",padding:0})]}),document.body)}function Hd({showDivider:e=!0,compact:r=!1}={}){const{edgeMode:t,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:s,readOnly:a,themeColor:c,colorMode:l}=Ue(),{edgeById:d}=Xt(),{data:u,schema:h,setSchema:p,bindings:m,structured:g}=j.useContext($t),y=(g==null?void 0:g.sourceBindings)??m,b=(g==null?void 0:g.sourceSchema)??h,{colorText:x}=at(),v=j.useRef(null),w=j.useRef(0),[C,S]=j.useState(!1),[E,M]=j.useState("");j.useEffect(()=>()=>{w.current++},[]),j.useEffect(()=>{w.current++,S(!1)},[a,u,y]);const P=o?[...d.values()].filter(R=>Dd(o,R.data)).length:0,T=o?`${o.name}: ${b?`${Object.keys(b).length} form types loaded; `:""}${P} invalid or unverified connections`:"",k=jo(f.jsx(Hd,{showDivider:!1,compact:!0}));return f.jsx(nn.Provider,{value:null,children:f.jsxs("span",{style:{display:"contents"},onClickCapture:k,children:[f.jsx(Lb,{message:E,onDismiss:()=>M("")}),e&&f.jsx(Nn,{}),f.jsxs(It,{"aria-label":"Edge mode",title:t==="auto"?"Connections: Auto":t==="properties"?"Connections: Properties":"Connections: Nodes",icon:t==="auto"?f.jsx(Q.PiGraph,{size:20}):t==="properties"?f.jsx(Q.PiTable,{size:20}):f.jsx(Q.PiTreeStructure,{size:20}),style:{width:36},value:t,disabled:a,footer:s.onWorkflowConfigurationOpen&&f.jsxs(f.Fragment,{children:[f.jsx("hr",{style:{border:0,borderTop:"1px solid currentColor",opacity:.2,margin:"8px 0"}}),f.jsxs(W.Button,{"data-flow-menu-action":"",variant:"ghost",width:"100%",justifyContent:"flex-start",color:"inherit",bg:"transparent",css:ho,_hover:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},onClick:R=>{var _,N;(_=R.currentTarget.closest("[popover]"))==null||_.hidePopover(),(N=s.onWorkflowConfigurationOpen)==null||N.call(s)},children:[f.jsx(Q.PiGear,{}),"Configuration"]})]}),onValueChange:R=>{var N;const _=R==="auto"?"auto":R==="properties"?"properties":"nodes";n(_),(N=s.onEdgeModeChange)==null||N.call(s,_)},children:[f.jsx("option",{value:"auto",children:"Auto"}),f.jsx("option",{value:"nodes",children:"Nodes"}),f.jsx("option",{value:"properties",children:"Properties"})]}),f.jsxs("span",{style:{display:t==="auto"||t==="properties"?"contents":"none"},children:[f.jsx(Ge,{label:o?`Replace ${o.name}`:"Upload workflow interface",children:f.jsx(Ne,{"aria-label":"Upload workflow interface",icon:f.jsx(Q.PiUploadSimple,{size:20}),color:Me(c),size:"sm",variant:"ghost",disabled:C||a,onClick:()=>{var R;return(R=v.current)==null?void 0:R.click()}})}),f.jsx("input",{ref:v,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:a||C,onChange:async R=>{var $,V;const _=($=R.target.files)==null?void 0:$[0];if(R.target.value="",!_)return;const N=++w.current;S(!0),M("");try{const I=y?await Wd(_,[...new Set(Object.values(y).map(se=>se.schemaType??se.type))]):void 0;if(y&&I){for(const se of Object.values(y))if(!Object.prototype.hasOwnProperty.call(I,se.schemaType??se.type))throw new Error(`Missing form type: ${se.schemaType??se.type}`)}const{contract:F,schema:oe}=y&&I?{schema:I,contract:{name:_.name,nodes:Object.fromEntries(Object.entries(y).map(([se,H])=>[se,{type:I[H.schemaType??H.type],optional:!1}]))}}:await Uw(_,u);if(N!==w.current)return;p==null||p(oe),i(F),(V=s.onWorkflowContractChange)==null||V.call(s,F)}catch(I){N===w.current&&M(`${_.name}: ${I instanceof Error?I.message:"Unable to load interface."}`)}finally{N===w.current&&S(!1)}}}),!r&&(T||C)&&f.jsx("span",{role:"status",title:T,style:{color:Me(x),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:C?"Loading interface...":T}),!r&&o&&f.jsx(Ge,{label:"Remove workflow interface",children:f.jsx(Ne,{"aria-label":"Remove workflow interface",icon:f.jsx(Q.PiX,{size:16}),size:"sm",variant:"ghost",disabled:a||C,onClick:()=>{var R;p==null||p(void 0),i(void 0),(R=s.onWorkflowContractChange)==null||R.call(s,void 0),M("")}})})]})]})})}const Kw=[{value:"BT",label:"Bottom to Up",icon:Q.PiArrowUp,flowType:Sn.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:Q.PiArrowDown,flowType:Sn.TOP_DOWN},{value:"LR",label:"Left to Right",icon:Q.PiArrowRight,flowType:Sn.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:Q.PiArrowLeft,flowType:Sn.RIGHT_LEFT}],Fb=({nodeGridControlsTarget:e}={})=>{const{engineRef:r,themeColor:t,setThemeColor:n,edgeColor:o,setEdgeColor:i,backgroundSelected:s,setBackgroundSelected:a,direction:c,edgeMode:l,allNodesIconLabel:d,setAllNodesIconLabel:u,nodeGridOptions:h,selectedNodeIds:p,setSelectedNodeIds:m,selectedEdgeId:g,setSelectedEdgeId:y,isZoomMode:b,setIsZoomMode:x,isMultiSelectMode:v,setIsMultiSelectMode:w,isDragMode:C,setIsDragMode:S,isEdgeHandlesEnabled:E,setIsEdgeHandlesEnabled:M,isArrayNodeMode:P,setIsArrayNodeMode:T,isPinned:k,setIsPinned:R,callbacks:_,config:N,readOnly:$}=Ue(),{nodeById:V,edgeById:I,parentIds:F}=Xt(),oe=N.colorMode==="dark",{background:se,border:H,colorInactive:ee,colorText:ue,colorActive:q}=at(),D=oe?H:"gray.300",K=`var(--chakra-colors-${se.replace(".","-")})`,G=`var(--chakra-colors-${(oe?H:"gray.300").replace(".","-")})`,[ce,re]=j.useState(!1),[Z,ae]=j.useState(!0),ye=N.bottomBarCollapsed??Z,xe=j.useRef(null),fe=So({edge:"bottom",enabled:!k,bounds:xe,inside:[xe]}),U=j.useCallback(Ae=>{const Ke=r.current;if(!Ke)return;const lt=N.minZoom??.01,Je=N.maxZoom??1.5,yt=.02;let At=Ke.zoom();switch(Ae){case"increase":At=Math.min(Je,At+yt),Ke.zoom(At),Ke.center(!1);break;case"decrease":At=Math.max(lt,At-yt),Ke.zoom(At),Ke.center(!1);break;case"reset":Ke.fit(50);break}},[r,N.minZoom,N.maxZoom]),te=N.renderSelectedNodeToolbar,de=p.length>0&&!!te,Pe=j.useMemo(()=>de?p.map(Ae=>{var lt;return{...((lt=V.get(Ae))==null?void 0:lt.data)??{id:Ae},isParent:F.has(Ae)}}):[],[de,p,V,F]),ie=j.useCallback(()=>{var Ae;m([]),(Ae=_.onNodeDeselect)==null||Ae.call(_)},[m,_]),we=N.renderSelectedEdgeToolbar,$e=!!g&&!!we,He=j.useMemo(()=>{var Ae;return!$e||!g?null:((Ae=I.get(g))==null?void 0:Ae.data)??{id:g}},[$e,g,I]),Ve=j.useCallback(()=>{var Ae;y(null),(Ae=_.onEdgeDeselect)==null||Ae.call(_)},[y,_]),tt=N.selectionToolbar!==!1&&!$,me=tt&&!!g&&!we,Ie=tt&&!me&&p.length>0&&!te,De=me||Ie,be=k||fe||ce||De||N.bottomBarCollapsed===!1;j.useEffect(()=>{p.length||g?a(!1):$||(s&&R(!0),N.bottomBarCollapsed===void 0&&ae(!s))},[s,p.length,g,$,a,R,N.bottomBarCollapsed]);const Xe=N.renderBottomBar,ut=Iw();return Xe?f.jsxs(f.Fragment,{children:[de&&f.jsx(W.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:te({selectedNodeIds:p,selectedNodeData:Pe,onDeselect:ie})}),$e&&He&&f.jsx(W.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:we({edgeId:g,edgeData:He,onDeselect:Ve})}),f.jsx(W.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:Xe({zoomIn:()=>U("increase"),zoomOut:()=>U("decrease"),resetZoom:()=>U("reset"),direction:c,isZoomMode:b,setIsZoomMode:x,isMultiSelectMode:v,setIsMultiSelectMode:w,isDragMode:C,setIsDragMode:S,isEdgeHandlesEnabled:E,setIsEdgeHandlesEnabled:M,isArrayNodeMode:P,setIsArrayNodeMode:T,selectedNodeIds:p,selectedNodeData:Pe,selectedEdgeId:g,selectedEdgeData:He,onNodeDeselect:ie,onEdgeDeselect:Ve,callbacks:_})})]}):f.jsxs(nn.Provider,{value:ut,children:[de&&f.jsx(W.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:te({selectedNodeIds:p,selectedNodeData:Pe,onDeselect:ie})}),$e&&He&&f.jsx(W.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:we({edgeId:g,edgeData:He,onDeselect:Ve})}),f.jsx(W.Box,{ref:xe,role:"toolbar","aria-label":"Diagram controls",position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",transition:"opacity 0.3s ease-in, transform 0.3s ease",transform:be?"translateY(0)":"translateY(100%)",pointerEvents:be?"auto":"none",visibility:be?"visible":"hidden",opacity:be?1:0,css:{"& button > svg:not([popover] *)":{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",flexShrink:0},"@media (hover: none)":{visibility:"visible",opacity:1,transform:"none",pointerEvents:"auto"}},children:f.jsxs(W.Flex,{w:"100%",px:5,position:"absolute",bottom:"calc(20px + env(safe-area-inset-bottom, 0px))",flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:"24px",css:{"@media (min-width: 1024px)":{"& > :first-of-type":{maxWidth:"50vw"}}},children:[f.jsx(ko,{background:se,border:oe?H:"gray.300",children:f.jsxs(W.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[me?f.jsx(Tb,{edgeId:g,onClose:Ve}):Ie?f.jsx(Nb,{ids:p,onClose:ie}):null,f.jsxs("div",{style:{display:me||Ie?"none":"contents"},children:[f.jsxs("span",{style:{display:N.bottomBarNavigation===!1?"none":"contents"},children:[f.jsx(Ge,{label:k?"Unpin":"Pin",children:f.jsx(Ne,{"aria-label":"Pin",icon:f.jsx(W.Icon,{as:k?Q.PiPushPinFill:Q.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:k?t:ee,onClick:()=>{R(!k),re(!1)}})}),f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ge,{label:"Zoom Out",children:f.jsx(Ne,{"aria-label":"Zoom out",rememberAction:!1,icon:f.jsx(W.Icon,{as:Q.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:ue,onClick:()=>U("decrease")})}),f.jsx(Ge,{label:"Zoom In",children:f.jsx(Ne,{"aria-label":"Zoom in",rememberAction:!1,icon:f.jsx(W.Icon,{as:Q.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:ue,onClick:()=>U("increase")})}),f.jsx(Ge,{label:"Reset Zoom",children:f.jsx(Ne,{"aria-label":"Reset zoom",rememberAction:!1,icon:f.jsx(W.Icon,{as:Q.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:ue,onClick:()=>U("reset")})}),ye&&f.jsx(Nw,{visibleActions:h?["Collision mode","Fill",...h.fill?["Grid adjustment"]:[]]:[],divider:f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"})})]}),f.jsxs("span",{style:{display:ye?"none":"contents"},children:[f.jsxs("span",{style:{display:N.bottomBarNavigation===!1?"none":"contents"},children:[N.edgeHandles!==!1&&f.jsx(Ge,{label:E?"Draw Mode On (V)":"Draw Mode Off (V)",children:f.jsx(Ne,{"aria-label":"Toggle draw mode","aria-keyshortcuts":"V","aria-pressed":E,icon:f.jsx(W.Icon,{as:Q.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:E?t:ee,onClick:()=>M(!E)})}),f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ge,{label:b?"Zoom Mode (z)":"Pan Mode (z)",children:f.jsx(Ne,{"aria-label":"Toggle zoom mode",icon:f.jsx(W.Icon,{as:b?Q.PiMagnifyingGlassPlus:Q.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:b?t:ee,onClick:()=>x(!b)})}),f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ge,{label:v?"Multi-Select On (m)":"Multi-Select Off (m)",children:f.jsx(Ne,{"aria-label":"Toggle multi-select",icon:f.jsx(W.Icon,{as:Q.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:v?t:ee,onClick:()=>w(!v)})}),f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ge,{label:C?"Drag Mode On (d)":"Drag Mode Off (d)",children:f.jsx(Ne,{"aria-label":"Toggle drag mode",icon:f.jsx(W.Icon,{as:Q.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:C?t:ee,onClick:()=>S(!C)})})]}),N.bottomBarNavigation===!1&&(e===void 0?f.jsx(so,{}):e?Wr.createPortal(f.jsx(so,{}),e):null),N.bottomBarExtra&&f.jsxs(f.Fragment,{children:[N.bottomBarNavigation!==!1&&f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"}),N.bottomBarExtra]}),f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"}),f.jsx(vb,{})]}),f.jsx("span",{style:{display:N.bottomBarNavigation===!1||ye&&!h?"none":"contents"},children:f.jsx(so,{})}),f.jsxs("span",{style:{display:ye?"none":"contents"},children:[f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"}),f.jsx(xb,{}),l!=="properties"&&f.jsxs(f.Fragment,{children:[f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ge,{label:P?"Array Mode [ ]":"Set Mode { }",children:f.jsx(Ne,{"aria-label":"Toggle array mode",icon:f.jsx(W.Icon,{as:P?Q.PiBracketsSquare:Q.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:P?t:ee,onClick:()=>{var Ke;const Ae=!P;T(Ae),(Ke=_.onArrayModeChange)==null||Ke.call(_,Ae)}})})]}),f.jsx(Hd,{}),!$&&f.jsxs("span",{style:{display:s?"contents":"none"},children:[f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Vr,{label:"Graph theme",colors:po,value:t,includeTransparent:!1,onPick:Ae=>{var Ke;n(Ae),(Ke=_.onThemeColorChange)==null||Ke.call(_,Ae)}})]}),!$&&f.jsxs(f.Fragment,{children:[f.jsx(W.Icon,{as:Q.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"}),f.jsx(Vr,{label:"Graph edge color",colors:po,value:o||(oe?"gray.500":ln),onPick:i,onReset:()=>i("")}),f.jsx(W.Icon,{as:Q.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"})]}),f.jsx(wb,{})]}),f.jsx(W.Icon,{mx:-1,as:Q.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ge,{label:ye?"Expand toolbar":"Collapse toolbar",children:f.jsx(Ne,{"aria-label":"Toggle toolbar collapse",rememberAction:!1,icon:f.jsx(W.Icon,{as:ye?Q.PiCaretRight:Q.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:ee,onClick:()=>{var Ae;N.bottomBarCollapsed===void 0&&ae(!ye),a(ye),(Ae=_.onBottomBarCollapsedChange)==null||Ae.call(_,!ye)}})}),!ye&&f.jsx(qb,{})]})]})}),!De&&f.jsxs(W.Box,{position:"relative",ml:"auto",flexShrink:0,children:[f.jsx(W.Box,{"data-flow-direction-control":"",bg:se,borderRadius:"30px",h:50,css:gr(K,G),px:3,cursor:"pointer",onClick:()=>re(!ce),children:f.jsxs(W.Flex,{align:"center",h:"100%",children:[f.jsx(Ge,{label:"Flow Direction",children:f.jsx(Ne,{"aria-label":"Direction",onClick:Ae=>{Ae.stopPropagation(),re(!ce)},icon:f.jsx(W.Icon,{as:Q.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:ee})}),f.jsx(W.Text,{fontSize:"xs",textTransform:"uppercase !important",color:oe?"whiteAlpha.600":"blackAlpha.500",ml:1,children:c.toUpperCase()})]})}),ce&&f.jsx(W.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:f.jsxs(W.Box,{bg:se,borderRadius:"30px",p:2,minW:"180px",css:gr(K,G),children:[Kw.map(Ae=>f.jsxs(W.Flex,{align:"center",gap:3,px:3,py:2,css:ho,cursor:"pointer",_hover:{bg:oe?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ke;(Ke=_.onDirectionChange)==null||Ke.call(_,Ae.value),re(!1)},children:[f.jsx(W.Icon,{as:Ae.icon,boxSize:5,color:ue}),f.jsx(W.Text,{fontSize:"sm",color:ue,flex:1,whiteSpace:"nowrap",children:Ae.label}),c===Ae.value&&f.jsx(W.Icon,{as:Q.PiCheck,boxSize:4,color:q})]},Ae.value)),f.jsxs(W.Flex,{align:"center",gap:3,px:3,py:2,css:ho,cursor:"pointer",_hover:{bg:oe?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ae;(Ae=_.onDirectionChange)==null||Ae.call(_,"C"),re(!1)},children:[f.jsx(W.Icon,{as:Q.PiAlignCenterHorizontal,boxSize:5,color:ue}),f.jsx(W.Text,{fontSize:"sm",color:ue,flex:1,whiteSpace:"nowrap",children:"Center"}),c==="C"&&f.jsx(W.Icon,{as:Q.PiCheck,boxSize:4,color:q})]})]})})]})]})})]})};Fb.displayName="BottomBar";const zb=j.memo(Fb);function Jw({checked:e,onChange:r,disabled:t,label:n="Connected nodes"}){return f.jsx(on,{hideLabel:!0,label:n,helper:`${n}: isolate node and its connections`,checked:e,onChange:r,disabled:t,icon:f.jsx(W.Icon,{as:Q.PiGraph,boxSize:5})})}const Ku={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function Bb(e,r){const t=new Map,n=(i,s)=>{if(Object.is(i,s))return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const a=Object.keys(i);return a.length===Object.keys(s).length&&a.every(c=>Object.prototype.hasOwnProperty.call(s,c)&&n(i[c],s[c]))},o=(i,s,a)=>{if(i===s)return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const c=new Set([...Object.keys(i),...Object.keys(s)]);for(const l of c)if(!n(i[l],s[l])){if(Object.prototype.hasOwnProperty.call(Ku,l)){if(typeof s[l]!="string"||!s[l])return!1;t.set(a,{...t.get(a),[Ku[l]]:s[l]})}else if(l.startsWith("$")&&l!=="$"||!o(i[l],s[l],l==="$"?a:`${a}.${l}`))return!1}return!0};if(o(e,r,"root"))return t}function Zw(e,r){return Bb(e,r)!==void 0}function Xw(e,r,t){if(e===r)return t;const n=Bb(e,r);if(!n)return;const o=new Set(t.nodes.map(i=>i.data.id));for(const i of n.keys())if(!o.has(i)||!Oe(r,i))return;return{edges:t.edges,nodes:t.nodes.map(i=>{const s=n.get(i.data.id),a=Oe(e,i.data.id),c=Oe(r,i.data.id);return!s&&a===c?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(c,null,2)}:{},...s?{viewProps:{...i.data.viewProps,...s},config:{...i.data.config,...s}}:{}}}})}}function _d(e){return e.kind==="literal"?e.value:e.kind==="union"?_d(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,r])=>!r.optional).map(([r,t])=>[r,_d(t.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Db(e,r,t){var y,b,x;const n=(y=Oe(e,r))==null?void 0:y.$form,o=n==null?void 0:n.$create;if(!o)return;const i=o.$address.split(".");if(i.shift()!=="root"||!i.length||i.some(v=>!/^[A-Za-z0-9_-]+$/.test(v)||["__proto__","constructor","prototype"].includes(v)))throw new Error("Invalid form creation address.");if(!t||!Object.prototype.hasOwnProperty.call(t,o.$type))throw new Error(`Load form type: ${o.$type}`);const s=i.pop(),a=["root",...i].join("."),c=un(e,a,t),l=(b=c==null?void 0:c.type.properties[s])==null?void 0:b.type;if((l==null?void 0:l.kind)!=="array"||l.items.kind!=="object")throw new Error("Form creation must target an object-array field.");const d=t[o.$type],u=o.$defaults??{};for(const[v,w]of Object.entries(u))if(!Object.prototype.hasOwnProperty.call(d.properties,v)||Jt(d.properties[v].type,w,!d.properties[v].optional))throw new Error(`Invalid creation default: ${v}`);const h={..._d(d),...structuredClone(u)};((x=d.properties.id)==null?void 0:x.type.kind)==="string"&&(h.id=Td());let p=e;const m=Oe(e,o.$address);if(m===void 0)p=Pt(e,a,v=>({...v,[s]:[]}));else if(!Array.isArray(m)&&!Array.isArray(m==null?void 0:m.$))throw new Error("Form creation destination is not an array.");const g=$d(p,o.$address,{...h,$label:o.$label??o.$type,...o.$icon?{$icon:o.$icon}:{},$form:{$type:o.$type,$create:o}});return{address:g.address,json:qd(g.json,r,{target:g.address,label:o.$edgeLabel})}}function Yw(e,r,t){var i,s;if(Array.isArray(r)){const a=new Set(r);if(!Oe(e,t)||[...a].some(u=>u==="root"||!Oe(e,u)))throw new Error("The source or Parent no longer exists.");const c=new Set;let l=t;for(;l;){if(c.has(l)||[...a].some(h=>l===h||l.startsWith(`${h}.`)))throw new Error("A node cannot be moved inside itself or its descendants.");c.add(l);const u=(i=Oe(e,l))==null?void 0:i.$parent;l=typeof u=="string"?u:l.includes(".")?l.slice(0,l.lastIndexOf(".")):void 0}const d=(u,h)=>{let p=u;const m=(g,y)=>{p===u&&(p=Array.isArray(u)?[...u]:{...u}),p[g]=y};if(u&&typeof u=="object")for(const[g,y]of Object.entries(u)){if(g.startsWith("$")&&g!=="$")continue;const b=d(y,g==="$"?h:`${h}.${g}`);b!==y&&m(g,b)}return a.has(h)&&(p={...p&&typeof p=="object"&&!Array.isArray(p)?p:{$:p},$parent:t}),p};return uo(d(e,"root"),t,!1)}if(r=r,r==="root"||!Oe(e,r)||!Oe(e,t))throw new Error("The source or Parent no longer exists.");const n=new Set;let o=t;for(;o;){if(o===r||o.startsWith(`${r}.`)||n.has(o))throw new Error("A node cannot be moved inside itself or its descendants.");n.add(o);const a=(s=Oe(e,o))==null?void 0:s.$parent;o=typeof a=="string"?a:o.includes(".")?o.slice(0,o.lastIndexOf(".")):void 0}return uo(Pt(e,r,a=>({...a,$parent:t})),t,!1)}function Wb(e,r){const t=new Set(r.filter(a=>Oe(e,a)!==void 0)),n=[],o=(a,c)=>{if(!(!a||typeof a!="object")){n.push([c,a]);for(const[l,d]of Object.entries(a))l.startsWith("$")||o(d,`${c}.${l}`)}};o(e,"root");const i=a=>[...t].some(c=>a===c||a.startsWith(`${c}.`));let s=!0;for(;s;){s=!1;for(const[a,c]of n)!i(a)&&typeof c.$parent=="string"&&i(c.$parent)&&(t.add(a),s=!0)}return[...t].filter(a=>![...t].some(c=>c!==a&&a.startsWith(`${c}.`)))}function Ud(e,r){const t=Wb(e,r),n=new Map(t.map((a,c)=>[a,`root.node_${c+1}`])),o=a=>{const c=t.find(l=>a===l||a.startsWith(`${l}.`));return c?`${n.get(c)}${a.slice(c.length)}`:void 0},i=a=>{if(!(!a||typeof a!="object")){Array.isArray(a.$connections)&&(a.$connections=a.$connections.flatMap(c=>{const l=typeof c.target=="string"&&o(c.target);return l?[{...c,id:void 0,target:l}]:[]}));for(const c of["$parent","$target"])if(typeof a[c]=="string"){const l=o(a[c]);l?a[c]=l:delete a[c]}for(const[c,l]of Object.entries(a))c.startsWith("$")||i(l)}},s={$hideRoot:!0};return t.forEach((a,c)=>{const l=structuredClone(Oe(e,a));i(l),s[`node_${c+1}`]=l}),s}function Vb(e,r){const t=Ud(e,r),n=Object.keys(t).filter(a=>!a.startsWith("$")),o=new Map(n.map(a=>[a,`copy_${crypto.randomUUID()}`])),i=a=>{if(!a||typeof a!="object")return;const c=l=>{const d=l.split(".");return d[0]==="root"&&o.has(d[1])&&(d[1]=o.get(d[1])),d.join(".")};for(const l of a.$connections??[])l.target=c(l.target),l.id=crypto.randomUUID();for(const l of["$parent","$target"])typeof a[l]=="string"&&(a[l]=c(a[l]));for(const[l,d]of Object.entries(a))l.startsWith("$")||i(d)},s=Object.fromEntries(n.map(a=>{const c=t[a];return i(c),[o.get(a),c]}));return{json:Pt(e,"root",a=>({...a,...s})),ids:[...o.values()].map(a=>`root.${a}`)}}function Qw(e,r){const t=o=>e&&typeof e=="object"&&o in e;let n=1;for(;t(`${r}_${n}`);)n++;return`${r}_${n}`}function Gb(e,r,t,n,o){const i=(a,c)=>{var h;if(a===e)return;const l=c.type.startsWith("node")&&c.type!=="nodeDelete",d=c.nodeAddresses??(l&&c.address?[c.address]:[]),u=d.length?(h=t.getNodeEditMetadata)==null?void 0:h.call(t):void 0;for(const p of d)JSON.stringify(Oe(a,p))!==JSON.stringify(Oe(e,p))&&(a=sb(a,p,u));e=a,n==null||n(a,c)},s=a=>{var l;const c=(l=r.find(d=>d.data.id===a))==null?void 0:l.data;return c&&{source:c.source,target:c.target,isInverted:c.isInverted,sourceProperty:c.sourceProperty,targetProperty:c.targetProperty,connection:c.connection}};return{...t,onNodesCopy:async a=>{var c;await((c=t.onNodesCopy)==null?void 0:c.call(t,a))!==!0&&await navigator.clipboard.writeText(JSON.stringify(Ud(e,a),null,2))},onNodesDuplicate:a=>{var l;if(((l=t.onNodesDuplicate)==null?void 0:l.call(t,a))===!0)return;const c=Vb(e,a);i(c.json,{type:"nodeCreate",address:c.ids[0],nodeAddresses:c.ids})},onFormChange:a=>{const c=Oe(e,a.nodeAddress);if(!c||a.nodeId!==void 0&&c.id!==a.nodeId)throw new Error("This form node has moved. Retry the edit.");i(_o(e,a,t.onFormChange),{type:"form",address:a.address,nodeAddresses:[a.nodeAddress],value:a.value})},onNodeLabelChange:(a,c)=>{var l;(l=t.onNodeLabelChange)==null||l.call(t,a,c),i(kt(e,a,"$label",c),{type:"nodeLabel",address:a,key:"$label",value:c})},onNodeContentChange:(a,c)=>{var l;(l=t.onNodeContentChange)==null||l.call(t,a,c),i(kt(e,a,"$content",c),{type:"nodeContent",address:a,key:"$content",value:c})},onNodeTypeViewChange:(a,c)=>{var l;c!==void 0&&!Ld.includes(c)||((l=t.onNodeTypeViewChange)==null||l.call(t,a,c),i(kt(e,a,"$view",c),{type:"nodeStyle",address:a,key:"$view",value:c}))},onNodeColorChange:(a,c,l)=>{var u;(u=t.onNodeColorChange)==null||u.call(t,a,c,l);const d=c==="bg"?"$bgColor":"$textColor";i(kt(e,a,d,l),{type:"nodeColor",address:a,key:d,value:l})},onNodeBorderColorChange:(a,c)=>{var l;(l=t.onNodeBorderColorChange)==null||l.call(t,a,c),i(kt(e,a,"$borderColor",c),{type:"nodeColor",address:a,key:"$borderColor",value:c})},onNodeBorderStyleChange:(a,c)=>{var l;(l=t.onNodeBorderStyleChange)==null||l.call(t,a,c),i(kt(e,a,"$borderStyle",c),{type:"nodeStyle",address:a,key:"$borderStyle",value:c})},onNodeBorderWidthChange:(a,c)=>{var l;c!==void 0&&(!Number.isFinite(c)||c<0)||((l=t.onNodeBorderWidthChange)==null||l.call(t,a,c),i(kt(e,a,"$borderWidth",c),{type:"nodeStyle",address:a,key:"$borderWidth",value:c}))},onNodeBorderRadiusChange:(a,c)=>{var l;c!==void 0&&(!Number.isFinite(c)||c<0)||((l=t.onNodeBorderRadiusChange)==null||l.call(t,a,c),i(kt(e,a,"$borderRadius",c),{type:"nodeStyle",address:a,key:"$borderRadius",value:c}))},onNodeIconChange:(a,c)=>{var l;(l=t.onNodeIconChange)==null||l.call(t,a,c),i(kt(e,a,"$icon",c),{type:"nodeIcon",address:a,key:"$icon",value:c})},onNodeOutlineChange:(a,c)=>{var l;(l=t.onNodeOutlineChange)==null||l.call(t,a,c),i(kt(e,a,"$outline",c),{type:"nodeOutline",address:a,key:"$outline",value:c})},onNodeAnimationChange:(a,c)=>{var l;(l=t.onNodeAnimationChange)==null||l.call(t,a,c),i(kt(e,a,"$isNodeAnimated",c),{type:"nodeAnimation",address:a,key:"$isNodeAnimated",value:c})},onNodeAnimationVariantChange:(a,c)=>{var l;c!=="traveling"&&c!=="pulse"||((l=t.onNodeAnimationVariantChange)==null||l.call(t,a,c),i(kt(e,a,"$nodeAnimationVariant",c),{type:"nodeAnimation",address:a,key:"$nodeAnimationVariant",value:c}))},onNodeCollapse:(a,c)=>{var l;(l=t.onNodeCollapse)==null||l.call(t,a,c),i(uo(e,a,c),{type:"nodeCollapse",address:a,key:"$collapsed",value:c})},onNodeCreate:a=>{var x;if(((x=t.onNodeCreate)==null?void 0:x.call(t,a))===!0)return;const c=a.sourceNodeId||"root",l=Oe(e,c),d=!!a.sourceNodeId&&a.isArrayMode&&!(l!=null&&l.$arrayDrawInitialized),u=Array.isArray(l==null?void 0:l.$)?l.$:l,h=new Set(Object.entries(u??{}).filter(([v])=>!v.startsWith("$")).map(([,v])=>v==null?void 0:v.$label));let p=1,m=e,g;const y=[];let b=a.isArrayMode?"array":"set";for(let v=0;v<(d?2:1);v++){const w=a.sourceNodeId&&Db(m,a.sourceNodeId,o);if(w){m=w.json,g??(g=w.address),y.push(w.address),b="form";continue}for(;h.has(`Untitled ${p}`);)p++;const C=`Untitled ${p++}`,S=Qw(Oe(m,c),a.isArrayMode?"list":"node"),E=a.isArrayMode?{$bgColor:"gray.500",$label:C,$:[]}:{$bgColor:"gray.500",$label:C},M=$d(m,c,E,S);m=M.json,g??(g=M.address),y.push(M.address)}d&&(m=Pt(m,c,v=>Array.isArray(v)?{$:v,$arrayDrawInitialized:!0}:{...v,$arrayDrawInitialized:!0})),i(m,{type:"nodeCreate",address:g,nodeAddresses:y,value:b})},onNodeDelete:(a,c)=>{var l;(l=t.onNodeDelete)==null||l.call(t,a,c),i(lb(e,a),{type:"nodeDelete",address:a})},onEdgeCreate:(a,c,l)=>{var u;(u=t.onEdgeCreate)==null||u.call(t,a,c,l);const d=l&&(l.sourceProperty!==void 0||l.targetProperty!==void 0)?{...l,target:c}:void 0;i(d?qd(e,a,d):db(e,a,c),{type:"edgeCreate",address:a,key:d?"$connections":"$target",value:d??c})},onEdgeLabelChange:(a,c)=>{var d;(d=t.onEdgeLabelChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$sourceLabel",c),{type:"edgeLabel",edge:l,key:l.connection?"$connections":"$sourceLabel",value:c})},onEdgeStyleChange:(a,c)=>{var d;(d=t.onEdgeStyleChange)==null||d.call(t,a,c);const l=s(a);l&&i(cb(e,l,c),{type:"edgeStyle",edge:l,value:c})},onEdgeAnimationVariantChange:(a,c)=>{var d;if(c!=="dashed"&&c!=="traveling")return;(d=t.onEdgeAnimationVariantChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$edgeAnimationVariant",c),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeAnimationVariant",value:c})},onEdgeTypeChange:(a,c)=>{var d;(d=t.onEdgeTypeChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$edgeType",c),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeType",value:c})},onEdgeIconChange:(a,c)=>{var d;(d=t.onEdgeIconChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$edgeIcon",c||void 0),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeIcon",value:c})},onEdgeColorChange:(a,c)=>{var d;(d=t.onEdgeColorChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$edgeColor",c),{type:"edgeColor",edge:l,key:l.connection?"$connections":"$edgeColor",value:c})},onEdgeDelete:(a,c)=>{var u;(u=t.onEdgeDelete)==null||u.call(t,a,c);const l=s(a);if(!l)return;const d=ub(e,l);d.removed&&i(d.json,{type:"edgeDelete",edge:l,key:l.connection?"$connections":"$target"})}}}const e1=".flow-sdk-edge-reveal{animation:flow-sdk-edge-reveal var(--flow-edge-reveal-duration,600ms) linear both;animation-play-state:var(--flow-edge-reveal-state,running)}.flow-sdk-edge-reveal-end{animation:flow-sdk-edge-reveal-end var(--flow-edge-reveal-duration,600ms) steps(1,end) both;animation-play-state:var(--flow-edge-reveal-state,running)}@keyframes flow-sdk-edge-reveal{from{stroke-dashoffset:var(--flow-edge-reveal-from,100)}to{stroke-dashoffset:0}}@keyframes flow-sdk-edge-reveal-end{from{opacity:0}to{opacity:1}}@media(prefers-reduced-motion:reduce){.flow-sdk-edge-reveal{animation:none;stroke-dashoffset:0}.flow-sdk-edge-reveal-end{animation:none;opacity:1}}";function t1({path:e,width:r,reversed:t,children:n,onComplete:o}){const i=`flow-edge-reveal-${j.useId().replace(/:/g,"")}`,s=j.useRef(null),[a,c]=j.useState({x:0,y:0,width:1,height:1});return j.useEffect(()=>{const l=matchMedia("(prefers-reduced-motion: reduce)"),d=()=>{l.matches&&(o==null||o())};return d(),l.addEventListener("change",d),()=>l.removeEventListener("change",d)},[o]),j.useLayoutEffect(()=>{var d;const l=(d=s.current)==null?void 0:d.getBBox();l&&c({x:l.x-r,y:l.y-r,width:l.width+r*2,height:l.height+r*2})},[e,r]),f.jsxs(f.Fragment,{children:[f.jsx("defs",{children:f.jsx("mask",{id:i,maskUnits:"userSpaceOnUse",...a,children:f.jsx("path",{ref:s,className:"flow-sdk-edge-reveal",onAnimationEnd:l=>{l.animationName==="flow-sdk-edge-reveal"&&(o==null||o())},"data-reveal-direction":t?"reverse":"forward",style:{"--flow-edge-reveal-from":t?-100:100},d:e,fill:"none",stroke:"white",strokeWidth:r,strokeLinecap:"butt",strokeLinejoin:"round",pathLength:100,strokeDasharray:"100 100"})})}),f.jsx("g",{mask:`url(#${i})`,children:n})]})}const r1=".flow-sdk-edge-trace{pointer-events:none;animation:flow-sdk-edge-trace 2.4s linear infinite}.flow-sdk-edge-trace-reverse{animation-direction:reverse}@keyframes flow-sdk-edge-trace{from{stroke-dashoffset:18}to{stroke-dashoffset:-100}}@media(prefers-reduced-motion:reduce){.flow-sdk-edge-trace,.flow-sdk-edge-anim{animation:none}}";function n1({path:e,color:r,width:t,reversed:n}){return f.jsx("path",{className:`flow-sdk-edge-trace${n?" flow-sdk-edge-trace-reverse":""}`,"data-animation-variant":"traveling","aria-hidden":"true",pointerEvents:"none",d:e,fill:"none",stroke:r,strokeWidth:t,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 100"})}const Hb=".flow-sdk-node-animation{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none;z-index:1}.flow-sdk-node-border-animation{pointer-events:none;animation:flow-sdk-node-border 2.4s linear infinite}.flow-sdk-node-border-pulse{stroke-width:var(--flow-pulse-rest-width);animation:flow-sdk-node-pulse 1.8s ease-in-out infinite}@keyframes flow-sdk-node-border{from{stroke-dashoffset:0}to{stroke-dashoffset:-100}}@keyframes flow-sdk-node-pulse{0%,100%{stroke-width:var(--flow-pulse-rest-width)}50%{stroke-width:var(--flow-pulse-expanded-width)}}@media(prefers-reduced-motion:reduce){.flow-sdk-node-border-animation{animation:none}}";function go({x:e=0,y:r=0,width:t,height:n,radius:o,color:i,strokeWidth:s=8,path:a,variant:c="traveling"}){const l=j.useId(),d=`flow-sdk-node-border-animation${c==="pulse"?" flow-sdk-node-border-pulse":""}`;if(c==="pulse"){const u=a?"path":"rect",h=a?{d:a}:{x:e,y:r,width:Math.max(0,t),height:Math.max(0,n),rx:Math.max(0,Math.min(o,t/2,n/2))},p=s+36,m={x:e-p,y:r-p,width:t+2*p,height:n+2*p};return f.jsxs("g",{"aria-hidden":"true",pointerEvents:"none",children:[f.jsx("defs",{children:f.jsxs("mask",{id:l,maskUnits:"userSpaceOnUse",...m,style:{maskType:"luminance"},children:[f.jsx("rect",{...m,fill:"white"}),f.jsx(u,{...h,fill:"black",stroke:"black",strokeWidth:s,strokeLinejoin:"round"})]})}),f.jsx(u,{...h,className:d,"data-animation-variant":c,fill:"none",stroke:`color-mix(in srgb, ${i} 30%, transparent)`,strokeLinejoin:"round",mask:`url(#${l})`,style:{"--flow-pulse-rest-width":`${s+16}px`,"--flow-pulse-expanded-width":`${s+36}px`}})]})}return a?f.jsx("path",{className:d,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",d:a,fill:"none",stroke:i,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"}):f.jsx("rect",{className:d,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",x:e,y:r,width:Math.max(0,t),height:Math.max(0,n),rx:Math.max(0,Math.min(o,t/2,n/2)),fill:"none",stroke:i,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const o1=e=>{const n=1/(Math.cbrt(e)*.8);let o=Math.round(650*n),i=Math.round(350*n);return o=Math.max(40,Math.min(450,o)),i=Math.max(30,Math.min(300,i)),{edgeSep:o,rankSep:i}};function Ub(e,r=!1){return e&&!r&&typeof requestAnimationFrame<"u"&&!(typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches)}function Kb(e,r,t=()=>{},n=300){let o,i,s=!1;const a=()=>{s=!0,o!==void 0&&cancelAnimationFrame(o),clearTimeout(i)},c=()=>{s||(a(),r(1),t())};if(!Ub(e))return c(),a;const l=performance.now(),d=u=>{if(s)return;const h=Math.max(0,Math.min(1,(u-l)/n));if(h>=1)return c();r(h<.5?4*h**3:1-(-2*h+2)**3/2),s||(o=requestAnimationFrame(d))};return o=requestAnimationFrame(d),i=setTimeout(c,n+100),a}function Ju(e,r,t){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const s of r)(s.parent===i||s.id.startsWith(`${i}.`)||t.some(c=>(c.inverted?c.target:c.source)===i&&(c.inverted?c.source:c.target)===s.id))&&!n.has(s.id)&&(n.add(s.id),o.push(s.id))}return n}function i1(e,r,t){const n=t==="downward"||t==="upward",o=new Map;for(const s of e){if(s.source===s.target||s.sourceProperty||s.targetProperty)continue;const a=r(s.source),c=r(s.target);if(!a||!c)continue;const l=n?c.y-a.y:c.x-a.x,d=Math.abs(l)-(n?a.h+c.h:a.w+c.w)/2;if(d<=320)continue;const u=JSON.stringify([s.source,Math.sign(l)]),h=o.get(u)??[];h.push({edge:s,gap:d,cross:n?c.x-a.x:c.y-a.y}),o.set(u,h)}const i=new Map;for(const s of o.values()){if(new Set(s.map(({edge:c})=>c.target)).size<2)continue;const a=new Map;for(const{edge:c}of s)a.set(c.target,(a.get(c.target)??0)+1);for(const c of[-1,0,1]){const l=s.filter(({cross:u})=>Math.sign(u)===c);l.sort((u,h)=>Math.abs(h.cross)-Math.abs(u.cross)||u.edge.id.localeCompare(h.edge.id));const d=Math.min(...l.map(({gap:u})=>u));l.forEach(({edge:u,gap:h,cross:p},m)=>{const g=l.length===1?d/2:120+(d-280)*m/(l.length-1),y=l.find(b=>Math.abs(b.cross)<Math.abs(p));i.set(u.id,{turn:g/h,labelAtTarget:a.get(u.target)===1,labelFraction:p?(p+((y==null?void 0:y.cross)??0))/(2*p):.5})})}}return i}const ir=e=>({x1:e.x-e.w/2,y1:e.y-e.h/2,x2:e.x+e.w/2,y2:e.y+e.h/2}),a1=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function ei(e){if(!e.length)return null;const r={...e[0]};for(let t=1;t<e.length;t++)r.x1=Math.min(r.x1,e[t].x1),r.y1=Math.min(r.y1,e[t].y1),r.x2=Math.max(r.x2,e[t].x2),r.y2=Math.max(r.y2,e[t].y2);return r}const s1=(e,r)=>e.x1<=r.x2&&e.x2>=r.x1&&e.y1<=r.y2&&e.y2>=r.y1,Zu=(e,r)=>e.x>=r.x1&&e.x<=r.x2&&e.y>=r.y1&&e.y<=r.y2,Bt=e=>(Math.round(e*10)/10).toString(),xt=e=>`${Bt(e.x)} ${Bt(e.y)}`,c1=e=>e>0?1:e<0?-1:0,Xu=(e,r)=>e>0?Math.max(e-r,0):Math.min(e+r,0);function l1(e,r,t,n,o=10){const i=r.x-e.x,s=r.y-e.y,a=Xu(i,(e.w+r.w)/2),c=Xu(s,(e.h+r.h)/2),l=t==="downward"||t==="upward",d=l?c:a,u=l?s:i,h=c1(u),p=n*d,m=x=>Math.abs(x)<o||Math.abs(x)>=Math.abs(d),g=m(p)||m(Math.abs(d)-Math.abs(p));let y;if(g)if(l)if(Math.abs(u)<=e.h/2){const x=(e.x+r.x)/2;y=[x,e.y,x,r.y]}else if(Math.abs(i)<=r.w/2){const x=(e.y+r.y)/2;y=[e.x,x,r.x,x]}else y=[e.x,r.y];else if(Math.abs(u)<=e.w/2){const x=(e.y+r.y)/2;y=[e.x,x,r.x,x]}else if(Math.abs(s)<=r.h/2){const x=(e.x+r.x)/2;y=[x,e.y,x,r.y]}else y=[r.x,e.y];else if(l){const x=e.y+p+e.h/2*h;y=[e.x,x,r.x,x]}else{const x=e.x+p+e.w/2*h;y=[x,e.y,x,r.y]}const b=[{x:e.x,y:e.y}];for(let x=0;x<y.length;x+=2)b.push({x:y[x],y:y[x+1]});return b.push({x:r.x,y:r.y}),b}function d1(e,r,t){const n=r.x-e.x,o=r.y-e.y,i=n>0?(t.x2-e.x)/n:n<0?(t.x1-e.x)/n:1/0,s=o>0?(t.y2-e.y)/o:o<0?(t.y1-e.y)/o:1/0,a=Math.min(i,s);return!Number.isFinite(a)||a>=1||a<0?null:{x:e.x+n*a,y:e.y+o*a}}function sn(e,r,t){var s;if(!((s=t.outline)!=null&&s.length))return d1(e,r,ir(t));const n=r.x-e.x,o=r.y-e.y;let i=1/0;return t.outline.forEach((a,c,l)=>{const d=l[(c+1)%l.length],u=d.x-a.x,h=d.y-a.y,p=n*h-o*u;if(Math.abs(p)<1e-9)return;const m=a.x-e.x,g=a.y-e.y,y=(m*h-g*u)/p,b=(m*o-g*n)/p;y>=0&&y<1&&b>=-1e-9&&b<=1+1e-9&&(i=Math.min(i,y))}),Number.isFinite(i)?{x:e.x+n*i,y:e.y+o*i}:null}function Jb(e,r,t=.5){const n=Number.isFinite(t)?Math.max(0,Math.min(1,t)):.5,o=r==="top"||r==="bottom",i=r==="top"||r==="left"?-1:1,s={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},a=Math.max(e.w,e.h)*2+1;return{...sn(s,{x:s.x+(o?0:i*a),y:s.y+(o?i*a:0)},e)??{x:o?s.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:s.y},side:r}}function Qr(e,r){return{x:e.x+(e.side==="right"?r:e.side==="left"?-r:0),y:e.y+(e.side==="bottom"?r:e.side==="top"?-r:0)}}function u1(e,r,t,n){const o=Qr(e,t.srcDist),i=Qr(r,t.tgtDist);if(n==="straight")return Xb(o,i,t);const s=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),a=e.side==="bottom"&&r.side==="top"?i.y-o.y:e.side==="top"&&r.side==="bottom"?o.y-i.y:e.side==="right"&&r.side==="left"?i.x-o.x:e.side==="left"&&r.side==="right"?o.x-i.x:void 0,c=a!==void 0&&a>0?Math.min(s,a/2):s,l=Qr({...o,side:e.side},c),d=Qr({...i,side:r.side},c),u=t.arrowAt==="source"?jt(o,l,t.arrowGap):o,h=t.arrowAt==="target"?jt(i,d,t.arrowGap):i,p=t.arrowAt==="source"?Wt(o,l,t.arrowSize,t.headShape):t.arrowAt==="target"?Wt(i,d,t.arrowSize,t.headShape):void 0;if(n==="bezier")return{d:`M${xt(u)} C${xt(l)} ${xt(d)} ${xt(h)}`,arrow:p,label:{x:(u.x+3*l.x+3*d.x+h.x)/8,y:(u.y+3*l.y+3*d.y+h.y)/8,angle:0}};const m=e.side==="left"||e.side==="right",g=r.side==="left"||r.side==="right";let y;if(m!==g){const x=m?{x:d.x,y:l.y}:{x:l.x,y:d.y},v=(x.x-l.x)*(l.x-o.x)+(x.y-l.y)*(l.y-o.y)>=0,w=(x.x-d.x)*(d.x-i.x)+(x.y-d.y)*(d.y-i.y)>=0;y=[v&&w?x:m?{x:l.x,y:d.y}:{x:d.x,y:l.y}]}else if(a!==void 0&&a<=0)if(m){const x=(l.y+d.y)/2;y=[{x:l.x,y:x},{x:d.x,y:x}]}else{const x=(l.x+d.x)/2;y=[{x,y:l.y},{x,y:d.y}]}else if(m){const x=e.side===r.side?e.side==="right"?Math.max(l.x,d.x):Math.min(l.x,d.x):(l.x+d.x)/2;y=[{x,y:l.y},{x,y:d.y}]}else{const x=e.side===r.side?e.side==="bottom"?Math.max(l.y,d.y):Math.min(l.y,d.y):(l.y+d.y)/2;y=[{x:l.x,y:x},{x:d.x,y:x}]}const b=[l,...y,d].filter((x,v,w)=>v===0||x.x!==w[v-1].x||x.y!==w[v-1].y);return Po(u,b,h,p,n==="orthogonal"?0:t.radius)}function jt(e,r,t){const n=e.x-r.x,o=e.y-r.y,i=Math.hypot(n,o);if(!i)return e;let s=(i-t)/i;return s<0&&(s=1e-5),{x:r.x+s*n,y:r.y+s*o}}function Wt(e,r,t,n="triangle"){const o=e.x-r.x,i=e.y-r.y,s=Math.hypot(o,i)||1,a=o/s,c=i/s,l=(n==="square"?.15:.3)*t,d=.15*t,u=e.x-a*l,h=e.y-c*l;if(n==="square")return`M${xt(e)} L${Bt(e.x-c*d)} ${Bt(e.y+a*d)} L${Bt(u-c*d)} ${Bt(h+a*d)} L${Bt(u+c*d)} ${Bt(h-a*d)} L${Bt(e.x+c*d)} ${Bt(e.y-a*d)} Z`;const p=[e,{x:u-c*d,y:h+a*d},{x:u+c*d,y:h-a*d}];return p.map((g,y)=>{const b=p[(y+2)%3],x=p[(y+1)%3],v=Math.hypot(b.x-g.x,b.y-g.y),w=Math.hypot(x.x-g.x,x.y-g.y),C={x:(b.x-g.x)/v,y:(b.y-g.y)/v},S={x:(x.x-g.x)/w,y:(x.y-g.y)/w},E=Math.max(-1,Math.min(1,C.x*S.x+C.y*S.y)),M=Math.sqrt((1-E)/(1+E)),P=Math.min(1/M,v/2,w/2);return{start:{x:g.x+C.x*P,y:g.y+C.y*P},end:{x:g.x+S.x*P,y:g.y+S.y*P},radius:P*M}}).map((g,y)=>`${y?"L":"M"}${xt(g.start)} A${Bt(g.radius)} ${Bt(g.radius)} 0 0 1 ${xt(g.end)}`).join(" ")+" Z"}function Cr(e,r){let t=Math.atan(r/e);return e===0&&t<0&&(t=-t),Number.isFinite(t)||(t=0),t*180/Math.PI}function f1(e,r,t,n){const o={x:r.x-e.x,y:r.y-e.y},i={x:t.x-r.x,y:t.y-r.y},s=Math.hypot(o.x,o.y),a=Math.hypot(i.x,i.y),c=o.x*i.y-o.y*i.x;if(s<1e-6||a<1e-6||Math.abs(c)<1e-6)return{p1:r,b:r,p2:r,r:0};const l=Math.min(n,s/2,a/2);return{p1:{x:r.x-o.x/s*l,y:r.y-o.y/s*l},b:r,p2:{x:r.x+i.x/a*l,y:r.y+i.y/a*l},r:l}}function Zb(e,r,t,n){let o=-1,i=null;for(let m=0;m<e.length-1;m++){const g=sn(e[m],e[m+1],r);if(g){o=m,i=g;break}}let s=-1,a=null;for(let m=e.length-1;m>0;m--){const g=sn(e[m],e[m-1],t);if(g){s=m,a=g;break}}if(!i||!a||o>=s)return null;const c=e.slice(o+1,s),l=c[0]??a,d=c[c.length-1]??i;let u,h,p;if(n.arrowAt==="source"){const m=jt(i,l,n.srcDist);u=jt(i,l,n.srcDist+n.arrowGap),p=Wt(m,l,n.arrowSize,n.headShape)}else u=jt(i,l,n.srcDist);if(n.arrowAt==="target"){const m=jt(a,d,n.tgtDist);h=jt(a,d,n.tgtDist+n.arrowGap),p=Wt(m,d,n.arrowSize,n.headShape)}else h=jt(a,d,n.tgtDist);return Po(u,c,h,p,n.radius,n.labelTargetLength,n.labelFraction)}function Po(e,r,t,n,o,i,s){var h;const a=[e,...r,t],c=[];let l=`M${xt(e)}`;for(let p=1;p<a.length-1;p++){const m=f1(a[p-1],a[p],a[p+1],o);c.push(m),m.r===0?l+=` L${xt(m.b)}`:l+=` L${xt(m.p1)} Q${xt(m.b)} ${xt(m.p2)}`}l+=` L${xt(t)}`;let d;const u=r.length;if(u===0)d={x:(e.x+t.x)/2,y:(e.y+t.y)/2,angle:Cr(t.x-e.x,t.y-e.y)};else if(u%2===0){const p=r[u/2-1],m=r[u/2];d={x:(p.x+m.x)/2,y:(p.y+m.y)/2,angle:Cr(m.x-p.x,m.y-p.y)}}else{const p=c[(u-1)/2];if(p.r===0){const m=a[(u-1)/2+2];d={x:p.b.x,y:p.b.y,angle:Cr(m.x-p.b.x,m.y-p.b.y)}}else d={x:.25*p.p1.x+.5*p.b.x+.25*p.p2.x,y:.25*p.p1.y+.5*p.b.y+.25*p.p2.y,angle:Cr(p.p2.x-p.p1.x,p.p2.y-p.p1.y)}}if(i!==void 0){if(s!==void 0&&c.length===2){const y=c[0].p2,b=c[1].p1,x=Math.hypot(b.x-y.x,b.y-y.y),v=Math.min(.5,i/(2*x)),w=Math.max(v,Math.min(1-v,s));d={x:y.x+(b.x-y.x)*w,y:y.y+(b.y-y.y)*w,angle:Cr(b.x-y.x,b.y-y.y)}}const p=((h=c[c.length-1])==null?void 0:h.p2)??e,m=t.x-p.x,g=t.y-p.y;Math.hypot(m,g)>=i&&(d={x:(p.x+t.x)/2,y:(p.y+t.y)/2,angle:Cr(m,g)})}return{d:l,arrow:n,label:d}}function Yu(e,r,t,n,o,i,s){const a=t==="leftward"?-1:1,c={x:e.x+a*(e.w/2+s.srcDist),y:n??e.y},l={x:r.x-a*(r.w/2+s.tgtDist),y:o??r.y},d=Math.max(80,s.arrowGap+s.arrowSize*.3),u=c.x+a*d,h=l.x-a*d;let p;if(a*(h-u)>=0){const b=c.x+(l.x-c.x)*i,x=Math.max(Math.min(u,h),Math.min(Math.max(u,h),b));p=[{x,y:c.y},{x,y:l.y}]}else{const b=Math.min(e.y-e.h/2,r.y-r.h/2)-d*(1+i);p=[{x:u,y:c.y},{x:u,y:b},{x:h,y:b},{x:h,y:l.y}]}const m=s.arrowAt==="source"?jt(c,p[0],s.arrowGap):c,g=s.arrowAt==="target"?jt(l,p[p.length-1],s.arrowGap):l,y=s.arrowAt==="source"?Wt(c,p[0],s.arrowSize,s.headShape):s.arrowAt==="target"?Wt(l,p[p.length-1],s.arrowSize,s.headShape):void 0;return Po(m,p,g,y,s.radius)}function Qu(e,r,t,n,o){return Zb(l1(e,r,t,n),e,r,o)}function ef(e,r,t,n,o,i){const s=n===void 0&&o===void 0&&(t==="downward"||t==="upward"),a=t==="leftward"||s&&t==="upward"?-1:1,c=(l,d,u)=>{const h={x:l.x,y:d??l.y},p=Math.max(l.w,l.h)*2+1,m=sn(h,{x:h.x+(s?0:u*p),y:h.y+(s?u*p:0)},l);return m?{x:m.x+(s?0:u*i),y:m.y+(s?u*i:0)}:s?{x:l.x,y:l.y+u*(l.h/2+i)}:{x:l.x+u*(l.w/2+i),y:d??l.y}};return{sourcePoint:c(e,n,a),targetPoint:c(r,o,-a)}}function h1(e,r,t,n){const o=t==="downward"||t==="upward",i=t==="leftward"||t==="upward"?-1:1,s=Math.max(100,Math.abs(o?r.y-e.y:r.x-e.x)/2),a={x:e.x+(o?0:i*s),y:e.y+(o?i*s:0)},c={x:r.x-(o?0:i*s),y:r.y-(o?i*s:0)},l=n.arrowAt==="source"?jt(e,a,n.arrowGap):e,d=n.arrowAt==="target"?jt(r,c,n.arrowGap):r;return{d:`M${xt(l)} C${xt(a)} ${xt(c)} ${xt(d)}`,arrow:n.arrowAt==="source"?Wt(e,a,n.arrowSize,n.headShape):n.arrowAt==="target"?Wt(r,c,n.arrowSize,n.headShape):void 0,label:{x:(l.x+3*a.x+3*c.x+d.x)/8,y:(l.y+3*a.y+3*c.y+d.y)/8,angle:Cr(d.x+c.x-a.x-l.x,d.y+c.y-a.y-l.y)}}}function Xb(e,r,t){const n=t.arrowAt==="source"?jt(e,r,t.arrowGap):e,o=t.arrowAt==="target"?jt(r,e,t.arrowGap):r,i=t.arrowAt==="source"?Wt(e,r,t.arrowSize,t.headShape):t.arrowAt==="target"?Wt(r,e,t.arrowSize,t.headShape):void 0;return Po(n,[],o,i,0)}function p1(e,r,t,n=-90,o=-60,i=350){const s=n*Math.PI/180,a=o*Math.PI/180,c=s-Math.PI/2,l=c-a/2,d=c+a/2,u=1.4*i*(r/3+1),h={x:e.x+Math.cos(l)*u,y:e.y+Math.sin(l)*u},p={x:e.x+Math.cos(d)*u,y:e.y+Math.sin(d)*u},m={x:e.x,y:e.y},g=sn(m,h,e),y=sn(m,p,e);if(!g||!y)return null;const b={x:(h.x+p.x)/2,y:(h.y+p.y)/2};let x=jt(g,h,t.srcDist),v=jt(y,p,t.tgtDist),w;if(t.arrowAt==="target"){const S=v;v=jt(y,p,t.tgtDist+t.arrowGap),w=Wt(S,p,t.arrowSize,t.headShape)}else if(t.arrowAt==="source"){const S=x;x=jt(g,h,t.srcDist+t.arrowGap),w=Wt(S,h,t.arrowSize,t.headShape)}return{d:`M${xt(x)} Q${xt(h)} ${xt(b)} Q${xt(p)} ${xt(v)}`,arrow:w,label:{x:b.x,y:b.y,angle:Cr(p.x-h.x,p.y-h.y)}}}const $r=e=>Math.round(e*1e3)/1e3;function Yb(e){var h,p;const r=e.querySelector("[data-flow-node-surface]");if(!r)return;const t=e.getBoundingClientRect(),n=t.width/e.offsetWidth;if(!Number.isFinite(n)||n<=0)return;const o=r.getBoundingClientRect();if(!o.width||!o.height)return;const i=(p=(h=r.closest("[data-flow-icon-label]"))==null?void 0:h.querySelector("[data-flow-icon-caption]"))==null?void 0:p.getBoundingClientRect(),s=r,a=typeof s.getScreenCTM=="function"?s.getScreenCTM():null,c=typeof s.getTotalLength=="function"?s.getTotalLength():0,l=s.points,d=(l==null?void 0:l.numberOfItems)||128,u=a&&c>0?Array.from({length:d},(m,g)=>{const y=l!=null&&l.numberOfItems?l.getItem(g):s.getPointAtLength(c*g/d);return{x:$r((a.a*y.x+a.c*y.y+a.e-t.left)/n),y:$r((a.b*y.x+a.d*y.y+a.f-t.top)/n)}}):void 0;return{left:$r((o.left-t.left)/n),top:$r((o.top-t.top)/n),width:r instanceof HTMLElement?r.offsetWidth:$r(o.width/n),height:r instanceof HTMLElement?r.offsetHeight:$r(o.height/n),radius:parseFloat(getComputedStyle(r).borderTopLeftRadius)||0,...i!=null&&i.height?{captionBottom:$r((i.bottom-t.top)/n)}:{},...u?{outline:u}:{}}}function qn(e,r){const t=e.x-e.w/2,n=e.y-e.h/2;return{x:t+r.left+r.width/2,y:n+r.top+r.height/2,w:r.width,h:r.height,...r.outline?{outline:r.outline.map(o=>({x:t+o.x,y:n+o.y}))}:{}}}function g1(e,r,t,n,o){var d;const i=o!=="TB"&&o!=="BT",s=i?"top":"left",a=i?"bottom":"right",c=new Map;for(const u of n)for(const[h,p,m]of[[u.source,u.sourceProperty,u.target],[u.target,u.targetProperty,u.source]]){const g=r.get(m);if(p===void 0||!g||m===h)continue;const y=t.get(m),b=JSON.stringify([h,p]),x=c.get(b)??[];x.push(y?qn(g,y):g),c.set(b,x)}const l=new Map(e);for(const[u,h]of e){const p=r.get(u);if(!p||!h.some(v=>v.placement==="config"))continue;const m=t.get(u),g=m?qn(p,m):p,y={x:p.w/2,y:p.h/2,w:p.w,h:p.h},b=m?qn(y,m):y,x=new Map;for(const v of h){if(v.placement!=="config")continue;const C=(c.get(JSON.stringify([u,v.property]))??[]).reduce((E,M)=>E+(i?M.y-g.y:M.x-g.x),0),S=((d=v.anchor)==null?void 0:d.side)===a?a:s;x.set(v,C<-.001?s:C>.001?a:S)}l.set(u,h.map(v=>{const w=x.get(v);if(!w)return v;const C=h.filter(M=>x.get(M)===w),S=(C.indexOf(v)+1)/(C.length+1),E=Jb(b,w,S);return{...v,anchor:E,top:E.y,height:0}}))}return l}function tf(e,r,t){const n=new Set(r.map(a=>a.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const a of r)!o.has(a.id)&&(o.has(a.parent??"")||a.id.startsWith(`${e}.`))&&(o.add(a.id),i=!0)}const s=new Set(o);for(const a of t)o.has(a.source)&&n.has(a.target)&&s.add(a.target),o.has(a.target)&&n.has(a.source)&&s.add(a.source);return s}const _r='"Helvetica Neue", Helvetica, sans-serif';let Cn;const oo=new Map;function Ao(e,r){const t=`${r}|${e}`,n=oo.get(t);if(n!==void 0)return n;Cn===void 0&&(Cn=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let o;return Cn?(Cn.font=r,o=Cn.measureText(e).width):o=e.length*(parseFloat(r)||16)*.55,oo.size>5e3&&oo.clear(),oo.set(t,o),o}function y1(e,r,t){const n=[];for(const o of String(e).split(`
210
- `)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let s="";for(const a of i){const c=s?`${s} ${a}`:a;!s||Ao(c,r)<=t?s=c:(n.push(s),s=a)}n.push(s)}return n}const rf=e=>e.stopPropagation();function m1({id:e,rect:r,label:t,labelLayer:n,labelContent:o,style:i,onSelect:s,onCollapse:a,selected:c=!1}){const l=r.x2-r.x1,d=r.y2-r.y1,u=i.borderWidth,h=i.borderStyle==="dashed"?`${u*4} ${u*2}`:i.borderStyle==="dotted"?`${u} ${u}`:void 0,p=r.x1+l/2,m=i.labelPosition==="top"?r.y1+i.labelMargin-i.fontSize/2:i.labelPosition==="bottom"?r.y2-i.labelMargin+i.fontSize/2:r.y1+d/2,g=t?Ao(t,`bold ${i.fontSize}px ${_r}`):0,y=i.fontSize/5,b=t||c&&a?f.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[c&&a&&f.jsx("foreignObject",{x:p+g/2+y+8,y:m-24,width:48,height:48,"data-flow-content-toggle":"","data-flow-collapse-control":"",style:{pointerEvents:"auto"},children:f.jsx(Ge,{label:"Show icon",children:f.jsx(Ne,{"aria-label":"Show icon",icon:f.jsx(Q.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:i.textColor},onClick:x=>{x.stopPropagation(),a(e)}})})}),o?f.jsx("foreignObject",{x:p-g/2-y,y:m-i.fontSize/2-y,width:g+2*y,height:i.fontSize+2*y,style:{overflow:"visible"},onClick:rf,children:o}):t&&f.jsxs(f.Fragment,{children:[f.jsx("rect",{x:p-g/2-y,y:m-i.fontSize/2-y,width:g+2*y,height:i.fontSize+2*y,fill:i.textColor==="transparent"?"transparent":i.labelBg}),f.jsx("text",{x:p,y:m,fill:i.textColor,fontSize:i.fontSize,fontWeight:"bold",fontFamily:_r,style:{fontSize:i.fontSize,fontWeight:"bold",fontFamily:_r},textAnchor:"middle",dominantBaseline:"central",children:t})]})]}):null;return f.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:rf,onClick:x=>{x.stopPropagation(),s==null||s(e,{shiftKey:x.shiftKey,ctrlKey:x.ctrlKey,metaKey:x.metaKey,altKey:x.altKey})},children:[f.jsx("rect",{x:r.x1,y:r.y1,width:l,height:d,rx:i.borderRadius,ry:i.borderRadius,fill:i.bgColor,fillOpacity:i.bgOpacity,stroke:i.borderColor,strokeWidth:i.borderStyle==="double"?u/3:u,strokeDasharray:h}),i.borderStyle==="double"&&f.jsx("rect",{x:r.x1+u*2/3,y:r.y1+u*2/3,width:Math.max(0,l-u*4/3),height:Math.max(0,d-u*4/3),rx:Math.max(0,i.borderRadius-u*2/3),ry:Math.max(0,i.borderRadius-u*2/3),fill:"none",stroke:i.borderColor,strokeWidth:u/3}),i.animated&&u>0&&f.jsx(go,{variant:i.animationVariant,x:r.x1,y:r.y1,width:l,height:d,radius:i.borderRadius,color:i.animationColor||i.borderColor,strokeWidth:Math.max(8,u*1.6)}),n&&b?Wr.createPortal(b,n):b]})}const b1=j.memo(m1),yo=45,Qb=70,Lr=15,ex=50;function tx(e,r,t=yo){const n=`${t}px ${_r}`,o=e?y1(e,n,200*t/yo):[],i=r?48+(o.length?12:0):0,s=i+Math.max(0,...o.map(l=>Ao(l,n))),a=Math.max(o.length*t,r?48:0),c=o.length||r?2*Lr:0;return{lines:o,iconWidth:i,contentWidth:s,contentHeight:a,width:s+c,height:a+c}}const Ln=6,rx=3,Kd=.3,x1=8,Jd=Math.max(Math.pow(Ln*13.37,.9),29)*rx-x1/Kd,nx=Ln*rx*2,co=80,v1=2*co+Jd*Kd+100,w1=36+2*Math.max(80,nx+Jd*Kd);function kd(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function Pd(e,r){return r==="auto"||(r==="properties"?kd(e):!kd(e))}function ar(e,r,t){return t!=="properties"||e!=="root"||r.some(n=>(n.source===e||n.target===e)&&kd(n))}function C1(e,r,t,n=!1,o){if(!n)return{nodes:e,edges:r};const i=e.filter(a=>ar(a.id,r,t)&&(!o||o.has(a.id))),s=new Set(i.map(a=>a.id));return{nodes:i,edges:r.filter(a=>Pd(a,t)&&s.has(a.source)&&s.has(a.target))}}const S1=500,j1="32 18",E1=e=>e.stopPropagation();function _1({id:e,reveal:r,onRevealComplete:t,edgeData:n,validationIssue:o,edgeType:i="rounded-orthogonal",edgeRadius:s,customEdgeTypes:a,source:c,target:l,sourceProperty:d,targetProperty:u,sourceY:h,targetY:p,sourcePort:m,targetPort:g,propertyMode:y=!1,dir:b,turn:x,labelAtTarget:v,labelFraction:w,color:C,connectorColor:S,labelBg:E,labelLayer:M,label:P,dashed:T,animated:k,inverted:R,loopIndex:_=0,onSelect:N}){const $=n==null?void 0:n.icon,V=y?yo:Qb,{lines:I,iconWidth:F,contentWidth:oe,contentHeight:se}=j.useMemo(()=>tx(P,$,V),[P,$,V]),H=j.useMemo(()=>{const xe={srcDist:co,tgtDist:co,arrowGap:nx,arrowSize:Jd,headShape:y&&(R?h!==void 0||m:p!==void 0||g)?"square":"triangle",radius:s??(v?40:S1),arrowAt:R?"source":"target",labelTargetLength:v?oe+2*Lr:void 0,labelFraction:v?w:void 0},fe=h!==void 0||p!==void 0||!!m||!!g,U=ef(c,l,b,h,p,0),te=h===void 0&&p===void 0&&(b==="downward"||b==="upward"),de=m??{...U.sourcePoint,side:te?b==="upward"?"top":"bottom":b==="leftward"?"left":"right"},Pe=g??{...U.targetPoint,side:te?b==="upward"?"bottom":"top":b==="leftward"?"right":"left"},ie=c.x===l.x&&c.y===l.y,we=m||g?u1(de,Pe,{...xe,srcDist:18,tgtDist:18},i):fe?Yu(c,l,b,h,p,x,{...xe,srcDist:18,tgtDist:18,radius:s??Math.min(xe.radius,40)}):ie?p1(c,_,{...xe,srcDist:0,tgtDist:0}):Qu(c,l,b,x,xe);if(!we)return null;const $e=ef(c,l,b,h,p,fe?18:co);m&&($e.sourcePoint=Qr(m,18)),g&&($e.targetPoint=Qr(g,18));const He=Object.prototype.hasOwnProperty.call(a??{},i)?a==null?void 0:a[i]:void 0;if(He){const Ve={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return He({edge:n??{id:e,source:"",target:""},source:{...c},target:{...l},...$e,direction:Ve[b],sourceY:h,targetY:p,inverted:!!R,defaultGeometry:we})??we}return ie||m||g?we:i==="straight"?fe?Xb($e.sourcePoint,$e.targetPoint,xe):Zb([c,l],c,l,xe):i==="bezier"?h1($e.sourcePoint,$e.targetPoint,fe?b==="leftward"?"leftward":"rightward":b,xe):i==="orthogonal"?fe?Yu(c,l,b,h,p,x,{...xe,srcDist:18,tgtDist:18,radius:0}):Qu(c,l,b,x,{...xe,radius:0}):we},[c,e,n,i,s,a,l,y,h,p,m,g,b,x,R,_,v,w,oe]);if(!H)return null;const ee=(b==="rightward"||b==="leftward")&&!Object.prototype.hasOwnProperty.call(a??{},i)&&!(y&&(h!==void 0||p!==void 0||m||g)),ue=ee?`translate(${H.label.x} ${H.label.y-se/2-2*Lr})`:`translate(${H.label.x} ${H.label.y}) rotate(${H.label.angle}) translate(${b==="downward"||b==="upward"||v||Object.prototype.hasOwnProperty.call(a??{},i)?0:ex} 0)`,q=o!=null&&o.startsWith("Unverified:")?"#b45309":"#dc2626",D=o?q:C,K=o?f.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":o,transform:`translate(${H.label.x} ${H.label.y-I.length*V/2-55})`,children:[f.jsx("title",{children:o}),f.jsx(cr,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:q})]}):null,G=k&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",ce=!G&&(T||k)?j1:void 0,re=k&&!G?`flow-sdk-edge-anim${R?" flow-sdk-edge-anim-rev":""}`:void 0;let Z=null;const ae=r?{"--flow-edge-reveal-duration":`${r.durationMs??600}ms`,"--flow-edge-reveal-state":r.paused?"paused":"running"}:void 0;if(I.length||$){const xe=oe,fe=se;Z=f.jsxs("g",{className:`flow-sdk-edge-label${r?" flow-sdk-edge-reveal-end":""}`,style:ae,"data-label-transform":ue,"data-label-horizontal":ee||void 0,"data-edge-id":e,"data-source-property":d,"data-target-property":u,transform:ue,children:[f.jsx("rect",{x:-xe/2-Lr,y:-fe/2-Lr,width:xe+2*Lr,height:fe+2*Lr,fill:C==="transparent"?"transparent":E}),f.jsx("text",{fill:C,fontSize:V,style:{fontSize:V,fontFamily:_r},fontFamily:_r,textAnchor:"middle",dominantBaseline:"central",children:I.map((U,te)=>f.jsx("tspan",{x:F/2,y:(te-(I.length-1)/2)*V,children:U},te))}),$&&f.jsxs("g",{className:"flow-sdk-edge-icon",opacity:C==="transparent"?0:1,children:[f.jsx("title",{children:P?`Edge icon: ${P}`:"Edge icon"}),f.jsx("rect",{x:-xe/2,y:-24,width:48,height:48,fill:"transparent"}),f.jsx(cr,{name:$,svg:!0,size:48,x:-xe/2,y:-24,color:C})]})]})}const ye=f.jsxs(f.Fragment,{children:[f.jsx("path",{d:H.d,fill:"none",stroke:D,strokeWidth:Ln,strokeOpacity:G?.35:void 0,strokeDasharray:ce,className:re}),G&&f.jsx(n1,{path:H.d,color:D,width:Ln*1.6,reversed:R})]});return f.jsxs("g",{className:"flow-sdk-edge",style:ae,"data-edge-id":e,"data-source-property":d,"data-target-property":u,"data-validation":o?o.startsWith("Unverified:")?"unverified":"invalid":void 0,"aria-label":o,onPointerDown:E1,onClick:xe=>{xe.stopPropagation(),N==null||N(e)},children:[r?f.jsx(t1,{path:H.d,width:Ln*4,reversed:R,onComplete:()=>t==null?void 0:t(e),children:ye}):ye,H.arrow&&f.jsx("path",{className:r?"flow-sdk-edge-reveal-end":void 0,d:H.arrow,fill:o?q:S??D}),M&&Z?Wr.createPortal(Z,M):Z,M&&K?Wr.createPortal(K,M):K,f.jsx("path",{className:"flow-sdk-edge-hit",d:H.d,fill:"none",stroke:"transparent"})]})}const nf=j.memo(_1);var io=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function k1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Zd(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 ti,of;function P1(){if(of)return ti;of=1;function e(){this.__data__=[],this.size=0}return ti=e,ti}var ri,af;function fn(){if(af)return ri;af=1;function e(r,t){return r===t||r!==r&&t!==t}return ri=e,ri}var ni,sf;function Ro(){if(sf)return ni;sf=1;var e=fn();function r(t,n){for(var o=t.length;o--;)if(e(t[o][0],n))return o;return-1}return ni=r,ni}var oi,cf;function A1(){if(cf)return oi;cf=1;var e=Ro(),r=Array.prototype,t=r.splice;function n(o){var i=this.__data__,s=e(i,o);if(s<0)return!1;var a=i.length-1;return s==a?i.pop():t.call(i,s,1),--this.size,!0}return oi=n,oi}var ii,lf;function R1(){if(lf)return ii;lf=1;var e=Ro();function r(t){var n=this.__data__,o=e(n,t);return o<0?void 0:n[o][1]}return ii=r,ii}var ai,df;function M1(){if(df)return ai;df=1;var e=Ro();function r(t){return e(this.__data__,t)>-1}return ai=r,ai}var si,uf;function T1(){if(uf)return si;uf=1;var e=Ro();function r(t,n){var o=this.__data__,i=e(o,t);return i<0?(++this.size,o.push([t,n])):o[i][1]=n,this}return si=r,si}var ci,ff;function Mo(){if(ff)return ci;ff=1;var e=P1(),r=A1(),t=R1(),n=M1(),o=T1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,ci=i,ci}var li,hf;function I1(){if(hf)return li;hf=1;var e=Mo();function r(){this.__data__=new e,this.size=0}return li=r,li}var di,pf;function N1(){if(pf)return di;pf=1;function e(r){var t=this.__data__,n=t.delete(r);return this.size=t.size,n}return di=e,di}var ui,gf;function O1(){if(gf)return ui;gf=1;function e(r){return this.__data__.get(r)}return ui=e,ui}var fi,yf;function $1(){if(yf)return fi;yf=1;function e(r){return this.__data__.has(r)}return fi=e,fi}var hi,mf;function ox(){if(mf)return hi;mf=1;var e=typeof io=="object"&&io&&io.Object===Object&&io;return hi=e,hi}var pi,bf;function Yt(){if(bf)return pi;bf=1;var e=ox(),r=typeof self=="object"&&self&&self.Object===Object&&self,t=e||r||Function("return this")();return pi=t,pi}var gi,xf;function hn(){if(xf)return gi;xf=1;var e=Yt(),r=e.Symbol;return gi=r,gi}var yi,vf;function q1(){if(vf)return yi;vf=1;var e=hn(),r=Object.prototype,t=r.hasOwnProperty,n=r.toString,o=e?e.toStringTag:void 0;function i(s){var a=t.call(s,o),c=s[o];try{s[o]=void 0;var l=!0}catch{}var d=n.call(s);return l&&(a?s[o]=c:delete s[o]),d}return yi=i,yi}var mi,wf;function L1(){if(wf)return mi;wf=1;var e=Object.prototype,r=e.toString;function t(n){return r.call(n)}return mi=t,mi}var bi,Cf;function Gr(){if(Cf)return bi;Cf=1;var e=hn(),r=q1(),t=L1(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function s(a){return a==null?a===void 0?o:n:i&&i in Object(a)?r(a):t(a)}return bi=s,bi}var xi,Sf;function Vt(){if(Sf)return xi;Sf=1;function e(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}return xi=e,xi}var vi,jf;function Un(){if(jf)return vi;jf=1;var e=Gr(),r=Vt(),t="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function s(a){if(!r(a))return!1;var c=e(a);return c==n||c==o||c==t||c==i}return vi=s,vi}var wi,Ef;function F1(){if(Ef)return wi;Ef=1;var e=Yt(),r=e["__core-js_shared__"];return wi=r,wi}var Ci,_f;function z1(){if(_f)return Ci;_f=1;var e=F1(),r=(function(){var n=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})();function t(n){return!!r&&r in n}return Ci=t,Ci}var Si,kf;function ix(){if(kf)return Si;kf=1;var e=Function.prototype,r=e.toString;function t(n){if(n!=null){try{return r.call(n)}catch{}try{return n+""}catch{}}return""}return Si=t,Si}var ji,Pf;function B1(){if(Pf)return ji;Pf=1;var e=Un(),r=z1(),t=Vt(),n=ix(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,s=Function.prototype,a=Object.prototype,c=s.toString,l=a.hasOwnProperty,d=RegExp("^"+c.call(l).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function u(h){if(!t(h)||r(h))return!1;var p=e(h)?d:i;return p.test(n(h))}return ji=u,ji}var Ei,Af;function D1(){if(Af)return Ei;Af=1;function e(r,t){return r==null?void 0:r[t]}return Ei=e,Ei}var _i,Rf;function Hr(){if(Rf)return _i;Rf=1;var e=B1(),r=D1();function t(n,o){var i=r(n,o);return e(i)?i:void 0}return _i=t,_i}var ki,Mf;function Xd(){if(Mf)return ki;Mf=1;var e=Hr(),r=Yt(),t=e(r,"Map");return ki=t,ki}var Pi,Tf;function To(){if(Tf)return Pi;Tf=1;var e=Hr(),r=e(Object,"create");return Pi=r,Pi}var Ai,If;function W1(){if(If)return Ai;If=1;var e=To();function r(){this.__data__=e?e(null):{},this.size=0}return Ai=r,Ai}var Ri,Nf;function V1(){if(Nf)return Ri;Nf=1;function e(r){var t=this.has(r)&&delete this.__data__[r];return this.size-=t?1:0,t}return Ri=e,Ri}var Mi,Of;function G1(){if(Of)return Mi;Of=1;var e=To(),r="__lodash_hash_undefined__",t=Object.prototype,n=t.hasOwnProperty;function o(i){var s=this.__data__;if(e){var a=s[i];return a===r?void 0:a}return n.call(s,i)?s[i]:void 0}return Mi=o,Mi}var Ti,$f;function H1(){if($f)return Ti;$f=1;var e=To(),r=Object.prototype,t=r.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:t.call(i,o)}return Ti=n,Ti}var Ii,qf;function U1(){if(qf)return Ii;qf=1;var e=To(),r="__lodash_hash_undefined__";function t(n,o){var i=this.__data__;return this.size+=this.has(n)?0:1,i[n]=e&&o===void 0?r:o,this}return Ii=t,Ii}var Ni,Lf;function K1(){if(Lf)return Ni;Lf=1;var e=W1(),r=V1(),t=G1(),n=H1(),o=U1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Ni=i,Ni}var Oi,Ff;function J1(){if(Ff)return Oi;Ff=1;var e=K1(),r=Mo(),t=Xd();function n(){this.size=0,this.__data__={hash:new e,map:new(t||r),string:new e}}return Oi=n,Oi}var $i,zf;function Z1(){if(zf)return $i;zf=1;function e(r){var t=typeof r;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?r!=="__proto__":r===null}return $i=e,$i}var qi,Bf;function Io(){if(Bf)return qi;Bf=1;var e=Z1();function r(t,n){var o=t.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return qi=r,qi}var Li,Df;function X1(){if(Df)return Li;Df=1;var e=Io();function r(t){var n=e(this,t).delete(t);return this.size-=n?1:0,n}return Li=r,Li}var Fi,Wf;function Y1(){if(Wf)return Fi;Wf=1;var e=Io();function r(t){return e(this,t).get(t)}return Fi=r,Fi}var zi,Vf;function Q1(){if(Vf)return zi;Vf=1;var e=Io();function r(t){return e(this,t).has(t)}return zi=r,zi}var Bi,Gf;function eC(){if(Gf)return Bi;Gf=1;var e=Io();function r(t,n){var o=e(this,t),i=o.size;return o.set(t,n),this.size+=o.size==i?0:1,this}return Bi=r,Bi}var Di,Hf;function Yd(){if(Hf)return Di;Hf=1;var e=J1(),r=X1(),t=Y1(),n=Q1(),o=eC();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Di=i,Di}var Wi,Uf;function tC(){if(Uf)return Wi;Uf=1;var e=Mo(),r=Xd(),t=Yd(),n=200;function o(i,s){var a=this.__data__;if(a instanceof e){var c=a.__data__;if(!r||c.length<n-1)return c.push([i,s]),this.size=++a.size,this;a=this.__data__=new t(c)}return a.set(i,s),this.size=a.size,this}return Wi=o,Wi}var Vi,Kf;function No(){if(Kf)return Vi;Kf=1;var e=Mo(),r=I1(),t=N1(),n=O1(),o=$1(),i=tC();function s(a){var c=this.__data__=new e(a);this.size=c.size}return s.prototype.clear=r,s.prototype.delete=t,s.prototype.get=n,s.prototype.has=o,s.prototype.set=i,Vi=s,Vi}var Gi,Jf;function Qd(){if(Jf)return Gi;Jf=1;function e(r,t){for(var n=-1,o=r==null?0:r.length;++n<o&&t(r[n],n,r)!==!1;);return r}return Gi=e,Gi}var Hi,Zf;function ax(){if(Zf)return Hi;Zf=1;var e=Hr(),r=(function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch{}})();return Hi=r,Hi}var Ui,Xf;function Oo(){if(Xf)return Ui;Xf=1;var e=ax();function r(t,n,o){n=="__proto__"&&e?e(t,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):t[n]=o}return Ui=r,Ui}var Ki,Yf;function $o(){if(Yf)return Ki;Yf=1;var e=Oo(),r=fn(),t=Object.prototype,n=t.hasOwnProperty;function o(i,s,a){var c=i[s];(!(n.call(i,s)&&r(c,a))||a===void 0&&!(s in i))&&e(i,s,a)}return Ki=o,Ki}var Ji,Qf;function Kn(){if(Qf)return Ji;Qf=1;var e=$o(),r=Oo();function t(n,o,i,s){var a=!i;i||(i={});for(var c=-1,l=o.length;++c<l;){var d=o[c],u=s?s(i[d],n[d],d,i,n):void 0;u===void 0&&(u=n[d]),a?r(i,d,u):e(i,d,u)}return i}return Ji=t,Ji}var Zi,eh;function rC(){if(eh)return Zi;eh=1;function e(r,t){for(var n=-1,o=Array(r);++n<r;)o[n]=t(n);return o}return Zi=e,Zi}var Xi,th;function lr(){if(th)return Xi;th=1;function e(r){return r!=null&&typeof r=="object"}return Xi=e,Xi}var Yi,rh;function nC(){if(rh)return Yi;rh=1;var e=Gr(),r=lr(),t="[object Arguments]";function n(o){return r(o)&&e(o)==t}return Yi=n,Yi}var Qi,nh;function Jn(){if(nh)return Qi;nh=1;var e=nC(),r=lr(),t=Object.prototype,n=t.hasOwnProperty,o=t.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(s){return r(s)&&n.call(s,"callee")&&!o.call(s,"callee")};return Qi=i,Qi}var ea,oh;function Ct(){if(oh)return ea;oh=1;var e=Array.isArray;return ea=e,ea}var kn={exports:{}},ta,ih;function oC(){if(ih)return ta;ih=1;function e(){return!1}return ta=e,ta}kn.exports;var ah;function pn(){return ah||(ah=1,(function(e,r){var t=Yt(),n=oC(),o=r&&!r.nodeType&&r,i=o&&!0&&e&&!e.nodeType&&e,s=i&&i.exports===o,a=s?t.Buffer:void 0,c=a?a.isBuffer:void 0,l=c||n;e.exports=l})(kn,kn.exports)),kn.exports}var ra,sh;function qo(){if(sh)return ra;sh=1;var e=9007199254740991,r=/^(?:0|[1-9]\d*)$/;function t(n,o){var i=typeof n;return o=o??e,!!o&&(i=="number"||i!="symbol"&&r.test(n))&&n>-1&&n%1==0&&n<o}return ra=t,ra}var na,ch;function eu(){if(ch)return na;ch=1;var e=9007199254740991;function r(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=e}return na=r,na}var oa,lh;function iC(){if(lh)return oa;lh=1;var e=Gr(),r=eu(),t=lr(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",s="[object Date]",a="[object Error]",c="[object Function]",l="[object Map]",d="[object Number]",u="[object Object]",h="[object RegExp]",p="[object Set]",m="[object String]",g="[object WeakMap]",y="[object ArrayBuffer]",b="[object DataView]",x="[object Float32Array]",v="[object Float64Array]",w="[object Int8Array]",C="[object Int16Array]",S="[object Int32Array]",E="[object Uint8Array]",M="[object Uint8ClampedArray]",P="[object Uint16Array]",T="[object Uint32Array]",k={};k[x]=k[v]=k[w]=k[C]=k[S]=k[E]=k[M]=k[P]=k[T]=!0,k[n]=k[o]=k[y]=k[i]=k[b]=k[s]=k[a]=k[c]=k[l]=k[d]=k[u]=k[h]=k[p]=k[m]=k[g]=!1;function R(_){return t(_)&&r(_.length)&&!!k[e(_)]}return oa=R,oa}var ia,dh;function Lo(){if(dh)return ia;dh=1;function e(r){return function(t){return r(t)}}return ia=e,ia}var Pn={exports:{}};Pn.exports;var uh;function tu(){return uh||(uh=1,(function(e,r){var t=ox(),n=r&&!r.nodeType&&r,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i&&t.process,a=(function(){try{var c=o&&o.require&&o.require("util").types;return c||s&&s.binding&&s.binding("util")}catch{}})();e.exports=a})(Pn,Pn.exports)),Pn.exports}var aa,fh;function Zn(){if(fh)return aa;fh=1;var e=iC(),r=Lo(),t=tu(),n=t&&t.isTypedArray,o=n?r(n):e;return aa=o,aa}var sa,hh;function sx(){if(hh)return sa;hh=1;var e=rC(),r=Jn(),t=Ct(),n=pn(),o=qo(),i=Zn(),s=Object.prototype,a=s.hasOwnProperty;function c(l,d){var u=t(l),h=!u&&r(l),p=!u&&!h&&n(l),m=!u&&!h&&!p&&i(l),g=u||h||p||m,y=g?e(l.length,String):[],b=y.length;for(var x in l)(d||a.call(l,x))&&!(g&&(x=="length"||p&&(x=="offset"||x=="parent")||m&&(x=="buffer"||x=="byteLength"||x=="byteOffset")||o(x,b)))&&y.push(x);return y}return sa=c,sa}var ca,ph;function Fo(){if(ph)return ca;ph=1;var e=Object.prototype;function r(t){var n=t&&t.constructor,o=typeof n=="function"&&n.prototype||e;return t===o}return ca=r,ca}var la,gh;function cx(){if(gh)return la;gh=1;function e(r,t){return function(n){return r(t(n))}}return la=e,la}var da,yh;function aC(){if(yh)return da;yh=1;var e=cx(),r=e(Object.keys,Object);return da=r,da}var ua,mh;function ru(){if(mh)return ua;mh=1;var e=Fo(),r=aC(),t=Object.prototype,n=t.hasOwnProperty;function o(i){if(!e(i))return r(i);var s=[];for(var a in Object(i))n.call(i,a)&&a!="constructor"&&s.push(a);return s}return ua=o,ua}var fa,bh;function yr(){if(bh)return fa;bh=1;var e=Un(),r=eu();function t(n){return n!=null&&r(n.length)&&!e(n)}return fa=t,fa}var ha,xh;function Mr(){if(xh)return ha;xh=1;var e=sx(),r=ru(),t=yr();function n(o){return t(o)?e(o):r(o)}return ha=n,ha}var pa,vh;function sC(){if(vh)return pa;vh=1;var e=Kn(),r=Mr();function t(n,o){return n&&e(o,r(o),n)}return pa=t,pa}var ga,wh;function cC(){if(wh)return ga;wh=1;function e(r){var t=[];if(r!=null)for(var n in Object(r))t.push(n);return t}return ga=e,ga}var ya,Ch;function lC(){if(Ch)return ya;Ch=1;var e=Vt(),r=Fo(),t=cC(),n=Object.prototype,o=n.hasOwnProperty;function i(s){if(!e(s))return t(s);var a=r(s),c=[];for(var l in s)l=="constructor"&&(a||!o.call(s,l))||c.push(l);return c}return ya=i,ya}var ma,Sh;function Ur(){if(Sh)return ma;Sh=1;var e=sx(),r=lC(),t=yr();function n(o){return t(o)?e(o,!0):r(o)}return ma=n,ma}var ba,jh;function dC(){if(jh)return ba;jh=1;var e=Kn(),r=Ur();function t(n,o){return n&&e(o,r(o),n)}return ba=t,ba}var An={exports:{}};An.exports;var Eh;function lx(){return Eh||(Eh=1,(function(e,r){var t=Yt(),n=r&&!r.nodeType&&r,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i?t.Buffer:void 0,a=s?s.allocUnsafe:void 0;function c(l,d){if(d)return l.slice();var u=l.length,h=a?a(u):new l.constructor(u);return l.copy(h),h}e.exports=c})(An,An.exports)),An.exports}var xa,_h;function dx(){if(_h)return xa;_h=1;function e(r,t){var n=-1,o=r.length;for(t||(t=Array(o));++n<o;)t[n]=r[n];return t}return xa=e,xa}var va,kh;function ux(){if(kh)return va;kh=1;function e(r,t){for(var n=-1,o=r==null?0:r.length,i=0,s=[];++n<o;){var a=r[n];t(a,n,r)&&(s[i++]=a)}return s}return va=e,va}var wa,Ph;function fx(){if(Ph)return wa;Ph=1;function e(){return[]}return wa=e,wa}var Ca,Ah;function nu(){if(Ah)return Ca;Ah=1;var e=ux(),r=fx(),t=Object.prototype,n=t.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(s){return s==null?[]:(s=Object(s),e(o(s),function(a){return n.call(s,a)}))}:r;return Ca=i,Ca}var Sa,Rh;function uC(){if(Rh)return Sa;Rh=1;var e=Kn(),r=nu();function t(n,o){return e(n,r(n),o)}return Sa=t,Sa}var ja,Mh;function ou(){if(Mh)return ja;Mh=1;function e(r,t){for(var n=-1,o=t.length,i=r.length;++n<o;)r[i+n]=t[n];return r}return ja=e,ja}var Ea,Th;function zo(){if(Th)return Ea;Th=1;var e=cx(),r=e(Object.getPrototypeOf,Object);return Ea=r,Ea}var _a,Ih;function hx(){if(Ih)return _a;Ih=1;var e=ou(),r=zo(),t=nu(),n=fx(),o=Object.getOwnPropertySymbols,i=o?function(s){for(var a=[];s;)e(a,t(s)),s=r(s);return a}:n;return _a=i,_a}var ka,Nh;function fC(){if(Nh)return ka;Nh=1;var e=Kn(),r=hx();function t(n,o){return e(n,r(n),o)}return ka=t,ka}var Pa,Oh;function px(){if(Oh)return Pa;Oh=1;var e=ou(),r=Ct();function t(n,o,i){var s=o(n);return r(n)?s:e(s,i(n))}return Pa=t,Pa}var Aa,$h;function gx(){if($h)return Aa;$h=1;var e=px(),r=nu(),t=Mr();function n(o){return e(o,t,r)}return Aa=n,Aa}var Ra,qh;function hC(){if(qh)return Ra;qh=1;var e=px(),r=hx(),t=Ur();function n(o){return e(o,t,r)}return Ra=n,Ra}var Ma,Lh;function pC(){if(Lh)return Ma;Lh=1;var e=Hr(),r=Yt(),t=e(r,"DataView");return Ma=t,Ma}var Ta,Fh;function gC(){if(Fh)return Ta;Fh=1;var e=Hr(),r=Yt(),t=e(r,"Promise");return Ta=t,Ta}var Ia,zh;function yx(){if(zh)return Ia;zh=1;var e=Hr(),r=Yt(),t=e(r,"Set");return Ia=t,Ia}var Na,Bh;function yC(){if(Bh)return Na;Bh=1;var e=Hr(),r=Yt(),t=e(r,"WeakMap");return Na=t,Na}var Oa,Dh;function gn(){if(Dh)return Oa;Dh=1;var e=pC(),r=Xd(),t=gC(),n=yx(),o=yC(),i=Gr(),s=ix(),a="[object Map]",c="[object Object]",l="[object Promise]",d="[object Set]",u="[object WeakMap]",h="[object DataView]",p=s(e),m=s(r),g=s(t),y=s(n),b=s(o),x=i;return(e&&x(new e(new ArrayBuffer(1)))!=h||r&&x(new r)!=a||t&&x(t.resolve())!=l||n&&x(new n)!=d||o&&x(new o)!=u)&&(x=function(v){var w=i(v),C=w==c?v.constructor:void 0,S=C?s(C):"";if(S)switch(S){case p:return h;case m:return a;case g:return l;case y:return d;case b:return u}return w}),Oa=x,Oa}var $a,Wh;function mC(){if(Wh)return $a;Wh=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n){var o=n.length,i=new n.constructor(o);return o&&typeof n[0]=="string"&&r.call(n,"index")&&(i.index=n.index,i.input=n.input),i}return $a=t,$a}var qa,Vh;function mx(){if(Vh)return qa;Vh=1;var e=Yt(),r=e.Uint8Array;return qa=r,qa}var La,Gh;function iu(){if(Gh)return La;Gh=1;var e=mx();function r(t){var n=new t.constructor(t.byteLength);return new e(n).set(new e(t)),n}return La=r,La}var Fa,Hh;function bC(){if(Hh)return Fa;Hh=1;var e=iu();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.byteLength)}return Fa=r,Fa}var za,Uh;function xC(){if(Uh)return za;Uh=1;var e=/\w*$/;function r(t){var n=new t.constructor(t.source,e.exec(t));return n.lastIndex=t.lastIndex,n}return za=r,za}var Ba,Kh;function vC(){if(Kh)return Ba;Kh=1;var e=hn(),r=e?e.prototype:void 0,t=r?r.valueOf:void 0;function n(o){return t?Object(t.call(o)):{}}return Ba=n,Ba}var Da,Jh;function bx(){if(Jh)return Da;Jh=1;var e=iu();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}return Da=r,Da}var Wa,Zh;function wC(){if(Zh)return Wa;Zh=1;var e=iu(),r=bC(),t=xC(),n=vC(),o=bx(),i="[object Boolean]",s="[object Date]",a="[object Map]",c="[object Number]",l="[object RegExp]",d="[object Set]",u="[object String]",h="[object Symbol]",p="[object ArrayBuffer]",m="[object DataView]",g="[object Float32Array]",y="[object Float64Array]",b="[object Int8Array]",x="[object Int16Array]",v="[object Int32Array]",w="[object Uint8Array]",C="[object Uint8ClampedArray]",S="[object Uint16Array]",E="[object Uint32Array]";function M(P,T,k){var R=P.constructor;switch(T){case p:return e(P);case i:case s:return new R(+P);case m:return r(P,k);case g:case y:case b:case x:case v:case w:case C:case S:case E:return o(P,k);case a:return new R;case c:case u:return new R(P);case l:return t(P);case d:return new R;case h:return n(P)}}return Wa=M,Wa}var Va,Xh;function xx(){if(Xh)return Va;Xh=1;var e=Vt(),r=Object.create,t=(function(){function n(){}return function(o){if(!e(o))return{};if(r)return r(o);n.prototype=o;var i=new n;return n.prototype=void 0,i}})();return Va=t,Va}var Ga,Yh;function vx(){if(Yh)return Ga;Yh=1;var e=xx(),r=zo(),t=Fo();function n(o){return typeof o.constructor=="function"&&!t(o)?e(r(o)):{}}return Ga=n,Ga}var Ha,Qh;function CC(){if(Qh)return Ha;Qh=1;var e=gn(),r=lr(),t="[object Map]";function n(o){return r(o)&&e(o)==t}return Ha=n,Ha}var Ua,ep;function SC(){if(ep)return Ua;ep=1;var e=CC(),r=Lo(),t=tu(),n=t&&t.isMap,o=n?r(n):e;return Ua=o,Ua}var Ka,tp;function jC(){if(tp)return Ka;tp=1;var e=gn(),r=lr(),t="[object Set]";function n(o){return r(o)&&e(o)==t}return Ka=n,Ka}var Ja,rp;function EC(){if(rp)return Ja;rp=1;var e=jC(),r=Lo(),t=tu(),n=t&&t.isSet,o=n?r(n):e;return Ja=o,Ja}var Za,np;function wx(){if(np)return Za;np=1;var e=No(),r=Qd(),t=$o(),n=sC(),o=dC(),i=lx(),s=dx(),a=uC(),c=fC(),l=gx(),d=hC(),u=gn(),h=mC(),p=wC(),m=vx(),g=Ct(),y=pn(),b=SC(),x=Vt(),v=EC(),w=Mr(),C=Ur(),S=1,E=2,M=4,P="[object Arguments]",T="[object Array]",k="[object Boolean]",R="[object Date]",_="[object Error]",N="[object Function]",$="[object GeneratorFunction]",V="[object Map]",I="[object Number]",F="[object Object]",oe="[object RegExp]",se="[object Set]",H="[object String]",ee="[object Symbol]",ue="[object WeakMap]",q="[object ArrayBuffer]",D="[object DataView]",K="[object Float32Array]",G="[object Float64Array]",ce="[object Int8Array]",re="[object Int16Array]",Z="[object Int32Array]",ae="[object Uint8Array]",ye="[object Uint8ClampedArray]",xe="[object Uint16Array]",fe="[object Uint32Array]",U={};U[P]=U[T]=U[q]=U[D]=U[k]=U[R]=U[K]=U[G]=U[ce]=U[re]=U[Z]=U[V]=U[I]=U[F]=U[oe]=U[se]=U[H]=U[ee]=U[ae]=U[ye]=U[xe]=U[fe]=!0,U[_]=U[N]=U[ue]=!1;function te(de,Pe,ie,we,$e,He){var Ve,tt=Pe&S,me=Pe&E,Ie=Pe&M;if(ie&&(Ve=$e?ie(de,we,$e,He):ie(de)),Ve!==void 0)return Ve;if(!x(de))return de;var De=g(de);if(De){if(Ve=h(de),!tt)return s(de,Ve)}else{var be=u(de),Xe=be==N||be==$;if(y(de))return i(de,tt);if(be==F||be==P||Xe&&!$e){if(Ve=me||Xe?{}:m(de),!tt)return me?c(de,o(Ve,de)):a(de,n(Ve,de))}else{if(!U[be])return $e?de:{};Ve=p(de,be,tt)}}He||(He=new e);var ut=He.get(de);if(ut)return ut;He.set(de,Ve),v(de)?de.forEach(function(lt){Ve.add(te(lt,Pe,ie,lt,de,He))}):b(de)&&de.forEach(function(lt,Je){Ve.set(Je,te(lt,Pe,ie,Je,de,He))});var Ae=Ie?me?d:l:me?C:w,Ke=De?void 0:Ae(de);return r(Ke||de,function(lt,Je){Ke&&(Je=lt,lt=de[Je]),t(Ve,Je,te(lt,Pe,ie,Je,de,He))}),Ve}return Za=te,Za}var Xa,op;function _C(){if(op)return Xa;op=1;var e=wx(),r=4;function t(n){return e(n,r)}return Xa=t,Xa}var Ya,ip;function au(){if(ip)return Ya;ip=1;function e(r){return function(){return r}}return Ya=e,Ya}var Qa,ap;function kC(){if(ap)return Qa;ap=1;function e(r){return function(t,n,o){for(var i=-1,s=Object(t),a=o(t),c=a.length;c--;){var l=a[r?c:++i];if(n(s[l],l,s)===!1)break}return t}}return Qa=e,Qa}var es,sp;function su(){if(sp)return es;sp=1;var e=kC(),r=e();return es=r,es}var ts,cp;function cu(){if(cp)return ts;cp=1;var e=su(),r=Mr();function t(n,o){return n&&e(n,o,r)}return ts=t,ts}var rs,lp;function PC(){if(lp)return rs;lp=1;var e=yr();function r(t,n){return function(o,i){if(o==null)return o;if(!e(o))return t(o,i);for(var s=o.length,a=n?s:-1,c=Object(o);(n?a--:++a<s)&&i(c[a],a,c)!==!1;);return o}}return rs=r,rs}var ns,dp;function Bo(){if(dp)return ns;dp=1;var e=cu(),r=PC(),t=r(e);return ns=t,ns}var os,up;function Kr(){if(up)return os;up=1;function e(r){return r}return os=e,os}var is,fp;function Cx(){if(fp)return is;fp=1;var e=Kr();function r(t){return typeof t=="function"?t:e}return is=r,is}var as,hp;function Sx(){if(hp)return as;hp=1;var e=Qd(),r=Bo(),t=Cx(),n=Ct();function o(i,s){var a=n(i)?e:r;return a(i,t(s))}return as=o,as}var ss,pp;function jx(){return pp||(pp=1,ss=Sx()),ss}var cs,gp;function AC(){if(gp)return cs;gp=1;var e=Bo();function r(t,n){var o=[];return e(t,function(i,s,a){n(i,s,a)&&o.push(i)}),o}return cs=r,cs}var ls,yp;function RC(){if(yp)return ls;yp=1;var e="__lodash_hash_undefined__";function r(t){return this.__data__.set(t,e),this}return ls=r,ls}var ds,mp;function MC(){if(mp)return ds;mp=1;function e(r){return this.__data__.has(r)}return ds=e,ds}var us,bp;function Ex(){if(bp)return us;bp=1;var e=Yd(),r=RC(),t=MC();function n(o){var i=-1,s=o==null?0:o.length;for(this.__data__=new e;++i<s;)this.add(o[i])}return n.prototype.add=n.prototype.push=r,n.prototype.has=t,us=n,us}var fs,xp;function TC(){if(xp)return fs;xp=1;function e(r,t){for(var n=-1,o=r==null?0:r.length;++n<o;)if(t(r[n],n,r))return!0;return!1}return fs=e,fs}var hs,vp;function _x(){if(vp)return hs;vp=1;function e(r,t){return r.has(t)}return hs=e,hs}var ps,wp;function kx(){if(wp)return ps;wp=1;var e=Ex(),r=TC(),t=_x(),n=1,o=2;function i(s,a,c,l,d,u){var h=c&n,p=s.length,m=a.length;if(p!=m&&!(h&&m>p))return!1;var g=u.get(s),y=u.get(a);if(g&&y)return g==a&&y==s;var b=-1,x=!0,v=c&o?new e:void 0;for(u.set(s,a),u.set(a,s);++b<p;){var w=s[b],C=a[b];if(l)var S=h?l(C,w,b,a,s,u):l(w,C,b,s,a,u);if(S!==void 0){if(S)continue;x=!1;break}if(v){if(!r(a,function(E,M){if(!t(v,M)&&(w===E||d(w,E,c,l,u)))return v.push(M)})){x=!1;break}}else if(!(w===C||d(w,C,c,l,u))){x=!1;break}}return u.delete(s),u.delete(a),x}return ps=i,ps}var gs,Cp;function IC(){if(Cp)return gs;Cp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o,i){n[++t]=[i,o]}),n}return gs=e,gs}var ys,Sp;function lu(){if(Sp)return ys;Sp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o){n[++t]=o}),n}return ys=e,ys}var ms,jp;function NC(){if(jp)return ms;jp=1;var e=hn(),r=mx(),t=fn(),n=kx(),o=IC(),i=lu(),s=1,a=2,c="[object Boolean]",l="[object Date]",d="[object Error]",u="[object Map]",h="[object Number]",p="[object RegExp]",m="[object Set]",g="[object String]",y="[object Symbol]",b="[object ArrayBuffer]",x="[object DataView]",v=e?e.prototype:void 0,w=v?v.valueOf:void 0;function C(S,E,M,P,T,k,R){switch(M){case x:if(S.byteLength!=E.byteLength||S.byteOffset!=E.byteOffset)return!1;S=S.buffer,E=E.buffer;case b:return!(S.byteLength!=E.byteLength||!k(new r(S),new r(E)));case c:case l:case h:return t(+S,+E);case d:return S.name==E.name&&S.message==E.message;case p:case g:return S==E+"";case u:var _=o;case m:var N=P&s;if(_||(_=i),S.size!=E.size&&!N)return!1;var $=R.get(S);if($)return $==E;P|=a,R.set(S,E);var V=n(_(S),_(E),P,T,k,R);return R.delete(S),V;case y:if(w)return w.call(S)==w.call(E)}return!1}return ms=C,ms}var bs,Ep;function OC(){if(Ep)return bs;Ep=1;var e=gx(),r=1,t=Object.prototype,n=t.hasOwnProperty;function o(i,s,a,c,l,d){var u=a&r,h=e(i),p=h.length,m=e(s),g=m.length;if(p!=g&&!u)return!1;for(var y=p;y--;){var b=h[y];if(!(u?b in s:n.call(s,b)))return!1}var x=d.get(i),v=d.get(s);if(x&&v)return x==s&&v==i;var w=!0;d.set(i,s),d.set(s,i);for(var C=u;++y<p;){b=h[y];var S=i[b],E=s[b];if(c)var M=u?c(E,S,b,s,i,d):c(S,E,b,i,s,d);if(!(M===void 0?S===E||l(S,E,a,c,d):M)){w=!1;break}C||(C=b=="constructor")}if(w&&!C){var P=i.constructor,T=s.constructor;P!=T&&"constructor"in i&&"constructor"in s&&!(typeof P=="function"&&P instanceof P&&typeof T=="function"&&T instanceof T)&&(w=!1)}return d.delete(i),d.delete(s),w}return bs=o,bs}var xs,_p;function $C(){if(_p)return xs;_p=1;var e=No(),r=kx(),t=NC(),n=OC(),o=gn(),i=Ct(),s=pn(),a=Zn(),c=1,l="[object Arguments]",d="[object Array]",u="[object Object]",h=Object.prototype,p=h.hasOwnProperty;function m(g,y,b,x,v,w){var C=i(g),S=i(y),E=C?d:o(g),M=S?d:o(y);E=E==l?u:E,M=M==l?u:M;var P=E==u,T=M==u,k=E==M;if(k&&s(g)){if(!s(y))return!1;C=!0,P=!1}if(k&&!P)return w||(w=new e),C||a(g)?r(g,y,b,x,v,w):t(g,y,E,b,x,v,w);if(!(b&c)){var R=P&&p.call(g,"__wrapped__"),_=T&&p.call(y,"__wrapped__");if(R||_){var N=R?g.value():g,$=_?y.value():y;return w||(w=new e),v(N,$,b,x,w)}}return k?(w||(w=new e),n(g,y,b,x,v,w)):!1}return xs=m,xs}var vs,kp;function Px(){if(kp)return vs;kp=1;var e=$C(),r=lr();function t(n,o,i,s,a){return n===o?!0:n==null||o==null||!r(n)&&!r(o)?n!==n&&o!==o:e(n,o,i,s,t,a)}return vs=t,vs}var ws,Pp;function qC(){if(Pp)return ws;Pp=1;var e=No(),r=Px(),t=1,n=2;function o(i,s,a,c){var l=a.length,d=l,u=!c;if(i==null)return!d;for(i=Object(i);l--;){var h=a[l];if(u&&h[2]?h[1]!==i[h[0]]:!(h[0]in i))return!1}for(;++l<d;){h=a[l];var p=h[0],m=i[p],g=h[1];if(u&&h[2]){if(m===void 0&&!(p in i))return!1}else{var y=new e;if(c)var b=c(m,g,p,i,s,y);if(!(b===void 0?r(g,m,t|n,c,y):b))return!1}}return!0}return ws=o,ws}var Cs,Ap;function Ax(){if(Ap)return Cs;Ap=1;var e=Vt();function r(t){return t===t&&!e(t)}return Cs=r,Cs}var Ss,Rp;function LC(){if(Rp)return Ss;Rp=1;var e=Ax(),r=Mr();function t(n){for(var o=r(n),i=o.length;i--;){var s=o[i],a=n[s];o[i]=[s,a,e(a)]}return o}return Ss=t,Ss}var js,Mp;function Rx(){if(Mp)return js;Mp=1;function e(r,t){return function(n){return n==null?!1:n[r]===t&&(t!==void 0||r in Object(n))}}return js=e,js}var Es,Tp;function FC(){if(Tp)return Es;Tp=1;var e=qC(),r=LC(),t=Rx();function n(o){var i=r(o);return i.length==1&&i[0][2]?t(i[0][0],i[0][1]):function(s){return s===o||e(s,o,i)}}return Es=n,Es}var _s,Ip;function yn(){if(Ip)return _s;Ip=1;var e=Gr(),r=lr(),t="[object Symbol]";function n(o){return typeof o=="symbol"||r(o)&&e(o)==t}return _s=n,_s}var ks,Np;function du(){if(Np)return ks;Np=1;var e=Ct(),r=yn(),t=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,s){if(e(i))return!1;var a=typeof i;return a=="number"||a=="symbol"||a=="boolean"||i==null||r(i)?!0:n.test(i)||!t.test(i)||s!=null&&i in Object(s)}return ks=o,ks}var Ps,Op;function zC(){if(Op)return Ps;Op=1;var e=Yd(),r="Expected a function";function t(n,o){if(typeof n!="function"||o!=null&&typeof o!="function")throw new TypeError(r);var i=function(){var s=arguments,a=o?o.apply(this,s):s[0],c=i.cache;if(c.has(a))return c.get(a);var l=n.apply(this,s);return i.cache=c.set(a,l)||c,l};return i.cache=new(t.Cache||e),i}return t.Cache=e,Ps=t,Ps}var As,$p;function BC(){if($p)return As;$p=1;var e=zC(),r=500;function t(n){var o=e(n,function(s){return i.size===r&&i.clear(),s}),i=o.cache;return o}return As=t,As}var Rs,qp;function DC(){if(qp)return Rs;qp=1;var e=BC(),r=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,t=/\\(\\)?/g,n=e(function(o){var i=[];return o.charCodeAt(0)===46&&i.push(""),o.replace(r,function(s,a,c,l){i.push(c?l.replace(t,"$1"):a||s)}),i});return Rs=n,Rs}var Ms,Lp;function Do(){if(Lp)return Ms;Lp=1;function e(r,t){for(var n=-1,o=r==null?0:r.length,i=Array(o);++n<o;)i[n]=t(r[n],n,r);return i}return Ms=e,Ms}var Ts,Fp;function WC(){if(Fp)return Ts;Fp=1;var e=hn(),r=Do(),t=Ct(),n=yn(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function s(a){if(typeof a=="string")return a;if(t(a))return r(a,s)+"";if(n(a))return i?i.call(a):"";var c=a+"";return c=="0"&&1/a==-1/0?"-0":c}return Ts=s,Ts}var Is,zp;function Mx(){if(zp)return Is;zp=1;var e=WC();function r(t){return t==null?"":e(t)}return Is=r,Is}var Ns,Bp;function Wo(){if(Bp)return Ns;Bp=1;var e=Ct(),r=du(),t=DC(),n=Mx();function o(i,s){return e(i)?i:r(i,s)?[i]:t(n(i))}return Ns=o,Ns}var Os,Dp;function Xn(){if(Dp)return Os;Dp=1;var e=yn();function r(t){if(typeof t=="string"||e(t))return t;var n=t+"";return n=="0"&&1/t==-1/0?"-0":n}return Os=r,Os}var $s,Wp;function Vo(){if(Wp)return $s;Wp=1;var e=Wo(),r=Xn();function t(n,o){o=e(o,n);for(var i=0,s=o.length;n!=null&&i<s;)n=n[r(o[i++])];return i&&i==s?n:void 0}return $s=t,$s}var qs,Vp;function VC(){if(Vp)return qs;Vp=1;var e=Vo();function r(t,n,o){var i=t==null?void 0:e(t,n);return i===void 0?o:i}return qs=r,qs}var Ls,Gp;function GC(){if(Gp)return Ls;Gp=1;function e(r,t){return r!=null&&t in Object(r)}return Ls=e,Ls}var Fs,Hp;function Tx(){if(Hp)return Fs;Hp=1;var e=Wo(),r=Jn(),t=Ct(),n=qo(),o=eu(),i=Xn();function s(a,c,l){c=e(c,a);for(var d=-1,u=c.length,h=!1;++d<u;){var p=i(c[d]);if(!(h=a!=null&&l(a,p)))break;a=a[p]}return h||++d!=u?h:(u=a==null?0:a.length,!!u&&o(u)&&n(p,u)&&(t(a)||r(a)))}return Fs=s,Fs}var zs,Up;function Ix(){if(Up)return zs;Up=1;var e=GC(),r=Tx();function t(n,o){return n!=null&&r(n,o,e)}return zs=t,zs}var Bs,Kp;function HC(){if(Kp)return Bs;Kp=1;var e=Px(),r=VC(),t=Ix(),n=du(),o=Ax(),i=Rx(),s=Xn(),a=1,c=2;function l(d,u){return n(d)&&o(u)?i(s(d),u):function(h){var p=r(h,d);return p===void 0&&p===u?t(h,d):e(u,p,a|c)}}return Bs=l,Bs}var Ds,Jp;function Nx(){if(Jp)return Ds;Jp=1;function e(r){return function(t){return t==null?void 0:t[r]}}return Ds=e,Ds}var Ws,Zp;function UC(){if(Zp)return Ws;Zp=1;var e=Vo();function r(t){return function(n){return e(n,t)}}return Ws=r,Ws}var Vs,Xp;function KC(){if(Xp)return Vs;Xp=1;var e=Nx(),r=UC(),t=du(),n=Xn();function o(i){return t(i)?e(n(i)):r(i)}return Vs=o,Vs}var Gs,Yp;function mr(){if(Yp)return Gs;Yp=1;var e=FC(),r=HC(),t=Kr(),n=Ct(),o=KC();function i(s){return typeof s=="function"?s:s==null?t:typeof s=="object"?n(s)?r(s[0],s[1]):e(s):o(s)}return Gs=i,Gs}var Hs,Qp;function Ox(){if(Qp)return Hs;Qp=1;var e=ux(),r=AC(),t=mr(),n=Ct();function o(i,s){var a=n(i)?e:r;return a(i,t(s,3))}return Hs=o,Hs}var Us,eg;function JC(){if(eg)return Us;eg=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n,o){return n!=null&&r.call(n,o)}return Us=t,Us}var Ks,tg;function $x(){if(tg)return Ks;tg=1;var e=JC(),r=Tx();function t(n,o){return n!=null&&r(n,o,e)}return Ks=t,Ks}var Js,rg;function ZC(){if(rg)return Js;rg=1;var e=ru(),r=gn(),t=Jn(),n=Ct(),o=yr(),i=pn(),s=Fo(),a=Zn(),c="[object Map]",l="[object Set]",d=Object.prototype,u=d.hasOwnProperty;function h(p){if(p==null)return!0;if(o(p)&&(n(p)||typeof p=="string"||typeof p.splice=="function"||i(p)||a(p)||t(p)))return!p.length;var m=r(p);if(m==c||m==l)return!p.size;if(s(p))return!e(p).length;for(var g in p)if(u.call(p,g))return!1;return!0}return Js=h,Js}var Zs,ng;function qx(){if(ng)return Zs;ng=1;function e(r){return r===void 0}return Zs=e,Zs}var Xs,og;function Lx(){if(og)return Xs;og=1;var e=Bo(),r=yr();function t(n,o){var i=-1,s=r(n)?Array(n.length):[];return e(n,function(a,c,l){s[++i]=o(a,c,l)}),s}return Xs=t,Xs}var Ys,ig;function Fx(){if(ig)return Ys;ig=1;var e=Do(),r=mr(),t=Lx(),n=Ct();function o(i,s){var a=n(i)?e:t;return a(i,r(s,3))}return Ys=o,Ys}var Qs,ag;function XC(){if(ag)return Qs;ag=1;function e(r,t,n,o){var i=-1,s=r==null?0:r.length;for(o&&s&&(n=r[++i]);++i<s;)n=t(n,r[i],i,r);return n}return Qs=e,Qs}var ec,sg;function YC(){if(sg)return ec;sg=1;function e(r,t,n,o,i){return i(r,function(s,a,c){n=o?(o=!1,s):t(n,s,a,c)}),n}return ec=e,ec}var tc,cg;function zx(){if(cg)return tc;cg=1;var e=XC(),r=Bo(),t=mr(),n=YC(),o=Ct();function i(s,a,c){var l=o(s)?e:n,d=arguments.length<3;return l(s,t(a,4),c,d,r)}return tc=i,tc}var rc,lg;function QC(){if(lg)return rc;lg=1;var e=Gr(),r=Ct(),t=lr(),n="[object String]";function o(i){return typeof i=="string"||!r(i)&&t(i)&&e(i)==n}return rc=o,rc}var nc,dg;function eS(){if(dg)return nc;dg=1;var e=Nx(),r=e("length");return nc=r,nc}var oc,ug;function tS(){if(ug)return oc;ug=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=r+t+n,i="\\ufe0e\\ufe0f",s="\\u200d",a=RegExp("["+s+e+o+i+"]");function c(l){return a.test(l)}return oc=c,oc}var ic,fg;function rS(){if(fg)return ic;fg=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=r+t+n,i="\\ufe0e\\ufe0f",s="["+e+"]",a="["+o+"]",c="\\ud83c[\\udffb-\\udfff]",l="(?:"+a+"|"+c+")",d="[^"+e+"]",u="(?:\\ud83c[\\udde6-\\uddff]){2}",h="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",m=l+"?",g="["+i+"]?",y="(?:"+p+"(?:"+[d,u,h].join("|")+")"+g+m+")*",b=g+m+y,x="(?:"+[d+a+"?",a,u,h,s].join("|")+")",v=RegExp(c+"(?="+c+")|"+x+b,"g");function w(C){for(var S=v.lastIndex=0;v.test(C);)++S;return S}return ic=w,ic}var ac,hg;function nS(){if(hg)return ac;hg=1;var e=eS(),r=tS(),t=rS();function n(o){return r(o)?t(o):e(o)}return ac=n,ac}var sc,pg;function oS(){if(pg)return sc;pg=1;var e=ru(),r=gn(),t=yr(),n=QC(),o=nS(),i="[object Map]",s="[object Set]";function a(c){if(c==null)return 0;if(t(c))return n(c)?o(c):c.length;var l=r(c);return l==i||l==s?c.size:e(c).length}return sc=a,sc}var cc,gg;function iS(){if(gg)return cc;gg=1;var e=Qd(),r=xx(),t=cu(),n=mr(),o=zo(),i=Ct(),s=pn(),a=Un(),c=Vt(),l=Zn();function d(u,h,p){var m=i(u),g=m||s(u)||l(u);if(h=n(h,4),p==null){var y=u&&u.constructor;g?p=m?new y:[]:c(u)?p=a(y)?r(o(u)):{}:p={}}return(g?e:t)(u,function(b,x,v){return h(p,b,x,v)}),p}return cc=d,cc}var lc,yg;function aS(){if(yg)return lc;yg=1;var e=hn(),r=Jn(),t=Ct(),n=e?e.isConcatSpreadable:void 0;function o(i){return t(i)||r(i)||!!(n&&i&&i[n])}return lc=o,lc}var dc,mg;function uu(){if(mg)return dc;mg=1;var e=ou(),r=aS();function t(n,o,i,s,a){var c=-1,l=n.length;for(i||(i=r),a||(a=[]);++c<l;){var d=n[c];o>0&&i(d)?o>1?t(d,o-1,i,s,a):e(a,d):s||(a[a.length]=d)}return a}return dc=t,dc}var uc,bg;function sS(){if(bg)return uc;bg=1;function e(r,t,n){switch(n.length){case 0:return r.call(t);case 1:return r.call(t,n[0]);case 2:return r.call(t,n[0],n[1]);case 3:return r.call(t,n[0],n[1],n[2])}return r.apply(t,n)}return uc=e,uc}var fc,xg;function Bx(){if(xg)return fc;xg=1;var e=sS(),r=Math.max;function t(n,o,i){return o=r(o===void 0?n.length-1:o,0),function(){for(var s=arguments,a=-1,c=r(s.length-o,0),l=Array(c);++a<c;)l[a]=s[o+a];a=-1;for(var d=Array(o+1);++a<o;)d[a]=s[a];return d[o]=i(l),e(n,this,d)}}return fc=t,fc}var hc,vg;function cS(){if(vg)return hc;vg=1;var e=au(),r=ax(),t=Kr(),n=r?function(o,i){return r(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:t;return hc=n,hc}var pc,wg;function lS(){if(wg)return pc;wg=1;var e=800,r=16,t=Date.now;function n(o){var i=0,s=0;return function(){var a=t(),c=r-(a-s);if(s=a,c>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return pc=n,pc}var gc,Cg;function Dx(){if(Cg)return gc;Cg=1;var e=cS(),r=lS(),t=r(e);return gc=t,gc}var yc,Sg;function Go(){if(Sg)return yc;Sg=1;var e=Kr(),r=Bx(),t=Dx();function n(o,i){return t(r(o,i,e),o+"")}return yc=n,yc}var mc,jg;function Wx(){if(jg)return mc;jg=1;function e(r,t,n,o){for(var i=r.length,s=n+(o?1:-1);o?s--:++s<i;)if(t(r[s],s,r))return s;return-1}return mc=e,mc}var bc,Eg;function dS(){if(Eg)return bc;Eg=1;function e(r){return r!==r}return bc=e,bc}var xc,_g;function uS(){if(_g)return xc;_g=1;function e(r,t,n){for(var o=n-1,i=r.length;++o<i;)if(r[o]===t)return o;return-1}return xc=e,xc}var vc,kg;function fS(){if(kg)return vc;kg=1;var e=Wx(),r=dS(),t=uS();function n(o,i,s){return i===i?t(o,i,s):e(o,r,s)}return vc=n,vc}var wc,Pg;function hS(){if(Pg)return wc;Pg=1;var e=fS();function r(t,n){var o=t==null?0:t.length;return!!o&&e(t,n,0)>-1}return wc=r,wc}var Cc,Ag;function pS(){if(Ag)return Cc;Ag=1;function e(r,t,n){for(var o=-1,i=r==null?0:r.length;++o<i;)if(n(t,r[o]))return!0;return!1}return Cc=e,Cc}var Sc,Rg;function gS(){if(Rg)return Sc;Rg=1;function e(){}return Sc=e,Sc}var jc,Mg;function yS(){if(Mg)return jc;Mg=1;var e=yx(),r=gS(),t=lu(),n=1/0,o=e&&1/t(new e([,-0]))[1]==n?function(i){return new e(i)}:r;return jc=o,jc}var Ec,Tg;function mS(){if(Tg)return Ec;Tg=1;var e=Ex(),r=hS(),t=pS(),n=_x(),o=yS(),i=lu(),s=200;function a(c,l,d){var u=-1,h=r,p=c.length,m=!0,g=[],y=g;if(d)m=!1,h=t;else if(p>=s){var b=l?null:o(c);if(b)return i(b);m=!1,h=n,y=new e}else y=l?[]:g;e:for(;++u<p;){var x=c[u],v=l?l(x):x;if(x=d||x!==0?x:0,m&&v===v){for(var w=y.length;w--;)if(y[w]===v)continue e;l&&y.push(v),g.push(x)}else h(y,v,d)||(y!==g&&y.push(v),g.push(x))}return g}return Ec=a,Ec}var _c,Ig;function Vx(){if(Ig)return _c;Ig=1;var e=yr(),r=lr();function t(n){return r(n)&&e(n)}return _c=t,_c}var kc,Ng;function bS(){if(Ng)return kc;Ng=1;var e=uu(),r=Go(),t=mS(),n=Vx(),o=r(function(i){return t(e(i,1,n,!0))});return kc=o,kc}var Pc,Og;function xS(){if(Og)return Pc;Og=1;var e=Do();function r(t,n){return e(n,function(o){return t[o]})}return Pc=r,Pc}var Ac,$g;function Gx(){if($g)return Ac;$g=1;var e=xS(),r=Mr();function t(n){return n==null?[]:e(n,r(n))}return Ac=t,Ac}var Rc,qg;function Gt(){if(qg)return Rc;qg=1;var e;if(typeof Zd=="function")try{e={clone:_C(),constant:au(),each:jx(),filter:Ox(),has:$x(),isArray:Ct(),isEmpty:ZC(),isFunction:Un(),isUndefined:qx(),keys:Mr(),map:Fx(),reduce:zx(),size:oS(),transform:iS(),union:bS(),values:Gx()}}catch{}return e||(e=window._),Rc=e,Rc}var Mc,Lg;function fu(){if(Lg)return Mc;Lg=1;var e=Gt();Mc=o;var r="\0",t="\0",n="";function o(d){this._isDirected=e.has(d,"directed")?d.directed:!0,this._isMultigraph=e.has(d,"multigraph")?d.multigraph:!1,this._isCompound=e.has(d,"compound")?d.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[t]={}),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(d){return this._label=d,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultNodeLabelFn=d,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._in[u])})},o.prototype.sinks=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._out[u])})},o.prototype.setNodes=function(d,u){var h=arguments,p=this;return e.each(d,function(m){h.length>1?p.setNode(m,u):p.setNode(m)}),this},o.prototype.setNode=function(d,u){return e.has(this._nodes,d)?(arguments.length>1&&(this._nodes[d]=u),this):(this._nodes[d]=arguments.length>1?u:this._defaultNodeLabelFn(d),this._isCompound&&(this._parent[d]=t,this._children[d]={},this._children[t][d]=!0),this._in[d]={},this._preds[d]={},this._out[d]={},this._sucs[d]={},++this._nodeCount,this)},o.prototype.node=function(d){return this._nodes[d]},o.prototype.hasNode=function(d){return e.has(this._nodes,d)},o.prototype.removeNode=function(d){var u=this;if(e.has(this._nodes,d)){var h=function(p){u.removeEdge(u._edgeObjs[p])};delete this._nodes[d],this._isCompound&&(this._removeFromParentsChildList(d),delete this._parent[d],e.each(this.children(d),function(p){u.setParent(p)}),delete this._children[d]),e.each(e.keys(this._in[d]),h),delete this._in[d],delete this._preds[d],e.each(e.keys(this._out[d]),h),delete this._out[d],delete this._sucs[d],--this._nodeCount}return this},o.prototype.setParent=function(d,u){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(u))u=t;else{u+="";for(var h=u;!e.isUndefined(h);h=this.parent(h))if(h===d)throw new Error("Setting "+u+" as parent of "+d+" would create a cycle");this.setNode(u)}return this.setNode(d),this._removeFromParentsChildList(d),this._parent[d]=u,this._children[u][d]=!0,this},o.prototype._removeFromParentsChildList=function(d){delete this._children[this._parent[d]][d]},o.prototype.parent=function(d){if(this._isCompound){var u=this._parent[d];if(u!==t)return u}},o.prototype.children=function(d){if(e.isUndefined(d)&&(d=t),this._isCompound){var u=this._children[d];if(u)return e.keys(u)}else{if(d===t)return this.nodes();if(this.hasNode(d))return[]}},o.prototype.predecessors=function(d){var u=this._preds[d];if(u)return e.keys(u)},o.prototype.successors=function(d){var u=this._sucs[d];if(u)return e.keys(u)},o.prototype.neighbors=function(d){var u=this.predecessors(d);if(u)return e.union(u,this.successors(d))},o.prototype.isLeaf=function(d){var u;return this.isDirected()?u=this.successors(d):u=this.neighbors(d),u.length===0},o.prototype.filterNodes=function(d){var u=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});u.setGraph(this.graph());var h=this;e.each(this._nodes,function(g,y){d(y)&&u.setNode(y,g)}),e.each(this._edgeObjs,function(g){u.hasNode(g.v)&&u.hasNode(g.w)&&u.setEdge(g,h.edge(g))});var p={};function m(g){var y=h.parent(g);return y===void 0||u.hasNode(y)?(p[g]=y,y):y in p?p[y]:m(y)}return this._isCompound&&e.each(u.nodes(),function(g){u.setParent(g,m(g))}),u},o.prototype.setDefaultEdgeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultEdgeLabelFn=d,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(d,u){var h=this,p=arguments;return e.reduce(d,function(m,g){return p.length>1?h.setEdge(m,g,u):h.setEdge(m,g),g}),this},o.prototype.setEdge=function(){var d,u,h,p,m=!1,g=arguments[0];typeof g=="object"&&g!==null&&"v"in g?(d=g.v,u=g.w,h=g.name,arguments.length===2&&(p=arguments[1],m=!0)):(d=g,u=arguments[1],h=arguments[3],arguments.length>2&&(p=arguments[2],m=!0)),d=""+d,u=""+u,e.isUndefined(h)||(h=""+h);var y=a(this._isDirected,d,u,h);if(e.has(this._edgeLabels,y))return m&&(this._edgeLabels[y]=p),this;if(!e.isUndefined(h)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(d),this.setNode(u),this._edgeLabels[y]=m?p:this._defaultEdgeLabelFn(d,u,h);var b=c(this._isDirected,d,u,h);return d=b.v,u=b.w,Object.freeze(b),this._edgeObjs[y]=b,i(this._preds[u],d),i(this._sucs[d],u),this._in[u][y]=b,this._out[d][y]=b,this._edgeCount++,this},o.prototype.edge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h);return this._edgeLabels[p]},o.prototype.hasEdge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h);return e.has(this._edgeLabels,p)},o.prototype.removeEdge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h),m=this._edgeObjs[p];return m&&(d=m.v,u=m.w,delete this._edgeLabels[p],delete this._edgeObjs[p],s(this._preds[u],d),s(this._sucs[d],u),delete this._in[u][p],delete this._out[d][p],this._edgeCount--),this},o.prototype.inEdges=function(d,u){var h=this._in[d];if(h){var p=e.values(h);return u?e.filter(p,function(m){return m.v===u}):p}},o.prototype.outEdges=function(d,u){var h=this._out[d];if(h){var p=e.values(h);return u?e.filter(p,function(m){return m.w===u}):p}},o.prototype.nodeEdges=function(d,u){var h=this.inEdges(d,u);if(h)return h.concat(this.outEdges(d,u))};function i(d,u){d[u]?d[u]++:d[u]=1}function s(d,u){--d[u]||delete d[u]}function a(d,u,h,p){var m=""+u,g=""+h;if(!d&&m>g){var y=m;m=g,g=y}return m+n+g+n+(e.isUndefined(p)?r:p)}function c(d,u,h,p){var m=""+u,g=""+h;if(!d&&m>g){var y=m;m=g,g=y}var b={v:m,w:g};return p&&(b.name=p),b}function l(d,u){return a(d,u.v,u.w,u.name)}return Mc}var Tc,Fg;function vS(){return Fg||(Fg=1,Tc="2.1.8"),Tc}var Ic,zg;function wS(){return zg||(zg=1,Ic={Graph:fu(),version:vS()}),Ic}var Nc,Bg;function CS(){if(Bg)return Nc;Bg=1;var e=Gt(),r=fu();Nc={write:t,read:i};function t(s){var a={options:{directed:s.isDirected(),multigraph:s.isMultigraph(),compound:s.isCompound()},nodes:n(s),edges:o(s)};return e.isUndefined(s.graph())||(a.value=e.clone(s.graph())),a}function n(s){return e.map(s.nodes(),function(a){var c=s.node(a),l=s.parent(a),d={v:a};return e.isUndefined(c)||(d.value=c),e.isUndefined(l)||(d.parent=l),d})}function o(s){return e.map(s.edges(),function(a){var c=s.edge(a),l={v:a.v,w:a.w};return e.isUndefined(a.name)||(l.name=a.name),e.isUndefined(c)||(l.value=c),l})}function i(s){var a=new r(s.options).setGraph(s.value);return e.each(s.nodes,function(c){a.setNode(c.v,c.value),c.parent&&a.setParent(c.v,c.parent)}),e.each(s.edges,function(c){a.setEdge({v:c.v,w:c.w,name:c.name},c.value)}),a}return Nc}var Oc,Dg;function SS(){if(Dg)return Oc;Dg=1;var e=Gt();Oc=r;function r(t){var n={},o=[],i;function s(a){e.has(n,a)||(n[a]=!0,i.push(a),e.each(t.successors(a),s),e.each(t.predecessors(a),s))}return e.each(t.nodes(),function(a){i=[],s(a),i.length&&o.push(i)}),o}return Oc}var $c,Wg;function Hx(){if(Wg)return $c;Wg=1;var e=Gt();$c=r;function r(){this._arr=[],this._keyIndices={}}return r.prototype.size=function(){return this._arr.length},r.prototype.keys=function(){return this._arr.map(function(t){return t.key})},r.prototype.has=function(t){return e.has(this._keyIndices,t)},r.prototype.priority=function(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority},r.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},r.prototype.add=function(t,n){var o=this._keyIndices;if(t=String(t),!e.has(o,t)){var i=this._arr,s=i.length;return o[t]=s,i.push({key:t,priority:n}),this._decrease(s),!0}return!1},r.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key},r.prototype.decrease=function(t,n){var o=this._keyIndices[t];if(n>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[o].priority+" New: "+n);this._arr[o].priority=n,this._decrease(o)},r.prototype._heapify=function(t){var n=this._arr,o=2*t,i=o+1,s=t;o<n.length&&(s=n[o].priority<n[s].priority?o:s,i<n.length&&(s=n[i].priority<n[s].priority?i:s),s!==t&&(this._swap(t,s),this._heapify(s)))},r.prototype._decrease=function(t){for(var n=this._arr,o=n[t].priority,i;t!==0&&(i=t>>1,!(n[i].priority<o));)this._swap(t,i),t=i},r.prototype._swap=function(t,n){var o=this._arr,i=this._keyIndices,s=o[t],a=o[n];o[t]=a,o[n]=s,i[a.key]=t,i[s.key]=n},$c}var qc,Vg;function Ux(){if(Vg)return qc;Vg=1;var e=Gt(),r=Hx();qc=n;var t=e.constant(1);function n(i,s,a,c){return o(i,String(s),a||t,c||function(l){return i.outEdges(l)})}function o(i,s,a,c){var l={},d=new r,u,h,p=function(m){var g=m.v!==u?m.v:m.w,y=l[g],b=a(m),x=h.distance+b;if(b<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+m+" Weight: "+b);x<y.distance&&(y.distance=x,y.predecessor=u,d.decrease(g,x))};for(i.nodes().forEach(function(m){var g=m===s?0:Number.POSITIVE_INFINITY;l[m]={distance:g},d.add(m,g)});d.size()>0&&(u=d.removeMin(),h=l[u],h.distance!==Number.POSITIVE_INFINITY);)c(u).forEach(p);return l}return qc}var Lc,Gg;function jS(){if(Gg)return Lc;Gg=1;var e=Ux(),r=Gt();Lc=t;function t(n,o,i){return r.transform(n.nodes(),function(s,a){s[a]=e(n,a,o,i)},{})}return Lc}var Fc,Hg;function Kx(){if(Hg)return Fc;Hg=1;var e=Gt();Fc=r;function r(t){var n=0,o=[],i={},s=[];function a(c){var l=i[c]={onStack:!0,lowlink:n,index:n++};if(o.push(c),t.successors(c).forEach(function(h){e.has(i,h)?i[h].onStack&&(l.lowlink=Math.min(l.lowlink,i[h].index)):(a(h),l.lowlink=Math.min(l.lowlink,i[h].lowlink))}),l.lowlink===l.index){var d=[],u;do u=o.pop(),i[u].onStack=!1,d.push(u);while(c!==u);s.push(d)}}return t.nodes().forEach(function(c){e.has(i,c)||a(c)}),s}return Fc}var zc,Ug;function ES(){if(Ug)return zc;Ug=1;var e=Gt(),r=Kx();zc=t;function t(n){return e.filter(r(n),function(o){return o.length>1||o.length===1&&n.hasEdge(o[0],o[0])})}return zc}var Bc,Kg;function _S(){if(Kg)return Bc;Kg=1;var e=Gt();Bc=t;var r=e.constant(1);function t(o,i,s){return n(o,i||r,s||function(a){return o.outEdges(a)})}function n(o,i,s){var a={},c=o.nodes();return c.forEach(function(l){a[l]={},a[l][l]={distance:0},c.forEach(function(d){l!==d&&(a[l][d]={distance:Number.POSITIVE_INFINITY})}),s(l).forEach(function(d){var u=d.v===l?d.w:d.v,h=i(d);a[l][u]={distance:h,predecessor:l}})}),c.forEach(function(l){var d=a[l];c.forEach(function(u){var h=a[u];c.forEach(function(p){var m=h[l],g=d[p],y=h[p],b=m.distance+g.distance;b<y.distance&&(y.distance=b,y.predecessor=g.predecessor)})})}),a}return Bc}var Dc,Jg;function Jx(){if(Jg)return Dc;Jg=1;var e=Gt();Dc=r,r.CycleException=t;function r(n){var o={},i={},s=[];function a(c){if(e.has(i,c))throw new t;e.has(o,c)||(i[c]=!0,o[c]=!0,e.each(n.predecessors(c),a),delete i[c],s.push(c))}if(e.each(n.sinks(),a),e.size(o)!==n.nodeCount())throw new t;return s}function t(){}return t.prototype=new Error,Dc}var Wc,Zg;function kS(){if(Zg)return Wc;Zg=1;var e=Jx();Wc=r;function r(t){try{e(t)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Wc}var Vc,Xg;function Zx(){if(Xg)return Vc;Xg=1;var e=Gt();Vc=r;function r(n,o,i){e.isArray(o)||(o=[o]);var s=(n.isDirected()?n.successors:n.neighbors).bind(n),a=[],c={};return e.each(o,function(l){if(!n.hasNode(l))throw new Error("Graph does not have node: "+l);t(n,l,i==="post",c,s,a)}),a}function t(n,o,i,s,a,c){e.has(s,o)||(s[o]=!0,i||c.push(o),e.each(a(o),function(l){t(n,l,i,s,a,c)}),i&&c.push(o))}return Vc}var Gc,Yg;function PS(){if(Yg)return Gc;Yg=1;var e=Zx();Gc=r;function r(t,n){return e(t,n,"post")}return Gc}var Hc,Qg;function AS(){if(Qg)return Hc;Qg=1;var e=Zx();Hc=r;function r(t,n){return e(t,n,"pre")}return Hc}var Uc,ey;function RS(){if(ey)return Uc;ey=1;var e=Gt(),r=fu(),t=Hx();Uc=n;function n(o,i){var s=new r,a={},c=new t,l;function d(h){var p=h.v===l?h.w:h.v,m=c.priority(p);if(m!==void 0){var g=i(h);g<m&&(a[p]=l,c.decrease(p,g))}}if(o.nodeCount()===0)return s;e.each(o.nodes(),function(h){c.add(h,Number.POSITIVE_INFINITY),s.setNode(h)}),c.decrease(o.nodes()[0],0);for(var u=!1;c.size()>0;){if(l=c.removeMin(),e.has(a,l))s.setEdge(l,a[l]);else{if(u)throw new Error("Input graph is not connected: "+o);u=!0}o.nodeEdges(l).forEach(d)}return s}return Uc}var Kc,ty;function MS(){return ty||(ty=1,Kc={components:SS(),dijkstra:Ux(),dijkstraAll:jS(),findCycles:ES(),floydWarshall:_S(),isAcyclic:kS(),postorder:PS(),preorder:AS(),prim:RS(),tarjan:Kx(),topsort:Jx()}),Kc}var Jc,ry;function TS(){if(ry)return Jc;ry=1;var e=wS();return Jc={Graph:e.Graph,json:CS(),alg:MS(),version:e.version},Jc}var Zc,ny;function Zt(){if(ny)return Zc;ny=1;var e;if(typeof Zd=="function")try{e=TS()}catch{}return e||(e=window.graphlib),Zc=e,Zc}var Xc,oy;function IS(){if(oy)return Xc;oy=1;var e=wx(),r=1,t=4;function n(o){return e(o,r|t)}return Xc=n,Xc}var Yc,iy;function Ho(){if(iy)return Yc;iy=1;var e=fn(),r=yr(),t=qo(),n=Vt();function o(i,s,a){if(!n(a))return!1;var c=typeof s;return(c=="number"?r(a)&&t(s,a.length):c=="string"&&s in a)?e(a[s],i):!1}return Yc=o,Yc}var Qc,ay;function NS(){if(ay)return Qc;ay=1;var e=Go(),r=fn(),t=Ho(),n=Ur(),o=Object.prototype,i=o.hasOwnProperty,s=e(function(a,c){a=Object(a);var l=-1,d=c.length,u=d>2?c[2]:void 0;for(u&&t(c[0],c[1],u)&&(d=1);++l<d;)for(var h=c[l],p=n(h),m=-1,g=p.length;++m<g;){var y=p[m],b=a[y];(b===void 0||r(b,o[y])&&!i.call(a,y))&&(a[y]=h[y])}return a});return Qc=s,Qc}var el,sy;function OS(){if(sy)return el;sy=1;var e=mr(),r=yr(),t=Mr();function n(o){return function(i,s,a){var c=Object(i);if(!r(i)){var l=e(s,3);i=t(i),s=function(u){return l(c[u],u,c)}}var d=o(i,s,a);return d>-1?c[l?i[d]:d]:void 0}}return el=n,el}var tl,cy;function $S(){if(cy)return tl;cy=1;var e=/\s/;function r(t){for(var n=t.length;n--&&e.test(t.charAt(n)););return n}return tl=r,tl}var rl,ly;function qS(){if(ly)return rl;ly=1;var e=$S(),r=/^\s+/;function t(n){return n&&n.slice(0,e(n)+1).replace(r,"")}return rl=t,rl}var nl,dy;function LS(){if(dy)return nl;dy=1;var e=qS(),r=Vt(),t=yn(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,s=/^0o[0-7]+$/i,a=parseInt;function c(l){if(typeof l=="number")return l;if(t(l))return n;if(r(l)){var d=typeof l.valueOf=="function"?l.valueOf():l;l=r(d)?d+"":d}if(typeof l!="string")return l===0?l:+l;l=e(l);var u=i.test(l);return u||s.test(l)?a(l.slice(2),u?2:8):o.test(l)?n:+l}return nl=c,nl}var ol,uy;function Xx(){if(uy)return ol;uy=1;var e=LS(),r=1/0,t=17976931348623157e292;function n(o){if(!o)return o===0?o:0;if(o=e(o),o===r||o===-r){var i=o<0?-1:1;return i*t}return o===o?o:0}return ol=n,ol}var il,fy;function FS(){if(fy)return il;fy=1;var e=Xx();function r(t){var n=e(t),o=n%1;return n===n?o?n-o:n:0}return il=r,il}var al,hy;function zS(){if(hy)return al;hy=1;var e=Wx(),r=mr(),t=FS(),n=Math.max;function o(i,s,a){var c=i==null?0:i.length;if(!c)return-1;var l=a==null?0:t(a);return l<0&&(l=n(c+l,0)),e(i,r(s,3),l)}return al=o,al}var sl,py;function BS(){if(py)return sl;py=1;var e=OS(),r=zS(),t=e(r);return sl=t,sl}var cl,gy;function Yx(){if(gy)return cl;gy=1;var e=uu();function r(t){var n=t==null?0:t.length;return n?e(t,1):[]}return cl=r,cl}var ll,yy;function DS(){if(yy)return ll;yy=1;var e=su(),r=Cx(),t=Ur();function n(o,i){return o==null?o:e(o,r(i),t)}return ll=n,ll}var dl,my;function WS(){if(my)return dl;my=1;function e(r){var t=r==null?0:r.length;return t?r[t-1]:void 0}return dl=e,dl}var ul,by;function VS(){if(by)return ul;by=1;var e=Oo(),r=cu(),t=mr();function n(o,i){var s={};return i=t(i,3),r(o,function(a,c,l){e(s,c,i(a,c,l))}),s}return ul=n,ul}var fl,xy;function hu(){if(xy)return fl;xy=1;var e=yn();function r(t,n,o){for(var i=-1,s=t.length;++i<s;){var a=t[i],c=n(a);if(c!=null&&(l===void 0?c===c&&!e(c):o(c,l)))var l=c,d=a}return d}return fl=r,fl}var hl,vy;function GS(){if(vy)return hl;vy=1;function e(r,t){return r>t}return hl=e,hl}var pl,wy;function HS(){if(wy)return pl;wy=1;var e=hu(),r=GS(),t=Kr();function n(o){return o&&o.length?e(o,t,r):void 0}return pl=n,pl}var gl,Cy;function Qx(){if(Cy)return gl;Cy=1;var e=Oo(),r=fn();function t(n,o,i){(i!==void 0&&!r(n[o],i)||i===void 0&&!(o in n))&&e(n,o,i)}return gl=t,gl}var yl,Sy;function US(){if(Sy)return yl;Sy=1;var e=Gr(),r=zo(),t=lr(),n="[object Object]",o=Function.prototype,i=Object.prototype,s=o.toString,a=i.hasOwnProperty,c=s.call(Object);function l(d){if(!t(d)||e(d)!=n)return!1;var u=r(d);if(u===null)return!0;var h=a.call(u,"constructor")&&u.constructor;return typeof h=="function"&&h instanceof h&&s.call(h)==c}return yl=l,yl}var ml,jy;function ev(){if(jy)return ml;jy=1;function e(r,t){if(!(t==="constructor"&&typeof r[t]=="function")&&t!="__proto__")return r[t]}return ml=e,ml}var bl,Ey;function KS(){if(Ey)return bl;Ey=1;var e=Kn(),r=Ur();function t(n){return e(n,r(n))}return bl=t,bl}var xl,_y;function JS(){if(_y)return xl;_y=1;var e=Qx(),r=lx(),t=bx(),n=dx(),o=vx(),i=Jn(),s=Ct(),a=Vx(),c=pn(),l=Un(),d=Vt(),u=US(),h=Zn(),p=ev(),m=KS();function g(y,b,x,v,w,C,S){var E=p(y,x),M=p(b,x),P=S.get(M);if(P){e(y,x,P);return}var T=C?C(E,M,x+"",y,b,S):void 0,k=T===void 0;if(k){var R=s(M),_=!R&&c(M),N=!R&&!_&&h(M);T=M,R||_||N?s(E)?T=E:a(E)?T=n(E):_?(k=!1,T=r(M,!0)):N?(k=!1,T=t(M,!0)):T=[]:u(M)||i(M)?(T=E,i(E)?T=m(E):(!d(E)||l(E))&&(T=o(M))):k=!1}k&&(S.set(M,T),w(T,M,v,C,S),S.delete(M)),e(y,x,T)}return xl=g,xl}var vl,ky;function ZS(){if(ky)return vl;ky=1;var e=No(),r=Qx(),t=su(),n=JS(),o=Vt(),i=Ur(),s=ev();function a(c,l,d,u,h){c!==l&&t(l,function(p,m){if(h||(h=new e),o(p))n(c,l,m,d,a,u,h);else{var g=u?u(s(c,m),p,m+"",c,l,h):void 0;g===void 0&&(g=p),r(c,m,g)}},i)}return vl=a,vl}var wl,Py;function XS(){if(Py)return wl;Py=1;var e=Go(),r=Ho();function t(n){return e(function(o,i){var s=-1,a=i.length,c=a>1?i[a-1]:void 0,l=a>2?i[2]:void 0;for(c=n.length>3&&typeof c=="function"?(a--,c):void 0,l&&r(i[0],i[1],l)&&(c=a<3?void 0:c,a=1),o=Object(o);++s<a;){var d=i[s];d&&n(o,d,s,c)}return o})}return wl=t,wl}var Cl,Ay;function YS(){if(Ay)return Cl;Ay=1;var e=ZS(),r=XS(),t=r(function(n,o,i){e(n,o,i)});return Cl=t,Cl}var Sl,Ry;function tv(){if(Ry)return Sl;Ry=1;function e(r,t){return r<t}return Sl=e,Sl}var jl,My;function QS(){if(My)return jl;My=1;var e=hu(),r=tv(),t=Kr();function n(o){return o&&o.length?e(o,t,r):void 0}return jl=n,jl}var El,Ty;function ej(){if(Ty)return El;Ty=1;var e=hu(),r=mr(),t=tv();function n(o,i){return o&&o.length?e(o,r(i,2),t):void 0}return El=n,El}var _l,Iy;function tj(){if(Iy)return _l;Iy=1;var e=Yt(),r=function(){return e.Date.now()};return _l=r,_l}var kl,Ny;function rj(){if(Ny)return kl;Ny=1;var e=$o(),r=Wo(),t=qo(),n=Vt(),o=Xn();function i(s,a,c,l){if(!n(s))return s;a=r(a,s);for(var d=-1,u=a.length,h=u-1,p=s;p!=null&&++d<u;){var m=o(a[d]),g=c;if(m==="__proto__"||m==="constructor"||m==="prototype")return s;if(d!=h){var y=p[m];g=l?l(y,m,p):void 0,g===void 0&&(g=n(y)?y:t(a[d+1])?[]:{})}e(p,m,g),p=p[m]}return s}return kl=i,kl}var Pl,Oy;function nj(){if(Oy)return Pl;Oy=1;var e=Vo(),r=rj(),t=Wo();function n(o,i,s){for(var a=-1,c=i.length,l={};++a<c;){var d=i[a],u=e(o,d);s(u,d)&&r(l,t(d,o),u)}return l}return Pl=n,Pl}var Al,$y;function oj(){if($y)return Al;$y=1;var e=nj(),r=Ix();function t(n,o){return e(n,o,function(i,s){return r(n,s)})}return Al=t,Al}var Rl,qy;function ij(){if(qy)return Rl;qy=1;var e=Yx(),r=Bx(),t=Dx();function n(o){return t(r(o,void 0,e),o+"")}return Rl=n,Rl}var Ml,Ly;function aj(){if(Ly)return Ml;Ly=1;var e=oj(),r=ij(),t=r(function(n,o){return n==null?{}:e(n,o)});return Ml=t,Ml}var Tl,Fy;function sj(){if(Fy)return Tl;Fy=1;var e=Math.ceil,r=Math.max;function t(n,o,i,s){for(var a=-1,c=r(e((o-n)/(i||1)),0),l=Array(c);c--;)l[s?c:++a]=n,n+=i;return l}return Tl=t,Tl}var Il,zy;function cj(){if(zy)return Il;zy=1;var e=sj(),r=Ho(),t=Xx();function n(o){return function(i,s,a){return a&&typeof a!="number"&&r(i,s,a)&&(s=a=void 0),i=t(i),s===void 0?(s=i,i=0):s=t(s),a=a===void 0?i<s?1:-1:t(a),e(i,s,a,o)}}return Il=n,Il}var Nl,By;function lj(){if(By)return Nl;By=1;var e=cj(),r=e();return Nl=r,Nl}var Ol,Dy;function dj(){if(Dy)return Ol;Dy=1;function e(r,t){var n=r.length;for(r.sort(t);n--;)r[n]=r[n].value;return r}return Ol=e,Ol}var $l,Wy;function uj(){if(Wy)return $l;Wy=1;var e=yn();function r(t,n){if(t!==n){var o=t!==void 0,i=t===null,s=t===t,a=e(t),c=n!==void 0,l=n===null,d=n===n,u=e(n);if(!l&&!u&&!a&&t>n||a&&c&&d&&!l&&!u||i&&c&&d||!o&&d||!s)return 1;if(!i&&!a&&!u&&t<n||u&&o&&s&&!i&&!a||l&&o&&s||!c&&s||!d)return-1}return 0}return $l=r,$l}var ql,Vy;function fj(){if(Vy)return ql;Vy=1;var e=uj();function r(t,n,o){for(var i=-1,s=t.criteria,a=n.criteria,c=s.length,l=o.length;++i<c;){var d=e(s[i],a[i]);if(d){if(i>=l)return d;var u=o[i];return d*(u=="desc"?-1:1)}}return t.index-n.index}return ql=r,ql}var Ll,Gy;function hj(){if(Gy)return Ll;Gy=1;var e=Do(),r=Vo(),t=mr(),n=Lx(),o=dj(),i=Lo(),s=fj(),a=Kr(),c=Ct();function l(d,u,h){u.length?u=e(u,function(g){return c(g)?function(y){return r(y,g.length===1?g[0]:g)}:g}):u=[a];var p=-1;u=e(u,i(t));var m=n(d,function(g,y,b){var x=e(u,function(v){return v(g)});return{criteria:x,index:++p,value:g}});return o(m,function(g,y){return s(g,y,h)})}return Ll=l,Ll}var Fl,Hy;function pj(){if(Hy)return Fl;Hy=1;var e=uu(),r=hj(),t=Go(),n=Ho(),o=t(function(i,s){if(i==null)return[];var a=s.length;return a>1&&n(i,s[0],s[1])?s=[]:a>2&&n(s[0],s[1],s[2])&&(s=[s[0]]),r(i,e(s,1),[])});return Fl=o,Fl}var zl,Uy;function gj(){if(Uy)return zl;Uy=1;var e=Mx(),r=0;function t(n){var o=++r;return e(n)+o}return zl=t,zl}var Bl,Ky;function yj(){if(Ky)return Bl;Ky=1;function e(r,t,n){for(var o=-1,i=r.length,s=t.length,a={};++o<i;){var c=o<s?t[o]:void 0;n(a,r[o],c)}return a}return Bl=e,Bl}var Dl,Jy;function mj(){if(Jy)return Dl;Jy=1;var e=$o(),r=yj();function t(n,o){return r(n||[],o||[],e)}return Dl=t,Dl}var Wl,Zy;function gt(){if(Zy)return Wl;Zy=1;var e;if(typeof Zd=="function")try{e={cloneDeep:IS(),constant:au(),defaults:NS(),each:jx(),filter:Ox(),find:BS(),flatten:Yx(),forEach:Sx(),forIn:DS(),has:$x(),isUndefined:qx(),last:WS(),map:Fx(),mapValues:VS(),max:HS(),merge:YS(),min:QS(),minBy:ej(),now:tj(),pick:aj(),range:lj(),reduce:zx(),sortBy:pj(),uniqueId:gj(),values:Gx(),zipObject:mj()}}catch{}return e||(e=window._),Wl=e,Wl}var Vl,Xy;function bj(){if(Xy)return Vl;Xy=1,Vl=e;function e(){var n={};n._next=n._prev=n,this._sentinel=n}e.prototype.dequeue=function(){var n=this._sentinel,o=n._prev;if(o!==n)return r(o),o},e.prototype.enqueue=function(n){var o=this._sentinel;n._prev&&n._next&&r(n),n._next=o._next,o._next._prev=n,o._next=n,n._prev=o},e.prototype.toString=function(){for(var n=[],o=this._sentinel,i=o._prev;i!==o;)n.push(JSON.stringify(i,t)),i=i._prev;return"["+n.join(", ")+"]"};function r(n){n._prev._next=n._next,n._next._prev=n._prev,delete n._next,delete n._prev}function t(n,o){if(n!=="_next"&&n!=="_prev")return o}return Vl}var Gl,Yy;function xj(){if(Yy)return Gl;Yy=1;var e=gt(),r=Zt().Graph,t=bj();Gl=o;var n=e.constant(1);function o(l,d){if(l.nodeCount()<=1)return[];var u=a(l,d||n),h=i(u.graph,u.buckets,u.zeroIdx);return e.flatten(e.map(h,function(p){return l.outEdges(p.v,p.w)}),!0)}function i(l,d,u){for(var h=[],p=d[d.length-1],m=d[0],g;l.nodeCount();){for(;g=m.dequeue();)s(l,d,u,g);for(;g=p.dequeue();)s(l,d,u,g);if(l.nodeCount()){for(var y=d.length-2;y>0;--y)if(g=d[y].dequeue(),g){h=h.concat(s(l,d,u,g,!0));break}}}return h}function s(l,d,u,h,p){var m=p?[]:void 0;return e.forEach(l.inEdges(h.v),function(g){var y=l.edge(g),b=l.node(g.v);p&&m.push({v:g.v,w:g.w}),b.out-=y,c(d,u,b)}),e.forEach(l.outEdges(h.v),function(g){var y=l.edge(g),b=g.w,x=l.node(b);x.in-=y,c(d,u,x)}),l.removeNode(h.v),m}function a(l,d){var u=new r,h=0,p=0;e.forEach(l.nodes(),function(y){u.setNode(y,{v:y,in:0,out:0})}),e.forEach(l.edges(),function(y){var b=u.edge(y.v,y.w)||0,x=d(y),v=b+x;u.setEdge(y.v,y.w,v),p=Math.max(p,u.node(y.v).out+=x),h=Math.max(h,u.node(y.w).in+=x)});var m=e.range(p+h+3).map(function(){return new t}),g=h+1;return e.forEach(u.nodes(),function(y){c(m,g,u.node(y))}),{graph:u,buckets:m,zeroIdx:g}}function c(l,d,u){u.out?u.in?l[u.out-u.in+d].enqueue(u):l[l.length-1].enqueue(u):l[0].enqueue(u)}return Gl}var Hl,Qy;function vj(){if(Qy)return Hl;Qy=1;var e=gt(),r=xj();Hl={run:t,undo:o};function t(i){var s=i.graph().acyclicer==="greedy"?r(i,a(i)):n(i);e.forEach(s,function(c){var l=i.edge(c);i.removeEdge(c),l.forwardName=c.name,l.reversed=!0,i.setEdge(c.w,c.v,l,e.uniqueId("rev"))});function a(c){return function(l){return c.edge(l).weight}}}function n(i){var s=[],a={},c={};function l(d){e.has(c,d)||(c[d]=!0,a[d]=!0,e.forEach(i.outEdges(d),function(u){e.has(a,u.w)?s.push(u):l(u.w)}),delete a[d])}return e.forEach(i.nodes(),l),s}function o(i){e.forEach(i.edges(),function(s){var a=i.edge(s);if(a.reversed){i.removeEdge(s);var c=a.forwardName;delete a.reversed,delete a.forwardName,i.setEdge(s.w,s.v,a,c)}})}return Hl}var Ul,em;function Nt(){if(em)return Ul;em=1;var e=gt(),r=Zt().Graph;Ul={addDummyNode:t,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:s,intersectRect:a,buildLayerMatrix:c,normalizeRanks:l,removeEmptyRanks:d,addBorderNode:u,maxRank:h,partition:p,time:m,notime:g};function t(y,b,x,v){var w;do w=e.uniqueId(v);while(y.hasNode(w));return x.dummy=b,y.setNode(w,x),w}function n(y){var b=new r().setGraph(y.graph());return e.forEach(y.nodes(),function(x){b.setNode(x,y.node(x))}),e.forEach(y.edges(),function(x){var v=b.edge(x.v,x.w)||{weight:0,minlen:1},w=y.edge(x);b.setEdge(x.v,x.w,{weight:v.weight+w.weight,minlen:Math.max(v.minlen,w.minlen)})}),b}function o(y){var b=new r({multigraph:y.isMultigraph()}).setGraph(y.graph());return e.forEach(y.nodes(),function(x){y.children(x).length||b.setNode(x,y.node(x))}),e.forEach(y.edges(),function(x){b.setEdge(x,y.edge(x))}),b}function i(y){var b=e.map(y.nodes(),function(x){var v={};return e.forEach(y.outEdges(x),function(w){v[w.w]=(v[w.w]||0)+y.edge(w).weight}),v});return e.zipObject(y.nodes(),b)}function s(y){var b=e.map(y.nodes(),function(x){var v={};return e.forEach(y.inEdges(x),function(w){v[w.v]=(v[w.v]||0)+y.edge(w).weight}),v});return e.zipObject(y.nodes(),b)}function a(y,b){var x=y.x,v=y.y,w=b.x-x,C=b.y-v,S=y.width/2,E=y.height/2;if(!w&&!C)throw new Error("Not possible to find intersection inside of the rectangle");var M,P;return Math.abs(C)*S>Math.abs(w)*E?(C<0&&(E=-E),M=E*w/C,P=E):(w<0&&(S=-S),M=S,P=S*C/w),{x:x+M,y:v+P}}function c(y){var b=e.map(e.range(h(y)+1),function(){return[]});return e.forEach(y.nodes(),function(x){var v=y.node(x),w=v.rank;e.isUndefined(w)||(b[w][v.order]=x)}),b}function l(y){var b=e.min(e.map(y.nodes(),function(x){return y.node(x).rank}));e.forEach(y.nodes(),function(x){var v=y.node(x);e.has(v,"rank")&&(v.rank-=b)})}function d(y){var b=e.min(e.map(y.nodes(),function(C){return y.node(C).rank})),x=[];e.forEach(y.nodes(),function(C){var S=y.node(C).rank-b;x[S]||(x[S]=[]),x[S].push(C)});var v=0,w=y.graph().nodeRankFactor;e.forEach(x,function(C,S){e.isUndefined(C)&&S%w!==0?--v:v&&e.forEach(C,function(E){y.node(E).rank+=v})})}function u(y,b,x,v){var w={width:0,height:0};return arguments.length>=4&&(w.rank=x,w.order=v),t(y,"border",w,b)}function h(y){return e.max(e.map(y.nodes(),function(b){var x=y.node(b).rank;if(!e.isUndefined(x))return x}))}function p(y,b){var x={lhs:[],rhs:[]};return e.forEach(y,function(v){b(v)?x.lhs.push(v):x.rhs.push(v)}),x}function m(y,b){var x=e.now();try{return b()}finally{console.log(y+" time: "+(e.now()-x)+"ms")}}function g(y,b){return b()}return Ul}var Kl,tm;function wj(){if(tm)return Kl;tm=1;var e=gt(),r=Nt();Kl={run:t,undo:o};function t(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(s){n(i,s)})}function n(i,s){var a=s.v,c=i.node(a).rank,l=s.w,d=i.node(l).rank,u=s.name,h=i.edge(s),p=h.labelRank;if(d!==c+1){i.removeEdge(s);var m,g,y;for(y=0,++c;c<d;++y,++c)h.points=[],g={width:0,height:0,edgeLabel:h,edgeObj:s,rank:c},m=r.addDummyNode(i,"edge",g,"_d"),c===p&&(g.width=h.width,g.height=h.height,g.dummy="edge-label",g.labelpos=h.labelpos),i.setEdge(a,m,{weight:h.weight},u),y===0&&i.graph().dummyChains.push(m),a=m;i.setEdge(a,l,{weight:h.weight},u)}}function o(i){e.forEach(i.graph().dummyChains,function(s){var a=i.node(s),c=a.edgeLabel,l;for(i.setEdge(a.edgeObj,c);a.dummy;)l=i.successors(s)[0],i.removeNode(s),c.points.push({x:a.x,y:a.y}),a.dummy==="edge-label"&&(c.x=a.x,c.y=a.y,c.width=a.width,c.height=a.height),s=l,a=i.node(s)})}return Kl}var Jl,rm;function mo(){if(rm)return Jl;rm=1;var e=gt();Jl={longestPath:r,slack:t};function r(n){var o={};function i(s){var a=n.node(s);if(e.has(o,s))return a.rank;o[s]=!0;var c=e.min(e.map(n.outEdges(s),function(l){return i(l.w)-n.edge(l).minlen}));return(c===Number.POSITIVE_INFINITY||c===void 0||c===null)&&(c=0),a.rank=c}e.forEach(n.sources(),i)}function t(n,o){return n.node(o.w).rank-n.node(o.v).rank-n.edge(o).minlen}return Jl}var Zl,nm;function rv(){if(nm)return Zl;nm=1;var e=gt(),r=Zt().Graph,t=mo().slack;Zl=n;function n(a){var c=new r({directed:!1}),l=a.nodes()[0],d=a.nodeCount();c.setNode(l,{});for(var u,h;o(c,a)<d;)u=i(c,a),h=c.hasNode(u.v)?t(a,u):-t(a,u),s(c,a,h);return c}function o(a,c){function l(d){e.forEach(c.nodeEdges(d),function(u){var h=u.v,p=d===h?u.w:h;!a.hasNode(p)&&!t(c,u)&&(a.setNode(p,{}),a.setEdge(d,p,{}),l(p))})}return e.forEach(a.nodes(),l),a.nodeCount()}function i(a,c){return e.minBy(c.edges(),function(l){if(a.hasNode(l.v)!==a.hasNode(l.w))return t(c,l)})}function s(a,c,l){e.forEach(a.nodes(),function(d){c.node(d).rank+=l})}return Zl}var Xl,om;function Cj(){if(om)return Xl;om=1;var e=gt(),r=rv(),t=mo().slack,n=mo().longestPath,o=Zt().alg.preorder,i=Zt().alg.postorder,s=Nt().simplify;Xl=a,a.initLowLimValues=u,a.initCutValues=c,a.calcCutValue=d,a.leaveEdge=p,a.enterEdge=m,a.exchangeEdges=g;function a(v){v=s(v),n(v);var w=r(v);u(w),c(w,v);for(var C,S;C=p(w);)S=m(w,v,C),g(w,v,C,S)}function c(v,w){var C=i(v,v.nodes());C=C.slice(0,C.length-1),e.forEach(C,function(S){l(v,w,S)})}function l(v,w,C){var S=v.node(C),E=S.parent;v.edge(C,E).cutvalue=d(v,w,C)}function d(v,w,C){var S=v.node(C),E=S.parent,M=!0,P=w.edge(C,E),T=0;return P||(M=!1,P=w.edge(E,C)),T=P.weight,e.forEach(w.nodeEdges(C),function(k){var R=k.v===C,_=R?k.w:k.v;if(_!==E){var N=R===M,$=w.edge(k).weight;if(T+=N?$:-$,b(v,C,_)){var V=v.edge(C,_).cutvalue;T+=N?-V:V}}}),T}function u(v,w){arguments.length<2&&(w=v.nodes()[0]),h(v,{},1,w)}function h(v,w,C,S,E){var M=C,P=v.node(S);return w[S]=!0,e.forEach(v.neighbors(S),function(T){e.has(w,T)||(C=h(v,w,C,T,S))}),P.low=M,P.lim=C++,E?P.parent=E:delete P.parent,C}function p(v){return e.find(v.edges(),function(w){return v.edge(w).cutvalue<0})}function m(v,w,C){var S=C.v,E=C.w;w.hasEdge(S,E)||(S=C.w,E=C.v);var M=v.node(S),P=v.node(E),T=M,k=!1;M.lim>P.lim&&(T=P,k=!0);var R=e.filter(w.edges(),function(_){return k===x(v,v.node(_.v),T)&&k!==x(v,v.node(_.w),T)});return e.minBy(R,function(_){return t(w,_)})}function g(v,w,C,S){var E=C.v,M=C.w;v.removeEdge(E,M),v.setEdge(S.v,S.w,{}),u(v),c(v,w),y(v,w)}function y(v,w){var C=e.find(v.nodes(),function(E){return!w.node(E).parent}),S=o(v,C);S=S.slice(1),e.forEach(S,function(E){var M=v.node(E).parent,P=w.edge(E,M),T=!1;P||(P=w.edge(M,E),T=!0),w.node(E).rank=w.node(M).rank+(T?P.minlen:-P.minlen)})}function b(v,w,C){return v.hasEdge(w,C)}function x(v,w,C){return C.low<=w.lim&&w.lim<=C.lim}return Xl}var Yl,im;function Sj(){if(im)return Yl;im=1;var e=mo(),r=e.longestPath,t=rv(),n=Cj();Yl=o;function o(c){switch(c.graph().ranker){case"network-simplex":a(c);break;case"tight-tree":s(c);break;case"longest-path":i(c);break;default:a(c)}}var i=r;function s(c){r(c),t(c)}function a(c){n(c)}return Yl}var Ql,am;function jj(){if(am)return Ql;am=1;var e=gt();Ql=r;function r(o){var i=n(o);e.forEach(o.graph().dummyChains,function(s){for(var a=o.node(s),c=a.edgeObj,l=t(o,i,c.v,c.w),d=l.path,u=l.lca,h=0,p=d[h],m=!0;s!==c.w;){if(a=o.node(s),m){for(;(p=d[h])!==u&&o.node(p).maxRank<a.rank;)h++;p===u&&(m=!1)}if(!m){for(;h<d.length-1&&o.node(p=d[h+1]).minRank<=a.rank;)h++;p=d[h]}o.setParent(s,p),s=o.successors(s)[0]}})}function t(o,i,s,a){var c=[],l=[],d=Math.min(i[s].low,i[a].low),u=Math.max(i[s].lim,i[a].lim),h,p;h=s;do h=o.parent(h),c.push(h);while(h&&(i[h].low>d||u>i[h].lim));for(p=h,h=a;(h=o.parent(h))!==p;)l.push(h);return{path:c.concat(l.reverse()),lca:p}}function n(o){var i={},s=0;function a(c){var l=s;e.forEach(o.children(c),a),i[c]={low:l,lim:s++}}return e.forEach(o.children(),a),i}return Ql}var ed,sm;function Ej(){if(sm)return ed;sm=1;var e=gt(),r=Nt();ed={run:t,cleanup:s};function t(a){var c=r.addDummyNode(a,"root",{},"_root"),l=o(a),d=e.max(e.values(l))-1,u=2*d+1;a.graph().nestingRoot=c,e.forEach(a.edges(),function(p){a.edge(p).minlen*=u});var h=i(a)+1;e.forEach(a.children(),function(p){n(a,c,u,h,d,l,p)}),a.graph().nodeRankFactor=u}function n(a,c,l,d,u,h,p){var m=a.children(p);if(!m.length){p!==c&&a.setEdge(c,p,{weight:0,minlen:l});return}var g=r.addBorderNode(a,"_bt"),y=r.addBorderNode(a,"_bb"),b=a.node(p);a.setParent(g,p),b.borderTop=g,a.setParent(y,p),b.borderBottom=y,e.forEach(m,function(x){n(a,c,l,d,u,h,x);var v=a.node(x),w=v.borderTop?v.borderTop:x,C=v.borderBottom?v.borderBottom:x,S=v.borderTop?d:2*d,E=w!==C?1:u-h[p]+1;a.setEdge(g,w,{weight:S,minlen:E,nestingEdge:!0}),a.setEdge(C,y,{weight:S,minlen:E,nestingEdge:!0})}),a.parent(p)||a.setEdge(c,g,{weight:0,minlen:u+h[p]})}function o(a){var c={};function l(d,u){var h=a.children(d);h&&h.length&&e.forEach(h,function(p){l(p,u+1)}),c[d]=u}return e.forEach(a.children(),function(d){l(d,1)}),c}function i(a){return e.reduce(a.edges(),function(c,l){return c+a.edge(l).weight},0)}function s(a){var c=a.graph();a.removeNode(c.nestingRoot),delete c.nestingRoot,e.forEach(a.edges(),function(l){var d=a.edge(l);d.nestingEdge&&a.removeEdge(l)})}return ed}var td,cm;function _j(){if(cm)return td;cm=1;var e=gt(),r=Nt();td=t;function t(o){function i(s){var a=o.children(s),c=o.node(s);if(a.length&&e.forEach(a,i),e.has(c,"minRank")){c.borderLeft=[],c.borderRight=[];for(var l=c.minRank,d=c.maxRank+1;l<d;++l)n(o,"borderLeft","_bl",s,c,l),n(o,"borderRight","_br",s,c,l)}}e.forEach(o.children(),i)}function n(o,i,s,a,c,l){var d={width:0,height:0,rank:l,borderType:i},u=c[i][l-1],h=r.addDummyNode(o,"border",d,s);c[i][l]=h,o.setParent(h,a),u&&o.setEdge(u,h,{weight:1})}return td}var rd,lm;function kj(){if(lm)return rd;lm=1;var e=gt();rd={adjust:r,undo:t};function r(l){var d=l.graph().rankdir.toLowerCase();(d==="lr"||d==="rl")&&n(l)}function t(l){var d=l.graph().rankdir.toLowerCase();(d==="bt"||d==="rl")&&i(l),(d==="lr"||d==="rl")&&(a(l),n(l))}function n(l){e.forEach(l.nodes(),function(d){o(l.node(d))}),e.forEach(l.edges(),function(d){o(l.edge(d))})}function o(l){var d=l.width;l.width=l.height,l.height=d}function i(l){e.forEach(l.nodes(),function(d){s(l.node(d))}),e.forEach(l.edges(),function(d){var u=l.edge(d);e.forEach(u.points,s),e.has(u,"y")&&s(u)})}function s(l){l.y=-l.y}function a(l){e.forEach(l.nodes(),function(d){c(l.node(d))}),e.forEach(l.edges(),function(d){var u=l.edge(d);e.forEach(u.points,c),e.has(u,"x")&&c(u)})}function c(l){var d=l.x;l.x=l.y,l.y=d}return rd}var nd,dm;function Pj(){if(dm)return nd;dm=1;var e=gt();nd=r;function r(t){var n={},o=e.filter(t.nodes(),function(l){return!t.children(l).length}),i=e.max(e.map(o,function(l){return t.node(l).rank})),s=e.map(e.range(i+1),function(){return[]});function a(l){if(!e.has(n,l)){n[l]=!0;var d=t.node(l);s[d.rank].push(l),e.forEach(t.successors(l),a)}}var c=e.sortBy(o,function(l){return t.node(l).rank});return e.forEach(c,a),s}return nd}var od,um;function Aj(){if(um)return od;um=1;var e=gt();od=r;function r(n,o){for(var i=0,s=1;s<o.length;++s)i+=t(n,o[s-1],o[s]);return i}function t(n,o,i){for(var s=e.zipObject(i,e.map(i,function(h,p){return p})),a=e.flatten(e.map(o,function(h){return e.sortBy(e.map(n.outEdges(h),function(p){return{pos:s[p.w],weight:n.edge(p).weight}}),"pos")}),!0),c=1;c<i.length;)c<<=1;var l=2*c-1;c-=1;var d=e.map(new Array(l),function(){return 0}),u=0;return e.forEach(a.forEach(function(h){var p=h.pos+c;d[p]+=h.weight;for(var m=0;p>0;)p%2&&(m+=d[p+1]),p=p-1>>1,d[p]+=h.weight;u+=h.weight*m})),u}return od}var id,fm;function Rj(){if(fm)return id;fm=1;var e=gt();id=r;function r(t,n){return e.map(n,function(o){var i=t.inEdges(o);if(i.length){var s=e.reduce(i,function(a,c){var l=t.edge(c),d=t.node(c.v);return{sum:a.sum+l.weight*d.order,weight:a.weight+l.weight}},{sum:0,weight:0});return{v:o,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:o}})}return id}var ad,hm;function Mj(){if(hm)return ad;hm=1;var e=gt();ad=r;function r(o,i){var s={};e.forEach(o,function(c,l){var d=s[c.v]={indegree:0,in:[],out:[],vs:[c.v],i:l};e.isUndefined(c.barycenter)||(d.barycenter=c.barycenter,d.weight=c.weight)}),e.forEach(i.edges(),function(c){var l=s[c.v],d=s[c.w];!e.isUndefined(l)&&!e.isUndefined(d)&&(d.indegree++,l.out.push(s[c.w]))});var a=e.filter(s,function(c){return!c.indegree});return t(a)}function t(o){var i=[];function s(l){return function(d){d.merged||(e.isUndefined(d.barycenter)||e.isUndefined(l.barycenter)||d.barycenter>=l.barycenter)&&n(l,d)}}function a(l){return function(d){d.in.push(l),--d.indegree===0&&o.push(d)}}for(;o.length;){var c=o.pop();i.push(c),e.forEach(c.in.reverse(),s(c)),e.forEach(c.out,a(c))}return e.map(e.filter(i,function(l){return!l.merged}),function(l){return e.pick(l,["vs","i","barycenter","weight"])})}function n(o,i){var s=0,a=0;o.weight&&(s+=o.barycenter*o.weight,a+=o.weight),i.weight&&(s+=i.barycenter*i.weight,a+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=s/a,o.weight=a,o.i=Math.min(i.i,o.i),i.merged=!0}return ad}var sd,pm;function Tj(){if(pm)return sd;pm=1;var e=gt(),r=Nt();sd=t;function t(i,s){var a=r.partition(i,function(g){return e.has(g,"barycenter")}),c=a.lhs,l=e.sortBy(a.rhs,function(g){return-g.i}),d=[],u=0,h=0,p=0;c.sort(o(!!s)),p=n(d,l,p),e.forEach(c,function(g){p+=g.vs.length,d.push(g.vs),u+=g.barycenter*g.weight,h+=g.weight,p=n(d,l,p)});var m={vs:e.flatten(d,!0)};return h&&(m.barycenter=u/h,m.weight=h),m}function n(i,s,a){for(var c;s.length&&(c=e.last(s)).i<=a;)s.pop(),i.push(c.vs),a++;return a}function o(i){return function(s,a){return s.barycenter<a.barycenter?-1:s.barycenter>a.barycenter?1:i?a.i-s.i:s.i-a.i}}return sd}var cd,gm;function Ij(){if(gm)return cd;gm=1;var e=gt(),r=Rj(),t=Mj(),n=Tj();cd=o;function o(a,c,l,d){var u=a.children(c),h=a.node(c),p=h?h.borderLeft:void 0,m=h?h.borderRight:void 0,g={};p&&(u=e.filter(u,function(C){return C!==p&&C!==m}));var y=r(a,u);e.forEach(y,function(C){if(a.children(C.v).length){var S=o(a,C.v,l,d);g[C.v]=S,e.has(S,"barycenter")&&s(C,S)}});var b=t(y,l);i(b,g);var x=n(b,d);if(p&&(x.vs=e.flatten([p,x.vs,m],!0),a.predecessors(p).length)){var v=a.node(a.predecessors(p)[0]),w=a.node(a.predecessors(m)[0]);e.has(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+v.order+w.order)/(x.weight+2),x.weight+=2}return x}function i(a,c){e.forEach(a,function(l){l.vs=e.flatten(l.vs.map(function(d){return c[d]?c[d].vs:d}),!0)})}function s(a,c){e.isUndefined(a.barycenter)?(a.barycenter=c.barycenter,a.weight=c.weight):(a.barycenter=(a.barycenter*a.weight+c.barycenter*c.weight)/(a.weight+c.weight),a.weight+=c.weight)}return cd}var ld,ym;function Nj(){if(ym)return ld;ym=1;var e=gt(),r=Zt().Graph;ld=t;function t(o,i,s){var a=n(o),c=new r({compound:!0}).setGraph({root:a}).setDefaultNodeLabel(function(l){return o.node(l)});return e.forEach(o.nodes(),function(l){var d=o.node(l),u=o.parent(l);(d.rank===i||d.minRank<=i&&i<=d.maxRank)&&(c.setNode(l),c.setParent(l,u||a),e.forEach(o[s](l),function(h){var p=h.v===l?h.w:h.v,m=c.edge(p,l),g=e.isUndefined(m)?0:m.weight;c.setEdge(p,l,{weight:o.edge(h).weight+g})}),e.has(d,"minRank")&&c.setNode(l,{borderLeft:d.borderLeft[i],borderRight:d.borderRight[i]}))}),c}function n(o){for(var i;o.hasNode(i=e.uniqueId("_root")););return i}return ld}var dd,mm;function Oj(){if(mm)return dd;mm=1;var e=gt();dd=r;function r(t,n,o){var i={},s;e.forEach(o,function(a){for(var c=t.parent(a),l,d;c;){if(l=t.parent(c),l?(d=i[l],i[l]=c):(d=s,s=c),d&&d!==c){n.setEdge(d,c);return}c=l}})}return dd}var ud,bm;function $j(){if(bm)return ud;bm=1;var e=gt(),r=Pj(),t=Aj(),n=Ij(),o=Nj(),i=Oj(),s=Zt().Graph,a=Nt();ud=c;function c(h){var p=a.maxRank(h),m=l(h,e.range(1,p+1),"inEdges"),g=l(h,e.range(p-1,-1,-1),"outEdges"),y=r(h);u(h,y);for(var b=Number.POSITIVE_INFINITY,x,v=0,w=0;w<4;++v,++w){d(v%2?m:g,v%4>=2),y=a.buildLayerMatrix(h);var C=t(h,y);C<b&&(w=0,x=e.cloneDeep(y),b=C)}u(h,x)}function l(h,p,m){return e.map(p,function(g){return o(h,g,m)})}function d(h,p){var m=new s;e.forEach(h,function(g){var y=g.graph().root,b=n(g,y,m,p);e.forEach(b.vs,function(x,v){g.node(x).order=v}),i(g,m,b.vs)})}function u(h,p){e.forEach(p,function(m){e.forEach(m,function(g,y){h.node(g).order=y})})}return ud}var fd,xm;function qj(){if(xm)return fd;xm=1;var e=gt(),r=Zt().Graph,t=Nt();fd={positionX:m,findType1Conflicts:n,findType2Conflicts:o,addConflict:s,hasConflict:a,verticalAlignment:c,horizontalCompaction:l,alignCoordinates:h,findSmallestWidthAlignment:u,balance:p};function n(b,x){var v={};function w(C,S){var E=0,M=0,P=C.length,T=e.last(S);return e.forEach(S,function(k,R){var _=i(b,k),N=_?b.node(_).order:P;(_||k===T)&&(e.forEach(S.slice(M,R+1),function($){e.forEach(b.predecessors($),function(V){var I=b.node(V),F=I.order;(F<E||N<F)&&!(I.dummy&&b.node($).dummy)&&s(v,V,$)})}),M=R+1,E=N)}),S}return e.reduce(x,w),v}function o(b,x){var v={};function w(S,E,M,P,T){var k;e.forEach(e.range(E,M),function(R){k=S[R],b.node(k).dummy&&e.forEach(b.predecessors(k),function(_){var N=b.node(_);N.dummy&&(N.order<P||N.order>T)&&s(v,_,k)})})}function C(S,E){var M=-1,P,T=0;return e.forEach(E,function(k,R){if(b.node(k).dummy==="border"){var _=b.predecessors(k);_.length&&(P=b.node(_[0]).order,w(E,T,R,M,P),T=R,M=P)}w(E,T,E.length,P,S.length)}),E}return e.reduce(x,C),v}function i(b,x){if(b.node(x).dummy)return e.find(b.predecessors(x),function(v){return b.node(v).dummy})}function s(b,x,v){if(x>v){var w=x;x=v,v=w}var C=b[x];C||(b[x]=C={}),C[v]=!0}function a(b,x,v){if(x>v){var w=x;x=v,v=w}return e.has(b[x],v)}function c(b,x,v,w){var C={},S={},E={};return e.forEach(x,function(M){e.forEach(M,function(P,T){C[P]=P,S[P]=P,E[P]=T})}),e.forEach(x,function(M){var P=-1;e.forEach(M,function(T){var k=w(T);if(k.length){k=e.sortBy(k,function(V){return E[V]});for(var R=(k.length-1)/2,_=Math.floor(R),N=Math.ceil(R);_<=N;++_){var $=k[_];S[T]===T&&P<E[$]&&!a(v,T,$)&&(S[$]=T,S[T]=C[T]=C[$],P=E[$])}}})}),{root:C,align:S}}function l(b,x,v,w,C){var S={},E=d(b,x,v,C),M=C?"borderLeft":"borderRight";function P(R,_){for(var N=E.nodes(),$=N.pop(),V={};$;)V[$]?R($):(V[$]=!0,N.push($),N=N.concat(_($))),$=N.pop()}function T(R){S[R]=E.inEdges(R).reduce(function(_,N){return Math.max(_,S[N.v]+E.edge(N))},0)}function k(R){var _=E.outEdges(R).reduce(function($,V){return Math.min($,S[V.w]-E.edge(V))},Number.POSITIVE_INFINITY),N=b.node(R);_!==Number.POSITIVE_INFINITY&&N.borderType!==M&&(S[R]=Math.max(S[R],_))}return P(T,E.predecessors.bind(E)),P(k,E.successors.bind(E)),e.forEach(w,function(R){S[R]=S[v[R]]}),S}function d(b,x,v,w){var C=new r,S=b.graph(),E=g(S.nodesep,S.edgesep,w);return e.forEach(x,function(M){var P;e.forEach(M,function(T){var k=v[T];if(C.setNode(k),P){var R=v[P],_=C.edge(R,k);C.setEdge(R,k,Math.max(E(b,T,P),_||0))}P=T})}),C}function u(b,x){return e.minBy(e.values(x),function(v){var w=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY;return e.forIn(v,function(S,E){var M=y(b,E)/2;w=Math.max(S+M,w),C=Math.min(S-M,C)}),w-C})}function h(b,x){var v=e.values(x),w=e.min(v),C=e.max(v);e.forEach(["u","d"],function(S){e.forEach(["l","r"],function(E){var M=S+E,P=b[M],T;if(P!==x){var k=e.values(P);T=E==="l"?w-e.min(k):C-e.max(k),T&&(b[M]=e.mapValues(P,function(R){return R+T}))}})})}function p(b,x){return e.mapValues(b.ul,function(v,w){if(x)return b[x.toLowerCase()][w];var C=e.sortBy(e.map(b,w));return(C[1]+C[2])/2})}function m(b){var x=t.buildLayerMatrix(b),v=e.merge(n(b,x),o(b,x)),w={},C;e.forEach(["u","d"],function(E){C=E==="u"?x:e.values(x).reverse(),e.forEach(["l","r"],function(M){M==="r"&&(C=e.map(C,function(R){return e.values(R).reverse()}));var P=(E==="u"?b.predecessors:b.successors).bind(b),T=c(b,C,v,P),k=l(b,C,T.root,T.align,M==="r");M==="r"&&(k=e.mapValues(k,function(R){return-R})),w[E+M]=k})});var S=u(b,w);return h(w,S),p(w,b.graph().align)}function g(b,x,v){return function(w,C,S){var E=w.node(C),M=w.node(S),P=0,T;if(P+=E.width/2,e.has(E,"labelpos"))switch(E.labelpos.toLowerCase()){case"l":T=-E.width/2;break;case"r":T=E.width/2;break}if(T&&(P+=v?T:-T),T=0,P+=(E.dummy?x:b)/2,P+=(M.dummy?x:b)/2,P+=M.width/2,e.has(M,"labelpos"))switch(M.labelpos.toLowerCase()){case"l":T=M.width/2;break;case"r":T=-M.width/2;break}return T&&(P+=v?T:-T),T=0,P}}function y(b,x){return b.node(x).width}return fd}var hd,vm;function Lj(){if(vm)return hd;vm=1;var e=gt(),r=Nt(),t=qj().positionX;hd=n;function n(i){i=r.asNonCompoundGraph(i),o(i),e.forEach(t(i),function(s,a){i.node(a).x=s})}function o(i){var s=r.buildLayerMatrix(i),a=i.graph().ranksep,c=0;e.forEach(s,function(l){var d=e.max(e.map(l,function(u){return i.node(u).height}));e.forEach(l,function(u){i.node(u).y=c+d/2}),c+=d+a})}return hd}var pd,wm;function Fj(){if(wm)return pd;wm=1;var e=gt(),r=vj(),t=wj(),n=Sj(),o=Nt().normalizeRanks,i=jj(),s=Nt().removeEmptyRanks,a=Ej(),c=_j(),l=kj(),d=$j(),u=Lj(),h=Nt(),p=Zt().Graph;pd=m;function m(q,D){var K=D&&D.debugTiming?h.time:h.notime;K("layout",function(){var G=K(" buildLayoutGraph",function(){return P(q)});K(" runLayout",function(){g(G,K)}),K(" updateInputGraph",function(){y(q,G)})})}function g(q,D){D(" makeSpaceForEdgeLabels",function(){T(q)}),D(" removeSelfEdges",function(){oe(q)}),D(" acyclic",function(){r.run(q)}),D(" nestingGraph.run",function(){a.run(q)}),D(" rank",function(){n(h.asNonCompoundGraph(q))}),D(" injectEdgeLabelProxies",function(){k(q)}),D(" removeEmptyRanks",function(){s(q)}),D(" nestingGraph.cleanup",function(){a.cleanup(q)}),D(" normalizeRanks",function(){o(q)}),D(" assignRankMinMax",function(){R(q)}),D(" removeEdgeLabelProxies",function(){_(q)}),D(" normalize.run",function(){t.run(q)}),D(" parentDummyChains",function(){i(q)}),D(" addBorderSegments",function(){c(q)}),D(" order",function(){d(q)}),D(" insertSelfEdges",function(){se(q)}),D(" adjustCoordinateSystem",function(){l.adjust(q)}),D(" position",function(){u(q)}),D(" positionSelfEdges",function(){H(q)}),D(" removeBorderNodes",function(){F(q)}),D(" normalize.undo",function(){t.undo(q)}),D(" fixupEdgeLabelCoords",function(){V(q)}),D(" undoCoordinateSystem",function(){l.undo(q)}),D(" translateGraph",function(){N(q)}),D(" assignNodeIntersects",function(){$(q)}),D(" reversePoints",function(){I(q)}),D(" acyclic.undo",function(){r.undo(q)})}function y(q,D){e.forEach(q.nodes(),function(K){var G=q.node(K),ce=D.node(K);G&&(G.x=ce.x,G.y=ce.y,D.children(K).length&&(G.width=ce.width,G.height=ce.height))}),e.forEach(q.edges(),function(K){var G=q.edge(K),ce=D.edge(K);G.points=ce.points,e.has(ce,"x")&&(G.x=ce.x,G.y=ce.y)}),q.graph().width=D.graph().width,q.graph().height=D.graph().height}var b=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},v=["acyclicer","ranker","rankdir","align"],w=["width","height"],C={width:0,height:0},S=["minlen","weight","width","height","labeloffset"],E={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},M=["labelpos"];function P(q){var D=new p({multigraph:!0,compound:!0}),K=ue(q.graph());return D.setGraph(e.merge({},x,ee(K,b),e.pick(K,v))),e.forEach(q.nodes(),function(G){var ce=ue(q.node(G));D.setNode(G,e.defaults(ee(ce,w),C)),D.setParent(G,q.parent(G))}),e.forEach(q.edges(),function(G){var ce=ue(q.edge(G));D.setEdge(G,e.merge({},E,ee(ce,S),e.pick(ce,M)))}),D}function T(q){var D=q.graph();D.ranksep/=2,e.forEach(q.edges(),function(K){var G=q.edge(K);G.minlen*=2,G.labelpos.toLowerCase()!=="c"&&(D.rankdir==="TB"||D.rankdir==="BT"?G.width+=G.labeloffset:G.height+=G.labeloffset)})}function k(q){e.forEach(q.edges(),function(D){var K=q.edge(D);if(K.width&&K.height){var G=q.node(D.v),ce=q.node(D.w),re={rank:(ce.rank-G.rank)/2+G.rank,e:D};h.addDummyNode(q,"edge-proxy",re,"_ep")}})}function R(q){var D=0;e.forEach(q.nodes(),function(K){var G=q.node(K);G.borderTop&&(G.minRank=q.node(G.borderTop).rank,G.maxRank=q.node(G.borderBottom).rank,D=e.max(D,G.maxRank))}),q.graph().maxRank=D}function _(q){e.forEach(q.nodes(),function(D){var K=q.node(D);K.dummy==="edge-proxy"&&(q.edge(K.e).labelRank=K.rank,q.removeNode(D))})}function N(q){var D=Number.POSITIVE_INFINITY,K=0,G=Number.POSITIVE_INFINITY,ce=0,re=q.graph(),Z=re.marginx||0,ae=re.marginy||0;function ye(xe){var fe=xe.x,U=xe.y,te=xe.width,de=xe.height;D=Math.min(D,fe-te/2),K=Math.max(K,fe+te/2),G=Math.min(G,U-de/2),ce=Math.max(ce,U+de/2)}e.forEach(q.nodes(),function(xe){ye(q.node(xe))}),e.forEach(q.edges(),function(xe){var fe=q.edge(xe);e.has(fe,"x")&&ye(fe)}),D-=Z,G-=ae,e.forEach(q.nodes(),function(xe){var fe=q.node(xe);fe.x-=D,fe.y-=G}),e.forEach(q.edges(),function(xe){var fe=q.edge(xe);e.forEach(fe.points,function(U){U.x-=D,U.y-=G}),e.has(fe,"x")&&(fe.x-=D),e.has(fe,"y")&&(fe.y-=G)}),re.width=K-D+Z,re.height=ce-G+ae}function $(q){e.forEach(q.edges(),function(D){var K=q.edge(D),G=q.node(D.v),ce=q.node(D.w),re,Z;K.points?(re=K.points[0],Z=K.points[K.points.length-1]):(K.points=[],re=ce,Z=G),K.points.unshift(h.intersectRect(G,re)),K.points.push(h.intersectRect(ce,Z))})}function V(q){e.forEach(q.edges(),function(D){var K=q.edge(D);if(e.has(K,"x"))switch((K.labelpos==="l"||K.labelpos==="r")&&(K.width-=K.labeloffset),K.labelpos){case"l":K.x-=K.width/2+K.labeloffset;break;case"r":K.x+=K.width/2+K.labeloffset;break}})}function I(q){e.forEach(q.edges(),function(D){var K=q.edge(D);K.reversed&&K.points.reverse()})}function F(q){e.forEach(q.nodes(),function(D){if(q.children(D).length){var K=q.node(D),G=q.node(K.borderTop),ce=q.node(K.borderBottom),re=q.node(e.last(K.borderLeft)),Z=q.node(e.last(K.borderRight));K.width=Math.abs(Z.x-re.x),K.height=Math.abs(ce.y-G.y),K.x=re.x+K.width/2,K.y=G.y+K.height/2}}),e.forEach(q.nodes(),function(D){q.node(D).dummy==="border"&&q.removeNode(D)})}function oe(q){e.forEach(q.edges(),function(D){if(D.v===D.w){var K=q.node(D.v);K.selfEdges||(K.selfEdges=[]),K.selfEdges.push({e:D,label:q.edge(D)}),q.removeEdge(D)}})}function se(q){var D=h.buildLayerMatrix(q);e.forEach(D,function(K){var G=0;e.forEach(K,function(ce,re){var Z=q.node(ce);Z.order=re+G,e.forEach(Z.selfEdges,function(ae){h.addDummyNode(q,"selfedge",{width:ae.label.width,height:ae.label.height,rank:Z.rank,order:re+ ++G,e:ae.e,label:ae.label},"_se")}),delete Z.selfEdges})})}function H(q){e.forEach(q.nodes(),function(D){var K=q.node(D);if(K.dummy==="selfedge"){var G=q.node(K.e.v),ce=G.x+G.width/2,re=G.y,Z=K.x-ce,ae=G.height/2;q.setEdge(K.e,K.label),q.removeNode(D),K.label.points=[{x:ce+2*Z/3,y:re-ae},{x:ce+5*Z/6,y:re-ae},{x:ce+Z,y:re},{x:ce+5*Z/6,y:re+ae},{x:ce+2*Z/3,y:re+ae}],K.label.x=K.x,K.label.y=K.y}})}function ee(q,D){return e.mapValues(e.pick(q,D),Number)}function ue(q){var D={};return e.forEach(q,function(K,G){D[G.toLowerCase()]=K}),D}return pd}var gd,Cm;function zj(){if(Cm)return gd;Cm=1;var e=gt(),r=Nt(),t=Zt().Graph;gd={debugOrdering:n};function n(o){var i=r.buildLayerMatrix(o),s=new t({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(a){s.setNode(a,{label:a}),s.setParent(a,"layer"+o.node(a).rank)}),e.forEach(o.edges(),function(a){s.setEdge(a.v,a.w,{},a.name)}),e.forEach(i,function(a,c){var l="layer"+c;s.setNode(l,{rank:"same"}),e.reduce(a,function(d,u){return s.setEdge(d,u,{style:"invis"}),u})}),s}return gd}var yd,Sm;function Bj(){return Sm||(Sm=1,yd="0.8.5"),yd}var md,jm;function Dj(){return jm||(jm=1,md={graphlib:Zt(),layout:Fj(),debug:zj(),util:{time:Nt().time,notime:Nt().notime},version:Bj()}),md}var Wj=Dj();const Em=k1(Wj);function Vj(e,r,t){var h,p;const n=new Set(e.map(m=>m.id)),o=new Map(e.map(m=>[m.id,m])),i=new Set;for(const m of e)m.parent&&n.has(m.parent)&&i.add(m.parent);const s=new Map;for(const m of e){if(!m.hasBody||!i.has(m.id))continue;let g=`${m.id}.$body`;for(;n.has(g);)g+="$";s.set(m.id,g),n.add(g)}const a=new Em.graphlib.Graph({multigraph:!0,compound:!0}),c=t.compactSpacingScale??(t.spacingFactor>0?t.spacingFactor/1.3:1);a.setGraph({rankdir:t.rankDir,nodesep:t.compact?Math.max(t.nodeSep,24*c):t.nodeSep,edgesep:t.compact?Math.min(t.edgeSep,24*c):t.edgeSep,ranksep:t.compact?Math.min(t.rankSep,80*c):t.rankSep,ranker:"network-simplex"}),a.setDefaultEdgeLabel(()=>({})),a.setDefaultNodeLabel(()=>({}));for(const m of e)a.setNode(m.id,{width:m.width+2,height:m.height+2});for(const m of e)m.parent&&n.has(m.parent)&&a.setParent(m.id,m.parent);for(const[m,g]of s){const y=o.get(m);a.setNode(g,{width:y.width+2,height:y.height+2}),a.setParent(g,m)}for(const m of e){if(i.has(m.id)&&!s.has(m.id))continue;let g=m.parent;const y=new Set;for(;g&&!s.has(g)&&!y.has(g);)y.add(g),g=(h=o.get(g))==null?void 0:h.parent;const b=g&&s.get(g);b&&a.setEdge(b,s.get(m.id)??m.id,{minlen:1,weight:1},"parent-body")}for(const m of r){if(!n.has(m.source)||!n.has(m.target))continue;const g=s.get(m.source)??m.source,y=s.get(m.target)??m.target;if(i.has(g)||i.has(y))continue;const b=tx(m.label,m.icon??((p=m.data)==null?void 0:p.icon),t.edgeLabelFontSize),x=t.rankDir==="LR"||t.rankDir==="RL",v=(b.width?b.width+2*ex:0)+(m.connectorClearance??0);a.setEdge(g,y,{minlen:1,weight:1,...v?{width:x?v:Math.max(1,b.height),height:x?Math.max(1,b.height):v,labelpos:"c"}:{}},m.id)}Em.layout(a);const l=new Map;for(const m of e){if(i.has(m.id)&&!s.has(m.id))continue;const g=a.node(s.get(m.id)??m.id);g&&Number.isFinite(g.x)&&Number.isFinite(g.y)&&l.set(m.id,{x:g.x,y:g.y})}const d=t.compact?1:t.spacingFactor;if(d&&d!==1&&l.size){let m=1/0,g=1/0,y=-1/0,b=-1/0;l.forEach(w=>{m=Math.min(m,w.x),g=Math.min(g,w.y),y=Math.max(y,w.x),b=Math.max(b,w.y)});const x=(m+y)/2,v=(g+b)/2;l.forEach((w,C)=>l.set(C,{x:x+(w.x-x)*d,y:v+(w.y-v)*d}))}const u=t.nodeAlignment??"center";if(u!=="center"){const m=t.rankDir==="LR"||t.rankDir==="RL",g=m?"x":"y",y=m?"width":"height",b=t.rankDir==="RL"||t.rankDir==="BT"?-1:1,x=u==="leading"?-b:b,v=new Map;for(const w of e){const C=l.get(w.id);if(!C)continue;const S=C[g];v.set(S,Math.max(v.get(S)??0,w[y]))}for(const w of e){const C=l.get(w.id);if(!C)continue;const S=C[g],E=(v.get(S)-w[y])/2;l.set(w.id,{...C,[g]:S+x*E})}}return l}function Ad(e,r,t,n,o,i){const s=new Map,a=new Map(e.map(u=>[u.id,u]));for(const u of e){if(!u.parent||!a.has(u.parent))continue;const h=s.get(u.parent);h?h.push(u.id):s.set(u.parent,[u.id])}const c=(u,h=new Set)=>{var m;const p=(m=a.get(u))==null?void 0:m.parent;return!p||!a.has(p)||h.has(u)?0:(h.add(u),1+c(p,h))},l=[...s.keys()].sort((u,h)=>c(h)-c(u)),d=new Map;for(const u of l){const h=i==null?void 0:i.get(u),p=r.get(u);if(h&&p){d.set(u,{x1:p.x-h.w/2,y1:p.y-h.h/2,x2:p.x+h.w/2,y2:p.y+h.h/2});continue}const m=t.get(u);let g=p&&m?{x1:p.x-m.w/2,y1:p.y-m.h/2,x2:p.x+m.w/2,y2:p.y+m.h/2}:null;for(const x of s.get(u)||[]){let v=d.get(x);if(!v){const w=r.get(x);if(!w)continue;const C=t.get(x)||{w:60,h:60};v={x1:w.x-C.w/2,y1:w.y-C.h/2,x2:w.x+C.w/2,y2:w.y+C.h/2}}g=g?{x1:Math.min(g.x1,v.x1),y1:Math.min(g.y1,v.y1),x2:Math.max(g.x2,v.x2),y2:Math.max(g.y2,v.y2)}:{...v}}if(!g)continue;const y=n(u);g={x1:g.x1-y,y1:g.y1-y,x2:g.x2+y,y2:g.y2+y};const b=o(u);if(b){const x=g.x2-g.x1,v=g.y2-g.y1;if(b.w>x){const w=(b.w-x)/2;g.x1-=w,g.x2+=w}if(b.h>v){const w=(b.h-v)/2;g.y1-=w,g.y2+=w}}d.set(u,g)}return d}function _m(e,r,t){var c,l,d;const n=[...r.weights],o=n.reduce((u,h)=>u+h,0),i=n[r.index]+n[r.index+1],s=Math.min(i*.95,Math.max(i*.05,n[r.index]+t/r.length*o));n[r.index]=s,n[r.index+1]=i-s;const a={...(l=(c=e.adjustment)==null?void 0:c.sections)==null?void 0:l[r.section]};if(r.axis==="y")a.rows=n;else{for(a.columns=[...a.columns??[]];a.columns.length<=r.row;)a.columns.push([]);a.columns[r.row]=n}return{...e,adjustment:{...e.adjustment,sections:{...(d=e.adjustment)==null?void 0:d.sections,[r.section]:a}}}}function nv(e){if(e===void 0)return;if(!e||typeof e!="object"||Array.isArray(e)||e.enabled!==void 0&&typeof e.enabled!="boolean")throw new RangeError("Invalid grid adjustment.");const r=t=>Array.isArray(t)&&t.length<=1e4&&t.every(n=>typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1e6);if(e.sections!==void 0&&(!e.sections||typeof e.sections!="object"||Array.isArray(e.sections)))throw new RangeError("Invalid grid sections.");for(const[t,n]of Object.entries(e.sections??{}))if(["__proto__","constructor","prototype"].includes(t)||!n||typeof n!="object"||Array.isArray(n)||n.rows!==void 0&&!r(n.rows)||n.columns!==void 0&&(!Array.isArray(n.columns)||n.columns.length>1e4||!n.columns.every(r))||n.members!==void 0&&(!Array.isArray(n.members)||n.members.length>1e4||!n.members.every(o=>Array.isArray(o)&&o.length>0&&o.length<=1e4&&o.every(i=>typeof i=="string"&&i.length>0))||new Set(n.members.flat()).size!==n.members.flat().length))throw new RangeError("Invalid grid section proportions.")}function pu(e){const r=e.margin??15;if(!Number.isFinite(r)||r<0)throw new RangeError("Collision margin must be finite and non-negative.");return r}function Yn(e){const r=new Map(e.nodes.map(a=>[a.id,a])),t=new Map;for(const a of e.nodes){const c=a.parent&&r.has(a.parent)?a.parent:void 0,l=t.get(c)??[];l.push(a.id),t.set(c,l)}const n=[],o=new Map,i=a=>{const c=t.get(a),l=c?c.flatMap(i):e.positions.has(a)?[a]:[];return o.set(a,l),c&&n.push(c),l},s=t.get(void 0)??[];return s.forEach(i),n.push(s),{groups:n,leaves:o,children:t,roots:s}}function kr(e,r,t=e.fixedSizes){const n=Ad(e.nodes,r,e.sizes,e.padding,e.minSize,t);for(const o of e.nodes){if(n.has(o.id))continue;const i=r.get(o.id),s=e.sizes.get(o.id);i&&s&&n.set(o.id,ir({...i,...s}))}return n}function ov(e,r,t,n){const o=t.get(e),i=t.get(r);if(!o||!i)return;const s={x:Math.min(o.x2-i.x1,i.x2-o.x1)+n,y:Math.min(o.y2-i.y1,i.y2-o.y1)+n};if(s.x>.001&&s.y>.001)return{source:e,target:r,overlap:s}}function Vn(e,r,t){const n=[];for(const o of e)for(let i=0;i<o.length;i++)for(let s=i+1;s<o.length;s++){const a=ov(o[i],o[s],r,t);a&&n.push(a)}return n}function iv(e,r={}){const t=pu(r),{groups:n}=Yn(e);return Vn(n,kr(e,e.positions),t)}function av(e,r,t,n){var a,c,l;const o=new Set(e),i=(((l=(c=(a=r.adjustment)==null?void 0:a.sections)==null?void 0:c[t])==null?void 0:l.members)??[]).map(d=>d.filter(u=>o.delete(u))).filter(d=>d.length),s=e.filter(d=>o.has(d));for(let d=0;d<s.length;d+=n)i.push(s.slice(d,d+n));return i}function Gj(e,r,t,n,o){var x,v,w,C;if(t===n)return;const{groups:i,leaves:s}=Yn(e),a=i.find(S=>S.includes(t)&&S.includes(n));if(!a||a.some(S=>e.fixedIds.has(S)||(s.get(S)??[]).some(E=>e.fixedIds.has(E))))return;const c=kr(e,e.positions);if(a.some(S=>!c.has(S)))return;const l=((x=e.nodes.find(S=>S.id===t))==null?void 0:x.parent)??"canvas",d=(w=(v=r.adjustment)==null?void 0:v.sections)==null?void 0:w[l],u=[],h=[...a].sort((S,E)=>{const M=c.get(S),P=c.get(E),T=(M.y1+M.y2-P.y1-P.y2)/2;return Math.abs(T)>1?T:M.x1-P.x1});for(const S of h){const E=u.at(-1),M=c.get(S),P=E&&c.get(E[0]);P&&Math.abs(M.y1+M.y2-P.y1-P.y2)<2?E.push(S):u.push([S])}const p=u.map((S,E)=>{var M;return{weight:((M=d==null?void 0:d.rows)==null?void 0:M[E])??1,cells:S.map((P,T)=>{var k,R;return{id:P,weight:((R=(k=d==null?void 0:d.columns)==null?void 0:k[E])==null?void 0:R[T])??1}})}});for(const S of p)S.cells=S.cells.filter(E=>E.id!==t);const m=p.filter(S=>S.cells.length),g=m.findIndex(S=>S.cells.some(E=>E.id===n)),y=m[g];if(!y)return;o==="above"||o==="below"?m.splice(g+(o==="below"?1:0),0,{weight:1,cells:[{id:t,weight:1}]}):y.cells.splice(y.cells.findIndex(S=>S.id===n)+(o==="after"?1:0),0,{id:t,weight:1});const b=m.map(S=>S.cells.map(E=>E.id));if(JSON.stringify(b)!==JSON.stringify(u))return{...r,adjustment:{...r.adjustment,sections:{...(C=r.adjustment)==null?void 0:C.sections,[l]:{...d,members:b,rows:m.map(S=>S.weight),columns:m.map(S=>S.cells.map(E=>E.weight))}}}}}function bd(e,r={}){var d;nv(r.adjustment);const t=pu(r),n=typeof r.gaps=="object"?r.gaps:{x:r.gaps??t,y:r.gaps??t};if(!n||[n.x,n.y].some(u=>!Number.isFinite(u)||u<0))throw new RangeError("Grid gaps must be finite and non-negative.");const o=r.padding??0;if(!Number.isFinite(o)||o<0)throw new RangeError("Grid padding must be finite and non-negative.");if(r.columns!==void 0&&(!Number.isSafeInteger(r.columns)||r.columns<1))throw new RangeError("Grid columns must be a positive safe integer.");if(r.fill&&e.viewportSize)return Hj(e,r,n,o);const{groups:i,leaves:s}=Yn(e),a=new Map([...e.positions].map(([u,h])=>[u,{...h}])),c=new Set;for(const u of i){const h=kr(e,a),p=u.filter(k=>h.has(k));if(p.length<2)continue;if(p.some(k=>e.fixedIds.has(k)||(s.get(k)??[]).some(R=>e.fixedIds.has(R)))){p.forEach(k=>c.add(k));continue}const g=p.map(k=>h.get(k)),y=Math.max(...g.map(k=>k.x2-k.x1)),b=Math.max(...g.map(k=>k.y2-k.y1)),x=Math.min(p.length,r.columns??Math.ceil(Math.sqrt(p.length))),v=((d=e.nodes.find(k=>k.id===p[0]))==null?void 0:d.parent)??"canvas",w=av(p,r,v,x),C=Math.max(...w.map(k=>k.length)),S=y+n.x,E=b+n.y,M=g.map(k=>({x:(k.x1+k.x2)/2,y:(k.y1+k.y2)/2})),P=(Math.min(...M.map(k=>k.x))+Math.max(...M.map(k=>k.x)))/2,T=(Math.min(...M.map(k=>k.y))+Math.max(...M.map(k=>k.y)))/2;w.forEach((k,R)=>k.forEach((_,N)=>{const $=h.get(_),V={x:P+(N-(C-1)/2)*S-($.x1+$.x2)/2,y:T+(R-(w.length-1)/2)*E-($.y1+$.y2)/2};for(const I of s.get(_)??[]){const F=a.get(I);a.set(I,{x:F.x+V.x,y:F.y+V.y})}}))}const l=[...a].filter(([u,h])=>{const p=e.positions.get(u);return h.x!==p.x||h.y!==p.y}).map(([u])=>u);return{positions:a,movedNodeIds:l,skippedNodeIds:[...c],collisions:Vn(i,kr(e,a),Math.min(n.x,n.y))}}function Hj(e,r,t,n){const{groups:o,children:i,roots:s}=Yn(e),a=new Map([...e.positions].map(([y,b])=>[y,{...b}]));if(e.nodes.some(y=>e.fixedIds.has(y.id)))return{positions:a,movedNodeIds:[],skippedNodeIds:e.nodes.map(y=>y.id),collisions:iv(e,{margin:Math.min(t.x,t.y)})};const c=e.viewportSize,l=Math.min(n,Math.max(0,(c.w-1)/2)),d=Math.min(n,Math.max(0,(c.h-1)/2)),u={x1:l,y1:d,x2:Math.max(l+1,c.w-l),y2:Math.max(d+1,c.h-d)},h=new Map,p=[],m=(y,b,x="canvas")=>{var N,$;if(!y.length)return;const v=b.x2-b.x1,w=b.y2-b.y1,C=Math.min(y.length,r.columns??Math.max(1,Math.round(Math.sqrt(y.length*v/w)))),S=av(y,r,x,C),E=S.length,M=Math.min(t.y,w/(2*E)),P=($=(N=r.adjustment)==null?void 0:N.sections)==null?void 0:$[x],T=Array.from({length:E},(V,I)=>{var F;return((F=P==null?void 0:P.rows)==null?void 0:F[I])??1}),k=T.reduce((V,I)=>V+I,0),R=w-(E-1)*M;let _=b.y1;for(let V=0;V<E;V++){const I=R*T[V]/k,F=S[V].length,oe=Math.min(t.x,v/(2*F)),se=Array.from({length:F},(q,D)=>{var K,G;return((G=(K=P==null?void 0:P.columns)==null?void 0:K[V])==null?void 0:G[D])??1}),H=se.reduce((q,D)=>q+D,0),ee=v-(F-1)*oe;let ue=b.x1;for(let q=0;q<F;q++){const D=S[V][q],K=ee*se[q]/H,G=i.get(D);if(G){a.set(D,{x:ue+K/2,y:_+I/2}),h.set(D,{w:K,h:I});const ce=Math.min(e.padding(D),Math.max(0,(Math.min(K,I)-1)/2));m(G,{x1:ue+ce,y1:_+ce,x2:ue+K-ce,y2:_+I-ce},D)}else a.has(D)&&(a.set(D,{x:ue+K/2,y:_+I/2}),h.set(D,{w:K,h:I}));q<F-1&&p.push({section:x,axis:"x",row:V,index:q,weights:se,length:ee,position:{x:ue+K+oe/2,y:_+I/2}}),ue+=K+oe}V<E-1&&p.push({section:x,axis:"y",row:V,index:V,weights:T,length:R,position:{x:b.x1+v/2,y:_+I+M/2}}),_+=I+M}};m(s,u);const g=[...a].filter(([y,b])=>{const x=e.positions.get(y);return!x||b.x!==x.x||b.y!==x.y}).map(([y])=>y);return{positions:a,movedNodeIds:g,skippedNodeIds:[],bounds:u,sizes:h,dividers:p,collisions:Vn(o,kr({...e,sizes:h},a,h),0)}}function Uj(e,r={}){const t=pu(r),n=r.maxIterations??50;if(!Number.isInteger(n)||n<0||n>1e3)throw new RangeError("Collision maxIterations must be an integer between 0 and 1000.");const{groups:o,leaves:i}=Yn(e),s=new Map([...e.positions].map(([u,h])=>[u,{...h}])),a=u=>e.fixedIds.has(u)||(i.get(u)??[]).some(h=>e.fixedIds.has(h));let c=Vn(o,kr(e,s),t),l=0;for(;c.length&&l<n;){let u=!1;for(const h of o){if(h.length<2)continue;const p=kr(e,s),m=(g,y,b)=>{for(const v of i.get(g)??[])s.get(v)[y]+=b;const x=p.get(g);y==="x"?(x.x1+=b,x.x2+=b):(x.y1+=b,x.y2+=b)};for(let g=0;g<h.length;g++)for(let y=g+1;y<h.length;y++){const b=h[g],x=h[y],v=ov(b,x,p,t);if(!v)continue;const w=a(b),C=a(x);if(w&&C)continue;const S=v.overlap.x<=v.overlap.y?"x":"y",E=p.get(b),M=p.get(x),P=S==="x"?E.x1+E.x2<=M.x1+M.x2?-1:1:E.y1+E.y2<=M.y1+M.y2?-1:1,T=v.overlap[S];w||m(b,S,P*T/(C?1:2)),C||m(x,S,-P*T/(w?1:2)),u=!0}}if(l++,c=Vn(o,kr(e,s),t),!u)break}const d=[...s].filter(([u,h])=>{const p=e.positions.get(u);return h.x!==p.x||h.y!==p.y}).map(([u])=>u);return{positions:s,movedNodeIds:d,collisions:c,iterations:l,resolved:c.length===0}}function Kj({dividers:e,options:r,zoom:t,onChange:n}){const o=j.useRef();return f.jsx(f.Fragment,{children:e.map(i=>{const s=i.axis==="x",a=s?Q.PiArrowsHorizontal:Q.PiArrowsVertical,c=`${s?"Column":"Row"} divider ${i.index+1}${s?` in row ${i.row+1}`:""}`;return f.jsx("button",{type:"button",role:"separator","aria-label":c,"aria-orientation":s?"vertical":"horizontal","aria-valuemin":5,"aria-valuemax":95,"aria-valuenow":Math.round(100*i.weights[i.index]/(i.weights[i.index]+i.weights[i.index+1])),title:c,"data-flow-grid-adjustment":"",style:{position:"absolute",left:i.position.x,top:i.position.y,transform:"translate(-50%, -50%)",width:28,height:28,padding:3,border:"1px solid currentColor",borderRadius:4,background:"var(--chakra-colors-gray-100)",color:"var(--chakra-colors-gray-800)",display:"grid",placeItems:"center",cursor:s?"col-resize":"row-resize",touchAction:"none",pointerEvents:"auto",zIndex:30},onPointerDown:l=>{if(l.button!==0)return;l.preventDefault(),l.stopPropagation();const d=l.currentTarget.closest(".flow-sdk-canvas"),u=d.getBoundingClientRect();o.current={pointerId:l.pointerId,start:s?l.clientX:l.clientY,scale:t*(s?u.width/d.clientWidth:u.height/d.clientHeight),divider:i,options:r},l.currentTarget.setPointerCapture(l.pointerId)},onPointerMove:l=>{const d=o.current;if(!d||d.pointerId!==l.pointerId)return;l.preventDefault(),l.stopPropagation();const u=((s?l.clientX:l.clientY)-d.start)/d.scale;n(_m(d.options,d.divider,u))},onPointerUp:l=>{o.current&&(l.stopPropagation(),o.current=void 0,l.currentTarget.releasePointerCapture(l.pointerId))},onPointerCancel:()=>{o.current&&n(o.current.options),o.current=void 0},onLostPointerCapture:()=>{o.current=void 0},onClick:l=>l.stopPropagation(),onKeyDown:l=>{l.key==="Escape"&&o.current&&(n(o.current.options),o.current=void 0);const d=(s?["ArrowLeft","ArrowRight"]:["ArrowUp","ArrowDown"]).indexOf(l.key);d<0||(l.preventDefault(),l.stopPropagation(),n(_m(r,i,i.length*(l.shiftKey?.1:.02)*(d===0?-1:1))))},children:f.jsx(a,{size:20,"aria-hidden":"true"})},`${i.section}:${i.axis}:${i.row}:${i.index}`)})})}const km=(e,r)=>e.left<r.right&&e.right>r.left&&e.top<r.bottom&&e.bottom>r.top,xd=new WeakMap;function Pm(e,r){const t=[...r.querySelectorAll(".flow-sdk-edge-label")];if(!t.length){xd.delete(r);return}const n=r==null?void 0:r.getScreenCTM();if(!r||!n)return;const o=n.inverse(),i=(u,h=0)=>{const p=u.getBoundingClientRect(),m=new DOMPoint(p.left,p.top).matrixTransform(o),g=new DOMPoint(p.right,p.bottom).matrixTransform(o);return{left:m.x-h,right:g.x+h,top:m.y-h,bottom:g.y+h}},s=[...e.querySelectorAll(".flow-sdk-node, .flow-sdk-node button")].filter(u=>u.closest(".flow-sdk-canvas")===e).filter(u=>{const h=u.getBoundingClientRect(),p=getComputedStyle(u);return h.width>0&&h.height>0&&p.visibility!=="hidden"&&p.opacity!=="0"}).map(u=>i(u,24));for(const u of r.querySelectorAll(".flow-sdk-container-label"))s.push(i(u,12));const a=new Map([...e.querySelectorAll(".flow-sdk-edge")].filter(u=>u.closest(".flow-sdk-canvas")===e).map(u=>[u.dataset.edgeId,u.querySelector("path")])),c=JSON.stringify([s,[...a].map(([u,h])=>[u,h==null?void 0:h.getAttribute("d")]),t.map(u=>{var m;const h=u.getBBox(),p=(m=u.querySelector("rect"))==null?void 0:m.getBBox();return[u.dataset.edgeId,u.dataset.labelTransform,u.dataset.labelHorizontal,h.x,h.y,h.width,h.height,p==null?void 0:p.width,p==null?void 0:p.height]})],(u,h)=>typeof h=="number"?Math.round(h*1e3)/1e3:h),l=xd.get(r);if((l==null?void 0:l.geometry)===c&&t.every(u=>l.transforms.has(u))){for(const u of t){const h=l.transforms.get(u);u.getAttribute("transform")!==h&&u.setAttribute("transform",h)}return}for(const u of t)u.setAttribute("transform",u.dataset.labelTransform??"");const d=new Map(t.map(u=>[u,i(u,8)]));for(const u of t){const h=u.dataset.labelHorizontal==="true",p=d.get(u);d.delete(u);const m=P=>s.some(T=>km(P,T))||[...d.values()].some(T=>km(P,T));if(!h&&!m(p)){d.set(u,p);continue}const g=a.get(u.dataset.edgeId),y=u.querySelector("rect");if(!g||!y)continue;const b=y.getBBox(),x=g.getTotalLength();if(!Number.isFinite(x)||x<=0)continue;const v=(p.left+p.right)/2,w=(p.top+p.bottom)/2,C=Math.min(256,Math.max(16,Math.ceil(x/24))),S=Array.from({length:C+1},(P,T)=>g.getPointAtLength(x*T/C)),M=Array.from({length:C+1},(P,T)=>{const k=x*T/C,R=S[T],_=h?{x:R.x,y:R.y-b.height/2-15}:R,N=g.getPointAtLength(Math.max(0,k-2)),$=g.getPointAtLength(Math.min(x,k+2));let V=Math.atan2($.y-N.y,$.x-N.x)*180/Math.PI;V>90&&(V-=180),V<-90&&(V+=180);const I=Math.abs(V)<1;h&&(V=0);const F=V*Math.PI/180,oe=Math.abs(Math.cos(F))*b.width+Math.abs(Math.sin(F))*b.height,se=Math.abs(Math.sin(F))*b.width+Math.abs(Math.cos(F))*b.height;return{point:_,angle:V,straight:I,score:Math.hypot(_.x-v,_.y-w),bounds:{left:_.x-oe/2-8,right:_.x+oe/2+8,top:_.y-se/2-8,bottom:_.y+se/2+8}}}).sort((P,T)=>P.score-T.score).find(P=>!m(P.bounds)&&(!h||P.straight&&!S.some(T=>T.x>P.bounds.left&&T.x<P.bounds.right&&T.y>P.bounds.top&&T.y<P.bounds.bottom)));M?(u.setAttribute("transform",`translate(${M.point.x} ${M.point.y}) rotate(${M.angle})`),d.set(u,M.bounds)):d.set(u,p)}xd.set(r,{geometry:c,transforms:new Map(t.map(u=>[u,u.getAttribute("transform")??""]))})}function Jj(e){const r=e.getBoundingClientRect(),t=r.height/e.offsetHeight;if(!Number.isFinite(t)||t<=0)return[];const n=Yb(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],s=new Set(i.filter(a=>a.hasAttribute("data-flow-inspection-row")&&a.getBoundingClientRect().height>0).map(a=>a.dataset.flowProperty));return i.flatMap(a=>{if(a.closest(".flow-sdk-node")!==e)return[];if(s.has(a.dataset.flowProperty)&&!a.hasAttribute("data-flow-inspection-row"))return[];const c=a.dataset.flowPortSide;if(c&&["top","right","bottom","left"].includes(c)){const d=Jb(n?qn(o,n):o,c,Number(a.dataset.flowPortPosition??.5));return[{property:a.getAttribute("data-flow-property"),top:d.y,height:0,anchor:d,...a.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]}const l=a.getBoundingClientRect();return!l.width||!l.height?[]:[{property:a.getAttribute("data-flow-property"),top:Math.round((l.top-r.top)/t*1e3)/1e3,height:Math.round(l.height/t*1e3)/1e3,...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]})}function Zj({id:e,x:r,y:t,placed:n,hidden:o,gridDraggable:i,gridDragging:s,gridDropTarget:a,gridSize:c,gridPreview:l,onMount:d,drawHandles:u,drawMode:h,connectedPorts:p,resolvedRows:m,hasCollapseControl:g,handleColor:y,animated:b,animationColor:x,animationWidth:v=8,animationVariant:w,width:C=0,height:S=0,propertyMode:E,reversePorts:M,direction:P="LR",onPropertyRows:T,onSurface:k,children:R}){var G,ce;const _=j.useRef(null),[N,$]=j.useState([]),V=m??N,[I,F]=j.useState(),oe=j.useId(),se=j.useRef(),H=!!l,ee=!!(l!=null&&l.floating);j.useLayoutEffect(()=>{var xe;const re=_.current;if(!re||!H)return;const Z=re.cloneNode(!0);Z.removeAttribute("data-node-id"),Z.removeAttribute("data-grid-dragging"),Z.removeAttribute("data-grid-draggable"),Z.removeAttribute("data-grid-drop-target"),Z.setAttribute("data-grid-preview",e),Z.setAttribute("aria-hidden","true"),Z.setAttribute("inert","");const ae=[Z,...Z.querySelectorAll("*")],ye=new Map(ae.filter(fe=>fe.id).map(fe=>[fe.id,`${fe.id}-${oe}`]));for(const fe of ae){fe.id&&(fe.id=ye.get(fe.id));for(const U of[...fe.attributes]){if(U.name==="id")continue;let te=U.value;for(const[de,Pe]of ye)te===`#${de}`&&(te=`#${Pe}`),te=te.split(`url(#${de})`).join(`url(#${Pe})`);te!==U.value&&fe.setAttribute(U.name,te)}}if(Object.assign(Z.style,{opacity:"0.35",zIndex:ee?"2147483647":"11",pointerEvents:"none",outline:"none",visibility:"visible"}),ee){const fe=getComputedStyle(re);Z.setAttribute("data-grid-preview-floating",""),Object.assign(Z.style,{position:"fixed",left:"0",top:"0",transformOrigin:"top left",font:fe.font,color:fe.color});for(const U of ae)U.removeAttribute("data-node-id"),U.style.pointerEvents="none"}return Z.querySelectorAll(".flow-sdk-node-animation, .flow-sdk-handle, .flow-sdk-property-port, [data-flow-collapse-control]").forEach(fe=>fe.remove()),(xe=ee?document.body:re.parentElement)==null||xe.appendChild(Z),se.current=Z,()=>{Z.remove(),se.current=void 0}},[e,oe,H,ee]),j.useLayoutEffect(()=>{const re=se.current;if(!re||!l)return;const{x:Z,y:ae,size:ye}=l;if(ee&&_.current){const U=_.current,te=U.getBoundingClientRect(),de=te.width/U.offsetWidth||1,Pe=te.height/U.offsetHeight||1,ie=te.left+(Z-r)*de,we=te.top+(ae-t)*Pe;re.style.transform=`translate3d(${ie}px, ${we}px, 0) scale(${de}, ${Pe})`,re.style.width=`${U.offsetWidth}px`,re.style.height=`${U.offsetHeight}px`;return}const xe=ye?Math.round(Z-ye.w/2):Z,fe=ye?Math.round(ae-ye.h/2):ae;re.style.transform=ye?`translate3d(${xe}px, ${fe}px, 0)`:`translate(-50%, -50%) translate3d(${xe}px, ${fe}px, 0)`,re.style.width=ye?`${Math.round(Z+ye.w/2)-xe}px`:"",re.style.height=ye?`${Math.round(ae+ye.h/2)-fe}px`:"",ye&&(re.style.setProperty("--flow-grid-width",`${ye.w}px`),re.style.setProperty("--flow-grid-height",`${ye.h}px`),re.style.setProperty("--flow-grid-font",`${Math.max(12,Math.min(48,ye.w/8,ye.h/5))}px`))},[l==null?void 0:l.x,l==null?void 0:l.y,(G=l==null?void 0:l.size)==null?void 0:G.w,(ce=l==null?void 0:l.size)==null?void 0:ce.h,ee,r,t]),j.useLayoutEffect(()=>{const re=_.current;if(!re)return;const Z=()=>{const xe=Yb(re);F(fe=>JSON.stringify(fe)===JSON.stringify(xe)?fe:xe),k==null||k(e,xe)};Z();const ae=new ResizeObserver(Z);ae.observe(re);const ye=re.querySelector("[data-flow-node-surface]");return ye&&ae.observe(ye),()=>ae.disconnect()},[e,R,k]),j.useLayoutEffect(()=>(d(e,_.current),()=>{d(e,null),k==null||k(e,void 0)}),[e,d,k]),j.useLayoutEffect(()=>{const re=_.current;if(!re)return;let Z="";const ae=()=>{const U=Jj(re),te=E?U:U.filter(Pe=>Pe.anchor),de=JSON.stringify(te);de!==Z&&(Z=de,$(te),T==null||T(e,te))};if(ae(),!E&&!re.querySelector("[data-flow-port-side]"))return;const ye=new ResizeObserver(ae),xe=()=>{ye.disconnect(),ye.observe(re),re.querySelectorAll("[data-flow-property]").forEach(U=>ye.observe(U)),ae()};xe();const fe=new MutationObserver(xe);return fe.observe(re,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["data-flow-property","data-flow-port-role","data-flow-port-side","data-flow-port-position","data-flow-port-placement"]}),re.addEventListener("scroll",ae,!0),()=>{ye.disconnect(),fe.disconnect(),re.removeEventListener("scroll",ae,!0)}},[e,E,T,R]);const ue=c?Math.round(r-c.w/2):0,q=c?Math.round(t-c.h/2):0,D=c?Math.round(r+c.w/2)-ue:void 0,K=c?Math.round(t+c.h/2)-q:void 0;return f.jsxs("div",{ref:_,className:"flow-sdk-node","data-node-id":e,"data-grid-draggable":i||void 0,"data-grid-dragging":s||void 0,"data-grid-drop-target":a||void 0,"data-grid-fill":c?"":void 0,style:{transform:c?`translate3d(${ue}px, ${q}px, 0)`:`translate(-50%, -50%) translate3d(${r.toFixed(2)}px, ${t.toFixed(2)}px, 0)`,visibility:n&&!o?void 0:"hidden",cursor:i?s?"grabbing":"grab":void 0,zIndex:s?12:void 0,opacity:l?0:s?.75:void 0,outline:a?`2px solid ${y||"currentColor"}`:void 0,outlineOffset:a?8:void 0,width:D,height:K,...c?{"--flow-grid-width":`${c.w}px`,"--flow-grid-height":`${c.h}px`,"--flow-grid-font":`${Math.max(12,Math.min(48,c.w/8,c.h/5))}px`}:{}},children:[R,!c&&b&&v>0&&C>0&&S>0&&f.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:f.jsx(go,{variant:w,x:((I==null?void 0:I.left)??0)+v/2,y:((I==null?void 0:I.top)??0)+v/2,width:((I==null?void 0:I.width)??C)-v,height:((I==null?void 0:I.height)??S)-v,radius:((I==null?void 0:I.radius)??0)-v/2,path:I!=null&&I.outline?`M${I.outline.map(re=>`${re.x} ${re.y}`).join(" L")} Z`:void 0,color:x||y||"currentColor",strokeWidth:v})}),u&&E&&V.map(re=>["source","target"].filter(Z=>!re.role||re.role===Z).filter(Z=>h||(p==null?void 0:p.has(`${Z}:${re.property}`))).map(Z=>{var ae;return f.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":re.property,"data-port-role":Z,"data-port-side":(ae=re.anchor)==null?void 0:ae.side,"aria-label":`${Z==="source"?"Connect":"Input"} ${re.property}`,title:`${Z==="source"?"Connect":"Input"} ${re.property}`,style:{color:y,...re.anchor?{top:re.anchor.y,left:re.anchor.x-16}:{top:re.top+re.height/2,[Z==="source"!=!!M?"right":"left"]:-16}},onClick:ye=>ye.stopPropagation()},`${re.property}:${Z}`)})),u&&!g&&(!E||!V.length)&&(!E||!V.some(re=>re.anchor))&&f.jsx("button",{type:"button",className:"flow-sdk-handle","aria-label":"Draw edge",title:"Draw edge",style:{color:y,left:((I==null?void 0:I.left)??0)+(P==="RL"?-36:P==="LR"?(I==null?void 0:I.width)??C:((I==null?void 0:I.width)??C)/2),top:((I==null?void 0:I.top)??0)+(P==="BT"?-36:P==="TB"?(I==null?void 0:I.height)??S:((I==null?void 0:I.height)??S)/2),transform:P==="BT"||P==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:re=>re.stopPropagation(),children:f.jsx(Q.PiPlusBold,{size:24})})]})}const Xj=j.memo(Zj);function Yj(e,r,t){const[n,o]=j.useState(()=>({nodes:new Set,edges:new Set})),i=j.useMemo(()=>{const a=new Set(e.map(p=>p.id)),c=r.filter(p=>a.has(p.source)&&a.has(p.target)).map(p=>({id:p.id,source:p.inverted?p.target:p.source,target:p.inverted?p.source:p.target})),l=new Set(c.map(p=>p.id)),d=new Set([...n.nodes].filter(p=>a.has(p))),u=new Set([...n.edges].filter(p=>l.has(p)));if(!t)return{nodes:a,edges:l,ready:l};for(const p of e)c.filter(g=>g.target===p.id&&g.source!==g.target).every(g=>u.has(g.id))&&d.add(p.id);let h=new Set(c.filter(p=>d.has(p.source)).map(p=>p.id));if(d.size<a.size&&!c.some(p=>h.has(p.id)&&!u.has(p.id))){const p=e.find(m=>!d.has(m.id));p&&d.add(p.id),h=new Set(c.filter(m=>d.has(m.source)).map(m=>m.id))}return{nodes:d,edges:u,ready:h}},[e,r,t,n]);j.useLayoutEffect(()=>{o(a=>{const c=t?i:{nodes:new Set,edges:new Set},l=(d,u)=>d.size===u.size&&[...d].every(h=>u.has(h));return l(a.nodes,c.nodes)&&l(a.edges,c.edges)?a:{nodes:c.nodes,edges:c.edges}})},[i,t]);const s=j.useCallback(a=>{o(c=>c.edges.has(a)?c:{...c,edges:new Set([...c.edges,a])})},[]);return{shown:i.nodes,ready:i.ready,complete:s}}class Qj{constructor(r,t,n){zt(this,"_pan");zt(this,"_zoom");zt(this,"minZoom");zt(this,"maxZoom");zt(this,"size",{w:0,h:0});zt(this,"listeners",new Set);zt(this,"cancelTransition");zt(this,"animationVersion",0);zt(this,"captureTransition");zt(this,"animationsDisabled",!1);zt(this,"finishTransition");this.minZoom=t,this.maxZoom=n,this._pan={...r.pan},this._zoom=this.clamp(r.zoom)}setAnimationsDisabled(r){var t;r!==this.animationsDisabled&&(this.animationsDisabled=r,r&&((t=this.finishTransition)==null||t.call(this),this.cancelAnimation()))}cancelAnimation(){var r;(r=this.cancelTransition)==null||r.call(this),this.cancelTransition=void 0,this.finishTransition=void 0,this.animationVersion++}coordinate(r){let t;this.captureTransition=n=>{t=n};try{r()}finally{this.captureTransition=void 0}return t}transition(r,t=!1){this.cancelAnimation();const n=this.state,o={pan:{...r.pan},zoom:this.clamp(r.zoom)},i=this.animationVersion,s=Ub(t,this.animationsDisabled),a=c=>{if(i!==this.animationVersion)return;const l=s?c:1;this.apply({x:n.pan.x+(o.pan.x-n.pan.x)*l,y:n.pan.y+(o.pan.y-n.pan.y)*l},n.zoom+(o.zoom-n.zoom)*l)};this.finishTransition=()=>a(1),this.captureTransition?this.captureTransition(a):this.cancelTransition=Kb(s,a,void 0,300/1.4)}get pan(){return{...this._pan}}get zoom(){return this._zoom}get state(){return{pan:this.pan,zoom:this._zoom}}clamp(r){return Number.isFinite(r)?Math.max(this.minZoom,Math.min(this.maxZoom,r)):this.minZoom}set(r,t){this.cancelAnimation(),this.apply(r,t)}apply(r,t){let n=!1;if(r&&(r.x!==this._pan.x||r.y!==this._pan.y)&&(this._pan={x:r.x,y:r.y},n=!0),t!==void 0){const o=this.clamp(t);o!==this._zoom&&(this._zoom=o,n=!0)}n&&this.emit()}zoomAt(r,t){const n=this.clamp(r),o=this._zoom;if(n===o)return;const i=n/o;this.set({x:t.x-(t.x-this._pan.x)*i,y:t.y-(t.y-this._pan.y)*i},n)}fit(r,t=0,n=!1,o=1){const i=r.x2-r.x1,s=r.y2-r.y1;if(!(i>0)||!(s>0)||!this.size.w||!this.size.h)return;const a=this.clamp(this.clamp(Math.min((this.size.w-2*t)/i,(this.size.h-2*t)/s))*o);this.transition({pan:{x:(this.size.w-a*(r.x1+r.x2))/2,y:(this.size.h-a*(r.y1+r.y2))/2},zoom:a},n)}center(r,t=!1){if(!this.size.w||!this.size.h)return;const n=this._zoom;this.transition({pan:{x:(this.size.w-n*(r.x1+r.x2))/2,y:(this.size.h-n*(r.y1+r.y2))/2},zoom:n},t)}renderedToModel(r){return{x:(r.x-this._pan.x)/this._zoom,y:(r.y-this._pan.y)/this._zoom}}modelToRendered(r){return{x:r.x*this._zoom+this._pan.x,y:r.y*this._zoom+this._pan.y}}onChange(r){return this.listeners.add(r),()=>{this.listeners.delete(r)}}emit(){const r=this.state;this.listeners.forEach(t=>t(r))}}const eE={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},ao={w:60,h:60},vd=4,tE=30,rE=500,nE=45;function Am(e){const[r,t]=[...e.values()];return!r||!t?null:{center:{x:(r.x+t.x)/2,y:(r.y+t.y)/2},distance:Math.max(1,Math.hypot(t.x-r.x,t.y-r.y))}}function oE(e){var Cu,Su,ju,Eu,_u;const{nodes:r,edges:t,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:s=!1,rankSep:a,edgeSep:c,spacingFactor:l=1.3,compactSpacingScale:d,minZoom:u,maxZoom:h,initialViewport:p,containerStyle:m,lineColor:g,drawMode:y,dragMode:b,multiSelect:x,isPerformanceMode:v,disableAnimations:w=!1}=e,[C,S]=j.useState(null),E=j.useMemo(()=>C?(C.mode==="connections"?tf:Ju)(C.id,r,t):null,[C,r,t]),M=i==="auto"||i==="properties",P=j.useMemo(()=>t.filter(A=>Pd(A,i)&&(!E||E.has(A.source)&&E.has(A.target))),[t,i,E]),T=j.useMemo(()=>C1(r,t,i,s,E),[r,t,i,s,E]),k=j.useRef(T);k.current=T;const R=j.useRef(e);R.current=e;const _=j.useRef(null),N=j.useRef(null),$=j.useRef(null),V=j.useRef(null),I=j.useMemo(()=>new Qj(p,u,h),[]);j.useEffect(()=>{I.minZoom=u,I.maxZoom=h},[I,u,h]),j.useLayoutEffect(()=>{I.setAnimationsDisabled(w)},[I,w]);const F=j.useRef(new Map),oe=j.useRef(new Map),se=j.useRef(new Map),H=j.useRef(null),[ee,ue]=j.useState(new Map),q=j.useCallback((A,L)=>{ue(B=>{if(JSON.stringify(B.get(A))===JSON.stringify(L))return B;const J=new Map(B);return L?J.set(A,L):J.delete(A),J})},[]),[D,K]=j.useState(new Map),G=j.useRef(D),ce=j.useCallback((A,L)=>{K(B=>{if(JSON.stringify(B.get(A)??[])===JSON.stringify(L))return B;const J=new Map(B);return L.length?J.set(A,L):J.delete(A),J})},[]),[re,Z]=j.useState(()=>new Map),ae=j.useRef(re);ae.current=re;const[ye,xe]=j.useState(new Map),fe=j.useRef(ye),U=()=>{fe.current=new Map,xe(fe.current)},te=j.useRef(new Map(Object.entries(e.fixedNodePositions??{}))),de=j.useRef(new Set(Object.keys(e.fixedNodePositions??{}))),Pe=j.useRef(null),ie=j.useRef(!1),[we,$e]=j.useState(0),He=j.useRef(),Ve=j.useRef(),tt=j.useRef(null),me=j.useRef(),Ie=j.useRef(!1),De=j.useRef(null),be=j.useRef(null),Xe=j.useRef(),ut=j.useRef(l),Ae=s,Ke=j.useRef(Ae),[lt,Je]=j.useState(!0),[yt,At]=j.useState(!!((Cu=e.initialNodeGrid)!=null&&Cu.enabled)),[Jr,Tr]=j.useState([]),rt=j.useRef((Su=e.initialNodeGrid)!=null&&Su.enabled?{options:{...e.initialNodeGrid.options,animate:!1},order:[...e.initialNodeGrid.order??e.initialNodeGrid.options.order??r.map(A=>A.id)],previousPositions:new Map,previousViewport:p,previousSize:{w:0,h:0},ready:!1}:null),[We,Qt]=j.useState(null),ft=j.useRef(null);ft.current=E;const qt=j.useRef(1);qt.current=(C==null?void 0:C.mode)==="connections"?1.25:1;const dr=j.useRef(null),Be=j.useRef(r),Ht=j.useRef([]),Lt=j.useRef(!1),ur=()=>{var A;(A=tt.current)==null||A.call(tt),tt.current=null,me.current=void 0},z=()=>{be.current=null,Ht.current.length&&!te.current.size&&(Lt.current=!0),!ie.current&&R.current.fitOnInit!==!1&&(Ie.current=!0),clearTimeout(Ve.current),Ve.current=setTimeout(()=>{ie.current=ae.current.size>0,$e(A=>A+1)},rE)},O=(A,L,B,J=z,he)=>{ur();const Ee=new Map(ae.current),Ce=new Map([...F.current,...fe.current]);tt.current=Kb(L,Se=>{const Qe=new Map;if(A.forEach((qe,ze)=>{const ke=Ee.get(ze);Qe.set(ze,te.current.get(ze)??(ke?{x:ke.x+(qe.x-ke.x)*Se,y:ke.y+(qe.y-ke.y)*Se}:qe))}),ae.current=Qe,Z(Qe),he){const qe=new Map;for(const[ze,ke]of he){const X=Ce.get(ze)??ke;qe.set(ze,{w:X.w+(ke.w-X.w)*Se,h:X.h+(ke.h-X.h)*Se})}fe.current=qe,xe(qe)}B==null||B(Se)},J)},ne=()=>{var ze;if(clearTimeout(He.current),rt.current){pt.arrangeNodesInGrid(rt.current.options);return}fe.current.size&&U();const A=R.current,L=qt.current,B=k.current,J=new Set(A.nodes.filter(ke=>ke.label===void 0).map(ke=>ke.id)),he=B.nodes.map(ke=>{const X=oe.current.get(ke.id);X&&(X.offsetWidth||X.offsetHeight)&&F.current.set(ke.id,{w:X.offsetWidth,h:X.offsetHeight});const Y=F.current.get(ke.id)||ao;return{id:ke.id,parent:ke.parent,width:Y.w,height:Y.h,hasBody:J.has(ke.id)}});let Ee;try{const ke=A.compactPropertyLayout,X=A.edgeMode!=="nodes"&&A.edgeMode!=="workflow",Y=B.edges.map(pe=>({...pe,connectorClearance:ke?X&&(pe.sourceProperty!==void 0||pe.targetProperty!==void 0)?w1:v1:0}));Ee=Vj(he,Y,{edgeLabelFontSize:A.edgeMode==="nodes"||A.edgeMode==="workflow"?Qb:yo,rankDir:A.direction,compact:ke,nodeAlignment:A.nodeAlignment,rankSep:A.rankSep*L,edgeSep:A.edgeSep*L,nodeSep:5*L,spacingFactor:A.spacingFactor??1.3,compactSpacingScale:(A.compactSpacingScale??(A.spacingFactor??1.3)/1.3)*L})}catch(ke){console.warn("[flow-sdk] layout failed",ke);return}const Ce=[...te.current].find(([ke])=>Ee.has(ke)),Se=Ce?{id:Ce[0],position:Ce[1]}:be.current?null:Pe.current;Pe.current=null;const Qe=Se&&Ee.get(Se.id);if(Se&&Qe){const ke={x:Se.position.x-Qe.x,y:Se.position.y-Qe.y};Ee=new Map([...Ee].map(([X,Y])=>[X,{x:Y.x+ke.x,y:Y.y+ke.y}]))}for(const[ke,X]of te.current)A.nodes.some(Y=>Y.id===ke)?Ee.set(ke,X):te.current.delete(ke);if(be.current){const ke=JSON.stringify([he,[...Ee],I.size,A.isPerformanceMode,A.disableAnimations]);if(((ze=Xe.current)==null?void 0:ze.focus)===be.current&&Xe.current.geometry===ke)return;Xe.current={focus:be.current,geometry:ke}}else Xe.current=void 0;const qe=I.coordinate(()=>{var ke;return(ke=be.current)==null?void 0:ke.call(be,Ee)});O(Ee,ie.current&&!A.isPerformanceMode&&!A.disableAnimations,qe)},ge=j.useCallback(()=>{clearTimeout(Ve.current),clearTimeout(He.current),He.current=setTimeout(ne,R.current.layoutDebounce)},[]);j.useLayoutEffect(()=>{const A=e.fixedNodePositions??{};let L=!1;for(const B of de.current)Object.prototype.hasOwnProperty.call(A,B)||(L=te.current.delete(B)||L);for(const[B,J]of Object.entries(A)){if(!r.some(Ee=>Ee.id===B)||!J||![J.x,J.y].every(Number.isFinite))continue;const he=te.current.get(B);((he==null?void 0:he.x)!==J.x||(he==null?void 0:he.y)!==J.y)&&(te.current.set(B,{...J}),L=!0)}de.current=new Set(Object.keys(A)),L&&ge()},[e.fixedNodePositions,r,ge]),j.useLayoutEffect(()=>{const A=new Map(Be.current.map(L=>[L.id,L]));r.some(L=>{var B;return((B=A.get(L.id))==null?void 0:B.collapsed)===!0&&!L.collapsed})&&(Ht.current=r.filter(L=>!A.has(L.id)).map(L=>L.id)),Be.current=r,ut.current!==l&&ae.current.size>0&&(ie.current=!0,Ie.current=!1,clearTimeout(Ve.current)),ut.current=l,Ke.current!==Ae&&(Ie.current=!De.current),Ke.current=Ae,ge()},[r,t,T.nodes,T.edges,Ae,n,o,a,c,ge,l,d,w,e.nodeGridSpacing]),j.useEffect(()=>()=>{clearTimeout(He.current),clearTimeout(Ve.current),ur()},[]);const je=j.useCallback((A,L)=>{var B,J;if(!H.current&&typeof ResizeObserver<"u"&&(H.current=new ResizeObserver(he=>{let Ee=!1;for(const Ce of he){const Se=se.current.get(Ce.target);if(!Se||fe.current.has(Se))continue;const Qe=Ce.target,qe=Qe.offsetWidth,ze=Qe.offsetHeight;if(!qe&&!ze)continue;const ke=F.current.get(Se);if(ke&&ke.w===qe&&ke.h===ze)continue;const X=ae.current.get(Se);ke&&X&&ie.current&&!Pe.current&&(Pe.current={id:Se,position:{...X}}),F.current.set(Se,{w:qe,h:ze}),Ee=!0}Ee&&ge()})),L){oe.current.set(A,L),se.current.set(L,A),(B=H.current)==null||B.observe(L);const he=L.offsetWidth,Ee=L.offsetHeight;!fe.current.has(A)&&(he||Ee)&&F.current.set(A,{w:he,h:Ee})}else{const he=oe.current.get(A);he&&((J=H.current)==null||J.unobserve(he),se.current.delete(he)),oe.current.delete(A),F.current.delete(A),G.current.has(A)&&ce(A,[])}ge()},[ge,ce]);j.useEffect(()=>()=>{var A;return(A=H.current)==null?void 0:A.disconnect()},[]);const Te=A=>{var J;const L=(J=R.current.nodes.find(he=>he.id===A))==null?void 0:J.label;if(!L)return;const B=R.current.containerStyle(A);return{w:Ao(L,`bold ${B.fontSize}px ${_r}`)+2*nE,h:0}},Re=j.useMemo(()=>{const A=new Map;for(const L of r)L.label&&A.set(L.id,L.label);return A},[r]),Ye=j.useMemo(()=>Ad(T.nodes,re,new Map([...F.current,...ye]),A=>m(A).padding,Te,ye),[T.nodes,re,m,Re,ye]),et=j.useRef(Ye);et.current=Ye;const Fe=j.useCallback(A=>{const L=et.current.get(A);if(L)return a1(L);const B=ae.current.get(A);if(!B)return;const J=fe.current.get(A)||F.current.get(A)||ao;return{x:B.x,y:B.y,w:J.w,h:J.h}},[]),ct=j.useMemo(()=>{const A=new Map;for(const L of r){const B=Fe(L.id);B&&A.set(L.id,B)}return g1(D,A,ee,t,n)},[D,r,re,Ye,ee,t,n,Fe]);G.current=ct;const ht=(A,L)=>{var he;if(!M||L===void 0)return;const B=(he=ct.get(A))==null?void 0:he.find(Ee=>Ee.property===L),J=Fe(A);return B&&!B.anchor&&J?J.y-J.h/2+B.top+B.height/2:void 0},wt=(A,L)=>{var he,Ee;if(L===void 0)return;const B=(Ee=(he=ct.get(A))==null?void 0:he.find(Ce=>Ce.property===L))==null?void 0:Ee.anchor,J=Fe(A);return B&&J?{x:J.x-J.w/2+B.x,y:J.y-J.h/2+B.y,side:B.side}:void 0},St=(A,L)=>{const B=Fe(A),J=ee.get(A);return B&&J&&!Ye.has(A)&&ht(A,L)===void 0?qn(B,(n==="TB"||n==="BT")&&J.captionBottom!==void 0?{...J,height:Math.max(J.height,J.captionBottom-J.top),outline:void 0}:J):B},Rt=()=>{const A=[];ae.current.forEach((L,B)=>{if(et.current.has(B))return;const J=Fe(B);J&&A.push(ir(J))}),et.current.forEach(L=>A.push(L));try{for(const L of[N.current,$.current]){const B=L==null?void 0:L.getBBox();B&&B.width>0&&B.height>0&&A.push({x1:B.x,y1:B.y,x2:B.x+B.width,y2:B.y+B.height})}}catch{}return ei(A)},Mt=()=>{var B,J;const{pan:A,zoom:L}=I;V.current&&(V.current.style.transform=`translate3d(${A.x}px, ${A.y}px, 0) scale(${L})`),(B=N.current)==null||B.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`),(J=$.current)==null||J.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`)};j.useEffect(()=>{Mt();let A=null,L;const B=I.onChange(()=>{Mt();const J=_.current;J&&(J.classList.add("flow-sdk-busy"),clearTimeout(L),L=setTimeout(()=>J.classList.remove("flow-sdk-busy"),150)),A===null&&(A=requestAnimationFrame(()=>{var he,Ee;A=null,(Ee=(he=R.current).onViewportChange)==null||Ee.call(he,I.state)}))});return()=>{B(),clearTimeout(L),A!==null&&cancelAnimationFrame(A)}},[]),j.useLayoutEffect(()=>{const A=_.current;if(!A)return;const L=()=>{var Ce;if(!A.getClientRects().length)return;let J=A.clientWidth,he=A.clientHeight;he||(he=Math.max(0,window.innerHeight-A.getBoundingClientRect().top-100),he&&(A.style.height=`${he}px`)),J||(J=window.innerWidth,J&&(A.style.width=`${J}px`));const Ee=I.size.w!==J||I.size.h!==he;I.size={w:J,h:he},Ee&&((Ce=rt.current)!=null&&Ce.options.fill)&&(!ie.current&&J>0&&he>0?ne():ge()),!ie.current&&!ae.current.size&&R.current.fitOnInit!==!1&&(I.set({x:J/2,y:he/2}),Mt())};if(L(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(L);return B.observe(A),()=>B.disconnect()},[I]),j.useLayoutEffect(()=>{if(Lt.current){Lt.current=!1;const L=Ht.current.flatMap(J=>{const he=Fe(J);return he?[ir(he)]:[]});Ht.current=[];const B=ei(L);if(B){Ie.current=!1,I.center(B,R.current.animateViewport);return}}if(!Ie.current)return;Ie.current=!1;const A=Rt();A&&(I.fit(A,50,ie.current&&R.current.animateViewport),ie.current||Mt())},[re]);const pt=j.useMemo(()=>{const A=X=>{const Y=R.current;if(Y.nodeGridSpacing!=="layout")return X;const pe=Y.direction==="LR"||Y.direction==="RL";return{...X,gaps:{x:pe?Y.rankSep:Y.edgeSep,y:pe?Y.edgeSep:Y.rankSep}}},L=()=>{const X=R.current,Y=k.current.nodes.filter(pe=>ar(pe.id,X.edges,X.edgeMode)&&(!ft.current||ft.current.has(pe.id)));return{nodes:Y,positions:ae.current,sizes:new Map(Y.map(pe=>[pe.id,F.current.get(pe.id)??ao])),padding:pe=>R.current.containerStyle(pe).padding,minSize:Te,fixedIds:new Set(te.current.keys()),viewportSize:{...I.size}}},B=X=>Ju(X,R.current.nodes,R.current.edges),J=(X,Y=!0,pe=()=>{},le,Le,ve=!1)=>{clearTimeout(He.current),clearTimeout(Ve.current),ve||(be.current=null),De.current=null,Ie.current=!1,Ht.current=[],Lt.current=!1;const _e=Y&&!R.current.isPerformanceMode&&!R.current.disableAnimations,Ze=I.coordinate(()=>{var nt;le?le(_e):ve&&((nt=be.current)==null||nt.call(be,X))});O(new Map([...X].map(([nt,st])=>[nt,{...st}])),_e,Ze,pe,Le)},he=(X,Y=50,pe=R.current.animateViewport,le=1,Le=!1,ve)=>{const _e=Ze=>{const nt=k.current,st=X??new Set(nt.nodes.map(bt=>bt.id)),rr=new Set(nt.nodes.map(bt=>bt.parent).filter(Boolean));if(!Ze&&(!X||[...X].some(bt=>rr.has(bt))))return;const hr=Ze&&Ad(nt.nodes,Ze,F.current,bt=>R.current.containerStyle(bt).padding,Te),vn=new Map([...st].flatMap(bt=>{const or=hr==null?void 0:hr.get(bt);if(or)return[[bt,or]];const Ut=Ze==null?void 0:Ze.get(bt),vr=F.current.get(bt)||ao,ku=Ut?{...Ut,...vr}:Fe(bt);return ku?[[bt,ir(ku)]]:[]}));let nr=ei([...vn.values()]);if(!nr)return;const xr=ve?vn.get(ve):void 0;if(xr){const bt=(xr.x1+xr.x2)/2,or=(xr.y1+xr.y2)/2,Ut=Math.max(bt-nr.x1,nr.x2-bt),vr=Math.max(or-nr.y1,nr.y2-or);nr={x1:bt-Ut,x2:bt+Ut,y1:or-vr,y2:or+vr}}Ie.current=!1,Ht.current=[],Lt.current=!1,I.fit(nr,Number.isFinite(Y)?Math.max(0,Y):50,pe,le)};be.current=Le?_e:null,Le||_e(ae.current)},Ee=(X,Y,pe,le)=>{var ve;if(!Fe(X))return;const Le=Y==="connections"?Se(X):B(X);if(Y==="connections"&&qt.current===1.25&&((ve=ft.current)==null?void 0:ve.size)===Le.size&&[...Le].every(_e=>ft.current.has(_e))){S({id:X,mode:Y});return}dr.current||(dr.current={pan:{...I.pan},zoom:I.zoom}),ft.current=Le,R.current.compactPropertyLayout&&(Ie.current=!1,De.current=()=>he(ft.current??Le,pe,le)),S({id:X,mode:Y}),R.current.compactPropertyLayout||he(Le,pe,le)},Ce=X=>{De.current?De.current=X:X()},Se=X=>tf(X,R.current.nodes,R.current.edges),Qe=(X=>{var Y,pe,le;if(X===void 0)return I.zoom;X<I.zoom&&((Y=rt.current)!=null&&Y.options.fill)&&!R.current.readOnly&&((le=(pe=R.current).onNodeGridZoomOut)==null?void 0:le.call(pe,rt.current.options))===!0||(be.current=null,I.set(void 0,X))}),qe=((X,Y=!1)=>{if(X===void 0)return I.pan;be.current=null,Y?I.transition({pan:X,zoom:I.zoom},!0):I.set(X)}),ze=(X,Y)=>{var le;const pe=(le=_.current)==null?void 0:le.getBoundingClientRect();return{x:X-((pe==null?void 0:pe.left)??0),y:Y-((pe==null?void 0:pe.top)??0)}},ke=(X=0,Y=R.current.animateViewport,pe=!1)=>{if(pe){he(void 0,X,Y,1,!0);return}be.current=null,Ce(()=>{const le=Rt();le&&I.fit(le,X,Y)})};return{zoom:Qe,pan:qe,setEdgesVisible:Je,focusNode:(X,Y,pe,le)=>Ce(()=>he(new Set([X]),Y,pe,.6,le)),focusBranch:(X,Y,pe,le,Le=!1,ve=1)=>Ce(()=>he(B(X),Y,pe,ve,le,Le?X:void 0)),focusConnections:(X,Y,pe,le)=>Ce(()=>he(Se(X),Y,pe,1,le)),isolateConnections:(X,Y,pe)=>Ee(X,"connections",Y,pe),isolateBranch:(X,Y,pe)=>Ee(X,"branch",Y,pe),restoreView:(X=R.current.animateViewport,Y,pe=!1)=>{be.current=null;const le=pe&&!rt.current&&!ft.current,Le=R.current.compactPropertyLayout&&!!ft.current;ft.current=null,S(null);const ve=Y??dr.current;dr.current=null,ve&&le?(Ie.current=!1,De.current=null,Pe.current=null,be.current=()=>I.transition(ve,X),ge()):Le?De.current=()=>{ve&&I.transition(ve,X)}:ve&&Ce(()=>I.transition(ve,X))},zoomAt:(X,Y)=>{var pe,le,Le;X<I.zoom&&((pe=rt.current)!=null&&pe.options.fill)&&!R.current.readOnly&&((Le=(le=R.current).onNodeGridZoomOut)==null?void 0:Le.call(le,rt.current.options))===!0||(be.current=null,I.zoomAt(X,Y))},fit:ke,centerAndFit:ke,center:(X=R.current.animateViewport)=>{be.current=null;const Y=Rt();Y&&I.center(Y,X)},clientToModel:(X,Y)=>I.renderedToModel(ze(X,Y)),modelToClient:X=>{var le;const Y=(le=_.current)==null?void 0:le.getBoundingClientRect(),pe=I.modelToRendered(X);return{x:pe.x+((Y==null?void 0:Y.left)??0),y:pe.y+((Y==null?void 0:Y.top)??0)}},getNodeBox:X=>Fe(X),detectNodeCollisions:X=>{const Y=L();return iv({...Y,sizes:new Map([...Y.sizes,...fe.current]),fixedSizes:fe.current},X)},resolveNodeCollisions:(X={})=>{const Y=Uj(L(),X);return Y.movedNodeIds.length&&J(Y.positions,X.animate),Y},arrangeNodesInGrid:(X={})=>{const Y=L(),pe=rt.current;if(pe){Y.positions=new Map(Y.positions);for(const st of Y.nodes)Y.positions.has(st.id)||Y.positions.set(st.id,I.renderedToModel({x:I.size.w/2,y:I.size.h/2}));const _e=new Set(Y.nodes.map(st=>st.id));pe.order=pe.order.filter(st=>_e.has(st));const Ze=new Set(pe.order);pe.order.push(...Y.nodes.filter(st=>!Ze.has(st.id)).map(st=>st.id));const nt=new Map(pe.order.map((st,rr)=>[st,rr]));Y.nodes=[...Y.nodes].sort((st,rr)=>nt.get(st.id)-nt.get(rr.id))}const le=bd(Y,A(X)),Le=le.sizes?JSON.stringify([[...le.positions],[...le.sizes]]):void 0;if(Le&&Le===me.current&&X.animate!==!1&&!be.current)return le;Tr(le.dividers??[]),pe&&(pe.ready=!1);const ve=()=>{pe&&(pe.ready=!0),pe&&Y.nodes.length&&!ie.current&&(ie.current=!0,R.current.fitOnInit!==!1&&!X.fill?pt.centerAndFit(50,!1):R.current.fitOnInit===!1&&I.transition(p,!1)),$e(_e=>_e+1)};return!le.sizes&&fe.current.size&&U(),Y.nodes.some(_e=>!ae.current.has(_e.id))||le.movedNodeIds.length||le.bounds||be.current?J(le.positions,X.animate,ve,le.bounds&&(!pe||!fe.current.size)?_e=>I.transition({zoom:1,pan:{x:0,y:0}},_e):void 0,le.sizes,!!pe&&!le.bounds):ve(),me.current=Le,le},setNodeGridMode:(X,Y={})=>{var pe,le,Le,ve;if(Y.order&&(!Array.isArray(Y.order)||Y.order.some(_e=>typeof _e!="string")||new Set(Y.order).size!==Y.order.length))throw new Error("Invalid grid node order.");if(X){bd(L(),A(Y));const _e=!rt.current||rt.current.options.fill&&!Y.fill;be.current=null,rt.current||(rt.current={options:Y,order:L().nodes.map(Ze=>Ze.id),previousPositions:new Map([...ae.current].map(([Ze,nt])=>[Ze,{...nt}])),previousViewport:{zoom:I.zoom,pan:{...I.pan}},previousSize:{...I.size},ready:!1}),_e&&pt.centerAndFit(80,Y.animate,!0),Y.order&&(rt.current.order=[...Y.order]),rt.current.options={...Y},At(!0),pt.arrangeNodesInGrid(Y),(le=(pe=R.current).onNodeGridModeChange)==null||le.call(pe,{...Y,order:[...rt.current.order]})}else{const _e=rt.current;if(!_e)return;if(I.size.w===_e.previousSize.w&&I.size.h===_e.previousSize.h&&ae.current.size===_e.previousPositions.size&&[...ae.current.keys()].every(st=>_e.previousPositions.has(st))?be.current=()=>I.transition(_e.previousViewport,Y.animate!==!1&&!R.current.disableAnimations&&!R.current.isPerformanceMode):pt.centerAndFit(80,Y.animate,!0),rt.current=null,At(!1),U(),(ve=(Le=R.current).onNodeGridModeChange)==null||ve.call(Le,null),Qt(null),!_e.previousPositions.size){ge();return}const nt=new Map([...ae.current].map(([st,rr])=>[st,_e.previousPositions.get(st)??rr]));J(nt,Y.animate,void 0,void 0,void 0,!0)}},swapGridNodes:(X,Y,pe)=>{var vn,nr,xr,bt,or;const le=rt.current;if(!le||!le.ready||R.current.readOnly||X===Y)return!1;const Le=L(),ve=Le.nodes.find(Ut=>Ut.id===X),_e=Le.nodes.find(Ut=>Ut.id===Y);if(!ve||!_e||ve.parent!==_e.parent)return!1;const Ze=bd(Le,A(le.options));if(Ze.skippedNodeIds.includes(X)||Ze.skippedNodeIds.includes(Y))return!1;const nt=le.order.indexOf(X),st=le.order.indexOf(Y);if(nt<0||st<0)return!1;[le.order[nt],le.order[st]]=[le.order[st],le.order[nt]],be.current=null,le.options={...le.options,order:[...le.order]};const rr=ve.parent??"canvas",hr=(nr=(vn=le.options.adjustment)==null?void 0:vn.sections)==null?void 0:nr[rr];return hr!=null&&hr.members&&(le.options={...le.options,adjustment:{...le.options.adjustment,sections:{...(xr=le.options.adjustment)==null?void 0:xr.sections,[rr]:{...hr,members:hr.members.map(Ut=>Ut.map(vr=>vr===X?Y:vr===Y?X:vr))}}}}),pt.arrangeNodesInGrid({...le.options,animate:pe??le.options.animate}),(or=(bt=R.current).onNodeGridModeChange)==null||or.call(bt,{...le.options}),!0},setNodePosition:(X,Y,pe)=>{var Le,ve,_e,Ze;if(!ae.current.has(X)||Y&&(!Number.isFinite(Y.x)||!Number.isFinite(Y.y)))return!1;if(ur(),!Y)return te.current.delete(X),(ve=(Le=R.current).onFixedNodePositionsChange)==null||ve.call(Le,Object.fromEntries(te.current)),ge(),!0;const le=new Map(ae.current);return le.set(X,{...Y}),(pe==null?void 0:pe.persist)===!1?te.current.delete(X):te.current.set(X,{...Y}),ae.current=le,Z(le),(pe==null?void 0:pe.persist)!==!1&&((Ze=(_e=R.current).onFixedNodePositionsChange)==null||Ze.call(_e,Object.fromEntries(te.current))),(pe==null?void 0:pe.persist)===!1&&ge(),!0},getFixedNodePositions:()=>Object.fromEntries([...te.current].map(([X,Y])=>[X,{...Y}])),onViewportChange:X=>I.onChange(X)}},[]);j.useEffect(()=>{var A,L;return(L=(A=R.current).onInit)==null||L.call(A,pt),()=>I.cancelAnimation()},[pt]),j.useEffect(()=>{var A,L;if(we>0){const B=De.current;De.current=null,B==null||B(),(L=(A=R.current).onLayoutComplete)==null||L.call(A,pt)}},[pt,we]);const mt=j.useRef(null),vt=j.useRef(new Map),er=j.useRef(!1),[tr,Ft]=j.useState(null),[it,br]=j.useState(null),Ir=A=>{const L=_.current.getBoundingClientRect();return{x:(A.clientX-L.left)*(_.current.clientWidth/L.width||1),y:(A.clientY-L.top)*(_.current.clientHeight/L.height||1)}},fr=(A,L)=>{const B=R.current.nodes;for(let J=B.length-1;J>=0;J--){const he=B[J].id;if(!ar(he,R.current.edges,R.current.edgeMode)||ft.current&&!ft.current.has(he)||he===L||et.current.has(he))continue;const Ee=Fe(he);if(Ee&&Zu(A,ir(Ee)))return he}for(const[J,he]of et.current)if(ar(J,R.current.edges,R.current.edgeMode)&&!(ft.current&&!ft.current.has(J))&&J!==L&&Zu(A,he))return J;return null},mn=(A,L)=>{const B=R.current.nodes.find(Se=>Se.id===A),J=Fe(A);if(!B||!J)return null;const he=ir({...J,x:J.x+L.x,y:J.y+L.y});let Ee=null,Ce=0;for(const Se of R.current.nodes){if(Se.id===A||Se.parent!==B.parent||te.current.has(Se.id)||et.current.has(Se.id)||!ar(Se.id,R.current.edges,R.current.edgeMode)||ft.current&&!ft.current.has(Se.id))continue;const Qe=Fe(Se.id);if(!Qe)continue;const qe=ir(Qe),ze=Math.max(0,Math.min(he.x2,qe.x2)-Math.max(he.x1,qe.x1))*Math.max(0,Math.min(he.y2,qe.y2)-Math.max(he.y1,qe.y1));ze>Ce&&(Ce=ze,Ee=Se.id)}return Ee},bn=(A,L)=>{const B=rt.current;if(!(B!=null&&B.ready)||R.current.readOnly)return;const J=R.current.nodes.filter(ze=>ar(ze.id,R.current.edges,R.current.edgeMode)&&(!ft.current||ft.current.has(ze.id))),he=J.find(ze=>ze.id===A);if(!he)return;const Ee=_.current,Ce=I.zoom*(Ee&&Ee.clientWidth?Ee.getBoundingClientRect().width/Ee.clientWidth:1),Se=24/Ce;let Qe;for(const ze of J){if(ze.id===A||ze.parent!==he.parent)continue;const ke=Fe(ze.id);if(!ke)continue;const X=ir(ke),Y=Math.min(ke.w/4,Se),pe=Math.min(ke.h/4,Se),le=3/Ce,Le=[];if(L.y>X.y1+pe&&L.y<X.y2-pe)for(const ve of["before","after"]){const _e=ve==="before"?X.x1:X.x2,Ze=Math.abs(L.x-_e),nt=ve==="before"?L.x<_e:L.x>_e;Ze<=(nt?Se:Y)&&Le.push({side:ve,distance:Ze,marker:{x1:_e-le/2,x2:_e+le/2,y1:X.y1,y2:X.y2}})}if(L.x>=X.x1&&L.x<=X.x2)for(const ve of["above","below"]){const _e=ve==="above"?X.y1:X.y2,Ze=Math.abs(L.y-_e),nt=ve==="above"?L.y<_e:L.y>_e;Ze<=(nt?Se:pe)&&Le.push({side:ve,distance:Ze,marker:{x1:X.x1,x2:X.x2,y1:_e-le/2,y2:_e+le/2}})}for(const ve of Le)(!Qe||ve.distance<Qe.distance)&&(Qe={id:ze.id,...ve})}if(!Qe)return;const qe=Gj({nodes:J,positions:ae.current,sizes:new Map([...F.current,...fe.current]),fixedSizes:fe.current,padding:ze=>R.current.containerStyle(ze).padding,minSize:Te,fixedIds:new Set(te.current.keys())},B.options,A,Qe.id,Qe.side);return qe?{options:qe,marker:Qe.marker}:void 0},Zr=(A,L)=>{if(R.current.edgeMode==="nodes"||R.current.edgeMode==="workflow")return null;const B=R.current.direction==="RL",J=Math.max(16,6/I.zoom);let he=null;for(const Ee of[...R.current.nodes].reverse()){if(!ar(Ee.id,R.current.edges,R.current.edgeMode)||ft.current&&!ft.current.has(Ee.id))continue;const Ce=Fe(Ee.id),Se=G.current.get(Ee.id);if(!Ce||!Se||et.current.has(Ee.id))continue;const Qe=Ce.x+(L==="source"!==B?1:-1)*Ce.w/2;for(const qe of Se){if(qe.role&&qe.role!==L)continue;const ze=Ce.y-Ce.h/2+qe.top,ke=Math.hypot(A.x-(qe.anchor?Ce.x-Ce.w/2+qe.anchor.x:Qe),A.y-ze-qe.height/2);if(!qe.anchor&&A.x>=Ce.x-Ce.w/2&&A.x<=Ce.x+Ce.w/2&&A.y>=ze&&A.y<=ze+qe.height)return{nodeId:Ee.id,property:qe.property};ke<=J&&(!he||ke<he.distance)&&(he={nodeId:Ee.id,property:qe.property,distance:ke})}}return he},mv=A=>{var Se,Qe;if(!A.currentTarget.contains(A.target)||(mt.current||(er.current=!1),A.target.closest(".flow-sdk-canvas")!==A.currentTarget)||A.button!==0||R.current.readOnly)return;const L=A.target;if(L.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const B=R.current,J=Ir(A);if(A.pointerType==="touch"){vt.current.set(A.pointerId,J);const qe=Am(vt.current);if(qe){Qt(null),mt.current={kind:"pinch",distance:qe.distance,zoom:I.zoom,anchor:I.renderedToModel(qe.center)},br(null),Ft(null),er.current=!0;for(const ze of vt.current.keys())A.currentTarget.setPointerCapture(ze);return}}if(mt.current)return;const he=!rt.current||!!B.nodeGridConnections,Ee=B.drawHandles&&L.closest(".flow-sdk-handle"),Ce=B.drawHandles&&L.closest(".flow-sdk-property-port");if((!he||!Ee&&!Ce&&(!B.drawMode||A.shiftKey))&&(rt.current||A.shiftKey&&(B.onNodeGridDrop||B.onNodeParentChange))){if(rt.current&&!rt.current.ready||L.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]"))return;const qe=(Se=L.closest("[data-node-id]"))==null?void 0:Se.dataset.nodeId;if(qe&&!te.current.has(qe)){L.setPointerCapture(A.pointerId),mt.current={kind:"grid",pointerId:A.pointerId,captureTarget:L,source:qe,start:J,moved:!1};return}if(qe)return}if(he&&(B.drawMode||Ee||Ce)){const qe=I.renderedToModel(J),ze=B.drawMode?Zr(qe,"source"):null,ke=Ce||Ee,X=ke?(Qe=ke.closest("[data-node-id]"))==null?void 0:Qe.dataset.nodeId:(ze==null?void 0:ze.nodeId)??fr(qe),Y=Ce?Ce.dataset.property:ze==null?void 0:ze.property;if(X){mt.current={kind:"draw",pointerId:A.pointerId,source:X,sourceProperty:Y,reverse:(Ce==null?void 0:Ce.dataset.portRole)==="target",startClient:{x:A.clientX,y:A.clientY}},er.current=!0,br({source:X,sourceProperty:Y,point:qe,target:null}),A.currentTarget.setPointerCapture(A.pointerId);return}}L.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(be.current=null,B.multiSelect?mt.current={kind:"box",pointerId:A.pointerId,start:J,current:J}:B.dragMode?mt.current={kind:"pan",pointerId:A.pointerId,start:J,pan0:I.pan,moved:!1}:mt.current={kind:"tap",pointerId:A.pointerId,start:J,moved:!1},A.currentTarget.setPointerCapture(A.pointerId))},bv=A=>{var J,he,Ee;const L=mt.current;if(!L||R.current.readOnly)return;const B=Ir(A);if(vt.current.has(A.pointerId)&&vt.current.set(A.pointerId,B),L.kind==="pinch"){const Ce=Am(vt.current);if(!Ce)return;const Se=Math.max(I.minZoom,Math.min(I.maxZoom,L.zoom*Ce.distance/L.distance));if(Se<I.zoom&&((J=rt.current)!=null&&J.options.fill)&&((Ee=(he=R.current).onNodeGridZoomOut)==null?void 0:Ee.call(he,rt.current.options))===!0)return;I.set({x:Ce.center.x-L.anchor.x*Se,y:Ce.center.y-L.anchor.y*Se},Se);return}if(L.pointerId===A.pointerId)switch(L.kind){case"grid":{const Ce={x:B.x-L.start.x,y:B.y-L.start.y};if(!L.moved&&Math.hypot(Ce.x,Ce.y)<=vd)return;L.moved||(ur(),be.current=null,I.cancelAnimation()),L.moved=!0,er.current=!0,A.preventDefault();const Se={x:Ce.x/I.zoom,y:Ce.y/I.zoom},Qe=!A.shiftKey&&B.x>=0&&B.y>=0&&B.x<=I.size.w&&B.y<=I.size.h?bn(L.source,I.renderedToModel(B)):void 0;Qt({source:L.source,offset:Se,target:A.shiftKey||Qe?null:mn(L.source,Se),shiftKey:A.shiftKey,insertion:Qe});break}case"pan":{const Ce=B.x-L.start.x,Se=B.y-L.start.y;if(!L.moved&&Math.hypot(Ce,Se)<=vd)return;L.moved=!0,er.current=!0,I.set({x:L.pan0.x+Ce,y:L.pan0.y+Se});break}case"tap":{Math.hypot(B.x-L.start.x,B.y-L.start.y)>vd&&(L.moved=!0);break}case"box":{er.current=!0,L.current=B,Ft({x1:Math.min(L.start.x,B.x),y1:Math.min(L.start.y,B.y),x2:Math.max(L.start.x,B.x),y2:Math.max(L.start.y,B.y)});break}case"draw":{const Ce=I.renderedToModel(B),Se=Zr(Ce,L.reverse?"source":"target");br(L.reverse&&Se?{source:Se.nodeId,sourceProperty:Se.property,point:Ce,target:L.source,targetProperty:L.sourceProperty}:{source:L.source,sourceProperty:L.sourceProperty,point:Ce,target:(Se==null?void 0:Se.nodeId)??fr(Ce,L.source),targetProperty:Se==null?void 0:Se.property});break}}},xu=(A,L)=>{var he,Ee,Ce,Se,Qe,qe,ze,ke,X,Y,pe;vt.current.delete(A.pointerId);const B=mt.current;if(!B)return;if(B.kind==="pinch"){const le=[...vt.current][0];mt.current=le&&R.current.dragMode&&!L?{kind:"pan",pointerId:le[0],start:le[1],pan0:I.pan,moved:!0}:null;return}if(B.pointerId!==A.pointerId)return;mt.current=null;try{(B.kind==="grid"?B.captureTarget:A.currentTarget).releasePointerCapture(A.pointerId)}catch{}const J=R.current;switch(L=L||!!J.readOnly,B.kind){case"grid":{if(Qt(null),L||!B.moved)break;const le=Ir(A);if(!A.shiftKey&&le.x>=0&&le.y>=0&&le.x<=I.size.w&&le.y<=I.size.h){const ve=bn(B.source,I.renderedToModel(le));if(ve){pt.setNodeGridMode(!0,{...ve.options,animate:!1});break}}if(((he=J.onNodeGridDrop)==null?void 0:he.call(J,B.source,{x:A.clientX,y:A.clientY},{shiftKey:A.shiftKey,ctrlKey:A.ctrlKey,metaKey:A.metaKey,altKey:A.altKey}))===!0||le.x<0||le.y<0||le.x>I.size.w||le.y>I.size.h)break;if(A.shiftKey){const ve=new Map(J.nodes.map(nt=>[nt.id,nt]));let _e=fr(I.renderedToModel(le),B.source);const Ze=new Set;for(;_e&&!((Ee=ve.get(_e))!=null&&Ee.acceptsChildren)&&!Ze.has(_e);)Ze.add(_e),_e=((Ce=ve.get(_e))==null?void 0:Ce.parent)??null;if(_e&&((Se=ve.get(_e))!=null&&Se.acceptsChildren)){let nt=_e;const st=new Set;for(;nt&&!st.has(nt);)st.add(nt),nt=(Qe=ve.get(nt))==null?void 0:Qe.parent;st.has(B.source)||(qe=J.onNodeParentChange)==null||qe.call(J,B.source,_e)}break}if(!rt.current)break;const Le=mn(B.source,{x:(le.x-B.start.x)/I.zoom,y:(le.y-B.start.y)/I.zoom});Le&&pt.swapGridNodes(B.source,Le,!1);break}case"pan":case"tap":!L&&!B.moved&&((ze=J.onBackgroundTap)==null||ze.call(J));break;case"box":{if(Ft(null),L)break;const le=I.renderedToModel(B.start),Le=I.renderedToModel(B.current),ve={x1:Math.min(le.x,Le.x),y1:Math.min(le.y,Le.y),x2:Math.max(le.x,Le.x),y2:Math.max(le.y,Le.y)};if(ve.x2-ve.x1<1&&ve.y2-ve.y1<1){(ke=J.onBackgroundTap)==null||ke.call(J);break}const _e=[];for(const Ze of J.nodes){const nt=Fe(Ze.id);nt&&s1(ir(nt),ve)&&_e.push(Ze.id)}_e.length&&((X=J.onBoxSelect)==null||X.call(J,_e));break}case"draw":{if(br(null),L)break;const le=Ir(A),Le=I.renderedToModel(le),ve=Zr(Le,B.reverse?"source":"target"),_e=(ve==null?void 0:ve.nodeId)??fr(Le);if(_e===B.source&&(B.sourceProperty===void 0||(ve==null?void 0:ve.property)===void 0||ve.property===B.sourceProperty))break;_e?(Y=J.onEdgeDraw)==null||Y.call(J,B.reverse?_e:B.source,B.reverse?B.source:_e,B.sourceProperty!==void 0||(ve==null?void 0:ve.property)!==void 0?{sourceProperty:B.reverse?ve==null?void 0:ve.property:B.sourceProperty,targetProperty:B.reverse?B.sourceProperty:ve==null?void 0:ve.property}:void 0):Math.max(Math.abs(A.clientX-B.startClient.x),Math.abs(A.clientY-B.startClient.y))>tE&&((pe=J.onDrawIntoSpace)==null||pe.call(J,B.source,Le,B.sourceProperty,B.reverse));break}}},Nr=j.useCallback(()=>{var B;const A=mt.current,L=[...vt.current.keys()];A&&A.kind!=="pinch"&&L.push(A.pointerId),mt.current=null,vt.current.clear(),Qt(null),br(null),Ft(null);for(const J of L)(A==null?void 0:A.kind)==="grid"&&A.captureTarget.hasPointerCapture(J)&&A.captureTarget.releasePointerCapture(J),(B=_.current)!=null&&B.hasPointerCapture(J)&&_.current.releasePointerCapture(J)},[]);j.useEffect(()=>{const A=L=>{L.key==="Escape"&&Nr()};return window.addEventListener("keydown",A),window.addEventListener("blur",Nr),()=>{window.removeEventListener("keydown",A),window.removeEventListener("blur",Nr),mt.current=null,vt.current.clear()}},[Nr]),j.useEffect(()=>{Nr()},[y,b,x,i,n,e.drawHandles,e.readOnly,yt,Nr]);const xv=j.useMemo(()=>{const A=new Map,L=new Map;for(const B of P){if(B.source!==B.target)continue;const J=A.get(B.source)??0;A.set(B.source,J+1),L.set(B.id,J)}return L},[P]),Ko=eE[n],[Or,vv]=j.useState(null),Jo=Yj(r,P,!!((ju=e.edgeReveal)!=null&&ju.revealNodes));j.useLayoutEffect(()=>{_.current&&Or&&Pm(_.current,Or)}),j.useEffect(()=>{const A=_.current;if(!A||!Or)return;const L=A.ownerDocument.fonts,B=()=>Pm(A,Or);return L==null||L.addEventListener("loadingdone",B),()=>L==null?void 0:L.removeEventListener("loadingdone",B)},[Or]);const Zo=i1(P,St,Ko),wv=e.onEdgeSelect,Cv=e.onContainerSelect,vu=it?it.target&&St(it.target,it.targetProperty)||{x:it.point.x,y:it.point.y,w:1,h:1}:null,wu=it?St(it.source,it.sourceProperty):null,xn=!yt||!!e.nodeGridConnections,Sv=["flow-sdk-canvas",y&&xn?"flow-sdk-draw":"",v?"flow-sdk-perf":""].filter(Boolean).join(" ");return f.jsxs("div",{ref:_,className:Sv,"data-edge-mode":i,"data-node-grid":yt||void 0,"data-grid-connections":e.nodeGridConnections||void 0,onPointerDownCapture:mv,onPointerMove:bv,onPointerUp:A=>xu(A,!1),onPointerCancel:A=>xu(A,!0),onLostPointerCapture:A=>{const L=mt.current;L&&(L.kind==="pinch"||L.pointerId===A.pointerId)&&Nr()},onClickCapture:A=>{if(!A.currentTarget.contains(A.target))return;const L=A.target instanceof Element&&A.target.closest("button[data-flow-fullscreen], button[data-flow-content-navigation]");(er.current||e.readOnly&&!L)&&(A.preventDefault(),A.stopPropagation())},children:[f.jsx("svg",{className:"flow-sdk-svg",children:f.jsxs("g",{ref:N,children:[f.jsx("g",{className:"flow-sdk-containers",children:[...Ye].filter(([A])=>ar(A,t,i)).filter(([A])=>!E||E.has(A)).map(([A,L])=>{var B,J;return f.jsx(b1,{id:A,rect:L,label:Re.get(A),labelLayer:Or,labelContent:(B=r.find(he=>he.id===A&&he.label!==void 0))==null?void 0:B.element,style:m(A),onSelect:Cv,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(J=e.selectedNodeIds)==null?void 0:J.includes(A)},A)})}),f.jsx("g",{className:"flow-sdk-edges",children:lt&&xn&&P.map(A=>{var J,he,Ee;if(!Jo.ready.has(A.id)||E&&(!E.has(A.source)||!E.has(A.target)))return null;const L=St(A.source,A.sourceProperty),B=St(A.target,A.targetProperty);return!L||!B?null:f.jsx(nf,{id:A.id,edgeData:A.data,validationIssue:A.validationIssue,edgeType:A.type,edgeRadius:e.edgeRadius,propertyMode:M,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:Jo.complete,source:L,target:B,sourceProperty:A.sourceProperty,targetProperty:A.targetProperty,sourceY:ht(A.source,A.sourceProperty),targetY:ht(A.target,A.targetProperty),sourcePort:wt(A.source,A.sourceProperty),targetPort:wt(A.target,A.targetProperty),dir:Ko,turn:((J=Zo.get(A.id))==null?void 0:J.turn)??A.turn,labelAtTarget:(he=Zo.get(A.id))==null?void 0:he.labelAtTarget,labelFraction:(Ee=Zo.get(A.id))==null?void 0:Ee.labelFraction,color:A.color,connectorColor:A.connectorColor,labelBg:A.labelBg,label:A.label,labelLayer:Or,dashed:A.dashed,animated:A.animated&&!v,inverted:A.inverted,loopIndex:xv.get(A.id)??0,onSelect:wv},A.id)})}),lt&&xn&&it&&Pd(it,i)&&wu&&vu&&f.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:f.jsx(nf,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:it.source,target:it.target??"",sourceProperty:it.sourceProperty,targetProperty:it.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:M,customEdgeTypes:e.customEdgeTypes,source:wu,target:vu,sourceProperty:it.sourceProperty,targetProperty:it.targetProperty,sourceY:ht(it.source,it.sourceProperty),sourcePort:wt(it.source,it.sourceProperty),targetPort:it.target?wt(it.target,it.targetProperty):void 0,targetY:it.target?ht(it.target,it.targetProperty):void 0,dir:Ko,turn:.5,color:g,labelBg:g})})]})}),f.jsxs("div",{ref:V,className:"flow-sdk-nodes",children:[(We==null?void 0:We.insertion)&&f.jsx("div",{className:"flow-sdk-box","data-grid-insertion":"",style:{left:We.insertion.marker.x1,top:We.insertion.marker.y1,width:We.insertion.marker.x2-We.insertion.marker.x1,height:We.insertion.marker.y2-We.insertion.marker.y1,background:g,border:0}}),yt&&((Eu=rt.current)==null?void 0:Eu.options.fill)&&((_u=rt.current.options.adjustment)==null?void 0:_u.enabled)&&!e.readOnly&&f.jsx(Kj,{dividers:Jr,options:rt.current.options,zoom:I.zoom,onChange:A=>pt.setNodeGridMode(!0,{...A,animate:!1})}),r.map(A=>{var Le,ve,_e;if((Le=rt.current)!=null&&Le.options.fill&&!ie.current)return null;const L=re.get(A.id),B=Ye.get(A.id);if(B&&A.label!==void 0)return null;const J=(L==null?void 0:L.x)??(B?(B.x1+B.x2)/2:0),he=(L==null?void 0:L.y)??(B?(B.y1+B.y2)/2:0),Ee=We!=null&&We.target?A.id===We.source?We.target:A.id===We.target?We.source:void 0:void 0,Ce=Ee?re.get(Ee):void 0,Se=We?re.get(We.source):void 0,Qe=We!=null&&We.target?re.get(We.target):void 0,qe=Se&&Qe?{x:Qe.x-Se.x,y:Qe.y-Se.y}:void 0,ze=qe?qe.x**2+qe.y**2:0,ke=ze&&We&&qe?Math.max(0,Math.min(1,(We.offset.x*qe.x+We.offset.y*qe.y)/ze)):0,X=Ce?{x:J+(Ce.x-J)*ke,y:he+(Ce.y-he)*ke}:(We==null?void 0:We.source)===A.id?{x:J+We.offset.x,y:he+We.offset.y}:void 0,Y=ye.get(A.id),pe=Ee?ye.get(Ee):void 0,le=Y&&pe?{w:Y.w+(pe.w-Y.w)*ke,h:Y.h+(pe.h-Y.h)*ke}:Y;return f.jsx(Xj,{id:A.id,x:J,y:he,gridDraggable:yt&&!e.readOnly&&!te.current.has(A.id),gridDragging:(We==null?void 0:We.source)===A.id,gridDropTarget:(We==null?void 0:We.target)===A.id,gridSize:ye.get(A.id),gridPreview:X?{...X,size:le,floating:We==null?void 0:We.shiftKey}:void 0,placed:!!L||!!B,hidden:!yt&&!Jo.shown.has(A.id)||!ar(A.id,t,i)||!!E&&!E.has(A.id),onMount:je,drawHandles:e.drawHandles&&!e.readOnly&&xn,drawMode:y&&xn,connectedPorts:new Set(P.flatMap(Ze=>[...Ze.source===A.id&&Ze.sourceProperty!==void 0?[`source:${Ze.sourceProperty}`]:[],...Ze.target===A.id&&Ze.targetProperty!==void 0?[`target:${Ze.targetProperty}`]:[]])),hasCollapseControl:A.hasCollapseControl,handleColor:g,animated:A.animated&&!B&&!v&&!yt,animationColor:A.animationColor,animationWidth:A.animationWidth,animationVariant:A.animationVariant,width:(ve=F.current.get(A.id))==null?void 0:ve.w,height:(_e=F.current.get(A.id))==null?void 0:_e.h,propertyMode:M,resolvedRows:ct.get(A.id),reversePorts:n==="RL",direction:n,onPropertyRows:ce,onSurface:q,children:Y?A.fillElement??A.element:A.element},A.id)})]}),tr&&f.jsx("div",{className:"flow-sdk-box",style:{left:tr.x1,top:tr.y1,width:tr.x2-tr.x1,height:tr.y2-tr.y1}}),f.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:f.jsx("g",{ref:$,transform:`translate(${I.pan.x} ${I.pan.y}) scale(${I.zoom})`,children:f.jsx("g",{ref:vv,className:"flow-sdk-labels",style:{pointerEvents:y?"none":"visiblePainted",outline:"none"}})})})]})}const iE=j.memo(oE);function gu(e=!0){const r=j.useRef(null);return j.useEffect(()=>{if(!e||!r.current)return;const t=i=>{i.stopPropagation()},n=r.current,o=["mousedown","mouseup","click","dblclick","pointerdown","pointerup","wheel"];return o.forEach(i=>n.addEventListener(i,t)),()=>{o.forEach(i=>n.removeEventListener(i,t))}},[e]),r}const cn=({nodeId:e,label:r,color:t,fontWeight:n="bold",fontSize:o="5xl",wrap:i=!1,isEditing:s,onEditStart:a,onEditEnd:c})=>{const{callbacks:l,config:d,readOnly:u}=Ue(),h=d.editable&&!u,[p,m]=j.useState(r),[g,y]=j.useState(),b=j.useRef(null),x=j.useRef(!1),v=gu(s);j.useEffect(()=>{if(s&&(x.current=!1,b.current)){b.current.focus();const C=b.current.value.length;b.current.setSelectionRange(C,C)}},[s]);const w=()=>{var S;if(x.current)return;x.current=!0;const C=p.trim();C&&C!==r&&((S=l.onNodeLabelChange)==null||S.call(l,e,C)),c()};return!h||!s?f.jsx(W.Text,{color:t,fontWeight:n,fontSize:o,minW:0,maxW:"100%",whiteSpace:i?"normal":"nowrap",overflowWrap:i?"anywhere":void 0,overflow:"hidden",textOverflow:"ellipsis",title:r,onDoubleClick:h?C=>{C.stopPropagation(),y({width:C.currentTarget.offsetWidth,height:C.currentTarget.offsetHeight}),m(r),a()}:void 0,cursor:h?"text":void 0,children:r}):f.jsxs("div",{ref:v,style:{position:"relative",width:"max-content",minWidth:g==null?void 0:g.width,maxWidth:900,height:g==null?void 0:g.height},children:[f.jsx(W.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),f.jsx(W.Input,{ref:b,value:p,onChange:C=>m(C.target.value),onBlur:w,onKeyDown:C=>{C.key==="Enter"&&w(),C.key==="Escape"&&(x.current=!0,c())},color:t,fontWeight:n,fontSize:o,bg:"transparent",borderWidth:0,_focus:{outline:"none",boxShadow:"none"},_focusVisible:{outline:"none",boxShadow:"none"},p:0,display:"block",position:"absolute",top:0,left:0,w:"100%",h:"100%",minW:0,minH:0,lineHeight:"normal"})]})};function sv({id:e,label:r,role:t,side:n,position:o=.5,placement:i,children:s,style:a}){return f.jsx("div",{"data-flow-property":e,"data-flow-port-role":t,"data-flow-port-side":n,"data-flow-port-position":n?o:void 0,"data-flow-port-placement":i,style:{minHeight:32,display:"flex",alignItems:"center",justifyContent:t==="source"?"flex-end":"flex-start",...a,...n?{display:"none"}:{}},children:s??r??e})}const aE=xo.default.dialog`
209
+ `;function Ku({request:e,property:r,config:t,value:n,disabled:o}){var fe,U,re,de,Pe;const{callbacks:i,structured:s,references:a}=j.useContext($t),{themeColor:c}=He(),{background:l}=at(),d=j.useId(),u=r.type.kind==="object"||r.type.kind==="array"||r.type.kind==="json",h=n===void 0?"":u?JSON.stringify(n,null,2):String(n),[p,m]=j.useState(h),[g,y]=j.useState(""),[b,x]=j.useState(0),w=j.useRef(null),v=j.useRef(),[C,S]=j.useState(!1),[E,R]=j.useState(!1),[P,I]=j.useState(),M=((fe=t.$options)==null?void 0:fe.$source)==="callback",k=i.resolveFormOptions,{data:_,address:N,nodeAddress:$,nodeId:D}=e;j.useEffect(()=>(S(!1),R(!1),()=>{var ae;(ae=v.current)==null||ae.abort(),v.current=void 0}),[N,$,D,o,h,t.$control,(U=t.$upload)==null?void 0:U.accept,(re=t.$upload)==null?void 0:re.maxSizeBytes]);const T=j.useRef(_);T.current=_;const Z=JSON.stringify([N,D,(de=t.$options)!=null&&de.$dependsOn?t.$options.$dependsOn.map(ae=>Oe(_,ae)):Oe(_,$)]);j.useEffect(()=>{m(h),y("")},[h,N,D]),j.useEffect(()=>{if(!M)return;const ae=new AbortController;return Promise.resolve().then(()=>{if(!k)throw new Error("No options resolver configured");return k({address:N,nodeAddress:$,nodeId:D,data:an(T.current),signal:ae.signal})}).then(we=>{if(!Array.isArray(we)||we.some($e=>!$e||typeof $e.label!="string"||!["string","number","boolean"].includes(typeof $e.value)&&$e.value!==null))throw new Error("Invalid options response");ae.signal.aborted||I({key:Z,options:we})}).catch(we=>{ae.signal.aborted||I({key:Z,options:[],error:we instanceof Error?we.message:"Options unavailable"})}),()=>ae.abort()},[M,k,Z,N,$,D,b]);const K=M&&(P==null?void 0:P.key)!==Z,ne=M?(P==null?void 0:P.key)===Z?P.options:[]:r.type.kind==="null"?[{label:"Null",value:null}]:r.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:On(r.type),se=r.type.kind==="array",W=(t.$control==="upload"?"upload":s&&u||t.$control==="checkbox"?"pills":t.$control)??(ne?se||r.type.kind==="boolean"?"pills":"select":r.type.kind==="boolean"?"checkbox":u?"textarea":"input"),ue=!r.optional||!!t.$requiredWhen&&Eo(t.$requiredWhen,_),q=ue?"Required":"Optional",F=W!=="upload"&&!!(a!=null&&a.length)&&typeof n=="string"&&n.includes("{{"),H=g||M&&(P==null?void 0:P.key)===Z&&P.error||!F&&Jt(r.type,n,ue),G=Dt(t.$label??N.split(".").pop()),ce=ae=>{var we;if(!(o||Object.is(ae,n)))try{(we=i.onFormChange)==null||we.call(i,{...e,previousValue:n,value:ae}),y("")}catch($e){y($e instanceof Error?$e.message:"Unable to update field")}},te=j.useRef(ce);j.useLayoutEffect(()=>{te.current=ce});const X=()=>{if(u){try{const Ue=p===""&&r.optional?void 0:JSON.parse(p),Ve=Jt(r.type,Ue,ue);if(Ve){y(Ve);return}ce(Ue)}catch{y("Enter valid JSON")}return}const ae=r.type.kind==="number"||r.type.kind==="integer",we=p===""&&r.optional?void 0:ae&&p!==""?Number(p):p,$e=Jt(r.type,we,ue);if(ae&&$e&&p!==""){y($e);return}ce(we)},ie=async ae=>{var $e,Ue,Ve;if(o||v.current||!ae.length)return;const we=new AbortController;v.current=we,y(""),S(!0);try{if(r.type.kind!=="string"&&!(r.type.kind==="array"&&r.type.items.kind==="string"))throw new Error("Uploads require a string or string-array field.");if(!se&&ae.length!==1)throw new Error("Choose one file for this field.");if(!i.uploadFormFile)throw new Error("No file upload handler configured.");const tt=(Ue=($e=t.$upload)==null?void 0:$e.accept)==null?void 0:Ue.split(",").map(be=>be.trim().toLowerCase()).filter(Boolean);for(const be of ae){if(((Ve=t.$upload)==null?void 0:Ve.maxSizeBytes)!==void 0&&be.size>t.$upload.maxSizeBytes)throw new Error(`${be.name} exceeds the file size limit.`);if(tt!=null&&tt.length&&!tt.some(Xe=>Xe.startsWith(".")?be.name.toLowerCase().endsWith(Xe):Xe.endsWith("/*")?be.type.toLowerCase().startsWith(Xe.slice(0,-1)):be.type.toLowerCase()===Xe))throw new Error(`${be.name} is not an accepted file type.`)}const ge=await Promise.all(ae.map(async be=>{const Xe=await i.uploadFormFile({...e,data:an(_),file:be,signal:we.signal});if(typeof Xe!="string")throw new Error("Upload handler must return an HTTP or HTTPS URL.");let ut;try{ut=new URL(Xe)}catch{throw new Error("Upload handler must return an HTTP or HTTPS URL.")}if(!["http:","https:"].includes(ut.protocol)||ut.username||ut.password)throw new Error("Upload handler must return an HTTP or HTTPS URL.");return Xe}));if(we.signal.aborted||v.current!==we)return;const Ae=se?[...Array.isArray(n)?n:[],...ge]:ge[0],Le=Jt(r.type,Ae,ue);if(Le)throw new Error(Le);te.current(Ae)}catch(tt){we.signal.aborted||y(tt instanceof Error?tt.message:"Unable to upload file."),we.abort()}finally{v.current===we&&(v.current=void 0,S(!1))}},me={id:d,disabled:o,"aria-label":G,"aria-required":ue,"aria-invalid":!!H,"aria-describedby":H?`${d}-error`:void 0},xe=Te(c);return f.jsxs("div",{"data-form-field":N,"data-flow-property":N.slice($.length+1),children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[f.jsxs("label",{htmlFor:d,children:[G,ue?" *":""]}),r.optional&&n!==void 0&&f.jsx("button",{type:"button","aria-label":`Reset ${G}`,title:`Reset ${G}`,disabled:o||C,style:{width:24,height:24,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:0,background:"transparent",color:"inherit"},onClick:()=>ce(void 0),children:f.jsx(ee.PiArrowCounterClockwise,{size:14})})]}),!!(a!=null&&a.length)&&!u&&W!=="upload"&&f.jsx(Vw,{label:G,value:n,references:a,disabled:o,onChange:ce}),W==="upload"?f.jsxs("div",{"data-form-upload":se?"multiple":"single","aria-busy":C,style:{"--flow-upload-surface":Te(l),outline:E?"2px dashed var(--flow-form-input-background)":void 0,borderRadius:"var(--flow-form-input-radius)"},onDragOver:ae=>{ae.preventDefault(),ae.stopPropagation(),!o&&!C&&(ae.dataTransfer.dropEffect="copy",R(!0))},onDragLeave:ae=>{ae.currentTarget.contains(ae.relatedTarget)||R(!1)},onDrop:ae=>{ae.preventDefault(),ae.stopPropagation(),R(!1),ie(Array.from(ae.dataTransfer.files))},children:[f.jsx("input",{ref:w,type:"file",hidden:!0,"aria-label":`Upload ${G}`,accept:(Pe=t.$upload)==null?void 0:Pe.accept,multiple:se,disabled:o||C,onChange:ae=>{const we=Array.from(ae.target.files??[]);ae.target.value="",ie(we)}}),f.jsxs("div",{"data-upload-items":"",children:[(se?Array.isArray(n)?n:[]:n?[n]:[]).map((ae,we)=>f.jsxs("div",{"data-upload-preview":"",children:[typeof ae=="string"&&wr(ae)&&f.jsxs("a",{href:ae,target:"_blank",rel:"noopener noreferrer","aria-label":`${G} file ${we+1}`,children:[f.jsx(ee.PiFile,{size:32,"aria-hidden":"true"}),f.jsx(cr,{name:ae,size:120,onError:$e=>{$e.currentTarget.style.visibility="hidden"}})]}),f.jsxs("div",{"data-upload-actions":"",children:[!se&&f.jsx(Ne,{"aria-label":`Replace ${G}`,title:`Replace ${G}`,icon:f.jsx(ee.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>{var $e;return($e=w.current)==null?void 0:$e.click()}}),f.jsx(Ne,{"aria-label":`Remove ${G} file ${we+1}`,title:"Remove file",icon:f.jsx(ee.PiTrash,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>ce(se&&Array.isArray(n)?n.filter(($e,Ue)=>Ue!==we):"")})]})]},`${we}:${ae}`)),(se||!n)&&f.jsx("button",{...me,type:"button","data-upload-drop":"",title:`Upload ${G}`,disabled:o||C,onClick:()=>{var ae;return(ae=w.current)==null?void 0:ae.click()},children:f.jsx(ee.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&f.jsx("span",{role:"status",children:"Uploading..."})]}):F?null:W==="select"?f.jsx("div",{"data-form-select":"",children:f.jsxs(It,{...me,disabled:o||K||!!(P!=null&&P.error),labelCase:"preserve",value:String((ne==null?void 0:ne.findIndex(ae=>Object.is(ae.value,n)))??-1),onValueChange:ae=>{const we=ne==null?void 0:ne[Number(ae)];we&&ce(we.value)},children:[f.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):q}),ne==null?void 0:ne.map((ae,we)=>f.jsx("option",{value:we,children:Dt(ae.label)||ae.label},we))]})}):W==="pills"?f.jsxs("div",{id:d,role:"group","aria-label":G,"aria-describedby":me["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:[ne==null?void 0:ne.map((ae,we)=>{const $e=se?Array.isArray(n)&&n.includes(ae.value):Object.is(n,ae.value);return f.jsx("button",{type:"button",disabled:o||K,"aria-pressed":$e,style:{padding:"8px 16px",borderRadius:24,border:0,color:$e?xe:"inherit",background:$e?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>ce(se?$e?n.filter(Ue=>Ue!==ae.value):[...Array.isArray(n)?n:[],ae.value]:ae.value),children:Dt(ae.label)||ae.label},we)}),K&&f.jsx("span",{role:"status",children:"Loading..."})]}):W==="textarea"?f.jsx("textarea",{...me,placeholder:q,value:p,onChange:ae=>m(ae.target.value),onBlur:X}):f.jsx("input",{...me,placeholder:q,type:r.type.kind==="number"||r.type.kind==="integer"?"number":"text",step:r.type.kind==="integer"?1:"any",value:p,onChange:ae=>m(ae.target.value),onBlur:X,onKeyDown:ae=>{ae.key==="Enter"&&X(),ae.key==="Escape"&&m(n===void 0?"":String(n))}}),H&&f.jsx("div",{role:"alert",id:`${d}-error`,children:H}),M&&(P==null?void 0:P.error)&&f.jsx("button",{type:"button",disabled:o,onClick:()=>{I(void 0),x(b+1)},children:"Retry"})]})}function Vd({nodeAddress:e,structured:r=!1}){return r?f.jsx(Hw,{nodeAddress:e},e):f.jsx(Ed,{nodeAddress:e})}function Hw({nodeAddress:e}){var u,h,p;const r=j.useContext($t),[t,n]=j.useState([]),o=((u=r.structured)==null?void 0:u.sourceSchema)??r.schema,i=((h=r.structured)==null?void 0:h.sourceBindings)??r.bindings,s=j.useMemo(()=>{if(!(!r.data||!o||!i))return kb(r.data,i,o,[{data:{id:e,type:"objectView"}}])},[r.data,i,o,e]);if(!s)return f.jsx(Ed,{nodeAddress:e});const a=t.findIndex(m=>!s.containers.has(m)),c=a<0?t:t.slice(0,a),l=c.at(-1)??e,d=(p=[...s.slots.values()].find(m=>m.nodeId===l))==null?void 0:p.label;return f.jsxs($t.Provider,{value:{...r,structured:s,schema:s.schema,bindings:s.bindings,renderForm:void 0,onFieldCreate:l===e?r.onFieldCreate:void 0},children:[!!c.length&&f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[f.jsx(Ne,{"aria-label":"Back to parent fields",title:"Back to parent fields",icon:f.jsx(ee.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:()=>n(c.slice(0,-1))}),f.jsx("strong",{style:{minWidth:0,overflowWrap:"anywhere"},children:Dt(d)})]}),f.jsx(Ed,{nodeAddress:l,onOpen:m=>n([...c,m])},l)]})}function Ed({nodeAddress:e,onOpen:r}){var S,E;const{data:t,schema:n,callbacks:o,bindings:i,editable:s,renderForm:a,structured:c}=j.useContext($t),{readOnly:l,config:d,colorMode:u}=He(),h=a==null?void 0:a(e);if(h!==void 0)return f.jsx("fieldset",{"data-flow-form":e,disabled:l||d.editable===!1||!s,style:{border:0,margin:0,padding:0,minWidth:0},children:h});if(!t)return f.jsx(no,{$colorMode:u,role:"alert",children:"Forms require a JSON document."});const p=i?Hn(i,e,n):void 0,m=i?p:n&&un(t,e,n);if(!m)return f.jsx(no,{$colorMode:u,role:"status",children:"Form schema unavailable."});const g=(p==null?void 0:p.address)??e,y=Oe(t,g),b=(S=c==null?void 0:c.containers.get(e))==null?void 0:S.scalar;if(y===void 0||typeof y!="object"&&!b)return f.jsx(no,{$colorMode:u,role:"alert",children:"Bound form state is unavailable."});const x=Object.entries(m.type.properties).filter(([R])=>{var P;return Eo((P=m.fields[R])==null?void 0:P.$visibleWhen,t)}),w=x.length>8||x.some(([R])=>{var P;return(P=m.fields[R])==null?void 0:P.$section}),v=new Map;for(const R of x){const[P,I]=R,M=w?Dt(((E=m.fields[P])==null?void 0:E.$section)??(I.type.kind==="object"||I.type.kind==="array"?P:I.optional?"Options":"General")):"";v.has(M)||v.set(M,[]),v.get(M).push(R)}const C=([R,P])=>f.jsx(Ku,{request:{data:t,address:b?g:`${g}.${R}`,nodeAddress:g,nodeId:typeof(y==null?void 0:y.id)=="string"?y.id:void 0},property:P,config:m.fields[R]??{},value:b?y:y==null?void 0:y[R],disabled:l||d.editable===!1||!(s??!!o.onJsonChange)},`${(y==null?void 0:y.id)??e}:${R}`);return f.jsxs(no,{$colorMode:u,"data-flow-form":e,onClick:R=>R.stopPropagation(),onDoubleClick:R=>R.stopPropagation(),children:[c&&f.jsx(Gw,{nodeAddress:e,onOpen:r}),!c&&p&&m.type.additionalProperties&&x.length===0&&f.jsx(Ku,{request:{data:t,address:g,nodeAddress:g},property:{type:m.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:y,disabled:l||d.editable===!1||!s}),[...v].map(([R,P])=>w&&P.length>1?f.jsxs("details",{open:!0,children:[f.jsxs("summary",{children:[f.jsx("span",{children:R}),f.jsx(ee.PiCaretDown,{size:16,"aria-hidden":"true"})]}),P.map(C)]},R):P.map(C))]})}function Ab(e){const{viewData:r}=j.useContext($t),{nodeById:t,edgeById:n,parentIds:o}=Xt();if(r){const i=Oe(r,e),s=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(s)?s.length>0:!!s&&typeof s=="object"&&Object.entries(s).some(([a,c])=>!a.startsWith("$")&&c!==null&&typeof c=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const s=i.isInverted?i.target:i.source,a=i.isInverted?i.source:i.target;return s===e&&a!==e&&t.has(a)})}function Dn(e,r){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:r}function Wn(e,r,t,n){return{borderColor:r,borderWidth:Dn(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",...gb(r==="transparent"?"currentColor":r,t,".flow-sdk-node:hover &",!t)}}function Rb({label:e,value:r,options:t,onChange:n,disabled:o}){var i;return f.jsxs(It,{"aria-label":e,title:`Animation: ${((i=t.find(s=>s.value===r))==null?void 0:i.label)??"Mixed"}`,value:r,style:{width:104},disabled:o,onValueChange:s=>{const a=t.find(c=>c.value===s);a&&n(a.value)},children:[r===""&&f.jsx("option",{value:"",disabled:!0,children:"Mixed"}),t.map(s=>f.jsx("option",{value:s.value,children:s.label},s.value))]})}function Gd({nodeId:e,edgeId:r,value:t,open:n,onOpenChange:o}){const{callbacks:i,readOnly:s,themeColor:a,colorMode:c}=He(),{background:l,backgroundSecondary:d,border:u,colorText:h,colorInactive:p}=at(),m=c==="dark"?ln:Te(p),g=j.useRef(null),y=j.useRef(null),b=j.useRef(0),[x,w]=j.useState(!1),[v,C]=j.useState("icons"),[S,E]=j.useState([]),[R,P]=j.useState("loading"),[I,M]=j.useState(""),[k,_]=j.useState(0),[N,$]=j.useState(""),[D,T]=j.useState(""),[Z,K]=j.useState(!1);j.useEffect(()=>()=>{b.current++},[]),j.useEffect(()=>{if(!x)return;let G=!0;return import("react-icons/pi").then(ce=>{G&&(E(Object.keys(ce).filter(te=>te.startsWith("Pi")).sort()),P("ready"))}).catch(()=>{G&&P("unavailable")}),()=>{G=!1}},[x]),j.useEffect(()=>{var G;s&&((G=g.current)==null||G.close())},[s]),j.useEffect(()=>{var G,ce,te;if(n!==void 0){if(!n||s){(G=g.current)==null||G.close();return}(ce=g.current)!=null&&ce.open||(T(""),C(t==="PiFileSvg"||t&&wr(t)?"custom":"icons"),$(t&&!t.startsWith($n)&&wr(t)?t:""),w(!0),(te=g.current)==null||te.showModal())}},[n,s,t]);const ne=G=>{var ce,te,X;s||(r?(ce=i.onEdgeIconChange)==null||ce.call(i,r,G):e&&((te=i.onNodeIconChange)==null||te.call(i,e,G)),o==null||o(!1),(X=g.current)==null||X.close())},se=S.filter(G=>G.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(I.trim().toLowerCase())),W=36,ue=Math.max(1,Math.ceil(se.length/W)),q=Math.min(k,ue-1),F=se.slice(q*W,(q+1)*W),H={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${Te(u)}`,borderRadius:30};return f.jsxs(f.Fragment,{children:[n===void 0&&f.jsx(Ge,{label:r?"Choose edge icon":"Choose node icon",children:f.jsx(Ne,{"aria-label":r?"Choose edge icon":"Choose node icon",icon:f.jsx(ee.PiShapes,{size:20}),size:"sm",variant:"ghost",color:Te(a),disabled:s,onClick:()=>{var G;T(""),C(t&&wr(t)?"custom":"icons"),$(t&&!t.startsWith($n)&&wr(t)?t:""),w(!0),(G=g.current)==null||G.showModal()}})}),f.jsx(V.chakra.dialog,{ref:g,"aria-label":r?"Choose edge icon":"Choose node icon",css:gr(Te(l),Te(u)),onClose:()=>{w(!1),o==null||o(!1),b.current++,K(!1)},onClick:G=>{G.stopPropagation(),G.target===G.currentTarget&&G.currentTarget.close()},onKeyDown:G=>G.stopPropagation(),style:{margin:"auto",padding:12,width:336,maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",borderRadius:30,background:Te(l),color:Te(h)},children:x&&f.jsxs("div",{style:{display:"grid",gap:8},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[f.jsx("strong",{children:r?"Edge icon":"Node icon"}),f.jsxs("div",{style:{display:"flex",alignItems:"center",marginLeft:"auto",gap:4},children:[t&&f.jsx(Ge,{label:"Remove icon",children:f.jsx(Ne,{"aria-label":r?"Remove edge icon":"Remove node icon",icon:f.jsx(ee.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:s||Z,onClick:()=>ne("")})}),f.jsx(dn,{"aria-label":"Close icon picker",onClick:()=>{var G;return(G=g.current)==null?void 0:G.close()}})]})]}),f.jsxs(V.Tabs.Root,{value:v,onValueChange:({value:G})=>{C(G),T("")},display:"contents",css:{"--indicator-thickness":"1px"},children:[f.jsx(V.Tabs.List,{"aria-label":"Icon source",width:"100%",borderBottomWidth:0,children:["icons","custom"].map(G=>f.jsx(V.Tabs.Trigger,{value:G,flex:1,minW:0,justifyContent:"center",px:3,py:2,fontSize:"13px",_selected:{color:a,borderColor:m,"--indicator-color":m},children:G==="icons"?"React icons":"Custom SVG"},G))}),f.jsx("input",{ref:y,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:Z||s,onChange:async G=>{var X;const ce=(X=G.target.files)==null?void 0:X[0];if(G.target.value="",!ce)return;const te=++b.current;K(!0),T("");try{const ie=await $w(ce);te===b.current&&ne(ie)}catch(ie){te===b.current&&T(ie instanceof Error?ie.message:"Unable to read SVG.")}finally{te===b.current&&K(!1)}}}),f.jsx(V.Tabs.Content,{value:v,p:0,style:{display:"grid",gap:8},children:v==="icons"?f.jsxs(f.Fragment,{children:[f.jsx("input",{"aria-label":"Search icons",placeholder:"Search icons...",value:I,onChange:G=>{M(G.target.value),_(0)},style:H}),f.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[F.map(G=>f.jsx("button",{type:"button","aria-label":`Choose ${G}`,"aria-pressed":t===G,title:G,onClick:()=>ne(G),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${t===G?2:1}px solid ${Te(t===G?a:u)}`,background:Te(t===G?l:d),color:"inherit",cursor:"pointer"},children:f.jsx(cr,{name:G,size:24})},G)),F.length===0&&f.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:R==="loading"?"Loading icons...":R==="unavailable"?"React icons unavailable":"No icons found"})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[f.jsxs("span",{role:"status",style:{fontSize:12},children:[se.length," icons · ",q+1," / ",ue]}),f.jsxs("div",{style:{display:"flex",gap:4},children:[f.jsx(Ge,{label:"Previous icons",children:f.jsx(Ne,{"aria-label":"Previous icons",icon:f.jsx(ee.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:q===0,onClick:()=>_(q-1)})}),f.jsx(Ge,{label:"Next icons",children:f.jsx(Ne,{"aria-label":"Next icons",icon:f.jsx(ee.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:q+1>=ue,onClick:()=>_(q+1)})})]})]})]}):f.jsxs(f.Fragment,{children:[t&&wr(t)&&f.jsx(cr,{name:t,size:64}),f.jsxs("button",{type:"button",disabled:Z||s,onClick:()=>{var G;return(G=y.current)==null?void 0:G.click()},style:{...H,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[f.jsx(ee.PiUploadSimple,{}),Z?"Uploading...":"Upload SVG"]}),f.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:G=>{G.preventDefault(),!(Z||s)&&(!wr(N.trim())||N.trim().startsWith($n)?T("Enter an HTTP or HTTPS image URL."):ne(N.trim()))},children:[f.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:N,disabled:Z||s,onChange:G=>$(G.target.value),style:{...H,flex:1,minWidth:0}}),f.jsx(Ge,{label:"Apply URL",children:f.jsx(Ne,{type:"submit","aria-label":"Apply URL",icon:f.jsx(ee.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:Z||s||!N.trim(),style:{flexShrink:0}})})]})]})})]}),D&&f.jsx("div",{role:"alert",style:{fontSize:13},children:D})]})})]})}const po=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500",ln],Mb=["gray.900",ln,"gray.600","gray.200","white"];function Tb(){const{config:e}=He(),r=e.selectionToolbar||{},t=new Set(r.hide||[]);return{palette:r.palette||po,show:n=>!t.has(n)}}function Tt(){const{border:e}=at();return f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:e})}function Er({value:e,placeholder:r,ariaLabel:t,width:n="140px",type:o="text",min:i,disabled:s=!1,onCommit:a}){const{colorText:c}=at(),[l,d]=j.useState(e),u=j.useRef(!1);j.useEffect(()=>d(e),[e]);const h=()=>{if(s||u.current)return;u.current=!0;const p=l.trim();if(o==="number"&&p!==""&&(!Number.isFinite(Number(p))||Number(p)<(i??0))){d(e);return}p!==e&&a(p)};return f.jsx(V.Input,{"aria-label":t,type:o,min:i,disabled:s,size:"xs",fontSize:"16px",w:n,value:l,placeholder:r,color:c,borderWidth:0,_focusVisible:{boxShadow:"none",outline:"none"},borderRadius:"8px",onFocus:()=>{u.current=!1},onChange:p=>d(p.target.value),onBlur:h,onKeyDown:p=>{p.key==="Enter"&&(h(),p.target.blur()),p.key==="Escape"&&(u.current=!0,d(e),p.target.blur())}})}function Vr({colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:s,colorText:a}=at(),[c,l]=j.useState(!1),d=j.useId(),u=j.useRef(null),h=r??e[0]??"transparent",p=jo(f.jsx(Vr,{colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i}));return f.jsx(nn.Provider,{value:null,children:f.jsxs(V.HStack,{gap:1,"aria-label":t,role:"group",onClickCapture:p,onKeyDown:m=>{var g;m.key==="Escape"&&(l(!1),(g=u.current)==null||g.focus())},children:[f.jsx(Ge,{label:`${t}: ${h}`,children:f.jsx(V.chakra.button,{ref:u,type:"button","aria-label":`${t} colors`,"aria-expanded":c,"aria-controls":d,w:4,h:4,flexShrink:0,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Te(h),...h==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${Te(a)}`,outlineOffset:"1px",onClick:()=>l(m=>!m)})}),c&&f.jsxs(V.HStack,{id:d,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(m=>{const g=r===m;return f.jsx(Ge,{label:`${t}: ${m}`,children:f.jsx(V.Box,{as:"button","aria-label":`${t} ${m}`,"aria-pressed":g,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Te(m),...m==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:g?`2px solid ${Te(a)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>n(m),onDoubleClick:y=>{var b;y.stopPropagation(),l(!1),(b=u.current)==null||b.focus()}})},m)}),o&&f.jsx(Ge,{label:`Reset ${t.toLowerCase()}`,children:f.jsx(Ne,{"aria-label":`Reset ${t}`,icon:f.jsx(V.Icon,{as:ee.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:s,onClick:()=>{var m;o(),l(!1),(m=u.current)==null||m.focus()}})})]})]})})}function Ib({edgeId:e,onClose:r}){var p;const{callbacks:t,themeColor:n,config:o}=He(),{colorInactive:i}=at(),{edgeById:s}=Xt(),{palette:a,show:c}=Tb(),l=(p=s.get(e))==null?void 0:p.data,d=[...new Set(["rounded-orthogonal","orthogonal","straight","bezier",...Object.keys(o.customEdgeTypes??{}),...l!=null&&l.type?[l.type]:[]])],u=l!=null&&l.isEdgeAnimated?"animated":l!=null&&l.isEdgeDashed?"dashed":"solid",h=[{key:"solid",icon:ee.PiLineSegment,label:"Solid"},{key:"dashed",icon:ee.PiLineSegments,label:"Dashed"},{key:"animated",icon:ee.PiFastForward,label:"Animated"}];return f.jsxs(f.Fragment,{children:[f.jsx(dn,{onClick:r}),c("label")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Er,{ariaLabel:"Edge label",placeholder:"Edge label",value:(l==null?void 0:l.label)||"",onCommit:m=>{var g;return(g=t.onEdgeLabelChange)==null?void 0:g.call(t,e,m)}})]}),c("style")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),h.map(m=>f.jsx(Ge,{label:m.label,children:f.jsx(Ne,{"aria-label":`Edge style ${m.key}`,"aria-pressed":u===m.key,icon:f.jsx(V.Icon,{as:m.icon,boxSize:5}),size:"sm",variant:"ghost",color:u===m.key?n:i,onClick:()=>{var g;return(g=t.onEdgeStyleChange)==null?void 0:g.call(t,e,m.key)}})},m.key)),u==="animated"&&f.jsx(Rb,{label:"Edge animation",value:(l==null?void 0:l.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:o.readOnly,onChange:m=>{var g;return(g=t.onEdgeAnimationVariantChange)==null?void 0:g.call(t,e,m)}}),f.jsxs(It,{"aria-label":"Edge shape",title:`Edge shape: ${(l==null?void 0:l.type)??"Default"}`,icon:f.jsx(ee.PiBezierCurve,{size:20}),style:{width:36},value:(l==null?void 0:l.type)??"",disabled:o.readOnly,onValueChange:m=>{var g;return(g=t.onEdgeTypeChange)==null?void 0:g.call(t,e,m||void 0)},children:[f.jsx("option",{value:"",children:"Default"}),d.map(m=>f.jsx("option",{value:m,children:m},m))]})]}),c("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Gd,{edgeId:e,value:l==null?void 0:l.icon},e),f.jsx(Er,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(l==null?void 0:l.icon)??"",onCommit:m=>{var g;return(g=t.onEdgeIconChange)==null?void 0:g.call(t,e,m)}})]}),c("color")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Vr,{label:"Edge color",colors:a,value:l==null?void 0:l.color,onPick:m=>{var g;return(g=t.onEdgeColorChange)==null?void 0:g.call(t,e,m)},onReset:()=>{var m;return(m=t.onEdgeColorChange)==null?void 0:m.call(t,e,"")}})]}),c("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:"Delete edge",children:f.jsx(Ne,{"aria-label":"Delete edge",icon:f.jsx(V.Icon,{as:ee.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var m;(m=t.onEdgeDelete)==null||m.call(t,e,l),r()}})})]})]})}function Nb({ids:e,showDivider:r=!0}){const{callbacks:t,config:n,nodeGridOptions:o,fillRadiusEditedIds:i}=He(),{colorInactive:s}=at(),{nodeById:a}=Xt(),[c,l]=j.useState(!1),d=e.map(y=>{var b,x;return o!=null&&o.fill&&!i.has(y)?0:(x=(b=a.get(y))==null?void 0:b.data.viewProps)==null?void 0:x.borderRadius}),u=!d.every(y=>y===d[0]),h=u?"mixed":String(d[0]??""),p=["0","8","16","30","53","100"],m=c||!u&&h!==""&&!p.includes(h),g=y=>e.forEach(b=>{var x;return(x=t.onNodeBorderRadiusChange)==null?void 0:x.call(t,b,y)});return f.jsxs(f.Fragment,{children:[r&&f.jsx(Tt,{}),f.jsx(V.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:f.jsxs(It,{icon:f.jsx(V.Icon,{as:Tv.TbBorderRadius,boxSize:5,color:s,"aria-hidden":"true"}),"aria-label":"Node border radius",title:`Border radius: ${u?"Mixed":d[0]===void 0?"Default":`${d[0]}px`}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",cursor:"pointer"},value:m?"custom":h,disabled:n.readOnly,onValueChange:y=>{l(y==="custom"),y!=="custom"&&g(y===""?void 0:Number(y))},children:[f.jsx("option",{value:"",children:"Default radius"}),u&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed radii"}),p.map(y=>f.jsxs("option",{value:y,children:[y,"px radius"]},y)),f.jsx("option",{value:"custom",children:"Custom radius"})]})}),m&&f.jsx(Er,{ariaLabel:"Custom border radius",placeholder:u?"Mixed":"Auto",type:"number",min:0,width:"72px",value:u?"":h,onCommit:y=>g(y===""?void 0:Number(y))})]})}function Ob({ids:e,onClose:r,afterLabel:t}){var G,ce,te,X,ie,me,xe,fe;const{callbacks:n,colorMode:o,themeColor:i,config:s,setNodeViewMode:a}=He(),{colorText:c,colorInactive:l}=at(),{nodeById:d,parentIds:u}=Xt(),{palette:h,show:p}=Tb(),m=e.length===1,[g,y]=j.useState(""),b=m?(G=d.get(e[0]))==null?void 0:G.data:void 0,x=e.map(U=>{var re,de;return((de=(re=d.get(U))==null?void 0:re.data.config)==null?void 0:de.typeView)??""}),w=x.some(U=>U!==x[0]),v=w?"mixed":x[0]??"",C=[{value:"text",label:"Text",view:"text",icon:ee.PiTextT},{value:"icon-label",label:"Icon Label",view:"icon-label",icon:ee.PiShapes},{value:"object",label:"Object",view:"object",icon:ee.PiBracketsCurly},{value:"grid",label:"Grid",view:"grid",icon:ee.PiGridFour},{value:"parent",label:"Parent",view:"parent",icon:ee.PiStack},{value:"media",label:"Media",view:"icon-label",icon:ee.PiFileSvg},{value:"content",label:"Content",view:"object",icon:ee.PiTextAlignLeft},{value:"prompt",label:"Prompt",view:"prompt",icon:ee.PiTextAlignLeft}].filter(U=>U.view!=="prompt"||!!n.onPromptSubmit),S=e.some(U=>{var de,Pe;const re=(de=d.get(U))==null?void 0:de.data;return re&&(u.has(U)||((Pe=re.config)==null?void 0:Pe.parentContainer)||Object.prototype.hasOwnProperty.call(s.customViews??{},re.type))}),E=(ce=b==null?void 0:b.config)==null?void 0:ce.collapsed,R=Ab(e[0]),P=U=>{var re,de,Pe;return(((de=(re=d.get(U))==null?void 0:re.data.viewProps)==null?void 0:de.outline)??(u.has(U)?(Pe=s.parentNodeStyle)==null?void 0:Pe.outline:!1))===!0},I=e.every(P),M=!I&&e.some(P),k=U=>{var re;return((re=d.get(U))==null?void 0:re.data.isNodeAnimated)===!0},_=e.every(k),N=!_&&e.some(k),$=e.map(U=>{var re;return((re=d.get(U))==null?void 0:re.data.nodeAnimationVariant)??"traveling"}),D=$.every(U=>U===$[0])?$[0]:"",T=U=>e.forEach(U),[Z,K]=j.useState(!1),ne=Z&&p("color")&&p("borderColor"),se=U=>{var re,de,Pe;return(((de=(re=d.get(U))==null?void 0:re.data.viewProps)==null?void 0:de.borderStyle)??(u.has(U)?(Pe=s.parentNodeStyle)==null?void 0:Pe.borderStyle:"solid"))==="dashed"},W=e.every(se),ue=!W&&e.some(se),q=e.map(U=>{var Pe,ae,we;const re=(Pe=d.get(U))==null?void 0:Pe.data,de=u.has(U)?Dn((ae=s.parentNodeStyle)==null?void 0:ae.borderWidth,6):(re==null?void 0:re.type)==="objectView"?3:2;return Dn((we=re==null?void 0:re.viewProps)==null?void 0:we.borderWidth,de)}),F=q.every(U=>U===q[0])?String(q[0]??""):"",H=U=>T(re=>{var de,Pe;ne?(de=n.onNodeBorderColorChange)==null||de.call(n,re,U):(Pe=n.onNodeColorChange)==null||Pe.call(n,re,"bg",U)});return f.jsxs(f.Fragment,{children:[f.jsx(dn,{onClick:r}),f.jsx(Tt,{}),m&&p("label")?f.jsx(Er,{ariaLabel:"Node label",placeholder:"Node label",value:(b==null?void 0:b.label)??(b==null?void 0:b.headerTitle)??"",onCommit:U=>{var re;return(re=n.onNodeLabelChange)==null?void 0:re.call(n,e[0],U)}}):f.jsxs(V.Text,{fontSize:"xs",color:c,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),t,p("typeView")&&f.jsxs(It,{"aria-label":"Type view",title:S?"Type view is managed by the custom renderer or container":`Type view: ${v||"None (default)"}`,icon:f.jsx(ee.PiCards,{size:20}),style:{width:36},value:v,disabled:s.readOnly||s.editable===!1||S,onValueChange:U=>{var de;const re=(de=C.find(Pe=>Pe.value===U))==null?void 0:de.view;re&&T(Pe=>{var ae,we;(ae=n.onNodeTypeViewChange)==null||ae.call(n,Pe,re),a(Pe,"default"),(we=n.onNodeViewToggle)==null||we.call(n,Pe)})},children:[w&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),C.map(U=>f.jsx("option",{value:U.value,children:f.jsxs(V.HStack,{gap:"12px",children:[f.jsx(U.icon,{size:20,"aria-hidden":"true",style:{flexShrink:0}}),f.jsx("span",{children:U.label})]})},U.value))]}),p("style")&&f.jsx(Nb,{ids:e},e.join("\0")),p("outline")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:I?"Restore node fill":"Remove node fill",children:f.jsx(Ne,{"aria-label":"Toggle node outline","aria-pressed":M?"mixed":I,icon:f.jsx(V.Icon,{as:I?ee.PiSquare:ee.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:I?i:l,onClick:()=>T(U=>{var re;return(re=n.onNodeOutlineChange)==null?void 0:re.call(n,U,!I)})})})]}),p("color")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),p("borderColor")&&f.jsx(Ge,{label:ne?"Edit node colors":"Edit node border",children:f.jsx(Ne,{"aria-label":"Edit node border","aria-pressed":ne,icon:f.jsx(V.Icon,{as:ee.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:ne?i:l,bg:ne?o==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>K(U=>!U)})}),f.jsx(Vr,{label:ne?"Border color":"Background",colors:h,value:ne?((te=b==null?void 0:b.viewProps)==null?void 0:te.borderColor)??(m&&u.has(e[0])?(X=s.parentNodeStyle)==null?void 0:X.borderColor:void 0):(ie=b==null?void 0:b.viewProps)==null?void 0:ie.bgColor,onPick:H,onReset:()=>H("")}),ne&&p("style")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:W?"Solid border":"Dashed border",children:f.jsx(Ne,{"aria-label":"Toggle dashed border","aria-pressed":ue?"mixed":W,icon:f.jsx(V.Icon,{as:W?ee.PiLineSegments:ee.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:W?i:l,onClick:()=>T(U=>{var re;return(re=n.onNodeBorderStyleChange)==null?void 0:re.call(n,U,W?"solid":"dashed")})})}),f.jsx(Er,{ariaLabel:"Border thickness",placeholder:m?"Auto":"Mixed",width:"64px",type:"number",min:0,value:F,onCommit:U=>T(re=>{var de;return(de=n.onNodeBorderWidthChange)==null?void 0:de.call(n,re,U===""?void 0:Number(U))})})]})]}),p("animation")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:_?"Stop border animation":"Animate node border",children:f.jsx(Ne,{"aria-label":"Toggle node animation","aria-pressed":N?"mixed":_,icon:f.jsx(V.Icon,{as:ee.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:_?i:l,onClick:()=>T(U=>{var re;return(re=n.onNodeAnimationChange)==null?void 0:re.call(n,U,!_)})})}),(_||N)&&f.jsx(Rb,{label:"Node animation",value:D,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:s.readOnly,onChange:U=>T(re=>{var de;return(de=n.onNodeAnimationVariantChange)==null?void 0:de.call(n,re,U)})})]}),!ne&&p("textColor")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Vr,{label:"Text color",colors:Mb,value:(me=b==null?void 0:b.viewProps)==null?void 0:me.textColor,onPick:U=>T(re=>{var de;return(de=n.onNodeColorChange)==null?void 0:de.call(n,re,"text",U)}),onReset:()=>T(U=>{var re;return(re=n.onNodeColorChange)==null?void 0:re.call(n,U,"text","")})})]}),m&&p("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Gd,{nodeId:e[0],value:(xe=b==null?void 0:b.config)==null?void 0:xe.icon},e[0]),f.jsx(Er,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((fe=b==null?void 0:b.config)==null?void 0:fe.icon)||"",onCommit:U=>{var re;return(re=n.onNodeIconChange)==null?void 0:re.call(n,e[0],U)}})]}),m&&R&&p("collapse")&&E!==void 0&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:E?"Expand":"Collapse",children:f.jsx(Ne,{"aria-label":E?"Expand node":"Collapse node",icon:f.jsx(V.Icon,{as:E?ee.PiArrowsOutLineVertical:ee.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:l,onClick:()=>{var U;return(U=n.onNodeCollapse)==null?void 0:U.call(n,e[0],!E)}})})]}),p("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(Tt,{}),f.jsx(Ge,{label:m?"Delete node":`Delete ${e.length} nodes`,children:f.jsx(Ne,{"aria-label":"Delete selected nodes",icon:f.jsx(V.Icon,{as:ee.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:o==="dark"?"red.300":"red.500",onClick:()=>{T(U=>{var re,de;return(de=n.onNodeDelete)==null?void 0:de.call(n,U,((re=d.get(U))==null?void 0:re.data)||{id:U})}),r()}})})]}),f.jsx(Ge,{label:"Copy selection",children:f.jsx(Ne,{"aria-label":"Copy selection",icon:f.jsx(ee.PiCopy,{size:20}),size:"sm",variant:"ghost",color:l,onClick:async()=>{var U;try{await((U=n.onNodesCopy)==null?void 0:U.call(n,e)),y("")}catch(re){y(String(re))}}})}),f.jsx(Ge,{label:"Duplicate selection",children:f.jsx(Ne,{"aria-label":"Duplicate selection",icon:f.jsx(ee.PiCopySimple,{size:20}),size:"sm",variant:"ghost",color:l,disabled:s.readOnly||s.editable===!1,onClick:()=>{var U;try{(U=n.onNodesDuplicate)==null||U.call(n,e),y("")}catch(re){y(String(re))}}})}),g&&f.jsx(V.Text,{role:"alert",fontSize:"xs",children:g})]})}async function $b(e){const{toSvg:r}=await Promise.resolve().then(()=>require("./index-sHQXTNv9.cjs"));await document.fonts.ready;const t=await r(e,{filter:o=>!(o instanceof Element)||!o.matches("button, iframe, [role=tooltip], .flow-sdk-handle, .flow-sdk-property-port, .flow-sdk-edge-hit, .flow-sdk-ghost, .flow-sdk-node-animation")}),n=new DOMParser().parseFromString(decodeURIComponent(t.slice(t.indexOf(",")+1)),"image/svg+xml");return n.querySelectorAll(".flow-sdk-edge-hit, .flow-sdk-handle, .flow-sdk-property-port, .flow-sdk-ghost").forEach(o=>o.remove()),n.querySelectorAll("[data-flow-preview-source]").forEach(o=>{o.setAttribute("style","display:block;white-space:pre-wrap;font:16px/1.5 monospace;overflow-wrap:anywhere")}),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(n))}`}async function qb(e,r="squeed.svg"){const t=document.createElement("a");t.href=await $b(e),t.download=r.endsWith(".svg")?r:`${r}.svg`,t.click()}function Lb(){const{themeColor:e}=He(),[r,t]=j.useState(!1),[n,o]=j.useState("");return f.jsxs(f.Fragment,{children:[f.jsx(Ge,{label:"Download SVG (current view)",children:f.jsx(Ne,{"aria-label":"Download SVG",icon:f.jsx(ee.PiDownloadSimpleFill,{size:20}),disabled:r,borderRadius:"30%",color:e,variant:"ghost",onClick:async i=>{var a;const s=(a=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:a.querySelector("[data-flow-background]");if(!s){o("Diagram not available for export.");return}t(!0),o("");try{await qb(s)}catch(c){o(c instanceof Error?c.message:"Unable to export SVG.")}finally{t(!1)}}})}),n&&f.jsx("span",{role:"alert",style:{fontSize:12,maxWidth:220},children:n})]})}function ko({children:e,background:r,border:t,endElement:n,startElement:o,startElementWidth:i=44,framed:s=!0}){const a=j.useRef(null),c=j.useRef(null),[l,d]=j.useState(i);j.useLayoutEffect(()=>{const g=c.current;if(!o||!g)return;const y=()=>{const x=Math.ceil(g.getBoundingClientRect().width)+18;d(w=>Math.abs(w-x)>1?x:w)};y();const b=new ResizeObserver(y);return b.observe(g),()=>b.disconnect()},[o]);const u=o?l:0,[h,p]=j.useState({left:!1,right:!1});j.useLayoutEffect(()=>{const g=a.current;let y=g.parentElement.offsetWidth;const b=()=>{const v=g.parentElement.offsetWidth;if(v>0&&v!==y){const E=y/v;y=v,E>0&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches&&g.parentElement.animate({transform:[`scaleX(${E})`,"scaleX(1)"],transformOrigin:[n?"right center":"left center",n?"right center":"left center"]},{duration:180,easing:"ease-out",id:"flow-toolbar-grow"})}const C=g.scrollLeft>1,S=g.scrollWidth-g.clientWidth-g.scrollLeft>1;p(E=>E.left===C&&E.right===S?E:{left:C,right:S})},x=v=>{const C=v.target instanceof Element?v.target:null;if((C==null?void 0:C.closest("[data-flow-toolbar-scroll]"))!==g||C.closest("[popover], [data-flow-floating-panel]")!==g.closest("[popover], [data-flow-floating-panel]")||v.defaultPrevented||v.ctrlKey||s&&v.deltaX!==0||!(v.deltaX||v.deltaY)||g.scrollWidth<=g.clientWidth)return;v.preventDefault();const S=v.deltaMode===WheelEvent.DOM_DELTA_LINE?16:v.deltaMode===WheelEvent.DOM_DELTA_PAGE?g.clientWidth:1;g.scrollLeft+=(v.deltaX||v.deltaY)*S},w=new ResizeObserver(b);return w.observe(g),g.firstElementChild&&w.observe(g.firstElementChild),g.addEventListener("scroll",b,{passive:!0}),g.addEventListener("wheel",x,{passive:!1}),b(),()=>{w.disconnect(),g.removeEventListener("scroll",b),g.removeEventListener("wheel",x)}},[]);const m=`var(--chakra-colors-${r.replace(".","-")})`;return f.jsxs(V.Box,{position:"relative",bg:s?r:"transparent",minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:s?"30px":0,css:{...s?gr(m,`var(--chakra-colors-${t.replace(".","-")})`):{},...s||o?{"--flow-toolbar-start-width":o?`${u}px`:"0px"}:{}},children:[f.jsx(V.Box,{ref:a,"data-flow-toolbar-scroll":"",h:50,minH:50,alignContent:"center",overflowX:"auto",overflowY:"hidden",mr:n?"44px":void 0,ml:o?`${u}px`:void 0,borderRadius:"inherit",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e}),["left","right"].map(g=>f.jsx(V.Box,{"data-flow-toolbar-fade":g,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",zIndex:2,borderRadius:g==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[g]:g==="right"&&n?44:g==="left"&&o?u:0,opacity:h[g]?1:0,background:`linear-gradient(to ${g==="left"?"right":"left"}, ${m}, transparent)`}},g)),n&&f.jsx(V.Box,{position:"absolute",right:"6px",top:0,h:"50px",w:"32px",display:"flex",alignItems:"center",justifyContent:"center",background:m,borderRadius:s?"0 30px 30px 0":void 0,zIndex:1,children:n}),o&&f.jsx(V.Box,{ref:c,position:"absolute",left:"6px",top:0,h:"50px",w:"max-content",display:"flex",alignItems:"center",justifyContent:"center",background:m,borderRadius:s?"30px 0 0 30px":void 0,zIndex:1,children:o})]})}async function Uw(e,r){const t=new Set,n=[],o=(a,c)=>{var d,u,h;if(!a||typeof a!="object")return;const l=a;n.push(c),typeof((d=l.$form)==null?void 0:d.$type)=="string"&&t.add(l.$form.$type),typeof((h=(u=l.$form)==null?void 0:u.$create)==null?void 0:h.$type)=="string"&&t.add(l.$form.$create.$type);for(const[p,m]of Object.entries(l))p==="$"?o(m,c):p.startsWith("$")||o(m,`${c}.${p}`)};if(o(r,"root"),!t.size)return{contract:await Eb(e)};const i=await Wd(e,[...t]);for(const a of t)if(!Object.prototype.hasOwnProperty.call(i,a))throw new Error(`Missing form type: ${a}`);const s={};for(const a of n){const c=un(r,a,i);c&&(s[a]={type:c.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:s}}}function Fb({message:e,onDismiss:r}){const{background:t,colorText:n,border:o}=at();return!e||typeof document>"u"?null:Wr.createPortal(f.jsxs(V.chakra.div,{role:"alert","aria-atomic":"true",css:gr(Te(t),Te(o)),onPointerDown:i=>i.stopPropagation(),onClick:i=>i.stopPropagation(),style:{position:"fixed",top:20,right:20,zIndex:1e4,width:360,maxWidth:"calc(100vw - 40px)",boxSizing:"border-box",display:"flex",alignItems:"flex-start",gap:10,padding:16,borderRadius:8,background:Te(t),color:Te(n),fontSize:14,lineHeight:1.5},children:[f.jsx(ee.PiWarningCircle,{size:20,"aria-hidden":"true",style:{flexShrink:0,color:"#ef4444"}}),f.jsxs("div",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:[f.jsx("strong",{children:"Interface upload failed"}),f.jsx("div",{children:e})]}),f.jsx(dn,{type:"button","aria-label":"Dismiss upload error",title:"Dismiss upload error",onClick:r,flexShrink:0,width:"24px",height:"24px",minWidth:"24px",padding:0})]}),document.body)}function Hd({showDivider:e=!0,compact:r=!1}={}){const{edgeMode:t,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:s,readOnly:a,themeColor:c,colorMode:l}=He(),{edgeById:d}=Xt(),{data:u,schema:h,setSchema:p,bindings:m,structured:g}=j.useContext($t),y=(g==null?void 0:g.sourceBindings)??m,b=(g==null?void 0:g.sourceSchema)??h,{colorText:x}=at(),w=j.useRef(null),v=j.useRef(0),[C,S]=j.useState(!1),[E,R]=j.useState("");j.useEffect(()=>()=>{v.current++},[]),j.useEffect(()=>{v.current++,S(!1)},[a,u,y]);const P=o?[...d.values()].filter(k=>Dd(o,k.data)).length:0,I=o?`${o.name}: ${b?`${Object.keys(b).length} form types loaded; `:""}${P} invalid or unverified connections`:"",M=jo(f.jsx(Hd,{showDivider:!1,compact:!0}));return f.jsx(nn.Provider,{value:null,children:f.jsxs("span",{style:{display:"contents"},onClickCapture:M,children:[f.jsx(Fb,{message:E,onDismiss:()=>R("")}),e&&f.jsx(Nn,{}),f.jsxs(It,{"aria-label":"Edge mode",title:t==="auto"?"Connections: Auto":t==="properties"?"Connections: Properties":"Connections: Nodes",icon:t==="auto"?f.jsx(ee.PiGraph,{size:20}):t==="properties"?f.jsx(ee.PiTable,{size:20}):f.jsx(ee.PiTreeStructure,{size:20}),style:{width:36},value:t,disabled:a,footer:s.onWorkflowConfigurationOpen&&f.jsxs(f.Fragment,{children:[f.jsx("hr",{style:{border:0,borderTop:"1px solid currentColor",opacity:.2,margin:"8px 0"}}),f.jsxs(V.Button,{"data-flow-menu-action":"",variant:"ghost",width:"100%",justifyContent:"flex-start",color:"inherit",bg:"transparent",css:ho,_hover:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},onClick:k=>{var _,N;(_=k.currentTarget.closest("[popover]"))==null||_.hidePopover(),(N=s.onWorkflowConfigurationOpen)==null||N.call(s)},children:[f.jsx(ee.PiGear,{}),"Configuration"]})]}),onValueChange:k=>{var N;const _=k==="auto"?"auto":k==="properties"?"properties":"nodes";n(_),(N=s.onEdgeModeChange)==null||N.call(s,_)},children:[f.jsx("option",{value:"auto",children:"Auto"}),f.jsx("option",{value:"nodes",children:"Nodes"}),f.jsx("option",{value:"properties",children:"Properties"})]}),f.jsxs("span",{style:{display:t==="auto"||t==="properties"?"contents":"none"},children:[f.jsx(Ge,{label:o?`Replace ${o.name}`:"Upload workflow interface",children:f.jsx(Ne,{"aria-label":"Upload workflow interface",icon:f.jsx(ee.PiUploadSimple,{size:20}),color:Te(c),size:"sm",variant:"ghost",disabled:C||a,onClick:()=>{var k;return(k=w.current)==null?void 0:k.click()}})}),f.jsx("input",{ref:w,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:a||C,onChange:async k=>{var $,D;const _=($=k.target.files)==null?void 0:$[0];if(k.target.value="",!_)return;const N=++v.current;S(!0),R("");try{const T=y?await Wd(_,[...new Set(Object.values(y).map(ne=>ne.schemaType??ne.type))]):void 0;if(y&&T){for(const ne of Object.values(y))if(!Object.prototype.hasOwnProperty.call(T,ne.schemaType??ne.type))throw new Error(`Missing form type: ${ne.schemaType??ne.type}`)}const{contract:Z,schema:K}=y&&T?{schema:T,contract:{name:_.name,nodes:Object.fromEntries(Object.entries(y).map(([ne,se])=>[ne,{type:T[se.schemaType??se.type],optional:!1}]))}}:await Uw(_,u);if(N!==v.current)return;p==null||p(K),i(Z),(D=s.onWorkflowContractChange)==null||D.call(s,Z)}catch(T){N===v.current&&R(`${_.name}: ${T instanceof Error?T.message:"Unable to load interface."}`)}finally{N===v.current&&S(!1)}}}),!r&&(I||C)&&f.jsx("span",{role:"status",title:I,style:{color:Te(x),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:C?"Loading interface...":I}),!r&&o&&f.jsx(Ge,{label:"Remove workflow interface",children:f.jsx(Ne,{"aria-label":"Remove workflow interface",icon:f.jsx(ee.PiX,{size:16}),size:"sm",variant:"ghost",disabled:a||C,onClick:()=>{var k;p==null||p(void 0),i(void 0),(k=s.onWorkflowContractChange)==null||k.call(s,void 0),R("")}})})]})]})})}const Kw=[{value:"BT",label:"Bottom to Up",icon:ee.PiArrowUp,flowType:Sn.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:ee.PiArrowDown,flowType:Sn.TOP_DOWN},{value:"LR",label:"Left to Right",icon:ee.PiArrowRight,flowType:Sn.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:ee.PiArrowLeft,flowType:Sn.RIGHT_LEFT}],zb=({nodeGridControlsTarget:e}={})=>{const{engineRef:r,themeColor:t,setThemeColor:n,edgeColor:o,setEdgeColor:i,backgroundSelected:s,setBackgroundSelected:a,direction:c,edgeMode:l,allNodesIconLabel:d,setAllNodesIconLabel:u,nodeGridOptions:h,selectedNodeIds:p,setSelectedNodeIds:m,selectedEdgeId:g,setSelectedEdgeId:y,isZoomMode:b,setIsZoomMode:x,isMultiSelectMode:w,setIsMultiSelectMode:v,isDragMode:C,setIsDragMode:S,isEdgeHandlesEnabled:E,setIsEdgeHandlesEnabled:R,isArrayNodeMode:P,setIsArrayNodeMode:I,isPinned:M,setIsPinned:k,callbacks:_,config:N,readOnly:$}=He(),{nodeById:D,edgeById:T,parentIds:Z}=Xt(),K=N.colorMode==="dark",{background:ne,border:se,colorInactive:W,colorText:ue,colorActive:q}=at(),F=K?se:"gray.300",H=`var(--chakra-colors-${ne.replace(".","-")})`,G=`var(--chakra-colors-${(K?se:"gray.300").replace(".","-")})`,[ce,te]=j.useState(!1),[X,ie]=j.useState(!0),me=N.bottomBarCollapsed??X,xe=j.useRef(null),fe=So({edge:"bottom",enabled:!M,bounds:xe,inside:[xe]}),U=j.useCallback(Re=>{const Ke=r.current;if(!Ke)return;const lt=N.minZoom??.01,Je=N.maxZoom??1.5,mt=.02;let At=Ke.zoom();switch(Re){case"increase":At=Math.min(Je,At+mt),Ke.zoom(At),Ke.center(!1);break;case"decrease":At=Math.max(lt,At-mt),Ke.zoom(At),Ke.center(!1);break;case"reset":Ke.fit(50);break}},[r,N.minZoom,N.maxZoom]),re=N.renderSelectedNodeToolbar,de=p.length>0&&!!re,Pe=j.useMemo(()=>de?p.map(Re=>{var lt;return{...((lt=D.get(Re))==null?void 0:lt.data)??{id:Re},isParent:Z.has(Re)}}):[],[de,p,D,Z]),ae=j.useCallback(()=>{var Re;m([]),(Re=_.onNodeDeselect)==null||Re.call(_)},[m,_]),we=N.renderSelectedEdgeToolbar,$e=!!g&&!!we,Ue=j.useMemo(()=>{var Re;return!$e||!g?null:((Re=T.get(g))==null?void 0:Re.data)??{id:g}},[$e,g,T]),Ve=j.useCallback(()=>{var Re;y(null),(Re=_.onEdgeDeselect)==null||Re.call(_)},[y,_]),tt=N.selectionToolbar!==!1&&!$,ge=tt&&!!g&&!we,Ae=tt&&!ge&&p.length>0&&!re,Le=ge||Ae,be=M||fe||ce||Le||N.bottomBarCollapsed===!1;j.useEffect(()=>{p.length||g?a(!1):$||(s&&k(!0),N.bottomBarCollapsed===void 0&&ie(!s))},[s,p.length,g,$,a,k,N.bottomBarCollapsed]);const Xe=N.renderBottomBar,ut=Iw();return Xe?f.jsxs(f.Fragment,{children:[de&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:re({selectedNodeIds:p,selectedNodeData:Pe,onDeselect:ae})}),$e&&Ue&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:we({edgeId:g,edgeData:Ue,onDeselect:Ve})}),f.jsx(V.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:Xe({zoomIn:()=>U("increase"),zoomOut:()=>U("decrease"),resetZoom:()=>U("reset"),direction:c,isZoomMode:b,setIsZoomMode:x,isMultiSelectMode:w,setIsMultiSelectMode:v,isDragMode:C,setIsDragMode:S,isEdgeHandlesEnabled:E,setIsEdgeHandlesEnabled:R,isArrayNodeMode:P,setIsArrayNodeMode:I,selectedNodeIds:p,selectedNodeData:Pe,selectedEdgeId:g,selectedEdgeData:Ue,onNodeDeselect:ae,onEdgeDeselect:Ve,callbacks:_})})]}):f.jsxs(nn.Provider,{value:ut,children:[de&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:re({selectedNodeIds:p,selectedNodeData:Pe,onDeselect:ae})}),$e&&Ue&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:we({edgeId:g,edgeData:Ue,onDeselect:Ve})}),f.jsx(V.Box,{ref:xe,role:"toolbar","aria-label":"Diagram controls",position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",transition:"opacity 0.3s ease-in, transform 0.3s ease",transform:be?"translateY(0)":"translateY(100%)",pointerEvents:be?"auto":"none",visibility:be?"visible":"hidden",opacity:be?1:0,css:{"& button > svg:not([popover] *)":{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",flexShrink:0},"@media (hover: none)":{visibility:"visible",opacity:1,transform:"none",pointerEvents:"auto"}},children:f.jsxs(V.Flex,{w:"100%",px:5,position:"absolute",bottom:"calc(20px + env(safe-area-inset-bottom, 0px))",flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:"24px",css:{"@media (min-width: 1024px)":{"& > :first-of-type":{maxWidth:"50vw"}}},children:[f.jsx(ko,{background:ne,border:K?se:"gray.300",children:f.jsxs(V.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[ge?f.jsx(Ib,{edgeId:g,onClose:Ve}):Ae?f.jsx(Ob,{ids:p,onClose:ae}):null,f.jsxs("div",{style:{display:ge||Ae?"none":"contents"},children:[f.jsxs("span",{style:{display:N.bottomBarNavigation===!1?"none":"contents"},children:[f.jsx(Ge,{label:M?"Unpin":"Pin",children:f.jsx(Ne,{"aria-label":"Pin",icon:f.jsx(V.Icon,{as:M?ee.PiPushPinFill:ee.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:M?t:W,onClick:()=>{k(!M),te(!1)}})}),f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Ge,{label:"Zoom Out",children:f.jsx(Ne,{"aria-label":"Zoom out",rememberAction:!1,icon:f.jsx(V.Icon,{as:ee.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:ue,onClick:()=>U("decrease")})}),f.jsx(Ge,{label:"Zoom In",children:f.jsx(Ne,{"aria-label":"Zoom in",rememberAction:!1,icon:f.jsx(V.Icon,{as:ee.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:ue,onClick:()=>U("increase")})}),f.jsx(Ge,{label:"Reset Zoom",children:f.jsx(Ne,{"aria-label":"Reset zoom",rememberAction:!1,icon:f.jsx(V.Icon,{as:ee.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:ue,onClick:()=>U("reset")})}),me&&f.jsx(Nw,{visibleActions:h?["Collision mode","Fill",...h.fill?["Grid adjustment"]:[]]:[],divider:f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"})})]}),f.jsxs("span",{style:{display:me?"none":"contents"},children:[f.jsxs("span",{style:{display:N.bottomBarNavigation===!1?"none":"contents"},children:[N.edgeHandles!==!1&&f.jsx(Ge,{label:E?"Draw Mode On (V)":"Draw Mode Off (V)",children:f.jsx(Ne,{"aria-label":"Toggle draw mode","aria-keyshortcuts":"V","aria-pressed":E,icon:f.jsx(V.Icon,{as:ee.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:E?t:W,onClick:()=>R(!E)})}),f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Ge,{label:b?"Zoom Mode (z)":"Pan Mode (z)",children:f.jsx(Ne,{"aria-label":"Toggle zoom mode",icon:f.jsx(V.Icon,{as:b?ee.PiMagnifyingGlassPlus:ee.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:b?t:W,onClick:()=>x(!b)})}),f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Ge,{label:w?"Multi-Select On (m)":"Multi-Select Off (m)",children:f.jsx(Ne,{"aria-label":"Toggle multi-select",icon:f.jsx(V.Icon,{as:ee.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:w?t:W,onClick:()=>v(!w)})}),f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Ge,{label:C?"Drag Mode On (d)":"Drag Mode Off (d)",children:f.jsx(Ne,{"aria-label":"Toggle drag mode",icon:f.jsx(V.Icon,{as:ee.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:C?t:W,onClick:()=>S(!C)})})]}),N.bottomBarNavigation===!1&&(e===void 0?f.jsx(so,{}):e?Wr.createPortal(f.jsx(so,{}),e):null),N.bottomBarExtra&&f.jsxs(f.Fragment,{children:[N.bottomBarNavigation!==!1&&f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),N.bottomBarExtra]}),f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),f.jsx(wb,{})]}),f.jsx("span",{style:{display:N.bottomBarNavigation===!1||me&&!h?"none":"contents"},children:f.jsx(so,{})}),f.jsxs("span",{style:{display:me?"none":"contents"},children:[f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),f.jsx(vb,{}),l!=="properties"&&f.jsxs(f.Fragment,{children:[f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Ge,{label:P?"Array Mode [ ]":"Set Mode { }",children:f.jsx(Ne,{"aria-label":"Toggle array mode",icon:f.jsx(V.Icon,{as:P?ee.PiBracketsSquare:ee.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:P?t:W,onClick:()=>{var Ke;const Re=!P;I(Re),(Ke=_.onArrayModeChange)==null||Ke.call(_,Re)}})})]}),f.jsx(Hd,{}),!$&&f.jsxs("span",{style:{display:s?"contents":"none"},children:[f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Vr,{label:"Graph theme",colors:po,value:t,includeTransparent:!1,onPick:Re=>{var Ke;n(Re),(Ke=_.onThemeColorChange)==null||Ke.call(_,Re)}})]}),!$&&f.jsxs(f.Fragment,{children:[f.jsx(V.Icon,{as:ee.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),f.jsx(Vr,{label:"Graph edge color",colors:po,value:o||(K?"gray.500":ln),onPick:i,onReset:()=>i("")}),f.jsx(V.Icon,{as:ee.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"})]}),f.jsx(Cb,{})]}),f.jsx(V.Icon,{mx:-1,as:ee.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Ge,{label:me?"Expand toolbar":"Collapse toolbar",children:f.jsx(Ne,{"aria-label":"Toggle toolbar collapse",rememberAction:!1,icon:f.jsx(V.Icon,{as:me?ee.PiCaretRight:ee.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:W,onClick:()=>{var Re;N.bottomBarCollapsed===void 0&&ie(!me),a(me),(Re=_.onBottomBarCollapsedChange)==null||Re.call(_,!me)}})}),!me&&f.jsx(Lb,{})]})]})}),!Le&&f.jsxs(V.Box,{position:"relative",ml:"auto",flexShrink:0,children:[f.jsx(V.Box,{"data-flow-direction-control":"",bg:ne,borderRadius:"30px",h:50,css:gr(H,G),px:3,cursor:"pointer",onClick:()=>te(!ce),children:f.jsxs(V.Flex,{align:"center",h:"100%",children:[f.jsx(Ge,{label:"Flow Direction",children:f.jsx(Ne,{"aria-label":"Direction",onClick:Re=>{Re.stopPropagation(),te(!ce)},icon:f.jsx(V.Icon,{as:ee.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:W})}),f.jsx(V.Text,{fontSize:"xs",textTransform:"uppercase !important",color:K?"whiteAlpha.600":"blackAlpha.500",ml:1,children:c.toUpperCase()})]})}),ce&&f.jsx(V.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:f.jsxs(V.Box,{bg:ne,borderRadius:"30px",p:2,minW:"180px",css:gr(H,G),children:[Kw.map(Re=>f.jsxs(V.Flex,{align:"center",gap:3,px:3,py:2,css:ho,cursor:"pointer",_hover:{bg:K?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ke;(Ke=_.onDirectionChange)==null||Ke.call(_,Re.value),te(!1)},children:[f.jsx(V.Icon,{as:Re.icon,boxSize:5,color:ue}),f.jsx(V.Text,{fontSize:"sm",color:ue,flex:1,whiteSpace:"nowrap",children:Re.label}),c===Re.value&&f.jsx(V.Icon,{as:ee.PiCheck,boxSize:4,color:q})]},Re.value)),f.jsxs(V.Flex,{align:"center",gap:3,px:3,py:2,css:ho,cursor:"pointer",_hover:{bg:K?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Re;(Re=_.onDirectionChange)==null||Re.call(_,"C"),te(!1)},children:[f.jsx(V.Icon,{as:ee.PiAlignCenterHorizontal,boxSize:5,color:ue}),f.jsx(V.Text,{fontSize:"sm",color:ue,flex:1,whiteSpace:"nowrap",children:"Center"}),c==="C"&&f.jsx(V.Icon,{as:ee.PiCheck,boxSize:4,color:q})]})]})})]})]})})]})};zb.displayName="BottomBar";const Bb=j.memo(zb);function Jw({checked:e,onChange:r,disabled:t,label:n="Connected nodes"}){return f.jsx(on,{hideLabel:!0,label:n,helper:`${n}: isolate node and its connections`,checked:e,onChange:r,disabled:t,icon:f.jsx(V.Icon,{as:ee.PiGraph,boxSize:5})})}const Ju={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function Db(e,r){const t=new Map,n=(i,s)=>{if(Object.is(i,s))return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const a=Object.keys(i);return a.length===Object.keys(s).length&&a.every(c=>Object.prototype.hasOwnProperty.call(s,c)&&n(i[c],s[c]))},o=(i,s,a)=>{if(i===s)return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const c=new Set([...Object.keys(i),...Object.keys(s)]);for(const l of c)if(!n(i[l],s[l])){if(Object.prototype.hasOwnProperty.call(Ju,l)){if(typeof s[l]!="string"||!s[l])return!1;t.set(a,{...t.get(a),[Ju[l]]:s[l]})}else if(l.startsWith("$")&&l!=="$"||!o(i[l],s[l],l==="$"?a:`${a}.${l}`))return!1}return!0};if(o(e,r,"root"))return t}function Zw(e,r){return Db(e,r)!==void 0}function Xw(e,r,t){if(e===r)return t;const n=Db(e,r);if(!n)return;const o=new Set(t.nodes.map(i=>i.data.id));for(const i of n.keys())if(!o.has(i)||!Oe(r,i))return;return{edges:t.edges,nodes:t.nodes.map(i=>{const s=n.get(i.data.id),a=Oe(e,i.data.id),c=Oe(r,i.data.id);return!s&&a===c?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(c,null,2)}:{},...s?{viewProps:{...i.data.viewProps,...s},config:{...i.data.config,...s}}:{}}}})}}function _d(e){return e.kind==="literal"?e.value:e.kind==="union"?_d(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,r])=>!r.optional).map(([r,t])=>[r,_d(t.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Wb(e,r,t){var y,b,x;const n=(y=Oe(e,r))==null?void 0:y.$form,o=n==null?void 0:n.$create;if(!o)return;const i=o.$address.split(".");if(i.shift()!=="root"||!i.length||i.some(w=>!/^[A-Za-z0-9_-]+$/.test(w)||["__proto__","constructor","prototype"].includes(w)))throw new Error("Invalid form creation address.");if(!t||!Object.prototype.hasOwnProperty.call(t,o.$type))throw new Error(`Load form type: ${o.$type}`);const s=i.pop(),a=["root",...i].join("."),c=un(e,a,t),l=(b=c==null?void 0:c.type.properties[s])==null?void 0:b.type;if((l==null?void 0:l.kind)!=="array"||l.items.kind!=="object")throw new Error("Form creation must target an object-array field.");const d=t[o.$type],u=o.$defaults??{};for(const[w,v]of Object.entries(u))if(!Object.prototype.hasOwnProperty.call(d.properties,w)||Jt(d.properties[w].type,v,!d.properties[w].optional))throw new Error(`Invalid creation default: ${w}`);const h={..._d(d),...structuredClone(u)};((x=d.properties.id)==null?void 0:x.type.kind)==="string"&&(h.id=Td());let p=e;const m=Oe(e,o.$address);if(m===void 0)p=Pt(e,a,w=>({...w,[s]:[]}));else if(!Array.isArray(m)&&!Array.isArray(m==null?void 0:m.$))throw new Error("Form creation destination is not an array.");const g=$d(p,o.$address,{...h,$label:o.$label??o.$type,...o.$icon?{$icon:o.$icon}:{},$form:{$type:o.$type,$create:o}});return{address:g.address,json:qd(g.json,r,{target:g.address,label:o.$edgeLabel})}}function Yw(e,r,t){var i,s;if(Array.isArray(r)){const a=new Set(r);if(!Oe(e,t)||[...a].some(u=>u==="root"||!Oe(e,u)))throw new Error("The source or Parent no longer exists.");const c=new Set;let l=t;for(;l;){if(c.has(l)||[...a].some(h=>l===h||l.startsWith(`${h}.`)))throw new Error("A node cannot be moved inside itself or its descendants.");c.add(l);const u=(i=Oe(e,l))==null?void 0:i.$parent;l=typeof u=="string"?u:l.includes(".")?l.slice(0,l.lastIndexOf(".")):void 0}const d=(u,h)=>{let p=u;const m=(g,y)=>{p===u&&(p=Array.isArray(u)?[...u]:{...u}),p[g]=y};if(u&&typeof u=="object")for(const[g,y]of Object.entries(u)){if(g.startsWith("$")&&g!=="$")continue;const b=d(y,g==="$"?h:`${h}.${g}`);b!==y&&m(g,b)}return a.has(h)&&(p={...p&&typeof p=="object"&&!Array.isArray(p)?p:{$:p},$parent:t}),p};return uo(d(e,"root"),t,!1)}if(r=r,r==="root"||!Oe(e,r)||!Oe(e,t))throw new Error("The source or Parent no longer exists.");const n=new Set;let o=t;for(;o;){if(o===r||o.startsWith(`${r}.`)||n.has(o))throw new Error("A node cannot be moved inside itself or its descendants.");n.add(o);const a=(s=Oe(e,o))==null?void 0:s.$parent;o=typeof a=="string"?a:o.includes(".")?o.slice(0,o.lastIndexOf(".")):void 0}return uo(Pt(e,r,a=>({...a,$parent:t})),t,!1)}function Vb(e,r){const t=new Set(r.filter(a=>Oe(e,a)!==void 0)),n=[],o=(a,c)=>{if(!(!a||typeof a!="object")){n.push([c,a]);for(const[l,d]of Object.entries(a))l.startsWith("$")||o(d,`${c}.${l}`)}};o(e,"root");const i=a=>[...t].some(c=>a===c||a.startsWith(`${c}.`));let s=!0;for(;s;){s=!1;for(const[a,c]of n)!i(a)&&typeof c.$parent=="string"&&i(c.$parent)&&(t.add(a),s=!0)}return[...t].filter(a=>![...t].some(c=>c!==a&&a.startsWith(`${c}.`)))}function Ud(e,r){const t=Vb(e,r),n=new Map(t.map((a,c)=>[a,`root.node_${c+1}`])),o=a=>{const c=t.find(l=>a===l||a.startsWith(`${l}.`));return c?`${n.get(c)}${a.slice(c.length)}`:void 0},i=a=>{if(!(!a||typeof a!="object")){Array.isArray(a.$connections)&&(a.$connections=a.$connections.flatMap(c=>{const l=typeof c.target=="string"&&o(c.target);return l?[{...c,id:void 0,target:l}]:[]}));for(const c of["$parent","$target"])if(typeof a[c]=="string"){const l=o(a[c]);l?a[c]=l:delete a[c]}for(const[c,l]of Object.entries(a))c.startsWith("$")||i(l)}},s={$hideRoot:!0};return t.forEach((a,c)=>{const l=structuredClone(Oe(e,a));i(l),s[`node_${c+1}`]=l}),s}function Gb(e,r){const t=Ud(e,r),n=Object.keys(t).filter(a=>!a.startsWith("$")),o=new Map(n.map(a=>[a,`copy_${crypto.randomUUID()}`])),i=a=>{if(!a||typeof a!="object")return;const c=l=>{const d=l.split(".");return d[0]==="root"&&o.has(d[1])&&(d[1]=o.get(d[1])),d.join(".")};for(const l of a.$connections??[])l.target=c(l.target),l.id=crypto.randomUUID();for(const l of["$parent","$target"])typeof a[l]=="string"&&(a[l]=c(a[l]));for(const[l,d]of Object.entries(a))l.startsWith("$")||i(d)},s=Object.fromEntries(n.map(a=>{const c=t[a];return i(c),[o.get(a),c]}));return{json:Pt(e,"root",a=>({...a,...s})),ids:[...o.values()].map(a=>`root.${a}`)}}function Qw(e,r){const t=o=>e&&typeof e=="object"&&o in e;let n=1;for(;t(`${r}_${n}`);)n++;return`${r}_${n}`}function Hb(e,r,t,n,o){const i=(a,c)=>{var h;if(a===e)return;const l=c.type.startsWith("node")&&c.type!=="nodeDelete",d=c.nodeAddresses??(l&&c.address?[c.address]:[]),u=d.length?(h=t.getNodeEditMetadata)==null?void 0:h.call(t):void 0;for(const p of d)JSON.stringify(Oe(a,p))!==JSON.stringify(Oe(e,p))&&(a=cb(a,p,u));e=a,n==null||n(a,c)},s=a=>{var l;const c=(l=r.find(d=>d.data.id===a))==null?void 0:l.data;return c&&{source:c.source,target:c.target,isInverted:c.isInverted,sourceProperty:c.sourceProperty,targetProperty:c.targetProperty,connection:c.connection}};return{...t,onNodesCopy:async a=>{var c;await((c=t.onNodesCopy)==null?void 0:c.call(t,a))!==!0&&await navigator.clipboard.writeText(JSON.stringify(Ud(e,a),null,2))},onNodesDuplicate:a=>{var l;if(((l=t.onNodesDuplicate)==null?void 0:l.call(t,a))===!0)return;const c=Gb(e,a);i(c.json,{type:"nodeCreate",address:c.ids[0],nodeAddresses:c.ids})},onFormChange:a=>{const c=Oe(e,a.nodeAddress);if(!c||a.nodeId!==void 0&&c.id!==a.nodeId)throw new Error("This form node has moved. Retry the edit.");i(_o(e,a,t.onFormChange),{type:"form",address:a.address,nodeAddresses:[a.nodeAddress],value:a.value})},onNodeLabelChange:(a,c)=>{var l;(l=t.onNodeLabelChange)==null||l.call(t,a,c),i(jt(e,a,"$label",c),{type:"nodeLabel",address:a,key:"$label",value:c})},onNodeContentChange:(a,c)=>{var l;(l=t.onNodeContentChange)==null||l.call(t,a,c),i(jt(e,a,"$content",c),{type:"nodeContent",address:a,key:"$content",value:c})},onNodeContentFormatChange:(a,c)=>{var l;["markdown","html","jsx"].includes(c)&&((l=t.onNodeContentFormatChange)==null||l.call(t,a,c),i(jt(e,a,"$contentFormat",c),{type:"nodeStyle",address:a,key:"$contentFormat",value:c}))},onNodeTypeViewChange:(a,c)=>{var l;c!==void 0&&!Ld.includes(c)||((l=t.onNodeTypeViewChange)==null||l.call(t,a,c),i(jt(e,a,"$view",c),{type:"nodeStyle",address:a,key:"$view",value:c}))},onNodeColorChange:(a,c,l)=>{var u;(u=t.onNodeColorChange)==null||u.call(t,a,c,l);const d=c==="bg"?"$bgColor":"$textColor";i(jt(e,a,d,l),{type:"nodeColor",address:a,key:d,value:l})},onNodeBorderColorChange:(a,c)=>{var l;(l=t.onNodeBorderColorChange)==null||l.call(t,a,c),i(jt(e,a,"$borderColor",c),{type:"nodeColor",address:a,key:"$borderColor",value:c})},onNodeBorderStyleChange:(a,c)=>{var l;(l=t.onNodeBorderStyleChange)==null||l.call(t,a,c),i(jt(e,a,"$borderStyle",c),{type:"nodeStyle",address:a,key:"$borderStyle",value:c})},onNodeBorderWidthChange:(a,c)=>{var l;c!==void 0&&(!Number.isFinite(c)||c<0)||((l=t.onNodeBorderWidthChange)==null||l.call(t,a,c),i(jt(e,a,"$borderWidth",c),{type:"nodeStyle",address:a,key:"$borderWidth",value:c}))},onNodeBorderRadiusChange:(a,c)=>{var l;c!==void 0&&(!Number.isFinite(c)||c<0)||((l=t.onNodeBorderRadiusChange)==null||l.call(t,a,c),i(jt(e,a,"$borderRadius",c),{type:"nodeStyle",address:a,key:"$borderRadius",value:c}))},onNodeIconChange:(a,c)=>{var l;(l=t.onNodeIconChange)==null||l.call(t,a,c),i(jt(e,a,"$icon",c),{type:"nodeIcon",address:a,key:"$icon",value:c})},onNodeOutlineChange:(a,c)=>{var l;(l=t.onNodeOutlineChange)==null||l.call(t,a,c),i(jt(e,a,"$outline",c),{type:"nodeOutline",address:a,key:"$outline",value:c})},onNodeAnimationChange:(a,c)=>{var l;(l=t.onNodeAnimationChange)==null||l.call(t,a,c),i(jt(e,a,"$isNodeAnimated",c),{type:"nodeAnimation",address:a,key:"$isNodeAnimated",value:c})},onNodeAnimationVariantChange:(a,c)=>{var l;c!=="traveling"&&c!=="pulse"||((l=t.onNodeAnimationVariantChange)==null||l.call(t,a,c),i(jt(e,a,"$nodeAnimationVariant",c),{type:"nodeAnimation",address:a,key:"$nodeAnimationVariant",value:c}))},onNodeCollapse:(a,c)=>{var l;(l=t.onNodeCollapse)==null||l.call(t,a,c),i(uo(e,a,c),{type:"nodeCollapse",address:a,key:"$collapsed",value:c})},onNodeCreate:a=>{var x;if(((x=t.onNodeCreate)==null?void 0:x.call(t,a))===!0)return;const c=a.sourceNodeId||"root",l=Oe(e,c),d=!!a.sourceNodeId&&a.isArrayMode&&!(l!=null&&l.$arrayDrawInitialized),u=Array.isArray(l==null?void 0:l.$)?l.$:l,h=new Set(Object.entries(u??{}).filter(([w])=>!w.startsWith("$")).map(([,w])=>w==null?void 0:w.$label));let p=1,m=e,g;const y=[];let b=a.isArrayMode?"array":"set";for(let w=0;w<(d?2:1);w++){const v=a.sourceNodeId&&Wb(m,a.sourceNodeId,o);if(v){m=v.json,g??(g=v.address),y.push(v.address),b="form";continue}for(;h.has(`Untitled ${p}`);)p++;const C=`Untitled ${p++}`,S=Qw(Oe(m,c),a.isArrayMode?"list":"node"),E=a.isArrayMode?{$bgColor:"gray.500",$label:C,$:[]}:{$bgColor:"gray.500",$label:C},R=$d(m,c,E,S);m=R.json,g??(g=R.address),y.push(R.address)}d&&(m=Pt(m,c,w=>Array.isArray(w)?{$:w,$arrayDrawInitialized:!0}:{...w,$arrayDrawInitialized:!0})),i(m,{type:"nodeCreate",address:g,nodeAddresses:y,value:b})},onNodeDelete:(a,c)=>{var l;(l=t.onNodeDelete)==null||l.call(t,a,c),i(db(e,a),{type:"nodeDelete",address:a})},onEdgeCreate:(a,c,l)=>{var u;(u=t.onEdgeCreate)==null||u.call(t,a,c,l);const d=l&&(l.sourceProperty!==void 0||l.targetProperty!==void 0)?{...l,target:c}:void 0;i(d?qd(e,a,d):ub(e,a,c),{type:"edgeCreate",address:a,key:d?"$connections":"$target",value:d??c})},onEdgeLabelChange:(a,c)=>{var d;(d=t.onEdgeLabelChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$sourceLabel",c),{type:"edgeLabel",edge:l,key:l.connection?"$connections":"$sourceLabel",value:c})},onEdgeStyleChange:(a,c)=>{var d;(d=t.onEdgeStyleChange)==null||d.call(t,a,c);const l=s(a);l&&i(lb(e,l,c),{type:"edgeStyle",edge:l,value:c})},onEdgeAnimationVariantChange:(a,c)=>{var d;if(c!=="dashed"&&c!=="traveling")return;(d=t.onEdgeAnimationVariantChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$edgeAnimationVariant",c),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeAnimationVariant",value:c})},onEdgeTypeChange:(a,c)=>{var d;(d=t.onEdgeTypeChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$edgeType",c),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeType",value:c})},onEdgeIconChange:(a,c)=>{var d;(d=t.onEdgeIconChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$edgeIcon",c||void 0),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeIcon",value:c})},onEdgeColorChange:(a,c)=>{var d;(d=t.onEdgeColorChange)==null||d.call(t,a,c);const l=s(a);l&&i(Sr(e,l,"$edgeColor",c),{type:"edgeColor",edge:l,key:l.connection?"$connections":"$edgeColor",value:c})},onEdgeDelete:(a,c)=>{var u;(u=t.onEdgeDelete)==null||u.call(t,a,c);const l=s(a);if(!l)return;const d=fb(e,l);d.removed&&i(d.json,{type:"edgeDelete",edge:l,key:l.connection?"$connections":"$target"})}}}const e1=".flow-sdk-edge-reveal{animation:flow-sdk-edge-reveal var(--flow-edge-reveal-duration,600ms) linear both;animation-play-state:var(--flow-edge-reveal-state,running)}.flow-sdk-edge-reveal-end{animation:flow-sdk-edge-reveal-end var(--flow-edge-reveal-duration,600ms) steps(1,end) both;animation-play-state:var(--flow-edge-reveal-state,running)}@keyframes flow-sdk-edge-reveal{from{stroke-dashoffset:var(--flow-edge-reveal-from,100)}to{stroke-dashoffset:0}}@keyframes flow-sdk-edge-reveal-end{from{opacity:0}to{opacity:1}}@media(prefers-reduced-motion:reduce){.flow-sdk-edge-reveal{animation:none;stroke-dashoffset:0}.flow-sdk-edge-reveal-end{animation:none;opacity:1}}";function t1({path:e,width:r,reversed:t,children:n,onComplete:o}){const i=`flow-edge-reveal-${j.useId().replace(/:/g,"")}`,s=j.useRef(null),[a,c]=j.useState({x:0,y:0,width:1,height:1});return j.useEffect(()=>{const l=matchMedia("(prefers-reduced-motion: reduce)"),d=()=>{l.matches&&(o==null||o())};return d(),l.addEventListener("change",d),()=>l.removeEventListener("change",d)},[o]),j.useLayoutEffect(()=>{var d;const l=(d=s.current)==null?void 0:d.getBBox();l&&c({x:l.x-r,y:l.y-r,width:l.width+r*2,height:l.height+r*2})},[e,r]),f.jsxs(f.Fragment,{children:[f.jsx("defs",{children:f.jsx("mask",{id:i,maskUnits:"userSpaceOnUse",...a,children:f.jsx("path",{ref:s,className:"flow-sdk-edge-reveal",onAnimationEnd:l=>{l.animationName==="flow-sdk-edge-reveal"&&(o==null||o())},"data-reveal-direction":t?"reverse":"forward",style:{"--flow-edge-reveal-from":t?-100:100},d:e,fill:"none",stroke:"white",strokeWidth:r,strokeLinecap:"butt",strokeLinejoin:"round",pathLength:100,strokeDasharray:"100 100"})})}),f.jsx("g",{mask:`url(#${i})`,children:n})]})}const r1=".flow-sdk-edge-trace{pointer-events:none;animation:flow-sdk-edge-trace 2.4s linear infinite}.flow-sdk-edge-trace-reverse{animation-direction:reverse}@keyframes flow-sdk-edge-trace{from{stroke-dashoffset:18}to{stroke-dashoffset:-100}}@media(prefers-reduced-motion:reduce){.flow-sdk-edge-trace,.flow-sdk-edge-anim{animation:none}}";function n1({path:e,color:r,width:t,reversed:n}){return f.jsx("path",{className:`flow-sdk-edge-trace${n?" flow-sdk-edge-trace-reverse":""}`,"data-animation-variant":"traveling","aria-hidden":"true",pointerEvents:"none",d:e,fill:"none",stroke:r,strokeWidth:t,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 100"})}const Ub=".flow-sdk-node-animation{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none;z-index:1}.flow-sdk-node-border-animation{pointer-events:none;animation:flow-sdk-node-border 2.4s linear infinite}.flow-sdk-node-border-pulse{stroke-width:var(--flow-pulse-rest-width);animation:flow-sdk-node-pulse 1.8s ease-in-out infinite}@keyframes flow-sdk-node-border{from{stroke-dashoffset:0}to{stroke-dashoffset:-100}}@keyframes flow-sdk-node-pulse{0%,100%{stroke-width:var(--flow-pulse-rest-width)}50%{stroke-width:var(--flow-pulse-expanded-width)}}@media(prefers-reduced-motion:reduce){.flow-sdk-node-border-animation{animation:none}}";function go({x:e=0,y:r=0,width:t,height:n,radius:o,color:i,strokeWidth:s=8,path:a,variant:c="traveling"}){const l=j.useId(),d=`flow-sdk-node-border-animation${c==="pulse"?" flow-sdk-node-border-pulse":""}`;if(c==="pulse"){const u=a?"path":"rect",h=a?{d:a}:{x:e,y:r,width:Math.max(0,t),height:Math.max(0,n),rx:Math.max(0,Math.min(o,t/2,n/2))},p=s+36,m={x:e-p,y:r-p,width:t+2*p,height:n+2*p};return f.jsxs("g",{"aria-hidden":"true",pointerEvents:"none",children:[f.jsx("defs",{children:f.jsxs("mask",{id:l,maskUnits:"userSpaceOnUse",...m,style:{maskType:"luminance"},children:[f.jsx("rect",{...m,fill:"white"}),f.jsx(u,{...h,fill:"black",stroke:"black",strokeWidth:s,strokeLinejoin:"round"})]})}),f.jsx(u,{...h,className:d,"data-animation-variant":c,fill:"none",stroke:`color-mix(in srgb, ${i} 30%, transparent)`,strokeLinejoin:"round",mask:`url(#${l})`,style:{"--flow-pulse-rest-width":`${s+16}px`,"--flow-pulse-expanded-width":`${s+36}px`}})]})}return a?f.jsx("path",{className:d,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",d:a,fill:"none",stroke:i,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"}):f.jsx("rect",{className:d,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",x:e,y:r,width:Math.max(0,t),height:Math.max(0,n),rx:Math.max(0,Math.min(o,t/2,n/2)),fill:"none",stroke:i,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const o1=e=>{const n=1/(Math.cbrt(e)*.8);let o=Math.round(650*n),i=Math.round(350*n);return o=Math.max(40,Math.min(450,o)),i=Math.max(30,Math.min(300,i)),{edgeSep:o,rankSep:i}};function Kb(e,r=!1){return e&&!r&&typeof requestAnimationFrame<"u"&&!(typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches)}function Jb(e,r,t=()=>{},n=300){let o,i,s=!1;const a=()=>{s=!0,o!==void 0&&cancelAnimationFrame(o),clearTimeout(i)},c=()=>{s||(a(),r(1),t())};if(!Kb(e))return c(),a;const l=performance.now(),d=u=>{if(s)return;const h=Math.max(0,Math.min(1,(u-l)/n));if(h>=1)return c();r(h<.5?4*h**3:1-(-2*h+2)**3/2),s||(o=requestAnimationFrame(d))};return o=requestAnimationFrame(d),i=setTimeout(c,n+100),a}function Zu(e,r,t){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const s of r)(s.parent===i||s.id.startsWith(`${i}.`)||t.some(c=>(c.inverted?c.target:c.source)===i&&(c.inverted?c.source:c.target)===s.id))&&!n.has(s.id)&&(n.add(s.id),o.push(s.id))}return n}function i1(e,r,t){const n=t==="downward"||t==="upward",o=new Map;for(const s of e){if(s.source===s.target||s.sourceProperty||s.targetProperty)continue;const a=r(s.source),c=r(s.target);if(!a||!c)continue;const l=n?c.y-a.y:c.x-a.x,d=Math.abs(l)-(n?a.h+c.h:a.w+c.w)/2;if(d<=320)continue;const u=JSON.stringify([s.source,Math.sign(l)]),h=o.get(u)??[];h.push({edge:s,gap:d,cross:n?c.x-a.x:c.y-a.y}),o.set(u,h)}const i=new Map;for(const s of o.values()){if(new Set(s.map(({edge:c})=>c.target)).size<2)continue;const a=new Map;for(const{edge:c}of s)a.set(c.target,(a.get(c.target)??0)+1);for(const c of[-1,0,1]){const l=s.filter(({cross:u})=>Math.sign(u)===c);l.sort((u,h)=>Math.abs(h.cross)-Math.abs(u.cross)||u.edge.id.localeCompare(h.edge.id));const d=Math.min(...l.map(({gap:u})=>u));l.forEach(({edge:u,gap:h,cross:p},m)=>{const g=l.length===1?d/2:120+(d-280)*m/(l.length-1),y=l.find(b=>Math.abs(b.cross)<Math.abs(p));i.set(u.id,{turn:g/h,labelAtTarget:a.get(u.target)===1,labelFraction:p?(p+((y==null?void 0:y.cross)??0))/(2*p):.5})})}}return i}const ir=e=>({x1:e.x-e.w/2,y1:e.y-e.h/2,x2:e.x+e.w/2,y2:e.y+e.h/2}),a1=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function ei(e){if(!e.length)return null;const r={...e[0]};for(let t=1;t<e.length;t++)r.x1=Math.min(r.x1,e[t].x1),r.y1=Math.min(r.y1,e[t].y1),r.x2=Math.max(r.x2,e[t].x2),r.y2=Math.max(r.y2,e[t].y2);return r}const s1=(e,r)=>e.x1<=r.x2&&e.x2>=r.x1&&e.y1<=r.y2&&e.y2>=r.y1,Xu=(e,r)=>e.x>=r.x1&&e.x<=r.x2&&e.y>=r.y1&&e.y<=r.y2,Bt=e=>(Math.round(e*10)/10).toString(),xt=e=>`${Bt(e.x)} ${Bt(e.y)}`,c1=e=>e>0?1:e<0?-1:0,Yu=(e,r)=>e>0?Math.max(e-r,0):Math.min(e+r,0);function l1(e,r,t,n,o=10){const i=r.x-e.x,s=r.y-e.y,a=Yu(i,(e.w+r.w)/2),c=Yu(s,(e.h+r.h)/2),l=t==="downward"||t==="upward",d=l?c:a,u=l?s:i,h=c1(u),p=n*d,m=x=>Math.abs(x)<o||Math.abs(x)>=Math.abs(d),g=m(p)||m(Math.abs(d)-Math.abs(p));let y;if(g)if(l)if(Math.abs(u)<=e.h/2){const x=(e.x+r.x)/2;y=[x,e.y,x,r.y]}else if(Math.abs(i)<=r.w/2){const x=(e.y+r.y)/2;y=[e.x,x,r.x,x]}else y=[e.x,r.y];else if(Math.abs(u)<=e.w/2){const x=(e.y+r.y)/2;y=[e.x,x,r.x,x]}else if(Math.abs(s)<=r.h/2){const x=(e.x+r.x)/2;y=[x,e.y,x,r.y]}else y=[r.x,e.y];else if(l){const x=e.y+p+e.h/2*h;y=[e.x,x,r.x,x]}else{const x=e.x+p+e.w/2*h;y=[x,e.y,x,r.y]}const b=[{x:e.x,y:e.y}];for(let x=0;x<y.length;x+=2)b.push({x:y[x],y:y[x+1]});return b.push({x:r.x,y:r.y}),b}function d1(e,r,t){const n=r.x-e.x,o=r.y-e.y,i=n>0?(t.x2-e.x)/n:n<0?(t.x1-e.x)/n:1/0,s=o>0?(t.y2-e.y)/o:o<0?(t.y1-e.y)/o:1/0,a=Math.min(i,s);return!Number.isFinite(a)||a>=1||a<0?null:{x:e.x+n*a,y:e.y+o*a}}function sn(e,r,t){var s;if(!((s=t.outline)!=null&&s.length))return d1(e,r,ir(t));const n=r.x-e.x,o=r.y-e.y;let i=1/0;return t.outline.forEach((a,c,l)=>{const d=l[(c+1)%l.length],u=d.x-a.x,h=d.y-a.y,p=n*h-o*u;if(Math.abs(p)<1e-9)return;const m=a.x-e.x,g=a.y-e.y,y=(m*h-g*u)/p,b=(m*o-g*n)/p;y>=0&&y<1&&b>=-1e-9&&b<=1+1e-9&&(i=Math.min(i,y))}),Number.isFinite(i)?{x:e.x+n*i,y:e.y+o*i}:null}function Zb(e,r,t=.5){const n=Number.isFinite(t)?Math.max(0,Math.min(1,t)):.5,o=r==="top"||r==="bottom",i=r==="top"||r==="left"?-1:1,s={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},a=Math.max(e.w,e.h)*2+1;return{...sn(s,{x:s.x+(o?0:i*a),y:s.y+(o?i*a:0)},e)??{x:o?s.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:s.y},side:r}}function Qr(e,r){return{x:e.x+(e.side==="right"?r:e.side==="left"?-r:0),y:e.y+(e.side==="bottom"?r:e.side==="top"?-r:0)}}function u1(e,r,t,n){const o=Qr(e,t.srcDist),i=Qr(r,t.tgtDist);if(n==="straight")return Yb(o,i,t);const s=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),a=e.side==="bottom"&&r.side==="top"?i.y-o.y:e.side==="top"&&r.side==="bottom"?o.y-i.y:e.side==="right"&&r.side==="left"?i.x-o.x:e.side==="left"&&r.side==="right"?o.x-i.x:void 0,c=a!==void 0&&a>0?Math.min(s,a/2):s,l=Qr({...o,side:e.side},c),d=Qr({...i,side:r.side},c),u=t.arrowAt==="source"?Et(o,l,t.arrowGap):o,h=t.arrowAt==="target"?Et(i,d,t.arrowGap):i,p=t.arrowAt==="source"?Wt(o,l,t.arrowSize,t.headShape):t.arrowAt==="target"?Wt(i,d,t.arrowSize,t.headShape):void 0;if(n==="bezier")return{d:`M${xt(u)} C${xt(l)} ${xt(d)} ${xt(h)}`,arrow:p,label:{x:(u.x+3*l.x+3*d.x+h.x)/8,y:(u.y+3*l.y+3*d.y+h.y)/8,angle:0}};const m=e.side==="left"||e.side==="right",g=r.side==="left"||r.side==="right";let y;if(m!==g){const x=m?{x:d.x,y:l.y}:{x:l.x,y:d.y},w=(x.x-l.x)*(l.x-o.x)+(x.y-l.y)*(l.y-o.y)>=0,v=(x.x-d.x)*(d.x-i.x)+(x.y-d.y)*(d.y-i.y)>=0;y=[w&&v?x:m?{x:l.x,y:d.y}:{x:d.x,y:l.y}]}else if(a!==void 0&&a<=0)if(m){const x=(l.y+d.y)/2;y=[{x:l.x,y:x},{x:d.x,y:x}]}else{const x=(l.x+d.x)/2;y=[{x,y:l.y},{x,y:d.y}]}else if(m){const x=e.side===r.side?e.side==="right"?Math.max(l.x,d.x):Math.min(l.x,d.x):(l.x+d.x)/2;y=[{x,y:l.y},{x,y:d.y}]}else{const x=e.side===r.side?e.side==="bottom"?Math.max(l.y,d.y):Math.min(l.y,d.y):(l.y+d.y)/2;y=[{x:l.x,y:x},{x:d.x,y:x}]}const b=[l,...y,d].filter((x,w,v)=>w===0||x.x!==v[w-1].x||x.y!==v[w-1].y);return Po(u,b,h,p,n==="orthogonal"?0:t.radius)}function Et(e,r,t){const n=e.x-r.x,o=e.y-r.y,i=Math.hypot(n,o);if(!i)return e;let s=(i-t)/i;return s<0&&(s=1e-5),{x:r.x+s*n,y:r.y+s*o}}function Wt(e,r,t,n="triangle"){const o=e.x-r.x,i=e.y-r.y,s=Math.hypot(o,i)||1,a=o/s,c=i/s,l=(n==="square"?.15:.3)*t,d=.15*t,u=e.x-a*l,h=e.y-c*l;if(n==="square")return`M${xt(e)} L${Bt(e.x-c*d)} ${Bt(e.y+a*d)} L${Bt(u-c*d)} ${Bt(h+a*d)} L${Bt(u+c*d)} ${Bt(h-a*d)} L${Bt(e.x+c*d)} ${Bt(e.y-a*d)} Z`;const p=[e,{x:u-c*d,y:h+a*d},{x:u+c*d,y:h-a*d}];return p.map((g,y)=>{const b=p[(y+2)%3],x=p[(y+1)%3],w=Math.hypot(b.x-g.x,b.y-g.y),v=Math.hypot(x.x-g.x,x.y-g.y),C={x:(b.x-g.x)/w,y:(b.y-g.y)/w},S={x:(x.x-g.x)/v,y:(x.y-g.y)/v},E=Math.max(-1,Math.min(1,C.x*S.x+C.y*S.y)),R=Math.sqrt((1-E)/(1+E)),P=Math.min(1/R,w/2,v/2);return{start:{x:g.x+C.x*P,y:g.y+C.y*P},end:{x:g.x+S.x*P,y:g.y+S.y*P},radius:P*R}}).map((g,y)=>`${y?"L":"M"}${xt(g.start)} A${Bt(g.radius)} ${Bt(g.radius)} 0 0 1 ${xt(g.end)}`).join(" ")+" Z"}function Cr(e,r){let t=Math.atan(r/e);return e===0&&t<0&&(t=-t),Number.isFinite(t)||(t=0),t*180/Math.PI}function f1(e,r,t,n){const o={x:r.x-e.x,y:r.y-e.y},i={x:t.x-r.x,y:t.y-r.y},s=Math.hypot(o.x,o.y),a=Math.hypot(i.x,i.y),c=o.x*i.y-o.y*i.x;if(s<1e-6||a<1e-6||Math.abs(c)<1e-6)return{p1:r,b:r,p2:r,r:0};const l=Math.min(n,s/2,a/2);return{p1:{x:r.x-o.x/s*l,y:r.y-o.y/s*l},b:r,p2:{x:r.x+i.x/a*l,y:r.y+i.y/a*l},r:l}}function Xb(e,r,t,n){let o=-1,i=null;for(let m=0;m<e.length-1;m++){const g=sn(e[m],e[m+1],r);if(g){o=m,i=g;break}}let s=-1,a=null;for(let m=e.length-1;m>0;m--){const g=sn(e[m],e[m-1],t);if(g){s=m,a=g;break}}if(!i||!a||o>=s)return null;const c=e.slice(o+1,s),l=c[0]??a,d=c[c.length-1]??i;let u,h,p;if(n.arrowAt==="source"){const m=Et(i,l,n.srcDist);u=Et(i,l,n.srcDist+n.arrowGap),p=Wt(m,l,n.arrowSize,n.headShape)}else u=Et(i,l,n.srcDist);if(n.arrowAt==="target"){const m=Et(a,d,n.tgtDist);h=Et(a,d,n.tgtDist+n.arrowGap),p=Wt(m,d,n.arrowSize,n.headShape)}else h=Et(a,d,n.tgtDist);return Po(u,c,h,p,n.radius,n.labelTargetLength,n.labelFraction)}function Po(e,r,t,n,o,i,s){var h;const a=[e,...r,t],c=[];let l=`M${xt(e)}`;for(let p=1;p<a.length-1;p++){const m=f1(a[p-1],a[p],a[p+1],o);c.push(m),m.r===0?l+=` L${xt(m.b)}`:l+=` L${xt(m.p1)} Q${xt(m.b)} ${xt(m.p2)}`}l+=` L${xt(t)}`;let d;const u=r.length;if(u===0)d={x:(e.x+t.x)/2,y:(e.y+t.y)/2,angle:Cr(t.x-e.x,t.y-e.y)};else if(u%2===0){const p=r[u/2-1],m=r[u/2];d={x:(p.x+m.x)/2,y:(p.y+m.y)/2,angle:Cr(m.x-p.x,m.y-p.y)}}else{const p=c[(u-1)/2];if(p.r===0){const m=a[(u-1)/2+2];d={x:p.b.x,y:p.b.y,angle:Cr(m.x-p.b.x,m.y-p.b.y)}}else d={x:.25*p.p1.x+.5*p.b.x+.25*p.p2.x,y:.25*p.p1.y+.5*p.b.y+.25*p.p2.y,angle:Cr(p.p2.x-p.p1.x,p.p2.y-p.p1.y)}}if(i!==void 0){if(s!==void 0&&c.length===2){const y=c[0].p2,b=c[1].p1,x=Math.hypot(b.x-y.x,b.y-y.y),w=Math.min(.5,i/(2*x)),v=Math.max(w,Math.min(1-w,s));d={x:y.x+(b.x-y.x)*v,y:y.y+(b.y-y.y)*v,angle:Cr(b.x-y.x,b.y-y.y)}}const p=((h=c[c.length-1])==null?void 0:h.p2)??e,m=t.x-p.x,g=t.y-p.y;Math.hypot(m,g)>=i&&(d={x:(p.x+t.x)/2,y:(p.y+t.y)/2,angle:Cr(m,g)})}return{d:l,arrow:n,label:d}}function Qu(e,r,t,n,o,i,s){const a=t==="leftward"?-1:1,c={x:e.x+a*(e.w/2+s.srcDist),y:n??e.y},l={x:r.x-a*(r.w/2+s.tgtDist),y:o??r.y},d=Math.max(80,s.arrowGap+s.arrowSize*.3),u=c.x+a*d,h=l.x-a*d;let p;if(a*(h-u)>=0){const b=c.x+(l.x-c.x)*i,x=Math.max(Math.min(u,h),Math.min(Math.max(u,h),b));p=[{x,y:c.y},{x,y:l.y}]}else{const b=Math.min(e.y-e.h/2,r.y-r.h/2)-d*(1+i);p=[{x:u,y:c.y},{x:u,y:b},{x:h,y:b},{x:h,y:l.y}]}const m=s.arrowAt==="source"?Et(c,p[0],s.arrowGap):c,g=s.arrowAt==="target"?Et(l,p[p.length-1],s.arrowGap):l,y=s.arrowAt==="source"?Wt(c,p[0],s.arrowSize,s.headShape):s.arrowAt==="target"?Wt(l,p[p.length-1],s.arrowSize,s.headShape):void 0;return Po(m,p,g,y,s.radius)}function ef(e,r,t,n,o){return Xb(l1(e,r,t,n),e,r,o)}function tf(e,r,t,n,o,i){const s=n===void 0&&o===void 0&&(t==="downward"||t==="upward"),a=t==="leftward"||s&&t==="upward"?-1:1,c=(l,d,u)=>{const h={x:l.x,y:d??l.y},p=Math.max(l.w,l.h)*2+1,m=sn(h,{x:h.x+(s?0:u*p),y:h.y+(s?u*p:0)},l);return m?{x:m.x+(s?0:u*i),y:m.y+(s?u*i:0)}:s?{x:l.x,y:l.y+u*(l.h/2+i)}:{x:l.x+u*(l.w/2+i),y:d??l.y}};return{sourcePoint:c(e,n,a),targetPoint:c(r,o,-a)}}function h1(e,r,t,n){const o=t==="downward"||t==="upward",i=t==="leftward"||t==="upward"?-1:1,s=Math.max(100,Math.abs(o?r.y-e.y:r.x-e.x)/2),a={x:e.x+(o?0:i*s),y:e.y+(o?i*s:0)},c={x:r.x-(o?0:i*s),y:r.y-(o?i*s:0)},l=n.arrowAt==="source"?Et(e,a,n.arrowGap):e,d=n.arrowAt==="target"?Et(r,c,n.arrowGap):r;return{d:`M${xt(l)} C${xt(a)} ${xt(c)} ${xt(d)}`,arrow:n.arrowAt==="source"?Wt(e,a,n.arrowSize,n.headShape):n.arrowAt==="target"?Wt(r,c,n.arrowSize,n.headShape):void 0,label:{x:(l.x+3*a.x+3*c.x+d.x)/8,y:(l.y+3*a.y+3*c.y+d.y)/8,angle:Cr(d.x+c.x-a.x-l.x,d.y+c.y-a.y-l.y)}}}function Yb(e,r,t){const n=t.arrowAt==="source"?Et(e,r,t.arrowGap):e,o=t.arrowAt==="target"?Et(r,e,t.arrowGap):r,i=t.arrowAt==="source"?Wt(e,r,t.arrowSize,t.headShape):t.arrowAt==="target"?Wt(r,e,t.arrowSize,t.headShape):void 0;return Po(n,[],o,i,0)}function p1(e,r,t,n=-90,o=-60,i=350){const s=n*Math.PI/180,a=o*Math.PI/180,c=s-Math.PI/2,l=c-a/2,d=c+a/2,u=1.4*i*(r/3+1),h={x:e.x+Math.cos(l)*u,y:e.y+Math.sin(l)*u},p={x:e.x+Math.cos(d)*u,y:e.y+Math.sin(d)*u},m={x:e.x,y:e.y},g=sn(m,h,e),y=sn(m,p,e);if(!g||!y)return null;const b={x:(h.x+p.x)/2,y:(h.y+p.y)/2};let x=Et(g,h,t.srcDist),w=Et(y,p,t.tgtDist),v;if(t.arrowAt==="target"){const S=w;w=Et(y,p,t.tgtDist+t.arrowGap),v=Wt(S,p,t.arrowSize,t.headShape)}else if(t.arrowAt==="source"){const S=x;x=Et(g,h,t.srcDist+t.arrowGap),v=Wt(S,h,t.arrowSize,t.headShape)}return{d:`M${xt(x)} Q${xt(h)} ${xt(b)} Q${xt(p)} ${xt(w)}`,arrow:v,label:{x:b.x,y:b.y,angle:Cr(p.x-h.x,p.y-h.y)}}}const $r=e=>Math.round(e*1e3)/1e3;function Qb(e){var h,p;const r=e.querySelector("[data-flow-node-surface]");if(!r)return;const t=e.getBoundingClientRect(),n=t.width/e.offsetWidth;if(!Number.isFinite(n)||n<=0)return;const o=r.getBoundingClientRect();if(!o.width||!o.height)return;const i=(p=(h=r.closest("[data-flow-icon-label]"))==null?void 0:h.querySelector("[data-flow-icon-caption]"))==null?void 0:p.getBoundingClientRect(),s=r,a=typeof s.getScreenCTM=="function"?s.getScreenCTM():null,c=typeof s.getTotalLength=="function"?s.getTotalLength():0,l=s.points,d=(l==null?void 0:l.numberOfItems)||128,u=a&&c>0?Array.from({length:d},(m,g)=>{const y=l!=null&&l.numberOfItems?l.getItem(g):s.getPointAtLength(c*g/d);return{x:$r((a.a*y.x+a.c*y.y+a.e-t.left)/n),y:$r((a.b*y.x+a.d*y.y+a.f-t.top)/n)}}):void 0;return{left:$r((o.left-t.left)/n),top:$r((o.top-t.top)/n),width:r instanceof HTMLElement?r.offsetWidth:$r(o.width/n),height:r instanceof HTMLElement?r.offsetHeight:$r(o.height/n),radius:parseFloat(getComputedStyle(r).borderTopLeftRadius)||0,...i!=null&&i.height?{captionBottom:$r((i.bottom-t.top)/n)}:{},...u?{outline:u}:{}}}function qn(e,r){const t=e.x-e.w/2,n=e.y-e.h/2;return{x:t+r.left+r.width/2,y:n+r.top+r.height/2,w:r.width,h:r.height,...r.outline?{outline:r.outline.map(o=>({x:t+o.x,y:n+o.y}))}:{}}}function g1(e,r,t,n,o){var d;const i=o!=="TB"&&o!=="BT",s=i?"top":"left",a=i?"bottom":"right",c=new Map;for(const u of n)for(const[h,p,m]of[[u.source,u.sourceProperty,u.target],[u.target,u.targetProperty,u.source]]){const g=r.get(m);if(p===void 0||!g||m===h)continue;const y=t.get(m),b=JSON.stringify([h,p]),x=c.get(b)??[];x.push(y?qn(g,y):g),c.set(b,x)}const l=new Map(e);for(const[u,h]of e){const p=r.get(u);if(!p||!h.some(w=>w.placement==="config"))continue;const m=t.get(u),g=m?qn(p,m):p,y={x:p.w/2,y:p.h/2,w:p.w,h:p.h},b=m?qn(y,m):y,x=new Map;for(const w of h){if(w.placement!=="config")continue;const C=(c.get(JSON.stringify([u,w.property]))??[]).reduce((E,R)=>E+(i?R.y-g.y:R.x-g.x),0),S=((d=w.anchor)==null?void 0:d.side)===a?a:s;x.set(w,C<-.001?s:C>.001?a:S)}l.set(u,h.map(w=>{const v=x.get(w);if(!v)return w;const C=h.filter(R=>x.get(R)===v),S=(C.indexOf(w)+1)/(C.length+1),E=Zb(b,v,S);return{...w,anchor:E,top:E.y,height:0}}))}return l}function rf(e,r,t){const n=new Set(r.map(a=>a.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const a of r)!o.has(a.id)&&(o.has(a.parent??"")||a.id.startsWith(`${e}.`))&&(o.add(a.id),i=!0)}const s=new Set(o);for(const a of t)o.has(a.source)&&n.has(a.target)&&s.add(a.target),o.has(a.target)&&n.has(a.source)&&s.add(a.source);return s}const _r='"Helvetica Neue", Helvetica, sans-serif';let Cn;const oo=new Map;function Ao(e,r){const t=`${r}|${e}`,n=oo.get(t);if(n!==void 0)return n;Cn===void 0&&(Cn=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let o;return Cn?(Cn.font=r,o=Cn.measureText(e).width):o=e.length*(parseFloat(r)||16)*.55,oo.size>5e3&&oo.clear(),oo.set(t,o),o}function y1(e,r,t){const n=[];for(const o of String(e).split(`
210
+ `)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let s="";for(const a of i){const c=s?`${s} ${a}`:a;!s||Ao(c,r)<=t?s=c:(n.push(s),s=a)}n.push(s)}return n}const nf=e=>e.stopPropagation();function m1({id:e,rect:r,label:t,labelLayer:n,labelContent:o,style:i,onSelect:s,onCollapse:a,selected:c=!1}){const l=r.x2-r.x1,d=r.y2-r.y1,u=i.borderWidth,h=i.borderStyle==="dashed"?`${u*4} ${u*2}`:i.borderStyle==="dotted"?`${u} ${u}`:void 0,p=r.x1+l/2,m=i.labelPosition==="top"?r.y1+i.labelMargin-i.fontSize/2:i.labelPosition==="bottom"?r.y2-i.labelMargin+i.fontSize/2:r.y1+d/2,g=t?Ao(t,`bold ${i.fontSize}px ${_r}`):0,y=i.fontSize/5,b=t||c&&a?f.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[c&&a&&f.jsx("foreignObject",{x:p+g/2+y+8,y:m-24,width:48,height:48,"data-flow-content-toggle":"","data-flow-collapse-control":"",style:{pointerEvents:"auto"},children:f.jsx(Ge,{label:"Show icon",children:f.jsx(Ne,{"aria-label":"Show icon",icon:f.jsx(ee.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:i.textColor},onClick:x=>{x.stopPropagation(),a(e)}})})}),o?f.jsx("foreignObject",{x:p-g/2-y,y:m-i.fontSize/2-y,width:g+2*y,height:i.fontSize+2*y,style:{overflow:"visible"},onClick:nf,children:o}):t&&f.jsxs(f.Fragment,{children:[f.jsx("rect",{x:p-g/2-y,y:m-i.fontSize/2-y,width:g+2*y,height:i.fontSize+2*y,fill:i.textColor==="transparent"?"transparent":i.labelBg}),f.jsx("text",{x:p,y:m,fill:i.textColor,fontSize:i.fontSize,fontWeight:"bold",fontFamily:_r,style:{fontSize:i.fontSize,fontWeight:"bold",fontFamily:_r},textAnchor:"middle",dominantBaseline:"central",children:t})]})]}):null;return f.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:nf,onClick:x=>{x.stopPropagation(),s==null||s(e,{shiftKey:x.shiftKey,ctrlKey:x.ctrlKey,metaKey:x.metaKey,altKey:x.altKey})},children:[f.jsx("rect",{x:r.x1,y:r.y1,width:l,height:d,rx:i.borderRadius,ry:i.borderRadius,fill:i.bgColor,fillOpacity:i.bgOpacity,stroke:i.borderColor,strokeWidth:i.borderStyle==="double"?u/3:u,strokeDasharray:h}),i.borderStyle==="double"&&f.jsx("rect",{x:r.x1+u*2/3,y:r.y1+u*2/3,width:Math.max(0,l-u*4/3),height:Math.max(0,d-u*4/3),rx:Math.max(0,i.borderRadius-u*2/3),ry:Math.max(0,i.borderRadius-u*2/3),fill:"none",stroke:i.borderColor,strokeWidth:u/3}),i.animated&&u>0&&f.jsx(go,{variant:i.animationVariant,x:r.x1,y:r.y1,width:l,height:d,radius:i.borderRadius,color:i.animationColor||i.borderColor,strokeWidth:Math.max(8,u*1.6)}),n&&b?Wr.createPortal(b,n):b]})}const b1=j.memo(m1),yo=45,ex=70,Lr=15,tx=50;function rx(e,r,t=yo){const n=`${t}px ${_r}`,o=e?y1(e,n,200*t/yo):[],i=r?48+(o.length?12:0):0,s=i+Math.max(0,...o.map(l=>Ao(l,n))),a=Math.max(o.length*t,r?48:0),c=o.length||r?2*Lr:0;return{lines:o,iconWidth:i,contentWidth:s,contentHeight:a,width:s+c,height:a+c}}const Ln=6,nx=3,Kd=.3,x1=8,Jd=Math.max(Math.pow(Ln*13.37,.9),29)*nx-x1/Kd,ox=Ln*nx*2,co=80,v1=2*co+Jd*Kd+100,w1=36+2*Math.max(80,ox+Jd*Kd);function kd(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function Pd(e,r){return r==="auto"||(r==="properties"?kd(e):!kd(e))}function ar(e,r,t){return t!=="properties"||e!=="root"||r.some(n=>(n.source===e||n.target===e)&&kd(n))}function C1(e,r,t,n=!1,o){if(!n)return{nodes:e,edges:r};const i=e.filter(a=>ar(a.id,r,t)&&(!o||o.has(a.id))),s=new Set(i.map(a=>a.id));return{nodes:i,edges:r.filter(a=>Pd(a,t)&&s.has(a.source)&&s.has(a.target))}}const S1=500,j1="32 18",E1=e=>e.stopPropagation();function _1({id:e,reveal:r,onRevealComplete:t,edgeData:n,validationIssue:o,edgeType:i="rounded-orthogonal",edgeRadius:s,customEdgeTypes:a,source:c,target:l,sourceProperty:d,targetProperty:u,sourceY:h,targetY:p,sourcePort:m,targetPort:g,propertyMode:y=!1,dir:b,turn:x,labelAtTarget:w,labelFraction:v,color:C,connectorColor:S,labelBg:E,labelLayer:R,label:P,dashed:I,animated:M,inverted:k,loopIndex:_=0,onSelect:N}){const $=n==null?void 0:n.icon,D=y?yo:ex,{lines:T,iconWidth:Z,contentWidth:K,contentHeight:ne}=j.useMemo(()=>rx(P,$,D),[P,$,D]),se=j.useMemo(()=>{const xe={srcDist:co,tgtDist:co,arrowGap:ox,arrowSize:Jd,headShape:y&&(k?h!==void 0||m:p!==void 0||g)?"square":"triangle",radius:s??(w?40:S1),arrowAt:k?"source":"target",labelTargetLength:w?K+2*Lr:void 0,labelFraction:w?v:void 0},fe=h!==void 0||p!==void 0||!!m||!!g,U=tf(c,l,b,h,p,0),re=h===void 0&&p===void 0&&(b==="downward"||b==="upward"),de=m??{...U.sourcePoint,side:re?b==="upward"?"top":"bottom":b==="leftward"?"left":"right"},Pe=g??{...U.targetPoint,side:re?b==="upward"?"bottom":"top":b==="leftward"?"right":"left"},ae=c.x===l.x&&c.y===l.y,we=m||g?u1(de,Pe,{...xe,srcDist:18,tgtDist:18},i):fe?Qu(c,l,b,h,p,x,{...xe,srcDist:18,tgtDist:18,radius:s??Math.min(xe.radius,40)}):ae?p1(c,_,{...xe,srcDist:0,tgtDist:0}):ef(c,l,b,x,xe);if(!we)return null;const $e=tf(c,l,b,h,p,fe?18:co);m&&($e.sourcePoint=Qr(m,18)),g&&($e.targetPoint=Qr(g,18));const Ue=Object.prototype.hasOwnProperty.call(a??{},i)?a==null?void 0:a[i]:void 0;if(Ue){const Ve={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return Ue({edge:n??{id:e,source:"",target:""},source:{...c},target:{...l},...$e,direction:Ve[b],sourceY:h,targetY:p,inverted:!!k,defaultGeometry:we})??we}return ae||m||g?we:i==="straight"?fe?Yb($e.sourcePoint,$e.targetPoint,xe):Xb([c,l],c,l,xe):i==="bezier"?h1($e.sourcePoint,$e.targetPoint,fe?b==="leftward"?"leftward":"rightward":b,xe):i==="orthogonal"?fe?Qu(c,l,b,h,p,x,{...xe,srcDist:18,tgtDist:18,radius:0}):ef(c,l,b,x,{...xe,radius:0}):we},[c,e,n,i,s,a,l,y,h,p,m,g,b,x,k,_,w,v,K]);if(!se)return null;const W=(b==="rightward"||b==="leftward")&&!Object.prototype.hasOwnProperty.call(a??{},i)&&!(y&&(h!==void 0||p!==void 0||m||g)),ue=W?`translate(${se.label.x} ${se.label.y-ne/2-2*Lr})`:`translate(${se.label.x} ${se.label.y}) rotate(${se.label.angle}) translate(${b==="downward"||b==="upward"||w||Object.prototype.hasOwnProperty.call(a??{},i)?0:tx} 0)`,q=o!=null&&o.startsWith("Unverified:")?"#b45309":"#dc2626",F=o?q:C,H=o?f.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":o,transform:`translate(${se.label.x} ${se.label.y-T.length*D/2-55})`,children:[f.jsx("title",{children:o}),f.jsx(cr,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:q})]}):null,G=M&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",ce=!G&&(I||M)?j1:void 0,te=M&&!G?`flow-sdk-edge-anim${k?" flow-sdk-edge-anim-rev":""}`:void 0;let X=null;const ie=r?{"--flow-edge-reveal-duration":`${r.durationMs??600}ms`,"--flow-edge-reveal-state":r.paused?"paused":"running"}:void 0;if(T.length||$){const xe=K,fe=ne;X=f.jsxs("g",{className:`flow-sdk-edge-label${r?" flow-sdk-edge-reveal-end":""}`,style:ie,"data-label-transform":ue,"data-label-horizontal":W||void 0,"data-edge-id":e,"data-source-property":d,"data-target-property":u,transform:ue,children:[f.jsx("rect",{x:-xe/2-Lr,y:-fe/2-Lr,width:xe+2*Lr,height:fe+2*Lr,fill:C==="transparent"?"transparent":E}),f.jsx("text",{fill:C,fontSize:D,style:{fontSize:D,fontFamily:_r},fontFamily:_r,textAnchor:"middle",dominantBaseline:"central",children:T.map((U,re)=>f.jsx("tspan",{x:Z/2,y:(re-(T.length-1)/2)*D,children:U},re))}),$&&f.jsxs("g",{className:"flow-sdk-edge-icon",opacity:C==="transparent"?0:1,children:[f.jsx("title",{children:P?`Edge icon: ${P}`:"Edge icon"}),f.jsx("rect",{x:-xe/2,y:-24,width:48,height:48,fill:"transparent"}),f.jsx(cr,{name:$,svg:!0,size:48,x:-xe/2,y:-24,color:C})]})]})}const me=f.jsxs(f.Fragment,{children:[f.jsx("path",{d:se.d,fill:"none",stroke:F,strokeWidth:Ln,strokeOpacity:G?.35:void 0,strokeDasharray:ce,className:te}),G&&f.jsx(n1,{path:se.d,color:F,width:Ln*1.6,reversed:k})]});return f.jsxs("g",{className:"flow-sdk-edge",style:ie,"data-edge-id":e,"data-source-property":d,"data-target-property":u,"data-validation":o?o.startsWith("Unverified:")?"unverified":"invalid":void 0,"aria-label":o,onPointerDown:E1,onClick:xe=>{xe.stopPropagation(),N==null||N(e)},children:[r?f.jsx(t1,{path:se.d,width:Ln*4,reversed:k,onComplete:()=>t==null?void 0:t(e),children:me}):me,se.arrow&&f.jsx("path",{className:r?"flow-sdk-edge-reveal-end":void 0,d:se.arrow,fill:o?q:S??F}),R&&X?Wr.createPortal(X,R):X,R&&H?Wr.createPortal(H,R):H,f.jsx("path",{className:"flow-sdk-edge-hit",d:se.d,fill:"none",stroke:"transparent"})]})}const of=j.memo(_1);var io=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function k1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Zd(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 ti,af;function P1(){if(af)return ti;af=1;function e(){this.__data__=[],this.size=0}return ti=e,ti}var ri,sf;function fn(){if(sf)return ri;sf=1;function e(r,t){return r===t||r!==r&&t!==t}return ri=e,ri}var ni,cf;function Ro(){if(cf)return ni;cf=1;var e=fn();function r(t,n){for(var o=t.length;o--;)if(e(t[o][0],n))return o;return-1}return ni=r,ni}var oi,lf;function A1(){if(lf)return oi;lf=1;var e=Ro(),r=Array.prototype,t=r.splice;function n(o){var i=this.__data__,s=e(i,o);if(s<0)return!1;var a=i.length-1;return s==a?i.pop():t.call(i,s,1),--this.size,!0}return oi=n,oi}var ii,df;function R1(){if(df)return ii;df=1;var e=Ro();function r(t){var n=this.__data__,o=e(n,t);return o<0?void 0:n[o][1]}return ii=r,ii}var ai,uf;function M1(){if(uf)return ai;uf=1;var e=Ro();function r(t){return e(this.__data__,t)>-1}return ai=r,ai}var si,ff;function T1(){if(ff)return si;ff=1;var e=Ro();function r(t,n){var o=this.__data__,i=e(o,t);return i<0?(++this.size,o.push([t,n])):o[i][1]=n,this}return si=r,si}var ci,hf;function Mo(){if(hf)return ci;hf=1;var e=P1(),r=A1(),t=R1(),n=M1(),o=T1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,ci=i,ci}var li,pf;function I1(){if(pf)return li;pf=1;var e=Mo();function r(){this.__data__=new e,this.size=0}return li=r,li}var di,gf;function N1(){if(gf)return di;gf=1;function e(r){var t=this.__data__,n=t.delete(r);return this.size=t.size,n}return di=e,di}var ui,yf;function O1(){if(yf)return ui;yf=1;function e(r){return this.__data__.get(r)}return ui=e,ui}var fi,mf;function $1(){if(mf)return fi;mf=1;function e(r){return this.__data__.has(r)}return fi=e,fi}var hi,bf;function ix(){if(bf)return hi;bf=1;var e=typeof io=="object"&&io&&io.Object===Object&&io;return hi=e,hi}var pi,xf;function Yt(){if(xf)return pi;xf=1;var e=ix(),r=typeof self=="object"&&self&&self.Object===Object&&self,t=e||r||Function("return this")();return pi=t,pi}var gi,vf;function hn(){if(vf)return gi;vf=1;var e=Yt(),r=e.Symbol;return gi=r,gi}var yi,wf;function q1(){if(wf)return yi;wf=1;var e=hn(),r=Object.prototype,t=r.hasOwnProperty,n=r.toString,o=e?e.toStringTag:void 0;function i(s){var a=t.call(s,o),c=s[o];try{s[o]=void 0;var l=!0}catch{}var d=n.call(s);return l&&(a?s[o]=c:delete s[o]),d}return yi=i,yi}var mi,Cf;function L1(){if(Cf)return mi;Cf=1;var e=Object.prototype,r=e.toString;function t(n){return r.call(n)}return mi=t,mi}var bi,Sf;function Gr(){if(Sf)return bi;Sf=1;var e=hn(),r=q1(),t=L1(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function s(a){return a==null?a===void 0?o:n:i&&i in Object(a)?r(a):t(a)}return bi=s,bi}var xi,jf;function Vt(){if(jf)return xi;jf=1;function e(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}return xi=e,xi}var vi,Ef;function Un(){if(Ef)return vi;Ef=1;var e=Gr(),r=Vt(),t="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function s(a){if(!r(a))return!1;var c=e(a);return c==n||c==o||c==t||c==i}return vi=s,vi}var wi,_f;function F1(){if(_f)return wi;_f=1;var e=Yt(),r=e["__core-js_shared__"];return wi=r,wi}var Ci,kf;function z1(){if(kf)return Ci;kf=1;var e=F1(),r=(function(){var n=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})();function t(n){return!!r&&r in n}return Ci=t,Ci}var Si,Pf;function ax(){if(Pf)return Si;Pf=1;var e=Function.prototype,r=e.toString;function t(n){if(n!=null){try{return r.call(n)}catch{}try{return n+""}catch{}}return""}return Si=t,Si}var ji,Af;function B1(){if(Af)return ji;Af=1;var e=Un(),r=z1(),t=Vt(),n=ax(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,s=Function.prototype,a=Object.prototype,c=s.toString,l=a.hasOwnProperty,d=RegExp("^"+c.call(l).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function u(h){if(!t(h)||r(h))return!1;var p=e(h)?d:i;return p.test(n(h))}return ji=u,ji}var Ei,Rf;function D1(){if(Rf)return Ei;Rf=1;function e(r,t){return r==null?void 0:r[t]}return Ei=e,Ei}var _i,Mf;function Hr(){if(Mf)return _i;Mf=1;var e=B1(),r=D1();function t(n,o){var i=r(n,o);return e(i)?i:void 0}return _i=t,_i}var ki,Tf;function Xd(){if(Tf)return ki;Tf=1;var e=Hr(),r=Yt(),t=e(r,"Map");return ki=t,ki}var Pi,If;function To(){if(If)return Pi;If=1;var e=Hr(),r=e(Object,"create");return Pi=r,Pi}var Ai,Nf;function W1(){if(Nf)return Ai;Nf=1;var e=To();function r(){this.__data__=e?e(null):{},this.size=0}return Ai=r,Ai}var Ri,Of;function V1(){if(Of)return Ri;Of=1;function e(r){var t=this.has(r)&&delete this.__data__[r];return this.size-=t?1:0,t}return Ri=e,Ri}var Mi,$f;function G1(){if($f)return Mi;$f=1;var e=To(),r="__lodash_hash_undefined__",t=Object.prototype,n=t.hasOwnProperty;function o(i){var s=this.__data__;if(e){var a=s[i];return a===r?void 0:a}return n.call(s,i)?s[i]:void 0}return Mi=o,Mi}var Ti,qf;function H1(){if(qf)return Ti;qf=1;var e=To(),r=Object.prototype,t=r.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:t.call(i,o)}return Ti=n,Ti}var Ii,Lf;function U1(){if(Lf)return Ii;Lf=1;var e=To(),r="__lodash_hash_undefined__";function t(n,o){var i=this.__data__;return this.size+=this.has(n)?0:1,i[n]=e&&o===void 0?r:o,this}return Ii=t,Ii}var Ni,Ff;function K1(){if(Ff)return Ni;Ff=1;var e=W1(),r=V1(),t=G1(),n=H1(),o=U1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Ni=i,Ni}var Oi,zf;function J1(){if(zf)return Oi;zf=1;var e=K1(),r=Mo(),t=Xd();function n(){this.size=0,this.__data__={hash:new e,map:new(t||r),string:new e}}return Oi=n,Oi}var $i,Bf;function Z1(){if(Bf)return $i;Bf=1;function e(r){var t=typeof r;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?r!=="__proto__":r===null}return $i=e,$i}var qi,Df;function Io(){if(Df)return qi;Df=1;var e=Z1();function r(t,n){var o=t.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return qi=r,qi}var Li,Wf;function X1(){if(Wf)return Li;Wf=1;var e=Io();function r(t){var n=e(this,t).delete(t);return this.size-=n?1:0,n}return Li=r,Li}var Fi,Vf;function Y1(){if(Vf)return Fi;Vf=1;var e=Io();function r(t){return e(this,t).get(t)}return Fi=r,Fi}var zi,Gf;function Q1(){if(Gf)return zi;Gf=1;var e=Io();function r(t){return e(this,t).has(t)}return zi=r,zi}var Bi,Hf;function eC(){if(Hf)return Bi;Hf=1;var e=Io();function r(t,n){var o=e(this,t),i=o.size;return o.set(t,n),this.size+=o.size==i?0:1,this}return Bi=r,Bi}var Di,Uf;function Yd(){if(Uf)return Di;Uf=1;var e=J1(),r=X1(),t=Y1(),n=Q1(),o=eC();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Di=i,Di}var Wi,Kf;function tC(){if(Kf)return Wi;Kf=1;var e=Mo(),r=Xd(),t=Yd(),n=200;function o(i,s){var a=this.__data__;if(a instanceof e){var c=a.__data__;if(!r||c.length<n-1)return c.push([i,s]),this.size=++a.size,this;a=this.__data__=new t(c)}return a.set(i,s),this.size=a.size,this}return Wi=o,Wi}var Vi,Jf;function No(){if(Jf)return Vi;Jf=1;var e=Mo(),r=I1(),t=N1(),n=O1(),o=$1(),i=tC();function s(a){var c=this.__data__=new e(a);this.size=c.size}return s.prototype.clear=r,s.prototype.delete=t,s.prototype.get=n,s.prototype.has=o,s.prototype.set=i,Vi=s,Vi}var Gi,Zf;function Qd(){if(Zf)return Gi;Zf=1;function e(r,t){for(var n=-1,o=r==null?0:r.length;++n<o&&t(r[n],n,r)!==!1;);return r}return Gi=e,Gi}var Hi,Xf;function sx(){if(Xf)return Hi;Xf=1;var e=Hr(),r=(function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch{}})();return Hi=r,Hi}var Ui,Yf;function Oo(){if(Yf)return Ui;Yf=1;var e=sx();function r(t,n,o){n=="__proto__"&&e?e(t,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):t[n]=o}return Ui=r,Ui}var Ki,Qf;function $o(){if(Qf)return Ki;Qf=1;var e=Oo(),r=fn(),t=Object.prototype,n=t.hasOwnProperty;function o(i,s,a){var c=i[s];(!(n.call(i,s)&&r(c,a))||a===void 0&&!(s in i))&&e(i,s,a)}return Ki=o,Ki}var Ji,eh;function Kn(){if(eh)return Ji;eh=1;var e=$o(),r=Oo();function t(n,o,i,s){var a=!i;i||(i={});for(var c=-1,l=o.length;++c<l;){var d=o[c],u=s?s(i[d],n[d],d,i,n):void 0;u===void 0&&(u=n[d]),a?r(i,d,u):e(i,d,u)}return i}return Ji=t,Ji}var Zi,th;function rC(){if(th)return Zi;th=1;function e(r,t){for(var n=-1,o=Array(r);++n<r;)o[n]=t(n);return o}return Zi=e,Zi}var Xi,rh;function lr(){if(rh)return Xi;rh=1;function e(r){return r!=null&&typeof r=="object"}return Xi=e,Xi}var Yi,nh;function nC(){if(nh)return Yi;nh=1;var e=Gr(),r=lr(),t="[object Arguments]";function n(o){return r(o)&&e(o)==t}return Yi=n,Yi}var Qi,oh;function Jn(){if(oh)return Qi;oh=1;var e=nC(),r=lr(),t=Object.prototype,n=t.hasOwnProperty,o=t.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(s){return r(s)&&n.call(s,"callee")&&!o.call(s,"callee")};return Qi=i,Qi}var ea,ih;function Ct(){if(ih)return ea;ih=1;var e=Array.isArray;return ea=e,ea}var kn={exports:{}},ta,ah;function oC(){if(ah)return ta;ah=1;function e(){return!1}return ta=e,ta}kn.exports;var sh;function pn(){return sh||(sh=1,(function(e,r){var t=Yt(),n=oC(),o=r&&!r.nodeType&&r,i=o&&!0&&e&&!e.nodeType&&e,s=i&&i.exports===o,a=s?t.Buffer:void 0,c=a?a.isBuffer:void 0,l=c||n;e.exports=l})(kn,kn.exports)),kn.exports}var ra,ch;function qo(){if(ch)return ra;ch=1;var e=9007199254740991,r=/^(?:0|[1-9]\d*)$/;function t(n,o){var i=typeof n;return o=o??e,!!o&&(i=="number"||i!="symbol"&&r.test(n))&&n>-1&&n%1==0&&n<o}return ra=t,ra}var na,lh;function eu(){if(lh)return na;lh=1;var e=9007199254740991;function r(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=e}return na=r,na}var oa,dh;function iC(){if(dh)return oa;dh=1;var e=Gr(),r=eu(),t=lr(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",s="[object Date]",a="[object Error]",c="[object Function]",l="[object Map]",d="[object Number]",u="[object Object]",h="[object RegExp]",p="[object Set]",m="[object String]",g="[object WeakMap]",y="[object ArrayBuffer]",b="[object DataView]",x="[object Float32Array]",w="[object Float64Array]",v="[object Int8Array]",C="[object Int16Array]",S="[object Int32Array]",E="[object Uint8Array]",R="[object Uint8ClampedArray]",P="[object Uint16Array]",I="[object Uint32Array]",M={};M[x]=M[w]=M[v]=M[C]=M[S]=M[E]=M[R]=M[P]=M[I]=!0,M[n]=M[o]=M[y]=M[i]=M[b]=M[s]=M[a]=M[c]=M[l]=M[d]=M[u]=M[h]=M[p]=M[m]=M[g]=!1;function k(_){return t(_)&&r(_.length)&&!!M[e(_)]}return oa=k,oa}var ia,uh;function Lo(){if(uh)return ia;uh=1;function e(r){return function(t){return r(t)}}return ia=e,ia}var Pn={exports:{}};Pn.exports;var fh;function tu(){return fh||(fh=1,(function(e,r){var t=ix(),n=r&&!r.nodeType&&r,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i&&t.process,a=(function(){try{var c=o&&o.require&&o.require("util").types;return c||s&&s.binding&&s.binding("util")}catch{}})();e.exports=a})(Pn,Pn.exports)),Pn.exports}var aa,hh;function Zn(){if(hh)return aa;hh=1;var e=iC(),r=Lo(),t=tu(),n=t&&t.isTypedArray,o=n?r(n):e;return aa=o,aa}var sa,ph;function cx(){if(ph)return sa;ph=1;var e=rC(),r=Jn(),t=Ct(),n=pn(),o=qo(),i=Zn(),s=Object.prototype,a=s.hasOwnProperty;function c(l,d){var u=t(l),h=!u&&r(l),p=!u&&!h&&n(l),m=!u&&!h&&!p&&i(l),g=u||h||p||m,y=g?e(l.length,String):[],b=y.length;for(var x in l)(d||a.call(l,x))&&!(g&&(x=="length"||p&&(x=="offset"||x=="parent")||m&&(x=="buffer"||x=="byteLength"||x=="byteOffset")||o(x,b)))&&y.push(x);return y}return sa=c,sa}var ca,gh;function Fo(){if(gh)return ca;gh=1;var e=Object.prototype;function r(t){var n=t&&t.constructor,o=typeof n=="function"&&n.prototype||e;return t===o}return ca=r,ca}var la,yh;function lx(){if(yh)return la;yh=1;function e(r,t){return function(n){return r(t(n))}}return la=e,la}var da,mh;function aC(){if(mh)return da;mh=1;var e=lx(),r=e(Object.keys,Object);return da=r,da}var ua,bh;function ru(){if(bh)return ua;bh=1;var e=Fo(),r=aC(),t=Object.prototype,n=t.hasOwnProperty;function o(i){if(!e(i))return r(i);var s=[];for(var a in Object(i))n.call(i,a)&&a!="constructor"&&s.push(a);return s}return ua=o,ua}var fa,xh;function yr(){if(xh)return fa;xh=1;var e=Un(),r=eu();function t(n){return n!=null&&r(n.length)&&!e(n)}return fa=t,fa}var ha,vh;function Mr(){if(vh)return ha;vh=1;var e=cx(),r=ru(),t=yr();function n(o){return t(o)?e(o):r(o)}return ha=n,ha}var pa,wh;function sC(){if(wh)return pa;wh=1;var e=Kn(),r=Mr();function t(n,o){return n&&e(o,r(o),n)}return pa=t,pa}var ga,Ch;function cC(){if(Ch)return ga;Ch=1;function e(r){var t=[];if(r!=null)for(var n in Object(r))t.push(n);return t}return ga=e,ga}var ya,Sh;function lC(){if(Sh)return ya;Sh=1;var e=Vt(),r=Fo(),t=cC(),n=Object.prototype,o=n.hasOwnProperty;function i(s){if(!e(s))return t(s);var a=r(s),c=[];for(var l in s)l=="constructor"&&(a||!o.call(s,l))||c.push(l);return c}return ya=i,ya}var ma,jh;function Ur(){if(jh)return ma;jh=1;var e=cx(),r=lC(),t=yr();function n(o){return t(o)?e(o,!0):r(o)}return ma=n,ma}var ba,Eh;function dC(){if(Eh)return ba;Eh=1;var e=Kn(),r=Ur();function t(n,o){return n&&e(o,r(o),n)}return ba=t,ba}var An={exports:{}};An.exports;var _h;function dx(){return _h||(_h=1,(function(e,r){var t=Yt(),n=r&&!r.nodeType&&r,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i?t.Buffer:void 0,a=s?s.allocUnsafe:void 0;function c(l,d){if(d)return l.slice();var u=l.length,h=a?a(u):new l.constructor(u);return l.copy(h),h}e.exports=c})(An,An.exports)),An.exports}var xa,kh;function ux(){if(kh)return xa;kh=1;function e(r,t){var n=-1,o=r.length;for(t||(t=Array(o));++n<o;)t[n]=r[n];return t}return xa=e,xa}var va,Ph;function fx(){if(Ph)return va;Ph=1;function e(r,t){for(var n=-1,o=r==null?0:r.length,i=0,s=[];++n<o;){var a=r[n];t(a,n,r)&&(s[i++]=a)}return s}return va=e,va}var wa,Ah;function hx(){if(Ah)return wa;Ah=1;function e(){return[]}return wa=e,wa}var Ca,Rh;function nu(){if(Rh)return Ca;Rh=1;var e=fx(),r=hx(),t=Object.prototype,n=t.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(s){return s==null?[]:(s=Object(s),e(o(s),function(a){return n.call(s,a)}))}:r;return Ca=i,Ca}var Sa,Mh;function uC(){if(Mh)return Sa;Mh=1;var e=Kn(),r=nu();function t(n,o){return e(n,r(n),o)}return Sa=t,Sa}var ja,Th;function ou(){if(Th)return ja;Th=1;function e(r,t){for(var n=-1,o=t.length,i=r.length;++n<o;)r[i+n]=t[n];return r}return ja=e,ja}var Ea,Ih;function zo(){if(Ih)return Ea;Ih=1;var e=lx(),r=e(Object.getPrototypeOf,Object);return Ea=r,Ea}var _a,Nh;function px(){if(Nh)return _a;Nh=1;var e=ou(),r=zo(),t=nu(),n=hx(),o=Object.getOwnPropertySymbols,i=o?function(s){for(var a=[];s;)e(a,t(s)),s=r(s);return a}:n;return _a=i,_a}var ka,Oh;function fC(){if(Oh)return ka;Oh=1;var e=Kn(),r=px();function t(n,o){return e(n,r(n),o)}return ka=t,ka}var Pa,$h;function gx(){if($h)return Pa;$h=1;var e=ou(),r=Ct();function t(n,o,i){var s=o(n);return r(n)?s:e(s,i(n))}return Pa=t,Pa}var Aa,qh;function yx(){if(qh)return Aa;qh=1;var e=gx(),r=nu(),t=Mr();function n(o){return e(o,t,r)}return Aa=n,Aa}var Ra,Lh;function hC(){if(Lh)return Ra;Lh=1;var e=gx(),r=px(),t=Ur();function n(o){return e(o,t,r)}return Ra=n,Ra}var Ma,Fh;function pC(){if(Fh)return Ma;Fh=1;var e=Hr(),r=Yt(),t=e(r,"DataView");return Ma=t,Ma}var Ta,zh;function gC(){if(zh)return Ta;zh=1;var e=Hr(),r=Yt(),t=e(r,"Promise");return Ta=t,Ta}var Ia,Bh;function mx(){if(Bh)return Ia;Bh=1;var e=Hr(),r=Yt(),t=e(r,"Set");return Ia=t,Ia}var Na,Dh;function yC(){if(Dh)return Na;Dh=1;var e=Hr(),r=Yt(),t=e(r,"WeakMap");return Na=t,Na}var Oa,Wh;function gn(){if(Wh)return Oa;Wh=1;var e=pC(),r=Xd(),t=gC(),n=mx(),o=yC(),i=Gr(),s=ax(),a="[object Map]",c="[object Object]",l="[object Promise]",d="[object Set]",u="[object WeakMap]",h="[object DataView]",p=s(e),m=s(r),g=s(t),y=s(n),b=s(o),x=i;return(e&&x(new e(new ArrayBuffer(1)))!=h||r&&x(new r)!=a||t&&x(t.resolve())!=l||n&&x(new n)!=d||o&&x(new o)!=u)&&(x=function(w){var v=i(w),C=v==c?w.constructor:void 0,S=C?s(C):"";if(S)switch(S){case p:return h;case m:return a;case g:return l;case y:return d;case b:return u}return v}),Oa=x,Oa}var $a,Vh;function mC(){if(Vh)return $a;Vh=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n){var o=n.length,i=new n.constructor(o);return o&&typeof n[0]=="string"&&r.call(n,"index")&&(i.index=n.index,i.input=n.input),i}return $a=t,$a}var qa,Gh;function bx(){if(Gh)return qa;Gh=1;var e=Yt(),r=e.Uint8Array;return qa=r,qa}var La,Hh;function iu(){if(Hh)return La;Hh=1;var e=bx();function r(t){var n=new t.constructor(t.byteLength);return new e(n).set(new e(t)),n}return La=r,La}var Fa,Uh;function bC(){if(Uh)return Fa;Uh=1;var e=iu();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.byteLength)}return Fa=r,Fa}var za,Kh;function xC(){if(Kh)return za;Kh=1;var e=/\w*$/;function r(t){var n=new t.constructor(t.source,e.exec(t));return n.lastIndex=t.lastIndex,n}return za=r,za}var Ba,Jh;function vC(){if(Jh)return Ba;Jh=1;var e=hn(),r=e?e.prototype:void 0,t=r?r.valueOf:void 0;function n(o){return t?Object(t.call(o)):{}}return Ba=n,Ba}var Da,Zh;function xx(){if(Zh)return Da;Zh=1;var e=iu();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}return Da=r,Da}var Wa,Xh;function wC(){if(Xh)return Wa;Xh=1;var e=iu(),r=bC(),t=xC(),n=vC(),o=xx(),i="[object Boolean]",s="[object Date]",a="[object Map]",c="[object Number]",l="[object RegExp]",d="[object Set]",u="[object String]",h="[object Symbol]",p="[object ArrayBuffer]",m="[object DataView]",g="[object Float32Array]",y="[object Float64Array]",b="[object Int8Array]",x="[object Int16Array]",w="[object Int32Array]",v="[object Uint8Array]",C="[object Uint8ClampedArray]",S="[object Uint16Array]",E="[object Uint32Array]";function R(P,I,M){var k=P.constructor;switch(I){case p:return e(P);case i:case s:return new k(+P);case m:return r(P,M);case g:case y:case b:case x:case w:case v:case C:case S:case E:return o(P,M);case a:return new k;case c:case u:return new k(P);case l:return t(P);case d:return new k;case h:return n(P)}}return Wa=R,Wa}var Va,Yh;function vx(){if(Yh)return Va;Yh=1;var e=Vt(),r=Object.create,t=(function(){function n(){}return function(o){if(!e(o))return{};if(r)return r(o);n.prototype=o;var i=new n;return n.prototype=void 0,i}})();return Va=t,Va}var Ga,Qh;function wx(){if(Qh)return Ga;Qh=1;var e=vx(),r=zo(),t=Fo();function n(o){return typeof o.constructor=="function"&&!t(o)?e(r(o)):{}}return Ga=n,Ga}var Ha,ep;function CC(){if(ep)return Ha;ep=1;var e=gn(),r=lr(),t="[object Map]";function n(o){return r(o)&&e(o)==t}return Ha=n,Ha}var Ua,tp;function SC(){if(tp)return Ua;tp=1;var e=CC(),r=Lo(),t=tu(),n=t&&t.isMap,o=n?r(n):e;return Ua=o,Ua}var Ka,rp;function jC(){if(rp)return Ka;rp=1;var e=gn(),r=lr(),t="[object Set]";function n(o){return r(o)&&e(o)==t}return Ka=n,Ka}var Ja,np;function EC(){if(np)return Ja;np=1;var e=jC(),r=Lo(),t=tu(),n=t&&t.isSet,o=n?r(n):e;return Ja=o,Ja}var Za,op;function Cx(){if(op)return Za;op=1;var e=No(),r=Qd(),t=$o(),n=sC(),o=dC(),i=dx(),s=ux(),a=uC(),c=fC(),l=yx(),d=hC(),u=gn(),h=mC(),p=wC(),m=wx(),g=Ct(),y=pn(),b=SC(),x=Vt(),w=EC(),v=Mr(),C=Ur(),S=1,E=2,R=4,P="[object Arguments]",I="[object Array]",M="[object Boolean]",k="[object Date]",_="[object Error]",N="[object Function]",$="[object GeneratorFunction]",D="[object Map]",T="[object Number]",Z="[object Object]",K="[object RegExp]",ne="[object Set]",se="[object String]",W="[object Symbol]",ue="[object WeakMap]",q="[object ArrayBuffer]",F="[object DataView]",H="[object Float32Array]",G="[object Float64Array]",ce="[object Int8Array]",te="[object Int16Array]",X="[object Int32Array]",ie="[object Uint8Array]",me="[object Uint8ClampedArray]",xe="[object Uint16Array]",fe="[object Uint32Array]",U={};U[P]=U[I]=U[q]=U[F]=U[M]=U[k]=U[H]=U[G]=U[ce]=U[te]=U[X]=U[D]=U[T]=U[Z]=U[K]=U[ne]=U[se]=U[W]=U[ie]=U[me]=U[xe]=U[fe]=!0,U[_]=U[N]=U[ue]=!1;function re(de,Pe,ae,we,$e,Ue){var Ve,tt=Pe&S,ge=Pe&E,Ae=Pe&R;if(ae&&(Ve=$e?ae(de,we,$e,Ue):ae(de)),Ve!==void 0)return Ve;if(!x(de))return de;var Le=g(de);if(Le){if(Ve=h(de),!tt)return s(de,Ve)}else{var be=u(de),Xe=be==N||be==$;if(y(de))return i(de,tt);if(be==Z||be==P||Xe&&!$e){if(Ve=ge||Xe?{}:m(de),!tt)return ge?c(de,o(Ve,de)):a(de,n(Ve,de))}else{if(!U[be])return $e?de:{};Ve=p(de,be,tt)}}Ue||(Ue=new e);var ut=Ue.get(de);if(ut)return ut;Ue.set(de,Ve),w(de)?de.forEach(function(lt){Ve.add(re(lt,Pe,ae,lt,de,Ue))}):b(de)&&de.forEach(function(lt,Je){Ve.set(Je,re(lt,Pe,ae,Je,de,Ue))});var Re=Ae?ge?d:l:ge?C:v,Ke=Le?void 0:Re(de);return r(Ke||de,function(lt,Je){Ke&&(Je=lt,lt=de[Je]),t(Ve,Je,re(lt,Pe,ae,Je,de,Ue))}),Ve}return Za=re,Za}var Xa,ip;function _C(){if(ip)return Xa;ip=1;var e=Cx(),r=4;function t(n){return e(n,r)}return Xa=t,Xa}var Ya,ap;function au(){if(ap)return Ya;ap=1;function e(r){return function(){return r}}return Ya=e,Ya}var Qa,sp;function kC(){if(sp)return Qa;sp=1;function e(r){return function(t,n,o){for(var i=-1,s=Object(t),a=o(t),c=a.length;c--;){var l=a[r?c:++i];if(n(s[l],l,s)===!1)break}return t}}return Qa=e,Qa}var es,cp;function su(){if(cp)return es;cp=1;var e=kC(),r=e();return es=r,es}var ts,lp;function cu(){if(lp)return ts;lp=1;var e=su(),r=Mr();function t(n,o){return n&&e(n,o,r)}return ts=t,ts}var rs,dp;function PC(){if(dp)return rs;dp=1;var e=yr();function r(t,n){return function(o,i){if(o==null)return o;if(!e(o))return t(o,i);for(var s=o.length,a=n?s:-1,c=Object(o);(n?a--:++a<s)&&i(c[a],a,c)!==!1;);return o}}return rs=r,rs}var ns,up;function Bo(){if(up)return ns;up=1;var e=cu(),r=PC(),t=r(e);return ns=t,ns}var os,fp;function Kr(){if(fp)return os;fp=1;function e(r){return r}return os=e,os}var is,hp;function Sx(){if(hp)return is;hp=1;var e=Kr();function r(t){return typeof t=="function"?t:e}return is=r,is}var as,pp;function jx(){if(pp)return as;pp=1;var e=Qd(),r=Bo(),t=Sx(),n=Ct();function o(i,s){var a=n(i)?e:r;return a(i,t(s))}return as=o,as}var ss,gp;function Ex(){return gp||(gp=1,ss=jx()),ss}var cs,yp;function AC(){if(yp)return cs;yp=1;var e=Bo();function r(t,n){var o=[];return e(t,function(i,s,a){n(i,s,a)&&o.push(i)}),o}return cs=r,cs}var ls,mp;function RC(){if(mp)return ls;mp=1;var e="__lodash_hash_undefined__";function r(t){return this.__data__.set(t,e),this}return ls=r,ls}var ds,bp;function MC(){if(bp)return ds;bp=1;function e(r){return this.__data__.has(r)}return ds=e,ds}var us,xp;function _x(){if(xp)return us;xp=1;var e=Yd(),r=RC(),t=MC();function n(o){var i=-1,s=o==null?0:o.length;for(this.__data__=new e;++i<s;)this.add(o[i])}return n.prototype.add=n.prototype.push=r,n.prototype.has=t,us=n,us}var fs,vp;function TC(){if(vp)return fs;vp=1;function e(r,t){for(var n=-1,o=r==null?0:r.length;++n<o;)if(t(r[n],n,r))return!0;return!1}return fs=e,fs}var hs,wp;function kx(){if(wp)return hs;wp=1;function e(r,t){return r.has(t)}return hs=e,hs}var ps,Cp;function Px(){if(Cp)return ps;Cp=1;var e=_x(),r=TC(),t=kx(),n=1,o=2;function i(s,a,c,l,d,u){var h=c&n,p=s.length,m=a.length;if(p!=m&&!(h&&m>p))return!1;var g=u.get(s),y=u.get(a);if(g&&y)return g==a&&y==s;var b=-1,x=!0,w=c&o?new e:void 0;for(u.set(s,a),u.set(a,s);++b<p;){var v=s[b],C=a[b];if(l)var S=h?l(C,v,b,a,s,u):l(v,C,b,s,a,u);if(S!==void 0){if(S)continue;x=!1;break}if(w){if(!r(a,function(E,R){if(!t(w,R)&&(v===E||d(v,E,c,l,u)))return w.push(R)})){x=!1;break}}else if(!(v===C||d(v,C,c,l,u))){x=!1;break}}return u.delete(s),u.delete(a),x}return ps=i,ps}var gs,Sp;function IC(){if(Sp)return gs;Sp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o,i){n[++t]=[i,o]}),n}return gs=e,gs}var ys,jp;function lu(){if(jp)return ys;jp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o){n[++t]=o}),n}return ys=e,ys}var ms,Ep;function NC(){if(Ep)return ms;Ep=1;var e=hn(),r=bx(),t=fn(),n=Px(),o=IC(),i=lu(),s=1,a=2,c="[object Boolean]",l="[object Date]",d="[object Error]",u="[object Map]",h="[object Number]",p="[object RegExp]",m="[object Set]",g="[object String]",y="[object Symbol]",b="[object ArrayBuffer]",x="[object DataView]",w=e?e.prototype:void 0,v=w?w.valueOf:void 0;function C(S,E,R,P,I,M,k){switch(R){case x:if(S.byteLength!=E.byteLength||S.byteOffset!=E.byteOffset)return!1;S=S.buffer,E=E.buffer;case b:return!(S.byteLength!=E.byteLength||!M(new r(S),new r(E)));case c:case l:case h:return t(+S,+E);case d:return S.name==E.name&&S.message==E.message;case p:case g:return S==E+"";case u:var _=o;case m:var N=P&s;if(_||(_=i),S.size!=E.size&&!N)return!1;var $=k.get(S);if($)return $==E;P|=a,k.set(S,E);var D=n(_(S),_(E),P,I,M,k);return k.delete(S),D;case y:if(v)return v.call(S)==v.call(E)}return!1}return ms=C,ms}var bs,_p;function OC(){if(_p)return bs;_p=1;var e=yx(),r=1,t=Object.prototype,n=t.hasOwnProperty;function o(i,s,a,c,l,d){var u=a&r,h=e(i),p=h.length,m=e(s),g=m.length;if(p!=g&&!u)return!1;for(var y=p;y--;){var b=h[y];if(!(u?b in s:n.call(s,b)))return!1}var x=d.get(i),w=d.get(s);if(x&&w)return x==s&&w==i;var v=!0;d.set(i,s),d.set(s,i);for(var C=u;++y<p;){b=h[y];var S=i[b],E=s[b];if(c)var R=u?c(E,S,b,s,i,d):c(S,E,b,i,s,d);if(!(R===void 0?S===E||l(S,E,a,c,d):R)){v=!1;break}C||(C=b=="constructor")}if(v&&!C){var P=i.constructor,I=s.constructor;P!=I&&"constructor"in i&&"constructor"in s&&!(typeof P=="function"&&P instanceof P&&typeof I=="function"&&I instanceof I)&&(v=!1)}return d.delete(i),d.delete(s),v}return bs=o,bs}var xs,kp;function $C(){if(kp)return xs;kp=1;var e=No(),r=Px(),t=NC(),n=OC(),o=gn(),i=Ct(),s=pn(),a=Zn(),c=1,l="[object Arguments]",d="[object Array]",u="[object Object]",h=Object.prototype,p=h.hasOwnProperty;function m(g,y,b,x,w,v){var C=i(g),S=i(y),E=C?d:o(g),R=S?d:o(y);E=E==l?u:E,R=R==l?u:R;var P=E==u,I=R==u,M=E==R;if(M&&s(g)){if(!s(y))return!1;C=!0,P=!1}if(M&&!P)return v||(v=new e),C||a(g)?r(g,y,b,x,w,v):t(g,y,E,b,x,w,v);if(!(b&c)){var k=P&&p.call(g,"__wrapped__"),_=I&&p.call(y,"__wrapped__");if(k||_){var N=k?g.value():g,$=_?y.value():y;return v||(v=new e),w(N,$,b,x,v)}}return M?(v||(v=new e),n(g,y,b,x,w,v)):!1}return xs=m,xs}var vs,Pp;function Ax(){if(Pp)return vs;Pp=1;var e=$C(),r=lr();function t(n,o,i,s,a){return n===o?!0:n==null||o==null||!r(n)&&!r(o)?n!==n&&o!==o:e(n,o,i,s,t,a)}return vs=t,vs}var ws,Ap;function qC(){if(Ap)return ws;Ap=1;var e=No(),r=Ax(),t=1,n=2;function o(i,s,a,c){var l=a.length,d=l,u=!c;if(i==null)return!d;for(i=Object(i);l--;){var h=a[l];if(u&&h[2]?h[1]!==i[h[0]]:!(h[0]in i))return!1}for(;++l<d;){h=a[l];var p=h[0],m=i[p],g=h[1];if(u&&h[2]){if(m===void 0&&!(p in i))return!1}else{var y=new e;if(c)var b=c(m,g,p,i,s,y);if(!(b===void 0?r(g,m,t|n,c,y):b))return!1}}return!0}return ws=o,ws}var Cs,Rp;function Rx(){if(Rp)return Cs;Rp=1;var e=Vt();function r(t){return t===t&&!e(t)}return Cs=r,Cs}var Ss,Mp;function LC(){if(Mp)return Ss;Mp=1;var e=Rx(),r=Mr();function t(n){for(var o=r(n),i=o.length;i--;){var s=o[i],a=n[s];o[i]=[s,a,e(a)]}return o}return Ss=t,Ss}var js,Tp;function Mx(){if(Tp)return js;Tp=1;function e(r,t){return function(n){return n==null?!1:n[r]===t&&(t!==void 0||r in Object(n))}}return js=e,js}var Es,Ip;function FC(){if(Ip)return Es;Ip=1;var e=qC(),r=LC(),t=Mx();function n(o){var i=r(o);return i.length==1&&i[0][2]?t(i[0][0],i[0][1]):function(s){return s===o||e(s,o,i)}}return Es=n,Es}var _s,Np;function yn(){if(Np)return _s;Np=1;var e=Gr(),r=lr(),t="[object Symbol]";function n(o){return typeof o=="symbol"||r(o)&&e(o)==t}return _s=n,_s}var ks,Op;function du(){if(Op)return ks;Op=1;var e=Ct(),r=yn(),t=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,s){if(e(i))return!1;var a=typeof i;return a=="number"||a=="symbol"||a=="boolean"||i==null||r(i)?!0:n.test(i)||!t.test(i)||s!=null&&i in Object(s)}return ks=o,ks}var Ps,$p;function zC(){if($p)return Ps;$p=1;var e=Yd(),r="Expected a function";function t(n,o){if(typeof n!="function"||o!=null&&typeof o!="function")throw new TypeError(r);var i=function(){var s=arguments,a=o?o.apply(this,s):s[0],c=i.cache;if(c.has(a))return c.get(a);var l=n.apply(this,s);return i.cache=c.set(a,l)||c,l};return i.cache=new(t.Cache||e),i}return t.Cache=e,Ps=t,Ps}var As,qp;function BC(){if(qp)return As;qp=1;var e=zC(),r=500;function t(n){var o=e(n,function(s){return i.size===r&&i.clear(),s}),i=o.cache;return o}return As=t,As}var Rs,Lp;function DC(){if(Lp)return Rs;Lp=1;var e=BC(),r=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,t=/\\(\\)?/g,n=e(function(o){var i=[];return o.charCodeAt(0)===46&&i.push(""),o.replace(r,function(s,a,c,l){i.push(c?l.replace(t,"$1"):a||s)}),i});return Rs=n,Rs}var Ms,Fp;function Do(){if(Fp)return Ms;Fp=1;function e(r,t){for(var n=-1,o=r==null?0:r.length,i=Array(o);++n<o;)i[n]=t(r[n],n,r);return i}return Ms=e,Ms}var Ts,zp;function WC(){if(zp)return Ts;zp=1;var e=hn(),r=Do(),t=Ct(),n=yn(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function s(a){if(typeof a=="string")return a;if(t(a))return r(a,s)+"";if(n(a))return i?i.call(a):"";var c=a+"";return c=="0"&&1/a==-1/0?"-0":c}return Ts=s,Ts}var Is,Bp;function Tx(){if(Bp)return Is;Bp=1;var e=WC();function r(t){return t==null?"":e(t)}return Is=r,Is}var Ns,Dp;function Wo(){if(Dp)return Ns;Dp=1;var e=Ct(),r=du(),t=DC(),n=Tx();function o(i,s){return e(i)?i:r(i,s)?[i]:t(n(i))}return Ns=o,Ns}var Os,Wp;function Xn(){if(Wp)return Os;Wp=1;var e=yn();function r(t){if(typeof t=="string"||e(t))return t;var n=t+"";return n=="0"&&1/t==-1/0?"-0":n}return Os=r,Os}var $s,Vp;function Vo(){if(Vp)return $s;Vp=1;var e=Wo(),r=Xn();function t(n,o){o=e(o,n);for(var i=0,s=o.length;n!=null&&i<s;)n=n[r(o[i++])];return i&&i==s?n:void 0}return $s=t,$s}var qs,Gp;function VC(){if(Gp)return qs;Gp=1;var e=Vo();function r(t,n,o){var i=t==null?void 0:e(t,n);return i===void 0?o:i}return qs=r,qs}var Ls,Hp;function GC(){if(Hp)return Ls;Hp=1;function e(r,t){return r!=null&&t in Object(r)}return Ls=e,Ls}var Fs,Up;function Ix(){if(Up)return Fs;Up=1;var e=Wo(),r=Jn(),t=Ct(),n=qo(),o=eu(),i=Xn();function s(a,c,l){c=e(c,a);for(var d=-1,u=c.length,h=!1;++d<u;){var p=i(c[d]);if(!(h=a!=null&&l(a,p)))break;a=a[p]}return h||++d!=u?h:(u=a==null?0:a.length,!!u&&o(u)&&n(p,u)&&(t(a)||r(a)))}return Fs=s,Fs}var zs,Kp;function Nx(){if(Kp)return zs;Kp=1;var e=GC(),r=Ix();function t(n,o){return n!=null&&r(n,o,e)}return zs=t,zs}var Bs,Jp;function HC(){if(Jp)return Bs;Jp=1;var e=Ax(),r=VC(),t=Nx(),n=du(),o=Rx(),i=Mx(),s=Xn(),a=1,c=2;function l(d,u){return n(d)&&o(u)?i(s(d),u):function(h){var p=r(h,d);return p===void 0&&p===u?t(h,d):e(u,p,a|c)}}return Bs=l,Bs}var Ds,Zp;function Ox(){if(Zp)return Ds;Zp=1;function e(r){return function(t){return t==null?void 0:t[r]}}return Ds=e,Ds}var Ws,Xp;function UC(){if(Xp)return Ws;Xp=1;var e=Vo();function r(t){return function(n){return e(n,t)}}return Ws=r,Ws}var Vs,Yp;function KC(){if(Yp)return Vs;Yp=1;var e=Ox(),r=UC(),t=du(),n=Xn();function o(i){return t(i)?e(n(i)):r(i)}return Vs=o,Vs}var Gs,Qp;function mr(){if(Qp)return Gs;Qp=1;var e=FC(),r=HC(),t=Kr(),n=Ct(),o=KC();function i(s){return typeof s=="function"?s:s==null?t:typeof s=="object"?n(s)?r(s[0],s[1]):e(s):o(s)}return Gs=i,Gs}var Hs,eg;function $x(){if(eg)return Hs;eg=1;var e=fx(),r=AC(),t=mr(),n=Ct();function o(i,s){var a=n(i)?e:r;return a(i,t(s,3))}return Hs=o,Hs}var Us,tg;function JC(){if(tg)return Us;tg=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n,o){return n!=null&&r.call(n,o)}return Us=t,Us}var Ks,rg;function qx(){if(rg)return Ks;rg=1;var e=JC(),r=Ix();function t(n,o){return n!=null&&r(n,o,e)}return Ks=t,Ks}var Js,ng;function ZC(){if(ng)return Js;ng=1;var e=ru(),r=gn(),t=Jn(),n=Ct(),o=yr(),i=pn(),s=Fo(),a=Zn(),c="[object Map]",l="[object Set]",d=Object.prototype,u=d.hasOwnProperty;function h(p){if(p==null)return!0;if(o(p)&&(n(p)||typeof p=="string"||typeof p.splice=="function"||i(p)||a(p)||t(p)))return!p.length;var m=r(p);if(m==c||m==l)return!p.size;if(s(p))return!e(p).length;for(var g in p)if(u.call(p,g))return!1;return!0}return Js=h,Js}var Zs,og;function Lx(){if(og)return Zs;og=1;function e(r){return r===void 0}return Zs=e,Zs}var Xs,ig;function Fx(){if(ig)return Xs;ig=1;var e=Bo(),r=yr();function t(n,o){var i=-1,s=r(n)?Array(n.length):[];return e(n,function(a,c,l){s[++i]=o(a,c,l)}),s}return Xs=t,Xs}var Ys,ag;function zx(){if(ag)return Ys;ag=1;var e=Do(),r=mr(),t=Fx(),n=Ct();function o(i,s){var a=n(i)?e:t;return a(i,r(s,3))}return Ys=o,Ys}var Qs,sg;function XC(){if(sg)return Qs;sg=1;function e(r,t,n,o){var i=-1,s=r==null?0:r.length;for(o&&s&&(n=r[++i]);++i<s;)n=t(n,r[i],i,r);return n}return Qs=e,Qs}var ec,cg;function YC(){if(cg)return ec;cg=1;function e(r,t,n,o,i){return i(r,function(s,a,c){n=o?(o=!1,s):t(n,s,a,c)}),n}return ec=e,ec}var tc,lg;function Bx(){if(lg)return tc;lg=1;var e=XC(),r=Bo(),t=mr(),n=YC(),o=Ct();function i(s,a,c){var l=o(s)?e:n,d=arguments.length<3;return l(s,t(a,4),c,d,r)}return tc=i,tc}var rc,dg;function QC(){if(dg)return rc;dg=1;var e=Gr(),r=Ct(),t=lr(),n="[object String]";function o(i){return typeof i=="string"||!r(i)&&t(i)&&e(i)==n}return rc=o,rc}var nc,ug;function eS(){if(ug)return nc;ug=1;var e=Ox(),r=e("length");return nc=r,nc}var oc,fg;function tS(){if(fg)return oc;fg=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=r+t+n,i="\\ufe0e\\ufe0f",s="\\u200d",a=RegExp("["+s+e+o+i+"]");function c(l){return a.test(l)}return oc=c,oc}var ic,hg;function rS(){if(hg)return ic;hg=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=r+t+n,i="\\ufe0e\\ufe0f",s="["+e+"]",a="["+o+"]",c="\\ud83c[\\udffb-\\udfff]",l="(?:"+a+"|"+c+")",d="[^"+e+"]",u="(?:\\ud83c[\\udde6-\\uddff]){2}",h="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",m=l+"?",g="["+i+"]?",y="(?:"+p+"(?:"+[d,u,h].join("|")+")"+g+m+")*",b=g+m+y,x="(?:"+[d+a+"?",a,u,h,s].join("|")+")",w=RegExp(c+"(?="+c+")|"+x+b,"g");function v(C){for(var S=w.lastIndex=0;w.test(C);)++S;return S}return ic=v,ic}var ac,pg;function nS(){if(pg)return ac;pg=1;var e=eS(),r=tS(),t=rS();function n(o){return r(o)?t(o):e(o)}return ac=n,ac}var sc,gg;function oS(){if(gg)return sc;gg=1;var e=ru(),r=gn(),t=yr(),n=QC(),o=nS(),i="[object Map]",s="[object Set]";function a(c){if(c==null)return 0;if(t(c))return n(c)?o(c):c.length;var l=r(c);return l==i||l==s?c.size:e(c).length}return sc=a,sc}var cc,yg;function iS(){if(yg)return cc;yg=1;var e=Qd(),r=vx(),t=cu(),n=mr(),o=zo(),i=Ct(),s=pn(),a=Un(),c=Vt(),l=Zn();function d(u,h,p){var m=i(u),g=m||s(u)||l(u);if(h=n(h,4),p==null){var y=u&&u.constructor;g?p=m?new y:[]:c(u)?p=a(y)?r(o(u)):{}:p={}}return(g?e:t)(u,function(b,x,w){return h(p,b,x,w)}),p}return cc=d,cc}var lc,mg;function aS(){if(mg)return lc;mg=1;var e=hn(),r=Jn(),t=Ct(),n=e?e.isConcatSpreadable:void 0;function o(i){return t(i)||r(i)||!!(n&&i&&i[n])}return lc=o,lc}var dc,bg;function uu(){if(bg)return dc;bg=1;var e=ou(),r=aS();function t(n,o,i,s,a){var c=-1,l=n.length;for(i||(i=r),a||(a=[]);++c<l;){var d=n[c];o>0&&i(d)?o>1?t(d,o-1,i,s,a):e(a,d):s||(a[a.length]=d)}return a}return dc=t,dc}var uc,xg;function sS(){if(xg)return uc;xg=1;function e(r,t,n){switch(n.length){case 0:return r.call(t);case 1:return r.call(t,n[0]);case 2:return r.call(t,n[0],n[1]);case 3:return r.call(t,n[0],n[1],n[2])}return r.apply(t,n)}return uc=e,uc}var fc,vg;function Dx(){if(vg)return fc;vg=1;var e=sS(),r=Math.max;function t(n,o,i){return o=r(o===void 0?n.length-1:o,0),function(){for(var s=arguments,a=-1,c=r(s.length-o,0),l=Array(c);++a<c;)l[a]=s[o+a];a=-1;for(var d=Array(o+1);++a<o;)d[a]=s[a];return d[o]=i(l),e(n,this,d)}}return fc=t,fc}var hc,wg;function cS(){if(wg)return hc;wg=1;var e=au(),r=sx(),t=Kr(),n=r?function(o,i){return r(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:t;return hc=n,hc}var pc,Cg;function lS(){if(Cg)return pc;Cg=1;var e=800,r=16,t=Date.now;function n(o){var i=0,s=0;return function(){var a=t(),c=r-(a-s);if(s=a,c>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return pc=n,pc}var gc,Sg;function Wx(){if(Sg)return gc;Sg=1;var e=cS(),r=lS(),t=r(e);return gc=t,gc}var yc,jg;function Go(){if(jg)return yc;jg=1;var e=Kr(),r=Dx(),t=Wx();function n(o,i){return t(r(o,i,e),o+"")}return yc=n,yc}var mc,Eg;function Vx(){if(Eg)return mc;Eg=1;function e(r,t,n,o){for(var i=r.length,s=n+(o?1:-1);o?s--:++s<i;)if(t(r[s],s,r))return s;return-1}return mc=e,mc}var bc,_g;function dS(){if(_g)return bc;_g=1;function e(r){return r!==r}return bc=e,bc}var xc,kg;function uS(){if(kg)return xc;kg=1;function e(r,t,n){for(var o=n-1,i=r.length;++o<i;)if(r[o]===t)return o;return-1}return xc=e,xc}var vc,Pg;function fS(){if(Pg)return vc;Pg=1;var e=Vx(),r=dS(),t=uS();function n(o,i,s){return i===i?t(o,i,s):e(o,r,s)}return vc=n,vc}var wc,Ag;function hS(){if(Ag)return wc;Ag=1;var e=fS();function r(t,n){var o=t==null?0:t.length;return!!o&&e(t,n,0)>-1}return wc=r,wc}var Cc,Rg;function pS(){if(Rg)return Cc;Rg=1;function e(r,t,n){for(var o=-1,i=r==null?0:r.length;++o<i;)if(n(t,r[o]))return!0;return!1}return Cc=e,Cc}var Sc,Mg;function gS(){if(Mg)return Sc;Mg=1;function e(){}return Sc=e,Sc}var jc,Tg;function yS(){if(Tg)return jc;Tg=1;var e=mx(),r=gS(),t=lu(),n=1/0,o=e&&1/t(new e([,-0]))[1]==n?function(i){return new e(i)}:r;return jc=o,jc}var Ec,Ig;function mS(){if(Ig)return Ec;Ig=1;var e=_x(),r=hS(),t=pS(),n=kx(),o=yS(),i=lu(),s=200;function a(c,l,d){var u=-1,h=r,p=c.length,m=!0,g=[],y=g;if(d)m=!1,h=t;else if(p>=s){var b=l?null:o(c);if(b)return i(b);m=!1,h=n,y=new e}else y=l?[]:g;e:for(;++u<p;){var x=c[u],w=l?l(x):x;if(x=d||x!==0?x:0,m&&w===w){for(var v=y.length;v--;)if(y[v]===w)continue e;l&&y.push(w),g.push(x)}else h(y,w,d)||(y!==g&&y.push(w),g.push(x))}return g}return Ec=a,Ec}var _c,Ng;function Gx(){if(Ng)return _c;Ng=1;var e=yr(),r=lr();function t(n){return r(n)&&e(n)}return _c=t,_c}var kc,Og;function bS(){if(Og)return kc;Og=1;var e=uu(),r=Go(),t=mS(),n=Gx(),o=r(function(i){return t(e(i,1,n,!0))});return kc=o,kc}var Pc,$g;function xS(){if($g)return Pc;$g=1;var e=Do();function r(t,n){return e(n,function(o){return t[o]})}return Pc=r,Pc}var Ac,qg;function Hx(){if(qg)return Ac;qg=1;var e=xS(),r=Mr();function t(n){return n==null?[]:e(n,r(n))}return Ac=t,Ac}var Rc,Lg;function Gt(){if(Lg)return Rc;Lg=1;var e;if(typeof Zd=="function")try{e={clone:_C(),constant:au(),each:Ex(),filter:$x(),has:qx(),isArray:Ct(),isEmpty:ZC(),isFunction:Un(),isUndefined:Lx(),keys:Mr(),map:zx(),reduce:Bx(),size:oS(),transform:iS(),union:bS(),values:Hx()}}catch{}return e||(e=window._),Rc=e,Rc}var Mc,Fg;function fu(){if(Fg)return Mc;Fg=1;var e=Gt();Mc=o;var r="\0",t="\0",n="";function o(d){this._isDirected=e.has(d,"directed")?d.directed:!0,this._isMultigraph=e.has(d,"multigraph")?d.multigraph:!1,this._isCompound=e.has(d,"compound")?d.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[t]={}),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(d){return this._label=d,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultNodeLabelFn=d,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._in[u])})},o.prototype.sinks=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._out[u])})},o.prototype.setNodes=function(d,u){var h=arguments,p=this;return e.each(d,function(m){h.length>1?p.setNode(m,u):p.setNode(m)}),this},o.prototype.setNode=function(d,u){return e.has(this._nodes,d)?(arguments.length>1&&(this._nodes[d]=u),this):(this._nodes[d]=arguments.length>1?u:this._defaultNodeLabelFn(d),this._isCompound&&(this._parent[d]=t,this._children[d]={},this._children[t][d]=!0),this._in[d]={},this._preds[d]={},this._out[d]={},this._sucs[d]={},++this._nodeCount,this)},o.prototype.node=function(d){return this._nodes[d]},o.prototype.hasNode=function(d){return e.has(this._nodes,d)},o.prototype.removeNode=function(d){var u=this;if(e.has(this._nodes,d)){var h=function(p){u.removeEdge(u._edgeObjs[p])};delete this._nodes[d],this._isCompound&&(this._removeFromParentsChildList(d),delete this._parent[d],e.each(this.children(d),function(p){u.setParent(p)}),delete this._children[d]),e.each(e.keys(this._in[d]),h),delete this._in[d],delete this._preds[d],e.each(e.keys(this._out[d]),h),delete this._out[d],delete this._sucs[d],--this._nodeCount}return this},o.prototype.setParent=function(d,u){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(u))u=t;else{u+="";for(var h=u;!e.isUndefined(h);h=this.parent(h))if(h===d)throw new Error("Setting "+u+" as parent of "+d+" would create a cycle");this.setNode(u)}return this.setNode(d),this._removeFromParentsChildList(d),this._parent[d]=u,this._children[u][d]=!0,this},o.prototype._removeFromParentsChildList=function(d){delete this._children[this._parent[d]][d]},o.prototype.parent=function(d){if(this._isCompound){var u=this._parent[d];if(u!==t)return u}},o.prototype.children=function(d){if(e.isUndefined(d)&&(d=t),this._isCompound){var u=this._children[d];if(u)return e.keys(u)}else{if(d===t)return this.nodes();if(this.hasNode(d))return[]}},o.prototype.predecessors=function(d){var u=this._preds[d];if(u)return e.keys(u)},o.prototype.successors=function(d){var u=this._sucs[d];if(u)return e.keys(u)},o.prototype.neighbors=function(d){var u=this.predecessors(d);if(u)return e.union(u,this.successors(d))},o.prototype.isLeaf=function(d){var u;return this.isDirected()?u=this.successors(d):u=this.neighbors(d),u.length===0},o.prototype.filterNodes=function(d){var u=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});u.setGraph(this.graph());var h=this;e.each(this._nodes,function(g,y){d(y)&&u.setNode(y,g)}),e.each(this._edgeObjs,function(g){u.hasNode(g.v)&&u.hasNode(g.w)&&u.setEdge(g,h.edge(g))});var p={};function m(g){var y=h.parent(g);return y===void 0||u.hasNode(y)?(p[g]=y,y):y in p?p[y]:m(y)}return this._isCompound&&e.each(u.nodes(),function(g){u.setParent(g,m(g))}),u},o.prototype.setDefaultEdgeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultEdgeLabelFn=d,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(d,u){var h=this,p=arguments;return e.reduce(d,function(m,g){return p.length>1?h.setEdge(m,g,u):h.setEdge(m,g),g}),this},o.prototype.setEdge=function(){var d,u,h,p,m=!1,g=arguments[0];typeof g=="object"&&g!==null&&"v"in g?(d=g.v,u=g.w,h=g.name,arguments.length===2&&(p=arguments[1],m=!0)):(d=g,u=arguments[1],h=arguments[3],arguments.length>2&&(p=arguments[2],m=!0)),d=""+d,u=""+u,e.isUndefined(h)||(h=""+h);var y=a(this._isDirected,d,u,h);if(e.has(this._edgeLabels,y))return m&&(this._edgeLabels[y]=p),this;if(!e.isUndefined(h)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(d),this.setNode(u),this._edgeLabels[y]=m?p:this._defaultEdgeLabelFn(d,u,h);var b=c(this._isDirected,d,u,h);return d=b.v,u=b.w,Object.freeze(b),this._edgeObjs[y]=b,i(this._preds[u],d),i(this._sucs[d],u),this._in[u][y]=b,this._out[d][y]=b,this._edgeCount++,this},o.prototype.edge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h);return this._edgeLabels[p]},o.prototype.hasEdge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h);return e.has(this._edgeLabels,p)},o.prototype.removeEdge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h),m=this._edgeObjs[p];return m&&(d=m.v,u=m.w,delete this._edgeLabels[p],delete this._edgeObjs[p],s(this._preds[u],d),s(this._sucs[d],u),delete this._in[u][p],delete this._out[d][p],this._edgeCount--),this},o.prototype.inEdges=function(d,u){var h=this._in[d];if(h){var p=e.values(h);return u?e.filter(p,function(m){return m.v===u}):p}},o.prototype.outEdges=function(d,u){var h=this._out[d];if(h){var p=e.values(h);return u?e.filter(p,function(m){return m.w===u}):p}},o.prototype.nodeEdges=function(d,u){var h=this.inEdges(d,u);if(h)return h.concat(this.outEdges(d,u))};function i(d,u){d[u]?d[u]++:d[u]=1}function s(d,u){--d[u]||delete d[u]}function a(d,u,h,p){var m=""+u,g=""+h;if(!d&&m>g){var y=m;m=g,g=y}return m+n+g+n+(e.isUndefined(p)?r:p)}function c(d,u,h,p){var m=""+u,g=""+h;if(!d&&m>g){var y=m;m=g,g=y}var b={v:m,w:g};return p&&(b.name=p),b}function l(d,u){return a(d,u.v,u.w,u.name)}return Mc}var Tc,zg;function vS(){return zg||(zg=1,Tc="2.1.8"),Tc}var Ic,Bg;function wS(){return Bg||(Bg=1,Ic={Graph:fu(),version:vS()}),Ic}var Nc,Dg;function CS(){if(Dg)return Nc;Dg=1;var e=Gt(),r=fu();Nc={write:t,read:i};function t(s){var a={options:{directed:s.isDirected(),multigraph:s.isMultigraph(),compound:s.isCompound()},nodes:n(s),edges:o(s)};return e.isUndefined(s.graph())||(a.value=e.clone(s.graph())),a}function n(s){return e.map(s.nodes(),function(a){var c=s.node(a),l=s.parent(a),d={v:a};return e.isUndefined(c)||(d.value=c),e.isUndefined(l)||(d.parent=l),d})}function o(s){return e.map(s.edges(),function(a){var c=s.edge(a),l={v:a.v,w:a.w};return e.isUndefined(a.name)||(l.name=a.name),e.isUndefined(c)||(l.value=c),l})}function i(s){var a=new r(s.options).setGraph(s.value);return e.each(s.nodes,function(c){a.setNode(c.v,c.value),c.parent&&a.setParent(c.v,c.parent)}),e.each(s.edges,function(c){a.setEdge({v:c.v,w:c.w,name:c.name},c.value)}),a}return Nc}var Oc,Wg;function SS(){if(Wg)return Oc;Wg=1;var e=Gt();Oc=r;function r(t){var n={},o=[],i;function s(a){e.has(n,a)||(n[a]=!0,i.push(a),e.each(t.successors(a),s),e.each(t.predecessors(a),s))}return e.each(t.nodes(),function(a){i=[],s(a),i.length&&o.push(i)}),o}return Oc}var $c,Vg;function Ux(){if(Vg)return $c;Vg=1;var e=Gt();$c=r;function r(){this._arr=[],this._keyIndices={}}return r.prototype.size=function(){return this._arr.length},r.prototype.keys=function(){return this._arr.map(function(t){return t.key})},r.prototype.has=function(t){return e.has(this._keyIndices,t)},r.prototype.priority=function(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority},r.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},r.prototype.add=function(t,n){var o=this._keyIndices;if(t=String(t),!e.has(o,t)){var i=this._arr,s=i.length;return o[t]=s,i.push({key:t,priority:n}),this._decrease(s),!0}return!1},r.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key},r.prototype.decrease=function(t,n){var o=this._keyIndices[t];if(n>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[o].priority+" New: "+n);this._arr[o].priority=n,this._decrease(o)},r.prototype._heapify=function(t){var n=this._arr,o=2*t,i=o+1,s=t;o<n.length&&(s=n[o].priority<n[s].priority?o:s,i<n.length&&(s=n[i].priority<n[s].priority?i:s),s!==t&&(this._swap(t,s),this._heapify(s)))},r.prototype._decrease=function(t){for(var n=this._arr,o=n[t].priority,i;t!==0&&(i=t>>1,!(n[i].priority<o));)this._swap(t,i),t=i},r.prototype._swap=function(t,n){var o=this._arr,i=this._keyIndices,s=o[t],a=o[n];o[t]=a,o[n]=s,i[a.key]=t,i[s.key]=n},$c}var qc,Gg;function Kx(){if(Gg)return qc;Gg=1;var e=Gt(),r=Ux();qc=n;var t=e.constant(1);function n(i,s,a,c){return o(i,String(s),a||t,c||function(l){return i.outEdges(l)})}function o(i,s,a,c){var l={},d=new r,u,h,p=function(m){var g=m.v!==u?m.v:m.w,y=l[g],b=a(m),x=h.distance+b;if(b<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+m+" Weight: "+b);x<y.distance&&(y.distance=x,y.predecessor=u,d.decrease(g,x))};for(i.nodes().forEach(function(m){var g=m===s?0:Number.POSITIVE_INFINITY;l[m]={distance:g},d.add(m,g)});d.size()>0&&(u=d.removeMin(),h=l[u],h.distance!==Number.POSITIVE_INFINITY);)c(u).forEach(p);return l}return qc}var Lc,Hg;function jS(){if(Hg)return Lc;Hg=1;var e=Kx(),r=Gt();Lc=t;function t(n,o,i){return r.transform(n.nodes(),function(s,a){s[a]=e(n,a,o,i)},{})}return Lc}var Fc,Ug;function Jx(){if(Ug)return Fc;Ug=1;var e=Gt();Fc=r;function r(t){var n=0,o=[],i={},s=[];function a(c){var l=i[c]={onStack:!0,lowlink:n,index:n++};if(o.push(c),t.successors(c).forEach(function(h){e.has(i,h)?i[h].onStack&&(l.lowlink=Math.min(l.lowlink,i[h].index)):(a(h),l.lowlink=Math.min(l.lowlink,i[h].lowlink))}),l.lowlink===l.index){var d=[],u;do u=o.pop(),i[u].onStack=!1,d.push(u);while(c!==u);s.push(d)}}return t.nodes().forEach(function(c){e.has(i,c)||a(c)}),s}return Fc}var zc,Kg;function ES(){if(Kg)return zc;Kg=1;var e=Gt(),r=Jx();zc=t;function t(n){return e.filter(r(n),function(o){return o.length>1||o.length===1&&n.hasEdge(o[0],o[0])})}return zc}var Bc,Jg;function _S(){if(Jg)return Bc;Jg=1;var e=Gt();Bc=t;var r=e.constant(1);function t(o,i,s){return n(o,i||r,s||function(a){return o.outEdges(a)})}function n(o,i,s){var a={},c=o.nodes();return c.forEach(function(l){a[l]={},a[l][l]={distance:0},c.forEach(function(d){l!==d&&(a[l][d]={distance:Number.POSITIVE_INFINITY})}),s(l).forEach(function(d){var u=d.v===l?d.w:d.v,h=i(d);a[l][u]={distance:h,predecessor:l}})}),c.forEach(function(l){var d=a[l];c.forEach(function(u){var h=a[u];c.forEach(function(p){var m=h[l],g=d[p],y=h[p],b=m.distance+g.distance;b<y.distance&&(y.distance=b,y.predecessor=g.predecessor)})})}),a}return Bc}var Dc,Zg;function Zx(){if(Zg)return Dc;Zg=1;var e=Gt();Dc=r,r.CycleException=t;function r(n){var o={},i={},s=[];function a(c){if(e.has(i,c))throw new t;e.has(o,c)||(i[c]=!0,o[c]=!0,e.each(n.predecessors(c),a),delete i[c],s.push(c))}if(e.each(n.sinks(),a),e.size(o)!==n.nodeCount())throw new t;return s}function t(){}return t.prototype=new Error,Dc}var Wc,Xg;function kS(){if(Xg)return Wc;Xg=1;var e=Zx();Wc=r;function r(t){try{e(t)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Wc}var Vc,Yg;function Xx(){if(Yg)return Vc;Yg=1;var e=Gt();Vc=r;function r(n,o,i){e.isArray(o)||(o=[o]);var s=(n.isDirected()?n.successors:n.neighbors).bind(n),a=[],c={};return e.each(o,function(l){if(!n.hasNode(l))throw new Error("Graph does not have node: "+l);t(n,l,i==="post",c,s,a)}),a}function t(n,o,i,s,a,c){e.has(s,o)||(s[o]=!0,i||c.push(o),e.each(a(o),function(l){t(n,l,i,s,a,c)}),i&&c.push(o))}return Vc}var Gc,Qg;function PS(){if(Qg)return Gc;Qg=1;var e=Xx();Gc=r;function r(t,n){return e(t,n,"post")}return Gc}var Hc,ey;function AS(){if(ey)return Hc;ey=1;var e=Xx();Hc=r;function r(t,n){return e(t,n,"pre")}return Hc}var Uc,ty;function RS(){if(ty)return Uc;ty=1;var e=Gt(),r=fu(),t=Ux();Uc=n;function n(o,i){var s=new r,a={},c=new t,l;function d(h){var p=h.v===l?h.w:h.v,m=c.priority(p);if(m!==void 0){var g=i(h);g<m&&(a[p]=l,c.decrease(p,g))}}if(o.nodeCount()===0)return s;e.each(o.nodes(),function(h){c.add(h,Number.POSITIVE_INFINITY),s.setNode(h)}),c.decrease(o.nodes()[0],0);for(var u=!1;c.size()>0;){if(l=c.removeMin(),e.has(a,l))s.setEdge(l,a[l]);else{if(u)throw new Error("Input graph is not connected: "+o);u=!0}o.nodeEdges(l).forEach(d)}return s}return Uc}var Kc,ry;function MS(){return ry||(ry=1,Kc={components:SS(),dijkstra:Kx(),dijkstraAll:jS(),findCycles:ES(),floydWarshall:_S(),isAcyclic:kS(),postorder:PS(),preorder:AS(),prim:RS(),tarjan:Jx(),topsort:Zx()}),Kc}var Jc,ny;function TS(){if(ny)return Jc;ny=1;var e=wS();return Jc={Graph:e.Graph,json:CS(),alg:MS(),version:e.version},Jc}var Zc,oy;function Zt(){if(oy)return Zc;oy=1;var e;if(typeof Zd=="function")try{e=TS()}catch{}return e||(e=window.graphlib),Zc=e,Zc}var Xc,iy;function IS(){if(iy)return Xc;iy=1;var e=Cx(),r=1,t=4;function n(o){return e(o,r|t)}return Xc=n,Xc}var Yc,ay;function Ho(){if(ay)return Yc;ay=1;var e=fn(),r=yr(),t=qo(),n=Vt();function o(i,s,a){if(!n(a))return!1;var c=typeof s;return(c=="number"?r(a)&&t(s,a.length):c=="string"&&s in a)?e(a[s],i):!1}return Yc=o,Yc}var Qc,sy;function NS(){if(sy)return Qc;sy=1;var e=Go(),r=fn(),t=Ho(),n=Ur(),o=Object.prototype,i=o.hasOwnProperty,s=e(function(a,c){a=Object(a);var l=-1,d=c.length,u=d>2?c[2]:void 0;for(u&&t(c[0],c[1],u)&&(d=1);++l<d;)for(var h=c[l],p=n(h),m=-1,g=p.length;++m<g;){var y=p[m],b=a[y];(b===void 0||r(b,o[y])&&!i.call(a,y))&&(a[y]=h[y])}return a});return Qc=s,Qc}var el,cy;function OS(){if(cy)return el;cy=1;var e=mr(),r=yr(),t=Mr();function n(o){return function(i,s,a){var c=Object(i);if(!r(i)){var l=e(s,3);i=t(i),s=function(u){return l(c[u],u,c)}}var d=o(i,s,a);return d>-1?c[l?i[d]:d]:void 0}}return el=n,el}var tl,ly;function $S(){if(ly)return tl;ly=1;var e=/\s/;function r(t){for(var n=t.length;n--&&e.test(t.charAt(n)););return n}return tl=r,tl}var rl,dy;function qS(){if(dy)return rl;dy=1;var e=$S(),r=/^\s+/;function t(n){return n&&n.slice(0,e(n)+1).replace(r,"")}return rl=t,rl}var nl,uy;function LS(){if(uy)return nl;uy=1;var e=qS(),r=Vt(),t=yn(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,s=/^0o[0-7]+$/i,a=parseInt;function c(l){if(typeof l=="number")return l;if(t(l))return n;if(r(l)){var d=typeof l.valueOf=="function"?l.valueOf():l;l=r(d)?d+"":d}if(typeof l!="string")return l===0?l:+l;l=e(l);var u=i.test(l);return u||s.test(l)?a(l.slice(2),u?2:8):o.test(l)?n:+l}return nl=c,nl}var ol,fy;function Yx(){if(fy)return ol;fy=1;var e=LS(),r=1/0,t=17976931348623157e292;function n(o){if(!o)return o===0?o:0;if(o=e(o),o===r||o===-r){var i=o<0?-1:1;return i*t}return o===o?o:0}return ol=n,ol}var il,hy;function FS(){if(hy)return il;hy=1;var e=Yx();function r(t){var n=e(t),o=n%1;return n===n?o?n-o:n:0}return il=r,il}var al,py;function zS(){if(py)return al;py=1;var e=Vx(),r=mr(),t=FS(),n=Math.max;function o(i,s,a){var c=i==null?0:i.length;if(!c)return-1;var l=a==null?0:t(a);return l<0&&(l=n(c+l,0)),e(i,r(s,3),l)}return al=o,al}var sl,gy;function BS(){if(gy)return sl;gy=1;var e=OS(),r=zS(),t=e(r);return sl=t,sl}var cl,yy;function Qx(){if(yy)return cl;yy=1;var e=uu();function r(t){var n=t==null?0:t.length;return n?e(t,1):[]}return cl=r,cl}var ll,my;function DS(){if(my)return ll;my=1;var e=su(),r=Sx(),t=Ur();function n(o,i){return o==null?o:e(o,r(i),t)}return ll=n,ll}var dl,by;function WS(){if(by)return dl;by=1;function e(r){var t=r==null?0:r.length;return t?r[t-1]:void 0}return dl=e,dl}var ul,xy;function VS(){if(xy)return ul;xy=1;var e=Oo(),r=cu(),t=mr();function n(o,i){var s={};return i=t(i,3),r(o,function(a,c,l){e(s,c,i(a,c,l))}),s}return ul=n,ul}var fl,vy;function hu(){if(vy)return fl;vy=1;var e=yn();function r(t,n,o){for(var i=-1,s=t.length;++i<s;){var a=t[i],c=n(a);if(c!=null&&(l===void 0?c===c&&!e(c):o(c,l)))var l=c,d=a}return d}return fl=r,fl}var hl,wy;function GS(){if(wy)return hl;wy=1;function e(r,t){return r>t}return hl=e,hl}var pl,Cy;function HS(){if(Cy)return pl;Cy=1;var e=hu(),r=GS(),t=Kr();function n(o){return o&&o.length?e(o,t,r):void 0}return pl=n,pl}var gl,Sy;function ev(){if(Sy)return gl;Sy=1;var e=Oo(),r=fn();function t(n,o,i){(i!==void 0&&!r(n[o],i)||i===void 0&&!(o in n))&&e(n,o,i)}return gl=t,gl}var yl,jy;function US(){if(jy)return yl;jy=1;var e=Gr(),r=zo(),t=lr(),n="[object Object]",o=Function.prototype,i=Object.prototype,s=o.toString,a=i.hasOwnProperty,c=s.call(Object);function l(d){if(!t(d)||e(d)!=n)return!1;var u=r(d);if(u===null)return!0;var h=a.call(u,"constructor")&&u.constructor;return typeof h=="function"&&h instanceof h&&s.call(h)==c}return yl=l,yl}var ml,Ey;function tv(){if(Ey)return ml;Ey=1;function e(r,t){if(!(t==="constructor"&&typeof r[t]=="function")&&t!="__proto__")return r[t]}return ml=e,ml}var bl,_y;function KS(){if(_y)return bl;_y=1;var e=Kn(),r=Ur();function t(n){return e(n,r(n))}return bl=t,bl}var xl,ky;function JS(){if(ky)return xl;ky=1;var e=ev(),r=dx(),t=xx(),n=ux(),o=wx(),i=Jn(),s=Ct(),a=Gx(),c=pn(),l=Un(),d=Vt(),u=US(),h=Zn(),p=tv(),m=KS();function g(y,b,x,w,v,C,S){var E=p(y,x),R=p(b,x),P=S.get(R);if(P){e(y,x,P);return}var I=C?C(E,R,x+"",y,b,S):void 0,M=I===void 0;if(M){var k=s(R),_=!k&&c(R),N=!k&&!_&&h(R);I=R,k||_||N?s(E)?I=E:a(E)?I=n(E):_?(M=!1,I=r(R,!0)):N?(M=!1,I=t(R,!0)):I=[]:u(R)||i(R)?(I=E,i(E)?I=m(E):(!d(E)||l(E))&&(I=o(R))):M=!1}M&&(S.set(R,I),v(I,R,w,C,S),S.delete(R)),e(y,x,I)}return xl=g,xl}var vl,Py;function ZS(){if(Py)return vl;Py=1;var e=No(),r=ev(),t=su(),n=JS(),o=Vt(),i=Ur(),s=tv();function a(c,l,d,u,h){c!==l&&t(l,function(p,m){if(h||(h=new e),o(p))n(c,l,m,d,a,u,h);else{var g=u?u(s(c,m),p,m+"",c,l,h):void 0;g===void 0&&(g=p),r(c,m,g)}},i)}return vl=a,vl}var wl,Ay;function XS(){if(Ay)return wl;Ay=1;var e=Go(),r=Ho();function t(n){return e(function(o,i){var s=-1,a=i.length,c=a>1?i[a-1]:void 0,l=a>2?i[2]:void 0;for(c=n.length>3&&typeof c=="function"?(a--,c):void 0,l&&r(i[0],i[1],l)&&(c=a<3?void 0:c,a=1),o=Object(o);++s<a;){var d=i[s];d&&n(o,d,s,c)}return o})}return wl=t,wl}var Cl,Ry;function YS(){if(Ry)return Cl;Ry=1;var e=ZS(),r=XS(),t=r(function(n,o,i){e(n,o,i)});return Cl=t,Cl}var Sl,My;function rv(){if(My)return Sl;My=1;function e(r,t){return r<t}return Sl=e,Sl}var jl,Ty;function QS(){if(Ty)return jl;Ty=1;var e=hu(),r=rv(),t=Kr();function n(o){return o&&o.length?e(o,t,r):void 0}return jl=n,jl}var El,Iy;function ej(){if(Iy)return El;Iy=1;var e=hu(),r=mr(),t=rv();function n(o,i){return o&&o.length?e(o,r(i,2),t):void 0}return El=n,El}var _l,Ny;function tj(){if(Ny)return _l;Ny=1;var e=Yt(),r=function(){return e.Date.now()};return _l=r,_l}var kl,Oy;function rj(){if(Oy)return kl;Oy=1;var e=$o(),r=Wo(),t=qo(),n=Vt(),o=Xn();function i(s,a,c,l){if(!n(s))return s;a=r(a,s);for(var d=-1,u=a.length,h=u-1,p=s;p!=null&&++d<u;){var m=o(a[d]),g=c;if(m==="__proto__"||m==="constructor"||m==="prototype")return s;if(d!=h){var y=p[m];g=l?l(y,m,p):void 0,g===void 0&&(g=n(y)?y:t(a[d+1])?[]:{})}e(p,m,g),p=p[m]}return s}return kl=i,kl}var Pl,$y;function nj(){if($y)return Pl;$y=1;var e=Vo(),r=rj(),t=Wo();function n(o,i,s){for(var a=-1,c=i.length,l={};++a<c;){var d=i[a],u=e(o,d);s(u,d)&&r(l,t(d,o),u)}return l}return Pl=n,Pl}var Al,qy;function oj(){if(qy)return Al;qy=1;var e=nj(),r=Nx();function t(n,o){return e(n,o,function(i,s){return r(n,s)})}return Al=t,Al}var Rl,Ly;function ij(){if(Ly)return Rl;Ly=1;var e=Qx(),r=Dx(),t=Wx();function n(o){return t(r(o,void 0,e),o+"")}return Rl=n,Rl}var Ml,Fy;function aj(){if(Fy)return Ml;Fy=1;var e=oj(),r=ij(),t=r(function(n,o){return n==null?{}:e(n,o)});return Ml=t,Ml}var Tl,zy;function sj(){if(zy)return Tl;zy=1;var e=Math.ceil,r=Math.max;function t(n,o,i,s){for(var a=-1,c=r(e((o-n)/(i||1)),0),l=Array(c);c--;)l[s?c:++a]=n,n+=i;return l}return Tl=t,Tl}var Il,By;function cj(){if(By)return Il;By=1;var e=sj(),r=Ho(),t=Yx();function n(o){return function(i,s,a){return a&&typeof a!="number"&&r(i,s,a)&&(s=a=void 0),i=t(i),s===void 0?(s=i,i=0):s=t(s),a=a===void 0?i<s?1:-1:t(a),e(i,s,a,o)}}return Il=n,Il}var Nl,Dy;function lj(){if(Dy)return Nl;Dy=1;var e=cj(),r=e();return Nl=r,Nl}var Ol,Wy;function dj(){if(Wy)return Ol;Wy=1;function e(r,t){var n=r.length;for(r.sort(t);n--;)r[n]=r[n].value;return r}return Ol=e,Ol}var $l,Vy;function uj(){if(Vy)return $l;Vy=1;var e=yn();function r(t,n){if(t!==n){var o=t!==void 0,i=t===null,s=t===t,a=e(t),c=n!==void 0,l=n===null,d=n===n,u=e(n);if(!l&&!u&&!a&&t>n||a&&c&&d&&!l&&!u||i&&c&&d||!o&&d||!s)return 1;if(!i&&!a&&!u&&t<n||u&&o&&s&&!i&&!a||l&&o&&s||!c&&s||!d)return-1}return 0}return $l=r,$l}var ql,Gy;function fj(){if(Gy)return ql;Gy=1;var e=uj();function r(t,n,o){for(var i=-1,s=t.criteria,a=n.criteria,c=s.length,l=o.length;++i<c;){var d=e(s[i],a[i]);if(d){if(i>=l)return d;var u=o[i];return d*(u=="desc"?-1:1)}}return t.index-n.index}return ql=r,ql}var Ll,Hy;function hj(){if(Hy)return Ll;Hy=1;var e=Do(),r=Vo(),t=mr(),n=Fx(),o=dj(),i=Lo(),s=fj(),a=Kr(),c=Ct();function l(d,u,h){u.length?u=e(u,function(g){return c(g)?function(y){return r(y,g.length===1?g[0]:g)}:g}):u=[a];var p=-1;u=e(u,i(t));var m=n(d,function(g,y,b){var x=e(u,function(w){return w(g)});return{criteria:x,index:++p,value:g}});return o(m,function(g,y){return s(g,y,h)})}return Ll=l,Ll}var Fl,Uy;function pj(){if(Uy)return Fl;Uy=1;var e=uu(),r=hj(),t=Go(),n=Ho(),o=t(function(i,s){if(i==null)return[];var a=s.length;return a>1&&n(i,s[0],s[1])?s=[]:a>2&&n(s[0],s[1],s[2])&&(s=[s[0]]),r(i,e(s,1),[])});return Fl=o,Fl}var zl,Ky;function gj(){if(Ky)return zl;Ky=1;var e=Tx(),r=0;function t(n){var o=++r;return e(n)+o}return zl=t,zl}var Bl,Jy;function yj(){if(Jy)return Bl;Jy=1;function e(r,t,n){for(var o=-1,i=r.length,s=t.length,a={};++o<i;){var c=o<s?t[o]:void 0;n(a,r[o],c)}return a}return Bl=e,Bl}var Dl,Zy;function mj(){if(Zy)return Dl;Zy=1;var e=$o(),r=yj();function t(n,o){return r(n||[],o||[],e)}return Dl=t,Dl}var Wl,Xy;function yt(){if(Xy)return Wl;Xy=1;var e;if(typeof Zd=="function")try{e={cloneDeep:IS(),constant:au(),defaults:NS(),each:Ex(),filter:$x(),find:BS(),flatten:Qx(),forEach:jx(),forIn:DS(),has:qx(),isUndefined:Lx(),last:WS(),map:zx(),mapValues:VS(),max:HS(),merge:YS(),min:QS(),minBy:ej(),now:tj(),pick:aj(),range:lj(),reduce:Bx(),sortBy:pj(),uniqueId:gj(),values:Hx(),zipObject:mj()}}catch{}return e||(e=window._),Wl=e,Wl}var Vl,Yy;function bj(){if(Yy)return Vl;Yy=1,Vl=e;function e(){var n={};n._next=n._prev=n,this._sentinel=n}e.prototype.dequeue=function(){var n=this._sentinel,o=n._prev;if(o!==n)return r(o),o},e.prototype.enqueue=function(n){var o=this._sentinel;n._prev&&n._next&&r(n),n._next=o._next,o._next._prev=n,o._next=n,n._prev=o},e.prototype.toString=function(){for(var n=[],o=this._sentinel,i=o._prev;i!==o;)n.push(JSON.stringify(i,t)),i=i._prev;return"["+n.join(", ")+"]"};function r(n){n._prev._next=n._next,n._next._prev=n._prev,delete n._next,delete n._prev}function t(n,o){if(n!=="_next"&&n!=="_prev")return o}return Vl}var Gl,Qy;function xj(){if(Qy)return Gl;Qy=1;var e=yt(),r=Zt().Graph,t=bj();Gl=o;var n=e.constant(1);function o(l,d){if(l.nodeCount()<=1)return[];var u=a(l,d||n),h=i(u.graph,u.buckets,u.zeroIdx);return e.flatten(e.map(h,function(p){return l.outEdges(p.v,p.w)}),!0)}function i(l,d,u){for(var h=[],p=d[d.length-1],m=d[0],g;l.nodeCount();){for(;g=m.dequeue();)s(l,d,u,g);for(;g=p.dequeue();)s(l,d,u,g);if(l.nodeCount()){for(var y=d.length-2;y>0;--y)if(g=d[y].dequeue(),g){h=h.concat(s(l,d,u,g,!0));break}}}return h}function s(l,d,u,h,p){var m=p?[]:void 0;return e.forEach(l.inEdges(h.v),function(g){var y=l.edge(g),b=l.node(g.v);p&&m.push({v:g.v,w:g.w}),b.out-=y,c(d,u,b)}),e.forEach(l.outEdges(h.v),function(g){var y=l.edge(g),b=g.w,x=l.node(b);x.in-=y,c(d,u,x)}),l.removeNode(h.v),m}function a(l,d){var u=new r,h=0,p=0;e.forEach(l.nodes(),function(y){u.setNode(y,{v:y,in:0,out:0})}),e.forEach(l.edges(),function(y){var b=u.edge(y.v,y.w)||0,x=d(y),w=b+x;u.setEdge(y.v,y.w,w),p=Math.max(p,u.node(y.v).out+=x),h=Math.max(h,u.node(y.w).in+=x)});var m=e.range(p+h+3).map(function(){return new t}),g=h+1;return e.forEach(u.nodes(),function(y){c(m,g,u.node(y))}),{graph:u,buckets:m,zeroIdx:g}}function c(l,d,u){u.out?u.in?l[u.out-u.in+d].enqueue(u):l[l.length-1].enqueue(u):l[0].enqueue(u)}return Gl}var Hl,em;function vj(){if(em)return Hl;em=1;var e=yt(),r=xj();Hl={run:t,undo:o};function t(i){var s=i.graph().acyclicer==="greedy"?r(i,a(i)):n(i);e.forEach(s,function(c){var l=i.edge(c);i.removeEdge(c),l.forwardName=c.name,l.reversed=!0,i.setEdge(c.w,c.v,l,e.uniqueId("rev"))});function a(c){return function(l){return c.edge(l).weight}}}function n(i){var s=[],a={},c={};function l(d){e.has(c,d)||(c[d]=!0,a[d]=!0,e.forEach(i.outEdges(d),function(u){e.has(a,u.w)?s.push(u):l(u.w)}),delete a[d])}return e.forEach(i.nodes(),l),s}function o(i){e.forEach(i.edges(),function(s){var a=i.edge(s);if(a.reversed){i.removeEdge(s);var c=a.forwardName;delete a.reversed,delete a.forwardName,i.setEdge(s.w,s.v,a,c)}})}return Hl}var Ul,tm;function Nt(){if(tm)return Ul;tm=1;var e=yt(),r=Zt().Graph;Ul={addDummyNode:t,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:s,intersectRect:a,buildLayerMatrix:c,normalizeRanks:l,removeEmptyRanks:d,addBorderNode:u,maxRank:h,partition:p,time:m,notime:g};function t(y,b,x,w){var v;do v=e.uniqueId(w);while(y.hasNode(v));return x.dummy=b,y.setNode(v,x),v}function n(y){var b=new r().setGraph(y.graph());return e.forEach(y.nodes(),function(x){b.setNode(x,y.node(x))}),e.forEach(y.edges(),function(x){var w=b.edge(x.v,x.w)||{weight:0,minlen:1},v=y.edge(x);b.setEdge(x.v,x.w,{weight:w.weight+v.weight,minlen:Math.max(w.minlen,v.minlen)})}),b}function o(y){var b=new r({multigraph:y.isMultigraph()}).setGraph(y.graph());return e.forEach(y.nodes(),function(x){y.children(x).length||b.setNode(x,y.node(x))}),e.forEach(y.edges(),function(x){b.setEdge(x,y.edge(x))}),b}function i(y){var b=e.map(y.nodes(),function(x){var w={};return e.forEach(y.outEdges(x),function(v){w[v.w]=(w[v.w]||0)+y.edge(v).weight}),w});return e.zipObject(y.nodes(),b)}function s(y){var b=e.map(y.nodes(),function(x){var w={};return e.forEach(y.inEdges(x),function(v){w[v.v]=(w[v.v]||0)+y.edge(v).weight}),w});return e.zipObject(y.nodes(),b)}function a(y,b){var x=y.x,w=y.y,v=b.x-x,C=b.y-w,S=y.width/2,E=y.height/2;if(!v&&!C)throw new Error("Not possible to find intersection inside of the rectangle");var R,P;return Math.abs(C)*S>Math.abs(v)*E?(C<0&&(E=-E),R=E*v/C,P=E):(v<0&&(S=-S),R=S,P=S*C/v),{x:x+R,y:w+P}}function c(y){var b=e.map(e.range(h(y)+1),function(){return[]});return e.forEach(y.nodes(),function(x){var w=y.node(x),v=w.rank;e.isUndefined(v)||(b[v][w.order]=x)}),b}function l(y){var b=e.min(e.map(y.nodes(),function(x){return y.node(x).rank}));e.forEach(y.nodes(),function(x){var w=y.node(x);e.has(w,"rank")&&(w.rank-=b)})}function d(y){var b=e.min(e.map(y.nodes(),function(C){return y.node(C).rank})),x=[];e.forEach(y.nodes(),function(C){var S=y.node(C).rank-b;x[S]||(x[S]=[]),x[S].push(C)});var w=0,v=y.graph().nodeRankFactor;e.forEach(x,function(C,S){e.isUndefined(C)&&S%v!==0?--w:w&&e.forEach(C,function(E){y.node(E).rank+=w})})}function u(y,b,x,w){var v={width:0,height:0};return arguments.length>=4&&(v.rank=x,v.order=w),t(y,"border",v,b)}function h(y){return e.max(e.map(y.nodes(),function(b){var x=y.node(b).rank;if(!e.isUndefined(x))return x}))}function p(y,b){var x={lhs:[],rhs:[]};return e.forEach(y,function(w){b(w)?x.lhs.push(w):x.rhs.push(w)}),x}function m(y,b){var x=e.now();try{return b()}finally{console.log(y+" time: "+(e.now()-x)+"ms")}}function g(y,b){return b()}return Ul}var Kl,rm;function wj(){if(rm)return Kl;rm=1;var e=yt(),r=Nt();Kl={run:t,undo:o};function t(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(s){n(i,s)})}function n(i,s){var a=s.v,c=i.node(a).rank,l=s.w,d=i.node(l).rank,u=s.name,h=i.edge(s),p=h.labelRank;if(d!==c+1){i.removeEdge(s);var m,g,y;for(y=0,++c;c<d;++y,++c)h.points=[],g={width:0,height:0,edgeLabel:h,edgeObj:s,rank:c},m=r.addDummyNode(i,"edge",g,"_d"),c===p&&(g.width=h.width,g.height=h.height,g.dummy="edge-label",g.labelpos=h.labelpos),i.setEdge(a,m,{weight:h.weight},u),y===0&&i.graph().dummyChains.push(m),a=m;i.setEdge(a,l,{weight:h.weight},u)}}function o(i){e.forEach(i.graph().dummyChains,function(s){var a=i.node(s),c=a.edgeLabel,l;for(i.setEdge(a.edgeObj,c);a.dummy;)l=i.successors(s)[0],i.removeNode(s),c.points.push({x:a.x,y:a.y}),a.dummy==="edge-label"&&(c.x=a.x,c.y=a.y,c.width=a.width,c.height=a.height),s=l,a=i.node(s)})}return Kl}var Jl,nm;function mo(){if(nm)return Jl;nm=1;var e=yt();Jl={longestPath:r,slack:t};function r(n){var o={};function i(s){var a=n.node(s);if(e.has(o,s))return a.rank;o[s]=!0;var c=e.min(e.map(n.outEdges(s),function(l){return i(l.w)-n.edge(l).minlen}));return(c===Number.POSITIVE_INFINITY||c===void 0||c===null)&&(c=0),a.rank=c}e.forEach(n.sources(),i)}function t(n,o){return n.node(o.w).rank-n.node(o.v).rank-n.edge(o).minlen}return Jl}var Zl,om;function nv(){if(om)return Zl;om=1;var e=yt(),r=Zt().Graph,t=mo().slack;Zl=n;function n(a){var c=new r({directed:!1}),l=a.nodes()[0],d=a.nodeCount();c.setNode(l,{});for(var u,h;o(c,a)<d;)u=i(c,a),h=c.hasNode(u.v)?t(a,u):-t(a,u),s(c,a,h);return c}function o(a,c){function l(d){e.forEach(c.nodeEdges(d),function(u){var h=u.v,p=d===h?u.w:h;!a.hasNode(p)&&!t(c,u)&&(a.setNode(p,{}),a.setEdge(d,p,{}),l(p))})}return e.forEach(a.nodes(),l),a.nodeCount()}function i(a,c){return e.minBy(c.edges(),function(l){if(a.hasNode(l.v)!==a.hasNode(l.w))return t(c,l)})}function s(a,c,l){e.forEach(a.nodes(),function(d){c.node(d).rank+=l})}return Zl}var Xl,im;function Cj(){if(im)return Xl;im=1;var e=yt(),r=nv(),t=mo().slack,n=mo().longestPath,o=Zt().alg.preorder,i=Zt().alg.postorder,s=Nt().simplify;Xl=a,a.initLowLimValues=u,a.initCutValues=c,a.calcCutValue=d,a.leaveEdge=p,a.enterEdge=m,a.exchangeEdges=g;function a(w){w=s(w),n(w);var v=r(w);u(v),c(v,w);for(var C,S;C=p(v);)S=m(v,w,C),g(v,w,C,S)}function c(w,v){var C=i(w,w.nodes());C=C.slice(0,C.length-1),e.forEach(C,function(S){l(w,v,S)})}function l(w,v,C){var S=w.node(C),E=S.parent;w.edge(C,E).cutvalue=d(w,v,C)}function d(w,v,C){var S=w.node(C),E=S.parent,R=!0,P=v.edge(C,E),I=0;return P||(R=!1,P=v.edge(E,C)),I=P.weight,e.forEach(v.nodeEdges(C),function(M){var k=M.v===C,_=k?M.w:M.v;if(_!==E){var N=k===R,$=v.edge(M).weight;if(I+=N?$:-$,b(w,C,_)){var D=w.edge(C,_).cutvalue;I+=N?-D:D}}}),I}function u(w,v){arguments.length<2&&(v=w.nodes()[0]),h(w,{},1,v)}function h(w,v,C,S,E){var R=C,P=w.node(S);return v[S]=!0,e.forEach(w.neighbors(S),function(I){e.has(v,I)||(C=h(w,v,C,I,S))}),P.low=R,P.lim=C++,E?P.parent=E:delete P.parent,C}function p(w){return e.find(w.edges(),function(v){return w.edge(v).cutvalue<0})}function m(w,v,C){var S=C.v,E=C.w;v.hasEdge(S,E)||(S=C.w,E=C.v);var R=w.node(S),P=w.node(E),I=R,M=!1;R.lim>P.lim&&(I=P,M=!0);var k=e.filter(v.edges(),function(_){return M===x(w,w.node(_.v),I)&&M!==x(w,w.node(_.w),I)});return e.minBy(k,function(_){return t(v,_)})}function g(w,v,C,S){var E=C.v,R=C.w;w.removeEdge(E,R),w.setEdge(S.v,S.w,{}),u(w),c(w,v),y(w,v)}function y(w,v){var C=e.find(w.nodes(),function(E){return!v.node(E).parent}),S=o(w,C);S=S.slice(1),e.forEach(S,function(E){var R=w.node(E).parent,P=v.edge(E,R),I=!1;P||(P=v.edge(R,E),I=!0),v.node(E).rank=v.node(R).rank+(I?P.minlen:-P.minlen)})}function b(w,v,C){return w.hasEdge(v,C)}function x(w,v,C){return C.low<=v.lim&&v.lim<=C.lim}return Xl}var Yl,am;function Sj(){if(am)return Yl;am=1;var e=mo(),r=e.longestPath,t=nv(),n=Cj();Yl=o;function o(c){switch(c.graph().ranker){case"network-simplex":a(c);break;case"tight-tree":s(c);break;case"longest-path":i(c);break;default:a(c)}}var i=r;function s(c){r(c),t(c)}function a(c){n(c)}return Yl}var Ql,sm;function jj(){if(sm)return Ql;sm=1;var e=yt();Ql=r;function r(o){var i=n(o);e.forEach(o.graph().dummyChains,function(s){for(var a=o.node(s),c=a.edgeObj,l=t(o,i,c.v,c.w),d=l.path,u=l.lca,h=0,p=d[h],m=!0;s!==c.w;){if(a=o.node(s),m){for(;(p=d[h])!==u&&o.node(p).maxRank<a.rank;)h++;p===u&&(m=!1)}if(!m){for(;h<d.length-1&&o.node(p=d[h+1]).minRank<=a.rank;)h++;p=d[h]}o.setParent(s,p),s=o.successors(s)[0]}})}function t(o,i,s,a){var c=[],l=[],d=Math.min(i[s].low,i[a].low),u=Math.max(i[s].lim,i[a].lim),h,p;h=s;do h=o.parent(h),c.push(h);while(h&&(i[h].low>d||u>i[h].lim));for(p=h,h=a;(h=o.parent(h))!==p;)l.push(h);return{path:c.concat(l.reverse()),lca:p}}function n(o){var i={},s=0;function a(c){var l=s;e.forEach(o.children(c),a),i[c]={low:l,lim:s++}}return e.forEach(o.children(),a),i}return Ql}var ed,cm;function Ej(){if(cm)return ed;cm=1;var e=yt(),r=Nt();ed={run:t,cleanup:s};function t(a){var c=r.addDummyNode(a,"root",{},"_root"),l=o(a),d=e.max(e.values(l))-1,u=2*d+1;a.graph().nestingRoot=c,e.forEach(a.edges(),function(p){a.edge(p).minlen*=u});var h=i(a)+1;e.forEach(a.children(),function(p){n(a,c,u,h,d,l,p)}),a.graph().nodeRankFactor=u}function n(a,c,l,d,u,h,p){var m=a.children(p);if(!m.length){p!==c&&a.setEdge(c,p,{weight:0,minlen:l});return}var g=r.addBorderNode(a,"_bt"),y=r.addBorderNode(a,"_bb"),b=a.node(p);a.setParent(g,p),b.borderTop=g,a.setParent(y,p),b.borderBottom=y,e.forEach(m,function(x){n(a,c,l,d,u,h,x);var w=a.node(x),v=w.borderTop?w.borderTop:x,C=w.borderBottom?w.borderBottom:x,S=w.borderTop?d:2*d,E=v!==C?1:u-h[p]+1;a.setEdge(g,v,{weight:S,minlen:E,nestingEdge:!0}),a.setEdge(C,y,{weight:S,minlen:E,nestingEdge:!0})}),a.parent(p)||a.setEdge(c,g,{weight:0,minlen:u+h[p]})}function o(a){var c={};function l(d,u){var h=a.children(d);h&&h.length&&e.forEach(h,function(p){l(p,u+1)}),c[d]=u}return e.forEach(a.children(),function(d){l(d,1)}),c}function i(a){return e.reduce(a.edges(),function(c,l){return c+a.edge(l).weight},0)}function s(a){var c=a.graph();a.removeNode(c.nestingRoot),delete c.nestingRoot,e.forEach(a.edges(),function(l){var d=a.edge(l);d.nestingEdge&&a.removeEdge(l)})}return ed}var td,lm;function _j(){if(lm)return td;lm=1;var e=yt(),r=Nt();td=t;function t(o){function i(s){var a=o.children(s),c=o.node(s);if(a.length&&e.forEach(a,i),e.has(c,"minRank")){c.borderLeft=[],c.borderRight=[];for(var l=c.minRank,d=c.maxRank+1;l<d;++l)n(o,"borderLeft","_bl",s,c,l),n(o,"borderRight","_br",s,c,l)}}e.forEach(o.children(),i)}function n(o,i,s,a,c,l){var d={width:0,height:0,rank:l,borderType:i},u=c[i][l-1],h=r.addDummyNode(o,"border",d,s);c[i][l]=h,o.setParent(h,a),u&&o.setEdge(u,h,{weight:1})}return td}var rd,dm;function kj(){if(dm)return rd;dm=1;var e=yt();rd={adjust:r,undo:t};function r(l){var d=l.graph().rankdir.toLowerCase();(d==="lr"||d==="rl")&&n(l)}function t(l){var d=l.graph().rankdir.toLowerCase();(d==="bt"||d==="rl")&&i(l),(d==="lr"||d==="rl")&&(a(l),n(l))}function n(l){e.forEach(l.nodes(),function(d){o(l.node(d))}),e.forEach(l.edges(),function(d){o(l.edge(d))})}function o(l){var d=l.width;l.width=l.height,l.height=d}function i(l){e.forEach(l.nodes(),function(d){s(l.node(d))}),e.forEach(l.edges(),function(d){var u=l.edge(d);e.forEach(u.points,s),e.has(u,"y")&&s(u)})}function s(l){l.y=-l.y}function a(l){e.forEach(l.nodes(),function(d){c(l.node(d))}),e.forEach(l.edges(),function(d){var u=l.edge(d);e.forEach(u.points,c),e.has(u,"x")&&c(u)})}function c(l){var d=l.x;l.x=l.y,l.y=d}return rd}var nd,um;function Pj(){if(um)return nd;um=1;var e=yt();nd=r;function r(t){var n={},o=e.filter(t.nodes(),function(l){return!t.children(l).length}),i=e.max(e.map(o,function(l){return t.node(l).rank})),s=e.map(e.range(i+1),function(){return[]});function a(l){if(!e.has(n,l)){n[l]=!0;var d=t.node(l);s[d.rank].push(l),e.forEach(t.successors(l),a)}}var c=e.sortBy(o,function(l){return t.node(l).rank});return e.forEach(c,a),s}return nd}var od,fm;function Aj(){if(fm)return od;fm=1;var e=yt();od=r;function r(n,o){for(var i=0,s=1;s<o.length;++s)i+=t(n,o[s-1],o[s]);return i}function t(n,o,i){for(var s=e.zipObject(i,e.map(i,function(h,p){return p})),a=e.flatten(e.map(o,function(h){return e.sortBy(e.map(n.outEdges(h),function(p){return{pos:s[p.w],weight:n.edge(p).weight}}),"pos")}),!0),c=1;c<i.length;)c<<=1;var l=2*c-1;c-=1;var d=e.map(new Array(l),function(){return 0}),u=0;return e.forEach(a.forEach(function(h){var p=h.pos+c;d[p]+=h.weight;for(var m=0;p>0;)p%2&&(m+=d[p+1]),p=p-1>>1,d[p]+=h.weight;u+=h.weight*m})),u}return od}var id,hm;function Rj(){if(hm)return id;hm=1;var e=yt();id=r;function r(t,n){return e.map(n,function(o){var i=t.inEdges(o);if(i.length){var s=e.reduce(i,function(a,c){var l=t.edge(c),d=t.node(c.v);return{sum:a.sum+l.weight*d.order,weight:a.weight+l.weight}},{sum:0,weight:0});return{v:o,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:o}})}return id}var ad,pm;function Mj(){if(pm)return ad;pm=1;var e=yt();ad=r;function r(o,i){var s={};e.forEach(o,function(c,l){var d=s[c.v]={indegree:0,in:[],out:[],vs:[c.v],i:l};e.isUndefined(c.barycenter)||(d.barycenter=c.barycenter,d.weight=c.weight)}),e.forEach(i.edges(),function(c){var l=s[c.v],d=s[c.w];!e.isUndefined(l)&&!e.isUndefined(d)&&(d.indegree++,l.out.push(s[c.w]))});var a=e.filter(s,function(c){return!c.indegree});return t(a)}function t(o){var i=[];function s(l){return function(d){d.merged||(e.isUndefined(d.barycenter)||e.isUndefined(l.barycenter)||d.barycenter>=l.barycenter)&&n(l,d)}}function a(l){return function(d){d.in.push(l),--d.indegree===0&&o.push(d)}}for(;o.length;){var c=o.pop();i.push(c),e.forEach(c.in.reverse(),s(c)),e.forEach(c.out,a(c))}return e.map(e.filter(i,function(l){return!l.merged}),function(l){return e.pick(l,["vs","i","barycenter","weight"])})}function n(o,i){var s=0,a=0;o.weight&&(s+=o.barycenter*o.weight,a+=o.weight),i.weight&&(s+=i.barycenter*i.weight,a+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=s/a,o.weight=a,o.i=Math.min(i.i,o.i),i.merged=!0}return ad}var sd,gm;function Tj(){if(gm)return sd;gm=1;var e=yt(),r=Nt();sd=t;function t(i,s){var a=r.partition(i,function(g){return e.has(g,"barycenter")}),c=a.lhs,l=e.sortBy(a.rhs,function(g){return-g.i}),d=[],u=0,h=0,p=0;c.sort(o(!!s)),p=n(d,l,p),e.forEach(c,function(g){p+=g.vs.length,d.push(g.vs),u+=g.barycenter*g.weight,h+=g.weight,p=n(d,l,p)});var m={vs:e.flatten(d,!0)};return h&&(m.barycenter=u/h,m.weight=h),m}function n(i,s,a){for(var c;s.length&&(c=e.last(s)).i<=a;)s.pop(),i.push(c.vs),a++;return a}function o(i){return function(s,a){return s.barycenter<a.barycenter?-1:s.barycenter>a.barycenter?1:i?a.i-s.i:s.i-a.i}}return sd}var cd,ym;function Ij(){if(ym)return cd;ym=1;var e=yt(),r=Rj(),t=Mj(),n=Tj();cd=o;function o(a,c,l,d){var u=a.children(c),h=a.node(c),p=h?h.borderLeft:void 0,m=h?h.borderRight:void 0,g={};p&&(u=e.filter(u,function(C){return C!==p&&C!==m}));var y=r(a,u);e.forEach(y,function(C){if(a.children(C.v).length){var S=o(a,C.v,l,d);g[C.v]=S,e.has(S,"barycenter")&&s(C,S)}});var b=t(y,l);i(b,g);var x=n(b,d);if(p&&(x.vs=e.flatten([p,x.vs,m],!0),a.predecessors(p).length)){var w=a.node(a.predecessors(p)[0]),v=a.node(a.predecessors(m)[0]);e.has(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+w.order+v.order)/(x.weight+2),x.weight+=2}return x}function i(a,c){e.forEach(a,function(l){l.vs=e.flatten(l.vs.map(function(d){return c[d]?c[d].vs:d}),!0)})}function s(a,c){e.isUndefined(a.barycenter)?(a.barycenter=c.barycenter,a.weight=c.weight):(a.barycenter=(a.barycenter*a.weight+c.barycenter*c.weight)/(a.weight+c.weight),a.weight+=c.weight)}return cd}var ld,mm;function Nj(){if(mm)return ld;mm=1;var e=yt(),r=Zt().Graph;ld=t;function t(o,i,s){var a=n(o),c=new r({compound:!0}).setGraph({root:a}).setDefaultNodeLabel(function(l){return o.node(l)});return e.forEach(o.nodes(),function(l){var d=o.node(l),u=o.parent(l);(d.rank===i||d.minRank<=i&&i<=d.maxRank)&&(c.setNode(l),c.setParent(l,u||a),e.forEach(o[s](l),function(h){var p=h.v===l?h.w:h.v,m=c.edge(p,l),g=e.isUndefined(m)?0:m.weight;c.setEdge(p,l,{weight:o.edge(h).weight+g})}),e.has(d,"minRank")&&c.setNode(l,{borderLeft:d.borderLeft[i],borderRight:d.borderRight[i]}))}),c}function n(o){for(var i;o.hasNode(i=e.uniqueId("_root")););return i}return ld}var dd,bm;function Oj(){if(bm)return dd;bm=1;var e=yt();dd=r;function r(t,n,o){var i={},s;e.forEach(o,function(a){for(var c=t.parent(a),l,d;c;){if(l=t.parent(c),l?(d=i[l],i[l]=c):(d=s,s=c),d&&d!==c){n.setEdge(d,c);return}c=l}})}return dd}var ud,xm;function $j(){if(xm)return ud;xm=1;var e=yt(),r=Pj(),t=Aj(),n=Ij(),o=Nj(),i=Oj(),s=Zt().Graph,a=Nt();ud=c;function c(h){var p=a.maxRank(h),m=l(h,e.range(1,p+1),"inEdges"),g=l(h,e.range(p-1,-1,-1),"outEdges"),y=r(h);u(h,y);for(var b=Number.POSITIVE_INFINITY,x,w=0,v=0;v<4;++w,++v){d(w%2?m:g,w%4>=2),y=a.buildLayerMatrix(h);var C=t(h,y);C<b&&(v=0,x=e.cloneDeep(y),b=C)}u(h,x)}function l(h,p,m){return e.map(p,function(g){return o(h,g,m)})}function d(h,p){var m=new s;e.forEach(h,function(g){var y=g.graph().root,b=n(g,y,m,p);e.forEach(b.vs,function(x,w){g.node(x).order=w}),i(g,m,b.vs)})}function u(h,p){e.forEach(p,function(m){e.forEach(m,function(g,y){h.node(g).order=y})})}return ud}var fd,vm;function qj(){if(vm)return fd;vm=1;var e=yt(),r=Zt().Graph,t=Nt();fd={positionX:m,findType1Conflicts:n,findType2Conflicts:o,addConflict:s,hasConflict:a,verticalAlignment:c,horizontalCompaction:l,alignCoordinates:h,findSmallestWidthAlignment:u,balance:p};function n(b,x){var w={};function v(C,S){var E=0,R=0,P=C.length,I=e.last(S);return e.forEach(S,function(M,k){var _=i(b,M),N=_?b.node(_).order:P;(_||M===I)&&(e.forEach(S.slice(R,k+1),function($){e.forEach(b.predecessors($),function(D){var T=b.node(D),Z=T.order;(Z<E||N<Z)&&!(T.dummy&&b.node($).dummy)&&s(w,D,$)})}),R=k+1,E=N)}),S}return e.reduce(x,v),w}function o(b,x){var w={};function v(S,E,R,P,I){var M;e.forEach(e.range(E,R),function(k){M=S[k],b.node(M).dummy&&e.forEach(b.predecessors(M),function(_){var N=b.node(_);N.dummy&&(N.order<P||N.order>I)&&s(w,_,M)})})}function C(S,E){var R=-1,P,I=0;return e.forEach(E,function(M,k){if(b.node(M).dummy==="border"){var _=b.predecessors(M);_.length&&(P=b.node(_[0]).order,v(E,I,k,R,P),I=k,R=P)}v(E,I,E.length,P,S.length)}),E}return e.reduce(x,C),w}function i(b,x){if(b.node(x).dummy)return e.find(b.predecessors(x),function(w){return b.node(w).dummy})}function s(b,x,w){if(x>w){var v=x;x=w,w=v}var C=b[x];C||(b[x]=C={}),C[w]=!0}function a(b,x,w){if(x>w){var v=x;x=w,w=v}return e.has(b[x],w)}function c(b,x,w,v){var C={},S={},E={};return e.forEach(x,function(R){e.forEach(R,function(P,I){C[P]=P,S[P]=P,E[P]=I})}),e.forEach(x,function(R){var P=-1;e.forEach(R,function(I){var M=v(I);if(M.length){M=e.sortBy(M,function(D){return E[D]});for(var k=(M.length-1)/2,_=Math.floor(k),N=Math.ceil(k);_<=N;++_){var $=M[_];S[I]===I&&P<E[$]&&!a(w,I,$)&&(S[$]=I,S[I]=C[I]=C[$],P=E[$])}}})}),{root:C,align:S}}function l(b,x,w,v,C){var S={},E=d(b,x,w,C),R=C?"borderLeft":"borderRight";function P(k,_){for(var N=E.nodes(),$=N.pop(),D={};$;)D[$]?k($):(D[$]=!0,N.push($),N=N.concat(_($))),$=N.pop()}function I(k){S[k]=E.inEdges(k).reduce(function(_,N){return Math.max(_,S[N.v]+E.edge(N))},0)}function M(k){var _=E.outEdges(k).reduce(function($,D){return Math.min($,S[D.w]-E.edge(D))},Number.POSITIVE_INFINITY),N=b.node(k);_!==Number.POSITIVE_INFINITY&&N.borderType!==R&&(S[k]=Math.max(S[k],_))}return P(I,E.predecessors.bind(E)),P(M,E.successors.bind(E)),e.forEach(v,function(k){S[k]=S[w[k]]}),S}function d(b,x,w,v){var C=new r,S=b.graph(),E=g(S.nodesep,S.edgesep,v);return e.forEach(x,function(R){var P;e.forEach(R,function(I){var M=w[I];if(C.setNode(M),P){var k=w[P],_=C.edge(k,M);C.setEdge(k,M,Math.max(E(b,I,P),_||0))}P=I})}),C}function u(b,x){return e.minBy(e.values(x),function(w){var v=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY;return e.forIn(w,function(S,E){var R=y(b,E)/2;v=Math.max(S+R,v),C=Math.min(S-R,C)}),v-C})}function h(b,x){var w=e.values(x),v=e.min(w),C=e.max(w);e.forEach(["u","d"],function(S){e.forEach(["l","r"],function(E){var R=S+E,P=b[R],I;if(P!==x){var M=e.values(P);I=E==="l"?v-e.min(M):C-e.max(M),I&&(b[R]=e.mapValues(P,function(k){return k+I}))}})})}function p(b,x){return e.mapValues(b.ul,function(w,v){if(x)return b[x.toLowerCase()][v];var C=e.sortBy(e.map(b,v));return(C[1]+C[2])/2})}function m(b){var x=t.buildLayerMatrix(b),w=e.merge(n(b,x),o(b,x)),v={},C;e.forEach(["u","d"],function(E){C=E==="u"?x:e.values(x).reverse(),e.forEach(["l","r"],function(R){R==="r"&&(C=e.map(C,function(k){return e.values(k).reverse()}));var P=(E==="u"?b.predecessors:b.successors).bind(b),I=c(b,C,w,P),M=l(b,C,I.root,I.align,R==="r");R==="r"&&(M=e.mapValues(M,function(k){return-k})),v[E+R]=M})});var S=u(b,v);return h(v,S),p(v,b.graph().align)}function g(b,x,w){return function(v,C,S){var E=v.node(C),R=v.node(S),P=0,I;if(P+=E.width/2,e.has(E,"labelpos"))switch(E.labelpos.toLowerCase()){case"l":I=-E.width/2;break;case"r":I=E.width/2;break}if(I&&(P+=w?I:-I),I=0,P+=(E.dummy?x:b)/2,P+=(R.dummy?x:b)/2,P+=R.width/2,e.has(R,"labelpos"))switch(R.labelpos.toLowerCase()){case"l":I=R.width/2;break;case"r":I=-R.width/2;break}return I&&(P+=w?I:-I),I=0,P}}function y(b,x){return b.node(x).width}return fd}var hd,wm;function Lj(){if(wm)return hd;wm=1;var e=yt(),r=Nt(),t=qj().positionX;hd=n;function n(i){i=r.asNonCompoundGraph(i),o(i),e.forEach(t(i),function(s,a){i.node(a).x=s})}function o(i){var s=r.buildLayerMatrix(i),a=i.graph().ranksep,c=0;e.forEach(s,function(l){var d=e.max(e.map(l,function(u){return i.node(u).height}));e.forEach(l,function(u){i.node(u).y=c+d/2}),c+=d+a})}return hd}var pd,Cm;function Fj(){if(Cm)return pd;Cm=1;var e=yt(),r=vj(),t=wj(),n=Sj(),o=Nt().normalizeRanks,i=jj(),s=Nt().removeEmptyRanks,a=Ej(),c=_j(),l=kj(),d=$j(),u=Lj(),h=Nt(),p=Zt().Graph;pd=m;function m(q,F){var H=F&&F.debugTiming?h.time:h.notime;H("layout",function(){var G=H(" buildLayoutGraph",function(){return P(q)});H(" runLayout",function(){g(G,H)}),H(" updateInputGraph",function(){y(q,G)})})}function g(q,F){F(" makeSpaceForEdgeLabels",function(){I(q)}),F(" removeSelfEdges",function(){K(q)}),F(" acyclic",function(){r.run(q)}),F(" nestingGraph.run",function(){a.run(q)}),F(" rank",function(){n(h.asNonCompoundGraph(q))}),F(" injectEdgeLabelProxies",function(){M(q)}),F(" removeEmptyRanks",function(){s(q)}),F(" nestingGraph.cleanup",function(){a.cleanup(q)}),F(" normalizeRanks",function(){o(q)}),F(" assignRankMinMax",function(){k(q)}),F(" removeEdgeLabelProxies",function(){_(q)}),F(" normalize.run",function(){t.run(q)}),F(" parentDummyChains",function(){i(q)}),F(" addBorderSegments",function(){c(q)}),F(" order",function(){d(q)}),F(" insertSelfEdges",function(){ne(q)}),F(" adjustCoordinateSystem",function(){l.adjust(q)}),F(" position",function(){u(q)}),F(" positionSelfEdges",function(){se(q)}),F(" removeBorderNodes",function(){Z(q)}),F(" normalize.undo",function(){t.undo(q)}),F(" fixupEdgeLabelCoords",function(){D(q)}),F(" undoCoordinateSystem",function(){l.undo(q)}),F(" translateGraph",function(){N(q)}),F(" assignNodeIntersects",function(){$(q)}),F(" reversePoints",function(){T(q)}),F(" acyclic.undo",function(){r.undo(q)})}function y(q,F){e.forEach(q.nodes(),function(H){var G=q.node(H),ce=F.node(H);G&&(G.x=ce.x,G.y=ce.y,F.children(H).length&&(G.width=ce.width,G.height=ce.height))}),e.forEach(q.edges(),function(H){var G=q.edge(H),ce=F.edge(H);G.points=ce.points,e.has(ce,"x")&&(G.x=ce.x,G.y=ce.y)}),q.graph().width=F.graph().width,q.graph().height=F.graph().height}var b=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},w=["acyclicer","ranker","rankdir","align"],v=["width","height"],C={width:0,height:0},S=["minlen","weight","width","height","labeloffset"],E={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},R=["labelpos"];function P(q){var F=new p({multigraph:!0,compound:!0}),H=ue(q.graph());return F.setGraph(e.merge({},x,W(H,b),e.pick(H,w))),e.forEach(q.nodes(),function(G){var ce=ue(q.node(G));F.setNode(G,e.defaults(W(ce,v),C)),F.setParent(G,q.parent(G))}),e.forEach(q.edges(),function(G){var ce=ue(q.edge(G));F.setEdge(G,e.merge({},E,W(ce,S),e.pick(ce,R)))}),F}function I(q){var F=q.graph();F.ranksep/=2,e.forEach(q.edges(),function(H){var G=q.edge(H);G.minlen*=2,G.labelpos.toLowerCase()!=="c"&&(F.rankdir==="TB"||F.rankdir==="BT"?G.width+=G.labeloffset:G.height+=G.labeloffset)})}function M(q){e.forEach(q.edges(),function(F){var H=q.edge(F);if(H.width&&H.height){var G=q.node(F.v),ce=q.node(F.w),te={rank:(ce.rank-G.rank)/2+G.rank,e:F};h.addDummyNode(q,"edge-proxy",te,"_ep")}})}function k(q){var F=0;e.forEach(q.nodes(),function(H){var G=q.node(H);G.borderTop&&(G.minRank=q.node(G.borderTop).rank,G.maxRank=q.node(G.borderBottom).rank,F=e.max(F,G.maxRank))}),q.graph().maxRank=F}function _(q){e.forEach(q.nodes(),function(F){var H=q.node(F);H.dummy==="edge-proxy"&&(q.edge(H.e).labelRank=H.rank,q.removeNode(F))})}function N(q){var F=Number.POSITIVE_INFINITY,H=0,G=Number.POSITIVE_INFINITY,ce=0,te=q.graph(),X=te.marginx||0,ie=te.marginy||0;function me(xe){var fe=xe.x,U=xe.y,re=xe.width,de=xe.height;F=Math.min(F,fe-re/2),H=Math.max(H,fe+re/2),G=Math.min(G,U-de/2),ce=Math.max(ce,U+de/2)}e.forEach(q.nodes(),function(xe){me(q.node(xe))}),e.forEach(q.edges(),function(xe){var fe=q.edge(xe);e.has(fe,"x")&&me(fe)}),F-=X,G-=ie,e.forEach(q.nodes(),function(xe){var fe=q.node(xe);fe.x-=F,fe.y-=G}),e.forEach(q.edges(),function(xe){var fe=q.edge(xe);e.forEach(fe.points,function(U){U.x-=F,U.y-=G}),e.has(fe,"x")&&(fe.x-=F),e.has(fe,"y")&&(fe.y-=G)}),te.width=H-F+X,te.height=ce-G+ie}function $(q){e.forEach(q.edges(),function(F){var H=q.edge(F),G=q.node(F.v),ce=q.node(F.w),te,X;H.points?(te=H.points[0],X=H.points[H.points.length-1]):(H.points=[],te=ce,X=G),H.points.unshift(h.intersectRect(G,te)),H.points.push(h.intersectRect(ce,X))})}function D(q){e.forEach(q.edges(),function(F){var H=q.edge(F);if(e.has(H,"x"))switch((H.labelpos==="l"||H.labelpos==="r")&&(H.width-=H.labeloffset),H.labelpos){case"l":H.x-=H.width/2+H.labeloffset;break;case"r":H.x+=H.width/2+H.labeloffset;break}})}function T(q){e.forEach(q.edges(),function(F){var H=q.edge(F);H.reversed&&H.points.reverse()})}function Z(q){e.forEach(q.nodes(),function(F){if(q.children(F).length){var H=q.node(F),G=q.node(H.borderTop),ce=q.node(H.borderBottom),te=q.node(e.last(H.borderLeft)),X=q.node(e.last(H.borderRight));H.width=Math.abs(X.x-te.x),H.height=Math.abs(ce.y-G.y),H.x=te.x+H.width/2,H.y=G.y+H.height/2}}),e.forEach(q.nodes(),function(F){q.node(F).dummy==="border"&&q.removeNode(F)})}function K(q){e.forEach(q.edges(),function(F){if(F.v===F.w){var H=q.node(F.v);H.selfEdges||(H.selfEdges=[]),H.selfEdges.push({e:F,label:q.edge(F)}),q.removeEdge(F)}})}function ne(q){var F=h.buildLayerMatrix(q);e.forEach(F,function(H){var G=0;e.forEach(H,function(ce,te){var X=q.node(ce);X.order=te+G,e.forEach(X.selfEdges,function(ie){h.addDummyNode(q,"selfedge",{width:ie.label.width,height:ie.label.height,rank:X.rank,order:te+ ++G,e:ie.e,label:ie.label},"_se")}),delete X.selfEdges})})}function se(q){e.forEach(q.nodes(),function(F){var H=q.node(F);if(H.dummy==="selfedge"){var G=q.node(H.e.v),ce=G.x+G.width/2,te=G.y,X=H.x-ce,ie=G.height/2;q.setEdge(H.e,H.label),q.removeNode(F),H.label.points=[{x:ce+2*X/3,y:te-ie},{x:ce+5*X/6,y:te-ie},{x:ce+X,y:te},{x:ce+5*X/6,y:te+ie},{x:ce+2*X/3,y:te+ie}],H.label.x=H.x,H.label.y=H.y}})}function W(q,F){return e.mapValues(e.pick(q,F),Number)}function ue(q){var F={};return e.forEach(q,function(H,G){F[G.toLowerCase()]=H}),F}return pd}var gd,Sm;function zj(){if(Sm)return gd;Sm=1;var e=yt(),r=Nt(),t=Zt().Graph;gd={debugOrdering:n};function n(o){var i=r.buildLayerMatrix(o),s=new t({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(a){s.setNode(a,{label:a}),s.setParent(a,"layer"+o.node(a).rank)}),e.forEach(o.edges(),function(a){s.setEdge(a.v,a.w,{},a.name)}),e.forEach(i,function(a,c){var l="layer"+c;s.setNode(l,{rank:"same"}),e.reduce(a,function(d,u){return s.setEdge(d,u,{style:"invis"}),u})}),s}return gd}var yd,jm;function Bj(){return jm||(jm=1,yd="0.8.5"),yd}var md,Em;function Dj(){return Em||(Em=1,md={graphlib:Zt(),layout:Fj(),debug:zj(),util:{time:Nt().time,notime:Nt().notime},version:Bj()}),md}var Wj=Dj();const _m=k1(Wj);function Vj(e,r,t){var h,p;const n=new Set(e.map(m=>m.id)),o=new Map(e.map(m=>[m.id,m])),i=new Set;for(const m of e)m.parent&&n.has(m.parent)&&i.add(m.parent);const s=new Map;for(const m of e){if(!m.hasBody||!i.has(m.id))continue;let g=`${m.id}.$body`;for(;n.has(g);)g+="$";s.set(m.id,g),n.add(g)}const a=new _m.graphlib.Graph({multigraph:!0,compound:!0}),c=t.compactSpacingScale??(t.spacingFactor>0?t.spacingFactor/1.3:1);a.setGraph({rankdir:t.rankDir,nodesep:t.compact?Math.max(t.nodeSep,24*c):t.nodeSep,edgesep:t.compact?Math.min(t.edgeSep,24*c):t.edgeSep,ranksep:t.compact?Math.min(t.rankSep,80*c):t.rankSep,ranker:"network-simplex"}),a.setDefaultEdgeLabel(()=>({})),a.setDefaultNodeLabel(()=>({}));for(const m of e)a.setNode(m.id,{width:m.width+2,height:m.height+2});for(const m of e)m.parent&&n.has(m.parent)&&a.setParent(m.id,m.parent);for(const[m,g]of s){const y=o.get(m);a.setNode(g,{width:y.width+2,height:y.height+2}),a.setParent(g,m)}for(const m of e){if(i.has(m.id)&&!s.has(m.id))continue;let g=m.parent;const y=new Set;for(;g&&!s.has(g)&&!y.has(g);)y.add(g),g=(h=o.get(g))==null?void 0:h.parent;const b=g&&s.get(g);b&&a.setEdge(b,s.get(m.id)??m.id,{minlen:1,weight:1},"parent-body")}for(const m of r){if(!n.has(m.source)||!n.has(m.target))continue;const g=s.get(m.source)??m.source,y=s.get(m.target)??m.target;if(i.has(g)||i.has(y))continue;const b=rx(m.label,m.icon??((p=m.data)==null?void 0:p.icon),t.edgeLabelFontSize),x=t.rankDir==="LR"||t.rankDir==="RL",w=(b.width?b.width+2*tx:0)+(m.connectorClearance??0);a.setEdge(g,y,{minlen:1,weight:1,...w?{width:x?w:Math.max(1,b.height),height:x?Math.max(1,b.height):w,labelpos:"c"}:{}},m.id)}_m.layout(a);const l=new Map;for(const m of e){if(i.has(m.id)&&!s.has(m.id))continue;const g=a.node(s.get(m.id)??m.id);g&&Number.isFinite(g.x)&&Number.isFinite(g.y)&&l.set(m.id,{x:g.x,y:g.y})}const d=t.compact?1:t.spacingFactor;if(d&&d!==1&&l.size){let m=1/0,g=1/0,y=-1/0,b=-1/0;l.forEach(v=>{m=Math.min(m,v.x),g=Math.min(g,v.y),y=Math.max(y,v.x),b=Math.max(b,v.y)});const x=(m+y)/2,w=(g+b)/2;l.forEach((v,C)=>l.set(C,{x:x+(v.x-x)*d,y:w+(v.y-w)*d}))}const u=t.nodeAlignment??"center";if(u!=="center"){const m=t.rankDir==="LR"||t.rankDir==="RL",g=m?"x":"y",y=m?"width":"height",b=t.rankDir==="RL"||t.rankDir==="BT"?-1:1,x=u==="leading"?-b:b,w=new Map;for(const v of e){const C=l.get(v.id);if(!C)continue;const S=C[g];w.set(S,Math.max(w.get(S)??0,v[y]))}for(const v of e){const C=l.get(v.id);if(!C)continue;const S=C[g],E=(w.get(S)-v[y])/2;l.set(v.id,{...C,[g]:S+x*E})}}return l}function Ad(e,r,t,n,o,i){const s=new Map,a=new Map(e.map(u=>[u.id,u]));for(const u of e){if(!u.parent||!a.has(u.parent))continue;const h=s.get(u.parent);h?h.push(u.id):s.set(u.parent,[u.id])}const c=(u,h=new Set)=>{var m;const p=(m=a.get(u))==null?void 0:m.parent;return!p||!a.has(p)||h.has(u)?0:(h.add(u),1+c(p,h))},l=[...s.keys()].sort((u,h)=>c(h)-c(u)),d=new Map;for(const u of l){const h=i==null?void 0:i.get(u),p=r.get(u);if(h&&p){d.set(u,{x1:p.x-h.w/2,y1:p.y-h.h/2,x2:p.x+h.w/2,y2:p.y+h.h/2});continue}const m=t.get(u);let g=p&&m?{x1:p.x-m.w/2,y1:p.y-m.h/2,x2:p.x+m.w/2,y2:p.y+m.h/2}:null;for(const x of s.get(u)||[]){let w=d.get(x);if(!w){const v=r.get(x);if(!v)continue;const C=t.get(x)||{w:60,h:60};w={x1:v.x-C.w/2,y1:v.y-C.h/2,x2:v.x+C.w/2,y2:v.y+C.h/2}}g=g?{x1:Math.min(g.x1,w.x1),y1:Math.min(g.y1,w.y1),x2:Math.max(g.x2,w.x2),y2:Math.max(g.y2,w.y2)}:{...w}}if(!g)continue;const y=n(u);g={x1:g.x1-y,y1:g.y1-y,x2:g.x2+y,y2:g.y2+y};const b=o(u);if(b){const x=g.x2-g.x1,w=g.y2-g.y1;if(b.w>x){const v=(b.w-x)/2;g.x1-=v,g.x2+=v}if(b.h>w){const v=(b.h-w)/2;g.y1-=v,g.y2+=v}}d.set(u,g)}return d}function km(e,r,t){var c,l,d;const n=[...r.weights],o=n.reduce((u,h)=>u+h,0),i=n[r.index]+n[r.index+1],s=Math.min(i*.95,Math.max(i*.05,n[r.index]+t/r.length*o));n[r.index]=s,n[r.index+1]=i-s;const a={...(l=(c=e.adjustment)==null?void 0:c.sections)==null?void 0:l[r.section]};if(r.axis==="y")a.rows=n;else{for(a.columns=[...a.columns??[]];a.columns.length<=r.row;)a.columns.push([]);a.columns[r.row]=n}return{...e,adjustment:{...e.adjustment,sections:{...(d=e.adjustment)==null?void 0:d.sections,[r.section]:a}}}}function ov(e){if(e===void 0)return;if(!e||typeof e!="object"||Array.isArray(e)||e.enabled!==void 0&&typeof e.enabled!="boolean")throw new RangeError("Invalid grid adjustment.");const r=t=>Array.isArray(t)&&t.length<=1e4&&t.every(n=>typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1e6);if(e.sections!==void 0&&(!e.sections||typeof e.sections!="object"||Array.isArray(e.sections)))throw new RangeError("Invalid grid sections.");for(const[t,n]of Object.entries(e.sections??{}))if(["__proto__","constructor","prototype"].includes(t)||!n||typeof n!="object"||Array.isArray(n)||n.rows!==void 0&&!r(n.rows)||n.columns!==void 0&&(!Array.isArray(n.columns)||n.columns.length>1e4||!n.columns.every(r))||n.members!==void 0&&(!Array.isArray(n.members)||n.members.length>1e4||!n.members.every(o=>Array.isArray(o)&&o.length>0&&o.length<=1e4&&o.every(i=>typeof i=="string"&&i.length>0))||new Set(n.members.flat()).size!==n.members.flat().length))throw new RangeError("Invalid grid section proportions.")}function pu(e){const r=e.margin??15;if(!Number.isFinite(r)||r<0)throw new RangeError("Collision margin must be finite and non-negative.");return r}function Yn(e){const r=new Map(e.nodes.map(a=>[a.id,a])),t=new Map;for(const a of e.nodes){const c=a.parent&&r.has(a.parent)?a.parent:void 0,l=t.get(c)??[];l.push(a.id),t.set(c,l)}const n=[],o=new Map,i=a=>{const c=t.get(a),l=c?c.flatMap(i):e.positions.has(a)?[a]:[];return o.set(a,l),c&&n.push(c),l},s=t.get(void 0)??[];return s.forEach(i),n.push(s),{groups:n,leaves:o,children:t,roots:s}}function kr(e,r,t=e.fixedSizes){const n=Ad(e.nodes,r,e.sizes,e.padding,e.minSize,t);for(const o of e.nodes){if(n.has(o.id))continue;const i=r.get(o.id),s=e.sizes.get(o.id);i&&s&&n.set(o.id,ir({...i,...s}))}return n}function iv(e,r,t,n){const o=t.get(e),i=t.get(r);if(!o||!i)return;const s={x:Math.min(o.x2-i.x1,i.x2-o.x1)+n,y:Math.min(o.y2-i.y1,i.y2-o.y1)+n};if(s.x>.001&&s.y>.001)return{source:e,target:r,overlap:s}}function Vn(e,r,t){const n=[];for(const o of e)for(let i=0;i<o.length;i++)for(let s=i+1;s<o.length;s++){const a=iv(o[i],o[s],r,t);a&&n.push(a)}return n}function av(e,r={}){const t=pu(r),{groups:n}=Yn(e);return Vn(n,kr(e,e.positions),t)}function sv(e,r,t,n){var a,c,l;const o=new Set(e),i=(((l=(c=(a=r.adjustment)==null?void 0:a.sections)==null?void 0:c[t])==null?void 0:l.members)??[]).map(d=>d.filter(u=>o.delete(u))).filter(d=>d.length),s=e.filter(d=>o.has(d));for(let d=0;d<s.length;d+=n)i.push(s.slice(d,d+n));return i}function Gj(e,r,t,n,o){var x,w,v,C;if(t===n)return;const{groups:i,leaves:s}=Yn(e),a=i.find(S=>S.includes(t)&&S.includes(n));if(!a||a.some(S=>e.fixedIds.has(S)||(s.get(S)??[]).some(E=>e.fixedIds.has(E))))return;const c=kr(e,e.positions);if(a.some(S=>!c.has(S)))return;const l=((x=e.nodes.find(S=>S.id===t))==null?void 0:x.parent)??"canvas",d=(v=(w=r.adjustment)==null?void 0:w.sections)==null?void 0:v[l],u=[],h=[...a].sort((S,E)=>{const R=c.get(S),P=c.get(E),I=(R.y1+R.y2-P.y1-P.y2)/2;return Math.abs(I)>1?I:R.x1-P.x1});for(const S of h){const E=u.at(-1),R=c.get(S),P=E&&c.get(E[0]);P&&Math.abs(R.y1+R.y2-P.y1-P.y2)<2?E.push(S):u.push([S])}const p=u.map((S,E)=>{var R;return{weight:((R=d==null?void 0:d.rows)==null?void 0:R[E])??1,cells:S.map((P,I)=>{var M,k;return{id:P,weight:((k=(M=d==null?void 0:d.columns)==null?void 0:M[E])==null?void 0:k[I])??1}})}});for(const S of p)S.cells=S.cells.filter(E=>E.id!==t);const m=p.filter(S=>S.cells.length),g=m.findIndex(S=>S.cells.some(E=>E.id===n)),y=m[g];if(!y)return;o==="above"||o==="below"?m.splice(g+(o==="below"?1:0),0,{weight:1,cells:[{id:t,weight:1}]}):y.cells.splice(y.cells.findIndex(S=>S.id===n)+(o==="after"?1:0),0,{id:t,weight:1});const b=m.map(S=>S.cells.map(E=>E.id));if(JSON.stringify(b)!==JSON.stringify(u))return{...r,adjustment:{...r.adjustment,sections:{...(C=r.adjustment)==null?void 0:C.sections,[l]:{...d,members:b,rows:m.map(S=>S.weight),columns:m.map(S=>S.cells.map(E=>E.weight))}}}}}function bd(e,r={}){var d;ov(r.adjustment);const t=pu(r),n=typeof r.gaps=="object"?r.gaps:{x:r.gaps??t,y:r.gaps??t};if(!n||[n.x,n.y].some(u=>!Number.isFinite(u)||u<0))throw new RangeError("Grid gaps must be finite and non-negative.");const o=r.padding??0;if(!Number.isFinite(o)||o<0)throw new RangeError("Grid padding must be finite and non-negative.");if(r.columns!==void 0&&(!Number.isSafeInteger(r.columns)||r.columns<1))throw new RangeError("Grid columns must be a positive safe integer.");if(r.fill&&e.viewportSize)return Hj(e,r,n,o);const{groups:i,leaves:s}=Yn(e),a=new Map([...e.positions].map(([u,h])=>[u,{...h}])),c=new Set;for(const u of i){const h=kr(e,a),p=u.filter(M=>h.has(M));if(p.length<2)continue;if(p.some(M=>e.fixedIds.has(M)||(s.get(M)??[]).some(k=>e.fixedIds.has(k)))){p.forEach(M=>c.add(M));continue}const g=p.map(M=>h.get(M)),y=Math.max(...g.map(M=>M.x2-M.x1)),b=Math.max(...g.map(M=>M.y2-M.y1)),x=Math.min(p.length,r.columns??Math.ceil(Math.sqrt(p.length))),w=((d=e.nodes.find(M=>M.id===p[0]))==null?void 0:d.parent)??"canvas",v=sv(p,r,w,x),C=Math.max(...v.map(M=>M.length)),S=y+n.x,E=b+n.y,R=g.map(M=>({x:(M.x1+M.x2)/2,y:(M.y1+M.y2)/2})),P=(Math.min(...R.map(M=>M.x))+Math.max(...R.map(M=>M.x)))/2,I=(Math.min(...R.map(M=>M.y))+Math.max(...R.map(M=>M.y)))/2;v.forEach((M,k)=>M.forEach((_,N)=>{const $=h.get(_),D={x:P+(N-(C-1)/2)*S-($.x1+$.x2)/2,y:I+(k-(v.length-1)/2)*E-($.y1+$.y2)/2};for(const T of s.get(_)??[]){const Z=a.get(T);a.set(T,{x:Z.x+D.x,y:Z.y+D.y})}}))}const l=[...a].filter(([u,h])=>{const p=e.positions.get(u);return h.x!==p.x||h.y!==p.y}).map(([u])=>u);return{positions:a,movedNodeIds:l,skippedNodeIds:[...c],collisions:Vn(i,kr(e,a),Math.min(n.x,n.y))}}function Hj(e,r,t,n){const{groups:o,children:i,roots:s}=Yn(e),a=new Map([...e.positions].map(([y,b])=>[y,{...b}]));if(e.nodes.some(y=>e.fixedIds.has(y.id)))return{positions:a,movedNodeIds:[],skippedNodeIds:e.nodes.map(y=>y.id),collisions:av(e,{margin:Math.min(t.x,t.y)})};const c=e.viewportSize,l=Math.min(n,Math.max(0,(c.w-1)/2)),d=Math.min(n,Math.max(0,(c.h-1)/2)),u={x1:l,y1:d,x2:Math.max(l+1,c.w-l),y2:Math.max(d+1,c.h-d)},h=new Map,p=[],m=(y,b,x="canvas")=>{var N,$;if(!y.length)return;const w=b.x2-b.x1,v=b.y2-b.y1,C=Math.min(y.length,r.columns??Math.max(1,Math.round(Math.sqrt(y.length*w/v)))),S=sv(y,r,x,C),E=S.length,R=Math.min(t.y,v/(2*E)),P=($=(N=r.adjustment)==null?void 0:N.sections)==null?void 0:$[x],I=Array.from({length:E},(D,T)=>{var Z;return((Z=P==null?void 0:P.rows)==null?void 0:Z[T])??1}),M=I.reduce((D,T)=>D+T,0),k=v-(E-1)*R;let _=b.y1;for(let D=0;D<E;D++){const T=k*I[D]/M,Z=S[D].length,K=Math.min(t.x,w/(2*Z)),ne=Array.from({length:Z},(q,F)=>{var H,G;return((G=(H=P==null?void 0:P.columns)==null?void 0:H[D])==null?void 0:G[F])??1}),se=ne.reduce((q,F)=>q+F,0),W=w-(Z-1)*K;let ue=b.x1;for(let q=0;q<Z;q++){const F=S[D][q],H=W*ne[q]/se,G=i.get(F);if(G){a.set(F,{x:ue+H/2,y:_+T/2}),h.set(F,{w:H,h:T});const ce=Math.min(e.padding(F),Math.max(0,(Math.min(H,T)-1)/2));m(G,{x1:ue+ce,y1:_+ce,x2:ue+H-ce,y2:_+T-ce},F)}else a.has(F)&&(a.set(F,{x:ue+H/2,y:_+T/2}),h.set(F,{w:H,h:T}));q<Z-1&&p.push({section:x,axis:"x",row:D,index:q,weights:ne,length:W,position:{x:ue+H+K/2,y:_+T/2}}),ue+=H+K}D<E-1&&p.push({section:x,axis:"y",row:D,index:D,weights:I,length:k,position:{x:b.x1+w/2,y:_+T+R/2}}),_+=T+R}};m(s,u);const g=[...a].filter(([y,b])=>{const x=e.positions.get(y);return!x||b.x!==x.x||b.y!==x.y}).map(([y])=>y);return{positions:a,movedNodeIds:g,skippedNodeIds:[],bounds:u,sizes:h,dividers:p,collisions:Vn(o,kr({...e,sizes:h},a,h),0)}}function Uj(e,r={}){const t=pu(r),n=r.maxIterations??50;if(!Number.isInteger(n)||n<0||n>1e3)throw new RangeError("Collision maxIterations must be an integer between 0 and 1000.");const{groups:o,leaves:i}=Yn(e),s=new Map([...e.positions].map(([u,h])=>[u,{...h}])),a=u=>e.fixedIds.has(u)||(i.get(u)??[]).some(h=>e.fixedIds.has(h));let c=Vn(o,kr(e,s),t),l=0;for(;c.length&&l<n;){let u=!1;for(const h of o){if(h.length<2)continue;const p=kr(e,s),m=(g,y,b)=>{for(const w of i.get(g)??[])s.get(w)[y]+=b;const x=p.get(g);y==="x"?(x.x1+=b,x.x2+=b):(x.y1+=b,x.y2+=b)};for(let g=0;g<h.length;g++)for(let y=g+1;y<h.length;y++){const b=h[g],x=h[y],w=iv(b,x,p,t);if(!w)continue;const v=a(b),C=a(x);if(v&&C)continue;const S=w.overlap.x<=w.overlap.y?"x":"y",E=p.get(b),R=p.get(x),P=S==="x"?E.x1+E.x2<=R.x1+R.x2?-1:1:E.y1+E.y2<=R.y1+R.y2?-1:1,I=w.overlap[S];v||m(b,S,P*I/(C?1:2)),C||m(x,S,-P*I/(v?1:2)),u=!0}}if(l++,c=Vn(o,kr(e,s),t),!u)break}const d=[...s].filter(([u,h])=>{const p=e.positions.get(u);return h.x!==p.x||h.y!==p.y}).map(([u])=>u);return{positions:s,movedNodeIds:d,collisions:c,iterations:l,resolved:c.length===0}}function Kj({dividers:e,options:r,zoom:t,onChange:n}){const o=j.useRef();return f.jsx(f.Fragment,{children:e.map(i=>{const s=i.axis==="x",a=s?ee.PiArrowsHorizontal:ee.PiArrowsVertical,c=`${s?"Column":"Row"} divider ${i.index+1}${s?` in row ${i.row+1}`:""}`;return f.jsx("button",{type:"button",role:"separator","aria-label":c,"aria-orientation":s?"vertical":"horizontal","aria-valuemin":5,"aria-valuemax":95,"aria-valuenow":Math.round(100*i.weights[i.index]/(i.weights[i.index]+i.weights[i.index+1])),title:c,"data-flow-grid-adjustment":"",style:{position:"absolute",left:i.position.x,top:i.position.y,transform:"translate(-50%, -50%)",width:28,height:28,padding:3,border:"1px solid currentColor",borderRadius:4,background:"var(--chakra-colors-gray-100)",color:"var(--chakra-colors-gray-800)",display:"grid",placeItems:"center",cursor:s?"col-resize":"row-resize",touchAction:"none",pointerEvents:"auto",zIndex:30},onPointerDown:l=>{if(l.button!==0)return;l.preventDefault(),l.stopPropagation();const d=l.currentTarget.closest(".flow-sdk-canvas"),u=d.getBoundingClientRect();o.current={pointerId:l.pointerId,start:s?l.clientX:l.clientY,scale:t*(s?u.width/d.clientWidth:u.height/d.clientHeight),divider:i,options:r},l.currentTarget.setPointerCapture(l.pointerId)},onPointerMove:l=>{const d=o.current;if(!d||d.pointerId!==l.pointerId)return;l.preventDefault(),l.stopPropagation();const u=((s?l.clientX:l.clientY)-d.start)/d.scale;n(km(d.options,d.divider,u))},onPointerUp:l=>{o.current&&(l.stopPropagation(),o.current=void 0,l.currentTarget.releasePointerCapture(l.pointerId))},onPointerCancel:()=>{o.current&&n(o.current.options),o.current=void 0},onLostPointerCapture:()=>{o.current=void 0},onClick:l=>l.stopPropagation(),onKeyDown:l=>{l.key==="Escape"&&o.current&&(n(o.current.options),o.current=void 0);const d=(s?["ArrowLeft","ArrowRight"]:["ArrowUp","ArrowDown"]).indexOf(l.key);d<0||(l.preventDefault(),l.stopPropagation(),n(km(r,i,i.length*(l.shiftKey?.1:.02)*(d===0?-1:1))))},children:f.jsx(a,{size:20,"aria-hidden":"true"})},`${i.section}:${i.axis}:${i.row}:${i.index}`)})})}const Pm=(e,r)=>e.left<r.right&&e.right>r.left&&e.top<r.bottom&&e.bottom>r.top,xd=new WeakMap;function Am(e,r){const t=[...r.querySelectorAll(".flow-sdk-edge-label")];if(!t.length){xd.delete(r);return}const n=r==null?void 0:r.getScreenCTM();if(!r||!n)return;const o=n.inverse(),i=(u,h=0)=>{const p=u.getBoundingClientRect(),m=new DOMPoint(p.left,p.top).matrixTransform(o),g=new DOMPoint(p.right,p.bottom).matrixTransform(o);return{left:m.x-h,right:g.x+h,top:m.y-h,bottom:g.y+h}},s=[...e.querySelectorAll(".flow-sdk-node, .flow-sdk-node button")].filter(u=>u.closest(".flow-sdk-canvas")===e).filter(u=>{const h=u.getBoundingClientRect(),p=getComputedStyle(u);return h.width>0&&h.height>0&&p.visibility!=="hidden"&&p.opacity!=="0"}).map(u=>i(u,24));for(const u of r.querySelectorAll(".flow-sdk-container-label"))s.push(i(u,12));const a=new Map([...e.querySelectorAll(".flow-sdk-edge")].filter(u=>u.closest(".flow-sdk-canvas")===e).map(u=>[u.dataset.edgeId,u.querySelector("path")])),c=JSON.stringify([s,[...a].map(([u,h])=>[u,h==null?void 0:h.getAttribute("d")]),t.map(u=>{var m;const h=u.getBBox(),p=(m=u.querySelector("rect"))==null?void 0:m.getBBox();return[u.dataset.edgeId,u.dataset.labelTransform,u.dataset.labelHorizontal,h.x,h.y,h.width,h.height,p==null?void 0:p.width,p==null?void 0:p.height]})],(u,h)=>typeof h=="number"?Math.round(h*1e3)/1e3:h),l=xd.get(r);if((l==null?void 0:l.geometry)===c&&t.every(u=>l.transforms.has(u))){for(const u of t){const h=l.transforms.get(u);u.getAttribute("transform")!==h&&u.setAttribute("transform",h)}return}for(const u of t)u.setAttribute("transform",u.dataset.labelTransform??"");const d=new Map(t.map(u=>[u,i(u,8)]));for(const u of t){const h=u.dataset.labelHorizontal==="true",p=d.get(u);d.delete(u);const m=P=>s.some(I=>Pm(P,I))||[...d.values()].some(I=>Pm(P,I));if(!h&&!m(p)){d.set(u,p);continue}const g=a.get(u.dataset.edgeId),y=u.querySelector("rect");if(!g||!y)continue;const b=y.getBBox(),x=g.getTotalLength();if(!Number.isFinite(x)||x<=0)continue;const w=(p.left+p.right)/2,v=(p.top+p.bottom)/2,C=Math.min(256,Math.max(16,Math.ceil(x/24))),S=Array.from({length:C+1},(P,I)=>g.getPointAtLength(x*I/C)),R=Array.from({length:C+1},(P,I)=>{const M=x*I/C,k=S[I],_=h?{x:k.x,y:k.y-b.height/2-15}:k,N=g.getPointAtLength(Math.max(0,M-2)),$=g.getPointAtLength(Math.min(x,M+2));let D=Math.atan2($.y-N.y,$.x-N.x)*180/Math.PI;D>90&&(D-=180),D<-90&&(D+=180);const T=Math.abs(D)<1;h&&(D=0);const Z=D*Math.PI/180,K=Math.abs(Math.cos(Z))*b.width+Math.abs(Math.sin(Z))*b.height,ne=Math.abs(Math.sin(Z))*b.width+Math.abs(Math.cos(Z))*b.height;return{point:_,angle:D,straight:T,score:Math.hypot(_.x-w,_.y-v),bounds:{left:_.x-K/2-8,right:_.x+K/2+8,top:_.y-ne/2-8,bottom:_.y+ne/2+8}}}).sort((P,I)=>P.score-I.score).find(P=>!m(P.bounds)&&(!h||P.straight&&!S.some(I=>I.x>P.bounds.left&&I.x<P.bounds.right&&I.y>P.bounds.top&&I.y<P.bounds.bottom)));R?(u.setAttribute("transform",`translate(${R.point.x} ${R.point.y}) rotate(${R.angle})`),d.set(u,R.bounds)):d.set(u,p)}xd.set(r,{geometry:c,transforms:new Map(t.map(u=>[u,u.getAttribute("transform")??""]))})}function Jj(e){const r=e.getBoundingClientRect(),t=r.height/e.offsetHeight;if(!Number.isFinite(t)||t<=0)return[];const n=Qb(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],s=new Set(i.filter(a=>a.hasAttribute("data-flow-inspection-row")&&a.getBoundingClientRect().height>0).map(a=>a.dataset.flowProperty));return i.flatMap(a=>{if(a.closest(".flow-sdk-node")!==e)return[];if(s.has(a.dataset.flowProperty)&&!a.hasAttribute("data-flow-inspection-row"))return[];const c=a.dataset.flowPortSide;if(c&&["top","right","bottom","left"].includes(c)){const d=Zb(n?qn(o,n):o,c,Number(a.dataset.flowPortPosition??.5));return[{property:a.getAttribute("data-flow-property"),top:d.y,height:0,anchor:d,...a.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]}const l=a.getBoundingClientRect();return!l.width||!l.height?[]:[{property:a.getAttribute("data-flow-property"),top:Math.round((l.top-r.top)/t*1e3)/1e3,height:Math.round(l.height/t*1e3)/1e3,...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]})}function Zj({id:e,x:r,y:t,placed:n,hidden:o,gridDraggable:i,gridDragging:s,gridDropTarget:a,gridSize:c,gridPreview:l,onMount:d,drawHandles:u,drawMode:h,connectedPorts:p,resolvedRows:m,hasCollapseControl:g,handleColor:y,animated:b,animationColor:x,animationWidth:w=8,animationVariant:v,width:C=0,height:S=0,propertyMode:E,reversePorts:R,direction:P="LR",onPropertyRows:I,onSurface:M,children:k}){var G,ce;const _=j.useRef(null),[N,$]=j.useState([]),D=m??N,[T,Z]=j.useState(),K=j.useId(),ne=j.useRef(),se=!!l,W=!!(l!=null&&l.floating);j.useLayoutEffect(()=>{var xe;const te=_.current;if(!te||!se)return;const X=te.cloneNode(!0);X.removeAttribute("data-node-id"),X.removeAttribute("data-grid-dragging"),X.removeAttribute("data-grid-draggable"),X.removeAttribute("data-grid-drop-target"),X.setAttribute("data-grid-preview",e),X.setAttribute("aria-hidden","true"),X.setAttribute("inert","");const ie=[X,...X.querySelectorAll("*")],me=new Map(ie.filter(fe=>fe.id).map(fe=>[fe.id,`${fe.id}-${K}`]));for(const fe of ie){fe.id&&(fe.id=me.get(fe.id));for(const U of[...fe.attributes]){if(U.name==="id")continue;let re=U.value;for(const[de,Pe]of me)re===`#${de}`&&(re=`#${Pe}`),re=re.split(`url(#${de})`).join(`url(#${Pe})`);re!==U.value&&fe.setAttribute(U.name,re)}}if(Object.assign(X.style,{opacity:"0.35",zIndex:W?"2147483647":"11",pointerEvents:"none",outline:"none",visibility:"visible"}),W){const fe=getComputedStyle(te);X.setAttribute("data-grid-preview-floating",""),Object.assign(X.style,{position:"fixed",left:"0",top:"0",transformOrigin:"top left",font:fe.font,color:fe.color});for(const U of ie)U.removeAttribute("data-node-id"),U.style.pointerEvents="none"}return X.querySelectorAll(".flow-sdk-node-animation, .flow-sdk-handle, .flow-sdk-property-port, [data-flow-collapse-control]").forEach(fe=>fe.remove()),(xe=W?document.body:te.parentElement)==null||xe.appendChild(X),ne.current=X,()=>{X.remove(),ne.current=void 0}},[e,K,se,W]),j.useLayoutEffect(()=>{const te=ne.current;if(!te||!l)return;const{x:X,y:ie,size:me}=l;if(W&&_.current){const U=_.current,re=U.getBoundingClientRect(),de=re.width/U.offsetWidth||1,Pe=re.height/U.offsetHeight||1,ae=re.left+(X-r)*de,we=re.top+(ie-t)*Pe;te.style.transform=`translate3d(${ae}px, ${we}px, 0) scale(${de}, ${Pe})`,te.style.width=`${U.offsetWidth}px`,te.style.height=`${U.offsetHeight}px`;return}const xe=me?Math.round(X-me.w/2):X,fe=me?Math.round(ie-me.h/2):ie;te.style.transform=me?`translate3d(${xe}px, ${fe}px, 0)`:`translate(-50%, -50%) translate3d(${xe}px, ${fe}px, 0)`,te.style.width=me?`${Math.round(X+me.w/2)-xe}px`:"",te.style.height=me?`${Math.round(ie+me.h/2)-fe}px`:"",me&&(te.style.setProperty("--flow-grid-width",`${me.w}px`),te.style.setProperty("--flow-grid-height",`${me.h}px`),te.style.setProperty("--flow-grid-font",`${Math.max(12,Math.min(48,me.w/8,me.h/5))}px`))},[l==null?void 0:l.x,l==null?void 0:l.y,(G=l==null?void 0:l.size)==null?void 0:G.w,(ce=l==null?void 0:l.size)==null?void 0:ce.h,W,r,t]),j.useLayoutEffect(()=>{const te=_.current;if(!te)return;const X=()=>{const xe=Qb(te);Z(fe=>JSON.stringify(fe)===JSON.stringify(xe)?fe:xe),M==null||M(e,xe)};X();const ie=new ResizeObserver(X);ie.observe(te);const me=te.querySelector("[data-flow-node-surface]");return me&&ie.observe(me),()=>ie.disconnect()},[e,k,M]),j.useLayoutEffect(()=>(d(e,_.current),()=>{d(e,null),M==null||M(e,void 0)}),[e,d,M]),j.useLayoutEffect(()=>{const te=_.current;if(!te)return;let X="";const ie=()=>{const U=Jj(te),re=E?U:U.filter(Pe=>Pe.anchor),de=JSON.stringify(re);de!==X&&(X=de,$(re),I==null||I(e,re))};if(ie(),!E&&!te.querySelector("[data-flow-port-side]"))return;const me=new ResizeObserver(ie),xe=()=>{me.disconnect(),me.observe(te),te.querySelectorAll("[data-flow-property]").forEach(U=>me.observe(U)),ie()};xe();const fe=new MutationObserver(xe);return fe.observe(te,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["data-flow-property","data-flow-port-role","data-flow-port-side","data-flow-port-position","data-flow-port-placement"]}),te.addEventListener("scroll",ie,!0),()=>{me.disconnect(),fe.disconnect(),te.removeEventListener("scroll",ie,!0)}},[e,E,I,k]);const ue=c?Math.round(r-c.w/2):0,q=c?Math.round(t-c.h/2):0,F=c?Math.round(r+c.w/2)-ue:void 0,H=c?Math.round(t+c.h/2)-q:void 0;return f.jsxs("div",{ref:_,className:"flow-sdk-node","data-node-id":e,"data-grid-draggable":i||void 0,"data-grid-dragging":s||void 0,"data-grid-drop-target":a||void 0,"data-grid-fill":c?"":void 0,style:{transform:c?`translate3d(${ue}px, ${q}px, 0)`:`translate(-50%, -50%) translate3d(${r.toFixed(2)}px, ${t.toFixed(2)}px, 0)`,visibility:n&&!o?void 0:"hidden",cursor:i?s?"grabbing":"grab":void 0,zIndex:s?12:void 0,opacity:l?0:s?.75:void 0,outline:a?`2px solid ${y||"currentColor"}`:void 0,outlineOffset:a?8:void 0,width:F,height:H,...c?{"--flow-grid-width":`${c.w}px`,"--flow-grid-height":`${c.h}px`,"--flow-grid-font":`${Math.max(12,Math.min(48,c.w/8,c.h/5))}px`}:{}},children:[k,!c&&b&&w>0&&C>0&&S>0&&f.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:f.jsx(go,{variant:v,x:((T==null?void 0:T.left)??0)+w/2,y:((T==null?void 0:T.top)??0)+w/2,width:((T==null?void 0:T.width)??C)-w,height:((T==null?void 0:T.height)??S)-w,radius:((T==null?void 0:T.radius)??0)-w/2,path:T!=null&&T.outline?`M${T.outline.map(te=>`${te.x} ${te.y}`).join(" L")} Z`:void 0,color:x||y||"currentColor",strokeWidth:w})}),u&&E&&D.map(te=>["source","target"].filter(X=>!te.role||te.role===X).filter(X=>h||(p==null?void 0:p.has(`${X}:${te.property}`))).map(X=>{var ie;return f.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":te.property,"data-port-role":X,"data-port-side":(ie=te.anchor)==null?void 0:ie.side,"aria-label":`${X==="source"?"Connect":"Input"} ${te.property}`,title:`${X==="source"?"Connect":"Input"} ${te.property}`,style:{color:y,...te.anchor?{top:te.anchor.y,left:te.anchor.x-16}:{top:te.top+te.height/2,[X==="source"!=!!R?"right":"left"]:-16}},onClick:me=>me.stopPropagation()},`${te.property}:${X}`)})),u&&!g&&(!E||!D.length)&&(!E||!D.some(te=>te.anchor))&&f.jsx("button",{type:"button",className:"flow-sdk-handle","aria-label":"Draw edge",title:"Draw edge",style:{color:y,left:((T==null?void 0:T.left)??0)+(P==="RL"?-36:P==="LR"?(T==null?void 0:T.width)??C:((T==null?void 0:T.width)??C)/2),top:((T==null?void 0:T.top)??0)+(P==="BT"?-36:P==="TB"?(T==null?void 0:T.height)??S:((T==null?void 0:T.height)??S)/2),transform:P==="BT"||P==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:te=>te.stopPropagation(),children:f.jsx(ee.PiPlusBold,{size:24})})]})}const Xj=j.memo(Zj);function Yj(e,r,t){const[n,o]=j.useState(()=>({nodes:new Set,edges:new Set})),i=j.useMemo(()=>{const a=new Set(e.map(p=>p.id)),c=r.filter(p=>a.has(p.source)&&a.has(p.target)).map(p=>({id:p.id,source:p.inverted?p.target:p.source,target:p.inverted?p.source:p.target})),l=new Set(c.map(p=>p.id)),d=new Set([...n.nodes].filter(p=>a.has(p))),u=new Set([...n.edges].filter(p=>l.has(p)));if(!t)return{nodes:a,edges:l,ready:l};for(const p of e)c.filter(g=>g.target===p.id&&g.source!==g.target).every(g=>u.has(g.id))&&d.add(p.id);let h=new Set(c.filter(p=>d.has(p.source)).map(p=>p.id));if(d.size<a.size&&!c.some(p=>h.has(p.id)&&!u.has(p.id))){const p=e.find(m=>!d.has(m.id));p&&d.add(p.id),h=new Set(c.filter(m=>d.has(m.source)).map(m=>m.id))}return{nodes:d,edges:u,ready:h}},[e,r,t,n]);j.useLayoutEffect(()=>{o(a=>{const c=t?i:{nodes:new Set,edges:new Set},l=(d,u)=>d.size===u.size&&[...d].every(h=>u.has(h));return l(a.nodes,c.nodes)&&l(a.edges,c.edges)?a:{nodes:c.nodes,edges:c.edges}})},[i,t]);const s=j.useCallback(a=>{o(c=>c.edges.has(a)?c:{...c,edges:new Set([...c.edges,a])})},[]);return{shown:i.nodes,ready:i.ready,complete:s}}class Qj{constructor(r,t,n){zt(this,"_pan");zt(this,"_zoom");zt(this,"minZoom");zt(this,"maxZoom");zt(this,"size",{w:0,h:0});zt(this,"listeners",new Set);zt(this,"cancelTransition");zt(this,"animationVersion",0);zt(this,"captureTransition");zt(this,"animationsDisabled",!1);zt(this,"finishTransition");this.minZoom=t,this.maxZoom=n,this._pan={...r.pan},this._zoom=this.clamp(r.zoom)}setAnimationsDisabled(r){var t;r!==this.animationsDisabled&&(this.animationsDisabled=r,r&&((t=this.finishTransition)==null||t.call(this),this.cancelAnimation()))}cancelAnimation(){var r;(r=this.cancelTransition)==null||r.call(this),this.cancelTransition=void 0,this.finishTransition=void 0,this.animationVersion++}coordinate(r){let t;this.captureTransition=n=>{t=n};try{r()}finally{this.captureTransition=void 0}return t}transition(r,t=!1){this.cancelAnimation();const n=this.state,o={pan:{...r.pan},zoom:this.clamp(r.zoom)},i=this.animationVersion,s=Kb(t,this.animationsDisabled),a=c=>{if(i!==this.animationVersion)return;const l=s?c:1;this.apply({x:n.pan.x+(o.pan.x-n.pan.x)*l,y:n.pan.y+(o.pan.y-n.pan.y)*l},n.zoom+(o.zoom-n.zoom)*l)};this.finishTransition=()=>a(1),this.captureTransition?this.captureTransition(a):this.cancelTransition=Jb(s,a,void 0,300/1.4)}get pan(){return{...this._pan}}get zoom(){return this._zoom}get state(){return{pan:this.pan,zoom:this._zoom}}clamp(r){return Number.isFinite(r)?Math.max(this.minZoom,Math.min(this.maxZoom,r)):this.minZoom}set(r,t){this.cancelAnimation(),this.apply(r,t)}apply(r,t){let n=!1;if(r&&(r.x!==this._pan.x||r.y!==this._pan.y)&&(this._pan={x:r.x,y:r.y},n=!0),t!==void 0){const o=this.clamp(t);o!==this._zoom&&(this._zoom=o,n=!0)}n&&this.emit()}zoomAt(r,t){const n=this.clamp(r),o=this._zoom;if(n===o)return;const i=n/o;this.set({x:t.x-(t.x-this._pan.x)*i,y:t.y-(t.y-this._pan.y)*i},n)}fit(r,t=0,n=!1,o=1){const i=r.x2-r.x1,s=r.y2-r.y1;if(!(i>0)||!(s>0)||!this.size.w||!this.size.h)return;const a=this.clamp(this.clamp(Math.min((this.size.w-2*t)/i,(this.size.h-2*t)/s))*o);this.transition({pan:{x:(this.size.w-a*(r.x1+r.x2))/2,y:(this.size.h-a*(r.y1+r.y2))/2},zoom:a},n)}center(r,t=!1){if(!this.size.w||!this.size.h)return;const n=this._zoom;this.transition({pan:{x:(this.size.w-n*(r.x1+r.x2))/2,y:(this.size.h-n*(r.y1+r.y2))/2},zoom:n},t)}renderedToModel(r){return{x:(r.x-this._pan.x)/this._zoom,y:(r.y-this._pan.y)/this._zoom}}modelToRendered(r){return{x:r.x*this._zoom+this._pan.x,y:r.y*this._zoom+this._pan.y}}onChange(r){return this.listeners.add(r),()=>{this.listeners.delete(r)}}emit(){const r=this.state;this.listeners.forEach(t=>t(r))}}const eE={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},ao={w:60,h:60},vd=4,tE=30,rE=500,nE=45;function Rm(e){const[r,t]=[...e.values()];return!r||!t?null:{center:{x:(r.x+t.x)/2,y:(r.y+t.y)/2},distance:Math.max(1,Math.hypot(t.x-r.x,t.y-r.y))}}function oE(e){var Su,ju,Eu,_u,ku;const{nodes:r,edges:t,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:s=!1,rankSep:a,edgeSep:c,spacingFactor:l=1.3,compactSpacingScale:d,minZoom:u,maxZoom:h,initialViewport:p,containerStyle:m,lineColor:g,drawMode:y,dragMode:b,multiSelect:x,isPerformanceMode:w,disableAnimations:v=!1}=e,[C,S]=j.useState(null),E=j.useMemo(()=>C?(C.mode==="connections"?rf:Zu)(C.id,r,t):null,[C,r,t]),R=i==="auto"||i==="properties",P=j.useMemo(()=>t.filter(A=>Pd(A,i)&&(!E||E.has(A.source)&&E.has(A.target))),[t,i,E]),I=j.useMemo(()=>C1(r,t,i,s,E),[r,t,i,s,E]),M=j.useRef(I);M.current=I;const k=j.useRef(e);k.current=e;const _=j.useRef(null),N=j.useRef(null),$=j.useRef(null),D=j.useRef(null),T=j.useMemo(()=>new Qj(p,u,h),[]);j.useEffect(()=>{T.minZoom=u,T.maxZoom=h},[T,u,h]),j.useLayoutEffect(()=>{T.setAnimationsDisabled(v)},[T,v]);const Z=j.useRef(new Map),K=j.useRef(new Map),ne=j.useRef(new Map),se=j.useRef(null),[W,ue]=j.useState(new Map),q=j.useCallback((A,L)=>{ue(B=>{if(JSON.stringify(B.get(A))===JSON.stringify(L))return B;const J=new Map(B);return L?J.set(A,L):J.delete(A),J})},[]),[F,H]=j.useState(new Map),G=j.useRef(F),ce=j.useCallback((A,L)=>{H(B=>{if(JSON.stringify(B.get(A)??[])===JSON.stringify(L))return B;const J=new Map(B);return L.length?J.set(A,L):J.delete(A),J})},[]),[te,X]=j.useState(()=>new Map),ie=j.useRef(te);ie.current=te;const[me,xe]=j.useState(new Map),fe=j.useRef(me),U=()=>{fe.current=new Map,xe(fe.current)},re=j.useRef(new Map(Object.entries(e.fixedNodePositions??{}))),de=j.useRef(new Set(Object.keys(e.fixedNodePositions??{}))),Pe=j.useRef(null),ae=j.useRef(!1),[we,$e]=j.useState(0),Ue=j.useRef(),Ve=j.useRef(),tt=j.useRef(null),ge=j.useRef(),Ae=j.useRef(!1),Le=j.useRef(null),be=j.useRef(null),Xe=j.useRef(),ut=j.useRef(l),Re=s,Ke=j.useRef(Re),[lt,Je]=j.useState(!0),[mt,At]=j.useState(!!((Su=e.initialNodeGrid)!=null&&Su.enabled)),[Jr,Tr]=j.useState([]),rt=j.useRef((ju=e.initialNodeGrid)!=null&&ju.enabled?{options:{...e.initialNodeGrid.options,animate:!1},order:[...e.initialNodeGrid.order??e.initialNodeGrid.options.order??r.map(A=>A.id)],previousPositions:new Map,previousViewport:p,previousSize:{w:0,h:0},ready:!1}:null),[We,Qt]=j.useState(null),ft=j.useRef(null);ft.current=E;const qt=j.useRef(1);qt.current=(C==null?void 0:C.mode)==="connections"?1.25:1;const dr=j.useRef(null),De=j.useRef(r),Ht=j.useRef([]),Lt=j.useRef(!1),ur=()=>{var A;(A=tt.current)==null||A.call(tt),tt.current=null,ge.current=void 0},z=()=>{be.current=null,Ht.current.length&&!re.current.size&&(Lt.current=!0),!ae.current&&k.current.fitOnInit!==!1&&(Ae.current=!0),clearTimeout(Ve.current),Ve.current=setTimeout(()=>{ae.current=ie.current.size>0,$e(A=>A+1)},rE)},O=(A,L,B,J=z,he)=>{ur();const Ee=new Map(ie.current),Ce=new Map([...Z.current,...fe.current]);tt.current=Jb(L,Se=>{const Qe=new Map;if(A.forEach((qe,Be)=>{const ke=Ee.get(Be);Qe.set(Be,re.current.get(Be)??(ke?{x:ke.x+(qe.x-ke.x)*Se,y:ke.y+(qe.y-ke.y)*Se}:qe))}),ie.current=Qe,X(Qe),he){const qe=new Map;for(const[Be,ke]of he){const Y=Ce.get(Be)??ke;qe.set(Be,{w:Y.w+(ke.w-Y.w)*Se,h:Y.h+(ke.h-Y.h)*Se})}fe.current=qe,xe(qe)}B==null||B(Se)},J)},oe=()=>{var Be;if(clearTimeout(Ue.current),rt.current){pt.arrangeNodesInGrid(rt.current.options);return}fe.current.size&&U();const A=k.current,L=qt.current,B=M.current,J=new Set(A.nodes.filter(ke=>ke.label===void 0).map(ke=>ke.id)),he=B.nodes.map(ke=>{const Y=K.current.get(ke.id);Y&&(Y.offsetWidth||Y.offsetHeight)&&Z.current.set(ke.id,{w:Y.offsetWidth,h:Y.offsetHeight});const Q=Z.current.get(ke.id)||ao;return{id:ke.id,parent:ke.parent,width:Q.w,height:Q.h,hasBody:J.has(ke.id)}});let Ee;try{const ke=A.compactPropertyLayout,Y=A.edgeMode!=="nodes"&&A.edgeMode!=="workflow",Q=B.edges.map(pe=>({...pe,connectorClearance:ke?Y&&(pe.sourceProperty!==void 0||pe.targetProperty!==void 0)?w1:v1:0}));Ee=Vj(he,Q,{edgeLabelFontSize:A.edgeMode==="nodes"||A.edgeMode==="workflow"?ex:yo,rankDir:A.direction,compact:ke,nodeAlignment:A.nodeAlignment,rankSep:A.rankSep*L,edgeSep:A.edgeSep*L,nodeSep:5*L,spacingFactor:A.spacingFactor??1.3,compactSpacingScale:(A.compactSpacingScale??(A.spacingFactor??1.3)/1.3)*L})}catch(ke){console.warn("[flow-sdk] layout failed",ke);return}const Ce=[...re.current].find(([ke])=>Ee.has(ke)),Se=Ce?{id:Ce[0],position:Ce[1]}:be.current?null:Pe.current;Pe.current=null;const Qe=Se&&Ee.get(Se.id);if(Se&&Qe){const ke={x:Se.position.x-Qe.x,y:Se.position.y-Qe.y};Ee=new Map([...Ee].map(([Y,Q])=>[Y,{x:Q.x+ke.x,y:Q.y+ke.y}]))}for(const[ke,Y]of re.current)A.nodes.some(Q=>Q.id===ke)?Ee.set(ke,Y):re.current.delete(ke);if(be.current){const ke=JSON.stringify([he,[...Ee],T.size,A.isPerformanceMode,A.disableAnimations]);if(((Be=Xe.current)==null?void 0:Be.focus)===be.current&&Xe.current.geometry===ke)return;Xe.current={focus:be.current,geometry:ke}}else Xe.current=void 0;const qe=T.coordinate(()=>{var ke;return(ke=be.current)==null?void 0:ke.call(be,Ee)});O(Ee,ae.current&&!A.isPerformanceMode&&!A.disableAnimations,qe)},ye=j.useCallback(()=>{clearTimeout(Ve.current),clearTimeout(Ue.current),Ue.current=setTimeout(oe,k.current.layoutDebounce)},[]);j.useLayoutEffect(()=>{const A=e.fixedNodePositions??{};let L=!1;for(const B of de.current)Object.prototype.hasOwnProperty.call(A,B)||(L=re.current.delete(B)||L);for(const[B,J]of Object.entries(A)){if(!r.some(Ee=>Ee.id===B)||!J||![J.x,J.y].every(Number.isFinite))continue;const he=re.current.get(B);((he==null?void 0:he.x)!==J.x||(he==null?void 0:he.y)!==J.y)&&(re.current.set(B,{...J}),L=!0)}de.current=new Set(Object.keys(A)),L&&ye()},[e.fixedNodePositions,r,ye]),j.useLayoutEffect(()=>{const A=new Map(De.current.map(L=>[L.id,L]));r.some(L=>{var B;return((B=A.get(L.id))==null?void 0:B.collapsed)===!0&&!L.collapsed})&&(Ht.current=r.filter(L=>!A.has(L.id)).map(L=>L.id)),De.current=r,ut.current!==l&&ie.current.size>0&&(ae.current=!0,Ae.current=!1,clearTimeout(Ve.current)),ut.current=l,Ke.current!==Re&&(Ae.current=!Le.current),Ke.current=Re,ye()},[r,t,I.nodes,I.edges,Re,n,o,a,c,ye,l,d,v,e.nodeGridSpacing]),j.useEffect(()=>()=>{clearTimeout(Ue.current),clearTimeout(Ve.current),ur()},[]);const je=j.useCallback((A,L)=>{var B,J;if(!se.current&&typeof ResizeObserver<"u"&&(se.current=new ResizeObserver(he=>{let Ee=!1;for(const Ce of he){const Se=ne.current.get(Ce.target);if(!Se||fe.current.has(Se))continue;const Qe=Ce.target,qe=Qe.offsetWidth,Be=Qe.offsetHeight;if(!qe&&!Be)continue;const ke=Z.current.get(Se);if(ke&&ke.w===qe&&ke.h===Be)continue;const Y=ie.current.get(Se);ke&&Y&&ae.current&&!Pe.current&&(Pe.current={id:Se,position:{...Y}}),Z.current.set(Se,{w:qe,h:Be}),Ee=!0}Ee&&ye()})),L){K.current.set(A,L),ne.current.set(L,A),(B=se.current)==null||B.observe(L);const he=L.offsetWidth,Ee=L.offsetHeight;!fe.current.has(A)&&(he||Ee)&&Z.current.set(A,{w:he,h:Ee})}else{const he=K.current.get(A);he&&((J=se.current)==null||J.unobserve(he),ne.current.delete(he)),K.current.delete(A),Z.current.delete(A),G.current.has(A)&&ce(A,[])}ye()},[ye,ce]);j.useEffect(()=>()=>{var A;return(A=se.current)==null?void 0:A.disconnect()},[]);const Ie=A=>{var J;const L=(J=k.current.nodes.find(he=>he.id===A))==null?void 0:J.label;if(!L)return;const B=k.current.containerStyle(A);return{w:Ao(L,`bold ${B.fontSize}px ${_r}`)+2*nE,h:0}},Me=j.useMemo(()=>{const A=new Map;for(const L of r)L.label&&A.set(L.id,L.label);return A},[r]),Ye=j.useMemo(()=>Ad(I.nodes,te,new Map([...Z.current,...me]),A=>m(A).padding,Ie,me),[I.nodes,te,m,Me,me]),et=j.useRef(Ye);et.current=Ye;const ze=j.useCallback(A=>{const L=et.current.get(A);if(L)return a1(L);const B=ie.current.get(A);if(!B)return;const J=fe.current.get(A)||Z.current.get(A)||ao;return{x:B.x,y:B.y,w:J.w,h:J.h}},[]),ct=j.useMemo(()=>{const A=new Map;for(const L of r){const B=ze(L.id);B&&A.set(L.id,B)}return g1(F,A,W,t,n)},[F,r,te,Ye,W,t,n,ze]);G.current=ct;const ht=(A,L)=>{var he;if(!R||L===void 0)return;const B=(he=ct.get(A))==null?void 0:he.find(Ee=>Ee.property===L),J=ze(A);return B&&!B.anchor&&J?J.y-J.h/2+B.top+B.height/2:void 0},wt=(A,L)=>{var he,Ee;if(L===void 0)return;const B=(Ee=(he=ct.get(A))==null?void 0:he.find(Ce=>Ce.property===L))==null?void 0:Ee.anchor,J=ze(A);return B&&J?{x:J.x-J.w/2+B.x,y:J.y-J.h/2+B.y,side:B.side}:void 0},St=(A,L)=>{const B=ze(A),J=W.get(A);return B&&J&&!Ye.has(A)&&ht(A,L)===void 0?qn(B,(n==="TB"||n==="BT")&&J.captionBottom!==void 0?{...J,height:Math.max(J.height,J.captionBottom-J.top),outline:void 0}:J):B},Rt=()=>{const A=[];ie.current.forEach((L,B)=>{if(et.current.has(B))return;const J=ze(B);J&&A.push(ir(J))}),et.current.forEach(L=>A.push(L));try{for(const L of[N.current,$.current]){const B=L==null?void 0:L.getBBox();B&&B.width>0&&B.height>0&&A.push({x1:B.x,y1:B.y,x2:B.x+B.width,y2:B.y+B.height})}}catch{}return ei(A)},Mt=()=>{var B,J;const{pan:A,zoom:L}=T;D.current&&(D.current.style.transform=`translate3d(${A.x}px, ${A.y}px, 0) scale(${L})`),(B=N.current)==null||B.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`),(J=$.current)==null||J.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`)};j.useEffect(()=>{Mt();let A=null,L;const B=T.onChange(()=>{Mt();const J=_.current;J&&(J.classList.add("flow-sdk-busy"),clearTimeout(L),L=setTimeout(()=>J.classList.remove("flow-sdk-busy"),150)),A===null&&(A=requestAnimationFrame(()=>{var he,Ee;A=null,(Ee=(he=k.current).onViewportChange)==null||Ee.call(he,T.state)}))});return()=>{B(),clearTimeout(L),A!==null&&cancelAnimationFrame(A)}},[]),j.useLayoutEffect(()=>{const A=_.current;if(!A)return;const L=()=>{var Ce;if(!A.getClientRects().length)return;let J=A.clientWidth,he=A.clientHeight;he||(he=Math.max(0,window.innerHeight-A.getBoundingClientRect().top-100),he&&(A.style.height=`${he}px`)),J||(J=window.innerWidth,J&&(A.style.width=`${J}px`));const Ee=T.size.w!==J||T.size.h!==he;T.size={w:J,h:he},Ee&&((Ce=rt.current)!=null&&Ce.options.fill)&&(!ae.current&&J>0&&he>0?oe():ye()),!ae.current&&!ie.current.size&&k.current.fitOnInit!==!1&&(T.set({x:J/2,y:he/2}),Mt())};if(L(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(L);return B.observe(A),()=>B.disconnect()},[T]),j.useLayoutEffect(()=>{if(Lt.current){Lt.current=!1;const L=Ht.current.flatMap(J=>{const he=ze(J);return he?[ir(he)]:[]});Ht.current=[];const B=ei(L);if(B){Ae.current=!1,T.center(B,k.current.animateViewport);return}}if(!Ae.current)return;Ae.current=!1;const A=Rt();A&&(T.fit(A,50,ae.current&&k.current.animateViewport),ae.current||Mt())},[te]);const pt=j.useMemo(()=>{const A=Y=>{const Q=k.current;if(Q.nodeGridSpacing!=="layout")return Y;const pe=Q.direction==="LR"||Q.direction==="RL";return{...Y,gaps:{x:pe?Q.rankSep:Q.edgeSep,y:pe?Q.edgeSep:Q.rankSep}}},L=()=>{const Y=k.current,Q=M.current.nodes.filter(pe=>ar(pe.id,Y.edges,Y.edgeMode)&&(!ft.current||ft.current.has(pe.id)));return{nodes:Q,positions:ie.current,sizes:new Map(Q.map(pe=>[pe.id,Z.current.get(pe.id)??ao])),padding:pe=>k.current.containerStyle(pe).padding,minSize:Ie,fixedIds:new Set(re.current.keys()),viewportSize:{...T.size}}},B=Y=>Zu(Y,k.current.nodes,k.current.edges),J=(Y,Q=!0,pe=()=>{},le,Fe,ve=!1)=>{clearTimeout(Ue.current),clearTimeout(Ve.current),ve||(be.current=null),Le.current=null,Ae.current=!1,Ht.current=[],Lt.current=!1;const _e=Q&&!k.current.isPerformanceMode&&!k.current.disableAnimations,Ze=T.coordinate(()=>{var nt;le?le(_e):ve&&((nt=be.current)==null||nt.call(be,Y))});O(new Map([...Y].map(([nt,st])=>[nt,{...st}])),_e,Ze,pe,Fe)},he=(Y,Q=50,pe=k.current.animateViewport,le=1,Fe=!1,ve)=>{const _e=Ze=>{const nt=M.current,st=Y??new Set(nt.nodes.map(bt=>bt.id)),rr=new Set(nt.nodes.map(bt=>bt.parent).filter(Boolean));if(!Ze&&(!Y||[...Y].some(bt=>rr.has(bt))))return;const hr=Ze&&Ad(nt.nodes,Ze,Z.current,bt=>k.current.containerStyle(bt).padding,Ie),vn=new Map([...st].flatMap(bt=>{const or=hr==null?void 0:hr.get(bt);if(or)return[[bt,or]];const Ut=Ze==null?void 0:Ze.get(bt),vr=Z.current.get(bt)||ao,Pu=Ut?{...Ut,...vr}:ze(bt);return Pu?[[bt,ir(Pu)]]:[]}));let nr=ei([...vn.values()]);if(!nr)return;const xr=ve?vn.get(ve):void 0;if(xr){const bt=(xr.x1+xr.x2)/2,or=(xr.y1+xr.y2)/2,Ut=Math.max(bt-nr.x1,nr.x2-bt),vr=Math.max(or-nr.y1,nr.y2-or);nr={x1:bt-Ut,x2:bt+Ut,y1:or-vr,y2:or+vr}}Ae.current=!1,Ht.current=[],Lt.current=!1,T.fit(nr,Number.isFinite(Q)?Math.max(0,Q):50,pe,le)};be.current=Fe?_e:null,Fe||_e(ie.current)},Ee=(Y,Q,pe,le)=>{var ve;if(!ze(Y))return;const Fe=Q==="connections"?Se(Y):B(Y);if(Q==="connections"&&qt.current===1.25&&((ve=ft.current)==null?void 0:ve.size)===Fe.size&&[...Fe].every(_e=>ft.current.has(_e))){S({id:Y,mode:Q});return}dr.current||(dr.current={pan:{...T.pan},zoom:T.zoom}),ft.current=Fe,k.current.compactPropertyLayout&&(Ae.current=!1,Le.current=()=>he(ft.current??Fe,pe,le)),S({id:Y,mode:Q}),k.current.compactPropertyLayout||he(Fe,pe,le)},Ce=Y=>{Le.current?Le.current=Y:Y()},Se=Y=>rf(Y,k.current.nodes,k.current.edges),Qe=(Y=>{var Q,pe,le;if(Y===void 0)return T.zoom;Y<T.zoom&&((Q=rt.current)!=null&&Q.options.fill)&&!k.current.readOnly&&((le=(pe=k.current).onNodeGridZoomOut)==null?void 0:le.call(pe,rt.current.options))===!0||(be.current=null,T.set(void 0,Y))}),qe=((Y,Q=!1)=>{if(Y===void 0)return T.pan;be.current=null,Q?T.transition({pan:Y,zoom:T.zoom},!0):T.set(Y)}),Be=(Y,Q)=>{var le;const pe=(le=_.current)==null?void 0:le.getBoundingClientRect();return{x:Y-((pe==null?void 0:pe.left)??0),y:Q-((pe==null?void 0:pe.top)??0)}},ke=(Y=0,Q=k.current.animateViewport,pe=!1)=>{if(pe){he(void 0,Y,Q,1,!0);return}be.current=null,Ce(()=>{const le=Rt();le&&T.fit(le,Y,Q)})};return{zoom:Qe,pan:qe,setEdgesVisible:Je,focusNode:(Y,Q,pe,le)=>Ce(()=>he(new Set([Y]),Q,pe,.6,le)),focusBranch:(Y,Q,pe,le,Fe=!1,ve=1)=>Ce(()=>he(B(Y),Q,pe,ve,le,Fe?Y:void 0)),focusConnections:(Y,Q,pe,le)=>Ce(()=>he(Se(Y),Q,pe,1,le)),isolateConnections:(Y,Q,pe)=>Ee(Y,"connections",Q,pe),isolateBranch:(Y,Q,pe)=>Ee(Y,"branch",Q,pe),restoreView:(Y=k.current.animateViewport,Q,pe=!1)=>{be.current=null;const le=pe&&!rt.current&&!ft.current,Fe=k.current.compactPropertyLayout&&!!ft.current;ft.current=null,S(null);const ve=Q??dr.current;dr.current=null,ve&&le?(Ae.current=!1,Le.current=null,Pe.current=null,be.current=()=>T.transition(ve,Y),ye()):Fe?Le.current=()=>{ve&&T.transition(ve,Y)}:ve&&Ce(()=>T.transition(ve,Y))},zoomAt:(Y,Q)=>{var pe,le,Fe;Y<T.zoom&&((pe=rt.current)!=null&&pe.options.fill)&&!k.current.readOnly&&((Fe=(le=k.current).onNodeGridZoomOut)==null?void 0:Fe.call(le,rt.current.options))===!0||(be.current=null,T.zoomAt(Y,Q))},fit:ke,centerAndFit:ke,center:(Y=k.current.animateViewport)=>{be.current=null;const Q=Rt();Q&&T.center(Q,Y)},clientToModel:(Y,Q)=>T.renderedToModel(Be(Y,Q)),modelToClient:Y=>{var le;const Q=(le=_.current)==null?void 0:le.getBoundingClientRect(),pe=T.modelToRendered(Y);return{x:pe.x+((Q==null?void 0:Q.left)??0),y:pe.y+((Q==null?void 0:Q.top)??0)}},getNodeBox:Y=>ze(Y),detectNodeCollisions:Y=>{const Q=L();return av({...Q,sizes:new Map([...Q.sizes,...fe.current]),fixedSizes:fe.current},Y)},resolveNodeCollisions:(Y={})=>{const Q=Uj(L(),Y);return Q.movedNodeIds.length&&J(Q.positions,Y.animate),Q},arrangeNodesInGrid:(Y={})=>{const Q=L(),pe=rt.current;if(pe){Q.positions=new Map(Q.positions);for(const st of Q.nodes)Q.positions.has(st.id)||Q.positions.set(st.id,T.renderedToModel({x:T.size.w/2,y:T.size.h/2}));const _e=new Set(Q.nodes.map(st=>st.id));pe.order=pe.order.filter(st=>_e.has(st));const Ze=new Set(pe.order);pe.order.push(...Q.nodes.filter(st=>!Ze.has(st.id)).map(st=>st.id));const nt=new Map(pe.order.map((st,rr)=>[st,rr]));Q.nodes=[...Q.nodes].sort((st,rr)=>nt.get(st.id)-nt.get(rr.id))}const le=bd(Q,A(Y)),Fe=le.sizes?JSON.stringify([[...le.positions],[...le.sizes]]):void 0;if(Fe&&Fe===ge.current&&Y.animate!==!1&&!be.current)return le;Tr(le.dividers??[]),pe&&(pe.ready=!1);const ve=()=>{pe&&(pe.ready=!0),pe&&Q.nodes.length&&!ae.current&&(ae.current=!0,k.current.fitOnInit!==!1&&!Y.fill?pt.centerAndFit(50,!1):k.current.fitOnInit===!1&&T.transition(p,!1)),$e(_e=>_e+1)};return!le.sizes&&fe.current.size&&U(),Q.nodes.some(_e=>!ie.current.has(_e.id))||le.movedNodeIds.length||le.bounds||be.current?J(le.positions,Y.animate,ve,le.bounds&&(!pe||!fe.current.size)?_e=>T.transition({zoom:1,pan:{x:0,y:0}},_e):void 0,le.sizes,!!pe&&!le.bounds):ve(),ge.current=Fe,le},setNodeGridMode:(Y,Q={})=>{var pe,le,Fe,ve;if(Q.order&&(!Array.isArray(Q.order)||Q.order.some(_e=>typeof _e!="string")||new Set(Q.order).size!==Q.order.length))throw new Error("Invalid grid node order.");if(Y){bd(L(),A(Q));const _e=!rt.current||rt.current.options.fill&&!Q.fill;be.current=null,rt.current||(rt.current={options:Q,order:L().nodes.map(Ze=>Ze.id),previousPositions:new Map([...ie.current].map(([Ze,nt])=>[Ze,{...nt}])),previousViewport:{zoom:T.zoom,pan:{...T.pan}},previousSize:{...T.size},ready:!1}),_e&&pt.centerAndFit(80,Q.animate,!0),Q.order&&(rt.current.order=[...Q.order]),rt.current.options={...Q},At(!0),pt.arrangeNodesInGrid(Q),(le=(pe=k.current).onNodeGridModeChange)==null||le.call(pe,{...Q,order:[...rt.current.order]})}else{const _e=rt.current;if(!_e)return;if(T.size.w===_e.previousSize.w&&T.size.h===_e.previousSize.h&&ie.current.size===_e.previousPositions.size&&[...ie.current.keys()].every(st=>_e.previousPositions.has(st))?be.current=()=>T.transition(_e.previousViewport,Q.animate!==!1&&!k.current.disableAnimations&&!k.current.isPerformanceMode):pt.centerAndFit(80,Q.animate,!0),rt.current=null,At(!1),U(),(ve=(Fe=k.current).onNodeGridModeChange)==null||ve.call(Fe,null),Qt(null),!_e.previousPositions.size){ye();return}const nt=new Map([...ie.current].map(([st,rr])=>[st,_e.previousPositions.get(st)??rr]));J(nt,Q.animate,void 0,void 0,void 0,!0)}},swapGridNodes:(Y,Q,pe)=>{var vn,nr,xr,bt,or;const le=rt.current;if(!le||!le.ready||k.current.readOnly||Y===Q)return!1;const Fe=L(),ve=Fe.nodes.find(Ut=>Ut.id===Y),_e=Fe.nodes.find(Ut=>Ut.id===Q);if(!ve||!_e||ve.parent!==_e.parent)return!1;const Ze=bd(Fe,A(le.options));if(Ze.skippedNodeIds.includes(Y)||Ze.skippedNodeIds.includes(Q))return!1;const nt=le.order.indexOf(Y),st=le.order.indexOf(Q);if(nt<0||st<0)return!1;[le.order[nt],le.order[st]]=[le.order[st],le.order[nt]],be.current=null,le.options={...le.options,order:[...le.order]};const rr=ve.parent??"canvas",hr=(nr=(vn=le.options.adjustment)==null?void 0:vn.sections)==null?void 0:nr[rr];return hr!=null&&hr.members&&(le.options={...le.options,adjustment:{...le.options.adjustment,sections:{...(xr=le.options.adjustment)==null?void 0:xr.sections,[rr]:{...hr,members:hr.members.map(Ut=>Ut.map(vr=>vr===Y?Q:vr===Q?Y:vr))}}}}),pt.arrangeNodesInGrid({...le.options,animate:pe??le.options.animate}),(or=(bt=k.current).onNodeGridModeChange)==null||or.call(bt,{...le.options}),!0},setNodePosition:(Y,Q,pe)=>{var Fe,ve,_e,Ze;if(!ie.current.has(Y)||Q&&(!Number.isFinite(Q.x)||!Number.isFinite(Q.y)))return!1;if(ur(),!Q)return re.current.delete(Y),(ve=(Fe=k.current).onFixedNodePositionsChange)==null||ve.call(Fe,Object.fromEntries(re.current)),ye(),!0;const le=new Map(ie.current);return le.set(Y,{...Q}),(pe==null?void 0:pe.persist)===!1?re.current.delete(Y):re.current.set(Y,{...Q}),ie.current=le,X(le),(pe==null?void 0:pe.persist)!==!1&&((Ze=(_e=k.current).onFixedNodePositionsChange)==null||Ze.call(_e,Object.fromEntries(re.current))),(pe==null?void 0:pe.persist)===!1&&ye(),!0},getFixedNodePositions:()=>Object.fromEntries([...re.current].map(([Y,Q])=>[Y,{...Q}])),onViewportChange:Y=>T.onChange(Y)}},[]);j.useEffect(()=>{var A,L;return(L=(A=k.current).onInit)==null||L.call(A,pt),()=>T.cancelAnimation()},[pt]),j.useEffect(()=>{var A,L;if(we>0){const B=Le.current;Le.current=null,B==null||B(),(L=(A=k.current).onLayoutComplete)==null||L.call(A,pt)}},[pt,we]);const gt=j.useRef(null),vt=j.useRef(new Map),er=j.useRef(!1),[tr,Ft]=j.useState(null),[it,br]=j.useState(null),Ir=A=>{const L=_.current.getBoundingClientRect();return{x:(A.clientX-L.left)*(_.current.clientWidth/L.width||1),y:(A.clientY-L.top)*(_.current.clientHeight/L.height||1)}},fr=(A,L)=>{const B=k.current.nodes;for(let J=B.length-1;J>=0;J--){const he=B[J].id;if(!ar(he,k.current.edges,k.current.edgeMode)||ft.current&&!ft.current.has(he)||he===L||et.current.has(he))continue;const Ee=ze(he);if(Ee&&Xu(A,ir(Ee)))return he}for(const[J,he]of et.current)if(ar(J,k.current.edges,k.current.edgeMode)&&!(ft.current&&!ft.current.has(J))&&J!==L&&Xu(A,he))return J;return null},mn=(A,L)=>{const B=k.current.nodes.find(Se=>Se.id===A),J=ze(A);if(!B||!J)return null;const he=ir({...J,x:J.x+L.x,y:J.y+L.y});let Ee=null,Ce=0;for(const Se of k.current.nodes){if(Se.id===A||Se.parent!==B.parent||re.current.has(Se.id)||et.current.has(Se.id)||!ar(Se.id,k.current.edges,k.current.edgeMode)||ft.current&&!ft.current.has(Se.id))continue;const Qe=ze(Se.id);if(!Qe)continue;const qe=ir(Qe),Be=Math.max(0,Math.min(he.x2,qe.x2)-Math.max(he.x1,qe.x1))*Math.max(0,Math.min(he.y2,qe.y2)-Math.max(he.y1,qe.y1));Be>Ce&&(Ce=Be,Ee=Se.id)}return Ee},bn=(A,L)=>{const B=rt.current;if(!(B!=null&&B.ready)||k.current.readOnly)return;const J=k.current.nodes.filter(Be=>ar(Be.id,k.current.edges,k.current.edgeMode)&&(!ft.current||ft.current.has(Be.id))),he=J.find(Be=>Be.id===A);if(!he)return;const Ee=_.current,Ce=T.zoom*(Ee&&Ee.clientWidth?Ee.getBoundingClientRect().width/Ee.clientWidth:1),Se=24/Ce;let Qe;for(const Be of J){if(Be.id===A||Be.parent!==he.parent)continue;const ke=ze(Be.id);if(!ke)continue;const Y=ir(ke),Q=Math.min(ke.w/4,Se),pe=Math.min(ke.h/4,Se),le=3/Ce,Fe=[];if(L.y>Y.y1+pe&&L.y<Y.y2-pe)for(const ve of["before","after"]){const _e=ve==="before"?Y.x1:Y.x2,Ze=Math.abs(L.x-_e),nt=ve==="before"?L.x<_e:L.x>_e;Ze<=(nt?Se:Q)&&Fe.push({side:ve,distance:Ze,marker:{x1:_e-le/2,x2:_e+le/2,y1:Y.y1,y2:Y.y2}})}if(L.x>=Y.x1&&L.x<=Y.x2)for(const ve of["above","below"]){const _e=ve==="above"?Y.y1:Y.y2,Ze=Math.abs(L.y-_e),nt=ve==="above"?L.y<_e:L.y>_e;Ze<=(nt?Se:pe)&&Fe.push({side:ve,distance:Ze,marker:{x1:Y.x1,x2:Y.x2,y1:_e-le/2,y2:_e+le/2}})}for(const ve of Fe)(!Qe||ve.distance<Qe.distance)&&(Qe={id:Be.id,...ve})}if(!Qe)return;const qe=Gj({nodes:J,positions:ie.current,sizes:new Map([...Z.current,...fe.current]),fixedSizes:fe.current,padding:Be=>k.current.containerStyle(Be).padding,minSize:Ie,fixedIds:new Set(re.current.keys())},B.options,A,Qe.id,Qe.side);return qe?{options:qe,marker:Qe.marker}:void 0},Zr=(A,L)=>{if(k.current.edgeMode==="nodes"||k.current.edgeMode==="workflow")return null;const B=k.current.direction==="RL",J=Math.max(16,6/T.zoom);let he=null;for(const Ee of[...k.current.nodes].reverse()){if(!ar(Ee.id,k.current.edges,k.current.edgeMode)||ft.current&&!ft.current.has(Ee.id))continue;const Ce=ze(Ee.id),Se=G.current.get(Ee.id);if(!Ce||!Se||et.current.has(Ee.id))continue;const Qe=Ce.x+(L==="source"!==B?1:-1)*Ce.w/2;for(const qe of Se){if(qe.role&&qe.role!==L)continue;const Be=Ce.y-Ce.h/2+qe.top,ke=Math.hypot(A.x-(qe.anchor?Ce.x-Ce.w/2+qe.anchor.x:Qe),A.y-Be-qe.height/2);if(!qe.anchor&&A.x>=Ce.x-Ce.w/2&&A.x<=Ce.x+Ce.w/2&&A.y>=Be&&A.y<=Be+qe.height)return{nodeId:Ee.id,property:qe.property};ke<=J&&(!he||ke<he.distance)&&(he={nodeId:Ee.id,property:qe.property,distance:ke})}}return he},mv=A=>{var Se,Qe;if(!A.currentTarget.contains(A.target)||(gt.current||(er.current=!1),A.target.closest(".flow-sdk-canvas")!==A.currentTarget)||A.button!==0)return;const L=A.target;if(L.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const B=k.current,J=Ir(A);if(A.pointerType==="touch"){vt.current.set(A.pointerId,J);const qe=Rm(vt.current);if(qe){Qt(null),gt.current={kind:"pinch",distance:qe.distance,zoom:T.zoom,anchor:T.renderedToModel(qe.center)},br(null),Ft(null),er.current=!0;for(const Be of vt.current.keys())A.currentTarget.setPointerCapture(Be);return}}if(gt.current)return;if(k.current.readOnly){B.dragMode&&(gt.current={kind:"pan",pointerId:A.pointerId,start:J,pan0:T.pan,moved:!1},A.currentTarget.setPointerCapture(A.pointerId));return}const he=!rt.current||!!B.nodeGridConnections,Ee=B.drawHandles&&L.closest(".flow-sdk-handle"),Ce=B.drawHandles&&L.closest(".flow-sdk-property-port");if((!he||!Ee&&!Ce&&(!B.drawMode||A.shiftKey))&&(rt.current||A.shiftKey&&(B.onNodeGridDrop||B.onNodeParentChange))){if(rt.current&&!rt.current.ready||L.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]"))return;const qe=(Se=L.closest("[data-node-id]"))==null?void 0:Se.dataset.nodeId;if(qe&&!re.current.has(qe)){L.setPointerCapture(A.pointerId),gt.current={kind:"grid",pointerId:A.pointerId,captureTarget:L,source:qe,start:J,moved:!1};return}if(qe)return}if(he&&(B.drawMode||Ee||Ce)){const qe=T.renderedToModel(J),Be=B.drawMode?Zr(qe,"source"):null,ke=Ce||Ee,Y=ke?(Qe=ke.closest("[data-node-id]"))==null?void 0:Qe.dataset.nodeId:(Be==null?void 0:Be.nodeId)??fr(qe),Q=Ce?Ce.dataset.property:Be==null?void 0:Be.property;if(Y){gt.current={kind:"draw",pointerId:A.pointerId,source:Y,sourceProperty:Q,reverse:(Ce==null?void 0:Ce.dataset.portRole)==="target",startClient:{x:A.clientX,y:A.clientY}},er.current=!0,br({source:Y,sourceProperty:Q,point:qe,target:null}),A.currentTarget.setPointerCapture(A.pointerId);return}}L.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(be.current=null,B.multiSelect?gt.current={kind:"box",pointerId:A.pointerId,start:J,current:J}:B.dragMode?gt.current={kind:"pan",pointerId:A.pointerId,start:J,pan0:T.pan,moved:!1}:gt.current={kind:"tap",pointerId:A.pointerId,start:J,moved:!1},A.currentTarget.setPointerCapture(A.pointerId))},bv=A=>{var J,he,Ee;const L=gt.current;if(!L)return;const B=Ir(A);if(vt.current.has(A.pointerId)&&vt.current.set(A.pointerId,B),L.kind==="pinch"){const Ce=Rm(vt.current);if(!Ce)return;const Se=Math.max(T.minZoom,Math.min(T.maxZoom,L.zoom*Ce.distance/L.distance));if(Se<T.zoom&&((J=rt.current)!=null&&J.options.fill)&&((Ee=(he=k.current).onNodeGridZoomOut)==null?void 0:Ee.call(he,rt.current.options))===!0)return;T.set({x:Ce.center.x-L.anchor.x*Se,y:Ce.center.y-L.anchor.y*Se},Se);return}if(L.pointerId===A.pointerId)switch(L.kind){case"grid":{const Ce={x:B.x-L.start.x,y:B.y-L.start.y};if(!L.moved&&Math.hypot(Ce.x,Ce.y)<=vd)return;L.moved||(ur(),be.current=null,T.cancelAnimation()),L.moved=!0,er.current=!0,A.preventDefault();const Se={x:Ce.x/T.zoom,y:Ce.y/T.zoom},Qe=!A.shiftKey&&B.x>=0&&B.y>=0&&B.x<=T.size.w&&B.y<=T.size.h?bn(L.source,T.renderedToModel(B)):void 0;Qt({source:L.source,offset:Se,target:A.shiftKey||Qe?null:mn(L.source,Se),shiftKey:A.shiftKey,insertion:Qe});break}case"pan":{const Ce=B.x-L.start.x,Se=B.y-L.start.y;if(!L.moved&&Math.hypot(Ce,Se)<=vd)return;L.moved=!0,er.current=!0,T.set({x:L.pan0.x+Ce,y:L.pan0.y+Se});break}case"tap":{Math.hypot(B.x-L.start.x,B.y-L.start.y)>vd&&(L.moved=!0);break}case"box":{er.current=!0,L.current=B,Ft({x1:Math.min(L.start.x,B.x),y1:Math.min(L.start.y,B.y),x2:Math.max(L.start.x,B.x),y2:Math.max(L.start.y,B.y)});break}case"draw":{const Ce=T.renderedToModel(B),Se=Zr(Ce,L.reverse?"source":"target");br(L.reverse&&Se?{source:Se.nodeId,sourceProperty:Se.property,point:Ce,target:L.source,targetProperty:L.sourceProperty}:{source:L.source,sourceProperty:L.sourceProperty,point:Ce,target:(Se==null?void 0:Se.nodeId)??fr(Ce,L.source),targetProperty:Se==null?void 0:Se.property});break}}},vu=(A,L)=>{var he,Ee,Ce,Se,Qe,qe,Be,ke,Y,Q,pe;vt.current.delete(A.pointerId);const B=gt.current;if(!B)return;if(B.kind==="pinch"){const le=[...vt.current][0];gt.current=le&&k.current.dragMode&&!L?{kind:"pan",pointerId:le[0],start:le[1],pan0:T.pan,moved:!0}:null;return}if(B.pointerId!==A.pointerId)return;gt.current=null;try{(B.kind==="grid"?B.captureTarget:A.currentTarget).releasePointerCapture(A.pointerId)}catch{}const J=k.current;switch(L=L||!!J.readOnly,B.kind){case"grid":{if(Qt(null),L||!B.moved)break;const le=Ir(A);if(!A.shiftKey&&le.x>=0&&le.y>=0&&le.x<=T.size.w&&le.y<=T.size.h){const ve=bn(B.source,T.renderedToModel(le));if(ve){pt.setNodeGridMode(!0,{...ve.options,animate:!1});break}}if(((he=J.onNodeGridDrop)==null?void 0:he.call(J,B.source,{x:A.clientX,y:A.clientY},{shiftKey:A.shiftKey,ctrlKey:A.ctrlKey,metaKey:A.metaKey,altKey:A.altKey}))===!0||le.x<0||le.y<0||le.x>T.size.w||le.y>T.size.h)break;if(A.shiftKey){const ve=new Map(J.nodes.map(nt=>[nt.id,nt]));let _e=fr(T.renderedToModel(le),B.source);const Ze=new Set;for(;_e&&!((Ee=ve.get(_e))!=null&&Ee.acceptsChildren)&&!Ze.has(_e);)Ze.add(_e),_e=((Ce=ve.get(_e))==null?void 0:Ce.parent)??null;if(_e&&((Se=ve.get(_e))!=null&&Se.acceptsChildren)){let nt=_e;const st=new Set;for(;nt&&!st.has(nt);)st.add(nt),nt=(Qe=ve.get(nt))==null?void 0:Qe.parent;st.has(B.source)||(qe=J.onNodeParentChange)==null||qe.call(J,B.source,_e)}break}if(!rt.current)break;const Fe=mn(B.source,{x:(le.x-B.start.x)/T.zoom,y:(le.y-B.start.y)/T.zoom});Fe&&pt.swapGridNodes(B.source,Fe,!1);break}case"pan":case"tap":!L&&!B.moved&&((Be=J.onBackgroundTap)==null||Be.call(J));break;case"box":{if(Ft(null),L)break;const le=T.renderedToModel(B.start),Fe=T.renderedToModel(B.current),ve={x1:Math.min(le.x,Fe.x),y1:Math.min(le.y,Fe.y),x2:Math.max(le.x,Fe.x),y2:Math.max(le.y,Fe.y)};if(ve.x2-ve.x1<1&&ve.y2-ve.y1<1){(ke=J.onBackgroundTap)==null||ke.call(J);break}const _e=[];for(const Ze of J.nodes){const nt=ze(Ze.id);nt&&s1(ir(nt),ve)&&_e.push(Ze.id)}_e.length&&((Y=J.onBoxSelect)==null||Y.call(J,_e));break}case"draw":{if(br(null),L)break;const le=Ir(A),Fe=T.renderedToModel(le),ve=Zr(Fe,B.reverse?"source":"target"),_e=(ve==null?void 0:ve.nodeId)??fr(Fe);if(_e===B.source&&(B.sourceProperty===void 0||(ve==null?void 0:ve.property)===void 0||ve.property===B.sourceProperty))break;_e?(Q=J.onEdgeDraw)==null||Q.call(J,B.reverse?_e:B.source,B.reverse?B.source:_e,B.sourceProperty!==void 0||(ve==null?void 0:ve.property)!==void 0?{sourceProperty:B.reverse?ve==null?void 0:ve.property:B.sourceProperty,targetProperty:B.reverse?B.sourceProperty:ve==null?void 0:ve.property}:void 0):Math.max(Math.abs(A.clientX-B.startClient.x),Math.abs(A.clientY-B.startClient.y))>tE&&((pe=J.onDrawIntoSpace)==null||pe.call(J,B.source,Fe,B.sourceProperty,B.reverse));break}}},Nr=j.useCallback(()=>{var B;const A=gt.current,L=[...vt.current.keys()];A&&A.kind!=="pinch"&&L.push(A.pointerId),gt.current=null,vt.current.clear(),Qt(null),br(null),Ft(null);for(const J of L)(A==null?void 0:A.kind)==="grid"&&A.captureTarget.hasPointerCapture(J)&&A.captureTarget.releasePointerCapture(J),(B=_.current)!=null&&B.hasPointerCapture(J)&&_.current.releasePointerCapture(J)},[]);j.useEffect(()=>{const A=L=>{L.key==="Escape"&&Nr()};return window.addEventListener("keydown",A),window.addEventListener("blur",Nr),()=>{window.removeEventListener("keydown",A),window.removeEventListener("blur",Nr),gt.current=null,vt.current.clear()}},[Nr]),j.useEffect(()=>{Nr()},[y,b,x,i,n,e.drawHandles,e.readOnly,mt,Nr]);const xv=j.useMemo(()=>{const A=new Map,L=new Map;for(const B of P){if(B.source!==B.target)continue;const J=A.get(B.source)??0;A.set(B.source,J+1),L.set(B.id,J)}return L},[P]),Ko=eE[n],[Or,vv]=j.useState(null),Jo=Yj(r,P,!!((Eu=e.edgeReveal)!=null&&Eu.revealNodes));j.useLayoutEffect(()=>{_.current&&Or&&Am(_.current,Or)}),j.useEffect(()=>{const A=_.current;if(!A||!Or)return;const L=A.ownerDocument.fonts,B=()=>Am(A,Or);return L==null||L.addEventListener("loadingdone",B),()=>L==null?void 0:L.removeEventListener("loadingdone",B)},[Or]);const Zo=i1(P,St,Ko),wv=e.onEdgeSelect,Cv=e.onContainerSelect,wu=it?it.target&&St(it.target,it.targetProperty)||{x:it.point.x,y:it.point.y,w:1,h:1}:null,Cu=it?St(it.source,it.sourceProperty):null,xn=!mt||!!e.nodeGridConnections,Sv=["flow-sdk-canvas",y&&xn?"flow-sdk-draw":"",w?"flow-sdk-perf":""].filter(Boolean).join(" ");return f.jsxs("div",{ref:_,className:Sv,"data-edge-mode":i,"data-node-grid":mt||void 0,"data-grid-connections":e.nodeGridConnections||void 0,onPointerDownCapture:mv,onPointerMove:bv,onPointerUp:A=>vu(A,!1),onPointerCancel:A=>vu(A,!0),onLostPointerCapture:A=>{const L=gt.current;L&&(L.kind==="pinch"||L.pointerId===A.pointerId)&&Nr()},onClickCapture:A=>{if(!A.currentTarget.contains(A.target))return;const L=A.target instanceof Element&&A.target.closest("button[data-flow-fullscreen], button[data-flow-content-navigation]");(er.current||e.readOnly&&!L)&&(A.preventDefault(),A.stopPropagation())},children:[f.jsx("svg",{className:"flow-sdk-svg",children:f.jsxs("g",{ref:N,children:[f.jsx("g",{className:"flow-sdk-containers",children:[...Ye].filter(([A])=>ar(A,t,i)).filter(([A])=>!E||E.has(A)).map(([A,L])=>{var B,J;return f.jsx(b1,{id:A,rect:L,label:Me.get(A),labelLayer:Or,labelContent:(B=r.find(he=>he.id===A&&he.label!==void 0))==null?void 0:B.element,style:m(A),onSelect:Cv,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(J=e.selectedNodeIds)==null?void 0:J.includes(A)},A)})}),f.jsx("g",{className:"flow-sdk-edges",children:lt&&xn&&P.map(A=>{var J,he,Ee;if(!Jo.ready.has(A.id)||E&&(!E.has(A.source)||!E.has(A.target)))return null;const L=St(A.source,A.sourceProperty),B=St(A.target,A.targetProperty);return!L||!B?null:f.jsx(of,{id:A.id,edgeData:A.data,validationIssue:A.validationIssue,edgeType:A.type,edgeRadius:e.edgeRadius,propertyMode:R,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:Jo.complete,source:L,target:B,sourceProperty:A.sourceProperty,targetProperty:A.targetProperty,sourceY:ht(A.source,A.sourceProperty),targetY:ht(A.target,A.targetProperty),sourcePort:wt(A.source,A.sourceProperty),targetPort:wt(A.target,A.targetProperty),dir:Ko,turn:((J=Zo.get(A.id))==null?void 0:J.turn)??A.turn,labelAtTarget:(he=Zo.get(A.id))==null?void 0:he.labelAtTarget,labelFraction:(Ee=Zo.get(A.id))==null?void 0:Ee.labelFraction,color:A.color,connectorColor:A.connectorColor,labelBg:A.labelBg,label:A.label,labelLayer:Or,dashed:A.dashed,animated:A.animated&&!w,inverted:A.inverted,loopIndex:xv.get(A.id)??0,onSelect:wv},A.id)})}),lt&&xn&&it&&Pd(it,i)&&Cu&&wu&&f.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:f.jsx(of,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:it.source,target:it.target??"",sourceProperty:it.sourceProperty,targetProperty:it.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:R,customEdgeTypes:e.customEdgeTypes,source:Cu,target:wu,sourceProperty:it.sourceProperty,targetProperty:it.targetProperty,sourceY:ht(it.source,it.sourceProperty),sourcePort:wt(it.source,it.sourceProperty),targetPort:it.target?wt(it.target,it.targetProperty):void 0,targetY:it.target?ht(it.target,it.targetProperty):void 0,dir:Ko,turn:.5,color:g,labelBg:g})})]})}),f.jsxs("div",{ref:D,className:"flow-sdk-nodes",children:[(We==null?void 0:We.insertion)&&f.jsx("div",{className:"flow-sdk-box","data-grid-insertion":"",style:{left:We.insertion.marker.x1,top:We.insertion.marker.y1,width:We.insertion.marker.x2-We.insertion.marker.x1,height:We.insertion.marker.y2-We.insertion.marker.y1,background:g,border:0}}),mt&&((_u=rt.current)==null?void 0:_u.options.fill)&&((ku=rt.current.options.adjustment)==null?void 0:ku.enabled)&&!e.readOnly&&f.jsx(Kj,{dividers:Jr,options:rt.current.options,zoom:T.zoom,onChange:A=>pt.setNodeGridMode(!0,{...A,animate:!1})}),r.map(A=>{var Fe,ve,_e;if((Fe=rt.current)!=null&&Fe.options.fill&&!ae.current)return null;const L=te.get(A.id),B=Ye.get(A.id);if(B&&A.label!==void 0)return null;const J=(L==null?void 0:L.x)??(B?(B.x1+B.x2)/2:0),he=(L==null?void 0:L.y)??(B?(B.y1+B.y2)/2:0),Ee=We!=null&&We.target?A.id===We.source?We.target:A.id===We.target?We.source:void 0:void 0,Ce=Ee?te.get(Ee):void 0,Se=We?te.get(We.source):void 0,Qe=We!=null&&We.target?te.get(We.target):void 0,qe=Se&&Qe?{x:Qe.x-Se.x,y:Qe.y-Se.y}:void 0,Be=qe?qe.x**2+qe.y**2:0,ke=Be&&We&&qe?Math.max(0,Math.min(1,(We.offset.x*qe.x+We.offset.y*qe.y)/Be)):0,Y=Ce?{x:J+(Ce.x-J)*ke,y:he+(Ce.y-he)*ke}:(We==null?void 0:We.source)===A.id?{x:J+We.offset.x,y:he+We.offset.y}:void 0,Q=me.get(A.id),pe=Ee?me.get(Ee):void 0,le=Q&&pe?{w:Q.w+(pe.w-Q.w)*ke,h:Q.h+(pe.h-Q.h)*ke}:Q;return f.jsx(Xj,{id:A.id,x:J,y:he,gridDraggable:mt&&!e.readOnly&&!re.current.has(A.id),gridDragging:(We==null?void 0:We.source)===A.id,gridDropTarget:(We==null?void 0:We.target)===A.id,gridSize:me.get(A.id),gridPreview:Y?{...Y,size:le,floating:We==null?void 0:We.shiftKey}:void 0,placed:!!L||!!B,hidden:!mt&&!Jo.shown.has(A.id)||!ar(A.id,t,i)||!!E&&!E.has(A.id),onMount:je,drawHandles:e.drawHandles&&!e.readOnly&&xn,drawMode:y&&xn,connectedPorts:new Set(P.flatMap(Ze=>[...Ze.source===A.id&&Ze.sourceProperty!==void 0?[`source:${Ze.sourceProperty}`]:[],...Ze.target===A.id&&Ze.targetProperty!==void 0?[`target:${Ze.targetProperty}`]:[]])),hasCollapseControl:A.hasCollapseControl,handleColor:g,animated:A.animated&&!B&&!w&&!mt,animationColor:A.animationColor,animationWidth:A.animationWidth,animationVariant:A.animationVariant,width:(ve=Z.current.get(A.id))==null?void 0:ve.w,height:(_e=Z.current.get(A.id))==null?void 0:_e.h,propertyMode:R,resolvedRows:ct.get(A.id),reversePorts:n==="RL",direction:n,onPropertyRows:ce,onSurface:q,children:Q?A.fillElement??A.element:A.element},A.id)})]}),tr&&f.jsx("div",{className:"flow-sdk-box",style:{left:tr.x1,top:tr.y1,width:tr.x2-tr.x1,height:tr.y2-tr.y1}}),f.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:f.jsx("g",{ref:$,transform:`translate(${T.pan.x} ${T.pan.y}) scale(${T.zoom})`,children:f.jsx("g",{ref:vv,className:"flow-sdk-labels",style:{pointerEvents:y?"none":"visiblePainted",outline:"none"}})})})]})}const iE=j.memo(oE);function gu(e=!0){const r=j.useRef(null);return j.useEffect(()=>{if(!e||!r.current)return;const t=i=>{i.stopPropagation()},n=r.current,o=["mousedown","mouseup","click","dblclick","pointerdown","pointerup","wheel"];return o.forEach(i=>n.addEventListener(i,t)),()=>{o.forEach(i=>n.removeEventListener(i,t))}},[e]),r}const cn=({nodeId:e,label:r,color:t,fontWeight:n="bold",fontSize:o="5xl",wrap:i=!1,isEditing:s,onEditStart:a,onEditEnd:c})=>{const{callbacks:l,config:d,readOnly:u}=He(),h=d.editable&&!u,[p,m]=j.useState(r),[g,y]=j.useState(),b=j.useRef(null),x=j.useRef(!1),w=gu(s);j.useEffect(()=>{if(s&&(x.current=!1,b.current)){b.current.focus();const C=b.current.value.length;b.current.setSelectionRange(C,C)}},[s]);const v=()=>{var S;if(x.current)return;x.current=!0;const C=p.trim();C&&C!==r&&((S=l.onNodeLabelChange)==null||S.call(l,e,C)),c()};return!h||!s?f.jsx(V.Text,{color:t,fontWeight:n,fontSize:o,minW:0,maxW:"100%",whiteSpace:i?"normal":"nowrap",overflowWrap:i?"anywhere":void 0,overflow:"hidden",textOverflow:"ellipsis",title:r,onDoubleClick:h?C=>{C.stopPropagation(),y({width:C.currentTarget.offsetWidth,height:C.currentTarget.offsetHeight}),m(r),a()}:void 0,cursor:h?"text":void 0,children:r}):f.jsxs("div",{ref:w,style:{position:"relative",width:"max-content",minWidth:g==null?void 0:g.width,maxWidth:900,height:g==null?void 0:g.height},children:[f.jsx(V.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),f.jsx(V.Input,{ref:b,value:p,onChange:C=>m(C.target.value),onBlur:v,onKeyDown:C=>{C.key==="Enter"&&v(),C.key==="Escape"&&(x.current=!0,c())},color:t,fontWeight:n,fontSize:o,bg:"transparent",borderWidth:0,_focus:{outline:"none",boxShadow:"none"},_focusVisible:{outline:"none",boxShadow:"none"},p:0,display:"block",position:"absolute",top:0,left:0,w:"100%",h:"100%",minW:0,minH:0,lineHeight:"normal"})]})};function cv({id:e,label:r,role:t,side:n,position:o=.5,placement:i,children:s,style:a}){return f.jsx("div",{"data-flow-property":e,"data-flow-port-role":t,"data-flow-port-side":n,"data-flow-port-position":n?o:void 0,"data-flow-port-placement":i,style:{minHeight:32,display:"flex",alignItems:"center",justifyContent:t==="source"?"flex-end":"flex-start",...a,...n?{display:"none"}:{}},children:s??r??e})}const aE=xo.default.dialog`
211
211
  ${e=>gr(e.$surface,e.$border)}
212
212
  &,
213
213
  &:hover {
@@ -277,8 +277,9 @@
277
277
  black calc(100% - 32px),
278
278
  transparent
279
279
  );
280
- `;function yu({nodeAddress:e,active:r,label:t,open:n=!1,onClose:o,children:i,filter:s,height:a,width:c}){const{background:l,border:d,colorText:u}=at(),{colorMode:h}=Ue(),p=j.useRef(null),m=j.useId(),{data:g,schema:y,bindings:b}=j.useContext($t),x=i!==void 0||!!(g&&y&&(b?Hn(b,e,y):un(g,e,y)));j.useEffect(()=>{var w,C,S,E,M;!r||!x||!n?(w=p.current)==null||w.close():(C=p.current)!=null&&C.open||((S=p.current)==null||S.showModal(),(M=(E=p.current)==null?void 0:E.querySelector("[data-form-filter] input"))==null||M.focus())},[r,x,n]);const v=Me(l);return x?f.jsx(f.Fragment,{children:typeof document<"u"&&Wr.createPortal(f.jsx(aE,{ref:p,id:m,$surface:v,$border:Me(d),"aria-label":`Configure ${t}`,onClose:o,onPointerDown:w=>w.stopPropagation(),onWheel:w=>w.stopPropagation(),onKeyDown:w=>w.stopPropagation(),onClick:w=>{var C;w.stopPropagation(),w.target===w.currentTarget&&((C=p.current)==null||C.close())},style:{position:"fixed",inset:"94px 20px auto auto",margin:0,padding:20,width:c??"var(--top-toolbar-width, 360px)",boxSizing:"border-box",maxWidth:"calc(100vw - 40px)",maxHeight:"calc(100dvh - 114px)",height:a,overflow:"hidden",borderRadius:30,background:v,color:Me(u),fontSize:16,textTransform:"none"},children:n&&f.jsxs(f.Fragment,{children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexShrink:0},children:[f.jsx("strong",{style:{overflowWrap:"anywhere",minWidth:0},children:t}),f.jsx(dn,{"aria-label":"Close node configuration",onClick:()=>{var w;return(w=p.current)==null?void 0:w.close()}})]}),s&&f.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:s}),f.jsx(sE,{$divider:`var(--chakra-colors-gray-${h==="dark"?"700":"200"})`,"data-form-scroll":"",style:a?{flex:1}:void 0,children:i??f.jsx(Vd,{nodeAddress:e})})]})}),document.body)}):null}const Rd=({icon:e,label:r,onClick:t,color:n,boxSize:o=6,...i})=>{const{background:s,border:a,colorText:c}=at();return f.jsx(Ge,{label:r,children:f.jsx(W.Flex,{asChild:!0,p:0,border:0,bg:"transparent",children:f.jsx("button",{type:"button","aria-label":r,onClick:t,children:f.jsx(W.Icon,{as:e,boxSize:o,color:n,cursor:t?"pointer":void 0})})})})},cE=`${Hb}
280
+ `;function yu({nodeAddress:e,active:r,label:t,open:n=!1,onClose:o,children:i,filter:s,height:a,width:c}){const{background:l,border:d,colorText:u}=at(),{colorMode:h}=He(),p=j.useRef(null),m=j.useId(),{data:g,schema:y,bindings:b}=j.useContext($t),x=i!==void 0||!!(g&&y&&(b?Hn(b,e,y):un(g,e,y)));j.useEffect(()=>{var v,C,S,E,R;!r||!x||!n?(v=p.current)==null||v.close():(C=p.current)!=null&&C.open||((S=p.current)==null||S.showModal(),(R=(E=p.current)==null?void 0:E.querySelector("[data-form-filter] input"))==null||R.focus())},[r,x,n]);const w=Te(l);return x?f.jsx(f.Fragment,{children:typeof document<"u"&&Wr.createPortal(f.jsx(aE,{ref:p,id:m,$surface:w,$border:Te(d),"aria-label":`Configure ${t}`,onClose:o,onPointerDown:v=>v.stopPropagation(),onWheel:v=>v.stopPropagation(),onKeyDown:v=>v.stopPropagation(),onClick:v=>{var C;v.stopPropagation(),v.target===v.currentTarget&&((C=p.current)==null||C.close())},style:{position:"fixed",inset:"94px 20px auto auto",margin:0,padding:20,width:c??"var(--top-toolbar-width, 360px)",boxSizing:"border-box",maxWidth:"calc(100vw - 40px)",maxHeight:"calc(100dvh - 114px)",height:a,overflow:"hidden",borderRadius:30,background:w,color:Te(u),fontSize:16,textTransform:"none"},children:n&&f.jsxs(f.Fragment,{children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexShrink:0},children:[f.jsx("strong",{style:{overflowWrap:"anywhere",minWidth:0},children:t}),f.jsx(dn,{"aria-label":"Close node configuration",onClick:()=>{var v;return(v=p.current)==null?void 0:v.close()}})]}),s&&f.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:s}),f.jsx(sE,{$divider:`var(--chakra-colors-gray-${h==="dark"?"700":"200"})`,"data-form-scroll":"",style:a?{flex:1}:void 0,children:i??f.jsx(Vd,{nodeAddress:e})})]})}),document.body)}):null}const Rd=({icon:e,label:r,onClick:t,color:n,boxSize:o=6,...i})=>{const{background:s,border:a,colorText:c}=at();return f.jsx(Ge,{label:r,children:f.jsx(V.Flex,{asChild:!0,p:0,border:0,bg:"transparent",children:f.jsx("button",{type:"button","aria-label":r,onClick:t,children:f.jsx(V.Icon,{as:e,boxSize:o,color:n,cursor:t?"pointer":void 0})})})})},cE=`${Ub}
281
281
  [data-flow-loading-border][data-flow-loading-border] .flow-sdk-node-border-animation{animation:flow-sdk-node-border 2.4s linear infinite!important}
282
282
  [data-flow-loading-border][data-flow-loading-border][data-motion-disabled] .flow-sdk-node-border-animation{animation:none!important}
283
- @media(prefers-reduced-motion:reduce){[data-flow-loading-border][data-flow-loading-border] .flow-sdk-node-border-animation{animation:none!important}}`;function cv({active:e=!0,label:r="Loading content",radius:t}){const{config:n,themeColor:o}=Ue(),{colorText:i}=at(),s=j.useRef(null),[a,c]=j.useState({width:0,height:0,radius:0});if(j.useLayoutEffect(()=>{const u=s.current;if(!e||!u)return;const h=()=>{const m=u.parentElement,g={width:u.clientWidth,height:u.clientHeight,radius:t??(m&&parseFloat(getComputedStyle(m).borderTopLeftRadius)||0)};c(y=>y.width===g.width&&y.height===g.height&&y.radius===g.radius?y:g)},p=new ResizeObserver(h);return p.observe(u),h(),()=>p.disconnect()},[e,t]),!e)return null;const l=Me(o||i),d={x:4,y:4,width:a.width-8,height:a.height-8,radius:Math.max(0,a.radius-4),color:l,strokeWidth:2};return f.jsxs("div",{ref:s,role:"status","aria-label":r,"data-flow-loading-border":"","data-motion-disabled":n.disableAnimations||void 0,style:{position:"absolute",inset:0,pointerEvents:"none",borderRadius:"inherit",overflow:"hidden",zIndex:2},children:[f.jsx("style",{children:cE}),f.jsxs("svg",{width:"100%",height:"100%","aria-hidden":"true",style:{display:"block",pointerEvents:"none"},children:[f.jsx("g",{opacity:.5,style:{filter:"blur(3px)"},children:f.jsx(go,{...d,strokeWidth:6})}),f.jsx(go,{...d})]})]})}function lE({nodeId:e}){var k,R;const{nodeById:r}=Xt(),{callbacks:t,config:n,readOnly:o,colorMode:i,isPerformanceMode:s}=Ue(),{background:a,border:c,colorInactive:l,colorText:d}=at(),u=[...r.values()].filter(({data:_})=>{var N,$,V,I,F;return _.type!=="grid"&&!((N=_.config)!=null&&N.parentContainer)&&((($=_.config)==null?void 0:$.contentFormat)==="html"||((V=_.config)==null?void 0:V.contentFormat)==="jsx")&&(typeof((I=_.config)==null?void 0:I.content)=="string"||Array.isArray((F=_.config)==null?void 0:F.content))}),[h,p]=j.useState(e),[m,g]=j.useState(!1),y=j.useRef(null),b=So({edge:"top",enabled:!0,bounds:y,inside:[y],threshold:90}),x=j.useRef(null),v=j.useRef(1),w=u.find(_=>_.data.id===h)??u.find(_=>_.data.id===e)??u[0],C=u.indexOf(w),S=!!n.editable&&!o,E=_=>typeof _=="number"?_>0&&Number.isFinite(_)?String(_):"":typeof _=="string"&&/^\d+(\.\d+)?px$/.test(_)?String(parseFloat(_)):"",M=E((k=w==null?void 0:w.data.viewProps)==null?void 0:k.width),P=E((R=w==null?void 0:w.data.viewProps)==null?void 0:R.height);j.useLayoutEffect(()=>{const _=x.current;if(!_||n.disableAnimations||s||matchMedia("(prefers-reduced-motion: reduce)").matches)return;const N=_.animate({transform:[`translateX(${v.current*100}%)`,"translateX(0)"]},{duration:240,easing:"ease-out",id:"flow-content-slide"});return()=>N.cancel()},[w==null?void 0:w.data.id,n.disableAnimations,s]);const T=_=>{const N=u[C+_];!N||m||(v.current=_,p(N.data.id))};return w?f.jsxs(W.Box,{"data-content-gallery":"",position:"relative",h:"100%",display:"flex",flexDirection:"column",minH:0,color:d,onClick:_=>_.stopPropagation(),onDoubleClick:_=>_.stopPropagation(),onPointerDown:_=>_.stopPropagation(),children:[f.jsx(W.Box,{ref:y,role:"toolbar","aria-label":"Preview controls",position:"absolute",top:"8px",left:"8px",w:"max-content",maxW:"calc(100% - 76px)",zIndex:2,css:{"@media (hover: hover) and (pointer: fine)":{opacity:b?1:0},"&:hover, &:focus-within":{opacity:1}},children:f.jsx(ko,{background:a,border:i==="dark"?c:"gray.300",children:f.jsxs(W.HStack,{px:2,gap:2,width:"max-content",height:"100%",children:[f.jsx(Ge,{label:"Previous content",children:f.jsx(Ne,{"data-flow-content-navigation":"","aria-label":"Previous content",icon:f.jsx(Q.PiCaretLeft,{size:20}),disabled:C<=0||m,onClick:()=>T(-1),rememberAction:!1,size:"sm",variant:"ghost"})}),f.jsxs(W.Text,{"aria-live":"polite",fontSize:"12px",minW:"42px",textAlign:"center",children:[C+1," / ",u.length]}),f.jsx(Ge,{label:"Next content",children:f.jsx(Ne,{"data-flow-content-navigation":"","aria-label":"Next content",icon:f.jsx(Q.PiCaretRight,{size:20}),disabled:C>=u.length-1||m,onClick:()=>T(1),rememberAction:!1,size:"sm",variant:"ghost"})}),["width","height"].map(_=>f.jsxs(W.Box,{as:"label",display:"flex",alignItems:"center",gap:1,fontSize:"12px",opacity:S?1:.5,children:[_==="width"?"W":"H",f.jsx(Er,{value:_==="width"?M:P,placeholder:"Auto",ariaLabel:`Content ${_}`,type:"number",min:1,width:"72px",disabled:!S||!t.onNodeDimensionChange||m,onCommit:N=>{var $;S&&(($=t.onNodeDimensionChange)==null||$.call(t,w.data.id,_,N===""?void 0:Number(N)))}})]},`${w.data.id}:${_}`)),S&&!m&&f.jsx(Ge,{label:"Edit content source",children:f.jsx(Ne,{"aria-label":"Edit content source",icon:f.jsx(Q.PiCode,{size:20}),onClick:()=>g(!0),rememberAction:!1,size:"sm",variant:"ghost",color:l})})]})})}),f.jsx(W.Box,{flex:1,minH:0,overflow:"auto",position:"relative","data-content-slide-viewport":"",children:f.jsx(W.Box,{ref:x,"data-content-slide":w.data.id,width:M?`${M}px`:"100%",height:P?`${P}px`:"100%",minH:P?void 0:"100%",mx:"auto",overflow:"auto",children:f.jsx(mu,{nodeId:w.data.id,content:w.data.config.content,format:w.data.config.contentFormat,color:d,previewControls:!1,editOnMount:m,onEditEnd:()=>g(!1)},`${w.data.id}:${m}`)},w.data.id)})]}):f.jsx(W.Box,{role:"status",p:4,children:"No HTML or JSX content available."})}const lv=j.forwardRef(function({fullscreen:r,onClick:t},n){const{colorInactive:o}=at();return f.jsx(Ne,{ref:n,"data-flow-fullscreen":"","aria-label":r?"Exit fullscreen":"Expand preview",title:r?"Exit fullscreen":"Expand preview","aria-expanded":r,icon:r?f.jsx(Q.PiArrowsIn,{size:20}):f.jsx(Q.PiArrowsOut,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:o,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:t})});function dE({content:e,format:r,onEdit:t,autoHeight:n=!1,nodeId:o,controls:i=!0}){var D,K,G,ce,re;const{config:s,colorMode:a}=Ue(),{nodeById:c}=Xt(),l=o?(K=(D=c.get(o))==null?void 0:D.data.viewProps)==null?void 0:K.height:void 0,d=typeof l=="number"?`${l}px`:typeof l=="string"&&/^\d+(\.\d+)?px$/.test(l)?l:void 0;n=n&&!d;const{background:u,border:h,colorInactive:p}=at(),m=(G=s.customViews)==null?void 0:G.jsxContent,g=typeof e=="string"?e:JSON.stringify(e,null,2);let y,b=r==="jsx"&&o?(re=(ce=c.get(o))==null?void 0:ce.data.config)==null?void 0:re.contentReferenceError:void 0;if(r==="jsx"&&!b)try{const Z=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(Z)||Z.some(ae=>!ae||typeof ae!="object"||Array.isArray(ae)||typeof ae.type!="string"))throw new Error("JSX content must be an array of components with a type.");y=Z}catch(Z){b=Z instanceof Error?Z.message:"Invalid components array."}const x=j.useRef(null),v=j.useRef(null),w=j.useRef(null),C=j.useRef(!1),[S,E]=j.useState(!1),M=j.useRef(null),P=So({edge:"top",enabled:S,bounds:M,inside:[M],threshold:90}),[T,k]=j.useState(""),[R,_]=j.useState(),N=!!t;j.useEffect(()=>{const Z=()=>{var ye;const ae=document.fullscreenElement===v.current;E(ae),C.current&&!ae&&!document.fullscreenElement&&((ye=w.current)==null||ye.focus({preventScroll:!0})),C.current=ae};return document.addEventListener("fullscreenchange",Z),()=>document.removeEventListener("fullscreenchange",Z)},[]);const $=async()=>{var Z;k("");try{if(document.fullscreenElement===v.current)await document.exitFullscreen();else if((Z=v.current)!=null&&Z.requestFullscreen)await v.current.requestFullscreen();else throw new Error("Fullscreen is not supported in this browser.")}catch(ae){k(ae instanceof Error?ae.message:"Unable to change fullscreen.")}},[V,I]=j.useState(),[F,oe]=j.useState(),[se,H]=j.useState();j.useEffect(()=>{if(r==="jsx")return;let Z=!1;return Promise.resolve().then(()=>require("./contentPreviewDocument-i1zWN5gw.cjs")).then(({contentPreviewDocument:ae})=>ae(g,r,N,n)).then(ae=>{Z||I({content:g,format:r,editable:N,autoHeight:n,document:ae})},ae=>{Z||I({content:g,format:r,editable:N,autoHeight:n,error:ae instanceof Error?ae.message:String(ae)})}),()=>{Z=!0}},[g,r,N,n]),j.useEffect(()=>{if(!t)return;const Z=async ae=>{var ye,xe;if(!(!((ye=x.current)!=null&&ye.contentWindow)||ae.source!==x.current.contentWindow||((xe=ae.data)==null?void 0:xe.type)!=="squeed:content-edit"))try{document.fullscreenElement===v.current&&await document.exitFullscreen(),t()}catch(fe){k(fe instanceof Error?fe.message:"Unable to close fullscreen.")}};return window.addEventListener("message",Z),()=>window.removeEventListener("message",Z)},[t]);const ee=(V==null?void 0:V.content)===g&&V.format===r&&V.editable===N&&V.autoHeight===n?V:void 0;j.useEffect(()=>{if(!n||r!=="html"||!(ee!=null&&ee.document))return;const Z=ee.document,ae=ye=>{var fe,U,te;const xe=(fe=ye.data)==null?void 0:fe.height;!((U=x.current)!=null&&U.contentWindow)||ye.source!==x.current.contentWindow||((te=ye.data)==null?void 0:te.type)!=="squeed:content-size"||typeof xe!="number"||!Number.isFinite(xe)||xe<=0||xe>1e5||document.fullscreenElement===v.current||_(de=>(de==null?void 0:de.document)===Z&&de.height===xe?de:{document:Z,height:xe})};return window.addEventListener("message",ae),()=>window.removeEventListener("message",ae)},[n,r,ee==null?void 0:ee.document]);const ue=!!ee&&ee===se,q=r!=="jsx"&&!(ee!=null&&ee.error)&&!ue&&(!ee||F!==ee);return f.jsxs("div",{"data-flow-content-preview":"",style:{width:"100%",height:i?d??(n?r==="jsx"?"auto":(R==null?void 0:R.document)===(ee==null?void 0:ee.document)?R==null?void 0:R.height:360:360):n?"auto":"100%",fontSize:16,overflow:"auto"},children:[f.jsx("pre",{"data-flow-preview-source":"",style:{display:"none",whiteSpace:"pre-wrap"},children:g}),f.jsxs(W.Box,{ref:v,position:"relative",w:"100%",h:n&&r==="jsx"?"auto":"100%","aria-busy":!S&&r!=="jsx"?q:void 0,bg:r==="jsx"&&a==="dark"?"gray.900":"white",onDoubleClick:Z=>{r!=="jsx"||!t||Z.defaultPrevented||Z.target.closest('button, a, input, textarea, select, [contenteditable], [role="button"], [role="textbox"]')||(Z.stopPropagation(),(async()=>{document.fullscreenElement===v.current&&await document.exitFullscreen(),t()})().catch(ae=>k(String(ae))))},onKeyDownCapture:Z=>{Z.key!=="Escape"||document.fullscreenElement!==v.current||Z.target instanceof Element&&Z.target.closest('input, textarea, select, [contenteditable="true"]')||(Z.preventDefault(),Z.stopPropagation(),$())},css:{"&:fullscreen":{width:"100vw",height:"100dvh",maxWidth:"none",maxHeight:"none",padding:0},"&:not(:fullscreen):hover > [data-flow-content-toolbar], &:not(:fullscreen):focus-within > [data-flow-content-toolbar]":{opacity:1,pointerEvents:"auto"},"@media (hover: none)":{"& > [data-flow-content-toolbar]":{opacity:1,pointerEvents:"auto"}}},children:[i&&f.jsx(W.Box,{ref:M,role:"toolbar","aria-label":"Content controls","data-flow-content-toolbar":"",position:"absolute",top:"8px",right:"8px",zIndex:1,w:"max-content",maxW:"calc(100% - 16px)",opacity:S?1:0,pointerEvents:S?"auto":"none",css:S?{"@media (hover: hover) and (pointer: fine)":{opacity:P?1:0},"&:hover, &:focus-within":{opacity:1}}:void 0,children:f.jsx(ko,{background:u,border:a==="dark"?h:"gray.300",children:f.jsxs(W.HStack,{px:"8px",gap:"8px",h:"100%",w:"max-content",css:{"& button > svg":{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",flexShrink:0}},children:[t&&(!S||!o)&&f.jsx(Ne,{"data-flow-content-edit":"","aria-label":"Edit content source",title:"Edit content source",icon:f.jsx(Q.PiCode,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:p,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:Z=>{Z.stopPropagation(),(async()=>{document.fullscreenElement===v.current&&await document.exitFullscreen(),t()})().catch(ae=>k(String(ae)))}}),f.jsx(lv,{ref:w,fullscreen:S,onClick:Z=>{Z.stopPropagation(),$()}})]})})}),T&&f.jsx(W.Box,{role:"alert",position:"absolute",bottom:0,insetInline:0,bg:"white",color:"red.700",fontSize:"14px",children:T}),S&&o?f.jsx(lE,{nodeId:o}):r==="jsx"?b?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:b}):m&&y?f.jsx(m,{components:y,colorMode:a,fillHeight:!n||S}):f.jsx(W.Box,{role:"status",fontSize:"14px",children:"JSX content renderer is not available."}):ee!=null&&ee.error||ue?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:(ee==null?void 0:ee.error)||"Content preview could not be loaded."}):ee!=null&&ee.document?f.jsx("iframe",{ref:x,title:`${r.toUpperCase()} content preview`,sandbox:N||n?"allow-scripts":"",allowFullScreen:!0,referrerPolicy:"no-referrer",srcDoc:ee.document,onLoad:()=>oe(ee),onError:()=>H(ee),style:{width:"100%",height:"100%",border:0,display:"block",background:"white",visibility:q?"hidden":"visible"}},ee.document):null,f.jsx(cv,{active:!S&&q,label:"Loading HTML content"})]})]})}const Rm=1.55;function mu({nodeId:e,content:r,color:t,format:n="markdown",fillBody:o=!1,autoHeight:i=!1,previewControls:s=!0,editOnMount:a=!1,plainText:c=!1,onChange:l,onEditEnd:d,onSubmit:u,onDraftChange:h}){var oe,se;const{callbacks:p,config:m,readOnly:g,nodeGridOptions:y}=Ue(),b=!!m.editable&&!g,x=b&&(!y||o&&y.fill&&n==="markdown"),{nodeById:v}=Xt(),w=n==="jsx"&&!l?((se=(oe=v.get(e))==null?void 0:oe.data.config)==null?void 0:se.contentSource)??r:r,C=typeof w=="string"?w:JSON.stringify(w,null,2),[S,E]=j.useState(a&&b),[M,P]=j.useState(C),[T,k]=j.useState(""),[R,_]=j.useState(),N=j.useRef(null),$=j.useRef(!1),V=gu(S);j.useLayoutEffect(()=>{const H=N.current;!S||!H||(H.style.height="auto",H.style.height=`${Math.max((R==null?void 0:R.height)??0,H.scrollHeight)}px`)},[M,S,R]),j.useEffect(()=>{var H,ee;b?S&&($.current=!1,(H=N.current)==null||H.focus({preventScroll:!0}),(ee=N.current)==null||ee.select()):(E(!1),h==null||h(void 0))},[S,b,h]);const I=(H,ee=!1)=>{!b||y&&!x&&!ee||(_({width:H.offsetWidth,height:H.offsetHeight}),P(C),h==null||h(C),k(""),E(!0))},F=()=>{var ee;if($.current||!b)return;let H=M;if(n==="jsx")try{if(H=JSON.parse(M),!Array.isArray(H)||H.some(ue=>!ue||typeof ue!="object"||Array.isArray(ue)||typeof ue.type!="string"&&typeof ue.$contentRef!="string"))throw new Error("JSX content must be an array of components with a type.")}catch(ue){k(ue instanceof Error?ue.message:"Invalid components array.");return}$.current=!0,M!==C&&(l?l(H):(ee=p.onNodeContentChange)==null||ee.call(p,e,H)),E(!1),d==null||d()};return(!S||!b)&&n!=="markdown"?f.jsx(W.Box,{ref:V,w:"100%",h:!s&&!i?"100%":void 0,position:"relative","data-flow-content":"",children:f.jsx(dE,{nodeId:e,content:r,format:n,controls:s,autoHeight:i&&!(y!=null&&y.fill),onEdit:x?()=>{V.current&&I(V.current)}:void 0})}):!S||!b?f.jsx(W.Box,{"data-flow-content":"",color:t,opacity:r?void 0:.6,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:Rm,overflowWrap:"anywhere",css:{"& > :first-of-type":{marginTop:0},"& > :last-of-type":{marginBottom:0},"& h1, & h2, & h3, & h4, & h5, & h6":{fontWeight:700,lineHeight:1.2,margin:"1em 0 0.45em"},"& h1":{fontSize:"1.5em"},"& h2":{fontSize:"1.3em"},"& h3":{fontSize:"1.1em"},"& p":{margin:"0.65em 0",whiteSpace:"pre-wrap"},"& ul, & ol":{margin:"0.65em 0",paddingInlineStart:"1.6em"},"& ul":{listStyleType:"disc"},"& ol":{listStyleType:"decimal"},"& li":{display:"list-item",margin:"0.3em 0",paddingInlineStart:"0.15em"},"& li > ul, & li > ol":{margin:"0.25em 0"},"& li > p":{margin:0},"& a":{color:"inherit",textDecoration:"underline"},"& code":{fontFamily:"monospace",fontSize:"0.85em"},"& :not(pre) > code":{background:"color-mix(in srgb, currentColor 10%, transparent)",padding:"0.1em 0.25em",borderRadius:"0.2em"},"& pre":{margin:"0.75em 0",padding:"0.75em",background:"color-mix(in srgb, currentColor 8%, transparent)",border:0,borderRadius:"6px",maxWidth:"100%",overflowX:"auto",whiteSpace:"pre",overflowWrap:"normal",lineHeight:1.5},"& pre code":{background:"transparent",padding:0,whiteSpace:"inherit"},"& strong":{fontWeight:700},"& em":{fontStyle:"italic"},"& blockquote":{margin:"0.4em 0",borderInlineStart:"0.1em solid currentColor",paddingInlineStart:"0.6em"},"& table":{width:"100%",tableLayout:"fixed",borderCollapse:"collapse",margin:"0.4em 0"},"& th, & td":{border:"1px solid currentColor",padding:"0.2em 0.3em",textAlign:"left"},"& th":{fontWeight:700},"& img":{maxWidth:"100%",height:"auto"}},cursor:x?"text":void 0,tabIndex:x?0:void 0,outline:"none",_focusVisible:{outline:"none",boxShadow:"none"},onClick:H=>{!b||y&&!x&&!H.shiftKey||H.target instanceof Element&&H.target.closest("a, button, input")||(H.stopPropagation(),I(H.currentTarget,H.shiftKey))},onDoubleClick:H=>{H.stopPropagation(),I(H.currentTarget,H.shiftKey)},onKeyDown:H=>{b&&(x||H.shiftKey)&&H.key==="Enter"&&H.target===H.currentTarget&&(H.preventDefault(),H.stopPropagation(),I(H.currentTarget,H.shiftKey))},children:c?f.jsx(W.Box,{whiteSpace:"pre-wrap",minH:"100%",children:C||(b?"Write your content here":"")}):f.jsx(Nv.default,{options:{forceBlock:!0,wrapper:j.Fragment,disableParsingRawHTML:!0,overrides:{a:{props:{target:"_blank",rel:"noopener noreferrer"}},img:{props:{loading:"lazy",referrerPolicy:"no-referrer"}}}},children:C||(m.editable&&!g?"Write your content here":"")})}):f.jsxs("div",{ref:V,style:{width:c?"100%":R==null?void 0:R.width,minHeight:R==null?void 0:R.height,maxWidth:"100%"},children:[f.jsx(W.Textarea,{ref:N,"aria-label":"Node content",placeholder:"Write your content here",value:M,"aria-invalid":!!T,onChange:H=>{P(H.target.value),h==null||h(H.target.value)},onPaste:H=>{c&&H.clipboardData.files.length&&(H.preventDefault(),H.stopPropagation())},onDrop:H=>{c&&(H.stopPropagation(),H.dataTransfer.files.length&&H.preventDefault())},onBlur:F,onKeyDown:H=>{if(H.stopPropagation(),!H.nativeEvent.isComposing){if(u&&n==="markdown"&&H.key==="Enter"&&!H.shiftKey&&!H.ctrlKey&&!H.metaKey&&!H.altKey){H.preventDefault(),!H.repeat&&!$.current&&M.trim()&&(Wr.flushSync(F),u(M));return}H.key==="Enter"&&(H.ctrlKey||H.metaKey)&&(H.preventDefault(),F()),H.key==="Escape"&&($.current=!0,E(!1),h==null||h(void 0),d==null||d())}},color:t,fontFamily:"inherit",fontSize:"inherit",lineHeight:Rm,overflowWrap:"anywhere",whiteSpace:"pre-wrap",rows:1,bg:"transparent",display:"block",style:{border:0,outline:"none",boxShadow:"none"},_focus:{border:0,outline:"none",boxShadow:"none"},_focusVisible:{border:0,outline:"none",boxShadow:"none"},p:0,w:"100%",h:"100%",minW:0,minH:0,resize:"none"}),T&&f.jsx(W.Box,{role:"alert",fontSize:"14px",color:"red.500",children:T})]})}function uE({edited:e,fontSize:r}){const t=Pw(e.at);return!t||!e.name?null:f.jsxs(W.Text,{"data-flow-node-edited":"",fontSize:r,lineHeight:1.3,textTransform:"none",children:[e.name," · edited"," ",f.jsx("time",{dateTime:e.at,title:new Date(e.at).toLocaleString(),children:t})]})}function Mm({data:e,caption:r=!1}){var a,c,l,d,u;const{colorText:t}=at(),n=typeof((a=e.config)==null?void 0:a.subtitle)=="string"?e.config.subtitle:"",o=(c=e.config)==null?void 0:c.edited,i=r||typeof((l=e.config)==null?void 0:l.content)=="string"||Array.isArray((d=e.config)==null?void 0:d.content),s=e.type==="objectView"||(u=e.config)!=null&&u.labelBelow||i?"32px":"20px";return!o&&!i||!o&&!n?null:f.jsxs(W.Box,{"data-flow-node-subtitles":"",color:t,opacity:.7,pt:2,minW:0,maxW:"100%",textAlign:"center",overflowWrap:"anywhere",children:[n&&f.jsx(W.Text,{"data-flow-node-subtitle":"",fontSize:s,lineHeight:1.3,children:n}),o&&f.jsx(uE,{edited:o,fontSize:s})]})}const fE=({data:e,children:r,isInverted:t,isParent:n,onOpenView:o,editOnMount:i=!1,hoverLeaveDelay:s=0})=>{var fe,U,te,de,Pe,ie,we,$e,He,Ve,tt;const{selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isMultiSelectMode:u,nodeGridOptions:h,isPerformanceMode:p,engineRef:m,callbacks:g,config:y,themeColor:b,direction:x,nodeViewModes:v}=Ue(),{background:w,border:C,colorText:S}=at(),E=j.useRef(null),M=j.useRef(null);j.useEffect(()=>()=>{M.current&&clearTimeout(M.current)},[]);const[P,T]=j.useState(!1),[k,R]=j.useState(i&&!!y.editable&&!y.readOnly),[_,N]=j.useState(!1),$=e==null?void 0:e.id,V=Pb($),I=a.includes($);j.useEffect(()=>{if(!I||a.length!==1||y.readOnly||k||_)return;const me=Ie=>{var Xe,ut,Ae,Ke,lt;if(Ie.key!=="Enter"||Ie.defaultPrevented||Ie.isComposing||Ie.ctrlKey||Ie.metaKey||Ie.altKey||Ie.shiftKey||Ie.target instanceof Element&&Ie.target.closest('button, input, textarea, select, a, [contenteditable], [role="textbox"], [role="dialog"], [role="menu"], [role="listbox"], [popover], [data-flow-content]')||Array.from(document.querySelectorAll('dialog[open], :popover-open, [role="dialog"], [role="menu"], [role="listbox"]')).some(Je=>Je.getClientRects().length&&getComputedStyle(Je).visibility!=="hidden"))return;const De=Array.from(((Xe=E.current)==null?void 0:Xe.querySelectorAll("[data-flow-content-toggle] button, button[data-flow-collapse-control]"))??[]).find(Je=>{var yt;return((yt=Je.closest("[data-node-id]"))==null?void 0:yt.getAttribute("data-node-id"))===$&&!Je.disabled&&Je.getClientRects().length&&getComputedStyle(Je).visibility!=="hidden"}),be=!De&&(e==null?void 0:e.type)==="grid"&&((ut=e.config)==null?void 0:ut.documentId)&&((Ae=E.current)==null?void 0:Ae.getClientRects().length)&&g.onNodeHoverAction&&((Ke=y.nodeOverlayActions)==null?void 0:Ke.find(Je=>Je.id==="open-document"&&(!Je.nodeTypes||Je.nodeTypes.includes(e.type))));!De&&!be||(Ie.preventDefault(),Ie.stopPropagation(),Ie.repeat||(De?De.click():(lt=g.onNodeHoverAction)==null||lt.call(g,be.id,$,e)))};return window.addEventListener("keydown",me,!0),()=>window.removeEventListener("keydown",me,!0)},[$,I,a.length,y.readOnly,k,_,e,g.onNodeHoverAction,y.nodeOverlayActions]);const F=(fe=y.nodeOverlayActions)==null?void 0:fe.filter(me=>!me.nodeTypes||me.nodeTypes.includes(e==null?void 0:e.type)),oe=y.renderNodeOverlay,se=(e==null?void 0:e.type)==="grid"?(U=y.customViews)==null?void 0:U.gridHoverControls:void 0,H=(e==null?void 0:e.type)==="grid"?"20px":"-100px",ee=(e==null?void 0:e.type)==="grid"?"top center":void 0,ue=(e==null?void 0:e.type)==="grid"?"translateX(-50%) scale3d(1.8, 1.8, 1)":"translateX(-50%) scale3d(3, 3, 1)",q=(()=>{var me;try{const Ie=(me=m.current)==null?void 0:me.zoom();return Ie!==void 0&&Ie<.08}catch{return!1}})(),D=j.useCallback((me,Ie=!1)=>{var be,Xe,ut,Ae,Ke;if(k||y.readOnly||h!=null&&h.fill&&!me.shiftKey||me.detail===2&&((be=e==null?void 0:e.config)!=null&&be.form)&&!o&&!Ie&&!u&&!l&&!me.shiftKey&&!me.ctrlKey&&!me.metaKey&&!me.altKey&&a.length===1&&a[0]===$)return;const De={shiftKey:me.shiftKey,ctrlKey:me.ctrlKey,metaKey:me.metaKey,altKey:me.altKey,...Ie?{viewToggle:!0}:{}};if(l&&(d(null),(Xe=g.onEdgeDeselect)==null||Xe.call(g)),u||me.shiftKey&&(h!=null&&h.fill)){const lt=a.includes($),Je=lt?a.filter(yt=>yt!==$):[...a,$];c(Je),lt?(ut=g.onNodeDeselect)==null||ut.call(g):(Ae=g.onNodeSelect)==null||Ae.call(g,$,e,De)}else c([$]),(Ke=g.onNodeSelect)==null||Ke.call(g,$,e,De)},[$,e,a,l,u,h,k,o,c,d,g,y]),K=j.useCallback(()=>{var me;k||y.readOnly||(me=g.onNodeDoubleClick)==null||me.call(g,$,e)},[$,e,k,g,y]),G=j.useCallback(()=>{M.current&&clearTimeout(M.current),M.current=setTimeout(()=>T(!0),100)},[]),ce=j.useCallback(me=>{var Ie;me.relatedTarget instanceof Node&&((Ie=E.current)!=null&&Ie.contains(me.relatedTarget))||(M.current&&clearTimeout(M.current),s?M.current=setTimeout(()=>T(!1),s):T(!1))},[s]),re=(e==null?void 0:e.type)==="text"&&!((te=e==null?void 0:e.config)!=null&&te.parentContainer)&&!((de=e==null?void 0:e.config)!=null&&de.form),Z=!!((Pe=e==null?void 0:e.config)!=null&&Pe.form)||re,ae={tabIndex:Z?0:void 0,"aria-haspopup":Z?"dialog":void 0,"aria-expanded":Z?_:void 0,onDoubleClickCapture:me=>{var Ie;!Z&&!o||y.readOnly||re&&!y.editable||k||!me.currentTarget.contains(me.target)||me.target instanceof Element&&me.target.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]")||(me.preventDefault(),me.stopPropagation(),(a.length!==1||a[0]!==$)&&c([$]),o?o():N(!0),(Ie=g.onNodeDoubleClick)==null||Ie.call(g,$,e))},onKeyDown:me=>{!Z&&!o||y.readOnly||re&&!y.editable||me.target!==me.currentTarget||me.key!=="Enter"||(me.preventDefault(),me.stopPropagation(),c([$]),o?o():N(!0))}},ye=Z&&f.jsx(yu,{nodeAddress:$,active:I,label:e.label||e.headerTitle||"Node",open:_&&(!re||!!y.editable&&!y.readOnly),onClose:()=>{var me;N(!1),I&&((me=E.current)==null||me.focus({preventScroll:!0}))},children:re?f.jsx(mu,{nodeId:$,content:e.label??e.text??"",color:Me(S),editOnMount:!0,onChange:me=>{var Ie;return(Ie=g.onNodeLabelChange)==null?void 0:Ie.call(g,$,String(me))},onEditEnd:()=>N(!1)}):void 0}),xe=Array.isArray((ie=e==null?void 0:e.config)==null?void 0:ie.ports)?e.config.ports.map(me=>f.jsx(sv,{...me},`${me.id}:${me.role}`)):null;return n?f.jsxs(W.Box,{ref:E,...ae,onClick:D,onDoubleClick:K,onMouseEnter:G,onMouseLeave:ce,cursor:"pointer",position:"relative",children:[ye,!p&&(oe||F&&F.length>0)&&P&&!q&&f.jsxs(f.Fragment,{children:[f.jsx(W.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>T(!0),onMouseLeave:ce}),oe?f.jsx(W.Box,{position:"absolute",zIndex:1e3,top:H,transformOrigin:ee,left:"50%",pointerEvents:"auto",transform:ue,onMouseEnter:()=>T(!0),onMouseLeave:ce,willChange:"transform",children:oe({nodeId:$,nodeData:e,isRoot:$==="root",isParent:!0,isHovered:P,setIsHovered:T})}):f.jsx(W.Box,{position:"absolute",zIndex:1e3,top:H,transformOrigin:ee,left:"50%",bg:w,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:ue,boxShadow:"lg",onMouseEnter:()=>T(!0),onMouseLeave:ce,willChange:"transform",children:f.jsxs(W.HStack,{px:2,gap:2,"data-flow-grid-toolbar":(e==null?void 0:e.type)==="grid"?"":void 0,css:(e==null?void 0:e.type)==="grid"?{"& button svg":{width:"22px",height:"22px",minWidth:"22px",minHeight:"22px"}}:void 0,children:[F.map((me,Ie)=>f.jsxs(W.Box,{display:"contents",children:[Ie>0&&f.jsx(W.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(Rd,{icon:me.icon,label:me.label,color:S,bgColor:w,borderColor:C,textColor:S,boxSize:5,onClick:De=>{var be;De.stopPropagation(),(be=g.onNodeHoverAction)==null||be.call(g,me.id,$,e)}})]},me.id)),se&&f.jsx(se,{data:e})]})})]}),r({id:$,data:e,isActive:I,isHovered:P,isLowZoom:q,isEditing:k,onSelect:D,onEditStart:()=>R(!0),onEditEnd:()=>R(!1)}),f.jsx(Mm,{data:e}),V&&!((we=e==null?void 0:e.config)!=null&&we.parentContainer)&&(($e=e==null?void 0:e.config)==null?void 0:$e.collapsed)!==void 0&&(()=>{var De;const me=x==="TB"||x==="BT",Ie=t||x==="RL";return f.jsx(W.IconButton,{position:"absolute",...me?{[x==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:Ie?void 0:"-75px",left:Ie?"-75px":void 0,top:"50%",transform:"translateY(-50%)"},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:y.readOnly,onClick:be=>{var Xe;be.stopPropagation(),(Xe=g.onNodeCollapse)==null||Xe.call(g,$,!e.config.collapsed)},bgColor:Me(((De=e==null?void 0:e.viewProps)==null?void 0:De.bgColor)||b),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Q.PiPlusBold,{size:30,color:Me("gray.800")}):f.jsx(Q.PiMinusBold,{size:30,color:Me("gray.800")})})})()]}):f.jsxs(W.Box,{ref:E,...ae,onClick:D,onDoubleClick:K,onMouseEnter:G,onMouseLeave:ce,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[ye,xe,!p&&(oe||F&&F.length>0)&&P&&!q&&f.jsxs(f.Fragment,{children:[f.jsx(W.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>T(!0),onMouseLeave:ce}),oe?f.jsx(W.Box,{position:"absolute",zIndex:1e3,top:H,transformOrigin:ee,left:"50%",pointerEvents:"auto",transform:ue,onMouseEnter:()=>T(!0),onMouseLeave:ce,willChange:"transform",children:oe({nodeId:$,nodeData:e,isRoot:$==="root",isParent:!!n,isHovered:P,setIsHovered:T})}):f.jsx(W.Box,{position:"absolute",zIndex:1e3,top:H,transformOrigin:ee,left:"50%",bg:w,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:ue,boxShadow:"lg",onMouseEnter:()=>T(!0),onMouseLeave:ce,willChange:"transform",children:f.jsxs(W.HStack,{px:2,gap:2,"data-flow-grid-toolbar":(e==null?void 0:e.type)==="grid"?"":void 0,css:(e==null?void 0:e.type)==="grid"?{"& button svg":{width:"22px",height:"22px",minWidth:"22px",minHeight:"22px"}}:void 0,children:[F.map((me,Ie)=>f.jsxs(W.Box,{display:"contents",children:[Ie>0&&f.jsx(W.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(Rd,{icon:me.icon,label:me.label,color:S,bgColor:w,borderColor:C,textColor:S,boxSize:5,onClick:De=>{var be;De.stopPropagation(),(be=g.onNodeHoverAction)==null||be.call(g,me.id,$,e)}})]},me.id)),se&&f.jsx(se,{data:e})]})})]}),f.jsxs(W.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[V&&!((He=e==null?void 0:e.config)!=null&&He.parentContainer)&&((Ve=e==null?void 0:e.config)==null?void 0:Ve.collapsed)!==void 0&&!n&&(()=>{var be,Xe,ut;const me=x==="TB"||x==="BT",Ie=t||x==="RL",De=(be=e==null?void 0:e.config)!=null&&be.labelBelow&&v[$]!=="properties"?((((Xe=e==null?void 0:e.viewProps)==null?void 0:Xe.fontSize)||1)*100+100)/2:void 0;return f.jsx(W.IconButton,{position:"absolute",...me?{[x==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:Ie?void 0:De===void 0?"-75px":`calc(50% - ${De+75}px)`,left:Ie?De===void 0?"-75px":`calc(50% - ${De+75}px)`:void 0,alignSelf:De===void 0?"center":void 0,top:De===void 0?void 0:`${De}px`,transform:De===void 0?void 0:"translateY(-50%)",zIndex:De===void 0?void 0:1},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:y.readOnly,onClick:Ae=>{var Ke;Ae.stopPropagation(),(Ke=g.onNodeCollapse)==null||Ke.call(g,$,!e.config.collapsed)},bgColor:Me(((ut=e==null?void 0:e.viewProps)==null?void 0:ut.bgColor)||b),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Q.PiPlusBold,{size:30,color:Me("gray.800")}):f.jsx(Q.PiMinusBold,{size:30,color:Me("gray.800")})})})(),r({id:$,data:e,isActive:I,isHovered:P,isLowZoom:q,isEditing:k,onSelect:D,onEditStart:()=>R(!0),onEditEnd:()=>R(!1)})]}),f.jsx(Mm,{data:e,caption:!!((tt=e.config)!=null&&tt.labelBelow)&&v[$]!=="properties"})]})},Qn=j.memo(fE),hE=({id:e,data:r,isActive:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var g,y,b,x,v,w,C,S;const{themeColor:s}=Ue(),{colorText:a}=at(),c=((g=r==null?void 0:r.viewProps)==null?void 0:g.bgColor)==="transparent",l=((y=r==null?void 0:r.viewProps)==null?void 0:y.outline)===!0,{highlightColor:d,borderColor:u,textColor:h}=Gn(((b=r==null?void 0:r.viewProps)==null?void 0:b.bgColor)||s),p=Me(((x=r==null?void 0:r.viewProps)==null?void 0:x.textColor)||(c||l?a:h)),m=((v=r==null?void 0:r.viewProps)==null?void 0:v.borderColor)||(l?!c&&((w=r==null?void 0:r.viewProps)==null?void 0:w.bgColor)||s:u);return f.jsx(W.Box,{"data-flow-node-surface":"",borderRadius:(C=r==null?void 0:r.viewProps)==null?void 0:C.borderRadius,bgColor:l?"transparent":d,...Wn(r==null?void 0:r.viewProps,m,t,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:f.jsxs(W.Flex,{justifyContent:"start",alignItems:"center",gap:8,w:"fit-content",maxW:900,minW:0,fontSize:"5xl",lineHeight:"normal",children:[((S=r==null?void 0:r.config)==null?void 0:S.icon)&&f.jsx(W.Box,{flexShrink:0,children:f.jsx(cr,{name:r.config.icon,size:80,color:p})}),f.jsx(cn,{nodeId:e,label:(r==null?void 0:r.label)||(r==null?void 0:r.text)||"",color:p,isEditing:n,onEditStart:o,onEditEnd:i})]})})};function bu(e,r,t){const{readOnly:n,selectedNodeIds:o}=Ue(),i=o.includes(e),s=j.useRef(i),a=j.useRef(t);a.current=t,j.useEffect(()=>{s.current&&!i&&r&&!n&&a.current(),s.current=i},[i,r,n])}function eo(){const{nodeViewModes:e,setNodeViewMode:r,allNodesIconLabel:t,setAllNodesIconLabel:n}=Ue();return{allNodesIconLabel:t,setAllNodesIconLabel:n,getNodeViewMode:o=>e[o]??"default",showNodeProperties:o=>r(o,"properties"),restoreNodeView:o=>r(o,"default"),toggleNodeView:o=>r(o,e[o]==="properties"?"default":"properties"),setNodeViewMode:r}}const pE=({id:e,isActive:r,data:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var v,w,C,S,E,M,P,T,k,R,_,N,$;const{themeColor:s}=Ue(),{colorText:a}=at(),c=((v=t==null?void 0:t.viewProps)==null?void 0:v.bgColor)==="transparent",l=((w=t==null?void 0:t.viewProps)==null?void 0:w.outline)===!0,d=!c&&((C=t==null?void 0:t.viewProps)==null?void 0:C.bgColor)||s,{borderColor:u,highlightColor:h,textColor:p}=Gn(d),m=Me(((S=t==null?void 0:t.viewProps)==null?void 0:S.textColor)||(c||l?a:p)),g=c&&!l&&!((E=t==null?void 0:t.viewProps)!=null&&E.borderColor)?"transparent":Me(((M=t==null?void 0:t.viewProps)==null?void 0:M.borderColor)||(l?d:u)),y=c||l?"transparent":d!=null&&d.startsWith("#")?d:Me(h),b=(P=t==null?void 0:t.config)==null?void 0:P.icon,x=(t==null?void 0:t.label)??(t==null?void 0:t.text)??"";if((T=t==null?void 0:t.config)!=null&&T.labelBelow){const V=(((k=t==null?void 0:t.viewProps)==null?void 0:k.fontSize)||1)*100;return f.jsxs(W.Flex,{"data-flow-icon-label":"",css:{"--flow-grid-on-surface-color":m},direction:"column",align:"center",gap:"24px",width:`${Math.max(V+200,360)}px`,position:"relative",children:[f.jsx(W.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${V+100}px`,height:`${V+100}px`,flexShrink:0,borderRadius:(R=t==null?void 0:t.viewProps)==null?void 0:R.borderRadius,backgroundColor:y,...Wn(t==null?void 0:t.viewProps,g,r,2),children:!!b&&f.jsx(cr,{name:b,size:V,color:m})}),f.jsx(W.Flex,{"data-flow-icon-caption":"",direction:"column",align:"center",gap:"8px",justify:"center",width:"100%",minW:0,textAlign:"center",children:f.jsx(cn,{nodeId:e,label:x,color:`var(--flow-grid-caption-color, ${Me(((_=t==null?void 0:t.viewProps)==null?void 0:_.textColor)||a)})`,isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0})})]})}return f.jsxs(W.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:(N=t==null?void 0:t.viewProps)==null?void 0:N.borderRadius,bgColor:y,style:{backgroundColor:y},textTransform:"capitalize",...Wn(t==null?void 0:t.viewProps,g,r,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!b&&f.jsx(W.Flex,{align:"center",py:14,mr:x?8:0,flexShrink:0,children:f.jsx(cr,{name:b,size:((($=t==null?void 0:t.viewProps)==null?void 0:$.fontSize)||1)*100,color:m},m)}),(x||!b)&&f.jsx(W.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:f.jsx(cn,{nodeId:e,label:x,color:m,isEditing:n,onEditStart:o,onEditEnd:i})})]})};function bo({onExpand:e,toggleLabel:r="Show properties",toggleDisabled:t=!1,renderCompact:n=pE,...o}){const{colorMode:i,callbacks:s}=Ue();return f.jsx(Qn,{...o,hoverLeaveDelay:e?350:0,children:a=>f.jsxs(W.Box,{position:"relative",children:[f.jsx(n,{...a}),e&&(a.isHovered||a.isActive)&&f.jsx(W.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:f.jsx(Ge,{label:r,children:f.jsx(Ne,{"aria-label":r,icon:f.jsx(W.Icon,{as:Q.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:i==="dark"?"gray.100":"gray.800",disabled:t,onClick:c=>{var l;c.stopPropagation(),a.isActive||a.onSelect(c,!0),(l=s.onNodeViewToggle)==null||l.call(s,o.data.id),e()}})})})]})})}const dv=(e,r,t)=>{var h,p,m,g;const n=((h=e==null?void 0:e.viewProps)==null?void 0:h.bgColor)||r,[o]=n.split("."),i=Gn(n),s=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,a=n==="transparent"||s,c=t==="dark"?"gray.200":"gray.900",l=a?"transparent":n!=null&&n.startsWith("#")?Me(n):Me(i.bgColor),d=Me(((m=e==null?void 0:e.viewProps)==null?void 0:m.textColor)||(a?c:i.textColor)),u=Me(((g=e==null?void 0:e.viewProps)==null?void 0:g.borderColor)||(s?n==="transparent"?r:n:i.borderColor));return{...i,bgColor:a?"transparent":i.bgColor,highlightColor:a?"transparent":i.highlightColor,isTransparent:a,propertyColor:a?c:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:l,hextextColor:d,hexborderColor:u}},gE=(e,r=350)=>`${String(e).substring(0,r)}${String(e).length>r?"...":""}`,yE=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,uv=600,mE=3,bE=e=>{const r=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(r*28+30,200)};function xE({headerTitle:e,hasContent:r,data:t,icon:n,colors:o,hasConfig:i,id:s,isActive:a,isHovered:c,isEditing:l,onSelect:d,onEditStart:u,onEditEnd:h,props:p,objVisible:m,setObjVisible:g,onShowNativeIcon:y}){var w,C,S,E;const{callbacks:b}=Ue();if(r&&!m&&t.label===""&&(((w=t.config)==null?void 0:w.contentFormat)==="html"||((C=t.config)==null?void 0:C.contentFormat)==="jsx"))return null;const x=p.onShowIcon??y,v=x?"Show icon":m?"Show content":"Show properties";return f.jsx(f.Fragment,{children:(e||r||((S=t.config)==null?void 0:S.form)||(a||c)&&y)&&f.jsxs(W.Flex,{justify:"flex-start",direction:"row",p:r||Object.entries(t.description||{}).length?8:20,borderBottomWidth:1,minWidth:"max-content !important",width:"100%",textTransform:"capitalize",align:"center",textOverflow:"ellipsis",alignItems:"center",fontWeight:"bold",color:o.propertyColor,bgColor:o.highlightColor,borderBottomColor:!i&&!r?"transparent":o.hexborderColor,children:[!!n&&f.jsx(W.Flex,{mr:6,alignItems:"center",flexShrink:0,children:f.jsx(cr,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),f.jsx(cn,{nodeId:s,label:yE(e),color:((E=t==null?void 0:t.viewProps)==null?void 0:E.textColor)||o.propertyColor,isEditing:l,onEditStart:u,onEditEnd:h}),(a||c)&&(r||x)&&f.jsx(W.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:f.jsx(Ge,{label:v,children:f.jsx(Ne,{"aria-label":v,icon:f.jsx(W.Icon,{as:Q.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:M=>{var P;M.stopPropagation(),a||d(M),x?x():g(!m),(P=b.onNodeViewToggle)==null||P.call(b,s)}})})})]})})}function vE({data:e,resourcePorts:r,inspecting:t,form:n,inspectionPorts:o,extraPorts:i,colors:s,direction:a,uniformKeyWidth:c}){const{edgeById:l}=Xt(),d=new Set;for(const{data:u}of l.values())u.source===e.id&&u.sourceProperty!==void 0&&d.add(`source:${u.sourceProperty}`),u.target===e.id&&u.targetProperty!==void 0&&d.add(`target:${u.targetProperty}`);return f.jsx(W.Box,{children:Object.entries(e.description||{}).map(([u,h],p)=>{var _,N,$;const m=r&&Object.keys(r).find(V=>V.slice(V.indexOf(":")+1)===u),g=t&&((_=n==null?void 0:n.type.ports)==null?void 0:_[u]),y=m??(g?`${g.kind}:${u}`:u),b=o.find(V=>V.id===y),x=m?"source":b==null?void 0:b.role,v=d.has(`source:${y}`),w=d.has(`target:${y}`),C=i.some(V=>V.id===u),S=h===""&&(C||(x?d.has(`${x}:${y}`):v||w)),E=x??(v!==w?v?"source":"target":void 0),M=(b==null?void 0:b.side)??(E?E==="source"!=(a==="RL")?"right":"left":void 0),P=S&&M==="right"?"right":"left",T=(b==null?void 0:b.label)??(g==null?void 0:g.label)??(C?u.replace(/^(template|input|output|config|error):/,""):u),k=sr(s.wordBeforeDot)[typeof h],R=sr(s.wordBeforeDot).property;return f.jsxs(W.Box,{"data-flow-property":m&&(a==="TB"||a==="BT")?void 0:y,"data-flow-port-role":x,"data-flow-inspection-row":t?"":void 0,children:[f.jsxs(W.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[f.jsx(W.Flex,{justifyContent:"start",align:"center",background:s.highlightColor,width:S?"100%":`${c}px`,minWidth:`${c}px`,borderRightColor:s.hexborderColor,borderRightWidth:S?0:1,children:f.jsx(W.Text,{py:5,px:10,w:"100%",textAlign:P,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((N=e==null?void 0:e.viewProps)==null?void 0:N.textColor)||(s.isTransparent?s.hextextColor:R),children:T})}),!S&&f.jsx(W.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:s.hexbgColor,w:uv,maxH:200,children:f.jsx(W.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:(($=e==null?void 0:e.viewProps)==null?void 0:$.textColor)||(s.isTransparent?s.hextextColor:k),fontWeight:400,children:gE(h)})})]}),p!==Object.entries(e.description||{}).length-1&&f.jsx(W.Box,{borderTopWidth:1,my:0,borderColor:s.hexborderColor})]},u)})})}function wE(e){var v,w,C,S,E;const{themeColor:r,colorMode:t,direction:n}=Ue(),o=eo(),i=o.getNodeViewMode(e.data.id)==="properties",s=M=>o.setNodeViewMode(e.data.id,M?"properties":"default"),a=!!e.onShowIcon||i||typeof((v=e.data.config)==null?void 0:v.content)!="string"&&!(((w=e.data.config)==null?void 0:w.contentFormat)==="jsx"&&Array.isArray((C=e.data.config)==null?void 0:C.content)),{bindings:c,data:l,schema:d}=j.useContext($t),u=(S=c==null?void 0:c[e.data.id])==null?void 0:S.portResources,h=c?Hn(c,e.data.id,d):l&&d?un(l,e.data.id,d):void 0,p=h&&Oe(l,"address"in h?h.address:e.data.id),m=p&&typeof p=="object"&&h?Object.fromEntries(Object.keys(h.type.properties).filter(M=>{var P;return Object.prototype.hasOwnProperty.call(p,M)&&Eo((P=h.fields[M])==null?void 0:P.$visibleWhen,l)}).map(M=>[M,p[M]!==null&&typeof p[M]=="object"?JSON.stringify(p[M],null,2):p[M]===null?"null":p[M]])):{},g=u?Object.fromEntries(Object.entries(u).map(([M,P])=>{var T;return[M.slice(M.indexOf(":")+1),((T=Oe(l,P))==null?void 0:T.name)??P.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:m,y=a&&!u?((E=e.data.config)==null?void 0:E.ports)??[]:[],b=y.filter(M=>!Object.prototype.hasOwnProperty.call(g,M.id)&&!Object.entries((h==null?void 0:h.type.ports)??{}).some(([P,T])=>`${T.kind}:${P}`===M.id&&Object.prototype.hasOwnProperty.call(g,P))),x={...g,...Object.fromEntries(b.map(M=>[M.id,""]))};return{themeColor:r,colorMode:t,direction:n,objVisible:i,setObjVisible:s,inspecting:a,resourcePorts:u,form:h,description:x,inspectionPorts:y,extraPorts:b}}const Uo=e=>{var x,v,w,C,S,E,M,P;const{themeColor:r,colorMode:t,direction:n,objVisible:o,setObjVisible:i,inspecting:s,resourcePorts:a,form:c,description:l,inspectionPorts:d,extraPorts:u}=wE(e),h=eo(),p=h.getNodeViewMode(e.data.id)==="icon-label",m=!e.onShowIcon&&(typeof((x=e.data.config)==null?void 0:x.content)=="string"||((v=e.data.config)==null?void 0:v.contentFormat)==="jsx"&&Array.isArray((w=e.data.config)==null?void 0:w.content)),g=j.useRef(p);p&&(g.current=!0),bu(e.data.id,m&&!((C=e.data.config)!=null&&C.parentContainer)&&h.allNodesIconLabel&&!p&&g.current,()=>h.setNodeViewMode(e.data.id,"icon-label"));const b=!e.onShowIcon&&!((S=e.data.config)!=null&&S.parentContainer)?()=>h.setNodeViewMode(e.data.id,"icon-label"):void 0;return!e.onShowIcon&&p?f.jsx(bo,{...e,data:{...e.data,label:e.data.label??e.data.headerTitle,config:{...e.data.config,labelBelow:!0,icon:((E=e.data.config)==null?void 0:E.icon)||(m?((M=e.data.config)==null?void 0:M.contentFormat)==="html"?"PiFileHtml":((P=e.data.config)==null?void 0:P.contentFormat)==="jsx"?"PiFileJsx":"PiMarkdownLogo":"PiBracketsCurly")}},onExpand:()=>h.restoreNodeView(e.data.id)}):f.jsx(Qn,{...e,data:{...e.data,description:l},hoverLeaveDelay:m||e.onShowIcon||b?350:0,children:({id:T,data:k,isActive:R,isHovered:_,isEditing:N,onSelect:$,onEditStart:V,onEditEnd:I})=>{var ce,re,Z,ae,ye,xe,fe,U,te,de,Pe,ie,we,$e,He,Ve,tt;const F=dv(k,r,t),oe=k.label??k.headerTitle,se=Object.entries(k.description||{}).length>0,H=bE(k.description),ee=(re=(ce=e.data)==null?void 0:ce.config)==null?void 0:re.icon,ue=(ae=(Z=e.data)==null?void 0:Z.config)==null?void 0:ae.content,q=m&&!o&&k.label===""&&(((ye=k.config)==null?void 0:ye.contentFormat)==="html"||((xe=k.config)==null?void 0:xe.contentFormat)==="jsx"),D=m&&!o&&(((fe=k.config)==null?void 0:fe.contentFormat)==="html"||((U=k.config)==null?void 0:U.contentFormat)==="jsx")&&((te=k.viewProps)==null?void 0:te.width)!==void 0&&k.viewProps.width!=="100%",K=((de=k==null?void 0:k.viewProps)==null?void 0:de.borderRadius)??"53px",G=Wn(k==null?void 0:k.viewProps,F.hexborderColor,R,mE);return f.jsx(W.Flex,{justifyContent:"space-between",...k==null?void 0:k.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:K,overflow:"hidden",alignItems:"center",style:{backgroundColor:F.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:e.contentWidth??(q||D?((Pe=k.viewProps)==null?void 0:Pe.width)!==void 0&&k.viewProps.width!=="100%"?k.viewProps.width:"max-content":"100%"),maxW:q?"calc(100vw - 40px)":void 0,height:e.contentHeight??((ie=k.viewProps)==null?void 0:ie.height),minW:e.contentMinWidth??(e.contentWidth||q||D?0:m||e.onShowIcon?H+uv+G.borderWidth*2:void 0),...G,children:f.jsxs(W.Flex,{width:"100%",height:e.contentHeight!==void 0?"100%":void 0,minH:e.contentHeight!==void 0?0:void 0,direction:"column",borderRadius:K,borderColor:F.hexborderColor,borderWidth:0,overflow:"hidden",children:[!e.fillBody&&f.jsx(xE,{headerTitle:oe,hasContent:m,data:k,icon:ee,colors:F,hasConfig:se,id:T,isActive:R,isHovered:_,isEditing:N,onSelect:$,onEditStart:V,onEditEnd:I,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:b}),m&&!o?f.jsx(W.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:F.highlightColor,p:["html","jsx"].includes(($e=(we=e.data)==null?void 0:we.config)==null?void 0:$e.contentFormat)?0:12,fontSize:"5xl",lineHeight:"normal",...e.contentProps,children:f.jsx(mu,{nodeId:T,content:ue,format:(Ve=(He=e.data)==null?void 0:He.config)==null?void 0:Ve.contentFormat,fillBody:e.fillBody,autoHeight:q,color:((tt=k==null?void 0:k.viewProps)==null?void 0:tt.textColor)||F.hextextColor,onSubmit:e.onContentSubmit,onDraftChange:e.onContentDraftChange,plainText:e.contentPlainText})}):f.jsx(vE,{data:k,resourcePorts:a,inspecting:s,form:c,inspectionPorts:d,extraPorts:u,colors:F,direction:n,uniformKeyWidth:H}),e.footer]})})}})};Uo.displayName="NodeJsonObjectView";const fv=e=>{var h,p,m,g,y,b,x,v,w,C,S,E;const r=eo(),[t,n]=j.useState(!1),o=r.getNodeViewMode(e.data.id)==="properties",i=M=>{n(M),r.setNodeViewMode(e.data.id,M?"properties":"default")},{callbacks:s,readOnly:a}=Ue(),c=(p=(h=e.data)==null?void 0:h.config)==null?void 0:p.parentContainer;bu(e.data.id,o&&((g=(m=e.data)==null?void 0:m.config)==null?void 0:g.labelBelow)&&!c,()=>i(!1));const l=c?"Show parent":"Show properties",d=c||((b=(y=e.data)==null?void 0:y.config)==null?void 0:b.form)||((w=(v=(x=e.data)==null?void 0:x.config)==null?void 0:v.ports)==null?void 0:w.length),u=d?()=>{var M;c?(M=s.onNodeCollapse)==null||M.call(s,e.data.id,!1):i(!0)}:void 0;return!c&&e.data.type==="text"&&r.getNodeViewMode(e.data.id)==="icon-label"?f.jsx(bo,{...e,renderCompact:void 0,data:{...e.data,config:{...e.data.config,labelBelow:!0,icon:((C=e.data.config)==null?void 0:C.icon)||"PiTextT"}},toggleLabel:"Show text",onExpand:()=>r.restoreNodeView(e.data.id)}):!c&&d&&o?f.jsx(Uo,{...e,editOnMount:t,onShowIcon:()=>i(!1)}):f.jsx(bo,{...e,onOpenView:u&&(c||(E=(S=e.data)==null?void 0:S.config)!=null&&E.labelBelow)?()=>{var M;u(),(M=s.onNodeViewToggle)==null||M.call(s,e.data.id)}:void 0,toggleLabel:!c&&e.data.type==="text"?"Show icon":l,toggleDisabled:c&&a,onExpand:!c&&e.data.type==="text"?()=>r.setNodeViewMode(e.data.id,"icon-label"):u})};function CE(e){var b,x,v,w,C,S;const{config:r,callbacks:t,readOnly:n,selectedNodeIds:o,nodeRadiusPreviews:i,nodeViewModes:s,allNodesIconLabel:a}=Ue(),c=i[e.data.id]??((b=e.data.viewProps)==null?void 0:b.borderRadius),[l,d]=j.useState(!1),u=eo(),{border:h,colorText:p}=at(),m=(x=r.customViews)==null?void 0:x.gridContent,g=(s[e.data.id]??(a?"icon-label":"default"))==="icon-label",y=j.useRef(g);return g&&(y.current=!0),bu(e.data.id,a&&!g&&y.current,()=>u.setNodeViewMode(e.data.id,"icon-label")),g?f.jsx(W.Box,{"data-grid-document":((v=e.data.config)==null?void 0:v.documentId)??"",children:f.jsx(bo,{...e,data:{...e.data,viewProps:{...e.data.viewProps,borderRadius:c},config:{...e.data.config,labelBelow:!0,icon:((w=e.data.config)==null?void 0:w.icon)||"PiGridFour"}},toggleLabel:"Show grid",onExpand:()=>u.restoreNodeView(e.data.id)})}):f.jsxs(f.Fragment,{children:[f.jsx(Qn,{...e,onOpenView:()=>d(!0),children:({data:E,isActive:M})=>{var P,T,k,R,_,N,$,V;return f.jsx(W.Box,{"data-flow-node-surface":"","data-grid-document":((P=E.config)==null?void 0:P.documentId)??"",width:`${((k=(T=E.config)==null?void 0:T.gridSize)==null?void 0:k.width)??600}px`,height:`${((_=(R=E.config)==null?void 0:R.gridSize)==null?void 0:_.height)??440}px`,overflow:"hidden",position:"relative",bg:((N=E.viewProps)==null?void 0:N.bgColor)??"transparent",color:(($=E.viewProps)==null?void 0:$.textColor)??p,borderRadius:`${c??0}px`,...Wn(E.viewProps,Me(((V=E.viewProps)==null?void 0:V.borderColor)??h),M,0),children:m?f.jsx(m,{...e}):f.jsx(W.Box,{p:4,children:E.label??"Grid"})})}}),f.jsx(yu,{nodeAddress:e.data.id,active:o.includes(e.data.id),label:e.data.label??"Grid",open:l&&!n,onClose:()=>d(!1),children:f.jsx($t.Provider,{value:{data:{metadata:{label:e.data.label??"",subtitle:((C=e.data.config)==null?void 0:C.subtitle)??"",icon:((S=e.data.config)==null?void 0:S.icon)??"PiGridFour"}},bindings:{[e.data.id]:{address:"root.metadata",type:"GridMetadata"}},schema:{GridMetadata:{kind:"object",properties:{label:{optional:!0,type:{kind:"string"}},subtitle:{optional:!0,type:{kind:"string"}},icon:{optional:!0,type:{kind:"string"}}}}},editable:!!r.editable&&!n,callbacks:{onFormChange:E=>{var P,T,k;if(n||!r.editable)return;const M=String(E.value??"");E.address==="root.metadata.label"?(P=t.onNodeLabelChange)==null||P.call(t,e.data.id,M):E.address==="root.metadata.subtitle"?(T=t.onNodeSubtitleChange)==null||T.call(t,e.data.id,M):E.address==="root.metadata.icon"&&((k=t.onNodeIconChange)==null||k.call(t,e.data.id,M))}}},children:f.jsx(Vd,{nodeAddress:e.data.id})})})]})}function SE(e){var P;const{callbacks:r,config:t,readOnly:n,themeColor:o,colorMode:i}=Ue(),{canvas:s,background:a,border:c,colorText:l}=at(),d=dv(e.data,o,i),u=j.useRef(),[h,p]=j.useState(!1),[m,g]=j.useState(""),[y,b]=j.useState(1),[x,v]=j.useState(),w=typeof((P=e.data.config)==null?void 0:P.content)=="string"?e.data.config.content:"",C=x??w,S=!n&&t.editable!==!1&&!h&&!!r.onPromptSubmit&&!!C.trim(),E=S?s:a;j.useEffect(()=>v(void 0),[w]),j.useEffect(()=>()=>{var T;return(T=u.current)==null?void 0:T.abort()},[]);const M=async(T=C)=>{if(u.current||n||t.editable===!1||!T.trim()||!r.onPromptSubmit)return;const k=new AbortController;u.current=k,p(!0),g("");try{await r.onPromptSubmit({nodeId:e.data.id,prompt:T,temperature:y},k.signal)}catch(R){k.signal.aborted||g(R instanceof Error?R.message:"Prompt execution failed.")}finally{u.current===k&&(u.current=void 0,p(!1))}};return f.jsx(Uo,{...e,contentProps:{px:8,py:6,minH:"200px",flexShrink:0,overscrollBehavior:"contain"},contentPlainText:!0,onContentDraftChange:v,onContentSubmit:!h&&r.onPromptSubmit?T=>void M(T):void 0,data:{...e.data,viewProps:{...e.data.viewProps,containerType:"inline-size"},config:{...e.data.config,content:w,contentFormat:"markdown"}},footer:f.jsxs(W.Box,{"data-prompt-controls":"",background:d.highlightColor,flexShrink:0,width:"100%",pl:8,pr:4,pt:1,pb:4,onPointerDown:T=>T.stopPropagation(),onClick:T=>T.stopPropagation(),css:{"@container (max-width: 300px)":{paddingLeft:"16px"},'& [role="combobox"] > svg':{width:"32px",height:"32px"},'& [role="option"]':{fontSize:"28px"},'& [role="option"] svg':{width:"32px",height:"32px"}},children:[m&&f.jsx(W.Text,{role:"alert",fontSize:"sm",color:"red.500",children:m}),f.jsxs(W.HStack,{justifyContent:"space-between",alignItems:"center",gap:3,children:[f.jsxs(W.HStack,{minW:0,gap:2,flexWrap:"wrap",color:d.hextextColor,children:[f.jsx(W.Text,{fontSize:"32px",lineHeight:"1.15",fontWeight:"bold",children:"Thinking effort"}),f.jsxs(It,{"aria-label":"Thinking effort",value:String(y),disabled:n||t.editable===!1||h||!r.onPromptSubmit,style:{width:"176px",height:"60px",flexShrink:0,fontSize:"32px",color:d.hextextColor},onValueChange:T=>b(Number(T)),children:[f.jsx("option",{value:"0",children:"Low"}),f.jsx("option",{value:"1",children:"Mid"}),f.jsx("option",{value:"2",children:"Max"})]})]}),f.jsx(Ge,{label:h?"Cancel prompt":r.onPromptSubmit?"Run prompt":"Prompt execution is not connected",children:f.jsx(Ne,{"aria-label":h?"Cancel prompt":"Run prompt","aria-busy":h,variant:"ghost",rounded:"50%",width:"80px",minWidth:"80px",height:"80px",flexShrink:0,mr:"2px",bg:E,color:l,_hover:{bg:E,color:l},_active:{bg:E},css:{...gr(`var(--chakra-colors-${E.replace(".","-")})`,`var(--chakra-colors-${c.replace(".","-")})`),"& > svg":{width:"40px",height:"40px"}},icon:h?f.jsx(Q.PiStop,{size:40}):f.jsx(Q.PiPaperPlaneRight,{size:40}),disabled:n||t.editable===!1||!h&&!S,rememberAction:!1,onClick:()=>{var T;return h?(T=u.current)==null?void 0:T.abort():void M()}})})]})]})})}const hv=e=>f.jsx(fv,{...e,renderCompact:hE}),pv=e=>f.jsx(fv,{...e}),gv=({containerStyle:e,...r})=>{const{selectedNodeIds:t}=Ue();return f.jsx(Qn,{...r,editOnMount:t.includes(r.data.id),children:n=>f.jsx(W.Box,{bg:e.textColor==="transparent"?"transparent":e.labelBg,p:`${e.fontSize/5}px`,fontFamily:_r,lineHeight:1,w:"fit-content",children:f.jsx(cn,{nodeId:n.id,label:n.data.label??n.data.headerTitle??"Container",color:e.textColor,fontSize:`${e.fontSize}px`,isEditing:n.isEditing,onEditStart:n.onEditStart,onEditEnd:n.onEditEnd})})})};hv.displayName="text";pv.displayName="arrayView";gv.displayName="ParentContainerView";const jE={grid:CE,prompt:SE,objectView:Uo,arrayView:pv,text:hv,parentContainer:gv},EE=({children:e,pattern:r="dot",backgroundColor:t})=>{const{colorMode:n}=Ue(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",s=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return r==="none"?f.jsx(W.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:t,children:e}):f.jsxs(W.Box,{"data-flow-background":r,position:"relative",width:"100%",height:"100%",padding:0,bg:t,children:[f.jsx(W.Box,{position:"absolute",top:0,left:0,right:0,bottom:0,width:"100%",height:"100%",zIndex:0,pointerEvents:"none",style:{backgroundImage:r==="dot"?`radial-gradient(var(${i}) 8%, transparent 8%)`:r==="steel"?`repeating-linear-gradient(45deg, var(${s}) 0, var(${s}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${s}) 1px, transparent 1px), linear-gradient(90deg, var(${s}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),f.jsx(W.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},_E=.4,qr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},kE=({nodes:e,edges:r})=>{var ur;const{themeColor:t,spacing:n,edgeRadius:o,backgroundVariant:i,backgroundSelected:s,setBackgroundSelected:a,edgeColor:c,direction:l,nodeAlignment:d,edgeMode:u,compactPropertyLayout:h,workflowContract:p,parentNodeStyle:m,engineRef:g,callbacks:y,config:b,selectedNodeIds:x,setSelectedNodeIds:v,selectedEdgeId:w,setSelectedEdgeId:C,setIsPerformanceMode:S,setNodeGridOptions:E,fillRadiusEditedIds:M,isZoomMode:P,setIsZoomMode:T,isMultiSelectMode:k,setIsMultiSelectMode:R,isDragMode:_,setIsDragMode:N,isEdgeHandlesEnabled:$,setIsEdgeHandlesEnabled:V,isArrayNodeMode:I}=Ue(),F=j.useRef(null),[oe,se]=j.useState(null),H=j.useRef(null),ee=e.length>200;j.useEffect(()=>{S(ee)},[ee,S]);const{edgeSep:ue,rankSep:q,spacingFactor:D}=j.useMemo(()=>{const z=o1(e.length),O=b.nodeGridSpacing==="layout"&&n<.5?n*1.3:n<1?.3+.7*n:.5+.5*n;return{edgeSep:z.edgeSep*O,rankSep:z.rankSep*O,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n,b.nodeGridSpacing]),{bgColor:K}=Gn(t),{canvas:G,borderSecondary:ce,colorText:re}=at(),Z=i==="transparent"?"transparent":b.backgroundColor||G,ae=j.useCallback(z=>{if(!z)return Me(t);switch(z){case"dark":return Me(Z);case"light":return Me(ce);default:return Me(z)}},[t,Z,ce]),ye=b.colorMode==="dark",xe=ye?Me("gray.500"):ln,fe=ye?K!=null&&K.includes("gray")?"whitesmoke":ae(K):xe,U=c?ae(c):xe,te=j.useMemo(()=>{var z;return b.initialViewport||{pan:{x:0,y:0},zoom:(z=b.nodeGrid)!=null&&z.enabled&&b.nodeGrid.options.fill?1:.01}},[]),de=l==="C"?"LR":l,Pe=j.useCallback(z=>{const O={...m,...z};return{...O,bgColor:O.bgColor||t,bgOpacity:O.outline?0:O.bgOpacity??_E}},[m,t]),ie=j.useMemo(()=>{var O;const z=new Map;for(const ne of e)(O=ne.data)!=null&&O.id&&z.set(ne.data.id,ne);return z},[e]),we=j.useMemo(()=>{var O;const z=new Map;for(const ne of r)(O=ne.data)!=null&&O.id&&z.set(ne.data.id,ne);return z},[r]),$e=j.useCallback(z=>{var je;const O=(je=ie.get(z))==null?void 0:je.data,ne=Pe(O==null?void 0:O.viewProps),ge=Me(ne.bgColor);return{animated:!!(O!=null&&O.isNodeAnimated)&&!ee,animationVariant:O==null?void 0:O.nodeAnimationVariant,animationColor:Me(ne.borderColor||t),bgColor:ne.outline?"transparent":ge,bgOpacity:ne.bgOpacity,borderColor:ne.borderColor?Me(ne.borderColor):ne.outline&&ne.bgColor==="transparent"?Me(t):ge,borderWidth:Dn(ne.borderWidth,qr.borderWidth),borderStyle:ne.borderStyle??qr.borderStyle,borderRadius:ne.borderRadius??qr.borderRadius,textColor:ne.textColor?Me(ne.textColor):ne.outline||ne.bgColor==="transparent"?Me(re):ge,fontSize:ne.fontSize??qr.fontSize,labelPosition:ne.labelPosition??qr.labelPosition,labelMargin:qr.labelMargin,labelBg:Fu(ae("dark"),ge,ne.bgOpacity)??ae("dark"),padding:ne.padding??qr.padding}},[Pe,ie,re,t,ee,ae]),He=j.useMemo(()=>{var ne,ge;const z=new Map;for(const je of r){const Te=(ne=je.data)==null?void 0:ne.source,Re=(ge=je.data)==null?void 0:ge.target;if(!Te||!Re||Te===Re)continue;const Ye=Te<Re?`${Te}|${Re}`:`${Re}|${Te}`,et=z.get(Ye);et?et.push({id:je.data.id,source:Te}):z.set(Ye,[{id:je.data.id,source:Te}])}const O=new Map;for(const[je,Te]of z){if(Te.length<2)continue;const Re=je.split("|")[0],Ye=Math.min(20,70/Te.length);Te.forEach(({id:et,source:Fe},ct)=>{const ht=50+(ct-(Te.length-1)/2)*Ye;O.set(et,(Fe===Re?ht:100-ht)/100)})}return O},[r]),Ve=j.useMemo(()=>{const z=ae("dark");return r.filter(O=>{var ne;return((ne=O.data)==null?void 0:ne.id)&&O.data.source&&O.data.target}).map(({data:O})=>{var Te,Re,Ye,et,Fe,ct;let ne=z;const ge=(Re=(Te=ie.get(O.source))==null?void 0:Te.data)==null?void 0:Re.parent,je=(et=(Ye=ie.get(O.target))==null?void 0:Ye.data)==null?void 0:et.parent;if(ge&&ge===je){const ht=Pe((ct=(Fe=ie.get(ge))==null?void 0:Fe.data)==null?void 0:ct.viewProps),wt=Fu(z,Me(ht.bgColor),ht.bgOpacity);wt&&(ne=wt)}return{id:O.id,data:O,type:O.type??b.edgeType??"rounded-orthogonal",source:O.source,target:O.target,sourceProperty:O.sourceProperty,targetProperty:O.targetProperty,label:O.label,validationIssue:(u==="auto"||u==="properties")&&(O.sourceProperty!==void 0||O.targetProperty!==void 0)&&p?Dd(p,O):void 0,color:c?U:O.color?Me(O.color):U,connectorColor:c?U:O.color?Me(O.color):fe,labelBg:ne,dashed:!!O.isEdgeDashed,animated:!!O.isEdgeAnimated,inverted:!!O.isInverted,turn:He.get(O.id)??.5}})},[r,U,fe,c,He,b.edgeType,u,p,ie,Pe,ae]),tt=j.useMemo(()=>{var O;const z=new Set;for(const ne of e)(O=ne.data)!=null&&O.parent&&z.add(ne.data.parent);return z},[e]),me=j.useMemo(()=>{const z=new Map;for(const O of r){const ne=O.data.isInverted?O.data.target:O.data.source;ne&&!z.has(ne)&&z.set(ne,O.data)}for(const O of r){if(O.data.connection)continue;const ne=O.data.isInverted?O.data.target:O.data.source,ge=O.data.isInverted?O.data.source:O.data.target;ge.startsWith(`${ne}.`)&&(z.set(ne,O.data),z.set(ge,O.data))}return z},[r]),Ie=j.useMemo(()=>{const z={...jE,...b.customViews};return e.filter(O=>{var ne;return(ne=O.data)==null?void 0:ne.id}).map(O=>{var et,Fe,ct,ht,wt,St,Rt,Mt,pt;const ne=tt.has(O.data.id)&&!O.data.parent,ge=ne&&O.data.type!=="prompt"?O.data.label??O.data.headerTitle??"Container":void 0,je=O.data.type==="prompt"?z.prompt:ne?z.parentContainer:z[O.data.type]||z.text,Te=((et=b.customViews)==null?void 0:et.fillNode)??je,Re=me.get(O.data.id),Ye={...O,isInverted:((Fe=O.data.config)==null?void 0:Fe.isInverted)??(Re==null?void 0:Re.isInverted),isParent:ne,containerStyle:ne?$e(O.data.id):void 0};return{id:O.data.id,collapsed:(ct=O.data.config)==null?void 0:ct.collapsed,parent:O.data.parent,acceptsChildren:!!((ht=O.data.config)!=null&&ht.parentContainer)||tt.has(O.data.id),label:ge,animated:!!O.data.isNodeAnimated,animationVariant:O.data.nodeAnimationVariant,hasCollapseControl:((wt=O.data.config)==null?void 0:wt.collapsed)!==void 0,animationColor:Me(((St=O.data.viewProps)==null?void 0:St.borderColor)||t),animationWidth:Dn((Rt=O.data.viewProps)==null?void 0:Rt.borderWidth,8),element:j.createElement(je,{...Ye,key:`${O.data.id}-${t}`}),fillElement:M.has(O.data.id)&&!((Mt=b.customViews)!=null&&Mt.fillNode)?void 0:j.createElement(Te,{...Ye,...(pt=b.customViews)!=null&&pt.fillNode?{renderNode:je}:{},data:{...O.data,viewProps:M.has(O.data.id)?O.data.viewProps:{...O.data.viewProps,borderRadius:0}},containerStyle:Ye.containerStyle&&!M.has(O.data.id)?{...Ye.containerStyle,borderRadius:0}:Ye.containerStyle,key:`${O.data.id}-${t}`})}})},[e,tt,me,t,b.customViews,$e,M]),De=j.useMemo(()=>ee?300:e.length>50?150:e.length>20?100:50,[e.length,ee]),be=j.useRef(b);be.current=b;const Xe=j.useRef(P);Xe.current=P;const ut=j.useRef(I);ut.current=I;const Ae=j.useRef(x);Ae.current=x;const Ke=j.useRef(w);Ke.current=w;const lt=j.useRef(k);lt.current=k;const Je=j.useRef(ie);Je.current=ie;const yt=j.useRef(we);yt.current=we;const At=j.useRef(new Map);j.useEffect(()=>{var ne,ge;const z=new Map([...we].filter(([,je])=>ie.has(je.data.source)&&ie.has(je.data.target))),O=At.current;At.current=z;for(const[je,Te]of O)z.has(je)||(Ke.current===je&&(C(null),(ne=y.onEdgeDeselect)==null||ne.call(y)),(ge=y.onEdgeRemove)==null||ge.call(y,je,Te.data))},[we,ie,y,C]),j.useEffect(()=>{const z=F.current;if(!oe||!z)return;let O=null,ne=null,ge=0,je=0,Te=0,Re=0,Ye=0;const et=Fe=>{var wt;if(be.current.readOnly||be.current.minZoom===be.current.maxZoom&&be.current.minZoom!==void 0&&((wt=z.parentElement)!=null&&wt.closest(".flow-sdk-canvas")))return;const ct=z.ownerDocument.fullscreenElement;if(ct&&ct!==z&&z.contains(ct)&&Fe.target instanceof Node&&ct.contains(Fe.target))return;Fe.preventDefault(),Fe.stopPropagation(),Xe.current||Fe.metaKey||Fe.ctrlKey?(Te+=Fe.deltaY,Re=Fe.clientX,Ye=Fe.clientY,ne===null&&(ne=requestAnimationFrame(()=>{ne=null;const St=be.current,Rt=oe.zoom(),Mt=Te;Te=0;let pt=Rt-Mt*.05/100;pt=Math.max(St.minZoom??.01,Math.min(St.maxZoom??1.5,pt));const mt=z.getBoundingClientRect();oe.zoomAt(pt,{x:Re-mt.left,y:Ye-mt.top})}))):(ge+=Fe.deltaX,je+=Fe.deltaY,O===null&&(O=requestAnimationFrame(()=>{O=null;const St=oe.pan(),Rt=oe.zoom(),Mt=.35,pt=ge,mt=je;ge=0,je=0,oe.pan({x:St.x+-pt*Mt/Rt,y:St.y+-mt*Mt/Rt})})))};return z.addEventListener("wheel",et,{passive:!1}),()=>{z.removeEventListener("wheel",et),O!==null&&cancelAnimationFrame(O),ne!==null&&cancelAnimationFrame(ne)}},[oe]),j.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const z=O=>{var ge,je,Te,Re,Ye,et;if(be.current.readOnly)return;const ne=O.target;if(!(ne.tagName==="INPUT"||ne.tagName==="TEXTAREA"||ne.isContentEditable)){if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(O.key)){const Fe=F.current,ct=g.current,ht=Fe==null?void 0:Fe.querySelector(".flow-sdk-canvas");if(!Fe||!ht||!ct||ne!==Fe&&(ne.closest(".flow-sdk-canvas")!==ht||!ne.closest(".flow-sdk-node")||ne.querySelector(":scope > .flow-sdk-canvas")||ne.closest('button, input, textarea, select, a, [contenteditable], [role="button"], [role="textbox"], [role="combobox"], [role="slider"], [role="spinbutton"], [data-flow-content]'))||O.defaultPrevented||O.isComposing||O.shiftKey||O.ctrlKey||O.metaKey||O.altKey||lt.current||Ae.current.length>1||ht.querySelector("[data-grid-dragging], .flow-sdk-ghost, .flow-sdk-box")||Array.from(document.querySelectorAll('dialog[open], :popover-open, [role="dialog"], [role="menu"], [role="listbox"]')).some(Ft=>Ft.getClientRects().length>0&&getComputedStyle(Ft).visibility!=="hidden"))return;const wt=ht.getBoundingClientRect();if(!wt.width||!wt.height)return;const St=ct.clientToModel(wt.left+wt.width/2,wt.top+wt.height/2),Rt=Ae.current[0],Mt=Rt&&ct.getNodeBox(Rt)||St,pt=O.key==="ArrowLeft"||O.key==="ArrowRight",mt=O.key==="ArrowLeft"||O.key==="ArrowUp"?-1:1;let vt;for(const Ft of ht.querySelectorAll(".flow-sdk-node")){if(Ft.closest(".flow-sdk-canvas")!==ht)continue;const it=Ft.getAttribute("data-node-id");if(!it||it===Rt||!Je.current.has(it))continue;const br=Ft.getBoundingClientRect(),Ir=getComputedStyle(Ft);if(!br.width||!br.height||Ir.visibility==="hidden"||Ir.opacity==="0")continue;const fr=ct.getNodeBox(it);if(!fr)continue;const mn=fr.x-Mt.x,bn=fr.y-Mt.y;if((pt?mn:bn)*mt<=.01)continue;const Zr=Math.hypot(mn,bn);(!vt||Zr<vt.distance)&&(vt={id:it,box:fr,distance:Zr})}if(O.preventDefault(),O.stopPropagation(),!vt)return;Ke.current&&(C(null),(ge=y.onEdgeDeselect)==null||ge.call(y)),v([vt.id]),(je=y.onNodeSelect)==null||je.call(y,vt.id,Je.current.get(vt.id).data,{shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1,keyboardNavigation:!0});const er=ct.pan(),tr=ct.zoom();ct.pan({x:er.x+(St.x-vt.box.x)*tr,y:er.y+(St.y-vt.box.y)*tr},!0);return}if((O.key==="z"||O.key==="Z")&&T(!Xe.current),(O.key==="m"||O.key==="M")&&R(!k),(O.key==="d"||O.key==="D")&&N(!_),(O.key==="v"||O.key==="V")&&!O.repeat&&!O.metaKey&&!O.ctrlKey&&!O.altKey&&ne.tagName!=="SELECT"&&V(!$),(O.key==="Delete"||O.key==="Backspace")&&Ke.current){O.preventDefault();const Fe=Ke.current;(Re=y.onEdgeDelete)==null||Re.call(y,Fe,((Te=yt.current.get(Fe))==null?void 0:Te.data)??{id:Fe}),C(null);return}if((O.key==="Delete"||O.key==="Backspace")&&Ae.current.length>0){O.preventDefault();const Fe=Ae.current.filter(ct=>ct!=="root");if(Fe.length===0)return;for(const ct of Fe){const ht=(Ye=Je.current.get(ct))==null?void 0:Ye.data;(et=y.onNodeDelete)==null||et.call(y,ct,ht||{})}v([])}}};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[k,_,$,V,T,R,N,b.disableKeyboardShortcuts,y,v,C]);const Jr=j.useCallback(z=>{var O;g.current=z,se(z),(O=y.onInit)==null||O.call(y,z)},[g,y]),Tr=j.useCallback(z=>{var O;return(O=y.onViewportChange)==null?void 0:O.call(y,z)},[y]),rt=j.useCallback(z=>{var ne,ge,je;const O=((ne=yt.current.get(z))==null?void 0:ne.data)??{id:z};if(Ke.current===z&&lt.current){C(null),(ge=y.onEdgeDeselect)==null||ge.call(y);return}Ae.current.length&&v([]),C(z),(je=y.onEdgeSelect)==null||je.call(y,z,O)},[y,C,v]),We=j.useCallback(()=>{var z,O,ne,ge,je,Te;if((z=F.current)==null||z.focus({preventScroll:!0}),a(b.bottomBarCollapsed??(Ae.current.length>0||!!Ke.current||!s)),(O=y.onBackgroundClick)==null||O.call(y),!be.current.readOnly){const Re=new Set;for(const Ye of Ae.current){let et=Je.current.get(Ye);for(;et&&!Re.has(et.data.id);)Re.add(et.data.id),tt.has(et.data.id)&&((ne=et.data.config)==null?void 0:ne.collapsed)!==!0&&((ge=y.onNodeCollapse)==null||ge.call(y,et.data.id,!0)),et=et.data.parent?Je.current.get(et.data.parent):void 0}}Ae.current.length&&(v([]),(je=y.onNodeDeselect)==null||je.call(y)),Ke.current&&(C(null),(Te=y.onEdgeDeselect)==null||Te.call(y))},[y,v,C,a,s,b.bottomBarCollapsed,tt]);j.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const z=O=>{const ne=F.current,ge=ne==null?void 0:ne.querySelector(".flow-sdk-canvas"),je=O.target;O.key!=="Escape"||O.defaultPrevented||O.repeat||O.isComposing||O.ctrlKey||O.metaKey||O.altKey||O.shiftKey||be.current.readOnly||!Ae.current.length||!ne||!ge||!ne.getClientRects().length||document.fullscreenElement||ge.querySelector("[data-grid-dragging], .flow-sdk-ghost, .flow-sdk-box")||je instanceof Element&&(je.closest('input, textarea, select, [contenteditable], [role="textbox"], [role="combobox"], dialog, [role="dialog"], [role="menu"], [role="listbox"], [popover]')||je!==document.body&&!ne.contains(je)||je.closest(".flow-sdk-canvas")&&je.closest(".flow-sdk-canvas")!==ge)||Array.from(document.querySelectorAll('dialog[open], :popover-open, [role="dialog"], [role="menu"], [role="listbox"]')).some(Te=>Te.getClientRects().length>0&&getComputedStyle(Te).visibility!=="hidden")||(O.preventDefault(),O.stopPropagation(),We())};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)},[b.disableKeyboardShortcuts,We]);const Qt=j.useCallback(z=>{var ge,je;const O=Ae.current,ne=z.filter(Te=>!O.includes(Te));if(ne.length){v([...O,...ne]);for(const Te of ne)(je=y.onNodeSelect)==null||je.call(y,Te,((ge=Je.current.get(Te))==null?void 0:ge.data)??{id:Te})}},[y,v]),ft=j.useCallback((z,O)=>{var ne,ge;v([z]),(ge=y.onNodeSelect)==null||ge.call(y,z,((ne=Je.current.get(z))==null?void 0:ne.data)??{id:z},O)},[y,v]),qt=j.useRef(null),dr=j.useCallback((z,O,ne)=>{var ge;qt.current={source:z,target:O,edgeIds:new Set(yt.current.keys())};try{(ge=y.onEdgeCreate)==null||ge.call(y,z,O,ne)}catch(je){throw qt.current=null,je}},[y]),Be=j.useCallback((z,O,ne,ge=!1)=>{var je,Te;if(H.current={sourceId:z,nodeIds:new Set(Je.current.keys()),reverse:ge},!(u==="properties"&&((je=y.onNodeCreateRequest)==null?void 0:je.call(y,{sourceNodeId:z,position:O,sourceProperty:ne,reverse:ge}))===!0)){if(ne!==void 0||ge){H.current=null;return}(Te=y.onNodeCreate)==null||Te.call(y,{type:"text",sourceNodeId:z,position:O,isArrayMode:ut.current})}},[y,u]),Ht=!b.readOnly&&$&&b.edgeHandles!==!1,Lt=i==="transparent"?"none":i;return f.jsx(EE,{pattern:Lt,backgroundColor:Z,children:f.jsx(W.Box,{ref:F,tabIndex:0,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:f.jsx(iE,{nodes:Ie,edges:Ve,direction:de,nodeAlignment:d,onContainerCollapse:z=>{var O,ne;(O=y.onNodeCollapse)==null||O.call(y,z,!0),(ne=y.onNodeViewToggle)==null||ne.call(y,z)},selectedNodeIds:x,edgeMode:u,compactPropertyLayout:h,edgeType:b.edgeType,edgeRadius:o,customEdgeTypes:b.customEdgeTypes,edgeReveal:b.disableAnimations?void 0:b.edgeReveal,rankSep:q,edgeSep:ue,nodeGridSpacing:b.nodeGridSpacing,nodeGridConnections:b.nodeGridConnections,initialNodeGrid:b.nodeGrid,spacingFactor:D,compactSpacingScale:n,layoutDebounce:De,isPerformanceMode:ee,minZoom:b.minZoom??.01,maxZoom:b.maxZoom??1.5,initialViewport:te,fixedNodePositions:b.fixedNodePositions,onFixedNodePositionsChange:y.onFixedNodePositionsChange,fitOnInit:!b.initialViewport&&!((ur=b.nodeGrid)!=null&&ur.enabled&&b.nodeGrid.options.fill),readOnly:!!b.readOnly,containerStyle:$e,lineColor:c?U:fe,drawMode:Ht,drawHandles:!b.readOnly&&b.edgeHandles!==!1,dragMode:_,multiSelect:!!k,onInit:Jr,onLayoutComplete:z=>{var Te;(Te=y.onLayoutComplete)==null||Te.call(y,z);const O=qt.current;O&&(!Je.current.has(O.source)||!Je.current.has(O.target)?qt.current=null:r.some(({data:Re})=>Re.source===O.source&&Re.target===O.target&&!O.edgeIds.has(Re.id))&&z.getNodeBox(O.source)&&z.getNodeBox(O.target)&&(qt.current=null,z.focusConnections(O.source)));const ne=H.current;if(!ne)return;if(!Je.current.has(ne.sourceId)){H.current=null;return}const je=e.filter(Re=>!ne.nodeIds.has(Re.data.id)).filter(Re=>r.some(({data:Ye})=>Ye.source===ne.sourceId&&Ye.target===Re.data.id||Ye.target===ne.sourceId&&Ye.source===Re.data.id));!je.length||je.some(Re=>!z.getNodeBox(Re.data.id))||(H.current=null,z.focusBranch(ne.reverse?je[0].data.id:ne.sourceId))},onNodeGridModeChange:E,onNodeGridZoomOut:y.onNodeGridZoomOut,onNodeGridDrop:y.onNodeGridDrop,onNodeParentChange:y.onNodeParentChange,animateViewport:b.animateViewport,disableAnimations:b.disableAnimations,onViewportChange:Tr,onBackgroundTap:We,onBoxSelect:Qt,onEdgeSelect:rt,onContainerSelect:ft,onEdgeDraw:dr,onDrawIntoSpace:Be})})})},yv=j.memo(kE),PE=".flow-sdk-canvas{position:relative;width:100%;height:100%;overflow:clip;user-select:none;-webkit-user-select:none;touch-action:none}.flow-sdk-svg{position:absolute;top:0;left:0;width:100%;height:100%;overflow:visible;display:block}.flow-sdk-nodes{position:absolute;top:0;left:0;transform-origin:0 0;pointer-events:none;will-change:transform;backface-visibility:hidden;z-index:10}.flow-sdk-node{position:absolute;top:0;left:0;transform-origin:0 0;pointer-events:auto;will-change:transform;backface-visibility:hidden;z-index:10}.flow-sdk-node input,.flow-sdk-node textarea{pointer-events:auto;user-select:text;-webkit-user-select:text;cursor:text}.flow-sdk-edge-hit{fill:none;stroke:transparent;stroke-width:24px;vector-effect:non-scaling-stroke;pointer-events:stroke;cursor:pointer}.flow-sdk-container{cursor:pointer}.flow-sdk-edge-anim{animation:flow-sdk-dash .5s linear infinite}.flow-sdk-edge-anim-rev{animation-direction:reverse}@keyframes flow-sdk-dash{to{stroke-dashoffset:-50}}.flow-sdk-draw{cursor:crosshair}.flow-sdk-draw .flow-sdk-node,.flow-sdk-draw .flow-sdk-node input,.flow-sdk-draw .flow-sdk-node textarea,.flow-sdk-draw .flow-sdk-edge,.flow-sdk-draw .flow-sdk-container{pointer-events:none}.flow-sdk-perf.flow-sdk-busy .flow-sdk-edges{display:none}.flow-sdk-box{position:absolute;border:1px solid rgba(170,170,170,.9);background:rgba(221,221,221,.25);pointer-events:none;z-index:20}";let Tm=!1;function AE(){if(Tm||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=PE+".flow-sdk-canvas[data-node-grid] .flow-sdk-node,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *::before,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *::after{animation:none!important;transition:none!important}.flow-sdk-node[data-grid-fill] [data-flow-icon-label]{--flow-grid-caption-color:var(--flow-grid-on-surface-color)}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]{border:0;outline:none;box-shadow:none}.flow-sdk-node[data-grid-fill]{box-sizing:border-box}.flow-sdk-node[data-grid-fill] :not(svg):has([data-flow-node-surface]),.flow-sdk-node[data-grid-fill]>:not(svg):not(button){width:100%;height:100%;min-width:0;max-width:none}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]{width:100%;height:100%;min-width:0;max-width:none;box-sizing:border-box;overflow:hidden}.flow-sdk-node[data-grid-fill] [data-flow-icon-label]{gap:0}.flow-sdk-node[data-grid-fill] [data-flow-icon-caption]{position:absolute;bottom:12px;left:12px;width:calc(100% - 24px);max-height:40%;overflow:hidden}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]>svg{max-width:45%;max-height:55%}.flow-sdk-node[data-grid-fill] p{font-size:var(--flow-grid-font);white-space:normal;overflow-wrap:anywhere}.flow-sdk-canvas[data-node-grid]:not([data-grid-connections]) .flow-sdk-property-port,.flow-sdk-canvas[data-node-grid]:not([data-grid-connections]) .flow-sdk-handle,.flow-sdk-canvas[data-node-grid] [data-flow-collapse-control]{display:none}.flow-sdk-node[data-grid-draggable] :not(button):not(input):not(textarea):not(select):not(a){cursor:inherit}"+Hb+r1+e1+".flow-sdk-handle{position:absolute;left:-36px;top:50%;transform:translateY(-50%);width:36px;height:36px;display:grid;place-items:center;border:2px solid currentColor;border-radius:50%;background:white;cursor:crosshair;opacity:0;pointer-events:none}.flow-sdk-node:hover>.flow-sdk-handle,.flow-sdk-handle:focus-visible{opacity:1;pointer-events:auto}.flow-sdk-draw .flow-sdk-node *,.flow-sdk-draw .flow-sdk-edge *,.flow-sdk-draw .flow-sdk-container *,.flow-sdk-ghost *{pointer-events:none}",document.head.appendChild(e),e.textContent+=".flow-sdk-draw .flow-sdk-node{pointer-events:auto}.flow-sdk-draw .flow-sdk-node>.flow-sdk-handle{opacity:0;pointer-events:none}.flow-sdk-draw .flow-sdk-node:hover>.flow-sdk-handle,.flow-sdk-draw .flow-sdk-node>.flow-sdk-handle:focus-visible{opacity:1;pointer-events:auto}",e.textContent+='.flow-sdk-property-port{position:absolute;transform:translateY(-50%);width:32px;height:32px;margin:0;padding:0;border:3px solid currentColor;border-radius:50%;background:white;cursor:crosshair;pointer-events:auto;z-index:20}.flow-sdk-property-port[data-port-role="source"]{background:currentColor}.flow-sdk-property-port:hover{outline:3px solid currentColor;outline-offset:3px}.flow-sdk-draw .flow-sdk-node .flow-sdk-property-port{pointer-events:auto}',Tm=!0}function RE({loading:e=!1,loader:r,...t}){var c,l;const[n,o]=j.useState(null),i=j.useMemo(()=>!!(n!=null&&n.json)&&!!t.json&&Zw(n.json,t.json),[n==null?void 0:n.json,t.json]),s=n===null||n.json!==t.json&&!i,a=e||s;return j.useEffect(()=>{!e&&i&&(n==null?void 0:n.json)!==t.json&&o(t)},[e,i,n==null?void 0:n.json,t.json]),j.useEffect(()=>{if(e||!s)return;let d;const u=requestAnimationFrame(()=>{d=requestAnimationFrame(()=>o(t))});return()=>{cancelAnimationFrame(u),d!==void 0&&cancelAnimationFrame(d)}},[e,s,t.json]),f.jsxs(W.Box,{className:t.className,style:t.style,width:"100%",height:"100%",position:"relative","aria-busy":a,children:[f.jsx("div",{style:{width:"100%",height:"100%"},ref:d=>{var h;const u=(d==null?void 0:d.contains(document.activeElement))&&((h=document.activeElement)==null?void 0:h.matches("input, textarea, [contenteditable=true]"));a&&(e||!u)?d==null||d.setAttribute("inert",""):d==null||d.removeAttribute("inert")},children:n&&f.jsx(ME,{...s?n:t,children:t.children,config:t.config,className:void 0,style:void 0})}),a&&r!==null&&f.jsx(W.Box,{"data-flow-loader":"",role:"status","aria-label":"Loading diagram",position:"absolute",inset:0,zIndex:1e3,display:"grid",placeItems:"center",background:((c=t.config)==null?void 0:c.colorMode)==="dark"?"gray.800":"gray.100",color:((l=t.config)==null?void 0:l.colorMode)==="dark"?"whiteAlpha.800":"blackAlpha.800",children:r===void 0?f.jsx("span",{children:"Loading diagram..."}):r})]})}function ME({title:e="untitled",json:r,forms:t,nodes:n,edges:o,config:i={},callbacks:s={},className:a,style:c,showBottomBar:l=!0,children:d}){AE();const[u,h]=j.useState(),[p,m]=j.useState(!1),g=i.formSchema??u,y=j.useMemo(()=>r&&t?Eb(r,t.state):r,[r,t==null?void 0:t.state]),b=i.direction==="C",x=j.useMemo(()=>{let k,R;return _=>(R=k&&R?Xw(k,_,R)??Sd(_,{title:e,isCenter:b}):Sd(_,{title:e,isCenter:b}),k=_,R)},[e,b]),v=j.useMemo(()=>y?x(y):null,[y,x]),w=j.useMemo(()=>t!=null&&t.structured&&!p&&g?_b(t.state,t.bindings,g,(v==null?void 0:v.nodes)??n??[]):void 0,[t==null?void 0:t.structured,p,t==null?void 0:t.state,t==null?void 0:t.bindings,g,v,n]),C=(w==null?void 0:w.schema)??g,S=(w==null?void 0:w.bindings)??(t==null?void 0:t.bindings),E=j.useMemo(()=>[...(v==null?void 0:v.nodes)??n??[],...(w==null?void 0:w.nodes)??[]].map(R=>{var oe,se,H,ee;const _=r?(oe=Oe(r,R.data.id))==null?void 0:oe.$view:(se=R.data.config)==null?void 0:se.typeView,N=_&&Ld.includes(_)?_:void 0,$=N?N==="icon-label":(H=R.data.config)==null?void 0:H.labelBelow,V=N==="object"?"objectView":N==="text"?"text":$?"arrayView":R.data.type,I=C&&(t?Hn(S,R.data.id,C):r&&un(r,R.data.id,C)),F=(((ee=R.data.config)==null?void 0:ee.ports)??[]).map(ue=>({...ue}));if(w&&I){const ue=i.direction==="RL"?{input:"right",output:"left",config:"bottom",error:"top"}:i.direction==="TB"?{input:"top",output:"bottom",config:"right",error:"left"}:i.direction==="BT"?{input:"bottom",output:"top",config:"left",error:"right"}:{input:"left",output:"right",config:"top",error:"bottom"};for(const[q,D]of Object.entries(I.type.ports??{})){const K=`${D.kind}:${q}`,G=F.find(ce=>ce.id===K);G?G.label===void 0&&D.label!==void 0&&(G.label=D.label):F.push({id:K,...D.label!==void 0?{label:D.label}:{},role:D.kind==="input"||D.kind==="config"?"target":"source",side:ue[D.kind],...D.kind==="config"?{placement:"config"}:{}})}for(const q of F){const D=F.filter(K=>K.side===q.side);q.position=(D.indexOf(q)+1)/(D.length+1)}}return I||$||N?{...R,data:{...R.data,type:V,...t?{description:Object.fromEntries(Object.entries(R.data.description??{}).filter(([ue])=>!ue.startsWith("$")&&!(w!=null&&w.slots.has(En(R.data.id,ue)))))}:{},config:{...R.data.config,...w&&I?{ports:F}:{},...I?{form:!0}:{},...N?{typeView:N,labelBelow:!!$}:$?{labelBelow:!0}:{}}}}:R}),[v,n,r,C,S,w,i.direction]),M=j.useMemo(()=>[...(v==null?void 0:v.edges)??o??[],...(w==null?void 0:w.edges)??[]],[v==null?void 0:v.edges,o,w==null?void 0:w.edges]),P=j.useMemo(()=>{const k=r&&v?Gb(r,v.edges,s,s.onJsonChange,g):{...s};if(w){const R=new Set([...w.nodes.map(_=>_.data.id),...w.edges.map(_=>_.data.id)]);for(const _ of Object.keys(k)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(_))continue;const N=k[_];k[_]=($,...V)=>{if(!R.has($))return N==null?void 0:N($,...V)}}}return{...k,onAllNodesIconLabelChange:R=>{var _;m(R),(_=k.onAllNodesIconLabelChange)==null||_.call(k,R)}}},[r,v,s,g,w]),T=j.useMemo(()=>{if(!t)return P;let k=t.state;const R=N=>{if(i.readOnly||i.editable===!1)return;const $=t.onStateChange??t.onChange;if(!$)return;const V=Lw(k,N,s.onFormChange);V!==k&&(k=V,$(V,{...N,data:V}))},_=(N,$,V)=>{var F;const I=r&&((F=Oe(r,N))==null?void 0:F[$]);return!I||typeof I.$state!="string"?!1:(R({address:I.$state,nodeAddress:N,previousValue:Oe(k,I.$state),value:V,data:k}),!0)};return{...P,onFormChange:R,onNodeCreateRequest:N=>{var I,F;const $=(I=N.sourceProperty)!=null&&I.startsWith("config:")?N.sourceProperty.slice(7):void 0,V=$!==void 0&&(w==null?void 0:w.slots.get(En(N.sourceNodeId,$)));return V?(V.present||R({data:k,nodeAddress:V.address.split(".").slice(0,-1).join("."),address:V.address,value:_n(V.type),previousValue:void 0}),!0):((F=P.onNodeCreateRequest)==null?void 0:F.call(P,N))??!1},onNodeDelete:(N,$)=>{var H,ee;if(!(w!=null&&w.nodes.some(ue=>ue.data.id===N)))return(H=P.onNodeDelete)==null?void 0:H.call(P,N,$);const V=w&&[...w.slots.values()].find(ue=>ue.nodeId===N);if(!V)return(ee=P.onNodeDelete)==null?void 0:ee.call(P,N,$);const I=V.address.split("."),F=I.pop(),oe=I.join("."),se=Oe(k,oe);R(Array.isArray(se)?{data:k,nodeAddress:oe,address:oe,previousValue:se,value:se.filter((ue,q)=>String(q)!==F)}:{data:k,nodeAddress:oe,address:V.address,previousValue:Oe(k,V.address),value:void 0})},onEdgeCreate:(N,$,V)=>{var oe,se;const I=((oe=V==null?void 0:V.targetProperty)==null?void 0:oe.startsWith("config:"))&&(w==null?void 0:w.slots.get(En($,V.targetProperty.slice(7)))),F=w==null?void 0:w.containers.get(N);if(I&&F&&(V==null?void 0:V.sourceProperty)==="output:resource"){const H=Bw(k,F,I);H!==void 0&&R({data:k,nodeAddress:I.address.split(".").slice(0,-1).join("."),address:I.address,previousValue:Oe(k,I.address),value:H});return}I||w!=null&&w.nodes.some(H=>H.data.id===N||H.data.id===$)||(se=P.onEdgeCreate)==null||se.call(P,N,$,V)},onEdgeDelete:(N,$)=>{var ee;const V=w==null?void 0:w.edges.find(ue=>ue.data.id===N);if(!V)return(ee=P.onEdgeDelete)==null?void 0:ee.call(P,N,$);const I=w.slots.get(En(V.data.target,V.data.targetProperty.slice(7))),F=I.address.split("."),oe=F.pop(),se=F.join("."),H=Oe(k,se);R(Array.isArray(H)?{data:k,nodeAddress:se,address:se,previousValue:H,value:H.filter((ue,q)=>String(q)!==oe)}:{data:k,nodeAddress:se,address:I.address,previousValue:Oe(k,I.address),value:void 0})},onNodeContentChange:(N,$)=>{var V,I;_(N,"$content",$)?(V=s.onNodeContentChange)==null||V.call(s,N,$):(I=P.onNodeContentChange)==null||I.call(P,N,$)},onNodeLabelChange:(N,$)=>{var V,I;_(N,"$label",$)?(V=s.onNodeLabelChange)==null||V.call(s,N,$):(I=P.onNodeLabelChange)==null||I.call(P,N,$)}}},[P,t,r,s,w,i.readOnly,i.editable]);return f.jsx($t.Provider,{value:{data:(t==null?void 0:t.state)??r,viewData:r,bindings:S,references:t==null?void 0:t.references,structured:w,renderForm:t==null?void 0:t.renderForm,editable:t?!!(t.onStateChange??t.onChange):!!s.onJsonChange,schema:C,setSchema:k=>{var R;h(k),(R=s.onFormSchemaChange)==null||R.call(s,k)},callbacks:T},children:f.jsx(mb,{config:w?{...i,formSchema:C}:i,callbacks:T,nodes:E,edges:M,children:f.jsxs(W.Box,{className:a,"data-flow-diagram":"","data-animations-disabled":i.disableAnimations||void 0,style:c,width:"100%",height:"100%",position:"relative",overflow:"hidden",css:{"&[data-animations-disabled], &[data-animations-disabled] *, &[data-animations-disabled] *::before, &[data-animations-disabled] *::after":{animation:"none !important",transition:"none !important"},"& input, & textarea, & select":{outline:"none !important",boxShadow:"none !important"}},children:[f.jsx(yv,{nodes:E,edges:M}),l&&f.jsx(zb,{}),d]})})})}function TE(e){return Md(JSON.parse(e))}function Md(e){if(!e||typeof e!="object")throw new Error("Expected a JSON object or array.");const r=new Set,t=n=>{if(!(n===null||typeof n=="string"||typeof n=="boolean")&&!(typeof n=="number"&&Number.isFinite(n))){if(!n||typeof n!="object"||r.has(n)||!Array.isArray(n)&&![Object.prototype,null].includes(Object.getPrototypeOf(n)))throw new Error("Document must contain only finite, acyclic JSON values.");r.add(n);for(const[o,i]of Object.entries(n)){if(["__proto__","prototype","constructor"].includes(o))throw new Error(`Unsafe document key: ${o}`);t(i)}r.delete(n)}};return t(e),structuredClone(e)}function IE(e){return{replaceJson(r){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const t=Md(r);return e.onJsonChange(t,{type:"documentReplace",address:"root"}),t},replaceState(r){if(e.readOnly||!e.onStateChange)throw new Error("Form state is read-only.");const t=Md(r);return e.onStateChange(t,{address:"root",nodeAddress:"root",previousValue:e.state,value:t,data:t}),t}}}function NE(e,r){const t=(n,o)=>{if(n===null||typeof n!="object")return typeof n==typeof o?n:void 0;if(!(!o||typeof o!="object"))return Array.isArray(n)?Array.isArray(o)?n.map((i,s)=>t(i,o[s])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,s])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i==="$content"&&n.$contentFormat==="jsx"&&o.$contentFormat==="jsx"&&Array.isArray(s)&&Array.isArray(o[i]))return[[i,s.filter((c,l)=>JSON.stringify(c)===JSON.stringify(o[i][l]))]];if(i.startsWith("$")&&i!=="$")return JSON.stringify(s)===JSON.stringify(o[i])?[[i,s]]:[];const a=t(s,o[i]);return a===void 0?[]:[[i,a]]}))};return t(e,r)??{}}function lo(e){let r="",t=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},s=()=>{if(i(),!(t||!r.trim()))try{const c=e.parse(e.repair(r)),l=JSON.stringify(c);if(l===n)return;e.preview(c),n=l}catch{}},a=c=>{if(!t){if(new TextEncoder().encode(c).byteLength>(e.maxBytes??1024*1024))throw t=!0,i(),new Error("JSON stream exceeds the size limit.");r=c,o||(o=setTimeout(s,e.intervalMs??150))}};return{snapshot:a,append(c){a(r+c)},flush:s,finish(){if(t)throw new Error("JSON stream is closed.");t=!0,i();const c=e.parse(r);return e.commit(c),c},cancel(){t=!0,i(),r=""}}}function OE(e){const{source:r}=e,t=e.tickMs??50,n=e.durationMs??8e3;if(!Number.isFinite(t)||t<=0||!Number.isFinite(n)||n<=0)throw new Error("Playback timing must be positive.");if(new TextEncoder().encode(r).byteLength>(e.maxBytes??1024*1024))throw new Error("JSON stream exceeds the size limit.");e.parse(r);let o=lo(e),i=0,s=!1,a=!1,c;const l=Math.max(1,Math.ceil(r.length*t/n)),d=()=>e.onChange({position:i,total:r.length,playing:s}),u=()=>{clearTimeout(c),c=void 0},h=(g=!1)=>{o.snapshot(r.slice(0,i)),i===r.length?(s=!1,u(),o.finish()):g&&o.flush()},p=g=>{s=!1,u(),o.cancel(),d(),e.onError(g)},m=()=>{if(c=void 0,!(!s||a)){i=Math.min(r.length,i+l);try{h()}catch(g){p(g);return}d(),s&&(c=setTimeout(m,t))}};return{play(){a||s||(i===r.length&&(o.cancel(),o=lo(e),i=0),s=!0,d(),c=setTimeout(m,t))},pause(){a||(s=!1,u(),o.flush(),d())},seek(g){if(!a){if(!Number.isFinite(g))throw new Error("Playback position must be finite.");u(),i=Math.max(0,Math.min(r.length,Math.round(g))),o.cancel(),o=lo(e);try{h(!0)}catch(y){p(y);return}d(),s&&(c=setTimeout(m,t))}},dispose(){a=!0,s=!1,u(),o.cancel()}}}function $E({nodeAddress:e,expanded:r=!1}){var l;const{data:t,schema:n,bindings:o}=j.useContext($t),{colorText:i,background:s}=at();if((l=o==null?void 0:o[e])!=null&&l.portResources)return null;const a=o&&Hn(o,e,n);if(!t||!a)return null;const c=Oe(t,a.address);return!c||typeof c!="object"?null:f.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:Me(i),background:Me(s),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(a.type.properties).map(d=>{const u=a.fields[d]??{};if(!Eo(u.$visibleWhen,t))return null;const h=c[d],p=h==null?"":typeof h=="object"?JSON.stringify(h):String(h);return f.jsxs("div",{"data-flow-property":d,style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:12,padding:"10px 16px",borderTop:"1px solid color-mix(in srgb, currentColor 12%, transparent)"},children:[f.jsx("span",{style:{overflowWrap:"anywhere"},children:Dt(u.$label??d)}),f.jsx("span",{title:p,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:r?"pre-wrap":"nowrap",overflowWrap:r?"anywhere":void 0},children:p})]},d)})})}exports.BottomBar=zb;exports.CollapseAllToggle=xb;exports.CompactPropertyLayoutToggle=vb;exports.ConnectionsOnlyToggle=Jw;exports.ContentFullscreenButton=lv;exports.DEFAULT_PALETTE=po;exports.DiagramAppearanceControls=wb;exports.DynamicIcon=cr;exports.EdgeTools=Tb;exports.EditableLabel=cn;exports.ErrorToast=Lb;exports.FlowDiagram=RE;exports.FlowDiagramProvider=mb;exports.FlowPort=sv;exports.FlowView=yv;exports.FormDocumentContext=$t;exports.GridAdjustmentToggle=Cb;exports.LIGHT_BLACK=ln;exports.LoadingBorder=cv;exports.NODE_TYPE_VIEWS=Ld;exports.NodeBorderRadiusControl=Ib;exports.NodeConfigSummary=$E;exports.NodeForm=Vd;exports.NodeFormPopover=yu;exports.NodeGridControls=so;exports.NodeIconPicker=Gd;exports.NodeTools=Nb;exports.NodeView=Qn;exports.PanelDragHandle=bb;exports.SvgExportButton=qb;exports.Swatches=Vr;exports.TEXT_PALETTE=Rb;exports.ToolbarCloseButton=dn;exports.ToolbarCommitInput=Er;exports.ToolbarDivider=Nn;exports.ToolbarIconButton=Ne;exports.ToolbarRangeInput=Fd;exports.ToolbarScrollContainer=ko;exports.ToolbarSelect=It;exports.ToolbarTooltip=Ge;exports.TooltipIconButton=Rd;exports.WorkflowControls=Hd;exports.addChild=$d;exports.addConnection=qd;exports.addTargetEdge=db;exports.addressToPath=Kt;exports.applyCollapsed=Sw;exports.applyFormChange=_o;exports.applyStateEdits=qw;exports.bindSqueedCallbacks=Gb;exports.compileSqueed=Sd;exports.connectionIssue=Dd;exports.contentObjTheme=sr;exports.copySelection=Ud;exports.createFlowDiagram=Dr;exports.createFlowDocumentActions=IE;exports.createFormNode=Db;exports.createJsonPlayback=OE;exports.createJsonStream=lo;exports.createWorkflowExecution=Aw;exports.downloadSvg=$b;exports.duplicateSelection=Vb;exports.exportSvg=Ob;exports.formValueError=Jt;exports.formatTimeAgo=fb;exports.getChakraColorHex=Me;exports.getColorVariant=hb;exports.getDarkerHexColor=fo;exports.getInteractionSurface=gr;exports.getNode=Oe;exports.getSelectionRoots=Wb;exports.isNodeVisible=ar;exports.parseFlowDocument=TE;exports.parseJsonContract=zd;exports.parseTypeScriptContract=Sb;exports.parseTypeScriptForm=Bd;exports.projectJsonPlaybackPreview=NE;exports.readFormSchema=Wd;exports.readWorkflowContract=jb;exports.removeEdge=ub;exports.removeNode=lb;exports.reparentNode=Yw;exports.resolveEdgeOwner=zr;exports.resolveStateView=Eb;exports.setCollapsed=uo;exports.setEdgeProp=Sr;exports.setEdgeStyle=cb;exports.setNodeProp=kt;exports.stampNodeEdit=sb;exports.updateNode=Pt;exports.useCustomColors=at;exports.useEdgeProximity=So;exports.useFlowData=Xt;exports.useFlowDiagramContext=Ue;exports.useNodeViewActions=eo;exports.useStopPropagation=gu;exports.useThemeContentColors=Gn;exports.validateGridAdjustment=nv;
283
+ @media(prefers-reduced-motion:reduce){[data-flow-loading-border][data-flow-loading-border] .flow-sdk-node-border-animation{animation:none!important}}`;function mu({active:e=!0,label:r="Loading content",radius:t}){const{config:n,themeColor:o}=He(),{colorText:i}=at(),s=j.useRef(null),[a,c]=j.useState({width:0,height:0,radius:0});if(j.useLayoutEffect(()=>{const u=s.current;if(!e||!u)return;const h=()=>{const m=u.parentElement,g={width:u.clientWidth,height:u.clientHeight,radius:t??(m&&parseFloat(getComputedStyle(m).borderTopLeftRadius)||0)};c(y=>y.width===g.width&&y.height===g.height&&y.radius===g.radius?y:g)},p=new ResizeObserver(h);return p.observe(u),h(),()=>p.disconnect()},[e,t]),!e)return null;const l=Te(o||i),d={x:4,y:4,width:a.width-8,height:a.height-8,radius:Math.max(0,a.radius-4),color:l,strokeWidth:2};return f.jsxs("div",{ref:s,role:"status","aria-label":r,"data-flow-loading-border":"","data-motion-disabled":n.disableAnimations||void 0,style:{position:"absolute",inset:0,pointerEvents:"none",borderRadius:"inherit",overflow:"hidden",zIndex:2},children:[f.jsx("style",{children:cE}),f.jsxs("svg",{width:"100%",height:"100%","aria-hidden":"true",style:{display:"block",pointerEvents:"none"},children:[f.jsx("g",{opacity:.5,style:{filter:"blur(3px)"},children:f.jsx(go,{...d,strokeWidth:6})}),f.jsx(go,{...d})]})]})}function lE({nodeId:e}){var M,k;const{nodeById:r}=Xt(),{callbacks:t,config:n,readOnly:o,colorMode:i,isPerformanceMode:s}=He(),{background:a,border:c,colorInactive:l,colorText:d}=at(),u=[...r.values()].filter(({data:_})=>{var N,$,D,T,Z;return _.type!=="grid"&&!((N=_.config)!=null&&N.parentContainer)&&((($=_.config)==null?void 0:$.contentFormat)==="html"||((D=_.config)==null?void 0:D.contentFormat)==="jsx")&&(typeof((T=_.config)==null?void 0:T.content)=="string"||Array.isArray((Z=_.config)==null?void 0:Z.content))}),[h,p]=j.useState(e),[m,g]=j.useState(!1),y=j.useRef(null),b=So({edge:"top",enabled:!0,bounds:y,inside:[y],threshold:90}),x=j.useRef(null),w=j.useRef(1),v=u.find(_=>_.data.id===h)??u.find(_=>_.data.id===e)??u[0],C=u.indexOf(v),S=!!n.editable&&!o,E=_=>typeof _=="number"?_>0&&Number.isFinite(_)?String(_):"":typeof _=="string"&&/^\d+(\.\d+)?px$/.test(_)?String(parseFloat(_)):"",R=E((M=v==null?void 0:v.data.viewProps)==null?void 0:M.width),P=E((k=v==null?void 0:v.data.viewProps)==null?void 0:k.height);j.useLayoutEffect(()=>{const _=x.current;if(!_||n.disableAnimations||s||matchMedia("(prefers-reduced-motion: reduce)").matches)return;const N=_.animate({transform:[`translateX(${w.current*100}%)`,"translateX(0)"]},{duration:240,easing:"ease-out",id:"flow-content-slide"});return()=>N.cancel()},[v==null?void 0:v.data.id,n.disableAnimations,s]);const I=_=>{const N=u[C+_];!N||m||(w.current=_,p(N.data.id))};return v?f.jsxs(V.Box,{"data-content-gallery":"",position:"relative",h:"100%",display:"flex",flexDirection:"column",minH:0,color:d,onClick:_=>_.stopPropagation(),onDoubleClick:_=>_.stopPropagation(),onPointerDown:_=>_.stopPropagation(),children:[f.jsx(V.Box,{ref:y,role:"toolbar","aria-label":"Preview controls",position:"absolute",top:"8px",left:"8px",w:"max-content",maxW:"calc(100% - 76px)",zIndex:2,css:{"@media (hover: hover) and (pointer: fine)":{opacity:b?1:0},"&:hover, &:focus-within":{opacity:1}},children:f.jsx(ko,{background:a,border:i==="dark"?c:"gray.300",children:f.jsxs(V.HStack,{px:2,gap:2,width:"max-content",height:"100%",children:[f.jsx(Ge,{label:"Previous content",children:f.jsx(Ne,{"data-flow-content-navigation":"","aria-label":"Previous content",icon:f.jsx(ee.PiCaretLeft,{size:20}),disabled:C<=0||m,onClick:()=>I(-1),rememberAction:!1,size:"sm",variant:"ghost"})}),f.jsxs(V.Text,{"aria-live":"polite",fontSize:"12px",minW:"42px",textAlign:"center",children:[C+1," / ",u.length]}),f.jsx(Ge,{label:"Next content",children:f.jsx(Ne,{"data-flow-content-navigation":"","aria-label":"Next content",icon:f.jsx(ee.PiCaretRight,{size:20}),disabled:C>=u.length-1||m,onClick:()=>I(1),rememberAction:!1,size:"sm",variant:"ghost"})}),["width","height"].map(_=>f.jsxs(V.Box,{as:"label",display:"flex",alignItems:"center",gap:1,fontSize:"12px",opacity:S?1:.5,children:[_==="width"?"W":"H",f.jsx(Er,{value:_==="width"?R:P,placeholder:"Auto",ariaLabel:`Content ${_}`,type:"number",min:1,width:"72px",disabled:!S||!t.onNodeDimensionChange||m,onCommit:N=>{var $;S&&(($=t.onNodeDimensionChange)==null||$.call(t,v.data.id,_,N===""?void 0:Number(N)))}})]},`${v.data.id}:${_}`)),S&&!m&&f.jsx(Ge,{label:"Edit content source",children:f.jsx(Ne,{"aria-label":"Edit content source",icon:f.jsx(ee.PiCode,{size:20}),onClick:()=>g(!0),rememberAction:!1,size:"sm",variant:"ghost",color:l})})]})})}),f.jsx(V.Box,{flex:1,minH:0,overflow:"auto",position:"relative","data-content-slide-viewport":"",children:f.jsx(V.Box,{ref:x,"data-content-slide":v.data.id,width:R?`${R}px`:"100%",height:P?`${P}px`:"100%",minH:P?void 0:"100%",mx:"auto",overflow:"auto",children:f.jsx(bu,{nodeId:v.data.id,content:v.data.config.content,format:v.data.config.contentFormat,color:d,previewControls:!1,editOnMount:m,onEditEnd:()=>g(!1)},`${v.data.id}:${m}`)},v.data.id)})]}):f.jsx(V.Box,{role:"status",p:4,children:"No HTML or JSX content available."})}const lv=j.forwardRef(function({fullscreen:r,onClick:t},n){const{colorInactive:o}=at();return f.jsx(Ne,{ref:n,"data-flow-fullscreen":"","aria-label":r?"Exit fullscreen":"Expand preview",title:r?"Exit fullscreen":"Expand preview","aria-expanded":r,icon:r?f.jsx(ee.PiArrowsIn,{size:20}):f.jsx(ee.PiArrowsOut,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:o,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:t})});function dE({content:e,format:r,onEdit:t,autoHeight:n=!1,nodeId:o,controls:i=!0}){var F,H,G,ce,te;const{config:s,colorMode:a}=He(),{nodeById:c}=Xt(),l=o?(H=(F=c.get(o))==null?void 0:F.data.viewProps)==null?void 0:H.height:void 0,d=typeof l=="number"?`${l}px`:typeof l=="string"&&/^\d+(\.\d+)?px$/.test(l)?l:void 0;n=n&&!d;const{background:u,border:h,colorInactive:p}=at(),m=(G=s.customViews)==null?void 0:G.jsxContent,g=typeof e=="string"?e:JSON.stringify(e,null,2);let y,b=r==="jsx"&&o?(te=(ce=c.get(o))==null?void 0:ce.data.config)==null?void 0:te.contentReferenceError:void 0;if(r==="jsx"&&!b)try{const X=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(X)||X.some(ie=>!ie||typeof ie!="object"||Array.isArray(ie)||typeof ie.type!="string"))throw new Error("JSX content must be an array of components with a type.");y=X}catch(X){b=X instanceof Error?X.message:"Invalid components array."}const x=j.useRef(null),w=j.useRef(null),v=j.useRef(null),C=j.useRef(!1),[S,E]=j.useState(!1),R=j.useRef(null),P=So({edge:"top",enabled:S,bounds:R,inside:[R],threshold:90}),[I,M]=j.useState(""),[k,_]=j.useState(),N=!!t;j.useEffect(()=>{const X=()=>{var me;const ie=document.fullscreenElement===w.current;E(ie),C.current&&!ie&&!document.fullscreenElement&&((me=v.current)==null||me.focus({preventScroll:!0})),C.current=ie};return document.addEventListener("fullscreenchange",X),()=>document.removeEventListener("fullscreenchange",X)},[]);const $=async()=>{var X;M("");try{if(document.fullscreenElement===w.current)await document.exitFullscreen();else if((X=w.current)!=null&&X.requestFullscreen)await w.current.requestFullscreen();else throw new Error("Fullscreen is not supported in this browser.")}catch(ie){M(ie instanceof Error?ie.message:"Unable to change fullscreen.")}},[D,T]=j.useState(),[Z,K]=j.useState(),[ne,se]=j.useState();j.useEffect(()=>{if(r==="jsx")return;let X=!1;return Promise.resolve().then(()=>require("./contentPreviewDocument-i1zWN5gw.cjs")).then(({contentPreviewDocument:ie})=>ie(g,r,N,n)).then(ie=>{X||T({content:g,format:r,editable:N,autoHeight:n,document:ie})},ie=>{X||T({content:g,format:r,editable:N,autoHeight:n,error:ie instanceof Error?ie.message:String(ie)})}),()=>{X=!0}},[g,r,N,n]),j.useEffect(()=>{if(!t)return;const X=async ie=>{var me,xe;if(!(!((me=x.current)!=null&&me.contentWindow)||ie.source!==x.current.contentWindow||((xe=ie.data)==null?void 0:xe.type)!=="squeed:content-edit"))try{document.fullscreenElement===w.current&&await document.exitFullscreen(),t()}catch(fe){M(fe instanceof Error?fe.message:"Unable to close fullscreen.")}};return window.addEventListener("message",X),()=>window.removeEventListener("message",X)},[t]);const W=(D==null?void 0:D.content)===g&&D.format===r&&D.editable===N&&D.autoHeight===n?D:void 0;j.useEffect(()=>{if(!n||r!=="html"||!(W!=null&&W.document))return;const X=W.document,ie=me=>{var fe,U,re;const xe=(fe=me.data)==null?void 0:fe.height;!((U=x.current)!=null&&U.contentWindow)||me.source!==x.current.contentWindow||((re=me.data)==null?void 0:re.type)!=="squeed:content-size"||typeof xe!="number"||!Number.isFinite(xe)||xe<=0||xe>1e5||document.fullscreenElement===w.current||_(de=>(de==null?void 0:de.document)===X&&de.height===xe?de:{document:X,height:xe})};return window.addEventListener("message",ie),()=>window.removeEventListener("message",ie)},[n,r,W==null?void 0:W.document]);const ue=!!W&&W===ne,q=r!=="jsx"&&!(W!=null&&W.error)&&!ue&&(!W||Z!==W);return f.jsxs("div",{"data-flow-content-preview":"",style:{width:"100%",height:i?d??(n?r==="jsx"?"auto":(k==null?void 0:k.document)===(W==null?void 0:W.document)?k==null?void 0:k.height:360:360):n?"auto":"100%",fontSize:16,overflow:"auto"},children:[f.jsx("pre",{"data-flow-preview-source":"",style:{display:"none",whiteSpace:"pre-wrap"},children:g}),f.jsxs(V.Box,{ref:w,position:"relative",w:"100%",h:n&&r==="jsx"?"auto":"100%","aria-busy":!S&&r!=="jsx"?q:void 0,bg:r==="jsx"&&a==="dark"?"gray.900":"white",onDoubleClick:X=>{r!=="jsx"||!t||X.defaultPrevented||X.target.closest('button, a, input, textarea, select, [contenteditable], [role="button"], [role="textbox"]')||(X.stopPropagation(),(async()=>{document.fullscreenElement===w.current&&await document.exitFullscreen(),t()})().catch(ie=>M(String(ie))))},onKeyDownCapture:X=>{X.key!=="Escape"||document.fullscreenElement!==w.current||X.target instanceof Element&&X.target.closest('input, textarea, select, [contenteditable="true"]')||(X.preventDefault(),X.stopPropagation(),$())},css:{"&:fullscreen":{width:"100vw",height:"100dvh",maxWidth:"none",maxHeight:"none",padding:0},"&:not(:fullscreen):hover > [data-flow-content-toolbar], &:not(:fullscreen):focus-within > [data-flow-content-toolbar]":{opacity:1,pointerEvents:"auto"},"@media (hover: none)":{"& > [data-flow-content-toolbar]":{opacity:1,pointerEvents:"auto"}}},children:[i&&f.jsx(V.Box,{ref:R,role:"toolbar","aria-label":"Content controls","data-flow-content-toolbar":"",position:"absolute",top:"8px",right:"8px",zIndex:1,w:"max-content",maxW:"calc(100% - 16px)",opacity:S?1:0,pointerEvents:S?"auto":"none",css:S?{"@media (hover: hover) and (pointer: fine)":{opacity:P?1:0},"&:hover, &:focus-within":{opacity:1}}:void 0,children:f.jsx(ko,{background:u,border:a==="dark"?h:"gray.300",children:f.jsxs(V.HStack,{px:"8px",gap:"8px",h:"100%",w:"max-content",css:{"& button > svg":{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",flexShrink:0}},children:[t&&(!S||!o)&&f.jsx(Ne,{"data-flow-content-edit":"","aria-label":"Edit content source",title:"Edit content source",icon:f.jsx(ee.PiCode,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:p,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:X=>{X.stopPropagation(),(async()=>{document.fullscreenElement===w.current&&await document.exitFullscreen(),t()})().catch(ie=>M(String(ie)))}}),f.jsx(lv,{ref:v,fullscreen:S,onClick:X=>{X.stopPropagation(),$()}})]})})}),I&&f.jsx(V.Box,{role:"alert",position:"absolute",bottom:0,insetInline:0,bg:"white",color:"red.700",fontSize:"14px",children:I}),S&&o?f.jsx(lE,{nodeId:o}):r==="jsx"?b?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:b}):m&&y?f.jsx(m,{components:y,colorMode:a,fillHeight:!n||S}):f.jsx(V.Box,{role:"status",fontSize:"14px",children:"JSX content renderer is not available."}):W!=null&&W.error||ue?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:(W==null?void 0:W.error)||"Content preview could not be loaded."}):W!=null&&W.document?f.jsx("iframe",{ref:x,title:`${r.toUpperCase()} content preview`,sandbox:N||n?"allow-scripts":"",allowFullScreen:!0,referrerPolicy:"no-referrer",srcDoc:W.document,onLoad:()=>K(W),onError:()=>se(W),style:{width:"100%",height:"100%",border:0,display:"block",background:"white",visibility:q?"hidden":"visible"}},W.document):null,f.jsx(mu,{active:!S&&q,label:"Loading HTML content"})]})]})}const Mm=1.55;function bu({nodeId:e,content:r,color:t,format:n="markdown",fillBody:o=!1,autoHeight:i=!1,previewControls:s=!0,editOnMount:a=!1,plainText:c=!1,placeholder:l="Write your content here",onChange:d,onEditEnd:u,onSubmit:h,onDraftChange:p}){var ne,se;const{callbacks:m,config:g,readOnly:y,nodeGridOptions:b}=He(),x=!!g.editable&&!y,w=x&&(!b||o&&b.fill&&n==="markdown"),{nodeById:v}=Xt(),C=n==="jsx"&&!d?((se=(ne=v.get(e))==null?void 0:ne.data.config)==null?void 0:se.contentSource)??r:r,S=typeof C=="string"?C:JSON.stringify(C,null,2),[E,R]=j.useState(a&&x),[P,I]=j.useState(S),[M,k]=j.useState(""),[_,N]=j.useState(),$=j.useRef(null),D=j.useRef(!1),T=gu(E);j.useLayoutEffect(()=>{const W=$.current;!E||!W||(W.style.height="auto",W.style.height=`${Math.max((_==null?void 0:_.height)??0,W.scrollHeight)}px`)},[P,E,_]),j.useEffect(()=>{var W,ue;x?E&&(D.current=!1,(W=$.current)==null||W.focus({preventScroll:!0}),(ue=$.current)==null||ue.select()):(R(!1),p==null||p(void 0))},[E,x,p]);const Z=(W,ue=!1)=>{!x||b&&!w&&!ue||(N({width:W.offsetWidth,height:W.offsetHeight}),I(S),p==null||p(S),k(""),R(!0))},K=()=>{var ue;if(D.current||!x)return;let W=P;if(n==="jsx")try{if(W=JSON.parse(P),!Array.isArray(W)||W.some(q=>!q||typeof q!="object"||Array.isArray(q)||typeof q.type!="string"&&typeof q.$contentRef!="string"))throw new Error("JSX content must be an array of components with a type.")}catch(q){k(q instanceof Error?q.message:"Invalid components array.");return}D.current=!0,P!==S&&(d?d(W):(ue=m.onNodeContentChange)==null||ue.call(m,e,W)),R(!1),u==null||u()};return(!E||!x)&&n!=="markdown"?f.jsx(V.Box,{ref:T,w:"100%",h:!s&&!i?"100%":void 0,position:"relative","data-flow-content":"",children:f.jsx(dE,{nodeId:e,content:r,format:n,controls:s,autoHeight:i&&!(b!=null&&b.fill),onEdit:w?()=>{T.current&&Z(T.current)}:void 0})}):!E||!x?f.jsx(V.Box,{"data-flow-content":"",color:t,opacity:r?void 0:.6,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:Mm,overflowWrap:"anywhere",css:{"& > :first-of-type":{marginTop:0},"& > :last-of-type":{marginBottom:0},"& h1, & h2, & h3, & h4, & h5, & h6":{fontWeight:700,lineHeight:1.2,margin:"1em 0 0.45em"},"& h1":{fontSize:"1.5em"},"& h2":{fontSize:"1.3em"},"& h3":{fontSize:"1.1em"},"& p":{margin:"0.65em 0",whiteSpace:"pre-wrap"},"& ul, & ol":{margin:"0.65em 0",paddingInlineStart:"1.6em"},"& ul":{listStyleType:"disc"},"& ol":{listStyleType:"decimal"},"& li":{display:"list-item",margin:"0.3em 0",paddingInlineStart:"0.15em"},"& li > ul, & li > ol":{margin:"0.25em 0"},"& li > p":{margin:0},"& a":{color:"inherit",textDecoration:"underline"},"& code":{fontFamily:"monospace",fontSize:"0.85em"},"& :not(pre) > code":{background:"color-mix(in srgb, currentColor 10%, transparent)",padding:"0.1em 0.25em",borderRadius:"0.2em"},"& pre":{margin:"0.75em 0",padding:"0.75em",background:"color-mix(in srgb, currentColor 8%, transparent)",border:0,borderRadius:"6px",maxWidth:"100%",overflowX:"auto",whiteSpace:"pre",overflowWrap:"normal",lineHeight:1.5},"& pre code":{background:"transparent",padding:0,whiteSpace:"inherit"},"& strong":{fontWeight:700},"& em":{fontStyle:"italic"},"& blockquote":{margin:"0.4em 0",borderInlineStart:"0.1em solid currentColor",paddingInlineStart:"0.6em"},"& table":{width:"100%",tableLayout:"fixed",borderCollapse:"collapse",margin:"0.4em 0"},"& th, & td":{border:"1px solid currentColor",padding:"0.2em 0.3em",textAlign:"left"},"& th":{fontWeight:700},"& img":{maxWidth:"100%",height:"auto"}},cursor:w?"text":void 0,tabIndex:w?0:void 0,outline:"none",_focusVisible:{outline:"none",boxShadow:"none"},onClick:W=>{!x||b&&!w&&!W.shiftKey||W.target instanceof Element&&W.target.closest("a, button, input")||(W.stopPropagation(),Z(W.currentTarget,W.shiftKey))},onDoubleClick:W=>{W.stopPropagation(),Z(W.currentTarget,W.shiftKey)},onKeyDown:W=>{x&&(w||W.shiftKey)&&W.key==="Enter"&&W.target===W.currentTarget&&(W.preventDefault(),W.stopPropagation(),Z(W.currentTarget,W.shiftKey))},children:c?f.jsx(V.Box,{whiteSpace:"pre-wrap",minH:"100%",children:S||(x?l:"")}):f.jsx(Nv.default,{options:{forceBlock:!0,wrapper:j.Fragment,disableParsingRawHTML:!0,overrides:{a:{props:{target:"_blank",rel:"noopener noreferrer"}},img:{props:{loading:"lazy",referrerPolicy:"no-referrer"}}}},children:S||(g.editable&&!y?l:"")})}):f.jsxs("div",{ref:T,style:{width:c?"100%":_==null?void 0:_.width,minHeight:_==null?void 0:_.height,maxWidth:"100%"},children:[f.jsx(V.Textarea,{ref:$,"aria-label":"Node content",placeholder:l,value:P,"aria-invalid":!!M,onChange:W=>{I(W.target.value),p==null||p(W.target.value)},onPaste:W=>{c&&W.clipboardData.files.length&&(W.preventDefault(),W.stopPropagation())},onDrop:W=>{c&&(W.stopPropagation(),W.dataTransfer.files.length&&W.preventDefault())},onBlur:K,onKeyDown:W=>{if(W.stopPropagation(),!W.nativeEvent.isComposing){if(h&&n==="markdown"&&W.key==="Enter"&&!W.shiftKey&&!W.ctrlKey&&!W.metaKey&&!W.altKey){W.preventDefault(),!W.repeat&&!D.current&&P.trim()&&(Wr.flushSync(K),h(P));return}W.key==="Enter"&&(W.ctrlKey||W.metaKey)&&(W.preventDefault(),K()),W.key==="Escape"&&(D.current=!0,R(!1),p==null||p(void 0),u==null||u())}},color:t,fontFamily:"inherit",fontSize:"inherit",lineHeight:Mm,overflowWrap:"anywhere",whiteSpace:"pre-wrap",rows:1,bg:"transparent",display:"block",style:{border:0,outline:"none",boxShadow:"none"},_focus:{border:0,outline:"none",boxShadow:"none"},_focusVisible:{border:0,outline:"none",boxShadow:"none"},p:0,w:"100%",h:"100%",minW:0,minH:0,resize:"none"}),M&&f.jsx(V.Box,{role:"alert",fontSize:"14px",color:"red.500",children:M})]})}function uE({edited:e,relative:r,helpText:t,fontSize:n}){return!r||!e.name?null:f.jsxs(V.Text,{"data-flow-node-edited":"",fontSize:n,lineHeight:1.3,textTransform:"none",title:t,children:[e.name," · edited"," ",f.jsx("time",{dateTime:e.at,title:t,children:r})]})}function Tm({data:e,caption:r=!1}){var l,d,u,h,p;const{colorText:t}=at(),n=typeof((l=e.config)==null?void 0:l.subtitle)=="string"?e.config.subtitle:"",o=(d=e.config)==null?void 0:d.edited,i=Pw(o==null?void 0:o.at),s=r||typeof((u=e.config)==null?void 0:u.content)=="string"||Array.isArray((h=e.config)==null?void 0:h.content),a=e.type==="objectView"||(p=e.config)!=null&&p.labelBelow||s?"32px":"20px",c=[n,o==null?void 0:o.name,o?`edited ${i??""} · ${new Date(o.at).toLocaleString()}`:void 0].filter(m=>!!m).join(`
284
+ `);return!o&&!s||!o&&!n?null:f.jsxs(V.Box,{"data-flow-node-subtitles":"",color:t,opacity:.7,pt:2,minW:0,maxW:"100%",textAlign:"center",overflowWrap:"anywhere",title:c||void 0,children:[o&&f.jsx(uE,{edited:o,relative:i,helpText:c,fontSize:a}),n&&f.jsx(V.Text,{"data-flow-node-subtitle":"",fontSize:a,lineHeight:1.3,whiteSpace:"pre-line",title:c,children:n})]})}const fE=({data:e,children:r,isInverted:t,isParent:n,onOpenView:o,editOnMount:i=!1,hoverLeaveDelay:s=0})=>{var fe,U,re,de,Pe,ae,we,$e,Ue,Ve,tt;const{selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isMultiSelectMode:u,nodeGridOptions:h,isPerformanceMode:p,engineRef:m,callbacks:g,config:y,themeColor:b,direction:x,nodeViewModes:w}=He(),{background:v,border:C,colorText:S}=at(),E=j.useRef(null),R=j.useRef(null);j.useEffect(()=>()=>{R.current&&clearTimeout(R.current)},[]);const[P,I]=j.useState(!1),[M,k]=j.useState(i&&!!y.editable&&!y.readOnly),[_,N]=j.useState(!1),$=e==null?void 0:e.id,D=Ab($),T=a.includes($);j.useEffect(()=>{if(!T||a.length!==1||y.readOnly||M||_)return;const ge=Ae=>{var Xe,ut,Re,Ke,lt;if(Ae.key!=="Enter"||Ae.defaultPrevented||Ae.isComposing||Ae.ctrlKey||Ae.metaKey||Ae.altKey||Ae.shiftKey||Ae.target instanceof Element&&Ae.target.closest('button, input, textarea, select, a, [contenteditable], [role="textbox"], [role="dialog"], [role="menu"], [role="listbox"], [popover], [data-flow-content]')||Array.from(document.querySelectorAll('dialog[open], :popover-open, [role="dialog"], [role="menu"], [role="listbox"]')).some(Je=>Je.getClientRects().length&&getComputedStyle(Je).visibility!=="hidden"))return;const Le=Array.from(((Xe=E.current)==null?void 0:Xe.querySelectorAll("[data-flow-content-toggle] button, button[data-flow-collapse-control]"))??[]).find(Je=>{var mt;return((mt=Je.closest("[data-node-id]"))==null?void 0:mt.getAttribute("data-node-id"))===$&&!Je.disabled&&Je.getClientRects().length&&getComputedStyle(Je).visibility!=="hidden"}),be=!Le&&(e==null?void 0:e.type)==="grid"&&((ut=e.config)==null?void 0:ut.documentId)&&((Re=E.current)==null?void 0:Re.getClientRects().length)&&g.onNodeHoverAction&&((Ke=y.nodeOverlayActions)==null?void 0:Ke.find(Je=>Je.id==="open-document"&&(!Je.nodeTypes||Je.nodeTypes.includes(e.type))));!Le&&!be||(Ae.preventDefault(),Ae.stopPropagation(),Ae.repeat||(Le?Le.click():(lt=g.onNodeHoverAction)==null||lt.call(g,be.id,$,e)))};return window.addEventListener("keydown",ge,!0),()=>window.removeEventListener("keydown",ge,!0)},[$,T,a.length,y.readOnly,M,_,e,g.onNodeHoverAction,y.nodeOverlayActions]);const Z=(fe=y.nodeOverlayActions)==null?void 0:fe.filter(ge=>!ge.nodeTypes||ge.nodeTypes.includes(e==null?void 0:e.type)),K=y.renderNodeOverlay,ne=(e==null?void 0:e.type)==="grid"?(U=y.customViews)==null?void 0:U.gridHoverControls:void 0,se=(e==null?void 0:e.type)==="grid"?"20px":"-100px",W=(e==null?void 0:e.type)==="grid"?"top center":void 0,ue=(e==null?void 0:e.type)==="grid"?"translateX(-50%) scale3d(1.8, 1.8, 1)":"translateX(-50%) scale3d(3, 3, 1)",q=(()=>{var ge;try{const Ae=(ge=m.current)==null?void 0:ge.zoom();return Ae!==void 0&&Ae<.08}catch{return!1}})(),F=j.useCallback((ge,Ae=!1)=>{var be,Xe,ut,Re,Ke;if(M||y.readOnly||h!=null&&h.fill&&!ge.shiftKey||ge.detail===2&&((be=e==null?void 0:e.config)!=null&&be.form)&&!o&&!Ae&&!u&&!l&&!ge.shiftKey&&!ge.ctrlKey&&!ge.metaKey&&!ge.altKey&&a.length===1&&a[0]===$)return;const Le={shiftKey:ge.shiftKey,ctrlKey:ge.ctrlKey,metaKey:ge.metaKey,altKey:ge.altKey,...Ae?{viewToggle:!0}:{}};if(l&&(d(null),(Xe=g.onEdgeDeselect)==null||Xe.call(g)),u||ge.shiftKey&&(h!=null&&h.fill)){const lt=a.includes($),Je=lt?a.filter(mt=>mt!==$):[...a,$];c(Je),lt?(ut=g.onNodeDeselect)==null||ut.call(g):(Re=g.onNodeSelect)==null||Re.call(g,$,e,Le)}else c([$]),(Ke=g.onNodeSelect)==null||Ke.call(g,$,e,Le)},[$,e,a,l,u,h,M,o,c,d,g,y]),H=j.useCallback(()=>{var ge;M||y.readOnly||(ge=g.onNodeDoubleClick)==null||ge.call(g,$,e)},[$,e,M,g,y]),G=j.useCallback(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>I(!0),100)},[]),ce=j.useCallback(ge=>{var Ae;ge.relatedTarget instanceof Node&&((Ae=E.current)!=null&&Ae.contains(ge.relatedTarget))||(R.current&&clearTimeout(R.current),s?R.current=setTimeout(()=>I(!1),s):I(!1))},[s]),te=(e==null?void 0:e.type)==="text"&&!((re=e==null?void 0:e.config)!=null&&re.parentContainer)&&!((de=e==null?void 0:e.config)!=null&&de.form),X=!!((Pe=e==null?void 0:e.config)!=null&&Pe.form)||te,ie={tabIndex:X?0:void 0,"aria-haspopup":X?"dialog":void 0,"aria-expanded":X?_:void 0,onDoubleClickCapture:ge=>{var Ae;!X&&!o||y.readOnly||te&&!y.editable||M||!ge.currentTarget.contains(ge.target)||ge.target instanceof Element&&ge.target.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]")||(ge.preventDefault(),ge.stopPropagation(),(a.length!==1||a[0]!==$)&&c([$]),o?o():N(!0),(Ae=g.onNodeDoubleClick)==null||Ae.call(g,$,e))},onKeyDown:ge=>{!X&&!o||y.readOnly||te&&!y.editable||ge.target!==ge.currentTarget||ge.key!=="Enter"||(ge.preventDefault(),ge.stopPropagation(),c([$]),o?o():N(!0))}},me=X&&f.jsx(yu,{nodeAddress:$,active:T,label:e.label||e.headerTitle||"Node",open:_&&(!te||!!y.editable&&!y.readOnly),onClose:()=>{var ge;N(!1),T&&((ge=E.current)==null||ge.focus({preventScroll:!0}))},children:te?f.jsx(bu,{nodeId:$,content:e.label??e.text??"",color:Te(S),editOnMount:!0,onChange:ge=>{var Ae;return(Ae=g.onNodeLabelChange)==null?void 0:Ae.call(g,$,String(ge))},onEditEnd:()=>N(!1)}):void 0}),xe=Array.isArray((ae=e==null?void 0:e.config)==null?void 0:ae.ports)?e.config.ports.map(ge=>f.jsx(cv,{...ge},`${ge.id}:${ge.role}`)):null;return n?f.jsxs(V.Box,{ref:E,...ie,onClick:F,onDoubleClick:H,onMouseEnter:G,onMouseLeave:ce,cursor:"pointer",position:"relative",children:[me,!p&&(K||Z&&Z.length>0)&&P&&!q&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>I(!0),onMouseLeave:ce}),K?f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:se,transformOrigin:W,left:"50%",pointerEvents:"auto",transform:ue,onMouseEnter:()=>I(!0),onMouseLeave:ce,willChange:"transform",children:K({nodeId:$,nodeData:e,isRoot:$==="root",isParent:!0,isHovered:P,setIsHovered:I})}):f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:se,transformOrigin:W,left:"50%",bg:v,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:ue,boxShadow:"lg",onMouseEnter:()=>I(!0),onMouseLeave:ce,willChange:"transform",children:f.jsxs(V.HStack,{px:2,gap:2,"data-flow-grid-toolbar":(e==null?void 0:e.type)==="grid"?"":void 0,css:(e==null?void 0:e.type)==="grid"?{"& button svg":{width:"22px",height:"22px",minWidth:"22px",minHeight:"22px"}}:void 0,children:[Z.map((ge,Ae)=>f.jsxs(V.Box,{display:"contents",children:[Ae>0&&f.jsx(V.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(Rd,{icon:ge.icon,label:ge.label,color:S,bgColor:v,borderColor:C,textColor:S,boxSize:5,onClick:Le=>{var be;Le.stopPropagation(),(be=g.onNodeHoverAction)==null||be.call(g,ge.id,$,e)}})]},ge.id)),ne&&f.jsx(ne,{data:e})]})})]}),r({id:$,data:e,isActive:T,isHovered:P,isLowZoom:q,isEditing:M,onSelect:F,onEditStart:()=>k(!0),onEditEnd:()=>k(!1)}),f.jsx(Tm,{data:e}),D&&!((we=e==null?void 0:e.config)!=null&&we.parentContainer)&&(($e=e==null?void 0:e.config)==null?void 0:$e.collapsed)!==void 0&&(()=>{var Le;const ge=x==="TB"||x==="BT",Ae=t||x==="RL";return f.jsx(V.IconButton,{position:"absolute",...ge?{[x==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:Ae?void 0:"-75px",left:Ae?"-75px":void 0,top:"50%",transform:"translateY(-50%)"},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:y.readOnly,onClick:be=>{var Xe;be.stopPropagation(),(Xe=g.onNodeCollapse)==null||Xe.call(g,$,!e.config.collapsed)},bgColor:Te(((Le=e==null?void 0:e.viewProps)==null?void 0:Le.bgColor)||b),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(ee.PiPlusBold,{size:30,color:Te("gray.800")}):f.jsx(ee.PiMinusBold,{size:30,color:Te("gray.800")})})})()]}):f.jsxs(V.Box,{ref:E,...ie,onClick:F,onDoubleClick:H,onMouseEnter:G,onMouseLeave:ce,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[me,xe,!p&&(K||Z&&Z.length>0)&&P&&!q&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>I(!0),onMouseLeave:ce}),K?f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:se,transformOrigin:W,left:"50%",pointerEvents:"auto",transform:ue,onMouseEnter:()=>I(!0),onMouseLeave:ce,willChange:"transform",children:K({nodeId:$,nodeData:e,isRoot:$==="root",isParent:!!n,isHovered:P,setIsHovered:I})}):f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:se,transformOrigin:W,left:"50%",bg:v,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:ue,boxShadow:"lg",onMouseEnter:()=>I(!0),onMouseLeave:ce,willChange:"transform",children:f.jsxs(V.HStack,{px:2,gap:2,"data-flow-grid-toolbar":(e==null?void 0:e.type)==="grid"?"":void 0,css:(e==null?void 0:e.type)==="grid"?{"& button svg":{width:"22px",height:"22px",minWidth:"22px",minHeight:"22px"}}:void 0,children:[Z.map((ge,Ae)=>f.jsxs(V.Box,{display:"contents",children:[Ae>0&&f.jsx(V.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(Rd,{icon:ge.icon,label:ge.label,color:S,bgColor:v,borderColor:C,textColor:S,boxSize:5,onClick:Le=>{var be;Le.stopPropagation(),(be=g.onNodeHoverAction)==null||be.call(g,ge.id,$,e)}})]},ge.id)),ne&&f.jsx(ne,{data:e})]})})]}),f.jsxs(V.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[D&&!((Ue=e==null?void 0:e.config)!=null&&Ue.parentContainer)&&((Ve=e==null?void 0:e.config)==null?void 0:Ve.collapsed)!==void 0&&!n&&(()=>{var be,Xe,ut;const ge=x==="TB"||x==="BT",Ae=t||x==="RL",Le=(be=e==null?void 0:e.config)!=null&&be.labelBelow&&w[$]!=="properties"?((((Xe=e==null?void 0:e.viewProps)==null?void 0:Xe.fontSize)||1)*100+100)/2:void 0;return f.jsx(V.IconButton,{position:"absolute",...ge?{[x==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:Ae?void 0:Le===void 0?"-75px":`calc(50% - ${Le+75}px)`,left:Ae?Le===void 0?"-75px":`calc(50% - ${Le+75}px)`:void 0,alignSelf:Le===void 0?"center":void 0,top:Le===void 0?void 0:`${Le}px`,transform:Le===void 0?void 0:"translateY(-50%)",zIndex:Le===void 0?void 0:1},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:y.readOnly,onClick:Re=>{var Ke;Re.stopPropagation(),(Ke=g.onNodeCollapse)==null||Ke.call(g,$,!e.config.collapsed)},bgColor:Te(((ut=e==null?void 0:e.viewProps)==null?void 0:ut.bgColor)||b),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(ee.PiPlusBold,{size:30,color:Te("gray.800")}):f.jsx(ee.PiMinusBold,{size:30,color:Te("gray.800")})})})(),r({id:$,data:e,isActive:T,isHovered:P,isLowZoom:q,isEditing:M,onSelect:F,onEditStart:()=>k(!0),onEditEnd:()=>k(!1)})]}),f.jsx(Tm,{data:e,caption:!!((tt=e.config)!=null&&tt.labelBelow)&&w[$]!=="properties"})]})},Qn=j.memo(fE),hE=({id:e,data:r,isActive:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var g,y,b,x,w,v,C,S;const{themeColor:s}=He(),{colorText:a}=at(),c=((g=r==null?void 0:r.viewProps)==null?void 0:g.bgColor)==="transparent",l=((y=r==null?void 0:r.viewProps)==null?void 0:y.outline)===!0,{highlightColor:d,borderColor:u,textColor:h}=Gn(((b=r==null?void 0:r.viewProps)==null?void 0:b.bgColor)||s),p=Te(((x=r==null?void 0:r.viewProps)==null?void 0:x.textColor)||(c||l?a:h)),m=((w=r==null?void 0:r.viewProps)==null?void 0:w.borderColor)||(l?!c&&((v=r==null?void 0:r.viewProps)==null?void 0:v.bgColor)||s:u);return f.jsx(V.Box,{"data-flow-node-surface":"",borderRadius:(C=r==null?void 0:r.viewProps)==null?void 0:C.borderRadius,bgColor:l?"transparent":d,...Wn(r==null?void 0:r.viewProps,m,t,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:f.jsxs(V.Flex,{justifyContent:"start",alignItems:"center",gap:8,w:"fit-content",maxW:900,minW:0,fontSize:"5xl",lineHeight:"normal",children:[((S=r==null?void 0:r.config)==null?void 0:S.icon)&&f.jsx(V.Box,{flexShrink:0,children:f.jsx(cr,{name:r.config.icon,size:80,color:p})}),f.jsx(cn,{nodeId:e,label:(r==null?void 0:r.label)||(r==null?void 0:r.text)||"",color:p,isEditing:n,onEditStart:o,onEditEnd:i})]})})};function xu(e,r,t){const{readOnly:n,selectedNodeIds:o}=He(),i=o.includes(e),s=j.useRef(i),a=j.useRef(t);a.current=t,j.useEffect(()=>{s.current&&!i&&r&&!n&&a.current(),s.current=i},[i,r,n])}function eo(){const{nodeViewModes:e,setNodeViewMode:r,allNodesIconLabel:t,setAllNodesIconLabel:n}=He();return{allNodesIconLabel:t,setAllNodesIconLabel:n,getNodeViewMode:o=>e[o]??"default",showNodeProperties:o=>r(o,"properties"),restoreNodeView:o=>r(o,"default"),toggleNodeView:o=>r(o,e[o]==="properties"?"default":"properties"),setNodeViewMode:r}}const pE=({id:e,isActive:r,data:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var w,v,C,S,E,R,P,I,M,k,_,N,$;const{themeColor:s}=He(),{colorText:a}=at(),c=((w=t==null?void 0:t.viewProps)==null?void 0:w.bgColor)==="transparent",l=((v=t==null?void 0:t.viewProps)==null?void 0:v.outline)===!0,d=!c&&((C=t==null?void 0:t.viewProps)==null?void 0:C.bgColor)||s,{borderColor:u,highlightColor:h,textColor:p}=Gn(d),m=Te(((S=t==null?void 0:t.viewProps)==null?void 0:S.textColor)||(c||l?a:p)),g=c&&!l&&!((E=t==null?void 0:t.viewProps)!=null&&E.borderColor)?"transparent":Te(((R=t==null?void 0:t.viewProps)==null?void 0:R.borderColor)||(l?d:u)),y=c||l?"transparent":d!=null&&d.startsWith("#")?d:Te(h),b=(P=t==null?void 0:t.config)==null?void 0:P.icon,x=(t==null?void 0:t.label)??(t==null?void 0:t.text)??"";if((I=t==null?void 0:t.config)!=null&&I.labelBelow){const D=(((M=t==null?void 0:t.viewProps)==null?void 0:M.fontSize)||1)*100;return f.jsxs(V.Flex,{"data-flow-icon-label":"",css:{"--flow-grid-on-surface-color":m},direction:"column",align:"center",gap:"24px",width:`${Math.max(D+200,360)}px`,position:"relative",children:[f.jsx(V.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${D+100}px`,height:`${D+100}px`,flexShrink:0,borderRadius:(k=t==null?void 0:t.viewProps)==null?void 0:k.borderRadius,backgroundColor:y,...Wn(t==null?void 0:t.viewProps,g,r,2),children:!!b&&f.jsx(cr,{name:b,size:D,color:m})}),f.jsx(V.Flex,{"data-flow-icon-caption":"",direction:"column",align:"center",gap:"8px",justify:"center",width:"100%",minW:0,textAlign:"center",children:f.jsx(cn,{nodeId:e,label:x,color:`var(--flow-grid-caption-color, ${Te(((_=t==null?void 0:t.viewProps)==null?void 0:_.textColor)||a)})`,isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0})})]})}return f.jsxs(V.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:(N=t==null?void 0:t.viewProps)==null?void 0:N.borderRadius,bgColor:y,style:{backgroundColor:y},textTransform:"capitalize",...Wn(t==null?void 0:t.viewProps,g,r,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!b&&f.jsx(V.Flex,{align:"center",py:14,mr:x?8:0,flexShrink:0,children:f.jsx(cr,{name:b,size:((($=t==null?void 0:t.viewProps)==null?void 0:$.fontSize)||1)*100,color:m},m)}),(x||!b)&&f.jsx(V.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:f.jsx(cn,{nodeId:e,label:x,color:m,isEditing:n,onEditStart:o,onEditEnd:i})})]})};function bo({onExpand:e,toggleLabel:r="Show properties",toggleDisabled:t=!1,renderCompact:n=pE,...o}){const{colorMode:i,callbacks:s}=He();return f.jsx(Qn,{...o,hoverLeaveDelay:e?350:0,children:a=>f.jsxs(V.Box,{position:"relative",children:[f.jsx(n,{...a}),e&&(a.isHovered||a.isActive)&&f.jsx(V.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:f.jsx(Ge,{label:r,children:f.jsx(Ne,{"aria-label":r,icon:f.jsx(V.Icon,{as:ee.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:i==="dark"?"gray.100":"gray.800",disabled:t,onClick:c=>{var l;c.stopPropagation(),a.isActive||a.onSelect(c,!0),(l=s.onNodeViewToggle)==null||l.call(s,o.data.id),e()}})})})]})})}const dv=(e,r,t)=>{var h,p,m,g;const n=((h=e==null?void 0:e.viewProps)==null?void 0:h.bgColor)||r,[o]=n.split("."),i=Gn(n),s=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,a=n==="transparent"||s,c=t==="dark"?"gray.200":"gray.900",l=a?"transparent":n!=null&&n.startsWith("#")?Te(n):Te(i.bgColor),d=Te(((m=e==null?void 0:e.viewProps)==null?void 0:m.textColor)||(a?c:i.textColor)),u=Te(((g=e==null?void 0:e.viewProps)==null?void 0:g.borderColor)||(s?n==="transparent"?r:n:i.borderColor));return{...i,bgColor:a?"transparent":i.bgColor,highlightColor:a?"transparent":i.highlightColor,isTransparent:a,propertyColor:a?c:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:l,hextextColor:d,hexborderColor:u}},gE=(e,r=350)=>`${String(e).substring(0,r)}${String(e).length>r?"...":""}`,yE=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,uv=600,mE=3,bE=e=>{const r=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(r*28+30,200)};function xE({headerTitle:e,hasContent:r,data:t,icon:n,colors:o,hasConfig:i,id:s,isActive:a,isHovered:c,isEditing:l,onSelect:d,onEditStart:u,onEditEnd:h,props:p,objVisible:m,setObjVisible:g,onShowNativeIcon:y}){var v,C,S,E;const{callbacks:b}=He();if(r&&!m&&t.label===""&&(((v=t.config)==null?void 0:v.contentFormat)==="html"||((C=t.config)==null?void 0:C.contentFormat)==="jsx"))return null;const x=p.onShowIcon??y,w=x?"Show icon":m?"Show content":"Show properties";return f.jsx(f.Fragment,{children:(e||r||((S=t.config)==null?void 0:S.form)||(a||c)&&y)&&f.jsxs(V.Flex,{justify:"flex-start",direction:"row",p:r||Object.entries(t.description||{}).length?8:20,borderBottomWidth:1,minWidth:"max-content !important",width:"100%",textTransform:"capitalize",align:"center",textOverflow:"ellipsis",alignItems:"center",fontWeight:"bold",color:o.propertyColor,bgColor:o.highlightColor,borderBottomColor:!i&&!r?"transparent":o.hexborderColor,children:[!!n&&f.jsx(V.Flex,{mr:6,alignItems:"center",flexShrink:0,children:f.jsx(cr,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),f.jsx(cn,{nodeId:s,label:yE(e),color:((E=t==null?void 0:t.viewProps)==null?void 0:E.textColor)||o.propertyColor,isEditing:l,onEditStart:u,onEditEnd:h}),(a||c)&&(r||x)&&f.jsx(V.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:f.jsx(Ge,{label:w,children:f.jsx(Ne,{"aria-label":w,icon:f.jsx(V.Icon,{as:ee.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:R=>{var P;R.stopPropagation(),a||d(R),x?x():g(!m),(P=b.onNodeViewToggle)==null||P.call(b,s)}})})})]})})}function vE({data:e,resourcePorts:r,inspecting:t,form:n,inspectionPorts:o,extraPorts:i,colors:s,direction:a,uniformKeyWidth:c}){const{edgeById:l}=Xt(),d=new Set;for(const{data:u}of l.values())u.source===e.id&&u.sourceProperty!==void 0&&d.add(`source:${u.sourceProperty}`),u.target===e.id&&u.targetProperty!==void 0&&d.add(`target:${u.targetProperty}`);return f.jsx(V.Box,{children:Object.entries(e.description||{}).map(([u,h],p)=>{var _,N,$;const m=r&&Object.keys(r).find(D=>D.slice(D.indexOf(":")+1)===u),g=t&&((_=n==null?void 0:n.type.ports)==null?void 0:_[u]),y=m??(g?`${g.kind}:${u}`:u),b=o.find(D=>D.id===y),x=m?"source":b==null?void 0:b.role,w=d.has(`source:${y}`),v=d.has(`target:${y}`),C=i.some(D=>D.id===u),S=h===""&&(C||(x?d.has(`${x}:${y}`):w||v)),E=x??(w!==v?w?"source":"target":void 0),R=(b==null?void 0:b.side)??(E?E==="source"!=(a==="RL")?"right":"left":void 0),P=S&&R==="right"?"right":"left",I=(b==null?void 0:b.label)??(g==null?void 0:g.label)??(C?u.replace(/^(template|input|output|config|error):/,""):u),M=sr(s.wordBeforeDot)[typeof h],k=sr(s.wordBeforeDot).property;return f.jsxs(V.Box,{"data-flow-property":m&&(a==="TB"||a==="BT")?void 0:y,"data-flow-port-role":x,"data-flow-inspection-row":t?"":void 0,children:[f.jsxs(V.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[f.jsx(V.Flex,{justifyContent:"start",align:"center",background:s.highlightColor,width:S?"100%":`${c}px`,minWidth:`${c}px`,borderRightColor:s.hexborderColor,borderRightWidth:S?0:1,children:f.jsx(V.Text,{py:5,px:10,w:"100%",textAlign:P,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((N=e==null?void 0:e.viewProps)==null?void 0:N.textColor)||(s.isTransparent?s.hextextColor:k),children:I})}),!S&&f.jsx(V.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:s.hexbgColor,w:uv,maxH:200,children:f.jsx(V.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:(($=e==null?void 0:e.viewProps)==null?void 0:$.textColor)||(s.isTransparent?s.hextextColor:M),fontWeight:400,children:gE(h)})})]}),p!==Object.entries(e.description||{}).length-1&&f.jsx(V.Box,{borderTopWidth:1,my:0,borderColor:s.hexborderColor})]},u)})})}function wE(e){var w,v,C,S,E;const{themeColor:r,colorMode:t,direction:n}=He(),o=eo(),i=o.getNodeViewMode(e.data.id)==="properties",s=R=>o.setNodeViewMode(e.data.id,R?"properties":"default"),a=!!e.onShowIcon||i||typeof((w=e.data.config)==null?void 0:w.content)!="string"&&!(((v=e.data.config)==null?void 0:v.contentFormat)==="jsx"&&Array.isArray((C=e.data.config)==null?void 0:C.content)),{bindings:c,data:l,schema:d}=j.useContext($t),u=(S=c==null?void 0:c[e.data.id])==null?void 0:S.portResources,h=c?Hn(c,e.data.id,d):l&&d?un(l,e.data.id,d):void 0,p=h&&Oe(l,"address"in h?h.address:e.data.id),m=p&&typeof p=="object"&&h?Object.fromEntries(Object.keys(h.type.properties).filter(R=>{var P;return Object.prototype.hasOwnProperty.call(p,R)&&Eo((P=h.fields[R])==null?void 0:P.$visibleWhen,l)}).map(R=>[R,p[R]!==null&&typeof p[R]=="object"?JSON.stringify(p[R],null,2):p[R]===null?"null":p[R]])):{},g=u?Object.fromEntries(Object.entries(u).map(([R,P])=>{var I;return[R.slice(R.indexOf(":")+1),((I=Oe(l,P))==null?void 0:I.name)??P.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:m,y=a&&!u?((E=e.data.config)==null?void 0:E.ports)??[]:[],b=y.filter(R=>!Object.prototype.hasOwnProperty.call(g,R.id)&&!Object.entries((h==null?void 0:h.type.ports)??{}).some(([P,I])=>`${I.kind}:${P}`===R.id&&Object.prototype.hasOwnProperty.call(g,P))),x={...g,...Object.fromEntries(b.map(R=>[R.id,""]))};return{themeColor:r,colorMode:t,direction:n,objVisible:i,setObjVisible:s,inspecting:a,resourcePorts:u,form:h,description:x,inspectionPorts:y,extraPorts:b}}const Uo=e=>{var w,v,C,S,E,R,P,I;const{config:r}=He(),{themeColor:t,colorMode:n,direction:o,objVisible:i,setObjVisible:s,inspecting:a,resourcePorts:c,form:l,description:d,inspectionPorts:u,extraPorts:h}=wE(e),p=eo(),m=p.getNodeViewMode(e.data.id)==="icon-label",g=!e.onShowIcon&&(typeof((w=e.data.config)==null?void 0:w.content)=="string"||((v=e.data.config)==null?void 0:v.contentFormat)==="jsx"&&Array.isArray((C=e.data.config)==null?void 0:C.content)),y=j.useRef(m);m&&(y.current=!0),xu(e.data.id,g&&!((S=e.data.config)!=null&&S.parentContainer)&&p.allNodesIconLabel&&!m&&y.current,()=>p.setNodeViewMode(e.data.id,"icon-label"));const x=!e.onShowIcon&&!((E=e.data.config)!=null&&E.parentContainer)?()=>p.setNodeViewMode(e.data.id,"icon-label"):void 0;return!e.onShowIcon&&m?f.jsx(bo,{...e,data:{...e.data,label:e.data.label??e.data.headerTitle,config:{...e.data.config,labelBelow:!0,icon:((R=e.data.config)==null?void 0:R.icon)||(g?((P=e.data.config)==null?void 0:P.contentFormat)==="html"?"PiFileHtml":((I=e.data.config)==null?void 0:I.contentFormat)==="jsx"?"PiFileJsx":"PiMarkdownLogo":"PiBracketsCurly")}},onExpand:()=>p.restoreNodeView(e.data.id)}):f.jsx(Qn,{...e,data:{...e.data,description:d},hoverLeaveDelay:g||e.onShowIcon||x?350:0,children:({id:M,data:k,isActive:_,isHovered:N,isEditing:$,onSelect:D,onEditStart:T,onEditEnd:Z})=>{var te,X,ie,me,xe,fe,U,re,de,Pe,ae,we,$e,Ue,Ve,tt,ge,Ae,Le;const K=dv(k,t,n),ne=k.label??k.headerTitle,se=Object.entries(k.description||{}).length>0,W=bE(k.description),ue=(X=(te=e.data)==null?void 0:te.config)==null?void 0:X.icon,q=(me=(ie=e.data)==null?void 0:ie.config)==null?void 0:me.content,F=g&&!i&&k.label===""&&(((xe=k.config)==null?void 0:xe.contentFormat)==="html"||((fe=k.config)==null?void 0:fe.contentFormat)==="jsx"),H=g&&!i&&(((U=k.config)==null?void 0:U.contentFormat)==="html"||((re=k.config)==null?void 0:re.contentFormat)==="jsx")&&((de=k.viewProps)==null?void 0:de.width)!==void 0&&k.viewProps.width!=="100%",G=((Pe=k==null?void 0:k.viewProps)==null?void 0:Pe.borderRadius)??"53px",ce=Wn(k==null?void 0:k.viewProps,K.hexborderColor,_,mE);return f.jsx(V.Flex,{justifyContent:"space-between",...k==null?void 0:k.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:G,overflow:"hidden",alignItems:"center",style:{backgroundColor:K.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:e.contentWidth??(F||H?((ae=k.viewProps)==null?void 0:ae.width)!==void 0&&k.viewProps.width!=="100%"?k.viewProps.width:"max-content":"100%"),maxW:F?"calc(100vw - 40px)":void 0,height:e.contentHeight??((we=k.viewProps)==null?void 0:we.height),minW:e.contentMinWidth??(e.contentWidth||F||H?0:g||e.onShowIcon?W+uv+ce.borderWidth*2:void 0),...ce,children:f.jsxs(V.Flex,{width:"100%",height:e.contentHeight!==void 0?"100%":void 0,minH:e.contentHeight!==void 0?0:void 0,direction:"column",position:"relative",borderRadius:G,borderColor:K.hexborderColor,borderWidth:0,overflow:"hidden",children:[e.surfaceOverlay,!e.fillBody&&f.jsx(xE,{headerTitle:ne,hasContent:g,data:k,icon:ue,colors:K,hasConfig:se,id:M,isActive:_,isHovered:N,isEditing:$,onSelect:D,onEditStart:T,onEditEnd:Z,props:e,objVisible:i,setObjVisible:s,onShowNativeIcon:x}),e.headerOverlay,g&&!i?f.jsx(V.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:K.highlightColor,p:["html","jsx"].includes((Ue=($e=e.data)==null?void 0:$e.config)==null?void 0:Ue.contentFormat)?0:12,fontSize:"5xl",lineHeight:"normal",...e.contentProps,children:f.jsx(bu,{nodeId:M,content:q,format:(tt=(Ve=e.data)==null?void 0:Ve.config)==null?void 0:tt.contentFormat,fillBody:e.fillBody,autoHeight:F,color:((ge=k==null?void 0:k.viewProps)==null?void 0:ge.textColor)||K.hextextColor,onSubmit:e.onContentSubmit,onDraftChange:e.onContentDraftChange,plainText:e.contentPlainText,placeholder:e.contentPlaceholder??((Ae=r.nodePlaceholder)==null?void 0:Ae.call(r,e.data.id,e.data))??((Le=e.data.config)!=null&&Le.promptTurn?"Thinking...":void 0)})}):f.jsx(vE,{data:k,resourcePorts:c,inspecting:a,form:l,inspectionPorts:u,extraPorts:h,colors:K,direction:o,uniformKeyWidth:W}),e.footer]})})}})};Uo.displayName="NodeJsonObjectView";const fv=e=>{var h,p,m,g,y,b,x,w,v,C,S,E;const r=eo(),[t,n]=j.useState(!1),o=r.getNodeViewMode(e.data.id)==="properties",i=R=>{n(R),r.setNodeViewMode(e.data.id,R?"properties":"default")},{callbacks:s,readOnly:a}=He(),c=(p=(h=e.data)==null?void 0:h.config)==null?void 0:p.parentContainer;xu(e.data.id,o&&((g=(m=e.data)==null?void 0:m.config)==null?void 0:g.labelBelow)&&!c,()=>i(!1));const l=c?"Show parent":"Show properties",d=c||((b=(y=e.data)==null?void 0:y.config)==null?void 0:b.form)||((v=(w=(x=e.data)==null?void 0:x.config)==null?void 0:w.ports)==null?void 0:v.length),u=d?()=>{var R;c?(R=s.onNodeCollapse)==null||R.call(s,e.data.id,!1):i(!0)}:void 0;return!c&&e.data.type==="text"&&r.getNodeViewMode(e.data.id)==="icon-label"?f.jsx(bo,{...e,renderCompact:void 0,data:{...e.data,config:{...e.data.config,labelBelow:!0,icon:((C=e.data.config)==null?void 0:C.icon)||"PiTextT"}},toggleLabel:"Show text",onExpand:()=>r.restoreNodeView(e.data.id)}):!c&&d&&o?f.jsx(Uo,{...e,editOnMount:t,onShowIcon:()=>i(!1)}):f.jsx(bo,{...e,onOpenView:u&&(c||(E=(S=e.data)==null?void 0:S.config)!=null&&E.labelBelow)?()=>{var R;u(),(R=s.onNodeViewToggle)==null||R.call(s,e.data.id)}:void 0,toggleLabel:!c&&e.data.type==="text"?"Show icon":l,toggleDisabled:c&&a,onExpand:!c&&e.data.type==="text"?()=>r.setNodeViewMode(e.data.id,"icon-label"):u})};function CE(e){var b,x,w,v,C,S;const{config:r,callbacks:t,readOnly:n,selectedNodeIds:o,nodeRadiusPreviews:i,nodeViewModes:s,allNodesIconLabel:a}=He(),c=i[e.data.id]??((b=e.data.viewProps)==null?void 0:b.borderRadius),[l,d]=j.useState(!1),u=eo(),{border:h,colorText:p}=at(),m=(x=r.customViews)==null?void 0:x.gridContent,g=(s[e.data.id]??(a?"icon-label":"default"))==="icon-label",y=j.useRef(g);return g&&(y.current=!0),xu(e.data.id,a&&!g&&y.current,()=>u.setNodeViewMode(e.data.id,"icon-label")),g?f.jsx(V.Box,{"data-grid-document":((w=e.data.config)==null?void 0:w.documentId)??"",children:f.jsx(bo,{...e,data:{...e.data,viewProps:{...e.data.viewProps,borderRadius:c},config:{...e.data.config,labelBelow:!0,icon:((v=e.data.config)==null?void 0:v.icon)||"PiGridFour"}},toggleLabel:"Show grid",onExpand:()=>u.restoreNodeView(e.data.id)})}):f.jsxs(f.Fragment,{children:[f.jsx(Qn,{...e,onOpenView:()=>d(!0),children:({data:E,isActive:R})=>{var P,I,M,k,_,N,$,D;return f.jsx(V.Box,{"data-flow-node-surface":"","data-grid-document":((P=E.config)==null?void 0:P.documentId)??"",width:`${((M=(I=E.config)==null?void 0:I.gridSize)==null?void 0:M.width)??600}px`,height:`${((_=(k=E.config)==null?void 0:k.gridSize)==null?void 0:_.height)??440}px`,overflow:"hidden",position:"relative",bg:((N=E.viewProps)==null?void 0:N.bgColor)??"transparent",color:(($=E.viewProps)==null?void 0:$.textColor)??p,borderRadius:`${c??0}px`,...Wn(E.viewProps,Te(((D=E.viewProps)==null?void 0:D.borderColor)??h),R,0),children:m?f.jsx(m,{...e}):f.jsx(V.Box,{p:4,children:E.label??"Grid"})})}}),f.jsx(yu,{nodeAddress:e.data.id,active:o.includes(e.data.id),label:e.data.label??"Grid",open:l&&!n,onClose:()=>d(!1),children:f.jsx($t.Provider,{value:{data:{metadata:{label:e.data.label??"",subtitle:((C=e.data.config)==null?void 0:C.subtitle)??"",icon:((S=e.data.config)==null?void 0:S.icon)??"PiGridFour"}},bindings:{[e.data.id]:{address:"root.metadata",type:"GridMetadata"}},schema:{GridMetadata:{kind:"object",properties:{label:{optional:!0,type:{kind:"string"}},subtitle:{optional:!0,type:{kind:"string"}},icon:{optional:!0,type:{kind:"string"}}}}},editable:!!r.editable&&!n,callbacks:{onFormChange:E=>{var P,I,M;if(n||!r.editable)return;const R=String(E.value??"");E.address==="root.metadata.label"?(P=t.onNodeLabelChange)==null||P.call(t,e.data.id,R):E.address==="root.metadata.subtitle"?(I=t.onNodeSubtitleChange)==null||I.call(t,e.data.id,R):E.address==="root.metadata.icon"&&((M=t.onNodeIconChange)==null||M.call(t,e.data.id,R))}}},children:f.jsx(Vd,{nodeAddress:e.data.id})})})]})}function SE(e){var M,k,_;const{callbacks:r,config:t,readOnly:n,themeColor:o,colorMode:i}=He(),{canvas:s,background:a,border:c,colorText:l}=at(),d=dv(e.data,o,i),u=(M=t.promptBudget)==null?void 0:M.call(t,e.data.id),h=u&&u.limit>0?Math.min(100,Math.max(0,u.used/u.limit*100)):void 0,p=j.useRef(),[m,g]=j.useState(!1),[y,b]=j.useState(""),[x,w]=j.useState(1),[v,C]=j.useState(),S=typeof((k=e.data.config)==null?void 0:k.content)=="string"?e.data.config.content:"",E=v??S,R=!n&&t.editable!==!1&&!m&&!!r.onPromptSubmit&&!!E.trim(),P=R?s:a;j.useEffect(()=>C(void 0),[S]),j.useEffect(()=>()=>{var N;return(N=p.current)==null?void 0:N.abort()},[]);const I=async(N=E)=>{if(p.current||n||t.editable===!1||!N.trim()||!r.onPromptSubmit)return;const $=new AbortController;p.current=$,g(!0),b("");try{await r.onPromptSubmit({nodeId:e.data.id,prompt:N,temperature:x},$.signal)}catch(D){$.signal.aborted||b(D instanceof Error?D.message:"Prompt execution failed.")}finally{p.current===$&&(p.current=void 0,g(!1))}};return f.jsx(Uo,{...e,contentProps:{px:8,py:6,minH:"200px",flexShrink:0,overscrollBehavior:"contain"},contentPlainText:!0,contentPlaceholder:"How can I assist you?",surfaceOverlay:m?f.jsx(mu,{active:!0,label:"Prompt running"}):void 0,headerOverlay:h!==void 0?f.jsx(V.Box,{position:"relative",h:"0",flexShrink:0,"aria-hidden":"true","data-prompt-budget":"",children:f.jsx(V.Box,{position:"absolute",left:"0",right:"0",top:"-1px",h:"2px",bg:d.highlightColor,children:f.jsx(V.Box,{className:"flow-sdk-edge-trace",h:"100%",width:`${h}%`,style:{animation:"none",backgroundImage:"repeating-linear-gradient(90deg, currentColor 0 6px, transparent 6px 12px)",color:d.hextextColor,opacity:.75}})})}):void 0,onContentDraftChange:C,onContentSubmit:!m&&r.onPromptSubmit?N=>void I(N):void 0,data:{...e.data,viewProps:{...e.data.viewProps,containerType:"inline-size"},config:{...e.data.config,content:S,contentFormat:"markdown",icon:((_=e.data.config)==null?void 0:_.icon)??"PiBrain"}},footer:f.jsxs(V.Box,{"data-prompt-controls":"",background:d.highlightColor,flexShrink:0,width:"100%",pl:8,pr:4,pt:1,pb:4,onPointerDown:N=>N.stopPropagation(),onClick:N=>N.stopPropagation(),css:{"@container (max-width: 300px)":{paddingLeft:"16px"},'& [role="combobox"] > svg':{width:"32px",height:"32px"},'& [role="option"]':{fontSize:"28px"},'& [role="option"] svg':{width:"32px",height:"32px"}},children:[y&&f.jsx(V.Text,{role:"alert",fontSize:"sm",color:"red.500",children:y}),f.jsxs(V.HStack,{justifyContent:"space-between",alignItems:"center",gap:3,children:[f.jsxs(V.HStack,{minW:0,gap:2,flexWrap:"wrap",color:d.hextextColor,children:[f.jsx(V.Text,{fontSize:"32px",lineHeight:"1.15",fontWeight:"bold",children:"Thinking effort"}),f.jsxs(It,{"aria-label":"Thinking effort",value:String(x),disabled:n||t.editable===!1||m||!r.onPromptSubmit,style:{width:"176px",height:"60px",flexShrink:0,fontSize:"32px",color:d.hextextColor},onValueChange:N=>w(Number(N)),children:[f.jsx("option",{value:"0",children:"Low"}),f.jsx("option",{value:"1",children:"Mid"}),f.jsx("option",{value:"2",children:"Max"})]})]}),f.jsx(Ge,{label:m?"Cancel prompt":r.onPromptSubmit?"Run prompt":"Prompt execution is not connected",children:f.jsx(Ne,{"aria-label":m?"Cancel prompt":"Run prompt","aria-busy":m,variant:"ghost",rounded:"50%",width:"80px",minWidth:"80px",height:"80px",flexShrink:0,mr:"2px",bg:P,color:l,_hover:{bg:P,color:l},_active:{bg:P},css:{...gr(`var(--chakra-colors-${P.replace(".","-")})`,`var(--chakra-colors-${c.replace(".","-")})`),"& > svg":{width:"40px",height:"40px"}},icon:m?f.jsx(ee.PiStop,{size:40}):f.jsx(ee.PiPaperPlaneRight,{size:40}),disabled:n||t.editable===!1||!m&&!R,rememberAction:!1,onClick:()=>{var N;return m?(N=p.current)==null?void 0:N.abort():void I()}})})]})]})})}const hv=e=>f.jsx(fv,{...e,renderCompact:hE}),pv=e=>f.jsx(fv,{...e}),gv=({containerStyle:e,...r})=>{const{selectedNodeIds:t}=He();return f.jsx(Qn,{...r,editOnMount:t.includes(r.data.id),children:n=>f.jsx(V.Box,{bg:e.textColor==="transparent"?"transparent":e.labelBg,p:`${e.fontSize/5}px`,fontFamily:_r,lineHeight:1,w:"fit-content",children:f.jsx(cn,{nodeId:n.id,label:n.data.label??n.data.headerTitle??"Container",color:e.textColor,fontSize:`${e.fontSize}px`,isEditing:n.isEditing,onEditStart:n.onEditStart,onEditEnd:n.onEditEnd})})})};hv.displayName="text";pv.displayName="arrayView";gv.displayName="ParentContainerView";const jE={grid:CE,prompt:SE,objectView:Uo,arrayView:pv,text:hv,parentContainer:gv},EE=({children:e,pattern:r="dot",backgroundColor:t})=>{const{colorMode:n}=He(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",s=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return r==="none"?f.jsx(V.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:t,children:e}):f.jsxs(V.Box,{"data-flow-background":r,position:"relative",width:"100%",height:"100%",padding:0,bg:t,children:[f.jsx(V.Box,{position:"absolute",top:0,left:0,right:0,bottom:0,width:"100%",height:"100%",zIndex:0,pointerEvents:"none",style:{backgroundImage:r==="dot"?`radial-gradient(var(${i}) 8%, transparent 8%)`:r==="steel"?`repeating-linear-gradient(45deg, var(${s}) 0, var(${s}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${s}) 1px, transparent 1px), linear-gradient(90deg, var(${s}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),f.jsx(V.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},_E=.4,qr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},kE=({nodes:e,edges:r})=>{var ur;const{themeColor:t,spacing:n,edgeRadius:o,backgroundVariant:i,backgroundSelected:s,setBackgroundSelected:a,edgeColor:c,direction:l,nodeAlignment:d,edgeMode:u,compactPropertyLayout:h,workflowContract:p,parentNodeStyle:m,engineRef:g,callbacks:y,config:b,selectedNodeIds:x,setSelectedNodeIds:w,selectedEdgeId:v,setSelectedEdgeId:C,setIsPerformanceMode:S,setNodeGridOptions:E,fillRadiusEditedIds:R,isZoomMode:P,setIsZoomMode:I,isMultiSelectMode:M,setIsMultiSelectMode:k,isDragMode:_,setIsDragMode:N,isEdgeHandlesEnabled:$,setIsEdgeHandlesEnabled:D,isArrayNodeMode:T}=He(),Z=j.useRef(null),[K,ne]=j.useState(null),se=j.useRef(null),W=e.length>200;j.useEffect(()=>{S(W)},[W,S]);const{edgeSep:ue,rankSep:q,spacingFactor:F}=j.useMemo(()=>{const z=o1(e.length),O=b.nodeGridSpacing==="layout"&&n<.5?n*1.3:n<1?.3+.7*n:.5+.5*n;return{edgeSep:z.edgeSep*O,rankSep:z.rankSep*O,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n,b.nodeGridSpacing]),{bgColor:H}=Gn(t),{canvas:G,borderSecondary:ce,colorText:te}=at(),X=i==="transparent"?"transparent":b.backgroundColor||G,ie=j.useCallback(z=>{if(!z)return Te(t);switch(z){case"dark":return Te(X);case"light":return Te(ce);default:return Te(z)}},[t,X,ce]),me=b.colorMode==="dark",xe=me?Te("gray.500"):ln,fe=me?H!=null&&H.includes("gray")?"whitesmoke":ie(H):xe,U=c?ie(c):xe,re=j.useMemo(()=>{var z;return b.initialViewport||{pan:{x:0,y:0},zoom:(z=b.nodeGrid)!=null&&z.enabled&&b.nodeGrid.options.fill?1:.01}},[]),de=l==="C"?"LR":l,Pe=j.useCallback(z=>{const O={...m,...z};return{...O,bgColor:O.bgColor||t,bgOpacity:O.outline?0:O.bgOpacity??_E}},[m,t]),ae=j.useMemo(()=>{var O;const z=new Map;for(const oe of e)(O=oe.data)!=null&&O.id&&z.set(oe.data.id,oe);return z},[e]),we=j.useMemo(()=>{var O;const z=new Map;for(const oe of r)(O=oe.data)!=null&&O.id&&z.set(oe.data.id,oe);return z},[r]),$e=j.useCallback(z=>{var je;const O=(je=ae.get(z))==null?void 0:je.data,oe=Pe(O==null?void 0:O.viewProps),ye=Te(oe.bgColor);return{animated:!!(O!=null&&O.isNodeAnimated)&&!W,animationVariant:O==null?void 0:O.nodeAnimationVariant,animationColor:Te(oe.borderColor||t),bgColor:oe.outline?"transparent":ye,bgOpacity:oe.bgOpacity,borderColor:oe.borderColor?Te(oe.borderColor):oe.outline&&oe.bgColor==="transparent"?Te(t):ye,borderWidth:Dn(oe.borderWidth,qr.borderWidth),borderStyle:oe.borderStyle??qr.borderStyle,borderRadius:oe.borderRadius??qr.borderRadius,textColor:oe.textColor?Te(oe.textColor):oe.outline||oe.bgColor==="transparent"?Te(te):ye,fontSize:oe.fontSize??qr.fontSize,labelPosition:oe.labelPosition??qr.labelPosition,labelMargin:qr.labelMargin,labelBg:zu(ie("dark"),ye,oe.bgOpacity)??ie("dark"),padding:oe.padding??qr.padding}},[Pe,ae,te,t,W,ie]),Ue=j.useMemo(()=>{var oe,ye;const z=new Map;for(const je of r){const Ie=(oe=je.data)==null?void 0:oe.source,Me=(ye=je.data)==null?void 0:ye.target;if(!Ie||!Me||Ie===Me)continue;const Ye=Ie<Me?`${Ie}|${Me}`:`${Me}|${Ie}`,et=z.get(Ye);et?et.push({id:je.data.id,source:Ie}):z.set(Ye,[{id:je.data.id,source:Ie}])}const O=new Map;for(const[je,Ie]of z){if(Ie.length<2)continue;const Me=je.split("|")[0],Ye=Math.min(20,70/Ie.length);Ie.forEach(({id:et,source:ze},ct)=>{const ht=50+(ct-(Ie.length-1)/2)*Ye;O.set(et,(ze===Me?ht:100-ht)/100)})}return O},[r]),Ve=j.useMemo(()=>{const z=ie("dark");return r.filter(O=>{var oe;return((oe=O.data)==null?void 0:oe.id)&&O.data.source&&O.data.target}).map(({data:O})=>{var Ie,Me,Ye,et,ze,ct;let oe=z;const ye=(Me=(Ie=ae.get(O.source))==null?void 0:Ie.data)==null?void 0:Me.parent,je=(et=(Ye=ae.get(O.target))==null?void 0:Ye.data)==null?void 0:et.parent;if(ye&&ye===je){const ht=Pe((ct=(ze=ae.get(ye))==null?void 0:ze.data)==null?void 0:ct.viewProps),wt=zu(z,Te(ht.bgColor),ht.bgOpacity);wt&&(oe=wt)}return{id:O.id,data:O,type:O.type??b.edgeType??"rounded-orthogonal",source:O.source,target:O.target,sourceProperty:O.sourceProperty,targetProperty:O.targetProperty,label:O.label,validationIssue:(u==="auto"||u==="properties")&&(O.sourceProperty!==void 0||O.targetProperty!==void 0)&&p?Dd(p,O):void 0,color:c?U:O.color?Te(O.color):U,connectorColor:c?U:O.color?Te(O.color):fe,labelBg:oe,dashed:!!O.isEdgeDashed,animated:!!O.isEdgeAnimated,inverted:!!O.isInverted,turn:Ue.get(O.id)??.5}})},[r,U,fe,c,Ue,b.edgeType,u,p,ae,Pe,ie]),tt=j.useMemo(()=>{var O;const z=new Set;for(const oe of e)(O=oe.data)!=null&&O.parent&&z.add(oe.data.parent);return z},[e]),ge=j.useMemo(()=>{const z=new Map;for(const O of r){const oe=O.data.isInverted?O.data.target:O.data.source;oe&&!z.has(oe)&&z.set(oe,O.data)}for(const O of r){if(O.data.connection)continue;const oe=O.data.isInverted?O.data.target:O.data.source,ye=O.data.isInverted?O.data.source:O.data.target;ye.startsWith(`${oe}.`)&&(z.set(oe,O.data),z.set(ye,O.data))}return z},[r]),Ae=j.useMemo(()=>{const z={...jE,...b.customViews};return e.filter(O=>{var oe;return(oe=O.data)==null?void 0:oe.id}).map(O=>{var et,ze,ct,ht,wt,St,Rt,Mt,pt;const oe=tt.has(O.data.id)&&!O.data.parent,ye=oe&&O.data.type!=="prompt"?O.data.label??O.data.headerTitle??"Container":void 0,je=O.data.type==="prompt"?z.prompt:oe?z.parentContainer:z[O.data.type]||z.text,Ie=((et=b.customViews)==null?void 0:et.fillNode)??je,Me=ge.get(O.data.id),Ye={...O,isInverted:((ze=O.data.config)==null?void 0:ze.isInverted)??(Me==null?void 0:Me.isInverted),isParent:oe,containerStyle:oe?$e(O.data.id):void 0};return{id:O.data.id,collapsed:(ct=O.data.config)==null?void 0:ct.collapsed,parent:O.data.parent,acceptsChildren:!!((ht=O.data.config)!=null&&ht.parentContainer)||tt.has(O.data.id),label:ye,animated:!!O.data.isNodeAnimated,animationVariant:O.data.nodeAnimationVariant,hasCollapseControl:((wt=O.data.config)==null?void 0:wt.collapsed)!==void 0,animationColor:Te(((St=O.data.viewProps)==null?void 0:St.borderColor)||t),animationWidth:Dn((Rt=O.data.viewProps)==null?void 0:Rt.borderWidth,8),element:j.createElement(je,{...Ye,key:`${O.data.id}-${t}`}),fillElement:R.has(O.data.id)&&!((Mt=b.customViews)!=null&&Mt.fillNode)?void 0:j.createElement(Ie,{...Ye,...(pt=b.customViews)!=null&&pt.fillNode?{renderNode:je}:{},data:{...O.data,viewProps:R.has(O.data.id)?O.data.viewProps:{...O.data.viewProps,borderRadius:0}},containerStyle:Ye.containerStyle&&!R.has(O.data.id)?{...Ye.containerStyle,borderRadius:0}:Ye.containerStyle,key:`${O.data.id}-${t}`})}})},[e,tt,ge,t,b.customViews,$e,R]),Le=j.useMemo(()=>W?300:e.length>50?150:e.length>20?100:50,[e.length,W]),be=j.useRef(b);be.current=b;const Xe=j.useRef(P);Xe.current=P;const ut=j.useRef(T);ut.current=T;const Re=j.useRef(x);Re.current=x;const Ke=j.useRef(v);Ke.current=v;const lt=j.useRef(M);lt.current=M;const Je=j.useRef(ae);Je.current=ae;const mt=j.useRef(we);mt.current=we;const At=j.useRef(new Map);j.useEffect(()=>{var oe,ye;const z=new Map([...we].filter(([,je])=>ae.has(je.data.source)&&ae.has(je.data.target))),O=At.current;At.current=z;for(const[je,Ie]of O)z.has(je)||(Ke.current===je&&(C(null),(oe=y.onEdgeDeselect)==null||oe.call(y)),(ye=y.onEdgeRemove)==null||ye.call(y,je,Ie.data))},[we,ae,y,C]),j.useEffect(()=>{const z=Z.current;if(!K||!z)return;let O=null,oe=null,ye=0,je=0,Ie=0,Me=0,Ye=0;const et=ze=>{var wt;if(be.current.readOnly||be.current.minZoom===be.current.maxZoom&&be.current.minZoom!==void 0&&((wt=z.parentElement)!=null&&wt.closest(".flow-sdk-canvas")))return;const ct=z.ownerDocument.fullscreenElement;if(ct&&ct!==z&&z.contains(ct)&&ze.target instanceof Node&&ct.contains(ze.target))return;ze.preventDefault(),ze.stopPropagation(),Xe.current||ze.metaKey||ze.ctrlKey?(Ie+=ze.deltaY,Me=ze.clientX,Ye=ze.clientY,oe===null&&(oe=requestAnimationFrame(()=>{oe=null;const St=be.current,Rt=K.zoom(),Mt=Ie;Ie=0;let pt=Rt-Mt*.05/100;pt=Math.max(St.minZoom??.01,Math.min(St.maxZoom??1.5,pt));const gt=z.getBoundingClientRect();K.zoomAt(pt,{x:Me-gt.left,y:Ye-gt.top})}))):(ye+=ze.deltaX,je+=ze.deltaY,O===null&&(O=requestAnimationFrame(()=>{O=null;const St=K.pan(),Rt=K.zoom(),Mt=.35,pt=ye,gt=je;ye=0,je=0,K.pan({x:St.x+-pt*Mt/Rt,y:St.y+-gt*Mt/Rt})})))};return z.addEventListener("wheel",et,{passive:!1}),()=>{z.removeEventListener("wheel",et),O!==null&&cancelAnimationFrame(O),oe!==null&&cancelAnimationFrame(oe)}},[K]),j.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const z=O=>{var ye,je,Ie,Me,Ye,et;if(be.current.readOnly)return;const oe=O.target;if(!(oe.tagName==="INPUT"||oe.tagName==="TEXTAREA"||oe.isContentEditable)){if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(O.key)){const ze=Z.current,ct=g.current,ht=ze==null?void 0:ze.querySelector(".flow-sdk-canvas");if(!ze||!ht||!ct||oe!==ze&&(oe.closest(".flow-sdk-canvas")!==ht||!oe.closest(".flow-sdk-node")||oe.querySelector(":scope > .flow-sdk-canvas")||oe.closest('button, input, textarea, select, a, [contenteditable], [role="button"], [role="textbox"], [role="combobox"], [role="slider"], [role="spinbutton"], [data-flow-content]'))||O.defaultPrevented||O.isComposing||O.shiftKey||O.ctrlKey||O.metaKey||O.altKey||lt.current||Re.current.length>1||ht.querySelector("[data-grid-dragging], .flow-sdk-ghost, .flow-sdk-box")||Array.from(document.querySelectorAll('dialog[open], :popover-open, [role="dialog"], [role="menu"], [role="listbox"]')).some(Ft=>Ft.getClientRects().length>0&&getComputedStyle(Ft).visibility!=="hidden"))return;const wt=ht.getBoundingClientRect();if(!wt.width||!wt.height)return;const St=ct.clientToModel(wt.left+wt.width/2,wt.top+wt.height/2),Rt=Re.current[0],Mt=Rt&&ct.getNodeBox(Rt)||St,pt=O.key==="ArrowLeft"||O.key==="ArrowRight",gt=O.key==="ArrowLeft"||O.key==="ArrowUp"?-1:1;let vt;for(const Ft of ht.querySelectorAll(".flow-sdk-node")){if(Ft.closest(".flow-sdk-canvas")!==ht)continue;const it=Ft.getAttribute("data-node-id");if(!it||it===Rt||!Je.current.has(it))continue;const br=Ft.getBoundingClientRect(),Ir=getComputedStyle(Ft);if(!br.width||!br.height||Ir.visibility==="hidden"||Ir.opacity==="0")continue;const fr=ct.getNodeBox(it);if(!fr)continue;const mn=fr.x-Mt.x,bn=fr.y-Mt.y;if((pt?mn:bn)*gt<=.01)continue;const Zr=Math.hypot(mn,bn);(!vt||Zr<vt.distance)&&(vt={id:it,box:fr,distance:Zr})}if(O.preventDefault(),O.stopPropagation(),!vt)return;Ke.current&&(C(null),(ye=y.onEdgeDeselect)==null||ye.call(y)),w([vt.id]),(je=y.onNodeSelect)==null||je.call(y,vt.id,Je.current.get(vt.id).data,{shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1,keyboardNavigation:!0});const er=ct.pan(),tr=ct.zoom();ct.pan({x:er.x+(St.x-vt.box.x)*tr,y:er.y+(St.y-vt.box.y)*tr},!0);return}if((O.key==="z"||O.key==="Z")&&I(!Xe.current),(O.key==="m"||O.key==="M")&&k(!M),(O.key==="d"||O.key==="D")&&N(!_),(O.key==="v"||O.key==="V")&&!O.repeat&&!O.metaKey&&!O.ctrlKey&&!O.altKey&&oe.tagName!=="SELECT"&&D(!$),(O.key==="Delete"||O.key==="Backspace")&&Ke.current){O.preventDefault();const ze=Ke.current;(Me=y.onEdgeDelete)==null||Me.call(y,ze,((Ie=mt.current.get(ze))==null?void 0:Ie.data)??{id:ze}),C(null);return}if((O.key==="Delete"||O.key==="Backspace")&&Re.current.length>0){O.preventDefault();const ze=Re.current.filter(ct=>ct!=="root");if(ze.length===0)return;for(const ct of ze){const ht=(Ye=Je.current.get(ct))==null?void 0:Ye.data;(et=y.onNodeDelete)==null||et.call(y,ct,ht||{})}w([])}}};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[M,_,$,D,I,k,N,b.disableKeyboardShortcuts,y,w,C]);const Jr=j.useCallback(z=>{var O;g.current=z,ne(z),(O=y.onInit)==null||O.call(y,z)},[g,y]),Tr=j.useCallback(z=>{var O;return(O=y.onViewportChange)==null?void 0:O.call(y,z)},[y]),rt=j.useCallback(z=>{var oe,ye,je;const O=((oe=mt.current.get(z))==null?void 0:oe.data)??{id:z};if(Ke.current===z&&lt.current){C(null),(ye=y.onEdgeDeselect)==null||ye.call(y);return}Re.current.length&&w([]),C(z),(je=y.onEdgeSelect)==null||je.call(y,z,O)},[y,C,w]),We=j.useCallback(()=>{var z,O,oe,ye,je,Ie;if((z=Z.current)==null||z.focus({preventScroll:!0}),a(b.bottomBarCollapsed??(Re.current.length>0||!!Ke.current||!s)),(O=y.onBackgroundClick)==null||O.call(y),!be.current.readOnly){const Me=new Set;for(const Ye of Re.current){let et=Je.current.get(Ye);for(;et&&!Me.has(et.data.id);)Me.add(et.data.id),tt.has(et.data.id)&&((oe=et.data.config)==null?void 0:oe.collapsed)!==!0&&((ye=y.onNodeCollapse)==null||ye.call(y,et.data.id,!0)),et=et.data.parent?Je.current.get(et.data.parent):void 0}}Re.current.length&&(w([]),(je=y.onNodeDeselect)==null||je.call(y)),Ke.current&&(C(null),(Ie=y.onEdgeDeselect)==null||Ie.call(y))},[y,w,C,a,s,b.bottomBarCollapsed,tt]);j.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const z=O=>{const oe=Z.current,ye=oe==null?void 0:oe.querySelector(".flow-sdk-canvas"),je=O.target;O.key!=="Escape"||O.defaultPrevented||O.repeat||O.isComposing||O.ctrlKey||O.metaKey||O.altKey||O.shiftKey||be.current.readOnly||!Re.current.length||!oe||!ye||!oe.getClientRects().length||document.fullscreenElement||ye.querySelector("[data-grid-dragging], .flow-sdk-ghost, .flow-sdk-box")||je instanceof Element&&(je.closest('input, textarea, select, [contenteditable], [role="textbox"], [role="combobox"], dialog, [role="dialog"], [role="menu"], [role="listbox"], [popover]')||je!==document.body&&!oe.contains(je)||je.closest(".flow-sdk-canvas")&&je.closest(".flow-sdk-canvas")!==ye)||Array.from(document.querySelectorAll('dialog[open], :popover-open, [role="dialog"], [role="menu"], [role="listbox"]')).some(Ie=>Ie.getClientRects().length>0&&getComputedStyle(Ie).visibility!=="hidden")||(O.preventDefault(),O.stopPropagation(),We())};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)},[b.disableKeyboardShortcuts,We]);const Qt=j.useCallback(z=>{var ye,je;const O=Re.current,oe=z.filter(Ie=>!O.includes(Ie));if(oe.length){w([...O,...oe]);for(const Ie of oe)(je=y.onNodeSelect)==null||je.call(y,Ie,((ye=Je.current.get(Ie))==null?void 0:ye.data)??{id:Ie})}},[y,w]),ft=j.useCallback((z,O)=>{var oe,ye;w([z]),(ye=y.onNodeSelect)==null||ye.call(y,z,((oe=Je.current.get(z))==null?void 0:oe.data)??{id:z},O)},[y,w]),qt=j.useRef(null),dr=j.useCallback((z,O,oe)=>{var ye;qt.current={source:z,target:O,edgeIds:new Set(mt.current.keys())};try{(ye=y.onEdgeCreate)==null||ye.call(y,z,O,oe)}catch(je){throw qt.current=null,je}},[y]),De=j.useCallback((z,O,oe,ye=!1)=>{var je,Ie;if(se.current={sourceId:z,nodeIds:new Set(Je.current.keys()),reverse:ye},!(u==="properties"&&((je=y.onNodeCreateRequest)==null?void 0:je.call(y,{sourceNodeId:z,position:O,sourceProperty:oe,reverse:ye}))===!0)){if(oe!==void 0||ye){se.current=null;return}(Ie=y.onNodeCreate)==null||Ie.call(y,{type:"text",sourceNodeId:z,position:O,isArrayMode:ut.current})}},[y,u]),Ht=!b.readOnly&&$&&b.edgeHandles!==!1,Lt=i==="transparent"?"none":i;return f.jsx(EE,{pattern:Lt,backgroundColor:X,children:f.jsx(V.Box,{ref:Z,tabIndex:0,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:f.jsx(iE,{nodes:Ae,edges:Ve,direction:de,nodeAlignment:d,onContainerCollapse:z=>{var O,oe;(O=y.onNodeCollapse)==null||O.call(y,z,!0),(oe=y.onNodeViewToggle)==null||oe.call(y,z)},selectedNodeIds:x,edgeMode:u,compactPropertyLayout:h,edgeType:b.edgeType,edgeRadius:o,customEdgeTypes:b.customEdgeTypes,edgeReveal:b.disableAnimations?void 0:b.edgeReveal,rankSep:q,edgeSep:ue,nodeGridSpacing:b.nodeGridSpacing,nodeGridConnections:b.nodeGridConnections,initialNodeGrid:b.nodeGrid,spacingFactor:F,compactSpacingScale:n,layoutDebounce:Le,isPerformanceMode:W,minZoom:b.minZoom??.01,maxZoom:b.maxZoom??1.5,initialViewport:re,fixedNodePositions:b.fixedNodePositions,onFixedNodePositionsChange:y.onFixedNodePositionsChange,fitOnInit:!b.initialViewport&&!((ur=b.nodeGrid)!=null&&ur.enabled&&b.nodeGrid.options.fill),readOnly:!!b.readOnly,containerStyle:$e,lineColor:c?U:fe,drawMode:Ht,drawHandles:!b.readOnly&&b.edgeHandles!==!1,dragMode:_,multiSelect:!!M,onInit:Jr,onLayoutComplete:z=>{var Ie;(Ie=y.onLayoutComplete)==null||Ie.call(y,z);const O=qt.current;O&&(!Je.current.has(O.source)||!Je.current.has(O.target)?qt.current=null:r.some(({data:Me})=>Me.source===O.source&&Me.target===O.target&&!O.edgeIds.has(Me.id))&&z.getNodeBox(O.source)&&z.getNodeBox(O.target)&&(qt.current=null,z.focusConnections(O.source)));const oe=se.current;if(!oe)return;if(!Je.current.has(oe.sourceId)){se.current=null;return}const je=e.filter(Me=>!oe.nodeIds.has(Me.data.id)).filter(Me=>r.some(({data:Ye})=>Ye.source===oe.sourceId&&Ye.target===Me.data.id||Ye.target===oe.sourceId&&Ye.source===Me.data.id));!je.length||je.some(Me=>!z.getNodeBox(Me.data.id))||(se.current=null,z.focusBranch(oe.reverse?je[0].data.id:oe.sourceId))},onNodeGridModeChange:E,onNodeGridZoomOut:y.onNodeGridZoomOut,onNodeGridDrop:y.onNodeGridDrop,onNodeParentChange:y.onNodeParentChange,animateViewport:b.animateViewport,disableAnimations:b.disableAnimations,onViewportChange:Tr,onBackgroundTap:We,onBoxSelect:Qt,onEdgeSelect:rt,onContainerSelect:ft,onEdgeDraw:dr,onDrawIntoSpace:De})})})},yv=j.memo(kE),PE=".flow-sdk-canvas{position:relative;width:100%;height:100%;overflow:clip;user-select:none;-webkit-user-select:none;touch-action:none}.flow-sdk-svg{position:absolute;top:0;left:0;width:100%;height:100%;overflow:visible;display:block}.flow-sdk-nodes{position:absolute;top:0;left:0;transform-origin:0 0;pointer-events:none;will-change:transform;backface-visibility:hidden;z-index:10}.flow-sdk-node{position:absolute;top:0;left:0;transform-origin:0 0;pointer-events:auto;will-change:transform;backface-visibility:hidden;z-index:10}.flow-sdk-node input,.flow-sdk-node textarea{pointer-events:auto;user-select:text;-webkit-user-select:text;cursor:text}.flow-sdk-edge-hit{fill:none;stroke:transparent;stroke-width:24px;vector-effect:non-scaling-stroke;pointer-events:stroke;cursor:pointer}.flow-sdk-container{cursor:pointer}.flow-sdk-edge-anim{animation:flow-sdk-dash .5s linear infinite}.flow-sdk-edge-anim-rev{animation-direction:reverse}@keyframes flow-sdk-dash{to{stroke-dashoffset:-50}}.flow-sdk-draw{cursor:crosshair}.flow-sdk-draw .flow-sdk-node,.flow-sdk-draw .flow-sdk-node input,.flow-sdk-draw .flow-sdk-node textarea,.flow-sdk-draw .flow-sdk-edge,.flow-sdk-draw .flow-sdk-container{pointer-events:none}.flow-sdk-perf.flow-sdk-busy .flow-sdk-edges{display:none}.flow-sdk-box{position:absolute;border:1px solid rgba(170,170,170,.9);background:rgba(221,221,221,.25);pointer-events:none;z-index:20}";let Im=!1;function AE(){if(Im||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=PE+".flow-sdk-canvas[data-node-grid] .flow-sdk-node,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *::before,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *::after{animation:none!important;transition:none!important}.flow-sdk-node[data-grid-fill] [data-flow-icon-label]{--flow-grid-caption-color:var(--flow-grid-on-surface-color)}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]{border:0;outline:none;box-shadow:none}.flow-sdk-node[data-grid-fill]{box-sizing:border-box}.flow-sdk-node[data-grid-fill] :not(svg):has([data-flow-node-surface]),.flow-sdk-node[data-grid-fill]>:not(svg):not(button){width:100%;height:100%;min-width:0;max-width:none}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]{width:100%;height:100%;min-width:0;max-width:none;box-sizing:border-box;overflow:hidden}.flow-sdk-node[data-grid-fill] [data-flow-icon-label]{gap:0}.flow-sdk-node[data-grid-fill] [data-flow-icon-caption]{position:absolute;bottom:12px;left:12px;width:calc(100% - 24px);max-height:40%;overflow:hidden}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]>svg{max-width:45%;max-height:55%}.flow-sdk-node[data-grid-fill] p{font-size:var(--flow-grid-font);white-space:normal;overflow-wrap:anywhere}.flow-sdk-canvas[data-node-grid]:not([data-grid-connections]) .flow-sdk-property-port,.flow-sdk-canvas[data-node-grid]:not([data-grid-connections]) .flow-sdk-handle,.flow-sdk-canvas[data-node-grid] [data-flow-collapse-control]{display:none}.flow-sdk-node[data-grid-draggable] :not(button):not(input):not(textarea):not(select):not(a){cursor:inherit}"+Ub+r1+e1+".flow-sdk-handle{position:absolute;left:-36px;top:50%;transform:translateY(-50%);width:36px;height:36px;display:grid;place-items:center;border:2px solid currentColor;border-radius:50%;background:white;cursor:crosshair;opacity:0;pointer-events:none}.flow-sdk-node:hover>.flow-sdk-handle,.flow-sdk-handle:focus-visible{opacity:1;pointer-events:auto}.flow-sdk-draw .flow-sdk-node *,.flow-sdk-draw .flow-sdk-edge *,.flow-sdk-draw .flow-sdk-container *,.flow-sdk-ghost *{pointer-events:none}",document.head.appendChild(e),e.textContent+=".flow-sdk-draw .flow-sdk-node{pointer-events:auto}.flow-sdk-draw .flow-sdk-node>.flow-sdk-handle{opacity:0;pointer-events:none}.flow-sdk-draw .flow-sdk-node:hover>.flow-sdk-handle,.flow-sdk-draw .flow-sdk-node>.flow-sdk-handle:focus-visible{opacity:1;pointer-events:auto}",e.textContent+='.flow-sdk-property-port{position:absolute;transform:translateY(-50%);width:32px;height:32px;margin:0;padding:0;border:3px solid currentColor;border-radius:50%;background:white;cursor:crosshair;pointer-events:auto;z-index:20}.flow-sdk-property-port[data-port-role="source"]{background:currentColor}.flow-sdk-property-port:hover{outline:3px solid currentColor;outline-offset:3px}.flow-sdk-draw .flow-sdk-node .flow-sdk-property-port{pointer-events:auto}',Im=!0}function RE({loading:e=!1,loader:r,...t}){var c,l;const[n,o]=j.useState(null),i=j.useMemo(()=>!!(n!=null&&n.json)&&!!t.json&&Zw(n.json,t.json),[n==null?void 0:n.json,t.json]),s=n===null||n.json!==t.json&&!i,a=e||s;return j.useEffect(()=>{!e&&i&&(n==null?void 0:n.json)!==t.json&&o(t)},[e,i,n==null?void 0:n.json,t.json]),j.useEffect(()=>{if(e||!s)return;let d;const u=requestAnimationFrame(()=>{d=requestAnimationFrame(()=>o(t))});return()=>{cancelAnimationFrame(u),d!==void 0&&cancelAnimationFrame(d)}},[e,s,t.json]),f.jsxs(V.Box,{className:t.className,style:t.style,width:"100%",height:"100%",position:"relative","aria-busy":a,children:[f.jsx("div",{style:{width:"100%",height:"100%"},ref:d=>{var h;const u=(d==null?void 0:d.contains(document.activeElement))&&((h=document.activeElement)==null?void 0:h.matches("input, textarea, [contenteditable=true]"));a&&(e||!u)?d==null||d.setAttribute("inert",""):d==null||d.removeAttribute("inert")},children:n&&f.jsx(ME,{...s?n:t,children:t.children,config:t.config,className:void 0,style:void 0})}),a&&r!==null&&f.jsx(V.Box,{"data-flow-loader":"",role:"status","aria-label":"Loading diagram",position:"absolute",inset:0,zIndex:1e3,display:"grid",placeItems:"center",background:((c=t.config)==null?void 0:c.colorMode)==="dark"?"gray.800":"gray.100",color:((l=t.config)==null?void 0:l.colorMode)==="dark"?"whiteAlpha.800":"blackAlpha.800",children:r===void 0?f.jsx("span",{children:"Loading diagram..."}):r})]})}function ME({title:e="untitled",json:r,forms:t,nodes:n,edges:o,config:i={},callbacks:s={},className:a,style:c,showBottomBar:l=!0,children:d}){AE();const[u,h]=j.useState(),[p,m]=j.useState(!1),g=i.formSchema??u,y=j.useMemo(()=>r&&t?_b(r,t.state):r,[r,t==null?void 0:t.state]),b=i.direction==="C",x=j.useMemo(()=>{let M,k;return _=>(k=M&&k?Xw(M,_,k)??Sd(_,{title:e,isCenter:b}):Sd(_,{title:e,isCenter:b}),M=_,k)},[e,b]),w=j.useMemo(()=>y?x(y):null,[y,x]),v=j.useMemo(()=>t!=null&&t.structured&&!p&&g?kb(t.state,t.bindings,g,(w==null?void 0:w.nodes)??n??[]):void 0,[t==null?void 0:t.structured,p,t==null?void 0:t.state,t==null?void 0:t.bindings,g,w,n]),C=(v==null?void 0:v.schema)??g,S=(v==null?void 0:v.bindings)??(t==null?void 0:t.bindings),E=j.useMemo(()=>[...(w==null?void 0:w.nodes)??n??[],...(v==null?void 0:v.nodes)??[]].map(k=>{var K,ne,se,W;const _=r?(K=Oe(r,k.data.id))==null?void 0:K.$view:(ne=k.data.config)==null?void 0:ne.typeView,N=_&&Ld.includes(_)?_:void 0,$=N?N==="icon-label":(se=k.data.config)==null?void 0:se.labelBelow,D=N==="object"?"objectView":N==="text"?"text":$?"arrayView":k.data.type,T=C&&(t?Hn(S,k.data.id,C):r&&un(r,k.data.id,C)),Z=(((W=k.data.config)==null?void 0:W.ports)??[]).map(ue=>({...ue}));if(v&&T){const ue=i.direction==="RL"?{input:"right",output:"left",config:"bottom",error:"top"}:i.direction==="TB"?{input:"top",output:"bottom",config:"right",error:"left"}:i.direction==="BT"?{input:"bottom",output:"top",config:"left",error:"right"}:{input:"left",output:"right",config:"top",error:"bottom"};for(const[q,F]of Object.entries(T.type.ports??{})){const H=`${F.kind}:${q}`,G=Z.find(ce=>ce.id===H);G?G.label===void 0&&F.label!==void 0&&(G.label=F.label):Z.push({id:H,...F.label!==void 0?{label:F.label}:{},role:F.kind==="input"||F.kind==="config"?"target":"source",side:ue[F.kind],...F.kind==="config"?{placement:"config"}:{}})}for(const q of Z){const F=Z.filter(H=>H.side===q.side);q.position=(F.indexOf(q)+1)/(F.length+1)}}return T||$||N?{...k,data:{...k.data,type:D,...t?{description:Object.fromEntries(Object.entries(k.data.description??{}).filter(([ue])=>!ue.startsWith("$")&&!(v!=null&&v.slots.has(En(k.data.id,ue)))))}:{},config:{...k.data.config,...v&&T?{ports:Z}:{},...T?{form:!0}:{},...N?{typeView:N,labelBelow:!!$}:$?{labelBelow:!0}:{}}}}:k}),[w,n,r,C,S,v,i.direction]),R=j.useMemo(()=>[...(w==null?void 0:w.edges)??o??[],...(v==null?void 0:v.edges)??[]],[w==null?void 0:w.edges,o,v==null?void 0:v.edges]),P=j.useMemo(()=>{const M=r&&w?Hb(r,w.edges,s,s.onJsonChange,g):{...s};if(v){const k=new Set([...v.nodes.map(_=>_.data.id),...v.edges.map(_=>_.data.id)]);for(const _ of Object.keys(M)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(_))continue;const N=M[_];M[_]=($,...D)=>{if(!k.has($))return N==null?void 0:N($,...D)}}}return{...M,onAllNodesIconLabelChange:k=>{var _;m(k),(_=M.onAllNodesIconLabelChange)==null||_.call(M,k)}}},[r,w,s,g,v]),I=j.useMemo(()=>{if(!t)return P;let M=t.state;const k=N=>{if(i.readOnly||i.editable===!1)return;const $=t.onStateChange??t.onChange;if(!$)return;const D=Lw(M,N,s.onFormChange);D!==M&&(M=D,$(D,{...N,data:D}))},_=(N,$,D)=>{var Z;const T=r&&((Z=Oe(r,N))==null?void 0:Z[$]);return!T||typeof T.$state!="string"?!1:(k({address:T.$state,nodeAddress:N,previousValue:Oe(M,T.$state),value:D,data:M}),!0)};return{...P,onFormChange:k,onNodeCreateRequest:N=>{var T,Z;const $=(T=N.sourceProperty)!=null&&T.startsWith("config:")?N.sourceProperty.slice(7):void 0,D=$!==void 0&&(v==null?void 0:v.slots.get(En(N.sourceNodeId,$)));return D?(D.present||k({data:M,nodeAddress:D.address.split(".").slice(0,-1).join("."),address:D.address,value:_n(D.type),previousValue:void 0}),!0):((Z=P.onNodeCreateRequest)==null?void 0:Z.call(P,N))??!1},onNodeDelete:(N,$)=>{var se,W;if(!(v!=null&&v.nodes.some(ue=>ue.data.id===N)))return(se=P.onNodeDelete)==null?void 0:se.call(P,N,$);const D=v&&[...v.slots.values()].find(ue=>ue.nodeId===N);if(!D)return(W=P.onNodeDelete)==null?void 0:W.call(P,N,$);const T=D.address.split("."),Z=T.pop(),K=T.join("."),ne=Oe(M,K);k(Array.isArray(ne)?{data:M,nodeAddress:K,address:K,previousValue:ne,value:ne.filter((ue,q)=>String(q)!==Z)}:{data:M,nodeAddress:K,address:D.address,previousValue:Oe(M,D.address),value:void 0})},onEdgeCreate:(N,$,D)=>{var K,ne;const T=((K=D==null?void 0:D.targetProperty)==null?void 0:K.startsWith("config:"))&&(v==null?void 0:v.slots.get(En($,D.targetProperty.slice(7)))),Z=v==null?void 0:v.containers.get(N);if(T&&Z&&(D==null?void 0:D.sourceProperty)==="output:resource"){const se=Bw(M,Z,T);se!==void 0&&k({data:M,nodeAddress:T.address.split(".").slice(0,-1).join("."),address:T.address,previousValue:Oe(M,T.address),value:se});return}T||v!=null&&v.nodes.some(se=>se.data.id===N||se.data.id===$)||(ne=P.onEdgeCreate)==null||ne.call(P,N,$,D)},onEdgeDelete:(N,$)=>{var W;const D=v==null?void 0:v.edges.find(ue=>ue.data.id===N);if(!D)return(W=P.onEdgeDelete)==null?void 0:W.call(P,N,$);const T=v.slots.get(En(D.data.target,D.data.targetProperty.slice(7))),Z=T.address.split("."),K=Z.pop(),ne=Z.join("."),se=Oe(M,ne);k(Array.isArray(se)?{data:M,nodeAddress:ne,address:ne,previousValue:se,value:se.filter((ue,q)=>String(q)!==K)}:{data:M,nodeAddress:ne,address:T.address,previousValue:Oe(M,T.address),value:void 0})},onNodeContentChange:(N,$)=>{var D,T;_(N,"$content",$)?(D=s.onNodeContentChange)==null||D.call(s,N,$):(T=P.onNodeContentChange)==null||T.call(P,N,$)},onNodeLabelChange:(N,$)=>{var D,T;_(N,"$label",$)?(D=s.onNodeLabelChange)==null||D.call(s,N,$):(T=P.onNodeLabelChange)==null||T.call(P,N,$)}}},[P,t,r,s,v,i.readOnly,i.editable]);return f.jsx($t.Provider,{value:{data:(t==null?void 0:t.state)??r,viewData:r,bindings:S,references:t==null?void 0:t.references,structured:v,renderForm:t==null?void 0:t.renderForm,editable:t?!!(t.onStateChange??t.onChange):!!s.onJsonChange,schema:C,setSchema:M=>{var k;h(M),(k=s.onFormSchemaChange)==null||k.call(s,M)},callbacks:I},children:f.jsx(bb,{config:v?{...i,formSchema:C}:i,callbacks:I,nodes:E,edges:R,children:f.jsxs(V.Box,{className:a,"data-flow-diagram":"","data-animations-disabled":i.disableAnimations||void 0,style:c,width:"100%",height:"100%",position:"relative",overflow:"hidden",css:{"&[data-animations-disabled], &[data-animations-disabled] *, &[data-animations-disabled] *::before, &[data-animations-disabled] *::after":{animation:"none !important",transition:"none !important"},"& input, & textarea, & select":{outline:"none !important",boxShadow:"none !important"}},children:[f.jsx(yv,{nodes:E,edges:R}),l&&f.jsx(Bb,{}),d]})})})}function TE(e){return Md(JSON.parse(e))}function Md(e){if(!e||typeof e!="object")throw new Error("Expected a JSON object or array.");const r=new Set,t=n=>{if(!(n===null||typeof n=="string"||typeof n=="boolean")&&!(typeof n=="number"&&Number.isFinite(n))){if(!n||typeof n!="object"||r.has(n)||!Array.isArray(n)&&![Object.prototype,null].includes(Object.getPrototypeOf(n)))throw new Error("Document must contain only finite, acyclic JSON values.");r.add(n);for(const[o,i]of Object.entries(n)){if(["__proto__","prototype","constructor"].includes(o))throw new Error(`Unsafe document key: ${o}`);t(i)}r.delete(n)}};return t(e),structuredClone(e)}function IE(e){return{replaceJson(r){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const t=Md(r);return e.onJsonChange(t,{type:"documentReplace",address:"root"}),t},replaceState(r){if(e.readOnly||!e.onStateChange)throw new Error("Form state is read-only.");const t=Md(r);return e.onStateChange(t,{address:"root",nodeAddress:"root",previousValue:e.state,value:t,data:t}),t}}}function NE(e,r){const t=(n,o)=>{if(n===null||typeof n!="object")return typeof n==typeof o?n:void 0;if(!(!o||typeof o!="object"))return Array.isArray(n)?Array.isArray(o)?n.map((i,s)=>t(i,o[s])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,s])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i==="$content"&&n.$contentFormat==="jsx"&&o.$contentFormat==="jsx"&&Array.isArray(s)&&Array.isArray(o[i]))return[[i,s.filter((c,l)=>JSON.stringify(c)===JSON.stringify(o[i][l]))]];if(i.startsWith("$")&&i!=="$")return JSON.stringify(s)===JSON.stringify(o[i])?[[i,s]]:[];const a=t(s,o[i]);return a===void 0?[]:[[i,a]]}))};return t(e,r)??{}}function lo(e){let r="",t=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},s=()=>{if(i(),!(t||!r.trim()))try{const c=e.parse(e.repair(r)),l=JSON.stringify(c);if(l===n)return;e.preview(c),n=l}catch{}},a=c=>{if(!t){if(new TextEncoder().encode(c).byteLength>(e.maxBytes??1024*1024))throw t=!0,i(),new Error("JSON stream exceeds the size limit.");r=c,o||(o=setTimeout(s,e.intervalMs??150))}};return{snapshot:a,append(c){a(r+c)},flush:s,finish(){if(t)throw new Error("JSON stream is closed.");t=!0,i();const c=e.parse(r);return e.commit(c),c},cancel(){t=!0,i(),r=""}}}function OE(e){const{source:r}=e,t=e.tickMs??50,n=e.durationMs??8e3;if(!Number.isFinite(t)||t<=0||!Number.isFinite(n)||n<=0)throw new Error("Playback timing must be positive.");if(new TextEncoder().encode(r).byteLength>(e.maxBytes??1024*1024))throw new Error("JSON stream exceeds the size limit.");e.parse(r);let o=lo(e),i=0,s=!1,a=!1,c;const l=Math.max(1,Math.ceil(r.length*t/n)),d=()=>e.onChange({position:i,total:r.length,playing:s}),u=()=>{clearTimeout(c),c=void 0},h=(g=!1)=>{o.snapshot(r.slice(0,i)),i===r.length?(s=!1,u(),o.finish()):g&&o.flush()},p=g=>{s=!1,u(),o.cancel(),d(),e.onError(g)},m=()=>{if(c=void 0,!(!s||a)){i=Math.min(r.length,i+l);try{h()}catch(g){p(g);return}d(),s&&(c=setTimeout(m,t))}};return{play(){a||s||(i===r.length&&(o.cancel(),o=lo(e),i=0),s=!0,d(),c=setTimeout(m,t))},pause(){a||(s=!1,u(),o.flush(),d())},seek(g){if(!a){if(!Number.isFinite(g))throw new Error("Playback position must be finite.");u(),i=Math.max(0,Math.min(r.length,Math.round(g))),o.cancel(),o=lo(e);try{h(!0)}catch(y){p(y);return}d(),s&&(c=setTimeout(m,t))}},dispose(){a=!0,s=!1,u(),o.cancel()}}}function $E({nodeAddress:e,expanded:r=!1}){var l;const{data:t,schema:n,bindings:o}=j.useContext($t),{colorText:i,background:s}=at();if((l=o==null?void 0:o[e])!=null&&l.portResources)return null;const a=o&&Hn(o,e,n);if(!t||!a)return null;const c=Oe(t,a.address);return!c||typeof c!="object"?null:f.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:Te(i),background:Te(s),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(a.type.properties).map(d=>{const u=a.fields[d]??{};if(!Eo(u.$visibleWhen,t))return null;const h=c[d],p=h==null?"":typeof h=="object"?JSON.stringify(h):String(h);return f.jsxs("div",{"data-flow-property":d,style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:12,padding:"10px 16px",borderTop:"1px solid color-mix(in srgb, currentColor 12%, transparent)"},children:[f.jsx("span",{style:{overflowWrap:"anywhere"},children:Dt(u.$label??d)}),f.jsx("span",{title:p,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:r?"pre-wrap":"nowrap",overflowWrap:r?"anywhere":void 0},children:p})]},d)})})}exports.BottomBar=Bb;exports.CollapseAllToggle=vb;exports.CompactPropertyLayoutToggle=wb;exports.ConnectionsOnlyToggle=Jw;exports.ContentFullscreenButton=lv;exports.DEFAULT_PALETTE=po;exports.DiagramAppearanceControls=Cb;exports.DynamicIcon=cr;exports.EdgeTools=Ib;exports.EditableLabel=cn;exports.ErrorToast=Fb;exports.FlowDiagram=RE;exports.FlowDiagramProvider=bb;exports.FlowPort=cv;exports.FlowView=yv;exports.FormDocumentContext=$t;exports.GridAdjustmentToggle=Sb;exports.LIGHT_BLACK=ln;exports.LoadingBorder=mu;exports.NODE_TYPE_VIEWS=Ld;exports.NodeBorderRadiusControl=Nb;exports.NodeConfigSummary=$E;exports.NodeForm=Vd;exports.NodeFormPopover=yu;exports.NodeGridControls=so;exports.NodeIconPicker=Gd;exports.NodeTools=Ob;exports.NodeView=Qn;exports.PanelDragHandle=xb;exports.SvgExportButton=Lb;exports.Swatches=Vr;exports.TEXT_PALETTE=Mb;exports.ToolbarCloseButton=dn;exports.ToolbarCommitInput=Er;exports.ToolbarDivider=Nn;exports.ToolbarIconButton=Ne;exports.ToolbarRangeInput=Fd;exports.ToolbarScrollContainer=ko;exports.ToolbarSelect=It;exports.ToolbarTooltip=Ge;exports.TooltipIconButton=Rd;exports.WorkflowControls=Hd;exports.addChild=$d;exports.addConnection=qd;exports.addTargetEdge=ub;exports.addressToPath=Kt;exports.applyCollapsed=Sw;exports.applyFormChange=_o;exports.applyStateEdits=qw;exports.bindSqueedCallbacks=Hb;exports.compileSqueed=Sd;exports.connectionIssue=Dd;exports.contentObjTheme=sr;exports.copySelection=Ud;exports.createFlowDiagram=Dr;exports.createFlowDocumentActions=IE;exports.createFormNode=Wb;exports.createJsonPlayback=OE;exports.createJsonStream=lo;exports.createWorkflowExecution=Aw;exports.downloadSvg=qb;exports.duplicateSelection=Gb;exports.exportSvg=$b;exports.formValueError=Jt;exports.formatTimeAgo=hb;exports.getChakraColorHex=Te;exports.getColorVariant=pb;exports.getDarkerHexColor=fo;exports.getInteractionSurface=gr;exports.getNode=Oe;exports.getSelectionRoots=Vb;exports.isNodeVisible=ar;exports.parseFlowDocument=TE;exports.parseJsonContract=zd;exports.parseTypeScriptContract=jb;exports.parseTypeScriptForm=Bd;exports.projectJsonPlaybackPreview=NE;exports.readFormSchema=Wd;exports.readWorkflowContract=Eb;exports.removeEdge=fb;exports.removeNode=db;exports.reparentNode=Yw;exports.resolveEdgeOwner=zr;exports.resolveStateView=_b;exports.setCollapsed=uo;exports.setEdgeProp=Sr;exports.setEdgeStyle=lb;exports.setNodeProp=jt;exports.stampNodeEdit=cb;exports.updateNode=Pt;exports.useCustomColors=at;exports.useEdgeProximity=So;exports.useFlowData=Xt;exports.useFlowDiagramContext=He;exports.useNodeViewActions=eo;exports.useStopPropagation=gu;exports.useThemeContentColors=Gn;exports.validateGridAdjustment=ov;
284
285
  //# sourceMappingURL=index.cjs.map