@squeed/flow-sdk 2.0.49 → 2.0.50
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 +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +4386 -4361
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var Ev=Object.create;var Yo=Object.defineProperty;var _v=Object.getOwnPropertyDescriptor;var kv=Object.getOwnPropertyNames;var Pv=Object.getPrototypeOf,Av=Object.prototype.hasOwnProperty;var Rv=(e,r,t)=>r in e?Yo(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var Mv=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of kv(r))!Av.call(e,o)&&o!==t&&Yo(e,o,{get:()=>r[o],enumerable:!(n=_v(r,o))||n.enumerable});return e};var ut=(e,r,t)=>(t=e!=null?Ev(Pv(e)):{},Mv(r||!e||!e.__esModule?Yo(t,"default",{value:e,enumerable:!0}):t,e));var Dt=(e,r,t)=>Rv(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react"),f=require("react/jsx-runtime"),D=require("@chakra-ui/react"),Vr=require("react-dom"),Z=require("react-icons/pi"),Om=require("@emotion/react"),Tv=require("@emotion/styled"),Iv=require("react-icons/tb"),Nv=require("markdown-to-jsx/react"),$m=e=>e&&e.__esModule?e:{default:e},xo=$m(Tv),Ov=$m(Nv),Pt=[];for(let e=0;e<256;++e)Pt.push((e+256).toString(16).slice(1));function $v(e,r=0){return(Pt[e[r+0]]+Pt[e[r+1]]+Pt[e[r+2]]+Pt[e[r+3]]+"-"+Pt[e[r+4]]+Pt[e[r+5]]+"-"+Pt[e[r+6]]+Pt[e[r+7]]+"-"+Pt[e[r+8]]+Pt[e[r+9]]+"-"+Pt[e[r+10]]+Pt[e[r+11]]+Pt[e[r+12]]+Pt[e[r+13]]+Pt[e[r+14]]+Pt[e[r+15]]).toLowerCase()}let Qo;const qv=new Uint8Array(16);function Lv(){if(!Qo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Qo=crypto.getRandomValues.bind(crypto)}return Qo(qv)}const Fv=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ru={randomUUID:Fv};function Nd(e,r,t){var o;if(Ru.randomUUID&&!e)return Ru.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??Lv();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,$v(n)}var zv=typeof global=="object"&&global&&global.Object===Object&&global,Bv=typeof self=="object"&&self&&self.Object===Object&&self,Dv=zv||Bv||Function("return this")(),rn=Dv.Symbol,qm=Object.prototype,Wv=qm.hasOwnProperty,Vv=qm.toString,wn=rn?rn.toStringTag:void 0;function Gv(e){var r=Wv.call(e,wn),t=e[wn];try{e[wn]=void 0;var n=!0}catch{}var o=Vv.call(e);return n&&(r?e[wn]=t:delete e[wn]),o}var Hv=Object.prototype,Uv=Hv.toString;function Kv(e){return Uv.call(e)}var Jv="[object Null]",Zv="[object Undefined]",Mu=rn?rn.toStringTag:void 0;function Xv(e){return e==null?e===void 0?Zv:Jv:Mu&&Mu in Object(e)?Gv(e):Kv(e)}function Yv(e){return e!=null&&typeof e=="object"}var Qv="[object Symbol]";function e0(e){return typeof e=="symbol"||Yv(e)&&Xv(e)==Qv}function t0(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,Tu=rn?rn.prototype:void 0,Iu=Tu?Tu.toString:void 0;function Lm(e){if(typeof e=="string")return e;if(ot(e))return t0(e,Lm)+"";if(e0(e))return Iu?Iu.call(e):"";var r=e+"";return r=="0"&&1/e==-1/0?"-0":r}function Od(e){return e==null?"":Lm(e)}function r0(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 n0(e,r,t){var n=e.length;return t=t===void 0?n:t,!r&&t>=n?e:r0(e,r,t)}var o0="\\ud800-\\udfff",i0="\\u0300-\\u036f",a0="\\ufe20-\\ufe2f",s0="\\u20d0-\\u20ff",c0=i0+a0+s0,l0="\\ufe0e\\ufe0f",d0="\\u200d",u0=RegExp("["+d0+o0+c0+l0+"]");function Fm(e){return u0.test(e)}function f0(e){return e.split("")}var zm="\\ud800-\\udfff",h0="\\u0300-\\u036f",p0="\\ufe20-\\ufe2f",g0="\\u20d0-\\u20ff",y0=h0+p0+g0,m0="\\ufe0e\\ufe0f",b0="["+zm+"]",Sd="["+y0+"]",jd="\\ud83c[\\udffb-\\udfff]",x0="(?:"+Sd+"|"+jd+")",Bm="[^"+zm+"]",Dm="(?:\\ud83c[\\udde6-\\uddff]){2}",Wm="[\\ud800-\\udbff][\\udc00-\\udfff]",v0="\\u200d",Vm=x0+"?",Gm="["+m0+"]?",w0="(?:"+v0+"(?:"+[Bm,Dm,Wm].join("|")+")"+Gm+Vm+")*",C0=Gm+Vm+w0,S0="(?:"+[Bm+Sd+"?",Sd,Dm,Wm,b0].join("|")+")",j0=RegExp(jd+"(?="+jd+")|"+S0+C0,"g");function E0(e){return e.match(j0)||[]}function _0(e){return Fm(e)?E0(e):f0(e)}function k0(e){return function(r){r=Od(r);var t=Fm(r)?_0(r):void 0,n=t?t[0]:r.charAt(0),o=t?n0(t,1).join(""):r.slice(1);return n[e]()+o}}var P0=k0("toUpperCase");function A0(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 R0(e){return function(r){return e==null?void 0:e[r]}}var M0={À:"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"},T0=R0(M0),I0=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,N0="\\u0300-\\u036f",O0="\\ufe20-\\ufe2f",$0="\\u20d0-\\u20ff",q0=N0+O0+$0,L0="["+q0+"]",F0=RegExp(L0,"g");function z0(e){return e=Od(e),e&&e.replace(I0,T0).replace(F0,"")}var B0=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function D0(e){return e.match(B0)||[]}var W0=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function V0(e){return W0.test(e)}var Hm="\\ud800-\\udfff",G0="\\u0300-\\u036f",H0="\\ufe20-\\ufe2f",U0="\\u20d0-\\u20ff",K0=G0+H0+U0,Um="\\u2700-\\u27bf",Km="a-z\\xdf-\\xf6\\xf8-\\xff",J0="\\xac\\xb1\\xd7\\xf7",Z0="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",X0="\\u2000-\\u206f",Y0=" \\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",Jm="A-Z\\xc0-\\xd6\\xd8-\\xde",Q0="\\ufe0e\\ufe0f",Zm=J0+Z0+X0+Y0,Xm="['’]",Nu="["+Zm+"]",ew="["+K0+"]",Ym="\\d+",tw="["+Um+"]",Qm="["+Km+"]",eb="[^"+Hm+Zm+Ym+Um+Km+Jm+"]",rw="\\ud83c[\\udffb-\\udfff]",nw="(?:"+ew+"|"+rw+")",ow="[^"+Hm+"]",tb="(?:\\ud83c[\\udde6-\\uddff]){2}",rb="[\\ud800-\\udbff][\\udc00-\\udfff]",Xr="["+Jm+"]",iw="\\u200d",Ou="(?:"+Qm+"|"+eb+")",aw="(?:"+Xr+"|"+eb+")",$u="(?:"+Xm+"(?:d|ll|m|re|s|t|ve))?",qu="(?:"+Xm+"(?:D|LL|M|RE|S|T|VE))?",nb=nw+"?",ob="["+Q0+"]?",sw="(?:"+iw+"(?:"+[ow,tb,rb].join("|")+")"+ob+nb+")*",cw="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",lw="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",dw=ob+nb+sw,uw="(?:"+[tw,tb,rb].join("|")+")"+dw,fw=RegExp([Xr+"?"+Qm+"+"+$u+"(?="+[Nu,Xr,"$"].join("|")+")",aw+"+"+qu+"(?="+[Nu,Xr+Ou,"$"].join("|")+")",Xr+"?"+Ou+"+"+$u,Xr+"+"+qu,lw,cw,Ym,uw].join("|"),"g");function hw(e){return e.match(fw)||[]}function pw(e,r,t){return e=Od(e),r=r,r===void 0?V0(e)?hw(e):D0(e):e.match(r)||[]}var gw="['’]",yw=RegExp(gw,"g");function mw(e){return function(r){return A0(pw(z0(r).replace(yw,"")),e,"")}}var Vt=mw(function(e,r,t){return e+(t?" ":"")+P0(r)});const vo={label:"Untitled",description:"",isTask:!1,isLocked:!1},$d={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"}}},Lu={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"}}},bw={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"}}},Fu={id:null,type:"workflowStep",data:{...vo,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},$t=e=>typeof e=="object",ib=e=>Array.isArray(e),xw=["order","position","selected","locked","grabbed","grabbable","scratch"],Rr=e=>Object.entries(e).reduce((r,[t,n])=>(!$t(n)&&!t.startsWith("$")&&(r[t]=n),r),{}),qd=(e,r)=>typeof e=="string"&&e.startsWith("$")?ei(e,r):$t(e)&&!ib(e)?Object.entries(e).reduce((t,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete t["..."],t[n]={...ei(o,r),...e}):typeof o=="string"&&o.startsWith("$")?t[n]=ei(o,r):t[n]=o,t),{}):e,Mr=e=>Object.entries(e).reduce((r,[t,n])=>($t(n)&&t&&n&&!t.startsWith("$")&&(xw.includes(t)&&(t=t+"#"),r[t]=n),r),{}),zr=(e,r,{label:t,parent:n=void 0},o,i=null)=>(i!==null&&($t(i)||ib(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}}),_r=(e,r,t=null,n=null,o=null,i=!1,s=null)=>({data:{id:Nd(),source:o?r:e,target:o?e:r,label:n||"",isInverted:o,isEdgeAnimated:i,parent:s}}),Tr=(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=Lu;const{view:n,borderColor:o,borderRadius:i,bgColor:s,textColor:a,fontSize:c,stepType:l}=r;e=n||e,l?t={...Fu}:e==="object"?t=Lu:e==="text"?t=$d:e==="array"?t=bw:e==="workflowStep"&&(t={...Fu});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),ei=(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=vw(o,t);return JSON.stringify(i).includes(e)?e:i||e}return e},vw=(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}=Tr(s);return s=c.length?c:s,s[a]},i))(r)};function en(e,r="root",t=[]){try{const{arrayObject:n}=Tr(e);n.length&&(e=n);const o=Rr(e),i=Mr(e);return $t(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=Rr(s),l=Mr(s),{newConfig:d,arrayObject:u}=Tr(s);let h=`${r}.${a}`;$t(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)&&ab({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=Rr(i),c=Mr(i),{newConfig:l,arrayObject:d}=Tr(i);d.length&&(i=d),n.split(".").slice(0,2).join(".");let u=e?`${e}.${o}`:`${n}.${o}`;if($t(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)}),ab=({chldPth:e,item:r,nodes:t,path:n})=>r.forEach((o,i)=>{let s=`${e}.${i}`;const a=Mr(o),c=Rr(o);$t(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)&&ab({chldPth:s,item:o,nodes:t,path:n}):t.push(s)}),Mn=[];let Tn;function Wr(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}=Tr(e),h=Object.keys(s).length>0?s:d;u.length&&(e=u);const p=Rr(e),m=Mr(e),{label:g,collapsed:y,parent:b}=h;if(!$t(e))t.push(zr($d,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(zr(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 A=!1;Number.isNaN(Number(o))||(A=!0);const I=e;if(g){const{config:M}=Yr("object",h);t.push(zr(M,r,{label:g||`${g} ${w}`,parent:b},p,I))}else x.data.headerTitle=R,t.push(zr(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=qd(x,Tn);const v=x,C=Rr(x),S=Mr(x),{newConfig:E,arrayObject:R}=Tr(x);R.length&&(x=R);const{config:A}=Yr(typeof x=="string"?"text":"array",E),{hideConfig:I,sourceLabel:M,label:k,isEdgeAnimated:_,parent:N}=E;c=c||I;const O=r==="root"&&i.isCntr,W=r.split(".").slice(0,2).join("."),T=Mn.includes(W),Y=i.isCntr&&T||w%2===0&&O;let he=`${r}.${w}`;he=Fn(he,t),Y&&Mn.push(he),$t(x)?Object.keys(C).length&&!ot(x)?(n.push(_r(r,he,null,M,Y,_)),Wr(x,he,t,n,k||w,i,E)):Object.keys(S).length&&!ot(x)?In({flowConfig:i,chldPth:he,isInverted:Y,edges:n,itrblObjct:S,nodes:t,path:r,newConfig:E,forceIsInverted:!0}):ot(x)?sb({flowConfig:i,chldPth:he,edges:n,isInverted:Y,item:x,nodes:t,path:r}):$t(x)&&In({flowConfig:i,chldPth:he,isInverted:Y,edges:n,itrblObjct:[x],nodes:t,path:r,newConfig:E}):(n.push(_r(r,he,null,M,Y,_)),t.push(zr(A,he,{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=qd(h,Tn);const m=h,g=Rr(h),y=Mr(h),{newConfig:b,arrayObject:x}=Tr(h);x.length&&(h=x);const{hideConfig:w,sourceLabel:v,label:C,content:S,target:E,targetLabel:R,collapsed:A,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 O=e?`${e}.${u}`:`${s}.${u}`;if(O=Fn(O,o),i&&Mn.push(O),E&&t.push(_r(O,E,null,R,i,I)),$t(h)&&!ot(h)){t.push(_r(s,O,null,v,i,I));const W=d||Object.keys(g).length===0;if(W){const T=S?"object":"array",{config:Y}=Yr(T,b);Y.data.headerTitle=S?C:null,o.push(zr(Y,O,{label:C||u,parent:M},h,m))}if(Object.keys(g).length&&!l){const T=ot(h)?` ${h.length||""}`:`{${Object.keys(h).length||""}}`;let Y=O;W&&(Y=`${O}.${T}`,Y=Fn(Y,o),t.push(_r(O,Y,null,v,i,I))),Wr(h,Y,o,t,C||u,r,b)}else Object.keys(y).length&&!ot(h)?In({chldPth:O,flowConfig:r,itrblObjct:y,path:O,edges:t,nodes:o,newConfig:b,isInverted:i}):Wr(h,O,o,t,u,r,b)}else ot(h)&&(t.push(_r(s,O,null,v,i,I)),Wr(h,O,o,t,u,r,b))})},sb=({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=qd(a,Tn);const u=Mr(a),h=Rr(a),{newConfig:p}=Tr(a),{collapsed:m,label:g,parent:y,sourceLabel:b,isEdgeAnimated:x,content:w}=p;$t(a)?!ot(a)&&Object.keys(h).length?(t.push(_r(s,l,null,b,n,x)),Wr(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)&&sb({flowConfig:e,chldPth:l,edges:t,isInverted:n,item:a,nodes:i,path:s}):(t.push(_r(s,l,null,b,n,x)),i.push(zr($d,l,{label:g||String(a),parent:y},a,d)))});function ww(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=$e(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=$e(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 cb(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 Cw(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 lb(e,r,t){return!t||$e(e,r)===void 0||!t.userId||!t.name.trim()||!Number.isFinite(Date.parse(t.at))?e:Et(e,r,"$edited",t)}const zu=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Zt(e){const r=e.split(".");for(r[0]===tn&&r.shift();r.length&&zu(r[r.length-1]);)r.pop();return r.filter(t=>!zu(t))}function Co(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function $e(e,r){return Zt(r).reduce((t,n)=>{var o;if(t!=null)return(o=Co(t))==null?void 0:o[n]},e)}function Sw(e){return Array.isArray(e)?[...e]:{...e}}function Rt(e,r,t){const n=Zt(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=Sw(c);return d[a]=l,c!==i?{...i,$:d}:d};return o(e,0)}function yr(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 Et(e,r,t,n){return Rt(e,r,o=>t==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:yr(o,t,n))}const uo=(e,r,t)=>Et(e,r,"$collapsed",t);function Br(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=Zt(t).join("."),i=Zt(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 Er(e,r,t,n){if(r.connection){const a=r.connection;return Rt(e,a.address,c=>cb(c,a.key,l=>{if(t==="$edgeIcon")return yr(l,"icon",n);if(t==="$edgeType")return yr(l,"type",n);if(t==="$edgeAnimationVariant")return yr(l,"animationVariant",n);if(t==="$sourceLabel"||t==="$edgeColor")return yr(l,t==="$sourceLabel"?"label":"color",n);const d=t==="$isEdgeAnimated"?"animated":"dashed";return n?{...l,style:d}:l.style===d?yr(l,"style",void 0):l}))}const{address:o,kind:i}=Br(r),s=i==="target"&&t==="$sourceLabel"?"$targetLabel":i==="target"&&t==="$edgeType"?"$targetEdgeType":i==="target"&&t==="$edgeIcon"?"$targetIcon":i==="target"&&t==="$edgeAnimationVariant"?"$targetAnimationVariant":t;return Rt(e,o,a=>yr(a,s,n))}const db=(e,r,t)=>Er(Er(e,r,"$isEdgeAnimated",t==="animated"||void 0),r,"$isEdgeDashed",t==="dashed"||void 0);function Ld(e,r,t,n){let o=n||"";const i=Rt(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=Zt(r);return{json:i,address:[tn,...s,o].join(".")}}function ub(e,r){const t=Zt(r);if(!t.length)return e;const n=t[t.length-1],o=[tn,...t.slice(0,-1)].join(".");return Rt(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 fb=(e,r,t,n)=>Et(n?Rt(e,r,o=>yr(o,"$targetLabel",n)):e,r,"$target",t);function Fd(e,r,t){const n=$e(e,r);return wo(n).some(({value:i})=>i.target===t.target&&i.sourceProperty===t.sourceProperty&&i.targetProperty===t.targetProperty)?e:Rt(e,r,i=>yr(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...t,id:t.id||Nd()}]))}function hb(e,r){if(r.connection){const i=r.connection;return wo($e(e,i.address)).some(s=>s.key===i.key)?{json:Rt(e,i.address,s=>cb(s,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:t,kind:n}=Br(r);return n==="hierarchy"?$e(e,t)===void 0?{json:e,removed:!1}:{json:Rt(e,t,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:Rt(e,t,i=>{const{$target:s,$targetLabel:a,...c}=i||{};return c}),removed:!0}}function Ed(e,r={}){var x;const t=Cw(e),{nodes:n,edges:o}=Wr(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")||$e(e,v)!==void 0)continue;const C=v.slice(0,-2),S=$e(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=Br(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(Zt(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}.${Zt(v)[0]}`,S=w.get(C);typeof S=="boolean"&&l.set(v,S)}}const d=n.map(w=>{var A;const v=a(w.data.id),C=$e(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(((A=S.config)==null?void 0:A.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=Br(w.data),R=l.get(a(E.address));E.kind==="hierarchy"&&R!==void 0&&R!==!!S&&([v,C]=[C,v],S=R);const A=`${v}->${C}`,I=u.get(A)??0;u.set(A,I+1);const M={...w.data,id:I?`${A}#${I}`:A,source:v,target:C,isInverted:S},k=Br(M),_=$e(e,k.address);if(_&&typeof _=="object"){const N=_[k.kind==="target"?"$targetEdgeType":"$edgeType"];typeof N=="string"&&(M.type=N);const O=_[k.kind==="target"?"$targetIcon":"$edgeIcon"];typeof O=="string"&&(M.icon=O),_.$isEdgeAnimated!==void 0&&(M.isEdgeAnimated=!!_.$isEdgeAnimated);const W=_[k.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(W)&&(M.edgeAnimationVariant=W),_.$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=Br(v);(!p.has(v.source)||!p.has(v.target)||C.kind==="hierarchy"&&((x=$e(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=ww(e,{nodes:d,edges:h}),g=m.nodes.filter(w=>{var v;return(v=w.data.config)==null?void 0:v.collapsed}).map(w=>Zt(w.data.id));if(!g.length)return m;const y=m.nodes.filter(w=>{const v=Zt(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 jw(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 Ew=new Intl.RelativeTimeFormat("en",{numeric:"always"});function pb(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 Ew.format(-Math.floor(n/i),s)}let _d=Date.now(),to;const ro=new Set,_w=e=>(ro.add(e),to||(_d=Date.now(),to=setInterval(()=>{_d=Date.now(),ro.forEach(r=>r())},6e4)),()=>{ro.delete(e),ro.size||(clearInterval(to),to=void 0)}),kw=()=>_d,Pw=()=>0;function Aw(e){const r=j.useSyncExternalStore(_w,kw,Pw);return pb(e,r||Date.now())}function Rw(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 Bu(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 lr=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"},gb=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}},Du={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=Du[n])!=null&&i[Number(o)])?Du[n][Number(o)]:`var(--chakra-colors-${t})`},Mw=Om.keyframes`
|
|
1
|
+
"use strict";var _v=Object.create;var Yo=Object.defineProperty;var kv=Object.getOwnPropertyDescriptor;var Pv=Object.getOwnPropertyNames;var Av=Object.getPrototypeOf,Rv=Object.prototype.hasOwnProperty;var Mv=(e,r,t)=>r in e?Yo(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var Tv=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Pv(r))!Rv.call(e,o)&&o!==t&&Yo(e,o,{get:()=>r[o],enumerable:!(n=kv(r,o))||n.enumerable});return e};var ut=(e,r,t)=>(t=e!=null?_v(Av(e)):{},Tv(r||!e||!e.__esModule?Yo(t,"default",{value:e,enumerable:!0}):t,e));var Vt=(e,r,t)=>Mv(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react"),f=require("react/jsx-runtime"),D=require("@chakra-ui/react"),Vr=require("react-dom"),X=require("react-icons/pi"),$m=require("@emotion/react"),Iv=require("@emotion/styled"),Nv=require("react-icons/tb"),Ov=require("markdown-to-jsx/react"),qm=e=>e&&e.__esModule?e:{default:e},xo=qm(Iv),$v=qm(Ov),Pt=[];for(let e=0;e<256;++e)Pt.push((e+256).toString(16).slice(1));function qv(e,r=0){return(Pt[e[r+0]]+Pt[e[r+1]]+Pt[e[r+2]]+Pt[e[r+3]]+"-"+Pt[e[r+4]]+Pt[e[r+5]]+"-"+Pt[e[r+6]]+Pt[e[r+7]]+"-"+Pt[e[r+8]]+Pt[e[r+9]]+"-"+Pt[e[r+10]]+Pt[e[r+11]]+Pt[e[r+12]]+Pt[e[r+13]]+Pt[e[r+14]]+Pt[e[r+15]]).toLowerCase()}let Qo;const Lv=new Uint8Array(16);function Fv(){if(!Qo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Qo=crypto.getRandomValues.bind(crypto)}return Qo(Lv)}const zv=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ru={randomUUID:zv};function Nd(e,r,t){var o;if(Ru.randomUUID&&!e)return Ru.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??Fv();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,qv(n)}var Bv=typeof global=="object"&&global&&global.Object===Object&&global,Dv=typeof self=="object"&&self&&self.Object===Object&&self,Wv=Bv||Dv||Function("return this")(),rn=Wv.Symbol,Lm=Object.prototype,Vv=Lm.hasOwnProperty,Gv=Lm.toString,wn=rn?rn.toStringTag:void 0;function Hv(e){var r=Vv.call(e,wn),t=e[wn];try{e[wn]=void 0;var n=!0}catch{}var o=Gv.call(e);return n&&(r?e[wn]=t:delete e[wn]),o}var Uv=Object.prototype,Kv=Uv.toString;function Jv(e){return Kv.call(e)}var Zv="[object Null]",Xv="[object Undefined]",Mu=rn?rn.toStringTag:void 0;function Yv(e){return e==null?e===void 0?Xv:Zv:Mu&&Mu in Object(e)?Hv(e):Jv(e)}function Qv(e){return e!=null&&typeof e=="object"}var e0="[object Symbol]";function t0(e){return typeof e=="symbol"||Qv(e)&&Yv(e)==e0}function r0(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,Tu=rn?rn.prototype:void 0,Iu=Tu?Tu.toString:void 0;function Fm(e){if(typeof e=="string")return e;if(ot(e))return r0(e,Fm)+"";if(t0(e))return Iu?Iu.call(e):"";var r=e+"";return r=="0"&&1/e==-1/0?"-0":r}function Od(e){return e==null?"":Fm(e)}function n0(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 o0(e,r,t){var n=e.length;return t=t===void 0?n:t,!r&&t>=n?e:n0(e,r,t)}var i0="\\ud800-\\udfff",a0="\\u0300-\\u036f",s0="\\ufe20-\\ufe2f",c0="\\u20d0-\\u20ff",l0=a0+s0+c0,d0="\\ufe0e\\ufe0f",u0="\\u200d",f0=RegExp("["+u0+i0+l0+d0+"]");function zm(e){return f0.test(e)}function h0(e){return e.split("")}var Bm="\\ud800-\\udfff",p0="\\u0300-\\u036f",g0="\\ufe20-\\ufe2f",y0="\\u20d0-\\u20ff",m0=p0+g0+y0,b0="\\ufe0e\\ufe0f",x0="["+Bm+"]",Sd="["+m0+"]",jd="\\ud83c[\\udffb-\\udfff]",v0="(?:"+Sd+"|"+jd+")",Dm="[^"+Bm+"]",Wm="(?:\\ud83c[\\udde6-\\uddff]){2}",Vm="[\\ud800-\\udbff][\\udc00-\\udfff]",w0="\\u200d",Gm=v0+"?",Hm="["+b0+"]?",C0="(?:"+w0+"(?:"+[Dm,Wm,Vm].join("|")+")"+Hm+Gm+")*",S0=Hm+Gm+C0,j0="(?:"+[Dm+Sd+"?",Sd,Wm,Vm,x0].join("|")+")",E0=RegExp(jd+"(?="+jd+")|"+j0+S0,"g");function _0(e){return e.match(E0)||[]}function k0(e){return zm(e)?_0(e):h0(e)}function P0(e){return function(r){r=Od(r);var t=zm(r)?k0(r):void 0,n=t?t[0]:r.charAt(0),o=t?o0(t,1).join(""):r.slice(1);return n[e]()+o}}var A0=P0("toUpperCase");function R0(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 M0(e){return function(r){return e==null?void 0:e[r]}}var T0={À:"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"},I0=M0(T0),N0=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,O0="\\u0300-\\u036f",$0="\\ufe20-\\ufe2f",q0="\\u20d0-\\u20ff",L0=O0+$0+q0,F0="["+L0+"]",z0=RegExp(F0,"g");function B0(e){return e=Od(e),e&&e.replace(N0,I0).replace(z0,"")}var D0=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function W0(e){return e.match(D0)||[]}var V0=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function G0(e){return V0.test(e)}var Um="\\ud800-\\udfff",H0="\\u0300-\\u036f",U0="\\ufe20-\\ufe2f",K0="\\u20d0-\\u20ff",J0=H0+U0+K0,Km="\\u2700-\\u27bf",Jm="a-z\\xdf-\\xf6\\xf8-\\xff",Z0="\\xac\\xb1\\xd7\\xf7",X0="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Y0="\\u2000-\\u206f",Q0=" \\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",Zm="A-Z\\xc0-\\xd6\\xd8-\\xde",ew="\\ufe0e\\ufe0f",Xm=Z0+X0+Y0+Q0,Ym="['’]",Nu="["+Xm+"]",tw="["+J0+"]",Qm="\\d+",rw="["+Km+"]",eb="["+Jm+"]",tb="[^"+Um+Xm+Qm+Km+Jm+Zm+"]",nw="\\ud83c[\\udffb-\\udfff]",ow="(?:"+tw+"|"+nw+")",iw="[^"+Um+"]",rb="(?:\\ud83c[\\udde6-\\uddff]){2}",nb="[\\ud800-\\udbff][\\udc00-\\udfff]",Xr="["+Zm+"]",aw="\\u200d",Ou="(?:"+eb+"|"+tb+")",sw="(?:"+Xr+"|"+tb+")",$u="(?:"+Ym+"(?:d|ll|m|re|s|t|ve))?",qu="(?:"+Ym+"(?:D|LL|M|RE|S|T|VE))?",ob=ow+"?",ib="["+ew+"]?",cw="(?:"+aw+"(?:"+[iw,rb,nb].join("|")+")"+ib+ob+")*",lw="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",dw="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",uw=ib+ob+cw,fw="(?:"+[rw,rb,nb].join("|")+")"+uw,hw=RegExp([Xr+"?"+eb+"+"+$u+"(?="+[Nu,Xr,"$"].join("|")+")",sw+"+"+qu+"(?="+[Nu,Xr+Ou,"$"].join("|")+")",Xr+"?"+Ou+"+"+$u,Xr+"+"+qu,dw,lw,Qm,fw].join("|"),"g");function pw(e){return e.match(hw)||[]}function gw(e,r,t){return e=Od(e),r=r,r===void 0?G0(e)?pw(e):W0(e):e.match(r)||[]}var yw="['’]",mw=RegExp(yw,"g");function bw(e){return function(r){return R0(gw(B0(r).replace(mw,"")),e,"")}}var Ht=bw(function(e,r,t){return e+(t?" ":"")+A0(r)});const vo={label:"Untitled",description:"",isTask:!1,isLocked:!1},$d={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"}}},Lu={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"}}},xw={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"}}},Fu={id:null,type:"workflowStep",data:{...vo,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},Lt=e=>typeof e=="object",ab=e=>Array.isArray(e),vw=["order","position","selected","locked","grabbed","grabbable","scratch"],Rr=e=>Object.entries(e).reduce((r,[t,n])=>(!Lt(n)&&!t.startsWith("$")&&(r[t]=n),r),{}),qd=(e,r)=>typeof e=="string"&&e.startsWith("$")?ei(e,r):Lt(e)&&!ab(e)?Object.entries(e).reduce((t,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete t["..."],t[n]={...ei(o,r),...e}):typeof o=="string"&&o.startsWith("$")?t[n]=ei(o,r):t[n]=o,t),{}):e,Mr=e=>Object.entries(e).reduce((r,[t,n])=>(Lt(n)&&t&&n&&!t.startsWith("$")&&(vw.includes(t)&&(t=t+"#"),r[t]=n),r),{}),zr=(e,r,{label:t,parent:n=void 0},o,i=null)=>(i!==null&&(Lt(i)||ab(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}}),_r=(e,r,t=null,n=null,o=null,i=!1,s=null)=>({data:{id:Nd(),source:o?r:e,target:o?e:r,label:n||"",isInverted:o,isEdgeAnimated:i,parent:s}}),Tr=(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=Lu;const{view:n,borderColor:o,borderRadius:i,bgColor:s,textColor:a,fontSize:c,stepType:l}=r;e=n||e,l?t={...Fu}:e==="object"?t=Lu:e==="text"?t=$d:e==="array"?t=xw:e==="workflowStep"&&(t={...Fu});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),ei=(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=ww(o,t);return JSON.stringify(i).includes(e)?e:i||e}return e},ww=(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}=Tr(s);return s=c.length?c:s,s[a]},i))(r)};function en(e,r="root",t=[]){try{const{arrayObject:n}=Tr(e);n.length&&(e=n);const o=Rr(e),i=Mr(e);return Lt(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=Rr(s),l=Mr(s),{newConfig:d,arrayObject:u}=Tr(s);let h=`${r}.${a}`;Lt(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)&&sb({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=Rr(i),c=Mr(i),{newConfig:l,arrayObject:d}=Tr(i);d.length&&(i=d),n.split(".").slice(0,2).join(".");let u=e?`${e}.${o}`:`${n}.${o}`;if(Lt(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)}),sb=({chldPth:e,item:r,nodes:t,path:n})=>r.forEach((o,i)=>{let s=`${e}.${i}`;const a=Mr(o),c=Rr(o);Lt(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)&&sb({chldPth:s,item:o,nodes:t,path:n}):t.push(s)}),Mn=[];let Tn;function Wr(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}=Tr(e),h=Object.keys(s).length>0?s:d;u.length&&(e=u);const p=Rr(e),m=Mr(e),{label:g,collapsed:y,parent:b}=h;if(!Lt(e))t.push(zr($d,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(zr(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 A=!1;Number.isNaN(Number(o))||(A=!0);const I=e;if(g){const{config:M}=Yr("object",h);t.push(zr(M,r,{label:g||`${g} ${w}`,parent:b},p,I))}else x.data.headerTitle=R,t.push(zr(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=qd(x,Tn);const v=x,C=Rr(x),S=Mr(x),{newConfig:E,arrayObject:R}=Tr(x);R.length&&(x=R);const{config:A}=Yr(typeof x=="string"?"text":"array",E),{hideConfig:I,sourceLabel:M,label:k,isEdgeAnimated:_,parent:$}=E;c=c||I;const N=r==="root"&&i.isCntr,W=r.split(".").slice(0,2).join("."),T=Mn.includes(W),Q=i.isCntr&&T||w%2===0&&N;let ue=`${r}.${w}`;ue=Fn(ue,t),Q&&Mn.push(ue),Lt(x)?Object.keys(C).length&&!ot(x)?(n.push(_r(r,ue,null,M,Q,_)),Wr(x,ue,t,n,k||w,i,E)):Object.keys(S).length&&!ot(x)?In({flowConfig:i,chldPth:ue,isInverted:Q,edges:n,itrblObjct:S,nodes:t,path:r,newConfig:E,forceIsInverted:!0}):ot(x)?cb({flowConfig:i,chldPth:ue,edges:n,isInverted:Q,item:x,nodes:t,path:r}):Lt(x)&&In({flowConfig:i,chldPth:ue,isInverted:Q,edges:n,itrblObjct:[x],nodes:t,path:r,newConfig:E}):(n.push(_r(r,ue,null,M,Q,_)),t.push(zr(A,ue,{label:k||String(x),parent:$},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=qd(h,Tn);const m=h,g=Rr(h),y=Mr(h),{newConfig:b,arrayObject:x}=Tr(h);x.length&&(h=x);const{hideConfig:w,sourceLabel:v,label:C,content:S,target:E,targetLabel:R,collapsed:A,isEdgeAnimated:I,parent:M}=b;l=l||w;const k=s==="root"&&r.isCntr,_=s.split(".").slice(0,2).join("."),$=Mn.includes(_);c||(i=r.isCntr&&$||p%2===0&&k);let N=e?`${e}.${u}`:`${s}.${u}`;if(N=Fn(N,o),i&&Mn.push(N),E&&t.push(_r(N,E,null,R,i,I)),Lt(h)&&!ot(h)){t.push(_r(s,N,null,v,i,I));const W=d||Object.keys(g).length===0;if(W){const T=S?"object":"array",{config:Q}=Yr(T,b);Q.data.headerTitle=S?C:null,o.push(zr(Q,N,{label:C||u,parent:M},h,m))}if(Object.keys(g).length&&!l){const T=ot(h)?` ${h.length||""}`:`{${Object.keys(h).length||""}}`;let Q=N;W&&(Q=`${N}.${T}`,Q=Fn(Q,o),t.push(_r(N,Q,null,v,i,I))),Wr(h,Q,o,t,C||u,r,b)}else Object.keys(y).length&&!ot(h)?In({chldPth:N,flowConfig:r,itrblObjct:y,path:N,edges:t,nodes:o,newConfig:b,isInverted:i}):Wr(h,N,o,t,u,r,b)}else ot(h)&&(t.push(_r(s,N,null,v,i,I)),Wr(h,N,o,t,u,r,b))})},cb=({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=qd(a,Tn);const u=Mr(a),h=Rr(a),{newConfig:p}=Tr(a),{collapsed:m,label:g,parent:y,sourceLabel:b,isEdgeAnimated:x,content:w}=p;Lt(a)?!ot(a)&&Object.keys(h).length?(t.push(_r(s,l,null,b,n,x)),Wr(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)&&cb({flowConfig:e,chldPth:l,edges:t,isInverted:n,item:a,nodes:i,path:s}):(t.push(_r(s,l,null,b,n,x)),i.push(zr($d,l,{label:g||String(a),parent:y},a,d)))});function Cw(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=$e(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=$e(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 lb(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 Sw(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 db(e,r,t){return!t||$e(e,r)===void 0||!t.userId||!t.name.trim()||!Number.isFinite(Date.parse(t.at))?e:Et(e,r,"$edited",t)}const zu=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Yt(e){const r=e.split(".");for(r[0]===tn&&r.shift();r.length&&zu(r[r.length-1]);)r.pop();return r.filter(t=>!zu(t))}function Co(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function $e(e,r){return Yt(r).reduce((t,n)=>{var o;if(t!=null)return(o=Co(t))==null?void 0:o[n]},e)}function jw(e){return Array.isArray(e)?[...e]:{...e}}function Rt(e,r,t){const n=Yt(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=jw(c);return d[a]=l,c!==i?{...i,$:d}:d};return o(e,0)}function yr(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 Et(e,r,t,n){return Rt(e,r,o=>t==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:yr(o,t,n))}const uo=(e,r,t)=>Et(e,r,"$collapsed",t);function Br(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=Yt(t).join("."),i=Yt(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 Er(e,r,t,n){if(r.connection){const a=r.connection;return Rt(e,a.address,c=>lb(c,a.key,l=>{if(t==="$edgeIcon")return yr(l,"icon",n);if(t==="$edgeType")return yr(l,"type",n);if(t==="$edgeAnimationVariant")return yr(l,"animationVariant",n);if(t==="$sourceLabel"||t==="$edgeColor")return yr(l,t==="$sourceLabel"?"label":"color",n);const d=t==="$isEdgeAnimated"?"animated":"dashed";return n?{...l,style:d}:l.style===d?yr(l,"style",void 0):l}))}const{address:o,kind:i}=Br(r),s=i==="target"&&t==="$sourceLabel"?"$targetLabel":i==="target"&&t==="$edgeType"?"$targetEdgeType":i==="target"&&t==="$edgeIcon"?"$targetIcon":i==="target"&&t==="$edgeAnimationVariant"?"$targetAnimationVariant":t;return Rt(e,o,a=>yr(a,s,n))}const ub=(e,r,t)=>Er(Er(e,r,"$isEdgeAnimated",t==="animated"||void 0),r,"$isEdgeDashed",t==="dashed"||void 0);function Ld(e,r,t,n){let o=n||"";const i=Rt(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=Yt(r);return{json:i,address:[tn,...s,o].join(".")}}function fb(e,r){const t=Yt(r);if(!t.length)return e;const n=t[t.length-1],o=[tn,...t.slice(0,-1)].join(".");return Rt(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 hb=(e,r,t,n)=>Et(n?Rt(e,r,o=>yr(o,"$targetLabel",n)):e,r,"$target",t);function Fd(e,r,t){const n=$e(e,r);return wo(n).some(({value:i})=>i.target===t.target&&i.sourceProperty===t.sourceProperty&&i.targetProperty===t.targetProperty)?e:Rt(e,r,i=>yr(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...t,id:t.id||Nd()}]))}function pb(e,r){if(r.connection){const i=r.connection;return wo($e(e,i.address)).some(s=>s.key===i.key)?{json:Rt(e,i.address,s=>lb(s,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:t,kind:n}=Br(r);return n==="hierarchy"?$e(e,t)===void 0?{json:e,removed:!1}:{json:Rt(e,t,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:Rt(e,t,i=>{const{$target:s,$targetLabel:a,...c}=i||{};return c}),removed:!0}}function Ed(e,r={}){var x;const t=Sw(e),{nodes:n,edges:o}=Wr(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")||$e(e,v)!==void 0)continue;const C=v.slice(0,-2),S=$e(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=Br(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(Yt(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}.${Yt(v)[0]}`,S=w.get(C);typeof S=="boolean"&&l.set(v,S)}}const d=n.map(w=>{var A;const v=a(w.data.id),C=$e(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(((A=S.config)==null?void 0:A.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=Br(w.data),R=l.get(a(E.address));E.kind==="hierarchy"&&R!==void 0&&R!==!!S&&([v,C]=[C,v],S=R);const A=`${v}->${C}`,I=u.get(A)??0;u.set(A,I+1);const M={...w.data,id:I?`${A}#${I}`:A,source:v,target:C,isInverted:S},k=Br(M),_=$e(e,k.address);if(_&&typeof _=="object"){const $=_[k.kind==="target"?"$targetEdgeType":"$edgeType"];typeof $=="string"&&(M.type=$);const N=_[k.kind==="target"?"$targetIcon":"$edgeIcon"];typeof N=="string"&&(M.icon=N),_.$isEdgeAnimated!==void 0&&(M.isEdgeAnimated=!!_.$isEdgeAnimated);const W=_[k.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(W)&&(M.edgeAnimationVariant=W),_.$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=Br(v);(!p.has(v.source)||!p.has(v.target)||C.kind==="hierarchy"&&((x=$e(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=Cw(e,{nodes:d,edges:h}),g=m.nodes.filter(w=>{var v;return(v=w.data.config)==null?void 0:v.collapsed}).map(w=>Yt(w.data.id));if(!g.length)return m;const y=m.nodes.filter(w=>{const v=Yt(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 Ew(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 _w=new Intl.RelativeTimeFormat("en",{numeric:"always"});function gb(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 _w.format(-Math.floor(n/i),s)}let _d=Date.now(),to;const ro=new Set,kw=e=>(ro.add(e),to||(_d=Date.now(),to=setInterval(()=>{_d=Date.now(),ro.forEach(r=>r())},6e4)),()=>{ro.delete(e),ro.size||(clearInterval(to),to=void 0)}),Pw=()=>_d,Aw=()=>0;function Rw(e){const r=j.useSyncExternalStore(kw,Pw,Aw);return gb(e,r||Date.now())}function Mw(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 Bu(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 lr=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"},yb=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}},Du={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"}},Ie=(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=Du[n])!=null&&i[Number(o)])?Du[n][Number(o)]:`var(--chakra-colors-${t})`},Tw=$m.keyframes`
|
|
2
2
|
0%, 100% { box-shadow: var(--flow-rest-shadow); }
|
|
3
3
|
25%, 50% { box-shadow: var(--flow-hover-shadow); }
|
|
4
|
-
`,
|
|
4
|
+
`,Iw=$m.keyframes`
|
|
5
5
|
from { box-shadow: var(--flow-start-shadow); }
|
|
6
6
|
to { box-shadow: var(--flow-rest-shadow); }
|
|
7
|
-
`;function yb(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?`${Mw} 1200ms steps(10, end) 600ms`:"none"}}}}}}function mr(e,r){const{boxShadow:t,css:n}=yb(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:`${Tw} 600ms steps(5, end)`}}}}}const mb=j.createContext(null),bb=j.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function Qt(){return j.useContext(bb)}function Ve(){const e=j.useContext(mb);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function xb({config:e,callbacks:r,nodes:t=[],edges:n=[],children:o}){const i=j.useMemo(()=>{var xe,_e,Te;const F=new Map;for(const Re of t)(xe=Re.data)!=null&&xe.id&&F.set(Re.data.id,Re);const $=new Map;for(const Re of n)(_e=Re.data)!=null&&_e.id&&$.set(Re.data.id,Re);const se=new Set;for(const Re of t)(Te=Re.data)!=null&&Te.parent&&se.add(Re.data.parent);return{nodeById:F,edgeById:$,parentIds:se}},[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),[A,I]=j.useState(null),M=j.useRef(A),[k,_]=j.useState({gaps:15,fill:!1,padding:0}),[N,O]=j.useState(()=>new Set),[W,T]=j.useState({}),Y=j.useCallback((F,$)=>{T(se=>{const xe={...se};for(const _e of F)$===void 0?delete xe[_e]:xe[_e]=$;return xe})},[]),he=j.useCallback(F=>{var $;!!(F!=null&&F.fill)!=!!(($=M.current)!=null&&$.fill)&&O(new Set),M.current=F,F&&_(F),I(F)},[]),[K,re]=j.useState("auto"),[G,ne]=j.useState(!1),q=e.compactPropertyLayout??G,[z,H]=j.useState({}),V=e.nodeViewModes??z,le=[...i.nodeById.values()].filter(F=>{var $;return i.parentIds.has(F.data.id)||(($=F.data.config)==null?void 0:$.parentContainer)||F.data.type==="objectView"||F.data.type==="arrayView"}),X=!!le.length&&le.every(F=>{var $,se,xe;return i.parentIds.has(F.data.id)||($=F.data.config)!=null&&$.parentContainer?!!((se=F.data.config)!=null&&se.collapsed):V[F.data.id]==="icon-label"||((xe=F.data.config)==null?void 0:xe.labelBelow)&&V[F.data.id]!=="properties"}),[ue,oe]=j.useState("normal"),[de,ge]=j.useState(),ce=e.edgeRadius??de,U=ce!==void 0&&Number.isFinite(ce)?Math.min(500,Math.max(0,ce)):void 0,[te,pe]=j.useState(),ve=e.spacing??ue,Ne=typeof ve=="number"?Number.isFinite(ve)?Math.min(2,Math.max(.5,ve)):1:ve==="compact"?.5:ve==="spacious"?2:1,Je=e.backgroundVariant??te??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[tt,Ye]=j.useState(),Ue=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:tt,[lt,be]=j.useState("blue.500"),[Ae,ie]=j.useState(!1),ae=j.useRef(r);ae.current=r;const Ie=j.useMemo(()=>{const F=xe=>(..._e)=>{var Te,Re;return(Re=(Te=ae.current)==null?void 0:Te[xe])==null?void 0:Re.call(Te,..._e)},$=F("onPromptSubmit"),se=F("onFixedNodePositionsChange");return{getNodeEditMetadata:F("getNodeEditMetadata"),onNodeSelect:F("onNodeSelect"),onNodesCopy:F("onNodesCopy"),onNodesDuplicate:F("onNodesDuplicate"),onBackgroundClick:F("onBackgroundClick"),onBottomBarCollapsedChange:F("onBottomBarCollapsedChange"),onNodeGridZoomOut:F("onNodeGridZoomOut"),onNodeGridFillRequest:F("onNodeGridFillRequest"),onNodeGridModeRequest:F("onNodeGridModeRequest"),onNodeGridDrop:F("onNodeGridDrop"),onNodeDeselect:F("onNodeDeselect"),onNodeDoubleClick:F("onNodeDoubleClick"),onNodeViewToggle:F("onNodeViewToggle"),onNodeTypeViewChange:F("onNodeTypeViewChange"),onNodeCreate:F("onNodeCreate"),onNodeCreateRequest:F("onNodeCreateRequest"),onNodeDelete:F("onNodeDelete"),onNodeLabelChange:F("onNodeLabelChange"),onNodeSubtitleChange:F("onNodeSubtitleChange"),onNodeContentChange:F("onNodeContentChange"),onNodeContentFormatChange:F("onNodeContentFormatChange"),onNodeDimensionChange:F("onNodeDimensionChange"),onNodeParentChange:F("onNodeParentChange"),get onFixedNodePositionsChange(){return ae.current.onFixedNodePositionsChange?se:void 0},get onPromptSubmit(){return ae.current.onPromptSubmit?$:void 0},onNodeCollapse:F("onNodeCollapse"),onNodeColorChange:F("onNodeColorChange"),onNodeBorderColorChange:F("onNodeBorderColorChange"),onNodeBorderStyleChange:F("onNodeBorderStyleChange"),onNodeBorderWidthChange:F("onNodeBorderWidthChange"),onNodeBorderRadiusChange:(xe,_e)=>{var Te,Re,Ze;(Te=M.current)!=null&&Te.fill&&O(Qe=>new Set([...Qe,xe])),(Ze=(Re=ae.current).onNodeBorderRadiusChange)==null||Ze.call(Re,xe,_e)},onNodeIconChange:F("onNodeIconChange"),onNodeOutlineChange:F("onNodeOutlineChange"),onNodeAnimationChange:F("onNodeAnimationChange"),onNodeAnimationVariantChange:F("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:F("onEdgeAnimationVariantChange"),onNodeHoverAction:F("onNodeHoverAction"),onEdgeCreate:F("onEdgeCreate"),onEdgeSelect:F("onEdgeSelect"),onEdgeDeselect:F("onEdgeDeselect"),onEdgeRemove:F("onEdgeRemove"),onEdgeDelete:F("onEdgeDelete"),onEdgeColorChange:F("onEdgeColorChange"),onEdgeTypeChange:F("onEdgeTypeChange"),onEdgeIconChange:F("onEdgeIconChange"),onEdgeLabelChange:F("onEdgeLabelChange"),onEdgeStyleChange:F("onEdgeStyleChange"),onViewportChange:F("onViewportChange"),onDirectionChange:F("onDirectionChange"),onThemeColorChange:F("onThemeColorChange"),onSpacingChange:F("onSpacingChange"),onEdgeRadiusChange:F("onEdgeRadiusChange"),onBackgroundVariantChange:F("onBackgroundVariantChange"),onEdgeModeChange:F("onEdgeModeChange"),onCompactPropertyLayoutChange:F("onCompactPropertyLayoutChange"),onWorkflowContractChange:F("onWorkflowContractChange"),onWorkflowConfigurationOpen:r.onWorkflowConfigurationOpen?F("onWorkflowConfigurationOpen"):void 0,onArrayModeChange:F("onArrayModeChange"),onInit:F("onInit"),onLayoutComplete:F("onLayoutComplete"),onJsonChange:F("onJsonChange")}},[]),et=e.themeColor||lt,[Ee,Le]=j.useState(""),at=e.edgeColor??Ee,He=e.colorMode||"light",ft=e.direction||"LR",ht=e.nodeAlignment??"center",At=e.edgeMode==="workflow"?"nodes":e.edgeMode??K,Lt=e.readOnly??!1,rt=JSON.stringify(e.parentNodeStyle??null),We=j.useMemo(()=>e.parentNodeStyle,[rt]),tr=e.isZoomMode!==void 0?e.isZoomMode:u,pt=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,Ft=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:b,fr=e.isDragMode!==void 0?e.isDragMode:g,De=j.useRef(e);De.current=e;const Kt=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}}),[]),zt=j.useCallback((F,$)=>{var se;if($!=="default"&&$!=="properties"&&$!=="icon-label")throw new Error("Unknown node view mode.");H(xe=>xe[F]===$?xe:{...xe,[F]:$}),(se=r.onNodeViewModeChange)==null||se.call(r,F,$)},[r.onNodeViewModeChange]),hr=j.useMemo(()=>({allNodesIconLabel:X,setAllNodesIconLabel:F=>{var $,se,xe,_e,Te;if(!F)for(const[Re,Ze]of Object.entries(V))Ze==="icon-label"&&!i.nodeById.has(Re)&&zt(Re,"default");for(const Re of le)i.parentIds.has(Re.data.id)||($=Re.data.config)!=null&&$.parentContainer?!Lt&&!!((se=Re.data.config)!=null&&se.collapsed)!==F&&((xe=r.onNodeCollapse)==null||xe.call(r,Re.data.id,F)):zt(Re.data.id,F?"icon-label":(_e=Re.data.config)!=null&&_e.labelBelow?"properties":"default");(Te=r.onAllNodesIconLabelChange)==null||Te.call(r,F)},nodeViewModes:V,setNodeViewMode:zt,nodeRadiusPreviews:W,setNodeRadiusPreview:Y,spacing:Ne,setSpacing:oe,edgeRadius:U,setEdgeRadius:ge,backgroundVariant:Je,setBackgroundVariant:pe,themeColor:et,setThemeColor:be,backgroundSelected:Ae,setBackgroundSelected:ie,edgeColor:at,setEdgeColor:F=>{var $;Le(F),($=r.onGraphEdgeColorChange)==null||$.call(r,F)},colorMode:He,direction:ft,nodeAlignment:ht,edgeMode:At,setEdgeMode:re,compactPropertyLayout:q,setCompactPropertyLayout:ne,workflowContract:Ue,setWorkflowContract:Ye,parentNodeStyle:We,selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isZoomMode:tr,setIsZoomMode:h,isMultiSelectMode:pt,setIsMultiSelectMode:m,isDragMode:fr,setIsDragMode:y,isEdgeHandlesEnabled:Ft,setIsEdgeHandlesEnabled:x,isArrayNodeMode:w,setIsArrayNodeMode:v,isPinned:C,setIsPinned:S,isPerformanceMode:E,setIsPerformanceMode:R,nodeGridOptions:A,setNodeGridOptions:he,lastNodeGridOptions:k,fillRadiusEditedIds:N,setFillRadiusEditedIds:O,engineRef:s,callbacks:Ie,config:Kt,readOnly:Lt}),[X,i,zt,r.onNodeCollapse,r.onAllNodesIconLabelChange,r.onGraphEdgeColorChange,V,W,Y,r.onNodeViewModeChange,et,Ne,Je,U,e.backgroundColor,Ae,at,He,ft,ht,At,Ue,We,a,l,tr,pt,fr,Ft,w,C,E,A,k,N,Lt,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,Ie,Kt]);return f.jsx(mb.Provider,{value:hr,children:f.jsx(bb.Provider,{value:i,children:o})})}function kt(e,r,t){return e?t:r}function Gn(e){const[r]=(e==null?void 0:e.split("."))||[],{secondary:t}=gb(e),n=lr(r).background,o=lr(r).highlight,i=lr(r).border,s=lr(r).property,a=lr(r).property;let c=lr(r).background,l=lr(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 st(e=null){const{colorMode:r}=Ve(),t=e==null?void 0:e.includes("gray"),n=r==="dark",o=kt(n,"white","gray.900"),i=kt(n,"gray.100","gray.800"),s=kt(n,"gray.200","blackAlpha.400"),a=kt(n,"gray.200","blackAlpha.600"),c=kt(n,"gray.500","gray.700"),l=kt(n,"gray.700","gray.700"),d=kt(n,"gray.900","gray.900"),u=kt(n,"gray.400","gray.500"),h=kt(n,"gray.400","gray.500"),p=kt(n,"gray.900","gray.200"),m=kt(n,t?"gray.900":"gray.200",t?"gray.200":"gray.900"),g=kt(n,"gray.900","gray.200"),y=kt(n,e&&"#000000",e||"#ffffff"),b=kt(n,e||"#ffffff",e?"#000000":"#ffffff"),x=l,w=kt(n,"gray.300","gray.800"),v=kt(n,"white","blackAlpha.400"),C=kt(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 zd=["","icon-label","object","text","grid","parent","prompt"];function vb({label:e,disabled:r=!1}){const t=j.useRef(null),n=j.useRef(),{colorInactive:o}=st(),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(D.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(Z.PiDotsSix,{size:20,"aria-hidden":"true"})})}function Iw(){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),Nw=()=>j.useState(Iw)[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 Ow({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(!D.Tooltip.Root){const n=D.Tooltip;return f.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:t})}return f.jsxs(D.Tooltip.Root,{positioning:{placement:"top"},children:[f.jsx(D.Tooltip.Trigger,{asChild:!0,children:t}),f.jsx(D.Portal,{children:f.jsx(D.Tooltip.Positioner,{children:f.jsx(D.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function Nn(){const{border:e}=st(),{colorMode:r}=Ve();return f.jsx(D.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:r==="dark"?e:"gray.300"})}function Nt({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 he;const{colorMode:y}=Ve(),{background:b,border:x,colorText:w,colorInactive:v}=st(),C=y==="dark",S=j.useId(),E=j.useRef(null),R=j.useRef(null),[A,I]=j.useState(!1),M=jo(f.jsx(Nt,{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,re=K.matches(":popover-open"),G=document.activeElement instanceof HTMLElement&&K.contains(document.activeElement)?document.activeElement:null,ne=[K,...K.querySelectorAll("*")].filter(H=>H.scrollTop||H.scrollLeft).map(H=>({element:H,top:H.scrollTop,left:H.scrollLeft})),q=l?"manual":"auto";if(K.getAttribute("popover")!==q&&K.setAttribute("popover",q),re){K.showPopover(),!l&&K.dataset.flowPanelMoved&&(delete K.dataset.flowPanelMoved,O()),G==null||G.focus({preventScroll:!0});for(const{element:H,top:V,left:le}of ne)H.scrollTop=V,H.scrollLeft=le}const z=H=>{const V=H.newState==="open";I(V),h==null||h(V)};return K.addEventListener("toggle",z),()=>K.removeEventListener("toggle",z)},[l,h]);const k=j.Children.toArray(e).filter(j.isValidElement).map(K=>{const re=K.props;return{value:String(re.value),label:typeof re.children=="string"&&p==="title"?Vt(re.children):re.children,description:re.description,disabled:re.disabled}}),_=k.some(K=>K.description),N=()=>{var K;return(K=R.current)==null?void 0:K.hidePopover()},O=()=>{var z,H,V,le,X;const K=(z=E.current)==null?void 0:z.getBoundingClientRect(),re=R.current;if(!K||!re||l&&re.dataset.flowPanelMoved)return;if(l){re.style.maxHeight=`${Math.max(60,window.innerHeight-108)}px`,re.style.left="20px",re.style.top="84px";return}if((H=E.current)!=null&&H.closest("[popover]")){const ue=window.innerHeight-K.bottom-16,oe=K.top-16;re.style.maxHeight=`${Math.max(60,ue,oe)}px`;const de=re.getBoundingClientRect();re.style.left=`${Math.max(12,Math.min(K.right-de.width,window.innerWidth-de.width-12))}px`,re.style.top=`${Math.max(12,de.height<=ue?K.bottom+4:K.top-de.height-4)}px`;return}const G=(X=(le=(V=E.current)==null?void 0:V.closest("[data-flow-toolbar-scroll]"))==null?void 0:le.parentElement)==null?void 0:X.getBoundingClientRect(),ne=G??K;re.style.maxHeight=`${Math.max(60,Math.max(ne.top-40,window.innerHeight-ne.bottom-40))}px`;const q=re.getBoundingClientRect();re.style.left=`${Math.max(12,Math.min(Math.max((G==null?void 0:G.left)??12,K.right-q.width),((G==null?void 0:G.right)??window.innerWidth-12)-q.width,window.innerWidth-q.width-12))}px`,re.style.top=`${Math.max(12,ne.top>=q.height+36?ne.top-q.height-24:Math.min(ne.bottom+24,window.innerHeight-q.height-12))}px`},W=()=>{try{return localStorage.getItem(`flow:panel-position:${m}`)}catch{return null}},T=()=>{var G,ne,q,z,H,V;if(n)return;if(R.current&&!R.current.matches(":popover-open")&&!W()&&delete R.current.dataset.flowPanelMoved,(G=R.current)==null||G.showPopover(),O(),a){(q=(ne=R.current)==null?void 0:ne.querySelector("input"))==null||q.focus({preventScroll:!0});return}const K=(z=R.current)==null?void 0:z.querySelectorAll('[role="option"]:not(:disabled)');(V=((H=R.current)==null?void 0:H.querySelector('[aria-selected="true"]:not(:disabled)'))??(K==null?void 0:K[0]))==null||V.focus()};j.useLayoutEffect(()=>{u!==void 0&&(u?T():N())},[u]),j.useEffect(()=>{if(A){if(n){N();return}return O(),window.addEventListener("resize",O),window.addEventListener("scroll",O,!0),()=>{window.removeEventListener("resize",O),window.removeEventListener("scroll",O,!0)}}},[A,n,l]);const Y=`var(--chakra-colors-${b.replace(".","-")})`;return f.jsxs(f.Fragment,{children:[f.jsx(Ge,{label:i??m,children:f.jsx(D.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":A,"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(),A?N():T()},onKeyDown:K=>{["ArrowDown","ArrowUp"].includes(K.key)&&(K.preventDefault(),T())},children:s??f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((he=k.find(K=>K.value===r))==null?void 0:he.label)??r}),f.jsx(Z.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),f.jsxs(D.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"},...mr(Y,`var(--chakra-colors-${(C?x:"gray.300").replace(".","-")})`)},onKeyDown:K=>{var ne,q,z;if(a&&!["Escape","Tab"].includes(K.key))return;const re=[...K.currentTarget.querySelectorAll('[role="option"]:not(:disabled), [data-flow-menu-action]:not(:disabled)')],G=re.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(K.key)){K.preventDefault();const H=K.key==="Home"?0:K.key==="End"?re.length-1:(G+(K.key==="ArrowDown"?1:-1)+re.length)%re.length;(ne=re[H])==null||ne.focus()}else if(K.key==="Escape"||K.key==="Tab"){if(K.key==="Tab"&&l)return;K.key==="Escape"&&(K.preventDefault(),K.stopPropagation()),N(),(q=E.current)==null||q.focus()}else K.key.length===1&&K.key!==" "&&((z=re.find((H,V)=>{var le;return V>G&&((le=H.textContent)==null?void 0:le.toLowerCase().startsWith(K.key.toLowerCase()))}))==null||z.focus())},children:[d&&l&&f.jsx(vb,{label:m}),a??k.map(K=>f.jsxs(D.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"},..._&&{_notLast:{borderBottom:"1px solid",borderColor:C?"whiteAlpha.100":"blackAlpha.100"}},onClick:()=>{var re;l||(N(),(re=E.current)==null||re.focus()),t(K.value)},children:[f.jsxs("span",{style:{flex:1,display:"flex",flexDirection:"column",gap:1,minWidth:0},children:[f.jsx("span",{style:{flexShrink:0},children:K.label}),K.description&&f.jsx("span",{style:{opacity:.55,fontFamily:"monospace",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:K.description})]}),f.jsx(Z.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"}},Oe=j.forwardRef(function({icon:r,rememberAction:t=!0,...n},o){const{colorMode:i}=Ve(),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(Oe,{...s,icon:r})}),t&&!!n.onClick);return f.jsx(D.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}=Ve();return f.jsx(Ge,{label:"Close",children:f.jsx(Oe,{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(Z.PiXLight,{size:20,"aria-hidden":"true"})})})});function wb({onBeforeExpand:e}={}){const{allNodesIconLabel:r,setAllNodesIconLabel:t}=Ve();return f.jsx(on,{label:"Collapse all",hideLabel:!0,checked:r,icon:f.jsx(Z.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}=Ve(),{colorInactive:l}=st();return f.jsx(Ge,{label:s,children:f.jsx(Oe,{"aria-label":e,"aria-pressed":t,icon:f.jsxs(f.Fragment,{children:[r,!i&&f.jsx(D.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 Cb({label:e="Compact layout"}={}){const{compactPropertyLayout:r,setCompactPropertyLayout:t,callbacks:n}=Ve();return f.jsx(on,{hideLabel:!0,label:e,checked:r,icon:f.jsx(D.Icon,{as:Z.PiArrowsIn,boxSize:5}),onChange:o=>{var i;t(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const $w=xo.default.input`
|
|
7
|
+
`;function mb(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?`${Tw} 1200ms steps(10, end) 600ms`:"none"}}}}}}function mr(e,r){const{boxShadow:t,css:n}=mb(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:`${Iw} 600ms steps(5, end)`}}}}}const bb=j.createContext(null),xb=j.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function tr(){return j.useContext(xb)}function Ge(){const e=j.useContext(bb);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function vb({config:e,callbacks:r,nodes:t=[],edges:n=[],children:o}){const i=j.useMemo(()=>{var be,ke,Me;const z=new Map;for(const Te of t)(be=Te.data)!=null&&be.id&&z.set(Te.data.id,Te);const O=new Map;for(const Te of n)(ke=Te.data)!=null&&ke.id&&O.set(Te.data.id,Te);const ae=new Set;for(const Te of t)(Me=Te.data)!=null&&Me.parent&&ae.add(Te.data.parent);return{nodeById:z,edgeById:O,parentIds:ae}},[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),[A,I]=j.useState(null),M=j.useRef(A),[k,_]=j.useState({gaps:15,fill:!1,padding:0}),[$,N]=j.useState(()=>new Set),[W,T]=j.useState({}),Q=j.useCallback((z,O)=>{T(ae=>{const be={...ae};for(const ke of z)O===void 0?delete be[ke]:be[ke]=O;return be})},[]),ue=j.useCallback(z=>{var O;!!(z!=null&&z.fill)!=!!((O=M.current)!=null&&O.fill)&&N(new Set),M.current=z,z&&_(z),I(z)},[]),[K,ce]=j.useState("auto"),[V,re]=j.useState(!1),q=e.compactPropertyLayout??V,[F,G]=j.useState({}),se=e.nodeViewModes??F,U=[...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"}),Y=!!U.length&&U.every(z=>{var O,ae,be;return i.parentIds.has(z.data.id)||(O=z.data.config)!=null&&O.parentContainer?!!((ae=z.data.config)!=null&&ae.collapsed):se[z.data.id]==="icon-label"||((be=z.data.config)==null?void 0:be.labelBelow)&&se[z.data.id]!=="properties"}),[le,ne]=j.useState("normal"),[de,xe]=j.useState(),he=e.edgeRadius??de,H=he!==void 0&&Number.isFinite(he)?Math.min(500,Math.max(0,he)):void 0,[J,fe]=j.useState(),ve=e.spacing??le,Re=typeof ve=="number"?Number.isFinite(ve)?Math.min(2,Math.max(.5,ve)):1:ve==="compact"?.5:ve==="spacious"?2:1,Je=e.backgroundVariant??J??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[st,Ye]=j.useState(),We=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:st,[Ze,me]=j.useState("blue.500"),[Ae,oe]=j.useState(!1),ie=j.useRef(r);ie.current=r;const Ne=j.useMemo(()=>{const z=be=>(...ke)=>{var Me,Te;return(Te=(Me=ie.current)==null?void 0:Me[be])==null?void 0:Te.call(Me,...ke)},O=z("onPromptSubmit"),ae=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 ie.current.onFixedNodePositionsChange?ae:void 0},get onPromptSubmit(){return ie.current.onPromptSubmit?O:void 0},onNodeCollapse:z("onNodeCollapse"),onNodeColorChange:z("onNodeColorChange"),onNodeBorderColorChange:z("onNodeBorderColorChange"),onNodeBorderStyleChange:z("onNodeBorderStyleChange"),onNodeBorderWidthChange:z("onNodeBorderWidthChange"),onNodeBorderRadiusChange:(be,ke)=>{var Me,Te,rt;(Me=M.current)!=null&&Me.fill&&N(et=>new Set([...et,be])),(rt=(Te=ie.current).onNodeBorderRadiusChange)==null||rt.call(Te,be,ke)},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")}},[]),Qe=e.themeColor||Ze,[Ee,Le]=j.useState(""),ct=e.edgeColor??Ee,Ue=e.colorMode||"light",ht=e.direction||"LR",pt=e.nodeAlignment??"center",At=e.edgeMode==="workflow"?"nodes":e.edgeMode??K,zt=e.readOnly??!1,tt=JSON.stringify(e.parentNodeStyle??null),Ve=j.useMemo(()=>e.parentNodeStyle,[tt]),nr=e.isZoomMode!==void 0?e.isZoomMode:u,gt=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,Bt=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:b,fr=e.isDragMode!==void 0?e.isDragMode:g,De=j.useRef(e);De.current=e;const Zt=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}}),[]),Dt=j.useCallback((z,O)=>{var ae;if(O!=="default"&&O!=="properties"&&O!=="icon-label")throw new Error("Unknown node view mode.");G(be=>be[z]===O?be:{...be,[z]:O}),(ae=r.onNodeViewModeChange)==null||ae.call(r,z,O)},[r.onNodeViewModeChange]),hr=j.useMemo(()=>({allNodesIconLabel:Y,setAllNodesIconLabel:z=>{var O,ae,be,ke,Me;if(!z)for(const[Te,rt]of Object.entries(se))rt==="icon-label"&&!i.nodeById.has(Te)&&Dt(Te,"default");for(const Te of U)i.parentIds.has(Te.data.id)||(O=Te.data.config)!=null&&O.parentContainer?!zt&&!!((ae=Te.data.config)!=null&&ae.collapsed)!==z&&((be=r.onNodeCollapse)==null||be.call(r,Te.data.id,z)):Dt(Te.data.id,z?"icon-label":(ke=Te.data.config)!=null&&ke.labelBelow?"properties":"default");(Me=r.onAllNodesIconLabelChange)==null||Me.call(r,z)},nodeViewModes:se,setNodeViewMode:Dt,nodeRadiusPreviews:W,setNodeRadiusPreview:Q,spacing:Re,setSpacing:ne,edgeRadius:H,setEdgeRadius:xe,backgroundVariant:Je,setBackgroundVariant:fe,themeColor:Qe,setThemeColor:me,backgroundSelected:Ae,setBackgroundSelected:oe,edgeColor:ct,setEdgeColor:z=>{var O;Le(z),(O=r.onGraphEdgeColorChange)==null||O.call(r,z)},colorMode:Ue,direction:ht,nodeAlignment:pt,edgeMode:At,setEdgeMode:ce,compactPropertyLayout:q,setCompactPropertyLayout:re,workflowContract:We,setWorkflowContract:Ye,parentNodeStyle:Ve,selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isZoomMode:nr,setIsZoomMode:h,isMultiSelectMode:gt,setIsMultiSelectMode:m,isDragMode:fr,setIsDragMode:y,isEdgeHandlesEnabled:Bt,setIsEdgeHandlesEnabled:x,isArrayNodeMode:w,setIsArrayNodeMode:v,isPinned:C,setIsPinned:S,isPerformanceMode:E,setIsPerformanceMode:R,nodeGridOptions:A,setNodeGridOptions:ue,lastNodeGridOptions:k,fillRadiusEditedIds:$,setFillRadiusEditedIds:N,engineRef:s,callbacks:Ne,config:Zt,readOnly:zt}),[Y,i,Dt,r.onNodeCollapse,r.onAllNodesIconLabelChange,r.onGraphEdgeColorChange,se,W,Q,r.onNodeViewModeChange,Qe,Re,Je,H,e.backgroundColor,Ae,ct,Ue,ht,pt,At,We,Ve,a,l,nr,gt,fr,Bt,w,C,E,A,k,$,zt,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,Ne,Zt]);return f.jsx(bb.Provider,{value:hr,children:f.jsx(xb.Provider,{value:i,children:o})})}function kt(e,r,t){return e?t:r}function Gn(e){const[r]=(e==null?void 0:e.split("."))||[],{secondary:t}=yb(e),n=lr(r).background,o=lr(r).highlight,i=lr(r).border,s=lr(r).property,a=lr(r).property;let c=lr(r).background,l=lr(r).highlight;return c=e==="transparent"?e:Ie(c)+50,l=e==="transparent"?e:Ie(l)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:s,propertyColor:a,secondary:t,bgColorFaint:c,highlightColorFaint:l}}function lt(e=null){const{colorMode:r}=Ge(),t=e==null?void 0:e.includes("gray"),n=r==="dark",o=kt(n,"white","gray.900"),i=kt(n,"gray.100","gray.800"),s=kt(n,"gray.200","blackAlpha.400"),a=kt(n,"gray.200","blackAlpha.600"),c=kt(n,"gray.500","gray.700"),l=kt(n,"gray.700","gray.700"),d=kt(n,"gray.900","gray.900"),u=kt(n,"gray.400","gray.500"),h=kt(n,"gray.400","gray.500"),p=kt(n,"gray.900","gray.200"),m=kt(n,t?"gray.900":"gray.200",t?"gray.200":"gray.900"),g=kt(n,"gray.900","gray.200"),y=kt(n,e&&"#000000",e||"#ffffff"),b=kt(n,e||"#ffffff",e?"#000000":"#ffffff"),x=l,w=kt(n,"gray.300","gray.800"),v=kt(n,"white","blackAlpha.400"),C=kt(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 zd=["","icon-label","object","text","grid","parent","prompt"];function wb({label:e,disabled:r=!1}){const t=j.useRef(null),n=j.useRef(),{colorInactive:o}=lt(),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(D.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(X.PiDotsSix,{size:20,"aria-hidden":"true"})})}function Nw(){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),Ow=()=>j.useState(Nw)[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 $w({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 He({label:e,children:r}){const t=j.cloneElement(r,{title:r.props.title??e});if(!D.Tooltip.Root){const n=D.Tooltip;return f.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:t})}return f.jsxs(D.Tooltip.Root,{positioning:{placement:"top"},children:[f.jsx(D.Tooltip.Trigger,{asChild:!0,children:t}),f.jsx(D.Portal,{children:f.jsx(D.Tooltip.Positioner,{children:f.jsx(D.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function Nn(){const{border:e}=lt(),{colorMode:r}=Ge();return f.jsx(D.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:r==="dark"?e:"gray.300"})}function Ot({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 ue;const{colorMode:y}=Ge(),{background:b,border:x,colorText:w,colorInactive:v}=lt(),C=y==="dark",S=j.useId(),E=j.useRef(null),R=j.useRef(null),[A,I]=j.useState(!1),M=jo(f.jsx(Ot,{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,ce=K.matches(":popover-open"),V=document.activeElement instanceof HTMLElement&&K.contains(document.activeElement)?document.activeElement:null,re=[K,...K.querySelectorAll("*")].filter(G=>G.scrollTop||G.scrollLeft).map(G=>({element:G,top:G.scrollTop,left:G.scrollLeft})),q=l?"manual":"auto";if(K.getAttribute("popover")!==q&&K.setAttribute("popover",q),ce){K.showPopover(),!l&&K.dataset.flowPanelMoved&&(delete K.dataset.flowPanelMoved,N()),V==null||V.focus({preventScroll:!0});for(const{element:G,top:se,left:U}of re)G.scrollTop=se,G.scrollLeft=U}const F=G=>{const se=G.newState==="open";I(se),h==null||h(se)};return K.addEventListener("toggle",F),()=>K.removeEventListener("toggle",F)},[l,h]);const k=j.Children.toArray(e).filter(j.isValidElement).map(K=>{const ce=K.props;return{value:String(ce.value),label:typeof ce.children=="string"&&p==="title"?Ht(ce.children):ce.children,description:ce.description,disabled:ce.disabled}}),_=k.some(K=>K.description),$=()=>{var K;return(K=R.current)==null?void 0:K.hidePopover()},N=()=>{var F,G,se,U,Y;const K=(F=E.current)==null?void 0:F.getBoundingClientRect(),ce=R.current;if(!K||!ce||l&&ce.dataset.flowPanelMoved)return;if(l){ce.style.maxHeight=`${Math.max(60,window.innerHeight-108)}px`,ce.style.left="20px",ce.style.top="84px";return}if((G=E.current)!=null&&G.closest("[popover]")){const le=window.innerHeight-K.bottom-16,ne=K.top-16;ce.style.maxHeight=`${Math.max(60,le,ne)}px`;const de=ce.getBoundingClientRect();ce.style.left=`${Math.max(12,Math.min(K.right-de.width,window.innerWidth-de.width-12))}px`,ce.style.top=`${Math.max(12,de.height<=le?K.bottom+4:K.top-de.height-4)}px`;return}const V=(Y=(U=(se=E.current)==null?void 0:se.closest("[data-flow-toolbar-scroll]"))==null?void 0:U.parentElement)==null?void 0:Y.getBoundingClientRect(),re=V??K;ce.style.maxHeight=`${Math.max(60,Math.max(re.top-40,window.innerHeight-re.bottom-40))}px`;const q=ce.getBoundingClientRect();ce.style.left=`${Math.max(12,Math.min(Math.max((V==null?void 0:V.left)??12,K.right-q.width),((V==null?void 0:V.right)??window.innerWidth-12)-q.width,window.innerWidth-q.width-12))}px`,ce.style.top=`${Math.max(12,re.top>=q.height+36?re.top-q.height-24:Math.min(re.bottom+24,window.innerHeight-q.height-12))}px`},W=()=>{try{return localStorage.getItem(`flow:panel-position:${m}`)}catch{return null}},T=()=>{var V,re,q,F,G,se;if(n)return;if(R.current&&!R.current.matches(":popover-open")&&!W()&&delete R.current.dataset.flowPanelMoved,(V=R.current)==null||V.showPopover(),N(),a){(q=(re=R.current)==null?void 0:re.querySelector("input"))==null||q.focus({preventScroll:!0});return}const K=(F=R.current)==null?void 0:F.querySelectorAll('[role="option"]:not(:disabled)');(se=((G=R.current)==null?void 0:G.querySelector('[aria-selected="true"]:not(:disabled)'))??(K==null?void 0:K[0]))==null||se.focus()};j.useLayoutEffect(()=>{u!==void 0&&(u?T():$())},[u]),j.useEffect(()=>{if(A){if(n){$();return}return N(),window.addEventListener("resize",N),window.addEventListener("scroll",N,!0),()=>{window.removeEventListener("resize",N),window.removeEventListener("scroll",N,!0)}}},[A,n,l]);const Q=`var(--chakra-colors-${b.replace(".","-")})`;return f.jsxs(f.Fragment,{children:[f.jsx(He,{label:i??m,children:f.jsx(D.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":A,"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(),A?$():T()},onKeyDown:K=>{["ArrowDown","ArrowUp"].includes(K.key)&&(K.preventDefault(),T())},children:s??f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((ue=k.find(K=>K.value===r))==null?void 0:ue.label)??r}),f.jsx(X.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),f.jsxs(D.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"},...mr(Q,`var(--chakra-colors-${(C?x:"gray.300").replace(".","-")})`)},onKeyDown:K=>{var re,q,F;if(a&&!["Escape","Tab"].includes(K.key))return;const ce=[...K.currentTarget.querySelectorAll('[role="option"]:not(:disabled), [data-flow-menu-action]:not(:disabled)')],V=ce.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(K.key)){K.preventDefault();const G=K.key==="Home"?0:K.key==="End"?ce.length-1:(V+(K.key==="ArrowDown"?1:-1)+ce.length)%ce.length;(re=ce[G])==null||re.focus()}else if(K.key==="Escape"||K.key==="Tab"){if(K.key==="Tab"&&l)return;K.key==="Escape"&&(K.preventDefault(),K.stopPropagation()),$(),(q=E.current)==null||q.focus()}else K.key.length===1&&K.key!==" "&&((F=ce.find((G,se)=>{var U;return se>V&&((U=G.textContent)==null?void 0:U.toLowerCase().startsWith(K.key.toLowerCase()))}))==null||F.focus())},children:[d&&l&&f.jsx(wb,{label:m}),a??k.map(K=>f.jsxs(D.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"},..._&&{_notLast:{borderBottom:"1px solid",borderColor:C?"whiteAlpha.100":"blackAlpha.100"}},onClick:()=>{var ce;l||($(),(ce=E.current)==null||ce.focus()),t(K.value)},children:[f.jsxs("span",{style:{flex:1,display:"flex",flexDirection:"column",gap:1,minWidth:0},children:[f.jsx("span",{style:{flexShrink:0},children:K.label}),K.description&&f.jsx("span",{style:{opacity:.55,fontFamily:"monospace",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:K.description})]}),f.jsx(X.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"}},Oe=j.forwardRef(function({icon:r,rememberAction:t=!0,...n},o){const{colorMode:i}=Ge(),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(He,{label:n.title??n["aria-label"]??"Last used action",children:f.jsx(Oe,{...s,icon:r})}),t&&!!n.onClick);return f.jsx(D.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}=Ge();return f.jsx(He,{label:"Close",children:f.jsx(Oe,{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(X.PiXLight,{size:20,"aria-hidden":"true"})})})});function Cb({onBeforeExpand:e}={}){const{allNodesIconLabel:r,setAllNodesIconLabel:t}=Ge();return f.jsx(on,{label:"Collapse all",hideLabel:!0,checked:r,icon:f.jsx(X.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}=Ge(),{colorInactive:l}=lt();return f.jsx(He,{label:s,children:f.jsx(Oe,{"aria-label":e,"aria-pressed":t,icon:f.jsxs(f.Fragment,{children:[r,!i&&f.jsx(D.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 Sb({label:e="Compact layout"}={}){const{compactPropertyLayout:r,setCompactPropertyLayout:t,callbacks:n}=Ge();return f.jsx(on,{hideLabel:!0,label:e,checked:r,icon:f.jsx(D.Icon,{as:X.PiArrowsIn,boxSize:5}),onChange:o=>{var i;t(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const qw=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
|
-
`,Bd=j.forwardRef(function({style:r,...t},n){return f.jsx($w,{...t,ref:n,style:{...r,backgroundImage:"none","--flow-range-track":(r==null?void 0:r.backgroundImage)??"none"}})});function Wu({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}=Ve(),{colorInactive:h}=st(),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(Bd,{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 Vu={dot:{label:"Dots",icon:Z.PiDotsNine},grid:{label:"Grid",icon:Z.PiGridFour},steel:{label:"Steel",icon:Z.PiLineSegments},none:{label:"Solid",icon:Z.PiSquareFill},transparent:{label:"Transparent",icon:Z.PiSelection}};function Sb(){const{spacing:e,setSpacing:r,edgeRadius:t,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:s,readOnly:a,config:c}=Ve(),l=Vu[o].icon;return f.jsxs(f.Fragment,{children:[f.jsx(Nn,{}),f.jsx(Nt,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:f.jsx(Z.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:a,onValueChange:()=>{},popupContent:f.jsx(Wu,{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(Nt,{"aria-label":"Edge radius",title:`Edge radius: ${t??"Default"}`,icon:f.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:a,onValueChange:()=>{},popupContent:f.jsx(Wu,{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(Nt,{"aria-label":"Background variant",title:`Background: ${Vu[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 jb(){var o;const{engineRef:e,nodeGridOptions:r,readOnly:t}=Ve(),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(Z.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}=Ve(),{colorText:c,colorInactive:l}=st(),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(Z.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(D.HStack,{role:"group","aria-label":"Collision settings",gap:2,flexShrink:0,children:[!e&&t&&a.nodeGridSpacing!=="layout"&&f.jsxs(f.Fragment,{children:[f.jsx(D.Box,{width:"96px",flexShrink:0,display:"flex",alignItems:"center",children:f.jsx(Bd,{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(D.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(Z.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(jb,{})]})]})}function Dd(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 Wd(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(A=>A.tagName.text==="port"):[];if(R.length>1)throw new Error(`Duplicate port declaration: ${S.name.text}`);if(R.length){const[A,I,M]=String(R[0].comment??"").trim().split(/\s+/);if(A!=="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,...A]=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=A.length?JSON.parse(A.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 Eb(e,r){const t=await Wd(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 Vd(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 _b(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 Dd(r,e.name);if(/\.ts$/i.test(e.name))return Eb(r,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Gu=new WeakMap;function an(e){if(!e||typeof e!="object")return e;const r=Gu.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 Gu.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=$e(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 Gd(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 Wd(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=Dd(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($e(r,e.$address)):$e(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 Xt(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=>!Xt(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=>!Xt(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)&&Xt(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>Xt(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 Hu(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=$e(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 Et(e,i,n,r.op==="remove"?void 0:r.value)}return Rt(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=Hu(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($e(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=Hu(n,i)}return n}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 kb(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=$e(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=xo.default.dialog`
|
|
58
|
+
`,Bd=j.forwardRef(function({style:r,...t},n){return f.jsx(qw,{...t,ref:n,style:{...r,backgroundImage:"none","--flow-range-track":(r==null?void 0:r.backgroundImage)??"none"}})});function Wu({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}=Ge(),{colorInactive:h}=lt(),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(Bd,{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 Vu={dot:{label:"Dots",icon:X.PiDotsNine},grid:{label:"Grid",icon:X.PiGridFour},steel:{label:"Steel",icon:X.PiLineSegments},none:{label:"Solid",icon:X.PiSquareFill},transparent:{label:"Transparent",icon:X.PiSelection}};function jb(){const{spacing:e,setSpacing:r,edgeRadius:t,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:s,readOnly:a,config:c}=Ge(),l=Vu[o].icon;return f.jsxs(f.Fragment,{children:[f.jsx(Nn,{}),f.jsx(Ot,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:f.jsx(X.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:a,onValueChange:()=>{},popupContent:f.jsx(Wu,{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(Ot,{"aria-label":"Edge radius",title:`Edge radius: ${t??"Default"}`,icon:f.jsx(X.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:a,onValueChange:()=>{},popupContent:f.jsx(Wu,{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(Ot,{"aria-label":"Background variant",title:`Background: ${Vu[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 Eb(){var o;const{engineRef:e,nodeGridOptions:r,readOnly:t}=Ge(),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(X.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}=Ge(),{colorText:c,colorInactive:l}=lt(),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(X.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(D.HStack,{role:"group","aria-label":"Collision settings",gap:2,flexShrink:0,children:[!e&&t&&a.nodeGridSpacing!=="layout"&&f.jsxs(f.Fragment,{children:[f.jsx(D.Box,{width:"96px",flexShrink:0,display:"flex",alignItems:"center",children:f.jsx(Bd,{type:"range","aria-label":"Collision gap",title:`Gap: ${u}`,min:0,max:h,step:5,value:u,disabled:o,style:{color:Ie(i),backgroundImage:`linear-gradient(to right, currentColor ${u/h*100}%, ${Ie(l)} ${u/h*100}%)`},onChange:m=>p({gaps:Number(m.target.value)})})}),f.jsx(D.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(X.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(Eb,{})]})]})}function Dd(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 Wd(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(A=>A.tagName.text==="port"):[];if(R.length>1)throw new Error(`Duplicate port declaration: ${S.name.text}`);if(R.length){const[A,I,M]=String(R[0].comment??"").trim().split(/\s+/);if(A!=="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,...A]=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=A.length?JSON.parse(A.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 _b(e,r){const t=await Wd(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 Vd(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 kb(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 Dd(r,e.name);if(/\.ts$/i.test(e.name))return _b(r,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Gu=new WeakMap;function an(e){if(!e||typeof e!="object")return e;const r=Gu.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 Gu.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=$e(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 Gd(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 Wd(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=Dd(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($e(r,e.$address)):$e(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 Qt(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=>!Qt(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=>!Qt(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)&&Qt(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>Qt(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 Hu(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=$e(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 Et(e,i,n,r.op==="remove"?void 0:r.value)}return Rt(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=Hu(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($e(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=Hu(n,i)}return n}function Lw(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 Fw(e,r,t){zn(r.value);const n=_o(e,r,t);return zn(n),n}function Pb(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=$e(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 zw=xo.default.dialog`
|
|
59
59
|
${e=>mr(e.$surface,e.$border)}
|
|
60
60
|
&,
|
|
61
61
|
&:hover {
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
& *::-webkit-scrollbar {
|
|
81
81
|
display: none;
|
|
82
82
|
}
|
|
83
|
-
`,
|
|
83
|
+
`,Bw=xo.default.div`
|
|
84
84
|
min-height: 0;
|
|
85
85
|
container-type: inline-size;
|
|
86
86
|
@container (min-width: 520px) {
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
black calc(100% - 32px),
|
|
126
126
|
transparent
|
|
127
127
|
);
|
|
128
|
-
`;function ko({nodeAddress:e,active:r,label:t,open:n=!1,onClose:o,onBack:i,children:s,filter:a,height:c,width:l}){const{background:d,border:u,colorText:h}=st(),{colorMode:p}=Ve(),m=j.useRef(null),g=j.useId(),{data:y,schema:b,bindings:x}=j.useContext(qt),w=s!==void 0||!!(y&&b&&(x?Hn(x,e,b):un(y,e,b)));j.useEffect(()=>{var C,S,E,R,A;!r||!w||!n?(C=m.current)==null||C.close():(S=m.current)!=null&&S.open||((E=m.current)==null||E.showModal(),(A=(R=m.current)==null?void 0:R.querySelector("[data-form-filter] input"))==null||A.focus())},[r,w,n]);const v=Me(d);return w?f.jsx(f.Fragment,{children:typeof document<"u"&&Vr.createPortal(f.jsx(Fw,{ref:m,id:g,$surface:v,$border:Me(u),"aria-label":`Configure ${t}`,onClose:C=>{C.stopPropagation(),o==null||o()},onPointerDown:C=>C.stopPropagation(),onWheel:C=>C.stopPropagation(),onKeyDown:C=>C.stopPropagation(),onClick:C=>{var S;C.stopPropagation(),C.target===C.currentTarget&&((S=m.current)==null||S.close())},style:{position:"fixed",inset:"94px 20px auto auto",margin:0,padding:20,width:l??"var(--top-toolbar-width, 360px)",boxSizing:"border-box",maxWidth:"calc(100vw - 40px)",maxHeight:"calc(100dvh - 114px)",height:c,overflow:"hidden",borderRadius:30,background:v,color:Me(h),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.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[i&&f.jsx(Oe,{"aria-label":"Back",title:"Back",icon:f.jsx(Z.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:i}),f.jsx("strong",{style:{overflowWrap:"anywhere",minWidth:0},children:t})]}),f.jsx(dn,{"aria-label":"Close node configuration",onClick:()=>{var C;return(C=m.current)==null?void 0:C.close()}})]}),a&&f.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:a}),f.jsx(zw,{$divider:`var(--chakra-colors-gray-${p==="dark"?"700":"200"})`,"data-form-scroll":"",style:c?{flex:1}:void 0,children:s??f.jsx(Hd,{nodeAddress:e})})]})}),document.body)}):null}const $n="data:image/svg+xml;base64,";function Sr(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 Bw(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 dr=({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"&&Sr(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})},Dw=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),Ww=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 Uu(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 Vw(e,r,t){if(r.address===t.address)return;const n=$e(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==="":!Xt(i,s,!0);if(o(t.type,n))return structuredClone(n)}function Pb(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,A,I,M;if(m>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const y=$e(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(!Dw(k))throw new Error(`Unsupported structured property key: ${k}`);const N=x?u:`${u}.${k}`,O=$e(e,N),W=Bn(_.type,O),T=W.kind==="object"||W.kind==="array",Y=(A=C.ports)==null?void 0:A[k],he=(Y==null?void 0:Y.kind)==="config"&&(((I=v[k])==null?void 0:I.$options)||On(_.type)),K=_.type.kind==="json"||_.type.kind==="union"&&!On(_.type);if(((M=v[k])==null?void 0:M.$control)==="upload"||!T&&b.kind!=="array"&&(!K||x)||he){C.properties[k]={..._,type:_.type.kind==="json"?W:_.type};continue}const re=s.get(N)??Ww(N),G=b.kind==="array"?`Item ${Number(k)+1}`:k,ne={address:N,owner:d,field:k,type:_.type,label:G,nodeId:re,present:O!==void 0};if(o.slots.set(En(d,k),ne),C.ports[k]={kind:"config",resourceType:`__form:${re}`},O===void 0||(o.edges.push({data:{id:`__form-edge:${d}:${k}`,source:re,target:d,sourceProperty:"output:resource",targetProperty:`config:${k}`,isEdgeDashed:!0}}),o.containers.has(re)||s.has(N)))continue;if(i.has(re))throw new Error(`Structured node identity conflict: ${re}`);i.add(re);const q={data:{id:re,type:"objectView",label:G,headerTitle:G,description:{},config:{form:!0,icon:W.kind==="array"?"PiListNumbers":T?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push(q),a(re,N,_.type,p,m+1,!0);const z=o.schema[`__form:${re}`];q.data.description=Object.fromEntries(Object.keys(z.properties).map(H=>[H,$e(e,W.kind==="array"||W.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||$e(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 Dr=(e="reference")=>({kind:e,text:"",paths:[""]}),Ab=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(r=>["__proto__","constructor","prototype"].includes(r));function Gw(e,r){const t=new Set(r.map(s=>s.path)),n=s=>{if(!s.paths.length||s.paths.some(a=>!Ab(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 Hw(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=Dr();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(!Ab(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({...Dr("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({...Dr("text"),text:s.slice(c)}),a},o={mode:"reference",parts:[Dr()],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 Ku({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(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),f.jsx(Oe,{"aria-label":`Remove part ${s+1}`,title:"Remove part",icon:f.jsx(Z.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(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},c)),i.kind==="reference"&&f.jsxs(f.Fragment,{children:[f.jsx(Oe,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:f.jsx(Z.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(Oe,{"aria-label":"Add part",title:"Add part",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t([...e,Dr()])})]})}function Uw({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 Hw(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(Oe,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:f.jsx(Z.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:[Dr()]}),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(Z.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(Ku,{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(Oe,{"aria-label":"Remove output field",title:"Remove output field",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:i.fields.filter((m,g)=>g!==p)})})]},p)),f.jsx(Oe,{"aria-label":"Add output field",title:"Add output field",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:[...i.fields,{key:"",parts:[Dr()]}]})})]}):f.jsx(Ku,{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(Oe,{"aria-label":"Apply binding",title:"Apply binding",icon:f.jsx(Z.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(Gw(i,t)),s(void 0),c("")}catch(h){c(h instanceof Error?h.message:"Unable to apply binding.")}}}),f.jsx(Oe,{"aria-label":"Cancel binding",title:"Cancel binding",icon:f.jsx(Z.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{s(void 0),c("")}})]})]}),a&&f.jsx("p",{role:"alert",children:a})]})}function Kw({nodeAddress:e,onOpen:r}){const{structured:t,data:n,callbacks:o,editable:i,onFieldCreate:s}=j.useContext(qt),a=Ve(),[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=$e(n,m.address),b=Uu(m.declared),x=m.type.kind==="array"?m.type.items:m.type.kind==="object"?m.type.additionalProperties:void 0,w=x?Uu(x):[],v=!!s&&m.type.kind==="object"&&(x==null?void 0:x.kind)==="json",C=_=>_.kind==="literal"?String(_.value):_.kind==="string"?"Text":Vt(_.kind),S=[...t.slots.values()].filter(_=>_.owner===e),E=(_,N)=>{var O;return(O=o.onFormChange)==null?void 0:O.call(o,{data:n,nodeAddress:m.address,address:_,previousValue:$e(n,_),value:N})},R=_=>{var N;a.setSelectedNodeIds([_]),(N=a.engineRef.current)==null||N.focusNode(_,90,!1)},A=(_,N)=>{if(!Array.isArray(y))return;const O=[...y];[O[_],O[_+N]]=[O[_+N],O[_]],E(m.address,O)},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(Nt,{"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(Z.PiListNumbers,{size:20}):f.jsx(Z.PiBracketsCurly,{size:20}),f.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:Vt(_.label)}),f.jsx(Oe,{"aria-label":`${_.present?r?"Edit":"Focus":"Create"} ${Vt(_.label)}`,title:`${_.present?r?"Edit":"Focus":"Create"} ${Vt(_.label)}`,icon:_.present?f.jsx(Z.PiMagnifyingGlass,{size:18}):f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:g&&!_.present,onClick:O=>{var W;_.present?r?r(_.nodeId):((W=O.currentTarget.closest("dialog"))==null||W.close(),R(_.nodeId)):E(_.address,_n(_.type))}}),k&&f.jsxs(f.Fragment,{children:[f.jsx(Oe,{"aria-label":`Move item ${N+1} up`,icon:f.jsx(Z.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:g||N===0,onClick:()=>A(N,-1)}),f.jsx(Oe,{"aria-label":`Move item ${N+1} down`,icon:f.jsx(Z.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:g||N===S.length-1,onClick:()=>A(N,1)})]}),_.present&&f.jsx(Oe,{"aria-label":`Remove ${Vt(_.label)}`,icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:g,onClick:()=>k?E(m.address,y.filter((O,W)=>W!==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(Nt,{"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(Oe,{"aria-label":k?"Add item":"Add property",icon:f.jsx(Z.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:g,onClick:I})})]}),h&&f.jsx("p",{role:"alert",children:h})]})}const qt=j.createContext({callbacks:{}}),no=xo.default.div`
|
|
128
|
+
`;function ko({nodeAddress:e,active:r,label:t,open:n=!1,onClose:o,onBack:i,children:s,filter:a,height:c,width:l}){const{background:d,border:u,colorText:h}=lt(),{colorMode:p}=Ge(),m=j.useRef(null),g=j.useId(),{data:y,schema:b,bindings:x}=j.useContext(Ft),w=s!==void 0||!!(y&&b&&(x?Hn(x,e,b):un(y,e,b)));j.useEffect(()=>{var C,S,E,R,A;!r||!w||!n?(C=m.current)==null||C.close():(S=m.current)!=null&&S.open||((E=m.current)==null||E.showModal(),(A=(R=m.current)==null?void 0:R.querySelector("[data-form-filter] input"))==null||A.focus())},[r,w,n]);const v=Ie(d);return w?f.jsx(f.Fragment,{children:typeof document<"u"&&Vr.createPortal(f.jsx(zw,{ref:m,id:g,$surface:v,$border:Ie(u),"aria-label":`Configure ${t}`,onClose:C=>{C.stopPropagation(),o==null||o()},onPointerDown:C=>C.stopPropagation(),onWheel:C=>C.stopPropagation(),onKeyDown:C=>C.stopPropagation(),onClick:C=>{var S;C.stopPropagation(),C.target===C.currentTarget&&((S=m.current)==null||S.close())},style:{position:"fixed",inset:"94px 20px auto auto",margin:0,padding:20,width:l??"var(--top-toolbar-width, 360px)",boxSizing:"border-box",maxWidth:"calc(100vw - 40px)",maxHeight:"calc(100dvh - 114px)",height:c,overflow:"hidden",borderRadius:30,background:v,color:Ie(h),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.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[i&&f.jsx(Oe,{"aria-label":"Back",title:"Back",icon:f.jsx(X.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:i}),f.jsx("strong",{style:{overflowWrap:"anywhere",minWidth:0},children:t})]}),f.jsx(dn,{"aria-label":"Close node configuration",onClick:()=>{var C;return(C=m.current)==null?void 0:C.close()}})]}),a&&f.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:a}),f.jsx(Bw,{$divider:`var(--chakra-colors-gray-${p==="dark"?"700":"200"})`,"data-form-scroll":"",style:c?{flex:1}:void 0,children:s??f.jsx(Hd,{nodeAddress:e})})]})}),document.body)}):null}const $n="data:image/svg+xml;base64,";function Sr(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 Dw(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 dr=({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"&&Sr(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})},Ww=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),Vw=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 Uu(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 Gw(e,r,t){if(r.address===t.address)return;const n=$e(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==="":!Qt(i,s,!0);if(o(t.type,n))return structuredClone(n)}function Ab(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,A,I,M;if(m>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const y=$e(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(!Ww(k))throw new Error(`Unsupported structured property key: ${k}`);const $=x?u:`${u}.${k}`,N=$e(e,$),W=Bn(_.type,N),T=W.kind==="object"||W.kind==="array",Q=(A=C.ports)==null?void 0:A[k],ue=(Q==null?void 0:Q.kind)==="config"&&(((I=v[k])==null?void 0:I.$options)||On(_.type)),K=_.type.kind==="json"||_.type.kind==="union"&&!On(_.type);if(((M=v[k])==null?void 0:M.$control)==="upload"||!T&&b.kind!=="array"&&(!K||x)||ue){C.properties[k]={..._,type:_.type.kind==="json"?W:_.type};continue}const ce=s.get($)??Vw($),V=b.kind==="array"?`Item ${Number(k)+1}`:k,re={address:$,owner:d,field:k,type:_.type,label:V,nodeId:ce,present:N!==void 0};if(o.slots.set(En(d,k),re),C.ports[k]={kind:"config",resourceType:`__form:${ce}`},N===void 0||(o.edges.push({data:{id:`__form-edge:${d}:${k}`,source:ce,target:d,sourceProperty:"output:resource",targetProperty:`config:${k}`,isEdgeDashed:!0}}),o.containers.has(ce)||s.has($)))continue;if(i.has(ce))throw new Error(`Structured node identity conflict: ${ce}`);i.add(ce);const q={data:{id:ce,type:"objectView",label:V,headerTitle:V,description:{},config:{form:!0,icon:W.kind==="array"?"PiListNumbers":T?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push(q),a(ce,$,_.type,p,m+1,!0);const F=o.schema[`__form:${ce}`];q.data.description=Object.fromEntries(Object.keys(F.properties).map(G=>[G,$e(e,W.kind==="array"||W.kind==="object"?`${$}.${G}`:$)]).filter(([,G])=>G!==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||$e(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 Dr=(e="reference")=>({kind:e,text:"",paths:[""]}),Rb=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(r=>["__proto__","constructor","prototype"].includes(r));function Hw(e,r){const t=new Set(r.map(s=>s.path)),n=s=>{if(!s.paths.length||s.paths.some(a=>!Rb(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 Uw(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=Dr();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(!Rb(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({...Dr("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({...Dr("text"),text:s.slice(c)}),a},o={mode:"reference",parts:[Dr()],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 Ku({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(X.PiCaretDown,{size:16,"aria-hidden":"true"})]}),f.jsx(Oe,{"aria-label":`Remove part ${s+1}`,title:"Remove part",icon:f.jsx(X.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(X.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},c)),i.kind==="reference"&&f.jsxs(f.Fragment,{children:[f.jsx(Oe,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:f.jsx(X.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(Oe,{"aria-label":"Add part",title:"Add part",icon:f.jsx(X.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t([...e,Dr()])})]})}function Kw({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 Uw(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(Oe,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:f.jsx(X.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:[Dr()]}),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(X.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(Ku,{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(Oe,{"aria-label":"Remove output field",title:"Remove output field",icon:f.jsx(X.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:i.fields.filter((m,g)=>g!==p)})})]},p)),f.jsx(Oe,{"aria-label":"Add output field",title:"Add output field",icon:f.jsx(X.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:[...i.fields,{key:"",parts:[Dr()]}]})})]}):f.jsx(Ku,{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(Oe,{"aria-label":"Apply binding",title:"Apply binding",icon:f.jsx(X.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(Hw(i,t)),s(void 0),c("")}catch(h){c(h instanceof Error?h.message:"Unable to apply binding.")}}}),f.jsx(Oe,{"aria-label":"Cancel binding",title:"Cancel binding",icon:f.jsx(X.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{s(void 0),c("")}})]})]}),a&&f.jsx("p",{role:"alert",children:a})]})}function Jw({nodeAddress:e,onOpen:r}){const{structured:t,data:n,callbacks:o,editable:i,onFieldCreate:s}=j.useContext(Ft),a=Ge(),[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=$e(n,m.address),b=Uu(m.declared),x=m.type.kind==="array"?m.type.items:m.type.kind==="object"?m.type.additionalProperties:void 0,w=x?Uu(x):[],v=!!s&&m.type.kind==="object"&&(x==null?void 0:x.kind)==="json",C=_=>_.kind==="literal"?String(_.value):_.kind==="string"?"Text":Ht(_.kind),S=[...t.slots.values()].filter(_=>_.owner===e),E=(_,$)=>{var N;return(N=o.onFormChange)==null?void 0:N.call(o,{data:n,nodeAddress:m.address,address:_,previousValue:$e(n,_),value:$})},R=_=>{var $;a.setSelectedNodeIds([_]),($=a.engineRef.current)==null||$.focusNode(_,90,!1)},A=(_,$)=>{if(!Array.isArray(y))return;const N=[...y];[N[_],N[_+$]]=[N[_+$],N[_]],E(m.address,N)},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(Ot,{"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((_,$)=>f.jsx("option",{value:$,children:C(_)},$))})})]}),S.map((_,$)=>f.jsxs("div",{"data-structured-slot":_.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[_.type.kind==="array"?f.jsx(X.PiListNumbers,{size:20}):f.jsx(X.PiBracketsCurly,{size:20}),f.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:Ht(_.label)}),f.jsx(Oe,{"aria-label":`${_.present?r?"Edit":"Focus":"Create"} ${Ht(_.label)}`,title:`${_.present?r?"Edit":"Focus":"Create"} ${Ht(_.label)}`,icon:_.present?f.jsx(X.PiMagnifyingGlass,{size:18}):f.jsx(X.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:g&&!_.present,onClick:N=>{var W;_.present?r?r(_.nodeId):((W=N.currentTarget.closest("dialog"))==null||W.close(),R(_.nodeId)):E(_.address,_n(_.type))}}),k&&f.jsxs(f.Fragment,{children:[f.jsx(Oe,{"aria-label":`Move item ${$+1} up`,icon:f.jsx(X.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:g||$===0,onClick:()=>A($,-1)}),f.jsx(Oe,{"aria-label":`Move item ${$+1} down`,icon:f.jsx(X.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:g||$===S.length-1,onClick:()=>A($,1)})]}),_.present&&f.jsx(Oe,{"aria-label":`Remove ${Ht(_.label)}`,icon:f.jsx(X.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:g,onClick:()=>k?E(m.address,y.filter((N,W)=>W!==$)):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(Ot,{"aria-label":"New value type",value:d,disabled:g,onValueChange:u,children:[w.map((_,$)=>f.jsx("option",{value:$,children:C(_)},$)),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(Oe,{"aria-label":k?"Add item":"Add property",icon:f.jsx(X.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:g,onClick:I})})]}),h&&f.jsx("p",{role:"alert",children:h})]})}const Ft=j.createContext({callbacks:{}}),no=xo.default.div`
|
|
129
129
|
--flow-form-input-radius: 16px;
|
|
130
130
|
--flow-form-input-background: color-mix(
|
|
131
131
|
in srgb,
|
|
@@ -276,10 +276,10 @@
|
|
|
276
276
|
font-size: 14px;
|
|
277
277
|
margin-top: 8px;
|
|
278
278
|
}
|
|
279
|
-
`;function Jw({options:e,onPick:r,disabled:t,label:n,selected:o}){const{colorMode:i}=Ve(),s=i==="dark",[a,c]=j.useState(!1),[l,d]=j.useState(""),h=(e??[]).map(m=>String(m.value)).filter(m=>m.toLowerCase().includes(l.trim().toLowerCase())),p=()=>{c(!1),d("")};return f.jsxs(f.Fragment,{children:[f.jsx("button",{type:"button",disabled:t,"aria-label":`Add ${n}`,"aria-haspopup":"dialog",onClick:()=>c(!0),style:{width:"100%",padding:"8px 12px",borderRadius:20,border:"1px dashed",borderColor:s?"var(--chakra-colors-gray-600)":"var(--chakra-colors-gray-300)",background:"transparent",color:"inherit",textAlign:"center",cursor:t?"default":"pointer",fontSize:14,opacity:t?.6:1},children:"+ Add tool"}),f.jsx(ko,{active:!0,nodeAddress:"",label:`Add ${n}`,open:a,onClose:p,onBack:p,height:440,filter:f.jsx("input",{"aria-label":`Search ${n}`,placeholder:"Search tools...",value:l,onChange:m=>d(m.target.value),style:{width:"100%",marginTop:14,padding:"10px 14px",borderRadius:20,border:"1px solid",borderColor:s?"var(--chakra-colors-gray-600)":"var(--chakra-colors-gray-200)",background:s?"var(--chakra-colors-gray-700)":"var(--chakra-colors-gray-100)",color:"inherit",fontSize:15,boxSizing:"border-box"}}),children:f.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,width:"100%"},children:[h.map(m=>{const g=(o??[]).includes(m),y="color-mix(in srgb, currentColor 10%, transparent)";return f.jsxs("button",{type:"button","aria-selected":g,onClick:()=>{r(m)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,textAlign:"left",padding:"10px 14px",borderRadius:12,border:0,background:g?y:"transparent",color:"inherit",cursor:"pointer",fontSize:15,fontWeight:g?700:400},onMouseEnter:b=>{g||(b.currentTarget.style.background=s?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.05)")},onMouseLeave:b=>{b.currentTarget.style.background=g?y:"transparent"},children:[f.jsx("span",{style:{flex:1,minWidth:0},children:m}),f.jsx(Z.PiCheck,{size:16,"aria-hidden":"true",style:{flexShrink:0,visibility:g?"visible":"hidden"}})]},m)}),h.length===0&&f.jsxs("span",{style:{opacity:.55,fontSize:13,padding:"8px 14px"},children:["No tools match “",l,"”"]})]})})]})}function ti({value:e,kind:r,itemKind:t,nameOnly:n,options:o,accent:i="currentColor",disabled:s,label:a,onChange:c}){const l={display:"flex",gap:6,width:"100%",alignItems:"center"},d={display:"inline-flex",alignItems:"center",background:"transparent",border:0,color:"inherit",cursor:s?"default":"pointer",padding:2,flexShrink:0},u=p=>{try{return JSON.parse(p)}catch{return p}};if(r==="object"){const p=e&&typeof e=="object"&&!Array.isArray(e)?e:{},m=()=>{let g=Object.keys(p).length+1,y=`entry${g}`;for(;Object.prototype.hasOwnProperty.call(p,y);)y=`entry${++g}`;return y};if(n){const g=Object.keys(p),y=b=>{if(b)if(Object.prototype.hasOwnProperty.call(p,b)){const x={...p};delete x[b],c(x)}else c({...p,[b]:{name:b}})};return f.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,width:"100%"},children:[g.length>0&&f.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:g.map((b,x)=>f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 6px 6px 14px",borderRadius:24,color:i,background:"color-mix(in srgb, currentColor 12%, transparent)"},children:[b,f.jsx("button",{type:"button","aria-label":`Remove ${a} ${x+1}`,disabled:s,style:d,onClick:()=>{const w={...p};delete w[b],c(w)},children:f.jsx(Z.PiTrash,{size:12,"aria-hidden":"true"})})]},`${x}:${b}`))}),f.jsx(Jw,{options:o,onPick:y,disabled:s,label:a,selected:g})]})}return f.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,width:"100%"},children:[Object.entries(p).map(([g,y],b)=>f.jsxs("div",{style:l,children:[f.jsx("input",{style:{flex:1,minWidth:0},"aria-label":`${a} key ${b+1}`,placeholder:"key",value:g,disabled:s,onChange:x=>{const w={};for(const[v,C]of Object.entries(p))w[v===g?x.target.value:v]=C;c(w)}}),f.jsx("input",{style:{flex:1,minWidth:0},"aria-label":`${a} value ${b+1}`,placeholder:"value",value:typeof y=="string"?y:JSON.stringify(y),disabled:s,onChange:x=>c({...p,[g]:u(x.target.value)})}),f.jsx("button",{type:"button","aria-label":`Remove ${a} ${b+1}`,disabled:s,style:d,onClick:()=>{const x={...p};delete x[g],c(x)},children:f.jsx(Z.PiTrash,{size:12,"aria-hidden":"true"})})]},`${b}:${g}`)),f.jsx("button",{type:"button",disabled:s,onClick:()=>c({...p,[m()]:""}),children:"Add entry"})]})}const h=Array.isArray(e)?e:[];return f.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,width:"100%"},children:[h.map((p,m)=>f.jsxs("div",{style:{...l,alignItems:"flex-start"},children:[f.jsx("textarea",{style:{flex:1,minWidth:0},"aria-label":`${a} item ${m+1}`,rows:2,value:typeof p=="string"?p:JSON.stringify(p,null,2),disabled:s,onChange:g=>{const y=[...h];y[m]=u(g.target.value),c(y)}}),f.jsx("button",{type:"button","aria-label":`Remove ${a} ${m+1}`,disabled:s,style:d,onClick:()=>c(h.filter((g,y)=>y!==m)),children:f.jsx(Z.PiTrash,{size:12,"aria-hidden":"true"})})]},m)),f.jsx("button",{type:"button",disabled:s,onClick:()=>c([...h,t==="string"?"":{}]),children:"Add item"})]})}function Ju({request:e,property:r,config:t,value:n,disabled:o}){var Je,tt,Ye,Ue,lt,be,Ae;const{callbacks:i,structured:s,references:a}=j.useContext(qt),{themeColor:c}=Ve(),{background:l}=st(),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),[A,I]=j.useState(""),[M,k]=j.useState(),_=((Je=t.$options)==null?void 0:Je.$source)==="callback",N=i.resolveFormOptions,{data:O,address:W,nodeAddress:T,nodeId:Y}=e;j.useEffect(()=>(S(!1),R(!1),()=>{var ie;(ie=v.current)==null||ie.abort(),v.current=void 0}),[W,T,Y,o,h,t.$control,(tt=t.$upload)==null?void 0:tt.accept,(Ye=t.$upload)==null?void 0:Ye.maxSizeBytes]);const he=j.useRef(O);he.current=O;const K=JSON.stringify([W,Y,(Ue=t.$options)!=null&&Ue.$dependsOn?t.$options.$dependsOn.map(ie=>$e(O,ie)):$e(O,T)]);j.useEffect(()=>{m(h),y("")},[h,W,Y]),j.useEffect(()=>{if(!_)return;const ie=new AbortController;return Promise.resolve().then(()=>{if(!N)throw new Error("No options resolver configured");return N({address:W,nodeAddress:T,nodeId:Y,data:an(he.current),signal:ie.signal})}).then(ae=>{if(!Array.isArray(ae)||ae.some(Ie=>!Ie||typeof Ie.label!="string"||!["string","number","boolean"].includes(typeof Ie.value)&&Ie.value!==null))throw new Error("Invalid options response");ie.signal.aborted||k({key:K,options:ae})}).catch(ae=>{ie.signal.aborted||k({key:K,options:[],error:ae instanceof Error?ae.message:"Options unavailable"})}),()=>ie.abort()},[_,N,K,W,T,Y,b]);const re=_&&(M==null?void 0:M.key)!==K,G=_?(M==null?void 0:M.key)===K?M.options:[]:r.type.kind==="null"?[{label:"Null",value:null}]:r.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:On(r.type),ne=r.type.kind==="array",q=r.type.kind==="array"?(lt=r.type.items)==null?void 0:lt.kind:void 0,z=r.type.kind==="object"?r.type.additionalProperties:void 0,H=!!z&&z.kind==="object"&&!!z.properties&&Object.keys(z.properties).length===1&&((be=z.properties.name)==null?void 0:be.kind)==="string"||!!n&&typeof n=="object"&&!Array.isArray(n)&&Object.keys(n).length>0&&Object.entries(n).every(([ie,ae])=>!!ae&&typeof ae=="object"&&!Array.isArray(ae)&&ae.name===ie&&Object.keys(ae).length===1),V=((G==null?void 0:G.length)??0)===0&&!re,le=(t.$control==="upload"?"upload":s&&u||t.$control==="checkbox"?"pills":t.$control)??(G?ne||r.type.kind==="boolean"?"pills":"select":r.type.kind==="boolean"?"checkbox":u?"textarea":"input"),X=!r.optional||!!t.$requiredWhen&&Eo(t.$requiredWhen,O),ue=X?"Required":"Optional",oe=le!=="upload"&&!!(a!=null&&a.length)&&typeof n=="string"&&n.includes("{{"),de=g||_&&(M==null?void 0:M.key)===K&&M.error||!oe&&Xt(r.type,n,X),ge=Vt(t.$label??W.split(".").pop()),ce=ie=>{var ae;if(!(o||Object.is(ie,n)))try{(ae=i.onFormChange)==null||ae.call(i,{...e,previousValue:n,value:ie}),y("")}catch(Ie){y(Ie instanceof Error?Ie.message:"Unable to update field")}},U=j.useRef(ce);j.useLayoutEffect(()=>{U.current=ce});const te=()=>{if(u){try{const et=p===""&&r.optional?void 0:JSON.parse(p),Ee=Xt(r.type,et,X);if(Ee){y(Ee);return}ce(et)}catch{y("Enter valid JSON")}return}const ie=r.type.kind==="number"||r.type.kind==="integer",ae=p===""&&r.optional?void 0:ie&&p!==""?Number(p):p,Ie=Xt(r.type,ae,X);if(ie&&Ie&&p!==""){y(Ie);return}ce(ae)},pe=async ie=>{var Ie,et,Ee;if(o||v.current||!ie.length)return;const ae=new AbortController;v.current=ae,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(!ne&&ie.length!==1)throw new Error("Choose one file for this field.");if(!i.uploadFormFile)throw new Error("No file upload handler configured.");const Le=(et=(Ie=t.$upload)==null?void 0:Ie.accept)==null?void 0:et.split(",").map(ht=>ht.trim().toLowerCase()).filter(Boolean);for(const ht of ie){if(((Ee=t.$upload)==null?void 0:Ee.maxSizeBytes)!==void 0&&ht.size>t.$upload.maxSizeBytes)throw new Error(`${ht.name} exceeds the file size limit.`);if(Le!=null&&Le.length&&!Le.some(At=>At.startsWith(".")?ht.name.toLowerCase().endsWith(At):At.endsWith("/*")?ht.type.toLowerCase().startsWith(At.slice(0,-1)):ht.type.toLowerCase()===At))throw new Error(`${ht.name} is not an accepted file type.`)}const at=await Promise.all(ie.map(async ht=>{const At=await i.uploadFormFile({...e,data:an(O),file:ht,signal:ae.signal});if(typeof At!="string")throw new Error("Upload handler must return an HTTP or HTTPS URL.");let Lt;try{Lt=new URL(At)}catch{throw new Error("Upload handler must return an HTTP or HTTPS URL.")}if(!["http:","https:"].includes(Lt.protocol)||Lt.username||Lt.password)throw new Error("Upload handler must return an HTTP or HTTPS URL.");return At}));if(ae.signal.aborted||v.current!==ae)return;const He=ne?[...Array.isArray(n)?n:[],...at]:at[0],ft=Xt(r.type,He,X);if(ft)throw new Error(ft);U.current(He)}catch(Le){ae.signal.aborted||y(Le instanceof Error?Le.message:"Unable to upload file."),ae.abort()}finally{v.current===ae&&(v.current=void 0,S(!1))}},ve={id:d,disabled:o,"aria-label":ge,"aria-required":X,"aria-invalid":!!de,"aria-describedby":de?`${d}-error`:void 0},Ne=Me(c);return f.jsxs("div",{"data-form-field":W,"data-flow-property":W.slice(T.length+1),children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[f.jsxs("label",{htmlFor:d,children:[ge,X?" *":""]}),r.optional&&n!==void 0&&f.jsx("button",{type:"button","aria-label":`Reset ${ge}`,title:`Reset ${ge}`,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(Z.PiArrowCounterClockwise,{size:14})})]}),!!(a!=null&&a.length)&&!u&&le!=="upload"&&f.jsx(Uw,{label:ge,value:n,references:a,disabled:o,onChange:ce}),le==="upload"?f.jsxs("div",{"data-form-upload":ne?"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",R(!0))},onDragLeave:ie=>{ie.currentTarget.contains(ie.relatedTarget)||R(!1)},onDrop:ie=>{ie.preventDefault(),ie.stopPropagation(),R(!1),pe(Array.from(ie.dataTransfer.files))},children:[f.jsx("input",{ref:w,type:"file",hidden:!0,"aria-label":`Upload ${ge}`,accept:(Ae=t.$upload)==null?void 0:Ae.accept,multiple:ne,disabled:o||C,onChange:ie=>{const ae=Array.from(ie.target.files??[]);ie.target.value="",pe(ae)}}),f.jsxs("div",{"data-upload-items":"",children:[(ne?Array.isArray(n)?n:[]:n?[n]:[]).map((ie,ae)=>f.jsxs("div",{"data-upload-preview":"",children:[typeof ie=="string"&&Sr(ie)&&f.jsxs("a",{href:ie,target:"_blank",rel:"noopener noreferrer","aria-label":`${ge} file ${ae+1}`,children:[f.jsx(Z.PiFile,{size:32,"aria-hidden":"true"}),f.jsx(dr,{name:ie,size:120,onError:Ie=>{Ie.currentTarget.style.visibility="hidden"}})]}),f.jsxs("div",{"data-upload-actions":"",children:[!ne&&f.jsx(Oe,{"aria-label":`Replace ${ge}`,title:`Replace ${ge}`,icon:f.jsx(Z.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>{var Ie;return(Ie=w.current)==null?void 0:Ie.click()}}),f.jsx(Oe,{"aria-label":`Remove ${ge} file ${ae+1}`,title:"Remove file",icon:f.jsx(Z.PiTrash,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>ce(ne&&Array.isArray(n)?n.filter((Ie,et)=>et!==ae):"")})]})]},`${ae}:${ie}`)),(ne||!n)&&f.jsx("button",{...ve,type:"button","data-upload-drop":"",title:`Upload ${ge}`,disabled:o||C,onClick:()=>{var ie;return(ie=w.current)==null?void 0:ie.click()},children:f.jsx(Z.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&f.jsx("span",{role:"status",children:"Uploading..."})]}):oe?null:le==="select"?f.jsx("div",{"data-form-select":"",children:f.jsxs(Nt,{...ve,disabled:o||re||!!(M!=null&&M.error),labelCase:"preserve",value:String((G==null?void 0:G.findIndex(ie=>Object.is(ie.value,n)))??-1),onValueChange:ie=>{const ae=G==null?void 0:G[Number(ie)];ae&&ce(ae.value)},children:[f.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):ue}),G==null?void 0:G.map((ie,ae)=>f.jsx("option",{value:ae,...ie.description?{description:ie.description}:{},children:Vt(ie.label)||ie.label},ae))]})}):le==="pills"?f.jsx("div",{id:d,role:"group","aria-label":ge,"aria-describedby":ve["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:r.type.kind==="object"&&H?f.jsx(ti,{value:n,kind:"object",nameOnly:!0,options:G,accent:Ne,disabled:o,label:ge,onChange:ce}):V?ne&&q==="string"?f.jsxs(f.Fragment,{children:[(Array.isArray(n)?n:[]).map((ie,ae)=>f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"8px 8px 8px 16px",borderRadius:24,border:0,color:Ne,background:"color-mix(in srgb, currentColor 12%, transparent)"},children:[String(ie),f.jsx("button",{type:"button","aria-label":`Remove ${ge} ${ae+1}`,disabled:o,style:{display:"inline-flex",alignItems:"center",background:"transparent",border:0,color:"inherit",cursor:o?"default":"pointer",padding:2},onClick:()=>ce(n.filter((Ie,et)=>et!==ae)),children:f.jsx(Z.PiTrash,{size:12,"aria-hidden":"true"})})]},ae)),f.jsx("input",{"aria-label":`Add ${ge}`,placeholder:ue,value:A,disabled:o,onChange:ie=>I(ie.target.value),onKeyDown:ie=>{if(ie.key!=="Enter")return;ie.preventDefault();const ae=A.trim();if(!ae)return;const Ie=Array.isArray(n)?n:[];if(Ie.some(et=>String(et)===ae)){I("");return}ce([...Ie,ae]),I("")}}),f.jsx("button",{type:"button",disabled:o||!A.trim(),onClick:()=>{const ie=A.trim();if(!ie)return;const ae=Array.isArray(n)?n:[];ae.some(Ie=>String(Ie)===ie)||ce([...ae,ie]),I("")},children:"Add"})]}):ne?f.jsx(ti,{value:n,kind:"array",itemKind:q,disabled:o,label:ge,onChange:ce}):r.type.kind==="object"?f.jsx(ti,{value:n,kind:"object",nameOnly:H,disabled:o,label:ge,onChange:ce}):f.jsx("textarea",{...ve,placeholder:ue,value:p,onChange:ie=>m(ie.target.value),onBlur:te}):f.jsxs(f.Fragment,{children:[G==null?void 0:G.map((ie,ae)=>{const Ie=ne?Array.isArray(n)&&n.includes(ie.value):Object.is(n,ie.value);return f.jsx("button",{type:"button",disabled:o||re,"aria-pressed":Ie,style:{padding:"8px 16px",borderRadius:24,border:0,color:Ie?Ne:"inherit",background:Ie?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>ce(ne?Ie?n.filter(et=>et!==ie.value):[...Array.isArray(n)?n:[],ie.value]:ie.value),children:Vt(ie.label)||ie.label},ae)}),re&&f.jsx("span",{role:"status",children:"Loading..."})]})}):le==="textarea"?f.jsx("textarea",{...ve,placeholder:ue,value:p,onChange:ie=>m(ie.target.value),onBlur:te}):f.jsx("input",{...ve,placeholder:ue,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:te,onKeyDown:ie=>{ie.key==="Enter"&&te(),ie.key==="Escape"&&m(n===void 0?"":String(n))}}),de&&f.jsx("div",{role:"alert",id:`${d}-error`,children:de}),_&&(M==null?void 0:M.error)&&f.jsx("button",{type:"button",disabled:o,onClick:()=>{k(void 0),x(b+1)},children:"Retry"})]})}function Hd({nodeAddress:e,structured:r=!1}){return r?f.jsx(Zw,{nodeAddress:e},e):f.jsx(kd,{nodeAddress:e})}function Zw({nodeAddress:e}){var u,h,p;const r=j.useContext(qt),[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 Pb(r.data,i,o,[{data:{id:e,type:"objectView"}}])},[r.data,i,o,e]);if(!s)return f.jsx(kd,{nodeAddress:e});const a=t.findIndex(m=>!s.containers.has(m)),c=a<0?t:t.slice(0,a),l=(c==null?void 0:c.at(-1))??e,d=(p=[...s.slots.values()].find(m=>m.nodeId===l))==null?void 0:p.label;return f.jsxs(qt.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(Oe,{"aria-label":"Back to parent fields",title:"Back to parent fields",icon:f.jsx(Z.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:()=>n(c.slice(0,-1))}),f.jsx("strong",{style:{minWidth:0,overflowWrap:"anywhere"},children:Vt(d)})]}),f.jsx(kd,{nodeAddress:l,onOpen:m=>n([...c,m])},l)]})}function kd({nodeAddress:e,onOpen:r}){var S,E;const{data:t,schema:n,callbacks:o,bindings:i,editable:s,renderForm:a,structured:c}=j.useContext(qt),{readOnly:l,config:d,colorMode:u}=Ve(),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=$e(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 A;return Eo((A=m.fields[R])==null?void 0:A.$visibleWhen,t)}),w=x.length>8||x.some(([R])=>{var A;return(A=m.fields[R])==null?void 0:A.$section}),v=new Map;for(const R of x){const[A,I]=R,M=w?Vt(((E=m.fields[A])==null?void 0:E.$section)??(I.type.kind==="object"||I.type.kind==="array"?A:I.optional?"Options":"General")):"";v.has(M)||v.set(M,[]),v.get(M).push(R)}const C=([R,A])=>f.jsx(Ju,{request:{data:t,address:b?g:`${g}.${R}`,nodeAddress:g,nodeId:typeof(y==null?void 0:y.id)=="string"?y.id:void 0},property:A,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(Kw,{nodeAddress:e,onOpen:r}),!c&&p&&m.type.additionalProperties&&x.length===0&&f.jsx(Ju,{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,A])=>w&&A.length>1?f.jsxs("details",{open:!0,children:[f.jsxs("summary",{children:[f.jsx("span",{children:R}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),A.map(C)]},R):A.map(C))]})}function Rb(e){const{viewData:r}=j.useContext(qt),{nodeById:t,edgeById:n,parentIds:o}=Qt();if(r){const i=$e(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",...yb(r==="transparent"?"currentColor":r,t,".flow-sdk-node:hover &",!t)}}function Mb({label:e,value:r,options:t,onChange:n,disabled:o}){var i;return f.jsxs(Nt,{"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 Ud({nodeId:e,edgeId:r,value:t,open:n,onOpenChange:o}){const{callbacks:i,readOnly:s,themeColor:a,colorMode:c}=Ve(),{background:l,backgroundSecondary:d,border:u,colorText:h,colorInactive:p}=st(),m=c==="dark"?ln:Me(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,A]=j.useState("loading"),[I,M]=j.useState(""),[k,_]=j.useState(0),[N,O]=j.useState(""),[W,T]=j.useState(""),[Y,he]=j.useState(!1);j.useEffect(()=>()=>{b.current++},[]),j.useEffect(()=>{if(!x)return;let V=!0;return import("react-icons/pi").then(le=>{V&&(E(Object.keys(le).filter(X=>X.startsWith("Pi")).sort()),A("ready"))}).catch(()=>{V&&A("unavailable")}),()=>{V=!1}},[x]),j.useEffect(()=>{var V;s&&((V=g.current)==null||V.close())},[s]),j.useEffect(()=>{var V,le,X;if(n!==void 0){if(!n||s){(V=g.current)==null||V.close();return}(le=g.current)!=null&&le.open||(T(""),C(t==="PiFileSvg"||t&&Sr(t)?"custom":"icons"),O(t&&!t.startsWith($n)&&Sr(t)?t:""),w(!0),(X=g.current)==null||X.showModal())}},[n,s,t]);const K=V=>{var le,X,ue;s||(r?(le=i.onEdgeIconChange)==null||le.call(i,r,V):e&&((X=i.onNodeIconChange)==null||X.call(i,e,V)),o==null||o(!1),(ue=g.current)==null||ue.close())},re=S.filter(V=>V.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(I.trim().toLowerCase())),G=36,ne=Math.max(1,Math.ceil(re.length/G)),q=Math.min(k,ne-1),z=re.slice(q*G,(q+1)*G),H={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(Oe,{"aria-label":r?"Choose edge icon":"Choose node icon",icon:f.jsx(Z.PiShapes,{size:20}),size:"sm",variant:"ghost",color:Me(a),disabled:s,onClick:()=>{var V;T(""),C(t&&Sr(t)?"custom":"icons"),O(t&&!t.startsWith($n)&&Sr(t)?t:""),w(!0),(V=g.current)==null||V.showModal()}})}),f.jsx(D.chakra.dialog,{ref:g,"aria-label":r?"Choose edge icon":"Choose node icon",css:mr(Me(l),Me(u)),onClose:()=>{w(!1),o==null||o(!1),b.current++,he(!1)},onClick:V=>{V.stopPropagation(),V.target===V.currentTarget&&V.currentTarget.close()},onKeyDown:V=>V.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(Oe,{"aria-label":r?"Remove edge icon":"Remove node icon",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:s||Y,onClick:()=>K("")})}),f.jsx(dn,{"aria-label":"Close icon picker",onClick:()=>{var V;return(V=g.current)==null?void 0:V.close()}})]})]}),f.jsxs(D.Tabs.Root,{value:v,onValueChange:({value:V})=>{C(V),T("")},display:"contents",css:{"--indicator-thickness":"1px"},children:[f.jsx(D.Tabs.List,{"aria-label":"Icon source",width:"100%",borderBottomWidth:0,children:["icons","custom"].map(V=>f.jsx(D.Tabs.Trigger,{value:V,flex:1,minW:0,justifyContent:"center",px:3,py:2,fontSize:"13px",_selected:{color:a,borderColor:m,"--indicator-color":m},children:V==="icons"?"React icons":"Custom SVG"},V))}),f.jsx("input",{ref:y,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:Y||s,onChange:async V=>{var ue;const le=(ue=V.target.files)==null?void 0:ue[0];if(V.target.value="",!le)return;const X=++b.current;he(!0),T("");try{const oe=await Bw(le);X===b.current&&K(oe)}catch(oe){X===b.current&&T(oe instanceof Error?oe.message:"Unable to read SVG.")}finally{X===b.current&&he(!1)}}}),f.jsx(D.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:V=>{M(V.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:[z.map(V=>f.jsx("button",{type:"button","aria-label":`Choose ${V}`,"aria-pressed":t===V,title:V,onClick:()=>K(V),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${t===V?2:1}px solid ${Me(t===V?a:u)}`,background:Me(t===V?l:d),color:"inherit",cursor:"pointer"},children:f.jsx(dr,{name:V,size:24})},V)),z.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:[re.length," icons · ",q+1," / ",ne]}),f.jsxs("div",{style:{display:"flex",gap:4},children:[f.jsx(Ge,{label:"Previous icons",children:f.jsx(Oe,{"aria-label":"Previous icons",icon:f.jsx(Z.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:q===0,onClick:()=>_(q-1)})}),f.jsx(Ge,{label:"Next icons",children:f.jsx(Oe,{"aria-label":"Next icons",icon:f.jsx(Z.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:q+1>=ne,onClick:()=>_(q+1)})})]})]})]}):f.jsxs(f.Fragment,{children:[t&&Sr(t)&&f.jsx(dr,{name:t,size:64}),f.jsxs("button",{type:"button",disabled:Y||s,onClick:()=>{var V;return(V=y.current)==null?void 0:V.click()},style:{...H,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[f.jsx(Z.PiUploadSimple,{}),Y?"Uploading...":"Upload SVG"]}),f.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:V=>{V.preventDefault(),!(Y||s)&&(!Sr(N.trim())||N.trim().startsWith($n)?T("Enter an HTTP or HTTPS image URL."):K(N.trim()))},children:[f.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:N,disabled:Y||s,onChange:V=>O(V.target.value),style:{...H,flex:1,minWidth:0}}),f.jsx(Ge,{label:"Apply URL",children:f.jsx(Oe,{type:"submit","aria-label":"Apply URL",icon:f.jsx(Z.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:Y||s||!N.trim(),style:{flexShrink:0}})})]})]})})]}),W&&f.jsx("div",{role:"alert",style:{fontSize:13},children:W})]})})]})}const po=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500",ln],Tb=["gray.900",ln,"gray.600","gray.200","white"];function Ib(){const{config:e}=Ve(),r=e.selectionToolbar||{},t=new Set(r.hide||[]);return{palette:r.palette||po,show:n=>!t.has(n)}}function It(){const{border:e}=st();return f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:e})}function kr({value:e,placeholder:r,ariaLabel:t,width:n="140px",type:o="text",min:i,disabled:s=!1,onCommit:a}){const{colorText:c}=st(),[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(D.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 Gr({colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:s,colorText:a}=st(),[c,l]=j.useState(!1),d=j.useId(),u=j.useRef(null),h=r??e[0]??"transparent",p=jo(f.jsx(Gr,{colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i}));return f.jsx(nn.Provider,{value:null,children:f.jsxs(D.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(D.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(D.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(D.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(Oe,{"aria-label":`Reset ${t}`,icon:f.jsx(D.Icon,{as:Z.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:s,onClick:()=>{var m;o(),l(!1),(m=u.current)==null||m.focus()}})})]})]})})}function Nb({edgeId:e,onClose:r}){var p;const{callbacks:t,themeColor:n,config:o}=Ve(),{colorInactive:i}=st(),{edgeById:s}=Qt(),{palette:a,show:c}=Ib(),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:Z.PiLineSegment,label:"Solid"},{key:"dashed",icon:Z.PiLineSegments,label:"Dashed"},{key:"animated",icon:Z.PiFastForward,label:"Animated"}];return f.jsxs(f.Fragment,{children:[f.jsx(dn,{onClick:r}),c("label")&&f.jsxs(f.Fragment,{children:[f.jsx(It,{}),f.jsx(kr,{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(It,{}),h.map(m=>f.jsx(Ge,{label:m.label,children:f.jsx(Oe,{"aria-label":`Edge style ${m.key}`,"aria-pressed":u===m.key,icon:f.jsx(D.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(Mb,{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(Nt,{"aria-label":"Edge shape",title:`Edge shape: ${(l==null?void 0:l.type)??"Default"}`,icon:f.jsx(Z.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(It,{}),f.jsx(Ud,{edgeId:e,value:l==null?void 0:l.icon},e),f.jsx(kr,{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(It,{}),f.jsx(Gr,{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(It,{}),f.jsx(Ge,{label:"Delete edge",children:f.jsx(Oe,{"aria-label":"Delete edge",icon:f.jsx(D.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var m;(m=t.onEdgeDelete)==null||m.call(t,e,l),r()}})})]})]})}function Ob({ids:e,showDivider:r=!0}){const{callbacks:t,config:n,nodeGridOptions:o,fillRadiusEditedIds:i}=Ve(),{colorInactive:s}=st(),{nodeById:a}=Qt(),[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(It,{}),f.jsx(D.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:f.jsxs(Nt,{icon:f.jsx(D.Icon,{as:Iv.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(kr,{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 $b({ids:e,onClose:r,afterLabel:t}){var V,le,X,ue,oe,de,ge,ce;const{callbacks:n,colorMode:o,themeColor:i,config:s,setNodeViewMode:a}=Ve(),{colorText:c,colorInactive:l}=st(),{nodeById:d,parentIds:u}=Qt(),{palette:h,show:p}=Ib(),m=e.length===1,[g,y]=j.useState(""),b=m?(V=d.get(e[0]))==null?void 0:V.data:void 0,x=e.map(U=>{var te,pe;return((pe=(te=d.get(U))==null?void 0:te.data.config)==null?void 0:pe.typeView)??""}),w=x.some(U=>U!==x[0]),v=w?"mixed":x[0]??"",C=[{value:"text",label:"Text",view:"text",icon:Z.PiTextT},{value:"icon-label",label:"Icon Label",view:"icon-label",icon:Z.PiShapes},{value:"object",label:"Object",view:"object",icon:Z.PiBracketsCurly},{value:"grid",label:"Grid",view:"grid",icon:Z.PiGridFour},{value:"parent",label:"Parent",view:"parent",icon:Z.PiStack},{value:"media",label:"Media",view:"icon-label",icon:Z.PiFileSvg},{value:"content",label:"Content",view:"object",icon:Z.PiTextAlignLeft},{value:"prompt",label:"Prompt",view:"prompt",icon:Z.PiTextAlignLeft}].filter(U=>U.view!=="prompt"||!!n.onPromptSubmit),S=e.some(U=>{var pe,ve;const te=(pe=d.get(U))==null?void 0:pe.data;return te&&(u.has(U)||((ve=te.config)==null?void 0:ve.parentContainer)||Object.prototype.hasOwnProperty.call(s.customViews??{},te.type))}),E=(le=b==null?void 0:b.config)==null?void 0:le.collapsed,R=Rb(e[0]),A=U=>{var te,pe,ve;return(((pe=(te=d.get(U))==null?void 0:te.data.viewProps)==null?void 0:pe.outline)??(u.has(U)?(ve=s.parentNodeStyle)==null?void 0:ve.outline:!1))===!0},I=e.every(A),M=!I&&e.some(A),k=U=>{var te;return((te=d.get(U))==null?void 0:te.data.isNodeAnimated)===!0},_=e.every(k),N=!_&&e.some(k),O=e.map(U=>{var te;return((te=d.get(U))==null?void 0:te.data.nodeAnimationVariant)??"traveling"}),W=O.every(U=>U===O[0])?O[0]:"",T=U=>e.forEach(U),[Y,he]=j.useState(!1),K=Y&&p("color")&&p("borderColor"),re=U=>{var te,pe,ve;return(((pe=(te=d.get(U))==null?void 0:te.data.viewProps)==null?void 0:pe.borderStyle)??(u.has(U)?(ve=s.parentNodeStyle)==null?void 0:ve.borderStyle:"solid"))==="dashed"},G=e.every(re),ne=!G&&e.some(re),q=e.map(U=>{var ve,Ne,Je;const te=(ve=d.get(U))==null?void 0:ve.data,pe=u.has(U)?Dn((Ne=s.parentNodeStyle)==null?void 0:Ne.borderWidth,6):(te==null?void 0:te.type)==="objectView"?3:2;return Dn((Je=te==null?void 0:te.viewProps)==null?void 0:Je.borderWidth,pe)}),z=q.every(U=>U===q[0])?String(q[0]??""):"",H=U=>T(te=>{var pe,ve;K?(pe=n.onNodeBorderColorChange)==null||pe.call(n,te,U):(ve=n.onNodeColorChange)==null||ve.call(n,te,"bg",U)});return f.jsxs(f.Fragment,{children:[f.jsx(dn,{onClick:r}),f.jsx(It,{}),m&&p("label")?f.jsx(kr,{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(D.Text,{fontSize:"xs",color:c,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),t,p("typeView")&&f.jsxs(Nt,{"aria-label":"Type view",title:S?"Type view is managed by the custom renderer or container":`Type view: ${v||"None (default)"}`,icon:f.jsx(Z.PiCards,{size:20}),style:{width:36},value:v,disabled:s.readOnly||s.editable===!1||S,onValueChange:U=>{var pe;const te=(pe=C.find(ve=>ve.value===U))==null?void 0:pe.view;te&&T(ve=>{var Ne,Je;(Ne=n.onNodeTypeViewChange)==null||Ne.call(n,ve,te),a(ve,"default"),(Je=n.onNodeViewToggle)==null||Je.call(n,ve)})},children:[w&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),C.map(U=>f.jsx("option",{value:U.value,children:f.jsxs(D.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(Ob,{ids:e},e.join("\0")),p("outline")&&f.jsxs(f.Fragment,{children:[f.jsx(It,{}),f.jsx(Ge,{label:I?"Restore node fill":"Remove node fill",children:f.jsx(Oe,{"aria-label":"Toggle node outline","aria-pressed":M?"mixed":I,icon:f.jsx(D.Icon,{as:I?Z.PiSquare:Z.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:I?i:l,onClick:()=>T(U=>{var te;return(te=n.onNodeOutlineChange)==null?void 0:te.call(n,U,!I)})})})]}),p("color")&&f.jsxs(f.Fragment,{children:[f.jsx(It,{}),p("borderColor")&&f.jsx(Ge,{label:K?"Edit node colors":"Edit node border",children:f.jsx(Oe,{"aria-label":"Edit node border","aria-pressed":K,icon:f.jsx(D.Icon,{as:Z.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:K?i:l,bg:K?o==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>he(U=>!U)})}),f.jsx(Gr,{label:K?"Border color":"Background",colors:h,value:K?((X=b==null?void 0:b.viewProps)==null?void 0:X.borderColor)??(m&&u.has(e[0])?(ue=s.parentNodeStyle)==null?void 0:ue.borderColor:void 0):(oe=b==null?void 0:b.viewProps)==null?void 0:oe.bgColor,onPick:H,onReset:()=>H("")}),K&&p("style")&&f.jsxs(f.Fragment,{children:[f.jsx(It,{}),f.jsx(Ge,{label:G?"Solid border":"Dashed border",children:f.jsx(Oe,{"aria-label":"Toggle dashed border","aria-pressed":ne?"mixed":G,icon:f.jsx(D.Icon,{as:G?Z.PiLineSegments:Z.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:G?i:l,onClick:()=>T(U=>{var te;return(te=n.onNodeBorderStyleChange)==null?void 0:te.call(n,U,G?"solid":"dashed")})})}),f.jsx(kr,{ariaLabel:"Border thickness",placeholder:m?"Auto":"Mixed",width:"64px",type:"number",min:0,value:z,onCommit:U=>T(te=>{var pe;return(pe=n.onNodeBorderWidthChange)==null?void 0:pe.call(n,te,U===""?void 0:Number(U))})})]})]}),p("animation")&&f.jsxs(f.Fragment,{children:[f.jsx(It,{}),f.jsx(Ge,{label:_?"Stop border animation":"Animate node border",children:f.jsx(Oe,{"aria-label":"Toggle node animation","aria-pressed":N?"mixed":_,icon:f.jsx(D.Icon,{as:Z.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:_?i:l,onClick:()=>T(U=>{var te;return(te=n.onNodeAnimationChange)==null?void 0:te.call(n,U,!_)})})}),(_||N)&&f.jsx(Mb,{label:"Node animation",value:W,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:s.readOnly,onChange:U=>T(te=>{var pe;return(pe=n.onNodeAnimationVariantChange)==null?void 0:pe.call(n,te,U)})})]}),!K&&p("textColor")&&f.jsxs(f.Fragment,{children:[f.jsx(It,{}),f.jsx(Gr,{label:"Text color",colors:Tb,value:(de=b==null?void 0:b.viewProps)==null?void 0:de.textColor,onPick:U=>T(te=>{var pe;return(pe=n.onNodeColorChange)==null?void 0:pe.call(n,te,"text",U)}),onReset:()=>T(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(It,{}),f.jsx(Ud,{nodeId:e[0],value:(ge=b==null?void 0:b.config)==null?void 0:ge.icon},e[0]),f.jsx(kr,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((ce=b==null?void 0:b.config)==null?void 0:ce.icon)||"",onCommit:U=>{var te;return(te=n.onNodeIconChange)==null?void 0:te.call(n,e[0],U)}})]}),m&&R&&p("collapse")&&E!==void 0&&f.jsxs(f.Fragment,{children:[f.jsx(It,{}),f.jsx(Ge,{label:E?"Expand":"Collapse",children:f.jsx(Oe,{"aria-label":E?"Expand node":"Collapse node",icon:f.jsx(D.Icon,{as:E?Z.PiArrowsOutLineVertical:Z.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(It,{}),f.jsx(Ge,{label:m?"Delete node":`Delete ${e.length} nodes`,children:f.jsx(Oe,{"aria-label":"Delete selected nodes",icon:f.jsx(D.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:o==="dark"?"red.300":"red.500",onClick:()=>{T(U=>{var te,pe;return(pe=n.onNodeDelete)==null?void 0:pe.call(n,U,((te=d.get(U))==null?void 0:te.data)||{id:U})}),r()}})})]}),f.jsx(Ge,{label:"Copy selection",children:f.jsx(Oe,{"aria-label":"Copy selection",icon:f.jsx(Z.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(Oe,{"aria-label":"Duplicate selection",icon:f.jsx(Z.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(D.Text,{role:"alert",fontSize:"xs",children:g})]})}async function qb(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 Lb(e,r="squeed.svg"){const t=document.createElement("a");t.href=await qb(e),t.download=r.endsWith(".svg")?r:`${r}.svg`,t.click()}function Fb(){const{themeColor:e}=Ve(),[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(Oe,{"aria-label":"Download SVG",icon:f.jsx(Z.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 Lb(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 Po({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(D.Box,{position:"relative",bg:s?r:"transparent",minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:s?"30px":0,css:{...s?mr(m,`var(--chakra-colors-${t.replace(".","-")})`):{},...s||o?{"--flow-toolbar-start-width":o?`${u}px`:"0px"}:{}},children:[f.jsx(D.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(D.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(D.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(D.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 Xw(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 _b(e)};const i=await Gd(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 zb({message:e,onDismiss:r}){const{background:t,colorText:n,border:o}=st();return!e||typeof document>"u"?null:Vr.createPortal(f.jsxs(D.chakra.div,{role:"alert","aria-atomic":"true",css:mr(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(Z.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 Kd({showDivider:e=!0,compact:r=!1}={}){const{edgeMode:t,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:s,readOnly:a,themeColor:c,colorMode:l}=Ve(),{edgeById:d}=Qt(),{data:u,schema:h,setSchema:p,bindings:m,structured:g}=j.useContext(qt),y=(g==null?void 0:g.sourceBindings)??m,b=(g==null?void 0:g.sourceSchema)??h,{colorText:x}=st(),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 A=o?[...d.values()].filter(k=>Vd(o,k.data)).length:0,I=o?`${o.name}: ${b?`${Object.keys(b).length} form types loaded; `:""}${A} invalid or unverified connections`:"",M=jo(f.jsx(Kd,{showDivider:!1,compact:!0}));return f.jsx(nn.Provider,{value:null,children:f.jsxs("span",{style:{display:"contents"},onClickCapture:M,children:[f.jsx(zb,{message:E,onDismiss:()=>R("")}),e&&f.jsx(Nn,{}),f.jsxs(Nt,{"aria-label":"Edge mode",title:t==="auto"?"Connections: Auto":t==="properties"?"Connections: Properties":"Connections: Nodes",icon:t==="auto"?f.jsx(Z.PiGraph,{size:20}):t==="properties"?f.jsx(Z.PiTable,{size:20}):f.jsx(Z.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(D.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(Z.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(Oe,{"aria-label":"Upload workflow interface",icon:f.jsx(Z.PiUploadSimple,{size:20}),color:Me(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 O,W;const _=(O=k.target.files)==null?void 0:O[0];if(k.target.value="",!_)return;const N=++v.current;S(!0),R("");try{const T=y?await Gd(_,[...new Set(Object.values(y).map(K=>K.schemaType??K.type))]):void 0;if(y&&T){for(const K of Object.values(y))if(!Object.prototype.hasOwnProperty.call(T,K.schemaType??K.type))throw new Error(`Missing form type: ${K.schemaType??K.type}`)}const{contract:Y,schema:he}=y&&T?{schema:T,contract:{name:_.name,nodes:Object.fromEntries(Object.entries(y).map(([K,re])=>[K,{type:T[re.schemaType??re.type],optional:!1}]))}}:await Xw(_,u);if(N!==v.current)return;p==null||p(he),i(Y),(W=s.onWorkflowContractChange)==null||W.call(s,Y)}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:Me(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(Oe,{"aria-label":"Remove workflow interface",icon:f.jsx(Z.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 Yw=[{value:"BT",label:"Bottom to Up",icon:Z.PiArrowUp,flowType:Sn.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:Z.PiArrowDown,flowType:Sn.TOP_DOWN},{value:"LR",label:"Left to Right",icon:Z.PiArrowRight,flowType:Sn.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:Z.PiArrowLeft,flowType:Sn.RIGHT_LEFT}],Bb=({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:A,setIsArrayNodeMode:I,isPinned:M,setIsPinned:k,callbacks:_,config:N,readOnly:O}=Ve(),{nodeById:W,edgeById:T,parentIds:Y}=Qt(),he=N.colorMode==="dark",{background:K,border:re,colorInactive:G,colorText:ne,colorActive:q}=st(),z=he?re:"gray.300",H=`var(--chakra-colors-${K.replace(".","-")})`,V=`var(--chakra-colors-${(he?re:"gray.300").replace(".","-")})`,[le,X]=j.useState(!1),[ue,oe]=j.useState(!0),de=N.bottomBarCollapsed??ue,ge=j.useRef(null),ce=So({edge:"bottom",enabled:!M,bounds:ge,inside:[ge]}),U=j.useCallback(Ee=>{const Le=r.current;if(!Le)return;const at=N.minZoom??.01,He=N.maxZoom??1.5,ft=.02;let ht=Le.zoom();switch(Ee){case"increase":ht=Math.min(He,ht+ft),Le.zoom(ht),Le.center(!1);break;case"decrease":ht=Math.max(at,ht-ft),Le.zoom(ht),Le.center(!1);break;case"reset":Le.fit(50);break}},[r,N.minZoom,N.maxZoom]),te=N.renderSelectedNodeToolbar,pe=p.length>0&&!!te,ve=j.useMemo(()=>pe?p.map(Ee=>{var at;return{...((at=W.get(Ee))==null?void 0:at.data)??{id:Ee},isParent:Y.has(Ee)}}):[],[pe,p,W,Y]),Ne=j.useCallback(()=>{var Ee;m([]),(Ee=_.onNodeDeselect)==null||Ee.call(_)},[m,_]),Je=N.renderSelectedEdgeToolbar,tt=!!g&&!!Je,Ye=j.useMemo(()=>{var Ee;return!tt||!g?null:((Ee=T.get(g))==null?void 0:Ee.data)??{id:g}},[tt,g,T]),Ue=j.useCallback(()=>{var Ee;y(null),(Ee=_.onEdgeDeselect)==null||Ee.call(_)},[y,_]),lt=N.selectionToolbar!==!1&&!O,be=lt&&!!g&&!Je,Ae=lt&&!be&&p.length>0&&!te,ie=be||Ae,ae=M||ce||le||ie||N.bottomBarCollapsed===!1;j.useEffect(()=>{p.length||g?a(!1):O||N.bottomBarCollapsed===void 0&&oe(!s)},[s,p.length,g,O,a,N.bottomBarCollapsed]);const Ie=N.renderBottomBar,et=Nw();return Ie?f.jsxs(f.Fragment,{children:[pe&&f.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:te({selectedNodeIds:p,selectedNodeData:ve,onDeselect:Ne})}),tt&&Ye&&f.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Je({edgeId:g,edgeData:Ye,onDeselect:Ue})}),f.jsx(D.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:Ie({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:A,setIsArrayNodeMode:I,selectedNodeIds:p,selectedNodeData:ve,selectedEdgeId:g,selectedEdgeData:Ye,onNodeDeselect:Ne,onEdgeDeselect:Ue,callbacks:_})})]}):f.jsxs(nn.Provider,{value:et,children:[pe&&f.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:te({selectedNodeIds:p,selectedNodeData:ve,onDeselect:Ne})}),tt&&Ye&&f.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Je({edgeId:g,edgeData:Ye,onDeselect:Ue})}),f.jsx(D.Box,{ref:ge,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:ae?"translateY(0)":"translateY(100%)",pointerEvents:ae?"auto":"none",visibility:ae?"visible":"hidden",opacity:ae?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(D.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(Po,{background:K,border:he?re:"gray.300",children:f.jsxs(D.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[be?f.jsx(Nb,{edgeId:g,onClose:Ue}):Ae?f.jsx($b,{ids:p,onClose:Ne}):null,f.jsxs("div",{style:{display:be||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(Oe,{"aria-label":"Pin","aria-pressed":M,icon:f.jsx(D.Icon,{as:M?Z.PiPushPinFill:Z.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:M?t:G,onClick:()=>{k(!M),X(!1)}})}),f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ge,{label:"Zoom Out",children:f.jsx(Oe,{"aria-label":"Zoom out",rememberAction:!1,icon:f.jsx(D.Icon,{as:Z.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:ne,onClick:()=>U("decrease")})}),f.jsx(Ge,{label:"Zoom In",children:f.jsx(Oe,{"aria-label":"Zoom in",rememberAction:!1,icon:f.jsx(D.Icon,{as:Z.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:ne,onClick:()=>U("increase")})}),f.jsx(Ge,{label:"Reset Zoom",children:f.jsx(Oe,{"aria-label":"Reset zoom",rememberAction:!1,icon:f.jsx(D.Icon,{as:Z.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:ne,onClick:()=>U("reset")})}),de&&f.jsx(Ow,{visibleActions:h?["Collision mode","Fill",...h.fill?["Grid adjustment"]:[]]:[],divider:f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"})})]}),f.jsxs("span",{style:{display:de?"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(Oe,{"aria-label":"Toggle draw mode","aria-keyshortcuts":"V","aria-pressed":E,icon:f.jsx(D.Icon,{as:Z.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:E?t:G,onClick:()=>R(!E)})}),f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ge,{label:b?"Zoom Mode (z)":"Pan Mode (z)",children:f.jsx(Oe,{"aria-label":"Toggle zoom mode",icon:f.jsx(D.Icon,{as:b?Z.PiMagnifyingGlassPlus:Z.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:b?t:G,onClick:()=>x(!b)})}),f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ge,{label:w?"Multi-Select On (m)":"Multi-Select Off (m)",children:f.jsx(Oe,{"aria-label":"Toggle multi-select",icon:f.jsx(D.Icon,{as:Z.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:w?t:G,onClick:()=>v(!w)})}),f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ge,{label:C?"Drag Mode On (d)":"Drag Mode Off (d)",children:f.jsx(Oe,{"aria-label":"Toggle drag mode",icon:f.jsx(D.Icon,{as:Z.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:C?t:G,onClick:()=>S(!C)})})]}),N.bottomBarNavigation===!1&&(e===void 0?f.jsx(so,{}):e?Vr.createPortal(f.jsx(so,{}),e):null),N.bottomBarExtra&&f.jsxs(f.Fragment,{children:[N.bottomBarNavigation!==!1&&f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"}),N.bottomBarExtra]}),f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"}),f.jsx(Cb,{})]}),f.jsx("span",{style:{display:N.bottomBarNavigation===!1||de&&!h?"none":"contents"},children:f.jsx(so,{})}),f.jsxs("span",{style:{display:de?"none":"contents"},children:[f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"}),f.jsx(wb,{}),l!=="properties"&&f.jsxs(f.Fragment,{children:[f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ge,{label:A?"Array Mode [ ]":"Set Mode { }",children:f.jsx(Oe,{"aria-label":"Toggle array mode",icon:f.jsx(D.Icon,{as:A?Z.PiBracketsSquare:Z.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:A?t:G,onClick:()=>{var Le;const Ee=!A;I(Ee),(Le=_.onArrayModeChange)==null||Le.call(_,Ee)}})})]}),f.jsx(Kd,{}),!O&&f.jsxs("span",{style:{display:s?"contents":"none"},children:[f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Gr,{label:"Graph theme",colors:po,value:t,includeTransparent:!1,onPick:Ee=>{var Le;n(Ee),(Le=_.onThemeColorChange)==null||Le.call(_,Ee)}})]}),!O&&f.jsxs(f.Fragment,{children:[f.jsx(D.Icon,{as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"}),f.jsx(Gr,{label:"Graph edge color",colors:po,value:o||(he?"gray.500":ln),onPick:i,onReset:()=>i("")}),f.jsx(D.Icon,{as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"})]}),f.jsx(Sb,{})]}),f.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ge,{label:de?"Expand toolbar":"Collapse toolbar",children:f.jsx(Oe,{"aria-label":"Toggle toolbar collapse",rememberAction:!1,icon:f.jsx(D.Icon,{as:de?Z.PiCaretRight:Z.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:G,onClick:()=>{var Ee;N.bottomBarCollapsed===void 0&&oe(!de),a(de),(Ee=_.onBottomBarCollapsedChange)==null||Ee.call(_,!de)}})}),!de&&f.jsx(Fb,{})]})]})}),!ie&&f.jsxs(D.Box,{position:"relative",ml:"auto",flexShrink:0,children:[f.jsx(D.Box,{"data-flow-direction-control":"",bg:K,borderRadius:"30px",h:50,css:mr(H,V),px:3,cursor:"pointer",onClick:()=>X(!le),children:f.jsxs(D.Flex,{align:"center",h:"100%",children:[f.jsx(Ge,{label:"Flow Direction",children:f.jsx(Oe,{"aria-label":"Direction",onClick:Ee=>{Ee.stopPropagation(),X(!le)},icon:f.jsx(D.Icon,{as:Z.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:G})}),f.jsx(D.Text,{fontSize:"xs",textTransform:"uppercase !important",color:he?"whiteAlpha.600":"blackAlpha.500",ml:1,children:c.toUpperCase()})]})}),le&&f.jsx(D.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:f.jsxs(D.Box,{bg:K,borderRadius:"30px",p:2,minW:"180px",css:mr(H,V),children:[Yw.map(Ee=>f.jsxs(D.Flex,{align:"center",gap:3,px:3,py:2,css:ho,cursor:"pointer",_hover:{bg:he?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Le;(Le=_.onDirectionChange)==null||Le.call(_,Ee.value),X(!1)},children:[f.jsx(D.Icon,{as:Ee.icon,boxSize:5,color:ne}),f.jsx(D.Text,{fontSize:"sm",color:ne,flex:1,whiteSpace:"nowrap",children:Ee.label}),c===Ee.value&&f.jsx(D.Icon,{as:Z.PiCheck,boxSize:4,color:q})]},Ee.value)),f.jsxs(D.Flex,{align:"center",gap:3,px:3,py:2,css:ho,cursor:"pointer",_hover:{bg:he?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ee;(Ee=_.onDirectionChange)==null||Ee.call(_,"C"),X(!1)},children:[f.jsx(D.Icon,{as:Z.PiAlignCenterHorizontal,boxSize:5,color:ne}),f.jsx(D.Text,{fontSize:"sm",color:ne,flex:1,whiteSpace:"nowrap",children:"Center"}),c==="C"&&f.jsx(D.Icon,{as:Z.PiCheck,boxSize:4,color:q})]})]})})]})]})})]})};Bb.displayName="BottomBar";const Db=j.memo(Bb);function Qw({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(D.Icon,{as:Z.PiGraph,boxSize:5})})}const Zu={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function Wb(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(Zu,l)){if(typeof s[l]!="string"||!s[l])return!1;t.set(a,{...t.get(a),[Zu[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 e1(e,r){return Wb(e,r)!==void 0}function t1(e,r,t){if(e===r)return t;const n=Wb(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)||!$e(r,i))return;return{edges:t.edges,nodes:t.nodes.map(i=>{const s=n.get(i.data.id),a=$e(e,i.data.id),c=$e(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 Pd(e){return e.kind==="literal"?e.value:e.kind==="union"?Pd(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,r])=>!r.optional).map(([r,t])=>[r,Pd(t.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Vb(e,r,t){var y,b,x;const n=(y=$e(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)||Xt(d.properties[w].type,v,!d.properties[w].optional))throw new Error(`Invalid creation default: ${w}`);const h={...Pd(d),...structuredClone(u)};((x=d.properties.id)==null?void 0:x.type.kind)==="string"&&(h.id=Nd());let p=e;const m=$e(e,o.$address);if(m===void 0)p=Rt(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=Ld(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:Fd(g.json,r,{target:g.address,label:o.$edgeLabel})}}function r1(e,r,t){var i,s;if(Array.isArray(r)){const a=new Set(r);if(!$e(e,t)||[...a].some(u=>u==="root"||!$e(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=$e(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"||!$e(e,r)||!$e(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=$e(e,o))==null?void 0:s.$parent;o=typeof a=="string"?a:o.includes(".")?o.slice(0,o.lastIndexOf(".")):void 0}return uo(Rt(e,r,a=>({...a,$parent:t})),t,!1)}function Gb(e,r){const t=new Set(r.filter(a=>$e(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 Jd(e,r){const t=Gb(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($e(e,a));i(l),s[`node_${c+1}`]=l}),s}function Hb(e,r){const t=Jd(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:Rt(e,"root",a=>({...a,...s})),ids:[...o.values()].map(a=>`root.${a}`)}}function n1(e,r){const t=o=>e&&typeof e=="object"&&o in e;let n=1;for(;t(`${r}_${n}`);)n++;return`${r}_${n}`}function Ub(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($e(a,p))!==JSON.stringify($e(e,p))&&(a=lb(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(Jd(e,a),null,2))},onNodesDuplicate:a=>{var l;if(((l=t.onNodesDuplicate)==null?void 0:l.call(t,a))===!0)return;const c=Hb(e,a);i(c.json,{type:"nodeCreate",address:c.ids[0],nodeAddresses:c.ids})},onFormChange:a=>{const c=$e(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(Et(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(Et(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(Et(e,a,"$contentFormat",c),{type:"nodeStyle",address:a,key:"$contentFormat",value:c}))},onNodeTypeViewChange:(a,c)=>{var l;c!==void 0&&!zd.includes(c)||((l=t.onNodeTypeViewChange)==null||l.call(t,a,c),i(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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=$e(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&&Vb(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=n1($e(m,c),a.isArrayMode?"list":"node"),E=a.isArrayMode?{$bgColor:"gray.500",$label:C,$:[]}:{$bgColor:"gray.500",$label:C},R=Ld(m,c,E,S);m=R.json,g??(g=R.address),y.push(R.address)}d&&(m=Rt(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(ub(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?Fd(e,a,d):fb(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(Er(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(db(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(Er(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(Er(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(Er(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(Er(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=hb(e,l);d.removed&&i(d.json,{type:"edgeDelete",edge:l,key:l.connection?"$connections":"$target"})}}}const o1=".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 i1({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 a1=".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 s1({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 Kb=".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 c1=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 Jb(e,r=!1){return e&&!r&&typeof requestAnimationFrame<"u"&&!(typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches)}function Zb(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(!Jb(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 Xu(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 l1(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 sr=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}),d1=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function ri(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 u1=(e,r)=>e.x1<=r.x2&&e.x2>=r.x1&&e.y1<=r.y2&&e.y2>=r.y1,Yu=(e,r)=>e.x>=r.x1&&e.x<=r.x2&&e.y>=r.y1&&e.y<=r.y2,Wt=e=>(Math.round(e*10)/10).toString(),vt=e=>`${Wt(e.x)} ${Wt(e.y)}`,f1=e=>e>0?1:e<0?-1:0,Qu=(e,r)=>e>0?Math.max(e-r,0):Math.min(e+r,0);function h1(e,r,t,n,o=10){const i=r.x-e.x,s=r.y-e.y,a=Qu(i,(e.w+r.w)/2),c=Qu(s,(e.h+r.h)/2),l=t==="downward"||t==="upward",d=l?c:a,u=l?s:i,h=f1(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 p1(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 p1(e,r,sr(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 Xb(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 g1(e,r,t,n){const o=Qr(e,t.srcDist),i=Qr(r,t.tgtDist);if(n==="straight")return Qb(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"?_t(o,l,t.arrowGap):o,h=t.arrowAt==="target"?_t(i,d,t.arrowGap):i,p=t.arrowAt==="source"?Gt(o,l,t.arrowSize,t.headShape):t.arrowAt==="target"?Gt(i,d,t.arrowSize,t.headShape):void 0;if(n==="bezier")return{d:`M${vt(u)} C${vt(l)} ${vt(d)} ${vt(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 Ao(u,b,h,p,n==="orthogonal"?0:t.radius)}function _t(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 Gt(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${vt(e)} L${Wt(e.x-c*d)} ${Wt(e.y+a*d)} L${Wt(u-c*d)} ${Wt(h+a*d)} L${Wt(u+c*d)} ${Wt(h-a*d)} L${Wt(e.x+c*d)} ${Wt(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)),A=Math.min(1/R,w/2,v/2);return{start:{x:g.x+C.x*A,y:g.y+C.y*A},end:{x:g.x+S.x*A,y:g.y+S.y*A},radius:A*R}}).map((g,y)=>`${y?"L":"M"}${vt(g.start)} A${Wt(g.radius)} ${Wt(g.radius)} 0 0 1 ${vt(g.end)}`).join(" ")+" Z"}function jr(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 y1(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 Yb(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=_t(i,l,n.srcDist);u=_t(i,l,n.srcDist+n.arrowGap),p=Gt(m,l,n.arrowSize,n.headShape)}else u=_t(i,l,n.srcDist);if(n.arrowAt==="target"){const m=_t(a,d,n.tgtDist);h=_t(a,d,n.tgtDist+n.arrowGap),p=Gt(m,d,n.arrowSize,n.headShape)}else h=_t(a,d,n.tgtDist);return Ao(u,c,h,p,n.radius,n.labelTargetLength,n.labelFraction)}function Ao(e,r,t,n,o,i,s){var h;const a=[e,...r,t],c=[];let l=`M${vt(e)}`;for(let p=1;p<a.length-1;p++){const m=y1(a[p-1],a[p],a[p+1],o);c.push(m),m.r===0?l+=` L${vt(m.b)}`:l+=` L${vt(m.p1)} Q${vt(m.b)} ${vt(m.p2)}`}l+=` L${vt(t)}`;let d;const u=r.length;if(u===0)d={x:(e.x+t.x)/2,y:(e.y+t.y)/2,angle:jr(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:jr(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:jr(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:jr(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:jr(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:jr(m,g)})}return{d:l,arrow:n,label:d}}function ef(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"?_t(c,p[0],s.arrowGap):c,g=s.arrowAt==="target"?_t(l,p[p.length-1],s.arrowGap):l,y=s.arrowAt==="source"?Gt(c,p[0],s.arrowSize,s.headShape):s.arrowAt==="target"?Gt(l,p[p.length-1],s.arrowSize,s.headShape):void 0;return Ao(m,p,g,y,s.radius)}function tf(e,r,t,n,o){return Yb(h1(e,r,t,n),e,r,o)}function rf(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 m1(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"?_t(e,a,n.arrowGap):e,d=n.arrowAt==="target"?_t(r,c,n.arrowGap):r;return{d:`M${vt(l)} C${vt(a)} ${vt(c)} ${vt(d)}`,arrow:n.arrowAt==="source"?Gt(e,a,n.arrowSize,n.headShape):n.arrowAt==="target"?Gt(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:jr(d.x+c.x-a.x-l.x,d.y+c.y-a.y-l.y)}}}function Qb(e,r,t){const n=t.arrowAt==="source"?_t(e,r,t.arrowGap):e,o=t.arrowAt==="target"?_t(r,e,t.arrowGap):r,i=t.arrowAt==="source"?Gt(e,r,t.arrowSize,t.headShape):t.arrowAt==="target"?Gt(r,e,t.arrowSize,t.headShape):void 0;return Ao(n,[],o,i,0)}function b1(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=_t(g,h,t.srcDist),w=_t(y,p,t.tgtDist),v;if(t.arrowAt==="target"){const S=w;w=_t(y,p,t.tgtDist+t.arrowGap),v=Gt(S,p,t.arrowSize,t.headShape)}else if(t.arrowAt==="source"){const S=x;x=_t(g,h,t.srcDist+t.arrowGap),v=Gt(S,h,t.arrowSize,t.headShape)}return{d:`M${vt(x)} Q${vt(h)} ${vt(b)} Q${vt(p)} ${vt(w)}`,arrow:v,label:{x:b.x,y:b.y,angle:jr(p.x-h.x,p.y-h.y)}}}const qr=e=>Math.round(e*1e3)/1e3;function ex(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:qr((a.a*y.x+a.c*y.y+a.e-t.left)/n),y:qr((a.b*y.x+a.d*y.y+a.f-t.top)/n)}}):void 0;return{left:qr((o.left-t.left)/n),top:qr((o.top-t.top)/n),width:r instanceof HTMLElement?r.offsetWidth:qr(o.width/n),height:r instanceof HTMLElement?r.offsetHeight:qr(o.height/n),radius:parseFloat(getComputedStyle(r).borderTopLeftRadius)||0,...i!=null&&i.height?{captionBottom:qr((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 x1(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=Xb(b,v,S);return{...w,anchor:E,top:E.y,height:0}}))}return l}function nf(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 Pr='"Helvetica Neue", Helvetica, sans-serif';let Cn;const oo=new Map;function Ro(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 v1(e,r,t){const n=[];for(const o of String(e).split(`
|
|
280
|
-
`)){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||Ro(c,r)<=t?s=c:(n.push(s),s=a)}n.push(s)}return n}const of=e=>e.stopPropagation();function w1({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?Ro(t,`bold ${i.fontSize}px ${Pr}`):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(Oe,{"aria-label":"Show icon",icon:f.jsx(Z.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:of,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:Pr,style:{fontSize:i.fontSize,fontWeight:"bold",fontFamily:Pr},textAnchor:"middle",dominantBaseline:"central",children:t})]})]}):null;return f.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:of,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?Vr.createPortal(b,n):b]})}const C1=j.memo(w1),yo=45,tx=70,Fr=15,rx=50;function nx(e,r,t=yo){const n=`${t}px ${Pr}`,o=e?v1(e,n,200*t/yo):[],i=r?48+(o.length?12:0):0,s=i+Math.max(0,...o.map(l=>Ro(l,n))),a=Math.max(o.length*t,r?48:0),c=o.length||r?2*Fr:0;return{lines:o,iconWidth:i,contentWidth:s,contentHeight:a,width:s+c,height:a+c}}const Ln=6,ox=3,Zd=.3,S1=8,Xd=Math.max(Math.pow(Ln*13.37,.9),29)*ox-S1/Zd,ix=Ln*ox*2,co=80,j1=2*co+Xd*Zd+100,E1=36+2*Math.max(80,ix+Xd*Zd);function Ad(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function Rd(e,r){return r==="auto"||(r==="properties"?Ad(e):!Ad(e))}function cr(e,r,t){return t!=="properties"||e!=="root"||r.some(n=>(n.source===e||n.target===e)&&Ad(n))}function _1(e,r,t,n=!1,o){if(!n)return{nodes:e,edges:r};const i=e.filter(a=>cr(a.id,r,t)&&(!o||o.has(a.id))),s=new Set(i.map(a=>a.id));return{nodes:i,edges:r.filter(a=>Rd(a,t)&&s.has(a.source)&&s.has(a.target))}}const k1=500,P1="32 18",A1=e=>e.stopPropagation();function R1({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:A,dashed:I,animated:M,inverted:k,loopIndex:_=0,onSelect:N}){const O=n==null?void 0:n.icon,W=y?yo:tx,{lines:T,iconWidth:Y,contentWidth:he,contentHeight:K}=j.useMemo(()=>nx(A,O,W),[A,O,W]),re=j.useMemo(()=>{const ge={srcDist:co,tgtDist:co,arrowGap:ix,arrowSize:Xd,headShape:y&&(k?h!==void 0||m:p!==void 0||g)?"square":"triangle",radius:s??(w?40:k1),arrowAt:k?"source":"target",labelTargetLength:w?he+2*Fr:void 0,labelFraction:w?v:void 0},ce=h!==void 0||p!==void 0||!!m||!!g,U=rf(c,l,b,h,p,0),te=h===void 0&&p===void 0&&(b==="downward"||b==="upward"),pe=m??{...U.sourcePoint,side:te?b==="upward"?"top":"bottom":b==="leftward"?"left":"right"},ve=g??{...U.targetPoint,side:te?b==="upward"?"bottom":"top":b==="leftward"?"right":"left"},Ne=c.x===l.x&&c.y===l.y,Je=m||g?g1(pe,ve,{...ge,srcDist:18,tgtDist:18},i):ce?ef(c,l,b,h,p,x,{...ge,srcDist:18,tgtDist:18,radius:s??Math.min(ge.radius,40)}):Ne?b1(c,_,{...ge,srcDist:0,tgtDist:0}):tf(c,l,b,x,ge);if(!Je)return null;const tt=rf(c,l,b,h,p,ce?18:co);m&&(tt.sourcePoint=Qr(m,18)),g&&(tt.targetPoint=Qr(g,18));const Ye=Object.prototype.hasOwnProperty.call(a??{},i)?a==null?void 0:a[i]:void 0;if(Ye){const Ue={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return Ye({edge:n??{id:e,source:"",target:""},source:{...c},target:{...l},...tt,direction:Ue[b],sourceY:h,targetY:p,inverted:!!k,defaultGeometry:Je})??Je}return Ne||m||g?Je:i==="straight"?ce?Qb(tt.sourcePoint,tt.targetPoint,ge):Yb([c,l],c,l,ge):i==="bezier"?m1(tt.sourcePoint,tt.targetPoint,ce?b==="leftward"?"leftward":"rightward":b,ge):i==="orthogonal"?ce?ef(c,l,b,h,p,x,{...ge,srcDist:18,tgtDist:18,radius:0}):tf(c,l,b,x,{...ge,radius:0}):Je},[c,e,n,i,s,a,l,y,h,p,m,g,b,x,k,_,w,v,he]);if(!re)return null;const G=(b==="rightward"||b==="leftward")&&!Object.prototype.hasOwnProperty.call(a??{},i)&&!(y&&(h!==void 0||p!==void 0||m||g)),ne=G?`translate(${re.label.x} ${re.label.y-K/2-2*Fr})`:`translate(${re.label.x} ${re.label.y}) rotate(${re.label.angle}) translate(${b==="downward"||b==="upward"||w||Object.prototype.hasOwnProperty.call(a??{},i)?0:rx} 0)`,q=o!=null&&o.startsWith("Unverified:")?"#b45309":"#dc2626",z=o?q:C,H=o?f.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":o,transform:`translate(${re.label.x} ${re.label.y-T.length*W/2-55})`,children:[f.jsx("title",{children:o}),f.jsx(dr,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:q})]}):null,V=M&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",le=!V&&(I||M)?P1:void 0,X=M&&!V?`flow-sdk-edge-anim${k?" flow-sdk-edge-anim-rev":""}`:void 0;let ue=null;const oe=r?{"--flow-edge-reveal-duration":`${r.durationMs??600}ms`,"--flow-edge-reveal-state":r.paused?"paused":"running"}:void 0;if(T.length||O){const ge=he,ce=K;ue=f.jsxs("g",{className:`flow-sdk-edge-label${r?" flow-sdk-edge-reveal-end":""}`,style:oe,"data-label-transform":ne,"data-label-horizontal":G||void 0,"data-edge-id":e,"data-source-property":d,"data-target-property":u,transform:ne,children:[f.jsx("rect",{x:-ge/2-Fr,y:-ce/2-Fr,width:ge+2*Fr,height:ce+2*Fr,fill:C==="transparent"?"transparent":E}),f.jsx("text",{fill:C,fontSize:W,style:{fontSize:W,fontFamily:Pr},fontFamily:Pr,textAnchor:"middle",dominantBaseline:"central",children:T.map((U,te)=>f.jsx("tspan",{x:Y/2,y:(te-(T.length-1)/2)*W,children:U},te))}),O&&f.jsxs("g",{className:"flow-sdk-edge-icon",opacity:C==="transparent"?0:1,children:[f.jsx("title",{children:A?`Edge icon: ${A}`:"Edge icon"}),f.jsx("rect",{x:-ge/2,y:-24,width:48,height:48,fill:"transparent"}),f.jsx(dr,{name:O,svg:!0,size:48,x:-ge/2,y:-24,color:C})]})]})}const de=f.jsxs(f.Fragment,{children:[f.jsx("path",{d:re.d,fill:"none",stroke:z,strokeWidth:Ln,strokeOpacity:V?.35:void 0,strokeDasharray:le,className:X}),V&&f.jsx(s1,{path:re.d,color:z,width:Ln*1.6,reversed:k})]});return f.jsxs("g",{className:"flow-sdk-edge",style:oe,"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:A1,onClick:ge=>{ge.stopPropagation(),N==null||N(e)},children:[r?f.jsx(i1,{path:re.d,width:Ln*4,reversed:k,onComplete:()=>t==null?void 0:t(e),children:de}):de,re.arrow&&f.jsx("path",{className:r?"flow-sdk-edge-reveal-end":void 0,d:re.arrow,fill:o?q:S??z}),R&&ue?Vr.createPortal(ue,R):ue,R&&H?Vr.createPortal(H,R):H,f.jsx("path",{className:"flow-sdk-edge-hit",d:re.d,fill:"none",stroke:"transparent"})]})}const af=j.memo(R1);var io=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function M1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Yd(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 ni,sf;function T1(){if(sf)return ni;sf=1;function e(){this.__data__=[],this.size=0}return ni=e,ni}var oi,cf;function fn(){if(cf)return oi;cf=1;function e(r,t){return r===t||r!==r&&t!==t}return oi=e,oi}var ii,lf;function Mo(){if(lf)return ii;lf=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 ii=r,ii}var ai,df;function I1(){if(df)return ai;df=1;var e=Mo(),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 ai=n,ai}var si,uf;function N1(){if(uf)return si;uf=1;var e=Mo();function r(t){var n=this.__data__,o=e(n,t);return o<0?void 0:n[o][1]}return si=r,si}var ci,ff;function O1(){if(ff)return ci;ff=1;var e=Mo();function r(t){return e(this.__data__,t)>-1}return ci=r,ci}var li,hf;function $1(){if(hf)return li;hf=1;var e=Mo();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 li=r,li}var di,pf;function To(){if(pf)return di;pf=1;var e=T1(),r=I1(),t=N1(),n=O1(),o=$1();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 ui,gf;function q1(){if(gf)return ui;gf=1;var e=To();function r(){this.__data__=new e,this.size=0}return ui=r,ui}var fi,yf;function L1(){if(yf)return fi;yf=1;function e(r){var t=this.__data__,n=t.delete(r);return this.size=t.size,n}return fi=e,fi}var hi,mf;function F1(){if(mf)return hi;mf=1;function e(r){return this.__data__.get(r)}return hi=e,hi}var pi,bf;function z1(){if(bf)return pi;bf=1;function e(r){return this.__data__.has(r)}return pi=e,pi}var gi,xf;function ax(){if(xf)return gi;xf=1;var e=typeof io=="object"&&io&&io.Object===Object&&io;return gi=e,gi}var yi,vf;function er(){if(vf)return yi;vf=1;var e=ax(),r=typeof self=="object"&&self&&self.Object===Object&&self,t=e||r||Function("return this")();return yi=t,yi}var mi,wf;function hn(){if(wf)return mi;wf=1;var e=er(),r=e.Symbol;return mi=r,mi}var bi,Cf;function B1(){if(Cf)return bi;Cf=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 bi=i,bi}var xi,Sf;function D1(){if(Sf)return xi;Sf=1;var e=Object.prototype,r=e.toString;function t(n){return r.call(n)}return xi=t,xi}var vi,jf;function Hr(){if(jf)return vi;jf=1;var e=hn(),r=B1(),t=D1(),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 vi=s,vi}var wi,Ef;function Ht(){if(Ef)return wi;Ef=1;function e(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}return wi=e,wi}var Ci,_f;function Un(){if(_f)return Ci;_f=1;var e=Hr(),r=Ht(),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 Ci=s,Ci}var Si,kf;function W1(){if(kf)return Si;kf=1;var e=er(),r=e["__core-js_shared__"];return Si=r,Si}var ji,Pf;function V1(){if(Pf)return ji;Pf=1;var e=W1(),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 ji=t,ji}var Ei,Af;function sx(){if(Af)return Ei;Af=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 Ei=t,Ei}var _i,Rf;function G1(){if(Rf)return _i;Rf=1;var e=Un(),r=V1(),t=Ht(),n=sx(),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 _i=u,_i}var ki,Mf;function H1(){if(Mf)return ki;Mf=1;function e(r,t){return r==null?void 0:r[t]}return ki=e,ki}var Pi,Tf;function Ur(){if(Tf)return Pi;Tf=1;var e=G1(),r=H1();function t(n,o){var i=r(n,o);return e(i)?i:void 0}return Pi=t,Pi}var Ai,If;function Qd(){if(If)return Ai;If=1;var e=Ur(),r=er(),t=e(r,"Map");return Ai=t,Ai}var Ri,Nf;function Io(){if(Nf)return Ri;Nf=1;var e=Ur(),r=e(Object,"create");return Ri=r,Ri}var Mi,Of;function U1(){if(Of)return Mi;Of=1;var e=Io();function r(){this.__data__=e?e(null):{},this.size=0}return Mi=r,Mi}var Ti,$f;function K1(){if($f)return Ti;$f=1;function e(r){var t=this.has(r)&&delete this.__data__[r];return this.size-=t?1:0,t}return Ti=e,Ti}var Ii,qf;function J1(){if(qf)return Ii;qf=1;var e=Io(),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 Ii=o,Ii}var Ni,Lf;function Z1(){if(Lf)return Ni;Lf=1;var e=Io(),r=Object.prototype,t=r.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:t.call(i,o)}return Ni=n,Ni}var Oi,Ff;function X1(){if(Ff)return Oi;Ff=1;var e=Io(),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 Oi=t,Oi}var $i,zf;function Y1(){if(zf)return $i;zf=1;var e=U1(),r=K1(),t=J1(),n=Z1(),o=X1();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,$i=i,$i}var qi,Bf;function Q1(){if(Bf)return qi;Bf=1;var e=Y1(),r=To(),t=Qd();function n(){this.size=0,this.__data__={hash:new e,map:new(t||r),string:new e}}return qi=n,qi}var Li,Df;function eC(){if(Df)return Li;Df=1;function e(r){var t=typeof r;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?r!=="__proto__":r===null}return Li=e,Li}var Fi,Wf;function No(){if(Wf)return Fi;Wf=1;var e=eC();function r(t,n){var o=t.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return Fi=r,Fi}var zi,Vf;function tC(){if(Vf)return zi;Vf=1;var e=No();function r(t){var n=e(this,t).delete(t);return this.size-=n?1:0,n}return zi=r,zi}var Bi,Gf;function rC(){if(Gf)return Bi;Gf=1;var e=No();function r(t){return e(this,t).get(t)}return Bi=r,Bi}var Di,Hf;function nC(){if(Hf)return Di;Hf=1;var e=No();function r(t){return e(this,t).has(t)}return Di=r,Di}var Wi,Uf;function oC(){if(Uf)return Wi;Uf=1;var e=No();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 Wi=r,Wi}var Vi,Kf;function eu(){if(Kf)return Vi;Kf=1;var e=Q1(),r=tC(),t=rC(),n=nC(),o=oC();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,Vi=i,Vi}var Gi,Jf;function iC(){if(Jf)return Gi;Jf=1;var e=To(),r=Qd(),t=eu(),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 Gi=o,Gi}var Hi,Zf;function Oo(){if(Zf)return Hi;Zf=1;var e=To(),r=q1(),t=L1(),n=F1(),o=z1(),i=iC();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,Hi=s,Hi}var Ui,Xf;function tu(){if(Xf)return Ui;Xf=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 Ui=e,Ui}var Ki,Yf;function cx(){if(Yf)return Ki;Yf=1;var e=Ur(),r=(function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch{}})();return Ki=r,Ki}var Ji,Qf;function $o(){if(Qf)return Ji;Qf=1;var e=cx();function r(t,n,o){n=="__proto__"&&e?e(t,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):t[n]=o}return Ji=r,Ji}var Zi,eh;function qo(){if(eh)return Zi;eh=1;var e=$o(),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 Zi=o,Zi}var Xi,th;function Kn(){if(th)return Xi;th=1;var e=qo(),r=$o();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 Xi=t,Xi}var Yi,rh;function aC(){if(rh)return Yi;rh=1;function e(r,t){for(var n=-1,o=Array(r);++n<r;)o[n]=t(n);return o}return Yi=e,Yi}var Qi,nh;function ur(){if(nh)return Qi;nh=1;function e(r){return r!=null&&typeof r=="object"}return Qi=e,Qi}var ea,oh;function sC(){if(oh)return ea;oh=1;var e=Hr(),r=ur(),t="[object Arguments]";function n(o){return r(o)&&e(o)==t}return ea=n,ea}var ta,ih;function Jn(){if(ih)return ta;ih=1;var e=sC(),r=ur(),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 ta=i,ta}var ra,ah;function St(){if(ah)return ra;ah=1;var e=Array.isArray;return ra=e,ra}var kn={exports:{}},na,sh;function cC(){if(sh)return na;sh=1;function e(){return!1}return na=e,na}kn.exports;var ch;function pn(){return ch||(ch=1,(function(e,r){var t=er(),n=cC(),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 oa,lh;function Lo(){if(lh)return oa;lh=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 oa=t,oa}var ia,dh;function ru(){if(dh)return ia;dh=1;var e=9007199254740991;function r(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=e}return ia=r,ia}var aa,uh;function lC(){if(uh)return aa;uh=1;var e=Hr(),r=ru(),t=ur(),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]",A="[object Uint16Array]",I="[object Uint32Array]",M={};M[x]=M[w]=M[v]=M[C]=M[S]=M[E]=M[R]=M[A]=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 aa=k,aa}var sa,fh;function Fo(){if(fh)return sa;fh=1;function e(r){return function(t){return r(t)}}return sa=e,sa}var Pn={exports:{}};Pn.exports;var hh;function nu(){return hh||(hh=1,(function(e,r){var t=ax(),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 ca,ph;function Zn(){if(ph)return ca;ph=1;var e=lC(),r=Fo(),t=nu(),n=t&&t.isTypedArray,o=n?r(n):e;return ca=o,ca}var la,gh;function lx(){if(gh)return la;gh=1;var e=aC(),r=Jn(),t=St(),n=pn(),o=Lo(),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 la=c,la}var da,yh;function zo(){if(yh)return da;yh=1;var e=Object.prototype;function r(t){var n=t&&t.constructor,o=typeof n=="function"&&n.prototype||e;return t===o}return da=r,da}var ua,mh;function dx(){if(mh)return ua;mh=1;function e(r,t){return function(n){return r(t(n))}}return ua=e,ua}var fa,bh;function dC(){if(bh)return fa;bh=1;var e=dx(),r=e(Object.keys,Object);return fa=r,fa}var ha,xh;function ou(){if(xh)return ha;xh=1;var e=zo(),r=dC(),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 ha=o,ha}var pa,vh;function br(){if(vh)return pa;vh=1;var e=Un(),r=ru();function t(n){return n!=null&&r(n.length)&&!e(n)}return pa=t,pa}var ga,wh;function Ir(){if(wh)return ga;wh=1;var e=lx(),r=ou(),t=br();function n(o){return t(o)?e(o):r(o)}return ga=n,ga}var ya,Ch;function uC(){if(Ch)return ya;Ch=1;var e=Kn(),r=Ir();function t(n,o){return n&&e(o,r(o),n)}return ya=t,ya}var ma,Sh;function fC(){if(Sh)return ma;Sh=1;function e(r){var t=[];if(r!=null)for(var n in Object(r))t.push(n);return t}return ma=e,ma}var ba,jh;function hC(){if(jh)return ba;jh=1;var e=Ht(),r=zo(),t=fC(),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 ba=i,ba}var xa,Eh;function Kr(){if(Eh)return xa;Eh=1;var e=lx(),r=hC(),t=br();function n(o){return t(o)?e(o,!0):r(o)}return xa=n,xa}var va,_h;function pC(){if(_h)return va;_h=1;var e=Kn(),r=Kr();function t(n,o){return n&&e(o,r(o),n)}return va=t,va}var An={exports:{}};An.exports;var kh;function ux(){return kh||(kh=1,(function(e,r){var t=er(),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 wa,Ph;function fx(){if(Ph)return wa;Ph=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 wa=e,wa}var Ca,Ah;function hx(){if(Ah)return Ca;Ah=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 Ca=e,Ca}var Sa,Rh;function px(){if(Rh)return Sa;Rh=1;function e(){return[]}return Sa=e,Sa}var ja,Mh;function iu(){if(Mh)return ja;Mh=1;var e=hx(),r=px(),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 ja=i,ja}var Ea,Th;function gC(){if(Th)return Ea;Th=1;var e=Kn(),r=iu();function t(n,o){return e(n,r(n),o)}return Ea=t,Ea}var _a,Ih;function au(){if(Ih)return _a;Ih=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 _a=e,_a}var ka,Nh;function Bo(){if(Nh)return ka;Nh=1;var e=dx(),r=e(Object.getPrototypeOf,Object);return ka=r,ka}var Pa,Oh;function gx(){if(Oh)return Pa;Oh=1;var e=au(),r=Bo(),t=iu(),n=px(),o=Object.getOwnPropertySymbols,i=o?function(s){for(var a=[];s;)e(a,t(s)),s=r(s);return a}:n;return Pa=i,Pa}var Aa,$h;function yC(){if($h)return Aa;$h=1;var e=Kn(),r=gx();function t(n,o){return e(n,r(n),o)}return Aa=t,Aa}var Ra,qh;function yx(){if(qh)return Ra;qh=1;var e=au(),r=St();function t(n,o,i){var s=o(n);return r(n)?s:e(s,i(n))}return Ra=t,Ra}var Ma,Lh;function mx(){if(Lh)return Ma;Lh=1;var e=yx(),r=iu(),t=Ir();function n(o){return e(o,t,r)}return Ma=n,Ma}var Ta,Fh;function mC(){if(Fh)return Ta;Fh=1;var e=yx(),r=gx(),t=Kr();function n(o){return e(o,t,r)}return Ta=n,Ta}var Ia,zh;function bC(){if(zh)return Ia;zh=1;var e=Ur(),r=er(),t=e(r,"DataView");return Ia=t,Ia}var Na,Bh;function xC(){if(Bh)return Na;Bh=1;var e=Ur(),r=er(),t=e(r,"Promise");return Na=t,Na}var Oa,Dh;function bx(){if(Dh)return Oa;Dh=1;var e=Ur(),r=er(),t=e(r,"Set");return Oa=t,Oa}var $a,Wh;function vC(){if(Wh)return $a;Wh=1;var e=Ur(),r=er(),t=e(r,"WeakMap");return $a=t,$a}var qa,Vh;function gn(){if(Vh)return qa;Vh=1;var e=bC(),r=Qd(),t=xC(),n=bx(),o=vC(),i=Hr(),s=sx(),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}),qa=x,qa}var La,Gh;function wC(){if(Gh)return La;Gh=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 La=t,La}var Fa,Hh;function xx(){if(Hh)return Fa;Hh=1;var e=er(),r=e.Uint8Array;return Fa=r,Fa}var za,Uh;function su(){if(Uh)return za;Uh=1;var e=xx();function r(t){var n=new t.constructor(t.byteLength);return new e(n).set(new e(t)),n}return za=r,za}var Ba,Kh;function CC(){if(Kh)return Ba;Kh=1;var e=su();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.byteLength)}return Ba=r,Ba}var Da,Jh;function SC(){if(Jh)return Da;Jh=1;var e=/\w*$/;function r(t){var n=new t.constructor(t.source,e.exec(t));return n.lastIndex=t.lastIndex,n}return Da=r,Da}var Wa,Zh;function jC(){if(Zh)return Wa;Zh=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 Wa=n,Wa}var Va,Xh;function vx(){if(Xh)return Va;Xh=1;var e=su();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}return Va=r,Va}var Ga,Yh;function EC(){if(Yh)return Ga;Yh=1;var e=su(),r=CC(),t=SC(),n=jC(),o=vx(),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(A,I,M){var k=A.constructor;switch(I){case p:return e(A);case i:case s:return new k(+A);case m:return r(A,M);case g:case y:case b:case x:case w:case v:case C:case S:case E:return o(A,M);case a:return new k;case c:case u:return new k(A);case l:return t(A);case d:return new k;case h:return n(A)}}return Ga=R,Ga}var Ha,Qh;function wx(){if(Qh)return Ha;Qh=1;var e=Ht(),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 Ha=t,Ha}var Ua,ep;function Cx(){if(ep)return Ua;ep=1;var e=wx(),r=Bo(),t=zo();function n(o){return typeof o.constructor=="function"&&!t(o)?e(r(o)):{}}return Ua=n,Ua}var Ka,tp;function _C(){if(tp)return Ka;tp=1;var e=gn(),r=ur(),t="[object Map]";function n(o){return r(o)&&e(o)==t}return Ka=n,Ka}var Ja,rp;function kC(){if(rp)return Ja;rp=1;var e=_C(),r=Fo(),t=nu(),n=t&&t.isMap,o=n?r(n):e;return Ja=o,Ja}var Za,np;function PC(){if(np)return Za;np=1;var e=gn(),r=ur(),t="[object Set]";function n(o){return r(o)&&e(o)==t}return Za=n,Za}var Xa,op;function AC(){if(op)return Xa;op=1;var e=PC(),r=Fo(),t=nu(),n=t&&t.isSet,o=n?r(n):e;return Xa=o,Xa}var Ya,ip;function Sx(){if(ip)return Ya;ip=1;var e=Oo(),r=tu(),t=qo(),n=uC(),o=pC(),i=ux(),s=fx(),a=gC(),c=yC(),l=mx(),d=mC(),u=gn(),h=wC(),p=EC(),m=Cx(),g=St(),y=pn(),b=kC(),x=Ht(),w=AC(),v=Ir(),C=Kr(),S=1,E=2,R=4,A="[object Arguments]",I="[object Array]",M="[object Boolean]",k="[object Date]",_="[object Error]",N="[object Function]",O="[object GeneratorFunction]",W="[object Map]",T="[object Number]",Y="[object Object]",he="[object RegExp]",K="[object Set]",re="[object String]",G="[object Symbol]",ne="[object WeakMap]",q="[object ArrayBuffer]",z="[object DataView]",H="[object Float32Array]",V="[object Float64Array]",le="[object Int8Array]",X="[object Int16Array]",ue="[object Int32Array]",oe="[object Uint8Array]",de="[object Uint8ClampedArray]",ge="[object Uint16Array]",ce="[object Uint32Array]",U={};U[A]=U[I]=U[q]=U[z]=U[M]=U[k]=U[H]=U[V]=U[le]=U[X]=U[ue]=U[W]=U[T]=U[Y]=U[he]=U[K]=U[re]=U[G]=U[oe]=U[de]=U[ge]=U[ce]=!0,U[_]=U[N]=U[ne]=!1;function te(pe,ve,Ne,Je,tt,Ye){var Ue,lt=ve&S,be=ve&E,Ae=ve&R;if(Ne&&(Ue=tt?Ne(pe,Je,tt,Ye):Ne(pe)),Ue!==void 0)return Ue;if(!x(pe))return pe;var ie=g(pe);if(ie){if(Ue=h(pe),!lt)return s(pe,Ue)}else{var ae=u(pe),Ie=ae==N||ae==O;if(y(pe))return i(pe,lt);if(ae==Y||ae==A||Ie&&!tt){if(Ue=be||Ie?{}:m(pe),!lt)return be?c(pe,o(Ue,pe)):a(pe,n(Ue,pe))}else{if(!U[ae])return tt?pe:{};Ue=p(pe,ae,lt)}}Ye||(Ye=new e);var et=Ye.get(pe);if(et)return et;Ye.set(pe,Ue),w(pe)?pe.forEach(function(at){Ue.add(te(at,ve,Ne,at,pe,Ye))}):b(pe)&&pe.forEach(function(at,He){Ue.set(He,te(at,ve,Ne,He,pe,Ye))});var Ee=Ae?be?d:l:be?C:v,Le=ie?void 0:Ee(pe);return r(Le||pe,function(at,He){Le&&(He=at,at=pe[He]),t(Ue,He,te(at,ve,Ne,He,pe,Ye))}),Ue}return Ya=te,Ya}var Qa,ap;function RC(){if(ap)return Qa;ap=1;var e=Sx(),r=4;function t(n){return e(n,r)}return Qa=t,Qa}var es,sp;function cu(){if(sp)return es;sp=1;function e(r){return function(){return r}}return es=e,es}var ts,cp;function MC(){if(cp)return ts;cp=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 ts=e,ts}var rs,lp;function lu(){if(lp)return rs;lp=1;var e=MC(),r=e();return rs=r,rs}var ns,dp;function du(){if(dp)return ns;dp=1;var e=lu(),r=Ir();function t(n,o){return n&&e(n,o,r)}return ns=t,ns}var os,up;function TC(){if(up)return os;up=1;var e=br();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 os=r,os}var is,fp;function Do(){if(fp)return is;fp=1;var e=du(),r=TC(),t=r(e);return is=t,is}var as,hp;function Jr(){if(hp)return as;hp=1;function e(r){return r}return as=e,as}var ss,pp;function jx(){if(pp)return ss;pp=1;var e=Jr();function r(t){return typeof t=="function"?t:e}return ss=r,ss}var cs,gp;function Ex(){if(gp)return cs;gp=1;var e=tu(),r=Do(),t=jx(),n=St();function o(i,s){var a=n(i)?e:r;return a(i,t(s))}return cs=o,cs}var ls,yp;function _x(){return yp||(yp=1,ls=Ex()),ls}var ds,mp;function IC(){if(mp)return ds;mp=1;var e=Do();function r(t,n){var o=[];return e(t,function(i,s,a){n(i,s,a)&&o.push(i)}),o}return ds=r,ds}var us,bp;function NC(){if(bp)return us;bp=1;var e="__lodash_hash_undefined__";function r(t){return this.__data__.set(t,e),this}return us=r,us}var fs,xp;function OC(){if(xp)return fs;xp=1;function e(r){return this.__data__.has(r)}return fs=e,fs}var hs,vp;function kx(){if(vp)return hs;vp=1;var e=eu(),r=NC(),t=OC();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,hs=n,hs}var ps,wp;function $C(){if(wp)return ps;wp=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 ps=e,ps}var gs,Cp;function Px(){if(Cp)return gs;Cp=1;function e(r,t){return r.has(t)}return gs=e,gs}var ys,Sp;function Ax(){if(Sp)return ys;Sp=1;var e=kx(),r=$C(),t=Px(),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 ys=i,ys}var ms,jp;function qC(){if(jp)return ms;jp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o,i){n[++t]=[i,o]}),n}return ms=e,ms}var bs,Ep;function uu(){if(Ep)return bs;Ep=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o){n[++t]=o}),n}return bs=e,bs}var xs,_p;function LC(){if(_p)return xs;_p=1;var e=hn(),r=xx(),t=fn(),n=Ax(),o=qC(),i=uu(),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,A,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=A&s;if(_||(_=i),S.size!=E.size&&!N)return!1;var O=k.get(S);if(O)return O==E;A|=a,k.set(S,E);var W=n(_(S),_(E),A,I,M,k);return k.delete(S),W;case y:if(v)return v.call(S)==v.call(E)}return!1}return xs=C,xs}var vs,kp;function FC(){if(kp)return vs;kp=1;var e=mx(),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 A=i.constructor,I=s.constructor;A!=I&&"constructor"in i&&"constructor"in s&&!(typeof A=="function"&&A instanceof A&&typeof I=="function"&&I instanceof I)&&(v=!1)}return d.delete(i),d.delete(s),v}return vs=o,vs}var ws,Pp;function zC(){if(Pp)return ws;Pp=1;var e=Oo(),r=Ax(),t=LC(),n=FC(),o=gn(),i=St(),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 A=E==u,I=R==u,M=E==R;if(M&&s(g)){if(!s(y))return!1;C=!0,A=!1}if(M&&!A)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=A&&p.call(g,"__wrapped__"),_=I&&p.call(y,"__wrapped__");if(k||_){var N=k?g.value():g,O=_?y.value():y;return v||(v=new e),w(N,O,b,x,v)}}return M?(v||(v=new e),n(g,y,b,x,w,v)):!1}return ws=m,ws}var Cs,Ap;function Rx(){if(Ap)return Cs;Ap=1;var e=zC(),r=ur();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 Cs=t,Cs}var Ss,Rp;function BC(){if(Rp)return Ss;Rp=1;var e=Oo(),r=Rx(),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 Ss=o,Ss}var js,Mp;function Mx(){if(Mp)return js;Mp=1;var e=Ht();function r(t){return t===t&&!e(t)}return js=r,js}var Es,Tp;function DC(){if(Tp)return Es;Tp=1;var e=Mx(),r=Ir();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 Es=t,Es}var _s,Ip;function Tx(){if(Ip)return _s;Ip=1;function e(r,t){return function(n){return n==null?!1:n[r]===t&&(t!==void 0||r in Object(n))}}return _s=e,_s}var ks,Np;function WC(){if(Np)return ks;Np=1;var e=BC(),r=DC(),t=Tx();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 ks=n,ks}var Ps,Op;function yn(){if(Op)return Ps;Op=1;var e=Hr(),r=ur(),t="[object Symbol]";function n(o){return typeof o=="symbol"||r(o)&&e(o)==t}return Ps=n,Ps}var As,$p;function fu(){if($p)return As;$p=1;var e=St(),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 As=o,As}var Rs,qp;function VC(){if(qp)return Rs;qp=1;var e=eu(),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,Rs=t,Rs}var Ms,Lp;function GC(){if(Lp)return Ms;Lp=1;var e=VC(),r=500;function t(n){var o=e(n,function(s){return i.size===r&&i.clear(),s}),i=o.cache;return o}return Ms=t,Ms}var Ts,Fp;function HC(){if(Fp)return Ts;Fp=1;var e=GC(),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 Ts=n,Ts}var Is,zp;function Wo(){if(zp)return Is;zp=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 Is=e,Is}var Ns,Bp;function UC(){if(Bp)return Ns;Bp=1;var e=hn(),r=Wo(),t=St(),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 Ns=s,Ns}var Os,Dp;function Ix(){if(Dp)return Os;Dp=1;var e=UC();function r(t){return t==null?"":e(t)}return Os=r,Os}var $s,Wp;function Vo(){if(Wp)return $s;Wp=1;var e=St(),r=fu(),t=HC(),n=Ix();function o(i,s){return e(i)?i:r(i,s)?[i]:t(n(i))}return $s=o,$s}var qs,Vp;function Xn(){if(Vp)return qs;Vp=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 qs=r,qs}var Ls,Gp;function Go(){if(Gp)return Ls;Gp=1;var e=Vo(),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 Ls=t,Ls}var Fs,Hp;function KC(){if(Hp)return Fs;Hp=1;var e=Go();function r(t,n,o){var i=t==null?void 0:e(t,n);return i===void 0?o:i}return Fs=r,Fs}var zs,Up;function JC(){if(Up)return zs;Up=1;function e(r,t){return r!=null&&t in Object(r)}return zs=e,zs}var Bs,Kp;function Nx(){if(Kp)return Bs;Kp=1;var e=Vo(),r=Jn(),t=St(),n=Lo(),o=ru(),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 Bs=s,Bs}var Ds,Jp;function Ox(){if(Jp)return Ds;Jp=1;var e=JC(),r=Nx();function t(n,o){return n!=null&&r(n,o,e)}return Ds=t,Ds}var Ws,Zp;function ZC(){if(Zp)return Ws;Zp=1;var e=Rx(),r=KC(),t=Ox(),n=fu(),o=Mx(),i=Tx(),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 Ws=l,Ws}var Vs,Xp;function $x(){if(Xp)return Vs;Xp=1;function e(r){return function(t){return t==null?void 0:t[r]}}return Vs=e,Vs}var Gs,Yp;function XC(){if(Yp)return Gs;Yp=1;var e=Go();function r(t){return function(n){return e(n,t)}}return Gs=r,Gs}var Hs,Qp;function YC(){if(Qp)return Hs;Qp=1;var e=$x(),r=XC(),t=fu(),n=Xn();function o(i){return t(i)?e(n(i)):r(i)}return Hs=o,Hs}var Us,eg;function xr(){if(eg)return Us;eg=1;var e=WC(),r=ZC(),t=Jr(),n=St(),o=YC();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 Us=i,Us}var Ks,tg;function qx(){if(tg)return Ks;tg=1;var e=hx(),r=IC(),t=xr(),n=St();function o(i,s){var a=n(i)?e:r;return a(i,t(s,3))}return Ks=o,Ks}var Js,rg;function QC(){if(rg)return Js;rg=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n,o){return n!=null&&r.call(n,o)}return Js=t,Js}var Zs,ng;function Lx(){if(ng)return Zs;ng=1;var e=QC(),r=Nx();function t(n,o){return n!=null&&r(n,o,e)}return Zs=t,Zs}var Xs,og;function eS(){if(og)return Xs;og=1;var e=ou(),r=gn(),t=Jn(),n=St(),o=br(),i=pn(),s=zo(),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 Xs=h,Xs}var Ys,ig;function Fx(){if(ig)return Ys;ig=1;function e(r){return r===void 0}return Ys=e,Ys}var Qs,ag;function zx(){if(ag)return Qs;ag=1;var e=Do(),r=br();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 Qs=t,Qs}var ec,sg;function Bx(){if(sg)return ec;sg=1;var e=Wo(),r=xr(),t=zx(),n=St();function o(i,s){var a=n(i)?e:t;return a(i,r(s,3))}return ec=o,ec}var tc,cg;function tS(){if(cg)return tc;cg=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 tc=e,tc}var rc,lg;function rS(){if(lg)return rc;lg=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 rc=e,rc}var nc,dg;function Dx(){if(dg)return nc;dg=1;var e=tS(),r=Do(),t=xr(),n=rS(),o=St();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 nc=i,nc}var oc,ug;function nS(){if(ug)return oc;ug=1;var e=Hr(),r=St(),t=ur(),n="[object String]";function o(i){return typeof i=="string"||!r(i)&&t(i)&&e(i)==n}return oc=o,oc}var ic,fg;function oS(){if(fg)return ic;fg=1;var e=$x(),r=e("length");return ic=r,ic}var ac,hg;function iS(){if(hg)return ac;hg=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 ac=c,ac}var sc,pg;function aS(){if(pg)return sc;pg=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 sc=v,sc}var cc,gg;function sS(){if(gg)return cc;gg=1;var e=oS(),r=iS(),t=aS();function n(o){return r(o)?t(o):e(o)}return cc=n,cc}var lc,yg;function cS(){if(yg)return lc;yg=1;var e=ou(),r=gn(),t=br(),n=nS(),o=sS(),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 lc=a,lc}var dc,mg;function lS(){if(mg)return dc;mg=1;var e=tu(),r=wx(),t=du(),n=xr(),o=Bo(),i=St(),s=pn(),a=Un(),c=Ht(),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 dc=d,dc}var uc,bg;function dS(){if(bg)return uc;bg=1;var e=hn(),r=Jn(),t=St(),n=e?e.isConcatSpreadable:void 0;function o(i){return t(i)||r(i)||!!(n&&i&&i[n])}return uc=o,uc}var fc,xg;function hu(){if(xg)return fc;xg=1;var e=au(),r=dS();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 fc=t,fc}var hc,vg;function uS(){if(vg)return hc;vg=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 hc=e,hc}var pc,wg;function Wx(){if(wg)return pc;wg=1;var e=uS(),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 pc=t,pc}var gc,Cg;function fS(){if(Cg)return gc;Cg=1;var e=cu(),r=cx(),t=Jr(),n=r?function(o,i){return r(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:t;return gc=n,gc}var yc,Sg;function hS(){if(Sg)return yc;Sg=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 yc=n,yc}var mc,jg;function Vx(){if(jg)return mc;jg=1;var e=fS(),r=hS(),t=r(e);return mc=t,mc}var bc,Eg;function Ho(){if(Eg)return bc;Eg=1;var e=Jr(),r=Wx(),t=Vx();function n(o,i){return t(r(o,i,e),o+"")}return bc=n,bc}var xc,_g;function Gx(){if(_g)return xc;_g=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 xc=e,xc}var vc,kg;function pS(){if(kg)return vc;kg=1;function e(r){return r!==r}return vc=e,vc}var wc,Pg;function gS(){if(Pg)return wc;Pg=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 wc=e,wc}var Cc,Ag;function yS(){if(Ag)return Cc;Ag=1;var e=Gx(),r=pS(),t=gS();function n(o,i,s){return i===i?t(o,i,s):e(o,r,s)}return Cc=n,Cc}var Sc,Rg;function mS(){if(Rg)return Sc;Rg=1;var e=yS();function r(t,n){var o=t==null?0:t.length;return!!o&&e(t,n,0)>-1}return Sc=r,Sc}var jc,Mg;function bS(){if(Mg)return jc;Mg=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 jc=e,jc}var Ec,Tg;function xS(){if(Tg)return Ec;Tg=1;function e(){}return Ec=e,Ec}var _c,Ig;function vS(){if(Ig)return _c;Ig=1;var e=bx(),r=xS(),t=uu(),n=1/0,o=e&&1/t(new e([,-0]))[1]==n?function(i){return new e(i)}:r;return _c=o,_c}var kc,Ng;function wS(){if(Ng)return kc;Ng=1;var e=kx(),r=mS(),t=bS(),n=Px(),o=vS(),i=uu(),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 kc=a,kc}var Pc,Og;function Hx(){if(Og)return Pc;Og=1;var e=br(),r=ur();function t(n){return r(n)&&e(n)}return Pc=t,Pc}var Ac,$g;function CS(){if($g)return Ac;$g=1;var e=hu(),r=Ho(),t=wS(),n=Hx(),o=r(function(i){return t(e(i,1,n,!0))});return Ac=o,Ac}var Rc,qg;function SS(){if(qg)return Rc;qg=1;var e=Wo();function r(t,n){return e(n,function(o){return t[o]})}return Rc=r,Rc}var Mc,Lg;function Ux(){if(Lg)return Mc;Lg=1;var e=SS(),r=Ir();function t(n){return n==null?[]:e(n,r(n))}return Mc=t,Mc}var Tc,Fg;function Ut(){if(Fg)return Tc;Fg=1;var e;if(typeof Yd=="function")try{e={clone:RC(),constant:cu(),each:_x(),filter:qx(),has:Lx(),isArray:St(),isEmpty:eS(),isFunction:Un(),isUndefined:Fx(),keys:Ir(),map:Bx(),reduce:Dx(),size:cS(),transform:lS(),union:CS(),values:Ux()}}catch{}return e||(e=window._),Tc=e,Tc}var Ic,zg;function pu(){if(zg)return Ic;zg=1;var e=Ut();Ic=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 Ic}var Nc,Bg;function jS(){return Bg||(Bg=1,Nc="2.1.8"),Nc}var Oc,Dg;function ES(){return Dg||(Dg=1,Oc={Graph:pu(),version:jS()}),Oc}var $c,Wg;function _S(){if(Wg)return $c;Wg=1;var e=Ut(),r=pu();$c={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 $c}var qc,Vg;function kS(){if(Vg)return qc;Vg=1;var e=Ut();qc=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 qc}var Lc,Gg;function Kx(){if(Gg)return Lc;Gg=1;var e=Ut();Lc=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},Lc}var Fc,Hg;function Jx(){if(Hg)return Fc;Hg=1;var e=Ut(),r=Kx();Fc=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 Fc}var zc,Ug;function PS(){if(Ug)return zc;Ug=1;var e=Jx(),r=Ut();zc=t;function t(n,o,i){return r.transform(n.nodes(),function(s,a){s[a]=e(n,a,o,i)},{})}return zc}var Bc,Kg;function Zx(){if(Kg)return Bc;Kg=1;var e=Ut();Bc=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 Bc}var Dc,Jg;function AS(){if(Jg)return Dc;Jg=1;var e=Ut(),r=Zx();Dc=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 Dc}var Wc,Zg;function RS(){if(Zg)return Wc;Zg=1;var e=Ut();Wc=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 Wc}var Vc,Xg;function Xx(){if(Xg)return Vc;Xg=1;var e=Ut();Vc=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,Vc}var Gc,Yg;function MS(){if(Yg)return Gc;Yg=1;var e=Xx();Gc=r;function r(t){try{e(t)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Gc}var Hc,Qg;function Yx(){if(Qg)return Hc;Qg=1;var e=Ut();Hc=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 Hc}var Uc,ey;function TS(){if(ey)return Uc;ey=1;var e=Yx();Uc=r;function r(t,n){return e(t,n,"post")}return Uc}var Kc,ty;function IS(){if(ty)return Kc;ty=1;var e=Yx();Kc=r;function r(t,n){return e(t,n,"pre")}return Kc}var Jc,ry;function NS(){if(ry)return Jc;ry=1;var e=Ut(),r=pu(),t=Kx();Jc=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 Jc}var Zc,ny;function OS(){return ny||(ny=1,Zc={components:kS(),dijkstra:Jx(),dijkstraAll:PS(),findCycles:AS(),floydWarshall:RS(),isAcyclic:MS(),postorder:TS(),preorder:IS(),prim:NS(),tarjan:Zx(),topsort:Xx()}),Zc}var Xc,oy;function $S(){if(oy)return Xc;oy=1;var e=ES();return Xc={Graph:e.Graph,json:_S(),alg:OS(),version:e.version},Xc}var Yc,iy;function Yt(){if(iy)return Yc;iy=1;var e;if(typeof Yd=="function")try{e=$S()}catch{}return e||(e=window.graphlib),Yc=e,Yc}var Qc,ay;function qS(){if(ay)return Qc;ay=1;var e=Sx(),r=1,t=4;function n(o){return e(o,r|t)}return Qc=n,Qc}var el,sy;function Uo(){if(sy)return el;sy=1;var e=fn(),r=br(),t=Lo(),n=Ht();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 el=o,el}var tl,cy;function LS(){if(cy)return tl;cy=1;var e=Ho(),r=fn(),t=Uo(),n=Kr(),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 tl=s,tl}var rl,ly;function FS(){if(ly)return rl;ly=1;var e=xr(),r=br(),t=Ir();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 rl=n,rl}var nl,dy;function zS(){if(dy)return nl;dy=1;var e=/\s/;function r(t){for(var n=t.length;n--&&e.test(t.charAt(n)););return n}return nl=r,nl}var ol,uy;function BS(){if(uy)return ol;uy=1;var e=zS(),r=/^\s+/;function t(n){return n&&n.slice(0,e(n)+1).replace(r,"")}return ol=t,ol}var il,fy;function DS(){if(fy)return il;fy=1;var e=BS(),r=Ht(),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 il=c,il}var al,hy;function Qx(){if(hy)return al;hy=1;var e=DS(),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 al=n,al}var sl,py;function WS(){if(py)return sl;py=1;var e=Qx();function r(t){var n=e(t),o=n%1;return n===n?o?n-o:n:0}return sl=r,sl}var cl,gy;function VS(){if(gy)return cl;gy=1;var e=Gx(),r=xr(),t=WS(),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 cl=o,cl}var ll,yy;function GS(){if(yy)return ll;yy=1;var e=FS(),r=VS(),t=e(r);return ll=t,ll}var dl,my;function ev(){if(my)return dl;my=1;var e=hu();function r(t){var n=t==null?0:t.length;return n?e(t,1):[]}return dl=r,dl}var ul,by;function HS(){if(by)return ul;by=1;var e=lu(),r=jx(),t=Kr();function n(o,i){return o==null?o:e(o,r(i),t)}return ul=n,ul}var fl,xy;function US(){if(xy)return fl;xy=1;function e(r){var t=r==null?0:r.length;return t?r[t-1]:void 0}return fl=e,fl}var hl,vy;function KS(){if(vy)return hl;vy=1;var e=$o(),r=du(),t=xr();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 hl=n,hl}var pl,wy;function gu(){if(wy)return pl;wy=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 pl=r,pl}var gl,Cy;function JS(){if(Cy)return gl;Cy=1;function e(r,t){return r>t}return gl=e,gl}var yl,Sy;function ZS(){if(Sy)return yl;Sy=1;var e=gu(),r=JS(),t=Jr();function n(o){return o&&o.length?e(o,t,r):void 0}return yl=n,yl}var ml,jy;function tv(){if(jy)return ml;jy=1;var e=$o(),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 ml=t,ml}var bl,Ey;function XS(){if(Ey)return bl;Ey=1;var e=Hr(),r=Bo(),t=ur(),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 bl=l,bl}var xl,_y;function rv(){if(_y)return xl;_y=1;function e(r,t){if(!(t==="constructor"&&typeof r[t]=="function")&&t!="__proto__")return r[t]}return xl=e,xl}var vl,ky;function YS(){if(ky)return vl;ky=1;var e=Kn(),r=Kr();function t(n){return e(n,r(n))}return vl=t,vl}var wl,Py;function QS(){if(Py)return wl;Py=1;var e=tv(),r=ux(),t=vx(),n=fx(),o=Cx(),i=Jn(),s=St(),a=Hx(),c=pn(),l=Un(),d=Ht(),u=XS(),h=Zn(),p=rv(),m=YS();function g(y,b,x,w,v,C,S){var E=p(y,x),R=p(b,x),A=S.get(R);if(A){e(y,x,A);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 wl=g,wl}var Cl,Ay;function ej(){if(Ay)return Cl;Ay=1;var e=Oo(),r=tv(),t=lu(),n=QS(),o=Ht(),i=Kr(),s=rv();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 Cl=a,Cl}var Sl,Ry;function tj(){if(Ry)return Sl;Ry=1;var e=Ho(),r=Uo();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 Sl=t,Sl}var jl,My;function rj(){if(My)return jl;My=1;var e=ej(),r=tj(),t=r(function(n,o,i){e(n,o,i)});return jl=t,jl}var El,Ty;function nv(){if(Ty)return El;Ty=1;function e(r,t){return r<t}return El=e,El}var _l,Iy;function nj(){if(Iy)return _l;Iy=1;var e=gu(),r=nv(),t=Jr();function n(o){return o&&o.length?e(o,t,r):void 0}return _l=n,_l}var kl,Ny;function oj(){if(Ny)return kl;Ny=1;var e=gu(),r=xr(),t=nv();function n(o,i){return o&&o.length?e(o,r(i,2),t):void 0}return kl=n,kl}var Pl,Oy;function ij(){if(Oy)return Pl;Oy=1;var e=er(),r=function(){return e.Date.now()};return Pl=r,Pl}var Al,$y;function aj(){if($y)return Al;$y=1;var e=qo(),r=Vo(),t=Lo(),n=Ht(),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 Al=i,Al}var Rl,qy;function sj(){if(qy)return Rl;qy=1;var e=Go(),r=aj(),t=Vo();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 Rl=n,Rl}var Ml,Ly;function cj(){if(Ly)return Ml;Ly=1;var e=sj(),r=Ox();function t(n,o){return e(n,o,function(i,s){return r(n,s)})}return Ml=t,Ml}var Tl,Fy;function lj(){if(Fy)return Tl;Fy=1;var e=ev(),r=Wx(),t=Vx();function n(o){return t(r(o,void 0,e),o+"")}return Tl=n,Tl}var Il,zy;function dj(){if(zy)return Il;zy=1;var e=cj(),r=lj(),t=r(function(n,o){return n==null?{}:e(n,o)});return Il=t,Il}var Nl,By;function uj(){if(By)return Nl;By=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 Nl=t,Nl}var Ol,Dy;function fj(){if(Dy)return Ol;Dy=1;var e=uj(),r=Uo(),t=Qx();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 Ol=n,Ol}var $l,Wy;function hj(){if(Wy)return $l;Wy=1;var e=fj(),r=e();return $l=r,$l}var ql,Vy;function pj(){if(Vy)return ql;Vy=1;function e(r,t){var n=r.length;for(r.sort(t);n--;)r[n]=r[n].value;return r}return ql=e,ql}var Ll,Gy;function gj(){if(Gy)return Ll;Gy=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 Ll=r,Ll}var Fl,Hy;function yj(){if(Hy)return Fl;Hy=1;var e=gj();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 Fl=r,Fl}var zl,Uy;function mj(){if(Uy)return zl;Uy=1;var e=Wo(),r=Go(),t=xr(),n=zx(),o=pj(),i=Fo(),s=yj(),a=Jr(),c=St();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 zl=l,zl}var Bl,Ky;function bj(){if(Ky)return Bl;Ky=1;var e=hu(),r=mj(),t=Ho(),n=Uo(),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 Bl=o,Bl}var Dl,Jy;function xj(){if(Jy)return Dl;Jy=1;var e=Ix(),r=0;function t(n){var o=++r;return e(n)+o}return Dl=t,Dl}var Wl,Zy;function vj(){if(Zy)return Wl;Zy=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 Wl=e,Wl}var Vl,Xy;function wj(){if(Xy)return Vl;Xy=1;var e=qo(),r=vj();function t(n,o){return r(n||[],o||[],e)}return Vl=t,Vl}var Gl,Yy;function bt(){if(Yy)return Gl;Yy=1;var e;if(typeof Yd=="function")try{e={cloneDeep:qS(),constant:cu(),defaults:LS(),each:_x(),filter:qx(),find:GS(),flatten:ev(),forEach:Ex(),forIn:HS(),has:Lx(),isUndefined:Fx(),last:US(),map:Bx(),mapValues:KS(),max:ZS(),merge:rj(),min:nj(),minBy:oj(),now:ij(),pick:dj(),range:hj(),reduce:Dx(),sortBy:bj(),uniqueId:xj(),values:Ux(),zipObject:wj()}}catch{}return e||(e=window._),Gl=e,Gl}var Hl,Qy;function Cj(){if(Qy)return Hl;Qy=1,Hl=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 Hl}var Ul,em;function Sj(){if(em)return Ul;em=1;var e=bt(),r=Yt().Graph,t=Cj();Ul=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 Ul}var Kl,tm;function jj(){if(tm)return Kl;tm=1;var e=bt(),r=Sj();Kl={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 Kl}var Jl,rm;function Ot(){if(rm)return Jl;rm=1;var e=bt(),r=Yt().Graph;Jl={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,A;return Math.abs(C)*S>Math.abs(v)*E?(C<0&&(E=-E),R=E*v/C,A=E):(v<0&&(S=-S),R=S,A=S*C/v),{x:x+R,y:w+A}}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 Jl}var Zl,nm;function Ej(){if(nm)return Zl;nm=1;var e=bt(),r=Ot();Zl={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 Zl}var Xl,om;function mo(){if(om)return Xl;om=1;var e=bt();Xl={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 Xl}var Yl,im;function ov(){if(im)return Yl;im=1;var e=bt(),r=Yt().Graph,t=mo().slack;Yl=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 Yl}var Ql,am;function _j(){if(am)return Ql;am=1;var e=bt(),r=ov(),t=mo().slack,n=mo().longestPath,o=Yt().alg.preorder,i=Yt().alg.postorder,s=Ot().simplify;Ql=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,A=v.edge(C,E),I=0;return A||(R=!1,A=v.edge(E,C)),I=A.weight,e.forEach(v.nodeEdges(C),function(M){var k=M.v===C,_=k?M.w:M.v;if(_!==E){var N=k===R,O=v.edge(M).weight;if(I+=N?O:-O,b(w,C,_)){var W=w.edge(C,_).cutvalue;I+=N?-W:W}}}),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,A=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))}),A.low=R,A.lim=C++,E?A.parent=E:delete A.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),A=w.node(E),I=R,M=!1;R.lim>A.lim&&(I=A,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,A=v.edge(E,R),I=!1;A||(A=v.edge(R,E),I=!0),v.node(E).rank=v.node(R).rank+(I?A.minlen:-A.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 Ql}var ed,sm;function kj(){if(sm)return ed;sm=1;var e=mo(),r=e.longestPath,t=ov(),n=_j();ed=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 ed}var td,cm;function Pj(){if(cm)return td;cm=1;var e=bt();td=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 td}var rd,lm;function Aj(){if(lm)return rd;lm=1;var e=bt(),r=Ot();rd={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 rd}var nd,dm;function Rj(){if(dm)return nd;dm=1;var e=bt(),r=Ot();nd=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 nd}var od,um;function Mj(){if(um)return od;um=1;var e=bt();od={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 od}var id,fm;function Tj(){if(fm)return id;fm=1;var e=bt();id=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 id}var ad,hm;function Ij(){if(hm)return ad;hm=1;var e=bt();ad=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 ad}var sd,pm;function Nj(){if(pm)return sd;pm=1;var e=bt();sd=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 sd}var cd,gm;function Oj(){if(gm)return cd;gm=1;var e=bt();cd=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 cd}var ld,ym;function $j(){if(ym)return ld;ym=1;var e=bt(),r=Ot();ld=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 ld}var dd,mm;function qj(){if(mm)return dd;mm=1;var e=bt(),r=Nj(),t=Oj(),n=$j();dd=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 dd}var ud,bm;function Lj(){if(bm)return ud;bm=1;var e=bt(),r=Yt().Graph;ud=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 ud}var fd,xm;function Fj(){if(xm)return fd;xm=1;var e=bt();fd=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 fd}var hd,vm;function zj(){if(vm)return hd;vm=1;var e=bt(),r=Tj(),t=Ij(),n=qj(),o=Lj(),i=Fj(),s=Yt().Graph,a=Ot();hd=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 hd}var pd,wm;function Bj(){if(wm)return pd;wm=1;var e=bt(),r=Yt().Graph,t=Ot();pd={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,A=C.length,I=e.last(S);return e.forEach(S,function(M,k){var _=i(b,M),N=_?b.node(_).order:A;(_||M===I)&&(e.forEach(S.slice(R,k+1),function(O){e.forEach(b.predecessors(O),function(W){var T=b.node(W),Y=T.order;(Y<E||N<Y)&&!(T.dummy&&b.node(O).dummy)&&s(w,W,O)})}),R=k+1,E=N)}),S}return e.reduce(x,v),w}function o(b,x){var w={};function v(S,E,R,A,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<A||N.order>I)&&s(w,_,M)})})}function C(S,E){var R=-1,A,I=0;return e.forEach(E,function(M,k){if(b.node(M).dummy==="border"){var _=b.predecessors(M);_.length&&(A=b.node(_[0]).order,v(E,I,k,R,A),I=k,R=A)}v(E,I,E.length,A,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(A,I){C[A]=A,S[A]=A,E[A]=I})}),e.forEach(x,function(R){var A=-1;e.forEach(R,function(I){var M=v(I);if(M.length){M=e.sortBy(M,function(W){return E[W]});for(var k=(M.length-1)/2,_=Math.floor(k),N=Math.ceil(k);_<=N;++_){var O=M[_];S[I]===I&&A<E[O]&&!a(w,I,O)&&(S[O]=I,S[I]=C[I]=C[O],A=E[O])}}})}),{root:C,align:S}}function l(b,x,w,v,C){var S={},E=d(b,x,w,C),R=C?"borderLeft":"borderRight";function A(k,_){for(var N=E.nodes(),O=N.pop(),W={};O;)W[O]?k(O):(W[O]=!0,N.push(O),N=N.concat(_(O))),O=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(O,W){return Math.min(O,S[W.w]-E.edge(W))},Number.POSITIVE_INFINITY),N=b.node(k);_!==Number.POSITIVE_INFINITY&&N.borderType!==R&&(S[k]=Math.max(S[k],_))}return A(I,E.predecessors.bind(E)),A(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 A;e.forEach(R,function(I){var M=w[I];if(C.setNode(M),A){var k=w[A],_=C.edge(k,M);C.setEdge(k,M,Math.max(E(b,I,A),_||0))}A=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,A=b[R],I;if(A!==x){var M=e.values(A);I=E==="l"?v-e.min(M):C-e.max(M),I&&(b[R]=e.mapValues(A,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 A=(E==="u"?b.predecessors:b.successors).bind(b),I=c(b,C,w,A),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),A=0,I;if(A+=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&&(A+=w?I:-I),I=0,A+=(E.dummy?x:b)/2,A+=(R.dummy?x:b)/2,A+=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&&(A+=w?I:-I),I=0,A}}function y(b,x){return b.node(x).width}return pd}var gd,Cm;function Dj(){if(Cm)return gd;Cm=1;var e=bt(),r=Ot(),t=Bj().positionX;gd=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 gd}var yd,Sm;function Wj(){if(Sm)return yd;Sm=1;var e=bt(),r=jj(),t=Ej(),n=kj(),o=Ot().normalizeRanks,i=Pj(),s=Ot().removeEmptyRanks,a=Aj(),c=Rj(),l=Mj(),d=zj(),u=Dj(),h=Ot(),p=Yt().Graph;yd=m;function m(q,z){var H=z&&z.debugTiming?h.time:h.notime;H("layout",function(){var V=H(" buildLayoutGraph",function(){return A(q)});H(" runLayout",function(){g(V,H)}),H(" updateInputGraph",function(){y(q,V)})})}function g(q,z){z(" makeSpaceForEdgeLabels",function(){I(q)}),z(" removeSelfEdges",function(){he(q)}),z(" acyclic",function(){r.run(q)}),z(" nestingGraph.run",function(){a.run(q)}),z(" rank",function(){n(h.asNonCompoundGraph(q))}),z(" injectEdgeLabelProxies",function(){M(q)}),z(" removeEmptyRanks",function(){s(q)}),z(" nestingGraph.cleanup",function(){a.cleanup(q)}),z(" normalizeRanks",function(){o(q)}),z(" assignRankMinMax",function(){k(q)}),z(" removeEdgeLabelProxies",function(){_(q)}),z(" normalize.run",function(){t.run(q)}),z(" parentDummyChains",function(){i(q)}),z(" addBorderSegments",function(){c(q)}),z(" order",function(){d(q)}),z(" insertSelfEdges",function(){K(q)}),z(" adjustCoordinateSystem",function(){l.adjust(q)}),z(" position",function(){u(q)}),z(" positionSelfEdges",function(){re(q)}),z(" removeBorderNodes",function(){Y(q)}),z(" normalize.undo",function(){t.undo(q)}),z(" fixupEdgeLabelCoords",function(){W(q)}),z(" undoCoordinateSystem",function(){l.undo(q)}),z(" translateGraph",function(){N(q)}),z(" assignNodeIntersects",function(){O(q)}),z(" reversePoints",function(){T(q)}),z(" acyclic.undo",function(){r.undo(q)})}function y(q,z){e.forEach(q.nodes(),function(H){var V=q.node(H),le=z.node(H);V&&(V.x=le.x,V.y=le.y,z.children(H).length&&(V.width=le.width,V.height=le.height))}),e.forEach(q.edges(),function(H){var V=q.edge(H),le=z.edge(H);V.points=le.points,e.has(le,"x")&&(V.x=le.x,V.y=le.y)}),q.graph().width=z.graph().width,q.graph().height=z.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 A(q){var z=new p({multigraph:!0,compound:!0}),H=ne(q.graph());return z.setGraph(e.merge({},x,G(H,b),e.pick(H,w))),e.forEach(q.nodes(),function(V){var le=ne(q.node(V));z.setNode(V,e.defaults(G(le,v),C)),z.setParent(V,q.parent(V))}),e.forEach(q.edges(),function(V){var le=ne(q.edge(V));z.setEdge(V,e.merge({},E,G(le,S),e.pick(le,R)))}),z}function I(q){var z=q.graph();z.ranksep/=2,e.forEach(q.edges(),function(H){var V=q.edge(H);V.minlen*=2,V.labelpos.toLowerCase()!=="c"&&(z.rankdir==="TB"||z.rankdir==="BT"?V.width+=V.labeloffset:V.height+=V.labeloffset)})}function M(q){e.forEach(q.edges(),function(z){var H=q.edge(z);if(H.width&&H.height){var V=q.node(z.v),le=q.node(z.w),X={rank:(le.rank-V.rank)/2+V.rank,e:z};h.addDummyNode(q,"edge-proxy",X,"_ep")}})}function k(q){var z=0;e.forEach(q.nodes(),function(H){var V=q.node(H);V.borderTop&&(V.minRank=q.node(V.borderTop).rank,V.maxRank=q.node(V.borderBottom).rank,z=e.max(z,V.maxRank))}),q.graph().maxRank=z}function _(q){e.forEach(q.nodes(),function(z){var H=q.node(z);H.dummy==="edge-proxy"&&(q.edge(H.e).labelRank=H.rank,q.removeNode(z))})}function N(q){var z=Number.POSITIVE_INFINITY,H=0,V=Number.POSITIVE_INFINITY,le=0,X=q.graph(),ue=X.marginx||0,oe=X.marginy||0;function de(ge){var ce=ge.x,U=ge.y,te=ge.width,pe=ge.height;z=Math.min(z,ce-te/2),H=Math.max(H,ce+te/2),V=Math.min(V,U-pe/2),le=Math.max(le,U+pe/2)}e.forEach(q.nodes(),function(ge){de(q.node(ge))}),e.forEach(q.edges(),function(ge){var ce=q.edge(ge);e.has(ce,"x")&&de(ce)}),z-=ue,V-=oe,e.forEach(q.nodes(),function(ge){var ce=q.node(ge);ce.x-=z,ce.y-=V}),e.forEach(q.edges(),function(ge){var ce=q.edge(ge);e.forEach(ce.points,function(U){U.x-=z,U.y-=V}),e.has(ce,"x")&&(ce.x-=z),e.has(ce,"y")&&(ce.y-=V)}),X.width=H-z+ue,X.height=le-V+oe}function O(q){e.forEach(q.edges(),function(z){var H=q.edge(z),V=q.node(z.v),le=q.node(z.w),X,ue;H.points?(X=H.points[0],ue=H.points[H.points.length-1]):(H.points=[],X=le,ue=V),H.points.unshift(h.intersectRect(V,X)),H.points.push(h.intersectRect(le,ue))})}function W(q){e.forEach(q.edges(),function(z){var H=q.edge(z);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(z){var H=q.edge(z);H.reversed&&H.points.reverse()})}function Y(q){e.forEach(q.nodes(),function(z){if(q.children(z).length){var H=q.node(z),V=q.node(H.borderTop),le=q.node(H.borderBottom),X=q.node(e.last(H.borderLeft)),ue=q.node(e.last(H.borderRight));H.width=Math.abs(ue.x-X.x),H.height=Math.abs(le.y-V.y),H.x=X.x+H.width/2,H.y=V.y+H.height/2}}),e.forEach(q.nodes(),function(z){q.node(z).dummy==="border"&&q.removeNode(z)})}function he(q){e.forEach(q.edges(),function(z){if(z.v===z.w){var H=q.node(z.v);H.selfEdges||(H.selfEdges=[]),H.selfEdges.push({e:z,label:q.edge(z)}),q.removeEdge(z)}})}function K(q){var z=h.buildLayerMatrix(q);e.forEach(z,function(H){var V=0;e.forEach(H,function(le,X){var ue=q.node(le);ue.order=X+V,e.forEach(ue.selfEdges,function(oe){h.addDummyNode(q,"selfedge",{width:oe.label.width,height:oe.label.height,rank:ue.rank,order:X+ ++V,e:oe.e,label:oe.label},"_se")}),delete ue.selfEdges})})}function re(q){e.forEach(q.nodes(),function(z){var H=q.node(z);if(H.dummy==="selfedge"){var V=q.node(H.e.v),le=V.x+V.width/2,X=V.y,ue=H.x-le,oe=V.height/2;q.setEdge(H.e,H.label),q.removeNode(z),H.label.points=[{x:le+2*ue/3,y:X-oe},{x:le+5*ue/6,y:X-oe},{x:le+ue,y:X},{x:le+5*ue/6,y:X+oe},{x:le+2*ue/3,y:X+oe}],H.label.x=H.x,H.label.y=H.y}})}function G(q,z){return e.mapValues(e.pick(q,z),Number)}function ne(q){var z={};return e.forEach(q,function(H,V){z[V.toLowerCase()]=H}),z}return yd}var md,jm;function Vj(){if(jm)return md;jm=1;var e=bt(),r=Ot(),t=Yt().Graph;md={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 md}var bd,Em;function Gj(){return Em||(Em=1,bd="0.8.5"),bd}var xd,_m;function Hj(){return _m||(_m=1,xd={graphlib:Yt(),layout:Wj(),debug:Vj(),util:{time:Ot().time,notime:Ot().notime},version:Gj()}),xd}var Uj=Hj();const km=M1(Uj);function Kj(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 km.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=nx(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*rx: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)}km.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 Md(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 Pm(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 iv(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 yu(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 Ar(e,r,t=e.fixedSizes){const n=Md(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,sr({...i,...s}))}return n}function av(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=av(o[i],o[s],r,t);a&&n.push(a)}return n}function sv(e,r={}){const t=yu(r),{groups:n}=Yn(e);return Vn(n,Ar(e,e.positions),t)}function cv(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 Jj(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=Ar(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),A=c.get(E),I=(R.y1+R.y2-A.y1-A.y2)/2;return Math.abs(I)>1?I:R.x1-A.x1});for(const S of h){const E=u.at(-1),R=c.get(S),A=E&&c.get(E[0]);A&&Math.abs(R.y1+R.y2-A.y1-A.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((A,I)=>{var M,k;return{id:A,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 vd(e,r={}){var d;iv(r.adjustment);const t=yu(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 Zj(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=Ar(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=cv(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})),A=(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 O=h.get(_),W={x:A+(N-(C-1)/2)*S-(O.x1+O.x2)/2,y:I+(k-(v.length-1)/2)*E-(O.y1+O.y2)/2};for(const T of s.get(_)??[]){const Y=a.get(T);a.set(T,{x:Y.x+W.x,y:Y.y+W.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,Ar(e,a),Math.min(n.x,n.y))}}function Zj(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:sv(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,O;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=cv(y,r,x,C),E=S.length,R=Math.min(t.y,v/(2*E)),A=(O=(N=r.adjustment)==null?void 0:N.sections)==null?void 0:O[x],I=Array.from({length:E},(W,T)=>{var Y;return((Y=A==null?void 0:A.rows)==null?void 0:Y[T])??1}),M=I.reduce((W,T)=>W+T,0),k=v-(E-1)*R;let _=b.y1;for(let W=0;W<E;W++){const T=k*I[W]/M,Y=S[W].length,he=Math.min(t.x,w/(2*Y)),K=Array.from({length:Y},(q,z)=>{var H,V;return((V=(H=A==null?void 0:A.columns)==null?void 0:H[W])==null?void 0:V[z])??1}),re=K.reduce((q,z)=>q+z,0),G=w-(Y-1)*he;let ne=b.x1;for(let q=0;q<Y;q++){const z=S[W][q],H=G*K[q]/re,V=i.get(z);if(V){a.set(z,{x:ne+H/2,y:_+T/2}),h.set(z,{w:H,h:T});const le=Math.min(e.padding(z),Math.max(0,(Math.min(H,T)-1)/2));m(V,{x1:ne+le,y1:_+le,x2:ne+H-le,y2:_+T-le},z)}else a.has(z)&&(a.set(z,{x:ne+H/2,y:_+T/2}),h.set(z,{w:H,h:T}));q<Y-1&&p.push({section:x,axis:"x",row:W,index:q,weights:K,length:G,position:{x:ne+H+he/2,y:_+T/2}}),ne+=H+he}W<E-1&&p.push({section:x,axis:"y",row:W,index:W,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,Ar({...e,sizes:h},a,h),0)}}function Xj(e,r={}){const t=yu(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,Ar(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=Ar(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=av(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),A=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,A*I/(C?1:2)),C||m(x,S,-A*I/(v?1:2)),u=!0}}if(l++,c=Vn(o,Ar(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 Yj({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?Z.PiArrowsHorizontal:Z.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(Pm(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(Pm(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 Am=(e,r)=>e.left<r.right&&e.right>r.left&&e.top<r.bottom&&e.bottom>r.top,wd=new WeakMap;function Rm(e,r){const t=[...r.querySelectorAll(".flow-sdk-edge-label")];if(!t.length){wd.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=wd.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=A=>s.some(I=>Am(A,I))||[...d.values()].some(I=>Am(A,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},(A,I)=>g.getPointAtLength(x*I/C)),R=Array.from({length:C+1},(A,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)),O=g.getPointAtLength(Math.min(x,M+2));let W=Math.atan2(O.y-N.y,O.x-N.x)*180/Math.PI;W>90&&(W-=180),W<-90&&(W+=180);const T=Math.abs(W)<1;h&&(W=0);const Y=W*Math.PI/180,he=Math.abs(Math.cos(Y))*b.width+Math.abs(Math.sin(Y))*b.height,K=Math.abs(Math.sin(Y))*b.width+Math.abs(Math.cos(Y))*b.height;return{point:_,angle:W,straight:T,score:Math.hypot(_.x-w,_.y-v),bounds:{left:_.x-he/2-8,right:_.x+he/2+8,top:_.y-K/2-8,bottom:_.y+K/2+8}}}).sort((A,I)=>A.score-I.score).find(A=>!m(A.bounds)&&(!h||A.straight&&!S.some(I=>I.x>A.bounds.left&&I.x<A.bounds.right&&I.y>A.bounds.top&&I.y<A.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)}wd.set(r,{geometry:c,transforms:new Map(t.map(u=>[u,u.getAttribute("transform")??""]))})}function Qj(e){const r=e.getBoundingClientRect(),t=r.height/e.offsetHeight;if(!Number.isFinite(t)||t<=0)return[];const n=ex(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=Xb(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 eE({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:A="LR",onPropertyRows:I,onSurface:M,children:k}){var V,le;const _=j.useRef(null),[N,O]=j.useState([]),W=m??N,[T,Y]=j.useState(),he=j.useId(),K=j.useRef(),re=!!l,G=!!(l!=null&&l.floating);j.useLayoutEffect(()=>{var ge;const X=_.current;if(!X||!re)return;const ue=X.cloneNode(!0);ue.removeAttribute("data-node-id"),ue.removeAttribute("data-grid-dragging"),ue.removeAttribute("data-grid-draggable"),ue.removeAttribute("data-grid-drop-target"),ue.setAttribute("data-grid-preview",e),ue.setAttribute("aria-hidden","true"),ue.setAttribute("inert","");const oe=[ue,...ue.querySelectorAll("*")],de=new Map(oe.filter(ce=>ce.id).map(ce=>[ce.id,`${ce.id}-${he}`]));for(const ce of oe){ce.id&&(ce.id=de.get(ce.id));for(const U of[...ce.attributes]){if(U.name==="id")continue;let te=U.value;for(const[pe,ve]of de)te===`#${pe}`&&(te=`#${ve}`),te=te.split(`url(#${pe})`).join(`url(#${ve})`);te!==U.value&&ce.setAttribute(U.name,te)}}if(Object.assign(ue.style,{opacity:"0.35",zIndex:G?"2147483647":"11",pointerEvents:"none",outline:"none",visibility:"visible"}),G){const ce=getComputedStyle(X);ue.setAttribute("data-grid-preview-floating",""),Object.assign(ue.style,{position:"fixed",left:"0",top:"0",transformOrigin:"top left",font:ce.font,color:ce.color});for(const U of oe)U.removeAttribute("data-node-id"),U.style.pointerEvents="none"}return ue.querySelectorAll(".flow-sdk-node-animation, .flow-sdk-handle, .flow-sdk-property-port, [data-flow-collapse-control]").forEach(ce=>ce.remove()),(ge=G?document.body:X.parentElement)==null||ge.appendChild(ue),K.current=ue,()=>{ue.remove(),K.current=void 0}},[e,he,re,G]),j.useLayoutEffect(()=>{const X=K.current;if(!X||!l)return;const{x:ue,y:oe,size:de}=l;if(G&&_.current){const U=_.current,te=U.getBoundingClientRect(),pe=te.width/U.offsetWidth||1,ve=te.height/U.offsetHeight||1,Ne=te.left+(ue-r)*pe,Je=te.top+(oe-t)*ve;X.style.transform=`translate3d(${Ne}px, ${Je}px, 0) scale(${pe}, ${ve})`,X.style.width=`${U.offsetWidth}px`,X.style.height=`${U.offsetHeight}px`;return}const ge=de?Math.round(ue-de.w/2):ue,ce=de?Math.round(oe-de.h/2):oe;X.style.transform=de?`translate3d(${ge}px, ${ce}px, 0)`:`translate(-50%, -50%) translate3d(${ge}px, ${ce}px, 0)`,X.style.width=de?`${Math.round(ue+de.w/2)-ge}px`:"",X.style.height=de?`${Math.round(oe+de.h/2)-ce}px`:"",de&&(X.style.setProperty("--flow-grid-width",`${de.w}px`),X.style.setProperty("--flow-grid-height",`${de.h}px`),X.style.setProperty("--flow-grid-font",`${Math.max(12,Math.min(48,de.w/8,de.h/5))}px`))},[l==null?void 0:l.x,l==null?void 0:l.y,(V=l==null?void 0:l.size)==null?void 0:V.w,(le=l==null?void 0:l.size)==null?void 0:le.h,G,r,t]),j.useLayoutEffect(()=>{const X=_.current;if(!X)return;const ue=()=>{const ge=ex(X);Y(ce=>JSON.stringify(ce)===JSON.stringify(ge)?ce:ge),M==null||M(e,ge)};ue();const oe=new ResizeObserver(ue);oe.observe(X);const de=X.querySelector("[data-flow-node-surface]");return de&&oe.observe(de),()=>oe.disconnect()},[e,k,M]),j.useLayoutEffect(()=>(d(e,_.current),()=>{d(e,null),M==null||M(e,void 0)}),[e,d,M]),j.useLayoutEffect(()=>{const X=_.current;if(!X)return;let ue="";const oe=()=>{const U=Qj(X),te=E?U:U.filter(ve=>ve.anchor),pe=JSON.stringify(te);pe!==ue&&(ue=pe,O(te),I==null||I(e,te))};if(oe(),!E&&!X.querySelector("[data-flow-port-side]"))return;const de=new ResizeObserver(oe),ge=()=>{de.disconnect(),de.observe(X),X.querySelectorAll("[data-flow-property]").forEach(U=>de.observe(U)),oe()};ge();const ce=new MutationObserver(ge);return ce.observe(X,{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"]}),X.addEventListener("scroll",oe,!0),()=>{de.disconnect(),ce.disconnect(),X.removeEventListener("scroll",oe,!0)}},[e,E,I,k]);const ne=c?Math.round(r-c.w/2):0,q=c?Math.round(t-c.h/2):0,z=c?Math.round(r+c.w/2)-ne: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(${ne}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:z,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(X=>`${X.x} ${X.y}`).join(" L")} Z`:void 0,color:x||y||"currentColor",strokeWidth:w})}),u&&E&&W.map(X=>["source","target"].filter(ue=>!X.role||X.role===ue).filter(ue=>h||(p==null?void 0:p.has(`${ue}:${X.property}`))).map(ue=>{var oe;return f.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":X.property,"data-port-role":ue,"data-port-side":(oe=X.anchor)==null?void 0:oe.side,"aria-label":`${ue==="source"?"Connect":"Input"} ${X.property}`,title:`${ue==="source"?"Connect":"Input"} ${X.property}`,style:{color:y,...X.anchor?{top:X.anchor.y,left:X.anchor.x-16}:{top:X.top+X.height/2,[ue==="source"!=!!R?"right":"left"]:-16}},onClick:de=>de.stopPropagation()},`${X.property}:${ue}`)})),u&&!g&&(!E||!W.length)&&(!E||!W.some(X=>X.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)+(A==="RL"?-36:A==="LR"?(T==null?void 0:T.width)??C:((T==null?void 0:T.width)??C)/2),top:((T==null?void 0:T.top)??0)+(A==="BT"?-36:A==="TB"?(T==null?void 0:T.height)??S:((T==null?void 0:T.height)??S)/2),transform:A==="BT"||A==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:X=>X.stopPropagation(),children:f.jsx(Z.PiPlusBold,{size:24})})]})}const tE=j.memo(eE);function rE(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 nE{constructor(r,t,n){Dt(this,"_pan");Dt(this,"_zoom");Dt(this,"minZoom");Dt(this,"maxZoom");Dt(this,"size",{w:0,h:0});Dt(this,"listeners",new Set);Dt(this,"cancelTransition");Dt(this,"animationVersion",0);Dt(this,"captureTransition");Dt(this,"animationsDisabled",!1);Dt(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=Jb(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=Zb(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 oE={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},ao={w:60,h:60},Cd=4,iE=30,aE=500,sE=45;function Mm(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 cE(e){var ju,Eu,_u,ku,Pu;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"?nf:Xu)(C.id,r,t):null,[C,r,t]),R=i==="auto"||i==="properties",A=j.useMemo(()=>t.filter(P=>Rd(P,i)&&(!E||E.has(P.source)&&E.has(P.target))),[t,i,E]),I=j.useMemo(()=>_1(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),O=j.useRef(null),W=j.useRef(null),T=j.useMemo(()=>new nE(p,u,h),[]);j.useEffect(()=>{T.minZoom=u,T.maxZoom=h},[T,u,h]),j.useLayoutEffect(()=>{T.setAnimationsDisabled(v)},[T,v]);const Y=j.useRef(new Map),he=j.useRef(new Map),K=j.useRef(new Map),re=j.useRef(null),[G,ne]=j.useState(new Map),q=j.useCallback((P,L)=>{ne(B=>{if(JSON.stringify(B.get(P))===JSON.stringify(L))return B;const J=new Map(B);return L?J.set(P,L):J.delete(P),J})},[]),[z,H]=j.useState(new Map),V=j.useRef(z),le=j.useCallback((P,L)=>{H(B=>{if(JSON.stringify(B.get(P)??[])===JSON.stringify(L))return B;const J=new Map(B);return L.length?J.set(P,L):J.delete(P),J})},[]),[X,ue]=j.useState(()=>new Map),oe=j.useRef(X);oe.current=X;const[de,ge]=j.useState(new Map),ce=j.useRef(de),U=()=>{ce.current=new Map,ge(ce.current)},te=j.useRef(new Map(Object.entries(e.fixedNodePositions??{}))),pe=j.useRef(new Set(Object.keys(e.fixedNodePositions??{}))),ve=j.useRef(null),Ne=j.useRef(!1),[Je,tt]=j.useState(0),Ye=j.useRef(),Ue=j.useRef(),lt=j.useRef(null),be=j.useRef(),Ae=j.useRef(!1),ie=j.useRef(null),ae=j.useRef(null),Ie=j.useRef(),et=j.useRef(l),Ee=s,Le=j.useRef(Ee),[at,He]=j.useState(!0),[ft,ht]=j.useState(!!((ju=e.initialNodeGrid)!=null&&ju.enabled)),[At,Lt]=j.useState([]),rt=j.useRef((Eu=e.initialNodeGrid)!=null&&Eu.enabled?{options:{...e.initialNodeGrid.options,animate:!1},order:[...e.initialNodeGrid.order??e.initialNodeGrid.options.order??r.map(P=>P.id)],previousPositions:new Map,previousViewport:p,previousSize:{w:0,h:0},ready:!1}:null),[We,tr]=j.useState(null),pt=j.useRef(null);pt.current=E;const Ft=j.useRef(1);Ft.current=(C==null?void 0:C.mode)==="connections"?1.25:1;const fr=j.useRef(null),De=j.useRef(r),Kt=j.useRef([]),zt=j.useRef(!1),hr=()=>{var P;(P=lt.current)==null||P.call(lt),lt.current=null,be.current=void 0},F=()=>{ae.current=null,Kt.current.length&&!te.current.size&&(zt.current=!0),!Ne.current&&k.current.fitOnInit!==!1&&(Ae.current=!0),clearTimeout(Ue.current),Ue.current=setTimeout(()=>{Ne.current=oe.current.size>0,tt(P=>P+1)},aE)},$=(P,L,B,J=F,ye)=>{hr();const ke=new Map(oe.current),Se=new Map([...Y.current,...ce.current]);lt.current=Zb(L,je=>{const Xe=new Map;if(P.forEach((qe,Be)=>{const Pe=ke.get(Be);Xe.set(Be,te.current.get(Be)??(Pe?{x:Pe.x+(qe.x-Pe.x)*je,y:Pe.y+(qe.y-Pe.y)*je}:qe))}),oe.current=Xe,ue(Xe),ye){const qe=new Map;for(const[Be,Pe]of ye){const Q=Se.get(Be)??Pe;qe.set(Be,{w:Q.w+(Pe.w-Q.w)*je,h:Q.h+(Pe.h-Q.h)*je})}ce.current=qe,ge(qe)}B==null||B(je)},J)},se=()=>{var Be;if(clearTimeout(Ye.current),rt.current){yt.arrangeNodesInGrid(rt.current.options);return}ce.current.size&&U();const P=k.current,L=Ft.current,B=M.current,J=new Set(P.nodes.filter(Pe=>Pe.label===void 0).map(Pe=>Pe.id)),ye=B.nodes.map(Pe=>{const Q=he.current.get(Pe.id);Q&&(Q.offsetWidth||Q.offsetHeight)&&Y.current.set(Pe.id,{w:Q.offsetWidth,h:Q.offsetHeight});const ee=Y.current.get(Pe.id)||ao;return{id:Pe.id,parent:Pe.parent,width:ee.w,height:ee.h,hasBody:J.has(Pe.id)}});let ke;try{const Pe=P.compactPropertyLayout,Q=P.edgeMode!=="nodes"&&P.edgeMode!=="workflow",ee=B.edges.map(me=>({...me,connectorClearance:Pe?Q&&(me.sourceProperty!==void 0||me.targetProperty!==void 0)?E1:j1:0}));ke=Kj(ye,ee,{edgeLabelFontSize:P.edgeMode==="nodes"||P.edgeMode==="workflow"?tx:yo,rankDir:P.direction,compact:Pe,nodeAlignment:P.nodeAlignment,rankSep:P.rankSep*L,edgeSep:P.edgeSep*L,nodeSep:5*L,spacingFactor:P.spacingFactor??1.3,compactSpacingScale:(P.compactSpacingScale??(P.spacingFactor??1.3)/1.3)*L})}catch(Pe){console.warn("[flow-sdk] layout failed",Pe);return}const Se=[...te.current].find(([Pe])=>ke.has(Pe)),je=Se?{id:Se[0],position:Se[1]}:ae.current?null:ve.current;ve.current=null;const Xe=je&&ke.get(je.id);if(je&&Xe){const Pe={x:je.position.x-Xe.x,y:je.position.y-Xe.y};ke=new Map([...ke].map(([Q,ee])=>[Q,{x:ee.x+Pe.x,y:ee.y+Pe.y}]))}for(const[Pe,Q]of te.current)P.nodes.some(ee=>ee.id===Pe)?ke.set(Pe,Q):te.current.delete(Pe);if(ae.current){const Pe=JSON.stringify([ye,[...ke],T.size,P.isPerformanceMode,P.disableAnimations]);if(((Be=Ie.current)==null?void 0:Be.focus)===ae.current&&Ie.current.geometry===Pe)return;Ie.current={focus:ae.current,geometry:Pe}}else Ie.current=void 0;const qe=T.coordinate(()=>{var Pe;return(Pe=ae.current)==null?void 0:Pe.call(ae,ke)});$(ke,Ne.current&&!P.isPerformanceMode&&!P.disableAnimations,qe)},xe=j.useCallback(()=>{clearTimeout(Ue.current),clearTimeout(Ye.current),Ye.current=setTimeout(se,k.current.layoutDebounce)},[]);j.useLayoutEffect(()=>{const P=e.fixedNodePositions??{};let L=!1;for(const B of pe.current)Object.prototype.hasOwnProperty.call(P,B)||(L=te.current.delete(B)||L);for(const[B,J]of Object.entries(P)){if(!r.some(ke=>ke.id===B)||!J||![J.x,J.y].every(Number.isFinite))continue;const ye=te.current.get(B);((ye==null?void 0:ye.x)!==J.x||(ye==null?void 0:ye.y)!==J.y)&&(te.current.set(B,{...J}),L=!0)}pe.current=new Set(Object.keys(P)),L&&xe()},[e.fixedNodePositions,r,xe]),j.useLayoutEffect(()=>{const P=new Map(De.current.map(L=>[L.id,L]));r.some(L=>{var B;return((B=P.get(L.id))==null?void 0:B.collapsed)===!0&&!L.collapsed})&&(Kt.current=r.filter(L=>!P.has(L.id)).map(L=>L.id)),De.current=r,et.current!==l&&oe.current.size>0&&(Ne.current=!0,Ae.current=!1,clearTimeout(Ue.current)),et.current=l,Le.current!==Ee&&(Ae.current=!ie.current),Le.current=Ee,xe()},[r,t,I.nodes,I.edges,Ee,n,o,a,c,xe,l,d,v,e.nodeGridSpacing]),j.useEffect(()=>()=>{clearTimeout(Ye.current),clearTimeout(Ue.current),hr()},[]);const _e=j.useCallback((P,L)=>{var B,J;if(!re.current&&typeof ResizeObserver<"u"&&(re.current=new ResizeObserver(ye=>{let ke=!1;for(const Se of ye){const je=K.current.get(Se.target);if(!je||ce.current.has(je))continue;const Xe=Se.target,qe=Xe.offsetWidth,Be=Xe.offsetHeight;if(!qe&&!Be)continue;const Pe=Y.current.get(je);if(Pe&&Pe.w===qe&&Pe.h===Be)continue;const Q=oe.current.get(je);Pe&&Q&&Ne.current&&!ve.current&&(ve.current={id:je,position:{...Q}}),Y.current.set(je,{w:qe,h:Be}),ke=!0}ke&&xe()})),L){he.current.set(P,L),K.current.set(L,P),(B=re.current)==null||B.observe(L);const ye=L.offsetWidth,ke=L.offsetHeight;!ce.current.has(P)&&(ye||ke)&&Y.current.set(P,{w:ye,h:ke})}else{const ye=he.current.get(P);ye&&((J=re.current)==null||J.unobserve(ye),K.current.delete(ye)),he.current.delete(P),Y.current.delete(P),V.current.has(P)&&le(P,[])}xe()},[xe,le]);j.useEffect(()=>()=>{var P;return(P=re.current)==null?void 0:P.disconnect()},[]);const Te=P=>{var J;const L=(J=k.current.nodes.find(ye=>ye.id===P))==null?void 0:J.label;if(!L)return;const B=k.current.containerStyle(P);return{w:Ro(L,`bold ${B.fontSize}px ${Pr}`)+2*sE,h:0}},Re=j.useMemo(()=>{const P=new Map;for(const L of r)L.label&&P.set(L.id,L.label);return P},[r]),Ze=j.useMemo(()=>Md(I.nodes,X,new Map([...Y.current,...de]),P=>m(P).padding,Te,de),[I.nodes,X,m,Re,de]),Qe=j.useRef(Ze);Qe.current=Ze;const ze=j.useCallback(P=>{const L=Qe.current.get(P);if(L)return d1(L);const B=oe.current.get(P);if(!B)return;const J=ce.current.get(P)||Y.current.get(P)||ao;return{x:B.x,y:B.y,w:J.w,h:J.h}},[]),dt=j.useMemo(()=>{const P=new Map;for(const L of r){const B=ze(L.id);B&&P.set(L.id,B)}return x1(z,P,G,t,n)},[z,r,X,Ze,G,t,n,ze]);V.current=dt;const gt=(P,L)=>{var ye;if(!R||L===void 0)return;const B=(ye=dt.get(P))==null?void 0:ye.find(ke=>ke.property===L),J=ze(P);return B&&!B.anchor&&J?J.y-J.h/2+B.top+B.height/2:void 0},Ct=(P,L)=>{var ye,ke;if(L===void 0)return;const B=(ke=(ye=dt.get(P))==null?void 0:ye.find(Se=>Se.property===L))==null?void 0:ke.anchor,J=ze(P);return B&&J?{x:J.x-J.w/2+B.x,y:J.y-J.h/2+B.y,side:B.side}:void 0},jt=(P,L)=>{const B=ze(P),J=G.get(P);return B&&J&&!Ze.has(P)&>(P,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},Mt=()=>{const P=[];oe.current.forEach((L,B)=>{if(Qe.current.has(B))return;const J=ze(B);J&&P.push(sr(J))}),Qe.current.forEach(L=>P.push(L));try{for(const L of[N.current,O.current]){const B=L==null?void 0:L.getBBox();B&&B.width>0&&B.height>0&&P.push({x1:B.x,y1:B.y,x2:B.x+B.width,y2:B.y+B.height})}}catch{}return ri(P)},Tt=()=>{var B,J;const{pan:P,zoom:L}=T;W.current&&(W.current.style.transform=`translate3d(${P.x}px, ${P.y}px, 0) scale(${L})`),(B=N.current)==null||B.setAttribute("transform",`translate(${P.x} ${P.y}) scale(${L})`),(J=O.current)==null||J.setAttribute("transform",`translate(${P.x} ${P.y}) scale(${L})`)};j.useEffect(()=>{Tt();let P=null,L;const B=T.onChange(()=>{Tt();const J=_.current;J&&(J.classList.add("flow-sdk-busy"),clearTimeout(L),L=setTimeout(()=>J.classList.remove("flow-sdk-busy"),150)),P===null&&(P=requestAnimationFrame(()=>{var ye,ke;P=null,(ke=(ye=k.current).onViewportChange)==null||ke.call(ye,T.state)}))});return()=>{B(),clearTimeout(L),P!==null&&cancelAnimationFrame(P)}},[]),j.useLayoutEffect(()=>{const P=_.current;if(!P)return;const L=()=>{var Se;if(!P.getClientRects().length)return;let J=P.clientWidth,ye=P.clientHeight;ye||(ye=Math.max(0,window.innerHeight-P.getBoundingClientRect().top-100),ye&&(P.style.height=`${ye}px`)),J||(J=window.innerWidth,J&&(P.style.width=`${J}px`));const ke=T.size.w!==J||T.size.h!==ye;T.size={w:J,h:ye},ke&&((Se=rt.current)!=null&&Se.options.fill)&&(!Ne.current&&J>0&&ye>0?se():xe()),!Ne.current&&!oe.current.size&&k.current.fitOnInit!==!1&&(T.set({x:J/2,y:ye/2}),Tt())};if(L(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(L);return B.observe(P),()=>B.disconnect()},[T]),j.useLayoutEffect(()=>{if(zt.current){zt.current=!1;const L=Kt.current.flatMap(J=>{const ye=ze(J);return ye?[sr(ye)]:[]});Kt.current=[];const B=ri(L);if(B){Ae.current=!1,T.center(B,k.current.animateViewport);return}}if(!Ae.current)return;Ae.current=!1;const P=Mt();P&&(T.fit(P,50,Ne.current&&k.current.animateViewport),Ne.current||Tt())},[X]);const yt=j.useMemo(()=>{const P=Q=>{const ee=k.current;if(ee.nodeGridSpacing!=="layout")return Q;const me=ee.direction==="LR"||ee.direction==="RL";return{...Q,gaps:{x:me?ee.rankSep:ee.edgeSep,y:me?ee.edgeSep:ee.rankSep}}},L=()=>{const Q=k.current,ee=M.current.nodes.filter(me=>cr(me.id,Q.edges,Q.edgeMode)&&(!pt.current||pt.current.has(me.id)));return{nodes:ee,positions:oe.current,sizes:new Map(ee.map(me=>[me.id,Y.current.get(me.id)??ao])),padding:me=>k.current.containerStyle(me).padding,minSize:Te,fixedIds:new Set(te.current.keys()),viewportSize:{...T.size}}},B=Q=>Xu(Q,k.current.nodes,k.current.edges),J=(Q,ee=!0,me=()=>{},fe,Fe,we=!1)=>{clearTimeout(Ye.current),clearTimeout(Ue.current),we||(ae.current=null),ie.current=null,Ae.current=!1,Kt.current=[],zt.current=!1;const Ce=ee&&!k.current.isPerformanceMode&&!k.current.disableAnimations,Ke=T.coordinate(()=>{var nt;fe?fe(Ce):we&&((nt=ae.current)==null||nt.call(ae,Q))});$(new Map([...Q].map(([nt,ct])=>[nt,{...ct}])),Ce,Ke,me,Fe)},ye=(Q,ee=50,me=k.current.animateViewport,fe=1,Fe=!1,we)=>{const Ce=Ke=>{const nt=M.current,ct=Q??new Set(nt.nodes.map(xt=>xt.id)),or=new Set(nt.nodes.map(xt=>xt.parent).filter(Boolean));if(!Ke&&(!Q||[...Q].some(xt=>or.has(xt))))return;const gr=Ke&&Md(nt.nodes,Ke,Y.current,xt=>k.current.containerStyle(xt).padding,Te),vn=new Map([...ct].flatMap(xt=>{const ar=gr==null?void 0:gr.get(xt);if(ar)return[[xt,ar]];const Jt=Ke==null?void 0:Ke.get(xt),Cr=Y.current.get(xt)||ao,Au=Jt?{...Jt,...Cr}:ze(xt);return Au?[[xt,sr(Au)]]:[]}));let ir=ri([...vn.values()]);if(!ir)return;const wr=we?vn.get(we):void 0;if(wr){const xt=(wr.x1+wr.x2)/2,ar=(wr.y1+wr.y2)/2,Jt=Math.max(xt-ir.x1,ir.x2-xt),Cr=Math.max(ar-ir.y1,ir.y2-ar);ir={x1:xt-Jt,x2:xt+Jt,y1:ar-Cr,y2:ar+Cr}}Ae.current=!1,Kt.current=[],zt.current=!1,T.fit(ir,Number.isFinite(ee)?Math.max(0,ee):50,me,fe)};ae.current=Fe?Ce:null,Fe||Ce(oe.current)},ke=(Q,ee,me,fe)=>{var we;if(!ze(Q))return;const Fe=ee==="connections"?je(Q):B(Q);if(ee==="connections"&&Ft.current===1.25&&((we=pt.current)==null?void 0:we.size)===Fe.size&&[...Fe].every(Ce=>pt.current.has(Ce))){S({id:Q,mode:ee});return}if(fr.current||(fr.current={pan:{...T.pan},zoom:T.zoom}),pt.current=Fe,k.current.compactPropertyLayout){Ae.current=!1,ye(pt.current??Fe,me,fe,1,!0);const Ce=ae.current;Ce&&(ae.current=Ke=>{ae.current=null,Ie.current=void 0,Ce(Ke)})}S({id:Q,mode:ee}),k.current.compactPropertyLayout||ye(Fe,me,fe)},Se=Q=>{ie.current?ie.current=Q:Q()},je=Q=>nf(Q,k.current.nodes,k.current.edges),Xe=(Q=>{var ee,me,fe;if(Q===void 0)return T.zoom;Q<T.zoom&&((ee=rt.current)!=null&&ee.options.fill)&&!k.current.readOnly&&((fe=(me=k.current).onNodeGridZoomOut)==null?void 0:fe.call(me,rt.current.options))===!0||(ae.current=null,T.set(void 0,Q))}),qe=((Q,ee=!1)=>{if(Q===void 0)return T.pan;ae.current=null,ee?T.transition({pan:Q,zoom:T.zoom},!0):T.set(Q)}),Be=(Q,ee)=>{var fe;const me=(fe=_.current)==null?void 0:fe.getBoundingClientRect();return{x:Q-((me==null?void 0:me.left)??0),y:ee-((me==null?void 0:me.top)??0)}},Pe=(Q=0,ee=k.current.animateViewport,me=!1)=>{if(me){ye(void 0,Q,ee,1,!0);return}ae.current=null,Se(()=>{const fe=Mt();fe&&T.fit(fe,Q,ee)})};return{zoom:Xe,pan:qe,setEdgesVisible:He,focusNode:(Q,ee,me,fe)=>Se(()=>ye(new Set([Q]),ee,me,.6,fe)),focusBranch:(Q,ee,me,fe,Fe=!1,we=1)=>Se(()=>ye(B(Q),ee,me,we,fe,Fe?Q:void 0)),focusConnections:(Q,ee,me,fe)=>Se(()=>ye(je(Q),ee,me,1,fe)),isolateConnections:(Q,ee,me)=>ke(Q,"connections",ee,me),isolateBranch:(Q,ee,me)=>ke(Q,"branch",ee,me),restoreView:(Q=k.current.animateViewport,ee,me=!1)=>{ae.current=null;const fe=me&&!rt.current&&!pt.current,Fe=k.current.compactPropertyLayout&&!!pt.current;pt.current=null,S(null);const we=ee??fr.current;fr.current=null,we&&fe?(Ae.current=!1,ie.current=null,ve.current=null,ae.current=()=>T.transition(we,Q),xe()):Fe?ie.current=()=>{we&&T.transition(we,Q)}:we&&Se(()=>T.transition(we,Q))},zoomAt:(Q,ee)=>{var me,fe,Fe;Q<T.zoom&&((me=rt.current)!=null&&me.options.fill)&&!k.current.readOnly&&((Fe=(fe=k.current).onNodeGridZoomOut)==null?void 0:Fe.call(fe,rt.current.options))===!0||(ae.current=null,T.zoomAt(Q,ee))},fit:Pe,centerAndFit:Pe,center:(Q=k.current.animateViewport)=>{ae.current=null;const ee=Mt();ee&&T.center(ee,Q)},clientToModel:(Q,ee)=>T.renderedToModel(Be(Q,ee)),modelToClient:Q=>{var fe;const ee=(fe=_.current)==null?void 0:fe.getBoundingClientRect(),me=T.modelToRendered(Q);return{x:me.x+((ee==null?void 0:ee.left)??0),y:me.y+((ee==null?void 0:ee.top)??0)}},getNodeBox:Q=>ze(Q),detectNodeCollisions:Q=>{const ee=L();return sv({...ee,sizes:new Map([...ee.sizes,...ce.current]),fixedSizes:ce.current},Q)},resolveNodeCollisions:(Q={})=>{const ee=Xj(L(),Q);return ee.movedNodeIds.length&&J(ee.positions,Q.animate),ee},arrangeNodesInGrid:(Q={})=>{const ee=L(),me=rt.current;if(me){ee.positions=new Map(ee.positions);for(const ct of ee.nodes)ee.positions.has(ct.id)||ee.positions.set(ct.id,T.renderedToModel({x:T.size.w/2,y:T.size.h/2}));const Ce=new Set(ee.nodes.map(ct=>ct.id));me.order=me.order.filter(ct=>Ce.has(ct));const Ke=new Set(me.order);me.order.push(...ee.nodes.filter(ct=>!Ke.has(ct.id)).map(ct=>ct.id));const nt=new Map(me.order.map((ct,or)=>[ct,or]));ee.nodes=[...ee.nodes].sort((ct,or)=>nt.get(ct.id)-nt.get(or.id))}const fe=vd(ee,P(Q)),Fe=fe.sizes?JSON.stringify([[...fe.positions],[...fe.sizes]]):void 0;if(Fe&&Fe===be.current&&Q.animate!==!1&&!ae.current)return fe;Lt(fe.dividers??[]),me&&(me.ready=!1);const we=()=>{me&&(me.ready=!0),me&&ee.nodes.length&&!Ne.current&&(Ne.current=!0,k.current.fitOnInit!==!1&&!Q.fill?yt.centerAndFit(50,!1):k.current.fitOnInit===!1&&T.transition(p,!1)),tt(Ce=>Ce+1)};return!fe.sizes&&ce.current.size&&U(),ee.nodes.some(Ce=>!oe.current.has(Ce.id))||fe.movedNodeIds.length||fe.bounds||ae.current?J(fe.positions,Q.animate,we,fe.bounds&&(!me||!ce.current.size)?Ce=>T.transition({zoom:1,pan:{x:0,y:0}},Ce):void 0,fe.sizes,!!me&&!fe.bounds):we(),be.current=Fe,fe},setNodeGridMode:(Q,ee={})=>{var me,fe,Fe,we;if(ee.order&&(!Array.isArray(ee.order)||ee.order.some(Ce=>typeof Ce!="string")||new Set(ee.order).size!==ee.order.length))throw new Error("Invalid grid node order.");if(Q){vd(L(),P(ee));const Ce=!rt.current||rt.current.options.fill&&!ee.fill;ae.current=null,rt.current||(rt.current={options:ee,order:L().nodes.map(Ke=>Ke.id),previousPositions:new Map([...oe.current].map(([Ke,nt])=>[Ke,{...nt}])),previousViewport:{zoom:T.zoom,pan:{...T.pan}},previousSize:{...T.size},ready:!1}),Ce&&yt.centerAndFit(80,ee.animate,!0),ee.order&&(rt.current.order=[...ee.order]),rt.current.options={...ee},ht(!0),yt.arrangeNodesInGrid(ee),(fe=(me=k.current).onNodeGridModeChange)==null||fe.call(me,{...ee,order:[...rt.current.order]})}else{const Ce=rt.current;if(!Ce)return;if(T.size.w===Ce.previousSize.w&&T.size.h===Ce.previousSize.h&&oe.current.size===Ce.previousPositions.size&&[...oe.current.keys()].every(ct=>Ce.previousPositions.has(ct))?ae.current=()=>T.transition(Ce.previousViewport,ee.animate!==!1&&!k.current.disableAnimations&&!k.current.isPerformanceMode):yt.centerAndFit(80,ee.animate,!0),rt.current=null,ht(!1),U(),(we=(Fe=k.current).onNodeGridModeChange)==null||we.call(Fe,null),tr(null),!Ce.previousPositions.size){xe();return}const nt=new Map([...oe.current].map(([ct,or])=>[ct,Ce.previousPositions.get(ct)??or]));J(nt,ee.animate,void 0,void 0,void 0,!0)}},swapGridNodes:(Q,ee,me)=>{var vn,ir,wr,xt,ar;const fe=rt.current;if(!fe||!fe.ready||k.current.readOnly||Q===ee)return!1;const Fe=L(),we=Fe.nodes.find(Jt=>Jt.id===Q),Ce=Fe.nodes.find(Jt=>Jt.id===ee);if(!we||!Ce||we.parent!==Ce.parent)return!1;const Ke=vd(Fe,P(fe.options));if(Ke.skippedNodeIds.includes(Q)||Ke.skippedNodeIds.includes(ee))return!1;const nt=fe.order.indexOf(Q),ct=fe.order.indexOf(ee);if(nt<0||ct<0)return!1;[fe.order[nt],fe.order[ct]]=[fe.order[ct],fe.order[nt]],ae.current=null,fe.options={...fe.options,order:[...fe.order]};const or=we.parent??"canvas",gr=(ir=(vn=fe.options.adjustment)==null?void 0:vn.sections)==null?void 0:ir[or];return gr!=null&&gr.members&&(fe.options={...fe.options,adjustment:{...fe.options.adjustment,sections:{...(wr=fe.options.adjustment)==null?void 0:wr.sections,[or]:{...gr,members:gr.members.map(Jt=>Jt.map(Cr=>Cr===Q?ee:Cr===ee?Q:Cr))}}}}),yt.arrangeNodesInGrid({...fe.options,animate:me??fe.options.animate}),(ar=(xt=k.current).onNodeGridModeChange)==null||ar.call(xt,{...fe.options}),!0},setNodePosition:(Q,ee,me)=>{var Fe,we,Ce,Ke;if(!oe.current.has(Q)||ee&&(!Number.isFinite(ee.x)||!Number.isFinite(ee.y)))return!1;if(hr(),!ee)return te.current.delete(Q),(we=(Fe=k.current).onFixedNodePositionsChange)==null||we.call(Fe,Object.fromEntries(te.current)),xe(),!0;const fe=new Map(oe.current);return fe.set(Q,{...ee}),(me==null?void 0:me.persist)===!1?te.current.delete(Q):te.current.set(Q,{...ee}),oe.current=fe,ue(fe),(me==null?void 0:me.persist)!==!1&&((Ke=(Ce=k.current).onFixedNodePositionsChange)==null||Ke.call(Ce,Object.fromEntries(te.current))),(me==null?void 0:me.persist)===!1&&xe(),!0},getFixedNodePositions:()=>Object.fromEntries([...te.current].map(([Q,ee])=>[Q,{...ee}])),onViewportChange:Q=>T.onChange(Q)}},[]);j.useEffect(()=>{var P,L;return(L=(P=k.current).onInit)==null||L.call(P,yt),()=>T.cancelAnimation()},[yt]),j.useEffect(()=>{var P,L;if(Je>0){const B=ie.current;ie.current=null,B==null||B(),(L=(P=k.current).onLayoutComplete)==null||L.call(P,yt)}},[yt,Je]);const mt=j.useRef(null),wt=j.useRef(new Map),rr=j.useRef(!1),[nr,Bt]=j.useState(null),[it,vr]=j.useState(null),Nr=P=>{const L=_.current.getBoundingClientRect();return{x:(P.clientX-L.left)*(_.current.clientWidth/L.width||1),y:(P.clientY-L.top)*(_.current.clientHeight/L.height||1)}},pr=(P,L)=>{const B=k.current.nodes;for(let J=B.length-1;J>=0;J--){const ye=B[J].id;if(!cr(ye,k.current.edges,k.current.edgeMode)||pt.current&&!pt.current.has(ye)||ye===L||Qe.current.has(ye))continue;const ke=ze(ye);if(ke&&Yu(P,sr(ke)))return ye}for(const[J,ye]of Qe.current)if(cr(J,k.current.edges,k.current.edgeMode)&&!(pt.current&&!pt.current.has(J))&&J!==L&&Yu(P,ye))return J;return null},mn=(P,L)=>{const B=k.current.nodes.find(je=>je.id===P),J=ze(P);if(!B||!J)return null;const ye=sr({...J,x:J.x+L.x,y:J.y+L.y});let ke=null,Se=0;for(const je of k.current.nodes){if(je.id===P||je.parent!==B.parent||te.current.has(je.id)||Qe.current.has(je.id)||!cr(je.id,k.current.edges,k.current.edgeMode)||pt.current&&!pt.current.has(je.id))continue;const Xe=ze(je.id);if(!Xe)continue;const qe=sr(Xe),Be=Math.max(0,Math.min(ye.x2,qe.x2)-Math.max(ye.x1,qe.x1))*Math.max(0,Math.min(ye.y2,qe.y2)-Math.max(ye.y1,qe.y1));Be>Se&&(Se=Be,ke=je.id)}return ke},bn=(P,L)=>{const B=rt.current;if(!(B!=null&&B.ready)||k.current.readOnly)return;const J=k.current.nodes.filter(Be=>cr(Be.id,k.current.edges,k.current.edgeMode)&&(!pt.current||pt.current.has(Be.id))),ye=J.find(Be=>Be.id===P);if(!ye)return;const ke=_.current,Se=T.zoom*(ke&&ke.clientWidth?ke.getBoundingClientRect().width/ke.clientWidth:1),je=24/Se;let Xe;for(const Be of J){if(Be.id===P||Be.parent!==ye.parent)continue;const Pe=ze(Be.id);if(!Pe)continue;const Q=sr(Pe),ee=Math.min(Pe.w/4,je),me=Math.min(Pe.h/4,je),fe=3/Se,Fe=[];if(L.y>Q.y1+me&&L.y<Q.y2-me)for(const we of["before","after"]){const Ce=we==="before"?Q.x1:Q.x2,Ke=Math.abs(L.x-Ce),nt=we==="before"?L.x<Ce:L.x>Ce;Ke<=(nt?je:ee)&&Fe.push({side:we,distance:Ke,marker:{x1:Ce-fe/2,x2:Ce+fe/2,y1:Q.y1,y2:Q.y2}})}if(L.x>=Q.x1&&L.x<=Q.x2)for(const we of["above","below"]){const Ce=we==="above"?Q.y1:Q.y2,Ke=Math.abs(L.y-Ce),nt=we==="above"?L.y<Ce:L.y>Ce;Ke<=(nt?je:me)&&Fe.push({side:we,distance:Ke,marker:{x1:Q.x1,x2:Q.x2,y1:Ce-fe/2,y2:Ce+fe/2}})}for(const we of Fe)(!Xe||we.distance<Xe.distance)&&(Xe={id:Be.id,...we})}if(!Xe)return;const qe=Jj({nodes:J,positions:oe.current,sizes:new Map([...Y.current,...ce.current]),fixedSizes:ce.current,padding:Be=>k.current.containerStyle(Be).padding,minSize:Te,fixedIds:new Set(te.current.keys())},B.options,P,Xe.id,Xe.side);return qe?{options:qe,marker:Xe.marker}:void 0},Zr=(P,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 ye=null;for(const ke of[...k.current.nodes].reverse()){if(!cr(ke.id,k.current.edges,k.current.edgeMode)||pt.current&&!pt.current.has(ke.id))continue;const Se=ze(ke.id),je=V.current.get(ke.id);if(!Se||!je||Qe.current.has(ke.id))continue;const Xe=Se.x+(L==="source"!==B?1:-1)*Se.w/2;for(const qe of je){if(qe.role&&qe.role!==L)continue;const Be=Se.y-Se.h/2+qe.top,Pe=Math.hypot(P.x-(qe.anchor?Se.x-Se.w/2+qe.anchor.x:Xe),P.y-Be-qe.height/2);if(!qe.anchor&&P.x>=Se.x-Se.w/2&&P.x<=Se.x+Se.w/2&&P.y>=Be&&P.y<=Be+qe.height)return{nodeId:ke.id,property:qe.property};Pe<=J&&(!ye||Pe<ye.distance)&&(ye={nodeId:ke.id,property:qe.property,distance:Pe})}}return ye},bv=P=>{var je,Xe;if(!P.currentTarget.contains(P.target)||(mt.current||(rr.current=!1),P.target.closest(".flow-sdk-canvas")!==P.currentTarget)||P.button!==0)return;const L=P.target;if(L.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const B=k.current,J=Nr(P);if(P.pointerType==="touch"){wt.current.set(P.pointerId,J);const qe=Mm(wt.current);if(qe){tr(null),mt.current={kind:"pinch",distance:qe.distance,zoom:T.zoom,anchor:T.renderedToModel(qe.center)},vr(null),Bt(null),rr.current=!0;for(const Be of wt.current.keys())P.currentTarget.setPointerCapture(Be);return}}if(mt.current)return;if(k.current.readOnly){B.dragMode&&(mt.current={kind:"pan",pointerId:P.pointerId,start:J,pan0:T.pan,moved:!1},P.currentTarget.setPointerCapture(P.pointerId));return}const ye=!rt.current||!!B.nodeGridConnections,ke=B.drawHandles&&L.closest(".flow-sdk-handle"),Se=B.drawHandles&&L.closest(".flow-sdk-property-port");if((!ye||!ke&&!Se&&(!B.drawMode||P.shiftKey))&&(rt.current||P.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=(je=L.closest("[data-node-id]"))==null?void 0:je.dataset.nodeId;if(qe&&!te.current.has(qe)){L.setPointerCapture(P.pointerId),mt.current={kind:"grid",pointerId:P.pointerId,captureTarget:L,source:qe,start:J,moved:!1};return}if(qe)return}if(ye&&(B.drawMode||ke||Se)){const qe=T.renderedToModel(J),Be=B.drawMode?Zr(qe,"source"):null,Pe=Se||ke,Q=Pe?(Xe=Pe.closest("[data-node-id]"))==null?void 0:Xe.dataset.nodeId:(Be==null?void 0:Be.nodeId)??pr(qe),ee=Se?Se.dataset.property:Be==null?void 0:Be.property;if(Q){mt.current={kind:"draw",pointerId:P.pointerId,source:Q,sourceProperty:ee,reverse:(Se==null?void 0:Se.dataset.portRole)==="target",startClient:{x:P.clientX,y:P.clientY}},rr.current=!0,vr({source:Q,sourceProperty:ee,point:qe,target:null}),P.currentTarget.setPointerCapture(P.pointerId);return}}L.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(ae.current=null,B.multiSelect?mt.current={kind:"box",pointerId:P.pointerId,start:J,current:J}:B.dragMode?mt.current={kind:"pan",pointerId:P.pointerId,start:J,pan0:T.pan,moved:!1}:mt.current={kind:"tap",pointerId:P.pointerId,start:J,moved:!1},P.currentTarget.setPointerCapture(P.pointerId))},xv=P=>{var J,ye,ke;const L=mt.current;if(!L)return;const B=Nr(P);if(wt.current.has(P.pointerId)&&wt.current.set(P.pointerId,B),L.kind==="pinch"){const Se=Mm(wt.current);if(!Se)return;const je=Math.max(T.minZoom,Math.min(T.maxZoom,L.zoom*Se.distance/L.distance));if(je<T.zoom&&((J=rt.current)!=null&&J.options.fill)&&((ke=(ye=k.current).onNodeGridZoomOut)==null?void 0:ke.call(ye,rt.current.options))===!0)return;T.set({x:Se.center.x-L.anchor.x*je,y:Se.center.y-L.anchor.y*je},je);return}if(L.pointerId===P.pointerId)switch(L.kind){case"grid":{const Se={x:B.x-L.start.x,y:B.y-L.start.y};if(!L.moved&&Math.hypot(Se.x,Se.y)<=Cd)return;L.moved||(hr(),ae.current=null,T.cancelAnimation()),L.moved=!0,rr.current=!0,P.preventDefault();const je={x:Se.x/T.zoom,y:Se.y/T.zoom},Xe=!P.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;tr({source:L.source,offset:je,target:P.shiftKey||Xe?null:mn(L.source,je),shiftKey:P.shiftKey,insertion:Xe});break}case"pan":{const Se=B.x-L.start.x,je=B.y-L.start.y;if(!L.moved&&Math.hypot(Se,je)<=Cd)return;L.moved=!0,rr.current=!0,T.set({x:L.pan0.x+Se,y:L.pan0.y+je});break}case"tap":{Math.hypot(B.x-L.start.x,B.y-L.start.y)>Cd&&(L.moved=!0);break}case"box":{rr.current=!0,L.current=B,Bt({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 Se=T.renderedToModel(B),je=Zr(Se,L.reverse?"source":"target");vr(L.reverse&&je?{source:je.nodeId,sourceProperty:je.property,point:Se,target:L.source,targetProperty:L.sourceProperty}:{source:L.source,sourceProperty:L.sourceProperty,point:Se,target:(je==null?void 0:je.nodeId)??pr(Se,L.source),targetProperty:je==null?void 0:je.property});break}}},wu=(P,L)=>{var ye,ke,Se,je,Xe,qe,Be,Pe,Q,ee,me;wt.current.delete(P.pointerId);const B=mt.current;if(!B)return;if(B.kind==="pinch"){const fe=[...wt.current][0];mt.current=fe&&k.current.dragMode&&!L?{kind:"pan",pointerId:fe[0],start:fe[1],pan0:T.pan,moved:!0}:null;return}if(B.pointerId!==P.pointerId)return;mt.current=null;try{(B.kind==="grid"?B.captureTarget:P.currentTarget).releasePointerCapture(P.pointerId)}catch{}const J=k.current;switch(L=L||!!J.readOnly,B.kind){case"grid":{if(tr(null),L||!B.moved)break;const fe=Nr(P);if(!P.shiftKey&&fe.x>=0&&fe.y>=0&&fe.x<=T.size.w&&fe.y<=T.size.h){const we=bn(B.source,T.renderedToModel(fe));if(we){yt.setNodeGridMode(!0,{...we.options,animate:!1});break}}if(((ye=J.onNodeGridDrop)==null?void 0:ye.call(J,B.source,{x:P.clientX,y:P.clientY},{shiftKey:P.shiftKey,ctrlKey:P.ctrlKey,metaKey:P.metaKey,altKey:P.altKey}))===!0||fe.x<0||fe.y<0||fe.x>T.size.w||fe.y>T.size.h)break;if(P.shiftKey){const we=new Map(J.nodes.map(nt=>[nt.id,nt]));let Ce=pr(T.renderedToModel(fe),B.source);const Ke=new Set;for(;Ce&&!((ke=we.get(Ce))!=null&&ke.acceptsChildren)&&!Ke.has(Ce);)Ke.add(Ce),Ce=((Se=we.get(Ce))==null?void 0:Se.parent)??null;if(Ce&&((je=we.get(Ce))!=null&&je.acceptsChildren)){let nt=Ce;const ct=new Set;for(;nt&&!ct.has(nt);)ct.add(nt),nt=(Xe=we.get(nt))==null?void 0:Xe.parent;ct.has(B.source)||(qe=J.onNodeParentChange)==null||qe.call(J,B.source,Ce)}break}if(!rt.current)break;const Fe=mn(B.source,{x:(fe.x-B.start.x)/T.zoom,y:(fe.y-B.start.y)/T.zoom});Fe&&yt.swapGridNodes(B.source,Fe,!1);break}case"pan":case"tap":!L&&!B.moved&&((Be=J.onBackgroundTap)==null||Be.call(J));break;case"box":{if(Bt(null),L)break;const fe=T.renderedToModel(B.start),Fe=T.renderedToModel(B.current),we={x1:Math.min(fe.x,Fe.x),y1:Math.min(fe.y,Fe.y),x2:Math.max(fe.x,Fe.x),y2:Math.max(fe.y,Fe.y)};if(we.x2-we.x1<1&&we.y2-we.y1<1){(Pe=J.onBackgroundTap)==null||Pe.call(J);break}const Ce=[];for(const Ke of J.nodes){const nt=ze(Ke.id);nt&&u1(sr(nt),we)&&Ce.push(Ke.id)}Ce.length&&((Q=J.onBoxSelect)==null||Q.call(J,Ce));break}case"draw":{if(vr(null),L)break;const fe=Nr(P),Fe=T.renderedToModel(fe),we=Zr(Fe,B.reverse?"source":"target"),Ce=(we==null?void 0:we.nodeId)??pr(Fe);if(Ce===B.source&&(B.sourceProperty===void 0||(we==null?void 0:we.property)===void 0||we.property===B.sourceProperty))break;Ce?(ee=J.onEdgeDraw)==null||ee.call(J,B.reverse?Ce:B.source,B.reverse?B.source:Ce,B.sourceProperty!==void 0||(we==null?void 0:we.property)!==void 0?{sourceProperty:B.reverse?we==null?void 0:we.property:B.sourceProperty,targetProperty:B.reverse?B.sourceProperty:we==null?void 0:we.property}:void 0):Math.max(Math.abs(P.clientX-B.startClient.x),Math.abs(P.clientY-B.startClient.y))>iE&&((me=J.onDrawIntoSpace)==null||me.call(J,B.source,Fe,B.sourceProperty,B.reverse));break}}},Or=j.useCallback(()=>{var B;const P=mt.current,L=[...wt.current.keys()];P&&P.kind!=="pinch"&&L.push(P.pointerId),mt.current=null,wt.current.clear(),tr(null),vr(null),Bt(null);for(const J of L)(P==null?void 0:P.kind)==="grid"&&P.captureTarget.hasPointerCapture(J)&&P.captureTarget.releasePointerCapture(J),(B=_.current)!=null&&B.hasPointerCapture(J)&&_.current.releasePointerCapture(J)},[]);j.useEffect(()=>{const P=L=>{L.key==="Escape"&&Or()};return window.addEventListener("keydown",P),window.addEventListener("blur",Or),()=>{window.removeEventListener("keydown",P),window.removeEventListener("blur",Or),mt.current=null,wt.current.clear()}},[Or]),j.useEffect(()=>{Or()},[y,b,x,i,n,e.drawHandles,e.readOnly,ft,Or]);const vv=j.useMemo(()=>{const P=new Map,L=new Map;for(const B of A){if(B.source!==B.target)continue;const J=P.get(B.source)??0;P.set(B.source,J+1),L.set(B.id,J)}return L},[A]),Jo=oE[n],[$r,wv]=j.useState(null),Zo=rE(r,A,!!((_u=e.edgeReveal)!=null&&_u.revealNodes));j.useLayoutEffect(()=>{_.current&&$r&&Rm(_.current,$r)}),j.useEffect(()=>{const P=_.current;if(!P||!$r)return;const L=P.ownerDocument.fonts,B=()=>Rm(P,$r);return L==null||L.addEventListener("loadingdone",B),()=>L==null?void 0:L.removeEventListener("loadingdone",B)},[$r]);const Xo=l1(A,jt,Jo),Cv=e.onEdgeSelect,Sv=e.onContainerSelect,Cu=it?it.target&&jt(it.target,it.targetProperty)||{x:it.point.x,y:it.point.y,w:1,h:1}:null,Su=it?jt(it.source,it.sourceProperty):null,xn=!ft||!!e.nodeGridConnections,jv=["flow-sdk-canvas",y&&xn?"flow-sdk-draw":"",w?"flow-sdk-perf":""].filter(Boolean).join(" ");return f.jsxs("div",{ref:_,className:jv,"data-edge-mode":i,"data-node-grid":ft||void 0,"data-grid-connections":e.nodeGridConnections||void 0,onPointerDownCapture:bv,onPointerMove:xv,onPointerUp:P=>wu(P,!1),onPointerCancel:P=>wu(P,!0),onLostPointerCapture:P=>{const L=mt.current;L&&(L.kind==="pinch"||L.pointerId===P.pointerId)&&Or()},onClickCapture:P=>{if(!P.currentTarget.contains(P.target))return;const L=P.target instanceof Element&&P.target.closest("button[data-flow-fullscreen], button[data-flow-content-navigation]");(rr.current||e.readOnly&&!L)&&(P.preventDefault(),P.stopPropagation())},children:[f.jsx("svg",{className:"flow-sdk-svg",children:f.jsxs("g",{ref:N,children:[f.jsx("g",{className:"flow-sdk-containers",children:[...Ze].filter(([P])=>cr(P,t,i)).filter(([P])=>!E||E.has(P)).map(([P,L])=>{var B,J;return f.jsx(C1,{id:P,rect:L,label:Re.get(P),labelLayer:$r,labelContent:(B=r.find(ye=>ye.id===P&&ye.label!==void 0))==null?void 0:B.element,style:m(P),onSelect:Sv,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(J=e.selectedNodeIds)==null?void 0:J.includes(P)},P)})}),f.jsx("g",{className:"flow-sdk-edges",children:at&&xn&&A.map(P=>{var J,ye,ke;if(!Zo.ready.has(P.id)||E&&(!E.has(P.source)||!E.has(P.target)))return null;const L=jt(P.source,P.sourceProperty),B=jt(P.target,P.targetProperty);return!L||!B?null:f.jsx(af,{id:P.id,edgeData:P.data,validationIssue:P.validationIssue,edgeType:P.type,edgeRadius:e.edgeRadius,propertyMode:R,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:Zo.complete,source:L,target:B,sourceProperty:P.sourceProperty,targetProperty:P.targetProperty,sourceY:gt(P.source,P.sourceProperty),targetY:gt(P.target,P.targetProperty),sourcePort:Ct(P.source,P.sourceProperty),targetPort:Ct(P.target,P.targetProperty),dir:Jo,turn:((J=Xo.get(P.id))==null?void 0:J.turn)??P.turn,labelAtTarget:(ye=Xo.get(P.id))==null?void 0:ye.labelAtTarget,labelFraction:(ke=Xo.get(P.id))==null?void 0:ke.labelFraction,color:P.color,connectorColor:P.connectorColor,labelBg:P.labelBg,label:P.label,labelLayer:$r,dashed:P.dashed,animated:P.animated&&!w,inverted:P.inverted,loopIndex:vv.get(P.id)??0,onSelect:Cv},P.id)})}),at&&xn&&it&&Rd(it,i)&&Su&&Cu&&f.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:f.jsx(af,{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:Su,target:Cu,sourceProperty:it.sourceProperty,targetProperty:it.targetProperty,sourceY:gt(it.source,it.sourceProperty),sourcePort:Ct(it.source,it.sourceProperty),targetPort:it.target?Ct(it.target,it.targetProperty):void 0,targetY:it.target?gt(it.target,it.targetProperty):void 0,dir:Jo,turn:.5,color:g,labelBg:g})})]})}),f.jsxs("div",{ref:W,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}}),ft&&((ku=rt.current)==null?void 0:ku.options.fill)&&((Pu=rt.current.options.adjustment)==null?void 0:Pu.enabled)&&!e.readOnly&&f.jsx(Yj,{dividers:At,options:rt.current.options,zoom:T.zoom,onChange:P=>yt.setNodeGridMode(!0,{...P,animate:!1})}),r.map(P=>{var Fe,we,Ce;if((Fe=rt.current)!=null&&Fe.options.fill&&!Ne.current)return null;const L=X.get(P.id),B=Ze.get(P.id);if(B&&P.label!==void 0)return null;const J=(L==null?void 0:L.x)??(B?(B.x1+B.x2)/2:0),ye=(L==null?void 0:L.y)??(B?(B.y1+B.y2)/2:0),ke=We!=null&&We.target?P.id===We.source?We.target:P.id===We.target?We.source:void 0:void 0,Se=ke?X.get(ke):void 0,je=We?X.get(We.source):void 0,Xe=We!=null&&We.target?X.get(We.target):void 0,qe=je&&Xe?{x:Xe.x-je.x,y:Xe.y-je.y}:void 0,Be=qe?qe.x**2+qe.y**2:0,Pe=Be&&We&&qe?Math.max(0,Math.min(1,(We.offset.x*qe.x+We.offset.y*qe.y)/Be)):0,Q=Se?{x:J+(Se.x-J)*Pe,y:ye+(Se.y-ye)*Pe}:(We==null?void 0:We.source)===P.id?{x:J+We.offset.x,y:ye+We.offset.y}:void 0,ee=de.get(P.id),me=ke?de.get(ke):void 0,fe=ee&&me?{w:ee.w+(me.w-ee.w)*Pe,h:ee.h+(me.h-ee.h)*Pe}:ee;return f.jsx(tE,{id:P.id,x:J,y:ye,gridDraggable:ft&&!e.readOnly&&!te.current.has(P.id),gridDragging:(We==null?void 0:We.source)===P.id,gridDropTarget:(We==null?void 0:We.target)===P.id,gridSize:de.get(P.id),gridPreview:Q?{...Q,size:fe,floating:We==null?void 0:We.shiftKey}:void 0,placed:!!L||!!B,hidden:!ft&&!Zo.shown.has(P.id)||!cr(P.id,t,i)||!!E&&!E.has(P.id),onMount:_e,drawHandles:e.drawHandles&&!e.readOnly&&xn,drawMode:y&&xn,connectedPorts:new Set(A.flatMap(Ke=>[...Ke.source===P.id&&Ke.sourceProperty!==void 0?[`source:${Ke.sourceProperty}`]:[],...Ke.target===P.id&&Ke.targetProperty!==void 0?[`target:${Ke.targetProperty}`]:[]])),hasCollapseControl:P.hasCollapseControl,handleColor:g,animated:P.animated&&!B&&!w&&!ft,animationColor:P.animationColor,animationWidth:P.animationWidth,animationVariant:P.animationVariant,width:(we=Y.current.get(P.id))==null?void 0:we.w,height:(Ce=Y.current.get(P.id))==null?void 0:Ce.h,propertyMode:R,resolvedRows:dt.get(P.id),reversePorts:n==="RL",direction:n,onPropertyRows:le,onSurface:q,children:ee?P.fillElement??P.element:P.element},P.id)})]}),nr&&f.jsx("div",{className:"flow-sdk-box",style:{left:nr.x1,top:nr.y1,width:nr.x2-nr.x1,height:nr.y2-nr.y1}}),f.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:f.jsx("g",{ref:O,transform:`translate(${T.pan.x} ${T.pan.y}) scale(${T.zoom})`,children:f.jsx("g",{ref:wv,className:"flow-sdk-labels",style:{pointerEvents:y?"none":"visiblePainted",outline:"none"}})})})]})}const lE=j.memo(cE);function mu(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}=Ve(),h=d.editable&&!u,[p,m]=j.useState(r),[g,y]=j.useState(),b=j.useRef(null),x=j.useRef(!1),w=mu(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(D.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(D.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),f.jsx(D.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 lv({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 Td=({icon:e,label:r,onClick:t,color:n,boxSize:o=6,...i})=>{const{background:s,border:a,colorText:c}=st();return f.jsx(Ge,{label:r,children:f.jsx(D.Flex,{asChild:!0,p:0,border:0,bg:"transparent",children:f.jsx("button",{type:"button","aria-label":r,onClick:t,children:f.jsx(D.Icon,{as:e,boxSize:o,color:n,cursor:t?"pointer":void 0})})})})},dE=`${Kb}
|
|
279
|
+
`;function Zw({options:e,onPick:r,disabled:t,label:n,selected:o}){const{colorMode:i}=Ge(),s=i==="dark",[a,c]=j.useState(!1),[l,d]=j.useState(""),h=(e??[]).map(m=>String(m.value)).filter(m=>m.toLowerCase().includes(l.trim().toLowerCase())),p=()=>{c(!1),d("")};return f.jsxs(f.Fragment,{children:[f.jsx("button",{type:"button",disabled:t,"aria-label":`Add ${n}`,"aria-haspopup":"dialog",onClick:()=>c(!0),style:{width:"100%",padding:"8px 12px",borderRadius:20,border:"1px dashed",borderColor:s?"var(--chakra-colors-gray-600)":"var(--chakra-colors-gray-300)",background:"transparent",color:"inherit",textAlign:"center",cursor:t?"default":"pointer",fontSize:14,opacity:t?.6:1},children:"+ Add tool"}),f.jsx(ko,{active:!0,nodeAddress:"",label:`Add ${n}`,open:a,onClose:p,onBack:p,height:440,filter:f.jsx("input",{"aria-label":`Search ${n}`,placeholder:"Search tools...",value:l,onChange:m=>d(m.target.value),style:{width:"100%",marginTop:14,padding:"10px 14px",borderRadius:20,border:"1px solid",borderColor:s?"var(--chakra-colors-gray-600)":"var(--chakra-colors-gray-200)",background:s?"var(--chakra-colors-gray-700)":"var(--chakra-colors-gray-100)",color:"inherit",fontSize:15,boxSizing:"border-box"}}),children:f.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,width:"100%"},children:[h.map(m=>{const g=(o??[]).includes(m),y="color-mix(in srgb, currentColor 10%, transparent)";return f.jsxs("button",{type:"button","aria-selected":g,onClick:()=>{r(m)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,textAlign:"left",padding:"10px 14px",borderRadius:12,border:0,background:g?y:"transparent",color:"inherit",cursor:"pointer",fontSize:15,fontWeight:g?700:400},onMouseEnter:b=>{g||(b.currentTarget.style.background=s?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.05)")},onMouseLeave:b=>{b.currentTarget.style.background=g?y:"transparent"},children:[f.jsx("span",{style:{flex:1,minWidth:0},children:m}),f.jsx(X.PiCheck,{size:16,"aria-hidden":"true",style:{flexShrink:0,visibility:g?"visible":"hidden"}})]},m)}),h.length===0&&f.jsxs("span",{style:{opacity:.55,fontSize:13,padding:"8px 14px"},children:["No tools match “",l,"”"]})]})})]})}function ti({value:e,kind:r,itemKind:t,nameOnly:n,options:o,accent:i="currentColor",disabled:s,label:a,onChange:c}){const l={display:"flex",gap:6,width:"100%",alignItems:"center"},d={display:"inline-flex",alignItems:"center",background:"transparent",border:0,color:"inherit",cursor:s?"default":"pointer",padding:2,flexShrink:0},u=p=>{try{return JSON.parse(p)}catch{return p}};if(r==="object"){const p=e&&typeof e=="object"&&!Array.isArray(e)?e:{},m=()=>{let g=Object.keys(p).length+1,y=`entry${g}`;for(;Object.prototype.hasOwnProperty.call(p,y);)y=`entry${++g}`;return y};if(n){const g=Object.keys(p),y=b=>{if(b)if(Object.prototype.hasOwnProperty.call(p,b)){const x={...p};delete x[b],c(x)}else c({...p,[b]:{name:b}})};return f.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,width:"100%"},children:[g.length>0&&f.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:g.map((b,x)=>f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 6px 6px 14px",borderRadius:24,color:i,background:"color-mix(in srgb, currentColor 12%, transparent)"},children:[b,f.jsx("button",{type:"button","aria-label":`Remove ${a} ${x+1}`,disabled:s,style:d,onClick:()=>{const w={...p};delete w[b],c(w)},children:f.jsx(X.PiTrash,{size:12,"aria-hidden":"true"})})]},`${x}:${b}`))}),f.jsx(Zw,{options:o,onPick:y,disabled:s,label:a,selected:g})]})}return f.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,width:"100%"},children:[Object.entries(p).map(([g,y],b)=>f.jsxs("div",{style:l,children:[f.jsx("input",{style:{flex:1,minWidth:0},"aria-label":`${a} key ${b+1}`,placeholder:"key",value:g,disabled:s,onChange:x=>{const w={};for(const[v,C]of Object.entries(p))w[v===g?x.target.value:v]=C;c(w)}}),f.jsx("input",{style:{flex:1,minWidth:0},"aria-label":`${a} value ${b+1}`,placeholder:"value",value:typeof y=="string"?y:JSON.stringify(y),disabled:s,onChange:x=>c({...p,[g]:u(x.target.value)})}),f.jsx("button",{type:"button","aria-label":`Remove ${a} ${b+1}`,disabled:s,style:d,onClick:()=>{const x={...p};delete x[g],c(x)},children:f.jsx(X.PiTrash,{size:12,"aria-hidden":"true"})})]},`${b}:${g}`)),f.jsx("button",{type:"button",disabled:s,onClick:()=>c({...p,[m()]:""}),children:"Add entry"})]})}const h=Array.isArray(e)?e:[];return f.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,width:"100%"},children:[h.map((p,m)=>f.jsxs("div",{style:{...l,alignItems:"flex-start"},children:[f.jsx("textarea",{style:{flex:1,minWidth:0},"aria-label":`${a} item ${m+1}`,rows:2,value:typeof p=="string"?p:JSON.stringify(p,null,2),disabled:s,onChange:g=>{const y=[...h];y[m]=u(g.target.value),c(y)}}),f.jsx("button",{type:"button","aria-label":`Remove ${a} ${m+1}`,disabled:s,style:d,onClick:()=>c(h.filter((g,y)=>y!==m)),children:f.jsx(X.PiTrash,{size:12,"aria-hidden":"true"})})]},m)),f.jsx("button",{type:"button",disabled:s,onClick:()=>c([...h,t==="string"?"":{}]),children:"Add item"})]})}function Ju({request:e,property:r,config:t,value:n,disabled:o}){var Je,st,Ye,We,Ze,me,Ae;const{callbacks:i,structured:s,references:a}=j.useContext(Ft),{themeColor:c}=Ge(),{background:l}=lt(),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),[A,I]=j.useState(""),[M,k]=j.useState(),_=((Je=t.$options)==null?void 0:Je.$source)==="callback",$=i.resolveFormOptions,{data:N,address:W,nodeAddress:T,nodeId:Q}=e;j.useEffect(()=>(S(!1),R(!1),()=>{var oe;(oe=v.current)==null||oe.abort(),v.current=void 0}),[W,T,Q,o,h,t.$control,(st=t.$upload)==null?void 0:st.accept,(Ye=t.$upload)==null?void 0:Ye.maxSizeBytes]);const ue=j.useRef(N);ue.current=N;const K=JSON.stringify([W,Q,(We=t.$options)!=null&&We.$dependsOn?t.$options.$dependsOn.map(oe=>$e(N,oe)):$e(N,T)]);j.useEffect(()=>{m(h),y("")},[h,W,Q]),j.useEffect(()=>{if(!_)return;const oe=new AbortController;return Promise.resolve().then(()=>{if(!$)throw new Error("No options resolver configured");return $({address:W,nodeAddress:T,nodeId:Q,data:an(ue.current),signal:oe.signal})}).then(ie=>{if(!Array.isArray(ie)||ie.some(Ne=>!Ne||typeof Ne.label!="string"||!["string","number","boolean"].includes(typeof Ne.value)&&Ne.value!==null))throw new Error("Invalid options response");oe.signal.aborted||k({key:K,options:ie})}).catch(ie=>{oe.signal.aborted||k({key:K,options:[],error:ie instanceof Error?ie.message:"Options unavailable"})}),()=>oe.abort()},[_,$,K,W,T,Q,b]);const ce=_&&(M==null?void 0:M.key)!==K,V=_?(M==null?void 0:M.key)===K?M.options:[]:r.type.kind==="null"?[{label:"Null",value:null}]:r.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:On(r.type),re=r.type.kind==="array",q=r.type.kind==="array"?(Ze=r.type.items)==null?void 0:Ze.kind:void 0,F=r.type.kind==="object"?r.type.additionalProperties:void 0,G=!!F&&F.kind==="object"&&!!F.properties&&Object.keys(F.properties).length===1&&((me=F.properties.name)==null?void 0:me.kind)==="string"||!!n&&typeof n=="object"&&!Array.isArray(n)&&Object.keys(n).length>0&&Object.entries(n).every(([oe,ie])=>!!ie&&typeof ie=="object"&&!Array.isArray(ie)&&ie.name===oe&&Object.keys(ie).length===1),se=((V==null?void 0:V.length)??0)===0&&!ce,U=(t.$control==="upload"?"upload":s&&u||t.$control==="checkbox"?"pills":t.$control)??(V?re||r.type.kind==="boolean"?"pills":"select":r.type.kind==="boolean"?"checkbox":u?"textarea":"input"),Y=!r.optional||!!t.$requiredWhen&&Eo(t.$requiredWhen,N),le=Y?"Required":"Optional",ne=U!=="upload"&&!!(a!=null&&a.length)&&typeof n=="string"&&n.includes("{{"),de=g||_&&(M==null?void 0:M.key)===K&&M.error||!ne&&Qt(r.type,n,Y),xe=Ht(t.$label??W.split(".").pop()),he=oe=>{var ie;if(!(o||Object.is(oe,n)))try{(ie=i.onFormChange)==null||ie.call(i,{...e,previousValue:n,value:oe}),y("")}catch(Ne){y(Ne instanceof Error?Ne.message:"Unable to update field")}},H=j.useRef(he);j.useLayoutEffect(()=>{H.current=he});const J=()=>{if(u){try{const Qe=p===""&&r.optional?void 0:JSON.parse(p),Ee=Qt(r.type,Qe,Y);if(Ee){y(Ee);return}he(Qe)}catch{y("Enter valid JSON")}return}const oe=r.type.kind==="number"||r.type.kind==="integer",ie=p===""&&r.optional?void 0:oe&&p!==""?Number(p):p,Ne=Qt(r.type,ie,Y);if(oe&&Ne&&p!==""){y(Ne);return}he(ie)},fe=async oe=>{var Ne,Qe,Ee;if(o||v.current||!oe.length)return;const ie=new AbortController;v.current=ie,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(!re&&oe.length!==1)throw new Error("Choose one file for this field.");if(!i.uploadFormFile)throw new Error("No file upload handler configured.");const Le=(Qe=(Ne=t.$upload)==null?void 0:Ne.accept)==null?void 0:Qe.split(",").map(pt=>pt.trim().toLowerCase()).filter(Boolean);for(const pt of oe){if(((Ee=t.$upload)==null?void 0:Ee.maxSizeBytes)!==void 0&&pt.size>t.$upload.maxSizeBytes)throw new Error(`${pt.name} exceeds the file size limit.`);if(Le!=null&&Le.length&&!Le.some(At=>At.startsWith(".")?pt.name.toLowerCase().endsWith(At):At.endsWith("/*")?pt.type.toLowerCase().startsWith(At.slice(0,-1)):pt.type.toLowerCase()===At))throw new Error(`${pt.name} is not an accepted file type.`)}const ct=await Promise.all(oe.map(async pt=>{const At=await i.uploadFormFile({...e,data:an(N),file:pt,signal:ie.signal});if(typeof At!="string")throw new Error("Upload handler must return an HTTP or HTTPS URL.");let zt;try{zt=new URL(At)}catch{throw new Error("Upload handler must return an HTTP or HTTPS URL.")}if(!["http:","https:"].includes(zt.protocol)||zt.username||zt.password)throw new Error("Upload handler must return an HTTP or HTTPS URL.");return At}));if(ie.signal.aborted||v.current!==ie)return;const Ue=re?[...Array.isArray(n)?n:[],...ct]:ct[0],ht=Qt(r.type,Ue,Y);if(ht)throw new Error(ht);H.current(Ue)}catch(Le){ie.signal.aborted||y(Le instanceof Error?Le.message:"Unable to upload file."),ie.abort()}finally{v.current===ie&&(v.current=void 0,S(!1))}},ve={id:d,disabled:o,"aria-label":xe,"aria-required":Y,"aria-invalid":!!de,"aria-describedby":de?`${d}-error`:void 0},Re=Ie(c);return f.jsxs("div",{"data-form-field":W,"data-flow-property":W.slice(T.length+1),children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[f.jsxs("label",{htmlFor:d,children:[xe,Y?" *":""]}),r.optional&&n!==void 0&&f.jsx("button",{type:"button","aria-label":`Reset ${xe}`,title:`Reset ${xe}`,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:()=>he(void 0),children:f.jsx(X.PiArrowCounterClockwise,{size:14})})]}),!!(a!=null&&a.length)&&!u&&U!=="upload"&&f.jsx(Kw,{label:xe,value:n,references:a,disabled:o,onChange:he}),U==="upload"?f.jsxs("div",{"data-form-upload":re?"multiple":"single","aria-busy":C,style:{"--flow-upload-surface":Ie(l),outline:E?"2px dashed var(--flow-form-input-background)":void 0,borderRadius:"var(--flow-form-input-radius)"},onDragOver:oe=>{oe.preventDefault(),oe.stopPropagation(),!o&&!C&&(oe.dataTransfer.dropEffect="copy",R(!0))},onDragLeave:oe=>{oe.currentTarget.contains(oe.relatedTarget)||R(!1)},onDrop:oe=>{oe.preventDefault(),oe.stopPropagation(),R(!1),fe(Array.from(oe.dataTransfer.files))},children:[f.jsx("input",{ref:w,type:"file",hidden:!0,"aria-label":`Upload ${xe}`,accept:(Ae=t.$upload)==null?void 0:Ae.accept,multiple:re,disabled:o||C,onChange:oe=>{const ie=Array.from(oe.target.files??[]);oe.target.value="",fe(ie)}}),f.jsxs("div",{"data-upload-items":"",children:[(re?Array.isArray(n)?n:[]:n?[n]:[]).map((oe,ie)=>f.jsxs("div",{"data-upload-preview":"",children:[typeof oe=="string"&&Sr(oe)&&f.jsxs("a",{href:oe,target:"_blank",rel:"noopener noreferrer","aria-label":`${xe} file ${ie+1}`,children:[f.jsx(X.PiFile,{size:32,"aria-hidden":"true"}),f.jsx(dr,{name:oe,size:120,onError:Ne=>{Ne.currentTarget.style.visibility="hidden"}})]}),f.jsxs("div",{"data-upload-actions":"",children:[!re&&f.jsx(Oe,{"aria-label":`Replace ${xe}`,title:`Replace ${xe}`,icon:f.jsx(X.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>{var Ne;return(Ne=w.current)==null?void 0:Ne.click()}}),f.jsx(Oe,{"aria-label":`Remove ${xe} file ${ie+1}`,title:"Remove file",icon:f.jsx(X.PiTrash,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>he(re&&Array.isArray(n)?n.filter((Ne,Qe)=>Qe!==ie):"")})]})]},`${ie}:${oe}`)),(re||!n)&&f.jsx("button",{...ve,type:"button","data-upload-drop":"",title:`Upload ${xe}`,disabled:o||C,onClick:()=>{var oe;return(oe=w.current)==null?void 0:oe.click()},children:f.jsx(X.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&f.jsx("span",{role:"status",children:"Uploading..."})]}):ne?null:U==="select"?f.jsx("div",{"data-form-select":"",children:f.jsxs(Ot,{...ve,disabled:o||ce||!!(M!=null&&M.error),labelCase:"preserve",value:String((V==null?void 0:V.findIndex(oe=>Object.is(oe.value,n)))??-1),onValueChange:oe=>{const ie=V==null?void 0:V[Number(oe)];ie&&he(ie.value)},children:[f.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):le}),V==null?void 0:V.map((oe,ie)=>f.jsx("option",{value:ie,...oe.description?{description:oe.description}:{},children:Ht(oe.label)||oe.label},ie))]})}):U==="pills"?f.jsx("div",{id:d,role:"group","aria-label":xe,"aria-describedby":ve["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:r.type.kind==="object"&&G?f.jsx(ti,{value:n,kind:"object",nameOnly:!0,options:V,accent:Re,disabled:o,label:xe,onChange:he}):se?re&&q==="string"?f.jsxs(f.Fragment,{children:[(Array.isArray(n)?n:[]).map((oe,ie)=>f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"8px 8px 8px 16px",borderRadius:24,border:0,color:Re,background:"color-mix(in srgb, currentColor 12%, transparent)"},children:[String(oe),f.jsx("button",{type:"button","aria-label":`Remove ${xe} ${ie+1}`,disabled:o,style:{display:"inline-flex",alignItems:"center",background:"transparent",border:0,color:"inherit",cursor:o?"default":"pointer",padding:2},onClick:()=>he(n.filter((Ne,Qe)=>Qe!==ie)),children:f.jsx(X.PiTrash,{size:12,"aria-hidden":"true"})})]},ie)),f.jsx("input",{"aria-label":`Add ${xe}`,placeholder:le,value:A,disabled:o,onChange:oe=>I(oe.target.value),onKeyDown:oe=>{if(oe.key!=="Enter")return;oe.preventDefault();const ie=A.trim();if(!ie)return;const Ne=Array.isArray(n)?n:[];if(Ne.some(Qe=>String(Qe)===ie)){I("");return}he([...Ne,ie]),I("")}}),f.jsx("button",{type:"button",disabled:o||!A.trim(),onClick:()=>{const oe=A.trim();if(!oe)return;const ie=Array.isArray(n)?n:[];ie.some(Ne=>String(Ne)===oe)||he([...ie,oe]),I("")},children:"Add"})]}):re?f.jsx(ti,{value:n,kind:"array",itemKind:q,disabled:o,label:xe,onChange:he}):r.type.kind==="object"?f.jsx(ti,{value:n,kind:"object",nameOnly:G,disabled:o,label:xe,onChange:he}):f.jsx("textarea",{...ve,placeholder:le,value:p,onChange:oe=>m(oe.target.value),onBlur:J}):f.jsxs(f.Fragment,{children:[V==null?void 0:V.map((oe,ie)=>{const Ne=re?Array.isArray(n)&&n.includes(oe.value):Object.is(n,oe.value);return f.jsx("button",{type:"button",disabled:o||ce,"aria-pressed":Ne,style:{padding:"8px 16px",borderRadius:24,border:0,color:Ne?Re:"inherit",background:Ne?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>he(re?Ne?n.filter(Qe=>Qe!==oe.value):[...Array.isArray(n)?n:[],oe.value]:oe.value),children:Ht(oe.label)||oe.label},ie)}),ce&&f.jsx("span",{role:"status",children:"Loading..."})]})}):U==="textarea"?f.jsx("textarea",{...ve,placeholder:le,value:p,onChange:oe=>m(oe.target.value),onBlur:J}):f.jsx("input",{...ve,placeholder:le,type:r.type.kind==="number"||r.type.kind==="integer"?"number":"text",step:r.type.kind==="integer"?1:"any",value:p,onChange:oe=>m(oe.target.value),onBlur:J,onKeyDown:oe=>{oe.key==="Enter"&&J(),oe.key==="Escape"&&m(n===void 0?"":String(n))}}),de&&f.jsx("div",{role:"alert",id:`${d}-error`,children:de}),_&&(M==null?void 0:M.error)&&f.jsx("button",{type:"button",disabled:o,onClick:()=>{k(void 0),x(b+1)},children:"Retry"})]})}function Hd({nodeAddress:e,structured:r=!1}){return r?f.jsx(Xw,{nodeAddress:e},e):f.jsx(kd,{nodeAddress:e})}function Xw({nodeAddress:e}){var u,h,p;const r=j.useContext(Ft),[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 Ab(r.data,i,o,[{data:{id:e,type:"objectView"}}])},[r.data,i,o,e]);if(!s)return f.jsx(kd,{nodeAddress:e});const a=t.findIndex(m=>!s.containers.has(m)),c=a<0?t:t.slice(0,a),l=(c==null?void 0:c.at(-1))??e,d=(p=[...s.slots.values()].find(m=>m.nodeId===l))==null?void 0:p.label;return f.jsxs(Ft.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(Oe,{"aria-label":"Back to parent fields",title:"Back to parent fields",icon:f.jsx(X.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:()=>n(c.slice(0,-1))}),f.jsx("strong",{style:{minWidth:0,overflowWrap:"anywhere"},children:Ht(d)})]}),f.jsx(kd,{nodeAddress:l,onOpen:m=>n([...c,m])},l)]})}function kd({nodeAddress:e,onOpen:r}){var S,E;const{data:t,schema:n,callbacks:o,bindings:i,editable:s,renderForm:a,structured:c}=j.useContext(Ft),{readOnly:l,config:d,colorMode:u}=Ge(),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=$e(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 A;return Eo((A=m.fields[R])==null?void 0:A.$visibleWhen,t)}),w=x.length>8||x.some(([R])=>{var A;return(A=m.fields[R])==null?void 0:A.$section}),v=new Map;for(const R of x){const[A,I]=R,M=w?Ht(((E=m.fields[A])==null?void 0:E.$section)??(I.type.kind==="object"||I.type.kind==="array"?A:I.optional?"Options":"General")):"";v.has(M)||v.set(M,[]),v.get(M).push(R)}const C=([R,A])=>f.jsx(Ju,{request:{data:t,address:b?g:`${g}.${R}`,nodeAddress:g,nodeId:typeof(y==null?void 0:y.id)=="string"?y.id:void 0},property:A,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(Jw,{nodeAddress:e,onOpen:r}),!c&&p&&m.type.additionalProperties&&x.length===0&&f.jsx(Ju,{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,A])=>w&&A.length>1?f.jsxs("details",{open:!0,children:[f.jsxs("summary",{children:[f.jsx("span",{children:R}),f.jsx(X.PiCaretDown,{size:16,"aria-hidden":"true"})]}),A.map(C)]},R):A.map(C))]})}function Mb(e){const{viewData:r}=j.useContext(Ft),{nodeById:t,edgeById:n,parentIds:o}=tr();if(r){const i=$e(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",...mb(r==="transparent"?"currentColor":r,t,".flow-sdk-node:hover &",!t)}}function Tb({label:e,value:r,options:t,onChange:n,disabled:o}){var i;return f.jsxs(Ot,{"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 Ud({nodeId:e,edgeId:r,value:t,open:n,onOpenChange:o,onSelect:i}){const{callbacks:s,readOnly:a,themeColor:c,colorMode:l}=Ge(),{background:d,backgroundSecondary:u,border:h,colorText:p,colorInactive:m}=lt(),g=l==="dark"?ln:Ie(m),y=j.useRef(null),b=j.useRef(null),x=j.useRef(0),[w,v]=j.useState(!1),[C,S]=j.useState("icons"),[E,R]=j.useState([]),[A,I]=j.useState("loading"),[M,k]=j.useState(""),[_,$]=j.useState(0),[N,W]=j.useState(""),[T,Q]=j.useState(""),[ue,K]=j.useState(!1);j.useEffect(()=>()=>{x.current++},[]),j.useEffect(()=>{if(!w)return;let U=!0;return import("react-icons/pi").then(Y=>{U&&(R(Object.keys(Y).filter(le=>le.startsWith("Pi")).sort()),I("ready"))}).catch(()=>{U&&I("unavailable")}),()=>{U=!1}},[w]),j.useEffect(()=>{var U;a&&((U=y.current)==null||U.close())},[a]),j.useEffect(()=>{var U,Y,le;if(n!==void 0){if(!n||a){(U=y.current)==null||U.close();return}(Y=y.current)!=null&&Y.open||(Q(""),S(t==="PiFileSvg"||t&&Sr(t)?"custom":"icons"),W(t&&!t.startsWith($n)&&Sr(t)?t:""),v(!0),(le=y.current)==null||le.showModal())}},[n,a,t]);const ce=U=>{var Y,le,ne;a||(i?i(U):r?(Y=s.onEdgeIconChange)==null||Y.call(s,r,U):e&&((le=s.onNodeIconChange)==null||le.call(s,e,U)),o==null||o(!1),(ne=y.current)==null||ne.close())},V=E.filter(U=>U.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(M.trim().toLowerCase())),re=36,q=Math.max(1,Math.ceil(V.length/re)),F=Math.min(_,q-1),G=V.slice(F*re,(F+1)*re),se={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${Ie(h)}`,borderRadius:30};return f.jsxs(f.Fragment,{children:[n===void 0&&f.jsx(He,{label:r?"Choose edge icon":"Choose node icon",children:f.jsx(Oe,{"aria-label":r?"Choose edge icon":"Choose node icon",icon:f.jsx(X.PiShapes,{size:20}),size:"sm",variant:"ghost",color:Ie(c),disabled:a,onClick:()=>{var U;Q(""),S(t&&Sr(t)?"custom":"icons"),W(t&&!t.startsWith($n)&&Sr(t)?t:""),v(!0),(U=y.current)==null||U.showModal()}})}),f.jsx(D.chakra.dialog,{ref:y,"aria-label":r?"Choose edge icon":"Choose node icon",css:mr(Ie(d),Ie(h)),onClose:()=>{v(!1),o==null||o(!1),x.current++,K(!1)},onClick:U=>{U.stopPropagation(),U.target===U.currentTarget&&U.currentTarget.close()},onKeyDown:U=>U.stopPropagation(),style:{margin:"auto",padding:12,width:336,maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",borderRadius:30,background:Ie(d),color:Ie(p)},children:w&&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(He,{label:"Remove icon",children:f.jsx(Oe,{"aria-label":r?"Remove edge icon":"Remove node icon",icon:f.jsx(X.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:a||ue,onClick:()=>ce("")})}),f.jsx(dn,{"aria-label":"Close icon picker",onClick:()=>{var U;return(U=y.current)==null?void 0:U.close()}})]})]}),f.jsxs(D.Tabs.Root,{value:C,onValueChange:({value:U})=>{S(U),Q("")},display:"contents",css:{"--indicator-thickness":"1px"},children:[f.jsx(D.Tabs.List,{"aria-label":"Icon source",width:"100%",borderBottomWidth:0,children:["icons","custom"].map(U=>f.jsx(D.Tabs.Trigger,{value:U,flex:1,minW:0,justifyContent:"center",px:3,py:2,fontSize:"13px",_selected:{color:c,borderColor:g,"--indicator-color":g},children:U==="icons"?"React icons":"Custom SVG"},U))}),f.jsx("input",{ref:b,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:ue||a,onChange:async U=>{var ne;const Y=(ne=U.target.files)==null?void 0:ne[0];if(U.target.value="",!Y)return;const le=++x.current;K(!0),Q("");try{const de=await Dw(Y);le===x.current&&ce(de)}catch(de){le===x.current&&Q(de instanceof Error?de.message:"Unable to read SVG.")}finally{le===x.current&&K(!1)}}}),f.jsx(D.Tabs.Content,{value:C,p:0,style:{display:"grid",gap:8},children:C==="icons"?f.jsxs(f.Fragment,{children:[f.jsx("input",{"aria-label":"Search icons",placeholder:"Search icons...",value:M,onChange:U=>{k(U.target.value),$(0)},style:se}),f.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[G.map(U=>f.jsx("button",{type:"button","aria-label":`Choose ${U}`,"aria-pressed":t===U,title:U,onClick:()=>ce(U),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${t===U?2:1}px solid ${Ie(t===U?c:h)}`,background:Ie(t===U?d:u),color:"inherit",cursor:"pointer"},children:f.jsx(dr,{name:U,size:24})},U)),G.length===0&&f.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:A==="loading"?"Loading icons...":A==="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:[V.length," icons · ",F+1," / ",q]}),f.jsxs("div",{style:{display:"flex",gap:4},children:[f.jsx(He,{label:"Previous icons",children:f.jsx(Oe,{"aria-label":"Previous icons",icon:f.jsx(X.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:F===0,onClick:()=>$(F-1)})}),f.jsx(He,{label:"Next icons",children:f.jsx(Oe,{"aria-label":"Next icons",icon:f.jsx(X.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:F+1>=q,onClick:()=>$(F+1)})})]})]})]}):f.jsxs(f.Fragment,{children:[t&&Sr(t)&&f.jsx(dr,{name:t,size:64}),f.jsxs("button",{type:"button",disabled:ue||a,onClick:()=>{var U;return(U=b.current)==null?void 0:U.click()},style:{...se,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[f.jsx(X.PiUploadSimple,{}),ue?"Uploading...":"Upload SVG"]}),f.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:U=>{U.preventDefault(),!(ue||a)&&(!Sr(N.trim())||N.trim().startsWith($n)?Q("Enter an HTTP or HTTPS image URL."):ce(N.trim()))},children:[f.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:N,disabled:ue||a,onChange:U=>W(U.target.value),style:{...se,flex:1,minWidth:0}}),f.jsx(He,{label:"Apply URL",children:f.jsx(Oe,{type:"submit","aria-label":"Apply URL",icon:f.jsx(X.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:ue||a||!N.trim(),style:{flexShrink:0}})})]})]})})]}),T&&f.jsx("div",{role:"alert",style:{fontSize:13},children:T})]})})]})}const po=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500",ln],Ib=["gray.900",ln,"gray.600","gray.200","white"];function Nb(){const{config:e}=Ge(),r=e.selectionToolbar||{},t=new Set(r.hide||[]);return{palette:r.palette||po,show:n=>!t.has(n)}}function Nt(){const{border:e}=lt();return f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:e})}function kr({value:e,placeholder:r,ariaLabel:t,width:n="140px",type:o="text",min:i,disabled:s=!1,onCommit:a}){const{colorText:c}=lt(),[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(D.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 Gr({colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:s,colorText:a}=lt(),[c,l]=j.useState(!1),d=j.useId(),u=j.useRef(null),h=r??e[0]??"transparent",p=jo(f.jsx(Gr,{colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i}));return f.jsx(nn.Provider,{value:null,children:f.jsxs(D.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(He,{label:`${t}: ${h}`,children:f.jsx(D.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:Ie(h),...h==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${Ie(a)}`,outlineOffset:"1px",onClick:()=>l(m=>!m)})}),c&&f.jsxs(D.HStack,{id:d,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(m=>{const g=r===m;return f.jsx(He,{label:`${t}: ${m}`,children:f.jsx(D.Box,{as:"button","aria-label":`${t} ${m}`,"aria-pressed":g,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Ie(m),...m==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:g?`2px solid ${Ie(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(He,{label:`Reset ${t.toLowerCase()}`,children:f.jsx(Oe,{"aria-label":`Reset ${t}`,icon:f.jsx(D.Icon,{as:X.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:s,onClick:()=>{var m;o(),l(!1),(m=u.current)==null||m.focus()}})})]})]})})}function Ob({edgeId:e,onClose:r}){var p;const{callbacks:t,themeColor:n,config:o}=Ge(),{colorInactive:i}=lt(),{edgeById:s}=tr(),{palette:a,show:c}=Nb(),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:X.PiLineSegment,label:"Solid"},{key:"dashed",icon:X.PiLineSegments,label:"Dashed"},{key:"animated",icon:X.PiFastForward,label:"Animated"}];return f.jsxs(f.Fragment,{children:[f.jsx(dn,{onClick:r}),c("label")&&f.jsxs(f.Fragment,{children:[f.jsx(Nt,{}),f.jsx(kr,{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(Nt,{}),h.map(m=>f.jsx(He,{label:m.label,children:f.jsx(Oe,{"aria-label":`Edge style ${m.key}`,"aria-pressed":u===m.key,icon:f.jsx(D.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(Tb,{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(Ot,{"aria-label":"Edge shape",title:`Edge shape: ${(l==null?void 0:l.type)??"Default"}`,icon:f.jsx(X.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(Nt,{}),f.jsx(Ud,{edgeId:e,value:l==null?void 0:l.icon},e),f.jsx(kr,{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(Nt,{}),f.jsx(Gr,{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(Nt,{}),f.jsx(He,{label:"Delete edge",children:f.jsx(Oe,{"aria-label":"Delete edge",icon:f.jsx(D.Icon,{as:X.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var m;(m=t.onEdgeDelete)==null||m.call(t,e,l),r()}})})]})]})}function $b({ids:e,showDivider:r=!0}){const{callbacks:t,config:n,nodeGridOptions:o,fillRadiusEditedIds:i}=Ge(),{colorInactive:s}=lt(),{nodeById:a}=tr(),[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(Nt,{}),f.jsx(D.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:f.jsxs(Ot,{icon:f.jsx(D.Icon,{as:Nv.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(kr,{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 qb({ids:e,onClose:r,afterLabel:t}){var se,U,Y,le,ne,de,xe,he;const{callbacks:n,colorMode:o,themeColor:i,config:s,setNodeViewMode:a}=Ge(),{colorText:c,colorInactive:l}=lt(),{nodeById:d,parentIds:u}=tr(),{palette:h,show:p}=Nb(),m=e.length===1,[g,y]=j.useState(""),b=m?(se=d.get(e[0]))==null?void 0:se.data:void 0,x=e.map(H=>{var J,fe;return((fe=(J=d.get(H))==null?void 0:J.data.config)==null?void 0:fe.typeView)??""}),w=x.some(H=>H!==x[0]),v=w?"mixed":x[0]??"",C=[{value:"text",label:"Text",view:"text",icon:X.PiTextT},{value:"icon-label",label:"Icon Label",view:"icon-label",icon:X.PiShapes},{value:"object",label:"Object",view:"object",icon:X.PiBracketsCurly},{value:"grid",label:"Grid",view:"grid",icon:X.PiGridFour},{value:"parent",label:"Parent",view:"parent",icon:X.PiStack},{value:"media",label:"Media",view:"icon-label",icon:X.PiFileSvg},{value:"content",label:"Content",view:"object",icon:X.PiTextAlignLeft},{value:"prompt",label:"Prompt",view:"prompt",icon:X.PiTextAlignLeft}].filter(H=>H.view!=="prompt"||!!n.onPromptSubmit),S=e.some(H=>{var Re,Je,st;const J=(Re=d.get(H))==null?void 0:Re.data,fe=J?(Je=s.customViews)==null?void 0:Je[J.type]:void 0,ve=(fe==null?void 0:fe.wrapsDefault)===!0;return J&&(u.has(H)||((st=J.config)==null?void 0:st.parentContainer)||!!fe&&!ve)}),E=(U=b==null?void 0:b.config)==null?void 0:U.collapsed,R=Mb(e[0]),A=H=>{var J,fe,ve;return(((fe=(J=d.get(H))==null?void 0:J.data.viewProps)==null?void 0:fe.outline)??(u.has(H)?(ve=s.parentNodeStyle)==null?void 0:ve.outline:!1))===!0},I=e.every(A),M=!I&&e.some(A),k=H=>{var J;return((J=d.get(H))==null?void 0:J.data.isNodeAnimated)===!0},_=e.every(k),$=!_&&e.some(k),N=e.map(H=>{var J;return((J=d.get(H))==null?void 0:J.data.nodeAnimationVariant)??"traveling"}),W=N.every(H=>H===N[0])?N[0]:"",T=H=>e.forEach(H),[Q,ue]=j.useState(!1),K=Q&&p("color")&&p("borderColor"),ce=H=>{var J,fe,ve;return(((fe=(J=d.get(H))==null?void 0:J.data.viewProps)==null?void 0:fe.borderStyle)??(u.has(H)?(ve=s.parentNodeStyle)==null?void 0:ve.borderStyle:"solid"))==="dashed"},V=e.every(ce),re=!V&&e.some(ce),q=e.map(H=>{var ve,Re,Je;const J=(ve=d.get(H))==null?void 0:ve.data,fe=u.has(H)?Dn((Re=s.parentNodeStyle)==null?void 0:Re.borderWidth,6):(J==null?void 0:J.type)==="objectView"?3:2;return Dn((Je=J==null?void 0:J.viewProps)==null?void 0:Je.borderWidth,fe)}),F=q.every(H=>H===q[0])?String(q[0]??""):"",G=H=>T(J=>{var fe,ve;K?(fe=n.onNodeBorderColorChange)==null||fe.call(n,J,H):(ve=n.onNodeColorChange)==null||ve.call(n,J,"bg",H)});return f.jsxs(f.Fragment,{children:[f.jsx(dn,{onClick:r}),f.jsx(Nt,{}),m&&p("label")?f.jsx(kr,{ariaLabel:"Node label",placeholder:"Node label",value:(b==null?void 0:b.label)??(b==null?void 0:b.headerTitle)??"",onCommit:H=>{var J;return(J=n.onNodeLabelChange)==null?void 0:J.call(n,e[0],H)}}):f.jsxs(D.Text,{fontSize:"xs",color:c,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),t,p("typeView")&&f.jsxs(Ot,{"aria-label":"Type view",title:S?"Type view is managed by the custom renderer or container":`Type view: ${v||"None (default)"}`,icon:f.jsx(X.PiCards,{size:20}),style:{width:36},value:v,disabled:s.readOnly||s.editable===!1||S,onValueChange:H=>{var fe;const J=(fe=C.find(ve=>ve.value===H))==null?void 0:fe.view;J&&T(ve=>{var Re,Je;(Re=n.onNodeTypeViewChange)==null||Re.call(n,ve,J),a(ve,"default"),(Je=n.onNodeViewToggle)==null||Je.call(n,ve)})},children:[w&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),C.map(H=>f.jsx("option",{value:H.value,children:f.jsxs(D.HStack,{gap:"12px",children:[f.jsx(H.icon,{size:20,"aria-hidden":"true",style:{flexShrink:0}}),f.jsx("span",{children:H.label})]})},H.value))]}),p("style")&&f.jsx($b,{ids:e},e.join("\0")),p("outline")&&f.jsxs(f.Fragment,{children:[f.jsx(Nt,{}),f.jsx(He,{label:I?"Restore node fill":"Remove node fill",children:f.jsx(Oe,{"aria-label":"Toggle node outline","aria-pressed":M?"mixed":I,icon:f.jsx(D.Icon,{as:I?X.PiSquare:X.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:I?i:l,onClick:()=>T(H=>{var J;return(J=n.onNodeOutlineChange)==null?void 0:J.call(n,H,!I)})})})]}),p("color")&&f.jsxs(f.Fragment,{children:[f.jsx(Nt,{}),p("borderColor")&&f.jsx(He,{label:K?"Edit node colors":"Edit node border",children:f.jsx(Oe,{"aria-label":"Edit node border","aria-pressed":K,icon:f.jsx(D.Icon,{as:X.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:K?i:l,bg:K?o==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>ue(H=>!H)})}),f.jsx(Gr,{label:K?"Border color":"Background",colors:h,value:K?((Y=b==null?void 0:b.viewProps)==null?void 0:Y.borderColor)??(m&&u.has(e[0])?(le=s.parentNodeStyle)==null?void 0:le.borderColor:void 0):(ne=b==null?void 0:b.viewProps)==null?void 0:ne.bgColor,onPick:G,onReset:()=>G("")}),K&&p("style")&&f.jsxs(f.Fragment,{children:[f.jsx(Nt,{}),f.jsx(He,{label:V?"Solid border":"Dashed border",children:f.jsx(Oe,{"aria-label":"Toggle dashed border","aria-pressed":re?"mixed":V,icon:f.jsx(D.Icon,{as:V?X.PiLineSegments:X.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:V?i:l,onClick:()=>T(H=>{var J;return(J=n.onNodeBorderStyleChange)==null?void 0:J.call(n,H,V?"solid":"dashed")})})}),f.jsx(kr,{ariaLabel:"Border thickness",placeholder:m?"Auto":"Mixed",width:"64px",type:"number",min:0,value:F,onCommit:H=>T(J=>{var fe;return(fe=n.onNodeBorderWidthChange)==null?void 0:fe.call(n,J,H===""?void 0:Number(H))})})]})]}),p("animation")&&f.jsxs(f.Fragment,{children:[f.jsx(Nt,{}),f.jsx(He,{label:_?"Stop border animation":"Animate node border",children:f.jsx(Oe,{"aria-label":"Toggle node animation","aria-pressed":$?"mixed":_,icon:f.jsx(D.Icon,{as:X.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:_?i:l,onClick:()=>T(H=>{var J;return(J=n.onNodeAnimationChange)==null?void 0:J.call(n,H,!_)})})}),(_||$)&&f.jsx(Tb,{label:"Node animation",value:W,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:s.readOnly,onChange:H=>T(J=>{var fe;return(fe=n.onNodeAnimationVariantChange)==null?void 0:fe.call(n,J,H)})})]}),!K&&p("textColor")&&f.jsxs(f.Fragment,{children:[f.jsx(Nt,{}),f.jsx(Gr,{label:"Text color",colors:Ib,value:(de=b==null?void 0:b.viewProps)==null?void 0:de.textColor,onPick:H=>T(J=>{var fe;return(fe=n.onNodeColorChange)==null?void 0:fe.call(n,J,"text",H)}),onReset:()=>T(H=>{var J;return(J=n.onNodeColorChange)==null?void 0:J.call(n,H,"text","")})})]}),m&&p("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(Nt,{}),f.jsx(Ud,{nodeId:e[0],value:(xe=b==null?void 0:b.config)==null?void 0:xe.icon},e[0]),f.jsx(kr,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((he=b==null?void 0:b.config)==null?void 0:he.icon)||"",onCommit:H=>{var J;return(J=n.onNodeIconChange)==null?void 0:J.call(n,e[0],H)}})]}),m&&R&&p("collapse")&&E!==void 0&&f.jsxs(f.Fragment,{children:[f.jsx(Nt,{}),f.jsx(He,{label:E?"Expand":"Collapse",children:f.jsx(Oe,{"aria-label":E?"Expand node":"Collapse node",icon:f.jsx(D.Icon,{as:E?X.PiArrowsOutLineVertical:X.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:l,onClick:()=>{var H;return(H=n.onNodeCollapse)==null?void 0:H.call(n,e[0],!E)}})})]}),p("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(Nt,{}),f.jsx(He,{label:m?"Delete node":`Delete ${e.length} nodes`,children:f.jsx(Oe,{"aria-label":"Delete selected nodes",icon:f.jsx(D.Icon,{as:X.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:o==="dark"?"red.300":"red.500",onClick:()=>{T(H=>{var J,fe;return(fe=n.onNodeDelete)==null?void 0:fe.call(n,H,((J=d.get(H))==null?void 0:J.data)||{id:H})}),r()}})})]}),f.jsx(He,{label:"Copy selection",children:f.jsx(Oe,{"aria-label":"Copy selection",icon:f.jsx(X.PiCopy,{size:20}),size:"sm",variant:"ghost",color:l,onClick:async()=>{var H;try{await((H=n.onNodesCopy)==null?void 0:H.call(n,e)),y("")}catch(J){y(String(J))}}})}),f.jsx(He,{label:"Duplicate selection",children:f.jsx(Oe,{"aria-label":"Duplicate selection",icon:f.jsx(X.PiCopySimple,{size:20}),size:"sm",variant:"ghost",color:l,disabled:s.readOnly||s.editable===!1,onClick:()=>{var H;try{(H=n.onNodesDuplicate)==null||H.call(n,e),y("")}catch(J){y(String(J))}}})}),g&&f.jsx(D.Text,{role:"alert",fontSize:"xs",children:g})]})}async function Lb(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 Fb(e,r="squeed.svg"){const t=document.createElement("a");t.href=await Lb(e),t.download=r.endsWith(".svg")?r:`${r}.svg`,t.click()}function zb(){const{themeColor:e}=Ge(),[r,t]=j.useState(!1),[n,o]=j.useState("");return f.jsxs(f.Fragment,{children:[f.jsx(He,{label:"Download SVG (current view)",children:f.jsx(Oe,{"aria-label":"Download SVG",icon:f.jsx(X.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 Fb(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 Po({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(D.Box,{position:"relative",bg:s?r:"transparent",minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:s?"30px":0,css:{...s?mr(m,`var(--chakra-colors-${t.replace(".","-")})`):{},...s||o?{"--flow-toolbar-start-width":o?`${u}px`:"0px"}:{}},children:[f.jsx(D.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(D.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(D.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(D.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 Yw(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 kb(e)};const i=await Gd(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 Bb({message:e,onDismiss:r}){const{background:t,colorText:n,border:o}=lt();return!e||typeof document>"u"?null:Vr.createPortal(f.jsxs(D.chakra.div,{role:"alert","aria-atomic":"true",css:mr(Ie(t),Ie(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:Ie(t),color:Ie(n),fontSize:14,lineHeight:1.5},children:[f.jsx(X.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 Kd({showDivider:e=!0,compact:r=!1}={}){const{edgeMode:t,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:s,readOnly:a,themeColor:c,colorMode:l}=Ge(),{edgeById:d}=tr(),{data:u,schema:h,setSchema:p,bindings:m,structured:g}=j.useContext(Ft),y=(g==null?void 0:g.sourceBindings)??m,b=(g==null?void 0:g.sourceSchema)??h,{colorText:x}=lt(),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 A=o?[...d.values()].filter(k=>Vd(o,k.data)).length:0,I=o?`${o.name}: ${b?`${Object.keys(b).length} form types loaded; `:""}${A} invalid or unverified connections`:"",M=jo(f.jsx(Kd,{showDivider:!1,compact:!0}));return f.jsx(nn.Provider,{value:null,children:f.jsxs("span",{style:{display:"contents"},onClickCapture:M,children:[f.jsx(Bb,{message:E,onDismiss:()=>R("")}),e&&f.jsx(Nn,{}),f.jsxs(Ot,{"aria-label":"Edge mode",title:t==="auto"?"Connections: Auto":t==="properties"?"Connections: Properties":"Connections: Nodes",icon:t==="auto"?f.jsx(X.PiGraph,{size:20}):t==="properties"?f.jsx(X.PiTable,{size:20}):f.jsx(X.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(D.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 _,$;(_=k.currentTarget.closest("[popover]"))==null||_.hidePopover(),($=s.onWorkflowConfigurationOpen)==null||$.call(s)},children:[f.jsx(X.PiGear,{}),"Configuration"]})]}),onValueChange:k=>{var $;const _=k==="auto"?"auto":k==="properties"?"properties":"nodes";n(_),($=s.onEdgeModeChange)==null||$.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(He,{label:o?`Replace ${o.name}`:"Upload workflow interface",children:f.jsx(Oe,{"aria-label":"Upload workflow interface",icon:f.jsx(X.PiUploadSimple,{size:20}),color:Ie(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 N,W;const _=(N=k.target.files)==null?void 0:N[0];if(k.target.value="",!_)return;const $=++v.current;S(!0),R("");try{const T=y?await Gd(_,[...new Set(Object.values(y).map(K=>K.schemaType??K.type))]):void 0;if(y&&T){for(const K of Object.values(y))if(!Object.prototype.hasOwnProperty.call(T,K.schemaType??K.type))throw new Error(`Missing form type: ${K.schemaType??K.type}`)}const{contract:Q,schema:ue}=y&&T?{schema:T,contract:{name:_.name,nodes:Object.fromEntries(Object.entries(y).map(([K,ce])=>[K,{type:T[ce.schemaType??ce.type],optional:!1}]))}}:await Yw(_,u);if($!==v.current)return;p==null||p(ue),i(Q),(W=s.onWorkflowContractChange)==null||W.call(s,Q)}catch(T){$===v.current&&R(`${_.name}: ${T instanceof Error?T.message:"Unable to load interface."}`)}finally{$===v.current&&S(!1)}}}),!r&&(I||C)&&f.jsx("span",{role:"status",title:I,style:{color:Ie(x),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:C?"Loading interface...":I}),!r&&o&&f.jsx(He,{label:"Remove workflow interface",children:f.jsx(Oe,{"aria-label":"Remove workflow interface",icon:f.jsx(X.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 Qw=[{value:"BT",label:"Bottom to Up",icon:X.PiArrowUp,flowType:Sn.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:X.PiArrowDown,flowType:Sn.TOP_DOWN},{value:"LR",label:"Left to Right",icon:X.PiArrowRight,flowType:Sn.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:X.PiArrowLeft,flowType:Sn.RIGHT_LEFT}],Db=({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:A,setIsArrayNodeMode:I,isPinned:M,setIsPinned:k,callbacks:_,config:$,readOnly:N}=Ge(),{nodeById:W,edgeById:T,parentIds:Q}=tr(),ue=$.colorMode==="dark",{background:K,border:ce,colorInactive:V,colorText:re,colorActive:q}=lt(),F=ue?ce:"gray.300",G=`var(--chakra-colors-${K.replace(".","-")})`,se=`var(--chakra-colors-${(ue?ce:"gray.300").replace(".","-")})`,[U,Y]=j.useState(!1),[le,ne]=j.useState(!0),de=$.bottomBarCollapsed??le,xe=j.useRef(null),he=So({edge:"bottom",enabled:!M,bounds:xe,inside:[xe]}),H=j.useCallback(Ee=>{const Le=r.current;if(!Le)return;const ct=$.minZoom??.01,Ue=$.maxZoom??1.5,ht=.02;let pt=Le.zoom();switch(Ee){case"increase":pt=Math.min(Ue,pt+ht),Le.zoom(pt),Le.center(!1);break;case"decrease":pt=Math.max(ct,pt-ht),Le.zoom(pt),Le.center(!1);break;case"reset":Le.fit(50);break}},[r,$.minZoom,$.maxZoom]),J=$.renderSelectedNodeToolbar,fe=p.length>0&&!!J,ve=j.useMemo(()=>fe?p.map(Ee=>{var ct;return{...((ct=W.get(Ee))==null?void 0:ct.data)??{id:Ee},isParent:Q.has(Ee)}}):[],[fe,p,W,Q]),Re=j.useCallback(()=>{var Ee;m([]),(Ee=_.onNodeDeselect)==null||Ee.call(_)},[m,_]),Je=$.renderSelectedEdgeToolbar,st=!!g&&!!Je,Ye=j.useMemo(()=>{var Ee;return!st||!g?null:((Ee=T.get(g))==null?void 0:Ee.data)??{id:g}},[st,g,T]),We=j.useCallback(()=>{var Ee;y(null),(Ee=_.onEdgeDeselect)==null||Ee.call(_)},[y,_]),Ze=$.selectionToolbar!==!1&&!N,me=Ze&&!!g&&!Je,Ae=Ze&&!me&&p.length>0&&!J,oe=me||Ae,ie=M||he||U||oe||$.bottomBarCollapsed===!1;j.useEffect(()=>{p.length||g?a(!1):N||$.bottomBarCollapsed===void 0&&ne(!s)},[s,p.length,g,N,a,$.bottomBarCollapsed]);const Ne=$.renderBottomBar,Qe=Ow();return Ne?f.jsxs(f.Fragment,{children:[fe&&f.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:J({selectedNodeIds:p,selectedNodeData:ve,onDeselect:Re})}),st&&Ye&&f.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Je({edgeId:g,edgeData:Ye,onDeselect:We})}),f.jsx(D.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:Ne({zoomIn:()=>H("increase"),zoomOut:()=>H("decrease"),resetZoom:()=>H("reset"),direction:c,isZoomMode:b,setIsZoomMode:x,isMultiSelectMode:w,setIsMultiSelectMode:v,isDragMode:C,setIsDragMode:S,isEdgeHandlesEnabled:E,setIsEdgeHandlesEnabled:R,isArrayNodeMode:A,setIsArrayNodeMode:I,selectedNodeIds:p,selectedNodeData:ve,selectedEdgeId:g,selectedEdgeData:Ye,onNodeDeselect:Re,onEdgeDeselect:We,callbacks:_})})]}):f.jsxs(nn.Provider,{value:Qe,children:[fe&&f.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:J({selectedNodeIds:p,selectedNodeData:ve,onDeselect:Re})}),st&&Ye&&f.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Je({edgeId:g,edgeData:Ye,onDeselect:We})}),f.jsx(D.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:ie?"translateY(0)":"translateY(100%)",pointerEvents:ie?"auto":"none",visibility:ie?"visible":"hidden",opacity:ie?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(D.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(Po,{background:K,border:ue?ce:"gray.300",children:f.jsxs(D.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[me?f.jsx(Ob,{edgeId:g,onClose:We}):Ae?f.jsx(qb,{ids:p,onClose:Re}):null,f.jsxs("div",{style:{display:me||Ae?"none":"contents"},children:[f.jsxs("span",{style:{display:$.bottomBarNavigation===!1?"none":"contents"},children:[f.jsx(He,{label:M?"Unpin":"Pin",children:f.jsx(Oe,{"aria-label":"Pin","aria-pressed":M,icon:f.jsx(D.Icon,{as:M?X.PiPushPinFill:X.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:M?t:V,onClick:()=>{k(!M),Y(!1)}})}),f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(He,{label:"Zoom Out",children:f.jsx(Oe,{"aria-label":"Zoom out",rememberAction:!1,icon:f.jsx(D.Icon,{as:X.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:re,onClick:()=>H("decrease")})}),f.jsx(He,{label:"Zoom In",children:f.jsx(Oe,{"aria-label":"Zoom in",rememberAction:!1,icon:f.jsx(D.Icon,{as:X.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:re,onClick:()=>H("increase")})}),f.jsx(He,{label:"Reset Zoom",children:f.jsx(Oe,{"aria-label":"Reset zoom",rememberAction:!1,icon:f.jsx(D.Icon,{as:X.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:re,onClick:()=>H("reset")})}),de&&f.jsx($w,{visibleActions:h?["Collision mode","Fill",...h.fill?["Grid adjustment"]:[]]:[],divider:f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"})})]}),f.jsxs("span",{style:{display:de?"none":"contents"},children:[f.jsxs("span",{style:{display:$.bottomBarNavigation===!1?"none":"contents"},children:[$.edgeHandles!==!1&&f.jsx(He,{label:E?"Draw Mode On (V)":"Draw Mode Off (V)",children:f.jsx(Oe,{"aria-label":"Toggle draw mode","aria-keyshortcuts":"V","aria-pressed":E,icon:f.jsx(D.Icon,{as:X.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:E?t:V,onClick:()=>R(!E)})}),f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(He,{label:b?"Zoom Mode (z)":"Pan Mode (z)",children:f.jsx(Oe,{"aria-label":"Toggle zoom mode",icon:f.jsx(D.Icon,{as:b?X.PiMagnifyingGlassPlus:X.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:b?t:V,onClick:()=>x(!b)})}),f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(He,{label:w?"Multi-Select On (m)":"Multi-Select Off (m)",children:f.jsx(Oe,{"aria-label":"Toggle multi-select",icon:f.jsx(D.Icon,{as:X.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:w?t:V,onClick:()=>v(!w)})}),f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(He,{label:C?"Drag Mode On (d)":"Drag Mode Off (d)",children:f.jsx(Oe,{"aria-label":"Toggle drag mode",icon:f.jsx(D.Icon,{as:X.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:C?t:V,onClick:()=>S(!C)})})]}),$.bottomBarNavigation===!1&&(e===void 0?f.jsx(so,{}):e?Vr.createPortal(f.jsx(so,{}),e):null),$.bottomBarExtra&&f.jsxs(f.Fragment,{children:[$.bottomBarNavigation!==!1&&f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),$.bottomBarExtra]}),f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),f.jsx(Sb,{})]}),f.jsx("span",{style:{display:$.bottomBarNavigation===!1||de&&!h?"none":"contents"},children:f.jsx(so,{})}),f.jsxs("span",{style:{display:de?"none":"contents"},children:[f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),f.jsx(Cb,{}),l!=="properties"&&f.jsxs(f.Fragment,{children:[f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(He,{label:A?"Array Mode [ ]":"Set Mode { }",children:f.jsx(Oe,{"aria-label":"Toggle array mode",icon:f.jsx(D.Icon,{as:A?X.PiBracketsSquare:X.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:A?t:V,onClick:()=>{var Le;const Ee=!A;I(Ee),(Le=_.onArrayModeChange)==null||Le.call(_,Ee)}})})]}),f.jsx(Kd,{}),!N&&f.jsxs("span",{style:{display:s?"contents":"none"},children:[f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Gr,{label:"Graph theme",colors:po,value:t,includeTransparent:!1,onPick:Ee=>{var Le;n(Ee),(Le=_.onThemeColorChange)==null||Le.call(_,Ee)}})]}),!N&&f.jsxs(f.Fragment,{children:[f.jsx(D.Icon,{as:X.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),f.jsx(Gr,{label:"Graph edge color",colors:po,value:o||(ue?"gray.500":ln),onPick:i,onReset:()=>i("")}),f.jsx(D.Icon,{as:X.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"})]}),f.jsx(jb,{})]}),f.jsx(D.Icon,{mx:-1,as:X.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(He,{label:de?"Expand toolbar":"Collapse toolbar",children:f.jsx(Oe,{"aria-label":"Toggle toolbar collapse",rememberAction:!1,icon:f.jsx(D.Icon,{as:de?X.PiCaretRight:X.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:V,onClick:()=>{var Ee;$.bottomBarCollapsed===void 0&&ne(!de),a(de),(Ee=_.onBottomBarCollapsedChange)==null||Ee.call(_,!de)}})}),!de&&f.jsx(zb,{})]})]})}),!oe&&f.jsxs(D.Box,{position:"relative",ml:"auto",flexShrink:0,children:[f.jsx(D.Box,{"data-flow-direction-control":"",bg:K,borderRadius:"30px",h:50,css:mr(G,se),px:3,cursor:"pointer",onClick:()=>Y(!U),children:f.jsxs(D.Flex,{align:"center",h:"100%",children:[f.jsx(He,{label:"Flow Direction",children:f.jsx(Oe,{"aria-label":"Direction",onClick:Ee=>{Ee.stopPropagation(),Y(!U)},icon:f.jsx(D.Icon,{as:X.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:V})}),f.jsx(D.Text,{fontSize:"xs",textTransform:"uppercase !important",color:ue?"whiteAlpha.600":"blackAlpha.500",ml:1,children:c.toUpperCase()})]})}),U&&f.jsx(D.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:f.jsxs(D.Box,{bg:K,borderRadius:"30px",p:2,minW:"180px",css:mr(G,se),children:[Qw.map(Ee=>f.jsxs(D.Flex,{align:"center",gap:3,px:3,py:2,css:ho,cursor:"pointer",_hover:{bg:ue?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Le;(Le=_.onDirectionChange)==null||Le.call(_,Ee.value),Y(!1)},children:[f.jsx(D.Icon,{as:Ee.icon,boxSize:5,color:re}),f.jsx(D.Text,{fontSize:"sm",color:re,flex:1,whiteSpace:"nowrap",children:Ee.label}),c===Ee.value&&f.jsx(D.Icon,{as:X.PiCheck,boxSize:4,color:q})]},Ee.value)),f.jsxs(D.Flex,{align:"center",gap:3,px:3,py:2,css:ho,cursor:"pointer",_hover:{bg:ue?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ee;(Ee=_.onDirectionChange)==null||Ee.call(_,"C"),Y(!1)},children:[f.jsx(D.Icon,{as:X.PiAlignCenterHorizontal,boxSize:5,color:re}),f.jsx(D.Text,{fontSize:"sm",color:re,flex:1,whiteSpace:"nowrap",children:"Center"}),c==="C"&&f.jsx(D.Icon,{as:X.PiCheck,boxSize:4,color:q})]})]})})]})]})})]})};Db.displayName="BottomBar";const Wb=j.memo(Db);function e1({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(D.Icon,{as:X.PiGraph,boxSize:5})})}const Zu={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function Vb(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(Zu,l)){if(typeof s[l]!="string"||!s[l])return!1;t.set(a,{...t.get(a),[Zu[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 t1(e,r){return Vb(e,r)!==void 0}function r1(e,r,t){if(e===r)return t;const n=Vb(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)||!$e(r,i))return;return{edges:t.edges,nodes:t.nodes.map(i=>{const s=n.get(i.data.id),a=$e(e,i.data.id),c=$e(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 Pd(e){return e.kind==="literal"?e.value:e.kind==="union"?Pd(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,r])=>!r.optional).map(([r,t])=>[r,Pd(t.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Gb(e,r,t){var y,b,x;const n=(y=$e(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)||Qt(d.properties[w].type,v,!d.properties[w].optional))throw new Error(`Invalid creation default: ${w}`);const h={...Pd(d),...structuredClone(u)};((x=d.properties.id)==null?void 0:x.type.kind)==="string"&&(h.id=Nd());let p=e;const m=$e(e,o.$address);if(m===void 0)p=Rt(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=Ld(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:Fd(g.json,r,{target:g.address,label:o.$edgeLabel})}}function n1(e,r,t){var i,s;if(Array.isArray(r)){const a=new Set(r);if(!$e(e,t)||[...a].some(u=>u==="root"||!$e(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=$e(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"||!$e(e,r)||!$e(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=$e(e,o))==null?void 0:s.$parent;o=typeof a=="string"?a:o.includes(".")?o.slice(0,o.lastIndexOf(".")):void 0}return uo(Rt(e,r,a=>({...a,$parent:t})),t,!1)}function Hb(e,r){const t=new Set(r.filter(a=>$e(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 Jd(e,r){const t=Hb(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($e(e,a));i(l),s[`node_${c+1}`]=l}),s}function Ub(e,r){const t=Jd(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:Rt(e,"root",a=>({...a,...s})),ids:[...o.values()].map(a=>`root.${a}`)}}function o1(e,r){const t=o=>e&&typeof e=="object"&&o in e;let n=1;for(;t(`${r}_${n}`);)n++;return`${r}_${n}`}function Kb(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($e(a,p))!==JSON.stringify($e(e,p))&&(a=db(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(Jd(e,a),null,2))},onNodesDuplicate:a=>{var l;if(((l=t.onNodesDuplicate)==null?void 0:l.call(t,a))===!0)return;const c=Ub(e,a);i(c.json,{type:"nodeCreate",address:c.ids[0],nodeAddresses:c.ids})},onFormChange:a=>{const c=$e(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(Et(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(Et(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(Et(e,a,"$contentFormat",c),{type:"nodeStyle",address:a,key:"$contentFormat",value:c}))},onNodeTypeViewChange:(a,c)=>{var l;c!==void 0&&!zd.includes(c)||((l=t.onNodeTypeViewChange)==null||l.call(t,a,c),i(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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(Et(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=$e(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&&Gb(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=o1($e(m,c),a.isArrayMode?"list":"node"),E=a.isArrayMode?{$bgColor:"gray.500",$label:C,$:[]}:{$bgColor:"gray.500",$label:C},R=Ld(m,c,E,S);m=R.json,g??(g=R.address),y.push(R.address)}d&&(m=Rt(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(fb(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?Fd(e,a,d):hb(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(Er(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(ub(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(Er(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(Er(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(Er(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(Er(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=pb(e,l);d.removed&&i(d.json,{type:"edgeDelete",edge:l,key:l.connection?"$connections":"$target"})}}}const i1=".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 a1({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 s1=".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 c1({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 Jb=".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 l1=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 Zb(e,r=!1){return e&&!r&&typeof requestAnimationFrame<"u"&&!(typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches)}function Xb(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(!Zb(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 Xu(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 d1(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 sr=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}),u1=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function ri(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 f1=(e,r)=>e.x1<=r.x2&&e.x2>=r.x1&&e.y1<=r.y2&&e.y2>=r.y1,Yu=(e,r)=>e.x>=r.x1&&e.x<=r.x2&&e.y>=r.y1&&e.y<=r.y2,Gt=e=>(Math.round(e*10)/10).toString(),wt=e=>`${Gt(e.x)} ${Gt(e.y)}`,h1=e=>e>0?1:e<0?-1:0,Qu=(e,r)=>e>0?Math.max(e-r,0):Math.min(e+r,0);function p1(e,r,t,n,o=10){const i=r.x-e.x,s=r.y-e.y,a=Qu(i,(e.w+r.w)/2),c=Qu(s,(e.h+r.h)/2),l=t==="downward"||t==="upward",d=l?c:a,u=l?s:i,h=h1(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 g1(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 g1(e,r,sr(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 Yb(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 y1(e,r,t,n){const o=Qr(e,t.srcDist),i=Qr(r,t.tgtDist);if(n==="straight")return ex(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"?_t(o,l,t.arrowGap):o,h=t.arrowAt==="target"?_t(i,d,t.arrowGap):i,p=t.arrowAt==="source"?Ut(o,l,t.arrowSize,t.headShape):t.arrowAt==="target"?Ut(i,d,t.arrowSize,t.headShape):void 0;if(n==="bezier")return{d:`M${wt(u)} C${wt(l)} ${wt(d)} ${wt(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 Ao(u,b,h,p,n==="orthogonal"?0:t.radius)}function _t(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 Ut(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${wt(e)} L${Gt(e.x-c*d)} ${Gt(e.y+a*d)} L${Gt(u-c*d)} ${Gt(h+a*d)} L${Gt(u+c*d)} ${Gt(h-a*d)} L${Gt(e.x+c*d)} ${Gt(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)),A=Math.min(1/R,w/2,v/2);return{start:{x:g.x+C.x*A,y:g.y+C.y*A},end:{x:g.x+S.x*A,y:g.y+S.y*A},radius:A*R}}).map((g,y)=>`${y?"L":"M"}${wt(g.start)} A${Gt(g.radius)} ${Gt(g.radius)} 0 0 1 ${wt(g.end)}`).join(" ")+" Z"}function jr(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 m1(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 Qb(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=_t(i,l,n.srcDist);u=_t(i,l,n.srcDist+n.arrowGap),p=Ut(m,l,n.arrowSize,n.headShape)}else u=_t(i,l,n.srcDist);if(n.arrowAt==="target"){const m=_t(a,d,n.tgtDist);h=_t(a,d,n.tgtDist+n.arrowGap),p=Ut(m,d,n.arrowSize,n.headShape)}else h=_t(a,d,n.tgtDist);return Ao(u,c,h,p,n.radius,n.labelTargetLength,n.labelFraction)}function Ao(e,r,t,n,o,i,s){var h;const a=[e,...r,t],c=[];let l=`M${wt(e)}`;for(let p=1;p<a.length-1;p++){const m=m1(a[p-1],a[p],a[p+1],o);c.push(m),m.r===0?l+=` L${wt(m.b)}`:l+=` L${wt(m.p1)} Q${wt(m.b)} ${wt(m.p2)}`}l+=` L${wt(t)}`;let d;const u=r.length;if(u===0)d={x:(e.x+t.x)/2,y:(e.y+t.y)/2,angle:jr(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:jr(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:jr(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:jr(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:jr(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:jr(m,g)})}return{d:l,arrow:n,label:d}}function ef(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"?_t(c,p[0],s.arrowGap):c,g=s.arrowAt==="target"?_t(l,p[p.length-1],s.arrowGap):l,y=s.arrowAt==="source"?Ut(c,p[0],s.arrowSize,s.headShape):s.arrowAt==="target"?Ut(l,p[p.length-1],s.arrowSize,s.headShape):void 0;return Ao(m,p,g,y,s.radius)}function tf(e,r,t,n,o){return Qb(p1(e,r,t,n),e,r,o)}function rf(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 b1(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"?_t(e,a,n.arrowGap):e,d=n.arrowAt==="target"?_t(r,c,n.arrowGap):r;return{d:`M${wt(l)} C${wt(a)} ${wt(c)} ${wt(d)}`,arrow:n.arrowAt==="source"?Ut(e,a,n.arrowSize,n.headShape):n.arrowAt==="target"?Ut(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:jr(d.x+c.x-a.x-l.x,d.y+c.y-a.y-l.y)}}}function ex(e,r,t){const n=t.arrowAt==="source"?_t(e,r,t.arrowGap):e,o=t.arrowAt==="target"?_t(r,e,t.arrowGap):r,i=t.arrowAt==="source"?Ut(e,r,t.arrowSize,t.headShape):t.arrowAt==="target"?Ut(r,e,t.arrowSize,t.headShape):void 0;return Ao(n,[],o,i,0)}function x1(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=_t(g,h,t.srcDist),w=_t(y,p,t.tgtDist),v;if(t.arrowAt==="target"){const S=w;w=_t(y,p,t.tgtDist+t.arrowGap),v=Ut(S,p,t.arrowSize,t.headShape)}else if(t.arrowAt==="source"){const S=x;x=_t(g,h,t.srcDist+t.arrowGap),v=Ut(S,h,t.arrowSize,t.headShape)}return{d:`M${wt(x)} Q${wt(h)} ${wt(b)} Q${wt(p)} ${wt(w)}`,arrow:v,label:{x:b.x,y:b.y,angle:jr(p.x-h.x,p.y-h.y)}}}const qr=e=>Math.round(e*1e3)/1e3;function tx(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:qr((a.a*y.x+a.c*y.y+a.e-t.left)/n),y:qr((a.b*y.x+a.d*y.y+a.f-t.top)/n)}}):void 0;return{left:qr((o.left-t.left)/n),top:qr((o.top-t.top)/n),width:r instanceof HTMLElement?r.offsetWidth:qr(o.width/n),height:r instanceof HTMLElement?r.offsetHeight:qr(o.height/n),radius:parseFloat(getComputedStyle(r).borderTopLeftRadius)||0,...i!=null&&i.height?{captionBottom:qr((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 v1(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=Yb(b,v,S);return{...w,anchor:E,top:E.y,height:0}}))}return l}function nf(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 Pr='"Helvetica Neue", Helvetica, sans-serif';let Cn;const oo=new Map;function Ro(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 w1(e,r,t){const n=[];for(const o of String(e).split(`
|
|
280
|
+
`)){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||Ro(c,r)<=t?s=c:(n.push(s),s=a)}n.push(s)}return n}const of=e=>e.stopPropagation();function C1({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?Ro(t,`bold ${i.fontSize}px ${Pr}`):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(He,{label:"Show icon",children:f.jsx(Oe,{"aria-label":"Show icon",icon:f.jsx(X.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:of,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:Pr,style:{fontSize:i.fontSize,fontWeight:"bold",fontFamily:Pr},textAnchor:"middle",dominantBaseline:"central",children:t})]})]}):null;return f.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:of,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?Vr.createPortal(b,n):b]})}const S1=j.memo(C1),yo=45,rx=70,Fr=15,nx=50;function ox(e,r,t=yo){const n=`${t}px ${Pr}`,o=e?w1(e,n,200*t/yo):[],i=r?48+(o.length?12:0):0,s=i+Math.max(0,...o.map(l=>Ro(l,n))),a=Math.max(o.length*t,r?48:0),c=o.length||r?2*Fr:0;return{lines:o,iconWidth:i,contentWidth:s,contentHeight:a,width:s+c,height:a+c}}const Ln=6,ix=3,Zd=.3,j1=8,Xd=Math.max(Math.pow(Ln*13.37,.9),29)*ix-j1/Zd,ax=Ln*ix*2,co=80,E1=2*co+Xd*Zd+100,_1=36+2*Math.max(80,ax+Xd*Zd);function Ad(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function Rd(e,r){return r==="auto"||(r==="properties"?Ad(e):!Ad(e))}function cr(e,r,t){return t!=="properties"||e!=="root"||r.some(n=>(n.source===e||n.target===e)&&Ad(n))}function k1(e,r,t,n=!1,o){if(!n)return{nodes:e,edges:r};const i=e.filter(a=>cr(a.id,r,t)&&(!o||o.has(a.id))),s=new Set(i.map(a=>a.id));return{nodes:i,edges:r.filter(a=>Rd(a,t)&&s.has(a.source)&&s.has(a.target))}}const P1=500,A1="32 18",R1=e=>e.stopPropagation();function M1({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:A,dashed:I,animated:M,inverted:k,loopIndex:_=0,selected:$=!1,onSelect:N}){const W=n==null?void 0:n.icon,[T,Q]=j.useState(!1),ue=y?yo:rx,{lines:K,iconWidth:ce,contentWidth:V,contentHeight:re}=j.useMemo(()=>ox(A,W,ue),[A,W,ue]),q=j.useMemo(()=>{const J={srcDist:co,tgtDist:co,arrowGap:ax,arrowSize:Xd,headShape:y&&(k?h!==void 0||m:p!==void 0||g)?"square":"triangle",radius:s??(w?40:P1),arrowAt:k?"source":"target",labelTargetLength:w?V+2*Fr:void 0,labelFraction:w?v:void 0},fe=h!==void 0||p!==void 0||!!m||!!g,ve=rf(c,l,b,h,p,0),Re=h===void 0&&p===void 0&&(b==="downward"||b==="upward"),Je=m??{...ve.sourcePoint,side:Re?b==="upward"?"top":"bottom":b==="leftward"?"left":"right"},st=g??{...ve.targetPoint,side:Re?b==="upward"?"bottom":"top":b==="leftward"?"right":"left"},Ye=c.x===l.x&&c.y===l.y,We=m||g?y1(Je,st,{...J,srcDist:18,tgtDist:18},i):fe?ef(c,l,b,h,p,x,{...J,srcDist:18,tgtDist:18,radius:s??Math.min(J.radius,40)}):Ye?x1(c,_,{...J,srcDist:0,tgtDist:0}):tf(c,l,b,x,J);if(!We)return null;const Ze=rf(c,l,b,h,p,fe?18:co);m&&(Ze.sourcePoint=Qr(m,18)),g&&(Ze.targetPoint=Qr(g,18));const me=Object.prototype.hasOwnProperty.call(a??{},i)?a==null?void 0:a[i]:void 0;if(me){const Ae={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return me({edge:n??{id:e,source:"",target:""},source:{...c},target:{...l},...Ze,direction:Ae[b],sourceY:h,targetY:p,inverted:!!k,defaultGeometry:We})??We}return Ye||m||g?We:i==="straight"?fe?ex(Ze.sourcePoint,Ze.targetPoint,J):Qb([c,l],c,l,J):i==="bezier"?b1(Ze.sourcePoint,Ze.targetPoint,fe?b==="leftward"?"leftward":"rightward":b,J):i==="orthogonal"?fe?ef(c,l,b,h,p,x,{...J,srcDist:18,tgtDist:18,radius:0}):tf(c,l,b,x,{...J,radius:0}):We},[c,e,n,i,s,a,l,y,h,p,m,g,b,x,k,_,w,v,V]);if(!q)return null;const F=(b==="rightward"||b==="leftward")&&!Object.prototype.hasOwnProperty.call(a??{},i)&&!(y&&(h!==void 0||p!==void 0||m||g)),G=F?`translate(${q.label.x} ${q.label.y-re/2-2*Fr})`:`translate(${q.label.x} ${q.label.y}) rotate(${q.label.angle}) translate(${b==="downward"||b==="upward"||w||Object.prototype.hasOwnProperty.call(a??{},i)?0:nx} 0)`,se=o!=null&&o.startsWith("Unverified:")?"#b45309":"#dc2626",U=T||$?"#3b82f6":o?se:C,Y=o?f.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":o,transform:`translate(${q.label.x} ${q.label.y-K.length*ue/2-55})`,children:[f.jsx("title",{children:o}),f.jsx(dr,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:se})]}):null,le=M&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",ne=!le&&(I||M)?A1:void 0,de=M&&!le?`flow-sdk-edge-anim${k?" flow-sdk-edge-anim-rev":""}`:void 0;let xe=null;const he=r?{"--flow-edge-reveal-duration":`${r.durationMs??600}ms`,"--flow-edge-reveal-state":r.paused?"paused":"running"}:void 0;if(K.length||W){const J=V,fe=re;xe=f.jsxs("g",{className:`flow-sdk-edge-label${r?" flow-sdk-edge-reveal-end":""}`,style:he,"data-label-transform":G,"data-label-horizontal":F||void 0,"data-edge-id":e,"data-source-property":d,"data-target-property":u,transform:G,children:[f.jsx("rect",{x:-J/2-Fr,y:-fe/2-Fr,width:J+2*Fr,height:fe+2*Fr,fill:C==="transparent"?"transparent":E}),f.jsx("text",{fill:C,fontSize:ue,style:{fontSize:ue,fontFamily:Pr},fontFamily:Pr,textAnchor:"middle",dominantBaseline:"central",children:K.map((ve,Re)=>f.jsx("tspan",{x:ce/2,y:(Re-(K.length-1)/2)*ue,children:ve},Re))}),W&&f.jsxs("g",{className:"flow-sdk-edge-icon",opacity:C==="transparent"?0:1,children:[f.jsx("title",{children:A?`Edge icon: ${A}`:"Edge icon"}),f.jsx("rect",{x:-J/2,y:-24,width:48,height:48,fill:"transparent"}),f.jsx(dr,{name:W,svg:!0,size:48,x:-J/2,y:-24,color:C})]})]})}const H=f.jsxs(f.Fragment,{children:[f.jsx("path",{d:q.d,fill:"none",stroke:U,strokeWidth:Ln,strokeOpacity:le?.35:void 0,strokeDasharray:ne,className:de}),le&&f.jsx(c1,{path:q.d,color:U,width:Ln*1.6,reversed:k})]});return f.jsxs("g",{className:"flow-sdk-edge",style:he,"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:R1,onClick:J=>{J.stopPropagation(),N==null||N(e)},children:[r?f.jsx(a1,{path:q.d,width:Ln*4,reversed:k,onComplete:()=>t==null?void 0:t(e),children:H}):H,q.arrow&&f.jsx("path",{className:r?"flow-sdk-edge-reveal-end":void 0,d:q.arrow,fill:T||$?"#3b82f6":o?se:S??U}),R&&xe?Vr.createPortal(xe,R):xe,R&&Y?Vr.createPortal(Y,R):Y,f.jsx("path",{className:"flow-sdk-edge-hit",d:q.d,fill:"none",stroke:"transparent",onPointerEnter:()=>Q(!0),onPointerLeave:()=>Q(!1)})]})}const af=j.memo(M1);var io=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function T1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Yd(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 ni,sf;function I1(){if(sf)return ni;sf=1;function e(){this.__data__=[],this.size=0}return ni=e,ni}var oi,cf;function fn(){if(cf)return oi;cf=1;function e(r,t){return r===t||r!==r&&t!==t}return oi=e,oi}var ii,lf;function Mo(){if(lf)return ii;lf=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 ii=r,ii}var ai,df;function N1(){if(df)return ai;df=1;var e=Mo(),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 ai=n,ai}var si,uf;function O1(){if(uf)return si;uf=1;var e=Mo();function r(t){var n=this.__data__,o=e(n,t);return o<0?void 0:n[o][1]}return si=r,si}var ci,ff;function $1(){if(ff)return ci;ff=1;var e=Mo();function r(t){return e(this.__data__,t)>-1}return ci=r,ci}var li,hf;function q1(){if(hf)return li;hf=1;var e=Mo();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 li=r,li}var di,pf;function To(){if(pf)return di;pf=1;var e=I1(),r=N1(),t=O1(),n=$1(),o=q1();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 ui,gf;function L1(){if(gf)return ui;gf=1;var e=To();function r(){this.__data__=new e,this.size=0}return ui=r,ui}var fi,yf;function F1(){if(yf)return fi;yf=1;function e(r){var t=this.__data__,n=t.delete(r);return this.size=t.size,n}return fi=e,fi}var hi,mf;function z1(){if(mf)return hi;mf=1;function e(r){return this.__data__.get(r)}return hi=e,hi}var pi,bf;function B1(){if(bf)return pi;bf=1;function e(r){return this.__data__.has(r)}return pi=e,pi}var gi,xf;function sx(){if(xf)return gi;xf=1;var e=typeof io=="object"&&io&&io.Object===Object&&io;return gi=e,gi}var yi,vf;function rr(){if(vf)return yi;vf=1;var e=sx(),r=typeof self=="object"&&self&&self.Object===Object&&self,t=e||r||Function("return this")();return yi=t,yi}var mi,wf;function hn(){if(wf)return mi;wf=1;var e=rr(),r=e.Symbol;return mi=r,mi}var bi,Cf;function D1(){if(Cf)return bi;Cf=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 bi=i,bi}var xi,Sf;function W1(){if(Sf)return xi;Sf=1;var e=Object.prototype,r=e.toString;function t(n){return r.call(n)}return xi=t,xi}var vi,jf;function Hr(){if(jf)return vi;jf=1;var e=hn(),r=D1(),t=W1(),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 vi=s,vi}var wi,Ef;function Kt(){if(Ef)return wi;Ef=1;function e(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}return wi=e,wi}var Ci,_f;function Un(){if(_f)return Ci;_f=1;var e=Hr(),r=Kt(),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 Ci=s,Ci}var Si,kf;function V1(){if(kf)return Si;kf=1;var e=rr(),r=e["__core-js_shared__"];return Si=r,Si}var ji,Pf;function G1(){if(Pf)return ji;Pf=1;var e=V1(),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 ji=t,ji}var Ei,Af;function cx(){if(Af)return Ei;Af=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 Ei=t,Ei}var _i,Rf;function H1(){if(Rf)return _i;Rf=1;var e=Un(),r=G1(),t=Kt(),n=cx(),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 _i=u,_i}var ki,Mf;function U1(){if(Mf)return ki;Mf=1;function e(r,t){return r==null?void 0:r[t]}return ki=e,ki}var Pi,Tf;function Ur(){if(Tf)return Pi;Tf=1;var e=H1(),r=U1();function t(n,o){var i=r(n,o);return e(i)?i:void 0}return Pi=t,Pi}var Ai,If;function Qd(){if(If)return Ai;If=1;var e=Ur(),r=rr(),t=e(r,"Map");return Ai=t,Ai}var Ri,Nf;function Io(){if(Nf)return Ri;Nf=1;var e=Ur(),r=e(Object,"create");return Ri=r,Ri}var Mi,Of;function K1(){if(Of)return Mi;Of=1;var e=Io();function r(){this.__data__=e?e(null):{},this.size=0}return Mi=r,Mi}var Ti,$f;function J1(){if($f)return Ti;$f=1;function e(r){var t=this.has(r)&&delete this.__data__[r];return this.size-=t?1:0,t}return Ti=e,Ti}var Ii,qf;function Z1(){if(qf)return Ii;qf=1;var e=Io(),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 Ii=o,Ii}var Ni,Lf;function X1(){if(Lf)return Ni;Lf=1;var e=Io(),r=Object.prototype,t=r.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:t.call(i,o)}return Ni=n,Ni}var Oi,Ff;function Y1(){if(Ff)return Oi;Ff=1;var e=Io(),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 Oi=t,Oi}var $i,zf;function Q1(){if(zf)return $i;zf=1;var e=K1(),r=J1(),t=Z1(),n=X1(),o=Y1();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,$i=i,$i}var qi,Bf;function eC(){if(Bf)return qi;Bf=1;var e=Q1(),r=To(),t=Qd();function n(){this.size=0,this.__data__={hash:new e,map:new(t||r),string:new e}}return qi=n,qi}var Li,Df;function tC(){if(Df)return Li;Df=1;function e(r){var t=typeof r;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?r!=="__proto__":r===null}return Li=e,Li}var Fi,Wf;function No(){if(Wf)return Fi;Wf=1;var e=tC();function r(t,n){var o=t.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return Fi=r,Fi}var zi,Vf;function rC(){if(Vf)return zi;Vf=1;var e=No();function r(t){var n=e(this,t).delete(t);return this.size-=n?1:0,n}return zi=r,zi}var Bi,Gf;function nC(){if(Gf)return Bi;Gf=1;var e=No();function r(t){return e(this,t).get(t)}return Bi=r,Bi}var Di,Hf;function oC(){if(Hf)return Di;Hf=1;var e=No();function r(t){return e(this,t).has(t)}return Di=r,Di}var Wi,Uf;function iC(){if(Uf)return Wi;Uf=1;var e=No();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 Wi=r,Wi}var Vi,Kf;function eu(){if(Kf)return Vi;Kf=1;var e=eC(),r=rC(),t=nC(),n=oC(),o=iC();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,Vi=i,Vi}var Gi,Jf;function aC(){if(Jf)return Gi;Jf=1;var e=To(),r=Qd(),t=eu(),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 Gi=o,Gi}var Hi,Zf;function Oo(){if(Zf)return Hi;Zf=1;var e=To(),r=L1(),t=F1(),n=z1(),o=B1(),i=aC();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,Hi=s,Hi}var Ui,Xf;function tu(){if(Xf)return Ui;Xf=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 Ui=e,Ui}var Ki,Yf;function lx(){if(Yf)return Ki;Yf=1;var e=Ur(),r=(function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch{}})();return Ki=r,Ki}var Ji,Qf;function $o(){if(Qf)return Ji;Qf=1;var e=lx();function r(t,n,o){n=="__proto__"&&e?e(t,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):t[n]=o}return Ji=r,Ji}var Zi,eh;function qo(){if(eh)return Zi;eh=1;var e=$o(),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 Zi=o,Zi}var Xi,th;function Kn(){if(th)return Xi;th=1;var e=qo(),r=$o();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 Xi=t,Xi}var Yi,rh;function sC(){if(rh)return Yi;rh=1;function e(r,t){for(var n=-1,o=Array(r);++n<r;)o[n]=t(n);return o}return Yi=e,Yi}var Qi,nh;function ur(){if(nh)return Qi;nh=1;function e(r){return r!=null&&typeof r=="object"}return Qi=e,Qi}var ea,oh;function cC(){if(oh)return ea;oh=1;var e=Hr(),r=ur(),t="[object Arguments]";function n(o){return r(o)&&e(o)==t}return ea=n,ea}var ta,ih;function Jn(){if(ih)return ta;ih=1;var e=cC(),r=ur(),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 ta=i,ta}var ra,ah;function St(){if(ah)return ra;ah=1;var e=Array.isArray;return ra=e,ra}var kn={exports:{}},na,sh;function lC(){if(sh)return na;sh=1;function e(){return!1}return na=e,na}kn.exports;var ch;function pn(){return ch||(ch=1,(function(e,r){var t=rr(),n=lC(),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 oa,lh;function Lo(){if(lh)return oa;lh=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 oa=t,oa}var ia,dh;function ru(){if(dh)return ia;dh=1;var e=9007199254740991;function r(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=e}return ia=r,ia}var aa,uh;function dC(){if(uh)return aa;uh=1;var e=Hr(),r=ru(),t=ur(),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]",A="[object Uint16Array]",I="[object Uint32Array]",M={};M[x]=M[w]=M[v]=M[C]=M[S]=M[E]=M[R]=M[A]=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 aa=k,aa}var sa,fh;function Fo(){if(fh)return sa;fh=1;function e(r){return function(t){return r(t)}}return sa=e,sa}var Pn={exports:{}};Pn.exports;var hh;function nu(){return hh||(hh=1,(function(e,r){var t=sx(),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 ca,ph;function Zn(){if(ph)return ca;ph=1;var e=dC(),r=Fo(),t=nu(),n=t&&t.isTypedArray,o=n?r(n):e;return ca=o,ca}var la,gh;function dx(){if(gh)return la;gh=1;var e=sC(),r=Jn(),t=St(),n=pn(),o=Lo(),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 la=c,la}var da,yh;function zo(){if(yh)return da;yh=1;var e=Object.prototype;function r(t){var n=t&&t.constructor,o=typeof n=="function"&&n.prototype||e;return t===o}return da=r,da}var ua,mh;function ux(){if(mh)return ua;mh=1;function e(r,t){return function(n){return r(t(n))}}return ua=e,ua}var fa,bh;function uC(){if(bh)return fa;bh=1;var e=ux(),r=e(Object.keys,Object);return fa=r,fa}var ha,xh;function ou(){if(xh)return ha;xh=1;var e=zo(),r=uC(),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 ha=o,ha}var pa,vh;function br(){if(vh)return pa;vh=1;var e=Un(),r=ru();function t(n){return n!=null&&r(n.length)&&!e(n)}return pa=t,pa}var ga,wh;function Ir(){if(wh)return ga;wh=1;var e=dx(),r=ou(),t=br();function n(o){return t(o)?e(o):r(o)}return ga=n,ga}var ya,Ch;function fC(){if(Ch)return ya;Ch=1;var e=Kn(),r=Ir();function t(n,o){return n&&e(o,r(o),n)}return ya=t,ya}var ma,Sh;function hC(){if(Sh)return ma;Sh=1;function e(r){var t=[];if(r!=null)for(var n in Object(r))t.push(n);return t}return ma=e,ma}var ba,jh;function pC(){if(jh)return ba;jh=1;var e=Kt(),r=zo(),t=hC(),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 ba=i,ba}var xa,Eh;function Kr(){if(Eh)return xa;Eh=1;var e=dx(),r=pC(),t=br();function n(o){return t(o)?e(o,!0):r(o)}return xa=n,xa}var va,_h;function gC(){if(_h)return va;_h=1;var e=Kn(),r=Kr();function t(n,o){return n&&e(o,r(o),n)}return va=t,va}var An={exports:{}};An.exports;var kh;function fx(){return kh||(kh=1,(function(e,r){var t=rr(),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 wa,Ph;function hx(){if(Ph)return wa;Ph=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 wa=e,wa}var Ca,Ah;function px(){if(Ah)return Ca;Ah=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 Ca=e,Ca}var Sa,Rh;function gx(){if(Rh)return Sa;Rh=1;function e(){return[]}return Sa=e,Sa}var ja,Mh;function iu(){if(Mh)return ja;Mh=1;var e=px(),r=gx(),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 ja=i,ja}var Ea,Th;function yC(){if(Th)return Ea;Th=1;var e=Kn(),r=iu();function t(n,o){return e(n,r(n),o)}return Ea=t,Ea}var _a,Ih;function au(){if(Ih)return _a;Ih=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 _a=e,_a}var ka,Nh;function Bo(){if(Nh)return ka;Nh=1;var e=ux(),r=e(Object.getPrototypeOf,Object);return ka=r,ka}var Pa,Oh;function yx(){if(Oh)return Pa;Oh=1;var e=au(),r=Bo(),t=iu(),n=gx(),o=Object.getOwnPropertySymbols,i=o?function(s){for(var a=[];s;)e(a,t(s)),s=r(s);return a}:n;return Pa=i,Pa}var Aa,$h;function mC(){if($h)return Aa;$h=1;var e=Kn(),r=yx();function t(n,o){return e(n,r(n),o)}return Aa=t,Aa}var Ra,qh;function mx(){if(qh)return Ra;qh=1;var e=au(),r=St();function t(n,o,i){var s=o(n);return r(n)?s:e(s,i(n))}return Ra=t,Ra}var Ma,Lh;function bx(){if(Lh)return Ma;Lh=1;var e=mx(),r=iu(),t=Ir();function n(o){return e(o,t,r)}return Ma=n,Ma}var Ta,Fh;function bC(){if(Fh)return Ta;Fh=1;var e=mx(),r=yx(),t=Kr();function n(o){return e(o,t,r)}return Ta=n,Ta}var Ia,zh;function xC(){if(zh)return Ia;zh=1;var e=Ur(),r=rr(),t=e(r,"DataView");return Ia=t,Ia}var Na,Bh;function vC(){if(Bh)return Na;Bh=1;var e=Ur(),r=rr(),t=e(r,"Promise");return Na=t,Na}var Oa,Dh;function xx(){if(Dh)return Oa;Dh=1;var e=Ur(),r=rr(),t=e(r,"Set");return Oa=t,Oa}var $a,Wh;function wC(){if(Wh)return $a;Wh=1;var e=Ur(),r=rr(),t=e(r,"WeakMap");return $a=t,$a}var qa,Vh;function gn(){if(Vh)return qa;Vh=1;var e=xC(),r=Qd(),t=vC(),n=xx(),o=wC(),i=Hr(),s=cx(),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}),qa=x,qa}var La,Gh;function CC(){if(Gh)return La;Gh=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 La=t,La}var Fa,Hh;function vx(){if(Hh)return Fa;Hh=1;var e=rr(),r=e.Uint8Array;return Fa=r,Fa}var za,Uh;function su(){if(Uh)return za;Uh=1;var e=vx();function r(t){var n=new t.constructor(t.byteLength);return new e(n).set(new e(t)),n}return za=r,za}var Ba,Kh;function SC(){if(Kh)return Ba;Kh=1;var e=su();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.byteLength)}return Ba=r,Ba}var Da,Jh;function jC(){if(Jh)return Da;Jh=1;var e=/\w*$/;function r(t){var n=new t.constructor(t.source,e.exec(t));return n.lastIndex=t.lastIndex,n}return Da=r,Da}var Wa,Zh;function EC(){if(Zh)return Wa;Zh=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 Wa=n,Wa}var Va,Xh;function wx(){if(Xh)return Va;Xh=1;var e=su();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}return Va=r,Va}var Ga,Yh;function _C(){if(Yh)return Ga;Yh=1;var e=su(),r=SC(),t=jC(),n=EC(),o=wx(),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(A,I,M){var k=A.constructor;switch(I){case p:return e(A);case i:case s:return new k(+A);case m:return r(A,M);case g:case y:case b:case x:case w:case v:case C:case S:case E:return o(A,M);case a:return new k;case c:case u:return new k(A);case l:return t(A);case d:return new k;case h:return n(A)}}return Ga=R,Ga}var Ha,Qh;function Cx(){if(Qh)return Ha;Qh=1;var e=Kt(),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 Ha=t,Ha}var Ua,ep;function Sx(){if(ep)return Ua;ep=1;var e=Cx(),r=Bo(),t=zo();function n(o){return typeof o.constructor=="function"&&!t(o)?e(r(o)):{}}return Ua=n,Ua}var Ka,tp;function kC(){if(tp)return Ka;tp=1;var e=gn(),r=ur(),t="[object Map]";function n(o){return r(o)&&e(o)==t}return Ka=n,Ka}var Ja,rp;function PC(){if(rp)return Ja;rp=1;var e=kC(),r=Fo(),t=nu(),n=t&&t.isMap,o=n?r(n):e;return Ja=o,Ja}var Za,np;function AC(){if(np)return Za;np=1;var e=gn(),r=ur(),t="[object Set]";function n(o){return r(o)&&e(o)==t}return Za=n,Za}var Xa,op;function RC(){if(op)return Xa;op=1;var e=AC(),r=Fo(),t=nu(),n=t&&t.isSet,o=n?r(n):e;return Xa=o,Xa}var Ya,ip;function jx(){if(ip)return Ya;ip=1;var e=Oo(),r=tu(),t=qo(),n=fC(),o=gC(),i=fx(),s=hx(),a=yC(),c=mC(),l=bx(),d=bC(),u=gn(),h=CC(),p=_C(),m=Sx(),g=St(),y=pn(),b=PC(),x=Kt(),w=RC(),v=Ir(),C=Kr(),S=1,E=2,R=4,A="[object Arguments]",I="[object Array]",M="[object Boolean]",k="[object Date]",_="[object Error]",$="[object Function]",N="[object GeneratorFunction]",W="[object Map]",T="[object Number]",Q="[object Object]",ue="[object RegExp]",K="[object Set]",ce="[object String]",V="[object Symbol]",re="[object WeakMap]",q="[object ArrayBuffer]",F="[object DataView]",G="[object Float32Array]",se="[object Float64Array]",U="[object Int8Array]",Y="[object Int16Array]",le="[object Int32Array]",ne="[object Uint8Array]",de="[object Uint8ClampedArray]",xe="[object Uint16Array]",he="[object Uint32Array]",H={};H[A]=H[I]=H[q]=H[F]=H[M]=H[k]=H[G]=H[se]=H[U]=H[Y]=H[le]=H[W]=H[T]=H[Q]=H[ue]=H[K]=H[ce]=H[V]=H[ne]=H[de]=H[xe]=H[he]=!0,H[_]=H[$]=H[re]=!1;function J(fe,ve,Re,Je,st,Ye){var We,Ze=ve&S,me=ve&E,Ae=ve&R;if(Re&&(We=st?Re(fe,Je,st,Ye):Re(fe)),We!==void 0)return We;if(!x(fe))return fe;var oe=g(fe);if(oe){if(We=h(fe),!Ze)return s(fe,We)}else{var ie=u(fe),Ne=ie==$||ie==N;if(y(fe))return i(fe,Ze);if(ie==Q||ie==A||Ne&&!st){if(We=me||Ne?{}:m(fe),!Ze)return me?c(fe,o(We,fe)):a(fe,n(We,fe))}else{if(!H[ie])return st?fe:{};We=p(fe,ie,Ze)}}Ye||(Ye=new e);var Qe=Ye.get(fe);if(Qe)return Qe;Ye.set(fe,We),w(fe)?fe.forEach(function(ct){We.add(J(ct,ve,Re,ct,fe,Ye))}):b(fe)&&fe.forEach(function(ct,Ue){We.set(Ue,J(ct,ve,Re,Ue,fe,Ye))});var Ee=Ae?me?d:l:me?C:v,Le=oe?void 0:Ee(fe);return r(Le||fe,function(ct,Ue){Le&&(Ue=ct,ct=fe[Ue]),t(We,Ue,J(ct,ve,Re,Ue,fe,Ye))}),We}return Ya=J,Ya}var Qa,ap;function MC(){if(ap)return Qa;ap=1;var e=jx(),r=4;function t(n){return e(n,r)}return Qa=t,Qa}var es,sp;function cu(){if(sp)return es;sp=1;function e(r){return function(){return r}}return es=e,es}var ts,cp;function TC(){if(cp)return ts;cp=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 ts=e,ts}var rs,lp;function lu(){if(lp)return rs;lp=1;var e=TC(),r=e();return rs=r,rs}var ns,dp;function du(){if(dp)return ns;dp=1;var e=lu(),r=Ir();function t(n,o){return n&&e(n,o,r)}return ns=t,ns}var os,up;function IC(){if(up)return os;up=1;var e=br();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 os=r,os}var is,fp;function Do(){if(fp)return is;fp=1;var e=du(),r=IC(),t=r(e);return is=t,is}var as,hp;function Jr(){if(hp)return as;hp=1;function e(r){return r}return as=e,as}var ss,pp;function Ex(){if(pp)return ss;pp=1;var e=Jr();function r(t){return typeof t=="function"?t:e}return ss=r,ss}var cs,gp;function _x(){if(gp)return cs;gp=1;var e=tu(),r=Do(),t=Ex(),n=St();function o(i,s){var a=n(i)?e:r;return a(i,t(s))}return cs=o,cs}var ls,yp;function kx(){return yp||(yp=1,ls=_x()),ls}var ds,mp;function NC(){if(mp)return ds;mp=1;var e=Do();function r(t,n){var o=[];return e(t,function(i,s,a){n(i,s,a)&&o.push(i)}),o}return ds=r,ds}var us,bp;function OC(){if(bp)return us;bp=1;var e="__lodash_hash_undefined__";function r(t){return this.__data__.set(t,e),this}return us=r,us}var fs,xp;function $C(){if(xp)return fs;xp=1;function e(r){return this.__data__.has(r)}return fs=e,fs}var hs,vp;function Px(){if(vp)return hs;vp=1;var e=eu(),r=OC(),t=$C();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,hs=n,hs}var ps,wp;function qC(){if(wp)return ps;wp=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 ps=e,ps}var gs,Cp;function Ax(){if(Cp)return gs;Cp=1;function e(r,t){return r.has(t)}return gs=e,gs}var ys,Sp;function Rx(){if(Sp)return ys;Sp=1;var e=Px(),r=qC(),t=Ax(),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 ys=i,ys}var ms,jp;function LC(){if(jp)return ms;jp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o,i){n[++t]=[i,o]}),n}return ms=e,ms}var bs,Ep;function uu(){if(Ep)return bs;Ep=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o){n[++t]=o}),n}return bs=e,bs}var xs,_p;function FC(){if(_p)return xs;_p=1;var e=hn(),r=vx(),t=fn(),n=Rx(),o=LC(),i=uu(),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,A,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 $=A&s;if(_||(_=i),S.size!=E.size&&!$)return!1;var N=k.get(S);if(N)return N==E;A|=a,k.set(S,E);var W=n(_(S),_(E),A,I,M,k);return k.delete(S),W;case y:if(v)return v.call(S)==v.call(E)}return!1}return xs=C,xs}var vs,kp;function zC(){if(kp)return vs;kp=1;var e=bx(),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 A=i.constructor,I=s.constructor;A!=I&&"constructor"in i&&"constructor"in s&&!(typeof A=="function"&&A instanceof A&&typeof I=="function"&&I instanceof I)&&(v=!1)}return d.delete(i),d.delete(s),v}return vs=o,vs}var ws,Pp;function BC(){if(Pp)return ws;Pp=1;var e=Oo(),r=Rx(),t=FC(),n=zC(),o=gn(),i=St(),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 A=E==u,I=R==u,M=E==R;if(M&&s(g)){if(!s(y))return!1;C=!0,A=!1}if(M&&!A)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=A&&p.call(g,"__wrapped__"),_=I&&p.call(y,"__wrapped__");if(k||_){var $=k?g.value():g,N=_?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 ws=m,ws}var Cs,Ap;function Mx(){if(Ap)return Cs;Ap=1;var e=BC(),r=ur();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 Cs=t,Cs}var Ss,Rp;function DC(){if(Rp)return Ss;Rp=1;var e=Oo(),r=Mx(),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 Ss=o,Ss}var js,Mp;function Tx(){if(Mp)return js;Mp=1;var e=Kt();function r(t){return t===t&&!e(t)}return js=r,js}var Es,Tp;function WC(){if(Tp)return Es;Tp=1;var e=Tx(),r=Ir();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 Es=t,Es}var _s,Ip;function Ix(){if(Ip)return _s;Ip=1;function e(r,t){return function(n){return n==null?!1:n[r]===t&&(t!==void 0||r in Object(n))}}return _s=e,_s}var ks,Np;function VC(){if(Np)return ks;Np=1;var e=DC(),r=WC(),t=Ix();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 ks=n,ks}var Ps,Op;function yn(){if(Op)return Ps;Op=1;var e=Hr(),r=ur(),t="[object Symbol]";function n(o){return typeof o=="symbol"||r(o)&&e(o)==t}return Ps=n,Ps}var As,$p;function fu(){if($p)return As;$p=1;var e=St(),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 As=o,As}var Rs,qp;function GC(){if(qp)return Rs;qp=1;var e=eu(),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,Rs=t,Rs}var Ms,Lp;function HC(){if(Lp)return Ms;Lp=1;var e=GC(),r=500;function t(n){var o=e(n,function(s){return i.size===r&&i.clear(),s}),i=o.cache;return o}return Ms=t,Ms}var Ts,Fp;function UC(){if(Fp)return Ts;Fp=1;var e=HC(),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 Ts=n,Ts}var Is,zp;function Wo(){if(zp)return Is;zp=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 Is=e,Is}var Ns,Bp;function KC(){if(Bp)return Ns;Bp=1;var e=hn(),r=Wo(),t=St(),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 Ns=s,Ns}var Os,Dp;function Nx(){if(Dp)return Os;Dp=1;var e=KC();function r(t){return t==null?"":e(t)}return Os=r,Os}var $s,Wp;function Vo(){if(Wp)return $s;Wp=1;var e=St(),r=fu(),t=UC(),n=Nx();function o(i,s){return e(i)?i:r(i,s)?[i]:t(n(i))}return $s=o,$s}var qs,Vp;function Xn(){if(Vp)return qs;Vp=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 qs=r,qs}var Ls,Gp;function Go(){if(Gp)return Ls;Gp=1;var e=Vo(),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 Ls=t,Ls}var Fs,Hp;function JC(){if(Hp)return Fs;Hp=1;var e=Go();function r(t,n,o){var i=t==null?void 0:e(t,n);return i===void 0?o:i}return Fs=r,Fs}var zs,Up;function ZC(){if(Up)return zs;Up=1;function e(r,t){return r!=null&&t in Object(r)}return zs=e,zs}var Bs,Kp;function Ox(){if(Kp)return Bs;Kp=1;var e=Vo(),r=Jn(),t=St(),n=Lo(),o=ru(),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 Bs=s,Bs}var Ds,Jp;function $x(){if(Jp)return Ds;Jp=1;var e=ZC(),r=Ox();function t(n,o){return n!=null&&r(n,o,e)}return Ds=t,Ds}var Ws,Zp;function XC(){if(Zp)return Ws;Zp=1;var e=Mx(),r=JC(),t=$x(),n=fu(),o=Tx(),i=Ix(),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 Ws=l,Ws}var Vs,Xp;function qx(){if(Xp)return Vs;Xp=1;function e(r){return function(t){return t==null?void 0:t[r]}}return Vs=e,Vs}var Gs,Yp;function YC(){if(Yp)return Gs;Yp=1;var e=Go();function r(t){return function(n){return e(n,t)}}return Gs=r,Gs}var Hs,Qp;function QC(){if(Qp)return Hs;Qp=1;var e=qx(),r=YC(),t=fu(),n=Xn();function o(i){return t(i)?e(n(i)):r(i)}return Hs=o,Hs}var Us,eg;function xr(){if(eg)return Us;eg=1;var e=VC(),r=XC(),t=Jr(),n=St(),o=QC();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 Us=i,Us}var Ks,tg;function Lx(){if(tg)return Ks;tg=1;var e=px(),r=NC(),t=xr(),n=St();function o(i,s){var a=n(i)?e:r;return a(i,t(s,3))}return Ks=o,Ks}var Js,rg;function eS(){if(rg)return Js;rg=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n,o){return n!=null&&r.call(n,o)}return Js=t,Js}var Zs,ng;function Fx(){if(ng)return Zs;ng=1;var e=eS(),r=Ox();function t(n,o){return n!=null&&r(n,o,e)}return Zs=t,Zs}var Xs,og;function tS(){if(og)return Xs;og=1;var e=ou(),r=gn(),t=Jn(),n=St(),o=br(),i=pn(),s=zo(),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 Xs=h,Xs}var Ys,ig;function zx(){if(ig)return Ys;ig=1;function e(r){return r===void 0}return Ys=e,Ys}var Qs,ag;function Bx(){if(ag)return Qs;ag=1;var e=Do(),r=br();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 Qs=t,Qs}var ec,sg;function Dx(){if(sg)return ec;sg=1;var e=Wo(),r=xr(),t=Bx(),n=St();function o(i,s){var a=n(i)?e:t;return a(i,r(s,3))}return ec=o,ec}var tc,cg;function rS(){if(cg)return tc;cg=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 tc=e,tc}var rc,lg;function nS(){if(lg)return rc;lg=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 rc=e,rc}var nc,dg;function Wx(){if(dg)return nc;dg=1;var e=rS(),r=Do(),t=xr(),n=nS(),o=St();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 nc=i,nc}var oc,ug;function oS(){if(ug)return oc;ug=1;var e=Hr(),r=St(),t=ur(),n="[object String]";function o(i){return typeof i=="string"||!r(i)&&t(i)&&e(i)==n}return oc=o,oc}var ic,fg;function iS(){if(fg)return ic;fg=1;var e=qx(),r=e("length");return ic=r,ic}var ac,hg;function aS(){if(hg)return ac;hg=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 ac=c,ac}var sc,pg;function sS(){if(pg)return sc;pg=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 sc=v,sc}var cc,gg;function cS(){if(gg)return cc;gg=1;var e=iS(),r=aS(),t=sS();function n(o){return r(o)?t(o):e(o)}return cc=n,cc}var lc,yg;function lS(){if(yg)return lc;yg=1;var e=ou(),r=gn(),t=br(),n=oS(),o=cS(),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 lc=a,lc}var dc,mg;function dS(){if(mg)return dc;mg=1;var e=tu(),r=Cx(),t=du(),n=xr(),o=Bo(),i=St(),s=pn(),a=Un(),c=Kt(),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 dc=d,dc}var uc,bg;function uS(){if(bg)return uc;bg=1;var e=hn(),r=Jn(),t=St(),n=e?e.isConcatSpreadable:void 0;function o(i){return t(i)||r(i)||!!(n&&i&&i[n])}return uc=o,uc}var fc,xg;function hu(){if(xg)return fc;xg=1;var e=au(),r=uS();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 fc=t,fc}var hc,vg;function fS(){if(vg)return hc;vg=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 hc=e,hc}var pc,wg;function Vx(){if(wg)return pc;wg=1;var e=fS(),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 pc=t,pc}var gc,Cg;function hS(){if(Cg)return gc;Cg=1;var e=cu(),r=lx(),t=Jr(),n=r?function(o,i){return r(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:t;return gc=n,gc}var yc,Sg;function pS(){if(Sg)return yc;Sg=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 yc=n,yc}var mc,jg;function Gx(){if(jg)return mc;jg=1;var e=hS(),r=pS(),t=r(e);return mc=t,mc}var bc,Eg;function Ho(){if(Eg)return bc;Eg=1;var e=Jr(),r=Vx(),t=Gx();function n(o,i){return t(r(o,i,e),o+"")}return bc=n,bc}var xc,_g;function Hx(){if(_g)return xc;_g=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 xc=e,xc}var vc,kg;function gS(){if(kg)return vc;kg=1;function e(r){return r!==r}return vc=e,vc}var wc,Pg;function yS(){if(Pg)return wc;Pg=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 wc=e,wc}var Cc,Ag;function mS(){if(Ag)return Cc;Ag=1;var e=Hx(),r=gS(),t=yS();function n(o,i,s){return i===i?t(o,i,s):e(o,r,s)}return Cc=n,Cc}var Sc,Rg;function bS(){if(Rg)return Sc;Rg=1;var e=mS();function r(t,n){var o=t==null?0:t.length;return!!o&&e(t,n,0)>-1}return Sc=r,Sc}var jc,Mg;function xS(){if(Mg)return jc;Mg=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 jc=e,jc}var Ec,Tg;function vS(){if(Tg)return Ec;Tg=1;function e(){}return Ec=e,Ec}var _c,Ig;function wS(){if(Ig)return _c;Ig=1;var e=xx(),r=vS(),t=uu(),n=1/0,o=e&&1/t(new e([,-0]))[1]==n?function(i){return new e(i)}:r;return _c=o,_c}var kc,Ng;function CS(){if(Ng)return kc;Ng=1;var e=Px(),r=bS(),t=xS(),n=Ax(),o=wS(),i=uu(),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 kc=a,kc}var Pc,Og;function Ux(){if(Og)return Pc;Og=1;var e=br(),r=ur();function t(n){return r(n)&&e(n)}return Pc=t,Pc}var Ac,$g;function SS(){if($g)return Ac;$g=1;var e=hu(),r=Ho(),t=CS(),n=Ux(),o=r(function(i){return t(e(i,1,n,!0))});return Ac=o,Ac}var Rc,qg;function jS(){if(qg)return Rc;qg=1;var e=Wo();function r(t,n){return e(n,function(o){return t[o]})}return Rc=r,Rc}var Mc,Lg;function Kx(){if(Lg)return Mc;Lg=1;var e=jS(),r=Ir();function t(n){return n==null?[]:e(n,r(n))}return Mc=t,Mc}var Tc,Fg;function Jt(){if(Fg)return Tc;Fg=1;var e;if(typeof Yd=="function")try{e={clone:MC(),constant:cu(),each:kx(),filter:Lx(),has:Fx(),isArray:St(),isEmpty:tS(),isFunction:Un(),isUndefined:zx(),keys:Ir(),map:Dx(),reduce:Wx(),size:lS(),transform:dS(),union:SS(),values:Kx()}}catch{}return e||(e=window._),Tc=e,Tc}var Ic,zg;function pu(){if(zg)return Ic;zg=1;var e=Jt();Ic=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 Ic}var Nc,Bg;function ES(){return Bg||(Bg=1,Nc="2.1.8"),Nc}var Oc,Dg;function _S(){return Dg||(Dg=1,Oc={Graph:pu(),version:ES()}),Oc}var $c,Wg;function kS(){if(Wg)return $c;Wg=1;var e=Jt(),r=pu();$c={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 $c}var qc,Vg;function PS(){if(Vg)return qc;Vg=1;var e=Jt();qc=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 qc}var Lc,Gg;function Jx(){if(Gg)return Lc;Gg=1;var e=Jt();Lc=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},Lc}var Fc,Hg;function Zx(){if(Hg)return Fc;Hg=1;var e=Jt(),r=Jx();Fc=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 Fc}var zc,Ug;function AS(){if(Ug)return zc;Ug=1;var e=Zx(),r=Jt();zc=t;function t(n,o,i){return r.transform(n.nodes(),function(s,a){s[a]=e(n,a,o,i)},{})}return zc}var Bc,Kg;function Xx(){if(Kg)return Bc;Kg=1;var e=Jt();Bc=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 Bc}var Dc,Jg;function RS(){if(Jg)return Dc;Jg=1;var e=Jt(),r=Xx();Dc=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 Dc}var Wc,Zg;function MS(){if(Zg)return Wc;Zg=1;var e=Jt();Wc=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 Wc}var Vc,Xg;function Yx(){if(Xg)return Vc;Xg=1;var e=Jt();Vc=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,Vc}var Gc,Yg;function TS(){if(Yg)return Gc;Yg=1;var e=Yx();Gc=r;function r(t){try{e(t)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Gc}var Hc,Qg;function Qx(){if(Qg)return Hc;Qg=1;var e=Jt();Hc=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 Hc}var Uc,ey;function IS(){if(ey)return Uc;ey=1;var e=Qx();Uc=r;function r(t,n){return e(t,n,"post")}return Uc}var Kc,ty;function NS(){if(ty)return Kc;ty=1;var e=Qx();Kc=r;function r(t,n){return e(t,n,"pre")}return Kc}var Jc,ry;function OS(){if(ry)return Jc;ry=1;var e=Jt(),r=pu(),t=Jx();Jc=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 Jc}var Zc,ny;function $S(){return ny||(ny=1,Zc={components:PS(),dijkstra:Zx(),dijkstraAll:AS(),findCycles:RS(),floydWarshall:MS(),isAcyclic:TS(),postorder:IS(),preorder:NS(),prim:OS(),tarjan:Xx(),topsort:Yx()}),Zc}var Xc,oy;function qS(){if(oy)return Xc;oy=1;var e=_S();return Xc={Graph:e.Graph,json:kS(),alg:$S(),version:e.version},Xc}var Yc,iy;function er(){if(iy)return Yc;iy=1;var e;if(typeof Yd=="function")try{e=qS()}catch{}return e||(e=window.graphlib),Yc=e,Yc}var Qc,ay;function LS(){if(ay)return Qc;ay=1;var e=jx(),r=1,t=4;function n(o){return e(o,r|t)}return Qc=n,Qc}var el,sy;function Uo(){if(sy)return el;sy=1;var e=fn(),r=br(),t=Lo(),n=Kt();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 el=o,el}var tl,cy;function FS(){if(cy)return tl;cy=1;var e=Ho(),r=fn(),t=Uo(),n=Kr(),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 tl=s,tl}var rl,ly;function zS(){if(ly)return rl;ly=1;var e=xr(),r=br(),t=Ir();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 rl=n,rl}var nl,dy;function BS(){if(dy)return nl;dy=1;var e=/\s/;function r(t){for(var n=t.length;n--&&e.test(t.charAt(n)););return n}return nl=r,nl}var ol,uy;function DS(){if(uy)return ol;uy=1;var e=BS(),r=/^\s+/;function t(n){return n&&n.slice(0,e(n)+1).replace(r,"")}return ol=t,ol}var il,fy;function WS(){if(fy)return il;fy=1;var e=DS(),r=Kt(),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 il=c,il}var al,hy;function ev(){if(hy)return al;hy=1;var e=WS(),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 al=n,al}var sl,py;function VS(){if(py)return sl;py=1;var e=ev();function r(t){var n=e(t),o=n%1;return n===n?o?n-o:n:0}return sl=r,sl}var cl,gy;function GS(){if(gy)return cl;gy=1;var e=Hx(),r=xr(),t=VS(),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 cl=o,cl}var ll,yy;function HS(){if(yy)return ll;yy=1;var e=zS(),r=GS(),t=e(r);return ll=t,ll}var dl,my;function tv(){if(my)return dl;my=1;var e=hu();function r(t){var n=t==null?0:t.length;return n?e(t,1):[]}return dl=r,dl}var ul,by;function US(){if(by)return ul;by=1;var e=lu(),r=Ex(),t=Kr();function n(o,i){return o==null?o:e(o,r(i),t)}return ul=n,ul}var fl,xy;function KS(){if(xy)return fl;xy=1;function e(r){var t=r==null?0:r.length;return t?r[t-1]:void 0}return fl=e,fl}var hl,vy;function JS(){if(vy)return hl;vy=1;var e=$o(),r=du(),t=xr();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 hl=n,hl}var pl,wy;function gu(){if(wy)return pl;wy=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 pl=r,pl}var gl,Cy;function ZS(){if(Cy)return gl;Cy=1;function e(r,t){return r>t}return gl=e,gl}var yl,Sy;function XS(){if(Sy)return yl;Sy=1;var e=gu(),r=ZS(),t=Jr();function n(o){return o&&o.length?e(o,t,r):void 0}return yl=n,yl}var ml,jy;function rv(){if(jy)return ml;jy=1;var e=$o(),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 ml=t,ml}var bl,Ey;function YS(){if(Ey)return bl;Ey=1;var e=Hr(),r=Bo(),t=ur(),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 bl=l,bl}var xl,_y;function nv(){if(_y)return xl;_y=1;function e(r,t){if(!(t==="constructor"&&typeof r[t]=="function")&&t!="__proto__")return r[t]}return xl=e,xl}var vl,ky;function QS(){if(ky)return vl;ky=1;var e=Kn(),r=Kr();function t(n){return e(n,r(n))}return vl=t,vl}var wl,Py;function ej(){if(Py)return wl;Py=1;var e=rv(),r=fx(),t=wx(),n=hx(),o=Sx(),i=Jn(),s=St(),a=Ux(),c=pn(),l=Un(),d=Kt(),u=YS(),h=Zn(),p=nv(),m=QS();function g(y,b,x,w,v,C,S){var E=p(y,x),R=p(b,x),A=S.get(R);if(A){e(y,x,A);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),$=!k&&!_&&h(R);I=R,k||_||$?s(E)?I=E:a(E)?I=n(E):_?(M=!1,I=r(R,!0)):$?(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 wl=g,wl}var Cl,Ay;function tj(){if(Ay)return Cl;Ay=1;var e=Oo(),r=rv(),t=lu(),n=ej(),o=Kt(),i=Kr(),s=nv();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 Cl=a,Cl}var Sl,Ry;function rj(){if(Ry)return Sl;Ry=1;var e=Ho(),r=Uo();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 Sl=t,Sl}var jl,My;function nj(){if(My)return jl;My=1;var e=tj(),r=rj(),t=r(function(n,o,i){e(n,o,i)});return jl=t,jl}var El,Ty;function ov(){if(Ty)return El;Ty=1;function e(r,t){return r<t}return El=e,El}var _l,Iy;function oj(){if(Iy)return _l;Iy=1;var e=gu(),r=ov(),t=Jr();function n(o){return o&&o.length?e(o,t,r):void 0}return _l=n,_l}var kl,Ny;function ij(){if(Ny)return kl;Ny=1;var e=gu(),r=xr(),t=ov();function n(o,i){return o&&o.length?e(o,r(i,2),t):void 0}return kl=n,kl}var Pl,Oy;function aj(){if(Oy)return Pl;Oy=1;var e=rr(),r=function(){return e.Date.now()};return Pl=r,Pl}var Al,$y;function sj(){if($y)return Al;$y=1;var e=qo(),r=Vo(),t=Lo(),n=Kt(),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 Al=i,Al}var Rl,qy;function cj(){if(qy)return Rl;qy=1;var e=Go(),r=sj(),t=Vo();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 Rl=n,Rl}var Ml,Ly;function lj(){if(Ly)return Ml;Ly=1;var e=cj(),r=$x();function t(n,o){return e(n,o,function(i,s){return r(n,s)})}return Ml=t,Ml}var Tl,Fy;function dj(){if(Fy)return Tl;Fy=1;var e=tv(),r=Vx(),t=Gx();function n(o){return t(r(o,void 0,e),o+"")}return Tl=n,Tl}var Il,zy;function uj(){if(zy)return Il;zy=1;var e=lj(),r=dj(),t=r(function(n,o){return n==null?{}:e(n,o)});return Il=t,Il}var Nl,By;function fj(){if(By)return Nl;By=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 Nl=t,Nl}var Ol,Dy;function hj(){if(Dy)return Ol;Dy=1;var e=fj(),r=Uo(),t=ev();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 Ol=n,Ol}var $l,Wy;function pj(){if(Wy)return $l;Wy=1;var e=hj(),r=e();return $l=r,$l}var ql,Vy;function gj(){if(Vy)return ql;Vy=1;function e(r,t){var n=r.length;for(r.sort(t);n--;)r[n]=r[n].value;return r}return ql=e,ql}var Ll,Gy;function yj(){if(Gy)return Ll;Gy=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 Ll=r,Ll}var Fl,Hy;function mj(){if(Hy)return Fl;Hy=1;var e=yj();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 Fl=r,Fl}var zl,Uy;function bj(){if(Uy)return zl;Uy=1;var e=Wo(),r=Go(),t=xr(),n=Bx(),o=gj(),i=Fo(),s=mj(),a=Jr(),c=St();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 zl=l,zl}var Bl,Ky;function xj(){if(Ky)return Bl;Ky=1;var e=hu(),r=bj(),t=Ho(),n=Uo(),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 Bl=o,Bl}var Dl,Jy;function vj(){if(Jy)return Dl;Jy=1;var e=Nx(),r=0;function t(n){var o=++r;return e(n)+o}return Dl=t,Dl}var Wl,Zy;function wj(){if(Zy)return Wl;Zy=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 Wl=e,Wl}var Vl,Xy;function Cj(){if(Xy)return Vl;Xy=1;var e=qo(),r=wj();function t(n,o){return r(n||[],o||[],e)}return Vl=t,Vl}var Gl,Yy;function xt(){if(Yy)return Gl;Yy=1;var e;if(typeof Yd=="function")try{e={cloneDeep:LS(),constant:cu(),defaults:FS(),each:kx(),filter:Lx(),find:HS(),flatten:tv(),forEach:_x(),forIn:US(),has:Fx(),isUndefined:zx(),last:KS(),map:Dx(),mapValues:JS(),max:XS(),merge:nj(),min:oj(),minBy:ij(),now:aj(),pick:uj(),range:pj(),reduce:Wx(),sortBy:xj(),uniqueId:vj(),values:Kx(),zipObject:Cj()}}catch{}return e||(e=window._),Gl=e,Gl}var Hl,Qy;function Sj(){if(Qy)return Hl;Qy=1,Hl=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 Hl}var Ul,em;function jj(){if(em)return Ul;em=1;var e=xt(),r=er().Graph,t=Sj();Ul=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 Ul}var Kl,tm;function Ej(){if(tm)return Kl;tm=1;var e=xt(),r=jj();Kl={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 Kl}var Jl,rm;function $t(){if(rm)return Jl;rm=1;var e=xt(),r=er().Graph;Jl={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,A;return Math.abs(C)*S>Math.abs(v)*E?(C<0&&(E=-E),R=E*v/C,A=E):(v<0&&(S=-S),R=S,A=S*C/v),{x:x+R,y:w+A}}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 Jl}var Zl,nm;function _j(){if(nm)return Zl;nm=1;var e=xt(),r=$t();Zl={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 Zl}var Xl,om;function mo(){if(om)return Xl;om=1;var e=xt();Xl={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 Xl}var Yl,im;function iv(){if(im)return Yl;im=1;var e=xt(),r=er().Graph,t=mo().slack;Yl=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 Yl}var Ql,am;function kj(){if(am)return Ql;am=1;var e=xt(),r=iv(),t=mo().slack,n=mo().longestPath,o=er().alg.preorder,i=er().alg.postorder,s=$t().simplify;Ql=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,A=v.edge(C,E),I=0;return A||(R=!1,A=v.edge(E,C)),I=A.weight,e.forEach(v.nodeEdges(C),function(M){var k=M.v===C,_=k?M.w:M.v;if(_!==E){var $=k===R,N=v.edge(M).weight;if(I+=$?N:-N,b(w,C,_)){var W=w.edge(C,_).cutvalue;I+=$?-W:W}}}),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,A=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))}),A.low=R,A.lim=C++,E?A.parent=E:delete A.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),A=w.node(E),I=R,M=!1;R.lim>A.lim&&(I=A,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,A=v.edge(E,R),I=!1;A||(A=v.edge(R,E),I=!0),v.node(E).rank=v.node(R).rank+(I?A.minlen:-A.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 Ql}var ed,sm;function Pj(){if(sm)return ed;sm=1;var e=mo(),r=e.longestPath,t=iv(),n=kj();ed=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 ed}var td,cm;function Aj(){if(cm)return td;cm=1;var e=xt();td=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 td}var rd,lm;function Rj(){if(lm)return rd;lm=1;var e=xt(),r=$t();rd={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 rd}var nd,dm;function Mj(){if(dm)return nd;dm=1;var e=xt(),r=$t();nd=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 nd}var od,um;function Tj(){if(um)return od;um=1;var e=xt();od={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 od}var id,fm;function Ij(){if(fm)return id;fm=1;var e=xt();id=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 id}var ad,hm;function Nj(){if(hm)return ad;hm=1;var e=xt();ad=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 ad}var sd,pm;function Oj(){if(pm)return sd;pm=1;var e=xt();sd=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 sd}var cd,gm;function $j(){if(gm)return cd;gm=1;var e=xt();cd=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 cd}var ld,ym;function qj(){if(ym)return ld;ym=1;var e=xt(),r=$t();ld=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 ld}var dd,mm;function Lj(){if(mm)return dd;mm=1;var e=xt(),r=Oj(),t=$j(),n=qj();dd=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 dd}var ud,bm;function Fj(){if(bm)return ud;bm=1;var e=xt(),r=er().Graph;ud=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 ud}var fd,xm;function zj(){if(xm)return fd;xm=1;var e=xt();fd=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 fd}var hd,vm;function Bj(){if(vm)return hd;vm=1;var e=xt(),r=Ij(),t=Nj(),n=Lj(),o=Fj(),i=zj(),s=er().Graph,a=$t();hd=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 hd}var pd,wm;function Dj(){if(wm)return pd;wm=1;var e=xt(),r=er().Graph,t=$t();pd={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,A=C.length,I=e.last(S);return e.forEach(S,function(M,k){var _=i(b,M),$=_?b.node(_).order:A;(_||M===I)&&(e.forEach(S.slice(R,k+1),function(N){e.forEach(b.predecessors(N),function(W){var T=b.node(W),Q=T.order;(Q<E||$<Q)&&!(T.dummy&&b.node(N).dummy)&&s(w,W,N)})}),R=k+1,E=$)}),S}return e.reduce(x,v),w}function o(b,x){var w={};function v(S,E,R,A,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 $=b.node(_);$.dummy&&($.order<A||$.order>I)&&s(w,_,M)})})}function C(S,E){var R=-1,A,I=0;return e.forEach(E,function(M,k){if(b.node(M).dummy==="border"){var _=b.predecessors(M);_.length&&(A=b.node(_[0]).order,v(E,I,k,R,A),I=k,R=A)}v(E,I,E.length,A,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(A,I){C[A]=A,S[A]=A,E[A]=I})}),e.forEach(x,function(R){var A=-1;e.forEach(R,function(I){var M=v(I);if(M.length){M=e.sortBy(M,function(W){return E[W]});for(var k=(M.length-1)/2,_=Math.floor(k),$=Math.ceil(k);_<=$;++_){var N=M[_];S[I]===I&&A<E[N]&&!a(w,I,N)&&(S[N]=I,S[I]=C[I]=C[N],A=E[N])}}})}),{root:C,align:S}}function l(b,x,w,v,C){var S={},E=d(b,x,w,C),R=C?"borderLeft":"borderRight";function A(k,_){for(var $=E.nodes(),N=$.pop(),W={};N;)W[N]?k(N):(W[N]=!0,$.push(N),$=$.concat(_(N))),N=$.pop()}function I(k){S[k]=E.inEdges(k).reduce(function(_,$){return Math.max(_,S[$.v]+E.edge($))},0)}function M(k){var _=E.outEdges(k).reduce(function(N,W){return Math.min(N,S[W.w]-E.edge(W))},Number.POSITIVE_INFINITY),$=b.node(k);_!==Number.POSITIVE_INFINITY&&$.borderType!==R&&(S[k]=Math.max(S[k],_))}return A(I,E.predecessors.bind(E)),A(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 A;e.forEach(R,function(I){var M=w[I];if(C.setNode(M),A){var k=w[A],_=C.edge(k,M);C.setEdge(k,M,Math.max(E(b,I,A),_||0))}A=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,A=b[R],I;if(A!==x){var M=e.values(A);I=E==="l"?v-e.min(M):C-e.max(M),I&&(b[R]=e.mapValues(A,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 A=(E==="u"?b.predecessors:b.successors).bind(b),I=c(b,C,w,A),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),A=0,I;if(A+=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&&(A+=w?I:-I),I=0,A+=(E.dummy?x:b)/2,A+=(R.dummy?x:b)/2,A+=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&&(A+=w?I:-I),I=0,A}}function y(b,x){return b.node(x).width}return pd}var gd,Cm;function Wj(){if(Cm)return gd;Cm=1;var e=xt(),r=$t(),t=Dj().positionX;gd=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 gd}var yd,Sm;function Vj(){if(Sm)return yd;Sm=1;var e=xt(),r=Ej(),t=_j(),n=Pj(),o=$t().normalizeRanks,i=Aj(),s=$t().removeEmptyRanks,a=Rj(),c=Mj(),l=Tj(),d=Bj(),u=Wj(),h=$t(),p=er().Graph;yd=m;function m(q,F){var G=F&&F.debugTiming?h.time:h.notime;G("layout",function(){var se=G(" buildLayoutGraph",function(){return A(q)});G(" runLayout",function(){g(se,G)}),G(" updateInputGraph",function(){y(q,se)})})}function g(q,F){F(" makeSpaceForEdgeLabels",function(){I(q)}),F(" removeSelfEdges",function(){ue(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(){K(q)}),F(" adjustCoordinateSystem",function(){l.adjust(q)}),F(" position",function(){u(q)}),F(" positionSelfEdges",function(){ce(q)}),F(" removeBorderNodes",function(){Q(q)}),F(" normalize.undo",function(){t.undo(q)}),F(" fixupEdgeLabelCoords",function(){W(q)}),F(" undoCoordinateSystem",function(){l.undo(q)}),F(" translateGraph",function(){$(q)}),F(" assignNodeIntersects",function(){N(q)}),F(" reversePoints",function(){T(q)}),F(" acyclic.undo",function(){r.undo(q)})}function y(q,F){e.forEach(q.nodes(),function(G){var se=q.node(G),U=F.node(G);se&&(se.x=U.x,se.y=U.y,F.children(G).length&&(se.width=U.width,se.height=U.height))}),e.forEach(q.edges(),function(G){var se=q.edge(G),U=F.edge(G);se.points=U.points,e.has(U,"x")&&(se.x=U.x,se.y=U.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 A(q){var F=new p({multigraph:!0,compound:!0}),G=re(q.graph());return F.setGraph(e.merge({},x,V(G,b),e.pick(G,w))),e.forEach(q.nodes(),function(se){var U=re(q.node(se));F.setNode(se,e.defaults(V(U,v),C)),F.setParent(se,q.parent(se))}),e.forEach(q.edges(),function(se){var U=re(q.edge(se));F.setEdge(se,e.merge({},E,V(U,S),e.pick(U,R)))}),F}function I(q){var F=q.graph();F.ranksep/=2,e.forEach(q.edges(),function(G){var se=q.edge(G);se.minlen*=2,se.labelpos.toLowerCase()!=="c"&&(F.rankdir==="TB"||F.rankdir==="BT"?se.width+=se.labeloffset:se.height+=se.labeloffset)})}function M(q){e.forEach(q.edges(),function(F){var G=q.edge(F);if(G.width&&G.height){var se=q.node(F.v),U=q.node(F.w),Y={rank:(U.rank-se.rank)/2+se.rank,e:F};h.addDummyNode(q,"edge-proxy",Y,"_ep")}})}function k(q){var F=0;e.forEach(q.nodes(),function(G){var se=q.node(G);se.borderTop&&(se.minRank=q.node(se.borderTop).rank,se.maxRank=q.node(se.borderBottom).rank,F=e.max(F,se.maxRank))}),q.graph().maxRank=F}function _(q){e.forEach(q.nodes(),function(F){var G=q.node(F);G.dummy==="edge-proxy"&&(q.edge(G.e).labelRank=G.rank,q.removeNode(F))})}function $(q){var F=Number.POSITIVE_INFINITY,G=0,se=Number.POSITIVE_INFINITY,U=0,Y=q.graph(),le=Y.marginx||0,ne=Y.marginy||0;function de(xe){var he=xe.x,H=xe.y,J=xe.width,fe=xe.height;F=Math.min(F,he-J/2),G=Math.max(G,he+J/2),se=Math.min(se,H-fe/2),U=Math.max(U,H+fe/2)}e.forEach(q.nodes(),function(xe){de(q.node(xe))}),e.forEach(q.edges(),function(xe){var he=q.edge(xe);e.has(he,"x")&&de(he)}),F-=le,se-=ne,e.forEach(q.nodes(),function(xe){var he=q.node(xe);he.x-=F,he.y-=se}),e.forEach(q.edges(),function(xe){var he=q.edge(xe);e.forEach(he.points,function(H){H.x-=F,H.y-=se}),e.has(he,"x")&&(he.x-=F),e.has(he,"y")&&(he.y-=se)}),Y.width=G-F+le,Y.height=U-se+ne}function N(q){e.forEach(q.edges(),function(F){var G=q.edge(F),se=q.node(F.v),U=q.node(F.w),Y,le;G.points?(Y=G.points[0],le=G.points[G.points.length-1]):(G.points=[],Y=U,le=se),G.points.unshift(h.intersectRect(se,Y)),G.points.push(h.intersectRect(U,le))})}function W(q){e.forEach(q.edges(),function(F){var G=q.edge(F);if(e.has(G,"x"))switch((G.labelpos==="l"||G.labelpos==="r")&&(G.width-=G.labeloffset),G.labelpos){case"l":G.x-=G.width/2+G.labeloffset;break;case"r":G.x+=G.width/2+G.labeloffset;break}})}function T(q){e.forEach(q.edges(),function(F){var G=q.edge(F);G.reversed&&G.points.reverse()})}function Q(q){e.forEach(q.nodes(),function(F){if(q.children(F).length){var G=q.node(F),se=q.node(G.borderTop),U=q.node(G.borderBottom),Y=q.node(e.last(G.borderLeft)),le=q.node(e.last(G.borderRight));G.width=Math.abs(le.x-Y.x),G.height=Math.abs(U.y-se.y),G.x=Y.x+G.width/2,G.y=se.y+G.height/2}}),e.forEach(q.nodes(),function(F){q.node(F).dummy==="border"&&q.removeNode(F)})}function ue(q){e.forEach(q.edges(),function(F){if(F.v===F.w){var G=q.node(F.v);G.selfEdges||(G.selfEdges=[]),G.selfEdges.push({e:F,label:q.edge(F)}),q.removeEdge(F)}})}function K(q){var F=h.buildLayerMatrix(q);e.forEach(F,function(G){var se=0;e.forEach(G,function(U,Y){var le=q.node(U);le.order=Y+se,e.forEach(le.selfEdges,function(ne){h.addDummyNode(q,"selfedge",{width:ne.label.width,height:ne.label.height,rank:le.rank,order:Y+ ++se,e:ne.e,label:ne.label},"_se")}),delete le.selfEdges})})}function ce(q){e.forEach(q.nodes(),function(F){var G=q.node(F);if(G.dummy==="selfedge"){var se=q.node(G.e.v),U=se.x+se.width/2,Y=se.y,le=G.x-U,ne=se.height/2;q.setEdge(G.e,G.label),q.removeNode(F),G.label.points=[{x:U+2*le/3,y:Y-ne},{x:U+5*le/6,y:Y-ne},{x:U+le,y:Y},{x:U+5*le/6,y:Y+ne},{x:U+2*le/3,y:Y+ne}],G.label.x=G.x,G.label.y=G.y}})}function V(q,F){return e.mapValues(e.pick(q,F),Number)}function re(q){var F={};return e.forEach(q,function(G,se){F[se.toLowerCase()]=G}),F}return yd}var md,jm;function Gj(){if(jm)return md;jm=1;var e=xt(),r=$t(),t=er().Graph;md={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 md}var bd,Em;function Hj(){return Em||(Em=1,bd="0.8.5"),bd}var xd,_m;function Uj(){return _m||(_m=1,xd={graphlib:er(),layout:Vj(),debug:Gj(),util:{time:$t().time,notime:$t().notime},version:Hj()}),xd}var Kj=Uj();const km=T1(Kj);function Jj(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 km.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=ox(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*nx: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)}km.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 Md(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 Pm(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 av(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 yu(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 Ar(e,r,t=e.fixedSizes){const n=Md(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,sr({...i,...s}))}return n}function sv(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=sv(o[i],o[s],r,t);a&&n.push(a)}return n}function cv(e,r={}){const t=yu(r),{groups:n}=Yn(e);return Vn(n,Ar(e,e.positions),t)}function lv(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 Zj(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=Ar(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),A=c.get(E),I=(R.y1+R.y2-A.y1-A.y2)/2;return Math.abs(I)>1?I:R.x1-A.x1});for(const S of h){const E=u.at(-1),R=c.get(S),A=E&&c.get(E[0]);A&&Math.abs(R.y1+R.y2-A.y1-A.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((A,I)=>{var M,k;return{id:A,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 vd(e,r={}){var d;av(r.adjustment);const t=yu(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 Xj(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=Ar(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=lv(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})),A=(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((_,$)=>{const N=h.get(_),W={x:A+($-(C-1)/2)*S-(N.x1+N.x2)/2,y:I+(k-(v.length-1)/2)*E-(N.y1+N.y2)/2};for(const T of s.get(_)??[]){const Q=a.get(T);a.set(T,{x:Q.x+W.x,y:Q.y+W.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,Ar(e,a),Math.min(n.x,n.y))}}function Xj(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:cv(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=lv(y,r,x,C),E=S.length,R=Math.min(t.y,v/(2*E)),A=(N=($=r.adjustment)==null?void 0:$.sections)==null?void 0:N[x],I=Array.from({length:E},(W,T)=>{var Q;return((Q=A==null?void 0:A.rows)==null?void 0:Q[T])??1}),M=I.reduce((W,T)=>W+T,0),k=v-(E-1)*R;let _=b.y1;for(let W=0;W<E;W++){const T=k*I[W]/M,Q=S[W].length,ue=Math.min(t.x,w/(2*Q)),K=Array.from({length:Q},(q,F)=>{var G,se;return((se=(G=A==null?void 0:A.columns)==null?void 0:G[W])==null?void 0:se[F])??1}),ce=K.reduce((q,F)=>q+F,0),V=w-(Q-1)*ue;let re=b.x1;for(let q=0;q<Q;q++){const F=S[W][q],G=V*K[q]/ce,se=i.get(F);if(se){a.set(F,{x:re+G/2,y:_+T/2}),h.set(F,{w:G,h:T});const U=Math.min(e.padding(F),Math.max(0,(Math.min(G,T)-1)/2));m(se,{x1:re+U,y1:_+U,x2:re+G-U,y2:_+T-U},F)}else a.has(F)&&(a.set(F,{x:re+G/2,y:_+T/2}),h.set(F,{w:G,h:T}));q<Q-1&&p.push({section:x,axis:"x",row:W,index:q,weights:K,length:V,position:{x:re+G+ue/2,y:_+T/2}}),re+=G+ue}W<E-1&&p.push({section:x,axis:"y",row:W,index:W,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,Ar({...e,sizes:h},a,h),0)}}function Yj(e,r={}){const t=yu(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,Ar(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=Ar(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=sv(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),A=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,A*I/(C?1:2)),C||m(x,S,-A*I/(v?1:2)),u=!0}}if(l++,c=Vn(o,Ar(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 Qj({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?X.PiArrowsHorizontal:X.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(Pm(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(Pm(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 Am=(e,r)=>e.left<r.right&&e.right>r.left&&e.top<r.bottom&&e.bottom>r.top,wd=new WeakMap;function Rm(e,r){const t=[...r.querySelectorAll(".flow-sdk-edge-label")];if(!t.length){wd.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=wd.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=A=>s.some(I=>Am(A,I))||[...d.values()].some(I=>Am(A,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},(A,I)=>g.getPointAtLength(x*I/C)),R=Array.from({length:C+1},(A,I)=>{const M=x*I/C,k=S[I],_=h?{x:k.x,y:k.y-b.height/2-15}:k,$=g.getPointAtLength(Math.max(0,M-2)),N=g.getPointAtLength(Math.min(x,M+2));let W=Math.atan2(N.y-$.y,N.x-$.x)*180/Math.PI;W>90&&(W-=180),W<-90&&(W+=180);const T=Math.abs(W)<1;h&&(W=0);const Q=W*Math.PI/180,ue=Math.abs(Math.cos(Q))*b.width+Math.abs(Math.sin(Q))*b.height,K=Math.abs(Math.sin(Q))*b.width+Math.abs(Math.cos(Q))*b.height;return{point:_,angle:W,straight:T,score:Math.hypot(_.x-w,_.y-v),bounds:{left:_.x-ue/2-8,right:_.x+ue/2+8,top:_.y-K/2-8,bottom:_.y+K/2+8}}}).sort((A,I)=>A.score-I.score).find(A=>!m(A.bounds)&&(!h||A.straight&&!S.some(I=>I.x>A.bounds.left&&I.x<A.bounds.right&&I.y>A.bounds.top&&I.y<A.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)}wd.set(r,{geometry:c,transforms:new Map(t.map(u=>[u,u.getAttribute("transform")??""]))})}function eE(e){const r=e.getBoundingClientRect(),t=r.height/e.offsetHeight;if(!Number.isFinite(t)||t<=0)return[];const n=tx(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=Yb(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 tE({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:A="LR",onPropertyRows:I,onSurface:M,children:k}){var se,U;const _=j.useRef(null),[$,N]=j.useState([]),W=m??$,[T,Q]=j.useState(),ue=j.useId(),K=j.useRef(),ce=!!l,V=!!(l!=null&&l.floating);j.useLayoutEffect(()=>{var xe;const Y=_.current;if(!Y||!ce)return;const le=Y.cloneNode(!0);le.removeAttribute("data-node-id"),le.removeAttribute("data-grid-dragging"),le.removeAttribute("data-grid-draggable"),le.removeAttribute("data-grid-drop-target"),le.setAttribute("data-grid-preview",e),le.setAttribute("aria-hidden","true"),le.setAttribute("inert","");const ne=[le,...le.querySelectorAll("*")],de=new Map(ne.filter(he=>he.id).map(he=>[he.id,`${he.id}-${ue}`]));for(const he of ne){he.id&&(he.id=de.get(he.id));for(const H of[...he.attributes]){if(H.name==="id")continue;let J=H.value;for(const[fe,ve]of de)J===`#${fe}`&&(J=`#${ve}`),J=J.split(`url(#${fe})`).join(`url(#${ve})`);J!==H.value&&he.setAttribute(H.name,J)}}if(Object.assign(le.style,{opacity:"0.35",zIndex:V?"2147483647":"11",pointerEvents:"none",outline:"none",visibility:"visible"}),V){const he=getComputedStyle(Y);le.setAttribute("data-grid-preview-floating",""),Object.assign(le.style,{position:"fixed",left:"0",top:"0",transformOrigin:"top left",font:he.font,color:he.color});for(const H of ne)H.removeAttribute("data-node-id"),H.style.pointerEvents="none"}return le.querySelectorAll(".flow-sdk-node-animation, .flow-sdk-handle, .flow-sdk-property-port, [data-flow-collapse-control]").forEach(he=>he.remove()),(xe=V?document.body:Y.parentElement)==null||xe.appendChild(le),K.current=le,()=>{le.remove(),K.current=void 0}},[e,ue,ce,V]),j.useLayoutEffect(()=>{const Y=K.current;if(!Y||!l)return;const{x:le,y:ne,size:de}=l;if(V&&_.current){const H=_.current,J=H.getBoundingClientRect(),fe=J.width/H.offsetWidth||1,ve=J.height/H.offsetHeight||1,Re=J.left+(le-r)*fe,Je=J.top+(ne-t)*ve;Y.style.transform=`translate3d(${Re}px, ${Je}px, 0) scale(${fe}, ${ve})`,Y.style.width=`${H.offsetWidth}px`,Y.style.height=`${H.offsetHeight}px`;return}const xe=de?Math.round(le-de.w/2):le,he=de?Math.round(ne-de.h/2):ne;Y.style.transform=de?`translate3d(${xe}px, ${he}px, 0)`:`translate(-50%, -50%) translate3d(${xe}px, ${he}px, 0)`,Y.style.width=de?`${Math.round(le+de.w/2)-xe}px`:"",Y.style.height=de?`${Math.round(ne+de.h/2)-he}px`:"",de&&(Y.style.setProperty("--flow-grid-width",`${de.w}px`),Y.style.setProperty("--flow-grid-height",`${de.h}px`),Y.style.setProperty("--flow-grid-font",`${Math.max(12,Math.min(48,de.w/8,de.h/5))}px`))},[l==null?void 0:l.x,l==null?void 0:l.y,(se=l==null?void 0:l.size)==null?void 0:se.w,(U=l==null?void 0:l.size)==null?void 0:U.h,V,r,t]),j.useLayoutEffect(()=>{const Y=_.current;if(!Y)return;const le=()=>{const xe=tx(Y);Q(he=>JSON.stringify(he)===JSON.stringify(xe)?he:xe),M==null||M(e,xe)};le();const ne=new ResizeObserver(le);ne.observe(Y);const de=Y.querySelector("[data-flow-node-surface]");return de&&ne.observe(de),()=>ne.disconnect()},[e,k,M]),j.useLayoutEffect(()=>(d(e,_.current),()=>{d(e,null),M==null||M(e,void 0)}),[e,d,M]),j.useLayoutEffect(()=>{const Y=_.current;if(!Y)return;let le="";const ne=()=>{const H=eE(Y),J=E?H:H.filter(ve=>ve.anchor),fe=JSON.stringify(J);fe!==le&&(le=fe,N(J),I==null||I(e,J))};if(ne(),!E&&!Y.querySelector("[data-flow-port-side]"))return;const de=new ResizeObserver(ne),xe=()=>{de.disconnect(),de.observe(Y),Y.querySelectorAll("[data-flow-property]").forEach(H=>de.observe(H)),ne()};xe();const he=new MutationObserver(xe);return he.observe(Y,{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"]}),Y.addEventListener("scroll",ne,!0),()=>{de.disconnect(),he.disconnect(),Y.removeEventListener("scroll",ne,!0)}},[e,E,I,k]);const re=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)-re:void 0,G=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(${re}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:G,...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(Y=>`${Y.x} ${Y.y}`).join(" L")} Z`:void 0,color:x||y||"currentColor",strokeWidth:w})}),u&&E&&W.map(Y=>["source","target"].filter(le=>!Y.role||Y.role===le).filter(le=>h||(p==null?void 0:p.has(`${le}:${Y.property}`))).map(le=>{var ne;return f.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":Y.property,"data-port-role":le,"data-port-side":(ne=Y.anchor)==null?void 0:ne.side,"aria-label":`${le==="source"?"Connect":"Input"} ${Y.property}`,title:`${le==="source"?"Connect":"Input"} ${Y.property}`,style:{color:y,...Y.anchor?{top:Y.anchor.y,left:Y.anchor.x-16}:{top:Y.top+Y.height/2,[le==="source"!=!!R?"right":"left"]:-16}},onClick:de=>de.stopPropagation()},`${Y.property}:${le}`)})),u&&!g&&(!E||!W.length)&&(!E||!W.some(Y=>Y.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)+(A==="RL"?-36:A==="LR"?(T==null?void 0:T.width)??C:((T==null?void 0:T.width)??C)/2),top:((T==null?void 0:T.top)??0)+(A==="BT"?-36:A==="TB"?(T==null?void 0:T.height)??S:((T==null?void 0:T.height)??S)/2),transform:A==="BT"||A==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:Y=>Y.stopPropagation(),children:f.jsx(X.PiPlusBold,{size:24})})]})}const rE=j.memo(tE);function nE(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 oE{constructor(r,t,n){Vt(this,"_pan");Vt(this,"_zoom");Vt(this,"minZoom");Vt(this,"maxZoom");Vt(this,"size",{w:0,h:0});Vt(this,"listeners",new Set);Vt(this,"cancelTransition");Vt(this,"animationVersion",0);Vt(this,"captureTransition");Vt(this,"animationsDisabled",!1);Vt(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=Zb(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=Xb(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 iE={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},ao={w:60,h:60},Cd=4,aE=30,sE=500,cE=45;function Mm(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 lE(e){var ju,Eu,_u,ku,Pu;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"?nf:Xu)(C.id,r,t):null,[C,r,t]),R=i==="auto"||i==="properties",A=j.useMemo(()=>t.filter(P=>Rd(P,i)&&(!E||E.has(P.source)&&E.has(P.target))),[t,i,E]),I=j.useMemo(()=>k1(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),$=j.useRef(null),N=j.useRef(null),W=j.useRef(null),T=j.useMemo(()=>new oE(p,u,h),[]);j.useEffect(()=>{T.minZoom=u,T.maxZoom=h},[T,u,h]),j.useLayoutEffect(()=>{T.setAnimationsDisabled(v)},[T,v]);const Q=j.useRef(new Map),ue=j.useRef(new Map),K=j.useRef(new Map),ce=j.useRef(null),[V,re]=j.useState(new Map),q=j.useCallback((P,L)=>{re(B=>{if(JSON.stringify(B.get(P))===JSON.stringify(L))return B;const Z=new Map(B);return L?Z.set(P,L):Z.delete(P),Z})},[]),[F,G]=j.useState(new Map),se=j.useRef(F),U=j.useCallback((P,L)=>{G(B=>{if(JSON.stringify(B.get(P)??[])===JSON.stringify(L))return B;const Z=new Map(B);return L.length?Z.set(P,L):Z.delete(P),Z})},[]),[Y,le]=j.useState(()=>new Map),ne=j.useRef(Y);ne.current=Y;const[de,xe]=j.useState(new Map),he=j.useRef(de),H=()=>{he.current=new Map,xe(he.current)},J=j.useRef(new Map(Object.entries(e.fixedNodePositions??{}))),fe=j.useRef(new Set(Object.keys(e.fixedNodePositions??{}))),ve=j.useRef(null),Re=j.useRef(!1),[Je,st]=j.useState(0),Ye=j.useRef(),We=j.useRef(),Ze=j.useRef(null),me=j.useRef(),Ae=j.useRef(!1),oe=j.useRef(null),ie=j.useRef(null),Ne=j.useRef(),Qe=j.useRef(l),Ee=s,Le=j.useRef(Ee),[ct,Ue]=j.useState(!0),[ht,pt]=j.useState(!!((ju=e.initialNodeGrid)!=null&&ju.enabled)),[At,zt]=j.useState([]),tt=j.useRef((Eu=e.initialNodeGrid)!=null&&Eu.enabled?{options:{...e.initialNodeGrid.options,animate:!1},order:[...e.initialNodeGrid.order??e.initialNodeGrid.options.order??r.map(P=>P.id)],previousPositions:new Map,previousViewport:p,previousSize:{w:0,h:0},ready:!1}:null),[Ve,nr]=j.useState(null),gt=j.useRef(null);gt.current=E;const Bt=j.useRef(1);Bt.current=(C==null?void 0:C.mode)==="connections"?1.25:1;const fr=j.useRef(null),De=j.useRef(r),Zt=j.useRef([]),Dt=j.useRef(!1),hr=()=>{var P;(P=Ze.current)==null||P.call(Ze),Ze.current=null,me.current=void 0},z=()=>{ie.current=null,Zt.current.length&&!J.current.size&&(Dt.current=!0),!Re.current&&k.current.fitOnInit!==!1&&(Ae.current=!0),clearTimeout(We.current),We.current=setTimeout(()=>{Re.current=ne.current.size>0,st(P=>P+1)},sE)},O=(P,L,B,Z=z,ge)=>{hr();const _e=new Map(ne.current),Se=new Map([...Q.current,...he.current]);Ze.current=Xb(L,je=>{const Xe=new Map;if(P.forEach((qe,Be)=>{const Pe=_e.get(Be);Xe.set(Be,J.current.get(Be)??(Pe?{x:Pe.x+(qe.x-Pe.x)*je,y:Pe.y+(qe.y-Pe.y)*je}:qe))}),ne.current=Xe,le(Xe),ge){const qe=new Map;for(const[Be,Pe]of ge){const ee=Se.get(Be)??Pe;qe.set(Be,{w:ee.w+(Pe.w-ee.w)*je,h:ee.h+(Pe.h-ee.h)*je})}he.current=qe,xe(qe)}B==null||B(je)},Z)},ae=()=>{var Be;if(clearTimeout(Ye.current),tt.current){mt.arrangeNodesInGrid(tt.current.options);return}he.current.size&&H();const P=k.current,L=Bt.current,B=M.current,Z=new Set(P.nodes.filter(Pe=>Pe.label===void 0).map(Pe=>Pe.id)),ge=B.nodes.map(Pe=>{const ee=ue.current.get(Pe.id);ee&&(ee.offsetWidth||ee.offsetHeight)&&Q.current.set(Pe.id,{w:ee.offsetWidth,h:ee.offsetHeight});const te=Q.current.get(Pe.id)||ao;return{id:Pe.id,parent:Pe.parent,width:te.w,height:te.h,hasBody:Z.has(Pe.id)}});let _e;try{const Pe=P.compactPropertyLayout,ee=P.edgeMode!=="nodes"&&P.edgeMode!=="workflow",te=B.edges.map(ye=>({...ye,connectorClearance:Pe?ee&&(ye.sourceProperty!==void 0||ye.targetProperty!==void 0)?_1:E1:0}));_e=Jj(ge,te,{edgeLabelFontSize:P.edgeMode==="nodes"||P.edgeMode==="workflow"?rx:yo,rankDir:P.direction,compact:Pe,nodeAlignment:P.nodeAlignment,rankSep:P.rankSep*L,edgeSep:P.edgeSep*L,nodeSep:5*L,spacingFactor:P.spacingFactor??1.3,compactSpacingScale:(P.compactSpacingScale??(P.spacingFactor??1.3)/1.3)*L})}catch(Pe){console.warn("[flow-sdk] layout failed",Pe);return}const Se=[...J.current].find(([Pe])=>_e.has(Pe)),je=Se?{id:Se[0],position:Se[1]}:ie.current?null:ve.current;ve.current=null;const Xe=je&&_e.get(je.id);if(je&&Xe){const Pe={x:je.position.x-Xe.x,y:je.position.y-Xe.y};_e=new Map([..._e].map(([ee,te])=>[ee,{x:te.x+Pe.x,y:te.y+Pe.y}]))}for(const[Pe,ee]of J.current)P.nodes.some(te=>te.id===Pe)?_e.set(Pe,ee):J.current.delete(Pe);if(ie.current){const Pe=JSON.stringify([ge,[..._e],T.size,P.isPerformanceMode,P.disableAnimations]);if(((Be=Ne.current)==null?void 0:Be.focus)===ie.current&&Ne.current.geometry===Pe)return;Ne.current={focus:ie.current,geometry:Pe}}else Ne.current=void 0;const qe=T.coordinate(()=>{var Pe;return(Pe=ie.current)==null?void 0:Pe.call(ie,_e)});O(_e,Re.current&&!P.isPerformanceMode&&!P.disableAnimations,qe)},be=j.useCallback(()=>{clearTimeout(We.current),clearTimeout(Ye.current),Ye.current=setTimeout(ae,k.current.layoutDebounce)},[]);j.useLayoutEffect(()=>{const P=e.fixedNodePositions??{};let L=!1;for(const B of fe.current)Object.prototype.hasOwnProperty.call(P,B)||(L=J.current.delete(B)||L);for(const[B,Z]of Object.entries(P)){if(!r.some(_e=>_e.id===B)||!Z||![Z.x,Z.y].every(Number.isFinite))continue;const ge=J.current.get(B);((ge==null?void 0:ge.x)!==Z.x||(ge==null?void 0:ge.y)!==Z.y)&&(J.current.set(B,{...Z}),L=!0)}fe.current=new Set(Object.keys(P)),L&&be()},[e.fixedNodePositions,r,be]),j.useLayoutEffect(()=>{const P=new Map(De.current.map(L=>[L.id,L]));r.some(L=>{var B;return((B=P.get(L.id))==null?void 0:B.collapsed)===!0&&!L.collapsed})&&(Zt.current=r.filter(L=>!P.has(L.id)).map(L=>L.id)),De.current=r,Qe.current!==l&&ne.current.size>0&&(Re.current=!0,Ae.current=!1,clearTimeout(We.current)),Qe.current=l,Le.current!==Ee&&(Ae.current=!oe.current),Le.current=Ee,be()},[r,t,I.nodes,I.edges,Ee,n,o,a,c,be,l,d,v,e.nodeGridSpacing]),j.useEffect(()=>()=>{clearTimeout(Ye.current),clearTimeout(We.current),hr()},[]);const ke=j.useCallback((P,L)=>{var B,Z;if(!ce.current&&typeof ResizeObserver<"u"&&(ce.current=new ResizeObserver(ge=>{let _e=!1;for(const Se of ge){const je=K.current.get(Se.target);if(!je||he.current.has(je))continue;const Xe=Se.target,qe=Xe.offsetWidth,Be=Xe.offsetHeight;if(!qe&&!Be)continue;const Pe=Q.current.get(je);if(Pe&&Pe.w===qe&&Pe.h===Be)continue;const ee=ne.current.get(je);Pe&&ee&&Re.current&&!ve.current&&(ve.current={id:je,position:{...ee}}),Q.current.set(je,{w:qe,h:Be}),_e=!0}_e&&be()})),L){ue.current.set(P,L),K.current.set(L,P),(B=ce.current)==null||B.observe(L);const ge=L.offsetWidth,_e=L.offsetHeight;!he.current.has(P)&&(ge||_e)&&Q.current.set(P,{w:ge,h:_e})}else{const ge=ue.current.get(P);ge&&((Z=ce.current)==null||Z.unobserve(ge),K.current.delete(ge)),ue.current.delete(P),Q.current.delete(P),se.current.has(P)&&U(P,[])}be()},[be,U]);j.useEffect(()=>()=>{var P;return(P=ce.current)==null?void 0:P.disconnect()},[]);const Me=P=>{var Z;const L=(Z=k.current.nodes.find(ge=>ge.id===P))==null?void 0:Z.label;if(!L)return;const B=k.current.containerStyle(P);return{w:Ro(L,`bold ${B.fontSize}px ${Pr}`)+2*cE,h:0}},Te=j.useMemo(()=>{const P=new Map;for(const L of r)L.label&&P.set(L.id,L.label);return P},[r]),rt=j.useMemo(()=>Md(I.nodes,Y,new Map([...Q.current,...de]),P=>m(P).padding,Me,de),[I.nodes,Y,m,Te,de]),et=j.useRef(rt);et.current=rt;const Fe=j.useCallback(P=>{const L=et.current.get(P);if(L)return u1(L);const B=ne.current.get(P);if(!B)return;const Z=he.current.get(P)||Q.current.get(P)||ao;return{x:B.x,y:B.y,w:Z.w,h:Z.h}},[]),it=j.useMemo(()=>{const P=new Map;for(const L of r){const B=Fe(L.id);B&&P.set(L.id,B)}return v1(F,P,V,t,n)},[F,r,Y,rt,V,t,n,Fe]);se.current=it;const yt=(P,L)=>{var ge;if(!R||L===void 0)return;const B=(ge=it.get(P))==null?void 0:ge.find(_e=>_e.property===L),Z=Fe(P);return B&&!B.anchor&&Z?Z.y-Z.h/2+B.top+B.height/2:void 0},Ct=(P,L)=>{var ge,_e;if(L===void 0)return;const B=(_e=(ge=it.get(P))==null?void 0:ge.find(Se=>Se.property===L))==null?void 0:_e.anchor,Z=Fe(P);return B&&Z?{x:Z.x-Z.w/2+B.x,y:Z.y-Z.h/2+B.y,side:B.side}:void 0},jt=(P,L)=>{const B=Fe(P),Z=V.get(P);return B&&Z&&!rt.has(P)&&yt(P,L)===void 0?qn(B,(n==="TB"||n==="BT")&&Z.captionBottom!==void 0?{...Z,height:Math.max(Z.height,Z.captionBottom-Z.top),outline:void 0}:Z):B},Mt=()=>{const P=[];ne.current.forEach((L,B)=>{if(et.current.has(B))return;const Z=Fe(B);Z&&P.push(sr(Z))}),et.current.forEach(L=>P.push(L));try{for(const L of[$.current,N.current]){const B=L==null?void 0:L.getBBox();B&&B.width>0&&B.height>0&&P.push({x1:B.x,y1:B.y,x2:B.x+B.width,y2:B.y+B.height})}}catch{}return ri(P)},Tt=()=>{var B,Z;const{pan:P,zoom:L}=T;W.current&&(W.current.style.transform=`translate3d(${P.x}px, ${P.y}px, 0) scale(${L})`),(B=$.current)==null||B.setAttribute("transform",`translate(${P.x} ${P.y}) scale(${L})`),(Z=N.current)==null||Z.setAttribute("transform",`translate(${P.x} ${P.y}) scale(${L})`)};j.useEffect(()=>{Tt();let P=null,L;const B=T.onChange(()=>{Tt();const Z=_.current;Z&&(Z.classList.add("flow-sdk-busy"),clearTimeout(L),L=setTimeout(()=>Z.classList.remove("flow-sdk-busy"),150)),P===null&&(P=requestAnimationFrame(()=>{var ge,_e;P=null,(_e=(ge=k.current).onViewportChange)==null||_e.call(ge,T.state)}))});return()=>{B(),clearTimeout(L),P!==null&&cancelAnimationFrame(P)}},[]),j.useLayoutEffect(()=>{const P=_.current;if(!P)return;const L=()=>{var Se;if(!P.getClientRects().length)return;let Z=P.clientWidth,ge=P.clientHeight;ge||(ge=Math.max(0,window.innerHeight-P.getBoundingClientRect().top-100),ge&&(P.style.height=`${ge}px`)),Z||(Z=window.innerWidth,Z&&(P.style.width=`${Z}px`));const _e=T.size.w!==Z||T.size.h!==ge;T.size={w:Z,h:ge},_e&&((Se=tt.current)!=null&&Se.options.fill)&&(!Re.current&&Z>0&&ge>0?ae():be()),!Re.current&&!ne.current.size&&k.current.fitOnInit!==!1&&(T.set({x:Z/2,y:ge/2}),Tt())};if(L(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(L);return B.observe(P),()=>B.disconnect()},[T]),j.useLayoutEffect(()=>{if(Dt.current){Dt.current=!1;const L=Zt.current.flatMap(Z=>{const ge=Fe(Z);return ge?[sr(ge)]:[]});Zt.current=[];const B=ri(L);if(B){Ae.current=!1,T.center(B,k.current.animateViewport);return}}if(!Ae.current)return;Ae.current=!1;const P=Mt();P&&(T.fit(P,50,Re.current&&k.current.animateViewport),Re.current||Tt())},[Y]);const mt=j.useMemo(()=>{const P=ee=>{const te=k.current;if(te.nodeGridSpacing!=="layout")return ee;const ye=te.direction==="LR"||te.direction==="RL";return{...ee,gaps:{x:ye?te.rankSep:te.edgeSep,y:ye?te.edgeSep:te.rankSep}}},L=()=>{const ee=k.current,te=M.current.nodes.filter(ye=>cr(ye.id,ee.edges,ee.edgeMode)&&(!gt.current||gt.current.has(ye.id)));return{nodes:te,positions:ne.current,sizes:new Map(te.map(ye=>[ye.id,Q.current.get(ye.id)??ao])),padding:ye=>k.current.containerStyle(ye).padding,minSize:Me,fixedIds:new Set(J.current.keys()),viewportSize:{...T.size}}},B=ee=>Xu(ee,k.current.nodes,k.current.edges),Z=(ee,te=!0,ye=()=>{},pe,ze,we=!1)=>{clearTimeout(Ye.current),clearTimeout(We.current),we||(ie.current=null),oe.current=null,Ae.current=!1,Zt.current=[],Dt.current=!1;const Ce=te&&!k.current.isPerformanceMode&&!k.current.disableAnimations,Ke=T.coordinate(()=>{var nt;pe?pe(Ce):we&&((nt=ie.current)==null||nt.call(ie,ee))});O(new Map([...ee].map(([nt,dt])=>[nt,{...dt}])),Ce,Ke,ye,ze)},ge=(ee,te=50,ye=k.current.animateViewport,pe=1,ze=!1,we)=>{const Ce=Ke=>{const nt=M.current,dt=ee??new Set(nt.nodes.map(vt=>vt.id)),or=new Set(nt.nodes.map(vt=>vt.parent).filter(Boolean));if(!Ke&&(!ee||[...ee].some(vt=>or.has(vt))))return;const gr=Ke&&Md(nt.nodes,Ke,Q.current,vt=>k.current.containerStyle(vt).padding,Me),vn=new Map([...dt].flatMap(vt=>{const ar=gr==null?void 0:gr.get(vt);if(ar)return[[vt,ar]];const Xt=Ke==null?void 0:Ke.get(vt),Cr=Q.current.get(vt)||ao,Au=Xt?{...Xt,...Cr}:Fe(vt);return Au?[[vt,sr(Au)]]:[]}));let ir=ri([...vn.values()]);if(!ir)return;const wr=we?vn.get(we):void 0;if(wr){const vt=(wr.x1+wr.x2)/2,ar=(wr.y1+wr.y2)/2,Xt=Math.max(vt-ir.x1,ir.x2-vt),Cr=Math.max(ar-ir.y1,ir.y2-ar);ir={x1:vt-Xt,x2:vt+Xt,y1:ar-Cr,y2:ar+Cr}}Ae.current=!1,Zt.current=[],Dt.current=!1,T.fit(ir,Number.isFinite(te)?Math.max(0,te):50,ye,pe)};ie.current=ze?Ce:null,ze||Ce(ne.current)},_e=(ee,te,ye,pe)=>{var we;if(!Fe(ee))return;const ze=te==="connections"?je(ee):B(ee);if(te==="connections"&&Bt.current===1.25&&((we=gt.current)==null?void 0:we.size)===ze.size&&[...ze].every(Ce=>gt.current.has(Ce))){S({id:ee,mode:te});return}if(fr.current||(fr.current={pan:{...T.pan},zoom:T.zoom}),gt.current=ze,k.current.compactPropertyLayout){Ae.current=!1,ge(gt.current??ze,ye,pe,1,!0);const Ce=ie.current;Ce&&(ie.current=Ke=>{ie.current=null,Ne.current=void 0,Ce(Ke)})}S({id:ee,mode:te}),k.current.compactPropertyLayout||ge(ze,ye,pe)},Se=ee=>{oe.current?oe.current=ee:ee()},je=ee=>nf(ee,k.current.nodes,k.current.edges),Xe=(ee=>{var te,ye,pe;if(ee===void 0)return T.zoom;ee<T.zoom&&((te=tt.current)!=null&&te.options.fill)&&!k.current.readOnly&&((pe=(ye=k.current).onNodeGridZoomOut)==null?void 0:pe.call(ye,tt.current.options))===!0||(ie.current=null,T.set(void 0,ee))}),qe=((ee,te=!1)=>{if(ee===void 0)return T.pan;ie.current=null,te?T.transition({pan:ee,zoom:T.zoom},!0):T.set(ee)}),Be=(ee,te)=>{var pe;const ye=(pe=_.current)==null?void 0:pe.getBoundingClientRect();return{x:ee-((ye==null?void 0:ye.left)??0),y:te-((ye==null?void 0:ye.top)??0)}},Pe=(ee=0,te=k.current.animateViewport,ye=!1)=>{if(ye){ge(void 0,ee,te,1,!0);return}ie.current=null,Se(()=>{const pe=Mt();pe&&T.fit(pe,ee,te)})};return{zoom:Xe,pan:qe,setEdgesVisible:Ue,focusNode:(ee,te,ye,pe)=>Se(()=>ge(new Set([ee]),te,ye,.6,pe)),focusBranch:(ee,te,ye,pe,ze=!1,we=1)=>Se(()=>ge(B(ee),te,ye,we,pe,ze?ee:void 0)),focusConnections:(ee,te,ye,pe)=>Se(()=>ge(je(ee),te,ye,1,pe)),isolateConnections:(ee,te,ye)=>_e(ee,"connections",te,ye),isolateBranch:(ee,te,ye)=>_e(ee,"branch",te,ye),restoreView:(ee=k.current.animateViewport,te,ye=!1)=>{ie.current=null;const pe=ye&&!tt.current&&!gt.current,ze=k.current.compactPropertyLayout&&!!gt.current;gt.current=null,S(null);const we=te??fr.current;fr.current=null,we&&pe?(Ae.current=!1,oe.current=null,ve.current=null,ie.current=()=>T.transition(we,ee),be()):ze?oe.current=()=>{we&&T.transition(we,ee)}:we&&Se(()=>T.transition(we,ee))},zoomAt:(ee,te)=>{var ye,pe,ze;ee<T.zoom&&((ye=tt.current)!=null&&ye.options.fill)&&!k.current.readOnly&&((ze=(pe=k.current).onNodeGridZoomOut)==null?void 0:ze.call(pe,tt.current.options))===!0||(ie.current=null,T.zoomAt(ee,te))},fit:Pe,centerAndFit:Pe,center:(ee=k.current.animateViewport)=>{ie.current=null;const te=Mt();te&&T.center(te,ee)},clientToModel:(ee,te)=>T.renderedToModel(Be(ee,te)),modelToClient:ee=>{var pe;const te=(pe=_.current)==null?void 0:pe.getBoundingClientRect(),ye=T.modelToRendered(ee);return{x:ye.x+((te==null?void 0:te.left)??0),y:ye.y+((te==null?void 0:te.top)??0)}},getNodeBox:ee=>Fe(ee),detectNodeCollisions:ee=>{const te=L();return cv({...te,sizes:new Map([...te.sizes,...he.current]),fixedSizes:he.current},ee)},resolveNodeCollisions:(ee={})=>{const te=Yj(L(),ee);return te.movedNodeIds.length&&Z(te.positions,ee.animate),te},arrangeNodesInGrid:(ee={})=>{const te=L(),ye=tt.current;if(ye){te.positions=new Map(te.positions);for(const dt of te.nodes)te.positions.has(dt.id)||te.positions.set(dt.id,T.renderedToModel({x:T.size.w/2,y:T.size.h/2}));const Ce=new Set(te.nodes.map(dt=>dt.id));ye.order=ye.order.filter(dt=>Ce.has(dt));const Ke=new Set(ye.order);ye.order.push(...te.nodes.filter(dt=>!Ke.has(dt.id)).map(dt=>dt.id));const nt=new Map(ye.order.map((dt,or)=>[dt,or]));te.nodes=[...te.nodes].sort((dt,or)=>nt.get(dt.id)-nt.get(or.id))}const pe=vd(te,P(ee)),ze=pe.sizes?JSON.stringify([[...pe.positions],[...pe.sizes]]):void 0;if(ze&&ze===me.current&&ee.animate!==!1&&!ie.current)return pe;zt(pe.dividers??[]),ye&&(ye.ready=!1);const we=()=>{ye&&(ye.ready=!0),ye&&te.nodes.length&&!Re.current&&(Re.current=!0,k.current.fitOnInit!==!1&&!ee.fill?mt.centerAndFit(50,!1):k.current.fitOnInit===!1&&T.transition(p,!1)),st(Ce=>Ce+1)};return!pe.sizes&&he.current.size&&H(),te.nodes.some(Ce=>!ne.current.has(Ce.id))||pe.movedNodeIds.length||pe.bounds||ie.current?Z(pe.positions,ee.animate,we,pe.bounds&&(!ye||!he.current.size)?Ce=>T.transition({zoom:1,pan:{x:0,y:0}},Ce):void 0,pe.sizes,!!ye&&!pe.bounds):we(),me.current=ze,pe},setNodeGridMode:(ee,te={})=>{var ye,pe,ze,we;if(te.order&&(!Array.isArray(te.order)||te.order.some(Ce=>typeof Ce!="string")||new Set(te.order).size!==te.order.length))throw new Error("Invalid grid node order.");if(ee){vd(L(),P(te));const Ce=!tt.current||tt.current.options.fill&&!te.fill;ie.current=null,tt.current||(tt.current={options:te,order:L().nodes.map(Ke=>Ke.id),previousPositions:new Map([...ne.current].map(([Ke,nt])=>[Ke,{...nt}])),previousViewport:{zoom:T.zoom,pan:{...T.pan}},previousSize:{...T.size},ready:!1}),Ce&&mt.centerAndFit(80,te.animate,!0),te.order&&(tt.current.order=[...te.order]),tt.current.options={...te},pt(!0),mt.arrangeNodesInGrid(te),(pe=(ye=k.current).onNodeGridModeChange)==null||pe.call(ye,{...te,order:[...tt.current.order]})}else{const Ce=tt.current;if(!Ce)return;if(T.size.w===Ce.previousSize.w&&T.size.h===Ce.previousSize.h&&ne.current.size===Ce.previousPositions.size&&[...ne.current.keys()].every(dt=>Ce.previousPositions.has(dt))?ie.current=()=>T.transition(Ce.previousViewport,te.animate!==!1&&!k.current.disableAnimations&&!k.current.isPerformanceMode):mt.centerAndFit(80,te.animate,!0),tt.current=null,pt(!1),H(),(we=(ze=k.current).onNodeGridModeChange)==null||we.call(ze,null),nr(null),!Ce.previousPositions.size){be();return}const nt=new Map([...ne.current].map(([dt,or])=>[dt,Ce.previousPositions.get(dt)??or]));Z(nt,te.animate,void 0,void 0,void 0,!0)}},swapGridNodes:(ee,te,ye)=>{var vn,ir,wr,vt,ar;const pe=tt.current;if(!pe||!pe.ready||k.current.readOnly||ee===te)return!1;const ze=L(),we=ze.nodes.find(Xt=>Xt.id===ee),Ce=ze.nodes.find(Xt=>Xt.id===te);if(!we||!Ce||we.parent!==Ce.parent)return!1;const Ke=vd(ze,P(pe.options));if(Ke.skippedNodeIds.includes(ee)||Ke.skippedNodeIds.includes(te))return!1;const nt=pe.order.indexOf(ee),dt=pe.order.indexOf(te);if(nt<0||dt<0)return!1;[pe.order[nt],pe.order[dt]]=[pe.order[dt],pe.order[nt]],ie.current=null,pe.options={...pe.options,order:[...pe.order]};const or=we.parent??"canvas",gr=(ir=(vn=pe.options.adjustment)==null?void 0:vn.sections)==null?void 0:ir[or];return gr!=null&&gr.members&&(pe.options={...pe.options,adjustment:{...pe.options.adjustment,sections:{...(wr=pe.options.adjustment)==null?void 0:wr.sections,[or]:{...gr,members:gr.members.map(Xt=>Xt.map(Cr=>Cr===ee?te:Cr===te?ee:Cr))}}}}),mt.arrangeNodesInGrid({...pe.options,animate:ye??pe.options.animate}),(ar=(vt=k.current).onNodeGridModeChange)==null||ar.call(vt,{...pe.options}),!0},setNodePosition:(ee,te,ye)=>{var ze,we,Ce,Ke;if(!ne.current.has(ee)||te&&(!Number.isFinite(te.x)||!Number.isFinite(te.y)))return!1;if(hr(),!te)return J.current.delete(ee),(we=(ze=k.current).onFixedNodePositionsChange)==null||we.call(ze,Object.fromEntries(J.current)),be(),!0;const pe=new Map(ne.current);return pe.set(ee,{...te}),(ye==null?void 0:ye.persist)===!1?J.current.delete(ee):J.current.set(ee,{...te}),ne.current=pe,le(pe),(ye==null?void 0:ye.persist)!==!1&&((Ke=(Ce=k.current).onFixedNodePositionsChange)==null||Ke.call(Ce,Object.fromEntries(J.current))),(ye==null?void 0:ye.persist)===!1&&be(),!0},getFixedNodePositions:()=>Object.fromEntries([...J.current].map(([ee,te])=>[ee,{...te}])),onViewportChange:ee=>T.onChange(ee)}},[]);j.useEffect(()=>{var P,L;return(L=(P=k.current).onInit)==null||L.call(P,mt),()=>T.cancelAnimation()},[mt]),j.useEffect(()=>{var P,L;if(Je>0){const B=oe.current;oe.current=null,B==null||B(),(L=(P=k.current).onLayoutComplete)==null||L.call(P,mt)}},[mt,Je]);const ft=j.useRef(null),bt=j.useRef(new Map),qt=j.useRef(!1),[It,Wt]=j.useState(null),[at,vr]=j.useState(null),Nr=P=>{const L=_.current.getBoundingClientRect();return{x:(P.clientX-L.left)*(_.current.clientWidth/L.width||1),y:(P.clientY-L.top)*(_.current.clientHeight/L.height||1)}},pr=(P,L)=>{const B=k.current.nodes;for(let Z=B.length-1;Z>=0;Z--){const ge=B[Z].id;if(!cr(ge,k.current.edges,k.current.edgeMode)||gt.current&&!gt.current.has(ge)||ge===L||et.current.has(ge))continue;const _e=Fe(ge);if(_e&&Yu(P,sr(_e)))return ge}for(const[Z,ge]of et.current)if(cr(Z,k.current.edges,k.current.edgeMode)&&!(gt.current&&!gt.current.has(Z))&&Z!==L&&Yu(P,ge))return Z;return null},mn=(P,L)=>{const B=k.current.nodes.find(je=>je.id===P),Z=Fe(P);if(!B||!Z)return null;const ge=sr({...Z,x:Z.x+L.x,y:Z.y+L.y});let _e=null,Se=0;for(const je of k.current.nodes){if(je.id===P||je.parent!==B.parent||J.current.has(je.id)||et.current.has(je.id)||!cr(je.id,k.current.edges,k.current.edgeMode)||gt.current&&!gt.current.has(je.id))continue;const Xe=Fe(je.id);if(!Xe)continue;const qe=sr(Xe),Be=Math.max(0,Math.min(ge.x2,qe.x2)-Math.max(ge.x1,qe.x1))*Math.max(0,Math.min(ge.y2,qe.y2)-Math.max(ge.y1,qe.y1));Be>Se&&(Se=Be,_e=je.id)}return _e},bn=(P,L)=>{const B=tt.current;if(!(B!=null&&B.ready)||k.current.readOnly)return;const Z=k.current.nodes.filter(Be=>cr(Be.id,k.current.edges,k.current.edgeMode)&&(!gt.current||gt.current.has(Be.id))),ge=Z.find(Be=>Be.id===P);if(!ge)return;const _e=_.current,Se=T.zoom*(_e&&_e.clientWidth?_e.getBoundingClientRect().width/_e.clientWidth:1),je=24/Se;let Xe;for(const Be of Z){if(Be.id===P||Be.parent!==ge.parent)continue;const Pe=Fe(Be.id);if(!Pe)continue;const ee=sr(Pe),te=Math.min(Pe.w/4,je),ye=Math.min(Pe.h/4,je),pe=3/Se,ze=[];if(L.y>ee.y1+ye&&L.y<ee.y2-ye)for(const we of["before","after"]){const Ce=we==="before"?ee.x1:ee.x2,Ke=Math.abs(L.x-Ce),nt=we==="before"?L.x<Ce:L.x>Ce;Ke<=(nt?je:te)&&ze.push({side:we,distance:Ke,marker:{x1:Ce-pe/2,x2:Ce+pe/2,y1:ee.y1,y2:ee.y2}})}if(L.x>=ee.x1&&L.x<=ee.x2)for(const we of["above","below"]){const Ce=we==="above"?ee.y1:ee.y2,Ke=Math.abs(L.y-Ce),nt=we==="above"?L.y<Ce:L.y>Ce;Ke<=(nt?je:ye)&&ze.push({side:we,distance:Ke,marker:{x1:ee.x1,x2:ee.x2,y1:Ce-pe/2,y2:Ce+pe/2}})}for(const we of ze)(!Xe||we.distance<Xe.distance)&&(Xe={id:Be.id,...we})}if(!Xe)return;const qe=Zj({nodes:Z,positions:ne.current,sizes:new Map([...Q.current,...he.current]),fixedSizes:he.current,padding:Be=>k.current.containerStyle(Be).padding,minSize:Me,fixedIds:new Set(J.current.keys())},B.options,P,Xe.id,Xe.side);return qe?{options:qe,marker:Xe.marker}:void 0},Zr=(P,L)=>{if(k.current.edgeMode==="nodes"||k.current.edgeMode==="workflow")return null;const B=k.current.direction==="RL",Z=Math.max(16,6/T.zoom);let ge=null;for(const _e of[...k.current.nodes].reverse()){if(!cr(_e.id,k.current.edges,k.current.edgeMode)||gt.current&&!gt.current.has(_e.id))continue;const Se=Fe(_e.id),je=se.current.get(_e.id);if(!Se||!je||et.current.has(_e.id))continue;const Xe=Se.x+(L==="source"!==B?1:-1)*Se.w/2;for(const qe of je){if(qe.role&&qe.role!==L)continue;const Be=Se.y-Se.h/2+qe.top,Pe=Math.hypot(P.x-(qe.anchor?Se.x-Se.w/2+qe.anchor.x:Xe),P.y-Be-qe.height/2);if(!qe.anchor&&P.x>=Se.x-Se.w/2&&P.x<=Se.x+Se.w/2&&P.y>=Be&&P.y<=Be+qe.height)return{nodeId:_e.id,property:qe.property};Pe<=Z&&(!ge||Pe<ge.distance)&&(ge={nodeId:_e.id,property:qe.property,distance:Pe})}}return ge},xv=P=>{var je,Xe;if(!P.currentTarget.contains(P.target)||(ft.current||(qt.current=!1),P.target.closest(".flow-sdk-canvas")!==P.currentTarget)||P.button!==0)return;const L=P.target;if(L.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const B=k.current,Z=Nr(P);if(P.pointerType==="touch"){bt.current.set(P.pointerId,Z);const qe=Mm(bt.current);if(qe){nr(null),ft.current={kind:"pinch",distance:qe.distance,zoom:T.zoom,anchor:T.renderedToModel(qe.center)},vr(null),Wt(null),qt.current=!0;for(const Be of bt.current.keys())P.currentTarget.setPointerCapture(Be);return}}if(ft.current)return;if(k.current.readOnly){B.dragMode&&(ft.current={kind:"pan",pointerId:P.pointerId,start:Z,pan0:T.pan,moved:!1},P.currentTarget.setPointerCapture(P.pointerId));return}const ge=!tt.current||!!B.nodeGridConnections,_e=B.drawHandles&&L.closest(".flow-sdk-handle"),Se=B.drawHandles&&L.closest(".flow-sdk-property-port");if((!ge||!_e&&!Se&&(!B.drawMode||P.shiftKey))&&(tt.current||P.shiftKey&&(B.onNodeGridDrop||B.onNodeParentChange))){if(tt.current&&!tt.current.ready||L.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]"))return;const qe=(je=L.closest("[data-node-id]"))==null?void 0:je.dataset.nodeId;if(qe&&!J.current.has(qe)){L.setPointerCapture(P.pointerId),ft.current={kind:"grid",pointerId:P.pointerId,captureTarget:L,source:qe,start:Z,moved:!1};return}if(qe)return}if(ge&&(B.drawMode||_e||Se)){const qe=T.renderedToModel(Z),Be=B.drawMode?Zr(qe,"source"):null,Pe=Se||_e,ee=Pe?(Xe=Pe.closest("[data-node-id]"))==null?void 0:Xe.dataset.nodeId:(Be==null?void 0:Be.nodeId)??pr(qe),te=Se?Se.dataset.property:Be==null?void 0:Be.property;if(ee){ft.current={kind:"draw",pointerId:P.pointerId,source:ee,sourceProperty:te,reverse:(Se==null?void 0:Se.dataset.portRole)==="target",startClient:{x:P.clientX,y:P.clientY}},qt.current=!0,vr({source:ee,sourceProperty:te,point:qe,target:null}),P.currentTarget.setPointerCapture(P.pointerId);return}}L.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(ie.current=null,B.multiSelect?ft.current={kind:"box",pointerId:P.pointerId,start:Z,current:Z}:B.dragMode?ft.current={kind:"pan",pointerId:P.pointerId,start:Z,pan0:T.pan,moved:!1}:ft.current={kind:"tap",pointerId:P.pointerId,start:Z,moved:!1},P.currentTarget.setPointerCapture(P.pointerId))},vv=P=>{var Z,ge,_e;const L=ft.current;if(!L)return;const B=Nr(P);if(bt.current.has(P.pointerId)&&bt.current.set(P.pointerId,B),L.kind==="pinch"){const Se=Mm(bt.current);if(!Se)return;const je=Math.max(T.minZoom,Math.min(T.maxZoom,L.zoom*Se.distance/L.distance));if(je<T.zoom&&((Z=tt.current)!=null&&Z.options.fill)&&((_e=(ge=k.current).onNodeGridZoomOut)==null?void 0:_e.call(ge,tt.current.options))===!0)return;T.set({x:Se.center.x-L.anchor.x*je,y:Se.center.y-L.anchor.y*je},je);return}if(L.pointerId===P.pointerId)switch(L.kind){case"grid":{const Se={x:B.x-L.start.x,y:B.y-L.start.y};if(!L.moved&&Math.hypot(Se.x,Se.y)<=Cd)return;L.moved||(hr(),ie.current=null,T.cancelAnimation()),L.moved=!0,qt.current=!0,P.preventDefault();const je={x:Se.x/T.zoom,y:Se.y/T.zoom},Xe=!P.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;nr({source:L.source,offset:je,target:P.shiftKey||Xe?null:mn(L.source,je),shiftKey:P.shiftKey,insertion:Xe});break}case"pan":{const Se=B.x-L.start.x,je=B.y-L.start.y;if(!L.moved&&Math.hypot(Se,je)<=Cd)return;L.moved=!0,qt.current=!0,T.set({x:L.pan0.x+Se,y:L.pan0.y+je});break}case"tap":{Math.hypot(B.x-L.start.x,B.y-L.start.y)>Cd&&(L.moved=!0);break}case"box":{qt.current=!0,L.current=B,Wt({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 Se=T.renderedToModel(B),je=Zr(Se,L.reverse?"source":"target");vr(L.reverse&&je?{source:je.nodeId,sourceProperty:je.property,point:Se,target:L.source,targetProperty:L.sourceProperty}:{source:L.source,sourceProperty:L.sourceProperty,point:Se,target:(je==null?void 0:je.nodeId)??pr(Se,L.source),targetProperty:je==null?void 0:je.property});break}}},wu=(P,L)=>{var ge,_e,Se,je,Xe,qe,Be,Pe,ee,te,ye;bt.current.delete(P.pointerId);const B=ft.current;if(!B)return;if(B.kind==="pinch"){const pe=[...bt.current][0];ft.current=pe&&k.current.dragMode&&!L?{kind:"pan",pointerId:pe[0],start:pe[1],pan0:T.pan,moved:!0}:null;return}if(B.pointerId!==P.pointerId)return;ft.current=null;try{(B.kind==="grid"?B.captureTarget:P.currentTarget).releasePointerCapture(P.pointerId)}catch{}const Z=k.current;switch(L=L||!!Z.readOnly,B.kind){case"grid":{if(nr(null),L||!B.moved)break;const pe=Nr(P);if(!P.shiftKey&&pe.x>=0&&pe.y>=0&&pe.x<=T.size.w&&pe.y<=T.size.h){const we=bn(B.source,T.renderedToModel(pe));if(we){mt.setNodeGridMode(!0,{...we.options,animate:!1});break}}if(((ge=Z.onNodeGridDrop)==null?void 0:ge.call(Z,B.source,{x:P.clientX,y:P.clientY},{shiftKey:P.shiftKey,ctrlKey:P.ctrlKey,metaKey:P.metaKey,altKey:P.altKey}))===!0||pe.x<0||pe.y<0||pe.x>T.size.w||pe.y>T.size.h)break;if(P.shiftKey){const we=new Map(Z.nodes.map(nt=>[nt.id,nt]));let Ce=pr(T.renderedToModel(pe),B.source);const Ke=new Set;for(;Ce&&!((_e=we.get(Ce))!=null&&_e.acceptsChildren)&&!Ke.has(Ce);)Ke.add(Ce),Ce=((Se=we.get(Ce))==null?void 0:Se.parent)??null;if(Ce&&((je=we.get(Ce))!=null&&je.acceptsChildren)){let nt=Ce;const dt=new Set;for(;nt&&!dt.has(nt);)dt.add(nt),nt=(Xe=we.get(nt))==null?void 0:Xe.parent;dt.has(B.source)||(qe=Z.onNodeParentChange)==null||qe.call(Z,B.source,Ce)}break}if(!tt.current)break;const ze=mn(B.source,{x:(pe.x-B.start.x)/T.zoom,y:(pe.y-B.start.y)/T.zoom});ze&&mt.swapGridNodes(B.source,ze,!1);break}case"pan":case"tap":!L&&!B.moved&&((Be=Z.onBackgroundTap)==null||Be.call(Z));break;case"box":{if(Wt(null),L)break;const pe=T.renderedToModel(B.start),ze=T.renderedToModel(B.current),we={x1:Math.min(pe.x,ze.x),y1:Math.min(pe.y,ze.y),x2:Math.max(pe.x,ze.x),y2:Math.max(pe.y,ze.y)};if(we.x2-we.x1<1&&we.y2-we.y1<1){(Pe=Z.onBackgroundTap)==null||Pe.call(Z);break}const Ce=[];for(const Ke of Z.nodes){const nt=Fe(Ke.id);nt&&f1(sr(nt),we)&&Ce.push(Ke.id)}Ce.length&&((ee=Z.onBoxSelect)==null||ee.call(Z,Ce));break}case"draw":{if(vr(null),L)break;const pe=Nr(P),ze=T.renderedToModel(pe),we=Zr(ze,B.reverse?"source":"target"),Ce=(we==null?void 0:we.nodeId)??pr(ze);if(Ce===B.source&&(B.sourceProperty===void 0||(we==null?void 0:we.property)===void 0||we.property===B.sourceProperty))break;Ce?(te=Z.onEdgeDraw)==null||te.call(Z,B.reverse?Ce:B.source,B.reverse?B.source:Ce,B.sourceProperty!==void 0||(we==null?void 0:we.property)!==void 0?{sourceProperty:B.reverse?we==null?void 0:we.property:B.sourceProperty,targetProperty:B.reverse?B.sourceProperty:we==null?void 0:we.property}:void 0):Math.max(Math.abs(P.clientX-B.startClient.x),Math.abs(P.clientY-B.startClient.y))>aE&&((ye=Z.onDrawIntoSpace)==null||ye.call(Z,B.source,ze,B.sourceProperty,B.reverse));break}}},Or=j.useCallback(()=>{var B;const P=ft.current,L=[...bt.current.keys()];P&&P.kind!=="pinch"&&L.push(P.pointerId),ft.current=null,bt.current.clear(),nr(null),vr(null),Wt(null);for(const Z of L)(P==null?void 0:P.kind)==="grid"&&P.captureTarget.hasPointerCapture(Z)&&P.captureTarget.releasePointerCapture(Z),(B=_.current)!=null&&B.hasPointerCapture(Z)&&_.current.releasePointerCapture(Z)},[]);j.useEffect(()=>{const P=L=>{L.key==="Escape"&&Or()};return window.addEventListener("keydown",P),window.addEventListener("blur",Or),()=>{window.removeEventListener("keydown",P),window.removeEventListener("blur",Or),ft.current=null,bt.current.clear()}},[Or]),j.useEffect(()=>{Or()},[y,b,x,i,n,e.drawHandles,e.readOnly,ht,Or]);const wv=j.useMemo(()=>{const P=new Map,L=new Map;for(const B of A){if(B.source!==B.target)continue;const Z=P.get(B.source)??0;P.set(B.source,Z+1),L.set(B.id,Z)}return L},[A]),Jo=iE[n],[$r,Cv]=j.useState(null),Zo=nE(r,A,!!((_u=e.edgeReveal)!=null&&_u.revealNodes));j.useLayoutEffect(()=>{_.current&&$r&&Rm(_.current,$r)}),j.useEffect(()=>{const P=_.current;if(!P||!$r)return;const L=P.ownerDocument.fonts,B=()=>Rm(P,$r);return L==null||L.addEventListener("loadingdone",B),()=>L==null?void 0:L.removeEventListener("loadingdone",B)},[$r]);const Xo=d1(A,jt,Jo),Sv=e.onEdgeSelect,jv=e.onContainerSelect,Cu=at?at.target&&jt(at.target,at.targetProperty)||{x:at.point.x,y:at.point.y,w:1,h:1}:null,Su=at?jt(at.source,at.sourceProperty):null,xn=!ht||!!e.nodeGridConnections,Ev=["flow-sdk-canvas",y&&xn?"flow-sdk-draw":"",w?"flow-sdk-perf":""].filter(Boolean).join(" ");return f.jsxs("div",{ref:_,className:Ev,"data-edge-mode":i,"data-node-grid":ht||void 0,"data-grid-connections":e.nodeGridConnections||void 0,onPointerDownCapture:xv,onPointerMove:vv,onPointerUp:P=>wu(P,!1),onPointerCancel:P=>wu(P,!0),onLostPointerCapture:P=>{const L=ft.current;L&&(L.kind==="pinch"||L.pointerId===P.pointerId)&&Or()},onClickCapture:P=>{if(!P.currentTarget.contains(P.target))return;const L=P.target instanceof Element&&P.target.closest("button[data-flow-fullscreen], button[data-flow-content-navigation]");(qt.current||e.readOnly&&!L)&&(P.preventDefault(),P.stopPropagation())},children:[f.jsx("svg",{className:"flow-sdk-svg",children:f.jsxs("g",{ref:$,children:[f.jsx("g",{className:"flow-sdk-containers",children:[...rt].filter(([P])=>cr(P,t,i)).filter(([P])=>!E||E.has(P)).map(([P,L])=>{var B,Z;return f.jsx(S1,{id:P,rect:L,label:Te.get(P),labelLayer:$r,labelContent:(B=r.find(ge=>ge.id===P&&ge.label!==void 0))==null?void 0:B.element,style:m(P),onSelect:jv,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(Z=e.selectedNodeIds)==null?void 0:Z.includes(P)},P)})}),f.jsx("g",{className:"flow-sdk-edges",children:ct&&xn&&A.map(P=>{var Z,ge,_e;if(!Zo.ready.has(P.id)||E&&(!E.has(P.source)||!E.has(P.target)))return null;const L=jt(P.source,P.sourceProperty),B=jt(P.target,P.targetProperty);return!L||!B?null:f.jsx(af,{id:P.id,edgeData:P.data,validationIssue:P.validationIssue,edgeType:P.type,edgeRadius:e.edgeRadius,propertyMode:R,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:Zo.complete,source:L,target:B,sourceProperty:P.sourceProperty,targetProperty:P.targetProperty,sourceY:yt(P.source,P.sourceProperty),targetY:yt(P.target,P.targetProperty),sourcePort:Ct(P.source,P.sourceProperty),targetPort:Ct(P.target,P.targetProperty),dir:Jo,turn:((Z=Xo.get(P.id))==null?void 0:Z.turn)??P.turn,labelAtTarget:(ge=Xo.get(P.id))==null?void 0:ge.labelAtTarget,labelFraction:(_e=Xo.get(P.id))==null?void 0:_e.labelFraction,color:P.color,connectorColor:P.connectorColor,labelBg:P.labelBg,label:P.label,labelLayer:$r,dashed:P.dashed,animated:P.animated&&!w,inverted:P.inverted,loopIndex:wv.get(P.id)??0,selected:P.id===e.selectedEdgeId,onSelect:Sv},P.id)})}),ct&&xn&&at&&Rd(at,i)&&Su&&Cu&&f.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:f.jsx(af,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:at.source,target:at.target??"",sourceProperty:at.sourceProperty,targetProperty:at.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:R,customEdgeTypes:e.customEdgeTypes,source:Su,target:Cu,sourceProperty:at.sourceProperty,targetProperty:at.targetProperty,sourceY:yt(at.source,at.sourceProperty),sourcePort:Ct(at.source,at.sourceProperty),targetPort:at.target?Ct(at.target,at.targetProperty):void 0,targetY:at.target?yt(at.target,at.targetProperty):void 0,dir:Jo,turn:.5,color:g,labelBg:g})})]})}),f.jsxs("div",{ref:W,className:"flow-sdk-nodes",children:[(Ve==null?void 0:Ve.insertion)&&f.jsx("div",{className:"flow-sdk-box","data-grid-insertion":"",style:{left:Ve.insertion.marker.x1,top:Ve.insertion.marker.y1,width:Ve.insertion.marker.x2-Ve.insertion.marker.x1,height:Ve.insertion.marker.y2-Ve.insertion.marker.y1,background:g,border:0}}),ht&&((ku=tt.current)==null?void 0:ku.options.fill)&&((Pu=tt.current.options.adjustment)==null?void 0:Pu.enabled)&&!e.readOnly&&f.jsx(Qj,{dividers:At,options:tt.current.options,zoom:T.zoom,onChange:P=>mt.setNodeGridMode(!0,{...P,animate:!1})}),r.map(P=>{var ze,we,Ce;if((ze=tt.current)!=null&&ze.options.fill&&!Re.current)return null;const L=Y.get(P.id),B=rt.get(P.id);if(B&&P.label!==void 0)return null;const Z=(L==null?void 0:L.x)??(B?(B.x1+B.x2)/2:0),ge=(L==null?void 0:L.y)??(B?(B.y1+B.y2)/2:0),_e=Ve!=null&&Ve.target?P.id===Ve.source?Ve.target:P.id===Ve.target?Ve.source:void 0:void 0,Se=_e?Y.get(_e):void 0,je=Ve?Y.get(Ve.source):void 0,Xe=Ve!=null&&Ve.target?Y.get(Ve.target):void 0,qe=je&&Xe?{x:Xe.x-je.x,y:Xe.y-je.y}:void 0,Be=qe?qe.x**2+qe.y**2:0,Pe=Be&&Ve&&qe?Math.max(0,Math.min(1,(Ve.offset.x*qe.x+Ve.offset.y*qe.y)/Be)):0,ee=Se?{x:Z+(Se.x-Z)*Pe,y:ge+(Se.y-ge)*Pe}:(Ve==null?void 0:Ve.source)===P.id?{x:Z+Ve.offset.x,y:ge+Ve.offset.y}:void 0,te=de.get(P.id),ye=_e?de.get(_e):void 0,pe=te&&ye?{w:te.w+(ye.w-te.w)*Pe,h:te.h+(ye.h-te.h)*Pe}:te;return f.jsx(rE,{id:P.id,x:Z,y:ge,gridDraggable:ht&&!e.readOnly&&!J.current.has(P.id),gridDragging:(Ve==null?void 0:Ve.source)===P.id,gridDropTarget:(Ve==null?void 0:Ve.target)===P.id,gridSize:de.get(P.id),gridPreview:ee?{...ee,size:pe,floating:Ve==null?void 0:Ve.shiftKey}:void 0,placed:!!L||!!B,hidden:!ht&&!Zo.shown.has(P.id)||!cr(P.id,t,i)||!!E&&!E.has(P.id),onMount:ke,drawHandles:e.drawHandles&&!e.readOnly&&xn,drawMode:y&&xn,connectedPorts:new Set(A.flatMap(Ke=>[...Ke.source===P.id&&Ke.sourceProperty!==void 0?[`source:${Ke.sourceProperty}`]:[],...Ke.target===P.id&&Ke.targetProperty!==void 0?[`target:${Ke.targetProperty}`]:[]])),hasCollapseControl:P.hasCollapseControl,handleColor:g,animated:P.animated&&!B&&!w&&!ht,animationColor:P.animationColor,animationWidth:P.animationWidth,animationVariant:P.animationVariant,width:(we=Q.current.get(P.id))==null?void 0:we.w,height:(Ce=Q.current.get(P.id))==null?void 0:Ce.h,propertyMode:R,resolvedRows:it.get(P.id),reversePorts:n==="RL",direction:n,onPropertyRows:U,onSurface:q,children:te?P.fillElement??P.element:P.element},P.id)})]}),It&&f.jsx("div",{className:"flow-sdk-box",style:{left:It.x1,top:It.y1,width:It.x2-It.x1,height:It.y2-It.y1}}),f.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:f.jsx("g",{ref:N,transform:`translate(${T.pan.x} ${T.pan.y}) scale(${T.zoom})`,children:f.jsx("g",{ref:Cv,className:"flow-sdk-labels",style:{pointerEvents:y?"none":"visiblePainted",outline:"none"}})})})]})}const dE=j.memo(lE);function mu(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}=Ge(),h=d.editable&&!u,[p,m]=j.useState(r),[g,y]=j.useState(),b=j.useRef(null),x=j.useRef(!1),w=mu(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(D.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(D.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),f.jsx(D.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 dv({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 Td=({icon:e,label:r,onClick:t,color:n,boxSize:o=6,...i})=>{const{background:s,border:a,colorText:c}=lt();return f.jsx(He,{label:r,children:f.jsx(D.Flex,{asChild:!0,p:0,border:0,bg:"transparent",children:f.jsx("button",{type:"button","aria-label":r,onClick:t,children:f.jsx(D.Icon,{as:e,boxSize:o,color:n,cursor:t?"pointer":void 0})})})})},uE=`${Jb}
|
|
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 bu({active:e=!0,label:r="Loading content",radius:t}){const{config:n,themeColor:o}=Ve(),{colorText:i}=st(),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:dE}),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 uE({nodeId:e}){var M,k;const{nodeById:r}=Qt(),{callbacks:t,config:n,readOnly:o,colorMode:i,isPerformanceMode:s}=Ve(),{background:a,border:c,colorInactive:l,colorText:d}=st(),u=[...r.values()].filter(({data:_})=>{var N,O,W,T,Y;return _.type!=="grid"&&!((N=_.config)!=null&&N.parentContainer)&&(((O=_.config)==null?void 0:O.contentFormat)==="html"||((W=_.config)==null?void 0:W.contentFormat)==="jsx")&&(typeof((T=_.config)==null?void 0:T.content)=="string"||Array.isArray((Y=_.config)==null?void 0:Y.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),A=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(D.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(D.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(Po,{background:a,border:i==="dark"?c:"gray.300",children:f.jsxs(D.HStack,{px:2,gap:2,width:"max-content",height:"100%",children:[f.jsx(Ge,{label:"Previous content",children:f.jsx(Oe,{"data-flow-content-navigation":"","aria-label":"Previous content",icon:f.jsx(Z.PiCaretLeft,{size:20}),disabled:C<=0||m,onClick:()=>I(-1),rememberAction:!1,size:"sm",variant:"ghost"})}),f.jsxs(D.Text,{"aria-live":"polite",fontSize:"12px",minW:"42px",textAlign:"center",children:[C+1," / ",u.length]}),f.jsx(Ge,{label:"Next content",children:f.jsx(Oe,{"data-flow-content-navigation":"","aria-label":"Next content",icon:f.jsx(Z.PiCaretRight,{size:20}),disabled:C>=u.length-1||m,onClick:()=>I(1),rememberAction:!1,size:"sm",variant:"ghost"})}),["width","height"].map(_=>f.jsxs(D.Box,{as:"label",display:"flex",alignItems:"center",gap:1,fontSize:"12px",opacity:S?1:.5,children:[_==="width"?"W":"H",f.jsx(kr,{value:_==="width"?R:A,placeholder:"Auto",ariaLabel:`Content ${_}`,type:"number",min:1,width:"72px",disabled:!S||!t.onNodeDimensionChange||m,onCommit:N=>{var O;S&&((O=t.onNodeDimensionChange)==null||O.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(Oe,{"aria-label":"Edit content source",icon:f.jsx(Z.PiCode,{size:20}),onClick:()=>g(!0),rememberAction:!1,size:"sm",variant:"ghost",color:l})})]})})}),f.jsx(D.Box,{flex:1,minH:0,overflow:"auto",position:"relative","data-content-slide-viewport":"",children:f.jsx(D.Box,{ref:x,"data-content-slide":v.data.id,width:R?`${R}px`:"100%",height:A?`${A}px`:"100%",minH:A?void 0:"100%",mx:"auto",overflow:"auto",children:f.jsx(xu,{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(D.Box,{role:"status",p:4,children:"No HTML or JSX content available."})}const dv=j.forwardRef(function({fullscreen:r,onClick:t},n){const{colorInactive:o}=st();return f.jsx(Oe,{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(Z.PiArrowsIn,{size:20}):f.jsx(Z.PiArrowsOut,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:o,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:t})});function fE({content:e,format:r,onEdit:t,autoHeight:n=!1,nodeId:o,controls:i=!0}){var H,V,le,X,ue;const{config:s,colorMode:a}=Ve(),{nodeById:c}=Qt(),l=o?(V=(H=c.get(o))==null?void 0:H.data.viewProps)==null?void 0:V.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}=st(),m=(le=s.customViews)==null?void 0:le.jsxContent,g=typeof e=="string"?e:JSON.stringify(e,null,2);let y,b=r==="jsx"&&o?(ue=(X=c.get(o))==null?void 0:X.data.config)==null?void 0:ue.contentReferenceError:void 0;const x=typeof e=="string"?e.trim().length>0:e!=null;if(r==="jsx"&&!b&&x)try{const oe=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(oe)||oe.some(de=>!de||typeof de!="object"||Array.isArray(de)||typeof de.type!="string"))throw new Error("JSX content must be an array of components with a type.");y=oe}catch(oe){b=oe instanceof Error?oe.message:"Invalid components array."}const w=j.useRef(null),v=j.useRef(null),C=j.useRef(null),S=j.useRef(!1),[E,R]=j.useState(!1),A=j.useRef(null),I=So({edge:"top",enabled:E,bounds:A,inside:[A],threshold:90}),[M,k]=j.useState(""),[_,N]=j.useState(),O=!!t;j.useEffect(()=>{const oe=()=>{var ge;const de=document.fullscreenElement===v.current;R(de),S.current&&!de&&!document.fullscreenElement&&((ge=C.current)==null||ge.focus({preventScroll:!0})),S.current=de};return document.addEventListener("fullscreenchange",oe),()=>document.removeEventListener("fullscreenchange",oe)},[]);const W=async()=>{var oe;k("");try{if(document.fullscreenElement===v.current)await document.exitFullscreen();else if((oe=v.current)!=null&&oe.requestFullscreen)await v.current.requestFullscreen();else throw new Error("Fullscreen is not supported in this browser.")}catch(de){k(de instanceof Error?de.message:"Unable to change fullscreen.")}},[T,Y]=j.useState(),[he,K]=j.useState(),[re,G]=j.useState();j.useEffect(()=>{if(r==="jsx")return;let oe=!1;return Promise.resolve().then(()=>require("./contentPreviewDocument-26_hwvOv.cjs")).then(({contentPreviewDocument:de})=>de(g,r,O,n)).then(de=>{oe||Y({content:g,format:r,editable:O,autoHeight:n,document:de})},de=>{oe||Y({content:g,format:r,editable:O,autoHeight:n,error:de instanceof Error?de.message:String(de)})}),()=>{oe=!0}},[g,r,O,n]),j.useEffect(()=>{if(!t)return;const oe=async de=>{var ge,ce;if(!(!((ge=w.current)!=null&&ge.contentWindow)||de.source!==w.current.contentWindow||((ce=de.data)==null?void 0:ce.type)!=="squeed:content-edit"))try{document.fullscreenElement===v.current&&await document.exitFullscreen(),t()}catch(U){k(U instanceof Error?U.message:"Unable to close fullscreen.")}};return window.addEventListener("message",oe),()=>window.removeEventListener("message",oe)},[t]);const ne=(T==null?void 0:T.content)===g&&T.format===r&&T.editable===O&&T.autoHeight===n?T:void 0;j.useEffect(()=>{if(!n||r!=="html"||!(ne!=null&&ne.document))return;const oe=ne.document,de=ge=>{var U,te,pe;const ce=(U=ge.data)==null?void 0:U.height;!((te=w.current)!=null&&te.contentWindow)||ge.source!==w.current.contentWindow||((pe=ge.data)==null?void 0:pe.type)!=="squeed:content-size"||typeof ce!="number"||!Number.isFinite(ce)||ce<=0||ce>1e5||document.fullscreenElement===v.current||N(ve=>(ve==null?void 0:ve.document)===oe&&ve.height===ce?ve:{document:oe,height:ce})};return window.addEventListener("message",de),()=>window.removeEventListener("message",de)},[n,r,ne==null?void 0:ne.document]);const q=!!ne&&ne===re,z=r!=="jsx"&&!(ne!=null&&ne.error)&&!q&&(!ne||he!==ne);return f.jsxs("div",{"data-flow-content-preview":"",style:{width:"100%",height:i?d??(n?r==="jsx"?"auto":(_==null?void 0:_.document)===(ne==null?void 0:ne.document)?_==null?void 0:_.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(D.Box,{ref:v,position:"relative",w:"100%",h:n&&r==="jsx"?"auto":"100%","aria-busy":!E&&r!=="jsx"?z:void 0,bg:r==="jsx"&&a==="dark"?"gray.900":"white",onDoubleClick:oe=>{r!=="jsx"||!t||oe.defaultPrevented||oe.target.closest('button, a, input, textarea, select, [contenteditable], [role="button"], [role="textbox"]')||(oe.stopPropagation(),(async()=>{document.fullscreenElement===v.current&&await document.exitFullscreen(),t()})().catch(de=>k(String(de))))},onKeyDownCapture:oe=>{oe.key!=="Escape"||document.fullscreenElement!==v.current||oe.target instanceof Element&&oe.target.closest('input, textarea, select, [contenteditable="true"]')||(oe.preventDefault(),oe.stopPropagation(),W())},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(D.Box,{ref:A,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:E?1:0,pointerEvents:E?"auto":"none",css:E?{"@media (hover: hover) and (pointer: fine)":{opacity:I?1:0},"&:hover, &:focus-within":{opacity:1}}:void 0,children:f.jsx(Po,{background:u,border:a==="dark"?h:"gray.300",children:f.jsxs(D.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&&(!E||!o)&&f.jsx(Oe,{"data-flow-content-edit":"","aria-label":"Edit content source",title:"Edit content source",icon:f.jsx(Z.PiCode,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:p,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:oe=>{oe.stopPropagation(),(async()=>{document.fullscreenElement===v.current&&await document.exitFullscreen(),t()})().catch(de=>k(String(de)))}}),f.jsx(dv,{ref:C,fullscreen:E,onClick:oe=>{oe.stopPropagation(),W()}})]})})}),M&&f.jsx(D.Box,{role:"alert",position:"absolute",bottom:0,insetInline:0,bg:"white",color:"red.700",fontSize:"14px",children:M}),E&&o?f.jsx(uE,{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||E}):x?f.jsx(D.Box,{role:"status",fontSize:"14px",children:"JSX content renderer is not available."}):null:ne!=null&&ne.error||q?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:(ne==null?void 0:ne.error)||"Content preview could not be loaded."}):ne!=null&&ne.document?f.jsx("iframe",{ref:w,title:`${r.toUpperCase()} content preview`,sandbox:O||n?"allow-scripts":"",allowFullScreen:!0,referrerPolicy:"no-referrer",srcDoc:ne.document,onLoad:()=>K(ne),onError:()=>G(ne),style:{width:"100%",height:"100%",border:0,display:"block",background:"white",visibility:z?"hidden":"visible"}},ne.document):null,f.jsx(bu,{active:!E&&z,label:"Loading HTML content"})]})]})}const Tm=1.55;function xu({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 K,re;const{callbacks:m,config:g,readOnly:y,nodeGridOptions:b}=Ve(),x=!!g.editable&&!y,w=x&&(!b||o&&b.fill&&n==="markdown"),{nodeById:v}=Qt(),C=n==="jsx"&&!d?((re=(K=v.get(e))==null?void 0:K.data.config)==null?void 0:re.contentSource)??r:r,S=typeof C=="string"?C:JSON.stringify(C,null,2),[E,R]=j.useState(a&&x),[A,I]=j.useState(S),[M,k]=j.useState(""),[_,N]=j.useState(),O=j.useRef(null),W=j.useRef(!1),T=mu(E);j.useLayoutEffect(()=>{const G=O.current;!E||!G||(G.style.height="auto",G.style.height=`${Math.max((_==null?void 0:_.height)??0,G.scrollHeight)}px`)},[A,E,_]),j.useEffect(()=>{var G,ne;x?E&&(W.current=!1,(G=O.current)==null||G.focus({preventScroll:!0}),(ne=O.current)==null||ne.select()):(R(!1),p==null||p(void 0))},[E,x,p]);const Y=(G,ne=!1)=>{!x||b&&!w&&!ne||(N({width:G.offsetWidth,height:G.offsetHeight}),I(S),p==null||p(S),k(""),R(!0))},he=()=>{var ne;if(W.current||!x)return;let G=A;if(n==="jsx")try{if(G=JSON.parse(A),!Array.isArray(G)||G.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}W.current=!0,A!==S&&(d?d(G):(ne=m.onNodeContentChange)==null||ne.call(m,e,G)),R(!1),u==null||u()};return(!E||!x)&&n!=="markdown"?f.jsx(D.Box,{ref:T,w:"100%",h:!s&&!i?"100%":void 0,position:"relative","data-flow-content":"",children:f.jsx(fE,{nodeId:e,content:r,format:n,controls:s,autoHeight:i&&!(b!=null&&b.fill),onEdit:w?()=>{T.current&&Y(T.current)}:void 0})}):!E||!x?f.jsx(D.Box,{"data-flow-content":"",color:t,opacity:r?void 0:.6,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:Tm,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:G=>{!x||b&&!w&&!G.shiftKey||G.target instanceof Element&&G.target.closest("a, button, input")||(G.stopPropagation(),Y(G.currentTarget,G.shiftKey))},onDoubleClick:G=>{G.stopPropagation(),Y(G.currentTarget,G.shiftKey)},onKeyDown:G=>{x&&(w||G.shiftKey)&&G.key==="Enter"&&G.target===G.currentTarget&&(G.preventDefault(),G.stopPropagation(),Y(G.currentTarget,G.shiftKey))},children:c?f.jsx(D.Box,{whiteSpace:"pre-wrap",minH:"100%",children:S||(x?l:"")}):f.jsx(Ov.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(D.Textarea,{ref:O,"aria-label":"Node content",placeholder:l,value:A,"aria-invalid":!!M,onChange:G=>{I(G.target.value),p==null||p(G.target.value)},onPaste:G=>{c&&G.clipboardData.files.length&&(G.preventDefault(),G.stopPropagation())},onDrop:G=>{c&&(G.stopPropagation(),G.dataTransfer.files.length&&G.preventDefault())},onBlur:he,onKeyDown:G=>{if(G.stopPropagation(),!G.nativeEvent.isComposing){if(h&&n==="markdown"&&G.key==="Enter"&&!G.shiftKey&&!G.ctrlKey&&!G.metaKey&&!G.altKey){G.preventDefault(),!G.repeat&&!W.current&&A.trim()&&(Vr.flushSync(he),h(A));return}G.key==="Enter"&&(G.ctrlKey||G.metaKey)&&(G.preventDefault(),he()),G.key==="Escape"&&(W.current=!0,R(!1),p==null||p(void 0),u==null||u())}},color:t,fontFamily:"inherit",fontSize:"inherit",lineHeight:Tm,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(D.Box,{role:"alert",fontSize:"14px",color:"red.500",children:M})]})}function hE({edited:e,relative:r,helpText:t,fontSize:n}){return!r||!e.name?null:f.jsxs(D.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 Im({data:e,caption:r=!1}){var l,d,u,h,p;const{colorText:t}=st(),n=typeof((l=e.config)==null?void 0:l.subtitle)=="string"?e.config.subtitle:"",o=(d=e.config)==null?void 0:d.edited,i=Aw(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(D.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(hE,{edited:o,relative:i,helpText:c,fontSize:a}),n&&f.jsx(D.Text,{"data-flow-node-subtitle":"",fontSize:a,lineHeight:1.3,whiteSpace:"pre-line",title:c,children:n})]})}const pE=({data:e,children:r,isInverted:t,isParent:n,onOpenView:o,editOnMount:i=!1,hoverLeaveDelay:s=0})=>{var ce,U,te,pe,ve,Ne,Je,tt,Ye,Ue,lt;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}=Ve(),{background:v,border:C,colorText:S}=st(),E=j.useRef(null),R=j.useRef(null);j.useEffect(()=>()=>{R.current&&clearTimeout(R.current)},[]);const[A,I]=j.useState(!1),[M,k]=j.useState(i&&!!y.editable&&!y.readOnly),[_,N]=j.useState(!1),O=e==null?void 0:e.id,W=Rb(O),T=a.includes(O);j.useEffect(()=>{if(!T||a.length!==1||y.readOnly||M||_)return;const be=Ae=>{var Ie,et,Ee,Le,at;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(He=>He.getClientRects().length&&getComputedStyle(He).visibility!=="hidden"))return;const ie=Array.from(((Ie=E.current)==null?void 0:Ie.querySelectorAll("[data-flow-content-toggle] button, button[data-flow-collapse-control]"))??[]).find(He=>{var ft;return((ft=He.closest("[data-node-id]"))==null?void 0:ft.getAttribute("data-node-id"))===O&&!He.disabled&&He.getClientRects().length&&getComputedStyle(He).visibility!=="hidden"}),ae=!ie&&(e==null?void 0:e.type)==="grid"&&((et=e.config)==null?void 0:et.documentId)&&((Ee=E.current)==null?void 0:Ee.getClientRects().length)&&g.onNodeHoverAction&&((Le=y.nodeOverlayActions)==null?void 0:Le.find(He=>He.id==="open-document"&&(!He.nodeTypes||He.nodeTypes.includes(e.type))));!ie&&!ae||(Ae.preventDefault(),Ae.stopPropagation(),Ae.repeat||(ie?ie.click():(at=g.onNodeHoverAction)==null||at.call(g,ae.id,O,e)))};return window.addEventListener("keydown",be,!0),()=>window.removeEventListener("keydown",be,!0)},[O,T,a.length,y.readOnly,M,_,e,g.onNodeHoverAction,y.nodeOverlayActions]);const Y=(ce=y.nodeOverlayActions)==null?void 0:ce.filter(be=>!be.nodeTypes||be.nodeTypes.includes(e==null?void 0:e.type)),he=y.renderNodeOverlay,K=(e==null?void 0:e.type)==="grid"?(U=y.customViews)==null?void 0:U.gridHoverControls:void 0,re=(e==null?void 0:e.type)==="grid"?"20px":"-100px",G=(e==null?void 0:e.type)==="grid"?"top center":void 0,ne=(e==null?void 0:e.type)==="grid"?"translateX(-50%) scale3d(1.8, 1.8, 1)":"translateX(-50%) scale3d(3, 3, 1)",q=(()=>{var be;try{const Ae=(be=m.current)==null?void 0:be.zoom();return Ae!==void 0&&Ae<.08}catch{return!1}})(),z=j.useCallback((be,Ae=!1)=>{var ae,Ie,et,Ee,Le;if(M||y.readOnly||h!=null&&h.fill&&!be.shiftKey||be.detail===2&&((ae=e==null?void 0:e.config)!=null&&ae.form)&&!o&&!Ae&&!u&&!l&&!be.shiftKey&&!be.ctrlKey&&!be.metaKey&&!be.altKey&&a.length===1&&a[0]===O)return;const ie={shiftKey:be.shiftKey,ctrlKey:be.ctrlKey,metaKey:be.metaKey,altKey:be.altKey,...Ae?{viewToggle:!0}:{}};if(l&&(d(null),(Ie=g.onEdgeDeselect)==null||Ie.call(g)),u||be.shiftKey&&(h!=null&&h.fill)){const at=a.includes(O),He=at?a.filter(ft=>ft!==O):[...a,O];c(He),at?(et=g.onNodeDeselect)==null||et.call(g):(Ee=g.onNodeSelect)==null||Ee.call(g,O,e,ie)}else c([O]),(Le=g.onNodeSelect)==null||Le.call(g,O,e,ie)},[O,e,a,l,u,h,M,o,c,d,g,y]),H=j.useCallback(()=>{var be;M||y.readOnly||(be=g.onNodeDoubleClick)==null||be.call(g,O,e)},[O,e,M,g,y]),V=j.useCallback(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>I(!0),100)},[]),le=j.useCallback(be=>{var Ae;be.relatedTarget instanceof Node&&((Ae=E.current)!=null&&Ae.contains(be.relatedTarget))||(R.current&&clearTimeout(R.current),s?R.current=setTimeout(()=>I(!1),s):I(!1))},[s]),X=(e==null?void 0:e.type)==="text"&&!((te=e==null?void 0:e.config)!=null&&te.parentContainer)&&!((pe=e==null?void 0:e.config)!=null&&pe.form),ue=!!((ve=e==null?void 0:e.config)!=null&&ve.form)||X,oe={tabIndex:ue?0:void 0,"aria-haspopup":ue?"dialog":void 0,"aria-expanded":ue?_:void 0,onDoubleClickCapture:be=>{var Ae;!ue&&!o||y.readOnly||X&&!y.editable||M||!be.currentTarget.contains(be.target)||be.target instanceof Element&&be.target.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]")||(be.preventDefault(),be.stopPropagation(),(a.length!==1||a[0]!==O)&&c([O]),o?o():N(!0),(Ae=g.onNodeDoubleClick)==null||Ae.call(g,O,e))},onKeyDown:be=>{!ue&&!o||y.readOnly||X&&!y.editable||be.target!==be.currentTarget||be.key!=="Enter"||(be.preventDefault(),be.stopPropagation(),c([O]),o?o():N(!0))}},de=ue&&f.jsx(ko,{nodeAddress:O,active:T,label:e.label||e.headerTitle||"Node",open:_&&(!X||!!y.editable&&!y.readOnly),onClose:()=>{var be;N(!1),T&&((be=E.current)==null||be.focus({preventScroll:!0}))},children:X?f.jsx(xu,{nodeId:O,content:e.label??e.text??"",color:Me(S),editOnMount:!0,onChange:be=>{var Ae;return(Ae=g.onNodeLabelChange)==null?void 0:Ae.call(g,O,String(be))},onEditEnd:()=>N(!1)}):void 0}),ge=Array.isArray((Ne=e==null?void 0:e.config)==null?void 0:Ne.ports)?e.config.ports.map(be=>f.jsx(lv,{...be},`${be.id}:${be.role}`)):null;return n?f.jsxs(D.Box,{ref:E,...oe,onClick:z,onDoubleClick:H,onMouseEnter:V,onMouseLeave:le,cursor:"pointer",position:"relative",children:[de,!p&&(he||Y&&Y.length>0)&&A&&!q&&f.jsxs(f.Fragment,{children:[f.jsx(D.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>I(!0),onMouseLeave:le}),he?f.jsx(D.Box,{position:"absolute",zIndex:1e3,top:re,transformOrigin:G,left:"50%",pointerEvents:"auto",transform:ne,onMouseEnter:()=>I(!0),onMouseLeave:le,willChange:"transform",children:he({nodeId:O,nodeData:e,isRoot:O==="root",isParent:!0,isHovered:A,setIsHovered:I})}):f.jsx(D.Box,{position:"absolute",zIndex:1e3,top:re,transformOrigin:G,left:"50%",bg:v,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:ne,boxShadow:"lg",onMouseEnter:()=>I(!0),onMouseLeave:le,willChange:"transform",children:f.jsxs(D.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:[Y.map((be,Ae)=>f.jsxs(D.Box,{display:"contents",children:[Ae>0&&f.jsx(D.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(Td,{icon:be.icon,label:be.label,color:S,bgColor:v,borderColor:C,textColor:S,boxSize:5,onClick:ie=>{var ae;ie.stopPropagation(),(ae=g.onNodeHoverAction)==null||ae.call(g,be.id,O,e)}})]},be.id)),K&&f.jsx(K,{data:e})]})})]}),r({id:O,data:e,isActive:T,isHovered:A,isLowZoom:q,isEditing:M,onSelect:z,onEditStart:()=>k(!0),onEditEnd:()=>k(!1)}),f.jsx(Im,{data:e}),W&&!((Je=e==null?void 0:e.config)!=null&&Je.parentContainer)&&((tt=e==null?void 0:e.config)==null?void 0:tt.collapsed)!==void 0&&(()=>{var ie;const be=x==="TB"||x==="BT",Ae=t||x==="RL";return f.jsx(D.IconButton,{position:"absolute",...be?{[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:ae=>{var Ie;ae.stopPropagation(),(Ie=g.onNodeCollapse)==null||Ie.call(g,O,!e.config.collapsed)},bgColor:Me(((ie=e==null?void 0:e.viewProps)==null?void 0:ie.bgColor)||b),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Z.PiPlusBold,{size:30,color:Me("gray.800")}):f.jsx(Z.PiMinusBold,{size:30,color:Me("gray.800")})})})()]}):f.jsxs(D.Box,{ref:E,...oe,onClick:z,onDoubleClick:H,onMouseEnter:V,onMouseLeave:le,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[de,ge,!p&&(he||Y&&Y.length>0)&&A&&!q&&f.jsxs(f.Fragment,{children:[f.jsx(D.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>I(!0),onMouseLeave:le}),he?f.jsx(D.Box,{position:"absolute",zIndex:1e3,top:re,transformOrigin:G,left:"50%",pointerEvents:"auto",transform:ne,onMouseEnter:()=>I(!0),onMouseLeave:le,willChange:"transform",children:he({nodeId:O,nodeData:e,isRoot:O==="root",isParent:!!n,isHovered:A,setIsHovered:I})}):f.jsx(D.Box,{position:"absolute",zIndex:1e3,top:re,transformOrigin:G,left:"50%",bg:v,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:ne,boxShadow:"lg",onMouseEnter:()=>I(!0),onMouseLeave:le,willChange:"transform",children:f.jsxs(D.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:[Y.map((be,Ae)=>f.jsxs(D.Box,{display:"contents",children:[Ae>0&&f.jsx(D.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(Td,{icon:be.icon,label:be.label,color:S,bgColor:v,borderColor:C,textColor:S,boxSize:5,onClick:ie=>{var ae;ie.stopPropagation(),(ae=g.onNodeHoverAction)==null||ae.call(g,be.id,O,e)}})]},be.id)),K&&f.jsx(K,{data:e})]})})]}),f.jsxs(D.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[W&&!((Ye=e==null?void 0:e.config)!=null&&Ye.parentContainer)&&((Ue=e==null?void 0:e.config)==null?void 0:Ue.collapsed)!==void 0&&!n&&(()=>{var ae,Ie,et;const be=x==="TB"||x==="BT",Ae=t||x==="RL",ie=(ae=e==null?void 0:e.config)!=null&&ae.labelBelow&&w[O]!=="properties"?((((Ie=e==null?void 0:e.viewProps)==null?void 0:Ie.fontSize)||1)*100+100)/2:void 0;return f.jsx(D.IconButton,{position:"absolute",...be?{[x==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:Ae?void 0:ie===void 0?"-75px":`calc(50% - ${ie+75}px)`,left:Ae?ie===void 0?"-75px":`calc(50% - ${ie+75}px)`:void 0,alignSelf:ie===void 0?"center":void 0,top:ie===void 0?void 0:`${ie}px`,transform:ie===void 0?void 0:"translateY(-50%)",zIndex:ie===void 0?void 0:1},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:y.readOnly,onClick:Ee=>{var Le;Ee.stopPropagation(),(Le=g.onNodeCollapse)==null||Le.call(g,O,!e.config.collapsed)},bgColor:Me(((et=e==null?void 0:e.viewProps)==null?void 0:et.bgColor)||b),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Z.PiPlusBold,{size:30,color:Me("gray.800")}):f.jsx(Z.PiMinusBold,{size:30,color:Me("gray.800")})})})(),r({id:O,data:e,isActive:T,isHovered:A,isLowZoom:q,isEditing:M,onSelect:z,onEditStart:()=>k(!0),onEditEnd:()=>k(!1)})]}),f.jsx(Im,{data:e,caption:!!((lt=e.config)!=null&<.labelBelow)&&w[O]!=="properties"})]})},Qn=j.memo(pE),gE=({id:e,data:r,isActive:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var g,y,b,x,w,v,C,S;const{themeColor:s}=Ve(),{colorText:a}=st(),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=((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(D.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(D.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(D.Box,{flexShrink:0,children:f.jsx(dr,{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 vu(e,r,t){const{readOnly:n,selectedNodeIds:o}=Ve(),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}=Ve();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 yE=({id:e,isActive:r,data:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var w,v,C,S,E,R,A,I,M,k,_,N,O;const{themeColor:s}=Ve(),{colorText:a}=st(),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=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(((R=t==null?void 0:t.viewProps)==null?void 0:R.borderColor)||(l?d:u)),y=c||l?"transparent":d!=null&&d.startsWith("#")?d:Me(h),b=(A=t==null?void 0:t.config)==null?void 0:A.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 W=(((M=t==null?void 0:t.viewProps)==null?void 0:M.fontSize)||1)*100;return f.jsxs(D.Flex,{"data-flow-icon-label":"",css:{"--flow-grid-on-surface-color":m},direction:"column",align:"center",gap:"24px",width:`${Math.max(W+200,360)}px`,position:"relative",children:[f.jsx(D.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${W+100}px`,height:`${W+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(dr,{name:b,size:W,color:m})}),f.jsx(D.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(D.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(D.Flex,{align:"center",py:14,mr:x?8:0,flexShrink:0,children:f.jsx(dr,{name:b,size:(((O=t==null?void 0:t.viewProps)==null?void 0:O.fontSize)||1)*100,color:m},m)}),(x||!b)&&f.jsx(D.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=yE,...o}){const{colorMode:i,callbacks:s}=Ve();return f.jsx(Qn,{...o,hoverLeaveDelay:e?350:0,children:a=>f.jsxs(D.Box,{position:"relative",children:[f.jsx(n,{...a}),e&&(a.isHovered||a.isActive)&&f.jsx(D.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:f.jsx(Ge,{label:r,children:f.jsx(Oe,{"aria-label":r,icon:f.jsx(D.Icon,{as:Z.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 uv=(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}},mE=(e,r=350)=>`${String(e).substring(0,r)}${String(e).length>r?"...":""}`,bE=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,fv=600,xE=3,vE=e=>{const r=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(r*28+30,200)};function wE({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}=Ve();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(D.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(D.Flex,{mr:6,alignItems:"center",flexShrink:0,children:f.jsx(dr,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),f.jsx(cn,{nodeId:s,label:bE(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(D.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:f.jsx(Ge,{label:w,children:f.jsx(Oe,{"aria-label":w,icon:f.jsx(D.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:R=>{var A;R.stopPropagation(),a||d(R),x?x():g(!m),(A=b.onNodeViewToggle)==null||A.call(b,s)}})})})]})})}function CE({data:e,resourcePorts:r,inspecting:t,form:n,inspectionPorts:o,extraPorts:i,colors:s,direction:a,uniformKeyWidth:c}){const{edgeById:l}=Qt(),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(D.Box,{children:Object.entries(e.description||{}).map(([u,h],p)=>{var _,N,O;const m=r&&Object.keys(r).find(W=>W.slice(W.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(W=>W.id===y),x=m?"source":b==null?void 0:b.role,w=d.has(`source:${y}`),v=d.has(`target:${y}`),C=i.some(W=>W.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),A=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=lr(s.wordBeforeDot)[typeof h],k=lr(s.wordBeforeDot).property;return f.jsxs(D.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(D.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[f.jsx(D.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(D.Text,{py:5,px:10,w:"100%",textAlign:A,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(D.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:s.hexbgColor,w:fv,maxH:200,children:f.jsx(D.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:((O=e==null?void 0:e.viewProps)==null?void 0:O.textColor)||(s.isTransparent?s.hextextColor:M),fontWeight:400,children:mE(h)})})]}),p!==Object.entries(e.description||{}).length-1&&f.jsx(D.Box,{borderTopWidth:1,my:0,borderColor:s.hexborderColor})]},u)})})}function SE(e){var w,v,C,S,E;const{themeColor:r,colorMode:t,direction:n}=Ve(),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(qt),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&&$e(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 A;return Object.prototype.hasOwnProperty.call(p,R)&&Eo((A=h.fields[R])==null?void 0:A.$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,A])=>{var I;return[R.slice(R.indexOf(":")+1),((I=$e(l,A))==null?void 0:I.name)??A.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(([A,I])=>`${I.kind}:${A}`===R.id&&Object.prototype.hasOwnProperty.call(g,A))),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 Ko=e=>{var w,v,C,S,E,R,A,I;const{config:r}=Ve(),{themeColor:t,colorMode:n,direction:o,objVisible:i,setObjVisible:s,inspecting:a,resourcePorts:c,form:l,description:d,inspectionPorts:u,extraPorts:h}=SE(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),vu(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?((A=e.data.config)==null?void 0:A.contentFormat)==="html"?"PiFileHtml":((I=e.data.config)==null?void 0:I.contentFormat)==="jsx"?"PiFileJsx":"https://squeed.co/squeed.svg":"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:O,onSelect:W,onEditStart:T,onEditEnd:Y})=>{var X,ue,oe,de,ge,ce,U,te,pe,ve,Ne,Je,tt,Ye,Ue,lt,be,Ae,ie;const he=uv(k,t,n),K=k.label??k.headerTitle,re=Object.entries(k.description||{}).length>0,G=vE(k.description),ne=(ue=(X=e.data)==null?void 0:X.config)==null?void 0:ue.icon,q=(de=(oe=e.data)==null?void 0:oe.config)==null?void 0:de.content,z=g&&!i&&k.label===""&&(((ge=k.config)==null?void 0:ge.contentFormat)==="html"||((ce=k.config)==null?void 0:ce.contentFormat)==="jsx"),H=g&&!i&&(((U=k.config)==null?void 0:U.contentFormat)==="html"||((te=k.config)==null?void 0:te.contentFormat)==="jsx")&&((pe=k.viewProps)==null?void 0:pe.width)!==void 0&&k.viewProps.width!=="100%",V=((ve=k==null?void 0:k.viewProps)==null?void 0:ve.borderRadius)??"53px",le=Wn(k==null?void 0:k.viewProps,he.hexborderColor,_,xE);return f.jsx(D.Flex,{justifyContent:"space-between",...k==null?void 0:k.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:V,overflow:"hidden",alignItems:"center",style:{backgroundColor:he.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:e.contentWidth??(z||H?((Ne=k.viewProps)==null?void 0:Ne.width)!==void 0&&k.viewProps.width!=="100%"?k.viewProps.width:"max-content":"100%"),maxW:z?"calc(100vw - 40px)":void 0,height:e.contentHeight??((Je=k.viewProps)==null?void 0:Je.height),minW:e.contentMinWidth??(e.contentWidth||z||H?0:g||e.onShowIcon?G+fv+le.borderWidth*2:void 0),...le,children:f.jsxs(D.Flex,{width:"100%",height:e.contentHeight!==void 0?"100%":void 0,minH:e.contentHeight!==void 0?0:void 0,direction:"column",position:"relative",borderRadius:V,borderColor:he.hexborderColor,borderWidth:0,overflow:"hidden",children:[e.surfaceOverlay,!e.fillBody&&f.jsx(wE,{headerTitle:K,hasContent:g,data:k,icon:ne,colors:he,hasConfig:re,id:M,isActive:_,isHovered:N,isEditing:O,onSelect:W,onEditStart:T,onEditEnd:Y,props:e,objVisible:i,setObjVisible:s,onShowNativeIcon:x}),e.headerOverlay,g&&!i?f.jsx(D.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:he.highlightColor,p:["html","jsx"].includes((Ye=(tt=e.data)==null?void 0:tt.config)==null?void 0:Ye.contentFormat)?0:12,fontSize:"5xl",lineHeight:"normal",...e.contentProps,children:f.jsx(xu,{nodeId:M,content:q,format:(lt=(Ue=e.data)==null?void 0:Ue.config)==null?void 0:lt.contentFormat,fillBody:e.fillBody,autoHeight:z,color:((be=k==null?void 0:k.viewProps)==null?void 0:be.textColor)||he.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))??((ie=e.data.config)!=null&&ie.promptTurn?"Thinking...":void 0)})}):f.jsx(CE,{data:k,resourcePorts:c,inspecting:a,form:l,inspectionPorts:u,extraPorts:h,colors:he,direction:o,uniformKeyWidth:G}),e.footer]})})}})};Ko.displayName="NodeJsonObjectView";const hv=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}=Ve(),c=(p=(h=e.data)==null?void 0:h.config)==null?void 0:p.parentContainer;vu(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(Ko,{...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 jE(e){var b,x,w,v,C,S;const{config:r,callbacks:t,readOnly:n,selectedNodeIds:o,nodeRadiusPreviews:i,nodeViewModes:s,allNodesIconLabel:a}=Ve(),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}=st(),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),vu(e.data.id,a&&!g&&y.current,()=>u.setNodeViewMode(e.data.id,"icon-label")),g?f.jsx(D.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 A,I,M,k,_,N,O,W;return f.jsx(D.Box,{"data-flow-node-surface":"","data-grid-document":((A=E.config)==null?void 0:A.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:((O=E.viewProps)==null?void 0:O.textColor)??p,borderRadius:`${c??0}px`,...Wn(E.viewProps,Me(((W=E.viewProps)==null?void 0:W.borderColor)??h),R,0),children:m?f.jsx(m,{...e}):f.jsx(D.Box,{p:4,children:E.label??"Grid"})})}}),f.jsx(ko,{nodeAddress:e.data.id,active:o.includes(e.data.id),label:e.data.label??"Grid",open:l&&!n,onClose:()=>d(!1),children:f.jsx(qt.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 A,I,M;if(n||!r.editable)return;const R=String(E.value??"");E.address==="root.metadata.label"?(A=t.onNodeLabelChange)==null||A.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(Hd,{nodeAddress:e.data.id})})})]})}function EE(e){var M,k,_;const{callbacks:r,config:t,readOnly:n,themeColor:o,colorMode:i}=Ve(),{canvas:s,background:a,border:c,colorText:l}=st(),d=uv(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(),A=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 O=new AbortController;p.current=O,g(!0),b("");try{await r.onPromptSubmit({nodeId:e.data.id,prompt:N,temperature:x},O.signal)}catch(W){O.signal.aborted||b(W instanceof Error?W.message:"Prompt execution failed.")}finally{p.current===O&&(p.current=void 0,g(!1))}};return f.jsx(Ko,{...e,contentProps:{px:8,py:6,minH:"200px",flexShrink:0,overscrollBehavior:"contain"},contentPlainText:!0,contentPlaceholder:"How can I assist you?",surfaceOverlay:m?f.jsx(bu,{active:!0,label:"Prompt running"}):void 0,headerOverlay:h!==void 0?f.jsx(D.Box,{position:"relative",h:"0",flexShrink:0,"aria-hidden":"true","data-prompt-budget":"",children:f.jsx(D.Box,{position:"absolute",left:"0",right:"0",top:"-1px",h:"2px",bg:d.highlightColor,children:f.jsx(D.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(D.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(D.Text,{role:"alert",fontSize:"sm",color:"red.500",children:y}),f.jsxs(D.HStack,{justifyContent:"space-between",alignItems:"center",gap:3,children:[f.jsxs(D.HStack,{minW:0,gap:2,flexWrap:"wrap",color:d.hextextColor,children:[f.jsx(D.Text,{fontSize:"32px",lineHeight:"1.15",fontWeight:"bold",children:"Thinking effort"}),f.jsxs(Nt,{"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(Oe,{"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:A,color:l,_hover:{bg:A,color:l},_active:{bg:A},css:{...mr(`var(--chakra-colors-${A.replace(".","-")})`,`var(--chakra-colors-${c.replace(".","-")})`),"& > svg":{width:"40px",height:"40px"}},icon:m?f.jsx(Z.PiStop,{size:40}):f.jsx(Z.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 pv=e=>f.jsx(hv,{...e,renderCompact:gE}),gv=e=>f.jsx(hv,{...e}),yv=({containerStyle:e,...r})=>{const{selectedNodeIds:t}=Ve();return f.jsx(Qn,{...r,editOnMount:t.includes(r.data.id),children:n=>f.jsx(D.Box,{bg:e.textColor==="transparent"?"transparent":e.labelBg,p:`${e.fontSize/5}px`,fontFamily:Pr,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})})})};pv.displayName="text";gv.displayName="arrayView";yv.displayName="ParentContainerView";const _E={grid:jE,prompt:EE,objectView:Ko,arrayView:gv,text:pv,parentContainer:yv},kE=({children:e,pattern:r="dot",backgroundColor:t})=>{const{colorMode:n}=Ve(),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(D.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:t,children:e}):f.jsxs(D.Box,{"data-flow-background":r,position:"relative",width:"100%",height:"100%",padding:0,bg:t,children:[f.jsx(D.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(D.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},PE=.4,Lr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},AE=({nodes:e,edges:r})=>{var hr;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:A,setIsZoomMode:I,isMultiSelectMode:M,setIsMultiSelectMode:k,isDragMode:_,setIsDragMode:N,isEdgeHandlesEnabled:O,setIsEdgeHandlesEnabled:W,isArrayNodeMode:T}=Ve(),Y=j.useRef(null),[he,K]=j.useState(null),re=j.useRef(null),G=e.length>200;j.useEffect(()=>{S(G)},[G,S]);const{edgeSep:ne,rankSep:q,spacingFactor:z}=j.useMemo(()=>{const F=c1(e.length),$=b.nodeGridSpacing==="layout"&&n<.5?n*1.3:n<1?.3+.7*n:.5+.5*n;return{edgeSep:F.edgeSep*$,rankSep:F.rankSep*$,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n,b.nodeGridSpacing]),{bgColor:H}=Gn(t),{canvas:V,borderSecondary:le,colorText:X}=st(),ue=i==="transparent"?"transparent":b.backgroundColor||V,oe=j.useCallback(F=>{if(!F)return Me(t);switch(F){case"dark":return Me(ue);case"light":return Me(le);default:return Me(F)}},[t,ue,le]),de=b.colorMode==="dark",ge=de?Me("gray.500"):ln,ce=de?H!=null&&H.includes("gray")?"whitesmoke":oe(H):ge,U=c?oe(c):ge,te=j.useMemo(()=>{var F;return b.initialViewport||{pan:{x:0,y:0},zoom:(F=b.nodeGrid)!=null&&F.enabled&&b.nodeGrid.options.fill?1:.01}},[]),pe=l==="C"?"LR":l,ve=j.useCallback(F=>{const $={...m,...F};return{...$,bgColor:$.bgColor||t,bgOpacity:$.outline?0:$.bgOpacity??PE}},[m,t]),Ne=j.useMemo(()=>{var $;const F=new Map;for(const se of e)($=se.data)!=null&&$.id&&F.set(se.data.id,se);return F},[e]),Je=j.useMemo(()=>{var $;const F=new Map;for(const se of r)($=se.data)!=null&&$.id&&F.set(se.data.id,se);return F},[r]),tt=j.useCallback(F=>{var _e;const $=(_e=Ne.get(F))==null?void 0:_e.data,se=ve($==null?void 0:$.viewProps),xe=Me(se.bgColor);return{animated:!!($!=null&&$.isNodeAnimated)&&!G,animationVariant:$==null?void 0:$.nodeAnimationVariant,animationColor:Me(se.borderColor||t),bgColor:se.outline?"transparent":xe,bgOpacity:se.bgOpacity,borderColor:se.borderColor?Me(se.borderColor):se.outline&&se.bgColor==="transparent"?Me(t):xe,borderWidth:Dn(se.borderWidth,Lr.borderWidth),borderStyle:se.borderStyle??Lr.borderStyle,borderRadius:se.borderRadius??Lr.borderRadius,textColor:se.textColor?Me(se.textColor):se.outline||se.bgColor==="transparent"?Me(X):xe,fontSize:se.fontSize??Lr.fontSize,labelPosition:se.labelPosition??Lr.labelPosition,labelMargin:Lr.labelMargin,labelBg:Bu(oe("dark"),xe,se.bgOpacity)??oe("dark"),padding:se.padding??Lr.padding}},[ve,Ne,X,t,G,oe]),Ye=j.useMemo(()=>{var se,xe;const F=new Map;for(const _e of r){const Te=(se=_e.data)==null?void 0:se.source,Re=(xe=_e.data)==null?void 0:xe.target;if(!Te||!Re||Te===Re)continue;const Ze=Te<Re?`${Te}|${Re}`:`${Re}|${Te}`,Qe=F.get(Ze);Qe?Qe.push({id:_e.data.id,source:Te}):F.set(Ze,[{id:_e.data.id,source:Te}])}const $=new Map;for(const[_e,Te]of F){if(Te.length<2)continue;const Re=_e.split("|")[0],Ze=Math.min(20,70/Te.length);Te.forEach(({id:Qe,source:ze},dt)=>{const gt=50+(dt-(Te.length-1)/2)*Ze;$.set(Qe,(ze===Re?gt:100-gt)/100)})}return $},[r]),Ue=j.useMemo(()=>{const F=oe("dark");return r.filter($=>{var se;return((se=$.data)==null?void 0:se.id)&&$.data.source&&$.data.target}).map(({data:$})=>{var Te,Re,Ze,Qe,ze,dt;let se=F;const xe=(Re=(Te=Ne.get($.source))==null?void 0:Te.data)==null?void 0:Re.parent,_e=(Qe=(Ze=Ne.get($.target))==null?void 0:Ze.data)==null?void 0:Qe.parent;if(xe&&xe===_e){const gt=ve((dt=(ze=Ne.get(xe))==null?void 0:ze.data)==null?void 0:dt.viewProps),Ct=Bu(F,Me(gt.bgColor),gt.bgOpacity);Ct&&(se=Ct)}return{id:$.id,data:$,type:$.type??b.edgeType??"rounded-orthogonal",source:$.source,target:$.target,sourceProperty:$.sourceProperty,targetProperty:$.targetProperty,label:$.label,validationIssue:(u==="auto"||u==="properties")&&($.sourceProperty!==void 0||$.targetProperty!==void 0)&&p?Vd(p,$):void 0,color:c?U:$.color?Me($.color):U,connectorColor:c?U:$.color?Me($.color):ce,labelBg:se,dashed:!!$.isEdgeDashed,animated:!!$.isEdgeAnimated,inverted:!!$.isInverted,turn:Ye.get($.id)??.5}})},[r,U,ce,c,Ye,b.edgeType,u,p,Ne,ve,oe]),lt=j.useMemo(()=>{var $;const F=new Set;for(const se of e)($=se.data)!=null&&$.parent&&F.add(se.data.parent);return F},[e]),be=j.useMemo(()=>{const F=new Map;for(const $ of r){const se=$.data.isInverted?$.data.target:$.data.source;se&&!F.has(se)&&F.set(se,$.data)}for(const $ of r){if($.data.connection)continue;const se=$.data.isInverted?$.data.target:$.data.source,xe=$.data.isInverted?$.data.source:$.data.target;xe.startsWith(`${se}.`)&&(F.set(se,$.data),F.set(xe,$.data))}return F},[r]),Ae=j.useMemo(()=>{const F={..._E,...b.customViews};return e.filter($=>{var se;return(se=$.data)==null?void 0:se.id}).map($=>{var Qe,ze,dt,gt,Ct,jt,Mt,Tt,yt;const se=lt.has($.data.id)&&!$.data.parent,xe=se&&$.data.type!=="prompt"?$.data.label??$.data.headerTitle??"Container":void 0,_e=$.data.type==="prompt"?F.prompt:se?F.parentContainer:F[$.data.type]||F.text,Te=((Qe=b.customViews)==null?void 0:Qe.fillNode)??_e,Re=be.get($.data.id),Ze={...$,isInverted:((ze=$.data.config)==null?void 0:ze.isInverted)??(Re==null?void 0:Re.isInverted),isParent:se,containerStyle:se?tt($.data.id):void 0};return{id:$.data.id,collapsed:(dt=$.data.config)==null?void 0:dt.collapsed,parent:$.data.parent,acceptsChildren:!!((gt=$.data.config)!=null&>.parentContainer)||lt.has($.data.id),label:xe,animated:!!$.data.isNodeAnimated,animationVariant:$.data.nodeAnimationVariant,hasCollapseControl:((Ct=$.data.config)==null?void 0:Ct.collapsed)!==void 0,animationColor:Me(((jt=$.data.viewProps)==null?void 0:jt.borderColor)||t),animationWidth:Dn((Mt=$.data.viewProps)==null?void 0:Mt.borderWidth,8),element:j.createElement(_e,{...Ze,key:`${$.data.id}-${t}`}),fillElement:R.has($.data.id)&&!((Tt=b.customViews)!=null&&Tt.fillNode)?void 0:j.createElement(Te,{...Ze,...(yt=b.customViews)!=null&&yt.fillNode?{renderNode:_e}:{},data:{...$.data,viewProps:R.has($.data.id)?$.data.viewProps:{...$.data.viewProps,borderRadius:0}},containerStyle:Ze.containerStyle&&!R.has($.data.id)?{...Ze.containerStyle,borderRadius:0}:Ze.containerStyle,key:`${$.data.id}-${t}`})}})},[e,lt,be,t,b.customViews,tt,R]),ie=j.useMemo(()=>G?300:e.length>50?150:e.length>20?100:50,[e.length,G]),ae=j.useRef(b);ae.current=b;const Ie=j.useRef(A);Ie.current=A;const et=j.useRef(T);et.current=T;const Ee=j.useRef(x);Ee.current=x;const Le=j.useRef(v);Le.current=v;const at=j.useRef(M);at.current=M;const He=j.useRef(Ne);He.current=Ne;const ft=j.useRef(Je);ft.current=Je;const ht=j.useRef(new Map);j.useEffect(()=>{var se,xe;const F=new Map([...Je].filter(([,_e])=>Ne.has(_e.data.source)&&Ne.has(_e.data.target))),$=ht.current;ht.current=F;for(const[_e,Te]of $)F.has(_e)||(Le.current===_e&&(C(null),(se=y.onEdgeDeselect)==null||se.call(y)),(xe=y.onEdgeRemove)==null||xe.call(y,_e,Te.data))},[Je,Ne,y,C]),j.useEffect(()=>{const F=Y.current;if(!he||!F)return;let $=null,se=null,xe=0,_e=0,Te=0,Re=0,Ze=0;const Qe=ze=>{var Ct;if(ae.current.readOnly||ae.current.minZoom===ae.current.maxZoom&&ae.current.minZoom!==void 0&&((Ct=F.parentElement)!=null&&Ct.closest(".flow-sdk-canvas")))return;const dt=F.ownerDocument.fullscreenElement;if(dt&&dt!==F&&F.contains(dt)&&ze.target instanceof Node&&dt.contains(ze.target))return;ze.preventDefault(),ze.stopPropagation(),Ie.current||ze.metaKey||ze.ctrlKey?(Te+=ze.deltaY,Re=ze.clientX,Ze=ze.clientY,se===null&&(se=requestAnimationFrame(()=>{se=null;const jt=ae.current,Mt=he.zoom(),Tt=Te;Te=0;let yt=Mt-Tt*.05/100;yt=Math.max(jt.minZoom??.01,Math.min(jt.maxZoom??1.5,yt));const mt=F.getBoundingClientRect();he.zoomAt(yt,{x:Re-mt.left,y:Ze-mt.top})}))):(xe+=ze.deltaX,_e+=ze.deltaY,$===null&&($=requestAnimationFrame(()=>{$=null;const jt=he.pan(),Mt=he.zoom(),Tt=.35,yt=xe,mt=_e;xe=0,_e=0,he.pan({x:jt.x+-yt*Tt/Mt,y:jt.y+-mt*Tt/Mt})})))};return F.addEventListener("wheel",Qe,{passive:!1}),()=>{F.removeEventListener("wheel",Qe),$!==null&&cancelAnimationFrame($),se!==null&&cancelAnimationFrame(se)}},[he]),j.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const F=$=>{var xe,_e,Te,Re,Ze,Qe;if(ae.current.readOnly)return;const se=$.target;if(!(se.tagName==="INPUT"||se.tagName==="TEXTAREA"||se.isContentEditable)){if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes($.key)){const ze=Y.current,dt=g.current,gt=ze==null?void 0:ze.querySelector(".flow-sdk-canvas");if(!ze||!gt||!dt||se!==ze&&(se.closest(".flow-sdk-canvas")!==gt||!se.closest(".flow-sdk-node")||se.querySelector(":scope > .flow-sdk-canvas")||se.closest('button, input, textarea, select, a, [contenteditable], [role="button"], [role="textbox"], [role="combobox"], [role="slider"], [role="spinbutton"], [data-flow-content]'))||$.defaultPrevented||$.isComposing||$.shiftKey||$.ctrlKey||$.metaKey||$.altKey||at.current||Ee.current.length>1||gt.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(Bt=>Bt.getClientRects().length>0&&getComputedStyle(Bt).visibility!=="hidden"))return;const Ct=gt.getBoundingClientRect();if(!Ct.width||!Ct.height)return;const jt=dt.clientToModel(Ct.left+Ct.width/2,Ct.top+Ct.height/2),Mt=Ee.current[0],Tt=Mt&&dt.getNodeBox(Mt)||jt,yt=$.key==="ArrowLeft"||$.key==="ArrowRight",mt=$.key==="ArrowLeft"||$.key==="ArrowUp"?-1:1;let wt;for(const Bt of gt.querySelectorAll(".flow-sdk-node")){if(Bt.closest(".flow-sdk-canvas")!==gt)continue;const it=Bt.getAttribute("data-node-id");if(!it||it===Mt||!He.current.has(it))continue;const vr=Bt.getBoundingClientRect(),Nr=getComputedStyle(Bt);if(!vr.width||!vr.height||Nr.visibility==="hidden"||Nr.opacity==="0")continue;const pr=dt.getNodeBox(it);if(!pr)continue;const mn=pr.x-Tt.x,bn=pr.y-Tt.y;if((yt?mn:bn)*mt<=.01)continue;const Zr=Math.hypot(mn,bn);(!wt||Zr<wt.distance)&&(wt={id:it,box:pr,distance:Zr})}if($.preventDefault(),$.stopPropagation(),!wt)return;Le.current&&(C(null),(xe=y.onEdgeDeselect)==null||xe.call(y)),w([wt.id]),(_e=y.onNodeSelect)==null||_e.call(y,wt.id,He.current.get(wt.id).data,{shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1,keyboardNavigation:!0});const rr=dt.pan(),nr=dt.zoom();dt.pan({x:rr.x+(jt.x-wt.box.x)*nr,y:rr.y+(jt.y-wt.box.y)*nr},!0);return}if(($.key==="z"||$.key==="Z")&&I(!Ie.current),($.key==="m"||$.key==="M")&&k(!M),($.key==="d"||$.key==="D")&&N(!_),($.key==="v"||$.key==="V")&&!$.repeat&&!$.metaKey&&!$.ctrlKey&&!$.altKey&&se.tagName!=="SELECT"&&W(!O),($.key==="Delete"||$.key==="Backspace")&&Le.current){$.preventDefault();const ze=Le.current;(Re=y.onEdgeDelete)==null||Re.call(y,ze,((Te=ft.current.get(ze))==null?void 0:Te.data)??{id:ze}),C(null);return}if(($.key==="Delete"||$.key==="Backspace")&&Ee.current.length>0){$.preventDefault();const ze=Ee.current.filter(dt=>dt!=="root");if(ze.length===0)return;for(const dt of ze){const gt=(Ze=He.current.get(dt))==null?void 0:Ze.data;(Qe=y.onNodeDelete)==null||Qe.call(y,dt,gt||{})}w([])}}};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[M,_,O,W,I,k,N,b.disableKeyboardShortcuts,y,w,C]);const At=j.useCallback(F=>{var $;g.current=F,K(F),($=y.onInit)==null||$.call(y,F)},[g,y]),Lt=j.useCallback(F=>{var $;return($=y.onViewportChange)==null?void 0:$.call(y,F)},[y]),rt=j.useCallback(F=>{var se,xe,_e;const $=((se=ft.current.get(F))==null?void 0:se.data)??{id:F};if(Le.current===F&&at.current){C(null),(xe=y.onEdgeDeselect)==null||xe.call(y);return}Ee.current.length&&w([]),C(F),(_e=y.onEdgeSelect)==null||_e.call(y,F,$)},[y,C,w]),We=j.useCallback(()=>{var F,$,se,xe,_e,Te;if((F=Y.current)==null||F.focus({preventScroll:!0}),a(b.bottomBarCollapsed??(Ee.current.length>0||!!Le.current||!s)),($=y.onBackgroundClick)==null||$.call(y),!ae.current.readOnly){const Re=new Set;for(const Ze of Ee.current){let Qe=He.current.get(Ze);for(;Qe&&!Re.has(Qe.data.id);)Re.add(Qe.data.id),lt.has(Qe.data.id)&&((se=Qe.data.config)==null?void 0:se.collapsed)!==!0&&((xe=y.onNodeCollapse)==null||xe.call(y,Qe.data.id,!0)),Qe=Qe.data.parent?He.current.get(Qe.data.parent):void 0}}Ee.current.length&&(w([]),(_e=y.onNodeDeselect)==null||_e.call(y)),Le.current&&(C(null),(Te=y.onEdgeDeselect)==null||Te.call(y))},[y,w,C,a,s,b.bottomBarCollapsed,lt]);j.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const F=$=>{const se=Y.current,xe=se==null?void 0:se.querySelector(".flow-sdk-canvas"),_e=$.target;$.key!=="Escape"||$.defaultPrevented||$.repeat||$.isComposing||$.ctrlKey||$.metaKey||$.altKey||$.shiftKey||ae.current.readOnly||!Ee.current.length||!se||!xe||!se.getClientRects().length||document.fullscreenElement||xe.querySelector("[data-grid-dragging], .flow-sdk-ghost, .flow-sdk-box")||_e instanceof Element&&(_e.closest('input, textarea, select, [contenteditable], [role="textbox"], [role="combobox"], dialog, [role="dialog"], [role="menu"], [role="listbox"], [popover]')||_e!==document.body&&!se.contains(_e)||_e.closest(".flow-sdk-canvas")&&_e.closest(".flow-sdk-canvas")!==xe)||Array.from(document.querySelectorAll('dialog[open], :popover-open, [role="dialog"], [role="menu"], [role="listbox"]')).some(Te=>Te.getClientRects().length>0&&getComputedStyle(Te).visibility!=="hidden")||($.preventDefault(),$.stopPropagation(),We())};return window.addEventListener("keydown",F,!0),()=>window.removeEventListener("keydown",F,!0)},[b.disableKeyboardShortcuts,We]);const tr=j.useCallback(F=>{var xe,_e;const $=Ee.current,se=F.filter(Te=>!$.includes(Te));if(se.length){w([...$,...se]);for(const Te of se)(_e=y.onNodeSelect)==null||_e.call(y,Te,((xe=He.current.get(Te))==null?void 0:xe.data)??{id:Te})}},[y,w]),pt=j.useCallback((F,$)=>{var se,xe;w([F]),(xe=y.onNodeSelect)==null||xe.call(y,F,((se=He.current.get(F))==null?void 0:se.data)??{id:F},$)},[y,w]),Ft=j.useRef(null),fr=j.useCallback((F,$,se)=>{var xe;Ft.current={source:F,target:$,edgeIds:new Set(ft.current.keys())};try{(xe=y.onEdgeCreate)==null||xe.call(y,F,$,se)}catch(_e){throw Ft.current=null,_e}},[y]),De=j.useCallback((F,$,se,xe=!1)=>{var _e,Te;if(re.current={sourceId:F,nodeIds:new Set(He.current.keys()),reverse:xe},!(u==="properties"&&((_e=y.onNodeCreateRequest)==null?void 0:_e.call(y,{sourceNodeId:F,position:$,sourceProperty:se,reverse:xe}))===!0)){if(se!==void 0||xe){re.current=null;return}(Te=y.onNodeCreate)==null||Te.call(y,{type:"text",sourceNodeId:F,position:$,isArrayMode:et.current})}},[y,u]),Kt=!b.readOnly&&O&&b.edgeHandles!==!1,zt=i==="transparent"?"none":i;return f.jsx(kE,{pattern:zt,backgroundColor:ue,children:f.jsx(D.Box,{ref:Y,tabIndex:0,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:f.jsx(lE,{nodes:Ae,edges:Ue,direction:pe,nodeAlignment:d,onContainerCollapse:F=>{var $,se;($=y.onNodeCollapse)==null||$.call(y,F,!0),(se=y.onNodeViewToggle)==null||se.call(y,F)},selectedNodeIds:x,edgeMode:u,compactPropertyLayout:h,edgeType:b.edgeType,edgeRadius:o,customEdgeTypes:b.customEdgeTypes,edgeReveal:b.disableAnimations?void 0:b.edgeReveal,rankSep:q,edgeSep:ne,nodeGridSpacing:b.nodeGridSpacing,nodeGridConnections:b.nodeGridConnections,initialNodeGrid:b.nodeGrid,spacingFactor:z,compactSpacingScale:n,layoutDebounce:ie,isPerformanceMode:G,minZoom:b.minZoom??.01,maxZoom:b.maxZoom??1.5,initialViewport:te,fixedNodePositions:b.fixedNodePositions,onFixedNodePositionsChange:y.onFixedNodePositionsChange,fitOnInit:!b.initialViewport&&!((hr=b.nodeGrid)!=null&&hr.enabled&&b.nodeGrid.options.fill),readOnly:!!b.readOnly,containerStyle:tt,lineColor:c?U:ce,drawMode:Kt,drawHandles:!b.readOnly&&b.edgeHandles!==!1,dragMode:_,multiSelect:!!M,onInit:At,onLayoutComplete:F=>{var Te;(Te=y.onLayoutComplete)==null||Te.call(y,F);const $=Ft.current;$&&(!He.current.has($.source)||!He.current.has($.target)?Ft.current=null:r.some(({data:Re})=>Re.source===$.source&&Re.target===$.target&&!$.edgeIds.has(Re.id))&&F.getNodeBox($.source)&&F.getNodeBox($.target)&&(Ft.current=null,F.focusConnections($.source)));const se=re.current;if(!se)return;if(!He.current.has(se.sourceId)){re.current=null;return}const _e=e.filter(Re=>!se.nodeIds.has(Re.data.id)).filter(Re=>r.some(({data:Ze})=>Ze.source===se.sourceId&&Ze.target===Re.data.id||Ze.target===se.sourceId&&Ze.source===Re.data.id));!_e.length||_e.some(Re=>!F.getNodeBox(Re.data.id))||(re.current=null,F.focusBranch(se.reverse?_e[0].data.id:se.sourceId))},onNodeGridModeChange:E,onNodeGridZoomOut:y.onNodeGridZoomOut,onNodeGridDrop:y.onNodeGridDrop,onNodeParentChange:y.onNodeParentChange,animateViewport:b.animateViewport,disableAnimations:b.disableAnimations,onViewportChange:Lt,onBackgroundTap:We,onBoxSelect:tr,onEdgeSelect:rt,onContainerSelect:pt,onEdgeDraw:fr,onDrawIntoSpace:De})})})},mv=j.memo(AE),RE=".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 Nm=!1;function ME(){if(Nm||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=RE+".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}"+Kb+a1+o1+".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}',Nm=!0}function TE({loading:e=!1,loader:r,...t}){var c,l;const[n,o]=j.useState(null),i=j.useMemo(()=>!!(n!=null&&n.json)&&!!t.json&&e1(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(D.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(IE,{...s?n:t,children:t.children,config:t.config,className:void 0,style:void 0})}),a&&r!==null&&f.jsx(D.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 IE({title:e="untitled",json:r,forms:t,nodes:n,edges:o,config:i={},callbacks:s={},className:a,style:c,showBottomBar:l=!0,children:d}){ME();const[u,h]=j.useState(),[p,m]=j.useState(!1),g=i.formSchema??u,y=j.useMemo(()=>r&&t?kb(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?t1(M,_,k)??Ed(_,{title:e,isCenter:b}):Ed(_,{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?Pb(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 he,K,re,G;const _=r?(he=$e(r,k.data.id))==null?void 0:he.$view:(K=k.data.config)==null?void 0:K.typeView,N=_&&zd.includes(_)?_:void 0,O=N?N==="icon-label":(re=k.data.config)==null?void 0:re.labelBelow,W=N==="object"?"objectView":N==="text"?"text":O?"arrayView":k.data.type,T=C&&(t?Hn(S,k.data.id,C):r&&un(r,k.data.id,C)),Y=(((G=k.data.config)==null?void 0:G.ports)??[]).map(ne=>({...ne}));if(v&&T){const ne=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,z]of Object.entries(T.type.ports??{})){const H=`${z.kind}:${q}`,V=Y.find(le=>le.id===H);V?V.label===void 0&&z.label!==void 0&&(V.label=z.label):Y.push({id:H,...z.label!==void 0?{label:z.label}:{},role:z.kind==="input"||z.kind==="config"?"target":"source",side:ne[z.kind],...z.kind==="config"?{placement:"config"}:{}})}for(const q of Y){const z=Y.filter(H=>H.side===q.side);q.position=(z.indexOf(q)+1)/(z.length+1)}}return T||O||N?{...k,data:{...k.data,type:W,...t?{description:Object.fromEntries(Object.entries(k.data.description??{}).filter(([ne])=>!ne.startsWith("$")&&!(v!=null&&v.slots.has(En(k.data.id,ne)))))}:{},config:{...k.data.config,...v&&T?{ports:Y}:{},...T?{form:!0}:{},...N?{typeView:N,labelBelow:!!O}:O?{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]),A=j.useMemo(()=>{const M=r&&w?Ub(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[_]=(O,...W)=>{if(!k.has(O))return N==null?void 0:N(O,...W)}}}return{...M,onAllNodesIconLabelChange:k=>{var _;m(k),(_=M.onAllNodesIconLabelChange)==null||_.call(M,k)}}},[r,w,s,g,v]),I=j.useMemo(()=>{if(!t)return A;let M=t.state;const k=N=>{if(i.readOnly||i.editable===!1)return;const O=t.onStateChange??t.onChange;if(!O)return;const W=Lw(M,N,s.onFormChange);W!==M&&(M=W,O(W,{...N,data:W}))},_=(N,O,W)=>{var Y;const T=r&&((Y=$e(r,N))==null?void 0:Y[O]);return!T||typeof T.$state!="string"?!1:(k({address:T.$state,nodeAddress:N,previousValue:$e(M,T.$state),value:W,data:M}),!0)};return{...A,onFormChange:k,onNodeCreateRequest:N=>{var T,Y;const O=(T=N.sourceProperty)!=null&&T.startsWith("config:")?N.sourceProperty.slice(7):void 0,W=O!==void 0&&(v==null?void 0:v.slots.get(En(N.sourceNodeId,O)));return W?(W.present||k({data:M,nodeAddress:W.address.split(".").slice(0,-1).join("."),address:W.address,value:_n(W.type),previousValue:void 0}),!0):((Y=A.onNodeCreateRequest)==null?void 0:Y.call(A,N))??!1},onNodeDelete:(N,O)=>{var re,G;if(!(v!=null&&v.nodes.some(ne=>ne.data.id===N)))return(re=A.onNodeDelete)==null?void 0:re.call(A,N,O);const W=v&&[...v.slots.values()].find(ne=>ne.nodeId===N);if(!W)return(G=A.onNodeDelete)==null?void 0:G.call(A,N,O);const T=W.address.split("."),Y=T.pop(),he=T.join("."),K=$e(M,he);k(Array.isArray(K)?{data:M,nodeAddress:he,address:he,previousValue:K,value:K.filter((ne,q)=>String(q)!==Y)}:{data:M,nodeAddress:he,address:W.address,previousValue:$e(M,W.address),value:void 0})},onEdgeCreate:(N,O,W)=>{var he,K;const T=((he=W==null?void 0:W.targetProperty)==null?void 0:he.startsWith("config:"))&&(v==null?void 0:v.slots.get(En(O,W.targetProperty.slice(7)))),Y=v==null?void 0:v.containers.get(N);if(T&&Y&&(W==null?void 0:W.sourceProperty)==="output:resource"){const re=Vw(M,Y,T);re!==void 0&&k({data:M,nodeAddress:T.address.split(".").slice(0,-1).join("."),address:T.address,previousValue:$e(M,T.address),value:re});return}T||v!=null&&v.nodes.some(re=>re.data.id===N||re.data.id===O)||(K=A.onEdgeCreate)==null||K.call(A,N,O,W)},onEdgeDelete:(N,O)=>{var G;const W=v==null?void 0:v.edges.find(ne=>ne.data.id===N);if(!W)return(G=A.onEdgeDelete)==null?void 0:G.call(A,N,O);const T=v.slots.get(En(W.data.target,W.data.targetProperty.slice(7))),Y=T.address.split("."),he=Y.pop(),K=Y.join("."),re=$e(M,K);k(Array.isArray(re)?{data:M,nodeAddress:K,address:K,previousValue:re,value:re.filter((ne,q)=>String(q)!==he)}:{data:M,nodeAddress:K,address:T.address,previousValue:$e(M,T.address),value:void 0})},onNodeContentChange:(N,O)=>{var W,T;_(N,"$content",O)?(W=s.onNodeContentChange)==null||W.call(s,N,O):(T=A.onNodeContentChange)==null||T.call(A,N,O)},onNodeLabelChange:(N,O)=>{var W,T;_(N,"$label",O)?(W=s.onNodeLabelChange)==null||W.call(s,N,O):(T=A.onNodeLabelChange)==null||T.call(A,N,O)}}},[A,t,r,s,v,i.readOnly,i.editable]);return f.jsx(qt.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(xb,{config:v?{...i,formSchema:C}:i,callbacks:I,nodes:E,edges:R,children:f.jsxs(D.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(mv,{nodes:E,edges:R}),l&&f.jsx(Db,{}),d]})})})}function NE(e){return Id(JSON.parse(e))}function Id(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 OE(e){return{replaceJson(r){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const t=Id(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=Id(r);return e.onStateChange(t,{address:"root",nodeAddress:"root",previousValue:e.state,value:t,data:t}),t}}}function $E(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 qE(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 LE({nodeAddress:e,expanded:r=!1}){var l;const{data:t,schema:n,bindings:o}=j.useContext(qt),{colorText:i,background:s}=st();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=$e(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:Vt(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=Db;exports.CollapseAllToggle=wb;exports.CompactPropertyLayoutToggle=Cb;exports.ConnectionsOnlyToggle=Qw;exports.ContentFullscreenButton=dv;exports.DEFAULT_PALETTE=po;exports.DiagramAppearanceControls=Sb;exports.DynamicIcon=dr;exports.EdgeTools=Nb;exports.EditableLabel=cn;exports.ErrorToast=zb;exports.FlowDiagram=TE;exports.FlowDiagramProvider=xb;exports.FlowPort=lv;exports.FlowView=mv;exports.FormDocumentContext=qt;exports.GridAdjustmentToggle=jb;exports.LIGHT_BLACK=ln;exports.LoadingBorder=bu;exports.NODE_TYPE_VIEWS=zd;exports.NodeBorderRadiusControl=Ob;exports.NodeConfigSummary=LE;exports.NodeForm=Hd;exports.NodeFormPopover=ko;exports.NodeGridControls=so;exports.NodeIconPicker=Ud;exports.NodeTools=$b;exports.NodeView=Qn;exports.PanelDragHandle=vb;exports.SvgExportButton=Fb;exports.Swatches=Gr;exports.TEXT_PALETTE=Tb;exports.ToolbarCloseButton=dn;exports.ToolbarCommitInput=kr;exports.ToolbarDivider=Nn;exports.ToolbarIconButton=Oe;exports.ToolbarRangeInput=Bd;exports.ToolbarScrollContainer=Po;exports.ToolbarSelect=Nt;exports.ToolbarTooltip=Ge;exports.TooltipIconButton=Td;exports.WorkflowControls=Kd;exports.addChild=Ld;exports.addConnection=Fd;exports.addTargetEdge=fb;exports.addressToPath=Zt;exports.applyCollapsed=jw;exports.applyFormChange=_o;exports.applyStateEdits=qw;exports.bindSqueedCallbacks=Ub;exports.compileSqueed=Ed;exports.connectionIssue=Vd;exports.contentObjTheme=lr;exports.copySelection=Jd;exports.createFlowDiagram=Wr;exports.createFlowDocumentActions=OE;exports.createFormNode=Vb;exports.createJsonPlayback=qE;exports.createJsonStream=lo;exports.createWorkflowExecution=Rw;exports.downloadSvg=Lb;exports.duplicateSelection=Hb;exports.exportSvg=qb;exports.formValueError=Xt;exports.formatTimeAgo=pb;exports.getChakraColorHex=Me;exports.getColorVariant=gb;exports.getDarkerHexColor=fo;exports.getInteractionSurface=mr;exports.getNode=$e;exports.getSelectionRoots=Gb;exports.isNodeVisible=cr;exports.parseFlowDocument=NE;exports.parseJsonContract=Dd;exports.parseTypeScriptContract=Eb;exports.parseTypeScriptForm=Wd;exports.projectJsonPlaybackPreview=$E;exports.readFormSchema=Gd;exports.readWorkflowContract=_b;exports.removeEdge=hb;exports.removeNode=ub;exports.reparentNode=r1;exports.resolveEdgeOwner=Br;exports.resolveStateView=kb;exports.setCollapsed=uo;exports.setEdgeProp=Er;exports.setEdgeStyle=db;exports.setNodeProp=Et;exports.stampNodeEdit=lb;exports.updateNode=Rt;exports.useCustomColors=st;exports.useEdgeProximity=So;exports.useFlowData=Qt;exports.useFlowDiagramContext=Ve;exports.useNodeViewActions=eo;exports.useStopPropagation=mu;exports.useThemeContentColors=Gn;exports.validateGridAdjustment=iv;
|
|
283
|
+
@media(prefers-reduced-motion:reduce){[data-flow-loading-border][data-flow-loading-border] .flow-sdk-node-border-animation{animation:none!important}}`;function bu({active:e=!0,label:r="Loading content",radius:t}){const{config:n,themeColor:o}=Ge(),{colorText:i}=lt(),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=Ie(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:uE}),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 fE({nodeId:e}){var M,k;const{nodeById:r}=tr(),{callbacks:t,config:n,readOnly:o,colorMode:i,isPerformanceMode:s}=Ge(),{background:a,border:c,colorInactive:l,colorText:d}=lt(),u=[...r.values()].filter(({data:_})=>{var $,N,W,T,Q;return _.type!=="grid"&&!(($=_.config)!=null&&$.parentContainer)&&(((N=_.config)==null?void 0:N.contentFormat)==="html"||((W=_.config)==null?void 0:W.contentFormat)==="jsx")&&(typeof((T=_.config)==null?void 0:T.content)=="string"||Array.isArray((Q=_.config)==null?void 0:Q.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),A=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 $=_.animate({transform:[`translateX(${w.current*100}%)`,"translateX(0)"]},{duration:240,easing:"ease-out",id:"flow-content-slide"});return()=>$.cancel()},[v==null?void 0:v.data.id,n.disableAnimations,s]);const I=_=>{const $=u[C+_];!$||m||(w.current=_,p($.data.id))};return v?f.jsxs(D.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(D.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(Po,{background:a,border:i==="dark"?c:"gray.300",children:f.jsxs(D.HStack,{px:2,gap:2,width:"max-content",height:"100%",children:[f.jsx(He,{label:"Previous content",children:f.jsx(Oe,{"data-flow-content-navigation":"","aria-label":"Previous content",icon:f.jsx(X.PiCaretLeft,{size:20}),disabled:C<=0||m,onClick:()=>I(-1),rememberAction:!1,size:"sm",variant:"ghost"})}),f.jsxs(D.Text,{"aria-live":"polite",fontSize:"12px",minW:"42px",textAlign:"center",children:[C+1," / ",u.length]}),f.jsx(He,{label:"Next content",children:f.jsx(Oe,{"data-flow-content-navigation":"","aria-label":"Next content",icon:f.jsx(X.PiCaretRight,{size:20}),disabled:C>=u.length-1||m,onClick:()=>I(1),rememberAction:!1,size:"sm",variant:"ghost"})}),["width","height"].map(_=>f.jsxs(D.Box,{as:"label",display:"flex",alignItems:"center",gap:1,fontSize:"12px",opacity:S?1:.5,children:[_==="width"?"W":"H",f.jsx(kr,{value:_==="width"?R:A,placeholder:"Auto",ariaLabel:`Content ${_}`,type:"number",min:1,width:"72px",disabled:!S||!t.onNodeDimensionChange||m,onCommit:$=>{var N;S&&((N=t.onNodeDimensionChange)==null||N.call(t,v.data.id,_,$===""?void 0:Number($)))}})]},`${v.data.id}:${_}`)),S&&!m&&f.jsx(He,{label:"Edit content source",children:f.jsx(Oe,{"aria-label":"Edit content source",icon:f.jsx(X.PiCode,{size:20}),onClick:()=>g(!0),rememberAction:!1,size:"sm",variant:"ghost",color:l})})]})})}),f.jsx(D.Box,{flex:1,minH:0,overflow:"auto",position:"relative","data-content-slide-viewport":"",children:f.jsx(D.Box,{ref:x,"data-content-slide":v.data.id,width:R?`${R}px`:"100%",height:A?`${A}px`:"100%",minH:A?void 0:"100%",mx:"auto",overflow:"auto",children:f.jsx(xu,{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(D.Box,{role:"status",p:4,children:"No HTML or JSX content available."})}const uv=j.forwardRef(function({fullscreen:r,onClick:t},n){const{colorInactive:o}=lt();return f.jsx(Oe,{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(X.PiArrowsIn,{size:20}):f.jsx(X.PiArrowsOut,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:o,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:t})});function hE({content:e,format:r,onEdit:t,autoHeight:n=!1,nodeId:o,controls:i=!0}){var G,se,U,Y,le;const{config:s,colorMode:a}=Ge(),{nodeById:c}=tr(),l=o?(se=(G=c.get(o))==null?void 0:G.data.viewProps)==null?void 0:se.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}=lt(),m=(U=s.customViews)==null?void 0:U.jsxContent,g=typeof e=="string"?e:JSON.stringify(e,null,2);let y,b=r==="jsx"&&o?(le=(Y=c.get(o))==null?void 0:Y.data.config)==null?void 0:le.contentReferenceError:void 0;const x=typeof e=="string"?e.trim().length>0:e!=null;if(r==="jsx"&&!b&&x)try{const ne=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(ne)||ne.some(de=>!de||typeof de!="object"||Array.isArray(de)||typeof de.type!="string"))throw new Error("JSX content must be an array of components with a type.");y=ne}catch(ne){b=ne instanceof Error?ne.message:"Invalid components array."}const w=j.useRef(null),v=j.useRef(null),C=j.useRef(null),S=j.useRef(!1),[E,R]=j.useState(!1),A=j.useRef(null),I=So({edge:"top",enabled:E,bounds:A,inside:[A],threshold:90}),[M,k]=j.useState(""),[_,$]=j.useState(),N=!!t;j.useEffect(()=>{const ne=()=>{var xe;const de=document.fullscreenElement===v.current;R(de),S.current&&!de&&!document.fullscreenElement&&((xe=C.current)==null||xe.focus({preventScroll:!0})),S.current=de};return document.addEventListener("fullscreenchange",ne),()=>document.removeEventListener("fullscreenchange",ne)},[]);const W=async()=>{var ne;k("");try{if(document.fullscreenElement===v.current)await document.exitFullscreen();else if((ne=v.current)!=null&&ne.requestFullscreen)await v.current.requestFullscreen();else throw new Error("Fullscreen is not supported in this browser.")}catch(de){k(de instanceof Error?de.message:"Unable to change fullscreen.")}},[T,Q]=j.useState(),[ue,K]=j.useState(),[ce,V]=j.useState();j.useEffect(()=>{if(r==="jsx")return;let ne=!1;return Promise.resolve().then(()=>require("./contentPreviewDocument-26_hwvOv.cjs")).then(({contentPreviewDocument:de})=>de(g,r,N,n)).then(de=>{ne||Q({content:g,format:r,editable:N,autoHeight:n,document:de})},de=>{ne||Q({content:g,format:r,editable:N,autoHeight:n,error:de instanceof Error?de.message:String(de)})}),()=>{ne=!0}},[g,r,N,n]),j.useEffect(()=>{if(!t)return;const ne=async de=>{var xe,he;if(!(!((xe=w.current)!=null&&xe.contentWindow)||de.source!==w.current.contentWindow||((he=de.data)==null?void 0:he.type)!=="squeed:content-edit"))try{document.fullscreenElement===v.current&&await document.exitFullscreen(),t()}catch(H){k(H instanceof Error?H.message:"Unable to close fullscreen.")}};return window.addEventListener("message",ne),()=>window.removeEventListener("message",ne)},[t]);const re=(T==null?void 0:T.content)===g&&T.format===r&&T.editable===N&&T.autoHeight===n?T:void 0;j.useEffect(()=>{if(!n||r!=="html"||!(re!=null&&re.document))return;const ne=re.document,de=xe=>{var H,J,fe;const he=(H=xe.data)==null?void 0:H.height;!((J=w.current)!=null&&J.contentWindow)||xe.source!==w.current.contentWindow||((fe=xe.data)==null?void 0:fe.type)!=="squeed:content-size"||typeof he!="number"||!Number.isFinite(he)||he<=0||he>1e5||document.fullscreenElement===v.current||$(ve=>(ve==null?void 0:ve.document)===ne&&ve.height===he?ve:{document:ne,height:he})};return window.addEventListener("message",de),()=>window.removeEventListener("message",de)},[n,r,re==null?void 0:re.document]);const q=!!re&&re===ce,F=r!=="jsx"&&!(re!=null&&re.error)&&!q&&(!re||ue!==re);return f.jsxs("div",{"data-flow-content-preview":"",style:{width:"100%",height:i?d??(n?r==="jsx"?"auto":(_==null?void 0:_.document)===(re==null?void 0:re.document)?_==null?void 0:_.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(D.Box,{ref:v,position:"relative",w:"100%",h:n&&r==="jsx"?"auto":"100%","aria-busy":!E&&r!=="jsx"?F:void 0,bg:r==="jsx"&&a==="dark"?"gray.900":"white",onDoubleClick:ne=>{r!=="jsx"||!t||ne.defaultPrevented||ne.target.closest('button, a, input, textarea, select, [contenteditable], [role="button"], [role="textbox"]')||(ne.stopPropagation(),(async()=>{document.fullscreenElement===v.current&&await document.exitFullscreen(),t()})().catch(de=>k(String(de))))},onKeyDownCapture:ne=>{ne.key!=="Escape"||document.fullscreenElement!==v.current||ne.target instanceof Element&&ne.target.closest('input, textarea, select, [contenteditable="true"]')||(ne.preventDefault(),ne.stopPropagation(),W())},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(D.Box,{ref:A,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:E?1:0,pointerEvents:E?"auto":"none",css:E?{"@media (hover: hover) and (pointer: fine)":{opacity:I?1:0},"&:hover, &:focus-within":{opacity:1}}:void 0,children:f.jsx(Po,{background:u,border:a==="dark"?h:"gray.300",children:f.jsxs(D.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&&(!E||!o)&&f.jsx(Oe,{"data-flow-content-edit":"","aria-label":"Edit content source",title:"Edit content source",icon:f.jsx(X.PiCode,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:p,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:ne=>{ne.stopPropagation(),(async()=>{document.fullscreenElement===v.current&&await document.exitFullscreen(),t()})().catch(de=>k(String(de)))}}),f.jsx(uv,{ref:C,fullscreen:E,onClick:ne=>{ne.stopPropagation(),W()}})]})})}),M&&f.jsx(D.Box,{role:"alert",position:"absolute",bottom:0,insetInline:0,bg:"white",color:"red.700",fontSize:"14px",children:M}),E&&o?f.jsx(fE,{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||E}):x?f.jsx(D.Box,{role:"status",fontSize:"14px",children:"JSX content renderer is not available."}):null:re!=null&&re.error||q?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:(re==null?void 0:re.error)||"Content preview could not be loaded."}):re!=null&&re.document?f.jsx("iframe",{ref:w,title:`${r.toUpperCase()} content preview`,sandbox:N||n?"allow-scripts":"",allowFullScreen:!0,referrerPolicy:"no-referrer",srcDoc:re.document,onLoad:()=>K(re),onError:()=>V(re),style:{width:"100%",height:"100%",border:0,display:"block",background:"white",visibility:F?"hidden":"visible"}},re.document):null,f.jsx(bu,{active:!E&&F,label:"Loading HTML content"})]})]})}const Tm=1.55;function xu({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 K,ce;const{callbacks:m,config:g,readOnly:y,nodeGridOptions:b}=Ge(),x=!!g.editable&&!y,w=x&&(!b||o&&b.fill&&n==="markdown"),{nodeById:v}=tr(),C=n==="jsx"&&!d?((ce=(K=v.get(e))==null?void 0:K.data.config)==null?void 0:ce.contentSource)??r:r,S=typeof C=="string"?C:JSON.stringify(C,null,2),[E,R]=j.useState(a&&x),[A,I]=j.useState(S),[M,k]=j.useState(""),[_,$]=j.useState(),N=j.useRef(null),W=j.useRef(!1),T=mu(E);j.useLayoutEffect(()=>{const V=N.current;!E||!V||(V.style.height="auto",V.style.height=`${Math.max((_==null?void 0:_.height)??0,V.scrollHeight)}px`)},[A,E,_]),j.useEffect(()=>{var V,re;x?E&&(W.current=!1,(V=N.current)==null||V.focus({preventScroll:!0}),(re=N.current)==null||re.select()):(R(!1),p==null||p(void 0))},[E,x,p]);const Q=(V,re=!1)=>{!x||b&&!w&&!re||($({width:V.offsetWidth,height:V.offsetHeight}),I(S),p==null||p(S),k(""),R(!0))},ue=()=>{var re;if(W.current||!x)return;let V=A;if(n==="jsx")try{if(V=JSON.parse(A),!Array.isArray(V)||V.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}W.current=!0,A!==S&&(d?d(V):(re=m.onNodeContentChange)==null||re.call(m,e,V)),R(!1),u==null||u()};return(!E||!x)&&n!=="markdown"?f.jsx(D.Box,{ref:T,w:"100%",h:!s&&!i?"100%":void 0,position:"relative","data-flow-content":"",children:f.jsx(hE,{nodeId:e,content:r,format:n,controls:s,autoHeight:i&&!(b!=null&&b.fill),onEdit:w?()=>{T.current&&Q(T.current)}:void 0})}):!E||!x?f.jsx(D.Box,{"data-flow-content":"",color:t,opacity:r?void 0:.6,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:Tm,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:V=>{!x||b&&!w&&!V.shiftKey||V.target instanceof Element&&V.target.closest("a, button, input")||(V.stopPropagation(),Q(V.currentTarget,V.shiftKey))},onDoubleClick:V=>{V.stopPropagation(),Q(V.currentTarget,V.shiftKey)},onKeyDown:V=>{x&&(w||V.shiftKey)&&V.key==="Enter"&&V.target===V.currentTarget&&(V.preventDefault(),V.stopPropagation(),Q(V.currentTarget,V.shiftKey))},children:c?f.jsx(D.Box,{whiteSpace:"pre-wrap",minH:"100%",children:S||(x?l:"")}):f.jsx($v.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(D.Textarea,{ref:N,"aria-label":"Node content",placeholder:l,value:A,"aria-invalid":!!M,onChange:V=>{I(V.target.value),p==null||p(V.target.value)},onPaste:V=>{c&&V.clipboardData.files.length&&(V.preventDefault(),V.stopPropagation())},onDrop:V=>{c&&(V.stopPropagation(),V.dataTransfer.files.length&&V.preventDefault())},onBlur:ue,onKeyDown:V=>{if(V.stopPropagation(),!V.nativeEvent.isComposing){if(h&&n==="markdown"&&V.key==="Enter"&&!V.shiftKey&&!V.ctrlKey&&!V.metaKey&&!V.altKey){V.preventDefault(),!V.repeat&&!W.current&&A.trim()&&(Vr.flushSync(ue),h(A));return}V.key==="Enter"&&(V.ctrlKey||V.metaKey)&&(V.preventDefault(),ue()),V.key==="Escape"&&(W.current=!0,R(!1),p==null||p(void 0),u==null||u())}},color:t,fontFamily:"inherit",fontSize:"inherit",lineHeight:Tm,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(D.Box,{role:"alert",fontSize:"14px",color:"red.500",children:M})]})}function pE({edited:e,relative:r,helpText:t,fontSize:n}){return!r||!e.name?null:f.jsxs(D.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 Im({data:e,caption:r=!1}){var l,d,u,h,p;const{colorText:t}=lt(),n=typeof((l=e.config)==null?void 0:l.subtitle)=="string"?e.config.subtitle:"",o=(d=e.config)==null?void 0:d.edited,i=Rw(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(D.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(pE,{edited:o,relative:i,helpText:c,fontSize:a}),n&&f.jsx(D.Text,{"data-flow-node-subtitle":"",fontSize:a,lineHeight:1.3,whiteSpace:"pre-line",title:c,children:n})]})}const gE=({data:e,children:r,isInverted:t,isParent:n,onOpenView:o,editOnMount:i=!1,hoverLeaveDelay:s=0})=>{var he,H,J,fe,ve,Re,Je,st,Ye,We,Ze;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}=Ge(),{background:v,border:C,colorText:S}=lt(),E=j.useRef(null),R=j.useRef(null);j.useEffect(()=>()=>{R.current&&clearTimeout(R.current)},[]);const[A,I]=j.useState(!1),[M,k]=j.useState(i&&!!y.editable&&!y.readOnly),[_,$]=j.useState(!1),N=e==null?void 0:e.id,W=Mb(N),T=a.includes(N);j.useEffect(()=>{if(!T||a.length!==1||y.readOnly||M||_)return;const me=Ae=>{var Ne,Qe,Ee,Le,ct;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(Ue=>Ue.getClientRects().length&&getComputedStyle(Ue).visibility!=="hidden"))return;const oe=Array.from(((Ne=E.current)==null?void 0:Ne.querySelectorAll("[data-flow-content-toggle] button, button[data-flow-collapse-control]"))??[]).find(Ue=>{var ht;return((ht=Ue.closest("[data-node-id]"))==null?void 0:ht.getAttribute("data-node-id"))===N&&!Ue.disabled&&Ue.getClientRects().length&&getComputedStyle(Ue).visibility!=="hidden"}),ie=!oe&&(e==null?void 0:e.type)==="grid"&&((Qe=e.config)==null?void 0:Qe.documentId)&&((Ee=E.current)==null?void 0:Ee.getClientRects().length)&&g.onNodeHoverAction&&((Le=y.nodeOverlayActions)==null?void 0:Le.find(Ue=>Ue.id==="open-document"&&(!Ue.nodeTypes||Ue.nodeTypes.includes(e.type))));!oe&&!ie||(Ae.preventDefault(),Ae.stopPropagation(),Ae.repeat||(oe?oe.click():(ct=g.onNodeHoverAction)==null||ct.call(g,ie.id,N,e)))};return window.addEventListener("keydown",me,!0),()=>window.removeEventListener("keydown",me,!0)},[N,T,a.length,y.readOnly,M,_,e,g.onNodeHoverAction,y.nodeOverlayActions]);const Q=(he=y.nodeOverlayActions)==null?void 0:he.filter(me=>!me.nodeTypes||me.nodeTypes.includes(e==null?void 0:e.type)),ue=y.renderNodeOverlay,K=(e==null?void 0:e.type)==="grid"?(H=y.customViews)==null?void 0:H.gridHoverControls:void 0,ce=(e==null?void 0:e.type)==="grid"?"20px":"-100px",V=(e==null?void 0:e.type)==="grid"?"top center":void 0,re=(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 Ae=(me=m.current)==null?void 0:me.zoom();return Ae!==void 0&&Ae<.08}catch{return!1}})(),F=j.useCallback((me,Ae=!1)=>{var ie,Ne,Qe,Ee,Le;if(M||y.readOnly||h!=null&&h.fill&&!me.shiftKey||me.detail===2&&((ie=e==null?void 0:e.config)!=null&&ie.form)&&!o&&!Ae&&!u&&!l&&!me.shiftKey&&!me.ctrlKey&&!me.metaKey&&!me.altKey&&a.length===1&&a[0]===N)return;const oe={shiftKey:me.shiftKey,ctrlKey:me.ctrlKey,metaKey:me.metaKey,altKey:me.altKey,...Ae?{viewToggle:!0}:{}};if(l&&(d(null),(Ne=g.onEdgeDeselect)==null||Ne.call(g)),u||me.shiftKey&&(h!=null&&h.fill)){const ct=a.includes(N),Ue=ct?a.filter(ht=>ht!==N):[...a,N];c(Ue),ct?(Qe=g.onNodeDeselect)==null||Qe.call(g):(Ee=g.onNodeSelect)==null||Ee.call(g,N,e,oe)}else c([N]),(Le=g.onNodeSelect)==null||Le.call(g,N,e,oe)},[N,e,a,l,u,h,M,o,c,d,g,y]),G=j.useCallback(()=>{var me;M||y.readOnly||(me=g.onNodeDoubleClick)==null||me.call(g,N,e)},[N,e,M,g,y]),se=j.useCallback(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>I(!0),100)},[]),U=j.useCallback(me=>{var Ae;me.relatedTarget instanceof Node&&((Ae=E.current)!=null&&Ae.contains(me.relatedTarget))||(R.current&&clearTimeout(R.current),s?R.current=setTimeout(()=>I(!1),s):I(!1))},[s]),Y=(e==null?void 0:e.type)==="text"&&!((J=e==null?void 0:e.config)!=null&&J.parentContainer)&&!((fe=e==null?void 0:e.config)!=null&&fe.form),le=!!((ve=e==null?void 0:e.config)!=null&&ve.form)||Y,ne={tabIndex:le?0:void 0,"aria-haspopup":le?"dialog":void 0,"aria-expanded":le?_:void 0,onDoubleClickCapture:me=>{var Ae;!le&&!o||y.readOnly||Y&&!y.editable||M||!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]!==N)&&c([N]),o?o():$(!0),(Ae=g.onNodeDoubleClick)==null||Ae.call(g,N,e))},onKeyDown:me=>{!le&&!o||y.readOnly||Y&&!y.editable||me.target!==me.currentTarget||me.key!=="Enter"||(me.preventDefault(),me.stopPropagation(),c([N]),o?o():$(!0))}},de=le&&f.jsx(ko,{nodeAddress:N,active:T,label:e.label||e.headerTitle||"Node",open:_&&(!Y||!!y.editable&&!y.readOnly),onClose:()=>{var me;$(!1),T&&((me=E.current)==null||me.focus({preventScroll:!0}))},children:Y?f.jsx(xu,{nodeId:N,content:e.label??e.text??"",color:Ie(S),editOnMount:!0,onChange:me=>{var Ae;return(Ae=g.onNodeLabelChange)==null?void 0:Ae.call(g,N,String(me))},onEditEnd:()=>$(!1)}):void 0}),xe=Array.isArray((Re=e==null?void 0:e.config)==null?void 0:Re.ports)?e.config.ports.map(me=>f.jsx(dv,{...me},`${me.id}:${me.role}`)):null;return n?f.jsxs(D.Box,{ref:E,...ne,onClick:F,onDoubleClick:G,onMouseEnter:se,onMouseLeave:U,cursor:"pointer",position:"relative",children:[de,!p&&(ue||Q&&Q.length>0)&&A&&!q&&f.jsxs(f.Fragment,{children:[f.jsx(D.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>I(!0),onMouseLeave:U}),ue?f.jsx(D.Box,{position:"absolute",zIndex:1e3,top:ce,transformOrigin:V,left:"50%",pointerEvents:"auto",transform:re,onMouseEnter:()=>I(!0),onMouseLeave:U,willChange:"transform",children:ue({nodeId:N,nodeData:e,isRoot:N==="root",isParent:!0,isHovered:A,setIsHovered:I})}):f.jsx(D.Box,{position:"absolute",zIndex:1e3,top:ce,transformOrigin:V,left:"50%",bg:v,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:re,boxShadow:"lg",onMouseEnter:()=>I(!0),onMouseLeave:U,willChange:"transform",children:f.jsxs(D.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:[Q.map((me,Ae)=>f.jsxs(D.Box,{display:"contents",children:[Ae>0&&f.jsx(D.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(Td,{icon:me.icon,label:me.label,color:S,bgColor:v,borderColor:C,textColor:S,boxSize:5,onClick:oe=>{var ie;oe.stopPropagation(),(ie=g.onNodeHoverAction)==null||ie.call(g,me.id,N,e)}})]},me.id)),K&&f.jsx(K,{data:e})]})})]}),r({id:N,data:e,isActive:T,isHovered:A,isLowZoom:q,isEditing:M,onSelect:F,onEditStart:()=>k(!0),onEditEnd:()=>k(!1)}),f.jsx(Im,{data:e}),W&&!((Je=e==null?void 0:e.config)!=null&&Je.parentContainer)&&((st=e==null?void 0:e.config)==null?void 0:st.collapsed)!==void 0&&(()=>{var oe;const me=x==="TB"||x==="BT",Ae=t||x==="RL";return f.jsx(D.IconButton,{position:"absolute",...me?{[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:ie=>{var Ne;ie.stopPropagation(),(Ne=g.onNodeCollapse)==null||Ne.call(g,N,!e.config.collapsed)},bgColor:Ie(((oe=e==null?void 0:e.viewProps)==null?void 0:oe.bgColor)||b),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(X.PiPlusBold,{size:30,color:Ie("gray.800")}):f.jsx(X.PiMinusBold,{size:30,color:Ie("gray.800")})})})()]}):f.jsxs(D.Box,{ref:E,...ne,onClick:F,onDoubleClick:G,onMouseEnter:se,onMouseLeave:U,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[de,xe,!p&&(ue||Q&&Q.length>0)&&A&&!q&&f.jsxs(f.Fragment,{children:[f.jsx(D.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>I(!0),onMouseLeave:U}),ue?f.jsx(D.Box,{position:"absolute",zIndex:1e3,top:ce,transformOrigin:V,left:"50%",pointerEvents:"auto",transform:re,onMouseEnter:()=>I(!0),onMouseLeave:U,willChange:"transform",children:ue({nodeId:N,nodeData:e,isRoot:N==="root",isParent:!!n,isHovered:A,setIsHovered:I})}):f.jsx(D.Box,{position:"absolute",zIndex:1e3,top:ce,transformOrigin:V,left:"50%",bg:v,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:re,boxShadow:"lg",onMouseEnter:()=>I(!0),onMouseLeave:U,willChange:"transform",children:f.jsxs(D.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:[Q.map((me,Ae)=>f.jsxs(D.Box,{display:"contents",children:[Ae>0&&f.jsx(D.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(Td,{icon:me.icon,label:me.label,color:S,bgColor:v,borderColor:C,textColor:S,boxSize:5,onClick:oe=>{var ie;oe.stopPropagation(),(ie=g.onNodeHoverAction)==null||ie.call(g,me.id,N,e)}})]},me.id)),K&&f.jsx(K,{data:e})]})})]}),f.jsxs(D.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[W&&!((Ye=e==null?void 0:e.config)!=null&&Ye.parentContainer)&&((We=e==null?void 0:e.config)==null?void 0:We.collapsed)!==void 0&&!n&&(()=>{var ie,Ne,Qe;const me=x==="TB"||x==="BT",Ae=t||x==="RL",oe=(ie=e==null?void 0:e.config)!=null&&ie.labelBelow&&w[N]!=="properties"?((((Ne=e==null?void 0:e.viewProps)==null?void 0:Ne.fontSize)||1)*100+100)/2:void 0;return f.jsx(D.IconButton,{position:"absolute",...me?{[x==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:Ae?void 0:oe===void 0?"-75px":`calc(50% - ${oe+75}px)`,left:Ae?oe===void 0?"-75px":`calc(50% - ${oe+75}px)`:void 0,alignSelf:oe===void 0?"center":void 0,top:oe===void 0?void 0:`${oe}px`,transform:oe===void 0?void 0:"translateY(-50%)",zIndex:oe===void 0?void 0:1},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:y.readOnly,onClick:Ee=>{var Le;Ee.stopPropagation(),(Le=g.onNodeCollapse)==null||Le.call(g,N,!e.config.collapsed)},bgColor:Ie(((Qe=e==null?void 0:e.viewProps)==null?void 0:Qe.bgColor)||b),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(X.PiPlusBold,{size:30,color:Ie("gray.800")}):f.jsx(X.PiMinusBold,{size:30,color:Ie("gray.800")})})})(),r({id:N,data:e,isActive:T,isHovered:A,isLowZoom:q,isEditing:M,onSelect:F,onEditStart:()=>k(!0),onEditEnd:()=>k(!1)})]}),f.jsx(Im,{data:e,caption:!!((Ze=e.config)!=null&&Ze.labelBelow)&&w[N]!=="properties"})]})},Qn=j.memo(gE),yE=({id:e,data:r,isActive:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var g,y,b,x,w,v,C,S;const{themeColor:s}=Ge(),{colorText:a}=lt(),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=Ie(((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(D.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(D.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(D.Box,{flexShrink:0,children:f.jsx(dr,{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 vu(e,r,t){const{readOnly:n,selectedNodeIds:o}=Ge(),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}=Ge();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 mE=({id:e,isActive:r,data:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var w,v,C,S,E,R,A,I,M,k,_,$,N;const{themeColor:s}=Ge(),{colorText:a}=lt(),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=Ie(((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":Ie(((R=t==null?void 0:t.viewProps)==null?void 0:R.borderColor)||(l?d:u)),y=c||l?"transparent":d!=null&&d.startsWith("#")?d:Ie(h),b=(A=t==null?void 0:t.config)==null?void 0:A.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 W=(((M=t==null?void 0:t.viewProps)==null?void 0:M.fontSize)||1)*100;return f.jsxs(D.Flex,{"data-flow-icon-label":"",css:{"--flow-grid-on-surface-color":m},direction:"column",align:"center",gap:"24px",width:`${Math.max(W+200,360)}px`,position:"relative",children:[f.jsx(D.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${W+100}px`,height:`${W+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(dr,{name:b,size:W,color:m})}),f.jsx(D.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, ${Ie(((_=t==null?void 0:t.viewProps)==null?void 0:_.textColor)||a)})`,isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0})})]})}return f.jsxs(D.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:($=t==null?void 0:t.viewProps)==null?void 0:$.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(D.Flex,{align:"center",py:14,mr:x?8:0,flexShrink:0,children:f.jsx(dr,{name:b,size:(((N=t==null?void 0:t.viewProps)==null?void 0:N.fontSize)||1)*100,color:m},m)}),(x||!b)&&f.jsx(D.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=mE,...o}){const{colorMode:i,callbacks:s}=Ge();return f.jsx(Qn,{...o,hoverLeaveDelay:e?350:0,children:a=>f.jsxs(D.Box,{position:"relative",children:[f.jsx(n,{...a}),e&&(a.isHovered||a.isActive)&&f.jsx(D.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:f.jsx(He,{label:r,children:f.jsx(Oe,{"aria-label":r,icon:f.jsx(D.Icon,{as:X.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 fv=(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("#")?Ie(n):Ie(i.bgColor),d=Ie(((m=e==null?void 0:e.viewProps)==null?void 0:m.textColor)||(a?c:i.textColor)),u=Ie(((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}},bE=(e,r=350)=>`${String(e).substring(0,r)}${String(e).length>r?"...":""}`,xE=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,hv=600,vE=3,wE=e=>{const r=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(r*28+30,200)};function CE({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}=Ge();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(D.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(D.Flex,{mr:6,alignItems:"center",flexShrink:0,children:f.jsx(dr,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),f.jsx(cn,{nodeId:s,label:xE(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(D.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:f.jsx(He,{label:w,children:f.jsx(Oe,{"aria-label":w,icon:f.jsx(D.Icon,{as:X.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:R=>{var A;R.stopPropagation(),a||d(R),x?x():g(!m),(A=b.onNodeViewToggle)==null||A.call(b,s)}})})})]})})}function SE({data:e,resourcePorts:r,inspecting:t,form:n,inspectionPorts:o,extraPorts:i,colors:s,direction:a,uniformKeyWidth:c}){const{edgeById:l}=tr(),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(D.Box,{children:Object.entries(e.description||{}).map(([u,h],p)=>{var _,$,N;const m=r&&Object.keys(r).find(W=>W.slice(W.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(W=>W.id===y),x=m?"source":b==null?void 0:b.role,w=d.has(`source:${y}`),v=d.has(`target:${y}`),C=i.some(W=>W.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),A=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=lr(s.wordBeforeDot)[typeof h],k=lr(s.wordBeforeDot).property;return f.jsxs(D.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(D.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[f.jsx(D.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(D.Text,{py:5,px:10,w:"100%",textAlign:A,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:(($=e==null?void 0:e.viewProps)==null?void 0:$.textColor)||(s.isTransparent?s.hextextColor:k),children:I})}),!S&&f.jsx(D.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:s.hexbgColor,w:hv,maxH:200,children:f.jsx(D.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:((N=e==null?void 0:e.viewProps)==null?void 0:N.textColor)||(s.isTransparent?s.hextextColor:M),fontWeight:400,children:bE(h)})})]}),p!==Object.entries(e.description||{}).length-1&&f.jsx(D.Box,{borderTopWidth:1,my:0,borderColor:s.hexborderColor})]},u)})})}function jE(e){var w,v,C,S,E;const{themeColor:r,colorMode:t,direction:n}=Ge(),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(Ft),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&&$e(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 A;return Object.prototype.hasOwnProperty.call(p,R)&&Eo((A=h.fields[R])==null?void 0:A.$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,A])=>{var I;return[R.slice(R.indexOf(":")+1),((I=$e(l,A))==null?void 0:I.name)??A.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(([A,I])=>`${I.kind}:${A}`===R.id&&Object.prototype.hasOwnProperty.call(g,A))),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 Ko=e=>{var w,v,C,S,E,R,A,I;const{config:r}=Ge(),{themeColor:t,colorMode:n,direction:o,objVisible:i,setObjVisible:s,inspecting:a,resourcePorts:c,form:l,description:d,inspectionPorts:u,extraPorts:h}=jE(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),vu(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?((A=e.data.config)==null?void 0:A.contentFormat)==="html"?"PiFileHtml":((I=e.data.config)==null?void 0:I.contentFormat)==="jsx"?"PiFileJsx":"https://squeed.co/squeed.svg":"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:$,isEditing:N,onSelect:W,onEditStart:T,onEditEnd:Q})=>{var Y,le,ne,de,xe,he,H,J,fe,ve,Re,Je,st,Ye,We,Ze,me,Ae,oe;const ue=fv(k,t,n),K=k.label??k.headerTitle,ce=Object.entries(k.description||{}).length>0,V=wE(k.description),re=(le=(Y=e.data)==null?void 0:Y.config)==null?void 0:le.icon,q=(de=(ne=e.data)==null?void 0:ne.config)==null?void 0:de.content,F=g&&!i&&k.label===""&&(((xe=k.config)==null?void 0:xe.contentFormat)==="html"||((he=k.config)==null?void 0:he.contentFormat)==="jsx"),G=g&&!i&&(((H=k.config)==null?void 0:H.contentFormat)==="html"||((J=k.config)==null?void 0:J.contentFormat)==="jsx")&&((fe=k.viewProps)==null?void 0:fe.width)!==void 0&&k.viewProps.width!=="100%",se=((ve=k==null?void 0:k.viewProps)==null?void 0:ve.borderRadius)??"53px",U=Wn(k==null?void 0:k.viewProps,ue.hexborderColor,_,vE);return f.jsx(D.Flex,{justifyContent:"space-between",...k==null?void 0:k.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:se,overflow:"hidden",alignItems:"center",style:{backgroundColor:ue.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:e.contentWidth??(F||G?((Re=k.viewProps)==null?void 0:Re.width)!==void 0&&k.viewProps.width!=="100%"?k.viewProps.width:"max-content":"100%"),maxW:F?"calc(100vw - 40px)":void 0,height:e.contentHeight??((Je=k.viewProps)==null?void 0:Je.height),minW:e.contentMinWidth??(e.contentWidth||F||G?0:g||e.onShowIcon?V+hv+U.borderWidth*2:void 0),...U,children:f.jsxs(D.Flex,{width:"100%",height:e.contentHeight!==void 0?"100%":void 0,minH:e.contentHeight!==void 0?0:void 0,direction:"column",position:"relative",borderRadius:se,borderColor:ue.hexborderColor,borderWidth:0,overflow:"hidden",children:[e.surfaceOverlay,!e.fillBody&&f.jsx(CE,{headerTitle:K,hasContent:g,data:k,icon:re,colors:ue,hasConfig:ce,id:M,isActive:_,isHovered:$,isEditing:N,onSelect:W,onEditStart:T,onEditEnd:Q,props:e,objVisible:i,setObjVisible:s,onShowNativeIcon:x}),e.headerOverlay,g&&!i?f.jsx(D.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:ue.highlightColor,p:["html","jsx"].includes((Ye=(st=e.data)==null?void 0:st.config)==null?void 0:Ye.contentFormat)?0:12,fontSize:"5xl",lineHeight:"normal",...e.contentProps,children:f.jsx(xu,{nodeId:M,content:q,format:(Ze=(We=e.data)==null?void 0:We.config)==null?void 0:Ze.contentFormat,fillBody:e.fillBody,autoHeight:F,color:((me=k==null?void 0:k.viewProps)==null?void 0:me.textColor)||ue.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))??((oe=e.data.config)!=null&&oe.promptTurn?"Thinking...":void 0)})}):f.jsx(SE,{data:k,resourcePorts:c,inspecting:a,form:l,inspectionPorts:u,extraPorts:h,colors:ue,direction:o,uniformKeyWidth:V}),e.footer]})})}})};Ko.displayName="NodeJsonObjectView";const pv=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}=Ge(),c=(p=(h=e.data)==null?void 0:h.config)==null?void 0:p.parentContainer;vu(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(Ko,{...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 EE(e){var b,x,w,v,C,S;const{config:r,callbacks:t,readOnly:n,selectedNodeIds:o,nodeRadiusPreviews:i,nodeViewModes:s,allNodesIconLabel:a}=Ge(),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}=lt(),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),vu(e.data.id,a&&!g&&y.current,()=>u.setNodeViewMode(e.data.id,"icon-label")),g?f.jsx(D.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 A,I,M,k,_,$,N,W;return f.jsx(D.Box,{"data-flow-node-surface":"","data-grid-document":((A=E.config)==null?void 0:A.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:(($=E.viewProps)==null?void 0:$.bgColor)??"transparent",color:((N=E.viewProps)==null?void 0:N.textColor)??p,borderRadius:`${c??0}px`,...Wn(E.viewProps,Ie(((W=E.viewProps)==null?void 0:W.borderColor)??h),R,0),children:m?f.jsx(m,{...e}):f.jsx(D.Box,{p:4,children:E.label??"Grid"})})}}),f.jsx(ko,{nodeAddress:e.data.id,active:o.includes(e.data.id),label:e.data.label??"Grid",open:l&&!n,onClose:()=>d(!1),children:f.jsx(Ft.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 A,I,M;if(n||!r.editable)return;const R=String(E.value??"");E.address==="root.metadata.label"?(A=t.onNodeLabelChange)==null||A.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(Hd,{nodeAddress:e.data.id})})})]})}function _E(e){var M,k,_,$;const{callbacks:r,config:t,readOnly:n,themeColor:o,colorMode:i}=Ge(),{canvas:s,background:a,border:c,colorText:l}=lt(),d=fv(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(),A=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 W=new AbortController;p.current=W,g(!0),b("");try{await r.onPromptSubmit({nodeId:e.data.id,prompt:N,temperature:x},W.signal)}catch(T){W.signal.aborted||b(T instanceof Error?T.message:"Prompt execution failed.")}finally{p.current===W&&(p.current=void 0,g(!1))}};return f.jsx(Ko,{...e,contentProps:{px:8,py:6,minH:"200px",flexShrink:0,overscrollBehavior:"contain"},contentPlainText:!0,contentPlaceholder:((_=t.nodePlaceholder)==null?void 0:_.call(t,e.data.id,e.data))||"Ask Squeed to build or change this canvas…",surfaceOverlay:m?f.jsx(bu,{active:!0,label:"Prompt running"}):void 0,headerOverlay:h!==void 0?f.jsx(D.Box,{position:"relative",h:"0",flexShrink:0,"aria-hidden":"true","data-prompt-budget":"",children:f.jsx(D.Box,{position:"absolute",left:"0",right:"0",top:"-1px",h:"2px",bg:d.highlightColor,children:f.jsx(D.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(D.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(D.Text,{role:"alert",fontSize:"sm",color:"red.500",children:y}),f.jsxs(D.HStack,{justifyContent:"space-between",alignItems:"center",gap:3,children:[f.jsxs(D.HStack,{minW:0,gap:2,flexWrap:"wrap",color:d.hextextColor,children:[f.jsx(D.Text,{fontSize:"32px",lineHeight:"1.15",fontWeight:"bold",children:"Thinking effort"}),f.jsxs(Ot,{"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(He,{label:m?"Cancel prompt":r.onPromptSubmit?"Run prompt":"Prompt execution is not connected",children:f.jsx(Oe,{"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:A,color:l,_hover:{bg:A,color:l},_active:{bg:A},css:{...mr(`var(--chakra-colors-${A.replace(".","-")})`,`var(--chakra-colors-${c.replace(".","-")})`),"& > svg":{width:"40px",height:"40px"}},icon:m?f.jsx(X.PiStop,{size:40}):f.jsx(X.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 gv=e=>f.jsx(pv,{...e,renderCompact:yE}),yv=e=>f.jsx(pv,{...e}),mv=({containerStyle:e,...r})=>{const{selectedNodeIds:t}=Ge();return f.jsx(Qn,{...r,editOnMount:t.includes(r.data.id),children:n=>f.jsx(D.Box,{bg:e.textColor==="transparent"?"transparent":e.labelBg,p:`${e.fontSize/5}px`,fontFamily:Pr,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})})})};gv.displayName="text";yv.displayName="arrayView";mv.displayName="ParentContainerView";const Nm={grid:EE,prompt:_E,objectView:Ko,arrayView:yv,text:gv,parentContainer:mv},kE=({children:e,pattern:r="dot",backgroundColor:t})=>{const{colorMode:n}=Ge(),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(D.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:t,children:e}):f.jsxs(D.Box,{"data-flow-background":r,position:"relative",width:"100%",height:"100%",padding:0,bg:t,children:[f.jsx(D.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(D.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},PE=.4,Lr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},AE=({nodes:e,edges:r})=>{var hr;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:A,setIsZoomMode:I,isMultiSelectMode:M,setIsMultiSelectMode:k,isDragMode:_,setIsDragMode:$,isEdgeHandlesEnabled:N,setIsEdgeHandlesEnabled:W,isArrayNodeMode:T}=Ge(),Q=j.useRef(null),[ue,K]=j.useState(null),ce=j.useRef(null),V=e.length>200;j.useEffect(()=>{S(V)},[V,S]);const{edgeSep:re,rankSep:q,spacingFactor:F}=j.useMemo(()=>{const z=l1(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:G}=Gn(t),{canvas:se,borderSecondary:U,colorText:Y}=lt(),le=i==="transparent"?"transparent":b.backgroundColor||se,ne=j.useCallback(z=>{if(!z)return Ie(t);switch(z){case"dark":return Ie(le);case"light":return Ie(U);default:return Ie(z)}},[t,le,U]),de=b.colorMode==="dark",xe=de?Ie("gray.500"):ln,he=de?G!=null&&G.includes("gray")?"whitesmoke":ne(G):xe,H=c?ne(c):xe,J=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}},[]),fe=l==="C"?"LR":l,ve=j.useCallback(z=>{const O={...m,...z};return{...O,bgColor:O.bgColor||t,bgOpacity:O.outline?0:O.bgOpacity??PE}},[m,t]),Re=j.useMemo(()=>{var O;const z=new Map;for(const ae of e)(O=ae.data)!=null&&O.id&&z.set(ae.data.id,ae);return z},[e]),Je=j.useMemo(()=>{var O;const z=new Map;for(const ae of r)(O=ae.data)!=null&&O.id&&z.set(ae.data.id,ae);return z},[r]),st=j.useCallback(z=>{var ke;const O=(ke=Re.get(z))==null?void 0:ke.data,ae=ve(O==null?void 0:O.viewProps),be=Ie(ae.bgColor);return{animated:!!(O!=null&&O.isNodeAnimated)&&!V,animationVariant:O==null?void 0:O.nodeAnimationVariant,animationColor:Ie(ae.borderColor||t),bgColor:ae.outline?"transparent":be,bgOpacity:ae.bgOpacity,borderColor:ae.borderColor?Ie(ae.borderColor):ae.outline&&ae.bgColor==="transparent"?Ie(t):be,borderWidth:Dn(ae.borderWidth,Lr.borderWidth),borderStyle:ae.borderStyle??Lr.borderStyle,borderRadius:ae.borderRadius??Lr.borderRadius,textColor:ae.textColor?Ie(ae.textColor):ae.outline||ae.bgColor==="transparent"?Ie(Y):be,fontSize:ae.fontSize??Lr.fontSize,labelPosition:ae.labelPosition??Lr.labelPosition,labelMargin:Lr.labelMargin,labelBg:Bu(ne("dark"),be,ae.bgOpacity)??ne("dark"),padding:ae.padding??Lr.padding}},[ve,Re,Y,t,V,ne]),Ye=j.useMemo(()=>{var ae,be;const z=new Map;for(const ke of r){const Me=(ae=ke.data)==null?void 0:ae.source,Te=(be=ke.data)==null?void 0:be.target;if(!Me||!Te||Me===Te)continue;const rt=Me<Te?`${Me}|${Te}`:`${Te}|${Me}`,et=z.get(rt);et?et.push({id:ke.data.id,source:Me}):z.set(rt,[{id:ke.data.id,source:Me}])}const O=new Map;for(const[ke,Me]of z){if(Me.length<2)continue;const Te=ke.split("|")[0],rt=Math.min(20,70/Me.length);Me.forEach(({id:et,source:Fe},it)=>{const yt=50+(it-(Me.length-1)/2)*rt;O.set(et,(Fe===Te?yt:100-yt)/100)})}return O},[r]),We=j.useMemo(()=>{const z=ne("dark");return r.filter(O=>{var ae;return((ae=O.data)==null?void 0:ae.id)&&O.data.source&&O.data.target}).map(({data:O})=>{var Me,Te,rt,et,Fe,it;let ae=z;const be=(Te=(Me=Re.get(O.source))==null?void 0:Me.data)==null?void 0:Te.parent,ke=(et=(rt=Re.get(O.target))==null?void 0:rt.data)==null?void 0:et.parent;if(be&&be===ke){const yt=ve((it=(Fe=Re.get(be))==null?void 0:Fe.data)==null?void 0:it.viewProps),Ct=Bu(z,Ie(yt.bgColor),yt.bgOpacity);Ct&&(ae=Ct)}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?Vd(p,O):void 0,color:c?H:O.color?Ie(O.color):H,connectorColor:c?H:O.color?Ie(O.color):he,labelBg:ae,dashed:!!O.isEdgeDashed,animated:!!O.isEdgeAnimated,inverted:!!O.isInverted,turn:Ye.get(O.id)??.5}})},[r,H,he,c,Ye,b.edgeType,u,p,Re,ve,ne]),Ze=j.useMemo(()=>{var O;const z=new Set;for(const ae of e)(O=ae.data)!=null&&O.parent&&z.add(ae.data.parent);return z},[e]),me=j.useMemo(()=>{const z=new Map;for(const O of r){const ae=O.data.isInverted?O.data.target:O.data.source;ae&&!z.has(ae)&&z.set(ae,O.data)}for(const O of r){if(O.data.connection)continue;const ae=O.data.isInverted?O.data.target:O.data.source,be=O.data.isInverted?O.data.source:O.data.target;be.startsWith(`${ae}.`)&&(z.set(ae,O.data),z.set(be,O.data))}return z},[r]),Ae=j.useMemo(()=>{const z={...Nm,...b.customViews};return e.filter(O=>{var ae;return(ae=O.data)==null?void 0:ae.id}).map(O=>{var yt,Ct,jt,Mt,Tt,mt,ft,bt,qt;const ae=Ze.has(O.data.id)&&!O.data.parent,be=ae&&O.data.type!=="prompt"?O.data.label??O.data.headerTitle??"Container":void 0,ke=It=>O.data.type==="prompt"?It.prompt:ae?It.parentContainer:It[O.data.type]||It.text,Me=ke(Nm),Te=ke(z),rt=Te!==Me,et=((yt=b.customViews)==null?void 0:yt.fillNode)??Te,Fe=me.get(O.data.id),it={...O,isInverted:((Ct=O.data.config)==null?void 0:Ct.isInverted)??(Fe==null?void 0:Fe.isInverted),isParent:ae,containerStyle:ae?st(O.data.id):void 0};return{id:O.data.id,collapsed:(jt=O.data.config)==null?void 0:jt.collapsed,parent:O.data.parent,acceptsChildren:!!((Mt=O.data.config)!=null&&Mt.parentContainer)||Ze.has(O.data.id),label:be,animated:!!O.data.isNodeAnimated,animationVariant:O.data.nodeAnimationVariant,hasCollapseControl:((Tt=O.data.config)==null?void 0:Tt.collapsed)!==void 0,animationColor:Ie(((mt=O.data.viewProps)==null?void 0:mt.borderColor)||t),animationWidth:Dn((ft=O.data.viewProps)==null?void 0:ft.borderWidth,8),element:j.createElement(Te,{...it,...rt?{renderNode:Me}:{},key:`${O.data.id}-${t}`}),fillElement:R.has(O.data.id)&&!((bt=b.customViews)!=null&&bt.fillNode)?void 0:j.createElement(et,{...it,...(qt=b.customViews)!=null&&qt.fillNode?{renderNode:Te}:rt?{renderNode:Me}:{},data:{...O.data,viewProps:R.has(O.data.id)?O.data.viewProps:{...O.data.viewProps,borderRadius:0}},containerStyle:it.containerStyle&&!R.has(O.data.id)?{...it.containerStyle,borderRadius:0}:it.containerStyle,key:`${O.data.id}-${t}`})}})},[e,Ze,me,t,b.customViews,st,R]),oe=j.useMemo(()=>V?300:e.length>50?150:e.length>20?100:50,[e.length,V]),ie=j.useRef(b);ie.current=b;const Ne=j.useRef(A);Ne.current=A;const Qe=j.useRef(T);Qe.current=T;const Ee=j.useRef(x);Ee.current=x;const Le=j.useRef(v);Le.current=v;const ct=j.useRef(M);ct.current=M;const Ue=j.useRef(Re);Ue.current=Re;const ht=j.useRef(Je);ht.current=Je;const pt=j.useRef(new Map);j.useEffect(()=>{var ae,be;const z=new Map([...Je].filter(([,ke])=>Re.has(ke.data.source)&&Re.has(ke.data.target))),O=pt.current;pt.current=z;for(const[ke,Me]of O)z.has(ke)||(Le.current===ke&&(C(null),(ae=y.onEdgeDeselect)==null||ae.call(y)),(be=y.onEdgeRemove)==null||be.call(y,ke,Me.data))},[Je,Re,y,C]),j.useEffect(()=>{const z=Q.current;if(!ue||!z)return;let O=null,ae=null,be=0,ke=0,Me=0,Te=0,rt=0;const et=Fe=>{var Ct;if(ie.current.readOnly||ie.current.minZoom===ie.current.maxZoom&&ie.current.minZoom!==void 0&&((Ct=z.parentElement)!=null&&Ct.closest(".flow-sdk-canvas")))return;const it=z.ownerDocument.fullscreenElement;if(it&&it!==z&&z.contains(it)&&Fe.target instanceof Node&&it.contains(Fe.target))return;Fe.preventDefault(),Fe.stopPropagation(),Ne.current||Fe.metaKey||Fe.ctrlKey?(Me+=Fe.deltaY,Te=Fe.clientX,rt=Fe.clientY,ae===null&&(ae=requestAnimationFrame(()=>{ae=null;const jt=ie.current,Mt=ue.zoom(),Tt=Me;Me=0;let mt=Mt-Tt*.05/100;mt=Math.max(jt.minZoom??.01,Math.min(jt.maxZoom??1.5,mt));const ft=z.getBoundingClientRect();ue.zoomAt(mt,{x:Te-ft.left,y:rt-ft.top})}))):(be+=Fe.deltaX,ke+=Fe.deltaY,O===null&&(O=requestAnimationFrame(()=>{O=null;const jt=ue.pan(),Mt=ue.zoom(),Tt=.35,mt=be,ft=ke;be=0,ke=0,ue.pan({x:jt.x+-mt*Tt/Mt,y:jt.y+-ft*Tt/Mt})})))};return z.addEventListener("wheel",et,{passive:!1}),()=>{z.removeEventListener("wheel",et),O!==null&&cancelAnimationFrame(O),ae!==null&&cancelAnimationFrame(ae)}},[ue]),j.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const z=O=>{var be,ke,Me,Te,rt,et;if(ie.current.readOnly)return;const ae=O.target;if(!(ae.tagName==="INPUT"||ae.tagName==="TEXTAREA"||ae.isContentEditable)){if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(O.key)){const Fe=Q.current,it=g.current,yt=Fe==null?void 0:Fe.querySelector(".flow-sdk-canvas");if(!Fe||!yt||!it||ae!==Fe&&(ae.closest(".flow-sdk-canvas")!==yt||!ae.closest(".flow-sdk-node")||ae.querySelector(":scope > .flow-sdk-canvas")||ae.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||ct.current||Ee.current.length>1||yt.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(Wt=>Wt.getClientRects().length>0&&getComputedStyle(Wt).visibility!=="hidden"))return;const Ct=yt.getBoundingClientRect();if(!Ct.width||!Ct.height)return;const jt=it.clientToModel(Ct.left+Ct.width/2,Ct.top+Ct.height/2),Mt=Ee.current[0],Tt=Mt&&it.getNodeBox(Mt)||jt,mt=O.key==="ArrowLeft"||O.key==="ArrowRight",ft=O.key==="ArrowLeft"||O.key==="ArrowUp"?-1:1;let bt;for(const Wt of yt.querySelectorAll(".flow-sdk-node")){if(Wt.closest(".flow-sdk-canvas")!==yt)continue;const at=Wt.getAttribute("data-node-id");if(!at||at===Mt||!Ue.current.has(at))continue;const vr=Wt.getBoundingClientRect(),Nr=getComputedStyle(Wt);if(!vr.width||!vr.height||Nr.visibility==="hidden"||Nr.opacity==="0")continue;const pr=it.getNodeBox(at);if(!pr)continue;const mn=pr.x-Tt.x,bn=pr.y-Tt.y;if((mt?mn:bn)*ft<=.01)continue;const Zr=Math.hypot(mn,bn);(!bt||Zr<bt.distance)&&(bt={id:at,box:pr,distance:Zr})}if(O.preventDefault(),O.stopPropagation(),!bt)return;Le.current&&(C(null),(be=y.onEdgeDeselect)==null||be.call(y)),w([bt.id]),(ke=y.onNodeSelect)==null||ke.call(y,bt.id,Ue.current.get(bt.id).data,{shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1,keyboardNavigation:!0});const qt=it.pan(),It=it.zoom();it.pan({x:qt.x+(jt.x-bt.box.x)*It,y:qt.y+(jt.y-bt.box.y)*It},!0);return}if((O.key==="z"||O.key==="Z")&&I(!Ne.current),(O.key==="m"||O.key==="M")&&k(!M),(O.key==="d"||O.key==="D")&&$(!_),(O.key==="v"||O.key==="V")&&!O.repeat&&!O.metaKey&&!O.ctrlKey&&!O.altKey&&ae.tagName!=="SELECT"&&W(!N),(O.key==="Delete"||O.key==="Backspace")&&Le.current){O.preventDefault();const Fe=Le.current;(Te=y.onEdgeDelete)==null||Te.call(y,Fe,((Me=ht.current.get(Fe))==null?void 0:Me.data)??{id:Fe}),C(null);return}if((O.key==="Delete"||O.key==="Backspace")&&Ee.current.length>0){O.preventDefault();const Fe=Ee.current.filter(it=>it!=="root");if(Fe.length===0)return;for(const it of Fe){const yt=(rt=Ue.current.get(it))==null?void 0:rt.data;(et=y.onNodeDelete)==null||et.call(y,it,yt||{})}w([])}}};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[M,_,N,W,I,k,$,b.disableKeyboardShortcuts,y,w,C]);const At=j.useCallback(z=>{var O;g.current=z,K(z),(O=y.onInit)==null||O.call(y,z)},[g,y]),zt=j.useCallback(z=>{var O;return(O=y.onViewportChange)==null?void 0:O.call(y,z)},[y]),tt=j.useCallback(z=>{var ae,be,ke;const O=((ae=ht.current.get(z))==null?void 0:ae.data)??{id:z};if(Le.current===z&&ct.current){C(null),(be=y.onEdgeDeselect)==null||be.call(y);return}Ee.current.length&&w([]),C(z),(ke=y.onEdgeSelect)==null||ke.call(y,z,O)},[y,C,w]),Ve=j.useCallback(()=>{var z,O,ae,be,ke,Me;if((z=Q.current)==null||z.focus({preventScroll:!0}),a(b.bottomBarCollapsed??(Ee.current.length>0||!!Le.current||!s)),(O=y.onBackgroundClick)==null||O.call(y),!ie.current.readOnly){const Te=new Set;for(const rt of Ee.current){let et=Ue.current.get(rt);for(;et&&!Te.has(et.data.id);)Te.add(et.data.id),Ze.has(et.data.id)&&((ae=et.data.config)==null?void 0:ae.collapsed)!==!0&&((be=y.onNodeCollapse)==null||be.call(y,et.data.id,!0)),et=et.data.parent?Ue.current.get(et.data.parent):void 0}}Ee.current.length&&(w([]),(ke=y.onNodeDeselect)==null||ke.call(y)),Le.current&&(C(null),(Me=y.onEdgeDeselect)==null||Me.call(y))},[y,w,C,a,s,b.bottomBarCollapsed,Ze]);j.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const z=O=>{const ae=Q.current,be=ae==null?void 0:ae.querySelector(".flow-sdk-canvas"),ke=O.target;O.key!=="Escape"||O.defaultPrevented||O.repeat||O.isComposing||O.ctrlKey||O.metaKey||O.altKey||O.shiftKey||ie.current.readOnly||!Ee.current.length||!ae||!be||!ae.getClientRects().length||document.fullscreenElement||be.querySelector("[data-grid-dragging], .flow-sdk-ghost, .flow-sdk-box")||ke instanceof Element&&(ke.closest('input, textarea, select, [contenteditable], [role="textbox"], [role="combobox"], dialog, [role="dialog"], [role="menu"], [role="listbox"], [popover]')||ke!==document.body&&!ae.contains(ke)||ke.closest(".flow-sdk-canvas")&&ke.closest(".flow-sdk-canvas")!==be)||Array.from(document.querySelectorAll('dialog[open], :popover-open, [role="dialog"], [role="menu"], [role="listbox"]')).some(Me=>Me.getClientRects().length>0&&getComputedStyle(Me).visibility!=="hidden")||(O.preventDefault(),O.stopPropagation(),Ve())};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)},[b.disableKeyboardShortcuts,Ve]);const nr=j.useCallback(z=>{var be,ke;const O=Ee.current,ae=z.filter(Me=>!O.includes(Me));if(ae.length){w([...O,...ae]);for(const Me of ae)(ke=y.onNodeSelect)==null||ke.call(y,Me,((be=Ue.current.get(Me))==null?void 0:be.data)??{id:Me})}},[y,w]),gt=j.useCallback((z,O)=>{var ae,be;w([z]),(be=y.onNodeSelect)==null||be.call(y,z,((ae=Ue.current.get(z))==null?void 0:ae.data)??{id:z},O)},[y,w]),Bt=j.useRef(null),fr=j.useCallback((z,O,ae)=>{var be;Bt.current={source:z,target:O,edgeIds:new Set(ht.current.keys())};try{(be=y.onEdgeCreate)==null||be.call(y,z,O,ae)}catch(ke){throw Bt.current=null,ke}},[y]),De=j.useCallback((z,O,ae,be=!1)=>{var ke,Me;if(ce.current={sourceId:z,nodeIds:new Set(Ue.current.keys()),reverse:be},!(u==="properties"&&((ke=y.onNodeCreateRequest)==null?void 0:ke.call(y,{sourceNodeId:z,position:O,sourceProperty:ae,reverse:be}))===!0)){if(ae!==void 0||be){ce.current=null;return}(Me=y.onNodeCreate)==null||Me.call(y,{type:"text",sourceNodeId:z,position:O,isArrayMode:Qe.current})}},[y,u]),Zt=!b.readOnly&&N&&b.edgeHandles!==!1,Dt=i==="transparent"?"none":i;return f.jsx(kE,{pattern:Dt,backgroundColor:le,children:f.jsx(D.Box,{ref:Q,tabIndex:0,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:f.jsx(dE,{nodes:Ae,edges:We,direction:fe,nodeAlignment:d,onContainerCollapse:z=>{var O,ae;(O=y.onNodeCollapse)==null||O.call(y,z,!0),(ae=y.onNodeViewToggle)==null||ae.call(y,z)},selectedNodeIds:x,selectedEdgeId:v,edgeMode:u,compactPropertyLayout:h,edgeType:b.edgeType,edgeRadius:o,customEdgeTypes:b.customEdgeTypes,edgeReveal:b.disableAnimations?void 0:b.edgeReveal,rankSep:q,edgeSep:re,nodeGridSpacing:b.nodeGridSpacing,nodeGridConnections:b.nodeGridConnections,initialNodeGrid:b.nodeGrid,spacingFactor:F,compactSpacingScale:n,layoutDebounce:oe,isPerformanceMode:V,minZoom:b.minZoom??.01,maxZoom:b.maxZoom??1.5,initialViewport:J,fixedNodePositions:b.fixedNodePositions,onFixedNodePositionsChange:y.onFixedNodePositionsChange,fitOnInit:!b.initialViewport&&!((hr=b.nodeGrid)!=null&&hr.enabled&&b.nodeGrid.options.fill),readOnly:!!b.readOnly,containerStyle:st,lineColor:c?H:he,drawMode:Zt,drawHandles:!b.readOnly&&b.edgeHandles!==!1,dragMode:_,multiSelect:!!M,onInit:At,onLayoutComplete:z=>{var Me;(Me=y.onLayoutComplete)==null||Me.call(y,z);const O=Bt.current;O&&(!Ue.current.has(O.source)||!Ue.current.has(O.target)?Bt.current=null:r.some(({data:Te})=>Te.source===O.source&&Te.target===O.target&&!O.edgeIds.has(Te.id))&&z.getNodeBox(O.source)&&z.getNodeBox(O.target)&&(Bt.current=null,z.focusConnections(O.source)));const ae=ce.current;if(!ae)return;if(!Ue.current.has(ae.sourceId)){ce.current=null;return}const ke=e.filter(Te=>!ae.nodeIds.has(Te.data.id)).filter(Te=>r.some(({data:rt})=>rt.source===ae.sourceId&&rt.target===Te.data.id||rt.target===ae.sourceId&&rt.source===Te.data.id));!ke.length||ke.some(Te=>!z.getNodeBox(Te.data.id))||(ce.current=null,z.focusBranch(ae.reverse?ke[0].data.id:ae.sourceId))},onNodeGridModeChange:E,onNodeGridZoomOut:y.onNodeGridZoomOut,onNodeGridDrop:y.onNodeGridDrop,onNodeParentChange:y.onNodeParentChange,animateViewport:b.animateViewport,disableAnimations:b.disableAnimations,onViewportChange:zt,onBackgroundTap:Ve,onBoxSelect:nr,onEdgeSelect:tt,onContainerSelect:gt,onEdgeDraw:fr,onDrawIntoSpace:De})})})},bv=j.memo(AE),RE=".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 Om=!1;function ME(){if(Om||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=RE+".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}"+Jb+s1+i1+".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}',Om=!0}function TE({loading:e=!1,loader:r,...t}){var c,l;const[n,o]=j.useState(null),i=j.useMemo(()=>!!(n!=null&&n.json)&&!!t.json&&t1(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(D.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(IE,{...s?n:t,children:t.children,config:t.config,className:void 0,style:void 0})}),a&&r!==null&&f.jsx(D.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 IE({title:e="untitled",json:r,forms:t,nodes:n,edges:o,config:i={},callbacks:s={},className:a,style:c,showBottomBar:l=!0,children:d}){ME();const[u,h]=j.useState(),[p,m]=j.useState(!1),g=i.formSchema??u,y=j.useMemo(()=>r&&t?Pb(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?r1(M,_,k)??Ed(_,{title:e,isCenter:b}):Ed(_,{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?Ab(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 ue,K,ce,V;const _=r?(ue=$e(r,k.data.id))==null?void 0:ue.$view:(K=k.data.config)==null?void 0:K.typeView,$=_&&zd.includes(_)?_:void 0,N=$?$==="icon-label":(ce=k.data.config)==null?void 0:ce.labelBelow,W=$==="object"?"objectView":$==="text"?"text":N?"arrayView":k.data.type,T=C&&(t?Hn(S,k.data.id,C):r&&un(r,k.data.id,C)),Q=(((V=k.data.config)==null?void 0:V.ports)??[]).map(re=>({...re}));if(v&&T){const re=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 G=`${F.kind}:${q}`,se=Q.find(U=>U.id===G);se?se.label===void 0&&F.label!==void 0&&(se.label=F.label):Q.push({id:G,...F.label!==void 0?{label:F.label}:{},role:F.kind==="input"||F.kind==="config"?"target":"source",side:re[F.kind],...F.kind==="config"?{placement:"config"}:{}})}for(const q of Q){const F=Q.filter(G=>G.side===q.side);q.position=(F.indexOf(q)+1)/(F.length+1)}}return T||N||$?{...k,data:{...k.data,type:W,...t?{description:Object.fromEntries(Object.entries(k.data.description??{}).filter(([re])=>!re.startsWith("$")&&!(v!=null&&v.slots.has(En(k.data.id,re)))))}:{},config:{...k.data.config,...v&&T?{ports:Q}:{},...T?{form:!0}:{},...$?{typeView:$,labelBelow:!!N}:N?{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]),A=j.useMemo(()=>{const M=r&&w?Kb(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 $=M[_];M[_]=(N,...W)=>{if(!k.has(N))return $==null?void 0:$(N,...W)}}}return{...M,onAllNodesIconLabelChange:k=>{var _;m(k),(_=M.onAllNodesIconLabelChange)==null||_.call(M,k)}}},[r,w,s,g,v]),I=j.useMemo(()=>{if(!t)return A;let M=t.state;const k=$=>{if(i.readOnly||i.editable===!1)return;const N=t.onStateChange??t.onChange;if(!N)return;const W=Fw(M,$,s.onFormChange);W!==M&&(M=W,N(W,{...$,data:W}))},_=($,N,W)=>{var Q;const T=r&&((Q=$e(r,$))==null?void 0:Q[N]);return!T||typeof T.$state!="string"?!1:(k({address:T.$state,nodeAddress:$,previousValue:$e(M,T.$state),value:W,data:M}),!0)};return{...A,onFormChange:k,onNodeCreateRequest:$=>{var T,Q;const N=(T=$.sourceProperty)!=null&&T.startsWith("config:")?$.sourceProperty.slice(7):void 0,W=N!==void 0&&(v==null?void 0:v.slots.get(En($.sourceNodeId,N)));return W?(W.present||k({data:M,nodeAddress:W.address.split(".").slice(0,-1).join("."),address:W.address,value:_n(W.type),previousValue:void 0}),!0):((Q=A.onNodeCreateRequest)==null?void 0:Q.call(A,$))??!1},onNodeDelete:($,N)=>{var ce,V;if(!(v!=null&&v.nodes.some(re=>re.data.id===$)))return(ce=A.onNodeDelete)==null?void 0:ce.call(A,$,N);const W=v&&[...v.slots.values()].find(re=>re.nodeId===$);if(!W)return(V=A.onNodeDelete)==null?void 0:V.call(A,$,N);const T=W.address.split("."),Q=T.pop(),ue=T.join("."),K=$e(M,ue);k(Array.isArray(K)?{data:M,nodeAddress:ue,address:ue,previousValue:K,value:K.filter((re,q)=>String(q)!==Q)}:{data:M,nodeAddress:ue,address:W.address,previousValue:$e(M,W.address),value:void 0})},onEdgeCreate:($,N,W)=>{var ue,K;const T=((ue=W==null?void 0:W.targetProperty)==null?void 0:ue.startsWith("config:"))&&(v==null?void 0:v.slots.get(En(N,W.targetProperty.slice(7)))),Q=v==null?void 0:v.containers.get($);if(T&&Q&&(W==null?void 0:W.sourceProperty)==="output:resource"){const ce=Gw(M,Q,T);ce!==void 0&&k({data:M,nodeAddress:T.address.split(".").slice(0,-1).join("."),address:T.address,previousValue:$e(M,T.address),value:ce});return}T||v!=null&&v.nodes.some(ce=>ce.data.id===$||ce.data.id===N)||(K=A.onEdgeCreate)==null||K.call(A,$,N,W)},onEdgeDelete:($,N)=>{var V;const W=v==null?void 0:v.edges.find(re=>re.data.id===$);if(!W)return(V=A.onEdgeDelete)==null?void 0:V.call(A,$,N);const T=v.slots.get(En(W.data.target,W.data.targetProperty.slice(7))),Q=T.address.split("."),ue=Q.pop(),K=Q.join("."),ce=$e(M,K);k(Array.isArray(ce)?{data:M,nodeAddress:K,address:K,previousValue:ce,value:ce.filter((re,q)=>String(q)!==ue)}:{data:M,nodeAddress:K,address:T.address,previousValue:$e(M,T.address),value:void 0})},onNodeContentChange:($,N)=>{var W,T;_($,"$content",N)?(W=s.onNodeContentChange)==null||W.call(s,$,N):(T=A.onNodeContentChange)==null||T.call(A,$,N)},onNodeLabelChange:($,N)=>{var W,T;_($,"$label",N)?(W=s.onNodeLabelChange)==null||W.call(s,$,N):(T=A.onNodeLabelChange)==null||T.call(A,$,N)}}},[A,t,r,s,v,i.readOnly,i.editable]);return f.jsx(Ft.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(vb,{config:v?{...i,formSchema:C}:i,callbacks:I,nodes:E,edges:R,children:f.jsxs(D.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(bv,{nodes:E,edges:R}),l&&f.jsx(Wb,{}),d]})})})}function NE(e){return Id(JSON.parse(e))}function Id(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 OE(e){return{replaceJson(r){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const t=Id(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=Id(r);return e.onStateChange(t,{address:"root",nodeAddress:"root",previousValue:e.state,value:t,data:t}),t}}}function $E(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 qE(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 LE({nodeAddress:e,expanded:r=!1}){var l;const{data:t,schema:n,bindings:o}=j.useContext(Ft),{colorText:i,background:s}=lt();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=$e(t,a.address);return!c||typeof c!="object"?null:f.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:Ie(i),background:Ie(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:Ht(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=Wb;exports.CollapseAllToggle=Cb;exports.CompactPropertyLayoutToggle=Sb;exports.ConnectionsOnlyToggle=e1;exports.ContentFullscreenButton=uv;exports.DEFAULT_PALETTE=po;exports.DiagramAppearanceControls=jb;exports.DynamicIcon=dr;exports.EdgeTools=Ob;exports.EditableLabel=cn;exports.ErrorToast=Bb;exports.FlowDiagram=TE;exports.FlowDiagramProvider=vb;exports.FlowPort=dv;exports.FlowView=bv;exports.FormDocumentContext=Ft;exports.GridAdjustmentToggle=Eb;exports.LIGHT_BLACK=ln;exports.LoadingBorder=bu;exports.NODE_TYPE_VIEWS=zd;exports.NodeBorderRadiusControl=$b;exports.NodeConfigSummary=LE;exports.NodeForm=Hd;exports.NodeFormPopover=ko;exports.NodeGridControls=so;exports.NodeIconPicker=Ud;exports.NodeTools=qb;exports.NodeView=Qn;exports.PanelDragHandle=wb;exports.SvgExportButton=zb;exports.Swatches=Gr;exports.TEXT_PALETTE=Ib;exports.ToolbarCloseButton=dn;exports.ToolbarCommitInput=kr;exports.ToolbarDivider=Nn;exports.ToolbarIconButton=Oe;exports.ToolbarRangeInput=Bd;exports.ToolbarScrollContainer=Po;exports.ToolbarSelect=Ot;exports.ToolbarTooltip=He;exports.TooltipIconButton=Td;exports.WorkflowControls=Kd;exports.addChild=Ld;exports.addConnection=Fd;exports.addTargetEdge=hb;exports.addressToPath=Yt;exports.applyCollapsed=Ew;exports.applyFormChange=_o;exports.applyStateEdits=Lw;exports.bindSqueedCallbacks=Kb;exports.compileSqueed=Ed;exports.connectionIssue=Vd;exports.contentObjTheme=lr;exports.copySelection=Jd;exports.createFlowDiagram=Wr;exports.createFlowDocumentActions=OE;exports.createFormNode=Gb;exports.createJsonPlayback=qE;exports.createJsonStream=lo;exports.createWorkflowExecution=Mw;exports.downloadSvg=Fb;exports.duplicateSelection=Ub;exports.exportSvg=Lb;exports.formValueError=Qt;exports.formatTimeAgo=gb;exports.getChakraColorHex=Ie;exports.getColorVariant=yb;exports.getDarkerHexColor=fo;exports.getInteractionSurface=mr;exports.getNode=$e;exports.getSelectionRoots=Hb;exports.isNodeVisible=cr;exports.parseFlowDocument=NE;exports.parseJsonContract=Dd;exports.parseTypeScriptContract=_b;exports.parseTypeScriptForm=Wd;exports.projectJsonPlaybackPreview=$E;exports.readFormSchema=Gd;exports.readWorkflowContract=kb;exports.removeEdge=pb;exports.removeNode=fb;exports.reparentNode=n1;exports.resolveEdgeOwner=Br;exports.resolveStateView=Pb;exports.setCollapsed=uo;exports.setEdgeProp=Er;exports.setEdgeStyle=ub;exports.setNodeProp=Et;exports.stampNodeEdit=db;exports.updateNode=Rt;exports.useCustomColors=lt;exports.useEdgeProximity=So;exports.useFlowData=tr;exports.useFlowDiagramContext=Ge;exports.useNodeViewActions=eo;exports.useStopPropagation=mu;exports.useThemeContentColors=Gn;exports.validateGridAdjustment=av;
|
|
285
285
|
//# sourceMappingURL=index.cjs.map
|