@squeed/flow-sdk 2.0.10 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";var Yb=Object.create;var Yn=Object.defineProperty;var Xb=Object.getOwnPropertyDescriptor;var Qb=Object.getOwnPropertyNames;var ev=Object.getPrototypeOf,rv=Object.prototype.hasOwnProperty;var tv=(e,t,r)=>t in e?Yn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var nv=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Qb(t))!rv.call(e,o)&&o!==r&&Yn(e,o,{get:()=>t[o],enumerable:!(n=Xb(t,o))||n.enumerable});return e};var $e=(e,t,r)=>(r=e!=null?Yb(ev(e)):{},nv(t||!e||!e.__esModule?Yn(r,"default",{value:e,enumerable:!0}):r,e));var Ar=(e,t,r)=>tv(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),D=require("@chakra-ui/react"),S=require("react"),Z=require("react-icons/pi"),gy=require("@emotion/react"),ov=require("@emotion/styled"),iv=require("react-icons/tb"),Wt=require("react-dom"),av=require("markdown-to-jsx/react"),yy=e=>e&&e.__esModule?e:{default:e},xn=yy(ov),sv=yy(av);function my({edge:e,enabled:t,bounds:r,inside:n=[],threshold:o=80}){const[i,s]=S.useState(!1),[a,c]=S.useState(!1),u=S.useRef(n);return u.current=n,S.useEffect(()=>{if(!t)return;const l=()=>{const f=document.querySelectorAll(':popover-open, dialog[open], [role="dialog"], [role="menu"], [role="listbox"]');c(Array.from(f).some(p=>p.getClientRects().length>0&&!p.closest('[hidden], [aria-hidden="true"], [data-state="closed"]')&&getComputedStyle(p).visibility==="visible"))},d=new MutationObserver(l);return d.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["open","hidden","aria-hidden","data-state"]}),document.addEventListener("toggle",l,!0),l(),()=>{d.disconnect(),document.removeEventListener("toggle",l,!0)}},[t]),S.useEffect(()=>{const l=f=>{var m;const p=(m=r.current)==null?void 0:m.getBoundingClientRect();if(!p)return;const y=f.target instanceof Node?f.target:null,g=!!y&&u.current.some(w=>{var v;return(v=w.current)==null?void 0:v.contains(y)}),b=e==="bottom"?p.bottom-f.clientY:f.clientY-p.top,x=f.clientX>=p.left&&f.clientX<=p.right&&b>=0&&b<=o;s(g||x)},d=()=>s(!1);return document.addEventListener("pointermove",l,!0),document.addEventListener("pointerdown",l,!0),document.documentElement.addEventListener("pointerleave",d),()=>{document.removeEventListener("pointermove",l,!0),document.removeEventListener("pointerdown",l,!0),document.documentElement.removeEventListener("pointerleave",d)}},[e,r,o]),t&&(i||a)}const cv=gy.keyframes`
1
+ "use strict";var Xb=Object.create;var Xn=Object.defineProperty;var Qb=Object.getOwnPropertyDescriptor;var ev=Object.getOwnPropertyNames;var rv=Object.getPrototypeOf,tv=Object.prototype.hasOwnProperty;var nv=(e,t,r)=>t in e?Xn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ov=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ev(t))!tv.call(e,o)&&o!==r&&Xn(e,o,{get:()=>t[o],enumerable:!(n=Qb(t,o))||n.enumerable});return e};var Ve=(e,t,r)=>(r=e!=null?Xb(rv(e)):{},ov(t||!e||!e.__esModule?Xn(r,"default",{value:e,enumerable:!0}):r,e));var Or=(e,t,r)=>nv(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),z=require("@chakra-ui/react"),E=require("react"),J=require("react-icons/pi"),yy=require("@emotion/react"),iv=require("@emotion/styled"),av=require("react-icons/tb"),Ht=require("react-dom"),sv=require("markdown-to-jsx/react"),my=e=>e&&e.__esModule?e:{default:e},wn=my(iv),cv=my(sv);function by({edge:e,enabled:t,bounds:r,inside:n=[],threshold:o=80}){const[i,s]=E.useState(!1),[a,u]=E.useState(!1),c=E.useRef(n);return c.current=n,E.useEffect(()=>{if(!t)return;const l=()=>{const f=document.querySelectorAll(':popover-open, dialog[open], [role="dialog"], [role="menu"], [role="listbox"]');u(Array.from(f).some(p=>p.getClientRects().length>0&&!p.closest('[hidden], [aria-hidden="true"], [data-state="closed"]')&&getComputedStyle(p).visibility==="visible"))},d=new MutationObserver(l);return d.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["open","hidden","aria-hidden","data-state"]}),document.addEventListener("toggle",l,!0),l(),()=>{d.disconnect(),document.removeEventListener("toggle",l,!0)}},[t]),E.useEffect(()=>{const l=f=>{var m;const p=(m=r.current)==null?void 0:m.getBoundingClientRect();if(!p)return;const y=f.target instanceof Node?f.target:null,g=!!y&&c.current.some(w=>{var v;return(v=w.current)==null?void 0:v.contains(y)}),b=e==="bottom"?p.bottom-f.clientY:f.clientY-p.top,x=f.clientX>=p.left&&f.clientX<=p.right&&b>=0&&b<=o;s(g||x)},d=()=>s(!1);return document.addEventListener("pointermove",l,!0),document.addEventListener("pointerdown",l,!0),document.documentElement.addEventListener("pointerleave",d),()=>{document.removeEventListener("pointermove",l,!0),document.removeEventListener("pointerdown",l,!0),document.documentElement.removeEventListener("pointerleave",d)}},[e,r,o]),t&&(i||a)}const wt="#8c8c8d";function gn(e,t=.2){const r=e.replace(/^#/,""),n=parseInt(r,16);let o=n>>16&255,i=n>>8&255,s=n&255;return o=Math.max(0,Math.floor(o*(1-t))),i=Math.max(0,Math.floor(i*(1-t))),s=Math.max(0,Math.floor(s*(1-t))),"#"+((1<<24)+(o<<16)+(i<<8)+s).toString(16).slice(1).toUpperCase()}function hl(e,t,r){const n=a=>{const u=/^#?([0-9a-f]{6})$/i.exec((a==null?void 0:a.trim())??"");return u?parseInt(u[1],16):null},o=n(e),i=n(t);if(o===null||i===null)return null;const s=a=>Math.round((o>>a&255)*(1-r)+(i>>a&255)*r);return"#"+((1<<24)+(s(16)<<16)+(s(8)<<8)+s(0)).toString(16).slice(1).toUpperCase()}const Rr=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:gn(e,.1),border:gn(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"},vy=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let t=e;if(t!=null&&t.startsWith("#"))return{secondary:gn(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}},pl={red:{50:"#FFF5F5",100:"#FED7D7",200:"#FEB2B2",300:"#FC8181",400:"#F56565",500:"#E53E3E",600:"#C53030",700:"#9B2C2C",800:"#822727",900:"#63171B"},orange:{50:"#FFFAF0",100:"#FEEBC8",200:"#FBD38D",300:"#F6AD55",400:"#ED8936",500:"#DD6B20",600:"#C05621",700:"#9C4221",800:"#7B341E",900:"#652B19"},yellow:{50:"#FFFFF0",100:"#FEFCBF",200:"#FAF089",300:"#F6E05E",400:"#ECC94B",500:"#D69E2E",600:"#B7791F",700:"#975A16",800:"#744210",900:"#5F370E"},green:{50:"#F0FFF4",100:"#C6F6D5",200:"#9AE6B4",300:"#68D391",400:"#48BB78",500:"#38A169",600:"#2F855A",700:"#276749",800:"#22543D",900:"#1C4532"},teal:{50:"#E6FFFA",100:"#B2F5EA",200:"#81E6D9",300:"#4FD1C5",400:"#38B2AC",500:"#319795",600:"#2C7A7B",700:"#285E61",800:"#234E52",900:"#1D4044"},blue:{50:"#EBF8FF",100:"#BEE3F8",200:"#90CDF4",300:"#63B3ED",400:"#4299E1",500:"#3182CE",600:"#2B6CB0",700:"#2C5282",800:"#2A4365",900:"#1A365D"},cyan:{50:"#EDFDFD",100:"#C4F1F9",200:"#9DECF9",300:"#76E4F7",400:"#0BC5EA",500:"#00B5D8",600:"#00A3C4",700:"#0987A0",800:"#086F83",900:"#065666"},purple:{50:"#FAF5FF",100:"#E9D8FD",200:"#D6BCFA",300:"#B794F4",400:"#9F7AEA",500:"#805AD5",600:"#6B46C1",700:"#553C9A",800:"#44337A",900:"#322659"},pink:{50:"#FFF5F7",100:"#FED7E2",200:"#FBB6CE",300:"#F687B3",400:"#ED64A6",500:"#D53F8C",600:"#B83280",700:"#97266D",800:"#702459",900:"#521B41"},gray:{50:"#F7FAFC",100:"#EDF2F7",200:"#E2E8F0",300:"#CBD5E0",400:"#A0AEC0",500:"#718096",600:"#4A5568",700:"#2D3748",800:"#1A202C",900:"#171923",950:"#0d1117"}},me=(e,t)=>{var i;if(e==="transparent"||e!=null&&e.startsWith("#"))return e;if(!e)return"whitesmoke";const r=e.replace(/\./g,"-");try{const a=getComputedStyle(document.documentElement).getPropertyValue(`--chakra-colors-${r}`).trim();if(a&&a!=="")return a}catch{}const[n,o]=e.split(".");return n&&o&&((i=pl[n])!=null&&i[Number(o)])?pl[n][Number(o)]:`var(--chakra-colors-${r})`},uv=yy.keyframes`
2
2
  0%, 100% { box-shadow: var(--flow-rest-shadow); }
3
3
  25%, 50% { box-shadow: var(--flow-hover-shadow); }
4
- `,uv=gy.keyframes`
4
+ `,lv=yy.keyframes`
5
5
  from { box-shadow: var(--flow-start-shadow); }
6
6
  to { box-shadow: var(--flow-rest-shadow); }
7
- `;function by(e,t=!0,r="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,s=`0 0 0 ${t?8:0}px ${o}`,a=`0 0 0 8px ${o}`;return{boxShadow:s,css:{"--flow-rest-shadow":a,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[r]:{boxShadow:a,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${cv} 1200ms steps(10, end) 600ms`:"none"}}}}}}function zr(e,t){const{boxShadow:r,css:n}=by(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:`${uv} 600ms steps(5, end)`}}}}}const vy=S.createContext(null),xy=S.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function Ur(){return S.useContext(xy)}function Ie(){const e=S.useContext(vy);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function wy({config:e,callbacks:t,nodes:r=[],edges:n=[],children:o}){const i=S.useMemo(()=>{var qe,cr,Q;const ie=new Map;for(const F of r)(qe=F.data)!=null&&qe.id&&ie.set(F.data.id,F);const Me=new Map;for(const F of n)(cr=F.data)!=null&&cr.id&&Me.set(F.data.id,F);const Ke=new Set;for(const F of r)(Q=F.data)!=null&&Q.parent&&Ke.add(F.data.parent);return{nodeById:ie,edgeById:Me,parentIds:Ke}},[r,n]),s=S.useRef(null),[a,c]=S.useState([]),[u,l]=S.useState(null),[d,f]=S.useState(!0),[p,y]=S.useState(!1),[g,b]=S.useState(!0),[x,m]=S.useState(!1),[w,v]=S.useState(!1),[C,_]=S.useState(!0),[R,T]=S.useState(!1),[A,k]=S.useState("auto"),[j,E]=S.useState(!1),M=e.compactPropertyLayout??j,[I,N]=S.useState({}),O=e.nodeViewModes??I,W=[...i.nodeById.values()].filter(ie=>{var Me;return i.parentIds.has(ie.data.id)||((Me=ie.data.config)==null?void 0:Me.parentContainer)||ie.data.type==="objectView"||ie.data.type==="arrayView"}),G=!!W.length&&W.every(ie=>{var Me,Ke,qe;return i.parentIds.has(ie.data.id)||(Me=ie.data.config)!=null&&Me.parentContainer?!!((Ke=ie.data.config)!=null&&Ke.collapsed):O[ie.data.id]==="icon-label"||((qe=ie.data.config)==null?void 0:qe.labelBelow)&&O[ie.data.id]!=="properties"}),[ee,ne]=S.useState("normal"),[ce,me]=S.useState(),K=e.edgeRadius??ce,q=K!==void 0&&Number.isFinite(K)?Math.min(500,Math.max(0,K)):void 0,[L,z]=S.useState(),H=e.spacing??ee,X=typeof H=="number"?Number.isFinite(H)?Math.min(2,Math.max(.5,H)):1:H==="compact"?.5:H==="spacious"?2:1,le=e.backgroundVariant??L??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[J,V]=S.useState(),Y=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:J,[te,de]=S.useState("blue.500"),[ue,Se]=S.useState(!1),ye=S.useRef(t);ye.current=t;const De=S.useMemo(()=>{const ie=Me=>(...Ke)=>{var qe,cr;return(cr=(qe=ye.current)==null?void 0:qe[Me])==null?void 0:cr.call(qe,...Ke)};return{onNodeSelect:ie("onNodeSelect"),onBackgroundClick:ie("onBackgroundClick"),onNodeDeselect:ie("onNodeDeselect"),onNodeDoubleClick:ie("onNodeDoubleClick"),onNodeViewToggle:ie("onNodeViewToggle"),onNodeTypeViewChange:ie("onNodeTypeViewChange"),onNodeCreate:ie("onNodeCreate"),onNodeCreateRequest:ie("onNodeCreateRequest"),onNodeDelete:ie("onNodeDelete"),onNodeLabelChange:ie("onNodeLabelChange"),onNodeContentChange:ie("onNodeContentChange"),onNodeCollapse:ie("onNodeCollapse"),onNodeColorChange:ie("onNodeColorChange"),onNodeBorderColorChange:ie("onNodeBorderColorChange"),onNodeBorderStyleChange:ie("onNodeBorderStyleChange"),onNodeBorderWidthChange:ie("onNodeBorderWidthChange"),onNodeBorderRadiusChange:ie("onNodeBorderRadiusChange"),onNodeIconChange:ie("onNodeIconChange"),onNodeOutlineChange:ie("onNodeOutlineChange"),onNodeAnimationChange:ie("onNodeAnimationChange"),onNodeAnimationVariantChange:ie("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:ie("onEdgeAnimationVariantChange"),onNodeHoverAction:ie("onNodeHoverAction"),onEdgeCreate:ie("onEdgeCreate"),onEdgeSelect:ie("onEdgeSelect"),onEdgeDeselect:ie("onEdgeDeselect"),onEdgeRemove:ie("onEdgeRemove"),onEdgeDelete:ie("onEdgeDelete"),onEdgeColorChange:ie("onEdgeColorChange"),onEdgeTypeChange:ie("onEdgeTypeChange"),onEdgeIconChange:ie("onEdgeIconChange"),onEdgeLabelChange:ie("onEdgeLabelChange"),onEdgeStyleChange:ie("onEdgeStyleChange"),onViewportChange:ie("onViewportChange"),onDirectionChange:ie("onDirectionChange"),onThemeColorChange:ie("onThemeColorChange"),onSpacingChange:ie("onSpacingChange"),onEdgeRadiusChange:ie("onEdgeRadiusChange"),onBackgroundVariantChange:ie("onBackgroundVariantChange"),onEdgeModeChange:ie("onEdgeModeChange"),onCompactPropertyLayoutChange:ie("onCompactPropertyLayoutChange"),onWorkflowContractChange:ie("onWorkflowContractChange"),onArrayModeChange:ie("onArrayModeChange"),onInit:ie("onInit"),onLayoutComplete:ie("onLayoutComplete"),onJsonChange:ie("onJsonChange")}},[]),Le=e.themeColor||te,[He,ze]=S.useState(""),Ve=e.edgeColor??He,Fe=e.colorMode||"light",Ye=e.direction||"LR",ir=e.nodeAlignment??"center",be=e.edgeMode==="workflow"?"nodes":e.edgeMode??A,Pe=e.readOnly??!1,We=JSON.stringify(e.parentNodeStyle??null),pr=S.useMemo(()=>e.parentNodeStyle,[We]),er=e.isZoomMode!==void 0?e.isZoomMode:d,Qe=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,lr=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:x,ar=e.isDragMode!==void 0?e.isDragMode:g,xe=S.useRef(e);xe.current=e;const ct=S.useMemo(()=>({get direction(){return xe.current.direction},get nodeAlignment(){return xe.current.nodeAlignment},get edgeMode(){return xe.current.edgeMode},get compactPropertyLayout(){return xe.current.compactPropertyLayout},get edgeType(){return xe.current.edgeType},get edgeReveal(){return xe.current.edgeReveal},get customEdgeTypes(){return xe.current.customEdgeTypes},get themeColor(){return xe.current.themeColor},get colorMode(){return xe.current.colorMode},get readOnly(){return xe.current.readOnly},get editable(){return xe.current.editable},get minZoom(){return xe.current.minZoom},get maxZoom(){return xe.current.maxZoom},get backgroundPattern(){return xe.current.backgroundPattern},get edgeColor(){return xe.current.edgeColor},get parentNodeStyle(){return xe.current.parentNodeStyle},get backgroundColor(){return xe.current.backgroundColor},get edgeHandles(){return xe.current.edgeHandles},get initialViewport(){return xe.current.initialViewport},get animateViewport(){return xe.current.animateViewport},get nodeOverlayActions(){return xe.current.nodeOverlayActions},get renderNodeOverlay(){return xe.current.renderNodeOverlay},get renderSelectedNodeToolbar(){return xe.current.renderSelectedNodeToolbar},get renderSelectedEdgeToolbar(){return xe.current.renderSelectedEdgeToolbar},get renderBottomBar(){return xe.current.renderBottomBar},get bottomBarExtra(){return xe.current.bottomBarExtra},get selectionToolbar(){return xe.current.selectionToolbar},get customViews(){return xe.current.customViews},get disableKeyboardShortcuts(){return xe.current.disableKeyboardShortcuts},get isZoomMode(){return xe.current.isZoomMode},get isMultiSelectMode(){return xe.current.isMultiSelectMode},get isEdgeHandlesEnabled(){return xe.current.isEdgeHandlesEnabled},get isDragMode(){return xe.current.isDragMode}}),[]),dr=S.useCallback((ie,Me)=>{var Ke;if(Me!=="default"&&Me!=="properties"&&Me!=="icon-label")throw new Error("Unknown node view mode.");N(qe=>qe[ie]===Me?qe:{...qe,[ie]:Me}),(Ke=t.onNodeViewModeChange)==null||Ke.call(t,ie,Me)},[t.onNodeViewModeChange]),jt=S.useMemo(()=>({allNodesIconLabel:G,setAllNodesIconLabel:ie=>{var Me,Ke,qe,cr;if(!ie)for(const[Q,F]of Object.entries(O))F==="icon-label"&&!i.nodeById.has(Q)&&dr(Q,"default");for(const Q of W)i.parentIds.has(Q.data.id)||(Me=Q.data.config)!=null&&Me.parentContainer?!Pe&&!!((Ke=Q.data.config)!=null&&Ke.collapsed)!==ie&&((qe=t.onNodeCollapse)==null||qe.call(t,Q.data.id,ie)):dr(Q.data.id,ie?"icon-label":"default");(cr=t.onAllNodesIconLabelChange)==null||cr.call(t,ie)},nodeViewModes:O,setNodeViewMode:dr,spacing:X,setSpacing:ne,edgeRadius:q,setEdgeRadius:me,backgroundVariant:le,setBackgroundVariant:z,themeColor:Le,setThemeColor:de,backgroundSelected:ue,setBackgroundSelected:Se,edgeColor:Ve,setEdgeColor:ie=>{var Me;ze(ie),(Me=t.onGraphEdgeColorChange)==null||Me.call(t,ie)},colorMode:Fe,direction:Ye,nodeAlignment:ir,edgeMode:be,setEdgeMode:k,compactPropertyLayout:M,setCompactPropertyLayout:E,workflowContract:Y,setWorkflowContract:V,parentNodeStyle:pr,selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:u,setSelectedEdgeId:l,isZoomMode:er,setIsZoomMode:f,isMultiSelectMode:Qe,setIsMultiSelectMode:y,isDragMode:ar,setIsDragMode:b,isEdgeHandlesEnabled:lr,setIsEdgeHandlesEnabled:m,isArrayNodeMode:w,setIsArrayNodeMode:v,isPinned:C,setIsPinned:_,isPerformanceMode:R,setIsPerformanceMode:T,engineRef:s,callbacks:De,config:ct,readOnly:Pe}),[G,i,dr,t.onNodeCollapse,t.onAllNodesIconLabelChange,t.onGraphEdgeColorChange,O,t.onNodeViewModeChange,Le,X,le,q,e.backgroundColor,ue,Ve,Fe,Ye,ir,be,Y,pr,a,u,er,Qe,ar,lr,w,C,R,Pe,e.edgeHandles,e.edgeType,e.edgeReveal,e.animateViewport,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.compactPropertyLayout,M,De,ct]);return h.jsx(vy.Provider,{value:jt,children:h.jsx(xy.Provider,{value:i,children:o})})}function hn(e,t=.2){const r=e.replace(/^#/,""),n=parseInt(r,16);let o=n>>16&255,i=n>>8&255,s=n&255;return o=Math.max(0,Math.floor(o*(1-t))),i=Math.max(0,Math.floor(i*(1-t))),s=Math.max(0,Math.floor(s*(1-t))),"#"+((1<<24)+(o<<16)+(i<<8)+s).toString(16).slice(1).toUpperCase()}function fl(e,t,r){const n=a=>{const c=/^#?([0-9a-f]{6})$/i.exec((a==null?void 0:a.trim())??"");return c?parseInt(c[1],16):null},o=n(e),i=n(t);if(o===null||i===null)return null;const s=a=>Math.round((o>>a&255)*(1-r)+(i>>a&255)*r);return"#"+((1<<24)+(s(16)<<16)+(s(8)<<8)+s(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:hn(e,.1),border:hn(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"},Cy=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let t=e;if(t!=null&&t.startsWith("#"))return{secondary:hn(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}},hl={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"}},he=(e,t)=>{var i;if(e==="transparent"||e!=null&&e.startsWith("#"))return e;if(!e)return"whitesmoke";const r=e.replace(/\./g,"-");try{const a=getComputedStyle(document.documentElement).getPropertyValue(`--chakra-colors-${r}`).trim();if(a&&a!=="")return a}catch{}const[n,o]=e.split(".");return n&&o&&((i=hl[n])!=null&&i[Number(o)])?hl[n][Number(o)]:`var(--chakra-colors-${r})`};function nr(e,t,r){return e?r:t}function en(e){const[t]=(e==null?void 0:e.split("."))||[],{secondary:r}=Cy(e),n=Er(t).background,o=Er(t).highlight,i=Er(t).border,s=Er(t).property,a=Er(t).property;let c=Er(t).background,u=Er(t).highlight;return c=e==="transparent"?e:he(c)+50,u=e==="transparent"?e:he(u)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:s,propertyColor:a,secondary:r,bgColorFaint:c,highlightColorFaint:u}}function Je(e=null){const{colorMode:t}=Ie(),r=e==null?void 0:e.includes("gray"),n=t==="dark",o=nr(n,"white","gray.900"),i=nr(n,"gray.100","gray.800"),s=nr(n,"gray.200","blackAlpha.400"),a=nr(n,"gray.200","blackAlpha.600"),c=nr(n,"gray.500","gray.700"),u=nr(n,"gray.700","gray.700"),l=nr(n,"gray.900","gray.900"),d=nr(n,"gray.400","gray.500"),f=nr(n,"gray.400","gray.500"),p=nr(n,"gray.900","gray.200"),y=nr(n,r?"gray.900":"gray.200",r?"gray.200":"gray.900"),g=nr(n,"gray.900","gray.200"),b=nr(n,e&&"#000000",e||"#ffffff"),x=nr(n,e||"#ffffff",e?"#000000":"#ffffff"),m=u,w=nr(n,"gray.300","gray.800"),v=nr(n,"white","blackAlpha.400"),C=nr(n,"green.100","green.700");return{canvas:o,background:i,backgroundSecondary:s,darkBackgroundSecondary:a,border:c,darkColor:l,backgroundWhiteColor:v,borderSecondary:u,colorActive:d,colorInactive:f,iconColor:g,moreIconColor:m,colorText:p,themedColorText:y,logoColor:b,logoColorSecondary:x,darkColorActive:w,greenColor:C}}var Pt=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(Pt||{});const Gt=["","icon-label","object","text"];var lv=typeof global=="object"&&global&&global.Object===Object&&global,dv=typeof self=="object"&&self&&self.Object===Object&&self,fv=lv||dv||Function("return this")(),yt=fv.Symbol,_y=Object.prototype,hv=_y.hasOwnProperty,pv=_y.toString,Rt=yt?yt.toStringTag:void 0;function gv(e){var t=hv.call(e,Rt),r=e[Rt];try{e[Rt]=void 0;var n=!0}catch{}var o=pv.call(e);return n&&(t?e[Rt]=r:delete e[Rt]),o}var yv=Object.prototype,mv=yv.toString;function bv(e){return mv.call(e)}var vv="[object Null]",xv="[object Undefined]",pl=yt?yt.toStringTag:void 0;function wv(e){return e==null?e===void 0?xv:vv:pl&&pl in Object(e)?gv(e):bv(e)}function Cv(e){return e!=null&&typeof e=="object"}var _v="[object Symbol]";function Sv(e){return typeof e=="symbol"||Cv(e)&&wv(e)==_v}function Ev(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 Te=Array.isArray,gl=yt?yt.prototype:void 0,yl=gl?gl.toString:void 0;function Sy(e){if(typeof e=="string")return e;if(Te(e))return Ev(e,Sy)+"";if(Sv(e))return yl?yl.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function Pu(e){return e==null?"":Sy(e)}function jv(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 Rv(e,t,r){var n=e.length;return r=r===void 0?n:r,!t&&r>=n?e:jv(e,t,r)}var kv="\\ud800-\\udfff",Pv="\\u0300-\\u036f",Av="\\ufe20-\\ufe2f",Tv="\\u20d0-\\u20ff",Ov=Pv+Av+Tv,Iv="\\ufe0e\\ufe0f",Mv="\\u200d",qv=RegExp("["+Mv+kv+Ov+Iv+"]");function Ey(e){return qv.test(e)}function Nv(e){return e.split("")}var jy="\\ud800-\\udfff",$v="\\u0300-\\u036f",Lv="\\ufe20-\\ufe2f",Fv="\\u20d0-\\u20ff",Bv=$v+Lv+Fv,Dv="\\ufe0e\\ufe0f",zv="["+jy+"]",xu="["+Bv+"]",wu="\\ud83c[\\udffb-\\udfff]",Vv="(?:"+xu+"|"+wu+")",Ry="[^"+jy+"]",ky="(?:\\ud83c[\\udde6-\\uddff]){2}",Py="[\\ud800-\\udbff][\\udc00-\\udfff]",Wv="\\u200d",Ay=Vv+"?",Ty="["+Dv+"]?",Gv="(?:"+Wv+"(?:"+[Ry,ky,Py].join("|")+")"+Ty+Ay+")*",Uv=Ty+Ay+Gv,Hv="(?:"+[Ry+xu+"?",xu,ky,Py,zv].join("|")+")",Kv=RegExp(wu+"(?="+wu+")|"+Hv+Uv,"g");function Jv(e){return e.match(Kv)||[]}function Zv(e){return Ey(e)?Jv(e):Nv(e)}function Yv(e){return function(t){t=Pu(t);var r=Ey(t)?Zv(t):void 0,n=r?r[0]:t.charAt(0),o=r?Rv(r,1).join(""):t.slice(1);return n[e]()+o}}var Xv=Yv("toUpperCase");function Qv(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 ex(e){return function(t){return e==null?void 0:e[t]}}var rx={À:"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"},tx=ex(rx),nx=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,ox="\\u0300-\\u036f",ix="\\ufe20-\\ufe2f",ax="\\u20d0-\\u20ff",sx=ox+ix+ax,cx="["+sx+"]",ux=RegExp(cx,"g");function lx(e){return e=Pu(e),e&&e.replace(nx,tx).replace(ux,"")}var dx=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function fx(e){return e.match(dx)||[]}var hx=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function px(e){return hx.test(e)}var Oy="\\ud800-\\udfff",gx="\\u0300-\\u036f",yx="\\ufe20-\\ufe2f",mx="\\u20d0-\\u20ff",bx=gx+yx+mx,Iy="\\u2700-\\u27bf",My="a-z\\xdf-\\xf6\\xf8-\\xff",vx="\\xac\\xb1\\xd7\\xf7",xx="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",wx="\\u2000-\\u206f",Cx=" \\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",qy="A-Z\\xc0-\\xd6\\xd8-\\xde",_x="\\ufe0e\\ufe0f",Ny=vx+xx+wx+Cx,$y="['’]",ml="["+Ny+"]",Sx="["+bx+"]",Ly="\\d+",Ex="["+Iy+"]",Fy="["+My+"]",By="[^"+Oy+Ny+Ly+Iy+My+qy+"]",jx="\\ud83c[\\udffb-\\udfff]",Rx="(?:"+Sx+"|"+jx+")",kx="[^"+Oy+"]",Dy="(?:\\ud83c[\\udde6-\\uddff]){2}",zy="[\\ud800-\\udbff][\\udc00-\\udfff]",lt="["+qy+"]",Px="\\u200d",bl="(?:"+Fy+"|"+By+")",Ax="(?:"+lt+"|"+By+")",vl="(?:"+$y+"(?:d|ll|m|re|s|t|ve))?",xl="(?:"+$y+"(?:D|LL|M|RE|S|T|VE))?",Vy=Rx+"?",Wy="["+_x+"]?",Tx="(?:"+Px+"(?:"+[kx,Dy,zy].join("|")+")"+Wy+Vy+")*",Ox="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Ix="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",Mx=Wy+Vy+Tx,qx="(?:"+[Ex,Dy,zy].join("|")+")"+Mx,Nx=RegExp([lt+"?"+Fy+"+"+vl+"(?="+[ml,lt,"$"].join("|")+")",Ax+"+"+xl+"(?="+[ml,lt+bl,"$"].join("|")+")",lt+"?"+bl+"+"+vl,lt+"+"+xl,Ix,Ox,Ly,qx].join("|"),"g");function $x(e){return e.match(Nx)||[]}function Lx(e,t,r){return e=Pu(e),t=t,t===void 0?px(e)?$x(e):fx(e):e.match(t)||[]}var Fx="['’]",Bx=RegExp(Fx,"g");function Dx(e){return function(t){return Qv(Lx(lx(t).replace(Bx,"")),e,"")}}var wr=Dx(function(e,t,r){return e+(r?" ":"")+Xv(t)});function Re({label:e,children:t}){const r=S.cloneElement(t,{title:t.props.title??e});if(!D.Tooltip.Root){const n=D.Tooltip;return h.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:r})}return h.jsxs(D.Tooltip.Root,{positioning:{placement:"top"},children:[h.jsx(D.Tooltip.Trigger,{asChild:!0,children:r}),h.jsx(D.Portal,{children:h.jsx(D.Tooltip.Positioner,{children:h.jsx(D.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function $t(){const{border:e}=Je();return h.jsx(D.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:s,popupContent:a,labelCase:c="title","aria-label":u}){var j;const{colorMode:l}=Ie(),{background:d,border:f,colorText:p,colorActive:y,colorInactive:g}=Je(),b=l==="dark",x=S.useId(),m=S.useRef(null),w=S.useRef(null),[v,C]=S.useState(!1);S.useEffect(()=>{const E=w.current;E.setAttribute("popover","auto");const M=I=>C(I.newState==="open");return E.addEventListener("toggle",M),()=>E.removeEventListener("toggle",M)},[]);const _=S.Children.toArray(e).filter(S.isValidElement).map(E=>{const M=E.props;return{value:String(M.value),label:typeof M.children=="string"&&c==="title"?wr(M.children):M.children,disabled:M.disabled}}),R=()=>{var E;return(E=w.current)==null?void 0:E.hidePopover()},T=()=>{var W,G,ee,ne;const E=(W=m.current)==null?void 0:W.getBoundingClientRect(),M=w.current;if(!E||!M)return;const I=(ne=(ee=(G=m.current)==null?void 0:G.closest("[data-flow-toolbar-scroll]"))==null?void 0:ee.parentElement)==null?void 0:ne.getBoundingClientRect(),N=I??E;M.style.maxHeight=`${Math.max(60,Math.max(N.top-40,window.innerHeight-N.bottom-40))}px`;const O=M.getBoundingClientRect();M.style.left=`${Math.max(12,Math.min(Math.max((I==null?void 0:I.left)??12,E.right-O.width),((I==null?void 0:I.right)??window.innerWidth-12)-O.width,window.innerWidth-O.width-12))}px`,M.style.top=`${Math.max(12,N.top>=O.height+36?N.top-O.height-24:Math.min(N.bottom+24,window.innerHeight-O.height-12))}px`},A=()=>{var I,N,O,W,G,ee;if(n)return;if((I=w.current)==null||I.showPopover(),T(),a){(O=(N=w.current)==null?void 0:N.querySelector("input"))==null||O.focus({preventScroll:!0});return}const E=(W=w.current)==null?void 0:W.querySelectorAll('[role="option"]:not(:disabled)');(ee=((G=w.current)==null?void 0:G.querySelector('[aria-selected="true"]:not(:disabled)'))??(E==null?void 0:E[0]))==null||ee.focus()};S.useEffect(()=>{if(v){if(n){R();return}return window.addEventListener("resize",T),window.addEventListener("scroll",T,!0),()=>{window.removeEventListener("resize",T),window.removeEventListener("scroll",T,!0)}}},[v,n]);const k=`var(--chakra-colors-${d.replace(".","-")})`;return h.jsxs(h.Fragment,{children:[h.jsx(Re,{label:i??u,children:h.jsx(D.chakra.button,{ref:m,type:"button",role:"combobox","data-flow-select-icon":s?"":void 0,"aria-label":u,title:i??u,"aria-haspopup":a?"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:s?g:p,display:"flex",alignItems:"center",justifyContent:s?"center":"space-between",gap:2,style:o,onClick:()=>v?R():A(),onKeyDown:E=>{["ArrowDown","ArrowUp"].includes(E.key)&&(E.preventDefault(),A())},children:s??h.jsxs(h.Fragment,{children:[h.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((j=_.find(E=>E.value===t))==null?void 0:j.label)??t}),h.jsx(Z.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),h.jsx(D.chakra.div,{ref:w,id:x,role:a?"dialog":"listbox","aria-label":u,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"},'& [role="option"]':Cu,'& details [role="option"]:first-child':{borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},...zr(k,`var(--chakra-colors-${(b?f:"gray.300").replace(".","-")})`)},onKeyDown:E=>{var N,O,W;if(a&&!["Escape","Tab"].includes(E.key))return;const M=[...E.currentTarget.querySelectorAll('[role="option"]:not(:disabled)')],I=M.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(E.key)){E.preventDefault();const G=E.key==="Home"?0:E.key==="End"?M.length-1:(I+(E.key==="ArrowDown"?1:-1)+M.length)%M.length;(N=M[G])==null||N.focus()}else E.key==="Escape"||E.key==="Tab"?(E.key==="Escape"&&(E.preventDefault(),E.stopPropagation()),R(),(O=m.current)==null||O.focus()):E.key.length===1&&E.key!==" "&&((W=M.find((G,ee)=>{var ne;return ee>I&&((ne=G.textContent)==null?void 0:ne.toLowerCase().startsWith(E.key.toLowerCase()))}))==null||W.focus())},children:a??_.map(E=>h.jsxs(D.chakra.button,{type:"button",role:"option","aria-selected":E.value===t,disabled:E.disabled,tabIndex:-1,display:"flex",alignItems:"center",gap:3,px:3,py:2,w:"100%",fontSize:"sm",textAlign:"left",bg:"transparent",color:p,_hover:{bg:b?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:b?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var M;R(),(M=m.current)==null||M.focus(),r(E.value)},children:[h.jsx("span",{style:{flex:1},children:E.label}),h.jsx(Z.PiCheck,{size:16,color:`var(--chakra-colors-${y.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:E.value===t?"visible":"hidden"}})]},E.value))})]})}const Cu={borderRadius:"4px","&:first-child":{borderTopLeftRadius:"22px",borderTopRightRadius:"22px"},"&:last-child":{borderBottomLeftRadius:"22px",borderBottomRightRadius:"22px"}},ve=S.forwardRef(function({icon:t,...r},n){const{colorMode:o}=Ie();return h.jsx(D.IconButton,{ref:n,_hover:{bg:o==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:r.title??r["aria-label"],...r,children:t})}),vt=S.forwardRef(function(t,r){const{themeColor:n}=Ie();return h.jsx(Re,{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 Au({label:e,icon:t,checked:r,onChange:n,disabled:o}){const{themeColor:i,readOnly:s}=Ie(),{colorInactive:a}=Je();return h.jsx(Re,{label:e,children:h.jsx(ve,{"aria-label":e,"aria-pressed":r,icon:h.jsxs(h.Fragment,{children:[t,h.jsx(D.Text,{as:"span",fontSize:"xs",fontWeight:"normal",whiteSpace:"nowrap",children:e})]}),size:"sm",variant:"ghost",width:"auto",px:2,gap:2,color:r?i:a,disabled:o||s,onClick:()=>n(!r)})})}function Gy({label:e="Compact layout"}={}){const{compactPropertyLayout:t,setCompactPropertyLayout:r,callbacks:n}=Ie();return h.jsx(Au,{label:e,checked:t,icon:h.jsx(D.Icon,{as:Z.PiArrowsIn,boxSize:5}),onChange:o=>{var i;r(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const zx=xn.default.input`
7
+ `;function xy(e,t=!0,r="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,s=`0 0 0 ${t?8:0}px ${o}`,a=`0 0 0 8px ${o}`;return{boxShadow:s,css:{"--flow-rest-shadow":a,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[r]:{boxShadow:a,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${uv} 1200ms steps(10, end) 600ms`:"none"}}}}}}function Vr(e,t){const{boxShadow:r,css:n}=xy(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:`${lv} 600ms steps(5, end)`}}}}}const wy=E.createContext(null),Cy=E.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function Hr(){return E.useContext(Cy)}function $e(){const e=E.useContext(wy);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function _y({config:e,callbacks:t,nodes:r=[],edges:n=[],children:o}){const i=E.useMemo(()=>{var Be,lr,re;const ie=new Map;for(const F of r)(Be=F.data)!=null&&Be.id&&ie.set(F.data.id,F);const Fe=new Map;for(const F of n)(lr=F.data)!=null&&lr.id&&Fe.set(F.data.id,F);const Ze=new Set;for(const F of r)(re=F.data)!=null&&re.parent&&Ze.add(F.data.parent);return{nodeById:ie,edgeById:Fe,parentIds:Ze}},[r,n]),s=E.useRef(null),[a,u]=E.useState([]),[c,l]=E.useState(null),[d,f]=E.useState(!0),[p,y]=E.useState(!1),[g,b]=E.useState(!0),[x,m]=E.useState(!1),[w,v]=E.useState(!1),[C,S]=E.useState(!0),[j,T]=E.useState(!1),[k,M]=E.useState("auto"),[R,_]=E.useState(!1),A=e.compactPropertyLayout??R,[I,q]=E.useState({}),O=e.nodeViewModes??I,W=[...i.nodeById.values()].filter(ie=>{var Fe;return i.parentIds.has(ie.data.id)||((Fe=ie.data.config)==null?void 0:Fe.parentContainer)||ie.data.type==="objectView"||ie.data.type==="arrayView"}),V=!!W.length&&W.every(ie=>{var Fe,Ze,Be;return i.parentIds.has(ie.data.id)||(Fe=ie.data.config)!=null&&Fe.parentContainer?!!((Ze=ie.data.config)!=null&&Ze.collapsed):O[ie.data.id]==="icon-label"||((Be=ie.data.config)==null?void 0:Be.labelBelow)&&O[ie.data.id]!=="properties"}),[ue,ne]=E.useState("normal"),[Q,he]=E.useState(),le=e.edgeRadius??Q,$=le!==void 0&&Number.isFinite(le)?Math.min(500,Math.max(0,le)):void 0,[D,G]=E.useState(),N=e.spacing??ue,ee=typeof N=="number"?Number.isFinite(N)?Math.min(2,Math.max(.5,N)):1:N==="compact"?.5:N==="spacious"?2:1,ge=e.backgroundVariant??D??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[ye,K]=E.useState(),X=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:ye,[U,se]=E.useState("blue.500"),[te,xe]=E.useState(!1),pe=E.useRef(t);pe.current=t;const De=E.useMemo(()=>{const ie=Fe=>(...Ze)=>{var Be,lr;return(lr=(Be=pe.current)==null?void 0:Be[Fe])==null?void 0:lr.call(Be,...Ze)};return{onNodeSelect:ie("onNodeSelect"),onBackgroundClick:ie("onBackgroundClick"),onNodeDeselect:ie("onNodeDeselect"),onNodeDoubleClick:ie("onNodeDoubleClick"),onNodeViewToggle:ie("onNodeViewToggle"),onNodeTypeViewChange:ie("onNodeTypeViewChange"),onNodeCreate:ie("onNodeCreate"),onNodeCreateRequest:ie("onNodeCreateRequest"),onNodeDelete:ie("onNodeDelete"),onNodeLabelChange:ie("onNodeLabelChange"),onNodeContentChange:ie("onNodeContentChange"),onNodeCollapse:ie("onNodeCollapse"),onNodeColorChange:ie("onNodeColorChange"),onNodeBorderColorChange:ie("onNodeBorderColorChange"),onNodeBorderStyleChange:ie("onNodeBorderStyleChange"),onNodeBorderWidthChange:ie("onNodeBorderWidthChange"),onNodeBorderRadiusChange:ie("onNodeBorderRadiusChange"),onNodeIconChange:ie("onNodeIconChange"),onNodeOutlineChange:ie("onNodeOutlineChange"),onNodeAnimationChange:ie("onNodeAnimationChange"),onNodeAnimationVariantChange:ie("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:ie("onEdgeAnimationVariantChange"),onNodeHoverAction:ie("onNodeHoverAction"),onEdgeCreate:ie("onEdgeCreate"),onEdgeSelect:ie("onEdgeSelect"),onEdgeDeselect:ie("onEdgeDeselect"),onEdgeRemove:ie("onEdgeRemove"),onEdgeDelete:ie("onEdgeDelete"),onEdgeColorChange:ie("onEdgeColorChange"),onEdgeTypeChange:ie("onEdgeTypeChange"),onEdgeIconChange:ie("onEdgeIconChange"),onEdgeLabelChange:ie("onEdgeLabelChange"),onEdgeStyleChange:ie("onEdgeStyleChange"),onViewportChange:ie("onViewportChange"),onDirectionChange:ie("onDirectionChange"),onThemeColorChange:ie("onThemeColorChange"),onSpacingChange:ie("onSpacingChange"),onEdgeRadiusChange:ie("onEdgeRadiusChange"),onBackgroundVariantChange:ie("onBackgroundVariantChange"),onEdgeModeChange:ie("onEdgeModeChange"),onCompactPropertyLayoutChange:ie("onCompactPropertyLayoutChange"),onWorkflowContractChange:ie("onWorkflowContractChange"),onArrayModeChange:ie("onArrayModeChange"),onInit:ie("onInit"),onLayoutComplete:ie("onLayoutComplete"),onJsonChange:ie("onJsonChange")}},[]),Z=e.themeColor||U,[de,Ce]=E.useState(""),Ie=e.edgeColor??de,qe=e.colorMode||"light",Ue=e.direction||"LR",Qe=e.nodeAlignment??"center",We=e.edgeMode==="workflow"?"nodes":e.edgeMode??k,we=e.readOnly??!1,_e=JSON.stringify(e.parentNodeStyle??null),He=E.useMemo(()=>e.parentNodeStyle,[_e]),Xe=e.isZoomMode!==void 0?e.isZoomMode:d,ur=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,er=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:x,sr=e.isDragMode!==void 0?e.isDragMode:g,Ee=E.useRef(e);Ee.current=e;const ut=E.useMemo(()=>({get direction(){return Ee.current.direction},get nodeAlignment(){return Ee.current.nodeAlignment},get edgeMode(){return Ee.current.edgeMode},get compactPropertyLayout(){return Ee.current.compactPropertyLayout},get edgeType(){return Ee.current.edgeType},get edgeReveal(){return Ee.current.edgeReveal},get customEdgeTypes(){return Ee.current.customEdgeTypes},get themeColor(){return Ee.current.themeColor},get colorMode(){return Ee.current.colorMode},get readOnly(){return Ee.current.readOnly},get editable(){return Ee.current.editable},get minZoom(){return Ee.current.minZoom},get maxZoom(){return Ee.current.maxZoom},get backgroundPattern(){return Ee.current.backgroundPattern},get edgeColor(){return Ee.current.edgeColor},get parentNodeStyle(){return Ee.current.parentNodeStyle},get backgroundColor(){return Ee.current.backgroundColor},get edgeHandles(){return Ee.current.edgeHandles},get initialViewport(){return Ee.current.initialViewport},get animateViewport(){return Ee.current.animateViewport},get nodeOverlayActions(){return Ee.current.nodeOverlayActions},get renderNodeOverlay(){return Ee.current.renderNodeOverlay},get renderSelectedNodeToolbar(){return Ee.current.renderSelectedNodeToolbar},get renderSelectedEdgeToolbar(){return Ee.current.renderSelectedEdgeToolbar},get renderBottomBar(){return Ee.current.renderBottomBar},get bottomBarExtra(){return Ee.current.bottomBarExtra},get selectionToolbar(){return Ee.current.selectionToolbar},get customViews(){return Ee.current.customViews},get disableKeyboardShortcuts(){return Ee.current.disableKeyboardShortcuts},get isZoomMode(){return Ee.current.isZoomMode},get isMultiSelectMode(){return Ee.current.isMultiSelectMode},get isEdgeHandlesEnabled(){return Ee.current.isEdgeHandlesEnabled},get isDragMode(){return Ee.current.isDragMode}}),[]),fr=E.useCallback((ie,Fe)=>{var Ze;if(Fe!=="default"&&Fe!=="properties"&&Fe!=="icon-label")throw new Error("Unknown node view mode.");q(Be=>Be[ie]===Fe?Be:{...Be,[ie]:Fe}),(Ze=t.onNodeViewModeChange)==null||Ze.call(t,ie,Fe)},[t.onNodeViewModeChange]),Pt=E.useMemo(()=>({allNodesIconLabel:V,setAllNodesIconLabel:ie=>{var Fe,Ze,Be,lr,re;if(!ie)for(const[F,Y]of Object.entries(O))Y==="icon-label"&&!i.nodeById.has(F)&&fr(F,"default");for(const F of W)i.parentIds.has(F.data.id)||(Fe=F.data.config)!=null&&Fe.parentContainer?!we&&!!((Ze=F.data.config)!=null&&Ze.collapsed)!==ie&&((Be=t.onNodeCollapse)==null||Be.call(t,F.data.id,ie)):fr(F.data.id,ie?"icon-label":(lr=F.data.config)!=null&&lr.labelBelow?"properties":"default");(re=t.onAllNodesIconLabelChange)==null||re.call(t,ie)},nodeViewModes:O,setNodeViewMode:fr,spacing:ee,setSpacing:ne,edgeRadius:$,setEdgeRadius:he,backgroundVariant:ge,setBackgroundVariant:G,themeColor:Z,setThemeColor:se,backgroundSelected:te,setBackgroundSelected:xe,edgeColor:Ie,setEdgeColor:ie=>{var Fe;Ce(ie),(Fe=t.onGraphEdgeColorChange)==null||Fe.call(t,ie)},colorMode:qe,direction:Ue,nodeAlignment:Qe,edgeMode:We,setEdgeMode:M,compactPropertyLayout:A,setCompactPropertyLayout:_,workflowContract:X,setWorkflowContract:K,parentNodeStyle:He,selectedNodeIds:a,setSelectedNodeIds:u,selectedEdgeId:c,setSelectedEdgeId:l,isZoomMode:Xe,setIsZoomMode:f,isMultiSelectMode:ur,setIsMultiSelectMode:y,isDragMode:sr,setIsDragMode:b,isEdgeHandlesEnabled:er,setIsEdgeHandlesEnabled:m,isArrayNodeMode:w,setIsArrayNodeMode:v,isPinned:C,setIsPinned:S,isPerformanceMode:j,setIsPerformanceMode:T,engineRef:s,callbacks:De,config:ut,readOnly:we}),[V,i,fr,t.onNodeCollapse,t.onAllNodesIconLabelChange,t.onGraphEdgeColorChange,O,t.onNodeViewModeChange,Z,ee,ge,$,e.backgroundColor,te,Ie,qe,Ue,Qe,We,X,He,a,c,Xe,ur,sr,er,w,C,j,we,e.edgeHandles,e.edgeType,e.edgeReveal,e.animateViewport,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.compactPropertyLayout,A,De,ut]);return h.jsx(wy.Provider,{value:Pt,children:h.jsx(Cy.Provider,{value:i,children:o})})}function ir(e,t,r){return e?r:t}function tn(e){const[t]=(e==null?void 0:e.split("."))||[],{secondary:r}=vy(e),n=Rr(t).background,o=Rr(t).highlight,i=Rr(t).border,s=Rr(t).property,a=Rr(t).property;let u=Rr(t).background,c=Rr(t).highlight;return u=e==="transparent"?e:me(u)+50,c=e==="transparent"?e:me(c)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:s,propertyColor:a,secondary:r,bgColorFaint:u,highlightColorFaint:c}}function Ye(e=null){const{colorMode:t}=$e(),r=e==null?void 0:e.includes("gray"),n=t==="dark",o=ir(n,"white","gray.900"),i=ir(n,"gray.100","gray.800"),s=ir(n,"gray.200","blackAlpha.400"),a=ir(n,"gray.200","blackAlpha.600"),u=ir(n,"gray.500","gray.700"),c=ir(n,"gray.700","gray.700"),l=ir(n,"gray.900","gray.900"),d=ir(n,"gray.400","gray.500"),f=ir(n,"gray.400","gray.500"),p=ir(n,"gray.900","gray.200"),y=ir(n,r?"gray.900":"gray.200",r?"gray.200":"gray.900"),g=ir(n,"gray.900","gray.200"),b=ir(n,e&&"#000000",e||"#ffffff"),x=ir(n,e||"#ffffff",e?"#000000":"#ffffff"),m=c,w=ir(n,"gray.300","gray.800"),v=ir(n,"white","blackAlpha.400"),C=ir(n,"green.100","green.700");return{canvas:o,background:i,backgroundSecondary:s,darkBackgroundSecondary:a,border:u,darkColor:l,backgroundWhiteColor:v,borderSecondary:c,colorActive:d,colorInactive:f,iconColor:g,moreIconColor:m,colorText:p,themedColorText:y,logoColor:b,logoColorSecondary:x,darkColorActive:w,greenColor:C}}var Ot=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(Ot||{});const Kt=["","icon-label","object","text"];var dv=typeof global=="object"&&global&&global.Object===Object&&global,fv=typeof self=="object"&&self&&self.Object===Object&&self,hv=dv||fv||Function("return this")(),mt=hv.Symbol,Sy=Object.prototype,pv=Sy.hasOwnProperty,gv=Sy.toString,At=mt?mt.toStringTag:void 0;function yv(e){var t=pv.call(e,At),r=e[At];try{e[At]=void 0;var n=!0}catch{}var o=gv.call(e);return n&&(t?e[At]=r:delete e[At]),o}var mv=Object.prototype,bv=mv.toString;function vv(e){return bv.call(e)}var xv="[object Null]",wv="[object Undefined]",gl=mt?mt.toStringTag:void 0;function Cv(e){return e==null?e===void 0?wv:xv:gl&&gl in Object(e)?yv(e):vv(e)}function _v(e){return e!=null&&typeof e=="object"}var Sv="[object Symbol]";function Ev(e){return typeof e=="symbol"||_v(e)&&Cv(e)==Sv}function jv(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 Ne=Array.isArray,yl=mt?mt.prototype:void 0,ml=yl?yl.toString:void 0;function Ey(e){if(typeof e=="string")return e;if(Ne(e))return jv(e,Ey)+"";if(Ev(e))return ml?ml.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function Au(e){return e==null?"":Ey(e)}function Rv(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 kv(e,t,r){var n=e.length;return r=r===void 0?n:r,!t&&r>=n?e:Rv(e,t,r)}var Pv="\\ud800-\\udfff",Av="\\u0300-\\u036f",Tv="\\ufe20-\\ufe2f",Ov="\\u20d0-\\u20ff",Iv=Av+Tv+Ov,Mv="\\ufe0e\\ufe0f",qv="\\u200d",Nv=RegExp("["+qv+Pv+Iv+Mv+"]");function jy(e){return Nv.test(e)}function $v(e){return e.split("")}var Ry="\\ud800-\\udfff",Lv="\\u0300-\\u036f",Fv="\\ufe20-\\ufe2f",Bv="\\u20d0-\\u20ff",zv=Lv+Fv+Bv,Dv="\\ufe0e\\ufe0f",Vv="["+Ry+"]",wu="["+zv+"]",Cu="\\ud83c[\\udffb-\\udfff]",Wv="(?:"+wu+"|"+Cu+")",ky="[^"+Ry+"]",Py="(?:\\ud83c[\\udde6-\\uddff]){2}",Ay="[\\ud800-\\udbff][\\udc00-\\udfff]",Gv="\\u200d",Ty=Wv+"?",Oy="["+Dv+"]?",Uv="(?:"+Gv+"(?:"+[ky,Py,Ay].join("|")+")"+Oy+Ty+")*",Hv=Oy+Ty+Uv,Kv="(?:"+[ky+wu+"?",wu,Py,Ay,Vv].join("|")+")",Jv=RegExp(Cu+"(?="+Cu+")|"+Kv+Hv,"g");function Zv(e){return e.match(Jv)||[]}function Yv(e){return jy(e)?Zv(e):$v(e)}function Xv(e){return function(t){t=Au(t);var r=jy(t)?Yv(t):void 0,n=r?r[0]:t.charAt(0),o=r?kv(r,1).join(""):t.slice(1);return n[e]()+o}}var Qv=Xv("toUpperCase");function ex(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 rx(e){return function(t){return e==null?void 0:e[t]}}var tx={À:"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"},nx=rx(tx),ox=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,ix="\\u0300-\\u036f",ax="\\ufe20-\\ufe2f",sx="\\u20d0-\\u20ff",cx=ix+ax+sx,ux="["+cx+"]",lx=RegExp(ux,"g");function dx(e){return e=Au(e),e&&e.replace(ox,nx).replace(lx,"")}var fx=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function hx(e){return e.match(fx)||[]}var px=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function gx(e){return px.test(e)}var Iy="\\ud800-\\udfff",yx="\\u0300-\\u036f",mx="\\ufe20-\\ufe2f",bx="\\u20d0-\\u20ff",vx=yx+mx+bx,My="\\u2700-\\u27bf",qy="a-z\\xdf-\\xf6\\xf8-\\xff",xx="\\xac\\xb1\\xd7\\xf7",wx="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Cx="\\u2000-\\u206f",_x=" \\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",Ny="A-Z\\xc0-\\xd6\\xd8-\\xde",Sx="\\ufe0e\\ufe0f",$y=xx+wx+Cx+_x,Ly="['’]",bl="["+$y+"]",Ex="["+vx+"]",Fy="\\d+",jx="["+My+"]",By="["+qy+"]",zy="[^"+Iy+$y+Fy+My+qy+Ny+"]",Rx="\\ud83c[\\udffb-\\udfff]",kx="(?:"+Ex+"|"+Rx+")",Px="[^"+Iy+"]",Dy="(?:\\ud83c[\\udde6-\\uddff]){2}",Vy="[\\ud800-\\udbff][\\udc00-\\udfff]",dt="["+Ny+"]",Ax="\\u200d",vl="(?:"+By+"|"+zy+")",Tx="(?:"+dt+"|"+zy+")",xl="(?:"+Ly+"(?:d|ll|m|re|s|t|ve))?",wl="(?:"+Ly+"(?:D|LL|M|RE|S|T|VE))?",Wy=kx+"?",Gy="["+Sx+"]?",Ox="(?:"+Ax+"(?:"+[Px,Dy,Vy].join("|")+")"+Gy+Wy+")*",Ix="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Mx="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",qx=Gy+Wy+Ox,Nx="(?:"+[jx,Dy,Vy].join("|")+")"+qx,$x=RegExp([dt+"?"+By+"+"+xl+"(?="+[bl,dt,"$"].join("|")+")",Tx+"+"+wl+"(?="+[bl,dt+vl,"$"].join("|")+")",dt+"?"+vl+"+"+xl,dt+"+"+wl,Mx,Ix,Fy,Nx].join("|"),"g");function Lx(e){return e.match($x)||[]}function Fx(e,t,r){return e=Au(e),t=t,t===void 0?gx(e)?Lx(e):hx(e):e.match(t)||[]}var Bx="['’]",zx=RegExp(Bx,"g");function Dx(e){return function(t){return ex(Fx(dx(t).replace(zx,"")),e,"")}}var Cr=Dx(function(e,t,r){return e+(r?" ":"")+Qv(t)});function Te({label:e,children:t}){const r=E.cloneElement(t,{title:t.props.title??e});if(!z.Tooltip.Root){const n=z.Tooltip;return h.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:r})}return h.jsxs(z.Tooltip.Root,{positioning:{placement:"top"},children:[h.jsx(z.Tooltip.Trigger,{asChild:!0,children:r}),h.jsx(z.Portal,{children:h.jsx(z.Tooltip.Positioner,{children:h.jsx(z.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function Ft(){const{border:e}=Ye(),{colorMode:t}=$e();return h.jsx(z.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:t==="dark"?e:"gray.300"})}function br({children:e,value:t,onValueChange:r,disabled:n,style:o,title:i,icon:s,popupContent:a,labelCase:u="title","aria-label":c,...l}){var R;const{colorMode:d}=$e(),{background:f,border:p,colorText:y,colorInactive:g}=Ye(),b=d==="dark",x=E.useId(),m=E.useRef(null),w=E.useRef(null),[v,C]=E.useState(!1);E.useEffect(()=>{const _=w.current;_.setAttribute("popover","auto");const A=I=>C(I.newState==="open");return _.addEventListener("toggle",A),()=>_.removeEventListener("toggle",A)},[]);const S=E.Children.toArray(e).filter(E.isValidElement).map(_=>{const A=_.props;return{value:String(A.value),label:typeof A.children=="string"&&u==="title"?Cr(A.children):A.children,disabled:A.disabled}}),j=()=>{var _;return(_=w.current)==null?void 0:_.hidePopover()},T=()=>{var W,V,ue,ne;const _=(W=m.current)==null?void 0:W.getBoundingClientRect(),A=w.current;if(!_||!A)return;const I=(ne=(ue=(V=m.current)==null?void 0:V.closest("[data-flow-toolbar-scroll]"))==null?void 0:ue.parentElement)==null?void 0:ne.getBoundingClientRect(),q=I??_;A.style.maxHeight=`${Math.max(60,Math.max(q.top-40,window.innerHeight-q.bottom-40))}px`;const O=A.getBoundingClientRect();A.style.left=`${Math.max(12,Math.min(Math.max((I==null?void 0:I.left)??12,_.right-O.width),((I==null?void 0:I.right)??window.innerWidth-12)-O.width,window.innerWidth-O.width-12))}px`,A.style.top=`${Math.max(12,q.top>=O.height+36?q.top-O.height-24:Math.min(q.bottom+24,window.innerHeight-O.height-12))}px`},k=()=>{var I,q,O,W,V,ue;if(n)return;if((I=w.current)==null||I.showPopover(),T(),a){(O=(q=w.current)==null?void 0:q.querySelector("input"))==null||O.focus({preventScroll:!0});return}const _=(W=w.current)==null?void 0:W.querySelectorAll('[role="option"]:not(:disabled)');(ue=((V=w.current)==null?void 0:V.querySelector('[aria-selected="true"]:not(:disabled)'))??(_==null?void 0:_[0]))==null||ue.focus()};E.useEffect(()=>{if(v){if(n){j();return}return window.addEventListener("resize",T),window.addEventListener("scroll",T,!0),()=>{window.removeEventListener("resize",T),window.removeEventListener("scroll",T,!0)}}},[v,n]);const M=`var(--chakra-colors-${f.replace(".","-")})`;return h.jsxs(h.Fragment,{children:[h.jsx(Te,{label:i??c,children:h.jsx(z.chakra.button,{...l,ref:m,type:"button",role:"combobox","data-flow-select-icon":s?"":void 0,"aria-label":c,title:i??c,"aria-haspopup":a?"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:s?g:y,display:"flex",alignItems:"center",justifyContent:s?"center":"space-between",gap:2,style:o,onClick:()=>v?j():k(),onKeyDown:_=>{["ArrowDown","ArrowUp"].includes(_.key)&&(_.preventDefault(),k())},children:s??h.jsxs(h.Fragment,{children:[h.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((R=S.find(_=>_.value===t))==null?void 0:R.label)??t}),h.jsx(J.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),h.jsx(z.chakra.div,{ref:w,id:x,role:a?"dialog":"listbox","aria-label":c,position:"fixed",m:0,p:2,minW:"180px",maxW:"calc(100vw - 24px)",overflowY:"auto",bg:f,color:y,borderRadius:"30px",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"},'& [role="option"]':_u,'& details [role="option"]:first-child':{borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},...Vr(M,`var(--chakra-colors-${(b?p:"gray.300").replace(".","-")})`)},onKeyDown:_=>{var q,O,W;if(a&&!["Escape","Tab"].includes(_.key))return;const A=[..._.currentTarget.querySelectorAll('[role="option"]:not(:disabled)')],I=A.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(_.key)){_.preventDefault();const V=_.key==="Home"?0:_.key==="End"?A.length-1:(I+(_.key==="ArrowDown"?1:-1)+A.length)%A.length;(q=A[V])==null||q.focus()}else _.key==="Escape"||_.key==="Tab"?(_.key==="Escape"&&(_.preventDefault(),_.stopPropagation()),j(),(O=m.current)==null||O.focus()):_.key.length===1&&_.key!==" "&&((W=A.find((V,ue)=>{var ne;return ue>I&&((ne=V.textContent)==null?void 0:ne.toLowerCase().startsWith(_.key.toLowerCase()))}))==null||W.focus())},children:a??S.map(_=>h.jsxs(z.chakra.button,{type:"button",role:"option","aria-selected":_.value===t,disabled:_.disabled,tabIndex:-1,display:"flex",alignItems:"center",gap:3,px:3,py:2,w:"100%",fontSize:"sm",textAlign:"left",bg:"transparent",color:y,_hover:{bg:b?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:b?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var A;j(),(A=m.current)==null||A.focus(),r(_.value)},children:[h.jsx("span",{style:{flex:1},children:_.label}),h.jsx(J.PiCheck,{size:16,color:`var(--chakra-colors-${y.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:_.value===t?"visible":"hidden"}})]},_.value))})]})}const _u={borderRadius:"4px","&:first-child":{borderTopLeftRadius:"22px",borderTopRightRadius:"22px"},"&:last-child":{borderBottomLeftRadius:"22px",borderBottomRightRadius:"22px"}},Se=E.forwardRef(function({icon:t,...r},n){const{colorMode:o}=$e();return h.jsx(z.IconButton,{ref:n,_hover:{bg:o==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:r.title??r["aria-label"],...r,children:t})}),Ct=E.forwardRef(function(t,r){const{themeColor:n}=$e();return h.jsx(Te,{label:"Close",children:h.jsx(Se,{ref:r,size:"sm",variant:"ghost",color:n,focusRingColor:n,...t,"aria-label":t["aria-label"]??"Close selection tools",icon:h.jsx(J.PiXLight,{size:20,"aria-hidden":"true"})})})});function Tu({label:e,icon:t,checked:r,onChange:n,disabled:o}){const{themeColor:i,readOnly:s}=$e(),{colorInactive:a}=Ye();return h.jsx(Te,{label:e,children:h.jsx(Se,{"aria-label":e,"aria-pressed":r,icon:h.jsxs(h.Fragment,{children:[t,h.jsx(z.Text,{as:"span",fontSize:"16px",fontWeight:r?"bold":"normal",whiteSpace:"nowrap",children:e})]}),size:"sm",variant:"ghost",width:"auto",px:2,gap:2,color:r?i:a,disabled:o||s,onClick:()=>n(!r)})})}function Uy({label:e="Compact layout"}={}){const{compactPropertyLayout:t,setCompactPropertyLayout:r,callbacks:n}=$e();return h.jsx(Tu,{label:e,checked:t,icon:h.jsx(z.Icon,{as:J.PiArrowsIn,boxSize:5}),onChange:o=>{var i;r(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const Vx=wn.default.input`
8
8
  appearance: none;
9
9
  width: 100%;
10
10
  height: 24px;
@@ -55,7 +55,7 @@
55
55
  cursor: default;
56
56
  opacity: 0.5;
57
57
  }
58
- `,Uy=S.forwardRef(function({style:t,...r},n){return h.jsx(zx,{...r,ref:n,style:{...t,backgroundImage:"none","--flow-range-track":(t==null?void 0:t.backgroundImage)??"none"}})});function wl({label:e,inputLabel:t,value:r,displayValue:n,min:o,max:i,onChange:s}){const a=S.useId(),{readOnly:c,themeColor:u}=Ie(),{colorInactive:l}=Je(),d=(r-o)/(i-o)*100,f=u.includes(".")?`var(--chakra-colors-${u.replace(".","-")})`:u;return h.jsxs("div",{style:{width:224,maxWidth:"calc(100vw - 64px)",padding:12},children:[h.jsxs("label",{htmlFor:a,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",h.jsx("span",{children:n})]}),h.jsx(Uy,{id:a,"aria-label":t,type:"range",min:o,max:i,step:5,value:r,disabled:c,style:{color:f,accentColor:f,backgroundImage:`linear-gradient(to right, currentColor ${d}%, var(--chakra-colors-${l.replace(".","-")}) ${d}%)`},onChange:p=>s(Number(p.target.value))})]})}const Cl={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 Hy(){const{spacing:e,setSpacing:t,edgeRadius:r,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:s,readOnly:a}=Ie(),c=Cl[o].icon;return h.jsxs(h.Fragment,{children:[h.jsx($t,{}),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:a,onValueChange:()=>{},popupContent:h.jsx(wl,{label:"Spacing",inputLabel:"Node spacing percentage",min:50,max:200,value:Math.round(e*100),displayValue:`${Math.round(e*100)}%`,onChange:u=>{var l;t(u/100),(l=s.onSpacingChange)==null||l.call(s,u/100)}}),children:h.jsx("option",{value:"spacing",children:"Spacing"})}),h.jsx($t,{}),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:a,onValueChange:()=>{},popupContent:h.jsx(wl,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:r??500,displayValue:r??"Default",onChange:u=>{var l;n(u),(l=s.onEdgeRadiusChange)==null||l.call(s,u)}}),children:h.jsx("option",{value:"radius",children:"Edge radius"})}),h.jsx($t,{}),h.jsxs(Or,{"aria-label":"Background variant",title:`Background: ${Cl[o].label}`,icon:h.jsx(c,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:a,onValueChange:u=>{var l;i(u),(l=s.onBackgroundVariantChange)==null||l.call(s,u)},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 or=[];for(let e=0;e<256;++e)or.push((e+256).toString(16).slice(1));function Vx(e,t=0){return(or[e[t+0]]+or[e[t+1]]+or[e[t+2]]+or[e[t+3]]+"-"+or[e[t+4]]+or[e[t+5]]+"-"+or[e[t+6]]+or[e[t+7]]+"-"+or[e[t+8]]+or[e[t+9]]+"-"+or[e[t+10]]+or[e[t+11]]+or[e[t+12]]+or[e[t+13]]+or[e[t+14]]+or[e[t+15]]).toLowerCase()}let Xn;const Wx=new Uint8Array(16);function Gx(){if(!Xn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Xn=crypto.getRandomValues.bind(crypto)}return Xn(Wx)}const Ux=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),_l={randomUUID:Ux};function Tu(e,t,r){var o;if(_l.randomUUID&&!e)return _l.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??Gx();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,Vx(n)}const wn={label:"Untitled",description:"",isTask:!1,isLocked:!1},Ou={id:null,type:"text",data:{...wn,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"}}},Sl={id:null,type:"objectView",data:{...wn,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},Hx={id:null,type:"arrayView",data:{...wn,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"}}},El={id:null,type:"workflowStep",data:{...wn,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},yr=e=>typeof e=="object",Ky=e=>Array.isArray(e),Kx=["order","position","selected","locked","grabbed","grabbable","scratch"],Vr=e=>Object.entries(e).reduce((t,[r,n])=>(!yr(n)&&!r.startsWith("$")&&(t[r]=n),t),{}),Iu=(e,t)=>typeof e=="string"&&e.startsWith("$")?Qn(e,t):yr(e)&&!Ky(e)?Object.entries(e).reduce((r,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete r["..."],r[n]={...Qn(o,t),...e}):typeof o=="string"&&o.startsWith("$")?r[n]=Qn(o,t):r[n]=o,r),{}):e,Wr=e=>Object.entries(e).reduce((t,[r,n])=>(yr(n)&&r&&n&&!r.startsWith("$")&&(Kx.includes(r)&&(r=r+"#"),t[r]=n),t),{}),Qr=(e,t,{label:r,parent:n=void 0},o,i=null)=>(i!==null&&(yr(i)||Ky(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}}),Dr=(e,t,r=null,n=null,o=null,i=!1,s=null)=>({data:{id:Tu(),source:o?t:e,target:o?e:t,label:n||"",isInverted:o,isEdgeAnimated:i,parent:s}}),Gr=(e,t=[])=>{const r={},n={};let o=[];if(e)for(const[i,s]of Object.entries(e))i.startsWith("$")&&i!=="$"?r[i.slice(1)]=s:i!=="$"?n[i]=s:i==="$"&&(o=s);return{newConfig:r,updatedObject:n,arrayObject:o}},ht=(e,t)=>{let r=Sl;const{view:n,borderColor:o,borderRadius:i,bgColor:s,textColor:a,fontSize:c,stepType:u}=t;e=n||e,u?r={...El}:e==="object"?r=Sl:e==="text"?r=Ou:e==="array"?r=Hx:e==="workflowStep"&&(r={...El});const l=r.data.viewProps;return r.data.viewProps={...l,borderRadius:i||(u?15:53),bgColor:s,borderColor:o,textColor:a,fontSize:c},r.data.config=t,{config:r}},Ut=(e,t)=>(e=t.find(n=>n.data.id===e)?`${e}.#`:e,e),Qn=(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(a=>a.split(".").slice(-1)[0]===n||n===a);if(!o)return e;const i=Jx(o,r);return JSON.stringify(i).includes(e)?e:i||e}return e},Jx=(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((s,a)=>{a=a.replace("[","").replace("]","");const{arrayObject:c}=Gr(s);return s=c.length?c:s,s[a]},i))(t)};function gt(e,t="root",r=[]){try{const{arrayObject:n}=Gr(e);n.length&&(e=n);const o=Vr(e),i=Wr(e);return yr(e)?(Te(e)||Te(e)&&t==="root"||!Te(e)&&Object.keys(o).length||t==="root")&&r.push(t):r.push(t),Object.keys(i).length&&!Te(e)?Lt({chldPth:null,itrblObjct:i,nodes:r,path:t}):Te(e)&&e.forEach((s,a)=>{const c=Vr(s),u=Wr(s),{newConfig:l,arrayObject:d}=Gr(s);let f=`${t}.${a}`;yr(s)?Object.keys(c).length?(gt(c,f,r),Object.keys(u).length&&!Te(s)&&Lt({chldPth:f,itrblObjct:u,nodes:r,path:t})):Object.keys(u).length&&!Te(s)?Lt({chldPth:f,itrblObjct:u,nodes:r,path:t}):Te(s)&&Jy({chldPth:f,item:s,nodes:r,path:t}):r.push(f)}),{nodes:r}}catch{return{nodes:r}}}const Lt=({chldPth:e,itrblObjct:t,nodes:r,path:n})=>Object.entries(t).forEach(([o,i],s)=>{const a=Vr(i),c=Wr(i),{newConfig:u,arrayObject:l}=Gr(i);l.length&&(i=l),n.split(".").slice(0,2).join(".");let d=e?`${e}.${o}`:`${n}.${o}`;if(yr(i)&&!Te(i)){const f=Object.keys(a).length===0;if(f&&(ht("array",u),r.push(d)),Object.keys(a).length){const p=Te(i)?`${i.length||""}`:`{${Object.keys(i).length||""}}`;let y=d;f&&(y=`${d}.${p}`),gt(i,y,r)}else Object.keys(c).length&&!Te(i)?Lt({chldPth:d,itrblObjct:c,path:d,nodes:r}):gt(i,d,r)}else Te(i)&&gt(i,d,r)}),Jy=({chldPth:e,item:t,nodes:r,path:n})=>t.forEach((o,i)=>{let s=`${e}.${i}`;const a=Wr(o),c=Vr(o);yr(o)?!Te(o)&&Object.keys(c).length?gt(o,s,r):Object.keys(a).length&&!Te(o)?Lt({chldPth:s,itrblObjct:a,path:n,nodes:r}):Te(o)&&Jy({chldPth:s,item:o,nodes:r,path:n}):r.push(s)}),pn=[];let Ft;function rt(e,t="root",r=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},s={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:r,edges:n};const a=e;if(!Ft){const{nodes:l}=gt(e);Ft={ids:l,jsnObjct:e}}let{hideDefaultObject:c,sprtObjctKy:u}=i;try{t=Ut(t,r);const{newConfig:l,arrayObject:d}=Gr(e),f=Object.keys(s).length>0?s:l;d.length&&(e=d);const p=Vr(e),y=Wr(e),{label:g,collapsed:b,parent:x}=f;if(!yr(e))r.push(Qr(Ou,t,{label:g||t,parent:x},e,a));else if(Te(e)||Te(e)&&t==="root"){const{config:m}=ht("array",f),w=Te(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,v=t==="root"?o:`${o} ${w}`;r.push(Qr(m,t,{label:g||v,parent:x},e,Te(a)?{[o]:a}:a))}else if(!Te(e)&&Object.keys(p).length||t==="root"){const{config:m}=ht(null,f),w=Te(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,v=t.split("."),C=v[v.length-1];let _=isNaN(Number(C))?null:Number(C)+1;const R=isNaN(Number(C))?C:v[v.length-2]+" "+_,T=t==="root"?o:R;let A=!1;Number.isNaN(Number(o))||(A=!0);const k=e;if(g){const{config:j}=ht("object",f);r.push(Qr(j,t,{label:g||`${g} ${w}`,parent:x},p,k))}else m.data.headerTitle=T,r.push(Qr(m,t,{label:g,parent:x},p,k))}return b||(Object.keys(y).length&&!Te(e)?Bt({flowConfig:i,chldPth:null,edges:n,isInverted:null,itrblObjct:y,nodes:r,path:t,newConfig:f}):Te(e)&&e.forEach((m,w)=>{m=Iu(m,Ft);const v=m,C=Vr(m),_=Wr(m),{newConfig:R,arrayObject:T}=Gr(m);T.length&&(m=T);const{config:A}=ht(typeof m=="string"?"text":"array",R),{hideConfig:k,sourceLabel:j,label:E,isEdgeAnimated:M,parent:I}=R;c=c||k;const N=t==="root"&&i.isCntr,O=t.split(".").slice(0,2).join("."),W=pn.includes(O),G=i.isCntr&&W||w%2===0&&N;let ee=`${t}.${w}`;ee=Ut(ee,r),G&&pn.push(ee),yr(m)?Object.keys(C).length&&!Te(m)?(n.push(Dr(t,ee,null,j,G,M)),rt(m,ee,r,n,E||w,i,R)):Object.keys(_).length&&!Te(m)?Bt({flowConfig:i,chldPth:ee,isInverted:G,edges:n,itrblObjct:_,nodes:r,path:t,newConfig:R,forceIsInverted:!0}):Te(m)?Zy({flowConfig:i,chldPth:ee,edges:n,isInverted:G,item:m,nodes:r,path:t}):yr(m)&&Bt({flowConfig:i,chldPth:ee,isInverted:G,edges:n,itrblObjct:[m],nodes:r,path:t,newConfig:R}):(n.push(Dr(t,ee,null,j,G,M)),r.push(Qr(A,ee,{label:E||String(m),parent:I},m,v)))})),{nodes:r,edges:n}}catch{return{nodes:r,edges:n}}}const Bt=({chldPth:e,flowConfig:t,edges:r,itrblObjct:n,nodes:o,isInverted:i,path:s,newConfig:a,forceIsInverted:c=!1})=>{let{hideDefaultObject:u,sprtObjctKy:l}=t;return Object.entries(n).forEach(([d,f],p)=>{f=Iu(f,Ft);const y=f,g=Vr(f),b=Wr(f),{newConfig:x,arrayObject:m}=Gr(f);m.length&&(f=m);const{hideConfig:w,sourceLabel:v,label:C,content:_,target:R,targetLabel:T,collapsed:A,isEdgeAnimated:k,parent:j}=x;u=u||w;const E=s==="root"&&t.isCntr,M=s.split(".").slice(0,2).join("."),I=pn.includes(M);c||(i=t.isCntr&&I||p%2===0&&E);let N=e?`${e}.${d}`:`${s}.${d}`;if(N=Ut(N,o),i&&pn.push(N),R&&r.push(Dr(N,R,null,T,i,k)),yr(f)&&!Te(f)){r.push(Dr(s,N,null,v,i,k));const O=l||Object.keys(g).length===0;if(O){const W=_?"object":"array",{config:G}=ht(W,x);G.data.headerTitle=_?C:null,o.push(Qr(G,N,{label:C||d,parent:j},f,y))}if(Object.keys(g).length&&!u){const W=Te(f)?` ${f.length||""}`:`{${Object.keys(f).length||""}}`;let G=N;O&&(G=`${N}.${W}`,G=Ut(G,o),r.push(Dr(N,G,null,v,i,k))),rt(f,G,o,r,C||d,t,x)}else Object.keys(b).length&&!Te(f)?Bt({chldPth:N,flowConfig:t,itrblObjct:b,path:N,edges:r,nodes:o,newConfig:x,isInverted:i}):rt(f,N,o,r,d,t,x)}else Te(f)&&(r.push(Dr(s,N,null,v,i,k)),rt(f,N,o,r,d,t,x))})},Zy=({flowConfig:e,chldPth:t,edges:r,isInverted:n,item:o,nodes:i,path:s})=>o.forEach((a,c)=>{let u=`${t}.${c}`;u=Ut(u,i);const l=a;a=Iu(a,Ft);const d=Wr(a),f=Vr(a),{newConfig:p}=Gr(a),{collapsed:y,label:g,parent:b,sourceLabel:x,isEdgeAnimated:m,content:w}=p;yr(a)?!Te(a)&&Object.keys(f).length?(r.push(Dr(s,u,null,x,n,m)),rt(a,u,i,r,c,e,p)):Object.keys(d).length&&!Te(a)&&!y?Bt({chldPth:u,flowConfig:e,itrblObjct:d,path:s,edges:r,nodes:i,isInverted:n,newConfig:p}):Te(a)&&Zy({flowConfig:e,chldPth:u,edges:r,isInverted:n,item:a,nodes:i,path:s}):(r.push(Dr(s,u,null,x,n,m)),i.push(Qr(Ou,u,{label:g||String(a),parent:b},a,l)))});function Zx(e,t){const r=new Set,n=u=>{if(!(!u||typeof u!="object")){typeof u.$parent=="string"&&r.add(u.$parent);for(const[l,d]of Object.entries(u))(!l.startsWith("$")||l==="$")&&n(d)}};if(n(e),!r.size)return t;const o=new Map(t.nodes.map(u=>[u.data.id,u])),i=u=>{var p,y;let l=u.data.id;const d=new Set([u.data.id]);let f=u.data.parent;for(;f&&!d.has(f);)r.has(f)&&o.has(f)&&((p=we(e,f))!=null&&p.$collapsed)&&(l=f),d.add(f),f=(y=o.get(f))==null?void 0:y.data.parent;return l},s=new Map(t.nodes.map(u=>[u.data.id,i(u)])),a=t.nodes.filter(u=>s.get(u.data.id)===u.data.id).map(u=>{if(!r.has(u.data.id))return u;const l=we(e,u.data.id),d=!!(l!=null&&l.$collapsed);return{...u,data:{...u.data,...d?{type:"arrayView"}:{},config:{...u.data.config,parentContainer:!0,collapsed:d,...d?{labelBelow:!0,icon:(l==null?void 0:l.$icon)||"PiStack"}:{}}}}}),c=new Set(a.map(u=>u.data.id));return{nodes:a,edges:t.edges.flatMap(u=>{const l=s.get(u.data.source),d=s.get(u.data.target);return!l||!d||!c.has(l)||!c.has(d)?[]:l===u.data.source&&d===u.data.target?[u]:l===d?[]:[{...u,data:{...u.data,source:l,target:d,collapsedEndpoints:u.data.collapsedEndpoints??{source:u.data.source,target:u.data.target}}}]})}}function Cn(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]),s=t.get(i)??0;return t.set(i,s+1),[{value:o,key:`${i}#${s}`,index:n}]})}function Yy(e,t,r){const n=Cn(e).find(c=>c.key===t);if(!n)return e;const o=r(n.value),i=e.$connections.flatMap((c,u)=>u===n.index?o?[o]:[]:[c]);if(i.length)return{...e,$connections:i};const{$connections:s,...a}=e;return a}function Yx(e){const t=[],r=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,s)=>r(i,`${o}.${s}`));for(const i of Cn(n)){const s=i.value;t.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:s.target,type:typeof s.type=="string"?s.type:void 0,sourceProperty:s.sourceProperty,targetProperty:s.targetProperty,icon:typeof s.icon=="string"?s.icon:void 0,label:typeof s.label=="string"?s.label:void 0,color:typeof s.color=="string"?s.color:void 0,isEdgeDashed:s.style==="dashed",isEdgeAnimated:s.style==="animated",...["dashed","traveling"].includes(s.animationVariant)?{edgeAnimationVariant:s.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,s])=>[i,i==="$"?r(s,o):i.startsWith("$")?s:r(s,`${o}.${i}`)]))};return{json:r(e,"root"),edges:t}}const Ht="root",jl=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Ir(e){const t=e.split(".");for(t[0]===Ht&&t.shift();t.length&&jl(t[t.length-1]);)t.pop();return t.filter(r=>!jl(r))}function _n(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function we(e,t){return Ir(t).reduce((r,n)=>{var o;if(r!=null)return(o=_n(r))==null?void 0:o[n]},e)}function Xx(e){return Array.isArray(e)?[...e]:{...e}}function mr(e,t,r){const n=Ir(t),o=(i,s)=>{if(s===n.length)return r(i);const a=n[s],c=_n(i);if(c==null||typeof c!="object")return i;const u=o(c[a],s+1);if(Object.is(u,c[a]))return i;const l=Xx(c);return l[a]=u,c!==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 sr(e,t,r,n){return mr(e,t,o=>r==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:Tr(o,r,n))}const Xy=(e,t,r)=>sr(e,t,"$collapsed",r);function Kt(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 Br(e,t,r,n){if(t.connection){const a=t.connection;return mr(e,a.address,c=>Yy(c,a.key,u=>{if(r==="$edgeIcon")return Tr(u,"icon",n);if(r==="$edgeType")return Tr(u,"type",n);if(r==="$edgeAnimationVariant")return Tr(u,"animationVariant",n);if(r==="$sourceLabel"||r==="$edgeColor")return Tr(u,r==="$sourceLabel"?"label":"color",n);const l=r==="$isEdgeAnimated"?"animated":"dashed";return n?{...u,style:l}:u.style===l?Tr(u,"style",void 0):u}))}const{address:o,kind:i}=Kt(t),s=i==="target"&&r==="$sourceLabel"?"$targetLabel":i==="target"&&r==="$edgeType"?"$targetEdgeType":i==="target"&&r==="$edgeIcon"?"$targetIcon":i==="target"&&r==="$edgeAnimationVariant"?"$targetAnimationVariant":r;return mr(e,o,a=>Tr(a,s,n))}const Qy=(e,t,r)=>Br(Br(e,t,"$isEdgeAnimated",r==="animated"||void 0),t,"$isEdgeDashed",r==="dashed"||void 0);function Mu(e,t,r,n){let o=n||"";const i=mr(e,t,a=>{const c=_n(a);if(Array.isArray(c)){o=String(c.length);const l=[...c,r];return c===a?l:{...a,$:l}}const u=a!=null&&typeof a=="object"&&!Array.isArray(a)?{...a}:a!=null&&typeof a!="object"?{$label:String(a)}:{};if(!o){let l=1;for(;`node_${l}`in u;)l++;o=`node_${l}`}return u[o]=r,u}),s=Ir(t);return{json:i,address:[Ht,...s,o].join(".")}}function em(e,t){const r=Ir(t);if(!r.length)return e;const n=r[r.length-1],o=[Ht,...r.slice(0,-1)].join(".");return mr(e,o,i=>{const s=_n(i);if(s==null||typeof s!="object"||!Object.prototype.hasOwnProperty.call(s,n))return i;if(Array.isArray(s)){const u=s.filter((l,d)=>String(d)!==n);return s===i?u:{...i,$:u}}const{[n]:a,...c}=i;return c})}const rm=(e,t,r,n)=>sr(n?mr(e,t,o=>Tr(o,"$targetLabel",n)):e,t,"$target",r);function qu(e,t,r){const n=we(e,t);return Cn(n).some(({value:i})=>i.target===r.target&&i.sourceProperty===r.sourceProperty&&i.targetProperty===r.targetProperty)?e:mr(e,t,i=>Tr(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...r,id:r.id||Tu()}]))}function tm(e,t){if(t.connection){const i=t.connection;return Cn(we(e,i.address)).some(s=>s.key===i.key)?{json:mr(e,i.address,s=>Yy(s,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:r,kind:n}=Kt(t);return n==="hierarchy"?we(e,r)===void 0?{json:e,removed:!1}:{json:mr(e,r,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:mr(e,r,i=>{const{$target:s,$targetLabel:a,...c}=i||{};return c}),removed:!0}}function _u(e,t={}){var x;const r=Yx(e),{nodes:n,edges:o}=rt(r.json,Ht,[],[],t.title||"untitled",{hideDefaultObject:!!t.hideDefaultObject,sprtObjctKy:!!t.separateObjectKeys,isCntr:!!t.isCenter}),i=new Set(n.map(m=>m.data.id)),s=new Map;for(const m of n){const w=m.data.id;if(!w.endsWith(".0")||we(e,w)!==void 0)continue;const v=w.slice(0,-2),C=we(e,v);!i.has(v)&&C&&typeof C=="object"&&!Array.isArray(C)&&typeof C.$label=="string"&&Object.keys(C).every(_=>_.startsWith("$")&&_!=="$")&&s.set(w,v)}const a=m=>s.get(m)??m,c=new Set(n.flatMap(m=>m.data.parent?[a(m.data.parent)]:[])),u=n.map(m=>{var T;const w=a(m.data.id),v=we(e,w),C={...m.data,id:w},_=v&&typeof v=="object"&&!Array.isArray(v)&&"$"in v?v.$:v;if((Array.isArray(_)?_.length>0:_&&typeof _=="object"&&Object.keys(_).some(A=>!A.startsWith("$")))&&(C.config={...C.config,collapsed:!!v.$collapsed}),c.has(w)||(C.viewProps={...C.viewProps},delete C.viewProps.borderWidth),!v||typeof v!="object"||Array.isArray(v))return{data:C};if(v.$form&&typeof v.$form=="object"&&(C.config={...C.config,form:v.$form},C.type="objectView"),Array.isArray(v.$ports)){const A=v.$ports.filter(k=>k&&typeof k.id=="string"&&["source","target"].includes(k.role)&&["top","right","bottom","left"].includes(k.side));C.config={...C.config,ports:A}}return C.parent&&(C.parent=a(C.parent)),typeof v.$label=="string"&&(C.label=v.$label,C.headerTitle=v.$label),typeof v.$subtitle=="string"&&(C.config={...C.config,subtitle:v.$subtitle}),typeof v.$outline=="boolean"&&(C.viewProps={...C.viewProps,outline:v.$outline}),["solid","dashed","dotted","double"].includes(v.$borderStyle)&&(C.viewProps={...C.viewProps,borderStyle:v.$borderStyle}),Number.isFinite(v.$borderWidth)&&v.$borderWidth>=0&&(C.viewProps={...C.viewProps,borderWidth:v.$borderWidth}),Number.isFinite(v.$borderRadius)&&v.$borderRadius>=0&&(C.viewProps={...C.viewProps,borderRadius:v.$borderRadius}),typeof v.$isNodeAnimated=="boolean"&&(C.isNodeAnimated=v.$isNodeAnimated),["traveling","pulse"].includes(v.$nodeAnimationVariant)&&(C.nodeAnimationVariant=v.$nodeAnimationVariant),typeof v.$content=="string"&&(C.config={...C.config,content:v.$content},v.$view||(C.type="objectView")),(((T=C.config)==null?void 0:T.collapsed)!==void 0||v.$collapsed!==void 0||v.$icon!==void 0)&&(C.config={...C.config||{}},(v.$collapsed!==void 0||C.config.collapsed!==void 0)&&(C.config.collapsed=!!v.$collapsed),v.$icon!==void 0&&(C.config.icon=v.$icon)),{data:C}}),l=new Map,d=o.map(m=>{const w=a(m.data.source),v=a(m.data.target),C=`${w}->${v}`,_=l.get(C)??0;l.set(C,_+1);const R={...m.data,id:_?`${C}#${_}`:C,source:w,target:v},T=Kt(R),A=we(e,T.address);if(A&&typeof A=="object"){const k=A[T.kind==="target"?"$targetEdgeType":"$edgeType"];typeof k=="string"&&(R.type=k);const j=A[T.kind==="target"?"$targetIcon":"$edgeIcon"];typeof j=="string"&&(R.icon=j),A.$isEdgeAnimated!==void 0&&(R.isEdgeAnimated=!!A.$isEdgeAnimated);const E=A[T.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(E)&&(R.edgeAnimationVariant=E),A.$isEdgeDashed!==void 0&&(R.isEdgeDashed=!!A.$isEdgeDashed),A.$edgeColor&&(R.color=A.$edgeColor)}return{data:R}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const m=u.findIndex(w=>w.data.id===Ht);m!==-1&&u.splice(m,1)}const f=new Set(u.map(m=>m.data.id));for(let m=d.length-1;m>=0;m--){const w=d[m].data,v=Kt(w);(!f.has(w.source)||!f.has(w.target)||v.kind==="hierarchy"&&((x=we(e,v.address))==null?void 0:x.$hideParentEdge)===!0)&&d.splice(m,1)}d.push(...r.edges.filter(m=>f.has(m.data.source)&&f.has(m.data.target)));const p=Zx(e,{nodes:u,edges:d}),y=p.nodes.filter(m=>{var w;return(w=m.data.config)==null?void 0:w.collapsed}).map(m=>Ir(m.data.id));if(!y.length)return p;const g=p.nodes.filter(m=>{const w=Ir(m.data.id);return!y.some(v=>v.length<w.length&&v.every((C,_)=>C===w[_]))}),b=new Set(g.map(m=>m.data.id));return{nodes:g,edges:p.edges.filter(m=>b.has(m.data.source)&&b.has(m.data.target))}}function Qx(e,t){const r=new Set(e.filter(c=>{var u,l;return(l=(u=c.data)==null?void 0:u.config)==null?void 0:l.collapsed}).map(c=>c.data.id));if(!r.size)return{nodes:e,edges:t};const n=new Map(e.map(c=>[c.data.id,c])),o=new Set(e.map(c=>c.data.parent).filter(Boolean)),i=new Map(e.map(c=>{var f;let u=c.data.id,l=c.data.parent;const d=new Set([u]);for(;l&&!d.has(l);)r.has(l)&&(u=l),d.add(l),l=(f=n.get(l))==null?void 0:f.data.parent;return[c.data.id,u]})),s=new Map;for(const c of t){const u=c.data.isInverted?c.data.target:c.data.source,l=c.data.isInverted?c.data.source:c.data.target;(s.get(u)??s.set(u,[]).get(u)).push(l)}const a=new Set(e.filter(c=>i.get(c.data.id)!==c.data.id).map(c=>c.data.id));for(const c of r){if(o.has(c))continue;const u=[...s.get(c)||[]];for(;u.length;){const l=u.pop();r.has(l)||a.has(l)||(a.add(l),u.push(...s.get(l)||[]))}}return{nodes:e.filter(c=>!a.has(c.data.id)).map(c=>{var u;return r.has(c.data.id)&&o.has(c.data.id)?{...c,data:{...c.data,type:"arrayView",label:c.data.label??c.data.headerTitle,config:{...c.data.config,parentContainer:!0,labelBelow:!0,icon:((u=c.data.config)==null?void 0:u.icon)||"PiStack"}}}:c}),edges:t.flatMap(c=>{const u=i.get(c.data.source)??c.data.source,l=i.get(c.data.target)??c.data.target;return a.has(u)||a.has(l)?[]:u===c.data.source&&l===c.data.target?[c]:u===l?[]:[{...c,data:{...c.data,source:u,target:l,collapsedEndpoints:c.data.collapsedEndpoints??{source:c.data.source,target:c.data.target}}}]})}}function Nu(e,t){const r=JSON.parse(e);let n=512;const o=(s,a=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!s||typeof s!="object"||Array.isArray(s))throw new Error("Expected a JSON Schema object.");const c=new Set(["$schema","$id","$defs","definitions","$ref","title","description","default","examples","type","properties","required","items","enum","const","anyOf","additionalProperties"]);for(const l of Object.keys(s))if(!c.has(l))throw new Error(`Unsupported JSON Schema keyword: ${l}`);const u=["$schema","$id","$defs","definitions","title","description","default","examples"];if(s.$ref){if(Object.keys(s).some(d=>!["$ref","title","description"].includes(d)))throw new Error("Use $ref without sibling constraints.");if(typeof s.$ref!="string"||!s.$ref.startsWith("#/")||a.includes(s.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let l=r;for(const d of s.$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: ${s.$ref}`);l=l[f]}return o(l,[...a,s.$ref])}if(s.anyOf){if(!Array.isArray(s.anyOf)||!s.anyOf.length||Object.keys(s).some(l=>l!=="anyOf"&&!u.includes(l)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:s.anyOf.map(l=>o(l,a))}}if(Object.prototype.hasOwnProperty.call(s,"const")||s.enum){if(Object.keys(s).some(f=>![...u,"const","enum","type"].includes(f))||s.enum&&Object.prototype.hasOwnProperty.call(s,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const l=Object.prototype.hasOwnProperty.call(s,"const")?[s.const]:s.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(s.type&&!(Array.isArray(s.type)?s.type:[s.type]).some(y=>y===p||y==="integer"&&Number.isInteger(f)))throw new Error("Literal does not match its declared type.");return{kind:"literal",value:f}})}}if(Array.isArray(s.type)){if(!s.type.length||s.type.some(l=>typeof l!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(s).some(l=>l!=="type"&&!u.includes(l)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:s.type.map(l=>o({type:l},a))}}if((s.properties||s.required||s.additionalProperties!==void 0)&&s.type!=="object"&&s.type!==void 0)throw new Error("Object constraints require an object type.");if(s.items&&s.type!=="array")throw new Error("items requires an array type.");if(s.type==="object"||s.properties){if(s.additionalProperties!==void 0&&s.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!s.properties||typeof s.properties!="object"||Array.isArray(s.properties))throw new Error("Object schemas must declare properties.");if(s.required!==void 0&&(!Array.isArray(s.required)||s.required.some(d=>typeof d!="string"||!Object.prototype.hasOwnProperty.call(s.properties,d))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(s.properties).map(([d,f])=>[d,{type:o(f,a),optional:!(s.required??[]).includes(d)}]))}}if(s.type==="array")return{kind:"array",items:o(s.items,a)};if(["string","number","integer","boolean","null"].includes(s.type))return{kind:s.type};throw new Error("Every property must declare a supported type.")},i=o(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(s=>s.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:t,nodes:i.properties}}async function $u(e,t,r,n={}){var y;let o=512;const i=await import("typescript"),s=i.createSourceFile(t,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),a=s.parseDiagnostics;if(a!=null&&a.length)throw new Error("Invalid TypeScript syntax.");const c=new Map;for(const g of s.statements){if(!i.isInterfaceDeclaration(g)&&!i.isTypeAliasDeclaration(g))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((y=g.typeParameters)!=null&&y.length||c.has(g.name.text))throw new Error("Generics and duplicate declarations are not supported.");c.set(g.name.text,g)}const u=(g,b)=>{var C;const x={},m=g.find(_=>i.isIndexSignatureDeclaration(_));let w;if(m&&n.allowJson&&i.isIndexSignatureDeclaration(m)){if(g.filter(_=>i.isIndexSignatureDeclaration(_)).length!==1||m.parameters.length!==1||((C=m.parameters[0].type)==null?void 0:C.kind)!==i.SyntaxKind.StringKeyword||!m.type)throw new Error("Only one string-keyed index signature is supported for forms.");w=d(m.type,b)}return{kind:"object",properties:Object.fromEntries(g.filter(_=>_!==m||!w).map(_=>{if(!i.isPropertySignature(_)||!_.type||!_.name||!i.isIdentifier(_.name)&&!i.isStringLiteral(_.name))throw new Error("Only explicitly typed named properties are supported.");const R=d(_.type,b),T=n.allowJson?i.getJSDocTags(_).filter(A=>A.tagName.text==="port"):[];if(T.length>1)throw new Error(`Duplicate port declaration: ${_.name.text}`);if(T.length){const[A,k,j]=String(T[0].comment??"").trim().split(/\s+/);if(A!=="config"||!k||j||!c.has(k))throw new Error(`Config port ${_.name.text} requires @port config ResourceType`);const E=R.kind==="array";if((R.kind==="array"?R.items.kind:R.kind)!=="string")throw new Error(`Config port ${_.name.text} must be a string or string array reference`);x[_.name.text]={kind:"config",resourceType:k,multiple:E}}return[_.name.text,{type:R,optional:!!_.questionToken}]})),...w?{additionalProperties:w}:{},...Object.keys(x).length?{ports:x}:{}}},l=(g,b)=>{var C;if(b.includes(g))throw new Error("Recursive types are not supported.");const x=c.get(g);if(!x)throw new Error(`Unknown type: ${g}`);let m;if(i.isInterfaceDeclaration(x)){if((C=x.heritageClauses)!=null&&C.length)throw new Error("Interface inheritance is not supported; declare properties explicitly.");m=u(x.members,[...b,g])}else m=d(x.type,[...b,g]);const w=n.allowJson?i.getJSDocTags(x).filter(_=>_.tagName.text==="port"):[];if(!w.length)return m;if(m.kind!=="object")throw new Error("Node ports require an object interface");const v={...m.ports};for(const _ of w){const[R,T,...A]=String(_.comment??"").trim().split(/\s+/);if(!["input","output","error"].includes(R)||!/^[A-Za-z][\w-]*$/.test(T??""))throw new Error("Node ports require @port input|output|error Name");const k=A.length?JSON.parse(A.join(" ")):void 0;if(k!==void 0&&typeof k!="string")throw new Error("Node port labels must be JSON strings");if(Object.prototype.hasOwnProperty.call(v,T))throw new Error(`Duplicate port declaration: ${T}`);v[T]={kind:R,...typeof k=="string"?{label:k}:{}}}return{...m,ports:v}},d=(g,b)=>{var x,m,w;if(--o<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(g.kind===i.SyntaxKind.StringKeyword)return{kind:"string"};if(g.kind===i.SyntaxKind.NumberKeyword)return{kind:"number"};if(g.kind===i.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[i.SyntaxKind.AnyKeyword,i.SyntaxKind.UnknownKeyword].includes(g.kind))return{kind:"json"};if(i.isParenthesizedTypeNode(g))return d(g.type,b);if(i.isUnionTypeNode(g))return{kind:"union",types:g.types.map(v=>d(v,b))};if(i.isArrayTypeNode(g))return{kind:"array",items:d(g.elementType,b)};if(i.isTypeLiteralNode(g))return u(g.members,b);if(i.isLiteralTypeNode(g)){const v=g.literal;if(i.isStringLiteral(v))return{kind:"literal",value:v.text};if(i.isNumericLiteral(v))return{kind:"literal",value:Number(v.text)};if(v.kind===i.SyntaxKind.NullKeyword)return{kind:"null"};if(v.kind===i.SyntaxKind.TrueKeyword||v.kind===i.SyntaxKind.FalseKeyword)return{kind:"literal",value:v.kind===i.SyntaxKind.TrueKeyword}}if(i.isTypeReferenceNode(g)&&i.isIdentifier(g.typeName)){if(n.allowJson&&g.typeName.text==="Record"&&!c.has("Record")&&((x=g.typeArguments)==null?void 0:x.length)===2&&g.typeArguments[0].kind===i.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:d(g.typeArguments[1],b)};if(g.typeName.text==="Array"&&((m=g.typeArguments)==null?void 0:m.length)===1)return{kind:"array",items:d(g.typeArguments[0],b)};if(!((w=g.typeArguments)!=null&&w.length))return l(g.typeName.text,b)}throw new Error(`Unsupported TypeScript type: ${g.getText(s)}`)},f=r??(c.has("Graph")?"Graph":c.size===1?[...c.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 nm(e,t){const r=await $u(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 At(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=>At(r,t));if(t.kind==="union")return t.types.some(r=>At(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"?At(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)&&At(o.type,n.type):n.optional}):e.kind===t.kind}function Lu(e,t){if(!t.sourceProperty&&!t.targetProperty)return;const r=(s,a)=>{var l;const c=Object.prototype.hasOwnProperty.call(e.nodes,s)?s:s.replace(/^root\./,""),u=Object.prototype.hasOwnProperty.call(e.nodes,c)?(l=e.nodes[c])==null?void 0:l.type:void 0;return a&&(u==null?void 0:u.kind)==="object"&&Object.prototype.hasOwnProperty.call(u.properties,a)?u.properties[a]: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=s=>s.kind==="json"||s.kind==="object"&&(!!s.additionalProperties||Object.values(s.properties).some(a=>i(a.type)))||s.kind==="array"&&i(s.items)||s.kind==="union"&&s.types.some(i);if(i(n.type)||i(o.type))return"Unverified: arbitrary JSON or dictionary fields require runtime validation.";if(n.optional&&!o.optional)return"Optional source cannot supply a required target property.";if(!At(n.type,o.type))return`Incompatible property types: ${t.sourceProperty} -> ${t.targetProperty}.`}async function om(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 Nu(t,e.name);if(/\.ts$/i.test(e.name))return nm(t,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Rl=new WeakMap;function Jt(e){if(!e||typeof e!="object")return e;const t=Rl.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)=>Jt(Reflect.get(e,i)),has:(o,i)=>Reflect.has(e,i),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(o,i)=>{const s=Reflect.getOwnPropertyDescriptor(e,i);return s&&{...s,value:Jt(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:r,deleteProperty:r,defineProperty:r,setPrototypeOf:r,preventExtensions:r});return Rl.set(e,n),n}function xt(e,t,r){var o;const n=t.split(".");for(let i=n.length;i>0;i--){const s=n.slice(0,i).join("."),a=(o=we(e,s))==null?void 0:o.$form;if(!(a!=null&&a.$type))continue;let c=Object.prototype.hasOwnProperty.call(r,a.$type)?r[a.$type]:void 0;for(const d of n.slice(i))(c==null?void 0:c.kind)==="array"&&/^\d+$/.test(d)?c=c.items:(c==null?void 0:c.kind)==="object"?c=Object.prototype.hasOwnProperty.call(c.properties,d)?c.properties[d].type:void 0:c=void 0;if((c==null?void 0:c.kind)!=="object")return;const u=n.slice(i).join("."),l=Object.fromEntries(Object.entries(a.$fields??{}).filter(([d])=>!u||d.startsWith(`${u}.`)).map(([d,f])=>[u?d.slice(u.length+1):d,f]));return{type:c,fields:l,binding:a}}}async function Fu(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 s of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const a=await $u(r,e.name,s,{allowJson:!0});o.push([s,a]);for(const c of Object.values(a.ports??{}))c.resourceType&&i.add(c.resourceType)}return Object.fromEntries(o)}if(!e.name.endsWith(".json"))throw new Error("Choose a .ts interface or .json schema file.");const n=Nu(r,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([o,i])=>[o,i.type]))}function Sn(e,t){return!e||("$in"in e?e.$in.includes(we(t,e.$address)):we(t,e.$address)===e.$equals)}function Dt(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 jr(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 s=Object.values(i).every(o);return n.delete(i),s};return o(t)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!jr(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=>!jr(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)&&jr(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>jr(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 kl(e,t){const r=t.address.split(".");if(r.shift()!=="root"||!r.length||r.some(a=>!a||["__proto__","prototype","constructor","#"].includes(a)))throw new Error("Invalid form field address.");const n=r.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(r.some(a=>a.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...r].join("."),s=we(e,i);if(!s||typeof s!="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 sr(e,i,n,t.op==="remove"?void 0:t.value)}return mr(e,i,a=>{const c=Array.isArray(a.$)?a.$:a;if(t.op==="remove"&&!Object.prototype.hasOwnProperty.call(c,n)||t.op==="set"&&Object.is(c[n],t.value))return a;const u=Array.isArray(c)?[...c]:{...c};if(Array.isArray(u)&&(!/^(0|[1-9]\d*)$/.test(n)||Number(n)>=u.length))throw new Error("Invalid array address.");return t.op==="remove"?Array.isArray(u)?u.splice(Number(n),1):delete u[n]:Object.defineProperty(u,n,{value:structuredClone(t.value),enumerable:!0,writable:!0,configurable:!0}),c===a?u:{...a,$:u}})}function En(e,t,r){let n=kl(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:Jt(we(e,t.address)),data:Jt(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=kl(n,i)}return n}function e0(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(s=>s.startsWith("$")||["__proto__","prototype","constructor"].includes(s)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;Zt(i),r=En(r,{address:n.address,nodeAddress:o.slice(0,-1).join("."),value:i})}return Zt(r),r}function rn(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 Zt(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}`);Zt(r)}}function r0(e,t,r){Zt(t.value);const n=En(e,t,r);return Zt(n),n}function im(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 s=we(t,n.$state);return s==null?"":typeof s=="object"?JSON.stringify(s,null,2):String(s)}let i=n;for(const[s,a]of Object.entries(n)){const c=r(a,s);c!==a&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,s,{value:c,enumerable:!0,writable:!0,configurable:!0}))}return i};return r(e)}const et=(e="reference")=>({kind:e,text:"",paths:[""]}),am=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(t=>["__proto__","constructor","prototype"].includes(t));function t0(e,t){const r=new Set(t.map(s=>s.path)),n=s=>{if(!s.paths.length||s.paths.some(a=>!am(a)||!r.has(a)))throw new Error("Choose an available reference.");return[...s.paths,...s.fallback===void 0?[]:[JSON.stringify(s.fallback)]].join(" || ")},o=s=>{if(s.includes("{{")||s.includes("}}"))throw new Error("Use a reference part for dynamic values.");return s},i=s=>s.map(a=>{if(a.kind==="text")return o(a.text);if(a.kind==="conditional"){if(a.paths.length!==1||a.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(a)}}}${o(a.text)}{{/if}}`}return`{{${n(a)}}}`}).join("");if(e.mode==="reference"||e.mode==="condition"){if(e.parts.length!==1||e.parts[0].kind!=="reference")throw new Error("Choose one reference binding.");const s=i(e.parts);return e.mode==="condition"?`${s} == ${JSON.stringify(e.comparison)}`:s}if(e.mode==="json"){const s=e.fields.map(a=>a.key);if(!s.length||new Set(s).size!==s.length||s.some(a=>!a||["__proto__","constructor","prototype"].includes(a)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(a=>[a.key,i(a.parts)])))}return i(e.parts)}async function n0(e){const t=await import("typescript"),r=s=>{const a=t.createSourceFile("binding.ts",`(${s})`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS);if(a.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const c=a.statements[0];if(!c||!t.isExpressionStatement(c))throw new Error("Unsupported reference expression.");const u=et();u.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(u.fallback!==void 0)throw new Error("Multiple fallback values.");u.fallback=d.text;return}const f=d.getText(a);if(!am(f)||u.fallback!==void 0)throw new Error("Unsupported reference expression.");u.paths.push(f)};if(l(c.expression),!u.paths.length)throw new Error("A binding needs a reference.");return u},n=s=>{const a=[];let c=0;const u=/\{\{([\s\S]*?)\}\}/g;for(const l of s.matchAll(u)){const d=l.index;if(d<c)continue;d>c&&a.push({...et("text"),text:s.slice(c,d)});const f=l[1].trim();if(f.startsWith("#if ")){const p=s.indexOf("{{/if}}",d+l[0].length);if(p<0)throw new Error("Unclosed condition.");a.push({...r(f.slice(4)),kind:"conditional",text:s.slice(d+l[0].length,p)}),c=p+7}else a.push(r(f)),c=d+l[0].length}return c<s.length&&a.push({...et("text"),text:s.slice(c)}),a},o={mode:"reference",parts:[et()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const s=JSON.parse(e);if(s&&typeof s=="object"&&!Array.isArray(s)&&Object.values(s).every(a=>typeof a=="string"))return{...o,mode:"json",fields:Object.entries(s).map(([a,c])=>({key:a,parts:n(c)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const s=t.createSourceFile("condition.ts",`value ${i[1].text}`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS),a=s.statements[0];if(s.statements.length===1&&t.isExpressionStatement(a)&&t.isBinaryExpression(a.expression)&&a.expression.operatorToken.kind===t.SyntaxKind.EqualsEqualsToken&&t.isStringLiteral(a.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:a.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function Pl({parts:e,references:t,onChange:r,disabled:n}){const o=(i,s)=>r(e.map((a,c)=>c===i?{...a,...s}:a));return h.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,s)=>h.jsxs("fieldset",{"data-binding-part":s,style:{border:0,padding:0,margin:0,minWidth:0},children:[h.jsxs("legend",{children:["Part ",s+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:a=>o(s,{kind:a.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 ${s+1}`,title:"Remove part",icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r(e.filter((a,c)=>c!==s))})]}),i.kind!=="text"&&h.jsxs(h.Fragment,{children:[i.paths.map((a,c)=>h.jsxs("label",{children:["Reference ",c+1,h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsxs("select",{"aria-label":`Reference ${c+1}`,disabled:n,value:a,onChange:u=>o(s,{paths:i.paths.map((l,d)=>d===c?u.target.value:l)}),children:[h.jsx("option",{value:"",children:"Select reference"}),t.map(u=>h.jsx("option",{value:u.path,children:u.label},u.path))]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},c)),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(s,{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:a=>o(s,{fallback:a.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&h.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:a=>o(s,{fallback:a.target.value})})]})]}),i.kind!=="reference"&&h.jsxs("label",{children:["Text",h.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:a=>o(s,{text:a.target.value})})]})]},s)),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,et()])})]})}function o0({label:e,value:t,references:r,disabled:n,onChange:o}){const[i,s]=S.useState(),[a,c]=S.useState(""),[u,l]=S.useState(!1),d=async()=>{l(!0),c("");try{s(await n0(typeof t=="string"?t:""))}catch(f){c(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||u,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=>s({...i,mode:f.target.value,parts:[et()]}),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:y=>s({...i,fields:i.fields.map((g,b)=>b===p?{...g,key:y.target.value}:g)})})]}),h.jsx(Pl,{parts:f.parts,references:r,disabled:n,onChange:y=>s({...i,fields:i.fields.map((g,b)=>b===p?{...g,parts:y}:g)})}),h.jsx(ve,{"aria-label":"Remove output field",title:"Remove output field",icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:i.fields.filter((y,g)=>g!==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:()=>s({...i,fields:[...i.fields,{key:"",parts:[et()]}]})})]}):h.jsx(Pl,{parts:i.parts,references:r,disabled:n,onChange:f=>s({...i,parts:f})}),i.mode==="condition"&&h.jsxs("label",{children:["Equals",h.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:f=>s({...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(t0(i,r)),s(void 0),c("")}catch(f){c(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:()=>{s(void 0),c("")}})]})]}),a&&h.jsx("p",{role:"alert",children:a})]})}const i0=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),a0=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,Tt=(e,t)=>JSON.stringify([e,t]);function Yt(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 Yt(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 Ot(e){const t=Yt(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 Al(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"&&!Dt(e)?e.types:[e]}function s0(e,t,r){if(t.address===r.address)return;const n=we(e,t.address),o=(i,s)=>s===void 0?!1:i.kind==="union"?i.types.some(a=>o(a,s)):i.kind==="array"?Array.isArray(s)&&s.every(a=>o(i.items,a)):i.kind==="object"?!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(i.properties).every(([a,c])=>c.optional&&s[a]===void 0||o(c.type,s[a]))&&Object.entries(s).every(([a,c])=>Object.prototype.hasOwnProperty.call(i.properties,a)||!i.additionalProperties||o(i.additionalProperties,c)):s===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!jr(i,s,!0);if(o(r.type,n))return structuredClone(n)}function c0(e,t,r,n){var c,u;const o={sourceSchema:r,sourceBindings:t,nodes:[],edges:[],schema:{...r},bindings:{...t},slots:new Map,containers:new Map},i=new Set(n.map(l=>l.data.id)),s=new Map(n.flatMap(l=>{const d=t[l.data.id];return d&&r[d.type]?[[d.address,l.data.id]]:[]})),a=(l,d,f,p,y,g=!1)=>{var R,T,A,k;if(y>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const b=we(e,d),x=Yt(f,b),m=x.kind!=="object"&&x.kind!=="array";o.containers.set(l,{address:d,type:x,declared:f,scalar:m});const w=`__form:${l}`,v={...(R=o.bindings[l])==null?void 0:R.fields},C={kind:"object",properties:{},ports:{...x.kind==="object"?x.ports:{},...g?{resource:{label:"output",...x.kind==="object"?(T=x.ports)==null?void 0:T.resource:{},kind:"output"}}:{}}},_=x.kind==="object"?{...x.properties,...Object.fromEntries(Object.keys(b??{}).filter(j=>!Object.prototype.hasOwnProperty.call(x.properties,j)&&x.additionalProperties).map(j=>[j,{type:x.additionalProperties,optional:!0}]))}:x.kind==="array"?Object.fromEntries((Array.isArray(b)?b:[]).map((j,E)=>[String(E),{type:x.items,optional:!0}])):{value:{type:Dt(f)?f:x,optional:!1}};for(const[j,E]of Object.entries(_)){if(!i0(j))throw new Error(`Unsupported structured property key: ${j}`);const M=m?d:`${d}.${j}`,I=we(e,M),N=Yt(E.type,I),O=N.kind==="object"||N.kind==="array",W=(A=C.ports)==null?void 0:A[j],G=(W==null?void 0:W.kind)==="config"&&(((k=v[j])==null?void 0:k.$options)||Dt(E.type)),ee=E.type.kind==="json"||E.type.kind==="union"&&!Dt(E.type);if(!O&&x.kind!=="array"&&(!ee||m)||G){C.properties[j]={...E,type:E.type.kind==="json"?N:E.type};continue}const ne=s.get(M)??a0(M),ce=x.kind==="array"?`Item ${Number(j)+1}`:j,me={address:M,owner:l,field:j,type:E.type,label:ce,nodeId:ne,present:I!==void 0};if(o.slots.set(Tt(l,j),me),C.ports[j]={kind:"config",resourceType:`__form:${ne}`},I===void 0||(o.edges.push({data:{id:`__form-edge:${l}:${j}`,source:ne,target:l,sourceProperty:"output:resource",targetProperty:`config:${j}`,isEdgeDashed:!0}}),o.containers.has(ne)||s.has(M)))continue;if(i.has(ne))throw new Error(`Structured node identity conflict: ${ne}`);i.add(ne);const K={data:{id:ne,type:"objectView",label:ce,headerTitle:ce,description:{},config:{form:!0,icon:N.kind==="array"?"PiListNumbers":O?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push(K),a(ne,M,E.type,p,y+1,!0);const q=o.schema[`__form:${ne}`];K.data.description=Object.fromEntries(Object.keys(q.properties).map(L=>[L,we(e,N.kind==="array"||N.kind==="object"?`${M}.${L}`:M)]).filter(([,L])=>L!==void 0))}o.schema[w]=C,o.bindings[l]={...o.bindings[l],address:d,type:w,fields:v}};for(const l of n){const d=t[l.data.id];if(d!=null&&d.portResources)continue;const f=d&&r[d.type];!d||!f||we(e,d.address)===void 0||a(l.data.id,d.address,f,(c=l.data.viewProps)==null?void 0:c.bgColor,0,o.edges.some(p=>p.data.source===l.data.id))}for(const l of o.edges){const d=o.bindings[l.data.source],f=o.schema[d.type].ports;f.resource={...f.resource,kind:"output",label:((u=f.resource)==null?void 0:u.label)??"output"}}return o}function u0({nodeAddress:e}){const{structured:t,data:r,callbacks:n,editable:o}=S.useContext(Rr),i=Ie(),[s,a]=S.useState(""),[c,u]=S.useState("0"),[l,d]=S.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,y=we(r,f.address),g=Al(f.declared),b=f.type.kind==="array"?f.type.items:f.type.kind==="object"?f.type.additionalProperties:void 0,x=b?Al(b):[],m=k=>k.kind==="literal"?String(k.value):k.kind==="string"?"Text":wr(k.kind),w=[...t.slots.values()].filter(k=>k.owner===e),v=(k,j)=>{var E;return(E=n.onFormChange)==null?void 0:E.call(n,{data:r,nodeAddress:f.address,address:k,previousValue:we(r,k),value:j})},C=k=>{var j;i.setSelectedNodeIds([k]),(j=i.engineRef.current)==null||j.focusNode(k,90,!1)},_=(k,j)=>{if(!Array.isArray(y))return;const E=[...y];[E[k],E[k+j]]=[E[k+j],E[k]],v(f.address,E)},R=()=>{const k=x[Number(c)]??x[0];if(k)if(f.type.kind==="array")v(f.address,[...Array.isArray(y)?y:[],Ot(k)]);else{if(!s||s.includes(".")||s.startsWith("$")||["__proto__","constructor","prototype"].includes(s)){d("Choose a property name without dots or reserved prefixes.");return}if(Object.prototype.hasOwnProperty.call(y,s)){d("Property already exists.");return}v(`${f.address}.${s}`,Ot(k)),a(""),d("")}},T=f.type.kind==="object"&&!!f.type.additionalProperties,A=f.type.kind==="array";return h.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[g.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:g.findIndex(k=>Yt(k,y).kind===f.type.kind),onChange:k=>v(f.address,Ot(g[Number(k.target.value)])),children:g.map((k,j)=>h.jsx("option",{value:j,children:m(k)},j))}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),w.map((k,j)=>h.jsxs("div",{"data-structured-slot":k.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[k.type.kind==="array"?h.jsx(Z.PiListNumbers,{size:20}):h.jsx(Z.PiBracketsCurly,{size:20}),h.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:wr(k.label)}),h.jsx(ve,{"aria-label":`${k.present?"Focus":"Create"} ${wr(k.label)}`,title:`${k.present?"Focus":"Create"} ${wr(k.label)}`,icon:k.present?h.jsx(Z.PiMagnifyingGlass,{size:18}):h.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:p&&!k.present,onClick:E=>{var M;k.present?((M=E.currentTarget.closest("dialog"))==null||M.close(),C(k.nodeId)):v(k.address,Ot(k.type))}}),A&&h.jsxs(h.Fragment,{children:[h.jsx(ve,{"aria-label":`Move item ${j+1} up`,icon:h.jsx(Z.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:p||j===0,onClick:()=>_(j,-1)}),h.jsx(ve,{"aria-label":`Move item ${j+1} down`,icon:h.jsx(Z.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:p||j===w.length-1,onClick:()=>_(j,1)})]}),k.present&&h.jsx(ve,{"aria-label":`Remove ${wr(k.label)}`,icon:h.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:p,onClick:()=>A?v(f.address,y.filter((E,M)=>M!==j)):v(k.address,void 0)})]},k.address)),(A||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,display:"grid",gap:8},children:["Property name",h.jsx("input",{"aria-label":"Property name",placeholder:"Required",value:s,disabled:p,onChange:k=>a(k.target.value)})]}),x.length>1&&h.jsxs("label",{style:{flex:"1 1 100px",minWidth:0,display:"grid",gap:8},children:["New value type",h.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[h.jsx("select",{"aria-label":"New value type",value:c,disabled:p,onChange:k=>u(k.target.value),children:x.map((k,j)=>h.jsx("option",{value:j,children:m(k)},j))}),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":A?"Add item":"Add property",icon:h.jsx(Z.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:p,onClick:R})})]}),l&&h.jsx("p",{role:"alert",children:l})]})}const Rr=S.createContext({callbacks:{}}),cn=xn.default.div`
58
+ `,Hy=E.forwardRef(function({style:t,...r},n){return h.jsx(Vx,{...r,ref:n,style:{...t,backgroundImage:"none","--flow-range-track":(t==null?void 0:t.backgroundImage)??"none"}})});function Cl({label:e,inputLabel:t,value:r,displayValue:n,min:o,max:i,onChange:s}){const a=E.useId(),{readOnly:u,themeColor:c}=$e(),{colorInactive:l}=Ye(),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:a,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",h.jsx("span",{children:n})]}),h.jsx(Hy,{id:a,"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=>s(Number(p.target.value))})]})}const _l={dot:{label:"Dots",icon:J.PiDotsNine},grid:{label:"Grid",icon:J.PiGridFour},steel:{label:"Steel",icon:J.PiLineSegments},none:{label:"Solid",icon:J.PiSquareFill},transparent:{label:"Transparent",icon:J.PiSelection}};function Ky(){const{spacing:e,setSpacing:t,edgeRadius:r,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:s,readOnly:a}=$e(),u=_l[o].icon;return h.jsxs(h.Fragment,{children:[h.jsx(Ft,{}),h.jsx(br,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:h.jsx(J.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:a,onValueChange:()=>{},popupContent:h.jsx(Cl,{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=s.onSpacingChange)==null||l.call(s,c/100)}}),children:h.jsx("option",{value:"spacing",children:"Spacing"})}),h.jsx(Ft,{}),h.jsx(br,{"aria-label":"Edge radius",title:`Edge radius: ${r??"Default"}`,icon:h.jsx(J.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:a,onValueChange:()=>{},popupContent:h.jsx(Cl,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:r??500,displayValue:r??"Default",onChange:c=>{var l;n(c),(l=s.onEdgeRadiusChange)==null||l.call(s,c)}}),children:h.jsx("option",{value:"radius",children:"Edge radius"})}),h.jsx(Ft,{}),h.jsxs(br,{"aria-label":"Background variant",title:`Background: ${_l[o].label}`,icon:h.jsx(u,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:a,onValueChange:c=>{var l;i(c),(l=s.onBackgroundVariantChange)==null||l.call(s,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 ar=[];for(let e=0;e<256;++e)ar.push((e+256).toString(16).slice(1));function Wx(e,t=0){return(ar[e[t+0]]+ar[e[t+1]]+ar[e[t+2]]+ar[e[t+3]]+"-"+ar[e[t+4]]+ar[e[t+5]]+"-"+ar[e[t+6]]+ar[e[t+7]]+"-"+ar[e[t+8]]+ar[e[t+9]]+"-"+ar[e[t+10]]+ar[e[t+11]]+ar[e[t+12]]+ar[e[t+13]]+ar[e[t+14]]+ar[e[t+15]]).toLowerCase()}let Qn;const Gx=new Uint8Array(16);function Ux(){if(!Qn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Qn=crypto.getRandomValues.bind(crypto)}return Qn(Gx)}const Hx=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Sl={randomUUID:Hx};function Ou(e,t,r){var o;if(Sl.randomUUID&&!e)return Sl.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??Ux();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,Wx(n)}const Cn={label:"Untitled",description:"",isTask:!1,isLocked:!1},Iu={id:null,type:"text",data:{...Cn,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"}}},El={id:null,type:"objectView",data:{...Cn,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},Kx={id:null,type:"arrayView",data:{...Cn,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"}}},jl={id:null,type:"workflowStep",data:{...Cn,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},yr=e=>typeof e=="object",Jy=e=>Array.isArray(e),Jx=["order","position","selected","locked","grabbed","grabbable","scratch"],Wr=e=>Object.entries(e).reduce((t,[r,n])=>(!yr(n)&&!r.startsWith("$")&&(t[r]=n),t),{}),Mu=(e,t)=>typeof e=="string"&&e.startsWith("$")?eo(e,t):yr(e)&&!Jy(e)?Object.entries(e).reduce((r,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete r["..."],r[n]={...eo(o,t),...e}):typeof o=="string"&&o.startsWith("$")?r[n]=eo(o,t):r[n]=o,r),{}):e,Gr=e=>Object.entries(e).reduce((t,[r,n])=>(yr(n)&&r&&n&&!r.startsWith("$")&&(Jx.includes(r)&&(r=r+"#"),t[r]=n),t),{}),et=(e,t,{label:r,parent:n=void 0},o,i=null)=>(i!==null&&(yr(i)||Jy(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}}),Dr=(e,t,r=null,n=null,o=null,i=!1,s=null)=>({data:{id:Ou(),source:o?t:e,target:o?e:t,label:n||"",isInverted:o,isEdgeAnimated:i,parent:s}}),Ur=(e,t=[])=>{const r={},n={};let o=[];if(e)for(const[i,s]of Object.entries(e))i.startsWith("$")&&i!=="$"?r[i.slice(1)]=s:i!=="$"?n[i]=s:i==="$"&&(o=s);return{newConfig:r,updatedObject:n,arrayObject:o}},pt=(e,t)=>{let r=El;const{view:n,borderColor:o,borderRadius:i,bgColor:s,textColor:a,fontSize:u,stepType:c}=t;e=n||e,c?r={...jl}:e==="object"?r=El:e==="text"?r=Iu:e==="array"?r=Kx:e==="workflowStep"&&(r={...jl});const l=r.data.viewProps;return r.data.viewProps={...l,borderRadius:i||(c?15:53),bgColor:s,borderColor:o,textColor:a,fontSize:u},r.data.config=t,{config:r}},Jt=(e,t)=>(e=t.find(n=>n.data.id===e)?`${e}.#`:e,e),eo=(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(a=>a.split(".").slice(-1)[0]===n||n===a);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((s,a)=>{a=a.replace("[","").replace("]","");const{arrayObject:u}=Ur(s);return s=u.length?u:s,s[a]},i))(t)};function yt(e,t="root",r=[]){try{const{arrayObject:n}=Ur(e);n.length&&(e=n);const o=Wr(e),i=Gr(e);return yr(e)?(Ne(e)||Ne(e)&&t==="root"||!Ne(e)&&Object.keys(o).length||t==="root")&&r.push(t):r.push(t),Object.keys(i).length&&!Ne(e)?Bt({chldPth:null,itrblObjct:i,nodes:r,path:t}):Ne(e)&&e.forEach((s,a)=>{const u=Wr(s),c=Gr(s),{newConfig:l,arrayObject:d}=Ur(s);let f=`${t}.${a}`;yr(s)?Object.keys(u).length?(yt(u,f,r),Object.keys(c).length&&!Ne(s)&&Bt({chldPth:f,itrblObjct:c,nodes:r,path:t})):Object.keys(c).length&&!Ne(s)?Bt({chldPth:f,itrblObjct:c,nodes:r,path:t}):Ne(s)&&Zy({chldPth:f,item:s,nodes:r,path:t}):r.push(f)}),{nodes:r}}catch{return{nodes:r}}}const Bt=({chldPth:e,itrblObjct:t,nodes:r,path:n})=>Object.entries(t).forEach(([o,i],s)=>{const a=Wr(i),u=Gr(i),{newConfig:c,arrayObject:l}=Ur(i);l.length&&(i=l),n.split(".").slice(0,2).join(".");let d=e?`${e}.${o}`:`${n}.${o}`;if(yr(i)&&!Ne(i)){const f=Object.keys(a).length===0;if(f&&(pt("array",c),r.push(d)),Object.keys(a).length){const p=Ne(i)?`${i.length||""}`:`{${Object.keys(i).length||""}}`;let y=d;f&&(y=`${d}.${p}`),yt(i,y,r)}else Object.keys(u).length&&!Ne(i)?Bt({chldPth:d,itrblObjct:u,path:d,nodes:r}):yt(i,d,r)}else Ne(i)&&yt(i,d,r)}),Zy=({chldPth:e,item:t,nodes:r,path:n})=>t.forEach((o,i)=>{let s=`${e}.${i}`;const a=Gr(o),u=Wr(o);yr(o)?!Ne(o)&&Object.keys(u).length?yt(o,s,r):Object.keys(a).length&&!Ne(o)?Bt({chldPth:s,itrblObjct:a,path:n,nodes:r}):Ne(o)&&Zy({chldPth:s,item:o,nodes:r,path:n}):r.push(s)}),yn=[];let zt;function tt(e,t="root",r=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},s={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:r,edges:n};const a=e;if(!zt){const{nodes:l}=yt(e);zt={ids:l,jsnObjct:e}}let{hideDefaultObject:u,sprtObjctKy:c}=i;try{t=Jt(t,r);const{newConfig:l,arrayObject:d}=Ur(e),f=Object.keys(s).length>0?s:l;d.length&&(e=d);const p=Wr(e),y=Gr(e),{label:g,collapsed:b,parent:x}=f;if(!yr(e))r.push(et(Iu,t,{label:g||t,parent:x},e,a));else if(Ne(e)||Ne(e)&&t==="root"){const{config:m}=pt("array",f),w=Ne(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,v=t==="root"?o:`${o} ${w}`;r.push(et(m,t,{label:g||v,parent:x},e,Ne(a)?{[o]:a}:a))}else if(!Ne(e)&&Object.keys(p).length||t==="root"){const{config:m}=pt(null,f),w=Ne(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,v=t.split("."),C=v[v.length-1];let S=isNaN(Number(C))?null:Number(C)+1;const j=isNaN(Number(C))?C:v[v.length-2]+" "+S,T=t==="root"?o:j;let k=!1;Number.isNaN(Number(o))||(k=!0);const M=e;if(g){const{config:R}=pt("object",f);r.push(et(R,t,{label:g||`${g} ${w}`,parent:x},p,M))}else m.data.headerTitle=T,r.push(et(m,t,{label:g,parent:x},p,M))}return b||(Object.keys(y).length&&!Ne(e)?Dt({flowConfig:i,chldPth:null,edges:n,isInverted:null,itrblObjct:y,nodes:r,path:t,newConfig:f}):Ne(e)&&e.forEach((m,w)=>{m=Mu(m,zt);const v=m,C=Wr(m),S=Gr(m),{newConfig:j,arrayObject:T}=Ur(m);T.length&&(m=T);const{config:k}=pt(typeof m=="string"?"text":"array",j),{hideConfig:M,sourceLabel:R,label:_,isEdgeAnimated:A,parent:I}=j;u=u||M;const q=t==="root"&&i.isCntr,O=t.split(".").slice(0,2).join("."),W=yn.includes(O),V=i.isCntr&&W||w%2===0&&q;let ue=`${t}.${w}`;ue=Jt(ue,r),V&&yn.push(ue),yr(m)?Object.keys(C).length&&!Ne(m)?(n.push(Dr(t,ue,null,R,V,A)),tt(m,ue,r,n,_||w,i,j)):Object.keys(S).length&&!Ne(m)?Dt({flowConfig:i,chldPth:ue,isInverted:V,edges:n,itrblObjct:S,nodes:r,path:t,newConfig:j,forceIsInverted:!0}):Ne(m)?Yy({flowConfig:i,chldPth:ue,edges:n,isInverted:V,item:m,nodes:r,path:t}):yr(m)&&Dt({flowConfig:i,chldPth:ue,isInverted:V,edges:n,itrblObjct:[m],nodes:r,path:t,newConfig:j}):(n.push(Dr(t,ue,null,R,V,A)),r.push(et(k,ue,{label:_||String(m),parent:I},m,v)))})),{nodes:r,edges:n}}catch{return{nodes:r,edges:n}}}const Dt=({chldPth:e,flowConfig:t,edges:r,itrblObjct:n,nodes:o,isInverted:i,path:s,newConfig:a,forceIsInverted:u=!1})=>{let{hideDefaultObject:c,sprtObjctKy:l}=t;return Object.entries(n).forEach(([d,f],p)=>{f=Mu(f,zt);const y=f,g=Wr(f),b=Gr(f),{newConfig:x,arrayObject:m}=Ur(f);m.length&&(f=m);const{hideConfig:w,sourceLabel:v,label:C,content:S,target:j,targetLabel:T,collapsed:k,isEdgeAnimated:M,parent:R}=x;c=c||w;const _=s==="root"&&t.isCntr,A=s.split(".").slice(0,2).join("."),I=yn.includes(A);u||(i=t.isCntr&&I||p%2===0&&_);let q=e?`${e}.${d}`:`${s}.${d}`;if(q=Jt(q,o),i&&yn.push(q),j&&r.push(Dr(q,j,null,T,i,M)),yr(f)&&!Ne(f)){r.push(Dr(s,q,null,v,i,M));const O=l||Object.keys(g).length===0;if(O){const W=S?"object":"array",{config:V}=pt(W,x);V.data.headerTitle=S?C:null,o.push(et(V,q,{label:C||d,parent:R},f,y))}if(Object.keys(g).length&&!c){const W=Ne(f)?` ${f.length||""}`:`{${Object.keys(f).length||""}}`;let V=q;O&&(V=`${q}.${W}`,V=Jt(V,o),r.push(Dr(q,V,null,v,i,M))),tt(f,V,o,r,C||d,t,x)}else Object.keys(b).length&&!Ne(f)?Dt({chldPth:q,flowConfig:t,itrblObjct:b,path:q,edges:r,nodes:o,newConfig:x,isInverted:i}):tt(f,q,o,r,d,t,x)}else Ne(f)&&(r.push(Dr(s,q,null,v,i,M)),tt(f,q,o,r,d,t,x))})},Yy=({flowConfig:e,chldPth:t,edges:r,isInverted:n,item:o,nodes:i,path:s})=>o.forEach((a,u)=>{let c=`${t}.${u}`;c=Jt(c,i);const l=a;a=Mu(a,zt);const d=Gr(a),f=Wr(a),{newConfig:p}=Ur(a),{collapsed:y,label:g,parent:b,sourceLabel:x,isEdgeAnimated:m,content:w}=p;yr(a)?!Ne(a)&&Object.keys(f).length?(r.push(Dr(s,c,null,x,n,m)),tt(a,c,i,r,u,e,p)):Object.keys(d).length&&!Ne(a)&&!y?Dt({chldPth:c,flowConfig:e,itrblObjct:d,path:s,edges:r,nodes:i,isInverted:n,newConfig:p}):Ne(a)&&Yy({flowConfig:e,chldPth:c,edges:r,isInverted:n,item:a,nodes:i,path:s}):(r.push(Dr(s,c,null,x,n,m)),i.push(et(Iu,c,{label:g||String(a),parent:b},a,l)))});function Yx(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,y;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=je(e,f))!=null&&p.$collapsed)&&(l=f),d.add(f),f=(y=o.get(f))==null?void 0:y.data.parent;return l},s=new Map(t.nodes.map(c=>[c.data.id,i(c)])),a=t.nodes.filter(c=>s.get(c.data.id)===c.data.id).map(c=>{if(!r.has(c.data.id))return c;const l=je(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(a.map(c=>c.data.id));return{nodes:a,edges:t.edges.flatMap(c=>{const l=s.get(c.data.source),d=s.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 _n(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]),s=t.get(i)??0;return t.set(i,s+1),[{value:o,key:`${i}#${s}`,index:n}]})}function Xy(e,t,r){const n=_n(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:s,...a}=e;return a}function Xx(e){const t=[],r=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,s)=>r(i,`${o}.${s}`));for(const i of _n(n)){const s=i.value;t.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:s.target,type:typeof s.type=="string"?s.type:void 0,sourceProperty:s.sourceProperty,targetProperty:s.targetProperty,icon:typeof s.icon=="string"?s.icon:void 0,label:typeof s.label=="string"?s.label:void 0,color:typeof s.color=="string"?s.color:void 0,isEdgeDashed:s.style==="dashed",isEdgeAnimated:s.style==="animated",...["dashed","traveling"].includes(s.animationVariant)?{edgeAnimationVariant:s.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,s])=>[i,i==="$"?r(s,o):i.startsWith("$")?s:r(s,`${o}.${i}`)]))};return{json:r(e,"root"),edges:t}}const Zt="root",Rl=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Mr(e){const t=e.split(".");for(t[0]===Zt&&t.shift();t.length&&Rl(t[t.length-1]);)t.pop();return t.filter(r=>!Rl(r))}function Sn(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function je(e,t){return Mr(t).reduce((r,n)=>{var o;if(r!=null)return(o=Sn(r))==null?void 0:o[n]},e)}function Qx(e){return Array.isArray(e)?[...e]:{...e}}function mr(e,t,r){const n=Mr(t),o=(i,s)=>{if(s===n.length)return r(i);const a=n[s],u=Sn(i);if(u==null||typeof u!="object")return i;const c=o(u[a],s+1);if(Object.is(c,u[a]))return i;const l=Qx(u);return l[a]=c,u!==i?{...i,$:l}:l};return o(e,0)}function Ir(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 cr(e,t,r,n){return mr(e,t,o=>r==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:Ir(o,r,n))}const Qy=(e,t,r)=>cr(e,t,"$collapsed",r);function Yt(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=Mr(r).join("."),i=Mr(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 zr(e,t,r,n){if(t.connection){const a=t.connection;return mr(e,a.address,u=>Xy(u,a.key,c=>{if(r==="$edgeIcon")return Ir(c,"icon",n);if(r==="$edgeType")return Ir(c,"type",n);if(r==="$edgeAnimationVariant")return Ir(c,"animationVariant",n);if(r==="$sourceLabel"||r==="$edgeColor")return Ir(c,r==="$sourceLabel"?"label":"color",n);const l=r==="$isEdgeAnimated"?"animated":"dashed";return n?{...c,style:l}:c.style===l?Ir(c,"style",void 0):c}))}const{address:o,kind:i}=Yt(t),s=i==="target"&&r==="$sourceLabel"?"$targetLabel":i==="target"&&r==="$edgeType"?"$targetEdgeType":i==="target"&&r==="$edgeIcon"?"$targetIcon":i==="target"&&r==="$edgeAnimationVariant"?"$targetAnimationVariant":r;return mr(e,o,a=>Ir(a,s,n))}const em=(e,t,r)=>zr(zr(e,t,"$isEdgeAnimated",r==="animated"||void 0),t,"$isEdgeDashed",r==="dashed"||void 0);function qu(e,t,r,n){let o=n||"";const i=mr(e,t,a=>{const u=Sn(a);if(Array.isArray(u)){o=String(u.length);const l=[...u,r];return u===a?l:{...a,$:l}}const c=a!=null&&typeof a=="object"&&!Array.isArray(a)?{...a}:a!=null&&typeof a!="object"?{$label:String(a)}:{};if(!o){let l=1;for(;`node_${l}`in c;)l++;o=`node_${l}`}return c[o]=r,c}),s=Mr(t);return{json:i,address:[Zt,...s,o].join(".")}}function rm(e,t){const r=Mr(t);if(!r.length)return e;const n=r[r.length-1],o=[Zt,...r.slice(0,-1)].join(".");return mr(e,o,i=>{const s=Sn(i);if(s==null||typeof s!="object"||!Object.prototype.hasOwnProperty.call(s,n))return i;if(Array.isArray(s)){const c=s.filter((l,d)=>String(d)!==n);return s===i?c:{...i,$:c}}const{[n]:a,...u}=i;return u})}const tm=(e,t,r,n)=>cr(n?mr(e,t,o=>Ir(o,"$targetLabel",n)):e,t,"$target",r);function Nu(e,t,r){const n=je(e,t);return _n(n).some(({value:i})=>i.target===r.target&&i.sourceProperty===r.sourceProperty&&i.targetProperty===r.targetProperty)?e:mr(e,t,i=>Ir(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...r,id:r.id||Ou()}]))}function nm(e,t){if(t.connection){const i=t.connection;return _n(je(e,i.address)).some(s=>s.key===i.key)?{json:mr(e,i.address,s=>Xy(s,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:r,kind:n}=Yt(t);return n==="hierarchy"?je(e,r)===void 0?{json:e,removed:!1}:{json:mr(e,r,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:mr(e,r,i=>{const{$target:s,$targetLabel:a,...u}=i||{};return u}),removed:!0}}function Su(e,t={}){var x;const r=Xx(e),{nodes:n,edges:o}=tt(r.json,Zt,[],[],t.title||"untitled",{hideDefaultObject:!!t.hideDefaultObject,sprtObjctKy:!!t.separateObjectKeys,isCntr:!!t.isCenter}),i=new Set(n.map(m=>m.data.id)),s=new Map;for(const m of n){const w=m.data.id;if(!w.endsWith(".0")||je(e,w)!==void 0)continue;const v=w.slice(0,-2),C=je(e,v);!i.has(v)&&C&&typeof C=="object"&&!Array.isArray(C)&&typeof C.$label=="string"&&Object.keys(C).every(S=>S.startsWith("$")&&S!=="$")&&s.set(w,v)}const a=m=>s.get(m)??m,u=new Set(n.flatMap(m=>m.data.parent?[a(m.data.parent)]:[])),c=n.map(m=>{var T;const w=a(m.data.id),v=je(e,w),C={...m.data,id:w},S=v&&typeof v=="object"&&!Array.isArray(v)&&"$"in v?v.$:v;if((Array.isArray(S)?S.length>0:S&&typeof S=="object"&&Object.keys(S).some(k=>!k.startsWith("$")))&&(C.config={...C.config,collapsed:!!v.$collapsed}),u.has(w)||(C.viewProps={...C.viewProps},delete C.viewProps.borderWidth),!v||typeof v!="object"||Array.isArray(v))return{data:C};if(v.$form&&typeof v.$form=="object"&&(C.config={...C.config,form:v.$form},C.type="objectView"),Array.isArray(v.$ports)){const k=v.$ports.filter(M=>M&&typeof M.id=="string"&&["source","target"].includes(M.role)&&["top","right","bottom","left"].includes(M.side));C.config={...C.config,ports:k}}return C.parent&&(C.parent=a(C.parent)),typeof v.$label=="string"&&(C.label=v.$label,C.headerTitle=v.$label),typeof v.$subtitle=="string"&&(C.config={...C.config,subtitle:v.$subtitle}),typeof v.$outline=="boolean"&&(C.viewProps={...C.viewProps,outline:v.$outline}),["solid","dashed","dotted","double"].includes(v.$borderStyle)&&(C.viewProps={...C.viewProps,borderStyle:v.$borderStyle}),Number.isFinite(v.$borderWidth)&&v.$borderWidth>=0&&(C.viewProps={...C.viewProps,borderWidth:v.$borderWidth}),Number.isFinite(v.$borderRadius)&&v.$borderRadius>=0&&(C.viewProps={...C.viewProps,borderRadius:v.$borderRadius}),typeof v.$isNodeAnimated=="boolean"&&(C.isNodeAnimated=v.$isNodeAnimated),["traveling","pulse"].includes(v.$nodeAnimationVariant)&&(C.nodeAnimationVariant=v.$nodeAnimationVariant),typeof v.$content=="string"&&(C.config={...C.config,content:v.$content},v.$view||(C.type="objectView")),(((T=C.config)==null?void 0:T.collapsed)!==void 0||v.$collapsed!==void 0||v.$icon!==void 0)&&(C.config={...C.config||{}},(v.$collapsed!==void 0||C.config.collapsed!==void 0)&&(C.config.collapsed=!!v.$collapsed),v.$icon!==void 0&&(C.config.icon=v.$icon)),{data:C}}),l=new Map,d=o.map(m=>{const w=a(m.data.source),v=a(m.data.target),C=`${w}->${v}`,S=l.get(C)??0;l.set(C,S+1);const j={...m.data,id:S?`${C}#${S}`:C,source:w,target:v},T=Yt(j),k=je(e,T.address);if(k&&typeof k=="object"){const M=k[T.kind==="target"?"$targetEdgeType":"$edgeType"];typeof M=="string"&&(j.type=M);const R=k[T.kind==="target"?"$targetIcon":"$edgeIcon"];typeof R=="string"&&(j.icon=R),k.$isEdgeAnimated!==void 0&&(j.isEdgeAnimated=!!k.$isEdgeAnimated);const _=k[T.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(_)&&(j.edgeAnimationVariant=_),k.$isEdgeDashed!==void 0&&(j.isEdgeDashed=!!k.$isEdgeDashed),k.$edgeColor&&(j.color=k.$edgeColor)}return{data:j}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const m=c.findIndex(w=>w.data.id===Zt);m!==-1&&c.splice(m,1)}const f=new Set(c.map(m=>m.data.id));for(let m=d.length-1;m>=0;m--){const w=d[m].data,v=Yt(w);(!f.has(w.source)||!f.has(w.target)||v.kind==="hierarchy"&&((x=je(e,v.address))==null?void 0:x.$hideParentEdge)===!0)&&d.splice(m,1)}d.push(...r.edges.filter(m=>f.has(m.data.source)&&f.has(m.data.target)));const p=Yx(e,{nodes:c,edges:d}),y=p.nodes.filter(m=>{var w;return(w=m.data.config)==null?void 0:w.collapsed}).map(m=>Mr(m.data.id));if(!y.length)return p;const g=p.nodes.filter(m=>{const w=Mr(m.data.id);return!y.some(v=>v.length<w.length&&v.every((C,S)=>C===w[S]))}),b=new Set(g.map(m=>m.data.id));return{nodes:g,edges:p.edges.filter(m=>b.has(m.data.source)&&b.has(m.data.target))}}function e0(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]})),s=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;(s.get(c)??s.set(c,[]).get(c)).push(l)}const a=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=[...s.get(u)||[]];for(;c.length;){const l=c.pop();r.has(l)||a.has(l)||(a.add(l),c.push(...s.get(l)||[]))}}return{nodes:e.filter(u=>!a.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 a.has(c)||a.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 $u(e,t){const r=JSON.parse(e);let n=512;const o=(s,a=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!s||typeof s!="object"||Array.isArray(s))throw new Error("Expected a JSON Schema object.");const 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(s))if(!u.has(l))throw new Error(`Unsupported JSON Schema keyword: ${l}`);const c=["$schema","$id","$defs","definitions","title","description","default","examples"];if(s.$ref){if(Object.keys(s).some(d=>!["$ref","title","description"].includes(d)))throw new Error("Use $ref without sibling constraints.");if(typeof s.$ref!="string"||!s.$ref.startsWith("#/")||a.includes(s.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let l=r;for(const d of s.$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: ${s.$ref}`);l=l[f]}return o(l,[...a,s.$ref])}if(s.anyOf){if(!Array.isArray(s.anyOf)||!s.anyOf.length||Object.keys(s).some(l=>l!=="anyOf"&&!c.includes(l)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:s.anyOf.map(l=>o(l,a))}}if(Object.prototype.hasOwnProperty.call(s,"const")||s.enum){if(Object.keys(s).some(f=>![...c,"const","enum","type"].includes(f))||s.enum&&Object.prototype.hasOwnProperty.call(s,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const l=Object.prototype.hasOwnProperty.call(s,"const")?[s.const]:s.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(s.type&&!(Array.isArray(s.type)?s.type:[s.type]).some(y=>y===p||y==="integer"&&Number.isInteger(f)))throw new Error("Literal does not match its declared type.");return{kind:"literal",value:f}})}}if(Array.isArray(s.type)){if(!s.type.length||s.type.some(l=>typeof l!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(s).some(l=>l!=="type"&&!c.includes(l)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:s.type.map(l=>o({type:l},a))}}if((s.properties||s.required||s.additionalProperties!==void 0)&&s.type!=="object"&&s.type!==void 0)throw new Error("Object constraints require an object type.");if(s.items&&s.type!=="array")throw new Error("items requires an array type.");if(s.type==="object"||s.properties){if(s.additionalProperties!==void 0&&s.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!s.properties||typeof s.properties!="object"||Array.isArray(s.properties))throw new Error("Object schemas must declare properties.");if(s.required!==void 0&&(!Array.isArray(s.required)||s.required.some(d=>typeof d!="string"||!Object.prototype.hasOwnProperty.call(s.properties,d))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(s.properties).map(([d,f])=>[d,{type:o(f,a),optional:!(s.required??[]).includes(d)}]))}}if(s.type==="array")return{kind:"array",items:o(s.items,a)};if(["string","number","integer","boolean","null"].includes(s.type))return{kind:s.type};throw new Error("Every property must declare a supported type.")},i=o(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(s=>s.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:t,nodes:i.properties}}async function Lu(e,t,r,n={}){var y;let o=512;const i=await import("typescript"),s=i.createSourceFile(t,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),a=s.parseDiagnostics;if(a!=null&&a.length)throw new Error("Invalid TypeScript syntax.");const u=new Map;for(const g of s.statements){if(!i.isInterfaceDeclaration(g)&&!i.isTypeAliasDeclaration(g))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((y=g.typeParameters)!=null&&y.length||u.has(g.name.text))throw new Error("Generics and duplicate declarations are not supported.");u.set(g.name.text,g)}const c=(g,b)=>{var C;const x={},m=g.find(S=>i.isIndexSignatureDeclaration(S));let w;if(m&&n.allowJson&&i.isIndexSignatureDeclaration(m)){if(g.filter(S=>i.isIndexSignatureDeclaration(S)).length!==1||m.parameters.length!==1||((C=m.parameters[0].type)==null?void 0:C.kind)!==i.SyntaxKind.StringKeyword||!m.type)throw new Error("Only one string-keyed index signature is supported for forms.");w=d(m.type,b)}return{kind:"object",properties:Object.fromEntries(g.filter(S=>S!==m||!w).map(S=>{if(!i.isPropertySignature(S)||!S.type||!S.name||!i.isIdentifier(S.name)&&!i.isStringLiteral(S.name))throw new Error("Only explicitly typed named properties are supported.");const j=d(S.type,b),T=n.allowJson?i.getJSDocTags(S).filter(k=>k.tagName.text==="port"):[];if(T.length>1)throw new Error(`Duplicate port declaration: ${S.name.text}`);if(T.length){const[k,M,R]=String(T[0].comment??"").trim().split(/\s+/);if(k!=="config"||!M||R||!u.has(M))throw new Error(`Config port ${S.name.text} requires @port config ResourceType`);const _=j.kind==="array";if((j.kind==="array"?j.items.kind:j.kind)!=="string")throw new Error(`Config port ${S.name.text} must be a string or string array reference`);x[S.name.text]={kind:"config",resourceType:M,multiple:_}}return[S.name.text,{type:j,optional:!!S.questionToken}]})),...w?{additionalProperties:w}:{},...Object.keys(x).length?{ports:x}:{}}},l=(g,b)=>{var C;if(b.includes(g))throw new Error("Recursive types are not supported.");const x=u.get(g);if(!x)throw new Error(`Unknown type: ${g}`);let m;if(i.isInterfaceDeclaration(x)){if((C=x.heritageClauses)!=null&&C.length)throw new Error("Interface inheritance is not supported; declare properties explicitly.");m=c(x.members,[...b,g])}else m=d(x.type,[...b,g]);const w=n.allowJson?i.getJSDocTags(x).filter(S=>S.tagName.text==="port"):[];if(!w.length)return m;if(m.kind!=="object")throw new Error("Node ports require an object interface");const v={...m.ports};for(const S of w){const[j,T,...k]=String(S.comment??"").trim().split(/\s+/);if(!["input","output","error"].includes(j)||!/^[A-Za-z][\w-]*$/.test(T??""))throw new Error("Node ports require @port input|output|error Name");const M=k.length?JSON.parse(k.join(" ")):void 0;if(M!==void 0&&typeof M!="string")throw new Error("Node port labels must be JSON strings");if(Object.prototype.hasOwnProperty.call(v,T))throw new Error(`Duplicate port declaration: ${T}`);v[T]={kind:j,...typeof M=="string"?{label:M}:{}}}return{...m,ports:v}},d=(g,b)=>{var x,m,w;if(--o<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(g.kind===i.SyntaxKind.StringKeyword)return{kind:"string"};if(g.kind===i.SyntaxKind.NumberKeyword)return{kind:"number"};if(g.kind===i.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[i.SyntaxKind.AnyKeyword,i.SyntaxKind.UnknownKeyword].includes(g.kind))return{kind:"json"};if(i.isParenthesizedTypeNode(g))return d(g.type,b);if(i.isUnionTypeNode(g))return{kind:"union",types:g.types.map(v=>d(v,b))};if(i.isArrayTypeNode(g))return{kind:"array",items:d(g.elementType,b)};if(i.isTypeLiteralNode(g))return c(g.members,b);if(i.isLiteralTypeNode(g)){const v=g.literal;if(i.isStringLiteral(v))return{kind:"literal",value:v.text};if(i.isNumericLiteral(v))return{kind:"literal",value:Number(v.text)};if(v.kind===i.SyntaxKind.NullKeyword)return{kind:"null"};if(v.kind===i.SyntaxKind.TrueKeyword||v.kind===i.SyntaxKind.FalseKeyword)return{kind:"literal",value:v.kind===i.SyntaxKind.TrueKeyword}}if(i.isTypeReferenceNode(g)&&i.isIdentifier(g.typeName)){if(n.allowJson&&g.typeName.text==="Record"&&!u.has("Record")&&((x=g.typeArguments)==null?void 0:x.length)===2&&g.typeArguments[0].kind===i.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:d(g.typeArguments[1],b)};if(g.typeName.text==="Array"&&((m=g.typeArguments)==null?void 0:m.length)===1)return{kind:"array",items:d(g.typeArguments[0],b)};if(!((w=g.typeArguments)!=null&&w.length))return l(g.typeName.text,b)}throw new Error(`Unsupported TypeScript type: ${g.getText(s)}`)},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 om(e,t){const r=await Lu(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 It(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=>It(r,t));if(t.kind==="union")return t.types.some(r=>It(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"?It(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)&&It(o.type,n.type):n.optional}):e.kind===t.kind}function Fu(e,t){if(!t.sourceProperty&&!t.targetProperty)return;const r=(s,a)=>{var l;const u=Object.prototype.hasOwnProperty.call(e.nodes,s)?s:s.replace(/^root\./,""),c=Object.prototype.hasOwnProperty.call(e.nodes,u)?(l=e.nodes[u])==null?void 0:l.type:void 0;return a&&(c==null?void 0:c.kind)==="object"&&Object.prototype.hasOwnProperty.call(c.properties,a)?c.properties[a]: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=s=>s.kind==="json"||s.kind==="object"&&(!!s.additionalProperties||Object.values(s.properties).some(a=>i(a.type)))||s.kind==="array"&&i(s.items)||s.kind==="union"&&s.types.some(i);if(i(n.type)||i(o.type))return"Unverified: arbitrary JSON or dictionary fields require runtime validation.";if(n.optional&&!o.optional)return"Optional source cannot supply a required target property.";if(!It(n.type,o.type))return`Incompatible property types: ${t.sourceProperty} -> ${t.targetProperty}.`}async function im(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 $u(t,e.name);if(/\.ts$/i.test(e.name))return om(t,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const kl=new WeakMap;function bt(e){if(!e||typeof e!="object")return e;const t=kl.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)=>bt(Reflect.get(e,i)),has:(o,i)=>Reflect.has(e,i),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(o,i)=>{const s=Reflect.getOwnPropertyDescriptor(e,i);return s&&{...s,value:bt(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:r,deleteProperty:r,defineProperty:r,setPrototypeOf:r,preventExtensions:r});return kl.set(e,n),n}function _t(e,t,r){var o;const n=t.split(".");for(let i=n.length;i>0;i--){const s=n.slice(0,i).join("."),a=(o=je(e,s))==null?void 0:o.$form;if(!(a!=null&&a.$type))continue;let u=Object.prototype.hasOwnProperty.call(r,a.$type)?r[a.$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(a.$fields??{}).filter(([d])=>!c||d.startsWith(`${c}.`)).map(([d,f])=>[c?d.slice(c.length+1):d,f]));return{type:u,fields:l,binding:a}}}async function Bu(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 s of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const a=await Lu(r,e.name,s,{allowJson:!0});o.push([s,a]);for(const u of Object.values(a.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=$u(r,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([o,i])=>[o,i.type]))}function En(e,t){return!e||("$in"in e?e.$in.includes(je(t,e.$address)):je(t,e.$address)===e.$equals)}function Vt(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 _r(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 s=Object.values(i).every(o);return n.delete(i),s};return o(t)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!_r(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=>!_r(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)&&_r(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>_r(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 Pl(e,t){const r=t.address.split(".");if(r.shift()!=="root"||!r.length||r.some(a=>!a||["__proto__","prototype","constructor","#"].includes(a)))throw new Error("Invalid form field address.");const n=r.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(r.some(a=>a.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...r].join("."),s=je(e,i);if(!s||typeof s!="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 cr(e,i,n,t.op==="remove"?void 0:t.value)}return mr(e,i,a=>{const u=Array.isArray(a.$)?a.$:a;if(t.op==="remove"&&!Object.prototype.hasOwnProperty.call(u,n)||t.op==="set"&&Object.is(u[n],t.value))return a;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===a?c:{...a,$:c}})}function jn(e,t,r){let n=Pl(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:bt(je(e,t.address)),data:bt(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=Pl(n,i)}return n}const Wt="data:image/svg+xml;base64,";function Fr(e){if(e.startsWith(Wt))return!0;try{const t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:")&&!t.username&&!t.password}catch{return!1}}async function r0(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(s=>/^on/i.test(s.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 Wt+btoa(o)}const kr=({name:e,svg:t=!1,...r})=>{const[n,o]=E.useState(null),[i,s]=E.useState(!0),[a,u]=E.useState(!1),c=typeof e=="string"&&Fr(e);if(E.useEffect(()=>{if(c||!e||e.length<2){o(null),s(!1);return}s(!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{s(!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 t0(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(s=>s.startsWith("$")||["__proto__","prototype","constructor"].includes(s)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;Xt(i),r=jn(r,{address:n.address,nodeAddress:o.slice(0,-1).join("."),value:i})}return Xt(r),r}function nn(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 Xt(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}`);Xt(r)}}function n0(e,t,r){Xt(t.value);const n=jn(e,t,r);return Xt(n),n}function am(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 s=je(t,n.$state);return s==null?"":typeof s=="object"?JSON.stringify(s,null,2):String(s)}let i=n;for(const[s,a]of Object.entries(n)){const u=r(a,s);u!==a&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,s,{value:u,enumerable:!0,writable:!0,configurable:!0}))}return i};return r(e)}const rt=(e="reference")=>({kind:e,text:"",paths:[""]}),sm=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(t=>["__proto__","constructor","prototype"].includes(t));function o0(e,t){const r=new Set(t.map(s=>s.path)),n=s=>{if(!s.paths.length||s.paths.some(a=>!sm(a)||!r.has(a)))throw new Error("Choose an available reference.");return[...s.paths,...s.fallback===void 0?[]:[JSON.stringify(s.fallback)]].join(" || ")},o=s=>{if(s.includes("{{")||s.includes("}}"))throw new Error("Use a reference part for dynamic values.");return s},i=s=>s.map(a=>{if(a.kind==="text")return o(a.text);if(a.kind==="conditional"){if(a.paths.length!==1||a.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(a)}}}${o(a.text)}{{/if}}`}return`{{${n(a)}}}`}).join("");if(e.mode==="reference"||e.mode==="condition"){if(e.parts.length!==1||e.parts[0].kind!=="reference")throw new Error("Choose one reference binding.");const s=i(e.parts);return e.mode==="condition"?`${s} == ${JSON.stringify(e.comparison)}`:s}if(e.mode==="json"){const s=e.fields.map(a=>a.key);if(!s.length||new Set(s).size!==s.length||s.some(a=>!a||["__proto__","constructor","prototype"].includes(a)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(a=>[a.key,i(a.parts)])))}return i(e.parts)}async function i0(e){const t=await import("typescript"),r=s=>{const a=t.createSourceFile("binding.ts",`(${s})`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS);if(a.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const u=a.statements[0];if(!u||!t.isExpressionStatement(u))throw new Error("Unsupported reference expression.");const c=rt();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(a);if(!sm(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=s=>{const a=[];let u=0;const c=/\{\{([\s\S]*?)\}\}/g;for(const l of s.matchAll(c)){const d=l.index;if(d<u)continue;d>u&&a.push({...rt("text"),text:s.slice(u,d)});const f=l[1].trim();if(f.startsWith("#if ")){const p=s.indexOf("{{/if}}",d+l[0].length);if(p<0)throw new Error("Unclosed condition.");a.push({...r(f.slice(4)),kind:"conditional",text:s.slice(d+l[0].length,p)}),u=p+7}else a.push(r(f)),u=d+l[0].length}return u<s.length&&a.push({...rt("text"),text:s.slice(u)}),a},o={mode:"reference",parts:[rt()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const s=JSON.parse(e);if(s&&typeof s=="object"&&!Array.isArray(s)&&Object.values(s).every(a=>typeof a=="string"))return{...o,mode:"json",fields:Object.entries(s).map(([a,u])=>({key:a,parts:n(u)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const s=t.createSourceFile("condition.ts",`value ${i[1].text}`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS),a=s.statements[0];if(s.statements.length===1&&t.isExpressionStatement(a)&&t.isBinaryExpression(a.expression)&&a.expression.operatorToken.kind===t.SyntaxKind.EqualsEqualsToken&&t.isStringLiteral(a.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:a.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function Al({parts:e,references:t,onChange:r,disabled:n}){const o=(i,s)=>r(e.map((a,u)=>u===i?{...a,...s}:a));return h.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,s)=>h.jsxs("fieldset",{"data-binding-part":s,style:{border:0,padding:0,margin:0,minWidth:0},children:[h.jsxs("legend",{children:["Part ",s+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:a=>o(s,{kind:a.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(J.PiCaretDown,{size:16,"aria-hidden":"true"})]}),h.jsx(Se,{"aria-label":`Remove part ${s+1}`,title:"Remove part",icon:h.jsx(J.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r(e.filter((a,u)=>u!==s))})]}),i.kind!=="text"&&h.jsxs(h.Fragment,{children:[i.paths.map((a,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:a,onChange:c=>o(s,{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(J.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},u)),i.kind==="reference"&&h.jsxs(h.Fragment,{children:[h.jsx(Se,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:h.jsx(J.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>o(s,{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:a=>o(s,{fallback:a.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&h.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:a=>o(s,{fallback:a.target.value})})]})]}),i.kind!=="reference"&&h.jsxs("label",{children:["Text",h.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:a=>o(s,{text:a.target.value})})]})]},s)),h.jsx(Se,{"aria-label":"Add part",title:"Add part",icon:h.jsx(J.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r([...e,rt()])})]})}function a0({label:e,value:t,references:r,disabled:n,onChange:o}){const[i,s]=E.useState(),[a,u]=E.useState(""),[c,l]=E.useState(!1),d=async()=>{l(!0),u("");try{s(await i0(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(Se,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:h.jsx(J.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=>s({...i,mode:f.target.value,parts:[rt()]}),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(J.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:y=>s({...i,fields:i.fields.map((g,b)=>b===p?{...g,key:y.target.value}:g)})})]}),h.jsx(Al,{parts:f.parts,references:r,disabled:n,onChange:y=>s({...i,fields:i.fields.map((g,b)=>b===p?{...g,parts:y}:g)})}),h.jsx(Se,{"aria-label":"Remove output field",title:"Remove output field",icon:h.jsx(J.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:i.fields.filter((y,g)=>g!==p)})})]},p)),h.jsx(Se,{"aria-label":"Add output field",title:"Add output field",icon:h.jsx(J.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:[...i.fields,{key:"",parts:[rt()]}]})})]}):h.jsx(Al,{parts:i.parts,references:r,disabled:n,onChange:f=>s({...i,parts:f})}),i.mode==="condition"&&h.jsxs("label",{children:["Equals",h.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:f=>s({...i,comparison:f.target.value})})]}),h.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[h.jsx(Se,{"aria-label":"Apply binding",title:"Apply binding",icon:h.jsx(J.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(o0(i,r)),s(void 0),u("")}catch(f){u(f instanceof Error?f.message:"Unable to apply binding.")}}}),h.jsx(Se,{"aria-label":"Cancel binding",title:"Cancel binding",icon:h.jsx(J.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{s(void 0),u("")}})]})]}),a&&h.jsx("p",{role:"alert",children:a})]})}const s0=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),c0=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,Mt=(e,t)=>JSON.stringify([e,t]);function Qt(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 Qt(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 qt(e){const t=Qt(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 Tl(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"&&!Vt(e)?e.types:[e]}function u0(e,t,r){if(t.address===r.address)return;const n=je(e,t.address),o=(i,s)=>s===void 0?!1:i.kind==="union"?i.types.some(a=>o(a,s)):i.kind==="array"?Array.isArray(s)&&s.every(a=>o(i.items,a)):i.kind==="object"?!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(i.properties).every(([a,u])=>u.optional&&s[a]===void 0||o(u.type,s[a]))&&Object.entries(s).every(([a,u])=>Object.prototype.hasOwnProperty.call(i.properties,a)||!i.additionalProperties||o(i.additionalProperties,u)):s===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!_r(i,s,!0);if(o(r.type,n))return structuredClone(n)}function l0(e,t,r,n){var u,c;const o={sourceSchema:r,sourceBindings:t,nodes:[],edges:[],schema:{...r},bindings:{...t},slots:new Map,containers:new Map},i=new Set(n.map(l=>l.data.id)),s=new Map(n.flatMap(l=>{const d=t[l.data.id];return d&&r[d.type]?[[d.address,l.data.id]]:[]})),a=(l,d,f,p,y,g=!1)=>{var j,T,k,M,R;if(y>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const b=je(e,d),x=Qt(f,b),m=x.kind!=="object"&&x.kind!=="array";o.containers.set(l,{address:d,type:x,declared:f,scalar:m});const w=`__form:${l}`,v={...(j=o.bindings[l])==null?void 0:j.fields},C={kind:"object",properties:{},ports:{...x.kind==="object"?x.ports:{},...g?{resource:{label:"output",...x.kind==="object"?(T=x.ports)==null?void 0:T.resource:{},kind:"output"}}:{}}},S=x.kind==="object"?{...x.properties,...Object.fromEntries(Object.keys(b??{}).filter(_=>!Object.prototype.hasOwnProperty.call(x.properties,_)&&x.additionalProperties).map(_=>[_,{type:x.additionalProperties,optional:!0}]))}:x.kind==="array"?Object.fromEntries((Array.isArray(b)?b:[]).map((_,A)=>[String(A),{type:x.items,optional:!0}])):{value:{type:Vt(f)?f:x,optional:!1}};for(const[_,A]of Object.entries(S)){if(!s0(_))throw new Error(`Unsupported structured property key: ${_}`);const I=m?d:`${d}.${_}`,q=je(e,I),O=Qt(A.type,q),W=O.kind==="object"||O.kind==="array",V=(k=C.ports)==null?void 0:k[_],ue=(V==null?void 0:V.kind)==="config"&&(((M=v[_])==null?void 0:M.$options)||Vt(A.type)),ne=A.type.kind==="json"||A.type.kind==="union"&&!Vt(A.type);if(((R=v[_])==null?void 0:R.$control)==="upload"||!W&&x.kind!=="array"&&(!ne||m)||ue){C.properties[_]={...A,type:A.type.kind==="json"?O:A.type};continue}const Q=s.get(I)??c0(I),he=x.kind==="array"?`Item ${Number(_)+1}`:_,le={address:I,owner:l,field:_,type:A.type,label:he,nodeId:Q,present:q!==void 0};if(o.slots.set(Mt(l,_),le),C.ports[_]={kind:"config",resourceType:`__form:${Q}`},q===void 0||(o.edges.push({data:{id:`__form-edge:${l}:${_}`,source:Q,target:l,sourceProperty:"output:resource",targetProperty:`config:${_}`,isEdgeDashed:!0}}),o.containers.has(Q)||s.has(I)))continue;if(i.has(Q))throw new Error(`Structured node identity conflict: ${Q}`);i.add(Q);const $={data:{id:Q,type:"objectView",label:he,headerTitle:he,description:{},config:{form:!0,icon:O.kind==="array"?"PiListNumbers":W?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push($),a(Q,I,A.type,p,y+1,!0);const D=o.schema[`__form:${Q}`];$.data.description=Object.fromEntries(Object.keys(D.properties).map(G=>[G,je(e,O.kind==="array"||O.kind==="object"?`${I}.${G}`:I)]).filter(([,G])=>G!==void 0))}o.schema[w]=C,o.bindings[l]={...o.bindings[l],address:d,type:w,fields:v}};for(const l of n){const d=t[l.data.id];if(d!=null&&d.portResources)continue;const f=d&&r[d.type];!d||!f||je(e,d.address)===void 0||a(l.data.id,d.address,f,(u=l.data.viewProps)==null?void 0:u.bgColor,0,o.edges.some(p=>p.data.source===l.data.id))}for(const l of o.edges){const d=o.bindings[l.data.source],f=o.schema[d.type].ports;f.resource={...f.resource,kind:"output",label:((c=f.resource)==null?void 0:c.label)??"output"}}return o}function d0({nodeAddress:e}){const{structured:t,data:r,callbacks:n,editable:o,onFieldCreate:i}=E.useContext(Pr),s=$e(),[a,u]=E.useState(""),[c,l]=E.useState("0"),[d,f]=E.useState(""),p=t==null?void 0:t.containers.get(e);if(!p||!r||!t)return null;const y=s.readOnly||s.config.editable===!1||!o,g=je(r,p.address),b=Tl(p.declared),x=p.type.kind==="array"?p.type.items:p.type.kind==="object"?p.type.additionalProperties:void 0,m=x?Tl(x):[],w=!!i&&p.type.kind==="object"&&(x==null?void 0:x.kind)==="json",v=_=>_.kind==="literal"?String(_.value):_.kind==="string"?"Text":Cr(_.kind),C=[...t.slots.values()].filter(_=>_.owner===e),S=(_,A)=>{var I;return(I=n.onFormChange)==null?void 0:I.call(n,{data:r,nodeAddress:p.address,address:_,previousValue:je(r,_),value:A})},j=_=>{var A;s.setSelectedNodeIds([_]),(A=s.engineRef.current)==null||A.focusNode(_,90,!1)},T=(_,A)=>{if(!Array.isArray(g))return;const I=[...g];[I[_],I[_+A]]=[I[_+A],I[_]],S(p.address,I)},k=()=>{const _=m[Number(c)]??m[0];if(_)if(p.type.kind==="array")S(p.address,[...Array.isArray(g)?g:[],qt(_)]);else{if(!a||a.includes(".")||a.startsWith("$")||["__proto__","constructor","prototype"].includes(a)){f("Choose a property name without dots or reserved prefixes.");return}if(Object.prototype.hasOwnProperty.call(g,a)){f("Property already exists.");return}w&&(c==="file"||c==="files")?i==null||i({data:r,nodeAddress:p.address,address:`${p.address}.${a}`,previousValue:void 0,value:c==="files"?[]:""},{$control:"upload"}):S(`${p.address}.${a}`,qt(_)),u(""),f("")}},M=p.type.kind==="object"&&!!p.type.additionalProperties,R=p.type.kind==="array";return h.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[b.length>1&&h.jsxs("label",{children:["Value type",h.jsx("span",{"data-form-select":"",style:{display:"block"},children:h.jsx(br,{"aria-label":"Value type",disabled:y,value:String(b.findIndex(_=>Qt(_,g).kind===p.type.kind)),onValueChange:_=>S(p.address,qt(b[Number(_)])),children:b.map((_,A)=>h.jsx("option",{value:A,children:v(_)},A))})})]}),C.map((_,A)=>h.jsxs("div",{"data-structured-slot":_.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[_.type.kind==="array"?h.jsx(J.PiListNumbers,{size:20}):h.jsx(J.PiBracketsCurly,{size:20}),h.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:Cr(_.label)}),h.jsx(Se,{"aria-label":`${_.present?"Focus":"Create"} ${Cr(_.label)}`,title:`${_.present?"Focus":"Create"} ${Cr(_.label)}`,icon:_.present?h.jsx(J.PiMagnifyingGlass,{size:18}):h.jsx(J.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:y&&!_.present,onClick:I=>{var q;_.present?((q=I.currentTarget.closest("dialog"))==null||q.close(),j(_.nodeId)):S(_.address,qt(_.type))}}),R&&h.jsxs(h.Fragment,{children:[h.jsx(Se,{"aria-label":`Move item ${A+1} up`,icon:h.jsx(J.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:y||A===0,onClick:()=>T(A,-1)}),h.jsx(Se,{"aria-label":`Move item ${A+1} down`,icon:h.jsx(J.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:y||A===C.length-1,onClick:()=>T(A,1)})]}),_.present&&h.jsx(Se,{"aria-label":`Remove ${Cr(_.label)}`,icon:h.jsx(J.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:y,onClick:()=>R?S(p.address,g.filter((I,q)=>q!==A)):S(_.address,void 0)})]},_.address)),(R||M)&&h.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[M&&h.jsxs("label",{style:{flex:"1 1 120px",minWidth:0,display:"grid",gap:8},children:["Property name",h.jsx("input",{"aria-label":"Property name",placeholder:"Required",value:a,disabled:y,onChange:_=>u(_.target.value)})]}),m.length>1&&h.jsxs("label",{style:{flex:"1 1 100px",minWidth:0,display:"grid",gap:8},children:["New value type",h.jsx("span",{"data-form-select":"",style:{display:"block"},children:h.jsxs(br,{"aria-label":"New value type",value:c,disabled:y,onValueChange:l,children:[m.map((_,A)=>h.jsx("option",{value:A,children:v(_)},A)),w&&h.jsx("option",{value:"file",children:"File"}),w&&h.jsx("option",{value:"files",children:"Files"})]})})]}),h.jsx("span",{style:{display:"flex",alignItems:"center",flexShrink:0,...M||m.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:h.jsx(Se,{"aria-label":R?"Add item":"Add property",icon:h.jsx(J.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:y,onClick:k})})]}),d&&h.jsx("p",{role:"alert",children:d})]})}const Pr=E.createContext({callbacks:{}}),ln=wn.default.div`
59
59
  padding: 0;
60
60
  font-size: 16px;
61
61
  line-height: 1.4;
@@ -72,7 +72,7 @@
72
72
  }
73
73
  & input:not([type="checkbox"]),
74
74
  & textarea,
75
- & select {
75
+ & [data-form-select] > [role="combobox"] {
76
76
  width: 100%;
77
77
  min-width: 0;
78
78
  box-sizing: border-box;
@@ -89,22 +89,68 @@
89
89
  min-height: 98px;
90
90
  resize: vertical;
91
91
  }
92
- & [data-form-select] {
92
+ & [data-upload-items] {
93
+ display: flex;
94
+ flex-wrap: wrap;
95
+ gap: 8px;
96
+ align-items: start;
97
+ }
98
+ & [data-upload-drop],
99
+ & [data-upload-preview] {
100
+ width: 120px;
101
+ max-width: 100%;
102
+ aspect-ratio: 1;
103
+ box-sizing: border-box;
104
+ border-radius: 8px;
93
105
  position: relative;
94
106
  }
95
- & [data-form-select] select {
96
- appearance: none;
97
- padding-right: 40px;
107
+ & [data-upload-drop] {
108
+ display: grid;
109
+ place-items: center;
110
+ padding: 0;
111
+ border: 2px dashed currentColor;
112
+ background: transparent;
113
+ color: inherit;
114
+ cursor: pointer;
115
+ }
116
+ & [data-upload-drop]:focus-visible,
117
+ & [data-upload-preview]:focus-within {
118
+ outline: 2px solid currentColor;
119
+ outline-offset: 2px;
98
120
  }
99
- & [data-form-select] > svg {
121
+ & [data-upload-preview] {
122
+ border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
123
+ background: color-mix(in srgb, currentColor 7%, transparent);
124
+ overflow: hidden;
125
+ }
126
+ & [data-upload-preview] > a {
127
+ display: grid;
128
+ place-items: center;
129
+ width: 100%;
130
+ height: 100%;
131
+ color: inherit;
132
+ }
133
+ & [data-upload-preview] img {
100
134
  position: absolute;
101
- right: 12px;
102
- top: 50%;
103
- transform: translateY(-50%);
104
- pointer-events: none;
135
+ inset: 0;
136
+ width: 100%;
137
+ height: 100%;
138
+ object-fit: contain;
105
139
  }
106
- & [data-form-select] select:disabled + svg {
107
- opacity: 0.55;
140
+ & [data-upload-actions] {
141
+ position: absolute;
142
+ right: 4px;
143
+ bottom: 4px;
144
+ display: flex;
145
+ gap: 4px;
146
+ background: var(--flow-upload-surface);
147
+ border-radius: 4px;
148
+ }
149
+ & [data-form-select] {
150
+ position: relative;
151
+ }
152
+ & [data-form-select] > [role="combobox"] {
153
+ height: auto;
108
154
  }
109
155
  & details {
110
156
  border-bottom: 1px solid color-mix(in srgb, currentColor 12%, transparent);
@@ -153,9 +199,9 @@
153
199
  font-size: 14px;
154
200
  margin-top: 8px;
155
201
  }
156
- `;function Tl({request:e,property:t,config:r,value:n,disabled:o}){var z,H;const{callbacks:i,structured:s,references:a}=S.useContext(Rr),{themeColor:c}=Ie(),{background:u}=Je(),l=S.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,y]=S.useState(f),[g,b]=S.useState(""),[x,m]=S.useState(0),[w,v]=S.useState(),C=((z=r.$options)==null?void 0:z.$source)==="callback",_=i.resolveFormOptions,{data:R,address:T,nodeAddress:A,nodeId:k}=e,j=S.useRef(R);j.current=R;const E=JSON.stringify([T,k,(H=r.$options)!=null&&H.$dependsOn?r.$options.$dependsOn.map(X=>we(R,X)):we(R,A)]);S.useEffect(()=>{y(f),b("")},[f,T,k]),S.useEffect(()=>{if(!C)return;const X=new AbortController;return Promise.resolve().then(()=>{if(!_)throw new Error("No options resolver configured");return _({address:T,nodeAddress:A,nodeId:k,data:Jt(j.current),signal:X.signal})}).then(le=>{if(!Array.isArray(le)||le.some(J=>!J||typeof J.label!="string"||!["string","number","boolean"].includes(typeof J.value)&&J.value!==null))throw new Error("Invalid options response");X.signal.aborted||v({key:E,options:le})}).catch(le=>{X.signal.aborted||v({key:E,options:[],error:le instanceof Error?le.message:"Options unavailable"})}),()=>X.abort()},[C,_,E,T,A,k,x]);const M=C&&(w==null?void 0:w.key)!==E,I=C?(w==null?void 0:w.key)===E?w.options:[]:t.type.kind==="null"?[{label:"Null",value:null}]:t.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:Dt(t.type),N=t.type.kind==="array",O=(s&&d||r.$control==="checkbox"?"pills":r.$control)??(I?N||t.type.kind==="boolean"?"pills":"select":t.type.kind==="boolean"?"checkbox":d?"textarea":"input"),W=!t.optional||!!r.$requiredWhen&&Sn(r.$requiredWhen,R),G=W?"Required":"Optional",ee=!!(a!=null&&a.length)&&typeof n=="string"&&n.includes("{{"),ne=g||C&&(w==null?void 0:w.key)===E&&w.error||!ee&&jr(t.type,n,W),ce=wr(r.$label??T.split(".").pop()),me=X=>{var le;if(!(o||Object.is(X,n)))try{(le=i.onFormChange)==null||le.call(i,{...e,previousValue:n,value:X}),b("")}catch(J){b(J instanceof Error?J.message:"Unable to update field")}},K=()=>{if(d){try{const V=p===""&&t.optional?void 0:JSON.parse(p),Y=jr(t.type,V,W);if(Y){b(Y);return}me(V)}catch{b("Enter valid JSON")}return}const X=t.type.kind==="number"||t.type.kind==="integer",le=p===""&&t.optional?void 0:X&&p!==""?Number(p):p,J=jr(t.type,le,W);if(X&&J&&p!==""){b(J);return}me(le)},q={id:l,disabled:o,"aria-label":ce,"aria-required":W,"aria-invalid":!!ne,"aria-describedby":ne?`${l}-error`:void 0},L=he(c);return h.jsxs("div",{"data-form-field":T,"data-flow-property":T.slice(A.length+1),children:[h.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[h.jsxs("label",{htmlFor:l,children:[ce,W?" *":""]}),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:()=>me(void 0),children:h.jsx(Z.PiArrowCounterClockwise,{size:14})})]}),!!(a!=null&&a.length)&&!d&&h.jsx(o0,{label:ce,value:n,references:a,disabled:o,onChange:me}),ee?null:O==="select"?h.jsxs("div",{"data-form-select":"",children:[h.jsxs("select",{...q,disabled:o||M||!!(w!=null&&w.error),value:(I==null?void 0:I.findIndex(X=>Object.is(X.value,n)))??-1,onChange:X=>{const le=I==null?void 0:I[Number(X.target.value)];le&&me(le.value)},children:[h.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):G}),I==null?void 0:I.map((X,le)=>h.jsx("option",{value:le,style:{background:he(u)},children:wr(X.label)||X.label},le))]}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}):O==="pills"?h.jsxs("div",{id:l,role:"group","aria-label":ce,"aria-describedby":q["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:[I==null?void 0:I.map((X,le)=>{const J=N?Array.isArray(n)&&n.includes(X.value):Object.is(n,X.value);return h.jsx("button",{type:"button",disabled:o||M,"aria-pressed":J,style:{padding:"8px 16px",borderRadius:24,border:0,color:J?L:"inherit",background:J?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>me(N?J?n.filter(V=>V!==X.value):[...Array.isArray(n)?n:[],X.value]:X.value),children:wr(X.label)||X.label},le)}),M&&h.jsx("span",{role:"status",children:"Loading..."})]}):O==="textarea"?h.jsx("textarea",{...q,placeholder:G,value:p,onChange:X=>y(X.target.value),onBlur:K}):h.jsx("input",{...q,placeholder:G,type:t.type.kind==="number"||t.type.kind==="integer"?"number":"text",step:t.type.kind==="integer"?1:"any",value:p,onChange:X=>y(X.target.value),onBlur:K,onKeyDown:X=>{X.key==="Enter"&&K(),X.key==="Escape"&&y(n===void 0?"":String(n))}}),ne&&h.jsx("div",{role:"alert",id:`${l}-error`,children:ne}),C&&(w==null?void 0:w.error)&&h.jsx("button",{type:"button",disabled:o,onClick:()=>{v(void 0),m(x+1)},children:"Retry"})]})}function sm({nodeAddress:e}){var v,C;const{data:t,schema:r,callbacks:n,bindings:o,editable:i,renderForm:s,structured:a}=S.useContext(Rr),{readOnly:c,config:u}=Ie(),l=s==null?void 0:s(e);if(l!==void 0)return h.jsx("fieldset",{"data-flow-form":e,disabled:c||u.editable===!1||!i,style:{border:0,margin:0,padding:0,minWidth:0},children:l});if(!t)return h.jsx(cn,{role:"alert",children:"Forms require a JSON document."});const d=o?rn(o,e,r):void 0,f=o?d:r&&xt(t,e,r);if(!f)return h.jsx(cn,{role:"status",children:"Form schema unavailable."});const p=(d==null?void 0:d.address)??e,y=we(t,p),g=(v=a==null?void 0:a.containers.get(e))==null?void 0:v.scalar;if(y===void 0||typeof y!="object"&&!g)return h.jsx(cn,{role:"alert",children:"Bound form state is unavailable."});const b=Object.entries(f.type.properties).filter(([_])=>{var R;return Sn((R=f.fields[_])==null?void 0:R.$visibleWhen,t)}),x=b.length>8||b.some(([_])=>{var R;return(R=f.fields[_])==null?void 0:R.$section}),m=new Map;for(const _ of b){const[R,T]=_,A=x?wr(((C=f.fields[R])==null?void 0:C.$section)??(T.type.kind==="object"||T.type.kind==="array"?R:T.optional?"Options":"General")):"";m.has(A)||m.set(A,[]),m.get(A).push(_)}const w=([_,R])=>h.jsx(Tl,{request:{data:t,address:g?p:`${p}.${_}`,nodeAddress:p,nodeId:typeof(y==null?void 0:y.id)=="string"?y.id:void 0},property:R,config:f.fields[_]??{},value:g?y:y==null?void 0:y[_],disabled:c||u.editable===!1||!(i??!!n.onJsonChange)},`${(y==null?void 0:y.id)??e}:${_}`);return h.jsxs(cn,{"data-flow-form":e,onClick:_=>_.stopPropagation(),onDoubleClick:_=>_.stopPropagation(),children:[a&&h.jsx(u0,{nodeAddress:e}),d&&f.type.additionalProperties&&b.length===0&&h.jsx(Tl,{request:{data:t,address:p,nodeAddress:p},property:{type:f.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:y,disabled:c||u.editable===!1||!i}),[...m].map(([_,R])=>x&&R.length>1?h.jsxs("details",{open:!0,children:[h.jsxs("summary",{children:[h.jsx("span",{children:_}),h.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),R.map(w)]},_):R.map(w))]})}function cm(e){const{viewData:t}=S.useContext(Rr),{nodeById:r,edgeById:n,parentIds:o}=Ur();if(t){const i=we(t,e),s=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(s)?s.length>0:!!s&&typeof s=="object"&&Object.entries(s).some(([a,c])=>!a.startsWith("$")&&c!==null&&typeof c=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const s=i.isInverted?i.target:i.source,a=i.isInverted?i.source:i.target;return s===e&&a!==e&&r.has(a)})}function Xt(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:t}function gn(e,t,r,n){return{borderColor:t,borderWidth:Xt(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",...by(t==="transparent"?"currentColor":t,r,".flow-sdk-node:hover &",!r)}}function um({label:e,value:t,options:r,onChange:n,disabled:o}){var i;return h.jsxs(Or,{"aria-label":e,title:`Animation: ${((i=r.find(s=>s.value===t))==null?void 0:i.label)??"Mixed"}`,value:t,style:{width:104},disabled:o,onValueChange:s=>{const a=r.find(c=>c.value===s);a&&n(a.value)},children:[t===""&&h.jsx("option",{value:"",disabled:!0,children:"Mixed"}),r.map(s=>h.jsx("option",{value:s.value,children:s.label},s.value))]})}const yn="data:image/svg+xml;base64,";function It(e){if(e.startsWith(yn))return!0;try{const t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:")&&!t.username&&!t.password}catch{return!1}}async function l0(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(s=>/^on/i.test(s.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 yn+btoa(o)}const Mr=({name:e,svg:t=!1,...r})=>{const[n,o]=S.useState(null),[i,s]=S.useState(!0),[a,c]=S.useState(!1),u=typeof e=="string"&&It(e);if(S.useEffect(()=>{if(u||!e||e.length<2){o(null),s(!1);return}s(!0),c(!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),c(!0),o(null)}finally{s(!1)}})()},[e,u]),u){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 Bu({nodeId:e,edgeId:t,value:r}){const{callbacks:n,readOnly:o,themeColor:i}=Ie(),{background:s,backgroundSecondary:a,border:c,colorText:u}=Je(),l=S.useRef(null),d=S.useId(),f=S.useRef(null),p=S.useRef(0),[y,g]=S.useState(!1),[b,x]=S.useState("icons"),[m,w]=S.useState([]),[v,C]=S.useState("loading"),[_,R]=S.useState(""),[T,A]=S.useState(0),[k,j]=S.useState(""),[E,M]=S.useState(""),[I,N]=S.useState(!1);S.useEffect(()=>()=>{p.current++},[]),S.useEffect(()=>{if(!y)return;let K=!0;return import("react-icons/pi").then(q=>{K&&(w(Object.keys(q).filter(L=>L.startsWith("Pi")).sort()),C("ready"))}).catch(()=>{K&&C("unavailable")}),()=>{K=!1}},[y]),S.useEffect(()=>{var K;o&&((K=l.current)==null||K.close())},[o]);const O=K=>{var q,L,z;o||(t?(q=n.onEdgeIconChange)==null||q.call(n,t,K):e&&((L=n.onNodeIconChange)==null||L.call(n,e,K)),(z=l.current)==null||z.close())},W=m.filter(K=>K.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(_.trim().toLowerCase())),G=36,ee=Math.max(1,Math.ceil(W.length/G)),ne=Math.min(T,ee-1),ce=W.slice(ne*G,(ne+1)*G),me={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${he(c)}`,borderRadius:30};return h.jsxs(h.Fragment,{children:[h.jsx(Re,{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:he(i),disabled:o,onClick:()=>{var K;M(""),x(r&&It(r)?"custom":"icons"),j(r&&!r.startsWith(yn)&&It(r)?r:""),g(!0),(K=l.current)==null||K.showModal()}})}),h.jsx(D.chakra.dialog,{ref:l,"aria-label":t?"Choose edge icon":"Choose node icon",css:zr(he(s),he(c)),onClose:()=>{g(!1),p.current++,N(!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",borderRadius:30,background:he(s),color:he(u)},children:y&&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(Re,{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||I,onClick:()=>O("")})}),h.jsx(vt,{"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 ${he(c)}`},children:["icons","custom"].map(K=>h.jsx("button",{id:`${d}-${K}`,type:"button",role:"tab","aria-selected":b===K,"aria-controls":`${d}-panel`,tabIndex:b===K?0:-1,onClick:()=>{x(K),M("")},onKeyDown:q=>{var z;if(!["ArrowLeft","ArrowRight","Home","End"].includes(q.key))return;q.preventDefault();const L=q.key==="Home"?"icons":q.key==="End"||K==="icons"?"custom":"icons";x(L),M(""),(z=document.getElementById(`${d}-${L}`))==null||z.focus()},style:{flex:1,padding:"8px 12px",background:"transparent",border:0,borderBottom:`2px solid ${b===K?he(i):"transparent"}`,color:b===K?he(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:I||o,onChange:async K=>{var z;const q=(z=K.target.files)==null?void 0:z[0];if(K.target.value="",!q)return;const L=++p.current;N(!0),M("");try{const H=await l0(q);L===p.current&&O(H)}catch(H){L===p.current&&M(H instanceof Error?H.message:"Unable to read SVG.")}finally{L===p.current&&N(!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:_,onChange:K=>{R(K.target.value),A(0)},style:me}),h.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[ce.map(K=>h.jsx("button",{type:"button","aria-label":`Choose ${K}`,"aria-pressed":r===K,title:K,onClick:()=>O(K),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${r===K?2:1}px solid ${he(r===K?i:c)}`,background:he(r===K?s:a),color:"inherit",cursor:"pointer"},children:h.jsx(Mr,{name:K,size:24})},K)),ce.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:[W.length," icons · ",ne+1," / ",ee]}),h.jsxs("div",{style:{display:"flex",gap:4},children:[h.jsx(Re,{label:"Previous icons",children:h.jsx(ve,{"aria-label":"Previous icons",icon:h.jsx(Z.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:ne===0,onClick:()=>A(ne-1)})}),h.jsx(Re,{label:"Next icons",children:h.jsx(ve,{"aria-label":"Next icons",icon:h.jsx(Z.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:ne+1>=ee,onClick:()=>A(ne+1)})})]})]})]}):h.jsxs(h.Fragment,{children:[r&&It(r)&&h.jsx(Mr,{name:r,size:64}),h.jsxs("button",{type:"button",disabled:I||o,onClick:()=>{var K;return(K=f.current)==null?void 0:K.click()},style:{...me,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[h.jsx(Z.PiUploadSimple,{}),I?"Uploading...":"Upload SVG"]}),h.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:K=>{K.preventDefault(),!(I||o)&&(!It(k.trim())||k.trim().startsWith(yn)?M("Enter an HTTP or HTTPS image URL."):O(k.trim()))},children:[h.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:k,disabled:I||o,onChange:K=>j(K.target.value),style:{...me,flex:1,minWidth:0}}),h.jsx(Re,{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:I||o||!k.trim(),style:{flexShrink:0}})})]})]})}),E&&h.jsx("div",{role:"alert",style:{fontSize:13},children:E})]})})]})}const mn=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500"],lm=["gray.900","gray.600","gray.200","white"];function dm(){const{config:e}=Ie(),t=e.selectionToolbar||{},r=new Set(t.hide||[]);return{palette:t.palette||mn,show:n=>!r.has(n)}}function ur(){const{border:e}=Je();return h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:e})}function tt({value:e,placeholder:t,ariaLabel:r,width:n="140px",type:o="text",min:i,onCommit:s}){const{colorText:a}=Je(),[c,u]=S.useState(e),l=S.useRef(!1);S.useEffect(()=>u(e),[e]);const d=()=>{if(l.current)return;l.current=!0;const f=c.trim();if(o==="number"&&f!==""&&(!Number.isFinite(Number(f))||Number(f)<(i??0))){u(e);return}f!==e&&s(f)};return h.jsx(D.Input,{"aria-label":r,type:o,min:i,size:"xs",w:n,value:c,placeholder:t,color:a,borderWidth:0,_focusVisible:{boxShadow:"none",outline:"none"},borderRadius:"8px",onFocus:()=>{l.current=!1},onChange:f=>u(f.target.value),onBlur:d,onKeyDown:f=>{f.key==="Enter"&&(d(),f.target.blur()),f.key==="Escape"&&(l.current=!0,u(e),f.target.blur())}})}function mt({colors:e,value:t,label:r,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:s,colorText:a}=Je(),[c,u]=S.useState(!1),l=S.useId(),d=S.useRef(null),f=t??e[0]??"transparent";return h.jsxs(D.HStack,{gap:1,"aria-label":r,role:"group",onKeyDown:p=>{var y;p.key==="Escape"&&(u(!1),(y=d.current)==null||y.focus())},children:[h.jsx(Re,{label:`${r}: ${f}`,children:h.jsx(D.chakra.button,{ref:d,type:"button","aria-label":`${r} colors`,"aria-expanded":c,"aria-controls":l,w:4,h:4,flexShrink:0,borderRadius:"full",cursor:"pointer",style:{backgroundColor:he(f),...f==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${he(a)}`,outlineOffset:"1px",onClick:()=>u(p=>!p)})}),c&&h.jsxs(D.HStack,{id:l,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(p=>{const y=t===p;return h.jsx(Re,{label:`${r}: ${p}`,children:h.jsx(D.Box,{as:"button","aria-label":`${r} ${p}`,"aria-pressed":y,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:he(p),...p==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:y?`2px solid ${he(a)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>n(p),onDoubleClick:g=>{var b;g.stopPropagation(),u(!1),(b=d.current)==null||b.focus()}})},p)}),o&&h.jsx(Re,{label:`Reset ${r.toLowerCase()}`,children:h.jsx(ve,{"aria-label":`Reset ${r}`,icon:h.jsx(D.Icon,{as:Z.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:s,onClick:()=>{var p;o(),u(!1),(p=d.current)==null||p.focus()}})})]})]})}function fm({edgeId:e,onClose:t}){var p;const{callbacks:r,themeColor:n,config:o}=Ie(),{colorInactive:i}=Je(),{edgeById:s}=Ur(),{palette:a,show:c}=dm(),u=(p=s.get(e))==null?void 0:p.data,l=[...new Set(["rounded-orthogonal","orthogonal","straight","bezier",...Object.keys(o.customEdgeTypes??{}),...u!=null&&u.type?[u.type]:[]])],d=u!=null&&u.isEdgeAnimated?"animated":u!=null&&u.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(vt,{onClick:t}),c("label")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(tt,{ariaLabel:"Edge label",placeholder:"Edge label",value:(u==null?void 0:u.label)||"",onCommit:y=>{var g;return(g=r.onEdgeLabelChange)==null?void 0:g.call(r,e,y)}})]}),c("style")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),f.map(y=>h.jsx(Re,{label:y.label,children:h.jsx(ve,{"aria-label":`Edge style ${y.key}`,"aria-pressed":d===y.key,icon:h.jsx(D.Icon,{as:y.icon,boxSize:5}),size:"sm",variant:"ghost",color:d===y.key?n:i,onClick:()=>{var g;return(g=r.onEdgeStyleChange)==null?void 0:g.call(r,e,y.key)}})},y.key)),d==="animated"&&h.jsx(um,{label:"Edge animation",value:(u==null?void 0:u.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:o.readOnly,onChange:y=>{var g;return(g=r.onEdgeAnimationVariantChange)==null?void 0:g.call(r,e,y)}}),h.jsxs(Or,{"aria-label":"Edge shape",title:`Edge shape: ${(u==null?void 0:u.type)??"Default"}`,icon:h.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:(u==null?void 0:u.type)??"",disabled:o.readOnly,onValueChange:y=>{var g;return(g=r.onEdgeTypeChange)==null?void 0:g.call(r,e,y||void 0)},children:[h.jsx("option",{value:"",children:"Default"}),l.map(y=>h.jsx("option",{value:y,children:y},y))]})]}),c("icon")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Bu,{edgeId:e,value:u==null?void 0:u.icon},e),h.jsx(tt,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(u==null?void 0:u.icon)??"",onCommit:y=>{var g;return(g=r.onEdgeIconChange)==null?void 0:g.call(r,e,y)}})]}),c("color")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(mt,{label:"Edge color",colors:a,value:u==null?void 0:u.color,onPick:y=>{var g;return(g=r.onEdgeColorChange)==null?void 0:g.call(r,e,y)},onReset:()=>{var y;return(y=r.onEdgeColorChange)==null?void 0:y.call(r,e,"")}})]}),c("delete")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Re,{label:"Delete edge",children:h.jsx(ve,{"aria-label":"Delete edge",icon:h.jsx(D.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var y;(y=r.onEdgeDelete)==null||y.call(r,e,u),t()}})})]})]})}function hm({ids:e,showDivider:t=!0}){const{callbacks:r,config:n}=Ie(),{colorInactive:o}=Je(),{nodeById:i}=Ur(),[s,a]=S.useState(!1),c=e.map(y=>{var g,b;return(b=(g=i.get(y))==null?void 0:g.data.viewProps)==null?void 0:b.borderRadius}),u=!c.every(y=>y===c[0]),l=u?"mixed":String(c[0]??""),d=["0","8","16","30","53","100"],f=s||!u&&l!==""&&!d.includes(l),p=y=>e.forEach(g=>{var b;return(b=r.onNodeBorderRadiusChange)==null?void 0:b.call(r,g,y)});return h.jsxs(h.Fragment,{children:[t&&h.jsx(ur,{}),h.jsx(D.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:h.jsxs(Or,{icon:h.jsx(D.Icon,{as:iv.TbBorderRadius,boxSize:5,color:o,"aria-hidden":"true"}),"aria-label":"Node border radius",title:`Border radius: ${u?"Mixed":c[0]===void 0?"Default":`${c[0]}px`}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",cursor:"pointer"},value:f?"custom":l,disabled:n.readOnly,onValueChange:y=>{a(y==="custom"),y!=="custom"&&p(y===""?void 0:Number(y))},children:[h.jsx("option",{value:"",children:"Default radius"}),u&&h.jsx("option",{value:"mixed",disabled:!0,children:"Mixed radii"}),d.map(y=>h.jsxs("option",{value:y,children:[y,"px radius"]},y)),h.jsx("option",{value:"custom",children:"Custom radius"})]})}),f&&h.jsx(tt,{ariaLabel:"Custom border radius",placeholder:u?"Mixed":"Auto",type:"number",min:0,width:"72px",value:u?"":l,onCommit:y=>p(y===""?void 0:Number(y))})]})}function pm({ids:e,onClose:t}){var K,q,L,z,H,X,le,J;const{callbacks:r,colorMode:n,themeColor:o,config:i,setNodeViewMode:s}=Ie(),{colorText:a,colorInactive:c}=Je(),{nodeById:u,parentIds:l}=Ur(),{palette:d,show:f}=dm(),p=e.length===1,y=p?(K=u.get(e[0]))==null?void 0:K.data:void 0,g=e.map(V=>{var Y,te;return((te=(Y=u.get(V))==null?void 0:Y.data.config)==null?void 0:te.typeView)??""}),b=g.some(V=>V!==g[0]),x=b?"mixed":g[0]??"",m=e.some(V=>{var te,de;const Y=(te=u.get(V))==null?void 0:te.data;return Y&&(l.has(V)||((de=Y.config)==null?void 0:de.parentContainer)||Object.prototype.hasOwnProperty.call(i.customViews??{},Y.type))}),w=(q=y==null?void 0:y.config)==null?void 0:q.collapsed,v=cm(e[0]),C=V=>{var Y,te,de;return(((te=(Y=u.get(V))==null?void 0:Y.data.viewProps)==null?void 0:te.outline)??(l.has(V)?(de=i.parentNodeStyle)==null?void 0:de.outline:!1))===!0},_=e.every(C),R=!_&&e.some(C),T=V=>{var Y;return((Y=u.get(V))==null?void 0:Y.data.isNodeAnimated)===!0},A=e.every(T),k=!A&&e.some(T),j=e.map(V=>{var Y;return((Y=u.get(V))==null?void 0:Y.data.nodeAnimationVariant)??"traveling"}),E=j.every(V=>V===j[0])?j[0]:"",M=V=>e.forEach(V),[I,N]=S.useState(!1),O=I&&f("color")&&f("borderColor"),W=V=>{var Y,te,de;return(((te=(Y=u.get(V))==null?void 0:Y.data.viewProps)==null?void 0:te.borderStyle)??(l.has(V)?(de=i.parentNodeStyle)==null?void 0:de.borderStyle:"solid"))==="dashed"},G=e.every(W),ee=!G&&e.some(W),ne=e.map(V=>{var de,ue,Se;const Y=(de=u.get(V))==null?void 0:de.data,te=l.has(V)?Xt((ue=i.parentNodeStyle)==null?void 0:ue.borderWidth,6):(Y==null?void 0:Y.type)==="objectView"?3:2;return Xt((Se=Y==null?void 0:Y.viewProps)==null?void 0:Se.borderWidth,te)}),ce=ne.every(V=>V===ne[0])?String(ne[0]??""):"",me=V=>M(Y=>{var te,de;O?(te=r.onNodeBorderColorChange)==null||te.call(r,Y,V):(de=r.onNodeColorChange)==null||de.call(r,Y,"bg",V)});return h.jsxs(h.Fragment,{children:[h.jsx(vt,{onClick:t}),h.jsx(ur,{}),p&&f("label")?h.jsx(tt,{ariaLabel:"Node label",placeholder:"Node label",value:(y==null?void 0:y.label)??(y==null?void 0:y.headerTitle)??"",onCommit:V=>{var Y;return(Y=r.onNodeLabelChange)==null?void 0:Y.call(r,e[0],V)}}):h.jsxs(D.Text,{fontSize:"xs",color:a,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),f("typeView")&&h.jsxs(Or,{"aria-label":"Type view",title:m?"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||m,onValueChange:V=>{Gt.includes(V)&&M(Y=>{var te,de;(te=r.onNodeTypeViewChange)==null||te.call(r,Y,V||void 0),s(Y,"default"),(de=r.onNodeViewToggle)==null||de.call(r,Y)})},children:[b&&h.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),Gt.map(V=>h.jsx("option",{value:V,children:V||"None"},V))]}),f("style")&&h.jsx(hm,{ids:e},e.join("\0")),f("outline")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Re,{label:_?"Restore node fill":"Remove node fill",children:h.jsx(ve,{"aria-label":"Toggle node outline","aria-pressed":R?"mixed":_,icon:h.jsx(D.Icon,{as:_?Z.PiSquare:Z.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:_?o:c,onClick:()=>M(V=>{var Y;return(Y=r.onNodeOutlineChange)==null?void 0:Y.call(r,V,!_)})})})]}),f("color")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),f("borderColor")&&h.jsx(Re,{label:O?"Edit node colors":"Edit node border",children:h.jsx(ve,{"aria-label":"Edit node border","aria-pressed":O,icon:h.jsx(D.Icon,{as:Z.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:O?o:c,bg:O?n==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>N(V=>!V)})}),h.jsx(mt,{label:O?"Border color":"Background",colors:d,value:O?((L=y==null?void 0:y.viewProps)==null?void 0:L.borderColor)??(p&&l.has(e[0])?(z=i.parentNodeStyle)==null?void 0:z.borderColor:void 0):(H=y==null?void 0:y.viewProps)==null?void 0:H.bgColor,onPick:me,onReset:()=>me("")}),O&&f("style")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Re,{label:G?"Solid border":"Dashed border",children:h.jsx(ve,{"aria-label":"Toggle dashed border","aria-pressed":ee?"mixed":G,icon:h.jsx(D.Icon,{as:G?Z.PiLineSegments:Z.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:G?o:c,onClick:()=>M(V=>{var Y;return(Y=r.onNodeBorderStyleChange)==null?void 0:Y.call(r,V,G?"solid":"dashed")})})}),h.jsx(tt,{ariaLabel:"Border thickness",placeholder:p?"Auto":"Mixed",width:"64px",type:"number",min:0,value:ce,onCommit:V=>M(Y=>{var te;return(te=r.onNodeBorderWidthChange)==null?void 0:te.call(r,Y,V===""?void 0:Number(V))})})]})]}),f("animation")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Re,{label:A?"Stop border animation":"Animate node border",children:h.jsx(ve,{"aria-label":"Toggle node animation","aria-pressed":k?"mixed":A,icon:h.jsx(D.Icon,{as:Z.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:A?o:c,onClick:()=>M(V=>{var Y;return(Y=r.onNodeAnimationChange)==null?void 0:Y.call(r,V,!A)})})}),(A||k)&&h.jsx(um,{label:"Node animation",value:E,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:i.readOnly,onChange:V=>M(Y=>{var te;return(te=r.onNodeAnimationVariantChange)==null?void 0:te.call(r,Y,V)})})]}),!O&&f("textColor")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(mt,{label:"Text color",colors:lm,value:(X=y==null?void 0:y.viewProps)==null?void 0:X.textColor,onPick:V=>M(Y=>{var te;return(te=r.onNodeColorChange)==null?void 0:te.call(r,Y,"text",V)}),onReset:()=>M(V=>{var Y;return(Y=r.onNodeColorChange)==null?void 0:Y.call(r,V,"text","")})})]}),p&&f("icon")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Bu,{nodeId:e[0],value:(le=y==null?void 0:y.config)==null?void 0:le.icon},e[0]),h.jsx(tt,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((J=y==null?void 0:y.config)==null?void 0:J.icon)||"",onCommit:V=>{var Y;return(Y=r.onNodeIconChange)==null?void 0:Y.call(r,e[0],V)}})]}),p&&v&&f("collapse")&&w!==void 0&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Re,{label:w?"Expand":"Collapse",children:h.jsx(ve,{"aria-label":w?"Expand node":"Collapse node",icon:h.jsx(D.Icon,{as:w?Z.PiArrowsOutLineVertical:Z.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:c,onClick:()=>{var V;return(V=r.onNodeCollapse)==null?void 0:V.call(r,e[0],!w)}})})]}),f("delete")&&h.jsxs(h.Fragment,{children:[h.jsx(ur,{}),h.jsx(Re,{label:p?"Delete node":`Delete ${e.length} nodes`,children:h.jsx(ve,{"aria-label":"Delete selected nodes",icon:h.jsx(D.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:n==="dark"?"red.300":"red.500",onClick:()=>{M(V=>{var Y,te;return(te=r.onNodeDelete)==null?void 0:te.call(r,V,((Y=u.get(V))==null?void 0:Y.data)||{id:V})}),t()}})})]})]})}async function gm(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 ym(e,t="squeed.svg"){const r=document.createElement("a");r.href=await gm(e),r.download=t.endsWith(".svg")?t:`${t}.svg`,r.click()}function mm(){const{themeColor:e}=Ie(),[t,r]=S.useState(!1),[n,o]=S.useState("");return h.jsxs(h.Fragment,{children:[h.jsx(Re,{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 a;const s=(a=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:a.querySelector("[data-flow-background]");if(!s){o("Diagram not available for export.");return}r(!0),o("");try{await ym(s)}catch(c){o(c instanceof Error?c.message:"Unable to export SVG.")}finally{r(!1)}}})}),n&&h.jsx("span",{role:"alert",style:{fontSize:12,maxWidth:220},children:n})]})}function bm({children:e,background:t,border:r}){const n=S.useRef(null),[o,i]=S.useState({left:!1,right:!1});S.useLayoutEffect(()=>{const a=n.current,c=()=>{const l=a.scrollLeft>1,d=a.scrollWidth-a.clientWidth-a.scrollLeft>1;i(f=>f.left===l&&f.right===d?f:{left:l,right:d})},u=new ResizeObserver(c);return u.observe(a),a.firstElementChild&&u.observe(a.firstElementChild),a.addEventListener("scroll",c,{passive:!0}),c(),()=>{u.disconnect(),a.removeEventListener("scroll",c)}},[]);const s=`var(--chakra-colors-${t.replace(".","-")})`;return h.jsxs(D.Box,{position:"relative",bg:t,minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:"30px",css:zr(s,`var(--chakra-colors-${r.replace(".","-")})`),children:[h.jsx(D.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(a=>h.jsx(D.Box,{"data-flow-toolbar-fade":a,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",borderRadius:a==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[a]:0,opacity:o[a]?1:0,background:`linear-gradient(to ${a==="left"?"right":"left"}, ${s}, transparent)`}},a))]})}async function d0(e,t){const r=new Set,n=[],o=(a,c)=>{var l,d,f;if(!a||typeof a!="object")return;const u=a;n.push(c),typeof((l=u.$form)==null?void 0:l.$type)=="string"&&r.add(u.$form.$type),typeof((f=(d=u.$form)==null?void 0:d.$create)==null?void 0:f.$type)=="string"&&r.add(u.$form.$create.$type);for(const[p,y]of Object.entries(u))p==="$"?o(y,c):p.startsWith("$")||o(y,`${c}.${p}`)};if(o(t,"root"),!r.size)return{contract:await om(e)};const i=await Fu(e,[...r]);for(const a of r)if(!Object.prototype.hasOwnProperty.call(i,a))throw new Error(`Missing form type: ${a}`);const s={};for(const a of n){const c=xt(t,a,i);c&&(s[a]={type:c.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:s}}}function vm({message:e,onDismiss:t}){const{background:r,colorText:n,border:o}=Je();return!e||typeof document>"u"?null:Wt.createPortal(h.jsxs(D.chakra.div,{role:"alert","aria-atomic":"true",css:zr(he(r),he(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:he(r),color:he(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(vt,{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 xm({showDivider:e=!0,compact:t=!1}={}){const{edgeMode:r,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:s,readOnly:a,themeColor:c}=Ie(),{edgeById:u}=Ur(),{data:l,schema:d,setSchema:f,bindings:p,structured:y}=S.useContext(Rr),g=(y==null?void 0:y.sourceBindings)??p,b=(y==null?void 0:y.sourceSchema)??d,{colorText:x}=Je(),m=S.useRef(null),w=S.useRef(0),[v,C]=S.useState(!1),[_,R]=S.useState("");S.useEffect(()=>()=>{w.current++},[]),S.useEffect(()=>{w.current++,C(!1)},[a,l,g]);const T=o?[...u.values()].filter(k=>Lu(o,k.data)).length:0,A=o?`${o.name}: ${b?`${Object.keys(b).length} form types loaded; `:""}${T} invalid or unverified connections`:"";return h.jsxs(h.Fragment,{children:[h.jsx(vm,{message:_,onDismiss:()=>R("")}),e&&h.jsx($t,{}),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:a,onValueChange:k=>{var E;const j=k==="auto"?"auto":k==="properties"?"properties":"nodes";n(j),(E=s.onEdgeModeChange)==null||E.call(s,j)},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(Re,{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:he(c),size:"sm",variant:"ghost",disabled:v||a,onClick:()=>{var k;return(k=m.current)==null?void 0:k.click()}})}),h.jsx("input",{ref:m,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:a||v,onChange:async k=>{var M,I;const j=(M=k.target.files)==null?void 0:M[0];if(k.target.value="",!j)return;const E=++w.current;C(!0),R("");try{const N=g?await Fu(j,[...new Set(Object.values(g).map(G=>G.schemaType??G.type))]):void 0;if(g&&N){for(const G of Object.values(g))if(!Object.prototype.hasOwnProperty.call(N,G.schemaType??G.type))throw new Error(`Missing form type: ${G.schemaType??G.type}`)}const{contract:O,schema:W}=g&&N?{schema:N,contract:{name:j.name,nodes:Object.fromEntries(Object.entries(g).map(([G,ee])=>[G,{type:N[ee.schemaType??ee.type],optional:!1}]))}}:await d0(j,l);if(E!==w.current)return;f==null||f(W),i(O),(I=s.onWorkflowContractChange)==null||I.call(s,O)}catch(N){E===w.current&&R(`${j.name}: ${N instanceof Error?N.message:"Unable to load interface."}`)}finally{E===w.current&&C(!1)}}}),!t&&(A||v)&&h.jsx("span",{role:"status",title:A,style:{color:he(x),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v?"Loading interface...":A}),!t&&o&&h.jsx(Re,{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:a||v,onClick:()=>{var k;f==null||f(void 0),i(void 0),(k=s.onWorkflowContractChange)==null||k.call(s,void 0),R("")}})})]})]})}const f0=[{value:"BT",label:"Bottom to Up",icon:Z.PiArrowUp,flowType:Pt.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:Z.PiArrowDown,flowType:Pt.TOP_DOWN},{value:"LR",label:"Left to Right",icon:Z.PiArrowRight,flowType:Pt.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:Z.PiArrowLeft,flowType:Pt.RIGHT_LEFT}],wm=()=>{const{engineRef:e,themeColor:t,setThemeColor:r,edgeColor:n,setEdgeColor:o,backgroundSelected:i,setBackgroundSelected:s,direction:a,edgeMode:c,allNodesIconLabel:u,setAllNodesIconLabel:l,selectedNodeIds:d,setSelectedNodeIds:f,selectedEdgeId:p,setSelectedEdgeId:y,isZoomMode:g,setIsZoomMode:b,isMultiSelectMode:x,setIsMultiSelectMode:m,isDragMode:w,setIsDragMode:v,isEdgeHandlesEnabled:C,setIsEdgeHandlesEnabled:_,isArrayNodeMode:R,setIsArrayNodeMode:T,isPinned:A,setIsPinned:k,callbacks:j,config:E,readOnly:M}=Ie(),{nodeById:I,edgeById:N,parentIds:O}=Ur(),W=E.colorMode==="dark",{background:G,border:ee,colorInactive:ne,colorText:ce,colorActive:me}=Je(),K=`var(--chakra-colors-${G.replace(".","-")})`,q=`var(--chakra-colors-${(W?ee:"gray.300").replace(".","-")})`,[L,z]=S.useState(!1),[H,X]=S.useState(!0),le=S.useRef(null),J=my({edge:"bottom",enabled:!A,bounds:le,inside:[le]}),V=S.useCallback(be=>{const Pe=e.current;if(!Pe)return;const We=E.minZoom??.01,pr=E.maxZoom??1.5,er=.02;let Qe=Pe.zoom();switch(be){case"increase":Qe=Math.min(pr,Qe+er),Pe.zoom(Qe),Pe.center();break;case"decrease":Qe=Math.max(We,Qe-er),Pe.zoom(Qe),Pe.center();break;case"reset":Pe.fit(50);break}},[e,E.minZoom,E.maxZoom]),Y=E.renderSelectedNodeToolbar,te=d.length>0&&!!Y,de=S.useMemo(()=>te?d.map(be=>{var We;return{...((We=I.get(be))==null?void 0:We.data)??{id:be},isParent:O.has(be)}}):[],[te,d,I,O]),ue=S.useCallback(()=>{var be;f([]),(be=j.onNodeDeselect)==null||be.call(j)},[f,j]),Se=E.renderSelectedEdgeToolbar,ye=!!p&&!!Se,De=S.useMemo(()=>{var be;return!ye||!p?null:((be=N.get(p))==null?void 0:be.data)??{id:p}},[ye,p,N]),Le=S.useCallback(()=>{var be;y(null),(be=j.onEdgeDeselect)==null||be.call(j)},[y,j]),He=E.selectionToolbar!==!1&&!M,ze=He&&!!p&&!Se,Ve=He&&!ze&&d.length>0&&!Y,Fe=ze||Ve,Ye=A||J||L||Fe;S.useEffect(()=>{d.length||p?s(!1):i&&!M&&(k(!0),X(!1))},[i,d.length,p,M,s,k]);const ir=E.renderBottomBar;return ir?h.jsxs(h.Fragment,{children:[te&&h.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Y({selectedNodeIds:d,selectedNodeData:de,onDeselect:ue})}),ye&&De&&h.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Se({edgeId:p,edgeData:De,onDeselect:Le})}),h.jsx(D.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:ir({zoomIn:()=>V("increase"),zoomOut:()=>V("decrease"),resetZoom:()=>V("reset"),direction:a,isZoomMode:g,setIsZoomMode:b,isMultiSelectMode:x,setIsMultiSelectMode:m,isDragMode:w,setIsDragMode:v,isEdgeHandlesEnabled:C,setIsEdgeHandlesEnabled:_,isArrayNodeMode:R,setIsArrayNodeMode:T,selectedNodeIds:d,selectedNodeData:de,selectedEdgeId:p,selectedEdgeData:De,onNodeDeselect:ue,onEdgeDeselect:Le,callbacks:j})})]}):h.jsxs(h.Fragment,{children:[te&&h.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Y({selectedNodeIds:d,selectedNodeData:de,onDeselect:ue})}),ye&&De&&h.jsx(D.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Se({edgeId:p,edgeData:De,onDeselect:Le})}),h.jsx(D.Box,{ref:le,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:Ye?"translateY(0)":"translateY(100%)",pointerEvents:Ye?"auto":"none",visibility:Ye?"visible":"hidden",opacity:Ye?1:0,css:{"@media (hover: none)":{visibility:"visible",opacity:1,transform:"none",pointerEvents:"auto"}},children:h.jsxs(D.Flex,{w:"100%",px:5,position:"absolute",bottom:"calc(20px + env(safe-area-inset-bottom, 0px))",flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:"24px",children:[h.jsx(bm,{background:G,border:W?ee:"gray.300",children:h.jsxs(D.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[ze?h.jsx(fm,{edgeId:p,onClose:Le}):Ve?h.jsx(pm,{ids:d,onClose:ue}):null,h.jsxs("div",{style:{display:ze||Ve?"none":"contents"},children:[h.jsx(Re,{label:A?"Unpin":"Pin",children:h.jsx(ve,{"aria-label":"Pin",icon:h.jsx(D.Icon,{as:A?Z.PiPushPinFill:Z.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:A?t:ne,onClick:()=>{k(!A),z(!1)}})}),h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee}),h.jsx(Re,{label:"Zoom Out",children:h.jsx(ve,{"aria-label":"Zoom out",icon:h.jsx(D.Icon,{as:Z.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:ce,onClick:()=>V("decrease")})}),h.jsx(Re,{label:"Zoom In",children:h.jsx(ve,{"aria-label":"Zoom in",icon:h.jsx(D.Icon,{as:Z.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:ce,onClick:()=>V("increase")})}),h.jsx(Re,{label:"Reset Zoom",children:h.jsx(ve,{"aria-label":"Reset zoom",icon:h.jsx(D.Icon,{as:Z.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:ce,onClick:()=>V("reset")})}),!H&&h.jsxs(h.Fragment,{children:[h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee}),h.jsx(Re,{label:g?"Zoom Mode (z)":"Pan Mode (z)",children:h.jsx(ve,{"aria-label":"Toggle zoom mode",icon:h.jsx(D.Icon,{as:g?Z.PiMagnifyingGlassPlus:Z.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:g?t:ne,onClick:()=>b(!g)})}),h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee}),h.jsx(Re,{label:x?"Multi-Select On (m)":"Multi-Select Off (m)",children:h.jsx(ve,{"aria-label":"Toggle multi-select",icon:h.jsx(D.Icon,{as:Z.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:x?t:ne,onClick:()=>m(!x)})}),h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee}),h.jsx(Re,{label:w?"Drag Mode On (d)":"Drag Mode Off (d)",children:h.jsx(ve,{"aria-label":"Toggle drag mode",icon:h.jsx(D.Icon,{as:Z.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:w?t:ne,onClick:()=>v(!w)})}),E.edgeHandles!==!1&&h.jsxs(h.Fragment,{children:[h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee}),h.jsx(Re,{label:C?"Draw Mode On":"Draw Mode Off",children:h.jsx(ve,{"aria-label":"Toggle draw mode",icon:h.jsx(D.Icon,{as:Z.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:C?t:ne,onClick:()=>_(!C)})})]}),E.bottomBarExtra&&h.jsxs(h.Fragment,{children:[h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee,role:"separator","aria-orientation":"vertical"}),E.bottomBarExtra]}),h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee,role:"separator","aria-orientation":"vertical"}),h.jsx(Gy,{}),h.jsx(Au,{label:"Collapse all",checked:u,icon:h.jsx(D.Icon,{as:Z.PiArrowsInLineVertical,boxSize:5}),onChange:l}),c!=="properties"&&h.jsxs(h.Fragment,{children:[h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee}),h.jsx(Re,{label:R?"Array Mode [ ]":"Set Mode { }",children:h.jsx(ve,{"aria-label":"Toggle array mode",icon:h.jsx(D.Icon,{as:R?Z.PiBracketsSquare:Z.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:R?t:ne,onClick:()=>{var Pe;const be=!R;T(be),(Pe=j.onArrayModeChange)==null||Pe.call(j,be)}})})]}),i&&!M&&h.jsxs(h.Fragment,{children:[h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee}),h.jsx(mt,{label:"Graph theme",colors:mn,value:t,includeTransparent:!1,onPick:be=>{var Pe;r(be),(Pe=j.onThemeColorChange)==null||Pe.call(j,be)}})]}),h.jsx(xm,{}),!M&&h.jsx(mt,{label:"Graph edge color",colors:mn,value:n||"gray.500",onPick:o,onReset:()=>o("")}),h.jsx(Hy,{})]}),h.jsx(D.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:ee}),h.jsx(Re,{label:H?"Expand toolbar":"Collapse toolbar",children:h.jsx(ve,{"aria-label":"Toggle toolbar collapse",icon:h.jsx(D.Icon,{as:H?Z.PiCaretRight:Z.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:ne,onClick:()=>X(!H)})}),!H&&h.jsx(mm,{})]})]})}),!Fe&&h.jsxs(D.Box,{position:"relative",ml:"auto",flexShrink:0,children:[h.jsx(D.Box,{"data-flow-direction-control":"",bg:G,borderRadius:"30px",h:50,css:zr(K,q),px:3,cursor:"pointer",onClick:()=>z(!L),children:h.jsxs(D.Flex,{align:"center",h:"100%",children:[h.jsx(Re,{label:"Flow Direction",children:h.jsx(ve,{"aria-label":"Direction",icon:h.jsx(D.Icon,{as:Z.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:ne})}),h.jsx(D.Text,{fontSize:"xs",color:W?"whiteAlpha.600":"blackAlpha.500",ml:1,children:a})]})}),L&&h.jsx(D.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:h.jsxs(D.Box,{bg:G,borderRadius:"30px",p:2,minW:"180px",css:zr(K,q),children:[f0.map(be=>h.jsxs(D.Flex,{align:"center",gap:3,px:3,py:2,css:Cu,cursor:"pointer",_hover:{bg:W?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Pe;(Pe=j.onDirectionChange)==null||Pe.call(j,be.value),z(!1)},children:[h.jsx(D.Icon,{as:be.icon,boxSize:5,color:ce}),h.jsx(D.Text,{fontSize:"sm",color:ce,flex:1,whiteSpace:"nowrap",children:be.label}),a===be.value&&h.jsx(D.Icon,{as:Z.PiCheck,boxSize:4,color:me})]},be.value)),h.jsxs(D.Flex,{align:"center",gap:3,px:3,py:2,css:Cu,cursor:"pointer",_hover:{bg:W?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var be;(be=j.onDirectionChange)==null||be.call(j,"C"),z(!1)},children:[h.jsx(D.Icon,{as:Z.PiAlignCenterHorizontal,boxSize:5,color:ce}),h.jsx(D.Text,{fontSize:"sm",color:ce,flex:1,whiteSpace:"nowrap",children:"Center"}),a==="C"&&h.jsx(D.Icon,{as:Z.PiCheck,boxSize:4,color:me})]})]})})]})]})})]})};wm.displayName="BottomBar";const Cm=S.memo(wm);function h0({checked:e,onChange:t,disabled:r,label:n="Connected nodes"}){return h.jsx(Au,{label:n,checked:e,onChange:t,disabled:r,icon:h.jsx(D.Icon,{as:Z.PiGraph,boxSize:5})})}const Ol={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function _m(e,t){const r=new Map,n=(i,s)=>{if(Object.is(i,s))return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const a=Object.keys(i);return a.length===Object.keys(s).length&&a.every(c=>Object.prototype.hasOwnProperty.call(s,c)&&n(i[c],s[c]))},o=(i,s,a)=>{if(i===s)return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const c=new Set([...Object.keys(i),...Object.keys(s)]);for(const u of c)if(!n(i[u],s[u])){if(Object.prototype.hasOwnProperty.call(Ol,u)){if(typeof s[u]!="string"||!s[u])return!1;r.set(a,{...r.get(a),[Ol[u]]:s[u]})}else if(u.startsWith("$")&&u!=="$"||!o(i[u],s[u],u==="$"?a:`${a}.${u}`))return!1}return!0};if(o(e,t,"root"))return r}function p0(e,t){return _m(e,t)!==void 0}function g0(e,t,r){if(e===t)return r;const n=_m(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)||!we(t,i))return;return{edges:r.edges,nodes:r.nodes.map(i=>{const s=n.get(i.data.id),a=we(e,i.data.id),c=we(t,i.data.id);return!s&&a===c?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(c,null,2)}:{},...s?{viewProps:{...i.data.viewProps,...s},config:{...i.data.config,...s}}:{}}}})}}function Su(e){return e.kind==="literal"?e.value:e.kind==="union"?Su(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,t])=>!t.optional).map(([t,r])=>[t,Su(r.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Sm(e,t,r){var b,x,m;const n=(b=we(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 s=i.pop(),a=["root",...i].join("."),c=xt(e,a,r),u=(x=c==null?void 0:c.type.properties[s])==null?void 0:x.type;if((u==null?void 0:u.kind)!=="array"||u.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)||jr(l.properties[w].type,v,!l.properties[w].optional))throw new Error(`Invalid creation default: ${w}`);const f={...Su(l),...structuredClone(d)};((m=l.properties.id)==null?void 0:m.type.kind)==="string"&&(f.id=Tu());let p=e;const y=we(e,o.$address);if(y===void 0)p=mr(e,a,w=>({...w,[s]:[]}));else if(!Array.isArray(y)&&!Array.isArray(y==null?void 0:y.$))throw new Error("Form creation destination is not an array.");const g=Mu(p,o.$address,{...f,$label:o.$label??o.$type,...o.$icon?{$icon:o.$icon}:{},$form:{$type:o.$type,$create:o}});return{address:g.address,json:qu(g.json,t,{target:g.address,label:o.$edgeLabel})}}function y0(e,t){const r=o=>e&&typeof e=="object"&&o in e;let n=1;for(;r(`${t}_${n}`);)n++;return`${t}_${n}`}function Em(e,t,r,n,o){const i=(a,c)=>{a!==e&&(e=a,n==null||n(a,c))},s=a=>{var u;const c=(u=t.find(l=>l.data.id===a))==null?void 0:u.data;return c&&{source:c.source,target:c.target,isInverted:c.isInverted,sourceProperty:c.sourceProperty,targetProperty:c.targetProperty,connection:c.connection}};return{...r,onFormChange:a=>{const c=we(e,a.nodeAddress);if(!c||a.nodeId!==void 0&&c.id!==a.nodeId)throw new Error("This form node has moved. Retry the edit.");i(En(e,a,r.onFormChange),{type:"form",address:a.address,value:a.value})},onNodeLabelChange:(a,c)=>{var u;(u=r.onNodeLabelChange)==null||u.call(r,a,c),i(sr(e,a,"$label",c),{type:"nodeLabel",address:a,key:"$label",value:c})},onNodeContentChange:(a,c)=>{var u;(u=r.onNodeContentChange)==null||u.call(r,a,c),i(sr(e,a,"$content",c),{type:"nodeContent",address:a,key:"$content",value:c})},onNodeTypeViewChange:(a,c)=>{var u;c!==void 0&&!Gt.includes(c)||((u=r.onNodeTypeViewChange)==null||u.call(r,a,c),i(sr(e,a,"$view",c),{type:"nodeStyle",address:a,key:"$view",value:c}))},onNodeColorChange:(a,c,u)=>{var d;(d=r.onNodeColorChange)==null||d.call(r,a,c,u);const l=c==="bg"?"$bgColor":"$textColor";i(sr(e,a,l,u),{type:"nodeColor",address:a,key:l,value:u})},onNodeBorderColorChange:(a,c)=>{var u;(u=r.onNodeBorderColorChange)==null||u.call(r,a,c),i(sr(e,a,"$borderColor",c),{type:"nodeColor",address:a,key:"$borderColor",value:c})},onNodeBorderStyleChange:(a,c)=>{var u;(u=r.onNodeBorderStyleChange)==null||u.call(r,a,c),i(sr(e,a,"$borderStyle",c),{type:"nodeStyle",address:a,key:"$borderStyle",value:c})},onNodeBorderWidthChange:(a,c)=>{var u;c!==void 0&&(!Number.isFinite(c)||c<0)||((u=r.onNodeBorderWidthChange)==null||u.call(r,a,c),i(sr(e,a,"$borderWidth",c),{type:"nodeStyle",address:a,key:"$borderWidth",value:c}))},onNodeBorderRadiusChange:(a,c)=>{var u;c!==void 0&&(!Number.isFinite(c)||c<0)||((u=r.onNodeBorderRadiusChange)==null||u.call(r,a,c),i(sr(e,a,"$borderRadius",c),{type:"nodeStyle",address:a,key:"$borderRadius",value:c}))},onNodeIconChange:(a,c)=>{var u;(u=r.onNodeIconChange)==null||u.call(r,a,c),i(sr(e,a,"$icon",c),{type:"nodeIcon",address:a,key:"$icon",value:c})},onNodeOutlineChange:(a,c)=>{var u;(u=r.onNodeOutlineChange)==null||u.call(r,a,c),i(sr(e,a,"$outline",c),{type:"nodeOutline",address:a,key:"$outline",value:c})},onNodeAnimationChange:(a,c)=>{var u;(u=r.onNodeAnimationChange)==null||u.call(r,a,c),i(sr(e,a,"$isNodeAnimated",c),{type:"nodeAnimation",address:a,key:"$isNodeAnimated",value:c})},onNodeAnimationVariantChange:(a,c)=>{var u;c!=="traveling"&&c!=="pulse"||((u=r.onNodeAnimationVariantChange)==null||u.call(r,a,c),i(sr(e,a,"$nodeAnimationVariant",c),{type:"nodeAnimation",address:a,key:"$nodeAnimationVariant",value:c}))},onNodeCollapse:(a,c)=>{var u;(u=r.onNodeCollapse)==null||u.call(r,a,c),i(Xy(e,a,c),{type:"nodeCollapse",address:a,key:"$collapsed",value:c})},onNodeCreate:a=>{var p,y;const c=a.sourceNodeId&&Sm(e,a.sourceNodeId,o);if(c){(p=r.onNodeCreate)==null||p.call(r,a),i(c.json,{type:"nodeCreate",address:c.address,value:"form"});return}(y=r.onNodeCreate)==null||y.call(r,a);const u=a.sourceNodeId||"root",l=we(e,u),d=y0(l,a.isArrayMode?"list":"node"),f=Mu(e,u,a.isArrayMode?[]:{},d);i(f.json,{type:"nodeCreate",address:f.address,value:a.isArrayMode?"array":"set"})},onNodeDelete:(a,c)=>{var u;(u=r.onNodeDelete)==null||u.call(r,a,c),i(em(e,a),{type:"nodeDelete",address:a})},onEdgeCreate:(a,c,u)=>{var d;(d=r.onEdgeCreate)==null||d.call(r,a,c,u);const l=u&&(u.sourceProperty!==void 0||u.targetProperty!==void 0)?{...u,target:c}:void 0;i(l?qu(e,a,l):rm(e,a,c),{type:"edgeCreate",address:a,key:l?"$connections":"$target",value:l??c})},onEdgeLabelChange:(a,c)=>{var l;(l=r.onEdgeLabelChange)==null||l.call(r,a,c);const u=s(a);u&&i(Br(e,u,"$sourceLabel",c),{type:"edgeLabel",edge:u,key:u.connection?"$connections":"$sourceLabel",value:c})},onEdgeStyleChange:(a,c)=>{var l;(l=r.onEdgeStyleChange)==null||l.call(r,a,c);const u=s(a);u&&i(Qy(e,u,c),{type:"edgeStyle",edge:u,value:c})},onEdgeAnimationVariantChange:(a,c)=>{var l;if(c!=="dashed"&&c!=="traveling")return;(l=r.onEdgeAnimationVariantChange)==null||l.call(r,a,c);const u=s(a);u&&i(Br(e,u,"$edgeAnimationVariant",c),{type:"edgeStyle",edge:u,key:u.connection?"$connections":"$edgeAnimationVariant",value:c})},onEdgeTypeChange:(a,c)=>{var l;(l=r.onEdgeTypeChange)==null||l.call(r,a,c);const u=s(a);u&&i(Br(e,u,"$edgeType",c),{type:"edgeStyle",edge:u,key:u.connection?"$connections":"$edgeType",value:c})},onEdgeIconChange:(a,c)=>{var l;(l=r.onEdgeIconChange)==null||l.call(r,a,c);const u=s(a);u&&i(Br(e,u,"$edgeIcon",c||void 0),{type:"edgeStyle",edge:u,key:u.connection?"$connections":"$edgeIcon",value:c})},onEdgeColorChange:(a,c)=>{var l;(l=r.onEdgeColorChange)==null||l.call(r,a,c);const u=s(a);u&&i(Br(e,u,"$edgeColor",c),{type:"edgeColor",edge:u,key:u.connection?"$connections":"$edgeColor",value:c})},onEdgeDelete:(a,c)=>{var d;(d=r.onEdgeDelete)==null||d.call(r,a,c);const u=s(a);if(!u)return;const l=tm(e,u);l.removed&&i(l.json,{type:"edgeDelete",edge:u,key:u.connection?"$connections":"$target"})}}}const m0=".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 b0({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 v0=".flow-sdk-edge-reveal{animation:flow-sdk-edge-reveal var(--flow-edge-reveal-duration,600ms) linear both;animation-play-state:var(--flow-edge-reveal-state,running)}.flow-sdk-edge-reveal-end{animation:flow-sdk-edge-reveal-end var(--flow-edge-reveal-duration,600ms) steps(1,end) both;animation-play-state:var(--flow-edge-reveal-state,running)}@keyframes flow-sdk-edge-reveal{from{stroke-dashoffset:var(--flow-edge-reveal-from,100)}to{stroke-dashoffset:0}}@keyframes flow-sdk-edge-reveal-end{from{opacity:0}to{opacity:1}}@media(prefers-reduced-motion:reduce){.flow-sdk-edge-reveal{animation:none;stroke-dashoffset:0}.flow-sdk-edge-reveal-end{animation:none;opacity:1}}";function x0({path:e,width:t,reversed:r,children:n,onComplete:o}){const i=`flow-edge-reveal-${S.useId().replace(/:/g,"")}`,s=S.useRef(null),[a,c]=S.useState({x:0,y:0,width:1,height:1});return S.useEffect(()=>{const u=matchMedia("(prefers-reduced-motion: reduce)"),l=()=>{u.matches&&(o==null||o())};return l(),u.addEventListener("change",l),()=>u.removeEventListener("change",l)},[o]),S.useLayoutEffect(()=>{var l;const u=(l=s.current)==null?void 0:l.getBBox();u&&c({x:u.x-t,y:u.y-t,width:u.width+t*2,height:u.height+t*2})},[e,t]),h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsx("mask",{id:i,maskUnits:"userSpaceOnUse",...a,children:h.jsx("path",{ref:s,className:"flow-sdk-edge-reveal",onAnimationEnd:u=>{u.animationName==="flow-sdk-edge-reveal"&&(o==null||o())},"data-reveal-direction":r?"reverse":"forward",style:{"--flow-edge-reveal-from":r?-100:100},d:e,fill:"none",stroke:"white",strokeWidth:t,strokeLinecap:"butt",strokeLinejoin:"round",pathLength:100,strokeDasharray:"100 100"})})}),h.jsx("g",{mask:`url(#${i})`,children:n})]})}const w0=".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 jm({x:e=0,y:t=0,width:r,height:n,radius:o,color:i,strokeWidth:s=8,path:a,variant:c="traveling"}){const u=S.useId(),l=`flow-sdk-node-border-animation${c==="pulse"?" flow-sdk-node-border-pulse":""}`;if(c==="pulse"){const d=a?"path":"rect",f=a?{d:a}:{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=s+36,y={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:u,maskUnits:"userSpaceOnUse",...y,style:{maskType:"luminance"},children:[h.jsx("rect",{...y,fill:"white"}),h.jsx(d,{...f,fill:"black",stroke:"black",strokeWidth:s,strokeLinejoin:"round"})]})}),h.jsx(d,{...f,className:l,"data-animation-variant":c,fill:"none",stroke:`color-mix(in srgb, ${i} 60%, transparent)`,strokeLinejoin:"round",mask:`url(#${u})`,style:{"--flow-pulse-rest-width":`${s+16}px`,"--flow-pulse-expanded-width":`${s+36}px`}})]})}return a?h.jsx("path",{className:l,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",d:a,fill:"none",stroke:i,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"}):h.jsx("rect",{className:l,"data-animation-variant":c,"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:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const C0=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 Il(e,t,r){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const s of t)(s.parent===i||s.id.startsWith(`${i}.`)||r.some(c=>(c.inverted?c.target:c.source)===i&&(c.inverted?c.source:c.target)===s.id))&&!n.has(s.id)&&(n.add(s.id),o.push(s.id))}return n}function _0(e,t,r){const n=r==="downward"||r==="upward",o=new Map;for(const s of e){if(s.source===s.target||s.sourceProperty||s.targetProperty)continue;const a=t(s.source),c=t(s.target);if(!a||!c)continue;const u=n?c.y-a.y:c.x-a.x,l=Math.abs(u)-(n?a.h+c.h:a.w+c.w)/2;if(l<=320)continue;const d=JSON.stringify([s.source,Math.sign(u)]),f=o.get(d)??[];f.push({edge:s,gap:l,cross:n?c.x-a.x:c.y-a.y}),o.set(d,f)}const i=new Map;for(const s of o.values()){if(new Set(s.map(({edge:c})=>c.target)).size<2)continue;const a=new Map;for(const{edge:c}of s)a.set(c.target,(a.get(c.target)??0)+1);for(const c of[-1,0,1]){const u=s.filter(({cross:d})=>Math.sign(d)===c);u.sort((d,f)=>Math.abs(f.cross)-Math.abs(d.cross)||d.edge.id.localeCompare(f.edge.id));const l=Math.min(...u.map(({gap:d})=>d));u.forEach(({edge:d,gap:f,cross:p},y)=>{const g=u.length===1?l/2:120+(l-280)*y/(u.length-1),b=u.find(x=>Math.abs(x.cross)<Math.abs(p));i.set(d.id,{turn:g/f,labelAtTarget:a.get(d.target)===1,labelFraction:p?(p+((b==null?void 0:b.cross)??0))/(2*p):.5})})}}return i}const dt=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}),S0=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function eo(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 E0=(e,t)=>e.x1<=t.x2&&e.x2>=t.x1&&e.y1<=t.y2&&e.y2>=t.y1,Ml=(e,t)=>e.x>=t.x1&&e.x<=t.x2&&e.y>=t.y1&&e.y<=t.y2,fr=e=>(Math.round(e*10)/10).toString(),Ze=e=>`${fr(e.x)} ${fr(e.y)}`,j0=e=>e>0?1:e<0?-1:0,ql=(e,t)=>e>0?Math.max(e-t,0):Math.min(e+t,0);function R0(e,t,r,n,o=10){const i=t.x-e.x,s=t.y-e.y,a=ql(i,(e.w+t.w)/2),c=ql(s,(e.h+t.h)/2),u=r==="downward"||r==="upward",l=u?c:a,d=u?s:i,f=j0(d),p=n*l,y=m=>Math.abs(m)<o||Math.abs(m)>=Math.abs(l),g=y(p)||y(Math.abs(l)-Math.abs(p));let b;if(g)if(u)if(Math.abs(d)<=e.h/2){const m=(e.x+t.x)/2;b=[m,e.y,m,t.y]}else if(Math.abs(i)<=t.w/2){const m=(e.y+t.y)/2;b=[e.x,m,t.x,m]}else b=[e.x,t.y];else if(Math.abs(d)<=e.w/2){const m=(e.y+t.y)/2;b=[e.x,m,t.x,m]}else if(Math.abs(s)<=t.h/2){const m=(e.x+t.x)/2;b=[m,e.y,m,t.y]}else b=[t.x,e.y];else if(u){const m=e.y+p+e.h/2*f;b=[e.x,m,t.x,m]}else{const m=e.x+p+e.w/2*f;b=[m,e.y,m,t.y]}const x=[{x:e.x,y:e.y}];for(let m=0;m<b.length;m+=2)x.push({x:b[m],y:b[m+1]});return x.push({x:t.x,y:t.y}),x}function k0(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,s=o>0?(r.y2-e.y)/o:o<0?(r.y1-e.y)/o:1/0,a=Math.min(i,s);return!Number.isFinite(a)||a>=1||a<0?null:{x:e.x+n*a,y:e.y+o*a}}function bt(e,t,r){var s;if(!((s=r.outline)!=null&&s.length))return k0(e,t,dt(r));const n=t.x-e.x,o=t.y-e.y;let i=1/0;return r.outline.forEach((a,c,u)=>{const l=u[(c+1)%u.length],d=l.x-a.x,f=l.y-a.y,p=n*f-o*d;if(Math.abs(p)<1e-9)return;const y=a.x-e.x,g=a.y-e.y,b=(y*f-g*d)/p,x=(y*o-g*n)/p;b>=0&&b<1&&x>=-1e-9&&x<=1+1e-9&&(i=Math.min(i,b))}),Number.isFinite(i)?{x:e.x+n*i,y:e.y+o*i}:null}function Rm(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,s={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},a=Math.max(e.w,e.h)*2+1;return{...bt(s,{x:s.x+(o?0:i*a),y:s.y+(o?i*a:0)},e)??{x:o?s.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:s.y},side:t}}function pt(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 P0(e,t,r,n){const o=pt(e,r.srcDist),i=pt(t,r.tgtDist);if(n==="straight")return Pm(o,i,r);const s=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),a=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,c=a!==void 0&&a>0?Math.min(s,a/2):s,u=pt({...o,side:e.side},c),l=pt({...i,side:t.side},c),d=r.arrowAt==="source"?tr(o,u,r.arrowGap):o,f=r.arrowAt==="target"?tr(i,l,r.arrowGap):i,p=r.arrowAt==="source"?br(o,u,r.arrowSize,r.headShape):r.arrowAt==="target"?br(i,l,r.arrowSize,r.headShape):void 0;if(n==="bezier")return{d:`M${Ze(d)} C${Ze(u)} ${Ze(l)} ${Ze(f)}`,arrow:p,label:{x:(d.x+3*u.x+3*l.x+f.x)/8,y:(d.y+3*u.y+3*l.y+f.y)/8,angle:0}};const y=e.side==="left"||e.side==="right",g=t.side==="left"||t.side==="right";let b;if(y!==g){const m=y?{x:l.x,y:u.y}:{x:u.x,y:l.y},w=(m.x-u.x)*(u.x-o.x)+(m.y-u.y)*(u.y-o.y)>=0,v=(m.x-l.x)*(l.x-i.x)+(m.y-l.y)*(l.y-i.y)>=0;b=[w&&v?m:y?{x:u.x,y:l.y}:{x:l.x,y:u.y}]}else if(a!==void 0&&a<=0)if(y){const m=(u.y+l.y)/2;b=[{x:u.x,y:m},{x:l.x,y:m}]}else{const m=(u.x+l.x)/2;b=[{x:m,y:u.y},{x:m,y:l.y}]}else if(y){const m=e.side===t.side?e.side==="right"?Math.max(u.x,l.x):Math.min(u.x,l.x):(u.x+l.x)/2;b=[{x:m,y:u.y},{x:m,y:l.y}]}else{const m=e.side===t.side?e.side==="bottom"?Math.max(u.y,l.y):Math.min(u.y,l.y):(u.y+l.y)/2;b=[{x:u.x,y:m},{x:l.x,y:m}]}const x=[u,...b,l].filter((m,w,v)=>w===0||m.x!==v[w-1].x||m.y!==v[w-1].y);return jn(d,x,f,p,n==="orthogonal"?0:r.radius)}function tr(e,t,r){const n=e.x-t.x,o=e.y-t.y,i=Math.hypot(n,o);if(!i)return e;let s=(i-r)/i;return s<0&&(s=1e-5),{x:t.x+s*n,y:t.y+s*o}}function br(e,t,r,n="triangle"){const o=e.x-t.x,i=e.y-t.y,s=Math.hypot(o,i)||1,a=o/s,c=i/s,u=(n==="square"?.15:.3)*r,l=.15*r,d=e.x-a*u,f=e.y-c*u;return n==="square"?`M${Ze(e)} L${fr(e.x-c*l)} ${fr(e.y+a*l)} L${fr(d-c*l)} ${fr(f+a*l)} L${fr(d+c*l)} ${fr(f-a*l)} L${fr(e.x+c*l)} ${fr(e.y-a*l)} Z`:`M${Ze(e)} L${fr(d-c*l)} ${fr(f+a*l)} L${fr(d+c*l)} ${fr(f-a*l)} Z`}function Fr(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 A0(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},s=Math.hypot(o.x,o.y),a=Math.hypot(i.x,i.y),c=o.x*i.y-o.y*i.x;if(s<1e-6||a<1e-6||Math.abs(c)<1e-6)return{p1:t,b:t,p2:t,r:0};const u=Math.min(n,s/2,a/2);return{p1:{x:t.x-o.x/s*u,y:t.y-o.y/s*u},b:t,p2:{x:t.x+i.x/a*u,y:t.y+i.y/a*u},r:u}}function km(e,t,r,n){let o=-1,i=null;for(let y=0;y<e.length-1;y++){const g=bt(e[y],e[y+1],t);if(g){o=y,i=g;break}}let s=-1,a=null;for(let y=e.length-1;y>0;y--){const g=bt(e[y],e[y-1],r);if(g){s=y,a=g;break}}if(!i||!a||o>=s)return null;const c=e.slice(o+1,s),u=c[0]??a,l=c[c.length-1]??i;let d,f,p;if(n.arrowAt==="source"){const y=tr(i,u,n.srcDist);d=tr(i,u,n.srcDist+n.arrowGap),p=br(y,u,n.arrowSize,n.headShape)}else d=tr(i,u,n.srcDist);if(n.arrowAt==="target"){const y=tr(a,l,n.tgtDist);f=tr(a,l,n.tgtDist+n.arrowGap),p=br(y,l,n.arrowSize,n.headShape)}else f=tr(a,l,n.tgtDist);return jn(d,c,f,p,n.radius,n.labelTargetLength,n.labelFraction)}function jn(e,t,r,n,o,i,s){var f;const a=[e,...t,r],c=[];let u=`M${Ze(e)}`;for(let p=1;p<a.length-1;p++){const y=A0(a[p-1],a[p],a[p+1],o);c.push(y),y.r===0?u+=` L${Ze(y.b)}`:u+=` L${Ze(y.p1)} Q${Ze(y.b)} ${Ze(y.p2)}`}u+=` L${Ze(r)}`;let l;const d=t.length;if(d===0)l={x:(e.x+r.x)/2,y:(e.y+r.y)/2,angle:Fr(r.x-e.x,r.y-e.y)};else if(d%2===0){const p=t[d/2-1],y=t[d/2];l={x:(p.x+y.x)/2,y:(p.y+y.y)/2,angle:Fr(y.x-p.x,y.y-p.y)}}else{const p=c[(d-1)/2];if(p.r===0){const y=a[(d-1)/2+2];l={x:p.b.x,y:p.b.y,angle:Fr(y.x-p.b.x,y.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:Fr(p.p2.x-p.p1.x,p.p2.y-p.p1.y)}}if(i!==void 0){if(s!==void 0&&c.length===2){const b=c[0].p2,x=c[1].p1,m=Math.hypot(x.x-b.x,x.y-b.y),w=Math.min(.5,i/(2*m)),v=Math.max(w,Math.min(1-w,s));l={x:b.x+(x.x-b.x)*v,y:b.y+(x.y-b.y)*v,angle:Fr(x.x-b.x,x.y-b.y)}}const p=((f=c[c.length-1])==null?void 0:f.p2)??e,y=r.x-p.x,g=r.y-p.y;Math.hypot(y,g)>=i&&(l={x:(p.x+r.x)/2,y:(p.y+r.y)/2,angle:Fr(y,g)})}return{d:u,arrow:n,label:l}}function Nl(e,t,r,n,o,i,s){const a=r==="leftward"?-1:1,c={x:e.x+a*(e.w/2+s.srcDist),y:n??e.y},u={x:t.x-a*(t.w/2+s.tgtDist),y:o??t.y},l=Math.max(80,s.arrowGap+s.arrowSize*.3),d=c.x+a*l,f=u.x-a*l;let p;if(a*(f-d)>=0){const x=c.x+(u.x-c.x)*i,m=Math.max(Math.min(d,f),Math.min(Math.max(d,f),x));p=[{x:m,y:c.y},{x:m,y:u.y}]}else{const x=Math.min(e.y-e.h/2,t.y-t.h/2)-l*(1+i);p=[{x:d,y:c.y},{x:d,y:x},{x:f,y:x},{x:f,y:u.y}]}const y=s.arrowAt==="source"?tr(c,p[0],s.arrowGap):c,g=s.arrowAt==="target"?tr(u,p[p.length-1],s.arrowGap):u,b=s.arrowAt==="source"?br(c,p[0],s.arrowSize,s.headShape):s.arrowAt==="target"?br(u,p[p.length-1],s.arrowSize,s.headShape):void 0;return jn(y,p,g,b,s.radius)}function $l(e,t,r,n,o){return km(R0(e,t,r,n),e,t,o)}function Ll(e,t,r,n,o,i){const s=n===void 0&&o===void 0&&(r==="downward"||r==="upward"),a=r==="leftward"||s&&r==="upward"?-1:1,c=(u,l,d)=>{const f={x:u.x,y:l??u.y},p=Math.max(u.w,u.h)*2+1,y=bt(f,{x:f.x+(s?0:d*p),y:f.y+(s?d*p:0)},u);return y?{x:y.x+(s?0:d*i),y:y.y+(s?d*i:0)}:s?{x:u.x,y:u.y+d*(u.h/2+i)}:{x:u.x+d*(u.w/2+i),y:l??u.y}};return{sourcePoint:c(e,n,a),targetPoint:c(t,o,-a)}}function T0(e,t,r,n){const o=r==="downward"||r==="upward",i=r==="leftward"||r==="upward"?-1:1,s=Math.max(100,Math.abs(o?t.y-e.y:t.x-e.x)/2),a={x:e.x+(o?0:i*s),y:e.y+(o?i*s:0)},c={x:t.x-(o?0:i*s),y:t.y-(o?i*s:0)},u=n.arrowAt==="source"?tr(e,a,n.arrowGap):e,l=n.arrowAt==="target"?tr(t,c,n.arrowGap):t;return{d:`M${Ze(u)} C${Ze(a)} ${Ze(c)} ${Ze(l)}`,arrow:n.arrowAt==="source"?br(e,a,n.arrowSize,n.headShape):n.arrowAt==="target"?br(t,c,n.arrowSize,n.headShape):void 0,label:{x:(u.x+3*a.x+3*c.x+l.x)/8,y:(u.y+3*a.y+3*c.y+l.y)/8,angle:Fr(l.x+c.x-a.x-u.x,l.y+c.y-a.y-u.y)}}}function Pm(e,t,r){const n=r.arrowAt==="source"?tr(e,t,r.arrowGap):e,o=r.arrowAt==="target"?tr(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 jn(n,[],o,i,0)}function O0(e,t,r,n=-90,o=-60,i=350){const s=n*Math.PI/180,a=o*Math.PI/180,c=s-Math.PI/2,u=c-a/2,l=c+a/2,d=1.4*i*(t/3+1),f={x:e.x+Math.cos(u)*d,y:e.y+Math.sin(u)*d},p={x:e.x+Math.cos(l)*d,y:e.y+Math.sin(l)*d},y={x:e.x,y:e.y},g=bt(y,f,e),b=bt(y,p,e);if(!g||!b)return null;const x={x:(f.x+p.x)/2,y:(f.y+p.y)/2};let m=tr(g,f,r.srcDist),w=tr(b,p,r.tgtDist),v;if(r.arrowAt==="target"){const _=w;w=tr(b,p,r.tgtDist+r.arrowGap),v=br(_,p,r.arrowSize,r.headShape)}else if(r.arrowAt==="source"){const _=m;m=tr(g,f,r.srcDist+r.arrowGap),v=br(_,f,r.arrowSize,r.headShape)}return{d:`M${Ze(m)} Q${Ze(f)} ${Ze(x)} Q${Ze(p)} ${Ze(w)}`,arrow:v,label:{x:x.x,y:x.y,angle:Fr(p.x-f.x,p.y-f.y)}}}const ut=e=>Math.round(e*1e3)/1e3;function Am(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,s=typeof i.getScreenCTM=="function"?i.getScreenCTM():null,a=typeof i.getTotalLength=="function"?i.getTotalLength():0,c=i.points,u=(c==null?void 0:c.numberOfItems)||128,l=s&&a>0?Array.from({length:u},(d,f)=>{const p=c!=null&&c.numberOfItems?c.getItem(f):i.getPointAtLength(a*f/u);return{x:ut((s.a*p.x+s.c*p.y+s.e-r.left)/n),y:ut((s.b*p.x+s.d*p.y+s.f-r.top)/n)}}):void 0;return{left:ut((o.left-r.left)/n),top:ut((o.top-r.top)/n),width:t instanceof HTMLElement?t.offsetWidth:ut(o.width/n),height:t instanceof HTMLElement?t.offsetHeight:ut(o.height/n),radius:parseFloat(getComputedStyle(t).borderTopLeftRadius)||0,...l?{outline:l}:{}}}function zt(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 I0(e,t,r,n,o){var l;const i=o!=="TB"&&o!=="BT",s=i?"top":"left",a=i?"bottom":"right",c=new Map;for(const d of n)for(const[f,p,y]of[[d.source,d.sourceProperty,d.target],[d.target,d.targetProperty,d.source]]){const g=t.get(y);if(p===void 0||!g||y===f)continue;const b=r.get(y),x=JSON.stringify([f,p]),m=c.get(x)??[];m.push(b?zt(g,b):g),c.set(x,m)}const u=new Map(e);for(const[d,f]of e){const p=t.get(d);if(!p||!f.some(w=>w.placement==="config"))continue;const y=r.get(d),g=y?zt(p,y):p,b={x:p.w/2,y:p.h/2,w:p.w,h:p.h},x=y?zt(b,y):b,m=new Map;for(const w of f){if(w.placement!=="config")continue;const C=(c.get(JSON.stringify([d,w.property]))??[]).reduce((R,T)=>R+(i?T.y-g.y:T.x-g.x),0),_=((l=w.anchor)==null?void 0:l.side)===a?a:s;m.set(w,C<-.001?s:C>.001?a:_)}u.set(d,f.map(w=>{const v=m.get(w);if(!v)return w;const C=f.filter(T=>m.get(T)===v),_=(C.indexOf(w)+1)/(C.length+1),R=Rm(x,v,_);return{...w,anchor:R,top:R.y,height:0}}))}return u}function Fl(e,t,r){const n=new Set(t.map(a=>a.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const a of t)!o.has(a.id)&&(o.has(a.parent??"")||a.id.startsWith(`${e}.`))&&(o.add(a.id),i=!0)}const s=new Set(o);for(const a of r)o.has(a.source)&&n.has(a.target)&&s.add(a.target),o.has(a.target)&&n.has(a.source)&&s.add(a.source);return s}const nt='"Helvetica Neue", Helvetica, sans-serif';let kt;const un=new Map;function Rn(e,t){const r=`${t}|${e}`,n=un.get(r);if(n!==void 0)return n;kt===void 0&&(kt=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let o;return kt?(kt.font=t,o=kt.measureText(e).width):o=e.length*(parseFloat(t)||16)*.55,un.size>5e3&&un.clear(),un.set(r,o),o}function M0(e,t,r){const n=[];for(const o of String(e).split(`
157
- `)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let s="";for(const a of i){const c=s?`${s} ${a}`:a;!s||Rn(c,t)<=r?s=c:(n.push(s),s=a)}n.push(s)}return n}const q0=e=>e.stopPropagation();function N0({id:e,rect:t,label:r,labelLayer:n,style:o,onSelect:i,onCollapse:s,selected:a=!1}){const c=t.x2-t.x1,u=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+c/2,p=o.labelPosition==="top"?t.y1+o.labelMargin-o.fontSize/2:o.labelPosition==="bottom"?t.y2-o.labelMargin+o.fontSize/2:t.y1+u/2,y=r?Rn(r,`bold ${o.fontSize}px ${nt}`):0,g=o.fontSize/5,b=r||a&&s?h.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[a&&s&&h.jsx("foreignObject",{x:f+y/2+g+8,y:p-24,width:48,height:48,"data-flow-content-toggle":"",style:{pointerEvents:"auto"},children:h.jsx(Re,{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(),s(e)}})})}),r&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:f-y/2-g,y:p-o.fontSize/2-g,width:y+2*g,height:o.fontSize+2*g,fill:o.textColor==="transparent"?"transparent":o.labelBg}),h.jsx("text",{x:f,y:p,fill:o.textColor,fontSize:o.fontSize,fontWeight:"bold",fontFamily:nt,style:{fontSize:o.fontSize,fontWeight:"bold",fontFamily:nt},textAnchor:"middle",dominantBaseline:"central",children:r})]})]}):null;return h.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:q0,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:c,height:u,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,c-l*4/3),height:Math.max(0,u-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(jm,{variant:o.animationVariant,x:t.x1,y:t.y1,width:c,height:u,radius:o.borderRadius,color:o.animationColor||o.borderColor,strokeWidth:Math.max(8,l*1.6)}),n&&b?Wt.createPortal(b,n):b]})}const $0=S.memo(N0),bn=45,Tm=70,Xr=15,Om=50;function Im(e,t,r=bn){const n=`${r}px ${nt}`,o=e?M0(e,n,200*r/bn):[],i=t?48+(o.length?12:0):0,s=i+Math.max(0,...o.map(u=>Rn(u,n))),a=Math.max(o.length*r,t?48:0),c=o.length||t?2*Xr:0;return{lines:o,iconWidth:i,contentWidth:s,contentHeight:a,width:s+c,height:a+c}}const Vt=6,Mm=3,Du=Math.max(Math.pow(Vt*13.37,.9),29)*Mm,qm=Vt*Mm*2,dn=80,L0=2*dn+Du*.3+100,F0=36+2*Math.max(80,qm+Du*.3);function Eu(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function ju(e,t){return t==="auto"||(t==="properties"?Eu(e):!Eu(e))}function ft(e,t,r){return r!=="properties"||e!=="root"||t.some(n=>(n.source===e||n.target===e)&&Eu(n))}function B0(e,t,r,n=!1,o){if(!n)return{nodes:e,edges:t};const i=e.filter(a=>ft(a.id,t,r)&&(!o||o.has(a.id))),s=new Set(i.map(a=>a.id));return{nodes:i,edges:t.filter(a=>ju(a,r)&&s.has(a.source)&&s.has(a.target))}}const D0=500,z0="32 18",V0=e=>e.stopPropagation();function W0({id:e,reveal:t,onRevealComplete:r,edgeData:n,validationIssue:o,edgeType:i="rounded-orthogonal",edgeRadius:s,customEdgeTypes:a,source:c,target:u,sourceProperty:l,targetProperty:d,sourceY:f,targetY:p,sourcePort:y,targetPort:g,propertyMode:b=!1,dir:x,turn:m,labelAtTarget:w,labelFraction:v,color:C,connectorColor:_,labelBg:R,labelLayer:T,label:A,dashed:k,animated:j,inverted:E,loopIndex:M=0,onSelect:I}){const N=n==null?void 0:n.icon,O=b?bn:Tm,{lines:W,iconWidth:G,contentWidth:ee,contentHeight:ne}=S.useMemo(()=>Im(A,N,O),[A,N,O]),ce=S.useMemo(()=>{const te={srcDist:dn,tgtDist:dn,arrowGap:qm,arrowSize:Du,headShape:b&&(E?f!==void 0||y:p!==void 0||g)?"square":"triangle",radius:s??(w?40:D0),arrowAt:E?"source":"target",labelTargetLength:w?ee+2*Xr:void 0,labelFraction:w?v:void 0},de=f!==void 0||p!==void 0||!!y||!!g,ue=Ll(c,u,x,f,p,0),Se=f===void 0&&p===void 0&&(x==="downward"||x==="upward"),ye=y??{...ue.sourcePoint,side:Se?x==="upward"?"top":"bottom":x==="leftward"?"left":"right"},De=g??{...ue.targetPoint,side:Se?x==="upward"?"bottom":"top":x==="leftward"?"right":"left"},Le=c.x===u.x&&c.y===u.y,He=y||g?P0(ye,De,{...te,srcDist:18,tgtDist:18},i):de?Nl(c,u,x,f,p,m,{...te,srcDist:18,tgtDist:18,radius:s??Math.min(te.radius,40)}):Le?O0(c,M,{...te,srcDist:0,tgtDist:0}):$l(c,u,x,m,te);if(!He)return null;const ze=Ll(c,u,x,f,p,de?18:dn);y&&(ze.sourcePoint=pt(y,18)),g&&(ze.targetPoint=pt(g,18));const Ve=Object.prototype.hasOwnProperty.call(a??{},i)?a==null?void 0:a[i]:void 0;if(Ve){const Fe={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return Ve({edge:n??{id:e,source:"",target:""},source:{...c},target:{...u},...ze,direction:Fe[x],sourceY:f,targetY:p,inverted:!!E,defaultGeometry:He})??He}return Le||y||g?He:i==="straight"?de?Pm(ze.sourcePoint,ze.targetPoint,te):km([c,u],c,u,te):i==="bezier"?T0(ze.sourcePoint,ze.targetPoint,de?x==="leftward"?"leftward":"rightward":x,te):i==="orthogonal"?de?Nl(c,u,x,f,p,m,{...te,srcDist:18,tgtDist:18,radius:0}):$l(c,u,x,m,{...te,radius:0}):He},[c,e,n,i,s,a,u,b,f,p,y,g,x,m,E,M,w,v,ee]);if(!ce)return null;const me=(x==="rightward"||x==="leftward")&&!Object.prototype.hasOwnProperty.call(a??{},i)&&!(b&&(f!==void 0||p!==void 0||y||g)),K=me?`translate(${ce.label.x} ${ce.label.y-ne/2-2*Xr})`:`translate(${ce.label.x} ${ce.label.y}) rotate(${ce.label.angle}) translate(${w||Object.prototype.hasOwnProperty.call(a??{},i)?0:Om} 0)`,q=o!=null&&o.startsWith("Unverified:")?"#b45309":"#dc2626",L=o?q:C,z=o?h.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":o,transform:`translate(${ce.label.x} ${ce.label.y-W.length*O/2-55})`,children:[h.jsx("title",{children:o}),h.jsx(Mr,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:q})]}):null,H=j&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",X=!H&&(k||j)?z0:void 0,le=j&&!H?`flow-sdk-edge-anim${E?" flow-sdk-edge-anim-rev":""}`:void 0;let J=null;const V=t?{"--flow-edge-reveal-duration":`${t.durationMs??600}ms`,"--flow-edge-reveal-state":t.paused?"paused":"running"}:void 0;if(W.length||N){const te=ee,de=ne;J=h.jsxs("g",{className:`flow-sdk-edge-label${t?" flow-sdk-edge-reveal-end":""}`,style:V,"data-label-transform":K,"data-label-horizontal":me||void 0,"data-edge-id":e,"data-source-property":l,"data-target-property":d,transform:K,children:[h.jsx("rect",{x:-te/2-Xr,y:-de/2-Xr,width:te+2*Xr,height:de+2*Xr,fill:C==="transparent"?"transparent":R}),h.jsx("text",{fill:C,fontSize:O,style:{fontSize:O,fontFamily:nt},fontFamily:nt,textAnchor:"middle",dominantBaseline:"central",children:W.map((ue,Se)=>h.jsx("tspan",{x:G/2,y:(Se-(W.length-1)/2)*O,children:ue},Se))}),N&&h.jsxs("g",{className:"flow-sdk-edge-icon",opacity:C==="transparent"?0:1,children:[h.jsx("title",{children:A?`Edge icon: ${A}`:"Edge icon"}),h.jsx("rect",{x:-te/2,y:-24,width:48,height:48,fill:"transparent"}),h.jsx(Mr,{name:N,svg:!0,size:48,x:-te/2,y:-24,color:C})]})]})}const Y=h.jsxs(h.Fragment,{children:[h.jsx("path",{d:ce.d,fill:"none",stroke:L,strokeWidth:Vt,strokeOpacity:H?.35:void 0,strokeDasharray:X,className:le}),H&&h.jsx(b0,{path:ce.d,color:L,width:Vt*1.6,reversed:E})]});return h.jsxs("g",{className:"flow-sdk-edge",style:V,"data-edge-id":e,"data-source-property":l,"data-target-property":d,"data-validation":o?o.startsWith("Unverified:")?"unverified":"invalid":void 0,"aria-label":o,onPointerDown:V0,onClick:te=>{te.stopPropagation(),I==null||I(e)},children:[t?h.jsx(x0,{path:ce.d,width:Vt*4,reversed:E,onComplete:()=>r==null?void 0:r(e),children:Y}):Y,ce.arrow&&h.jsx("path",{className:t?"flow-sdk-edge-reveal-end":void 0,d:ce.arrow,fill:o?q:_??L}),T&&J?Wt.createPortal(J,T):J,T&&z?Wt.createPortal(z,T):z,h.jsx("path",{className:"flow-sdk-edge-hit",d:ce.d,fill:"none",stroke:"transparent"})]})}const Bl=S.memo(W0),Dl=(e,t)=>e.left<t.right&&e.right>t.left&&e.top<t.bottom&&e.bottom>t.top;function G0(e){const t=e.querySelector(".flow-sdk-labels"),r=t==null?void 0:t.getScreenCTM();if(!t||!r)return;const n=r.inverse(),o=(u,l=0)=>{const d=u.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(u=>{const l=u.getBoundingClientRect(),d=getComputedStyle(u);return l.width>0&&l.height>0&&d.visibility!=="hidden"&&d.opacity!=="0"}).map(u=>o(u,24));for(const u of t.querySelectorAll(".flow-sdk-container-label"))i.push(o(u,12));const s=[...t.querySelectorAll(".flow-sdk-edge-label")];for(const u of s)u.setAttribute("transform",u.dataset.labelTransform??"");const a=new Map(s.map(u=>[u,o(u,8)])),c=new Map([...e.querySelectorAll(".flow-sdk-edge")].map(u=>[u.dataset.edgeId,u.querySelector("path")]));for(const u of s){const l=u.dataset.labelHorizontal==="true",d=a.get(u);a.delete(u);const f=R=>i.some(T=>Dl(R,T))||[...a.values()].some(T=>Dl(R,T));if(!l&&!f(d)){a.set(u,d);continue}const p=c.get(u.dataset.edgeId),y=u.querySelector("rect");if(!p||!y)continue;const g=y.getBBox(),b=p.getTotalLength();if(!Number.isFinite(b)||b<=0)continue;const x=(d.left+d.right)/2,m=(d.top+d.bottom)/2,w=Math.min(256,Math.max(16,Math.ceil(b/24))),v=Array.from({length:w+1},(R,T)=>p.getPointAtLength(b*T/w)),_=Array.from({length:w+1},(R,T)=>{const A=b*T/w,k=v[T],j=l?{x:k.x,y:k.y-g.height/2-15}:k,E=p.getPointAtLength(Math.max(0,A-2)),M=p.getPointAtLength(Math.min(b,A+2));let I=Math.atan2(M.y-E.y,M.x-E.x)*180/Math.PI;I>90&&(I-=180),I<-90&&(I+=180);const N=Math.abs(I)<1;l&&(I=0);const O=I*Math.PI/180,W=Math.abs(Math.cos(O))*g.width+Math.abs(Math.sin(O))*g.height,G=Math.abs(Math.sin(O))*g.width+Math.abs(Math.cos(O))*g.height;return{point:j,angle:I,straight:N,score:Math.hypot(j.x-x,j.y-m),bounds:{left:j.x-W/2-8,right:j.x+W/2+8,top:j.y-G/2-8,bottom:j.y+G/2+8}}}).sort((R,T)=>R.score-T.score).find(R=>!f(R.bounds)&&(!l||R.straight&&!v.some(T=>T.x>R.bounds.left&&T.x<R.bounds.right&&T.y>R.bounds.top&&T.y<R.bounds.bottom)));_?(u.setAttribute("transform",`translate(${_.point.x} ${_.point.y}) rotate(${_.angle})`),a.set(u,_.bounds)):a.set(u,d)}}var ln=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function U0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function zu(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 ro,zl;function H0(){if(zl)return ro;zl=1;function e(){this.__data__=[],this.size=0}return ro=e,ro}var to,Vl;function wt(){if(Vl)return to;Vl=1;function e(t,r){return t===r||t!==t&&r!==r}return to=e,to}var no,Wl;function kn(){if(Wl)return no;Wl=1;var e=wt();function t(r,n){for(var o=r.length;o--;)if(e(r[o][0],n))return o;return-1}return no=t,no}var oo,Gl;function K0(){if(Gl)return oo;Gl=1;var e=kn(),t=Array.prototype,r=t.splice;function n(o){var i=this.__data__,s=e(i,o);if(s<0)return!1;var a=i.length-1;return s==a?i.pop():r.call(i,s,1),--this.size,!0}return oo=n,oo}var io,Ul;function J0(){if(Ul)return io;Ul=1;var e=kn();function t(r){var n=this.__data__,o=e(n,r);return o<0?void 0:n[o][1]}return io=t,io}var ao,Hl;function Z0(){if(Hl)return ao;Hl=1;var e=kn();function t(r){return e(this.__data__,r)>-1}return ao=t,ao}var so,Kl;function Y0(){if(Kl)return so;Kl=1;var e=kn();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 so=t,so}var co,Jl;function Pn(){if(Jl)return co;Jl=1;var e=H0(),t=K0(),r=J0(),n=Z0(),o=Y0();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var u=s[a];this.set(u[0],u[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=o,co=i,co}var uo,Zl;function X0(){if(Zl)return uo;Zl=1;var e=Pn();function t(){this.__data__=new e,this.size=0}return uo=t,uo}var lo,Yl;function Q0(){if(Yl)return lo;Yl=1;function e(t){var r=this.__data__,n=r.delete(t);return this.size=r.size,n}return lo=e,lo}var fo,Xl;function ew(){if(Xl)return fo;Xl=1;function e(t){return this.__data__.get(t)}return fo=e,fo}var ho,Ql;function rw(){if(Ql)return ho;Ql=1;function e(t){return this.__data__.has(t)}return ho=e,ho}var po,ed;function Nm(){if(ed)return po;ed=1;var e=typeof ln=="object"&&ln&&ln.Object===Object&&ln;return po=e,po}var go,rd;function _r(){if(rd)return go;rd=1;var e=Nm(),t=typeof self=="object"&&self&&self.Object===Object&&self,r=e||t||Function("return this")();return go=r,go}var yo,td;function Ct(){if(td)return yo;td=1;var e=_r(),t=e.Symbol;return yo=t,yo}var mo,nd;function tw(){if(nd)return mo;nd=1;var e=Ct(),t=Object.prototype,r=t.hasOwnProperty,n=t.toString,o=e?e.toStringTag:void 0;function i(s){var a=r.call(s,o),c=s[o];try{s[o]=void 0;var u=!0}catch{}var l=n.call(s);return u&&(a?s[o]=c:delete s[o]),l}return mo=i,mo}var bo,od;function nw(){if(od)return bo;od=1;var e=Object.prototype,t=e.toString;function r(n){return t.call(n)}return bo=r,bo}var vo,id;function ot(){if(id)return vo;id=1;var e=Ct(),t=tw(),r=nw(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function s(a){return a==null?a===void 0?o:n:i&&i in Object(a)?t(a):r(a)}return vo=s,vo}var xo,ad;function vr(){if(ad)return xo;ad=1;function e(t){var r=typeof t;return t!=null&&(r=="object"||r=="function")}return xo=e,xo}var wo,sd;function tn(){if(sd)return wo;sd=1;var e=ot(),t=vr(),r="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function s(a){if(!t(a))return!1;var c=e(a);return c==n||c==o||c==r||c==i}return wo=s,wo}var Co,cd;function ow(){if(cd)return Co;cd=1;var e=_r(),t=e["__core-js_shared__"];return Co=t,Co}var _o,ud;function iw(){if(ud)return _o;ud=1;var e=ow(),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 _o=r,_o}var So,ld;function $m(){if(ld)return So;ld=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 So=r,So}var Eo,dd;function aw(){if(dd)return Eo;dd=1;var e=tn(),t=iw(),r=vr(),n=$m(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,s=Function.prototype,a=Object.prototype,c=s.toString,u=a.hasOwnProperty,l=RegExp("^"+c.call(u).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 Eo=d,Eo}var jo,fd;function sw(){if(fd)return jo;fd=1;function e(t,r){return t==null?void 0:t[r]}return jo=e,jo}var Ro,hd;function it(){if(hd)return Ro;hd=1;var e=aw(),t=sw();function r(n,o){var i=t(n,o);return e(i)?i:void 0}return Ro=r,Ro}var ko,pd;function Vu(){if(pd)return ko;pd=1;var e=it(),t=_r(),r=e(t,"Map");return ko=r,ko}var Po,gd;function An(){if(gd)return Po;gd=1;var e=it(),t=e(Object,"create");return Po=t,Po}var Ao,yd;function cw(){if(yd)return Ao;yd=1;var e=An();function t(){this.__data__=e?e(null):{},this.size=0}return Ao=t,Ao}var To,md;function uw(){if(md)return To;md=1;function e(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r}return To=e,To}var Oo,bd;function lw(){if(bd)return Oo;bd=1;var e=An(),t="__lodash_hash_undefined__",r=Object.prototype,n=r.hasOwnProperty;function o(i){var s=this.__data__;if(e){var a=s[i];return a===t?void 0:a}return n.call(s,i)?s[i]:void 0}return Oo=o,Oo}var Io,vd;function dw(){if(vd)return Io;vd=1;var e=An(),t=Object.prototype,r=t.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:r.call(i,o)}return Io=n,Io}var Mo,xd;function fw(){if(xd)return Mo;xd=1;var e=An(),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 Mo=r,Mo}var qo,wd;function hw(){if(wd)return qo;wd=1;var e=cw(),t=uw(),r=lw(),n=dw(),o=fw();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var u=s[a];this.set(u[0],u[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=o,qo=i,qo}var No,Cd;function pw(){if(Cd)return No;Cd=1;var e=hw(),t=Pn(),r=Vu();function n(){this.size=0,this.__data__={hash:new e,map:new(r||t),string:new e}}return No=n,No}var $o,_d;function gw(){if(_d)return $o;_d=1;function e(t){var r=typeof t;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?t!=="__proto__":t===null}return $o=e,$o}var Lo,Sd;function Tn(){if(Sd)return Lo;Sd=1;var e=gw();function t(r,n){var o=r.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return Lo=t,Lo}var Fo,Ed;function yw(){if(Ed)return Fo;Ed=1;var e=Tn();function t(r){var n=e(this,r).delete(r);return this.size-=n?1:0,n}return Fo=t,Fo}var Bo,jd;function mw(){if(jd)return Bo;jd=1;var e=Tn();function t(r){return e(this,r).get(r)}return Bo=t,Bo}var Do,Rd;function bw(){if(Rd)return Do;Rd=1;var e=Tn();function t(r){return e(this,r).has(r)}return Do=t,Do}var zo,kd;function vw(){if(kd)return zo;kd=1;var e=Tn();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 zo=t,zo}var Vo,Pd;function Wu(){if(Pd)return Vo;Pd=1;var e=pw(),t=yw(),r=mw(),n=bw(),o=vw();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var u=s[a];this.set(u[0],u[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=o,Vo=i,Vo}var Wo,Ad;function xw(){if(Ad)return Wo;Ad=1;var e=Pn(),t=Vu(),r=Wu(),n=200;function o(i,s){var a=this.__data__;if(a instanceof e){var c=a.__data__;if(!t||c.length<n-1)return c.push([i,s]),this.size=++a.size,this;a=this.__data__=new r(c)}return a.set(i,s),this.size=a.size,this}return Wo=o,Wo}var Go,Td;function On(){if(Td)return Go;Td=1;var e=Pn(),t=X0(),r=Q0(),n=ew(),o=rw(),i=xw();function s(a){var c=this.__data__=new e(a);this.size=c.size}return s.prototype.clear=t,s.prototype.delete=r,s.prototype.get=n,s.prototype.has=o,s.prototype.set=i,Go=s,Go}var Uo,Od;function Gu(){if(Od)return Uo;Od=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 Uo=e,Uo}var Ho,Id;function Lm(){if(Id)return Ho;Id=1;var e=it(),t=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return Ho=t,Ho}var Ko,Md;function In(){if(Md)return Ko;Md=1;var e=Lm();function t(r,n,o){n=="__proto__"&&e?e(r,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):r[n]=o}return Ko=t,Ko}var Jo,qd;function Mn(){if(qd)return Jo;qd=1;var e=In(),t=wt(),r=Object.prototype,n=r.hasOwnProperty;function o(i,s,a){var c=i[s];(!(n.call(i,s)&&t(c,a))||a===void 0&&!(s in i))&&e(i,s,a)}return Jo=o,Jo}var Zo,Nd;function nn(){if(Nd)return Zo;Nd=1;var e=Mn(),t=In();function r(n,o,i,s){var a=!i;i||(i={});for(var c=-1,u=o.length;++c<u;){var l=o[c],d=s?s(i[l],n[l],l,i,n):void 0;d===void 0&&(d=n[l]),a?t(i,l,d):e(i,l,d)}return i}return Zo=r,Zo}var Yo,$d;function ww(){if($d)return Yo;$d=1;function e(t,r){for(var n=-1,o=Array(t);++n<t;)o[n]=r(n);return o}return Yo=e,Yo}var Xo,Ld;function kr(){if(Ld)return Xo;Ld=1;function e(t){return t!=null&&typeof t=="object"}return Xo=e,Xo}var Qo,Fd;function Cw(){if(Fd)return Qo;Fd=1;var e=ot(),t=kr(),r="[object Arguments]";function n(o){return t(o)&&e(o)==r}return Qo=n,Qo}var ei,Bd;function on(){if(Bd)return ei;Bd=1;var e=Cw(),t=kr(),r=Object.prototype,n=r.hasOwnProperty,o=r.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(s){return t(s)&&n.call(s,"callee")&&!o.call(s,"callee")};return ei=i,ei}var ri,Dd;function Xe(){if(Dd)return ri;Dd=1;var e=Array.isArray;return ri=e,ri}var Mt={exports:{}},ti,zd;function _w(){if(zd)return ti;zd=1;function e(){return!1}return ti=e,ti}Mt.exports;var Vd;function _t(){return Vd||(Vd=1,(function(e,t){var r=_r(),n=_w(),o=t&&!t.nodeType&&t,i=o&&!0&&e&&!e.nodeType&&e,s=i&&i.exports===o,a=s?r.Buffer:void 0,c=a?a.isBuffer:void 0,u=c||n;e.exports=u})(Mt,Mt.exports)),Mt.exports}var ni,Wd;function qn(){if(Wd)return ni;Wd=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 ni=r,ni}var oi,Gd;function Uu(){if(Gd)return oi;Gd=1;var e=9007199254740991;function t(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return oi=t,oi}var ii,Ud;function Sw(){if(Ud)return ii;Ud=1;var e=ot(),t=Uu(),r=kr(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",s="[object Date]",a="[object Error]",c="[object Function]",u="[object Map]",l="[object Number]",d="[object Object]",f="[object RegExp]",p="[object Set]",y="[object String]",g="[object WeakMap]",b="[object ArrayBuffer]",x="[object DataView]",m="[object Float32Array]",w="[object Float64Array]",v="[object Int8Array]",C="[object Int16Array]",_="[object Int32Array]",R="[object Uint8Array]",T="[object Uint8ClampedArray]",A="[object Uint16Array]",k="[object Uint32Array]",j={};j[m]=j[w]=j[v]=j[C]=j[_]=j[R]=j[T]=j[A]=j[k]=!0,j[n]=j[o]=j[b]=j[i]=j[x]=j[s]=j[a]=j[c]=j[u]=j[l]=j[d]=j[f]=j[p]=j[y]=j[g]=!1;function E(M){return r(M)&&t(M.length)&&!!j[e(M)]}return ii=E,ii}var ai,Hd;function Nn(){if(Hd)return ai;Hd=1;function e(t){return function(r){return t(r)}}return ai=e,ai}var qt={exports:{}};qt.exports;var Kd;function Hu(){return Kd||(Kd=1,(function(e,t){var r=Nm(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i&&r.process,a=(function(){try{var c=o&&o.require&&o.require("util").types;return c||s&&s.binding&&s.binding("util")}catch{}})();e.exports=a})(qt,qt.exports)),qt.exports}var si,Jd;function an(){if(Jd)return si;Jd=1;var e=Sw(),t=Nn(),r=Hu(),n=r&&r.isTypedArray,o=n?t(n):e;return si=o,si}var ci,Zd;function Fm(){if(Zd)return ci;Zd=1;var e=ww(),t=on(),r=Xe(),n=_t(),o=qn(),i=an(),s=Object.prototype,a=s.hasOwnProperty;function c(u,l){var d=r(u),f=!d&&t(u),p=!d&&!f&&n(u),y=!d&&!f&&!p&&i(u),g=d||f||p||y,b=g?e(u.length,String):[],x=b.length;for(var m in u)(l||a.call(u,m))&&!(g&&(m=="length"||p&&(m=="offset"||m=="parent")||y&&(m=="buffer"||m=="byteLength"||m=="byteOffset")||o(m,x)))&&b.push(m);return b}return ci=c,ci}var ui,Yd;function $n(){if(Yd)return ui;Yd=1;var e=Object.prototype;function t(r){var n=r&&r.constructor,o=typeof n=="function"&&n.prototype||e;return r===o}return ui=t,ui}var li,Xd;function Bm(){if(Xd)return li;Xd=1;function e(t,r){return function(n){return t(r(n))}}return li=e,li}var di,Qd;function Ew(){if(Qd)return di;Qd=1;var e=Bm(),t=e(Object.keys,Object);return di=t,di}var fi,ef;function Ku(){if(ef)return fi;ef=1;var e=$n(),t=Ew(),r=Object.prototype,n=r.hasOwnProperty;function o(i){if(!e(i))return t(i);var s=[];for(var a in Object(i))n.call(i,a)&&a!="constructor"&&s.push(a);return s}return fi=o,fi}var hi,rf;function qr(){if(rf)return hi;rf=1;var e=tn(),t=Uu();function r(n){return n!=null&&t(n.length)&&!e(n)}return hi=r,hi}var pi,tf;function Hr(){if(tf)return pi;tf=1;var e=Fm(),t=Ku(),r=qr();function n(o){return r(o)?e(o):t(o)}return pi=n,pi}var gi,nf;function jw(){if(nf)return gi;nf=1;var e=nn(),t=Hr();function r(n,o){return n&&e(o,t(o),n)}return gi=r,gi}var yi,of;function Rw(){if(of)return yi;of=1;function e(t){var r=[];if(t!=null)for(var n in Object(t))r.push(n);return r}return yi=e,yi}var mi,af;function kw(){if(af)return mi;af=1;var e=vr(),t=$n(),r=Rw(),n=Object.prototype,o=n.hasOwnProperty;function i(s){if(!e(s))return r(s);var a=t(s),c=[];for(var u in s)u=="constructor"&&(a||!o.call(s,u))||c.push(u);return c}return mi=i,mi}var bi,sf;function at(){if(sf)return bi;sf=1;var e=Fm(),t=kw(),r=qr();function n(o){return r(o)?e(o,!0):t(o)}return bi=n,bi}var vi,cf;function Pw(){if(cf)return vi;cf=1;var e=nn(),t=at();function r(n,o){return n&&e(o,t(o),n)}return vi=r,vi}var Nt={exports:{}};Nt.exports;var uf;function Dm(){return uf||(uf=1,(function(e,t){var r=_r(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i?r.Buffer:void 0,a=s?s.allocUnsafe:void 0;function c(u,l){if(l)return u.slice();var d=u.length,f=a?a(d):new u.constructor(d);return u.copy(f),f}e.exports=c})(Nt,Nt.exports)),Nt.exports}var xi,lf;function zm(){if(lf)return xi;lf=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 xi=e,xi}var wi,df;function Vm(){if(df)return wi;df=1;function e(t,r){for(var n=-1,o=t==null?0:t.length,i=0,s=[];++n<o;){var a=t[n];r(a,n,t)&&(s[i++]=a)}return s}return wi=e,wi}var Ci,ff;function Wm(){if(ff)return Ci;ff=1;function e(){return[]}return Ci=e,Ci}var _i,hf;function Ju(){if(hf)return _i;hf=1;var e=Vm(),t=Wm(),r=Object.prototype,n=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(s){return s==null?[]:(s=Object(s),e(o(s),function(a){return n.call(s,a)}))}:t;return _i=i,_i}var Si,pf;function Aw(){if(pf)return Si;pf=1;var e=nn(),t=Ju();function r(n,o){return e(n,t(n),o)}return Si=r,Si}var Ei,gf;function Zu(){if(gf)return Ei;gf=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 Ei=e,Ei}var ji,yf;function Ln(){if(yf)return ji;yf=1;var e=Bm(),t=e(Object.getPrototypeOf,Object);return ji=t,ji}var Ri,mf;function Gm(){if(mf)return Ri;mf=1;var e=Zu(),t=Ln(),r=Ju(),n=Wm(),o=Object.getOwnPropertySymbols,i=o?function(s){for(var a=[];s;)e(a,r(s)),s=t(s);return a}:n;return Ri=i,Ri}var ki,bf;function Tw(){if(bf)return ki;bf=1;var e=nn(),t=Gm();function r(n,o){return e(n,t(n),o)}return ki=r,ki}var Pi,vf;function Um(){if(vf)return Pi;vf=1;var e=Zu(),t=Xe();function r(n,o,i){var s=o(n);return t(n)?s:e(s,i(n))}return Pi=r,Pi}var Ai,xf;function Hm(){if(xf)return Ai;xf=1;var e=Um(),t=Ju(),r=Hr();function n(o){return e(o,r,t)}return Ai=n,Ai}var Ti,wf;function Ow(){if(wf)return Ti;wf=1;var e=Um(),t=Gm(),r=at();function n(o){return e(o,r,t)}return Ti=n,Ti}var Oi,Cf;function Iw(){if(Cf)return Oi;Cf=1;var e=it(),t=_r(),r=e(t,"DataView");return Oi=r,Oi}var Ii,_f;function Mw(){if(_f)return Ii;_f=1;var e=it(),t=_r(),r=e(t,"Promise");return Ii=r,Ii}var Mi,Sf;function Km(){if(Sf)return Mi;Sf=1;var e=it(),t=_r(),r=e(t,"Set");return Mi=r,Mi}var qi,Ef;function qw(){if(Ef)return qi;Ef=1;var e=it(),t=_r(),r=e(t,"WeakMap");return qi=r,qi}var Ni,jf;function St(){if(jf)return Ni;jf=1;var e=Iw(),t=Vu(),r=Mw(),n=Km(),o=qw(),i=ot(),s=$m(),a="[object Map]",c="[object Object]",u="[object Promise]",l="[object Set]",d="[object WeakMap]",f="[object DataView]",p=s(e),y=s(t),g=s(r),b=s(n),x=s(o),m=i;return(e&&m(new e(new ArrayBuffer(1)))!=f||t&&m(new t)!=a||r&&m(r.resolve())!=u||n&&m(new n)!=l||o&&m(new o)!=d)&&(m=function(w){var v=i(w),C=v==c?w.constructor:void 0,_=C?s(C):"";if(_)switch(_){case p:return f;case y:return a;case g:return u;case b:return l;case x:return d}return v}),Ni=m,Ni}var $i,Rf;function Nw(){if(Rf)return $i;Rf=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 $i=r,$i}var Li,kf;function Jm(){if(kf)return Li;kf=1;var e=_r(),t=e.Uint8Array;return Li=t,Li}var Fi,Pf;function Yu(){if(Pf)return Fi;Pf=1;var e=Jm();function t(r){var n=new r.constructor(r.byteLength);return new e(n).set(new e(r)),n}return Fi=t,Fi}var Bi,Af;function $w(){if(Af)return Bi;Af=1;var e=Yu();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.byteLength)}return Bi=t,Bi}var Di,Tf;function Lw(){if(Tf)return Di;Tf=1;var e=/\w*$/;function t(r){var n=new r.constructor(r.source,e.exec(r));return n.lastIndex=r.lastIndex,n}return Di=t,Di}var zi,Of;function Fw(){if(Of)return zi;Of=1;var e=Ct(),t=e?e.prototype:void 0,r=t?t.valueOf:void 0;function n(o){return r?Object(r.call(o)):{}}return zi=n,zi}var Vi,If;function Zm(){if(If)return Vi;If=1;var e=Yu();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.length)}return Vi=t,Vi}var Wi,Mf;function Bw(){if(Mf)return Wi;Mf=1;var e=Yu(),t=$w(),r=Lw(),n=Fw(),o=Zm(),i="[object Boolean]",s="[object Date]",a="[object Map]",c="[object Number]",u="[object RegExp]",l="[object Set]",d="[object String]",f="[object Symbol]",p="[object ArrayBuffer]",y="[object DataView]",g="[object Float32Array]",b="[object Float64Array]",x="[object Int8Array]",m="[object Int16Array]",w="[object Int32Array]",v="[object Uint8Array]",C="[object Uint8ClampedArray]",_="[object Uint16Array]",R="[object Uint32Array]";function T(A,k,j){var E=A.constructor;switch(k){case p:return e(A);case i:case s:return new E(+A);case y:return t(A,j);case g:case b:case x:case m:case w:case v:case C:case _:case R:return o(A,j);case a:return new E;case c:case d:return new E(A);case u:return r(A);case l:return new E;case f:return n(A)}}return Wi=T,Wi}var Gi,qf;function Ym(){if(qf)return Gi;qf=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 Gi=r,Gi}var Ui,Nf;function Xm(){if(Nf)return Ui;Nf=1;var e=Ym(),t=Ln(),r=$n();function n(o){return typeof o.constructor=="function"&&!r(o)?e(t(o)):{}}return Ui=n,Ui}var Hi,$f;function Dw(){if($f)return Hi;$f=1;var e=St(),t=kr(),r="[object Map]";function n(o){return t(o)&&e(o)==r}return Hi=n,Hi}var Ki,Lf;function zw(){if(Lf)return Ki;Lf=1;var e=Dw(),t=Nn(),r=Hu(),n=r&&r.isMap,o=n?t(n):e;return Ki=o,Ki}var Ji,Ff;function Vw(){if(Ff)return Ji;Ff=1;var e=St(),t=kr(),r="[object Set]";function n(o){return t(o)&&e(o)==r}return Ji=n,Ji}var Zi,Bf;function Ww(){if(Bf)return Zi;Bf=1;var e=Vw(),t=Nn(),r=Hu(),n=r&&r.isSet,o=n?t(n):e;return Zi=o,Zi}var Yi,Df;function Qm(){if(Df)return Yi;Df=1;var e=On(),t=Gu(),r=Mn(),n=jw(),o=Pw(),i=Dm(),s=zm(),a=Aw(),c=Tw(),u=Hm(),l=Ow(),d=St(),f=Nw(),p=Bw(),y=Xm(),g=Xe(),b=_t(),x=zw(),m=vr(),w=Ww(),v=Hr(),C=at(),_=1,R=2,T=4,A="[object Arguments]",k="[object Array]",j="[object Boolean]",E="[object Date]",M="[object Error]",I="[object Function]",N="[object GeneratorFunction]",O="[object Map]",W="[object Number]",G="[object Object]",ee="[object RegExp]",ne="[object Set]",ce="[object String]",me="[object Symbol]",K="[object WeakMap]",q="[object ArrayBuffer]",L="[object DataView]",z="[object Float32Array]",H="[object Float64Array]",X="[object Int8Array]",le="[object Int16Array]",J="[object Int32Array]",V="[object Uint8Array]",Y="[object Uint8ClampedArray]",te="[object Uint16Array]",de="[object Uint32Array]",ue={};ue[A]=ue[k]=ue[q]=ue[L]=ue[j]=ue[E]=ue[z]=ue[H]=ue[X]=ue[le]=ue[J]=ue[O]=ue[W]=ue[G]=ue[ee]=ue[ne]=ue[ce]=ue[me]=ue[V]=ue[Y]=ue[te]=ue[de]=!0,ue[M]=ue[I]=ue[K]=!1;function Se(ye,De,Le,He,ze,Ve){var Fe,Ye=De&_,ir=De&R,be=De&T;if(Le&&(Fe=ze?Le(ye,He,ze,Ve):Le(ye)),Fe!==void 0)return Fe;if(!m(ye))return ye;var Pe=g(ye);if(Pe){if(Fe=f(ye),!Ye)return s(ye,Fe)}else{var We=d(ye),pr=We==I||We==N;if(b(ye))return i(ye,Ye);if(We==G||We==A||pr&&!ze){if(Fe=ir||pr?{}:y(ye),!Ye)return ir?c(ye,o(Fe,ye)):a(ye,n(Fe,ye))}else{if(!ue[We])return ze?ye:{};Fe=p(ye,We,Ye)}}Ve||(Ve=new e);var er=Ve.get(ye);if(er)return er;Ve.set(ye,Fe),w(ye)?ye.forEach(function(ar){Fe.add(Se(ar,De,Le,ar,ye,Ve))}):x(ye)&&ye.forEach(function(ar,xe){Fe.set(xe,Se(ar,De,Le,xe,ye,Ve))});var Qe=be?ir?l:u:ir?C:v,lr=Pe?void 0:Qe(ye);return t(lr||ye,function(ar,xe){lr&&(xe=ar,ar=ye[xe]),r(Fe,xe,Se(ar,De,Le,xe,ye,Ve))}),Fe}return Yi=Se,Yi}var Xi,zf;function Gw(){if(zf)return Xi;zf=1;var e=Qm(),t=4;function r(n){return e(n,t)}return Xi=r,Xi}var Qi,Vf;function Xu(){if(Vf)return Qi;Vf=1;function e(t){return function(){return t}}return Qi=e,Qi}var ea,Wf;function Uw(){if(Wf)return ea;Wf=1;function e(t){return function(r,n,o){for(var i=-1,s=Object(r),a=o(r),c=a.length;c--;){var u=a[t?c:++i];if(n(s[u],u,s)===!1)break}return r}}return ea=e,ea}var ra,Gf;function Qu(){if(Gf)return ra;Gf=1;var e=Uw(),t=e();return ra=t,ra}var ta,Uf;function el(){if(Uf)return ta;Uf=1;var e=Qu(),t=Hr();function r(n,o){return n&&e(n,o,t)}return ta=r,ta}var na,Hf;function Hw(){if(Hf)return na;Hf=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 s=o.length,a=n?s:-1,c=Object(o);(n?a--:++a<s)&&i(c[a],a,c)!==!1;);return o}}return na=t,na}var oa,Kf;function Fn(){if(Kf)return oa;Kf=1;var e=el(),t=Hw(),r=t(e);return oa=r,oa}var ia,Jf;function st(){if(Jf)return ia;Jf=1;function e(t){return t}return ia=e,ia}var aa,Zf;function eb(){if(Zf)return aa;Zf=1;var e=st();function t(r){return typeof r=="function"?r:e}return aa=t,aa}var sa,Yf;function rb(){if(Yf)return sa;Yf=1;var e=Gu(),t=Fn(),r=eb(),n=Xe();function o(i,s){var a=n(i)?e:t;return a(i,r(s))}return sa=o,sa}var ca,Xf;function tb(){return Xf||(Xf=1,ca=rb()),ca}var ua,Qf;function Kw(){if(Qf)return ua;Qf=1;var e=Fn();function t(r,n){var o=[];return e(r,function(i,s,a){n(i,s,a)&&o.push(i)}),o}return ua=t,ua}var la,eh;function Jw(){if(eh)return la;eh=1;var e="__lodash_hash_undefined__";function t(r){return this.__data__.set(r,e),this}return la=t,la}var da,rh;function Zw(){if(rh)return da;rh=1;function e(t){return this.__data__.has(t)}return da=e,da}var fa,th;function nb(){if(th)return fa;th=1;var e=Wu(),t=Jw(),r=Zw();function n(o){var i=-1,s=o==null?0:o.length;for(this.__data__=new e;++i<s;)this.add(o[i])}return n.prototype.add=n.prototype.push=t,n.prototype.has=r,fa=n,fa}var ha,nh;function Yw(){if(nh)return ha;nh=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 ha=e,ha}var pa,oh;function ob(){if(oh)return pa;oh=1;function e(t,r){return t.has(r)}return pa=e,pa}var ga,ih;function ib(){if(ih)return ga;ih=1;var e=nb(),t=Yw(),r=ob(),n=1,o=2;function i(s,a,c,u,l,d){var f=c&n,p=s.length,y=a.length;if(p!=y&&!(f&&y>p))return!1;var g=d.get(s),b=d.get(a);if(g&&b)return g==a&&b==s;var x=-1,m=!0,w=c&o?new e:void 0;for(d.set(s,a),d.set(a,s);++x<p;){var v=s[x],C=a[x];if(u)var _=f?u(C,v,x,a,s,d):u(v,C,x,s,a,d);if(_!==void 0){if(_)continue;m=!1;break}if(w){if(!t(a,function(R,T){if(!r(w,T)&&(v===R||l(v,R,c,u,d)))return w.push(T)})){m=!1;break}}else if(!(v===C||l(v,C,c,u,d))){m=!1;break}}return d.delete(s),d.delete(a),m}return ga=i,ga}var ya,ah;function Xw(){if(ah)return ya;ah=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o,i){n[++r]=[i,o]}),n}return ya=e,ya}var ma,sh;function rl(){if(sh)return ma;sh=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o){n[++r]=o}),n}return ma=e,ma}var ba,ch;function Qw(){if(ch)return ba;ch=1;var e=Ct(),t=Jm(),r=wt(),n=ib(),o=Xw(),i=rl(),s=1,a=2,c="[object Boolean]",u="[object Date]",l="[object Error]",d="[object Map]",f="[object Number]",p="[object RegExp]",y="[object Set]",g="[object String]",b="[object Symbol]",x="[object ArrayBuffer]",m="[object DataView]",w=e?e.prototype:void 0,v=w?w.valueOf:void 0;function C(_,R,T,A,k,j,E){switch(T){case m:if(_.byteLength!=R.byteLength||_.byteOffset!=R.byteOffset)return!1;_=_.buffer,R=R.buffer;case x:return!(_.byteLength!=R.byteLength||!j(new t(_),new t(R)));case c:case u:case f:return r(+_,+R);case l:return _.name==R.name&&_.message==R.message;case p:case g:return _==R+"";case d:var M=o;case y:var I=A&s;if(M||(M=i),_.size!=R.size&&!I)return!1;var N=E.get(_);if(N)return N==R;A|=a,E.set(_,R);var O=n(M(_),M(R),A,k,j,E);return E.delete(_),O;case b:if(v)return v.call(_)==v.call(R)}return!1}return ba=C,ba}var va,uh;function e1(){if(uh)return va;uh=1;var e=Hm(),t=1,r=Object.prototype,n=r.hasOwnProperty;function o(i,s,a,c,u,l){var d=a&t,f=e(i),p=f.length,y=e(s),g=y.length;if(p!=g&&!d)return!1;for(var b=p;b--;){var x=f[b];if(!(d?x in s:n.call(s,x)))return!1}var m=l.get(i),w=l.get(s);if(m&&w)return m==s&&w==i;var v=!0;l.set(i,s),l.set(s,i);for(var C=d;++b<p;){x=f[b];var _=i[x],R=s[x];if(c)var T=d?c(R,_,x,s,i,l):c(_,R,x,i,s,l);if(!(T===void 0?_===R||u(_,R,a,c,l):T)){v=!1;break}C||(C=x=="constructor")}if(v&&!C){var A=i.constructor,k=s.constructor;A!=k&&"constructor"in i&&"constructor"in s&&!(typeof A=="function"&&A instanceof A&&typeof k=="function"&&k instanceof k)&&(v=!1)}return l.delete(i),l.delete(s),v}return va=o,va}var xa,lh;function r1(){if(lh)return xa;lh=1;var e=On(),t=ib(),r=Qw(),n=e1(),o=St(),i=Xe(),s=_t(),a=an(),c=1,u="[object Arguments]",l="[object Array]",d="[object Object]",f=Object.prototype,p=f.hasOwnProperty;function y(g,b,x,m,w,v){var C=i(g),_=i(b),R=C?l:o(g),T=_?l:o(b);R=R==u?d:R,T=T==u?d:T;var A=R==d,k=T==d,j=R==T;if(j&&s(g)){if(!s(b))return!1;C=!0,A=!1}if(j&&!A)return v||(v=new e),C||a(g)?t(g,b,x,m,w,v):r(g,b,R,x,m,w,v);if(!(x&c)){var E=A&&p.call(g,"__wrapped__"),M=k&&p.call(b,"__wrapped__");if(E||M){var I=E?g.value():g,N=M?b.value():b;return v||(v=new e),w(I,N,x,m,v)}}return j?(v||(v=new e),n(g,b,x,m,w,v)):!1}return xa=y,xa}var wa,dh;function ab(){if(dh)return wa;dh=1;var e=r1(),t=kr();function r(n,o,i,s,a){return n===o?!0:n==null||o==null||!t(n)&&!t(o)?n!==n&&o!==o:e(n,o,i,s,r,a)}return wa=r,wa}var Ca,fh;function t1(){if(fh)return Ca;fh=1;var e=On(),t=ab(),r=1,n=2;function o(i,s,a,c){var u=a.length,l=u,d=!c;if(i==null)return!l;for(i=Object(i);u--;){var f=a[u];if(d&&f[2]?f[1]!==i[f[0]]:!(f[0]in i))return!1}for(;++u<l;){f=a[u];var p=f[0],y=i[p],g=f[1];if(d&&f[2]){if(y===void 0&&!(p in i))return!1}else{var b=new e;if(c)var x=c(y,g,p,i,s,b);if(!(x===void 0?t(g,y,r|n,c,b):x))return!1}}return!0}return Ca=o,Ca}var _a,hh;function sb(){if(hh)return _a;hh=1;var e=vr();function t(r){return r===r&&!e(r)}return _a=t,_a}var Sa,ph;function n1(){if(ph)return Sa;ph=1;var e=sb(),t=Hr();function r(n){for(var o=t(n),i=o.length;i--;){var s=o[i],a=n[s];o[i]=[s,a,e(a)]}return o}return Sa=r,Sa}var Ea,gh;function cb(){if(gh)return Ea;gh=1;function e(t,r){return function(n){return n==null?!1:n[t]===r&&(r!==void 0||t in Object(n))}}return Ea=e,Ea}var ja,yh;function o1(){if(yh)return ja;yh=1;var e=t1(),t=n1(),r=cb();function n(o){var i=t(o);return i.length==1&&i[0][2]?r(i[0][0],i[0][1]):function(s){return s===o||e(s,o,i)}}return ja=n,ja}var Ra,mh;function Et(){if(mh)return Ra;mh=1;var e=ot(),t=kr(),r="[object Symbol]";function n(o){return typeof o=="symbol"||t(o)&&e(o)==r}return Ra=n,Ra}var ka,bh;function tl(){if(bh)return ka;bh=1;var e=Xe(),t=Et(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,s){if(e(i))return!1;var a=typeof i;return a=="number"||a=="symbol"||a=="boolean"||i==null||t(i)?!0:n.test(i)||!r.test(i)||s!=null&&i in Object(s)}return ka=o,ka}var Pa,vh;function i1(){if(vh)return Pa;vh=1;var e=Wu(),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 s=arguments,a=o?o.apply(this,s):s[0],c=i.cache;if(c.has(a))return c.get(a);var u=n.apply(this,s);return i.cache=c.set(a,u)||c,u};return i.cache=new(r.Cache||e),i}return r.Cache=e,Pa=r,Pa}var Aa,xh;function a1(){if(xh)return Aa;xh=1;var e=i1(),t=500;function r(n){var o=e(n,function(s){return i.size===t&&i.clear(),s}),i=o.cache;return o}return Aa=r,Aa}var Ta,wh;function s1(){if(wh)return Ta;wh=1;var e=a1(),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(s,a,c,u){i.push(c?u.replace(r,"$1"):a||s)}),i});return Ta=n,Ta}var Oa,Ch;function Bn(){if(Ch)return Oa;Ch=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 Oa=e,Oa}var Ia,_h;function c1(){if(_h)return Ia;_h=1;var e=Ct(),t=Bn(),r=Xe(),n=Et(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function s(a){if(typeof a=="string")return a;if(r(a))return t(a,s)+"";if(n(a))return i?i.call(a):"";var c=a+"";return c=="0"&&1/a==-1/0?"-0":c}return Ia=s,Ia}var Ma,Sh;function ub(){if(Sh)return Ma;Sh=1;var e=c1();function t(r){return r==null?"":e(r)}return Ma=t,Ma}var qa,Eh;function Dn(){if(Eh)return qa;Eh=1;var e=Xe(),t=tl(),r=s1(),n=ub();function o(i,s){return e(i)?i:t(i,s)?[i]:r(n(i))}return qa=o,qa}var Na,jh;function sn(){if(jh)return Na;jh=1;var e=Et();function t(r){if(typeof r=="string"||e(r))return r;var n=r+"";return n=="0"&&1/r==-1/0?"-0":n}return Na=t,Na}var $a,Rh;function zn(){if(Rh)return $a;Rh=1;var e=Dn(),t=sn();function r(n,o){o=e(o,n);for(var i=0,s=o.length;n!=null&&i<s;)n=n[t(o[i++])];return i&&i==s?n:void 0}return $a=r,$a}var La,kh;function u1(){if(kh)return La;kh=1;var e=zn();function t(r,n,o){var i=r==null?void 0:e(r,n);return i===void 0?o:i}return La=t,La}var Fa,Ph;function l1(){if(Ph)return Fa;Ph=1;function e(t,r){return t!=null&&r in Object(t)}return Fa=e,Fa}var Ba,Ah;function lb(){if(Ah)return Ba;Ah=1;var e=Dn(),t=on(),r=Xe(),n=qn(),o=Uu(),i=sn();function s(a,c,u){c=e(c,a);for(var l=-1,d=c.length,f=!1;++l<d;){var p=i(c[l]);if(!(f=a!=null&&u(a,p)))break;a=a[p]}return f||++l!=d?f:(d=a==null?0:a.length,!!d&&o(d)&&n(p,d)&&(r(a)||t(a)))}return Ba=s,Ba}var Da,Th;function db(){if(Th)return Da;Th=1;var e=l1(),t=lb();function r(n,o){return n!=null&&t(n,o,e)}return Da=r,Da}var za,Oh;function d1(){if(Oh)return za;Oh=1;var e=ab(),t=u1(),r=db(),n=tl(),o=sb(),i=cb(),s=sn(),a=1,c=2;function u(l,d){return n(l)&&o(d)?i(s(l),d):function(f){var p=t(f,l);return p===void 0&&p===d?r(f,l):e(d,p,a|c)}}return za=u,za}var Va,Ih;function fb(){if(Ih)return Va;Ih=1;function e(t){return function(r){return r==null?void 0:r[t]}}return Va=e,Va}var Wa,Mh;function f1(){if(Mh)return Wa;Mh=1;var e=zn();function t(r){return function(n){return e(n,r)}}return Wa=t,Wa}var Ga,qh;function h1(){if(qh)return Ga;qh=1;var e=fb(),t=f1(),r=tl(),n=sn();function o(i){return r(i)?e(n(i)):t(i)}return Ga=o,Ga}var Ua,Nh;function Nr(){if(Nh)return Ua;Nh=1;var e=o1(),t=d1(),r=st(),n=Xe(),o=h1();function i(s){return typeof s=="function"?s:s==null?r:typeof s=="object"?n(s)?t(s[0],s[1]):e(s):o(s)}return Ua=i,Ua}var Ha,$h;function hb(){if($h)return Ha;$h=1;var e=Vm(),t=Kw(),r=Nr(),n=Xe();function o(i,s){var a=n(i)?e:t;return a(i,r(s,3))}return Ha=o,Ha}var Ka,Lh;function p1(){if(Lh)return Ka;Lh=1;var e=Object.prototype,t=e.hasOwnProperty;function r(n,o){return n!=null&&t.call(n,o)}return Ka=r,Ka}var Ja,Fh;function pb(){if(Fh)return Ja;Fh=1;var e=p1(),t=lb();function r(n,o){return n!=null&&t(n,o,e)}return Ja=r,Ja}var Za,Bh;function g1(){if(Bh)return Za;Bh=1;var e=Ku(),t=St(),r=on(),n=Xe(),o=qr(),i=_t(),s=$n(),a=an(),c="[object Map]",u="[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)||a(p)||r(p)))return!p.length;var y=t(p);if(y==c||y==u)return!p.size;if(s(p))return!e(p).length;for(var g in p)if(d.call(p,g))return!1;return!0}return Za=f,Za}var Ya,Dh;function gb(){if(Dh)return Ya;Dh=1;function e(t){return t===void 0}return Ya=e,Ya}var Xa,zh;function yb(){if(zh)return Xa;zh=1;var e=Fn(),t=qr();function r(n,o){var i=-1,s=t(n)?Array(n.length):[];return e(n,function(a,c,u){s[++i]=o(a,c,u)}),s}return Xa=r,Xa}var Qa,Vh;function mb(){if(Vh)return Qa;Vh=1;var e=Bn(),t=Nr(),r=yb(),n=Xe();function o(i,s){var a=n(i)?e:r;return a(i,t(s,3))}return Qa=o,Qa}var es,Wh;function y1(){if(Wh)return es;Wh=1;function e(t,r,n,o){var i=-1,s=t==null?0:t.length;for(o&&s&&(n=t[++i]);++i<s;)n=r(n,t[i],i,t);return n}return es=e,es}var rs,Gh;function m1(){if(Gh)return rs;Gh=1;function e(t,r,n,o,i){return i(t,function(s,a,c){n=o?(o=!1,s):r(n,s,a,c)}),n}return rs=e,rs}var ts,Uh;function bb(){if(Uh)return ts;Uh=1;var e=y1(),t=Fn(),r=Nr(),n=m1(),o=Xe();function i(s,a,c){var u=o(s)?e:n,l=arguments.length<3;return u(s,r(a,4),c,l,t)}return ts=i,ts}var ns,Hh;function b1(){if(Hh)return ns;Hh=1;var e=ot(),t=Xe(),r=kr(),n="[object String]";function o(i){return typeof i=="string"||!t(i)&&r(i)&&e(i)==n}return ns=o,ns}var os,Kh;function v1(){if(Kh)return os;Kh=1;var e=fb(),t=e("length");return os=t,os}var is,Jh;function x1(){if(Jh)return is;Jh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",s="\\u200d",a=RegExp("["+s+e+o+i+"]");function c(u){return a.test(u)}return is=c,is}var as,Zh;function w1(){if(Zh)return as;Zh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",s="["+e+"]",a="["+o+"]",c="\\ud83c[\\udffb-\\udfff]",u="(?:"+a+"|"+c+")",l="[^"+e+"]",d="(?:\\ud83c[\\udde6-\\uddff]){2}",f="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",y=u+"?",g="["+i+"]?",b="(?:"+p+"(?:"+[l,d,f].join("|")+")"+g+y+")*",x=g+y+b,m="(?:"+[l+a+"?",a,d,f,s].join("|")+")",w=RegExp(c+"(?="+c+")|"+m+x,"g");function v(C){for(var _=w.lastIndex=0;w.test(C);)++_;return _}return as=v,as}var ss,Yh;function C1(){if(Yh)return ss;Yh=1;var e=v1(),t=x1(),r=w1();function n(o){return t(o)?r(o):e(o)}return ss=n,ss}var cs,Xh;function _1(){if(Xh)return cs;Xh=1;var e=Ku(),t=St(),r=qr(),n=b1(),o=C1(),i="[object Map]",s="[object Set]";function a(c){if(c==null)return 0;if(r(c))return n(c)?o(c):c.length;var u=t(c);return u==i||u==s?c.size:e(c).length}return cs=a,cs}var us,Qh;function S1(){if(Qh)return us;Qh=1;var e=Gu(),t=Ym(),r=el(),n=Nr(),o=Ln(),i=Xe(),s=_t(),a=tn(),c=vr(),u=an();function l(d,f,p){var y=i(d),g=y||s(d)||u(d);if(f=n(f,4),p==null){var b=d&&d.constructor;g?p=y?new b:[]:c(d)?p=a(b)?t(o(d)):{}:p={}}return(g?e:r)(d,function(x,m,w){return f(p,x,m,w)}),p}return us=l,us}var ls,ep;function E1(){if(ep)return ls;ep=1;var e=Ct(),t=on(),r=Xe(),n=e?e.isConcatSpreadable:void 0;function o(i){return r(i)||t(i)||!!(n&&i&&i[n])}return ls=o,ls}var ds,rp;function nl(){if(rp)return ds;rp=1;var e=Zu(),t=E1();function r(n,o,i,s,a){var c=-1,u=n.length;for(i||(i=t),a||(a=[]);++c<u;){var l=n[c];o>0&&i(l)?o>1?r(l,o-1,i,s,a):e(a,l):s||(a[a.length]=l)}return a}return ds=r,ds}var fs,tp;function j1(){if(tp)return fs;tp=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 fs=e,fs}var hs,np;function vb(){if(np)return hs;np=1;var e=j1(),t=Math.max;function r(n,o,i){return o=t(o===void 0?n.length-1:o,0),function(){for(var s=arguments,a=-1,c=t(s.length-o,0),u=Array(c);++a<c;)u[a]=s[o+a];a=-1;for(var l=Array(o+1);++a<o;)l[a]=s[a];return l[o]=i(u),e(n,this,l)}}return hs=r,hs}var ps,op;function R1(){if(op)return ps;op=1;var e=Xu(),t=Lm(),r=st(),n=t?function(o,i){return t(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:r;return ps=n,ps}var gs,ip;function k1(){if(ip)return gs;ip=1;var e=800,t=16,r=Date.now;function n(o){var i=0,s=0;return function(){var a=r(),c=t-(a-s);if(s=a,c>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return gs=n,gs}var ys,ap;function xb(){if(ap)return ys;ap=1;var e=R1(),t=k1(),r=t(e);return ys=r,ys}var ms,sp;function Vn(){if(sp)return ms;sp=1;var e=st(),t=vb(),r=xb();function n(o,i){return r(t(o,i,e),o+"")}return ms=n,ms}var bs,cp;function wb(){if(cp)return bs;cp=1;function e(t,r,n,o){for(var i=t.length,s=n+(o?1:-1);o?s--:++s<i;)if(r(t[s],s,t))return s;return-1}return bs=e,bs}var vs,up;function P1(){if(up)return vs;up=1;function e(t){return t!==t}return vs=e,vs}var xs,lp;function A1(){if(lp)return xs;lp=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 xs=e,xs}var ws,dp;function T1(){if(dp)return ws;dp=1;var e=wb(),t=P1(),r=A1();function n(o,i,s){return i===i?r(o,i,s):e(o,t,s)}return ws=n,ws}var Cs,fp;function O1(){if(fp)return Cs;fp=1;var e=T1();function t(r,n){var o=r==null?0:r.length;return!!o&&e(r,n,0)>-1}return Cs=t,Cs}var _s,hp;function I1(){if(hp)return _s;hp=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 _s=e,_s}var Ss,pp;function M1(){if(pp)return Ss;pp=1;function e(){}return Ss=e,Ss}var Es,gp;function q1(){if(gp)return Es;gp=1;var e=Km(),t=M1(),r=rl(),n=1/0,o=e&&1/r(new e([,-0]))[1]==n?function(i){return new e(i)}:t;return Es=o,Es}var js,yp;function N1(){if(yp)return js;yp=1;var e=nb(),t=O1(),r=I1(),n=ob(),o=q1(),i=rl(),s=200;function a(c,u,l){var d=-1,f=t,p=c.length,y=!0,g=[],b=g;if(l)y=!1,f=r;else if(p>=s){var x=u?null:o(c);if(x)return i(x);y=!1,f=n,b=new e}else b=u?[]:g;e:for(;++d<p;){var m=c[d],w=u?u(m):m;if(m=l||m!==0?m:0,y&&w===w){for(var v=b.length;v--;)if(b[v]===w)continue e;u&&b.push(w),g.push(m)}else f(b,w,l)||(b!==g&&b.push(w),g.push(m))}return g}return js=a,js}var Rs,mp;function Cb(){if(mp)return Rs;mp=1;var e=qr(),t=kr();function r(n){return t(n)&&e(n)}return Rs=r,Rs}var ks,bp;function $1(){if(bp)return ks;bp=1;var e=nl(),t=Vn(),r=N1(),n=Cb(),o=t(function(i){return r(e(i,1,n,!0))});return ks=o,ks}var Ps,vp;function L1(){if(vp)return Ps;vp=1;var e=Bn();function t(r,n){return e(n,function(o){return r[o]})}return Ps=t,Ps}var As,xp;function _b(){if(xp)return As;xp=1;var e=L1(),t=Hr();function r(n){return n==null?[]:e(n,t(n))}return As=r,As}var Ts,wp;function xr(){if(wp)return Ts;wp=1;var e;if(typeof zu=="function")try{e={clone:Gw(),constant:Xu(),each:tb(),filter:hb(),has:pb(),isArray:Xe(),isEmpty:g1(),isFunction:tn(),isUndefined:gb(),keys:Hr(),map:mb(),reduce:bb(),size:_1(),transform:S1(),union:$1(),values:_b()}}catch{}return e||(e=window._),Ts=e,Ts}var Os,Cp;function ol(){if(Cp)return Os;Cp=1;var e=xr();Os=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(y){f.length>1?p.setNode(y,d):p.setNode(y)}),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(g,b){l(b)&&d.setNode(b,g)}),e.each(this._edgeObjs,function(g){d.hasNode(g.v)&&d.hasNode(g.w)&&d.setEdge(g,f.edge(g))});var p={};function y(g){var b=f.parent(g);return b===void 0||d.hasNode(b)?(p[g]=b,b):b in p?p[b]:y(b)}return this._isCompound&&e.each(d.nodes(),function(g){d.setParent(g,y(g))}),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(y,g){return p.length>1?f.setEdge(y,g,d):f.setEdge(y,g),g}),this},o.prototype.setEdge=function(){var l,d,f,p,y=!1,g=arguments[0];typeof g=="object"&&g!==null&&"v"in g?(l=g.v,d=g.w,f=g.name,arguments.length===2&&(p=arguments[1],y=!0)):(l=g,d=arguments[1],f=arguments[3],arguments.length>2&&(p=arguments[2],y=!0)),l=""+l,d=""+d,e.isUndefined(f)||(f=""+f);var b=a(this._isDirected,l,d,f);if(e.has(this._edgeLabels,b))return y&&(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]=y?p:this._defaultEdgeLabelFn(l,d,f);var x=c(this._isDirected,l,d,f);return l=x.v,d=x.w,Object.freeze(x),this._edgeObjs[b]=x,i(this._preds[d],l),i(this._sucs[l],d),this._in[d][b]=x,this._out[l][b]=x,this._edgeCount++,this},o.prototype.edge=function(l,d,f){var p=arguments.length===1?u(this._isDirected,arguments[0]):a(this._isDirected,l,d,f);return this._edgeLabels[p]},o.prototype.hasEdge=function(l,d,f){var p=arguments.length===1?u(this._isDirected,arguments[0]):a(this._isDirected,l,d,f);return e.has(this._edgeLabels,p)},o.prototype.removeEdge=function(l,d,f){var p=arguments.length===1?u(this._isDirected,arguments[0]):a(this._isDirected,l,d,f),y=this._edgeObjs[p];return y&&(l=y.v,d=y.w,delete this._edgeLabels[p],delete this._edgeObjs[p],s(this._preds[d],l),s(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(y){return y.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(y){return y.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 s(l,d){--l[d]||delete l[d]}function a(l,d,f,p){var y=""+d,g=""+f;if(!l&&y>g){var b=y;y=g,g=b}return y+n+g+n+(e.isUndefined(p)?t:p)}function c(l,d,f,p){var y=""+d,g=""+f;if(!l&&y>g){var b=y;y=g,g=b}var x={v:y,w:g};return p&&(x.name=p),x}function u(l,d){return a(l,d.v,d.w,d.name)}return Os}var Is,_p;function F1(){return _p||(_p=1,Is="2.1.8"),Is}var Ms,Sp;function B1(){return Sp||(Sp=1,Ms={Graph:ol(),version:F1()}),Ms}var qs,Ep;function D1(){if(Ep)return qs;Ep=1;var e=xr(),t=ol();qs={write:r,read:i};function r(s){var a={options:{directed:s.isDirected(),multigraph:s.isMultigraph(),compound:s.isCompound()},nodes:n(s),edges:o(s)};return e.isUndefined(s.graph())||(a.value=e.clone(s.graph())),a}function n(s){return e.map(s.nodes(),function(a){var c=s.node(a),u=s.parent(a),l={v:a};return e.isUndefined(c)||(l.value=c),e.isUndefined(u)||(l.parent=u),l})}function o(s){return e.map(s.edges(),function(a){var c=s.edge(a),u={v:a.v,w:a.w};return e.isUndefined(a.name)||(u.name=a.name),e.isUndefined(c)||(u.value=c),u})}function i(s){var a=new t(s.options).setGraph(s.value);return e.each(s.nodes,function(c){a.setNode(c.v,c.value),c.parent&&a.setParent(c.v,c.parent)}),e.each(s.edges,function(c){a.setEdge({v:c.v,w:c.w,name:c.name},c.value)}),a}return qs}var Ns,jp;function z1(){if(jp)return Ns;jp=1;var e=xr();Ns=t;function t(r){var n={},o=[],i;function s(a){e.has(n,a)||(n[a]=!0,i.push(a),e.each(r.successors(a),s),e.each(r.predecessors(a),s))}return e.each(r.nodes(),function(a){i=[],s(a),i.length&&o.push(i)}),o}return Ns}var $s,Rp;function Sb(){if(Rp)return $s;Rp=1;var e=xr();$s=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,s=i.length;return o[r]=s,i.push({key:r,priority:n}),this._decrease(s),!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,s=r;o<n.length&&(s=n[o].priority<n[s].priority?o:s,i<n.length&&(s=n[i].priority<n[s].priority?i:s),s!==r&&(this._swap(r,s),this._heapify(s)))},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,s=o[r],a=o[n];o[r]=a,o[n]=s,i[a.key]=r,i[s.key]=n},$s}var Ls,kp;function Eb(){if(kp)return Ls;kp=1;var e=xr(),t=Sb();Ls=n;var r=e.constant(1);function n(i,s,a,c){return o(i,String(s),a||r,c||function(u){return i.outEdges(u)})}function o(i,s,a,c){var u={},l=new t,d,f,p=function(y){var g=y.v!==d?y.v:y.w,b=u[g],x=a(y),m=f.distance+x;if(x<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+y+" Weight: "+x);m<b.distance&&(b.distance=m,b.predecessor=d,l.decrease(g,m))};for(i.nodes().forEach(function(y){var g=y===s?0:Number.POSITIVE_INFINITY;u[y]={distance:g},l.add(y,g)});l.size()>0&&(d=l.removeMin(),f=u[d],f.distance!==Number.POSITIVE_INFINITY);)c(d).forEach(p);return u}return Ls}var Fs,Pp;function V1(){if(Pp)return Fs;Pp=1;var e=Eb(),t=xr();Fs=r;function r(n,o,i){return t.transform(n.nodes(),function(s,a){s[a]=e(n,a,o,i)},{})}return Fs}var Bs,Ap;function jb(){if(Ap)return Bs;Ap=1;var e=xr();Bs=t;function t(r){var n=0,o=[],i={},s=[];function a(c){var u=i[c]={onStack:!0,lowlink:n,index:n++};if(o.push(c),r.successors(c).forEach(function(f){e.has(i,f)?i[f].onStack&&(u.lowlink=Math.min(u.lowlink,i[f].index)):(a(f),u.lowlink=Math.min(u.lowlink,i[f].lowlink))}),u.lowlink===u.index){var l=[],d;do d=o.pop(),i[d].onStack=!1,l.push(d);while(c!==d);s.push(l)}}return r.nodes().forEach(function(c){e.has(i,c)||a(c)}),s}return Bs}var Ds,Tp;function W1(){if(Tp)return Ds;Tp=1;var e=xr(),t=jb();Ds=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 Ds}var zs,Op;function G1(){if(Op)return zs;Op=1;var e=xr();zs=r;var t=e.constant(1);function r(o,i,s){return n(o,i||t,s||function(a){return o.outEdges(a)})}function n(o,i,s){var a={},c=o.nodes();return c.forEach(function(u){a[u]={},a[u][u]={distance:0},c.forEach(function(l){u!==l&&(a[u][l]={distance:Number.POSITIVE_INFINITY})}),s(u).forEach(function(l){var d=l.v===u?l.w:l.v,f=i(l);a[u][d]={distance:f,predecessor:u}})}),c.forEach(function(u){var l=a[u];c.forEach(function(d){var f=a[d];c.forEach(function(p){var y=f[u],g=l[p],b=f[p],x=y.distance+g.distance;x<b.distance&&(b.distance=x,b.predecessor=g.predecessor)})})}),a}return zs}var Vs,Ip;function Rb(){if(Ip)return Vs;Ip=1;var e=xr();Vs=t,t.CycleException=r;function t(n){var o={},i={},s=[];function a(c){if(e.has(i,c))throw new r;e.has(o,c)||(i[c]=!0,o[c]=!0,e.each(n.predecessors(c),a),delete i[c],s.push(c))}if(e.each(n.sinks(),a),e.size(o)!==n.nodeCount())throw new r;return s}function r(){}return r.prototype=new Error,Vs}var Ws,Mp;function U1(){if(Mp)return Ws;Mp=1;var e=Rb();Ws=t;function t(r){try{e(r)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Ws}var Gs,qp;function kb(){if(qp)return Gs;qp=1;var e=xr();Gs=t;function t(n,o,i){e.isArray(o)||(o=[o]);var s=(n.isDirected()?n.successors:n.neighbors).bind(n),a=[],c={};return e.each(o,function(u){if(!n.hasNode(u))throw new Error("Graph does not have node: "+u);r(n,u,i==="post",c,s,a)}),a}function r(n,o,i,s,a,c){e.has(s,o)||(s[o]=!0,i||c.push(o),e.each(a(o),function(u){r(n,u,i,s,a,c)}),i&&c.push(o))}return Gs}var Us,Np;function H1(){if(Np)return Us;Np=1;var e=kb();Us=t;function t(r,n){return e(r,n,"post")}return Us}var Hs,$p;function K1(){if($p)return Hs;$p=1;var e=kb();Hs=t;function t(r,n){return e(r,n,"pre")}return Hs}var Ks,Lp;function J1(){if(Lp)return Ks;Lp=1;var e=xr(),t=ol(),r=Sb();Ks=n;function n(o,i){var s=new t,a={},c=new r,u;function l(f){var p=f.v===u?f.w:f.v,y=c.priority(p);if(y!==void 0){var g=i(f);g<y&&(a[p]=u,c.decrease(p,g))}}if(o.nodeCount()===0)return s;e.each(o.nodes(),function(f){c.add(f,Number.POSITIVE_INFINITY),s.setNode(f)}),c.decrease(o.nodes()[0],0);for(var d=!1;c.size()>0;){if(u=c.removeMin(),e.has(a,u))s.setEdge(u,a[u]);else{if(d)throw new Error("Input graph is not connected: "+o);d=!0}o.nodeEdges(u).forEach(l)}return s}return Ks}var Js,Fp;function Z1(){return Fp||(Fp=1,Js={components:z1(),dijkstra:Eb(),dijkstraAll:V1(),findCycles:W1(),floydWarshall:G1(),isAcyclic:U1(),postorder:H1(),preorder:K1(),prim:J1(),tarjan:jb(),topsort:Rb()}),Js}var Zs,Bp;function Y1(){if(Bp)return Zs;Bp=1;var e=B1();return Zs={Graph:e.Graph,json:D1(),alg:Z1(),version:e.version},Zs}var Ys,Dp;function Cr(){if(Dp)return Ys;Dp=1;var e;if(typeof zu=="function")try{e=Y1()}catch{}return e||(e=window.graphlib),Ys=e,Ys}var Xs,zp;function X1(){if(zp)return Xs;zp=1;var e=Qm(),t=1,r=4;function n(o){return e(o,t|r)}return Xs=n,Xs}var Qs,Vp;function Wn(){if(Vp)return Qs;Vp=1;var e=wt(),t=qr(),r=qn(),n=vr();function o(i,s,a){if(!n(a))return!1;var c=typeof s;return(c=="number"?t(a)&&r(s,a.length):c=="string"&&s in a)?e(a[s],i):!1}return Qs=o,Qs}var ec,Wp;function Q1(){if(Wp)return ec;Wp=1;var e=Vn(),t=wt(),r=Wn(),n=at(),o=Object.prototype,i=o.hasOwnProperty,s=e(function(a,c){a=Object(a);var u=-1,l=c.length,d=l>2?c[2]:void 0;for(d&&r(c[0],c[1],d)&&(l=1);++u<l;)for(var f=c[u],p=n(f),y=-1,g=p.length;++y<g;){var b=p[y],x=a[b];(x===void 0||t(x,o[b])&&!i.call(a,b))&&(a[b]=f[b])}return a});return ec=s,ec}var rc,Gp;function eC(){if(Gp)return rc;Gp=1;var e=Nr(),t=qr(),r=Hr();function n(o){return function(i,s,a){var c=Object(i);if(!t(i)){var u=e(s,3);i=r(i),s=function(d){return u(c[d],d,c)}}var l=o(i,s,a);return l>-1?c[u?i[l]:l]:void 0}}return rc=n,rc}var tc,Up;function rC(){if(Up)return tc;Up=1;var e=/\s/;function t(r){for(var n=r.length;n--&&e.test(r.charAt(n)););return n}return tc=t,tc}var nc,Hp;function tC(){if(Hp)return nc;Hp=1;var e=rC(),t=/^\s+/;function r(n){return n&&n.slice(0,e(n)+1).replace(t,"")}return nc=r,nc}var oc,Kp;function nC(){if(Kp)return oc;Kp=1;var e=tC(),t=vr(),r=Et(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,s=/^0o[0-7]+$/i,a=parseInt;function c(u){if(typeof u=="number")return u;if(r(u))return n;if(t(u)){var l=typeof u.valueOf=="function"?u.valueOf():u;u=t(l)?l+"":l}if(typeof u!="string")return u===0?u:+u;u=e(u);var d=i.test(u);return d||s.test(u)?a(u.slice(2),d?2:8):o.test(u)?n:+u}return oc=c,oc}var ic,Jp;function Pb(){if(Jp)return ic;Jp=1;var e=nC(),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 ic=n,ic}var ac,Zp;function oC(){if(Zp)return ac;Zp=1;var e=Pb();function t(r){var n=e(r),o=n%1;return n===n?o?n-o:n:0}return ac=t,ac}var sc,Yp;function iC(){if(Yp)return sc;Yp=1;var e=wb(),t=Nr(),r=oC(),n=Math.max;function o(i,s,a){var c=i==null?0:i.length;if(!c)return-1;var u=a==null?0:r(a);return u<0&&(u=n(c+u,0)),e(i,t(s,3),u)}return sc=o,sc}var cc,Xp;function aC(){if(Xp)return cc;Xp=1;var e=eC(),t=iC(),r=e(t);return cc=r,cc}var uc,Qp;function Ab(){if(Qp)return uc;Qp=1;var e=nl();function t(r){var n=r==null?0:r.length;return n?e(r,1):[]}return uc=t,uc}var lc,eg;function sC(){if(eg)return lc;eg=1;var e=Qu(),t=eb(),r=at();function n(o,i){return o==null?o:e(o,t(i),r)}return lc=n,lc}var dc,rg;function cC(){if(rg)return dc;rg=1;function e(t){var r=t==null?0:t.length;return r?t[r-1]:void 0}return dc=e,dc}var fc,tg;function uC(){if(tg)return fc;tg=1;var e=In(),t=el(),r=Nr();function n(o,i){var s={};return i=r(i,3),t(o,function(a,c,u){e(s,c,i(a,c,u))}),s}return fc=n,fc}var hc,ng;function il(){if(ng)return hc;ng=1;var e=Et();function t(r,n,o){for(var i=-1,s=r.length;++i<s;){var a=r[i],c=n(a);if(c!=null&&(u===void 0?c===c&&!e(c):o(c,u)))var u=c,l=a}return l}return hc=t,hc}var pc,og;function lC(){if(og)return pc;og=1;function e(t,r){return t>r}return pc=e,pc}var gc,ig;function dC(){if(ig)return gc;ig=1;var e=il(),t=lC(),r=st();function n(o){return o&&o.length?e(o,r,t):void 0}return gc=n,gc}var yc,ag;function Tb(){if(ag)return yc;ag=1;var e=In(),t=wt();function r(n,o,i){(i!==void 0&&!t(n[o],i)||i===void 0&&!(o in n))&&e(n,o,i)}return yc=r,yc}var mc,sg;function fC(){if(sg)return mc;sg=1;var e=ot(),t=Ln(),r=kr(),n="[object Object]",o=Function.prototype,i=Object.prototype,s=o.toString,a=i.hasOwnProperty,c=s.call(Object);function u(l){if(!r(l)||e(l)!=n)return!1;var d=t(l);if(d===null)return!0;var f=a.call(d,"constructor")&&d.constructor;return typeof f=="function"&&f instanceof f&&s.call(f)==c}return mc=u,mc}var bc,cg;function Ob(){if(cg)return bc;cg=1;function e(t,r){if(!(r==="constructor"&&typeof t[r]=="function")&&r!="__proto__")return t[r]}return bc=e,bc}var vc,ug;function hC(){if(ug)return vc;ug=1;var e=nn(),t=at();function r(n){return e(n,t(n))}return vc=r,vc}var xc,lg;function pC(){if(lg)return xc;lg=1;var e=Tb(),t=Dm(),r=Zm(),n=zm(),o=Xm(),i=on(),s=Xe(),a=Cb(),c=_t(),u=tn(),l=vr(),d=fC(),f=an(),p=Ob(),y=hC();function g(b,x,m,w,v,C,_){var R=p(b,m),T=p(x,m),A=_.get(T);if(A){e(b,m,A);return}var k=C?C(R,T,m+"",b,x,_):void 0,j=k===void 0;if(j){var E=s(T),M=!E&&c(T),I=!E&&!M&&f(T);k=T,E||M||I?s(R)?k=R:a(R)?k=n(R):M?(j=!1,k=t(T,!0)):I?(j=!1,k=r(T,!0)):k=[]:d(T)||i(T)?(k=R,i(R)?k=y(R):(!l(R)||u(R))&&(k=o(T))):j=!1}j&&(_.set(T,k),v(k,T,w,C,_),_.delete(T)),e(b,m,k)}return xc=g,xc}var wc,dg;function gC(){if(dg)return wc;dg=1;var e=On(),t=Tb(),r=Qu(),n=pC(),o=vr(),i=at(),s=Ob();function a(c,u,l,d,f){c!==u&&r(u,function(p,y){if(f||(f=new e),o(p))n(c,u,y,l,a,d,f);else{var g=d?d(s(c,y),p,y+"",c,u,f):void 0;g===void 0&&(g=p),t(c,y,g)}},i)}return wc=a,wc}var Cc,fg;function yC(){if(fg)return Cc;fg=1;var e=Vn(),t=Wn();function r(n){return e(function(o,i){var s=-1,a=i.length,c=a>1?i[a-1]:void 0,u=a>2?i[2]:void 0;for(c=n.length>3&&typeof c=="function"?(a--,c):void 0,u&&t(i[0],i[1],u)&&(c=a<3?void 0:c,a=1),o=Object(o);++s<a;){var l=i[s];l&&n(o,l,s,c)}return o})}return Cc=r,Cc}var _c,hg;function mC(){if(hg)return _c;hg=1;var e=gC(),t=yC(),r=t(function(n,o,i){e(n,o,i)});return _c=r,_c}var Sc,pg;function Ib(){if(pg)return Sc;pg=1;function e(t,r){return t<r}return Sc=e,Sc}var Ec,gg;function bC(){if(gg)return Ec;gg=1;var e=il(),t=Ib(),r=st();function n(o){return o&&o.length?e(o,r,t):void 0}return Ec=n,Ec}var jc,yg;function vC(){if(yg)return jc;yg=1;var e=il(),t=Nr(),r=Ib();function n(o,i){return o&&o.length?e(o,t(i,2),r):void 0}return jc=n,jc}var Rc,mg;function xC(){if(mg)return Rc;mg=1;var e=_r(),t=function(){return e.Date.now()};return Rc=t,Rc}var kc,bg;function wC(){if(bg)return kc;bg=1;var e=Mn(),t=Dn(),r=qn(),n=vr(),o=sn();function i(s,a,c,u){if(!n(s))return s;a=t(a,s);for(var l=-1,d=a.length,f=d-1,p=s;p!=null&&++l<d;){var y=o(a[l]),g=c;if(y==="__proto__"||y==="constructor"||y==="prototype")return s;if(l!=f){var b=p[y];g=u?u(b,y,p):void 0,g===void 0&&(g=n(b)?b:r(a[l+1])?[]:{})}e(p,y,g),p=p[y]}return s}return kc=i,kc}var Pc,vg;function CC(){if(vg)return Pc;vg=1;var e=zn(),t=wC(),r=Dn();function n(o,i,s){for(var a=-1,c=i.length,u={};++a<c;){var l=i[a],d=e(o,l);s(d,l)&&t(u,r(l,o),d)}return u}return Pc=n,Pc}var Ac,xg;function _C(){if(xg)return Ac;xg=1;var e=CC(),t=db();function r(n,o){return e(n,o,function(i,s){return t(n,s)})}return Ac=r,Ac}var Tc,wg;function SC(){if(wg)return Tc;wg=1;var e=Ab(),t=vb(),r=xb();function n(o){return r(t(o,void 0,e),o+"")}return Tc=n,Tc}var Oc,Cg;function EC(){if(Cg)return Oc;Cg=1;var e=_C(),t=SC(),r=t(function(n,o){return n==null?{}:e(n,o)});return Oc=r,Oc}var Ic,_g;function jC(){if(_g)return Ic;_g=1;var e=Math.ceil,t=Math.max;function r(n,o,i,s){for(var a=-1,c=t(e((o-n)/(i||1)),0),u=Array(c);c--;)u[s?c:++a]=n,n+=i;return u}return Ic=r,Ic}var Mc,Sg;function RC(){if(Sg)return Mc;Sg=1;var e=jC(),t=Wn(),r=Pb();function n(o){return function(i,s,a){return a&&typeof a!="number"&&t(i,s,a)&&(s=a=void 0),i=r(i),s===void 0?(s=i,i=0):s=r(s),a=a===void 0?i<s?1:-1:r(a),e(i,s,a,o)}}return Mc=n,Mc}var qc,Eg;function kC(){if(Eg)return qc;Eg=1;var e=RC(),t=e();return qc=t,qc}var Nc,jg;function PC(){if(jg)return Nc;jg=1;function e(t,r){var n=t.length;for(t.sort(r);n--;)t[n]=t[n].value;return t}return Nc=e,Nc}var $c,Rg;function AC(){if(Rg)return $c;Rg=1;var e=Et();function t(r,n){if(r!==n){var o=r!==void 0,i=r===null,s=r===r,a=e(r),c=n!==void 0,u=n===null,l=n===n,d=e(n);if(!u&&!d&&!a&&r>n||a&&c&&l&&!u&&!d||i&&c&&l||!o&&l||!s)return 1;if(!i&&!a&&!d&&r<n||d&&o&&s&&!i&&!a||u&&o&&s||!c&&s||!l)return-1}return 0}return $c=t,$c}var Lc,kg;function TC(){if(kg)return Lc;kg=1;var e=AC();function t(r,n,o){for(var i=-1,s=r.criteria,a=n.criteria,c=s.length,u=o.length;++i<c;){var l=e(s[i],a[i]);if(l){if(i>=u)return l;var d=o[i];return l*(d=="desc"?-1:1)}}return r.index-n.index}return Lc=t,Lc}var Fc,Pg;function OC(){if(Pg)return Fc;Pg=1;var e=Bn(),t=zn(),r=Nr(),n=yb(),o=PC(),i=Nn(),s=TC(),a=st(),c=Xe();function u(l,d,f){d.length?d=e(d,function(g){return c(g)?function(b){return t(b,g.length===1?g[0]:g)}:g}):d=[a];var p=-1;d=e(d,i(r));var y=n(l,function(g,b,x){var m=e(d,function(w){return w(g)});return{criteria:m,index:++p,value:g}});return o(y,function(g,b){return s(g,b,f)})}return Fc=u,Fc}var Bc,Ag;function IC(){if(Ag)return Bc;Ag=1;var e=nl(),t=OC(),r=Vn(),n=Wn(),o=r(function(i,s){if(i==null)return[];var a=s.length;return a>1&&n(i,s[0],s[1])?s=[]:a>2&&n(s[0],s[1],s[2])&&(s=[s[0]]),t(i,e(s,1),[])});return Bc=o,Bc}var Dc,Tg;function MC(){if(Tg)return Dc;Tg=1;var e=ub(),t=0;function r(n){var o=++t;return e(n)+o}return Dc=r,Dc}var zc,Og;function qC(){if(Og)return zc;Og=1;function e(t,r,n){for(var o=-1,i=t.length,s=r.length,a={};++o<i;){var c=o<s?r[o]:void 0;n(a,t[o],c)}return a}return zc=e,zc}var Vc,Ig;function NC(){if(Ig)return Vc;Ig=1;var e=Mn(),t=qC();function r(n,o){return t(n||[],o||[],e)}return Vc=r,Vc}var Wc,Mg;function Ue(){if(Mg)return Wc;Mg=1;var e;if(typeof zu=="function")try{e={cloneDeep:X1(),constant:Xu(),defaults:Q1(),each:tb(),filter:hb(),find:aC(),flatten:Ab(),forEach:rb(),forIn:sC(),has:pb(),isUndefined:gb(),last:cC(),map:mb(),mapValues:uC(),max:dC(),merge:mC(),min:bC(),minBy:vC(),now:xC(),pick:EC(),range:kC(),reduce:bb(),sortBy:IC(),uniqueId:MC(),values:_b(),zipObject:NC()}}catch{}return e||(e=window._),Wc=e,Wc}var Gc,qg;function $C(){if(qg)return Gc;qg=1,Gc=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 Gc}var Uc,Ng;function LC(){if(Ng)return Uc;Ng=1;var e=Ue(),t=Cr().Graph,r=$C();Uc=o;var n=e.constant(1);function o(u,l){if(u.nodeCount()<=1)return[];var d=a(u,l||n),f=i(d.graph,d.buckets,d.zeroIdx);return e.flatten(e.map(f,function(p){return u.outEdges(p.v,p.w)}),!0)}function i(u,l,d){for(var f=[],p=l[l.length-1],y=l[0],g;u.nodeCount();){for(;g=y.dequeue();)s(u,l,d,g);for(;g=p.dequeue();)s(u,l,d,g);if(u.nodeCount()){for(var b=l.length-2;b>0;--b)if(g=l[b].dequeue(),g){f=f.concat(s(u,l,d,g,!0));break}}}return f}function s(u,l,d,f,p){var y=p?[]:void 0;return e.forEach(u.inEdges(f.v),function(g){var b=u.edge(g),x=u.node(g.v);p&&y.push({v:g.v,w:g.w}),x.out-=b,c(l,d,x)}),e.forEach(u.outEdges(f.v),function(g){var b=u.edge(g),x=g.w,m=u.node(x);m.in-=b,c(l,d,m)}),u.removeNode(f.v),y}function a(u,l){var d=new t,f=0,p=0;e.forEach(u.nodes(),function(b){d.setNode(b,{v:b,in:0,out:0})}),e.forEach(u.edges(),function(b){var x=d.edge(b.v,b.w)||0,m=l(b),w=x+m;d.setEdge(b.v,b.w,w),p=Math.max(p,d.node(b.v).out+=m),f=Math.max(f,d.node(b.w).in+=m)});var y=e.range(p+f+3).map(function(){return new r}),g=f+1;return e.forEach(d.nodes(),function(b){c(y,g,d.node(b))}),{graph:d,buckets:y,zeroIdx:g}}function c(u,l,d){d.out?d.in?u[d.out-d.in+l].enqueue(d):u[u.length-1].enqueue(d):u[0].enqueue(d)}return Uc}var Hc,$g;function FC(){if($g)return Hc;$g=1;var e=Ue(),t=LC();Hc={run:r,undo:o};function r(i){var s=i.graph().acyclicer==="greedy"?t(i,a(i)):n(i);e.forEach(s,function(c){var u=i.edge(c);i.removeEdge(c),u.forwardName=c.name,u.reversed=!0,i.setEdge(c.w,c.v,u,e.uniqueId("rev"))});function a(c){return function(u){return c.edge(u).weight}}}function n(i){var s=[],a={},c={};function u(l){e.has(c,l)||(c[l]=!0,a[l]=!0,e.forEach(i.outEdges(l),function(d){e.has(a,d.w)?s.push(d):u(d.w)}),delete a[l])}return e.forEach(i.nodes(),u),s}function o(i){e.forEach(i.edges(),function(s){var a=i.edge(s);if(a.reversed){i.removeEdge(s);var c=a.forwardName;delete a.reversed,delete a.forwardName,i.setEdge(s.w,s.v,a,c)}})}return Hc}var Kc,Lg;function hr(){if(Lg)return Kc;Lg=1;var e=Ue(),t=Cr().Graph;Kc={addDummyNode:r,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:s,intersectRect:a,buildLayerMatrix:c,normalizeRanks:u,removeEmptyRanks:l,addBorderNode:d,maxRank:f,partition:p,time:y,notime:g};function r(b,x,m,w){var v;do v=e.uniqueId(w);while(b.hasNode(v));return m.dummy=x,b.setNode(v,m),v}function n(b){var x=new t().setGraph(b.graph());return e.forEach(b.nodes(),function(m){x.setNode(m,b.node(m))}),e.forEach(b.edges(),function(m){var w=x.edge(m.v,m.w)||{weight:0,minlen:1},v=b.edge(m);x.setEdge(m.v,m.w,{weight:w.weight+v.weight,minlen:Math.max(w.minlen,v.minlen)})}),x}function o(b){var x=new t({multigraph:b.isMultigraph()}).setGraph(b.graph());return e.forEach(b.nodes(),function(m){b.children(m).length||x.setNode(m,b.node(m))}),e.forEach(b.edges(),function(m){x.setEdge(m,b.edge(m))}),x}function i(b){var x=e.map(b.nodes(),function(m){var w={};return e.forEach(b.outEdges(m),function(v){w[v.w]=(w[v.w]||0)+b.edge(v).weight}),w});return e.zipObject(b.nodes(),x)}function s(b){var x=e.map(b.nodes(),function(m){var w={};return e.forEach(b.inEdges(m),function(v){w[v.v]=(w[v.v]||0)+b.edge(v).weight}),w});return e.zipObject(b.nodes(),x)}function a(b,x){var m=b.x,w=b.y,v=x.x-m,C=x.y-w,_=b.width/2,R=b.height/2;if(!v&&!C)throw new Error("Not possible to find intersection inside of the rectangle");var T,A;return Math.abs(C)*_>Math.abs(v)*R?(C<0&&(R=-R),T=R*v/C,A=R):(v<0&&(_=-_),T=_,A=_*C/v),{x:m+T,y:w+A}}function c(b){var x=e.map(e.range(f(b)+1),function(){return[]});return e.forEach(b.nodes(),function(m){var w=b.node(m),v=w.rank;e.isUndefined(v)||(x[v][w.order]=m)}),x}function u(b){var x=e.min(e.map(b.nodes(),function(m){return b.node(m).rank}));e.forEach(b.nodes(),function(m){var w=b.node(m);e.has(w,"rank")&&(w.rank-=x)})}function l(b){var x=e.min(e.map(b.nodes(),function(C){return b.node(C).rank})),m=[];e.forEach(b.nodes(),function(C){var _=b.node(C).rank-x;m[_]||(m[_]=[]),m[_].push(C)});var w=0,v=b.graph().nodeRankFactor;e.forEach(m,function(C,_){e.isUndefined(C)&&_%v!==0?--w:w&&e.forEach(C,function(R){b.node(R).rank+=w})})}function d(b,x,m,w){var v={width:0,height:0};return arguments.length>=4&&(v.rank=m,v.order=w),r(b,"border",v,x)}function f(b){return e.max(e.map(b.nodes(),function(x){var m=b.node(x).rank;if(!e.isUndefined(m))return m}))}function p(b,x){var m={lhs:[],rhs:[]};return e.forEach(b,function(w){x(w)?m.lhs.push(w):m.rhs.push(w)}),m}function y(b,x){var m=e.now();try{return x()}finally{console.log(b+" time: "+(e.now()-m)+"ms")}}function g(b,x){return x()}return Kc}var Jc,Fg;function BC(){if(Fg)return Jc;Fg=1;var e=Ue(),t=hr();Jc={run:r,undo:o};function r(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(s){n(i,s)})}function n(i,s){var a=s.v,c=i.node(a).rank,u=s.w,l=i.node(u).rank,d=s.name,f=i.edge(s),p=f.labelRank;if(l!==c+1){i.removeEdge(s);var y,g,b;for(b=0,++c;c<l;++b,++c)f.points=[],g={width:0,height:0,edgeLabel:f,edgeObj:s,rank:c},y=t.addDummyNode(i,"edge",g,"_d"),c===p&&(g.width=f.width,g.height=f.height,g.dummy="edge-label",g.labelpos=f.labelpos),i.setEdge(a,y,{weight:f.weight},d),b===0&&i.graph().dummyChains.push(y),a=y;i.setEdge(a,u,{weight:f.weight},d)}}function o(i){e.forEach(i.graph().dummyChains,function(s){var a=i.node(s),c=a.edgeLabel,u;for(i.setEdge(a.edgeObj,c);a.dummy;)u=i.successors(s)[0],i.removeNode(s),c.points.push({x:a.x,y:a.y}),a.dummy==="edge-label"&&(c.x=a.x,c.y=a.y,c.width=a.width,c.height=a.height),s=u,a=i.node(s)})}return Jc}var Zc,Bg;function vn(){if(Bg)return Zc;Bg=1;var e=Ue();Zc={longestPath:t,slack:r};function t(n){var o={};function i(s){var a=n.node(s);if(e.has(o,s))return a.rank;o[s]=!0;var c=e.min(e.map(n.outEdges(s),function(u){return i(u.w)-n.edge(u).minlen}));return(c===Number.POSITIVE_INFINITY||c===void 0||c===null)&&(c=0),a.rank=c}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 Zc}var Yc,Dg;function Mb(){if(Dg)return Yc;Dg=1;var e=Ue(),t=Cr().Graph,r=vn().slack;Yc=n;function n(a){var c=new t({directed:!1}),u=a.nodes()[0],l=a.nodeCount();c.setNode(u,{});for(var d,f;o(c,a)<l;)d=i(c,a),f=c.hasNode(d.v)?r(a,d):-r(a,d),s(c,a,f);return c}function o(a,c){function u(l){e.forEach(c.nodeEdges(l),function(d){var f=d.v,p=l===f?d.w:f;!a.hasNode(p)&&!r(c,d)&&(a.setNode(p,{}),a.setEdge(l,p,{}),u(p))})}return e.forEach(a.nodes(),u),a.nodeCount()}function i(a,c){return e.minBy(c.edges(),function(u){if(a.hasNode(u.v)!==a.hasNode(u.w))return r(c,u)})}function s(a,c,u){e.forEach(a.nodes(),function(l){c.node(l).rank+=u})}return Yc}var Xc,zg;function DC(){if(zg)return Xc;zg=1;var e=Ue(),t=Mb(),r=vn().slack,n=vn().longestPath,o=Cr().alg.preorder,i=Cr().alg.postorder,s=hr().simplify;Xc=a,a.initLowLimValues=d,a.initCutValues=c,a.calcCutValue=l,a.leaveEdge=p,a.enterEdge=y,a.exchangeEdges=g;function a(w){w=s(w),n(w);var v=t(w);d(v),c(v,w);for(var C,_;C=p(v);)_=y(v,w,C),g(v,w,C,_)}function c(w,v){var C=i(w,w.nodes());C=C.slice(0,C.length-1),e.forEach(C,function(_){u(w,v,_)})}function u(w,v,C){var _=w.node(C),R=_.parent;w.edge(C,R).cutvalue=l(w,v,C)}function l(w,v,C){var _=w.node(C),R=_.parent,T=!0,A=v.edge(C,R),k=0;return A||(T=!1,A=v.edge(R,C)),k=A.weight,e.forEach(v.nodeEdges(C),function(j){var E=j.v===C,M=E?j.w:j.v;if(M!==R){var I=E===T,N=v.edge(j).weight;if(k+=I?N:-N,x(w,C,M)){var O=w.edge(C,M).cutvalue;k+=I?-O:O}}}),k}function d(w,v){arguments.length<2&&(v=w.nodes()[0]),f(w,{},1,v)}function f(w,v,C,_,R){var T=C,A=w.node(_);return v[_]=!0,e.forEach(w.neighbors(_),function(k){e.has(v,k)||(C=f(w,v,C,k,_))}),A.low=T,A.lim=C++,R?A.parent=R:delete A.parent,C}function p(w){return e.find(w.edges(),function(v){return w.edge(v).cutvalue<0})}function y(w,v,C){var _=C.v,R=C.w;v.hasEdge(_,R)||(_=C.w,R=C.v);var T=w.node(_),A=w.node(R),k=T,j=!1;T.lim>A.lim&&(k=A,j=!0);var E=e.filter(v.edges(),function(M){return j===m(w,w.node(M.v),k)&&j!==m(w,w.node(M.w),k)});return e.minBy(E,function(M){return r(v,M)})}function g(w,v,C,_){var R=C.v,T=C.w;w.removeEdge(R,T),w.setEdge(_.v,_.w,{}),d(w),c(w,v),b(w,v)}function b(w,v){var C=e.find(w.nodes(),function(R){return!v.node(R).parent}),_=o(w,C);_=_.slice(1),e.forEach(_,function(R){var T=w.node(R).parent,A=v.edge(R,T),k=!1;A||(A=v.edge(T,R),k=!0),v.node(R).rank=v.node(T).rank+(k?A.minlen:-A.minlen)})}function x(w,v,C){return w.hasEdge(v,C)}function m(w,v,C){return C.low<=v.lim&&v.lim<=C.lim}return Xc}var Qc,Vg;function zC(){if(Vg)return Qc;Vg=1;var e=vn(),t=e.longestPath,r=Mb(),n=DC();Qc=o;function o(c){switch(c.graph().ranker){case"network-simplex":a(c);break;case"tight-tree":s(c);break;case"longest-path":i(c);break;default:a(c)}}var i=t;function s(c){t(c),r(c)}function a(c){n(c)}return Qc}var eu,Wg;function VC(){if(Wg)return eu;Wg=1;var e=Ue();eu=t;function t(o){var i=n(o);e.forEach(o.graph().dummyChains,function(s){for(var a=o.node(s),c=a.edgeObj,u=r(o,i,c.v,c.w),l=u.path,d=u.lca,f=0,p=l[f],y=!0;s!==c.w;){if(a=o.node(s),y){for(;(p=l[f])!==d&&o.node(p).maxRank<a.rank;)f++;p===d&&(y=!1)}if(!y){for(;f<l.length-1&&o.node(p=l[f+1]).minRank<=a.rank;)f++;p=l[f]}o.setParent(s,p),s=o.successors(s)[0]}})}function r(o,i,s,a){var c=[],u=[],l=Math.min(i[s].low,i[a].low),d=Math.max(i[s].lim,i[a].lim),f,p;f=s;do f=o.parent(f),c.push(f);while(f&&(i[f].low>l||d>i[f].lim));for(p=f,f=a;(f=o.parent(f))!==p;)u.push(f);return{path:c.concat(u.reverse()),lca:p}}function n(o){var i={},s=0;function a(c){var u=s;e.forEach(o.children(c),a),i[c]={low:u,lim:s++}}return e.forEach(o.children(),a),i}return eu}var ru,Gg;function WC(){if(Gg)return ru;Gg=1;var e=Ue(),t=hr();ru={run:r,cleanup:s};function r(a){var c=t.addDummyNode(a,"root",{},"_root"),u=o(a),l=e.max(e.values(u))-1,d=2*l+1;a.graph().nestingRoot=c,e.forEach(a.edges(),function(p){a.edge(p).minlen*=d});var f=i(a)+1;e.forEach(a.children(),function(p){n(a,c,d,f,l,u,p)}),a.graph().nodeRankFactor=d}function n(a,c,u,l,d,f,p){var y=a.children(p);if(!y.length){p!==c&&a.setEdge(c,p,{weight:0,minlen:u});return}var g=t.addBorderNode(a,"_bt"),b=t.addBorderNode(a,"_bb"),x=a.node(p);a.setParent(g,p),x.borderTop=g,a.setParent(b,p),x.borderBottom=b,e.forEach(y,function(m){n(a,c,u,l,d,f,m);var w=a.node(m),v=w.borderTop?w.borderTop:m,C=w.borderBottom?w.borderBottom:m,_=w.borderTop?l:2*l,R=v!==C?1:d-f[p]+1;a.setEdge(g,v,{weight:_,minlen:R,nestingEdge:!0}),a.setEdge(C,b,{weight:_,minlen:R,nestingEdge:!0})}),a.parent(p)||a.setEdge(c,g,{weight:0,minlen:d+f[p]})}function o(a){var c={};function u(l,d){var f=a.children(l);f&&f.length&&e.forEach(f,function(p){u(p,d+1)}),c[l]=d}return e.forEach(a.children(),function(l){u(l,1)}),c}function i(a){return e.reduce(a.edges(),function(c,u){return c+a.edge(u).weight},0)}function s(a){var c=a.graph();a.removeNode(c.nestingRoot),delete c.nestingRoot,e.forEach(a.edges(),function(u){var l=a.edge(u);l.nestingEdge&&a.removeEdge(u)})}return ru}var tu,Ug;function GC(){if(Ug)return tu;Ug=1;var e=Ue(),t=hr();tu=r;function r(o){function i(s){var a=o.children(s),c=o.node(s);if(a.length&&e.forEach(a,i),e.has(c,"minRank")){c.borderLeft=[],c.borderRight=[];for(var u=c.minRank,l=c.maxRank+1;u<l;++u)n(o,"borderLeft","_bl",s,c,u),n(o,"borderRight","_br",s,c,u)}}e.forEach(o.children(),i)}function n(o,i,s,a,c,u){var l={width:0,height:0,rank:u,borderType:i},d=c[i][u-1],f=t.addDummyNode(o,"border",l,s);c[i][u]=f,o.setParent(f,a),d&&o.setEdge(d,f,{weight:1})}return tu}var nu,Hg;function UC(){if(Hg)return nu;Hg=1;var e=Ue();nu={adjust:t,undo:r};function t(u){var l=u.graph().rankdir.toLowerCase();(l==="lr"||l==="rl")&&n(u)}function r(u){var l=u.graph().rankdir.toLowerCase();(l==="bt"||l==="rl")&&i(u),(l==="lr"||l==="rl")&&(a(u),n(u))}function n(u){e.forEach(u.nodes(),function(l){o(u.node(l))}),e.forEach(u.edges(),function(l){o(u.edge(l))})}function o(u){var l=u.width;u.width=u.height,u.height=l}function i(u){e.forEach(u.nodes(),function(l){s(u.node(l))}),e.forEach(u.edges(),function(l){var d=u.edge(l);e.forEach(d.points,s),e.has(d,"y")&&s(d)})}function s(u){u.y=-u.y}function a(u){e.forEach(u.nodes(),function(l){c(u.node(l))}),e.forEach(u.edges(),function(l){var d=u.edge(l);e.forEach(d.points,c),e.has(d,"x")&&c(d)})}function c(u){var l=u.x;u.x=u.y,u.y=l}return nu}var ou,Kg;function HC(){if(Kg)return ou;Kg=1;var e=Ue();ou=t;function t(r){var n={},o=e.filter(r.nodes(),function(u){return!r.children(u).length}),i=e.max(e.map(o,function(u){return r.node(u).rank})),s=e.map(e.range(i+1),function(){return[]});function a(u){if(!e.has(n,u)){n[u]=!0;var l=r.node(u);s[l.rank].push(u),e.forEach(r.successors(u),a)}}var c=e.sortBy(o,function(u){return r.node(u).rank});return e.forEach(c,a),s}return ou}var iu,Jg;function KC(){if(Jg)return iu;Jg=1;var e=Ue();iu=t;function t(n,o){for(var i=0,s=1;s<o.length;++s)i+=r(n,o[s-1],o[s]);return i}function r(n,o,i){for(var s=e.zipObject(i,e.map(i,function(f,p){return p})),a=e.flatten(e.map(o,function(f){return e.sortBy(e.map(n.outEdges(f),function(p){return{pos:s[p.w],weight:n.edge(p).weight}}),"pos")}),!0),c=1;c<i.length;)c<<=1;var u=2*c-1;c-=1;var l=e.map(new Array(u),function(){return 0}),d=0;return e.forEach(a.forEach(function(f){var p=f.pos+c;l[p]+=f.weight;for(var y=0;p>0;)p%2&&(y+=l[p+1]),p=p-1>>1,l[p]+=f.weight;d+=f.weight*y})),d}return iu}var au,Zg;function JC(){if(Zg)return au;Zg=1;var e=Ue();au=t;function t(r,n){return e.map(n,function(o){var i=r.inEdges(o);if(i.length){var s=e.reduce(i,function(a,c){var u=r.edge(c),l=r.node(c.v);return{sum:a.sum+u.weight*l.order,weight:a.weight+u.weight}},{sum:0,weight:0});return{v:o,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:o}})}return au}var su,Yg;function ZC(){if(Yg)return su;Yg=1;var e=Ue();su=t;function t(o,i){var s={};e.forEach(o,function(c,u){var l=s[c.v]={indegree:0,in:[],out:[],vs:[c.v],i:u};e.isUndefined(c.barycenter)||(l.barycenter=c.barycenter,l.weight=c.weight)}),e.forEach(i.edges(),function(c){var u=s[c.v],l=s[c.w];!e.isUndefined(u)&&!e.isUndefined(l)&&(l.indegree++,u.out.push(s[c.w]))});var a=e.filter(s,function(c){return!c.indegree});return r(a)}function r(o){var i=[];function s(u){return function(l){l.merged||(e.isUndefined(l.barycenter)||e.isUndefined(u.barycenter)||l.barycenter>=u.barycenter)&&n(u,l)}}function a(u){return function(l){l.in.push(u),--l.indegree===0&&o.push(l)}}for(;o.length;){var c=o.pop();i.push(c),e.forEach(c.in.reverse(),s(c)),e.forEach(c.out,a(c))}return e.map(e.filter(i,function(u){return!u.merged}),function(u){return e.pick(u,["vs","i","barycenter","weight"])})}function n(o,i){var s=0,a=0;o.weight&&(s+=o.barycenter*o.weight,a+=o.weight),i.weight&&(s+=i.barycenter*i.weight,a+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=s/a,o.weight=a,o.i=Math.min(i.i,o.i),i.merged=!0}return su}var cu,Xg;function YC(){if(Xg)return cu;Xg=1;var e=Ue(),t=hr();cu=r;function r(i,s){var a=t.partition(i,function(g){return e.has(g,"barycenter")}),c=a.lhs,u=e.sortBy(a.rhs,function(g){return-g.i}),l=[],d=0,f=0,p=0;c.sort(o(!!s)),p=n(l,u,p),e.forEach(c,function(g){p+=g.vs.length,l.push(g.vs),d+=g.barycenter*g.weight,f+=g.weight,p=n(l,u,p)});var y={vs:e.flatten(l,!0)};return f&&(y.barycenter=d/f,y.weight=f),y}function n(i,s,a){for(var c;s.length&&(c=e.last(s)).i<=a;)s.pop(),i.push(c.vs),a++;return a}function o(i){return function(s,a){return s.barycenter<a.barycenter?-1:s.barycenter>a.barycenter?1:i?a.i-s.i:s.i-a.i}}return cu}var uu,Qg;function XC(){if(Qg)return uu;Qg=1;var e=Ue(),t=JC(),r=ZC(),n=YC();uu=o;function o(a,c,u,l){var d=a.children(c),f=a.node(c),p=f?f.borderLeft:void 0,y=f?f.borderRight:void 0,g={};p&&(d=e.filter(d,function(C){return C!==p&&C!==y}));var b=t(a,d);e.forEach(b,function(C){if(a.children(C.v).length){var _=o(a,C.v,u,l);g[C.v]=_,e.has(_,"barycenter")&&s(C,_)}});var x=r(b,u);i(x,g);var m=n(x,l);if(p&&(m.vs=e.flatten([p,m.vs,y],!0),a.predecessors(p).length)){var w=a.node(a.predecessors(p)[0]),v=a.node(a.predecessors(y)[0]);e.has(m,"barycenter")||(m.barycenter=0,m.weight=0),m.barycenter=(m.barycenter*m.weight+w.order+v.order)/(m.weight+2),m.weight+=2}return m}function i(a,c){e.forEach(a,function(u){u.vs=e.flatten(u.vs.map(function(l){return c[l]?c[l].vs:l}),!0)})}function s(a,c){e.isUndefined(a.barycenter)?(a.barycenter=c.barycenter,a.weight=c.weight):(a.barycenter=(a.barycenter*a.weight+c.barycenter*c.weight)/(a.weight+c.weight),a.weight+=c.weight)}return uu}var lu,ey;function QC(){if(ey)return lu;ey=1;var e=Ue(),t=Cr().Graph;lu=r;function r(o,i,s){var a=n(o),c=new t({compound:!0}).setGraph({root:a}).setDefaultNodeLabel(function(u){return o.node(u)});return e.forEach(o.nodes(),function(u){var l=o.node(u),d=o.parent(u);(l.rank===i||l.minRank<=i&&i<=l.maxRank)&&(c.setNode(u),c.setParent(u,d||a),e.forEach(o[s](u),function(f){var p=f.v===u?f.w:f.v,y=c.edge(p,u),g=e.isUndefined(y)?0:y.weight;c.setEdge(p,u,{weight:o.edge(f).weight+g})}),e.has(l,"minRank")&&c.setNode(u,{borderLeft:l.borderLeft[i],borderRight:l.borderRight[i]}))}),c}function n(o){for(var i;o.hasNode(i=e.uniqueId("_root")););return i}return lu}var du,ry;function e_(){if(ry)return du;ry=1;var e=Ue();du=t;function t(r,n,o){var i={},s;e.forEach(o,function(a){for(var c=r.parent(a),u,l;c;){if(u=r.parent(c),u?(l=i[u],i[u]=c):(l=s,s=c),l&&l!==c){n.setEdge(l,c);return}c=u}})}return du}var fu,ty;function r_(){if(ty)return fu;ty=1;var e=Ue(),t=HC(),r=KC(),n=XC(),o=QC(),i=e_(),s=Cr().Graph,a=hr();fu=c;function c(f){var p=a.maxRank(f),y=u(f,e.range(1,p+1),"inEdges"),g=u(f,e.range(p-1,-1,-1),"outEdges"),b=t(f);d(f,b);for(var x=Number.POSITIVE_INFINITY,m,w=0,v=0;v<4;++w,++v){l(w%2?y:g,w%4>=2),b=a.buildLayerMatrix(f);var C=r(f,b);C<x&&(v=0,m=e.cloneDeep(b),x=C)}d(f,m)}function u(f,p,y){return e.map(p,function(g){return o(f,g,y)})}function l(f,p){var y=new s;e.forEach(f,function(g){var b=g.graph().root,x=n(g,b,y,p);e.forEach(x.vs,function(m,w){g.node(m).order=w}),i(g,y,x.vs)})}function d(f,p){e.forEach(p,function(y){e.forEach(y,function(g,b){f.node(g).order=b})})}return fu}var hu,ny;function t_(){if(ny)return hu;ny=1;var e=Ue(),t=Cr().Graph,r=hr();hu={positionX:y,findType1Conflicts:n,findType2Conflicts:o,addConflict:s,hasConflict:a,verticalAlignment:c,horizontalCompaction:u,alignCoordinates:f,findSmallestWidthAlignment:d,balance:p};function n(x,m){var w={};function v(C,_){var R=0,T=0,A=C.length,k=e.last(_);return e.forEach(_,function(j,E){var M=i(x,j),I=M?x.node(M).order:A;(M||j===k)&&(e.forEach(_.slice(T,E+1),function(N){e.forEach(x.predecessors(N),function(O){var W=x.node(O),G=W.order;(G<R||I<G)&&!(W.dummy&&x.node(N).dummy)&&s(w,O,N)})}),T=E+1,R=I)}),_}return e.reduce(m,v),w}function o(x,m){var w={};function v(_,R,T,A,k){var j;e.forEach(e.range(R,T),function(E){j=_[E],x.node(j).dummy&&e.forEach(x.predecessors(j),function(M){var I=x.node(M);I.dummy&&(I.order<A||I.order>k)&&s(w,M,j)})})}function C(_,R){var T=-1,A,k=0;return e.forEach(R,function(j,E){if(x.node(j).dummy==="border"){var M=x.predecessors(j);M.length&&(A=x.node(M[0]).order,v(R,k,E,T,A),k=E,T=A)}v(R,k,R.length,A,_.length)}),R}return e.reduce(m,C),w}function i(x,m){if(x.node(m).dummy)return e.find(x.predecessors(m),function(w){return x.node(w).dummy})}function s(x,m,w){if(m>w){var v=m;m=w,w=v}var C=x[m];C||(x[m]=C={}),C[w]=!0}function a(x,m,w){if(m>w){var v=m;m=w,w=v}return e.has(x[m],w)}function c(x,m,w,v){var C={},_={},R={};return e.forEach(m,function(T){e.forEach(T,function(A,k){C[A]=A,_[A]=A,R[A]=k})}),e.forEach(m,function(T){var A=-1;e.forEach(T,function(k){var j=v(k);if(j.length){j=e.sortBy(j,function(O){return R[O]});for(var E=(j.length-1)/2,M=Math.floor(E),I=Math.ceil(E);M<=I;++M){var N=j[M];_[k]===k&&A<R[N]&&!a(w,k,N)&&(_[N]=k,_[k]=C[k]=C[N],A=R[N])}}})}),{root:C,align:_}}function u(x,m,w,v,C){var _={},R=l(x,m,w,C),T=C?"borderLeft":"borderRight";function A(E,M){for(var I=R.nodes(),N=I.pop(),O={};N;)O[N]?E(N):(O[N]=!0,I.push(N),I=I.concat(M(N))),N=I.pop()}function k(E){_[E]=R.inEdges(E).reduce(function(M,I){return Math.max(M,_[I.v]+R.edge(I))},0)}function j(E){var M=R.outEdges(E).reduce(function(N,O){return Math.min(N,_[O.w]-R.edge(O))},Number.POSITIVE_INFINITY),I=x.node(E);M!==Number.POSITIVE_INFINITY&&I.borderType!==T&&(_[E]=Math.max(_[E],M))}return A(k,R.predecessors.bind(R)),A(j,R.successors.bind(R)),e.forEach(v,function(E){_[E]=_[w[E]]}),_}function l(x,m,w,v){var C=new t,_=x.graph(),R=g(_.nodesep,_.edgesep,v);return e.forEach(m,function(T){var A;e.forEach(T,function(k){var j=w[k];if(C.setNode(j),A){var E=w[A],M=C.edge(E,j);C.setEdge(E,j,Math.max(R(x,k,A),M||0))}A=k})}),C}function d(x,m){return e.minBy(e.values(m),function(w){var v=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY;return e.forIn(w,function(_,R){var T=b(x,R)/2;v=Math.max(_+T,v),C=Math.min(_-T,C)}),v-C})}function f(x,m){var w=e.values(m),v=e.min(w),C=e.max(w);e.forEach(["u","d"],function(_){e.forEach(["l","r"],function(R){var T=_+R,A=x[T],k;if(A!==m){var j=e.values(A);k=R==="l"?v-e.min(j):C-e.max(j),k&&(x[T]=e.mapValues(A,function(E){return E+k}))}})})}function p(x,m){return e.mapValues(x.ul,function(w,v){if(m)return x[m.toLowerCase()][v];var C=e.sortBy(e.map(x,v));return(C[1]+C[2])/2})}function y(x){var m=r.buildLayerMatrix(x),w=e.merge(n(x,m),o(x,m)),v={},C;e.forEach(["u","d"],function(R){C=R==="u"?m:e.values(m).reverse(),e.forEach(["l","r"],function(T){T==="r"&&(C=e.map(C,function(E){return e.values(E).reverse()}));var A=(R==="u"?x.predecessors:x.successors).bind(x),k=c(x,C,w,A),j=u(x,C,k.root,k.align,T==="r");T==="r"&&(j=e.mapValues(j,function(E){return-E})),v[R+T]=j})});var _=d(x,v);return f(v,_),p(v,x.graph().align)}function g(x,m,w){return function(v,C,_){var R=v.node(C),T=v.node(_),A=0,k;if(A+=R.width/2,e.has(R,"labelpos"))switch(R.labelpos.toLowerCase()){case"l":k=-R.width/2;break;case"r":k=R.width/2;break}if(k&&(A+=w?k:-k),k=0,A+=(R.dummy?m:x)/2,A+=(T.dummy?m:x)/2,A+=T.width/2,e.has(T,"labelpos"))switch(T.labelpos.toLowerCase()){case"l":k=T.width/2;break;case"r":k=-T.width/2;break}return k&&(A+=w?k:-k),k=0,A}}function b(x,m){return x.node(m).width}return hu}var pu,oy;function n_(){if(oy)return pu;oy=1;var e=Ue(),t=hr(),r=t_().positionX;pu=n;function n(i){i=t.asNonCompoundGraph(i),o(i),e.forEach(r(i),function(s,a){i.node(a).x=s})}function o(i){var s=t.buildLayerMatrix(i),a=i.graph().ranksep,c=0;e.forEach(s,function(u){var l=e.max(e.map(u,function(d){return i.node(d).height}));e.forEach(u,function(d){i.node(d).y=c+l/2}),c+=l+a})}return pu}var gu,iy;function o_(){if(iy)return gu;iy=1;var e=Ue(),t=FC(),r=BC(),n=zC(),o=hr().normalizeRanks,i=VC(),s=hr().removeEmptyRanks,a=WC(),c=GC(),u=UC(),l=r_(),d=n_(),f=hr(),p=Cr().Graph;gu=y;function y(q,L){var z=L&&L.debugTiming?f.time:f.notime;z("layout",function(){var H=z(" buildLayoutGraph",function(){return A(q)});z(" runLayout",function(){g(H,z)}),z(" updateInputGraph",function(){b(q,H)})})}function g(q,L){L(" makeSpaceForEdgeLabels",function(){k(q)}),L(" removeSelfEdges",function(){ee(q)}),L(" acyclic",function(){t.run(q)}),L(" nestingGraph.run",function(){a.run(q)}),L(" rank",function(){n(f.asNonCompoundGraph(q))}),L(" injectEdgeLabelProxies",function(){j(q)}),L(" removeEmptyRanks",function(){s(q)}),L(" nestingGraph.cleanup",function(){a.cleanup(q)}),L(" normalizeRanks",function(){o(q)}),L(" assignRankMinMax",function(){E(q)}),L(" removeEdgeLabelProxies",function(){M(q)}),L(" normalize.run",function(){r.run(q)}),L(" parentDummyChains",function(){i(q)}),L(" addBorderSegments",function(){c(q)}),L(" order",function(){l(q)}),L(" insertSelfEdges",function(){ne(q)}),L(" adjustCoordinateSystem",function(){u.adjust(q)}),L(" position",function(){d(q)}),L(" positionSelfEdges",function(){ce(q)}),L(" removeBorderNodes",function(){G(q)}),L(" normalize.undo",function(){r.undo(q)}),L(" fixupEdgeLabelCoords",function(){O(q)}),L(" undoCoordinateSystem",function(){u.undo(q)}),L(" translateGraph",function(){I(q)}),L(" assignNodeIntersects",function(){N(q)}),L(" reversePoints",function(){W(q)}),L(" acyclic.undo",function(){t.undo(q)})}function b(q,L){e.forEach(q.nodes(),function(z){var H=q.node(z),X=L.node(z);H&&(H.x=X.x,H.y=X.y,L.children(z).length&&(H.width=X.width,H.height=X.height))}),e.forEach(q.edges(),function(z){var H=q.edge(z),X=L.edge(z);H.points=X.points,e.has(X,"x")&&(H.x=X.x,H.y=X.y)}),q.graph().width=L.graph().width,q.graph().height=L.graph().height}var x=["nodesep","edgesep","ranksep","marginx","marginy"],m={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},w=["acyclicer","ranker","rankdir","align"],v=["width","height"],C={width:0,height:0},_=["minlen","weight","width","height","labeloffset"],R={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},T=["labelpos"];function A(q){var L=new p({multigraph:!0,compound:!0}),z=K(q.graph());return L.setGraph(e.merge({},m,me(z,x),e.pick(z,w))),e.forEach(q.nodes(),function(H){var X=K(q.node(H));L.setNode(H,e.defaults(me(X,v),C)),L.setParent(H,q.parent(H))}),e.forEach(q.edges(),function(H){var X=K(q.edge(H));L.setEdge(H,e.merge({},R,me(X,_),e.pick(X,T)))}),L}function k(q){var L=q.graph();L.ranksep/=2,e.forEach(q.edges(),function(z){var H=q.edge(z);H.minlen*=2,H.labelpos.toLowerCase()!=="c"&&(L.rankdir==="TB"||L.rankdir==="BT"?H.width+=H.labeloffset:H.height+=H.labeloffset)})}function j(q){e.forEach(q.edges(),function(L){var z=q.edge(L);if(z.width&&z.height){var H=q.node(L.v),X=q.node(L.w),le={rank:(X.rank-H.rank)/2+H.rank,e:L};f.addDummyNode(q,"edge-proxy",le,"_ep")}})}function E(q){var L=0;e.forEach(q.nodes(),function(z){var H=q.node(z);H.borderTop&&(H.minRank=q.node(H.borderTop).rank,H.maxRank=q.node(H.borderBottom).rank,L=e.max(L,H.maxRank))}),q.graph().maxRank=L}function M(q){e.forEach(q.nodes(),function(L){var z=q.node(L);z.dummy==="edge-proxy"&&(q.edge(z.e).labelRank=z.rank,q.removeNode(L))})}function I(q){var L=Number.POSITIVE_INFINITY,z=0,H=Number.POSITIVE_INFINITY,X=0,le=q.graph(),J=le.marginx||0,V=le.marginy||0;function Y(te){var de=te.x,ue=te.y,Se=te.width,ye=te.height;L=Math.min(L,de-Se/2),z=Math.max(z,de+Se/2),H=Math.min(H,ue-ye/2),X=Math.max(X,ue+ye/2)}e.forEach(q.nodes(),function(te){Y(q.node(te))}),e.forEach(q.edges(),function(te){var de=q.edge(te);e.has(de,"x")&&Y(de)}),L-=J,H-=V,e.forEach(q.nodes(),function(te){var de=q.node(te);de.x-=L,de.y-=H}),e.forEach(q.edges(),function(te){var de=q.edge(te);e.forEach(de.points,function(ue){ue.x-=L,ue.y-=H}),e.has(de,"x")&&(de.x-=L),e.has(de,"y")&&(de.y-=H)}),le.width=z-L+J,le.height=X-H+V}function N(q){e.forEach(q.edges(),function(L){var z=q.edge(L),H=q.node(L.v),X=q.node(L.w),le,J;z.points?(le=z.points[0],J=z.points[z.points.length-1]):(z.points=[],le=X,J=H),z.points.unshift(f.intersectRect(H,le)),z.points.push(f.intersectRect(X,J))})}function O(q){e.forEach(q.edges(),function(L){var z=q.edge(L);if(e.has(z,"x"))switch((z.labelpos==="l"||z.labelpos==="r")&&(z.width-=z.labeloffset),z.labelpos){case"l":z.x-=z.width/2+z.labeloffset;break;case"r":z.x+=z.width/2+z.labeloffset;break}})}function W(q){e.forEach(q.edges(),function(L){var z=q.edge(L);z.reversed&&z.points.reverse()})}function G(q){e.forEach(q.nodes(),function(L){if(q.children(L).length){var z=q.node(L),H=q.node(z.borderTop),X=q.node(z.borderBottom),le=q.node(e.last(z.borderLeft)),J=q.node(e.last(z.borderRight));z.width=Math.abs(J.x-le.x),z.height=Math.abs(X.y-H.y),z.x=le.x+z.width/2,z.y=H.y+z.height/2}}),e.forEach(q.nodes(),function(L){q.node(L).dummy==="border"&&q.removeNode(L)})}function ee(q){e.forEach(q.edges(),function(L){if(L.v===L.w){var z=q.node(L.v);z.selfEdges||(z.selfEdges=[]),z.selfEdges.push({e:L,label:q.edge(L)}),q.removeEdge(L)}})}function ne(q){var L=f.buildLayerMatrix(q);e.forEach(L,function(z){var H=0;e.forEach(z,function(X,le){var J=q.node(X);J.order=le+H,e.forEach(J.selfEdges,function(V){f.addDummyNode(q,"selfedge",{width:V.label.width,height:V.label.height,rank:J.rank,order:le+ ++H,e:V.e,label:V.label},"_se")}),delete J.selfEdges})})}function ce(q){e.forEach(q.nodes(),function(L){var z=q.node(L);if(z.dummy==="selfedge"){var H=q.node(z.e.v),X=H.x+H.width/2,le=H.y,J=z.x-X,V=H.height/2;q.setEdge(z.e,z.label),q.removeNode(L),z.label.points=[{x:X+2*J/3,y:le-V},{x:X+5*J/6,y:le-V},{x:X+J,y:le},{x:X+5*J/6,y:le+V},{x:X+2*J/3,y:le+V}],z.label.x=z.x,z.label.y=z.y}})}function me(q,L){return e.mapValues(e.pick(q,L),Number)}function K(q){var L={};return e.forEach(q,function(z,H){L[H.toLowerCase()]=z}),L}return gu}var yu,ay;function i_(){if(ay)return yu;ay=1;var e=Ue(),t=hr(),r=Cr().Graph;yu={debugOrdering:n};function n(o){var i=t.buildLayerMatrix(o),s=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(a){s.setNode(a,{label:a}),s.setParent(a,"layer"+o.node(a).rank)}),e.forEach(o.edges(),function(a){s.setEdge(a.v,a.w,{},a.name)}),e.forEach(i,function(a,c){var u="layer"+c;s.setNode(u,{rank:"same"}),e.reduce(a,function(l,d){return s.setEdge(l,d,{style:"invis"}),d})}),s}return yu}var mu,sy;function a_(){return sy||(sy=1,mu="0.8.5"),mu}var bu,cy;function s_(){return cy||(cy=1,bu={graphlib:Cr(),layout:o_(),debug:i_(),util:{time:hr().time,notime:hr().notime},version:a_()}),bu}var c_=s_();const uy=U0(c_);function u_(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 uy.graphlib.Graph({multigraph:!0,compound:!0}),s=r.compactSpacingScale??(r.spacingFactor>0?r.spacingFactor/1.3:1);i.setGraph({rankdir:r.rankDir,nodesep:r.compact?Math.max(r.nodeSep,24*s):r.nodeSep,edgesep:r.compact?Math.min(r.edgeSep,24*s):r.edgeSep,ranksep:r.compact?Math.min(r.rankSep,80*s):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=Im(d.label,d.icon??((l=d.data)==null?void 0:l.icon),r.edgeLabelFontSize),p=r.rankDir==="LR"||r.rankDir==="RL",y=(f.width?f.width+2*Om:0)+(d.connectorClearance??0);i.setEdge(d.source,d.target,{minlen:1,weight:1,...y?{width:p?y:Math.max(1,f.height),height:p?Math.max(1,f.height):y,labelpos:"c"}:{}},d.id)}uy.layout(i);const a=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)&&a.set(d.id,{x:f.x,y:f.y})}const c=r.compact?1:r.spacingFactor;if(c&&c!==1&&a.size){let d=1/0,f=1/0,p=-1/0,y=-1/0;a.forEach(x=>{d=Math.min(d,x.x),f=Math.min(f,x.y),p=Math.max(p,x.x),y=Math.max(y,x.y)});const g=(d+p)/2,b=(f+y)/2;a.forEach((x,m)=>a.set(m,{x:g+(x.x-g)*c,y:b+(x.y-b)*c}))}const u=r.nodeAlignment??"center";if(u!=="center"){const d=r.rankDir==="LR"||r.rankDir==="RL",f=d?"x":"y",p=d?"width":"height",y=r.rankDir==="RL"||r.rankDir==="BT"?-1:1,g=u==="leading"?-y:y,b=new Map;for(const x of e){const m=a.get(x.id);if(!m)continue;const w=m[f];b.set(w,Math.max(b.get(w)??0,x[p]))}for(const x of e){const m=a.get(x.id);if(!m)continue;const w=m[f],v=(b.get(w)-x[p])/2;a.set(x.id,{...m,[f]:w+g*v})}}return a}function l_(e,t,r,n,o){const i=new Map,s=new Map(e.map(l=>[l.id,l]));for(const l of e){if(!l.parent||!s.has(l.parent))continue;const d=i.get(l.parent);d?d.push(l.id):i.set(l.parent,[l.id])}const a=(l,d=new Set)=>{var p;const f=(p=s.get(l))==null?void 0:p.parent;return!f||!s.has(f)||d.has(l)?0:(d.add(l),1+a(f,d))},c=[...i.keys()].sort((l,d)=>a(d)-a(l)),u=new Map;for(const l of c){let d=null;for(const y of i.get(l)||[]){let g=u.get(y);if(!g){const b=t.get(y);if(!b)continue;const x=r.get(y)||{w:60,h:60};g={x1:b.x-x.w/2,y1:b.y-x.h/2,x2:b.x+x.w/2,y2:b.y+x.h/2}}d=d?{x1:Math.min(d.x1,g.x1),y1:Math.min(d.y1,g.y1),x2:Math.max(d.x2,g.x2),y2:Math.max(d.y2,g.y2)}:{...g}}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 y=d.x2-d.x1,g=d.y2-d.y1;if(p.w>y){const b=(p.w-y)/2;d.x1-=b,d.x2+=b}if(p.h>g){const b=(p.h-g)/2;d.y1-=b,d.y2+=b}}u.set(l,d)}return u}function d_(e){const t=e.getBoundingClientRect(),r=t.height/e.offsetHeight;if(!Number.isFinite(r)||r<=0)return[];const n=Am(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],s=new Set(i.filter(a=>a.hasAttribute("data-flow-inspection-row")&&a.getBoundingClientRect().height>0).map(a=>a.dataset.flowProperty));return i.flatMap(a=>{if(a.closest(".flow-sdk-node")!==e)return[];if(s.has(a.dataset.flowProperty)&&!a.hasAttribute("data-flow-inspection-row"))return[];const c=a.dataset.flowPortSide;if(c&&["top","right","bottom","left"].includes(c)){const l=Rm(n?zt(o,n):o,c,Number(a.dataset.flowPortPosition??.5));return[{property:a.getAttribute("data-flow-property"),top:l.y,height:0,anchor:l,...a.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]}const u=a.getBoundingClientRect();return!u.width||!u.height?[]:[{property:a.getAttribute("data-flow-property"),top:Math.round((u.top-t.top)/r*1e3)/1e3,height:Math.round(u.height/r*1e3)/1e3,...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]})}function f_({id:e,x:t,y:r,placed:n,hidden:o,onMount:i,drawHandles:s,drawMode:a,connectedPorts:c,resolvedRows:u,hasCollapseControl:l,handleColor:d,animated:f,animationColor:p,animationWidth:y=8,animationVariant:g,width:b=0,height:x=0,propertyMode:m,reversePorts:w,direction:v="LR",onPropertyRows:C,onSurface:_,children:R}){const T=S.useRef(null),[A,k]=S.useState([]),j=u??A,[E,M]=S.useState();return S.useLayoutEffect(()=>{const I=T.current;if(!I)return;const N=()=>{const G=Am(I);M(ee=>JSON.stringify(ee)===JSON.stringify(G)?ee:G),_==null||_(e,G)};N();const O=new ResizeObserver(N);O.observe(I);const W=I.querySelector("[data-flow-node-surface]");return W&&O.observe(W),()=>O.disconnect()},[e,R,_]),S.useLayoutEffect(()=>(i(e,T.current),()=>{i(e,null),_==null||_(e,void 0)}),[e,i,_]),S.useLayoutEffect(()=>{const I=T.current;if(!I)return;let N="";const O=()=>{const ne=d_(I),ce=m?ne:ne.filter(K=>K.anchor),me=JSON.stringify(ce);me!==N&&(N=me,k(ce),C==null||C(e,ce))};if(O(),!m&&!I.querySelector("[data-flow-port-side]"))return;const W=new ResizeObserver(O),G=()=>{W.disconnect(),W.observe(I),I.querySelectorAll("[data-flow-property]").forEach(ne=>W.observe(ne)),O()};G();const ee=new MutationObserver(G);return ee.observe(I,{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"]}),I.addEventListener("scroll",O,!0),()=>{W.disconnect(),ee.disconnect(),I.removeEventListener("scroll",O,!0)}},[e,m,C,R]),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:[R,f&&y>0&&b>0&&x>0&&h.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:h.jsx(jm,{variant:g,x:((E==null?void 0:E.left)??0)+y/2,y:((E==null?void 0:E.top)??0)+y/2,width:((E==null?void 0:E.width)??b)-y,height:((E==null?void 0:E.height)??x)-y,radius:((E==null?void 0:E.radius)??0)-y/2,path:E!=null&&E.outline?`M${E.outline.map(I=>`${I.x} ${I.y}`).join(" L")} Z`:void 0,color:p||d||"currentColor",strokeWidth:y})}),s&&m&&j.map(I=>["source","target"].filter(N=>!I.role||I.role===N).filter(N=>a||(c==null?void 0:c.has(`${N}:${I.property}`))).map(N=>{var O;return h.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":I.property,"data-port-role":N,"data-port-side":(O=I.anchor)==null?void 0:O.side,"aria-label":`${N==="source"?"Connect":"Input"} ${I.property}`,title:`${N==="source"?"Connect":"Input"} ${I.property}`,style:{color:d,...I.anchor?{top:I.anchor.y,left:I.anchor.x-16}:{top:I.top+I.height/2,[N==="source"!=!!w?"right":"left"]:-16}},onClick:W=>W.stopPropagation()},`${I.property}:${N}`)})),s&&!l&&(!m||!j.length)&&(!m||!j.some(I=>I.anchor))&&h.jsx("button",{type:"button",className:"flow-sdk-handle","aria-label":"Draw edge",title:"Draw edge",style:{color:d,left:((E==null?void 0:E.left)??0)+(v==="RL"?-36:v==="LR"?(E==null?void 0:E.width)??b:((E==null?void 0:E.width)??b)/2),top:((E==null?void 0:E.top)??0)+(v==="BT"?-36:v==="TB"?(E==null?void 0:E.height)??x:((E==null?void 0:E.height)??x)/2),transform:v==="BT"||v==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:I=>I.stopPropagation(),children:h.jsx(Z.PiPlusBold,{size:24})})]})}const h_=S.memo(f_);function p_(e,t,r){const[n,o]=S.useState(()=>({nodes:new Set,edges:new Set})),i=S.useMemo(()=>{const a=new Set(e.map(p=>p.id)),c=t.filter(p=>a.has(p.source)&&a.has(p.target)).map(p=>({id:p.id,source:p.inverted?p.target:p.source,target:p.inverted?p.source:p.target})),u=new Set(c.map(p=>p.id)),l=new Set([...n.nodes].filter(p=>a.has(p))),d=new Set([...n.edges].filter(p=>u.has(p)));if(!r)return{nodes:a,edges:u,ready:u};for(const p of e)c.filter(g=>g.target===p.id&&g.source!==g.target).every(g=>d.has(g.id))&&l.add(p.id);let f=new Set(c.filter(p=>l.has(p.source)).map(p=>p.id));if(l.size<a.size&&!c.some(p=>f.has(p.id)&&!d.has(p.id))){const p=e.find(y=>!l.has(y.id));p&&l.add(p.id),f=new Set(c.filter(y=>l.has(y.source)).map(y=>y.id))}return{nodes:l,edges:d,ready:f}},[e,t,r,n]);S.useLayoutEffect(()=>{o(a=>{const c=r?i:{nodes:new Set,edges:new Set},u=(l,d)=>l.size===d.size&&[...l].every(f=>d.has(f));return u(a.nodes,c.nodes)&&u(a.edges,c.edges)?a:{nodes:c.nodes,edges:c.edges}})},[i,r]);const s=S.useCallback(a=>{o(c=>c.edges.has(a)?c:{...c,edges:new Set([...c.edges,a])})},[]);return{shown:i.nodes,ready:i.ready,complete:s}}class g_{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(),s=300/1.4,a=()=>{this.cancelAnimation(),this.set(o.pan,o.zoom)},c=u=>{const l=Math.min(1,(u-i)/s);if(l>=1){a();return}const d=l*l*(3-2*l);this.apply({x:n.pan.x+(o.pan.x-n.pan.x)*d,y:n.pan.y+(o.pan.y-n.pan.y)*d},n.zoom+(o.zoom-n.zoom)*d),this.animationFrame=requestAnimationFrame(c)};this.animationFrame=requestAnimationFrame(c),this.animationTimer=setTimeout(a,s+100)}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,o=1){const i=t.x2-t.x1,s=t.y2-t.y1;if(!(i>0)||!(s>0)||!this.size.w||!this.size.h)return;const a=this.clamp(this.clamp(Math.min((this.size.w-2*r)/i,(this.size.h-2*r)/s))*o);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 y_={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},vu={w:60,h:60},ly=4,m_=30,dy=300,b_=500,v_=45,x_=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2;function fy(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 w_(e){var dl;const{nodes:t,edges:r,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:s=!1,rankSep:a,edgeSep:c,spacingFactor:u=1.3,compactSpacingScale:l,minZoom:d,maxZoom:f,initialViewport:p,containerStyle:y,lineColor:g,drawMode:b,dragMode:x,multiSelect:m,isPerformanceMode:w}=e,[v,C]=S.useState(null),_=S.useMemo(()=>v?(v.mode==="connections"?Fl:Il)(v.id,t,r):null,[v,t,r]),R=i==="auto"||i==="properties",T=S.useMemo(()=>r.filter(P=>ju(P,i)&&(!_||_.has(P.source)&&_.has(P.target))),[r,i,_]),A=S.useMemo(()=>B0(t,r,i,s,_),[t,r,i,s,_]),k=S.useRef(A);k.current=A;const j=S.useRef(e);j.current=e;const E=S.useRef(null),M=S.useRef(null),I=S.useRef(null),N=S.useRef(null),O=S.useMemo(()=>new g_(p,d,f),[]);S.useEffect(()=>{O.minZoom=d,O.maxZoom=f},[O,d,f]);const W=S.useRef(new Map),G=S.useRef(new Map),ee=S.useRef(new Map),ne=S.useRef(null),[ce,me]=S.useState(new Map),K=S.useCallback((P,$)=>{me(B=>{if(JSON.stringify(B.get(P))===JSON.stringify($))return B;const U=new Map(B);return $?U.set(P,$):U.delete(P),U})},[]),[q,L]=S.useState(new Map),z=S.useRef(q),H=S.useCallback((P,$)=>{L(B=>{if(JSON.stringify(B.get(P)??[])===JSON.stringify($))return B;const U=new Map(B);return $.length?U.set(P,$):U.delete(P),U})},[]),[X,le]=S.useState(()=>new Map),J=S.useRef(X);J.current=X;const V=S.useRef(new Map),Y=S.useRef(!1),[te,de]=S.useState(0),ue=S.useRef(),Se=S.useRef(),ye=S.useRef(null),De=S.useRef(),Le=S.useRef(!1),He=S.useRef(null),ze=S.useRef(u),Ve=s,Fe=S.useRef(Ve),[Ye,ir]=S.useState(!0),be=S.useRef(null);be.current=_;const Pe=S.useRef(1);Pe.current=(v==null?void 0:v.mode)==="connections"?1.25:1;const We=S.useRef(null),pr=S.useRef(t),er=S.useRef([]),Qe=S.useRef(!1),lr=()=>{ye.current!==null&&cancelAnimationFrame(ye.current),ye.current=null,clearTimeout(De.current)},ar=()=>{er.current.length&&(Qe.current=!0),!Y.current&&j.current.fitOnInit!==!1&&(Le.current=!0),clearTimeout(Se.current),Se.current=setTimeout(()=>{Y.current=!0,de(P=>P+1)},b_)},xe=P=>{lr();const $=new Map(J.current),B=performance.now(),U=()=>{lr(),le(P),ar()},ae=pe=>{const ke=Math.min(1,(pe-B)/dy);if(ke>=1)return U();const Oe=x_(ke),oe=new Map;P.forEach((se,fe)=>{const ge=$.get(fe);oe.set(fe,ge?{x:ge.x+(se.x-ge.x)*Oe,y:ge.y+(se.y-ge.y)*Oe}:se)}),le(oe),ye.current=requestAnimationFrame(ae)};ye.current=requestAnimationFrame(ae),De.current=setTimeout(U,dy+100)},ct=()=>{const P=j.current,$=Pe.current,B=k.current,U=B.nodes.map(pe=>{const ke=W.current.get(pe.id)||vu;return{id:pe.id,parent:pe.parent,width:ke.w,height:ke.h}});let ae;try{const pe=P.compactPropertyLayout,ke=P.edgeMode!=="nodes"&&P.edgeMode!=="workflow",Oe=B.edges.map(oe=>({...oe,connectorClearance:pe?ke&&(oe.sourceProperty!==void 0||oe.targetProperty!==void 0)?F0:L0:0}));ae=u_(U,Oe,{edgeLabelFontSize:P.edgeMode==="nodes"||P.edgeMode==="workflow"?Tm:bn,rankDir:P.direction,compact:pe,nodeAlignment:P.nodeAlignment,rankSep:P.rankSep*$,edgeSep:P.edgeSep*$,nodeSep:5*$,spacingFactor:P.spacingFactor??1.3,compactSpacingScale:(P.compactSpacingScale??(P.spacingFactor??1.3)/1.3)*$})}catch(pe){console.warn("[flow-sdk] layout failed",pe);return}for(const[pe,ke]of V.current)ae.has(pe)?ae.set(pe,ke):P.nodes.some(Oe=>Oe.id===pe)||V.current.delete(pe);Y.current&&!P.isPerformanceMode?xe(ae):(lr(),le(ae),ar())},dr=S.useCallback(()=>{clearTimeout(Se.current),clearTimeout(ue.current),ue.current=setTimeout(ct,j.current.layoutDebounce)},[]);S.useEffect(()=>{const P=new Map(pr.current.map($=>[$.id,$]));t.some($=>{var B;return((B=P.get($.id))==null?void 0:B.collapsed)===!0&&!$.collapsed})&&(er.current=t.filter($=>!P.has($.id)).map($=>$.id)),pr.current=t,ze.current!==u&&J.current.size>0&&(Y.current=!0,Le.current=!1,clearTimeout(Se.current)),ze.current=u,Fe.current!==Ve&&(Le.current=!He.current),Fe.current=Ve,dr()},[t,r,A.nodes,A.edges,Ve,n,o,a,c,dr,u,l]),S.useEffect(()=>()=>{clearTimeout(ue.current),clearTimeout(Se.current),lr()},[]);const jt=S.useCallback((P,$)=>{var B,U;if(!ne.current&&typeof ResizeObserver<"u"&&(ne.current=new ResizeObserver(ae=>{let pe=!1;for(const ke of ae){const Oe=ee.current.get(ke.target);if(!Oe)continue;const oe=ke.target,se=oe.offsetWidth,fe=oe.offsetHeight;if(!se&&!fe)continue;const ge=W.current.get(Oe);ge&&ge.w===se&&ge.h===fe||(W.current.set(Oe,{w:se,h:fe}),pe=!0)}pe&&dr()})),$){G.current.set(P,$),ee.current.set($,P),(B=ne.current)==null||B.observe($);const ae=$.offsetWidth,pe=$.offsetHeight;(ae||pe)&&W.current.set(P,{w:ae,h:pe})}else{const ae=G.current.get(P);ae&&((U=ne.current)==null||U.unobserve(ae),ee.current.delete(ae)),G.current.delete(P),W.current.delete(P),z.current.has(P)&&H(P,[])}dr()},[dr,H]);S.useEffect(()=>()=>{var P;return(P=ne.current)==null?void 0:P.disconnect()},[]);const ie=S.useMemo(()=>{const P=new Map;for(const $ of t)$.label&&P.set($.id,$.label);return P},[t]),Me=S.useMemo(()=>l_(A.nodes,X,W.current,P=>y(P).padding,P=>{const $=ie.get(P);if(!$)return;const B=y(P);return{w:Rn($,`bold ${B.fontSize}px ${nt}`)+2*v_,h:0}}),[A.nodes,X,y,ie]),Ke=S.useRef(Me);Ke.current=Me;const qe=S.useCallback(P=>{const $=Ke.current.get(P);if($)return S0($);const B=J.current.get(P);if(!B)return;const U=W.current.get(P)||vu;return{x:B.x,y:B.y,w:U.w,h:U.h}},[]),cr=S.useMemo(()=>{const P=new Map;for(const $ of t){const B=qe($.id);B&&P.set($.id,B)}return I0(q,P,ce,r,n)},[q,t,X,Me,ce,r,n,qe]);z.current=cr;const Q=(P,$)=>{var ae;if(!R||$===void 0)return;const B=(ae=cr.get(P))==null?void 0:ae.find(pe=>pe.property===$),U=qe(P);return B&&!B.anchor&&U?U.y-U.h/2+B.top+B.height/2:void 0},F=(P,$)=>{var ae,pe;if($===void 0)return;const B=(pe=(ae=cr.get(P))==null?void 0:ae.find(ke=>ke.property===$))==null?void 0:pe.anchor,U=qe(P);return B&&U?{x:U.x-U.w/2+B.x,y:U.y-U.h/2+B.y,side:B.side}:void 0},re=(P,$)=>{const B=qe(P),U=ce.get(P);return B&&U&&!Me.has(P)&&Q(P,$)===void 0?zt(B,U):B},Ce=()=>{const P=[];J.current.forEach(($,B)=>{if(Ke.current.has(B))return;const U=W.current.get(B)||vu;P.push(dt({x:$.x,y:$.y,w:U.w,h:U.h}))}),Ke.current.forEach($=>P.push($));try{for(const $ of[M.current,I.current]){const B=$==null?void 0:$.getBBox();B&&B.width>0&&B.height>0&&P.push({x1:B.x,y1:B.y,x2:B.x+B.width,y2:B.y+B.height})}}catch{}return eo(P)},Ee=()=>{var B,U;const{pan:P,zoom:$}=O;N.current&&(N.current.style.transform=`translate3d(${P.x}px, ${P.y}px, 0) scale(${$})`),(B=M.current)==null||B.setAttribute("transform",`translate(${P.x} ${P.y}) scale(${$})`),(U=I.current)==null||U.setAttribute("transform",`translate(${P.x} ${P.y}) scale(${$})`)};S.useEffect(()=>{Ee();let P=null,$;const B=O.onChange(()=>{Ee();const U=E.current;U&&(U.classList.add("flow-sdk-busy"),clearTimeout($),$=setTimeout(()=>U.classList.remove("flow-sdk-busy"),150)),P===null&&(P=requestAnimationFrame(()=>{var ae,pe;P=null,(pe=(ae=j.current).onViewportChange)==null||pe.call(ae,O.state)}))});return()=>{B(),clearTimeout($),P!==null&&cancelAnimationFrame(P)}},[]),S.useLayoutEffect(()=>{const P=E.current;if(!P)return;const $=()=>{let U=P.clientWidth,ae=P.clientHeight;ae||(ae=Math.max(0,window.innerHeight-P.getBoundingClientRect().top-100),ae&&(P.style.height=`${ae}px`)),U||(U=window.innerWidth,U&&(P.style.width=`${U}px`)),O.size={w:U,h:ae}};if($(),typeof ResizeObserver>"u")return;const B=new ResizeObserver($);return B.observe(P),()=>B.disconnect()},[O]),S.useEffect(()=>{if(Qe.current){Qe.current=!1;const $=er.current.flatMap(U=>{const ae=qe(U);return ae?[dt(ae)]:[]});er.current=[];const B=eo($);if(B){Le.current=!1,O.center(B,j.current.animateViewport);return}}if(!Le.current)return;Le.current=!1;const P=Ce();P&&O.fit(P,50,j.current.animateViewport)},[X]);const _e=S.useMemo(()=>{const P=oe=>Il(oe,j.current.nodes,j.current.edges),$=(oe,se=50,fe=j.current.animateViewport,ge=1)=>{const rr=eo([...oe].flatMap(Jr=>{const Zr=qe(Jr);return Zr?[dt(Zr)]:[]}));rr&&(Le.current=!1,O.fit(rr,Number.isFinite(se)?Math.max(0,se):50,fe,ge))},B=(oe,se,fe,ge)=>{var Jr;if(!qe(oe))return;const rr=se==="connections"?ae(oe):P(oe);if(se==="connections"&&Pe.current===1.25&&((Jr=be.current)==null?void 0:Jr.size)===rr.size&&[...rr].every(Zr=>be.current.has(Zr))){C({id:oe,mode:se});return}We.current||(We.current={pan:{...O.pan},zoom:O.zoom}),be.current=rr,j.current.compactPropertyLayout&&(Le.current=!1,He.current=()=>$(be.current??rr,fe,ge)),C({id:oe,mode:se}),j.current.compactPropertyLayout||$(rr,fe,ge)},U=oe=>{He.current?He.current=oe:oe()},ae=oe=>Fl(oe,j.current.nodes,j.current.edges),pe=(oe=>{if(oe===void 0)return O.zoom;O.set(void 0,oe)}),ke=(oe=>{if(oe===void 0)return O.pan;O.set(oe)}),Oe=(oe,se)=>{var ge;const fe=(ge=E.current)==null?void 0:ge.getBoundingClientRect();return{x:oe-((fe==null?void 0:fe.left)??0),y:se-((fe==null?void 0:fe.top)??0)}};return{zoom:pe,pan:ke,setEdgesVisible:ir,focusNode:(oe,se,fe)=>U(()=>$(new Set([oe]),se,fe,.6)),focusBranch:(oe,se,fe)=>U(()=>$(P(oe),se,fe)),focusConnections:(oe,se,fe)=>U(()=>$(ae(oe),se,fe)),isolateConnections:(oe,se,fe)=>B(oe,"connections",se,fe),isolateBranch:(oe,se,fe)=>B(oe,"branch",se,fe),restoreView:(oe=j.current.animateViewport,se)=>{const fe=j.current.compactPropertyLayout&&!!be.current;be.current=null,C(null);const ge=se??We.current;We.current=null,fe?He.current=()=>{ge&&O.transition(ge,oe)}:ge&&U(()=>O.transition(ge,oe))},zoomAt:(oe,se)=>O.zoomAt(oe,se),fit:(oe=0,se=j.current.animateViewport)=>{U(()=>{const fe=Ce();fe&&O.fit(fe,oe,se)})},centerAndFit:(oe=0,se=j.current.animateViewport)=>{U(()=>{const fe=Ce();fe&&O.fit(fe,oe,se)})},center:(oe=j.current.animateViewport)=>{const se=Ce();se&&O.center(se,oe)},clientToModel:(oe,se)=>O.renderedToModel(Oe(oe,se)),modelToClient:oe=>{var ge;const se=(ge=E.current)==null?void 0:ge.getBoundingClientRect(),fe=O.modelToRendered(oe);return{x:fe.x+((se==null?void 0:se.left)??0),y:fe.y+((se==null?void 0:se.top)??0)}},getNodeBox:oe=>qe(oe),setNodePosition:(oe,se,fe)=>{if(!J.current.has(oe)||se&&(!Number.isFinite(se.x)||!Number.isFinite(se.y)))return!1;if(lr(),!se)return V.current.delete(oe),dr(),!0;const ge=new Map(J.current);return ge.set(oe,{...se}),(fe==null?void 0:fe.persist)===!1?V.current.delete(oe):V.current.set(oe,{...se}),J.current=ge,le(ge),(fe==null?void 0:fe.persist)===!1&&dr(),!0},onViewportChange:oe=>O.onChange(oe)}},[]);S.useEffect(()=>{var P,$;return($=(P=j.current).onInit)==null||$.call(P,_e),()=>O.cancelAnimation()},[_e]),S.useEffect(()=>{var P,$;if(te>0){const B=He.current;He.current=null,B==null||B(),($=(P=j.current).onLayoutComplete)==null||$.call(P,_e)}},[_e,te]);const Ae=S.useRef(null),Ne=S.useRef(new Map),Ge=S.useRef(!1),[Be,Sr]=S.useState(null),[je,gr]=S.useState(null),$r=P=>{const $=E.current.getBoundingClientRect();return{x:P.clientX-$.left,y:P.clientY-$.top}},Pr=(P,$)=>{const B=j.current.nodes;for(let U=B.length-1;U>=0;U--){const ae=B[U].id;if(!ft(ae,j.current.edges,j.current.edgeMode)||be.current&&!be.current.has(ae)||ae===$||Ke.current.has(ae))continue;const pe=qe(ae);if(pe&&Ml(P,dt(pe)))return ae}for(const[U,ae]of Ke.current)if(ft(U,j.current.edges,j.current.edgeMode)&&!(be.current&&!be.current.has(U))&&U!==$&&Ml(P,ae))return U;return null},Lr=(P,$)=>{if(j.current.edgeMode==="nodes"||j.current.edgeMode==="workflow")return null;const B=j.current.direction==="RL",U=Math.max(16,6/O.zoom);let ae=null;for(const pe of[...j.current.nodes].reverse()){if(!ft(pe.id,j.current.edges,j.current.edgeMode)||be.current&&!be.current.has(pe.id))continue;const ke=qe(pe.id),Oe=z.current.get(pe.id);if(!ke||!Oe||Ke.current.has(pe.id))continue;const oe=ke.x+($==="source"!==B?1:-1)*ke.w/2;for(const se of Oe){if(se.role&&se.role!==$)continue;const fe=ke.y-ke.h/2+se.top,ge=Math.hypot(P.x-(se.anchor?ke.x-ke.w/2+se.anchor.x:oe),P.y-fe-se.height/2);if(!se.anchor&&P.x>=ke.x-ke.w/2&&P.x<=ke.x+ke.w/2&&P.y>=fe&&P.y<=fe+se.height)return{nodeId:pe.id,property:se.property};ge<=U&&(!ae||ge<ae.distance)&&(ae={nodeId:pe.id,property:se.property,distance:ge})}}return ae},Wb=P=>{var ke;if(!P.currentTarget.contains(P.target)||P.button!==0||j.current.readOnly)return;Ae.current||(Ge.current=!1);const $=P.target;if($.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const B=j.current,U=$r(P);if(P.pointerType==="touch"){Ne.current.set(P.pointerId,U);const Oe=fy(Ne.current);if(Oe){Ae.current={kind:"pinch",distance:Oe.distance,zoom:O.zoom,anchor:O.renderedToModel(Oe.center)},gr(null),Sr(null),Ge.current=!0;for(const oe of Ne.current.keys())P.currentTarget.setPointerCapture(oe);return}}if(Ae.current)return;const ae=B.drawHandles&&$.closest(".flow-sdk-handle"),pe=B.drawHandles&&$.closest(".flow-sdk-property-port");if(B.drawMode||ae||pe){const Oe=O.renderedToModel(U),oe=B.drawMode?Lr(Oe,"source"):null,se=pe||ae,fe=se?(ke=se.closest("[data-node-id]"))==null?void 0:ke.dataset.nodeId:(oe==null?void 0:oe.nodeId)??Pr(Oe),ge=pe?pe.dataset.property:oe==null?void 0:oe.property;if(fe){Ae.current={kind:"draw",pointerId:P.pointerId,source:fe,sourceProperty:ge,reverse:(pe==null?void 0:pe.dataset.portRole)==="target",startClient:{x:P.clientX,y:P.clientY}},Ge.current=!0,gr({source:fe,sourceProperty:ge,point:Oe,target:null}),P.currentTarget.setPointerCapture(P.pointerId);return}}$.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(B.multiSelect?Ae.current={kind:"box",pointerId:P.pointerId,start:U,current:U}:B.dragMode?Ae.current={kind:"pan",pointerId:P.pointerId,start:U,pan0:O.pan,moved:!1}:Ae.current={kind:"tap",pointerId:P.pointerId,start:U,moved:!1},P.currentTarget.setPointerCapture(P.pointerId))},Gb=P=>{const $=Ae.current;if(!$||j.current.readOnly)return;const B=$r(P);if(Ne.current.has(P.pointerId)&&Ne.current.set(P.pointerId,B),$.kind==="pinch"){const U=fy(Ne.current);if(!U)return;const ae=Math.max(O.minZoom,Math.min(O.maxZoom,$.zoom*U.distance/$.distance));O.set({x:U.center.x-$.anchor.x*ae,y:U.center.y-$.anchor.y*ae},ae);return}if($.pointerId===P.pointerId)switch($.kind){case"pan":{const U=B.x-$.start.x,ae=B.y-$.start.y;if(!$.moved&&Math.hypot(U,ae)<=ly)return;$.moved=!0,Ge.current=!0,O.set({x:$.pan0.x+U,y:$.pan0.y+ae});break}case"tap":{Math.hypot(B.x-$.start.x,B.y-$.start.y)>ly&&($.moved=!0);break}case"box":{Ge.current=!0,$.current=B,Sr({x1:Math.min($.start.x,B.x),y1:Math.min($.start.y,B.y),x2:Math.max($.start.x,B.x),y2:Math.max($.start.y,B.y)});break}case"draw":{const U=O.renderedToModel(B),ae=Lr(U,$.reverse?"source":"target");gr($.reverse&&ae?{source:ae.nodeId,sourceProperty:ae.property,point:U,target:$.source,targetProperty:$.sourceProperty}:{source:$.source,sourceProperty:$.sourceProperty,point:U,target:(ae==null?void 0:ae.nodeId)??Pr(U,$.source),targetProperty:ae==null?void 0:ae.property});break}}},cl=(P,$)=>{var ae,pe,ke,Oe,oe;Ne.current.delete(P.pointerId);const B=Ae.current;if(!B)return;if(B.kind==="pinch"){const se=[...Ne.current][0];Ae.current=se&&j.current.dragMode&&!$?{kind:"pan",pointerId:se[0],start:se[1],pan0:O.pan,moved:!0}:null;return}if(B.pointerId!==P.pointerId)return;Ae.current=null;try{P.currentTarget.releasePointerCapture(P.pointerId)}catch{}const U=j.current;switch($=$||!!U.readOnly,B.kind){case"pan":case"tap":!$&&!B.moved&&((ae=U.onBackgroundTap)==null||ae.call(U));break;case"box":{if(Sr(null),$)break;const se=O.renderedToModel(B.start),fe=O.renderedToModel(B.current),ge={x1:Math.min(se.x,fe.x),y1:Math.min(se.y,fe.y),x2:Math.max(se.x,fe.x),y2:Math.max(se.y,fe.y)};if(ge.x2-ge.x1<1&&ge.y2-ge.y1<1){(pe=U.onBackgroundTap)==null||pe.call(U);break}const rr=[];for(const Jr of U.nodes){const Zr=qe(Jr.id);Zr&&E0(dt(Zr),ge)&&rr.push(Jr.id)}rr.length&&((ke=U.onBoxSelect)==null||ke.call(U,rr));break}case"draw":{if(gr(null),$)break;const se=$r(P),fe=O.renderedToModel(se),ge=Lr(fe,B.reverse?"source":"target"),rr=(ge==null?void 0:ge.nodeId)??Pr(fe);if(rr===B.source&&(B.sourceProperty===void 0||(ge==null?void 0:ge.property)===void 0||ge.property===B.sourceProperty))break;rr?(Oe=U.onEdgeDraw)==null||Oe.call(U,B.reverse?rr:B.source,B.reverse?B.source:rr,B.sourceProperty!==void 0||(ge==null?void 0:ge.property)!==void 0?{sourceProperty:B.reverse?ge==null?void 0:ge.property:B.sourceProperty,targetProperty:B.reverse?B.sourceProperty:ge==null?void 0:ge.property}:void 0):Math.max(Math.abs(P.clientX-B.startClient.x),Math.abs(P.clientY-B.startClient.y))>m_&&((oe=U.onDrawIntoSpace)==null||oe.call(U,B.source,fe,B.sourceProperty,B.reverse));break}}},Kr=S.useCallback(()=>{var B;const P=Ae.current,$=[...Ne.current.keys()];P&&P.kind!=="pinch"&&$.push(P.pointerId),Ae.current=null,Ne.current.clear(),gr(null),Sr(null);for(const U of $)(B=E.current)!=null&&B.hasPointerCapture(U)&&E.current.releasePointerCapture(U)},[]);S.useEffect(()=>{const P=$=>{$.key==="Escape"&&Kr()};return window.addEventListener("keydown",P),window.addEventListener("blur",Kr),()=>{window.removeEventListener("keydown",P),window.removeEventListener("blur",Kr),Ae.current=null,Ne.current.clear()}},[Kr]),S.useEffect(()=>{Kr()},[b,x,m,i,n,e.drawHandles,e.readOnly,Kr]);const Ub=S.useMemo(()=>{const P=new Map,$=new Map;for(const B of T){if(B.source!==B.target)continue;const U=P.get(B.source)??0;P.set(B.source,U+1),$.set(B.id,U)}return $},[T]),Hn=y_[n],[Kn,Hb]=S.useState(null),Jn=p_(t,T,!!((dl=e.edgeReveal)!=null&&dl.revealNodes));S.useLayoutEffect(()=>{E.current&&Kn&&G0(E.current)});const Zn=_0(T,re,Hn),Kb=e.onEdgeSelect,Jb=e.onContainerSelect,ul=je?je.target&&re(je.target,je.targetProperty)||{x:je.point.x,y:je.point.y,w:1,h:1}:null,ll=je?re(je.source,je.sourceProperty):null,Zb=["flow-sdk-canvas",b?"flow-sdk-draw":"",w?"flow-sdk-perf":""].filter(Boolean).join(" ");return h.jsxs("div",{ref:E,className:Zb,"data-edge-mode":i,onPointerDownCapture:Wb,onPointerMove:Gb,onPointerUp:P=>cl(P,!1),onPointerCancel:P=>cl(P,!0),onLostPointerCapture:P=>{const $=Ae.current;$&&($.kind==="pinch"||$.pointerId===P.pointerId)&&Kr()},onClickCapture:P=>{P.currentTarget.contains(P.target)&&(Ge.current||e.readOnly)&&(P.preventDefault(),P.stopPropagation())},children:[h.jsx("svg",{className:"flow-sdk-svg",children:h.jsxs("g",{ref:M,children:[h.jsx("g",{className:"flow-sdk-containers",children:[...Me].filter(([P])=>ft(P,r,i)).filter(([P])=>!_||_.has(P)).map(([P,$])=>{var B;return h.jsx($0,{id:P,rect:$,label:ie.get(P),labelLayer:Kn,style:y(P),onSelect:Jb,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(B=e.selectedNodeIds)==null?void 0:B.includes(P)},P)})}),h.jsx("g",{className:"flow-sdk-edges",children:Ye&&T.map(P=>{var U,ae,pe;if(!Jn.ready.has(P.id)||_&&(!_.has(P.source)||!_.has(P.target)))return null;const $=re(P.source,P.sourceProperty),B=re(P.target,P.targetProperty);return!$||!B?null:h.jsx(Bl,{id:P.id,edgeData:P.data,validationIssue:P.validationIssue,edgeType:P.type,edgeRadius:e.edgeRadius,propertyMode:R,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:Jn.complete,source:$,target:B,sourceProperty:P.sourceProperty,targetProperty:P.targetProperty,sourceY:Q(P.source,P.sourceProperty),targetY:Q(P.target,P.targetProperty),sourcePort:F(P.source,P.sourceProperty),targetPort:F(P.target,P.targetProperty),dir:Hn,turn:((U=Zn.get(P.id))==null?void 0:U.turn)??P.turn,labelAtTarget:(ae=Zn.get(P.id))==null?void 0:ae.labelAtTarget,labelFraction:(pe=Zn.get(P.id))==null?void 0:pe.labelFraction,color:P.color,connectorColor:P.connectorColor,labelBg:P.labelBg,label:P.label,labelLayer:Kn,dashed:P.dashed,animated:P.animated&&!w,inverted:P.inverted,loopIndex:Ub.get(P.id)??0,onSelect:Kb},P.id)})}),Ye&&je&&ju(je,i)&&ll&&ul&&h.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:h.jsx(Bl,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:je.source,target:je.target??"",sourceProperty:je.sourceProperty,targetProperty:je.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:R,customEdgeTypes:e.customEdgeTypes,source:ll,target:ul,sourceProperty:je.sourceProperty,targetProperty:je.targetProperty,sourceY:Q(je.source,je.sourceProperty),sourcePort:F(je.source,je.sourceProperty),targetPort:je.target?F(je.target,je.targetProperty):void 0,targetY:je.target?Q(je.target,je.targetProperty):void 0,dir:Hn,turn:.5,color:g,labelBg:g})})]})}),h.jsx("div",{ref:N,className:"flow-sdk-nodes",children:t.map(P=>{var pe,ke;const $=X.get(P.id),B=Me.get(P.id),U=($==null?void 0:$.x)??(B?(B.x1+B.x2)/2:0),ae=($==null?void 0:$.y)??(B?(B.y1+B.y2)/2:0);return h.jsx(h_,{id:P.id,x:U,y:ae,placed:!!$||!!B,hidden:!Jn.shown.has(P.id)||!ft(P.id,r,i)||!!_&&!_.has(P.id),onMount:jt,drawHandles:e.drawHandles&&!e.readOnly,drawMode:b,connectedPorts:new Set(T.flatMap(Oe=>[...Oe.source===P.id&&Oe.sourceProperty!==void 0?[`source:${Oe.sourceProperty}`]:[],...Oe.target===P.id&&Oe.targetProperty!==void 0?[`target:${Oe.targetProperty}`]:[]])),hasCollapseControl:P.hasCollapseControl,handleColor:g,animated:P.animated&&!B&&!w,animationColor:P.animationColor,animationWidth:P.animationWidth,animationVariant:P.animationVariant,width:(pe=W.current.get(P.id))==null?void 0:pe.w,height:(ke=W.current.get(P.id))==null?void 0:ke.h,propertyMode:R,resolvedRows:cr.get(P.id),reversePorts:n==="RL",direction:n,onPropertyRows:H,onSurface:K,children:P.element},P.id)})}),Be&&h.jsx("div",{className:"flow-sdk-box",style:{left:Be.x1,top:Be.y1,width:Be.x2-Be.x1,height:Be.y2-Be.y1}}),h.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:h.jsx("g",{ref:I,transform:`translate(${O.pan.x} ${O.pan.y}) scale(${O.zoom})`,children:h.jsx("g",{ref:Hb,className:"flow-sdk-labels",style:{pointerEvents:b?"none":"visiblePainted",outline:"none"}})})})]})}const C_=S.memo(w_);function qb({id:e,label:t,role:r,side:n,position:o=.5,placement:i,children:s,style:a}){return h.jsx("div",{"data-flow-property":e,"data-flow-port-role":r,"data-flow-port-side":n,"data-flow-port-position":n?o:void 0,"data-flow-port-placement":i,style:{minHeight:32,display:"flex",alignItems:"center",justifyContent:r==="source"?"flex-end":"flex-start",...a,...n?{display:"none"}:{}},children:s??t??e})}const __=xn.default.dialog`
158
- ${e=>zr(e.$surface,e.$border)}
202
+ `;function Ol({request:e,property:t,config:r,value:n,disabled:o}){var se,te,xe,pe,De;const{callbacks:i,structured:s,references:a}=E.useContext(Pr),{themeColor:u}=$e(),{background:c}=Ye(),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,y]=E.useState(f),[g,b]=E.useState(""),[x,m]=E.useState(0),w=E.useRef(null),v=E.useRef(),[C,S]=E.useState(!1),[j,T]=E.useState(!1),[k,M]=E.useState(),R=((se=r.$options)==null?void 0:se.$source)==="callback",_=i.resolveFormOptions,{data:A,address:I,nodeAddress:q,nodeId:O}=e;E.useEffect(()=>(S(!1),T(!1),()=>{var Z;(Z=v.current)==null||Z.abort(),v.current=void 0}),[I,q,O,o,f,r.$control,(te=r.$upload)==null?void 0:te.accept,(xe=r.$upload)==null?void 0:xe.maxSizeBytes]);const W=E.useRef(A);W.current=A;const V=JSON.stringify([I,O,(pe=r.$options)!=null&&pe.$dependsOn?r.$options.$dependsOn.map(Z=>je(A,Z)):je(A,q)]);E.useEffect(()=>{y(f),b("")},[f,I,O]),E.useEffect(()=>{if(!R)return;const Z=new AbortController;return Promise.resolve().then(()=>{if(!_)throw new Error("No options resolver configured");return _({address:I,nodeAddress:q,nodeId:O,data:bt(W.current),signal:Z.signal})}).then(de=>{if(!Array.isArray(de)||de.some(Ce=>!Ce||typeof Ce.label!="string"||!["string","number","boolean"].includes(typeof Ce.value)&&Ce.value!==null))throw new Error("Invalid options response");Z.signal.aborted||M({key:V,options:de})}).catch(de=>{Z.signal.aborted||M({key:V,options:[],error:de instanceof Error?de.message:"Options unavailable"})}),()=>Z.abort()},[R,_,V,I,q,O,x]);const ue=R&&(k==null?void 0:k.key)!==V,ne=R?(k==null?void 0:k.key)===V?k.options:[]:t.type.kind==="null"?[{label:"Null",value:null}]:t.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:Vt(t.type),Q=t.type.kind==="array",he=(r.$control==="upload"?"upload":s&&d||r.$control==="checkbox"?"pills":r.$control)??(ne?Q||t.type.kind==="boolean"?"pills":"select":t.type.kind==="boolean"?"checkbox":d?"textarea":"input"),le=!t.optional||!!r.$requiredWhen&&En(r.$requiredWhen,A),$=le?"Required":"Optional",D=he!=="upload"&&!!(a!=null&&a.length)&&typeof n=="string"&&n.includes("{{"),G=g||R&&(k==null?void 0:k.key)===V&&k.error||!D&&_r(t.type,n,le),N=Cr(r.$label??I.split(".").pop()),ee=Z=>{var de;if(!(o||Object.is(Z,n)))try{(de=i.onFormChange)==null||de.call(i,{...e,previousValue:n,value:Z}),b("")}catch(Ce){b(Ce instanceof Error?Ce.message:"Unable to update field")}},ge=E.useRef(ee);E.useLayoutEffect(()=>{ge.current=ee});const ye=()=>{if(d){try{const Ie=p===""&&t.optional?void 0:JSON.parse(p),qe=_r(t.type,Ie,le);if(qe){b(qe);return}ee(Ie)}catch{b("Enter valid JSON")}return}const Z=t.type.kind==="number"||t.type.kind==="integer",de=p===""&&t.optional?void 0:Z&&p!==""?Number(p):p,Ce=_r(t.type,de,le);if(Z&&Ce&&p!==""){b(Ce);return}ee(de)},K=async Z=>{var Ce,Ie,qe;if(o||v.current||!Z.length)return;const de=new AbortController;v.current=de,b(""),S(!0);try{if(t.type.kind!=="string"&&!(t.type.kind==="array"&&t.type.items.kind==="string"))throw new Error("Uploads require a string or string-array field.");if(!Q&&Z.length!==1)throw new Error("Choose one file for this field.");if(!i.uploadFormFile)throw new Error("No file upload handler configured.");const Ue=(Ie=(Ce=r.$upload)==null?void 0:Ce.accept)==null?void 0:Ie.split(",").map(_e=>_e.trim().toLowerCase()).filter(Boolean);for(const _e of Z){if(((qe=r.$upload)==null?void 0:qe.maxSizeBytes)!==void 0&&_e.size>r.$upload.maxSizeBytes)throw new Error(`${_e.name} exceeds the file size limit.`);if(Ue!=null&&Ue.length&&!Ue.some(He=>He.startsWith(".")?_e.name.toLowerCase().endsWith(He):He.endsWith("/*")?_e.type.toLowerCase().startsWith(He.slice(0,-1)):_e.type.toLowerCase()===He))throw new Error(`${_e.name} is not an accepted file type.`)}const Qe=await Promise.all(Z.map(async _e=>{const He=await i.uploadFormFile({...e,data:bt(A),file:_e,signal:de.signal});if(typeof He!="string")throw new Error("Upload handler must return an HTTP or HTTPS URL.");let Xe;try{Xe=new URL(He)}catch{throw new Error("Upload handler must return an HTTP or HTTPS URL.")}if(!["http:","https:"].includes(Xe.protocol)||Xe.username||Xe.password)throw new Error("Upload handler must return an HTTP or HTTPS URL.");return He}));if(de.signal.aborted||v.current!==de)return;const We=Q?[...Array.isArray(n)?n:[],...Qe]:Qe[0],we=_r(t.type,We,le);if(we)throw new Error(we);ge.current(We)}catch(Ue){de.signal.aborted||b(Ue instanceof Error?Ue.message:"Unable to upload file."),de.abort()}finally{v.current===de&&(v.current=void 0,S(!1))}},X={id:l,disabled:o,"aria-label":N,"aria-required":le,"aria-invalid":!!G,"aria-describedby":G?`${l}-error`:void 0},U=me(u);return h.jsxs("div",{"data-form-field":I,"data-flow-property":I.slice(q.length+1),children:[h.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[h.jsxs("label",{htmlFor:l,children:[N,le?" *":""]}),t.optional&&n!==void 0&&h.jsx("button",{type:"button","aria-label":`Reset ${N}`,title:`Reset ${N}`,disabled:o||C,style:{width:24,height:24,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:0,background:"transparent",color:"inherit"},onClick:()=>ee(void 0),children:h.jsx(J.PiArrowCounterClockwise,{size:14})})]}),!!(a!=null&&a.length)&&!d&&he!=="upload"&&h.jsx(a0,{label:N,value:n,references:a,disabled:o,onChange:ee}),he==="upload"?h.jsxs("div",{"data-form-upload":Q?"multiple":"single","aria-busy":C,style:{"--flow-upload-surface":me(c),outline:j?"2px dashed currentColor":void 0,borderRadius:8},onDragOver:Z=>{Z.preventDefault(),Z.stopPropagation(),!o&&!C&&(Z.dataTransfer.dropEffect="copy",T(!0))},onDragLeave:Z=>{Z.currentTarget.contains(Z.relatedTarget)||T(!1)},onDrop:Z=>{Z.preventDefault(),Z.stopPropagation(),T(!1),K(Array.from(Z.dataTransfer.files))},children:[h.jsx("input",{ref:w,type:"file",hidden:!0,"aria-label":`Upload ${N}`,accept:(De=r.$upload)==null?void 0:De.accept,multiple:Q,disabled:o||C,onChange:Z=>{const de=Array.from(Z.target.files??[]);Z.target.value="",K(de)}}),h.jsxs("div",{"data-upload-items":"",children:[(Q?Array.isArray(n)?n:[]:n?[n]:[]).map((Z,de)=>h.jsxs("div",{"data-upload-preview":"",children:[typeof Z=="string"&&Fr(Z)&&h.jsxs("a",{href:Z,target:"_blank",rel:"noopener noreferrer","aria-label":`${N} file ${de+1}`,children:[h.jsx(J.PiFile,{size:32,"aria-hidden":"true"}),h.jsx(kr,{name:Z,size:120,onError:Ce=>{Ce.currentTarget.style.visibility="hidden"}})]}),h.jsxs("div",{"data-upload-actions":"",children:[!Q&&h.jsx(Se,{"aria-label":`Replace ${N}`,title:`Replace ${N}`,icon:h.jsx(J.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>{var Ce;return(Ce=w.current)==null?void 0:Ce.click()}}),h.jsx(Se,{"aria-label":`Remove ${N} file ${de+1}`,title:"Remove file",icon:h.jsx(J.PiTrash,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>ee(Q&&Array.isArray(n)?n.filter((Ce,Ie)=>Ie!==de):"")})]})]},`${de}:${Z}`)),(Q||!n)&&h.jsx("button",{...X,type:"button","data-upload-drop":"",title:`Upload ${N}`,disabled:o||C,onClick:()=>{var Z;return(Z=w.current)==null?void 0:Z.click()},children:h.jsx(J.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&h.jsx("span",{role:"status",children:"Uploading..."})]}):D?null:he==="select"?h.jsx("div",{"data-form-select":"",children:h.jsxs(br,{...X,disabled:o||ue||!!(k!=null&&k.error),labelCase:"preserve",value:String((ne==null?void 0:ne.findIndex(Z=>Object.is(Z.value,n)))??-1),onValueChange:Z=>{const de=ne==null?void 0:ne[Number(Z)];de&&ee(de.value)},children:[h.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):$}),ne==null?void 0:ne.map((Z,de)=>h.jsx("option",{value:de,children:Cr(Z.label)||Z.label},de))]})}):he==="pills"?h.jsxs("div",{id:l,role:"group","aria-label":N,"aria-describedby":X["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:[ne==null?void 0:ne.map((Z,de)=>{const Ce=Q?Array.isArray(n)&&n.includes(Z.value):Object.is(n,Z.value);return h.jsx("button",{type:"button",disabled:o||ue,"aria-pressed":Ce,style:{padding:"8px 16px",borderRadius:24,border:0,color:Ce?U:"inherit",background:Ce?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>ee(Q?Ce?n.filter(Ie=>Ie!==Z.value):[...Array.isArray(n)?n:[],Z.value]:Z.value),children:Cr(Z.label)||Z.label},de)}),ue&&h.jsx("span",{role:"status",children:"Loading..."})]}):he==="textarea"?h.jsx("textarea",{...X,placeholder:$,value:p,onChange:Z=>y(Z.target.value),onBlur:ye}):h.jsx("input",{...X,placeholder:$,type:t.type.kind==="number"||t.type.kind==="integer"?"number":"text",step:t.type.kind==="integer"?1:"any",value:p,onChange:Z=>y(Z.target.value),onBlur:ye,onKeyDown:Z=>{Z.key==="Enter"&&ye(),Z.key==="Escape"&&y(n===void 0?"":String(n))}}),G&&h.jsx("div",{role:"alert",id:`${l}-error`,children:G}),R&&(k==null?void 0:k.error)&&h.jsx("button",{type:"button",disabled:o,onClick:()=>{M(void 0),m(x+1)},children:"Retry"})]})}function cm({nodeAddress:e}){var v,C;const{data:t,schema:r,callbacks:n,bindings:o,editable:i,renderForm:s,structured:a}=E.useContext(Pr),{readOnly:u,config:c}=$e(),l=s==null?void 0:s(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(ln,{role:"alert",children:"Forms require a JSON document."});const d=o?nn(o,e,r):void 0,f=o?d:r&&_t(t,e,r);if(!f)return h.jsx(ln,{role:"status",children:"Form schema unavailable."});const p=(d==null?void 0:d.address)??e,y=je(t,p),g=(v=a==null?void 0:a.containers.get(e))==null?void 0:v.scalar;if(y===void 0||typeof y!="object"&&!g)return h.jsx(ln,{role:"alert",children:"Bound form state is unavailable."});const b=Object.entries(f.type.properties).filter(([S])=>{var j;return En((j=f.fields[S])==null?void 0:j.$visibleWhen,t)}),x=b.length>8||b.some(([S])=>{var j;return(j=f.fields[S])==null?void 0:j.$section}),m=new Map;for(const S of b){const[j,T]=S,k=x?Cr(((C=f.fields[j])==null?void 0:C.$section)??(T.type.kind==="object"||T.type.kind==="array"?j:T.optional?"Options":"General")):"";m.has(k)||m.set(k,[]),m.get(k).push(S)}const w=([S,j])=>h.jsx(Ol,{request:{data:t,address:g?p:`${p}.${S}`,nodeAddress:p,nodeId:typeof(y==null?void 0:y.id)=="string"?y.id:void 0},property:j,config:f.fields[S]??{},value:g?y:y==null?void 0:y[S],disabled:u||c.editable===!1||!(i??!!n.onJsonChange)},`${(y==null?void 0:y.id)??e}:${S}`);return h.jsxs(ln,{"data-flow-form":e,onClick:S=>S.stopPropagation(),onDoubleClick:S=>S.stopPropagation(),children:[a&&h.jsx(d0,{nodeAddress:e}),d&&f.type.additionalProperties&&b.length===0&&h.jsx(Ol,{request:{data:t,address:p,nodeAddress:p},property:{type:f.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:y,disabled:u||c.editable===!1||!i}),[...m].map(([S,j])=>x&&j.length>1?h.jsxs("details",{open:!0,children:[h.jsxs("summary",{children:[h.jsx("span",{children:S}),h.jsx(J.PiCaretDown,{size:16,"aria-hidden":"true"})]}),j.map(w)]},S):j.map(w))]})}function um(e){const{viewData:t}=E.useContext(Pr),{nodeById:r,edgeById:n,parentIds:o}=Hr();if(t){const i=je(t,e),s=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(s)?s.length>0:!!s&&typeof s=="object"&&Object.entries(s).some(([a,u])=>!a.startsWith("$")&&u!==null&&typeof u=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const s=i.isInverted?i.target:i.source,a=i.isInverted?i.source:i.target;return s===e&&a!==e&&r.has(a)})}function en(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:t}function mn(e,t,r,n){return{borderColor:t,borderWidth:en(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",...xy(t==="transparent"?"currentColor":t,r,".flow-sdk-node:hover &",!r)}}function lm({label:e,value:t,options:r,onChange:n,disabled:o}){var i;return h.jsxs(br,{"aria-label":e,title:`Animation: ${((i=r.find(s=>s.value===t))==null?void 0:i.label)??"Mixed"}`,value:t,style:{width:104},disabled:o,onValueChange:s=>{const a=r.find(u=>u.value===s);a&&n(a.value)},children:[t===""&&h.jsx("option",{value:"",disabled:!0,children:"Mixed"}),r.map(s=>h.jsx("option",{value:s.value,children:s.label},s.value))]})}function zu({nodeId:e,edgeId:t,value:r,open:n,onOpenChange:o}){const{callbacks:i,readOnly:s,themeColor:a,colorMode:u}=$e(),{background:c,backgroundSecondary:l,border:d,colorText:f,colorInactive:p}=Ye(),y=u==="dark"?wt:me(p),g=E.useRef(null),b=E.useRef(null),x=E.useRef(0),[m,w]=E.useState(!1),[v,C]=E.useState("icons"),[S,j]=E.useState([]),[T,k]=E.useState("loading"),[M,R]=E.useState(""),[_,A]=E.useState(0),[I,q]=E.useState(""),[O,W]=E.useState(""),[V,ue]=E.useState(!1);E.useEffect(()=>()=>{x.current++},[]),E.useEffect(()=>{if(!m)return;let N=!0;return import("react-icons/pi").then(ee=>{N&&(j(Object.keys(ee).filter(ge=>ge.startsWith("Pi")).sort()),k("ready"))}).catch(()=>{N&&k("unavailable")}),()=>{N=!1}},[m]),E.useEffect(()=>{var N;s&&((N=g.current)==null||N.close())},[s]),E.useEffect(()=>{var N,ee,ge;if(n!==void 0){if(!n||s){(N=g.current)==null||N.close();return}(ee=g.current)!=null&&ee.open||(W(""),C(r==="PiFileSvg"||r&&Fr(r)?"custom":"icons"),q(r&&!r.startsWith(Wt)&&Fr(r)?r:""),w(!0),(ge=g.current)==null||ge.showModal())}},[n,s,r]);const ne=N=>{var ee,ge,ye;s||(t?(ee=i.onEdgeIconChange)==null||ee.call(i,t,N):e&&((ge=i.onNodeIconChange)==null||ge.call(i,e,N)),o==null||o(!1),(ye=g.current)==null||ye.close())},Q=S.filter(N=>N.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(M.trim().toLowerCase())),he=36,le=Math.max(1,Math.ceil(Q.length/he)),$=Math.min(_,le-1),D=Q.slice($*he,($+1)*he),G={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${me(d)}`,borderRadius:30};return h.jsxs(h.Fragment,{children:[n===void 0&&h.jsx(Te,{label:t?"Choose edge icon":"Choose node icon",children:h.jsx(Se,{"aria-label":t?"Choose edge icon":"Choose node icon",icon:h.jsx(J.PiShapes,{size:20}),size:"sm",variant:"ghost",color:me(a),disabled:s,onClick:()=>{var N;W(""),C(r&&Fr(r)?"custom":"icons"),q(r&&!r.startsWith(Wt)&&Fr(r)?r:""),w(!0),(N=g.current)==null||N.showModal()}})}),h.jsx(z.chakra.dialog,{ref:g,"aria-label":t?"Choose edge icon":"Choose node icon",css:Vr(me(c),me(d)),onClose:()=>{w(!1),o==null||o(!1),x.current++,ue(!1)},onClick:N=>{N.stopPropagation(),N.target===N.currentTarget&&N.currentTarget.close()},onKeyDown:N=>N.stopPropagation(),style:{margin:"auto",padding:12,width:336,maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",borderRadius:30,background:me(c),color:me(f)},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(Te,{label:"Remove icon",children:h.jsx(Se,{"aria-label":t?"Remove edge icon":"Remove node icon",icon:h.jsx(J.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:s||V,onClick:()=>ne("")})}),h.jsx(Ct,{"aria-label":"Close icon picker",onClick:()=>{var N;return(N=g.current)==null?void 0:N.close()}})]})]}),h.jsxs(z.Tabs.Root,{value:v,onValueChange:({value:N})=>{C(N),W("")},display:"contents",css:{"--indicator-thickness":"1px"},children:[h.jsx(z.Tabs.List,{"aria-label":"Icon source",width:"100%",borderBottomWidth:0,children:["icons","custom"].map(N=>h.jsx(z.Tabs.Trigger,{value:N,flex:1,minW:0,justifyContent:"center",px:3,py:2,fontSize:"13px",_selected:{color:a,borderColor:y,"--indicator-color":y},children:N==="icons"?"React icons":"Custom SVG"},N))}),h.jsx("input",{ref:b,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:V||s,onChange:async N=>{var ye;const ee=(ye=N.target.files)==null?void 0:ye[0];if(N.target.value="",!ee)return;const ge=++x.current;ue(!0),W("");try{const K=await r0(ee);ge===x.current&&ne(K)}catch(K){ge===x.current&&W(K instanceof Error?K.message:"Unable to read SVG.")}finally{ge===x.current&&ue(!1)}}}),h.jsx(z.Tabs.Content,{value:v,p:0,style:{display:"grid",gap:8},children:v==="icons"?h.jsxs(h.Fragment,{children:[h.jsx("input",{"aria-label":"Search icons",placeholder:"Search icons...",value:M,onChange:N=>{R(N.target.value),A(0)},style:G}),h.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[D.map(N=>h.jsx("button",{type:"button","aria-label":`Choose ${N}`,"aria-pressed":r===N,title:N,onClick:()=>ne(N),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${r===N?2:1}px solid ${me(r===N?a:d)}`,background:me(r===N?c:l),color:"inherit",cursor:"pointer"},children:h.jsx(kr,{name:N,size:24})},N)),D.length===0&&h.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:T==="loading"?"Loading icons...":T==="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:[Q.length," icons · ",$+1," / ",le]}),h.jsxs("div",{style:{display:"flex",gap:4},children:[h.jsx(Te,{label:"Previous icons",children:h.jsx(Se,{"aria-label":"Previous icons",icon:h.jsx(J.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:$===0,onClick:()=>A($-1)})}),h.jsx(Te,{label:"Next icons",children:h.jsx(Se,{"aria-label":"Next icons",icon:h.jsx(J.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:$+1>=le,onClick:()=>A($+1)})})]})]})]}):h.jsxs(h.Fragment,{children:[r&&Fr(r)&&h.jsx(kr,{name:r,size:64}),h.jsxs("button",{type:"button",disabled:V||s,onClick:()=>{var N;return(N=b.current)==null?void 0:N.click()},style:{...G,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[h.jsx(J.PiUploadSimple,{}),V?"Uploading...":"Upload SVG"]}),h.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:N=>{N.preventDefault(),!(V||s)&&(!Fr(I.trim())||I.trim().startsWith(Wt)?W("Enter an HTTP or HTTPS image URL."):ne(I.trim()))},children:[h.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:I,disabled:V||s,onChange:N=>q(N.target.value),style:{...G,flex:1,minWidth:0}}),h.jsx(Te,{label:"Apply URL",children:h.jsx(Se,{type:"submit","aria-label":"Apply URL",icon:h.jsx(J.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:V||s||!I.trim(),style:{flexShrink:0}})})]})]})})]}),O&&h.jsx("div",{role:"alert",style:{fontSize:13},children:O})]})})]})}const bn=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500",wt],dm=["gray.900",wt,"gray.600","gray.200","white"];function fm(){const{config:e}=$e(),t=e.selectionToolbar||{},r=new Set(t.hide||[]);return{palette:t.palette||bn,show:n=>!r.has(n)}}function dr(){const{border:e}=Ye();return h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:e})}function nt({value:e,placeholder:t,ariaLabel:r,width:n="140px",type:o="text",min:i,onCommit:s}){const{colorText:a}=Ye(),[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&&s(f)};return h.jsx(z.Input,{"aria-label":r,type:o,min:i,size:"xs",fontSize:"16px",w:n,value:u,placeholder:t,color:a,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 vt({colors:e,value:t,label:r,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:s,colorText:a}=Ye(),[u,c]=E.useState(!1),l=E.useId(),d=E.useRef(null),f=t??e[0]??"transparent";return h.jsxs(z.HStack,{gap:1,"aria-label":r,role:"group",onKeyDown:p=>{var y;p.key==="Escape"&&(c(!1),(y=d.current)==null||y.focus())},children:[h.jsx(Te,{label:`${r}: ${f}`,children:h.jsx(z.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:me(f),...f==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${me(a)}`,outlineOffset:"1px",onClick:()=>c(p=>!p)})}),u&&h.jsxs(z.HStack,{id:l,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(p=>{const y=t===p;return h.jsx(Te,{label:`${r}: ${p}`,children:h.jsx(z.Box,{as:"button","aria-label":`${r} ${p}`,"aria-pressed":y,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:me(p),...p==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:y?`2px solid ${me(a)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>n(p),onDoubleClick:g=>{var b;g.stopPropagation(),c(!1),(b=d.current)==null||b.focus()}})},p)}),o&&h.jsx(Te,{label:`Reset ${r.toLowerCase()}`,children:h.jsx(Se,{"aria-label":`Reset ${r}`,icon:h.jsx(z.Icon,{as:J.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:s,onClick:()=>{var p;o(),c(!1),(p=d.current)==null||p.focus()}})})]})]})}function hm({edgeId:e,onClose:t}){var p;const{callbacks:r,themeColor:n,config:o}=$e(),{colorInactive:i}=Ye(),{edgeById:s}=Hr(),{palette:a,show:u}=fm(),c=(p=s.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:J.PiLineSegment,label:"Solid"},{key:"dashed",icon:J.PiLineSegments,label:"Dashed"},{key:"animated",icon:J.PiFastForward,label:"Animated"}];return h.jsxs(h.Fragment,{children:[h.jsx(Ct,{onClick:t}),u("label")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(nt,{ariaLabel:"Edge label",placeholder:"Edge label",value:(c==null?void 0:c.label)||"",onCommit:y=>{var g;return(g=r.onEdgeLabelChange)==null?void 0:g.call(r,e,y)}})]}),u("style")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),f.map(y=>h.jsx(Te,{label:y.label,children:h.jsx(Se,{"aria-label":`Edge style ${y.key}`,"aria-pressed":d===y.key,icon:h.jsx(z.Icon,{as:y.icon,boxSize:5}),size:"sm",variant:"ghost",color:d===y.key?n:i,onClick:()=>{var g;return(g=r.onEdgeStyleChange)==null?void 0:g.call(r,e,y.key)}})},y.key)),d==="animated"&&h.jsx(lm,{label:"Edge animation",value:(c==null?void 0:c.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:o.readOnly,onChange:y=>{var g;return(g=r.onEdgeAnimationVariantChange)==null?void 0:g.call(r,e,y)}}),h.jsxs(br,{"aria-label":"Edge shape",title:`Edge shape: ${(c==null?void 0:c.type)??"Default"}`,icon:h.jsx(J.PiBezierCurve,{size:20}),style:{width:36},value:(c==null?void 0:c.type)??"",disabled:o.readOnly,onValueChange:y=>{var g;return(g=r.onEdgeTypeChange)==null?void 0:g.call(r,e,y||void 0)},children:[h.jsx("option",{value:"",children:"Default"}),l.map(y=>h.jsx("option",{value:y,children:y},y))]})]}),u("icon")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(zu,{edgeId:e,value:c==null?void 0:c.icon},e),h.jsx(nt,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(c==null?void 0:c.icon)??"",onCommit:y=>{var g;return(g=r.onEdgeIconChange)==null?void 0:g.call(r,e,y)}})]}),u("color")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(vt,{label:"Edge color",colors:a,value:c==null?void 0:c.color,onPick:y=>{var g;return(g=r.onEdgeColorChange)==null?void 0:g.call(r,e,y)},onReset:()=>{var y;return(y=r.onEdgeColorChange)==null?void 0:y.call(r,e,"")}})]}),u("delete")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(Te,{label:"Delete edge",children:h.jsx(Se,{"aria-label":"Delete edge",icon:h.jsx(z.Icon,{as:J.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var y;(y=r.onEdgeDelete)==null||y.call(r,e,c),t()}})})]})]})}function pm({ids:e,showDivider:t=!0}){const{callbacks:r,config:n}=$e(),{colorInactive:o}=Ye(),{nodeById:i}=Hr(),[s,a]=E.useState(!1),u=e.map(y=>{var g,b;return(b=(g=i.get(y))==null?void 0:g.data.viewProps)==null?void 0:b.borderRadius}),c=!u.every(y=>y===u[0]),l=c?"mixed":String(u[0]??""),d=["0","8","16","30","53","100"],f=s||!c&&l!==""&&!d.includes(l),p=y=>e.forEach(g=>{var b;return(b=r.onNodeBorderRadiusChange)==null?void 0:b.call(r,g,y)});return h.jsxs(h.Fragment,{children:[t&&h.jsx(dr,{}),h.jsx(z.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:h.jsxs(br,{icon:h.jsx(z.Icon,{as:av.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:y=>{a(y==="custom"),y!=="custom"&&p(y===""?void 0:Number(y))},children:[h.jsx("option",{value:"",children:"Default radius"}),c&&h.jsx("option",{value:"mixed",disabled:!0,children:"Mixed radii"}),d.map(y=>h.jsxs("option",{value:y,children:[y,"px radius"]},y)),h.jsx("option",{value:"custom",children:"Custom radius"})]})}),f&&h.jsx(nt,{ariaLabel:"Custom border radius",placeholder:c?"Mixed":"Auto",type:"number",min:0,width:"72px",value:c?"":l,onCommit:y=>p(y===""?void 0:Number(y))})]})}function gm({ids:e,onClose:t}){var le,$,D,G,N,ee,ge,ye;const{callbacks:r,colorMode:n,themeColor:o,config:i,setNodeViewMode:s}=$e(),{colorText:a,colorInactive:u}=Ye(),{nodeById:c,parentIds:l}=Hr(),{palette:d,show:f}=fm(),p=e.length===1,y=p?(le=c.get(e[0]))==null?void 0:le.data:void 0,g=e.map(K=>{var X,U;return((U=(X=c.get(K))==null?void 0:X.data.config)==null?void 0:U.typeView)??""}),b=g.some(K=>K!==g[0]),x=b?"mixed":g[0]??"",m=e.some(K=>{var U,se;const X=(U=c.get(K))==null?void 0:U.data;return X&&(l.has(K)||((se=X.config)==null?void 0:se.parentContainer)||Object.prototype.hasOwnProperty.call(i.customViews??{},X.type))}),w=($=y==null?void 0:y.config)==null?void 0:$.collapsed,v=um(e[0]),C=K=>{var X,U,se;return(((U=(X=c.get(K))==null?void 0:X.data.viewProps)==null?void 0:U.outline)??(l.has(K)?(se=i.parentNodeStyle)==null?void 0:se.outline:!1))===!0},S=e.every(C),j=!S&&e.some(C),T=K=>{var X;return((X=c.get(K))==null?void 0:X.data.isNodeAnimated)===!0},k=e.every(T),M=!k&&e.some(T),R=e.map(K=>{var X;return((X=c.get(K))==null?void 0:X.data.nodeAnimationVariant)??"traveling"}),_=R.every(K=>K===R[0])?R[0]:"",A=K=>e.forEach(K),[I,q]=E.useState(!1),O=I&&f("color")&&f("borderColor"),W=K=>{var X,U,se;return(((U=(X=c.get(K))==null?void 0:X.data.viewProps)==null?void 0:U.borderStyle)??(l.has(K)?(se=i.parentNodeStyle)==null?void 0:se.borderStyle:"solid"))==="dashed"},V=e.every(W),ue=!V&&e.some(W),ne=e.map(K=>{var se,te,xe;const X=(se=c.get(K))==null?void 0:se.data,U=l.has(K)?en((te=i.parentNodeStyle)==null?void 0:te.borderWidth,6):(X==null?void 0:X.type)==="objectView"?3:2;return en((xe=X==null?void 0:X.viewProps)==null?void 0:xe.borderWidth,U)}),Q=ne.every(K=>K===ne[0])?String(ne[0]??""):"",he=K=>A(X=>{var U,se;O?(U=r.onNodeBorderColorChange)==null||U.call(r,X,K):(se=r.onNodeColorChange)==null||se.call(r,X,"bg",K)});return h.jsxs(h.Fragment,{children:[h.jsx(Ct,{onClick:t}),h.jsx(dr,{}),p&&f("label")?h.jsx(nt,{ariaLabel:"Node label",placeholder:"Node label",value:(y==null?void 0:y.label)??(y==null?void 0:y.headerTitle)??"",onCommit:K=>{var X;return(X=r.onNodeLabelChange)==null?void 0:X.call(r,e[0],K)}}):h.jsxs(z.Text,{fontSize:"xs",color:a,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),f("typeView")&&h.jsxs(br,{"aria-label":"Type view",title:m?"Type view is managed by the custom renderer or container":`Type view: ${x||"None (default)"}`,icon:h.jsx(J.PiImage,{size:20}),style:{width:36},value:x,disabled:i.readOnly||i.editable===!1||m,onValueChange:K=>{Kt.includes(K)&&A(X=>{var U,se;(U=r.onNodeTypeViewChange)==null||U.call(r,X,K||void 0),s(X,"default"),(se=r.onNodeViewToggle)==null||se.call(r,X)})},children:[b&&h.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),Kt.map(K=>h.jsx("option",{value:K,children:K||"None"},K))]}),f("style")&&h.jsx(pm,{ids:e},e.join("\0")),f("outline")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(Te,{label:S?"Restore node fill":"Remove node fill",children:h.jsx(Se,{"aria-label":"Toggle node outline","aria-pressed":j?"mixed":S,icon:h.jsx(z.Icon,{as:S?J.PiSquare:J.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:S?o:u,onClick:()=>A(K=>{var X;return(X=r.onNodeOutlineChange)==null?void 0:X.call(r,K,!S)})})})]}),f("color")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),f("borderColor")&&h.jsx(Te,{label:O?"Edit node colors":"Edit node border",children:h.jsx(Se,{"aria-label":"Edit node border","aria-pressed":O,icon:h.jsx(z.Icon,{as:J.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:O?o:u,bg:O?n==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>q(K=>!K)})}),h.jsx(vt,{label:O?"Border color":"Background",colors:d,value:O?((D=y==null?void 0:y.viewProps)==null?void 0:D.borderColor)??(p&&l.has(e[0])?(G=i.parentNodeStyle)==null?void 0:G.borderColor:void 0):(N=y==null?void 0:y.viewProps)==null?void 0:N.bgColor,onPick:he,onReset:()=>he("")}),O&&f("style")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(Te,{label:V?"Solid border":"Dashed border",children:h.jsx(Se,{"aria-label":"Toggle dashed border","aria-pressed":ue?"mixed":V,icon:h.jsx(z.Icon,{as:V?J.PiLineSegments:J.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:V?o:u,onClick:()=>A(K=>{var X;return(X=r.onNodeBorderStyleChange)==null?void 0:X.call(r,K,V?"solid":"dashed")})})}),h.jsx(nt,{ariaLabel:"Border thickness",placeholder:p?"Auto":"Mixed",width:"64px",type:"number",min:0,value:Q,onCommit:K=>A(X=>{var U;return(U=r.onNodeBorderWidthChange)==null?void 0:U.call(r,X,K===""?void 0:Number(K))})})]})]}),f("animation")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(Te,{label:k?"Stop border animation":"Animate node border",children:h.jsx(Se,{"aria-label":"Toggle node animation","aria-pressed":M?"mixed":k,icon:h.jsx(z.Icon,{as:J.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:k?o:u,onClick:()=>A(K=>{var X;return(X=r.onNodeAnimationChange)==null?void 0:X.call(r,K,!k)})})}),(k||M)&&h.jsx(lm,{label:"Node animation",value:_,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:i.readOnly,onChange:K=>A(X=>{var U;return(U=r.onNodeAnimationVariantChange)==null?void 0:U.call(r,X,K)})})]}),!O&&f("textColor")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(vt,{label:"Text color",colors:dm,value:(ee=y==null?void 0:y.viewProps)==null?void 0:ee.textColor,onPick:K=>A(X=>{var U;return(U=r.onNodeColorChange)==null?void 0:U.call(r,X,"text",K)}),onReset:()=>A(K=>{var X;return(X=r.onNodeColorChange)==null?void 0:X.call(r,K,"text","")})})]}),p&&f("icon")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(zu,{nodeId:e[0],value:(ge=y==null?void 0:y.config)==null?void 0:ge.icon},e[0]),h.jsx(nt,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((ye=y==null?void 0:y.config)==null?void 0:ye.icon)||"",onCommit:K=>{var X;return(X=r.onNodeIconChange)==null?void 0:X.call(r,e[0],K)}})]}),p&&v&&f("collapse")&&w!==void 0&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(Te,{label:w?"Expand":"Collapse",children:h.jsx(Se,{"aria-label":w?"Expand node":"Collapse node",icon:h.jsx(z.Icon,{as:w?J.PiArrowsOutLineVertical:J.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:u,onClick:()=>{var K;return(K=r.onNodeCollapse)==null?void 0:K.call(r,e[0],!w)}})})]}),f("delete")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(Te,{label:p?"Delete node":`Delete ${e.length} nodes`,children:h.jsx(Se,{"aria-label":"Delete selected nodes",icon:h.jsx(z.Icon,{as:J.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:n==="dark"?"red.300":"red.500",onClick:()=>{A(K=>{var X,U;return(U=r.onNodeDelete)==null?void 0:U.call(r,K,((X=c.get(K))==null?void 0:X.data)||{id:K})}),t()}})})]})]})}async function ym(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 mm(e,t="squeed.svg"){const r=document.createElement("a");r.href=await ym(e),r.download=t.endsWith(".svg")?t:`${t}.svg`,r.click()}function bm(){const{themeColor:e}=$e(),[t,r]=E.useState(!1),[n,o]=E.useState("");return h.jsxs(h.Fragment,{children:[h.jsx(Te,{label:"Download SVG (current view)",children:h.jsx(Se,{"aria-label":"Download SVG",icon:h.jsx(J.PiDownloadSimpleFill,{size:20}),disabled:t,borderRadius:"30%",color:e,variant:"ghost",onClick:async i=>{var a;const s=(a=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:a.querySelector("[data-flow-background]");if(!s){o("Diagram not available for export.");return}r(!0),o("");try{await mm(s)}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 vm({children:e,background:t,border:r}){const n=E.useRef(null),[o,i]=E.useState({left:!1,right:!1});E.useLayoutEffect(()=>{const a=n.current,u=()=>{const l=a.scrollLeft>1,d=a.scrollWidth-a.clientWidth-a.scrollLeft>1;i(f=>f.left===l&&f.right===d?f:{left:l,right:d})},c=new ResizeObserver(u);return c.observe(a),a.firstElementChild&&c.observe(a.firstElementChild),a.addEventListener("scroll",u,{passive:!0}),u(),()=>{c.disconnect(),a.removeEventListener("scroll",u)}},[]);const s=`var(--chakra-colors-${t.replace(".","-")})`;return h.jsxs(z.Box,{position:"relative",bg:t,minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:"30px",css:Vr(s,`var(--chakra-colors-${r.replace(".","-")})`),children:[h.jsx(z.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(a=>h.jsx(z.Box,{"data-flow-toolbar-fade":a,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",borderRadius:a==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[a]:0,opacity:o[a]?1:0,background:`linear-gradient(to ${a==="left"?"right":"left"}, ${s}, transparent)`}},a))]})}async function f0(e,t){const r=new Set,n=[],o=(a,u)=>{var l,d,f;if(!a||typeof a!="object")return;const c=a;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,y]of Object.entries(c))p==="$"?o(y,u):p.startsWith("$")||o(y,`${u}.${p}`)};if(o(t,"root"),!r.size)return{contract:await im(e)};const i=await Bu(e,[...r]);for(const a of r)if(!Object.prototype.hasOwnProperty.call(i,a))throw new Error(`Missing form type: ${a}`);const s={};for(const a of n){const u=_t(t,a,i);u&&(s[a]={type:u.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:s}}}function xm({message:e,onDismiss:t}){const{background:r,colorText:n,border:o}=Ye();return!e||typeof document>"u"?null:Ht.createPortal(h.jsxs(z.chakra.div,{role:"alert","aria-atomic":"true",css:Vr(me(r),me(o)),onPointerDown:i=>i.stopPropagation(),onClick:i=>i.stopPropagation(),style:{position:"fixed",top:20,right:20,zIndex:1e4,width:360,maxWidth:"calc(100vw - 40px)",boxSizing:"border-box",display:"flex",alignItems:"flex-start",gap:10,padding:16,borderRadius:8,background:me(r),color:me(n),fontSize:14,lineHeight:1.5},children:[h.jsx(J.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(Ct,{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 wm({showDivider:e=!0,compact:t=!1}={}){const{edgeMode:r,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:s,readOnly:a,themeColor:u}=$e(),{edgeById:c}=Hr(),{data:l,schema:d,setSchema:f,bindings:p,structured:y}=E.useContext(Pr),g=(y==null?void 0:y.sourceBindings)??p,b=(y==null?void 0:y.sourceSchema)??d,{colorText:x}=Ye(),m=E.useRef(null),w=E.useRef(0),[v,C]=E.useState(!1),[S,j]=E.useState("");E.useEffect(()=>()=>{w.current++},[]),E.useEffect(()=>{w.current++,C(!1)},[a,l,g]);const T=o?[...c.values()].filter(M=>Fu(o,M.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(xm,{message:S,onDismiss:()=>j("")}),e&&h.jsx(Ft,{}),h.jsxs(br,{"aria-label":"Edge mode",title:r==="auto"?"Connections: Auto":r==="properties"?"Connections: Properties":"Connections: Nodes",icon:r==="auto"?h.jsx(J.PiGraph,{size:20}):r==="properties"?h.jsx(J.PiTable,{size:20}):h.jsx(J.PiTreeStructure,{size:20}),style:{width:36},value:r,disabled:a,onValueChange:M=>{var _;const R=M==="auto"?"auto":M==="properties"?"properties":"nodes";n(R),(_=s.onEdgeModeChange)==null||_.call(s,R)},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(Te,{label:o?`Replace ${o.name}`:"Upload workflow interface",children:h.jsx(Se,{"aria-label":"Upload workflow interface",icon:h.jsx(J.PiUploadSimple,{size:20}),color:me(u),size:"sm",variant:"ghost",disabled:v||a,onClick:()=>{var M;return(M=m.current)==null?void 0:M.click()}})}),h.jsx("input",{ref:m,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:a||v,onChange:async M=>{var A,I;const R=(A=M.target.files)==null?void 0:A[0];if(M.target.value="",!R)return;const _=++w.current;C(!0),j("");try{const q=g?await Bu(R,[...new Set(Object.values(g).map(V=>V.schemaType??V.type))]):void 0;if(g&&q){for(const V of Object.values(g))if(!Object.prototype.hasOwnProperty.call(q,V.schemaType??V.type))throw new Error(`Missing form type: ${V.schemaType??V.type}`)}const{contract:O,schema:W}=g&&q?{schema:q,contract:{name:R.name,nodes:Object.fromEntries(Object.entries(g).map(([V,ue])=>[V,{type:q[ue.schemaType??ue.type],optional:!1}]))}}:await f0(R,l);if(_!==w.current)return;f==null||f(W),i(O),(I=s.onWorkflowContractChange)==null||I.call(s,O)}catch(q){_===w.current&&j(`${R.name}: ${q instanceof Error?q.message:"Unable to load interface."}`)}finally{_===w.current&&C(!1)}}}),!t&&(k||v)&&h.jsx("span",{role:"status",title:k,style:{color:me(x),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v?"Loading interface...":k}),!t&&o&&h.jsx(Te,{label:"Remove workflow interface",children:h.jsx(Se,{"aria-label":"Remove workflow interface",icon:h.jsx(J.PiX,{size:16}),size:"sm",variant:"ghost",disabled:a||v,onClick:()=>{var M;f==null||f(void 0),i(void 0),(M=s.onWorkflowContractChange)==null||M.call(s,void 0),j("")}})})]})]})}const h0=[{value:"BT",label:"Bottom to Up",icon:J.PiArrowUp,flowType:Ot.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:J.PiArrowDown,flowType:Ot.TOP_DOWN},{value:"LR",label:"Left to Right",icon:J.PiArrowRight,flowType:Ot.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:J.PiArrowLeft,flowType:Ot.RIGHT_LEFT}],Cm=()=>{const{engineRef:e,themeColor:t,setThemeColor:r,edgeColor:n,setEdgeColor:o,backgroundSelected:i,setBackgroundSelected:s,direction:a,edgeMode:u,allNodesIconLabel:c,setAllNodesIconLabel:l,selectedNodeIds:d,setSelectedNodeIds:f,selectedEdgeId:p,setSelectedEdgeId:y,isZoomMode:g,setIsZoomMode:b,isMultiSelectMode:x,setIsMultiSelectMode:m,isDragMode:w,setIsDragMode:v,isEdgeHandlesEnabled:C,setIsEdgeHandlesEnabled:S,isArrayNodeMode:j,setIsArrayNodeMode:T,isPinned:k,setIsPinned:M,callbacks:R,config:_,readOnly:A}=$e(),{nodeById:I,edgeById:q,parentIds:O}=Hr(),W=_.colorMode==="dark",{background:V,border:ue,colorInactive:ne,colorText:Q,colorActive:he}=Ye(),le=W?ue:"gray.300",$=`var(--chakra-colors-${V.replace(".","-")})`,D=`var(--chakra-colors-${(W?ue:"gray.300").replace(".","-")})`,[G,N]=E.useState(!1),[ee,ge]=E.useState(!0),ye=E.useRef(null),K=by({edge:"bottom",enabled:!k,bounds:ye,inside:[ye]}),X=E.useCallback(we=>{const _e=e.current;if(!_e)return;const He=_.minZoom??.01,Xe=_.maxZoom??1.5,ur=.02;let er=_e.zoom();switch(we){case"increase":er=Math.min(Xe,er+ur),_e.zoom(er),_e.center();break;case"decrease":er=Math.max(He,er-ur),_e.zoom(er),_e.center();break;case"reset":_e.fit(50);break}},[e,_.minZoom,_.maxZoom]),U=_.renderSelectedNodeToolbar,se=d.length>0&&!!U,te=E.useMemo(()=>se?d.map(we=>{var He;return{...((He=I.get(we))==null?void 0:He.data)??{id:we},isParent:O.has(we)}}):[],[se,d,I,O]),xe=E.useCallback(()=>{var we;f([]),(we=R.onNodeDeselect)==null||we.call(R)},[f,R]),pe=_.renderSelectedEdgeToolbar,De=!!p&&!!pe,Z=E.useMemo(()=>{var we;return!De||!p?null:((we=q.get(p))==null?void 0:we.data)??{id:p}},[De,p,q]),de=E.useCallback(()=>{var we;y(null),(we=R.onEdgeDeselect)==null||we.call(R)},[y,R]),Ce=_.selectionToolbar!==!1&&!A,Ie=Ce&&!!p&&!pe,qe=Ce&&!Ie&&d.length>0&&!U,Ue=Ie||qe,Qe=k||K||G||Ue;E.useEffect(()=>{d.length||p?s(!1):i&&!A&&(M(!0),ge(!1))},[i,d.length,p,A,s,M]);const We=_.renderBottomBar;return We?h.jsxs(h.Fragment,{children:[se&&h.jsx(z.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:U({selectedNodeIds:d,selectedNodeData:te,onDeselect:xe})}),De&&Z&&h.jsx(z.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:pe({edgeId:p,edgeData:Z,onDeselect:de})}),h.jsx(z.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:We({zoomIn:()=>X("increase"),zoomOut:()=>X("decrease"),resetZoom:()=>X("reset"),direction:a,isZoomMode:g,setIsZoomMode:b,isMultiSelectMode:x,setIsMultiSelectMode:m,isDragMode:w,setIsDragMode:v,isEdgeHandlesEnabled:C,setIsEdgeHandlesEnabled:S,isArrayNodeMode:j,setIsArrayNodeMode:T,selectedNodeIds:d,selectedNodeData:te,selectedEdgeId:p,selectedEdgeData:Z,onNodeDeselect:xe,onEdgeDeselect:de,callbacks:R})})]}):h.jsxs(h.Fragment,{children:[se&&h.jsx(z.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:U({selectedNodeIds:d,selectedNodeData:te,onDeselect:xe})}),De&&Z&&h.jsx(z.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:pe({edgeId:p,edgeData:Z,onDeselect:de})}),h.jsx(z.Box,{ref:ye,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:Qe?"translateY(0)":"translateY(100%)",pointerEvents:Qe?"auto":"none",visibility:Qe?"visible":"hidden",opacity:Qe?1:0,css:{"@media (hover: none)":{visibility:"visible",opacity:1,transform:"none",pointerEvents:"auto"}},children:h.jsxs(z.Flex,{w:"100%",px:5,position:"absolute",bottom:"calc(20px + env(safe-area-inset-bottom, 0px))",flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:"24px",children:[h.jsx(vm,{background:V,border:W?ue:"gray.300",children:h.jsxs(z.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[Ie?h.jsx(hm,{edgeId:p,onClose:de}):qe?h.jsx(gm,{ids:d,onClose:xe}):null,h.jsxs("div",{style:{display:Ie||qe?"none":"contents"},children:[h.jsx(Te,{label:k?"Unpin":"Pin",children:h.jsx(Se,{"aria-label":"Pin",icon:h.jsx(z.Icon,{as:k?J.PiPushPinFill:J.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:k?t:ne,onClick:()=>{M(!k),N(!1)}})}),h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:"Zoom Out",children:h.jsx(Se,{"aria-label":"Zoom out",icon:h.jsx(z.Icon,{as:J.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:Q,onClick:()=>X("decrease")})}),h.jsx(Te,{label:"Zoom In",children:h.jsx(Se,{"aria-label":"Zoom in",icon:h.jsx(z.Icon,{as:J.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:Q,onClick:()=>X("increase")})}),h.jsx(Te,{label:"Reset Zoom",children:h.jsx(Se,{"aria-label":"Reset zoom",icon:h.jsx(z.Icon,{as:J.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:Q,onClick:()=>X("reset")})}),!ee&&h.jsxs(h.Fragment,{children:[h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:g?"Zoom Mode (z)":"Pan Mode (z)",children:h.jsx(Se,{"aria-label":"Toggle zoom mode",icon:h.jsx(z.Icon,{as:g?J.PiMagnifyingGlassPlus:J.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:g?t:ne,onClick:()=>b(!g)})}),h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:x?"Multi-Select On (m)":"Multi-Select Off (m)",children:h.jsx(Se,{"aria-label":"Toggle multi-select",icon:h.jsx(z.Icon,{as:J.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:x?t:ne,onClick:()=>m(!x)})}),h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:w?"Drag Mode On (d)":"Drag Mode Off (d)",children:h.jsx(Se,{"aria-label":"Toggle drag mode",icon:h.jsx(z.Icon,{as:J.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:w?t:ne,onClick:()=>v(!w)})}),_.edgeHandles!==!1&&h.jsxs(h.Fragment,{children:[h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:C?"Draw Mode On":"Draw Mode Off",children:h.jsx(Se,{"aria-label":"Toggle draw mode",icon:h.jsx(z.Icon,{as:J.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:C?t:ne,onClick:()=>S(!C)})})]}),_.bottomBarExtra&&h.jsxs(h.Fragment,{children:[h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le,role:"separator","aria-orientation":"vertical"}),_.bottomBarExtra]}),h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le,role:"separator","aria-orientation":"vertical"}),h.jsx(Uy,{}),h.jsx(Tu,{label:"Collapse all",checked:c,icon:h.jsx(z.Icon,{as:J.PiArrowsInLineVertical,boxSize:5}),onChange:l}),u!=="properties"&&h.jsxs(h.Fragment,{children:[h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:j?"Array Mode [ ]":"Set Mode { }",children:h.jsx(Se,{"aria-label":"Toggle array mode",icon:h.jsx(z.Icon,{as:j?J.PiBracketsSquare:J.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:j?t:ne,onClick:()=>{var _e;const we=!j;T(we),(_e=R.onArrayModeChange)==null||_e.call(R,we)}})})]}),i&&!A&&h.jsxs(h.Fragment,{children:[h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(vt,{label:"Graph theme",colors:bn,value:t,includeTransparent:!1,onPick:we=>{var _e;r(we),(_e=R.onThemeColorChange)==null||_e.call(R,we)}})]}),h.jsx(wm,{}),!A&&h.jsx(vt,{label:"Graph edge color",colors:bn,value:n||(W?"gray.500":wt),onPick:o,onReset:()=>o("")}),h.jsx(Ky,{})]}),h.jsx(z.Icon,{mx:-1,as:J.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:ee?"Expand toolbar":"Collapse toolbar",children:h.jsx(Se,{"aria-label":"Toggle toolbar collapse",icon:h.jsx(z.Icon,{as:ee?J.PiCaretRight:J.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:ne,onClick:()=>ge(!ee)})}),!ee&&h.jsx(bm,{})]})]})}),!Ue&&h.jsxs(z.Box,{position:"relative",ml:"auto",flexShrink:0,children:[h.jsx(z.Box,{"data-flow-direction-control":"",bg:V,borderRadius:"30px",h:50,css:Vr($,D),px:3,cursor:"pointer",onClick:()=>N(!G),children:h.jsxs(z.Flex,{align:"center",h:"100%",children:[h.jsx(Te,{label:"Flow Direction",children:h.jsx(Se,{"aria-label":"Direction",icon:h.jsx(z.Icon,{as:J.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:ne})}),h.jsx(z.Text,{fontSize:"xs",color:W?"whiteAlpha.600":"blackAlpha.500",ml:1,children:a})]})}),G&&h.jsx(z.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:h.jsxs(z.Box,{bg:V,borderRadius:"30px",p:2,minW:"180px",css:Vr($,D),children:[h0.map(we=>h.jsxs(z.Flex,{align:"center",gap:3,px:3,py:2,css:_u,cursor:"pointer",_hover:{bg:W?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var _e;(_e=R.onDirectionChange)==null||_e.call(R,we.value),N(!1)},children:[h.jsx(z.Icon,{as:we.icon,boxSize:5,color:Q}),h.jsx(z.Text,{fontSize:"sm",color:Q,flex:1,whiteSpace:"nowrap",children:we.label}),a===we.value&&h.jsx(z.Icon,{as:J.PiCheck,boxSize:4,color:he})]},we.value)),h.jsxs(z.Flex,{align:"center",gap:3,px:3,py:2,css:_u,cursor:"pointer",_hover:{bg:W?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var we;(we=R.onDirectionChange)==null||we.call(R,"C"),N(!1)},children:[h.jsx(z.Icon,{as:J.PiAlignCenterHorizontal,boxSize:5,color:Q}),h.jsx(z.Text,{fontSize:"sm",color:Q,flex:1,whiteSpace:"nowrap",children:"Center"}),a==="C"&&h.jsx(z.Icon,{as:J.PiCheck,boxSize:4,color:he})]})]})})]})]})})]})};Cm.displayName="BottomBar";const _m=E.memo(Cm);function p0({checked:e,onChange:t,disabled:r,label:n="Connected nodes"}){return h.jsx(Tu,{label:n,checked:e,onChange:t,disabled:r,icon:h.jsx(z.Icon,{as:J.PiGraph,boxSize:5})})}const Il={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function Sm(e,t){const r=new Map,n=(i,s)=>{if(Object.is(i,s))return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const a=Object.keys(i);return a.length===Object.keys(s).length&&a.every(u=>Object.prototype.hasOwnProperty.call(s,u)&&n(i[u],s[u]))},o=(i,s,a)=>{if(i===s)return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const u=new Set([...Object.keys(i),...Object.keys(s)]);for(const c of u)if(!n(i[c],s[c])){if(Object.prototype.hasOwnProperty.call(Il,c)){if(typeof s[c]!="string"||!s[c])return!1;r.set(a,{...r.get(a),[Il[c]]:s[c]})}else if(c.startsWith("$")&&c!=="$"||!o(i[c],s[c],c==="$"?a:`${a}.${c}`))return!1}return!0};if(o(e,t,"root"))return r}function g0(e,t){return Sm(e,t)!==void 0}function y0(e,t,r){if(e===t)return r;const n=Sm(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)||!je(t,i))return;return{edges:r.edges,nodes:r.nodes.map(i=>{const s=n.get(i.data.id),a=je(e,i.data.id),u=je(t,i.data.id);return!s&&a===u?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(u,null,2)}:{},...s?{viewProps:{...i.data.viewProps,...s},config:{...i.data.config,...s}}:{}}}})}}function Eu(e){return e.kind==="literal"?e.value:e.kind==="union"?Eu(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,t])=>!t.optional).map(([t,r])=>[t,Eu(r.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Em(e,t,r){var b,x,m;const n=(b=je(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 s=i.pop(),a=["root",...i].join("."),u=_t(e,a,r),c=(x=u==null?void 0:u.type.properties[s])==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)||_r(l.properties[w].type,v,!l.properties[w].optional))throw new Error(`Invalid creation default: ${w}`);const f={...Eu(l),...structuredClone(d)};((m=l.properties.id)==null?void 0:m.type.kind)==="string"&&(f.id=Ou());let p=e;const y=je(e,o.$address);if(y===void 0)p=mr(e,a,w=>({...w,[s]:[]}));else if(!Array.isArray(y)&&!Array.isArray(y==null?void 0:y.$))throw new Error("Form creation destination is not an array.");const g=qu(p,o.$address,{...f,$label:o.$label??o.$type,...o.$icon?{$icon:o.$icon}:{},$form:{$type:o.$type,$create:o}});return{address:g.address,json:Nu(g.json,t,{target:g.address,label:o.$edgeLabel})}}function m0(e,t){const r=o=>e&&typeof e=="object"&&o in e;let n=1;for(;r(`${t}_${n}`);)n++;return`${t}_${n}`}function jm(e,t,r,n,o){const i=(a,u)=>{a!==e&&(e=a,n==null||n(a,u))},s=a=>{var c;const u=(c=t.find(l=>l.data.id===a))==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:a=>{const u=je(e,a.nodeAddress);if(!u||a.nodeId!==void 0&&u.id!==a.nodeId)throw new Error("This form node has moved. Retry the edit.");i(jn(e,a,r.onFormChange),{type:"form",address:a.address,value:a.value})},onNodeLabelChange:(a,u)=>{var c;(c=r.onNodeLabelChange)==null||c.call(r,a,u),i(cr(e,a,"$label",u),{type:"nodeLabel",address:a,key:"$label",value:u})},onNodeContentChange:(a,u)=>{var c;(c=r.onNodeContentChange)==null||c.call(r,a,u),i(cr(e,a,"$content",u),{type:"nodeContent",address:a,key:"$content",value:u})},onNodeTypeViewChange:(a,u)=>{var c;u!==void 0&&!Kt.includes(u)||((c=r.onNodeTypeViewChange)==null||c.call(r,a,u),i(cr(e,a,"$view",u),{type:"nodeStyle",address:a,key:"$view",value:u}))},onNodeColorChange:(a,u,c)=>{var d;(d=r.onNodeColorChange)==null||d.call(r,a,u,c);const l=u==="bg"?"$bgColor":"$textColor";i(cr(e,a,l,c),{type:"nodeColor",address:a,key:l,value:c})},onNodeBorderColorChange:(a,u)=>{var c;(c=r.onNodeBorderColorChange)==null||c.call(r,a,u),i(cr(e,a,"$borderColor",u),{type:"nodeColor",address:a,key:"$borderColor",value:u})},onNodeBorderStyleChange:(a,u)=>{var c;(c=r.onNodeBorderStyleChange)==null||c.call(r,a,u),i(cr(e,a,"$borderStyle",u),{type:"nodeStyle",address:a,key:"$borderStyle",value:u})},onNodeBorderWidthChange:(a,u)=>{var c;u!==void 0&&(!Number.isFinite(u)||u<0)||((c=r.onNodeBorderWidthChange)==null||c.call(r,a,u),i(cr(e,a,"$borderWidth",u),{type:"nodeStyle",address:a,key:"$borderWidth",value:u}))},onNodeBorderRadiusChange:(a,u)=>{var c;u!==void 0&&(!Number.isFinite(u)||u<0)||((c=r.onNodeBorderRadiusChange)==null||c.call(r,a,u),i(cr(e,a,"$borderRadius",u),{type:"nodeStyle",address:a,key:"$borderRadius",value:u}))},onNodeIconChange:(a,u)=>{var c;(c=r.onNodeIconChange)==null||c.call(r,a,u),i(cr(e,a,"$icon",u),{type:"nodeIcon",address:a,key:"$icon",value:u})},onNodeOutlineChange:(a,u)=>{var c;(c=r.onNodeOutlineChange)==null||c.call(r,a,u),i(cr(e,a,"$outline",u),{type:"nodeOutline",address:a,key:"$outline",value:u})},onNodeAnimationChange:(a,u)=>{var c;(c=r.onNodeAnimationChange)==null||c.call(r,a,u),i(cr(e,a,"$isNodeAnimated",u),{type:"nodeAnimation",address:a,key:"$isNodeAnimated",value:u})},onNodeAnimationVariantChange:(a,u)=>{var c;u!=="traveling"&&u!=="pulse"||((c=r.onNodeAnimationVariantChange)==null||c.call(r,a,u),i(cr(e,a,"$nodeAnimationVariant",u),{type:"nodeAnimation",address:a,key:"$nodeAnimationVariant",value:u}))},onNodeCollapse:(a,u)=>{var c;(c=r.onNodeCollapse)==null||c.call(r,a,u),i(Qy(e,a,u),{type:"nodeCollapse",address:a,key:"$collapsed",value:u})},onNodeCreate:a=>{var p,y;const u=a.sourceNodeId&&Em(e,a.sourceNodeId,o);if(u){(p=r.onNodeCreate)==null||p.call(r,a),i(u.json,{type:"nodeCreate",address:u.address,value:"form"});return}(y=r.onNodeCreate)==null||y.call(r,a);const c=a.sourceNodeId||"root",l=je(e,c),d=m0(l,a.isArrayMode?"list":"node"),f=qu(e,c,a.isArrayMode?[]:{},d);i(f.json,{type:"nodeCreate",address:f.address,value:a.isArrayMode?"array":"set"})},onNodeDelete:(a,u)=>{var c;(c=r.onNodeDelete)==null||c.call(r,a,u),i(rm(e,a),{type:"nodeDelete",address:a})},onEdgeCreate:(a,u,c)=>{var d;(d=r.onEdgeCreate)==null||d.call(r,a,u,c);const l=c&&(c.sourceProperty!==void 0||c.targetProperty!==void 0)?{...c,target:u}:void 0;i(l?Nu(e,a,l):tm(e,a,u),{type:"edgeCreate",address:a,key:l?"$connections":"$target",value:l??u})},onEdgeLabelChange:(a,u)=>{var l;(l=r.onEdgeLabelChange)==null||l.call(r,a,u);const c=s(a);c&&i(zr(e,c,"$sourceLabel",u),{type:"edgeLabel",edge:c,key:c.connection?"$connections":"$sourceLabel",value:u})},onEdgeStyleChange:(a,u)=>{var l;(l=r.onEdgeStyleChange)==null||l.call(r,a,u);const c=s(a);c&&i(em(e,c,u),{type:"edgeStyle",edge:c,value:u})},onEdgeAnimationVariantChange:(a,u)=>{var l;if(u!=="dashed"&&u!=="traveling")return;(l=r.onEdgeAnimationVariantChange)==null||l.call(r,a,u);const c=s(a);c&&i(zr(e,c,"$edgeAnimationVariant",u),{type:"edgeStyle",edge:c,key:c.connection?"$connections":"$edgeAnimationVariant",value:u})},onEdgeTypeChange:(a,u)=>{var l;(l=r.onEdgeTypeChange)==null||l.call(r,a,u);const c=s(a);c&&i(zr(e,c,"$edgeType",u),{type:"edgeStyle",edge:c,key:c.connection?"$connections":"$edgeType",value:u})},onEdgeIconChange:(a,u)=>{var l;(l=r.onEdgeIconChange)==null||l.call(r,a,u);const c=s(a);c&&i(zr(e,c,"$edgeIcon",u||void 0),{type:"edgeStyle",edge:c,key:c.connection?"$connections":"$edgeIcon",value:u})},onEdgeColorChange:(a,u)=>{var l;(l=r.onEdgeColorChange)==null||l.call(r,a,u);const c=s(a);c&&i(zr(e,c,"$edgeColor",u),{type:"edgeColor",edge:c,key:c.connection?"$connections":"$edgeColor",value:u})},onEdgeDelete:(a,u)=>{var d;(d=r.onEdgeDelete)==null||d.call(r,a,u);const c=s(a);if(!c)return;const l=nm(e,c);l.removed&&i(l.json,{type:"edgeDelete",edge:c,key:c.connection?"$connections":"$target"})}}}const b0=".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 v0({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 x0=".flow-sdk-edge-reveal{animation:flow-sdk-edge-reveal var(--flow-edge-reveal-duration,600ms) linear both;animation-play-state:var(--flow-edge-reveal-state,running)}.flow-sdk-edge-reveal-end{animation:flow-sdk-edge-reveal-end var(--flow-edge-reveal-duration,600ms) steps(1,end) both;animation-play-state:var(--flow-edge-reveal-state,running)}@keyframes flow-sdk-edge-reveal{from{stroke-dashoffset:var(--flow-edge-reveal-from,100)}to{stroke-dashoffset:0}}@keyframes flow-sdk-edge-reveal-end{from{opacity:0}to{opacity:1}}@media(prefers-reduced-motion:reduce){.flow-sdk-edge-reveal{animation:none;stroke-dashoffset:0}.flow-sdk-edge-reveal-end{animation:none;opacity:1}}";function w0({path:e,width:t,reversed:r,children:n,onComplete:o}){const i=`flow-edge-reveal-${E.useId().replace(/:/g,"")}`,s=E.useRef(null),[a,u]=E.useState({x:0,y:0,width:1,height:1});return E.useEffect(()=>{const c=matchMedia("(prefers-reduced-motion: reduce)"),l=()=>{c.matches&&(o==null||o())};return l(),c.addEventListener("change",l),()=>c.removeEventListener("change",l)},[o]),E.useLayoutEffect(()=>{var l;const c=(l=s.current)==null?void 0:l.getBBox();c&&u({x:c.x-t,y:c.y-t,width:c.width+t*2,height:c.height+t*2})},[e,t]),h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsx("mask",{id:i,maskUnits:"userSpaceOnUse",...a,children:h.jsx("path",{ref:s,className:"flow-sdk-edge-reveal",onAnimationEnd:c=>{c.animationName==="flow-sdk-edge-reveal"&&(o==null||o())},"data-reveal-direction":r?"reverse":"forward",style:{"--flow-edge-reveal-from":r?-100:100},d:e,fill:"none",stroke:"white",strokeWidth:t,strokeLinecap:"butt",strokeLinejoin:"round",pathLength:100,strokeDasharray:"100 100"})})}),h.jsx("g",{mask:`url(#${i})`,children:n})]})}const C0=".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 Rm({x:e=0,y:t=0,width:r,height:n,radius:o,color:i,strokeWidth:s=8,path:a,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=a?"path":"rect",f=a?{d:a}:{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=s+36,y={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",...y,style:{maskType:"luminance"},children:[h.jsx("rect",{...y,fill:"white"}),h.jsx(d,{...f,fill:"black",stroke:"black",strokeWidth:s,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":`${s+16}px`,"--flow-pulse-expanded-width":`${s+36}px`}})]})}return a?h.jsx("path",{className:l,"data-animation-variant":u,"aria-hidden":"true",pointerEvents:"none",d:a,fill:"none",stroke:i,strokeWidth:s,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:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const _0=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 Ml(e,t,r){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const s of t)(s.parent===i||s.id.startsWith(`${i}.`)||r.some(u=>(u.inverted?u.target:u.source)===i&&(u.inverted?u.source:u.target)===s.id))&&!n.has(s.id)&&(n.add(s.id),o.push(s.id))}return n}function S0(e,t,r){const n=r==="downward"||r==="upward",o=new Map;for(const s of e){if(s.source===s.target||s.sourceProperty||s.targetProperty)continue;const a=t(s.source),u=t(s.target);if(!a||!u)continue;const c=n?u.y-a.y:u.x-a.x,l=Math.abs(c)-(n?a.h+u.h:a.w+u.w)/2;if(l<=320)continue;const d=JSON.stringify([s.source,Math.sign(c)]),f=o.get(d)??[];f.push({edge:s,gap:l,cross:n?u.x-a.x:u.y-a.y}),o.set(d,f)}const i=new Map;for(const s of o.values()){if(new Set(s.map(({edge:u})=>u.target)).size<2)continue;const a=new Map;for(const{edge:u}of s)a.set(u.target,(a.get(u.target)??0)+1);for(const u of[-1,0,1]){const c=s.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},y)=>{const g=c.length===1?l/2:120+(l-280)*y/(c.length-1),b=c.find(x=>Math.abs(x.cross)<Math.abs(p));i.set(d.id,{turn:g/f,labelAtTarget:a.get(d.target)===1,labelFraction:p?(p+((b==null?void 0:b.cross)??0))/(2*p):.5})})}}return i}const ft=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}),E0=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function ro(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 j0=(e,t)=>e.x1<=t.x2&&e.x2>=t.x1&&e.y1<=t.y2&&e.y2>=t.y1,ql=(e,t)=>e.x>=t.x1&&e.x<=t.x2&&e.y>=t.y1&&e.y<=t.y2,hr=e=>(Math.round(e*10)/10).toString(),rr=e=>`${hr(e.x)} ${hr(e.y)}`,R0=e=>e>0?1:e<0?-1:0,Nl=(e,t)=>e>0?Math.max(e-t,0):Math.min(e+t,0);function k0(e,t,r,n,o=10){const i=t.x-e.x,s=t.y-e.y,a=Nl(i,(e.w+t.w)/2),u=Nl(s,(e.h+t.h)/2),c=r==="downward"||r==="upward",l=c?u:a,d=c?s:i,f=R0(d),p=n*l,y=m=>Math.abs(m)<o||Math.abs(m)>=Math.abs(l),g=y(p)||y(Math.abs(l)-Math.abs(p));let b;if(g)if(c)if(Math.abs(d)<=e.h/2){const m=(e.x+t.x)/2;b=[m,e.y,m,t.y]}else if(Math.abs(i)<=t.w/2){const m=(e.y+t.y)/2;b=[e.x,m,t.x,m]}else b=[e.x,t.y];else if(Math.abs(d)<=e.w/2){const m=(e.y+t.y)/2;b=[e.x,m,t.x,m]}else if(Math.abs(s)<=t.h/2){const m=(e.x+t.x)/2;b=[m,e.y,m,t.y]}else b=[t.x,e.y];else if(c){const m=e.y+p+e.h/2*f;b=[e.x,m,t.x,m]}else{const m=e.x+p+e.w/2*f;b=[m,e.y,m,t.y]}const x=[{x:e.x,y:e.y}];for(let m=0;m<b.length;m+=2)x.push({x:b[m],y:b[m+1]});return x.push({x:t.x,y:t.y}),x}function P0(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,s=o>0?(r.y2-e.y)/o:o<0?(r.y1-e.y)/o:1/0,a=Math.min(i,s);return!Number.isFinite(a)||a>=1||a<0?null:{x:e.x+n*a,y:e.y+o*a}}function xt(e,t,r){var s;if(!((s=r.outline)!=null&&s.length))return P0(e,t,ft(r));const n=t.x-e.x,o=t.y-e.y;let i=1/0;return r.outline.forEach((a,u,c)=>{const l=c[(u+1)%c.length],d=l.x-a.x,f=l.y-a.y,p=n*f-o*d;if(Math.abs(p)<1e-9)return;const y=a.x-e.x,g=a.y-e.y,b=(y*f-g*d)/p,x=(y*o-g*n)/p;b>=0&&b<1&&x>=-1e-9&&x<=1+1e-9&&(i=Math.min(i,b))}),Number.isFinite(i)?{x:e.x+n*i,y:e.y+o*i}:null}function km(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,s={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},a=Math.max(e.w,e.h)*2+1;return{...xt(s,{x:s.x+(o?0:i*a),y:s.y+(o?i*a:0)},e)??{x:o?s.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:s.y},side:t}}function gt(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 A0(e,t,r,n){const o=gt(e,r.srcDist),i=gt(t,r.tgtDist);if(n==="straight")return Am(o,i,r);const s=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),a=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=a!==void 0&&a>0?Math.min(s,a/2):s,c=gt({...o,side:e.side},u),l=gt({...i,side:t.side},u),d=r.arrowAt==="source"?or(o,c,r.arrowGap):o,f=r.arrowAt==="target"?or(i,l,r.arrowGap):i,p=r.arrowAt==="source"?vr(o,c,r.arrowSize,r.headShape):r.arrowAt==="target"?vr(i,l,r.arrowSize,r.headShape):void 0;if(n==="bezier")return{d:`M${rr(d)} C${rr(c)} ${rr(l)} ${rr(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 y=e.side==="left"||e.side==="right",g=t.side==="left"||t.side==="right";let b;if(y!==g){const m=y?{x:l.x,y:c.y}:{x:c.x,y:l.y},w=(m.x-c.x)*(c.x-o.x)+(m.y-c.y)*(c.y-o.y)>=0,v=(m.x-l.x)*(l.x-i.x)+(m.y-l.y)*(l.y-i.y)>=0;b=[w&&v?m:y?{x:c.x,y:l.y}:{x:l.x,y:c.y}]}else if(a!==void 0&&a<=0)if(y){const m=(c.y+l.y)/2;b=[{x:c.x,y:m},{x:l.x,y:m}]}else{const m=(c.x+l.x)/2;b=[{x:m,y:c.y},{x:m,y:l.y}]}else if(y){const m=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:m,y:c.y},{x:m,y:l.y}]}else{const m=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:m},{x:l.x,y:m}]}const x=[c,...b,l].filter((m,w,v)=>w===0||m.x!==v[w-1].x||m.y!==v[w-1].y);return Rn(d,x,f,p,n==="orthogonal"?0:r.radius)}function or(e,t,r){const n=e.x-t.x,o=e.y-t.y,i=Math.hypot(n,o);if(!i)return e;let s=(i-r)/i;return s<0&&(s=1e-5),{x:t.x+s*n,y:t.y+s*o}}function vr(e,t,r,n="triangle"){const o=e.x-t.x,i=e.y-t.y,s=Math.hypot(o,i)||1,a=o/s,u=i/s,c=(n==="square"?.15:.3)*r,l=.15*r,d=e.x-a*c,f=e.y-u*c;return n==="square"?`M${rr(e)} L${hr(e.x-u*l)} ${hr(e.y+a*l)} L${hr(d-u*l)} ${hr(f+a*l)} L${hr(d+u*l)} ${hr(f-a*l)} L${hr(e.x+u*l)} ${hr(e.y-a*l)} Z`:`M${rr(e)} L${hr(d-u*l)} ${hr(f+a*l)} L${hr(d+u*l)} ${hr(f-a*l)} Z`}function Br(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 T0(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},s=Math.hypot(o.x,o.y),a=Math.hypot(i.x,i.y),u=o.x*i.y-o.y*i.x;if(s<1e-6||a<1e-6||Math.abs(u)<1e-6)return{p1:t,b:t,p2:t,r:0};const c=Math.min(n,s/2,a/2);return{p1:{x:t.x-o.x/s*c,y:t.y-o.y/s*c},b:t,p2:{x:t.x+i.x/a*c,y:t.y+i.y/a*c},r:c}}function Pm(e,t,r,n){let o=-1,i=null;for(let y=0;y<e.length-1;y++){const g=xt(e[y],e[y+1],t);if(g){o=y,i=g;break}}let s=-1,a=null;for(let y=e.length-1;y>0;y--){const g=xt(e[y],e[y-1],r);if(g){s=y,a=g;break}}if(!i||!a||o>=s)return null;const u=e.slice(o+1,s),c=u[0]??a,l=u[u.length-1]??i;let d,f,p;if(n.arrowAt==="source"){const y=or(i,c,n.srcDist);d=or(i,c,n.srcDist+n.arrowGap),p=vr(y,c,n.arrowSize,n.headShape)}else d=or(i,c,n.srcDist);if(n.arrowAt==="target"){const y=or(a,l,n.tgtDist);f=or(a,l,n.tgtDist+n.arrowGap),p=vr(y,l,n.arrowSize,n.headShape)}else f=or(a,l,n.tgtDist);return Rn(d,u,f,p,n.radius,n.labelTargetLength,n.labelFraction)}function Rn(e,t,r,n,o,i,s){var f;const a=[e,...t,r],u=[];let c=`M${rr(e)}`;for(let p=1;p<a.length-1;p++){const y=T0(a[p-1],a[p],a[p+1],o);u.push(y),y.r===0?c+=` L${rr(y.b)}`:c+=` L${rr(y.p1)} Q${rr(y.b)} ${rr(y.p2)}`}c+=` L${rr(r)}`;let l;const d=t.length;if(d===0)l={x:(e.x+r.x)/2,y:(e.y+r.y)/2,angle:Br(r.x-e.x,r.y-e.y)};else if(d%2===0){const p=t[d/2-1],y=t[d/2];l={x:(p.x+y.x)/2,y:(p.y+y.y)/2,angle:Br(y.x-p.x,y.y-p.y)}}else{const p=u[(d-1)/2];if(p.r===0){const y=a[(d-1)/2+2];l={x:p.b.x,y:p.b.y,angle:Br(y.x-p.b.x,y.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:Br(p.p2.x-p.p1.x,p.p2.y-p.p1.y)}}if(i!==void 0){if(s!==void 0&&u.length===2){const b=u[0].p2,x=u[1].p1,m=Math.hypot(x.x-b.x,x.y-b.y),w=Math.min(.5,i/(2*m)),v=Math.max(w,Math.min(1-w,s));l={x:b.x+(x.x-b.x)*v,y:b.y+(x.y-b.y)*v,angle:Br(x.x-b.x,x.y-b.y)}}const p=((f=u[u.length-1])==null?void 0:f.p2)??e,y=r.x-p.x,g=r.y-p.y;Math.hypot(y,g)>=i&&(l={x:(p.x+r.x)/2,y:(p.y+r.y)/2,angle:Br(y,g)})}return{d:c,arrow:n,label:l}}function $l(e,t,r,n,o,i,s){const a=r==="leftward"?-1:1,u={x:e.x+a*(e.w/2+s.srcDist),y:n??e.y},c={x:t.x-a*(t.w/2+s.tgtDist),y:o??t.y},l=Math.max(80,s.arrowGap+s.arrowSize*.3),d=u.x+a*l,f=c.x-a*l;let p;if(a*(f-d)>=0){const x=u.x+(c.x-u.x)*i,m=Math.max(Math.min(d,f),Math.min(Math.max(d,f),x));p=[{x:m,y:u.y},{x:m,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 y=s.arrowAt==="source"?or(u,p[0],s.arrowGap):u,g=s.arrowAt==="target"?or(c,p[p.length-1],s.arrowGap):c,b=s.arrowAt==="source"?vr(u,p[0],s.arrowSize,s.headShape):s.arrowAt==="target"?vr(c,p[p.length-1],s.arrowSize,s.headShape):void 0;return Rn(y,p,g,b,s.radius)}function Ll(e,t,r,n,o){return Pm(k0(e,t,r,n),e,t,o)}function Fl(e,t,r,n,o,i){const s=n===void 0&&o===void 0&&(r==="downward"||r==="upward"),a=r==="leftward"||s&&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,y=xt(f,{x:f.x+(s?0:d*p),y:f.y+(s?d*p:0)},c);return y?{x:y.x+(s?0:d*i),y:y.y+(s?d*i:0)}:s?{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,a),targetPoint:u(t,o,-a)}}function O0(e,t,r,n){const o=r==="downward"||r==="upward",i=r==="leftward"||r==="upward"?-1:1,s=Math.max(100,Math.abs(o?t.y-e.y:t.x-e.x)/2),a={x:e.x+(o?0:i*s),y:e.y+(o?i*s:0)},u={x:t.x-(o?0:i*s),y:t.y-(o?i*s:0)},c=n.arrowAt==="source"?or(e,a,n.arrowGap):e,l=n.arrowAt==="target"?or(t,u,n.arrowGap):t;return{d:`M${rr(c)} C${rr(a)} ${rr(u)} ${rr(l)}`,arrow:n.arrowAt==="source"?vr(e,a,n.arrowSize,n.headShape):n.arrowAt==="target"?vr(t,u,n.arrowSize,n.headShape):void 0,label:{x:(c.x+3*a.x+3*u.x+l.x)/8,y:(c.y+3*a.y+3*u.y+l.y)/8,angle:Br(l.x+u.x-a.x-c.x,l.y+u.y-a.y-c.y)}}}function Am(e,t,r){const n=r.arrowAt==="source"?or(e,t,r.arrowGap):e,o=r.arrowAt==="target"?or(t,e,r.arrowGap):t,i=r.arrowAt==="source"?vr(e,t,r.arrowSize,r.headShape):r.arrowAt==="target"?vr(t,e,r.arrowSize,r.headShape):void 0;return Rn(n,[],o,i,0)}function I0(e,t,r,n=-90,o=-60,i=350){const s=n*Math.PI/180,a=o*Math.PI/180,u=s-Math.PI/2,c=u-a/2,l=u+a/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},y={x:e.x,y:e.y},g=xt(y,f,e),b=xt(y,p,e);if(!g||!b)return null;const x={x:(f.x+p.x)/2,y:(f.y+p.y)/2};let m=or(g,f,r.srcDist),w=or(b,p,r.tgtDist),v;if(r.arrowAt==="target"){const S=w;w=or(b,p,r.tgtDist+r.arrowGap),v=vr(S,p,r.arrowSize,r.headShape)}else if(r.arrowAt==="source"){const S=m;m=or(g,f,r.srcDist+r.arrowGap),v=vr(S,f,r.arrowSize,r.headShape)}return{d:`M${rr(m)} Q${rr(f)} ${rr(x)} Q${rr(p)} ${rr(w)}`,arrow:v,label:{x:x.x,y:x.y,angle:Br(p.x-f.x,p.y-f.y)}}}const lt=e=>Math.round(e*1e3)/1e3;function Tm(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,s=typeof i.getScreenCTM=="function"?i.getScreenCTM():null,a=typeof i.getTotalLength=="function"?i.getTotalLength():0,u=i.points,c=(u==null?void 0:u.numberOfItems)||128,l=s&&a>0?Array.from({length:c},(d,f)=>{const p=u!=null&&u.numberOfItems?u.getItem(f):i.getPointAtLength(a*f/c);return{x:lt((s.a*p.x+s.c*p.y+s.e-r.left)/n),y:lt((s.b*p.x+s.d*p.y+s.f-r.top)/n)}}):void 0;return{left:lt((o.left-r.left)/n),top:lt((o.top-r.top)/n),width:t instanceof HTMLElement?t.offsetWidth:lt(o.width/n),height:t instanceof HTMLElement?t.offsetHeight:lt(o.height/n),radius:parseFloat(getComputedStyle(t).borderTopLeftRadius)||0,...l?{outline:l}:{}}}function Gt(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 M0(e,t,r,n,o){var l;const i=o!=="TB"&&o!=="BT",s=i?"top":"left",a=i?"bottom":"right",u=new Map;for(const d of n)for(const[f,p,y]of[[d.source,d.sourceProperty,d.target],[d.target,d.targetProperty,d.source]]){const g=t.get(y);if(p===void 0||!g||y===f)continue;const b=r.get(y),x=JSON.stringify([f,p]),m=u.get(x)??[];m.push(b?Gt(g,b):g),u.set(x,m)}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 y=r.get(d),g=y?Gt(p,y):p,b={x:p.w/2,y:p.h/2,w:p.w,h:p.h},x=y?Gt(b,y):b,m=new Map;for(const w of f){if(w.placement!=="config")continue;const C=(u.get(JSON.stringify([d,w.property]))??[]).reduce((j,T)=>j+(i?T.y-g.y:T.x-g.x),0),S=((l=w.anchor)==null?void 0:l.side)===a?a:s;m.set(w,C<-.001?s:C>.001?a:S)}c.set(d,f.map(w=>{const v=m.get(w);if(!v)return w;const C=f.filter(T=>m.get(T)===v),S=(C.indexOf(w)+1)/(C.length+1),j=km(x,v,S);return{...w,anchor:j,top:j.y,height:0}}))}return c}function Bl(e,t,r){const n=new Set(t.map(a=>a.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const a of t)!o.has(a.id)&&(o.has(a.parent??"")||a.id.startsWith(`${e}.`))&&(o.add(a.id),i=!0)}const s=new Set(o);for(const a of r)o.has(a.source)&&n.has(a.target)&&s.add(a.target),o.has(a.target)&&n.has(a.source)&&s.add(a.source);return s}const ot='"Helvetica Neue", Helvetica, sans-serif';let Tt;const dn=new Map;function kn(e,t){const r=`${t}|${e}`,n=dn.get(r);if(n!==void 0)return n;Tt===void 0&&(Tt=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let o;return Tt?(Tt.font=t,o=Tt.measureText(e).width):o=e.length*(parseFloat(t)||16)*.55,dn.size>5e3&&dn.clear(),dn.set(r,o),o}function q0(e,t,r){const n=[];for(const o of String(e).split(`
203
+ `)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let s="";for(const a of i){const u=s?`${s} ${a}`:a;!s||kn(u,t)<=r?s=u:(n.push(s),s=a)}n.push(s)}return n}const N0=e=>e.stopPropagation();function $0({id:e,rect:t,label:r,labelLayer:n,style:o,onSelect:i,onCollapse:s,selected:a=!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,y=r?kn(r,`bold ${o.fontSize}px ${ot}`):0,g=o.fontSize/5,b=r||a&&s?h.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[a&&s&&h.jsx("foreignObject",{x:f+y/2+g+8,y:p-24,width:48,height:48,"data-flow-content-toggle":"",style:{pointerEvents:"auto"},children:h.jsx(Te,{label:"Show icon",children:h.jsx(Se,{"aria-label":"Show icon",icon:h.jsx(J.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:o.textColor},onClick:x=>{x.stopPropagation(),s(e)}})})}),r&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:f-y/2-g,y:p-o.fontSize/2-g,width:y+2*g,height:o.fontSize+2*g,fill:o.textColor==="transparent"?"transparent":o.labelBg}),h.jsx("text",{x:f,y:p,fill:o.textColor,fontSize:o.fontSize,fontWeight:"bold",fontFamily:ot,style:{fontSize:o.fontSize,fontWeight:"bold",fontFamily:ot},textAnchor:"middle",dominantBaseline:"central",children:r})]})]}):null;return h.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:N0,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(Rm,{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?Ht.createPortal(b,n):b]})}const L0=E.memo($0),vn=45,Om=70,Qr=15,Im=50;function Mm(e,t,r=vn){const n=`${r}px ${ot}`,o=e?q0(e,n,200*r/vn):[],i=t?48+(o.length?12:0):0,s=i+Math.max(0,...o.map(c=>kn(c,n))),a=Math.max(o.length*r,t?48:0),u=o.length||t?2*Qr:0;return{lines:o,iconWidth:i,contentWidth:s,contentHeight:a,width:s+u,height:a+u}}const Ut=6,qm=3,Du=Math.max(Math.pow(Ut*13.37,.9),29)*qm,Nm=Ut*qm*2,hn=80,F0=2*hn+Du*.3+100,B0=36+2*Math.max(80,Nm+Du*.3);function ju(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function Ru(e,t){return t==="auto"||(t==="properties"?ju(e):!ju(e))}function ht(e,t,r){return r!=="properties"||e!=="root"||t.some(n=>(n.source===e||n.target===e)&&ju(n))}function z0(e,t,r,n=!1,o){if(!n)return{nodes:e,edges:t};const i=e.filter(a=>ht(a.id,t,r)&&(!o||o.has(a.id))),s=new Set(i.map(a=>a.id));return{nodes:i,edges:t.filter(a=>Ru(a,r)&&s.has(a.source)&&s.has(a.target))}}const D0=500,V0="32 18",W0=e=>e.stopPropagation();function G0({id:e,reveal:t,onRevealComplete:r,edgeData:n,validationIssue:o,edgeType:i="rounded-orthogonal",edgeRadius:s,customEdgeTypes:a,source:u,target:c,sourceProperty:l,targetProperty:d,sourceY:f,targetY:p,sourcePort:y,targetPort:g,propertyMode:b=!1,dir:x,turn:m,labelAtTarget:w,labelFraction:v,color:C,connectorColor:S,labelBg:j,labelLayer:T,label:k,dashed:M,animated:R,inverted:_,loopIndex:A=0,onSelect:I}){const q=n==null?void 0:n.icon,O=b?vn:Om,{lines:W,iconWidth:V,contentWidth:ue,contentHeight:ne}=E.useMemo(()=>Mm(k,q,O),[k,q,O]),Q=E.useMemo(()=>{const U={srcDist:hn,tgtDist:hn,arrowGap:Nm,arrowSize:Du,headShape:b&&(_?f!==void 0||y:p!==void 0||g)?"square":"triangle",radius:s??(w?40:D0),arrowAt:_?"source":"target",labelTargetLength:w?ue+2*Qr:void 0,labelFraction:w?v:void 0},se=f!==void 0||p!==void 0||!!y||!!g,te=Fl(u,c,x,f,p,0),xe=f===void 0&&p===void 0&&(x==="downward"||x==="upward"),pe=y??{...te.sourcePoint,side:xe?x==="upward"?"top":"bottom":x==="leftward"?"left":"right"},De=g??{...te.targetPoint,side:xe?x==="upward"?"bottom":"top":x==="leftward"?"right":"left"},Z=u.x===c.x&&u.y===c.y,de=y||g?A0(pe,De,{...U,srcDist:18,tgtDist:18},i):se?$l(u,c,x,f,p,m,{...U,srcDist:18,tgtDist:18,radius:s??Math.min(U.radius,40)}):Z?I0(u,A,{...U,srcDist:0,tgtDist:0}):Ll(u,c,x,m,U);if(!de)return null;const Ce=Fl(u,c,x,f,p,se?18:hn);y&&(Ce.sourcePoint=gt(y,18)),g&&(Ce.targetPoint=gt(g,18));const Ie=Object.prototype.hasOwnProperty.call(a??{},i)?a==null?void 0:a[i]:void 0;if(Ie){const qe={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return Ie({edge:n??{id:e,source:"",target:""},source:{...u},target:{...c},...Ce,direction:qe[x],sourceY:f,targetY:p,inverted:!!_,defaultGeometry:de})??de}return Z||y||g?de:i==="straight"?se?Am(Ce.sourcePoint,Ce.targetPoint,U):Pm([u,c],u,c,U):i==="bezier"?O0(Ce.sourcePoint,Ce.targetPoint,se?x==="leftward"?"leftward":"rightward":x,U):i==="orthogonal"?se?$l(u,c,x,f,p,m,{...U,srcDist:18,tgtDist:18,radius:0}):Ll(u,c,x,m,{...U,radius:0}):de},[u,e,n,i,s,a,c,b,f,p,y,g,x,m,_,A,w,v,ue]);if(!Q)return null;const he=(x==="rightward"||x==="leftward")&&!Object.prototype.hasOwnProperty.call(a??{},i)&&!(b&&(f!==void 0||p!==void 0||y||g)),le=he?`translate(${Q.label.x} ${Q.label.y-ne/2-2*Qr})`:`translate(${Q.label.x} ${Q.label.y}) rotate(${Q.label.angle}) translate(${w||Object.prototype.hasOwnProperty.call(a??{},i)?0:Im} 0)`,$=o!=null&&o.startsWith("Unverified:")?"#b45309":"#dc2626",D=o?$:C,G=o?h.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":o,transform:`translate(${Q.label.x} ${Q.label.y-W.length*O/2-55})`,children:[h.jsx("title",{children:o}),h.jsx(kr,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:$})]}):null,N=R&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",ee=!N&&(M||R)?V0:void 0,ge=R&&!N?`flow-sdk-edge-anim${_?" flow-sdk-edge-anim-rev":""}`:void 0;let ye=null;const K=t?{"--flow-edge-reveal-duration":`${t.durationMs??600}ms`,"--flow-edge-reveal-state":t.paused?"paused":"running"}:void 0;if(W.length||q){const U=ue,se=ne;ye=h.jsxs("g",{className:`flow-sdk-edge-label${t?" flow-sdk-edge-reveal-end":""}`,style:K,"data-label-transform":le,"data-label-horizontal":he||void 0,"data-edge-id":e,"data-source-property":l,"data-target-property":d,transform:le,children:[h.jsx("rect",{x:-U/2-Qr,y:-se/2-Qr,width:U+2*Qr,height:se+2*Qr,fill:C==="transparent"?"transparent":j}),h.jsx("text",{fill:C,fontSize:O,style:{fontSize:O,fontFamily:ot},fontFamily:ot,textAnchor:"middle",dominantBaseline:"central",children:W.map((te,xe)=>h.jsx("tspan",{x:V/2,y:(xe-(W.length-1)/2)*O,children:te},xe))}),q&&h.jsxs("g",{className:"flow-sdk-edge-icon",opacity:C==="transparent"?0:1,children:[h.jsx("title",{children:k?`Edge icon: ${k}`:"Edge icon"}),h.jsx("rect",{x:-U/2,y:-24,width:48,height:48,fill:"transparent"}),h.jsx(kr,{name:q,svg:!0,size:48,x:-U/2,y:-24,color:C})]})]})}const X=h.jsxs(h.Fragment,{children:[h.jsx("path",{d:Q.d,fill:"none",stroke:D,strokeWidth:Ut,strokeOpacity:N?.35:void 0,strokeDasharray:ee,className:ge}),N&&h.jsx(v0,{path:Q.d,color:D,width:Ut*1.6,reversed:_})]});return h.jsxs("g",{className:"flow-sdk-edge",style:K,"data-edge-id":e,"data-source-property":l,"data-target-property":d,"data-validation":o?o.startsWith("Unverified:")?"unverified":"invalid":void 0,"aria-label":o,onPointerDown:W0,onClick:U=>{U.stopPropagation(),I==null||I(e)},children:[t?h.jsx(w0,{path:Q.d,width:Ut*4,reversed:_,onComplete:()=>r==null?void 0:r(e),children:X}):X,Q.arrow&&h.jsx("path",{className:t?"flow-sdk-edge-reveal-end":void 0,d:Q.arrow,fill:o?$:S??D}),T&&ye?Ht.createPortal(ye,T):ye,T&&G?Ht.createPortal(G,T):G,h.jsx("path",{className:"flow-sdk-edge-hit",d:Q.d,fill:"none",stroke:"transparent"})]})}const zl=E.memo(G0),Dl=(e,t)=>e.left<t.right&&e.right>t.left&&e.top<t.bottom&&e.bottom>t.top;function U0(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 s=[...t.querySelectorAll(".flow-sdk-edge-label")];for(const c of s)c.setAttribute("transform",c.dataset.labelTransform??"");const a=new Map(s.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 s){const l=c.dataset.labelHorizontal==="true",d=a.get(c);a.delete(c);const f=j=>i.some(T=>Dl(j,T))||[...a.values()].some(T=>Dl(j,T));if(!l&&!f(d)){a.set(c,d);continue}const p=u.get(c.dataset.edgeId),y=c.querySelector("rect");if(!p||!y)continue;const g=y.getBBox(),b=p.getTotalLength();if(!Number.isFinite(b)||b<=0)continue;const x=(d.left+d.right)/2,m=(d.top+d.bottom)/2,w=Math.min(256,Math.max(16,Math.ceil(b/24))),v=Array.from({length:w+1},(j,T)=>p.getPointAtLength(b*T/w)),S=Array.from({length:w+1},(j,T)=>{const k=b*T/w,M=v[T],R=l?{x:M.x,y:M.y-g.height/2-15}:M,_=p.getPointAtLength(Math.max(0,k-2)),A=p.getPointAtLength(Math.min(b,k+2));let I=Math.atan2(A.y-_.y,A.x-_.x)*180/Math.PI;I>90&&(I-=180),I<-90&&(I+=180);const q=Math.abs(I)<1;l&&(I=0);const O=I*Math.PI/180,W=Math.abs(Math.cos(O))*g.width+Math.abs(Math.sin(O))*g.height,V=Math.abs(Math.sin(O))*g.width+Math.abs(Math.cos(O))*g.height;return{point:R,angle:I,straight:q,score:Math.hypot(R.x-x,R.y-m),bounds:{left:R.x-W/2-8,right:R.x+W/2+8,top:R.y-V/2-8,bottom:R.y+V/2+8}}}).sort((j,T)=>j.score-T.score).find(j=>!f(j.bounds)&&(!l||j.straight&&!v.some(T=>T.x>j.bounds.left&&T.x<j.bounds.right&&T.y>j.bounds.top&&T.y<j.bounds.bottom)));S?(c.setAttribute("transform",`translate(${S.point.x} ${S.point.y}) rotate(${S.angle})`),a.set(c,S.bounds)):a.set(c,d)}}var fn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function H0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Vu(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 to,Vl;function K0(){if(Vl)return to;Vl=1;function e(){this.__data__=[],this.size=0}return to=e,to}var no,Wl;function St(){if(Wl)return no;Wl=1;function e(t,r){return t===r||t!==t&&r!==r}return no=e,no}var oo,Gl;function Pn(){if(Gl)return oo;Gl=1;var e=St();function t(r,n){for(var o=r.length;o--;)if(e(r[o][0],n))return o;return-1}return oo=t,oo}var io,Ul;function J0(){if(Ul)return io;Ul=1;var e=Pn(),t=Array.prototype,r=t.splice;function n(o){var i=this.__data__,s=e(i,o);if(s<0)return!1;var a=i.length-1;return s==a?i.pop():r.call(i,s,1),--this.size,!0}return io=n,io}var ao,Hl;function Z0(){if(Hl)return ao;Hl=1;var e=Pn();function t(r){var n=this.__data__,o=e(n,r);return o<0?void 0:n[o][1]}return ao=t,ao}var so,Kl;function Y0(){if(Kl)return so;Kl=1;var e=Pn();function t(r){return e(this.__data__,r)>-1}return so=t,so}var co,Jl;function X0(){if(Jl)return co;Jl=1;var e=Pn();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 co=t,co}var uo,Zl;function An(){if(Zl)return uo;Zl=1;var e=K0(),t=J0(),r=Z0(),n=Y0(),o=X0();function i(s){var a=-1,u=s==null?0:s.length;for(this.clear();++a<u;){var c=s[a];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,uo=i,uo}var lo,Yl;function Q0(){if(Yl)return lo;Yl=1;var e=An();function t(){this.__data__=new e,this.size=0}return lo=t,lo}var fo,Xl;function ew(){if(Xl)return fo;Xl=1;function e(t){var r=this.__data__,n=r.delete(t);return this.size=r.size,n}return fo=e,fo}var ho,Ql;function rw(){if(Ql)return ho;Ql=1;function e(t){return this.__data__.get(t)}return ho=e,ho}var po,ed;function tw(){if(ed)return po;ed=1;function e(t){return this.__data__.has(t)}return po=e,po}var go,rd;function $m(){if(rd)return go;rd=1;var e=typeof fn=="object"&&fn&&fn.Object===Object&&fn;return go=e,go}var yo,td;function Er(){if(td)return yo;td=1;var e=$m(),t=typeof self=="object"&&self&&self.Object===Object&&self,r=e||t||Function("return this")();return yo=r,yo}var mo,nd;function Et(){if(nd)return mo;nd=1;var e=Er(),t=e.Symbol;return mo=t,mo}var bo,od;function nw(){if(od)return bo;od=1;var e=Et(),t=Object.prototype,r=t.hasOwnProperty,n=t.toString,o=e?e.toStringTag:void 0;function i(s){var a=r.call(s,o),u=s[o];try{s[o]=void 0;var c=!0}catch{}var l=n.call(s);return c&&(a?s[o]=u:delete s[o]),l}return bo=i,bo}var vo,id;function ow(){if(id)return vo;id=1;var e=Object.prototype,t=e.toString;function r(n){return t.call(n)}return vo=r,vo}var xo,ad;function it(){if(ad)return xo;ad=1;var e=Et(),t=nw(),r=ow(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function s(a){return a==null?a===void 0?o:n:i&&i in Object(a)?t(a):r(a)}return xo=s,xo}var wo,sd;function xr(){if(sd)return wo;sd=1;function e(t){var r=typeof t;return t!=null&&(r=="object"||r=="function")}return wo=e,wo}var Co,cd;function on(){if(cd)return Co;cd=1;var e=it(),t=xr(),r="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function s(a){if(!t(a))return!1;var u=e(a);return u==n||u==o||u==r||u==i}return Co=s,Co}var _o,ud;function iw(){if(ud)return _o;ud=1;var e=Er(),t=e["__core-js_shared__"];return _o=t,_o}var So,ld;function aw(){if(ld)return So;ld=1;var e=iw(),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 So=r,So}var Eo,dd;function Lm(){if(dd)return Eo;dd=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 Eo=r,Eo}var jo,fd;function sw(){if(fd)return jo;fd=1;var e=on(),t=aw(),r=xr(),n=Lm(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,s=Function.prototype,a=Object.prototype,u=s.toString,c=a.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 jo=d,jo}var Ro,hd;function cw(){if(hd)return Ro;hd=1;function e(t,r){return t==null?void 0:t[r]}return Ro=e,Ro}var ko,pd;function at(){if(pd)return ko;pd=1;var e=sw(),t=cw();function r(n,o){var i=t(n,o);return e(i)?i:void 0}return ko=r,ko}var Po,gd;function Wu(){if(gd)return Po;gd=1;var e=at(),t=Er(),r=e(t,"Map");return Po=r,Po}var Ao,yd;function Tn(){if(yd)return Ao;yd=1;var e=at(),t=e(Object,"create");return Ao=t,Ao}var To,md;function uw(){if(md)return To;md=1;var e=Tn();function t(){this.__data__=e?e(null):{},this.size=0}return To=t,To}var Oo,bd;function lw(){if(bd)return Oo;bd=1;function e(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r}return Oo=e,Oo}var Io,vd;function dw(){if(vd)return Io;vd=1;var e=Tn(),t="__lodash_hash_undefined__",r=Object.prototype,n=r.hasOwnProperty;function o(i){var s=this.__data__;if(e){var a=s[i];return a===t?void 0:a}return n.call(s,i)?s[i]:void 0}return Io=o,Io}var Mo,xd;function fw(){if(xd)return Mo;xd=1;var e=Tn(),t=Object.prototype,r=t.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:r.call(i,o)}return Mo=n,Mo}var qo,wd;function hw(){if(wd)return qo;wd=1;var e=Tn(),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 qo=r,qo}var No,Cd;function pw(){if(Cd)return No;Cd=1;var e=uw(),t=lw(),r=dw(),n=fw(),o=hw();function i(s){var a=-1,u=s==null?0:s.length;for(this.clear();++a<u;){var c=s[a];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,No=i,No}var $o,_d;function gw(){if(_d)return $o;_d=1;var e=pw(),t=An(),r=Wu();function n(){this.size=0,this.__data__={hash:new e,map:new(r||t),string:new e}}return $o=n,$o}var Lo,Sd;function yw(){if(Sd)return Lo;Sd=1;function e(t){var r=typeof t;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?t!=="__proto__":t===null}return Lo=e,Lo}var Fo,Ed;function On(){if(Ed)return Fo;Ed=1;var e=yw();function t(r,n){var o=r.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return Fo=t,Fo}var Bo,jd;function mw(){if(jd)return Bo;jd=1;var e=On();function t(r){var n=e(this,r).delete(r);return this.size-=n?1:0,n}return Bo=t,Bo}var zo,Rd;function bw(){if(Rd)return zo;Rd=1;var e=On();function t(r){return e(this,r).get(r)}return zo=t,zo}var Do,kd;function vw(){if(kd)return Do;kd=1;var e=On();function t(r){return e(this,r).has(r)}return Do=t,Do}var Vo,Pd;function xw(){if(Pd)return Vo;Pd=1;var e=On();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 Vo=t,Vo}var Wo,Ad;function Gu(){if(Ad)return Wo;Ad=1;var e=gw(),t=mw(),r=bw(),n=vw(),o=xw();function i(s){var a=-1,u=s==null?0:s.length;for(this.clear();++a<u;){var c=s[a];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,Wo=i,Wo}var Go,Td;function ww(){if(Td)return Go;Td=1;var e=An(),t=Wu(),r=Gu(),n=200;function o(i,s){var a=this.__data__;if(a instanceof e){var u=a.__data__;if(!t||u.length<n-1)return u.push([i,s]),this.size=++a.size,this;a=this.__data__=new r(u)}return a.set(i,s),this.size=a.size,this}return Go=o,Go}var Uo,Od;function In(){if(Od)return Uo;Od=1;var e=An(),t=Q0(),r=ew(),n=rw(),o=tw(),i=ww();function s(a){var u=this.__data__=new e(a);this.size=u.size}return s.prototype.clear=t,s.prototype.delete=r,s.prototype.get=n,s.prototype.has=o,s.prototype.set=i,Uo=s,Uo}var Ho,Id;function Uu(){if(Id)return Ho;Id=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 Ho=e,Ho}var Ko,Md;function Fm(){if(Md)return Ko;Md=1;var e=at(),t=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return Ko=t,Ko}var Jo,qd;function Mn(){if(qd)return Jo;qd=1;var e=Fm();function t(r,n,o){n=="__proto__"&&e?e(r,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):r[n]=o}return Jo=t,Jo}var Zo,Nd;function qn(){if(Nd)return Zo;Nd=1;var e=Mn(),t=St(),r=Object.prototype,n=r.hasOwnProperty;function o(i,s,a){var u=i[s];(!(n.call(i,s)&&t(u,a))||a===void 0&&!(s in i))&&e(i,s,a)}return Zo=o,Zo}var Yo,$d;function an(){if($d)return Yo;$d=1;var e=qn(),t=Mn();function r(n,o,i,s){var a=!i;i||(i={});for(var u=-1,c=o.length;++u<c;){var l=o[u],d=s?s(i[l],n[l],l,i,n):void 0;d===void 0&&(d=n[l]),a?t(i,l,d):e(i,l,d)}return i}return Yo=r,Yo}var Xo,Ld;function Cw(){if(Ld)return Xo;Ld=1;function e(t,r){for(var n=-1,o=Array(t);++n<t;)o[n]=r(n);return o}return Xo=e,Xo}var Qo,Fd;function Ar(){if(Fd)return Qo;Fd=1;function e(t){return t!=null&&typeof t=="object"}return Qo=e,Qo}var ei,Bd;function _w(){if(Bd)return ei;Bd=1;var e=it(),t=Ar(),r="[object Arguments]";function n(o){return t(o)&&e(o)==r}return ei=n,ei}var ri,zd;function sn(){if(zd)return ri;zd=1;var e=_w(),t=Ar(),r=Object.prototype,n=r.hasOwnProperty,o=r.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(s){return t(s)&&n.call(s,"callee")&&!o.call(s,"callee")};return ri=i,ri}var ti,Dd;function tr(){if(Dd)return ti;Dd=1;var e=Array.isArray;return ti=e,ti}var Nt={exports:{}},ni,Vd;function Sw(){if(Vd)return ni;Vd=1;function e(){return!1}return ni=e,ni}Nt.exports;var Wd;function jt(){return Wd||(Wd=1,(function(e,t){var r=Er(),n=Sw(),o=t&&!t.nodeType&&t,i=o&&!0&&e&&!e.nodeType&&e,s=i&&i.exports===o,a=s?r.Buffer:void 0,u=a?a.isBuffer:void 0,c=u||n;e.exports=c})(Nt,Nt.exports)),Nt.exports}var oi,Gd;function Nn(){if(Gd)return oi;Gd=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 oi=r,oi}var ii,Ud;function Hu(){if(Ud)return ii;Ud=1;var e=9007199254740991;function t(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return ii=t,ii}var ai,Hd;function Ew(){if(Hd)return ai;Hd=1;var e=it(),t=Hu(),r=Ar(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",s="[object Date]",a="[object Error]",u="[object Function]",c="[object Map]",l="[object Number]",d="[object Object]",f="[object RegExp]",p="[object Set]",y="[object String]",g="[object WeakMap]",b="[object ArrayBuffer]",x="[object DataView]",m="[object Float32Array]",w="[object Float64Array]",v="[object Int8Array]",C="[object Int16Array]",S="[object Int32Array]",j="[object Uint8Array]",T="[object Uint8ClampedArray]",k="[object Uint16Array]",M="[object Uint32Array]",R={};R[m]=R[w]=R[v]=R[C]=R[S]=R[j]=R[T]=R[k]=R[M]=!0,R[n]=R[o]=R[b]=R[i]=R[x]=R[s]=R[a]=R[u]=R[c]=R[l]=R[d]=R[f]=R[p]=R[y]=R[g]=!1;function _(A){return r(A)&&t(A.length)&&!!R[e(A)]}return ai=_,ai}var si,Kd;function $n(){if(Kd)return si;Kd=1;function e(t){return function(r){return t(r)}}return si=e,si}var $t={exports:{}};$t.exports;var Jd;function Ku(){return Jd||(Jd=1,(function(e,t){var r=$m(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i&&r.process,a=(function(){try{var u=o&&o.require&&o.require("util").types;return u||s&&s.binding&&s.binding("util")}catch{}})();e.exports=a})($t,$t.exports)),$t.exports}var ci,Zd;function cn(){if(Zd)return ci;Zd=1;var e=Ew(),t=$n(),r=Ku(),n=r&&r.isTypedArray,o=n?t(n):e;return ci=o,ci}var ui,Yd;function Bm(){if(Yd)return ui;Yd=1;var e=Cw(),t=sn(),r=tr(),n=jt(),o=Nn(),i=cn(),s=Object.prototype,a=s.hasOwnProperty;function u(c,l){var d=r(c),f=!d&&t(c),p=!d&&!f&&n(c),y=!d&&!f&&!p&&i(c),g=d||f||p||y,b=g?e(c.length,String):[],x=b.length;for(var m in c)(l||a.call(c,m))&&!(g&&(m=="length"||p&&(m=="offset"||m=="parent")||y&&(m=="buffer"||m=="byteLength"||m=="byteOffset")||o(m,x)))&&b.push(m);return b}return ui=u,ui}var li,Xd;function Ln(){if(Xd)return li;Xd=1;var e=Object.prototype;function t(r){var n=r&&r.constructor,o=typeof n=="function"&&n.prototype||e;return r===o}return li=t,li}var di,Qd;function zm(){if(Qd)return di;Qd=1;function e(t,r){return function(n){return t(r(n))}}return di=e,di}var fi,ef;function jw(){if(ef)return fi;ef=1;var e=zm(),t=e(Object.keys,Object);return fi=t,fi}var hi,rf;function Ju(){if(rf)return hi;rf=1;var e=Ln(),t=jw(),r=Object.prototype,n=r.hasOwnProperty;function o(i){if(!e(i))return t(i);var s=[];for(var a in Object(i))n.call(i,a)&&a!="constructor"&&s.push(a);return s}return hi=o,hi}var pi,tf;function qr(){if(tf)return pi;tf=1;var e=on(),t=Hu();function r(n){return n!=null&&t(n.length)&&!e(n)}return pi=r,pi}var gi,nf;function Kr(){if(nf)return gi;nf=1;var e=Bm(),t=Ju(),r=qr();function n(o){return r(o)?e(o):t(o)}return gi=n,gi}var yi,of;function Rw(){if(of)return yi;of=1;var e=an(),t=Kr();function r(n,o){return n&&e(o,t(o),n)}return yi=r,yi}var mi,af;function kw(){if(af)return mi;af=1;function e(t){var r=[];if(t!=null)for(var n in Object(t))r.push(n);return r}return mi=e,mi}var bi,sf;function Pw(){if(sf)return bi;sf=1;var e=xr(),t=Ln(),r=kw(),n=Object.prototype,o=n.hasOwnProperty;function i(s){if(!e(s))return r(s);var a=t(s),u=[];for(var c in s)c=="constructor"&&(a||!o.call(s,c))||u.push(c);return u}return bi=i,bi}var vi,cf;function st(){if(cf)return vi;cf=1;var e=Bm(),t=Pw(),r=qr();function n(o){return r(o)?e(o,!0):t(o)}return vi=n,vi}var xi,uf;function Aw(){if(uf)return xi;uf=1;var e=an(),t=st();function r(n,o){return n&&e(o,t(o),n)}return xi=r,xi}var Lt={exports:{}};Lt.exports;var lf;function Dm(){return lf||(lf=1,(function(e,t){var r=Er(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i?r.Buffer:void 0,a=s?s.allocUnsafe:void 0;function u(c,l){if(l)return c.slice();var d=c.length,f=a?a(d):new c.constructor(d);return c.copy(f),f}e.exports=u})(Lt,Lt.exports)),Lt.exports}var wi,df;function Vm(){if(df)return wi;df=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 wi=e,wi}var Ci,ff;function Wm(){if(ff)return Ci;ff=1;function e(t,r){for(var n=-1,o=t==null?0:t.length,i=0,s=[];++n<o;){var a=t[n];r(a,n,t)&&(s[i++]=a)}return s}return Ci=e,Ci}var _i,hf;function Gm(){if(hf)return _i;hf=1;function e(){return[]}return _i=e,_i}var Si,pf;function Zu(){if(pf)return Si;pf=1;var e=Wm(),t=Gm(),r=Object.prototype,n=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(s){return s==null?[]:(s=Object(s),e(o(s),function(a){return n.call(s,a)}))}:t;return Si=i,Si}var Ei,gf;function Tw(){if(gf)return Ei;gf=1;var e=an(),t=Zu();function r(n,o){return e(n,t(n),o)}return Ei=r,Ei}var ji,yf;function Yu(){if(yf)return ji;yf=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 ji=e,ji}var Ri,mf;function Fn(){if(mf)return Ri;mf=1;var e=zm(),t=e(Object.getPrototypeOf,Object);return Ri=t,Ri}var ki,bf;function Um(){if(bf)return ki;bf=1;var e=Yu(),t=Fn(),r=Zu(),n=Gm(),o=Object.getOwnPropertySymbols,i=o?function(s){for(var a=[];s;)e(a,r(s)),s=t(s);return a}:n;return ki=i,ki}var Pi,vf;function Ow(){if(vf)return Pi;vf=1;var e=an(),t=Um();function r(n,o){return e(n,t(n),o)}return Pi=r,Pi}var Ai,xf;function Hm(){if(xf)return Ai;xf=1;var e=Yu(),t=tr();function r(n,o,i){var s=o(n);return t(n)?s:e(s,i(n))}return Ai=r,Ai}var Ti,wf;function Km(){if(wf)return Ti;wf=1;var e=Hm(),t=Zu(),r=Kr();function n(o){return e(o,r,t)}return Ti=n,Ti}var Oi,Cf;function Iw(){if(Cf)return Oi;Cf=1;var e=Hm(),t=Um(),r=st();function n(o){return e(o,r,t)}return Oi=n,Oi}var Ii,_f;function Mw(){if(_f)return Ii;_f=1;var e=at(),t=Er(),r=e(t,"DataView");return Ii=r,Ii}var Mi,Sf;function qw(){if(Sf)return Mi;Sf=1;var e=at(),t=Er(),r=e(t,"Promise");return Mi=r,Mi}var qi,Ef;function Jm(){if(Ef)return qi;Ef=1;var e=at(),t=Er(),r=e(t,"Set");return qi=r,qi}var Ni,jf;function Nw(){if(jf)return Ni;jf=1;var e=at(),t=Er(),r=e(t,"WeakMap");return Ni=r,Ni}var $i,Rf;function Rt(){if(Rf)return $i;Rf=1;var e=Mw(),t=Wu(),r=qw(),n=Jm(),o=Nw(),i=it(),s=Lm(),a="[object Map]",u="[object Object]",c="[object Promise]",l="[object Set]",d="[object WeakMap]",f="[object DataView]",p=s(e),y=s(t),g=s(r),b=s(n),x=s(o),m=i;return(e&&m(new e(new ArrayBuffer(1)))!=f||t&&m(new t)!=a||r&&m(r.resolve())!=c||n&&m(new n)!=l||o&&m(new o)!=d)&&(m=function(w){var v=i(w),C=v==u?w.constructor:void 0,S=C?s(C):"";if(S)switch(S){case p:return f;case y:return a;case g:return c;case b:return l;case x:return d}return v}),$i=m,$i}var Li,kf;function $w(){if(kf)return Li;kf=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 Li=r,Li}var Fi,Pf;function Zm(){if(Pf)return Fi;Pf=1;var e=Er(),t=e.Uint8Array;return Fi=t,Fi}var Bi,Af;function Xu(){if(Af)return Bi;Af=1;var e=Zm();function t(r){var n=new r.constructor(r.byteLength);return new e(n).set(new e(r)),n}return Bi=t,Bi}var zi,Tf;function Lw(){if(Tf)return zi;Tf=1;var e=Xu();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.byteLength)}return zi=t,zi}var Di,Of;function Fw(){if(Of)return Di;Of=1;var e=/\w*$/;function t(r){var n=new r.constructor(r.source,e.exec(r));return n.lastIndex=r.lastIndex,n}return Di=t,Di}var Vi,If;function Bw(){if(If)return Vi;If=1;var e=Et(),t=e?e.prototype:void 0,r=t?t.valueOf:void 0;function n(o){return r?Object(r.call(o)):{}}return Vi=n,Vi}var Wi,Mf;function Ym(){if(Mf)return Wi;Mf=1;var e=Xu();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.length)}return Wi=t,Wi}var Gi,qf;function zw(){if(qf)return Gi;qf=1;var e=Xu(),t=Lw(),r=Fw(),n=Bw(),o=Ym(),i="[object Boolean]",s="[object Date]",a="[object Map]",u="[object Number]",c="[object RegExp]",l="[object Set]",d="[object String]",f="[object Symbol]",p="[object ArrayBuffer]",y="[object DataView]",g="[object Float32Array]",b="[object Float64Array]",x="[object Int8Array]",m="[object Int16Array]",w="[object Int32Array]",v="[object Uint8Array]",C="[object Uint8ClampedArray]",S="[object Uint16Array]",j="[object Uint32Array]";function T(k,M,R){var _=k.constructor;switch(M){case p:return e(k);case i:case s:return new _(+k);case y:return t(k,R);case g:case b:case x:case m:case w:case v:case C:case S:case j:return o(k,R);case a:return new _;case u:case d:return new _(k);case c:return r(k);case l:return new _;case f:return n(k)}}return Gi=T,Gi}var Ui,Nf;function Xm(){if(Nf)return Ui;Nf=1;var e=xr(),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 Ui=r,Ui}var Hi,$f;function Qm(){if($f)return Hi;$f=1;var e=Xm(),t=Fn(),r=Ln();function n(o){return typeof o.constructor=="function"&&!r(o)?e(t(o)):{}}return Hi=n,Hi}var Ki,Lf;function Dw(){if(Lf)return Ki;Lf=1;var e=Rt(),t=Ar(),r="[object Map]";function n(o){return t(o)&&e(o)==r}return Ki=n,Ki}var Ji,Ff;function Vw(){if(Ff)return Ji;Ff=1;var e=Dw(),t=$n(),r=Ku(),n=r&&r.isMap,o=n?t(n):e;return Ji=o,Ji}var Zi,Bf;function Ww(){if(Bf)return Zi;Bf=1;var e=Rt(),t=Ar(),r="[object Set]";function n(o){return t(o)&&e(o)==r}return Zi=n,Zi}var Yi,zf;function Gw(){if(zf)return Yi;zf=1;var e=Ww(),t=$n(),r=Ku(),n=r&&r.isSet,o=n?t(n):e;return Yi=o,Yi}var Xi,Df;function eb(){if(Df)return Xi;Df=1;var e=In(),t=Uu(),r=qn(),n=Rw(),o=Aw(),i=Dm(),s=Vm(),a=Tw(),u=Ow(),c=Km(),l=Iw(),d=Rt(),f=$w(),p=zw(),y=Qm(),g=tr(),b=jt(),x=Vw(),m=xr(),w=Gw(),v=Kr(),C=st(),S=1,j=2,T=4,k="[object Arguments]",M="[object Array]",R="[object Boolean]",_="[object Date]",A="[object Error]",I="[object Function]",q="[object GeneratorFunction]",O="[object Map]",W="[object Number]",V="[object Object]",ue="[object RegExp]",ne="[object Set]",Q="[object String]",he="[object Symbol]",le="[object WeakMap]",$="[object ArrayBuffer]",D="[object DataView]",G="[object Float32Array]",N="[object Float64Array]",ee="[object Int8Array]",ge="[object Int16Array]",ye="[object Int32Array]",K="[object Uint8Array]",X="[object Uint8ClampedArray]",U="[object Uint16Array]",se="[object Uint32Array]",te={};te[k]=te[M]=te[$]=te[D]=te[R]=te[_]=te[G]=te[N]=te[ee]=te[ge]=te[ye]=te[O]=te[W]=te[V]=te[ue]=te[ne]=te[Q]=te[he]=te[K]=te[X]=te[U]=te[se]=!0,te[A]=te[I]=te[le]=!1;function xe(pe,De,Z,de,Ce,Ie){var qe,Ue=De&S,Qe=De&j,We=De&T;if(Z&&(qe=Ce?Z(pe,de,Ce,Ie):Z(pe)),qe!==void 0)return qe;if(!m(pe))return pe;var we=g(pe);if(we){if(qe=f(pe),!Ue)return s(pe,qe)}else{var _e=d(pe),He=_e==I||_e==q;if(b(pe))return i(pe,Ue);if(_e==V||_e==k||He&&!Ce){if(qe=Qe||He?{}:y(pe),!Ue)return Qe?u(pe,o(qe,pe)):a(pe,n(qe,pe))}else{if(!te[_e])return Ce?pe:{};qe=p(pe,_e,Ue)}}Ie||(Ie=new e);var Xe=Ie.get(pe);if(Xe)return Xe;Ie.set(pe,qe),w(pe)?pe.forEach(function(sr){qe.add(xe(sr,De,Z,sr,pe,Ie))}):x(pe)&&pe.forEach(function(sr,Ee){qe.set(Ee,xe(sr,De,Z,Ee,pe,Ie))});var ur=We?Qe?l:c:Qe?C:v,er=we?void 0:ur(pe);return t(er||pe,function(sr,Ee){er&&(Ee=sr,sr=pe[Ee]),r(qe,Ee,xe(sr,De,Z,Ee,pe,Ie))}),qe}return Xi=xe,Xi}var Qi,Vf;function Uw(){if(Vf)return Qi;Vf=1;var e=eb(),t=4;function r(n){return e(n,t)}return Qi=r,Qi}var ea,Wf;function Qu(){if(Wf)return ea;Wf=1;function e(t){return function(){return t}}return ea=e,ea}var ra,Gf;function Hw(){if(Gf)return ra;Gf=1;function e(t){return function(r,n,o){for(var i=-1,s=Object(r),a=o(r),u=a.length;u--;){var c=a[t?u:++i];if(n(s[c],c,s)===!1)break}return r}}return ra=e,ra}var ta,Uf;function el(){if(Uf)return ta;Uf=1;var e=Hw(),t=e();return ta=t,ta}var na,Hf;function rl(){if(Hf)return na;Hf=1;var e=el(),t=Kr();function r(n,o){return n&&e(n,o,t)}return na=r,na}var oa,Kf;function Kw(){if(Kf)return oa;Kf=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 s=o.length,a=n?s:-1,u=Object(o);(n?a--:++a<s)&&i(u[a],a,u)!==!1;);return o}}return oa=t,oa}var ia,Jf;function Bn(){if(Jf)return ia;Jf=1;var e=rl(),t=Kw(),r=t(e);return ia=r,ia}var aa,Zf;function ct(){if(Zf)return aa;Zf=1;function e(t){return t}return aa=e,aa}var sa,Yf;function rb(){if(Yf)return sa;Yf=1;var e=ct();function t(r){return typeof r=="function"?r:e}return sa=t,sa}var ca,Xf;function tb(){if(Xf)return ca;Xf=1;var e=Uu(),t=Bn(),r=rb(),n=tr();function o(i,s){var a=n(i)?e:t;return a(i,r(s))}return ca=o,ca}var ua,Qf;function nb(){return Qf||(Qf=1,ua=tb()),ua}var la,eh;function Jw(){if(eh)return la;eh=1;var e=Bn();function t(r,n){var o=[];return e(r,function(i,s,a){n(i,s,a)&&o.push(i)}),o}return la=t,la}var da,rh;function Zw(){if(rh)return da;rh=1;var e="__lodash_hash_undefined__";function t(r){return this.__data__.set(r,e),this}return da=t,da}var fa,th;function Yw(){if(th)return fa;th=1;function e(t){return this.__data__.has(t)}return fa=e,fa}var ha,nh;function ob(){if(nh)return ha;nh=1;var e=Gu(),t=Zw(),r=Yw();function n(o){var i=-1,s=o==null?0:o.length;for(this.__data__=new e;++i<s;)this.add(o[i])}return n.prototype.add=n.prototype.push=t,n.prototype.has=r,ha=n,ha}var pa,oh;function Xw(){if(oh)return pa;oh=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 pa=e,pa}var ga,ih;function ib(){if(ih)return ga;ih=1;function e(t,r){return t.has(r)}return ga=e,ga}var ya,ah;function ab(){if(ah)return ya;ah=1;var e=ob(),t=Xw(),r=ib(),n=1,o=2;function i(s,a,u,c,l,d){var f=u&n,p=s.length,y=a.length;if(p!=y&&!(f&&y>p))return!1;var g=d.get(s),b=d.get(a);if(g&&b)return g==a&&b==s;var x=-1,m=!0,w=u&o?new e:void 0;for(d.set(s,a),d.set(a,s);++x<p;){var v=s[x],C=a[x];if(c)var S=f?c(C,v,x,a,s,d):c(v,C,x,s,a,d);if(S!==void 0){if(S)continue;m=!1;break}if(w){if(!t(a,function(j,T){if(!r(w,T)&&(v===j||l(v,j,u,c,d)))return w.push(T)})){m=!1;break}}else if(!(v===C||l(v,C,u,c,d))){m=!1;break}}return d.delete(s),d.delete(a),m}return ya=i,ya}var ma,sh;function Qw(){if(sh)return ma;sh=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o,i){n[++r]=[i,o]}),n}return ma=e,ma}var ba,ch;function tl(){if(ch)return ba;ch=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o){n[++r]=o}),n}return ba=e,ba}var va,uh;function e1(){if(uh)return va;uh=1;var e=Et(),t=Zm(),r=St(),n=ab(),o=Qw(),i=tl(),s=1,a=2,u="[object Boolean]",c="[object Date]",l="[object Error]",d="[object Map]",f="[object Number]",p="[object RegExp]",y="[object Set]",g="[object String]",b="[object Symbol]",x="[object ArrayBuffer]",m="[object DataView]",w=e?e.prototype:void 0,v=w?w.valueOf:void 0;function C(S,j,T,k,M,R,_){switch(T){case m:if(S.byteLength!=j.byteLength||S.byteOffset!=j.byteOffset)return!1;S=S.buffer,j=j.buffer;case x:return!(S.byteLength!=j.byteLength||!R(new t(S),new t(j)));case u:case c:case f:return r(+S,+j);case l:return S.name==j.name&&S.message==j.message;case p:case g:return S==j+"";case d:var A=o;case y:var I=k&s;if(A||(A=i),S.size!=j.size&&!I)return!1;var q=_.get(S);if(q)return q==j;k|=a,_.set(S,j);var O=n(A(S),A(j),k,M,R,_);return _.delete(S),O;case b:if(v)return v.call(S)==v.call(j)}return!1}return va=C,va}var xa,lh;function r1(){if(lh)return xa;lh=1;var e=Km(),t=1,r=Object.prototype,n=r.hasOwnProperty;function o(i,s,a,u,c,l){var d=a&t,f=e(i),p=f.length,y=e(s),g=y.length;if(p!=g&&!d)return!1;for(var b=p;b--;){var x=f[b];if(!(d?x in s:n.call(s,x)))return!1}var m=l.get(i),w=l.get(s);if(m&&w)return m==s&&w==i;var v=!0;l.set(i,s),l.set(s,i);for(var C=d;++b<p;){x=f[b];var S=i[x],j=s[x];if(u)var T=d?u(j,S,x,s,i,l):u(S,j,x,i,s,l);if(!(T===void 0?S===j||c(S,j,a,u,l):T)){v=!1;break}C||(C=x=="constructor")}if(v&&!C){var k=i.constructor,M=s.constructor;k!=M&&"constructor"in i&&"constructor"in s&&!(typeof k=="function"&&k instanceof k&&typeof M=="function"&&M instanceof M)&&(v=!1)}return l.delete(i),l.delete(s),v}return xa=o,xa}var wa,dh;function t1(){if(dh)return wa;dh=1;var e=In(),t=ab(),r=e1(),n=r1(),o=Rt(),i=tr(),s=jt(),a=cn(),u=1,c="[object Arguments]",l="[object Array]",d="[object Object]",f=Object.prototype,p=f.hasOwnProperty;function y(g,b,x,m,w,v){var C=i(g),S=i(b),j=C?l:o(g),T=S?l:o(b);j=j==c?d:j,T=T==c?d:T;var k=j==d,M=T==d,R=j==T;if(R&&s(g)){if(!s(b))return!1;C=!0,k=!1}if(R&&!k)return v||(v=new e),C||a(g)?t(g,b,x,m,w,v):r(g,b,j,x,m,w,v);if(!(x&u)){var _=k&&p.call(g,"__wrapped__"),A=M&&p.call(b,"__wrapped__");if(_||A){var I=_?g.value():g,q=A?b.value():b;return v||(v=new e),w(I,q,x,m,v)}}return R?(v||(v=new e),n(g,b,x,m,w,v)):!1}return wa=y,wa}var Ca,fh;function sb(){if(fh)return Ca;fh=1;var e=t1(),t=Ar();function r(n,o,i,s,a){return n===o?!0:n==null||o==null||!t(n)&&!t(o)?n!==n&&o!==o:e(n,o,i,s,r,a)}return Ca=r,Ca}var _a,hh;function n1(){if(hh)return _a;hh=1;var e=In(),t=sb(),r=1,n=2;function o(i,s,a,u){var c=a.length,l=c,d=!u;if(i==null)return!l;for(i=Object(i);c--;){var f=a[c];if(d&&f[2]?f[1]!==i[f[0]]:!(f[0]in i))return!1}for(;++c<l;){f=a[c];var p=f[0],y=i[p],g=f[1];if(d&&f[2]){if(y===void 0&&!(p in i))return!1}else{var b=new e;if(u)var x=u(y,g,p,i,s,b);if(!(x===void 0?t(g,y,r|n,u,b):x))return!1}}return!0}return _a=o,_a}var Sa,ph;function cb(){if(ph)return Sa;ph=1;var e=xr();function t(r){return r===r&&!e(r)}return Sa=t,Sa}var Ea,gh;function o1(){if(gh)return Ea;gh=1;var e=cb(),t=Kr();function r(n){for(var o=t(n),i=o.length;i--;){var s=o[i],a=n[s];o[i]=[s,a,e(a)]}return o}return Ea=r,Ea}var ja,yh;function ub(){if(yh)return ja;yh=1;function e(t,r){return function(n){return n==null?!1:n[t]===r&&(r!==void 0||t in Object(n))}}return ja=e,ja}var Ra,mh;function i1(){if(mh)return Ra;mh=1;var e=n1(),t=o1(),r=ub();function n(o){var i=t(o);return i.length==1&&i[0][2]?r(i[0][0],i[0][1]):function(s){return s===o||e(s,o,i)}}return Ra=n,Ra}var ka,bh;function kt(){if(bh)return ka;bh=1;var e=it(),t=Ar(),r="[object Symbol]";function n(o){return typeof o=="symbol"||t(o)&&e(o)==r}return ka=n,ka}var Pa,vh;function nl(){if(vh)return Pa;vh=1;var e=tr(),t=kt(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,s){if(e(i))return!1;var a=typeof i;return a=="number"||a=="symbol"||a=="boolean"||i==null||t(i)?!0:n.test(i)||!r.test(i)||s!=null&&i in Object(s)}return Pa=o,Pa}var Aa,xh;function a1(){if(xh)return Aa;xh=1;var e=Gu(),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 s=arguments,a=o?o.apply(this,s):s[0],u=i.cache;if(u.has(a))return u.get(a);var c=n.apply(this,s);return i.cache=u.set(a,c)||u,c};return i.cache=new(r.Cache||e),i}return r.Cache=e,Aa=r,Aa}var Ta,wh;function s1(){if(wh)return Ta;wh=1;var e=a1(),t=500;function r(n){var o=e(n,function(s){return i.size===t&&i.clear(),s}),i=o.cache;return o}return Ta=r,Ta}var Oa,Ch;function c1(){if(Ch)return Oa;Ch=1;var e=s1(),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(s,a,u,c){i.push(u?c.replace(r,"$1"):a||s)}),i});return Oa=n,Oa}var Ia,_h;function zn(){if(_h)return Ia;_h=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 Ia=e,Ia}var Ma,Sh;function u1(){if(Sh)return Ma;Sh=1;var e=Et(),t=zn(),r=tr(),n=kt(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function s(a){if(typeof a=="string")return a;if(r(a))return t(a,s)+"";if(n(a))return i?i.call(a):"";var u=a+"";return u=="0"&&1/a==-1/0?"-0":u}return Ma=s,Ma}var qa,Eh;function lb(){if(Eh)return qa;Eh=1;var e=u1();function t(r){return r==null?"":e(r)}return qa=t,qa}var Na,jh;function Dn(){if(jh)return Na;jh=1;var e=tr(),t=nl(),r=c1(),n=lb();function o(i,s){return e(i)?i:t(i,s)?[i]:r(n(i))}return Na=o,Na}var $a,Rh;function un(){if(Rh)return $a;Rh=1;var e=kt();function t(r){if(typeof r=="string"||e(r))return r;var n=r+"";return n=="0"&&1/r==-1/0?"-0":n}return $a=t,$a}var La,kh;function Vn(){if(kh)return La;kh=1;var e=Dn(),t=un();function r(n,o){o=e(o,n);for(var i=0,s=o.length;n!=null&&i<s;)n=n[t(o[i++])];return i&&i==s?n:void 0}return La=r,La}var Fa,Ph;function l1(){if(Ph)return Fa;Ph=1;var e=Vn();function t(r,n,o){var i=r==null?void 0:e(r,n);return i===void 0?o:i}return Fa=t,Fa}var Ba,Ah;function d1(){if(Ah)return Ba;Ah=1;function e(t,r){return t!=null&&r in Object(t)}return Ba=e,Ba}var za,Th;function db(){if(Th)return za;Th=1;var e=Dn(),t=sn(),r=tr(),n=Nn(),o=Hu(),i=un();function s(a,u,c){u=e(u,a);for(var l=-1,d=u.length,f=!1;++l<d;){var p=i(u[l]);if(!(f=a!=null&&c(a,p)))break;a=a[p]}return f||++l!=d?f:(d=a==null?0:a.length,!!d&&o(d)&&n(p,d)&&(r(a)||t(a)))}return za=s,za}var Da,Oh;function fb(){if(Oh)return Da;Oh=1;var e=d1(),t=db();function r(n,o){return n!=null&&t(n,o,e)}return Da=r,Da}var Va,Ih;function f1(){if(Ih)return Va;Ih=1;var e=sb(),t=l1(),r=fb(),n=nl(),o=cb(),i=ub(),s=un(),a=1,u=2;function c(l,d){return n(l)&&o(d)?i(s(l),d):function(f){var p=t(f,l);return p===void 0&&p===d?r(f,l):e(d,p,a|u)}}return Va=c,Va}var Wa,Mh;function hb(){if(Mh)return Wa;Mh=1;function e(t){return function(r){return r==null?void 0:r[t]}}return Wa=e,Wa}var Ga,qh;function h1(){if(qh)return Ga;qh=1;var e=Vn();function t(r){return function(n){return e(n,r)}}return Ga=t,Ga}var Ua,Nh;function p1(){if(Nh)return Ua;Nh=1;var e=hb(),t=h1(),r=nl(),n=un();function o(i){return r(i)?e(n(i)):t(i)}return Ua=o,Ua}var Ha,$h;function Nr(){if($h)return Ha;$h=1;var e=i1(),t=f1(),r=ct(),n=tr(),o=p1();function i(s){return typeof s=="function"?s:s==null?r:typeof s=="object"?n(s)?t(s[0],s[1]):e(s):o(s)}return Ha=i,Ha}var Ka,Lh;function pb(){if(Lh)return Ka;Lh=1;var e=Wm(),t=Jw(),r=Nr(),n=tr();function o(i,s){var a=n(i)?e:t;return a(i,r(s,3))}return Ka=o,Ka}var Ja,Fh;function g1(){if(Fh)return Ja;Fh=1;var e=Object.prototype,t=e.hasOwnProperty;function r(n,o){return n!=null&&t.call(n,o)}return Ja=r,Ja}var Za,Bh;function gb(){if(Bh)return Za;Bh=1;var e=g1(),t=db();function r(n,o){return n!=null&&t(n,o,e)}return Za=r,Za}var Ya,zh;function y1(){if(zh)return Ya;zh=1;var e=Ju(),t=Rt(),r=sn(),n=tr(),o=qr(),i=jt(),s=Ln(),a=cn(),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)||a(p)||r(p)))return!p.length;var y=t(p);if(y==u||y==c)return!p.size;if(s(p))return!e(p).length;for(var g in p)if(d.call(p,g))return!1;return!0}return Ya=f,Ya}var Xa,Dh;function yb(){if(Dh)return Xa;Dh=1;function e(t){return t===void 0}return Xa=e,Xa}var Qa,Vh;function mb(){if(Vh)return Qa;Vh=1;var e=Bn(),t=qr();function r(n,o){var i=-1,s=t(n)?Array(n.length):[];return e(n,function(a,u,c){s[++i]=o(a,u,c)}),s}return Qa=r,Qa}var es,Wh;function bb(){if(Wh)return es;Wh=1;var e=zn(),t=Nr(),r=mb(),n=tr();function o(i,s){var a=n(i)?e:r;return a(i,t(s,3))}return es=o,es}var rs,Gh;function m1(){if(Gh)return rs;Gh=1;function e(t,r,n,o){var i=-1,s=t==null?0:t.length;for(o&&s&&(n=t[++i]);++i<s;)n=r(n,t[i],i,t);return n}return rs=e,rs}var ts,Uh;function b1(){if(Uh)return ts;Uh=1;function e(t,r,n,o,i){return i(t,function(s,a,u){n=o?(o=!1,s):r(n,s,a,u)}),n}return ts=e,ts}var ns,Hh;function vb(){if(Hh)return ns;Hh=1;var e=m1(),t=Bn(),r=Nr(),n=b1(),o=tr();function i(s,a,u){var c=o(s)?e:n,l=arguments.length<3;return c(s,r(a,4),u,l,t)}return ns=i,ns}var os,Kh;function v1(){if(Kh)return os;Kh=1;var e=it(),t=tr(),r=Ar(),n="[object String]";function o(i){return typeof i=="string"||!t(i)&&r(i)&&e(i)==n}return os=o,os}var is,Jh;function x1(){if(Jh)return is;Jh=1;var e=hb(),t=e("length");return is=t,is}var as,Zh;function w1(){if(Zh)return as;Zh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",s="\\u200d",a=RegExp("["+s+e+o+i+"]");function u(c){return a.test(c)}return as=u,as}var ss,Yh;function C1(){if(Yh)return ss;Yh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",s="["+e+"]",a="["+o+"]",u="\\ud83c[\\udffb-\\udfff]",c="(?:"+a+"|"+u+")",l="[^"+e+"]",d="(?:\\ud83c[\\udde6-\\uddff]){2}",f="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",y=c+"?",g="["+i+"]?",b="(?:"+p+"(?:"+[l,d,f].join("|")+")"+g+y+")*",x=g+y+b,m="(?:"+[l+a+"?",a,d,f,s].join("|")+")",w=RegExp(u+"(?="+u+")|"+m+x,"g");function v(C){for(var S=w.lastIndex=0;w.test(C);)++S;return S}return ss=v,ss}var cs,Xh;function _1(){if(Xh)return cs;Xh=1;var e=x1(),t=w1(),r=C1();function n(o){return t(o)?r(o):e(o)}return cs=n,cs}var us,Qh;function S1(){if(Qh)return us;Qh=1;var e=Ju(),t=Rt(),r=qr(),n=v1(),o=_1(),i="[object Map]",s="[object Set]";function a(u){if(u==null)return 0;if(r(u))return n(u)?o(u):u.length;var c=t(u);return c==i||c==s?u.size:e(u).length}return us=a,us}var ls,ep;function E1(){if(ep)return ls;ep=1;var e=Uu(),t=Xm(),r=rl(),n=Nr(),o=Fn(),i=tr(),s=jt(),a=on(),u=xr(),c=cn();function l(d,f,p){var y=i(d),g=y||s(d)||c(d);if(f=n(f,4),p==null){var b=d&&d.constructor;g?p=y?new b:[]:u(d)?p=a(b)?t(o(d)):{}:p={}}return(g?e:r)(d,function(x,m,w){return f(p,x,m,w)}),p}return ls=l,ls}var ds,rp;function j1(){if(rp)return ds;rp=1;var e=Et(),t=sn(),r=tr(),n=e?e.isConcatSpreadable:void 0;function o(i){return r(i)||t(i)||!!(n&&i&&i[n])}return ds=o,ds}var fs,tp;function ol(){if(tp)return fs;tp=1;var e=Yu(),t=j1();function r(n,o,i,s,a){var u=-1,c=n.length;for(i||(i=t),a||(a=[]);++u<c;){var l=n[u];o>0&&i(l)?o>1?r(l,o-1,i,s,a):e(a,l):s||(a[a.length]=l)}return a}return fs=r,fs}var hs,np;function R1(){if(np)return hs;np=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 hs=e,hs}var ps,op;function xb(){if(op)return ps;op=1;var e=R1(),t=Math.max;function r(n,o,i){return o=t(o===void 0?n.length-1:o,0),function(){for(var s=arguments,a=-1,u=t(s.length-o,0),c=Array(u);++a<u;)c[a]=s[o+a];a=-1;for(var l=Array(o+1);++a<o;)l[a]=s[a];return l[o]=i(c),e(n,this,l)}}return ps=r,ps}var gs,ip;function k1(){if(ip)return gs;ip=1;var e=Qu(),t=Fm(),r=ct(),n=t?function(o,i){return t(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:r;return gs=n,gs}var ys,ap;function P1(){if(ap)return ys;ap=1;var e=800,t=16,r=Date.now;function n(o){var i=0,s=0;return function(){var a=r(),u=t-(a-s);if(s=a,u>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return ys=n,ys}var ms,sp;function wb(){if(sp)return ms;sp=1;var e=k1(),t=P1(),r=t(e);return ms=r,ms}var bs,cp;function Wn(){if(cp)return bs;cp=1;var e=ct(),t=xb(),r=wb();function n(o,i){return r(t(o,i,e),o+"")}return bs=n,bs}var vs,up;function Cb(){if(up)return vs;up=1;function e(t,r,n,o){for(var i=t.length,s=n+(o?1:-1);o?s--:++s<i;)if(r(t[s],s,t))return s;return-1}return vs=e,vs}var xs,lp;function A1(){if(lp)return xs;lp=1;function e(t){return t!==t}return xs=e,xs}var ws,dp;function T1(){if(dp)return ws;dp=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 ws=e,ws}var Cs,fp;function O1(){if(fp)return Cs;fp=1;var e=Cb(),t=A1(),r=T1();function n(o,i,s){return i===i?r(o,i,s):e(o,t,s)}return Cs=n,Cs}var _s,hp;function I1(){if(hp)return _s;hp=1;var e=O1();function t(r,n){var o=r==null?0:r.length;return!!o&&e(r,n,0)>-1}return _s=t,_s}var Ss,pp;function M1(){if(pp)return Ss;pp=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 Ss=e,Ss}var Es,gp;function q1(){if(gp)return Es;gp=1;function e(){}return Es=e,Es}var js,yp;function N1(){if(yp)return js;yp=1;var e=Jm(),t=q1(),r=tl(),n=1/0,o=e&&1/r(new e([,-0]))[1]==n?function(i){return new e(i)}:t;return js=o,js}var Rs,mp;function $1(){if(mp)return Rs;mp=1;var e=ob(),t=I1(),r=M1(),n=ib(),o=N1(),i=tl(),s=200;function a(u,c,l){var d=-1,f=t,p=u.length,y=!0,g=[],b=g;if(l)y=!1,f=r;else if(p>=s){var x=c?null:o(u);if(x)return i(x);y=!1,f=n,b=new e}else b=c?[]:g;e:for(;++d<p;){var m=u[d],w=c?c(m):m;if(m=l||m!==0?m:0,y&&w===w){for(var v=b.length;v--;)if(b[v]===w)continue e;c&&b.push(w),g.push(m)}else f(b,w,l)||(b!==g&&b.push(w),g.push(m))}return g}return Rs=a,Rs}var ks,bp;function _b(){if(bp)return ks;bp=1;var e=qr(),t=Ar();function r(n){return t(n)&&e(n)}return ks=r,ks}var Ps,vp;function L1(){if(vp)return Ps;vp=1;var e=ol(),t=Wn(),r=$1(),n=_b(),o=t(function(i){return r(e(i,1,n,!0))});return Ps=o,Ps}var As,xp;function F1(){if(xp)return As;xp=1;var e=zn();function t(r,n){return e(n,function(o){return r[o]})}return As=t,As}var Ts,wp;function Sb(){if(wp)return Ts;wp=1;var e=F1(),t=Kr();function r(n){return n==null?[]:e(n,t(n))}return Ts=r,Ts}var Os,Cp;function wr(){if(Cp)return Os;Cp=1;var e;if(typeof Vu=="function")try{e={clone:Uw(),constant:Qu(),each:nb(),filter:pb(),has:gb(),isArray:tr(),isEmpty:y1(),isFunction:on(),isUndefined:yb(),keys:Kr(),map:bb(),reduce:vb(),size:S1(),transform:E1(),union:L1(),values:Sb()}}catch{}return e||(e=window._),Os=e,Os}var Is,_p;function il(){if(_p)return Is;_p=1;var e=wr();Is=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(y){f.length>1?p.setNode(y,d):p.setNode(y)}),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(g,b){l(b)&&d.setNode(b,g)}),e.each(this._edgeObjs,function(g){d.hasNode(g.v)&&d.hasNode(g.w)&&d.setEdge(g,f.edge(g))});var p={};function y(g){var b=f.parent(g);return b===void 0||d.hasNode(b)?(p[g]=b,b):b in p?p[b]:y(b)}return this._isCompound&&e.each(d.nodes(),function(g){d.setParent(g,y(g))}),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(y,g){return p.length>1?f.setEdge(y,g,d):f.setEdge(y,g),g}),this},o.prototype.setEdge=function(){var l,d,f,p,y=!1,g=arguments[0];typeof g=="object"&&g!==null&&"v"in g?(l=g.v,d=g.w,f=g.name,arguments.length===2&&(p=arguments[1],y=!0)):(l=g,d=arguments[1],f=arguments[3],arguments.length>2&&(p=arguments[2],y=!0)),l=""+l,d=""+d,e.isUndefined(f)||(f=""+f);var b=a(this._isDirected,l,d,f);if(e.has(this._edgeLabels,b))return y&&(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]=y?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[b]=x,i(this._preds[d],l),i(this._sucs[l],d),this._in[d][b]=x,this._out[l][b]=x,this._edgeCount++,this},o.prototype.edge=function(l,d,f){var p=arguments.length===1?c(this._isDirected,arguments[0]):a(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]):a(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]):a(this._isDirected,l,d,f),y=this._edgeObjs[p];return y&&(l=y.v,d=y.w,delete this._edgeLabels[p],delete this._edgeObjs[p],s(this._preds[d],l),s(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(y){return y.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(y){return y.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 s(l,d){--l[d]||delete l[d]}function a(l,d,f,p){var y=""+d,g=""+f;if(!l&&y>g){var b=y;y=g,g=b}return y+n+g+n+(e.isUndefined(p)?t:p)}function u(l,d,f,p){var y=""+d,g=""+f;if(!l&&y>g){var b=y;y=g,g=b}var x={v:y,w:g};return p&&(x.name=p),x}function c(l,d){return a(l,d.v,d.w,d.name)}return Is}var Ms,Sp;function B1(){return Sp||(Sp=1,Ms="2.1.8"),Ms}var qs,Ep;function z1(){return Ep||(Ep=1,qs={Graph:il(),version:B1()}),qs}var Ns,jp;function D1(){if(jp)return Ns;jp=1;var e=wr(),t=il();Ns={write:r,read:i};function r(s){var a={options:{directed:s.isDirected(),multigraph:s.isMultigraph(),compound:s.isCompound()},nodes:n(s),edges:o(s)};return e.isUndefined(s.graph())||(a.value=e.clone(s.graph())),a}function n(s){return e.map(s.nodes(),function(a){var u=s.node(a),c=s.parent(a),l={v:a};return e.isUndefined(u)||(l.value=u),e.isUndefined(c)||(l.parent=c),l})}function o(s){return e.map(s.edges(),function(a){var u=s.edge(a),c={v:a.v,w:a.w};return e.isUndefined(a.name)||(c.name=a.name),e.isUndefined(u)||(c.value=u),c})}function i(s){var a=new t(s.options).setGraph(s.value);return e.each(s.nodes,function(u){a.setNode(u.v,u.value),u.parent&&a.setParent(u.v,u.parent)}),e.each(s.edges,function(u){a.setEdge({v:u.v,w:u.w,name:u.name},u.value)}),a}return Ns}var $s,Rp;function V1(){if(Rp)return $s;Rp=1;var e=wr();$s=t;function t(r){var n={},o=[],i;function s(a){e.has(n,a)||(n[a]=!0,i.push(a),e.each(r.successors(a),s),e.each(r.predecessors(a),s))}return e.each(r.nodes(),function(a){i=[],s(a),i.length&&o.push(i)}),o}return $s}var Ls,kp;function Eb(){if(kp)return Ls;kp=1;var e=wr();Ls=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,s=i.length;return o[r]=s,i.push({key:r,priority:n}),this._decrease(s),!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,s=r;o<n.length&&(s=n[o].priority<n[s].priority?o:s,i<n.length&&(s=n[i].priority<n[s].priority?i:s),s!==r&&(this._swap(r,s),this._heapify(s)))},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,s=o[r],a=o[n];o[r]=a,o[n]=s,i[a.key]=r,i[s.key]=n},Ls}var Fs,Pp;function jb(){if(Pp)return Fs;Pp=1;var e=wr(),t=Eb();Fs=n;var r=e.constant(1);function n(i,s,a,u){return o(i,String(s),a||r,u||function(c){return i.outEdges(c)})}function o(i,s,a,u){var c={},l=new t,d,f,p=function(y){var g=y.v!==d?y.v:y.w,b=c[g],x=a(y),m=f.distance+x;if(x<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+y+" Weight: "+x);m<b.distance&&(b.distance=m,b.predecessor=d,l.decrease(g,m))};for(i.nodes().forEach(function(y){var g=y===s?0:Number.POSITIVE_INFINITY;c[y]={distance:g},l.add(y,g)});l.size()>0&&(d=l.removeMin(),f=c[d],f.distance!==Number.POSITIVE_INFINITY);)u(d).forEach(p);return c}return Fs}var Bs,Ap;function W1(){if(Ap)return Bs;Ap=1;var e=jb(),t=wr();Bs=r;function r(n,o,i){return t.transform(n.nodes(),function(s,a){s[a]=e(n,a,o,i)},{})}return Bs}var zs,Tp;function Rb(){if(Tp)return zs;Tp=1;var e=wr();zs=t;function t(r){var n=0,o=[],i={},s=[];function a(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)):(a(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);s.push(l)}}return r.nodes().forEach(function(u){e.has(i,u)||a(u)}),s}return zs}var Ds,Op;function G1(){if(Op)return Ds;Op=1;var e=wr(),t=Rb();Ds=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 Ds}var Vs,Ip;function U1(){if(Ip)return Vs;Ip=1;var e=wr();Vs=r;var t=e.constant(1);function r(o,i,s){return n(o,i||t,s||function(a){return o.outEdges(a)})}function n(o,i,s){var a={},u=o.nodes();return u.forEach(function(c){a[c]={},a[c][c]={distance:0},u.forEach(function(l){c!==l&&(a[c][l]={distance:Number.POSITIVE_INFINITY})}),s(c).forEach(function(l){var d=l.v===c?l.w:l.v,f=i(l);a[c][d]={distance:f,predecessor:c}})}),u.forEach(function(c){var l=a[c];u.forEach(function(d){var f=a[d];u.forEach(function(p){var y=f[c],g=l[p],b=f[p],x=y.distance+g.distance;x<b.distance&&(b.distance=x,b.predecessor=g.predecessor)})})}),a}return Vs}var Ws,Mp;function kb(){if(Mp)return Ws;Mp=1;var e=wr();Ws=t,t.CycleException=r;function t(n){var o={},i={},s=[];function a(u){if(e.has(i,u))throw new r;e.has(o,u)||(i[u]=!0,o[u]=!0,e.each(n.predecessors(u),a),delete i[u],s.push(u))}if(e.each(n.sinks(),a),e.size(o)!==n.nodeCount())throw new r;return s}function r(){}return r.prototype=new Error,Ws}var Gs,qp;function H1(){if(qp)return Gs;qp=1;var e=kb();Gs=t;function t(r){try{e(r)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Gs}var Us,Np;function Pb(){if(Np)return Us;Np=1;var e=wr();Us=t;function t(n,o,i){e.isArray(o)||(o=[o]);var s=(n.isDirected()?n.successors:n.neighbors).bind(n),a=[],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,s,a)}),a}function r(n,o,i,s,a,u){e.has(s,o)||(s[o]=!0,i||u.push(o),e.each(a(o),function(c){r(n,c,i,s,a,u)}),i&&u.push(o))}return Us}var Hs,$p;function K1(){if($p)return Hs;$p=1;var e=Pb();Hs=t;function t(r,n){return e(r,n,"post")}return Hs}var Ks,Lp;function J1(){if(Lp)return Ks;Lp=1;var e=Pb();Ks=t;function t(r,n){return e(r,n,"pre")}return Ks}var Js,Fp;function Z1(){if(Fp)return Js;Fp=1;var e=wr(),t=il(),r=Eb();Js=n;function n(o,i){var s=new t,a={},u=new r,c;function l(f){var p=f.v===c?f.w:f.v,y=u.priority(p);if(y!==void 0){var g=i(f);g<y&&(a[p]=c,u.decrease(p,g))}}if(o.nodeCount()===0)return s;e.each(o.nodes(),function(f){u.add(f,Number.POSITIVE_INFINITY),s.setNode(f)}),u.decrease(o.nodes()[0],0);for(var d=!1;u.size()>0;){if(c=u.removeMin(),e.has(a,c))s.setEdge(c,a[c]);else{if(d)throw new Error("Input graph is not connected: "+o);d=!0}o.nodeEdges(c).forEach(l)}return s}return Js}var Zs,Bp;function Y1(){return Bp||(Bp=1,Zs={components:V1(),dijkstra:jb(),dijkstraAll:W1(),findCycles:G1(),floydWarshall:U1(),isAcyclic:H1(),postorder:K1(),preorder:J1(),prim:Z1(),tarjan:Rb(),topsort:kb()}),Zs}var Ys,zp;function X1(){if(zp)return Ys;zp=1;var e=z1();return Ys={Graph:e.Graph,json:D1(),alg:Y1(),version:e.version},Ys}var Xs,Dp;function Sr(){if(Dp)return Xs;Dp=1;var e;if(typeof Vu=="function")try{e=X1()}catch{}return e||(e=window.graphlib),Xs=e,Xs}var Qs,Vp;function Q1(){if(Vp)return Qs;Vp=1;var e=eb(),t=1,r=4;function n(o){return e(o,t|r)}return Qs=n,Qs}var ec,Wp;function Gn(){if(Wp)return ec;Wp=1;var e=St(),t=qr(),r=Nn(),n=xr();function o(i,s,a){if(!n(a))return!1;var u=typeof s;return(u=="number"?t(a)&&r(s,a.length):u=="string"&&s in a)?e(a[s],i):!1}return ec=o,ec}var rc,Gp;function eC(){if(Gp)return rc;Gp=1;var e=Wn(),t=St(),r=Gn(),n=st(),o=Object.prototype,i=o.hasOwnProperty,s=e(function(a,u){a=Object(a);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),y=-1,g=p.length;++y<g;){var b=p[y],x=a[b];(x===void 0||t(x,o[b])&&!i.call(a,b))&&(a[b]=f[b])}return a});return rc=s,rc}var tc,Up;function rC(){if(Up)return tc;Up=1;var e=Nr(),t=qr(),r=Kr();function n(o){return function(i,s,a){var u=Object(i);if(!t(i)){var c=e(s,3);i=r(i),s=function(d){return c(u[d],d,u)}}var l=o(i,s,a);return l>-1?u[c?i[l]:l]:void 0}}return tc=n,tc}var nc,Hp;function tC(){if(Hp)return nc;Hp=1;var e=/\s/;function t(r){for(var n=r.length;n--&&e.test(r.charAt(n)););return n}return nc=t,nc}var oc,Kp;function nC(){if(Kp)return oc;Kp=1;var e=tC(),t=/^\s+/;function r(n){return n&&n.slice(0,e(n)+1).replace(t,"")}return oc=r,oc}var ic,Jp;function oC(){if(Jp)return ic;Jp=1;var e=nC(),t=xr(),r=kt(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,s=/^0o[0-7]+$/i,a=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||s.test(c)?a(c.slice(2),d?2:8):o.test(c)?n:+c}return ic=u,ic}var ac,Zp;function Ab(){if(Zp)return ac;Zp=1;var e=oC(),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 ac=n,ac}var sc,Yp;function iC(){if(Yp)return sc;Yp=1;var e=Ab();function t(r){var n=e(r),o=n%1;return n===n?o?n-o:n:0}return sc=t,sc}var cc,Xp;function aC(){if(Xp)return cc;Xp=1;var e=Cb(),t=Nr(),r=iC(),n=Math.max;function o(i,s,a){var u=i==null?0:i.length;if(!u)return-1;var c=a==null?0:r(a);return c<0&&(c=n(u+c,0)),e(i,t(s,3),c)}return cc=o,cc}var uc,Qp;function sC(){if(Qp)return uc;Qp=1;var e=rC(),t=aC(),r=e(t);return uc=r,uc}var lc,eg;function Tb(){if(eg)return lc;eg=1;var e=ol();function t(r){var n=r==null?0:r.length;return n?e(r,1):[]}return lc=t,lc}var dc,rg;function cC(){if(rg)return dc;rg=1;var e=el(),t=rb(),r=st();function n(o,i){return o==null?o:e(o,t(i),r)}return dc=n,dc}var fc,tg;function uC(){if(tg)return fc;tg=1;function e(t){var r=t==null?0:t.length;return r?t[r-1]:void 0}return fc=e,fc}var hc,ng;function lC(){if(ng)return hc;ng=1;var e=Mn(),t=rl(),r=Nr();function n(o,i){var s={};return i=r(i,3),t(o,function(a,u,c){e(s,u,i(a,u,c))}),s}return hc=n,hc}var pc,og;function al(){if(og)return pc;og=1;var e=kt();function t(r,n,o){for(var i=-1,s=r.length;++i<s;){var a=r[i],u=n(a);if(u!=null&&(c===void 0?u===u&&!e(u):o(u,c)))var c=u,l=a}return l}return pc=t,pc}var gc,ig;function dC(){if(ig)return gc;ig=1;function e(t,r){return t>r}return gc=e,gc}var yc,ag;function fC(){if(ag)return yc;ag=1;var e=al(),t=dC(),r=ct();function n(o){return o&&o.length?e(o,r,t):void 0}return yc=n,yc}var mc,sg;function Ob(){if(sg)return mc;sg=1;var e=Mn(),t=St();function r(n,o,i){(i!==void 0&&!t(n[o],i)||i===void 0&&!(o in n))&&e(n,o,i)}return mc=r,mc}var bc,cg;function hC(){if(cg)return bc;cg=1;var e=it(),t=Fn(),r=Ar(),n="[object Object]",o=Function.prototype,i=Object.prototype,s=o.toString,a=i.hasOwnProperty,u=s.call(Object);function c(l){if(!r(l)||e(l)!=n)return!1;var d=t(l);if(d===null)return!0;var f=a.call(d,"constructor")&&d.constructor;return typeof f=="function"&&f instanceof f&&s.call(f)==u}return bc=c,bc}var vc,ug;function Ib(){if(ug)return vc;ug=1;function e(t,r){if(!(r==="constructor"&&typeof t[r]=="function")&&r!="__proto__")return t[r]}return vc=e,vc}var xc,lg;function pC(){if(lg)return xc;lg=1;var e=an(),t=st();function r(n){return e(n,t(n))}return xc=r,xc}var wc,dg;function gC(){if(dg)return wc;dg=1;var e=Ob(),t=Dm(),r=Ym(),n=Vm(),o=Qm(),i=sn(),s=tr(),a=_b(),u=jt(),c=on(),l=xr(),d=hC(),f=cn(),p=Ib(),y=pC();function g(b,x,m,w,v,C,S){var j=p(b,m),T=p(x,m),k=S.get(T);if(k){e(b,m,k);return}var M=C?C(j,T,m+"",b,x,S):void 0,R=M===void 0;if(R){var _=s(T),A=!_&&u(T),I=!_&&!A&&f(T);M=T,_||A||I?s(j)?M=j:a(j)?M=n(j):A?(R=!1,M=t(T,!0)):I?(R=!1,M=r(T,!0)):M=[]:d(T)||i(T)?(M=j,i(j)?M=y(j):(!l(j)||c(j))&&(M=o(T))):R=!1}R&&(S.set(T,M),v(M,T,w,C,S),S.delete(T)),e(b,m,M)}return wc=g,wc}var Cc,fg;function yC(){if(fg)return Cc;fg=1;var e=In(),t=Ob(),r=el(),n=gC(),o=xr(),i=st(),s=Ib();function a(u,c,l,d,f){u!==c&&r(c,function(p,y){if(f||(f=new e),o(p))n(u,c,y,l,a,d,f);else{var g=d?d(s(u,y),p,y+"",u,c,f):void 0;g===void 0&&(g=p),t(u,y,g)}},i)}return Cc=a,Cc}var _c,hg;function mC(){if(hg)return _c;hg=1;var e=Wn(),t=Gn();function r(n){return e(function(o,i){var s=-1,a=i.length,u=a>1?i[a-1]:void 0,c=a>2?i[2]:void 0;for(u=n.length>3&&typeof u=="function"?(a--,u):void 0,c&&t(i[0],i[1],c)&&(u=a<3?void 0:u,a=1),o=Object(o);++s<a;){var l=i[s];l&&n(o,l,s,u)}return o})}return _c=r,_c}var Sc,pg;function bC(){if(pg)return Sc;pg=1;var e=yC(),t=mC(),r=t(function(n,o,i){e(n,o,i)});return Sc=r,Sc}var Ec,gg;function Mb(){if(gg)return Ec;gg=1;function e(t,r){return t<r}return Ec=e,Ec}var jc,yg;function vC(){if(yg)return jc;yg=1;var e=al(),t=Mb(),r=ct();function n(o){return o&&o.length?e(o,r,t):void 0}return jc=n,jc}var Rc,mg;function xC(){if(mg)return Rc;mg=1;var e=al(),t=Nr(),r=Mb();function n(o,i){return o&&o.length?e(o,t(i,2),r):void 0}return Rc=n,Rc}var kc,bg;function wC(){if(bg)return kc;bg=1;var e=Er(),t=function(){return e.Date.now()};return kc=t,kc}var Pc,vg;function CC(){if(vg)return Pc;vg=1;var e=qn(),t=Dn(),r=Nn(),n=xr(),o=un();function i(s,a,u,c){if(!n(s))return s;a=t(a,s);for(var l=-1,d=a.length,f=d-1,p=s;p!=null&&++l<d;){var y=o(a[l]),g=u;if(y==="__proto__"||y==="constructor"||y==="prototype")return s;if(l!=f){var b=p[y];g=c?c(b,y,p):void 0,g===void 0&&(g=n(b)?b:r(a[l+1])?[]:{})}e(p,y,g),p=p[y]}return s}return Pc=i,Pc}var Ac,xg;function _C(){if(xg)return Ac;xg=1;var e=Vn(),t=CC(),r=Dn();function n(o,i,s){for(var a=-1,u=i.length,c={};++a<u;){var l=i[a],d=e(o,l);s(d,l)&&t(c,r(l,o),d)}return c}return Ac=n,Ac}var Tc,wg;function SC(){if(wg)return Tc;wg=1;var e=_C(),t=fb();function r(n,o){return e(n,o,function(i,s){return t(n,s)})}return Tc=r,Tc}var Oc,Cg;function EC(){if(Cg)return Oc;Cg=1;var e=Tb(),t=xb(),r=wb();function n(o){return r(t(o,void 0,e),o+"")}return Oc=n,Oc}var Ic,_g;function jC(){if(_g)return Ic;_g=1;var e=SC(),t=EC(),r=t(function(n,o){return n==null?{}:e(n,o)});return Ic=r,Ic}var Mc,Sg;function RC(){if(Sg)return Mc;Sg=1;var e=Math.ceil,t=Math.max;function r(n,o,i,s){for(var a=-1,u=t(e((o-n)/(i||1)),0),c=Array(u);u--;)c[s?u:++a]=n,n+=i;return c}return Mc=r,Mc}var qc,Eg;function kC(){if(Eg)return qc;Eg=1;var e=RC(),t=Gn(),r=Ab();function n(o){return function(i,s,a){return a&&typeof a!="number"&&t(i,s,a)&&(s=a=void 0),i=r(i),s===void 0?(s=i,i=0):s=r(s),a=a===void 0?i<s?1:-1:r(a),e(i,s,a,o)}}return qc=n,qc}var Nc,jg;function PC(){if(jg)return Nc;jg=1;var e=kC(),t=e();return Nc=t,Nc}var $c,Rg;function AC(){if(Rg)return $c;Rg=1;function e(t,r){var n=t.length;for(t.sort(r);n--;)t[n]=t[n].value;return t}return $c=e,$c}var Lc,kg;function TC(){if(kg)return Lc;kg=1;var e=kt();function t(r,n){if(r!==n){var o=r!==void 0,i=r===null,s=r===r,a=e(r),u=n!==void 0,c=n===null,l=n===n,d=e(n);if(!c&&!d&&!a&&r>n||a&&u&&l&&!c&&!d||i&&u&&l||!o&&l||!s)return 1;if(!i&&!a&&!d&&r<n||d&&o&&s&&!i&&!a||c&&o&&s||!u&&s||!l)return-1}return 0}return Lc=t,Lc}var Fc,Pg;function OC(){if(Pg)return Fc;Pg=1;var e=TC();function t(r,n,o){for(var i=-1,s=r.criteria,a=n.criteria,u=s.length,c=o.length;++i<u;){var l=e(s[i],a[i]);if(l){if(i>=c)return l;var d=o[i];return l*(d=="desc"?-1:1)}}return r.index-n.index}return Fc=t,Fc}var Bc,Ag;function IC(){if(Ag)return Bc;Ag=1;var e=zn(),t=Vn(),r=Nr(),n=mb(),o=AC(),i=$n(),s=OC(),a=ct(),u=tr();function c(l,d,f){d.length?d=e(d,function(g){return u(g)?function(b){return t(b,g.length===1?g[0]:g)}:g}):d=[a];var p=-1;d=e(d,i(r));var y=n(l,function(g,b,x){var m=e(d,function(w){return w(g)});return{criteria:m,index:++p,value:g}});return o(y,function(g,b){return s(g,b,f)})}return Bc=c,Bc}var zc,Tg;function MC(){if(Tg)return zc;Tg=1;var e=ol(),t=IC(),r=Wn(),n=Gn(),o=r(function(i,s){if(i==null)return[];var a=s.length;return a>1&&n(i,s[0],s[1])?s=[]:a>2&&n(s[0],s[1],s[2])&&(s=[s[0]]),t(i,e(s,1),[])});return zc=o,zc}var Dc,Og;function qC(){if(Og)return Dc;Og=1;var e=lb(),t=0;function r(n){var o=++t;return e(n)+o}return Dc=r,Dc}var Vc,Ig;function NC(){if(Ig)return Vc;Ig=1;function e(t,r,n){for(var o=-1,i=t.length,s=r.length,a={};++o<i;){var u=o<s?r[o]:void 0;n(a,t[o],u)}return a}return Vc=e,Vc}var Wc,Mg;function $C(){if(Mg)return Wc;Mg=1;var e=qn(),t=NC();function r(n,o){return t(n||[],o||[],e)}return Wc=r,Wc}var Gc,qg;function Je(){if(qg)return Gc;qg=1;var e;if(typeof Vu=="function")try{e={cloneDeep:Q1(),constant:Qu(),defaults:eC(),each:nb(),filter:pb(),find:sC(),flatten:Tb(),forEach:tb(),forIn:cC(),has:gb(),isUndefined:yb(),last:uC(),map:bb(),mapValues:lC(),max:fC(),merge:bC(),min:vC(),minBy:xC(),now:wC(),pick:jC(),range:PC(),reduce:vb(),sortBy:MC(),uniqueId:qC(),values:Sb(),zipObject:$C()}}catch{}return e||(e=window._),Gc=e,Gc}var Uc,Ng;function LC(){if(Ng)return Uc;Ng=1,Uc=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 Uc}var Hc,$g;function FC(){if($g)return Hc;$g=1;var e=Je(),t=Sr().Graph,r=LC();Hc=o;var n=e.constant(1);function o(c,l){if(c.nodeCount()<=1)return[];var d=a(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],y=l[0],g;c.nodeCount();){for(;g=y.dequeue();)s(c,l,d,g);for(;g=p.dequeue();)s(c,l,d,g);if(c.nodeCount()){for(var b=l.length-2;b>0;--b)if(g=l[b].dequeue(),g){f=f.concat(s(c,l,d,g,!0));break}}}return f}function s(c,l,d,f,p){var y=p?[]:void 0;return e.forEach(c.inEdges(f.v),function(g){var b=c.edge(g),x=c.node(g.v);p&&y.push({v:g.v,w:g.w}),x.out-=b,u(l,d,x)}),e.forEach(c.outEdges(f.v),function(g){var b=c.edge(g),x=g.w,m=c.node(x);m.in-=b,u(l,d,m)}),c.removeNode(f.v),y}function a(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 x=d.edge(b.v,b.w)||0,m=l(b),w=x+m;d.setEdge(b.v,b.w,w),p=Math.max(p,d.node(b.v).out+=m),f=Math.max(f,d.node(b.w).in+=m)});var y=e.range(p+f+3).map(function(){return new r}),g=f+1;return e.forEach(d.nodes(),function(b){u(y,g,d.node(b))}),{graph:d,buckets:y,zeroIdx:g}}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 Hc}var Kc,Lg;function BC(){if(Lg)return Kc;Lg=1;var e=Je(),t=FC();Kc={run:r,undo:o};function r(i){var s=i.graph().acyclicer==="greedy"?t(i,a(i)):n(i);e.forEach(s,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 a(u){return function(c){return u.edge(c).weight}}}function n(i){var s=[],a={},u={};function c(l){e.has(u,l)||(u[l]=!0,a[l]=!0,e.forEach(i.outEdges(l),function(d){e.has(a,d.w)?s.push(d):c(d.w)}),delete a[l])}return e.forEach(i.nodes(),c),s}function o(i){e.forEach(i.edges(),function(s){var a=i.edge(s);if(a.reversed){i.removeEdge(s);var u=a.forwardName;delete a.reversed,delete a.forwardName,i.setEdge(s.w,s.v,a,u)}})}return Kc}var Jc,Fg;function pr(){if(Fg)return Jc;Fg=1;var e=Je(),t=Sr().Graph;Jc={addDummyNode:r,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:s,intersectRect:a,buildLayerMatrix:u,normalizeRanks:c,removeEmptyRanks:l,addBorderNode:d,maxRank:f,partition:p,time:y,notime:g};function r(b,x,m,w){var v;do v=e.uniqueId(w);while(b.hasNode(v));return m.dummy=x,b.setNode(v,m),v}function n(b){var x=new t().setGraph(b.graph());return e.forEach(b.nodes(),function(m){x.setNode(m,b.node(m))}),e.forEach(b.edges(),function(m){var w=x.edge(m.v,m.w)||{weight:0,minlen:1},v=b.edge(m);x.setEdge(m.v,m.w,{weight:w.weight+v.weight,minlen:Math.max(w.minlen,v.minlen)})}),x}function o(b){var x=new t({multigraph:b.isMultigraph()}).setGraph(b.graph());return e.forEach(b.nodes(),function(m){b.children(m).length||x.setNode(m,b.node(m))}),e.forEach(b.edges(),function(m){x.setEdge(m,b.edge(m))}),x}function i(b){var x=e.map(b.nodes(),function(m){var w={};return e.forEach(b.outEdges(m),function(v){w[v.w]=(w[v.w]||0)+b.edge(v).weight}),w});return e.zipObject(b.nodes(),x)}function s(b){var x=e.map(b.nodes(),function(m){var w={};return e.forEach(b.inEdges(m),function(v){w[v.v]=(w[v.v]||0)+b.edge(v).weight}),w});return e.zipObject(b.nodes(),x)}function a(b,x){var m=b.x,w=b.y,v=x.x-m,C=x.y-w,S=b.width/2,j=b.height/2;if(!v&&!C)throw new Error("Not possible to find intersection inside of the rectangle");var T,k;return Math.abs(C)*S>Math.abs(v)*j?(C<0&&(j=-j),T=j*v/C,k=j):(v<0&&(S=-S),T=S,k=S*C/v),{x:m+T,y:w+k}}function u(b){var x=e.map(e.range(f(b)+1),function(){return[]});return e.forEach(b.nodes(),function(m){var w=b.node(m),v=w.rank;e.isUndefined(v)||(x[v][w.order]=m)}),x}function c(b){var x=e.min(e.map(b.nodes(),function(m){return b.node(m).rank}));e.forEach(b.nodes(),function(m){var w=b.node(m);e.has(w,"rank")&&(w.rank-=x)})}function l(b){var x=e.min(e.map(b.nodes(),function(C){return b.node(C).rank})),m=[];e.forEach(b.nodes(),function(C){var S=b.node(C).rank-x;m[S]||(m[S]=[]),m[S].push(C)});var w=0,v=b.graph().nodeRankFactor;e.forEach(m,function(C,S){e.isUndefined(C)&&S%v!==0?--w:w&&e.forEach(C,function(j){b.node(j).rank+=w})})}function d(b,x,m,w){var v={width:0,height:0};return arguments.length>=4&&(v.rank=m,v.order=w),r(b,"border",v,x)}function f(b){return e.max(e.map(b.nodes(),function(x){var m=b.node(x).rank;if(!e.isUndefined(m))return m}))}function p(b,x){var m={lhs:[],rhs:[]};return e.forEach(b,function(w){x(w)?m.lhs.push(w):m.rhs.push(w)}),m}function y(b,x){var m=e.now();try{return x()}finally{console.log(b+" time: "+(e.now()-m)+"ms")}}function g(b,x){return x()}return Jc}var Zc,Bg;function zC(){if(Bg)return Zc;Bg=1;var e=Je(),t=pr();Zc={run:r,undo:o};function r(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(s){n(i,s)})}function n(i,s){var a=s.v,u=i.node(a).rank,c=s.w,l=i.node(c).rank,d=s.name,f=i.edge(s),p=f.labelRank;if(l!==u+1){i.removeEdge(s);var y,g,b;for(b=0,++u;u<l;++b,++u)f.points=[],g={width:0,height:0,edgeLabel:f,edgeObj:s,rank:u},y=t.addDummyNode(i,"edge",g,"_d"),u===p&&(g.width=f.width,g.height=f.height,g.dummy="edge-label",g.labelpos=f.labelpos),i.setEdge(a,y,{weight:f.weight},d),b===0&&i.graph().dummyChains.push(y),a=y;i.setEdge(a,c,{weight:f.weight},d)}}function o(i){e.forEach(i.graph().dummyChains,function(s){var a=i.node(s),u=a.edgeLabel,c;for(i.setEdge(a.edgeObj,u);a.dummy;)c=i.successors(s)[0],i.removeNode(s),u.points.push({x:a.x,y:a.y}),a.dummy==="edge-label"&&(u.x=a.x,u.y=a.y,u.width=a.width,u.height=a.height),s=c,a=i.node(s)})}return Zc}var Yc,zg;function xn(){if(zg)return Yc;zg=1;var e=Je();Yc={longestPath:t,slack:r};function t(n){var o={};function i(s){var a=n.node(s);if(e.has(o,s))return a.rank;o[s]=!0;var u=e.min(e.map(n.outEdges(s),function(c){return i(c.w)-n.edge(c).minlen}));return(u===Number.POSITIVE_INFINITY||u===void 0||u===null)&&(u=0),a.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 Yc}var Xc,Dg;function qb(){if(Dg)return Xc;Dg=1;var e=Je(),t=Sr().Graph,r=xn().slack;Xc=n;function n(a){var u=new t({directed:!1}),c=a.nodes()[0],l=a.nodeCount();u.setNode(c,{});for(var d,f;o(u,a)<l;)d=i(u,a),f=u.hasNode(d.v)?r(a,d):-r(a,d),s(u,a,f);return u}function o(a,u){function c(l){e.forEach(u.nodeEdges(l),function(d){var f=d.v,p=l===f?d.w:f;!a.hasNode(p)&&!r(u,d)&&(a.setNode(p,{}),a.setEdge(l,p,{}),c(p))})}return e.forEach(a.nodes(),c),a.nodeCount()}function i(a,u){return e.minBy(u.edges(),function(c){if(a.hasNode(c.v)!==a.hasNode(c.w))return r(u,c)})}function s(a,u,c){e.forEach(a.nodes(),function(l){u.node(l).rank+=c})}return Xc}var Qc,Vg;function DC(){if(Vg)return Qc;Vg=1;var e=Je(),t=qb(),r=xn().slack,n=xn().longestPath,o=Sr().alg.preorder,i=Sr().alg.postorder,s=pr().simplify;Qc=a,a.initLowLimValues=d,a.initCutValues=u,a.calcCutValue=l,a.leaveEdge=p,a.enterEdge=y,a.exchangeEdges=g;function a(w){w=s(w),n(w);var v=t(w);d(v),u(v,w);for(var C,S;C=p(v);)S=y(v,w,C),g(v,w,C,S)}function u(w,v){var C=i(w,w.nodes());C=C.slice(0,C.length-1),e.forEach(C,function(S){c(w,v,S)})}function c(w,v,C){var S=w.node(C),j=S.parent;w.edge(C,j).cutvalue=l(w,v,C)}function l(w,v,C){var S=w.node(C),j=S.parent,T=!0,k=v.edge(C,j),M=0;return k||(T=!1,k=v.edge(j,C)),M=k.weight,e.forEach(v.nodeEdges(C),function(R){var _=R.v===C,A=_?R.w:R.v;if(A!==j){var I=_===T,q=v.edge(R).weight;if(M+=I?q:-q,x(w,C,A)){var O=w.edge(C,A).cutvalue;M+=I?-O:O}}}),M}function d(w,v){arguments.length<2&&(v=w.nodes()[0]),f(w,{},1,v)}function f(w,v,C,S,j){var T=C,k=w.node(S);return v[S]=!0,e.forEach(w.neighbors(S),function(M){e.has(v,M)||(C=f(w,v,C,M,S))}),k.low=T,k.lim=C++,j?k.parent=j:delete k.parent,C}function p(w){return e.find(w.edges(),function(v){return w.edge(v).cutvalue<0})}function y(w,v,C){var S=C.v,j=C.w;v.hasEdge(S,j)||(S=C.w,j=C.v);var T=w.node(S),k=w.node(j),M=T,R=!1;T.lim>k.lim&&(M=k,R=!0);var _=e.filter(v.edges(),function(A){return R===m(w,w.node(A.v),M)&&R!==m(w,w.node(A.w),M)});return e.minBy(_,function(A){return r(v,A)})}function g(w,v,C,S){var j=C.v,T=C.w;w.removeEdge(j,T),w.setEdge(S.v,S.w,{}),d(w),u(w,v),b(w,v)}function b(w,v){var C=e.find(w.nodes(),function(j){return!v.node(j).parent}),S=o(w,C);S=S.slice(1),e.forEach(S,function(j){var T=w.node(j).parent,k=v.edge(j,T),M=!1;k||(k=v.edge(T,j),M=!0),v.node(j).rank=v.node(T).rank+(M?k.minlen:-k.minlen)})}function x(w,v,C){return w.hasEdge(v,C)}function m(w,v,C){return C.low<=v.lim&&v.lim<=C.lim}return Qc}var eu,Wg;function VC(){if(Wg)return eu;Wg=1;var e=xn(),t=e.longestPath,r=qb(),n=DC();eu=o;function o(u){switch(u.graph().ranker){case"network-simplex":a(u);break;case"tight-tree":s(u);break;case"longest-path":i(u);break;default:a(u)}}var i=t;function s(u){t(u),r(u)}function a(u){n(u)}return eu}var ru,Gg;function WC(){if(Gg)return ru;Gg=1;var e=Je();ru=t;function t(o){var i=n(o);e.forEach(o.graph().dummyChains,function(s){for(var a=o.node(s),u=a.edgeObj,c=r(o,i,u.v,u.w),l=c.path,d=c.lca,f=0,p=l[f],y=!0;s!==u.w;){if(a=o.node(s),y){for(;(p=l[f])!==d&&o.node(p).maxRank<a.rank;)f++;p===d&&(y=!1)}if(!y){for(;f<l.length-1&&o.node(p=l[f+1]).minRank<=a.rank;)f++;p=l[f]}o.setParent(s,p),s=o.successors(s)[0]}})}function r(o,i,s,a){var u=[],c=[],l=Math.min(i[s].low,i[a].low),d=Math.max(i[s].lim,i[a].lim),f,p;f=s;do f=o.parent(f),u.push(f);while(f&&(i[f].low>l||d>i[f].lim));for(p=f,f=a;(f=o.parent(f))!==p;)c.push(f);return{path:u.concat(c.reverse()),lca:p}}function n(o){var i={},s=0;function a(u){var c=s;e.forEach(o.children(u),a),i[u]={low:c,lim:s++}}return e.forEach(o.children(),a),i}return ru}var tu,Ug;function GC(){if(Ug)return tu;Ug=1;var e=Je(),t=pr();tu={run:r,cleanup:s};function r(a){var u=t.addDummyNode(a,"root",{},"_root"),c=o(a),l=e.max(e.values(c))-1,d=2*l+1;a.graph().nestingRoot=u,e.forEach(a.edges(),function(p){a.edge(p).minlen*=d});var f=i(a)+1;e.forEach(a.children(),function(p){n(a,u,d,f,l,c,p)}),a.graph().nodeRankFactor=d}function n(a,u,c,l,d,f,p){var y=a.children(p);if(!y.length){p!==u&&a.setEdge(u,p,{weight:0,minlen:c});return}var g=t.addBorderNode(a,"_bt"),b=t.addBorderNode(a,"_bb"),x=a.node(p);a.setParent(g,p),x.borderTop=g,a.setParent(b,p),x.borderBottom=b,e.forEach(y,function(m){n(a,u,c,l,d,f,m);var w=a.node(m),v=w.borderTop?w.borderTop:m,C=w.borderBottom?w.borderBottom:m,S=w.borderTop?l:2*l,j=v!==C?1:d-f[p]+1;a.setEdge(g,v,{weight:S,minlen:j,nestingEdge:!0}),a.setEdge(C,b,{weight:S,minlen:j,nestingEdge:!0})}),a.parent(p)||a.setEdge(u,g,{weight:0,minlen:d+f[p]})}function o(a){var u={};function c(l,d){var f=a.children(l);f&&f.length&&e.forEach(f,function(p){c(p,d+1)}),u[l]=d}return e.forEach(a.children(),function(l){c(l,1)}),u}function i(a){return e.reduce(a.edges(),function(u,c){return u+a.edge(c).weight},0)}function s(a){var u=a.graph();a.removeNode(u.nestingRoot),delete u.nestingRoot,e.forEach(a.edges(),function(c){var l=a.edge(c);l.nestingEdge&&a.removeEdge(c)})}return tu}var nu,Hg;function UC(){if(Hg)return nu;Hg=1;var e=Je(),t=pr();nu=r;function r(o){function i(s){var a=o.children(s),u=o.node(s);if(a.length&&e.forEach(a,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",s,u,c),n(o,"borderRight","_br",s,u,c)}}e.forEach(o.children(),i)}function n(o,i,s,a,u,c){var l={width:0,height:0,rank:c,borderType:i},d=u[i][c-1],f=t.addDummyNode(o,"border",l,s);u[i][c]=f,o.setParent(f,a),d&&o.setEdge(d,f,{weight:1})}return nu}var ou,Kg;function HC(){if(Kg)return ou;Kg=1;var e=Je();ou={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")&&(a(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){s(c.node(l))}),e.forEach(c.edges(),function(l){var d=c.edge(l);e.forEach(d.points,s),e.has(d,"y")&&s(d)})}function s(c){c.y=-c.y}function a(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 ou}var iu,Jg;function KC(){if(Jg)return iu;Jg=1;var e=Je();iu=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})),s=e.map(e.range(i+1),function(){return[]});function a(c){if(!e.has(n,c)){n[c]=!0;var l=r.node(c);s[l.rank].push(c),e.forEach(r.successors(c),a)}}var u=e.sortBy(o,function(c){return r.node(c).rank});return e.forEach(u,a),s}return iu}var au,Zg;function JC(){if(Zg)return au;Zg=1;var e=Je();au=t;function t(n,o){for(var i=0,s=1;s<o.length;++s)i+=r(n,o[s-1],o[s]);return i}function r(n,o,i){for(var s=e.zipObject(i,e.map(i,function(f,p){return p})),a=e.flatten(e.map(o,function(f){return e.sortBy(e.map(n.outEdges(f),function(p){return{pos:s[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(a.forEach(function(f){var p=f.pos+u;l[p]+=f.weight;for(var y=0;p>0;)p%2&&(y+=l[p+1]),p=p-1>>1,l[p]+=f.weight;d+=f.weight*y})),d}return au}var su,Yg;function ZC(){if(Yg)return su;Yg=1;var e=Je();su=t;function t(r,n){return e.map(n,function(o){var i=r.inEdges(o);if(i.length){var s=e.reduce(i,function(a,u){var c=r.edge(u),l=r.node(u.v);return{sum:a.sum+c.weight*l.order,weight:a.weight+c.weight}},{sum:0,weight:0});return{v:o,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:o}})}return su}var cu,Xg;function YC(){if(Xg)return cu;Xg=1;var e=Je();cu=t;function t(o,i){var s={};e.forEach(o,function(u,c){var l=s[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=s[u.v],l=s[u.w];!e.isUndefined(c)&&!e.isUndefined(l)&&(l.indegree++,c.out.push(s[u.w]))});var a=e.filter(s,function(u){return!u.indegree});return r(a)}function r(o){var i=[];function s(c){return function(l){l.merged||(e.isUndefined(l.barycenter)||e.isUndefined(c.barycenter)||l.barycenter>=c.barycenter)&&n(c,l)}}function a(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(),s(u)),e.forEach(u.out,a(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 s=0,a=0;o.weight&&(s+=o.barycenter*o.weight,a+=o.weight),i.weight&&(s+=i.barycenter*i.weight,a+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=s/a,o.weight=a,o.i=Math.min(i.i,o.i),i.merged=!0}return cu}var uu,Qg;function XC(){if(Qg)return uu;Qg=1;var e=Je(),t=pr();uu=r;function r(i,s){var a=t.partition(i,function(g){return e.has(g,"barycenter")}),u=a.lhs,c=e.sortBy(a.rhs,function(g){return-g.i}),l=[],d=0,f=0,p=0;u.sort(o(!!s)),p=n(l,c,p),e.forEach(u,function(g){p+=g.vs.length,l.push(g.vs),d+=g.barycenter*g.weight,f+=g.weight,p=n(l,c,p)});var y={vs:e.flatten(l,!0)};return f&&(y.barycenter=d/f,y.weight=f),y}function n(i,s,a){for(var u;s.length&&(u=e.last(s)).i<=a;)s.pop(),i.push(u.vs),a++;return a}function o(i){return function(s,a){return s.barycenter<a.barycenter?-1:s.barycenter>a.barycenter?1:i?a.i-s.i:s.i-a.i}}return uu}var lu,ey;function QC(){if(ey)return lu;ey=1;var e=Je(),t=ZC(),r=YC(),n=XC();lu=o;function o(a,u,c,l){var d=a.children(u),f=a.node(u),p=f?f.borderLeft:void 0,y=f?f.borderRight:void 0,g={};p&&(d=e.filter(d,function(C){return C!==p&&C!==y}));var b=t(a,d);e.forEach(b,function(C){if(a.children(C.v).length){var S=o(a,C.v,c,l);g[C.v]=S,e.has(S,"barycenter")&&s(C,S)}});var x=r(b,c);i(x,g);var m=n(x,l);if(p&&(m.vs=e.flatten([p,m.vs,y],!0),a.predecessors(p).length)){var w=a.node(a.predecessors(p)[0]),v=a.node(a.predecessors(y)[0]);e.has(m,"barycenter")||(m.barycenter=0,m.weight=0),m.barycenter=(m.barycenter*m.weight+w.order+v.order)/(m.weight+2),m.weight+=2}return m}function i(a,u){e.forEach(a,function(c){c.vs=e.flatten(c.vs.map(function(l){return u[l]?u[l].vs:l}),!0)})}function s(a,u){e.isUndefined(a.barycenter)?(a.barycenter=u.barycenter,a.weight=u.weight):(a.barycenter=(a.barycenter*a.weight+u.barycenter*u.weight)/(a.weight+u.weight),a.weight+=u.weight)}return lu}var du,ry;function e_(){if(ry)return du;ry=1;var e=Je(),t=Sr().Graph;du=r;function r(o,i,s){var a=n(o),u=new t({compound:!0}).setGraph({root:a}).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||a),e.forEach(o[s](c),function(f){var p=f.v===c?f.w:f.v,y=u.edge(p,c),g=e.isUndefined(y)?0:y.weight;u.setEdge(p,c,{weight:o.edge(f).weight+g})}),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 du}var fu,ty;function r_(){if(ty)return fu;ty=1;var e=Je();fu=t;function t(r,n,o){var i={},s;e.forEach(o,function(a){for(var u=r.parent(a),c,l;u;){if(c=r.parent(u),c?(l=i[c],i[c]=u):(l=s,s=u),l&&l!==u){n.setEdge(l,u);return}u=c}})}return fu}var hu,ny;function t_(){if(ny)return hu;ny=1;var e=Je(),t=KC(),r=JC(),n=QC(),o=e_(),i=r_(),s=Sr().Graph,a=pr();hu=u;function u(f){var p=a.maxRank(f),y=c(f,e.range(1,p+1),"inEdges"),g=c(f,e.range(p-1,-1,-1),"outEdges"),b=t(f);d(f,b);for(var x=Number.POSITIVE_INFINITY,m,w=0,v=0;v<4;++w,++v){l(w%2?y:g,w%4>=2),b=a.buildLayerMatrix(f);var C=r(f,b);C<x&&(v=0,m=e.cloneDeep(b),x=C)}d(f,m)}function c(f,p,y){return e.map(p,function(g){return o(f,g,y)})}function l(f,p){var y=new s;e.forEach(f,function(g){var b=g.graph().root,x=n(g,b,y,p);e.forEach(x.vs,function(m,w){g.node(m).order=w}),i(g,y,x.vs)})}function d(f,p){e.forEach(p,function(y){e.forEach(y,function(g,b){f.node(g).order=b})})}return hu}var pu,oy;function n_(){if(oy)return pu;oy=1;var e=Je(),t=Sr().Graph,r=pr();pu={positionX:y,findType1Conflicts:n,findType2Conflicts:o,addConflict:s,hasConflict:a,verticalAlignment:u,horizontalCompaction:c,alignCoordinates:f,findSmallestWidthAlignment:d,balance:p};function n(x,m){var w={};function v(C,S){var j=0,T=0,k=C.length,M=e.last(S);return e.forEach(S,function(R,_){var A=i(x,R),I=A?x.node(A).order:k;(A||R===M)&&(e.forEach(S.slice(T,_+1),function(q){e.forEach(x.predecessors(q),function(O){var W=x.node(O),V=W.order;(V<j||I<V)&&!(W.dummy&&x.node(q).dummy)&&s(w,O,q)})}),T=_+1,j=I)}),S}return e.reduce(m,v),w}function o(x,m){var w={};function v(S,j,T,k,M){var R;e.forEach(e.range(j,T),function(_){R=S[_],x.node(R).dummy&&e.forEach(x.predecessors(R),function(A){var I=x.node(A);I.dummy&&(I.order<k||I.order>M)&&s(w,A,R)})})}function C(S,j){var T=-1,k,M=0;return e.forEach(j,function(R,_){if(x.node(R).dummy==="border"){var A=x.predecessors(R);A.length&&(k=x.node(A[0]).order,v(j,M,_,T,k),M=_,T=k)}v(j,M,j.length,k,S.length)}),j}return e.reduce(m,C),w}function i(x,m){if(x.node(m).dummy)return e.find(x.predecessors(m),function(w){return x.node(w).dummy})}function s(x,m,w){if(m>w){var v=m;m=w,w=v}var C=x[m];C||(x[m]=C={}),C[w]=!0}function a(x,m,w){if(m>w){var v=m;m=w,w=v}return e.has(x[m],w)}function u(x,m,w,v){var C={},S={},j={};return e.forEach(m,function(T){e.forEach(T,function(k,M){C[k]=k,S[k]=k,j[k]=M})}),e.forEach(m,function(T){var k=-1;e.forEach(T,function(M){var R=v(M);if(R.length){R=e.sortBy(R,function(O){return j[O]});for(var _=(R.length-1)/2,A=Math.floor(_),I=Math.ceil(_);A<=I;++A){var q=R[A];S[M]===M&&k<j[q]&&!a(w,M,q)&&(S[q]=M,S[M]=C[M]=C[q],k=j[q])}}})}),{root:C,align:S}}function c(x,m,w,v,C){var S={},j=l(x,m,w,C),T=C?"borderLeft":"borderRight";function k(_,A){for(var I=j.nodes(),q=I.pop(),O={};q;)O[q]?_(q):(O[q]=!0,I.push(q),I=I.concat(A(q))),q=I.pop()}function M(_){S[_]=j.inEdges(_).reduce(function(A,I){return Math.max(A,S[I.v]+j.edge(I))},0)}function R(_){var A=j.outEdges(_).reduce(function(q,O){return Math.min(q,S[O.w]-j.edge(O))},Number.POSITIVE_INFINITY),I=x.node(_);A!==Number.POSITIVE_INFINITY&&I.borderType!==T&&(S[_]=Math.max(S[_],A))}return k(M,j.predecessors.bind(j)),k(R,j.successors.bind(j)),e.forEach(v,function(_){S[_]=S[w[_]]}),S}function l(x,m,w,v){var C=new t,S=x.graph(),j=g(S.nodesep,S.edgesep,v);return e.forEach(m,function(T){var k;e.forEach(T,function(M){var R=w[M];if(C.setNode(R),k){var _=w[k],A=C.edge(_,R);C.setEdge(_,R,Math.max(j(x,M,k),A||0))}k=M})}),C}function d(x,m){return e.minBy(e.values(m),function(w){var v=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY;return e.forIn(w,function(S,j){var T=b(x,j)/2;v=Math.max(S+T,v),C=Math.min(S-T,C)}),v-C})}function f(x,m){var w=e.values(m),v=e.min(w),C=e.max(w);e.forEach(["u","d"],function(S){e.forEach(["l","r"],function(j){var T=S+j,k=x[T],M;if(k!==m){var R=e.values(k);M=j==="l"?v-e.min(R):C-e.max(R),M&&(x[T]=e.mapValues(k,function(_){return _+M}))}})})}function p(x,m){return e.mapValues(x.ul,function(w,v){if(m)return x[m.toLowerCase()][v];var C=e.sortBy(e.map(x,v));return(C[1]+C[2])/2})}function y(x){var m=r.buildLayerMatrix(x),w=e.merge(n(x,m),o(x,m)),v={},C;e.forEach(["u","d"],function(j){C=j==="u"?m:e.values(m).reverse(),e.forEach(["l","r"],function(T){T==="r"&&(C=e.map(C,function(_){return e.values(_).reverse()}));var k=(j==="u"?x.predecessors:x.successors).bind(x),M=u(x,C,w,k),R=c(x,C,M.root,M.align,T==="r");T==="r"&&(R=e.mapValues(R,function(_){return-_})),v[j+T]=R})});var S=d(x,v);return f(v,S),p(v,x.graph().align)}function g(x,m,w){return function(v,C,S){var j=v.node(C),T=v.node(S),k=0,M;if(k+=j.width/2,e.has(j,"labelpos"))switch(j.labelpos.toLowerCase()){case"l":M=-j.width/2;break;case"r":M=j.width/2;break}if(M&&(k+=w?M:-M),M=0,k+=(j.dummy?m:x)/2,k+=(T.dummy?m:x)/2,k+=T.width/2,e.has(T,"labelpos"))switch(T.labelpos.toLowerCase()){case"l":M=T.width/2;break;case"r":M=-T.width/2;break}return M&&(k+=w?M:-M),M=0,k}}function b(x,m){return x.node(m).width}return pu}var gu,iy;function o_(){if(iy)return gu;iy=1;var e=Je(),t=pr(),r=n_().positionX;gu=n;function n(i){i=t.asNonCompoundGraph(i),o(i),e.forEach(r(i),function(s,a){i.node(a).x=s})}function o(i){var s=t.buildLayerMatrix(i),a=i.graph().ranksep,u=0;e.forEach(s,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+a})}return gu}var yu,ay;function i_(){if(ay)return yu;ay=1;var e=Je(),t=BC(),r=zC(),n=VC(),o=pr().normalizeRanks,i=WC(),s=pr().removeEmptyRanks,a=GC(),u=UC(),c=HC(),l=t_(),d=o_(),f=pr(),p=Sr().Graph;yu=y;function y($,D){var G=D&&D.debugTiming?f.time:f.notime;G("layout",function(){var N=G(" buildLayoutGraph",function(){return k($)});G(" runLayout",function(){g(N,G)}),G(" updateInputGraph",function(){b($,N)})})}function g($,D){D(" makeSpaceForEdgeLabels",function(){M($)}),D(" removeSelfEdges",function(){ue($)}),D(" acyclic",function(){t.run($)}),D(" nestingGraph.run",function(){a.run($)}),D(" rank",function(){n(f.asNonCompoundGraph($))}),D(" injectEdgeLabelProxies",function(){R($)}),D(" removeEmptyRanks",function(){s($)}),D(" nestingGraph.cleanup",function(){a.cleanup($)}),D(" normalizeRanks",function(){o($)}),D(" assignRankMinMax",function(){_($)}),D(" removeEdgeLabelProxies",function(){A($)}),D(" normalize.run",function(){r.run($)}),D(" parentDummyChains",function(){i($)}),D(" addBorderSegments",function(){u($)}),D(" order",function(){l($)}),D(" insertSelfEdges",function(){ne($)}),D(" adjustCoordinateSystem",function(){c.adjust($)}),D(" position",function(){d($)}),D(" positionSelfEdges",function(){Q($)}),D(" removeBorderNodes",function(){V($)}),D(" normalize.undo",function(){r.undo($)}),D(" fixupEdgeLabelCoords",function(){O($)}),D(" undoCoordinateSystem",function(){c.undo($)}),D(" translateGraph",function(){I($)}),D(" assignNodeIntersects",function(){q($)}),D(" reversePoints",function(){W($)}),D(" acyclic.undo",function(){t.undo($)})}function b($,D){e.forEach($.nodes(),function(G){var N=$.node(G),ee=D.node(G);N&&(N.x=ee.x,N.y=ee.y,D.children(G).length&&(N.width=ee.width,N.height=ee.height))}),e.forEach($.edges(),function(G){var N=$.edge(G),ee=D.edge(G);N.points=ee.points,e.has(ee,"x")&&(N.x=ee.x,N.y=ee.y)}),$.graph().width=D.graph().width,$.graph().height=D.graph().height}var x=["nodesep","edgesep","ranksep","marginx","marginy"],m={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},w=["acyclicer","ranker","rankdir","align"],v=["width","height"],C={width:0,height:0},S=["minlen","weight","width","height","labeloffset"],j={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},T=["labelpos"];function k($){var D=new p({multigraph:!0,compound:!0}),G=le($.graph());return D.setGraph(e.merge({},m,he(G,x),e.pick(G,w))),e.forEach($.nodes(),function(N){var ee=le($.node(N));D.setNode(N,e.defaults(he(ee,v),C)),D.setParent(N,$.parent(N))}),e.forEach($.edges(),function(N){var ee=le($.edge(N));D.setEdge(N,e.merge({},j,he(ee,S),e.pick(ee,T)))}),D}function M($){var D=$.graph();D.ranksep/=2,e.forEach($.edges(),function(G){var N=$.edge(G);N.minlen*=2,N.labelpos.toLowerCase()!=="c"&&(D.rankdir==="TB"||D.rankdir==="BT"?N.width+=N.labeloffset:N.height+=N.labeloffset)})}function R($){e.forEach($.edges(),function(D){var G=$.edge(D);if(G.width&&G.height){var N=$.node(D.v),ee=$.node(D.w),ge={rank:(ee.rank-N.rank)/2+N.rank,e:D};f.addDummyNode($,"edge-proxy",ge,"_ep")}})}function _($){var D=0;e.forEach($.nodes(),function(G){var N=$.node(G);N.borderTop&&(N.minRank=$.node(N.borderTop).rank,N.maxRank=$.node(N.borderBottom).rank,D=e.max(D,N.maxRank))}),$.graph().maxRank=D}function A($){e.forEach($.nodes(),function(D){var G=$.node(D);G.dummy==="edge-proxy"&&($.edge(G.e).labelRank=G.rank,$.removeNode(D))})}function I($){var D=Number.POSITIVE_INFINITY,G=0,N=Number.POSITIVE_INFINITY,ee=0,ge=$.graph(),ye=ge.marginx||0,K=ge.marginy||0;function X(U){var se=U.x,te=U.y,xe=U.width,pe=U.height;D=Math.min(D,se-xe/2),G=Math.max(G,se+xe/2),N=Math.min(N,te-pe/2),ee=Math.max(ee,te+pe/2)}e.forEach($.nodes(),function(U){X($.node(U))}),e.forEach($.edges(),function(U){var se=$.edge(U);e.has(se,"x")&&X(se)}),D-=ye,N-=K,e.forEach($.nodes(),function(U){var se=$.node(U);se.x-=D,se.y-=N}),e.forEach($.edges(),function(U){var se=$.edge(U);e.forEach(se.points,function(te){te.x-=D,te.y-=N}),e.has(se,"x")&&(se.x-=D),e.has(se,"y")&&(se.y-=N)}),ge.width=G-D+ye,ge.height=ee-N+K}function q($){e.forEach($.edges(),function(D){var G=$.edge(D),N=$.node(D.v),ee=$.node(D.w),ge,ye;G.points?(ge=G.points[0],ye=G.points[G.points.length-1]):(G.points=[],ge=ee,ye=N),G.points.unshift(f.intersectRect(N,ge)),G.points.push(f.intersectRect(ee,ye))})}function O($){e.forEach($.edges(),function(D){var G=$.edge(D);if(e.has(G,"x"))switch((G.labelpos==="l"||G.labelpos==="r")&&(G.width-=G.labeloffset),G.labelpos){case"l":G.x-=G.width/2+G.labeloffset;break;case"r":G.x+=G.width/2+G.labeloffset;break}})}function W($){e.forEach($.edges(),function(D){var G=$.edge(D);G.reversed&&G.points.reverse()})}function V($){e.forEach($.nodes(),function(D){if($.children(D).length){var G=$.node(D),N=$.node(G.borderTop),ee=$.node(G.borderBottom),ge=$.node(e.last(G.borderLeft)),ye=$.node(e.last(G.borderRight));G.width=Math.abs(ye.x-ge.x),G.height=Math.abs(ee.y-N.y),G.x=ge.x+G.width/2,G.y=N.y+G.height/2}}),e.forEach($.nodes(),function(D){$.node(D).dummy==="border"&&$.removeNode(D)})}function ue($){e.forEach($.edges(),function(D){if(D.v===D.w){var G=$.node(D.v);G.selfEdges||(G.selfEdges=[]),G.selfEdges.push({e:D,label:$.edge(D)}),$.removeEdge(D)}})}function ne($){var D=f.buildLayerMatrix($);e.forEach(D,function(G){var N=0;e.forEach(G,function(ee,ge){var ye=$.node(ee);ye.order=ge+N,e.forEach(ye.selfEdges,function(K){f.addDummyNode($,"selfedge",{width:K.label.width,height:K.label.height,rank:ye.rank,order:ge+ ++N,e:K.e,label:K.label},"_se")}),delete ye.selfEdges})})}function Q($){e.forEach($.nodes(),function(D){var G=$.node(D);if(G.dummy==="selfedge"){var N=$.node(G.e.v),ee=N.x+N.width/2,ge=N.y,ye=G.x-ee,K=N.height/2;$.setEdge(G.e,G.label),$.removeNode(D),G.label.points=[{x:ee+2*ye/3,y:ge-K},{x:ee+5*ye/6,y:ge-K},{x:ee+ye,y:ge},{x:ee+5*ye/6,y:ge+K},{x:ee+2*ye/3,y:ge+K}],G.label.x=G.x,G.label.y=G.y}})}function he($,D){return e.mapValues(e.pick($,D),Number)}function le($){var D={};return e.forEach($,function(G,N){D[N.toLowerCase()]=G}),D}return yu}var mu,sy;function a_(){if(sy)return mu;sy=1;var e=Je(),t=pr(),r=Sr().Graph;mu={debugOrdering:n};function n(o){var i=t.buildLayerMatrix(o),s=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(a){s.setNode(a,{label:a}),s.setParent(a,"layer"+o.node(a).rank)}),e.forEach(o.edges(),function(a){s.setEdge(a.v,a.w,{},a.name)}),e.forEach(i,function(a,u){var c="layer"+u;s.setNode(c,{rank:"same"}),e.reduce(a,function(l,d){return s.setEdge(l,d,{style:"invis"}),d})}),s}return mu}var bu,cy;function s_(){return cy||(cy=1,bu="0.8.5"),bu}var vu,uy;function c_(){return uy||(uy=1,vu={graphlib:Sr(),layout:i_(),debug:a_(),util:{time:pr().time,notime:pr().notime},version:s_()}),vu}var u_=c_();const ly=H0(u_);function l_(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 ly.graphlib.Graph({multigraph:!0,compound:!0}),s=r.compactSpacingScale??(r.spacingFactor>0?r.spacingFactor/1.3:1);i.setGraph({rankdir:r.rankDir,nodesep:r.compact?Math.max(r.nodeSep,24*s):r.nodeSep,edgesep:r.compact?Math.min(r.edgeSep,24*s):r.edgeSep,ranksep:r.compact?Math.min(r.rankSep,80*s):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=Mm(d.label,d.icon??((l=d.data)==null?void 0:l.icon),r.edgeLabelFontSize),p=r.rankDir==="LR"||r.rankDir==="RL",y=(f.width?f.width+2*Im:0)+(d.connectorClearance??0);i.setEdge(d.source,d.target,{minlen:1,weight:1,...y?{width:p?y:Math.max(1,f.height),height:p?Math.max(1,f.height):y,labelpos:"c"}:{}},d.id)}ly.layout(i);const a=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)&&a.set(d.id,{x:f.x,y:f.y})}const u=r.compact?1:r.spacingFactor;if(u&&u!==1&&a.size){let d=1/0,f=1/0,p=-1/0,y=-1/0;a.forEach(x=>{d=Math.min(d,x.x),f=Math.min(f,x.y),p=Math.max(p,x.x),y=Math.max(y,x.y)});const g=(d+p)/2,b=(f+y)/2;a.forEach((x,m)=>a.set(m,{x:g+(x.x-g)*u,y:b+(x.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",y=r.rankDir==="RL"||r.rankDir==="BT"?-1:1,g=c==="leading"?-y:y,b=new Map;for(const x of e){const m=a.get(x.id);if(!m)continue;const w=m[f];b.set(w,Math.max(b.get(w)??0,x[p]))}for(const x of e){const m=a.get(x.id);if(!m)continue;const w=m[f],v=(b.get(w)-x[p])/2;a.set(x.id,{...m,[f]:w+g*v})}}return a}function d_(e,t,r,n,o){const i=new Map,s=new Map(e.map(l=>[l.id,l]));for(const l of e){if(!l.parent||!s.has(l.parent))continue;const d=i.get(l.parent);d?d.push(l.id):i.set(l.parent,[l.id])}const a=(l,d=new Set)=>{var p;const f=(p=s.get(l))==null?void 0:p.parent;return!f||!s.has(f)||d.has(l)?0:(d.add(l),1+a(f,d))},u=[...i.keys()].sort((l,d)=>a(d)-a(l)),c=new Map;for(const l of u){let d=null;for(const y of i.get(l)||[]){let g=c.get(y);if(!g){const b=t.get(y);if(!b)continue;const x=r.get(y)||{w:60,h:60};g={x1:b.x-x.w/2,y1:b.y-x.h/2,x2:b.x+x.w/2,y2:b.y+x.h/2}}d=d?{x1:Math.min(d.x1,g.x1),y1:Math.min(d.y1,g.y1),x2:Math.max(d.x2,g.x2),y2:Math.max(d.y2,g.y2)}:{...g}}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 y=d.x2-d.x1,g=d.y2-d.y1;if(p.w>y){const b=(p.w-y)/2;d.x1-=b,d.x2+=b}if(p.h>g){const b=(p.h-g)/2;d.y1-=b,d.y2+=b}}c.set(l,d)}return c}function f_(e){const t=e.getBoundingClientRect(),r=t.height/e.offsetHeight;if(!Number.isFinite(r)||r<=0)return[];const n=Tm(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],s=new Set(i.filter(a=>a.hasAttribute("data-flow-inspection-row")&&a.getBoundingClientRect().height>0).map(a=>a.dataset.flowProperty));return i.flatMap(a=>{if(a.closest(".flow-sdk-node")!==e)return[];if(s.has(a.dataset.flowProperty)&&!a.hasAttribute("data-flow-inspection-row"))return[];const u=a.dataset.flowPortSide;if(u&&["top","right","bottom","left"].includes(u)){const l=km(n?Gt(o,n):o,u,Number(a.dataset.flowPortPosition??.5));return[{property:a.getAttribute("data-flow-property"),top:l.y,height:0,anchor:l,...a.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]}const c=a.getBoundingClientRect();return!c.width||!c.height?[]:[{property:a.getAttribute("data-flow-property"),top:Math.round((c.top-t.top)/r*1e3)/1e3,height:Math.round(c.height/r*1e3)/1e3,...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]})}function h_({id:e,x:t,y:r,placed:n,hidden:o,onMount:i,drawHandles:s,drawMode:a,connectedPorts:u,resolvedRows:c,hasCollapseControl:l,handleColor:d,animated:f,animationColor:p,animationWidth:y=8,animationVariant:g,width:b=0,height:x=0,propertyMode:m,reversePorts:w,direction:v="LR",onPropertyRows:C,onSurface:S,children:j}){const T=E.useRef(null),[k,M]=E.useState([]),R=c??k,[_,A]=E.useState();return E.useLayoutEffect(()=>{const I=T.current;if(!I)return;const q=()=>{const V=Tm(I);A(ue=>JSON.stringify(ue)===JSON.stringify(V)?ue:V),S==null||S(e,V)};q();const O=new ResizeObserver(q);O.observe(I);const W=I.querySelector("[data-flow-node-surface]");return W&&O.observe(W),()=>O.disconnect()},[e,j,S]),E.useLayoutEffect(()=>(i(e,T.current),()=>{i(e,null),S==null||S(e,void 0)}),[e,i,S]),E.useLayoutEffect(()=>{const I=T.current;if(!I)return;let q="";const O=()=>{const ne=f_(I),Q=m?ne:ne.filter(le=>le.anchor),he=JSON.stringify(Q);he!==q&&(q=he,M(Q),C==null||C(e,Q))};if(O(),!m&&!I.querySelector("[data-flow-port-side]"))return;const W=new ResizeObserver(O),V=()=>{W.disconnect(),W.observe(I),I.querySelectorAll("[data-flow-property]").forEach(ne=>W.observe(ne)),O()};V();const ue=new MutationObserver(V);return ue.observe(I,{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"]}),I.addEventListener("scroll",O,!0),()=>{W.disconnect(),ue.disconnect(),I.removeEventListener("scroll",O,!0)}},[e,m,C,j]),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:[j,f&&y>0&&b>0&&x>0&&h.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:h.jsx(Rm,{variant:g,x:((_==null?void 0:_.left)??0)+y/2,y:((_==null?void 0:_.top)??0)+y/2,width:((_==null?void 0:_.width)??b)-y,height:((_==null?void 0:_.height)??x)-y,radius:((_==null?void 0:_.radius)??0)-y/2,path:_!=null&&_.outline?`M${_.outline.map(I=>`${I.x} ${I.y}`).join(" L")} Z`:void 0,color:p||d||"currentColor",strokeWidth:y})}),s&&m&&R.map(I=>["source","target"].filter(q=>!I.role||I.role===q).filter(q=>a||(u==null?void 0:u.has(`${q}:${I.property}`))).map(q=>{var O;return h.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":I.property,"data-port-role":q,"data-port-side":(O=I.anchor)==null?void 0:O.side,"aria-label":`${q==="source"?"Connect":"Input"} ${I.property}`,title:`${q==="source"?"Connect":"Input"} ${I.property}`,style:{color:d,...I.anchor?{top:I.anchor.y,left:I.anchor.x-16}:{top:I.top+I.height/2,[q==="source"!=!!w?"right":"left"]:-16}},onClick:W=>W.stopPropagation()},`${I.property}:${q}`)})),s&&!l&&(!m||!R.length)&&(!m||!R.some(I=>I.anchor))&&h.jsx("button",{type:"button",className:"flow-sdk-handle","aria-label":"Draw edge",title:"Draw edge",style:{color:d,left:((_==null?void 0:_.left)??0)+(v==="RL"?-36:v==="LR"?(_==null?void 0:_.width)??b:((_==null?void 0:_.width)??b)/2),top:((_==null?void 0:_.top)??0)+(v==="BT"?-36:v==="TB"?(_==null?void 0:_.height)??x:((_==null?void 0:_.height)??x)/2),transform:v==="BT"||v==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:I=>I.stopPropagation(),children:h.jsx(J.PiPlusBold,{size:24})})]})}const p_=E.memo(h_);function g_(e,t,r){const[n,o]=E.useState(()=>({nodes:new Set,edges:new Set})),i=E.useMemo(()=>{const a=new Set(e.map(p=>p.id)),u=t.filter(p=>a.has(p.source)&&a.has(p.target)).map(p=>({id:p.id,source:p.inverted?p.target:p.source,target:p.inverted?p.source:p.target})),c=new Set(u.map(p=>p.id)),l=new Set([...n.nodes].filter(p=>a.has(p))),d=new Set([...n.edges].filter(p=>c.has(p)));if(!r)return{nodes:a,edges:c,ready:c};for(const p of e)u.filter(g=>g.target===p.id&&g.source!==g.target).every(g=>d.has(g.id))&&l.add(p.id);let f=new Set(u.filter(p=>l.has(p.source)).map(p=>p.id));if(l.size<a.size&&!u.some(p=>f.has(p.id)&&!d.has(p.id))){const p=e.find(y=>!l.has(y.id));p&&l.add(p.id),f=new Set(u.filter(y=>l.has(y.source)).map(y=>y.id))}return{nodes:l,edges:d,ready:f}},[e,t,r,n]);E.useLayoutEffect(()=>{o(a=>{const u=r?i:{nodes:new Set,edges:new Set},c=(l,d)=>l.size===d.size&&[...l].every(f=>d.has(f));return c(a.nodes,u.nodes)&&c(a.edges,u.edges)?a:{nodes:u.nodes,edges:u.edges}})},[i,r]);const s=E.useCallback(a=>{o(u=>u.edges.has(a)?u:{...u,edges:new Set([...u.edges,a])})},[]);return{shown:i.nodes,ready:i.ready,complete:s}}class y_{constructor(t,r,n){Or(this,"_pan");Or(this,"_zoom");Or(this,"minZoom");Or(this,"maxZoom");Or(this,"size",{w:0,h:0});Or(this,"listeners",new Set);Or(this,"animationFrame");Or(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(),s=300/1.4,a=()=>{this.cancelAnimation(),this.set(o.pan,o.zoom)},u=c=>{const l=Math.min(1,(c-i)/s);if(l>=1){a();return}const d=l*l*(3-2*l);this.apply({x:n.pan.x+(o.pan.x-n.pan.x)*d,y:n.pan.y+(o.pan.y-n.pan.y)*d},n.zoom+(o.zoom-n.zoom)*d),this.animationFrame=requestAnimationFrame(u)};this.animationFrame=requestAnimationFrame(u),this.animationTimer=setTimeout(a,s+100)}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,o=1){const i=t.x2-t.x1,s=t.y2-t.y1;if(!(i>0)||!(s>0)||!this.size.w||!this.size.h)return;const a=this.clamp(this.clamp(Math.min((this.size.w-2*r)/i,(this.size.h-2*r)/s))*o);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 m_={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},xu={w:60,h:60},dy=4,b_=30,fy=300,v_=500,x_=45,w_=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2;function hy(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 C_(e){var fl;const{nodes:t,edges:r,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:s=!1,rankSep:a,edgeSep:u,spacingFactor:c=1.3,compactSpacingScale:l,minZoom:d,maxZoom:f,initialViewport:p,containerStyle:y,lineColor:g,drawMode:b,dragMode:x,multiSelect:m,isPerformanceMode:w}=e,[v,C]=E.useState(null),S=E.useMemo(()=>v?(v.mode==="connections"?Bl:Ml)(v.id,t,r):null,[v,t,r]),j=i==="auto"||i==="properties",T=E.useMemo(()=>r.filter(P=>Ru(P,i)&&(!S||S.has(P.source)&&S.has(P.target))),[r,i,S]),k=E.useMemo(()=>z0(t,r,i,s,S),[t,r,i,s,S]),M=E.useRef(k);M.current=k;const R=E.useRef(e);R.current=e;const _=E.useRef(null),A=E.useRef(null),I=E.useRef(null),q=E.useRef(null),O=E.useMemo(()=>new y_(p,d,f),[]);E.useEffect(()=>{O.minZoom=d,O.maxZoom=f},[O,d,f]);const W=E.useRef(new Map),V=E.useRef(new Map),ue=E.useRef(new Map),ne=E.useRef(null),[Q,he]=E.useState(new Map),le=E.useCallback((P,L)=>{he(B=>{if(JSON.stringify(B.get(P))===JSON.stringify(L))return B;const H=new Map(B);return L?H.set(P,L):H.delete(P),H})},[]),[$,D]=E.useState(new Map),G=E.useRef($),N=E.useCallback((P,L)=>{D(B=>{if(JSON.stringify(B.get(P)??[])===JSON.stringify(L))return B;const H=new Map(B);return L.length?H.set(P,L):H.delete(P),H})},[]),[ee,ge]=E.useState(()=>new Map),ye=E.useRef(ee);ye.current=ee;const K=E.useRef(new Map),X=E.useRef(!1),[U,se]=E.useState(0),te=E.useRef(),xe=E.useRef(),pe=E.useRef(null),De=E.useRef(),Z=E.useRef(!1),de=E.useRef(null),Ce=E.useRef(c),Ie=s,qe=E.useRef(Ie),[Ue,Qe]=E.useState(!0),We=E.useRef(null);We.current=S;const we=E.useRef(1);we.current=(v==null?void 0:v.mode)==="connections"?1.25:1;const _e=E.useRef(null),He=E.useRef(t),Xe=E.useRef([]),ur=E.useRef(!1),er=()=>{pe.current!==null&&cancelAnimationFrame(pe.current),pe.current=null,clearTimeout(De.current)},sr=()=>{Xe.current.length&&(ur.current=!0),!X.current&&R.current.fitOnInit!==!1&&(Z.current=!0),clearTimeout(xe.current),xe.current=setTimeout(()=>{X.current=!0,se(P=>P+1)},v_)},Ee=P=>{er();const L=new Map(ye.current),B=performance.now(),H=()=>{er(),ge(P),sr()},ae=be=>{const Oe=Math.min(1,(be-B)/fy);if(Oe>=1)return H();const Le=w_(Oe),oe=new Map;P.forEach((ce,fe)=>{const ve=L.get(fe);oe.set(fe,ve?{x:ve.x+(ce.x-ve.x)*Le,y:ve.y+(ce.y-ve.y)*Le}:ce)}),ge(oe),pe.current=requestAnimationFrame(ae)};pe.current=requestAnimationFrame(ae),De.current=setTimeout(H,fy+100)},ut=()=>{const P=R.current,L=we.current,B=M.current,H=B.nodes.map(be=>{const Oe=W.current.get(be.id)||xu;return{id:be.id,parent:be.parent,width:Oe.w,height:Oe.h}});let ae;try{const be=P.compactPropertyLayout,Oe=P.edgeMode!=="nodes"&&P.edgeMode!=="workflow",Le=B.edges.map(oe=>({...oe,connectorClearance:be?Oe&&(oe.sourceProperty!==void 0||oe.targetProperty!==void 0)?B0:F0:0}));ae=l_(H,Le,{edgeLabelFontSize:P.edgeMode==="nodes"||P.edgeMode==="workflow"?Om:vn,rankDir:P.direction,compact:be,nodeAlignment:P.nodeAlignment,rankSep:P.rankSep*L,edgeSep:P.edgeSep*L,nodeSep:5*L,spacingFactor:P.spacingFactor??1.3,compactSpacingScale:(P.compactSpacingScale??(P.spacingFactor??1.3)/1.3)*L})}catch(be){console.warn("[flow-sdk] layout failed",be);return}for(const[be,Oe]of K.current)ae.has(be)?ae.set(be,Oe):P.nodes.some(Le=>Le.id===be)||K.current.delete(be);X.current&&!P.isPerformanceMode?Ee(ae):(er(),ge(ae),sr())},fr=E.useCallback(()=>{clearTimeout(xe.current),clearTimeout(te.current),te.current=setTimeout(ut,R.current.layoutDebounce)},[]);E.useEffect(()=>{const P=new Map(He.current.map(L=>[L.id,L]));t.some(L=>{var B;return((B=P.get(L.id))==null?void 0:B.collapsed)===!0&&!L.collapsed})&&(Xe.current=t.filter(L=>!P.has(L.id)).map(L=>L.id)),He.current=t,Ce.current!==c&&ye.current.size>0&&(X.current=!0,Z.current=!1,clearTimeout(xe.current)),Ce.current=c,qe.current!==Ie&&(Z.current=!de.current),qe.current=Ie,fr()},[t,r,k.nodes,k.edges,Ie,n,o,a,u,fr,c,l]),E.useEffect(()=>()=>{clearTimeout(te.current),clearTimeout(xe.current),er()},[]);const Pt=E.useCallback((P,L)=>{var B,H;if(!ne.current&&typeof ResizeObserver<"u"&&(ne.current=new ResizeObserver(ae=>{let be=!1;for(const Oe of ae){const Le=ue.current.get(Oe.target);if(!Le)continue;const oe=Oe.target,ce=oe.offsetWidth,fe=oe.offsetHeight;if(!ce&&!fe)continue;const ve=W.current.get(Le);ve&&ve.w===ce&&ve.h===fe||(W.current.set(Le,{w:ce,h:fe}),be=!0)}be&&fr()})),L){V.current.set(P,L),ue.current.set(L,P),(B=ne.current)==null||B.observe(L);const ae=L.offsetWidth,be=L.offsetHeight;(ae||be)&&W.current.set(P,{w:ae,h:be})}else{const ae=V.current.get(P);ae&&((H=ne.current)==null||H.unobserve(ae),ue.current.delete(ae)),V.current.delete(P),W.current.delete(P),G.current.has(P)&&N(P,[])}fr()},[fr,N]);E.useEffect(()=>()=>{var P;return(P=ne.current)==null?void 0:P.disconnect()},[]);const ie=E.useMemo(()=>{const P=new Map;for(const L of t)L.label&&P.set(L.id,L.label);return P},[t]),Fe=E.useMemo(()=>d_(k.nodes,ee,W.current,P=>y(P).padding,P=>{const L=ie.get(P);if(!L)return;const B=y(P);return{w:kn(L,`bold ${B.fontSize}px ${ot}`)+2*x_,h:0}}),[k.nodes,ee,y,ie]),Ze=E.useRef(Fe);Ze.current=Fe;const Be=E.useCallback(P=>{const L=Ze.current.get(P);if(L)return E0(L);const B=ye.current.get(P);if(!B)return;const H=W.current.get(P)||xu;return{x:B.x,y:B.y,w:H.w,h:H.h}},[]),lr=E.useMemo(()=>{const P=new Map;for(const L of t){const B=Be(L.id);B&&P.set(L.id,B)}return M0($,P,Q,r,n)},[$,t,ee,Fe,Q,r,n,Be]);G.current=lr;const re=(P,L)=>{var ae;if(!j||L===void 0)return;const B=(ae=lr.get(P))==null?void 0:ae.find(be=>be.property===L),H=Be(P);return B&&!B.anchor&&H?H.y-H.h/2+B.top+B.height/2:void 0},F=(P,L)=>{var ae,be;if(L===void 0)return;const B=(be=(ae=lr.get(P))==null?void 0:ae.find(Oe=>Oe.property===L))==null?void 0:be.anchor,H=Be(P);return B&&H?{x:H.x-H.w/2+B.x,y:H.y-H.h/2+B.y,side:B.side}:void 0},Y=(P,L)=>{const B=Be(P),H=Q.get(P);return B&&H&&!Fe.has(P)&&re(P,L)===void 0?Gt(B,H):B},Re=()=>{const P=[];ye.current.forEach((L,B)=>{if(Ze.current.has(B))return;const H=W.current.get(B)||xu;P.push(ft({x:L.x,y:L.y,w:H.w,h:H.h}))}),Ze.current.forEach(L=>P.push(L));try{for(const L of[A.current,I.current]){const B=L==null?void 0:L.getBBox();B&&B.width>0&&B.height>0&&P.push({x1:B.x,y1:B.y,x2:B.x+B.width,y2:B.y+B.height})}}catch{}return ro(P)},Pe=()=>{var B,H;const{pan:P,zoom:L}=O;q.current&&(q.current.style.transform=`translate3d(${P.x}px, ${P.y}px, 0) scale(${L})`),(B=A.current)==null||B.setAttribute("transform",`translate(${P.x} ${P.y}) scale(${L})`),(H=I.current)==null||H.setAttribute("transform",`translate(${P.x} ${P.y}) scale(${L})`)};E.useEffect(()=>{Pe();let P=null,L;const B=O.onChange(()=>{Pe();const H=_.current;H&&(H.classList.add("flow-sdk-busy"),clearTimeout(L),L=setTimeout(()=>H.classList.remove("flow-sdk-busy"),150)),P===null&&(P=requestAnimationFrame(()=>{var ae,be;P=null,(be=(ae=R.current).onViewportChange)==null||be.call(ae,O.state)}))});return()=>{B(),clearTimeout(L),P!==null&&cancelAnimationFrame(P)}},[]),E.useLayoutEffect(()=>{const P=_.current;if(!P)return;const L=()=>{let H=P.clientWidth,ae=P.clientHeight;ae||(ae=Math.max(0,window.innerHeight-P.getBoundingClientRect().top-100),ae&&(P.style.height=`${ae}px`)),H||(H=window.innerWidth,H&&(P.style.width=`${H}px`)),O.size={w:H,h:ae}};if(L(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(L);return B.observe(P),()=>B.disconnect()},[O]),E.useEffect(()=>{if(ur.current){ur.current=!1;const L=Xe.current.flatMap(H=>{const ae=Be(H);return ae?[ft(ae)]:[]});Xe.current=[];const B=ro(L);if(B){Z.current=!1,O.center(B,R.current.animateViewport);return}}if(!Z.current)return;Z.current=!1;const P=Re();P&&O.fit(P,50,R.current.animateViewport)},[ee]);const ke=E.useMemo(()=>{const P=oe=>Ml(oe,R.current.nodes,R.current.edges),L=(oe,ce=50,fe=R.current.animateViewport,ve=1)=>{const nr=ro([...oe].flatMap(Zr=>{const Yr=Be(Zr);return Yr?[ft(Yr)]:[]}));nr&&(Z.current=!1,O.fit(nr,Number.isFinite(ce)?Math.max(0,ce):50,fe,ve))},B=(oe,ce,fe,ve)=>{var Zr;if(!Be(oe))return;const nr=ce==="connections"?ae(oe):P(oe);if(ce==="connections"&&we.current===1.25&&((Zr=We.current)==null?void 0:Zr.size)===nr.size&&[...nr].every(Yr=>We.current.has(Yr))){C({id:oe,mode:ce});return}_e.current||(_e.current={pan:{...O.pan},zoom:O.zoom}),We.current=nr,R.current.compactPropertyLayout&&(Z.current=!1,de.current=()=>L(We.current??nr,fe,ve)),C({id:oe,mode:ce}),R.current.compactPropertyLayout||L(nr,fe,ve)},H=oe=>{de.current?de.current=oe:oe()},ae=oe=>Bl(oe,R.current.nodes,R.current.edges),be=(oe=>{if(oe===void 0)return O.zoom;O.set(void 0,oe)}),Oe=(oe=>{if(oe===void 0)return O.pan;O.set(oe)}),Le=(oe,ce)=>{var ve;const fe=(ve=_.current)==null?void 0:ve.getBoundingClientRect();return{x:oe-((fe==null?void 0:fe.left)??0),y:ce-((fe==null?void 0:fe.top)??0)}};return{zoom:be,pan:Oe,setEdgesVisible:Qe,focusNode:(oe,ce,fe)=>H(()=>L(new Set([oe]),ce,fe,.6)),focusBranch:(oe,ce,fe)=>H(()=>L(P(oe),ce,fe)),focusConnections:(oe,ce,fe)=>H(()=>L(ae(oe),ce,fe)),isolateConnections:(oe,ce,fe)=>B(oe,"connections",ce,fe),isolateBranch:(oe,ce,fe)=>B(oe,"branch",ce,fe),restoreView:(oe=R.current.animateViewport,ce)=>{const fe=R.current.compactPropertyLayout&&!!We.current;We.current=null,C(null);const ve=ce??_e.current;_e.current=null,fe?de.current=()=>{ve&&O.transition(ve,oe)}:ve&&H(()=>O.transition(ve,oe))},zoomAt:(oe,ce)=>O.zoomAt(oe,ce),fit:(oe=0,ce=R.current.animateViewport)=>{H(()=>{const fe=Re();fe&&O.fit(fe,oe,ce)})},centerAndFit:(oe=0,ce=R.current.animateViewport)=>{H(()=>{const fe=Re();fe&&O.fit(fe,oe,ce)})},center:(oe=R.current.animateViewport)=>{const ce=Re();ce&&O.center(ce,oe)},clientToModel:(oe,ce)=>O.renderedToModel(Le(oe,ce)),modelToClient:oe=>{var ve;const ce=(ve=_.current)==null?void 0:ve.getBoundingClientRect(),fe=O.modelToRendered(oe);return{x:fe.x+((ce==null?void 0:ce.left)??0),y:fe.y+((ce==null?void 0:ce.top)??0)}},getNodeBox:oe=>Be(oe),setNodePosition:(oe,ce,fe)=>{if(!ye.current.has(oe)||ce&&(!Number.isFinite(ce.x)||!Number.isFinite(ce.y)))return!1;if(er(),!ce)return K.current.delete(oe),fr(),!0;const ve=new Map(ye.current);return ve.set(oe,{...ce}),(fe==null?void 0:fe.persist)===!1?K.current.delete(oe):K.current.set(oe,{...ce}),ye.current=ve,ge(ve),(fe==null?void 0:fe.persist)===!1&&fr(),!0},onViewportChange:oe=>O.onChange(oe)}},[]);E.useEffect(()=>{var P,L;return(L=(P=R.current).onInit)==null||L.call(P,ke),()=>O.cancelAnimation()},[ke]),E.useEffect(()=>{var P,L;if(U>0){const B=de.current;de.current=null,B==null||B(),(L=(P=R.current).onLayoutComplete)==null||L.call(P,ke)}},[ke,U]);const Me=E.useRef(null),ze=E.useRef(new Map),Ke=E.useRef(!1),[Ge,jr]=E.useState(null),[Ae,gr]=E.useState(null),$r=P=>{const L=_.current.getBoundingClientRect();return{x:P.clientX-L.left,y:P.clientY-L.top}},Tr=(P,L)=>{const B=R.current.nodes;for(let H=B.length-1;H>=0;H--){const ae=B[H].id;if(!ht(ae,R.current.edges,R.current.edgeMode)||We.current&&!We.current.has(ae)||ae===L||Ze.current.has(ae))continue;const be=Be(ae);if(be&&ql(P,ft(be)))return ae}for(const[H,ae]of Ze.current)if(ht(H,R.current.edges,R.current.edgeMode)&&!(We.current&&!We.current.has(H))&&H!==L&&ql(P,ae))return H;return null},Lr=(P,L)=>{if(R.current.edgeMode==="nodes"||R.current.edgeMode==="workflow")return null;const B=R.current.direction==="RL",H=Math.max(16,6/O.zoom);let ae=null;for(const be of[...R.current.nodes].reverse()){if(!ht(be.id,R.current.edges,R.current.edgeMode)||We.current&&!We.current.has(be.id))continue;const Oe=Be(be.id),Le=G.current.get(be.id);if(!Oe||!Le||Ze.current.has(be.id))continue;const oe=Oe.x+(L==="source"!==B?1:-1)*Oe.w/2;for(const ce of Le){if(ce.role&&ce.role!==L)continue;const fe=Oe.y-Oe.h/2+ce.top,ve=Math.hypot(P.x-(ce.anchor?Oe.x-Oe.w/2+ce.anchor.x:oe),P.y-fe-ce.height/2);if(!ce.anchor&&P.x>=Oe.x-Oe.w/2&&P.x<=Oe.x+Oe.w/2&&P.y>=fe&&P.y<=fe+ce.height)return{nodeId:be.id,property:ce.property};ve<=H&&(!ae||ve<ae.distance)&&(ae={nodeId:be.id,property:ce.property,distance:ve})}}return ae},Gb=P=>{var Oe;if(!P.currentTarget.contains(P.target)||P.button!==0||R.current.readOnly)return;Me.current||(Ke.current=!1);const L=P.target;if(L.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const B=R.current,H=$r(P);if(P.pointerType==="touch"){ze.current.set(P.pointerId,H);const Le=hy(ze.current);if(Le){Me.current={kind:"pinch",distance:Le.distance,zoom:O.zoom,anchor:O.renderedToModel(Le.center)},gr(null),jr(null),Ke.current=!0;for(const oe of ze.current.keys())P.currentTarget.setPointerCapture(oe);return}}if(Me.current)return;const ae=B.drawHandles&&L.closest(".flow-sdk-handle"),be=B.drawHandles&&L.closest(".flow-sdk-property-port");if(B.drawMode||ae||be){const Le=O.renderedToModel(H),oe=B.drawMode?Lr(Le,"source"):null,ce=be||ae,fe=ce?(Oe=ce.closest("[data-node-id]"))==null?void 0:Oe.dataset.nodeId:(oe==null?void 0:oe.nodeId)??Tr(Le),ve=be?be.dataset.property:oe==null?void 0:oe.property;if(fe){Me.current={kind:"draw",pointerId:P.pointerId,source:fe,sourceProperty:ve,reverse:(be==null?void 0:be.dataset.portRole)==="target",startClient:{x:P.clientX,y:P.clientY}},Ke.current=!0,gr({source:fe,sourceProperty:ve,point:Le,target:null}),P.currentTarget.setPointerCapture(P.pointerId);return}}L.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(B.multiSelect?Me.current={kind:"box",pointerId:P.pointerId,start:H,current:H}:B.dragMode?Me.current={kind:"pan",pointerId:P.pointerId,start:H,pan0:O.pan,moved:!1}:Me.current={kind:"tap",pointerId:P.pointerId,start:H,moved:!1},P.currentTarget.setPointerCapture(P.pointerId))},Ub=P=>{const L=Me.current;if(!L||R.current.readOnly)return;const B=$r(P);if(ze.current.has(P.pointerId)&&ze.current.set(P.pointerId,B),L.kind==="pinch"){const H=hy(ze.current);if(!H)return;const ae=Math.max(O.minZoom,Math.min(O.maxZoom,L.zoom*H.distance/L.distance));O.set({x:H.center.x-L.anchor.x*ae,y:H.center.y-L.anchor.y*ae},ae);return}if(L.pointerId===P.pointerId)switch(L.kind){case"pan":{const H=B.x-L.start.x,ae=B.y-L.start.y;if(!L.moved&&Math.hypot(H,ae)<=dy)return;L.moved=!0,Ke.current=!0,O.set({x:L.pan0.x+H,y:L.pan0.y+ae});break}case"tap":{Math.hypot(B.x-L.start.x,B.y-L.start.y)>dy&&(L.moved=!0);break}case"box":{Ke.current=!0,L.current=B,jr({x1:Math.min(L.start.x,B.x),y1:Math.min(L.start.y,B.y),x2:Math.max(L.start.x,B.x),y2:Math.max(L.start.y,B.y)});break}case"draw":{const H=O.renderedToModel(B),ae=Lr(H,L.reverse?"source":"target");gr(L.reverse&&ae?{source:ae.nodeId,sourceProperty:ae.property,point:H,target:L.source,targetProperty:L.sourceProperty}:{source:L.source,sourceProperty:L.sourceProperty,point:H,target:(ae==null?void 0:ae.nodeId)??Tr(H,L.source),targetProperty:ae==null?void 0:ae.property});break}}},ul=(P,L)=>{var ae,be,Oe,Le,oe;ze.current.delete(P.pointerId);const B=Me.current;if(!B)return;if(B.kind==="pinch"){const ce=[...ze.current][0];Me.current=ce&&R.current.dragMode&&!L?{kind:"pan",pointerId:ce[0],start:ce[1],pan0:O.pan,moved:!0}:null;return}if(B.pointerId!==P.pointerId)return;Me.current=null;try{P.currentTarget.releasePointerCapture(P.pointerId)}catch{}const H=R.current;switch(L=L||!!H.readOnly,B.kind){case"pan":case"tap":!L&&!B.moved&&((ae=H.onBackgroundTap)==null||ae.call(H));break;case"box":{if(jr(null),L)break;const ce=O.renderedToModel(B.start),fe=O.renderedToModel(B.current),ve={x1:Math.min(ce.x,fe.x),y1:Math.min(ce.y,fe.y),x2:Math.max(ce.x,fe.x),y2:Math.max(ce.y,fe.y)};if(ve.x2-ve.x1<1&&ve.y2-ve.y1<1){(be=H.onBackgroundTap)==null||be.call(H);break}const nr=[];for(const Zr of H.nodes){const Yr=Be(Zr.id);Yr&&j0(ft(Yr),ve)&&nr.push(Zr.id)}nr.length&&((Oe=H.onBoxSelect)==null||Oe.call(H,nr));break}case"draw":{if(gr(null),L)break;const ce=$r(P),fe=O.renderedToModel(ce),ve=Lr(fe,B.reverse?"source":"target"),nr=(ve==null?void 0:ve.nodeId)??Tr(fe);if(nr===B.source&&(B.sourceProperty===void 0||(ve==null?void 0:ve.property)===void 0||ve.property===B.sourceProperty))break;nr?(Le=H.onEdgeDraw)==null||Le.call(H,B.reverse?nr:B.source,B.reverse?B.source:nr,B.sourceProperty!==void 0||(ve==null?void 0:ve.property)!==void 0?{sourceProperty:B.reverse?ve==null?void 0:ve.property:B.sourceProperty,targetProperty:B.reverse?B.sourceProperty:ve==null?void 0:ve.property}:void 0):Math.max(Math.abs(P.clientX-B.startClient.x),Math.abs(P.clientY-B.startClient.y))>b_&&((oe=H.onDrawIntoSpace)==null||oe.call(H,B.source,fe,B.sourceProperty,B.reverse));break}}},Jr=E.useCallback(()=>{var B;const P=Me.current,L=[...ze.current.keys()];P&&P.kind!=="pinch"&&L.push(P.pointerId),Me.current=null,ze.current.clear(),gr(null),jr(null);for(const H of L)(B=_.current)!=null&&B.hasPointerCapture(H)&&_.current.releasePointerCapture(H)},[]);E.useEffect(()=>{const P=L=>{L.key==="Escape"&&Jr()};return window.addEventListener("keydown",P),window.addEventListener("blur",Jr),()=>{window.removeEventListener("keydown",P),window.removeEventListener("blur",Jr),Me.current=null,ze.current.clear()}},[Jr]),E.useEffect(()=>{Jr()},[b,x,m,i,n,e.drawHandles,e.readOnly,Jr]);const Hb=E.useMemo(()=>{const P=new Map,L=new Map;for(const B of T){if(B.source!==B.target)continue;const H=P.get(B.source)??0;P.set(B.source,H+1),L.set(B.id,H)}return L},[T]),Kn=m_[n],[Jn,Kb]=E.useState(null),Zn=g_(t,T,!!((fl=e.edgeReveal)!=null&&fl.revealNodes));E.useLayoutEffect(()=>{_.current&&Jn&&U0(_.current)});const Yn=S0(T,Y,Kn),Jb=e.onEdgeSelect,Zb=e.onContainerSelect,ll=Ae?Ae.target&&Y(Ae.target,Ae.targetProperty)||{x:Ae.point.x,y:Ae.point.y,w:1,h:1}:null,dl=Ae?Y(Ae.source,Ae.sourceProperty):null,Yb=["flow-sdk-canvas",b?"flow-sdk-draw":"",w?"flow-sdk-perf":""].filter(Boolean).join(" ");return h.jsxs("div",{ref:_,className:Yb,"data-edge-mode":i,onPointerDownCapture:Gb,onPointerMove:Ub,onPointerUp:P=>ul(P,!1),onPointerCancel:P=>ul(P,!0),onLostPointerCapture:P=>{const L=Me.current;L&&(L.kind==="pinch"||L.pointerId===P.pointerId)&&Jr()},onClickCapture:P=>{P.currentTarget.contains(P.target)&&(Ke.current||e.readOnly)&&(P.preventDefault(),P.stopPropagation())},children:[h.jsx("svg",{className:"flow-sdk-svg",children:h.jsxs("g",{ref:A,children:[h.jsx("g",{className:"flow-sdk-containers",children:[...Fe].filter(([P])=>ht(P,r,i)).filter(([P])=>!S||S.has(P)).map(([P,L])=>{var B;return h.jsx(L0,{id:P,rect:L,label:ie.get(P),labelLayer:Jn,style:y(P),onSelect:Zb,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(B=e.selectedNodeIds)==null?void 0:B.includes(P)},P)})}),h.jsx("g",{className:"flow-sdk-edges",children:Ue&&T.map(P=>{var H,ae,be;if(!Zn.ready.has(P.id)||S&&(!S.has(P.source)||!S.has(P.target)))return null;const L=Y(P.source,P.sourceProperty),B=Y(P.target,P.targetProperty);return!L||!B?null:h.jsx(zl,{id:P.id,edgeData:P.data,validationIssue:P.validationIssue,edgeType:P.type,edgeRadius:e.edgeRadius,propertyMode:j,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:Zn.complete,source:L,target:B,sourceProperty:P.sourceProperty,targetProperty:P.targetProperty,sourceY:re(P.source,P.sourceProperty),targetY:re(P.target,P.targetProperty),sourcePort:F(P.source,P.sourceProperty),targetPort:F(P.target,P.targetProperty),dir:Kn,turn:((H=Yn.get(P.id))==null?void 0:H.turn)??P.turn,labelAtTarget:(ae=Yn.get(P.id))==null?void 0:ae.labelAtTarget,labelFraction:(be=Yn.get(P.id))==null?void 0:be.labelFraction,color:P.color,connectorColor:P.connectorColor,labelBg:P.labelBg,label:P.label,labelLayer:Jn,dashed:P.dashed,animated:P.animated&&!w,inverted:P.inverted,loopIndex:Hb.get(P.id)??0,onSelect:Jb},P.id)})}),Ue&&Ae&&Ru(Ae,i)&&dl&&ll&&h.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:h.jsx(zl,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:Ae.source,target:Ae.target??"",sourceProperty:Ae.sourceProperty,targetProperty:Ae.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:j,customEdgeTypes:e.customEdgeTypes,source:dl,target:ll,sourceProperty:Ae.sourceProperty,targetProperty:Ae.targetProperty,sourceY:re(Ae.source,Ae.sourceProperty),sourcePort:F(Ae.source,Ae.sourceProperty),targetPort:Ae.target?F(Ae.target,Ae.targetProperty):void 0,targetY:Ae.target?re(Ae.target,Ae.targetProperty):void 0,dir:Kn,turn:.5,color:g,labelBg:g})})]})}),h.jsx("div",{ref:q,className:"flow-sdk-nodes",children:t.map(P=>{var be,Oe;const L=ee.get(P.id),B=Fe.get(P.id),H=(L==null?void 0:L.x)??(B?(B.x1+B.x2)/2:0),ae=(L==null?void 0:L.y)??(B?(B.y1+B.y2)/2:0);return h.jsx(p_,{id:P.id,x:H,y:ae,placed:!!L||!!B,hidden:!Zn.shown.has(P.id)||!ht(P.id,r,i)||!!S&&!S.has(P.id),onMount:Pt,drawHandles:e.drawHandles&&!e.readOnly,drawMode:b,connectedPorts:new Set(T.flatMap(Le=>[...Le.source===P.id&&Le.sourceProperty!==void 0?[`source:${Le.sourceProperty}`]:[],...Le.target===P.id&&Le.targetProperty!==void 0?[`target:${Le.targetProperty}`]:[]])),hasCollapseControl:P.hasCollapseControl,handleColor:g,animated:P.animated&&!B&&!w,animationColor:P.animationColor,animationWidth:P.animationWidth,animationVariant:P.animationVariant,width:(be=W.current.get(P.id))==null?void 0:be.w,height:(Oe=W.current.get(P.id))==null?void 0:Oe.h,propertyMode:j,resolvedRows:lr.get(P.id),reversePorts:n==="RL",direction:n,onPropertyRows:N,onSurface:le,children:P.element},P.id)})}),Ge&&h.jsx("div",{className:"flow-sdk-box",style:{left:Ge.x1,top:Ge.y1,width:Ge.x2-Ge.x1,height:Ge.y2-Ge.y1}}),h.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:h.jsx("g",{ref:I,transform:`translate(${O.pan.x} ${O.pan.y}) scale(${O.zoom})`,children:h.jsx("g",{ref:Kb,className:"flow-sdk-labels",style:{pointerEvents:b?"none":"visiblePainted",outline:"none"}})})})]})}const __=E.memo(C_);function Nb({id:e,label:t,role:r,side:n,position:o=.5,placement:i,children:s,style:a}){return h.jsx("div",{"data-flow-property":e,"data-flow-port-role":r,"data-flow-port-side":n,"data-flow-port-position":n?o:void 0,"data-flow-port-placement":i,style:{minHeight:32,display:"flex",alignItems:"center",justifyContent:r==="source"?"flex-end":"flex-start",...a,...n?{display:"none"}:{}},children:s??t??e})}const S_=wn.default.dialog`
204
+ ${e=>Vr(e.$surface,e.$border)}
159
205
  &,
160
206
  &:hover {
161
207
  box-shadow: none !important;
@@ -179,7 +225,7 @@
179
225
  & *::-webkit-scrollbar {
180
226
  display: none;
181
227
  }
182
- `,S_=xn.default.div`
228
+ `,E_=wn.default.div`
183
229
  min-height: 0;
184
230
  container-type: inline-size;
185
231
  @container (min-width: 520px) {
@@ -224,5 +270,5 @@
224
270
  black calc(100% - 32px),
225
271
  transparent
226
272
  );
227
- `;function Nb({nodeAddress:e,active:t,label:r,open:n=!1,onClose:o,children:i,filter:s,height:a}){const{background:c,border:u,colorText:l}=Je(),{colorMode:d}=Ie(),f=S.useRef(null),p=S.useId(),{data:y,schema:g,bindings:b}=S.useContext(Rr),x=i!==void 0||!!(y&&g&&(b?rn(b,e,g):xt(y,e,g)));S.useEffect(()=>{var w,v,C,_,R;!t||!x||!n?(w=f.current)==null||w.close():(v=f.current)!=null&&v.open||((C=f.current)==null||C.showModal(),(R=(_=f.current)==null?void 0:_.querySelector("[data-form-filter] input"))==null||R.focus())},[t,x,n]);const m=he(c);return x?h.jsx(h.Fragment,{children:typeof document<"u"&&Wt.createPortal(h.jsx(__,{ref:f,id:p,$surface:m,$border:he(u),"aria-label":`Configure ${r}`,onClose:o,onPointerDown:w=>w.stopPropagation(),onWheel:w=>w.stopPropagation(),onKeyDown:w=>w.stopPropagation(),onClick:w=>{var v;w.stopPropagation(),w.target===w.currentTarget&&((v=f.current)==null||v.close())},style:{position:"fixed",inset:"94px 20px auto auto",margin:0,padding:20,width:"var(--top-toolbar-width, 360px)",boxSizing:"border-box",maxWidth:"calc(100vw - 40px)",maxHeight:"calc(100dvh - 114px)",height:a,overflow:"hidden",borderRadius:30,background:m,color:he(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:w=>w.stopPropagation(),children:h.jsx(vt,{type:"submit","aria-label":"Close node configuration"})})]}),s&&h.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:s}),h.jsx(S_,{$divider:`var(--chakra-colors-gray-${d==="dark"?"700":"200"})`,"data-form-scroll":"",style:a?{flex:1}:void 0,children:i??h.jsx(sm,{nodeAddress:e})})]})}),document.body)}):null}const Ru=({icon:e,label:t,onClick:r,color:n,boxSize:o=6,...i})=>{const{background:s,border:a,colorText:c}=Je();return h.jsx(Re,{label:t,children:h.jsx(D.Flex,{children:h.jsx(D.Icon,{as:e,boxSize:o,color:n,cursor:r?"pointer":void 0,onClick:r})})})},E_=({data:e,children:t,isInverted:r,isParent:n})=>{var q,L,z,H,X,le;const{selectedNodeIds:o,setSelectedNodeIds:i,selectedEdgeId:s,setSelectedEdgeId:a,isMultiSelectMode:c,isPerformanceMode:u,engineRef:l,callbacks:d,config:f,themeColor:p,direction:y}=Ie(),{background:g,border:b,colorText:x}=Je(),m=S.useRef(null),w=S.useRef(null),[v,C]=S.useState(!1),[_,R]=S.useState(!1),[T,A]=S.useState(!1),k=e==null?void 0:e.id,j=cm(k),E=o.includes(k),M=f.nodeOverlayActions,I=f.renderNodeOverlay,N=(()=>{var J;try{const V=(J=l.current)==null?void 0:J.zoom();return V!==void 0&&V<.08}catch{return!1}})(),O=S.useCallback(J=>{var Y,te,de,ue;if(_||f.readOnly)return;const V={shiftKey:J.shiftKey,ctrlKey:J.ctrlKey,metaKey:J.metaKey,altKey:J.altKey};if(s&&(a(null),(Y=d.onEdgeDeselect)==null||Y.call(d)),c){const Se=o.includes(k),ye=Se?o.filter(De=>De!==k):[...o,k];i(ye),Se?(te=d.onNodeDeselect)==null||te.call(d):(de=d.onNodeSelect)==null||de.call(d,k,e,V)}else i([k]),(ue=d.onNodeSelect)==null||ue.call(d,k,e,V)},[k,e,o,s,c,_,i,a,d,f]),W=S.useCallback(()=>{var J;_||f.readOnly||(J=d.onNodeDoubleClick)==null||J.call(d,k,e)},[k,e,_,d,f]),G=S.useCallback(()=>{w.current&&clearTimeout(w.current),w.current=setTimeout(()=>C(!0),100)},[]),ee=S.useCallback(()=>{w.current&&clearTimeout(w.current),C(!1)},[]),ne=!!((q=e==null?void 0:e.config)!=null&&q.form),ce={tabIndex:ne?0:void 0,"aria-haspopup":ne?"dialog":void 0,"aria-expanded":ne?T:void 0,onDoubleClickCapture:J=>{var V;!ne||f.readOnly||_||!J.currentTarget.contains(J.target)||J.target instanceof Element&&J.target.closest("button, input, textarea, select, a, [contenteditable=true]")||(J.preventDefault(),J.stopPropagation(),i([k]),A(!0),(V=d.onNodeDoubleClick)==null||V.call(d,k,e))},onKeyDown:J=>{!ne||f.readOnly||J.target!==J.currentTarget||J.key!=="Enter"||(J.preventDefault(),J.stopPropagation(),i([k]),A(!0))}},me=ne&&h.jsx(Nb,{nodeAddress:k,active:E,label:e.label||e.headerTitle||"Node",open:T,onClose:()=>{var J;A(!1),E&&((J=m.current)==null||J.focus({preventScroll:!0}))}}),K=Array.isArray((L=e==null?void 0:e.config)==null?void 0:L.ports)?e.config.ports.map(J=>h.jsx(qb,{...J},`${J.id}:${J.role}`)):null;return n?h.jsxs(D.Box,{ref:m,...ce,onClick:O,onDoubleClick:W,onMouseEnter:G,onMouseLeave:ee,cursor:"pointer",position:"relative",children:[me,!u&&(I||M&&M.length>0)&&v&&!N&&h.jsxs(h.Fragment,{children:[h.jsx(D.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>C(!0),onMouseLeave:ee}),I?h.jsx(D.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>C(!0),onMouseLeave:ee,willChange:"transform",children:I({nodeId:k,nodeData:e,isRoot:k==="root",isParent:!0,isHovered:v,setIsHovered:C})}):h.jsx(D.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:g,p:3,borderColor:b,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>C(!0),onMouseLeave:ee,willChange:"transform",children:h.jsx(D.HStack,{px:2,gap:2,children:M.map((J,V)=>h.jsxs(D.Box,{display:"contents",children:[V>0&&h.jsx(D.Box,{borderColor:b,height:5,borderRightWidth:1}),h.jsx(Ru,{icon:J.icon,label:J.label,color:x,bgColor:g,borderColor:b,textColor:x,boxSize:5,onClick:Y=>{var te;Y.stopPropagation(),(te=d.onNodeHoverAction)==null||te.call(d,J.id,k,e)}})]},J.id))})})]}),t({id:k,data:e,isActive:E,isLowZoom:N,isEditing:_,onEditStart:()=>R(!0),onEditEnd:()=>R(!1)}),j&&!((z=e==null?void 0:e.config)!=null&&z.parentContainer)&&((H=e==null?void 0:e.config)==null?void 0:H.collapsed)!==void 0&&(()=>{var Y;const J=y==="TB"||y==="BT",V=r||y==="RL";return h.jsx(D.IconButton,{position:"absolute",...J?{[y==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:V?void 0:"-75px",left:V?"-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,k,!e.config.collapsed)},bgColor:he(((Y=e==null?void 0:e.viewProps)==null?void 0:Y.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:he("gray.800")}):h.jsx(Z.PiMinusBold,{size:30,color:he("gray.800")})})})()]}):h.jsxs(D.Box,{ref:m,...ce,onClick:O,onDoubleClick:W,onMouseEnter:G,onMouseLeave:ee,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[me,K,!u&&(I||M&&M.length>0)&&v&&!N&&h.jsxs(h.Fragment,{children:[h.jsx(D.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>C(!0),onMouseLeave:ee}),I?h.jsx(D.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>C(!0),onMouseLeave:ee,willChange:"transform",children:I({nodeId:k,nodeData:e,isRoot:k==="root",isParent:!!n,isHovered:v,setIsHovered:C})}):h.jsx(D.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:g,p:3,borderColor:b,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>C(!0),onMouseLeave:ee,willChange:"transform",children:h.jsx(D.HStack,{px:2,gap:2,children:M.map((J,V)=>h.jsxs(D.Box,{display:"contents",children:[V>0&&h.jsx(D.Box,{borderColor:b,height:5,borderRightWidth:1}),h.jsx(Ru,{icon:J.icon,label:J.label,color:x,bgColor:g,borderColor:b,textColor:x,boxSize:5,onClick:Y=>{var te;Y.stopPropagation(),(te=d.onNodeHoverAction)==null||te.call(d,J.id,k,e)}})]},J.id))})})]}),h.jsxs(D.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[j&&!((X=e==null?void 0:e.config)!=null&&X.parentContainer)&&((le=e==null?void 0:e.config)==null?void 0:le.collapsed)!==void 0&&!n&&(()=>{var te,de,ue;const J=y==="TB"||y==="BT",V=r||y==="RL",Y=(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(D.IconButton,{position:"absolute",...J?{[y==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:V?void 0:Y===void 0?"-75px":`calc(50% - ${Y+75}px)`,left:V?Y===void 0?"-75px":`calc(50% - ${Y+75}px)`:void 0,alignSelf:Y===void 0?"center":void 0,top:Y===void 0?void 0:`${Y}px`,transform:Y===void 0?void 0:"translateY(-50%)",zIndex:Y===void 0?void 0:1},"aria-label":e.config.collapsed?"Expand":"Collapse",disabled:f.readOnly,onClick:Se=>{var ye;Se.stopPropagation(),(ye=d.onNodeCollapse)==null||ye.call(d,k,!e.config.collapsed)},bgColor:he(((ue=e==null?void 0:e.viewProps)==null?void 0:ue.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:he("gray.800")}):h.jsx(Z.PiMinusBold,{size:30,color:he("gray.800")})})})(),t({id:k,data:e,isActive:E,isLowZoom:N,isEditing:_,onEditStart:()=>R(!0),onEditEnd:()=>R(!1)})]})]})},Gn=S.memo(E_);function al(e=!0){const t=S.useRef(null);return S.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 Qt=({nodeId:e,label:t,color:r,fontWeight:n="bold",fontSize:o="5xl",wrap:i=!1,isEditing:s,onEditStart:a,onEditEnd:c})=>{const{callbacks:u,config:l,readOnly:d}=Ie(),f=l.editable&&!d,[p,y]=S.useState(t),[g,b]=S.useState(),x=S.useRef(null),m=S.useRef(!1),w=al(s);S.useEffect(()=>{s&&(m.current=!1,x.current&&(x.current.focus(),x.current.select()))},[s]);const v=()=>{var _;if(m.current)return;m.current=!0;const C=p.trim();C&&C!==t&&((_=u.onNodeLabelChange)==null||_.call(u,e,C)),c()};return!f||!s?h.jsx(D.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?C=>{C.stopPropagation(),b({width:C.currentTarget.offsetWidth,height:C.currentTarget.offsetHeight}),y(t),a()}:void 0,cursor:f?"text":void 0,children:t}):h.jsxs("div",{ref:w,style:{position:"relative",width:"max-content",minWidth:g==null?void 0:g.width,maxWidth:900,height:g==null?void 0:g.height},children:[h.jsx(D.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),h.jsx(D.Input,{ref:x,value:p,onChange:C=>y(C.target.value),onBlur:v,onKeyDown:C=>{C.key==="Enter"&&v(),C.key==="Escape"&&(m.current=!0,c())},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"})]})},j_=({id:e,data:t,isActive:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var g,b,x,m,w,v,C,_;const{themeColor:s}=Ie(),{colorText:a}=Je(),c=((g=t==null?void 0:t.viewProps)==null?void 0:g.bgColor)==="transparent",u=((b=t==null?void 0:t.viewProps)==null?void 0:b.outline)===!0,{bgColor:l,borderColor:d,textColor:f}=en(((x=t==null?void 0:t.viewProps)==null?void 0:x.bgColor)||s),p=he(((m=t==null?void 0:t.viewProps)==null?void 0:m.textColor)||(c||u?a:f)),y=((w=t==null?void 0:t.viewProps)==null?void 0:w.borderColor)||(u?!c&&((v=t==null?void 0:t.viewProps)==null?void 0:v.bgColor)||s:d);return h.jsx(D.Box,{"data-flow-node-surface":"",borderRadius:(C=t==null?void 0:t.viewProps)==null?void 0:C.borderRadius,bgColor:u?"transparent":l,...gn(t==null?void 0:t.viewProps,y,r,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:h.jsxs(D.Flex,{justifyContent:"start",alignItems:"center",gap:8,w:"fit-content",maxW:900,minW:0,fontSize:"5xl",lineHeight:"normal",children:[((_=t==null?void 0:t.config)==null?void 0:_.icon)&&h.jsx(D.Box,{flexShrink:0,children:h.jsx(Mr,{name:t.config.icon,size:80,color:p})}),h.jsx(Qt,{nodeId:e,label:(t==null?void 0:t.label)||(t==null?void 0:t.text)||"",color:p,isEditing:n,onEditStart:o,onEditEnd:i})]})})};function Un(){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 R_=({id:e,isActive:t,data:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var w,v,C,_,R,T,A,k,j,E,M,I,N,O,W;const{themeColor:s}=Ie(),{colorText:a}=Je(),c=((w=r==null?void 0:r.viewProps)==null?void 0:w.bgColor)==="transparent",u=((v=r==null?void 0:r.viewProps)==null?void 0:v.outline)===!0,l=!c&&((C=r==null?void 0:r.viewProps)==null?void 0:C.bgColor)||s,{borderColor:d,highlightColor:f,textColor:p}=en(l),y=he(((_=r==null?void 0:r.viewProps)==null?void 0:_.textColor)||(c||u?a:p)),g=c&&!u&&!((R=r==null?void 0:r.viewProps)!=null&&R.borderColor)?"transparent":he(((T=r==null?void 0:r.viewProps)==null?void 0:T.borderColor)||(u?l:d)),b=c||u?"transparent":l!=null&&l.startsWith("#")?l:he(f),x=(A=r==null?void 0:r.config)==null?void 0:A.icon,m=(r==null?void 0:r.label)??(r==null?void 0:r.text)??"";if((k=r==null?void 0:r.config)!=null&&k.labelBelow){const G=(((j=r==null?void 0:r.viewProps)==null?void 0:j.fontSize)||1)*100;return h.jsxs(D.Flex,{"data-flow-icon-label":"",direction:"column",align:"center",gap:"24px",width:`${Math.max(G+200,360)}px`,position:"relative",children:[h.jsx(D.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${G+100}px`,height:`${G+100}px`,flexShrink:0,borderRadius:(E=r==null?void 0:r.viewProps)==null?void 0:E.borderRadius,backgroundColor:b,...gn(r==null?void 0:r.viewProps,g,t,2),children:!!x&&h.jsx(Mr,{name:x,size:G,color:y})}),h.jsxs(D.Flex,{"data-flow-icon-caption":"",direction:"column",align:"center",gap:"8px",justify:"center",width:"100%",minW:0,textAlign:"center",children:[h.jsx(Qt,{nodeId:e,label:m,color:he(((M=r==null?void 0:r.viewProps)==null?void 0:M.textColor)||a),isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0}),typeof((I=r.config)==null?void 0:I.subtitle)=="string"&&r.config.subtitle!==""&&h.jsx(D.Text,{"data-flow-node-subtitle":"",color:he(((N=r==null?void 0:r.viewProps)==null?void 0:N.textColor)||a),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(D.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:(O=r==null?void 0:r.viewProps)==null?void 0:O.borderRadius,bgColor:b,style:{backgroundColor:b},textTransform:"capitalize",...gn(r==null?void 0:r.viewProps,g,t,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!x&&h.jsx(D.Flex,{align:"center",py:14,mr:m?8:0,flexShrink:0,children:h.jsx(Mr,{name:x,size:(((W=r==null?void 0:r.viewProps)==null?void 0:W.fontSize)||1)*100,color:y},y)}),(m||!x)&&h.jsx(D.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:h.jsx(Qt,{nodeId:e,label:m,color:y,isEditing:n,onEditStart:o,onEditEnd:i})})]})};function $b({onExpand:e,toggleLabel:t="Show properties",toggleDisabled:r=!1,renderCompact:n=R_,...o}){const{colorMode:i,callbacks:s}=Ie();return h.jsx(Gn,{...o,children:a=>h.jsxs(D.Box,{position:"relative",children:[h.jsx(n,{...a}),e&&a.isActive&&h.jsx(D.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:h.jsx(Re,{label:t,children:h.jsx(ve,{"aria-label":t,icon:h.jsx(D.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:i==="dark"?"gray.100":"gray.800",disabled:r,onClick:c=>{var u;c.stopPropagation(),e(),(u=s.onNodeViewToggle)==null||u.call(s,o.data.id)}})})})]})})}const hy=1.55;function k_({nodeId:e,content:t,color:r}){const{callbacks:n,config:o,readOnly:i}=Ie(),s=!!o.editable&&!i,[a,c]=S.useState(!1),[u,l]=S.useState(t),[d,f]=S.useState(),p=S.useRef(null),y=S.useRef(!1),g=al(a);S.useLayoutEffect(()=>{const m=p.current;!a||!m||(m.style.height="auto",m.style.height=`${Math.max((d==null?void 0:d.height)??0,m.scrollHeight)}px`)},[u,a,d]),S.useEffect(()=>{var m;s?a&&(y.current=!1,(m=p.current)==null||m.focus()):c(!1)},[a,s]);const b=m=>{s&&(f({width:m.offsetWidth,height:m.offsetHeight}),l(t),c(!0))},x=()=>{var m;y.current||!s||(y.current=!0,u!==t&&((m=n.onNodeContentChange)==null||m.call(n,e,u)),c(!1))};return!a||!s?h.jsx(D.Box,{"data-flow-content":"",color:r,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:hy,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:s?"text":void 0,tabIndex:s?0:void 0,onDoubleClick:m=>{m.stopPropagation(),b(m.currentTarget)},onKeyDown:m=>{s&&m.key==="Enter"&&m.target===m.currentTarget&&(m.preventDefault(),m.stopPropagation(),b(m.currentTarget))},children:h.jsx(sv.default,{options:{forceBlock:!0,wrapper:S.Fragment,disableParsingRawHTML:!0,overrides:{a:{props:{target:"_blank",rel:"noopener noreferrer"}},img:{props:{loading:"lazy",referrerPolicy:"no-referrer"}}}},children:t})}):h.jsx("div",{ref:g,style:{width:d==null?void 0:d.width,minHeight:d==null?void 0:d.height,maxWidth:"100%"},children:h.jsx(D.Textarea,{ref:p,"aria-label":"Node content",value:u,onChange:m=>l(m.target.value),onBlur:x,onKeyDown:m=>{m.stopPropagation(),!m.nativeEvent.isComposing&&(m.key==="Enter"&&(m.ctrlKey||m.metaKey)&&(m.preventDefault(),x()),m.key==="Escape"&&(y.current=!0,c(!1)))},color:r,fontFamily:"inherit",fontSize:"inherit",lineHeight:hy,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 P_=(e,t,r)=>{var f,p,y,g;const n=((f=e==null?void 0:e.viewProps)==null?void 0:f.bgColor)||t,[o]=n.split("."),i=en(n),s=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,a=n==="transparent"||s,c=r==="dark"?"gray.200":"gray.900",u=a?"transparent":n!=null&&n.startsWith("#")?he(n):he(i.bgColor),l=he(((y=e==null?void 0:e.viewProps)==null?void 0:y.textColor)||(a?c:i.textColor)),d=he(((g=e==null?void 0:e.viewProps)==null?void 0:g.borderColor)||(s?n==="transparent"?t:n:i.borderColor));return{...i,bgColor:a?"transparent":i.bgColor,highlightColor:a?"transparent":i.highlightColor,isTransparent:a,propertyColor:a?c:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:u,hextextColor:l,hexborderColor:d}},A_=(e,t=350)=>`${String(e).substring(0,t)}${String(e).length>t?"...":""}`,T_=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,Lb=600,O_=3,I_=e=>{const t=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(t*28+30,200)};function M_({headerTitle:e,hasContent:t,data:r,icon:n,colors:o,hasConfig:i,id:s,isActive:a,isEditing:c,onEditStart:u,onEditEnd:l,props:d,objVisible:f,setObjVisible:p,onShowNativeIcon:y}){var m,w;const{callbacks:g}=Ie(),b=d.onShowIcon??y,x=b?"Show icon":f?"Show content":"Show properties";return h.jsx(h.Fragment,{children:(e||t||((m=r.config)==null?void 0:m.form)||a&&y)&&h.jsxs(D.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(D.Flex,{mr:6,alignItems:"center",flexShrink:0,children:h.jsx(Mr,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),h.jsx(Qt,{nodeId:s,label:T_(e),color:((w=r==null?void 0:r.viewProps)==null?void 0:w.textColor)||o.propertyColor,isEditing:c,onEditStart:u,onEditEnd:l}),a&&(t||b)&&h.jsx(D.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:h.jsx(Re,{label:x,children:h.jsx(ve,{"aria-label":x,icon:h.jsx(D.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:v=>{var C;v.stopPropagation(),b?b():p(!f),(C=g.onNodeViewToggle)==null||C.call(g,s)}})})})]})})}function q_({data:e,resourcePorts:t,inspecting:r,form:n,inspectionPorts:o,extraPorts:i,colors:s,direction:a,uniformKeyWidth:c}){const{edgeById:u}=Ur(),l=new Set;for(const{data:d}of u.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(D.Box,{children:Object.entries(e.description||{}).map(([d,f],p)=>{var M,I,N;const y=t&&Object.keys(t).find(O=>O.slice(O.indexOf(":")+1)===d),g=r&&((M=n==null?void 0:n.type.ports)==null?void 0:M[d]),b=y??(g?`${g.kind}:${d}`:d),x=o.find(O=>O.id===b),m=y?"source":x==null?void 0:x.role,w=l.has(`source:${b}`),v=l.has(`target:${b}`),C=i.some(O=>O.id===d),_=f===""&&(C||(m?l.has(`${m}:${b}`):w||v)),R=m??(w!==v?w?"source":"target":void 0),T=(x==null?void 0:x.side)??(R?R==="source"!=(a==="RL")?"right":"left":void 0),A=_&&T==="right"?"right":"left",k=(x==null?void 0:x.label)??(g==null?void 0:g.label)??(C?d.replace(/^(template|input|output|config|error):/,""):d),j=Er(s.wordBeforeDot)[typeof f],E=Er(s.wordBeforeDot).property;return h.jsxs(D.Box,{"data-flow-property":y&&(a==="TB"||a==="BT")?void 0:b,"data-flow-port-role":m,"data-flow-inspection-row":r?"":void 0,children:[h.jsxs(D.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[h.jsx(D.Flex,{justifyContent:"start",align:"center",background:s.highlightColor,width:_?"100%":`${c}px`,minWidth:`${c}px`,borderRightColor:s.hexborderColor,borderRightWidth:_?0:1,children:h.jsx(D.Text,{py:5,px:10,w:"100%",textAlign:A,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((I=e==null?void 0:e.viewProps)==null?void 0:I.textColor)||(s.isTransparent?s.hextextColor:E),children:k})}),!_&&h.jsx(D.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:s.hexbgColor,w:Lb,maxH:200,children:h.jsx(D.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:((N=e==null?void 0:e.viewProps)==null?void 0:N.textColor)||(s.isTransparent?s.hextextColor:j),fontWeight:400,children:A_(f)})})]}),p!==Object.entries(e.description||{}).length-1&&h.jsx(D.Box,{borderTopWidth:1,my:0,borderColor:s.hexborderColor})]},d)})})}function N_(e){var w,v,C;const{themeColor:t,colorMode:r,direction:n}=Ie(),o=Un(),i=o.getNodeViewMode(e.data.id)==="properties",s=_=>o.setNodeViewMode(e.data.id,_?"properties":"default"),a=!!e.onShowIcon||i||typeof((w=e.data.config)==null?void 0:w.content)!="string",{bindings:c,data:u,schema:l}=S.useContext(Rr),d=(v=c==null?void 0:c[e.data.id])==null?void 0:v.portResources,f=c?rn(c,e.data.id,l):u&&l?xt(u,e.data.id,l):void 0,p=f&&we(u,"address"in f?f.address:e.data.id),y=p&&typeof p=="object"&&f?Object.fromEntries(Object.keys(f.type.properties).filter(_=>{var R;return Object.prototype.hasOwnProperty.call(p,_)&&Sn((R=f.fields[_])==null?void 0:R.$visibleWhen,u)}).map(_=>[_,p[_]!==null&&typeof p[_]=="object"?JSON.stringify(p[_],null,2):p[_]===null?"null":p[_]])):{},g=d?Object.fromEntries(Object.entries(d).map(([_,R])=>{var T;return[_.slice(_.indexOf(":")+1),((T=we(u,R))==null?void 0:T.name)??R.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:y,b=a&&!d?((C=e.data.config)==null?void 0:C.ports)??[]:[],x=b.filter(_=>!Object.prototype.hasOwnProperty.call(g,_.id)&&!Object.entries((f==null?void 0:f.type.ports)??{}).some(([R,T])=>`${T.kind}:${R}`===_.id&&Object.prototype.hasOwnProperty.call(g,R))),m={...g,...Object.fromEntries(x.map(_=>[_.id,""]))};return{themeColor:t,colorMode:r,direction:n,objVisible:i,setObjVisible:s,inspecting:a,resourcePorts:d,form:f,description:m,inspectionPorts:b,extraPorts:x}}const sl=e=>{var b,x,m;const{themeColor:t,colorMode:r,direction:n,objVisible:o,setObjVisible:i,inspecting:s,resourcePorts:a,form:c,description:u,inspectionPorts:l,extraPorts:d}=N_(e),f=Un(),p=f.getNodeViewMode(e.data.id)==="icon-label",g=!e.onShowIcon&&!((b=e.data.config)!=null&&b.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($b,{...e,data:{...e.data,label:e.data.label??e.data.headerTitle,config:{...e.data.config,labelBelow:!0,icon:((m=e.data.config)==null?void 0:m.icon)||"PiBracketsCurly"}},onExpand:()=>f.restoreNodeView(e.data.id)}):h.jsx(Gn,{...e,data:{...e.data,description:u},children:({id:w,data:v,isActive:C,isEditing:_,onEditStart:R,onEditEnd:T})=>{var G,ee,ne,ce,me,K;const A=P_(v,t,r),k=v.label??v.headerTitle,j=Object.entries(v.description||{}).length>0,E=I_(v.description),M=(ee=(G=e.data)==null?void 0:G.config)==null?void 0:ee.icon,I=(ce=(ne=e.data)==null?void 0:ne.config)==null?void 0:ce.content,N=typeof I=="string"&&!e.onShowIcon,O=((me=v==null?void 0:v.viewProps)==null?void 0:me.borderRadius)??"53px",W=gn(v==null?void 0:v.viewProps,A.hexborderColor,C,O_);return h.jsx(D.Flex,{justifyContent:"space-between",...v==null?void 0:v.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:O,overflow:"hidden",alignItems:"center",style:{backgroundColor:A.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:"100%",minW:N||e.onShowIcon?E+Lb+W.borderWidth*2:void 0,...W,children:h.jsxs(D.Flex,{width:"100%",direction:"column",borderRadius:O,borderColor:A.hexborderColor,borderWidth:0,overflow:"hidden",children:[h.jsx(M_,{headerTitle:k,hasContent:N,data:v,icon:M,colors:A,hasConfig:j,id:w,isActive:C,isEditing:_,onEditStart:R,onEditEnd:T,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:g}),N&&!o?h.jsx(D.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:A.highlightColor,p:12,fontSize:"5xl",lineHeight:"normal",children:h.jsx(k_,{nodeId:w,content:I,color:((K=v==null?void 0:v.viewProps)==null?void 0:K.textColor)||A.hextextColor})}):h.jsx(q_,{data:v,resourcePorts:a,inspecting:s,form:c,inspectionPorts:l,extraPorts:d,colors:A,direction:n,uniformKeyWidth:E})]})})}})};sl.displayName="NodeJsonObjectView";const Fb=e=>{var u,l,d,f,p,y,g;const t=Un(),r=t.getNodeViewMode(e.data.id)==="properties",n=b=>t.setNodeViewMode(e.data.id,b?"properties":"default"),{callbacks:o,readOnly:i}=Ie(),s=(l=(u=e.data)==null?void 0:u.config)==null?void 0:l.parentContainer,a=s?"Show parent":"Show properties",c=s||((f=(d=e.data)==null?void 0:d.config)==null?void 0:f.form)||((g=(y=(p=e.data)==null?void 0:p.config)==null?void 0:y.ports)==null?void 0:g.length);return!s&&c&&r?h.jsx(sl,{...e,onShowIcon:()=>n(!1)}):h.jsx($b,{...e,toggleLabel:a,toggleDisabled:s&&i,onExpand:c?()=>{var b;s?(b=o.onNodeCollapse)==null||b.call(o,e.data.id,!1):n(!0)}:void 0})},Bb=e=>h.jsx(Fb,{...e,renderCompact:j_}),Db=e=>h.jsx(Fb,{...e}),zb=e=>h.jsx(Gn,{...e,children:()=>null});Bb.displayName="text";Db.displayName="arrayView";zb.displayName="ParentContainerView";const $_={objectView:sl,arrayView:Db,text:Bb,parentContainer:zb},L_=({children:e,pattern:t="dot",backgroundColor:r})=>{const{colorMode:n}=Ie(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",s=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return t==="none"?h.jsx(D.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:r,children:e}):h.jsxs(D.Box,{"data-flow-background":t,position:"relative",width:"100%",height:"100%",padding:0,bg:r,children:[h.jsx(D.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(${s}) 0, var(${s}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${s}) 1px, transparent 1px), linear-gradient(90deg, var(${s}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),h.jsx(D.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},F_=.4,Yr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},B_=({nodes:e,edges:t})=>{const{themeColor:r,spacing:n,edgeRadius:o,backgroundVariant:i,setBackgroundSelected:s,edgeColor:a,direction:c,nodeAlignment:u,edgeMode:l,compactPropertyLayout:d,workflowContract:f,parentNodeStyle:p,engineRef:y,callbacks:g,config:b,selectedNodeIds:x,setSelectedNodeIds:m,selectedEdgeId:w,setSelectedEdgeId:v,setIsPerformanceMode:C,isZoomMode:_,setIsZoomMode:R,isMultiSelectMode:T,setIsMultiSelectMode:A,isDragMode:k,setIsDragMode:j,isEdgeHandlesEnabled:E,setIsEdgeHandlesEnabled:M,isArrayNodeMode:I}=Ie(),N=S.useRef(null),[O,W]=S.useState(null),G=e.length>200;S.useEffect(()=>{C(G)},[G,C]);const{edgeSep:ee,rankSep:ne,spacingFactor:ce}=S.useMemo(()=>{const Q=C0(e.length),F=n<1?.3+.7*n:.5+.5*n;return{edgeSep:Q.edgeSep*F,rankSep:Q.rankSep*F,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n]),{bgColor:me}=en(r),{canvas:K,borderSecondary:q,colorText:L}=Je(),z=i==="transparent"?"transparent":b.backgroundColor||K,H=S.useCallback(Q=>{if(!Q)return he(r);switch(Q){case"dark":return he(z);case"light":return he(q);default:return he(Q)}},[r,z,q]),X=b.colorMode==="dark",le=he("gray.500"),J=X?me!=null&&me.includes("gray")?"whitesmoke":H(me):H("light"),V=a?H(a):le,Y=S.useMemo(()=>b.initialViewport||{pan:{x:0,y:0},zoom:.01},[]),te=c==="C"?"LR":c,de=S.useCallback(Q=>{const F={...p,...Q};return{...F,bgColor:F.bgColor||r,bgOpacity:F.outline?0:F.bgOpacity??F_}},[p,r]),ue=S.useMemo(()=>{var F;const Q=new Map;for(const re of e)(F=re.data)!=null&&F.id&&Q.set(re.data.id,re);return Q},[e]),Se=S.useMemo(()=>{var F;const Q=new Map;for(const re of t)(F=re.data)!=null&&F.id&&Q.set(re.data.id,re);return Q},[t]),ye=S.useCallback(Q=>{var Ee;const F=(Ee=ue.get(Q))==null?void 0:Ee.data,re=de(F==null?void 0:F.viewProps),Ce=he(re.bgColor);return{animated:!!(F!=null&&F.isNodeAnimated)&&!G,animationVariant:F==null?void 0:F.nodeAnimationVariant,animationColor:he(re.borderColor||r),bgColor:re.outline?"transparent":Ce,bgOpacity:re.bgOpacity,borderColor:re.borderColor?he(re.borderColor):re.outline&&re.bgColor==="transparent"?he(r):Ce,borderWidth:Xt(re.borderWidth,Yr.borderWidth),borderStyle:re.borderStyle??Yr.borderStyle,borderRadius:re.borderRadius??Yr.borderRadius,textColor:re.textColor?he(re.textColor):re.outline||re.bgColor==="transparent"?he(L):Ce,fontSize:re.fontSize??Yr.fontSize,labelPosition:re.labelPosition??Yr.labelPosition,labelMargin:Yr.labelMargin,labelBg:fl(H("dark"),Ce,re.bgOpacity)??H("dark"),padding:re.padding??Yr.padding}},[de,ue,L,r,G,H]),De=S.useMemo(()=>{var re,Ce;const Q=new Map;for(const Ee of t){const _e=(re=Ee.data)==null?void 0:re.source,Ae=(Ce=Ee.data)==null?void 0:Ce.target;if(!_e||!Ae||_e===Ae)continue;const Ne=_e<Ae?`${_e}|${Ae}`:`${Ae}|${_e}`,Ge=Q.get(Ne);Ge?Ge.push({id:Ee.data.id,source:_e}):Q.set(Ne,[{id:Ee.data.id,source:_e}])}const F=new Map;for(const[Ee,_e]of Q){if(_e.length<2)continue;const Ae=Ee.split("|")[0],Ne=Math.min(20,70/_e.length);_e.forEach(({id:Ge,source:Be},Sr)=>{const je=50+(Sr-(_e.length-1)/2)*Ne;F.set(Ge,(Be===Ae?je:100-je)/100)})}return F},[t]),Le=S.useMemo(()=>{const Q=H("dark");return t.filter(F=>{var re;return((re=F.data)==null?void 0:re.id)&&F.data.source&&F.data.target}).map(({data:F})=>{var _e,Ae,Ne,Ge,Be,Sr;let re=Q;const Ce=(Ae=(_e=ue.get(F.source))==null?void 0:_e.data)==null?void 0:Ae.parent,Ee=(Ge=(Ne=ue.get(F.target))==null?void 0:Ne.data)==null?void 0:Ge.parent;if(Ce&&Ce===Ee){const je=de((Sr=(Be=ue.get(Ce))==null?void 0:Be.data)==null?void 0:Sr.viewProps),gr=fl(Q,he(je.bgColor),je.bgOpacity);gr&&(re=gr)}return{id:F.id,data:F,type:F.type??b.edgeType??"rounded-orthogonal",source:F.source,target:F.target,sourceProperty:F.sourceProperty,targetProperty:F.targetProperty,label:F.label,validationIssue:(l==="auto"||l==="properties")&&(F.sourceProperty!==void 0||F.targetProperty!==void 0)&&f?Lu(f,F):void 0,color:a?V:F.color?he(F.color):V,connectorColor:a?V:F.color?he(F.color):J,labelBg:re,dashed:!!F.isEdgeDashed,animated:!!F.isEdgeAnimated,inverted:!!F.isInverted,turn:De.get(F.id)??.5}})},[t,V,J,a,De,b.edgeType,l,f,ue,de,H]),He=S.useMemo(()=>{var F;const Q=new Set;for(const re of e)(F=re.data)!=null&&F.parent&&Q.add(re.data.parent);return Q},[e]),ze=S.useMemo(()=>{var F;const Q=new Map;for(const re of t)(F=re.data)!=null&&F.source&&!Q.has(re.data.source)&&Q.set(re.data.source,re.data);return Q},[t]),Ve=S.useMemo(()=>{const Q={...$_,...b.customViews};return e.filter(F=>{var re;return(re=F.data)==null?void 0:re.id}).map(F=>{var Ae,Ne,Ge,Be;const re=He.has(F.data.id)&&!F.data.parent,Ce=re?F.data.label??F.data.headerTitle??"Container":void 0,Ee=re?Q.parentContainer:Q[F.data.type]||Q.text,_e=ze.get(F.data.id);return{id:F.data.id,collapsed:(Ae=F.data.config)==null?void 0:Ae.collapsed,parent:F.data.parent,label:Ce,animated:!!F.data.isNodeAnimated,animationVariant:F.data.nodeAnimationVariant,hasCollapseControl:((Ne=F.data.config)==null?void 0:Ne.collapsed)!==void 0,animationColor:he(((Ge=F.data.viewProps)==null?void 0:Ge.borderColor)||r),animationWidth:Xt((Be=F.data.viewProps)==null?void 0:Be.borderWidth,8),element:S.createElement(Ee,{...F,isInverted:_e==null?void 0:_e.isInverted,isParent:re,key:`${F.data.id}-${r}`})}})},[e,He,ze,r,b.customViews]),Fe=S.useMemo(()=>G?300:e.length>50?150:e.length>20?100:50,[e.length,G]),Ye=S.useRef(b);Ye.current=b;const ir=S.useRef(_);ir.current=_;const be=S.useRef(I);be.current=I;const Pe=S.useRef(x);Pe.current=x;const We=S.useRef(w);We.current=w;const pr=S.useRef(T);pr.current=T;const er=S.useRef(ue);er.current=ue;const Qe=S.useRef(Se);Qe.current=Se;const lr=S.useRef(new Map);S.useEffect(()=>{var re,Ce;const Q=new Map([...Se].filter(([,Ee])=>ue.has(Ee.data.source)&&ue.has(Ee.data.target))),F=lr.current;lr.current=Q;for(const[Ee,_e]of F)Q.has(Ee)||(We.current===Ee&&(v(null),(re=g.onEdgeDeselect)==null||re.call(g)),(Ce=g.onEdgeRemove)==null||Ce.call(g,Ee,_e.data))},[Se,ue,g,v]),S.useEffect(()=>{const Q=N.current;if(!O||!Q)return;let F=null,re=null,Ce=0,Ee=0,_e=0,Ae=0,Ne=0;const Ge=Be=>{if(Ye.current.readOnly)return;Be.preventDefault(),Be.stopPropagation(),ir.current||Be.metaKey||Be.ctrlKey?(_e+=Be.deltaY,Ae=Be.clientX,Ne=Be.clientY,re===null&&(re=requestAnimationFrame(()=>{re=null;const je=Ye.current,gr=O.zoom(),$r=_e;_e=0;let Pr=gr-$r*.05/100;Pr=Math.max(je.minZoom??.01,Math.min(je.maxZoom??1.5,Pr));const Lr=Q.getBoundingClientRect();O.zoomAt(Pr,{x:Ae-Lr.left,y:Ne-Lr.top})}))):(Ce+=Be.deltaX,Ee+=Be.deltaY,F===null&&(F=requestAnimationFrame(()=>{F=null;const je=O.pan(),gr=O.zoom(),$r=.35,Pr=Ce,Lr=Ee;Ce=0,Ee=0,O.pan({x:je.x+-Pr*$r/gr,y:je.y+-Lr*$r/gr})})))};return Q.addEventListener("wheel",Ge,{passive:!1}),()=>{Q.removeEventListener("wheel",Ge),F!==null&&cancelAnimationFrame(F),re!==null&&cancelAnimationFrame(re)}},[O]),S.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const Q=F=>{var Ce,Ee,_e,Ae;if(Ye.current.readOnly)return;const re=F.target;if(!(re.tagName==="INPUT"||re.tagName==="TEXTAREA"||re.isContentEditable)){if((F.key==="z"||F.key==="Z")&&R(!ir.current),(F.key==="m"||F.key==="M")&&A(!T),(F.key==="d"||F.key==="D")&&j(!k),(F.key==="v"||F.key==="V")&&!F.repeat&&!F.metaKey&&!F.ctrlKey&&!F.altKey&&re.tagName!=="SELECT"&&M(!E),(F.key==="Delete"||F.key==="Backspace")&&We.current){F.preventDefault();const Ne=We.current;(Ee=g.onEdgeDelete)==null||Ee.call(g,Ne,((Ce=Qe.current.get(Ne))==null?void 0:Ce.data)??{id:Ne}),v(null);return}if((F.key==="Delete"||F.key==="Backspace")&&Pe.current.length>0){F.preventDefault();const Ne=Pe.current.filter(Ge=>Ge!=="root");if(Ne.length===0)return;for(const Ge of Ne){const Be=(_e=er.current.get(Ge))==null?void 0:_e.data;(Ae=g.onNodeDelete)==null||Ae.call(g,Ge,Be||{})}m([])}}};return window.addEventListener("keydown",Q),()=>window.removeEventListener("keydown",Q)},[T,k,E,M,R,A,j,b.disableKeyboardShortcuts,g,m,v]);const ar=S.useCallback(Q=>{var F;y.current=Q,W(Q),(F=g.onInit)==null||F.call(g,Q)},[y,g]),xe=S.useCallback(Q=>{var F;return(F=g.onViewportChange)==null?void 0:F.call(g,Q)},[g]),ct=S.useCallback(Q=>{var re,Ce,Ee;const F=((re=Qe.current.get(Q))==null?void 0:re.data)??{id:Q};if(We.current===Q&&pr.current){v(null),(Ce=g.onEdgeDeselect)==null||Ce.call(g);return}Pe.current.length&&m([]),v(Q),(Ee=g.onEdgeSelect)==null||Ee.call(g,Q,F)},[g,v,m]),dr=S.useCallback(()=>{var Q,F,re;s(!0),(Q=g.onBackgroundClick)==null||Q.call(g),Pe.current.length&&(m([]),(F=g.onNodeDeselect)==null||F.call(g)),We.current&&(v(null),(re=g.onEdgeDeselect)==null||re.call(g))},[g,m,v,s]),jt=S.useCallback(Q=>{var Ce,Ee;const F=Pe.current,re=Q.filter(_e=>!F.includes(_e));if(re.length){m([...F,...re]);for(const _e of re)(Ee=g.onNodeSelect)==null||Ee.call(g,_e,((Ce=er.current.get(_e))==null?void 0:Ce.data)??{id:_e})}},[g,m]),ie=S.useCallback((Q,F)=>{var re,Ce;m([Q]),(Ce=g.onNodeSelect)==null||Ce.call(g,Q,((re=er.current.get(Q))==null?void 0:re.data)??{id:Q},F)},[g,m]),Me=S.useCallback((Q,F,re)=>{var Ce;return(Ce=g.onEdgeCreate)==null?void 0:Ce.call(g,Q,F,re)},[g]),Ke=S.useCallback((Q,F,re,Ce=!1)=>{var Ee,_e;l==="properties"&&((Ee=g.onNodeCreateRequest)==null?void 0:Ee.call(g,{sourceNodeId:Q,position:F,sourceProperty:re,reverse:Ce}))===!0||re!==void 0||Ce||(_e=g.onNodeCreate)==null||_e.call(g,{type:"text",sourceNodeId:Q,position:F,isArrayMode:be.current})},[g,l]),qe=!b.readOnly&&E&&b.edgeHandles!==!1,cr=i==="transparent"?"none":i;return h.jsx(L_,{pattern:cr,backgroundColor:z,children:h.jsx(D.Box,{ref:N,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:h.jsx(C_,{nodes:Ve,edges:Le,direction:te,nodeAlignment:u,onContainerCollapse:Q=>{var F,re;(F=g.onNodeCollapse)==null||F.call(g,Q,!0),(re=g.onNodeViewToggle)==null||re.call(g,Q)},selectedNodeIds:x,edgeMode:l,compactPropertyLayout:d,edgeType:b.edgeType,edgeRadius:o,customEdgeTypes:b.customEdgeTypes,edgeReveal:b.edgeReveal,rankSep:ne,edgeSep:ee,spacingFactor:ce,compactSpacingScale:n,layoutDebounce:Fe,isPerformanceMode:G,minZoom:b.minZoom??.01,maxZoom:b.maxZoom??1.5,initialViewport:Y,fitOnInit:!b.initialViewport,readOnly:!!b.readOnly,containerStyle:ye,lineColor:a?V:J,drawMode:qe,drawHandles:!b.readOnly&&b.edgeHandles!==!1,dragMode:k,multiSelect:!!T,onInit:ar,onLayoutComplete:g.onLayoutComplete,animateViewport:b.animateViewport,onViewportChange:xe,onBackgroundTap:dr,onBoxSelect:jt,onEdgeSelect:ct,onContainerSelect:ie,onEdgeDraw:Me,onDrawIntoSpace:Ke})})})},Vb=S.memo(B_),D_=".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 py=!1;function z_(){if(py||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=D_+w0+m0+v0+".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}',py=!0}function V_({loading:e=!1,loader:t,...r}){var c,u;const[n,o]=S.useState(null),i=S.useMemo(()=>!!(n!=null&&n.json)&&!!r.json&&p0(n.json,r.json),[n==null?void 0:n.json,r.json]),s=n===null||n.json!==r.json&&!i,a=e||s;return S.useEffect(()=>{!e&&i&&(n==null?void 0:n.json)!==r.json&&o(r)},[e,i,n==null?void 0:n.json,r.json]),S.useEffect(()=>{if(e||!s)return;let l;const d=requestAnimationFrame(()=>{l=requestAnimationFrame(()=>o(r))});return()=>{cancelAnimationFrame(d),l!==void 0&&cancelAnimationFrame(l)}},[e,s,r.json]),h.jsxs(D.Box,{className:r.className,style:r.style,width:"100%",height:"100%",position:"relative","aria-busy":a,children:[h.jsx("div",{style:{width:"100%",height:"100%"},ref:l=>{a?l==null||l.setAttribute("inert",""):l==null||l.removeAttribute("inert")},children:n&&h.jsx(W_,{...s?n:r,className:void 0,style:void 0})}),a&&t!==null&&h.jsx(D.Box,{"data-flow-loader":"",role:"status","aria-label":"Loading diagram",position:"absolute",inset:0,zIndex:1e3,display:"grid",placeItems:"center",background:((c=r.config)==null?void 0:c.colorMode)==="dark"?"gray.800":"gray.100",color:((u=r.config)==null?void 0:u.colorMode)==="dark"?"whiteAlpha.800":"blackAlpha.800",children:t===void 0?h.jsx("span",{children:"Loading diagram..."}):t})]})}function W_({title:e="untitled",json:t,forms:r,nodes:n,edges:o,config:i={},callbacks:s={},className:a,style:c,showBottomBar:u=!0,children:l}){z_();const[d,f]=S.useState(),[p,y]=S.useState(!1),g=i.formSchema??d,b=S.useMemo(()=>t&&r?im(t,r.state):t,[t,r==null?void 0:r.state]),x=i.direction==="C",m=S.useMemo(()=>{let j,E;return M=>(E=j&&E?g0(j,M,E)??_u(M,{title:e,isCenter:x}):_u(M,{title:e,isCenter:x}),j=M,E)},[e,x]),w=S.useMemo(()=>b?m(b):null,[b,m]),v=S.useMemo(()=>r!=null&&r.structured&&!p&&g?c0(r.state,r.bindings,g,(w==null?void 0:w.nodes)??n??[]):void 0,[r==null?void 0:r.structured,p,r==null?void 0:r.state,r==null?void 0:r.bindings,g,w,n]),C=(v==null?void 0:v.schema)??g,_=(v==null?void 0:v.bindings)??(r==null?void 0:r.bindings),R=S.useMemo(()=>[...(w==null?void 0:w.nodes)??n??[],...(v==null?void 0:v.nodes)??[]].map(E=>{var ee,ne,ce,me;const M=t?(ee=we(t,E.data.id))==null?void 0:ee.$view:(ne=E.data.config)==null?void 0:ne.typeView,I=M&&Gt.includes(M)?M:void 0,N=I?I==="icon-label":(ce=E.data.config)==null?void 0:ce.labelBelow,O=I==="object"?"objectView":I==="text"?"text":N?"arrayView":E.data.type,W=C&&(r?rn(_,E.data.id,C):t&&xt(t,E.data.id,C)),G=(((me=E.data.config)==null?void 0:me.ports)??[]).map(K=>({...K}));if(v&&W){const K=i.direction==="RL"?{input:"right",output:"left",config:"bottom",error:"top"}:i.direction==="TB"?{input:"top",output:"bottom",config:"right",error:"left"}:i.direction==="BT"?{input:"bottom",output:"top",config:"left",error:"right"}:{input:"left",output:"right",config:"top",error:"bottom"};for(const[q,L]of Object.entries(W.type.ports??{})){const z=`${L.kind}:${q}`,H=G.find(X=>X.id===z);H?H.label===void 0&&L.label!==void 0&&(H.label=L.label):G.push({id:z,...L.label!==void 0?{label:L.label}:{},role:L.kind==="input"||L.kind==="config"?"target":"source",side:K[L.kind],...L.kind==="config"?{placement:"config"}:{}})}for(const q of G){const L=G.filter(z=>z.side===q.side);q.position=(L.indexOf(q)+1)/(L.length+1)}}return W||N||I?{...E,data:{...E.data,type:O,...r?{description:Object.fromEntries(Object.entries(E.data.description??{}).filter(([K])=>!K.startsWith("$")&&!(v!=null&&v.slots.has(Tt(E.data.id,K)))))}:{},config:{...E.data.config,...v&&W?{ports:G}:{},...W?{form:!0}:{},...I?{typeView:I,labelBelow:!!N}:N?{labelBelow:!0}:{}}}}:E}),[w,n,t,C,_,v,i.direction]),T=[...(w==null?void 0:w.edges)??o??[],...(v==null?void 0:v.edges)??[]],A=S.useMemo(()=>{const j=t&&w?Em(t,w.edges,s,s.onJsonChange,g):{...s};if(v){const E=new Set([...v.nodes.map(M=>M.data.id),...v.edges.map(M=>M.data.id)]);for(const M of Object.keys(j)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(M))continue;const I=j[M];j[M]=(N,...O)=>{if(!E.has(N))return I==null?void 0:I(N,...O)}}}return{...j,onAllNodesIconLabelChange:E=>{var M;y(E),(M=j.onAllNodesIconLabelChange)==null||M.call(j,E)}}},[t,w,s,g,v]),k=S.useMemo(()=>{if(!r)return A;let j=r.state;const E=I=>{if(i.readOnly||i.editable===!1)return;const N=r.onStateChange??r.onChange;if(!N)return;const O=r0(j,I,s.onFormChange);O!==j&&(j=O,N(O,{...I,data:O}))},M=(I,N,O)=>{var G;const W=t&&((G=we(t,I))==null?void 0:G[N]);return!W||typeof W.$state!="string"?!1:(E({address:W.$state,nodeAddress:I,previousValue:we(j,W.$state),value:O,data:j}),!0)};return{...A,onFormChange:E,onNodeCreateRequest:I=>{var W,G;const N=(W=I.sourceProperty)!=null&&W.startsWith("config:")?I.sourceProperty.slice(7):void 0,O=N!==void 0&&(v==null?void 0:v.slots.get(Tt(I.sourceNodeId,N)));return O?(O.present||E({data:j,nodeAddress:O.address.split(".").slice(0,-1).join("."),address:O.address,value:Ot(O.type),previousValue:void 0}),!0):((G=A.onNodeCreateRequest)==null?void 0:G.call(A,I))??!1},onNodeDelete:(I,N)=>{var ce,me;if(!(v!=null&&v.nodes.some(K=>K.data.id===I)))return(ce=A.onNodeDelete)==null?void 0:ce.call(A,I,N);const O=v&&[...v.slots.values()].find(K=>K.nodeId===I);if(!O)return(me=A.onNodeDelete)==null?void 0:me.call(A,I,N);const W=O.address.split("."),G=W.pop(),ee=W.join("."),ne=we(j,ee);E(Array.isArray(ne)?{data:j,nodeAddress:ee,address:ee,previousValue:ne,value:ne.filter((K,q)=>String(q)!==G)}:{data:j,nodeAddress:ee,address:O.address,previousValue:we(j,O.address),value:void 0})},onEdgeCreate:(I,N,O)=>{var ee,ne;const W=((ee=O==null?void 0:O.targetProperty)==null?void 0:ee.startsWith("config:"))&&(v==null?void 0:v.slots.get(Tt(N,O.targetProperty.slice(7)))),G=v==null?void 0:v.containers.get(I);if(W&&G&&(O==null?void 0:O.sourceProperty)==="output:resource"){const ce=s0(j,G,W);ce!==void 0&&E({data:j,nodeAddress:W.address.split(".").slice(0,-1).join("."),address:W.address,previousValue:we(j,W.address),value:ce});return}W||v!=null&&v.nodes.some(ce=>ce.data.id===I||ce.data.id===N)||(ne=A.onEdgeCreate)==null||ne.call(A,I,N,O)},onEdgeDelete:(I,N)=>{var me;const O=v==null?void 0:v.edges.find(K=>K.data.id===I);if(!O)return(me=A.onEdgeDelete)==null?void 0:me.call(A,I,N);const W=v.slots.get(Tt(O.data.target,O.data.targetProperty.slice(7))),G=W.address.split("."),ee=G.pop(),ne=G.join("."),ce=we(j,ne);E(Array.isArray(ce)?{data:j,nodeAddress:ne,address:ne,previousValue:ce,value:ce.filter((K,q)=>String(q)!==ee)}:{data:j,nodeAddress:ne,address:W.address,previousValue:we(j,W.address),value:void 0})},onNodeContentChange:(I,N)=>{var O,W;M(I,"$content",N)?(O=s.onNodeContentChange)==null||O.call(s,I,N):(W=A.onNodeContentChange)==null||W.call(A,I,N)},onNodeLabelChange:(I,N)=>{var O,W;M(I,"$label",N)?(O=s.onNodeLabelChange)==null||O.call(s,I,N):(W=A.onNodeLabelChange)==null||W.call(A,I,N)}}},[A,r,t,s,v,i.readOnly,i.editable]);return h.jsx(Rr.Provider,{value:{data:(r==null?void 0:r.state)??t,viewData:t,bindings:_,references:r==null?void 0:r.references,structured:v,renderForm:r==null?void 0:r.renderForm,editable:r?!!(r.onStateChange??r.onChange):!!s.onJsonChange,schema:C,setSchema:j=>{var E;f(j),(E=s.onFormSchemaChange)==null||E.call(s,j)},callbacks:k},children:h.jsx(wy,{config:v?{...i,formSchema:C}:i,callbacks:k,nodes:R,edges:T,children:h.jsxs(D.Box,{className:a,"data-flow-diagram":"",style:c,width:"100%",height:"100%",position:"relative",overflow:"hidden",css:{"& input, & textarea, & select":{outline:"none !important",boxShadow:"none !important"}},children:[h.jsx(Vb,{nodes:R,edges:T}),u&&h.jsx(Cm,{}),l]})})})}function G_(e){return ku(JSON.parse(e))}function ku(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 U_(e){return{replaceJson(t){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const r=ku(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=ku(t);return e.onStateChange(r,{address:"root",nodeAddress:"root",previousValue:e.state,value:r,data:r}),r}}}function H_(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,s)=>r(i,o[s])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,s])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i.startsWith("$")&&i!=="$")return JSON.stringify(s)===JSON.stringify(o[i])?[[i,s]]:[];const a=r(s,o[i]);return a===void 0?[]:[[i,a]]}))};return r(e,t)??{}}function fn(e){let t="",r=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},s=()=>{if(i(),!(r||!t.trim()))try{const c=e.parse(e.repair(t)),u=JSON.stringify(c);if(u===n)return;e.preview(c),n=u}catch{}},a=c=>{if(!r){if(new TextEncoder().encode(c).byteLength>(e.maxBytes??1024*1024))throw r=!0,i(),new Error("JSON stream exceeds the size limit.");t=c,o||(o=setTimeout(s,e.intervalMs??150))}};return{snapshot:a,append(c){a(t+c)},flush:s,finish(){if(r)throw new Error("JSON stream is closed.");r=!0,i();const c=e.parse(t);return e.commit(c),c},cancel(){r=!0,i(),t=""}}}function K_(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=fn(e),i=0,s=!1,a=!1,c;const u=Math.max(1,Math.ceil(t.length*r/n)),l=()=>e.onChange({position:i,total:t.length,playing:s}),d=()=>{clearTimeout(c),c=void 0},f=(g=!1)=>{o.snapshot(t.slice(0,i)),i===t.length?(s=!1,d(),o.finish()):g&&o.flush()},p=g=>{s=!1,d(),o.cancel(),l(),e.onError(g)},y=()=>{if(c=void 0,!(!s||a)){i=Math.min(t.length,i+u);try{f()}catch(g){p(g);return}l(),s&&(c=setTimeout(y,r))}};return{play(){a||s||(i===t.length&&(o.cancel(),o=fn(e),i=0),s=!0,l(),c=setTimeout(y,r))},pause(){a||(s=!1,d(),o.flush(),l())},seek(g){if(!a){if(!Number.isFinite(g))throw new Error("Playback position must be finite.");d(),i=Math.max(0,Math.min(t.length,Math.round(g))),o.cancel(),o=fn(e);try{f(!0)}catch(b){p(b);return}l(),s&&(c=setTimeout(y,r))}},dispose(){a=!0,s=!1,d(),o.cancel()}}}function J_({nodeAddress:e,expanded:t=!1}){var u;const{data:r,schema:n,bindings:o}=S.useContext(Rr),{colorText:i,background:s}=Je();if((u=o==null?void 0:o[e])!=null&&u.portResources)return null;const a=o&&rn(o,e,n);if(!r||!a)return null;const c=we(r,a.address);return!c||typeof c!="object"?null:h.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:he(i),background:he(s),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(a.type.properties).map(l=>{const d=a.fields[l]??{};if(!Sn(d.$visibleWhen,r))return null;const f=c[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:wr(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=Cm;exports.CompactPropertyLayoutToggle=Gy;exports.ConnectionsOnlyToggle=h0;exports.DEFAULT_PALETTE=mn;exports.DiagramAppearanceControls=Hy;exports.DynamicIcon=Mr;exports.EdgeTools=fm;exports.EditableLabel=Qt;exports.ErrorToast=vm;exports.FlowDiagram=V_;exports.FlowDiagramProvider=wy;exports.FlowPort=qb;exports.FlowView=Vb;exports.FormDocumentContext=Rr;exports.NODE_TYPE_VIEWS=Gt;exports.NodeBorderRadiusControl=hm;exports.NodeConfigSummary=J_;exports.NodeForm=sm;exports.NodeFormPopover=Nb;exports.NodeIconPicker=Bu;exports.NodeTools=pm;exports.NodeView=Gn;exports.SvgExportButton=mm;exports.Swatches=mt;exports.TEXT_PALETTE=lm;exports.ToolbarCloseButton=vt;exports.ToolbarCommitInput=tt;exports.ToolbarDivider=$t;exports.ToolbarIconButton=ve;exports.ToolbarRangeInput=Uy;exports.ToolbarScrollContainer=bm;exports.ToolbarSelect=Or;exports.ToolbarTooltip=Re;exports.TooltipIconButton=Ru;exports.WorkflowControls=xm;exports.addChild=Mu;exports.addConnection=qu;exports.addTargetEdge=rm;exports.addressToPath=Ir;exports.applyCollapsed=Qx;exports.applyFormChange=En;exports.applyStateEdits=e0;exports.bindSqueedCallbacks=Em;exports.compileSqueed=_u;exports.connectionIssue=Lu;exports.contentObjTheme=Er;exports.createFlowDiagram=rt;exports.createFlowDocumentActions=U_;exports.createFormNode=Sm;exports.createJsonPlayback=K_;exports.createJsonStream=fn;exports.downloadSvg=ym;exports.exportSvg=gm;exports.formValueError=jr;exports.getChakraColorHex=he;exports.getColorVariant=Cy;exports.getDarkerHexColor=hn;exports.getInteractionSurface=zr;exports.getNode=we;exports.parseFlowDocument=G_;exports.parseJsonContract=Nu;exports.parseTypeScriptContract=nm;exports.parseTypeScriptForm=$u;exports.projectJsonPlaybackPreview=H_;exports.readFormSchema=Fu;exports.readWorkflowContract=om;exports.removeEdge=tm;exports.removeNode=em;exports.resolveEdgeOwner=Kt;exports.resolveStateView=im;exports.setCollapsed=Xy;exports.setEdgeProp=Br;exports.setEdgeStyle=Qy;exports.setNodeProp=sr;exports.updateNode=mr;exports.useCustomColors=Je;exports.useEdgeProximity=my;exports.useFlowData=Ur;exports.useFlowDiagramContext=Ie;exports.useNodeViewActions=Un;exports.useStopPropagation=al;exports.useThemeContentColors=en;
273
+ `;function $b({nodeAddress:e,active:t,label:r,open:n=!1,onClose:o,children:i,filter:s,height:a}){const{background:u,border:c,colorText:l}=Ye(),{colorMode:d}=$e(),f=E.useRef(null),p=E.useId(),{data:y,schema:g,bindings:b}=E.useContext(Pr),x=i!==void 0||!!(y&&g&&(b?nn(b,e,g):_t(y,e,g)));E.useEffect(()=>{var w,v,C,S,j;!t||!x||!n?(w=f.current)==null||w.close():(v=f.current)!=null&&v.open||((C=f.current)==null||C.showModal(),(j=(S=f.current)==null?void 0:S.querySelector("[data-form-filter] input"))==null||j.focus())},[t,x,n]);const m=me(u);return x?h.jsx(h.Fragment,{children:typeof document<"u"&&Ht.createPortal(h.jsx(S_,{ref:f,id:p,$surface:m,$border:me(c),"aria-label":`Configure ${r}`,onClose:o,onPointerDown:w=>w.stopPropagation(),onWheel:w=>w.stopPropagation(),onKeyDown:w=>w.stopPropagation(),onClick:w=>{var v;w.stopPropagation(),w.target===w.currentTarget&&((v=f.current)==null||v.close())},style:{position:"fixed",inset:"94px 20px auto auto",margin:0,padding:20,width:"var(--top-toolbar-width, 360px)",boxSizing:"border-box",maxWidth:"calc(100vw - 40px)",maxHeight:"calc(100dvh - 114px)",height:a,overflow:"hidden",borderRadius:30,background:m,color:me(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:w=>w.stopPropagation(),children:h.jsx(Ct,{type:"submit","aria-label":"Close node configuration"})})]}),s&&h.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:s}),h.jsx(E_,{$divider:`var(--chakra-colors-gray-${d==="dark"?"700":"200"})`,"data-form-scroll":"",style:a?{flex:1}:void 0,children:i??h.jsx(cm,{nodeAddress:e})})]})}),document.body)}):null}const ku=({icon:e,label:t,onClick:r,color:n,boxSize:o=6,...i})=>{const{background:s,border:a,colorText:u}=Ye();return h.jsx(Te,{label:t,children:h.jsx(z.Flex,{children:h.jsx(z.Icon,{as:e,boxSize:o,color:n,cursor:r?"pointer":void 0,onClick:r})})})},j_=({data:e,children:t,isInverted:r,isParent:n,onOpenView:o,editOnMount:i=!1})=>{var N,ee,ge,ye,K,X;const{selectedNodeIds:s,setSelectedNodeIds:a,selectedEdgeId:u,setSelectedEdgeId:c,isMultiSelectMode:l,isPerformanceMode:d,engineRef:f,callbacks:p,config:y,themeColor:g,direction:b,nodeViewModes:x}=$e(),{background:m,border:w,colorText:v}=Ye(),C=E.useRef(null),S=E.useRef(null),[j,T]=E.useState(!1),[k,M]=E.useState(i&&!!y.editable&&!y.readOnly),[R,_]=E.useState(!1),A=e==null?void 0:e.id,I=um(A),q=s.includes(A),O=y.nodeOverlayActions,W=y.renderNodeOverlay,V=(()=>{var U;try{const se=(U=f.current)==null?void 0:U.zoom();return se!==void 0&&se<.08}catch{return!1}})(),ue=E.useCallback(U=>{var te,xe,pe,De;if(k||y.readOnly)return;const se={shiftKey:U.shiftKey,ctrlKey:U.ctrlKey,metaKey:U.metaKey,altKey:U.altKey};if(u&&(c(null),(te=p.onEdgeDeselect)==null||te.call(p)),l){const Z=s.includes(A),de=Z?s.filter(Ce=>Ce!==A):[...s,A];a(de),Z?(xe=p.onNodeDeselect)==null||xe.call(p):(pe=p.onNodeSelect)==null||pe.call(p,A,e,se)}else a([A]),(De=p.onNodeSelect)==null||De.call(p,A,e,se)},[A,e,s,u,l,k,a,c,p,y]),ne=E.useCallback(()=>{var U;k||y.readOnly||(U=p.onNodeDoubleClick)==null||U.call(p,A,e)},[A,e,k,p,y]),Q=E.useCallback(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>T(!0),100)},[]),he=E.useCallback(()=>{S.current&&clearTimeout(S.current),T(!1)},[]),le=!!((N=e==null?void 0:e.config)!=null&&N.form),$={tabIndex:le?0:void 0,"aria-haspopup":le?"dialog":void 0,"aria-expanded":le?R:void 0,onDoubleClickCapture:U=>{var se;!le&&!o||y.readOnly||k||!U.currentTarget.contains(U.target)||U.target instanceof Element&&U.target.closest("button, input, textarea, select, a, [contenteditable=true]")||(U.preventDefault(),U.stopPropagation(),a([A]),o?o():_(!0),(se=p.onNodeDoubleClick)==null||se.call(p,A,e))},onKeyDown:U=>{!le&&!o||y.readOnly||U.target!==U.currentTarget||U.key!=="Enter"||(U.preventDefault(),U.stopPropagation(),a([A]),o?o():_(!0))}},D=le&&h.jsx($b,{nodeAddress:A,active:q,label:e.label||e.headerTitle||"Node",open:R,onClose:()=>{var U;_(!1),q&&((U=C.current)==null||U.focus({preventScroll:!0}))}}),G=Array.isArray((ee=e==null?void 0:e.config)==null?void 0:ee.ports)?e.config.ports.map(U=>h.jsx(Nb,{...U},`${U.id}:${U.role}`)):null;return n?h.jsxs(z.Box,{ref:C,...$,onClick:ue,onDoubleClick:ne,onMouseEnter:Q,onMouseLeave:he,cursor:"pointer",position:"relative",children:[D,!d&&(W||O&&O.length>0)&&j&&!V&&h.jsxs(h.Fragment,{children:[h.jsx(z.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>T(!0),onMouseLeave:he}),W?h.jsx(z.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>T(!0),onMouseLeave:he,willChange:"transform",children:W({nodeId:A,nodeData:e,isRoot:A==="root",isParent:!0,isHovered:j,setIsHovered:T})}):h.jsx(z.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:m,p:3,borderColor:w,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>T(!0),onMouseLeave:he,willChange:"transform",children:h.jsx(z.HStack,{px:2,gap:2,children:O.map((U,se)=>h.jsxs(z.Box,{display:"contents",children:[se>0&&h.jsx(z.Box,{borderColor:w,height:5,borderRightWidth:1}),h.jsx(ku,{icon:U.icon,label:U.label,color:v,bgColor:m,borderColor:w,textColor:v,boxSize:5,onClick:te=>{var xe;te.stopPropagation(),(xe=p.onNodeHoverAction)==null||xe.call(p,U.id,A,e)}})]},U.id))})})]}),t({id:A,data:e,isActive:q,isLowZoom:V,isEditing:k,onEditStart:()=>M(!0),onEditEnd:()=>M(!1)}),I&&!((ge=e==null?void 0:e.config)!=null&&ge.parentContainer)&&((ye=e==null?void 0:e.config)==null?void 0:ye.collapsed)!==void 0&&(()=>{var te;const U=b==="TB"||b==="BT",se=r||b==="RL";return h.jsx(z.IconButton,{position:"absolute",...U?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:se?void 0:"-75px",left:se?"-75px":void 0,top:"50%",transform:"translateY(-50%)"},"aria-label":e.config.collapsed?"Expand":"Collapse",disabled:y.readOnly,onClick:xe=>{var pe;xe.stopPropagation(),(pe=p.onNodeCollapse)==null||pe.call(p,A,!e.config.collapsed)},bgColor:me(((te=e==null?void 0:e.viewProps)==null?void 0:te.bgColor)||g),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?h.jsx(J.PiPlusBold,{size:30,color:me("gray.800")}):h.jsx(J.PiMinusBold,{size:30,color:me("gray.800")})})})()]}):h.jsxs(z.Box,{ref:C,...$,onClick:ue,onDoubleClick:ne,onMouseEnter:Q,onMouseLeave:he,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[D,G,!d&&(W||O&&O.length>0)&&j&&!V&&h.jsxs(h.Fragment,{children:[h.jsx(z.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>T(!0),onMouseLeave:he}),W?h.jsx(z.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>T(!0),onMouseLeave:he,willChange:"transform",children:W({nodeId:A,nodeData:e,isRoot:A==="root",isParent:!!n,isHovered:j,setIsHovered:T})}):h.jsx(z.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:m,p:3,borderColor:w,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>T(!0),onMouseLeave:he,willChange:"transform",children:h.jsx(z.HStack,{px:2,gap:2,children:O.map((U,se)=>h.jsxs(z.Box,{display:"contents",children:[se>0&&h.jsx(z.Box,{borderColor:w,height:5,borderRightWidth:1}),h.jsx(ku,{icon:U.icon,label:U.label,color:v,bgColor:m,borderColor:w,textColor:v,boxSize:5,onClick:te=>{var xe;te.stopPropagation(),(xe=p.onNodeHoverAction)==null||xe.call(p,U.id,A,e)}})]},U.id))})})]}),h.jsxs(z.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[I&&!((K=e==null?void 0:e.config)!=null&&K.parentContainer)&&((X=e==null?void 0:e.config)==null?void 0:X.collapsed)!==void 0&&!n&&(()=>{var xe,pe,De;const U=b==="TB"||b==="BT",se=r||b==="RL",te=(xe=e==null?void 0:e.config)!=null&&xe.labelBelow&&x[A]!=="properties"?((((pe=e==null?void 0:e.viewProps)==null?void 0:pe.fontSize)||1)*100+100)/2:void 0;return h.jsx(z.IconButton,{position:"absolute",...U?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:se?void 0:te===void 0?"-75px":`calc(50% - ${te+75}px)`,left:se?te===void 0?"-75px":`calc(50% - ${te+75}px)`:void 0,alignSelf:te===void 0?"center":void 0,top:te===void 0?void 0:`${te}px`,transform:te===void 0?void 0:"translateY(-50%)",zIndex:te===void 0?void 0:1},"aria-label":e.config.collapsed?"Expand":"Collapse",disabled:y.readOnly,onClick:Z=>{var de;Z.stopPropagation(),(de=p.onNodeCollapse)==null||de.call(p,A,!e.config.collapsed)},bgColor:me(((De=e==null?void 0:e.viewProps)==null?void 0:De.bgColor)||g),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?h.jsx(J.PiPlusBold,{size:30,color:me("gray.800")}):h.jsx(J.PiMinusBold,{size:30,color:me("gray.800")})})})(),t({id:A,data:e,isActive:q,isLowZoom:V,isEditing:k,onEditStart:()=>M(!0),onEditEnd:()=>M(!1)})]})]})},Un=E.memo(j_);function sl(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 rn=({nodeId:e,label:t,color:r,fontWeight:n="bold",fontSize:o="5xl",wrap:i=!1,isEditing:s,onEditStart:a,onEditEnd:u})=>{const{callbacks:c,config:l,readOnly:d}=$e(),f=l.editable&&!d,[p,y]=E.useState(t),[g,b]=E.useState(),x=E.useRef(null),m=E.useRef(!1),w=sl(s);E.useEffect(()=>{s&&(m.current=!1,x.current&&(x.current.focus(),x.current.select()))},[s]);const v=()=>{var S;if(m.current)return;m.current=!0;const C=p.trim();C&&C!==t&&((S=c.onNodeLabelChange)==null||S.call(c,e,C)),u()};return!f||!s?h.jsx(z.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?C=>{C.stopPropagation(),b({width:C.currentTarget.offsetWidth,height:C.currentTarget.offsetHeight}),y(t),a()}:void 0,cursor:f?"text":void 0,children:t}):h.jsxs("div",{ref:w,style:{position:"relative",width:"max-content",minWidth:g==null?void 0:g.width,maxWidth:900,height:g==null?void 0:g.height},children:[h.jsx(z.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),h.jsx(z.Input,{ref:x,value:p,onChange:C=>y(C.target.value),onBlur:v,onKeyDown:C=>{C.key==="Enter"&&v(),C.key==="Escape"&&(m.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"})]})},R_=({id:e,data:t,isActive:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var g,b,x,m,w,v,C,S;const{themeColor:s}=$e(),{colorText:a}=Ye(),u=((g=t==null?void 0:t.viewProps)==null?void 0:g.bgColor)==="transparent",c=((b=t==null?void 0:t.viewProps)==null?void 0:b.outline)===!0,{highlightColor:l,borderColor:d,textColor:f}=tn(((x=t==null?void 0:t.viewProps)==null?void 0:x.bgColor)||s),p=me(((m=t==null?void 0:t.viewProps)==null?void 0:m.textColor)||(u||c?a:f)),y=((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)||s:d);return h.jsx(z.Box,{"data-flow-node-surface":"",borderRadius:(C=t==null?void 0:t.viewProps)==null?void 0:C.borderRadius,bgColor:c?"transparent":l,...mn(t==null?void 0:t.viewProps,y,r,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:h.jsxs(z.Flex,{justifyContent:"start",alignItems:"center",gap:8,w:"fit-content",maxW:900,minW:0,fontSize:"5xl",lineHeight:"normal",children:[((S=t==null?void 0:t.config)==null?void 0:S.icon)&&h.jsx(z.Box,{flexShrink:0,children:h.jsx(kr,{name:t.config.icon,size:80,color:p})}),h.jsx(rn,{nodeId:e,label:(t==null?void 0:t.label)||(t==null?void 0:t.text)||"",color:p,isEditing:n,onEditStart:o,onEditEnd:i})]})})};function Hn(){const{nodeViewModes:e,setNodeViewMode:t,allNodesIconLabel:r,setAllNodesIconLabel:n}=$e();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 k_=({id:e,isActive:t,data:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var w,v,C,S,j,T,k,M,R,_,A,I,q,O,W;const{themeColor:s}=$e(),{colorText:a}=Ye(),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&&((C=r==null?void 0:r.viewProps)==null?void 0:C.bgColor)||s,{borderColor:d,highlightColor:f,textColor:p}=tn(l),y=me(((S=r==null?void 0:r.viewProps)==null?void 0:S.textColor)||(u||c?a:p)),g=u&&!c&&!((j=r==null?void 0:r.viewProps)!=null&&j.borderColor)?"transparent":me(((T=r==null?void 0:r.viewProps)==null?void 0:T.borderColor)||(c?l:d)),b=u||c?"transparent":l!=null&&l.startsWith("#")?l:me(f),x=(k=r==null?void 0:r.config)==null?void 0:k.icon,m=(r==null?void 0:r.label)??(r==null?void 0:r.text)??"";if((M=r==null?void 0:r.config)!=null&&M.labelBelow){const V=(((R=r==null?void 0:r.viewProps)==null?void 0:R.fontSize)||1)*100;return h.jsxs(z.Flex,{"data-flow-icon-label":"",direction:"column",align:"center",gap:"24px",width:`${Math.max(V+200,360)}px`,position:"relative",children:[h.jsx(z.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${V+100}px`,height:`${V+100}px`,flexShrink:0,borderRadius:(_=r==null?void 0:r.viewProps)==null?void 0:_.borderRadius,backgroundColor:b,...mn(r==null?void 0:r.viewProps,g,t,2),children:!!x&&h.jsx(kr,{name:x,size:V,color:y})}),h.jsxs(z.Flex,{"data-flow-icon-caption":"",direction:"column",align:"center",gap:"8px",justify:"center",width:"100%",minW:0,textAlign:"center",children:[h.jsx(rn,{nodeId:e,label:m,color:me(((A=r==null?void 0:r.viewProps)==null?void 0:A.textColor)||a),isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0}),typeof((I=r.config)==null?void 0:I.subtitle)=="string"&&r.config.subtitle!==""&&h.jsx(z.Text,{"data-flow-node-subtitle":"",color:me(((q=r==null?void 0:r.viewProps)==null?void 0:q.textColor)||a),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(z.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:(O=r==null?void 0:r.viewProps)==null?void 0:O.borderRadius,bgColor:b,style:{backgroundColor:b},textTransform:"capitalize",...mn(r==null?void 0:r.viewProps,g,t,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!x&&h.jsx(z.Flex,{align:"center",py:14,mr:m?8:0,flexShrink:0,children:h.jsx(kr,{name:x,size:(((W=r==null?void 0:r.viewProps)==null?void 0:W.fontSize)||1)*100,color:y},y)}),(m||!x)&&h.jsx(z.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:h.jsx(rn,{nodeId:e,label:m,color:y,isEditing:n,onEditStart:o,onEditEnd:i})})]})};function Lb({onExpand:e,toggleLabel:t="Show properties",toggleDisabled:r=!1,renderCompact:n=k_,...o}){const{colorMode:i,callbacks:s}=$e();return h.jsx(Un,{...o,children:a=>h.jsxs(z.Box,{position:"relative",children:[h.jsx(n,{...a}),e&&a.isActive&&h.jsx(z.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:h.jsx(Te,{label:t,children:h.jsx(Se,{"aria-label":t,icon:h.jsx(z.Icon,{as:J.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=s.onNodeViewToggle)==null||c.call(s,o.data.id)}})})})]})})}const py=1.55;function P_({nodeId:e,content:t,color:r}){const{callbacks:n,config:o,readOnly:i}=$e(),s=!!o.editable&&!i,[a,u]=E.useState(!1),[c,l]=E.useState(t),[d,f]=E.useState(),p=E.useRef(null),y=E.useRef(!1),g=sl(a);E.useLayoutEffect(()=>{const m=p.current;!a||!m||(m.style.height="auto",m.style.height=`${Math.max((d==null?void 0:d.height)??0,m.scrollHeight)}px`)},[c,a,d]),E.useEffect(()=>{var m;s?a&&(y.current=!1,(m=p.current)==null||m.focus()):u(!1)},[a,s]);const b=m=>{s&&(f({width:m.offsetWidth,height:m.offsetHeight}),l(t),u(!0))},x=()=>{var m;y.current||!s||(y.current=!0,c!==t&&((m=n.onNodeContentChange)==null||m.call(n,e,c)),u(!1))};return!a||!s?h.jsx(z.Box,{"data-flow-content":"",color:r,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:py,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:s?"text":void 0,tabIndex:s?0:void 0,onDoubleClick:m=>{m.stopPropagation(),b(m.currentTarget)},onKeyDown:m=>{s&&m.key==="Enter"&&m.target===m.currentTarget&&(m.preventDefault(),m.stopPropagation(),b(m.currentTarget))},children:h.jsx(cv.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:g,style:{width:d==null?void 0:d.width,minHeight:d==null?void 0:d.height,maxWidth:"100%"},children:h.jsx(z.Textarea,{ref:p,"aria-label":"Node content",value:c,onChange:m=>l(m.target.value),onBlur:x,onKeyDown:m=>{m.stopPropagation(),!m.nativeEvent.isComposing&&(m.key==="Enter"&&(m.ctrlKey||m.metaKey)&&(m.preventDefault(),x()),m.key==="Escape"&&(y.current=!0,u(!1)))},color:r,fontFamily:"inherit",fontSize:"inherit",lineHeight:py,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 A_=(e,t,r)=>{var f,p,y,g;const n=((f=e==null?void 0:e.viewProps)==null?void 0:f.bgColor)||t,[o]=n.split("."),i=tn(n),s=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,a=n==="transparent"||s,u=r==="dark"?"gray.200":"gray.900",c=a?"transparent":n!=null&&n.startsWith("#")?me(n):me(i.bgColor),l=me(((y=e==null?void 0:e.viewProps)==null?void 0:y.textColor)||(a?u:i.textColor)),d=me(((g=e==null?void 0:e.viewProps)==null?void 0:g.borderColor)||(s?n==="transparent"?t:n:i.borderColor));return{...i,bgColor:a?"transparent":i.bgColor,highlightColor:a?"transparent":i.highlightColor,isTransparent:a,propertyColor:a?u:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:c,hextextColor:l,hexborderColor:d}},T_=(e,t=350)=>`${String(e).substring(0,t)}${String(e).length>t?"...":""}`,O_=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,Fb=600,I_=3,M_=e=>{const t=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(t*28+30,200)};function q_({headerTitle:e,hasContent:t,data:r,icon:n,colors:o,hasConfig:i,id:s,isActive:a,isEditing:u,onEditStart:c,onEditEnd:l,props:d,objVisible:f,setObjVisible:p,onShowNativeIcon:y}){var m,w;const{callbacks:g}=$e(),b=d.onShowIcon??y,x=b?"Show icon":f?"Show content":"Show properties";return h.jsx(h.Fragment,{children:(e||t||((m=r.config)==null?void 0:m.form)||a&&y)&&h.jsxs(z.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(z.Flex,{mr:6,alignItems:"center",flexShrink:0,children:h.jsx(kr,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),h.jsx(rn,{nodeId:s,label:O_(e),color:((w=r==null?void 0:r.viewProps)==null?void 0:w.textColor)||o.propertyColor,isEditing:u,onEditStart:c,onEditEnd:l}),a&&(t||b)&&h.jsx(z.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:h.jsx(Te,{label:x,children:h.jsx(Se,{"aria-label":x,icon:h.jsx(z.Icon,{as:J.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:v=>{var C;v.stopPropagation(),b?b():p(!f),(C=g.onNodeViewToggle)==null||C.call(g,s)}})})})]})})}function N_({data:e,resourcePorts:t,inspecting:r,form:n,inspectionPorts:o,extraPorts:i,colors:s,direction:a,uniformKeyWidth:u}){const{edgeById:c}=Hr(),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(z.Box,{children:Object.entries(e.description||{}).map(([d,f],p)=>{var A,I,q;const y=t&&Object.keys(t).find(O=>O.slice(O.indexOf(":")+1)===d),g=r&&((A=n==null?void 0:n.type.ports)==null?void 0:A[d]),b=y??(g?`${g.kind}:${d}`:d),x=o.find(O=>O.id===b),m=y?"source":x==null?void 0:x.role,w=l.has(`source:${b}`),v=l.has(`target:${b}`),C=i.some(O=>O.id===d),S=f===""&&(C||(m?l.has(`${m}:${b}`):w||v)),j=m??(w!==v?w?"source":"target":void 0),T=(x==null?void 0:x.side)??(j?j==="source"!=(a==="RL")?"right":"left":void 0),k=S&&T==="right"?"right":"left",M=(x==null?void 0:x.label)??(g==null?void 0:g.label)??(C?d.replace(/^(template|input|output|config|error):/,""):d),R=Rr(s.wordBeforeDot)[typeof f],_=Rr(s.wordBeforeDot).property;return h.jsxs(z.Box,{"data-flow-property":y&&(a==="TB"||a==="BT")?void 0:b,"data-flow-port-role":m,"data-flow-inspection-row":r?"":void 0,children:[h.jsxs(z.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[h.jsx(z.Flex,{justifyContent:"start",align:"center",background:s.highlightColor,width:S?"100%":`${u}px`,minWidth:`${u}px`,borderRightColor:s.hexborderColor,borderRightWidth:S?0:1,children:h.jsx(z.Text,{py:5,px:10,w:"100%",textAlign:k,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((I=e==null?void 0:e.viewProps)==null?void 0:I.textColor)||(s.isTransparent?s.hextextColor:_),children:M})}),!S&&h.jsx(z.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:s.hexbgColor,w:Fb,maxH:200,children:h.jsx(z.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:((q=e==null?void 0:e.viewProps)==null?void 0:q.textColor)||(s.isTransparent?s.hextextColor:R),fontWeight:400,children:T_(f)})})]}),p!==Object.entries(e.description||{}).length-1&&h.jsx(z.Box,{borderTopWidth:1,my:0,borderColor:s.hexborderColor})]},d)})})}function $_(e){var w,v,C;const{themeColor:t,colorMode:r,direction:n}=$e(),o=Hn(),i=o.getNodeViewMode(e.data.id)==="properties",s=S=>o.setNodeViewMode(e.data.id,S?"properties":"default"),a=!!e.onShowIcon||i||typeof((w=e.data.config)==null?void 0:w.content)!="string",{bindings:u,data:c,schema:l}=E.useContext(Pr),d=(v=u==null?void 0:u[e.data.id])==null?void 0:v.portResources,f=u?nn(u,e.data.id,l):c&&l?_t(c,e.data.id,l):void 0,p=f&&je(c,"address"in f?f.address:e.data.id),y=p&&typeof p=="object"&&f?Object.fromEntries(Object.keys(f.type.properties).filter(S=>{var j;return Object.prototype.hasOwnProperty.call(p,S)&&En((j=f.fields[S])==null?void 0:j.$visibleWhen,c)}).map(S=>[S,p[S]!==null&&typeof p[S]=="object"?JSON.stringify(p[S],null,2):p[S]===null?"null":p[S]])):{},g=d?Object.fromEntries(Object.entries(d).map(([S,j])=>{var T;return[S.slice(S.indexOf(":")+1),((T=je(c,j))==null?void 0:T.name)??j.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:y,b=a&&!d?((C=e.data.config)==null?void 0:C.ports)??[]:[],x=b.filter(S=>!Object.prototype.hasOwnProperty.call(g,S.id)&&!Object.entries((f==null?void 0:f.type.ports)??{}).some(([j,T])=>`${T.kind}:${j}`===S.id&&Object.prototype.hasOwnProperty.call(g,j))),m={...g,...Object.fromEntries(x.map(S=>[S.id,""]))};return{themeColor:t,colorMode:r,direction:n,objVisible:i,setObjVisible:s,inspecting:a,resourcePorts:d,form:f,description:m,inspectionPorts:b,extraPorts:x}}const cl=e=>{var b,x,m;const{themeColor:t,colorMode:r,direction:n,objVisible:o,setObjVisible:i,inspecting:s,resourcePorts:a,form:u,description:c,inspectionPorts:l,extraPorts:d}=$_(e),f=Hn(),p=f.getNodeViewMode(e.data.id)==="icon-label",g=!e.onShowIcon&&!((b=e.data.config)!=null&&b.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(Lb,{...e,data:{...e.data,label:e.data.label??e.data.headerTitle,config:{...e.data.config,labelBelow:!0,icon:((m=e.data.config)==null?void 0:m.icon)||"PiBracketsCurly"}},onExpand:()=>f.restoreNodeView(e.data.id)}):h.jsx(Un,{...e,data:{...e.data,description:c},children:({id:w,data:v,isActive:C,isEditing:S,onEditStart:j,onEditEnd:T})=>{var V,ue,ne,Q,he,le;const k=A_(v,t,r),M=v.label??v.headerTitle,R=Object.entries(v.description||{}).length>0,_=M_(v.description),A=(ue=(V=e.data)==null?void 0:V.config)==null?void 0:ue.icon,I=(Q=(ne=e.data)==null?void 0:ne.config)==null?void 0:Q.content,q=typeof I=="string"&&!e.onShowIcon,O=((he=v==null?void 0:v.viewProps)==null?void 0:he.borderRadius)??"53px",W=mn(v==null?void 0:v.viewProps,k.hexborderColor,C,I_);return h.jsx(z.Flex,{justifyContent:"space-between",...v==null?void 0:v.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:O,overflow:"hidden",alignItems:"center",style:{backgroundColor:k.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:"100%",minW:q||e.onShowIcon?_+Fb+W.borderWidth*2:void 0,...W,children:h.jsxs(z.Flex,{width:"100%",direction:"column",borderRadius:O,borderColor:k.hexborderColor,borderWidth:0,overflow:"hidden",children:[h.jsx(q_,{headerTitle:M,hasContent:q,data:v,icon:A,colors:k,hasConfig:R,id:w,isActive:C,isEditing:S,onEditStart:j,onEditEnd:T,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:g}),q&&!o?h.jsx(z.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:k.highlightColor,p:12,fontSize:"5xl",lineHeight:"normal",children:h.jsx(P_,{nodeId:w,content:I,color:((le=v==null?void 0:v.viewProps)==null?void 0:le.textColor)||k.hextextColor})}):h.jsx(N_,{data:v,resourcePorts:a,inspecting:s,form:u,inspectionPorts:l,extraPorts:d,colors:k,direction:n,uniformKeyWidth:_})]})})}})};cl.displayName="NodeJsonObjectView";const Bb=e=>{var y,g,b,x,m,w,v,C,S,j,T;const t=Hn(),[r,n]=E.useState(!1),o=t.getNodeViewMode(e.data.id)==="properties",i=k=>{n(k),t.setNodeViewMode(e.data.id,k?"properties":"default")},{callbacks:s,readOnly:a,selectedNodeIds:u}=$e(),c=(g=(y=e.data)==null?void 0:y.config)==null?void 0:g.parentContainer,l=u.includes(e.data.id),d=E.useRef(l);E.useEffect(()=>{var k,M;d.current&&!l&&o&&((M=(k=e.data)==null?void 0:k.config)!=null&&M.labelBelow)&&!c&&!a&&i(!1),d.current=l},[l,o,(x=(b=e.data)==null?void 0:b.config)==null?void 0:x.labelBelow,c,a]);const f=c?"Show parent":"Show properties",p=c||((w=(m=e.data)==null?void 0:m.config)==null?void 0:w.form)||((S=(C=(v=e.data)==null?void 0:v.config)==null?void 0:C.ports)==null?void 0:S.length);return!c&&p&&o?h.jsx(cl,{...e,editOnMount:r,onShowIcon:()=>i(!1)}):h.jsx(Lb,{...e,onOpenView:!c&&p&&((T=(j=e.data)==null?void 0:j.config)!=null&&T.labelBelow)?()=>{var k;i(!0),(k=s.onNodeViewToggle)==null||k.call(s,e.data.id)}:void 0,toggleLabel:f,toggleDisabled:c&&a,onExpand:p?()=>{var k;c?(k=s.onNodeCollapse)==null||k.call(s,e.data.id,!1):i(!0)}:void 0})},zb=e=>h.jsx(Bb,{...e,renderCompact:R_}),Db=e=>h.jsx(Bb,{...e}),Vb=e=>h.jsx(Un,{...e,children:()=>null});zb.displayName="text";Db.displayName="arrayView";Vb.displayName="ParentContainerView";const L_={objectView:cl,arrayView:Db,text:zb,parentContainer:Vb},F_=({children:e,pattern:t="dot",backgroundColor:r})=>{const{colorMode:n}=$e(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",s=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return t==="none"?h.jsx(z.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:r,children:e}):h.jsxs(z.Box,{"data-flow-background":t,position:"relative",width:"100%",height:"100%",padding:0,bg:r,children:[h.jsx(z.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(${s}) 0, var(${s}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${s}) 1px, transparent 1px), linear-gradient(90deg, var(${s}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),h.jsx(z.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},B_=.4,Xr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},z_=({nodes:e,edges:t})=>{const{themeColor:r,spacing:n,edgeRadius:o,backgroundVariant:i,setBackgroundSelected:s,edgeColor:a,direction:u,nodeAlignment:c,edgeMode:l,compactPropertyLayout:d,workflowContract:f,parentNodeStyle:p,engineRef:y,callbacks:g,config:b,selectedNodeIds:x,setSelectedNodeIds:m,selectedEdgeId:w,setSelectedEdgeId:v,setIsPerformanceMode:C,isZoomMode:S,setIsZoomMode:j,isMultiSelectMode:T,setIsMultiSelectMode:k,isDragMode:M,setIsDragMode:R,isEdgeHandlesEnabled:_,setIsEdgeHandlesEnabled:A,isArrayNodeMode:I}=$e(),q=E.useRef(null),[O,W]=E.useState(null),V=e.length>200;E.useEffect(()=>{C(V)},[V,C]);const{edgeSep:ue,rankSep:ne,spacingFactor:Q}=E.useMemo(()=>{const re=_0(e.length),F=n<1?.3+.7*n:.5+.5*n;return{edgeSep:re.edgeSep*F,rankSep:re.rankSep*F,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n]),{bgColor:he}=tn(r),{canvas:le,borderSecondary:$,colorText:D}=Ye(),G=i==="transparent"?"transparent":b.backgroundColor||le,N=E.useCallback(re=>{if(!re)return me(r);switch(re){case"dark":return me(G);case"light":return me($);default:return me(re)}},[r,G,$]),ee=b.colorMode==="dark",ge=ee?me("gray.500"):wt,ye=ee?he!=null&&he.includes("gray")?"whitesmoke":N(he):ge,K=a?N(a):ge,X=E.useMemo(()=>b.initialViewport||{pan:{x:0,y:0},zoom:.01},[]),U=u==="C"?"LR":u,se=E.useCallback(re=>{const F={...p,...re};return{...F,bgColor:F.bgColor||r,bgOpacity:F.outline?0:F.bgOpacity??B_}},[p,r]),te=E.useMemo(()=>{var F;const re=new Map;for(const Y of e)(F=Y.data)!=null&&F.id&&re.set(Y.data.id,Y);return re},[e]),xe=E.useMemo(()=>{var F;const re=new Map;for(const Y of t)(F=Y.data)!=null&&F.id&&re.set(Y.data.id,Y);return re},[t]),pe=E.useCallback(re=>{var Pe;const F=(Pe=te.get(re))==null?void 0:Pe.data,Y=se(F==null?void 0:F.viewProps),Re=me(Y.bgColor);return{animated:!!(F!=null&&F.isNodeAnimated)&&!V,animationVariant:F==null?void 0:F.nodeAnimationVariant,animationColor:me(Y.borderColor||r),bgColor:Y.outline?"transparent":Re,bgOpacity:Y.bgOpacity,borderColor:Y.borderColor?me(Y.borderColor):Y.outline&&Y.bgColor==="transparent"?me(r):Re,borderWidth:en(Y.borderWidth,Xr.borderWidth),borderStyle:Y.borderStyle??Xr.borderStyle,borderRadius:Y.borderRadius??Xr.borderRadius,textColor:Y.textColor?me(Y.textColor):Y.outline||Y.bgColor==="transparent"?me(D):Re,fontSize:Y.fontSize??Xr.fontSize,labelPosition:Y.labelPosition??Xr.labelPosition,labelMargin:Xr.labelMargin,labelBg:hl(N("dark"),Re,Y.bgOpacity)??N("dark"),padding:Y.padding??Xr.padding}},[se,te,D,r,V,N]),De=E.useMemo(()=>{var Y,Re;const re=new Map;for(const Pe of t){const ke=(Y=Pe.data)==null?void 0:Y.source,Me=(Re=Pe.data)==null?void 0:Re.target;if(!ke||!Me||ke===Me)continue;const ze=ke<Me?`${ke}|${Me}`:`${Me}|${ke}`,Ke=re.get(ze);Ke?Ke.push({id:Pe.data.id,source:ke}):re.set(ze,[{id:Pe.data.id,source:ke}])}const F=new Map;for(const[Pe,ke]of re){if(ke.length<2)continue;const Me=Pe.split("|")[0],ze=Math.min(20,70/ke.length);ke.forEach(({id:Ke,source:Ge},jr)=>{const Ae=50+(jr-(ke.length-1)/2)*ze;F.set(Ke,(Ge===Me?Ae:100-Ae)/100)})}return F},[t]),Z=E.useMemo(()=>{const re=N("dark");return t.filter(F=>{var Y;return((Y=F.data)==null?void 0:Y.id)&&F.data.source&&F.data.target}).map(({data:F})=>{var ke,Me,ze,Ke,Ge,jr;let Y=re;const Re=(Me=(ke=te.get(F.source))==null?void 0:ke.data)==null?void 0:Me.parent,Pe=(Ke=(ze=te.get(F.target))==null?void 0:ze.data)==null?void 0:Ke.parent;if(Re&&Re===Pe){const Ae=se((jr=(Ge=te.get(Re))==null?void 0:Ge.data)==null?void 0:jr.viewProps),gr=hl(re,me(Ae.bgColor),Ae.bgOpacity);gr&&(Y=gr)}return{id:F.id,data:F,type:F.type??b.edgeType??"rounded-orthogonal",source:F.source,target:F.target,sourceProperty:F.sourceProperty,targetProperty:F.targetProperty,label:F.label,validationIssue:(l==="auto"||l==="properties")&&(F.sourceProperty!==void 0||F.targetProperty!==void 0)&&f?Fu(f,F):void 0,color:a?K:F.color?me(F.color):K,connectorColor:a?K:F.color?me(F.color):ye,labelBg:Y,dashed:!!F.isEdgeDashed,animated:!!F.isEdgeAnimated,inverted:!!F.isInverted,turn:De.get(F.id)??.5}})},[t,K,ye,a,De,b.edgeType,l,f,te,se,N]),de=E.useMemo(()=>{var F;const re=new Set;for(const Y of e)(F=Y.data)!=null&&F.parent&&re.add(Y.data.parent);return re},[e]),Ce=E.useMemo(()=>{var F;const re=new Map;for(const Y of t)(F=Y.data)!=null&&F.source&&!re.has(Y.data.source)&&re.set(Y.data.source,Y.data);return re},[t]),Ie=E.useMemo(()=>{const re={...L_,...b.customViews};return e.filter(F=>{var Y;return(Y=F.data)==null?void 0:Y.id}).map(F=>{var Me,ze,Ke,Ge;const Y=de.has(F.data.id)&&!F.data.parent,Re=Y?F.data.label??F.data.headerTitle??"Container":void 0,Pe=Y?re.parentContainer:re[F.data.type]||re.text,ke=Ce.get(F.data.id);return{id:F.data.id,collapsed:(Me=F.data.config)==null?void 0:Me.collapsed,parent:F.data.parent,label:Re,animated:!!F.data.isNodeAnimated,animationVariant:F.data.nodeAnimationVariant,hasCollapseControl:((ze=F.data.config)==null?void 0:ze.collapsed)!==void 0,animationColor:me(((Ke=F.data.viewProps)==null?void 0:Ke.borderColor)||r),animationWidth:en((Ge=F.data.viewProps)==null?void 0:Ge.borderWidth,8),element:E.createElement(Pe,{...F,isInverted:ke==null?void 0:ke.isInverted,isParent:Y,key:`${F.data.id}-${r}`})}})},[e,de,Ce,r,b.customViews]),qe=E.useMemo(()=>V?300:e.length>50?150:e.length>20?100:50,[e.length,V]),Ue=E.useRef(b);Ue.current=b;const Qe=E.useRef(S);Qe.current=S;const We=E.useRef(I);We.current=I;const we=E.useRef(x);we.current=x;const _e=E.useRef(w);_e.current=w;const He=E.useRef(T);He.current=T;const Xe=E.useRef(te);Xe.current=te;const ur=E.useRef(xe);ur.current=xe;const er=E.useRef(new Map);E.useEffect(()=>{var Y,Re;const re=new Map([...xe].filter(([,Pe])=>te.has(Pe.data.source)&&te.has(Pe.data.target))),F=er.current;er.current=re;for(const[Pe,ke]of F)re.has(Pe)||(_e.current===Pe&&(v(null),(Y=g.onEdgeDeselect)==null||Y.call(g)),(Re=g.onEdgeRemove)==null||Re.call(g,Pe,ke.data))},[xe,te,g,v]),E.useEffect(()=>{const re=q.current;if(!O||!re)return;let F=null,Y=null,Re=0,Pe=0,ke=0,Me=0,ze=0;const Ke=Ge=>{if(Ue.current.readOnly)return;Ge.preventDefault(),Ge.stopPropagation(),Qe.current||Ge.metaKey||Ge.ctrlKey?(ke+=Ge.deltaY,Me=Ge.clientX,ze=Ge.clientY,Y===null&&(Y=requestAnimationFrame(()=>{Y=null;const Ae=Ue.current,gr=O.zoom(),$r=ke;ke=0;let Tr=gr-$r*.05/100;Tr=Math.max(Ae.minZoom??.01,Math.min(Ae.maxZoom??1.5,Tr));const Lr=re.getBoundingClientRect();O.zoomAt(Tr,{x:Me-Lr.left,y:ze-Lr.top})}))):(Re+=Ge.deltaX,Pe+=Ge.deltaY,F===null&&(F=requestAnimationFrame(()=>{F=null;const Ae=O.pan(),gr=O.zoom(),$r=.35,Tr=Re,Lr=Pe;Re=0,Pe=0,O.pan({x:Ae.x+-Tr*$r/gr,y:Ae.y+-Lr*$r/gr})})))};return re.addEventListener("wheel",Ke,{passive:!1}),()=>{re.removeEventListener("wheel",Ke),F!==null&&cancelAnimationFrame(F),Y!==null&&cancelAnimationFrame(Y)}},[O]),E.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const re=F=>{var Re,Pe,ke,Me;if(Ue.current.readOnly)return;const Y=F.target;if(!(Y.tagName==="INPUT"||Y.tagName==="TEXTAREA"||Y.isContentEditable)){if((F.key==="z"||F.key==="Z")&&j(!Qe.current),(F.key==="m"||F.key==="M")&&k(!T),(F.key==="d"||F.key==="D")&&R(!M),(F.key==="v"||F.key==="V")&&!F.repeat&&!F.metaKey&&!F.ctrlKey&&!F.altKey&&Y.tagName!=="SELECT"&&A(!_),(F.key==="Delete"||F.key==="Backspace")&&_e.current){F.preventDefault();const ze=_e.current;(Pe=g.onEdgeDelete)==null||Pe.call(g,ze,((Re=ur.current.get(ze))==null?void 0:Re.data)??{id:ze}),v(null);return}if((F.key==="Delete"||F.key==="Backspace")&&we.current.length>0){F.preventDefault();const ze=we.current.filter(Ke=>Ke!=="root");if(ze.length===0)return;for(const Ke of ze){const Ge=(ke=Xe.current.get(Ke))==null?void 0:ke.data;(Me=g.onNodeDelete)==null||Me.call(g,Ke,Ge||{})}m([])}}};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[T,M,_,A,j,k,R,b.disableKeyboardShortcuts,g,m,v]);const sr=E.useCallback(re=>{var F;y.current=re,W(re),(F=g.onInit)==null||F.call(g,re)},[y,g]),Ee=E.useCallback(re=>{var F;return(F=g.onViewportChange)==null?void 0:F.call(g,re)},[g]),ut=E.useCallback(re=>{var Y,Re,Pe;const F=((Y=ur.current.get(re))==null?void 0:Y.data)??{id:re};if(_e.current===re&&He.current){v(null),(Re=g.onEdgeDeselect)==null||Re.call(g);return}we.current.length&&m([]),v(re),(Pe=g.onEdgeSelect)==null||Pe.call(g,re,F)},[g,v,m]),fr=E.useCallback(()=>{var re,F,Y;s(!0),(re=g.onBackgroundClick)==null||re.call(g),we.current.length&&(m([]),(F=g.onNodeDeselect)==null||F.call(g)),_e.current&&(v(null),(Y=g.onEdgeDeselect)==null||Y.call(g))},[g,m,v,s]),Pt=E.useCallback(re=>{var Re,Pe;const F=we.current,Y=re.filter(ke=>!F.includes(ke));if(Y.length){m([...F,...Y]);for(const ke of Y)(Pe=g.onNodeSelect)==null||Pe.call(g,ke,((Re=Xe.current.get(ke))==null?void 0:Re.data)??{id:ke})}},[g,m]),ie=E.useCallback((re,F)=>{var Y,Re;m([re]),(Re=g.onNodeSelect)==null||Re.call(g,re,((Y=Xe.current.get(re))==null?void 0:Y.data)??{id:re},F)},[g,m]),Fe=E.useCallback((re,F,Y)=>{var Re;return(Re=g.onEdgeCreate)==null?void 0:Re.call(g,re,F,Y)},[g]),Ze=E.useCallback((re,F,Y,Re=!1)=>{var Pe,ke;l==="properties"&&((Pe=g.onNodeCreateRequest)==null?void 0:Pe.call(g,{sourceNodeId:re,position:F,sourceProperty:Y,reverse:Re}))===!0||Y!==void 0||Re||(ke=g.onNodeCreate)==null||ke.call(g,{type:"text",sourceNodeId:re,position:F,isArrayMode:We.current})},[g,l]),Be=!b.readOnly&&_&&b.edgeHandles!==!1,lr=i==="transparent"?"none":i;return h.jsx(F_,{pattern:lr,backgroundColor:G,children:h.jsx(z.Box,{ref:q,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:h.jsx(__,{nodes:Ie,edges:Z,direction:U,nodeAlignment:c,onContainerCollapse:re=>{var F,Y;(F=g.onNodeCollapse)==null||F.call(g,re,!0),(Y=g.onNodeViewToggle)==null||Y.call(g,re)},selectedNodeIds:x,edgeMode:l,compactPropertyLayout:d,edgeType:b.edgeType,edgeRadius:o,customEdgeTypes:b.customEdgeTypes,edgeReveal:b.edgeReveal,rankSep:ne,edgeSep:ue,spacingFactor:Q,compactSpacingScale:n,layoutDebounce:qe,isPerformanceMode:V,minZoom:b.minZoom??.01,maxZoom:b.maxZoom??1.5,initialViewport:X,fitOnInit:!b.initialViewport,readOnly:!!b.readOnly,containerStyle:pe,lineColor:a?K:ye,drawMode:Be,drawHandles:!b.readOnly&&b.edgeHandles!==!1,dragMode:M,multiSelect:!!T,onInit:sr,onLayoutComplete:g.onLayoutComplete,animateViewport:b.animateViewport,onViewportChange:Ee,onBackgroundTap:fr,onBoxSelect:Pt,onEdgeSelect:ut,onContainerSelect:ie,onEdgeDraw:Fe,onDrawIntoSpace:Ze})})})},Wb=E.memo(z_),D_=".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 gy=!1;function V_(){if(gy||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=D_+C0+b0+x0+".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}',gy=!0}function W_({loading:e=!1,loader:t,...r}){var u,c;const[n,o]=E.useState(null),i=E.useMemo(()=>!!(n!=null&&n.json)&&!!r.json&&g0(n.json,r.json),[n==null?void 0:n.json,r.json]),s=n===null||n.json!==r.json&&!i,a=e||s;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||!s)return;let l;const d=requestAnimationFrame(()=>{l=requestAnimationFrame(()=>o(r))});return()=>{cancelAnimationFrame(d),l!==void 0&&cancelAnimationFrame(l)}},[e,s,r.json]),h.jsxs(z.Box,{className:r.className,style:r.style,width:"100%",height:"100%",position:"relative","aria-busy":a,children:[h.jsx("div",{style:{width:"100%",height:"100%"},ref:l=>{a?l==null||l.setAttribute("inert",""):l==null||l.removeAttribute("inert")},children:n&&h.jsx(G_,{...s?n:r,className:void 0,style:void 0})}),a&&t!==null&&h.jsx(z.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 G_({title:e="untitled",json:t,forms:r,nodes:n,edges:o,config:i={},callbacks:s={},className:a,style:u,showBottomBar:c=!0,children:l}){V_();const[d,f]=E.useState(),[p,y]=E.useState(!1),g=i.formSchema??d,b=E.useMemo(()=>t&&r?am(t,r.state):t,[t,r==null?void 0:r.state]),x=i.direction==="C",m=E.useMemo(()=>{let R,_;return A=>(_=R&&_?y0(R,A,_)??Su(A,{title:e,isCenter:x}):Su(A,{title:e,isCenter:x}),R=A,_)},[e,x]),w=E.useMemo(()=>b?m(b):null,[b,m]),v=E.useMemo(()=>r!=null&&r.structured&&!p&&g?l0(r.state,r.bindings,g,(w==null?void 0:w.nodes)??n??[]):void 0,[r==null?void 0:r.structured,p,r==null?void 0:r.state,r==null?void 0:r.bindings,g,w,n]),C=(v==null?void 0:v.schema)??g,S=(v==null?void 0:v.bindings)??(r==null?void 0:r.bindings),j=E.useMemo(()=>[...(w==null?void 0:w.nodes)??n??[],...(v==null?void 0:v.nodes)??[]].map(_=>{var ue,ne,Q,he;const A=t?(ue=je(t,_.data.id))==null?void 0:ue.$view:(ne=_.data.config)==null?void 0:ne.typeView,I=A&&Kt.includes(A)?A:void 0,q=I?I==="icon-label":(Q=_.data.config)==null?void 0:Q.labelBelow,O=I==="object"?"objectView":I==="text"?"text":q?"arrayView":_.data.type,W=C&&(r?nn(S,_.data.id,C):t&&_t(t,_.data.id,C)),V=(((he=_.data.config)==null?void 0:he.ports)??[]).map(le=>({...le}));if(v&&W){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[$,D]of Object.entries(W.type.ports??{})){const G=`${D.kind}:${$}`,N=V.find(ee=>ee.id===G);N?N.label===void 0&&D.label!==void 0&&(N.label=D.label):V.push({id:G,...D.label!==void 0?{label:D.label}:{},role:D.kind==="input"||D.kind==="config"?"target":"source",side:le[D.kind],...D.kind==="config"?{placement:"config"}:{}})}for(const $ of V){const D=V.filter(G=>G.side===$.side);$.position=(D.indexOf($)+1)/(D.length+1)}}return W||q||I?{..._,data:{..._.data,type:O,...r?{description:Object.fromEntries(Object.entries(_.data.description??{}).filter(([le])=>!le.startsWith("$")&&!(v!=null&&v.slots.has(Mt(_.data.id,le)))))}:{},config:{..._.data.config,...v&&W?{ports:V}:{},...W?{form:!0}:{},...I?{typeView:I,labelBelow:!!q}:q?{labelBelow:!0}:{}}}}:_}),[w,n,t,C,S,v,i.direction]),T=[...(w==null?void 0:w.edges)??o??[],...(v==null?void 0:v.edges)??[]],k=E.useMemo(()=>{const R=t&&w?jm(t,w.edges,s,s.onJsonChange,g):{...s};if(v){const _=new Set([...v.nodes.map(A=>A.data.id),...v.edges.map(A=>A.data.id)]);for(const A of Object.keys(R)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(A))continue;const I=R[A];R[A]=(q,...O)=>{if(!_.has(q))return I==null?void 0:I(q,...O)}}}return{...R,onAllNodesIconLabelChange:_=>{var A;y(_),(A=R.onAllNodesIconLabelChange)==null||A.call(R,_)}}},[t,w,s,g,v]),M=E.useMemo(()=>{if(!r)return k;let R=r.state;const _=I=>{if(i.readOnly||i.editable===!1)return;const q=r.onStateChange??r.onChange;if(!q)return;const O=n0(R,I,s.onFormChange);O!==R&&(R=O,q(O,{...I,data:O}))},A=(I,q,O)=>{var V;const W=t&&((V=je(t,I))==null?void 0:V[q]);return!W||typeof W.$state!="string"?!1:(_({address:W.$state,nodeAddress:I,previousValue:je(R,W.$state),value:O,data:R}),!0)};return{...k,onFormChange:_,onNodeCreateRequest:I=>{var W,V;const q=(W=I.sourceProperty)!=null&&W.startsWith("config:")?I.sourceProperty.slice(7):void 0,O=q!==void 0&&(v==null?void 0:v.slots.get(Mt(I.sourceNodeId,q)));return O?(O.present||_({data:R,nodeAddress:O.address.split(".").slice(0,-1).join("."),address:O.address,value:qt(O.type),previousValue:void 0}),!0):((V=k.onNodeCreateRequest)==null?void 0:V.call(k,I))??!1},onNodeDelete:(I,q)=>{var Q,he;if(!(v!=null&&v.nodes.some(le=>le.data.id===I)))return(Q=k.onNodeDelete)==null?void 0:Q.call(k,I,q);const O=v&&[...v.slots.values()].find(le=>le.nodeId===I);if(!O)return(he=k.onNodeDelete)==null?void 0:he.call(k,I,q);const W=O.address.split("."),V=W.pop(),ue=W.join("."),ne=je(R,ue);_(Array.isArray(ne)?{data:R,nodeAddress:ue,address:ue,previousValue:ne,value:ne.filter((le,$)=>String($)!==V)}:{data:R,nodeAddress:ue,address:O.address,previousValue:je(R,O.address),value:void 0})},onEdgeCreate:(I,q,O)=>{var ue,ne;const W=((ue=O==null?void 0:O.targetProperty)==null?void 0:ue.startsWith("config:"))&&(v==null?void 0:v.slots.get(Mt(q,O.targetProperty.slice(7)))),V=v==null?void 0:v.containers.get(I);if(W&&V&&(O==null?void 0:O.sourceProperty)==="output:resource"){const Q=u0(R,V,W);Q!==void 0&&_({data:R,nodeAddress:W.address.split(".").slice(0,-1).join("."),address:W.address,previousValue:je(R,W.address),value:Q});return}W||v!=null&&v.nodes.some(Q=>Q.data.id===I||Q.data.id===q)||(ne=k.onEdgeCreate)==null||ne.call(k,I,q,O)},onEdgeDelete:(I,q)=>{var he;const O=v==null?void 0:v.edges.find(le=>le.data.id===I);if(!O)return(he=k.onEdgeDelete)==null?void 0:he.call(k,I,q);const W=v.slots.get(Mt(O.data.target,O.data.targetProperty.slice(7))),V=W.address.split("."),ue=V.pop(),ne=V.join("."),Q=je(R,ne);_(Array.isArray(Q)?{data:R,nodeAddress:ne,address:ne,previousValue:Q,value:Q.filter((le,$)=>String($)!==ue)}:{data:R,nodeAddress:ne,address:W.address,previousValue:je(R,W.address),value:void 0})},onNodeContentChange:(I,q)=>{var O,W;A(I,"$content",q)?(O=s.onNodeContentChange)==null||O.call(s,I,q):(W=k.onNodeContentChange)==null||W.call(k,I,q)},onNodeLabelChange:(I,q)=>{var O,W;A(I,"$label",q)?(O=s.onNodeLabelChange)==null||O.call(s,I,q):(W=k.onNodeLabelChange)==null||W.call(k,I,q)}}},[k,r,t,s,v,i.readOnly,i.editable]);return h.jsx(Pr.Provider,{value:{data:(r==null?void 0:r.state)??t,viewData:t,bindings:S,references:r==null?void 0:r.references,structured:v,renderForm:r==null?void 0:r.renderForm,editable:r?!!(r.onStateChange??r.onChange):!!s.onJsonChange,schema:C,setSchema:R=>{var _;f(R),(_=s.onFormSchemaChange)==null||_.call(s,R)},callbacks:M},children:h.jsx(_y,{config:v?{...i,formSchema:C}:i,callbacks:M,nodes:j,edges:T,children:h.jsxs(z.Box,{className:a,"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(Wb,{nodes:j,edges:T}),c&&h.jsx(_m,{}),l]})})})}function U_(e){return Pu(JSON.parse(e))}function Pu(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 H_(e){return{replaceJson(t){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const r=Pu(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=Pu(t);return e.onStateChange(r,{address:"root",nodeAddress:"root",previousValue:e.state,value:r,data:r}),r}}}function K_(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,s)=>r(i,o[s])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,s])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i.startsWith("$")&&i!=="$")return JSON.stringify(s)===JSON.stringify(o[i])?[[i,s]]:[];const a=r(s,o[i]);return a===void 0?[]:[[i,a]]}))};return r(e,t)??{}}function pn(e){let t="",r=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},s=()=>{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{}},a=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(s,e.intervalMs??150))}};return{snapshot:a,append(u){a(t+u)},flush:s,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 J_(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=pn(e),i=0,s=!1,a=!1,u;const c=Math.max(1,Math.ceil(t.length*r/n)),l=()=>e.onChange({position:i,total:t.length,playing:s}),d=()=>{clearTimeout(u),u=void 0},f=(g=!1)=>{o.snapshot(t.slice(0,i)),i===t.length?(s=!1,d(),o.finish()):g&&o.flush()},p=g=>{s=!1,d(),o.cancel(),l(),e.onError(g)},y=()=>{if(u=void 0,!(!s||a)){i=Math.min(t.length,i+c);try{f()}catch(g){p(g);return}l(),s&&(u=setTimeout(y,r))}};return{play(){a||s||(i===t.length&&(o.cancel(),o=pn(e),i=0),s=!0,l(),u=setTimeout(y,r))},pause(){a||(s=!1,d(),o.flush(),l())},seek(g){if(!a){if(!Number.isFinite(g))throw new Error("Playback position must be finite.");d(),i=Math.max(0,Math.min(t.length,Math.round(g))),o.cancel(),o=pn(e);try{f(!0)}catch(b){p(b);return}l(),s&&(u=setTimeout(y,r))}},dispose(){a=!0,s=!1,d(),o.cancel()}}}function Z_({nodeAddress:e,expanded:t=!1}){var c;const{data:r,schema:n,bindings:o}=E.useContext(Pr),{colorText:i,background:s}=Ye();if((c=o==null?void 0:o[e])!=null&&c.portResources)return null;const a=o&&nn(o,e,n);if(!r||!a)return null;const u=je(r,a.address);return!u||typeof u!="object"?null:h.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:me(i),background:me(s),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(a.type.properties).map(l=>{const d=a.fields[l]??{};if(!En(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=_m;exports.CompactPropertyLayoutToggle=Uy;exports.ConnectionsOnlyToggle=p0;exports.DEFAULT_PALETTE=bn;exports.DiagramAppearanceControls=Ky;exports.DynamicIcon=kr;exports.EdgeTools=hm;exports.EditableLabel=rn;exports.ErrorToast=xm;exports.FlowDiagram=W_;exports.FlowDiagramProvider=_y;exports.FlowPort=Nb;exports.FlowView=Wb;exports.FormDocumentContext=Pr;exports.LIGHT_BLACK=wt;exports.NODE_TYPE_VIEWS=Kt;exports.NodeBorderRadiusControl=pm;exports.NodeConfigSummary=Z_;exports.NodeForm=cm;exports.NodeFormPopover=$b;exports.NodeIconPicker=zu;exports.NodeTools=gm;exports.NodeView=Un;exports.SvgExportButton=bm;exports.Swatches=vt;exports.TEXT_PALETTE=dm;exports.ToolbarCloseButton=Ct;exports.ToolbarCommitInput=nt;exports.ToolbarDivider=Ft;exports.ToolbarIconButton=Se;exports.ToolbarRangeInput=Hy;exports.ToolbarScrollContainer=vm;exports.ToolbarSelect=br;exports.ToolbarTooltip=Te;exports.TooltipIconButton=ku;exports.WorkflowControls=wm;exports.addChild=qu;exports.addConnection=Nu;exports.addTargetEdge=tm;exports.addressToPath=Mr;exports.applyCollapsed=e0;exports.applyFormChange=jn;exports.applyStateEdits=t0;exports.bindSqueedCallbacks=jm;exports.compileSqueed=Su;exports.connectionIssue=Fu;exports.contentObjTheme=Rr;exports.createFlowDiagram=tt;exports.createFlowDocumentActions=H_;exports.createFormNode=Em;exports.createJsonPlayback=J_;exports.createJsonStream=pn;exports.downloadSvg=mm;exports.exportSvg=ym;exports.formValueError=_r;exports.getChakraColorHex=me;exports.getColorVariant=vy;exports.getDarkerHexColor=gn;exports.getInteractionSurface=Vr;exports.getNode=je;exports.parseFlowDocument=U_;exports.parseJsonContract=$u;exports.parseTypeScriptContract=om;exports.parseTypeScriptForm=Lu;exports.projectJsonPlaybackPreview=K_;exports.readFormSchema=Bu;exports.readWorkflowContract=im;exports.removeEdge=nm;exports.removeNode=rm;exports.resolveEdgeOwner=Yt;exports.resolveStateView=am;exports.setCollapsed=Qy;exports.setEdgeProp=zr;exports.setEdgeStyle=em;exports.setNodeProp=cr;exports.updateNode=mr;exports.useCustomColors=Ye;exports.useEdgeProximity=by;exports.useFlowData=Hr;exports.useFlowDiagramContext=$e;exports.useNodeViewActions=Hn;exports.useStopPropagation=sl;exports.useThemeContentColors=tn;
228
274
  //# sourceMappingURL=index.cjs.map