@squeed/flow-sdk 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,10 @@
1
- "use strict";var Gm=Object.create;var Hn=Object.defineProperty;var Um=Object.getOwnPropertyDescriptor;var Hm=Object.getOwnPropertyNames;var Km=Object.getPrototypeOf,Zm=Object.prototype.hasOwnProperty;var Jm=(e,t,r)=>t in e?Hn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ym=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Hm(t))!Zm.call(e,o)&&o!==r&&Hn(e,o,{get:()=>t[o],enumerable:!(n=Um(t,o))||n.enumerable});return e};var qe=(e,t,r)=>(r=e!=null?Gm(Km(e)):{},Ym(t||!e||!e.__esModule?Hn(r,"default",{value:e,enumerable:!0}):r,e));var Ar=(e,t,r)=>Jm(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),F=require("@chakra-ui/react"),E=require("react"),Z=require("react-icons/pi"),Xm=require("@emotion/react"),Qm=require("@emotion/styled"),ev=require("react-icons/tb"),Lt=require("react-dom"),rv=require("markdown-to-jsx/react"),dy=e=>e&&e.__esModule?e:{default:e},gn=dy(Qm),tv=dy(rv),fy=E.createContext(null),hy=E.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function Wr(){return E.useContext(hy)}function Ie(){const e=E.useContext(fy);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function py({config:e,callbacks:t,nodes:r=[],edges:n=[],children:o}){const i=E.useMemo(()=>{var $e,Xe,Y;const ne=new Map;for(const D of r)($e=D.data)!=null&&$e.id&&ne.set(D.data.id,D);const Fe=new Map;for(const D of n)(Xe=D.data)!=null&&Xe.id&&Fe.set(D.data.id,D);const Je=new Set;for(const D of r)(Y=D.data)!=null&&Y.parent&&Je.add(D.data.parent);return{nodeById:ne,edgeById:Fe,parentIds:Je}},[r,n]),a=E.useRef(null),[s,u]=E.useState([]),[c,l]=E.useState(null),[d,f]=E.useState(!0),[p,b]=E.useState(!1),[y,m]=E.useState(!0),[x,g]=E.useState(!1),[w,v]=E.useState(!1),[_,C]=E.useState(!0),[S,T]=E.useState(!1),[k,j]=E.useState("auto"),[P,R]=E.useState(!1),I=e.compactPropertyLayout??P,[O,M]=E.useState({}),q=e.nodeViewModes??O,H=[...i.nodeById.values()].filter(ne=>{var Fe;return i.parentIds.has(ne.data.id)||((Fe=ne.data.config)==null?void 0:Fe.parentContainer)||ne.data.type==="objectView"||ne.data.type==="arrayView"}),V=!!H.length&&H.every(ne=>{var Fe,Je,$e;return i.parentIds.has(ne.data.id)||(Fe=ne.data.config)!=null&&Fe.parentContainer?!!((Je=ne.data.config)!=null&&Je.collapsed):q[ne.data.id]==="icon-label"||(($e=ne.data.config)==null?void 0:$e.labelBelow)&&q[ne.data.id]!=="properties"}),[re,ce]=E.useState("normal"),[le,be]=E.useState(),K=e.edgeRadius??le,N=K!==void 0&&Number.isFinite(K)?Math.min(500,Math.max(0,K)):void 0,[B,W]=E.useState(),z=e.spacing??re,X=typeof z=="number"?Number.isFinite(z)?Math.min(2,Math.max(.5,z)):1:z==="compact"?.5:z==="spacious"?2:1,se=e.backgroundVariant??B??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[Q,G]=E.useState(),J=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:Q,[te,de]=E.useState("blue.500"),[fe,Ee]=E.useState(!1),ge=E.useRef(t);ge.current=t;const We=E.useMemo(()=>{const ne=Fe=>(...Je)=>{var $e,Xe;return(Xe=($e=ge.current)==null?void 0:$e[Fe])==null?void 0:Xe.call($e,...Je)};return{onNodeSelect:ne("onNodeSelect"),onBackgroundClick:ne("onBackgroundClick"),onNodeDeselect:ne("onNodeDeselect"),onNodeDoubleClick:ne("onNodeDoubleClick"),onNodeViewToggle:ne("onNodeViewToggle"),onNodeTypeViewChange:ne("onNodeTypeViewChange"),onNodeCreate:ne("onNodeCreate"),onNodeCreateRequest:ne("onNodeCreateRequest"),onNodeDelete:ne("onNodeDelete"),onNodeLabelChange:ne("onNodeLabelChange"),onNodeContentChange:ne("onNodeContentChange"),onNodeCollapse:ne("onNodeCollapse"),onNodeColorChange:ne("onNodeColorChange"),onNodeBorderColorChange:ne("onNodeBorderColorChange"),onNodeBorderStyleChange:ne("onNodeBorderStyleChange"),onNodeBorderWidthChange:ne("onNodeBorderWidthChange"),onNodeBorderRadiusChange:ne("onNodeBorderRadiusChange"),onNodeIconChange:ne("onNodeIconChange"),onNodeOutlineChange:ne("onNodeOutlineChange"),onNodeAnimationChange:ne("onNodeAnimationChange"),onNodeAnimationVariantChange:ne("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:ne("onEdgeAnimationVariantChange"),onNodeHoverAction:ne("onNodeHoverAction"),onEdgeCreate:ne("onEdgeCreate"),onEdgeSelect:ne("onEdgeSelect"),onEdgeDeselect:ne("onEdgeDeselect"),onEdgeRemove:ne("onEdgeRemove"),onEdgeDelete:ne("onEdgeDelete"),onEdgeColorChange:ne("onEdgeColorChange"),onEdgeTypeChange:ne("onEdgeTypeChange"),onEdgeIconChange:ne("onEdgeIconChange"),onEdgeLabelChange:ne("onEdgeLabelChange"),onEdgeStyleChange:ne("onEdgeStyleChange"),onViewportChange:ne("onViewportChange"),onDirectionChange:ne("onDirectionChange"),onThemeColorChange:ne("onThemeColorChange"),onSpacingChange:ne("onSpacingChange"),onEdgeRadiusChange:ne("onEdgeRadiusChange"),onBackgroundVariantChange:ne("onBackgroundVariantChange"),onEdgeModeChange:ne("onEdgeModeChange"),onCompactPropertyLayoutChange:ne("onCompactPropertyLayoutChange"),onWorkflowContractChange:ne("onWorkflowContractChange"),onArrayModeChange:ne("onArrayModeChange"),onInit:ne("onInit"),onLayoutComplete:ne("onLayoutComplete"),onJsonChange:ne("onJsonChange")}},[]),me=e.themeColor||te,Te=e.edgeColor||"",er=e.colorMode||"light",De=e.direction||"LR",Ne=e.nodeAlignment??"center",He=e.edgeMode==="workflow"?"nodes":e.edgeMode??k,rr=e.readOnly??!1,ze=JSON.stringify(e.parentNodeStyle??null),xr=E.useMemo(()=>e.parentNodeStyle,[ze]),Ze=e.isZoomMode!==void 0?e.isZoomMode:d,pr=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,dr=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:x,jr=e.isDragMode!==void 0?e.isDragMode:y,we=E.useRef(e);we.current=e;const or=E.useMemo(()=>({get direction(){return we.current.direction},get nodeAlignment(){return we.current.nodeAlignment},get edgeMode(){return we.current.edgeMode},get compactPropertyLayout(){return we.current.compactPropertyLayout},get edgeType(){return we.current.edgeType},get customEdgeTypes(){return we.current.customEdgeTypes},get themeColor(){return we.current.themeColor},get colorMode(){return we.current.colorMode},get readOnly(){return we.current.readOnly},get editable(){return we.current.editable},get minZoom(){return we.current.minZoom},get maxZoom(){return we.current.maxZoom},get backgroundPattern(){return we.current.backgroundPattern},get edgeColor(){return we.current.edgeColor},get parentNodeStyle(){return we.current.parentNodeStyle},get backgroundColor(){return we.current.backgroundColor},get edgeHandles(){return we.current.edgeHandles},get initialViewport(){return we.current.initialViewport},get nodeOverlayActions(){return we.current.nodeOverlayActions},get renderNodeOverlay(){return we.current.renderNodeOverlay},get renderSelectedNodeToolbar(){return we.current.renderSelectedNodeToolbar},get renderSelectedEdgeToolbar(){return we.current.renderSelectedEdgeToolbar},get renderBottomBar(){return we.current.renderBottomBar},get bottomBarExtra(){return we.current.bottomBarExtra},get selectionToolbar(){return we.current.selectionToolbar},get customViews(){return we.current.customViews},get disableKeyboardShortcuts(){return we.current.disableKeyboardShortcuts},get isZoomMode(){return we.current.isZoomMode},get isMultiSelectMode(){return we.current.isMultiSelectMode},get isEdgeHandlesEnabled(){return we.current.isEdgeHandlesEnabled},get isDragMode(){return we.current.isDragMode}}),[]),ar=E.useCallback((ne,Fe)=>{var Je;if(Fe!=="default"&&Fe!=="properties"&&Fe!=="icon-label")throw new Error("Unknown node view mode.");M($e=>$e[ne]===Fe?$e:{...$e,[ne]:Fe}),(Je=t.onNodeViewModeChange)==null||Je.call(t,ne,Fe)},[t.onNodeViewModeChange]),xt=E.useMemo(()=>({allNodesIconLabel:V,setAllNodesIconLabel:ne=>{var Fe,Je,$e,Xe;for(const Y of H)i.parentIds.has(Y.data.id)||(Fe=Y.data.config)!=null&&Fe.parentContainer?!rr&&!!((Je=Y.data.config)!=null&&Je.collapsed)!==ne&&(($e=t.onNodeCollapse)==null||$e.call(t,Y.data.id,ne)):ar(Y.data.id,ne?"icon-label":"default");(Xe=t.onAllNodesIconLabelChange)==null||Xe.call(t,ne)},nodeViewModes:q,setNodeViewMode:ar,spacing:X,setSpacing:ce,edgeRadius:N,setEdgeRadius:be,backgroundVariant:se,setBackgroundVariant:W,themeColor:me,setThemeColor:de,backgroundSelected:fe,setBackgroundSelected:Ee,edgeColor:Te,colorMode:er,direction:De,nodeAlignment:Ne,edgeMode:He,setEdgeMode:j,compactPropertyLayout:I,setCompactPropertyLayout:R,workflowContract:J,setWorkflowContract:G,parentNodeStyle:xr,selectedNodeIds:s,setSelectedNodeIds:u,selectedEdgeId:c,setSelectedEdgeId:l,isZoomMode:Ze,setIsZoomMode:f,isMultiSelectMode:pr,setIsMultiSelectMode:b,isDragMode:jr,setIsDragMode:m,isEdgeHandlesEnabled:dr,setIsEdgeHandlesEnabled:g,isArrayNodeMode:w,setIsArrayNodeMode:v,isPinned:_,setIsPinned:C,isPerformanceMode:S,setIsPerformanceMode:T,engineRef:a,callbacks:We,config:or,readOnly:rr}),[V,i,ar,t.onNodeCollapse,t.onAllNodesIconLabelChange,q,t.onNodeViewModeChange,me,X,se,N,e.backgroundColor,fe,Te,er,De,Ne,He,J,xr,s,c,Ze,pr,jr,dr,w,_,S,rr,e.edgeHandles,e.edgeType,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.compactPropertyLayout,I,We,or]);return h.jsx(fy.Provider,{value:xt,children:h.jsx(hy.Provider,{value:i,children:o})})}function cn(e,t=.2){const r=e.replace(/^#/,""),n=parseInt(r,16);let o=n>>16&255,i=n>>8&255,a=n&255;return o=Math.max(0,Math.floor(o*(1-t))),i=Math.max(0,Math.floor(i*(1-t))),a=Math.max(0,Math.floor(a*(1-t))),"#"+((1<<24)+(o<<16)+(i<<8)+a).toString(16).slice(1).toUpperCase()}function cl(e,t,r){const n=s=>{const u=/^#?([0-9a-f]{6})$/i.exec((s==null?void 0:s.trim())??"");return u?parseInt(u[1],16):null},o=n(e),i=n(t);if(o===null||i===null)return null;const a=s=>Math.round((o>>s&255)*(1-r)+(i>>s&255)*r);return"#"+((1<<24)+(a(16)<<16)+(a(8)<<8)+a(0)).toString(16).slice(1).toUpperCase()}const Er=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:cn(e,.1),border:cn(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"},gy=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let t=e;if(t!=null&&t.startsWith("#"))return{secondary:cn(e)};let r=String(Number(e.slice(-3))+200);r=e.slice(0,-3).concat(r);let n=String(Number(e.slice(-3))-100);return n=e.slice(0,-3).concat(n),{primary:t,secondary:r,light:n}},ul={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"}},pe=(e,t)=>{var i;if(e==="transparent"||e!=null&&e.startsWith("#"))return e;if(!e)return"whitesmoke";const r=e.replace(/\./g,"-");try{const s=getComputedStyle(document.documentElement).getPropertyValue(`--chakra-colors-${r}`).trim();if(s&&s!=="")return s}catch{}const[n,o]=e.split(".");return n&&o&&((i=ul[n])!=null&&i[Number(o)])?ul[n][Number(o)]:`var(--chakra-colors-${r})`};function tr(e,t,r){return e?r:t}function Zt(e){const[t]=(e==null?void 0:e.split("."))||[],{secondary:r}=gy(e),n=Er(t).background,o=Er(t).highlight,i=Er(t).border,a=Er(t).property,s=Er(t).property;let u=Er(t).background,c=Er(t).highlight;return u=e==="transparent"?e:pe(u)+50,c=e==="transparent"?e:pe(c)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:a,propertyColor:s,secondary:r,bgColorFaint:u,highlightColorFaint:c}}function Ve(e=null){const{colorMode:t}=Ie(),r=e==null?void 0:e.includes("gray"),n=t==="dark",o=tr(n,"white","gray.900"),i=tr(n,"gray.100","gray.800"),a=tr(n,"gray.200","blackAlpha.400"),s=tr(n,"gray.200","blackAlpha.600"),u=tr(n,"gray.500","gray.700"),c=tr(n,"gray.700","gray.700"),l=tr(n,"gray.900","gray.900"),d=tr(n,"gray.400","gray.500"),f=tr(n,"gray.400","gray.500"),p=tr(n,"gray.900","gray.200"),b=tr(n,r?"gray.900":"gray.200",r?"gray.200":"gray.900"),y=tr(n,"gray.900","gray.200"),m=tr(n,e&&"#000000",e||"#ffffff"),x=tr(n,e||"#ffffff",e?"#000000":"#ffffff"),g=c,w=tr(n,"gray.300","gray.800"),v=tr(n,"white","blackAlpha.400"),_=tr(n,"green.100","green.700");return{canvas:o,background:i,backgroundSecondary:a,darkBackgroundSecondary:s,border:u,darkColor:l,backgroundWhiteColor:v,borderSecondary:c,colorActive:d,colorInactive:f,iconColor:y,moreIconColor:g,colorText:p,themedColorText:b,logoColor:m,logoColorSecondary:x,darkColorActive:w,greenColor:_}}const nv=Xm.keyframes`
1
+ "use strict";var Kb=Object.create;var Kn=Object.defineProperty;var Zb=Object.getOwnPropertyDescriptor;var Jb=Object.getOwnPropertyNames;var Yb=Object.getPrototypeOf,Xb=Object.prototype.hasOwnProperty;var Qb=(e,t,r)=>t in e?Kn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ev=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Jb(t))!Xb.call(e,o)&&o!==r&&Kn(e,o,{get:()=>t[o],enumerable:!(n=Zb(t,o))||n.enumerable});return e};var qe=(e,t,r)=>(r=e!=null?Kb(Yb(e)):{},ev(t||!e||!e.__esModule?Kn(r,"default",{value:e,enumerable:!0}):r,e));var Ar=(e,t,r)=>Qb(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),F=require("@chakra-ui/react"),j=require("react"),Z=require("react-icons/pi"),dy=require("@emotion/react"),rv=require("@emotion/styled"),tv=require("react-icons/tb"),Ft=require("react-dom"),nv=require("markdown-to-jsx/react"),fy=e=>e&&e.__esModule?e:{default:e},yn=fy(rv),ov=fy(nv);function hy({edge:e,enabled:t,bounds:r,inside:n=[],threshold:o=80}){const[i,a]=j.useState(!1),s=j.useRef(n);return s.current=n,j.useEffect(()=>{const u=l=>{var b;const d=(b=r.current)==null?void 0:b.getBoundingClientRect();if(!d)return;const f=l.target instanceof Node?l.target:null,p=!!f&&s.current.some(v=>{var g;return(g=v.current)==null?void 0:g.contains(f)}),m=e==="bottom"?d.bottom-l.clientY:l.clientY-d.top,y=l.clientX>=d.left&&l.clientX<=d.right&&m>=0&&m<=o;a(p||y)},c=()=>a(!1);return document.addEventListener("pointermove",u,!0),document.addEventListener("pointerdown",u,!0),document.documentElement.addEventListener("pointerleave",c),()=>{document.removeEventListener("pointermove",u,!0),document.removeEventListener("pointerdown",u,!0),document.documentElement.removeEventListener("pointerleave",c)}},[e,r,o]),t&&i}const iv=dy.keyframes`
2
2
  0%, 100% { box-shadow: var(--flow-rest-shadow); }
3
3
  25%, 50% { box-shadow: var(--flow-hover-shadow); }
4
- `;function Su(e,t=!0,r="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,a=`0 0 0 ${t?8:0}px ${o}`,s=`0 0 0 8px ${o}`;return{boxShadow:a,css:{"--flow-rest-shadow":s,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[r]:{boxShadow:s,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${nv} 1200ms steps(10, end) 600ms`:"none"}}}}}}var St=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(St||{});const Ft=["","icon-label","object","text"];var ov=typeof global=="object"&&global&&global.Object===Object&&global,iv=typeof self=="object"&&self&&self.Object===Object&&self,av=ov||iv||Function("return this")(),dt=av.Symbol,yy=Object.prototype,sv=yy.hasOwnProperty,cv=yy.toString,Ct=dt?dt.toStringTag:void 0;function uv(e){var t=sv.call(e,Ct),r=e[Ct];try{e[Ct]=void 0;var n=!0}catch{}var o=cv.call(e);return n&&(t?e[Ct]=r:delete e[Ct]),o}var lv=Object.prototype,dv=lv.toString;function fv(e){return dv.call(e)}var hv="[object Null]",pv="[object Undefined]",ll=dt?dt.toStringTag:void 0;function gv(e){return e==null?e===void 0?pv:hv:ll&&ll in Object(e)?uv(e):fv(e)}function yv(e){return e!=null&&typeof e=="object"}var bv="[object Symbol]";function mv(e){return typeof e=="symbol"||yv(e)&&gv(e)==bv}function vv(e,t){for(var r=-1,n=e==null?0:e.length,o=Array(n);++r<n;)o[r]=t(e[r],r,e);return o}var Pe=Array.isArray,dl=dt?dt.prototype:void 0,fl=dl?dl.toString:void 0;function by(e){if(typeof e=="string")return e;if(Pe(e))return vv(e,by)+"";if(mv(e))return fl?fl.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function ju(e){return e==null?"":by(e)}function xv(e,t,r){var n=-1,o=e.length;t<0&&(t=-t>o?0:o+t),r=r>o?o:r,r<0&&(r+=o),o=t>r?0:r-t>>>0,t>>>=0;for(var i=Array(o);++n<o;)i[n]=e[n+t];return i}function wv(e,t,r){var n=e.length;return r=r===void 0?n:r,!t&&r>=n?e:xv(e,t,r)}var Cv="\\ud800-\\udfff",_v="\\u0300-\\u036f",Sv="\\ufe20-\\ufe2f",jv="\\u20d0-\\u20ff",Ev=_v+Sv+jv,Rv="\\ufe0e\\ufe0f",kv="\\u200d",Pv=RegExp("["+kv+Cv+Ev+Rv+"]");function my(e){return Pv.test(e)}function Av(e){return e.split("")}var vy="\\ud800-\\udfff",Tv="\\u0300-\\u036f",Ov="\\ufe20-\\ufe2f",Iv="\\u20d0-\\u20ff",Mv=Tv+Ov+Iv,qv="\\ufe0e\\ufe0f",Nv="["+vy+"]",yu="["+Mv+"]",bu="\\ud83c[\\udffb-\\udfff]",$v="(?:"+yu+"|"+bu+")",xy="[^"+vy+"]",wy="(?:\\ud83c[\\udde6-\\uddff]){2}",Cy="[\\ud800-\\udbff][\\udc00-\\udfff]",Lv="\\u200d",_y=$v+"?",Sy="["+qv+"]?",Fv="(?:"+Lv+"(?:"+[xy,wy,Cy].join("|")+")"+Sy+_y+")*",Bv=Sy+_y+Fv,Dv="(?:"+[xy+yu+"?",yu,wy,Cy,Nv].join("|")+")",zv=RegExp(bu+"(?="+bu+")|"+Dv+Bv,"g");function Vv(e){return e.match(zv)||[]}function Wv(e){return my(e)?Vv(e):Av(e)}function Gv(e){return function(t){t=ju(t);var r=my(t)?Wv(t):void 0,n=r?r[0]:t.charAt(0),o=r?wv(r,1).join(""):t.slice(1);return n[e]()+o}}var Uv=Gv("toUpperCase");function Hv(e,t,r,n){for(var o=-1,i=e==null?0:e.length;++o<i;)r=t(r,e[o],o,e);return r}function Kv(e){return function(t){return e==null?void 0:e[t]}}var Zv={À:"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"},Jv=Kv(Zv),Yv=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Xv="\\u0300-\\u036f",Qv="\\ufe20-\\ufe2f",ex="\\u20d0-\\u20ff",rx=Xv+Qv+ex,tx="["+rx+"]",nx=RegExp(tx,"g");function ox(e){return e=ju(e),e&&e.replace(Yv,Jv).replace(nx,"")}var ix=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function ax(e){return e.match(ix)||[]}var sx=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function cx(e){return sx.test(e)}var jy="\\ud800-\\udfff",ux="\\u0300-\\u036f",lx="\\ufe20-\\ufe2f",dx="\\u20d0-\\u20ff",fx=ux+lx+dx,Ey="\\u2700-\\u27bf",Ry="a-z\\xdf-\\xf6\\xf8-\\xff",hx="\\xac\\xb1\\xd7\\xf7",px="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",gx="\\u2000-\\u206f",yx=" \\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",ky="A-Z\\xc0-\\xd6\\xd8-\\xde",bx="\\ufe0e\\ufe0f",Py=hx+px+gx+yx,Ay="['’]",hl="["+Py+"]",mx="["+fx+"]",Ty="\\d+",vx="["+Ey+"]",Oy="["+Ry+"]",Iy="[^"+jy+Py+Ty+Ey+Ry+ky+"]",xx="\\ud83c[\\udffb-\\udfff]",wx="(?:"+mx+"|"+xx+")",Cx="[^"+jy+"]",My="(?:\\ud83c[\\udde6-\\uddff]){2}",qy="[\\ud800-\\udbff][\\udc00-\\udfff]",it="["+ky+"]",_x="\\u200d",pl="(?:"+Oy+"|"+Iy+")",Sx="(?:"+it+"|"+Iy+")",gl="(?:"+Ay+"(?:d|ll|m|re|s|t|ve))?",yl="(?:"+Ay+"(?:D|LL|M|RE|S|T|VE))?",Ny=wx+"?",$y="["+bx+"]?",jx="(?:"+_x+"(?:"+[Cx,My,qy].join("|")+")"+$y+Ny+")*",Ex="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Rx="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",kx=$y+Ny+jx,Px="(?:"+[vx,My,qy].join("|")+")"+kx,Ax=RegExp([it+"?"+Oy+"+"+gl+"(?="+[hl,it,"$"].join("|")+")",Sx+"+"+yl+"(?="+[hl,it+pl,"$"].join("|")+")",it+"?"+pl+"+"+gl,it+"+"+yl,Rx,Ex,Ty,Px].join("|"),"g");function Tx(e){return e.match(Ax)||[]}function Ox(e,t,r){return e=ju(e),t=t,t===void 0?cx(e)?Tx(e):ax(e):e.match(t)||[]}var Ix="['’]",Mx=RegExp(Ix,"g");function qx(e){return function(t){return Hv(Ox(ox(t).replace(Mx,"")),e,"")}}var Cr=qx(function(e,t,r){return e+(r?" ":"")+Uv(t)});function je({label:e,children:t}){const r=E.cloneElement(t,{title:t.props.title??e});if(!F.Tooltip.Root){const n=F.Tooltip;return h.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:r})}return h.jsxs(F.Tooltip.Root,{positioning:{placement:"top"},children:[h.jsx(F.Tooltip.Trigger,{asChild:!0,children:r}),h.jsx(F.Portal,{children:h.jsx(F.Tooltip.Positioner,{children:h.jsx(F.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function Ot(){const{border:e}=Ve();return h.jsx(F.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:e})}function Or({children:e,value:t,onValueChange:r,disabled:n,style:o,title:i,icon:a,popupContent:s,labelCase:u="title","aria-label":c}){var P;const{colorMode:l}=Ie(),{background:d,border:f,colorText:p,colorActive:b,colorInactive:y}=Ve(),m=l==="dark",x=E.useId(),g=E.useRef(null),w=E.useRef(null),[v,_]=E.useState(!1);E.useEffect(()=>{const R=w.current;R.setAttribute("popover","auto");const I=O=>_(O.newState==="open");return R.addEventListener("toggle",I),()=>R.removeEventListener("toggle",I)},[]);const C=E.Children.toArray(e).filter(E.isValidElement).map(R=>{const I=R.props;return{value:String(I.value),label:typeof I.children=="string"&&u==="title"?Cr(I.children):I.children,disabled:I.disabled}}),S=()=>{var R;return(R=w.current)==null?void 0:R.hidePopover()},T=()=>{var H,V,re,ce;const R=(H=g.current)==null?void 0:H.getBoundingClientRect(),I=w.current;if(!R||!I)return;const M=((ce=(re=(V=g.current)==null?void 0:V.closest("[data-flow-toolbar-scroll]"))==null?void 0:re.parentElement)==null?void 0:ce.getBoundingClientRect())??R;I.style.maxHeight=`${Math.max(60,Math.max(M.top-40,window.innerHeight-M.bottom-40))}px`;const q=I.getBoundingClientRect();I.style.left=`${Math.max(12,Math.min(R.right-q.width,window.innerWidth-q.width-12))}px`,I.style.top=`${Math.max(12,M.top>=q.height+36?M.top-q.height-24:Math.min(M.bottom+24,window.innerHeight-q.height-12))}px`},k=()=>{var O,M,q,H,V,re;if(n)return;if((O=w.current)==null||O.showPopover(),T(),s){(q=(M=w.current)==null?void 0:M.querySelector("input"))==null||q.focus({preventScroll:!0});return}const R=(H=w.current)==null?void 0:H.querySelectorAll('[role="option"]:not(:disabled)');(re=((V=w.current)==null?void 0:V.querySelector('[aria-selected="true"]:not(:disabled)'))??(R==null?void 0:R[0]))==null||re.focus()};E.useEffect(()=>{if(v){if(n){S();return}return window.addEventListener("resize",T),window.addEventListener("scroll",T,!0),()=>{window.removeEventListener("resize",T),window.removeEventListener("scroll",T,!0)}}},[v,n]);const j=`var(--chakra-colors-${d.replace(".","-")})`;return h.jsxs(h.Fragment,{children:[h.jsx(je,{label:i??c,children:h.jsx(F.chakra.button,{ref:g,type:"button",role:"combobox","data-flow-select-icon":a?"":void 0,"aria-label":c,title:i??c,"aria-haspopup":s?"dialog":"listbox","aria-expanded":v,"aria-controls":x,disabled:n,h:"30px",w:"160px",px:"6px",fontSize:"12px",border:"none",borderRadius:"4px",bg:"transparent",color:a?y:p,display:"flex",alignItems:"center",justifyContent:a?"center":"space-between",gap:2,style:o,onClick:()=>v?S():k(),onKeyDown:R=>{["ArrowDown","ArrowUp"].includes(R.key)&&(R.preventDefault(),k())},children:a??h.jsxs(h.Fragment,{children:[h.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((P=C.find(R=>R.value===t))==null?void 0:P.label)??t}),h.jsx(Z.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),h.jsx(F.chakra.div,{ref:w,id:x,role:s?"dialog":"listbox","aria-label":c,position:"fixed",m:0,p:2,minW:"180px",maxW:"calc(100vw - 24px)",overflowY:"auto",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},bg:d,color:p,borderWidth:1,borderColor:m?f:"gray.300",borderRadius:"30px",boxShadow:`0 0 0 8px color-mix(in srgb, ${j} 40%, transparent), var(--chakra-shadows-lg)`,onKeyDown:R=>{var M,q,H;if(s&&!["Escape","Tab"].includes(R.key))return;const I=[...R.currentTarget.querySelectorAll('[role="option"]:not(:disabled)')],O=I.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(R.key)){R.preventDefault();const V=R.key==="Home"?0:R.key==="End"?I.length-1:(O+(R.key==="ArrowDown"?1:-1)+I.length)%I.length;(M=I[V])==null||M.focus()}else R.key==="Escape"||R.key==="Tab"?(R.key==="Escape"&&(R.preventDefault(),R.stopPropagation()),S(),(q=g.current)==null||q.focus()):R.key.length===1&&R.key!==" "&&((H=I.find((V,re)=>{var ce;return re>O&&((ce=V.textContent)==null?void 0:ce.toLowerCase().startsWith(R.key.toLowerCase()))}))==null||H.focus())},children:s??C.map(R=>h.jsxs(F.chakra.button,{type:"button",role:"option","aria-selected":R.value===t,disabled:R.disabled,tabIndex:-1,display:"flex",alignItems:"center",gap:3,px:3,py:2,w:"100%",borderRadius:"30px",fontSize:"sm",textAlign:"left",bg:"transparent",color:p,_hover:{bg:m?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:m?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var I;S(),(I=g.current)==null||I.focus(),r(R.value)},children:[h.jsx("span",{style:{flex:1},children:R.label}),h.jsx(Z.PiCheck,{size:16,color:`var(--chakra-colors-${b.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:R.value===t?"visible":"hidden"}})]},R.value))})]})}const ve=E.forwardRef(function({icon:t,...r},n){const{colorMode:o}=Ie();return h.jsx(F.IconButton,{ref:n,_hover:{bg:o==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:r.title??r["aria-label"],...r,children:t})}),ht=E.forwardRef(function(t,r){const{themeColor:n}=Ie();return h.jsx(je,{label:"Close",children:h.jsx(ve,{ref:r,size:"sm",variant:"ghost",color:n,focusRingColor:n,...t,"aria-label":t["aria-label"]??"Close selection tools",icon:h.jsx(Z.PiXLight,{size:20,"aria-hidden":"true"})})})}),Ly=gn.default.input`
4
+ `,av=dy.keyframes`
5
+ from { box-shadow: var(--flow-start-shadow); }
6
+ to { box-shadow: var(--flow-rest-shadow); }
7
+ `;function py(e,t=!0,r="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,a=`0 0 0 ${t?8:0}px ${o}`,s=`0 0 0 8px ${o}`;return{boxShadow:a,css:{"--flow-rest-shadow":s,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[r]:{boxShadow:s,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${iv} 1200ms steps(10, end) 600ms`:"none"}}}}}}function Dr(e,t){const{boxShadow:r,css:n}=py(e,!1),o=n["@media (hover: hover)"]["&:hover"];return{borderWidth:"1px",borderStyle:"solid",borderColor:"transparent",boxShadow:r,...n,"--flow-start-shadow":r,"@media (hover: hover)":{"&:hover":{...o,borderColor:t,"@media (prefers-reduced-motion: no-preference)":{animation:`${av} 600ms steps(5, end)`}}}}}const gy=j.createContext(null),yy=j.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function Gr(){return j.useContext(yy)}function Ie(){const e=j.useContext(gy);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function my({config:e,callbacks:t,nodes:r=[],edges:n=[],children:o}){const i=j.useMemo(()=>{var $e,er,Y;const ne=new Map;for(const B of r)($e=B.data)!=null&&$e.id&&ne.set(B.data.id,B);const Be=new Map;for(const B of n)(er=B.data)!=null&&er.id&&Be.set(B.data.id,B);const Je=new Set;for(const B of r)(Y=B.data)!=null&&Y.parent&&Je.add(B.data.parent);return{nodeById:ne,edgeById:Be,parentIds:Je}},[r,n]),a=j.useRef(null),[s,u]=j.useState([]),[c,l]=j.useState(null),[d,f]=j.useState(!0),[p,m]=j.useState(!1),[y,b]=j.useState(!0),[v,g]=j.useState(!1),[w,x]=j.useState(!1),[_,C]=j.useState(!0),[S,T]=j.useState(!1),[k,E]=j.useState("auto"),[P,R]=j.useState(!1),I=e.compactPropertyLayout??P,[O,M]=j.useState({}),q=e.nodeViewModes??O,K=[...i.nodeById.values()].filter(ne=>{var Be;return i.parentIds.has(ne.data.id)||((Be=ne.data.config)==null?void 0:Be.parentContainer)||ne.data.type==="objectView"||ne.data.type==="arrayView"}),V=!!K.length&&K.every(ne=>{var Be,Je,$e;return i.parentIds.has(ne.data.id)||(Be=ne.data.config)!=null&&Be.parentContainer?!!((Je=ne.data.config)!=null&&Je.collapsed):q[ne.data.id]==="icon-label"||(($e=ne.data.config)==null?void 0:$e.labelBelow)&&q[ne.data.id]!=="properties"}),[re,ce]=j.useState("normal"),[he,me]=j.useState(),H=e.edgeRadius??he,N=H!==void 0&&Number.isFinite(H)?Math.min(500,Math.max(0,H)):void 0,[D,W]=j.useState(),z=e.spacing??re,X=typeof z=="number"?Number.isFinite(z)?Math.min(2,Math.max(.5,z)):1:z==="compact"?.5:z==="spacious"?2:1,se=e.backgroundVariant??D??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[Q,G]=j.useState(),J=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:Q,[te,le]=j.useState("blue.500"),[de,Re]=j.useState(!1),ge=j.useRef(t);ge.current=t;const ze=j.useMemo(()=>{const ne=Be=>(...Je)=>{var $e,er;return(er=($e=ge.current)==null?void 0:$e[Be])==null?void 0:er.call($e,...Je)};return{onNodeSelect:ne("onNodeSelect"),onBackgroundClick:ne("onBackgroundClick"),onNodeDeselect:ne("onNodeDeselect"),onNodeDoubleClick:ne("onNodeDoubleClick"),onNodeViewToggle:ne("onNodeViewToggle"),onNodeTypeViewChange:ne("onNodeTypeViewChange"),onNodeCreate:ne("onNodeCreate"),onNodeCreateRequest:ne("onNodeCreateRequest"),onNodeDelete:ne("onNodeDelete"),onNodeLabelChange:ne("onNodeLabelChange"),onNodeContentChange:ne("onNodeContentChange"),onNodeCollapse:ne("onNodeCollapse"),onNodeColorChange:ne("onNodeColorChange"),onNodeBorderColorChange:ne("onNodeBorderColorChange"),onNodeBorderStyleChange:ne("onNodeBorderStyleChange"),onNodeBorderWidthChange:ne("onNodeBorderWidthChange"),onNodeBorderRadiusChange:ne("onNodeBorderRadiusChange"),onNodeIconChange:ne("onNodeIconChange"),onNodeOutlineChange:ne("onNodeOutlineChange"),onNodeAnimationChange:ne("onNodeAnimationChange"),onNodeAnimationVariantChange:ne("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:ne("onEdgeAnimationVariantChange"),onNodeHoverAction:ne("onNodeHoverAction"),onEdgeCreate:ne("onEdgeCreate"),onEdgeSelect:ne("onEdgeSelect"),onEdgeDeselect:ne("onEdgeDeselect"),onEdgeRemove:ne("onEdgeRemove"),onEdgeDelete:ne("onEdgeDelete"),onEdgeColorChange:ne("onEdgeColorChange"),onEdgeTypeChange:ne("onEdgeTypeChange"),onEdgeIconChange:ne("onEdgeIconChange"),onEdgeLabelChange:ne("onEdgeLabelChange"),onEdgeStyleChange:ne("onEdgeStyleChange"),onViewportChange:ne("onViewportChange"),onDirectionChange:ne("onDirectionChange"),onThemeColorChange:ne("onThemeColorChange"),onSpacingChange:ne("onSpacingChange"),onEdgeRadiusChange:ne("onEdgeRadiusChange"),onBackgroundVariantChange:ne("onBackgroundVariantChange"),onEdgeModeChange:ne("onEdgeModeChange"),onCompactPropertyLayoutChange:ne("onCompactPropertyLayoutChange"),onWorkflowContractChange:ne("onWorkflowContractChange"),onArrayModeChange:ne("onArrayModeChange"),onInit:ne("onInit"),onLayoutComplete:ne("onLayoutComplete"),onJsonChange:ne("onJsonChange")}},[]),Fe=e.themeColor||te,He=e.edgeColor||"",ar=e.colorMode||"light",be=e.direction||"LR",_e=e.nodeAlignment??"center",Xe=e.edgeMode==="workflow"?"nodes":e.edgeMode??k,Ke=e.readOnly??!1,Ne=JSON.stringify(e.parentNodeStyle??null),Qe=j.useMemo(()=>e.parentNodeStyle,[Ne]),Ze=e.isZoomMode!==void 0?e.isZoomMode:d,gr=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,fr=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:v,Er=e.isDragMode!==void 0?e.isDragMode:y,we=j.useRef(e);we.current=e;const or=j.useMemo(()=>({get direction(){return we.current.direction},get nodeAlignment(){return we.current.nodeAlignment},get edgeMode(){return we.current.edgeMode},get compactPropertyLayout(){return we.current.compactPropertyLayout},get edgeType(){return we.current.edgeType},get customEdgeTypes(){return we.current.customEdgeTypes},get themeColor(){return we.current.themeColor},get colorMode(){return we.current.colorMode},get readOnly(){return we.current.readOnly},get editable(){return we.current.editable},get minZoom(){return we.current.minZoom},get maxZoom(){return we.current.maxZoom},get backgroundPattern(){return we.current.backgroundPattern},get edgeColor(){return we.current.edgeColor},get parentNodeStyle(){return we.current.parentNodeStyle},get backgroundColor(){return we.current.backgroundColor},get edgeHandles(){return we.current.edgeHandles},get initialViewport(){return we.current.initialViewport},get nodeOverlayActions(){return we.current.nodeOverlayActions},get renderNodeOverlay(){return we.current.renderNodeOverlay},get renderSelectedNodeToolbar(){return we.current.renderSelectedNodeToolbar},get renderSelectedEdgeToolbar(){return we.current.renderSelectedEdgeToolbar},get renderBottomBar(){return we.current.renderBottomBar},get bottomBarExtra(){return we.current.bottomBarExtra},get selectionToolbar(){return we.current.selectionToolbar},get customViews(){return we.current.customViews},get disableKeyboardShortcuts(){return we.current.disableKeyboardShortcuts},get isZoomMode(){return we.current.isZoomMode},get isMultiSelectMode(){return we.current.isMultiSelectMode},get isEdgeHandlesEnabled(){return we.current.isEdgeHandlesEnabled},get isDragMode(){return we.current.isDragMode}}),[]),sr=j.useCallback((ne,Be)=>{var Je;if(Be!=="default"&&Be!=="properties"&&Be!=="icon-label")throw new Error("Unknown node view mode.");M($e=>$e[ne]===Be?$e:{...$e,[ne]:Be}),(Je=t.onNodeViewModeChange)==null||Je.call(t,ne,Be)},[t.onNodeViewModeChange]),wt=j.useMemo(()=>({allNodesIconLabel:V,setAllNodesIconLabel:ne=>{var Be,Je,$e,er;for(const Y of K)i.parentIds.has(Y.data.id)||(Be=Y.data.config)!=null&&Be.parentContainer?!Ke&&!!((Je=Y.data.config)!=null&&Je.collapsed)!==ne&&(($e=t.onNodeCollapse)==null||$e.call(t,Y.data.id,ne)):sr(Y.data.id,ne?"icon-label":"default");(er=t.onAllNodesIconLabelChange)==null||er.call(t,ne)},nodeViewModes:q,setNodeViewMode:sr,spacing:X,setSpacing:ce,edgeRadius:N,setEdgeRadius:me,backgroundVariant:se,setBackgroundVariant:W,themeColor:Fe,setThemeColor:le,backgroundSelected:de,setBackgroundSelected:Re,edgeColor:He,colorMode:ar,direction:be,nodeAlignment:_e,edgeMode:Xe,setEdgeMode:E,compactPropertyLayout:I,setCompactPropertyLayout:R,workflowContract:J,setWorkflowContract:G,parentNodeStyle:Qe,selectedNodeIds:s,setSelectedNodeIds:u,selectedEdgeId:c,setSelectedEdgeId:l,isZoomMode:Ze,setIsZoomMode:f,isMultiSelectMode:gr,setIsMultiSelectMode:m,isDragMode:Er,setIsDragMode:b,isEdgeHandlesEnabled:fr,setIsEdgeHandlesEnabled:g,isArrayNodeMode:w,setIsArrayNodeMode:x,isPinned:_,setIsPinned:C,isPerformanceMode:S,setIsPerformanceMode:T,engineRef:a,callbacks:ze,config:or,readOnly:Ke}),[V,i,sr,t.onNodeCollapse,t.onAllNodesIconLabelChange,q,t.onNodeViewModeChange,Fe,X,se,N,e.backgroundColor,de,He,ar,be,_e,Xe,J,Qe,s,c,Ze,gr,Er,fr,w,_,S,Ke,e.edgeHandles,e.edgeType,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.compactPropertyLayout,I,ze,or]);return h.jsx(gy.Provider,{value:wt,children:h.jsx(yy.Provider,{value:i,children:o})})}function un(e,t=.2){const r=e.replace(/^#/,""),n=parseInt(r,16);let o=n>>16&255,i=n>>8&255,a=n&255;return o=Math.max(0,Math.floor(o*(1-t))),i=Math.max(0,Math.floor(i*(1-t))),a=Math.max(0,Math.floor(a*(1-t))),"#"+((1<<24)+(o<<16)+(i<<8)+a).toString(16).slice(1).toUpperCase()}function cl(e,t,r){const n=s=>{const u=/^#?([0-9a-f]{6})$/i.exec((s==null?void 0:s.trim())??"");return u?parseInt(u[1],16):null},o=n(e),i=n(t);if(o===null||i===null)return null;const a=s=>Math.round((o>>s&255)*(1-r)+(i>>s&255)*r);return"#"+((1<<24)+(a(16)<<16)+(a(8)<<8)+a(0)).toString(16).slice(1).toUpperCase()}const jr=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:un(e,.1),border:un(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"},by=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let t=e;if(t!=null&&t.startsWith("#"))return{secondary:un(e)};let r=String(Number(e.slice(-3))+200);r=e.slice(0,-3).concat(r);let n=String(Number(e.slice(-3))-100);return n=e.slice(0,-3).concat(n),{primary:t,secondary:r,light:n}},ul={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"}},fe=(e,t)=>{var i;if(e==="transparent"||e!=null&&e.startsWith("#"))return e;if(!e)return"whitesmoke";const r=e.replace(/\./g,"-");try{const s=getComputedStyle(document.documentElement).getPropertyValue(`--chakra-colors-${r}`).trim();if(s&&s!=="")return s}catch{}const[n,o]=e.split(".");return n&&o&&((i=ul[n])!=null&&i[Number(o)])?ul[n][Number(o)]:`var(--chakra-colors-${r})`};function tr(e,t,r){return e?r:t}function Jt(e){const[t]=(e==null?void 0:e.split("."))||[],{secondary:r}=by(e),n=jr(t).background,o=jr(t).highlight,i=jr(t).border,a=jr(t).property,s=jr(t).property;let u=jr(t).background,c=jr(t).highlight;return u=e==="transparent"?e:fe(u)+50,c=e==="transparent"?e:fe(c)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:a,propertyColor:s,secondary:r,bgColorFaint:u,highlightColorFaint:c}}function Ve(e=null){const{colorMode:t}=Ie(),r=e==null?void 0:e.includes("gray"),n=t==="dark",o=tr(n,"white","gray.900"),i=tr(n,"gray.100","gray.800"),a=tr(n,"gray.200","blackAlpha.400"),s=tr(n,"gray.200","blackAlpha.600"),u=tr(n,"gray.500","gray.700"),c=tr(n,"gray.700","gray.700"),l=tr(n,"gray.900","gray.900"),d=tr(n,"gray.400","gray.500"),f=tr(n,"gray.400","gray.500"),p=tr(n,"gray.900","gray.200"),m=tr(n,r?"gray.900":"gray.200",r?"gray.200":"gray.900"),y=tr(n,"gray.900","gray.200"),b=tr(n,e&&"#000000",e||"#ffffff"),v=tr(n,e||"#ffffff",e?"#000000":"#ffffff"),g=c,w=tr(n,"gray.300","gray.800"),x=tr(n,"white","blackAlpha.400"),_=tr(n,"green.100","green.700");return{canvas:o,background:i,backgroundSecondary:a,darkBackgroundSecondary:s,border:u,darkColor:l,backgroundWhiteColor:x,borderSecondary:c,colorActive:d,colorInactive:f,iconColor:y,moreIconColor:g,colorText:p,themedColorText:m,logoColor:b,logoColorSecondary:v,darkColorActive:w,greenColor:_}}var Et=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(Et||{});const Bt=["","icon-label","object","text"];var sv=typeof global=="object"&&global&&global.Object===Object&&global,cv=typeof self=="object"&&self&&self.Object===Object&&self,uv=sv||cv||Function("return this")(),ft=uv.Symbol,vy=Object.prototype,lv=vy.hasOwnProperty,dv=vy.toString,_t=ft?ft.toStringTag:void 0;function fv(e){var t=lv.call(e,_t),r=e[_t];try{e[_t]=void 0;var n=!0}catch{}var o=dv.call(e);return n&&(t?e[_t]=r:delete e[_t]),o}var hv=Object.prototype,pv=hv.toString;function gv(e){return pv.call(e)}var yv="[object Null]",mv="[object Undefined]",ll=ft?ft.toStringTag:void 0;function bv(e){return e==null?e===void 0?mv:yv:ll&&ll in Object(e)?fv(e):gv(e)}function vv(e){return e!=null&&typeof e=="object"}var xv="[object Symbol]";function wv(e){return typeof e=="symbol"||vv(e)&&bv(e)==xv}function Cv(e,t){for(var r=-1,n=e==null?0:e.length,o=Array(n);++r<n;)o[r]=t(e[r],r,e);return o}var Ae=Array.isArray,dl=ft?ft.prototype:void 0,fl=dl?dl.toString:void 0;function xy(e){if(typeof e=="string")return e;if(Ae(e))return Cv(e,xy)+"";if(wv(e))return fl?fl.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function Eu(e){return e==null?"":xy(e)}function _v(e,t,r){var n=-1,o=e.length;t<0&&(t=-t>o?0:o+t),r=r>o?o:r,r<0&&(r+=o),o=t>r?0:r-t>>>0,t>>>=0;for(var i=Array(o);++n<o;)i[n]=e[n+t];return i}function Sv(e,t,r){var n=e.length;return r=r===void 0?n:r,!t&&r>=n?e:_v(e,t,r)}var Ev="\\ud800-\\udfff",jv="\\u0300-\\u036f",Rv="\\ufe20-\\ufe2f",kv="\\u20d0-\\u20ff",Pv=jv+Rv+kv,Av="\\ufe0e\\ufe0f",Tv="\\u200d",Ov=RegExp("["+Tv+Ev+Pv+Av+"]");function wy(e){return Ov.test(e)}function Iv(e){return e.split("")}var Cy="\\ud800-\\udfff",Mv="\\u0300-\\u036f",qv="\\ufe20-\\ufe2f",Nv="\\u20d0-\\u20ff",$v=Mv+qv+Nv,Lv="\\ufe0e\\ufe0f",Fv="["+Cy+"]",mu="["+$v+"]",bu="\\ud83c[\\udffb-\\udfff]",Bv="(?:"+mu+"|"+bu+")",_y="[^"+Cy+"]",Sy="(?:\\ud83c[\\udde6-\\uddff]){2}",Ey="[\\ud800-\\udbff][\\udc00-\\udfff]",Dv="\\u200d",jy=Bv+"?",Ry="["+Lv+"]?",zv="(?:"+Dv+"(?:"+[_y,Sy,Ey].join("|")+")"+Ry+jy+")*",Vv=Ry+jy+zv,Wv="(?:"+[_y+mu+"?",mu,Sy,Ey,Fv].join("|")+")",Gv=RegExp(bu+"(?="+bu+")|"+Wv+Vv,"g");function Uv(e){return e.match(Gv)||[]}function Hv(e){return wy(e)?Uv(e):Iv(e)}function Kv(e){return function(t){t=Eu(t);var r=wy(t)?Hv(t):void 0,n=r?r[0]:t.charAt(0),o=r?Sv(r,1).join(""):t.slice(1);return n[e]()+o}}var Zv=Kv("toUpperCase");function Jv(e,t,r,n){for(var o=-1,i=e==null?0:e.length;++o<i;)r=t(r,e[o],o,e);return r}function Yv(e){return function(t){return e==null?void 0:e[t]}}var Xv={À:"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"},Qv=Yv(Xv),ex=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,rx="\\u0300-\\u036f",tx="\\ufe20-\\ufe2f",nx="\\u20d0-\\u20ff",ox=rx+tx+nx,ix="["+ox+"]",ax=RegExp(ix,"g");function sx(e){return e=Eu(e),e&&e.replace(ex,Qv).replace(ax,"")}var cx=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function ux(e){return e.match(cx)||[]}var lx=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function dx(e){return lx.test(e)}var ky="\\ud800-\\udfff",fx="\\u0300-\\u036f",hx="\\ufe20-\\ufe2f",px="\\u20d0-\\u20ff",gx=fx+hx+px,Py="\\u2700-\\u27bf",Ay="a-z\\xdf-\\xf6\\xf8-\\xff",yx="\\xac\\xb1\\xd7\\xf7",mx="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",bx="\\u2000-\\u206f",vx=" \\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",Ty="A-Z\\xc0-\\xd6\\xd8-\\xde",xx="\\ufe0e\\ufe0f",Oy=yx+mx+bx+vx,Iy="['’]",hl="["+Oy+"]",wx="["+gx+"]",My="\\d+",Cx="["+Py+"]",qy="["+Ay+"]",Ny="[^"+ky+Oy+My+Py+Ay+Ty+"]",_x="\\ud83c[\\udffb-\\udfff]",Sx="(?:"+wx+"|"+_x+")",Ex="[^"+ky+"]",$y="(?:\\ud83c[\\udde6-\\uddff]){2}",Ly="[\\ud800-\\udbff][\\udc00-\\udfff]",at="["+Ty+"]",jx="\\u200d",pl="(?:"+qy+"|"+Ny+")",Rx="(?:"+at+"|"+Ny+")",gl="(?:"+Iy+"(?:d|ll|m|re|s|t|ve))?",yl="(?:"+Iy+"(?:D|LL|M|RE|S|T|VE))?",Fy=Sx+"?",By="["+xx+"]?",kx="(?:"+jx+"(?:"+[Ex,$y,Ly].join("|")+")"+By+Fy+")*",Px="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Ax="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",Tx=By+Fy+kx,Ox="(?:"+[Cx,$y,Ly].join("|")+")"+Tx,Ix=RegExp([at+"?"+qy+"+"+gl+"(?="+[hl,at,"$"].join("|")+")",Rx+"+"+yl+"(?="+[hl,at+pl,"$"].join("|")+")",at+"?"+pl+"+"+gl,at+"+"+yl,Ax,Px,My,Ox].join("|"),"g");function Mx(e){return e.match(Ix)||[]}function qx(e,t,r){return e=Eu(e),t=t,t===void 0?dx(e)?Mx(e):ux(e):e.match(t)||[]}var Nx="['’]",$x=RegExp(Nx,"g");function Lx(e){return function(t){return Jv(qx(sx(t).replace($x,"")),e,"")}}var Cr=Lx(function(e,t,r){return e+(r?" ":"")+Zv(t)});function je({label:e,children:t}){const r=j.cloneElement(t,{title:t.props.title??e});if(!F.Tooltip.Root){const n=F.Tooltip;return h.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:r})}return h.jsxs(F.Tooltip.Root,{positioning:{placement:"top"},children:[h.jsx(F.Tooltip.Trigger,{asChild:!0,children:r}),h.jsx(F.Portal,{children:h.jsx(F.Tooltip.Positioner,{children:h.jsx(F.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function It(){const{border:e}=Ve();return h.jsx(F.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:e})}function Or({children:e,value:t,onValueChange:r,disabled:n,style:o,title:i,icon:a,popupContent:s,labelCase:u="title","aria-label":c}){var P;const{colorMode:l}=Ie(),{background:d,border:f,colorText:p,colorActive:m,colorInactive:y}=Ve(),b=l==="dark",v=j.useId(),g=j.useRef(null),w=j.useRef(null),[x,_]=j.useState(!1);j.useEffect(()=>{const R=w.current;R.setAttribute("popover","auto");const I=O=>_(O.newState==="open");return R.addEventListener("toggle",I),()=>R.removeEventListener("toggle",I)},[]);const C=j.Children.toArray(e).filter(j.isValidElement).map(R=>{const I=R.props;return{value:String(I.value),label:typeof I.children=="string"&&u==="title"?Cr(I.children):I.children,disabled:I.disabled}}),S=()=>{var R;return(R=w.current)==null?void 0:R.hidePopover()},T=()=>{var K,V,re,ce;const R=(K=g.current)==null?void 0:K.getBoundingClientRect(),I=w.current;if(!R||!I)return;const M=((ce=(re=(V=g.current)==null?void 0:V.closest("[data-flow-toolbar-scroll]"))==null?void 0:re.parentElement)==null?void 0:ce.getBoundingClientRect())??R;I.style.maxHeight=`${Math.max(60,Math.max(M.top-40,window.innerHeight-M.bottom-40))}px`;const q=I.getBoundingClientRect();I.style.left=`${Math.max(12,Math.min(R.right-q.width,window.innerWidth-q.width-12))}px`,I.style.top=`${Math.max(12,M.top>=q.height+36?M.top-q.height-24:Math.min(M.bottom+24,window.innerHeight-q.height-12))}px`},k=()=>{var O,M,q,K,V,re;if(n)return;if((O=w.current)==null||O.showPopover(),T(),s){(q=(M=w.current)==null?void 0:M.querySelector("input"))==null||q.focus({preventScroll:!0});return}const R=(K=w.current)==null?void 0:K.querySelectorAll('[role="option"]:not(:disabled)');(re=((V=w.current)==null?void 0:V.querySelector('[aria-selected="true"]:not(:disabled)'))??(R==null?void 0:R[0]))==null||re.focus()};j.useEffect(()=>{if(x){if(n){S();return}return window.addEventListener("resize",T),window.addEventListener("scroll",T,!0),()=>{window.removeEventListener("resize",T),window.removeEventListener("scroll",T,!0)}}},[x,n]);const E=`var(--chakra-colors-${d.replace(".","-")})`;return h.jsxs(h.Fragment,{children:[h.jsx(je,{label:i??c,children:h.jsx(F.chakra.button,{ref:g,type:"button",role:"combobox","data-flow-select-icon":a?"":void 0,"aria-label":c,title:i??c,"aria-haspopup":s?"dialog":"listbox","aria-expanded":x,"aria-controls":v,disabled:n,h:"30px",w:"160px",px:"6px",fontSize:"12px",border:"none",borderRadius:"4px",bg:"transparent",color:a?y:p,display:"flex",alignItems:"center",justifyContent:a?"center":"space-between",gap:2,style:o,onClick:()=>x?S():k(),onKeyDown:R=>{["ArrowDown","ArrowUp"].includes(R.key)&&(R.preventDefault(),k())},children:a??h.jsxs(h.Fragment,{children:[h.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((P=C.find(R=>R.value===t))==null?void 0:P.label)??t}),h.jsx(Z.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),h.jsx(F.chakra.div,{ref:w,id:v,role:s?"dialog":"listbox","aria-label":c,position:"fixed",m:0,p:2,minW:"180px",maxW:"calc(100vw - 24px)",overflowY:"auto",bg:d,color:p,borderRadius:"30px",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"},...Dr(E,`var(--chakra-colors-${(b?f:"gray.300").replace(".","-")})`)},onKeyDown:R=>{var M,q,K;if(s&&!["Escape","Tab"].includes(R.key))return;const I=[...R.currentTarget.querySelectorAll('[role="option"]:not(:disabled)')],O=I.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(R.key)){R.preventDefault();const V=R.key==="Home"?0:R.key==="End"?I.length-1:(O+(R.key==="ArrowDown"?1:-1)+I.length)%I.length;(M=I[V])==null||M.focus()}else R.key==="Escape"||R.key==="Tab"?(R.key==="Escape"&&(R.preventDefault(),R.stopPropagation()),S(),(q=g.current)==null||q.focus()):R.key.length===1&&R.key!==" "&&((K=I.find((V,re)=>{var ce;return re>O&&((ce=V.textContent)==null?void 0:ce.toLowerCase().startsWith(R.key.toLowerCase()))}))==null||K.focus())},children:s??C.map(R=>h.jsxs(F.chakra.button,{type:"button",role:"option","aria-selected":R.value===t,disabled:R.disabled,tabIndex:-1,display:"flex",alignItems:"center",gap:3,px:3,py:2,w:"100%",borderRadius:"30px",fontSize:"sm",textAlign:"left",bg:"transparent",color:p,_hover:{bg:b?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:b?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var I;S(),(I=g.current)==null||I.focus(),r(R.value)},children:[h.jsx("span",{style:{flex:1},children:R.label}),h.jsx(Z.PiCheck,{size:16,color:`var(--chakra-colors-${m.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:R.value===t?"visible":"hidden"}})]},R.value))})]})}const ve=j.forwardRef(function({icon:t,...r},n){const{colorMode:o}=Ie();return h.jsx(F.IconButton,{ref:n,_hover:{bg:o==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:r.title??r["aria-label"],...r,children:t})}),pt=j.forwardRef(function(t,r){const{themeColor:n}=Ie();return h.jsx(je,{label:"Close",children:h.jsx(ve,{ref:r,size:"sm",variant:"ghost",color:n,focusRingColor:n,...t,"aria-label":t["aria-label"]??"Close selection tools",icon:h.jsx(Z.PiXLight,{size:20,"aria-hidden":"true"})})})});function Dy({label:e,icon:t,checked:r,onChange:n,disabled:o}){const{themeColor:i,readOnly:a}=Ie(),{colorInactive:s}=Ve();return h.jsx(je,{label:e,children:h.jsx(ve,{"aria-label":e,"aria-pressed":r,icon:h.jsxs(h.Fragment,{children:[t,h.jsx(F.Text,{as:"span",fontSize:"xs",fontWeight:"normal",whiteSpace:"nowrap",children:e})]}),size:"sm",variant:"ghost",width:"auto",px:2,gap:2,color:r?i:s,disabled:o||a,onClick:()=>n(!r)})})}function zy({label:e="Compact layout"}={}){const{compactPropertyLayout:t,setCompactPropertyLayout:r,callbacks:n}=Ie();return h.jsx(Dy,{label:e,checked:t,icon:h.jsx(F.Icon,{as:Z.PiArrowsIn,boxSize:5}),onChange:o=>{var i;r(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const Vy=yn.default.input`
5
8
  appearance: none;
6
9
  width: 100%;
7
10
  height: 24px;
@@ -48,7 +51,7 @@
48
51
  cursor: default;
49
52
  opacity: 0.5;
50
53
  }
51
- `;function bl({label:e,inputLabel:t,value:r,displayValue:n,min:o,max:i,onChange:a}){const s=E.useId(),{readOnly:u,themeColor:c}=Ie(),{colorInactive:l}=Ve(),d=(r-o)/(i-o)*100,f=c.includes(".")?`var(--chakra-colors-${c.replace(".","-")})`:c;return h.jsxs("div",{style:{width:224,maxWidth:"calc(100vw - 64px)",padding:12},children:[h.jsxs("label",{htmlFor:s,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",h.jsx("span",{children:n})]}),h.jsx(Ly,{id:s,"aria-label":t,type:"range",min:o,max:i,step:5,value:r,disabled:u,style:{color:f,accentColor:f,backgroundImage:`linear-gradient(to right, currentColor ${d}%, var(--chakra-colors-${l.replace(".","-")}) ${d}%)`},onChange:p=>a(Number(p.target.value))})]})}const ml={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 Fy(){const{spacing:e,setSpacing:t,edgeRadius:r,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:a,readOnly:s}=Ie(),u=ml[o].icon;return h.jsxs(h.Fragment,{children:[h.jsx(Ot,{}),h.jsx(Or,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:h.jsx(Z.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:s,onValueChange:()=>{},popupContent:h.jsx(bl,{label:"Spacing",inputLabel:"Node spacing percentage",min:50,max:200,value:Math.round(e*100),displayValue:`${Math.round(e*100)}%`,onChange:c=>{var l;t(c/100),(l=a.onSpacingChange)==null||l.call(a,c/100)}}),children:h.jsx("option",{value:"spacing",children:"Spacing"})}),h.jsx(Ot,{}),h.jsx(Or,{"aria-label":"Edge radius",title:`Edge radius: ${r??"Default"}`,icon:h.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:s,onValueChange:()=>{},popupContent:h.jsx(bl,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:r??500,displayValue:r??"Default",onChange:c=>{var l;n(c),(l=a.onEdgeRadiusChange)==null||l.call(a,c)}}),children:h.jsx("option",{value:"radius",children:"Edge radius"})}),h.jsx(Ot,{}),h.jsxs(Or,{"aria-label":"Background variant",title:`Background: ${ml[o].label}`,icon:h.jsx(u,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:s,onValueChange:c=>{var l;i(c),(l=a.onBackgroundVariantChange)==null||l.call(a,c)},children:[h.jsx("option",{value:"dot",children:"Dots"}),h.jsx("option",{value:"grid",children:"Grid"}),h.jsx("option",{value:"steel",children:"Steel"}),h.jsx("option",{value:"none",children:"Solid"}),h.jsx("option",{value:"transparent",children:"Transparent"})]})]})}function By({label:e,icon:t,checked:r,onChange:n,disabled:o}){const{themeColor:i,readOnly:a}=Ie(),{colorInactive:s}=Ve();return h.jsx(je,{label:e,children:h.jsx(ve,{"aria-label":e,"aria-pressed":r,icon:h.jsxs(h.Fragment,{children:[t,h.jsx(F.Text,{as:"span",fontSize:"xs",fontWeight:"normal",whiteSpace:"nowrap",children:e})]}),size:"sm",variant:"ghost",width:"auto",px:2,gap:2,color:r?i:s,disabled:o||a,onClick:()=>n(!r)})})}function Dy({label:e="Compact layout"}={}){const{compactPropertyLayout:t,setCompactPropertyLayout:r,callbacks:n}=Ie();return h.jsx(By,{label:e,checked:t,icon:h.jsx(F.Icon,{as:Z.PiArrowsIn,boxSize:5}),onChange:o=>{var i;r(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const nr=[];for(let e=0;e<256;++e)nr.push((e+256).toString(16).slice(1));function Nx(e,t=0){return(nr[e[t+0]]+nr[e[t+1]]+nr[e[t+2]]+nr[e[t+3]]+"-"+nr[e[t+4]]+nr[e[t+5]]+"-"+nr[e[t+6]]+nr[e[t+7]]+"-"+nr[e[t+8]]+nr[e[t+9]]+"-"+nr[e[t+10]]+nr[e[t+11]]+nr[e[t+12]]+nr[e[t+13]]+nr[e[t+14]]+nr[e[t+15]]).toLowerCase()}let Kn;const $x=new Uint8Array(16);function Lx(){if(!Kn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Kn=crypto.getRandomValues.bind(crypto)}return Kn($x)}const Fx=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),vl={randomUUID:Fx};function Eu(e,t,r){var o;if(vl.randomUUID&&!e)return vl.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??Lx();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,Nx(n)}const yn={label:"Untitled",description:"",isTask:!1,isLocked:!1},Ru={id:null,type:"text",data:{...yn,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"}}},xl={id:null,type:"objectView",data:{...yn,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},Bx={id:null,type:"arrayView",data:{...yn,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"}}},wl={id:null,type:"workflowStep",data:{...yn,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},fr=e=>typeof e=="object",zy=e=>Array.isArray(e),Dx=["order","position","selected","locked","grabbed","grabbable","scratch"],Dr=e=>Object.entries(e).reduce((t,[r,n])=>(!fr(n)&&!r.startsWith("$")&&(t[r]=n),t),{}),ku=(e,t)=>typeof e=="string"&&e.startsWith("$")?Zn(e,t):fr(e)&&!zy(e)?Object.entries(e).reduce((r,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete r["..."],r[n]={...Zn(o,t),...e}):typeof o=="string"&&o.startsWith("$")?r[n]=Zn(o,t):r[n]=o,r),{}):e,zr=e=>Object.entries(e).reduce((t,[r,n])=>(fr(n)&&r&&n&&!r.startsWith("$")&&(Dx.includes(r)&&(r=r+"#"),t[r]=n),t),{}),Zr=(e,t,{label:r,parent:n=void 0},o,i=null)=>(i!==null&&(fr(i)||zy(i))&&(i=JSON.stringify(i,null,2)),{data:{parent:n,...e.data,id:t,text:r||"",label:r,code:i||null,type:e.type,description:o}}),Br=(e,t,r=null,n=null,o=null,i=!1,a=null)=>({data:{id:Eu(),source:o?t:e,target:o?e:t,label:n||"",isInverted:o,isEdgeAnimated:i,parent:a}}),Vr=(e,t=[])=>{const r={},n={};let o=[];if(e)for(const[i,a]of Object.entries(e))i.startsWith("$")&&i!=="$"?r[i.slice(1)]=a:i!=="$"?n[i]=a:i==="$"&&(o=a);return{newConfig:r,updatedObject:n,arrayObject:o}},ct=(e,t)=>{let r=xl;const{view:n,borderColor:o,borderRadius:i,bgColor:a,textColor:s,fontSize:u,stepType:c}=t;e=n||e,c?r={...wl}:e==="object"?r=xl:e==="text"?r=Ru:e==="array"?r=Bx:e==="workflowStep"&&(r={...wl});const l=r.data.viewProps;return r.data.viewProps={...l,borderRadius:i||(c?15:53),bgColor:a,borderColor:o,textColor:s,fontSize:u},r.data.config=t,{config:r}},Bt=(e,t)=>(e=t.find(n=>n.data.id===e)?`${e}.#`:e,e),Zn=(e,{ids:t,jsnObjct:r})=>{if(typeof e=="string"&&(e!=null&&e.startsWith("$"))){const n=e.replace("$","").replace("*","");e==null||e.endsWith("*");const o=t.find(s=>s.split(".").slice(-1)[0]===n||n===s);if(!o)return e;const i=zx(o,r);return JSON.stringify(i).includes(e)?e:i||e}return e},zx=(e,t)=>{let r=e.split(".").splice(1);return r=r[r.length-1]==="#"||r[r.length-1].includes("{")?r.slice(0,-2):r,(i=>r.reduce((a,s)=>{s=s.replace("[","").replace("]","");const{arrayObject:u}=Vr(a);return a=u.length?u:a,a[s]},i))(t)};function lt(e,t="root",r=[]){try{const{arrayObject:n}=Vr(e);n.length&&(e=n);const o=Dr(e),i=zr(e);return fr(e)?(Pe(e)||Pe(e)&&t==="root"||!Pe(e)&&Object.keys(o).length||t==="root")&&r.push(t):r.push(t),Object.keys(i).length&&!Pe(e)?It({chldPth:null,itrblObjct:i,nodes:r,path:t}):Pe(e)&&e.forEach((a,s)=>{const u=Dr(a),c=zr(a),{newConfig:l,arrayObject:d}=Vr(a);let f=`${t}.${s}`;fr(a)?Object.keys(u).length?(lt(u,f,r),Object.keys(c).length&&!Pe(a)&&It({chldPth:f,itrblObjct:c,nodes:r,path:t})):Object.keys(c).length&&!Pe(a)?It({chldPth:f,itrblObjct:c,nodes:r,path:t}):Pe(a)&&Vy({chldPth:f,item:a,nodes:r,path:t}):r.push(f)}),{nodes:r}}catch{return{nodes:r}}}const It=({chldPth:e,itrblObjct:t,nodes:r,path:n})=>Object.entries(t).forEach(([o,i],a)=>{const s=Dr(i),u=zr(i),{newConfig:c,arrayObject:l}=Vr(i);l.length&&(i=l),n.split(".").slice(0,2).join(".");let d=e?`${e}.${o}`:`${n}.${o}`;if(fr(i)&&!Pe(i)){const f=Object.keys(s).length===0;if(f&&(ct("array",c),r.push(d)),Object.keys(s).length){const p=Pe(i)?`${i.length||""}`:`{${Object.keys(i).length||""}}`;let b=d;f&&(b=`${d}.${p}`),lt(i,b,r)}else Object.keys(u).length&&!Pe(i)?It({chldPth:d,itrblObjct:u,path:d,nodes:r}):lt(i,d,r)}else Pe(i)&&lt(i,d,r)}),Vy=({chldPth:e,item:t,nodes:r,path:n})=>t.forEach((o,i)=>{let a=`${e}.${i}`;const s=zr(o),u=Dr(o);fr(o)?!Pe(o)&&Object.keys(u).length?lt(o,a,r):Object.keys(s).length&&!Pe(o)?It({chldPth:a,itrblObjct:s,path:n,nodes:r}):Pe(o)&&Vy({chldPth:a,item:o,nodes:r,path:n}):r.push(a)}),un=[];let Mt;function Yr(e,t="root",r=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},a={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:r,edges:n};const s=e;if(!Mt){const{nodes:l}=lt(e);Mt={ids:l,jsnObjct:e}}let{hideDefaultObject:u,sprtObjctKy:c}=i;try{t=Bt(t,r);const{newConfig:l,arrayObject:d}=Vr(e),f=Object.keys(a).length>0?a:l;d.length&&(e=d);const p=Dr(e),b=zr(e),{label:y,collapsed:m,parent:x}=f;if(!fr(e))r.push(Zr(Ru,t,{label:y||t,parent:x},e,s));else if(Pe(e)||Pe(e)&&t==="root"){const{config:g}=ct("array",f),w=Pe(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,v=t==="root"?o:`${o} ${w}`;r.push(Zr(g,t,{label:y||v,parent:x},e,Pe(s)?{[o]:s}:s))}else if(!Pe(e)&&Object.keys(p).length||t==="root"){const{config:g}=ct(null,f),w=Pe(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,v=t.split("."),_=v[v.length-1];let C=isNaN(Number(_))?null:Number(_)+1;const S=isNaN(Number(_))?_:v[v.length-2]+" "+C,T=t==="root"?o:S;let k=!1;Number.isNaN(Number(o))||(k=!0);const j=e;if(y){const{config:P}=ct("object",f);r.push(Zr(P,t,{label:y||`${y} ${w}`,parent:x},p,j))}else g.data.headerTitle=T,r.push(Zr(g,t,{label:y,parent:x},p,j))}return m||(Object.keys(b).length&&!Pe(e)?qt({flowConfig:i,chldPth:null,edges:n,isInverted:null,itrblObjct:b,nodes:r,path:t,newConfig:f}):Pe(e)&&e.forEach((g,w)=>{g=ku(g,Mt);const v=g,_=Dr(g),C=zr(g),{newConfig:S,arrayObject:T}=Vr(g);T.length&&(g=T);const{config:k}=ct(typeof g=="string"?"text":"array",S),{hideConfig:j,sourceLabel:P,label:R,isEdgeAnimated:I,parent:O}=S;u=u||j;const M=t==="root"&&i.isCntr,q=t.split(".").slice(0,2).join("."),H=un.includes(q),V=i.isCntr&&H||w%2===0&&M;let re=`${t}.${w}`;re=Bt(re,r),V&&un.push(re),fr(g)?Object.keys(_).length&&!Pe(g)?(n.push(Br(t,re,null,P,V,I)),Yr(g,re,r,n,R||w,i,S)):Object.keys(C).length&&!Pe(g)?qt({flowConfig:i,chldPth:re,isInverted:V,edges:n,itrblObjct:C,nodes:r,path:t,newConfig:S,forceIsInverted:!0}):Pe(g)?Wy({flowConfig:i,chldPth:re,edges:n,isInverted:V,item:g,nodes:r,path:t}):fr(g)&&qt({flowConfig:i,chldPth:re,isInverted:V,edges:n,itrblObjct:[g],nodes:r,path:t,newConfig:S}):(n.push(Br(t,re,null,P,V,I)),r.push(Zr(k,re,{label:R||String(g),parent:O},g,v)))})),{nodes:r,edges:n}}catch{return{nodes:r,edges:n}}}const qt=({chldPth:e,flowConfig:t,edges:r,itrblObjct:n,nodes:o,isInverted:i,path:a,newConfig:s,forceIsInverted:u=!1})=>{let{hideDefaultObject:c,sprtObjctKy:l}=t;return Object.entries(n).forEach(([d,f],p)=>{f=ku(f,Mt);const b=f,y=Dr(f),m=zr(f),{newConfig:x,arrayObject:g}=Vr(f);g.length&&(f=g);const{hideConfig:w,sourceLabel:v,label:_,content:C,target:S,targetLabel:T,collapsed:k,isEdgeAnimated:j,parent:P}=x;c=c||w;const R=a==="root"&&t.isCntr,I=a.split(".").slice(0,2).join("."),O=un.includes(I);u||(i=t.isCntr&&O||p%2===0&&R);let M=e?`${e}.${d}`:`${a}.${d}`;if(M=Bt(M,o),i&&un.push(M),S&&r.push(Br(M,S,null,T,i,j)),fr(f)&&!Pe(f)){r.push(Br(a,M,null,v,i,j));const q=l||Object.keys(y).length===0;if(q){const H=C?"object":"array",{config:V}=ct(H,x);V.data.headerTitle=C?_:null,o.push(Zr(V,M,{label:_||d,parent:P},f,b))}if(Object.keys(y).length&&!c){const H=Pe(f)?` ${f.length||""}`:`{${Object.keys(f).length||""}}`;let V=M;q&&(V=`${M}.${H}`,V=Bt(V,o),r.push(Br(M,V,null,v,i,j))),Yr(f,V,o,r,_||d,t,x)}else Object.keys(m).length&&!Pe(f)?qt({chldPth:M,flowConfig:t,itrblObjct:m,path:M,edges:r,nodes:o,newConfig:x,isInverted:i}):Yr(f,M,o,r,d,t,x)}else Pe(f)&&(r.push(Br(a,M,null,v,i,j)),Yr(f,M,o,r,d,t,x))})},Wy=({flowConfig:e,chldPth:t,edges:r,isInverted:n,item:o,nodes:i,path:a})=>o.forEach((s,u)=>{let c=`${t}.${u}`;c=Bt(c,i);const l=s;s=ku(s,Mt);const d=zr(s),f=Dr(s),{newConfig:p}=Vr(s),{collapsed:b,label:y,parent:m,sourceLabel:x,isEdgeAnimated:g,content:w}=p;fr(s)?!Pe(s)&&Object.keys(f).length?(r.push(Br(a,c,null,x,n,g)),Yr(s,c,i,r,u,e,p)):Object.keys(d).length&&!Pe(s)&&!b?qt({chldPth:c,flowConfig:e,itrblObjct:d,path:a,edges:r,nodes:i,isInverted:n,newConfig:p}):Pe(s)&&Wy({flowConfig:e,chldPth:c,edges:r,isInverted:n,item:s,nodes:i,path:a}):(r.push(Br(a,c,null,x,n,g)),i.push(Zr(Ru,c,{label:y||String(s),parent:m},s,l)))});function Vx(e,t){const r=new Set,n=c=>{if(!(!c||typeof c!="object")){typeof c.$parent=="string"&&r.add(c.$parent);for(const[l,d]of Object.entries(c))(!l.startsWith("$")||l==="$")&&n(d)}};if(n(e),!r.size)return t;const o=new Map(t.nodes.map(c=>[c.data.id,c])),i=c=>{var p,b;let l=c.data.id;const d=new Set([c.data.id]);let f=c.data.parent;for(;f&&!d.has(f);)r.has(f)&&o.has(f)&&((p=xe(e,f))!=null&&p.$collapsed)&&(l=f),d.add(f),f=(b=o.get(f))==null?void 0:b.data.parent;return l},a=new Map(t.nodes.map(c=>[c.data.id,i(c)])),s=t.nodes.filter(c=>a.get(c.data.id)===c.data.id).map(c=>{if(!r.has(c.data.id))return c;const l=xe(e,c.data.id),d=!!(l!=null&&l.$collapsed);return{...c,data:{...c.data,...d?{type:"arrayView"}:{},config:{...c.data.config,parentContainer:!0,collapsed:d,...d?{labelBelow:!0,icon:(l==null?void 0:l.$icon)||"PiStack"}:{}}}}}),u=new Set(s.map(c=>c.data.id));return{nodes:s,edges:t.edges.flatMap(c=>{const l=a.get(c.data.source),d=a.get(c.data.target);return!l||!d||!u.has(l)||!u.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}}}]})}}function bn(e){if(!Array.isArray(e==null?void 0:e.$connections))return[];const t=new Map;return e.$connections.flatMap((r,n)=>{if(!r||typeof r!="object")return[];const o=r;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]),a=t.get(i)??0;return t.set(i,a+1),[{value:o,key:`${i}#${a}`,index:n}]})}function Gy(e,t,r){const n=bn(e).find(u=>u.key===t);if(!n)return e;const o=r(n.value),i=e.$connections.flatMap((u,c)=>c===n.index?o?[o]:[]:[u]);if(i.length)return{...e,$connections:i};const{$connections:a,...s}=e;return s}function Wx(e){const t=[],r=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,a)=>r(i,`${o}.${a}`));for(const i of bn(n)){const a=i.value;t.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:a.target,type:typeof a.type=="string"?a.type:void 0,sourceProperty:a.sourceProperty,targetProperty:a.targetProperty,icon:typeof a.icon=="string"?a.icon:void 0,label:typeof a.label=="string"?a.label:void 0,color:typeof a.color=="string"?a.color:void 0,isEdgeDashed:a.style==="dashed",isEdgeAnimated:a.style==="animated",...["dashed","traveling"].includes(a.animationVariant)?{edgeAnimationVariant:a.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,a])=>[i,i==="$"?r(a,o):i.startsWith("$")?a:r(a,`${o}.${i}`)]))};return{json:r(e,"root"),edges:t}}const Dt="root",Cl=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Ir(e){const t=e.split(".");for(t[0]===Dt&&t.shift();t.length&&Cl(t[t.length-1]);)t.pop();return t.filter(r=>!Cl(r))}function mn(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function xe(e,t){return Ir(t).reduce((r,n)=>{var o;if(r!=null)return(o=mn(r))==null?void 0:o[n]},e)}function Gx(e){return Array.isArray(e)?[...e]:{...e}}function hr(e,t,r){const n=Ir(t),o=(i,a)=>{if(a===n.length)return r(i);const s=n[a],u=mn(i);if(u==null||typeof u!="object")return i;const c=o(u[s],a+1);if(Object.is(c,u[s]))return i;const l=Gx(u);return l[s]=c,u!==i?{...i,$:l}:l};return o(e,0)}function Tr(e,t,r){const n=r===""&&t!=="$content"||r===void 0||r===null;if(Array.isArray(e))return n?e:{[t]:r,$:[...e]};const o=e!=null&&typeof e=="object"?{...e}:{};return e!=null&&typeof e!="object"&&(o.$label=String(e)),n?delete o[t]:o[t]=r,o}function ir(e,t,r,n){return hr(e,t,o=>r==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:Tr(o,r,n))}const Uy=(e,t,r)=>ir(e,t,"$collapsed",r);function zt(e){if(e.connection)return{address:e.connection.address,kind:"connection"};const t=e.collapsedEndpoints??e,r=e.isInverted?t.target:t.source,n=e.isInverted?t.source:t.target,o=Ir(r).join("."),i=Ir(n).join(".");return i.startsWith(o?o+".":"")&&i!==o?{address:n,kind:"hierarchy"}:o.startsWith(i?i+".":"")&&o!==i?{address:r,kind:"hierarchy"}:{address:r,kind:"target"}}function Fr(e,t,r,n){if(t.connection){const s=t.connection;return hr(e,s.address,u=>Gy(u,s.key,c=>{if(r==="$edgeIcon")return Tr(c,"icon",n);if(r==="$edgeType")return Tr(c,"type",n);if(r==="$edgeAnimationVariant")return Tr(c,"animationVariant",n);if(r==="$sourceLabel"||r==="$edgeColor")return Tr(c,r==="$sourceLabel"?"label":"color",n);const l=r==="$isEdgeAnimated"?"animated":"dashed";return n?{...c,style:l}:c.style===l?Tr(c,"style",void 0):c}))}const{address:o,kind:i}=zt(t),a=i==="target"&&r==="$sourceLabel"?"$targetLabel":i==="target"&&r==="$edgeType"?"$targetEdgeType":i==="target"&&r==="$edgeIcon"?"$targetIcon":i==="target"&&r==="$edgeAnimationVariant"?"$targetAnimationVariant":r;return hr(e,o,s=>Tr(s,a,n))}const Hy=(e,t,r)=>Fr(Fr(e,t,"$isEdgeAnimated",r==="animated"||void 0),t,"$isEdgeDashed",r==="dashed"||void 0);function Pu(e,t,r,n){let o=n||"";const i=hr(e,t,s=>{const u=mn(s);if(Array.isArray(u)){o=String(u.length);const l=[...u,r];return u===s?l:{...s,$:l}}const c=s!=null&&typeof s=="object"&&!Array.isArray(s)?{...s}:s!=null&&typeof s!="object"?{$label:String(s)}:{};if(!o){let l=1;for(;`node_${l}`in c;)l++;o=`node_${l}`}return c[o]=r,c}),a=Ir(t);return{json:i,address:[Dt,...a,o].join(".")}}function Ky(e,t){const r=Ir(t);if(!r.length)return e;const n=r[r.length-1],o=[Dt,...r.slice(0,-1)].join(".");return hr(e,o,i=>{const a=mn(i);if(a==null||typeof a!="object"||!Object.prototype.hasOwnProperty.call(a,n))return i;if(Array.isArray(a)){const c=a.filter((l,d)=>String(d)!==n);return a===i?c:{...i,$:c}}const{[n]:s,...u}=i;return u})}const Zy=(e,t,r,n)=>ir(n?hr(e,t,o=>Tr(o,"$targetLabel",n)):e,t,"$target",r);function Au(e,t,r){const n=xe(e,t);return bn(n).some(({value:i})=>i.target===r.target&&i.sourceProperty===r.sourceProperty&&i.targetProperty===r.targetProperty)?e:hr(e,t,i=>Tr(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...r,id:r.id||Eu()}]))}function Jy(e,t){if(t.connection){const i=t.connection;return bn(xe(e,i.address)).some(a=>a.key===i.key)?{json:hr(e,i.address,a=>Gy(a,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:r,kind:n}=zt(t);return n==="hierarchy"?xe(e,r)===void 0?{json:e,removed:!1}:{json:hr(e,r,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:hr(e,r,i=>{const{$target:a,$targetLabel:s,...u}=i||{};return u}),removed:!0}}function mu(e,t={}){var x;const r=Wx(e),{nodes:n,edges:o}=Yr(r.json,Dt,[],[],t.title||"untitled",{hideDefaultObject:!!t.hideDefaultObject,sprtObjctKy:!!t.separateObjectKeys,isCntr:!!t.isCenter}),i=new Set(n.map(g=>g.data.id)),a=new Map;for(const g of n){const w=g.data.id;if(!w.endsWith(".0")||xe(e,w)!==void 0)continue;const v=w.slice(0,-2),_=xe(e,v);!i.has(v)&&_&&typeof _=="object"&&!Array.isArray(_)&&typeof _.$label=="string"&&Object.keys(_).every(C=>C.startsWith("$")&&C!=="$")&&a.set(w,v)}const s=g=>a.get(g)??g,u=new Set(n.flatMap(g=>g.data.parent?[s(g.data.parent)]:[])),c=n.map(g=>{var T;const w=s(g.data.id),v=xe(e,w),_={...g.data,id:w},C=v&&typeof v=="object"&&!Array.isArray(v)&&"$"in v?v.$:v;if((Array.isArray(C)?C.length>0:C&&typeof C=="object"&&Object.keys(C).some(k=>!k.startsWith("$")))&&(_.config={..._.config,collapsed:!!v.$collapsed}),u.has(w)||(_.viewProps={..._.viewProps},delete _.viewProps.borderWidth),!v||typeof v!="object"||Array.isArray(v))return{data:_};if(v.$form&&typeof v.$form=="object"&&(_.config={..._.config,form:v.$form},_.type="objectView"),Array.isArray(v.$ports)){const k=v.$ports.filter(j=>j&&typeof j.id=="string"&&["source","target"].includes(j.role)&&["top","right","bottom","left"].includes(j.side));_.config={..._.config,ports:k}}return _.parent&&(_.parent=s(_.parent)),typeof v.$label=="string"&&(_.label=v.$label,_.headerTitle=v.$label),typeof v.$subtitle=="string"&&(_.config={..._.config,subtitle:v.$subtitle}),typeof v.$outline=="boolean"&&(_.viewProps={..._.viewProps,outline:v.$outline}),["solid","dashed","dotted","double"].includes(v.$borderStyle)&&(_.viewProps={..._.viewProps,borderStyle:v.$borderStyle}),Number.isFinite(v.$borderWidth)&&v.$borderWidth>=0&&(_.viewProps={..._.viewProps,borderWidth:v.$borderWidth}),Number.isFinite(v.$borderRadius)&&v.$borderRadius>=0&&(_.viewProps={..._.viewProps,borderRadius:v.$borderRadius}),typeof v.$isNodeAnimated=="boolean"&&(_.isNodeAnimated=v.$isNodeAnimated),["traveling","pulse"].includes(v.$nodeAnimationVariant)&&(_.nodeAnimationVariant=v.$nodeAnimationVariant),typeof v.$content=="string"&&(_.config={..._.config,content:v.$content},v.$view||(_.type="objectView")),(((T=_.config)==null?void 0:T.collapsed)!==void 0||v.$collapsed!==void 0||v.$icon!==void 0)&&(_.config={..._.config||{}},(v.$collapsed!==void 0||_.config.collapsed!==void 0)&&(_.config.collapsed=!!v.$collapsed),v.$icon!==void 0&&(_.config.icon=v.$icon)),{data:_}}),l=new Map,d=o.map(g=>{const w=s(g.data.source),v=s(g.data.target),_=`${w}->${v}`,C=l.get(_)??0;l.set(_,C+1);const S={...g.data,id:C?`${_}#${C}`:_,source:w,target:v},T=zt(S),k=xe(e,T.address);if(k&&typeof k=="object"){const j=k[T.kind==="target"?"$targetEdgeType":"$edgeType"];typeof j=="string"&&(S.type=j);const P=k[T.kind==="target"?"$targetIcon":"$edgeIcon"];typeof P=="string"&&(S.icon=P),k.$isEdgeAnimated!==void 0&&(S.isEdgeAnimated=!!k.$isEdgeAnimated);const R=k[T.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(R)&&(S.edgeAnimationVariant=R),k.$isEdgeDashed!==void 0&&(S.isEdgeDashed=!!k.$isEdgeDashed),k.$edgeColor&&(S.color=k.$edgeColor)}return{data:S}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const g=c.findIndex(w=>w.data.id===Dt);g!==-1&&c.splice(g,1)}const f=new Set(c.map(g=>g.data.id));for(let g=d.length-1;g>=0;g--){const w=d[g].data,v=zt(w);(!f.has(w.source)||!f.has(w.target)||v.kind==="hierarchy"&&((x=xe(e,v.address))==null?void 0:x.$hideParentEdge)===!0)&&d.splice(g,1)}d.push(...r.edges.filter(g=>f.has(g.data.source)&&f.has(g.data.target)));const p=Vx(e,{nodes:c,edges:d}),b=p.nodes.filter(g=>{var w;return(w=g.data.config)==null?void 0:w.collapsed}).map(g=>Ir(g.data.id));if(!b.length)return p;const y=p.nodes.filter(g=>{const w=Ir(g.data.id);return!b.some(v=>v.length<w.length&&v.every((_,C)=>_===w[C]))}),m=new Set(y.map(g=>g.data.id));return{nodes:y,edges:p.edges.filter(g=>m.has(g.data.source)&&m.has(g.data.target))}}function Ux(e,t){const r=new Set(e.filter(u=>{var c,l;return(l=(c=u.data)==null?void 0:c.config)==null?void 0:l.collapsed}).map(u=>u.data.id));if(!r.size)return{nodes:e,edges:t};const n=new Map(e.map(u=>[u.data.id,u])),o=new Set(e.map(u=>u.data.parent).filter(Boolean)),i=new Map(e.map(u=>{var f;let c=u.data.id,l=u.data.parent;const d=new Set([c]);for(;l&&!d.has(l);)r.has(l)&&(c=l),d.add(l),l=(f=n.get(l))==null?void 0:f.data.parent;return[u.data.id,c]})),a=new Map;for(const u of t){const c=u.data.isInverted?u.data.target:u.data.source,l=u.data.isInverted?u.data.source:u.data.target;(a.get(c)??a.set(c,[]).get(c)).push(l)}const s=new Set(e.filter(u=>i.get(u.data.id)!==u.data.id).map(u=>u.data.id));for(const u of r){if(o.has(u))continue;const c=[...a.get(u)||[]];for(;c.length;){const l=c.pop();r.has(l)||s.has(l)||(s.add(l),c.push(...a.get(l)||[]))}}return{nodes:e.filter(u=>!s.has(u.data.id)).map(u=>{var c;return r.has(u.data.id)&&o.has(u.data.id)?{...u,data:{...u.data,type:"arrayView",label:u.data.label??u.data.headerTitle,config:{...u.data.config,parentContainer:!0,labelBelow:!0,icon:((c=u.data.config)==null?void 0:c.icon)||"PiStack"}}}:u}),edges:t.flatMap(u=>{const c=i.get(u.data.source)??u.data.source,l=i.get(u.data.target)??u.data.target;return s.has(c)||s.has(l)?[]:c===u.data.source&&l===u.data.target?[u]:c===l?[]:[{...u,data:{...u.data,source:c,target:l,collapsedEndpoints:u.data.collapsedEndpoints??{source:u.data.source,target:u.data.target}}}]})}}function Tu(e,t){const r=JSON.parse(e);let n=512;const o=(a,s=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!a||typeof a!="object"||Array.isArray(a))throw new Error("Expected a JSON Schema object.");const u=new Set(["$schema","$id","$defs","definitions","$ref","title","description","default","examples","type","properties","required","items","enum","const","anyOf","additionalProperties"]);for(const l of Object.keys(a))if(!u.has(l))throw new Error(`Unsupported JSON Schema keyword: ${l}`);const c=["$schema","$id","$defs","definitions","title","description","default","examples"];if(a.$ref){if(Object.keys(a).some(d=>!["$ref","title","description"].includes(d)))throw new Error("Use $ref without sibling constraints.");if(typeof a.$ref!="string"||!a.$ref.startsWith("#/")||s.includes(a.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let l=r;for(const d of a.$ref.slice(2).split("/")){const f=d.replace(/~1/g,"/").replace(/~0/g,"~");if(!l||!Object.prototype.hasOwnProperty.call(l,f))throw new Error(`Unresolved reference: ${a.$ref}`);l=l[f]}return o(l,[...s,a.$ref])}if(a.anyOf){if(!Array.isArray(a.anyOf)||!a.anyOf.length||Object.keys(a).some(l=>l!=="anyOf"&&!c.includes(l)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:a.anyOf.map(l=>o(l,s))}}if(Object.prototype.hasOwnProperty.call(a,"const")||a.enum){if(Object.keys(a).some(f=>![...c,"const","enum","type"].includes(f))||a.enum&&Object.prototype.hasOwnProperty.call(a,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const l=Object.prototype.hasOwnProperty.call(a,"const")?[a.const]:a.enum;if(!Array.isArray(l)||!l.length)throw new Error("Expected a nonempty enum.");return{kind:"union",types:l.map(f=>{if(f!==null&&!["string","number","boolean"].includes(typeof f))throw new Error("Only primitive literals are supported.");const p=f===null?"null":typeof f;if(a.type&&!(Array.isArray(a.type)?a.type:[a.type]).some(b=>b===p||b==="integer"&&Number.isInteger(f)))throw new Error("Literal does not match its declared type.");return{kind:"literal",value:f}})}}if(Array.isArray(a.type)){if(!a.type.length||a.type.some(l=>typeof l!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(a).some(l=>l!=="type"&&!c.includes(l)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:a.type.map(l=>o({type:l},s))}}if((a.properties||a.required||a.additionalProperties!==void 0)&&a.type!=="object"&&a.type!==void 0)throw new Error("Object constraints require an object type.");if(a.items&&a.type!=="array")throw new Error("items requires an array type.");if(a.type==="object"||a.properties){if(a.additionalProperties!==void 0&&a.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!a.properties||typeof a.properties!="object"||Array.isArray(a.properties))throw new Error("Object schemas must declare properties.");if(a.required!==void 0&&(!Array.isArray(a.required)||a.required.some(d=>typeof d!="string"||!Object.prototype.hasOwnProperty.call(a.properties,d))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(a.properties).map(([d,f])=>[d,{type:o(f,s),optional:!(a.required??[]).includes(d)}]))}}if(a.type==="array")return{kind:"array",items:o(a.items,s)};if(["string","number","integer","boolean","null"].includes(a.type))return{kind:a.type};throw new Error("Every property must declare a supported type.")},i=o(r);if(i.kind!=="object")throw new Error("The root schema must be an object keyed by node ID.");if(Object.values(i.properties).some(a=>a.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:t,nodes:i.properties}}async function Ou(e,t,r,n={}){var b;let o=512;const i=await import("typescript"),a=i.createSourceFile(t,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),s=a.parseDiagnostics;if(s!=null&&s.length)throw new Error("Invalid TypeScript syntax.");const u=new Map;for(const y of a.statements){if(!i.isInterfaceDeclaration(y)&&!i.isTypeAliasDeclaration(y))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((b=y.typeParameters)!=null&&b.length||u.has(y.name.text))throw new Error("Generics and duplicate declarations are not supported.");u.set(y.name.text,y)}const c=(y,m)=>{var _;const x={},g=y.find(C=>i.isIndexSignatureDeclaration(C));let w;if(g&&n.allowJson&&i.isIndexSignatureDeclaration(g)){if(y.filter(C=>i.isIndexSignatureDeclaration(C)).length!==1||g.parameters.length!==1||((_=g.parameters[0].type)==null?void 0:_.kind)!==i.SyntaxKind.StringKeyword||!g.type)throw new Error("Only one string-keyed index signature is supported for forms.");w=d(g.type,m)}return{kind:"object",properties:Object.fromEntries(y.filter(C=>C!==g||!w).map(C=>{if(!i.isPropertySignature(C)||!C.type||!C.name||!i.isIdentifier(C.name)&&!i.isStringLiteral(C.name))throw new Error("Only explicitly typed named properties are supported.");const S=d(C.type,m),T=n.allowJson?i.getJSDocTags(C).filter(k=>k.tagName.text==="port"):[];if(T.length>1)throw new Error(`Duplicate port declaration: ${C.name.text}`);if(T.length){const[k,j,P]=String(T[0].comment??"").trim().split(/\s+/);if(k!=="config"||!j||P||!u.has(j))throw new Error(`Config port ${C.name.text} requires @port config ResourceType`);const R=S.kind==="array";if((S.kind==="array"?S.items.kind:S.kind)!=="string")throw new Error(`Config port ${C.name.text} must be a string or string array reference`);x[C.name.text]={kind:"config",resourceType:j,multiple:R}}return[C.name.text,{type:S,optional:!!C.questionToken}]})),...w?{additionalProperties:w}:{},...Object.keys(x).length?{ports:x}:{}}},l=(y,m)=>{var _;if(m.includes(y))throw new Error("Recursive types are not supported.");const x=u.get(y);if(!x)throw new Error(`Unknown type: ${y}`);let g;if(i.isInterfaceDeclaration(x)){if((_=x.heritageClauses)!=null&&_.length)throw new Error("Interface inheritance is not supported; declare properties explicitly.");g=c(x.members,[...m,y])}else g=d(x.type,[...m,y]);const w=n.allowJson?i.getJSDocTags(x).filter(C=>C.tagName.text==="port"):[];if(!w.length)return g;if(g.kind!=="object")throw new Error("Node ports require an object interface");const v={...g.ports};for(const C of w){const[S,T,k]=String(C.comment??"").trim().split(/\s+/);if(!["input","output","error"].includes(S)||!/^[A-Za-z][\w-]*$/.test(T??"")||k)throw new Error("Node ports require @port input|output|error Name");if(Object.prototype.hasOwnProperty.call(v,T))throw new Error(`Duplicate port declaration: ${T}`);v[T]={kind:S}}return{...g,ports:v}},d=(y,m)=>{var x,g,w;if(--o<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(y.kind===i.SyntaxKind.StringKeyword)return{kind:"string"};if(y.kind===i.SyntaxKind.NumberKeyword)return{kind:"number"};if(y.kind===i.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[i.SyntaxKind.AnyKeyword,i.SyntaxKind.UnknownKeyword].includes(y.kind))return{kind:"json"};if(i.isParenthesizedTypeNode(y))return d(y.type,m);if(i.isUnionTypeNode(y))return{kind:"union",types:y.types.map(v=>d(v,m))};if(i.isArrayTypeNode(y))return{kind:"array",items:d(y.elementType,m)};if(i.isTypeLiteralNode(y))return c(y.members,m);if(i.isLiteralTypeNode(y)){const v=y.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(y)&&i.isIdentifier(y.typeName)){if(n.allowJson&&y.typeName.text==="Record"&&!u.has("Record")&&((x=y.typeArguments)==null?void 0:x.length)===2&&y.typeArguments[0].kind===i.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:d(y.typeArguments[1],m)};if(y.typeName.text==="Array"&&((g=y.typeArguments)==null?void 0:g.length)===1)return{kind:"array",items:d(y.typeArguments[0],m)};if(!((w=y.typeArguments)!=null&&w.length))return l(y.typeName.text,m)}throw new Error(`Unsupported TypeScript type: ${y.getText(a)}`)},f=r??(u.has("Graph")?"Graph":u.size===1?[...u.keys()][0]:void 0);if(!f)throw new Error("Declare an interface Graph keyed by node ID.");const p=l(f,[]);if(p.kind!=="object")throw new Error("Graph must be an object keyed by node ID.");return p}async function Yy(e,t){const r=await Ou(e,t);if(Object.values(r.properties).some(n=>n.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:t,nodes:r.properties}}function jt(e,t){if(e.kind==="json"||t.kind==="json"||e.kind==="object"&&e.additionalProperties||t.kind==="object"&&t.additionalProperties)return!1;if(e.kind==="union")return e.types.every(r=>jt(r,t));if(t.kind==="union")return t.types.some(r=>jt(e,r));if(e.kind==="literal"){if(t.kind==="literal")return e.value===t.value;const r=e.value===null?"null":typeof e.value;return t.kind===r||t.kind==="integer"&&typeof e.value=="number"&&Number.isInteger(e.value)}return e.kind==="integer"&&t.kind==="number"?!0:e.kind==="array"&&t.kind==="array"?jt(e.items,t.items):e.kind==="object"&&t.kind==="object"?Object.entries(t.properties).every(([r,n])=>{const o=Object.prototype.hasOwnProperty.call(e.properties,r)?e.properties[r]:void 0;return o?(n.optional||!o.optional)&&jt(o.type,n.type):n.optional}):e.kind===t.kind}function Iu(e,t){if(!t.sourceProperty&&!t.targetProperty)return;const r=(a,s)=>{var l;const u=Object.prototype.hasOwnProperty.call(e.nodes,a)?a:a.replace(/^root\./,""),c=Object.prototype.hasOwnProperty.call(e.nodes,u)?(l=e.nodes[u])==null?void 0:l.type:void 0;return s&&(c==null?void 0:c.kind)==="object"&&Object.prototype.hasOwnProperty.call(c.properties,s)?c.properties[s]:void 0},n=r(t.source,t.sourceProperty),o=r(t.target,t.targetProperty);if(!n||!o)return"Unverified: source or target property is missing from the interface.";const i=a=>a.kind==="json"||a.kind==="object"&&(!!a.additionalProperties||Object.values(a.properties).some(s=>i(s.type)))||a.kind==="array"&&i(a.items)||a.kind==="union"&&a.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(!jt(n.type,o.type))return`Incompatible property types: ${t.sourceProperty} -> ${t.targetProperty}.`}async function Xy(e){if(e.size>256*1024)throw new Error("Interface must be 256 KB or smaller.");const t=await e.text();if(/\.json$/i.test(e.name))return Tu(t,e.name);if(/\.ts$/i.test(e.name))return Yy(t,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const _l=new WeakMap;function Vt(e){if(!e||typeof e!="object")return e;const t=_l.get(e);if(t)return t;const r=()=>{throw new Error("Form callback data is read-only. Return edits instead.")},n=new Proxy(Array.isArray(e)?[]:{},{get:(o,i)=>Vt(Reflect.get(e,i)),has:(o,i)=>Reflect.has(e,i),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(o,i)=>{const a=Reflect.getOwnPropertyDescriptor(e,i);return a&&{...a,value:Vt(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:r,deleteProperty:r,defineProperty:r,setPrototypeOf:r,preventExtensions:r});return _l.set(e,n),n}function pt(e,t,r){var o;const n=t.split(".");for(let i=n.length;i>0;i--){const a=n.slice(0,i).join("."),s=(o=xe(e,a))==null?void 0:o.$form;if(!(s!=null&&s.$type))continue;let u=Object.prototype.hasOwnProperty.call(r,s.$type)?r[s.$type]:void 0;for(const d of n.slice(i))(u==null?void 0:u.kind)==="array"&&/^\d+$/.test(d)?u=u.items:(u==null?void 0:u.kind)==="object"?u=Object.prototype.hasOwnProperty.call(u.properties,d)?u.properties[d].type:void 0:u=void 0;if((u==null?void 0:u.kind)!=="object")return;const c=n.slice(i).join("."),l=Object.fromEntries(Object.entries(s.$fields??{}).filter(([d])=>!c||d.startsWith(`${c}.`)).map(([d,f])=>[c?d.slice(c.length+1):d,f]));return{type:u,fields:l,binding:s}}}async function Mu(e,t){if(e.size>256*1024)throw new Error("Form schema exceeds 256 KB.");const r=await e.text();if(e.name.endsWith(".ts")){if(!t.length||t.length>32)throw new Error("Choose between 1 and 32 form interface names.");const o=[],i=new Set(t);for(const a of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const s=await Ou(r,e.name,a,{allowJson:!0});o.push([a,s]);for(const u of Object.values(s.ports??{}))u.resourceType&&i.add(u.resourceType)}return Object.fromEntries(o)}if(!e.name.endsWith(".json"))throw new Error("Choose a .ts interface or .json schema file.");const n=Tu(r,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([o,i])=>[o,i.type]))}function vn(e,t){return!e||("$in"in e?e.$in.includes(xe(t,e.$address)):xe(t,e.$address)===e.$equals)}function Nt(e){const t=e.kind==="array"?e.items:e,r=t.kind==="union"?t.types:[t];if(r.every(n=>n.kind==="literal"))return r.map(n=>({label:String(n.value),value:n.value}))}function Rr(e,t,r){if(t===void 0||t==="")return r?"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 a=Object.values(i).every(o);return n.delete(i),a};return o(t)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!Rr(n,t,!0))?void 0:"Choose a valid value";if(e.kind==="literal")return t===e.value?void 0:"Choose a valid value";if(e.kind==="array")return Array.isArray(t)&&t.every(n=>!Rr(e.items,n,!0))?void 0:"Invalid list value";if(e.kind==="object")return!t||typeof t!="object"||Array.isArray(t)?"Expected an object":e.additionalProperties&&Object.entries(t).some(([n,o])=>!Object.prototype.hasOwnProperty.call(e.properties,n)&&Rr(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>Rr(o.type,t[n],!o.optional))?"Invalid object fields":void 0;if(e.kind==="null")return t===null?void 0:"Expected null";if(e.kind==="integer")return Number.isInteger(t)?void 0:"Expected a whole number";if(typeof t!==e.kind||typeof t=="number"&&!Number.isFinite(t))return`Expected ${e.kind}`}function Sl(e,t){const r=t.address.split(".");if(r.shift()!=="root"||!r.length||r.some(s=>!s||["__proto__","prototype","constructor","#"].includes(s)))throw new Error("Invalid form field address.");const n=r.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(r.some(s=>s.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...r].join("."),a=xe(e,i);if(!a||typeof a!="object")throw new Error(`Missing form parent: ${i}`);if(o){if(t.op==="set"&&typeof t.value!="string")throw new Error("Node colors must be strings.");return ir(e,i,n,t.op==="remove"?void 0:t.value)}return hr(e,i,s=>{const u=Array.isArray(s.$)?s.$:s;if(t.op==="remove"&&!Object.prototype.hasOwnProperty.call(u,n)||t.op==="set"&&Object.is(u[n],t.value))return s;const c=Array.isArray(u)?[...u]:{...u};if(Array.isArray(c)&&(!/^(0|[1-9]\d*)$/.test(n)||Number(n)>=c.length))throw new Error("Invalid array address.");return t.op==="remove"?Array.isArray(c)?c.splice(Number(n),1):delete c[n]:Object.defineProperty(c,n,{value:structuredClone(t.value),enumerable:!0,writable:!0,configurable:!0}),u===s?c:{...s,$:c}})}function xn(e,t,r){let n=Sl(e,t.value===void 0?{op:"remove",address:t.address}:{op:"set",address:t.address,value:t.value});const o=r==null?void 0:r({...t,previousValue:Vt(xe(e,t.address)),data:Vt(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=Sl(n,i)}return n}function Hx(e,t){let r=e;for(const n of t){if(n.op!=="set"&&n.op!=="remove")throw new Error("Unsupported state edit.");const o=n.address.split(".");if(o.some(a=>a.startsWith("$")||["__proto__","prototype","constructor"].includes(a)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;Wt(i),r=xn(r,{address:n.address,nodeAddress:o.slice(0,-1).join("."),value:i})}return Wt(r),r}function Jt(e,t,r){const n=Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;if(!(!n||!r||!Object.prototype.hasOwnProperty.call(r,n.type)))return{address:n.address,type:r[n.type],fields:n.fields??{}}}function Wt(e){if(!(!e||typeof e!="object"))for(const[t,r]of Object.entries(e)){if(t.startsWith("$")||["__proto__","prototype","constructor"].includes(t))throw new Error(`Form state cannot contain view metadata or unsafe keys: ${t}`);Wt(r)}}function Kx(e,t,r){Wt(t.value);const n=xn(e,t,r);return Wt(n),n}function Qy(e,t){const r=(n,o="")=>{if(!n||typeof n!="object")return n;if(["$label","$subtitle","$content","$icon","$bgColor","$textColor","$borderColor"].includes(o)&&typeof n.$state=="string"){const a=xe(t,n.$state);return a==null?"":typeof a=="object"?JSON.stringify(a,null,2):String(a)}let i=n;for(const[a,s]of Object.entries(n)){const u=r(s,a);u!==s&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,a,{value:u,enumerable:!0,writable:!0,configurable:!0}))}return i};return r(e)}const Jr=(e="reference")=>({kind:e,text:"",paths:[""]}),eb=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(t=>["__proto__","constructor","prototype"].includes(t));function Zx(e,t){const r=new Set(t.map(a=>a.path)),n=a=>{if(!a.paths.length||a.paths.some(s=>!eb(s)||!r.has(s)))throw new Error("Choose an available reference.");return[...a.paths,...a.fallback===void 0?[]:[JSON.stringify(a.fallback)]].join(" || ")},o=a=>{if(a.includes("{{")||a.includes("}}"))throw new Error("Use a reference part for dynamic values.");return a},i=a=>a.map(s=>{if(s.kind==="text")return o(s.text);if(s.kind==="conditional"){if(s.paths.length!==1||s.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(s)}}}${o(s.text)}{{/if}}`}return`{{${n(s)}}}`}).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 a=i(e.parts);return e.mode==="condition"?`${a} == ${JSON.stringify(e.comparison)}`:a}if(e.mode==="json"){const a=e.fields.map(s=>s.key);if(!a.length||new Set(a).size!==a.length||a.some(s=>!s||["__proto__","constructor","prototype"].includes(s)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(s=>[s.key,i(s.parts)])))}return i(e.parts)}async function Jx(e){const t=await import("typescript"),r=a=>{const s=t.createSourceFile("binding.ts",`(${a})`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS);if(s.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const u=s.statements[0];if(!u||!t.isExpressionStatement(u))throw new Error("Unsupported reference expression.");const c=Jr();c.paths=[];const l=d=>{if(t.isParenthesizedExpression(d))return l(d.expression);if(t.isBinaryExpression(d)&&d.operatorToken.kind===t.SyntaxKind.BarBarToken){l(d.left),l(d.right);return}if(t.isStringLiteral(d)){if(c.fallback!==void 0)throw new Error("Multiple fallback values.");c.fallback=d.text;return}const f=d.getText(s);if(!eb(f)||c.fallback!==void 0)throw new Error("Unsupported reference expression.");c.paths.push(f)};if(l(u.expression),!c.paths.length)throw new Error("A binding needs a reference.");return c},n=a=>{const s=[];let u=0;const c=/\{\{([\s\S]*?)\}\}/g;for(const l of a.matchAll(c)){const d=l.index;if(d<u)continue;d>u&&s.push({...Jr("text"),text:a.slice(u,d)});const f=l[1].trim();if(f.startsWith("#if ")){const p=a.indexOf("{{/if}}",d+l[0].length);if(p<0)throw new Error("Unclosed condition.");s.push({...r(f.slice(4)),kind:"conditional",text:a.slice(d+l[0].length,p)}),u=p+7}else s.push(r(f)),u=d+l[0].length}return u<a.length&&s.push({...Jr("text"),text:a.slice(u)}),s},o={mode:"reference",parts:[Jr()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const a=JSON.parse(e);if(a&&typeof a=="object"&&!Array.isArray(a)&&Object.values(a).every(s=>typeof s=="string"))return{...o,mode:"json",fields:Object.entries(a).map(([s,u])=>({key:s,parts:n(u)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const a=t.createSourceFile("condition.ts",`value ${i[1].text}`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS),s=a.statements[0];if(a.statements.length===1&&t.isExpressionStatement(s)&&t.isBinaryExpression(s.expression)&&s.expression.operatorToken.kind===t.SyntaxKind.EqualsEqualsToken&&t.isStringLiteral(s.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:s.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function jl({parts:e,references:t,onChange:r,disabled:n}){const o=(i,a)=>r(e.map((s,u)=>u===i?{...s,...a}:s));return h.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,a)=>h.jsxs("fieldset",{"data-binding-part":a,style:{border:0,padding:0,margin:0,minWidth:0},children:[h.jsxs("legend",{children:["Part ",a+1]}),h.jsxs("div",{style:{display:"flex",gap:8},children:[h.jsxs("span",{"data-form-select":"",style:{flex:1},children:[h.jsxs("select",{"aria-label":"Part type",disabled:n,value:i.kind,onChange:s=>o(a,{kind:s.target.value}),children:[h.jsx("option",{value:"reference",children:"Reference"}),h.jsx("option",{value:"text",children:"Text"}),h.jsx("option",{value:"conditional",children:"Conditional text"})]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),h.jsx(ve,{"aria-label":`Remove part ${a+1}`,title:"Remove part",icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r(e.filter((s,u)=>u!==a))})]}),i.kind!=="text"&&h.jsxs(h.Fragment,{children:[i.paths.map((s,u)=>h.jsxs("label",{children:["Reference ",u+1,h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsxs("select",{"aria-label":`Reference ${u+1}`,disabled:n,value:s,onChange:c=>o(a,{paths:i.paths.map((l,d)=>d===u?c.target.value:l)}),children:[h.jsx("option",{value:"",children:"Select reference"}),t.map(c=>h.jsx("option",{value:c.path,children:c.label},c.path))]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},u)),i.kind==="reference"&&h.jsxs(h.Fragment,{children:[h.jsx(ve,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:h.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>o(a,{paths:[...i.paths,""]})}),h.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center"},children:[h.jsx("input",{type:"checkbox","aria-label":"Default value enabled",disabled:n,checked:i.fallback!==void 0,onChange:s=>o(a,{fallback:s.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&h.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:s=>o(a,{fallback:s.target.value})})]})]}),i.kind!=="reference"&&h.jsxs("label",{children:["Text",h.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:s=>o(a,{text:s.target.value})})]})]},a)),h.jsx(ve,{"aria-label":"Add part",title:"Add part",icon:h.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r([...e,Jr()])})]})}function Yx({label:e,value:t,references:r,disabled:n,onChange:o}){const[i,a]=E.useState(),[s,u]=E.useState(""),[c,l]=E.useState(!1),d=async()=>{l(!0),u("");try{a(await Jx(typeof t=="string"?t:""))}catch(f){u(f instanceof Error?f.message:"Unable to read binding.")}finally{l(!1)}};return h.jsxs("div",{"data-runtime-binding":e,style:{marginBottom:8},children:[h.jsx(ve,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:h.jsx(Z.PiLink,{size:18}),size:"sm",variant:"ghost",disabled:n||c,onClick:d}),typeof t=="string"&&t.includes("{{")&&h.jsx("span",{children:"Bound value"}),i&&h.jsxs("fieldset",{disabled:n,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[h.jsxs("label",{children:["Binding mode",h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsxs("select",{"aria-label":"Binding mode",value:i.mode,onChange:f=>a({...i,mode:f.target.value,parts:[Jr()]}),children:[h.jsx("option",{value:"reference",children:"Reference"}),h.jsx("option",{value:"condition",children:"Equals"}),h.jsx("option",{value:"template",children:"Text template"}),h.jsx("option",{value:"json",children:"JSON output"})]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),i.mode==="json"?h.jsxs(h.Fragment,{children:[i.fields.map((f,p)=>h.jsxs("fieldset",{"data-output-field":p,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[h.jsxs("label",{children:["Output field name",h.jsx("input",{"aria-label":"Output field name",value:f.key,onChange:b=>a({...i,fields:i.fields.map((y,m)=>m===p?{...y,key:b.target.value}:y)})})]}),h.jsx(jl,{parts:f.parts,references:r,disabled:n,onChange:b=>a({...i,fields:i.fields.map((y,m)=>m===p?{...y,parts:b}:y)})}),h.jsx(ve,{"aria-label":"Remove output field",title:"Remove output field",icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>a({...i,fields:i.fields.filter((b,y)=>y!==p)})})]},p)),h.jsx(ve,{"aria-label":"Add output field",title:"Add output field",icon:h.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>a({...i,fields:[...i.fields,{key:"",parts:[Jr()]}]})})]}):h.jsx(jl,{parts:i.parts,references:r,disabled:n,onChange:f=>a({...i,parts:f})}),i.mode==="condition"&&h.jsxs("label",{children:["Equals",h.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:f=>a({...i,comparison:f.target.value})})]}),h.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[h.jsx(ve,{"aria-label":"Apply binding",title:"Apply binding",icon:h.jsx(Z.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(Zx(i,r)),a(void 0),u("")}catch(f){u(f instanceof Error?f.message:"Unable to apply binding.")}}}),h.jsx(ve,{"aria-label":"Cancel binding",title:"Cancel binding",icon:h.jsx(Z.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{a(void 0),u("")}})]})]}),s&&h.jsx("p",{role:"alert",children:s})]})}const Xx=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),Qx=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,Et=(e,t)=>JSON.stringify([e,t]);function Gt(e,t){if(e.kind==="union"){const r=e.types.find(n=>n.kind===(Array.isArray(t)?"array":t===null?"null":typeof t)||n.kind==="literal"&&Object.is(n.value,t));return Gt(r??e.types.find(n=>n.kind!=="null")??e.types[0]??{kind:"json"},t)}return e.kind!=="json"?e:Array.isArray(t)?{kind:"array",items:{kind:"json"}}:t!==null&&typeof t=="object"||t===void 0?{kind:"object",properties:{},additionalProperties:{kind:"json"}}:{kind:t===null?"null":typeof t}}function Rt(e){const t=Gt(e,void 0);return t.kind==="object"?{}:t.kind==="array"?[]:t.kind==="literal"?t.value:t.kind==="number"||t.kind==="integer"?0:t.kind==="boolean"?!1:t.kind==="null"?null:""}function El(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"&&!Nt(e)?e.types:[e]}function e0(e,t,r){if(t.address===r.address)return;const n=xe(e,t.address),o=(i,a)=>a===void 0?!1:i.kind==="union"?i.types.some(s=>o(s,a)):i.kind==="array"?Array.isArray(a)&&a.every(s=>o(i.items,s)):i.kind==="object"?!!a&&typeof a=="object"&&!Array.isArray(a)&&Object.entries(i.properties).every(([s,u])=>u.optional&&a[s]===void 0||o(u.type,a[s]))&&Object.entries(a).every(([s,u])=>Object.prototype.hasOwnProperty.call(i.properties,s)||!i.additionalProperties||o(i.additionalProperties,u)):a===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!Rr(i,a,!0);if(o(r.type,n))return structuredClone(n)}function r0(e,t,r,n){var u;const o={sourceSchema:r,sourceBindings:t,nodes:[],edges:[],schema:{...r},bindings:{...t},slots:new Map,containers:new Map},i=new Set(n.map(c=>c.data.id)),a=new Map(n.flatMap(c=>{const l=t[c.data.id];return l&&r[l.type]?[[l.address,c.data.id]]:[]})),s=(c,l,d,f,p,b=!1)=>{var C,S,T;if(p>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const y=xe(e,l),m=Gt(d,y),x=m.kind!=="object"&&m.kind!=="array";o.containers.set(c,{address:l,type:m,declared:d,scalar:x});const g=`__form:${c}`,w={...(C=o.bindings[c])==null?void 0:C.fields},v={kind:"object",properties:{},ports:{...m.kind==="object"?m.ports:{},...b?{resource:{kind:"output"}}:{}}},_=m.kind==="object"?{...m.properties,...Object.fromEntries(Object.keys(y??{}).filter(k=>!Object.prototype.hasOwnProperty.call(m.properties,k)&&m.additionalProperties).map(k=>[k,{type:m.additionalProperties,optional:!0}]))}:m.kind==="array"?Object.fromEntries((Array.isArray(y)?y:[]).map((k,j)=>[String(j),{type:m.items,optional:!0}])):{value:{type:Nt(d)?d:m,optional:!1}};for(const[k,j]of Object.entries(_)){if(!Xx(k))throw new Error(`Unsupported structured property key: ${k}`);const P=x?l:`${l}.${k}`,R=xe(e,P),I=Gt(j.type,R),O=I.kind==="object"||I.kind==="array",M=(S=v.ports)==null?void 0:S[k],q=(M==null?void 0:M.kind)==="config"&&(((T=w[k])==null?void 0:T.$options)||Nt(j.type)),H=j.type.kind==="json"||j.type.kind==="union"&&!Nt(j.type);if(!O&&m.kind!=="array"&&(!H||x)||q){v.properties[k]={...j,type:j.type.kind==="json"?I:j.type};continue}const V=a.get(P)??Qx(P),re=m.kind==="array"?`Item ${Number(k)+1}`:k,ce={address:P,owner:c,field:k,type:j.type,label:re,nodeId:V,present:R!==void 0};if(o.slots.set(Et(c,k),ce),v.ports[k]={kind:"config",resourceType:`__form:${V}`},R===void 0||(o.edges.push({data:{id:`__form-edge:${c}:${k}`,source:V,target:c,sourceProperty:"output:resource",targetProperty:`config:${k}`,isEdgeDashed:!0}}),o.containers.has(V)||a.has(P)))continue;if(i.has(V))throw new Error(`Structured node identity conflict: ${V}`);i.add(V);const le={data:{id:V,type:"objectView",label:re,headerTitle:re,description:{},config:{form:!0,icon:I.kind==="array"?"PiListNumbers":O?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:f}}};o.nodes.push(le),s(V,P,j.type,f,p+1,!0);const be=o.schema[`__form:${V}`];le.data.description=Object.fromEntries(Object.keys(be.properties).map(K=>[K,xe(e,I.kind==="array"||I.kind==="object"?`${P}.${K}`:P)]).filter(([,K])=>K!==void 0))}o.schema[g]=v,o.bindings[c]={...o.bindings[c],address:l,type:g,fields:w}};for(const c of n){const l=t[c.data.id],d=l&&r[l.type];!l||!d||xe(e,l.address)===void 0||s(c.data.id,l.address,d,(u=c.data.viewProps)==null?void 0:u.bgColor,0,o.edges.some(f=>f.data.source===c.data.id))}for(const c of o.edges){const l=o.bindings[c.data.source];o.schema[l.type].ports.resource={kind:"output"}}return o}function t0({nodeAddress:e}){const{structured:t,data:r,callbacks:n,editable:o}=E.useContext(kr),i=Ie(),[a,s]=E.useState(""),[u,c]=E.useState("0"),[l,d]=E.useState(""),f=t==null?void 0:t.containers.get(e);if(!f||!r||!t)return null;const p=i.readOnly||i.config.editable===!1||!o,b=xe(r,f.address),y=El(f.declared),m=f.type.kind==="array"?f.type.items:f.type.kind==="object"?f.type.additionalProperties:void 0,x=m?El(m):[],g=j=>j.kind==="literal"?String(j.value):j.kind==="string"?"Text":Cr(j.kind),w=[...t.slots.values()].filter(j=>j.owner===e),v=(j,P)=>{var R;return(R=n.onFormChange)==null?void 0:R.call(n,{data:r,nodeAddress:f.address,address:j,previousValue:xe(r,j),value:P})},_=j=>{var P;i.setSelectedNodeIds([j]),(P=i.engineRef.current)==null||P.focusNode(j,90,!1)},C=(j,P)=>{if(!Array.isArray(b))return;const R=[...b];[R[j],R[j+P]]=[R[j+P],R[j]],v(f.address,R)},S=()=>{const j=x[Number(u)]??x[0];if(j)if(f.type.kind==="array")v(f.address,[...Array.isArray(b)?b:[],Rt(j)]);else{if(!a||a.includes(".")||a.startsWith("$")||["__proto__","constructor","prototype"].includes(a)){d("Choose a property name without dots or reserved prefixes.");return}if(Object.prototype.hasOwnProperty.call(b,a)){d("Property already exists.");return}v(`${f.address}.${a}`,Rt(j)),s(""),d("")}},T=f.type.kind==="object"&&!!f.type.additionalProperties,k=f.type.kind==="array";return h.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[y.length>1&&h.jsxs("label",{children:["Value type",h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsx("select",{"aria-label":"Value type",disabled:p,value:y.findIndex(j=>Gt(j,b).kind===f.type.kind),onChange:j=>v(f.address,Rt(y[Number(j.target.value)])),children:y.map((j,P)=>h.jsx("option",{value:P,children:g(j)},P))}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),w.map((j,P)=>h.jsxs("div",{"data-structured-slot":j.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[j.type.kind==="array"?h.jsx(Z.PiListNumbers,{size:20}):h.jsx(Z.PiBracketsCurly,{size:20}),h.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:Cr(j.label)}),h.jsx(ve,{"aria-label":`${j.present?"Focus":"Create"} ${Cr(j.label)}`,title:`${j.present?"Focus":"Create"} ${Cr(j.label)}`,icon:j.present?h.jsx(Z.PiMagnifyingGlass,{size:18}):h.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:p&&!j.present,onClick:R=>{var I;j.present?((I=R.currentTarget.closest("dialog"))==null||I.close(),_(j.nodeId)):v(j.address,Rt(j.type))}}),k&&h.jsxs(h.Fragment,{children:[h.jsx(ve,{"aria-label":`Move item ${P+1} up`,icon:h.jsx(Z.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:p||P===0,onClick:()=>C(P,-1)}),h.jsx(ve,{"aria-label":`Move item ${P+1} down`,icon:h.jsx(Z.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:p||P===w.length-1,onClick:()=>C(P,1)})]}),j.present&&h.jsx(ve,{"aria-label":`Remove ${Cr(j.label)}`,icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:p,onClick:()=>k?v(f.address,b.filter((R,I)=>I!==P)):v(j.address,void 0)})]},j.address)),(k||T)&&h.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[T&&h.jsxs("label",{style:{flex:"1 1 120px",minWidth:0},children:["Property name",h.jsx("input",{"aria-label":"Property name",value:a,disabled:p,onChange:j=>s(j.target.value)})]}),x.length>1&&h.jsxs("label",{style:{flex:"1 1 100px"},children:["New value type",h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsx("select",{"aria-label":"New value type",value:u,disabled:p,onChange:j=>c(j.target.value),children:x.map((j,P)=>h.jsx("option",{value:P,children:g(j)},P))}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),h.jsx("span",{style:{display:"flex",alignItems:"center",flexShrink:0,...T||x.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:h.jsx(ve,{"aria-label":k?"Add item":"Add property",icon:h.jsx(Z.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:p,onClick:S})})]}),l&&h.jsx("p",{role:"alert",children:l})]})}const kr=E.createContext({callbacks:{}}),tn=gn.default.div`
54
+ `;function ml({label:e,inputLabel:t,value:r,displayValue:n,min:o,max:i,onChange:a}){const s=j.useId(),{readOnly:u,themeColor:c}=Ie(),{colorInactive:l}=Ve(),d=(r-o)/(i-o)*100,f=c.includes(".")?`var(--chakra-colors-${c.replace(".","-")})`:c;return h.jsxs("div",{style:{width:224,maxWidth:"calc(100vw - 64px)",padding:12},children:[h.jsxs("label",{htmlFor:s,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",h.jsx("span",{children:n})]}),h.jsx(Vy,{id:s,"aria-label":t,type:"range",min:o,max:i,step:5,value:r,disabled:u,style:{color:f,accentColor:f,backgroundImage:`linear-gradient(to right, currentColor ${d}%, var(--chakra-colors-${l.replace(".","-")}) ${d}%)`},onChange:p=>a(Number(p.target.value))})]})}const bl={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 Wy(){const{spacing:e,setSpacing:t,edgeRadius:r,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:a,readOnly:s}=Ie(),u=bl[o].icon;return h.jsxs(h.Fragment,{children:[h.jsx(It,{}),h.jsx(Or,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:h.jsx(Z.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:s,onValueChange:()=>{},popupContent:h.jsx(ml,{label:"Spacing",inputLabel:"Node spacing percentage",min:50,max:200,value:Math.round(e*100),displayValue:`${Math.round(e*100)}%`,onChange:c=>{var l;t(c/100),(l=a.onSpacingChange)==null||l.call(a,c/100)}}),children:h.jsx("option",{value:"spacing",children:"Spacing"})}),h.jsx(It,{}),h.jsx(Or,{"aria-label":"Edge radius",title:`Edge radius: ${r??"Default"}`,icon:h.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:s,onValueChange:()=>{},popupContent:h.jsx(ml,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:r??500,displayValue:r??"Default",onChange:c=>{var l;n(c),(l=a.onEdgeRadiusChange)==null||l.call(a,c)}}),children:h.jsx("option",{value:"radius",children:"Edge radius"})}),h.jsx(It,{}),h.jsxs(Or,{"aria-label":"Background variant",title:`Background: ${bl[o].label}`,icon:h.jsx(u,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:s,onValueChange:c=>{var l;i(c),(l=a.onBackgroundVariantChange)==null||l.call(a,c)},children:[h.jsx("option",{value:"dot",children:"Dots"}),h.jsx("option",{value:"grid",children:"Grid"}),h.jsx("option",{value:"steel",children:"Steel"}),h.jsx("option",{value:"none",children:"Solid"}),h.jsx("option",{value:"transparent",children:"Transparent"})]})]})}const nr=[];for(let e=0;e<256;++e)nr.push((e+256).toString(16).slice(1));function Fx(e,t=0){return(nr[e[t+0]]+nr[e[t+1]]+nr[e[t+2]]+nr[e[t+3]]+"-"+nr[e[t+4]]+nr[e[t+5]]+"-"+nr[e[t+6]]+nr[e[t+7]]+"-"+nr[e[t+8]]+nr[e[t+9]]+"-"+nr[e[t+10]]+nr[e[t+11]]+nr[e[t+12]]+nr[e[t+13]]+nr[e[t+14]]+nr[e[t+15]]).toLowerCase()}let Zn;const Bx=new Uint8Array(16);function Dx(){if(!Zn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Zn=crypto.getRandomValues.bind(crypto)}return Zn(Bx)}const zx=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),vl={randomUUID:zx};function ju(e,t,r){var o;if(vl.randomUUID&&!e)return vl.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??Dx();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,Fx(n)}const mn={label:"Untitled",description:"",isTask:!1,isLocked:!1},Ru={id:null,type:"text",data:{...mn,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"}}},xl={id:null,type:"objectView",data:{...mn,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},Vx={id:null,type:"arrayView",data:{...mn,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"}}},wl={id:null,type:"workflowStep",data:{...mn,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},hr=e=>typeof e=="object",Gy=e=>Array.isArray(e),Wx=["order","position","selected","locked","grabbed","grabbable","scratch"],zr=e=>Object.entries(e).reduce((t,[r,n])=>(!hr(n)&&!r.startsWith("$")&&(t[r]=n),t),{}),ku=(e,t)=>typeof e=="string"&&e.startsWith("$")?Jn(e,t):hr(e)&&!Gy(e)?Object.entries(e).reduce((r,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete r["..."],r[n]={...Jn(o,t),...e}):typeof o=="string"&&o.startsWith("$")?r[n]=Jn(o,t):r[n]=o,r),{}):e,Vr=e=>Object.entries(e).reduce((t,[r,n])=>(hr(n)&&r&&n&&!r.startsWith("$")&&(Wx.includes(r)&&(r=r+"#"),t[r]=n),t),{}),Jr=(e,t,{label:r,parent:n=void 0},o,i=null)=>(i!==null&&(hr(i)||Gy(i))&&(i=JSON.stringify(i,null,2)),{data:{parent:n,...e.data,id:t,text:r||"",label:r,code:i||null,type:e.type,description:o}}),Br=(e,t,r=null,n=null,o=null,i=!1,a=null)=>({data:{id:ju(),source:o?t:e,target:o?e:t,label:n||"",isInverted:o,isEdgeAnimated:i,parent:a}}),Wr=(e,t=[])=>{const r={},n={};let o=[];if(e)for(const[i,a]of Object.entries(e))i.startsWith("$")&&i!=="$"?r[i.slice(1)]=a:i!=="$"?n[i]=a:i==="$"&&(o=a);return{newConfig:r,updatedObject:n,arrayObject:o}},ut=(e,t)=>{let r=xl;const{view:n,borderColor:o,borderRadius:i,bgColor:a,textColor:s,fontSize:u,stepType:c}=t;e=n||e,c?r={...wl}:e==="object"?r=xl:e==="text"?r=Ru:e==="array"?r=Vx:e==="workflowStep"&&(r={...wl});const l=r.data.viewProps;return r.data.viewProps={...l,borderRadius:i||(c?15:53),bgColor:a,borderColor:o,textColor:s,fontSize:u},r.data.config=t,{config:r}},Dt=(e,t)=>(e=t.find(n=>n.data.id===e)?`${e}.#`:e,e),Jn=(e,{ids:t,jsnObjct:r})=>{if(typeof e=="string"&&(e!=null&&e.startsWith("$"))){const n=e.replace("$","").replace("*","");e==null||e.endsWith("*");const o=t.find(s=>s.split(".").slice(-1)[0]===n||n===s);if(!o)return e;const i=Gx(o,r);return JSON.stringify(i).includes(e)?e:i||e}return e},Gx=(e,t)=>{let r=e.split(".").splice(1);return r=r[r.length-1]==="#"||r[r.length-1].includes("{")?r.slice(0,-2):r,(i=>r.reduce((a,s)=>{s=s.replace("[","").replace("]","");const{arrayObject:u}=Wr(a);return a=u.length?u:a,a[s]},i))(t)};function dt(e,t="root",r=[]){try{const{arrayObject:n}=Wr(e);n.length&&(e=n);const o=zr(e),i=Vr(e);return hr(e)?(Ae(e)||Ae(e)&&t==="root"||!Ae(e)&&Object.keys(o).length||t==="root")&&r.push(t):r.push(t),Object.keys(i).length&&!Ae(e)?Mt({chldPth:null,itrblObjct:i,nodes:r,path:t}):Ae(e)&&e.forEach((a,s)=>{const u=zr(a),c=Vr(a),{newConfig:l,arrayObject:d}=Wr(a);let f=`${t}.${s}`;hr(a)?Object.keys(u).length?(dt(u,f,r),Object.keys(c).length&&!Ae(a)&&Mt({chldPth:f,itrblObjct:c,nodes:r,path:t})):Object.keys(c).length&&!Ae(a)?Mt({chldPth:f,itrblObjct:c,nodes:r,path:t}):Ae(a)&&Uy({chldPth:f,item:a,nodes:r,path:t}):r.push(f)}),{nodes:r}}catch{return{nodes:r}}}const Mt=({chldPth:e,itrblObjct:t,nodes:r,path:n})=>Object.entries(t).forEach(([o,i],a)=>{const s=zr(i),u=Vr(i),{newConfig:c,arrayObject:l}=Wr(i);l.length&&(i=l),n.split(".").slice(0,2).join(".");let d=e?`${e}.${o}`:`${n}.${o}`;if(hr(i)&&!Ae(i)){const f=Object.keys(s).length===0;if(f&&(ut("array",c),r.push(d)),Object.keys(s).length){const p=Ae(i)?`${i.length||""}`:`{${Object.keys(i).length||""}}`;let m=d;f&&(m=`${d}.${p}`),dt(i,m,r)}else Object.keys(u).length&&!Ae(i)?Mt({chldPth:d,itrblObjct:u,path:d,nodes:r}):dt(i,d,r)}else Ae(i)&&dt(i,d,r)}),Uy=({chldPth:e,item:t,nodes:r,path:n})=>t.forEach((o,i)=>{let a=`${e}.${i}`;const s=Vr(o),u=zr(o);hr(o)?!Ae(o)&&Object.keys(u).length?dt(o,a,r):Object.keys(s).length&&!Ae(o)?Mt({chldPth:a,itrblObjct:s,path:n,nodes:r}):Ae(o)&&Uy({chldPth:a,item:o,nodes:r,path:n}):r.push(a)}),ln=[];let qt;function Xr(e,t="root",r=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},a={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:r,edges:n};const s=e;if(!qt){const{nodes:l}=dt(e);qt={ids:l,jsnObjct:e}}let{hideDefaultObject:u,sprtObjctKy:c}=i;try{t=Dt(t,r);const{newConfig:l,arrayObject:d}=Wr(e),f=Object.keys(a).length>0?a:l;d.length&&(e=d);const p=zr(e),m=Vr(e),{label:y,collapsed:b,parent:v}=f;if(!hr(e))r.push(Jr(Ru,t,{label:y||t,parent:v},e,s));else if(Ae(e)||Ae(e)&&t==="root"){const{config:g}=ut("array",f),w=Ae(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,x=t==="root"?o:`${o} ${w}`;r.push(Jr(g,t,{label:y||x,parent:v},e,Ae(s)?{[o]:s}:s))}else if(!Ae(e)&&Object.keys(p).length||t==="root"){const{config:g}=ut(null,f),w=Ae(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,x=t.split("."),_=x[x.length-1];let C=isNaN(Number(_))?null:Number(_)+1;const S=isNaN(Number(_))?_:x[x.length-2]+" "+C,T=t==="root"?o:S;let k=!1;Number.isNaN(Number(o))||(k=!0);const E=e;if(y){const{config:P}=ut("object",f);r.push(Jr(P,t,{label:y||`${y} ${w}`,parent:v},p,E))}else g.data.headerTitle=T,r.push(Jr(g,t,{label:y,parent:v},p,E))}return b||(Object.keys(m).length&&!Ae(e)?Nt({flowConfig:i,chldPth:null,edges:n,isInverted:null,itrblObjct:m,nodes:r,path:t,newConfig:f}):Ae(e)&&e.forEach((g,w)=>{g=ku(g,qt);const x=g,_=zr(g),C=Vr(g),{newConfig:S,arrayObject:T}=Wr(g);T.length&&(g=T);const{config:k}=ut(typeof g=="string"?"text":"array",S),{hideConfig:E,sourceLabel:P,label:R,isEdgeAnimated:I,parent:O}=S;u=u||E;const M=t==="root"&&i.isCntr,q=t.split(".").slice(0,2).join("."),K=ln.includes(q),V=i.isCntr&&K||w%2===0&&M;let re=`${t}.${w}`;re=Dt(re,r),V&&ln.push(re),hr(g)?Object.keys(_).length&&!Ae(g)?(n.push(Br(t,re,null,P,V,I)),Xr(g,re,r,n,R||w,i,S)):Object.keys(C).length&&!Ae(g)?Nt({flowConfig:i,chldPth:re,isInverted:V,edges:n,itrblObjct:C,nodes:r,path:t,newConfig:S,forceIsInverted:!0}):Ae(g)?Hy({flowConfig:i,chldPth:re,edges:n,isInverted:V,item:g,nodes:r,path:t}):hr(g)&&Nt({flowConfig:i,chldPth:re,isInverted:V,edges:n,itrblObjct:[g],nodes:r,path:t,newConfig:S}):(n.push(Br(t,re,null,P,V,I)),r.push(Jr(k,re,{label:R||String(g),parent:O},g,x)))})),{nodes:r,edges:n}}catch{return{nodes:r,edges:n}}}const Nt=({chldPth:e,flowConfig:t,edges:r,itrblObjct:n,nodes:o,isInverted:i,path:a,newConfig:s,forceIsInverted:u=!1})=>{let{hideDefaultObject:c,sprtObjctKy:l}=t;return Object.entries(n).forEach(([d,f],p)=>{f=ku(f,qt);const m=f,y=zr(f),b=Vr(f),{newConfig:v,arrayObject:g}=Wr(f);g.length&&(f=g);const{hideConfig:w,sourceLabel:x,label:_,content:C,target:S,targetLabel:T,collapsed:k,isEdgeAnimated:E,parent:P}=v;c=c||w;const R=a==="root"&&t.isCntr,I=a.split(".").slice(0,2).join("."),O=ln.includes(I);u||(i=t.isCntr&&O||p%2===0&&R);let M=e?`${e}.${d}`:`${a}.${d}`;if(M=Dt(M,o),i&&ln.push(M),S&&r.push(Br(M,S,null,T,i,E)),hr(f)&&!Ae(f)){r.push(Br(a,M,null,x,i,E));const q=l||Object.keys(y).length===0;if(q){const K=C?"object":"array",{config:V}=ut(K,v);V.data.headerTitle=C?_:null,o.push(Jr(V,M,{label:_||d,parent:P},f,m))}if(Object.keys(y).length&&!c){const K=Ae(f)?` ${f.length||""}`:`{${Object.keys(f).length||""}}`;let V=M;q&&(V=`${M}.${K}`,V=Dt(V,o),r.push(Br(M,V,null,x,i,E))),Xr(f,V,o,r,_||d,t,v)}else Object.keys(b).length&&!Ae(f)?Nt({chldPth:M,flowConfig:t,itrblObjct:b,path:M,edges:r,nodes:o,newConfig:v,isInverted:i}):Xr(f,M,o,r,d,t,v)}else Ae(f)&&(r.push(Br(a,M,null,x,i,E)),Xr(f,M,o,r,d,t,v))})},Hy=({flowConfig:e,chldPth:t,edges:r,isInverted:n,item:o,nodes:i,path:a})=>o.forEach((s,u)=>{let c=`${t}.${u}`;c=Dt(c,i);const l=s;s=ku(s,qt);const d=Vr(s),f=zr(s),{newConfig:p}=Wr(s),{collapsed:m,label:y,parent:b,sourceLabel:v,isEdgeAnimated:g,content:w}=p;hr(s)?!Ae(s)&&Object.keys(f).length?(r.push(Br(a,c,null,v,n,g)),Xr(s,c,i,r,u,e,p)):Object.keys(d).length&&!Ae(s)&&!m?Nt({chldPth:c,flowConfig:e,itrblObjct:d,path:a,edges:r,nodes:i,isInverted:n,newConfig:p}):Ae(s)&&Hy({flowConfig:e,chldPth:c,edges:r,isInverted:n,item:s,nodes:i,path:a}):(r.push(Br(a,c,null,v,n,g)),i.push(Jr(Ru,c,{label:y||String(s),parent:b},s,l)))});function Ux(e,t){const r=new Set,n=c=>{if(!(!c||typeof c!="object")){typeof c.$parent=="string"&&r.add(c.$parent);for(const[l,d]of Object.entries(c))(!l.startsWith("$")||l==="$")&&n(d)}};if(n(e),!r.size)return t;const o=new Map(t.nodes.map(c=>[c.data.id,c])),i=c=>{var p,m;let l=c.data.id;const d=new Set([c.data.id]);let f=c.data.parent;for(;f&&!d.has(f);)r.has(f)&&o.has(f)&&((p=xe(e,f))!=null&&p.$collapsed)&&(l=f),d.add(f),f=(m=o.get(f))==null?void 0:m.data.parent;return l},a=new Map(t.nodes.map(c=>[c.data.id,i(c)])),s=t.nodes.filter(c=>a.get(c.data.id)===c.data.id).map(c=>{if(!r.has(c.data.id))return c;const l=xe(e,c.data.id),d=!!(l!=null&&l.$collapsed);return{...c,data:{...c.data,...d?{type:"arrayView"}:{},config:{...c.data.config,parentContainer:!0,collapsed:d,...d?{labelBelow:!0,icon:(l==null?void 0:l.$icon)||"PiStack"}:{}}}}}),u=new Set(s.map(c=>c.data.id));return{nodes:s,edges:t.edges.flatMap(c=>{const l=a.get(c.data.source),d=a.get(c.data.target);return!l||!d||!u.has(l)||!u.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}}}]})}}function bn(e){if(!Array.isArray(e==null?void 0:e.$connections))return[];const t=new Map;return e.$connections.flatMap((r,n)=>{if(!r||typeof r!="object")return[];const o=r;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]),a=t.get(i)??0;return t.set(i,a+1),[{value:o,key:`${i}#${a}`,index:n}]})}function Ky(e,t,r){const n=bn(e).find(u=>u.key===t);if(!n)return e;const o=r(n.value),i=e.$connections.flatMap((u,c)=>c===n.index?o?[o]:[]:[u]);if(i.length)return{...e,$connections:i};const{$connections:a,...s}=e;return s}function Hx(e){const t=[],r=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,a)=>r(i,`${o}.${a}`));for(const i of bn(n)){const a=i.value;t.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:a.target,type:typeof a.type=="string"?a.type:void 0,sourceProperty:a.sourceProperty,targetProperty:a.targetProperty,icon:typeof a.icon=="string"?a.icon:void 0,label:typeof a.label=="string"?a.label:void 0,color:typeof a.color=="string"?a.color:void 0,isEdgeDashed:a.style==="dashed",isEdgeAnimated:a.style==="animated",...["dashed","traveling"].includes(a.animationVariant)?{edgeAnimationVariant:a.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,a])=>[i,i==="$"?r(a,o):i.startsWith("$")?a:r(a,`${o}.${i}`)]))};return{json:r(e,"root"),edges:t}}const zt="root",Cl=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Ir(e){const t=e.split(".");for(t[0]===zt&&t.shift();t.length&&Cl(t[t.length-1]);)t.pop();return t.filter(r=>!Cl(r))}function vn(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function xe(e,t){return Ir(t).reduce((r,n)=>{var o;if(r!=null)return(o=vn(r))==null?void 0:o[n]},e)}function Kx(e){return Array.isArray(e)?[...e]:{...e}}function pr(e,t,r){const n=Ir(t),o=(i,a)=>{if(a===n.length)return r(i);const s=n[a],u=vn(i);if(u==null||typeof u!="object")return i;const c=o(u[s],a+1);if(Object.is(c,u[s]))return i;const l=Kx(u);return l[s]=c,u!==i?{...i,$:l}:l};return o(e,0)}function Tr(e,t,r){const n=r===""&&t!=="$content"||r===void 0||r===null;if(Array.isArray(e))return n?e:{[t]:r,$:[...e]};const o=e!=null&&typeof e=="object"?{...e}:{};return e!=null&&typeof e!="object"&&(o.$label=String(e)),n?delete o[t]:o[t]=r,o}function ir(e,t,r,n){return pr(e,t,o=>r==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:Tr(o,r,n))}const Zy=(e,t,r)=>ir(e,t,"$collapsed",r);function Vt(e){if(e.connection)return{address:e.connection.address,kind:"connection"};const t=e.collapsedEndpoints??e,r=e.isInverted?t.target:t.source,n=e.isInverted?t.source:t.target,o=Ir(r).join("."),i=Ir(n).join(".");return i.startsWith(o?o+".":"")&&i!==o?{address:n,kind:"hierarchy"}:o.startsWith(i?i+".":"")&&o!==i?{address:r,kind:"hierarchy"}:{address:r,kind:"target"}}function Fr(e,t,r,n){if(t.connection){const s=t.connection;return pr(e,s.address,u=>Ky(u,s.key,c=>{if(r==="$edgeIcon")return Tr(c,"icon",n);if(r==="$edgeType")return Tr(c,"type",n);if(r==="$edgeAnimationVariant")return Tr(c,"animationVariant",n);if(r==="$sourceLabel"||r==="$edgeColor")return Tr(c,r==="$sourceLabel"?"label":"color",n);const l=r==="$isEdgeAnimated"?"animated":"dashed";return n?{...c,style:l}:c.style===l?Tr(c,"style",void 0):c}))}const{address:o,kind:i}=Vt(t),a=i==="target"&&r==="$sourceLabel"?"$targetLabel":i==="target"&&r==="$edgeType"?"$targetEdgeType":i==="target"&&r==="$edgeIcon"?"$targetIcon":i==="target"&&r==="$edgeAnimationVariant"?"$targetAnimationVariant":r;return pr(e,o,s=>Tr(s,a,n))}const Jy=(e,t,r)=>Fr(Fr(e,t,"$isEdgeAnimated",r==="animated"||void 0),t,"$isEdgeDashed",r==="dashed"||void 0);function Pu(e,t,r,n){let o=n||"";const i=pr(e,t,s=>{const u=vn(s);if(Array.isArray(u)){o=String(u.length);const l=[...u,r];return u===s?l:{...s,$:l}}const c=s!=null&&typeof s=="object"&&!Array.isArray(s)?{...s}:s!=null&&typeof s!="object"?{$label:String(s)}:{};if(!o){let l=1;for(;`node_${l}`in c;)l++;o=`node_${l}`}return c[o]=r,c}),a=Ir(t);return{json:i,address:[zt,...a,o].join(".")}}function Yy(e,t){const r=Ir(t);if(!r.length)return e;const n=r[r.length-1],o=[zt,...r.slice(0,-1)].join(".");return pr(e,o,i=>{const a=vn(i);if(a==null||typeof a!="object"||!Object.prototype.hasOwnProperty.call(a,n))return i;if(Array.isArray(a)){const c=a.filter((l,d)=>String(d)!==n);return a===i?c:{...i,$:c}}const{[n]:s,...u}=i;return u})}const Xy=(e,t,r,n)=>ir(n?pr(e,t,o=>Tr(o,"$targetLabel",n)):e,t,"$target",r);function Au(e,t,r){const n=xe(e,t);return bn(n).some(({value:i})=>i.target===r.target&&i.sourceProperty===r.sourceProperty&&i.targetProperty===r.targetProperty)?e:pr(e,t,i=>Tr(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...r,id:r.id||ju()}]))}function Qy(e,t){if(t.connection){const i=t.connection;return bn(xe(e,i.address)).some(a=>a.key===i.key)?{json:pr(e,i.address,a=>Ky(a,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:r,kind:n}=Vt(t);return n==="hierarchy"?xe(e,r)===void 0?{json:e,removed:!1}:{json:pr(e,r,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:pr(e,r,i=>{const{$target:a,$targetLabel:s,...u}=i||{};return u}),removed:!0}}function vu(e,t={}){var v;const r=Hx(e),{nodes:n,edges:o}=Xr(r.json,zt,[],[],t.title||"untitled",{hideDefaultObject:!!t.hideDefaultObject,sprtObjctKy:!!t.separateObjectKeys,isCntr:!!t.isCenter}),i=new Set(n.map(g=>g.data.id)),a=new Map;for(const g of n){const w=g.data.id;if(!w.endsWith(".0")||xe(e,w)!==void 0)continue;const x=w.slice(0,-2),_=xe(e,x);!i.has(x)&&_&&typeof _=="object"&&!Array.isArray(_)&&typeof _.$label=="string"&&Object.keys(_).every(C=>C.startsWith("$")&&C!=="$")&&a.set(w,x)}const s=g=>a.get(g)??g,u=new Set(n.flatMap(g=>g.data.parent?[s(g.data.parent)]:[])),c=n.map(g=>{var T;const w=s(g.data.id),x=xe(e,w),_={...g.data,id:w},C=x&&typeof x=="object"&&!Array.isArray(x)&&"$"in x?x.$:x;if((Array.isArray(C)?C.length>0:C&&typeof C=="object"&&Object.keys(C).some(k=>!k.startsWith("$")))&&(_.config={..._.config,collapsed:!!x.$collapsed}),u.has(w)||(_.viewProps={..._.viewProps},delete _.viewProps.borderWidth),!x||typeof x!="object"||Array.isArray(x))return{data:_};if(x.$form&&typeof x.$form=="object"&&(_.config={..._.config,form:x.$form},_.type="objectView"),Array.isArray(x.$ports)){const k=x.$ports.filter(E=>E&&typeof E.id=="string"&&["source","target"].includes(E.role)&&["top","right","bottom","left"].includes(E.side));_.config={..._.config,ports:k}}return _.parent&&(_.parent=s(_.parent)),typeof x.$label=="string"&&(_.label=x.$label,_.headerTitle=x.$label),typeof x.$subtitle=="string"&&(_.config={..._.config,subtitle:x.$subtitle}),typeof x.$outline=="boolean"&&(_.viewProps={..._.viewProps,outline:x.$outline}),["solid","dashed","dotted","double"].includes(x.$borderStyle)&&(_.viewProps={..._.viewProps,borderStyle:x.$borderStyle}),Number.isFinite(x.$borderWidth)&&x.$borderWidth>=0&&(_.viewProps={..._.viewProps,borderWidth:x.$borderWidth}),Number.isFinite(x.$borderRadius)&&x.$borderRadius>=0&&(_.viewProps={..._.viewProps,borderRadius:x.$borderRadius}),typeof x.$isNodeAnimated=="boolean"&&(_.isNodeAnimated=x.$isNodeAnimated),["traveling","pulse"].includes(x.$nodeAnimationVariant)&&(_.nodeAnimationVariant=x.$nodeAnimationVariant),typeof x.$content=="string"&&(_.config={..._.config,content:x.$content},x.$view||(_.type="objectView")),(((T=_.config)==null?void 0:T.collapsed)!==void 0||x.$collapsed!==void 0||x.$icon!==void 0)&&(_.config={..._.config||{}},(x.$collapsed!==void 0||_.config.collapsed!==void 0)&&(_.config.collapsed=!!x.$collapsed),x.$icon!==void 0&&(_.config.icon=x.$icon)),{data:_}}),l=new Map,d=o.map(g=>{const w=s(g.data.source),x=s(g.data.target),_=`${w}->${x}`,C=l.get(_)??0;l.set(_,C+1);const S={...g.data,id:C?`${_}#${C}`:_,source:w,target:x},T=Vt(S),k=xe(e,T.address);if(k&&typeof k=="object"){const E=k[T.kind==="target"?"$targetEdgeType":"$edgeType"];typeof E=="string"&&(S.type=E);const P=k[T.kind==="target"?"$targetIcon":"$edgeIcon"];typeof P=="string"&&(S.icon=P),k.$isEdgeAnimated!==void 0&&(S.isEdgeAnimated=!!k.$isEdgeAnimated);const R=k[T.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(R)&&(S.edgeAnimationVariant=R),k.$isEdgeDashed!==void 0&&(S.isEdgeDashed=!!k.$isEdgeDashed),k.$edgeColor&&(S.color=k.$edgeColor)}return{data:S}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const g=c.findIndex(w=>w.data.id===zt);g!==-1&&c.splice(g,1)}const f=new Set(c.map(g=>g.data.id));for(let g=d.length-1;g>=0;g--){const w=d[g].data,x=Vt(w);(!f.has(w.source)||!f.has(w.target)||x.kind==="hierarchy"&&((v=xe(e,x.address))==null?void 0:v.$hideParentEdge)===!0)&&d.splice(g,1)}d.push(...r.edges.filter(g=>f.has(g.data.source)&&f.has(g.data.target)));const p=Ux(e,{nodes:c,edges:d}),m=p.nodes.filter(g=>{var w;return(w=g.data.config)==null?void 0:w.collapsed}).map(g=>Ir(g.data.id));if(!m.length)return p;const y=p.nodes.filter(g=>{const w=Ir(g.data.id);return!m.some(x=>x.length<w.length&&x.every((_,C)=>_===w[C]))}),b=new Set(y.map(g=>g.data.id));return{nodes:y,edges:p.edges.filter(g=>b.has(g.data.source)&&b.has(g.data.target))}}function Zx(e,t){const r=new Set(e.filter(u=>{var c,l;return(l=(c=u.data)==null?void 0:c.config)==null?void 0:l.collapsed}).map(u=>u.data.id));if(!r.size)return{nodes:e,edges:t};const n=new Map(e.map(u=>[u.data.id,u])),o=new Set(e.map(u=>u.data.parent).filter(Boolean)),i=new Map(e.map(u=>{var f;let c=u.data.id,l=u.data.parent;const d=new Set([c]);for(;l&&!d.has(l);)r.has(l)&&(c=l),d.add(l),l=(f=n.get(l))==null?void 0:f.data.parent;return[u.data.id,c]})),a=new Map;for(const u of t){const c=u.data.isInverted?u.data.target:u.data.source,l=u.data.isInverted?u.data.source:u.data.target;(a.get(c)??a.set(c,[]).get(c)).push(l)}const s=new Set(e.filter(u=>i.get(u.data.id)!==u.data.id).map(u=>u.data.id));for(const u of r){if(o.has(u))continue;const c=[...a.get(u)||[]];for(;c.length;){const l=c.pop();r.has(l)||s.has(l)||(s.add(l),c.push(...a.get(l)||[]))}}return{nodes:e.filter(u=>!s.has(u.data.id)).map(u=>{var c;return r.has(u.data.id)&&o.has(u.data.id)?{...u,data:{...u.data,type:"arrayView",label:u.data.label??u.data.headerTitle,config:{...u.data.config,parentContainer:!0,labelBelow:!0,icon:((c=u.data.config)==null?void 0:c.icon)||"PiStack"}}}:u}),edges:t.flatMap(u=>{const c=i.get(u.data.source)??u.data.source,l=i.get(u.data.target)??u.data.target;return s.has(c)||s.has(l)?[]:c===u.data.source&&l===u.data.target?[u]:c===l?[]:[{...u,data:{...u.data,source:c,target:l,collapsedEndpoints:u.data.collapsedEndpoints??{source:u.data.source,target:u.data.target}}}]})}}function Tu(e,t){const r=JSON.parse(e);let n=512;const o=(a,s=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!a||typeof a!="object"||Array.isArray(a))throw new Error("Expected a JSON Schema object.");const u=new Set(["$schema","$id","$defs","definitions","$ref","title","description","default","examples","type","properties","required","items","enum","const","anyOf","additionalProperties"]);for(const l of Object.keys(a))if(!u.has(l))throw new Error(`Unsupported JSON Schema keyword: ${l}`);const c=["$schema","$id","$defs","definitions","title","description","default","examples"];if(a.$ref){if(Object.keys(a).some(d=>!["$ref","title","description"].includes(d)))throw new Error("Use $ref without sibling constraints.");if(typeof a.$ref!="string"||!a.$ref.startsWith("#/")||s.includes(a.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let l=r;for(const d of a.$ref.slice(2).split("/")){const f=d.replace(/~1/g,"/").replace(/~0/g,"~");if(!l||!Object.prototype.hasOwnProperty.call(l,f))throw new Error(`Unresolved reference: ${a.$ref}`);l=l[f]}return o(l,[...s,a.$ref])}if(a.anyOf){if(!Array.isArray(a.anyOf)||!a.anyOf.length||Object.keys(a).some(l=>l!=="anyOf"&&!c.includes(l)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:a.anyOf.map(l=>o(l,s))}}if(Object.prototype.hasOwnProperty.call(a,"const")||a.enum){if(Object.keys(a).some(f=>![...c,"const","enum","type"].includes(f))||a.enum&&Object.prototype.hasOwnProperty.call(a,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const l=Object.prototype.hasOwnProperty.call(a,"const")?[a.const]:a.enum;if(!Array.isArray(l)||!l.length)throw new Error("Expected a nonempty enum.");return{kind:"union",types:l.map(f=>{if(f!==null&&!["string","number","boolean"].includes(typeof f))throw new Error("Only primitive literals are supported.");const p=f===null?"null":typeof f;if(a.type&&!(Array.isArray(a.type)?a.type:[a.type]).some(m=>m===p||m==="integer"&&Number.isInteger(f)))throw new Error("Literal does not match its declared type.");return{kind:"literal",value:f}})}}if(Array.isArray(a.type)){if(!a.type.length||a.type.some(l=>typeof l!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(a).some(l=>l!=="type"&&!c.includes(l)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:a.type.map(l=>o({type:l},s))}}if((a.properties||a.required||a.additionalProperties!==void 0)&&a.type!=="object"&&a.type!==void 0)throw new Error("Object constraints require an object type.");if(a.items&&a.type!=="array")throw new Error("items requires an array type.");if(a.type==="object"||a.properties){if(a.additionalProperties!==void 0&&a.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!a.properties||typeof a.properties!="object"||Array.isArray(a.properties))throw new Error("Object schemas must declare properties.");if(a.required!==void 0&&(!Array.isArray(a.required)||a.required.some(d=>typeof d!="string"||!Object.prototype.hasOwnProperty.call(a.properties,d))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(a.properties).map(([d,f])=>[d,{type:o(f,s),optional:!(a.required??[]).includes(d)}]))}}if(a.type==="array")return{kind:"array",items:o(a.items,s)};if(["string","number","integer","boolean","null"].includes(a.type))return{kind:a.type};throw new Error("Every property must declare a supported type.")},i=o(r);if(i.kind!=="object")throw new Error("The root schema must be an object keyed by node ID.");if(Object.values(i.properties).some(a=>a.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:t,nodes:i.properties}}async function Ou(e,t,r,n={}){var m;let o=512;const i=await import("typescript"),a=i.createSourceFile(t,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),s=a.parseDiagnostics;if(s!=null&&s.length)throw new Error("Invalid TypeScript syntax.");const u=new Map;for(const y of a.statements){if(!i.isInterfaceDeclaration(y)&&!i.isTypeAliasDeclaration(y))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((m=y.typeParameters)!=null&&m.length||u.has(y.name.text))throw new Error("Generics and duplicate declarations are not supported.");u.set(y.name.text,y)}const c=(y,b)=>{var _;const v={},g=y.find(C=>i.isIndexSignatureDeclaration(C));let w;if(g&&n.allowJson&&i.isIndexSignatureDeclaration(g)){if(y.filter(C=>i.isIndexSignatureDeclaration(C)).length!==1||g.parameters.length!==1||((_=g.parameters[0].type)==null?void 0:_.kind)!==i.SyntaxKind.StringKeyword||!g.type)throw new Error("Only one string-keyed index signature is supported for forms.");w=d(g.type,b)}return{kind:"object",properties:Object.fromEntries(y.filter(C=>C!==g||!w).map(C=>{if(!i.isPropertySignature(C)||!C.type||!C.name||!i.isIdentifier(C.name)&&!i.isStringLiteral(C.name))throw new Error("Only explicitly typed named properties are supported.");const S=d(C.type,b),T=n.allowJson?i.getJSDocTags(C).filter(k=>k.tagName.text==="port"):[];if(T.length>1)throw new Error(`Duplicate port declaration: ${C.name.text}`);if(T.length){const[k,E,P]=String(T[0].comment??"").trim().split(/\s+/);if(k!=="config"||!E||P||!u.has(E))throw new Error(`Config port ${C.name.text} requires @port config ResourceType`);const R=S.kind==="array";if((S.kind==="array"?S.items.kind:S.kind)!=="string")throw new Error(`Config port ${C.name.text} must be a string or string array reference`);v[C.name.text]={kind:"config",resourceType:E,multiple:R}}return[C.name.text,{type:S,optional:!!C.questionToken}]})),...w?{additionalProperties:w}:{},...Object.keys(v).length?{ports:v}:{}}},l=(y,b)=>{var _;if(b.includes(y))throw new Error("Recursive types are not supported.");const v=u.get(y);if(!v)throw new Error(`Unknown type: ${y}`);let g;if(i.isInterfaceDeclaration(v)){if((_=v.heritageClauses)!=null&&_.length)throw new Error("Interface inheritance is not supported; declare properties explicitly.");g=c(v.members,[...b,y])}else g=d(v.type,[...b,y]);const w=n.allowJson?i.getJSDocTags(v).filter(C=>C.tagName.text==="port"):[];if(!w.length)return g;if(g.kind!=="object")throw new Error("Node ports require an object interface");const x={...g.ports};for(const C of w){const[S,T,k]=String(C.comment??"").trim().split(/\s+/);if(!["input","output","error"].includes(S)||!/^[A-Za-z][\w-]*$/.test(T??"")||k)throw new Error("Node ports require @port input|output|error Name");if(Object.prototype.hasOwnProperty.call(x,T))throw new Error(`Duplicate port declaration: ${T}`);x[T]={kind:S}}return{...g,ports:x}},d=(y,b)=>{var v,g,w;if(--o<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(y.kind===i.SyntaxKind.StringKeyword)return{kind:"string"};if(y.kind===i.SyntaxKind.NumberKeyword)return{kind:"number"};if(y.kind===i.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[i.SyntaxKind.AnyKeyword,i.SyntaxKind.UnknownKeyword].includes(y.kind))return{kind:"json"};if(i.isParenthesizedTypeNode(y))return d(y.type,b);if(i.isUnionTypeNode(y))return{kind:"union",types:y.types.map(x=>d(x,b))};if(i.isArrayTypeNode(y))return{kind:"array",items:d(y.elementType,b)};if(i.isTypeLiteralNode(y))return c(y.members,b);if(i.isLiteralTypeNode(y)){const x=y.literal;if(i.isStringLiteral(x))return{kind:"literal",value:x.text};if(i.isNumericLiteral(x))return{kind:"literal",value:Number(x.text)};if(x.kind===i.SyntaxKind.NullKeyword)return{kind:"null"};if(x.kind===i.SyntaxKind.TrueKeyword||x.kind===i.SyntaxKind.FalseKeyword)return{kind:"literal",value:x.kind===i.SyntaxKind.TrueKeyword}}if(i.isTypeReferenceNode(y)&&i.isIdentifier(y.typeName)){if(n.allowJson&&y.typeName.text==="Record"&&!u.has("Record")&&((v=y.typeArguments)==null?void 0:v.length)===2&&y.typeArguments[0].kind===i.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:d(y.typeArguments[1],b)};if(y.typeName.text==="Array"&&((g=y.typeArguments)==null?void 0:g.length)===1)return{kind:"array",items:d(y.typeArguments[0],b)};if(!((w=y.typeArguments)!=null&&w.length))return l(y.typeName.text,b)}throw new Error(`Unsupported TypeScript type: ${y.getText(a)}`)},f=r??(u.has("Graph")?"Graph":u.size===1?[...u.keys()][0]:void 0);if(!f)throw new Error("Declare an interface Graph keyed by node ID.");const p=l(f,[]);if(p.kind!=="object")throw new Error("Graph must be an object keyed by node ID.");return p}async function em(e,t){const r=await Ou(e,t);if(Object.values(r.properties).some(n=>n.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:t,nodes:r.properties}}function jt(e,t){if(e.kind==="json"||t.kind==="json"||e.kind==="object"&&e.additionalProperties||t.kind==="object"&&t.additionalProperties)return!1;if(e.kind==="union")return e.types.every(r=>jt(r,t));if(t.kind==="union")return t.types.some(r=>jt(e,r));if(e.kind==="literal"){if(t.kind==="literal")return e.value===t.value;const r=e.value===null?"null":typeof e.value;return t.kind===r||t.kind==="integer"&&typeof e.value=="number"&&Number.isInteger(e.value)}return e.kind==="integer"&&t.kind==="number"?!0:e.kind==="array"&&t.kind==="array"?jt(e.items,t.items):e.kind==="object"&&t.kind==="object"?Object.entries(t.properties).every(([r,n])=>{const o=Object.prototype.hasOwnProperty.call(e.properties,r)?e.properties[r]:void 0;return o?(n.optional||!o.optional)&&jt(o.type,n.type):n.optional}):e.kind===t.kind}function Iu(e,t){if(!t.sourceProperty&&!t.targetProperty)return;const r=(a,s)=>{var l;const u=Object.prototype.hasOwnProperty.call(e.nodes,a)?a:a.replace(/^root\./,""),c=Object.prototype.hasOwnProperty.call(e.nodes,u)?(l=e.nodes[u])==null?void 0:l.type:void 0;return s&&(c==null?void 0:c.kind)==="object"&&Object.prototype.hasOwnProperty.call(c.properties,s)?c.properties[s]:void 0},n=r(t.source,t.sourceProperty),o=r(t.target,t.targetProperty);if(!n||!o)return"Unverified: source or target property is missing from the interface.";const i=a=>a.kind==="json"||a.kind==="object"&&(!!a.additionalProperties||Object.values(a.properties).some(s=>i(s.type)))||a.kind==="array"&&i(a.items)||a.kind==="union"&&a.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(!jt(n.type,o.type))return`Incompatible property types: ${t.sourceProperty} -> ${t.targetProperty}.`}async function rm(e){if(e.size>256*1024)throw new Error("Interface must be 256 KB or smaller.");const t=await e.text();if(/\.json$/i.test(e.name))return Tu(t,e.name);if(/\.ts$/i.test(e.name))return em(t,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const _l=new WeakMap;function Wt(e){if(!e||typeof e!="object")return e;const t=_l.get(e);if(t)return t;const r=()=>{throw new Error("Form callback data is read-only. Return edits instead.")},n=new Proxy(Array.isArray(e)?[]:{},{get:(o,i)=>Wt(Reflect.get(e,i)),has:(o,i)=>Reflect.has(e,i),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(o,i)=>{const a=Reflect.getOwnPropertyDescriptor(e,i);return a&&{...a,value:Wt(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:r,deleteProperty:r,defineProperty:r,setPrototypeOf:r,preventExtensions:r});return _l.set(e,n),n}function gt(e,t,r){var o;const n=t.split(".");for(let i=n.length;i>0;i--){const a=n.slice(0,i).join("."),s=(o=xe(e,a))==null?void 0:o.$form;if(!(s!=null&&s.$type))continue;let u=Object.prototype.hasOwnProperty.call(r,s.$type)?r[s.$type]:void 0;for(const d of n.slice(i))(u==null?void 0:u.kind)==="array"&&/^\d+$/.test(d)?u=u.items:(u==null?void 0:u.kind)==="object"?u=Object.prototype.hasOwnProperty.call(u.properties,d)?u.properties[d].type:void 0:u=void 0;if((u==null?void 0:u.kind)!=="object")return;const c=n.slice(i).join("."),l=Object.fromEntries(Object.entries(s.$fields??{}).filter(([d])=>!c||d.startsWith(`${c}.`)).map(([d,f])=>[c?d.slice(c.length+1):d,f]));return{type:u,fields:l,binding:s}}}async function Mu(e,t){if(e.size>256*1024)throw new Error("Form schema exceeds 256 KB.");const r=await e.text();if(e.name.endsWith(".ts")){if(!t.length||t.length>32)throw new Error("Choose between 1 and 32 form interface names.");const o=[],i=new Set(t);for(const a of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const s=await Ou(r,e.name,a,{allowJson:!0});o.push([a,s]);for(const u of Object.values(s.ports??{}))u.resourceType&&i.add(u.resourceType)}return Object.fromEntries(o)}if(!e.name.endsWith(".json"))throw new Error("Choose a .ts interface or .json schema file.");const n=Tu(r,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([o,i])=>[o,i.type]))}function xn(e,t){return!e||("$in"in e?e.$in.includes(xe(t,e.$address)):xe(t,e.$address)===e.$equals)}function $t(e){const t=e.kind==="array"?e.items:e,r=t.kind==="union"?t.types:[t];if(r.every(n=>n.kind==="literal"))return r.map(n=>({label:String(n.value),value:n.value}))}function Rr(e,t,r){if(t===void 0||t==="")return r?"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 a=Object.values(i).every(o);return n.delete(i),a};return o(t)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!Rr(n,t,!0))?void 0:"Choose a valid value";if(e.kind==="literal")return t===e.value?void 0:"Choose a valid value";if(e.kind==="array")return Array.isArray(t)&&t.every(n=>!Rr(e.items,n,!0))?void 0:"Invalid list value";if(e.kind==="object")return!t||typeof t!="object"||Array.isArray(t)?"Expected an object":e.additionalProperties&&Object.entries(t).some(([n,o])=>!Object.prototype.hasOwnProperty.call(e.properties,n)&&Rr(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>Rr(o.type,t[n],!o.optional))?"Invalid object fields":void 0;if(e.kind==="null")return t===null?void 0:"Expected null";if(e.kind==="integer")return Number.isInteger(t)?void 0:"Expected a whole number";if(typeof t!==e.kind||typeof t=="number"&&!Number.isFinite(t))return`Expected ${e.kind}`}function Sl(e,t){const r=t.address.split(".");if(r.shift()!=="root"||!r.length||r.some(s=>!s||["__proto__","prototype","constructor","#"].includes(s)))throw new Error("Invalid form field address.");const n=r.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(r.some(s=>s.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...r].join("."),a=xe(e,i);if(!a||typeof a!="object")throw new Error(`Missing form parent: ${i}`);if(o){if(t.op==="set"&&typeof t.value!="string")throw new Error("Node colors must be strings.");return ir(e,i,n,t.op==="remove"?void 0:t.value)}return pr(e,i,s=>{const u=Array.isArray(s.$)?s.$:s;if(t.op==="remove"&&!Object.prototype.hasOwnProperty.call(u,n)||t.op==="set"&&Object.is(u[n],t.value))return s;const c=Array.isArray(u)?[...u]:{...u};if(Array.isArray(c)&&(!/^(0|[1-9]\d*)$/.test(n)||Number(n)>=c.length))throw new Error("Invalid array address.");return t.op==="remove"?Array.isArray(c)?c.splice(Number(n),1):delete c[n]:Object.defineProperty(c,n,{value:structuredClone(t.value),enumerable:!0,writable:!0,configurable:!0}),u===s?c:{...s,$:c}})}function wn(e,t,r){let n=Sl(e,t.value===void 0?{op:"remove",address:t.address}:{op:"set",address:t.address,value:t.value});const o=r==null?void 0:r({...t,previousValue:Wt(xe(e,t.address)),data:Wt(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=Sl(n,i)}return n}function Jx(e,t){let r=e;for(const n of t){if(n.op!=="set"&&n.op!=="remove")throw new Error("Unsupported state edit.");const o=n.address.split(".");if(o.some(a=>a.startsWith("$")||["__proto__","prototype","constructor"].includes(a)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;Gt(i),r=wn(r,{address:n.address,nodeAddress:o.slice(0,-1).join("."),value:i})}return Gt(r),r}function Yt(e,t,r){const n=Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;if(!(!n||!r||!Object.prototype.hasOwnProperty.call(r,n.type)))return{address:n.address,type:r[n.type],fields:n.fields??{}}}function Gt(e){if(!(!e||typeof e!="object"))for(const[t,r]of Object.entries(e)){if(t.startsWith("$")||["__proto__","prototype","constructor"].includes(t))throw new Error(`Form state cannot contain view metadata or unsafe keys: ${t}`);Gt(r)}}function Yx(e,t,r){Gt(t.value);const n=wn(e,t,r);return Gt(n),n}function tm(e,t){const r=(n,o="")=>{if(!n||typeof n!="object")return n;if(["$label","$subtitle","$content","$icon","$bgColor","$textColor","$borderColor"].includes(o)&&typeof n.$state=="string"){const a=xe(t,n.$state);return a==null?"":typeof a=="object"?JSON.stringify(a,null,2):String(a)}let i=n;for(const[a,s]of Object.entries(n)){const u=r(s,a);u!==s&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,a,{value:u,enumerable:!0,writable:!0,configurable:!0}))}return i};return r(e)}const Yr=(e="reference")=>({kind:e,text:"",paths:[""]}),nm=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(t=>["__proto__","constructor","prototype"].includes(t));function Xx(e,t){const r=new Set(t.map(a=>a.path)),n=a=>{if(!a.paths.length||a.paths.some(s=>!nm(s)||!r.has(s)))throw new Error("Choose an available reference.");return[...a.paths,...a.fallback===void 0?[]:[JSON.stringify(a.fallback)]].join(" || ")},o=a=>{if(a.includes("{{")||a.includes("}}"))throw new Error("Use a reference part for dynamic values.");return a},i=a=>a.map(s=>{if(s.kind==="text")return o(s.text);if(s.kind==="conditional"){if(s.paths.length!==1||s.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(s)}}}${o(s.text)}{{/if}}`}return`{{${n(s)}}}`}).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 a=i(e.parts);return e.mode==="condition"?`${a} == ${JSON.stringify(e.comparison)}`:a}if(e.mode==="json"){const a=e.fields.map(s=>s.key);if(!a.length||new Set(a).size!==a.length||a.some(s=>!s||["__proto__","constructor","prototype"].includes(s)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(s=>[s.key,i(s.parts)])))}return i(e.parts)}async function Qx(e){const t=await import("typescript"),r=a=>{const s=t.createSourceFile("binding.ts",`(${a})`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS);if(s.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const u=s.statements[0];if(!u||!t.isExpressionStatement(u))throw new Error("Unsupported reference expression.");const c=Yr();c.paths=[];const l=d=>{if(t.isParenthesizedExpression(d))return l(d.expression);if(t.isBinaryExpression(d)&&d.operatorToken.kind===t.SyntaxKind.BarBarToken){l(d.left),l(d.right);return}if(t.isStringLiteral(d)){if(c.fallback!==void 0)throw new Error("Multiple fallback values.");c.fallback=d.text;return}const f=d.getText(s);if(!nm(f)||c.fallback!==void 0)throw new Error("Unsupported reference expression.");c.paths.push(f)};if(l(u.expression),!c.paths.length)throw new Error("A binding needs a reference.");return c},n=a=>{const s=[];let u=0;const c=/\{\{([\s\S]*?)\}\}/g;for(const l of a.matchAll(c)){const d=l.index;if(d<u)continue;d>u&&s.push({...Yr("text"),text:a.slice(u,d)});const f=l[1].trim();if(f.startsWith("#if ")){const p=a.indexOf("{{/if}}",d+l[0].length);if(p<0)throw new Error("Unclosed condition.");s.push({...r(f.slice(4)),kind:"conditional",text:a.slice(d+l[0].length,p)}),u=p+7}else s.push(r(f)),u=d+l[0].length}return u<a.length&&s.push({...Yr("text"),text:a.slice(u)}),s},o={mode:"reference",parts:[Yr()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const a=JSON.parse(e);if(a&&typeof a=="object"&&!Array.isArray(a)&&Object.values(a).every(s=>typeof s=="string"))return{...o,mode:"json",fields:Object.entries(a).map(([s,u])=>({key:s,parts:n(u)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const a=t.createSourceFile("condition.ts",`value ${i[1].text}`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS),s=a.statements[0];if(a.statements.length===1&&t.isExpressionStatement(s)&&t.isBinaryExpression(s.expression)&&s.expression.operatorToken.kind===t.SyntaxKind.EqualsEqualsToken&&t.isStringLiteral(s.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:s.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function El({parts:e,references:t,onChange:r,disabled:n}){const o=(i,a)=>r(e.map((s,u)=>u===i?{...s,...a}:s));return h.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,a)=>h.jsxs("fieldset",{"data-binding-part":a,style:{border:0,padding:0,margin:0,minWidth:0},children:[h.jsxs("legend",{children:["Part ",a+1]}),h.jsxs("div",{style:{display:"flex",gap:8},children:[h.jsxs("span",{"data-form-select":"",style:{flex:1},children:[h.jsxs("select",{"aria-label":"Part type",disabled:n,value:i.kind,onChange:s=>o(a,{kind:s.target.value}),children:[h.jsx("option",{value:"reference",children:"Reference"}),h.jsx("option",{value:"text",children:"Text"}),h.jsx("option",{value:"conditional",children:"Conditional text"})]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),h.jsx(ve,{"aria-label":`Remove part ${a+1}`,title:"Remove part",icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r(e.filter((s,u)=>u!==a))})]}),i.kind!=="text"&&h.jsxs(h.Fragment,{children:[i.paths.map((s,u)=>h.jsxs("label",{children:["Reference ",u+1,h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsxs("select",{"aria-label":`Reference ${u+1}`,disabled:n,value:s,onChange:c=>o(a,{paths:i.paths.map((l,d)=>d===u?c.target.value:l)}),children:[h.jsx("option",{value:"",children:"Select reference"}),t.map(c=>h.jsx("option",{value:c.path,children:c.label},c.path))]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},u)),i.kind==="reference"&&h.jsxs(h.Fragment,{children:[h.jsx(ve,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:h.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>o(a,{paths:[...i.paths,""]})}),h.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center"},children:[h.jsx("input",{type:"checkbox","aria-label":"Default value enabled",disabled:n,checked:i.fallback!==void 0,onChange:s=>o(a,{fallback:s.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&h.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:s=>o(a,{fallback:s.target.value})})]})]}),i.kind!=="reference"&&h.jsxs("label",{children:["Text",h.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:s=>o(a,{text:s.target.value})})]})]},a)),h.jsx(ve,{"aria-label":"Add part",title:"Add part",icon:h.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r([...e,Yr()])})]})}function e0({label:e,value:t,references:r,disabled:n,onChange:o}){const[i,a]=j.useState(),[s,u]=j.useState(""),[c,l]=j.useState(!1),d=async()=>{l(!0),u("");try{a(await Qx(typeof t=="string"?t:""))}catch(f){u(f instanceof Error?f.message:"Unable to read binding.")}finally{l(!1)}};return h.jsxs("div",{"data-runtime-binding":e,style:{marginBottom:8},children:[h.jsx(ve,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:h.jsx(Z.PiLink,{size:18}),size:"sm",variant:"ghost",disabled:n||c,onClick:d}),typeof t=="string"&&t.includes("{{")&&h.jsx("span",{children:"Bound value"}),i&&h.jsxs("fieldset",{disabled:n,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[h.jsxs("label",{children:["Binding mode",h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsxs("select",{"aria-label":"Binding mode",value:i.mode,onChange:f=>a({...i,mode:f.target.value,parts:[Yr()]}),children:[h.jsx("option",{value:"reference",children:"Reference"}),h.jsx("option",{value:"condition",children:"Equals"}),h.jsx("option",{value:"template",children:"Text template"}),h.jsx("option",{value:"json",children:"JSON output"})]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),i.mode==="json"?h.jsxs(h.Fragment,{children:[i.fields.map((f,p)=>h.jsxs("fieldset",{"data-output-field":p,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[h.jsxs("label",{children:["Output field name",h.jsx("input",{"aria-label":"Output field name",value:f.key,onChange:m=>a({...i,fields:i.fields.map((y,b)=>b===p?{...y,key:m.target.value}:y)})})]}),h.jsx(El,{parts:f.parts,references:r,disabled:n,onChange:m=>a({...i,fields:i.fields.map((y,b)=>b===p?{...y,parts:m}:y)})}),h.jsx(ve,{"aria-label":"Remove output field",title:"Remove output field",icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>a({...i,fields:i.fields.filter((m,y)=>y!==p)})})]},p)),h.jsx(ve,{"aria-label":"Add output field",title:"Add output field",icon:h.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>a({...i,fields:[...i.fields,{key:"",parts:[Yr()]}]})})]}):h.jsx(El,{parts:i.parts,references:r,disabled:n,onChange:f=>a({...i,parts:f})}),i.mode==="condition"&&h.jsxs("label",{children:["Equals",h.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:f=>a({...i,comparison:f.target.value})})]}),h.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[h.jsx(ve,{"aria-label":"Apply binding",title:"Apply binding",icon:h.jsx(Z.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(Xx(i,r)),a(void 0),u("")}catch(f){u(f instanceof Error?f.message:"Unable to apply binding.")}}}),h.jsx(ve,{"aria-label":"Cancel binding",title:"Cancel binding",icon:h.jsx(Z.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{a(void 0),u("")}})]})]}),s&&h.jsx("p",{role:"alert",children:s})]})}const r0=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),t0=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,Rt=(e,t)=>JSON.stringify([e,t]);function Ut(e,t){if(e.kind==="union"){const r=e.types.find(n=>n.kind===(Array.isArray(t)?"array":t===null?"null":typeof t)||n.kind==="literal"&&Object.is(n.value,t));return Ut(r??e.types.find(n=>n.kind!=="null")??e.types[0]??{kind:"json"},t)}return e.kind!=="json"?e:Array.isArray(t)?{kind:"array",items:{kind:"json"}}:t!==null&&typeof t=="object"||t===void 0?{kind:"object",properties:{},additionalProperties:{kind:"json"}}:{kind:t===null?"null":typeof t}}function kt(e){const t=Ut(e,void 0);return t.kind==="object"?{}:t.kind==="array"?[]:t.kind==="literal"?t.value:t.kind==="number"||t.kind==="integer"?0:t.kind==="boolean"?!1:t.kind==="null"?null:""}function jl(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"&&!$t(e)?e.types:[e]}function n0(e,t,r){if(t.address===r.address)return;const n=xe(e,t.address),o=(i,a)=>a===void 0?!1:i.kind==="union"?i.types.some(s=>o(s,a)):i.kind==="array"?Array.isArray(a)&&a.every(s=>o(i.items,s)):i.kind==="object"?!!a&&typeof a=="object"&&!Array.isArray(a)&&Object.entries(i.properties).every(([s,u])=>u.optional&&a[s]===void 0||o(u.type,a[s]))&&Object.entries(a).every(([s,u])=>Object.prototype.hasOwnProperty.call(i.properties,s)||!i.additionalProperties||o(i.additionalProperties,u)):a===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!Rr(i,a,!0);if(o(r.type,n))return structuredClone(n)}function o0(e,t,r,n){var u;const o={sourceSchema:r,sourceBindings:t,nodes:[],edges:[],schema:{...r},bindings:{...t},slots:new Map,containers:new Map},i=new Set(n.map(c=>c.data.id)),a=new Map(n.flatMap(c=>{const l=t[c.data.id];return l&&r[l.type]?[[l.address,c.data.id]]:[]})),s=(c,l,d,f,p,m=!1)=>{var C,S,T;if(p>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const y=xe(e,l),b=Ut(d,y),v=b.kind!=="object"&&b.kind!=="array";o.containers.set(c,{address:l,type:b,declared:d,scalar:v});const g=`__form:${c}`,w={...(C=o.bindings[c])==null?void 0:C.fields},x={kind:"object",properties:{},ports:{...b.kind==="object"?b.ports:{},...m?{resource:{kind:"output"}}:{}}},_=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,E)=>[String(E),{type:b.items,optional:!0}])):{value:{type:$t(d)?d:b,optional:!1}};for(const[k,E]of Object.entries(_)){if(!r0(k))throw new Error(`Unsupported structured property key: ${k}`);const P=v?l:`${l}.${k}`,R=xe(e,P),I=Ut(E.type,R),O=I.kind==="object"||I.kind==="array",M=(S=x.ports)==null?void 0:S[k],q=(M==null?void 0:M.kind)==="config"&&(((T=w[k])==null?void 0:T.$options)||$t(E.type)),K=E.type.kind==="json"||E.type.kind==="union"&&!$t(E.type);if(!O&&b.kind!=="array"&&(!K||v)||q){x.properties[k]={...E,type:E.type.kind==="json"?I:E.type};continue}const V=a.get(P)??t0(P),re=b.kind==="array"?`Item ${Number(k)+1}`:k,ce={address:P,owner:c,field:k,type:E.type,label:re,nodeId:V,present:R!==void 0};if(o.slots.set(Rt(c,k),ce),x.ports[k]={kind:"config",resourceType:`__form:${V}`},R===void 0||(o.edges.push({data:{id:`__form-edge:${c}:${k}`,source:V,target:c,sourceProperty:"output:resource",targetProperty:`config:${k}`,isEdgeDashed:!0}}),o.containers.has(V)||a.has(P)))continue;if(i.has(V))throw new Error(`Structured node identity conflict: ${V}`);i.add(V);const he={data:{id:V,type:"objectView",label:re,headerTitle:re,description:{},config:{form:!0,icon:I.kind==="array"?"PiListNumbers":O?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:f}}};o.nodes.push(he),s(V,P,E.type,f,p+1,!0);const me=o.schema[`__form:${V}`];he.data.description=Object.fromEntries(Object.keys(me.properties).map(H=>[H,xe(e,I.kind==="array"||I.kind==="object"?`${P}.${H}`:P)]).filter(([,H])=>H!==void 0))}o.schema[g]=x,o.bindings[c]={...o.bindings[c],address:l,type:g,fields:w}};for(const c of n){const l=t[c.data.id],d=l&&r[l.type];!l||!d||xe(e,l.address)===void 0||s(c.data.id,l.address,d,(u=c.data.viewProps)==null?void 0:u.bgColor,0,o.edges.some(f=>f.data.source===c.data.id))}for(const c of o.edges){const l=o.bindings[c.data.source];o.schema[l.type].ports.resource={kind:"output"}}return o}function i0({nodeAddress:e}){const{structured:t,data:r,callbacks:n,editable:o}=j.useContext(kr),i=Ie(),[a,s]=j.useState(""),[u,c]=j.useState("0"),[l,d]=j.useState(""),f=t==null?void 0:t.containers.get(e);if(!f||!r||!t)return null;const p=i.readOnly||i.config.editable===!1||!o,m=xe(r,f.address),y=jl(f.declared),b=f.type.kind==="array"?f.type.items:f.type.kind==="object"?f.type.additionalProperties:void 0,v=b?jl(b):[],g=E=>E.kind==="literal"?String(E.value):E.kind==="string"?"Text":Cr(E.kind),w=[...t.slots.values()].filter(E=>E.owner===e),x=(E,P)=>{var R;return(R=n.onFormChange)==null?void 0:R.call(n,{data:r,nodeAddress:f.address,address:E,previousValue:xe(r,E),value:P})},_=E=>{var P;i.setSelectedNodeIds([E]),(P=i.engineRef.current)==null||P.focusNode(E,90,!1)},C=(E,P)=>{if(!Array.isArray(m))return;const R=[...m];[R[E],R[E+P]]=[R[E+P],R[E]],x(f.address,R)},S=()=>{const E=v[Number(u)]??v[0];if(E)if(f.type.kind==="array")x(f.address,[...Array.isArray(m)?m:[],kt(E)]);else{if(!a||a.includes(".")||a.startsWith("$")||["__proto__","constructor","prototype"].includes(a)){d("Choose a property name without dots or reserved prefixes.");return}if(Object.prototype.hasOwnProperty.call(m,a)){d("Property already exists.");return}x(`${f.address}.${a}`,kt(E)),s(""),d("")}},T=f.type.kind==="object"&&!!f.type.additionalProperties,k=f.type.kind==="array";return h.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[y.length>1&&h.jsxs("label",{children:["Value type",h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsx("select",{"aria-label":"Value type",disabled:p,value:y.findIndex(E=>Ut(E,m).kind===f.type.kind),onChange:E=>x(f.address,kt(y[Number(E.target.value)])),children:y.map((E,P)=>h.jsx("option",{value:P,children:g(E)},P))}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),w.map((E,P)=>h.jsxs("div",{"data-structured-slot":E.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[E.type.kind==="array"?h.jsx(Z.PiListNumbers,{size:20}):h.jsx(Z.PiBracketsCurly,{size:20}),h.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:Cr(E.label)}),h.jsx(ve,{"aria-label":`${E.present?"Focus":"Create"} ${Cr(E.label)}`,title:`${E.present?"Focus":"Create"} ${Cr(E.label)}`,icon:E.present?h.jsx(Z.PiMagnifyingGlass,{size:18}):h.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:p&&!E.present,onClick:R=>{var I;E.present?((I=R.currentTarget.closest("dialog"))==null||I.close(),_(E.nodeId)):x(E.address,kt(E.type))}}),k&&h.jsxs(h.Fragment,{children:[h.jsx(ve,{"aria-label":`Move item ${P+1} up`,icon:h.jsx(Z.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:p||P===0,onClick:()=>C(P,-1)}),h.jsx(ve,{"aria-label":`Move item ${P+1} down`,icon:h.jsx(Z.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:p||P===w.length-1,onClick:()=>C(P,1)})]}),E.present&&h.jsx(ve,{"aria-label":`Remove ${Cr(E.label)}`,icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:p,onClick:()=>k?x(f.address,m.filter((R,I)=>I!==P)):x(E.address,void 0)})]},E.address)),(k||T)&&h.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[T&&h.jsxs("label",{style:{flex:"1 1 120px",minWidth:0},children:["Property name",h.jsx("input",{"aria-label":"Property name",value:a,disabled:p,onChange:E=>s(E.target.value)})]}),v.length>1&&h.jsxs("label",{style:{flex:"1 1 100px"},children:["New value type",h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsx("select",{"aria-label":"New value type",value:u,disabled:p,onChange:E=>c(E.target.value),children:v.map((E,P)=>h.jsx("option",{value:P,children:g(E)},P))}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),h.jsx("span",{style:{display:"flex",alignItems:"center",flexShrink:0,...T||v.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:h.jsx(ve,{"aria-label":k?"Add item":"Add property",icon:h.jsx(Z.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:p,onClick:S})})]}),l&&h.jsx("p",{role:"alert",children:l})]})}const kr=j.createContext({callbacks:{}}),nn=yn.default.div`
52
55
  padding: 0;
53
56
  font-size: 16px;
54
57
  line-height: 1.4;
@@ -146,8 +149,9 @@
146
149
  font-size: 14px;
147
150
  margin-top: 8px;
148
151
  }
149
- `;function Rl({request:e,property:t,config:r,value:n,disabled:o}){var B,W;const{callbacks:i,structured:a,references:s}=E.useContext(kr),{themeColor:u}=Ie(),{background:c}=Ve(),l=E.useId(),d=t.type.kind==="object"||t.type.kind==="array"||t.type.kind==="json",f=n===void 0?"":d?JSON.stringify(n,null,2):String(n),[p,b]=E.useState(f),[y,m]=E.useState(""),[x,g]=E.useState(0),[w,v]=E.useState(),_=((B=r.$options)==null?void 0:B.$source)==="callback",C=i.resolveFormOptions,{data:S,address:T,nodeAddress:k,nodeId:j}=e,P=E.useRef(S);P.current=S;const R=JSON.stringify([T,j,(W=r.$options)!=null&&W.$dependsOn?r.$options.$dependsOn.map(z=>xe(S,z)):xe(S,k)]);E.useEffect(()=>{b(f),m("")},[f,T,j]),E.useEffect(()=>{if(!_)return;const z=new AbortController;return Promise.resolve().then(()=>{if(!C)throw new Error("No options resolver configured");return C({address:T,nodeAddress:k,nodeId:j,data:Vt(P.current),signal:z.signal})}).then(X=>{if(!Array.isArray(X)||X.some(se=>!se||typeof se.label!="string"||!["string","number","boolean"].includes(typeof se.value)&&se.value!==null))throw new Error("Invalid options response");z.signal.aborted||v({key:R,options:X})}).catch(X=>{z.signal.aborted||v({key:R,options:[],error:X instanceof Error?X.message:"Options unavailable"})}),()=>z.abort()},[_,C,R,T,k,j,x]);const I=_&&(w==null?void 0:w.key)!==R,O=_?(w==null?void 0:w.key)===R?w.options:[]:t.type.kind==="null"?[{label:"Null",value:null}]:t.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:Nt(t.type),M=t.type.kind==="array",q=(a&&d||r.$control==="checkbox"?"pills":r.$control)??(O?M||t.type.kind==="boolean"?"pills":"select":t.type.kind==="boolean"?"checkbox":d?"textarea":"input"),H=!t.optional||!!r.$requiredWhen&&vn(r.$requiredWhen,S),V=!!(s!=null&&s.length)&&typeof n=="string"&&n.includes("{{"),re=y||_&&(w==null?void 0:w.key)===R&&w.error||!V&&Rr(t.type,n,H),ce=Cr(r.$label??T.split(".").pop()),le=z=>{var X;if(!(o||Object.is(z,n)))try{(X=i.onFormChange)==null||X.call(i,{...e,previousValue:n,value:z}),m("")}catch(se){m(se instanceof Error?se.message:"Unable to update field")}},be=()=>{if(d){try{const Q=p===""&&t.optional?void 0:JSON.parse(p),G=Rr(t.type,Q,H);if(G){m(G);return}le(Q)}catch{m("Enter valid JSON")}return}const z=t.type.kind==="number"||t.type.kind==="integer",X=p===""&&t.optional?void 0:z&&p!==""?Number(p):p,se=Rr(t.type,X,H);if(z&&se&&p!==""){m(se);return}le(X)},K={id:l,disabled:o,"aria-label":ce,"aria-required":H,"aria-invalid":!!re,"aria-describedby":re?`${l}-error`:void 0},N=pe(u);return h.jsxs("div",{"data-form-field":T,"data-flow-property":T.slice(k.length+1),children:[h.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[h.jsxs("label",{htmlFor:l,children:[ce,H?" *":""]}),t.optional&&n!==void 0&&h.jsx("button",{type:"button","aria-label":`Reset ${ce}`,title:`Reset ${ce}`,disabled:o,style:{width:24,height:24,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:0,background:"transparent",color:"inherit"},onClick:()=>le(void 0),children:h.jsx(Z.PiArrowCounterClockwise,{size:14})})]}),!!(s!=null&&s.length)&&!d&&h.jsx(Yx,{label:ce,value:n,references:s,disabled:o,onChange:le}),V?null:q==="select"?h.jsxs("div",{"data-form-select":"",children:[h.jsxs("select",{...K,disabled:o||I||!!(w!=null&&w.error),value:(O==null?void 0:O.findIndex(z=>Object.is(z.value,n)))??-1,onChange:z=>{const X=O==null?void 0:O[Number(z.target.value)];X&&le(X.value)},children:[h.jsx("option",{value:-1,disabled:!0,children:n!==void 0?String(n):""}),O==null?void 0:O.map((z,X)=>h.jsx("option",{value:X,style:{background:pe(c)},children:Cr(z.label)||z.label},X))]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}):q==="pills"?h.jsxs("div",{id:l,role:"group","aria-label":ce,"aria-describedby":K["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:[O==null?void 0:O.map((z,X)=>{const se=M?Array.isArray(n)&&n.includes(z.value):Object.is(n,z.value);return h.jsx("button",{type:"button",disabled:o||I,"aria-pressed":se,style:{padding:"8px 16px",borderRadius:24,border:0,color:se?N:"inherit",background:se?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>le(M?se?n.filter(Q=>Q!==z.value):[...Array.isArray(n)?n:[],z.value]:z.value),children:Cr(z.label)||z.label},X)}),I&&h.jsx("span",{role:"status",children:"Loading..."})]}):q==="textarea"?h.jsx("textarea",{...K,value:p,onChange:z=>b(z.target.value),onBlur:be}):h.jsx("input",{...K,type:t.type.kind==="number"||t.type.kind==="integer"?"number":"text",step:t.type.kind==="integer"?1:"any",value:p,onChange:z=>b(z.target.value),onBlur:be,onKeyDown:z=>{z.key==="Enter"&&be(),z.key==="Escape"&&b(n===void 0?"":String(n))}}),re&&h.jsx("div",{role:"alert",id:`${l}-error`,children:re}),_&&(w==null?void 0:w.error)&&h.jsx("button",{type:"button",disabled:o,onClick:()=>{v(void 0),g(x+1)},children:"Retry"})]})}function rb({nodeAddress:e}){var v,_;const{data:t,schema:r,callbacks:n,bindings:o,editable:i,renderForm:a,structured:s}=E.useContext(kr),{readOnly:u,config:c}=Ie(),l=a==null?void 0:a(e);if(l!==void 0)return h.jsx("fieldset",{"data-flow-form":e,disabled:u||c.editable===!1||!i,style:{border:0,margin:0,padding:0,minWidth:0},children:l});if(!t)return h.jsx(tn,{role:"alert",children:"Forms require a JSON document."});const d=o?Jt(o,e,r):void 0,f=o?d:r&&pt(t,e,r);if(!f)return h.jsx(tn,{role:"status",children:"Form schema unavailable."});const p=(d==null?void 0:d.address)??e,b=xe(t,p),y=(v=s==null?void 0:s.containers.get(e))==null?void 0:v.scalar;if(b===void 0||typeof b!="object"&&!y)return h.jsx(tn,{role:"alert",children:"Bound form state is unavailable."});const m=Object.entries(f.type.properties).filter(([C])=>{var S;return vn((S=f.fields[C])==null?void 0:S.$visibleWhen,t)}),x=m.length>8||m.some(([C])=>{var S;return(S=f.fields[C])==null?void 0:S.$section}),g=new Map;for(const C of m){const[S,T]=C,k=x?Cr(((_=f.fields[S])==null?void 0:_.$section)??(T.type.kind==="object"||T.type.kind==="array"?S:T.optional?"Options":"General")):"";g.has(k)||g.set(k,[]),g.get(k).push(C)}const w=([C,S])=>h.jsx(Rl,{request:{data:t,address:y?p:`${p}.${C}`,nodeAddress:p,nodeId:typeof(b==null?void 0:b.id)=="string"?b.id:void 0},property:S,config:f.fields[C]??{},value:y?b:b==null?void 0:b[C],disabled:u||c.editable===!1||!(i??!!n.onJsonChange)},`${(b==null?void 0:b.id)??e}:${C}`);return h.jsxs(tn,{"data-flow-form":e,onClick:C=>C.stopPropagation(),onDoubleClick:C=>C.stopPropagation(),children:[s&&h.jsx(t0,{nodeAddress:e}),d&&f.type.additionalProperties&&m.length===0&&h.jsx(Rl,{request:{data:t,address:p,nodeAddress:p},property:{type:f.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:b,disabled:u||c.editable===!1||!i}),[...g].map(([C,S])=>x&&S.length>1?h.jsxs("details",{open:!0,children:[h.jsxs("summary",{children:[h.jsx("span",{children:C}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),S.map(w)]},C):S.map(w))]})}function tb(e){const{viewData:t}=E.useContext(kr),{nodeById:r,edgeById:n,parentIds:o}=Wr();if(t){const i=xe(t,e),a=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(a)?a.length>0:!!a&&typeof a=="object"&&Object.entries(a).some(([s,u])=>!s.startsWith("$")&&u!==null&&typeof u=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const a=i.isInverted?i.target:i.source,s=i.isInverted?i.source:i.target;return a===e&&s!==e&&r.has(s)})}function Ut(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:t}function ln(e,t,r,n){return{borderColor:t,borderWidth:Ut(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",...Su(t==="transparent"?"currentColor":t,r,".flow-sdk-node:hover &",!r)}}function nb({label:e,value:t,options:r,onChange:n,disabled:o}){var i;return h.jsxs(Or,{"aria-label":e,title:`Animation: ${((i=r.find(a=>a.value===t))==null?void 0:i.label)??"Mixed"}`,value:t,style:{width:104},disabled:o,onValueChange:a=>{const s=r.find(u=>u.value===a);s&&n(s.value)},children:[t===""&&h.jsx("option",{value:"",disabled:!0,children:"Mixed"}),r.map(a=>h.jsx("option",{value:a.value,children:a.label},a.value))]})}const dn="data:image/svg+xml;base64,";function kt(e){if(e.startsWith(dn))return!0;try{const t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:")&&!t.username&&!t.password}catch{return!1}}async function n0(e){if(e.size>256*1024)throw new Error("SVG must be 256 KB or smaller.");const t=await e.text(),r=new DOMParser().parseFromString(t,"image/svg+xml");if(r.doctype||r.querySelector("parsererror")||r.documentElement.localName!=="svg"||r.documentElement.namespaceURI!=="http://www.w3.org/2000/svg")throw new Error("Choose a valid SVG file.");if(r.querySelector("script, foreignObject")||[...r.querySelectorAll("*")].some(i=>[...i.attributes].some(a=>/^on/i.test(a.name))))throw new Error("SVG scripts and event handlers are not allowed.");const n=new TextEncoder().encode(t);let o="";for(const i of n)o+=String.fromCharCode(i);return dn+btoa(o)}const Mr=({name:e,svg:t=!1,...r})=>{const[n,o]=E.useState(null),[i,a]=E.useState(!0),[s,u]=E.useState(!1),c=typeof e=="string"&&kt(e);if(E.useEffect(()=>{if(c||!e||e.length<2){o(null),a(!1);return}a(!0),u(!1),(async()=>{try{let d;if(e.startsWith("Md"))d="md";else if(e.startsWith("Fa"))d="fa6";else if(e.startsWith("Io5"))d="io5";else if(e.startsWith("Io"))d="io";else if(e.startsWith("Ti"))d="ti";else if(e.startsWith("Go"))d="go";else if(e.startsWith("Fi"))d="fi";else if(e.startsWith("Di"))d="di";else if(e.startsWith("Ai"))d="ai";else if(e.startsWith("Bs"))d="bs";else if(e.startsWith("Ri"))d="ri";else if(e.startsWith("Fc"))d="fc";else if(e.startsWith("Gi"))d="gi";else if(e.startsWith("Hi2"))d="hi2";else if(e.startsWith("Hi"))d="hi";else if(e.startsWith("Si"))d="si";else if(e.startsWith("Sl"))d="sl";else if(e.startsWith("Im"))d="im";else if(e.startsWith("Bi"))d="bi";else if(e.startsWith("Pi"))d="pi";else if(e.startsWith("Vsc"))d="vsc";else if(e.startsWith("Tb"))d="tb";else if(e.startsWith("Tfi"))d="tfi";else if(e.startsWith("Cg"))d="cg";else if(e.startsWith("Lia"))d="lia";else if(e.startsWith("Lu"))d="lu";else throw new Error(`Unknown library prefix for icon: ${e}`);let f;switch(d){case"md":f=await import("react-icons/md");break;case"fa6":f=await import("react-icons/fa6");break;case"io5":f=await import("react-icons/io5");break;case"io":f=await import("react-icons/io");break;case"ti":f=await import("react-icons/ti");break;case"go":f=await import("react-icons/go");break;case"fi":f=await import("react-icons/fi");break;case"di":f=await import("react-icons/di");break;case"ai":f=await import("react-icons/ai");break;case"bs":f=await import("react-icons/bs");break;case"ri":f=await import("react-icons/ri");break;case"fc":f=await import("react-icons/fc");break;case"gi":f=await import("react-icons/gi");break;case"hi2":f=await import("react-icons/hi2");break;case"hi":f=await import("react-icons/hi");break;case"si":f=await import("react-icons/si");break;case"sl":f=await import("react-icons/sl");break;case"im":f=await import("react-icons/im");break;case"bi":f=await import("react-icons/bi");break;case"pi":f=await import("react-icons/pi");break;case"vsc":f=await import("react-icons/vsc");break;case"tb":f=await import("react-icons/tb");break;case"tfi":f=await import("react-icons/tfi");break;case"cg":f=await import("react-icons/cg");break;case"lia":f=await import("react-icons/lia");break;case"lu":f=await import("react-icons/lu");break;default:throw new Error(`Unsupported library: ${d}`)}const p=f[e];if(!p)throw new Error(`Icon ${e} not found in library ${d}`);o(()=>p)}catch(d){console.warn(`Failed to load icon ${e}:`,d.message),u(!0),o(null)}finally{a(!1)}})()},[e,c]),c){const{size:l=80,style:d,...f}=r;return t?h.jsx("image",{...f,href:e,width:l,height:l,preserveAspectRatio:"xMidYMid meet",style:d}):h.jsx("img",{...f,src:e,alt:"",width:l,height:l,referrerPolicy:"no-referrer",style:{objectFit:"contain",...d}})}return i||!n?null:h.jsx(n,{...r})};function qu({nodeId:e,edgeId:t,value:r}){const{callbacks:n,readOnly:o,themeColor:i}=Ie(),{background:a,backgroundSecondary:s,border:u,colorText:c}=Ve(),l=E.useRef(null),d=E.useId(),f=E.useRef(null),p=E.useRef(0),[b,y]=E.useState(!1),[m,x]=E.useState("icons"),[g,w]=E.useState([]),[v,_]=E.useState("loading"),[C,S]=E.useState(""),[T,k]=E.useState(0),[j,P]=E.useState(""),[R,I]=E.useState(""),[O,M]=E.useState(!1);E.useEffect(()=>()=>{p.current++},[]),E.useEffect(()=>{if(!b)return;let K=!0;return import("react-icons/pi").then(N=>{K&&(w(Object.keys(N).filter(B=>B.startsWith("Pi")).sort()),_("ready"))}).catch(()=>{K&&_("unavailable")}),()=>{K=!1}},[b]),E.useEffect(()=>{var K;o&&((K=l.current)==null||K.close())},[o]);const q=K=>{var N,B,W;o||(t?(N=n.onEdgeIconChange)==null||N.call(n,t,K):e&&((B=n.onNodeIconChange)==null||B.call(n,e,K)),(W=l.current)==null||W.close())},H=g.filter(K=>K.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(C.trim().toLowerCase())),V=36,re=Math.max(1,Math.ceil(H.length/V)),ce=Math.min(T,re-1),le=H.slice(ce*V,(ce+1)*V),be={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${pe(u)}`,borderRadius:30};return h.jsxs(h.Fragment,{children:[h.jsx(je,{label:t?"Choose edge icon":"Choose node icon",children:h.jsx(ve,{"aria-label":t?"Choose edge icon":"Choose node icon",icon:h.jsx(Z.PiShapes,{size:20}),size:"sm",variant:"ghost",color:pe(i),disabled:o,onClick:()=>{var K;I(""),x(r&&kt(r)?"custom":"icons"),P(r&&!r.startsWith(dn)&&kt(r)?r:""),y(!0),(K=l.current)==null||K.showModal()}})}),h.jsx("dialog",{ref:l,"aria-label":t?"Choose edge icon":"Choose node icon",onClose:()=>{y(!1),p.current++,M(!1)},onClick:K=>{K.stopPropagation(),K.target===K.currentTarget&&K.currentTarget.close()},onKeyDown:K=>K.stopPropagation(),style:{margin:"auto",padding:12,width:336,maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",border:`1px solid ${pe(u)}`,borderRadius:30,boxShadow:`0 0 0 8px color-mix(in srgb, ${pe(a)} 60%, transparent)`,background:pe(a),color:pe(c)},children:b&&h.jsxs("div",{style:{display:"grid",gap:8},children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[h.jsx("strong",{children:t?"Edge icon":"Node icon"}),h.jsxs("div",{style:{display:"flex",alignItems:"center",marginLeft:"auto",gap:4},children:[r&&h.jsx(je,{label:"Remove icon",children:h.jsx(ve,{"aria-label":t?"Remove edge icon":"Remove node icon",icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:o||O,onClick:()=>q("")})}),h.jsx(ht,{"aria-label":"Close icon picker",onClick:()=>{var K;return(K=l.current)==null?void 0:K.close()}})]})]}),h.jsx("div",{role:"tablist","aria-label":"Icon source",style:{display:"flex",borderBottom:`1px solid ${pe(u)}`},children:["icons","custom"].map(K=>h.jsx("button",{id:`${d}-${K}`,type:"button",role:"tab","aria-selected":m===K,"aria-controls":`${d}-panel`,tabIndex:m===K?0:-1,onClick:()=>{x(K),I("")},onKeyDown:N=>{var W;if(!["ArrowLeft","ArrowRight","Home","End"].includes(N.key))return;N.preventDefault();const B=N.key==="Home"?"icons":N.key==="End"||K==="icons"?"custom":"icons";x(B),I(""),(W=document.getElementById(`${d}-${B}`))==null||W.focus()},style:{flex:1,padding:"8px 12px",background:"transparent",border:0,borderBottom:`2px solid ${m===K?pe(i):"transparent"}`,color:m===K?pe(i):"inherit",cursor:"pointer",fontSize:13},children:K==="icons"?"React icons":"Custom SVG"},K))}),h.jsx("input",{ref:f,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:O||o,onChange:async K=>{var W;const N=(W=K.target.files)==null?void 0:W[0];if(K.target.value="",!N)return;const B=++p.current;M(!0),I("");try{const z=await n0(N);B===p.current&&q(z)}catch(z){B===p.current&&I(z instanceof Error?z.message:"Unable to read SVG.")}finally{B===p.current&&M(!1)}}}),h.jsx("div",{id:`${d}-panel`,role:"tabpanel","aria-labelledby":`${d}-${m}`,style:{display:"grid",gap:8},children:m==="icons"?h.jsxs(h.Fragment,{children:[h.jsx("input",{"aria-label":"Search icons",placeholder:"Search icons...",value:C,onChange:K=>{S(K.target.value),k(0)},style:be}),h.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[le.map(K=>h.jsx("button",{type:"button","aria-label":`Choose ${K}`,"aria-pressed":r===K,title:K,onClick:()=>q(K),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${r===K?2:1}px solid ${pe(r===K?i:u)}`,background:pe(r===K?a:s),color:"inherit",cursor:"pointer"},children:h.jsx(Mr,{name:K,size:24})},K)),le.length===0&&h.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:v==="loading"?"Loading icons...":v==="unavailable"?"React icons unavailable":"No icons found"})]}),h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[h.jsxs("span",{role:"status",style:{fontSize:12},children:[H.length," icons · ",ce+1," / ",re]}),h.jsxs("div",{style:{display:"flex",gap:4},children:[h.jsx(je,{label:"Previous icons",children:h.jsx(ve,{"aria-label":"Previous icons",icon:h.jsx(Z.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:ce===0,onClick:()=>k(ce-1)})}),h.jsx(je,{label:"Next icons",children:h.jsx(ve,{"aria-label":"Next icons",icon:h.jsx(Z.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:ce+1>=re,onClick:()=>k(ce+1)})})]})]})]}):h.jsxs(h.Fragment,{children:[r&&kt(r)&&h.jsx(Mr,{name:r,size:64}),h.jsxs("button",{type:"button",disabled:O||o,onClick:()=>{var K;return(K=f.current)==null?void 0:K.click()},style:{...be,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[h.jsx(Z.PiUploadSimple,{}),O?"Uploading...":"Upload SVG"]}),h.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:K=>{K.preventDefault(),!(O||o)&&(!kt(j.trim())||j.trim().startsWith(dn)?I("Enter an HTTP or HTTPS image URL."):q(j.trim()))},children:[h.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:j,disabled:O||o,onChange:K=>P(K.target.value),style:{...be,flex:1,minWidth:0}}),h.jsx(je,{label:"Apply URL",children:h.jsx(ve,{type:"submit","aria-label":"Apply URL",icon:h.jsx(Z.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:O||o||!j.trim(),style:{flexShrink:0}})})]})]})}),R&&h.jsx("div",{role:"alert",style:{fontSize:13},children:R})]})})]})}const Nu=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500"],ob=["gray.900","gray.600","gray.200","white"];function ib(){const{config:e}=Ie(),t=e.selectionToolbar||{},r=new Set(t.hide||[]);return{palette:t.palette||Nu,show:n=>!r.has(n)}}function cr(){const{border:e}=Ve();return h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:e})}function Xr({value:e,placeholder:t,ariaLabel:r,width:n="140px",type:o="text",min:i,onCommit:a}){const{colorText:s}=Ve(),[u,c]=E.useState(e),l=E.useRef(!1);E.useEffect(()=>c(e),[e]);const d=()=>{if(l.current)return;l.current=!0;const f=u.trim();if(o==="number"&&f!==""&&(!Number.isFinite(Number(f))||Number(f)<(i??0))){c(e);return}f!==e&&a(f)};return h.jsx(F.Input,{"aria-label":r,type:o,min:i,size:"xs",w:n,value:u,placeholder:t,color:s,borderWidth:0,_focusVisible:{boxShadow:"none",outline:"none"},borderRadius:"8px",onFocus:()=>{l.current=!1},onChange:f=>c(f.target.value),onBlur:d,onKeyDown:f=>{f.key==="Enter"&&(d(),f.target.blur()),f.key==="Escape"&&(l.current=!0,c(e),f.target.blur())}})}function Ht({colors:e,value:t,label:r,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:a,colorText:s}=Ve(),[u,c]=E.useState(!1),l=E.useId(),d=E.useRef(null),f=t??e[0]??"transparent";return h.jsxs(F.HStack,{gap:1,"aria-label":r,role:"group",onKeyDown:p=>{var b;p.key==="Escape"&&(c(!1),(b=d.current)==null||b.focus())},children:[h.jsx(je,{label:`${r}: ${f}`,children:h.jsx(F.chakra.button,{ref:d,type:"button","aria-label":`${r} colors`,"aria-expanded":u,"aria-controls":l,w:4,h:4,flexShrink:0,borderRadius:"full",cursor:"pointer",style:{backgroundColor:pe(f),...f==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${pe(s)}`,outlineOffset:"1px",onClick:()=>c(p=>!p)})}),u&&h.jsxs(F.HStack,{id:l,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(p=>{const b=t===p;return h.jsx(je,{label:`${r}: ${p}`,children:h.jsx(F.Box,{as:"button","aria-label":`${r} ${p}`,"aria-pressed":b,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:pe(p),...p==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:b?`2px solid ${pe(s)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>{var y;n(p),c(!1),(y=d.current)==null||y.focus()}})},p)}),o&&h.jsx(je,{label:`Reset ${r.toLowerCase()}`,children:h.jsx(ve,{"aria-label":`Reset ${r}`,icon:h.jsx(F.Icon,{as:Z.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:a,onClick:()=>{var p;o(),c(!1),(p=d.current)==null||p.focus()}})})]})]})}function ab({edgeId:e,onClose:t}){var p;const{callbacks:r,themeColor:n,config:o}=Ie(),{colorInactive:i}=Ve(),{edgeById:a}=Wr(),{palette:s,show:u}=ib(),c=(p=a.get(e))==null?void 0:p.data,l=[...new Set(["rounded-orthogonal","orthogonal","straight","bezier",...Object.keys(o.customEdgeTypes??{}),...c!=null&&c.type?[c.type]:[]])],d=c!=null&&c.isEdgeAnimated?"animated":c!=null&&c.isEdgeDashed?"dashed":"solid",f=[{key:"solid",icon:Z.PiLineSegment,label:"Solid"},{key:"dashed",icon:Z.PiLineSegments,label:"Dashed"},{key:"animated",icon:Z.PiFastForward,label:"Animated"}];return h.jsxs(h.Fragment,{children:[h.jsx(ht,{onClick:t}),u("label")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(Xr,{ariaLabel:"Edge label",placeholder:"Edge label",value:(c==null?void 0:c.label)||"",onCommit:b=>{var y;return(y=r.onEdgeLabelChange)==null?void 0:y.call(r,e,b)}})]}),u("style")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),f.map(b=>h.jsx(je,{label:b.label,children:h.jsx(ve,{"aria-label":`Edge style ${b.key}`,"aria-pressed":d===b.key,icon:h.jsx(F.Icon,{as:b.icon,boxSize:5}),size:"sm",variant:"ghost",color:d===b.key?n:i,onClick:()=>{var y;return(y=r.onEdgeStyleChange)==null?void 0:y.call(r,e,b.key)}})},b.key)),d==="animated"&&h.jsx(nb,{label:"Edge animation",value:(c==null?void 0:c.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:o.readOnly,onChange:b=>{var y;return(y=r.onEdgeAnimationVariantChange)==null?void 0:y.call(r,e,b)}}),h.jsxs(Or,{"aria-label":"Edge shape",title:`Edge shape: ${(c==null?void 0:c.type)??"Default"}`,icon:h.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:(c==null?void 0:c.type)??"",disabled:o.readOnly,onValueChange:b=>{var y;return(y=r.onEdgeTypeChange)==null?void 0:y.call(r,e,b||void 0)},children:[h.jsx("option",{value:"",children:"Default"}),l.map(b=>h.jsx("option",{value:b,children:b},b))]})]}),u("icon")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(qu,{edgeId:e,value:c==null?void 0:c.icon},e),h.jsx(Xr,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(c==null?void 0:c.icon)??"",onCommit:b=>{var y;return(y=r.onEdgeIconChange)==null?void 0:y.call(r,e,b)}})]}),u("color")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(Ht,{label:"Edge color",colors:s,value:c==null?void 0:c.color,onPick:b=>{var y;return(y=r.onEdgeColorChange)==null?void 0:y.call(r,e,b)},onReset:()=>{var b;return(b=r.onEdgeColorChange)==null?void 0:b.call(r,e,"")}})]}),u("delete")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(je,{label:"Delete edge",children:h.jsx(ve,{"aria-label":"Delete edge",icon:h.jsx(F.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var b;(b=r.onEdgeDelete)==null||b.call(r,e,c),t()}})})]})]})}function sb({ids:e,showDivider:t=!0}){const{callbacks:r,config:n}=Ie(),{colorInactive:o}=Ve(),{nodeById:i}=Wr(),[a,s]=E.useState(!1),u=e.map(b=>{var y,m;return(m=(y=i.get(b))==null?void 0:y.data.viewProps)==null?void 0:m.borderRadius}),c=!u.every(b=>b===u[0]),l=c?"mixed":String(u[0]??""),d=["0","8","16","30","53","100"],f=a||!c&&l!==""&&!d.includes(l),p=b=>e.forEach(y=>{var m;return(m=r.onNodeBorderRadiusChange)==null?void 0:m.call(r,y,b)});return h.jsxs(h.Fragment,{children:[t&&h.jsx(cr,{}),h.jsx(F.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:h.jsxs(Or,{icon:h.jsx(F.Icon,{as:ev.TbBorderRadius,boxSize:5,color:o,"aria-hidden":"true"}),"aria-label":"Node border radius",title:`Border radius: ${c?"Mixed":u[0]===void 0?"Default":`${u[0]}px`}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",cursor:"pointer"},value:f?"custom":l,disabled:n.readOnly,onValueChange:b=>{s(b==="custom"),b!=="custom"&&p(b===""?void 0:Number(b))},children:[h.jsx("option",{value:"",children:"Default radius"}),c&&h.jsx("option",{value:"mixed",disabled:!0,children:"Mixed radii"}),d.map(b=>h.jsxs("option",{value:b,children:[b,"px radius"]},b)),h.jsx("option",{value:"custom",children:"Custom radius"})]})}),f&&h.jsx(Xr,{ariaLabel:"Custom border radius",placeholder:c?"Mixed":"Auto",type:"number",min:0,width:"72px",value:c?"":l,onCommit:b=>p(b===""?void 0:Number(b))})]})}function cb({ids:e,onClose:t}){var K,N,B,W,z,X,se,Q;const{callbacks:r,colorMode:n,themeColor:o,config:i,setNodeViewMode:a}=Ie(),{colorText:s,colorInactive:u}=Ve(),{nodeById:c,parentIds:l}=Wr(),{palette:d,show:f}=ib(),p=e.length===1,b=p?(K=c.get(e[0]))==null?void 0:K.data:void 0,y=e.map(G=>{var J,te;return((te=(J=c.get(G))==null?void 0:J.data.config)==null?void 0:te.typeView)??""}),m=y.some(G=>G!==y[0]),x=m?"mixed":y[0]??"",g=e.some(G=>{var te,de;const J=(te=c.get(G))==null?void 0:te.data;return J&&(l.has(G)||((de=J.config)==null?void 0:de.parentContainer)||Object.prototype.hasOwnProperty.call(i.customViews??{},J.type))}),w=(N=b==null?void 0:b.config)==null?void 0:N.collapsed,v=tb(e[0]),_=G=>{var J,te,de;return(((te=(J=c.get(G))==null?void 0:J.data.viewProps)==null?void 0:te.outline)??(l.has(G)?(de=i.parentNodeStyle)==null?void 0:de.outline:!1))===!0},C=e.every(_),S=!C&&e.some(_),T=G=>{var J;return((J=c.get(G))==null?void 0:J.data.isNodeAnimated)===!0},k=e.every(T),j=!k&&e.some(T),P=e.map(G=>{var J;return((J=c.get(G))==null?void 0:J.data.nodeAnimationVariant)??"traveling"}),R=P.every(G=>G===P[0])?P[0]:"",I=G=>e.forEach(G),[O,M]=E.useState(!1),q=O&&f("color")&&f("borderColor"),H=G=>{var J,te,de;return(((te=(J=c.get(G))==null?void 0:J.data.viewProps)==null?void 0:te.borderStyle)??(l.has(G)?(de=i.parentNodeStyle)==null?void 0:de.borderStyle:"solid"))==="dashed"},V=e.every(H),re=!V&&e.some(H),ce=e.map(G=>{var de,fe,Ee;const J=(de=c.get(G))==null?void 0:de.data,te=l.has(G)?Ut((fe=i.parentNodeStyle)==null?void 0:fe.borderWidth,6):(J==null?void 0:J.type)==="objectView"?3:2;return Ut((Ee=J==null?void 0:J.viewProps)==null?void 0:Ee.borderWidth,te)}),le=ce.every(G=>G===ce[0])?String(ce[0]??""):"",be=G=>I(J=>{var te,de;q?(te=r.onNodeBorderColorChange)==null||te.call(r,J,G):(de=r.onNodeColorChange)==null||de.call(r,J,"bg",G)});return h.jsxs(h.Fragment,{children:[h.jsx(ht,{onClick:t}),h.jsx(cr,{}),p&&f("label")?h.jsx(Xr,{ariaLabel:"Node label",placeholder:"Node label",value:(b==null?void 0:b.label)??(b==null?void 0:b.headerTitle)??"",onCommit:G=>{var J;return(J=r.onNodeLabelChange)==null?void 0:J.call(r,e[0],G)}}):h.jsxs(F.Text,{fontSize:"xs",color:s,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),f("typeView")&&h.jsxs(Or,{"aria-label":"Type view",title:g?"Type view is managed by the custom renderer or container":`Type view: ${x||"None (default)"}`,icon:h.jsx(Z.PiImage,{size:20}),style:{width:36},value:x,disabled:i.readOnly||i.editable===!1||g,onValueChange:G=>{Ft.includes(G)&&I(J=>{var te,de;(te=r.onNodeTypeViewChange)==null||te.call(r,J,G||void 0),a(J,"default"),(de=r.onNodeViewToggle)==null||de.call(r,J)})},children:[m&&h.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),Ft.map(G=>h.jsx("option",{value:G,children:G||"None"},G))]}),f("style")&&h.jsx(sb,{ids:e},e.join("\0")),f("outline")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(je,{label:C?"Restore node fill":"Remove node fill",children:h.jsx(ve,{"aria-label":"Toggle node outline","aria-pressed":S?"mixed":C,icon:h.jsx(F.Icon,{as:C?Z.PiSquare:Z.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:C?o:u,onClick:()=>I(G=>{var J;return(J=r.onNodeOutlineChange)==null?void 0:J.call(r,G,!C)})})})]}),f("color")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),f("borderColor")&&h.jsx(je,{label:q?"Edit node colors":"Edit node border",children:h.jsx(ve,{"aria-label":"Edit node border","aria-pressed":q,icon:h.jsx(F.Icon,{as:Z.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:q?o:u,bg:q?n==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>M(G=>!G)})}),h.jsx(Ht,{label:q?"Border color":"Background",colors:d,value:q?((B=b==null?void 0:b.viewProps)==null?void 0:B.borderColor)??(p&&l.has(e[0])?(W=i.parentNodeStyle)==null?void 0:W.borderColor:void 0):(z=b==null?void 0:b.viewProps)==null?void 0:z.bgColor,onPick:be,onReset:()=>be("")}),q&&f("style")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(je,{label:V?"Solid border":"Dashed border",children:h.jsx(ve,{"aria-label":"Toggle dashed border","aria-pressed":re?"mixed":V,icon:h.jsx(F.Icon,{as:V?Z.PiLineSegments:Z.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:V?o:u,onClick:()=>I(G=>{var J;return(J=r.onNodeBorderStyleChange)==null?void 0:J.call(r,G,V?"solid":"dashed")})})}),h.jsx(Xr,{ariaLabel:"Border thickness",placeholder:p?"Auto":"Mixed",width:"64px",type:"number",min:0,value:le,onCommit:G=>I(J=>{var te;return(te=r.onNodeBorderWidthChange)==null?void 0:te.call(r,J,G===""?void 0:Number(G))})})]})]}),f("animation")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(je,{label:k?"Stop border animation":"Animate node border",children:h.jsx(ve,{"aria-label":"Toggle node animation","aria-pressed":j?"mixed":k,icon:h.jsx(F.Icon,{as:Z.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:k?o:u,onClick:()=>I(G=>{var J;return(J=r.onNodeAnimationChange)==null?void 0:J.call(r,G,!k)})})}),(k||j)&&h.jsx(nb,{label:"Node animation",value:R,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:i.readOnly,onChange:G=>I(J=>{var te;return(te=r.onNodeAnimationVariantChange)==null?void 0:te.call(r,J,G)})})]}),!q&&f("textColor")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(Ht,{label:"Text color",colors:ob,value:(X=b==null?void 0:b.viewProps)==null?void 0:X.textColor,onPick:G=>I(J=>{var te;return(te=r.onNodeColorChange)==null?void 0:te.call(r,J,"text",G)}),onReset:()=>I(G=>{var J;return(J=r.onNodeColorChange)==null?void 0:J.call(r,G,"text","")})})]}),p&&f("icon")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(qu,{nodeId:e[0],value:(se=b==null?void 0:b.config)==null?void 0:se.icon},e[0]),h.jsx(Xr,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((Q=b==null?void 0:b.config)==null?void 0:Q.icon)||"",onCommit:G=>{var J;return(J=r.onNodeIconChange)==null?void 0:J.call(r,e[0],G)}})]}),p&&v&&f("collapse")&&w!==void 0&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(je,{label:w?"Expand":"Collapse",children:h.jsx(ve,{"aria-label":w?"Expand node":"Collapse node",icon:h.jsx(F.Icon,{as:w?Z.PiArrowsOutLineVertical:Z.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:u,onClick:()=>{var G;return(G=r.onNodeCollapse)==null?void 0:G.call(r,e[0],!w)}})})]}),f("delete")&&h.jsxs(h.Fragment,{children:[h.jsx(cr,{}),h.jsx(je,{label:p?"Delete node":`Delete ${e.length} nodes`,children:h.jsx(ve,{"aria-label":"Delete selected nodes",icon:h.jsx(F.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:n==="dark"?"red.300":"red.500",onClick:()=>{I(G=>{var J,te;return(te=r.onNodeDelete)==null?void 0:te.call(r,G,((J=c.get(G))==null?void 0:J.data)||{id:G})}),t()}})})]})]})}async function ub(e){const{toSvg:t}=await Promise.resolve().then(()=>require("./index-sHQXTNv9.cjs"));await document.fonts.ready;const r=await t(e,{filter:o=>!(o instanceof Element)||!o.matches("button, [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(r.slice(r.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()),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(n))}`}async function lb(e,t="squeed.svg"){const r=document.createElement("a");r.href=await ub(e),r.download=t.endsWith(".svg")?t:`${t}.svg`,r.click()}function db(){const{themeColor:e}=Ie(),[t,r]=E.useState(!1),[n,o]=E.useState("");return h.jsxs(h.Fragment,{children:[h.jsx(je,{label:"Download SVG (current view)",children:h.jsx(ve,{"aria-label":"Download SVG",icon:h.jsx(Z.PiDownloadSimpleFill,{size:20}),disabled:t,borderRadius:"30%",color:e,variant:"ghost",onClick:async i=>{var s;const a=(s=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:s.querySelector("[data-flow-background]");if(!a){o("Diagram not available for export.");return}r(!0),o("");try{await lb(a)}catch(u){o(u instanceof Error?u.message:"Unable to export SVG.")}finally{r(!1)}}})}),n&&h.jsx("span",{role:"alert",style:{fontSize:12,maxWidth:220},children:n})]})}function fb({children:e,background:t,border:r}){const n=E.useRef(null),[o,i]=E.useState({left:!1,right:!1});E.useLayoutEffect(()=>{const s=n.current,u=()=>{const l=s.scrollLeft>1,d=s.scrollWidth-s.clientWidth-s.scrollLeft>1;i(f=>f.left===l&&f.right===d?f:{left:l,right:d})},c=new ResizeObserver(u);return c.observe(s),s.firstElementChild&&c.observe(s.firstElementChild),s.addEventListener("scroll",u,{passive:!0}),u(),()=>{c.disconnect(),s.removeEventListener("scroll",u)}},[]);const a=`var(--chakra-colors-${t.replace(".","-")})`;return h.jsxs(F.Box,{position:"relative",bg:t,minW:0,maxW:"100%",flex:"0 1 auto",borderColor:r,borderWidth:1,borderRadius:"30px",...Su(a),children:[h.jsx(F.Box,{ref:n,"data-flow-toolbar-scroll":"",h:50,minH:50,alignContent:"center",overflowX:"auto",overflowY:"hidden",borderRadius:"inherit",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e}),["left","right"].map(s=>h.jsx(F.Box,{"data-flow-toolbar-fade":s,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",borderRadius:s==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[s]:0,opacity:o[s]?1:0,background:`linear-gradient(to ${s==="left"?"right":"left"}, ${a}, transparent)`}},s))]})}async function o0(e,t){const r=new Set,n=[],o=(s,u)=>{var l,d,f;if(!s||typeof s!="object")return;const c=s;n.push(u),typeof((l=c.$form)==null?void 0:l.$type)=="string"&&r.add(c.$form.$type),typeof((f=(d=c.$form)==null?void 0:d.$create)==null?void 0:f.$type)=="string"&&r.add(c.$form.$create.$type);for(const[p,b]of Object.entries(c))p==="$"?o(b,u):p.startsWith("$")||o(b,`${u}.${p}`)};if(o(t,"root"),!r.size)return{contract:await Xy(e)};const i=await Mu(e,[...r]);for(const s of r)if(!Object.prototype.hasOwnProperty.call(i,s))throw new Error(`Missing form type: ${s}`);const a={};for(const s of n){const u=pt(t,s,i);u&&(a[s]={type:u.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:a}}}function hb({message:e,onDismiss:t}){const{background:r,colorText:n,border:o}=Ve();return!e||typeof document>"u"?null:Lt.createPortal(h.jsxs("div",{role:"alert","aria-atomic":"true",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,border:`1px solid ${pe(o)}`,background:pe(r),color:pe(n),boxShadow:"0 4px 20px #0003",fontSize:14,lineHeight:1.5},children:[h.jsx(Z.PiWarningCircle,{size:20,"aria-hidden":"true",style:{flexShrink:0,color:"#ef4444"}}),h.jsxs("div",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:[h.jsx("strong",{children:"Interface upload failed"}),h.jsx("div",{children:e})]}),h.jsx(ht,{type:"button","aria-label":"Dismiss upload error",title:"Dismiss upload error",onClick:t,flexShrink:0,width:"24px",height:"24px",minWidth:"24px",padding:0})]}),document.body)}function pb({showDivider:e=!0,compact:t=!1}={}){const{edgeMode:r,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:a,readOnly:s,themeColor:u}=Ie(),{edgeById:c}=Wr(),{data:l,schema:d,setSchema:f,bindings:p,structured:b}=E.useContext(kr),y=(b==null?void 0:b.sourceBindings)??p,m=(b==null?void 0:b.sourceSchema)??d,{colorText:x}=Ve(),g=E.useRef(null),w=E.useRef(0),[v,_]=E.useState(!1),[C,S]=E.useState("");E.useEffect(()=>()=>{w.current++},[]),E.useEffect(()=>{w.current++,_(!1)},[s,l,y]);const T=o?[...c.values()].filter(j=>Iu(o,j.data)).length:0,k=o?`${o.name}: ${m?`${Object.keys(m).length} form types loaded; `:""}${T} invalid or unverified connections`:"";return h.jsxs(h.Fragment,{children:[h.jsx(hb,{message:C,onDismiss:()=>S("")}),e&&h.jsx(Ot,{}),h.jsxs(Or,{"aria-label":"Edge mode",title:r==="auto"?"Connections: Auto":r==="properties"?"Connections: Properties":"Connections: Nodes",icon:r==="auto"?h.jsx(Z.PiGraph,{size:20}):r==="properties"?h.jsx(Z.PiTable,{size:20}):h.jsx(Z.PiTreeStructure,{size:20}),style:{width:36},value:r,disabled:s,onValueChange:j=>{var R;const P=j==="auto"?"auto":j==="properties"?"properties":"nodes";n(P),(R=a.onEdgeModeChange)==null||R.call(a,P)},children:[h.jsx("option",{value:"auto",children:"Auto"}),h.jsx("option",{value:"nodes",children:"Nodes"}),h.jsx("option",{value:"properties",children:"Properties"})]}),h.jsxs("span",{style:{display:r==="auto"||r==="properties"?"contents":"none"},children:[h.jsx(je,{label:o?`Replace ${o.name}`:"Upload workflow interface",children:h.jsx(ve,{"aria-label":"Upload workflow interface",icon:h.jsx(Z.PiUploadSimple,{size:20}),color:pe(u),size:"sm",variant:"ghost",disabled:v||s,onClick:()=>{var j;return(j=g.current)==null?void 0:j.click()}})}),h.jsx("input",{ref:g,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:s||v,onChange:async j=>{var I,O;const P=(I=j.target.files)==null?void 0:I[0];if(j.target.value="",!P)return;const R=++w.current;_(!0),S("");try{const M=y?await Mu(P,[...new Set(Object.values(y).map(V=>V.schemaType??V.type))]):void 0;if(y&&M){for(const V of Object.values(y))if(!Object.prototype.hasOwnProperty.call(M,V.schemaType??V.type))throw new Error(`Missing form type: ${V.schemaType??V.type}`)}const{contract:q,schema:H}=y&&M?{schema:M,contract:{name:P.name,nodes:Object.fromEntries(Object.entries(y).map(([V,re])=>[V,{type:M[re.schemaType??re.type],optional:!1}]))}}:await o0(P,l);if(R!==w.current)return;f==null||f(H),i(q),(O=a.onWorkflowContractChange)==null||O.call(a,q)}catch(M){R===w.current&&S(`${P.name}: ${M instanceof Error?M.message:"Unable to load interface."}`)}finally{R===w.current&&_(!1)}}}),!t&&(k||v)&&h.jsx("span",{role:"status",title:k,style:{color:pe(x),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v?"Loading interface...":k}),!t&&o&&h.jsx(je,{label:"Remove workflow interface",children:h.jsx(ve,{"aria-label":"Remove workflow interface",icon:h.jsx(Z.PiX,{size:16}),size:"sm",variant:"ghost",disabled:s||v,onClick:()=>{var j;f==null||f(void 0),i(void 0),(j=a.onWorkflowContractChange)==null||j.call(a,void 0),S("")}})})]})]})}const i0=[{value:"BT",label:"Bottom to Up",icon:Z.PiArrowUp,flowType:St.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:Z.PiArrowDown,flowType:St.TOP_DOWN},{value:"LR",label:"Left to Right",icon:Z.PiArrowRight,flowType:St.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:Z.PiArrowLeft,flowType:St.RIGHT_LEFT}],gb=()=>{const{engineRef:e,themeColor:t,setThemeColor:r,backgroundSelected:n,setBackgroundSelected:o,direction:i,edgeMode:a,selectedNodeIds:s,setSelectedNodeIds:u,selectedEdgeId:c,setSelectedEdgeId:l,isZoomMode:d,setIsZoomMode:f,isMultiSelectMode:p,setIsMultiSelectMode:b,isDragMode:y,setIsDragMode:m,isEdgeHandlesEnabled:x,setIsEdgeHandlesEnabled:g,isArrayNodeMode:w,setIsArrayNodeMode:v,isPinned:_,setIsPinned:C,callbacks:S,config:T,readOnly:k}=Ie(),{nodeById:j,edgeById:P,parentIds:R}=Wr(),I=T.colorMode==="dark",{background:O,border:M,colorInactive:q,colorText:H,colorActive:V,darkBackgroundSecondary:re}=Ve(),[ce,le]=E.useState(!1),[be,K]=E.useState(!0),N=E.useCallback(me=>{const Te=e.current;if(!Te)return;const er=T.minZoom??.01,De=T.maxZoom??1.5,Ne=.02;let He=Te.zoom();switch(me){case"increase":He=Math.min(De,He+Ne),Te.zoom(He),Te.center();break;case"decrease":He=Math.max(er,He-Ne),Te.zoom(He),Te.center();break;case"reset":Te.fit(50);break}},[e,T.minZoom,T.maxZoom]),B=T.renderSelectedNodeToolbar,W=s.length>0&&!!B,z=E.useMemo(()=>W?s.map(me=>{var er;return{...((er=j.get(me))==null?void 0:er.data)??{id:me},isParent:R.has(me)}}):[],[W,s,j,R]),X=E.useCallback(()=>{var me;u([]),(me=S.onNodeDeselect)==null||me.call(S)},[u,S]),se=T.renderSelectedEdgeToolbar,Q=!!c&&!!se,G=E.useMemo(()=>{var me;return!Q||!c?null:((me=P.get(c))==null?void 0:me.data)??{id:c}},[Q,c,P]),J=E.useCallback(()=>{var me;l(null),(me=S.onEdgeDeselect)==null||me.call(S)},[l,S]),te=T.selectionToolbar!==!1&&!k,de=te&&!!c&&!se,fe=te&&!de&&s.length>0&&!B,Ee=de||fe,ge=_||ce||Ee;E.useEffect(()=>{s.length||c?o(!1):n&&!k&&(C(!0),K(!1))},[n,s.length,c,k,o,C]);const We=T.renderBottomBar;return We?h.jsxs(h.Fragment,{children:[W&&h.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:B({selectedNodeIds:s,selectedNodeData:z,onDeselect:X})}),Q&&G&&h.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:se({edgeId:c,edgeData:G,onDeselect:J})}),h.jsx(F.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:We({zoomIn:()=>N("increase"),zoomOut:()=>N("decrease"),resetZoom:()=>N("reset"),direction:i,isZoomMode:d,setIsZoomMode:f,isMultiSelectMode:p,setIsMultiSelectMode:b,isDragMode:y,setIsDragMode:m,isEdgeHandlesEnabled:x,setIsEdgeHandlesEnabled:g,isArrayNodeMode:w,setIsArrayNodeMode:v,selectedNodeIds:s,selectedNodeData:z,selectedEdgeId:c,selectedEdgeData:G,onNodeDeselect:X,onEdgeDeselect:J,callbacks:S})})]}):h.jsxs(h.Fragment,{children:[W&&h.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:B({selectedNodeIds:s,selectedNodeData:z,onDeselect:X})}),Q&&G&&h.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:se({edgeId:c,edgeData:G,onDeselect:J})}),!_&&h.jsx(F.Box,{position:"absolute",bottom:5,left:0,zIndex:101,w:3,children:h.jsx(je,{label:"Show Bottom Bar",children:h.jsx(F.chakra.button,{type:"button","aria-label":"Show Bottom Bar",display:"flex",alignItems:"center",bg:O,borderColor:M,borderWidth:1,py:6,px:0,w:4,h:50,borderRadius:"15px",borderLeftRadius:0,onMouseEnter:()=>C(!0),onClick:()=>C(!0),_hover:{bg:re},children:h.jsx(F.Icon,{ml:-1,as:Z.PiLineVerticalBold,boxSize:5,color:M})})})}),h.jsx(F.Box,{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:ge?"translateY(0)":"translateY(100%)",pointerEvents:ge?"auto":"none",visibility:ge?"visible":"hidden",opacity:ge?1:0,children:h.jsxs(F.Flex,{w:"100%",px:5,position:"absolute",bottom:5,flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:"24px",children:[h.jsx(fb,{background:O,border:I?M:"gray.300",children:h.jsxs(F.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[de?h.jsx(ab,{edgeId:c,onClose:J}):fe?h.jsx(cb,{ids:s,onClose:X}):null,h.jsxs("div",{style:{display:de||fe?"none":"contents"},children:[h.jsx(je,{label:_?"Unpin":"Pin",children:h.jsx(ve,{"aria-label":"Pin",icon:h.jsx(F.Icon,{as:_?Z.PiPushPinFill:Z.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:_?t:q,onClick:()=>{C(!_),le(!1)}})}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:"Zoom Out",children:h.jsx(ve,{"aria-label":"Zoom out",icon:h.jsx(F.Icon,{as:Z.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:H,onClick:()=>N("decrease")})}),h.jsx(je,{label:"Zoom In",children:h.jsx(ve,{"aria-label":"Zoom in",icon:h.jsx(F.Icon,{as:Z.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:H,onClick:()=>N("increase")})}),h.jsx(je,{label:"Reset Zoom",children:h.jsx(ve,{"aria-label":"Reset zoom",icon:h.jsx(F.Icon,{as:Z.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:H,onClick:()=>N("reset")})}),!be&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:d?"Zoom Mode (z)":"Pan Mode (z)",children:h.jsx(ve,{"aria-label":"Toggle zoom mode",icon:h.jsx(F.Icon,{as:d?Z.PiMagnifyingGlassPlus:Z.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:d?t:q,onClick:()=>f(!d)})}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:p?"Multi-Select On (m)":"Multi-Select Off (m)",children:h.jsx(ve,{"aria-label":"Toggle multi-select",icon:h.jsx(F.Icon,{as:Z.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:p?t:q,onClick:()=>b(!p)})}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:y?"Drag Mode On (d)":"Drag Mode Off (d)",children:h.jsx(ve,{"aria-label":"Toggle drag mode",icon:h.jsx(F.Icon,{as:Z.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:y?t:q,onClick:()=>m(!y)})}),T.edgeHandles!==!1&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:x?"Draw Mode On":"Draw Mode Off",children:h.jsx(ve,{"aria-label":"Toggle draw mode",icon:h.jsx(F.Icon,{as:Z.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:x?t:q,onClick:()=>g(!x)})})]}),T.bottomBarExtra&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M,role:"separator","aria-orientation":"vertical"}),T.bottomBarExtra]}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M,role:"separator","aria-orientation":"vertical"}),h.jsx(Dy,{}),a!=="properties"&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:w?"Array Mode [ ]":"Set Mode { }",children:h.jsx(ve,{"aria-label":"Toggle array mode",icon:h.jsx(F.Icon,{as:w?Z.PiBracketsSquare:Z.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:w?t:q,onClick:()=>{var Te;const me=!w;v(me),(Te=S.onArrayModeChange)==null||Te.call(S,me)}})})]}),n&&!k&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(Ht,{label:"Graph theme",colors:Nu,value:t,includeTransparent:!1,onPick:me=>{var Te;r(me),(Te=S.onThemeColorChange)==null||Te.call(S,me)}})]}),h.jsx(pb,{}),h.jsx(Fy,{})]}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:be?"Expand toolbar":"Collapse toolbar",children:h.jsx(ve,{"aria-label":"Toggle toolbar collapse",icon:h.jsx(F.Icon,{as:be?Z.PiCaretRight:Z.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:q,onClick:()=>K(!be)})}),!be&&h.jsx(db,{})]})]})}),!Ee&&h.jsxs(F.Box,{position:"relative",ml:"auto",flexShrink:0,children:[h.jsx(F.Box,{"data-flow-direction-control":"",bg:O,borderWidth:1,borderColor:I?M:"gray.300",borderRadius:"30px",h:50,...Su(`var(--chakra-colors-${O.replace(".","-")})`),px:3,cursor:"pointer",onClick:()=>le(!ce),children:h.jsxs(F.Flex,{align:"center",h:"100%",children:[h.jsx(je,{label:"Flow Direction",children:h.jsx(ve,{"aria-label":"Direction",icon:h.jsx(F.Icon,{as:Z.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:q})}),h.jsx(F.Text,{fontSize:"xs",color:I?"whiteAlpha.600":"blackAlpha.500",ml:1,children:i})]})}),ce&&h.jsx(F.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:h.jsxs(F.Box,{bg:O,borderWidth:1,borderColor:I?M:"gray.300",borderRadius:"30px",p:2,minW:"180px",boxShadow:`0 0 0 8px color-mix(in srgb, var(--chakra-colors-${O.replace(".","-")}) 40%, transparent), var(--chakra-shadows-lg)`,children:[i0.map(me=>h.jsxs(F.Flex,{align:"center",gap:3,px:3,py:2,borderRadius:"30px",cursor:"pointer",_hover:{bg:I?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Te;(Te=S.onDirectionChange)==null||Te.call(S,me.value),le(!1)},children:[h.jsx(F.Icon,{as:me.icon,boxSize:5,color:H}),h.jsx(F.Text,{fontSize:"sm",color:H,flex:1,whiteSpace:"nowrap",children:me.label}),i===me.value&&h.jsx(F.Icon,{as:Z.PiCheck,boxSize:4,color:V})]},me.value)),h.jsxs(F.Flex,{align:"center",gap:3,px:3,py:2,borderRadius:"10px",cursor:"pointer",_hover:{bg:I?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var me;(me=S.onDirectionChange)==null||me.call(S,"C"),le(!1)},children:[h.jsx(F.Icon,{as:Z.PiAlignCenterHorizontal,boxSize:5,color:H}),h.jsx(F.Text,{fontSize:"sm",color:H,flex:1,whiteSpace:"nowrap",children:"Center"}),i==="C"&&h.jsx(F.Icon,{as:Z.PiCheck,boxSize:4,color:V})]})]})})]})]})})]})};gb.displayName="BottomBar";const yb=E.memo(gb);function a0({checked:e,onChange:t,disabled:r,label:n="Connected nodes"}){return h.jsx(By,{label:n,checked:e,onChange:t,disabled:r,icon:h.jsx(F.Icon,{as:Z.PiGraph,boxSize:5})})}const kl={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function bb(e,t){const r=new Map,n=(i,a)=>{if(Object.is(i,a))return!0;if(!i||!a||typeof i!="object"||typeof a!="object"||Array.isArray(i)!==Array.isArray(a))return!1;const s=Object.keys(i);return s.length===Object.keys(a).length&&s.every(u=>Object.prototype.hasOwnProperty.call(a,u)&&n(i[u],a[u]))},o=(i,a,s)=>{if(i===a)return!0;if(!i||!a||typeof i!="object"||typeof a!="object"||Array.isArray(i)!==Array.isArray(a))return!1;const u=new Set([...Object.keys(i),...Object.keys(a)]);for(const c of u)if(!n(i[c],a[c])){if(Object.prototype.hasOwnProperty.call(kl,c)){if(typeof a[c]!="string"||!a[c])return!1;r.set(s,{...r.get(s),[kl[c]]:a[c]})}else if(c.startsWith("$")&&c!=="$"||!o(i[c],a[c],c==="$"?s:`${s}.${c}`))return!1}return!0};if(o(e,t,"root"))return r}function s0(e,t){return bb(e,t)!==void 0}function c0(e,t,r){if(e===t)return r;const n=bb(e,t);if(!n)return;const o=new Set(r.nodes.map(i=>i.data.id));for(const i of n.keys())if(!o.has(i)||!xe(t,i))return;return{edges:r.edges,nodes:r.nodes.map(i=>{const a=n.get(i.data.id),s=xe(e,i.data.id),u=xe(t,i.data.id);return!a&&s===u?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(u,null,2)}:{},...a?{viewProps:{...i.data.viewProps,...a},config:{...i.data.config,...a}}:{}}}})}}function vu(e){return e.kind==="literal"?e.value:e.kind==="union"?vu(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,t])=>!t.optional).map(([t,r])=>[t,vu(r.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function mb(e,t,r){var m,x,g;const n=(m=xe(e,t))==null?void 0:m.$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(!r||!Object.prototype.hasOwnProperty.call(r,o.$type))throw new Error(`Load form type: ${o.$type}`);const a=i.pop(),s=["root",...i].join("."),u=pt(e,s,r),c=(x=u==null?void 0:u.type.properties[a])==null?void 0:x.type;if((c==null?void 0:c.kind)!=="array"||c.items.kind!=="object")throw new Error("Form creation must target an object-array field.");const l=r[o.$type],d=o.$defaults??{};for(const[w,v]of Object.entries(d))if(!Object.prototype.hasOwnProperty.call(l.properties,w)||Rr(l.properties[w].type,v,!l.properties[w].optional))throw new Error(`Invalid creation default: ${w}`);const f={...vu(l),...structuredClone(d)};((g=l.properties.id)==null?void 0:g.type.kind)==="string"&&(f.id=Eu());let p=e;const b=xe(e,o.$address);if(b===void 0)p=hr(e,s,w=>({...w,[a]:[]}));else if(!Array.isArray(b)&&!Array.isArray(b==null?void 0:b.$))throw new Error("Form creation destination is not an array.");const y=Pu(p,o.$address,{...f,$label:o.$label??o.$type,...o.$icon?{$icon:o.$icon}:{},$form:{$type:o.$type,$create:o}});return{address:y.address,json:Au(y.json,t,{target:y.address,label:o.$edgeLabel})}}function u0(e,t){const r=o=>e&&typeof e=="object"&&o in e;let n=1;for(;r(`${t}_${n}`);)n++;return`${t}_${n}`}function vb(e,t,r,n,o){const i=(s,u)=>{s!==e&&(e=s,n==null||n(s,u))},a=s=>{var c;const u=(c=t.find(l=>l.data.id===s))==null?void 0:c.data;return u&&{source:u.source,target:u.target,isInverted:u.isInverted,sourceProperty:u.sourceProperty,targetProperty:u.targetProperty,connection:u.connection}};return{...r,onFormChange:s=>{const u=xe(e,s.nodeAddress);if(!u||s.nodeId!==void 0&&u.id!==s.nodeId)throw new Error("This form node has moved. Retry the edit.");i(xn(e,s,r.onFormChange),{type:"form",address:s.address,value:s.value})},onNodeLabelChange:(s,u)=>{var c;(c=r.onNodeLabelChange)==null||c.call(r,s,u),i(ir(e,s,"$label",u),{type:"nodeLabel",address:s,key:"$label",value:u})},onNodeContentChange:(s,u)=>{var c;(c=r.onNodeContentChange)==null||c.call(r,s,u),i(ir(e,s,"$content",u),{type:"nodeContent",address:s,key:"$content",value:u})},onNodeTypeViewChange:(s,u)=>{var c;u!==void 0&&!Ft.includes(u)||((c=r.onNodeTypeViewChange)==null||c.call(r,s,u),i(ir(e,s,"$view",u),{type:"nodeStyle",address:s,key:"$view",value:u}))},onNodeColorChange:(s,u,c)=>{var d;(d=r.onNodeColorChange)==null||d.call(r,s,u,c);const l=u==="bg"?"$bgColor":"$textColor";i(ir(e,s,l,c),{type:"nodeColor",address:s,key:l,value:c})},onNodeBorderColorChange:(s,u)=>{var c;(c=r.onNodeBorderColorChange)==null||c.call(r,s,u),i(ir(e,s,"$borderColor",u),{type:"nodeColor",address:s,key:"$borderColor",value:u})},onNodeBorderStyleChange:(s,u)=>{var c;(c=r.onNodeBorderStyleChange)==null||c.call(r,s,u),i(ir(e,s,"$borderStyle",u),{type:"nodeStyle",address:s,key:"$borderStyle",value:u})},onNodeBorderWidthChange:(s,u)=>{var c;u!==void 0&&(!Number.isFinite(u)||u<0)||((c=r.onNodeBorderWidthChange)==null||c.call(r,s,u),i(ir(e,s,"$borderWidth",u),{type:"nodeStyle",address:s,key:"$borderWidth",value:u}))},onNodeBorderRadiusChange:(s,u)=>{var c;u!==void 0&&(!Number.isFinite(u)||u<0)||((c=r.onNodeBorderRadiusChange)==null||c.call(r,s,u),i(ir(e,s,"$borderRadius",u),{type:"nodeStyle",address:s,key:"$borderRadius",value:u}))},onNodeIconChange:(s,u)=>{var c;(c=r.onNodeIconChange)==null||c.call(r,s,u),i(ir(e,s,"$icon",u),{type:"nodeIcon",address:s,key:"$icon",value:u})},onNodeOutlineChange:(s,u)=>{var c;(c=r.onNodeOutlineChange)==null||c.call(r,s,u),i(ir(e,s,"$outline",u),{type:"nodeOutline",address:s,key:"$outline",value:u})},onNodeAnimationChange:(s,u)=>{var c;(c=r.onNodeAnimationChange)==null||c.call(r,s,u),i(ir(e,s,"$isNodeAnimated",u),{type:"nodeAnimation",address:s,key:"$isNodeAnimated",value:u})},onNodeAnimationVariantChange:(s,u)=>{var c;u!=="traveling"&&u!=="pulse"||((c=r.onNodeAnimationVariantChange)==null||c.call(r,s,u),i(ir(e,s,"$nodeAnimationVariant",u),{type:"nodeAnimation",address:s,key:"$nodeAnimationVariant",value:u}))},onNodeCollapse:(s,u)=>{var c;(c=r.onNodeCollapse)==null||c.call(r,s,u),i(Uy(e,s,u),{type:"nodeCollapse",address:s,key:"$collapsed",value:u})},onNodeCreate:s=>{var p,b;const u=s.sourceNodeId&&mb(e,s.sourceNodeId,o);if(u){(p=r.onNodeCreate)==null||p.call(r,s),i(u.json,{type:"nodeCreate",address:u.address,value:"form"});return}(b=r.onNodeCreate)==null||b.call(r,s);const c=s.sourceNodeId||"root",l=xe(e,c),d=u0(l,s.isArrayMode?"list":"node"),f=Pu(e,c,s.isArrayMode?[]:{},d);i(f.json,{type:"nodeCreate",address:f.address,value:s.isArrayMode?"array":"set"})},onNodeDelete:(s,u)=>{var c;(c=r.onNodeDelete)==null||c.call(r,s,u),i(Ky(e,s),{type:"nodeDelete",address:s})},onEdgeCreate:(s,u,c)=>{var d;(d=r.onEdgeCreate)==null||d.call(r,s,u,c);const l=c&&(c.sourceProperty!==void 0||c.targetProperty!==void 0)?{...c,target:u}:void 0;i(l?Au(e,s,l):Zy(e,s,u),{type:"edgeCreate",address:s,key:l?"$connections":"$target",value:l??u})},onEdgeLabelChange:(s,u)=>{var l;(l=r.onEdgeLabelChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$sourceLabel",u),{type:"edgeLabel",edge:c,key:c.connection?"$connections":"$sourceLabel",value:u})},onEdgeStyleChange:(s,u)=>{var l;(l=r.onEdgeStyleChange)==null||l.call(r,s,u);const c=a(s);c&&i(Hy(e,c,u),{type:"edgeStyle",edge:c,value:u})},onEdgeAnimationVariantChange:(s,u)=>{var l;if(u!=="dashed"&&u!=="traveling")return;(l=r.onEdgeAnimationVariantChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$edgeAnimationVariant",u),{type:"edgeStyle",edge:c,key:c.connection?"$connections":"$edgeAnimationVariant",value:u})},onEdgeTypeChange:(s,u)=>{var l;(l=r.onEdgeTypeChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$edgeType",u),{type:"edgeStyle",edge:c,key:c.connection?"$connections":"$edgeType",value:u})},onEdgeIconChange:(s,u)=>{var l;(l=r.onEdgeIconChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$edgeIcon",u||void 0),{type:"edgeStyle",edge:c,key:c.connection?"$connections":"$edgeIcon",value:u})},onEdgeColorChange:(s,u)=>{var l;(l=r.onEdgeColorChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$edgeColor",u),{type:"edgeColor",edge:c,key:c.connection?"$connections":"$edgeColor",value:u})},onEdgeDelete:(s,u)=>{var d;(d=r.onEdgeDelete)==null||d.call(r,s,u);const c=a(s);if(!c)return;const l=Jy(e,c);l.removed&&i(l.json,{type:"edgeDelete",edge:c,key:c.connection?"$connections":"$target"})}}}const l0=".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 d0({path:e,color:t,width:r,reversed:n}){return h.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:t,strokeWidth:r,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 100"})}const f0=".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 xb({x:e=0,y:t=0,width:r,height:n,radius:o,color:i,strokeWidth:a=8,path:s,variant:u="traveling"}){const c=E.useId(),l=`flow-sdk-node-border-animation${u==="pulse"?" flow-sdk-node-border-pulse":""}`;if(u==="pulse"){const d=s?"path":"rect",f=s?{d:s}:{x:e,y:t,width:Math.max(0,r),height:Math.max(0,n),rx:Math.max(0,Math.min(o,r/2,n/2))},p=a+36,b={x:e-p,y:t-p,width:r+2*p,height:n+2*p};return h.jsxs("g",{"aria-hidden":"true",pointerEvents:"none",children:[h.jsx("defs",{children:h.jsxs("mask",{id:c,maskUnits:"userSpaceOnUse",...b,style:{maskType:"luminance"},children:[h.jsx("rect",{...b,fill:"white"}),h.jsx(d,{...f,fill:"black",stroke:"black",strokeWidth:a,strokeLinejoin:"round"})]})}),h.jsx(d,{...f,className:l,"data-animation-variant":u,fill:"none",stroke:`color-mix(in srgb, ${i} 60%, transparent)`,strokeLinejoin:"round",mask:`url(#${c})`,style:{"--flow-pulse-rest-width":`${a+16}px`,"--flow-pulse-expanded-width":`${a+36}px`}})]})}return s?h.jsx("path",{className:l,"data-animation-variant":u,"aria-hidden":"true",pointerEvents:"none",d:s,fill:"none",stroke:i,strokeWidth:a,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"}):h.jsx("rect",{className:l,"data-animation-variant":u,"aria-hidden":"true",pointerEvents:"none",x:e,y:t,width:Math.max(0,r),height:Math.max(0,n),rx:Math.max(0,Math.min(o,r/2,n/2)),fill:"none",stroke:i,strokeWidth:a,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const h0=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 Pl(e,t,r){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const a of t)(a.parent===i||a.id.startsWith(`${i}.`)||r.some(u=>(u.inverted?u.target:u.source)===i&&(u.inverted?u.source:u.target)===a.id))&&!n.has(a.id)&&(n.add(a.id),o.push(a.id))}return n}function p0(e,t,r){const n=r==="downward"||r==="upward",o=new Map;for(const a of e){if(a.source===a.target||a.sourceProperty||a.targetProperty)continue;const s=t(a.source),u=t(a.target);if(!s||!u)continue;const c=n?u.y-s.y:u.x-s.x,l=Math.abs(c)-(n?s.h+u.h:s.w+u.w)/2;if(l<=320)continue;const d=JSON.stringify([a.source,Math.sign(c)]),f=o.get(d)??[];f.push({edge:a,gap:l,cross:n?u.x-s.x:u.y-s.y}),o.set(d,f)}const i=new Map;for(const a of o.values()){if(new Set(a.map(({edge:u})=>u.target)).size<2)continue;const s=new Map;for(const{edge:u}of a)s.set(u.target,(s.get(u.target)??0)+1);for(const u of[-1,0,1]){const c=a.filter(({cross:d})=>Math.sign(d)===u);c.sort((d,f)=>Math.abs(f.cross)-Math.abs(d.cross)||d.edge.id.localeCompare(f.edge.id));const l=Math.min(...c.map(({gap:d})=>d));c.forEach(({edge:d,gap:f,cross:p},b)=>{const y=c.length===1?l/2:120+(l-280)*b/(c.length-1),m=c.find(x=>Math.abs(x.cross)<Math.abs(p));i.set(d.id,{turn:y/f,labelAtTarget:s.get(d.target)===1,labelFraction:p?(p+((m==null?void 0:m.cross)??0))/(2*p):.5})})}}return i}const at=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}),g0=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function Jn(e){if(!e.length)return null;const t={...e[0]};for(let r=1;r<e.length;r++)t.x1=Math.min(t.x1,e[r].x1),t.y1=Math.min(t.y1,e[r].y1),t.x2=Math.max(t.x2,e[r].x2),t.y2=Math.max(t.y2,e[r].y2);return t}const y0=(e,t)=>e.x1<=t.x2&&e.x2>=t.x1&&e.y1<=t.y2&&e.y2>=t.y1,Al=(e,t)=>e.x>=t.x1&&e.x<=t.x2&&e.y>=t.y1&&e.y<=t.y2,ur=e=>(Math.round(e*10)/10).toString(),Ue=e=>`${ur(e.x)} ${ur(e.y)}`,b0=e=>e>0?1:e<0?-1:0,Tl=(e,t)=>e>0?Math.max(e-t,0):Math.min(e+t,0);function m0(e,t,r,n,o=10){const i=t.x-e.x,a=t.y-e.y,s=Tl(i,(e.w+t.w)/2),u=Tl(a,(e.h+t.h)/2),c=r==="downward"||r==="upward",l=c?u:s,d=c?a:i,f=b0(d),p=n*l,b=g=>Math.abs(g)<o||Math.abs(g)>=Math.abs(l),y=b(p)||b(Math.abs(l)-Math.abs(p));let m;if(y)if(c)if(Math.abs(d)<=e.h/2){const g=(e.x+t.x)/2;m=[g,e.y,g,t.y]}else if(Math.abs(i)<=t.w/2){const g=(e.y+t.y)/2;m=[e.x,g,t.x,g]}else m=[e.x,t.y];else if(Math.abs(d)<=e.w/2){const g=(e.y+t.y)/2;m=[e.x,g,t.x,g]}else if(Math.abs(a)<=t.h/2){const g=(e.x+t.x)/2;m=[g,e.y,g,t.y]}else m=[t.x,e.y];else if(c){const g=e.y+p+e.h/2*f;m=[e.x,g,t.x,g]}else{const g=e.x+p+e.w/2*f;m=[g,e.y,g,t.y]}const x=[{x:e.x,y:e.y}];for(let g=0;g<m.length;g+=2)x.push({x:m[g],y:m[g+1]});return x.push({x:t.x,y:t.y}),x}function v0(e,t,r){const n=t.x-e.x,o=t.y-e.y,i=n>0?(r.x2-e.x)/n:n<0?(r.x1-e.x)/n:1/0,a=o>0?(r.y2-e.y)/o:o<0?(r.y1-e.y)/o:1/0,s=Math.min(i,a);return!Number.isFinite(s)||s>=1||s<0?null:{x:e.x+n*s,y:e.y+o*s}}function ft(e,t,r){var a;if(!((a=r.outline)!=null&&a.length))return v0(e,t,at(r));const n=t.x-e.x,o=t.y-e.y;let i=1/0;return r.outline.forEach((s,u,c)=>{const l=c[(u+1)%c.length],d=l.x-s.x,f=l.y-s.y,p=n*f-o*d;if(Math.abs(p)<1e-9)return;const b=s.x-e.x,y=s.y-e.y,m=(b*f-y*d)/p,x=(b*o-y*n)/p;m>=0&&m<1&&x>=-1e-9&&x<=1+1e-9&&(i=Math.min(i,m))}),Number.isFinite(i)?{x:e.x+n*i,y:e.y+o*i}:null}function wb(e,t,r=.5){const n=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.5,o=t==="top"||t==="bottom",i=t==="top"||t==="left"?-1:1,a={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},s=Math.max(e.w,e.h)*2+1;return{...ft(a,{x:a.x+(o?0:i*s),y:a.y+(o?i*s:0)},e)??{x:o?a.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:a.y},side:t}}function ut(e,t){return{x:e.x+(e.side==="right"?t:e.side==="left"?-t:0),y:e.y+(e.side==="bottom"?t:e.side==="top"?-t:0)}}function x0(e,t,r,n){const o=ut(e,r.srcDist),i=ut(t,r.tgtDist);if(n==="straight")return _b(o,i,r);const a=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),s=e.side==="bottom"&&t.side==="top"?i.y-o.y:e.side==="top"&&t.side==="bottom"?o.y-i.y:e.side==="right"&&t.side==="left"?i.x-o.x:e.side==="left"&&t.side==="right"?o.x-i.x:void 0,u=s!==void 0&&s>0?Math.min(a,s/2):a,c=ut({...o,side:e.side},u),l=ut({...i,side:t.side},u),d=r.arrowAt==="source"?Qe(o,c,r.arrowGap):o,f=r.arrowAt==="target"?Qe(i,l,r.arrowGap):i,p=r.arrowAt==="source"?br(o,c,r.arrowSize,r.headShape):r.arrowAt==="target"?br(i,l,r.arrowSize,r.headShape):void 0;if(n==="bezier")return{d:`M${Ue(d)} C${Ue(c)} ${Ue(l)} ${Ue(f)}`,arrow:p,label:{x:(d.x+3*c.x+3*l.x+f.x)/8,y:(d.y+3*c.y+3*l.y+f.y)/8,angle:0}};const b=e.side==="left"||e.side==="right",y=t.side==="left"||t.side==="right";let m;if(b!==y){const g=b?{x:l.x,y:c.y}:{x:c.x,y:l.y},w=(g.x-c.x)*(c.x-o.x)+(g.y-c.y)*(c.y-o.y)>=0,v=(g.x-l.x)*(l.x-i.x)+(g.y-l.y)*(l.y-i.y)>=0;m=[w&&v?g:b?{x:c.x,y:l.y}:{x:l.x,y:c.y}]}else if(s!==void 0&&s<=0)if(b){const g=(c.y+l.y)/2;m=[{x:c.x,y:g},{x:l.x,y:g}]}else{const g=(c.x+l.x)/2;m=[{x:g,y:c.y},{x:g,y:l.y}]}else if(b){const g=e.side===t.side?e.side==="right"?Math.max(c.x,l.x):Math.min(c.x,l.x):(c.x+l.x)/2;m=[{x:g,y:c.y},{x:g,y:l.y}]}else{const g=e.side===t.side?e.side==="bottom"?Math.max(c.y,l.y):Math.min(c.y,l.y):(c.y+l.y)/2;m=[{x:c.x,y:g},{x:l.x,y:g}]}const x=[c,...m,l].filter((g,w,v)=>w===0||g.x!==v[w-1].x||g.y!==v[w-1].y);return wn(d,x,f,p,n==="orthogonal"?0:r.radius)}function Qe(e,t,r){const n=e.x-t.x,o=e.y-t.y,i=Math.hypot(n,o);if(!i)return e;let a=(i-r)/i;return a<0&&(a=1e-5),{x:t.x+a*n,y:t.y+a*o}}function br(e,t,r,n="triangle"){const o=e.x-t.x,i=e.y-t.y,a=Math.hypot(o,i)||1,s=o/a,u=i/a,c=(n==="square"?.15:.3)*r,l=.15*r,d=e.x-s*c,f=e.y-u*c;return n==="square"?`M${Ue(e)} L${ur(e.x-u*l)} ${ur(e.y+s*l)} L${ur(d-u*l)} ${ur(f+s*l)} L${ur(d+u*l)} ${ur(f-s*l)} L${ur(e.x+u*l)} ${ur(e.y-s*l)} Z`:`M${Ue(e)} L${ur(d-u*l)} ${ur(f+s*l)} L${ur(d+u*l)} ${ur(f-s*l)} Z`}function Lr(e,t){let r=Math.atan(t/e);return e===0&&r<0&&(r=-r),Number.isFinite(r)||(r=0),r*180/Math.PI}function w0(e,t,r,n){const o={x:t.x-e.x,y:t.y-e.y},i={x:r.x-t.x,y:r.y-t.y},a=Math.hypot(o.x,o.y),s=Math.hypot(i.x,i.y),u=o.x*i.y-o.y*i.x;if(a<1e-6||s<1e-6||Math.abs(u)<1e-6)return{p1:t,b:t,p2:t,r:0};const c=Math.min(n,a/2,s/2);return{p1:{x:t.x-o.x/a*c,y:t.y-o.y/a*c},b:t,p2:{x:t.x+i.x/s*c,y:t.y+i.y/s*c},r:c}}function Cb(e,t,r,n){let o=-1,i=null;for(let b=0;b<e.length-1;b++){const y=ft(e[b],e[b+1],t);if(y){o=b,i=y;break}}let a=-1,s=null;for(let b=e.length-1;b>0;b--){const y=ft(e[b],e[b-1],r);if(y){a=b,s=y;break}}if(!i||!s||o>=a)return null;const u=e.slice(o+1,a),c=u[0]??s,l=u[u.length-1]??i;let d,f,p;if(n.arrowAt==="source"){const b=Qe(i,c,n.srcDist);d=Qe(i,c,n.srcDist+n.arrowGap),p=br(b,c,n.arrowSize,n.headShape)}else d=Qe(i,c,n.srcDist);if(n.arrowAt==="target"){const b=Qe(s,l,n.tgtDist);f=Qe(s,l,n.tgtDist+n.arrowGap),p=br(b,l,n.arrowSize,n.headShape)}else f=Qe(s,l,n.tgtDist);return wn(d,u,f,p,n.radius,n.labelTargetLength,n.labelFraction)}function wn(e,t,r,n,o,i,a){var f;const s=[e,...t,r],u=[];let c=`M${Ue(e)}`;for(let p=1;p<s.length-1;p++){const b=w0(s[p-1],s[p],s[p+1],o);u.push(b),b.r===0?c+=` L${Ue(b.b)}`:c+=` L${Ue(b.p1)} Q${Ue(b.b)} ${Ue(b.p2)}`}c+=` L${Ue(r)}`;let l;const d=t.length;if(d===0)l={x:(e.x+r.x)/2,y:(e.y+r.y)/2,angle:Lr(r.x-e.x,r.y-e.y)};else if(d%2===0){const p=t[d/2-1],b=t[d/2];l={x:(p.x+b.x)/2,y:(p.y+b.y)/2,angle:Lr(b.x-p.x,b.y-p.y)}}else{const p=u[(d-1)/2];if(p.r===0){const b=s[(d-1)/2+2];l={x:p.b.x,y:p.b.y,angle:Lr(b.x-p.b.x,b.y-p.b.y)}}else l={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:Lr(p.p2.x-p.p1.x,p.p2.y-p.p1.y)}}if(i!==void 0){if(a!==void 0&&u.length===2){const m=u[0].p2,x=u[1].p1,g=Math.hypot(x.x-m.x,x.y-m.y),w=Math.min(.5,i/(2*g)),v=Math.max(w,Math.min(1-w,a));l={x:m.x+(x.x-m.x)*v,y:m.y+(x.y-m.y)*v,angle:Lr(x.x-m.x,x.y-m.y)}}const p=((f=u[u.length-1])==null?void 0:f.p2)??e,b=r.x-p.x,y=r.y-p.y;Math.hypot(b,y)>=i&&(l={x:(p.x+r.x)/2,y:(p.y+r.y)/2,angle:Lr(b,y)})}return{d:c,arrow:n,label:l}}function Ol(e,t,r,n,o,i,a){const s=r==="leftward"?-1:1,u={x:e.x+s*(e.w/2+a.srcDist),y:n??e.y},c={x:t.x-s*(t.w/2+a.tgtDist),y:o??t.y},l=Math.max(80,a.arrowGap+a.arrowSize*.3),d=u.x+s*l,f=c.x-s*l;let p;if(s*(f-d)>=0){const x=u.x+(c.x-u.x)*i,g=Math.max(Math.min(d,f),Math.min(Math.max(d,f),x));p=[{x:g,y:u.y},{x:g,y:c.y}]}else{const x=Math.min(e.y-e.h/2,t.y-t.h/2)-l*(1+i);p=[{x:d,y:u.y},{x:d,y:x},{x:f,y:x},{x:f,y:c.y}]}const b=a.arrowAt==="source"?Qe(u,p[0],a.arrowGap):u,y=a.arrowAt==="target"?Qe(c,p[p.length-1],a.arrowGap):c,m=a.arrowAt==="source"?br(u,p[0],a.arrowSize,a.headShape):a.arrowAt==="target"?br(c,p[p.length-1],a.arrowSize,a.headShape):void 0;return wn(b,p,y,m,a.radius)}function Il(e,t,r,n,o){return Cb(m0(e,t,r,n),e,t,o)}function Ml(e,t,r,n,o,i){const a=n===void 0&&o===void 0&&(r==="downward"||r==="upward"),s=r==="leftward"||a&&r==="upward"?-1:1,u=(c,l,d)=>{const f={x:c.x,y:l??c.y},p=Math.max(c.w,c.h)*2+1,b=ft(f,{x:f.x+(a?0:d*p),y:f.y+(a?d*p:0)},c);return b?{x:b.x+(a?0:d*i),y:b.y+(a?d*i:0)}:a?{x:c.x,y:c.y+d*(c.h/2+i)}:{x:c.x+d*(c.w/2+i),y:l??c.y}};return{sourcePoint:u(e,n,s),targetPoint:u(t,o,-s)}}function C0(e,t,r,n){const o=r==="downward"||r==="upward",i=r==="leftward"||r==="upward"?-1:1,a=Math.max(100,Math.abs(o?t.y-e.y:t.x-e.x)/2),s={x:e.x+(o?0:i*a),y:e.y+(o?i*a:0)},u={x:t.x-(o?0:i*a),y:t.y-(o?i*a:0)},c=n.arrowAt==="source"?Qe(e,s,n.arrowGap):e,l=n.arrowAt==="target"?Qe(t,u,n.arrowGap):t;return{d:`M${Ue(c)} C${Ue(s)} ${Ue(u)} ${Ue(l)}`,arrow:n.arrowAt==="source"?br(e,s,n.arrowSize,n.headShape):n.arrowAt==="target"?br(t,u,n.arrowSize,n.headShape):void 0,label:{x:(c.x+3*s.x+3*u.x+l.x)/8,y:(c.y+3*s.y+3*u.y+l.y)/8,angle:Lr(l.x+u.x-s.x-c.x,l.y+u.y-s.y-c.y)}}}function _b(e,t,r){const n=r.arrowAt==="source"?Qe(e,t,r.arrowGap):e,o=r.arrowAt==="target"?Qe(t,e,r.arrowGap):t,i=r.arrowAt==="source"?br(e,t,r.arrowSize,r.headShape):r.arrowAt==="target"?br(t,e,r.arrowSize,r.headShape):void 0;return wn(n,[],o,i,0)}function _0(e,t,r,n=-90,o=-60,i=350){const a=n*Math.PI/180,s=o*Math.PI/180,u=a-Math.PI/2,c=u-s/2,l=u+s/2,d=1.4*i*(t/3+1),f={x:e.x+Math.cos(c)*d,y:e.y+Math.sin(c)*d},p={x:e.x+Math.cos(l)*d,y:e.y+Math.sin(l)*d},b={x:e.x,y:e.y},y=ft(b,f,e),m=ft(b,p,e);if(!y||!m)return null;const x={x:(f.x+p.x)/2,y:(f.y+p.y)/2};let g=Qe(y,f,r.srcDist),w=Qe(m,p,r.tgtDist),v;if(r.arrowAt==="target"){const C=w;w=Qe(m,p,r.tgtDist+r.arrowGap),v=br(C,p,r.arrowSize,r.headShape)}else if(r.arrowAt==="source"){const C=g;g=Qe(y,f,r.srcDist+r.arrowGap),v=br(C,f,r.arrowSize,r.headShape)}return{d:`M${Ue(g)} Q${Ue(f)} ${Ue(x)} Q${Ue(p)} ${Ue(w)}`,arrow:v,label:{x:x.x,y:x.y,angle:Lr(p.x-f.x,p.y-f.y)}}}const ot=e=>Math.round(e*1e3)/1e3;function Sb(e){const t=e.querySelector("[data-flow-node-surface]");if(!t)return;const r=e.getBoundingClientRect(),n=r.width/e.offsetWidth;if(!Number.isFinite(n)||n<=0)return;const o=t.getBoundingClientRect();if(!o.width||!o.height)return;const i=t,a=typeof i.getScreenCTM=="function"?i.getScreenCTM():null,s=typeof i.getTotalLength=="function"?i.getTotalLength():0,u=i.points,c=(u==null?void 0:u.numberOfItems)||128,l=a&&s>0?Array.from({length:c},(d,f)=>{const p=u!=null&&u.numberOfItems?u.getItem(f):i.getPointAtLength(s*f/c);return{x:ot((a.a*p.x+a.c*p.y+a.e-r.left)/n),y:ot((a.b*p.x+a.d*p.y+a.f-r.top)/n)}}):void 0;return{left:ot((o.left-r.left)/n),top:ot((o.top-r.top)/n),width:t instanceof HTMLElement?t.offsetWidth:ot(o.width/n),height:t instanceof HTMLElement?t.offsetHeight:ot(o.height/n),radius:parseFloat(getComputedStyle(t).borderTopLeftRadius)||0,...l?{outline:l}:{}}}function $t(e,t){const r=e.x-e.w/2,n=e.y-e.h/2;return{x:r+t.left+t.width/2,y:n+t.top+t.height/2,w:t.width,h:t.height,...t.outline?{outline:t.outline.map(o=>({x:r+o.x,y:n+o.y}))}:{}}}function S0(e,t,r,n,o){var l;const i=o!=="TB"&&o!=="BT",a=i?"top":"left",s=i?"bottom":"right",u=new Map;for(const d of n)for(const[f,p,b]of[[d.source,d.sourceProperty,d.target],[d.target,d.targetProperty,d.source]]){const y=t.get(b);if(p===void 0||!y||b===f)continue;const m=r.get(b),x=JSON.stringify([f,p]),g=u.get(x)??[];g.push(m?$t(y,m):y),u.set(x,g)}const c=new Map(e);for(const[d,f]of e){const p=t.get(d);if(!p||!f.some(w=>w.placement==="config"))continue;const b=r.get(d),y=b?$t(p,b):p,m={x:p.w/2,y:p.h/2,w:p.w,h:p.h},x=b?$t(m,b):m,g=new Map;for(const w of f){if(w.placement!=="config")continue;const _=(u.get(JSON.stringify([d,w.property]))??[]).reduce((S,T)=>S+(i?T.y-y.y:T.x-y.x),0),C=((l=w.anchor)==null?void 0:l.side)===s?s:a;g.set(w,_<-.001?a:_>.001?s:C)}c.set(d,f.map(w=>{const v=g.get(w);if(!v)return w;const _=f.filter(T=>g.get(T)===v),C=(_.indexOf(w)+1)/(_.length+1),S=wb(x,v,C);return{...w,anchor:S,top:S.y,height:0}}))}return c}function ql(e,t,r){const n=new Set(t.map(s=>s.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const s of t)!o.has(s.id)&&(o.has(s.parent??"")||s.id.startsWith(`${e}.`))&&(o.add(s.id),i=!0)}const a=new Set(o);for(const s of r)o.has(s.source)&&n.has(s.target)&&a.add(s.target),o.has(s.target)&&n.has(s.source)&&a.add(s.source);return a}const Qr='"Helvetica Neue", Helvetica, sans-serif';let _t;const nn=new Map;function Cn(e,t){const r=`${t}|${e}`,n=nn.get(r);if(n!==void 0)return n;_t===void 0&&(_t=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let o;return _t?(_t.font=t,o=_t.measureText(e).width):o=e.length*(parseFloat(t)||16)*.55,nn.size>5e3&&nn.clear(),nn.set(r,o),o}function j0(e,t,r){const n=[];for(const o of String(e).split(`
150
- `)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let a="";for(const s of i){const u=a?`${a} ${s}`:s;!a||Cn(u,t)<=r?a=u:(n.push(a),a=s)}n.push(a)}return n}const E0=e=>e.stopPropagation();function R0({id:e,rect:t,label:r,labelLayer:n,style:o,onSelect:i,onCollapse:a,selected:s=!1}){const u=t.x2-t.x1,c=t.y2-t.y1,l=o.borderWidth,d=o.borderStyle==="dashed"?`${l*4} ${l*2}`:o.borderStyle==="dotted"?`${l} ${l}`:void 0,f=t.x1+u/2,p=o.labelPosition==="top"?t.y1+o.labelMargin-o.fontSize/2:o.labelPosition==="bottom"?t.y2-o.labelMargin+o.fontSize/2:t.y1+c/2,b=r?Cn(r,`bold ${o.fontSize}px ${Qr}`):0,y=o.fontSize/5,m=r||s&&a?h.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[s&&a&&h.jsx("foreignObject",{x:f+b/2+y+8,y:p-24,width:48,height:48,"data-flow-content-toggle":"",style:{pointerEvents:"auto"},children:h.jsx(je,{label:"Show icon",children:h.jsx(ve,{"aria-label":"Show icon",icon:h.jsx(Z.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:o.textColor},onClick:x=>{x.stopPropagation(),a(e)}})})}),r&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:f-b/2-y,y:p-o.fontSize/2-y,width:b+2*y,height:o.fontSize+2*y,fill:o.textColor==="transparent"?"transparent":o.labelBg}),h.jsx("text",{x:f,y:p,fill:o.textColor,fontSize:o.fontSize,fontWeight:"bold",fontFamily:Qr,style:{fontSize:o.fontSize,fontWeight:"bold",fontFamily:Qr},textAnchor:"middle",dominantBaseline:"central",children:r})]})]}):null;return h.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:E0,onClick:x=>{x.stopPropagation(),i==null||i(e,{shiftKey:x.shiftKey,ctrlKey:x.ctrlKey,metaKey:x.metaKey,altKey:x.altKey})},children:[h.jsx("rect",{x:t.x1,y:t.y1,width:u,height:c,rx:o.borderRadius,ry:o.borderRadius,fill:o.bgColor,fillOpacity:o.bgOpacity,stroke:o.borderColor,strokeWidth:o.borderStyle==="double"?l/3:l,strokeDasharray:d}),o.borderStyle==="double"&&h.jsx("rect",{x:t.x1+l*2/3,y:t.y1+l*2/3,width:Math.max(0,u-l*4/3),height:Math.max(0,c-l*4/3),rx:Math.max(0,o.borderRadius-l*2/3),ry:Math.max(0,o.borderRadius-l*2/3),fill:"none",stroke:o.borderColor,strokeWidth:l/3}),o.animated&&l>0&&h.jsx(xb,{variant:o.animationVariant,x:t.x1,y:t.y1,width:u,height:c,radius:o.borderRadius,color:o.animationColor||o.borderColor,strokeWidth:Math.max(8,l*1.6)}),n&&m?Lt.createPortal(m,n):m]})}const k0=E.memo(R0),fn=45,jb=70,Kr=15,Eb=50;function Rb(e,t,r=fn){const n=`${r}px ${Qr}`,o=e?j0(e,n,200*r/fn):[],i=t?48+(o.length?12:0):0,a=i+Math.max(0,...o.map(c=>Cn(c,n))),s=Math.max(o.length*r,t?48:0),u=o.length||t?2*Kr:0;return{lines:o,iconWidth:i,contentWidth:a,contentHeight:s,width:a+u,height:s+u}}const hn=6,kb=3,$u=Math.max(Math.pow(hn*13.37,.9),29)*kb,Pb=hn*kb*2,an=80,P0=2*an+$u*.3+100,A0=36+2*Math.max(80,Pb+$u*.3);function xu(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function wu(e,t){return t==="auto"||(t==="properties"?xu(e):!xu(e))}function st(e,t,r){return r!=="properties"||e!=="root"||t.some(n=>(n.source===e||n.target===e)&&xu(n))}function T0(e,t,r,n=!1,o){if(!n||r!=="properties"&&!o)return{nodes:e,edges:t};const i=e.filter(s=>st(s.id,t,r)&&(!o||o.has(s.id))),a=new Set(i.map(s=>s.id));return{nodes:i,edges:t.filter(s=>wu(s,r)&&a.has(s.source)&&a.has(s.target))}}const O0=500,I0="32 18",M0=e=>e.stopPropagation();function q0({id:e,edgeData:t,validationIssue:r,edgeType:n="rounded-orthogonal",edgeRadius:o,customEdgeTypes:i,source:a,target:s,sourceProperty:u,targetProperty:c,sourceY:l,targetY:d,sourcePort:f,targetPort:p,propertyMode:b=!1,dir:y,turn:m,labelAtTarget:x,labelFraction:g,color:w,labelBg:v,labelLayer:_,label:C,dashed:S,animated:T,inverted:k,loopIndex:j=0,onSelect:P}){const R=t==null?void 0:t.icon,I=b?fn:jb,{lines:O,iconWidth:M,contentWidth:q,contentHeight:H}=E.useMemo(()=>Rb(C,R,I),[C,R,I]),V=E.useMemo(()=>{const X={srcDist:an,tgtDist:an,arrowGap:Pb,arrowSize:$u,headShape:b&&(k?l!==void 0||f:d!==void 0||p)?"square":"triangle",radius:o??(x?40:O0),arrowAt:k?"source":"target",labelTargetLength:x?q+2*Kr:void 0,labelFraction:x?g:void 0},se=l!==void 0||d!==void 0||!!f||!!p,Q=Ml(a,s,y,l,d,0),G=l===void 0&&d===void 0&&(y==="downward"||y==="upward"),J=f??{...Q.sourcePoint,side:G?y==="upward"?"top":"bottom":y==="leftward"?"left":"right"},te=p??{...Q.targetPoint,side:G?y==="upward"?"bottom":"top":y==="leftward"?"right":"left"},de=a.x===s.x&&a.y===s.y,fe=f||p?x0(J,te,{...X,srcDist:18,tgtDist:18},n):se?Ol(a,s,y,l,d,m,{...X,srcDist:18,tgtDist:18,radius:o??Math.min(X.radius,40)}):de?_0(a,j,{...X,srcDist:0,tgtDist:0}):Il(a,s,y,m,X);if(!fe)return null;const Ee=Ml(a,s,y,l,d,se?18:an);f&&(Ee.sourcePoint=ut(f,18)),p&&(Ee.targetPoint=ut(p,18));const ge=Object.prototype.hasOwnProperty.call(i??{},n)?i==null?void 0:i[n]:void 0;if(ge){const We={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return ge({edge:t??{id:e,source:"",target:""},source:{...a},target:{...s},...Ee,direction:We[y],sourceY:l,targetY:d,inverted:!!k,defaultGeometry:fe})??fe}return de||f||p?fe:n==="straight"?se?_b(Ee.sourcePoint,Ee.targetPoint,X):Cb([a,s],a,s,X):n==="bezier"?C0(Ee.sourcePoint,Ee.targetPoint,se?y==="leftward"?"leftward":"rightward":y,X):n==="orthogonal"?se?Ol(a,s,y,l,d,m,{...X,srcDist:18,tgtDist:18,radius:0}):Il(a,s,y,m,{...X,radius:0}):fe},[a,e,t,n,o,i,s,b,l,d,f,p,y,m,k,j,x,g,q]);if(!V)return null;const re=(y==="rightward"||y==="leftward")&&!Object.prototype.hasOwnProperty.call(i??{},n)&&!(b&&(l!==void 0||d!==void 0||f||p)),ce=re?`translate(${V.label.x} ${V.label.y-H/2-2*Kr})`:`translate(${V.label.x} ${V.label.y}) rotate(${V.label.angle}) translate(${x||Object.prototype.hasOwnProperty.call(i??{},n)?0:Eb} 0)`,le=r!=null&&r.startsWith("Unverified:")?"#b45309":"#dc2626",be=r?le:w,K=r?h.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":r,transform:`translate(${V.label.x} ${V.label.y-O.length*I/2-55})`,children:[h.jsx("title",{children:r}),h.jsx(Mr,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:le})]}):null,N=T&&(t==null?void 0:t.edgeAnimationVariant)==="traveling",B=!N&&(S||T)?I0:void 0,W=T&&!N?`flow-sdk-edge-anim${k?" flow-sdk-edge-anim-rev":""}`:void 0;let z=null;if(O.length||R){const X=q,se=H;z=h.jsxs("g",{className:"flow-sdk-edge-label","data-label-transform":ce,"data-label-horizontal":re||void 0,"data-edge-id":e,"data-source-property":u,"data-target-property":c,transform:ce,children:[h.jsx("rect",{x:-X/2-Kr,y:-se/2-Kr,width:X+2*Kr,height:se+2*Kr,fill:w==="transparent"?"transparent":v}),h.jsx("text",{fill:w,fontSize:I,style:{fontSize:I,fontFamily:Qr},fontFamily:Qr,textAnchor:"middle",dominantBaseline:"central",children:O.map((Q,G)=>h.jsx("tspan",{x:M/2,y:(G-(O.length-1)/2)*I,children:Q},G))}),R&&h.jsxs("g",{className:"flow-sdk-edge-icon",opacity:w==="transparent"?0:1,children:[h.jsx("title",{children:C?`Edge icon: ${C}`:"Edge icon"}),h.jsx("rect",{x:-X/2,y:-24,width:48,height:48,fill:"transparent"}),h.jsx(Mr,{name:R,svg:!0,size:48,x:-X/2,y:-24,color:w})]})]})}return h.jsxs("g",{className:"flow-sdk-edge","data-edge-id":e,"data-source-property":u,"data-target-property":c,"data-validation":r?r.startsWith("Unverified:")?"unverified":"invalid":void 0,"aria-label":r,onPointerDown:M0,onClick:X=>{X.stopPropagation(),P==null||P(e)},children:[h.jsx("path",{d:V.d,fill:"none",stroke:be,strokeWidth:hn,strokeOpacity:N?.35:void 0,strokeDasharray:B,className:W}),N&&h.jsx(d0,{path:V.d,color:be,width:hn*1.6,reversed:k}),V.arrow&&h.jsx("path",{d:V.arrow,fill:be}),_&&z?Lt.createPortal(z,_):z,_&&K?Lt.createPortal(K,_):K,h.jsx("path",{className:"flow-sdk-edge-hit",d:V.d,fill:"none",stroke:"transparent"})]})}const Nl=E.memo(q0),$l=(e,t)=>e.left<t.right&&e.right>t.left&&e.top<t.bottom&&e.bottom>t.top;function N0(e){const t=e.querySelector(".flow-sdk-labels"),r=t==null?void 0:t.getScreenCTM();if(!t||!r)return;const n=r.inverse(),o=(c,l=0)=>{const d=c.getBoundingClientRect(),f=new DOMPoint(d.left,d.top).matrixTransform(n),p=new DOMPoint(d.right,d.bottom).matrixTransform(n);return{left:f.x-l,right:p.x+l,top:f.y-l,bottom:p.y+l}},i=[...e.querySelectorAll(".flow-sdk-node, .flow-sdk-node button")].filter(c=>{const l=c.getBoundingClientRect(),d=getComputedStyle(c);return l.width>0&&l.height>0&&d.visibility!=="hidden"&&d.opacity!=="0"}).map(c=>o(c,24));for(const c of t.querySelectorAll(".flow-sdk-container-label"))i.push(o(c,12));const a=[...t.querySelectorAll(".flow-sdk-edge-label")];for(const c of a)c.setAttribute("transform",c.dataset.labelTransform??"");const s=new Map(a.map(c=>[c,o(c,8)])),u=new Map([...e.querySelectorAll(".flow-sdk-edge")].map(c=>[c.dataset.edgeId,c.querySelector("path")]));for(const c of a){const l=c.dataset.labelHorizontal==="true",d=s.get(c);s.delete(c);const f=S=>i.some(T=>$l(S,T))||[...s.values()].some(T=>$l(S,T));if(!l&&!f(d)){s.set(c,d);continue}const p=u.get(c.dataset.edgeId),b=c.querySelector("rect");if(!p||!b)continue;const y=b.getBBox(),m=p.getTotalLength();if(!Number.isFinite(m)||m<=0)continue;const x=(d.left+d.right)/2,g=(d.top+d.bottom)/2,w=Math.min(256,Math.max(16,Math.ceil(m/24))),v=Array.from({length:w+1},(S,T)=>p.getPointAtLength(m*T/w)),C=Array.from({length:w+1},(S,T)=>{const k=m*T/w,j=v[T],P=l?{x:j.x,y:j.y-y.height/2-15}:j,R=p.getPointAtLength(Math.max(0,k-2)),I=p.getPointAtLength(Math.min(m,k+2));let O=Math.atan2(I.y-R.y,I.x-R.x)*180/Math.PI;O>90&&(O-=180),O<-90&&(O+=180);const M=Math.abs(O)<1;l&&(O=0);const q=O*Math.PI/180,H=Math.abs(Math.cos(q))*y.width+Math.abs(Math.sin(q))*y.height,V=Math.abs(Math.sin(q))*y.width+Math.abs(Math.cos(q))*y.height;return{point:P,angle:O,straight:M,score:Math.hypot(P.x-x,P.y-g),bounds:{left:P.x-H/2-8,right:P.x+H/2+8,top:P.y-V/2-8,bottom:P.y+V/2+8}}}).sort((S,T)=>S.score-T.score).find(S=>!f(S.bounds)&&(!l||S.straight&&!v.some(T=>T.x>S.bounds.left&&T.x<S.bounds.right&&T.y>S.bounds.top&&T.y<S.bounds.bottom)));C?(c.setAttribute("transform",`translate(${C.point.x} ${C.point.y}) rotate(${C.angle})`),s.set(c,C.bounds)):s.set(c,d)}}var on=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Lu(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 Yn,Ll;function L0(){if(Ll)return Yn;Ll=1;function e(){this.__data__=[],this.size=0}return Yn=e,Yn}var Xn,Fl;function gt(){if(Fl)return Xn;Fl=1;function e(t,r){return t===r||t!==t&&r!==r}return Xn=e,Xn}var Qn,Bl;function _n(){if(Bl)return Qn;Bl=1;var e=gt();function t(r,n){for(var o=r.length;o--;)if(e(r[o][0],n))return o;return-1}return Qn=t,Qn}var eo,Dl;function F0(){if(Dl)return eo;Dl=1;var e=_n(),t=Array.prototype,r=t.splice;function n(o){var i=this.__data__,a=e(i,o);if(a<0)return!1;var s=i.length-1;return a==s?i.pop():r.call(i,a,1),--this.size,!0}return eo=n,eo}var ro,zl;function B0(){if(zl)return ro;zl=1;var e=_n();function t(r){var n=this.__data__,o=e(n,r);return o<0?void 0:n[o][1]}return ro=t,ro}var to,Vl;function D0(){if(Vl)return to;Vl=1;var e=_n();function t(r){return e(this.__data__,r)>-1}return to=t,to}var no,Wl;function z0(){if(Wl)return no;Wl=1;var e=_n();function t(r,n){var o=this.__data__,i=e(o,r);return i<0?(++this.size,o.push([r,n])):o[i][1]=n,this}return no=t,no}var oo,Gl;function Sn(){if(Gl)return oo;Gl=1;var e=L0(),t=F0(),r=B0(),n=D0(),o=z0();function i(a){var s=-1,u=a==null?0:a.length;for(this.clear();++s<u;){var c=a[s];this.set(c[0],c[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=o,oo=i,oo}var io,Ul;function V0(){if(Ul)return io;Ul=1;var e=Sn();function t(){this.__data__=new e,this.size=0}return io=t,io}var ao,Hl;function W0(){if(Hl)return ao;Hl=1;function e(t){var r=this.__data__,n=r.delete(t);return this.size=r.size,n}return ao=e,ao}var so,Kl;function G0(){if(Kl)return so;Kl=1;function e(t){return this.__data__.get(t)}return so=e,so}var co,Zl;function U0(){if(Zl)return co;Zl=1;function e(t){return this.__data__.has(t)}return co=e,co}var uo,Jl;function Ab(){if(Jl)return uo;Jl=1;var e=typeof on=="object"&&on&&on.Object===Object&&on;return uo=e,uo}var lo,Yl;function Sr(){if(Yl)return lo;Yl=1;var e=Ab(),t=typeof self=="object"&&self&&self.Object===Object&&self,r=e||t||Function("return this")();return lo=r,lo}var fo,Xl;function yt(){if(Xl)return fo;Xl=1;var e=Sr(),t=e.Symbol;return fo=t,fo}var ho,Ql;function H0(){if(Ql)return ho;Ql=1;var e=yt(),t=Object.prototype,r=t.hasOwnProperty,n=t.toString,o=e?e.toStringTag:void 0;function i(a){var s=r.call(a,o),u=a[o];try{a[o]=void 0;var c=!0}catch{}var l=n.call(a);return c&&(s?a[o]=u:delete a[o]),l}return ho=i,ho}var po,ed;function K0(){if(ed)return po;ed=1;var e=Object.prototype,t=e.toString;function r(n){return t.call(n)}return po=r,po}var go,rd;function et(){if(rd)return go;rd=1;var e=yt(),t=H0(),r=K0(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function a(s){return s==null?s===void 0?o:n:i&&i in Object(s)?t(s):r(s)}return go=a,go}var yo,td;function mr(){if(td)return yo;td=1;function e(t){var r=typeof t;return t!=null&&(r=="object"||r=="function")}return yo=e,yo}var bo,nd;function Yt(){if(nd)return bo;nd=1;var e=et(),t=mr(),r="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function a(s){if(!t(s))return!1;var u=e(s);return u==n||u==o||u==r||u==i}return bo=a,bo}var mo,od;function Z0(){if(od)return mo;od=1;var e=Sr(),t=e["__core-js_shared__"];return mo=t,mo}var vo,id;function J0(){if(id)return vo;id=1;var e=Z0(),t=(function(){var n=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})();function r(n){return!!t&&t in n}return vo=r,vo}var xo,ad;function Tb(){if(ad)return xo;ad=1;var e=Function.prototype,t=e.toString;function r(n){if(n!=null){try{return t.call(n)}catch{}try{return n+""}catch{}}return""}return xo=r,xo}var wo,sd;function Y0(){if(sd)return wo;sd=1;var e=Yt(),t=J0(),r=mr(),n=Tb(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,a=Function.prototype,s=Object.prototype,u=a.toString,c=s.hasOwnProperty,l=RegExp("^"+u.call(c).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function d(f){if(!r(f)||t(f))return!1;var p=e(f)?l:i;return p.test(n(f))}return wo=d,wo}var Co,cd;function X0(){if(cd)return Co;cd=1;function e(t,r){return t==null?void 0:t[r]}return Co=e,Co}var _o,ud;function rt(){if(ud)return _o;ud=1;var e=Y0(),t=X0();function r(n,o){var i=t(n,o);return e(i)?i:void 0}return _o=r,_o}var So,ld;function Fu(){if(ld)return So;ld=1;var e=rt(),t=Sr(),r=e(t,"Map");return So=r,So}var jo,dd;function jn(){if(dd)return jo;dd=1;var e=rt(),t=e(Object,"create");return jo=t,jo}var Eo,fd;function Q0(){if(fd)return Eo;fd=1;var e=jn();function t(){this.__data__=e?e(null):{},this.size=0}return Eo=t,Eo}var Ro,hd;function ew(){if(hd)return Ro;hd=1;function e(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r}return Ro=e,Ro}var ko,pd;function rw(){if(pd)return ko;pd=1;var e=jn(),t="__lodash_hash_undefined__",r=Object.prototype,n=r.hasOwnProperty;function o(i){var a=this.__data__;if(e){var s=a[i];return s===t?void 0:s}return n.call(a,i)?a[i]:void 0}return ko=o,ko}var Po,gd;function tw(){if(gd)return Po;gd=1;var e=jn(),t=Object.prototype,r=t.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:r.call(i,o)}return Po=n,Po}var Ao,yd;function nw(){if(yd)return Ao;yd=1;var e=jn(),t="__lodash_hash_undefined__";function r(n,o){var i=this.__data__;return this.size+=this.has(n)?0:1,i[n]=e&&o===void 0?t:o,this}return Ao=r,Ao}var To,bd;function ow(){if(bd)return To;bd=1;var e=Q0(),t=ew(),r=rw(),n=tw(),o=nw();function i(a){var s=-1,u=a==null?0:a.length;for(this.clear();++s<u;){var c=a[s];this.set(c[0],c[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=o,To=i,To}var Oo,md;function iw(){if(md)return Oo;md=1;var e=ow(),t=Sn(),r=Fu();function n(){this.size=0,this.__data__={hash:new e,map:new(r||t),string:new e}}return Oo=n,Oo}var Io,vd;function aw(){if(vd)return Io;vd=1;function e(t){var r=typeof t;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?t!=="__proto__":t===null}return Io=e,Io}var Mo,xd;function En(){if(xd)return Mo;xd=1;var e=aw();function t(r,n){var o=r.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return Mo=t,Mo}var qo,wd;function sw(){if(wd)return qo;wd=1;var e=En();function t(r){var n=e(this,r).delete(r);return this.size-=n?1:0,n}return qo=t,qo}var No,Cd;function cw(){if(Cd)return No;Cd=1;var e=En();function t(r){return e(this,r).get(r)}return No=t,No}var $o,_d;function uw(){if(_d)return $o;_d=1;var e=En();function t(r){return e(this,r).has(r)}return $o=t,$o}var Lo,Sd;function lw(){if(Sd)return Lo;Sd=1;var e=En();function t(r,n){var o=e(this,r),i=o.size;return o.set(r,n),this.size+=o.size==i?0:1,this}return Lo=t,Lo}var Fo,jd;function Bu(){if(jd)return Fo;jd=1;var e=iw(),t=sw(),r=cw(),n=uw(),o=lw();function i(a){var s=-1,u=a==null?0:a.length;for(this.clear();++s<u;){var c=a[s];this.set(c[0],c[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=o,Fo=i,Fo}var Bo,Ed;function dw(){if(Ed)return Bo;Ed=1;var e=Sn(),t=Fu(),r=Bu(),n=200;function o(i,a){var s=this.__data__;if(s instanceof e){var u=s.__data__;if(!t||u.length<n-1)return u.push([i,a]),this.size=++s.size,this;s=this.__data__=new r(u)}return s.set(i,a),this.size=s.size,this}return Bo=o,Bo}var Do,Rd;function Rn(){if(Rd)return Do;Rd=1;var e=Sn(),t=V0(),r=W0(),n=G0(),o=U0(),i=dw();function a(s){var u=this.__data__=new e(s);this.size=u.size}return a.prototype.clear=t,a.prototype.delete=r,a.prototype.get=n,a.prototype.has=o,a.prototype.set=i,Do=a,Do}var zo,kd;function Du(){if(kd)return zo;kd=1;function e(t,r){for(var n=-1,o=t==null?0:t.length;++n<o&&r(t[n],n,t)!==!1;);return t}return zo=e,zo}var Vo,Pd;function Ob(){if(Pd)return Vo;Pd=1;var e=rt(),t=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return Vo=t,Vo}var Wo,Ad;function kn(){if(Ad)return Wo;Ad=1;var e=Ob();function t(r,n,o){n=="__proto__"&&e?e(r,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):r[n]=o}return Wo=t,Wo}var Go,Td;function Pn(){if(Td)return Go;Td=1;var e=kn(),t=gt(),r=Object.prototype,n=r.hasOwnProperty;function o(i,a,s){var u=i[a];(!(n.call(i,a)&&t(u,s))||s===void 0&&!(a in i))&&e(i,a,s)}return Go=o,Go}var Uo,Od;function Xt(){if(Od)return Uo;Od=1;var e=Pn(),t=kn();function r(n,o,i,a){var s=!i;i||(i={});for(var u=-1,c=o.length;++u<c;){var l=o[u],d=a?a(i[l],n[l],l,i,n):void 0;d===void 0&&(d=n[l]),s?t(i,l,d):e(i,l,d)}return i}return Uo=r,Uo}var Ho,Id;function fw(){if(Id)return Ho;Id=1;function e(t,r){for(var n=-1,o=Array(t);++n<t;)o[n]=r(n);return o}return Ho=e,Ho}var Ko,Md;function Pr(){if(Md)return Ko;Md=1;function e(t){return t!=null&&typeof t=="object"}return Ko=e,Ko}var Zo,qd;function hw(){if(qd)return Zo;qd=1;var e=et(),t=Pr(),r="[object Arguments]";function n(o){return t(o)&&e(o)==r}return Zo=n,Zo}var Jo,Nd;function Qt(){if(Nd)return Jo;Nd=1;var e=hw(),t=Pr(),r=Object.prototype,n=r.hasOwnProperty,o=r.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(a){return t(a)&&n.call(a,"callee")&&!o.call(a,"callee")};return Jo=i,Jo}var Yo,$d;function Ke(){if($d)return Yo;$d=1;var e=Array.isArray;return Yo=e,Yo}var Pt={exports:{}},Xo,Ld;function pw(){if(Ld)return Xo;Ld=1;function e(){return!1}return Xo=e,Xo}Pt.exports;var Fd;function bt(){return Fd||(Fd=1,(function(e,t){var r=Sr(),n=pw(),o=t&&!t.nodeType&&t,i=o&&!0&&e&&!e.nodeType&&e,a=i&&i.exports===o,s=a?r.Buffer:void 0,u=s?s.isBuffer:void 0,c=u||n;e.exports=c})(Pt,Pt.exports)),Pt.exports}var Qo,Bd;function An(){if(Bd)return Qo;Bd=1;var e=9007199254740991,t=/^(?:0|[1-9]\d*)$/;function r(n,o){var i=typeof n;return o=o??e,!!o&&(i=="number"||i!="symbol"&&t.test(n))&&n>-1&&n%1==0&&n<o}return Qo=r,Qo}var ei,Dd;function zu(){if(Dd)return ei;Dd=1;var e=9007199254740991;function t(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return ei=t,ei}var ri,zd;function gw(){if(zd)return ri;zd=1;var e=et(),t=zu(),r=Pr(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",a="[object Date]",s="[object Error]",u="[object Function]",c="[object Map]",l="[object Number]",d="[object Object]",f="[object RegExp]",p="[object Set]",b="[object String]",y="[object WeakMap]",m="[object ArrayBuffer]",x="[object DataView]",g="[object Float32Array]",w="[object Float64Array]",v="[object Int8Array]",_="[object Int16Array]",C="[object Int32Array]",S="[object Uint8Array]",T="[object Uint8ClampedArray]",k="[object Uint16Array]",j="[object Uint32Array]",P={};P[g]=P[w]=P[v]=P[_]=P[C]=P[S]=P[T]=P[k]=P[j]=!0,P[n]=P[o]=P[m]=P[i]=P[x]=P[a]=P[s]=P[u]=P[c]=P[l]=P[d]=P[f]=P[p]=P[b]=P[y]=!1;function R(I){return r(I)&&t(I.length)&&!!P[e(I)]}return ri=R,ri}var ti,Vd;function Tn(){if(Vd)return ti;Vd=1;function e(t){return function(r){return t(r)}}return ti=e,ti}var At={exports:{}};At.exports;var Wd;function Vu(){return Wd||(Wd=1,(function(e,t){var r=Ab(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,a=i&&r.process,s=(function(){try{var u=o&&o.require&&o.require("util").types;return u||a&&a.binding&&a.binding("util")}catch{}})();e.exports=s})(At,At.exports)),At.exports}var ni,Gd;function en(){if(Gd)return ni;Gd=1;var e=gw(),t=Tn(),r=Vu(),n=r&&r.isTypedArray,o=n?t(n):e;return ni=o,ni}var oi,Ud;function Ib(){if(Ud)return oi;Ud=1;var e=fw(),t=Qt(),r=Ke(),n=bt(),o=An(),i=en(),a=Object.prototype,s=a.hasOwnProperty;function u(c,l){var d=r(c),f=!d&&t(c),p=!d&&!f&&n(c),b=!d&&!f&&!p&&i(c),y=d||f||p||b,m=y?e(c.length,String):[],x=m.length;for(var g in c)(l||s.call(c,g))&&!(y&&(g=="length"||p&&(g=="offset"||g=="parent")||b&&(g=="buffer"||g=="byteLength"||g=="byteOffset")||o(g,x)))&&m.push(g);return m}return oi=u,oi}var ii,Hd;function On(){if(Hd)return ii;Hd=1;var e=Object.prototype;function t(r){var n=r&&r.constructor,o=typeof n=="function"&&n.prototype||e;return r===o}return ii=t,ii}var ai,Kd;function Mb(){if(Kd)return ai;Kd=1;function e(t,r){return function(n){return t(r(n))}}return ai=e,ai}var si,Zd;function yw(){if(Zd)return si;Zd=1;var e=Mb(),t=e(Object.keys,Object);return si=t,si}var ci,Jd;function Wu(){if(Jd)return ci;Jd=1;var e=On(),t=yw(),r=Object.prototype,n=r.hasOwnProperty;function o(i){if(!e(i))return t(i);var a=[];for(var s in Object(i))n.call(i,s)&&s!="constructor"&&a.push(s);return a}return ci=o,ci}var ui,Yd;function qr(){if(Yd)return ui;Yd=1;var e=Yt(),t=zu();function r(n){return n!=null&&t(n.length)&&!e(n)}return ui=r,ui}var li,Xd;function Gr(){if(Xd)return li;Xd=1;var e=Ib(),t=Wu(),r=qr();function n(o){return r(o)?e(o):t(o)}return li=n,li}var di,Qd;function bw(){if(Qd)return di;Qd=1;var e=Xt(),t=Gr();function r(n,o){return n&&e(o,t(o),n)}return di=r,di}var fi,ef;function mw(){if(ef)return fi;ef=1;function e(t){var r=[];if(t!=null)for(var n in Object(t))r.push(n);return r}return fi=e,fi}var hi,rf;function vw(){if(rf)return hi;rf=1;var e=mr(),t=On(),r=mw(),n=Object.prototype,o=n.hasOwnProperty;function i(a){if(!e(a))return r(a);var s=t(a),u=[];for(var c in a)c=="constructor"&&(s||!o.call(a,c))||u.push(c);return u}return hi=i,hi}var pi,tf;function tt(){if(tf)return pi;tf=1;var e=Ib(),t=vw(),r=qr();function n(o){return r(o)?e(o,!0):t(o)}return pi=n,pi}var gi,nf;function xw(){if(nf)return gi;nf=1;var e=Xt(),t=tt();function r(n,o){return n&&e(o,t(o),n)}return gi=r,gi}var Tt={exports:{}};Tt.exports;var of;function qb(){return of||(of=1,(function(e,t){var r=Sr(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,a=i?r.Buffer:void 0,s=a?a.allocUnsafe:void 0;function u(c,l){if(l)return c.slice();var d=c.length,f=s?s(d):new c.constructor(d);return c.copy(f),f}e.exports=u})(Tt,Tt.exports)),Tt.exports}var yi,af;function Nb(){if(af)return yi;af=1;function e(t,r){var n=-1,o=t.length;for(r||(r=Array(o));++n<o;)r[n]=t[n];return r}return yi=e,yi}var bi,sf;function $b(){if(sf)return bi;sf=1;function e(t,r){for(var n=-1,o=t==null?0:t.length,i=0,a=[];++n<o;){var s=t[n];r(s,n,t)&&(a[i++]=s)}return a}return bi=e,bi}var mi,cf;function Lb(){if(cf)return mi;cf=1;function e(){return[]}return mi=e,mi}var vi,uf;function Gu(){if(uf)return vi;uf=1;var e=$b(),t=Lb(),r=Object.prototype,n=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(a){return a==null?[]:(a=Object(a),e(o(a),function(s){return n.call(a,s)}))}:t;return vi=i,vi}var xi,lf;function ww(){if(lf)return xi;lf=1;var e=Xt(),t=Gu();function r(n,o){return e(n,t(n),o)}return xi=r,xi}var wi,df;function Uu(){if(df)return wi;df=1;function e(t,r){for(var n=-1,o=r.length,i=t.length;++n<o;)t[i+n]=r[n];return t}return wi=e,wi}var Ci,ff;function In(){if(ff)return Ci;ff=1;var e=Mb(),t=e(Object.getPrototypeOf,Object);return Ci=t,Ci}var _i,hf;function Fb(){if(hf)return _i;hf=1;var e=Uu(),t=In(),r=Gu(),n=Lb(),o=Object.getOwnPropertySymbols,i=o?function(a){for(var s=[];a;)e(s,r(a)),a=t(a);return s}:n;return _i=i,_i}var Si,pf;function Cw(){if(pf)return Si;pf=1;var e=Xt(),t=Fb();function r(n,o){return e(n,t(n),o)}return Si=r,Si}var ji,gf;function Bb(){if(gf)return ji;gf=1;var e=Uu(),t=Ke();function r(n,o,i){var a=o(n);return t(n)?a:e(a,i(n))}return ji=r,ji}var Ei,yf;function Db(){if(yf)return Ei;yf=1;var e=Bb(),t=Gu(),r=Gr();function n(o){return e(o,r,t)}return Ei=n,Ei}var Ri,bf;function _w(){if(bf)return Ri;bf=1;var e=Bb(),t=Fb(),r=tt();function n(o){return e(o,r,t)}return Ri=n,Ri}var ki,mf;function Sw(){if(mf)return ki;mf=1;var e=rt(),t=Sr(),r=e(t,"DataView");return ki=r,ki}var Pi,vf;function jw(){if(vf)return Pi;vf=1;var e=rt(),t=Sr(),r=e(t,"Promise");return Pi=r,Pi}var Ai,xf;function zb(){if(xf)return Ai;xf=1;var e=rt(),t=Sr(),r=e(t,"Set");return Ai=r,Ai}var Ti,wf;function Ew(){if(wf)return Ti;wf=1;var e=rt(),t=Sr(),r=e(t,"WeakMap");return Ti=r,Ti}var Oi,Cf;function mt(){if(Cf)return Oi;Cf=1;var e=Sw(),t=Fu(),r=jw(),n=zb(),o=Ew(),i=et(),a=Tb(),s="[object Map]",u="[object Object]",c="[object Promise]",l="[object Set]",d="[object WeakMap]",f="[object DataView]",p=a(e),b=a(t),y=a(r),m=a(n),x=a(o),g=i;return(e&&g(new e(new ArrayBuffer(1)))!=f||t&&g(new t)!=s||r&&g(r.resolve())!=c||n&&g(new n)!=l||o&&g(new o)!=d)&&(g=function(w){var v=i(w),_=v==u?w.constructor:void 0,C=_?a(_):"";if(C)switch(C){case p:return f;case b:return s;case y:return c;case m:return l;case x:return d}return v}),Oi=g,Oi}var Ii,_f;function Rw(){if(_f)return Ii;_f=1;var e=Object.prototype,t=e.hasOwnProperty;function r(n){var o=n.length,i=new n.constructor(o);return o&&typeof n[0]=="string"&&t.call(n,"index")&&(i.index=n.index,i.input=n.input),i}return Ii=r,Ii}var Mi,Sf;function Vb(){if(Sf)return Mi;Sf=1;var e=Sr(),t=e.Uint8Array;return Mi=t,Mi}var qi,jf;function Hu(){if(jf)return qi;jf=1;var e=Vb();function t(r){var n=new r.constructor(r.byteLength);return new e(n).set(new e(r)),n}return qi=t,qi}var Ni,Ef;function kw(){if(Ef)return Ni;Ef=1;var e=Hu();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.byteLength)}return Ni=t,Ni}var $i,Rf;function Pw(){if(Rf)return $i;Rf=1;var e=/\w*$/;function t(r){var n=new r.constructor(r.source,e.exec(r));return n.lastIndex=r.lastIndex,n}return $i=t,$i}var Li,kf;function Aw(){if(kf)return Li;kf=1;var e=yt(),t=e?e.prototype:void 0,r=t?t.valueOf:void 0;function n(o){return r?Object(r.call(o)):{}}return Li=n,Li}var Fi,Pf;function Wb(){if(Pf)return Fi;Pf=1;var e=Hu();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.length)}return Fi=t,Fi}var Bi,Af;function Tw(){if(Af)return Bi;Af=1;var e=Hu(),t=kw(),r=Pw(),n=Aw(),o=Wb(),i="[object Boolean]",a="[object Date]",s="[object Map]",u="[object Number]",c="[object RegExp]",l="[object Set]",d="[object String]",f="[object Symbol]",p="[object ArrayBuffer]",b="[object DataView]",y="[object Float32Array]",m="[object Float64Array]",x="[object Int8Array]",g="[object Int16Array]",w="[object Int32Array]",v="[object Uint8Array]",_="[object Uint8ClampedArray]",C="[object Uint16Array]",S="[object Uint32Array]";function T(k,j,P){var R=k.constructor;switch(j){case p:return e(k);case i:case a:return new R(+k);case b:return t(k,P);case y:case m:case x:case g:case w:case v:case _:case C:case S:return o(k,P);case s:return new R;case u:case d:return new R(k);case c:return r(k);case l:return new R;case f:return n(k)}}return Bi=T,Bi}var Di,Tf;function Gb(){if(Tf)return Di;Tf=1;var e=mr(),t=Object.create,r=(function(){function n(){}return function(o){if(!e(o))return{};if(t)return t(o);n.prototype=o;var i=new n;return n.prototype=void 0,i}})();return Di=r,Di}var zi,Of;function Ub(){if(Of)return zi;Of=1;var e=Gb(),t=In(),r=On();function n(o){return typeof o.constructor=="function"&&!r(o)?e(t(o)):{}}return zi=n,zi}var Vi,If;function Ow(){if(If)return Vi;If=1;var e=mt(),t=Pr(),r="[object Map]";function n(o){return t(o)&&e(o)==r}return Vi=n,Vi}var Wi,Mf;function Iw(){if(Mf)return Wi;Mf=1;var e=Ow(),t=Tn(),r=Vu(),n=r&&r.isMap,o=n?t(n):e;return Wi=o,Wi}var Gi,qf;function Mw(){if(qf)return Gi;qf=1;var e=mt(),t=Pr(),r="[object Set]";function n(o){return t(o)&&e(o)==r}return Gi=n,Gi}var Ui,Nf;function qw(){if(Nf)return Ui;Nf=1;var e=Mw(),t=Tn(),r=Vu(),n=r&&r.isSet,o=n?t(n):e;return Ui=o,Ui}var Hi,$f;function Hb(){if($f)return Hi;$f=1;var e=Rn(),t=Du(),r=Pn(),n=bw(),o=xw(),i=qb(),a=Nb(),s=ww(),u=Cw(),c=Db(),l=_w(),d=mt(),f=Rw(),p=Tw(),b=Ub(),y=Ke(),m=bt(),x=Iw(),g=mr(),w=qw(),v=Gr(),_=tt(),C=1,S=2,T=4,k="[object Arguments]",j="[object Array]",P="[object Boolean]",R="[object Date]",I="[object Error]",O="[object Function]",M="[object GeneratorFunction]",q="[object Map]",H="[object Number]",V="[object Object]",re="[object RegExp]",ce="[object Set]",le="[object String]",be="[object Symbol]",K="[object WeakMap]",N="[object ArrayBuffer]",B="[object DataView]",W="[object Float32Array]",z="[object Float64Array]",X="[object Int8Array]",se="[object Int16Array]",Q="[object Int32Array]",G="[object Uint8Array]",J="[object Uint8ClampedArray]",te="[object Uint16Array]",de="[object Uint32Array]",fe={};fe[k]=fe[j]=fe[N]=fe[B]=fe[P]=fe[R]=fe[W]=fe[z]=fe[X]=fe[se]=fe[Q]=fe[q]=fe[H]=fe[V]=fe[re]=fe[ce]=fe[le]=fe[be]=fe[G]=fe[J]=fe[te]=fe[de]=!0,fe[I]=fe[O]=fe[K]=!1;function Ee(ge,We,me,Te,er,De){var Ne,He=We&C,rr=We&S,ze=We&T;if(me&&(Ne=er?me(ge,Te,er,De):me(ge)),Ne!==void 0)return Ne;if(!g(ge))return ge;var xr=y(ge);if(xr){if(Ne=f(ge),!He)return a(ge,Ne)}else{var Ze=d(ge),pr=Ze==O||Ze==M;if(m(ge))return i(ge,He);if(Ze==V||Ze==k||pr&&!er){if(Ne=rr||pr?{}:b(ge),!He)return rr?u(ge,o(Ne,ge)):s(ge,n(Ne,ge))}else{if(!fe[Ze])return er?ge:{};Ne=p(ge,Ze,He)}}De||(De=new e);var dr=De.get(ge);if(dr)return dr;De.set(ge,Ne),w(ge)?ge.forEach(function(or){Ne.add(Ee(or,We,me,or,ge,De))}):x(ge)&&ge.forEach(function(or,ar){Ne.set(ar,Ee(or,We,me,ar,ge,De))});var jr=ze?rr?l:c:rr?_:v,we=xr?void 0:jr(ge);return t(we||ge,function(or,ar){we&&(ar=or,or=ge[ar]),r(Ne,ar,Ee(or,We,me,ar,ge,De))}),Ne}return Hi=Ee,Hi}var Ki,Lf;function Nw(){if(Lf)return Ki;Lf=1;var e=Hb(),t=4;function r(n){return e(n,t)}return Ki=r,Ki}var Zi,Ff;function Ku(){if(Ff)return Zi;Ff=1;function e(t){return function(){return t}}return Zi=e,Zi}var Ji,Bf;function $w(){if(Bf)return Ji;Bf=1;function e(t){return function(r,n,o){for(var i=-1,a=Object(r),s=o(r),u=s.length;u--;){var c=s[t?u:++i];if(n(a[c],c,a)===!1)break}return r}}return Ji=e,Ji}var Yi,Df;function Zu(){if(Df)return Yi;Df=1;var e=$w(),t=e();return Yi=t,Yi}var Xi,zf;function Ju(){if(zf)return Xi;zf=1;var e=Zu(),t=Gr();function r(n,o){return n&&e(n,o,t)}return Xi=r,Xi}var Qi,Vf;function Lw(){if(Vf)return Qi;Vf=1;var e=qr();function t(r,n){return function(o,i){if(o==null)return o;if(!e(o))return r(o,i);for(var a=o.length,s=n?a:-1,u=Object(o);(n?s--:++s<a)&&i(u[s],s,u)!==!1;);return o}}return Qi=t,Qi}var ea,Wf;function Mn(){if(Wf)return ea;Wf=1;var e=Ju(),t=Lw(),r=t(e);return ea=r,ea}var ra,Gf;function nt(){if(Gf)return ra;Gf=1;function e(t){return t}return ra=e,ra}var ta,Uf;function Kb(){if(Uf)return ta;Uf=1;var e=nt();function t(r){return typeof r=="function"?r:e}return ta=t,ta}var na,Hf;function Zb(){if(Hf)return na;Hf=1;var e=Du(),t=Mn(),r=Kb(),n=Ke();function o(i,a){var s=n(i)?e:t;return s(i,r(a))}return na=o,na}var oa,Kf;function Jb(){return Kf||(Kf=1,oa=Zb()),oa}var ia,Zf;function Fw(){if(Zf)return ia;Zf=1;var e=Mn();function t(r,n){var o=[];return e(r,function(i,a,s){n(i,a,s)&&o.push(i)}),o}return ia=t,ia}var aa,Jf;function Bw(){if(Jf)return aa;Jf=1;var e="__lodash_hash_undefined__";function t(r){return this.__data__.set(r,e),this}return aa=t,aa}var sa,Yf;function Dw(){if(Yf)return sa;Yf=1;function e(t){return this.__data__.has(t)}return sa=e,sa}var ca,Xf;function Yb(){if(Xf)return ca;Xf=1;var e=Bu(),t=Bw(),r=Dw();function n(o){var i=-1,a=o==null?0:o.length;for(this.__data__=new e;++i<a;)this.add(o[i])}return n.prototype.add=n.prototype.push=t,n.prototype.has=r,ca=n,ca}var ua,Qf;function zw(){if(Qf)return ua;Qf=1;function e(t,r){for(var n=-1,o=t==null?0:t.length;++n<o;)if(r(t[n],n,t))return!0;return!1}return ua=e,ua}var la,eh;function Xb(){if(eh)return la;eh=1;function e(t,r){return t.has(r)}return la=e,la}var da,rh;function Qb(){if(rh)return da;rh=1;var e=Yb(),t=zw(),r=Xb(),n=1,o=2;function i(a,s,u,c,l,d){var f=u&n,p=a.length,b=s.length;if(p!=b&&!(f&&b>p))return!1;var y=d.get(a),m=d.get(s);if(y&&m)return y==s&&m==a;var x=-1,g=!0,w=u&o?new e:void 0;for(d.set(a,s),d.set(s,a);++x<p;){var v=a[x],_=s[x];if(c)var C=f?c(_,v,x,s,a,d):c(v,_,x,a,s,d);if(C!==void 0){if(C)continue;g=!1;break}if(w){if(!t(s,function(S,T){if(!r(w,T)&&(v===S||l(v,S,u,c,d)))return w.push(T)})){g=!1;break}}else if(!(v===_||l(v,_,u,c,d))){g=!1;break}}return d.delete(a),d.delete(s),g}return da=i,da}var fa,th;function Vw(){if(th)return fa;th=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o,i){n[++r]=[i,o]}),n}return fa=e,fa}var ha,nh;function Yu(){if(nh)return ha;nh=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o){n[++r]=o}),n}return ha=e,ha}var pa,oh;function Ww(){if(oh)return pa;oh=1;var e=yt(),t=Vb(),r=gt(),n=Qb(),o=Vw(),i=Yu(),a=1,s=2,u="[object Boolean]",c="[object Date]",l="[object Error]",d="[object Map]",f="[object Number]",p="[object RegExp]",b="[object Set]",y="[object String]",m="[object Symbol]",x="[object ArrayBuffer]",g="[object DataView]",w=e?e.prototype:void 0,v=w?w.valueOf:void 0;function _(C,S,T,k,j,P,R){switch(T){case g:if(C.byteLength!=S.byteLength||C.byteOffset!=S.byteOffset)return!1;C=C.buffer,S=S.buffer;case x:return!(C.byteLength!=S.byteLength||!P(new t(C),new t(S)));case u:case c:case f:return r(+C,+S);case l:return C.name==S.name&&C.message==S.message;case p:case y:return C==S+"";case d:var I=o;case b:var O=k&a;if(I||(I=i),C.size!=S.size&&!O)return!1;var M=R.get(C);if(M)return M==S;k|=s,R.set(C,S);var q=n(I(C),I(S),k,j,P,R);return R.delete(C),q;case m:if(v)return v.call(C)==v.call(S)}return!1}return pa=_,pa}var ga,ih;function Gw(){if(ih)return ga;ih=1;var e=Db(),t=1,r=Object.prototype,n=r.hasOwnProperty;function o(i,a,s,u,c,l){var d=s&t,f=e(i),p=f.length,b=e(a),y=b.length;if(p!=y&&!d)return!1;for(var m=p;m--;){var x=f[m];if(!(d?x in a:n.call(a,x)))return!1}var g=l.get(i),w=l.get(a);if(g&&w)return g==a&&w==i;var v=!0;l.set(i,a),l.set(a,i);for(var _=d;++m<p;){x=f[m];var C=i[x],S=a[x];if(u)var T=d?u(S,C,x,a,i,l):u(C,S,x,i,a,l);if(!(T===void 0?C===S||c(C,S,s,u,l):T)){v=!1;break}_||(_=x=="constructor")}if(v&&!_){var k=i.constructor,j=a.constructor;k!=j&&"constructor"in i&&"constructor"in a&&!(typeof k=="function"&&k instanceof k&&typeof j=="function"&&j instanceof j)&&(v=!1)}return l.delete(i),l.delete(a),v}return ga=o,ga}var ya,ah;function Uw(){if(ah)return ya;ah=1;var e=Rn(),t=Qb(),r=Ww(),n=Gw(),o=mt(),i=Ke(),a=bt(),s=en(),u=1,c="[object Arguments]",l="[object Array]",d="[object Object]",f=Object.prototype,p=f.hasOwnProperty;function b(y,m,x,g,w,v){var _=i(y),C=i(m),S=_?l:o(y),T=C?l:o(m);S=S==c?d:S,T=T==c?d:T;var k=S==d,j=T==d,P=S==T;if(P&&a(y)){if(!a(m))return!1;_=!0,k=!1}if(P&&!k)return v||(v=new e),_||s(y)?t(y,m,x,g,w,v):r(y,m,S,x,g,w,v);if(!(x&u)){var R=k&&p.call(y,"__wrapped__"),I=j&&p.call(m,"__wrapped__");if(R||I){var O=R?y.value():y,M=I?m.value():m;return v||(v=new e),w(O,M,x,g,v)}}return P?(v||(v=new e),n(y,m,x,g,w,v)):!1}return ya=b,ya}var ba,sh;function em(){if(sh)return ba;sh=1;var e=Uw(),t=Pr();function r(n,o,i,a,s){return n===o?!0:n==null||o==null||!t(n)&&!t(o)?n!==n&&o!==o:e(n,o,i,a,r,s)}return ba=r,ba}var ma,ch;function Hw(){if(ch)return ma;ch=1;var e=Rn(),t=em(),r=1,n=2;function o(i,a,s,u){var c=s.length,l=c,d=!u;if(i==null)return!l;for(i=Object(i);c--;){var f=s[c];if(d&&f[2]?f[1]!==i[f[0]]:!(f[0]in i))return!1}for(;++c<l;){f=s[c];var p=f[0],b=i[p],y=f[1];if(d&&f[2]){if(b===void 0&&!(p in i))return!1}else{var m=new e;if(u)var x=u(b,y,p,i,a,m);if(!(x===void 0?t(y,b,r|n,u,m):x))return!1}}return!0}return ma=o,ma}var va,uh;function rm(){if(uh)return va;uh=1;var e=mr();function t(r){return r===r&&!e(r)}return va=t,va}var xa,lh;function Kw(){if(lh)return xa;lh=1;var e=rm(),t=Gr();function r(n){for(var o=t(n),i=o.length;i--;){var a=o[i],s=n[a];o[i]=[a,s,e(s)]}return o}return xa=r,xa}var wa,dh;function tm(){if(dh)return wa;dh=1;function e(t,r){return function(n){return n==null?!1:n[t]===r&&(r!==void 0||t in Object(n))}}return wa=e,wa}var Ca,fh;function Zw(){if(fh)return Ca;fh=1;var e=Hw(),t=Kw(),r=tm();function n(o){var i=t(o);return i.length==1&&i[0][2]?r(i[0][0],i[0][1]):function(a){return a===o||e(a,o,i)}}return Ca=n,Ca}var _a,hh;function vt(){if(hh)return _a;hh=1;var e=et(),t=Pr(),r="[object Symbol]";function n(o){return typeof o=="symbol"||t(o)&&e(o)==r}return _a=n,_a}var Sa,ph;function Xu(){if(ph)return Sa;ph=1;var e=Ke(),t=vt(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,a){if(e(i))return!1;var s=typeof i;return s=="number"||s=="symbol"||s=="boolean"||i==null||t(i)?!0:n.test(i)||!r.test(i)||a!=null&&i in Object(a)}return Sa=o,Sa}var ja,gh;function Jw(){if(gh)return ja;gh=1;var e=Bu(),t="Expected a function";function r(n,o){if(typeof n!="function"||o!=null&&typeof o!="function")throw new TypeError(t);var i=function(){var a=arguments,s=o?o.apply(this,a):a[0],u=i.cache;if(u.has(s))return u.get(s);var c=n.apply(this,a);return i.cache=u.set(s,c)||u,c};return i.cache=new(r.Cache||e),i}return r.Cache=e,ja=r,ja}var Ea,yh;function Yw(){if(yh)return Ea;yh=1;var e=Jw(),t=500;function r(n){var o=e(n,function(a){return i.size===t&&i.clear(),a}),i=o.cache;return o}return Ea=r,Ea}var Ra,bh;function Xw(){if(bh)return Ra;bh=1;var e=Yw(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,n=e(function(o){var i=[];return o.charCodeAt(0)===46&&i.push(""),o.replace(t,function(a,s,u,c){i.push(u?c.replace(r,"$1"):s||a)}),i});return Ra=n,Ra}var ka,mh;function qn(){if(mh)return ka;mh=1;function e(t,r){for(var n=-1,o=t==null?0:t.length,i=Array(o);++n<o;)i[n]=r(t[n],n,t);return i}return ka=e,ka}var Pa,vh;function Qw(){if(vh)return Pa;vh=1;var e=yt(),t=qn(),r=Ke(),n=vt(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function a(s){if(typeof s=="string")return s;if(r(s))return t(s,a)+"";if(n(s))return i?i.call(s):"";var u=s+"";return u=="0"&&1/s==-1/0?"-0":u}return Pa=a,Pa}var Aa,xh;function nm(){if(xh)return Aa;xh=1;var e=Qw();function t(r){return r==null?"":e(r)}return Aa=t,Aa}var Ta,wh;function Nn(){if(wh)return Ta;wh=1;var e=Ke(),t=Xu(),r=Xw(),n=nm();function o(i,a){return e(i)?i:t(i,a)?[i]:r(n(i))}return Ta=o,Ta}var Oa,Ch;function rn(){if(Ch)return Oa;Ch=1;var e=vt();function t(r){if(typeof r=="string"||e(r))return r;var n=r+"";return n=="0"&&1/r==-1/0?"-0":n}return Oa=t,Oa}var Ia,_h;function $n(){if(_h)return Ia;_h=1;var e=Nn(),t=rn();function r(n,o){o=e(o,n);for(var i=0,a=o.length;n!=null&&i<a;)n=n[t(o[i++])];return i&&i==a?n:void 0}return Ia=r,Ia}var Ma,Sh;function e1(){if(Sh)return Ma;Sh=1;var e=$n();function t(r,n,o){var i=r==null?void 0:e(r,n);return i===void 0?o:i}return Ma=t,Ma}var qa,jh;function r1(){if(jh)return qa;jh=1;function e(t,r){return t!=null&&r in Object(t)}return qa=e,qa}var Na,Eh;function om(){if(Eh)return Na;Eh=1;var e=Nn(),t=Qt(),r=Ke(),n=An(),o=zu(),i=rn();function a(s,u,c){u=e(u,s);for(var l=-1,d=u.length,f=!1;++l<d;){var p=i(u[l]);if(!(f=s!=null&&c(s,p)))break;s=s[p]}return f||++l!=d?f:(d=s==null?0:s.length,!!d&&o(d)&&n(p,d)&&(r(s)||t(s)))}return Na=a,Na}var $a,Rh;function im(){if(Rh)return $a;Rh=1;var e=r1(),t=om();function r(n,o){return n!=null&&t(n,o,e)}return $a=r,$a}var La,kh;function t1(){if(kh)return La;kh=1;var e=em(),t=e1(),r=im(),n=Xu(),o=rm(),i=tm(),a=rn(),s=1,u=2;function c(l,d){return n(l)&&o(d)?i(a(l),d):function(f){var p=t(f,l);return p===void 0&&p===d?r(f,l):e(d,p,s|u)}}return La=c,La}var Fa,Ph;function am(){if(Ph)return Fa;Ph=1;function e(t){return function(r){return r==null?void 0:r[t]}}return Fa=e,Fa}var Ba,Ah;function n1(){if(Ah)return Ba;Ah=1;var e=$n();function t(r){return function(n){return e(n,r)}}return Ba=t,Ba}var Da,Th;function o1(){if(Th)return Da;Th=1;var e=am(),t=n1(),r=Xu(),n=rn();function o(i){return r(i)?e(n(i)):t(i)}return Da=o,Da}var za,Oh;function Nr(){if(Oh)return za;Oh=1;var e=Zw(),t=t1(),r=nt(),n=Ke(),o=o1();function i(a){return typeof a=="function"?a:a==null?r:typeof a=="object"?n(a)?t(a[0],a[1]):e(a):o(a)}return za=i,za}var Va,Ih;function sm(){if(Ih)return Va;Ih=1;var e=$b(),t=Fw(),r=Nr(),n=Ke();function o(i,a){var s=n(i)?e:t;return s(i,r(a,3))}return Va=o,Va}var Wa,Mh;function i1(){if(Mh)return Wa;Mh=1;var e=Object.prototype,t=e.hasOwnProperty;function r(n,o){return n!=null&&t.call(n,o)}return Wa=r,Wa}var Ga,qh;function cm(){if(qh)return Ga;qh=1;var e=i1(),t=om();function r(n,o){return n!=null&&t(n,o,e)}return Ga=r,Ga}var Ua,Nh;function a1(){if(Nh)return Ua;Nh=1;var e=Wu(),t=mt(),r=Qt(),n=Ke(),o=qr(),i=bt(),a=On(),s=en(),u="[object Map]",c="[object Set]",l=Object.prototype,d=l.hasOwnProperty;function f(p){if(p==null)return!0;if(o(p)&&(n(p)||typeof p=="string"||typeof p.splice=="function"||i(p)||s(p)||r(p)))return!p.length;var b=t(p);if(b==u||b==c)return!p.size;if(a(p))return!e(p).length;for(var y in p)if(d.call(p,y))return!1;return!0}return Ua=f,Ua}var Ha,$h;function um(){if($h)return Ha;$h=1;function e(t){return t===void 0}return Ha=e,Ha}var Ka,Lh;function lm(){if(Lh)return Ka;Lh=1;var e=Mn(),t=qr();function r(n,o){var i=-1,a=t(n)?Array(n.length):[];return e(n,function(s,u,c){a[++i]=o(s,u,c)}),a}return Ka=r,Ka}var Za,Fh;function dm(){if(Fh)return Za;Fh=1;var e=qn(),t=Nr(),r=lm(),n=Ke();function o(i,a){var s=n(i)?e:r;return s(i,t(a,3))}return Za=o,Za}var Ja,Bh;function s1(){if(Bh)return Ja;Bh=1;function e(t,r,n,o){var i=-1,a=t==null?0:t.length;for(o&&a&&(n=t[++i]);++i<a;)n=r(n,t[i],i,t);return n}return Ja=e,Ja}var Ya,Dh;function c1(){if(Dh)return Ya;Dh=1;function e(t,r,n,o,i){return i(t,function(a,s,u){n=o?(o=!1,a):r(n,a,s,u)}),n}return Ya=e,Ya}var Xa,zh;function fm(){if(zh)return Xa;zh=1;var e=s1(),t=Mn(),r=Nr(),n=c1(),o=Ke();function i(a,s,u){var c=o(a)?e:n,l=arguments.length<3;return c(a,r(s,4),u,l,t)}return Xa=i,Xa}var Qa,Vh;function u1(){if(Vh)return Qa;Vh=1;var e=et(),t=Ke(),r=Pr(),n="[object String]";function o(i){return typeof i=="string"||!t(i)&&r(i)&&e(i)==n}return Qa=o,Qa}var es,Wh;function l1(){if(Wh)return es;Wh=1;var e=am(),t=e("length");return es=t,es}var rs,Gh;function d1(){if(Gh)return rs;Gh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",a="\\u200d",s=RegExp("["+a+e+o+i+"]");function u(c){return s.test(c)}return rs=u,rs}var ts,Uh;function f1(){if(Uh)return ts;Uh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",a="["+e+"]",s="["+o+"]",u="\\ud83c[\\udffb-\\udfff]",c="(?:"+s+"|"+u+")",l="[^"+e+"]",d="(?:\\ud83c[\\udde6-\\uddff]){2}",f="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",b=c+"?",y="["+i+"]?",m="(?:"+p+"(?:"+[l,d,f].join("|")+")"+y+b+")*",x=y+b+m,g="(?:"+[l+s+"?",s,d,f,a].join("|")+")",w=RegExp(u+"(?="+u+")|"+g+x,"g");function v(_){for(var C=w.lastIndex=0;w.test(_);)++C;return C}return ts=v,ts}var ns,Hh;function h1(){if(Hh)return ns;Hh=1;var e=l1(),t=d1(),r=f1();function n(o){return t(o)?r(o):e(o)}return ns=n,ns}var os,Kh;function p1(){if(Kh)return os;Kh=1;var e=Wu(),t=mt(),r=qr(),n=u1(),o=h1(),i="[object Map]",a="[object Set]";function s(u){if(u==null)return 0;if(r(u))return n(u)?o(u):u.length;var c=t(u);return c==i||c==a?u.size:e(u).length}return os=s,os}var is,Zh;function g1(){if(Zh)return is;Zh=1;var e=Du(),t=Gb(),r=Ju(),n=Nr(),o=In(),i=Ke(),a=bt(),s=Yt(),u=mr(),c=en();function l(d,f,p){var b=i(d),y=b||a(d)||c(d);if(f=n(f,4),p==null){var m=d&&d.constructor;y?p=b?new m:[]:u(d)?p=s(m)?t(o(d)):{}:p={}}return(y?e:r)(d,function(x,g,w){return f(p,x,g,w)}),p}return is=l,is}var as,Jh;function y1(){if(Jh)return as;Jh=1;var e=yt(),t=Qt(),r=Ke(),n=e?e.isConcatSpreadable:void 0;function o(i){return r(i)||t(i)||!!(n&&i&&i[n])}return as=o,as}var ss,Yh;function Qu(){if(Yh)return ss;Yh=1;var e=Uu(),t=y1();function r(n,o,i,a,s){var u=-1,c=n.length;for(i||(i=t),s||(s=[]);++u<c;){var l=n[u];o>0&&i(l)?o>1?r(l,o-1,i,a,s):e(s,l):a||(s[s.length]=l)}return s}return ss=r,ss}var cs,Xh;function b1(){if(Xh)return cs;Xh=1;function e(t,r,n){switch(n.length){case 0:return t.call(r);case 1:return t.call(r,n[0]);case 2:return t.call(r,n[0],n[1]);case 3:return t.call(r,n[0],n[1],n[2])}return t.apply(r,n)}return cs=e,cs}var us,Qh;function hm(){if(Qh)return us;Qh=1;var e=b1(),t=Math.max;function r(n,o,i){return o=t(o===void 0?n.length-1:o,0),function(){for(var a=arguments,s=-1,u=t(a.length-o,0),c=Array(u);++s<u;)c[s]=a[o+s];s=-1;for(var l=Array(o+1);++s<o;)l[s]=a[s];return l[o]=i(c),e(n,this,l)}}return us=r,us}var ls,ep;function m1(){if(ep)return ls;ep=1;var e=Ku(),t=Ob(),r=nt(),n=t?function(o,i){return t(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:r;return ls=n,ls}var ds,rp;function v1(){if(rp)return ds;rp=1;var e=800,t=16,r=Date.now;function n(o){var i=0,a=0;return function(){var s=r(),u=t-(s-a);if(a=s,u>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return ds=n,ds}var fs,tp;function pm(){if(tp)return fs;tp=1;var e=m1(),t=v1(),r=t(e);return fs=r,fs}var hs,np;function Ln(){if(np)return hs;np=1;var e=nt(),t=hm(),r=pm();function n(o,i){return r(t(o,i,e),o+"")}return hs=n,hs}var ps,op;function gm(){if(op)return ps;op=1;function e(t,r,n,o){for(var i=t.length,a=n+(o?1:-1);o?a--:++a<i;)if(r(t[a],a,t))return a;return-1}return ps=e,ps}var gs,ip;function x1(){if(ip)return gs;ip=1;function e(t){return t!==t}return gs=e,gs}var ys,ap;function w1(){if(ap)return ys;ap=1;function e(t,r,n){for(var o=n-1,i=t.length;++o<i;)if(t[o]===r)return o;return-1}return ys=e,ys}var bs,sp;function C1(){if(sp)return bs;sp=1;var e=gm(),t=x1(),r=w1();function n(o,i,a){return i===i?r(o,i,a):e(o,t,a)}return bs=n,bs}var ms,cp;function _1(){if(cp)return ms;cp=1;var e=C1();function t(r,n){var o=r==null?0:r.length;return!!o&&e(r,n,0)>-1}return ms=t,ms}var vs,up;function S1(){if(up)return vs;up=1;function e(t,r,n){for(var o=-1,i=t==null?0:t.length;++o<i;)if(n(r,t[o]))return!0;return!1}return vs=e,vs}var xs,lp;function j1(){if(lp)return xs;lp=1;function e(){}return xs=e,xs}var ws,dp;function E1(){if(dp)return ws;dp=1;var e=zb(),t=j1(),r=Yu(),n=1/0,o=e&&1/r(new e([,-0]))[1]==n?function(i){return new e(i)}:t;return ws=o,ws}var Cs,fp;function R1(){if(fp)return Cs;fp=1;var e=Yb(),t=_1(),r=S1(),n=Xb(),o=E1(),i=Yu(),a=200;function s(u,c,l){var d=-1,f=t,p=u.length,b=!0,y=[],m=y;if(l)b=!1,f=r;else if(p>=a){var x=c?null:o(u);if(x)return i(x);b=!1,f=n,m=new e}else m=c?[]:y;e:for(;++d<p;){var g=u[d],w=c?c(g):g;if(g=l||g!==0?g:0,b&&w===w){for(var v=m.length;v--;)if(m[v]===w)continue e;c&&m.push(w),y.push(g)}else f(m,w,l)||(m!==y&&m.push(w),y.push(g))}return y}return Cs=s,Cs}var _s,hp;function ym(){if(hp)return _s;hp=1;var e=qr(),t=Pr();function r(n){return t(n)&&e(n)}return _s=r,_s}var Ss,pp;function k1(){if(pp)return Ss;pp=1;var e=Qu(),t=Ln(),r=R1(),n=ym(),o=t(function(i){return r(e(i,1,n,!0))});return Ss=o,Ss}var js,gp;function P1(){if(gp)return js;gp=1;var e=qn();function t(r,n){return e(n,function(o){return r[o]})}return js=t,js}var Es,yp;function bm(){if(yp)return Es;yp=1;var e=P1(),t=Gr();function r(n){return n==null?[]:e(n,t(n))}return Es=r,Es}var Rs,bp;function vr(){if(bp)return Rs;bp=1;var e;if(typeof Lu=="function")try{e={clone:Nw(),constant:Ku(),each:Jb(),filter:sm(),has:cm(),isArray:Ke(),isEmpty:a1(),isFunction:Yt(),isUndefined:um(),keys:Gr(),map:dm(),reduce:fm(),size:p1(),transform:g1(),union:k1(),values:bm()}}catch{}return e||(e=window._),Rs=e,Rs}var ks,mp;function el(){if(mp)return ks;mp=1;var e=vr();ks=o;var t="\0",r="\0",n="";function o(l){this._isDirected=e.has(l,"directed")?l.directed:!0,this._isMultigraph=e.has(l,"multigraph")?l.multigraph:!1,this._isCompound=e.has(l,"compound")?l.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[r]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}o.prototype._nodeCount=0,o.prototype._edgeCount=0,o.prototype.isDirected=function(){return this._isDirected},o.prototype.isMultigraph=function(){return this._isMultigraph},o.prototype.isCompound=function(){return this._isCompound},o.prototype.setGraph=function(l){return this._label=l,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(l){return e.isFunction(l)||(l=e.constant(l)),this._defaultNodeLabelFn=l,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var l=this;return e.filter(this.nodes(),function(d){return e.isEmpty(l._in[d])})},o.prototype.sinks=function(){var l=this;return e.filter(this.nodes(),function(d){return e.isEmpty(l._out[d])})},o.prototype.setNodes=function(l,d){var f=arguments,p=this;return e.each(l,function(b){f.length>1?p.setNode(b,d):p.setNode(b)}),this},o.prototype.setNode=function(l,d){return e.has(this._nodes,l)?(arguments.length>1&&(this._nodes[l]=d),this):(this._nodes[l]=arguments.length>1?d:this._defaultNodeLabelFn(l),this._isCompound&&(this._parent[l]=r,this._children[l]={},this._children[r][l]=!0),this._in[l]={},this._preds[l]={},this._out[l]={},this._sucs[l]={},++this._nodeCount,this)},o.prototype.node=function(l){return this._nodes[l]},o.prototype.hasNode=function(l){return e.has(this._nodes,l)},o.prototype.removeNode=function(l){var d=this;if(e.has(this._nodes,l)){var f=function(p){d.removeEdge(d._edgeObjs[p])};delete this._nodes[l],this._isCompound&&(this._removeFromParentsChildList(l),delete this._parent[l],e.each(this.children(l),function(p){d.setParent(p)}),delete this._children[l]),e.each(e.keys(this._in[l]),f),delete this._in[l],delete this._preds[l],e.each(e.keys(this._out[l]),f),delete this._out[l],delete this._sucs[l],--this._nodeCount}return this},o.prototype.setParent=function(l,d){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(d))d=r;else{d+="";for(var f=d;!e.isUndefined(f);f=this.parent(f))if(f===l)throw new Error("Setting "+d+" as parent of "+l+" would create a cycle");this.setNode(d)}return this.setNode(l),this._removeFromParentsChildList(l),this._parent[l]=d,this._children[d][l]=!0,this},o.prototype._removeFromParentsChildList=function(l){delete this._children[this._parent[l]][l]},o.prototype.parent=function(l){if(this._isCompound){var d=this._parent[l];if(d!==r)return d}},o.prototype.children=function(l){if(e.isUndefined(l)&&(l=r),this._isCompound){var d=this._children[l];if(d)return e.keys(d)}else{if(l===r)return this.nodes();if(this.hasNode(l))return[]}},o.prototype.predecessors=function(l){var d=this._preds[l];if(d)return e.keys(d)},o.prototype.successors=function(l){var d=this._sucs[l];if(d)return e.keys(d)},o.prototype.neighbors=function(l){var d=this.predecessors(l);if(d)return e.union(d,this.successors(l))},o.prototype.isLeaf=function(l){var d;return this.isDirected()?d=this.successors(l):d=this.neighbors(l),d.length===0},o.prototype.filterNodes=function(l){var d=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});d.setGraph(this.graph());var f=this;e.each(this._nodes,function(y,m){l(m)&&d.setNode(m,y)}),e.each(this._edgeObjs,function(y){d.hasNode(y.v)&&d.hasNode(y.w)&&d.setEdge(y,f.edge(y))});var p={};function b(y){var m=f.parent(y);return m===void 0||d.hasNode(m)?(p[y]=m,m):m in p?p[m]:b(m)}return this._isCompound&&e.each(d.nodes(),function(y){d.setParent(y,b(y))}),d},o.prototype.setDefaultEdgeLabel=function(l){return e.isFunction(l)||(l=e.constant(l)),this._defaultEdgeLabelFn=l,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(l,d){var f=this,p=arguments;return e.reduce(l,function(b,y){return p.length>1?f.setEdge(b,y,d):f.setEdge(b,y),y}),this},o.prototype.setEdge=function(){var l,d,f,p,b=!1,y=arguments[0];typeof y=="object"&&y!==null&&"v"in y?(l=y.v,d=y.w,f=y.name,arguments.length===2&&(p=arguments[1],b=!0)):(l=y,d=arguments[1],f=arguments[3],arguments.length>2&&(p=arguments[2],b=!0)),l=""+l,d=""+d,e.isUndefined(f)||(f=""+f);var m=s(this._isDirected,l,d,f);if(e.has(this._edgeLabels,m))return b&&(this._edgeLabels[m]=p),this;if(!e.isUndefined(f)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(l),this.setNode(d),this._edgeLabels[m]=b?p:this._defaultEdgeLabelFn(l,d,f);var x=u(this._isDirected,l,d,f);return l=x.v,d=x.w,Object.freeze(x),this._edgeObjs[m]=x,i(this._preds[d],l),i(this._sucs[l],d),this._in[d][m]=x,this._out[l][m]=x,this._edgeCount++,this},o.prototype.edge=function(l,d,f){var p=arguments.length===1?c(this._isDirected,arguments[0]):s(this._isDirected,l,d,f);return this._edgeLabels[p]},o.prototype.hasEdge=function(l,d,f){var p=arguments.length===1?c(this._isDirected,arguments[0]):s(this._isDirected,l,d,f);return e.has(this._edgeLabels,p)},o.prototype.removeEdge=function(l,d,f){var p=arguments.length===1?c(this._isDirected,arguments[0]):s(this._isDirected,l,d,f),b=this._edgeObjs[p];return b&&(l=b.v,d=b.w,delete this._edgeLabels[p],delete this._edgeObjs[p],a(this._preds[d],l),a(this._sucs[l],d),delete this._in[d][p],delete this._out[l][p],this._edgeCount--),this},o.prototype.inEdges=function(l,d){var f=this._in[l];if(f){var p=e.values(f);return d?e.filter(p,function(b){return b.v===d}):p}},o.prototype.outEdges=function(l,d){var f=this._out[l];if(f){var p=e.values(f);return d?e.filter(p,function(b){return b.w===d}):p}},o.prototype.nodeEdges=function(l,d){var f=this.inEdges(l,d);if(f)return f.concat(this.outEdges(l,d))};function i(l,d){l[d]?l[d]++:l[d]=1}function a(l,d){--l[d]||delete l[d]}function s(l,d,f,p){var b=""+d,y=""+f;if(!l&&b>y){var m=b;b=y,y=m}return b+n+y+n+(e.isUndefined(p)?t:p)}function u(l,d,f,p){var b=""+d,y=""+f;if(!l&&b>y){var m=b;b=y,y=m}var x={v:b,w:y};return p&&(x.name=p),x}function c(l,d){return s(l,d.v,d.w,d.name)}return ks}var Ps,vp;function A1(){return vp||(vp=1,Ps="2.1.8"),Ps}var As,xp;function T1(){return xp||(xp=1,As={Graph:el(),version:A1()}),As}var Ts,wp;function O1(){if(wp)return Ts;wp=1;var e=vr(),t=el();Ts={write:r,read:i};function r(a){var s={options:{directed:a.isDirected(),multigraph:a.isMultigraph(),compound:a.isCompound()},nodes:n(a),edges:o(a)};return e.isUndefined(a.graph())||(s.value=e.clone(a.graph())),s}function n(a){return e.map(a.nodes(),function(s){var u=a.node(s),c=a.parent(s),l={v:s};return e.isUndefined(u)||(l.value=u),e.isUndefined(c)||(l.parent=c),l})}function o(a){return e.map(a.edges(),function(s){var u=a.edge(s),c={v:s.v,w:s.w};return e.isUndefined(s.name)||(c.name=s.name),e.isUndefined(u)||(c.value=u),c})}function i(a){var s=new t(a.options).setGraph(a.value);return e.each(a.nodes,function(u){s.setNode(u.v,u.value),u.parent&&s.setParent(u.v,u.parent)}),e.each(a.edges,function(u){s.setEdge({v:u.v,w:u.w,name:u.name},u.value)}),s}return Ts}var Os,Cp;function I1(){if(Cp)return Os;Cp=1;var e=vr();Os=t;function t(r){var n={},o=[],i;function a(s){e.has(n,s)||(n[s]=!0,i.push(s),e.each(r.successors(s),a),e.each(r.predecessors(s),a))}return e.each(r.nodes(),function(s){i=[],a(s),i.length&&o.push(i)}),o}return Os}var Is,_p;function mm(){if(_p)return Is;_p=1;var e=vr();Is=t;function t(){this._arr=[],this._keyIndices={}}return t.prototype.size=function(){return this._arr.length},t.prototype.keys=function(){return this._arr.map(function(r){return r.key})},t.prototype.has=function(r){return e.has(this._keyIndices,r)},t.prototype.priority=function(r){var n=this._keyIndices[r];if(n!==void 0)return this._arr[n].priority},t.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},t.prototype.add=function(r,n){var o=this._keyIndices;if(r=String(r),!e.has(o,r)){var i=this._arr,a=i.length;return o[r]=a,i.push({key:r,priority:n}),this._decrease(a),!0}return!1},t.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var r=this._arr.pop();return delete this._keyIndices[r.key],this._heapify(0),r.key},t.prototype.decrease=function(r,n){var o=this._keyIndices[r];if(n>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+r+" Old: "+this._arr[o].priority+" New: "+n);this._arr[o].priority=n,this._decrease(o)},t.prototype._heapify=function(r){var n=this._arr,o=2*r,i=o+1,a=r;o<n.length&&(a=n[o].priority<n[a].priority?o:a,i<n.length&&(a=n[i].priority<n[a].priority?i:a),a!==r&&(this._swap(r,a),this._heapify(a)))},t.prototype._decrease=function(r){for(var n=this._arr,o=n[r].priority,i;r!==0&&(i=r>>1,!(n[i].priority<o));)this._swap(r,i),r=i},t.prototype._swap=function(r,n){var o=this._arr,i=this._keyIndices,a=o[r],s=o[n];o[r]=s,o[n]=a,i[s.key]=r,i[a.key]=n},Is}var Ms,Sp;function vm(){if(Sp)return Ms;Sp=1;var e=vr(),t=mm();Ms=n;var r=e.constant(1);function n(i,a,s,u){return o(i,String(a),s||r,u||function(c){return i.outEdges(c)})}function o(i,a,s,u){var c={},l=new t,d,f,p=function(b){var y=b.v!==d?b.v:b.w,m=c[y],x=s(b),g=f.distance+x;if(x<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+b+" Weight: "+x);g<m.distance&&(m.distance=g,m.predecessor=d,l.decrease(y,g))};for(i.nodes().forEach(function(b){var y=b===a?0:Number.POSITIVE_INFINITY;c[b]={distance:y},l.add(b,y)});l.size()>0&&(d=l.removeMin(),f=c[d],f.distance!==Number.POSITIVE_INFINITY);)u(d).forEach(p);return c}return Ms}var qs,jp;function M1(){if(jp)return qs;jp=1;var e=vm(),t=vr();qs=r;function r(n,o,i){return t.transform(n.nodes(),function(a,s){a[s]=e(n,s,o,i)},{})}return qs}var Ns,Ep;function xm(){if(Ep)return Ns;Ep=1;var e=vr();Ns=t;function t(r){var n=0,o=[],i={},a=[];function s(u){var c=i[u]={onStack:!0,lowlink:n,index:n++};if(o.push(u),r.successors(u).forEach(function(f){e.has(i,f)?i[f].onStack&&(c.lowlink=Math.min(c.lowlink,i[f].index)):(s(f),c.lowlink=Math.min(c.lowlink,i[f].lowlink))}),c.lowlink===c.index){var l=[],d;do d=o.pop(),i[d].onStack=!1,l.push(d);while(u!==d);a.push(l)}}return r.nodes().forEach(function(u){e.has(i,u)||s(u)}),a}return Ns}var $s,Rp;function q1(){if(Rp)return $s;Rp=1;var e=vr(),t=xm();$s=r;function r(n){return e.filter(t(n),function(o){return o.length>1||o.length===1&&n.hasEdge(o[0],o[0])})}return $s}var Ls,kp;function N1(){if(kp)return Ls;kp=1;var e=vr();Ls=r;var t=e.constant(1);function r(o,i,a){return n(o,i||t,a||function(s){return o.outEdges(s)})}function n(o,i,a){var s={},u=o.nodes();return u.forEach(function(c){s[c]={},s[c][c]={distance:0},u.forEach(function(l){c!==l&&(s[c][l]={distance:Number.POSITIVE_INFINITY})}),a(c).forEach(function(l){var d=l.v===c?l.w:l.v,f=i(l);s[c][d]={distance:f,predecessor:c}})}),u.forEach(function(c){var l=s[c];u.forEach(function(d){var f=s[d];u.forEach(function(p){var b=f[c],y=l[p],m=f[p],x=b.distance+y.distance;x<m.distance&&(m.distance=x,m.predecessor=y.predecessor)})})}),s}return Ls}var Fs,Pp;function wm(){if(Pp)return Fs;Pp=1;var e=vr();Fs=t,t.CycleException=r;function t(n){var o={},i={},a=[];function s(u){if(e.has(i,u))throw new r;e.has(o,u)||(i[u]=!0,o[u]=!0,e.each(n.predecessors(u),s),delete i[u],a.push(u))}if(e.each(n.sinks(),s),e.size(o)!==n.nodeCount())throw new r;return a}function r(){}return r.prototype=new Error,Fs}var Bs,Ap;function $1(){if(Ap)return Bs;Ap=1;var e=wm();Bs=t;function t(r){try{e(r)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Bs}var Ds,Tp;function Cm(){if(Tp)return Ds;Tp=1;var e=vr();Ds=t;function t(n,o,i){e.isArray(o)||(o=[o]);var a=(n.isDirected()?n.successors:n.neighbors).bind(n),s=[],u={};return e.each(o,function(c){if(!n.hasNode(c))throw new Error("Graph does not have node: "+c);r(n,c,i==="post",u,a,s)}),s}function r(n,o,i,a,s,u){e.has(a,o)||(a[o]=!0,i||u.push(o),e.each(s(o),function(c){r(n,c,i,a,s,u)}),i&&u.push(o))}return Ds}var zs,Op;function L1(){if(Op)return zs;Op=1;var e=Cm();zs=t;function t(r,n){return e(r,n,"post")}return zs}var Vs,Ip;function F1(){if(Ip)return Vs;Ip=1;var e=Cm();Vs=t;function t(r,n){return e(r,n,"pre")}return Vs}var Ws,Mp;function B1(){if(Mp)return Ws;Mp=1;var e=vr(),t=el(),r=mm();Ws=n;function n(o,i){var a=new t,s={},u=new r,c;function l(f){var p=f.v===c?f.w:f.v,b=u.priority(p);if(b!==void 0){var y=i(f);y<b&&(s[p]=c,u.decrease(p,y))}}if(o.nodeCount()===0)return a;e.each(o.nodes(),function(f){u.add(f,Number.POSITIVE_INFINITY),a.setNode(f)}),u.decrease(o.nodes()[0],0);for(var d=!1;u.size()>0;){if(c=u.removeMin(),e.has(s,c))a.setEdge(c,s[c]);else{if(d)throw new Error("Input graph is not connected: "+o);d=!0}o.nodeEdges(c).forEach(l)}return a}return Ws}var Gs,qp;function D1(){return qp||(qp=1,Gs={components:I1(),dijkstra:vm(),dijkstraAll:M1(),findCycles:q1(),floydWarshall:N1(),isAcyclic:$1(),postorder:L1(),preorder:F1(),prim:B1(),tarjan:xm(),topsort:wm()}),Gs}var Us,Np;function z1(){if(Np)return Us;Np=1;var e=T1();return Us={Graph:e.Graph,json:O1(),alg:D1(),version:e.version},Us}var Hs,$p;function _r(){if($p)return Hs;$p=1;var e;if(typeof Lu=="function")try{e=z1()}catch{}return e||(e=window.graphlib),Hs=e,Hs}var Ks,Lp;function V1(){if(Lp)return Ks;Lp=1;var e=Hb(),t=1,r=4;function n(o){return e(o,t|r)}return Ks=n,Ks}var Zs,Fp;function Fn(){if(Fp)return Zs;Fp=1;var e=gt(),t=qr(),r=An(),n=mr();function o(i,a,s){if(!n(s))return!1;var u=typeof a;return(u=="number"?t(s)&&r(a,s.length):u=="string"&&a in s)?e(s[a],i):!1}return Zs=o,Zs}var Js,Bp;function W1(){if(Bp)return Js;Bp=1;var e=Ln(),t=gt(),r=Fn(),n=tt(),o=Object.prototype,i=o.hasOwnProperty,a=e(function(s,u){s=Object(s);var c=-1,l=u.length,d=l>2?u[2]:void 0;for(d&&r(u[0],u[1],d)&&(l=1);++c<l;)for(var f=u[c],p=n(f),b=-1,y=p.length;++b<y;){var m=p[b],x=s[m];(x===void 0||t(x,o[m])&&!i.call(s,m))&&(s[m]=f[m])}return s});return Js=a,Js}var Ys,Dp;function G1(){if(Dp)return Ys;Dp=1;var e=Nr(),t=qr(),r=Gr();function n(o){return function(i,a,s){var u=Object(i);if(!t(i)){var c=e(a,3);i=r(i),a=function(d){return c(u[d],d,u)}}var l=o(i,a,s);return l>-1?u[c?i[l]:l]:void 0}}return Ys=n,Ys}var Xs,zp;function U1(){if(zp)return Xs;zp=1;var e=/\s/;function t(r){for(var n=r.length;n--&&e.test(r.charAt(n)););return n}return Xs=t,Xs}var Qs,Vp;function H1(){if(Vp)return Qs;Vp=1;var e=U1(),t=/^\s+/;function r(n){return n&&n.slice(0,e(n)+1).replace(t,"")}return Qs=r,Qs}var ec,Wp;function K1(){if(Wp)return ec;Wp=1;var e=H1(),t=mr(),r=vt(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,a=/^0o[0-7]+$/i,s=parseInt;function u(c){if(typeof c=="number")return c;if(r(c))return n;if(t(c)){var l=typeof c.valueOf=="function"?c.valueOf():c;c=t(l)?l+"":l}if(typeof c!="string")return c===0?c:+c;c=e(c);var d=i.test(c);return d||a.test(c)?s(c.slice(2),d?2:8):o.test(c)?n:+c}return ec=u,ec}var rc,Gp;function _m(){if(Gp)return rc;Gp=1;var e=K1(),t=1/0,r=17976931348623157e292;function n(o){if(!o)return o===0?o:0;if(o=e(o),o===t||o===-t){var i=o<0?-1:1;return i*r}return o===o?o:0}return rc=n,rc}var tc,Up;function Z1(){if(Up)return tc;Up=1;var e=_m();function t(r){var n=e(r),o=n%1;return n===n?o?n-o:n:0}return tc=t,tc}var nc,Hp;function J1(){if(Hp)return nc;Hp=1;var e=gm(),t=Nr(),r=Z1(),n=Math.max;function o(i,a,s){var u=i==null?0:i.length;if(!u)return-1;var c=s==null?0:r(s);return c<0&&(c=n(u+c,0)),e(i,t(a,3),c)}return nc=o,nc}var oc,Kp;function Y1(){if(Kp)return oc;Kp=1;var e=G1(),t=J1(),r=e(t);return oc=r,oc}var ic,Zp;function Sm(){if(Zp)return ic;Zp=1;var e=Qu();function t(r){var n=r==null?0:r.length;return n?e(r,1):[]}return ic=t,ic}var ac,Jp;function X1(){if(Jp)return ac;Jp=1;var e=Zu(),t=Kb(),r=tt();function n(o,i){return o==null?o:e(o,t(i),r)}return ac=n,ac}var sc,Yp;function Q1(){if(Yp)return sc;Yp=1;function e(t){var r=t==null?0:t.length;return r?t[r-1]:void 0}return sc=e,sc}var cc,Xp;function eC(){if(Xp)return cc;Xp=1;var e=kn(),t=Ju(),r=Nr();function n(o,i){var a={};return i=r(i,3),t(o,function(s,u,c){e(a,u,i(s,u,c))}),a}return cc=n,cc}var uc,Qp;function rl(){if(Qp)return uc;Qp=1;var e=vt();function t(r,n,o){for(var i=-1,a=r.length;++i<a;){var s=r[i],u=n(s);if(u!=null&&(c===void 0?u===u&&!e(u):o(u,c)))var c=u,l=s}return l}return uc=t,uc}var lc,eg;function rC(){if(eg)return lc;eg=1;function e(t,r){return t>r}return lc=e,lc}var dc,rg;function tC(){if(rg)return dc;rg=1;var e=rl(),t=rC(),r=nt();function n(o){return o&&o.length?e(o,r,t):void 0}return dc=n,dc}var fc,tg;function jm(){if(tg)return fc;tg=1;var e=kn(),t=gt();function r(n,o,i){(i!==void 0&&!t(n[o],i)||i===void 0&&!(o in n))&&e(n,o,i)}return fc=r,fc}var hc,ng;function nC(){if(ng)return hc;ng=1;var e=et(),t=In(),r=Pr(),n="[object Object]",o=Function.prototype,i=Object.prototype,a=o.toString,s=i.hasOwnProperty,u=a.call(Object);function c(l){if(!r(l)||e(l)!=n)return!1;var d=t(l);if(d===null)return!0;var f=s.call(d,"constructor")&&d.constructor;return typeof f=="function"&&f instanceof f&&a.call(f)==u}return hc=c,hc}var pc,og;function Em(){if(og)return pc;og=1;function e(t,r){if(!(r==="constructor"&&typeof t[r]=="function")&&r!="__proto__")return t[r]}return pc=e,pc}var gc,ig;function oC(){if(ig)return gc;ig=1;var e=Xt(),t=tt();function r(n){return e(n,t(n))}return gc=r,gc}var yc,ag;function iC(){if(ag)return yc;ag=1;var e=jm(),t=qb(),r=Wb(),n=Nb(),o=Ub(),i=Qt(),a=Ke(),s=ym(),u=bt(),c=Yt(),l=mr(),d=nC(),f=en(),p=Em(),b=oC();function y(m,x,g,w,v,_,C){var S=p(m,g),T=p(x,g),k=C.get(T);if(k){e(m,g,k);return}var j=_?_(S,T,g+"",m,x,C):void 0,P=j===void 0;if(P){var R=a(T),I=!R&&u(T),O=!R&&!I&&f(T);j=T,R||I||O?a(S)?j=S:s(S)?j=n(S):I?(P=!1,j=t(T,!0)):O?(P=!1,j=r(T,!0)):j=[]:d(T)||i(T)?(j=S,i(S)?j=b(S):(!l(S)||c(S))&&(j=o(T))):P=!1}P&&(C.set(T,j),v(j,T,w,_,C),C.delete(T)),e(m,g,j)}return yc=y,yc}var bc,sg;function aC(){if(sg)return bc;sg=1;var e=Rn(),t=jm(),r=Zu(),n=iC(),o=mr(),i=tt(),a=Em();function s(u,c,l,d,f){u!==c&&r(c,function(p,b){if(f||(f=new e),o(p))n(u,c,b,l,s,d,f);else{var y=d?d(a(u,b),p,b+"",u,c,f):void 0;y===void 0&&(y=p),t(u,b,y)}},i)}return bc=s,bc}var mc,cg;function sC(){if(cg)return mc;cg=1;var e=Ln(),t=Fn();function r(n){return e(function(o,i){var a=-1,s=i.length,u=s>1?i[s-1]:void 0,c=s>2?i[2]:void 0;for(u=n.length>3&&typeof u=="function"?(s--,u):void 0,c&&t(i[0],i[1],c)&&(u=s<3?void 0:u,s=1),o=Object(o);++a<s;){var l=i[a];l&&n(o,l,a,u)}return o})}return mc=r,mc}var vc,ug;function cC(){if(ug)return vc;ug=1;var e=aC(),t=sC(),r=t(function(n,o,i){e(n,o,i)});return vc=r,vc}var xc,lg;function Rm(){if(lg)return xc;lg=1;function e(t,r){return t<r}return xc=e,xc}var wc,dg;function uC(){if(dg)return wc;dg=1;var e=rl(),t=Rm(),r=nt();function n(o){return o&&o.length?e(o,r,t):void 0}return wc=n,wc}var Cc,fg;function lC(){if(fg)return Cc;fg=1;var e=rl(),t=Nr(),r=Rm();function n(o,i){return o&&o.length?e(o,t(i,2),r):void 0}return Cc=n,Cc}var _c,hg;function dC(){if(hg)return _c;hg=1;var e=Sr(),t=function(){return e.Date.now()};return _c=t,_c}var Sc,pg;function fC(){if(pg)return Sc;pg=1;var e=Pn(),t=Nn(),r=An(),n=mr(),o=rn();function i(a,s,u,c){if(!n(a))return a;s=t(s,a);for(var l=-1,d=s.length,f=d-1,p=a;p!=null&&++l<d;){var b=o(s[l]),y=u;if(b==="__proto__"||b==="constructor"||b==="prototype")return a;if(l!=f){var m=p[b];y=c?c(m,b,p):void 0,y===void 0&&(y=n(m)?m:r(s[l+1])?[]:{})}e(p,b,y),p=p[b]}return a}return Sc=i,Sc}var jc,gg;function hC(){if(gg)return jc;gg=1;var e=$n(),t=fC(),r=Nn();function n(o,i,a){for(var s=-1,u=i.length,c={};++s<u;){var l=i[s],d=e(o,l);a(d,l)&&t(c,r(l,o),d)}return c}return jc=n,jc}var Ec,yg;function pC(){if(yg)return Ec;yg=1;var e=hC(),t=im();function r(n,o){return e(n,o,function(i,a){return t(n,a)})}return Ec=r,Ec}var Rc,bg;function gC(){if(bg)return Rc;bg=1;var e=Sm(),t=hm(),r=pm();function n(o){return r(t(o,void 0,e),o+"")}return Rc=n,Rc}var kc,mg;function yC(){if(mg)return kc;mg=1;var e=pC(),t=gC(),r=t(function(n,o){return n==null?{}:e(n,o)});return kc=r,kc}var Pc,vg;function bC(){if(vg)return Pc;vg=1;var e=Math.ceil,t=Math.max;function r(n,o,i,a){for(var s=-1,u=t(e((o-n)/(i||1)),0),c=Array(u);u--;)c[a?u:++s]=n,n+=i;return c}return Pc=r,Pc}var Ac,xg;function mC(){if(xg)return Ac;xg=1;var e=bC(),t=Fn(),r=_m();function n(o){return function(i,a,s){return s&&typeof s!="number"&&t(i,a,s)&&(a=s=void 0),i=r(i),a===void 0?(a=i,i=0):a=r(a),s=s===void 0?i<a?1:-1:r(s),e(i,a,s,o)}}return Ac=n,Ac}var Tc,wg;function vC(){if(wg)return Tc;wg=1;var e=mC(),t=e();return Tc=t,Tc}var Oc,Cg;function xC(){if(Cg)return Oc;Cg=1;function e(t,r){var n=t.length;for(t.sort(r);n--;)t[n]=t[n].value;return t}return Oc=e,Oc}var Ic,_g;function wC(){if(_g)return Ic;_g=1;var e=vt();function t(r,n){if(r!==n){var o=r!==void 0,i=r===null,a=r===r,s=e(r),u=n!==void 0,c=n===null,l=n===n,d=e(n);if(!c&&!d&&!s&&r>n||s&&u&&l&&!c&&!d||i&&u&&l||!o&&l||!a)return 1;if(!i&&!s&&!d&&r<n||d&&o&&a&&!i&&!s||c&&o&&a||!u&&a||!l)return-1}return 0}return Ic=t,Ic}var Mc,Sg;function CC(){if(Sg)return Mc;Sg=1;var e=wC();function t(r,n,o){for(var i=-1,a=r.criteria,s=n.criteria,u=a.length,c=o.length;++i<u;){var l=e(a[i],s[i]);if(l){if(i>=c)return l;var d=o[i];return l*(d=="desc"?-1:1)}}return r.index-n.index}return Mc=t,Mc}var qc,jg;function _C(){if(jg)return qc;jg=1;var e=qn(),t=$n(),r=Nr(),n=lm(),o=xC(),i=Tn(),a=CC(),s=nt(),u=Ke();function c(l,d,f){d.length?d=e(d,function(y){return u(y)?function(m){return t(m,y.length===1?y[0]:y)}:y}):d=[s];var p=-1;d=e(d,i(r));var b=n(l,function(y,m,x){var g=e(d,function(w){return w(y)});return{criteria:g,index:++p,value:y}});return o(b,function(y,m){return a(y,m,f)})}return qc=c,qc}var Nc,Eg;function SC(){if(Eg)return Nc;Eg=1;var e=Qu(),t=_C(),r=Ln(),n=Fn(),o=r(function(i,a){if(i==null)return[];var s=a.length;return s>1&&n(i,a[0],a[1])?a=[]:s>2&&n(a[0],a[1],a[2])&&(a=[a[0]]),t(i,e(a,1),[])});return Nc=o,Nc}var $c,Rg;function jC(){if(Rg)return $c;Rg=1;var e=nm(),t=0;function r(n){var o=++t;return e(n)+o}return $c=r,$c}var Lc,kg;function EC(){if(kg)return Lc;kg=1;function e(t,r,n){for(var o=-1,i=t.length,a=r.length,s={};++o<i;){var u=o<a?r[o]:void 0;n(s,t[o],u)}return s}return Lc=e,Lc}var Fc,Pg;function RC(){if(Pg)return Fc;Pg=1;var e=Pn(),t=EC();function r(n,o){return t(n||[],o||[],e)}return Fc=r,Fc}var Bc,Ag;function Be(){if(Ag)return Bc;Ag=1;var e;if(typeof Lu=="function")try{e={cloneDeep:V1(),constant:Ku(),defaults:W1(),each:Jb(),filter:sm(),find:Y1(),flatten:Sm(),forEach:Zb(),forIn:X1(),has:cm(),isUndefined:um(),last:Q1(),map:dm(),mapValues:eC(),max:tC(),merge:cC(),min:uC(),minBy:lC(),now:dC(),pick:yC(),range:vC(),reduce:fm(),sortBy:SC(),uniqueId:jC(),values:bm(),zipObject:RC()}}catch{}return e||(e=window._),Bc=e,Bc}var Dc,Tg;function kC(){if(Tg)return Dc;Tg=1,Dc=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 t(o),o},e.prototype.enqueue=function(n){var o=this._sentinel;n._prev&&n._next&&t(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,r)),i=i._prev;return"["+n.join(", ")+"]"};function t(n){n._prev._next=n._next,n._next._prev=n._prev,delete n._next,delete n._prev}function r(n,o){if(n!=="_next"&&n!=="_prev")return o}return Dc}var zc,Og;function PC(){if(Og)return zc;Og=1;var e=Be(),t=_r().Graph,r=kC();zc=o;var n=e.constant(1);function o(c,l){if(c.nodeCount()<=1)return[];var d=s(c,l||n),f=i(d.graph,d.buckets,d.zeroIdx);return e.flatten(e.map(f,function(p){return c.outEdges(p.v,p.w)}),!0)}function i(c,l,d){for(var f=[],p=l[l.length-1],b=l[0],y;c.nodeCount();){for(;y=b.dequeue();)a(c,l,d,y);for(;y=p.dequeue();)a(c,l,d,y);if(c.nodeCount()){for(var m=l.length-2;m>0;--m)if(y=l[m].dequeue(),y){f=f.concat(a(c,l,d,y,!0));break}}}return f}function a(c,l,d,f,p){var b=p?[]:void 0;return e.forEach(c.inEdges(f.v),function(y){var m=c.edge(y),x=c.node(y.v);p&&b.push({v:y.v,w:y.w}),x.out-=m,u(l,d,x)}),e.forEach(c.outEdges(f.v),function(y){var m=c.edge(y),x=y.w,g=c.node(x);g.in-=m,u(l,d,g)}),c.removeNode(f.v),b}function s(c,l){var d=new t,f=0,p=0;e.forEach(c.nodes(),function(m){d.setNode(m,{v:m,in:0,out:0})}),e.forEach(c.edges(),function(m){var x=d.edge(m.v,m.w)||0,g=l(m),w=x+g;d.setEdge(m.v,m.w,w),p=Math.max(p,d.node(m.v).out+=g),f=Math.max(f,d.node(m.w).in+=g)});var b=e.range(p+f+3).map(function(){return new r}),y=f+1;return e.forEach(d.nodes(),function(m){u(b,y,d.node(m))}),{graph:d,buckets:b,zeroIdx:y}}function u(c,l,d){d.out?d.in?c[d.out-d.in+l].enqueue(d):c[c.length-1].enqueue(d):c[0].enqueue(d)}return zc}var Vc,Ig;function AC(){if(Ig)return Vc;Ig=1;var e=Be(),t=PC();Vc={run:r,undo:o};function r(i){var a=i.graph().acyclicer==="greedy"?t(i,s(i)):n(i);e.forEach(a,function(u){var c=i.edge(u);i.removeEdge(u),c.forwardName=u.name,c.reversed=!0,i.setEdge(u.w,u.v,c,e.uniqueId("rev"))});function s(u){return function(c){return u.edge(c).weight}}}function n(i){var a=[],s={},u={};function c(l){e.has(u,l)||(u[l]=!0,s[l]=!0,e.forEach(i.outEdges(l),function(d){e.has(s,d.w)?a.push(d):c(d.w)}),delete s[l])}return e.forEach(i.nodes(),c),a}function o(i){e.forEach(i.edges(),function(a){var s=i.edge(a);if(s.reversed){i.removeEdge(a);var u=s.forwardName;delete s.reversed,delete s.forwardName,i.setEdge(a.w,a.v,s,u)}})}return Vc}var Wc,Mg;function lr(){if(Mg)return Wc;Mg=1;var e=Be(),t=_r().Graph;Wc={addDummyNode:r,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:a,intersectRect:s,buildLayerMatrix:u,normalizeRanks:c,removeEmptyRanks:l,addBorderNode:d,maxRank:f,partition:p,time:b,notime:y};function r(m,x,g,w){var v;do v=e.uniqueId(w);while(m.hasNode(v));return g.dummy=x,m.setNode(v,g),v}function n(m){var x=new t().setGraph(m.graph());return e.forEach(m.nodes(),function(g){x.setNode(g,m.node(g))}),e.forEach(m.edges(),function(g){var w=x.edge(g.v,g.w)||{weight:0,minlen:1},v=m.edge(g);x.setEdge(g.v,g.w,{weight:w.weight+v.weight,minlen:Math.max(w.minlen,v.minlen)})}),x}function o(m){var x=new t({multigraph:m.isMultigraph()}).setGraph(m.graph());return e.forEach(m.nodes(),function(g){m.children(g).length||x.setNode(g,m.node(g))}),e.forEach(m.edges(),function(g){x.setEdge(g,m.edge(g))}),x}function i(m){var x=e.map(m.nodes(),function(g){var w={};return e.forEach(m.outEdges(g),function(v){w[v.w]=(w[v.w]||0)+m.edge(v).weight}),w});return e.zipObject(m.nodes(),x)}function a(m){var x=e.map(m.nodes(),function(g){var w={};return e.forEach(m.inEdges(g),function(v){w[v.v]=(w[v.v]||0)+m.edge(v).weight}),w});return e.zipObject(m.nodes(),x)}function s(m,x){var g=m.x,w=m.y,v=x.x-g,_=x.y-w,C=m.width/2,S=m.height/2;if(!v&&!_)throw new Error("Not possible to find intersection inside of the rectangle");var T,k;return Math.abs(_)*C>Math.abs(v)*S?(_<0&&(S=-S),T=S*v/_,k=S):(v<0&&(C=-C),T=C,k=C*_/v),{x:g+T,y:w+k}}function u(m){var x=e.map(e.range(f(m)+1),function(){return[]});return e.forEach(m.nodes(),function(g){var w=m.node(g),v=w.rank;e.isUndefined(v)||(x[v][w.order]=g)}),x}function c(m){var x=e.min(e.map(m.nodes(),function(g){return m.node(g).rank}));e.forEach(m.nodes(),function(g){var w=m.node(g);e.has(w,"rank")&&(w.rank-=x)})}function l(m){var x=e.min(e.map(m.nodes(),function(_){return m.node(_).rank})),g=[];e.forEach(m.nodes(),function(_){var C=m.node(_).rank-x;g[C]||(g[C]=[]),g[C].push(_)});var w=0,v=m.graph().nodeRankFactor;e.forEach(g,function(_,C){e.isUndefined(_)&&C%v!==0?--w:w&&e.forEach(_,function(S){m.node(S).rank+=w})})}function d(m,x,g,w){var v={width:0,height:0};return arguments.length>=4&&(v.rank=g,v.order=w),r(m,"border",v,x)}function f(m){return e.max(e.map(m.nodes(),function(x){var g=m.node(x).rank;if(!e.isUndefined(g))return g}))}function p(m,x){var g={lhs:[],rhs:[]};return e.forEach(m,function(w){x(w)?g.lhs.push(w):g.rhs.push(w)}),g}function b(m,x){var g=e.now();try{return x()}finally{console.log(m+" time: "+(e.now()-g)+"ms")}}function y(m,x){return x()}return Wc}var Gc,qg;function TC(){if(qg)return Gc;qg=1;var e=Be(),t=lr();Gc={run:r,undo:o};function r(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(a){n(i,a)})}function n(i,a){var s=a.v,u=i.node(s).rank,c=a.w,l=i.node(c).rank,d=a.name,f=i.edge(a),p=f.labelRank;if(l!==u+1){i.removeEdge(a);var b,y,m;for(m=0,++u;u<l;++m,++u)f.points=[],y={width:0,height:0,edgeLabel:f,edgeObj:a,rank:u},b=t.addDummyNode(i,"edge",y,"_d"),u===p&&(y.width=f.width,y.height=f.height,y.dummy="edge-label",y.labelpos=f.labelpos),i.setEdge(s,b,{weight:f.weight},d),m===0&&i.graph().dummyChains.push(b),s=b;i.setEdge(s,c,{weight:f.weight},d)}}function o(i){e.forEach(i.graph().dummyChains,function(a){var s=i.node(a),u=s.edgeLabel,c;for(i.setEdge(s.edgeObj,u);s.dummy;)c=i.successors(a)[0],i.removeNode(a),u.points.push({x:s.x,y:s.y}),s.dummy==="edge-label"&&(u.x=s.x,u.y=s.y,u.width=s.width,u.height=s.height),a=c,s=i.node(a)})}return Gc}var Uc,Ng;function pn(){if(Ng)return Uc;Ng=1;var e=Be();Uc={longestPath:t,slack:r};function t(n){var o={};function i(a){var s=n.node(a);if(e.has(o,a))return s.rank;o[a]=!0;var u=e.min(e.map(n.outEdges(a),function(c){return i(c.w)-n.edge(c).minlen}));return(u===Number.POSITIVE_INFINITY||u===void 0||u===null)&&(u=0),s.rank=u}e.forEach(n.sources(),i)}function r(n,o){return n.node(o.w).rank-n.node(o.v).rank-n.edge(o).minlen}return Uc}var Hc,$g;function km(){if($g)return Hc;$g=1;var e=Be(),t=_r().Graph,r=pn().slack;Hc=n;function n(s){var u=new t({directed:!1}),c=s.nodes()[0],l=s.nodeCount();u.setNode(c,{});for(var d,f;o(u,s)<l;)d=i(u,s),f=u.hasNode(d.v)?r(s,d):-r(s,d),a(u,s,f);return u}function o(s,u){function c(l){e.forEach(u.nodeEdges(l),function(d){var f=d.v,p=l===f?d.w:f;!s.hasNode(p)&&!r(u,d)&&(s.setNode(p,{}),s.setEdge(l,p,{}),c(p))})}return e.forEach(s.nodes(),c),s.nodeCount()}function i(s,u){return e.minBy(u.edges(),function(c){if(s.hasNode(c.v)!==s.hasNode(c.w))return r(u,c)})}function a(s,u,c){e.forEach(s.nodes(),function(l){u.node(l).rank+=c})}return Hc}var Kc,Lg;function OC(){if(Lg)return Kc;Lg=1;var e=Be(),t=km(),r=pn().slack,n=pn().longestPath,o=_r().alg.preorder,i=_r().alg.postorder,a=lr().simplify;Kc=s,s.initLowLimValues=d,s.initCutValues=u,s.calcCutValue=l,s.leaveEdge=p,s.enterEdge=b,s.exchangeEdges=y;function s(w){w=a(w),n(w);var v=t(w);d(v),u(v,w);for(var _,C;_=p(v);)C=b(v,w,_),y(v,w,_,C)}function u(w,v){var _=i(w,w.nodes());_=_.slice(0,_.length-1),e.forEach(_,function(C){c(w,v,C)})}function c(w,v,_){var C=w.node(_),S=C.parent;w.edge(_,S).cutvalue=l(w,v,_)}function l(w,v,_){var C=w.node(_),S=C.parent,T=!0,k=v.edge(_,S),j=0;return k||(T=!1,k=v.edge(S,_)),j=k.weight,e.forEach(v.nodeEdges(_),function(P){var R=P.v===_,I=R?P.w:P.v;if(I!==S){var O=R===T,M=v.edge(P).weight;if(j+=O?M:-M,x(w,_,I)){var q=w.edge(_,I).cutvalue;j+=O?-q:q}}}),j}function d(w,v){arguments.length<2&&(v=w.nodes()[0]),f(w,{},1,v)}function f(w,v,_,C,S){var T=_,k=w.node(C);return v[C]=!0,e.forEach(w.neighbors(C),function(j){e.has(v,j)||(_=f(w,v,_,j,C))}),k.low=T,k.lim=_++,S?k.parent=S:delete k.parent,_}function p(w){return e.find(w.edges(),function(v){return w.edge(v).cutvalue<0})}function b(w,v,_){var C=_.v,S=_.w;v.hasEdge(C,S)||(C=_.w,S=_.v);var T=w.node(C),k=w.node(S),j=T,P=!1;T.lim>k.lim&&(j=k,P=!0);var R=e.filter(v.edges(),function(I){return P===g(w,w.node(I.v),j)&&P!==g(w,w.node(I.w),j)});return e.minBy(R,function(I){return r(v,I)})}function y(w,v,_,C){var S=_.v,T=_.w;w.removeEdge(S,T),w.setEdge(C.v,C.w,{}),d(w),u(w,v),m(w,v)}function m(w,v){var _=e.find(w.nodes(),function(S){return!v.node(S).parent}),C=o(w,_);C=C.slice(1),e.forEach(C,function(S){var T=w.node(S).parent,k=v.edge(S,T),j=!1;k||(k=v.edge(T,S),j=!0),v.node(S).rank=v.node(T).rank+(j?k.minlen:-k.minlen)})}function x(w,v,_){return w.hasEdge(v,_)}function g(w,v,_){return _.low<=v.lim&&v.lim<=_.lim}return Kc}var Zc,Fg;function IC(){if(Fg)return Zc;Fg=1;var e=pn(),t=e.longestPath,r=km(),n=OC();Zc=o;function o(u){switch(u.graph().ranker){case"network-simplex":s(u);break;case"tight-tree":a(u);break;case"longest-path":i(u);break;default:s(u)}}var i=t;function a(u){t(u),r(u)}function s(u){n(u)}return Zc}var Jc,Bg;function MC(){if(Bg)return Jc;Bg=1;var e=Be();Jc=t;function t(o){var i=n(o);e.forEach(o.graph().dummyChains,function(a){for(var s=o.node(a),u=s.edgeObj,c=r(o,i,u.v,u.w),l=c.path,d=c.lca,f=0,p=l[f],b=!0;a!==u.w;){if(s=o.node(a),b){for(;(p=l[f])!==d&&o.node(p).maxRank<s.rank;)f++;p===d&&(b=!1)}if(!b){for(;f<l.length-1&&o.node(p=l[f+1]).minRank<=s.rank;)f++;p=l[f]}o.setParent(a,p),a=o.successors(a)[0]}})}function r(o,i,a,s){var u=[],c=[],l=Math.min(i[a].low,i[s].low),d=Math.max(i[a].lim,i[s].lim),f,p;f=a;do f=o.parent(f),u.push(f);while(f&&(i[f].low>l||d>i[f].lim));for(p=f,f=s;(f=o.parent(f))!==p;)c.push(f);return{path:u.concat(c.reverse()),lca:p}}function n(o){var i={},a=0;function s(u){var c=a;e.forEach(o.children(u),s),i[u]={low:c,lim:a++}}return e.forEach(o.children(),s),i}return Jc}var Yc,Dg;function qC(){if(Dg)return Yc;Dg=1;var e=Be(),t=lr();Yc={run:r,cleanup:a};function r(s){var u=t.addDummyNode(s,"root",{},"_root"),c=o(s),l=e.max(e.values(c))-1,d=2*l+1;s.graph().nestingRoot=u,e.forEach(s.edges(),function(p){s.edge(p).minlen*=d});var f=i(s)+1;e.forEach(s.children(),function(p){n(s,u,d,f,l,c,p)}),s.graph().nodeRankFactor=d}function n(s,u,c,l,d,f,p){var b=s.children(p);if(!b.length){p!==u&&s.setEdge(u,p,{weight:0,minlen:c});return}var y=t.addBorderNode(s,"_bt"),m=t.addBorderNode(s,"_bb"),x=s.node(p);s.setParent(y,p),x.borderTop=y,s.setParent(m,p),x.borderBottom=m,e.forEach(b,function(g){n(s,u,c,l,d,f,g);var w=s.node(g),v=w.borderTop?w.borderTop:g,_=w.borderBottom?w.borderBottom:g,C=w.borderTop?l:2*l,S=v!==_?1:d-f[p]+1;s.setEdge(y,v,{weight:C,minlen:S,nestingEdge:!0}),s.setEdge(_,m,{weight:C,minlen:S,nestingEdge:!0})}),s.parent(p)||s.setEdge(u,y,{weight:0,minlen:d+f[p]})}function o(s){var u={};function c(l,d){var f=s.children(l);f&&f.length&&e.forEach(f,function(p){c(p,d+1)}),u[l]=d}return e.forEach(s.children(),function(l){c(l,1)}),u}function i(s){return e.reduce(s.edges(),function(u,c){return u+s.edge(c).weight},0)}function a(s){var u=s.graph();s.removeNode(u.nestingRoot),delete u.nestingRoot,e.forEach(s.edges(),function(c){var l=s.edge(c);l.nestingEdge&&s.removeEdge(c)})}return Yc}var Xc,zg;function NC(){if(zg)return Xc;zg=1;var e=Be(),t=lr();Xc=r;function r(o){function i(a){var s=o.children(a),u=o.node(a);if(s.length&&e.forEach(s,i),e.has(u,"minRank")){u.borderLeft=[],u.borderRight=[];for(var c=u.minRank,l=u.maxRank+1;c<l;++c)n(o,"borderLeft","_bl",a,u,c),n(o,"borderRight","_br",a,u,c)}}e.forEach(o.children(),i)}function n(o,i,a,s,u,c){var l={width:0,height:0,rank:c,borderType:i},d=u[i][c-1],f=t.addDummyNode(o,"border",l,a);u[i][c]=f,o.setParent(f,s),d&&o.setEdge(d,f,{weight:1})}return Xc}var Qc,Vg;function $C(){if(Vg)return Qc;Vg=1;var e=Be();Qc={adjust:t,undo:r};function t(c){var l=c.graph().rankdir.toLowerCase();(l==="lr"||l==="rl")&&n(c)}function r(c){var l=c.graph().rankdir.toLowerCase();(l==="bt"||l==="rl")&&i(c),(l==="lr"||l==="rl")&&(s(c),n(c))}function n(c){e.forEach(c.nodes(),function(l){o(c.node(l))}),e.forEach(c.edges(),function(l){o(c.edge(l))})}function o(c){var l=c.width;c.width=c.height,c.height=l}function i(c){e.forEach(c.nodes(),function(l){a(c.node(l))}),e.forEach(c.edges(),function(l){var d=c.edge(l);e.forEach(d.points,a),e.has(d,"y")&&a(d)})}function a(c){c.y=-c.y}function s(c){e.forEach(c.nodes(),function(l){u(c.node(l))}),e.forEach(c.edges(),function(l){var d=c.edge(l);e.forEach(d.points,u),e.has(d,"x")&&u(d)})}function u(c){var l=c.x;c.x=c.y,c.y=l}return Qc}var eu,Wg;function LC(){if(Wg)return eu;Wg=1;var e=Be();eu=t;function t(r){var n={},o=e.filter(r.nodes(),function(c){return!r.children(c).length}),i=e.max(e.map(o,function(c){return r.node(c).rank})),a=e.map(e.range(i+1),function(){return[]});function s(c){if(!e.has(n,c)){n[c]=!0;var l=r.node(c);a[l.rank].push(c),e.forEach(r.successors(c),s)}}var u=e.sortBy(o,function(c){return r.node(c).rank});return e.forEach(u,s),a}return eu}var ru,Gg;function FC(){if(Gg)return ru;Gg=1;var e=Be();ru=t;function t(n,o){for(var i=0,a=1;a<o.length;++a)i+=r(n,o[a-1],o[a]);return i}function r(n,o,i){for(var a=e.zipObject(i,e.map(i,function(f,p){return p})),s=e.flatten(e.map(o,function(f){return e.sortBy(e.map(n.outEdges(f),function(p){return{pos:a[p.w],weight:n.edge(p).weight}}),"pos")}),!0),u=1;u<i.length;)u<<=1;var c=2*u-1;u-=1;var l=e.map(new Array(c),function(){return 0}),d=0;return e.forEach(s.forEach(function(f){var p=f.pos+u;l[p]+=f.weight;for(var b=0;p>0;)p%2&&(b+=l[p+1]),p=p-1>>1,l[p]+=f.weight;d+=f.weight*b})),d}return ru}var tu,Ug;function BC(){if(Ug)return tu;Ug=1;var e=Be();tu=t;function t(r,n){return e.map(n,function(o){var i=r.inEdges(o);if(i.length){var a=e.reduce(i,function(s,u){var c=r.edge(u),l=r.node(u.v);return{sum:s.sum+c.weight*l.order,weight:s.weight+c.weight}},{sum:0,weight:0});return{v:o,barycenter:a.sum/a.weight,weight:a.weight}}else return{v:o}})}return tu}var nu,Hg;function DC(){if(Hg)return nu;Hg=1;var e=Be();nu=t;function t(o,i){var a={};e.forEach(o,function(u,c){var l=a[u.v]={indegree:0,in:[],out:[],vs:[u.v],i:c};e.isUndefined(u.barycenter)||(l.barycenter=u.barycenter,l.weight=u.weight)}),e.forEach(i.edges(),function(u){var c=a[u.v],l=a[u.w];!e.isUndefined(c)&&!e.isUndefined(l)&&(l.indegree++,c.out.push(a[u.w]))});var s=e.filter(a,function(u){return!u.indegree});return r(s)}function r(o){var i=[];function a(c){return function(l){l.merged||(e.isUndefined(l.barycenter)||e.isUndefined(c.barycenter)||l.barycenter>=c.barycenter)&&n(c,l)}}function s(c){return function(l){l.in.push(c),--l.indegree===0&&o.push(l)}}for(;o.length;){var u=o.pop();i.push(u),e.forEach(u.in.reverse(),a(u)),e.forEach(u.out,s(u))}return e.map(e.filter(i,function(c){return!c.merged}),function(c){return e.pick(c,["vs","i","barycenter","weight"])})}function n(o,i){var a=0,s=0;o.weight&&(a+=o.barycenter*o.weight,s+=o.weight),i.weight&&(a+=i.barycenter*i.weight,s+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=a/s,o.weight=s,o.i=Math.min(i.i,o.i),i.merged=!0}return nu}var ou,Kg;function zC(){if(Kg)return ou;Kg=1;var e=Be(),t=lr();ou=r;function r(i,a){var s=t.partition(i,function(y){return e.has(y,"barycenter")}),u=s.lhs,c=e.sortBy(s.rhs,function(y){return-y.i}),l=[],d=0,f=0,p=0;u.sort(o(!!a)),p=n(l,c,p),e.forEach(u,function(y){p+=y.vs.length,l.push(y.vs),d+=y.barycenter*y.weight,f+=y.weight,p=n(l,c,p)});var b={vs:e.flatten(l,!0)};return f&&(b.barycenter=d/f,b.weight=f),b}function n(i,a,s){for(var u;a.length&&(u=e.last(a)).i<=s;)a.pop(),i.push(u.vs),s++;return s}function o(i){return function(a,s){return a.barycenter<s.barycenter?-1:a.barycenter>s.barycenter?1:i?s.i-a.i:a.i-s.i}}return ou}var iu,Zg;function VC(){if(Zg)return iu;Zg=1;var e=Be(),t=BC(),r=DC(),n=zC();iu=o;function o(s,u,c,l){var d=s.children(u),f=s.node(u),p=f?f.borderLeft:void 0,b=f?f.borderRight:void 0,y={};p&&(d=e.filter(d,function(_){return _!==p&&_!==b}));var m=t(s,d);e.forEach(m,function(_){if(s.children(_.v).length){var C=o(s,_.v,c,l);y[_.v]=C,e.has(C,"barycenter")&&a(_,C)}});var x=r(m,c);i(x,y);var g=n(x,l);if(p&&(g.vs=e.flatten([p,g.vs,b],!0),s.predecessors(p).length)){var w=s.node(s.predecessors(p)[0]),v=s.node(s.predecessors(b)[0]);e.has(g,"barycenter")||(g.barycenter=0,g.weight=0),g.barycenter=(g.barycenter*g.weight+w.order+v.order)/(g.weight+2),g.weight+=2}return g}function i(s,u){e.forEach(s,function(c){c.vs=e.flatten(c.vs.map(function(l){return u[l]?u[l].vs:l}),!0)})}function a(s,u){e.isUndefined(s.barycenter)?(s.barycenter=u.barycenter,s.weight=u.weight):(s.barycenter=(s.barycenter*s.weight+u.barycenter*u.weight)/(s.weight+u.weight),s.weight+=u.weight)}return iu}var au,Jg;function WC(){if(Jg)return au;Jg=1;var e=Be(),t=_r().Graph;au=r;function r(o,i,a){var s=n(o),u=new t({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(function(c){return o.node(c)});return e.forEach(o.nodes(),function(c){var l=o.node(c),d=o.parent(c);(l.rank===i||l.minRank<=i&&i<=l.maxRank)&&(u.setNode(c),u.setParent(c,d||s),e.forEach(o[a](c),function(f){var p=f.v===c?f.w:f.v,b=u.edge(p,c),y=e.isUndefined(b)?0:b.weight;u.setEdge(p,c,{weight:o.edge(f).weight+y})}),e.has(l,"minRank")&&u.setNode(c,{borderLeft:l.borderLeft[i],borderRight:l.borderRight[i]}))}),u}function n(o){for(var i;o.hasNode(i=e.uniqueId("_root")););return i}return au}var su,Yg;function GC(){if(Yg)return su;Yg=1;var e=Be();su=t;function t(r,n,o){var i={},a;e.forEach(o,function(s){for(var u=r.parent(s),c,l;u;){if(c=r.parent(u),c?(l=i[c],i[c]=u):(l=a,a=u),l&&l!==u){n.setEdge(l,u);return}u=c}})}return su}var cu,Xg;function UC(){if(Xg)return cu;Xg=1;var e=Be(),t=LC(),r=FC(),n=VC(),o=WC(),i=GC(),a=_r().Graph,s=lr();cu=u;function u(f){var p=s.maxRank(f),b=c(f,e.range(1,p+1),"inEdges"),y=c(f,e.range(p-1,-1,-1),"outEdges"),m=t(f);d(f,m);for(var x=Number.POSITIVE_INFINITY,g,w=0,v=0;v<4;++w,++v){l(w%2?b:y,w%4>=2),m=s.buildLayerMatrix(f);var _=r(f,m);_<x&&(v=0,g=e.cloneDeep(m),x=_)}d(f,g)}function c(f,p,b){return e.map(p,function(y){return o(f,y,b)})}function l(f,p){var b=new a;e.forEach(f,function(y){var m=y.graph().root,x=n(y,m,b,p);e.forEach(x.vs,function(g,w){y.node(g).order=w}),i(y,b,x.vs)})}function d(f,p){e.forEach(p,function(b){e.forEach(b,function(y,m){f.node(y).order=m})})}return cu}var uu,Qg;function HC(){if(Qg)return uu;Qg=1;var e=Be(),t=_r().Graph,r=lr();uu={positionX:b,findType1Conflicts:n,findType2Conflicts:o,addConflict:a,hasConflict:s,verticalAlignment:u,horizontalCompaction:c,alignCoordinates:f,findSmallestWidthAlignment:d,balance:p};function n(x,g){var w={};function v(_,C){var S=0,T=0,k=_.length,j=e.last(C);return e.forEach(C,function(P,R){var I=i(x,P),O=I?x.node(I).order:k;(I||P===j)&&(e.forEach(C.slice(T,R+1),function(M){e.forEach(x.predecessors(M),function(q){var H=x.node(q),V=H.order;(V<S||O<V)&&!(H.dummy&&x.node(M).dummy)&&a(w,q,M)})}),T=R+1,S=O)}),C}return e.reduce(g,v),w}function o(x,g){var w={};function v(C,S,T,k,j){var P;e.forEach(e.range(S,T),function(R){P=C[R],x.node(P).dummy&&e.forEach(x.predecessors(P),function(I){var O=x.node(I);O.dummy&&(O.order<k||O.order>j)&&a(w,I,P)})})}function _(C,S){var T=-1,k,j=0;return e.forEach(S,function(P,R){if(x.node(P).dummy==="border"){var I=x.predecessors(P);I.length&&(k=x.node(I[0]).order,v(S,j,R,T,k),j=R,T=k)}v(S,j,S.length,k,C.length)}),S}return e.reduce(g,_),w}function i(x,g){if(x.node(g).dummy)return e.find(x.predecessors(g),function(w){return x.node(w).dummy})}function a(x,g,w){if(g>w){var v=g;g=w,w=v}var _=x[g];_||(x[g]=_={}),_[w]=!0}function s(x,g,w){if(g>w){var v=g;g=w,w=v}return e.has(x[g],w)}function u(x,g,w,v){var _={},C={},S={};return e.forEach(g,function(T){e.forEach(T,function(k,j){_[k]=k,C[k]=k,S[k]=j})}),e.forEach(g,function(T){var k=-1;e.forEach(T,function(j){var P=v(j);if(P.length){P=e.sortBy(P,function(q){return S[q]});for(var R=(P.length-1)/2,I=Math.floor(R),O=Math.ceil(R);I<=O;++I){var M=P[I];C[j]===j&&k<S[M]&&!s(w,j,M)&&(C[M]=j,C[j]=_[j]=_[M],k=S[M])}}})}),{root:_,align:C}}function c(x,g,w,v,_){var C={},S=l(x,g,w,_),T=_?"borderLeft":"borderRight";function k(R,I){for(var O=S.nodes(),M=O.pop(),q={};M;)q[M]?R(M):(q[M]=!0,O.push(M),O=O.concat(I(M))),M=O.pop()}function j(R){C[R]=S.inEdges(R).reduce(function(I,O){return Math.max(I,C[O.v]+S.edge(O))},0)}function P(R){var I=S.outEdges(R).reduce(function(M,q){return Math.min(M,C[q.w]-S.edge(q))},Number.POSITIVE_INFINITY),O=x.node(R);I!==Number.POSITIVE_INFINITY&&O.borderType!==T&&(C[R]=Math.max(C[R],I))}return k(j,S.predecessors.bind(S)),k(P,S.successors.bind(S)),e.forEach(v,function(R){C[R]=C[w[R]]}),C}function l(x,g,w,v){var _=new t,C=x.graph(),S=y(C.nodesep,C.edgesep,v);return e.forEach(g,function(T){var k;e.forEach(T,function(j){var P=w[j];if(_.setNode(P),k){var R=w[k],I=_.edge(R,P);_.setEdge(R,P,Math.max(S(x,j,k),I||0))}k=j})}),_}function d(x,g){return e.minBy(e.values(g),function(w){var v=Number.NEGATIVE_INFINITY,_=Number.POSITIVE_INFINITY;return e.forIn(w,function(C,S){var T=m(x,S)/2;v=Math.max(C+T,v),_=Math.min(C-T,_)}),v-_})}function f(x,g){var w=e.values(g),v=e.min(w),_=e.max(w);e.forEach(["u","d"],function(C){e.forEach(["l","r"],function(S){var T=C+S,k=x[T],j;if(k!==g){var P=e.values(k);j=S==="l"?v-e.min(P):_-e.max(P),j&&(x[T]=e.mapValues(k,function(R){return R+j}))}})})}function p(x,g){return e.mapValues(x.ul,function(w,v){if(g)return x[g.toLowerCase()][v];var _=e.sortBy(e.map(x,v));return(_[1]+_[2])/2})}function b(x){var g=r.buildLayerMatrix(x),w=e.merge(n(x,g),o(x,g)),v={},_;e.forEach(["u","d"],function(S){_=S==="u"?g:e.values(g).reverse(),e.forEach(["l","r"],function(T){T==="r"&&(_=e.map(_,function(R){return e.values(R).reverse()}));var k=(S==="u"?x.predecessors:x.successors).bind(x),j=u(x,_,w,k),P=c(x,_,j.root,j.align,T==="r");T==="r"&&(P=e.mapValues(P,function(R){return-R})),v[S+T]=P})});var C=d(x,v);return f(v,C),p(v,x.graph().align)}function y(x,g,w){return function(v,_,C){var S=v.node(_),T=v.node(C),k=0,j;if(k+=S.width/2,e.has(S,"labelpos"))switch(S.labelpos.toLowerCase()){case"l":j=-S.width/2;break;case"r":j=S.width/2;break}if(j&&(k+=w?j:-j),j=0,k+=(S.dummy?g:x)/2,k+=(T.dummy?g:x)/2,k+=T.width/2,e.has(T,"labelpos"))switch(T.labelpos.toLowerCase()){case"l":j=T.width/2;break;case"r":j=-T.width/2;break}return j&&(k+=w?j:-j),j=0,k}}function m(x,g){return x.node(g).width}return uu}var lu,ey;function KC(){if(ey)return lu;ey=1;var e=Be(),t=lr(),r=HC().positionX;lu=n;function n(i){i=t.asNonCompoundGraph(i),o(i),e.forEach(r(i),function(a,s){i.node(s).x=a})}function o(i){var a=t.buildLayerMatrix(i),s=i.graph().ranksep,u=0;e.forEach(a,function(c){var l=e.max(e.map(c,function(d){return i.node(d).height}));e.forEach(c,function(d){i.node(d).y=u+l/2}),u+=l+s})}return lu}var du,ry;function ZC(){if(ry)return du;ry=1;var e=Be(),t=AC(),r=TC(),n=IC(),o=lr().normalizeRanks,i=MC(),a=lr().removeEmptyRanks,s=qC(),u=NC(),c=$C(),l=UC(),d=KC(),f=lr(),p=_r().Graph;du=b;function b(N,B){var W=B&&B.debugTiming?f.time:f.notime;W("layout",function(){var z=W(" buildLayoutGraph",function(){return k(N)});W(" runLayout",function(){y(z,W)}),W(" updateInputGraph",function(){m(N,z)})})}function y(N,B){B(" makeSpaceForEdgeLabels",function(){j(N)}),B(" removeSelfEdges",function(){re(N)}),B(" acyclic",function(){t.run(N)}),B(" nestingGraph.run",function(){s.run(N)}),B(" rank",function(){n(f.asNonCompoundGraph(N))}),B(" injectEdgeLabelProxies",function(){P(N)}),B(" removeEmptyRanks",function(){a(N)}),B(" nestingGraph.cleanup",function(){s.cleanup(N)}),B(" normalizeRanks",function(){o(N)}),B(" assignRankMinMax",function(){R(N)}),B(" removeEdgeLabelProxies",function(){I(N)}),B(" normalize.run",function(){r.run(N)}),B(" parentDummyChains",function(){i(N)}),B(" addBorderSegments",function(){u(N)}),B(" order",function(){l(N)}),B(" insertSelfEdges",function(){ce(N)}),B(" adjustCoordinateSystem",function(){c.adjust(N)}),B(" position",function(){d(N)}),B(" positionSelfEdges",function(){le(N)}),B(" removeBorderNodes",function(){V(N)}),B(" normalize.undo",function(){r.undo(N)}),B(" fixupEdgeLabelCoords",function(){q(N)}),B(" undoCoordinateSystem",function(){c.undo(N)}),B(" translateGraph",function(){O(N)}),B(" assignNodeIntersects",function(){M(N)}),B(" reversePoints",function(){H(N)}),B(" acyclic.undo",function(){t.undo(N)})}function m(N,B){e.forEach(N.nodes(),function(W){var z=N.node(W),X=B.node(W);z&&(z.x=X.x,z.y=X.y,B.children(W).length&&(z.width=X.width,z.height=X.height))}),e.forEach(N.edges(),function(W){var z=N.edge(W),X=B.edge(W);z.points=X.points,e.has(X,"x")&&(z.x=X.x,z.y=X.y)}),N.graph().width=B.graph().width,N.graph().height=B.graph().height}var x=["nodesep","edgesep","ranksep","marginx","marginy"],g={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},w=["acyclicer","ranker","rankdir","align"],v=["width","height"],_={width:0,height:0},C=["minlen","weight","width","height","labeloffset"],S={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},T=["labelpos"];function k(N){var B=new p({multigraph:!0,compound:!0}),W=K(N.graph());return B.setGraph(e.merge({},g,be(W,x),e.pick(W,w))),e.forEach(N.nodes(),function(z){var X=K(N.node(z));B.setNode(z,e.defaults(be(X,v),_)),B.setParent(z,N.parent(z))}),e.forEach(N.edges(),function(z){var X=K(N.edge(z));B.setEdge(z,e.merge({},S,be(X,C),e.pick(X,T)))}),B}function j(N){var B=N.graph();B.ranksep/=2,e.forEach(N.edges(),function(W){var z=N.edge(W);z.minlen*=2,z.labelpos.toLowerCase()!=="c"&&(B.rankdir==="TB"||B.rankdir==="BT"?z.width+=z.labeloffset:z.height+=z.labeloffset)})}function P(N){e.forEach(N.edges(),function(B){var W=N.edge(B);if(W.width&&W.height){var z=N.node(B.v),X=N.node(B.w),se={rank:(X.rank-z.rank)/2+z.rank,e:B};f.addDummyNode(N,"edge-proxy",se,"_ep")}})}function R(N){var B=0;e.forEach(N.nodes(),function(W){var z=N.node(W);z.borderTop&&(z.minRank=N.node(z.borderTop).rank,z.maxRank=N.node(z.borderBottom).rank,B=e.max(B,z.maxRank))}),N.graph().maxRank=B}function I(N){e.forEach(N.nodes(),function(B){var W=N.node(B);W.dummy==="edge-proxy"&&(N.edge(W.e).labelRank=W.rank,N.removeNode(B))})}function O(N){var B=Number.POSITIVE_INFINITY,W=0,z=Number.POSITIVE_INFINITY,X=0,se=N.graph(),Q=se.marginx||0,G=se.marginy||0;function J(te){var de=te.x,fe=te.y,Ee=te.width,ge=te.height;B=Math.min(B,de-Ee/2),W=Math.max(W,de+Ee/2),z=Math.min(z,fe-ge/2),X=Math.max(X,fe+ge/2)}e.forEach(N.nodes(),function(te){J(N.node(te))}),e.forEach(N.edges(),function(te){var de=N.edge(te);e.has(de,"x")&&J(de)}),B-=Q,z-=G,e.forEach(N.nodes(),function(te){var de=N.node(te);de.x-=B,de.y-=z}),e.forEach(N.edges(),function(te){var de=N.edge(te);e.forEach(de.points,function(fe){fe.x-=B,fe.y-=z}),e.has(de,"x")&&(de.x-=B),e.has(de,"y")&&(de.y-=z)}),se.width=W-B+Q,se.height=X-z+G}function M(N){e.forEach(N.edges(),function(B){var W=N.edge(B),z=N.node(B.v),X=N.node(B.w),se,Q;W.points?(se=W.points[0],Q=W.points[W.points.length-1]):(W.points=[],se=X,Q=z),W.points.unshift(f.intersectRect(z,se)),W.points.push(f.intersectRect(X,Q))})}function q(N){e.forEach(N.edges(),function(B){var W=N.edge(B);if(e.has(W,"x"))switch((W.labelpos==="l"||W.labelpos==="r")&&(W.width-=W.labeloffset),W.labelpos){case"l":W.x-=W.width/2+W.labeloffset;break;case"r":W.x+=W.width/2+W.labeloffset;break}})}function H(N){e.forEach(N.edges(),function(B){var W=N.edge(B);W.reversed&&W.points.reverse()})}function V(N){e.forEach(N.nodes(),function(B){if(N.children(B).length){var W=N.node(B),z=N.node(W.borderTop),X=N.node(W.borderBottom),se=N.node(e.last(W.borderLeft)),Q=N.node(e.last(W.borderRight));W.width=Math.abs(Q.x-se.x),W.height=Math.abs(X.y-z.y),W.x=se.x+W.width/2,W.y=z.y+W.height/2}}),e.forEach(N.nodes(),function(B){N.node(B).dummy==="border"&&N.removeNode(B)})}function re(N){e.forEach(N.edges(),function(B){if(B.v===B.w){var W=N.node(B.v);W.selfEdges||(W.selfEdges=[]),W.selfEdges.push({e:B,label:N.edge(B)}),N.removeEdge(B)}})}function ce(N){var B=f.buildLayerMatrix(N);e.forEach(B,function(W){var z=0;e.forEach(W,function(X,se){var Q=N.node(X);Q.order=se+z,e.forEach(Q.selfEdges,function(G){f.addDummyNode(N,"selfedge",{width:G.label.width,height:G.label.height,rank:Q.rank,order:se+ ++z,e:G.e,label:G.label},"_se")}),delete Q.selfEdges})})}function le(N){e.forEach(N.nodes(),function(B){var W=N.node(B);if(W.dummy==="selfedge"){var z=N.node(W.e.v),X=z.x+z.width/2,se=z.y,Q=W.x-X,G=z.height/2;N.setEdge(W.e,W.label),N.removeNode(B),W.label.points=[{x:X+2*Q/3,y:se-G},{x:X+5*Q/6,y:se-G},{x:X+Q,y:se},{x:X+5*Q/6,y:se+G},{x:X+2*Q/3,y:se+G}],W.label.x=W.x,W.label.y=W.y}})}function be(N,B){return e.mapValues(e.pick(N,B),Number)}function K(N){var B={};return e.forEach(N,function(W,z){B[z.toLowerCase()]=W}),B}return du}var fu,ty;function JC(){if(ty)return fu;ty=1;var e=Be(),t=lr(),r=_r().Graph;fu={debugOrdering:n};function n(o){var i=t.buildLayerMatrix(o),a=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(s){a.setNode(s,{label:s}),a.setParent(s,"layer"+o.node(s).rank)}),e.forEach(o.edges(),function(s){a.setEdge(s.v,s.w,{},s.name)}),e.forEach(i,function(s,u){var c="layer"+u;a.setNode(c,{rank:"same"}),e.reduce(s,function(l,d){return a.setEdge(l,d,{style:"invis"}),d})}),a}return fu}var hu,ny;function YC(){return ny||(ny=1,hu="0.8.5"),hu}var pu,oy;function XC(){return oy||(oy=1,pu={graphlib:_r(),layout:ZC(),debug:JC(),util:{time:lr().time,notime:lr().notime},version:YC()}),pu}var QC=XC();const iy=$0(QC);function e_(e,t,r){var l;const n=new Set(e.map(d=>d.id)),o=new Set;for(const d of e)d.parent&&n.has(d.parent)&&o.add(d.parent);const i=new iy.graphlib.Graph({multigraph:!0,compound:!0}),a=r.compactSpacingScale??(r.spacingFactor>0?r.spacingFactor/1.3:1);i.setGraph({rankdir:r.rankDir,nodesep:r.compact?Math.max(r.nodeSep,24*a):r.nodeSep,edgesep:r.compact?Math.min(r.edgeSep,24*a):r.edgeSep,ranksep:r.compact?Math.min(r.rankSep,80*a):r.rankSep,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({})),i.setDefaultNodeLabel(()=>({}));for(const d of e)i.setNode(d.id,{width:d.width+2,height:d.height+2});for(const d of e)d.parent&&n.has(d.parent)&&i.setParent(d.id,d.parent);for(const d of t){if(!n.has(d.source)||!n.has(d.target)||o.has(d.source)||o.has(d.target))continue;const f=Rb(d.label,d.icon??((l=d.data)==null?void 0:l.icon),r.edgeLabelFontSize),p=r.rankDir==="LR"||r.rankDir==="RL",b=(f.width?f.width+2*Eb:0)+(d.connectorClearance??0);i.setEdge(d.source,d.target,{minlen:1,weight:1,...b?{width:p?b:Math.max(1,f.height),height:p?Math.max(1,f.height):b,labelpos:"c"}:{}},d.id)}iy.layout(i);const s=new Map;for(const d of e){if(o.has(d.id))continue;const f=i.node(d.id);f&&Number.isFinite(f.x)&&Number.isFinite(f.y)&&s.set(d.id,{x:f.x,y:f.y})}const u=r.compact?1:r.spacingFactor;if(u&&u!==1&&s.size){let d=1/0,f=1/0,p=-1/0,b=-1/0;s.forEach(x=>{d=Math.min(d,x.x),f=Math.min(f,x.y),p=Math.max(p,x.x),b=Math.max(b,x.y)});const y=(d+p)/2,m=(f+b)/2;s.forEach((x,g)=>s.set(g,{x:y+(x.x-y)*u,y:m+(x.y-m)*u}))}const c=r.nodeAlignment??"center";if(c!=="center"){const d=r.rankDir==="LR"||r.rankDir==="RL",f=d?"x":"y",p=d?"width":"height",b=r.rankDir==="RL"||r.rankDir==="BT"?-1:1,y=c==="leading"?-b:b,m=new Map;for(const x of e){const g=s.get(x.id);if(!g)continue;const w=g[f];m.set(w,Math.max(m.get(w)??0,x[p]))}for(const x of e){const g=s.get(x.id);if(!g)continue;const w=g[f],v=(m.get(w)-x[p])/2;s.set(x.id,{...g,[f]:w+y*v})}}return s}function r_(e,t,r,n,o){const i=new Map,a=new Map(e.map(l=>[l.id,l]));for(const l of e){if(!l.parent||!a.has(l.parent))continue;const d=i.get(l.parent);d?d.push(l.id):i.set(l.parent,[l.id])}const s=(l,d=new Set)=>{var p;const f=(p=a.get(l))==null?void 0:p.parent;return!f||!a.has(f)||d.has(l)?0:(d.add(l),1+s(f,d))},u=[...i.keys()].sort((l,d)=>s(d)-s(l)),c=new Map;for(const l of u){let d=null;for(const b of i.get(l)||[]){let y=c.get(b);if(!y){const m=t.get(b);if(!m)continue;const x=r.get(b)||{w:60,h:60};y={x1:m.x-x.w/2,y1:m.y-x.h/2,x2:m.x+x.w/2,y2:m.y+x.h/2}}d=d?{x1:Math.min(d.x1,y.x1),y1:Math.min(d.y1,y.y1),x2:Math.max(d.x2,y.x2),y2:Math.max(d.y2,y.y2)}:{...y}}if(!d)continue;const f=n(l);d={x1:d.x1-f,y1:d.y1-f,x2:d.x2+f,y2:d.y2+f};const p=o(l);if(p){const b=d.x2-d.x1,y=d.y2-d.y1;if(p.w>b){const m=(p.w-b)/2;d.x1-=m,d.x2+=m}if(p.h>y){const m=(p.h-y)/2;d.y1-=m,d.y2+=m}}c.set(l,d)}return c}function t_(e){const t=e.getBoundingClientRect(),r=t.height/e.offsetHeight;if(!Number.isFinite(r)||r<=0)return[];const n=Sb(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],a=new Set(i.filter(s=>s.hasAttribute("data-flow-inspection-row")&&s.getBoundingClientRect().height>0).map(s=>s.dataset.flowProperty));return i.flatMap(s=>{if(s.closest(".flow-sdk-node")!==e)return[];if(a.has(s.dataset.flowProperty)&&!s.hasAttribute("data-flow-inspection-row"))return[];const u=s.dataset.flowPortSide;if(u&&["top","right","bottom","left"].includes(u)){const l=wb(n?$t(o,n):o,u,Number(s.dataset.flowPortPosition??.5));return[{property:s.getAttribute("data-flow-property"),top:l.y,height:0,anchor:l,...s.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...s.dataset.flowPortRole==="source"||s.dataset.flowPortRole==="target"?{role:s.dataset.flowPortRole}:{}}]}const c=s.getBoundingClientRect();return!c.width||!c.height?[]:[{property:s.getAttribute("data-flow-property"),top:Math.round((c.top-t.top)/r*1e3)/1e3,height:Math.round(c.height/r*1e3)/1e3,...s.dataset.flowPortRole==="source"||s.dataset.flowPortRole==="target"?{role:s.dataset.flowPortRole}:{}}]})}function n_({id:e,x:t,y:r,placed:n,hidden:o,onMount:i,drawHandles:a,drawMode:s,connectedPorts:u,resolvedRows:c,hasCollapseControl:l,handleColor:d,animated:f,animationColor:p,animationWidth:b=8,animationVariant:y,width:m=0,height:x=0,propertyMode:g,reversePorts:w,direction:v="LR",onPropertyRows:_,onSurface:C,children:S}){const T=E.useRef(null),[k,j]=E.useState([]),P=c??k,[R,I]=E.useState();return E.useLayoutEffect(()=>{const O=T.current;if(!O)return;const M=()=>{const V=Sb(O);I(re=>JSON.stringify(re)===JSON.stringify(V)?re:V),C==null||C(e,V)};M();const q=new ResizeObserver(M);q.observe(O);const H=O.querySelector("[data-flow-node-surface]");return H&&q.observe(H),()=>q.disconnect()},[e,S,C]),E.useLayoutEffect(()=>(i(e,T.current),()=>{i(e,null),C==null||C(e,void 0)}),[e,i,C]),E.useLayoutEffect(()=>{const O=T.current;if(!O)return;let M="";const q=()=>{const ce=t_(O),le=g?ce:ce.filter(K=>K.anchor),be=JSON.stringify(le);be!==M&&(M=be,j(le),_==null||_(e,le))};if(q(),!g&&!O.querySelector("[data-flow-port-side]"))return;const H=new ResizeObserver(q),V=()=>{H.disconnect(),H.observe(O),O.querySelectorAll("[data-flow-property]").forEach(ce=>H.observe(ce)),q()};V();const re=new MutationObserver(V);return re.observe(O,{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"]}),O.addEventListener("scroll",q,!0),()=>{H.disconnect(),re.disconnect(),O.removeEventListener("scroll",q,!0)}},[e,g,_,S]),h.jsxs("div",{ref:T,className:"flow-sdk-node","data-node-id":e,style:{transform:`translate(-50%, -50%) translate3d(${t.toFixed(2)}px, ${r.toFixed(2)}px, 0)`,visibility:n&&!o?void 0:"hidden"},children:[S,f&&b>0&&m>0&&x>0&&h.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:h.jsx(xb,{variant:y,x:((R==null?void 0:R.left)??0)+b/2,y:((R==null?void 0:R.top)??0)+b/2,width:((R==null?void 0:R.width)??m)-b,height:((R==null?void 0:R.height)??x)-b,radius:((R==null?void 0:R.radius)??0)-b/2,path:R!=null&&R.outline?`M${R.outline.map(O=>`${O.x} ${O.y}`).join(" L")} Z`:void 0,color:p||d||"currentColor",strokeWidth:b})}),a&&g&&P.map(O=>["source","target"].filter(M=>!O.role||O.role===M).filter(M=>s||(u==null?void 0:u.has(`${M}:${O.property}`))).map(M=>{var q;return h.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":O.property,"data-port-role":M,"data-port-side":(q=O.anchor)==null?void 0:q.side,"aria-label":`${M==="source"?"Connect":"Input"} ${O.property}`,title:`${M==="source"?"Connect":"Input"} ${O.property}`,style:{color:d,...O.anchor?{top:O.anchor.y,left:O.anchor.x-16}:{top:O.top+O.height/2,[M==="source"!=!!w?"right":"left"]:-16}},onClick:H=>H.stopPropagation()},`${O.property}:${M}`)})),a&&!l&&(!g||!P.length)&&(!g||!P.some(O=>O.anchor))&&h.jsx("button",{type:"button",className:"flow-sdk-handle","aria-label":"Draw edge",title:"Draw edge",style:{color:d,left:((R==null?void 0:R.left)??0)+(v==="RL"?-36:v==="LR"?(R==null?void 0:R.width)??m:((R==null?void 0:R.width)??m)/2),top:((R==null?void 0:R.top)??0)+(v==="BT"?-36:v==="TB"?(R==null?void 0:R.height)??x:((R==null?void 0:R.height)??x)/2),transform:v==="BT"||v==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:O=>O.stopPropagation(),children:h.jsx(Z.PiPlusBold,{size:24})})]})}const o_=E.memo(n_);class i_{constructor(t,r,n){Ar(this,"_pan");Ar(this,"_zoom");Ar(this,"minZoom");Ar(this,"maxZoom");Ar(this,"size",{w:0,h:0});Ar(this,"listeners",new Set);Ar(this,"animationFrame");Ar(this,"animationTimer");this.minZoom=r,this.maxZoom=n,this._pan={...t.pan},this._zoom=this.clamp(t.zoom)}cancelAnimation(){this.animationFrame!==void 0&&cancelAnimationFrame(this.animationFrame),clearTimeout(this.animationTimer),this.animationFrame=void 0,this.animationTimer=void 0}transition(t,r=!1){if(this.cancelAnimation(),!r||typeof requestAnimationFrame>"u"||typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches){this.set(t.pan,t.zoom);return}const n=this.state,o={pan:{...t.pan},zoom:this.clamp(t.zoom)},i=performance.now(),a=()=>{this.cancelAnimation(),this.set(o.pan,o.zoom)},s=u=>{const c=Math.min(1,(u-i)/300);if(c>=1){a();return}const l=c*c*(3-2*c);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.animationFrame=requestAnimationFrame(s)};this.animationFrame=requestAnimationFrame(s),this.animationTimer=setTimeout(a,400)}get pan(){return{...this._pan}}get zoom(){return this._zoom}get state(){return{pan:this.pan,zoom:this._zoom}}clamp(t){return Number.isFinite(t)?Math.max(this.minZoom,Math.min(this.maxZoom,t)):this.minZoom}set(t,r){this.cancelAnimation(),this.apply(t,r)}apply(t,r){let n=!1;if(t&&(t.x!==this._pan.x||t.y!==this._pan.y)&&(this._pan={x:t.x,y:t.y},n=!0),r!==void 0){const o=this.clamp(r);o!==this._zoom&&(this._zoom=o,n=!0)}n&&this.emit()}zoomAt(t,r){const n=this.clamp(t),o=this._zoom;if(n===o)return;const i=n/o;this.set({x:r.x-(r.x-this._pan.x)*i,y:r.y-(r.y-this._pan.y)*i},n)}fit(t,r=0,n=!1){const o=t.x2-t.x1,i=t.y2-t.y1;if(!(o>0)||!(i>0)||!this.size.w||!this.size.h)return;const a=this.clamp(Math.min((this.size.w-2*r)/o,(this.size.h-2*r)/i));this.transition({pan:{x:(this.size.w-a*(t.x1+t.x2))/2,y:(this.size.h-a*(t.y1+t.y2))/2},zoom:a},n)}center(t,r=!1){if(!this.size.w||!this.size.h)return;const n=this._zoom;this.transition({pan:{x:(this.size.w-n*(t.x1+t.x2))/2,y:(this.size.h-n*(t.y1+t.y2))/2},zoom:n},r)}renderedToModel(t){return{x:(t.x-this._pan.x)/this._zoom,y:(t.y-this._pan.y)/this._zoom}}modelToRendered(t){return{x:t.x*this._zoom+this._pan.x,y:t.y*this._zoom+this._pan.y}}onChange(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}emit(){const t=this.state;this.listeners.forEach(r=>r(t))}}const a_={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},gu={w:60,h:60},ay=4,s_=30,sy=300,c_=500,u_=45,l_=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2;function cy(e){const[t,r]=[...e.values()];return!t||!r?null:{center:{x:(t.x+r.x)/2,y:(t.y+r.y)/2},distance:Math.max(1,Math.hypot(r.x-t.x,r.y-t.y))}}function d_(e){const{nodes:t,edges:r,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:a=!1,rankSep:s,edgeSep:u,spacingFactor:c=1.3,compactSpacingScale:l,minZoom:d,maxZoom:f,initialViewport:p,containerStyle:b,lineColor:y,drawMode:m,dragMode:x,multiSelect:g,isPerformanceMode:w}=e,[v,_]=E.useState(null),C=E.useMemo(()=>v?(v.mode==="connections"?ql:Pl)(v.id,t,r):null,[v,t,r]),S=i==="auto"||i==="properties",T=E.useMemo(()=>r.filter(A=>wu(A,i)&&(!C||C.has(A.source)&&C.has(A.target))),[r,i,C]),k=E.useMemo(()=>T0(t,r,i,a,C),[t,r,i,a,C]),j=E.useRef(k);j.current=k;const P=E.useRef(e);P.current=e;const R=E.useRef(null),I=E.useRef(null),O=E.useRef(null),M=E.useRef(null),q=E.useMemo(()=>new i_(p,d,f),[]);E.useEffect(()=>{q.minZoom=d,q.maxZoom=f},[q,d,f]);const H=E.useRef(new Map),V=E.useRef(new Map),re=E.useRef(new Map),ce=E.useRef(null),[le,be]=E.useState(new Map),K=E.useCallback((A,$)=>{be(L=>{if(JSON.stringify(L.get(A))===JSON.stringify($))return L;const U=new Map(L);return $?U.set(A,$):U.delete(A),U})},[]),[N,B]=E.useState(new Map),W=E.useRef(N),z=E.useCallback((A,$)=>{B(L=>{if(JSON.stringify(L.get(A)??[])===JSON.stringify($))return L;const U=new Map(L);return $.length?U.set(A,$):U.delete(A),U})},[]),[X,se]=E.useState(()=>new Map),Q=E.useRef(X);Q.current=X;const G=E.useRef(new Map),J=E.useRef(!1),[te,de]=E.useState(0),fe=E.useRef(),Ee=E.useRef(),ge=E.useRef(null),We=E.useRef(),me=E.useRef(!1),Te=E.useRef(null),er=E.useRef(c),De=a&&(i==="properties"||!!C),Ne=E.useRef(De),[He,rr]=E.useState(!0),ze=E.useRef(null);ze.current=C;const xr=E.useRef(1);xr.current=(v==null?void 0:v.mode)==="connections"?1.25:1;const Ze=E.useRef(null),pr=E.useRef(t),dr=E.useRef([]),jr=E.useRef(!1),we=()=>{ge.current!==null&&cancelAnimationFrame(ge.current),ge.current=null,clearTimeout(We.current)},or=()=>{dr.current.length&&(jr.current=!0),!J.current&&P.current.fitOnInit!==!1&&(me.current=!0),clearTimeout(Ee.current),Ee.current=setTimeout(()=>{J.current=!0,de(A=>A+1)},c_)},ar=A=>{we();const $=new Map(Q.current),L=performance.now(),U=()=>{we(),se(A),or()},oe=he=>{const Re=Math.min(1,(he-L)/sy);if(Re>=1)return U();const Ae=l_(Re),ie=new Map;A.forEach((ae,ue)=>{const ye=$.get(ue);ie.set(ue,ye?{x:ye.x+(ae.x-ye.x)*Ae,y:ye.y+(ae.y-ye.y)*Ae}:ae)}),se(ie),ge.current=requestAnimationFrame(oe)};ge.current=requestAnimationFrame(oe),We.current=setTimeout(U,sy+100)},xt=()=>{const A=P.current,$=xr.current,L=j.current,U=L.nodes.map(he=>{const Re=H.current.get(he.id)||gu;return{id:he.id,parent:he.parent,width:Re.w,height:Re.h}});let oe;try{const he=A.compactPropertyLayout&&(A.edgeMode==="properties"||!!ze.current),Re=A.edgeMode!=="nodes"&&A.edgeMode!=="workflow",Ae=L.edges.map(ie=>({...ie,connectorClearance:he?Re&&(ie.sourceProperty!==void 0||ie.targetProperty!==void 0)?A0:P0:0}));oe=e_(U,Ae,{edgeLabelFontSize:A.edgeMode==="nodes"||A.edgeMode==="workflow"?jb:fn,rankDir:A.direction,compact:he,nodeAlignment:A.nodeAlignment,rankSep:A.rankSep*$,edgeSep:A.edgeSep*$,nodeSep:5*$,spacingFactor:A.spacingFactor??1.3,compactSpacingScale:(A.compactSpacingScale??(A.spacingFactor??1.3)/1.3)*$})}catch(he){console.warn("[flow-sdk] layout failed",he);return}for(const[he,Re]of G.current)oe.has(he)?oe.set(he,Re):A.nodes.some(Ae=>Ae.id===he)||G.current.delete(he);J.current&&!A.isPerformanceMode?ar(oe):(we(),se(oe),or())},ne=E.useCallback(()=>{clearTimeout(Ee.current),clearTimeout(fe.current),fe.current=setTimeout(xt,P.current.layoutDebounce)},[]);E.useEffect(()=>{const A=new Map(pr.current.map($=>[$.id,$]));t.some($=>{var L;return((L=A.get($.id))==null?void 0:L.collapsed)===!0&&!$.collapsed})&&(dr.current=t.filter($=>!A.has($.id)).map($=>$.id)),pr.current=t,er.current!==c&&Q.current.size>0&&(J.current=!0,me.current=!1,clearTimeout(Ee.current)),er.current=c,Ne.current!==De&&(me.current=!Te.current),Ne.current=De,ne()},[t,r,k.nodes,k.edges,De,n,o,s,u,ne,c,l]),E.useEffect(()=>()=>{clearTimeout(fe.current),clearTimeout(Ee.current),we()},[]);const Fe=E.useCallback((A,$)=>{var L,U;if(!ce.current&&typeof ResizeObserver<"u"&&(ce.current=new ResizeObserver(oe=>{let he=!1;for(const Re of oe){const Ae=re.current.get(Re.target);if(!Ae)continue;const ie=Re.target,ae=ie.offsetWidth,ue=ie.offsetHeight;if(!ae&&!ue)continue;const ye=H.current.get(Ae);ye&&ye.w===ae&&ye.h===ue||(H.current.set(Ae,{w:ae,h:ue}),he=!0)}he&&ne()})),$){V.current.set(A,$),re.current.set($,A),(L=ce.current)==null||L.observe($);const oe=$.offsetWidth,he=$.offsetHeight;(oe||he)&&H.current.set(A,{w:oe,h:he})}else{const oe=V.current.get(A);oe&&((U=ce.current)==null||U.unobserve(oe),re.current.delete(oe)),V.current.delete(A),H.current.delete(A),W.current.has(A)&&z(A,[])}ne()},[ne,z]);E.useEffect(()=>()=>{var A;return(A=ce.current)==null?void 0:A.disconnect()},[]);const Je=E.useMemo(()=>{const A=new Map;for(const $ of t)$.label&&A.set($.id,$.label);return A},[t]),$e=E.useMemo(()=>r_(k.nodes,X,H.current,A=>b(A).padding,A=>{const $=Je.get(A);if(!$)return;const L=b(A);return{w:Cn($,`bold ${L.fontSize}px ${Qr}`)+2*u_,h:0}}),[k.nodes,X,b,Je]),Xe=E.useRef($e);Xe.current=$e;const Y=E.useCallback(A=>{const $=Xe.current.get(A);if($)return g0($);const L=Q.current.get(A);if(!L)return;const U=H.current.get(A)||gu;return{x:L.x,y:L.y,w:U.w,h:U.h}},[]),D=E.useMemo(()=>{const A=new Map;for(const $ of t){const L=Y($.id);L&&A.set($.id,L)}return S0(N,A,le,r,n)},[N,t,X,$e,le,r,n,Y]);W.current=D;const ee=(A,$)=>{var oe;if(!S||$===void 0)return;const L=(oe=D.get(A))==null?void 0:oe.find(he=>he.property===$),U=Y(A);return L&&!L.anchor&&U?U.y-U.h/2+L.top+L.height/2:void 0},Ce=(A,$)=>{var oe,he;if($===void 0)return;const L=(he=(oe=D.get(A))==null?void 0:oe.find(Re=>Re.property===$))==null?void 0:he.anchor,U=Y(A);return L&&U?{x:U.x-U.w/2+L.x,y:U.y-U.h/2+L.y,side:L.side}:void 0},_e=(A,$)=>{const L=Y(A),U=le.get(A);return L&&U&&!$e.has(A)&&ee(A,$)===void 0?$t(L,U):L},Se=()=>{const A=[];Q.current.forEach(($,L)=>{if(Xe.current.has(L))return;const U=H.current.get(L)||gu;A.push(at({x:$.x,y:$.y,w:U.w,h:U.h}))}),Xe.current.forEach($=>A.push($));try{for(const $ of[I.current,O.current]){const L=$==null?void 0:$.getBBox();L&&L.width>0&&L.height>0&&A.push({x1:L.x,y1:L.y,x2:L.x+L.width,y2:L.y+L.height})}}catch{}return Jn(A)},Ge=()=>{var L,U;const{pan:A,zoom:$}=q;M.current&&(M.current.style.transform=`translate3d(${A.x}px, ${A.y}px, 0) scale(${$})`),(L=I.current)==null||L.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${$})`),(U=O.current)==null||U.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${$})`)};E.useEffect(()=>{Ge();let A=null,$;const L=q.onChange(()=>{Ge();const U=R.current;U&&(U.classList.add("flow-sdk-busy"),clearTimeout($),$=setTimeout(()=>U.classList.remove("flow-sdk-busy"),150)),A===null&&(A=requestAnimationFrame(()=>{var oe,he;A=null,(he=(oe=P.current).onViewportChange)==null||he.call(oe,q.state)}))});return()=>{L(),clearTimeout($),A!==null&&cancelAnimationFrame(A)}},[]),E.useLayoutEffect(()=>{const A=R.current;if(!A)return;const $=()=>{let U=A.clientWidth,oe=A.clientHeight;oe||(oe=Math.max(0,window.innerHeight-A.getBoundingClientRect().top-100),oe&&(A.style.height=`${oe}px`)),U||(U=window.innerWidth,U&&(A.style.width=`${U}px`)),q.size={w:U,h:oe}};if($(),typeof ResizeObserver>"u")return;const L=new ResizeObserver($);return L.observe(A),()=>L.disconnect()},[q]),E.useEffect(()=>{if(jr.current){jr.current=!1;const $=dr.current.flatMap(U=>{const oe=Y(U);return oe?[at(oe)]:[]});dr.current=[];const L=Jn($);if(L){me.current=!1,q.center(L,P.current.animateViewport);return}}if(!me.current)return;me.current=!1;const A=Se();A&&q.fit(A,50,P.current.animateViewport)},[X]);const Le=E.useMemo(()=>{const A=ie=>Pl(ie,P.current.nodes,P.current.edges),$=(ie,ae=50,ue=P.current.animateViewport)=>{const ye=Jn([...ie].flatMap(sr=>{const wt=Y(sr);return wt?[at(wt)]:[]}));ye&&(me.current=!1,q.fit(ye,Number.isFinite(ae)?Math.max(0,ae):50,ue))},L=(ie,ae,ue,ye)=>{if(!Y(ie))return;const sr=ae==="connections"?oe(ie):A(ie);Ze.current||(Ze.current={pan:{...q.pan},zoom:q.zoom}),ze.current=sr,P.current.compactPropertyLayout&&(me.current=!1,Te.current=()=>$(ze.current??sr,ue,ye)),_({id:ie,mode:ae}),P.current.compactPropertyLayout||$(sr,ue,ye)},U=ie=>{Te.current?Te.current=ie:ie()},oe=ie=>ql(ie,P.current.nodes,P.current.edges),he=(ie=>{if(ie===void 0)return q.zoom;q.set(void 0,ie)}),Re=(ie=>{if(ie===void 0)return q.pan;q.set(ie)}),Ae=(ie,ae)=>{var ye;const ue=(ye=R.current)==null?void 0:ye.getBoundingClientRect();return{x:ie-((ue==null?void 0:ue.left)??0),y:ae-((ue==null?void 0:ue.top)??0)}};return{zoom:he,pan:Re,setEdgesVisible:rr,focusNode:(ie,ae,ue)=>U(()=>$(new Set([ie]),ae,ue)),focusBranch:(ie,ae,ue)=>U(()=>$(A(ie),ae,ue)),focusConnections:(ie,ae,ue)=>U(()=>$(oe(ie),ae,ue)),isolateConnections:(ie,ae,ue)=>L(ie,"connections",ae,ue),isolateBranch:(ie,ae,ue)=>L(ie,"branch",ae,ue),restoreView:(ie=P.current.animateViewport)=>{const ae=P.current.compactPropertyLayout&&!!ze.current;ze.current=null,_(null);const ue=Ze.current;Ze.current=null,ae?Te.current=()=>{ue&&q.transition(ue,ie)}:ue&&U(()=>q.transition(ue,ie))},zoomAt:(ie,ae)=>q.zoomAt(ie,ae),fit:(ie=0,ae=P.current.animateViewport)=>{U(()=>{const ue=Se();ue&&q.fit(ue,ie,ae)})},centerAndFit:(ie=0,ae=P.current.animateViewport)=>{U(()=>{const ue=Se();ue&&q.fit(ue,ie,ae)})},center:(ie=P.current.animateViewport)=>{const ae=Se();ae&&q.center(ae,ie)},clientToModel:(ie,ae)=>q.renderedToModel(Ae(ie,ae)),modelToClient:ie=>{var ye;const ae=(ye=R.current)==null?void 0:ye.getBoundingClientRect(),ue=q.modelToRendered(ie);return{x:ue.x+((ae==null?void 0:ae.left)??0),y:ue.y+((ae==null?void 0:ae.top)??0)}},getNodeBox:ie=>Y(ie),setNodePosition:(ie,ae,ue)=>{if(!Q.current.has(ie)||ae&&(!Number.isFinite(ae.x)||!Number.isFinite(ae.y)))return!1;if(we(),!ae)return G.current.delete(ie),ne(),!0;const ye=new Map(Q.current);return ye.set(ie,{...ae}),(ue==null?void 0:ue.persist)===!1?G.current.delete(ie):G.current.set(ie,{...ae}),Q.current=ye,se(ye),(ue==null?void 0:ue.persist)===!1&&ne(),!0},onViewportChange:ie=>q.onChange(ie)}},[]);E.useEffect(()=>{var A,$;return($=(A=P.current).onInit)==null||$.call(A,Le),()=>q.cancelAnimation()},[Le]),E.useEffect(()=>{var A,$;if(te>0){const L=Te.current;Te.current=null,L==null||L(),($=(A=P.current).onLayoutComplete)==null||$.call(A,Le)}},[Le,te]);const ke=E.useRef(null),Me=E.useRef(new Map),gr=E.useRef(!1),[Ye,yr]=E.useState(null),[Oe,wr]=E.useState(null),$r=A=>{const $=R.current.getBoundingClientRect();return{x:A.clientX-$.left,y:A.clientY-$.top}},zn=(A,$)=>{const L=P.current.nodes;for(let U=L.length-1;U>=0;U--){const oe=L[U].id;if(!st(oe,P.current.edges,P.current.edgeMode)||ze.current&&!ze.current.has(oe)||oe===$||Xe.current.has(oe))continue;const he=Y(oe);if(he&&Al(A,at(he)))return oe}for(const[U,oe]of Xe.current)if(st(U,P.current.edges,P.current.edgeMode)&&!(ze.current&&!ze.current.has(U))&&U!==$&&Al(A,oe))return U;return null},Vn=(A,$)=>{if(P.current.edgeMode==="nodes"||P.current.edgeMode==="workflow")return null;const L=P.current.direction==="RL",U=Math.max(16,6/q.zoom);let oe=null;for(const he of[...P.current.nodes].reverse()){if(!st(he.id,P.current.edges,P.current.edgeMode)||ze.current&&!ze.current.has(he.id))continue;const Re=Y(he.id),Ae=W.current.get(he.id);if(!Re||!Ae||Xe.current.has(he.id))continue;const ie=Re.x+($==="source"!==L?1:-1)*Re.w/2;for(const ae of Ae){if(ae.role&&ae.role!==$)continue;const ue=Re.y-Re.h/2+ae.top,ye=Math.hypot(A.x-(ae.anchor?Re.x-Re.w/2+ae.anchor.x:ie),A.y-ue-ae.height/2);if(!ae.anchor&&A.x>=Re.x-Re.w/2&&A.x<=Re.x+Re.w/2&&A.y>=ue&&A.y<=ue+ae.height)return{nodeId:he.id,property:ae.property};ye<=U&&(!oe||ye<oe.distance)&&(oe={nodeId:he.id,property:ae.property,distance:ye})}}return oe},Lm=A=>{var Re;if(!A.currentTarget.contains(A.target)||A.button!==0||P.current.readOnly)return;ke.current||(gr.current=!1);const $=A.target;if($.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const L=P.current,U=$r(A);if(A.pointerType==="touch"){Me.current.set(A.pointerId,U);const Ae=cy(Me.current);if(Ae){ke.current={kind:"pinch",distance:Ae.distance,zoom:q.zoom,anchor:q.renderedToModel(Ae.center)},wr(null),yr(null),gr.current=!0;for(const ie of Me.current.keys())A.currentTarget.setPointerCapture(ie);return}}if(ke.current)return;const oe=L.drawHandles&&$.closest(".flow-sdk-handle"),he=L.drawHandles&&$.closest(".flow-sdk-property-port");if(L.drawMode||oe||he){const Ae=q.renderedToModel(U),ie=L.drawMode?Vn(Ae,"source"):null,ae=he||oe,ue=ae?(Re=ae.closest("[data-node-id]"))==null?void 0:Re.dataset.nodeId:(ie==null?void 0:ie.nodeId)??zn(Ae),ye=he?he.dataset.property:ie==null?void 0:ie.property;if(ue){ke.current={kind:"draw",pointerId:A.pointerId,source:ue,sourceProperty:ye,reverse:(he==null?void 0:he.dataset.portRole)==="target",startClient:{x:A.clientX,y:A.clientY}},gr.current=!0,wr({source:ue,sourceProperty:ye,point:Ae,target:null}),A.currentTarget.setPointerCapture(A.pointerId);return}}$.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(L.multiSelect?ke.current={kind:"box",pointerId:A.pointerId,start:U,current:U}:L.dragMode?ke.current={kind:"pan",pointerId:A.pointerId,start:U,pan0:q.pan,moved:!1}:ke.current={kind:"tap",pointerId:A.pointerId,start:U,moved:!1},A.currentTarget.setPointerCapture(A.pointerId))},Fm=A=>{const $=ke.current;if(!$||P.current.readOnly)return;const L=$r(A);if(Me.current.has(A.pointerId)&&Me.current.set(A.pointerId,L),$.kind==="pinch"){const U=cy(Me.current);if(!U)return;const oe=Math.max(q.minZoom,Math.min(q.maxZoom,$.zoom*U.distance/$.distance));q.set({x:U.center.x-$.anchor.x*oe,y:U.center.y-$.anchor.y*oe},oe);return}if($.pointerId===A.pointerId)switch($.kind){case"pan":{const U=L.x-$.start.x,oe=L.y-$.start.y;if(!$.moved&&Math.hypot(U,oe)<=ay)return;$.moved=!0,gr.current=!0,q.set({x:$.pan0.x+U,y:$.pan0.y+oe});break}case"tap":{Math.hypot(L.x-$.start.x,L.y-$.start.y)>ay&&($.moved=!0);break}case"box":{gr.current=!0,$.current=L,yr({x1:Math.min($.start.x,L.x),y1:Math.min($.start.y,L.y),x2:Math.max($.start.x,L.x),y2:Math.max($.start.y,L.y)});break}case"draw":{const U=q.renderedToModel(L),oe=Vn(U,$.reverse?"source":"target");wr($.reverse&&oe?{source:oe.nodeId,sourceProperty:oe.property,point:U,target:$.source,targetProperty:$.sourceProperty}:{source:$.source,sourceProperty:$.sourceProperty,point:U,target:(oe==null?void 0:oe.nodeId)??zn(U,$.source),targetProperty:oe==null?void 0:oe.property});break}}},ol=(A,$)=>{var oe,he,Re,Ae,ie;Me.current.delete(A.pointerId);const L=ke.current;if(!L)return;if(L.kind==="pinch"){const ae=[...Me.current][0];ke.current=ae&&P.current.dragMode&&!$?{kind:"pan",pointerId:ae[0],start:ae[1],pan0:q.pan,moved:!0}:null;return}if(L.pointerId!==A.pointerId)return;ke.current=null;try{A.currentTarget.releasePointerCapture(A.pointerId)}catch{}const U=P.current;switch($=$||!!U.readOnly,L.kind){case"pan":case"tap":!$&&!L.moved&&((oe=U.onBackgroundTap)==null||oe.call(U));break;case"box":{if(yr(null),$)break;const ae=q.renderedToModel(L.start),ue=q.renderedToModel(L.current),ye={x1:Math.min(ae.x,ue.x),y1:Math.min(ae.y,ue.y),x2:Math.max(ae.x,ue.x),y2:Math.max(ae.y,ue.y)};if(ye.x2-ye.x1<1&&ye.y2-ye.y1<1){(he=U.onBackgroundTap)==null||he.call(U);break}const sr=[];for(const wt of U.nodes){const sl=Y(wt.id);sl&&y0(at(sl),ye)&&sr.push(wt.id)}sr.length&&((Re=U.onBoxSelect)==null||Re.call(U,sr));break}case"draw":{if(wr(null),$)break;const ae=$r(A),ue=q.renderedToModel(ae),ye=Vn(ue,L.reverse?"source":"target"),sr=(ye==null?void 0:ye.nodeId)??zn(ue);if(sr===L.source&&(L.sourceProperty===void 0||(ye==null?void 0:ye.property)===void 0||ye.property===L.sourceProperty))break;sr?(Ae=U.onEdgeDraw)==null||Ae.call(U,L.reverse?sr:L.source,L.reverse?L.source:sr,L.sourceProperty!==void 0||(ye==null?void 0:ye.property)!==void 0?{sourceProperty:L.reverse?ye==null?void 0:ye.property:L.sourceProperty,targetProperty:L.reverse?L.sourceProperty:ye==null?void 0:ye.property}:void 0):Math.max(Math.abs(A.clientX-L.startClient.x),Math.abs(A.clientY-L.startClient.y))>s_&&((ie=U.onDrawIntoSpace)==null||ie.call(U,L.source,ue,L.sourceProperty,L.reverse));break}}},Ur=E.useCallback(()=>{var L;const A=ke.current,$=[...Me.current.keys()];A&&A.kind!=="pinch"&&$.push(A.pointerId),ke.current=null,Me.current.clear(),wr(null),yr(null);for(const U of $)(L=R.current)!=null&&L.hasPointerCapture(U)&&R.current.releasePointerCapture(U)},[]);E.useEffect(()=>{const A=$=>{$.key==="Escape"&&Ur()};return window.addEventListener("keydown",A),window.addEventListener("blur",Ur),()=>{window.removeEventListener("keydown",A),window.removeEventListener("blur",Ur),ke.current=null,Me.current.clear()}},[Ur]),E.useEffect(()=>{Ur()},[m,x,g,i,n,e.drawHandles,e.readOnly,Ur]);const Bm=E.useMemo(()=>{const A=new Map,$=new Map;for(const L of T){if(L.source!==L.target)continue;const U=A.get(L.source)??0;A.set(L.source,U+1),$.set(L.id,U)}return $},[T]),Wn=a_[n],[Gn,Dm]=E.useState(null);E.useLayoutEffect(()=>{R.current&&Gn&&N0(R.current)});const Un=p0(T,_e,Wn),zm=e.onEdgeSelect,Vm=e.onContainerSelect,il=Oe?Oe.target&&_e(Oe.target,Oe.targetProperty)||{x:Oe.point.x,y:Oe.point.y,w:1,h:1}:null,al=Oe?_e(Oe.source,Oe.sourceProperty):null,Wm=["flow-sdk-canvas",m?"flow-sdk-draw":"",w?"flow-sdk-perf":""].filter(Boolean).join(" ");return h.jsxs("div",{ref:R,className:Wm,"data-edge-mode":i,onPointerDownCapture:Lm,onPointerMove:Fm,onPointerUp:A=>ol(A,!1),onPointerCancel:A=>ol(A,!0),onLostPointerCapture:A=>{const $=ke.current;$&&($.kind==="pinch"||$.pointerId===A.pointerId)&&Ur()},onClickCapture:A=>{A.currentTarget.contains(A.target)&&(gr.current||e.readOnly)&&(A.preventDefault(),A.stopPropagation())},children:[h.jsx("svg",{className:"flow-sdk-svg",children:h.jsxs("g",{ref:I,children:[h.jsx("g",{className:"flow-sdk-containers",children:[...$e].filter(([A])=>st(A,r,i)).filter(([A])=>!C||C.has(A)).map(([A,$])=>{var L;return h.jsx(k0,{id:A,rect:$,label:Je.get(A),labelLayer:Gn,style:b(A),onSelect:Vm,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(L=e.selectedNodeIds)==null?void 0:L.includes(A)},A)})}),h.jsx("g",{className:"flow-sdk-edges",children:He&&T.map(A=>{var U,oe,he;if(C&&(!C.has(A.source)||!C.has(A.target)))return null;const $=_e(A.source,A.sourceProperty),L=_e(A.target,A.targetProperty);return!$||!L?null:h.jsx(Nl,{id:A.id,edgeData:A.data,validationIssue:A.validationIssue,edgeType:A.type,edgeRadius:e.edgeRadius,propertyMode:S,customEdgeTypes:e.customEdgeTypes,source:$,target:L,sourceProperty:A.sourceProperty,targetProperty:A.targetProperty,sourceY:ee(A.source,A.sourceProperty),targetY:ee(A.target,A.targetProperty),sourcePort:Ce(A.source,A.sourceProperty),targetPort:Ce(A.target,A.targetProperty),dir:Wn,turn:((U=Un.get(A.id))==null?void 0:U.turn)??A.turn,labelAtTarget:(oe=Un.get(A.id))==null?void 0:oe.labelAtTarget,labelFraction:(he=Un.get(A.id))==null?void 0:he.labelFraction,color:A.color,labelBg:A.labelBg,label:A.label,labelLayer:Gn,dashed:A.dashed,animated:A.animated&&!w,inverted:A.inverted,loopIndex:Bm.get(A.id)??0,onSelect:zm},A.id)})}),He&&Oe&&wu(Oe,i)&&al&&il&&h.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:h.jsx(Nl,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:Oe.source,target:Oe.target??"",sourceProperty:Oe.sourceProperty,targetProperty:Oe.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:S,customEdgeTypes:e.customEdgeTypes,source:al,target:il,sourceProperty:Oe.sourceProperty,targetProperty:Oe.targetProperty,sourceY:ee(Oe.source,Oe.sourceProperty),sourcePort:Ce(Oe.source,Oe.sourceProperty),targetPort:Oe.target?Ce(Oe.target,Oe.targetProperty):void 0,targetY:Oe.target?ee(Oe.target,Oe.targetProperty):void 0,dir:Wn,turn:.5,color:y,labelBg:y})})]})}),h.jsx("div",{ref:M,className:"flow-sdk-nodes",children:t.map(A=>{var he,Re;const $=X.get(A.id),L=$e.get(A.id),U=($==null?void 0:$.x)??(L?(L.x1+L.x2)/2:0),oe=($==null?void 0:$.y)??(L?(L.y1+L.y2)/2:0);return h.jsx(o_,{id:A.id,x:U,y:oe,placed:!!$||!!L,hidden:!st(A.id,r,i)||!!C&&!C.has(A.id),onMount:Fe,drawHandles:e.drawHandles&&!e.readOnly,drawMode:m,connectedPorts:new Set(T.flatMap(Ae=>[...Ae.source===A.id&&Ae.sourceProperty!==void 0?[`source:${Ae.sourceProperty}`]:[],...Ae.target===A.id&&Ae.targetProperty!==void 0?[`target:${Ae.targetProperty}`]:[]])),hasCollapseControl:A.hasCollapseControl,handleColor:y,animated:A.animated&&!L&&!w,animationColor:A.animationColor,animationWidth:A.animationWidth,animationVariant:A.animationVariant,width:(he=H.current.get(A.id))==null?void 0:he.w,height:(Re=H.current.get(A.id))==null?void 0:Re.h,propertyMode:S,resolvedRows:D.get(A.id),reversePorts:n==="RL",direction:n,onPropertyRows:z,onSurface:K,children:A.element},A.id)})}),Ye&&h.jsx("div",{className:"flow-sdk-box",style:{left:Ye.x1,top:Ye.y1,width:Ye.x2-Ye.x1,height:Ye.y2-Ye.y1}}),h.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:h.jsx("g",{ref:O,transform:`translate(${q.pan.x} ${q.pan.y}) scale(${q.zoom})`,children:h.jsx("g",{ref:Dm,className:"flow-sdk-labels",style:{pointerEvents:m?"none":"visiblePainted",outline:"none"}})})})]})}const f_=E.memo(d_);function Pm({id:e,role:t,side:r,position:n=.5,placement:o,children:i,style:a}){return h.jsx("div",{"data-flow-property":e,"data-flow-port-role":t,"data-flow-port-side":r,"data-flow-port-position":r?n:void 0,"data-flow-port-placement":o,style:{minHeight:32,display:"flex",alignItems:"center",justifyContent:t==="source"?"flex-end":"flex-start",...a,...r?{display:"none"}:{}},children:i??e})}const h_=gn.default.dialog`
152
+ `;function Rl({request:e,property:t,config:r,value:n,disabled:o}){var D,W;const{callbacks:i,structured:a,references:s}=j.useContext(kr),{themeColor:u}=Ie(),{background:c}=Ve(),l=j.useId(),d=t.type.kind==="object"||t.type.kind==="array"||t.type.kind==="json",f=n===void 0?"":d?JSON.stringify(n,null,2):String(n),[p,m]=j.useState(f),[y,b]=j.useState(""),[v,g]=j.useState(0),[w,x]=j.useState(),_=((D=r.$options)==null?void 0:D.$source)==="callback",C=i.resolveFormOptions,{data:S,address:T,nodeAddress:k,nodeId:E}=e,P=j.useRef(S);P.current=S;const R=JSON.stringify([T,E,(W=r.$options)!=null&&W.$dependsOn?r.$options.$dependsOn.map(z=>xe(S,z)):xe(S,k)]);j.useEffect(()=>{m(f),b("")},[f,T,E]),j.useEffect(()=>{if(!_)return;const z=new AbortController;return Promise.resolve().then(()=>{if(!C)throw new Error("No options resolver configured");return C({address:T,nodeAddress:k,nodeId:E,data:Wt(P.current),signal:z.signal})}).then(X=>{if(!Array.isArray(X)||X.some(se=>!se||typeof se.label!="string"||!["string","number","boolean"].includes(typeof se.value)&&se.value!==null))throw new Error("Invalid options response");z.signal.aborted||x({key:R,options:X})}).catch(X=>{z.signal.aborted||x({key:R,options:[],error:X instanceof Error?X.message:"Options unavailable"})}),()=>z.abort()},[_,C,R,T,k,E,v]);const I=_&&(w==null?void 0:w.key)!==R,O=_?(w==null?void 0:w.key)===R?w.options:[]:t.type.kind==="null"?[{label:"Null",value:null}]:t.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:$t(t.type),M=t.type.kind==="array",q=(a&&d||r.$control==="checkbox"?"pills":r.$control)??(O?M||t.type.kind==="boolean"?"pills":"select":t.type.kind==="boolean"?"checkbox":d?"textarea":"input"),K=!t.optional||!!r.$requiredWhen&&xn(r.$requiredWhen,S),V=!!(s!=null&&s.length)&&typeof n=="string"&&n.includes("{{"),re=y||_&&(w==null?void 0:w.key)===R&&w.error||!V&&Rr(t.type,n,K),ce=Cr(r.$label??T.split(".").pop()),he=z=>{var X;if(!(o||Object.is(z,n)))try{(X=i.onFormChange)==null||X.call(i,{...e,previousValue:n,value:z}),b("")}catch(se){b(se instanceof Error?se.message:"Unable to update field")}},me=()=>{if(d){try{const Q=p===""&&t.optional?void 0:JSON.parse(p),G=Rr(t.type,Q,K);if(G){b(G);return}he(Q)}catch{b("Enter valid JSON")}return}const z=t.type.kind==="number"||t.type.kind==="integer",X=p===""&&t.optional?void 0:z&&p!==""?Number(p):p,se=Rr(t.type,X,K);if(z&&se&&p!==""){b(se);return}he(X)},H={id:l,disabled:o,"aria-label":ce,"aria-required":K,"aria-invalid":!!re,"aria-describedby":re?`${l}-error`:void 0},N=fe(u);return h.jsxs("div",{"data-form-field":T,"data-flow-property":T.slice(k.length+1),children:[h.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[h.jsxs("label",{htmlFor:l,children:[ce,K?" *":""]}),t.optional&&n!==void 0&&h.jsx("button",{type:"button","aria-label":`Reset ${ce}`,title:`Reset ${ce}`,disabled:o,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:h.jsx(Z.PiArrowCounterClockwise,{size:14})})]}),!!(s!=null&&s.length)&&!d&&h.jsx(e0,{label:ce,value:n,references:s,disabled:o,onChange:he}),V?null:q==="select"?h.jsxs("div",{"data-form-select":"",children:[h.jsxs("select",{...H,disabled:o||I||!!(w!=null&&w.error),value:(O==null?void 0:O.findIndex(z=>Object.is(z.value,n)))??-1,onChange:z=>{const X=O==null?void 0:O[Number(z.target.value)];X&&he(X.value)},children:[h.jsx("option",{value:-1,disabled:!0,children:n!==void 0?String(n):""}),O==null?void 0:O.map((z,X)=>h.jsx("option",{value:X,style:{background:fe(c)},children:Cr(z.label)||z.label},X))]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}):q==="pills"?h.jsxs("div",{id:l,role:"group","aria-label":ce,"aria-describedby":H["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:[O==null?void 0:O.map((z,X)=>{const se=M?Array.isArray(n)&&n.includes(z.value):Object.is(n,z.value);return h.jsx("button",{type:"button",disabled:o||I,"aria-pressed":se,style:{padding:"8px 16px",borderRadius:24,border:0,color:se?N:"inherit",background:se?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>he(M?se?n.filter(Q=>Q!==z.value):[...Array.isArray(n)?n:[],z.value]:z.value),children:Cr(z.label)||z.label},X)}),I&&h.jsx("span",{role:"status",children:"Loading..."})]}):q==="textarea"?h.jsx("textarea",{...H,value:p,onChange:z=>m(z.target.value),onBlur:me}):h.jsx("input",{...H,type:t.type.kind==="number"||t.type.kind==="integer"?"number":"text",step:t.type.kind==="integer"?1:"any",value:p,onChange:z=>m(z.target.value),onBlur:me,onKeyDown:z=>{z.key==="Enter"&&me(),z.key==="Escape"&&m(n===void 0?"":String(n))}}),re&&h.jsx("div",{role:"alert",id:`${l}-error`,children:re}),_&&(w==null?void 0:w.error)&&h.jsx("button",{type:"button",disabled:o,onClick:()=>{x(void 0),g(v+1)},children:"Retry"})]})}function om({nodeAddress:e}){var x,_;const{data:t,schema:r,callbacks:n,bindings:o,editable:i,renderForm:a,structured:s}=j.useContext(kr),{readOnly:u,config:c}=Ie(),l=a==null?void 0:a(e);if(l!==void 0)return h.jsx("fieldset",{"data-flow-form":e,disabled:u||c.editable===!1||!i,style:{border:0,margin:0,padding:0,minWidth:0},children:l});if(!t)return h.jsx(nn,{role:"alert",children:"Forms require a JSON document."});const d=o?Yt(o,e,r):void 0,f=o?d:r&&gt(t,e,r);if(!f)return h.jsx(nn,{role:"status",children:"Form schema unavailable."});const p=(d==null?void 0:d.address)??e,m=xe(t,p),y=(x=s==null?void 0:s.containers.get(e))==null?void 0:x.scalar;if(m===void 0||typeof m!="object"&&!y)return h.jsx(nn,{role:"alert",children:"Bound form state is unavailable."});const b=Object.entries(f.type.properties).filter(([C])=>{var S;return xn((S=f.fields[C])==null?void 0:S.$visibleWhen,t)}),v=b.length>8||b.some(([C])=>{var S;return(S=f.fields[C])==null?void 0:S.$section}),g=new Map;for(const C of b){const[S,T]=C,k=v?Cr(((_=f.fields[S])==null?void 0:_.$section)??(T.type.kind==="object"||T.type.kind==="array"?S:T.optional?"Options":"General")):"";g.has(k)||g.set(k,[]),g.get(k).push(C)}const w=([C,S])=>h.jsx(Rl,{request:{data:t,address:y?p:`${p}.${C}`,nodeAddress:p,nodeId:typeof(m==null?void 0:m.id)=="string"?m.id:void 0},property:S,config:f.fields[C]??{},value:y?m:m==null?void 0:m[C],disabled:u||c.editable===!1||!(i??!!n.onJsonChange)},`${(m==null?void 0:m.id)??e}:${C}`);return h.jsxs(nn,{"data-flow-form":e,onClick:C=>C.stopPropagation(),onDoubleClick:C=>C.stopPropagation(),children:[s&&h.jsx(i0,{nodeAddress:e}),d&&f.type.additionalProperties&&b.length===0&&h.jsx(Rl,{request:{data:t,address:p,nodeAddress:p},property:{type:f.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:m,disabled:u||c.editable===!1||!i}),[...g].map(([C,S])=>v&&S.length>1?h.jsxs("details",{open:!0,children:[h.jsxs("summary",{children:[h.jsx("span",{children:C}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),S.map(w)]},C):S.map(w))]})}function im(e){const{viewData:t}=j.useContext(kr),{nodeById:r,edgeById:n,parentIds:o}=Gr();if(t){const i=xe(t,e),a=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(a)?a.length>0:!!a&&typeof a=="object"&&Object.entries(a).some(([s,u])=>!s.startsWith("$")&&u!==null&&typeof u=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const a=i.isInverted?i.target:i.source,s=i.isInverted?i.source:i.target;return a===e&&s!==e&&r.has(s)})}function Ht(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:t}function dn(e,t,r,n){return{borderColor:t,borderWidth:Ht(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",...py(t==="transparent"?"currentColor":t,r,".flow-sdk-node:hover &",!r)}}function am({label:e,value:t,options:r,onChange:n,disabled:o}){var i;return h.jsxs(Or,{"aria-label":e,title:`Animation: ${((i=r.find(a=>a.value===t))==null?void 0:i.label)??"Mixed"}`,value:t,style:{width:104},disabled:o,onValueChange:a=>{const s=r.find(u=>u.value===a);s&&n(s.value)},children:[t===""&&h.jsx("option",{value:"",disabled:!0,children:"Mixed"}),r.map(a=>h.jsx("option",{value:a.value,children:a.label},a.value))]})}const fn="data:image/svg+xml;base64,";function Pt(e){if(e.startsWith(fn))return!0;try{const t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:")&&!t.username&&!t.password}catch{return!1}}async function a0(e){if(e.size>256*1024)throw new Error("SVG must be 256 KB or smaller.");const t=await e.text(),r=new DOMParser().parseFromString(t,"image/svg+xml");if(r.doctype||r.querySelector("parsererror")||r.documentElement.localName!=="svg"||r.documentElement.namespaceURI!=="http://www.w3.org/2000/svg")throw new Error("Choose a valid SVG file.");if(r.querySelector("script, foreignObject")||[...r.querySelectorAll("*")].some(i=>[...i.attributes].some(a=>/^on/i.test(a.name))))throw new Error("SVG scripts and event handlers are not allowed.");const n=new TextEncoder().encode(t);let o="";for(const i of n)o+=String.fromCharCode(i);return fn+btoa(o)}const Mr=({name:e,svg:t=!1,...r})=>{const[n,o]=j.useState(null),[i,a]=j.useState(!0),[s,u]=j.useState(!1),c=typeof e=="string"&&Pt(e);if(j.useEffect(()=>{if(c||!e||e.length<2){o(null),a(!1);return}a(!0),u(!1),(async()=>{try{let d;if(e.startsWith("Md"))d="md";else if(e.startsWith("Fa"))d="fa6";else if(e.startsWith("Io5"))d="io5";else if(e.startsWith("Io"))d="io";else if(e.startsWith("Ti"))d="ti";else if(e.startsWith("Go"))d="go";else if(e.startsWith("Fi"))d="fi";else if(e.startsWith("Di"))d="di";else if(e.startsWith("Ai"))d="ai";else if(e.startsWith("Bs"))d="bs";else if(e.startsWith("Ri"))d="ri";else if(e.startsWith("Fc"))d="fc";else if(e.startsWith("Gi"))d="gi";else if(e.startsWith("Hi2"))d="hi2";else if(e.startsWith("Hi"))d="hi";else if(e.startsWith("Si"))d="si";else if(e.startsWith("Sl"))d="sl";else if(e.startsWith("Im"))d="im";else if(e.startsWith("Bi"))d="bi";else if(e.startsWith("Pi"))d="pi";else if(e.startsWith("Vsc"))d="vsc";else if(e.startsWith("Tb"))d="tb";else if(e.startsWith("Tfi"))d="tfi";else if(e.startsWith("Cg"))d="cg";else if(e.startsWith("Lia"))d="lia";else if(e.startsWith("Lu"))d="lu";else throw new Error(`Unknown library prefix for icon: ${e}`);let f;switch(d){case"md":f=await import("react-icons/md");break;case"fa6":f=await import("react-icons/fa6");break;case"io5":f=await import("react-icons/io5");break;case"io":f=await import("react-icons/io");break;case"ti":f=await import("react-icons/ti");break;case"go":f=await import("react-icons/go");break;case"fi":f=await import("react-icons/fi");break;case"di":f=await import("react-icons/di");break;case"ai":f=await import("react-icons/ai");break;case"bs":f=await import("react-icons/bs");break;case"ri":f=await import("react-icons/ri");break;case"fc":f=await import("react-icons/fc");break;case"gi":f=await import("react-icons/gi");break;case"hi2":f=await import("react-icons/hi2");break;case"hi":f=await import("react-icons/hi");break;case"si":f=await import("react-icons/si");break;case"sl":f=await import("react-icons/sl");break;case"im":f=await import("react-icons/im");break;case"bi":f=await import("react-icons/bi");break;case"pi":f=await import("react-icons/pi");break;case"vsc":f=await import("react-icons/vsc");break;case"tb":f=await import("react-icons/tb");break;case"tfi":f=await import("react-icons/tfi");break;case"cg":f=await import("react-icons/cg");break;case"lia":f=await import("react-icons/lia");break;case"lu":f=await import("react-icons/lu");break;default:throw new Error(`Unsupported library: ${d}`)}const p=f[e];if(!p)throw new Error(`Icon ${e} not found in library ${d}`);o(()=>p)}catch(d){console.warn(`Failed to load icon ${e}:`,d.message),u(!0),o(null)}finally{a(!1)}})()},[e,c]),c){const{size:l=80,style:d,...f}=r;return t?h.jsx("image",{...f,href:e,width:l,height:l,preserveAspectRatio:"xMidYMid meet",style:d}):h.jsx("img",{...f,src:e,alt:"",width:l,height:l,referrerPolicy:"no-referrer",style:{objectFit:"contain",...d}})}return i||!n?null:h.jsx(n,{...r})};function qu({nodeId:e,edgeId:t,value:r}){const{callbacks:n,readOnly:o,themeColor:i}=Ie(),{background:a,backgroundSecondary:s,border:u,colorText:c}=Ve(),l=j.useRef(null),d=j.useId(),f=j.useRef(null),p=j.useRef(0),[m,y]=j.useState(!1),[b,v]=j.useState("icons"),[g,w]=j.useState([]),[x,_]=j.useState("loading"),[C,S]=j.useState(""),[T,k]=j.useState(0),[E,P]=j.useState(""),[R,I]=j.useState(""),[O,M]=j.useState(!1);j.useEffect(()=>()=>{p.current++},[]),j.useEffect(()=>{if(!m)return;let H=!0;return import("react-icons/pi").then(N=>{H&&(w(Object.keys(N).filter(D=>D.startsWith("Pi")).sort()),_("ready"))}).catch(()=>{H&&_("unavailable")}),()=>{H=!1}},[m]),j.useEffect(()=>{var H;o&&((H=l.current)==null||H.close())},[o]);const q=H=>{var N,D,W;o||(t?(N=n.onEdgeIconChange)==null||N.call(n,t,H):e&&((D=n.onNodeIconChange)==null||D.call(n,e,H)),(W=l.current)==null||W.close())},K=g.filter(H=>H.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(C.trim().toLowerCase())),V=36,re=Math.max(1,Math.ceil(K.length/V)),ce=Math.min(T,re-1),he=K.slice(ce*V,(ce+1)*V),me={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${fe(u)}`,borderRadius:30};return h.jsxs(h.Fragment,{children:[h.jsx(je,{label:t?"Choose edge icon":"Choose node icon",children:h.jsx(ve,{"aria-label":t?"Choose edge icon":"Choose node icon",icon:h.jsx(Z.PiShapes,{size:20}),size:"sm",variant:"ghost",color:fe(i),disabled:o,onClick:()=>{var H;I(""),v(r&&Pt(r)?"custom":"icons"),P(r&&!r.startsWith(fn)&&Pt(r)?r:""),y(!0),(H=l.current)==null||H.showModal()}})}),h.jsx(F.chakra.dialog,{ref:l,"aria-label":t?"Choose edge icon":"Choose node icon",css:Dr(fe(a),fe(u)),onClose:()=>{y(!1),p.current++,M(!1)},onClick:H=>{H.stopPropagation(),H.target===H.currentTarget&&H.currentTarget.close()},onKeyDown:H=>H.stopPropagation(),style:{margin:"auto",padding:12,width:336,maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",borderRadius:30,background:fe(a),color:fe(c)},children:m&&h.jsxs("div",{style:{display:"grid",gap:8},children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[h.jsx("strong",{children:t?"Edge icon":"Node icon"}),h.jsxs("div",{style:{display:"flex",alignItems:"center",marginLeft:"auto",gap:4},children:[r&&h.jsx(je,{label:"Remove icon",children:h.jsx(ve,{"aria-label":t?"Remove edge icon":"Remove node icon",icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:o||O,onClick:()=>q("")})}),h.jsx(pt,{"aria-label":"Close icon picker",onClick:()=>{var H;return(H=l.current)==null?void 0:H.close()}})]})]}),h.jsx("div",{role:"tablist","aria-label":"Icon source",style:{display:"flex",borderBottom:`1px solid ${fe(u)}`},children:["icons","custom"].map(H=>h.jsx("button",{id:`${d}-${H}`,type:"button",role:"tab","aria-selected":b===H,"aria-controls":`${d}-panel`,tabIndex:b===H?0:-1,onClick:()=>{v(H),I("")},onKeyDown:N=>{var W;if(!["ArrowLeft","ArrowRight","Home","End"].includes(N.key))return;N.preventDefault();const D=N.key==="Home"?"icons":N.key==="End"||H==="icons"?"custom":"icons";v(D),I(""),(W=document.getElementById(`${d}-${D}`))==null||W.focus()},style:{flex:1,padding:"8px 12px",background:"transparent",border:0,borderBottom:`2px solid ${b===H?fe(i):"transparent"}`,color:b===H?fe(i):"inherit",cursor:"pointer",fontSize:13},children:H==="icons"?"React icons":"Custom SVG"},H))}),h.jsx("input",{ref:f,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:O||o,onChange:async H=>{var W;const N=(W=H.target.files)==null?void 0:W[0];if(H.target.value="",!N)return;const D=++p.current;M(!0),I("");try{const z=await a0(N);D===p.current&&q(z)}catch(z){D===p.current&&I(z instanceof Error?z.message:"Unable to read SVG.")}finally{D===p.current&&M(!1)}}}),h.jsx("div",{id:`${d}-panel`,role:"tabpanel","aria-labelledby":`${d}-${b}`,style:{display:"grid",gap:8},children:b==="icons"?h.jsxs(h.Fragment,{children:[h.jsx("input",{"aria-label":"Search icons",placeholder:"Search icons...",value:C,onChange:H=>{S(H.target.value),k(0)},style:me}),h.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[he.map(H=>h.jsx("button",{type:"button","aria-label":`Choose ${H}`,"aria-pressed":r===H,title:H,onClick:()=>q(H),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${r===H?2:1}px solid ${fe(r===H?i:u)}`,background:fe(r===H?a:s),color:"inherit",cursor:"pointer"},children:h.jsx(Mr,{name:H,size:24})},H)),he.length===0&&h.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:x==="loading"?"Loading icons...":x==="unavailable"?"React icons unavailable":"No icons found"})]}),h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[h.jsxs("span",{role:"status",style:{fontSize:12},children:[K.length," icons · ",ce+1," / ",re]}),h.jsxs("div",{style:{display:"flex",gap:4},children:[h.jsx(je,{label:"Previous icons",children:h.jsx(ve,{"aria-label":"Previous icons",icon:h.jsx(Z.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:ce===0,onClick:()=>k(ce-1)})}),h.jsx(je,{label:"Next icons",children:h.jsx(ve,{"aria-label":"Next icons",icon:h.jsx(Z.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:ce+1>=re,onClick:()=>k(ce+1)})})]})]})]}):h.jsxs(h.Fragment,{children:[r&&Pt(r)&&h.jsx(Mr,{name:r,size:64}),h.jsxs("button",{type:"button",disabled:O||o,onClick:()=>{var H;return(H=f.current)==null?void 0:H.click()},style:{...me,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[h.jsx(Z.PiUploadSimple,{}),O?"Uploading...":"Upload SVG"]}),h.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:H=>{H.preventDefault(),!(O||o)&&(!Pt(E.trim())||E.trim().startsWith(fn)?I("Enter an HTTP or HTTPS image URL."):q(E.trim()))},children:[h.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:E,disabled:O||o,onChange:H=>P(H.target.value),style:{...me,flex:1,minWidth:0}}),h.jsx(je,{label:"Apply URL",children:h.jsx(ve,{type:"submit","aria-label":"Apply URL",icon:h.jsx(Z.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:O||o||!E.trim(),style:{flexShrink:0}})})]})]})}),R&&h.jsx("div",{role:"alert",style:{fontSize:13},children:R})]})})]})}const Nu=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500"],sm=["gray.900","gray.600","gray.200","white"];function cm(){const{config:e}=Ie(),t=e.selectionToolbar||{},r=new Set(t.hide||[]);return{palette:t.palette||Nu,show:n=>!r.has(n)}}function ur(){const{border:e}=Ve();return h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:e})}function Qr({value:e,placeholder:t,ariaLabel:r,width:n="140px",type:o="text",min:i,onCommit:a}){const{colorText:s}=Ve(),[u,c]=j.useState(e),l=j.useRef(!1);j.useEffect(()=>c(e),[e]);const d=()=>{if(l.current)return;l.current=!0;const f=u.trim();if(o==="number"&&f!==""&&(!Number.isFinite(Number(f))||Number(f)<(i??0))){c(e);return}f!==e&&a(f)};return h.jsx(F.Input,{"aria-label":r,type:o,min:i,size:"xs",w:n,value:u,placeholder:t,color:s,borderWidth:0,_focusVisible:{boxShadow:"none",outline:"none"},borderRadius:"8px",onFocus:()=>{l.current=!1},onChange:f=>c(f.target.value),onBlur:d,onKeyDown:f=>{f.key==="Enter"&&(d(),f.target.blur()),f.key==="Escape"&&(l.current=!0,c(e),f.target.blur())}})}function Kt({colors:e,value:t,label:r,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:a,colorText:s}=Ve(),[u,c]=j.useState(!1),l=j.useId(),d=j.useRef(null),f=t??e[0]??"transparent";return h.jsxs(F.HStack,{gap:1,"aria-label":r,role:"group",onKeyDown:p=>{var m;p.key==="Escape"&&(c(!1),(m=d.current)==null||m.focus())},children:[h.jsx(je,{label:`${r}: ${f}`,children:h.jsx(F.chakra.button,{ref:d,type:"button","aria-label":`${r} colors`,"aria-expanded":u,"aria-controls":l,w:4,h:4,flexShrink:0,borderRadius:"full",cursor:"pointer",style:{backgroundColor:fe(f),...f==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${fe(s)}`,outlineOffset:"1px",onClick:()=>c(p=>!p)})}),u&&h.jsxs(F.HStack,{id:l,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(p=>{const m=t===p;return h.jsx(je,{label:`${r}: ${p}`,children:h.jsx(F.Box,{as:"button","aria-label":`${r} ${p}`,"aria-pressed":m,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:fe(p),...p==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:m?`2px solid ${fe(s)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>{var y;n(p),c(!1),(y=d.current)==null||y.focus()}})},p)}),o&&h.jsx(je,{label:`Reset ${r.toLowerCase()}`,children:h.jsx(ve,{"aria-label":`Reset ${r}`,icon:h.jsx(F.Icon,{as:Z.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:a,onClick:()=>{var p;o(),c(!1),(p=d.current)==null||p.focus()}})})]})]})}function um({edgeId:e,onClose:t}){var p;const{callbacks:r,themeColor:n,config:o}=Ie(),{colorInactive:i}=Ve(),{edgeById:a}=Gr(),{palette:s,show:u}=cm(),c=(p=a.get(e))==null?void 0:p.data,l=[...new Set(["rounded-orthogonal","orthogonal","straight","bezier",...Object.keys(o.customEdgeTypes??{}),...c!=null&&c.type?[c.type]:[]])],d=c!=null&&c.isEdgeAnimated?"animated":c!=null&&c.isEdgeDashed?"dashed":"solid",f=[{key:"solid",icon:Z.PiLineSegment,label:"Solid"},{key:"dashed",icon:Z.PiLineSegments,label:"Dashed"},{key:"animated",icon:Z.PiFastForward,label:"Animated"}];return h.jsxs(h.Fragment,{children:[h.jsx(pt,{onClick:t}),u("label")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Qr,{ariaLabel:"Edge label",placeholder:"Edge label",value:(c==null?void 0:c.label)||"",onCommit:m=>{var y;return(y=r.onEdgeLabelChange)==null?void 0:y.call(r,e,m)}})]}),u("style")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),f.map(m=>h.jsx(je,{label:m.label,children:h.jsx(ve,{"aria-label":`Edge style ${m.key}`,"aria-pressed":d===m.key,icon:h.jsx(F.Icon,{as:m.icon,boxSize:5}),size:"sm",variant:"ghost",color:d===m.key?n:i,onClick:()=>{var y;return(y=r.onEdgeStyleChange)==null?void 0:y.call(r,e,m.key)}})},m.key)),d==="animated"&&h.jsx(am,{label:"Edge animation",value:(c==null?void 0:c.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:o.readOnly,onChange:m=>{var y;return(y=r.onEdgeAnimationVariantChange)==null?void 0:y.call(r,e,m)}}),h.jsxs(Or,{"aria-label":"Edge shape",title:`Edge shape: ${(c==null?void 0:c.type)??"Default"}`,icon:h.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:(c==null?void 0:c.type)??"",disabled:o.readOnly,onValueChange:m=>{var y;return(y=r.onEdgeTypeChange)==null?void 0:y.call(r,e,m||void 0)},children:[h.jsx("option",{value:"",children:"Default"}),l.map(m=>h.jsx("option",{value:m,children:m},m))]})]}),u("icon")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(qu,{edgeId:e,value:c==null?void 0:c.icon},e),h.jsx(Qr,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(c==null?void 0:c.icon)??"",onCommit:m=>{var y;return(y=r.onEdgeIconChange)==null?void 0:y.call(r,e,m)}})]}),u("color")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Kt,{label:"Edge color",colors:s,value:c==null?void 0:c.color,onPick:m=>{var y;return(y=r.onEdgeColorChange)==null?void 0:y.call(r,e,m)},onReset:()=>{var m;return(m=r.onEdgeColorChange)==null?void 0:m.call(r,e,"")}})]}),u("delete")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(je,{label:"Delete edge",children:h.jsx(ve,{"aria-label":"Delete edge",icon:h.jsx(F.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var m;(m=r.onEdgeDelete)==null||m.call(r,e,c),t()}})})]})]})}function lm({ids:e,showDivider:t=!0}){const{callbacks:r,config:n}=Ie(),{colorInactive:o}=Ve(),{nodeById:i}=Gr(),[a,s]=j.useState(!1),u=e.map(m=>{var y,b;return(b=(y=i.get(m))==null?void 0:y.data.viewProps)==null?void 0:b.borderRadius}),c=!u.every(m=>m===u[0]),l=c?"mixed":String(u[0]??""),d=["0","8","16","30","53","100"],f=a||!c&&l!==""&&!d.includes(l),p=m=>e.forEach(y=>{var b;return(b=r.onNodeBorderRadiusChange)==null?void 0:b.call(r,y,m)});return h.jsxs(h.Fragment,{children:[t&&h.jsx(ur,{}),h.jsx(F.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:h.jsxs(Or,{icon:h.jsx(F.Icon,{as:tv.TbBorderRadius,boxSize:5,color:o,"aria-hidden":"true"}),"aria-label":"Node border radius",title:`Border radius: ${c?"Mixed":u[0]===void 0?"Default":`${u[0]}px`}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",cursor:"pointer"},value:f?"custom":l,disabled:n.readOnly,onValueChange:m=>{s(m==="custom"),m!=="custom"&&p(m===""?void 0:Number(m))},children:[h.jsx("option",{value:"",children:"Default radius"}),c&&h.jsx("option",{value:"mixed",disabled:!0,children:"Mixed radii"}),d.map(m=>h.jsxs("option",{value:m,children:[m,"px radius"]},m)),h.jsx("option",{value:"custom",children:"Custom radius"})]})}),f&&h.jsx(Qr,{ariaLabel:"Custom border radius",placeholder:c?"Mixed":"Auto",type:"number",min:0,width:"72px",value:c?"":l,onCommit:m=>p(m===""?void 0:Number(m))})]})}function dm({ids:e,onClose:t}){var H,N,D,W,z,X,se,Q;const{callbacks:r,colorMode:n,themeColor:o,config:i,setNodeViewMode:a}=Ie(),{colorText:s,colorInactive:u}=Ve(),{nodeById:c,parentIds:l}=Gr(),{palette:d,show:f}=cm(),p=e.length===1,m=p?(H=c.get(e[0]))==null?void 0:H.data:void 0,y=e.map(G=>{var J,te;return((te=(J=c.get(G))==null?void 0:J.data.config)==null?void 0:te.typeView)??""}),b=y.some(G=>G!==y[0]),v=b?"mixed":y[0]??"",g=e.some(G=>{var te,le;const J=(te=c.get(G))==null?void 0:te.data;return J&&(l.has(G)||((le=J.config)==null?void 0:le.parentContainer)||Object.prototype.hasOwnProperty.call(i.customViews??{},J.type))}),w=(N=m==null?void 0:m.config)==null?void 0:N.collapsed,x=im(e[0]),_=G=>{var J,te,le;return(((te=(J=c.get(G))==null?void 0:J.data.viewProps)==null?void 0:te.outline)??(l.has(G)?(le=i.parentNodeStyle)==null?void 0:le.outline:!1))===!0},C=e.every(_),S=!C&&e.some(_),T=G=>{var J;return((J=c.get(G))==null?void 0:J.data.isNodeAnimated)===!0},k=e.every(T),E=!k&&e.some(T),P=e.map(G=>{var J;return((J=c.get(G))==null?void 0:J.data.nodeAnimationVariant)??"traveling"}),R=P.every(G=>G===P[0])?P[0]:"",I=G=>e.forEach(G),[O,M]=j.useState(!1),q=O&&f("color")&&f("borderColor"),K=G=>{var J,te,le;return(((te=(J=c.get(G))==null?void 0:J.data.viewProps)==null?void 0:te.borderStyle)??(l.has(G)?(le=i.parentNodeStyle)==null?void 0:le.borderStyle:"solid"))==="dashed"},V=e.every(K),re=!V&&e.some(K),ce=e.map(G=>{var le,de,Re;const J=(le=c.get(G))==null?void 0:le.data,te=l.has(G)?Ht((de=i.parentNodeStyle)==null?void 0:de.borderWidth,6):(J==null?void 0:J.type)==="objectView"?3:2;return Ht((Re=J==null?void 0:J.viewProps)==null?void 0:Re.borderWidth,te)}),he=ce.every(G=>G===ce[0])?String(ce[0]??""):"",me=G=>I(J=>{var te,le;q?(te=r.onNodeBorderColorChange)==null||te.call(r,J,G):(le=r.onNodeColorChange)==null||le.call(r,J,"bg",G)});return h.jsxs(h.Fragment,{children:[h.jsx(pt,{onClick:t}),h.jsx(ur,{}),p&&f("label")?h.jsx(Qr,{ariaLabel:"Node label",placeholder:"Node label",value:(m==null?void 0:m.label)??(m==null?void 0:m.headerTitle)??"",onCommit:G=>{var J;return(J=r.onNodeLabelChange)==null?void 0:J.call(r,e[0],G)}}):h.jsxs(F.Text,{fontSize:"xs",color:s,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),f("typeView")&&h.jsxs(Or,{"aria-label":"Type view",title:g?"Type view is managed by the custom renderer or container":`Type view: ${v||"None (default)"}`,icon:h.jsx(Z.PiImage,{size:20}),style:{width:36},value:v,disabled:i.readOnly||i.editable===!1||g,onValueChange:G=>{Bt.includes(G)&&I(J=>{var te,le;(te=r.onNodeTypeViewChange)==null||te.call(r,J,G||void 0),a(J,"default"),(le=r.onNodeViewToggle)==null||le.call(r,J)})},children:[b&&h.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),Bt.map(G=>h.jsx("option",{value:G,children:G||"None"},G))]}),f("style")&&h.jsx(lm,{ids:e},e.join("\0")),f("outline")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(je,{label:C?"Restore node fill":"Remove node fill",children:h.jsx(ve,{"aria-label":"Toggle node outline","aria-pressed":S?"mixed":C,icon:h.jsx(F.Icon,{as:C?Z.PiSquare:Z.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:C?o:u,onClick:()=>I(G=>{var J;return(J=r.onNodeOutlineChange)==null?void 0:J.call(r,G,!C)})})})]}),f("color")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),f("borderColor")&&h.jsx(je,{label:q?"Edit node colors":"Edit node border",children:h.jsx(ve,{"aria-label":"Edit node border","aria-pressed":q,icon:h.jsx(F.Icon,{as:Z.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:q?o:u,bg:q?n==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>M(G=>!G)})}),h.jsx(Kt,{label:q?"Border color":"Background",colors:d,value:q?((D=m==null?void 0:m.viewProps)==null?void 0:D.borderColor)??(p&&l.has(e[0])?(W=i.parentNodeStyle)==null?void 0:W.borderColor:void 0):(z=m==null?void 0:m.viewProps)==null?void 0:z.bgColor,onPick:me,onReset:()=>me("")}),q&&f("style")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(je,{label:V?"Solid border":"Dashed border",children:h.jsx(ve,{"aria-label":"Toggle dashed border","aria-pressed":re?"mixed":V,icon:h.jsx(F.Icon,{as:V?Z.PiLineSegments:Z.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:V?o:u,onClick:()=>I(G=>{var J;return(J=r.onNodeBorderStyleChange)==null?void 0:J.call(r,G,V?"solid":"dashed")})})}),h.jsx(Qr,{ariaLabel:"Border thickness",placeholder:p?"Auto":"Mixed",width:"64px",type:"number",min:0,value:he,onCommit:G=>I(J=>{var te;return(te=r.onNodeBorderWidthChange)==null?void 0:te.call(r,J,G===""?void 0:Number(G))})})]})]}),f("animation")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(je,{label:k?"Stop border animation":"Animate node border",children:h.jsx(ve,{"aria-label":"Toggle node animation","aria-pressed":E?"mixed":k,icon:h.jsx(F.Icon,{as:Z.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:k?o:u,onClick:()=>I(G=>{var J;return(J=r.onNodeAnimationChange)==null?void 0:J.call(r,G,!k)})})}),(k||E)&&h.jsx(am,{label:"Node animation",value:R,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:i.readOnly,onChange:G=>I(J=>{var te;return(te=r.onNodeAnimationVariantChange)==null?void 0:te.call(r,J,G)})})]}),!q&&f("textColor")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Kt,{label:"Text color",colors:sm,value:(X=m==null?void 0:m.viewProps)==null?void 0:X.textColor,onPick:G=>I(J=>{var te;return(te=r.onNodeColorChange)==null?void 0:te.call(r,J,"text",G)}),onReset:()=>I(G=>{var J;return(J=r.onNodeColorChange)==null?void 0:J.call(r,G,"text","")})})]}),p&&f("icon")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(qu,{nodeId:e[0],value:(se=m==null?void 0:m.config)==null?void 0:se.icon},e[0]),h.jsx(Qr,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((Q=m==null?void 0:m.config)==null?void 0:Q.icon)||"",onCommit:G=>{var J;return(J=r.onNodeIconChange)==null?void 0:J.call(r,e[0],G)}})]}),p&&x&&f("collapse")&&w!==void 0&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(je,{label:w?"Expand":"Collapse",children:h.jsx(ve,{"aria-label":w?"Expand node":"Collapse node",icon:h.jsx(F.Icon,{as:w?Z.PiArrowsOutLineVertical:Z.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:u,onClick:()=>{var G;return(G=r.onNodeCollapse)==null?void 0:G.call(r,e[0],!w)}})})]}),f("delete")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(je,{label:p?"Delete node":`Delete ${e.length} nodes`,children:h.jsx(ve,{"aria-label":"Delete selected nodes",icon:h.jsx(F.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:n==="dark"?"red.300":"red.500",onClick:()=>{I(G=>{var J,te;return(te=r.onNodeDelete)==null?void 0:te.call(r,G,((J=c.get(G))==null?void 0:J.data)||{id:G})}),t()}})})]})]})}async function fm(e){const{toSvg:t}=await Promise.resolve().then(()=>require("./index-sHQXTNv9.cjs"));await document.fonts.ready;const r=await t(e,{filter:o=>!(o instanceof Element)||!o.matches("button, [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(r.slice(r.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()),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(n))}`}async function hm(e,t="squeed.svg"){const r=document.createElement("a");r.href=await fm(e),r.download=t.endsWith(".svg")?t:`${t}.svg`,r.click()}function pm(){const{themeColor:e}=Ie(),[t,r]=j.useState(!1),[n,o]=j.useState("");return h.jsxs(h.Fragment,{children:[h.jsx(je,{label:"Download SVG (current view)",children:h.jsx(ve,{"aria-label":"Download SVG",icon:h.jsx(Z.PiDownloadSimpleFill,{size:20}),disabled:t,borderRadius:"30%",color:e,variant:"ghost",onClick:async i=>{var s;const a=(s=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:s.querySelector("[data-flow-background]");if(!a){o("Diagram not available for export.");return}r(!0),o("");try{await hm(a)}catch(u){o(u instanceof Error?u.message:"Unable to export SVG.")}finally{r(!1)}}})}),n&&h.jsx("span",{role:"alert",style:{fontSize:12,maxWidth:220},children:n})]})}function gm({children:e,background:t,border:r}){const n=j.useRef(null),[o,i]=j.useState({left:!1,right:!1});j.useLayoutEffect(()=>{const s=n.current,u=()=>{const l=s.scrollLeft>1,d=s.scrollWidth-s.clientWidth-s.scrollLeft>1;i(f=>f.left===l&&f.right===d?f:{left:l,right:d})},c=new ResizeObserver(u);return c.observe(s),s.firstElementChild&&c.observe(s.firstElementChild),s.addEventListener("scroll",u,{passive:!0}),u(),()=>{c.disconnect(),s.removeEventListener("scroll",u)}},[]);const a=`var(--chakra-colors-${t.replace(".","-")})`;return h.jsxs(F.Box,{position:"relative",bg:t,minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:"30px",css:Dr(a,`var(--chakra-colors-${r.replace(".","-")})`),children:[h.jsx(F.Box,{ref:n,"data-flow-toolbar-scroll":"",h:50,minH:50,alignContent:"center",overflowX:"auto",overflowY:"hidden",borderRadius:"inherit",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e}),["left","right"].map(s=>h.jsx(F.Box,{"data-flow-toolbar-fade":s,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",borderRadius:s==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[s]:0,opacity:o[s]?1:0,background:`linear-gradient(to ${s==="left"?"right":"left"}, ${a}, transparent)`}},s))]})}async function s0(e,t){const r=new Set,n=[],o=(s,u)=>{var l,d,f;if(!s||typeof s!="object")return;const c=s;n.push(u),typeof((l=c.$form)==null?void 0:l.$type)=="string"&&r.add(c.$form.$type),typeof((f=(d=c.$form)==null?void 0:d.$create)==null?void 0:f.$type)=="string"&&r.add(c.$form.$create.$type);for(const[p,m]of Object.entries(c))p==="$"?o(m,u):p.startsWith("$")||o(m,`${u}.${p}`)};if(o(t,"root"),!r.size)return{contract:await rm(e)};const i=await Mu(e,[...r]);for(const s of r)if(!Object.prototype.hasOwnProperty.call(i,s))throw new Error(`Missing form type: ${s}`);const a={};for(const s of n){const u=gt(t,s,i);u&&(a[s]={type:u.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:a}}}function ym({message:e,onDismiss:t}){const{background:r,colorText:n,border:o}=Ve();return!e||typeof document>"u"?null:Ft.createPortal(h.jsxs(F.chakra.div,{role:"alert","aria-atomic":"true",css:Dr(fe(r),fe(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:fe(r),color:fe(n),fontSize:14,lineHeight:1.5},children:[h.jsx(Z.PiWarningCircle,{size:20,"aria-hidden":"true",style:{flexShrink:0,color:"#ef4444"}}),h.jsxs("div",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:[h.jsx("strong",{children:"Interface upload failed"}),h.jsx("div",{children:e})]}),h.jsx(pt,{type:"button","aria-label":"Dismiss upload error",title:"Dismiss upload error",onClick:t,flexShrink:0,width:"24px",height:"24px",minWidth:"24px",padding:0})]}),document.body)}function mm({showDivider:e=!0,compact:t=!1}={}){const{edgeMode:r,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:a,readOnly:s,themeColor:u}=Ie(),{edgeById:c}=Gr(),{data:l,schema:d,setSchema:f,bindings:p,structured:m}=j.useContext(kr),y=(m==null?void 0:m.sourceBindings)??p,b=(m==null?void 0:m.sourceSchema)??d,{colorText:v}=Ve(),g=j.useRef(null),w=j.useRef(0),[x,_]=j.useState(!1),[C,S]=j.useState("");j.useEffect(()=>()=>{w.current++},[]),j.useEffect(()=>{w.current++,_(!1)},[s,l,y]);const T=o?[...c.values()].filter(E=>Iu(o,E.data)).length:0,k=o?`${o.name}: ${b?`${Object.keys(b).length} form types loaded; `:""}${T} invalid or unverified connections`:"";return h.jsxs(h.Fragment,{children:[h.jsx(ym,{message:C,onDismiss:()=>S("")}),e&&h.jsx(It,{}),h.jsxs(Or,{"aria-label":"Edge mode",title:r==="auto"?"Connections: Auto":r==="properties"?"Connections: Properties":"Connections: Nodes",icon:r==="auto"?h.jsx(Z.PiGraph,{size:20}):r==="properties"?h.jsx(Z.PiTable,{size:20}):h.jsx(Z.PiTreeStructure,{size:20}),style:{width:36},value:r,disabled:s,onValueChange:E=>{var R;const P=E==="auto"?"auto":E==="properties"?"properties":"nodes";n(P),(R=a.onEdgeModeChange)==null||R.call(a,P)},children:[h.jsx("option",{value:"auto",children:"Auto"}),h.jsx("option",{value:"nodes",children:"Nodes"}),h.jsx("option",{value:"properties",children:"Properties"})]}),h.jsxs("span",{style:{display:r==="auto"||r==="properties"?"contents":"none"},children:[h.jsx(je,{label:o?`Replace ${o.name}`:"Upload workflow interface",children:h.jsx(ve,{"aria-label":"Upload workflow interface",icon:h.jsx(Z.PiUploadSimple,{size:20}),color:fe(u),size:"sm",variant:"ghost",disabled:x||s,onClick:()=>{var E;return(E=g.current)==null?void 0:E.click()}})}),h.jsx("input",{ref:g,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:s||x,onChange:async E=>{var I,O;const P=(I=E.target.files)==null?void 0:I[0];if(E.target.value="",!P)return;const R=++w.current;_(!0),S("");try{const M=y?await Mu(P,[...new Set(Object.values(y).map(V=>V.schemaType??V.type))]):void 0;if(y&&M){for(const V of Object.values(y))if(!Object.prototype.hasOwnProperty.call(M,V.schemaType??V.type))throw new Error(`Missing form type: ${V.schemaType??V.type}`)}const{contract:q,schema:K}=y&&M?{schema:M,contract:{name:P.name,nodes:Object.fromEntries(Object.entries(y).map(([V,re])=>[V,{type:M[re.schemaType??re.type],optional:!1}]))}}:await s0(P,l);if(R!==w.current)return;f==null||f(K),i(q),(O=a.onWorkflowContractChange)==null||O.call(a,q)}catch(M){R===w.current&&S(`${P.name}: ${M instanceof Error?M.message:"Unable to load interface."}`)}finally{R===w.current&&_(!1)}}}),!t&&(k||x)&&h.jsx("span",{role:"status",title:k,style:{color:fe(v),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:x?"Loading interface...":k}),!t&&o&&h.jsx(je,{label:"Remove workflow interface",children:h.jsx(ve,{"aria-label":"Remove workflow interface",icon:h.jsx(Z.PiX,{size:16}),size:"sm",variant:"ghost",disabled:s||x,onClick:()=>{var E;f==null||f(void 0),i(void 0),(E=a.onWorkflowContractChange)==null||E.call(a,void 0),S("")}})})]})]})}const c0=[{value:"BT",label:"Bottom to Up",icon:Z.PiArrowUp,flowType:Et.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:Z.PiArrowDown,flowType:Et.TOP_DOWN},{value:"LR",label:"Left to Right",icon:Z.PiArrowRight,flowType:Et.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:Z.PiArrowLeft,flowType:Et.RIGHT_LEFT}],bm=()=>{const{engineRef:e,themeColor:t,setThemeColor:r,backgroundSelected:n,setBackgroundSelected:o,direction:i,edgeMode:a,selectedNodeIds:s,setSelectedNodeIds:u,selectedEdgeId:c,setSelectedEdgeId:l,isZoomMode:d,setIsZoomMode:f,isMultiSelectMode:p,setIsMultiSelectMode:m,isDragMode:y,setIsDragMode:b,isEdgeHandlesEnabled:v,setIsEdgeHandlesEnabled:g,isArrayNodeMode:w,setIsArrayNodeMode:x,isPinned:_,setIsPinned:C,callbacks:S,config:T,readOnly:k}=Ie(),{nodeById:E,edgeById:P,parentIds:R}=Gr(),I=T.colorMode==="dark",{background:O,border:M,colorInactive:q,colorText:K,colorActive:V}=Ve(),re=`var(--chakra-colors-${O.replace(".","-")})`,ce=`var(--chakra-colors-${(I?M:"gray.300").replace(".","-")})`,[he,me]=j.useState(!1),[H,N]=j.useState(!0),D=j.useRef(null),W=hy({edge:"bottom",enabled:!_,bounds:D,inside:[D]}),z=j.useCallback(be=>{const _e=e.current;if(!_e)return;const Xe=T.minZoom??.01,Ke=T.maxZoom??1.5,Ne=.02;let Qe=_e.zoom();switch(be){case"increase":Qe=Math.min(Ke,Qe+Ne),_e.zoom(Qe),_e.center();break;case"decrease":Qe=Math.max(Xe,Qe-Ne),_e.zoom(Qe),_e.center();break;case"reset":_e.fit(50);break}},[e,T.minZoom,T.maxZoom]),X=T.renderSelectedNodeToolbar,se=s.length>0&&!!X,Q=j.useMemo(()=>se?s.map(be=>{var Xe;return{...((Xe=E.get(be))==null?void 0:Xe.data)??{id:be},isParent:R.has(be)}}):[],[se,s,E,R]),G=j.useCallback(()=>{var be;u([]),(be=S.onNodeDeselect)==null||be.call(S)},[u,S]),J=T.renderSelectedEdgeToolbar,te=!!c&&!!J,le=j.useMemo(()=>{var be;return!te||!c?null:((be=P.get(c))==null?void 0:be.data)??{id:c}},[te,c,P]),de=j.useCallback(()=>{var be;l(null),(be=S.onEdgeDeselect)==null||be.call(S)},[l,S]),Re=T.selectionToolbar!==!1&&!k,ge=Re&&!!c&&!J,ze=Re&&!ge&&s.length>0&&!X,Fe=ge||ze,He=_||W||he||Fe;j.useEffect(()=>{s.length||c?o(!1):n&&!k&&(C(!0),N(!1))},[n,s.length,c,k,o,C]);const ar=T.renderBottomBar;return ar?h.jsxs(h.Fragment,{children:[se&&h.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:X({selectedNodeIds:s,selectedNodeData:Q,onDeselect:G})}),te&&le&&h.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:J({edgeId:c,edgeData:le,onDeselect:de})}),h.jsx(F.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:ar({zoomIn:()=>z("increase"),zoomOut:()=>z("decrease"),resetZoom:()=>z("reset"),direction:i,isZoomMode:d,setIsZoomMode:f,isMultiSelectMode:p,setIsMultiSelectMode:m,isDragMode:y,setIsDragMode:b,isEdgeHandlesEnabled:v,setIsEdgeHandlesEnabled:g,isArrayNodeMode:w,setIsArrayNodeMode:x,selectedNodeIds:s,selectedNodeData:Q,selectedEdgeId:c,selectedEdgeData:le,onNodeDeselect:G,onEdgeDeselect:de,callbacks:S})})]}):h.jsxs(h.Fragment,{children:[se&&h.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:X({selectedNodeIds:s,selectedNodeData:Q,onDeselect:G})}),te&&le&&h.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:J({edgeId:c,edgeData:le,onDeselect:de})}),h.jsx(F.Box,{ref:D,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:He?"translateY(0)":"translateY(100%)",pointerEvents:He?"auto":"none",visibility:He?"visible":"hidden",opacity:He?1:0,children:h.jsxs(F.Flex,{w:"100%",px:5,position:"absolute",bottom:5,flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:"24px",children:[h.jsx(gm,{background:O,border:I?M:"gray.300",children:h.jsxs(F.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[ge?h.jsx(um,{edgeId:c,onClose:de}):ze?h.jsx(dm,{ids:s,onClose:G}):null,h.jsxs("div",{style:{display:ge||ze?"none":"contents"},children:[h.jsx(je,{label:_?"Unpin":"Pin",children:h.jsx(ve,{"aria-label":"Pin",icon:h.jsx(F.Icon,{as:_?Z.PiPushPinFill:Z.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:_?t:q,onClick:()=>{C(!_),me(!1)}})}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:"Zoom Out",children:h.jsx(ve,{"aria-label":"Zoom out",icon:h.jsx(F.Icon,{as:Z.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:K,onClick:()=>z("decrease")})}),h.jsx(je,{label:"Zoom In",children:h.jsx(ve,{"aria-label":"Zoom in",icon:h.jsx(F.Icon,{as:Z.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:K,onClick:()=>z("increase")})}),h.jsx(je,{label:"Reset Zoom",children:h.jsx(ve,{"aria-label":"Reset zoom",icon:h.jsx(F.Icon,{as:Z.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:K,onClick:()=>z("reset")})}),!H&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:d?"Zoom Mode (z)":"Pan Mode (z)",children:h.jsx(ve,{"aria-label":"Toggle zoom mode",icon:h.jsx(F.Icon,{as:d?Z.PiMagnifyingGlassPlus:Z.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:d?t:q,onClick:()=>f(!d)})}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:p?"Multi-Select On (m)":"Multi-Select Off (m)",children:h.jsx(ve,{"aria-label":"Toggle multi-select",icon:h.jsx(F.Icon,{as:Z.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:p?t:q,onClick:()=>m(!p)})}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:y?"Drag Mode On (d)":"Drag Mode Off (d)",children:h.jsx(ve,{"aria-label":"Toggle drag mode",icon:h.jsx(F.Icon,{as:Z.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:y?t:q,onClick:()=>b(!y)})}),T.edgeHandles!==!1&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:v?"Draw Mode On":"Draw Mode Off",children:h.jsx(ve,{"aria-label":"Toggle draw mode",icon:h.jsx(F.Icon,{as:Z.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:v?t:q,onClick:()=>g(!v)})})]}),T.bottomBarExtra&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M,role:"separator","aria-orientation":"vertical"}),T.bottomBarExtra]}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M,role:"separator","aria-orientation":"vertical"}),h.jsx(zy,{}),a!=="properties"&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:w?"Array Mode [ ]":"Set Mode { }",children:h.jsx(ve,{"aria-label":"Toggle array mode",icon:h.jsx(F.Icon,{as:w?Z.PiBracketsSquare:Z.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:w?t:q,onClick:()=>{var _e;const be=!w;x(be),(_e=S.onArrayModeChange)==null||_e.call(S,be)}})})]}),n&&!k&&h.jsxs(h.Fragment,{children:[h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(Kt,{label:"Graph theme",colors:Nu,value:t,includeTransparent:!1,onPick:be=>{var _e;r(be),(_e=S.onThemeColorChange)==null||_e.call(S,be)}})]}),h.jsx(mm,{}),h.jsx(Wy,{})]}),h.jsx(F.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:M}),h.jsx(je,{label:H?"Expand toolbar":"Collapse toolbar",children:h.jsx(ve,{"aria-label":"Toggle toolbar collapse",icon:h.jsx(F.Icon,{as:H?Z.PiCaretRight:Z.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:q,onClick:()=>N(!H)})}),!H&&h.jsx(pm,{})]})]})}),!Fe&&h.jsxs(F.Box,{position:"relative",ml:"auto",flexShrink:0,children:[h.jsx(F.Box,{"data-flow-direction-control":"",bg:O,borderRadius:"30px",h:50,css:Dr(re,ce),px:3,cursor:"pointer",onClick:()=>me(!he),children:h.jsxs(F.Flex,{align:"center",h:"100%",children:[h.jsx(je,{label:"Flow Direction",children:h.jsx(ve,{"aria-label":"Direction",icon:h.jsx(F.Icon,{as:Z.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:q})}),h.jsx(F.Text,{fontSize:"xs",color:I?"whiteAlpha.600":"blackAlpha.500",ml:1,children:i})]})}),he&&h.jsx(F.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:h.jsxs(F.Box,{bg:O,borderRadius:"30px",p:2,minW:"180px",css:Dr(re,ce),children:[c0.map(be=>h.jsxs(F.Flex,{align:"center",gap:3,px:3,py:2,borderRadius:"30px",cursor:"pointer",_hover:{bg:I?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var _e;(_e=S.onDirectionChange)==null||_e.call(S,be.value),me(!1)},children:[h.jsx(F.Icon,{as:be.icon,boxSize:5,color:K}),h.jsx(F.Text,{fontSize:"sm",color:K,flex:1,whiteSpace:"nowrap",children:be.label}),i===be.value&&h.jsx(F.Icon,{as:Z.PiCheck,boxSize:4,color:V})]},be.value)),h.jsxs(F.Flex,{align:"center",gap:3,px:3,py:2,borderRadius:"10px",cursor:"pointer",_hover:{bg:I?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var be;(be=S.onDirectionChange)==null||be.call(S,"C"),me(!1)},children:[h.jsx(F.Icon,{as:Z.PiAlignCenterHorizontal,boxSize:5,color:K}),h.jsx(F.Text,{fontSize:"sm",color:K,flex:1,whiteSpace:"nowrap",children:"Center"}),i==="C"&&h.jsx(F.Icon,{as:Z.PiCheck,boxSize:4,color:V})]})]})})]})]})})]})};bm.displayName="BottomBar";const vm=j.memo(bm);function u0({checked:e,onChange:t,disabled:r,label:n="Connected nodes"}){return h.jsx(Dy,{label:n,checked:e,onChange:t,disabled:r,icon:h.jsx(F.Icon,{as:Z.PiGraph,boxSize:5})})}const kl={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function xm(e,t){const r=new Map,n=(i,a)=>{if(Object.is(i,a))return!0;if(!i||!a||typeof i!="object"||typeof a!="object"||Array.isArray(i)!==Array.isArray(a))return!1;const s=Object.keys(i);return s.length===Object.keys(a).length&&s.every(u=>Object.prototype.hasOwnProperty.call(a,u)&&n(i[u],a[u]))},o=(i,a,s)=>{if(i===a)return!0;if(!i||!a||typeof i!="object"||typeof a!="object"||Array.isArray(i)!==Array.isArray(a))return!1;const u=new Set([...Object.keys(i),...Object.keys(a)]);for(const c of u)if(!n(i[c],a[c])){if(Object.prototype.hasOwnProperty.call(kl,c)){if(typeof a[c]!="string"||!a[c])return!1;r.set(s,{...r.get(s),[kl[c]]:a[c]})}else if(c.startsWith("$")&&c!=="$"||!o(i[c],a[c],c==="$"?s:`${s}.${c}`))return!1}return!0};if(o(e,t,"root"))return r}function l0(e,t){return xm(e,t)!==void 0}function d0(e,t,r){if(e===t)return r;const n=xm(e,t);if(!n)return;const o=new Set(r.nodes.map(i=>i.data.id));for(const i of n.keys())if(!o.has(i)||!xe(t,i))return;return{edges:r.edges,nodes:r.nodes.map(i=>{const a=n.get(i.data.id),s=xe(e,i.data.id),u=xe(t,i.data.id);return!a&&s===u?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(u,null,2)}:{},...a?{viewProps:{...i.data.viewProps,...a},config:{...i.data.config,...a}}:{}}}})}}function xu(e){return e.kind==="literal"?e.value:e.kind==="union"?xu(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,t])=>!t.optional).map(([t,r])=>[t,xu(r.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function wm(e,t,r){var b,v,g;const n=(b=xe(e,t))==null?void 0:b.$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(!r||!Object.prototype.hasOwnProperty.call(r,o.$type))throw new Error(`Load form type: ${o.$type}`);const a=i.pop(),s=["root",...i].join("."),u=gt(e,s,r),c=(v=u==null?void 0:u.type.properties[a])==null?void 0:v.type;if((c==null?void 0:c.kind)!=="array"||c.items.kind!=="object")throw new Error("Form creation must target an object-array field.");const l=r[o.$type],d=o.$defaults??{};for(const[w,x]of Object.entries(d))if(!Object.prototype.hasOwnProperty.call(l.properties,w)||Rr(l.properties[w].type,x,!l.properties[w].optional))throw new Error(`Invalid creation default: ${w}`);const f={...xu(l),...structuredClone(d)};((g=l.properties.id)==null?void 0:g.type.kind)==="string"&&(f.id=ju());let p=e;const m=xe(e,o.$address);if(m===void 0)p=pr(e,s,w=>({...w,[a]:[]}));else if(!Array.isArray(m)&&!Array.isArray(m==null?void 0:m.$))throw new Error("Form creation destination is not an array.");const y=Pu(p,o.$address,{...f,$label:o.$label??o.$type,...o.$icon?{$icon:o.$icon}:{},$form:{$type:o.$type,$create:o}});return{address:y.address,json:Au(y.json,t,{target:y.address,label:o.$edgeLabel})}}function f0(e,t){const r=o=>e&&typeof e=="object"&&o in e;let n=1;for(;r(`${t}_${n}`);)n++;return`${t}_${n}`}function Cm(e,t,r,n,o){const i=(s,u)=>{s!==e&&(e=s,n==null||n(s,u))},a=s=>{var c;const u=(c=t.find(l=>l.data.id===s))==null?void 0:c.data;return u&&{source:u.source,target:u.target,isInverted:u.isInverted,sourceProperty:u.sourceProperty,targetProperty:u.targetProperty,connection:u.connection}};return{...r,onFormChange:s=>{const u=xe(e,s.nodeAddress);if(!u||s.nodeId!==void 0&&u.id!==s.nodeId)throw new Error("This form node has moved. Retry the edit.");i(wn(e,s,r.onFormChange),{type:"form",address:s.address,value:s.value})},onNodeLabelChange:(s,u)=>{var c;(c=r.onNodeLabelChange)==null||c.call(r,s,u),i(ir(e,s,"$label",u),{type:"nodeLabel",address:s,key:"$label",value:u})},onNodeContentChange:(s,u)=>{var c;(c=r.onNodeContentChange)==null||c.call(r,s,u),i(ir(e,s,"$content",u),{type:"nodeContent",address:s,key:"$content",value:u})},onNodeTypeViewChange:(s,u)=>{var c;u!==void 0&&!Bt.includes(u)||((c=r.onNodeTypeViewChange)==null||c.call(r,s,u),i(ir(e,s,"$view",u),{type:"nodeStyle",address:s,key:"$view",value:u}))},onNodeColorChange:(s,u,c)=>{var d;(d=r.onNodeColorChange)==null||d.call(r,s,u,c);const l=u==="bg"?"$bgColor":"$textColor";i(ir(e,s,l,c),{type:"nodeColor",address:s,key:l,value:c})},onNodeBorderColorChange:(s,u)=>{var c;(c=r.onNodeBorderColorChange)==null||c.call(r,s,u),i(ir(e,s,"$borderColor",u),{type:"nodeColor",address:s,key:"$borderColor",value:u})},onNodeBorderStyleChange:(s,u)=>{var c;(c=r.onNodeBorderStyleChange)==null||c.call(r,s,u),i(ir(e,s,"$borderStyle",u),{type:"nodeStyle",address:s,key:"$borderStyle",value:u})},onNodeBorderWidthChange:(s,u)=>{var c;u!==void 0&&(!Number.isFinite(u)||u<0)||((c=r.onNodeBorderWidthChange)==null||c.call(r,s,u),i(ir(e,s,"$borderWidth",u),{type:"nodeStyle",address:s,key:"$borderWidth",value:u}))},onNodeBorderRadiusChange:(s,u)=>{var c;u!==void 0&&(!Number.isFinite(u)||u<0)||((c=r.onNodeBorderRadiusChange)==null||c.call(r,s,u),i(ir(e,s,"$borderRadius",u),{type:"nodeStyle",address:s,key:"$borderRadius",value:u}))},onNodeIconChange:(s,u)=>{var c;(c=r.onNodeIconChange)==null||c.call(r,s,u),i(ir(e,s,"$icon",u),{type:"nodeIcon",address:s,key:"$icon",value:u})},onNodeOutlineChange:(s,u)=>{var c;(c=r.onNodeOutlineChange)==null||c.call(r,s,u),i(ir(e,s,"$outline",u),{type:"nodeOutline",address:s,key:"$outline",value:u})},onNodeAnimationChange:(s,u)=>{var c;(c=r.onNodeAnimationChange)==null||c.call(r,s,u),i(ir(e,s,"$isNodeAnimated",u),{type:"nodeAnimation",address:s,key:"$isNodeAnimated",value:u})},onNodeAnimationVariantChange:(s,u)=>{var c;u!=="traveling"&&u!=="pulse"||((c=r.onNodeAnimationVariantChange)==null||c.call(r,s,u),i(ir(e,s,"$nodeAnimationVariant",u),{type:"nodeAnimation",address:s,key:"$nodeAnimationVariant",value:u}))},onNodeCollapse:(s,u)=>{var c;(c=r.onNodeCollapse)==null||c.call(r,s,u),i(Zy(e,s,u),{type:"nodeCollapse",address:s,key:"$collapsed",value:u})},onNodeCreate:s=>{var p,m;const u=s.sourceNodeId&&wm(e,s.sourceNodeId,o);if(u){(p=r.onNodeCreate)==null||p.call(r,s),i(u.json,{type:"nodeCreate",address:u.address,value:"form"});return}(m=r.onNodeCreate)==null||m.call(r,s);const c=s.sourceNodeId||"root",l=xe(e,c),d=f0(l,s.isArrayMode?"list":"node"),f=Pu(e,c,s.isArrayMode?[]:{},d);i(f.json,{type:"nodeCreate",address:f.address,value:s.isArrayMode?"array":"set"})},onNodeDelete:(s,u)=>{var c;(c=r.onNodeDelete)==null||c.call(r,s,u),i(Yy(e,s),{type:"nodeDelete",address:s})},onEdgeCreate:(s,u,c)=>{var d;(d=r.onEdgeCreate)==null||d.call(r,s,u,c);const l=c&&(c.sourceProperty!==void 0||c.targetProperty!==void 0)?{...c,target:u}:void 0;i(l?Au(e,s,l):Xy(e,s,u),{type:"edgeCreate",address:s,key:l?"$connections":"$target",value:l??u})},onEdgeLabelChange:(s,u)=>{var l;(l=r.onEdgeLabelChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$sourceLabel",u),{type:"edgeLabel",edge:c,key:c.connection?"$connections":"$sourceLabel",value:u})},onEdgeStyleChange:(s,u)=>{var l;(l=r.onEdgeStyleChange)==null||l.call(r,s,u);const c=a(s);c&&i(Jy(e,c,u),{type:"edgeStyle",edge:c,value:u})},onEdgeAnimationVariantChange:(s,u)=>{var l;if(u!=="dashed"&&u!=="traveling")return;(l=r.onEdgeAnimationVariantChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$edgeAnimationVariant",u),{type:"edgeStyle",edge:c,key:c.connection?"$connections":"$edgeAnimationVariant",value:u})},onEdgeTypeChange:(s,u)=>{var l;(l=r.onEdgeTypeChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$edgeType",u),{type:"edgeStyle",edge:c,key:c.connection?"$connections":"$edgeType",value:u})},onEdgeIconChange:(s,u)=>{var l;(l=r.onEdgeIconChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$edgeIcon",u||void 0),{type:"edgeStyle",edge:c,key:c.connection?"$connections":"$edgeIcon",value:u})},onEdgeColorChange:(s,u)=>{var l;(l=r.onEdgeColorChange)==null||l.call(r,s,u);const c=a(s);c&&i(Fr(e,c,"$edgeColor",u),{type:"edgeColor",edge:c,key:c.connection?"$connections":"$edgeColor",value:u})},onEdgeDelete:(s,u)=>{var d;(d=r.onEdgeDelete)==null||d.call(r,s,u);const c=a(s);if(!c)return;const l=Qy(e,c);l.removed&&i(l.json,{type:"edgeDelete",edge:c,key:c.connection?"$connections":"$target"})}}}const h0=".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 p0({path:e,color:t,width:r,reversed:n}){return h.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:t,strokeWidth:r,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 100"})}const g0=".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 _m({x:e=0,y:t=0,width:r,height:n,radius:o,color:i,strokeWidth:a=8,path:s,variant:u="traveling"}){const c=j.useId(),l=`flow-sdk-node-border-animation${u==="pulse"?" flow-sdk-node-border-pulse":""}`;if(u==="pulse"){const d=s?"path":"rect",f=s?{d:s}:{x:e,y:t,width:Math.max(0,r),height:Math.max(0,n),rx:Math.max(0,Math.min(o,r/2,n/2))},p=a+36,m={x:e-p,y:t-p,width:r+2*p,height:n+2*p};return h.jsxs("g",{"aria-hidden":"true",pointerEvents:"none",children:[h.jsx("defs",{children:h.jsxs("mask",{id:c,maskUnits:"userSpaceOnUse",...m,style:{maskType:"luminance"},children:[h.jsx("rect",{...m,fill:"white"}),h.jsx(d,{...f,fill:"black",stroke:"black",strokeWidth:a,strokeLinejoin:"round"})]})}),h.jsx(d,{...f,className:l,"data-animation-variant":u,fill:"none",stroke:`color-mix(in srgb, ${i} 60%, transparent)`,strokeLinejoin:"round",mask:`url(#${c})`,style:{"--flow-pulse-rest-width":`${a+16}px`,"--flow-pulse-expanded-width":`${a+36}px`}})]})}return s?h.jsx("path",{className:l,"data-animation-variant":u,"aria-hidden":"true",pointerEvents:"none",d:s,fill:"none",stroke:i,strokeWidth:a,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"}):h.jsx("rect",{className:l,"data-animation-variant":u,"aria-hidden":"true",pointerEvents:"none",x:e,y:t,width:Math.max(0,r),height:Math.max(0,n),rx:Math.max(0,Math.min(o,r/2,n/2)),fill:"none",stroke:i,strokeWidth:a,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const y0=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 Pl(e,t,r){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const a of t)(a.parent===i||a.id.startsWith(`${i}.`)||r.some(u=>(u.inverted?u.target:u.source)===i&&(u.inverted?u.source:u.target)===a.id))&&!n.has(a.id)&&(n.add(a.id),o.push(a.id))}return n}function m0(e,t,r){const n=r==="downward"||r==="upward",o=new Map;for(const a of e){if(a.source===a.target||a.sourceProperty||a.targetProperty)continue;const s=t(a.source),u=t(a.target);if(!s||!u)continue;const c=n?u.y-s.y:u.x-s.x,l=Math.abs(c)-(n?s.h+u.h:s.w+u.w)/2;if(l<=320)continue;const d=JSON.stringify([a.source,Math.sign(c)]),f=o.get(d)??[];f.push({edge:a,gap:l,cross:n?u.x-s.x:u.y-s.y}),o.set(d,f)}const i=new Map;for(const a of o.values()){if(new Set(a.map(({edge:u})=>u.target)).size<2)continue;const s=new Map;for(const{edge:u}of a)s.set(u.target,(s.get(u.target)??0)+1);for(const u of[-1,0,1]){const c=a.filter(({cross:d})=>Math.sign(d)===u);c.sort((d,f)=>Math.abs(f.cross)-Math.abs(d.cross)||d.edge.id.localeCompare(f.edge.id));const l=Math.min(...c.map(({gap:d})=>d));c.forEach(({edge:d,gap:f,cross:p},m)=>{const y=c.length===1?l/2:120+(l-280)*m/(c.length-1),b=c.find(v=>Math.abs(v.cross)<Math.abs(p));i.set(d.id,{turn:y/f,labelAtTarget:s.get(d.target)===1,labelFraction:p?(p+((b==null?void 0:b.cross)??0))/(2*p):.5})})}}return i}const st=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}),b0=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function Yn(e){if(!e.length)return null;const t={...e[0]};for(let r=1;r<e.length;r++)t.x1=Math.min(t.x1,e[r].x1),t.y1=Math.min(t.y1,e[r].y1),t.x2=Math.max(t.x2,e[r].x2),t.y2=Math.max(t.y2,e[r].y2);return t}const v0=(e,t)=>e.x1<=t.x2&&e.x2>=t.x1&&e.y1<=t.y2&&e.y2>=t.y1,Al=(e,t)=>e.x>=t.x1&&e.x<=t.x2&&e.y>=t.y1&&e.y<=t.y2,lr=e=>(Math.round(e*10)/10).toString(),Ge=e=>`${lr(e.x)} ${lr(e.y)}`,x0=e=>e>0?1:e<0?-1:0,Tl=(e,t)=>e>0?Math.max(e-t,0):Math.min(e+t,0);function w0(e,t,r,n,o=10){const i=t.x-e.x,a=t.y-e.y,s=Tl(i,(e.w+t.w)/2),u=Tl(a,(e.h+t.h)/2),c=r==="downward"||r==="upward",l=c?u:s,d=c?a:i,f=x0(d),p=n*l,m=g=>Math.abs(g)<o||Math.abs(g)>=Math.abs(l),y=m(p)||m(Math.abs(l)-Math.abs(p));let b;if(y)if(c)if(Math.abs(d)<=e.h/2){const g=(e.x+t.x)/2;b=[g,e.y,g,t.y]}else if(Math.abs(i)<=t.w/2){const g=(e.y+t.y)/2;b=[e.x,g,t.x,g]}else b=[e.x,t.y];else if(Math.abs(d)<=e.w/2){const g=(e.y+t.y)/2;b=[e.x,g,t.x,g]}else if(Math.abs(a)<=t.h/2){const g=(e.x+t.x)/2;b=[g,e.y,g,t.y]}else b=[t.x,e.y];else if(c){const g=e.y+p+e.h/2*f;b=[e.x,g,t.x,g]}else{const g=e.x+p+e.w/2*f;b=[g,e.y,g,t.y]}const v=[{x:e.x,y:e.y}];for(let g=0;g<b.length;g+=2)v.push({x:b[g],y:b[g+1]});return v.push({x:t.x,y:t.y}),v}function C0(e,t,r){const n=t.x-e.x,o=t.y-e.y,i=n>0?(r.x2-e.x)/n:n<0?(r.x1-e.x)/n:1/0,a=o>0?(r.y2-e.y)/o:o<0?(r.y1-e.y)/o:1/0,s=Math.min(i,a);return!Number.isFinite(s)||s>=1||s<0?null:{x:e.x+n*s,y:e.y+o*s}}function ht(e,t,r){var a;if(!((a=r.outline)!=null&&a.length))return C0(e,t,st(r));const n=t.x-e.x,o=t.y-e.y;let i=1/0;return r.outline.forEach((s,u,c)=>{const l=c[(u+1)%c.length],d=l.x-s.x,f=l.y-s.y,p=n*f-o*d;if(Math.abs(p)<1e-9)return;const m=s.x-e.x,y=s.y-e.y,b=(m*f-y*d)/p,v=(m*o-y*n)/p;b>=0&&b<1&&v>=-1e-9&&v<=1+1e-9&&(i=Math.min(i,b))}),Number.isFinite(i)?{x:e.x+n*i,y:e.y+o*i}:null}function Sm(e,t,r=.5){const n=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.5,o=t==="top"||t==="bottom",i=t==="top"||t==="left"?-1:1,a={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},s=Math.max(e.w,e.h)*2+1;return{...ht(a,{x:a.x+(o?0:i*s),y:a.y+(o?i*s:0)},e)??{x:o?a.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:a.y},side:t}}function lt(e,t){return{x:e.x+(e.side==="right"?t:e.side==="left"?-t:0),y:e.y+(e.side==="bottom"?t:e.side==="top"?-t:0)}}function _0(e,t,r,n){const o=lt(e,r.srcDist),i=lt(t,r.tgtDist);if(n==="straight")return jm(o,i,r);const a=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),s=e.side==="bottom"&&t.side==="top"?i.y-o.y:e.side==="top"&&t.side==="bottom"?o.y-i.y:e.side==="right"&&t.side==="left"?i.x-o.x:e.side==="left"&&t.side==="right"?o.x-i.x:void 0,u=s!==void 0&&s>0?Math.min(a,s/2):a,c=lt({...o,side:e.side},u),l=lt({...i,side:t.side},u),d=r.arrowAt==="source"?rr(o,c,r.arrowGap):o,f=r.arrowAt==="target"?rr(i,l,r.arrowGap):i,p=r.arrowAt==="source"?br(o,c,r.arrowSize,r.headShape):r.arrowAt==="target"?br(i,l,r.arrowSize,r.headShape):void 0;if(n==="bezier")return{d:`M${Ge(d)} C${Ge(c)} ${Ge(l)} ${Ge(f)}`,arrow:p,label:{x:(d.x+3*c.x+3*l.x+f.x)/8,y:(d.y+3*c.y+3*l.y+f.y)/8,angle:0}};const m=e.side==="left"||e.side==="right",y=t.side==="left"||t.side==="right";let b;if(m!==y){const g=m?{x:l.x,y:c.y}:{x:c.x,y:l.y},w=(g.x-c.x)*(c.x-o.x)+(g.y-c.y)*(c.y-o.y)>=0,x=(g.x-l.x)*(l.x-i.x)+(g.y-l.y)*(l.y-i.y)>=0;b=[w&&x?g:m?{x:c.x,y:l.y}:{x:l.x,y:c.y}]}else if(s!==void 0&&s<=0)if(m){const g=(c.y+l.y)/2;b=[{x:c.x,y:g},{x:l.x,y:g}]}else{const g=(c.x+l.x)/2;b=[{x:g,y:c.y},{x:g,y:l.y}]}else if(m){const g=e.side===t.side?e.side==="right"?Math.max(c.x,l.x):Math.min(c.x,l.x):(c.x+l.x)/2;b=[{x:g,y:c.y},{x:g,y:l.y}]}else{const g=e.side===t.side?e.side==="bottom"?Math.max(c.y,l.y):Math.min(c.y,l.y):(c.y+l.y)/2;b=[{x:c.x,y:g},{x:l.x,y:g}]}const v=[c,...b,l].filter((g,w,x)=>w===0||g.x!==x[w-1].x||g.y!==x[w-1].y);return Cn(d,v,f,p,n==="orthogonal"?0:r.radius)}function rr(e,t,r){const n=e.x-t.x,o=e.y-t.y,i=Math.hypot(n,o);if(!i)return e;let a=(i-r)/i;return a<0&&(a=1e-5),{x:t.x+a*n,y:t.y+a*o}}function br(e,t,r,n="triangle"){const o=e.x-t.x,i=e.y-t.y,a=Math.hypot(o,i)||1,s=o/a,u=i/a,c=(n==="square"?.15:.3)*r,l=.15*r,d=e.x-s*c,f=e.y-u*c;return n==="square"?`M${Ge(e)} L${lr(e.x-u*l)} ${lr(e.y+s*l)} L${lr(d-u*l)} ${lr(f+s*l)} L${lr(d+u*l)} ${lr(f-s*l)} L${lr(e.x+u*l)} ${lr(e.y-s*l)} Z`:`M${Ge(e)} L${lr(d-u*l)} ${lr(f+s*l)} L${lr(d+u*l)} ${lr(f-s*l)} Z`}function Lr(e,t){let r=Math.atan(t/e);return e===0&&r<0&&(r=-r),Number.isFinite(r)||(r=0),r*180/Math.PI}function S0(e,t,r,n){const o={x:t.x-e.x,y:t.y-e.y},i={x:r.x-t.x,y:r.y-t.y},a=Math.hypot(o.x,o.y),s=Math.hypot(i.x,i.y),u=o.x*i.y-o.y*i.x;if(a<1e-6||s<1e-6||Math.abs(u)<1e-6)return{p1:t,b:t,p2:t,r:0};const c=Math.min(n,a/2,s/2);return{p1:{x:t.x-o.x/a*c,y:t.y-o.y/a*c},b:t,p2:{x:t.x+i.x/s*c,y:t.y+i.y/s*c},r:c}}function Em(e,t,r,n){let o=-1,i=null;for(let m=0;m<e.length-1;m++){const y=ht(e[m],e[m+1],t);if(y){o=m,i=y;break}}let a=-1,s=null;for(let m=e.length-1;m>0;m--){const y=ht(e[m],e[m-1],r);if(y){a=m,s=y;break}}if(!i||!s||o>=a)return null;const u=e.slice(o+1,a),c=u[0]??s,l=u[u.length-1]??i;let d,f,p;if(n.arrowAt==="source"){const m=rr(i,c,n.srcDist);d=rr(i,c,n.srcDist+n.arrowGap),p=br(m,c,n.arrowSize,n.headShape)}else d=rr(i,c,n.srcDist);if(n.arrowAt==="target"){const m=rr(s,l,n.tgtDist);f=rr(s,l,n.tgtDist+n.arrowGap),p=br(m,l,n.arrowSize,n.headShape)}else f=rr(s,l,n.tgtDist);return Cn(d,u,f,p,n.radius,n.labelTargetLength,n.labelFraction)}function Cn(e,t,r,n,o,i,a){var f;const s=[e,...t,r],u=[];let c=`M${Ge(e)}`;for(let p=1;p<s.length-1;p++){const m=S0(s[p-1],s[p],s[p+1],o);u.push(m),m.r===0?c+=` L${Ge(m.b)}`:c+=` L${Ge(m.p1)} Q${Ge(m.b)} ${Ge(m.p2)}`}c+=` L${Ge(r)}`;let l;const d=t.length;if(d===0)l={x:(e.x+r.x)/2,y:(e.y+r.y)/2,angle:Lr(r.x-e.x,r.y-e.y)};else if(d%2===0){const p=t[d/2-1],m=t[d/2];l={x:(p.x+m.x)/2,y:(p.y+m.y)/2,angle:Lr(m.x-p.x,m.y-p.y)}}else{const p=u[(d-1)/2];if(p.r===0){const m=s[(d-1)/2+2];l={x:p.b.x,y:p.b.y,angle:Lr(m.x-p.b.x,m.y-p.b.y)}}else l={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:Lr(p.p2.x-p.p1.x,p.p2.y-p.p1.y)}}if(i!==void 0){if(a!==void 0&&u.length===2){const b=u[0].p2,v=u[1].p1,g=Math.hypot(v.x-b.x,v.y-b.y),w=Math.min(.5,i/(2*g)),x=Math.max(w,Math.min(1-w,a));l={x:b.x+(v.x-b.x)*x,y:b.y+(v.y-b.y)*x,angle:Lr(v.x-b.x,v.y-b.y)}}const p=((f=u[u.length-1])==null?void 0:f.p2)??e,m=r.x-p.x,y=r.y-p.y;Math.hypot(m,y)>=i&&(l={x:(p.x+r.x)/2,y:(p.y+r.y)/2,angle:Lr(m,y)})}return{d:c,arrow:n,label:l}}function Ol(e,t,r,n,o,i,a){const s=r==="leftward"?-1:1,u={x:e.x+s*(e.w/2+a.srcDist),y:n??e.y},c={x:t.x-s*(t.w/2+a.tgtDist),y:o??t.y},l=Math.max(80,a.arrowGap+a.arrowSize*.3),d=u.x+s*l,f=c.x-s*l;let p;if(s*(f-d)>=0){const v=u.x+(c.x-u.x)*i,g=Math.max(Math.min(d,f),Math.min(Math.max(d,f),v));p=[{x:g,y:u.y},{x:g,y:c.y}]}else{const v=Math.min(e.y-e.h/2,t.y-t.h/2)-l*(1+i);p=[{x:d,y:u.y},{x:d,y:v},{x:f,y:v},{x:f,y:c.y}]}const m=a.arrowAt==="source"?rr(u,p[0],a.arrowGap):u,y=a.arrowAt==="target"?rr(c,p[p.length-1],a.arrowGap):c,b=a.arrowAt==="source"?br(u,p[0],a.arrowSize,a.headShape):a.arrowAt==="target"?br(c,p[p.length-1],a.arrowSize,a.headShape):void 0;return Cn(m,p,y,b,a.radius)}function Il(e,t,r,n,o){return Em(w0(e,t,r,n),e,t,o)}function Ml(e,t,r,n,o,i){const a=n===void 0&&o===void 0&&(r==="downward"||r==="upward"),s=r==="leftward"||a&&r==="upward"?-1:1,u=(c,l,d)=>{const f={x:c.x,y:l??c.y},p=Math.max(c.w,c.h)*2+1,m=ht(f,{x:f.x+(a?0:d*p),y:f.y+(a?d*p:0)},c);return m?{x:m.x+(a?0:d*i),y:m.y+(a?d*i:0)}:a?{x:c.x,y:c.y+d*(c.h/2+i)}:{x:c.x+d*(c.w/2+i),y:l??c.y}};return{sourcePoint:u(e,n,s),targetPoint:u(t,o,-s)}}function E0(e,t,r,n){const o=r==="downward"||r==="upward",i=r==="leftward"||r==="upward"?-1:1,a=Math.max(100,Math.abs(o?t.y-e.y:t.x-e.x)/2),s={x:e.x+(o?0:i*a),y:e.y+(o?i*a:0)},u={x:t.x-(o?0:i*a),y:t.y-(o?i*a:0)},c=n.arrowAt==="source"?rr(e,s,n.arrowGap):e,l=n.arrowAt==="target"?rr(t,u,n.arrowGap):t;return{d:`M${Ge(c)} C${Ge(s)} ${Ge(u)} ${Ge(l)}`,arrow:n.arrowAt==="source"?br(e,s,n.arrowSize,n.headShape):n.arrowAt==="target"?br(t,u,n.arrowSize,n.headShape):void 0,label:{x:(c.x+3*s.x+3*u.x+l.x)/8,y:(c.y+3*s.y+3*u.y+l.y)/8,angle:Lr(l.x+u.x-s.x-c.x,l.y+u.y-s.y-c.y)}}}function jm(e,t,r){const n=r.arrowAt==="source"?rr(e,t,r.arrowGap):e,o=r.arrowAt==="target"?rr(t,e,r.arrowGap):t,i=r.arrowAt==="source"?br(e,t,r.arrowSize,r.headShape):r.arrowAt==="target"?br(t,e,r.arrowSize,r.headShape):void 0;return Cn(n,[],o,i,0)}function j0(e,t,r,n=-90,o=-60,i=350){const a=n*Math.PI/180,s=o*Math.PI/180,u=a-Math.PI/2,c=u-s/2,l=u+s/2,d=1.4*i*(t/3+1),f={x:e.x+Math.cos(c)*d,y:e.y+Math.sin(c)*d},p={x:e.x+Math.cos(l)*d,y:e.y+Math.sin(l)*d},m={x:e.x,y:e.y},y=ht(m,f,e),b=ht(m,p,e);if(!y||!b)return null;const v={x:(f.x+p.x)/2,y:(f.y+p.y)/2};let g=rr(y,f,r.srcDist),w=rr(b,p,r.tgtDist),x;if(r.arrowAt==="target"){const C=w;w=rr(b,p,r.tgtDist+r.arrowGap),x=br(C,p,r.arrowSize,r.headShape)}else if(r.arrowAt==="source"){const C=g;g=rr(y,f,r.srcDist+r.arrowGap),x=br(C,f,r.arrowSize,r.headShape)}return{d:`M${Ge(g)} Q${Ge(f)} ${Ge(v)} Q${Ge(p)} ${Ge(w)}`,arrow:x,label:{x:v.x,y:v.y,angle:Lr(p.x-f.x,p.y-f.y)}}}const it=e=>Math.round(e*1e3)/1e3;function Rm(e){const t=e.querySelector("[data-flow-node-surface]");if(!t)return;const r=e.getBoundingClientRect(),n=r.width/e.offsetWidth;if(!Number.isFinite(n)||n<=0)return;const o=t.getBoundingClientRect();if(!o.width||!o.height)return;const i=t,a=typeof i.getScreenCTM=="function"?i.getScreenCTM():null,s=typeof i.getTotalLength=="function"?i.getTotalLength():0,u=i.points,c=(u==null?void 0:u.numberOfItems)||128,l=a&&s>0?Array.from({length:c},(d,f)=>{const p=u!=null&&u.numberOfItems?u.getItem(f):i.getPointAtLength(s*f/c);return{x:it((a.a*p.x+a.c*p.y+a.e-r.left)/n),y:it((a.b*p.x+a.d*p.y+a.f-r.top)/n)}}):void 0;return{left:it((o.left-r.left)/n),top:it((o.top-r.top)/n),width:t instanceof HTMLElement?t.offsetWidth:it(o.width/n),height:t instanceof HTMLElement?t.offsetHeight:it(o.height/n),radius:parseFloat(getComputedStyle(t).borderTopLeftRadius)||0,...l?{outline:l}:{}}}function Lt(e,t){const r=e.x-e.w/2,n=e.y-e.h/2;return{x:r+t.left+t.width/2,y:n+t.top+t.height/2,w:t.width,h:t.height,...t.outline?{outline:t.outline.map(o=>({x:r+o.x,y:n+o.y}))}:{}}}function R0(e,t,r,n,o){var l;const i=o!=="TB"&&o!=="BT",a=i?"top":"left",s=i?"bottom":"right",u=new Map;for(const d of n)for(const[f,p,m]of[[d.source,d.sourceProperty,d.target],[d.target,d.targetProperty,d.source]]){const y=t.get(m);if(p===void 0||!y||m===f)continue;const b=r.get(m),v=JSON.stringify([f,p]),g=u.get(v)??[];g.push(b?Lt(y,b):y),u.set(v,g)}const c=new Map(e);for(const[d,f]of e){const p=t.get(d);if(!p||!f.some(w=>w.placement==="config"))continue;const m=r.get(d),y=m?Lt(p,m):p,b={x:p.w/2,y:p.h/2,w:p.w,h:p.h},v=m?Lt(b,m):b,g=new Map;for(const w of f){if(w.placement!=="config")continue;const _=(u.get(JSON.stringify([d,w.property]))??[]).reduce((S,T)=>S+(i?T.y-y.y:T.x-y.x),0),C=((l=w.anchor)==null?void 0:l.side)===s?s:a;g.set(w,_<-.001?a:_>.001?s:C)}c.set(d,f.map(w=>{const x=g.get(w);if(!x)return w;const _=f.filter(T=>g.get(T)===x),C=(_.indexOf(w)+1)/(_.length+1),S=Sm(v,x,C);return{...w,anchor:S,top:S.y,height:0}}))}return c}function ql(e,t,r){const n=new Set(t.map(s=>s.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const s of t)!o.has(s.id)&&(o.has(s.parent??"")||s.id.startsWith(`${e}.`))&&(o.add(s.id),i=!0)}const a=new Set(o);for(const s of r)o.has(s.source)&&n.has(s.target)&&a.add(s.target),o.has(s.target)&&n.has(s.source)&&a.add(s.source);return a}const et='"Helvetica Neue", Helvetica, sans-serif';let St;const on=new Map;function _n(e,t){const r=`${t}|${e}`,n=on.get(r);if(n!==void 0)return n;St===void 0&&(St=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let o;return St?(St.font=t,o=St.measureText(e).width):o=e.length*(parseFloat(t)||16)*.55,on.size>5e3&&on.clear(),on.set(r,o),o}function k0(e,t,r){const n=[];for(const o of String(e).split(`
153
+ `)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let a="";for(const s of i){const u=a?`${a} ${s}`:s;!a||_n(u,t)<=r?a=u:(n.push(a),a=s)}n.push(a)}return n}const P0=e=>e.stopPropagation();function A0({id:e,rect:t,label:r,labelLayer:n,style:o,onSelect:i,onCollapse:a,selected:s=!1}){const u=t.x2-t.x1,c=t.y2-t.y1,l=o.borderWidth,d=o.borderStyle==="dashed"?`${l*4} ${l*2}`:o.borderStyle==="dotted"?`${l} ${l}`:void 0,f=t.x1+u/2,p=o.labelPosition==="top"?t.y1+o.labelMargin-o.fontSize/2:o.labelPosition==="bottom"?t.y2-o.labelMargin+o.fontSize/2:t.y1+c/2,m=r?_n(r,`bold ${o.fontSize}px ${et}`):0,y=o.fontSize/5,b=r||s&&a?h.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[s&&a&&h.jsx("foreignObject",{x:f+m/2+y+8,y:p-24,width:48,height:48,"data-flow-content-toggle":"",style:{pointerEvents:"auto"},children:h.jsx(je,{label:"Show icon",children:h.jsx(ve,{"aria-label":"Show icon",icon:h.jsx(Z.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:o.textColor},onClick:v=>{v.stopPropagation(),a(e)}})})}),r&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:f-m/2-y,y:p-o.fontSize/2-y,width:m+2*y,height:o.fontSize+2*y,fill:o.textColor==="transparent"?"transparent":o.labelBg}),h.jsx("text",{x:f,y:p,fill:o.textColor,fontSize:o.fontSize,fontWeight:"bold",fontFamily:et,style:{fontSize:o.fontSize,fontWeight:"bold",fontFamily:et},textAnchor:"middle",dominantBaseline:"central",children:r})]})]}):null;return h.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:P0,onClick:v=>{v.stopPropagation(),i==null||i(e,{shiftKey:v.shiftKey,ctrlKey:v.ctrlKey,metaKey:v.metaKey,altKey:v.altKey})},children:[h.jsx("rect",{x:t.x1,y:t.y1,width:u,height:c,rx:o.borderRadius,ry:o.borderRadius,fill:o.bgColor,fillOpacity:o.bgOpacity,stroke:o.borderColor,strokeWidth:o.borderStyle==="double"?l/3:l,strokeDasharray:d}),o.borderStyle==="double"&&h.jsx("rect",{x:t.x1+l*2/3,y:t.y1+l*2/3,width:Math.max(0,u-l*4/3),height:Math.max(0,c-l*4/3),rx:Math.max(0,o.borderRadius-l*2/3),ry:Math.max(0,o.borderRadius-l*2/3),fill:"none",stroke:o.borderColor,strokeWidth:l/3}),o.animated&&l>0&&h.jsx(_m,{variant:o.animationVariant,x:t.x1,y:t.y1,width:u,height:c,radius:o.borderRadius,color:o.animationColor||o.borderColor,strokeWidth:Math.max(8,l*1.6)}),n&&b?Ft.createPortal(b,n):b]})}const T0=j.memo(A0),hn=45,km=70,Zr=15,Pm=50;function Am(e,t,r=hn){const n=`${r}px ${et}`,o=e?k0(e,n,200*r/hn):[],i=t?48+(o.length?12:0):0,a=i+Math.max(0,...o.map(c=>_n(c,n))),s=Math.max(o.length*r,t?48:0),u=o.length||t?2*Zr:0;return{lines:o,iconWidth:i,contentWidth:a,contentHeight:s,width:a+u,height:s+u}}const pn=6,Tm=3,$u=Math.max(Math.pow(pn*13.37,.9),29)*Tm,Om=pn*Tm*2,sn=80,O0=2*sn+$u*.3+100,I0=36+2*Math.max(80,Om+$u*.3);function wu(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function Cu(e,t){return t==="auto"||(t==="properties"?wu(e):!wu(e))}function ct(e,t,r){return r!=="properties"||e!=="root"||t.some(n=>(n.source===e||n.target===e)&&wu(n))}function M0(e,t,r,n=!1,o){if(!n||r!=="properties"&&!o)return{nodes:e,edges:t};const i=e.filter(s=>ct(s.id,t,r)&&(!o||o.has(s.id))),a=new Set(i.map(s=>s.id));return{nodes:i,edges:t.filter(s=>Cu(s,r)&&a.has(s.source)&&a.has(s.target))}}const q0=500,N0="32 18",$0=e=>e.stopPropagation();function L0({id:e,edgeData:t,validationIssue:r,edgeType:n="rounded-orthogonal",edgeRadius:o,customEdgeTypes:i,source:a,target:s,sourceProperty:u,targetProperty:c,sourceY:l,targetY:d,sourcePort:f,targetPort:p,propertyMode:m=!1,dir:y,turn:b,labelAtTarget:v,labelFraction:g,color:w,labelBg:x,labelLayer:_,label:C,dashed:S,animated:T,inverted:k,loopIndex:E=0,onSelect:P}){const R=t==null?void 0:t.icon,I=m?hn:km,{lines:O,iconWidth:M,contentWidth:q,contentHeight:K}=j.useMemo(()=>Am(C,R,I),[C,R,I]),V=j.useMemo(()=>{const X={srcDist:sn,tgtDist:sn,arrowGap:Om,arrowSize:$u,headShape:m&&(k?l!==void 0||f:d!==void 0||p)?"square":"triangle",radius:o??(v?40:q0),arrowAt:k?"source":"target",labelTargetLength:v?q+2*Zr:void 0,labelFraction:v?g:void 0},se=l!==void 0||d!==void 0||!!f||!!p,Q=Ml(a,s,y,l,d,0),G=l===void 0&&d===void 0&&(y==="downward"||y==="upward"),J=f??{...Q.sourcePoint,side:G?y==="upward"?"top":"bottom":y==="leftward"?"left":"right"},te=p??{...Q.targetPoint,side:G?y==="upward"?"bottom":"top":y==="leftward"?"right":"left"},le=a.x===s.x&&a.y===s.y,de=f||p?_0(J,te,{...X,srcDist:18,tgtDist:18},n):se?Ol(a,s,y,l,d,b,{...X,srcDist:18,tgtDist:18,radius:o??Math.min(X.radius,40)}):le?j0(a,E,{...X,srcDist:0,tgtDist:0}):Il(a,s,y,b,X);if(!de)return null;const Re=Ml(a,s,y,l,d,se?18:sn);f&&(Re.sourcePoint=lt(f,18)),p&&(Re.targetPoint=lt(p,18));const ge=Object.prototype.hasOwnProperty.call(i??{},n)?i==null?void 0:i[n]:void 0;if(ge){const ze={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return ge({edge:t??{id:e,source:"",target:""},source:{...a},target:{...s},...Re,direction:ze[y],sourceY:l,targetY:d,inverted:!!k,defaultGeometry:de})??de}return le||f||p?de:n==="straight"?se?jm(Re.sourcePoint,Re.targetPoint,X):Em([a,s],a,s,X):n==="bezier"?E0(Re.sourcePoint,Re.targetPoint,se?y==="leftward"?"leftward":"rightward":y,X):n==="orthogonal"?se?Ol(a,s,y,l,d,b,{...X,srcDist:18,tgtDist:18,radius:0}):Il(a,s,y,b,{...X,radius:0}):de},[a,e,t,n,o,i,s,m,l,d,f,p,y,b,k,E,v,g,q]);if(!V)return null;const re=(y==="rightward"||y==="leftward")&&!Object.prototype.hasOwnProperty.call(i??{},n)&&!(m&&(l!==void 0||d!==void 0||f||p)),ce=re?`translate(${V.label.x} ${V.label.y-K/2-2*Zr})`:`translate(${V.label.x} ${V.label.y}) rotate(${V.label.angle}) translate(${v||Object.prototype.hasOwnProperty.call(i??{},n)?0:Pm} 0)`,he=r!=null&&r.startsWith("Unverified:")?"#b45309":"#dc2626",me=r?he:w,H=r?h.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":r,transform:`translate(${V.label.x} ${V.label.y-O.length*I/2-55})`,children:[h.jsx("title",{children:r}),h.jsx(Mr,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:he})]}):null,N=T&&(t==null?void 0:t.edgeAnimationVariant)==="traveling",D=!N&&(S||T)?N0:void 0,W=T&&!N?`flow-sdk-edge-anim${k?" flow-sdk-edge-anim-rev":""}`:void 0;let z=null;if(O.length||R){const X=q,se=K;z=h.jsxs("g",{className:"flow-sdk-edge-label","data-label-transform":ce,"data-label-horizontal":re||void 0,"data-edge-id":e,"data-source-property":u,"data-target-property":c,transform:ce,children:[h.jsx("rect",{x:-X/2-Zr,y:-se/2-Zr,width:X+2*Zr,height:se+2*Zr,fill:w==="transparent"?"transparent":x}),h.jsx("text",{fill:w,fontSize:I,style:{fontSize:I,fontFamily:et},fontFamily:et,textAnchor:"middle",dominantBaseline:"central",children:O.map((Q,G)=>h.jsx("tspan",{x:M/2,y:(G-(O.length-1)/2)*I,children:Q},G))}),R&&h.jsxs("g",{className:"flow-sdk-edge-icon",opacity:w==="transparent"?0:1,children:[h.jsx("title",{children:C?`Edge icon: ${C}`:"Edge icon"}),h.jsx("rect",{x:-X/2,y:-24,width:48,height:48,fill:"transparent"}),h.jsx(Mr,{name:R,svg:!0,size:48,x:-X/2,y:-24,color:w})]})]})}return h.jsxs("g",{className:"flow-sdk-edge","data-edge-id":e,"data-source-property":u,"data-target-property":c,"data-validation":r?r.startsWith("Unverified:")?"unverified":"invalid":void 0,"aria-label":r,onPointerDown:$0,onClick:X=>{X.stopPropagation(),P==null||P(e)},children:[h.jsx("path",{d:V.d,fill:"none",stroke:me,strokeWidth:pn,strokeOpacity:N?.35:void 0,strokeDasharray:D,className:W}),N&&h.jsx(p0,{path:V.d,color:me,width:pn*1.6,reversed:k}),V.arrow&&h.jsx("path",{d:V.arrow,fill:me}),_&&z?Ft.createPortal(z,_):z,_&&H?Ft.createPortal(H,_):H,h.jsx("path",{className:"flow-sdk-edge-hit",d:V.d,fill:"none",stroke:"transparent"})]})}const Nl=j.memo(L0),$l=(e,t)=>e.left<t.right&&e.right>t.left&&e.top<t.bottom&&e.bottom>t.top;function F0(e){const t=e.querySelector(".flow-sdk-labels"),r=t==null?void 0:t.getScreenCTM();if(!t||!r)return;const n=r.inverse(),o=(c,l=0)=>{const d=c.getBoundingClientRect(),f=new DOMPoint(d.left,d.top).matrixTransform(n),p=new DOMPoint(d.right,d.bottom).matrixTransform(n);return{left:f.x-l,right:p.x+l,top:f.y-l,bottom:p.y+l}},i=[...e.querySelectorAll(".flow-sdk-node, .flow-sdk-node button")].filter(c=>{const l=c.getBoundingClientRect(),d=getComputedStyle(c);return l.width>0&&l.height>0&&d.visibility!=="hidden"&&d.opacity!=="0"}).map(c=>o(c,24));for(const c of t.querySelectorAll(".flow-sdk-container-label"))i.push(o(c,12));const a=[...t.querySelectorAll(".flow-sdk-edge-label")];for(const c of a)c.setAttribute("transform",c.dataset.labelTransform??"");const s=new Map(a.map(c=>[c,o(c,8)])),u=new Map([...e.querySelectorAll(".flow-sdk-edge")].map(c=>[c.dataset.edgeId,c.querySelector("path")]));for(const c of a){const l=c.dataset.labelHorizontal==="true",d=s.get(c);s.delete(c);const f=S=>i.some(T=>$l(S,T))||[...s.values()].some(T=>$l(S,T));if(!l&&!f(d)){s.set(c,d);continue}const p=u.get(c.dataset.edgeId),m=c.querySelector("rect");if(!p||!m)continue;const y=m.getBBox(),b=p.getTotalLength();if(!Number.isFinite(b)||b<=0)continue;const v=(d.left+d.right)/2,g=(d.top+d.bottom)/2,w=Math.min(256,Math.max(16,Math.ceil(b/24))),x=Array.from({length:w+1},(S,T)=>p.getPointAtLength(b*T/w)),C=Array.from({length:w+1},(S,T)=>{const k=b*T/w,E=x[T],P=l?{x:E.x,y:E.y-y.height/2-15}:E,R=p.getPointAtLength(Math.max(0,k-2)),I=p.getPointAtLength(Math.min(b,k+2));let O=Math.atan2(I.y-R.y,I.x-R.x)*180/Math.PI;O>90&&(O-=180),O<-90&&(O+=180);const M=Math.abs(O)<1;l&&(O=0);const q=O*Math.PI/180,K=Math.abs(Math.cos(q))*y.width+Math.abs(Math.sin(q))*y.height,V=Math.abs(Math.sin(q))*y.width+Math.abs(Math.cos(q))*y.height;return{point:P,angle:O,straight:M,score:Math.hypot(P.x-v,P.y-g),bounds:{left:P.x-K/2-8,right:P.x+K/2+8,top:P.y-V/2-8,bottom:P.y+V/2+8}}}).sort((S,T)=>S.score-T.score).find(S=>!f(S.bounds)&&(!l||S.straight&&!x.some(T=>T.x>S.bounds.left&&T.x<S.bounds.right&&T.y>S.bounds.top&&T.y<S.bounds.bottom)));C?(c.setAttribute("transform",`translate(${C.point.x} ${C.point.y}) rotate(${C.angle})`),s.set(c,C.bounds)):s.set(c,d)}}var an=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function B0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Lu(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 Xn,Ll;function D0(){if(Ll)return Xn;Ll=1;function e(){this.__data__=[],this.size=0}return Xn=e,Xn}var Qn,Fl;function yt(){if(Fl)return Qn;Fl=1;function e(t,r){return t===r||t!==t&&r!==r}return Qn=e,Qn}var eo,Bl;function Sn(){if(Bl)return eo;Bl=1;var e=yt();function t(r,n){for(var o=r.length;o--;)if(e(r[o][0],n))return o;return-1}return eo=t,eo}var ro,Dl;function z0(){if(Dl)return ro;Dl=1;var e=Sn(),t=Array.prototype,r=t.splice;function n(o){var i=this.__data__,a=e(i,o);if(a<0)return!1;var s=i.length-1;return a==s?i.pop():r.call(i,a,1),--this.size,!0}return ro=n,ro}var to,zl;function V0(){if(zl)return to;zl=1;var e=Sn();function t(r){var n=this.__data__,o=e(n,r);return o<0?void 0:n[o][1]}return to=t,to}var no,Vl;function W0(){if(Vl)return no;Vl=1;var e=Sn();function t(r){return e(this.__data__,r)>-1}return no=t,no}var oo,Wl;function G0(){if(Wl)return oo;Wl=1;var e=Sn();function t(r,n){var o=this.__data__,i=e(o,r);return i<0?(++this.size,o.push([r,n])):o[i][1]=n,this}return oo=t,oo}var io,Gl;function En(){if(Gl)return io;Gl=1;var e=D0(),t=z0(),r=V0(),n=W0(),o=G0();function i(a){var s=-1,u=a==null?0:a.length;for(this.clear();++s<u;){var c=a[s];this.set(c[0],c[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=o,io=i,io}var ao,Ul;function U0(){if(Ul)return ao;Ul=1;var e=En();function t(){this.__data__=new e,this.size=0}return ao=t,ao}var so,Hl;function H0(){if(Hl)return so;Hl=1;function e(t){var r=this.__data__,n=r.delete(t);return this.size=r.size,n}return so=e,so}var co,Kl;function K0(){if(Kl)return co;Kl=1;function e(t){return this.__data__.get(t)}return co=e,co}var uo,Zl;function Z0(){if(Zl)return uo;Zl=1;function e(t){return this.__data__.has(t)}return uo=e,uo}var lo,Jl;function Im(){if(Jl)return lo;Jl=1;var e=typeof an=="object"&&an&&an.Object===Object&&an;return lo=e,lo}var fo,Yl;function Sr(){if(Yl)return fo;Yl=1;var e=Im(),t=typeof self=="object"&&self&&self.Object===Object&&self,r=e||t||Function("return this")();return fo=r,fo}var ho,Xl;function mt(){if(Xl)return ho;Xl=1;var e=Sr(),t=e.Symbol;return ho=t,ho}var po,Ql;function J0(){if(Ql)return po;Ql=1;var e=mt(),t=Object.prototype,r=t.hasOwnProperty,n=t.toString,o=e?e.toStringTag:void 0;function i(a){var s=r.call(a,o),u=a[o];try{a[o]=void 0;var c=!0}catch{}var l=n.call(a);return c&&(s?a[o]=u:delete a[o]),l}return po=i,po}var go,ed;function Y0(){if(ed)return go;ed=1;var e=Object.prototype,t=e.toString;function r(n){return t.call(n)}return go=r,go}var yo,rd;function rt(){if(rd)return yo;rd=1;var e=mt(),t=J0(),r=Y0(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function a(s){return s==null?s===void 0?o:n:i&&i in Object(s)?t(s):r(s)}return yo=a,yo}var mo,td;function vr(){if(td)return mo;td=1;function e(t){var r=typeof t;return t!=null&&(r=="object"||r=="function")}return mo=e,mo}var bo,nd;function Xt(){if(nd)return bo;nd=1;var e=rt(),t=vr(),r="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function a(s){if(!t(s))return!1;var u=e(s);return u==n||u==o||u==r||u==i}return bo=a,bo}var vo,od;function X0(){if(od)return vo;od=1;var e=Sr(),t=e["__core-js_shared__"];return vo=t,vo}var xo,id;function Q0(){if(id)return xo;id=1;var e=X0(),t=(function(){var n=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})();function r(n){return!!t&&t in n}return xo=r,xo}var wo,ad;function Mm(){if(ad)return wo;ad=1;var e=Function.prototype,t=e.toString;function r(n){if(n!=null){try{return t.call(n)}catch{}try{return n+""}catch{}}return""}return wo=r,wo}var Co,sd;function ew(){if(sd)return Co;sd=1;var e=Xt(),t=Q0(),r=vr(),n=Mm(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,a=Function.prototype,s=Object.prototype,u=a.toString,c=s.hasOwnProperty,l=RegExp("^"+u.call(c).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function d(f){if(!r(f)||t(f))return!1;var p=e(f)?l:i;return p.test(n(f))}return Co=d,Co}var _o,cd;function rw(){if(cd)return _o;cd=1;function e(t,r){return t==null?void 0:t[r]}return _o=e,_o}var So,ud;function tt(){if(ud)return So;ud=1;var e=ew(),t=rw();function r(n,o){var i=t(n,o);return e(i)?i:void 0}return So=r,So}var Eo,ld;function Fu(){if(ld)return Eo;ld=1;var e=tt(),t=Sr(),r=e(t,"Map");return Eo=r,Eo}var jo,dd;function jn(){if(dd)return jo;dd=1;var e=tt(),t=e(Object,"create");return jo=t,jo}var Ro,fd;function tw(){if(fd)return Ro;fd=1;var e=jn();function t(){this.__data__=e?e(null):{},this.size=0}return Ro=t,Ro}var ko,hd;function nw(){if(hd)return ko;hd=1;function e(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r}return ko=e,ko}var Po,pd;function ow(){if(pd)return Po;pd=1;var e=jn(),t="__lodash_hash_undefined__",r=Object.prototype,n=r.hasOwnProperty;function o(i){var a=this.__data__;if(e){var s=a[i];return s===t?void 0:s}return n.call(a,i)?a[i]:void 0}return Po=o,Po}var Ao,gd;function iw(){if(gd)return Ao;gd=1;var e=jn(),t=Object.prototype,r=t.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:r.call(i,o)}return Ao=n,Ao}var To,yd;function aw(){if(yd)return To;yd=1;var e=jn(),t="__lodash_hash_undefined__";function r(n,o){var i=this.__data__;return this.size+=this.has(n)?0:1,i[n]=e&&o===void 0?t:o,this}return To=r,To}var Oo,md;function sw(){if(md)return Oo;md=1;var e=tw(),t=nw(),r=ow(),n=iw(),o=aw();function i(a){var s=-1,u=a==null?0:a.length;for(this.clear();++s<u;){var c=a[s];this.set(c[0],c[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=o,Oo=i,Oo}var Io,bd;function cw(){if(bd)return Io;bd=1;var e=sw(),t=En(),r=Fu();function n(){this.size=0,this.__data__={hash:new e,map:new(r||t),string:new e}}return Io=n,Io}var Mo,vd;function uw(){if(vd)return Mo;vd=1;function e(t){var r=typeof t;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?t!=="__proto__":t===null}return Mo=e,Mo}var qo,xd;function Rn(){if(xd)return qo;xd=1;var e=uw();function t(r,n){var o=r.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return qo=t,qo}var No,wd;function lw(){if(wd)return No;wd=1;var e=Rn();function t(r){var n=e(this,r).delete(r);return this.size-=n?1:0,n}return No=t,No}var $o,Cd;function dw(){if(Cd)return $o;Cd=1;var e=Rn();function t(r){return e(this,r).get(r)}return $o=t,$o}var Lo,_d;function fw(){if(_d)return Lo;_d=1;var e=Rn();function t(r){return e(this,r).has(r)}return Lo=t,Lo}var Fo,Sd;function hw(){if(Sd)return Fo;Sd=1;var e=Rn();function t(r,n){var o=e(this,r),i=o.size;return o.set(r,n),this.size+=o.size==i?0:1,this}return Fo=t,Fo}var Bo,Ed;function Bu(){if(Ed)return Bo;Ed=1;var e=cw(),t=lw(),r=dw(),n=fw(),o=hw();function i(a){var s=-1,u=a==null?0:a.length;for(this.clear();++s<u;){var c=a[s];this.set(c[0],c[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=o,Bo=i,Bo}var Do,jd;function pw(){if(jd)return Do;jd=1;var e=En(),t=Fu(),r=Bu(),n=200;function o(i,a){var s=this.__data__;if(s instanceof e){var u=s.__data__;if(!t||u.length<n-1)return u.push([i,a]),this.size=++s.size,this;s=this.__data__=new r(u)}return s.set(i,a),this.size=s.size,this}return Do=o,Do}var zo,Rd;function kn(){if(Rd)return zo;Rd=1;var e=En(),t=U0(),r=H0(),n=K0(),o=Z0(),i=pw();function a(s){var u=this.__data__=new e(s);this.size=u.size}return a.prototype.clear=t,a.prototype.delete=r,a.prototype.get=n,a.prototype.has=o,a.prototype.set=i,zo=a,zo}var Vo,kd;function Du(){if(kd)return Vo;kd=1;function e(t,r){for(var n=-1,o=t==null?0:t.length;++n<o&&r(t[n],n,t)!==!1;);return t}return Vo=e,Vo}var Wo,Pd;function qm(){if(Pd)return Wo;Pd=1;var e=tt(),t=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return Wo=t,Wo}var Go,Ad;function Pn(){if(Ad)return Go;Ad=1;var e=qm();function t(r,n,o){n=="__proto__"&&e?e(r,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):r[n]=o}return Go=t,Go}var Uo,Td;function An(){if(Td)return Uo;Td=1;var e=Pn(),t=yt(),r=Object.prototype,n=r.hasOwnProperty;function o(i,a,s){var u=i[a];(!(n.call(i,a)&&t(u,s))||s===void 0&&!(a in i))&&e(i,a,s)}return Uo=o,Uo}var Ho,Od;function Qt(){if(Od)return Ho;Od=1;var e=An(),t=Pn();function r(n,o,i,a){var s=!i;i||(i={});for(var u=-1,c=o.length;++u<c;){var l=o[u],d=a?a(i[l],n[l],l,i,n):void 0;d===void 0&&(d=n[l]),s?t(i,l,d):e(i,l,d)}return i}return Ho=r,Ho}var Ko,Id;function gw(){if(Id)return Ko;Id=1;function e(t,r){for(var n=-1,o=Array(t);++n<t;)o[n]=r(n);return o}return Ko=e,Ko}var Zo,Md;function Pr(){if(Md)return Zo;Md=1;function e(t){return t!=null&&typeof t=="object"}return Zo=e,Zo}var Jo,qd;function yw(){if(qd)return Jo;qd=1;var e=rt(),t=Pr(),r="[object Arguments]";function n(o){return t(o)&&e(o)==r}return Jo=n,Jo}var Yo,Nd;function en(){if(Nd)return Yo;Nd=1;var e=yw(),t=Pr(),r=Object.prototype,n=r.hasOwnProperty,o=r.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(a){return t(a)&&n.call(a,"callee")&&!o.call(a,"callee")};return Yo=i,Yo}var Xo,$d;function Ue(){if($d)return Xo;$d=1;var e=Array.isArray;return Xo=e,Xo}var At={exports:{}},Qo,Ld;function mw(){if(Ld)return Qo;Ld=1;function e(){return!1}return Qo=e,Qo}At.exports;var Fd;function bt(){return Fd||(Fd=1,(function(e,t){var r=Sr(),n=mw(),o=t&&!t.nodeType&&t,i=o&&!0&&e&&!e.nodeType&&e,a=i&&i.exports===o,s=a?r.Buffer:void 0,u=s?s.isBuffer:void 0,c=u||n;e.exports=c})(At,At.exports)),At.exports}var ei,Bd;function Tn(){if(Bd)return ei;Bd=1;var e=9007199254740991,t=/^(?:0|[1-9]\d*)$/;function r(n,o){var i=typeof n;return o=o??e,!!o&&(i=="number"||i!="symbol"&&t.test(n))&&n>-1&&n%1==0&&n<o}return ei=r,ei}var ri,Dd;function zu(){if(Dd)return ri;Dd=1;var e=9007199254740991;function t(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return ri=t,ri}var ti,zd;function bw(){if(zd)return ti;zd=1;var e=rt(),t=zu(),r=Pr(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",a="[object Date]",s="[object Error]",u="[object Function]",c="[object Map]",l="[object Number]",d="[object Object]",f="[object RegExp]",p="[object Set]",m="[object String]",y="[object WeakMap]",b="[object ArrayBuffer]",v="[object DataView]",g="[object Float32Array]",w="[object Float64Array]",x="[object Int8Array]",_="[object Int16Array]",C="[object Int32Array]",S="[object Uint8Array]",T="[object Uint8ClampedArray]",k="[object Uint16Array]",E="[object Uint32Array]",P={};P[g]=P[w]=P[x]=P[_]=P[C]=P[S]=P[T]=P[k]=P[E]=!0,P[n]=P[o]=P[b]=P[i]=P[v]=P[a]=P[s]=P[u]=P[c]=P[l]=P[d]=P[f]=P[p]=P[m]=P[y]=!1;function R(I){return r(I)&&t(I.length)&&!!P[e(I)]}return ti=R,ti}var ni,Vd;function On(){if(Vd)return ni;Vd=1;function e(t){return function(r){return t(r)}}return ni=e,ni}var Tt={exports:{}};Tt.exports;var Wd;function Vu(){return Wd||(Wd=1,(function(e,t){var r=Im(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,a=i&&r.process,s=(function(){try{var u=o&&o.require&&o.require("util").types;return u||a&&a.binding&&a.binding("util")}catch{}})();e.exports=s})(Tt,Tt.exports)),Tt.exports}var oi,Gd;function rn(){if(Gd)return oi;Gd=1;var e=bw(),t=On(),r=Vu(),n=r&&r.isTypedArray,o=n?t(n):e;return oi=o,oi}var ii,Ud;function Nm(){if(Ud)return ii;Ud=1;var e=gw(),t=en(),r=Ue(),n=bt(),o=Tn(),i=rn(),a=Object.prototype,s=a.hasOwnProperty;function u(c,l){var d=r(c),f=!d&&t(c),p=!d&&!f&&n(c),m=!d&&!f&&!p&&i(c),y=d||f||p||m,b=y?e(c.length,String):[],v=b.length;for(var g in c)(l||s.call(c,g))&&!(y&&(g=="length"||p&&(g=="offset"||g=="parent")||m&&(g=="buffer"||g=="byteLength"||g=="byteOffset")||o(g,v)))&&b.push(g);return b}return ii=u,ii}var ai,Hd;function In(){if(Hd)return ai;Hd=1;var e=Object.prototype;function t(r){var n=r&&r.constructor,o=typeof n=="function"&&n.prototype||e;return r===o}return ai=t,ai}var si,Kd;function $m(){if(Kd)return si;Kd=1;function e(t,r){return function(n){return t(r(n))}}return si=e,si}var ci,Zd;function vw(){if(Zd)return ci;Zd=1;var e=$m(),t=e(Object.keys,Object);return ci=t,ci}var ui,Jd;function Wu(){if(Jd)return ui;Jd=1;var e=In(),t=vw(),r=Object.prototype,n=r.hasOwnProperty;function o(i){if(!e(i))return t(i);var a=[];for(var s in Object(i))n.call(i,s)&&s!="constructor"&&a.push(s);return a}return ui=o,ui}var li,Yd;function qr(){if(Yd)return li;Yd=1;var e=Xt(),t=zu();function r(n){return n!=null&&t(n.length)&&!e(n)}return li=r,li}var di,Xd;function Ur(){if(Xd)return di;Xd=1;var e=Nm(),t=Wu(),r=qr();function n(o){return r(o)?e(o):t(o)}return di=n,di}var fi,Qd;function xw(){if(Qd)return fi;Qd=1;var e=Qt(),t=Ur();function r(n,o){return n&&e(o,t(o),n)}return fi=r,fi}var hi,ef;function ww(){if(ef)return hi;ef=1;function e(t){var r=[];if(t!=null)for(var n in Object(t))r.push(n);return r}return hi=e,hi}var pi,rf;function Cw(){if(rf)return pi;rf=1;var e=vr(),t=In(),r=ww(),n=Object.prototype,o=n.hasOwnProperty;function i(a){if(!e(a))return r(a);var s=t(a),u=[];for(var c in a)c=="constructor"&&(s||!o.call(a,c))||u.push(c);return u}return pi=i,pi}var gi,tf;function nt(){if(tf)return gi;tf=1;var e=Nm(),t=Cw(),r=qr();function n(o){return r(o)?e(o,!0):t(o)}return gi=n,gi}var yi,nf;function _w(){if(nf)return yi;nf=1;var e=Qt(),t=nt();function r(n,o){return n&&e(o,t(o),n)}return yi=r,yi}var Ot={exports:{}};Ot.exports;var of;function Lm(){return of||(of=1,(function(e,t){var r=Sr(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,a=i?r.Buffer:void 0,s=a?a.allocUnsafe:void 0;function u(c,l){if(l)return c.slice();var d=c.length,f=s?s(d):new c.constructor(d);return c.copy(f),f}e.exports=u})(Ot,Ot.exports)),Ot.exports}var mi,af;function Fm(){if(af)return mi;af=1;function e(t,r){var n=-1,o=t.length;for(r||(r=Array(o));++n<o;)r[n]=t[n];return r}return mi=e,mi}var bi,sf;function Bm(){if(sf)return bi;sf=1;function e(t,r){for(var n=-1,o=t==null?0:t.length,i=0,a=[];++n<o;){var s=t[n];r(s,n,t)&&(a[i++]=s)}return a}return bi=e,bi}var vi,cf;function Dm(){if(cf)return vi;cf=1;function e(){return[]}return vi=e,vi}var xi,uf;function Gu(){if(uf)return xi;uf=1;var e=Bm(),t=Dm(),r=Object.prototype,n=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(a){return a==null?[]:(a=Object(a),e(o(a),function(s){return n.call(a,s)}))}:t;return xi=i,xi}var wi,lf;function Sw(){if(lf)return wi;lf=1;var e=Qt(),t=Gu();function r(n,o){return e(n,t(n),o)}return wi=r,wi}var Ci,df;function Uu(){if(df)return Ci;df=1;function e(t,r){for(var n=-1,o=r.length,i=t.length;++n<o;)t[i+n]=r[n];return t}return Ci=e,Ci}var _i,ff;function Mn(){if(ff)return _i;ff=1;var e=$m(),t=e(Object.getPrototypeOf,Object);return _i=t,_i}var Si,hf;function zm(){if(hf)return Si;hf=1;var e=Uu(),t=Mn(),r=Gu(),n=Dm(),o=Object.getOwnPropertySymbols,i=o?function(a){for(var s=[];a;)e(s,r(a)),a=t(a);return s}:n;return Si=i,Si}var Ei,pf;function Ew(){if(pf)return Ei;pf=1;var e=Qt(),t=zm();function r(n,o){return e(n,t(n),o)}return Ei=r,Ei}var ji,gf;function Vm(){if(gf)return ji;gf=1;var e=Uu(),t=Ue();function r(n,o,i){var a=o(n);return t(n)?a:e(a,i(n))}return ji=r,ji}var Ri,yf;function Wm(){if(yf)return Ri;yf=1;var e=Vm(),t=Gu(),r=Ur();function n(o){return e(o,r,t)}return Ri=n,Ri}var ki,mf;function jw(){if(mf)return ki;mf=1;var e=Vm(),t=zm(),r=nt();function n(o){return e(o,r,t)}return ki=n,ki}var Pi,bf;function Rw(){if(bf)return Pi;bf=1;var e=tt(),t=Sr(),r=e(t,"DataView");return Pi=r,Pi}var Ai,vf;function kw(){if(vf)return Ai;vf=1;var e=tt(),t=Sr(),r=e(t,"Promise");return Ai=r,Ai}var Ti,xf;function Gm(){if(xf)return Ti;xf=1;var e=tt(),t=Sr(),r=e(t,"Set");return Ti=r,Ti}var Oi,wf;function Pw(){if(wf)return Oi;wf=1;var e=tt(),t=Sr(),r=e(t,"WeakMap");return Oi=r,Oi}var Ii,Cf;function vt(){if(Cf)return Ii;Cf=1;var e=Rw(),t=Fu(),r=kw(),n=Gm(),o=Pw(),i=rt(),a=Mm(),s="[object Map]",u="[object Object]",c="[object Promise]",l="[object Set]",d="[object WeakMap]",f="[object DataView]",p=a(e),m=a(t),y=a(r),b=a(n),v=a(o),g=i;return(e&&g(new e(new ArrayBuffer(1)))!=f||t&&g(new t)!=s||r&&g(r.resolve())!=c||n&&g(new n)!=l||o&&g(new o)!=d)&&(g=function(w){var x=i(w),_=x==u?w.constructor:void 0,C=_?a(_):"";if(C)switch(C){case p:return f;case m:return s;case y:return c;case b:return l;case v:return d}return x}),Ii=g,Ii}var Mi,_f;function Aw(){if(_f)return Mi;_f=1;var e=Object.prototype,t=e.hasOwnProperty;function r(n){var o=n.length,i=new n.constructor(o);return o&&typeof n[0]=="string"&&t.call(n,"index")&&(i.index=n.index,i.input=n.input),i}return Mi=r,Mi}var qi,Sf;function Um(){if(Sf)return qi;Sf=1;var e=Sr(),t=e.Uint8Array;return qi=t,qi}var Ni,Ef;function Hu(){if(Ef)return Ni;Ef=1;var e=Um();function t(r){var n=new r.constructor(r.byteLength);return new e(n).set(new e(r)),n}return Ni=t,Ni}var $i,jf;function Tw(){if(jf)return $i;jf=1;var e=Hu();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.byteLength)}return $i=t,$i}var Li,Rf;function Ow(){if(Rf)return Li;Rf=1;var e=/\w*$/;function t(r){var n=new r.constructor(r.source,e.exec(r));return n.lastIndex=r.lastIndex,n}return Li=t,Li}var Fi,kf;function Iw(){if(kf)return Fi;kf=1;var e=mt(),t=e?e.prototype:void 0,r=t?t.valueOf:void 0;function n(o){return r?Object(r.call(o)):{}}return Fi=n,Fi}var Bi,Pf;function Hm(){if(Pf)return Bi;Pf=1;var e=Hu();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.length)}return Bi=t,Bi}var Di,Af;function Mw(){if(Af)return Di;Af=1;var e=Hu(),t=Tw(),r=Ow(),n=Iw(),o=Hm(),i="[object Boolean]",a="[object Date]",s="[object Map]",u="[object Number]",c="[object RegExp]",l="[object Set]",d="[object String]",f="[object Symbol]",p="[object ArrayBuffer]",m="[object DataView]",y="[object Float32Array]",b="[object Float64Array]",v="[object Int8Array]",g="[object Int16Array]",w="[object Int32Array]",x="[object Uint8Array]",_="[object Uint8ClampedArray]",C="[object Uint16Array]",S="[object Uint32Array]";function T(k,E,P){var R=k.constructor;switch(E){case p:return e(k);case i:case a:return new R(+k);case m:return t(k,P);case y:case b:case v:case g:case w:case x:case _:case C:case S:return o(k,P);case s:return new R;case u:case d:return new R(k);case c:return r(k);case l:return new R;case f:return n(k)}}return Di=T,Di}var zi,Tf;function Km(){if(Tf)return zi;Tf=1;var e=vr(),t=Object.create,r=(function(){function n(){}return function(o){if(!e(o))return{};if(t)return t(o);n.prototype=o;var i=new n;return n.prototype=void 0,i}})();return zi=r,zi}var Vi,Of;function Zm(){if(Of)return Vi;Of=1;var e=Km(),t=Mn(),r=In();function n(o){return typeof o.constructor=="function"&&!r(o)?e(t(o)):{}}return Vi=n,Vi}var Wi,If;function qw(){if(If)return Wi;If=1;var e=vt(),t=Pr(),r="[object Map]";function n(o){return t(o)&&e(o)==r}return Wi=n,Wi}var Gi,Mf;function Nw(){if(Mf)return Gi;Mf=1;var e=qw(),t=On(),r=Vu(),n=r&&r.isMap,o=n?t(n):e;return Gi=o,Gi}var Ui,qf;function $w(){if(qf)return Ui;qf=1;var e=vt(),t=Pr(),r="[object Set]";function n(o){return t(o)&&e(o)==r}return Ui=n,Ui}var Hi,Nf;function Lw(){if(Nf)return Hi;Nf=1;var e=$w(),t=On(),r=Vu(),n=r&&r.isSet,o=n?t(n):e;return Hi=o,Hi}var Ki,$f;function Jm(){if($f)return Ki;$f=1;var e=kn(),t=Du(),r=An(),n=xw(),o=_w(),i=Lm(),a=Fm(),s=Sw(),u=Ew(),c=Wm(),l=jw(),d=vt(),f=Aw(),p=Mw(),m=Zm(),y=Ue(),b=bt(),v=Nw(),g=vr(),w=Lw(),x=Ur(),_=nt(),C=1,S=2,T=4,k="[object Arguments]",E="[object Array]",P="[object Boolean]",R="[object Date]",I="[object Error]",O="[object Function]",M="[object GeneratorFunction]",q="[object Map]",K="[object Number]",V="[object Object]",re="[object RegExp]",ce="[object Set]",he="[object String]",me="[object Symbol]",H="[object WeakMap]",N="[object ArrayBuffer]",D="[object DataView]",W="[object Float32Array]",z="[object Float64Array]",X="[object Int8Array]",se="[object Int16Array]",Q="[object Int32Array]",G="[object Uint8Array]",J="[object Uint8ClampedArray]",te="[object Uint16Array]",le="[object Uint32Array]",de={};de[k]=de[E]=de[N]=de[D]=de[P]=de[R]=de[W]=de[z]=de[X]=de[se]=de[Q]=de[q]=de[K]=de[V]=de[re]=de[ce]=de[he]=de[me]=de[G]=de[J]=de[te]=de[le]=!0,de[I]=de[O]=de[H]=!1;function Re(ge,ze,Fe,He,ar,be){var _e,Xe=ze&C,Ke=ze&S,Ne=ze&T;if(Fe&&(_e=ar?Fe(ge,He,ar,be):Fe(ge)),_e!==void 0)return _e;if(!g(ge))return ge;var Qe=y(ge);if(Qe){if(_e=f(ge),!Xe)return a(ge,_e)}else{var Ze=d(ge),gr=Ze==O||Ze==M;if(b(ge))return i(ge,Xe);if(Ze==V||Ze==k||gr&&!ar){if(_e=Ke||gr?{}:m(ge),!Xe)return Ke?u(ge,o(_e,ge)):s(ge,n(_e,ge))}else{if(!de[Ze])return ar?ge:{};_e=p(ge,Ze,Xe)}}be||(be=new e);var fr=be.get(ge);if(fr)return fr;be.set(ge,_e),w(ge)?ge.forEach(function(or){_e.add(Re(or,ze,Fe,or,ge,be))}):v(ge)&&ge.forEach(function(or,sr){_e.set(sr,Re(or,ze,Fe,sr,ge,be))});var Er=Ne?Ke?l:c:Ke?_:x,we=Qe?void 0:Er(ge);return t(we||ge,function(or,sr){we&&(sr=or,or=ge[sr]),r(_e,sr,Re(or,ze,Fe,sr,ge,be))}),_e}return Ki=Re,Ki}var Zi,Lf;function Fw(){if(Lf)return Zi;Lf=1;var e=Jm(),t=4;function r(n){return e(n,t)}return Zi=r,Zi}var Ji,Ff;function Ku(){if(Ff)return Ji;Ff=1;function e(t){return function(){return t}}return Ji=e,Ji}var Yi,Bf;function Bw(){if(Bf)return Yi;Bf=1;function e(t){return function(r,n,o){for(var i=-1,a=Object(r),s=o(r),u=s.length;u--;){var c=s[t?u:++i];if(n(a[c],c,a)===!1)break}return r}}return Yi=e,Yi}var Xi,Df;function Zu(){if(Df)return Xi;Df=1;var e=Bw(),t=e();return Xi=t,Xi}var Qi,zf;function Ju(){if(zf)return Qi;zf=1;var e=Zu(),t=Ur();function r(n,o){return n&&e(n,o,t)}return Qi=r,Qi}var ea,Vf;function Dw(){if(Vf)return ea;Vf=1;var e=qr();function t(r,n){return function(o,i){if(o==null)return o;if(!e(o))return r(o,i);for(var a=o.length,s=n?a:-1,u=Object(o);(n?s--:++s<a)&&i(u[s],s,u)!==!1;);return o}}return ea=t,ea}var ra,Wf;function qn(){if(Wf)return ra;Wf=1;var e=Ju(),t=Dw(),r=t(e);return ra=r,ra}var ta,Gf;function ot(){if(Gf)return ta;Gf=1;function e(t){return t}return ta=e,ta}var na,Uf;function Ym(){if(Uf)return na;Uf=1;var e=ot();function t(r){return typeof r=="function"?r:e}return na=t,na}var oa,Hf;function Xm(){if(Hf)return oa;Hf=1;var e=Du(),t=qn(),r=Ym(),n=Ue();function o(i,a){var s=n(i)?e:t;return s(i,r(a))}return oa=o,oa}var ia,Kf;function Qm(){return Kf||(Kf=1,ia=Xm()),ia}var aa,Zf;function zw(){if(Zf)return aa;Zf=1;var e=qn();function t(r,n){var o=[];return e(r,function(i,a,s){n(i,a,s)&&o.push(i)}),o}return aa=t,aa}var sa,Jf;function Vw(){if(Jf)return sa;Jf=1;var e="__lodash_hash_undefined__";function t(r){return this.__data__.set(r,e),this}return sa=t,sa}var ca,Yf;function Ww(){if(Yf)return ca;Yf=1;function e(t){return this.__data__.has(t)}return ca=e,ca}var ua,Xf;function eb(){if(Xf)return ua;Xf=1;var e=Bu(),t=Vw(),r=Ww();function n(o){var i=-1,a=o==null?0:o.length;for(this.__data__=new e;++i<a;)this.add(o[i])}return n.prototype.add=n.prototype.push=t,n.prototype.has=r,ua=n,ua}var la,Qf;function Gw(){if(Qf)return la;Qf=1;function e(t,r){for(var n=-1,o=t==null?0:t.length;++n<o;)if(r(t[n],n,t))return!0;return!1}return la=e,la}var da,eh;function rb(){if(eh)return da;eh=1;function e(t,r){return t.has(r)}return da=e,da}var fa,rh;function tb(){if(rh)return fa;rh=1;var e=eb(),t=Gw(),r=rb(),n=1,o=2;function i(a,s,u,c,l,d){var f=u&n,p=a.length,m=s.length;if(p!=m&&!(f&&m>p))return!1;var y=d.get(a),b=d.get(s);if(y&&b)return y==s&&b==a;var v=-1,g=!0,w=u&o?new e:void 0;for(d.set(a,s),d.set(s,a);++v<p;){var x=a[v],_=s[v];if(c)var C=f?c(_,x,v,s,a,d):c(x,_,v,a,s,d);if(C!==void 0){if(C)continue;g=!1;break}if(w){if(!t(s,function(S,T){if(!r(w,T)&&(x===S||l(x,S,u,c,d)))return w.push(T)})){g=!1;break}}else if(!(x===_||l(x,_,u,c,d))){g=!1;break}}return d.delete(a),d.delete(s),g}return fa=i,fa}var ha,th;function Uw(){if(th)return ha;th=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o,i){n[++r]=[i,o]}),n}return ha=e,ha}var pa,nh;function Yu(){if(nh)return pa;nh=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o){n[++r]=o}),n}return pa=e,pa}var ga,oh;function Hw(){if(oh)return ga;oh=1;var e=mt(),t=Um(),r=yt(),n=tb(),o=Uw(),i=Yu(),a=1,s=2,u="[object Boolean]",c="[object Date]",l="[object Error]",d="[object Map]",f="[object Number]",p="[object RegExp]",m="[object Set]",y="[object String]",b="[object Symbol]",v="[object ArrayBuffer]",g="[object DataView]",w=e?e.prototype:void 0,x=w?w.valueOf:void 0;function _(C,S,T,k,E,P,R){switch(T){case g:if(C.byteLength!=S.byteLength||C.byteOffset!=S.byteOffset)return!1;C=C.buffer,S=S.buffer;case v:return!(C.byteLength!=S.byteLength||!P(new t(C),new t(S)));case u:case c:case f:return r(+C,+S);case l:return C.name==S.name&&C.message==S.message;case p:case y:return C==S+"";case d:var I=o;case m:var O=k&a;if(I||(I=i),C.size!=S.size&&!O)return!1;var M=R.get(C);if(M)return M==S;k|=s,R.set(C,S);var q=n(I(C),I(S),k,E,P,R);return R.delete(C),q;case b:if(x)return x.call(C)==x.call(S)}return!1}return ga=_,ga}var ya,ih;function Kw(){if(ih)return ya;ih=1;var e=Wm(),t=1,r=Object.prototype,n=r.hasOwnProperty;function o(i,a,s,u,c,l){var d=s&t,f=e(i),p=f.length,m=e(a),y=m.length;if(p!=y&&!d)return!1;for(var b=p;b--;){var v=f[b];if(!(d?v in a:n.call(a,v)))return!1}var g=l.get(i),w=l.get(a);if(g&&w)return g==a&&w==i;var x=!0;l.set(i,a),l.set(a,i);for(var _=d;++b<p;){v=f[b];var C=i[v],S=a[v];if(u)var T=d?u(S,C,v,a,i,l):u(C,S,v,i,a,l);if(!(T===void 0?C===S||c(C,S,s,u,l):T)){x=!1;break}_||(_=v=="constructor")}if(x&&!_){var k=i.constructor,E=a.constructor;k!=E&&"constructor"in i&&"constructor"in a&&!(typeof k=="function"&&k instanceof k&&typeof E=="function"&&E instanceof E)&&(x=!1)}return l.delete(i),l.delete(a),x}return ya=o,ya}var ma,ah;function Zw(){if(ah)return ma;ah=1;var e=kn(),t=tb(),r=Hw(),n=Kw(),o=vt(),i=Ue(),a=bt(),s=rn(),u=1,c="[object Arguments]",l="[object Array]",d="[object Object]",f=Object.prototype,p=f.hasOwnProperty;function m(y,b,v,g,w,x){var _=i(y),C=i(b),S=_?l:o(y),T=C?l:o(b);S=S==c?d:S,T=T==c?d:T;var k=S==d,E=T==d,P=S==T;if(P&&a(y)){if(!a(b))return!1;_=!0,k=!1}if(P&&!k)return x||(x=new e),_||s(y)?t(y,b,v,g,w,x):r(y,b,S,v,g,w,x);if(!(v&u)){var R=k&&p.call(y,"__wrapped__"),I=E&&p.call(b,"__wrapped__");if(R||I){var O=R?y.value():y,M=I?b.value():b;return x||(x=new e),w(O,M,v,g,x)}}return P?(x||(x=new e),n(y,b,v,g,w,x)):!1}return ma=m,ma}var ba,sh;function nb(){if(sh)return ba;sh=1;var e=Zw(),t=Pr();function r(n,o,i,a,s){return n===o?!0:n==null||o==null||!t(n)&&!t(o)?n!==n&&o!==o:e(n,o,i,a,r,s)}return ba=r,ba}var va,ch;function Jw(){if(ch)return va;ch=1;var e=kn(),t=nb(),r=1,n=2;function o(i,a,s,u){var c=s.length,l=c,d=!u;if(i==null)return!l;for(i=Object(i);c--;){var f=s[c];if(d&&f[2]?f[1]!==i[f[0]]:!(f[0]in i))return!1}for(;++c<l;){f=s[c];var p=f[0],m=i[p],y=f[1];if(d&&f[2]){if(m===void 0&&!(p in i))return!1}else{var b=new e;if(u)var v=u(m,y,p,i,a,b);if(!(v===void 0?t(y,m,r|n,u,b):v))return!1}}return!0}return va=o,va}var xa,uh;function ob(){if(uh)return xa;uh=1;var e=vr();function t(r){return r===r&&!e(r)}return xa=t,xa}var wa,lh;function Yw(){if(lh)return wa;lh=1;var e=ob(),t=Ur();function r(n){for(var o=t(n),i=o.length;i--;){var a=o[i],s=n[a];o[i]=[a,s,e(s)]}return o}return wa=r,wa}var Ca,dh;function ib(){if(dh)return Ca;dh=1;function e(t,r){return function(n){return n==null?!1:n[t]===r&&(r!==void 0||t in Object(n))}}return Ca=e,Ca}var _a,fh;function Xw(){if(fh)return _a;fh=1;var e=Jw(),t=Yw(),r=ib();function n(o){var i=t(o);return i.length==1&&i[0][2]?r(i[0][0],i[0][1]):function(a){return a===o||e(a,o,i)}}return _a=n,_a}var Sa,hh;function xt(){if(hh)return Sa;hh=1;var e=rt(),t=Pr(),r="[object Symbol]";function n(o){return typeof o=="symbol"||t(o)&&e(o)==r}return Sa=n,Sa}var Ea,ph;function Xu(){if(ph)return Ea;ph=1;var e=Ue(),t=xt(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,a){if(e(i))return!1;var s=typeof i;return s=="number"||s=="symbol"||s=="boolean"||i==null||t(i)?!0:n.test(i)||!r.test(i)||a!=null&&i in Object(a)}return Ea=o,Ea}var ja,gh;function Qw(){if(gh)return ja;gh=1;var e=Bu(),t="Expected a function";function r(n,o){if(typeof n!="function"||o!=null&&typeof o!="function")throw new TypeError(t);var i=function(){var a=arguments,s=o?o.apply(this,a):a[0],u=i.cache;if(u.has(s))return u.get(s);var c=n.apply(this,a);return i.cache=u.set(s,c)||u,c};return i.cache=new(r.Cache||e),i}return r.Cache=e,ja=r,ja}var Ra,yh;function e1(){if(yh)return Ra;yh=1;var e=Qw(),t=500;function r(n){var o=e(n,function(a){return i.size===t&&i.clear(),a}),i=o.cache;return o}return Ra=r,Ra}var ka,mh;function r1(){if(mh)return ka;mh=1;var e=e1(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,n=e(function(o){var i=[];return o.charCodeAt(0)===46&&i.push(""),o.replace(t,function(a,s,u,c){i.push(u?c.replace(r,"$1"):s||a)}),i});return ka=n,ka}var Pa,bh;function Nn(){if(bh)return Pa;bh=1;function e(t,r){for(var n=-1,o=t==null?0:t.length,i=Array(o);++n<o;)i[n]=r(t[n],n,t);return i}return Pa=e,Pa}var Aa,vh;function t1(){if(vh)return Aa;vh=1;var e=mt(),t=Nn(),r=Ue(),n=xt(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function a(s){if(typeof s=="string")return s;if(r(s))return t(s,a)+"";if(n(s))return i?i.call(s):"";var u=s+"";return u=="0"&&1/s==-1/0?"-0":u}return Aa=a,Aa}var Ta,xh;function ab(){if(xh)return Ta;xh=1;var e=t1();function t(r){return r==null?"":e(r)}return Ta=t,Ta}var Oa,wh;function $n(){if(wh)return Oa;wh=1;var e=Ue(),t=Xu(),r=r1(),n=ab();function o(i,a){return e(i)?i:t(i,a)?[i]:r(n(i))}return Oa=o,Oa}var Ia,Ch;function tn(){if(Ch)return Ia;Ch=1;var e=xt();function t(r){if(typeof r=="string"||e(r))return r;var n=r+"";return n=="0"&&1/r==-1/0?"-0":n}return Ia=t,Ia}var Ma,_h;function Ln(){if(_h)return Ma;_h=1;var e=$n(),t=tn();function r(n,o){o=e(o,n);for(var i=0,a=o.length;n!=null&&i<a;)n=n[t(o[i++])];return i&&i==a?n:void 0}return Ma=r,Ma}var qa,Sh;function n1(){if(Sh)return qa;Sh=1;var e=Ln();function t(r,n,o){var i=r==null?void 0:e(r,n);return i===void 0?o:i}return qa=t,qa}var Na,Eh;function o1(){if(Eh)return Na;Eh=1;function e(t,r){return t!=null&&r in Object(t)}return Na=e,Na}var $a,jh;function sb(){if(jh)return $a;jh=1;var e=$n(),t=en(),r=Ue(),n=Tn(),o=zu(),i=tn();function a(s,u,c){u=e(u,s);for(var l=-1,d=u.length,f=!1;++l<d;){var p=i(u[l]);if(!(f=s!=null&&c(s,p)))break;s=s[p]}return f||++l!=d?f:(d=s==null?0:s.length,!!d&&o(d)&&n(p,d)&&(r(s)||t(s)))}return $a=a,$a}var La,Rh;function cb(){if(Rh)return La;Rh=1;var e=o1(),t=sb();function r(n,o){return n!=null&&t(n,o,e)}return La=r,La}var Fa,kh;function i1(){if(kh)return Fa;kh=1;var e=nb(),t=n1(),r=cb(),n=Xu(),o=ob(),i=ib(),a=tn(),s=1,u=2;function c(l,d){return n(l)&&o(d)?i(a(l),d):function(f){var p=t(f,l);return p===void 0&&p===d?r(f,l):e(d,p,s|u)}}return Fa=c,Fa}var Ba,Ph;function ub(){if(Ph)return Ba;Ph=1;function e(t){return function(r){return r==null?void 0:r[t]}}return Ba=e,Ba}var Da,Ah;function a1(){if(Ah)return Da;Ah=1;var e=Ln();function t(r){return function(n){return e(n,r)}}return Da=t,Da}var za,Th;function s1(){if(Th)return za;Th=1;var e=ub(),t=a1(),r=Xu(),n=tn();function o(i){return r(i)?e(n(i)):t(i)}return za=o,za}var Va,Oh;function Nr(){if(Oh)return Va;Oh=1;var e=Xw(),t=i1(),r=ot(),n=Ue(),o=s1();function i(a){return typeof a=="function"?a:a==null?r:typeof a=="object"?n(a)?t(a[0],a[1]):e(a):o(a)}return Va=i,Va}var Wa,Ih;function lb(){if(Ih)return Wa;Ih=1;var e=Bm(),t=zw(),r=Nr(),n=Ue();function o(i,a){var s=n(i)?e:t;return s(i,r(a,3))}return Wa=o,Wa}var Ga,Mh;function c1(){if(Mh)return Ga;Mh=1;var e=Object.prototype,t=e.hasOwnProperty;function r(n,o){return n!=null&&t.call(n,o)}return Ga=r,Ga}var Ua,qh;function db(){if(qh)return Ua;qh=1;var e=c1(),t=sb();function r(n,o){return n!=null&&t(n,o,e)}return Ua=r,Ua}var Ha,Nh;function u1(){if(Nh)return Ha;Nh=1;var e=Wu(),t=vt(),r=en(),n=Ue(),o=qr(),i=bt(),a=In(),s=rn(),u="[object Map]",c="[object Set]",l=Object.prototype,d=l.hasOwnProperty;function f(p){if(p==null)return!0;if(o(p)&&(n(p)||typeof p=="string"||typeof p.splice=="function"||i(p)||s(p)||r(p)))return!p.length;var m=t(p);if(m==u||m==c)return!p.size;if(a(p))return!e(p).length;for(var y in p)if(d.call(p,y))return!1;return!0}return Ha=f,Ha}var Ka,$h;function fb(){if($h)return Ka;$h=1;function e(t){return t===void 0}return Ka=e,Ka}var Za,Lh;function hb(){if(Lh)return Za;Lh=1;var e=qn(),t=qr();function r(n,o){var i=-1,a=t(n)?Array(n.length):[];return e(n,function(s,u,c){a[++i]=o(s,u,c)}),a}return Za=r,Za}var Ja,Fh;function pb(){if(Fh)return Ja;Fh=1;var e=Nn(),t=Nr(),r=hb(),n=Ue();function o(i,a){var s=n(i)?e:r;return s(i,t(a,3))}return Ja=o,Ja}var Ya,Bh;function l1(){if(Bh)return Ya;Bh=1;function e(t,r,n,o){var i=-1,a=t==null?0:t.length;for(o&&a&&(n=t[++i]);++i<a;)n=r(n,t[i],i,t);return n}return Ya=e,Ya}var Xa,Dh;function d1(){if(Dh)return Xa;Dh=1;function e(t,r,n,o,i){return i(t,function(a,s,u){n=o?(o=!1,a):r(n,a,s,u)}),n}return Xa=e,Xa}var Qa,zh;function gb(){if(zh)return Qa;zh=1;var e=l1(),t=qn(),r=Nr(),n=d1(),o=Ue();function i(a,s,u){var c=o(a)?e:n,l=arguments.length<3;return c(a,r(s,4),u,l,t)}return Qa=i,Qa}var es,Vh;function f1(){if(Vh)return es;Vh=1;var e=rt(),t=Ue(),r=Pr(),n="[object String]";function o(i){return typeof i=="string"||!t(i)&&r(i)&&e(i)==n}return es=o,es}var rs,Wh;function h1(){if(Wh)return rs;Wh=1;var e=ub(),t=e("length");return rs=t,rs}var ts,Gh;function p1(){if(Gh)return ts;Gh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",a="\\u200d",s=RegExp("["+a+e+o+i+"]");function u(c){return s.test(c)}return ts=u,ts}var ns,Uh;function g1(){if(Uh)return ns;Uh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",a="["+e+"]",s="["+o+"]",u="\\ud83c[\\udffb-\\udfff]",c="(?:"+s+"|"+u+")",l="[^"+e+"]",d="(?:\\ud83c[\\udde6-\\uddff]){2}",f="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",m=c+"?",y="["+i+"]?",b="(?:"+p+"(?:"+[l,d,f].join("|")+")"+y+m+")*",v=y+m+b,g="(?:"+[l+s+"?",s,d,f,a].join("|")+")",w=RegExp(u+"(?="+u+")|"+g+v,"g");function x(_){for(var C=w.lastIndex=0;w.test(_);)++C;return C}return ns=x,ns}var os,Hh;function y1(){if(Hh)return os;Hh=1;var e=h1(),t=p1(),r=g1();function n(o){return t(o)?r(o):e(o)}return os=n,os}var is,Kh;function m1(){if(Kh)return is;Kh=1;var e=Wu(),t=vt(),r=qr(),n=f1(),o=y1(),i="[object Map]",a="[object Set]";function s(u){if(u==null)return 0;if(r(u))return n(u)?o(u):u.length;var c=t(u);return c==i||c==a?u.size:e(u).length}return is=s,is}var as,Zh;function b1(){if(Zh)return as;Zh=1;var e=Du(),t=Km(),r=Ju(),n=Nr(),o=Mn(),i=Ue(),a=bt(),s=Xt(),u=vr(),c=rn();function l(d,f,p){var m=i(d),y=m||a(d)||c(d);if(f=n(f,4),p==null){var b=d&&d.constructor;y?p=m?new b:[]:u(d)?p=s(b)?t(o(d)):{}:p={}}return(y?e:r)(d,function(v,g,w){return f(p,v,g,w)}),p}return as=l,as}var ss,Jh;function v1(){if(Jh)return ss;Jh=1;var e=mt(),t=en(),r=Ue(),n=e?e.isConcatSpreadable:void 0;function o(i){return r(i)||t(i)||!!(n&&i&&i[n])}return ss=o,ss}var cs,Yh;function Qu(){if(Yh)return cs;Yh=1;var e=Uu(),t=v1();function r(n,o,i,a,s){var u=-1,c=n.length;for(i||(i=t),s||(s=[]);++u<c;){var l=n[u];o>0&&i(l)?o>1?r(l,o-1,i,a,s):e(s,l):a||(s[s.length]=l)}return s}return cs=r,cs}var us,Xh;function x1(){if(Xh)return us;Xh=1;function e(t,r,n){switch(n.length){case 0:return t.call(r);case 1:return t.call(r,n[0]);case 2:return t.call(r,n[0],n[1]);case 3:return t.call(r,n[0],n[1],n[2])}return t.apply(r,n)}return us=e,us}var ls,Qh;function yb(){if(Qh)return ls;Qh=1;var e=x1(),t=Math.max;function r(n,o,i){return o=t(o===void 0?n.length-1:o,0),function(){for(var a=arguments,s=-1,u=t(a.length-o,0),c=Array(u);++s<u;)c[s]=a[o+s];s=-1;for(var l=Array(o+1);++s<o;)l[s]=a[s];return l[o]=i(c),e(n,this,l)}}return ls=r,ls}var ds,ep;function w1(){if(ep)return ds;ep=1;var e=Ku(),t=qm(),r=ot(),n=t?function(o,i){return t(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:r;return ds=n,ds}var fs,rp;function C1(){if(rp)return fs;rp=1;var e=800,t=16,r=Date.now;function n(o){var i=0,a=0;return function(){var s=r(),u=t-(s-a);if(a=s,u>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return fs=n,fs}var hs,tp;function mb(){if(tp)return hs;tp=1;var e=w1(),t=C1(),r=t(e);return hs=r,hs}var ps,np;function Fn(){if(np)return ps;np=1;var e=ot(),t=yb(),r=mb();function n(o,i){return r(t(o,i,e),o+"")}return ps=n,ps}var gs,op;function bb(){if(op)return gs;op=1;function e(t,r,n,o){for(var i=t.length,a=n+(o?1:-1);o?a--:++a<i;)if(r(t[a],a,t))return a;return-1}return gs=e,gs}var ys,ip;function _1(){if(ip)return ys;ip=1;function e(t){return t!==t}return ys=e,ys}var ms,ap;function S1(){if(ap)return ms;ap=1;function e(t,r,n){for(var o=n-1,i=t.length;++o<i;)if(t[o]===r)return o;return-1}return ms=e,ms}var bs,sp;function E1(){if(sp)return bs;sp=1;var e=bb(),t=_1(),r=S1();function n(o,i,a){return i===i?r(o,i,a):e(o,t,a)}return bs=n,bs}var vs,cp;function j1(){if(cp)return vs;cp=1;var e=E1();function t(r,n){var o=r==null?0:r.length;return!!o&&e(r,n,0)>-1}return vs=t,vs}var xs,up;function R1(){if(up)return xs;up=1;function e(t,r,n){for(var o=-1,i=t==null?0:t.length;++o<i;)if(n(r,t[o]))return!0;return!1}return xs=e,xs}var ws,lp;function k1(){if(lp)return ws;lp=1;function e(){}return ws=e,ws}var Cs,dp;function P1(){if(dp)return Cs;dp=1;var e=Gm(),t=k1(),r=Yu(),n=1/0,o=e&&1/r(new e([,-0]))[1]==n?function(i){return new e(i)}:t;return Cs=o,Cs}var _s,fp;function A1(){if(fp)return _s;fp=1;var e=eb(),t=j1(),r=R1(),n=rb(),o=P1(),i=Yu(),a=200;function s(u,c,l){var d=-1,f=t,p=u.length,m=!0,y=[],b=y;if(l)m=!1,f=r;else if(p>=a){var v=c?null:o(u);if(v)return i(v);m=!1,f=n,b=new e}else b=c?[]:y;e:for(;++d<p;){var g=u[d],w=c?c(g):g;if(g=l||g!==0?g:0,m&&w===w){for(var x=b.length;x--;)if(b[x]===w)continue e;c&&b.push(w),y.push(g)}else f(b,w,l)||(b!==y&&b.push(w),y.push(g))}return y}return _s=s,_s}var Ss,hp;function vb(){if(hp)return Ss;hp=1;var e=qr(),t=Pr();function r(n){return t(n)&&e(n)}return Ss=r,Ss}var Es,pp;function T1(){if(pp)return Es;pp=1;var e=Qu(),t=Fn(),r=A1(),n=vb(),o=t(function(i){return r(e(i,1,n,!0))});return Es=o,Es}var js,gp;function O1(){if(gp)return js;gp=1;var e=Nn();function t(r,n){return e(n,function(o){return r[o]})}return js=t,js}var Rs,yp;function xb(){if(yp)return Rs;yp=1;var e=O1(),t=Ur();function r(n){return n==null?[]:e(n,t(n))}return Rs=r,Rs}var ks,mp;function xr(){if(mp)return ks;mp=1;var e;if(typeof Lu=="function")try{e={clone:Fw(),constant:Ku(),each:Qm(),filter:lb(),has:db(),isArray:Ue(),isEmpty:u1(),isFunction:Xt(),isUndefined:fb(),keys:Ur(),map:pb(),reduce:gb(),size:m1(),transform:b1(),union:T1(),values:xb()}}catch{}return e||(e=window._),ks=e,ks}var Ps,bp;function el(){if(bp)return Ps;bp=1;var e=xr();Ps=o;var t="\0",r="\0",n="";function o(l){this._isDirected=e.has(l,"directed")?l.directed:!0,this._isMultigraph=e.has(l,"multigraph")?l.multigraph:!1,this._isCompound=e.has(l,"compound")?l.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[r]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}o.prototype._nodeCount=0,o.prototype._edgeCount=0,o.prototype.isDirected=function(){return this._isDirected},o.prototype.isMultigraph=function(){return this._isMultigraph},o.prototype.isCompound=function(){return this._isCompound},o.prototype.setGraph=function(l){return this._label=l,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(l){return e.isFunction(l)||(l=e.constant(l)),this._defaultNodeLabelFn=l,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var l=this;return e.filter(this.nodes(),function(d){return e.isEmpty(l._in[d])})},o.prototype.sinks=function(){var l=this;return e.filter(this.nodes(),function(d){return e.isEmpty(l._out[d])})},o.prototype.setNodes=function(l,d){var f=arguments,p=this;return e.each(l,function(m){f.length>1?p.setNode(m,d):p.setNode(m)}),this},o.prototype.setNode=function(l,d){return e.has(this._nodes,l)?(arguments.length>1&&(this._nodes[l]=d),this):(this._nodes[l]=arguments.length>1?d:this._defaultNodeLabelFn(l),this._isCompound&&(this._parent[l]=r,this._children[l]={},this._children[r][l]=!0),this._in[l]={},this._preds[l]={},this._out[l]={},this._sucs[l]={},++this._nodeCount,this)},o.prototype.node=function(l){return this._nodes[l]},o.prototype.hasNode=function(l){return e.has(this._nodes,l)},o.prototype.removeNode=function(l){var d=this;if(e.has(this._nodes,l)){var f=function(p){d.removeEdge(d._edgeObjs[p])};delete this._nodes[l],this._isCompound&&(this._removeFromParentsChildList(l),delete this._parent[l],e.each(this.children(l),function(p){d.setParent(p)}),delete this._children[l]),e.each(e.keys(this._in[l]),f),delete this._in[l],delete this._preds[l],e.each(e.keys(this._out[l]),f),delete this._out[l],delete this._sucs[l],--this._nodeCount}return this},o.prototype.setParent=function(l,d){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(d))d=r;else{d+="";for(var f=d;!e.isUndefined(f);f=this.parent(f))if(f===l)throw new Error("Setting "+d+" as parent of "+l+" would create a cycle");this.setNode(d)}return this.setNode(l),this._removeFromParentsChildList(l),this._parent[l]=d,this._children[d][l]=!0,this},o.prototype._removeFromParentsChildList=function(l){delete this._children[this._parent[l]][l]},o.prototype.parent=function(l){if(this._isCompound){var d=this._parent[l];if(d!==r)return d}},o.prototype.children=function(l){if(e.isUndefined(l)&&(l=r),this._isCompound){var d=this._children[l];if(d)return e.keys(d)}else{if(l===r)return this.nodes();if(this.hasNode(l))return[]}},o.prototype.predecessors=function(l){var d=this._preds[l];if(d)return e.keys(d)},o.prototype.successors=function(l){var d=this._sucs[l];if(d)return e.keys(d)},o.prototype.neighbors=function(l){var d=this.predecessors(l);if(d)return e.union(d,this.successors(l))},o.prototype.isLeaf=function(l){var d;return this.isDirected()?d=this.successors(l):d=this.neighbors(l),d.length===0},o.prototype.filterNodes=function(l){var d=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});d.setGraph(this.graph());var f=this;e.each(this._nodes,function(y,b){l(b)&&d.setNode(b,y)}),e.each(this._edgeObjs,function(y){d.hasNode(y.v)&&d.hasNode(y.w)&&d.setEdge(y,f.edge(y))});var p={};function m(y){var b=f.parent(y);return b===void 0||d.hasNode(b)?(p[y]=b,b):b in p?p[b]:m(b)}return this._isCompound&&e.each(d.nodes(),function(y){d.setParent(y,m(y))}),d},o.prototype.setDefaultEdgeLabel=function(l){return e.isFunction(l)||(l=e.constant(l)),this._defaultEdgeLabelFn=l,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(l,d){var f=this,p=arguments;return e.reduce(l,function(m,y){return p.length>1?f.setEdge(m,y,d):f.setEdge(m,y),y}),this},o.prototype.setEdge=function(){var l,d,f,p,m=!1,y=arguments[0];typeof y=="object"&&y!==null&&"v"in y?(l=y.v,d=y.w,f=y.name,arguments.length===2&&(p=arguments[1],m=!0)):(l=y,d=arguments[1],f=arguments[3],arguments.length>2&&(p=arguments[2],m=!0)),l=""+l,d=""+d,e.isUndefined(f)||(f=""+f);var b=s(this._isDirected,l,d,f);if(e.has(this._edgeLabels,b))return m&&(this._edgeLabels[b]=p),this;if(!e.isUndefined(f)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(l),this.setNode(d),this._edgeLabels[b]=m?p:this._defaultEdgeLabelFn(l,d,f);var v=u(this._isDirected,l,d,f);return l=v.v,d=v.w,Object.freeze(v),this._edgeObjs[b]=v,i(this._preds[d],l),i(this._sucs[l],d),this._in[d][b]=v,this._out[l][b]=v,this._edgeCount++,this},o.prototype.edge=function(l,d,f){var p=arguments.length===1?c(this._isDirected,arguments[0]):s(this._isDirected,l,d,f);return this._edgeLabels[p]},o.prototype.hasEdge=function(l,d,f){var p=arguments.length===1?c(this._isDirected,arguments[0]):s(this._isDirected,l,d,f);return e.has(this._edgeLabels,p)},o.prototype.removeEdge=function(l,d,f){var p=arguments.length===1?c(this._isDirected,arguments[0]):s(this._isDirected,l,d,f),m=this._edgeObjs[p];return m&&(l=m.v,d=m.w,delete this._edgeLabels[p],delete this._edgeObjs[p],a(this._preds[d],l),a(this._sucs[l],d),delete this._in[d][p],delete this._out[l][p],this._edgeCount--),this},o.prototype.inEdges=function(l,d){var f=this._in[l];if(f){var p=e.values(f);return d?e.filter(p,function(m){return m.v===d}):p}},o.prototype.outEdges=function(l,d){var f=this._out[l];if(f){var p=e.values(f);return d?e.filter(p,function(m){return m.w===d}):p}},o.prototype.nodeEdges=function(l,d){var f=this.inEdges(l,d);if(f)return f.concat(this.outEdges(l,d))};function i(l,d){l[d]?l[d]++:l[d]=1}function a(l,d){--l[d]||delete l[d]}function s(l,d,f,p){var m=""+d,y=""+f;if(!l&&m>y){var b=m;m=y,y=b}return m+n+y+n+(e.isUndefined(p)?t:p)}function u(l,d,f,p){var m=""+d,y=""+f;if(!l&&m>y){var b=m;m=y,y=b}var v={v:m,w:y};return p&&(v.name=p),v}function c(l,d){return s(l,d.v,d.w,d.name)}return Ps}var As,vp;function I1(){return vp||(vp=1,As="2.1.8"),As}var Ts,xp;function M1(){return xp||(xp=1,Ts={Graph:el(),version:I1()}),Ts}var Os,wp;function q1(){if(wp)return Os;wp=1;var e=xr(),t=el();Os={write:r,read:i};function r(a){var s={options:{directed:a.isDirected(),multigraph:a.isMultigraph(),compound:a.isCompound()},nodes:n(a),edges:o(a)};return e.isUndefined(a.graph())||(s.value=e.clone(a.graph())),s}function n(a){return e.map(a.nodes(),function(s){var u=a.node(s),c=a.parent(s),l={v:s};return e.isUndefined(u)||(l.value=u),e.isUndefined(c)||(l.parent=c),l})}function o(a){return e.map(a.edges(),function(s){var u=a.edge(s),c={v:s.v,w:s.w};return e.isUndefined(s.name)||(c.name=s.name),e.isUndefined(u)||(c.value=u),c})}function i(a){var s=new t(a.options).setGraph(a.value);return e.each(a.nodes,function(u){s.setNode(u.v,u.value),u.parent&&s.setParent(u.v,u.parent)}),e.each(a.edges,function(u){s.setEdge({v:u.v,w:u.w,name:u.name},u.value)}),s}return Os}var Is,Cp;function N1(){if(Cp)return Is;Cp=1;var e=xr();Is=t;function t(r){var n={},o=[],i;function a(s){e.has(n,s)||(n[s]=!0,i.push(s),e.each(r.successors(s),a),e.each(r.predecessors(s),a))}return e.each(r.nodes(),function(s){i=[],a(s),i.length&&o.push(i)}),o}return Is}var Ms,_p;function wb(){if(_p)return Ms;_p=1;var e=xr();Ms=t;function t(){this._arr=[],this._keyIndices={}}return t.prototype.size=function(){return this._arr.length},t.prototype.keys=function(){return this._arr.map(function(r){return r.key})},t.prototype.has=function(r){return e.has(this._keyIndices,r)},t.prototype.priority=function(r){var n=this._keyIndices[r];if(n!==void 0)return this._arr[n].priority},t.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},t.prototype.add=function(r,n){var o=this._keyIndices;if(r=String(r),!e.has(o,r)){var i=this._arr,a=i.length;return o[r]=a,i.push({key:r,priority:n}),this._decrease(a),!0}return!1},t.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var r=this._arr.pop();return delete this._keyIndices[r.key],this._heapify(0),r.key},t.prototype.decrease=function(r,n){var o=this._keyIndices[r];if(n>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+r+" Old: "+this._arr[o].priority+" New: "+n);this._arr[o].priority=n,this._decrease(o)},t.prototype._heapify=function(r){var n=this._arr,o=2*r,i=o+1,a=r;o<n.length&&(a=n[o].priority<n[a].priority?o:a,i<n.length&&(a=n[i].priority<n[a].priority?i:a),a!==r&&(this._swap(r,a),this._heapify(a)))},t.prototype._decrease=function(r){for(var n=this._arr,o=n[r].priority,i;r!==0&&(i=r>>1,!(n[i].priority<o));)this._swap(r,i),r=i},t.prototype._swap=function(r,n){var o=this._arr,i=this._keyIndices,a=o[r],s=o[n];o[r]=s,o[n]=a,i[s.key]=r,i[a.key]=n},Ms}var qs,Sp;function Cb(){if(Sp)return qs;Sp=1;var e=xr(),t=wb();qs=n;var r=e.constant(1);function n(i,a,s,u){return o(i,String(a),s||r,u||function(c){return i.outEdges(c)})}function o(i,a,s,u){var c={},l=new t,d,f,p=function(m){var y=m.v!==d?m.v:m.w,b=c[y],v=s(m),g=f.distance+v;if(v<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+m+" Weight: "+v);g<b.distance&&(b.distance=g,b.predecessor=d,l.decrease(y,g))};for(i.nodes().forEach(function(m){var y=m===a?0:Number.POSITIVE_INFINITY;c[m]={distance:y},l.add(m,y)});l.size()>0&&(d=l.removeMin(),f=c[d],f.distance!==Number.POSITIVE_INFINITY);)u(d).forEach(p);return c}return qs}var Ns,Ep;function $1(){if(Ep)return Ns;Ep=1;var e=Cb(),t=xr();Ns=r;function r(n,o,i){return t.transform(n.nodes(),function(a,s){a[s]=e(n,s,o,i)},{})}return Ns}var $s,jp;function _b(){if(jp)return $s;jp=1;var e=xr();$s=t;function t(r){var n=0,o=[],i={},a=[];function s(u){var c=i[u]={onStack:!0,lowlink:n,index:n++};if(o.push(u),r.successors(u).forEach(function(f){e.has(i,f)?i[f].onStack&&(c.lowlink=Math.min(c.lowlink,i[f].index)):(s(f),c.lowlink=Math.min(c.lowlink,i[f].lowlink))}),c.lowlink===c.index){var l=[],d;do d=o.pop(),i[d].onStack=!1,l.push(d);while(u!==d);a.push(l)}}return r.nodes().forEach(function(u){e.has(i,u)||s(u)}),a}return $s}var Ls,Rp;function L1(){if(Rp)return Ls;Rp=1;var e=xr(),t=_b();Ls=r;function r(n){return e.filter(t(n),function(o){return o.length>1||o.length===1&&n.hasEdge(o[0],o[0])})}return Ls}var Fs,kp;function F1(){if(kp)return Fs;kp=1;var e=xr();Fs=r;var t=e.constant(1);function r(o,i,a){return n(o,i||t,a||function(s){return o.outEdges(s)})}function n(o,i,a){var s={},u=o.nodes();return u.forEach(function(c){s[c]={},s[c][c]={distance:0},u.forEach(function(l){c!==l&&(s[c][l]={distance:Number.POSITIVE_INFINITY})}),a(c).forEach(function(l){var d=l.v===c?l.w:l.v,f=i(l);s[c][d]={distance:f,predecessor:c}})}),u.forEach(function(c){var l=s[c];u.forEach(function(d){var f=s[d];u.forEach(function(p){var m=f[c],y=l[p],b=f[p],v=m.distance+y.distance;v<b.distance&&(b.distance=v,b.predecessor=y.predecessor)})})}),s}return Fs}var Bs,Pp;function Sb(){if(Pp)return Bs;Pp=1;var e=xr();Bs=t,t.CycleException=r;function t(n){var o={},i={},a=[];function s(u){if(e.has(i,u))throw new r;e.has(o,u)||(i[u]=!0,o[u]=!0,e.each(n.predecessors(u),s),delete i[u],a.push(u))}if(e.each(n.sinks(),s),e.size(o)!==n.nodeCount())throw new r;return a}function r(){}return r.prototype=new Error,Bs}var Ds,Ap;function B1(){if(Ap)return Ds;Ap=1;var e=Sb();Ds=t;function t(r){try{e(r)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Ds}var zs,Tp;function Eb(){if(Tp)return zs;Tp=1;var e=xr();zs=t;function t(n,o,i){e.isArray(o)||(o=[o]);var a=(n.isDirected()?n.successors:n.neighbors).bind(n),s=[],u={};return e.each(o,function(c){if(!n.hasNode(c))throw new Error("Graph does not have node: "+c);r(n,c,i==="post",u,a,s)}),s}function r(n,o,i,a,s,u){e.has(a,o)||(a[o]=!0,i||u.push(o),e.each(s(o),function(c){r(n,c,i,a,s,u)}),i&&u.push(o))}return zs}var Vs,Op;function D1(){if(Op)return Vs;Op=1;var e=Eb();Vs=t;function t(r,n){return e(r,n,"post")}return Vs}var Ws,Ip;function z1(){if(Ip)return Ws;Ip=1;var e=Eb();Ws=t;function t(r,n){return e(r,n,"pre")}return Ws}var Gs,Mp;function V1(){if(Mp)return Gs;Mp=1;var e=xr(),t=el(),r=wb();Gs=n;function n(o,i){var a=new t,s={},u=new r,c;function l(f){var p=f.v===c?f.w:f.v,m=u.priority(p);if(m!==void 0){var y=i(f);y<m&&(s[p]=c,u.decrease(p,y))}}if(o.nodeCount()===0)return a;e.each(o.nodes(),function(f){u.add(f,Number.POSITIVE_INFINITY),a.setNode(f)}),u.decrease(o.nodes()[0],0);for(var d=!1;u.size()>0;){if(c=u.removeMin(),e.has(s,c))a.setEdge(c,s[c]);else{if(d)throw new Error("Input graph is not connected: "+o);d=!0}o.nodeEdges(c).forEach(l)}return a}return Gs}var Us,qp;function W1(){return qp||(qp=1,Us={components:N1(),dijkstra:Cb(),dijkstraAll:$1(),findCycles:L1(),floydWarshall:F1(),isAcyclic:B1(),postorder:D1(),preorder:z1(),prim:V1(),tarjan:_b(),topsort:Sb()}),Us}var Hs,Np;function G1(){if(Np)return Hs;Np=1;var e=M1();return Hs={Graph:e.Graph,json:q1(),alg:W1(),version:e.version},Hs}var Ks,$p;function _r(){if($p)return Ks;$p=1;var e;if(typeof Lu=="function")try{e=G1()}catch{}return e||(e=window.graphlib),Ks=e,Ks}var Zs,Lp;function U1(){if(Lp)return Zs;Lp=1;var e=Jm(),t=1,r=4;function n(o){return e(o,t|r)}return Zs=n,Zs}var Js,Fp;function Bn(){if(Fp)return Js;Fp=1;var e=yt(),t=qr(),r=Tn(),n=vr();function o(i,a,s){if(!n(s))return!1;var u=typeof a;return(u=="number"?t(s)&&r(a,s.length):u=="string"&&a in s)?e(s[a],i):!1}return Js=o,Js}var Ys,Bp;function H1(){if(Bp)return Ys;Bp=1;var e=Fn(),t=yt(),r=Bn(),n=nt(),o=Object.prototype,i=o.hasOwnProperty,a=e(function(s,u){s=Object(s);var c=-1,l=u.length,d=l>2?u[2]:void 0;for(d&&r(u[0],u[1],d)&&(l=1);++c<l;)for(var f=u[c],p=n(f),m=-1,y=p.length;++m<y;){var b=p[m],v=s[b];(v===void 0||t(v,o[b])&&!i.call(s,b))&&(s[b]=f[b])}return s});return Ys=a,Ys}var Xs,Dp;function K1(){if(Dp)return Xs;Dp=1;var e=Nr(),t=qr(),r=Ur();function n(o){return function(i,a,s){var u=Object(i);if(!t(i)){var c=e(a,3);i=r(i),a=function(d){return c(u[d],d,u)}}var l=o(i,a,s);return l>-1?u[c?i[l]:l]:void 0}}return Xs=n,Xs}var Qs,zp;function Z1(){if(zp)return Qs;zp=1;var e=/\s/;function t(r){for(var n=r.length;n--&&e.test(r.charAt(n)););return n}return Qs=t,Qs}var ec,Vp;function J1(){if(Vp)return ec;Vp=1;var e=Z1(),t=/^\s+/;function r(n){return n&&n.slice(0,e(n)+1).replace(t,"")}return ec=r,ec}var rc,Wp;function Y1(){if(Wp)return rc;Wp=1;var e=J1(),t=vr(),r=xt(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,a=/^0o[0-7]+$/i,s=parseInt;function u(c){if(typeof c=="number")return c;if(r(c))return n;if(t(c)){var l=typeof c.valueOf=="function"?c.valueOf():c;c=t(l)?l+"":l}if(typeof c!="string")return c===0?c:+c;c=e(c);var d=i.test(c);return d||a.test(c)?s(c.slice(2),d?2:8):o.test(c)?n:+c}return rc=u,rc}var tc,Gp;function jb(){if(Gp)return tc;Gp=1;var e=Y1(),t=1/0,r=17976931348623157e292;function n(o){if(!o)return o===0?o:0;if(o=e(o),o===t||o===-t){var i=o<0?-1:1;return i*r}return o===o?o:0}return tc=n,tc}var nc,Up;function X1(){if(Up)return nc;Up=1;var e=jb();function t(r){var n=e(r),o=n%1;return n===n?o?n-o:n:0}return nc=t,nc}var oc,Hp;function Q1(){if(Hp)return oc;Hp=1;var e=bb(),t=Nr(),r=X1(),n=Math.max;function o(i,a,s){var u=i==null?0:i.length;if(!u)return-1;var c=s==null?0:r(s);return c<0&&(c=n(u+c,0)),e(i,t(a,3),c)}return oc=o,oc}var ic,Kp;function eC(){if(Kp)return ic;Kp=1;var e=K1(),t=Q1(),r=e(t);return ic=r,ic}var ac,Zp;function Rb(){if(Zp)return ac;Zp=1;var e=Qu();function t(r){var n=r==null?0:r.length;return n?e(r,1):[]}return ac=t,ac}var sc,Jp;function rC(){if(Jp)return sc;Jp=1;var e=Zu(),t=Ym(),r=nt();function n(o,i){return o==null?o:e(o,t(i),r)}return sc=n,sc}var cc,Yp;function tC(){if(Yp)return cc;Yp=1;function e(t){var r=t==null?0:t.length;return r?t[r-1]:void 0}return cc=e,cc}var uc,Xp;function nC(){if(Xp)return uc;Xp=1;var e=Pn(),t=Ju(),r=Nr();function n(o,i){var a={};return i=r(i,3),t(o,function(s,u,c){e(a,u,i(s,u,c))}),a}return uc=n,uc}var lc,Qp;function rl(){if(Qp)return lc;Qp=1;var e=xt();function t(r,n,o){for(var i=-1,a=r.length;++i<a;){var s=r[i],u=n(s);if(u!=null&&(c===void 0?u===u&&!e(u):o(u,c)))var c=u,l=s}return l}return lc=t,lc}var dc,eg;function oC(){if(eg)return dc;eg=1;function e(t,r){return t>r}return dc=e,dc}var fc,rg;function iC(){if(rg)return fc;rg=1;var e=rl(),t=oC(),r=ot();function n(o){return o&&o.length?e(o,r,t):void 0}return fc=n,fc}var hc,tg;function kb(){if(tg)return hc;tg=1;var e=Pn(),t=yt();function r(n,o,i){(i!==void 0&&!t(n[o],i)||i===void 0&&!(o in n))&&e(n,o,i)}return hc=r,hc}var pc,ng;function aC(){if(ng)return pc;ng=1;var e=rt(),t=Mn(),r=Pr(),n="[object Object]",o=Function.prototype,i=Object.prototype,a=o.toString,s=i.hasOwnProperty,u=a.call(Object);function c(l){if(!r(l)||e(l)!=n)return!1;var d=t(l);if(d===null)return!0;var f=s.call(d,"constructor")&&d.constructor;return typeof f=="function"&&f instanceof f&&a.call(f)==u}return pc=c,pc}var gc,og;function Pb(){if(og)return gc;og=1;function e(t,r){if(!(r==="constructor"&&typeof t[r]=="function")&&r!="__proto__")return t[r]}return gc=e,gc}var yc,ig;function sC(){if(ig)return yc;ig=1;var e=Qt(),t=nt();function r(n){return e(n,t(n))}return yc=r,yc}var mc,ag;function cC(){if(ag)return mc;ag=1;var e=kb(),t=Lm(),r=Hm(),n=Fm(),o=Zm(),i=en(),a=Ue(),s=vb(),u=bt(),c=Xt(),l=vr(),d=aC(),f=rn(),p=Pb(),m=sC();function y(b,v,g,w,x,_,C){var S=p(b,g),T=p(v,g),k=C.get(T);if(k){e(b,g,k);return}var E=_?_(S,T,g+"",b,v,C):void 0,P=E===void 0;if(P){var R=a(T),I=!R&&u(T),O=!R&&!I&&f(T);E=T,R||I||O?a(S)?E=S:s(S)?E=n(S):I?(P=!1,E=t(T,!0)):O?(P=!1,E=r(T,!0)):E=[]:d(T)||i(T)?(E=S,i(S)?E=m(S):(!l(S)||c(S))&&(E=o(T))):P=!1}P&&(C.set(T,E),x(E,T,w,_,C),C.delete(T)),e(b,g,E)}return mc=y,mc}var bc,sg;function uC(){if(sg)return bc;sg=1;var e=kn(),t=kb(),r=Zu(),n=cC(),o=vr(),i=nt(),a=Pb();function s(u,c,l,d,f){u!==c&&r(c,function(p,m){if(f||(f=new e),o(p))n(u,c,m,l,s,d,f);else{var y=d?d(a(u,m),p,m+"",u,c,f):void 0;y===void 0&&(y=p),t(u,m,y)}},i)}return bc=s,bc}var vc,cg;function lC(){if(cg)return vc;cg=1;var e=Fn(),t=Bn();function r(n){return e(function(o,i){var a=-1,s=i.length,u=s>1?i[s-1]:void 0,c=s>2?i[2]:void 0;for(u=n.length>3&&typeof u=="function"?(s--,u):void 0,c&&t(i[0],i[1],c)&&(u=s<3?void 0:u,s=1),o=Object(o);++a<s;){var l=i[a];l&&n(o,l,a,u)}return o})}return vc=r,vc}var xc,ug;function dC(){if(ug)return xc;ug=1;var e=uC(),t=lC(),r=t(function(n,o,i){e(n,o,i)});return xc=r,xc}var wc,lg;function Ab(){if(lg)return wc;lg=1;function e(t,r){return t<r}return wc=e,wc}var Cc,dg;function fC(){if(dg)return Cc;dg=1;var e=rl(),t=Ab(),r=ot();function n(o){return o&&o.length?e(o,r,t):void 0}return Cc=n,Cc}var _c,fg;function hC(){if(fg)return _c;fg=1;var e=rl(),t=Nr(),r=Ab();function n(o,i){return o&&o.length?e(o,t(i,2),r):void 0}return _c=n,_c}var Sc,hg;function pC(){if(hg)return Sc;hg=1;var e=Sr(),t=function(){return e.Date.now()};return Sc=t,Sc}var Ec,pg;function gC(){if(pg)return Ec;pg=1;var e=An(),t=$n(),r=Tn(),n=vr(),o=tn();function i(a,s,u,c){if(!n(a))return a;s=t(s,a);for(var l=-1,d=s.length,f=d-1,p=a;p!=null&&++l<d;){var m=o(s[l]),y=u;if(m==="__proto__"||m==="constructor"||m==="prototype")return a;if(l!=f){var b=p[m];y=c?c(b,m,p):void 0,y===void 0&&(y=n(b)?b:r(s[l+1])?[]:{})}e(p,m,y),p=p[m]}return a}return Ec=i,Ec}var jc,gg;function yC(){if(gg)return jc;gg=1;var e=Ln(),t=gC(),r=$n();function n(o,i,a){for(var s=-1,u=i.length,c={};++s<u;){var l=i[s],d=e(o,l);a(d,l)&&t(c,r(l,o),d)}return c}return jc=n,jc}var Rc,yg;function mC(){if(yg)return Rc;yg=1;var e=yC(),t=cb();function r(n,o){return e(n,o,function(i,a){return t(n,a)})}return Rc=r,Rc}var kc,mg;function bC(){if(mg)return kc;mg=1;var e=Rb(),t=yb(),r=mb();function n(o){return r(t(o,void 0,e),o+"")}return kc=n,kc}var Pc,bg;function vC(){if(bg)return Pc;bg=1;var e=mC(),t=bC(),r=t(function(n,o){return n==null?{}:e(n,o)});return Pc=r,Pc}var Ac,vg;function xC(){if(vg)return Ac;vg=1;var e=Math.ceil,t=Math.max;function r(n,o,i,a){for(var s=-1,u=t(e((o-n)/(i||1)),0),c=Array(u);u--;)c[a?u:++s]=n,n+=i;return c}return Ac=r,Ac}var Tc,xg;function wC(){if(xg)return Tc;xg=1;var e=xC(),t=Bn(),r=jb();function n(o){return function(i,a,s){return s&&typeof s!="number"&&t(i,a,s)&&(a=s=void 0),i=r(i),a===void 0?(a=i,i=0):a=r(a),s=s===void 0?i<a?1:-1:r(s),e(i,a,s,o)}}return Tc=n,Tc}var Oc,wg;function CC(){if(wg)return Oc;wg=1;var e=wC(),t=e();return Oc=t,Oc}var Ic,Cg;function _C(){if(Cg)return Ic;Cg=1;function e(t,r){var n=t.length;for(t.sort(r);n--;)t[n]=t[n].value;return t}return Ic=e,Ic}var Mc,_g;function SC(){if(_g)return Mc;_g=1;var e=xt();function t(r,n){if(r!==n){var o=r!==void 0,i=r===null,a=r===r,s=e(r),u=n!==void 0,c=n===null,l=n===n,d=e(n);if(!c&&!d&&!s&&r>n||s&&u&&l&&!c&&!d||i&&u&&l||!o&&l||!a)return 1;if(!i&&!s&&!d&&r<n||d&&o&&a&&!i&&!s||c&&o&&a||!u&&a||!l)return-1}return 0}return Mc=t,Mc}var qc,Sg;function EC(){if(Sg)return qc;Sg=1;var e=SC();function t(r,n,o){for(var i=-1,a=r.criteria,s=n.criteria,u=a.length,c=o.length;++i<u;){var l=e(a[i],s[i]);if(l){if(i>=c)return l;var d=o[i];return l*(d=="desc"?-1:1)}}return r.index-n.index}return qc=t,qc}var Nc,Eg;function jC(){if(Eg)return Nc;Eg=1;var e=Nn(),t=Ln(),r=Nr(),n=hb(),o=_C(),i=On(),a=EC(),s=ot(),u=Ue();function c(l,d,f){d.length?d=e(d,function(y){return u(y)?function(b){return t(b,y.length===1?y[0]:y)}:y}):d=[s];var p=-1;d=e(d,i(r));var m=n(l,function(y,b,v){var g=e(d,function(w){return w(y)});return{criteria:g,index:++p,value:y}});return o(m,function(y,b){return a(y,b,f)})}return Nc=c,Nc}var $c,jg;function RC(){if(jg)return $c;jg=1;var e=Qu(),t=jC(),r=Fn(),n=Bn(),o=r(function(i,a){if(i==null)return[];var s=a.length;return s>1&&n(i,a[0],a[1])?a=[]:s>2&&n(a[0],a[1],a[2])&&(a=[a[0]]),t(i,e(a,1),[])});return $c=o,$c}var Lc,Rg;function kC(){if(Rg)return Lc;Rg=1;var e=ab(),t=0;function r(n){var o=++t;return e(n)+o}return Lc=r,Lc}var Fc,kg;function PC(){if(kg)return Fc;kg=1;function e(t,r,n){for(var o=-1,i=t.length,a=r.length,s={};++o<i;){var u=o<a?r[o]:void 0;n(s,t[o],u)}return s}return Fc=e,Fc}var Bc,Pg;function AC(){if(Pg)return Bc;Pg=1;var e=An(),t=PC();function r(n,o){return t(n||[],o||[],e)}return Bc=r,Bc}var Dc,Ag;function De(){if(Ag)return Dc;Ag=1;var e;if(typeof Lu=="function")try{e={cloneDeep:U1(),constant:Ku(),defaults:H1(),each:Qm(),filter:lb(),find:eC(),flatten:Rb(),forEach:Xm(),forIn:rC(),has:db(),isUndefined:fb(),last:tC(),map:pb(),mapValues:nC(),max:iC(),merge:dC(),min:fC(),minBy:hC(),now:pC(),pick:vC(),range:CC(),reduce:gb(),sortBy:RC(),uniqueId:kC(),values:xb(),zipObject:AC()}}catch{}return e||(e=window._),Dc=e,Dc}var zc,Tg;function TC(){if(Tg)return zc;Tg=1,zc=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 t(o),o},e.prototype.enqueue=function(n){var o=this._sentinel;n._prev&&n._next&&t(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,r)),i=i._prev;return"["+n.join(", ")+"]"};function t(n){n._prev._next=n._next,n._next._prev=n._prev,delete n._next,delete n._prev}function r(n,o){if(n!=="_next"&&n!=="_prev")return o}return zc}var Vc,Og;function OC(){if(Og)return Vc;Og=1;var e=De(),t=_r().Graph,r=TC();Vc=o;var n=e.constant(1);function o(c,l){if(c.nodeCount()<=1)return[];var d=s(c,l||n),f=i(d.graph,d.buckets,d.zeroIdx);return e.flatten(e.map(f,function(p){return c.outEdges(p.v,p.w)}),!0)}function i(c,l,d){for(var f=[],p=l[l.length-1],m=l[0],y;c.nodeCount();){for(;y=m.dequeue();)a(c,l,d,y);for(;y=p.dequeue();)a(c,l,d,y);if(c.nodeCount()){for(var b=l.length-2;b>0;--b)if(y=l[b].dequeue(),y){f=f.concat(a(c,l,d,y,!0));break}}}return f}function a(c,l,d,f,p){var m=p?[]:void 0;return e.forEach(c.inEdges(f.v),function(y){var b=c.edge(y),v=c.node(y.v);p&&m.push({v:y.v,w:y.w}),v.out-=b,u(l,d,v)}),e.forEach(c.outEdges(f.v),function(y){var b=c.edge(y),v=y.w,g=c.node(v);g.in-=b,u(l,d,g)}),c.removeNode(f.v),m}function s(c,l){var d=new t,f=0,p=0;e.forEach(c.nodes(),function(b){d.setNode(b,{v:b,in:0,out:0})}),e.forEach(c.edges(),function(b){var v=d.edge(b.v,b.w)||0,g=l(b),w=v+g;d.setEdge(b.v,b.w,w),p=Math.max(p,d.node(b.v).out+=g),f=Math.max(f,d.node(b.w).in+=g)});var m=e.range(p+f+3).map(function(){return new r}),y=f+1;return e.forEach(d.nodes(),function(b){u(m,y,d.node(b))}),{graph:d,buckets:m,zeroIdx:y}}function u(c,l,d){d.out?d.in?c[d.out-d.in+l].enqueue(d):c[c.length-1].enqueue(d):c[0].enqueue(d)}return Vc}var Wc,Ig;function IC(){if(Ig)return Wc;Ig=1;var e=De(),t=OC();Wc={run:r,undo:o};function r(i){var a=i.graph().acyclicer==="greedy"?t(i,s(i)):n(i);e.forEach(a,function(u){var c=i.edge(u);i.removeEdge(u),c.forwardName=u.name,c.reversed=!0,i.setEdge(u.w,u.v,c,e.uniqueId("rev"))});function s(u){return function(c){return u.edge(c).weight}}}function n(i){var a=[],s={},u={};function c(l){e.has(u,l)||(u[l]=!0,s[l]=!0,e.forEach(i.outEdges(l),function(d){e.has(s,d.w)?a.push(d):c(d.w)}),delete s[l])}return e.forEach(i.nodes(),c),a}function o(i){e.forEach(i.edges(),function(a){var s=i.edge(a);if(s.reversed){i.removeEdge(a);var u=s.forwardName;delete s.reversed,delete s.forwardName,i.setEdge(a.w,a.v,s,u)}})}return Wc}var Gc,Mg;function dr(){if(Mg)return Gc;Mg=1;var e=De(),t=_r().Graph;Gc={addDummyNode:r,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:a,intersectRect:s,buildLayerMatrix:u,normalizeRanks:c,removeEmptyRanks:l,addBorderNode:d,maxRank:f,partition:p,time:m,notime:y};function r(b,v,g,w){var x;do x=e.uniqueId(w);while(b.hasNode(x));return g.dummy=v,b.setNode(x,g),x}function n(b){var v=new t().setGraph(b.graph());return e.forEach(b.nodes(),function(g){v.setNode(g,b.node(g))}),e.forEach(b.edges(),function(g){var w=v.edge(g.v,g.w)||{weight:0,minlen:1},x=b.edge(g);v.setEdge(g.v,g.w,{weight:w.weight+x.weight,minlen:Math.max(w.minlen,x.minlen)})}),v}function o(b){var v=new t({multigraph:b.isMultigraph()}).setGraph(b.graph());return e.forEach(b.nodes(),function(g){b.children(g).length||v.setNode(g,b.node(g))}),e.forEach(b.edges(),function(g){v.setEdge(g,b.edge(g))}),v}function i(b){var v=e.map(b.nodes(),function(g){var w={};return e.forEach(b.outEdges(g),function(x){w[x.w]=(w[x.w]||0)+b.edge(x).weight}),w});return e.zipObject(b.nodes(),v)}function a(b){var v=e.map(b.nodes(),function(g){var w={};return e.forEach(b.inEdges(g),function(x){w[x.v]=(w[x.v]||0)+b.edge(x).weight}),w});return e.zipObject(b.nodes(),v)}function s(b,v){var g=b.x,w=b.y,x=v.x-g,_=v.y-w,C=b.width/2,S=b.height/2;if(!x&&!_)throw new Error("Not possible to find intersection inside of the rectangle");var T,k;return Math.abs(_)*C>Math.abs(x)*S?(_<0&&(S=-S),T=S*x/_,k=S):(x<0&&(C=-C),T=C,k=C*_/x),{x:g+T,y:w+k}}function u(b){var v=e.map(e.range(f(b)+1),function(){return[]});return e.forEach(b.nodes(),function(g){var w=b.node(g),x=w.rank;e.isUndefined(x)||(v[x][w.order]=g)}),v}function c(b){var v=e.min(e.map(b.nodes(),function(g){return b.node(g).rank}));e.forEach(b.nodes(),function(g){var w=b.node(g);e.has(w,"rank")&&(w.rank-=v)})}function l(b){var v=e.min(e.map(b.nodes(),function(_){return b.node(_).rank})),g=[];e.forEach(b.nodes(),function(_){var C=b.node(_).rank-v;g[C]||(g[C]=[]),g[C].push(_)});var w=0,x=b.graph().nodeRankFactor;e.forEach(g,function(_,C){e.isUndefined(_)&&C%x!==0?--w:w&&e.forEach(_,function(S){b.node(S).rank+=w})})}function d(b,v,g,w){var x={width:0,height:0};return arguments.length>=4&&(x.rank=g,x.order=w),r(b,"border",x,v)}function f(b){return e.max(e.map(b.nodes(),function(v){var g=b.node(v).rank;if(!e.isUndefined(g))return g}))}function p(b,v){var g={lhs:[],rhs:[]};return e.forEach(b,function(w){v(w)?g.lhs.push(w):g.rhs.push(w)}),g}function m(b,v){var g=e.now();try{return v()}finally{console.log(b+" time: "+(e.now()-g)+"ms")}}function y(b,v){return v()}return Gc}var Uc,qg;function MC(){if(qg)return Uc;qg=1;var e=De(),t=dr();Uc={run:r,undo:o};function r(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(a){n(i,a)})}function n(i,a){var s=a.v,u=i.node(s).rank,c=a.w,l=i.node(c).rank,d=a.name,f=i.edge(a),p=f.labelRank;if(l!==u+1){i.removeEdge(a);var m,y,b;for(b=0,++u;u<l;++b,++u)f.points=[],y={width:0,height:0,edgeLabel:f,edgeObj:a,rank:u},m=t.addDummyNode(i,"edge",y,"_d"),u===p&&(y.width=f.width,y.height=f.height,y.dummy="edge-label",y.labelpos=f.labelpos),i.setEdge(s,m,{weight:f.weight},d),b===0&&i.graph().dummyChains.push(m),s=m;i.setEdge(s,c,{weight:f.weight},d)}}function o(i){e.forEach(i.graph().dummyChains,function(a){var s=i.node(a),u=s.edgeLabel,c;for(i.setEdge(s.edgeObj,u);s.dummy;)c=i.successors(a)[0],i.removeNode(a),u.points.push({x:s.x,y:s.y}),s.dummy==="edge-label"&&(u.x=s.x,u.y=s.y,u.width=s.width,u.height=s.height),a=c,s=i.node(a)})}return Uc}var Hc,Ng;function gn(){if(Ng)return Hc;Ng=1;var e=De();Hc={longestPath:t,slack:r};function t(n){var o={};function i(a){var s=n.node(a);if(e.has(o,a))return s.rank;o[a]=!0;var u=e.min(e.map(n.outEdges(a),function(c){return i(c.w)-n.edge(c).minlen}));return(u===Number.POSITIVE_INFINITY||u===void 0||u===null)&&(u=0),s.rank=u}e.forEach(n.sources(),i)}function r(n,o){return n.node(o.w).rank-n.node(o.v).rank-n.edge(o).minlen}return Hc}var Kc,$g;function Tb(){if($g)return Kc;$g=1;var e=De(),t=_r().Graph,r=gn().slack;Kc=n;function n(s){var u=new t({directed:!1}),c=s.nodes()[0],l=s.nodeCount();u.setNode(c,{});for(var d,f;o(u,s)<l;)d=i(u,s),f=u.hasNode(d.v)?r(s,d):-r(s,d),a(u,s,f);return u}function o(s,u){function c(l){e.forEach(u.nodeEdges(l),function(d){var f=d.v,p=l===f?d.w:f;!s.hasNode(p)&&!r(u,d)&&(s.setNode(p,{}),s.setEdge(l,p,{}),c(p))})}return e.forEach(s.nodes(),c),s.nodeCount()}function i(s,u){return e.minBy(u.edges(),function(c){if(s.hasNode(c.v)!==s.hasNode(c.w))return r(u,c)})}function a(s,u,c){e.forEach(s.nodes(),function(l){u.node(l).rank+=c})}return Kc}var Zc,Lg;function qC(){if(Lg)return Zc;Lg=1;var e=De(),t=Tb(),r=gn().slack,n=gn().longestPath,o=_r().alg.preorder,i=_r().alg.postorder,a=dr().simplify;Zc=s,s.initLowLimValues=d,s.initCutValues=u,s.calcCutValue=l,s.leaveEdge=p,s.enterEdge=m,s.exchangeEdges=y;function s(w){w=a(w),n(w);var x=t(w);d(x),u(x,w);for(var _,C;_=p(x);)C=m(x,w,_),y(x,w,_,C)}function u(w,x){var _=i(w,w.nodes());_=_.slice(0,_.length-1),e.forEach(_,function(C){c(w,x,C)})}function c(w,x,_){var C=w.node(_),S=C.parent;w.edge(_,S).cutvalue=l(w,x,_)}function l(w,x,_){var C=w.node(_),S=C.parent,T=!0,k=x.edge(_,S),E=0;return k||(T=!1,k=x.edge(S,_)),E=k.weight,e.forEach(x.nodeEdges(_),function(P){var R=P.v===_,I=R?P.w:P.v;if(I!==S){var O=R===T,M=x.edge(P).weight;if(E+=O?M:-M,v(w,_,I)){var q=w.edge(_,I).cutvalue;E+=O?-q:q}}}),E}function d(w,x){arguments.length<2&&(x=w.nodes()[0]),f(w,{},1,x)}function f(w,x,_,C,S){var T=_,k=w.node(C);return x[C]=!0,e.forEach(w.neighbors(C),function(E){e.has(x,E)||(_=f(w,x,_,E,C))}),k.low=T,k.lim=_++,S?k.parent=S:delete k.parent,_}function p(w){return e.find(w.edges(),function(x){return w.edge(x).cutvalue<0})}function m(w,x,_){var C=_.v,S=_.w;x.hasEdge(C,S)||(C=_.w,S=_.v);var T=w.node(C),k=w.node(S),E=T,P=!1;T.lim>k.lim&&(E=k,P=!0);var R=e.filter(x.edges(),function(I){return P===g(w,w.node(I.v),E)&&P!==g(w,w.node(I.w),E)});return e.minBy(R,function(I){return r(x,I)})}function y(w,x,_,C){var S=_.v,T=_.w;w.removeEdge(S,T),w.setEdge(C.v,C.w,{}),d(w),u(w,x),b(w,x)}function b(w,x){var _=e.find(w.nodes(),function(S){return!x.node(S).parent}),C=o(w,_);C=C.slice(1),e.forEach(C,function(S){var T=w.node(S).parent,k=x.edge(S,T),E=!1;k||(k=x.edge(T,S),E=!0),x.node(S).rank=x.node(T).rank+(E?k.minlen:-k.minlen)})}function v(w,x,_){return w.hasEdge(x,_)}function g(w,x,_){return _.low<=x.lim&&x.lim<=_.lim}return Zc}var Jc,Fg;function NC(){if(Fg)return Jc;Fg=1;var e=gn(),t=e.longestPath,r=Tb(),n=qC();Jc=o;function o(u){switch(u.graph().ranker){case"network-simplex":s(u);break;case"tight-tree":a(u);break;case"longest-path":i(u);break;default:s(u)}}var i=t;function a(u){t(u),r(u)}function s(u){n(u)}return Jc}var Yc,Bg;function $C(){if(Bg)return Yc;Bg=1;var e=De();Yc=t;function t(o){var i=n(o);e.forEach(o.graph().dummyChains,function(a){for(var s=o.node(a),u=s.edgeObj,c=r(o,i,u.v,u.w),l=c.path,d=c.lca,f=0,p=l[f],m=!0;a!==u.w;){if(s=o.node(a),m){for(;(p=l[f])!==d&&o.node(p).maxRank<s.rank;)f++;p===d&&(m=!1)}if(!m){for(;f<l.length-1&&o.node(p=l[f+1]).minRank<=s.rank;)f++;p=l[f]}o.setParent(a,p),a=o.successors(a)[0]}})}function r(o,i,a,s){var u=[],c=[],l=Math.min(i[a].low,i[s].low),d=Math.max(i[a].lim,i[s].lim),f,p;f=a;do f=o.parent(f),u.push(f);while(f&&(i[f].low>l||d>i[f].lim));for(p=f,f=s;(f=o.parent(f))!==p;)c.push(f);return{path:u.concat(c.reverse()),lca:p}}function n(o){var i={},a=0;function s(u){var c=a;e.forEach(o.children(u),s),i[u]={low:c,lim:a++}}return e.forEach(o.children(),s),i}return Yc}var Xc,Dg;function LC(){if(Dg)return Xc;Dg=1;var e=De(),t=dr();Xc={run:r,cleanup:a};function r(s){var u=t.addDummyNode(s,"root",{},"_root"),c=o(s),l=e.max(e.values(c))-1,d=2*l+1;s.graph().nestingRoot=u,e.forEach(s.edges(),function(p){s.edge(p).minlen*=d});var f=i(s)+1;e.forEach(s.children(),function(p){n(s,u,d,f,l,c,p)}),s.graph().nodeRankFactor=d}function n(s,u,c,l,d,f,p){var m=s.children(p);if(!m.length){p!==u&&s.setEdge(u,p,{weight:0,minlen:c});return}var y=t.addBorderNode(s,"_bt"),b=t.addBorderNode(s,"_bb"),v=s.node(p);s.setParent(y,p),v.borderTop=y,s.setParent(b,p),v.borderBottom=b,e.forEach(m,function(g){n(s,u,c,l,d,f,g);var w=s.node(g),x=w.borderTop?w.borderTop:g,_=w.borderBottom?w.borderBottom:g,C=w.borderTop?l:2*l,S=x!==_?1:d-f[p]+1;s.setEdge(y,x,{weight:C,minlen:S,nestingEdge:!0}),s.setEdge(_,b,{weight:C,minlen:S,nestingEdge:!0})}),s.parent(p)||s.setEdge(u,y,{weight:0,minlen:d+f[p]})}function o(s){var u={};function c(l,d){var f=s.children(l);f&&f.length&&e.forEach(f,function(p){c(p,d+1)}),u[l]=d}return e.forEach(s.children(),function(l){c(l,1)}),u}function i(s){return e.reduce(s.edges(),function(u,c){return u+s.edge(c).weight},0)}function a(s){var u=s.graph();s.removeNode(u.nestingRoot),delete u.nestingRoot,e.forEach(s.edges(),function(c){var l=s.edge(c);l.nestingEdge&&s.removeEdge(c)})}return Xc}var Qc,zg;function FC(){if(zg)return Qc;zg=1;var e=De(),t=dr();Qc=r;function r(o){function i(a){var s=o.children(a),u=o.node(a);if(s.length&&e.forEach(s,i),e.has(u,"minRank")){u.borderLeft=[],u.borderRight=[];for(var c=u.minRank,l=u.maxRank+1;c<l;++c)n(o,"borderLeft","_bl",a,u,c),n(o,"borderRight","_br",a,u,c)}}e.forEach(o.children(),i)}function n(o,i,a,s,u,c){var l={width:0,height:0,rank:c,borderType:i},d=u[i][c-1],f=t.addDummyNode(o,"border",l,a);u[i][c]=f,o.setParent(f,s),d&&o.setEdge(d,f,{weight:1})}return Qc}var eu,Vg;function BC(){if(Vg)return eu;Vg=1;var e=De();eu={adjust:t,undo:r};function t(c){var l=c.graph().rankdir.toLowerCase();(l==="lr"||l==="rl")&&n(c)}function r(c){var l=c.graph().rankdir.toLowerCase();(l==="bt"||l==="rl")&&i(c),(l==="lr"||l==="rl")&&(s(c),n(c))}function n(c){e.forEach(c.nodes(),function(l){o(c.node(l))}),e.forEach(c.edges(),function(l){o(c.edge(l))})}function o(c){var l=c.width;c.width=c.height,c.height=l}function i(c){e.forEach(c.nodes(),function(l){a(c.node(l))}),e.forEach(c.edges(),function(l){var d=c.edge(l);e.forEach(d.points,a),e.has(d,"y")&&a(d)})}function a(c){c.y=-c.y}function s(c){e.forEach(c.nodes(),function(l){u(c.node(l))}),e.forEach(c.edges(),function(l){var d=c.edge(l);e.forEach(d.points,u),e.has(d,"x")&&u(d)})}function u(c){var l=c.x;c.x=c.y,c.y=l}return eu}var ru,Wg;function DC(){if(Wg)return ru;Wg=1;var e=De();ru=t;function t(r){var n={},o=e.filter(r.nodes(),function(c){return!r.children(c).length}),i=e.max(e.map(o,function(c){return r.node(c).rank})),a=e.map(e.range(i+1),function(){return[]});function s(c){if(!e.has(n,c)){n[c]=!0;var l=r.node(c);a[l.rank].push(c),e.forEach(r.successors(c),s)}}var u=e.sortBy(o,function(c){return r.node(c).rank});return e.forEach(u,s),a}return ru}var tu,Gg;function zC(){if(Gg)return tu;Gg=1;var e=De();tu=t;function t(n,o){for(var i=0,a=1;a<o.length;++a)i+=r(n,o[a-1],o[a]);return i}function r(n,o,i){for(var a=e.zipObject(i,e.map(i,function(f,p){return p})),s=e.flatten(e.map(o,function(f){return e.sortBy(e.map(n.outEdges(f),function(p){return{pos:a[p.w],weight:n.edge(p).weight}}),"pos")}),!0),u=1;u<i.length;)u<<=1;var c=2*u-1;u-=1;var l=e.map(new Array(c),function(){return 0}),d=0;return e.forEach(s.forEach(function(f){var p=f.pos+u;l[p]+=f.weight;for(var m=0;p>0;)p%2&&(m+=l[p+1]),p=p-1>>1,l[p]+=f.weight;d+=f.weight*m})),d}return tu}var nu,Ug;function VC(){if(Ug)return nu;Ug=1;var e=De();nu=t;function t(r,n){return e.map(n,function(o){var i=r.inEdges(o);if(i.length){var a=e.reduce(i,function(s,u){var c=r.edge(u),l=r.node(u.v);return{sum:s.sum+c.weight*l.order,weight:s.weight+c.weight}},{sum:0,weight:0});return{v:o,barycenter:a.sum/a.weight,weight:a.weight}}else return{v:o}})}return nu}var ou,Hg;function WC(){if(Hg)return ou;Hg=1;var e=De();ou=t;function t(o,i){var a={};e.forEach(o,function(u,c){var l=a[u.v]={indegree:0,in:[],out:[],vs:[u.v],i:c};e.isUndefined(u.barycenter)||(l.barycenter=u.barycenter,l.weight=u.weight)}),e.forEach(i.edges(),function(u){var c=a[u.v],l=a[u.w];!e.isUndefined(c)&&!e.isUndefined(l)&&(l.indegree++,c.out.push(a[u.w]))});var s=e.filter(a,function(u){return!u.indegree});return r(s)}function r(o){var i=[];function a(c){return function(l){l.merged||(e.isUndefined(l.barycenter)||e.isUndefined(c.barycenter)||l.barycenter>=c.barycenter)&&n(c,l)}}function s(c){return function(l){l.in.push(c),--l.indegree===0&&o.push(l)}}for(;o.length;){var u=o.pop();i.push(u),e.forEach(u.in.reverse(),a(u)),e.forEach(u.out,s(u))}return e.map(e.filter(i,function(c){return!c.merged}),function(c){return e.pick(c,["vs","i","barycenter","weight"])})}function n(o,i){var a=0,s=0;o.weight&&(a+=o.barycenter*o.weight,s+=o.weight),i.weight&&(a+=i.barycenter*i.weight,s+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=a/s,o.weight=s,o.i=Math.min(i.i,o.i),i.merged=!0}return ou}var iu,Kg;function GC(){if(Kg)return iu;Kg=1;var e=De(),t=dr();iu=r;function r(i,a){var s=t.partition(i,function(y){return e.has(y,"barycenter")}),u=s.lhs,c=e.sortBy(s.rhs,function(y){return-y.i}),l=[],d=0,f=0,p=0;u.sort(o(!!a)),p=n(l,c,p),e.forEach(u,function(y){p+=y.vs.length,l.push(y.vs),d+=y.barycenter*y.weight,f+=y.weight,p=n(l,c,p)});var m={vs:e.flatten(l,!0)};return f&&(m.barycenter=d/f,m.weight=f),m}function n(i,a,s){for(var u;a.length&&(u=e.last(a)).i<=s;)a.pop(),i.push(u.vs),s++;return s}function o(i){return function(a,s){return a.barycenter<s.barycenter?-1:a.barycenter>s.barycenter?1:i?s.i-a.i:a.i-s.i}}return iu}var au,Zg;function UC(){if(Zg)return au;Zg=1;var e=De(),t=VC(),r=WC(),n=GC();au=o;function o(s,u,c,l){var d=s.children(u),f=s.node(u),p=f?f.borderLeft:void 0,m=f?f.borderRight:void 0,y={};p&&(d=e.filter(d,function(_){return _!==p&&_!==m}));var b=t(s,d);e.forEach(b,function(_){if(s.children(_.v).length){var C=o(s,_.v,c,l);y[_.v]=C,e.has(C,"barycenter")&&a(_,C)}});var v=r(b,c);i(v,y);var g=n(v,l);if(p&&(g.vs=e.flatten([p,g.vs,m],!0),s.predecessors(p).length)){var w=s.node(s.predecessors(p)[0]),x=s.node(s.predecessors(m)[0]);e.has(g,"barycenter")||(g.barycenter=0,g.weight=0),g.barycenter=(g.barycenter*g.weight+w.order+x.order)/(g.weight+2),g.weight+=2}return g}function i(s,u){e.forEach(s,function(c){c.vs=e.flatten(c.vs.map(function(l){return u[l]?u[l].vs:l}),!0)})}function a(s,u){e.isUndefined(s.barycenter)?(s.barycenter=u.barycenter,s.weight=u.weight):(s.barycenter=(s.barycenter*s.weight+u.barycenter*u.weight)/(s.weight+u.weight),s.weight+=u.weight)}return au}var su,Jg;function HC(){if(Jg)return su;Jg=1;var e=De(),t=_r().Graph;su=r;function r(o,i,a){var s=n(o),u=new t({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(function(c){return o.node(c)});return e.forEach(o.nodes(),function(c){var l=o.node(c),d=o.parent(c);(l.rank===i||l.minRank<=i&&i<=l.maxRank)&&(u.setNode(c),u.setParent(c,d||s),e.forEach(o[a](c),function(f){var p=f.v===c?f.w:f.v,m=u.edge(p,c),y=e.isUndefined(m)?0:m.weight;u.setEdge(p,c,{weight:o.edge(f).weight+y})}),e.has(l,"minRank")&&u.setNode(c,{borderLeft:l.borderLeft[i],borderRight:l.borderRight[i]}))}),u}function n(o){for(var i;o.hasNode(i=e.uniqueId("_root")););return i}return su}var cu,Yg;function KC(){if(Yg)return cu;Yg=1;var e=De();cu=t;function t(r,n,o){var i={},a;e.forEach(o,function(s){for(var u=r.parent(s),c,l;u;){if(c=r.parent(u),c?(l=i[c],i[c]=u):(l=a,a=u),l&&l!==u){n.setEdge(l,u);return}u=c}})}return cu}var uu,Xg;function ZC(){if(Xg)return uu;Xg=1;var e=De(),t=DC(),r=zC(),n=UC(),o=HC(),i=KC(),a=_r().Graph,s=dr();uu=u;function u(f){var p=s.maxRank(f),m=c(f,e.range(1,p+1),"inEdges"),y=c(f,e.range(p-1,-1,-1),"outEdges"),b=t(f);d(f,b);for(var v=Number.POSITIVE_INFINITY,g,w=0,x=0;x<4;++w,++x){l(w%2?m:y,w%4>=2),b=s.buildLayerMatrix(f);var _=r(f,b);_<v&&(x=0,g=e.cloneDeep(b),v=_)}d(f,g)}function c(f,p,m){return e.map(p,function(y){return o(f,y,m)})}function l(f,p){var m=new a;e.forEach(f,function(y){var b=y.graph().root,v=n(y,b,m,p);e.forEach(v.vs,function(g,w){y.node(g).order=w}),i(y,m,v.vs)})}function d(f,p){e.forEach(p,function(m){e.forEach(m,function(y,b){f.node(y).order=b})})}return uu}var lu,Qg;function JC(){if(Qg)return lu;Qg=1;var e=De(),t=_r().Graph,r=dr();lu={positionX:m,findType1Conflicts:n,findType2Conflicts:o,addConflict:a,hasConflict:s,verticalAlignment:u,horizontalCompaction:c,alignCoordinates:f,findSmallestWidthAlignment:d,balance:p};function n(v,g){var w={};function x(_,C){var S=0,T=0,k=_.length,E=e.last(C);return e.forEach(C,function(P,R){var I=i(v,P),O=I?v.node(I).order:k;(I||P===E)&&(e.forEach(C.slice(T,R+1),function(M){e.forEach(v.predecessors(M),function(q){var K=v.node(q),V=K.order;(V<S||O<V)&&!(K.dummy&&v.node(M).dummy)&&a(w,q,M)})}),T=R+1,S=O)}),C}return e.reduce(g,x),w}function o(v,g){var w={};function x(C,S,T,k,E){var P;e.forEach(e.range(S,T),function(R){P=C[R],v.node(P).dummy&&e.forEach(v.predecessors(P),function(I){var O=v.node(I);O.dummy&&(O.order<k||O.order>E)&&a(w,I,P)})})}function _(C,S){var T=-1,k,E=0;return e.forEach(S,function(P,R){if(v.node(P).dummy==="border"){var I=v.predecessors(P);I.length&&(k=v.node(I[0]).order,x(S,E,R,T,k),E=R,T=k)}x(S,E,S.length,k,C.length)}),S}return e.reduce(g,_),w}function i(v,g){if(v.node(g).dummy)return e.find(v.predecessors(g),function(w){return v.node(w).dummy})}function a(v,g,w){if(g>w){var x=g;g=w,w=x}var _=v[g];_||(v[g]=_={}),_[w]=!0}function s(v,g,w){if(g>w){var x=g;g=w,w=x}return e.has(v[g],w)}function u(v,g,w,x){var _={},C={},S={};return e.forEach(g,function(T){e.forEach(T,function(k,E){_[k]=k,C[k]=k,S[k]=E})}),e.forEach(g,function(T){var k=-1;e.forEach(T,function(E){var P=x(E);if(P.length){P=e.sortBy(P,function(q){return S[q]});for(var R=(P.length-1)/2,I=Math.floor(R),O=Math.ceil(R);I<=O;++I){var M=P[I];C[E]===E&&k<S[M]&&!s(w,E,M)&&(C[M]=E,C[E]=_[E]=_[M],k=S[M])}}})}),{root:_,align:C}}function c(v,g,w,x,_){var C={},S=l(v,g,w,_),T=_?"borderLeft":"borderRight";function k(R,I){for(var O=S.nodes(),M=O.pop(),q={};M;)q[M]?R(M):(q[M]=!0,O.push(M),O=O.concat(I(M))),M=O.pop()}function E(R){C[R]=S.inEdges(R).reduce(function(I,O){return Math.max(I,C[O.v]+S.edge(O))},0)}function P(R){var I=S.outEdges(R).reduce(function(M,q){return Math.min(M,C[q.w]-S.edge(q))},Number.POSITIVE_INFINITY),O=v.node(R);I!==Number.POSITIVE_INFINITY&&O.borderType!==T&&(C[R]=Math.max(C[R],I))}return k(E,S.predecessors.bind(S)),k(P,S.successors.bind(S)),e.forEach(x,function(R){C[R]=C[w[R]]}),C}function l(v,g,w,x){var _=new t,C=v.graph(),S=y(C.nodesep,C.edgesep,x);return e.forEach(g,function(T){var k;e.forEach(T,function(E){var P=w[E];if(_.setNode(P),k){var R=w[k],I=_.edge(R,P);_.setEdge(R,P,Math.max(S(v,E,k),I||0))}k=E})}),_}function d(v,g){return e.minBy(e.values(g),function(w){var x=Number.NEGATIVE_INFINITY,_=Number.POSITIVE_INFINITY;return e.forIn(w,function(C,S){var T=b(v,S)/2;x=Math.max(C+T,x),_=Math.min(C-T,_)}),x-_})}function f(v,g){var w=e.values(g),x=e.min(w),_=e.max(w);e.forEach(["u","d"],function(C){e.forEach(["l","r"],function(S){var T=C+S,k=v[T],E;if(k!==g){var P=e.values(k);E=S==="l"?x-e.min(P):_-e.max(P),E&&(v[T]=e.mapValues(k,function(R){return R+E}))}})})}function p(v,g){return e.mapValues(v.ul,function(w,x){if(g)return v[g.toLowerCase()][x];var _=e.sortBy(e.map(v,x));return(_[1]+_[2])/2})}function m(v){var g=r.buildLayerMatrix(v),w=e.merge(n(v,g),o(v,g)),x={},_;e.forEach(["u","d"],function(S){_=S==="u"?g:e.values(g).reverse(),e.forEach(["l","r"],function(T){T==="r"&&(_=e.map(_,function(R){return e.values(R).reverse()}));var k=(S==="u"?v.predecessors:v.successors).bind(v),E=u(v,_,w,k),P=c(v,_,E.root,E.align,T==="r");T==="r"&&(P=e.mapValues(P,function(R){return-R})),x[S+T]=P})});var C=d(v,x);return f(x,C),p(x,v.graph().align)}function y(v,g,w){return function(x,_,C){var S=x.node(_),T=x.node(C),k=0,E;if(k+=S.width/2,e.has(S,"labelpos"))switch(S.labelpos.toLowerCase()){case"l":E=-S.width/2;break;case"r":E=S.width/2;break}if(E&&(k+=w?E:-E),E=0,k+=(S.dummy?g:v)/2,k+=(T.dummy?g:v)/2,k+=T.width/2,e.has(T,"labelpos"))switch(T.labelpos.toLowerCase()){case"l":E=T.width/2;break;case"r":E=-T.width/2;break}return E&&(k+=w?E:-E),E=0,k}}function b(v,g){return v.node(g).width}return lu}var du,ey;function YC(){if(ey)return du;ey=1;var e=De(),t=dr(),r=JC().positionX;du=n;function n(i){i=t.asNonCompoundGraph(i),o(i),e.forEach(r(i),function(a,s){i.node(s).x=a})}function o(i){var a=t.buildLayerMatrix(i),s=i.graph().ranksep,u=0;e.forEach(a,function(c){var l=e.max(e.map(c,function(d){return i.node(d).height}));e.forEach(c,function(d){i.node(d).y=u+l/2}),u+=l+s})}return du}var fu,ry;function XC(){if(ry)return fu;ry=1;var e=De(),t=IC(),r=MC(),n=NC(),o=dr().normalizeRanks,i=$C(),a=dr().removeEmptyRanks,s=LC(),u=FC(),c=BC(),l=ZC(),d=YC(),f=dr(),p=_r().Graph;fu=m;function m(N,D){var W=D&&D.debugTiming?f.time:f.notime;W("layout",function(){var z=W(" buildLayoutGraph",function(){return k(N)});W(" runLayout",function(){y(z,W)}),W(" updateInputGraph",function(){b(N,z)})})}function y(N,D){D(" makeSpaceForEdgeLabels",function(){E(N)}),D(" removeSelfEdges",function(){re(N)}),D(" acyclic",function(){t.run(N)}),D(" nestingGraph.run",function(){s.run(N)}),D(" rank",function(){n(f.asNonCompoundGraph(N))}),D(" injectEdgeLabelProxies",function(){P(N)}),D(" removeEmptyRanks",function(){a(N)}),D(" nestingGraph.cleanup",function(){s.cleanup(N)}),D(" normalizeRanks",function(){o(N)}),D(" assignRankMinMax",function(){R(N)}),D(" removeEdgeLabelProxies",function(){I(N)}),D(" normalize.run",function(){r.run(N)}),D(" parentDummyChains",function(){i(N)}),D(" addBorderSegments",function(){u(N)}),D(" order",function(){l(N)}),D(" insertSelfEdges",function(){ce(N)}),D(" adjustCoordinateSystem",function(){c.adjust(N)}),D(" position",function(){d(N)}),D(" positionSelfEdges",function(){he(N)}),D(" removeBorderNodes",function(){V(N)}),D(" normalize.undo",function(){r.undo(N)}),D(" fixupEdgeLabelCoords",function(){q(N)}),D(" undoCoordinateSystem",function(){c.undo(N)}),D(" translateGraph",function(){O(N)}),D(" assignNodeIntersects",function(){M(N)}),D(" reversePoints",function(){K(N)}),D(" acyclic.undo",function(){t.undo(N)})}function b(N,D){e.forEach(N.nodes(),function(W){var z=N.node(W),X=D.node(W);z&&(z.x=X.x,z.y=X.y,D.children(W).length&&(z.width=X.width,z.height=X.height))}),e.forEach(N.edges(),function(W){var z=N.edge(W),X=D.edge(W);z.points=X.points,e.has(X,"x")&&(z.x=X.x,z.y=X.y)}),N.graph().width=D.graph().width,N.graph().height=D.graph().height}var v=["nodesep","edgesep","ranksep","marginx","marginy"],g={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},w=["acyclicer","ranker","rankdir","align"],x=["width","height"],_={width:0,height:0},C=["minlen","weight","width","height","labeloffset"],S={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},T=["labelpos"];function k(N){var D=new p({multigraph:!0,compound:!0}),W=H(N.graph());return D.setGraph(e.merge({},g,me(W,v),e.pick(W,w))),e.forEach(N.nodes(),function(z){var X=H(N.node(z));D.setNode(z,e.defaults(me(X,x),_)),D.setParent(z,N.parent(z))}),e.forEach(N.edges(),function(z){var X=H(N.edge(z));D.setEdge(z,e.merge({},S,me(X,C),e.pick(X,T)))}),D}function E(N){var D=N.graph();D.ranksep/=2,e.forEach(N.edges(),function(W){var z=N.edge(W);z.minlen*=2,z.labelpos.toLowerCase()!=="c"&&(D.rankdir==="TB"||D.rankdir==="BT"?z.width+=z.labeloffset:z.height+=z.labeloffset)})}function P(N){e.forEach(N.edges(),function(D){var W=N.edge(D);if(W.width&&W.height){var z=N.node(D.v),X=N.node(D.w),se={rank:(X.rank-z.rank)/2+z.rank,e:D};f.addDummyNode(N,"edge-proxy",se,"_ep")}})}function R(N){var D=0;e.forEach(N.nodes(),function(W){var z=N.node(W);z.borderTop&&(z.minRank=N.node(z.borderTop).rank,z.maxRank=N.node(z.borderBottom).rank,D=e.max(D,z.maxRank))}),N.graph().maxRank=D}function I(N){e.forEach(N.nodes(),function(D){var W=N.node(D);W.dummy==="edge-proxy"&&(N.edge(W.e).labelRank=W.rank,N.removeNode(D))})}function O(N){var D=Number.POSITIVE_INFINITY,W=0,z=Number.POSITIVE_INFINITY,X=0,se=N.graph(),Q=se.marginx||0,G=se.marginy||0;function J(te){var le=te.x,de=te.y,Re=te.width,ge=te.height;D=Math.min(D,le-Re/2),W=Math.max(W,le+Re/2),z=Math.min(z,de-ge/2),X=Math.max(X,de+ge/2)}e.forEach(N.nodes(),function(te){J(N.node(te))}),e.forEach(N.edges(),function(te){var le=N.edge(te);e.has(le,"x")&&J(le)}),D-=Q,z-=G,e.forEach(N.nodes(),function(te){var le=N.node(te);le.x-=D,le.y-=z}),e.forEach(N.edges(),function(te){var le=N.edge(te);e.forEach(le.points,function(de){de.x-=D,de.y-=z}),e.has(le,"x")&&(le.x-=D),e.has(le,"y")&&(le.y-=z)}),se.width=W-D+Q,se.height=X-z+G}function M(N){e.forEach(N.edges(),function(D){var W=N.edge(D),z=N.node(D.v),X=N.node(D.w),se,Q;W.points?(se=W.points[0],Q=W.points[W.points.length-1]):(W.points=[],se=X,Q=z),W.points.unshift(f.intersectRect(z,se)),W.points.push(f.intersectRect(X,Q))})}function q(N){e.forEach(N.edges(),function(D){var W=N.edge(D);if(e.has(W,"x"))switch((W.labelpos==="l"||W.labelpos==="r")&&(W.width-=W.labeloffset),W.labelpos){case"l":W.x-=W.width/2+W.labeloffset;break;case"r":W.x+=W.width/2+W.labeloffset;break}})}function K(N){e.forEach(N.edges(),function(D){var W=N.edge(D);W.reversed&&W.points.reverse()})}function V(N){e.forEach(N.nodes(),function(D){if(N.children(D).length){var W=N.node(D),z=N.node(W.borderTop),X=N.node(W.borderBottom),se=N.node(e.last(W.borderLeft)),Q=N.node(e.last(W.borderRight));W.width=Math.abs(Q.x-se.x),W.height=Math.abs(X.y-z.y),W.x=se.x+W.width/2,W.y=z.y+W.height/2}}),e.forEach(N.nodes(),function(D){N.node(D).dummy==="border"&&N.removeNode(D)})}function re(N){e.forEach(N.edges(),function(D){if(D.v===D.w){var W=N.node(D.v);W.selfEdges||(W.selfEdges=[]),W.selfEdges.push({e:D,label:N.edge(D)}),N.removeEdge(D)}})}function ce(N){var D=f.buildLayerMatrix(N);e.forEach(D,function(W){var z=0;e.forEach(W,function(X,se){var Q=N.node(X);Q.order=se+z,e.forEach(Q.selfEdges,function(G){f.addDummyNode(N,"selfedge",{width:G.label.width,height:G.label.height,rank:Q.rank,order:se+ ++z,e:G.e,label:G.label},"_se")}),delete Q.selfEdges})})}function he(N){e.forEach(N.nodes(),function(D){var W=N.node(D);if(W.dummy==="selfedge"){var z=N.node(W.e.v),X=z.x+z.width/2,se=z.y,Q=W.x-X,G=z.height/2;N.setEdge(W.e,W.label),N.removeNode(D),W.label.points=[{x:X+2*Q/3,y:se-G},{x:X+5*Q/6,y:se-G},{x:X+Q,y:se},{x:X+5*Q/6,y:se+G},{x:X+2*Q/3,y:se+G}],W.label.x=W.x,W.label.y=W.y}})}function me(N,D){return e.mapValues(e.pick(N,D),Number)}function H(N){var D={};return e.forEach(N,function(W,z){D[z.toLowerCase()]=W}),D}return fu}var hu,ty;function QC(){if(ty)return hu;ty=1;var e=De(),t=dr(),r=_r().Graph;hu={debugOrdering:n};function n(o){var i=t.buildLayerMatrix(o),a=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(s){a.setNode(s,{label:s}),a.setParent(s,"layer"+o.node(s).rank)}),e.forEach(o.edges(),function(s){a.setEdge(s.v,s.w,{},s.name)}),e.forEach(i,function(s,u){var c="layer"+u;a.setNode(c,{rank:"same"}),e.reduce(s,function(l,d){return a.setEdge(l,d,{style:"invis"}),d})}),a}return hu}var pu,ny;function e_(){return ny||(ny=1,pu="0.8.5"),pu}var gu,oy;function r_(){return oy||(oy=1,gu={graphlib:_r(),layout:XC(),debug:QC(),util:{time:dr().time,notime:dr().notime},version:e_()}),gu}var t_=r_();const iy=B0(t_);function n_(e,t,r){var l;const n=new Set(e.map(d=>d.id)),o=new Set;for(const d of e)d.parent&&n.has(d.parent)&&o.add(d.parent);const i=new iy.graphlib.Graph({multigraph:!0,compound:!0}),a=r.compactSpacingScale??(r.spacingFactor>0?r.spacingFactor/1.3:1);i.setGraph({rankdir:r.rankDir,nodesep:r.compact?Math.max(r.nodeSep,24*a):r.nodeSep,edgesep:r.compact?Math.min(r.edgeSep,24*a):r.edgeSep,ranksep:r.compact?Math.min(r.rankSep,80*a):r.rankSep,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({})),i.setDefaultNodeLabel(()=>({}));for(const d of e)i.setNode(d.id,{width:d.width+2,height:d.height+2});for(const d of e)d.parent&&n.has(d.parent)&&i.setParent(d.id,d.parent);for(const d of t){if(!n.has(d.source)||!n.has(d.target)||o.has(d.source)||o.has(d.target))continue;const f=Am(d.label,d.icon??((l=d.data)==null?void 0:l.icon),r.edgeLabelFontSize),p=r.rankDir==="LR"||r.rankDir==="RL",m=(f.width?f.width+2*Pm:0)+(d.connectorClearance??0);i.setEdge(d.source,d.target,{minlen:1,weight:1,...m?{width:p?m:Math.max(1,f.height),height:p?Math.max(1,f.height):m,labelpos:"c"}:{}},d.id)}iy.layout(i);const s=new Map;for(const d of e){if(o.has(d.id))continue;const f=i.node(d.id);f&&Number.isFinite(f.x)&&Number.isFinite(f.y)&&s.set(d.id,{x:f.x,y:f.y})}const u=r.compact?1:r.spacingFactor;if(u&&u!==1&&s.size){let d=1/0,f=1/0,p=-1/0,m=-1/0;s.forEach(v=>{d=Math.min(d,v.x),f=Math.min(f,v.y),p=Math.max(p,v.x),m=Math.max(m,v.y)});const y=(d+p)/2,b=(f+m)/2;s.forEach((v,g)=>s.set(g,{x:y+(v.x-y)*u,y:b+(v.y-b)*u}))}const c=r.nodeAlignment??"center";if(c!=="center"){const d=r.rankDir==="LR"||r.rankDir==="RL",f=d?"x":"y",p=d?"width":"height",m=r.rankDir==="RL"||r.rankDir==="BT"?-1:1,y=c==="leading"?-m:m,b=new Map;for(const v of e){const g=s.get(v.id);if(!g)continue;const w=g[f];b.set(w,Math.max(b.get(w)??0,v[p]))}for(const v of e){const g=s.get(v.id);if(!g)continue;const w=g[f],x=(b.get(w)-v[p])/2;s.set(v.id,{...g,[f]:w+y*x})}}return s}function o_(e,t,r,n,o){const i=new Map,a=new Map(e.map(l=>[l.id,l]));for(const l of e){if(!l.parent||!a.has(l.parent))continue;const d=i.get(l.parent);d?d.push(l.id):i.set(l.parent,[l.id])}const s=(l,d=new Set)=>{var p;const f=(p=a.get(l))==null?void 0:p.parent;return!f||!a.has(f)||d.has(l)?0:(d.add(l),1+s(f,d))},u=[...i.keys()].sort((l,d)=>s(d)-s(l)),c=new Map;for(const l of u){let d=null;for(const m of i.get(l)||[]){let y=c.get(m);if(!y){const b=t.get(m);if(!b)continue;const v=r.get(m)||{w:60,h:60};y={x1:b.x-v.w/2,y1:b.y-v.h/2,x2:b.x+v.w/2,y2:b.y+v.h/2}}d=d?{x1:Math.min(d.x1,y.x1),y1:Math.min(d.y1,y.y1),x2:Math.max(d.x2,y.x2),y2:Math.max(d.y2,y.y2)}:{...y}}if(!d)continue;const f=n(l);d={x1:d.x1-f,y1:d.y1-f,x2:d.x2+f,y2:d.y2+f};const p=o(l);if(p){const m=d.x2-d.x1,y=d.y2-d.y1;if(p.w>m){const b=(p.w-m)/2;d.x1-=b,d.x2+=b}if(p.h>y){const b=(p.h-y)/2;d.y1-=b,d.y2+=b}}c.set(l,d)}return c}function i_(e){const t=e.getBoundingClientRect(),r=t.height/e.offsetHeight;if(!Number.isFinite(r)||r<=0)return[];const n=Rm(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],a=new Set(i.filter(s=>s.hasAttribute("data-flow-inspection-row")&&s.getBoundingClientRect().height>0).map(s=>s.dataset.flowProperty));return i.flatMap(s=>{if(s.closest(".flow-sdk-node")!==e)return[];if(a.has(s.dataset.flowProperty)&&!s.hasAttribute("data-flow-inspection-row"))return[];const u=s.dataset.flowPortSide;if(u&&["top","right","bottom","left"].includes(u)){const l=Sm(n?Lt(o,n):o,u,Number(s.dataset.flowPortPosition??.5));return[{property:s.getAttribute("data-flow-property"),top:l.y,height:0,anchor:l,...s.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...s.dataset.flowPortRole==="source"||s.dataset.flowPortRole==="target"?{role:s.dataset.flowPortRole}:{}}]}const c=s.getBoundingClientRect();return!c.width||!c.height?[]:[{property:s.getAttribute("data-flow-property"),top:Math.round((c.top-t.top)/r*1e3)/1e3,height:Math.round(c.height/r*1e3)/1e3,...s.dataset.flowPortRole==="source"||s.dataset.flowPortRole==="target"?{role:s.dataset.flowPortRole}:{}}]})}function a_({id:e,x:t,y:r,placed:n,hidden:o,onMount:i,drawHandles:a,drawMode:s,connectedPorts:u,resolvedRows:c,hasCollapseControl:l,handleColor:d,animated:f,animationColor:p,animationWidth:m=8,animationVariant:y,width:b=0,height:v=0,propertyMode:g,reversePorts:w,direction:x="LR",onPropertyRows:_,onSurface:C,children:S}){const T=j.useRef(null),[k,E]=j.useState([]),P=c??k,[R,I]=j.useState();return j.useLayoutEffect(()=>{const O=T.current;if(!O)return;const M=()=>{const V=Rm(O);I(re=>JSON.stringify(re)===JSON.stringify(V)?re:V),C==null||C(e,V)};M();const q=new ResizeObserver(M);q.observe(O);const K=O.querySelector("[data-flow-node-surface]");return K&&q.observe(K),()=>q.disconnect()},[e,S,C]),j.useLayoutEffect(()=>(i(e,T.current),()=>{i(e,null),C==null||C(e,void 0)}),[e,i,C]),j.useLayoutEffect(()=>{const O=T.current;if(!O)return;let M="";const q=()=>{const ce=i_(O),he=g?ce:ce.filter(H=>H.anchor),me=JSON.stringify(he);me!==M&&(M=me,E(he),_==null||_(e,he))};if(q(),!g&&!O.querySelector("[data-flow-port-side]"))return;const K=new ResizeObserver(q),V=()=>{K.disconnect(),K.observe(O),O.querySelectorAll("[data-flow-property]").forEach(ce=>K.observe(ce)),q()};V();const re=new MutationObserver(V);return re.observe(O,{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"]}),O.addEventListener("scroll",q,!0),()=>{K.disconnect(),re.disconnect(),O.removeEventListener("scroll",q,!0)}},[e,g,_,S]),h.jsxs("div",{ref:T,className:"flow-sdk-node","data-node-id":e,style:{transform:`translate(-50%, -50%) translate3d(${t.toFixed(2)}px, ${r.toFixed(2)}px, 0)`,visibility:n&&!o?void 0:"hidden"},children:[S,f&&m>0&&b>0&&v>0&&h.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:h.jsx(_m,{variant:y,x:((R==null?void 0:R.left)??0)+m/2,y:((R==null?void 0:R.top)??0)+m/2,width:((R==null?void 0:R.width)??b)-m,height:((R==null?void 0:R.height)??v)-m,radius:((R==null?void 0:R.radius)??0)-m/2,path:R!=null&&R.outline?`M${R.outline.map(O=>`${O.x} ${O.y}`).join(" L")} Z`:void 0,color:p||d||"currentColor",strokeWidth:m})}),a&&g&&P.map(O=>["source","target"].filter(M=>!O.role||O.role===M).filter(M=>s||(u==null?void 0:u.has(`${M}:${O.property}`))).map(M=>{var q;return h.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":O.property,"data-port-role":M,"data-port-side":(q=O.anchor)==null?void 0:q.side,"aria-label":`${M==="source"?"Connect":"Input"} ${O.property}`,title:`${M==="source"?"Connect":"Input"} ${O.property}`,style:{color:d,...O.anchor?{top:O.anchor.y,left:O.anchor.x-16}:{top:O.top+O.height/2,[M==="source"!=!!w?"right":"left"]:-16}},onClick:K=>K.stopPropagation()},`${O.property}:${M}`)})),a&&!l&&(!g||!P.length)&&(!g||!P.some(O=>O.anchor))&&h.jsx("button",{type:"button",className:"flow-sdk-handle","aria-label":"Draw edge",title:"Draw edge",style:{color:d,left:((R==null?void 0:R.left)??0)+(x==="RL"?-36:x==="LR"?(R==null?void 0:R.width)??b:((R==null?void 0:R.width)??b)/2),top:((R==null?void 0:R.top)??0)+(x==="BT"?-36:x==="TB"?(R==null?void 0:R.height)??v:((R==null?void 0:R.height)??v)/2),transform:x==="BT"||x==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:O=>O.stopPropagation(),children:h.jsx(Z.PiPlusBold,{size:24})})]})}const s_=j.memo(a_);class c_{constructor(t,r,n){Ar(this,"_pan");Ar(this,"_zoom");Ar(this,"minZoom");Ar(this,"maxZoom");Ar(this,"size",{w:0,h:0});Ar(this,"listeners",new Set);Ar(this,"animationFrame");Ar(this,"animationTimer");this.minZoom=r,this.maxZoom=n,this._pan={...t.pan},this._zoom=this.clamp(t.zoom)}cancelAnimation(){this.animationFrame!==void 0&&cancelAnimationFrame(this.animationFrame),clearTimeout(this.animationTimer),this.animationFrame=void 0,this.animationTimer=void 0}transition(t,r=!1){if(this.cancelAnimation(),!r||typeof requestAnimationFrame>"u"||typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches){this.set(t.pan,t.zoom);return}const n=this.state,o={pan:{...t.pan},zoom:this.clamp(t.zoom)},i=performance.now(),a=()=>{this.cancelAnimation(),this.set(o.pan,o.zoom)},s=u=>{const c=Math.min(1,(u-i)/300);if(c>=1){a();return}const l=c*c*(3-2*c);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.animationFrame=requestAnimationFrame(s)};this.animationFrame=requestAnimationFrame(s),this.animationTimer=setTimeout(a,400)}get pan(){return{...this._pan}}get zoom(){return this._zoom}get state(){return{pan:this.pan,zoom:this._zoom}}clamp(t){return Number.isFinite(t)?Math.max(this.minZoom,Math.min(this.maxZoom,t)):this.minZoom}set(t,r){this.cancelAnimation(),this.apply(t,r)}apply(t,r){let n=!1;if(t&&(t.x!==this._pan.x||t.y!==this._pan.y)&&(this._pan={x:t.x,y:t.y},n=!0),r!==void 0){const o=this.clamp(r);o!==this._zoom&&(this._zoom=o,n=!0)}n&&this.emit()}zoomAt(t,r){const n=this.clamp(t),o=this._zoom;if(n===o)return;const i=n/o;this.set({x:r.x-(r.x-this._pan.x)*i,y:r.y-(r.y-this._pan.y)*i},n)}fit(t,r=0,n=!1){const o=t.x2-t.x1,i=t.y2-t.y1;if(!(o>0)||!(i>0)||!this.size.w||!this.size.h)return;const a=this.clamp(Math.min((this.size.w-2*r)/o,(this.size.h-2*r)/i));this.transition({pan:{x:(this.size.w-a*(t.x1+t.x2))/2,y:(this.size.h-a*(t.y1+t.y2))/2},zoom:a},n)}center(t,r=!1){if(!this.size.w||!this.size.h)return;const n=this._zoom;this.transition({pan:{x:(this.size.w-n*(t.x1+t.x2))/2,y:(this.size.h-n*(t.y1+t.y2))/2},zoom:n},r)}renderedToModel(t){return{x:(t.x-this._pan.x)/this._zoom,y:(t.y-this._pan.y)/this._zoom}}modelToRendered(t){return{x:t.x*this._zoom+this._pan.x,y:t.y*this._zoom+this._pan.y}}onChange(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}emit(){const t=this.state;this.listeners.forEach(r=>r(t))}}const u_={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},yu={w:60,h:60},ay=4,l_=30,sy=300,d_=500,f_=45,h_=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2;function cy(e){const[t,r]=[...e.values()];return!t||!r?null:{center:{x:(t.x+r.x)/2,y:(t.y+r.y)/2},distance:Math.max(1,Math.hypot(r.x-t.x,r.y-t.y))}}function p_(e){const{nodes:t,edges:r,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:a=!1,rankSep:s,edgeSep:u,spacingFactor:c=1.3,compactSpacingScale:l,minZoom:d,maxZoom:f,initialViewport:p,containerStyle:m,lineColor:y,drawMode:b,dragMode:v,multiSelect:g,isPerformanceMode:w}=e,[x,_]=j.useState(null),C=j.useMemo(()=>x?(x.mode==="connections"?ql:Pl)(x.id,t,r):null,[x,t,r]),S=i==="auto"||i==="properties",T=j.useMemo(()=>r.filter(A=>Cu(A,i)&&(!C||C.has(A.source)&&C.has(A.target))),[r,i,C]),k=j.useMemo(()=>M0(t,r,i,a,C),[t,r,i,a,C]),E=j.useRef(k);E.current=k;const P=j.useRef(e);P.current=e;const R=j.useRef(null),I=j.useRef(null),O=j.useRef(null),M=j.useRef(null),q=j.useMemo(()=>new c_(p,d,f),[]);j.useEffect(()=>{q.minZoom=d,q.maxZoom=f},[q,d,f]);const K=j.useRef(new Map),V=j.useRef(new Map),re=j.useRef(new Map),ce=j.useRef(null),[he,me]=j.useState(new Map),H=j.useCallback((A,$)=>{me(L=>{if(JSON.stringify(L.get(A))===JSON.stringify($))return L;const U=new Map(L);return $?U.set(A,$):U.delete(A),U})},[]),[N,D]=j.useState(new Map),W=j.useRef(N),z=j.useCallback((A,$)=>{D(L=>{if(JSON.stringify(L.get(A)??[])===JSON.stringify($))return L;const U=new Map(L);return $.length?U.set(A,$):U.delete(A),U})},[]),[X,se]=j.useState(()=>new Map),Q=j.useRef(X);Q.current=X;const G=j.useRef(new Map),J=j.useRef(!1),[te,le]=j.useState(0),de=j.useRef(),Re=j.useRef(),ge=j.useRef(null),ze=j.useRef(),Fe=j.useRef(!1),He=j.useRef(null),ar=j.useRef(c),be=a&&(i==="properties"||!!C),_e=j.useRef(be),[Xe,Ke]=j.useState(!0),Ne=j.useRef(null);Ne.current=C;const Qe=j.useRef(1);Qe.current=(x==null?void 0:x.mode)==="connections"?1.25:1;const Ze=j.useRef(null),gr=j.useRef(t),fr=j.useRef([]),Er=j.useRef(!1),we=()=>{ge.current!==null&&cancelAnimationFrame(ge.current),ge.current=null,clearTimeout(ze.current)},or=()=>{fr.current.length&&(Er.current=!0),!J.current&&P.current.fitOnInit!==!1&&(Fe.current=!0),clearTimeout(Re.current),Re.current=setTimeout(()=>{J.current=!0,le(A=>A+1)},d_)},sr=A=>{we();const $=new Map(Q.current),L=performance.now(),U=()=>{we(),se(A),or()},oe=pe=>{const ke=Math.min(1,(pe-L)/sy);if(ke>=1)return U();const Te=h_(ke),ie=new Map;A.forEach((ae,ue)=>{const ye=$.get(ue);ie.set(ue,ye?{x:ye.x+(ae.x-ye.x)*Te,y:ye.y+(ae.y-ye.y)*Te}:ae)}),se(ie),ge.current=requestAnimationFrame(oe)};ge.current=requestAnimationFrame(oe),ze.current=setTimeout(U,sy+100)},wt=()=>{const A=P.current,$=Qe.current,L=E.current,U=L.nodes.map(pe=>{const ke=K.current.get(pe.id)||yu;return{id:pe.id,parent:pe.parent,width:ke.w,height:ke.h}});let oe;try{const pe=A.compactPropertyLayout&&(A.edgeMode==="properties"||!!Ne.current),ke=A.edgeMode!=="nodes"&&A.edgeMode!=="workflow",Te=L.edges.map(ie=>({...ie,connectorClearance:pe?ke&&(ie.sourceProperty!==void 0||ie.targetProperty!==void 0)?I0:O0:0}));oe=n_(U,Te,{edgeLabelFontSize:A.edgeMode==="nodes"||A.edgeMode==="workflow"?km:hn,rankDir:A.direction,compact:pe,nodeAlignment:A.nodeAlignment,rankSep:A.rankSep*$,edgeSep:A.edgeSep*$,nodeSep:5*$,spacingFactor:A.spacingFactor??1.3,compactSpacingScale:(A.compactSpacingScale??(A.spacingFactor??1.3)/1.3)*$})}catch(pe){console.warn("[flow-sdk] layout failed",pe);return}for(const[pe,ke]of G.current)oe.has(pe)?oe.set(pe,ke):A.nodes.some(Te=>Te.id===pe)||G.current.delete(pe);J.current&&!A.isPerformanceMode?sr(oe):(we(),se(oe),or())},ne=j.useCallback(()=>{clearTimeout(Re.current),clearTimeout(de.current),de.current=setTimeout(wt,P.current.layoutDebounce)},[]);j.useEffect(()=>{const A=new Map(gr.current.map($=>[$.id,$]));t.some($=>{var L;return((L=A.get($.id))==null?void 0:L.collapsed)===!0&&!$.collapsed})&&(fr.current=t.filter($=>!A.has($.id)).map($=>$.id)),gr.current=t,ar.current!==c&&Q.current.size>0&&(J.current=!0,Fe.current=!1,clearTimeout(Re.current)),ar.current=c,_e.current!==be&&(Fe.current=!He.current),_e.current=be,ne()},[t,r,k.nodes,k.edges,be,n,o,s,u,ne,c,l]),j.useEffect(()=>()=>{clearTimeout(de.current),clearTimeout(Re.current),we()},[]);const Be=j.useCallback((A,$)=>{var L,U;if(!ce.current&&typeof ResizeObserver<"u"&&(ce.current=new ResizeObserver(oe=>{let pe=!1;for(const ke of oe){const Te=re.current.get(ke.target);if(!Te)continue;const ie=ke.target,ae=ie.offsetWidth,ue=ie.offsetHeight;if(!ae&&!ue)continue;const ye=K.current.get(Te);ye&&ye.w===ae&&ye.h===ue||(K.current.set(Te,{w:ae,h:ue}),pe=!0)}pe&&ne()})),$){V.current.set(A,$),re.current.set($,A),(L=ce.current)==null||L.observe($);const oe=$.offsetWidth,pe=$.offsetHeight;(oe||pe)&&K.current.set(A,{w:oe,h:pe})}else{const oe=V.current.get(A);oe&&((U=ce.current)==null||U.unobserve(oe),re.current.delete(oe)),V.current.delete(A),K.current.delete(A),W.current.has(A)&&z(A,[])}ne()},[ne,z]);j.useEffect(()=>()=>{var A;return(A=ce.current)==null?void 0:A.disconnect()},[]);const Je=j.useMemo(()=>{const A=new Map;for(const $ of t)$.label&&A.set($.id,$.label);return A},[t]),$e=j.useMemo(()=>o_(k.nodes,X,K.current,A=>m(A).padding,A=>{const $=Je.get(A);if(!$)return;const L=m(A);return{w:_n($,`bold ${L.fontSize}px ${et}`)+2*f_,h:0}}),[k.nodes,X,m,Je]),er=j.useRef($e);er.current=$e;const Y=j.useCallback(A=>{const $=er.current.get(A);if($)return b0($);const L=Q.current.get(A);if(!L)return;const U=K.current.get(A)||yu;return{x:L.x,y:L.y,w:U.w,h:U.h}},[]),B=j.useMemo(()=>{const A=new Map;for(const $ of t){const L=Y($.id);L&&A.set($.id,L)}return R0(N,A,he,r,n)},[N,t,X,$e,he,r,n,Y]);W.current=B;const ee=(A,$)=>{var oe;if(!S||$===void 0)return;const L=(oe=B.get(A))==null?void 0:oe.find(pe=>pe.property===$),U=Y(A);return L&&!L.anchor&&U?U.y-U.h/2+L.top+L.height/2:void 0},Ce=(A,$)=>{var oe,pe;if($===void 0)return;const L=(pe=(oe=B.get(A))==null?void 0:oe.find(ke=>ke.property===$))==null?void 0:pe.anchor,U=Y(A);return L&&U?{x:U.x-U.w/2+L.x,y:U.y-U.h/2+L.y,side:L.side}:void 0},Se=(A,$)=>{const L=Y(A),U=he.get(A);return L&&U&&!$e.has(A)&&ee(A,$)===void 0?Lt(L,U):L},Ee=()=>{const A=[];Q.current.forEach(($,L)=>{if(er.current.has(L))return;const U=K.current.get(L)||yu;A.push(st({x:$.x,y:$.y,w:U.w,h:U.h}))}),er.current.forEach($=>A.push($));try{for(const $ of[I.current,O.current]){const L=$==null?void 0:$.getBBox();L&&L.width>0&&L.height>0&&A.push({x1:L.x,y1:L.y,x2:L.x+L.width,y2:L.y+L.height})}}catch{}return Yn(A)},We=()=>{var L,U;const{pan:A,zoom:$}=q;M.current&&(M.current.style.transform=`translate3d(${A.x}px, ${A.y}px, 0) scale(${$})`),(L=I.current)==null||L.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${$})`),(U=O.current)==null||U.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${$})`)};j.useEffect(()=>{We();let A=null,$;const L=q.onChange(()=>{We();const U=R.current;U&&(U.classList.add("flow-sdk-busy"),clearTimeout($),$=setTimeout(()=>U.classList.remove("flow-sdk-busy"),150)),A===null&&(A=requestAnimationFrame(()=>{var oe,pe;A=null,(pe=(oe=P.current).onViewportChange)==null||pe.call(oe,q.state)}))});return()=>{L(),clearTimeout($),A!==null&&cancelAnimationFrame(A)}},[]),j.useLayoutEffect(()=>{const A=R.current;if(!A)return;const $=()=>{let U=A.clientWidth,oe=A.clientHeight;oe||(oe=Math.max(0,window.innerHeight-A.getBoundingClientRect().top-100),oe&&(A.style.height=`${oe}px`)),U||(U=window.innerWidth,U&&(A.style.width=`${U}px`)),q.size={w:U,h:oe}};if($(),typeof ResizeObserver>"u")return;const L=new ResizeObserver($);return L.observe(A),()=>L.disconnect()},[q]),j.useEffect(()=>{if(Er.current){Er.current=!1;const $=fr.current.flatMap(U=>{const oe=Y(U);return oe?[st(oe)]:[]});fr.current=[];const L=Yn($);if(L){Fe.current=!1,q.center(L,P.current.animateViewport);return}}if(!Fe.current)return;Fe.current=!1;const A=Ee();A&&q.fit(A,50,P.current.animateViewport)},[X]);const Le=j.useMemo(()=>{const A=ie=>Pl(ie,P.current.nodes,P.current.edges),$=(ie,ae=50,ue=P.current.animateViewport)=>{const ye=Yn([...ie].flatMap(cr=>{const Ct=Y(cr);return Ct?[st(Ct)]:[]}));ye&&(Fe.current=!1,q.fit(ye,Number.isFinite(ae)?Math.max(0,ae):50,ue))},L=(ie,ae,ue,ye)=>{if(!Y(ie))return;const cr=ae==="connections"?oe(ie):A(ie);Ze.current||(Ze.current={pan:{...q.pan},zoom:q.zoom}),Ne.current=cr,P.current.compactPropertyLayout&&(Fe.current=!1,He.current=()=>$(Ne.current??cr,ue,ye)),_({id:ie,mode:ae}),P.current.compactPropertyLayout||$(cr,ue,ye)},U=ie=>{He.current?He.current=ie:ie()},oe=ie=>ql(ie,P.current.nodes,P.current.edges),pe=(ie=>{if(ie===void 0)return q.zoom;q.set(void 0,ie)}),ke=(ie=>{if(ie===void 0)return q.pan;q.set(ie)}),Te=(ie,ae)=>{var ye;const ue=(ye=R.current)==null?void 0:ye.getBoundingClientRect();return{x:ie-((ue==null?void 0:ue.left)??0),y:ae-((ue==null?void 0:ue.top)??0)}};return{zoom:pe,pan:ke,setEdgesVisible:Ke,focusNode:(ie,ae,ue)=>U(()=>$(new Set([ie]),ae,ue)),focusBranch:(ie,ae,ue)=>U(()=>$(A(ie),ae,ue)),focusConnections:(ie,ae,ue)=>U(()=>$(oe(ie),ae,ue)),isolateConnections:(ie,ae,ue)=>L(ie,"connections",ae,ue),isolateBranch:(ie,ae,ue)=>L(ie,"branch",ae,ue),restoreView:(ie=P.current.animateViewport)=>{const ae=P.current.compactPropertyLayout&&!!Ne.current;Ne.current=null,_(null);const ue=Ze.current;Ze.current=null,ae?He.current=()=>{ue&&q.transition(ue,ie)}:ue&&U(()=>q.transition(ue,ie))},zoomAt:(ie,ae)=>q.zoomAt(ie,ae),fit:(ie=0,ae=P.current.animateViewport)=>{U(()=>{const ue=Ee();ue&&q.fit(ue,ie,ae)})},centerAndFit:(ie=0,ae=P.current.animateViewport)=>{U(()=>{const ue=Ee();ue&&q.fit(ue,ie,ae)})},center:(ie=P.current.animateViewport)=>{const ae=Ee();ae&&q.center(ae,ie)},clientToModel:(ie,ae)=>q.renderedToModel(Te(ie,ae)),modelToClient:ie=>{var ye;const ae=(ye=R.current)==null?void 0:ye.getBoundingClientRect(),ue=q.modelToRendered(ie);return{x:ue.x+((ae==null?void 0:ae.left)??0),y:ue.y+((ae==null?void 0:ae.top)??0)}},getNodeBox:ie=>Y(ie),setNodePosition:(ie,ae,ue)=>{if(!Q.current.has(ie)||ae&&(!Number.isFinite(ae.x)||!Number.isFinite(ae.y)))return!1;if(we(),!ae)return G.current.delete(ie),ne(),!0;const ye=new Map(Q.current);return ye.set(ie,{...ae}),(ue==null?void 0:ue.persist)===!1?G.current.delete(ie):G.current.set(ie,{...ae}),Q.current=ye,se(ye),(ue==null?void 0:ue.persist)===!1&&ne(),!0},onViewportChange:ie=>q.onChange(ie)}},[]);j.useEffect(()=>{var A,$;return($=(A=P.current).onInit)==null||$.call(A,Le),()=>q.cancelAnimation()},[Le]),j.useEffect(()=>{var A,$;if(te>0){const L=He.current;He.current=null,L==null||L(),($=(A=P.current).onLayoutComplete)==null||$.call(A,Le)}},[Le,te]);const Pe=j.useRef(null),Me=j.useRef(new Map),yr=j.useRef(!1),[Ye,mr]=j.useState(null),[Oe,wr]=j.useState(null),$r=A=>{const $=R.current.getBoundingClientRect();return{x:A.clientX-$.left,y:A.clientY-$.top}},Vn=(A,$)=>{const L=P.current.nodes;for(let U=L.length-1;U>=0;U--){const oe=L[U].id;if(!ct(oe,P.current.edges,P.current.edgeMode)||Ne.current&&!Ne.current.has(oe)||oe===$||er.current.has(oe))continue;const pe=Y(oe);if(pe&&Al(A,st(pe)))return oe}for(const[U,oe]of er.current)if(ct(U,P.current.edges,P.current.edgeMode)&&!(Ne.current&&!Ne.current.has(U))&&U!==$&&Al(A,oe))return U;return null},Wn=(A,$)=>{if(P.current.edgeMode==="nodes"||P.current.edgeMode==="workflow")return null;const L=P.current.direction==="RL",U=Math.max(16,6/q.zoom);let oe=null;for(const pe of[...P.current.nodes].reverse()){if(!ct(pe.id,P.current.edges,P.current.edgeMode)||Ne.current&&!Ne.current.has(pe.id))continue;const ke=Y(pe.id),Te=W.current.get(pe.id);if(!ke||!Te||er.current.has(pe.id))continue;const ie=ke.x+($==="source"!==L?1:-1)*ke.w/2;for(const ae of Te){if(ae.role&&ae.role!==$)continue;const ue=ke.y-ke.h/2+ae.top,ye=Math.hypot(A.x-(ae.anchor?ke.x-ke.w/2+ae.anchor.x:ie),A.y-ue-ae.height/2);if(!ae.anchor&&A.x>=ke.x-ke.w/2&&A.x<=ke.x+ke.w/2&&A.y>=ue&&A.y<=ue+ae.height)return{nodeId:pe.id,property:ae.property};ye<=U&&(!oe||ye<oe.distance)&&(oe={nodeId:pe.id,property:ae.property,distance:ye})}}return oe},Db=A=>{var ke;if(!A.currentTarget.contains(A.target)||A.button!==0||P.current.readOnly)return;Pe.current||(yr.current=!1);const $=A.target;if($.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const L=P.current,U=$r(A);if(A.pointerType==="touch"){Me.current.set(A.pointerId,U);const Te=cy(Me.current);if(Te){Pe.current={kind:"pinch",distance:Te.distance,zoom:q.zoom,anchor:q.renderedToModel(Te.center)},wr(null),mr(null),yr.current=!0;for(const ie of Me.current.keys())A.currentTarget.setPointerCapture(ie);return}}if(Pe.current)return;const oe=L.drawHandles&&$.closest(".flow-sdk-handle"),pe=L.drawHandles&&$.closest(".flow-sdk-property-port");if(L.drawMode||oe||pe){const Te=q.renderedToModel(U),ie=L.drawMode?Wn(Te,"source"):null,ae=pe||oe,ue=ae?(ke=ae.closest("[data-node-id]"))==null?void 0:ke.dataset.nodeId:(ie==null?void 0:ie.nodeId)??Vn(Te),ye=pe?pe.dataset.property:ie==null?void 0:ie.property;if(ue){Pe.current={kind:"draw",pointerId:A.pointerId,source:ue,sourceProperty:ye,reverse:(pe==null?void 0:pe.dataset.portRole)==="target",startClient:{x:A.clientX,y:A.clientY}},yr.current=!0,wr({source:ue,sourceProperty:ye,point:Te,target:null}),A.currentTarget.setPointerCapture(A.pointerId);return}}$.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(L.multiSelect?Pe.current={kind:"box",pointerId:A.pointerId,start:U,current:U}:L.dragMode?Pe.current={kind:"pan",pointerId:A.pointerId,start:U,pan0:q.pan,moved:!1}:Pe.current={kind:"tap",pointerId:A.pointerId,start:U,moved:!1},A.currentTarget.setPointerCapture(A.pointerId))},zb=A=>{const $=Pe.current;if(!$||P.current.readOnly)return;const L=$r(A);if(Me.current.has(A.pointerId)&&Me.current.set(A.pointerId,L),$.kind==="pinch"){const U=cy(Me.current);if(!U)return;const oe=Math.max(q.minZoom,Math.min(q.maxZoom,$.zoom*U.distance/$.distance));q.set({x:U.center.x-$.anchor.x*oe,y:U.center.y-$.anchor.y*oe},oe);return}if($.pointerId===A.pointerId)switch($.kind){case"pan":{const U=L.x-$.start.x,oe=L.y-$.start.y;if(!$.moved&&Math.hypot(U,oe)<=ay)return;$.moved=!0,yr.current=!0,q.set({x:$.pan0.x+U,y:$.pan0.y+oe});break}case"tap":{Math.hypot(L.x-$.start.x,L.y-$.start.y)>ay&&($.moved=!0);break}case"box":{yr.current=!0,$.current=L,mr({x1:Math.min($.start.x,L.x),y1:Math.min($.start.y,L.y),x2:Math.max($.start.x,L.x),y2:Math.max($.start.y,L.y)});break}case"draw":{const U=q.renderedToModel(L),oe=Wn(U,$.reverse?"source":"target");wr($.reverse&&oe?{source:oe.nodeId,sourceProperty:oe.property,point:U,target:$.source,targetProperty:$.sourceProperty}:{source:$.source,sourceProperty:$.sourceProperty,point:U,target:(oe==null?void 0:oe.nodeId)??Vn(U,$.source),targetProperty:oe==null?void 0:oe.property});break}}},ol=(A,$)=>{var oe,pe,ke,Te,ie;Me.current.delete(A.pointerId);const L=Pe.current;if(!L)return;if(L.kind==="pinch"){const ae=[...Me.current][0];Pe.current=ae&&P.current.dragMode&&!$?{kind:"pan",pointerId:ae[0],start:ae[1],pan0:q.pan,moved:!0}:null;return}if(L.pointerId!==A.pointerId)return;Pe.current=null;try{A.currentTarget.releasePointerCapture(A.pointerId)}catch{}const U=P.current;switch($=$||!!U.readOnly,L.kind){case"pan":case"tap":!$&&!L.moved&&((oe=U.onBackgroundTap)==null||oe.call(U));break;case"box":{if(mr(null),$)break;const ae=q.renderedToModel(L.start),ue=q.renderedToModel(L.current),ye={x1:Math.min(ae.x,ue.x),y1:Math.min(ae.y,ue.y),x2:Math.max(ae.x,ue.x),y2:Math.max(ae.y,ue.y)};if(ye.x2-ye.x1<1&&ye.y2-ye.y1<1){(pe=U.onBackgroundTap)==null||pe.call(U);break}const cr=[];for(const Ct of U.nodes){const sl=Y(Ct.id);sl&&v0(st(sl),ye)&&cr.push(Ct.id)}cr.length&&((ke=U.onBoxSelect)==null||ke.call(U,cr));break}case"draw":{if(wr(null),$)break;const ae=$r(A),ue=q.renderedToModel(ae),ye=Wn(ue,L.reverse?"source":"target"),cr=(ye==null?void 0:ye.nodeId)??Vn(ue);if(cr===L.source&&(L.sourceProperty===void 0||(ye==null?void 0:ye.property)===void 0||ye.property===L.sourceProperty))break;cr?(Te=U.onEdgeDraw)==null||Te.call(U,L.reverse?cr:L.source,L.reverse?L.source:cr,L.sourceProperty!==void 0||(ye==null?void 0:ye.property)!==void 0?{sourceProperty:L.reverse?ye==null?void 0:ye.property:L.sourceProperty,targetProperty:L.reverse?L.sourceProperty:ye==null?void 0:ye.property}:void 0):Math.max(Math.abs(A.clientX-L.startClient.x),Math.abs(A.clientY-L.startClient.y))>l_&&((ie=U.onDrawIntoSpace)==null||ie.call(U,L.source,ue,L.sourceProperty,L.reverse));break}}},Hr=j.useCallback(()=>{var L;const A=Pe.current,$=[...Me.current.keys()];A&&A.kind!=="pinch"&&$.push(A.pointerId),Pe.current=null,Me.current.clear(),wr(null),mr(null);for(const U of $)(L=R.current)!=null&&L.hasPointerCapture(U)&&R.current.releasePointerCapture(U)},[]);j.useEffect(()=>{const A=$=>{$.key==="Escape"&&Hr()};return window.addEventListener("keydown",A),window.addEventListener("blur",Hr),()=>{window.removeEventListener("keydown",A),window.removeEventListener("blur",Hr),Pe.current=null,Me.current.clear()}},[Hr]),j.useEffect(()=>{Hr()},[b,v,g,i,n,e.drawHandles,e.readOnly,Hr]);const Vb=j.useMemo(()=>{const A=new Map,$=new Map;for(const L of T){if(L.source!==L.target)continue;const U=A.get(L.source)??0;A.set(L.source,U+1),$.set(L.id,U)}return $},[T]),Gn=u_[n],[Un,Wb]=j.useState(null);j.useLayoutEffect(()=>{R.current&&Un&&F0(R.current)});const Hn=m0(T,Se,Gn),Gb=e.onEdgeSelect,Ub=e.onContainerSelect,il=Oe?Oe.target&&Se(Oe.target,Oe.targetProperty)||{x:Oe.point.x,y:Oe.point.y,w:1,h:1}:null,al=Oe?Se(Oe.source,Oe.sourceProperty):null,Hb=["flow-sdk-canvas",b?"flow-sdk-draw":"",w?"flow-sdk-perf":""].filter(Boolean).join(" ");return h.jsxs("div",{ref:R,className:Hb,"data-edge-mode":i,onPointerDownCapture:Db,onPointerMove:zb,onPointerUp:A=>ol(A,!1),onPointerCancel:A=>ol(A,!0),onLostPointerCapture:A=>{const $=Pe.current;$&&($.kind==="pinch"||$.pointerId===A.pointerId)&&Hr()},onClickCapture:A=>{A.currentTarget.contains(A.target)&&(yr.current||e.readOnly)&&(A.preventDefault(),A.stopPropagation())},children:[h.jsx("svg",{className:"flow-sdk-svg",children:h.jsxs("g",{ref:I,children:[h.jsx("g",{className:"flow-sdk-containers",children:[...$e].filter(([A])=>ct(A,r,i)).filter(([A])=>!C||C.has(A)).map(([A,$])=>{var L;return h.jsx(T0,{id:A,rect:$,label:Je.get(A),labelLayer:Un,style:m(A),onSelect:Ub,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(L=e.selectedNodeIds)==null?void 0:L.includes(A)},A)})}),h.jsx("g",{className:"flow-sdk-edges",children:Xe&&T.map(A=>{var U,oe,pe;if(C&&(!C.has(A.source)||!C.has(A.target)))return null;const $=Se(A.source,A.sourceProperty),L=Se(A.target,A.targetProperty);return!$||!L?null:h.jsx(Nl,{id:A.id,edgeData:A.data,validationIssue:A.validationIssue,edgeType:A.type,edgeRadius:e.edgeRadius,propertyMode:S,customEdgeTypes:e.customEdgeTypes,source:$,target:L,sourceProperty:A.sourceProperty,targetProperty:A.targetProperty,sourceY:ee(A.source,A.sourceProperty),targetY:ee(A.target,A.targetProperty),sourcePort:Ce(A.source,A.sourceProperty),targetPort:Ce(A.target,A.targetProperty),dir:Gn,turn:((U=Hn.get(A.id))==null?void 0:U.turn)??A.turn,labelAtTarget:(oe=Hn.get(A.id))==null?void 0:oe.labelAtTarget,labelFraction:(pe=Hn.get(A.id))==null?void 0:pe.labelFraction,color:A.color,labelBg:A.labelBg,label:A.label,labelLayer:Un,dashed:A.dashed,animated:A.animated&&!w,inverted:A.inverted,loopIndex:Vb.get(A.id)??0,onSelect:Gb},A.id)})}),Xe&&Oe&&Cu(Oe,i)&&al&&il&&h.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:h.jsx(Nl,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:Oe.source,target:Oe.target??"",sourceProperty:Oe.sourceProperty,targetProperty:Oe.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:S,customEdgeTypes:e.customEdgeTypes,source:al,target:il,sourceProperty:Oe.sourceProperty,targetProperty:Oe.targetProperty,sourceY:ee(Oe.source,Oe.sourceProperty),sourcePort:Ce(Oe.source,Oe.sourceProperty),targetPort:Oe.target?Ce(Oe.target,Oe.targetProperty):void 0,targetY:Oe.target?ee(Oe.target,Oe.targetProperty):void 0,dir:Gn,turn:.5,color:y,labelBg:y})})]})}),h.jsx("div",{ref:M,className:"flow-sdk-nodes",children:t.map(A=>{var pe,ke;const $=X.get(A.id),L=$e.get(A.id),U=($==null?void 0:$.x)??(L?(L.x1+L.x2)/2:0),oe=($==null?void 0:$.y)??(L?(L.y1+L.y2)/2:0);return h.jsx(s_,{id:A.id,x:U,y:oe,placed:!!$||!!L,hidden:!ct(A.id,r,i)||!!C&&!C.has(A.id),onMount:Be,drawHandles:e.drawHandles&&!e.readOnly,drawMode:b,connectedPorts:new Set(T.flatMap(Te=>[...Te.source===A.id&&Te.sourceProperty!==void 0?[`source:${Te.sourceProperty}`]:[],...Te.target===A.id&&Te.targetProperty!==void 0?[`target:${Te.targetProperty}`]:[]])),hasCollapseControl:A.hasCollapseControl,handleColor:y,animated:A.animated&&!L&&!w,animationColor:A.animationColor,animationWidth:A.animationWidth,animationVariant:A.animationVariant,width:(pe=K.current.get(A.id))==null?void 0:pe.w,height:(ke=K.current.get(A.id))==null?void 0:ke.h,propertyMode:S,resolvedRows:B.get(A.id),reversePorts:n==="RL",direction:n,onPropertyRows:z,onSurface:H,children:A.element},A.id)})}),Ye&&h.jsx("div",{className:"flow-sdk-box",style:{left:Ye.x1,top:Ye.y1,width:Ye.x2-Ye.x1,height:Ye.y2-Ye.y1}}),h.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:h.jsx("g",{ref:O,transform:`translate(${q.pan.x} ${q.pan.y}) scale(${q.zoom})`,children:h.jsx("g",{ref:Wb,className:"flow-sdk-labels",style:{pointerEvents:b?"none":"visiblePainted",outline:"none"}})})})]})}const g_=j.memo(p_);function Ob({id:e,role:t,side:r,position:n=.5,placement:o,children:i,style:a}){return h.jsx("div",{"data-flow-property":e,"data-flow-port-role":t,"data-flow-port-side":r,"data-flow-port-position":r?n:void 0,"data-flow-port-placement":o,style:{minHeight:32,display:"flex",alignItems:"center",justifyContent:t==="source"?"flex-end":"flex-start",...a,...r?{display:"none"}:{}},children:i??e})}const y_=yn.default.dialog`
154
+ ${e=>Dr(e.$surface,e.$border)}
151
155
  &[open] {
152
156
  display: flex;
153
157
  flex-direction: column;
@@ -160,7 +164,7 @@
160
164
  & *::-webkit-scrollbar {
161
165
  display: none;
162
166
  }
163
- `,p_=gn.default.div`
167
+ `,m_=yn.default.div`
164
168
  min-height: 0;
165
169
  overflow: auto;
166
170
  padding: 32px 0;
@@ -178,5 +182,5 @@
178
182
  black calc(100% - 32px),
179
183
  transparent
180
184
  );
181
- `;function Am({nodeAddress:e,active:t,label:r,open:n=!1,onClose:o,children:i,filter:a,height:s}){const{background:u,border:c,colorText:l}=Ve(),d=E.useRef(null),f=E.useId(),{data:p,schema:b,bindings:y}=E.useContext(kr),m=i!==void 0||!!(p&&b&&(y?Jt(y,e,b):pt(p,e,b)));E.useEffect(()=>{var g,w,v,_,C;!t||!m||!n?(g=d.current)==null||g.close():(w=d.current)!=null&&w.open||((v=d.current)==null||v.showModal(),(C=(_=d.current)==null?void 0:_.querySelector("[data-form-filter] input"))==null||C.focus())},[t,m,n]);const x=pe(u);return m?h.jsx(h.Fragment,{children:typeof document<"u"&&Lt.createPortal(h.jsx(h_,{ref:d,id:f,"aria-label":`Configure ${r}`,onClose:o,onPointerDown:g=>g.stopPropagation(),onWheel:g=>g.stopPropagation(),onKeyDown:g=>g.stopPropagation(),onClick:g=>{var w;g.stopPropagation(),g.target===g.currentTarget&&((w=d.current)==null||w.close())},style:{margin:"auto",padding:20,width:380,boxSizing:"border-box",maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100dvh - 32px)",height:s,overflow:"hidden",borderRadius:30,border:`1px solid ${pe(c)}`,background:x,color:pe(l),boxShadow:`0 0 0 8px color-mix(in srgb, ${x} 60%, transparent)`,fontSize:16,textTransform:"none"},children:n&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexShrink:0},children:[h.jsx("strong",{style:{overflowWrap:"anywhere",minWidth:0},children:r}),h.jsx("form",{method:"dialog",style:{margin:0},onSubmit:g=>g.stopPropagation(),children:h.jsx(ht,{type:"submit","aria-label":"Close node configuration"})})]}),a&&h.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:a}),h.jsx(p_,{"data-form-scroll":"",style:s?{flex:1}:void 0,children:i??h.jsx(rb,{nodeAddress:e})})]})}),document.body)}):null}const Cu=({icon:e,label:t,onClick:r,color:n,boxSize:o=6,...i})=>{const{background:a,border:s,colorText:u}=Ve();return h.jsx(je,{label:t,children:h.jsx(F.Flex,{children:h.jsx(F.Icon,{as:e,boxSize:o,color:n,cursor:r?"pointer":void 0,onClick:r})})})},g_=({data:e,children:t,isInverted:r,isParent:n})=>{var N,B,W,z,X,se;const{selectedNodeIds:o,setSelectedNodeIds:i,selectedEdgeId:a,setSelectedEdgeId:s,isMultiSelectMode:u,isPerformanceMode:c,engineRef:l,callbacks:d,config:f,themeColor:p,direction:b}=Ie(),{background:y,border:m,colorText:x}=Ve(),g=E.useRef(null),w=E.useRef(null),[v,_]=E.useState(!1),[C,S]=E.useState(!1),[T,k]=E.useState(!1),j=e==null?void 0:e.id,P=tb(j),R=o.includes(j),I=f.nodeOverlayActions,O=f.renderNodeOverlay,M=(()=>{var Q;try{const G=(Q=l.current)==null?void 0:Q.zoom();return G!==void 0&&G<.08}catch{return!1}})(),q=E.useCallback(Q=>{var J,te,de,fe;if(C||f.readOnly)return;const G={shiftKey:Q.shiftKey,ctrlKey:Q.ctrlKey,metaKey:Q.metaKey,altKey:Q.altKey};if(a&&(s(null),(J=d.onEdgeDeselect)==null||J.call(d)),u){const Ee=o.includes(j),ge=Ee?o.filter(We=>We!==j):[...o,j];i(ge),Ee?(te=d.onNodeDeselect)==null||te.call(d):(de=d.onNodeSelect)==null||de.call(d,j,e,G)}else i([j]),(fe=d.onNodeSelect)==null||fe.call(d,j,e,G)},[j,e,o,a,u,C,i,s,d,f]),H=E.useCallback(()=>{var Q;C||f.readOnly||(Q=d.onNodeDoubleClick)==null||Q.call(d,j,e)},[j,e,C,d,f]),V=E.useCallback(()=>{w.current&&clearTimeout(w.current),w.current=setTimeout(()=>_(!0),100)},[]),re=E.useCallback(()=>{w.current&&clearTimeout(w.current),_(!1)},[]),ce=!!((N=e==null?void 0:e.config)!=null&&N.form),le={tabIndex:ce?0:void 0,"aria-haspopup":ce?"dialog":void 0,"aria-expanded":ce?T:void 0,onDoubleClickCapture:Q=>{var G;!ce||f.readOnly||C||!Q.currentTarget.contains(Q.target)||Q.target instanceof Element&&Q.target.closest("button, input, textarea, select, a, [contenteditable=true]")||(Q.preventDefault(),Q.stopPropagation(),i([j]),k(!0),(G=d.onNodeDoubleClick)==null||G.call(d,j,e))},onKeyDown:Q=>{!ce||f.readOnly||Q.target!==Q.currentTarget||Q.key!=="Enter"||(Q.preventDefault(),Q.stopPropagation(),i([j]),k(!0))}},be=ce&&h.jsx(Am,{nodeAddress:j,active:R,label:e.label||e.headerTitle||"Node",open:T,onClose:()=>{var Q;k(!1),R&&((Q=g.current)==null||Q.focus({preventScroll:!0}))}}),K=Array.isArray((B=e==null?void 0:e.config)==null?void 0:B.ports)?e.config.ports.map(Q=>h.jsx(Pm,{...Q},`${Q.id}:${Q.role}`)):null;return n?h.jsxs(F.Box,{ref:g,...le,onClick:q,onDoubleClick:H,onMouseEnter:V,onMouseLeave:re,cursor:"pointer",position:"relative",children:[be,!c&&(O||I&&I.length>0)&&v&&!M&&h.jsxs(h.Fragment,{children:[h.jsx(F.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>_(!0),onMouseLeave:re}),O?h.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>_(!0),onMouseLeave:re,willChange:"transform",children:O({nodeId:j,nodeData:e,isRoot:j==="root",isParent:!0,isHovered:v,setIsHovered:_})}):h.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:y,p:3,borderColor:m,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>_(!0),onMouseLeave:re,willChange:"transform",children:h.jsx(F.HStack,{px:2,gap:2,children:I.map((Q,G)=>h.jsxs(F.Box,{display:"contents",children:[G>0&&h.jsx(F.Box,{borderColor:m,height:5,borderRightWidth:1}),h.jsx(Cu,{icon:Q.icon,label:Q.label,color:x,bgColor:y,borderColor:m,textColor:x,boxSize:5,onClick:J=>{var te;J.stopPropagation(),(te=d.onNodeHoverAction)==null||te.call(d,Q.id,j,e)}})]},Q.id))})})]}),t({id:j,data:e,isActive:R,isLowZoom:M,isEditing:C,onEditStart:()=>S(!0),onEditEnd:()=>S(!1)}),P&&!((W=e==null?void 0:e.config)!=null&&W.parentContainer)&&((z=e==null?void 0:e.config)==null?void 0:z.collapsed)!==void 0&&(()=>{var J;const Q=b==="TB"||b==="BT",G=r||b==="RL";return h.jsx(F.IconButton,{position:"absolute",...Q?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:G?void 0:"-75px",left:G?"-75px":void 0,top:"50%",transform:"translateY(-50%)"},"aria-label":e.config.collapsed?"Expand":"Collapse",disabled:f.readOnly,onClick:te=>{var de;te.stopPropagation(),(de=d.onNodeCollapse)==null||de.call(d,j,!e.config.collapsed)},bgColor:pe(((J=e==null?void 0:e.viewProps)==null?void 0:J.bgColor)||p),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?h.jsx(Z.PiPlusBold,{size:30,color:pe("gray.800")}):h.jsx(Z.PiMinusBold,{size:30,color:pe("gray.800")})})})()]}):h.jsxs(F.Box,{ref:g,...le,onClick:q,onDoubleClick:H,onMouseEnter:V,onMouseLeave:re,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[be,K,!c&&(O||I&&I.length>0)&&v&&!M&&h.jsxs(h.Fragment,{children:[h.jsx(F.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>_(!0),onMouseLeave:re}),O?h.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>_(!0),onMouseLeave:re,willChange:"transform",children:O({nodeId:j,nodeData:e,isRoot:j==="root",isParent:!!n,isHovered:v,setIsHovered:_})}):h.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:y,p:3,borderColor:m,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>_(!0),onMouseLeave:re,willChange:"transform",children:h.jsx(F.HStack,{px:2,gap:2,children:I.map((Q,G)=>h.jsxs(F.Box,{display:"contents",children:[G>0&&h.jsx(F.Box,{borderColor:m,height:5,borderRightWidth:1}),h.jsx(Cu,{icon:Q.icon,label:Q.label,color:x,bgColor:y,borderColor:m,textColor:x,boxSize:5,onClick:J=>{var te;J.stopPropagation(),(te=d.onNodeHoverAction)==null||te.call(d,Q.id,j,e)}})]},Q.id))})})]}),h.jsxs(F.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[P&&!((X=e==null?void 0:e.config)!=null&&X.parentContainer)&&((se=e==null?void 0:e.config)==null?void 0:se.collapsed)!==void 0&&!n&&(()=>{var te,de,fe;const Q=b==="TB"||b==="BT",G=r||b==="RL",J=(te=e==null?void 0:e.config)!=null&&te.labelBelow?((((de=e==null?void 0:e.viewProps)==null?void 0:de.fontSize)||1)*100+100)/2:void 0;return h.jsx(F.IconButton,{position:"absolute",...Q?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:G?void 0:J===void 0?"-75px":`calc(50% - ${J+75}px)`,left:G?J===void 0?"-75px":`calc(50% - ${J+75}px)`:void 0,alignSelf:J===void 0?"center":void 0,top:J===void 0?void 0:`${J}px`,transform:J===void 0?void 0:"translateY(-50%)",zIndex:J===void 0?void 0:1},"aria-label":e.config.collapsed?"Expand":"Collapse",disabled:f.readOnly,onClick:Ee=>{var ge;Ee.stopPropagation(),(ge=d.onNodeCollapse)==null||ge.call(d,j,!e.config.collapsed)},bgColor:pe(((fe=e==null?void 0:e.viewProps)==null?void 0:fe.bgColor)||p),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?h.jsx(Z.PiPlusBold,{size:30,color:pe("gray.800")}):h.jsx(Z.PiMinusBold,{size:30,color:pe("gray.800")})})})(),t({id:j,data:e,isActive:R,isLowZoom:M,isEditing:C,onEditStart:()=>S(!0),onEditEnd:()=>S(!1)})]})]})},Bn=E.memo(g_);function tl(e=!0){const t=E.useRef(null);return E.useEffect(()=>{if(!e||!t.current)return;const r=i=>{i.stopPropagation()},n=t.current,o=["mousedown","mouseup","click","dblclick","pointerdown","pointerup","wheel"];return o.forEach(i=>n.addEventListener(i,r)),()=>{o.forEach(i=>n.removeEventListener(i,r))}},[e]),t}const Kt=({nodeId:e,label:t,color:r,fontWeight:n="bold",fontSize:o="5xl",wrap:i=!1,isEditing:a,onEditStart:s,onEditEnd:u})=>{const{callbacks:c,config:l,readOnly:d}=Ie(),f=l.editable&&!d,[p,b]=E.useState(t),[y,m]=E.useState(),x=E.useRef(null),g=E.useRef(!1),w=tl(a);E.useEffect(()=>{a&&(g.current=!1,x.current&&(x.current.focus(),x.current.select()))},[a]);const v=()=>{var C;if(g.current)return;g.current=!0;const _=p.trim();_&&_!==t&&((C=c.onNodeLabelChange)==null||C.call(c,e,_)),u()};return!f||!a?h.jsx(F.Text,{color:r,fontWeight:n,fontSize:o,minW:0,maxW:"100%",whiteSpace:i?"normal":"nowrap",overflowWrap:i?"anywhere":void 0,overflow:"hidden",textOverflow:"ellipsis",title:t,onDoubleClick:f?_=>{_.stopPropagation(),m({width:_.currentTarget.offsetWidth,height:_.currentTarget.offsetHeight}),b(t),s()}:void 0,cursor:f?"text":void 0,children:t}):h.jsxs("div",{ref:w,style:{position:"relative",width:"max-content",minWidth:y==null?void 0:y.width,maxWidth:900,height:y==null?void 0:y.height},children:[h.jsx(F.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),h.jsx(F.Input,{ref:x,value:p,onChange:_=>b(_.target.value),onBlur:v,onKeyDown:_=>{_.key==="Enter"&&v(),_.key==="Escape"&&(g.current=!0,u())},color:r,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"})]})},y_=({id:e,data:t,isActive:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var y,m,x,g,w,v,_,C;const{themeColor:a}=Ie(),{colorText:s}=Ve(),u=((y=t==null?void 0:t.viewProps)==null?void 0:y.bgColor)==="transparent",c=((m=t==null?void 0:t.viewProps)==null?void 0:m.outline)===!0,{bgColor:l,borderColor:d,textColor:f}=Zt(((x=t==null?void 0:t.viewProps)==null?void 0:x.bgColor)||a),p=pe(((g=t==null?void 0:t.viewProps)==null?void 0:g.textColor)||(u||c?s:f)),b=((w=t==null?void 0:t.viewProps)==null?void 0:w.borderColor)||(c?!u&&((v=t==null?void 0:t.viewProps)==null?void 0:v.bgColor)||a:d);return h.jsx(F.Box,{"data-flow-node-surface":"",borderRadius:(_=t==null?void 0:t.viewProps)==null?void 0:_.borderRadius,bgColor:c?"transparent":l,...ln(t==null?void 0:t.viewProps,b,r,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:h.jsxs(F.Flex,{justifyContent:"start",alignItems:"center",gap:8,w:"fit-content",maxW:900,minW:0,fontSize:"5xl",lineHeight:"normal",children:[((C=t==null?void 0:t.config)==null?void 0:C.icon)&&h.jsx(F.Box,{flexShrink:0,children:h.jsx(Mr,{name:t.config.icon,size:80,color:p})}),h.jsx(Kt,{nodeId:e,label:(t==null?void 0:t.label)||(t==null?void 0:t.text)||"",color:p,isEditing:n,onEditStart:o,onEditEnd:i})]})})};function Dn(){const{nodeViewModes:e,setNodeViewMode:t,allNodesIconLabel:r,setAllNodesIconLabel:n}=Ie();return{allNodesIconLabel:r,setAllNodesIconLabel:n,getNodeViewMode:o=>e[o]??"default",showNodeProperties:o=>t(o,"properties"),restoreNodeView:o=>t(o,"default"),toggleNodeView:o=>t(o,e[o]==="properties"?"default":"properties"),setNodeViewMode:t}}const b_=({id:e,isActive:t,data:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var w,v,_,C,S,T,k,j,P,R,I,O,M,q,H;const{themeColor:a}=Ie(),{colorText:s}=Ve(),u=((w=r==null?void 0:r.viewProps)==null?void 0:w.bgColor)==="transparent",c=((v=r==null?void 0:r.viewProps)==null?void 0:v.outline)===!0,l=!u&&((_=r==null?void 0:r.viewProps)==null?void 0:_.bgColor)||a,{borderColor:d,highlightColor:f,textColor:p}=Zt(l),b=pe(((C=r==null?void 0:r.viewProps)==null?void 0:C.textColor)||(u||c?s:p)),y=u&&!c&&!((S=r==null?void 0:r.viewProps)!=null&&S.borderColor)?"transparent":pe(((T=r==null?void 0:r.viewProps)==null?void 0:T.borderColor)||(c?l:d)),m=u||c?"transparent":l!=null&&l.startsWith("#")?l:pe(f),x=(k=r==null?void 0:r.config)==null?void 0:k.icon,g=(r==null?void 0:r.label)??(r==null?void 0:r.text)??"";if((j=r==null?void 0:r.config)!=null&&j.labelBelow){const V=(((P=r==null?void 0:r.viewProps)==null?void 0:P.fontSize)||1)*100;return h.jsxs(F.Flex,{"data-flow-icon-label":"",direction:"column",align:"center",gap:"24px",width:`${Math.max(V+200,360)}px`,position:"relative",children:[h.jsx(F.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${V+100}px`,height:`${V+100}px`,flexShrink:0,borderRadius:(R=r==null?void 0:r.viewProps)==null?void 0:R.borderRadius,backgroundColor:m,...ln(r==null?void 0:r.viewProps,y,t,2),children:!!x&&h.jsx(Mr,{name:x,size:V,color:b})}),h.jsxs(F.Flex,{"data-flow-icon-caption":"",direction:"column",align:"center",gap:"8px",justify:"center",width:"100%",minW:0,textAlign:"center",children:[h.jsx(Kt,{nodeId:e,label:g,color:pe(((I=r==null?void 0:r.viewProps)==null?void 0:I.textColor)||s),isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0}),typeof((O=r.config)==null?void 0:O.subtitle)=="string"&&r.config.subtitle!==""&&h.jsx(F.Text,{"data-flow-node-subtitle":"",color:pe(((M=r==null?void 0:r.viewProps)==null?void 0:M.textColor)||s),opacity:.65,fontSize:"32px",fontWeight:"normal",lineHeight:1.3,width:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",title:r.config.subtitle,children:r.config.subtitle})]})]})}return h.jsxs(F.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:(q=r==null?void 0:r.viewProps)==null?void 0:q.borderRadius,bgColor:m,style:{backgroundColor:m},textTransform:"capitalize",...ln(r==null?void 0:r.viewProps,y,t,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!x&&h.jsx(F.Flex,{align:"center",py:14,mr:g?8:0,flexShrink:0,children:h.jsx(Mr,{name:x,size:(((H=r==null?void 0:r.viewProps)==null?void 0:H.fontSize)||1)*100,color:b},b)}),(g||!x)&&h.jsx(F.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:h.jsx(Kt,{nodeId:e,label:g,color:b,isEditing:n,onEditStart:o,onEditEnd:i})})]})};function Tm({onExpand:e,toggleLabel:t="Show properties",toggleDisabled:r=!1,renderCompact:n=b_,...o}){const{colorMode:i,callbacks:a}=Ie();return h.jsx(Bn,{...o,children:s=>h.jsxs(F.Box,{position:"relative",children:[h.jsx(n,{...s}),e&&s.isActive&&h.jsx(F.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:h.jsx(je,{label:t,children:h.jsx(ve,{"aria-label":t,icon:h.jsx(F.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:i==="dark"?"gray.100":"gray.800",disabled:r,onClick:u=>{var c;u.stopPropagation(),e(),(c=a.onNodeViewToggle)==null||c.call(a,o.data.id)}})})})]})})}const uy=1.55;function m_({nodeId:e,content:t,color:r}){const{callbacks:n,config:o,readOnly:i}=Ie(),a=!!o.editable&&!i,[s,u]=E.useState(!1),[c,l]=E.useState(t),[d,f]=E.useState(),p=E.useRef(null),b=E.useRef(!1),y=tl(s);E.useLayoutEffect(()=>{const g=p.current;!s||!g||(g.style.height="auto",g.style.height=`${Math.max((d==null?void 0:d.height)??0,g.scrollHeight)}px`)},[c,s,d]),E.useEffect(()=>{var g;a?s&&(b.current=!1,(g=p.current)==null||g.focus()):u(!1)},[s,a]);const m=g=>{a&&(f({width:g.offsetWidth,height:g.offsetHeight}),l(t),u(!0))},x=()=>{var g;b.current||!a||(b.current=!0,c!==t&&((g=n.onNodeContentChange)==null||g.call(n,e,c)),u(!1))};return!s||!a?h.jsx(F.Box,{"data-flow-content":"",color:r,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:uy,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:a?"text":void 0,tabIndex:a?0:void 0,onDoubleClick:g=>{g.stopPropagation(),m(g.currentTarget)},onKeyDown:g=>{a&&g.key==="Enter"&&g.target===g.currentTarget&&(g.preventDefault(),g.stopPropagation(),m(g.currentTarget))},children:h.jsx(tv.default,{options:{forceBlock:!0,wrapper:E.Fragment,disableParsingRawHTML:!0,overrides:{a:{props:{target:"_blank",rel:"noopener noreferrer"}},img:{props:{loading:"lazy",referrerPolicy:"no-referrer"}}}},children:t})}):h.jsx("div",{ref:y,style:{width:d==null?void 0:d.width,minHeight:d==null?void 0:d.height,maxWidth:"100%"},children:h.jsx(F.Textarea,{ref:p,"aria-label":"Node content",value:c,onChange:g=>l(g.target.value),onBlur:x,onKeyDown:g=>{g.stopPropagation(),!g.nativeEvent.isComposing&&(g.key==="Enter"&&(g.ctrlKey||g.metaKey)&&(g.preventDefault(),x()),g.key==="Escape"&&(b.current=!0,u(!1)))},color:r,fontFamily:"inherit",fontSize:"inherit",lineHeight:uy,overflowWrap:"anywhere",whiteSpace:"pre-wrap",rows:1,bg:"transparent",display:"block",style:{border:0,outline:"none",boxShadow:"none"},p:0,w:"100%",h:"100%",minW:0,minH:0,resize:"none"})})}const v_=(e,t,r)=>{var f,p,b,y;const n=((f=e==null?void 0:e.viewProps)==null?void 0:f.bgColor)||t,[o]=n.split("."),i=Zt(n),a=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,s=n==="transparent"||a,u=r==="dark"?"gray.200":"gray.900",c=s?"transparent":n!=null&&n.startsWith("#")?pe(n):pe(i.bgColor),l=pe(((b=e==null?void 0:e.viewProps)==null?void 0:b.textColor)||(s?u:i.textColor)),d=pe(((y=e==null?void 0:e.viewProps)==null?void 0:y.borderColor)||(a?n==="transparent"?t:n:i.borderColor));return{...i,bgColor:s?"transparent":i.bgColor,highlightColor:s?"transparent":i.highlightColor,isTransparent:s,propertyColor:s?u:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:c,hextextColor:l,hexborderColor:d}},x_=(e,t=350)=>`${String(e).substring(0,t)}${String(e).length>t?"...":""}`,w_=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,Om=600,C_=3,__=e=>{const t=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(t*28+30,200)};function S_({headerTitle:e,hasContent:t,data:r,icon:n,colors:o,hasConfig:i,id:a,isActive:s,isEditing:u,onEditStart:c,onEditEnd:l,props:d,objVisible:f,setObjVisible:p,onShowNativeIcon:b}){var g,w;const{callbacks:y}=Ie(),m=d.onShowIcon??b,x=m?"Show icon":f?"Show content":"Show properties";return h.jsx(h.Fragment,{children:(e||t||((g=r.config)==null?void 0:g.form)||s&&b)&&h.jsxs(F.Flex,{justify:"flex-start",direction:"row",p:Object.entries(r.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&&!t?"transparent":o.hexborderColor,children:[!!n&&h.jsx(F.Flex,{mr:6,alignItems:"center",flexShrink:0,children:h.jsx(Mr,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),h.jsx(Kt,{nodeId:a,label:w_(e),color:((w=r==null?void 0:r.viewProps)==null?void 0:w.textColor)||o.propertyColor,isEditing:u,onEditStart:c,onEditEnd:l}),s&&(t||m)&&h.jsx(F.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:h.jsx(je,{label:x,children:h.jsx(ve,{"aria-label":x,icon:h.jsx(F.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:v=>{var _;v.stopPropagation(),m?m():p(!f),(_=y.onNodeViewToggle)==null||_.call(y,a)}})})})]})})}function j_({data:e,resourcePorts:t,inspecting:r,form:n,inspectionPorts:o,extraPorts:i,colors:a,direction:s,uniformKeyWidth:u}){const{edgeById:c}=Wr(),l=new Set;for(const{data:d}of c.values())d.source===e.id&&d.sourceProperty!==void 0&&l.add(`source:${d.sourceProperty}`),d.target===e.id&&d.targetProperty!==void 0&&l.add(`target:${d.targetProperty}`);return h.jsx(F.Box,{children:Object.entries(e.description||{}).map(([d,f],p)=>{var I,O,M;const b=t&&Object.keys(t).find(q=>q.slice(q.indexOf(":")+1)===d),y=r&&((I=n==null?void 0:n.type.ports)==null?void 0:I[d]),m=b??(y?`${y.kind}:${d}`:d),x=o.find(q=>q.id===m),g=b?"source":x==null?void 0:x.role,w=l.has(`source:${m}`),v=l.has(`target:${m}`),_=i.some(q=>q.id===d),C=f===""&&(_||(g?l.has(`${g}:${m}`):w||v)),S=g??(w!==v?w?"source":"target":void 0),T=(x==null?void 0:x.side)??(S?S==="source"!=(s==="RL")?"right":"left":void 0),k=C&&T==="right"?"right":"left",j=_?d.replace(/^(template|input|output|config|error):/,""):d,P=Er(a.wordBeforeDot)[typeof f],R=Er(a.wordBeforeDot).property;return h.jsxs(F.Box,{"data-flow-property":b&&(s==="TB"||s==="BT")?void 0:m,"data-flow-port-role":g,"data-flow-inspection-row":r?"":void 0,children:[h.jsxs(F.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[h.jsx(F.Flex,{justifyContent:"start",align:"center",background:a.highlightColor,width:C?"100%":`${u}px`,minWidth:`${u}px`,borderRightColor:a.hexborderColor,borderRightWidth:C?0:1,children:h.jsx(F.Text,{py:5,px:10,w:"100%",textAlign:k,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((O=e==null?void 0:e.viewProps)==null?void 0:O.textColor)||(a.isTransparent?a.hextextColor:R),children:j})}),!C&&h.jsx(F.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:a.hexbgColor,w:Om,maxH:200,children:h.jsx(F.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:((M=e==null?void 0:e.viewProps)==null?void 0:M.textColor)||(a.isTransparent?a.hextextColor:P),fontWeight:400,children:x_(f)})})]}),p!==Object.entries(e.description||{}).length-1&&h.jsx(F.Box,{borderTopWidth:1,my:0,borderColor:a.hexborderColor})]},d)})})}function E_(e){var w,v,_;const{themeColor:t,colorMode:r,direction:n}=Ie(),o=Dn(),i=o.getNodeViewMode(e.data.id)==="properties",a=C=>o.setNodeViewMode(e.data.id,C?"properties":"default"),s=!!e.onShowIcon||i||typeof((w=e.data.config)==null?void 0:w.content)!="string",{bindings:u,data:c,schema:l}=E.useContext(kr),d=(v=u==null?void 0:u[e.data.id])==null?void 0:v.portResources,f=u?Jt(u,e.data.id,l):c&&l?pt(c,e.data.id,l):void 0,p=f&&xe(c,"address"in f?f.address:e.data.id),b=p&&typeof p=="object"&&f?Object.fromEntries(Object.keys(f.type.properties).filter(C=>{var S;return Object.prototype.hasOwnProperty.call(p,C)&&vn((S=f.fields[C])==null?void 0:S.$visibleWhen,c)}).map(C=>[C,p[C]!==null&&typeof p[C]=="object"?JSON.stringify(p[C],null,2):p[C]===null?"null":p[C]])):{},y=d?Object.fromEntries(Object.entries(d).map(([C,S])=>{var T;return[C.slice(C.indexOf(":")+1),((T=xe(c,S))==null?void 0:T.name)??S.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:b,m=s&&!d?((_=e.data.config)==null?void 0:_.ports)??[]:[],x=m.filter(C=>!Object.prototype.hasOwnProperty.call(y,C.id)&&!Object.entries((f==null?void 0:f.type.ports)??{}).some(([S,T])=>`${T.kind}:${S}`===C.id&&Object.prototype.hasOwnProperty.call(y,S))),g={...y,...Object.fromEntries(x.map(C=>[C.id,""]))};return{themeColor:t,colorMode:r,direction:n,objVisible:i,setObjVisible:a,inspecting:s,resourcePorts:d,form:f,description:g,inspectionPorts:m,extraPorts:x}}const nl=e=>{var m,x,g;const{themeColor:t,colorMode:r,direction:n,objVisible:o,setObjVisible:i,inspecting:a,resourcePorts:s,form:u,description:c,inspectionPorts:l,extraPorts:d}=E_(e),f=Dn(),p=f.getNodeViewMode(e.data.id)==="icon-label",y=!e.onShowIcon&&!((m=e.data.config)!=null&&m.parentContainer)&&typeof((x=e.data.config)==null?void 0:x.content)!="string"?()=>f.setNodeViewMode(e.data.id,"icon-label"):void 0;return!e.onShowIcon&&p?h.jsx(Tm,{...e,data:{...e.data,label:e.data.label??e.data.headerTitle,config:{...e.data.config,labelBelow:!0,icon:((g=e.data.config)==null?void 0:g.icon)||"PiBracketsCurly"}},onExpand:()=>f.restoreNodeView(e.data.id)}):h.jsx(Bn,{...e,data:{...e.data,description:c},children:({id:w,data:v,isActive:_,isEditing:C,onEditStart:S,onEditEnd:T})=>{var V,re,ce,le,be,K;const k=v_(v,t,r),j=v.label??v.headerTitle,P=Object.entries(v.description||{}).length>0,R=__(v.description),I=(re=(V=e.data)==null?void 0:V.config)==null?void 0:re.icon,O=(le=(ce=e.data)==null?void 0:ce.config)==null?void 0:le.content,M=typeof O=="string"&&!e.onShowIcon,q=((be=v==null?void 0:v.viewProps)==null?void 0:be.borderRadius)??"53px",H=ln(v==null?void 0:v.viewProps,k.hexborderColor,_,C_);return h.jsx(F.Flex,{justifyContent:"space-between",...v==null?void 0:v.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:q,overflow:"hidden",alignItems:"center",style:{backgroundColor:k.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:"100%",minW:M||e.onShowIcon?R+Om+H.borderWidth*2:void 0,...H,children:h.jsxs(F.Flex,{width:"100%",direction:"column",borderRadius:q,borderColor:k.hexborderColor,borderWidth:0,overflow:"hidden",children:[h.jsx(S_,{headerTitle:j,hasContent:M,data:v,icon:I,colors:k,hasConfig:P,id:w,isActive:_,isEditing:C,onEditStart:S,onEditEnd:T,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:y}),M&&!o?h.jsx(F.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:k.highlightColor,p:12,fontSize:"5xl",lineHeight:"normal",children:h.jsx(m_,{nodeId:w,content:O,color:((K=v==null?void 0:v.viewProps)==null?void 0:K.textColor)||k.hextextColor})}):h.jsx(j_,{data:v,resourcePorts:s,inspecting:a,form:u,inspectionPorts:l,extraPorts:d,colors:k,direction:n,uniformKeyWidth:R})]})})}})};nl.displayName="NodeJsonObjectView";const Im=e=>{var c,l,d,f,p,b,y;const t=Dn(),r=t.getNodeViewMode(e.data.id)==="properties",n=m=>t.setNodeViewMode(e.data.id,m?"properties":"default"),{callbacks:o,readOnly:i}=Ie(),a=(l=(c=e.data)==null?void 0:c.config)==null?void 0:l.parentContainer,s=a?"Show parent":"Show properties",u=a||((f=(d=e.data)==null?void 0:d.config)==null?void 0:f.form)||((y=(b=(p=e.data)==null?void 0:p.config)==null?void 0:b.ports)==null?void 0:y.length);return!a&&u&&r?h.jsx(nl,{...e,onShowIcon:()=>n(!1)}):h.jsx(Tm,{...e,toggleLabel:s,toggleDisabled:a&&i,onExpand:u?()=>{var m;a?(m=o.onNodeCollapse)==null||m.call(o,e.data.id,!1):n(!0)}:void 0})},Mm=e=>h.jsx(Im,{...e,renderCompact:y_}),qm=e=>h.jsx(Im,{...e}),Nm=e=>h.jsx(Bn,{...e,children:()=>null});Mm.displayName="text";qm.displayName="arrayView";Nm.displayName="ParentContainerView";const R_={objectView:nl,arrayView:qm,text:Mm,parentContainer:Nm},k_=({children:e,pattern:t="dot",backgroundColor:r})=>{const{colorMode:n}=Ie(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",a=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return t==="none"?h.jsx(F.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:r,children:e}):h.jsxs(F.Box,{"data-flow-background":t,position:"relative",width:"100%",height:"100%",padding:0,bg:r,children:[h.jsx(F.Box,{position:"absolute",top:0,left:0,right:0,bottom:0,width:"100%",height:"100%",zIndex:0,pointerEvents:"none",style:{backgroundImage:t==="dot"?`radial-gradient(var(${i}) 8%, transparent 8%)`:t==="steel"?`repeating-linear-gradient(45deg, var(${a}) 0, var(${a}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${a}) 1px, transparent 1px), linear-gradient(90deg, var(${a}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),h.jsx(F.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},P_=.4,Hr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},A_=({nodes:e,edges:t})=>{const{themeColor:r,spacing:n,edgeRadius:o,backgroundVariant:i,setBackgroundSelected:a,edgeColor:s,direction:u,nodeAlignment:c,edgeMode:l,compactPropertyLayout:d,workflowContract:f,parentNodeStyle:p,engineRef:b,callbacks:y,config:m,selectedNodeIds:x,setSelectedNodeIds:g,selectedEdgeId:w,setSelectedEdgeId:v,setIsPerformanceMode:_,isZoomMode:C,setIsZoomMode:S,isMultiSelectMode:T,setIsMultiSelectMode:k,isDragMode:j,setIsDragMode:P,isEdgeHandlesEnabled:R,isArrayNodeMode:I}=Ie(),O=E.useRef(null),[M,q]=E.useState(null),H=e.length>200;E.useEffect(()=>{_(H)},[H,_]);const{edgeSep:V,rankSep:re,spacingFactor:ce}=E.useMemo(()=>{const Y=h0(e.length),D=n<1?.3+.7*n:.5+.5*n;return{edgeSep:Y.edgeSep*D,rankSep:Y.rankSep*D,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n]),{bgColor:le}=Zt(r),{canvas:be,borderSecondary:K,colorText:N}=Ve(),B=i==="transparent"?"transparent":m.backgroundColor||be,W=E.useCallback(Y=>{if(Y!=null&&Y.includes("gray"))return"whitesmoke";if(!Y)return pe(r);switch(Y){case"dark":return pe(B);case"light":return pe(K);default:return pe(Y)}},[r,B,K]),z=m.colorMode==="dark",X=E.useMemo(()=>W(z?le:"light"),[z,le,W]),se=s?W(s):X,Q=E.useMemo(()=>m.initialViewport||{pan:{x:0,y:0},zoom:.01},[]),G=u==="C"?"LR":u,J=E.useCallback(Y=>{const D={...p,...Y};return{...D,bgColor:D.bgColor||r,bgOpacity:D.outline?0:D.bgOpacity??P_}},[p,r]),te=E.useMemo(()=>{var D;const Y=new Map;for(const ee of e)(D=ee.data)!=null&&D.id&&Y.set(ee.data.id,ee);return Y},[e]),de=E.useMemo(()=>{var D;const Y=new Map;for(const ee of t)(D=ee.data)!=null&&D.id&&Y.set(ee.data.id,ee);return Y},[t]),fe=E.useCallback(Y=>{var _e;const D=(_e=te.get(Y))==null?void 0:_e.data,ee=J(D==null?void 0:D.viewProps),Ce=pe(ee.bgColor);return{animated:!!(D!=null&&D.isNodeAnimated)&&!H,animationVariant:D==null?void 0:D.nodeAnimationVariant,animationColor:pe(ee.borderColor||r),bgColor:ee.outline?"transparent":Ce,bgOpacity:ee.bgOpacity,borderColor:ee.borderColor?pe(ee.borderColor):ee.outline&&ee.bgColor==="transparent"?pe(r):Ce,borderWidth:Ut(ee.borderWidth,Hr.borderWidth),borderStyle:ee.borderStyle??Hr.borderStyle,borderRadius:ee.borderRadius??Hr.borderRadius,textColor:ee.textColor?pe(ee.textColor):ee.outline||ee.bgColor==="transparent"?pe(N):Ce,fontSize:ee.fontSize??Hr.fontSize,labelPosition:ee.labelPosition??Hr.labelPosition,labelMargin:Hr.labelMargin,labelBg:cl(W("dark"),Ce,ee.bgOpacity)??W("dark"),padding:ee.padding??Hr.padding}},[J,te,N,r,H,W]),Ee=E.useMemo(()=>{var ee,Ce;const Y=new Map;for(const _e of t){const Se=(ee=_e.data)==null?void 0:ee.source,Ge=(Ce=_e.data)==null?void 0:Ce.target;if(!Se||!Ge||Se===Ge)continue;const Le=Se<Ge?`${Se}|${Ge}`:`${Ge}|${Se}`,ke=Y.get(Le);ke?ke.push({id:_e.data.id,source:Se}):Y.set(Le,[{id:_e.data.id,source:Se}])}const D=new Map;for(const[_e,Se]of Y){if(Se.length<2)continue;const Ge=_e.split("|")[0],Le=Math.min(20,70/Se.length);Se.forEach(({id:ke,source:Me},gr)=>{const Ye=50+(gr-(Se.length-1)/2)*Le;D.set(ke,(Me===Ge?Ye:100-Ye)/100)})}return D},[t]),ge=E.useMemo(()=>{const Y=W("dark");return t.filter(D=>{var ee;return((ee=D.data)==null?void 0:ee.id)&&D.data.source&&D.data.target}).map(({data:D})=>{var Se,Ge,Le,ke,Me,gr;let ee=Y;const Ce=(Ge=(Se=te.get(D.source))==null?void 0:Se.data)==null?void 0:Ge.parent,_e=(ke=(Le=te.get(D.target))==null?void 0:Le.data)==null?void 0:ke.parent;if(Ce&&Ce===_e){const Ye=J((gr=(Me=te.get(Ce))==null?void 0:Me.data)==null?void 0:gr.viewProps),yr=cl(Y,pe(Ye.bgColor),Ye.bgOpacity);yr&&(ee=yr)}return{id:D.id,data:D,type:D.type??m.edgeType??"rounded-orthogonal",source:D.source,target:D.target,sourceProperty:D.sourceProperty,targetProperty:D.targetProperty,label:D.label,validationIssue:(l==="auto"||l==="properties")&&(D.sourceProperty!==void 0||D.targetProperty!==void 0)&&f?Iu(f,D):void 0,color:D.color?pe(D.color):se,labelBg:ee,dashed:!!D.isEdgeDashed,animated:!!D.isEdgeAnimated,inverted:!!D.isInverted,turn:Ee.get(D.id)??.5}})},[t,se,Ee,m.edgeType,l,f,te,J,W]),We=E.useMemo(()=>{var D;const Y=new Set;for(const ee of e)(D=ee.data)!=null&&D.parent&&Y.add(ee.data.parent);return Y},[e]),me=E.useMemo(()=>{var D;const Y=new Map;for(const ee of t)(D=ee.data)!=null&&D.source&&!Y.has(ee.data.source)&&Y.set(ee.data.source,ee.data);return Y},[t]),Te=E.useMemo(()=>{const Y={...R_,...m.customViews};return e.filter(D=>{var ee;return(ee=D.data)==null?void 0:ee.id}).map(D=>{var Ge,Le,ke,Me;const ee=We.has(D.data.id)&&!D.data.parent,Ce=ee?D.data.label??D.data.headerTitle??"Container":void 0,_e=ee?Y.parentContainer:Y[D.data.type]||Y.text,Se=me.get(D.data.id);return{id:D.data.id,collapsed:(Ge=D.data.config)==null?void 0:Ge.collapsed,parent:D.data.parent,label:Ce,animated:!!D.data.isNodeAnimated,animationVariant:D.data.nodeAnimationVariant,hasCollapseControl:((Le=D.data.config)==null?void 0:Le.collapsed)!==void 0,animationColor:pe(((ke=D.data.viewProps)==null?void 0:ke.borderColor)||r),animationWidth:Ut((Me=D.data.viewProps)==null?void 0:Me.borderWidth,8),element:E.createElement(_e,{...D,isInverted:Se==null?void 0:Se.isInverted,isParent:ee,key:`${D.data.id}-${r}`})}})},[e,We,me,r,m.customViews]),er=E.useMemo(()=>H?300:e.length>50?150:e.length>20?100:50,[e.length,H]),De=E.useRef(m);De.current=m;const Ne=E.useRef(C);Ne.current=C;const He=E.useRef(I);He.current=I;const rr=E.useRef(x);rr.current=x;const ze=E.useRef(w);ze.current=w;const xr=E.useRef(T);xr.current=T;const Ze=E.useRef(te);Ze.current=te;const pr=E.useRef(de);pr.current=de;const dr=E.useRef(new Map);E.useEffect(()=>{var ee,Ce;const Y=new Map([...de].filter(([,_e])=>te.has(_e.data.source)&&te.has(_e.data.target))),D=dr.current;dr.current=Y;for(const[_e,Se]of D)Y.has(_e)||(ze.current===_e&&(v(null),(ee=y.onEdgeDeselect)==null||ee.call(y)),(Ce=y.onEdgeRemove)==null||Ce.call(y,_e,Se.data))},[de,te,y,v]),E.useEffect(()=>{const Y=O.current;if(!M||!Y)return;let D=null,ee=null,Ce=0,_e=0,Se=0,Ge=0,Le=0;const ke=Me=>{if(De.current.readOnly)return;Me.preventDefault(),Me.stopPropagation(),Ne.current||Me.metaKey||Me.ctrlKey?(Se+=Me.deltaY,Ge=Me.clientX,Le=Me.clientY,ee===null&&(ee=requestAnimationFrame(()=>{ee=null;const Ye=De.current,yr=M.zoom(),Oe=Se;Se=0;let wr=yr-Oe*.05/100;wr=Math.max(Ye.minZoom??.01,Math.min(Ye.maxZoom??1.5,wr));const $r=Y.getBoundingClientRect();M.zoomAt(wr,{x:Ge-$r.left,y:Le-$r.top})}))):(Ce+=Me.deltaX,_e+=Me.deltaY,D===null&&(D=requestAnimationFrame(()=>{D=null;const Ye=M.pan(),yr=M.zoom(),Oe=.35,wr=Ce,$r=_e;Ce=0,_e=0,M.pan({x:Ye.x+-wr*Oe/yr,y:Ye.y+-$r*Oe/yr})})))};return Y.addEventListener("wheel",ke,{passive:!1}),()=>{Y.removeEventListener("wheel",ke),D!==null&&cancelAnimationFrame(D),ee!==null&&cancelAnimationFrame(ee)}},[M]),E.useEffect(()=>{if(m.disableKeyboardShortcuts)return;const Y=D=>{var Ce,_e,Se,Ge;if(De.current.readOnly)return;const ee=D.target;if(!(ee.tagName==="INPUT"||ee.tagName==="TEXTAREA"||ee.isContentEditable)){if((D.key==="z"||D.key==="Z")&&S(!Ne.current),(D.key==="m"||D.key==="M")&&k(!T),(D.key==="d"||D.key==="D")&&P(!j),(D.key==="Delete"||D.key==="Backspace")&&ze.current){D.preventDefault();const Le=ze.current;(_e=y.onEdgeDelete)==null||_e.call(y,Le,((Ce=pr.current.get(Le))==null?void 0:Ce.data)??{id:Le}),v(null);return}if((D.key==="Delete"||D.key==="Backspace")&&rr.current.length>0){D.preventDefault();const Le=rr.current.filter(ke=>ke!=="root");if(Le.length===0)return;for(const ke of Le){const Me=(Se=Ze.current.get(ke))==null?void 0:Se.data;(Ge=y.onNodeDelete)==null||Ge.call(y,ke,Me||{})}g([])}}};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[T,j,S,k,P,m.disableKeyboardShortcuts,y,g,v]);const jr=E.useCallback(Y=>{var D;b.current=Y,q(Y),(D=y.onInit)==null||D.call(y,Y)},[b,y]),we=E.useCallback(Y=>{var D;return(D=y.onViewportChange)==null?void 0:D.call(y,Y)},[y]),or=E.useCallback(Y=>{var ee,Ce,_e;const D=((ee=pr.current.get(Y))==null?void 0:ee.data)??{id:Y};if(ze.current===Y&&xr.current){v(null),(Ce=y.onEdgeDeselect)==null||Ce.call(y);return}rr.current.length&&g([]),v(Y),(_e=y.onEdgeSelect)==null||_e.call(y,Y,D)},[y,v,g]),ar=E.useCallback(()=>{var Y,D,ee;a(!0),(Y=y.onBackgroundClick)==null||Y.call(y),rr.current.length&&(g([]),(D=y.onNodeDeselect)==null||D.call(y)),ze.current&&(v(null),(ee=y.onEdgeDeselect)==null||ee.call(y))},[y,g,v,a]),xt=E.useCallback(Y=>{var Ce,_e;const D=rr.current,ee=Y.filter(Se=>!D.includes(Se));if(ee.length){g([...D,...ee]);for(const Se of ee)(_e=y.onNodeSelect)==null||_e.call(y,Se,((Ce=Ze.current.get(Se))==null?void 0:Ce.data)??{id:Se})}},[y,g]),ne=E.useCallback((Y,D)=>{var ee,Ce;g([Y]),(Ce=y.onNodeSelect)==null||Ce.call(y,Y,((ee=Ze.current.get(Y))==null?void 0:ee.data)??{id:Y},D)},[y,g]),Fe=E.useCallback((Y,D,ee)=>{var Ce;return(Ce=y.onEdgeCreate)==null?void 0:Ce.call(y,Y,D,ee)},[y]),Je=E.useCallback((Y,D,ee,Ce=!1)=>{var _e,Se;l==="properties"&&((_e=y.onNodeCreateRequest)==null?void 0:_e.call(y,{sourceNodeId:Y,position:D,sourceProperty:ee,reverse:Ce}))===!0||ee!==void 0||Ce||(Se=y.onNodeCreate)==null||Se.call(y,{type:"text",sourceNodeId:Y,position:D,isArrayMode:He.current})},[y,l]),$e=!m.readOnly&&R&&m.edgeHandles!==!1,Xe=i==="transparent"?"none":i;return h.jsx(k_,{pattern:Xe,backgroundColor:B,children:h.jsx(F.Box,{ref:O,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:h.jsx(f_,{nodes:Te,edges:ge,direction:G,nodeAlignment:c,onContainerCollapse:Y=>{var D,ee;(D=y.onNodeCollapse)==null||D.call(y,Y,!0),(ee=y.onNodeViewToggle)==null||ee.call(y,Y)},selectedNodeIds:x,edgeMode:l,compactPropertyLayout:d,edgeType:m.edgeType,edgeRadius:o,customEdgeTypes:m.customEdgeTypes,rankSep:re,edgeSep:V,spacingFactor:ce,compactSpacingScale:n,layoutDebounce:er,isPerformanceMode:H,minZoom:m.minZoom??.01,maxZoom:m.maxZoom??1.5,initialViewport:Q,fitOnInit:!m.initialViewport,readOnly:!!m.readOnly,containerStyle:fe,lineColor:se,drawMode:$e,drawHandles:!m.readOnly&&m.edgeHandles!==!1,dragMode:j,multiSelect:!!T,onInit:jr,onLayoutComplete:y.onLayoutComplete,animateViewport:m.animateViewport,onViewportChange:we,onBackgroundTap:ar,onBoxSelect:xt,onEdgeSelect:or,onContainerSelect:ne,onEdgeDraw:Fe,onDrawIntoSpace:Je})})})},$m=E.memo(A_),T_=".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 ly=!1;function O_(){if(ly||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=T_+f0+l0+".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}',ly=!0}function I_({loading:e=!1,loader:t,...r}){var u,c;const[n,o]=E.useState(null),i=E.useMemo(()=>!!(n!=null&&n.json)&&!!r.json&&s0(n.json,r.json),[n==null?void 0:n.json,r.json]),a=n===null||n.json!==r.json&&!i,s=e||a;return E.useEffect(()=>{!e&&i&&(n==null?void 0:n.json)!==r.json&&o(r)},[e,i,n==null?void 0:n.json,r.json]),E.useEffect(()=>{if(e||!a)return;let l;const d=requestAnimationFrame(()=>{l=requestAnimationFrame(()=>o(r))});return()=>{cancelAnimationFrame(d),l!==void 0&&cancelAnimationFrame(l)}},[e,a,r.json]),h.jsxs(F.Box,{className:r.className,style:r.style,width:"100%",height:"100%",position:"relative","aria-busy":s,children:[h.jsx("div",{style:{width:"100%",height:"100%"},ref:l=>{s?l==null||l.setAttribute("inert",""):l==null||l.removeAttribute("inert")},children:n&&h.jsx(M_,{...a?n:r,className:void 0,style:void 0})}),s&&h.jsx(F.Box,{"data-flow-loader":"",role:"status","aria-label":"Loading diagram",position:"absolute",inset:0,zIndex:1e3,display:"grid",placeItems:"center",background:((u=r.config)==null?void 0:u.colorMode)==="dark"?"gray.800":"gray.100",color:((c=r.config)==null?void 0:c.colorMode)==="dark"?"whiteAlpha.800":"blackAlpha.800",children:t===void 0?h.jsx("span",{children:"Loading diagram..."}):t})]})}function M_({title:e="untitled",json:t,forms:r,nodes:n,edges:o,config:i={},callbacks:a={},className:s,style:u,showBottomBar:c=!0,children:l}){O_();const[d,f]=E.useState(),p=i.formSchema??d,b=E.useMemo(()=>t&&r?Qy(t,r.state):t,[t,r==null?void 0:r.state]),y=i.direction==="C",m=E.useMemo(()=>{let k,j;return P=>(j=k&&j?c0(k,P,j)??mu(P,{title:e,isCenter:y}):mu(P,{title:e,isCenter:y}),k=P,j)},[e,y]),x=E.useMemo(()=>b?m(b):null,[b,m]),g=E.useMemo(()=>r!=null&&r.structured&&p?r0(r.state,r.bindings,p,(x==null?void 0:x.nodes)??n??[]):void 0,[r==null?void 0:r.structured,r==null?void 0:r.state,r==null?void 0:r.bindings,p,x,n]),w=(g==null?void 0:g.schema)??p,v=(g==null?void 0:g.bindings)??(r==null?void 0:r.bindings),_=E.useMemo(()=>[...(x==null?void 0:x.nodes)??n??[],...(g==null?void 0:g.nodes)??[]].map(j=>{var H,V,re,ce;const P=t?(H=xe(t,j.data.id))==null?void 0:H.$view:(V=j.data.config)==null?void 0:V.typeView,R=P&&Ft.includes(P)?P:void 0,I=R?R==="icon-label":(re=j.data.config)==null?void 0:re.labelBelow,O=R==="object"?"objectView":R==="text"?"text":I?"arrayView":j.data.type,M=w&&(r?Jt(v,j.data.id,w):t&&pt(t,j.data.id,w)),q=(((ce=j.data.config)==null?void 0:ce.ports)??[]).map(le=>({...le}));if(g&&M){const le=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[be,K]of Object.entries(M.type.ports??{})){const N=`${K.kind}:${be}`;q.some(B=>B.id===N)||q.push({id:N,role:K.kind==="input"||K.kind==="config"?"target":"source",side:le[K.kind],...K.kind==="config"?{placement:"config"}:{}})}for(const be of q){const K=q.filter(N=>N.side===be.side);be.position=(K.indexOf(be)+1)/(K.length+1)}}return M||I||R?{...j,data:{...j.data,type:O,...r?{description:Object.fromEntries(Object.entries(j.data.description??{}).filter(([le])=>!le.startsWith("$")&&!(g!=null&&g.slots.has(Et(j.data.id,le)))))}:{},config:{...j.data.config,...g&&M?{ports:q}:{},...M?{form:!0}:{},...R?{typeView:R,labelBelow:!!I}:I?{labelBelow:!0}:{}}}}:j}),[x,n,t,w,v,g,i.direction]),C=[...(x==null?void 0:x.edges)??o??[],...(g==null?void 0:g.edges)??[]],S=E.useMemo(()=>{const k=t&&x?vb(t,x.edges,a,a.onJsonChange,p):{...a};if(g){const j=new Set([...g.nodes.map(P=>P.data.id),...g.edges.map(P=>P.data.id)]);for(const P of Object.keys(k)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(P))continue;const R=k[P];k[P]=(I,...O)=>{if(!j.has(I))return R==null?void 0:R(I,...O)}}}return k},[t,x,a,p,g]),T=E.useMemo(()=>{if(!r)return S;let k=r.state;const j=R=>{if(i.readOnly||i.editable===!1)return;const I=r.onStateChange??r.onChange;if(!I)return;const O=Kx(k,R,a.onFormChange);O!==k&&(k=O,I(O,{...R,data:O}))},P=(R,I,O)=>{var q;const M=t&&((q=xe(t,R))==null?void 0:q[I]);return!M||typeof M.$state!="string"?!1:(j({address:M.$state,nodeAddress:R,previousValue:xe(k,M.$state),value:O,data:k}),!0)};return{...S,onFormChange:j,onNodeCreateRequest:R=>{var M,q;const I=(M=R.sourceProperty)!=null&&M.startsWith("config:")?R.sourceProperty.slice(7):void 0,O=I!==void 0&&(g==null?void 0:g.slots.get(Et(R.sourceNodeId,I)));return O?(O.present||j({data:k,nodeAddress:O.address.split(".").slice(0,-1).join("."),address:O.address,value:Rt(O.type),previousValue:void 0}),!0):((q=S.onNodeCreateRequest)==null?void 0:q.call(S,R))??!1},onNodeDelete:(R,I)=>{var re,ce;if(!(g!=null&&g.nodes.some(le=>le.data.id===R)))return(re=S.onNodeDelete)==null?void 0:re.call(S,R,I);const O=g&&[...g.slots.values()].find(le=>le.nodeId===R);if(!O)return(ce=S.onNodeDelete)==null?void 0:ce.call(S,R,I);const M=O.address.split("."),q=M.pop(),H=M.join("."),V=xe(k,H);j(Array.isArray(V)?{data:k,nodeAddress:H,address:H,previousValue:V,value:V.filter((le,be)=>String(be)!==q)}:{data:k,nodeAddress:H,address:O.address,previousValue:xe(k,O.address),value:void 0})},onEdgeCreate:(R,I,O)=>{var H,V;const M=((H=O==null?void 0:O.targetProperty)==null?void 0:H.startsWith("config:"))&&(g==null?void 0:g.slots.get(Et(I,O.targetProperty.slice(7)))),q=g==null?void 0:g.containers.get(R);if(M&&q&&(O==null?void 0:O.sourceProperty)==="output:resource"){const re=e0(k,q,M);re!==void 0&&j({data:k,nodeAddress:M.address.split(".").slice(0,-1).join("."),address:M.address,previousValue:xe(k,M.address),value:re});return}M||g!=null&&g.nodes.some(re=>re.data.id===R||re.data.id===I)||(V=S.onEdgeCreate)==null||V.call(S,R,I,O)},onEdgeDelete:(R,I)=>{var ce;const O=g==null?void 0:g.edges.find(le=>le.data.id===R);if(!O)return(ce=S.onEdgeDelete)==null?void 0:ce.call(S,R,I);const M=g.slots.get(Et(O.data.target,O.data.targetProperty.slice(7))),q=M.address.split("."),H=q.pop(),V=q.join("."),re=xe(k,V);j(Array.isArray(re)?{data:k,nodeAddress:V,address:V,previousValue:re,value:re.filter((le,be)=>String(be)!==H)}:{data:k,nodeAddress:V,address:M.address,previousValue:xe(k,M.address),value:void 0})},onNodeContentChange:(R,I)=>{var O,M;P(R,"$content",I)?(O=a.onNodeContentChange)==null||O.call(a,R,I):(M=S.onNodeContentChange)==null||M.call(S,R,I)},onNodeLabelChange:(R,I)=>{var O,M;P(R,"$label",I)?(O=a.onNodeLabelChange)==null||O.call(a,R,I):(M=S.onNodeLabelChange)==null||M.call(S,R,I)}}},[S,r,t,a,g,i.readOnly,i.editable]);return h.jsx(kr.Provider,{value:{data:(r==null?void 0:r.state)??t,viewData:t,bindings:v,references:r==null?void 0:r.references,structured:g,renderForm:r==null?void 0:r.renderForm,editable:r?!!(r.onStateChange??r.onChange):!!a.onJsonChange,schema:w,setSchema:k=>{var j;f(k),(j=a.onFormSchemaChange)==null||j.call(a,k)},callbacks:T},children:h.jsx(py,{config:g?{...i,formSchema:w}:i,callbacks:T,nodes:_,edges:C,children:h.jsxs(F.Box,{className:s,"data-flow-diagram":"",style:u,width:"100%",height:"100%",position:"relative",overflow:"hidden",css:{"& input, & textarea, & select":{outline:"none !important",boxShadow:"none !important"}},children:[h.jsx($m,{nodes:_,edges:C}),c&&h.jsx(yb,{}),l]})})})}function sn(e){let t="",r=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},a=()=>{if(i(),!(r||!t.trim()))try{const u=e.parse(e.repair(t)),c=JSON.stringify(u);if(c===n)return;e.preview(u),n=c}catch{}},s=u=>{if(!r){if(new TextEncoder().encode(u).byteLength>(e.maxBytes??1024*1024))throw r=!0,i(),new Error("JSON stream exceeds the size limit.");t=u,o||(o=setTimeout(a,e.intervalMs??150))}};return{snapshot:s,append(u){s(t+u)},flush:a,finish(){if(r)throw new Error("JSON stream is closed.");r=!0,i();const u=e.parse(t);return e.commit(u),u},cancel(){r=!0,i(),t=""}}}function q_(e){const{source:t}=e,r=e.tickMs??50,n=e.durationMs??8e3;if(!Number.isFinite(r)||r<=0||!Number.isFinite(n)||n<=0)throw new Error("Playback timing must be positive.");if(new TextEncoder().encode(t).byteLength>(e.maxBytes??1024*1024))throw new Error("JSON stream exceeds the size limit.");e.parse(t);let o=sn(e),i=0,a=!1,s=!1,u;const c=Math.max(1,Math.ceil(t.length*r/n)),l=()=>e.onChange({position:i,total:t.length,playing:a}),d=()=>{clearTimeout(u),u=void 0},f=(y=!1)=>{o.snapshot(t.slice(0,i)),i===t.length?(a=!1,d(),o.finish()):y&&o.flush()},p=y=>{a=!1,d(),o.cancel(),l(),e.onError(y)},b=()=>{if(u=void 0,!(!a||s)){i=Math.min(t.length,i+c);try{f()}catch(y){p(y);return}l(),a&&(u=setTimeout(b,r))}};return{play(){s||a||(i===t.length&&(o.cancel(),o=sn(e),i=0),a=!0,l(),u=setTimeout(b,r))},pause(){s||(a=!1,d(),o.flush(),l())},seek(y){if(!s){if(!Number.isFinite(y))throw new Error("Playback position must be finite.");d(),i=Math.max(0,Math.min(t.length,Math.round(y))),o.cancel(),o=sn(e);try{f(!0)}catch(m){p(m);return}l(),a&&(u=setTimeout(b,r))}},dispose(){s=!0,a=!1,d(),o.cancel()}}}function N_(e,t){const r=(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,a)=>r(i,o[a])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,a])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i.startsWith("$")&&i!=="$")return JSON.stringify(a)===JSON.stringify(o[i])?[[i,a]]:[];const s=r(a,o[i]);return s===void 0?[]:[[i,s]]}))};return r(e,t)??{}}function $_(e){return _u(JSON.parse(e))}function _u(e){if(!e||typeof e!="object")throw new Error("Expected a JSON object or array.");const t=new Set,r=n=>{if(!(n===null||typeof n=="string"||typeof n=="boolean")&&!(typeof n=="number"&&Number.isFinite(n))){if(!n||typeof n!="object"||t.has(n)||!Array.isArray(n)&&![Object.prototype,null].includes(Object.getPrototypeOf(n)))throw new Error("Document must contain only finite, acyclic JSON values.");t.add(n);for(const[o,i]of Object.entries(n)){if(["__proto__","prototype","constructor"].includes(o))throw new Error(`Unsafe document key: ${o}`);r(i)}t.delete(n)}};return r(e),structuredClone(e)}function L_(e){return{replaceJson(t){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const r=_u(t);return e.onJsonChange(r,{type:"documentReplace",address:"root"}),r},replaceState(t){if(e.readOnly||!e.onStateChange)throw new Error("Form state is read-only.");const r=_u(t);return e.onStateChange(r,{address:"root",nodeAddress:"root",previousValue:e.state,value:r,data:r}),r}}}function F_({nodeAddress:e,expanded:t=!1}){var c;const{data:r,schema:n,bindings:o}=E.useContext(kr),{colorText:i,background:a}=Ve();if((c=o==null?void 0:o[e])!=null&&c.portResources)return null;const s=o&&Jt(o,e,n);if(!r||!s)return null;const u=xe(r,s.address);return!u||typeof u!="object"?null:h.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:pe(i),background:pe(a),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(s.type.properties).map(l=>{const d=s.fields[l]??{};if(!vn(d.$visibleWhen,r))return null;const f=u[l],p=f==null?"":typeof f=="object"?JSON.stringify(f):String(f);return h.jsxs("div",{"data-flow-property":l,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:[h.jsx("span",{style:{overflowWrap:"anywhere"},children:Cr(d.$label??l)}),h.jsx("span",{title:p,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:t?"pre-wrap":"nowrap",overflowWrap:t?"anywhere":void 0},children:p})]},l)})})}exports.BottomBar=yb;exports.CompactPropertyLayoutToggle=Dy;exports.ConnectionsOnlyToggle=a0;exports.DEFAULT_PALETTE=Nu;exports.DiagramAppearanceControls=Fy;exports.DynamicIcon=Mr;exports.EdgeTools=ab;exports.EditableLabel=Kt;exports.ErrorToast=hb;exports.FlowDiagram=I_;exports.FlowDiagramProvider=py;exports.FlowPort=Pm;exports.FlowView=$m;exports.FormDocumentContext=kr;exports.NODE_TYPE_VIEWS=Ft;exports.NodeBorderRadiusControl=sb;exports.NodeConfigSummary=F_;exports.NodeForm=rb;exports.NodeFormPopover=Am;exports.NodeIconPicker=qu;exports.NodeTools=cb;exports.NodeView=Bn;exports.SvgExportButton=db;exports.Swatches=Ht;exports.TEXT_PALETTE=ob;exports.ToolbarCloseButton=ht;exports.ToolbarCommitInput=Xr;exports.ToolbarDivider=Ot;exports.ToolbarIconButton=ve;exports.ToolbarRangeInput=Ly;exports.ToolbarScrollContainer=fb;exports.ToolbarSelect=Or;exports.ToolbarTooltip=je;exports.TooltipIconButton=Cu;exports.WorkflowControls=pb;exports.addChild=Pu;exports.addConnection=Au;exports.addTargetEdge=Zy;exports.addressToPath=Ir;exports.applyCollapsed=Ux;exports.applyFormChange=xn;exports.applyStateEdits=Hx;exports.bindSqueedCallbacks=vb;exports.compileSqueed=mu;exports.connectionIssue=Iu;exports.contentObjTheme=Er;exports.createFlowDiagram=Yr;exports.createFlowDocumentActions=L_;exports.createFormNode=mb;exports.createJsonPlayback=q_;exports.createJsonStream=sn;exports.downloadSvg=lb;exports.exportSvg=ub;exports.formValueError=Rr;exports.getChakraColorHex=pe;exports.getColorVariant=gy;exports.getDarkerHexColor=cn;exports.getNode=xe;exports.parseFlowDocument=$_;exports.parseJsonContract=Tu;exports.parseTypeScriptContract=Yy;exports.parseTypeScriptForm=Ou;exports.projectJsonPlaybackPreview=N_;exports.readFormSchema=Mu;exports.readWorkflowContract=Xy;exports.removeEdge=Jy;exports.removeNode=Ky;exports.resolveEdgeOwner=zt;exports.resolveStateView=Qy;exports.setCollapsed=Uy;exports.setEdgeProp=Fr;exports.setEdgeStyle=Hy;exports.setNodeProp=ir;exports.updateNode=hr;exports.useCustomColors=Ve;exports.useFlowData=Wr;exports.useFlowDiagramContext=Ie;exports.useNodeViewActions=Dn;exports.useStopPropagation=tl;exports.useThemeContentColors=Zt;
185
+ `;function Ib({nodeAddress:e,active:t,label:r,open:n=!1,onClose:o,children:i,filter:a,height:s}){const{background:u,border:c,colorText:l}=Ve(),d=j.useRef(null),f=j.useId(),{data:p,schema:m,bindings:y}=j.useContext(kr),b=i!==void 0||!!(p&&m&&(y?Yt(y,e,m):gt(p,e,m)));j.useEffect(()=>{var g,w,x,_,C;!t||!b||!n?(g=d.current)==null||g.close():(w=d.current)!=null&&w.open||((x=d.current)==null||x.showModal(),(C=(_=d.current)==null?void 0:_.querySelector("[data-form-filter] input"))==null||C.focus())},[t,b,n]);const v=fe(u);return b?h.jsx(h.Fragment,{children:typeof document<"u"&&Ft.createPortal(h.jsx(y_,{ref:d,id:f,$surface:v,$border:fe(c),"aria-label":`Configure ${r}`,onClose:o,onPointerDown:g=>g.stopPropagation(),onWheel:g=>g.stopPropagation(),onKeyDown:g=>g.stopPropagation(),onClick:g=>{var w;g.stopPropagation(),g.target===g.currentTarget&&((w=d.current)==null||w.close())},style:{margin:"auto",padding:20,width:380,boxSizing:"border-box",maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100dvh - 32px)",height:s,overflow:"hidden",borderRadius:30,background:v,color:fe(l),fontSize:16,textTransform:"none"},children:n&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexShrink:0},children:[h.jsx("strong",{style:{overflowWrap:"anywhere",minWidth:0},children:r}),h.jsx("form",{method:"dialog",style:{margin:0},onSubmit:g=>g.stopPropagation(),children:h.jsx(pt,{type:"submit","aria-label":"Close node configuration"})})]}),a&&h.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:a}),h.jsx(m_,{"data-form-scroll":"",style:s?{flex:1}:void 0,children:i??h.jsx(om,{nodeAddress:e})})]})}),document.body)}):null}const _u=({icon:e,label:t,onClick:r,color:n,boxSize:o=6,...i})=>{const{background:a,border:s,colorText:u}=Ve();return h.jsx(je,{label:t,children:h.jsx(F.Flex,{children:h.jsx(F.Icon,{as:e,boxSize:o,color:n,cursor:r?"pointer":void 0,onClick:r})})})},b_=({data:e,children:t,isInverted:r,isParent:n})=>{var N,D,W,z,X,se;const{selectedNodeIds:o,setSelectedNodeIds:i,selectedEdgeId:a,setSelectedEdgeId:s,isMultiSelectMode:u,isPerformanceMode:c,engineRef:l,callbacks:d,config:f,themeColor:p,direction:m}=Ie(),{background:y,border:b,colorText:v}=Ve(),g=j.useRef(null),w=j.useRef(null),[x,_]=j.useState(!1),[C,S]=j.useState(!1),[T,k]=j.useState(!1),E=e==null?void 0:e.id,P=im(E),R=o.includes(E),I=f.nodeOverlayActions,O=f.renderNodeOverlay,M=(()=>{var Q;try{const G=(Q=l.current)==null?void 0:Q.zoom();return G!==void 0&&G<.08}catch{return!1}})(),q=j.useCallback(Q=>{var J,te,le,de;if(C||f.readOnly)return;const G={shiftKey:Q.shiftKey,ctrlKey:Q.ctrlKey,metaKey:Q.metaKey,altKey:Q.altKey};if(a&&(s(null),(J=d.onEdgeDeselect)==null||J.call(d)),u){const Re=o.includes(E),ge=Re?o.filter(ze=>ze!==E):[...o,E];i(ge),Re?(te=d.onNodeDeselect)==null||te.call(d):(le=d.onNodeSelect)==null||le.call(d,E,e,G)}else i([E]),(de=d.onNodeSelect)==null||de.call(d,E,e,G)},[E,e,o,a,u,C,i,s,d,f]),K=j.useCallback(()=>{var Q;C||f.readOnly||(Q=d.onNodeDoubleClick)==null||Q.call(d,E,e)},[E,e,C,d,f]),V=j.useCallback(()=>{w.current&&clearTimeout(w.current),w.current=setTimeout(()=>_(!0),100)},[]),re=j.useCallback(()=>{w.current&&clearTimeout(w.current),_(!1)},[]),ce=!!((N=e==null?void 0:e.config)!=null&&N.form),he={tabIndex:ce?0:void 0,"aria-haspopup":ce?"dialog":void 0,"aria-expanded":ce?T:void 0,onDoubleClickCapture:Q=>{var G;!ce||f.readOnly||C||!Q.currentTarget.contains(Q.target)||Q.target instanceof Element&&Q.target.closest("button, input, textarea, select, a, [contenteditable=true]")||(Q.preventDefault(),Q.stopPropagation(),i([E]),k(!0),(G=d.onNodeDoubleClick)==null||G.call(d,E,e))},onKeyDown:Q=>{!ce||f.readOnly||Q.target!==Q.currentTarget||Q.key!=="Enter"||(Q.preventDefault(),Q.stopPropagation(),i([E]),k(!0))}},me=ce&&h.jsx(Ib,{nodeAddress:E,active:R,label:e.label||e.headerTitle||"Node",open:T,onClose:()=>{var Q;k(!1),R&&((Q=g.current)==null||Q.focus({preventScroll:!0}))}}),H=Array.isArray((D=e==null?void 0:e.config)==null?void 0:D.ports)?e.config.ports.map(Q=>h.jsx(Ob,{...Q},`${Q.id}:${Q.role}`)):null;return n?h.jsxs(F.Box,{ref:g,...he,onClick:q,onDoubleClick:K,onMouseEnter:V,onMouseLeave:re,cursor:"pointer",position:"relative",children:[me,!c&&(O||I&&I.length>0)&&x&&!M&&h.jsxs(h.Fragment,{children:[h.jsx(F.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>_(!0),onMouseLeave:re}),O?h.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>_(!0),onMouseLeave:re,willChange:"transform",children:O({nodeId:E,nodeData:e,isRoot:E==="root",isParent:!0,isHovered:x,setIsHovered:_})}):h.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:y,p:3,borderColor:b,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>_(!0),onMouseLeave:re,willChange:"transform",children:h.jsx(F.HStack,{px:2,gap:2,children:I.map((Q,G)=>h.jsxs(F.Box,{display:"contents",children:[G>0&&h.jsx(F.Box,{borderColor:b,height:5,borderRightWidth:1}),h.jsx(_u,{icon:Q.icon,label:Q.label,color:v,bgColor:y,borderColor:b,textColor:v,boxSize:5,onClick:J=>{var te;J.stopPropagation(),(te=d.onNodeHoverAction)==null||te.call(d,Q.id,E,e)}})]},Q.id))})})]}),t({id:E,data:e,isActive:R,isLowZoom:M,isEditing:C,onEditStart:()=>S(!0),onEditEnd:()=>S(!1)}),P&&!((W=e==null?void 0:e.config)!=null&&W.parentContainer)&&((z=e==null?void 0:e.config)==null?void 0:z.collapsed)!==void 0&&(()=>{var J;const Q=m==="TB"||m==="BT",G=r||m==="RL";return h.jsx(F.IconButton,{position:"absolute",...Q?{[m==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:G?void 0:"-75px",left:G?"-75px":void 0,top:"50%",transform:"translateY(-50%)"},"aria-label":e.config.collapsed?"Expand":"Collapse",disabled:f.readOnly,onClick:te=>{var le;te.stopPropagation(),(le=d.onNodeCollapse)==null||le.call(d,E,!e.config.collapsed)},bgColor:fe(((J=e==null?void 0:e.viewProps)==null?void 0:J.bgColor)||p),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?h.jsx(Z.PiPlusBold,{size:30,color:fe("gray.800")}):h.jsx(Z.PiMinusBold,{size:30,color:fe("gray.800")})})})()]}):h.jsxs(F.Box,{ref:g,...he,onClick:q,onDoubleClick:K,onMouseEnter:V,onMouseLeave:re,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[me,H,!c&&(O||I&&I.length>0)&&x&&!M&&h.jsxs(h.Fragment,{children:[h.jsx(F.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>_(!0),onMouseLeave:re}),O?h.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>_(!0),onMouseLeave:re,willChange:"transform",children:O({nodeId:E,nodeData:e,isRoot:E==="root",isParent:!!n,isHovered:x,setIsHovered:_})}):h.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:y,p:3,borderColor:b,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>_(!0),onMouseLeave:re,willChange:"transform",children:h.jsx(F.HStack,{px:2,gap:2,children:I.map((Q,G)=>h.jsxs(F.Box,{display:"contents",children:[G>0&&h.jsx(F.Box,{borderColor:b,height:5,borderRightWidth:1}),h.jsx(_u,{icon:Q.icon,label:Q.label,color:v,bgColor:y,borderColor:b,textColor:v,boxSize:5,onClick:J=>{var te;J.stopPropagation(),(te=d.onNodeHoverAction)==null||te.call(d,Q.id,E,e)}})]},Q.id))})})]}),h.jsxs(F.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[P&&!((X=e==null?void 0:e.config)!=null&&X.parentContainer)&&((se=e==null?void 0:e.config)==null?void 0:se.collapsed)!==void 0&&!n&&(()=>{var te,le,de;const Q=m==="TB"||m==="BT",G=r||m==="RL",J=(te=e==null?void 0:e.config)!=null&&te.labelBelow?((((le=e==null?void 0:e.viewProps)==null?void 0:le.fontSize)||1)*100+100)/2:void 0;return h.jsx(F.IconButton,{position:"absolute",...Q?{[m==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:G?void 0:J===void 0?"-75px":`calc(50% - ${J+75}px)`,left:G?J===void 0?"-75px":`calc(50% - ${J+75}px)`:void 0,alignSelf:J===void 0?"center":void 0,top:J===void 0?void 0:`${J}px`,transform:J===void 0?void 0:"translateY(-50%)",zIndex:J===void 0?void 0:1},"aria-label":e.config.collapsed?"Expand":"Collapse",disabled:f.readOnly,onClick:Re=>{var ge;Re.stopPropagation(),(ge=d.onNodeCollapse)==null||ge.call(d,E,!e.config.collapsed)},bgColor:fe(((de=e==null?void 0:e.viewProps)==null?void 0:de.bgColor)||p),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?h.jsx(Z.PiPlusBold,{size:30,color:fe("gray.800")}):h.jsx(Z.PiMinusBold,{size:30,color:fe("gray.800")})})})(),t({id:E,data:e,isActive:R,isLowZoom:M,isEditing:C,onEditStart:()=>S(!0),onEditEnd:()=>S(!1)})]})]})},Dn=j.memo(b_);function tl(e=!0){const t=j.useRef(null);return j.useEffect(()=>{if(!e||!t.current)return;const r=i=>{i.stopPropagation()},n=t.current,o=["mousedown","mouseup","click","dblclick","pointerdown","pointerup","wheel"];return o.forEach(i=>n.addEventListener(i,r)),()=>{o.forEach(i=>n.removeEventListener(i,r))}},[e]),t}const Zt=({nodeId:e,label:t,color:r,fontWeight:n="bold",fontSize:o="5xl",wrap:i=!1,isEditing:a,onEditStart:s,onEditEnd:u})=>{const{callbacks:c,config:l,readOnly:d}=Ie(),f=l.editable&&!d,[p,m]=j.useState(t),[y,b]=j.useState(),v=j.useRef(null),g=j.useRef(!1),w=tl(a);j.useEffect(()=>{a&&(g.current=!1,v.current&&(v.current.focus(),v.current.select()))},[a]);const x=()=>{var C;if(g.current)return;g.current=!0;const _=p.trim();_&&_!==t&&((C=c.onNodeLabelChange)==null||C.call(c,e,_)),u()};return!f||!a?h.jsx(F.Text,{color:r,fontWeight:n,fontSize:o,minW:0,maxW:"100%",whiteSpace:i?"normal":"nowrap",overflowWrap:i?"anywhere":void 0,overflow:"hidden",textOverflow:"ellipsis",title:t,onDoubleClick:f?_=>{_.stopPropagation(),b({width:_.currentTarget.offsetWidth,height:_.currentTarget.offsetHeight}),m(t),s()}:void 0,cursor:f?"text":void 0,children:t}):h.jsxs("div",{ref:w,style:{position:"relative",width:"max-content",minWidth:y==null?void 0:y.width,maxWidth:900,height:y==null?void 0:y.height},children:[h.jsx(F.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),h.jsx(F.Input,{ref:v,value:p,onChange:_=>m(_.target.value),onBlur:x,onKeyDown:_=>{_.key==="Enter"&&x(),_.key==="Escape"&&(g.current=!0,u())},color:r,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"})]})},v_=({id:e,data:t,isActive:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var y,b,v,g,w,x,_,C;const{themeColor:a}=Ie(),{colorText:s}=Ve(),u=((y=t==null?void 0:t.viewProps)==null?void 0:y.bgColor)==="transparent",c=((b=t==null?void 0:t.viewProps)==null?void 0:b.outline)===!0,{bgColor:l,borderColor:d,textColor:f}=Jt(((v=t==null?void 0:t.viewProps)==null?void 0:v.bgColor)||a),p=fe(((g=t==null?void 0:t.viewProps)==null?void 0:g.textColor)||(u||c?s:f)),m=((w=t==null?void 0:t.viewProps)==null?void 0:w.borderColor)||(c?!u&&((x=t==null?void 0:t.viewProps)==null?void 0:x.bgColor)||a:d);return h.jsx(F.Box,{"data-flow-node-surface":"",borderRadius:(_=t==null?void 0:t.viewProps)==null?void 0:_.borderRadius,bgColor:c?"transparent":l,...dn(t==null?void 0:t.viewProps,m,r,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:h.jsxs(F.Flex,{justifyContent:"start",alignItems:"center",gap:8,w:"fit-content",maxW:900,minW:0,fontSize:"5xl",lineHeight:"normal",children:[((C=t==null?void 0:t.config)==null?void 0:C.icon)&&h.jsx(F.Box,{flexShrink:0,children:h.jsx(Mr,{name:t.config.icon,size:80,color:p})}),h.jsx(Zt,{nodeId:e,label:(t==null?void 0:t.label)||(t==null?void 0:t.text)||"",color:p,isEditing:n,onEditStart:o,onEditEnd:i})]})})};function zn(){const{nodeViewModes:e,setNodeViewMode:t,allNodesIconLabel:r,setAllNodesIconLabel:n}=Ie();return{allNodesIconLabel:r,setAllNodesIconLabel:n,getNodeViewMode:o=>e[o]??"default",showNodeProperties:o=>t(o,"properties"),restoreNodeView:o=>t(o,"default"),toggleNodeView:o=>t(o,e[o]==="properties"?"default":"properties"),setNodeViewMode:t}}const x_=({id:e,isActive:t,data:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var w,x,_,C,S,T,k,E,P,R,I,O,M,q,K;const{themeColor:a}=Ie(),{colorText:s}=Ve(),u=((w=r==null?void 0:r.viewProps)==null?void 0:w.bgColor)==="transparent",c=((x=r==null?void 0:r.viewProps)==null?void 0:x.outline)===!0,l=!u&&((_=r==null?void 0:r.viewProps)==null?void 0:_.bgColor)||a,{borderColor:d,highlightColor:f,textColor:p}=Jt(l),m=fe(((C=r==null?void 0:r.viewProps)==null?void 0:C.textColor)||(u||c?s:p)),y=u&&!c&&!((S=r==null?void 0:r.viewProps)!=null&&S.borderColor)?"transparent":fe(((T=r==null?void 0:r.viewProps)==null?void 0:T.borderColor)||(c?l:d)),b=u||c?"transparent":l!=null&&l.startsWith("#")?l:fe(f),v=(k=r==null?void 0:r.config)==null?void 0:k.icon,g=(r==null?void 0:r.label)??(r==null?void 0:r.text)??"";if((E=r==null?void 0:r.config)!=null&&E.labelBelow){const V=(((P=r==null?void 0:r.viewProps)==null?void 0:P.fontSize)||1)*100;return h.jsxs(F.Flex,{"data-flow-icon-label":"",direction:"column",align:"center",gap:"24px",width:`${Math.max(V+200,360)}px`,position:"relative",children:[h.jsx(F.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${V+100}px`,height:`${V+100}px`,flexShrink:0,borderRadius:(R=r==null?void 0:r.viewProps)==null?void 0:R.borderRadius,backgroundColor:b,...dn(r==null?void 0:r.viewProps,y,t,2),children:!!v&&h.jsx(Mr,{name:v,size:V,color:m})}),h.jsxs(F.Flex,{"data-flow-icon-caption":"",direction:"column",align:"center",gap:"8px",justify:"center",width:"100%",minW:0,textAlign:"center",children:[h.jsx(Zt,{nodeId:e,label:g,color:fe(((I=r==null?void 0:r.viewProps)==null?void 0:I.textColor)||s),isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0}),typeof((O=r.config)==null?void 0:O.subtitle)=="string"&&r.config.subtitle!==""&&h.jsx(F.Text,{"data-flow-node-subtitle":"",color:fe(((M=r==null?void 0:r.viewProps)==null?void 0:M.textColor)||s),opacity:.65,fontSize:"32px",fontWeight:"normal",lineHeight:1.3,width:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",title:r.config.subtitle,children:r.config.subtitle})]})]})}return h.jsxs(F.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:(q=r==null?void 0:r.viewProps)==null?void 0:q.borderRadius,bgColor:b,style:{backgroundColor:b},textTransform:"capitalize",...dn(r==null?void 0:r.viewProps,y,t,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!v&&h.jsx(F.Flex,{align:"center",py:14,mr:g?8:0,flexShrink:0,children:h.jsx(Mr,{name:v,size:(((K=r==null?void 0:r.viewProps)==null?void 0:K.fontSize)||1)*100,color:m},m)}),(g||!v)&&h.jsx(F.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:h.jsx(Zt,{nodeId:e,label:g,color:m,isEditing:n,onEditStart:o,onEditEnd:i})})]})};function Mb({onExpand:e,toggleLabel:t="Show properties",toggleDisabled:r=!1,renderCompact:n=x_,...o}){const{colorMode:i,callbacks:a}=Ie();return h.jsx(Dn,{...o,children:s=>h.jsxs(F.Box,{position:"relative",children:[h.jsx(n,{...s}),e&&s.isActive&&h.jsx(F.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:h.jsx(je,{label:t,children:h.jsx(ve,{"aria-label":t,icon:h.jsx(F.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:i==="dark"?"gray.100":"gray.800",disabled:r,onClick:u=>{var c;u.stopPropagation(),e(),(c=a.onNodeViewToggle)==null||c.call(a,o.data.id)}})})})]})})}const uy=1.55;function w_({nodeId:e,content:t,color:r}){const{callbacks:n,config:o,readOnly:i}=Ie(),a=!!o.editable&&!i,[s,u]=j.useState(!1),[c,l]=j.useState(t),[d,f]=j.useState(),p=j.useRef(null),m=j.useRef(!1),y=tl(s);j.useLayoutEffect(()=>{const g=p.current;!s||!g||(g.style.height="auto",g.style.height=`${Math.max((d==null?void 0:d.height)??0,g.scrollHeight)}px`)},[c,s,d]),j.useEffect(()=>{var g;a?s&&(m.current=!1,(g=p.current)==null||g.focus()):u(!1)},[s,a]);const b=g=>{a&&(f({width:g.offsetWidth,height:g.offsetHeight}),l(t),u(!0))},v=()=>{var g;m.current||!a||(m.current=!0,c!==t&&((g=n.onNodeContentChange)==null||g.call(n,e,c)),u(!1))};return!s||!a?h.jsx(F.Box,{"data-flow-content":"",color:r,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:uy,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:a?"text":void 0,tabIndex:a?0:void 0,onDoubleClick:g=>{g.stopPropagation(),b(g.currentTarget)},onKeyDown:g=>{a&&g.key==="Enter"&&g.target===g.currentTarget&&(g.preventDefault(),g.stopPropagation(),b(g.currentTarget))},children:h.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:t})}):h.jsx("div",{ref:y,style:{width:d==null?void 0:d.width,minHeight:d==null?void 0:d.height,maxWidth:"100%"},children:h.jsx(F.Textarea,{ref:p,"aria-label":"Node content",value:c,onChange:g=>l(g.target.value),onBlur:v,onKeyDown:g=>{g.stopPropagation(),!g.nativeEvent.isComposing&&(g.key==="Enter"&&(g.ctrlKey||g.metaKey)&&(g.preventDefault(),v()),g.key==="Escape"&&(m.current=!0,u(!1)))},color:r,fontFamily:"inherit",fontSize:"inherit",lineHeight:uy,overflowWrap:"anywhere",whiteSpace:"pre-wrap",rows:1,bg:"transparent",display:"block",style:{border:0,outline:"none",boxShadow:"none"},p:0,w:"100%",h:"100%",minW:0,minH:0,resize:"none"})})}const C_=(e,t,r)=>{var f,p,m,y;const n=((f=e==null?void 0:e.viewProps)==null?void 0:f.bgColor)||t,[o]=n.split("."),i=Jt(n),a=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,s=n==="transparent"||a,u=r==="dark"?"gray.200":"gray.900",c=s?"transparent":n!=null&&n.startsWith("#")?fe(n):fe(i.bgColor),l=fe(((m=e==null?void 0:e.viewProps)==null?void 0:m.textColor)||(s?u:i.textColor)),d=fe(((y=e==null?void 0:e.viewProps)==null?void 0:y.borderColor)||(a?n==="transparent"?t:n:i.borderColor));return{...i,bgColor:s?"transparent":i.bgColor,highlightColor:s?"transparent":i.highlightColor,isTransparent:s,propertyColor:s?u:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:c,hextextColor:l,hexborderColor:d}},__=(e,t=350)=>`${String(e).substring(0,t)}${String(e).length>t?"...":""}`,S_=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,qb=600,E_=3,j_=e=>{const t=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(t*28+30,200)};function R_({headerTitle:e,hasContent:t,data:r,icon:n,colors:o,hasConfig:i,id:a,isActive:s,isEditing:u,onEditStart:c,onEditEnd:l,props:d,objVisible:f,setObjVisible:p,onShowNativeIcon:m}){var g,w;const{callbacks:y}=Ie(),b=d.onShowIcon??m,v=b?"Show icon":f?"Show content":"Show properties";return h.jsx(h.Fragment,{children:(e||t||((g=r.config)==null?void 0:g.form)||s&&m)&&h.jsxs(F.Flex,{justify:"flex-start",direction:"row",p:Object.entries(r.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&&!t?"transparent":o.hexborderColor,children:[!!n&&h.jsx(F.Flex,{mr:6,alignItems:"center",flexShrink:0,children:h.jsx(Mr,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),h.jsx(Zt,{nodeId:a,label:S_(e),color:((w=r==null?void 0:r.viewProps)==null?void 0:w.textColor)||o.propertyColor,isEditing:u,onEditStart:c,onEditEnd:l}),s&&(t||b)&&h.jsx(F.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:h.jsx(je,{label:v,children:h.jsx(ve,{"aria-label":v,icon:h.jsx(F.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:x=>{var _;x.stopPropagation(),b?b():p(!f),(_=y.onNodeViewToggle)==null||_.call(y,a)}})})})]})})}function k_({data:e,resourcePorts:t,inspecting:r,form:n,inspectionPorts:o,extraPorts:i,colors:a,direction:s,uniformKeyWidth:u}){const{edgeById:c}=Gr(),l=new Set;for(const{data:d}of c.values())d.source===e.id&&d.sourceProperty!==void 0&&l.add(`source:${d.sourceProperty}`),d.target===e.id&&d.targetProperty!==void 0&&l.add(`target:${d.targetProperty}`);return h.jsx(F.Box,{children:Object.entries(e.description||{}).map(([d,f],p)=>{var I,O,M;const m=t&&Object.keys(t).find(q=>q.slice(q.indexOf(":")+1)===d),y=r&&((I=n==null?void 0:n.type.ports)==null?void 0:I[d]),b=m??(y?`${y.kind}:${d}`:d),v=o.find(q=>q.id===b),g=m?"source":v==null?void 0:v.role,w=l.has(`source:${b}`),x=l.has(`target:${b}`),_=i.some(q=>q.id===d),C=f===""&&(_||(g?l.has(`${g}:${b}`):w||x)),S=g??(w!==x?w?"source":"target":void 0),T=(v==null?void 0:v.side)??(S?S==="source"!=(s==="RL")?"right":"left":void 0),k=C&&T==="right"?"right":"left",E=_?d.replace(/^(template|input|output|config|error):/,""):d,P=jr(a.wordBeforeDot)[typeof f],R=jr(a.wordBeforeDot).property;return h.jsxs(F.Box,{"data-flow-property":m&&(s==="TB"||s==="BT")?void 0:b,"data-flow-port-role":g,"data-flow-inspection-row":r?"":void 0,children:[h.jsxs(F.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[h.jsx(F.Flex,{justifyContent:"start",align:"center",background:a.highlightColor,width:C?"100%":`${u}px`,minWidth:`${u}px`,borderRightColor:a.hexborderColor,borderRightWidth:C?0:1,children:h.jsx(F.Text,{py:5,px:10,w:"100%",textAlign:k,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((O=e==null?void 0:e.viewProps)==null?void 0:O.textColor)||(a.isTransparent?a.hextextColor:R),children:E})}),!C&&h.jsx(F.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:a.hexbgColor,w:qb,maxH:200,children:h.jsx(F.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:((M=e==null?void 0:e.viewProps)==null?void 0:M.textColor)||(a.isTransparent?a.hextextColor:P),fontWeight:400,children:__(f)})})]}),p!==Object.entries(e.description||{}).length-1&&h.jsx(F.Box,{borderTopWidth:1,my:0,borderColor:a.hexborderColor})]},d)})})}function P_(e){var w,x,_;const{themeColor:t,colorMode:r,direction:n}=Ie(),o=zn(),i=o.getNodeViewMode(e.data.id)==="properties",a=C=>o.setNodeViewMode(e.data.id,C?"properties":"default"),s=!!e.onShowIcon||i||typeof((w=e.data.config)==null?void 0:w.content)!="string",{bindings:u,data:c,schema:l}=j.useContext(kr),d=(x=u==null?void 0:u[e.data.id])==null?void 0:x.portResources,f=u?Yt(u,e.data.id,l):c&&l?gt(c,e.data.id,l):void 0,p=f&&xe(c,"address"in f?f.address:e.data.id),m=p&&typeof p=="object"&&f?Object.fromEntries(Object.keys(f.type.properties).filter(C=>{var S;return Object.prototype.hasOwnProperty.call(p,C)&&xn((S=f.fields[C])==null?void 0:S.$visibleWhen,c)}).map(C=>[C,p[C]!==null&&typeof p[C]=="object"?JSON.stringify(p[C],null,2):p[C]===null?"null":p[C]])):{},y=d?Object.fromEntries(Object.entries(d).map(([C,S])=>{var T;return[C.slice(C.indexOf(":")+1),((T=xe(c,S))==null?void 0:T.name)??S.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:m,b=s&&!d?((_=e.data.config)==null?void 0:_.ports)??[]:[],v=b.filter(C=>!Object.prototype.hasOwnProperty.call(y,C.id)&&!Object.entries((f==null?void 0:f.type.ports)??{}).some(([S,T])=>`${T.kind}:${S}`===C.id&&Object.prototype.hasOwnProperty.call(y,S))),g={...y,...Object.fromEntries(v.map(C=>[C.id,""]))};return{themeColor:t,colorMode:r,direction:n,objVisible:i,setObjVisible:a,inspecting:s,resourcePorts:d,form:f,description:g,inspectionPorts:b,extraPorts:v}}const nl=e=>{var b,v,g;const{themeColor:t,colorMode:r,direction:n,objVisible:o,setObjVisible:i,inspecting:a,resourcePorts:s,form:u,description:c,inspectionPorts:l,extraPorts:d}=P_(e),f=zn(),p=f.getNodeViewMode(e.data.id)==="icon-label",y=!e.onShowIcon&&!((b=e.data.config)!=null&&b.parentContainer)&&typeof((v=e.data.config)==null?void 0:v.content)!="string"?()=>f.setNodeViewMode(e.data.id,"icon-label"):void 0;return!e.onShowIcon&&p?h.jsx(Mb,{...e,data:{...e.data,label:e.data.label??e.data.headerTitle,config:{...e.data.config,labelBelow:!0,icon:((g=e.data.config)==null?void 0:g.icon)||"PiBracketsCurly"}},onExpand:()=>f.restoreNodeView(e.data.id)}):h.jsx(Dn,{...e,data:{...e.data,description:c},children:({id:w,data:x,isActive:_,isEditing:C,onEditStart:S,onEditEnd:T})=>{var V,re,ce,he,me,H;const k=C_(x,t,r),E=x.label??x.headerTitle,P=Object.entries(x.description||{}).length>0,R=j_(x.description),I=(re=(V=e.data)==null?void 0:V.config)==null?void 0:re.icon,O=(he=(ce=e.data)==null?void 0:ce.config)==null?void 0:he.content,M=typeof O=="string"&&!e.onShowIcon,q=((me=x==null?void 0:x.viewProps)==null?void 0:me.borderRadius)??"53px",K=dn(x==null?void 0:x.viewProps,k.hexborderColor,_,E_);return h.jsx(F.Flex,{justifyContent:"space-between",...x==null?void 0:x.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:q,overflow:"hidden",alignItems:"center",style:{backgroundColor:k.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:"100%",minW:M||e.onShowIcon?R+qb+K.borderWidth*2:void 0,...K,children:h.jsxs(F.Flex,{width:"100%",direction:"column",borderRadius:q,borderColor:k.hexborderColor,borderWidth:0,overflow:"hidden",children:[h.jsx(R_,{headerTitle:E,hasContent:M,data:x,icon:I,colors:k,hasConfig:P,id:w,isActive:_,isEditing:C,onEditStart:S,onEditEnd:T,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:y}),M&&!o?h.jsx(F.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:k.highlightColor,p:12,fontSize:"5xl",lineHeight:"normal",children:h.jsx(w_,{nodeId:w,content:O,color:((H=x==null?void 0:x.viewProps)==null?void 0:H.textColor)||k.hextextColor})}):h.jsx(k_,{data:x,resourcePorts:s,inspecting:a,form:u,inspectionPorts:l,extraPorts:d,colors:k,direction:n,uniformKeyWidth:R})]})})}})};nl.displayName="NodeJsonObjectView";const Nb=e=>{var c,l,d,f,p,m,y;const t=zn(),r=t.getNodeViewMode(e.data.id)==="properties",n=b=>t.setNodeViewMode(e.data.id,b?"properties":"default"),{callbacks:o,readOnly:i}=Ie(),a=(l=(c=e.data)==null?void 0:c.config)==null?void 0:l.parentContainer,s=a?"Show parent":"Show properties",u=a||((f=(d=e.data)==null?void 0:d.config)==null?void 0:f.form)||((y=(m=(p=e.data)==null?void 0:p.config)==null?void 0:m.ports)==null?void 0:y.length);return!a&&u&&r?h.jsx(nl,{...e,onShowIcon:()=>n(!1)}):h.jsx(Mb,{...e,toggleLabel:s,toggleDisabled:a&&i,onExpand:u?()=>{var b;a?(b=o.onNodeCollapse)==null||b.call(o,e.data.id,!1):n(!0)}:void 0})},$b=e=>h.jsx(Nb,{...e,renderCompact:v_}),Lb=e=>h.jsx(Nb,{...e}),Fb=e=>h.jsx(Dn,{...e,children:()=>null});$b.displayName="text";Lb.displayName="arrayView";Fb.displayName="ParentContainerView";const A_={objectView:nl,arrayView:Lb,text:$b,parentContainer:Fb},T_=({children:e,pattern:t="dot",backgroundColor:r})=>{const{colorMode:n}=Ie(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",a=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return t==="none"?h.jsx(F.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:r,children:e}):h.jsxs(F.Box,{"data-flow-background":t,position:"relative",width:"100%",height:"100%",padding:0,bg:r,children:[h.jsx(F.Box,{position:"absolute",top:0,left:0,right:0,bottom:0,width:"100%",height:"100%",zIndex:0,pointerEvents:"none",style:{backgroundImage:t==="dot"?`radial-gradient(var(${i}) 8%, transparent 8%)`:t==="steel"?`repeating-linear-gradient(45deg, var(${a}) 0, var(${a}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${a}) 1px, transparent 1px), linear-gradient(90deg, var(${a}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),h.jsx(F.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},O_=.4,Kr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},I_=({nodes:e,edges:t})=>{const{themeColor:r,spacing:n,edgeRadius:o,backgroundVariant:i,setBackgroundSelected:a,edgeColor:s,direction:u,nodeAlignment:c,edgeMode:l,compactPropertyLayout:d,workflowContract:f,parentNodeStyle:p,engineRef:m,callbacks:y,config:b,selectedNodeIds:v,setSelectedNodeIds:g,selectedEdgeId:w,setSelectedEdgeId:x,setIsPerformanceMode:_,isZoomMode:C,setIsZoomMode:S,isMultiSelectMode:T,setIsMultiSelectMode:k,isDragMode:E,setIsDragMode:P,isEdgeHandlesEnabled:R,isArrayNodeMode:I}=Ie(),O=j.useRef(null),[M,q]=j.useState(null),K=e.length>200;j.useEffect(()=>{_(K)},[K,_]);const{edgeSep:V,rankSep:re,spacingFactor:ce}=j.useMemo(()=>{const Y=y0(e.length),B=n<1?.3+.7*n:.5+.5*n;return{edgeSep:Y.edgeSep*B,rankSep:Y.rankSep*B,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n]),{bgColor:he}=Jt(r),{canvas:me,borderSecondary:H,colorText:N}=Ve(),D=i==="transparent"?"transparent":b.backgroundColor||me,W=j.useCallback(Y=>{if(Y!=null&&Y.includes("gray"))return"whitesmoke";if(!Y)return fe(r);switch(Y){case"dark":return fe(D);case"light":return fe(H);default:return fe(Y)}},[r,D,H]),z=b.colorMode==="dark",X=j.useMemo(()=>W(z?he:"light"),[z,he,W]),se=s?W(s):X,Q=j.useMemo(()=>b.initialViewport||{pan:{x:0,y:0},zoom:.01},[]),G=u==="C"?"LR":u,J=j.useCallback(Y=>{const B={...p,...Y};return{...B,bgColor:B.bgColor||r,bgOpacity:B.outline?0:B.bgOpacity??O_}},[p,r]),te=j.useMemo(()=>{var B;const Y=new Map;for(const ee of e)(B=ee.data)!=null&&B.id&&Y.set(ee.data.id,ee);return Y},[e]),le=j.useMemo(()=>{var B;const Y=new Map;for(const ee of t)(B=ee.data)!=null&&B.id&&Y.set(ee.data.id,ee);return Y},[t]),de=j.useCallback(Y=>{var Se;const B=(Se=te.get(Y))==null?void 0:Se.data,ee=J(B==null?void 0:B.viewProps),Ce=fe(ee.bgColor);return{animated:!!(B!=null&&B.isNodeAnimated)&&!K,animationVariant:B==null?void 0:B.nodeAnimationVariant,animationColor:fe(ee.borderColor||r),bgColor:ee.outline?"transparent":Ce,bgOpacity:ee.bgOpacity,borderColor:ee.borderColor?fe(ee.borderColor):ee.outline&&ee.bgColor==="transparent"?fe(r):Ce,borderWidth:Ht(ee.borderWidth,Kr.borderWidth),borderStyle:ee.borderStyle??Kr.borderStyle,borderRadius:ee.borderRadius??Kr.borderRadius,textColor:ee.textColor?fe(ee.textColor):ee.outline||ee.bgColor==="transparent"?fe(N):Ce,fontSize:ee.fontSize??Kr.fontSize,labelPosition:ee.labelPosition??Kr.labelPosition,labelMargin:Kr.labelMargin,labelBg:cl(W("dark"),Ce,ee.bgOpacity)??W("dark"),padding:ee.padding??Kr.padding}},[J,te,N,r,K,W]),Re=j.useMemo(()=>{var ee,Ce;const Y=new Map;for(const Se of t){const Ee=(ee=Se.data)==null?void 0:ee.source,We=(Ce=Se.data)==null?void 0:Ce.target;if(!Ee||!We||Ee===We)continue;const Le=Ee<We?`${Ee}|${We}`:`${We}|${Ee}`,Pe=Y.get(Le);Pe?Pe.push({id:Se.data.id,source:Ee}):Y.set(Le,[{id:Se.data.id,source:Ee}])}const B=new Map;for(const[Se,Ee]of Y){if(Ee.length<2)continue;const We=Se.split("|")[0],Le=Math.min(20,70/Ee.length);Ee.forEach(({id:Pe,source:Me},yr)=>{const Ye=50+(yr-(Ee.length-1)/2)*Le;B.set(Pe,(Me===We?Ye:100-Ye)/100)})}return B},[t]),ge=j.useMemo(()=>{const Y=W("dark");return t.filter(B=>{var ee;return((ee=B.data)==null?void 0:ee.id)&&B.data.source&&B.data.target}).map(({data:B})=>{var Ee,We,Le,Pe,Me,yr;let ee=Y;const Ce=(We=(Ee=te.get(B.source))==null?void 0:Ee.data)==null?void 0:We.parent,Se=(Pe=(Le=te.get(B.target))==null?void 0:Le.data)==null?void 0:Pe.parent;if(Ce&&Ce===Se){const Ye=J((yr=(Me=te.get(Ce))==null?void 0:Me.data)==null?void 0:yr.viewProps),mr=cl(Y,fe(Ye.bgColor),Ye.bgOpacity);mr&&(ee=mr)}return{id:B.id,data:B,type:B.type??b.edgeType??"rounded-orthogonal",source:B.source,target:B.target,sourceProperty:B.sourceProperty,targetProperty:B.targetProperty,label:B.label,validationIssue:(l==="auto"||l==="properties")&&(B.sourceProperty!==void 0||B.targetProperty!==void 0)&&f?Iu(f,B):void 0,color:B.color?fe(B.color):se,labelBg:ee,dashed:!!B.isEdgeDashed,animated:!!B.isEdgeAnimated,inverted:!!B.isInverted,turn:Re.get(B.id)??.5}})},[t,se,Re,b.edgeType,l,f,te,J,W]),ze=j.useMemo(()=>{var B;const Y=new Set;for(const ee of e)(B=ee.data)!=null&&B.parent&&Y.add(ee.data.parent);return Y},[e]),Fe=j.useMemo(()=>{var B;const Y=new Map;for(const ee of t)(B=ee.data)!=null&&B.source&&!Y.has(ee.data.source)&&Y.set(ee.data.source,ee.data);return Y},[t]),He=j.useMemo(()=>{const Y={...A_,...b.customViews};return e.filter(B=>{var ee;return(ee=B.data)==null?void 0:ee.id}).map(B=>{var We,Le,Pe,Me;const ee=ze.has(B.data.id)&&!B.data.parent,Ce=ee?B.data.label??B.data.headerTitle??"Container":void 0,Se=ee?Y.parentContainer:Y[B.data.type]||Y.text,Ee=Fe.get(B.data.id);return{id:B.data.id,collapsed:(We=B.data.config)==null?void 0:We.collapsed,parent:B.data.parent,label:Ce,animated:!!B.data.isNodeAnimated,animationVariant:B.data.nodeAnimationVariant,hasCollapseControl:((Le=B.data.config)==null?void 0:Le.collapsed)!==void 0,animationColor:fe(((Pe=B.data.viewProps)==null?void 0:Pe.borderColor)||r),animationWidth:Ht((Me=B.data.viewProps)==null?void 0:Me.borderWidth,8),element:j.createElement(Se,{...B,isInverted:Ee==null?void 0:Ee.isInverted,isParent:ee,key:`${B.data.id}-${r}`})}})},[e,ze,Fe,r,b.customViews]),ar=j.useMemo(()=>K?300:e.length>50?150:e.length>20?100:50,[e.length,K]),be=j.useRef(b);be.current=b;const _e=j.useRef(C);_e.current=C;const Xe=j.useRef(I);Xe.current=I;const Ke=j.useRef(v);Ke.current=v;const Ne=j.useRef(w);Ne.current=w;const Qe=j.useRef(T);Qe.current=T;const Ze=j.useRef(te);Ze.current=te;const gr=j.useRef(le);gr.current=le;const fr=j.useRef(new Map);j.useEffect(()=>{var ee,Ce;const Y=new Map([...le].filter(([,Se])=>te.has(Se.data.source)&&te.has(Se.data.target))),B=fr.current;fr.current=Y;for(const[Se,Ee]of B)Y.has(Se)||(Ne.current===Se&&(x(null),(ee=y.onEdgeDeselect)==null||ee.call(y)),(Ce=y.onEdgeRemove)==null||Ce.call(y,Se,Ee.data))},[le,te,y,x]),j.useEffect(()=>{const Y=O.current;if(!M||!Y)return;let B=null,ee=null,Ce=0,Se=0,Ee=0,We=0,Le=0;const Pe=Me=>{if(be.current.readOnly)return;Me.preventDefault(),Me.stopPropagation(),_e.current||Me.metaKey||Me.ctrlKey?(Ee+=Me.deltaY,We=Me.clientX,Le=Me.clientY,ee===null&&(ee=requestAnimationFrame(()=>{ee=null;const Ye=be.current,mr=M.zoom(),Oe=Ee;Ee=0;let wr=mr-Oe*.05/100;wr=Math.max(Ye.minZoom??.01,Math.min(Ye.maxZoom??1.5,wr));const $r=Y.getBoundingClientRect();M.zoomAt(wr,{x:We-$r.left,y:Le-$r.top})}))):(Ce+=Me.deltaX,Se+=Me.deltaY,B===null&&(B=requestAnimationFrame(()=>{B=null;const Ye=M.pan(),mr=M.zoom(),Oe=.35,wr=Ce,$r=Se;Ce=0,Se=0,M.pan({x:Ye.x+-wr*Oe/mr,y:Ye.y+-$r*Oe/mr})})))};return Y.addEventListener("wheel",Pe,{passive:!1}),()=>{Y.removeEventListener("wheel",Pe),B!==null&&cancelAnimationFrame(B),ee!==null&&cancelAnimationFrame(ee)}},[M]),j.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const Y=B=>{var Ce,Se,Ee,We;if(be.current.readOnly)return;const ee=B.target;if(!(ee.tagName==="INPUT"||ee.tagName==="TEXTAREA"||ee.isContentEditable)){if((B.key==="z"||B.key==="Z")&&S(!_e.current),(B.key==="m"||B.key==="M")&&k(!T),(B.key==="d"||B.key==="D")&&P(!E),(B.key==="Delete"||B.key==="Backspace")&&Ne.current){B.preventDefault();const Le=Ne.current;(Se=y.onEdgeDelete)==null||Se.call(y,Le,((Ce=gr.current.get(Le))==null?void 0:Ce.data)??{id:Le}),x(null);return}if((B.key==="Delete"||B.key==="Backspace")&&Ke.current.length>0){B.preventDefault();const Le=Ke.current.filter(Pe=>Pe!=="root");if(Le.length===0)return;for(const Pe of Le){const Me=(Ee=Ze.current.get(Pe))==null?void 0:Ee.data;(We=y.onNodeDelete)==null||We.call(y,Pe,Me||{})}g([])}}};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[T,E,S,k,P,b.disableKeyboardShortcuts,y,g,x]);const Er=j.useCallback(Y=>{var B;m.current=Y,q(Y),(B=y.onInit)==null||B.call(y,Y)},[m,y]),we=j.useCallback(Y=>{var B;return(B=y.onViewportChange)==null?void 0:B.call(y,Y)},[y]),or=j.useCallback(Y=>{var ee,Ce,Se;const B=((ee=gr.current.get(Y))==null?void 0:ee.data)??{id:Y};if(Ne.current===Y&&Qe.current){x(null),(Ce=y.onEdgeDeselect)==null||Ce.call(y);return}Ke.current.length&&g([]),x(Y),(Se=y.onEdgeSelect)==null||Se.call(y,Y,B)},[y,x,g]),sr=j.useCallback(()=>{var Y,B,ee;a(!0),(Y=y.onBackgroundClick)==null||Y.call(y),Ke.current.length&&(g([]),(B=y.onNodeDeselect)==null||B.call(y)),Ne.current&&(x(null),(ee=y.onEdgeDeselect)==null||ee.call(y))},[y,g,x,a]),wt=j.useCallback(Y=>{var Ce,Se;const B=Ke.current,ee=Y.filter(Ee=>!B.includes(Ee));if(ee.length){g([...B,...ee]);for(const Ee of ee)(Se=y.onNodeSelect)==null||Se.call(y,Ee,((Ce=Ze.current.get(Ee))==null?void 0:Ce.data)??{id:Ee})}},[y,g]),ne=j.useCallback((Y,B)=>{var ee,Ce;g([Y]),(Ce=y.onNodeSelect)==null||Ce.call(y,Y,((ee=Ze.current.get(Y))==null?void 0:ee.data)??{id:Y},B)},[y,g]),Be=j.useCallback((Y,B,ee)=>{var Ce;return(Ce=y.onEdgeCreate)==null?void 0:Ce.call(y,Y,B,ee)},[y]),Je=j.useCallback((Y,B,ee,Ce=!1)=>{var Se,Ee;l==="properties"&&((Se=y.onNodeCreateRequest)==null?void 0:Se.call(y,{sourceNodeId:Y,position:B,sourceProperty:ee,reverse:Ce}))===!0||ee!==void 0||Ce||(Ee=y.onNodeCreate)==null||Ee.call(y,{type:"text",sourceNodeId:Y,position:B,isArrayMode:Xe.current})},[y,l]),$e=!b.readOnly&&R&&b.edgeHandles!==!1,er=i==="transparent"?"none":i;return h.jsx(T_,{pattern:er,backgroundColor:D,children:h.jsx(F.Box,{ref:O,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:h.jsx(g_,{nodes:He,edges:ge,direction:G,nodeAlignment:c,onContainerCollapse:Y=>{var B,ee;(B=y.onNodeCollapse)==null||B.call(y,Y,!0),(ee=y.onNodeViewToggle)==null||ee.call(y,Y)},selectedNodeIds:v,edgeMode:l,compactPropertyLayout:d,edgeType:b.edgeType,edgeRadius:o,customEdgeTypes:b.customEdgeTypes,rankSep:re,edgeSep:V,spacingFactor:ce,compactSpacingScale:n,layoutDebounce:ar,isPerformanceMode:K,minZoom:b.minZoom??.01,maxZoom:b.maxZoom??1.5,initialViewport:Q,fitOnInit:!b.initialViewport,readOnly:!!b.readOnly,containerStyle:de,lineColor:se,drawMode:$e,drawHandles:!b.readOnly&&b.edgeHandles!==!1,dragMode:E,multiSelect:!!T,onInit:Er,onLayoutComplete:y.onLayoutComplete,animateViewport:b.animateViewport,onViewportChange:we,onBackgroundTap:sr,onBoxSelect:wt,onEdgeSelect:or,onContainerSelect:ne,onEdgeDraw:Be,onDrawIntoSpace:Je})})})},Bb=j.memo(I_),M_=".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 ly=!1;function q_(){if(ly||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=M_+g0+h0+".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}',ly=!0}function N_({loading:e=!1,loader:t,...r}){var u,c;const[n,o]=j.useState(null),i=j.useMemo(()=>!!(n!=null&&n.json)&&!!r.json&&l0(n.json,r.json),[n==null?void 0:n.json,r.json]),a=n===null||n.json!==r.json&&!i,s=e||a;return j.useEffect(()=>{!e&&i&&(n==null?void 0:n.json)!==r.json&&o(r)},[e,i,n==null?void 0:n.json,r.json]),j.useEffect(()=>{if(e||!a)return;let l;const d=requestAnimationFrame(()=>{l=requestAnimationFrame(()=>o(r))});return()=>{cancelAnimationFrame(d),l!==void 0&&cancelAnimationFrame(l)}},[e,a,r.json]),h.jsxs(F.Box,{className:r.className,style:r.style,width:"100%",height:"100%",position:"relative","aria-busy":s,children:[h.jsx("div",{style:{width:"100%",height:"100%"},ref:l=>{s?l==null||l.setAttribute("inert",""):l==null||l.removeAttribute("inert")},children:n&&h.jsx($_,{...a?n:r,className:void 0,style:void 0})}),s&&h.jsx(F.Box,{"data-flow-loader":"",role:"status","aria-label":"Loading diagram",position:"absolute",inset:0,zIndex:1e3,display:"grid",placeItems:"center",background:((u=r.config)==null?void 0:u.colorMode)==="dark"?"gray.800":"gray.100",color:((c=r.config)==null?void 0:c.colorMode)==="dark"?"whiteAlpha.800":"blackAlpha.800",children:t===void 0?h.jsx("span",{children:"Loading diagram..."}):t})]})}function $_({title:e="untitled",json:t,forms:r,nodes:n,edges:o,config:i={},callbacks:a={},className:s,style:u,showBottomBar:c=!0,children:l}){q_();const[d,f]=j.useState(),p=i.formSchema??d,m=j.useMemo(()=>t&&r?tm(t,r.state):t,[t,r==null?void 0:r.state]),y=i.direction==="C",b=j.useMemo(()=>{let k,E;return P=>(E=k&&E?d0(k,P,E)??vu(P,{title:e,isCenter:y}):vu(P,{title:e,isCenter:y}),k=P,E)},[e,y]),v=j.useMemo(()=>m?b(m):null,[m,b]),g=j.useMemo(()=>r!=null&&r.structured&&p?o0(r.state,r.bindings,p,(v==null?void 0:v.nodes)??n??[]):void 0,[r==null?void 0:r.structured,r==null?void 0:r.state,r==null?void 0:r.bindings,p,v,n]),w=(g==null?void 0:g.schema)??p,x=(g==null?void 0:g.bindings)??(r==null?void 0:r.bindings),_=j.useMemo(()=>[...(v==null?void 0:v.nodes)??n??[],...(g==null?void 0:g.nodes)??[]].map(E=>{var K,V,re,ce;const P=t?(K=xe(t,E.data.id))==null?void 0:K.$view:(V=E.data.config)==null?void 0:V.typeView,R=P&&Bt.includes(P)?P:void 0,I=R?R==="icon-label":(re=E.data.config)==null?void 0:re.labelBelow,O=R==="object"?"objectView":R==="text"?"text":I?"arrayView":E.data.type,M=w&&(r?Yt(x,E.data.id,w):t&&gt(t,E.data.id,w)),q=(((ce=E.data.config)==null?void 0:ce.ports)??[]).map(he=>({...he}));if(g&&M){const he=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[me,H]of Object.entries(M.type.ports??{})){const N=`${H.kind}:${me}`;q.some(D=>D.id===N)||q.push({id:N,role:H.kind==="input"||H.kind==="config"?"target":"source",side:he[H.kind],...H.kind==="config"?{placement:"config"}:{}})}for(const me of q){const H=q.filter(N=>N.side===me.side);me.position=(H.indexOf(me)+1)/(H.length+1)}}return M||I||R?{...E,data:{...E.data,type:O,...r?{description:Object.fromEntries(Object.entries(E.data.description??{}).filter(([he])=>!he.startsWith("$")&&!(g!=null&&g.slots.has(Rt(E.data.id,he)))))}:{},config:{...E.data.config,...g&&M?{ports:q}:{},...M?{form:!0}:{},...R?{typeView:R,labelBelow:!!I}:I?{labelBelow:!0}:{}}}}:E}),[v,n,t,w,x,g,i.direction]),C=[...(v==null?void 0:v.edges)??o??[],...(g==null?void 0:g.edges)??[]],S=j.useMemo(()=>{const k=t&&v?Cm(t,v.edges,a,a.onJsonChange,p):{...a};if(g){const E=new Set([...g.nodes.map(P=>P.data.id),...g.edges.map(P=>P.data.id)]);for(const P of Object.keys(k)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(P))continue;const R=k[P];k[P]=(I,...O)=>{if(!E.has(I))return R==null?void 0:R(I,...O)}}}return k},[t,v,a,p,g]),T=j.useMemo(()=>{if(!r)return S;let k=r.state;const E=R=>{if(i.readOnly||i.editable===!1)return;const I=r.onStateChange??r.onChange;if(!I)return;const O=Yx(k,R,a.onFormChange);O!==k&&(k=O,I(O,{...R,data:O}))},P=(R,I,O)=>{var q;const M=t&&((q=xe(t,R))==null?void 0:q[I]);return!M||typeof M.$state!="string"?!1:(E({address:M.$state,nodeAddress:R,previousValue:xe(k,M.$state),value:O,data:k}),!0)};return{...S,onFormChange:E,onNodeCreateRequest:R=>{var M,q;const I=(M=R.sourceProperty)!=null&&M.startsWith("config:")?R.sourceProperty.slice(7):void 0,O=I!==void 0&&(g==null?void 0:g.slots.get(Rt(R.sourceNodeId,I)));return O?(O.present||E({data:k,nodeAddress:O.address.split(".").slice(0,-1).join("."),address:O.address,value:kt(O.type),previousValue:void 0}),!0):((q=S.onNodeCreateRequest)==null?void 0:q.call(S,R))??!1},onNodeDelete:(R,I)=>{var re,ce;if(!(g!=null&&g.nodes.some(he=>he.data.id===R)))return(re=S.onNodeDelete)==null?void 0:re.call(S,R,I);const O=g&&[...g.slots.values()].find(he=>he.nodeId===R);if(!O)return(ce=S.onNodeDelete)==null?void 0:ce.call(S,R,I);const M=O.address.split("."),q=M.pop(),K=M.join("."),V=xe(k,K);E(Array.isArray(V)?{data:k,nodeAddress:K,address:K,previousValue:V,value:V.filter((he,me)=>String(me)!==q)}:{data:k,nodeAddress:K,address:O.address,previousValue:xe(k,O.address),value:void 0})},onEdgeCreate:(R,I,O)=>{var K,V;const M=((K=O==null?void 0:O.targetProperty)==null?void 0:K.startsWith("config:"))&&(g==null?void 0:g.slots.get(Rt(I,O.targetProperty.slice(7)))),q=g==null?void 0:g.containers.get(R);if(M&&q&&(O==null?void 0:O.sourceProperty)==="output:resource"){const re=n0(k,q,M);re!==void 0&&E({data:k,nodeAddress:M.address.split(".").slice(0,-1).join("."),address:M.address,previousValue:xe(k,M.address),value:re});return}M||g!=null&&g.nodes.some(re=>re.data.id===R||re.data.id===I)||(V=S.onEdgeCreate)==null||V.call(S,R,I,O)},onEdgeDelete:(R,I)=>{var ce;const O=g==null?void 0:g.edges.find(he=>he.data.id===R);if(!O)return(ce=S.onEdgeDelete)==null?void 0:ce.call(S,R,I);const M=g.slots.get(Rt(O.data.target,O.data.targetProperty.slice(7))),q=M.address.split("."),K=q.pop(),V=q.join("."),re=xe(k,V);E(Array.isArray(re)?{data:k,nodeAddress:V,address:V,previousValue:re,value:re.filter((he,me)=>String(me)!==K)}:{data:k,nodeAddress:V,address:M.address,previousValue:xe(k,M.address),value:void 0})},onNodeContentChange:(R,I)=>{var O,M;P(R,"$content",I)?(O=a.onNodeContentChange)==null||O.call(a,R,I):(M=S.onNodeContentChange)==null||M.call(S,R,I)},onNodeLabelChange:(R,I)=>{var O,M;P(R,"$label",I)?(O=a.onNodeLabelChange)==null||O.call(a,R,I):(M=S.onNodeLabelChange)==null||M.call(S,R,I)}}},[S,r,t,a,g,i.readOnly,i.editable]);return h.jsx(kr.Provider,{value:{data:(r==null?void 0:r.state)??t,viewData:t,bindings:x,references:r==null?void 0:r.references,structured:g,renderForm:r==null?void 0:r.renderForm,editable:r?!!(r.onStateChange??r.onChange):!!a.onJsonChange,schema:w,setSchema:k=>{var E;f(k),(E=a.onFormSchemaChange)==null||E.call(a,k)},callbacks:T},children:h.jsx(my,{config:g?{...i,formSchema:w}:i,callbacks:T,nodes:_,edges:C,children:h.jsxs(F.Box,{className:s,"data-flow-diagram":"",style:u,width:"100%",height:"100%",position:"relative",overflow:"hidden",css:{"& input, & textarea, & select":{outline:"none !important",boxShadow:"none !important"}},children:[h.jsx(Bb,{nodes:_,edges:C}),c&&h.jsx(vm,{}),l]})})})}function L_(e){return Su(JSON.parse(e))}function Su(e){if(!e||typeof e!="object")throw new Error("Expected a JSON object or array.");const t=new Set,r=n=>{if(!(n===null||typeof n=="string"||typeof n=="boolean")&&!(typeof n=="number"&&Number.isFinite(n))){if(!n||typeof n!="object"||t.has(n)||!Array.isArray(n)&&![Object.prototype,null].includes(Object.getPrototypeOf(n)))throw new Error("Document must contain only finite, acyclic JSON values.");t.add(n);for(const[o,i]of Object.entries(n)){if(["__proto__","prototype","constructor"].includes(o))throw new Error(`Unsafe document key: ${o}`);r(i)}t.delete(n)}};return r(e),structuredClone(e)}function F_(e){return{replaceJson(t){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const r=Su(t);return e.onJsonChange(r,{type:"documentReplace",address:"root"}),r},replaceState(t){if(e.readOnly||!e.onStateChange)throw new Error("Form state is read-only.");const r=Su(t);return e.onStateChange(r,{address:"root",nodeAddress:"root",previousValue:e.state,value:r,data:r}),r}}}function B_(e,t){const r=(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,a)=>r(i,o[a])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,a])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i.startsWith("$")&&i!=="$")return JSON.stringify(a)===JSON.stringify(o[i])?[[i,a]]:[];const s=r(a,o[i]);return s===void 0?[]:[[i,s]]}))};return r(e,t)??{}}function cn(e){let t="",r=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},a=()=>{if(i(),!(r||!t.trim()))try{const u=e.parse(e.repair(t)),c=JSON.stringify(u);if(c===n)return;e.preview(u),n=c}catch{}},s=u=>{if(!r){if(new TextEncoder().encode(u).byteLength>(e.maxBytes??1024*1024))throw r=!0,i(),new Error("JSON stream exceeds the size limit.");t=u,o||(o=setTimeout(a,e.intervalMs??150))}};return{snapshot:s,append(u){s(t+u)},flush:a,finish(){if(r)throw new Error("JSON stream is closed.");r=!0,i();const u=e.parse(t);return e.commit(u),u},cancel(){r=!0,i(),t=""}}}function D_(e){const{source:t}=e,r=e.tickMs??50,n=e.durationMs??8e3;if(!Number.isFinite(r)||r<=0||!Number.isFinite(n)||n<=0)throw new Error("Playback timing must be positive.");if(new TextEncoder().encode(t).byteLength>(e.maxBytes??1024*1024))throw new Error("JSON stream exceeds the size limit.");e.parse(t);let o=cn(e),i=0,a=!1,s=!1,u;const c=Math.max(1,Math.ceil(t.length*r/n)),l=()=>e.onChange({position:i,total:t.length,playing:a}),d=()=>{clearTimeout(u),u=void 0},f=(y=!1)=>{o.snapshot(t.slice(0,i)),i===t.length?(a=!1,d(),o.finish()):y&&o.flush()},p=y=>{a=!1,d(),o.cancel(),l(),e.onError(y)},m=()=>{if(u=void 0,!(!a||s)){i=Math.min(t.length,i+c);try{f()}catch(y){p(y);return}l(),a&&(u=setTimeout(m,r))}};return{play(){s||a||(i===t.length&&(o.cancel(),o=cn(e),i=0),a=!0,l(),u=setTimeout(m,r))},pause(){s||(a=!1,d(),o.flush(),l())},seek(y){if(!s){if(!Number.isFinite(y))throw new Error("Playback position must be finite.");d(),i=Math.max(0,Math.min(t.length,Math.round(y))),o.cancel(),o=cn(e);try{f(!0)}catch(b){p(b);return}l(),a&&(u=setTimeout(m,r))}},dispose(){s=!0,a=!1,d(),o.cancel()}}}function z_({nodeAddress:e,expanded:t=!1}){var c;const{data:r,schema:n,bindings:o}=j.useContext(kr),{colorText:i,background:a}=Ve();if((c=o==null?void 0:o[e])!=null&&c.portResources)return null;const s=o&&Yt(o,e,n);if(!r||!s)return null;const u=xe(r,s.address);return!u||typeof u!="object"?null:h.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:fe(i),background:fe(a),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(s.type.properties).map(l=>{const d=s.fields[l]??{};if(!xn(d.$visibleWhen,r))return null;const f=u[l],p=f==null?"":typeof f=="object"?JSON.stringify(f):String(f);return h.jsxs("div",{"data-flow-property":l,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:[h.jsx("span",{style:{overflowWrap:"anywhere"},children:Cr(d.$label??l)}),h.jsx("span",{title:p,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:t?"pre-wrap":"nowrap",overflowWrap:t?"anywhere":void 0},children:p})]},l)})})}exports.BottomBar=vm;exports.CompactPropertyLayoutToggle=zy;exports.ConnectionsOnlyToggle=u0;exports.DEFAULT_PALETTE=Nu;exports.DiagramAppearanceControls=Wy;exports.DynamicIcon=Mr;exports.EdgeTools=um;exports.EditableLabel=Zt;exports.ErrorToast=ym;exports.FlowDiagram=N_;exports.FlowDiagramProvider=my;exports.FlowPort=Ob;exports.FlowView=Bb;exports.FormDocumentContext=kr;exports.NODE_TYPE_VIEWS=Bt;exports.NodeBorderRadiusControl=lm;exports.NodeConfigSummary=z_;exports.NodeForm=om;exports.NodeFormPopover=Ib;exports.NodeIconPicker=qu;exports.NodeTools=dm;exports.NodeView=Dn;exports.SvgExportButton=pm;exports.Swatches=Kt;exports.TEXT_PALETTE=sm;exports.ToolbarCloseButton=pt;exports.ToolbarCommitInput=Qr;exports.ToolbarDivider=It;exports.ToolbarIconButton=ve;exports.ToolbarRangeInput=Vy;exports.ToolbarScrollContainer=gm;exports.ToolbarSelect=Or;exports.ToolbarTooltip=je;exports.TooltipIconButton=_u;exports.WorkflowControls=mm;exports.addChild=Pu;exports.addConnection=Au;exports.addTargetEdge=Xy;exports.addressToPath=Ir;exports.applyCollapsed=Zx;exports.applyFormChange=wn;exports.applyStateEdits=Jx;exports.bindSqueedCallbacks=Cm;exports.compileSqueed=vu;exports.connectionIssue=Iu;exports.contentObjTheme=jr;exports.createFlowDiagram=Xr;exports.createFlowDocumentActions=F_;exports.createFormNode=wm;exports.createJsonPlayback=D_;exports.createJsonStream=cn;exports.downloadSvg=hm;exports.exportSvg=fm;exports.formValueError=Rr;exports.getChakraColorHex=fe;exports.getColorVariant=by;exports.getDarkerHexColor=un;exports.getInteractionSurface=Dr;exports.getNode=xe;exports.parseFlowDocument=L_;exports.parseJsonContract=Tu;exports.parseTypeScriptContract=em;exports.parseTypeScriptForm=Ou;exports.projectJsonPlaybackPreview=B_;exports.readFormSchema=Mu;exports.readWorkflowContract=rm;exports.removeEdge=Qy;exports.removeNode=Yy;exports.resolveEdgeOwner=Vt;exports.resolveStateView=tm;exports.setCollapsed=Zy;exports.setEdgeProp=Fr;exports.setEdgeStyle=Jy;exports.setNodeProp=ir;exports.updateNode=pr;exports.useCustomColors=Ve;exports.useEdgeProximity=hy;exports.useFlowData=Gr;exports.useFlowDiagramContext=Ie;exports.useNodeViewActions=zn;exports.useStopPropagation=tl;exports.useThemeContentColors=Jt;
182
186
  //# sourceMappingURL=index.cjs.map