@squeed/flow-sdk 2.0.15 → 2.0.16

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 ev=Object.create;var Xn=Object.defineProperty;var rv=Object.getOwnPropertyDescriptor;var tv=Object.getOwnPropertyNames;var nv=Object.getPrototypeOf,ov=Object.prototype.hasOwnProperty;var iv=(e,t,r)=>t in e?Xn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var av=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of tv(t))!ov.call(e,o)&&o!==r&&Xn(e,o,{get:()=>t[o],enumerable:!(n=rv(t,o))||n.enumerable});return e};var Ve=(e,t,r)=>(r=e!=null?ev(nv(e)):{},av(t||!e||!e.__esModule?Xn(r,"default",{value:e,enumerable:!0}):r,e));var Ir=(e,t,r)=>iv(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),B=require("@chakra-ui/react"),_=require("react"),K=require("react-icons/pi"),my=require("@emotion/react"),sv=require("@emotion/styled"),cv=require("react-icons/tb"),Ht=require("react-dom"),uv=require("markdown-to-jsx/react"),by=e=>e&&e.__esModule?e:{default:e},wn=by(sv),lv=by(uv);function vy({edge:e,enabled:t,bounds:r,inside:n=[],threshold:o=80}){const[i,a]=_.useState(!1),[s,c]=_.useState(!1),u=_.useRef(n);return u.current=n,_.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]),_.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;a(g||x)},d=()=>a(!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||s)}const wt="#c6c6c6";function gn(e,t=.2){const r=e.replace(/^#/,""),n=parseInt(r,16);let o=n>>16&255,i=n>>8&255,a=n&255;return o=Math.max(0,Math.floor(o*(1-t))),i=Math.max(0,Math.floor(i*(1-t))),a=Math.max(0,Math.floor(a*(1-t))),"#"+((1<<24)+(o<<16)+(i<<8)+a).toString(16).slice(1).toUpperCase()}function pl(e,t,r){const n=s=>{const c=/^#?([0-9a-f]{6})$/i.exec((s==null?void 0:s.trim())??"");return c?parseInt(c[1],16):null},o=n(e),i=n(t);if(o===null||i===null)return null;const a=s=>Math.round((o>>s&255)*(1-r)+(i>>s&255)*r);return"#"+((1<<24)+(a(16)<<16)+(a(8)<<8)+a(0)).toString(16).slice(1).toUpperCase()}const kr=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"},xy=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}},gl={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("#")||e!=null&&e.startsWith("var(--"))return e;if(!e)return"whitesmoke";const r=e.replace(/\./g,"-");try{const s=getComputedStyle(document.documentElement).getPropertyValue(`--chakra-colors-${r}`).trim();if(s&&s!=="")return s}catch{}const[n,o]=e.split(".");return n&&o&&((i=gl[n])!=null&&i[Number(o)])?gl[n][Number(o)]:`var(--chakra-colors-${r})`},dv=my.keyframes`
1
+ "use strict";var ev=Object.create;var Qn=Object.defineProperty;var rv=Object.getOwnPropertyDescriptor;var tv=Object.getOwnPropertyNames;var nv=Object.getPrototypeOf,ov=Object.prototype.hasOwnProperty;var iv=(e,t,r)=>t in e?Qn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var av=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of tv(t))!ov.call(e,o)&&o!==r&&Qn(e,o,{get:()=>t[o],enumerable:!(n=rv(t,o))||n.enumerable});return e};var Ve=(e,t,r)=>(r=e!=null?ev(nv(e)):{},av(t||!e||!e.__esModule?Qn(r,"default",{value:e,enumerable:!0}):r,e));var Or=(e,t,r)=>iv(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),F=require("@chakra-ui/react"),_=require("react"),K=require("react-icons/pi"),by=require("@emotion/react"),sv=require("@emotion/styled"),cv=require("react-icons/tb"),Kt=require("react-dom"),uv=require("markdown-to-jsx/react"),vy=e=>e&&e.__esModule?e:{default:e},Cn=vy(sv),lv=vy(uv);function xy({edge:e,enabled:t,bounds:r,inside:n=[],threshold:o=80}){const[i,a]=_.useState(!1),[s,c]=_.useState(!1),u=_.useRef(n);return u.current=n,_.useEffect(()=>{if(!t)return;const l=()=>{const h=document.querySelectorAll(':popover-open, dialog[open], [role="dialog"], [role="menu"], [role="listbox"]');c(Array.from(h).some(p=>p.getClientRects().length>0&&!p.closest('[hidden], [aria-hidden="true"], [data-state="closed"]')&&getComputedStyle(p).visibility==="visible"))},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]),_.useEffect(()=>{const l=h=>{var b;const p=(b=r.current)==null?void 0:b.getBoundingClientRect();if(!p)return;const g=h.target instanceof Node?h.target:null,m=!!g&&u.current.some(w=>{var x;return(x=w.current)==null?void 0:x.contains(g)}),y=e==="bottom"?p.bottom-h.clientY:h.clientY-p.top,v=h.clientX>=p.left&&h.clientX<=p.right&&y>=0&&y<=o;a(m||v)},d=()=>a(!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||s)}const Ct="#c6c6c6";function yn(e,t=.2){const r=e.replace(/^#/,""),n=parseInt(r,16);let o=n>>16&255,i=n>>8&255,a=n&255;return o=Math.max(0,Math.floor(o*(1-t))),i=Math.max(0,Math.floor(i*(1-t))),a=Math.max(0,Math.floor(a*(1-t))),"#"+((1<<24)+(o<<16)+(i<<8)+a).toString(16).slice(1).toUpperCase()}function gl(e,t,r){const n=s=>{const c=/^#?([0-9a-f]{6})$/i.exec((s==null?void 0:s.trim())??"");return c?parseInt(c[1],16):null},o=n(e),i=n(t);if(o===null||i===null)return null;const a=s=>Math.round((o>>s&255)*(1-r)+(i>>s&255)*r);return"#"+((1<<24)+(a(16)<<16)+(a(8)<<8)+a(0)).toString(16).slice(1).toUpperCase()}const Pr=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:yn(e,.1),border:yn(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"},wy=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let t=e;if(t!=null&&t.startsWith("#"))return{secondary:yn(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}},yl={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("#")||e!=null&&e.startsWith("var(--"))return e;if(!e)return"whitesmoke";const r=e.replace(/\./g,"-");try{const s=getComputedStyle(document.documentElement).getPropertyValue(`--chakra-colors-${r}`).trim();if(s&&s!=="")return s}catch{}const[n,o]=e.split(".");return n&&o&&((i=yl[n])!=null&&i[Number(o)])?yl[n][Number(o)]:`var(--chakra-colors-${r})`},dv=by.keyframes`
2
2
  0%, 100% { box-shadow: var(--flow-rest-shadow); }
3
3
  25%, 50% { box-shadow: var(--flow-hover-shadow); }
4
- `,fv=my.keyframes`
4
+ `,fv=by.keyframes`
5
5
  from { box-shadow: var(--flow-start-shadow); }
6
6
  to { box-shadow: var(--flow-rest-shadow); }
7
- `;function wy(e,t=!0,r="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,a=`0 0 0 ${t?8:0}px ${o}`,s=`0 0 0 8px ${o}`;return{boxShadow:a,css:{"--flow-rest-shadow":s,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[r]:{boxShadow:s,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${dv} 1200ms steps(10, end) 600ms`:"none"}}}}}}function Vr(e,t){const{boxShadow:r,css:n}=wy(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:`${fv} 600ms steps(5, end)`}}}}}const Cy=_.createContext(null),_y=_.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function Hr(){return _.useContext(_y)}function $e(){const e=_.useContext(Cy);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function Sy({config:e,callbacks:t,nodes:r=[],edges:n=[],children:o}){const i=_.useMemo(()=>{var Be,lr,re;const ae=new Map;for(const F of r)(Be=F.data)!=null&&Be.id&&ae.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:ae,edgeById:Fe,parentIds:Ze}},[r,n]),a=_.useRef(null),[s,c]=_.useState([]),[u,l]=_.useState(null),[d,f]=_.useState(!0),[p,y]=_.useState(!1),[g,b]=_.useState(!0),[x,m]=_.useState(!1),[w,v]=_.useState(!1),[C,S]=_.useState(!0),[j,T]=_.useState(!1),[P,M]=_.useState("auto"),[R,E]=_.useState(!1),k=e.compactPropertyLayout??R,[I,q]=_.useState({}),O=e.nodeViewModes??I,W=[...i.nodeById.values()].filter(ae=>{var Fe;return i.parentIds.has(ae.data.id)||((Fe=ae.data.config)==null?void 0:Fe.parentContainer)||ae.data.type==="objectView"||ae.data.type==="arrayView"}),V=!!W.length&&W.every(ae=>{var Fe,Ze,Be;return i.parentIds.has(ae.data.id)||(Fe=ae.data.config)!=null&&Fe.parentContainer?!!((Ze=ae.data.config)!=null&&Ze.collapsed):O[ae.data.id]==="icon-label"||((Be=ae.data.config)==null?void 0:Be.labelBelow)&&O[ae.data.id]!=="properties"}),[ue,ne]=_.useState("normal"),[Q,pe]=_.useState(),le=e.edgeRadius??Q,$=le!==void 0&&Number.isFinite(le)?Math.min(500,Math.max(0,le)):void 0,[D,G]=_.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,ye=e.backgroundVariant??D??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[fe,J]=_.useState(),Y=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:fe,[U,se]=_.useState("blue.500"),[te,xe]=_.useState(!1),ge=_.useRef(t);ge.current=t;const De=_.useMemo(()=>{const ae=Fe=>(...Ze)=>{var Be,lr;return(lr=(Be=ge.current)==null?void 0:Be[Fe])==null?void 0:lr.call(Be,...Ze)};return{onNodeSelect:ae("onNodeSelect"),onBackgroundClick:ae("onBackgroundClick"),onNodeDeselect:ae("onNodeDeselect"),onNodeDoubleClick:ae("onNodeDoubleClick"),onNodeViewToggle:ae("onNodeViewToggle"),onNodeTypeViewChange:ae("onNodeTypeViewChange"),onNodeCreate:ae("onNodeCreate"),onNodeCreateRequest:ae("onNodeCreateRequest"),onNodeDelete:ae("onNodeDelete"),onNodeLabelChange:ae("onNodeLabelChange"),onNodeContentChange:ae("onNodeContentChange"),onNodeCollapse:ae("onNodeCollapse"),onNodeColorChange:ae("onNodeColorChange"),onNodeBorderColorChange:ae("onNodeBorderColorChange"),onNodeBorderStyleChange:ae("onNodeBorderStyleChange"),onNodeBorderWidthChange:ae("onNodeBorderWidthChange"),onNodeBorderRadiusChange:ae("onNodeBorderRadiusChange"),onNodeIconChange:ae("onNodeIconChange"),onNodeOutlineChange:ae("onNodeOutlineChange"),onNodeAnimationChange:ae("onNodeAnimationChange"),onNodeAnimationVariantChange:ae("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:ae("onEdgeAnimationVariantChange"),onNodeHoverAction:ae("onNodeHoverAction"),onEdgeCreate:ae("onEdgeCreate"),onEdgeSelect:ae("onEdgeSelect"),onEdgeDeselect:ae("onEdgeDeselect"),onEdgeRemove:ae("onEdgeRemove"),onEdgeDelete:ae("onEdgeDelete"),onEdgeColorChange:ae("onEdgeColorChange"),onEdgeTypeChange:ae("onEdgeTypeChange"),onEdgeIconChange:ae("onEdgeIconChange"),onEdgeLabelChange:ae("onEdgeLabelChange"),onEdgeStyleChange:ae("onEdgeStyleChange"),onViewportChange:ae("onViewportChange"),onDirectionChange:ae("onDirectionChange"),onThemeColorChange:ae("onThemeColorChange"),onSpacingChange:ae("onSpacingChange"),onEdgeRadiusChange:ae("onEdgeRadiusChange"),onBackgroundVariantChange:ae("onBackgroundVariantChange"),onEdgeModeChange:ae("onEdgeModeChange"),onCompactPropertyLayoutChange:ae("onCompactPropertyLayoutChange"),onWorkflowContractChange:ae("onWorkflowContractChange"),onArrayModeChange:ae("onArrayModeChange"),onInit:ae("onInit"),onLayoutComplete:ae("onLayoutComplete"),onJsonChange:ae("onJsonChange")}},[]),Z=e.themeColor||U,[de,Ce]=_.useState(""),Oe=e.edgeColor??de,qe=e.colorMode||"light",Ue=e.direction||"LR",Qe=e.nodeAlignment??"center",We=e.edgeMode==="workflow"?"nodes":e.edgeMode??P,we=e.readOnly??!1,Se=JSON.stringify(e.parentNodeStyle??null),He=_.useMemo(()=>e.parentNodeStyle,[Se]),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=_.useRef(e);Ee.current=e;const ut=_.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=_.useCallback((ae,Fe)=>{var Ze;if(Fe!=="default"&&Fe!=="properties"&&Fe!=="icon-label")throw new Error("Unknown node view mode.");q(Be=>Be[ae]===Fe?Be:{...Be,[ae]:Fe}),(Ze=t.onNodeViewModeChange)==null||Ze.call(t,ae,Fe)},[t.onNodeViewModeChange]),Pt=_.useMemo(()=>({allNodesIconLabel:V,setAllNodesIconLabel:ae=>{var Fe,Ze,Be,lr,re;if(!ae)for(const[F,X]of Object.entries(O))X==="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)!==ae&&((Be=t.onNodeCollapse)==null||Be.call(t,F.data.id,ae)):fr(F.data.id,ae?"icon-label":(lr=F.data.config)!=null&&lr.labelBelow?"properties":"default");(re=t.onAllNodesIconLabelChange)==null||re.call(t,ae)},nodeViewModes:O,setNodeViewMode:fr,spacing:ee,setSpacing:ne,edgeRadius:$,setEdgeRadius:pe,backgroundVariant:ye,setBackgroundVariant:G,themeColor:Z,setThemeColor:se,backgroundSelected:te,setBackgroundSelected:xe,edgeColor:Oe,setEdgeColor:ae=>{var Fe;Ce(ae),(Fe=t.onGraphEdgeColorChange)==null||Fe.call(t,ae)},colorMode:qe,direction:Ue,nodeAlignment:Qe,edgeMode:We,setEdgeMode:M,compactPropertyLayout:k,setCompactPropertyLayout:E,workflowContract:Y,setWorkflowContract:J,parentNodeStyle:He,selectedNodeIds:s,setSelectedNodeIds:c,selectedEdgeId:u,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:a,callbacks:De,config:ut,readOnly:we}),[V,i,fr,t.onNodeCollapse,t.onAllNodesIconLabelChange,t.onGraphEdgeColorChange,O,t.onNodeViewModeChange,Z,ee,ye,$,e.backgroundColor,te,Oe,qe,Ue,Qe,We,Y,He,s,u,Xe,ur,sr,er,w,C,j,we,e.edgeHandles,e.edgeType,e.edgeReveal,e.animateViewport,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.compactPropertyLayout,k,De,ut]);return h.jsx(Cy.Provider,{value:Pt,children:h.jsx(_y.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}=xy(e),n=kr(t).background,o=kr(t).highlight,i=kr(t).border,a=kr(t).property,s=kr(t).property;let c=kr(t).background,u=kr(t).highlight;return c=e==="transparent"?e:me(c)+50,u=e==="transparent"?e:me(u)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:a,propertyColor:s,secondary:r,bgColorFaint:c,highlightColorFaint:u}}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"),a=ir(n,"gray.200","blackAlpha.400"),s=ir(n,"gray.200","blackAlpha.600"),c=ir(n,"gray.500","gray.700"),u=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=u,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:a,darkBackgroundSecondary:s,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 It=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(It||{});const Kt=["","icon-label","object","text"];var hv=typeof global=="object"&&global&&global.Object===Object&&global,pv=typeof self=="object"&&self&&self.Object===Object&&self,gv=hv||pv||Function("return this")(),mt=gv.Symbol,Ey=Object.prototype,yv=Ey.hasOwnProperty,mv=Ey.toString,At=mt?mt.toStringTag:void 0;function bv(e){var t=yv.call(e,At),r=e[At];try{e[At]=void 0;var n=!0}catch{}var o=mv.call(e);return n&&(t?e[At]=r:delete e[At]),o}var vv=Object.prototype,xv=vv.toString;function wv(e){return xv.call(e)}var Cv="[object Null]",_v="[object Undefined]",yl=mt?mt.toStringTag:void 0;function Sv(e){return e==null?e===void 0?_v:Cv:yl&&yl in Object(e)?bv(e):wv(e)}function Ev(e){return e!=null&&typeof e=="object"}var jv="[object Symbol]";function Rv(e){return typeof e=="symbol"||Ev(e)&&Sv(e)==jv}function kv(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,ml=mt?mt.prototype:void 0,bl=ml?ml.toString:void 0;function jy(e){if(typeof e=="string")return e;if(Ne(e))return kv(e,jy)+"";if(Rv(e))return bl?bl.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function Tu(e){return e==null?"":jy(e)}function Pv(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 Av(e,t,r){var n=e.length;return r=r===void 0?n:r,!t&&r>=n?e:Pv(e,t,r)}var Tv="\\ud800-\\udfff",Iv="\\u0300-\\u036f",Ov="\\ufe20-\\ufe2f",Mv="\\u20d0-\\u20ff",qv=Iv+Ov+Mv,Nv="\\ufe0e\\ufe0f",$v="\\u200d",Lv=RegExp("["+$v+Tv+qv+Nv+"]");function Ry(e){return Lv.test(e)}function Fv(e){return e.split("")}var ky="\\ud800-\\udfff",Bv="\\u0300-\\u036f",zv="\\ufe20-\\ufe2f",Dv="\\u20d0-\\u20ff",Vv=Bv+zv+Dv,Wv="\\ufe0e\\ufe0f",Gv="["+ky+"]",wu="["+Vv+"]",Cu="\\ud83c[\\udffb-\\udfff]",Uv="(?:"+wu+"|"+Cu+")",Py="[^"+ky+"]",Ay="(?:\\ud83c[\\udde6-\\uddff]){2}",Ty="[\\ud800-\\udbff][\\udc00-\\udfff]",Hv="\\u200d",Iy=Uv+"?",Oy="["+Wv+"]?",Kv="(?:"+Hv+"(?:"+[Py,Ay,Ty].join("|")+")"+Oy+Iy+")*",Jv=Oy+Iy+Kv,Zv="(?:"+[Py+wu+"?",wu,Ay,Ty,Gv].join("|")+")",Yv=RegExp(Cu+"(?="+Cu+")|"+Zv+Jv,"g");function Xv(e){return e.match(Yv)||[]}function Qv(e){return Ry(e)?Xv(e):Fv(e)}function ex(e){return function(t){t=Tu(t);var r=Ry(t)?Qv(t):void 0,n=r?r[0]:t.charAt(0),o=r?Av(r,1).join(""):t.slice(1);return n[e]()+o}}var rx=ex("toUpperCase");function tx(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 nx(e){return function(t){return e==null?void 0:e[t]}}var ox={À:"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"},ix=nx(ox),ax=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,sx="\\u0300-\\u036f",cx="\\ufe20-\\ufe2f",ux="\\u20d0-\\u20ff",lx=sx+cx+ux,dx="["+lx+"]",fx=RegExp(dx,"g");function hx(e){return e=Tu(e),e&&e.replace(ax,ix).replace(fx,"")}var px=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function gx(e){return e.match(px)||[]}var yx=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function mx(e){return yx.test(e)}var My="\\ud800-\\udfff",bx="\\u0300-\\u036f",vx="\\ufe20-\\ufe2f",xx="\\u20d0-\\u20ff",wx=bx+vx+xx,qy="\\u2700-\\u27bf",Ny="a-z\\xdf-\\xf6\\xf8-\\xff",Cx="\\xac\\xb1\\xd7\\xf7",_x="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Sx="\\u2000-\\u206f",Ex=" \\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",$y="A-Z\\xc0-\\xd6\\xd8-\\xde",jx="\\ufe0e\\ufe0f",Ly=Cx+_x+Sx+Ex,Fy="['’]",vl="["+Ly+"]",Rx="["+wx+"]",By="\\d+",kx="["+qy+"]",zy="["+Ny+"]",Dy="[^"+My+Ly+By+qy+Ny+$y+"]",Px="\\ud83c[\\udffb-\\udfff]",Ax="(?:"+Rx+"|"+Px+")",Tx="[^"+My+"]",Vy="(?:\\ud83c[\\udde6-\\uddff]){2}",Wy="[\\ud800-\\udbff][\\udc00-\\udfff]",dt="["+$y+"]",Ix="\\u200d",xl="(?:"+zy+"|"+Dy+")",Ox="(?:"+dt+"|"+Dy+")",wl="(?:"+Fy+"(?:d|ll|m|re|s|t|ve))?",Cl="(?:"+Fy+"(?:D|LL|M|RE|S|T|VE))?",Gy=Ax+"?",Uy="["+jx+"]?",Mx="(?:"+Ix+"(?:"+[Tx,Vy,Wy].join("|")+")"+Uy+Gy+")*",qx="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Nx="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",$x=Uy+Gy+Mx,Lx="(?:"+[kx,Vy,Wy].join("|")+")"+$x,Fx=RegExp([dt+"?"+zy+"+"+wl+"(?="+[vl,dt,"$"].join("|")+")",Ox+"+"+Cl+"(?="+[vl,dt+xl,"$"].join("|")+")",dt+"?"+xl+"+"+wl,dt+"+"+Cl,Nx,qx,By,Lx].join("|"),"g");function Bx(e){return e.match(Fx)||[]}function zx(e,t,r){return e=Tu(e),t=t,t===void 0?mx(e)?Bx(e):gx(e):e.match(t)||[]}var Dx="['’]",Vx=RegExp(Dx,"g");function Wx(e){return function(t){return tx(zx(hx(t).replace(Vx,"")),e,"")}}var br=Wx(function(e,t,r){return e+(r?" ":"")+rx(t)});function Te({label:e,children:t}){const r=_.cloneElement(t,{title:t.props.title??e});if(!B.Tooltip.Root){const n=B.Tooltip;return h.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:r})}return h.jsxs(B.Tooltip.Root,{positioning:{placement:"top"},children:[h.jsx(B.Tooltip.Trigger,{asChild:!0,children:r}),h.jsx(B.Portal,{children:h.jsx(B.Tooltip.Positioner,{children:h.jsx(B.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function Ft(){const{border:e}=Ye(),{colorMode:t}=$e();return h.jsx(B.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:t==="dark"?e:"gray.300"})}function vr({children:e,value:t,onValueChange:r,disabled:n,style:o,title:i,icon:a,popupContent:s,labelCase:c="title","aria-label":u,...l}){var R;const{colorMode:d}=$e(),{background:f,border:p,colorText:y,colorInactive:g}=Ye(),b=d==="dark",x=_.useId(),m=_.useRef(null),w=_.useRef(null),[v,C]=_.useState(!1);_.useEffect(()=>{const E=w.current;E.setAttribute("popover","auto");const k=I=>C(I.newState==="open");return E.addEventListener("toggle",k),()=>E.removeEventListener("toggle",k)},[]);const S=_.Children.toArray(e).filter(_.isValidElement).map(E=>{const k=E.props;return{value:String(k.value),label:typeof k.children=="string"&&c==="title"?br(k.children):k.children,disabled:k.disabled}}),j=()=>{var E;return(E=w.current)==null?void 0:E.hidePopover()},T=()=>{var W,V,ue,ne;const E=(W=m.current)==null?void 0:W.getBoundingClientRect(),k=w.current;if(!E||!k)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??E;k.style.maxHeight=`${Math.max(60,Math.max(q.top-40,window.innerHeight-q.bottom-40))}px`;const O=k.getBoundingClientRect();k.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`,k.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`},P=()=>{var I,q,O,W,V,ue;if(n)return;if((I=w.current)==null||I.showPopover(),T(),s){(O=(q=w.current)==null?void 0:q.querySelector("input"))==null||O.focus({preventScroll:!0});return}const E=(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)'))??(E==null?void 0:E[0]))==null||ue.focus()};_.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??u,children:h.jsx(B.chakra.button,{...l,ref:m,type:"button",role:"combobox","data-flow-select-icon":a?"":void 0,"aria-label":u,title:i??u,"aria-haspopup":s?"dialog":"listbox","aria-expanded":v,"aria-controls":x,disabled:n,h:"30px",w:"160px",px:"6px",fontSize:"12px",border:"none",borderRadius:"4px",bg:"transparent",color:a?g:y,display:"flex",alignItems:"center",justifyContent:a?"center":"space-between",gap:2,style:o,onClick:()=>v?j():P(),onKeyDown:E=>{["ArrowDown","ArrowUp"].includes(E.key)&&(E.preventDefault(),P())},children:a??h.jsxs(h.Fragment,{children:[h.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((R=S.find(E=>E.value===t))==null?void 0:R.label)??t}),h.jsx(K.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),h.jsx(B.chakra.div,{ref:w,id:x,role:s?"dialog":"listbox","aria-label":u,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:E=>{var q,O,W;if(s&&!["Escape","Tab"].includes(E.key))return;const k=[...E.currentTarget.querySelectorAll('[role="option"]:not(:disabled)')],I=k.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(E.key)){E.preventDefault();const V=E.key==="Home"?0:E.key==="End"?k.length-1:(I+(E.key==="ArrowDown"?1:-1)+k.length)%k.length;(q=k[V])==null||q.focus()}else E.key==="Escape"||E.key==="Tab"?(E.key==="Escape"&&(E.preventDefault(),E.stopPropagation()),j(),(O=m.current)==null||O.focus()):E.key.length===1&&E.key!==" "&&((W=k.find((V,ue)=>{var ne;return ue>I&&((ne=V.textContent)==null?void 0:ne.toLowerCase().startsWith(E.key.toLowerCase()))}))==null||W.focus())},children:s??S.map(E=>h.jsxs(B.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:y,_hover:{bg:b?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:b?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var k;j(),(k=m.current)==null||k.focus(),r(E.value)},children:[h.jsx("span",{style:{flex:1},children:E.label}),h.jsx(K.PiCheck,{size:16,color:`var(--chakra-colors-${y.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:E.value===t?"visible":"hidden"}})]},E.value))})]})}const _u={borderRadius:"4px","&:first-child":{borderTopLeftRadius:"22px",borderTopRightRadius:"22px"},"&:last-child":{borderBottomLeftRadius:"22px",borderBottomRightRadius:"22px"}},_e=_.forwardRef(function({icon:t,...r},n){const{colorMode:o}=$e();return h.jsx(B.IconButton,{ref:n,_hover:{bg:o==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:r.title??r["aria-label"],...r,children:t})}),Ct=_.forwardRef(function(t,r){const{themeColor:n}=$e();return h.jsx(Te,{label:"Close",children:h.jsx(_e,{ref:r,size:"sm",variant:"ghost",color:n,focusRingColor:n,...t,"aria-label":t["aria-label"]??"Close selection tools",icon:h.jsx(K.PiXLight,{size:20,"aria-hidden":"true"})})})});function Iu({label:e,icon:t,checked:r,onChange:n,disabled:o}){const{themeColor:i,readOnly:a}=$e(),{colorInactive:s}=Ye();return h.jsx(Te,{label:e,children:h.jsx(_e,{"aria-label":e,"aria-pressed":r,icon:h.jsxs(h.Fragment,{children:[t,h.jsx(B.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:s,disabled:o||a,onClick:()=>n(!r)})})}function Hy({label:e="Compact layout"}={}){const{compactPropertyLayout:t,setCompactPropertyLayout:r,callbacks:n}=$e();return h.jsx(Iu,{label:e,checked:t,icon:h.jsx(B.Icon,{as:K.PiArrowsIn,boxSize:5}),onChange:o=>{var i;r(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const Gx=wn.default.input`
7
+ `;function Cy(e,t=!0,r="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,a=`0 0 0 ${t?8:0}px ${o}`,s=`0 0 0 8px ${o}`;return{boxShadow:a,css:{"--flow-rest-shadow":s,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[r]:{boxShadow:s,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${dv} 1200ms steps(10, end) 600ms`:"none"}}}}}}function Vr(e,t){const{boxShadow:r,css:n}=Cy(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:`${fv} 600ms steps(5, end)`}}}}}const _y=_.createContext(null),Sy=_.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function Hr(){return _.useContext(Sy)}function qe(){const e=_.useContext(_y);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function Ey({config:e,callbacks:t,nodes:r=[],edges:n=[],children:o}){const i=_.useMemo(()=>{var Fe,dr,yr;const oe=new Map;for(const Z of r)(Fe=Z.data)!=null&&Fe.id&&oe.set(Z.data.id,Z);const Le=new Map;for(const Z of n)(dr=Z.data)!=null&&dr.id&&Le.set(Z.data.id,Z);const Ye=new Set;for(const Z of r)(yr=Z.data)!=null&&yr.parent&&Ye.add(Z.data.parent);return{nodeById:oe,edgeById:Le,parentIds:Ye}},[r,n]),a=_.useRef(null),[s,c]=_.useState([]),[u,l]=_.useState(null),[d,h]=_.useState(!0),[p,g]=_.useState(!1),[m,y]=_.useState(!0),[v,b]=_.useState(!1),[w,x]=_.useState(!1),[C,S]=_.useState(!0),[j,T]=_.useState(!1),[k,M]=_.useState("auto"),[R,E]=_.useState(!1),P=e.compactPropertyLayout??R,[I,q]=_.useState({}),O=e.nodeViewModes??I,V=[...i.nodeById.values()].filter(oe=>{var Le;return i.parentIds.has(oe.data.id)||((Le=oe.data.config)==null?void 0:Le.parentContainer)||oe.data.type==="objectView"||oe.data.type==="arrayView"}),W=!!V.length&&V.every(oe=>{var Le,Ye,Fe;return i.parentIds.has(oe.data.id)||(Le=oe.data.config)!=null&&Le.parentContainer?!!((Ye=oe.data.config)!=null&&Ye.collapsed):O[oe.data.id]==="icon-label"||((Fe=oe.data.config)==null?void 0:Fe.labelBelow)&&O[oe.data.id]!=="properties"}),[te,ne]=_.useState("normal"),[ee,be]=_.useState(),le=e.edgeRadius??ee,$=le!==void 0&&Number.isFinite(le)?Math.min(500,Math.max(0,le)):void 0,[z,G]=_.useState(),N=e.spacing??te,re=typeof N=="number"?Number.isFinite(N)?Math.min(2,Math.max(.5,N)):1:N==="compact"?.5:N==="spacious"?2:1,ye=e.backgroundVariant??z??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[de,J]=_.useState(),X=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:de,[U,ue]=_.useState("blue.500"),[se,we]=_.useState(!1),pe=_.useRef(t);pe.current=t;const ze=_.useMemo(()=>{const oe=Le=>(...Ye)=>{var Fe,dr;return(dr=(Fe=pe.current)==null?void 0:Fe[Le])==null?void 0:dr.call(Fe,...Ye)};return{onNodeSelect:oe("onNodeSelect"),onBackgroundClick:oe("onBackgroundClick"),onBottomBarCollapsedChange:oe("onBottomBarCollapsedChange"),onNodeDeselect:oe("onNodeDeselect"),onNodeDoubleClick:oe("onNodeDoubleClick"),onNodeViewToggle:oe("onNodeViewToggle"),onNodeTypeViewChange:oe("onNodeTypeViewChange"),onNodeCreate:oe("onNodeCreate"),onNodeCreateRequest:oe("onNodeCreateRequest"),onNodeDelete:oe("onNodeDelete"),onNodeLabelChange:oe("onNodeLabelChange"),onNodeContentChange:oe("onNodeContentChange"),onNodeCollapse:oe("onNodeCollapse"),onNodeColorChange:oe("onNodeColorChange"),onNodeBorderColorChange:oe("onNodeBorderColorChange"),onNodeBorderStyleChange:oe("onNodeBorderStyleChange"),onNodeBorderWidthChange:oe("onNodeBorderWidthChange"),onNodeBorderRadiusChange:oe("onNodeBorderRadiusChange"),onNodeIconChange:oe("onNodeIconChange"),onNodeOutlineChange:oe("onNodeOutlineChange"),onNodeAnimationChange:oe("onNodeAnimationChange"),onNodeAnimationVariantChange:oe("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:oe("onEdgeAnimationVariantChange"),onNodeHoverAction:oe("onNodeHoverAction"),onEdgeCreate:oe("onEdgeCreate"),onEdgeSelect:oe("onEdgeSelect"),onEdgeDeselect:oe("onEdgeDeselect"),onEdgeRemove:oe("onEdgeRemove"),onEdgeDelete:oe("onEdgeDelete"),onEdgeColorChange:oe("onEdgeColorChange"),onEdgeTypeChange:oe("onEdgeTypeChange"),onEdgeIconChange:oe("onEdgeIconChange"),onEdgeLabelChange:oe("onEdgeLabelChange"),onEdgeStyleChange:oe("onEdgeStyleChange"),onViewportChange:oe("onViewportChange"),onDirectionChange:oe("onDirectionChange"),onThemeColorChange:oe("onThemeColorChange"),onSpacingChange:oe("onSpacingChange"),onEdgeRadiusChange:oe("onEdgeRadiusChange"),onBackgroundVariantChange:oe("onBackgroundVariantChange"),onEdgeModeChange:oe("onEdgeModeChange"),onCompactPropertyLayoutChange:oe("onCompactPropertyLayoutChange"),onWorkflowContractChange:oe("onWorkflowContractChange"),onArrayModeChange:oe("onArrayModeChange"),onInit:oe("onInit"),onLayoutComplete:oe("onLayoutComplete"),onJsonChange:oe("onJsonChange")}},[]),Y=e.themeColor||U,[fe,_e]=_.useState(""),Ie=e.edgeColor??fe,Oe=e.colorMode||"light",Ue=e.direction||"LR",er=e.nodeAlignment??"center",De=e.edgeMode==="workflow"?"nodes":e.edgeMode??k,tr=e.readOnly??!1,he=JSON.stringify(e.parentNodeStyle??null),Re=_.useMemo(()=>e.parentNodeStyle,[he]),Ze=e.isZoomMode!==void 0?e.isZoomMode:d,lr=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,nr=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:v,He=e.isDragMode!==void 0?e.isDragMode:m,Ee=_.useRef(e);Ee.current=e;const ut=_.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 bottomBarCollapsed(){return Ee.current.bottomBarCollapsed},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}}),[]),hr=_.useCallback((oe,Le)=>{var Ye;if(Le!=="default"&&Le!=="properties"&&Le!=="icon-label")throw new Error("Unknown node view mode.");q(Fe=>Fe[oe]===Le?Fe:{...Fe,[oe]:Le}),(Ye=t.onNodeViewModeChange)==null||Ye.call(t,oe,Le)},[t.onNodeViewModeChange]),At=_.useMemo(()=>({allNodesIconLabel:W,setAllNodesIconLabel:oe=>{var Le,Ye,Fe,dr,yr;if(!oe)for(const[Z,D]of Object.entries(O))D==="icon-label"&&!i.nodeById.has(Z)&&hr(Z,"default");for(const Z of V)i.parentIds.has(Z.data.id)||(Le=Z.data.config)!=null&&Le.parentContainer?!tr&&!!((Ye=Z.data.config)!=null&&Ye.collapsed)!==oe&&((Fe=t.onNodeCollapse)==null||Fe.call(t,Z.data.id,oe)):hr(Z.data.id,oe?"icon-label":(dr=Z.data.config)!=null&&dr.labelBelow?"properties":"default");(yr=t.onAllNodesIconLabelChange)==null||yr.call(t,oe)},nodeViewModes:O,setNodeViewMode:hr,spacing:re,setSpacing:ne,edgeRadius:$,setEdgeRadius:be,backgroundVariant:ye,setBackgroundVariant:G,themeColor:Y,setThemeColor:ue,backgroundSelected:se,setBackgroundSelected:we,edgeColor:Ie,setEdgeColor:oe=>{var Le;_e(oe),(Le=t.onGraphEdgeColorChange)==null||Le.call(t,oe)},colorMode:Oe,direction:Ue,nodeAlignment:er,edgeMode:De,setEdgeMode:M,compactPropertyLayout:P,setCompactPropertyLayout:E,workflowContract:X,setWorkflowContract:J,parentNodeStyle:Re,selectedNodeIds:s,setSelectedNodeIds:c,selectedEdgeId:u,setSelectedEdgeId:l,isZoomMode:Ze,setIsZoomMode:h,isMultiSelectMode:lr,setIsMultiSelectMode:g,isDragMode:He,setIsDragMode:y,isEdgeHandlesEnabled:nr,setIsEdgeHandlesEnabled:b,isArrayNodeMode:w,setIsArrayNodeMode:x,isPinned:C,setIsPinned:S,isPerformanceMode:j,setIsPerformanceMode:T,engineRef:a,callbacks:ze,config:ut,readOnly:tr}),[W,i,hr,t.onNodeCollapse,t.onAllNodesIconLabelChange,t.onGraphEdgeColorChange,O,t.onNodeViewModeChange,Y,re,ye,$,e.backgroundColor,se,Ie,Oe,Ue,er,De,X,Re,s,u,Ze,lr,He,nr,w,C,j,tr,e.edgeHandles,e.edgeType,e.edgeReveal,e.animateViewport,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.bottomBarCollapsed,e.compactPropertyLayout,P,ze,ut]);return f.jsx(_y.Provider,{value:At,children:f.jsx(Sy.Provider,{value:i,children:o})})}function sr(e,t,r){return e?r:t}function nn(e){const[t]=(e==null?void 0:e.split("."))||[],{secondary:r}=wy(e),n=Pr(t).background,o=Pr(t).highlight,i=Pr(t).border,a=Pr(t).property,s=Pr(t).property;let c=Pr(t).background,u=Pr(t).highlight;return c=e==="transparent"?e:me(c)+50,u=e==="transparent"?e:me(u)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:a,propertyColor:s,secondary:r,bgColorFaint:c,highlightColorFaint:u}}function Xe(e=null){const{colorMode:t}=qe(),r=e==null?void 0:e.includes("gray"),n=t==="dark",o=sr(n,"white","gray.900"),i=sr(n,"gray.100","gray.800"),a=sr(n,"gray.200","blackAlpha.400"),s=sr(n,"gray.200","blackAlpha.600"),c=sr(n,"gray.500","gray.700"),u=sr(n,"gray.700","gray.700"),l=sr(n,"gray.900","gray.900"),d=sr(n,"gray.400","gray.500"),h=sr(n,"gray.400","gray.500"),p=sr(n,"gray.900","gray.200"),g=sr(n,r?"gray.900":"gray.200",r?"gray.200":"gray.900"),m=sr(n,"gray.900","gray.200"),y=sr(n,e&&"#000000",e||"#ffffff"),v=sr(n,e||"#ffffff",e?"#000000":"#ffffff"),b=u,w=sr(n,"gray.300","gray.800"),x=sr(n,"white","blackAlpha.400"),C=sr(n,"green.100","green.700");return{canvas:o,background:i,backgroundSecondary:a,darkBackgroundSecondary:s,border:c,darkColor:l,backgroundWhiteColor:x,borderSecondary:u,colorActive:d,colorInactive:h,iconColor:m,moreIconColor:b,colorText:p,themedColorText:g,logoColor:y,logoColorSecondary:v,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 Jt=["","icon-label","object","text"];var hv=typeof global=="object"&&global&&global.Object===Object&&global,pv=typeof self=="object"&&self&&self.Object===Object&&self,gv=hv||pv||Function("return this")(),bt=gv.Symbol,jy=Object.prototype,yv=jy.hasOwnProperty,mv=jy.toString,Tt=bt?bt.toStringTag:void 0;function bv(e){var t=yv.call(e,Tt),r=e[Tt];try{e[Tt]=void 0;var n=!0}catch{}var o=mv.call(e);return n&&(t?e[Tt]=r:delete e[Tt]),o}var vv=Object.prototype,xv=vv.toString;function wv(e){return xv.call(e)}var Cv="[object Null]",_v="[object Undefined]",ml=bt?bt.toStringTag:void 0;function Sv(e){return e==null?e===void 0?_v:Cv:ml&&ml in Object(e)?bv(e):wv(e)}function Ev(e){return e!=null&&typeof e=="object"}var jv="[object Symbol]";function Rv(e){return typeof e=="symbol"||Ev(e)&&Sv(e)==jv}function kv(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 Me=Array.isArray,bl=bt?bt.prototype:void 0,vl=bl?bl.toString:void 0;function Ry(e){if(typeof e=="string")return e;if(Me(e))return kv(e,Ry)+"";if(Rv(e))return vl?vl.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function Iu(e){return e==null?"":Ry(e)}function Pv(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 Av(e,t,r){var n=e.length;return r=r===void 0?n:r,!t&&r>=n?e:Pv(e,t,r)}var Tv="\\ud800-\\udfff",Iv="\\u0300-\\u036f",Ov="\\ufe20-\\ufe2f",Mv="\\u20d0-\\u20ff",qv=Iv+Ov+Mv,Nv="\\ufe0e\\ufe0f",$v="\\u200d",Lv=RegExp("["+$v+Tv+qv+Nv+"]");function ky(e){return Lv.test(e)}function Fv(e){return e.split("")}var Py="\\ud800-\\udfff",Bv="\\u0300-\\u036f",zv="\\ufe20-\\ufe2f",Dv="\\u20d0-\\u20ff",Vv=Bv+zv+Dv,Wv="\\ufe0e\\ufe0f",Gv="["+Py+"]",Cu="["+Vv+"]",_u="\\ud83c[\\udffb-\\udfff]",Uv="(?:"+Cu+"|"+_u+")",Ay="[^"+Py+"]",Ty="(?:\\ud83c[\\udde6-\\uddff]){2}",Iy="[\\ud800-\\udbff][\\udc00-\\udfff]",Hv="\\u200d",Oy=Uv+"?",My="["+Wv+"]?",Kv="(?:"+Hv+"(?:"+[Ay,Ty,Iy].join("|")+")"+My+Oy+")*",Jv=My+Oy+Kv,Zv="(?:"+[Ay+Cu+"?",Cu,Ty,Iy,Gv].join("|")+")",Yv=RegExp(_u+"(?="+_u+")|"+Zv+Jv,"g");function Xv(e){return e.match(Yv)||[]}function Qv(e){return ky(e)?Xv(e):Fv(e)}function ex(e){return function(t){t=Iu(t);var r=ky(t)?Qv(t):void 0,n=r?r[0]:t.charAt(0),o=r?Av(r,1).join(""):t.slice(1);return n[e]()+o}}var rx=ex("toUpperCase");function tx(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 nx(e){return function(t){return e==null?void 0:e[t]}}var ox={À:"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"},ix=nx(ox),ax=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,sx="\\u0300-\\u036f",cx="\\ufe20-\\ufe2f",ux="\\u20d0-\\u20ff",lx=sx+cx+ux,dx="["+lx+"]",fx=RegExp(dx,"g");function hx(e){return e=Iu(e),e&&e.replace(ax,ix).replace(fx,"")}var px=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function gx(e){return e.match(px)||[]}var yx=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function mx(e){return yx.test(e)}var qy="\\ud800-\\udfff",bx="\\u0300-\\u036f",vx="\\ufe20-\\ufe2f",xx="\\u20d0-\\u20ff",wx=bx+vx+xx,Ny="\\u2700-\\u27bf",$y="a-z\\xdf-\\xf6\\xf8-\\xff",Cx="\\xac\\xb1\\xd7\\xf7",_x="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Sx="\\u2000-\\u206f",Ex=" \\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",Ly="A-Z\\xc0-\\xd6\\xd8-\\xde",jx="\\ufe0e\\ufe0f",Fy=Cx+_x+Sx+Ex,By="['’]",xl="["+Fy+"]",Rx="["+wx+"]",zy="\\d+",kx="["+Ny+"]",Dy="["+$y+"]",Vy="[^"+qy+Fy+zy+Ny+$y+Ly+"]",Px="\\ud83c[\\udffb-\\udfff]",Ax="(?:"+Rx+"|"+Px+")",Tx="[^"+qy+"]",Wy="(?:\\ud83c[\\udde6-\\uddff]){2}",Gy="[\\ud800-\\udbff][\\udc00-\\udfff]",ft="["+Ly+"]",Ix="\\u200d",wl="(?:"+Dy+"|"+Vy+")",Ox="(?:"+ft+"|"+Vy+")",Cl="(?:"+By+"(?:d|ll|m|re|s|t|ve))?",_l="(?:"+By+"(?:D|LL|M|RE|S|T|VE))?",Uy=Ax+"?",Hy="["+jx+"]?",Mx="(?:"+Ix+"(?:"+[Tx,Wy,Gy].join("|")+")"+Hy+Uy+")*",qx="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Nx="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",$x=Hy+Uy+Mx,Lx="(?:"+[kx,Wy,Gy].join("|")+")"+$x,Fx=RegExp([ft+"?"+Dy+"+"+Cl+"(?="+[xl,ft,"$"].join("|")+")",Ox+"+"+_l+"(?="+[xl,ft+wl,"$"].join("|")+")",ft+"?"+wl+"+"+Cl,ft+"+"+_l,Nx,qx,zy,Lx].join("|"),"g");function Bx(e){return e.match(Fx)||[]}function zx(e,t,r){return e=Iu(e),t=t,t===void 0?mx(e)?Bx(e):gx(e):e.match(t)||[]}var Dx="['’]",Vx=RegExp(Dx,"g");function Wx(e){return function(t){return tx(zx(hx(t).replace(Vx,"")),e,"")}}var vr=Wx(function(e,t,r){return e+(r?" ":"")+rx(t)});function Ae({label:e,children:t}){const r=_.cloneElement(t,{title:t.props.title??e});if(!F.Tooltip.Root){const n=F.Tooltip;return f.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:r})}return f.jsxs(F.Tooltip.Root,{positioning:{placement:"top"},children:[f.jsx(F.Tooltip.Trigger,{asChild:!0,children:r}),f.jsx(F.Portal,{children:f.jsx(F.Tooltip.Positioner,{children:f.jsx(F.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function Bt(){const{border:e}=Xe(),{colorMode:t}=qe();return f.jsx(F.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:t==="dark"?e:"gray.300"})}function xr({children:e,value:t,onValueChange:r,disabled:n,style:o,title:i,icon:a,popupContent:s,labelCase:c="title","aria-label":u,...l}){var R;const{colorMode:d}=qe(),{background:h,border:p,colorText:g,colorInactive:m}=Xe(),y=d==="dark",v=_.useId(),b=_.useRef(null),w=_.useRef(null),[x,C]=_.useState(!1);_.useEffect(()=>{const E=w.current;E.setAttribute("popover","auto");const P=I=>C(I.newState==="open");return E.addEventListener("toggle",P),()=>E.removeEventListener("toggle",P)},[]);const S=_.Children.toArray(e).filter(_.isValidElement).map(E=>{const P=E.props;return{value:String(P.value),label:typeof P.children=="string"&&c==="title"?vr(P.children):P.children,disabled:P.disabled}}),j=()=>{var E;return(E=w.current)==null?void 0:E.hidePopover()},T=()=>{var V,W,te,ne;const E=(V=b.current)==null?void 0:V.getBoundingClientRect(),P=w.current;if(!E||!P)return;const I=(ne=(te=(W=b.current)==null?void 0:W.closest("[data-flow-toolbar-scroll]"))==null?void 0:te.parentElement)==null?void 0:ne.getBoundingClientRect(),q=I??E;P.style.maxHeight=`${Math.max(60,Math.max(q.top-40,window.innerHeight-q.bottom-40))}px`;const O=P.getBoundingClientRect();P.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`,P.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,V,W,te;if(n)return;if((I=w.current)==null||I.showPopover(),T(),s){(O=(q=w.current)==null?void 0:q.querySelector("input"))==null||O.focus({preventScroll:!0});return}const E=(V=w.current)==null?void 0:V.querySelectorAll('[role="option"]:not(:disabled)');(te=((W=w.current)==null?void 0:W.querySelector('[aria-selected="true"]:not(:disabled)'))??(E==null?void 0:E[0]))==null||te.focus()};_.useEffect(()=>{if(x){if(n){j();return}return window.addEventListener("resize",T),window.addEventListener("scroll",T,!0),()=>{window.removeEventListener("resize",T),window.removeEventListener("scroll",T,!0)}}},[x,n]);const M=`var(--chakra-colors-${h.replace(".","-")})`;return f.jsxs(f.Fragment,{children:[f.jsx(Ae,{label:i??u,children:f.jsx(F.chakra.button,{...l,ref:b,type:"button",role:"combobox","data-flow-select-icon":a?"":void 0,"aria-label":u,title:i??u,"aria-haspopup":s?"dialog":"listbox","aria-expanded":x,"aria-controls":v,disabled:n,h:"30px",w:"160px",px:"6px",fontSize:"12px",border:"none",borderRadius:"4px",bg:"transparent",color:a?m:g,display:"flex",alignItems:"center",justifyContent:a?"center":"space-between",gap:2,style:o,onClick:()=>x?j():k(),onKeyDown:E=>{["ArrowDown","ArrowUp"].includes(E.key)&&(E.preventDefault(),k())},children:a??f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((R=S.find(E=>E.value===t))==null?void 0:R.label)??t}),f.jsx(K.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),f.jsx(F.chakra.div,{ref:w,id:v,role:s?"dialog":"listbox","aria-label":u,position:"fixed",m:0,p:2,minW:"180px",maxW:"calc(100vw - 24px)",overflowY:"auto",bg:h,color:g,borderRadius:"30px",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"},'& [role="option"]':Su,'& details [role="option"]:first-child':{borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},...Vr(M,`var(--chakra-colors-${(y?p:"gray.300").replace(".","-")})`)},onKeyDown:E=>{var q,O,V;if(s&&!["Escape","Tab"].includes(E.key))return;const P=[...E.currentTarget.querySelectorAll('[role="option"]:not(:disabled)')],I=P.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(E.key)){E.preventDefault();const W=E.key==="Home"?0:E.key==="End"?P.length-1:(I+(E.key==="ArrowDown"?1:-1)+P.length)%P.length;(q=P[W])==null||q.focus()}else E.key==="Escape"||E.key==="Tab"?(E.key==="Escape"&&(E.preventDefault(),E.stopPropagation()),j(),(O=b.current)==null||O.focus()):E.key.length===1&&E.key!==" "&&((V=P.find((W,te)=>{var ne;return te>I&&((ne=W.textContent)==null?void 0:ne.toLowerCase().startsWith(E.key.toLowerCase()))}))==null||V.focus())},children:s??S.map(E=>f.jsxs(F.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:g,_hover:{bg:y?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:y?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var P;j(),(P=b.current)==null||P.focus(),r(E.value)},children:[f.jsx("span",{style:{flex:1},children:E.label}),f.jsx(K.PiCheck,{size:16,color:`var(--chakra-colors-${g.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:E.value===t?"visible":"hidden"}})]},E.value))})]})}const Su={borderRadius:"4px","&:first-child":{borderTopLeftRadius:"22px",borderTopRightRadius:"22px"},"&:last-child":{borderBottomLeftRadius:"22px",borderBottomRightRadius:"22px"}},Se=_.forwardRef(function({icon:t,...r},n){const{colorMode:o}=qe();return f.jsx(F.IconButton,{ref:n,_hover:{bg:o==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:r.title??r["aria-label"],...r,children:t})}),_t=_.forwardRef(function(t,r){const{themeColor:n}=qe();return f.jsx(Ae,{label:"Close",children:f.jsx(Se,{ref:r,size:"sm",variant:"ghost",color:n,focusRingColor:n,...t,"aria-label":t["aria-label"]??"Close selection tools",icon:f.jsx(K.PiXLight,{size:20,"aria-hidden":"true"})})})});function Ou({label:e,icon:t,checked:r,onChange:n,disabled:o}){const{themeColor:i,readOnly:a}=qe(),{colorInactive:s}=Xe();return f.jsx(Ae,{label:e,children:f.jsx(Se,{"aria-label":e,"aria-pressed":r,icon:f.jsxs(f.Fragment,{children:[t,f.jsx(F.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:s,disabled:o||a,onClick:()=>n(!r)})})}function Ky({label:e="Compact layout"}={}){const{compactPropertyLayout:t,setCompactPropertyLayout:r,callbacks:n}=qe();return f.jsx(Ou,{label:e,checked:t,icon:f.jsx(F.Icon,{as:K.PiArrowsIn,boxSize:5}),onChange:o=>{var i;r(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const Gx=Cn.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
- `,Ky=_.forwardRef(function({style:t,...r},n){return h.jsx(Gx,{...r,ref:n,style:{...t,backgroundImage:"none","--flow-range-track":(t==null?void 0:t.backgroundImage)??"none"}})});function _l({label:e,inputLabel:t,value:r,displayValue:n,min:o,max:i,onChange:a}){const s=_.useId(),{readOnly:c,themeColor:u}=$e(),{colorInactive:l}=Ye(),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:s,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",h.jsx("span",{children:n})]}),h.jsx(Ky,{id:s,"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=>a(Number(p.target.value))})]})}const Sl={dot:{label:"Dots",icon:K.PiDotsNine},grid:{label:"Grid",icon:K.PiGridFour},steel:{label:"Steel",icon:K.PiLineSegments},none:{label:"Solid",icon:K.PiSquareFill},transparent:{label:"Transparent",icon:K.PiSelection}};function Jy(){const{spacing:e,setSpacing:t,edgeRadius:r,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:a,readOnly:s}=$e(),c=Sl[o].icon;return h.jsxs(h.Fragment,{children:[h.jsx(Ft,{}),h.jsx(vr,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:h.jsx(K.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:s,onValueChange:()=>{},popupContent:h.jsx(_l,{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=a.onSpacingChange)==null||l.call(a,u/100)}}),children:h.jsx("option",{value:"spacing",children:"Spacing"})}),h.jsx(Ft,{}),h.jsx(vr,{"aria-label":"Edge radius",title:`Edge radius: ${r??"Default"}`,icon:h.jsx(K.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:s,onValueChange:()=>{},popupContent:h.jsx(_l,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:r??500,displayValue:r??"Default",onChange:u=>{var l;n(u),(l=a.onEdgeRadiusChange)==null||l.call(a,u)}}),children:h.jsx("option",{value:"radius",children:"Edge radius"})}),h.jsx(Ft,{}),h.jsxs(vr,{"aria-label":"Background variant",title:`Background: ${Sl[o].label}`,icon:h.jsx(c,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:s,onValueChange:u=>{var l;i(u),(l=a.onBackgroundVariantChange)==null||l.call(a,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 ar=[];for(let e=0;e<256;++e)ar.push((e+256).toString(16).slice(1));function Ux(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 Hx=new Uint8Array(16);function Kx(){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(Hx)}const Jx=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),El={randomUUID:Jx};function Ou(e,t,r){var o;if(El.randomUUID&&!e)return El.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??Kx();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,Ux(n)}const Cn={label:"Untitled",description:"",isTask:!1,isLocked:!1},Mu={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"}}},jl={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"}}},Zx={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"}}},Rl={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",Zy=e=>Array.isArray(e),Yx=["order","position","selected","locked","grabbed","grabbable","scratch"],Wr=e=>Object.entries(e).reduce((t,[r,n])=>(!yr(n)&&!r.startsWith("$")&&(t[r]=n),t),{}),qu=(e,t)=>typeof e=="string"&&e.startsWith("$")?eo(e,t):yr(e)&&!Zy(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("$")&&(Yx.includes(r)&&(r=r+"#"),t[r]=n),t),{}),et=(e,t,{label:r,parent:n=void 0},o,i=null)=>(i!==null&&(yr(i)||Zy(i))&&(i=JSON.stringify(i,null,2)),{data:{parent:n,...e.data,id:t,text:r||"",label:r,code:i||null,type:e.type,description:o}}),Dr=(e,t,r=null,n=null,o=null,i=!1,a=null)=>({data:{id:Ou(),source:o?t:e,target:o?e:t,label:n||"",isInverted:o,isEdgeAnimated:i,parent:a}}),Ur=(e,t=[])=>{const r={},n={};let o=[];if(e)for(const[i,a]of Object.entries(e))i.startsWith("$")&&i!=="$"?r[i.slice(1)]=a:i!=="$"?n[i]=a:i==="$"&&(o=a);return{newConfig:r,updatedObject:n,arrayObject:o}},pt=(e,t)=>{let r=jl;const{view:n,borderColor:o,borderRadius:i,bgColor:a,textColor:s,fontSize:c,stepType:u}=t;e=n||e,u?r={...Rl}:e==="object"?r=jl:e==="text"?r=Mu:e==="array"?r=Zx:e==="workflowStep"&&(r={...Rl});const l=r.data.viewProps;return r.data.viewProps={...l,borderRadius:i||(u?15:53),bgColor:a,borderColor:o,textColor:s,fontSize:c},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(s=>s.split(".").slice(-1)[0]===n||n===s);if(!o)return e;const i=Xx(o,r);return JSON.stringify(i).includes(e)?e:i||e}return e},Xx=(e,t)=>{let r=e.split(".").splice(1);return r=r[r.length-1]==="#"||r[r.length-1].includes("{")?r.slice(0,-2):r,(i=>r.reduce((a,s)=>{s=s.replace("[","").replace("]","");const{arrayObject:c}=Ur(a);return a=c.length?c:a,a[s]},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((a,s)=>{const c=Wr(a),u=Gr(a),{newConfig:l,arrayObject:d}=Ur(a);let f=`${t}.${s}`;yr(a)?Object.keys(c).length?(yt(c,f,r),Object.keys(u).length&&!Ne(a)&&Bt({chldPth:f,itrblObjct:u,nodes:r,path:t})):Object.keys(u).length&&!Ne(a)?Bt({chldPth:f,itrblObjct:u,nodes:r,path:t}):Ne(a)&&Yy({chldPth:f,item:a,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],a)=>{const s=Wr(i),c=Gr(i),{newConfig:u,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(s).length===0;if(f&&(pt("array",u),r.push(d)),Object.keys(s).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(c).length&&!Ne(i)?Bt({chldPth:d,itrblObjct:c,path:d,nodes:r}):yt(i,d,r)}else Ne(i)&&yt(i,d,r)}),Yy=({chldPth:e,item:t,nodes:r,path:n})=>t.forEach((o,i)=>{let a=`${e}.${i}`;const s=Gr(o),c=Wr(o);yr(o)?!Ne(o)&&Object.keys(c).length?yt(o,a,r):Object.keys(s).length&&!Ne(o)?Bt({chldPth:a,itrblObjct:s,path:n,nodes:r}):Ne(o)&&Yy({chldPth:a,item:o,nodes:r,path:n}):r.push(a)}),yn=[];let zt;function tt(e,t="root",r=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},a={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:r,edges:n};const s=e;if(!zt){const{nodes:l}=yt(e);zt={ids:l,jsnObjct:e}}let{hideDefaultObject:c,sprtObjctKy:u}=i;try{t=Jt(t,r);const{newConfig:l,arrayObject:d}=Ur(e),f=Object.keys(a).length>0?a: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(Mu,t,{label:g||t,parent:x},e,s));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(s)?{[o]:s}:s))}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 P=!1;Number.isNaN(Number(o))||(P=!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=qu(m,zt);const v=m,C=Wr(m),S=Gr(m),{newConfig:j,arrayObject:T}=Ur(m);T.length&&(m=T);const{config:P}=pt(typeof m=="string"?"text":"array",j),{hideConfig:M,sourceLabel:R,label:E,isEdgeAnimated:k,parent:I}=j;c=c||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,k)),tt(m,ue,r,n,E||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)?Xy({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,k)),r.push(et(P,ue,{label:E||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:a,newConfig:s,forceIsInverted:c=!1})=>{let{hideDefaultObject:u,sprtObjctKy:l}=t;return Object.entries(n).forEach(([d,f],p)=>{f=qu(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:P,isEdgeAnimated:M,parent:R}=x;u=u||w;const E=a==="root"&&t.isCntr,k=a.split(".").slice(0,2).join("."),I=yn.includes(k);c||(i=t.isCntr&&I||p%2===0&&E);let q=e?`${e}.${d}`:`${a}.${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(a,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&&!u){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(a,q,null,v,i,M)),tt(f,q,o,r,d,t,x))})},Xy=({flowConfig:e,chldPth:t,edges:r,isInverted:n,item:o,nodes:i,path:a})=>o.forEach((s,c)=>{let u=`${t}.${c}`;u=Jt(u,i);const l=s;s=qu(s,zt);const d=Gr(s),f=Wr(s),{newConfig:p}=Ur(s),{collapsed:y,label:g,parent:b,sourceLabel:x,isEdgeAnimated:m,content:w}=p;yr(s)?!Ne(s)&&Object.keys(f).length?(r.push(Dr(a,u,null,x,n,m)),tt(s,u,i,r,c,e,p)):Object.keys(d).length&&!Ne(s)&&!y?Dt({chldPth:u,flowConfig:e,itrblObjct:d,path:a,edges:r,nodes:i,isInverted:n,newConfig:p}):Ne(s)&&Xy({flowConfig:e,chldPth:u,edges:r,isInverted:n,item:s,nodes:i,path:a}):(r.push(Dr(a,u,null,x,n,m)),i.push(et(Mu,u,{label:g||String(s),parent:b},s,l)))});function Qx(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=je(e,f))!=null&&p.$collapsed)&&(l=f),d.add(f),f=(y=o.get(f))==null?void 0:y.data.parent;return l},a=new Map(t.nodes.map(u=>[u.data.id,i(u)])),s=t.nodes.filter(u=>a.get(u.data.id)===u.data.id).map(u=>{if(!r.has(u.data.id))return u;const l=je(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(s.map(u=>u.data.id));return{nodes:s,edges:t.edges.flatMap(u=>{const l=a.get(u.data.source),d=a.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 _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]),a=t.get(i)??0;return t.set(i,a+1),[{value:o,key:`${i}#${a}`,index:n}]})}function Qy(e,t,r){const n=_n(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:a,...s}=e;return s}function e0(e){const t=[],r=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,a)=>r(i,`${o}.${a}`));for(const i of _n(n)){const a=i.value;t.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:a.target,type:typeof a.type=="string"?a.type:void 0,sourceProperty:a.sourceProperty,targetProperty:a.targetProperty,icon:typeof a.icon=="string"?a.icon:void 0,label:typeof a.label=="string"?a.label:void 0,color:typeof a.color=="string"?a.color:void 0,isEdgeDashed:a.style==="dashed",isEdgeAnimated:a.style==="animated",...["dashed","traveling"].includes(a.animationVariant)?{edgeAnimationVariant:a.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,a])=>[i,i==="$"?r(a,o):i.startsWith("$")?a:r(a,`${o}.${i}`)]))};return{json:r(e,"root"),edges:t}}const Zt="root",kl=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Mr(e){const t=e.split(".");for(t[0]===Zt&&t.shift();t.length&&kl(t[t.length-1]);)t.pop();return t.filter(r=>!kl(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 r0(e){return Array.isArray(e)?[...e]:{...e}}function mr(e,t,r){const n=Mr(t),o=(i,a)=>{if(a===n.length)return r(i);const s=n[a],c=Sn(i);if(c==null||typeof c!="object")return i;const u=o(c[s],a+1);if(Object.is(u,c[s]))return i;const l=r0(c);return l[s]=u,c!==i?{...i,$:l}:l};return o(e,0)}function Or(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:Or(o,r,n))}const em=(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 s=t.connection;return mr(e,s.address,c=>Qy(c,s.key,u=>{if(r==="$edgeIcon")return Or(u,"icon",n);if(r==="$edgeType")return Or(u,"type",n);if(r==="$edgeAnimationVariant")return Or(u,"animationVariant",n);if(r==="$sourceLabel"||r==="$edgeColor")return Or(u,r==="$sourceLabel"?"label":"color",n);const l=r==="$isEdgeAnimated"?"animated":"dashed";return n?{...u,style:l}:u.style===l?Or(u,"style",void 0):u}))}const{address:o,kind:i}=Yt(t),a=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,s=>Or(s,a,n))}const rm=(e,t,r)=>zr(zr(e,t,"$isEdgeAnimated",r==="animated"||void 0),t,"$isEdgeDashed",r==="dashed"||void 0);function Nu(e,t,r,n){let o=n||"";const i=mr(e,t,s=>{const c=Sn(s);if(Array.isArray(c)){o=String(c.length);const l=[...c,r];return c===s?l:{...s,$:l}}const u=s!=null&&typeof s=="object"&&!Array.isArray(s)?{...s}:s!=null&&typeof s!="object"?{$label:String(s)}:{};if(!o){let l=1;for(;`node_${l}`in u;)l++;o=`node_${l}`}return u[o]=r,u}),a=Mr(t);return{json:i,address:[Zt,...a,o].join(".")}}function tm(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 a=Sn(i);if(a==null||typeof a!="object"||!Object.prototype.hasOwnProperty.call(a,n))return i;if(Array.isArray(a)){const u=a.filter((l,d)=>String(d)!==n);return a===i?u:{...i,$:u}}const{[n]:s,...c}=i;return c})}const nm=(e,t,r,n)=>cr(n?mr(e,t,o=>Or(o,"$targetLabel",n)):e,t,"$target",r);function $u(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=>Or(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...r,id:r.id||Ou()}]))}function om(e,t){if(t.connection){const i=t.connection;return _n(je(e,i.address)).some(a=>a.key===i.key)?{json:mr(e,i.address,a=>Qy(a,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:a,$targetLabel:s,...c}=i||{};return c}),removed:!0}}function Su(e,t={}){var x;const r=e0(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)),a=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!=="$")&&a.set(w,v)}const s=m=>a.get(m)??m,c=new Set(n.flatMap(m=>m.data.parent?[s(m.data.parent)]:[])),u=n.map(m=>{var T;const w=s(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(P=>!P.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 P=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:P}}return C.parent&&(C.parent=s(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=s(m.data.source),v=s(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),P=je(e,T.address);if(P&&typeof P=="object"){const M=P[T.kind==="target"?"$targetEdgeType":"$edgeType"];typeof M=="string"&&(j.type=M);const R=P[T.kind==="target"?"$targetIcon":"$edgeIcon"];typeof R=="string"&&(j.icon=R),P.$isEdgeAnimated!==void 0&&(j.isEdgeAnimated=!!P.$isEdgeAnimated);const E=P[T.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(E)&&(j.edgeAnimationVariant=E),P.$isEdgeDashed!==void 0&&(j.isEdgeDashed=!!P.$isEdgeDashed),P.$edgeColor&&(j.color=P.$edgeColor)}return{data:j}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const m=u.findIndex(w=>w.data.id===Zt);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=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=Qx(e,{nodes:u,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 t0(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]})),a=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;(a.get(u)??a.set(u,[]).get(u)).push(l)}const s=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=[...a.get(c)||[]];for(;u.length;){const l=u.pop();r.has(l)||s.has(l)||(s.add(l),u.push(...a.get(l)||[]))}}return{nodes:e.filter(c=>!s.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 s.has(u)||s.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 Lu(e,t){const r=JSON.parse(e);let n=512;const o=(a,s=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!a||typeof a!="object"||Array.isArray(a))throw new Error("Expected a JSON Schema object.");const 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(a))if(!c.has(l))throw new Error(`Unsupported JSON Schema keyword: ${l}`);const u=["$schema","$id","$defs","definitions","title","description","default","examples"];if(a.$ref){if(Object.keys(a).some(d=>!["$ref","title","description"].includes(d)))throw new Error("Use $ref without sibling constraints.");if(typeof a.$ref!="string"||!a.$ref.startsWith("#/")||s.includes(a.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let l=r;for(const d of a.$ref.slice(2).split("/")){const f=d.replace(/~1/g,"/").replace(/~0/g,"~");if(!l||!Object.prototype.hasOwnProperty.call(l,f))throw new Error(`Unresolved reference: ${a.$ref}`);l=l[f]}return o(l,[...s,a.$ref])}if(a.anyOf){if(!Array.isArray(a.anyOf)||!a.anyOf.length||Object.keys(a).some(l=>l!=="anyOf"&&!u.includes(l)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:a.anyOf.map(l=>o(l,s))}}if(Object.prototype.hasOwnProperty.call(a,"const")||a.enum){if(Object.keys(a).some(f=>![...u,"const","enum","type"].includes(f))||a.enum&&Object.prototype.hasOwnProperty.call(a,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const l=Object.prototype.hasOwnProperty.call(a,"const")?[a.const]:a.enum;if(!Array.isArray(l)||!l.length)throw new Error("Expected a nonempty enum.");return{kind:"union",types:l.map(f=>{if(f!==null&&!["string","number","boolean"].includes(typeof f))throw new Error("Only primitive literals are supported.");const p=f===null?"null":typeof f;if(a.type&&!(Array.isArray(a.type)?a.type:[a.type]).some(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(a.type)){if(!a.type.length||a.type.some(l=>typeof l!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(a).some(l=>l!=="type"&&!u.includes(l)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:a.type.map(l=>o({type:l},s))}}if((a.properties||a.required||a.additionalProperties!==void 0)&&a.type!=="object"&&a.type!==void 0)throw new Error("Object constraints require an object type.");if(a.items&&a.type!=="array")throw new Error("items requires an array type.");if(a.type==="object"||a.properties){if(a.additionalProperties!==void 0&&a.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!a.properties||typeof a.properties!="object"||Array.isArray(a.properties))throw new Error("Object schemas must declare properties.");if(a.required!==void 0&&(!Array.isArray(a.required)||a.required.some(d=>typeof d!="string"||!Object.prototype.hasOwnProperty.call(a.properties,d))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(a.properties).map(([d,f])=>[d,{type:o(f,s),optional:!(a.required??[]).includes(d)}]))}}if(a.type==="array")return{kind:"array",items:o(a.items,s)};if(["string","number","integer","boolean","null"].includes(a.type))return{kind:a.type};throw new Error("Every property must declare a supported type.")},i=o(r);if(i.kind!=="object")throw new Error("The root schema must be an object keyed by node ID.");if(Object.values(i.properties).some(a=>a.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:t,nodes:i.properties}}async function Fu(e,t,r,n={}){var y;let o=512;const i=await import("typescript"),a=i.createSourceFile(t,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),s=a.parseDiagnostics;if(s!=null&&s.length)throw new Error("Invalid TypeScript syntax.");const c=new Map;for(const g of a.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(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(P=>P.tagName.text==="port"):[];if(T.length>1)throw new Error(`Duplicate port declaration: ${S.name.text}`);if(T.length){const[P,M,R]=String(T[0].comment??"").trim().split(/\s+/);if(P!=="config"||!M||R||!c.has(M))throw new Error(`Config port ${S.name.text} requires @port config ResourceType`);const E=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:E}}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=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(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,...P]=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=P.length?JSON.parse(P.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 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(a)}`)},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 im(e,t){const r=await Fu(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 Ot(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=>Ot(r,t));if(t.kind==="union")return t.types.some(r=>Ot(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"?Ot(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)&&Ot(o.type,n.type):n.optional}):e.kind===t.kind}function Bu(e,t){if(!t.sourceProperty&&!t.targetProperty)return;const r=(a,s)=>{var l;const c=Object.prototype.hasOwnProperty.call(e.nodes,a)?a:a.replace(/^root\./,""),u=Object.prototype.hasOwnProperty.call(e.nodes,c)?(l=e.nodes[c])==null?void 0:l.type:void 0;return s&&(u==null?void 0:u.kind)==="object"&&Object.prototype.hasOwnProperty.call(u.properties,s)?u.properties[s]:void 0},n=r(t.source,t.sourceProperty),o=r(t.target,t.targetProperty);if(!n||!o)return"Unverified: source or target property is missing from the interface.";const i=a=>a.kind==="json"||a.kind==="object"&&(!!a.additionalProperties||Object.values(a.properties).some(s=>i(s.type)))||a.kind==="array"&&i(a.items)||a.kind==="union"&&a.types.some(i);if(i(n.type)||i(o.type))return"Unverified: arbitrary JSON or dictionary fields require runtime validation.";if(n.optional&&!o.optional)return"Optional source cannot supply a required target property.";if(!Ot(n.type,o.type))return`Incompatible property types: ${t.sourceProperty} -> ${t.targetProperty}.`}async function am(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 Lu(t,e.name);if(/\.ts$/i.test(e.name))return im(t,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Pl=new WeakMap;function bt(e){if(!e||typeof e!="object")return e;const t=Pl.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 a=Reflect.getOwnPropertyDescriptor(e,i);return a&&{...a,value:bt(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:r,deleteProperty:r,defineProperty:r,setPrototypeOf:r,preventExtensions:r});return Pl.set(e,n),n}function _t(e,t,r){var o;const n=t.split(".");for(let i=n.length;i>0;i--){const a=n.slice(0,i).join("."),s=(o=je(e,a))==null?void 0:o.$form;if(!(s!=null&&s.$type))continue;let c=Object.prototype.hasOwnProperty.call(r,s.$type)?r[s.$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(s.$fields??{}).filter(([d])=>!u||d.startsWith(`${u}.`)).map(([d,f])=>[u?d.slice(u.length+1):d,f]));return{type:c,fields:l,binding:s}}}async function zu(e,t){if(e.size>256*1024)throw new Error("Form schema exceeds 256 KB.");const r=await e.text();if(e.name.endsWith(".ts")){if(!t.length||t.length>32)throw new Error("Choose between 1 and 32 form interface names.");const o=[],i=new Set(t);for(const a of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const s=await Fu(r,e.name,a,{allowJson:!0});o.push([a,s]);for(const c of Object.values(s.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=Lu(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 Sr(e,t,r){if(t===void 0||t==="")return r?"Required":void 0;if(e.kind==="json"){const n=new Set,o=i=>{if(i===null||typeof i=="string"||typeof i=="boolean")return!0;if(typeof i=="number")return Number.isFinite(i);if(!i||typeof i!="object"||n.has(i)||!Array.isArray(i)&&![Object.prototype,null].includes(Object.getPrototypeOf(i)))return!1;n.add(i);const a=Object.values(i).every(o);return n.delete(i),a};return o(t)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!Sr(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=>!Sr(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)&&Sr(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>Sr(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 Al(e,t){const r=t.address.split(".");if(r.shift()!=="root"||!r.length||r.some(s=>!s||["__proto__","prototype","constructor","#"].includes(s)))throw new Error("Invalid form field address.");const n=r.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(r.some(s=>s.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...r].join("."),a=je(e,i);if(!a||typeof a!="object")throw new Error(`Missing form parent: ${i}`);if(o){if(t.op==="set"&&typeof t.value!="string")throw new Error("Node colors must be strings.");return cr(e,i,n,t.op==="remove"?void 0:t.value)}return mr(e,i,s=>{const c=Array.isArray(s.$)?s.$:s;if(t.op==="remove"&&!Object.prototype.hasOwnProperty.call(c,n)||t.op==="set"&&Object.is(c[n],t.value))return s;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===s?u:{...s,$:u}})}function jn(e,t,r){let n=Al(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=Al(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 n0(e){if(e.size>256*1024)throw new Error("SVG must be 256 KB or smaller.");const t=await e.text(),r=new DOMParser().parseFromString(t,"image/svg+xml");if(r.doctype||r.querySelector("parsererror")||r.documentElement.localName!=="svg"||r.documentElement.namespaceURI!=="http://www.w3.org/2000/svg")throw new Error("Choose a valid SVG file.");if(r.querySelector("script, foreignObject")||[...r.querySelectorAll("*")].some(i=>[...i.attributes].some(a=>/^on/i.test(a.name))))throw new Error("SVG scripts and event handlers are not allowed.");const n=new TextEncoder().encode(t);let o="";for(const i of n)o+=String.fromCharCode(i);return Wt+btoa(o)}const Pr=({name:e,svg:t=!1,...r})=>{const[n,o]=_.useState(null),[i,a]=_.useState(!0),[s,c]=_.useState(!1),u=typeof e=="string"&&Fr(e);if(_.useEffect(()=>{if(u||!e||e.length<2){o(null),a(!1);return}a(!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{a(!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 o0(e,t){let r=e;for(const n of t){if(n.op!=="set"&&n.op!=="remove")throw new Error("Unsupported state edit.");const o=n.address.split(".");if(o.some(a=>a.startsWith("$")||["__proto__","prototype","constructor"].includes(a)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;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 i0(e,t,r){Xt(t.value);const n=jn(e,t,r);return Xt(n),n}function sm(e,t){const r=(n,o="")=>{if(!n||typeof n!="object")return n;if(["$label","$subtitle","$content","$icon","$bgColor","$textColor","$borderColor"].includes(o)&&typeof n.$state=="string"){const a=je(t,n.$state);return a==null?"":typeof a=="object"?JSON.stringify(a,null,2):String(a)}let i=n;for(const[a,s]of Object.entries(n)){const c=r(s,a);c!==s&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,a,{value:c,enumerable:!0,writable:!0,configurable:!0}))}return i};return r(e)}const a0=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),s0=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 c0(e,t,r){if(t.address===r.address)return;const n=je(e,t.address),o=(i,a)=>a===void 0?!1:i.kind==="union"?i.types.some(s=>o(s,a)):i.kind==="array"?Array.isArray(a)&&a.every(s=>o(i.items,s)):i.kind==="object"?!!a&&typeof a=="object"&&!Array.isArray(a)&&Object.entries(i.properties).every(([s,c])=>c.optional&&a[s]===void 0||o(c.type,a[s]))&&Object.entries(a).every(([s,c])=>Object.prototype.hasOwnProperty.call(i.properties,s)||!i.additionalProperties||o(i.additionalProperties,c)):a===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!Sr(i,a,!0);if(o(r.type,n))return structuredClone(n)}function cm(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)),a=new Map(n.flatMap(l=>{const d=t[l.data.id];return d&&r[d.type]?[[d.address,l.data.id]]:[]})),s=(l,d,f,p,y,g=!1)=>{var j,T,P,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(E=>!Object.prototype.hasOwnProperty.call(x.properties,E)&&x.additionalProperties).map(E=>[E,{type:x.additionalProperties,optional:!0}]))}:x.kind==="array"?Object.fromEntries((Array.isArray(b)?b:[]).map((E,k)=>[String(k),{type:x.items,optional:!0}])):{value:{type:Vt(f)?f:x,optional:!1}};for(const[E,k]of Object.entries(S)){if(!a0(E))throw new Error(`Unsupported structured property key: ${E}`);const I=m?d:`${d}.${E}`,q=je(e,I),O=Qt(k.type,q),W=O.kind==="object"||O.kind==="array",V=(P=C.ports)==null?void 0:P[E],ue=(V==null?void 0:V.kind)==="config"&&(((M=v[E])==null?void 0:M.$options)||Vt(k.type)),ne=k.type.kind==="json"||k.type.kind==="union"&&!Vt(k.type);if(((R=v[E])==null?void 0:R.$control)==="upload"||!W&&x.kind!=="array"&&(!ne||m)||ue){C.properties[E]={...k,type:k.type.kind==="json"?O:k.type};continue}const Q=a.get(I)??s0(I),pe=x.kind==="array"?`Item ${Number(E)+1}`:E,le={address:I,owner:l,field:E,type:k.type,label:pe,nodeId:Q,present:q!==void 0};if(o.slots.set(Mt(l,E),le),C.ports[E]={kind:"config",resourceType:`__form:${Q}`},q===void 0||(o.edges.push({data:{id:`__form-edge:${l}:${E}`,source:Q,target:l,sourceProperty:"output:resource",targetProperty:`config:${E}`,isEdgeDashed:!0}}),o.containers.has(Q)||a.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:pe,headerTitle:pe,description:{},config:{form:!0,icon:O.kind==="array"?"PiListNumbers":W?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push($),s(Q,I,k.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||s(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}const rt=(e="reference")=>({kind:e,text:"",paths:[""]}),um=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(t=>["__proto__","constructor","prototype"].includes(t));function u0(e,t){const r=new Set(t.map(a=>a.path)),n=a=>{if(!a.paths.length||a.paths.some(s=>!um(s)||!r.has(s)))throw new Error("Choose an available reference.");return[...a.paths,...a.fallback===void 0?[]:[JSON.stringify(a.fallback)]].join(" || ")},o=a=>{if(a.includes("{{")||a.includes("}}"))throw new Error("Use a reference part for dynamic values.");return a},i=a=>a.map(s=>{if(s.kind==="text")return o(s.text);if(s.kind==="conditional"){if(s.paths.length!==1||s.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(s)}}}${o(s.text)}{{/if}}`}return`{{${n(s)}}}`}).join("");if(e.mode==="reference"||e.mode==="condition"){if(e.parts.length!==1||e.parts[0].kind!=="reference")throw new Error("Choose one reference binding.");const a=i(e.parts);return e.mode==="condition"?`${a} == ${JSON.stringify(e.comparison)}`:a}if(e.mode==="json"){const a=e.fields.map(s=>s.key);if(!a.length||new Set(a).size!==a.length||a.some(s=>!s||["__proto__","constructor","prototype"].includes(s)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(s=>[s.key,i(s.parts)])))}return i(e.parts)}async function l0(e){const t=await import("typescript"),r=a=>{const s=t.createSourceFile("binding.ts",`(${a})`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS);if(s.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const c=s.statements[0];if(!c||!t.isExpressionStatement(c))throw new Error("Unsupported reference expression.");const u=rt();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(s);if(!um(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=a=>{const s=[];let c=0;const u=/\{\{([\s\S]*?)\}\}/g;for(const l of a.matchAll(u)){const d=l.index;if(d<c)continue;d>c&&s.push({...rt("text"),text:a.slice(c,d)});const f=l[1].trim();if(f.startsWith("#if ")){const p=a.indexOf("{{/if}}",d+l[0].length);if(p<0)throw new Error("Unclosed condition.");s.push({...r(f.slice(4)),kind:"conditional",text:a.slice(d+l[0].length,p)}),c=p+7}else s.push(r(f)),c=d+l[0].length}return c<a.length&&s.push({...rt("text"),text:a.slice(c)}),s},o={mode:"reference",parts:[rt()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const a=JSON.parse(e);if(a&&typeof a=="object"&&!Array.isArray(a)&&Object.values(a).every(s=>typeof s=="string"))return{...o,mode:"json",fields:Object.entries(a).map(([s,c])=>({key:s,parts:n(c)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const a=t.createSourceFile("condition.ts",`value ${i[1].text}`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS),s=a.statements[0];if(a.statements.length===1&&t.isExpressionStatement(s)&&t.isBinaryExpression(s.expression)&&s.expression.operatorToken.kind===t.SyntaxKind.EqualsEqualsToken&&t.isStringLiteral(s.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:s.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function Il({parts:e,references:t,onChange:r,disabled:n}){const o=(i,a)=>r(e.map((s,c)=>c===i?{...s,...a}:s));return h.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,a)=>h.jsxs("fieldset",{"data-binding-part":a,style:{border:0,padding:0,margin:0,minWidth:0},children:[h.jsxs("legend",{children:["Part ",a+1]}),h.jsxs("div",{style:{display:"flex",gap:8},children:[h.jsxs("span",{"data-form-select":"",style:{flex:1},children:[h.jsxs("select",{"aria-label":"Part type",disabled:n,value:i.kind,onChange:s=>o(a,{kind:s.target.value}),children:[h.jsx("option",{value:"reference",children:"Reference"}),h.jsx("option",{value:"text",children:"Text"}),h.jsx("option",{value:"conditional",children:"Conditional text"})]}),h.jsx(K.PiCaretDown,{size:16,"aria-hidden":"true"})]}),h.jsx(_e,{"aria-label":`Remove part ${a+1}`,title:"Remove part",icon:h.jsx(K.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r(e.filter((s,c)=>c!==a))})]}),i.kind!=="text"&&h.jsxs(h.Fragment,{children:[i.paths.map((s,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:s,onChange:u=>o(a,{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(K.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},c)),i.kind==="reference"&&h.jsxs(h.Fragment,{children:[h.jsx(_e,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:h.jsx(K.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>o(a,{paths:[...i.paths,""]})}),h.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center"},children:[h.jsx("input",{type:"checkbox","aria-label":"Default value enabled",disabled:n,checked:i.fallback!==void 0,onChange:s=>o(a,{fallback:s.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&h.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:s=>o(a,{fallback:s.target.value})})]})]}),i.kind!=="reference"&&h.jsxs("label",{children:["Text",h.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:s=>o(a,{text:s.target.value})})]})]},a)),h.jsx(_e,{"aria-label":"Add part",title:"Add part",icon:h.jsx(K.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r([...e,rt()])})]})}function d0({label:e,value:t,references:r,disabled:n,onChange:o}){const[i,a]=_.useState(),[s,c]=_.useState(""),[u,l]=_.useState(!1),d=async()=>{l(!0),c("");try{a(await l0(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(_e,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:h.jsx(K.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=>a({...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(K.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=>a({...i,fields:i.fields.map((g,b)=>b===p?{...g,key:y.target.value}:g)})})]}),h.jsx(Il,{parts:f.parts,references:r,disabled:n,onChange:y=>a({...i,fields:i.fields.map((g,b)=>b===p?{...g,parts:y}:g)})}),h.jsx(_e,{"aria-label":"Remove output field",title:"Remove output field",icon:h.jsx(K.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>a({...i,fields:i.fields.filter((y,g)=>g!==p)})})]},p)),h.jsx(_e,{"aria-label":"Add output field",title:"Add output field",icon:h.jsx(K.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>a({...i,fields:[...i.fields,{key:"",parts:[rt()]}]})})]}):h.jsx(Il,{parts:i.parts,references:r,disabled:n,onChange:f=>a({...i,parts:f})}),i.mode==="condition"&&h.jsxs("label",{children:["Equals",h.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:f=>a({...i,comparison:f.target.value})})]}),h.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[h.jsx(_e,{"aria-label":"Apply binding",title:"Apply binding",icon:h.jsx(K.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(u0(i,r)),a(void 0),c("")}catch(f){c(f instanceof Error?f.message:"Unable to apply binding.")}}}),h.jsx(_e,{"aria-label":"Cancel binding",title:"Cancel binding",icon:h.jsx(K.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{a(void 0),c("")}})]})]}),s&&h.jsx("p",{role:"alert",children:s})]})}function f0({nodeAddress:e,onOpen:t}){const{structured:r,data:n,callbacks:o,editable:i,onFieldCreate:a}=_.useContext(xr),s=$e(),[c,u]=_.useState(""),[l,d]=_.useState("0"),[f,p]=_.useState(""),y=r==null?void 0:r.containers.get(e);if(!y||!n||!r)return null;const g=s.readOnly||s.config.editable===!1||!i,b=je(n,y.address),x=Tl(y.declared),m=y.type.kind==="array"?y.type.items:y.type.kind==="object"?y.type.additionalProperties:void 0,w=m?Tl(m):[],v=!!a&&y.type.kind==="object"&&(m==null?void 0:m.kind)==="json",C=k=>k.kind==="literal"?String(k.value):k.kind==="string"?"Text":br(k.kind),S=[...r.slots.values()].filter(k=>k.owner===e),j=(k,I)=>{var q;return(q=o.onFormChange)==null?void 0:q.call(o,{data:n,nodeAddress:y.address,address:k,previousValue:je(n,k),value:I})},T=k=>{var I;s.setSelectedNodeIds([k]),(I=s.engineRef.current)==null||I.focusNode(k,90,!1)},P=(k,I)=>{if(!Array.isArray(b))return;const q=[...b];[q[k],q[k+I]]=[q[k+I],q[k]],j(y.address,q)},M=()=>{const k=w[Number(l)]??w[0];if(k)if(y.type.kind==="array")j(y.address,[...Array.isArray(b)?b:[],qt(k)]);else{if(!c||c.includes(".")||c.startsWith("$")||["__proto__","constructor","prototype"].includes(c)){p("Choose a property name without dots or reserved prefixes.");return}if(Object.prototype.hasOwnProperty.call(b,c)){p("Property already exists.");return}v&&(l==="file"||l==="files")?a==null||a({data:n,nodeAddress:y.address,address:`${y.address}.${c}`,previousValue:void 0,value:l==="files"?[]:""},{$control:"upload"}):j(`${y.address}.${c}`,qt(k)),u(""),p("")}},R=y.type.kind==="object"&&!!y.type.additionalProperties,E=y.type.kind==="array";return h.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[x.length>1&&h.jsxs("label",{children:["Value type",h.jsx("span",{"data-form-select":"",style:{display:"block"},children:h.jsx(vr,{"aria-label":"Value type",disabled:g,value:String(x.findIndex(k=>Qt(k,b).kind===y.type.kind)),onValueChange:k=>j(y.address,qt(x[Number(k)])),children:x.map((k,I)=>h.jsx("option",{value:I,children:C(k)},I))})})]}),S.map((k,I)=>h.jsxs("div",{"data-structured-slot":k.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[k.type.kind==="array"?h.jsx(K.PiListNumbers,{size:20}):h.jsx(K.PiBracketsCurly,{size:20}),h.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:br(k.label)}),h.jsx(_e,{"aria-label":`${k.present?t?"Edit":"Focus":"Create"} ${br(k.label)}`,title:`${k.present?t?"Edit":"Focus":"Create"} ${br(k.label)}`,icon:k.present?h.jsx(K.PiMagnifyingGlass,{size:18}):h.jsx(K.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:g&&!k.present,onClick:q=>{var O;k.present?t?t(k.nodeId):((O=q.currentTarget.closest("dialog"))==null||O.close(),T(k.nodeId)):j(k.address,qt(k.type))}}),E&&h.jsxs(h.Fragment,{children:[h.jsx(_e,{"aria-label":`Move item ${I+1} up`,icon:h.jsx(K.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:g||I===0,onClick:()=>P(I,-1)}),h.jsx(_e,{"aria-label":`Move item ${I+1} down`,icon:h.jsx(K.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:g||I===S.length-1,onClick:()=>P(I,1)})]}),k.present&&h.jsx(_e,{"aria-label":`Remove ${br(k.label)}`,icon:h.jsx(K.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:g,onClick:()=>E?j(y.address,b.filter((q,O)=>O!==I)):j(k.address,void 0)})]},k.address)),(E||R)&&h.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[R&&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:c,disabled:g,onChange:k=>u(k.target.value)})]}),w.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(vr,{"aria-label":"New value type",value:l,disabled:g,onValueChange:d,children:[w.map((k,I)=>h.jsx("option",{value:I,children:C(k)},I)),v&&h.jsx("option",{value:"file",children:"File"}),v&&h.jsx("option",{value:"files",children:"Files"})]})})]}),h.jsx("span",{style:{display:"flex",alignItems:"center",flexShrink:0,...R||w.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:h.jsx(_e,{"aria-label":E?"Add item":"Add property",icon:h.jsx(K.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:g,onClick:M})})]}),f&&h.jsx("p",{role:"alert",children:f})]})}const xr=_.createContext({callbacks:{}}),ln=wn.default.div`
58
+ `,Jy=_.forwardRef(function({style:t,...r},n){return f.jsx(Gx,{...r,ref:n,style:{...t,backgroundImage:"none","--flow-range-track":(t==null?void 0:t.backgroundImage)??"none"}})});function Sl({label:e,inputLabel:t,value:r,displayValue:n,min:o,max:i,onChange:a}){const s=_.useId(),{readOnly:c,themeColor:u}=qe(),{colorInactive:l}=Xe(),d=(r-o)/(i-o)*100,h=u.includes(".")?`var(--chakra-colors-${u.replace(".","-")})`:u;return f.jsxs("div",{style:{width:224,maxWidth:"calc(100vw - 64px)",padding:12},children:[f.jsxs("label",{htmlFor:s,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",f.jsx("span",{children:n})]}),f.jsx(Jy,{id:s,"aria-label":t,type:"range",min:o,max:i,step:5,value:r,disabled:c,style:{color:h,accentColor:h,backgroundImage:`linear-gradient(to right, currentColor ${d}%, var(--chakra-colors-${l.replace(".","-")}) ${d}%)`},onChange:p=>a(Number(p.target.value))})]})}const El={dot:{label:"Dots",icon:K.PiDotsNine},grid:{label:"Grid",icon:K.PiGridFour},steel:{label:"Steel",icon:K.PiLineSegments},none:{label:"Solid",icon:K.PiSquareFill},transparent:{label:"Transparent",icon:K.PiSelection}};function Zy(){const{spacing:e,setSpacing:t,edgeRadius:r,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:a,readOnly:s}=qe(),c=El[o].icon;return f.jsxs(f.Fragment,{children:[f.jsx(Bt,{}),f.jsx(xr,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:f.jsx(K.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:s,onValueChange:()=>{},popupContent:f.jsx(Sl,{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=a.onSpacingChange)==null||l.call(a,u/100)}}),children:f.jsx("option",{value:"spacing",children:"Spacing"})}),f.jsx(Bt,{}),f.jsx(xr,{"aria-label":"Edge radius",title:`Edge radius: ${r??"Default"}`,icon:f.jsx(K.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:s,onValueChange:()=>{},popupContent:f.jsx(Sl,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:r??500,displayValue:r??"Default",onChange:u=>{var l;n(u),(l=a.onEdgeRadiusChange)==null||l.call(a,u)}}),children:f.jsx("option",{value:"radius",children:"Edge radius"})}),f.jsx(Bt,{}),f.jsxs(xr,{"aria-label":"Background variant",title:`Background: ${El[o].label}`,icon:f.jsx(c,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:s,onValueChange:u=>{var l;i(u),(l=a.onBackgroundVariantChange)==null||l.call(a,u)},children:[f.jsx("option",{value:"dot",children:"Dots"}),f.jsx("option",{value:"grid",children:"Grid"}),f.jsx("option",{value:"steel",children:"Steel"}),f.jsx("option",{value:"none",children:"Solid"}),f.jsx("option",{value:"transparent",children:"Transparent"})]})]})}const cr=[];for(let e=0;e<256;++e)cr.push((e+256).toString(16).slice(1));function Ux(e,t=0){return(cr[e[t+0]]+cr[e[t+1]]+cr[e[t+2]]+cr[e[t+3]]+"-"+cr[e[t+4]]+cr[e[t+5]]+"-"+cr[e[t+6]]+cr[e[t+7]]+"-"+cr[e[t+8]]+cr[e[t+9]]+"-"+cr[e[t+10]]+cr[e[t+11]]+cr[e[t+12]]+cr[e[t+13]]+cr[e[t+14]]+cr[e[t+15]]).toLowerCase()}let eo;const Hx=new Uint8Array(16);function Kx(){if(!eo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");eo=crypto.getRandomValues.bind(crypto)}return eo(Hx)}const Jx=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),jl={randomUUID:Jx};function Mu(e,t,r){var o;if(jl.randomUUID&&!e)return jl.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??Kx();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,Ux(n)}const _n={label:"Untitled",description:"",isTask:!1,isLocked:!1},qu={id:null,type:"text",data:{..._n,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"}}},Rl={id:null,type:"objectView",data:{..._n,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},Zx={id:null,type:"arrayView",data:{..._n,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"}}},kl={id:null,type:"workflowStep",data:{..._n,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},mr=e=>typeof e=="object",Yy=e=>Array.isArray(e),Yx=["order","position","selected","locked","grabbed","grabbable","scratch"],Wr=e=>Object.entries(e).reduce((t,[r,n])=>(!mr(n)&&!r.startsWith("$")&&(t[r]=n),t),{}),Nu=(e,t)=>typeof e=="string"&&e.startsWith("$")?ro(e,t):mr(e)&&!Yy(e)?Object.entries(e).reduce((r,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete r["..."],r[n]={...ro(o,t),...e}):typeof o=="string"&&o.startsWith("$")?r[n]=ro(o,t):r[n]=o,r),{}):e,Gr=e=>Object.entries(e).reduce((t,[r,n])=>(mr(n)&&r&&n&&!r.startsWith("$")&&(Yx.includes(r)&&(r=r+"#"),t[r]=n),t),{}),et=(e,t,{label:r,parent:n=void 0},o,i=null)=>(i!==null&&(mr(i)||Yy(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,a=null)=>({data:{id:Mu(),source:o?t:e,target:o?e:t,label:n||"",isInverted:o,isEdgeAnimated:i,parent:a}}),Ur=(e,t=[])=>{const r={},n={};let o=[];if(e)for(const[i,a]of Object.entries(e))i.startsWith("$")&&i!=="$"?r[i.slice(1)]=a:i!=="$"?n[i]=a:i==="$"&&(o=a);return{newConfig:r,updatedObject:n,arrayObject:o}},gt=(e,t)=>{let r=Rl;const{view:n,borderColor:o,borderRadius:i,bgColor:a,textColor:s,fontSize:c,stepType:u}=t;e=n||e,u?r={...kl}:e==="object"?r=Rl:e==="text"?r=qu:e==="array"?r=Zx:e==="workflowStep"&&(r={...kl});const l=r.data.viewProps;return r.data.viewProps={...l,borderRadius:i||(u?15:53),bgColor:a,borderColor:o,textColor:s,fontSize:c},r.data.config=t,{config:r}},Zt=(e,t)=>(e=t.find(n=>n.data.id===e)?`${e}.#`:e,e),ro=(e,{ids:t,jsnObjct:r})=>{if(typeof e=="string"&&(e!=null&&e.startsWith("$"))){const n=e.replace("$","").replace("*","");e==null||e.endsWith("*");const o=t.find(s=>s.split(".").slice(-1)[0]===n||n===s);if(!o)return e;const i=Xx(o,r);return JSON.stringify(i).includes(e)?e:i||e}return e},Xx=(e,t)=>{let r=e.split(".").splice(1);return r=r[r.length-1]==="#"||r[r.length-1].includes("{")?r.slice(0,-2):r,(i=>r.reduce((a,s)=>{s=s.replace("[","").replace("]","");const{arrayObject:c}=Ur(a);return a=c.length?c:a,a[s]},i))(t)};function mt(e,t="root",r=[]){try{const{arrayObject:n}=Ur(e);n.length&&(e=n);const o=Wr(e),i=Gr(e);return mr(e)?(Me(e)||Me(e)&&t==="root"||!Me(e)&&Object.keys(o).length||t==="root")&&r.push(t):r.push(t),Object.keys(i).length&&!Me(e)?zt({chldPth:null,itrblObjct:i,nodes:r,path:t}):Me(e)&&e.forEach((a,s)=>{const c=Wr(a),u=Gr(a),{newConfig:l,arrayObject:d}=Ur(a);let h=`${t}.${s}`;mr(a)?Object.keys(c).length?(mt(c,h,r),Object.keys(u).length&&!Me(a)&&zt({chldPth:h,itrblObjct:u,nodes:r,path:t})):Object.keys(u).length&&!Me(a)?zt({chldPth:h,itrblObjct:u,nodes:r,path:t}):Me(a)&&Xy({chldPth:h,item:a,nodes:r,path:t}):r.push(h)}),{nodes:r}}catch{return{nodes:r}}}const zt=({chldPth:e,itrblObjct:t,nodes:r,path:n})=>Object.entries(t).forEach(([o,i],a)=>{const s=Wr(i),c=Gr(i),{newConfig:u,arrayObject:l}=Ur(i);l.length&&(i=l),n.split(".").slice(0,2).join(".");let d=e?`${e}.${o}`:`${n}.${o}`;if(mr(i)&&!Me(i)){const h=Object.keys(s).length===0;if(h&&(gt("array",u),r.push(d)),Object.keys(s).length){const p=Me(i)?`${i.length||""}`:`{${Object.keys(i).length||""}}`;let g=d;h&&(g=`${d}.${p}`),mt(i,g,r)}else Object.keys(c).length&&!Me(i)?zt({chldPth:d,itrblObjct:c,path:d,nodes:r}):mt(i,d,r)}else Me(i)&&mt(i,d,r)}),Xy=({chldPth:e,item:t,nodes:r,path:n})=>t.forEach((o,i)=>{let a=`${e}.${i}`;const s=Gr(o),c=Wr(o);mr(o)?!Me(o)&&Object.keys(c).length?mt(o,a,r):Object.keys(s).length&&!Me(o)?zt({chldPth:a,itrblObjct:s,path:n,nodes:r}):Me(o)&&Xy({chldPth:a,item:o,nodes:r,path:n}):r.push(a)}),mn=[];let Dt;function tt(e,t="root",r=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},a={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:r,edges:n};const s=e;if(!Dt){const{nodes:l}=mt(e);Dt={ids:l,jsnObjct:e}}let{hideDefaultObject:c,sprtObjctKy:u}=i;try{t=Zt(t,r);const{newConfig:l,arrayObject:d}=Ur(e),h=Object.keys(a).length>0?a:l;d.length&&(e=d);const p=Wr(e),g=Gr(e),{label:m,collapsed:y,parent:v}=h;if(!mr(e))r.push(et(qu,t,{label:m||t,parent:v},e,s));else if(Me(e)||Me(e)&&t==="root"){const{config:b}=gt("array",h),w=Me(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,x=t==="root"?o:`${o} ${w}`;r.push(et(b,t,{label:m||x,parent:v},e,Me(s)?{[o]:s}:s))}else if(!Me(e)&&Object.keys(p).length||t==="root"){const{config:b}=gt(null,h),w=Me(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,x=t.split("."),C=x[x.length-1];let S=isNaN(Number(C))?null:Number(C)+1;const j=isNaN(Number(C))?C:x[x.length-2]+" "+S,T=t==="root"?o:j;let k=!1;Number.isNaN(Number(o))||(k=!0);const M=e;if(m){const{config:R}=gt("object",h);r.push(et(R,t,{label:m||`${m} ${w}`,parent:v},p,M))}else b.data.headerTitle=T,r.push(et(b,t,{label:m,parent:v},p,M))}return y||(Object.keys(g).length&&!Me(e)?Vt({flowConfig:i,chldPth:null,edges:n,isInverted:null,itrblObjct:g,nodes:r,path:t,newConfig:h}):Me(e)&&e.forEach((b,w)=>{b=Nu(b,Dt);const x=b,C=Wr(b),S=Gr(b),{newConfig:j,arrayObject:T}=Ur(b);T.length&&(b=T);const{config:k}=gt(typeof b=="string"?"text":"array",j),{hideConfig:M,sourceLabel:R,label:E,isEdgeAnimated:P,parent:I}=j;c=c||M;const q=t==="root"&&i.isCntr,O=t.split(".").slice(0,2).join("."),V=mn.includes(O),W=i.isCntr&&V||w%2===0&&q;let te=`${t}.${w}`;te=Zt(te,r),W&&mn.push(te),mr(b)?Object.keys(C).length&&!Me(b)?(n.push(Dr(t,te,null,R,W,P)),tt(b,te,r,n,E||w,i,j)):Object.keys(S).length&&!Me(b)?Vt({flowConfig:i,chldPth:te,isInverted:W,edges:n,itrblObjct:S,nodes:r,path:t,newConfig:j,forceIsInverted:!0}):Me(b)?Qy({flowConfig:i,chldPth:te,edges:n,isInverted:W,item:b,nodes:r,path:t}):mr(b)&&Vt({flowConfig:i,chldPth:te,isInverted:W,edges:n,itrblObjct:[b],nodes:r,path:t,newConfig:j}):(n.push(Dr(t,te,null,R,W,P)),r.push(et(k,te,{label:E||String(b),parent:I},b,x)))})),{nodes:r,edges:n}}catch{return{nodes:r,edges:n}}}const Vt=({chldPth:e,flowConfig:t,edges:r,itrblObjct:n,nodes:o,isInverted:i,path:a,newConfig:s,forceIsInverted:c=!1})=>{let{hideDefaultObject:u,sprtObjctKy:l}=t;return Object.entries(n).forEach(([d,h],p)=>{h=Nu(h,Dt);const g=h,m=Wr(h),y=Gr(h),{newConfig:v,arrayObject:b}=Ur(h);b.length&&(h=b);const{hideConfig:w,sourceLabel:x,label:C,content:S,target:j,targetLabel:T,collapsed:k,isEdgeAnimated:M,parent:R}=v;u=u||w;const E=a==="root"&&t.isCntr,P=a.split(".").slice(0,2).join("."),I=mn.includes(P);c||(i=t.isCntr&&I||p%2===0&&E);let q=e?`${e}.${d}`:`${a}.${d}`;if(q=Zt(q,o),i&&mn.push(q),j&&r.push(Dr(q,j,null,T,i,M)),mr(h)&&!Me(h)){r.push(Dr(a,q,null,x,i,M));const O=l||Object.keys(m).length===0;if(O){const V=S?"object":"array",{config:W}=gt(V,v);W.data.headerTitle=S?C:null,o.push(et(W,q,{label:C||d,parent:R},h,g))}if(Object.keys(m).length&&!u){const V=Me(h)?` ${h.length||""}`:`{${Object.keys(h).length||""}}`;let W=q;O&&(W=`${q}.${V}`,W=Zt(W,o),r.push(Dr(q,W,null,x,i,M))),tt(h,W,o,r,C||d,t,v)}else Object.keys(y).length&&!Me(h)?Vt({chldPth:q,flowConfig:t,itrblObjct:y,path:q,edges:r,nodes:o,newConfig:v,isInverted:i}):tt(h,q,o,r,d,t,v)}else Me(h)&&(r.push(Dr(a,q,null,x,i,M)),tt(h,q,o,r,d,t,v))})},Qy=({flowConfig:e,chldPth:t,edges:r,isInverted:n,item:o,nodes:i,path:a})=>o.forEach((s,c)=>{let u=`${t}.${c}`;u=Zt(u,i);const l=s;s=Nu(s,Dt);const d=Gr(s),h=Wr(s),{newConfig:p}=Ur(s),{collapsed:g,label:m,parent:y,sourceLabel:v,isEdgeAnimated:b,content:w}=p;mr(s)?!Me(s)&&Object.keys(h).length?(r.push(Dr(a,u,null,v,n,b)),tt(s,u,i,r,c,e,p)):Object.keys(d).length&&!Me(s)&&!g?Vt({chldPth:u,flowConfig:e,itrblObjct:d,path:a,edges:r,nodes:i,isInverted:n,newConfig:p}):Me(s)&&Qy({flowConfig:e,chldPth:u,edges:r,isInverted:n,item:s,nodes:i,path:a}):(r.push(Dr(a,u,null,v,n,b)),i.push(et(qu,u,{label:m||String(s),parent:y},s,l)))});function Qx(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,g;let l=u.data.id;const d=new Set([u.data.id]);let h=u.data.parent;for(;h&&!d.has(h);)r.has(h)&&o.has(h)&&((p=je(e,h))!=null&&p.$collapsed)&&(l=h),d.add(h),h=(g=o.get(h))==null?void 0:g.data.parent;return l},a=new Map(t.nodes.map(u=>[u.data.id,i(u)])),s=t.nodes.filter(u=>a.get(u.data.id)===u.data.id).map(u=>{if(!r.has(u.data.id))return u;const l=je(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(s.map(u=>u.data.id));return{nodes:s,edges:t.edges.flatMap(u=>{const l=a.get(u.data.source),d=a.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 Sn(e){if(!Array.isArray(e==null?void 0:e.$connections))return[];const t=new Map;return e.$connections.flatMap((r,n)=>{if(!r||typeof r!="object")return[];const o=r;if(typeof o.target!="string"||!/^root(?:\.|$)/.test(o.target))return[];if(o.sourceProperty!==void 0&&typeof o.sourceProperty!="string")return[];if(o.targetProperty!==void 0&&typeof o.targetProperty!="string")return[];const i=typeof o.id=="string"&&o.id?JSON.stringify(["id",o.id]):JSON.stringify(["ports",o.target,o.sourceProperty??null,o.targetProperty??null]),a=t.get(i)??0;return t.set(i,a+1),[{value:o,key:`${i}#${a}`,index:n}]})}function em(e,t,r){const n=Sn(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:a,...s}=e;return s}function e0(e){const t=[],r=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,a)=>r(i,`${o}.${a}`));for(const i of Sn(n)){const a=i.value;t.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:a.target,type:typeof a.type=="string"?a.type:void 0,sourceProperty:a.sourceProperty,targetProperty:a.targetProperty,icon:typeof a.icon=="string"?a.icon:void 0,label:typeof a.label=="string"?a.label:void 0,color:typeof a.color=="string"?a.color:void 0,isEdgeDashed:a.style==="dashed",isEdgeAnimated:a.style==="animated",...["dashed","traveling"].includes(a.animationVariant)?{edgeAnimationVariant:a.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,a])=>[i,i==="$"?r(a,o):i.startsWith("$")?a:r(a,`${o}.${i}`)]))};return{json:r(e,"root"),edges:t}}const Yt="root",Pl=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function qr(e){const t=e.split(".");for(t[0]===Yt&&t.shift();t.length&&Pl(t[t.length-1]);)t.pop();return t.filter(r=>!Pl(r))}function En(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function je(e,t){return qr(t).reduce((r,n)=>{var o;if(r!=null)return(o=En(r))==null?void 0:o[n]},e)}function r0(e){return Array.isArray(e)?[...e]:{...e}}function br(e,t,r){const n=qr(t),o=(i,a)=>{if(a===n.length)return r(i);const s=n[a],c=En(i);if(c==null||typeof c!="object")return i;const u=o(c[s],a+1);if(Object.is(u,c[s]))return i;const l=r0(c);return l[s]=u,c!==i?{...i,$:l}:l};return o(e,0)}function Mr(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 ur(e,t,r,n){return br(e,t,o=>r==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:Mr(o,r,n))}const rm=(e,t,r)=>ur(e,t,"$collapsed",r);function Xt(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=qr(r).join("."),i=qr(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 s=t.connection;return br(e,s.address,c=>em(c,s.key,u=>{if(r==="$edgeIcon")return Mr(u,"icon",n);if(r==="$edgeType")return Mr(u,"type",n);if(r==="$edgeAnimationVariant")return Mr(u,"animationVariant",n);if(r==="$sourceLabel"||r==="$edgeColor")return Mr(u,r==="$sourceLabel"?"label":"color",n);const l=r==="$isEdgeAnimated"?"animated":"dashed";return n?{...u,style:l}:u.style===l?Mr(u,"style",void 0):u}))}const{address:o,kind:i}=Xt(t),a=i==="target"&&r==="$sourceLabel"?"$targetLabel":i==="target"&&r==="$edgeType"?"$targetEdgeType":i==="target"&&r==="$edgeIcon"?"$targetIcon":i==="target"&&r==="$edgeAnimationVariant"?"$targetAnimationVariant":r;return br(e,o,s=>Mr(s,a,n))}const tm=(e,t,r)=>zr(zr(e,t,"$isEdgeAnimated",r==="animated"||void 0),t,"$isEdgeDashed",r==="dashed"||void 0);function $u(e,t,r,n){let o=n||"";const i=br(e,t,s=>{const c=En(s);if(Array.isArray(c)){o=String(c.length);const l=[...c,r];return c===s?l:{...s,$:l}}const u=s!=null&&typeof s=="object"&&!Array.isArray(s)?{...s}:s!=null&&typeof s!="object"?{$label:String(s)}:{};if(!o){let l=1;for(;`node_${l}`in u;)l++;o=`node_${l}`}return u[o]=r,u}),a=qr(t);return{json:i,address:[Yt,...a,o].join(".")}}function nm(e,t){const r=qr(t);if(!r.length)return e;const n=r[r.length-1],o=[Yt,...r.slice(0,-1)].join(".");return br(e,o,i=>{const a=En(i);if(a==null||typeof a!="object"||!Object.prototype.hasOwnProperty.call(a,n))return i;if(Array.isArray(a)){const u=a.filter((l,d)=>String(d)!==n);return a===i?u:{...i,$:u}}const{[n]:s,...c}=i;return c})}const om=(e,t,r,n)=>ur(n?br(e,t,o=>Mr(o,"$targetLabel",n)):e,t,"$target",r);function Lu(e,t,r){const n=je(e,t);return Sn(n).some(({value:i})=>i.target===r.target&&i.sourceProperty===r.sourceProperty&&i.targetProperty===r.targetProperty)?e:br(e,t,i=>Mr(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...r,id:r.id||Mu()}]))}function im(e,t){if(t.connection){const i=t.connection;return Sn(je(e,i.address)).some(a=>a.key===i.key)?{json:br(e,i.address,a=>em(a,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:r,kind:n}=Xt(t);return n==="hierarchy"?je(e,r)===void 0?{json:e,removed:!1}:{json:br(e,r,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:br(e,r,i=>{const{$target:a,$targetLabel:s,...c}=i||{};return c}),removed:!0}}function Eu(e,t={}){var v;const r=e0(e),{nodes:n,edges:o}=tt(r.json,Yt,[],[],t.title||"untitled",{hideDefaultObject:!!t.hideDefaultObject,sprtObjctKy:!!t.separateObjectKeys,isCntr:!!t.isCenter}),i=new Set(n.map(b=>b.data.id)),a=new Map;for(const b of n){const w=b.data.id;if(!w.endsWith(".0")||je(e,w)!==void 0)continue;const x=w.slice(0,-2),C=je(e,x);!i.has(x)&&C&&typeof C=="object"&&!Array.isArray(C)&&typeof C.$label=="string"&&Object.keys(C).every(S=>S.startsWith("$")&&S!=="$")&&a.set(w,x)}const s=b=>a.get(b)??b,c=new Set(n.flatMap(b=>b.data.parent?[s(b.data.parent)]:[])),u=n.map(b=>{var T;const w=s(b.data.id),x=je(e,w),C={...b.data,id:w},S=x&&typeof x=="object"&&!Array.isArray(x)&&"$"in x?x.$:x;if((Array.isArray(S)?S.length>0:S&&typeof S=="object"&&Object.keys(S).some(k=>!k.startsWith("$")))&&(C.config={...C.config,collapsed:!!x.$collapsed}),c.has(w)||(C.viewProps={...C.viewProps},delete C.viewProps.borderWidth),!x||typeof x!="object"||Array.isArray(x))return{data:C};if(x.$form&&typeof x.$form=="object"&&(C.config={...C.config,form:x.$form},C.type="objectView"),Array.isArray(x.$ports)){const k=x.$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=s(C.parent)),typeof x.$label=="string"&&(C.label=x.$label,C.headerTitle=x.$label),typeof x.$subtitle=="string"&&(C.config={...C.config,subtitle:x.$subtitle}),typeof x.$outline=="boolean"&&(C.viewProps={...C.viewProps,outline:x.$outline}),["solid","dashed","dotted","double"].includes(x.$borderStyle)&&(C.viewProps={...C.viewProps,borderStyle:x.$borderStyle}),Number.isFinite(x.$borderWidth)&&x.$borderWidth>=0&&(C.viewProps={...C.viewProps,borderWidth:x.$borderWidth}),Number.isFinite(x.$borderRadius)&&x.$borderRadius>=0&&(C.viewProps={...C.viewProps,borderRadius:x.$borderRadius}),typeof x.$isNodeAnimated=="boolean"&&(C.isNodeAnimated=x.$isNodeAnimated),["traveling","pulse"].includes(x.$nodeAnimationVariant)&&(C.nodeAnimationVariant=x.$nodeAnimationVariant),typeof x.$content=="string"&&(C.config={...C.config,content:x.$content},x.$view||(C.type="objectView")),(((T=C.config)==null?void 0:T.collapsed)!==void 0||x.$collapsed!==void 0||x.$icon!==void 0)&&(C.config={...C.config||{}},(x.$collapsed!==void 0||C.config.collapsed!==void 0)&&(C.config.collapsed=!!x.$collapsed),x.$icon!==void 0&&(C.config.icon=x.$icon)),{data:C}}),l=new Map,d=o.map(b=>{const w=s(b.data.source),x=s(b.data.target),C=`${w}->${x}`,S=l.get(C)??0;l.set(C,S+1);const j={...b.data,id:S?`${C}#${S}`:C,source:w,target:x},T=Xt(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 E=k[T.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(E)&&(j.edgeAnimationVariant=E),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 b=u.findIndex(w=>w.data.id===Yt);b!==-1&&u.splice(b,1)}const h=new Set(u.map(b=>b.data.id));for(let b=d.length-1;b>=0;b--){const w=d[b].data,x=Xt(w);(!h.has(w.source)||!h.has(w.target)||x.kind==="hierarchy"&&((v=je(e,x.address))==null?void 0:v.$hideParentEdge)===!0)&&d.splice(b,1)}d.push(...r.edges.filter(b=>h.has(b.data.source)&&h.has(b.data.target)));const p=Qx(e,{nodes:u,edges:d}),g=p.nodes.filter(b=>{var w;return(w=b.data.config)==null?void 0:w.collapsed}).map(b=>qr(b.data.id));if(!g.length)return p;const m=p.nodes.filter(b=>{const w=qr(b.data.id);return!g.some(x=>x.length<w.length&&x.every((C,S)=>C===w[S]))}),y=new Set(m.map(b=>b.data.id));return{nodes:m,edges:p.edges.filter(b=>y.has(b.data.source)&&y.has(b.data.target))}}function t0(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 h;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=(h=n.get(l))==null?void 0:h.data.parent;return[c.data.id,u]})),a=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;(a.get(u)??a.set(u,[]).get(u)).push(l)}const s=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=[...a.get(c)||[]];for(;u.length;){const l=u.pop();r.has(l)||s.has(l)||(s.add(l),u.push(...a.get(l)||[]))}}return{nodes:e.filter(c=>!s.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 s.has(u)||s.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 Fu(e,t){const r=JSON.parse(e);let n=512;const o=(a,s=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!a||typeof a!="object"||Array.isArray(a))throw new Error("Expected a JSON Schema object.");const 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(a))if(!c.has(l))throw new Error(`Unsupported JSON Schema keyword: ${l}`);const u=["$schema","$id","$defs","definitions","title","description","default","examples"];if(a.$ref){if(Object.keys(a).some(d=>!["$ref","title","description"].includes(d)))throw new Error("Use $ref without sibling constraints.");if(typeof a.$ref!="string"||!a.$ref.startsWith("#/")||s.includes(a.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let l=r;for(const d of a.$ref.slice(2).split("/")){const h=d.replace(/~1/g,"/").replace(/~0/g,"~");if(!l||!Object.prototype.hasOwnProperty.call(l,h))throw new Error(`Unresolved reference: ${a.$ref}`);l=l[h]}return o(l,[...s,a.$ref])}if(a.anyOf){if(!Array.isArray(a.anyOf)||!a.anyOf.length||Object.keys(a).some(l=>l!=="anyOf"&&!u.includes(l)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:a.anyOf.map(l=>o(l,s))}}if(Object.prototype.hasOwnProperty.call(a,"const")||a.enum){if(Object.keys(a).some(h=>![...u,"const","enum","type"].includes(h))||a.enum&&Object.prototype.hasOwnProperty.call(a,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const l=Object.prototype.hasOwnProperty.call(a,"const")?[a.const]:a.enum;if(!Array.isArray(l)||!l.length)throw new Error("Expected a nonempty enum.");return{kind:"union",types:l.map(h=>{if(h!==null&&!["string","number","boolean"].includes(typeof h))throw new Error("Only primitive literals are supported.");const p=h===null?"null":typeof h;if(a.type&&!(Array.isArray(a.type)?a.type:[a.type]).some(g=>g===p||g==="integer"&&Number.isInteger(h)))throw new Error("Literal does not match its declared type.");return{kind:"literal",value:h}})}}if(Array.isArray(a.type)){if(!a.type.length||a.type.some(l=>typeof l!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(a).some(l=>l!=="type"&&!u.includes(l)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:a.type.map(l=>o({type:l},s))}}if((a.properties||a.required||a.additionalProperties!==void 0)&&a.type!=="object"&&a.type!==void 0)throw new Error("Object constraints require an object type.");if(a.items&&a.type!=="array")throw new Error("items requires an array type.");if(a.type==="object"||a.properties){if(a.additionalProperties!==void 0&&a.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!a.properties||typeof a.properties!="object"||Array.isArray(a.properties))throw new Error("Object schemas must declare properties.");if(a.required!==void 0&&(!Array.isArray(a.required)||a.required.some(d=>typeof d!="string"||!Object.prototype.hasOwnProperty.call(a.properties,d))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(a.properties).map(([d,h])=>[d,{type:o(h,s),optional:!(a.required??[]).includes(d)}]))}}if(a.type==="array")return{kind:"array",items:o(a.items,s)};if(["string","number","integer","boolean","null"].includes(a.type))return{kind:a.type};throw new Error("Every property must declare a supported type.")},i=o(r);if(i.kind!=="object")throw new Error("The root schema must be an object keyed by node ID.");if(Object.values(i.properties).some(a=>a.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:t,nodes:i.properties}}async function Bu(e,t,r,n={}){var g;let o=512;const i=await import("typescript"),a=i.createSourceFile(t,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),s=a.parseDiagnostics;if(s!=null&&s.length)throw new Error("Invalid TypeScript syntax.");const c=new Map;for(const m of a.statements){if(!i.isInterfaceDeclaration(m)&&!i.isTypeAliasDeclaration(m))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((g=m.typeParameters)!=null&&g.length||c.has(m.name.text))throw new Error("Generics and duplicate declarations are not supported.");c.set(m.name.text,m)}const u=(m,y)=>{var C;const v={},b=m.find(S=>i.isIndexSignatureDeclaration(S));let w;if(b&&n.allowJson&&i.isIndexSignatureDeclaration(b)){if(m.filter(S=>i.isIndexSignatureDeclaration(S)).length!==1||b.parameters.length!==1||((C=b.parameters[0].type)==null?void 0:C.kind)!==i.SyntaxKind.StringKeyword||!b.type)throw new Error("Only one string-keyed index signature is supported for forms.");w=d(b.type,y)}return{kind:"object",properties:Object.fromEntries(m.filter(S=>S!==b||!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,y),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||!c.has(M))throw new Error(`Config port ${S.name.text} requires @port config ResourceType`);const E=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`);v[S.name.text]={kind:"config",resourceType:M,multiple:E}}return[S.name.text,{type:j,optional:!!S.questionToken}]})),...w?{additionalProperties:w}:{},...Object.keys(v).length?{ports:v}:{}}},l=(m,y)=>{var C;if(y.includes(m))throw new Error("Recursive types are not supported.");const v=c.get(m);if(!v)throw new Error(`Unknown type: ${m}`);let b;if(i.isInterfaceDeclaration(v)){if((C=v.heritageClauses)!=null&&C.length)throw new Error("Interface inheritance is not supported; declare properties explicitly.");b=u(v.members,[...y,m])}else b=d(v.type,[...y,m]);const w=n.allowJson?i.getJSDocTags(v).filter(S=>S.tagName.text==="port"):[];if(!w.length)return b;if(b.kind!=="object")throw new Error("Node ports require an object interface");const x={...b.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(x,T))throw new Error(`Duplicate port declaration: ${T}`);x[T]={kind:j,...typeof M=="string"?{label:M}:{}}}return{...b,ports:x}},d=(m,y)=>{var v,b,w;if(--o<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(m.kind===i.SyntaxKind.StringKeyword)return{kind:"string"};if(m.kind===i.SyntaxKind.NumberKeyword)return{kind:"number"};if(m.kind===i.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[i.SyntaxKind.AnyKeyword,i.SyntaxKind.UnknownKeyword].includes(m.kind))return{kind:"json"};if(i.isParenthesizedTypeNode(m))return d(m.type,y);if(i.isUnionTypeNode(m))return{kind:"union",types:m.types.map(x=>d(x,y))};if(i.isArrayTypeNode(m))return{kind:"array",items:d(m.elementType,y)};if(i.isTypeLiteralNode(m))return u(m.members,y);if(i.isLiteralTypeNode(m)){const x=m.literal;if(i.isStringLiteral(x))return{kind:"literal",value:x.text};if(i.isNumericLiteral(x))return{kind:"literal",value:Number(x.text)};if(x.kind===i.SyntaxKind.NullKeyword)return{kind:"null"};if(x.kind===i.SyntaxKind.TrueKeyword||x.kind===i.SyntaxKind.FalseKeyword)return{kind:"literal",value:x.kind===i.SyntaxKind.TrueKeyword}}if(i.isTypeReferenceNode(m)&&i.isIdentifier(m.typeName)){if(n.allowJson&&m.typeName.text==="Record"&&!c.has("Record")&&((v=m.typeArguments)==null?void 0:v.length)===2&&m.typeArguments[0].kind===i.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:d(m.typeArguments[1],y)};if(m.typeName.text==="Array"&&((b=m.typeArguments)==null?void 0:b.length)===1)return{kind:"array",items:d(m.typeArguments[0],y)};if(!((w=m.typeArguments)!=null&&w.length))return l(m.typeName.text,y)}throw new Error(`Unsupported TypeScript type: ${m.getText(a)}`)},h=r??(c.has("Graph")?"Graph":c.size===1?[...c.keys()][0]:void 0);if(!h)throw new Error("Declare an interface Graph keyed by node ID.");const p=l(h,[]);if(p.kind!=="object")throw new Error("Graph must be an object keyed by node ID.");return p}async function am(e,t){const r=await Bu(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 Mt(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=>Mt(r,t));if(t.kind==="union")return t.types.some(r=>Mt(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"?Mt(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)&&Mt(o.type,n.type):n.optional}):e.kind===t.kind}function zu(e,t){if(!t.sourceProperty&&!t.targetProperty)return;const r=(a,s)=>{var l;const c=Object.prototype.hasOwnProperty.call(e.nodes,a)?a:a.replace(/^root\./,""),u=Object.prototype.hasOwnProperty.call(e.nodes,c)?(l=e.nodes[c])==null?void 0:l.type:void 0;return s&&(u==null?void 0:u.kind)==="object"&&Object.prototype.hasOwnProperty.call(u.properties,s)?u.properties[s]:void 0},n=r(t.source,t.sourceProperty),o=r(t.target,t.targetProperty);if(!n||!o)return"Unverified: source or target property is missing from the interface.";const i=a=>a.kind==="json"||a.kind==="object"&&(!!a.additionalProperties||Object.values(a.properties).some(s=>i(s.type)))||a.kind==="array"&&i(a.items)||a.kind==="union"&&a.types.some(i);if(i(n.type)||i(o.type))return"Unverified: arbitrary JSON or dictionary fields require runtime validation.";if(n.optional&&!o.optional)return"Optional source cannot supply a required target property.";if(!Mt(n.type,o.type))return`Incompatible property types: ${t.sourceProperty} -> ${t.targetProperty}.`}async function sm(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 Fu(t,e.name);if(/\.ts$/i.test(e.name))return am(t,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Al=new WeakMap;function vt(e){if(!e||typeof e!="object")return e;const t=Al.get(e);if(t)return t;const r=()=>{throw new Error("Form callback data is read-only. Return edits instead.")},n=new Proxy(Array.isArray(e)?[]:{},{get:(o,i)=>vt(Reflect.get(e,i)),has:(o,i)=>Reflect.has(e,i),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(o,i)=>{const a=Reflect.getOwnPropertyDescriptor(e,i);return a&&{...a,value:vt(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:r,deleteProperty:r,defineProperty:r,setPrototypeOf:r,preventExtensions:r});return Al.set(e,n),n}function St(e,t,r){var o;const n=t.split(".");for(let i=n.length;i>0;i--){const a=n.slice(0,i).join("."),s=(o=je(e,a))==null?void 0:o.$form;if(!(s!=null&&s.$type))continue;let c=Object.prototype.hasOwnProperty.call(r,s.$type)?r[s.$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(s.$fields??{}).filter(([d])=>!u||d.startsWith(`${u}.`)).map(([d,h])=>[u?d.slice(u.length+1):d,h]));return{type:c,fields:l,binding:s}}}async function Du(e,t){if(e.size>256*1024)throw new Error("Form schema exceeds 256 KB.");const r=await e.text();if(e.name.endsWith(".ts")){if(!t.length||t.length>32)throw new Error("Choose between 1 and 32 form interface names.");const o=[],i=new Set(t);for(const a of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const s=await Bu(r,e.name,a,{allowJson:!0});o.push([a,s]);for(const c of Object.values(s.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=Fu(r,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([o,i])=>[o,i.type]))}function jn(e,t){return!e||("$in"in e?e.$in.includes(je(t,e.$address)):je(t,e.$address)===e.$equals)}function Wt(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 a=Object.values(i).every(o);return n.delete(i),a};return o(t)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!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 Tl(e,t){const r=t.address.split(".");if(r.shift()!=="root"||!r.length||r.some(s=>!s||["__proto__","prototype","constructor","#"].includes(s)))throw new Error("Invalid form field address.");const n=r.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(r.some(s=>s.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...r].join("."),a=je(e,i);if(!a||typeof a!="object")throw new Error(`Missing form parent: ${i}`);if(o){if(t.op==="set"&&typeof t.value!="string")throw new Error("Node colors must be strings.");return ur(e,i,n,t.op==="remove"?void 0:t.value)}return br(e,i,s=>{const c=Array.isArray(s.$)?s.$:s;if(t.op==="remove"&&!Object.prototype.hasOwnProperty.call(c,n)||t.op==="set"&&Object.is(c[n],t.value))return s;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===s?u:{...s,$:u}})}function Rn(e,t,r){let n=Tl(e,t.value===void 0?{op:"remove",address:t.address}:{op:"set",address:t.address,value:t.value});const o=r==null?void 0:r({...t,previousValue:vt(je(e,t.address)),data:vt(n)});if(o&&!Array.isArray(o))throw new Error("Form change handlers must return edits synchronously.");for(const i of Array.isArray(o)?o:[]){if(i.op!=="set"&&i.op!=="remove")throw new Error("Unsupported form edit.");n=Tl(n,i)}return n}const Gt="data:image/svg+xml;base64,";function Fr(e){if(e.startsWith(Gt))return!0;try{const t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:")&&!t.username&&!t.password}catch{return!1}}async function n0(e){if(e.size>256*1024)throw new Error("SVG must be 256 KB or smaller.");const t=await e.text(),r=new DOMParser().parseFromString(t,"image/svg+xml");if(r.doctype||r.querySelector("parsererror")||r.documentElement.localName!=="svg"||r.documentElement.namespaceURI!=="http://www.w3.org/2000/svg")throw new Error("Choose a valid SVG file.");if(r.querySelector("script, foreignObject")||[...r.querySelectorAll("*")].some(i=>[...i.attributes].some(a=>/^on/i.test(a.name))))throw new Error("SVG scripts and event handlers are not allowed.");const n=new TextEncoder().encode(t);let o="";for(const i of n)o+=String.fromCharCode(i);return Gt+btoa(o)}const Ar=({name:e,svg:t=!1,...r})=>{const[n,o]=_.useState(null),[i,a]=_.useState(!0),[s,c]=_.useState(!1),u=typeof e=="string"&&Fr(e);if(_.useEffect(()=>{if(u||!e||e.length<2){o(null),a(!1);return}a(!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 h;switch(d){case"md":h=await import("react-icons/md");break;case"fa6":h=await import("react-icons/fa6");break;case"io5":h=await import("react-icons/io5");break;case"io":h=await import("react-icons/io");break;case"ti":h=await import("react-icons/ti");break;case"go":h=await import("react-icons/go");break;case"fi":h=await import("react-icons/fi");break;case"di":h=await import("react-icons/di");break;case"ai":h=await import("react-icons/ai");break;case"bs":h=await import("react-icons/bs");break;case"ri":h=await import("react-icons/ri");break;case"fc":h=await import("react-icons/fc");break;case"gi":h=await import("react-icons/gi");break;case"hi2":h=await import("react-icons/hi2");break;case"hi":h=await import("react-icons/hi");break;case"si":h=await import("react-icons/si");break;case"sl":h=await import("react-icons/sl");break;case"im":h=await import("react-icons/im");break;case"bi":h=await import("react-icons/bi");break;case"pi":h=await import("react-icons/pi");break;case"vsc":h=await import("react-icons/vsc");break;case"tb":h=await import("react-icons/tb");break;case"tfi":h=await import("react-icons/tfi");break;case"cg":h=await import("react-icons/cg");break;case"lia":h=await import("react-icons/lia");break;case"lu":h=await import("react-icons/lu");break;default:throw new Error(`Unsupported library: ${d}`)}const p=h[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{a(!1)}})()},[e,u]),u){const{size:l=80,style:d,...h}=r;return t?f.jsx("image",{...h,href:e,width:l,height:l,preserveAspectRatio:"xMidYMid meet",style:d}):f.jsx("img",{...h,src:e,alt:"",width:l,height:l,referrerPolicy:"no-referrer",style:{objectFit:"contain",...d}})}return i||!n?null:f.jsx(n,{...r})};function o0(e,t){let r=e;for(const n of t){if(n.op!=="set"&&n.op!=="remove")throw new Error("Unsupported state edit.");const o=n.address.split(".");if(o.some(a=>a.startsWith("$")||["__proto__","prototype","constructor"].includes(a)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;Qt(i),r=Rn(r,{address:n.address,nodeAddress:o.slice(0,-1).join("."),value:i})}return Qt(r),r}function on(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 Qt(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}`);Qt(r)}}function i0(e,t,r){Qt(t.value);const n=Rn(e,t,r);return Qt(n),n}function cm(e,t){const r=(n,o="")=>{if(!n||typeof n!="object")return n;if(["$label","$subtitle","$content","$icon","$bgColor","$textColor","$borderColor"].includes(o)&&typeof n.$state=="string"){const a=je(t,n.$state);return a==null?"":typeof a=="object"?JSON.stringify(a,null,2):String(a)}let i=n;for(const[a,s]of Object.entries(n)){const c=r(s,a);c!==s&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,a,{value:c,enumerable:!0,writable:!0,configurable:!0}))}return i};return r(e)}const a0=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),s0=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,qt=(e,t)=>JSON.stringify([e,t]);function en(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 en(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 Nt(e){const t=en(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 Il(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"&&!Wt(e)?e.types:[e]}function c0(e,t,r){if(t.address===r.address)return;const n=je(e,t.address),o=(i,a)=>a===void 0?!1:i.kind==="union"?i.types.some(s=>o(s,a)):i.kind==="array"?Array.isArray(a)&&a.every(s=>o(i.items,s)):i.kind==="object"?!!a&&typeof a=="object"&&!Array.isArray(a)&&Object.entries(i.properties).every(([s,c])=>c.optional&&a[s]===void 0||o(c.type,a[s]))&&Object.entries(a).every(([s,c])=>Object.prototype.hasOwnProperty.call(i.properties,s)||!i.additionalProperties||o(i.additionalProperties,c)):a===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!jr(i,a,!0);if(o(r.type,n))return structuredClone(n)}function um(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)),a=new Map(n.flatMap(l=>{const d=t[l.data.id];return d&&r[d.type]?[[d.address,l.data.id]]:[]})),s=(l,d,h,p,g,m=!1)=>{var j,T,k,M,R;if(g>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const y=je(e,d),v=en(h,y),b=v.kind!=="object"&&v.kind!=="array";o.containers.set(l,{address:d,type:v,declared:h,scalar:b});const w=`__form:${l}`,x={...(j=o.bindings[l])==null?void 0:j.fields},C={kind:"object",properties:{},ports:{...v.kind==="object"?v.ports:{},...m?{resource:{label:"output",...v.kind==="object"?(T=v.ports)==null?void 0:T.resource:{},kind:"output"}}:{}}},S=v.kind==="object"?{...v.properties,...Object.fromEntries(Object.keys(y??{}).filter(E=>!Object.prototype.hasOwnProperty.call(v.properties,E)&&v.additionalProperties).map(E=>[E,{type:v.additionalProperties,optional:!0}]))}:v.kind==="array"?Object.fromEntries((Array.isArray(y)?y:[]).map((E,P)=>[String(P),{type:v.items,optional:!0}])):{value:{type:Wt(h)?h:v,optional:!1}};for(const[E,P]of Object.entries(S)){if(!a0(E))throw new Error(`Unsupported structured property key: ${E}`);const I=b?d:`${d}.${E}`,q=je(e,I),O=en(P.type,q),V=O.kind==="object"||O.kind==="array",W=(k=C.ports)==null?void 0:k[E],te=(W==null?void 0:W.kind)==="config"&&(((M=x[E])==null?void 0:M.$options)||Wt(P.type)),ne=P.type.kind==="json"||P.type.kind==="union"&&!Wt(P.type);if(((R=x[E])==null?void 0:R.$control)==="upload"||!V&&v.kind!=="array"&&(!ne||b)||te){C.properties[E]={...P,type:P.type.kind==="json"?O:P.type};continue}const ee=a.get(I)??s0(I),be=v.kind==="array"?`Item ${Number(E)+1}`:E,le={address:I,owner:l,field:E,type:P.type,label:be,nodeId:ee,present:q!==void 0};if(o.slots.set(qt(l,E),le),C.ports[E]={kind:"config",resourceType:`__form:${ee}`},q===void 0||(o.edges.push({data:{id:`__form-edge:${l}:${E}`,source:ee,target:l,sourceProperty:"output:resource",targetProperty:`config:${E}`,isEdgeDashed:!0}}),o.containers.has(ee)||a.has(I)))continue;if(i.has(ee))throw new Error(`Structured node identity conflict: ${ee}`);i.add(ee);const $={data:{id:ee,type:"objectView",label:be,headerTitle:be,description:{},config:{form:!0,icon:O.kind==="array"?"PiListNumbers":V?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push($),s(ee,I,P.type,p,g+1,!0);const z=o.schema[`__form:${ee}`];$.data.description=Object.fromEntries(Object.keys(z.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:x}};for(const l of n){const d=t[l.data.id];if(d!=null&&d.portResources)continue;const h=d&&r[d.type];!d||!h||je(e,d.address)===void 0||s(l.data.id,d.address,h,(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],h=o.schema[d.type].ports;h.resource={...h.resource,kind:"output",label:((u=h.resource)==null?void 0:u.label)??"output"}}return o}const rt=(e="reference")=>({kind:e,text:"",paths:[""]}),lm=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(t=>["__proto__","constructor","prototype"].includes(t));function u0(e,t){const r=new Set(t.map(a=>a.path)),n=a=>{if(!a.paths.length||a.paths.some(s=>!lm(s)||!r.has(s)))throw new Error("Choose an available reference.");return[...a.paths,...a.fallback===void 0?[]:[JSON.stringify(a.fallback)]].join(" || ")},o=a=>{if(a.includes("{{")||a.includes("}}"))throw new Error("Use a reference part for dynamic values.");return a},i=a=>a.map(s=>{if(s.kind==="text")return o(s.text);if(s.kind==="conditional"){if(s.paths.length!==1||s.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(s)}}}${o(s.text)}{{/if}}`}return`{{${n(s)}}}`}).join("");if(e.mode==="reference"||e.mode==="condition"){if(e.parts.length!==1||e.parts[0].kind!=="reference")throw new Error("Choose one reference binding.");const a=i(e.parts);return e.mode==="condition"?`${a} == ${JSON.stringify(e.comparison)}`:a}if(e.mode==="json"){const a=e.fields.map(s=>s.key);if(!a.length||new Set(a).size!==a.length||a.some(s=>!s||["__proto__","constructor","prototype"].includes(s)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(s=>[s.key,i(s.parts)])))}return i(e.parts)}async function l0(e){const t=await import("typescript"),r=a=>{const s=t.createSourceFile("binding.ts",`(${a})`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS);if(s.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const c=s.statements[0];if(!c||!t.isExpressionStatement(c))throw new Error("Unsupported reference expression.");const u=rt();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 h=d.getText(s);if(!lm(h)||u.fallback!==void 0)throw new Error("Unsupported reference expression.");u.paths.push(h)};if(l(c.expression),!u.paths.length)throw new Error("A binding needs a reference.");return u},n=a=>{const s=[];let c=0;const u=/\{\{([\s\S]*?)\}\}/g;for(const l of a.matchAll(u)){const d=l.index;if(d<c)continue;d>c&&s.push({...rt("text"),text:a.slice(c,d)});const h=l[1].trim();if(h.startsWith("#if ")){const p=a.indexOf("{{/if}}",d+l[0].length);if(p<0)throw new Error("Unclosed condition.");s.push({...r(h.slice(4)),kind:"conditional",text:a.slice(d+l[0].length,p)}),c=p+7}else s.push(r(h)),c=d+l[0].length}return c<a.length&&s.push({...rt("text"),text:a.slice(c)}),s},o={mode:"reference",parts:[rt()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const a=JSON.parse(e);if(a&&typeof a=="object"&&!Array.isArray(a)&&Object.values(a).every(s=>typeof s=="string"))return{...o,mode:"json",fields:Object.entries(a).map(([s,c])=>({key:s,parts:n(c)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const a=t.createSourceFile("condition.ts",`value ${i[1].text}`,t.ScriptTarget.Latest,!0,t.ScriptKind.TS),s=a.statements[0];if(a.statements.length===1&&t.isExpressionStatement(s)&&t.isBinaryExpression(s.expression)&&s.expression.operatorToken.kind===t.SyntaxKind.EqualsEqualsToken&&t.isStringLiteral(s.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:s.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function Ol({parts:e,references:t,onChange:r,disabled:n}){const o=(i,a)=>r(e.map((s,c)=>c===i?{...s,...a}:s));return f.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,a)=>f.jsxs("fieldset",{"data-binding-part":a,style:{border:0,padding:0,margin:0,minWidth:0},children:[f.jsxs("legend",{children:["Part ",a+1]}),f.jsxs("div",{style:{display:"flex",gap:8},children:[f.jsxs("span",{"data-form-select":"",style:{flex:1},children:[f.jsxs("select",{"aria-label":"Part type",disabled:n,value:i.kind,onChange:s=>o(a,{kind:s.target.value}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"text",children:"Text"}),f.jsx("option",{value:"conditional",children:"Conditional text"})]}),f.jsx(K.PiCaretDown,{size:16,"aria-hidden":"true"})]}),f.jsx(Se,{"aria-label":`Remove part ${a+1}`,title:"Remove part",icon:f.jsx(K.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r(e.filter((s,c)=>c!==a))})]}),i.kind!=="text"&&f.jsxs(f.Fragment,{children:[i.paths.map((s,c)=>f.jsxs("label",{children:["Reference ",c+1,f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":`Reference ${c+1}`,disabled:n,value:s,onChange:u=>o(a,{paths:i.paths.map((l,d)=>d===c?u.target.value:l)}),children:[f.jsx("option",{value:"",children:"Select reference"}),t.map(u=>f.jsx("option",{value:u.path,children:u.label},u.path))]}),f.jsx(K.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},c)),i.kind==="reference"&&f.jsxs(f.Fragment,{children:[f.jsx(Se,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:f.jsx(K.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>o(a,{paths:[...i.paths,""]})}),f.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center"},children:[f.jsx("input",{type:"checkbox","aria-label":"Default value enabled",disabled:n,checked:i.fallback!==void 0,onChange:s=>o(a,{fallback:s.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&f.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:s=>o(a,{fallback:s.target.value})})]})]}),i.kind!=="reference"&&f.jsxs("label",{children:["Text",f.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:s=>o(a,{text:s.target.value})})]})]},a)),f.jsx(Se,{"aria-label":"Add part",title:"Add part",icon:f.jsx(K.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>r([...e,rt()])})]})}function d0({label:e,value:t,references:r,disabled:n,onChange:o}){const[i,a]=_.useState(),[s,c]=_.useState(""),[u,l]=_.useState(!1),d=async()=>{l(!0),c("");try{a(await l0(typeof t=="string"?t:""))}catch(h){c(h instanceof Error?h.message:"Unable to read binding.")}finally{l(!1)}};return f.jsxs("div",{"data-runtime-binding":e,style:{marginBottom:8},children:[f.jsx(Se,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:f.jsx(K.PiLink,{size:18}),size:"sm",variant:"ghost",disabled:n||u,onClick:d}),typeof t=="string"&&t.includes("{{")&&f.jsx("span",{children:"Bound value"}),i&&f.jsxs("fieldset",{disabled:n,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Binding mode",f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":"Binding mode",value:i.mode,onChange:h=>a({...i,mode:h.target.value,parts:[rt()]}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"condition",children:"Equals"}),f.jsx("option",{value:"template",children:"Text template"}),f.jsx("option",{value:"json",children:"JSON output"})]}),f.jsx(K.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),i.mode==="json"?f.jsxs(f.Fragment,{children:[i.fields.map((h,p)=>f.jsxs("fieldset",{"data-output-field":p,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Output field name",f.jsx("input",{"aria-label":"Output field name",value:h.key,onChange:g=>a({...i,fields:i.fields.map((m,y)=>y===p?{...m,key:g.target.value}:m)})})]}),f.jsx(Ol,{parts:h.parts,references:r,disabled:n,onChange:g=>a({...i,fields:i.fields.map((m,y)=>y===p?{...m,parts:g}:m)})}),f.jsx(Se,{"aria-label":"Remove output field",title:"Remove output field",icon:f.jsx(K.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>a({...i,fields:i.fields.filter((g,m)=>m!==p)})})]},p)),f.jsx(Se,{"aria-label":"Add output field",title:"Add output field",icon:f.jsx(K.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>a({...i,fields:[...i.fields,{key:"",parts:[rt()]}]})})]}):f.jsx(Ol,{parts:i.parts,references:r,disabled:n,onChange:h=>a({...i,parts:h})}),i.mode==="condition"&&f.jsxs("label",{children:["Equals",f.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:h=>a({...i,comparison:h.target.value})})]}),f.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[f.jsx(Se,{"aria-label":"Apply binding",title:"Apply binding",icon:f.jsx(K.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(u0(i,r)),a(void 0),c("")}catch(h){c(h instanceof Error?h.message:"Unable to apply binding.")}}}),f.jsx(Se,{"aria-label":"Cancel binding",title:"Cancel binding",icon:f.jsx(K.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{a(void 0),c("")}})]})]}),s&&f.jsx("p",{role:"alert",children:s})]})}function f0({nodeAddress:e,onOpen:t}){const{structured:r,data:n,callbacks:o,editable:i,onFieldCreate:a}=_.useContext(wr),s=qe(),[c,u]=_.useState(""),[l,d]=_.useState("0"),[h,p]=_.useState(""),g=r==null?void 0:r.containers.get(e);if(!g||!n||!r)return null;const m=s.readOnly||s.config.editable===!1||!i,y=je(n,g.address),v=Il(g.declared),b=g.type.kind==="array"?g.type.items:g.type.kind==="object"?g.type.additionalProperties:void 0,w=b?Il(b):[],x=!!a&&g.type.kind==="object"&&(b==null?void 0:b.kind)==="json",C=P=>P.kind==="literal"?String(P.value):P.kind==="string"?"Text":vr(P.kind),S=[...r.slots.values()].filter(P=>P.owner===e),j=(P,I)=>{var q;return(q=o.onFormChange)==null?void 0:q.call(o,{data:n,nodeAddress:g.address,address:P,previousValue:je(n,P),value:I})},T=P=>{var I;s.setSelectedNodeIds([P]),(I=s.engineRef.current)==null||I.focusNode(P,90,!1)},k=(P,I)=>{if(!Array.isArray(y))return;const q=[...y];[q[P],q[P+I]]=[q[P+I],q[P]],j(g.address,q)},M=()=>{const P=w[Number(l)]??w[0];if(P)if(g.type.kind==="array")j(g.address,[...Array.isArray(y)?y:[],Nt(P)]);else{if(!c||c.includes(".")||c.startsWith("$")||["__proto__","constructor","prototype"].includes(c)){p("Choose a property name without dots or reserved prefixes.");return}if(Object.prototype.hasOwnProperty.call(y,c)){p("Property already exists.");return}x&&(l==="file"||l==="files")?a==null||a({data:n,nodeAddress:g.address,address:`${g.address}.${c}`,previousValue:void 0,value:l==="files"?[]:""},{$control:"upload"}):j(`${g.address}.${c}`,Nt(P)),u(""),p("")}},R=g.type.kind==="object"&&!!g.type.additionalProperties,E=g.type.kind==="array";return f.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[v.length>1&&f.jsxs("label",{children:["Value type",f.jsx("span",{"data-form-select":"",style:{display:"block"},children:f.jsx(xr,{"aria-label":"Value type",disabled:m,value:String(v.findIndex(P=>en(P,y).kind===g.type.kind)),onValueChange:P=>j(g.address,Nt(v[Number(P)])),children:v.map((P,I)=>f.jsx("option",{value:I,children:C(P)},I))})})]}),S.map((P,I)=>f.jsxs("div",{"data-structured-slot":P.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[P.type.kind==="array"?f.jsx(K.PiListNumbers,{size:20}):f.jsx(K.PiBracketsCurly,{size:20}),f.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:vr(P.label)}),f.jsx(Se,{"aria-label":`${P.present?t?"Edit":"Focus":"Create"} ${vr(P.label)}`,title:`${P.present?t?"Edit":"Focus":"Create"} ${vr(P.label)}`,icon:P.present?f.jsx(K.PiMagnifyingGlass,{size:18}):f.jsx(K.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:m&&!P.present,onClick:q=>{var O;P.present?t?t(P.nodeId):((O=q.currentTarget.closest("dialog"))==null||O.close(),T(P.nodeId)):j(P.address,Nt(P.type))}}),E&&f.jsxs(f.Fragment,{children:[f.jsx(Se,{"aria-label":`Move item ${I+1} up`,icon:f.jsx(K.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:m||I===0,onClick:()=>k(I,-1)}),f.jsx(Se,{"aria-label":`Move item ${I+1} down`,icon:f.jsx(K.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:m||I===S.length-1,onClick:()=>k(I,1)})]}),P.present&&f.jsx(Se,{"aria-label":`Remove ${vr(P.label)}`,icon:f.jsx(K.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:m,onClick:()=>E?j(g.address,y.filter((q,O)=>O!==I)):j(P.address,void 0)})]},P.address)),(E||R)&&f.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[R&&f.jsxs("label",{style:{flex:"1 1 120px",minWidth:0,display:"grid",gap:8},children:["Property name",f.jsx("input",{"aria-label":"Property name",placeholder:"Required",value:c,disabled:m,onChange:P=>u(P.target.value)})]}),w.length>1&&f.jsxs("label",{style:{flex:"1 1 100px",minWidth:0,display:"grid",gap:8},children:["New value type",f.jsx("span",{"data-form-select":"",style:{display:"block"},children:f.jsxs(xr,{"aria-label":"New value type",value:l,disabled:m,onValueChange:d,children:[w.map((P,I)=>f.jsx("option",{value:I,children:C(P)},I)),x&&f.jsx("option",{value:"file",children:"File"}),x&&f.jsx("option",{value:"files",children:"Files"})]})})]}),f.jsx("span",{style:{display:"flex",alignItems:"center",flexShrink:0,...R||w.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:f.jsx(Se,{"aria-label":E?"Add item":"Add property",icon:f.jsx(K.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:m,onClick:M})})]}),h&&f.jsx("p",{role:"alert",children:h})]})}const wr=_.createContext({callbacks:{}}),dn=Cn.default.div`
59
59
  --flow-form-input-radius: 16px;
60
60
  --flow-form-input-background: color-mix(
61
61
  in srgb,
@@ -205,8 +205,8 @@
205
205
  font-size: 14px;
206
206
  margin-top: 8px;
207
207
  }
208
- `;function Ol({request:e,property:t,config:r,value:n,disabled:o}){var se,te,xe,ge,De;const{callbacks:i,structured:a,references:s}=_.useContext(xr),{themeColor:c}=$e(),{background:u}=Ye(),l=_.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]=_.useState(f),[g,b]=_.useState(""),[x,m]=_.useState(0),w=_.useRef(null),v=_.useRef(),[C,S]=_.useState(!1),[j,T]=_.useState(!1),[P,M]=_.useState(),R=((se=r.$options)==null?void 0:se.$source)==="callback",E=i.resolveFormOptions,{data:k,address:I,nodeAddress:q,nodeId:O}=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=_.useRef(k);W.current=k;const V=JSON.stringify([I,O,(ge=r.$options)!=null&&ge.$dependsOn?r.$options.$dependsOn.map(Z=>je(k,Z)):je(k,q)]);_.useEffect(()=>{y(f),b("")},[f,I,O]),_.useEffect(()=>{if(!R)return;const Z=new AbortController;return Promise.resolve().then(()=>{if(!E)throw new Error("No options resolver configured");return E({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,E,V,I,q,O,x]);const ue=R&&(P==null?void 0:P.key)!==V,ne=R?(P==null?void 0:P.key)===V?P.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",pe=(r.$control==="upload"?"upload":a&&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,k),$=le?"Required":"Optional",D=pe!=="upload"&&!!(s!=null&&s.length)&&typeof n=="string"&&n.includes("{{"),G=g||R&&(P==null?void 0:P.key)===V&&P.error||!D&&Sr(t.type,n,le),N=br(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")}},ye=_.useRef(ee);_.useLayoutEffect(()=>{ye.current=ee});const fe=()=>{if(d){try{const Oe=p===""&&t.optional?void 0:JSON.parse(p),qe=Sr(t.type,Oe,le);if(qe){b(qe);return}ee(Oe)}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=Sr(t.type,de,le);if(Z&&Ce&&p!==""){b(Ce);return}ee(de)},J=async Z=>{var Ce,Oe,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=(Oe=(Ce=r.$upload)==null?void 0:Ce.accept)==null?void 0:Oe.split(",").map(Se=>Se.trim().toLowerCase()).filter(Boolean);for(const Se of Z){if(((qe=r.$upload)==null?void 0:qe.maxSizeBytes)!==void 0&&Se.size>r.$upload.maxSizeBytes)throw new Error(`${Se.name} exceeds the file size limit.`);if(Ue!=null&&Ue.length&&!Ue.some(He=>He.startsWith(".")?Se.name.toLowerCase().endsWith(He):He.endsWith("/*")?Se.type.toLowerCase().startsWith(He.slice(0,-1)):Se.type.toLowerCase()===He))throw new Error(`${Se.name} is not an accepted file type.`)}const Qe=await Promise.all(Z.map(async Se=>{const He=await i.uploadFormFile({...e,data:bt(k),file:Se,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=Sr(t.type,We,le);if(we)throw new Error(we);ye.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))}},Y={id:l,disabled:o,"aria-label":N,"aria-required":le,"aria-invalid":!!G,"aria-describedby":G?`${l}-error`:void 0},U=me(c);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(K.PiArrowCounterClockwise,{size:14})})]}),!!(s!=null&&s.length)&&!d&&pe!=="upload"&&h.jsx(d0,{label:N,value:n,references:s,disabled:o,onChange:ee}),pe==="upload"?h.jsxs("div",{"data-form-upload":Q?"multiple":"single","aria-busy":C,style:{"--flow-upload-surface":me(u),outline:j?"2px dashed var(--flow-form-input-background)":void 0,borderRadius:"var(--flow-form-input-radius)"},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),J(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="",J(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(K.PiFile,{size:32,"aria-hidden":"true"}),h.jsx(Pr,{name:Z,size:120,onError:Ce=>{Ce.currentTarget.style.visibility="hidden"}})]}),h.jsxs("div",{"data-upload-actions":"",children:[!Q&&h.jsx(_e,{"aria-label":`Replace ${N}`,title:`Replace ${N}`,icon:h.jsx(K.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>{var Ce;return(Ce=w.current)==null?void 0:Ce.click()}}),h.jsx(_e,{"aria-label":`Remove ${N} file ${de+1}`,title:"Remove file",icon:h.jsx(K.PiTrash,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>ee(Q&&Array.isArray(n)?n.filter((Ce,Oe)=>Oe!==de):"")})]})]},`${de}:${Z}`)),(Q||!n)&&h.jsx("button",{...Y,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(K.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&h.jsx("span",{role:"status",children:"Uploading..."})]}):D?null:pe==="select"?h.jsx("div",{"data-form-select":"",children:h.jsxs(vr,{...Y,disabled:o||ue||!!(P!=null&&P.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:br(Z.label)||Z.label},de))]})}):pe==="pills"?h.jsxs("div",{id:l,role:"group","aria-label":N,"aria-describedby":Y["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(Oe=>Oe!==Z.value):[...Array.isArray(n)?n:[],Z.value]:Z.value),children:br(Z.label)||Z.label},de)}),ue&&h.jsx("span",{role:"status",children:"Loading..."})]}):pe==="textarea"?h.jsx("textarea",{...Y,placeholder:$,value:p,onChange:Z=>y(Z.target.value),onBlur:fe}):h.jsx("input",{...Y,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:fe,onKeyDown:Z=>{Z.key==="Enter"&&fe(),Z.key==="Escape"&&y(n===void 0?"":String(n))}}),G&&h.jsx("div",{role:"alert",id:`${l}-error`,children:G}),R&&(P==null?void 0:P.error)&&h.jsx("button",{type:"button",disabled:o,onClick:()=>{M(void 0),m(x+1)},children:"Retry"})]})}function lm({nodeAddress:e,structured:t=!1}){return t?h.jsx(h0,{nodeAddress:e},e):h.jsx(Eu,{nodeAddress:e})}function h0({nodeAddress:e}){var d,f,p;const t=_.useContext(xr),[r,n]=_.useState([]),o=((d=t.structured)==null?void 0:d.sourceSchema)??t.schema,i=((f=t.structured)==null?void 0:f.sourceBindings)??t.bindings,a=_.useMemo(()=>{if(!(!t.data||!o||!i))return cm(t.data,i,o,[{data:{id:e,type:"objectView"}}])},[t.data,i,o,e]);if(!a)return h.jsx(Eu,{nodeAddress:e});const s=r.findIndex(y=>!a.containers.has(y)),c=s<0?r:r.slice(0,s),u=c.at(-1)??e,l=(p=[...a.slots.values()].find(y=>y.nodeId===u))==null?void 0:p.label;return h.jsxs(xr.Provider,{value:{...t,structured:a,schema:a.schema,bindings:a.bindings,renderForm:void 0,onFieldCreate:u===e?t.onFieldCreate:void 0},children:[!!c.length&&h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[h.jsx(_e,{"aria-label":"Back to parent fields",title:"Back to parent fields",icon:h.jsx(K.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:()=>n(c.slice(0,-1))}),h.jsx("strong",{style:{minWidth:0,overflowWrap:"anywhere"},children:br(l)})]}),h.jsx(Eu,{nodeAddress:u,onOpen:y=>n([...c,y])},u)]})}function Eu({nodeAddress:e,onOpen:t}){var C,S;const{data:r,schema:n,callbacks:o,bindings:i,editable:a,renderForm:s,structured:c}=_.useContext(xr),{readOnly:u,config:l}=$e(),d=s==null?void 0:s(e);if(d!==void 0)return h.jsx("fieldset",{"data-flow-form":e,disabled:u||l.editable===!1||!a,style:{border:0,margin:0,padding:0,minWidth:0},children:d});if(!r)return h.jsx(ln,{role:"alert",children:"Forms require a JSON document."});const f=i?nn(i,e,n):void 0,p=i?f:n&&_t(r,e,n);if(!p)return h.jsx(ln,{role:"status",children:"Form schema unavailable."});const y=(f==null?void 0:f.address)??e,g=je(r,y),b=(C=c==null?void 0:c.containers.get(e))==null?void 0:C.scalar;if(g===void 0||typeof g!="object"&&!b)return h.jsx(ln,{role:"alert",children:"Bound form state is unavailable."});const x=Object.entries(p.type.properties).filter(([j])=>{var T;return En((T=p.fields[j])==null?void 0:T.$visibleWhen,r)}),m=x.length>8||x.some(([j])=>{var T;return(T=p.fields[j])==null?void 0:T.$section}),w=new Map;for(const j of x){const[T,P]=j,M=m?br(((S=p.fields[T])==null?void 0:S.$section)??(P.type.kind==="object"||P.type.kind==="array"?T:P.optional?"Options":"General")):"";w.has(M)||w.set(M,[]),w.get(M).push(j)}const v=([j,T])=>h.jsx(Ol,{request:{data:r,address:b?y:`${y}.${j}`,nodeAddress:y,nodeId:typeof(g==null?void 0:g.id)=="string"?g.id:void 0},property:T,config:p.fields[j]??{},value:b?g:g==null?void 0:g[j],disabled:u||l.editable===!1||!(a??!!o.onJsonChange)},`${(g==null?void 0:g.id)??e}:${j}`);return h.jsxs(ln,{"data-flow-form":e,onClick:j=>j.stopPropagation(),onDoubleClick:j=>j.stopPropagation(),children:[c&&h.jsx(f0,{nodeAddress:e,onOpen:t}),!c&&f&&p.type.additionalProperties&&x.length===0&&h.jsx(Ol,{request:{data:r,address:y,nodeAddress:y},property:{type:p.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:g,disabled:u||l.editable===!1||!a}),[...w].map(([j,T])=>m&&T.length>1?h.jsxs("details",{open:!0,children:[h.jsxs("summary",{children:[h.jsx("span",{children:j}),h.jsx(K.PiCaretDown,{size:16,"aria-hidden":"true"})]}),T.map(v)]},j):T.map(v))]})}function dm(e){const{viewData:t}=_.useContext(xr),{nodeById:r,edgeById:n,parentIds:o}=Hr();if(t){const i=je(t,e),a=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(a)?a.length>0:!!a&&typeof a=="object"&&Object.entries(a).some(([s,c])=>!s.startsWith("$")&&c!==null&&typeof c=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const a=i.isInverted?i.target:i.source,s=i.isInverted?i.source:i.target;return a===e&&s!==e&&r.has(s)})}function 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",...wy(t==="transparent"?"currentColor":t,r,".flow-sdk-node:hover &",!r)}}function fm({label:e,value:t,options:r,onChange:n,disabled:o}){var i;return h.jsxs(vr,{"aria-label":e,title:`Animation: ${((i=r.find(a=>a.value===t))==null?void 0:i.label)??"Mixed"}`,value:t,style:{width:104},disabled:o,onValueChange:a=>{const s=r.find(c=>c.value===a);s&&n(s.value)},children:[t===""&&h.jsx("option",{value:"",disabled:!0,children:"Mixed"}),r.map(a=>h.jsx("option",{value:a.value,children:a.label},a.value))]})}function Du({nodeId:e,edgeId:t,value:r,open:n,onOpenChange:o}){const{callbacks:i,readOnly:a,themeColor:s,colorMode:c}=$e(),{background:u,backgroundSecondary:l,border:d,colorText:f,colorInactive:p}=Ye(),y=c==="dark"?wt:me(p),g=_.useRef(null),b=_.useRef(null),x=_.useRef(0),[m,w]=_.useState(!1),[v,C]=_.useState("icons"),[S,j]=_.useState([]),[T,P]=_.useState("loading"),[M,R]=_.useState(""),[E,k]=_.useState(0),[I,q]=_.useState(""),[O,W]=_.useState(""),[V,ue]=_.useState(!1);_.useEffect(()=>()=>{x.current++},[]),_.useEffect(()=>{if(!m)return;let N=!0;return import("react-icons/pi").then(ee=>{N&&(j(Object.keys(ee).filter(ye=>ye.startsWith("Pi")).sort()),P("ready"))}).catch(()=>{N&&P("unavailable")}),()=>{N=!1}},[m]),_.useEffect(()=>{var N;a&&((N=g.current)==null||N.close())},[a]),_.useEffect(()=>{var N,ee,ye;if(n!==void 0){if(!n||a){(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),(ye=g.current)==null||ye.showModal())}},[n,a,r]);const ne=N=>{var ee,ye,fe;a||(t?(ee=i.onEdgeIconChange)==null||ee.call(i,t,N):e&&((ye=i.onNodeIconChange)==null||ye.call(i,e,N)),o==null||o(!1),(fe=g.current)==null||fe.close())},Q=S.filter(N=>N.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(M.trim().toLowerCase())),pe=36,le=Math.max(1,Math.ceil(Q.length/pe)),$=Math.min(E,le-1),D=Q.slice($*pe,($+1)*pe),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(_e,{"aria-label":t?"Choose edge icon":"Choose node icon",icon:h.jsx(K.PiShapes,{size:20}),size:"sm",variant:"ghost",color:me(s),disabled:a,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(B.chakra.dialog,{ref:g,"aria-label":t?"Choose edge icon":"Choose node icon",css:Vr(me(u),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(u),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(_e,{"aria-label":t?"Remove edge icon":"Remove node icon",icon:h.jsx(K.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:a||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(B.Tabs.Root,{value:v,onValueChange:({value:N})=>{C(N),W("")},display:"contents",css:{"--indicator-thickness":"1px"},children:[h.jsx(B.Tabs.List,{"aria-label":"Icon source",width:"100%",borderBottomWidth:0,children:["icons","custom"].map(N=>h.jsx(B.Tabs.Trigger,{value:N,flex:1,minW:0,justifyContent:"center",px:3,py:2,fontSize:"13px",_selected:{color:s,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||a,onChange:async N=>{var fe;const ee=(fe=N.target.files)==null?void 0:fe[0];if(N.target.value="",!ee)return;const ye=++x.current;ue(!0),W("");try{const J=await n0(ee);ye===x.current&&ne(J)}catch(J){ye===x.current&&W(J instanceof Error?J.message:"Unable to read SVG.")}finally{ye===x.current&&ue(!1)}}}),h.jsx(B.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),k(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?s:d)}`,background:me(r===N?u:l),color:"inherit",cursor:"pointer"},children:h.jsx(Pr,{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(_e,{"aria-label":"Previous icons",icon:h.jsx(K.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:$===0,onClick:()=>k($-1)})}),h.jsx(Te,{label:"Next icons",children:h.jsx(_e,{"aria-label":"Next icons",icon:h.jsx(K.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:$+1>=le,onClick:()=>k($+1)})})]})]})]}):h.jsxs(h.Fragment,{children:[r&&Fr(r)&&h.jsx(Pr,{name:r,size:64}),h.jsxs("button",{type:"button",disabled:V||a,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(K.PiUploadSimple,{}),V?"Uploading...":"Upload SVG"]}),h.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:N=>{N.preventDefault(),!(V||a)&&(!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||a,onChange:N=>q(N.target.value),style:{...G,flex:1,minWidth:0}}),h.jsx(Te,{label:"Apply URL",children:h.jsx(_e,{type:"submit","aria-label":"Apply URL",icon:h.jsx(K.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:V||a||!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],hm=["gray.900",wt,"gray.600","gray.200","white"];function pm(){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(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:e})}function nt({value:e,placeholder:t,ariaLabel:r,width:n="140px",type:o="text",min:i,onCommit:a}){const{colorText:s}=Ye(),[c,u]=_.useState(e),l=_.useRef(!1);_.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&&a(f)};return h.jsx(B.Input,{"aria-label":r,type:o,min:i,size:"xs",fontSize:"16px",w:n,value:c,placeholder:t,color:s,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 vt({colors:e,value:t,label:r,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:a,colorText:s}=Ye(),[c,u]=_.useState(!1),l=_.useId(),d=_.useRef(null),f=t??e[0]??"transparent";return h.jsxs(B.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(Te,{label:`${r}: ${f}`,children:h.jsx(B.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:me(f),...f==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${me(s)}`,outlineOffset:"1px",onClick:()=>u(p=>!p)})}),c&&h.jsxs(B.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(B.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(s)}`:"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(Te,{label:`Reset ${r.toLowerCase()}`,children:h.jsx(_e,{"aria-label":`Reset ${r}`,icon:h.jsx(B.Icon,{as:K.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:a,onClick:()=>{var p;o(),u(!1),(p=d.current)==null||p.focus()}})})]})]})}function gm({edgeId:e,onClose:t}){var p;const{callbacks:r,themeColor:n,config:o}=$e(),{colorInactive:i}=Ye(),{edgeById:a}=Hr(),{palette:s,show:c}=pm(),u=(p=a.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:K.PiLineSegment,label:"Solid"},{key:"dashed",icon:K.PiLineSegments,label:"Dashed"},{key:"animated",icon:K.PiFastForward,label:"Animated"}];return h.jsxs(h.Fragment,{children:[h.jsx(Ct,{onClick:t}),c("label")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(nt,{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(dr,{}),f.map(y=>h.jsx(Te,{label:y.label,children:h.jsx(_e,{"aria-label":`Edge style ${y.key}`,"aria-pressed":d===y.key,icon:h.jsx(B.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(fm,{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(vr,{"aria-label":"Edge shape",title:`Edge shape: ${(u==null?void 0:u.type)??"Default"}`,icon:h.jsx(K.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(dr,{}),h.jsx(Du,{edgeId:e,value:u==null?void 0:u.icon},e),h.jsx(nt,{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(dr,{}),h.jsx(vt,{label:"Edge color",colors:s,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(dr,{}),h.jsx(Te,{label:"Delete edge",children:h.jsx(_e,{"aria-label":"Delete edge",icon:h.jsx(B.Icon,{as:K.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var y;(y=r.onEdgeDelete)==null||y.call(r,e,u),t()}})})]})]})}function ym({ids:e,showDivider:t=!0}){const{callbacks:r,config:n}=$e(),{colorInactive:o}=Ye(),{nodeById:i}=Hr(),[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=a||!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(dr,{}),h.jsx(B.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:h.jsxs(vr,{icon:h.jsx(B.Icon,{as:cv.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=>{s(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(nt,{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 mm({ids:e,onClose:t}){var le,$,D,G,N,ee,ye,fe;const{callbacks:r,colorMode:n,themeColor:o,config:i,setNodeViewMode:a}=$e(),{colorText:s,colorInactive:c}=Ye(),{nodeById:u,parentIds:l}=Hr(),{palette:d,show:f}=pm(),p=e.length===1,y=p?(le=u.get(e[0]))==null?void 0:le.data:void 0,g=e.map(J=>{var Y,U;return((U=(Y=u.get(J))==null?void 0:Y.data.config)==null?void 0:U.typeView)??""}),b=g.some(J=>J!==g[0]),x=b?"mixed":g[0]??"",m=e.some(J=>{var U,se;const Y=(U=u.get(J))==null?void 0:U.data;return Y&&(l.has(J)||((se=Y.config)==null?void 0:se.parentContainer)||Object.prototype.hasOwnProperty.call(i.customViews??{},Y.type))}),w=($=y==null?void 0:y.config)==null?void 0:$.collapsed,v=dm(e[0]),C=J=>{var Y,U,se;return(((U=(Y=u.get(J))==null?void 0:Y.data.viewProps)==null?void 0:U.outline)??(l.has(J)?(se=i.parentNodeStyle)==null?void 0:se.outline:!1))===!0},S=e.every(C),j=!S&&e.some(C),T=J=>{var Y;return((Y=u.get(J))==null?void 0:Y.data.isNodeAnimated)===!0},P=e.every(T),M=!P&&e.some(T),R=e.map(J=>{var Y;return((Y=u.get(J))==null?void 0:Y.data.nodeAnimationVariant)??"traveling"}),E=R.every(J=>J===R[0])?R[0]:"",k=J=>e.forEach(J),[I,q]=_.useState(!1),O=I&&f("color")&&f("borderColor"),W=J=>{var Y,U,se;return(((U=(Y=u.get(J))==null?void 0:Y.data.viewProps)==null?void 0:U.borderStyle)??(l.has(J)?(se=i.parentNodeStyle)==null?void 0:se.borderStyle:"solid"))==="dashed"},V=e.every(W),ue=!V&&e.some(W),ne=e.map(J=>{var se,te,xe;const Y=(se=u.get(J))==null?void 0:se.data,U=l.has(J)?en((te=i.parentNodeStyle)==null?void 0:te.borderWidth,6):(Y==null?void 0:Y.type)==="objectView"?3:2;return en((xe=Y==null?void 0:Y.viewProps)==null?void 0:xe.borderWidth,U)}),Q=ne.every(J=>J===ne[0])?String(ne[0]??""):"",pe=J=>k(Y=>{var U,se;O?(U=r.onNodeBorderColorChange)==null||U.call(r,Y,J):(se=r.onNodeColorChange)==null||se.call(r,Y,"bg",J)});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:J=>{var Y;return(Y=r.onNodeLabelChange)==null?void 0:Y.call(r,e[0],J)}}):h.jsxs(B.Text,{fontSize:"xs",color:s,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),f("typeView")&&h.jsxs(vr,{"aria-label":"Type view",title:m?"Type view is managed by the custom renderer or container":`Type view: ${x||"None (default)"}`,icon:h.jsx(K.PiImage,{size:20}),style:{width:36},value:x,disabled:i.readOnly||i.editable===!1||m,onValueChange:J=>{Kt.includes(J)&&k(Y=>{var U,se;(U=r.onNodeTypeViewChange)==null||U.call(r,Y,J||void 0),a(Y,"default"),(se=r.onNodeViewToggle)==null||se.call(r,Y)})},children:[b&&h.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),Kt.map(J=>h.jsx("option",{value:J,children:J||"None"},J))]}),f("style")&&h.jsx(ym,{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(_e,{"aria-label":"Toggle node outline","aria-pressed":j?"mixed":S,icon:h.jsx(B.Icon,{as:S?K.PiSquare:K.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:S?o:c,onClick:()=>k(J=>{var Y;return(Y=r.onNodeOutlineChange)==null?void 0:Y.call(r,J,!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(_e,{"aria-label":"Edit node border","aria-pressed":O,icon:h.jsx(B.Icon,{as:K.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:O?o:c,bg:O?n==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>q(J=>!J)})}),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:pe,onReset:()=>pe("")}),O&&f("style")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(Te,{label:V?"Solid border":"Dashed border",children:h.jsx(_e,{"aria-label":"Toggle dashed border","aria-pressed":ue?"mixed":V,icon:h.jsx(B.Icon,{as:V?K.PiLineSegments:K.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:V?o:c,onClick:()=>k(J=>{var Y;return(Y=r.onNodeBorderStyleChange)==null?void 0:Y.call(r,J,V?"solid":"dashed")})})}),h.jsx(nt,{ariaLabel:"Border thickness",placeholder:p?"Auto":"Mixed",width:"64px",type:"number",min:0,value:Q,onCommit:J=>k(Y=>{var U;return(U=r.onNodeBorderWidthChange)==null?void 0:U.call(r,Y,J===""?void 0:Number(J))})})]})]}),f("animation")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(Te,{label:P?"Stop border animation":"Animate node border",children:h.jsx(_e,{"aria-label":"Toggle node animation","aria-pressed":M?"mixed":P,icon:h.jsx(B.Icon,{as:K.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:P?o:c,onClick:()=>k(J=>{var Y;return(Y=r.onNodeAnimationChange)==null?void 0:Y.call(r,J,!P)})})}),(P||M)&&h.jsx(fm,{label:"Node animation",value:E,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:i.readOnly,onChange:J=>k(Y=>{var U;return(U=r.onNodeAnimationVariantChange)==null?void 0:U.call(r,Y,J)})})]}),!O&&f("textColor")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(vt,{label:"Text color",colors:hm,value:(ee=y==null?void 0:y.viewProps)==null?void 0:ee.textColor,onPick:J=>k(Y=>{var U;return(U=r.onNodeColorChange)==null?void 0:U.call(r,Y,"text",J)}),onReset:()=>k(J=>{var Y;return(Y=r.onNodeColorChange)==null?void 0:Y.call(r,J,"text","")})})]}),p&&f("icon")&&h.jsxs(h.Fragment,{children:[h.jsx(dr,{}),h.jsx(Du,{nodeId:e[0],value:(ye=y==null?void 0:y.config)==null?void 0:ye.icon},e[0]),h.jsx(nt,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((fe=y==null?void 0:y.config)==null?void 0:fe.icon)||"",onCommit:J=>{var Y;return(Y=r.onNodeIconChange)==null?void 0:Y.call(r,e[0],J)}})]}),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(_e,{"aria-label":w?"Expand node":"Collapse node",icon:h.jsx(B.Icon,{as:w?K.PiArrowsOutLineVertical:K.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:c,onClick:()=>{var J;return(J=r.onNodeCollapse)==null?void 0:J.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(_e,{"aria-label":"Delete selected nodes",icon:h.jsx(B.Icon,{as:K.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:n==="dark"?"red.300":"red.500",onClick:()=>{k(J=>{var Y,U;return(U=r.onNodeDelete)==null?void 0:U.call(r,J,((Y=u.get(J))==null?void 0:Y.data)||{id:J})}),t()}})})]})]})}async function bm(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 vm(e,t="squeed.svg"){const r=document.createElement("a");r.href=await bm(e),r.download=t.endsWith(".svg")?t:`${t}.svg`,r.click()}function xm(){const{themeColor:e}=$e(),[t,r]=_.useState(!1),[n,o]=_.useState("");return h.jsxs(h.Fragment,{children:[h.jsx(Te,{label:"Download SVG (current view)",children:h.jsx(_e,{"aria-label":"Download SVG",icon:h.jsx(K.PiDownloadSimpleFill,{size:20}),disabled:t,borderRadius:"30%",color:e,variant:"ghost",onClick:async i=>{var s;const a=(s=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:s.querySelector("[data-flow-background]");if(!a){o("Diagram not available for export.");return}r(!0),o("");try{await vm(a)}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 wm({children:e,background:t,border:r,endElement:n}){const o=_.useRef(null),[i,a]=_.useState({left:!1,right:!1});_.useLayoutEffect(()=>{const c=o.current,u=()=>{const f=c.scrollLeft>1,p=c.scrollWidth-c.clientWidth-c.scrollLeft>1;a(y=>y.left===f&&y.right===p?y:{left:f,right:p})},l=f=>{if(f.defaultPrevented||f.ctrlKey||f.deltaX!==0||!f.deltaY||c.scrollWidth<=c.clientWidth)return;f.preventDefault();const p=f.deltaMode===WheelEvent.DOM_DELTA_LINE?16:f.deltaMode===WheelEvent.DOM_DELTA_PAGE?c.clientWidth:1;c.scrollLeft+=f.deltaY*p},d=new ResizeObserver(u);return d.observe(c),c.firstElementChild&&d.observe(c.firstElementChild),c.addEventListener("scroll",u,{passive:!0}),c.addEventListener("wheel",l,{passive:!1}),u(),()=>{d.disconnect(),c.removeEventListener("scroll",u),c.removeEventListener("wheel",l)}},[]);const s=`var(--chakra-colors-${t.replace(".","-")})`;return h.jsxs(B.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(B.Box,{ref:o,"data-flow-toolbar-scroll":"",h:50,minH:50,alignContent:"center",overflowX:"auto",overflowY:"hidden",mr:n?"44px":void 0,borderRadius:"inherit",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e}),["left","right"].map(c=>h.jsx(B.Box,{"data-flow-toolbar-fade":c,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",borderRadius:c==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[c]:c==="right"&&n?44:0,opacity:i[c]?1:0,background:`linear-gradient(to ${c==="left"?"right":"left"}, ${s}, transparent)`}},c)),n&&h.jsx(B.Box,{position:"absolute",right:"6px",top:0,h:"50px",w:"32px",display:"flex",alignItems:"center",justifyContent:"center",children:n})]})}async function p0(e,t){const r=new Set,n=[],o=(s,c)=>{var l,d,f;if(!s||typeof s!="object")return;const u=s;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 am(e)};const i=await zu(e,[...r]);for(const s of r)if(!Object.prototype.hasOwnProperty.call(i,s))throw new Error(`Missing form type: ${s}`);const a={};for(const s of n){const c=_t(t,s,i);c&&(a[s]={type:c.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:a}}}function Cm({message:e,onDismiss:t}){const{background:r,colorText:n,border:o}=Ye();return!e||typeof document>"u"?null:Ht.createPortal(h.jsxs(B.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(K.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 _m({showDivider:e=!0,compact:t=!1}={}){const{edgeMode:r,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:a,readOnly:s,themeColor:c}=$e(),{edgeById:u}=Hr(),{data:l,schema:d,setSchema:f,bindings:p,structured:y}=_.useContext(xr),g=(y==null?void 0:y.sourceBindings)??p,b=(y==null?void 0:y.sourceSchema)??d,{colorText:x}=Ye(),m=_.useRef(null),w=_.useRef(0),[v,C]=_.useState(!1),[S,j]=_.useState("");_.useEffect(()=>()=>{w.current++},[]),_.useEffect(()=>{w.current++,C(!1)},[s,l,g]);const T=o?[...u.values()].filter(M=>Bu(o,M.data)).length:0,P=o?`${o.name}: ${b?`${Object.keys(b).length} form types loaded; `:""}${T} invalid or unverified connections`:"";return h.jsxs(h.Fragment,{children:[h.jsx(Cm,{message:S,onDismiss:()=>j("")}),e&&h.jsx(Ft,{}),h.jsxs(vr,{"aria-label":"Edge mode",title:r==="auto"?"Connections: Auto":r==="properties"?"Connections: Properties":"Connections: Nodes",icon:r==="auto"?h.jsx(K.PiGraph,{size:20}):r==="properties"?h.jsx(K.PiTable,{size:20}):h.jsx(K.PiTreeStructure,{size:20}),style:{width:36},value:r,disabled:s,onValueChange:M=>{var E;const R=M==="auto"?"auto":M==="properties"?"properties":"nodes";n(R),(E=a.onEdgeModeChange)==null||E.call(a,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(_e,{"aria-label":"Upload workflow interface",icon:h.jsx(K.PiUploadSimple,{size:20}),color:me(c),size:"sm",variant:"ghost",disabled:v||s,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:s||v,onChange:async M=>{var k,I;const R=(k=M.target.files)==null?void 0:k[0];if(M.target.value="",!R)return;const E=++w.current;C(!0),j("");try{const q=g?await zu(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 p0(R,l);if(E!==w.current)return;f==null||f(W),i(O),(I=a.onWorkflowContractChange)==null||I.call(a,O)}catch(q){E===w.current&&j(`${R.name}: ${q instanceof Error?q.message:"Unable to load interface."}`)}finally{E===w.current&&C(!1)}}}),!t&&(P||v)&&h.jsx("span",{role:"status",title:P,style:{color:me(x),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v?"Loading interface...":P}),!t&&o&&h.jsx(Te,{label:"Remove workflow interface",children:h.jsx(_e,{"aria-label":"Remove workflow interface",icon:h.jsx(K.PiX,{size:16}),size:"sm",variant:"ghost",disabled:s||v,onClick:()=>{var M;f==null||f(void 0),i(void 0),(M=a.onWorkflowContractChange)==null||M.call(a,void 0),j("")}})})]})]})}const g0=[{value:"BT",label:"Bottom to Up",icon:K.PiArrowUp,flowType:It.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:K.PiArrowDown,flowType:It.TOP_DOWN},{value:"LR",label:"Left to Right",icon:K.PiArrowRight,flowType:It.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:K.PiArrowLeft,flowType:It.RIGHT_LEFT}],Sm=()=>{const{engineRef:e,themeColor:t,setThemeColor:r,edgeColor:n,setEdgeColor:o,backgroundSelected:i,setBackgroundSelected:a,direction:s,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:S,isArrayNodeMode:j,setIsArrayNodeMode:T,isPinned:P,setIsPinned:M,callbacks:R,config:E,readOnly:k}=$e(),{nodeById:I,edgeById:q,parentIds:O}=Hr(),W=E.colorMode==="dark",{background:V,border:ue,colorInactive:ne,colorText:Q,colorActive:pe}=Ye(),le=W?ue:"gray.300",$=`var(--chakra-colors-${V.replace(".","-")})`,D=`var(--chakra-colors-${(W?ue:"gray.300").replace(".","-")})`,[G,N]=_.useState(!1),[ee,ye]=_.useState(!0),fe=_.useRef(null),J=vy({edge:"bottom",enabled:!P,bounds:fe,inside:[fe]}),Y=_.useCallback(we=>{const Se=e.current;if(!Se)return;const He=E.minZoom??.01,Xe=E.maxZoom??1.5,ur=.02;let er=Se.zoom();switch(we){case"increase":er=Math.min(Xe,er+ur),Se.zoom(er),Se.center();break;case"decrease":er=Math.max(He,er-ur),Se.zoom(er),Se.center();break;case"reset":Se.fit(50);break}},[e,E.minZoom,E.maxZoom]),U=E.renderSelectedNodeToolbar,se=d.length>0&&!!U,te=_.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=_.useCallback(()=>{var we;f([]),(we=R.onNodeDeselect)==null||we.call(R)},[f,R]),ge=E.renderSelectedEdgeToolbar,De=!!p&&!!ge,Z=_.useMemo(()=>{var we;return!De||!p?null:((we=q.get(p))==null?void 0:we.data)??{id:p}},[De,p,q]),de=_.useCallback(()=>{var we;y(null),(we=R.onEdgeDeselect)==null||we.call(R)},[y,R]),Ce=E.selectionToolbar!==!1&&!k,Oe=Ce&&!!p&&!ge,qe=Ce&&!Oe&&d.length>0&&!U,Ue=Oe||qe,Qe=P||J||G||Ue;_.useEffect(()=>{d.length||p?a(!1):i&&!k&&(M(!0),ye(!1))},[i,d.length,p,k,a,M]);const We=E.renderBottomBar;return We?h.jsxs(h.Fragment,{children:[se&&h.jsx(B.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:U({selectedNodeIds:d,selectedNodeData:te,onDeselect:xe})}),De&&Z&&h.jsx(B.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:ge({edgeId:p,edgeData:Z,onDeselect:de})}),h.jsx(B.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:We({zoomIn:()=>Y("increase"),zoomOut:()=>Y("decrease"),resetZoom:()=>Y("reset"),direction:s,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(B.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:U({selectedNodeIds:d,selectedNodeData:te,onDeselect:xe})}),De&&Z&&h.jsx(B.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:ge({edgeId:p,edgeData:Z,onDeselect:de})}),h.jsx(B.Box,{ref:fe,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(B.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(wm,{background:V,border:W?ue:"gray.300",children:h.jsxs(B.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[Oe?h.jsx(gm,{edgeId:p,onClose:de}):qe?h.jsx(mm,{ids:d,onClose:xe}):null,h.jsxs("div",{style:{display:Oe||qe?"none":"contents"},children:[h.jsx(Te,{label:P?"Unpin":"Pin",children:h.jsx(_e,{"aria-label":"Pin",icon:h.jsx(B.Icon,{as:P?K.PiPushPinFill:K.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:P?t:ne,onClick:()=>{M(!P),N(!1)}})}),h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:"Zoom Out",children:h.jsx(_e,{"aria-label":"Zoom out",icon:h.jsx(B.Icon,{as:K.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:Q,onClick:()=>Y("decrease")})}),h.jsx(Te,{label:"Zoom In",children:h.jsx(_e,{"aria-label":"Zoom in",icon:h.jsx(B.Icon,{as:K.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:Q,onClick:()=>Y("increase")})}),h.jsx(Te,{label:"Reset Zoom",children:h.jsx(_e,{"aria-label":"Reset zoom",icon:h.jsx(B.Icon,{as:K.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:Q,onClick:()=>Y("reset")})}),!ee&&h.jsxs(h.Fragment,{children:[h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:g?"Zoom Mode (z)":"Pan Mode (z)",children:h.jsx(_e,{"aria-label":"Toggle zoom mode",icon:h.jsx(B.Icon,{as:g?K.PiMagnifyingGlassPlus:K.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:g?t:ne,onClick:()=>b(!g)})}),h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:x?"Multi-Select On (m)":"Multi-Select Off (m)",children:h.jsx(_e,{"aria-label":"Toggle multi-select",icon:h.jsx(B.Icon,{as:K.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:x?t:ne,onClick:()=>m(!x)})}),h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:w?"Drag Mode On (d)":"Drag Mode Off (d)",children:h.jsx(_e,{"aria-label":"Toggle drag mode",icon:h.jsx(B.Icon,{as:K.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:w?t:ne,onClick:()=>v(!w)})}),E.edgeHandles!==!1&&h.jsxs(h.Fragment,{children:[h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:C?"Draw Mode On":"Draw Mode Off",children:h.jsx(_e,{"aria-label":"Toggle draw mode",icon:h.jsx(B.Icon,{as:K.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:C?t:ne,onClick:()=>S(!C)})})]}),E.bottomBarExtra&&h.jsxs(h.Fragment,{children:[h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le,role:"separator","aria-orientation":"vertical"}),E.bottomBarExtra]}),h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le,role:"separator","aria-orientation":"vertical"}),h.jsx(Hy,{}),h.jsx(Iu,{label:"Collapse all",checked:u,icon:h.jsx(B.Icon,{as:K.PiArrowsInLineVertical,boxSize:5}),onChange:l}),c!=="properties"&&h.jsxs(h.Fragment,{children:[h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:j?"Array Mode [ ]":"Set Mode { }",children:h.jsx(_e,{"aria-label":"Toggle array mode",icon:h.jsx(B.Icon,{as:j?K.PiBracketsSquare:K.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:j?t:ne,onClick:()=>{var Se;const we=!j;T(we),(Se=R.onArrayModeChange)==null||Se.call(R,we)}})})]}),i&&!k&&h.jsxs(h.Fragment,{children:[h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(vt,{label:"Graph theme",colors:bn,value:t,includeTransparent:!1,onPick:we=>{var Se;r(we),(Se=R.onThemeColorChange)==null||Se.call(R,we)}})]}),h.jsx(_m,{}),!k&&h.jsx(vt,{label:"Graph edge color",colors:bn,value:n||(W?"gray.500":wt),onPick:o,onReset:()=>o("")}),h.jsx(Jy,{})]}),h.jsx(B.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),h.jsx(Te,{label:ee?"Expand toolbar":"Collapse toolbar",children:h.jsx(_e,{"aria-label":"Toggle toolbar collapse",icon:h.jsx(B.Icon,{as:ee?K.PiCaretRight:K.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:ne,onClick:()=>ye(!ee)})}),!ee&&h.jsx(xm,{})]})]})}),!Ue&&h.jsxs(B.Box,{position:"relative",ml:"auto",flexShrink:0,children:[h.jsx(B.Box,{"data-flow-direction-control":"",bg:V,borderRadius:"30px",h:50,css:Vr($,D),px:3,cursor:"pointer",onClick:()=>N(!G),children:h.jsxs(B.Flex,{align:"center",h:"100%",children:[h.jsx(Te,{label:"Flow Direction",children:h.jsx(_e,{"aria-label":"Direction",icon:h.jsx(B.Icon,{as:K.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:ne})}),h.jsx(B.Text,{fontSize:"xs",color:W?"whiteAlpha.600":"blackAlpha.500",ml:1,children:s})]})}),G&&h.jsx(B.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:h.jsxs(B.Box,{bg:V,borderRadius:"30px",p:2,minW:"180px",css:Vr($,D),children:[g0.map(we=>h.jsxs(B.Flex,{align:"center",gap:3,px:3,py:2,css:_u,cursor:"pointer",_hover:{bg:W?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Se;(Se=R.onDirectionChange)==null||Se.call(R,we.value),N(!1)},children:[h.jsx(B.Icon,{as:we.icon,boxSize:5,color:Q}),h.jsx(B.Text,{fontSize:"sm",color:Q,flex:1,whiteSpace:"nowrap",children:we.label}),s===we.value&&h.jsx(B.Icon,{as:K.PiCheck,boxSize:4,color:pe})]},we.value)),h.jsxs(B.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(B.Icon,{as:K.PiAlignCenterHorizontal,boxSize:5,color:Q}),h.jsx(B.Text,{fontSize:"sm",color:Q,flex:1,whiteSpace:"nowrap",children:"Center"}),s==="C"&&h.jsx(B.Icon,{as:K.PiCheck,boxSize:4,color:pe})]})]})})]})]})})]})};Sm.displayName="BottomBar";const Em=_.memo(Sm);function y0({checked:e,onChange:t,disabled:r,label:n="Connected nodes"}){return h.jsx(Iu,{label:n,checked:e,onChange:t,disabled:r,icon:h.jsx(B.Icon,{as:K.PiGraph,boxSize:5})})}const Ml={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function jm(e,t){const r=new Map,n=(i,a)=>{if(Object.is(i,a))return!0;if(!i||!a||typeof i!="object"||typeof a!="object"||Array.isArray(i)!==Array.isArray(a))return!1;const s=Object.keys(i);return s.length===Object.keys(a).length&&s.every(c=>Object.prototype.hasOwnProperty.call(a,c)&&n(i[c],a[c]))},o=(i,a,s)=>{if(i===a)return!0;if(!i||!a||typeof i!="object"||typeof a!="object"||Array.isArray(i)!==Array.isArray(a))return!1;const c=new Set([...Object.keys(i),...Object.keys(a)]);for(const u of c)if(!n(i[u],a[u])){if(Object.prototype.hasOwnProperty.call(Ml,u)){if(typeof a[u]!="string"||!a[u])return!1;r.set(s,{...r.get(s),[Ml[u]]:a[u]})}else if(u.startsWith("$")&&u!=="$"||!o(i[u],a[u],u==="$"?s:`${s}.${u}`))return!1}return!0};if(o(e,t,"root"))return r}function m0(e,t){return jm(e,t)!==void 0}function b0(e,t,r){if(e===t)return r;const n=jm(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 a=n.get(i.data.id),s=je(e,i.data.id),c=je(t,i.data.id);return!a&&s===c?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(c,null,2)}:{},...a?{viewProps:{...i.data.viewProps,...a},config:{...i.data.config,...a}}:{}}}})}}function ju(e){return e.kind==="literal"?e.value:e.kind==="union"?ju(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,t])=>!t.optional).map(([t,r])=>[t,ju(r.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Rm(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 a=i.pop(),s=["root",...i].join("."),c=_t(e,s,r),u=(x=c==null?void 0:c.type.properties[a])==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)||Sr(l.properties[w].type,v,!l.properties[w].optional))throw new Error(`Invalid creation default: ${w}`);const f={...ju(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,s,w=>({...w,[a]:[]}));else if(!Array.isArray(y)&&!Array.isArray(y==null?void 0:y.$))throw new Error("Form creation destination is not an array.");const g=Nu(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:$u(g.json,t,{target:g.address,label:o.$edgeLabel})}}function v0(e,t){const r=o=>e&&typeof e=="object"&&o in e;let n=1;for(;r(`${t}_${n}`);)n++;return`${t}_${n}`}function km(e,t,r,n,o){const i=(s,c)=>{s!==e&&(e=s,n==null||n(s,c))},a=s=>{var u;const c=(u=t.find(l=>l.data.id===s))==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:s=>{const c=je(e,s.nodeAddress);if(!c||s.nodeId!==void 0&&c.id!==s.nodeId)throw new Error("This form node has moved. Retry the edit.");i(jn(e,s,r.onFormChange),{type:"form",address:s.address,value:s.value})},onNodeLabelChange:(s,c)=>{var u;(u=r.onNodeLabelChange)==null||u.call(r,s,c),i(cr(e,s,"$label",c),{type:"nodeLabel",address:s,key:"$label",value:c})},onNodeContentChange:(s,c)=>{var u;(u=r.onNodeContentChange)==null||u.call(r,s,c),i(cr(e,s,"$content",c),{type:"nodeContent",address:s,key:"$content",value:c})},onNodeTypeViewChange:(s,c)=>{var u;c!==void 0&&!Kt.includes(c)||((u=r.onNodeTypeViewChange)==null||u.call(r,s,c),i(cr(e,s,"$view",c),{type:"nodeStyle",address:s,key:"$view",value:c}))},onNodeColorChange:(s,c,u)=>{var d;(d=r.onNodeColorChange)==null||d.call(r,s,c,u);const l=c==="bg"?"$bgColor":"$textColor";i(cr(e,s,l,u),{type:"nodeColor",address:s,key:l,value:u})},onNodeBorderColorChange:(s,c)=>{var u;(u=r.onNodeBorderColorChange)==null||u.call(r,s,c),i(cr(e,s,"$borderColor",c),{type:"nodeColor",address:s,key:"$borderColor",value:c})},onNodeBorderStyleChange:(s,c)=>{var u;(u=r.onNodeBorderStyleChange)==null||u.call(r,s,c),i(cr(e,s,"$borderStyle",c),{type:"nodeStyle",address:s,key:"$borderStyle",value:c})},onNodeBorderWidthChange:(s,c)=>{var u;c!==void 0&&(!Number.isFinite(c)||c<0)||((u=r.onNodeBorderWidthChange)==null||u.call(r,s,c),i(cr(e,s,"$borderWidth",c),{type:"nodeStyle",address:s,key:"$borderWidth",value:c}))},onNodeBorderRadiusChange:(s,c)=>{var u;c!==void 0&&(!Number.isFinite(c)||c<0)||((u=r.onNodeBorderRadiusChange)==null||u.call(r,s,c),i(cr(e,s,"$borderRadius",c),{type:"nodeStyle",address:s,key:"$borderRadius",value:c}))},onNodeIconChange:(s,c)=>{var u;(u=r.onNodeIconChange)==null||u.call(r,s,c),i(cr(e,s,"$icon",c),{type:"nodeIcon",address:s,key:"$icon",value:c})},onNodeOutlineChange:(s,c)=>{var u;(u=r.onNodeOutlineChange)==null||u.call(r,s,c),i(cr(e,s,"$outline",c),{type:"nodeOutline",address:s,key:"$outline",value:c})},onNodeAnimationChange:(s,c)=>{var u;(u=r.onNodeAnimationChange)==null||u.call(r,s,c),i(cr(e,s,"$isNodeAnimated",c),{type:"nodeAnimation",address:s,key:"$isNodeAnimated",value:c})},onNodeAnimationVariantChange:(s,c)=>{var u;c!=="traveling"&&c!=="pulse"||((u=r.onNodeAnimationVariantChange)==null||u.call(r,s,c),i(cr(e,s,"$nodeAnimationVariant",c),{type:"nodeAnimation",address:s,key:"$nodeAnimationVariant",value:c}))},onNodeCollapse:(s,c)=>{var u;(u=r.onNodeCollapse)==null||u.call(r,s,c),i(em(e,s,c),{type:"nodeCollapse",address:s,key:"$collapsed",value:c})},onNodeCreate:s=>{var p,y;const c=s.sourceNodeId&&Rm(e,s.sourceNodeId,o);if(c){(p=r.onNodeCreate)==null||p.call(r,s),i(c.json,{type:"nodeCreate",address:c.address,value:"form"});return}(y=r.onNodeCreate)==null||y.call(r,s);const u=s.sourceNodeId||"root",l=je(e,u),d=v0(l,s.isArrayMode?"list":"node"),f=Nu(e,u,s.isArrayMode?[]:{},d);i(f.json,{type:"nodeCreate",address:f.address,value:s.isArrayMode?"array":"set"})},onNodeDelete:(s,c)=>{var u;(u=r.onNodeDelete)==null||u.call(r,s,c),i(tm(e,s),{type:"nodeDelete",address:s})},onEdgeCreate:(s,c,u)=>{var d;(d=r.onEdgeCreate)==null||d.call(r,s,c,u);const l=u&&(u.sourceProperty!==void 0||u.targetProperty!==void 0)?{...u,target:c}:void 0;i(l?$u(e,s,l):nm(e,s,c),{type:"edgeCreate",address:s,key:l?"$connections":"$target",value:l??c})},onEdgeLabelChange:(s,c)=>{var l;(l=r.onEdgeLabelChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$sourceLabel",c),{type:"edgeLabel",edge:u,key:u.connection?"$connections":"$sourceLabel",value:c})},onEdgeStyleChange:(s,c)=>{var l;(l=r.onEdgeStyleChange)==null||l.call(r,s,c);const u=a(s);u&&i(rm(e,u,c),{type:"edgeStyle",edge:u,value:c})},onEdgeAnimationVariantChange:(s,c)=>{var l;if(c!=="dashed"&&c!=="traveling")return;(l=r.onEdgeAnimationVariantChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$edgeAnimationVariant",c),{type:"edgeStyle",edge:u,key:u.connection?"$connections":"$edgeAnimationVariant",value:c})},onEdgeTypeChange:(s,c)=>{var l;(l=r.onEdgeTypeChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$edgeType",c),{type:"edgeStyle",edge:u,key:u.connection?"$connections":"$edgeType",value:c})},onEdgeIconChange:(s,c)=>{var l;(l=r.onEdgeIconChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$edgeIcon",c||void 0),{type:"edgeStyle",edge:u,key:u.connection?"$connections":"$edgeIcon",value:c})},onEdgeColorChange:(s,c)=>{var l;(l=r.onEdgeColorChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$edgeColor",c),{type:"edgeColor",edge:u,key:u.connection?"$connections":"$edgeColor",value:c})},onEdgeDelete:(s,c)=>{var d;(d=r.onEdgeDelete)==null||d.call(r,s,c);const u=a(s);if(!u)return;const l=om(e,u);l.removed&&i(l.json,{type:"edgeDelete",edge:u,key:u.connection?"$connections":"$target"})}}}const x0=".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 w0({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 C0=".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 _0({path:e,width:t,reversed:r,children:n,onComplete:o}){const i=`flow-edge-reveal-${_.useId().replace(/:/g,"")}`,a=_.useRef(null),[s,c]=_.useState({x:0,y:0,width:1,height:1});return _.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]),_.useLayoutEffect(()=>{var l;const u=(l=a.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",...s,children:h.jsx("path",{ref:a,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 S0=".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 Pm({x:e=0,y:t=0,width:r,height:n,radius:o,color:i,strokeWidth:a=8,path:s,variant:c="traveling"}){const u=_.useId(),l=`flow-sdk-node-border-animation${c==="pulse"?" flow-sdk-node-border-pulse":""}`;if(c==="pulse"){const d=s?"path":"rect",f=s?{d:s}:{x:e,y:t,width:Math.max(0,r),height:Math.max(0,n),rx:Math.max(0,Math.min(o,r/2,n/2))},p=a+36,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:a,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":`${a+16}px`,"--flow-pulse-expanded-width":`${a+36}px`}})]})}return s?h.jsx("path",{className:l,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",d:s,fill:"none",stroke:i,strokeWidth:a,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"}):h.jsx("rect",{className:l,"data-animation-variant":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:a,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const E0=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 ql(e,t,r){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const a of t)(a.parent===i||a.id.startsWith(`${i}.`)||r.some(c=>(c.inverted?c.target:c.source)===i&&(c.inverted?c.source:c.target)===a.id))&&!n.has(a.id)&&(n.add(a.id),o.push(a.id))}return n}function j0(e,t,r){const n=r==="downward"||r==="upward",o=new Map;for(const a of e){if(a.source===a.target||a.sourceProperty||a.targetProperty)continue;const s=t(a.source),c=t(a.target);if(!s||!c)continue;const u=n?c.y-s.y:c.x-s.x,l=Math.abs(u)-(n?s.h+c.h:s.w+c.w)/2;if(l<=320)continue;const d=JSON.stringify([a.source,Math.sign(u)]),f=o.get(d)??[];f.push({edge:a,gap:l,cross:n?c.x-s.x:c.y-s.y}),o.set(d,f)}const i=new Map;for(const a of o.values()){if(new Set(a.map(({edge:c})=>c.target)).size<2)continue;const s=new Map;for(const{edge:c}of a)s.set(c.target,(s.get(c.target)??0)+1);for(const c of[-1,0,1]){const u=a.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:s.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}),R0=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 k0=(e,t)=>e.x1<=t.x2&&e.x2>=t.x1&&e.y1<=t.y2&&e.y2>=t.y1,Nl=(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)}`,P0=e=>e>0?1:e<0?-1:0,$l=(e,t)=>e>0?Math.max(e-t,0):Math.min(e+t,0);function A0(e,t,r,n,o=10){const i=t.x-e.x,a=t.y-e.y,s=$l(i,(e.w+t.w)/2),c=$l(a,(e.h+t.h)/2),u=r==="downward"||r==="upward",l=u?c:s,d=u?a:i,f=P0(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(a)<=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 T0(e,t,r){const n=t.x-e.x,o=t.y-e.y,i=n>0?(r.x2-e.x)/n:n<0?(r.x1-e.x)/n:1/0,a=o>0?(r.y2-e.y)/o:o<0?(r.y1-e.y)/o:1/0,s=Math.min(i,a);return!Number.isFinite(s)||s>=1||s<0?null:{x:e.x+n*s,y:e.y+o*s}}function xt(e,t,r){var a;if(!((a=r.outline)!=null&&a.length))return T0(e,t,ft(r));const n=t.x-e.x,o=t.y-e.y;let i=1/0;return r.outline.forEach((s,c,u)=>{const l=u[(c+1)%u.length],d=l.x-s.x,f=l.y-s.y,p=n*f-o*d;if(Math.abs(p)<1e-9)return;const y=s.x-e.x,g=s.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 Am(e,t,r=.5){const n=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.5,o=t==="top"||t==="bottom",i=t==="top"||t==="left"?-1:1,a={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},s=Math.max(e.w,e.h)*2+1;return{...xt(a,{x:a.x+(o?0:i*s),y:a.y+(o?i*s:0)},e)??{x:o?a.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:a.y},side:t}}function 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 I0(e,t,r,n){const o=gt(e,r.srcDist),i=gt(t,r.tgtDist);if(n==="straight")return Im(o,i,r);const a=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),s=e.side==="bottom"&&t.side==="top"?i.y-o.y:e.side==="top"&&t.side==="bottom"?o.y-i.y:e.side==="right"&&t.side==="left"?i.x-o.x:e.side==="left"&&t.side==="right"?o.x-i.x:void 0,c=s!==void 0&&s>0?Math.min(a,s/2):a,u=gt({...o,side:e.side},c),l=gt({...i,side:t.side},c),d=r.arrowAt==="source"?or(o,u,r.arrowGap):o,f=r.arrowAt==="target"?or(i,l,r.arrowGap):i,p=r.arrowAt==="source"?wr(o,u,r.arrowSize,r.headShape):r.arrowAt==="target"?wr(i,l,r.arrowSize,r.headShape):void 0;if(n==="bezier")return{d:`M${rr(d)} C${rr(u)} ${rr(l)} ${rr(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(s!==void 0&&s<=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 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 a=(i-r)/i;return a<0&&(a=1e-5),{x:t.x+a*n,y:t.y+a*o}}function wr(e,t,r,n="triangle"){const o=e.x-t.x,i=e.y-t.y,a=Math.hypot(o,i)||1,s=o/a,c=i/a,u=(n==="square"?.15:.3)*r,l=.15*r,d=e.x-s*u,f=e.y-c*u;return n==="square"?`M${rr(e)} L${hr(e.x-c*l)} ${hr(e.y+s*l)} L${hr(d-c*l)} ${hr(f+s*l)} L${hr(d+c*l)} ${hr(f-s*l)} L${hr(e.x+c*l)} ${hr(e.y-s*l)} Z`:`M${rr(e)} L${hr(d-c*l)} ${hr(f+s*l)} L${hr(d+c*l)} ${hr(f-s*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 O0(e,t,r,n){const o={x:t.x-e.x,y:t.y-e.y},i={x:r.x-t.x,y:r.y-t.y},a=Math.hypot(o.x,o.y),s=Math.hypot(i.x,i.y),c=o.x*i.y-o.y*i.x;if(a<1e-6||s<1e-6||Math.abs(c)<1e-6)return{p1:t,b:t,p2:t,r:0};const u=Math.min(n,a/2,s/2);return{p1:{x:t.x-o.x/a*u,y:t.y-o.y/a*u},b:t,p2:{x:t.x+i.x/s*u,y:t.y+i.y/s*u},r:u}}function Tm(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 a=-1,s=null;for(let y=e.length-1;y>0;y--){const g=xt(e[y],e[y-1],r);if(g){a=y,s=g;break}}if(!i||!s||o>=a)return null;const c=e.slice(o+1,a),u=c[0]??s,l=c[c.length-1]??i;let d,f,p;if(n.arrowAt==="source"){const y=or(i,u,n.srcDist);d=or(i,u,n.srcDist+n.arrowGap),p=wr(y,u,n.arrowSize,n.headShape)}else d=or(i,u,n.srcDist);if(n.arrowAt==="target"){const y=or(s,l,n.tgtDist);f=or(s,l,n.tgtDist+n.arrowGap),p=wr(y,l,n.arrowSize,n.headShape)}else f=or(s,l,n.tgtDist);return Rn(d,c,f,p,n.radius,n.labelTargetLength,n.labelFraction)}function Rn(e,t,r,n,o,i,a){var f;const s=[e,...t,r],c=[];let u=`M${rr(e)}`;for(let p=1;p<s.length-1;p++){const y=O0(s[p-1],s[p],s[p+1],o);c.push(y),y.r===0?u+=` L${rr(y.b)}`:u+=` L${rr(y.p1)} Q${rr(y.b)} ${rr(y.p2)}`}u+=` 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=c[(d-1)/2];if(p.r===0){const y=s[(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(a!==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,a));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=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:Br(y,g)})}return{d:u,arrow:n,label:l}}function Ll(e,t,r,n,o,i,a){const s=r==="leftward"?-1:1,c={x:e.x+s*(e.w/2+a.srcDist),y:n??e.y},u={x:t.x-s*(t.w/2+a.tgtDist),y:o??t.y},l=Math.max(80,a.arrowGap+a.arrowSize*.3),d=c.x+s*l,f=u.x-s*l;let p;if(s*(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=a.arrowAt==="source"?or(c,p[0],a.arrowGap):c,g=a.arrowAt==="target"?or(u,p[p.length-1],a.arrowGap):u,b=a.arrowAt==="source"?wr(c,p[0],a.arrowSize,a.headShape):a.arrowAt==="target"?wr(u,p[p.length-1],a.arrowSize,a.headShape):void 0;return Rn(y,p,g,b,a.radius)}function Fl(e,t,r,n,o){return Tm(A0(e,t,r,n),e,t,o)}function Bl(e,t,r,n,o,i){const a=n===void 0&&o===void 0&&(r==="downward"||r==="upward"),s=r==="leftward"||a&&r==="upward"?-1:1,c=(u,l,d)=>{const f={x:u.x,y:l??u.y},p=Math.max(u.w,u.h)*2+1,y=xt(f,{x:f.x+(a?0:d*p),y:f.y+(a?d*p:0)},u);return y?{x:y.x+(a?0:d*i),y:y.y+(a?d*i:0)}:a?{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,s),targetPoint:c(t,o,-s)}}function M0(e,t,r,n){const o=r==="downward"||r==="upward",i=r==="leftward"||r==="upward"?-1:1,a=Math.max(100,Math.abs(o?t.y-e.y:t.x-e.x)/2),s={x:e.x+(o?0:i*a),y:e.y+(o?i*a:0)},c={x:t.x-(o?0:i*a),y:t.y-(o?i*a:0)},u=n.arrowAt==="source"?or(e,s,n.arrowGap):e,l=n.arrowAt==="target"?or(t,c,n.arrowGap):t;return{d:`M${rr(u)} C${rr(s)} ${rr(c)} ${rr(l)}`,arrow:n.arrowAt==="source"?wr(e,s,n.arrowSize,n.headShape):n.arrowAt==="target"?wr(t,c,n.arrowSize,n.headShape):void 0,label:{x:(u.x+3*s.x+3*c.x+l.x)/8,y:(u.y+3*s.y+3*c.y+l.y)/8,angle:Br(l.x+c.x-s.x-u.x,l.y+c.y-s.y-u.y)}}}function Im(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"?wr(e,t,r.arrowSize,r.headShape):r.arrowAt==="target"?wr(t,e,r.arrowSize,r.headShape):void 0;return Rn(n,[],o,i,0)}function q0(e,t,r,n=-90,o=-60,i=350){const a=n*Math.PI/180,s=o*Math.PI/180,c=a-Math.PI/2,u=c-s/2,l=c+s/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=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=wr(S,p,r.arrowSize,r.headShape)}else if(r.arrowAt==="source"){const S=m;m=or(g,f,r.srcDist+r.arrowGap),v=wr(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 Om(e){const t=e.querySelector("[data-flow-node-surface]");if(!t)return;const r=e.getBoundingClientRect(),n=r.width/e.offsetWidth;if(!Number.isFinite(n)||n<=0)return;const o=t.getBoundingClientRect();if(!o.width||!o.height)return;const i=t,a=typeof i.getScreenCTM=="function"?i.getScreenCTM():null,s=typeof i.getTotalLength=="function"?i.getTotalLength():0,c=i.points,u=(c==null?void 0:c.numberOfItems)||128,l=a&&s>0?Array.from({length:u},(d,f)=>{const p=c!=null&&c.numberOfItems?c.getItem(f):i.getPointAtLength(s*f/u);return{x:lt((a.a*p.x+a.c*p.y+a.e-r.left)/n),y:lt((a.b*p.x+a.d*p.y+a.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 N0(e,t,r,n,o){var l;const i=o!=="TB"&&o!=="BT",a=i?"top":"left",s=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?Gt(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?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=(c.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)===s?s:a;m.set(w,C<-.001?a:C>.001?s:S)}u.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=Am(x,v,S);return{...w,anchor:j,top:j.y,height:0}}))}return u}function zl(e,t,r){const n=new Set(t.map(s=>s.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const s of t)!o.has(s.id)&&(o.has(s.parent??"")||s.id.startsWith(`${e}.`))&&(o.add(s.id),i=!0)}const a=new Set(o);for(const s of r)o.has(s.source)&&n.has(s.target)&&a.add(s.target),o.has(s.target)&&n.has(s.source)&&a.add(s.source);return a}const 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 $0(e,t,r){const n=[];for(const o of String(e).split(`
209
- `)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let a="";for(const s of i){const c=a?`${a} ${s}`:s;!a||kn(c,t)<=r?a=c:(n.push(a),a=s)}n.push(a)}return n}const L0=e=>e.stopPropagation();function F0({id:e,rect:t,label:r,labelLayer:n,style:o,onSelect:i,onCollapse:a,selected:s=!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?kn(r,`bold ${o.fontSize}px ${ot}`):0,g=o.fontSize/5,b=r||s&&a?h.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[s&&a&&h.jsx("foreignObject",{x:f+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(_e,{"aria-label":"Show icon",icon:h.jsx(K.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:o.textColor},onClick:x=>{x.stopPropagation(),a(e)}})})}),r&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:f-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:L0,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(Pm,{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?Ht.createPortal(b,n):b]})}const B0=_.memo(F0),vn=45,Mm=70,Qr=15,qm=50;function Nm(e,t,r=vn){const n=`${r}px ${ot}`,o=e?$0(e,n,200*r/vn):[],i=t?48+(o.length?12:0):0,a=i+Math.max(0,...o.map(u=>kn(u,n))),s=Math.max(o.length*r,t?48:0),c=o.length||t?2*Qr:0;return{lines:o,iconWidth:i,contentWidth:a,contentHeight:s,width:a+c,height:s+c}}const Ut=6,$m=3,Vu=Math.max(Math.pow(Ut*13.37,.9),29)*$m,Lm=Ut*$m*2,hn=80,z0=2*hn+Vu*.3+100,D0=36+2*Math.max(80,Lm+Vu*.3);function Ru(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function ku(e,t){return t==="auto"||(t==="properties"?Ru(e):!Ru(e))}function ht(e,t,r){return r!=="properties"||e!=="root"||t.some(n=>(n.source===e||n.target===e)&&Ru(n))}function V0(e,t,r,n=!1,o){if(!n)return{nodes:e,edges:t};const i=e.filter(s=>ht(s.id,t,r)&&(!o||o.has(s.id))),a=new Set(i.map(s=>s.id));return{nodes:i,edges:t.filter(s=>ku(s,r)&&a.has(s.source)&&a.has(s.target))}}const W0=500,G0="32 18",U0=e=>e.stopPropagation();function H0({id:e,reveal:t,onRevealComplete:r,edgeData:n,validationIssue:o,edgeType:i="rounded-orthogonal",edgeRadius:a,customEdgeTypes:s,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:S,labelBg:j,labelLayer:T,label:P,dashed:M,animated:R,inverted:E,loopIndex:k=0,onSelect:I}){const q=n==null?void 0:n.icon,O=b?vn:Mm,{lines:W,iconWidth:V,contentWidth:ue,contentHeight:ne}=_.useMemo(()=>Nm(P,q,O),[P,q,O]),Q=_.useMemo(()=>{const U={srcDist:hn,tgtDist:hn,arrowGap:Lm,arrowSize:Vu,headShape:b&&(E?f!==void 0||y:p!==void 0||g)?"square":"triangle",radius:a??(w?40:W0),arrowAt:E?"source":"target",labelTargetLength:w?ue+2*Qr:void 0,labelFraction:w?v:void 0},se=f!==void 0||p!==void 0||!!y||!!g,te=Bl(c,u,x,f,p,0),xe=f===void 0&&p===void 0&&(x==="downward"||x==="upward"),ge=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=c.x===u.x&&c.y===u.y,de=y||g?I0(ge,De,{...U,srcDist:18,tgtDist:18},i):se?Ll(c,u,x,f,p,m,{...U,srcDist:18,tgtDist:18,radius:a??Math.min(U.radius,40)}):Z?q0(c,k,{...U,srcDist:0,tgtDist:0}):Fl(c,u,x,m,U);if(!de)return null;const Ce=Bl(c,u,x,f,p,se?18:hn);y&&(Ce.sourcePoint=gt(y,18)),g&&(Ce.targetPoint=gt(g,18));const Oe=Object.prototype.hasOwnProperty.call(s??{},i)?s==null?void 0:s[i]:void 0;if(Oe){const qe={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return Oe({edge:n??{id:e,source:"",target:""},source:{...c},target:{...u},...Ce,direction:qe[x],sourceY:f,targetY:p,inverted:!!E,defaultGeometry:de})??de}return Z||y||g?de:i==="straight"?se?Im(Ce.sourcePoint,Ce.targetPoint,U):Tm([c,u],c,u,U):i==="bezier"?M0(Ce.sourcePoint,Ce.targetPoint,se?x==="leftward"?"leftward":"rightward":x,U):i==="orthogonal"?se?Ll(c,u,x,f,p,m,{...U,srcDist:18,tgtDist:18,radius:0}):Fl(c,u,x,m,{...U,radius:0}):de},[c,e,n,i,a,s,u,b,f,p,y,g,x,m,E,k,w,v,ue]);if(!Q)return null;const pe=(x==="rightward"||x==="leftward")&&!Object.prototype.hasOwnProperty.call(s??{},i)&&!(b&&(f!==void 0||p!==void 0||y||g)),le=pe?`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(s??{},i)?0:qm} 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(Pr,{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)?G0:void 0,ye=R&&!N?`flow-sdk-edge-anim${E?" flow-sdk-edge-anim-rev":""}`:void 0;let fe=null;const J=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;fe=h.jsxs("g",{className:`flow-sdk-edge-label${t?" flow-sdk-edge-reveal-end":""}`,style:J,"data-label-transform":le,"data-label-horizontal":pe||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:P?`Edge icon: ${P}`:"Edge icon"}),h.jsx("rect",{x:-U/2,y:-24,width:48,height:48,fill:"transparent"}),h.jsx(Pr,{name:q,svg:!0,size:48,x:-U/2,y:-24,color:C})]})]})}const Y=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:ye}),N&&h.jsx(w0,{path:Q.d,color:D,width:Ut*1.6,reversed:E})]});return h.jsxs("g",{className:"flow-sdk-edge",style:J,"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:U0,onClick:U=>{U.stopPropagation(),I==null||I(e)},children:[t?h.jsx(_0,{path:Q.d,width:Ut*4,reversed:E,onComplete:()=>r==null?void 0:r(e),children:Y}):Y,Q.arrow&&h.jsx("path",{className:t?"flow-sdk-edge-reveal-end":void 0,d:Q.arrow,fill:o?$:S??D}),T&&fe?Ht.createPortal(fe,T):fe,T&&G?Ht.createPortal(G,T):G,h.jsx("path",{className:"flow-sdk-edge-hit",d:Q.d,fill:"none",stroke:"transparent"})]})}const Dl=_.memo(H0),Vl=(e,t)=>e.left<t.right&&e.right>t.left&&e.top<t.bottom&&e.bottom>t.top;function K0(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 a=[...t.querySelectorAll(".flow-sdk-edge-label")];for(const u of a)u.setAttribute("transform",u.dataset.labelTransform??"");const s=new Map(a.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 a){const l=u.dataset.labelHorizontal==="true",d=s.get(u);s.delete(u);const f=j=>i.some(T=>Vl(j,T))||[...s.values()].some(T=>Vl(j,T));if(!l&&!f(d)){s.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},(j,T)=>p.getPointAtLength(b*T/w)),S=Array.from({length:w+1},(j,T)=>{const P=b*T/w,M=v[T],R=l?{x:M.x,y:M.y-g.height/2-15}:M,E=p.getPointAtLength(Math.max(0,P-2)),k=p.getPointAtLength(Math.min(b,P+2));let I=Math.atan2(k.y-E.y,k.x-E.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?(u.setAttribute("transform",`translate(${S.point.x} ${S.point.y}) rotate(${S.angle})`),s.set(u,S.bounds)):s.set(u,d)}}var fn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function J0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Wu(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,Wl;function Z0(){if(Wl)return to;Wl=1;function e(){this.__data__=[],this.size=0}return to=e,to}var no,Gl;function St(){if(Gl)return no;Gl=1;function e(t,r){return t===r||t!==t&&r!==r}return no=e,no}var oo,Ul;function Pn(){if(Ul)return oo;Ul=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,Hl;function Y0(){if(Hl)return io;Hl=1;var e=Pn(),t=Array.prototype,r=t.splice;function n(o){var i=this.__data__,a=e(i,o);if(a<0)return!1;var s=i.length-1;return a==s?i.pop():r.call(i,a,1),--this.size,!0}return io=n,io}var ao,Kl;function X0(){if(Kl)return ao;Kl=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,Jl;function Q0(){if(Jl)return so;Jl=1;var e=Pn();function t(r){return e(this.__data__,r)>-1}return so=t,so}var co,Zl;function ew(){if(Zl)return co;Zl=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,Yl;function An(){if(Yl)return uo;Yl=1;var e=Z0(),t=Y0(),r=X0(),n=Q0(),o=ew();function i(a){var s=-1,c=a==null?0:a.length;for(this.clear();++s<c;){var u=a[s];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,uo=i,uo}var lo,Xl;function rw(){if(Xl)return lo;Xl=1;var e=An();function t(){this.__data__=new e,this.size=0}return lo=t,lo}var fo,Ql;function tw(){if(Ql)return fo;Ql=1;function e(t){var r=this.__data__,n=r.delete(t);return this.size=r.size,n}return fo=e,fo}var ho,ed;function nw(){if(ed)return ho;ed=1;function e(t){return this.__data__.get(t)}return ho=e,ho}var po,rd;function ow(){if(rd)return po;rd=1;function e(t){return this.__data__.has(t)}return po=e,po}var go,td;function Fm(){if(td)return go;td=1;var e=typeof fn=="object"&&fn&&fn.Object===Object&&fn;return go=e,go}var yo,nd;function jr(){if(nd)return yo;nd=1;var e=Fm(),t=typeof self=="object"&&self&&self.Object===Object&&self,r=e||t||Function("return this")();return yo=r,yo}var mo,od;function Et(){if(od)return mo;od=1;var e=jr(),t=e.Symbol;return mo=t,mo}var bo,id;function iw(){if(id)return bo;id=1;var e=Et(),t=Object.prototype,r=t.hasOwnProperty,n=t.toString,o=e?e.toStringTag:void 0;function i(a){var s=r.call(a,o),c=a[o];try{a[o]=void 0;var u=!0}catch{}var l=n.call(a);return u&&(s?a[o]=c:delete a[o]),l}return bo=i,bo}var vo,ad;function aw(){if(ad)return vo;ad=1;var e=Object.prototype,t=e.toString;function r(n){return t.call(n)}return vo=r,vo}var xo,sd;function it(){if(sd)return xo;sd=1;var e=Et(),t=iw(),r=aw(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function a(s){return s==null?s===void 0?o:n:i&&i in Object(s)?t(s):r(s)}return xo=a,xo}var wo,cd;function Cr(){if(cd)return wo;cd=1;function e(t){var r=typeof t;return t!=null&&(r=="object"||r=="function")}return wo=e,wo}var Co,ud;function on(){if(ud)return Co;ud=1;var e=it(),t=Cr(),r="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function a(s){if(!t(s))return!1;var c=e(s);return c==n||c==o||c==r||c==i}return Co=a,Co}var _o,ld;function sw(){if(ld)return _o;ld=1;var e=jr(),t=e["__core-js_shared__"];return _o=t,_o}var So,dd;function cw(){if(dd)return So;dd=1;var e=sw(),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,fd;function Bm(){if(fd)return Eo;fd=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,hd;function uw(){if(hd)return jo;hd=1;var e=on(),t=cw(),r=Cr(),n=Bm(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,a=Function.prototype,s=Object.prototype,c=a.toString,u=s.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 jo=d,jo}var Ro,pd;function lw(){if(pd)return Ro;pd=1;function e(t,r){return t==null?void 0:t[r]}return Ro=e,Ro}var ko,gd;function at(){if(gd)return ko;gd=1;var e=uw(),t=lw();function r(n,o){var i=t(n,o);return e(i)?i:void 0}return ko=r,ko}var Po,yd;function Gu(){if(yd)return Po;yd=1;var e=at(),t=jr(),r=e(t,"Map");return Po=r,Po}var Ao,md;function Tn(){if(md)return Ao;md=1;var e=at(),t=e(Object,"create");return Ao=t,Ao}var To,bd;function dw(){if(bd)return To;bd=1;var e=Tn();function t(){this.__data__=e?e(null):{},this.size=0}return To=t,To}var Io,vd;function fw(){if(vd)return Io;vd=1;function e(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r}return Io=e,Io}var Oo,xd;function hw(){if(xd)return Oo;xd=1;var e=Tn(),t="__lodash_hash_undefined__",r=Object.prototype,n=r.hasOwnProperty;function o(i){var a=this.__data__;if(e){var s=a[i];return s===t?void 0:s}return n.call(a,i)?a[i]:void 0}return Oo=o,Oo}var Mo,wd;function pw(){if(wd)return Mo;wd=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,Cd;function gw(){if(Cd)return qo;Cd=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,_d;function yw(){if(_d)return No;_d=1;var e=dw(),t=fw(),r=hw(),n=pw(),o=gw();function i(a){var s=-1,c=a==null?0:a.length;for(this.clear();++s<c;){var u=a[s];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,No=i,No}var $o,Sd;function mw(){if(Sd)return $o;Sd=1;var e=yw(),t=An(),r=Gu();function n(){this.size=0,this.__data__={hash:new e,map:new(r||t),string:new e}}return $o=n,$o}var Lo,Ed;function bw(){if(Ed)return Lo;Ed=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,jd;function In(){if(jd)return Fo;jd=1;var e=bw();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,Rd;function vw(){if(Rd)return Bo;Rd=1;var e=In();function t(r){var n=e(this,r).delete(r);return this.size-=n?1:0,n}return Bo=t,Bo}var zo,kd;function xw(){if(kd)return zo;kd=1;var e=In();function t(r){return e(this,r).get(r)}return zo=t,zo}var Do,Pd;function ww(){if(Pd)return Do;Pd=1;var e=In();function t(r){return e(this,r).has(r)}return Do=t,Do}var Vo,Ad;function Cw(){if(Ad)return Vo;Ad=1;var e=In();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,Td;function Uu(){if(Td)return Wo;Td=1;var e=mw(),t=vw(),r=xw(),n=ww(),o=Cw();function i(a){var s=-1,c=a==null?0:a.length;for(this.clear();++s<c;){var u=a[s];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,Wo=i,Wo}var Go,Id;function _w(){if(Id)return Go;Id=1;var e=An(),t=Gu(),r=Uu(),n=200;function o(i,a){var s=this.__data__;if(s instanceof e){var c=s.__data__;if(!t||c.length<n-1)return c.push([i,a]),this.size=++s.size,this;s=this.__data__=new r(c)}return s.set(i,a),this.size=s.size,this}return Go=o,Go}var Uo,Od;function On(){if(Od)return Uo;Od=1;var e=An(),t=rw(),r=tw(),n=nw(),o=ow(),i=_w();function a(s){var c=this.__data__=new e(s);this.size=c.size}return a.prototype.clear=t,a.prototype.delete=r,a.prototype.get=n,a.prototype.has=o,a.prototype.set=i,Uo=a,Uo}var Ho,Md;function Hu(){if(Md)return Ho;Md=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,qd;function zm(){if(qd)return Ko;qd=1;var e=at(),t=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return Ko=t,Ko}var Jo,Nd;function Mn(){if(Nd)return Jo;Nd=1;var e=zm();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,$d;function qn(){if($d)return Zo;$d=1;var e=Mn(),t=St(),r=Object.prototype,n=r.hasOwnProperty;function o(i,a,s){var c=i[a];(!(n.call(i,a)&&t(c,s))||s===void 0&&!(a in i))&&e(i,a,s)}return Zo=o,Zo}var Yo,Ld;function an(){if(Ld)return Yo;Ld=1;var e=qn(),t=Mn();function r(n,o,i,a){var s=!i;i||(i={});for(var c=-1,u=o.length;++c<u;){var l=o[c],d=a?a(i[l],n[l],l,i,n):void 0;d===void 0&&(d=n[l]),s?t(i,l,d):e(i,l,d)}return i}return Yo=r,Yo}var Xo,Fd;function Sw(){if(Fd)return Xo;Fd=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,Bd;function Ar(){if(Bd)return Qo;Bd=1;function e(t){return t!=null&&typeof t=="object"}return Qo=e,Qo}var ei,zd;function Ew(){if(zd)return ei;zd=1;var e=it(),t=Ar(),r="[object Arguments]";function n(o){return t(o)&&e(o)==r}return ei=n,ei}var ri,Dd;function sn(){if(Dd)return ri;Dd=1;var e=Ew(),t=Ar(),r=Object.prototype,n=r.hasOwnProperty,o=r.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(a){return t(a)&&n.call(a,"callee")&&!o.call(a,"callee")};return ri=i,ri}var ti,Vd;function tr(){if(Vd)return ti;Vd=1;var e=Array.isArray;return ti=e,ti}var Nt={exports:{}},ni,Wd;function jw(){if(Wd)return ni;Wd=1;function e(){return!1}return ni=e,ni}Nt.exports;var Gd;function jt(){return Gd||(Gd=1,(function(e,t){var r=jr(),n=jw(),o=t&&!t.nodeType&&t,i=o&&!0&&e&&!e.nodeType&&e,a=i&&i.exports===o,s=a?r.Buffer:void 0,c=s?s.isBuffer:void 0,u=c||n;e.exports=u})(Nt,Nt.exports)),Nt.exports}var oi,Ud;function Nn(){if(Ud)return oi;Ud=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,Hd;function Ku(){if(Hd)return ii;Hd=1;var e=9007199254740991;function t(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return ii=t,ii}var ai,Kd;function Rw(){if(Kd)return ai;Kd=1;var e=it(),t=Ku(),r=Ar(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",a="[object Date]",s="[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]",S="[object Int32Array]",j="[object Uint8Array]",T="[object Uint8ClampedArray]",P="[object Uint16Array]",M="[object Uint32Array]",R={};R[m]=R[w]=R[v]=R[C]=R[S]=R[j]=R[T]=R[P]=R[M]=!0,R[n]=R[o]=R[b]=R[i]=R[x]=R[a]=R[s]=R[c]=R[u]=R[l]=R[d]=R[f]=R[p]=R[y]=R[g]=!1;function E(k){return r(k)&&t(k.length)&&!!R[e(k)]}return ai=E,ai}var si,Jd;function $n(){if(Jd)return si;Jd=1;function e(t){return function(r){return t(r)}}return si=e,si}var $t={exports:{}};$t.exports;var Zd;function Ju(){return Zd||(Zd=1,(function(e,t){var r=Fm(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,a=i&&r.process,s=(function(){try{var c=o&&o.require&&o.require("util").types;return c||a&&a.binding&&a.binding("util")}catch{}})();e.exports=s})($t,$t.exports)),$t.exports}var ci,Yd;function cn(){if(Yd)return ci;Yd=1;var e=Rw(),t=$n(),r=Ju(),n=r&&r.isTypedArray,o=n?t(n):e;return ci=o,ci}var ui,Xd;function Dm(){if(Xd)return ui;Xd=1;var e=Sw(),t=sn(),r=tr(),n=jt(),o=Nn(),i=cn(),a=Object.prototype,s=a.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||s.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 ui=c,ui}var li,Qd;function Ln(){if(Qd)return li;Qd=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,ef;function Vm(){if(ef)return di;ef=1;function e(t,r){return function(n){return t(r(n))}}return di=e,di}var fi,rf;function kw(){if(rf)return fi;rf=1;var e=Vm(),t=e(Object.keys,Object);return fi=t,fi}var hi,tf;function Zu(){if(tf)return hi;tf=1;var e=Ln(),t=kw(),r=Object.prototype,n=r.hasOwnProperty;function o(i){if(!e(i))return t(i);var a=[];for(var s in Object(i))n.call(i,s)&&s!="constructor"&&a.push(s);return a}return hi=o,hi}var pi,nf;function qr(){if(nf)return pi;nf=1;var e=on(),t=Ku();function r(n){return n!=null&&t(n.length)&&!e(n)}return pi=r,pi}var gi,of;function Kr(){if(of)return gi;of=1;var e=Dm(),t=Zu(),r=qr();function n(o){return r(o)?e(o):t(o)}return gi=n,gi}var yi,af;function Pw(){if(af)return yi;af=1;var e=an(),t=Kr();function r(n,o){return n&&e(o,t(o),n)}return yi=r,yi}var mi,sf;function Aw(){if(sf)return mi;sf=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,cf;function Tw(){if(cf)return bi;cf=1;var e=Cr(),t=Ln(),r=Aw(),n=Object.prototype,o=n.hasOwnProperty;function i(a){if(!e(a))return r(a);var s=t(a),c=[];for(var u in a)u=="constructor"&&(s||!o.call(a,u))||c.push(u);return c}return bi=i,bi}var vi,uf;function st(){if(uf)return vi;uf=1;var e=Dm(),t=Tw(),r=qr();function n(o){return r(o)?e(o,!0):t(o)}return vi=n,vi}var xi,lf;function Iw(){if(lf)return xi;lf=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 df;function Wm(){return df||(df=1,(function(e,t){var r=jr(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,a=i?r.Buffer:void 0,s=a?a.allocUnsafe:void 0;function c(u,l){if(l)return u.slice();var d=u.length,f=s?s(d):new u.constructor(d);return u.copy(f),f}e.exports=c})(Lt,Lt.exports)),Lt.exports}var wi,ff;function Gm(){if(ff)return wi;ff=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,hf;function Um(){if(hf)return Ci;hf=1;function e(t,r){for(var n=-1,o=t==null?0:t.length,i=0,a=[];++n<o;){var s=t[n];r(s,n,t)&&(a[i++]=s)}return a}return Ci=e,Ci}var _i,pf;function Hm(){if(pf)return _i;pf=1;function e(){return[]}return _i=e,_i}var Si,gf;function Yu(){if(gf)return Si;gf=1;var e=Um(),t=Hm(),r=Object.prototype,n=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(a){return a==null?[]:(a=Object(a),e(o(a),function(s){return n.call(a,s)}))}:t;return Si=i,Si}var Ei,yf;function Ow(){if(yf)return Ei;yf=1;var e=an(),t=Yu();function r(n,o){return e(n,t(n),o)}return Ei=r,Ei}var ji,mf;function Xu(){if(mf)return ji;mf=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,bf;function Fn(){if(bf)return Ri;bf=1;var e=Vm(),t=e(Object.getPrototypeOf,Object);return Ri=t,Ri}var ki,vf;function Km(){if(vf)return ki;vf=1;var e=Xu(),t=Fn(),r=Yu(),n=Hm(),o=Object.getOwnPropertySymbols,i=o?function(a){for(var s=[];a;)e(s,r(a)),a=t(a);return s}:n;return ki=i,ki}var Pi,xf;function Mw(){if(xf)return Pi;xf=1;var e=an(),t=Km();function r(n,o){return e(n,t(n),o)}return Pi=r,Pi}var Ai,wf;function Jm(){if(wf)return Ai;wf=1;var e=Xu(),t=tr();function r(n,o,i){var a=o(n);return t(n)?a:e(a,i(n))}return Ai=r,Ai}var Ti,Cf;function Zm(){if(Cf)return Ti;Cf=1;var e=Jm(),t=Yu(),r=Kr();function n(o){return e(o,r,t)}return Ti=n,Ti}var Ii,_f;function qw(){if(_f)return Ii;_f=1;var e=Jm(),t=Km(),r=st();function n(o){return e(o,r,t)}return Ii=n,Ii}var Oi,Sf;function Nw(){if(Sf)return Oi;Sf=1;var e=at(),t=jr(),r=e(t,"DataView");return Oi=r,Oi}var Mi,Ef;function $w(){if(Ef)return Mi;Ef=1;var e=at(),t=jr(),r=e(t,"Promise");return Mi=r,Mi}var qi,jf;function Ym(){if(jf)return qi;jf=1;var e=at(),t=jr(),r=e(t,"Set");return qi=r,qi}var Ni,Rf;function Lw(){if(Rf)return Ni;Rf=1;var e=at(),t=jr(),r=e(t,"WeakMap");return Ni=r,Ni}var $i,kf;function Rt(){if(kf)return $i;kf=1;var e=Nw(),t=Gu(),r=$w(),n=Ym(),o=Lw(),i=it(),a=Bm(),s="[object Map]",c="[object Object]",u="[object Promise]",l="[object Set]",d="[object WeakMap]",f="[object DataView]",p=a(e),y=a(t),g=a(r),b=a(n),x=a(o),m=i;return(e&&m(new e(new ArrayBuffer(1)))!=f||t&&m(new t)!=s||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,S=C?a(C):"";if(S)switch(S){case p:return f;case y:return s;case g:return u;case b:return l;case x:return d}return v}),$i=m,$i}var Li,Pf;function Fw(){if(Pf)return Li;Pf=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,Af;function Xm(){if(Af)return Fi;Af=1;var e=jr(),t=e.Uint8Array;return Fi=t,Fi}var Bi,Tf;function Qu(){if(Tf)return Bi;Tf=1;var e=Xm();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,If;function Bw(){if(If)return zi;If=1;var e=Qu();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 zw(){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,Mf;function Dw(){if(Mf)return Vi;Mf=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,qf;function Qm(){if(qf)return Wi;qf=1;var e=Qu();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,Nf;function Vw(){if(Nf)return Gi;Nf=1;var e=Qu(),t=Bw(),r=zw(),n=Dw(),o=Qm(),i="[object Boolean]",a="[object Date]",s="[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]",S="[object Uint16Array]",j="[object Uint32Array]";function T(P,M,R){var E=P.constructor;switch(M){case p:return e(P);case i:case a:return new E(+P);case y:return t(P,R);case g:case b:case x:case m:case w:case v:case C:case S:case j:return o(P,R);case s:return new E;case c:case d:return new E(P);case u:return r(P);case l:return new E;case f:return n(P)}}return Gi=T,Gi}var Ui,$f;function eb(){if($f)return Ui;$f=1;var e=Cr(),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,Lf;function rb(){if(Lf)return Hi;Lf=1;var e=eb(),t=Fn(),r=Ln();function n(o){return typeof o.constructor=="function"&&!r(o)?e(t(o)):{}}return Hi=n,Hi}var Ki,Ff;function Ww(){if(Ff)return Ki;Ff=1;var e=Rt(),t=Ar(),r="[object Map]";function n(o){return t(o)&&e(o)==r}return Ki=n,Ki}var Ji,Bf;function Gw(){if(Bf)return Ji;Bf=1;var e=Ww(),t=$n(),r=Ju(),n=r&&r.isMap,o=n?t(n):e;return Ji=o,Ji}var Zi,zf;function Uw(){if(zf)return Zi;zf=1;var e=Rt(),t=Ar(),r="[object Set]";function n(o){return t(o)&&e(o)==r}return Zi=n,Zi}var Yi,Df;function Hw(){if(Df)return Yi;Df=1;var e=Uw(),t=$n(),r=Ju(),n=r&&r.isSet,o=n?t(n):e;return Yi=o,Yi}var Xi,Vf;function tb(){if(Vf)return Xi;Vf=1;var e=On(),t=Hu(),r=qn(),n=Pw(),o=Iw(),i=Wm(),a=Gm(),s=Ow(),c=Mw(),u=Zm(),l=qw(),d=Rt(),f=Fw(),p=Vw(),y=rb(),g=tr(),b=jt(),x=Gw(),m=Cr(),w=Hw(),v=Kr(),C=st(),S=1,j=2,T=4,P="[object Arguments]",M="[object Array]",R="[object Boolean]",E="[object Date]",k="[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]",pe="[object Symbol]",le="[object WeakMap]",$="[object ArrayBuffer]",D="[object DataView]",G="[object Float32Array]",N="[object Float64Array]",ee="[object Int8Array]",ye="[object Int16Array]",fe="[object Int32Array]",J="[object Uint8Array]",Y="[object Uint8ClampedArray]",U="[object Uint16Array]",se="[object Uint32Array]",te={};te[P]=te[M]=te[$]=te[D]=te[R]=te[E]=te[G]=te[N]=te[ee]=te[ye]=te[fe]=te[O]=te[W]=te[V]=te[ue]=te[ne]=te[Q]=te[pe]=te[J]=te[Y]=te[U]=te[se]=!0,te[k]=te[I]=te[le]=!1;function xe(ge,De,Z,de,Ce,Oe){var qe,Ue=De&S,Qe=De&j,We=De&T;if(Z&&(qe=Ce?Z(ge,de,Ce,Oe):Z(ge)),qe!==void 0)return qe;if(!m(ge))return ge;var we=g(ge);if(we){if(qe=f(ge),!Ue)return a(ge,qe)}else{var Se=d(ge),He=Se==I||Se==q;if(b(ge))return i(ge,Ue);if(Se==V||Se==P||He&&!Ce){if(qe=Qe||He?{}:y(ge),!Ue)return Qe?c(ge,o(qe,ge)):s(ge,n(qe,ge))}else{if(!te[Se])return Ce?ge:{};qe=p(ge,Se,Ue)}}Oe||(Oe=new e);var Xe=Oe.get(ge);if(Xe)return Xe;Oe.set(ge,qe),w(ge)?ge.forEach(function(sr){qe.add(xe(sr,De,Z,sr,ge,Oe))}):x(ge)&&ge.forEach(function(sr,Ee){qe.set(Ee,xe(sr,De,Z,Ee,ge,Oe))});var ur=We?Qe?l:u:Qe?C:v,er=we?void 0:ur(ge);return t(er||ge,function(sr,Ee){er&&(Ee=sr,sr=ge[Ee]),r(qe,Ee,xe(sr,De,Z,Ee,ge,Oe))}),qe}return Xi=xe,Xi}var Qi,Wf;function Kw(){if(Wf)return Qi;Wf=1;var e=tb(),t=4;function r(n){return e(n,t)}return Qi=r,Qi}var ea,Gf;function el(){if(Gf)return ea;Gf=1;function e(t){return function(){return t}}return ea=e,ea}var ra,Uf;function Jw(){if(Uf)return ra;Uf=1;function e(t){return function(r,n,o){for(var i=-1,a=Object(r),s=o(r),c=s.length;c--;){var u=s[t?c:++i];if(n(a[u],u,a)===!1)break}return r}}return ra=e,ra}var ta,Hf;function rl(){if(Hf)return ta;Hf=1;var e=Jw(),t=e();return ta=t,ta}var na,Kf;function tl(){if(Kf)return na;Kf=1;var e=rl(),t=Kr();function r(n,o){return n&&e(n,o,t)}return na=r,na}var oa,Jf;function Zw(){if(Jf)return oa;Jf=1;var e=qr();function t(r,n){return function(o,i){if(o==null)return o;if(!e(o))return r(o,i);for(var a=o.length,s=n?a:-1,c=Object(o);(n?s--:++s<a)&&i(c[s],s,c)!==!1;);return o}}return oa=t,oa}var ia,Zf;function Bn(){if(Zf)return ia;Zf=1;var e=tl(),t=Zw(),r=t(e);return ia=r,ia}var aa,Yf;function ct(){if(Yf)return aa;Yf=1;function e(t){return t}return aa=e,aa}var sa,Xf;function nb(){if(Xf)return sa;Xf=1;var e=ct();function t(r){return typeof r=="function"?r:e}return sa=t,sa}var ca,Qf;function ob(){if(Qf)return ca;Qf=1;var e=Hu(),t=Bn(),r=nb(),n=tr();function o(i,a){var s=n(i)?e:t;return s(i,r(a))}return ca=o,ca}var ua,eh;function ib(){return eh||(eh=1,ua=ob()),ua}var la,rh;function Yw(){if(rh)return la;rh=1;var e=Bn();function t(r,n){var o=[];return e(r,function(i,a,s){n(i,a,s)&&o.push(i)}),o}return la=t,la}var da,th;function Xw(){if(th)return da;th=1;var e="__lodash_hash_undefined__";function t(r){return this.__data__.set(r,e),this}return da=t,da}var fa,nh;function Qw(){if(nh)return fa;nh=1;function e(t){return this.__data__.has(t)}return fa=e,fa}var ha,oh;function ab(){if(oh)return ha;oh=1;var e=Uu(),t=Xw(),r=Qw();function n(o){var i=-1,a=o==null?0:o.length;for(this.__data__=new e;++i<a;)this.add(o[i])}return n.prototype.add=n.prototype.push=t,n.prototype.has=r,ha=n,ha}var pa,ih;function e1(){if(ih)return pa;ih=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,ah;function sb(){if(ah)return ga;ah=1;function e(t,r){return t.has(r)}return ga=e,ga}var ya,sh;function cb(){if(sh)return ya;sh=1;var e=ab(),t=e1(),r=sb(),n=1,o=2;function i(a,s,c,u,l,d){var f=c&n,p=a.length,y=s.length;if(p!=y&&!(f&&y>p))return!1;var g=d.get(a),b=d.get(s);if(g&&b)return g==s&&b==a;var x=-1,m=!0,w=c&o?new e:void 0;for(d.set(a,s),d.set(s,a);++x<p;){var v=a[x],C=s[x];if(u)var S=f?u(C,v,x,s,a,d):u(v,C,x,a,s,d);if(S!==void 0){if(S)continue;m=!1;break}if(w){if(!t(s,function(j,T){if(!r(w,T)&&(v===j||l(v,j,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(a),d.delete(s),m}return ya=i,ya}var ma,ch;function r1(){if(ch)return ma;ch=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,uh;function nl(){if(uh)return ba;uh=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,lh;function t1(){if(lh)return va;lh=1;var e=Et(),t=Xm(),r=St(),n=cb(),o=r1(),i=nl(),a=1,s=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(S,j,T,P,M,R,E){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 c:case u: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 k=o;case y:var I=P&a;if(k||(k=i),S.size!=j.size&&!I)return!1;var q=E.get(S);if(q)return q==j;P|=s,E.set(S,j);var O=n(k(S),k(j),P,M,R,E);return E.delete(S),O;case b:if(v)return v.call(S)==v.call(j)}return!1}return va=C,va}var xa,dh;function n1(){if(dh)return xa;dh=1;var e=Zm(),t=1,r=Object.prototype,n=r.hasOwnProperty;function o(i,a,s,c,u,l){var d=s&t,f=e(i),p=f.length,y=e(a),g=y.length;if(p!=g&&!d)return!1;for(var b=p;b--;){var x=f[b];if(!(d?x in a:n.call(a,x)))return!1}var m=l.get(i),w=l.get(a);if(m&&w)return m==a&&w==i;var v=!0;l.set(i,a),l.set(a,i);for(var C=d;++b<p;){x=f[b];var S=i[x],j=a[x];if(c)var T=d?c(j,S,x,a,i,l):c(S,j,x,i,a,l);if(!(T===void 0?S===j||u(S,j,s,c,l):T)){v=!1;break}C||(C=x=="constructor")}if(v&&!C){var P=i.constructor,M=a.constructor;P!=M&&"constructor"in i&&"constructor"in a&&!(typeof P=="function"&&P instanceof P&&typeof M=="function"&&M instanceof M)&&(v=!1)}return l.delete(i),l.delete(a),v}return xa=o,xa}var wa,fh;function o1(){if(fh)return wa;fh=1;var e=On(),t=cb(),r=t1(),n=n1(),o=Rt(),i=tr(),a=jt(),s=cn(),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),S=i(b),j=C?l:o(g),T=S?l:o(b);j=j==u?d:j,T=T==u?d:T;var P=j==d,M=T==d,R=j==T;if(R&&a(g)){if(!a(b))return!1;C=!0,P=!1}if(R&&!P)return v||(v=new e),C||s(g)?t(g,b,x,m,w,v):r(g,b,j,x,m,w,v);if(!(x&c)){var E=P&&p.call(g,"__wrapped__"),k=M&&p.call(b,"__wrapped__");if(E||k){var I=E?g.value():g,q=k?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,hh;function ub(){if(hh)return Ca;hh=1;var e=o1(),t=Ar();function r(n,o,i,a,s){return n===o?!0:n==null||o==null||!t(n)&&!t(o)?n!==n&&o!==o:e(n,o,i,a,r,s)}return Ca=r,Ca}var _a,ph;function i1(){if(ph)return _a;ph=1;var e=On(),t=ub(),r=1,n=2;function o(i,a,s,c){var u=s.length,l=u,d=!c;if(i==null)return!l;for(i=Object(i);u--;){var f=s[u];if(d&&f[2]?f[1]!==i[f[0]]:!(f[0]in i))return!1}for(;++u<l;){f=s[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,a,b);if(!(x===void 0?t(g,y,r|n,c,b):x))return!1}}return!0}return _a=o,_a}var Sa,gh;function lb(){if(gh)return Sa;gh=1;var e=Cr();function t(r){return r===r&&!e(r)}return Sa=t,Sa}var Ea,yh;function a1(){if(yh)return Ea;yh=1;var e=lb(),t=Kr();function r(n){for(var o=t(n),i=o.length;i--;){var a=o[i],s=n[a];o[i]=[a,s,e(s)]}return o}return Ea=r,Ea}var ja,mh;function db(){if(mh)return ja;mh=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,bh;function s1(){if(bh)return Ra;bh=1;var e=i1(),t=a1(),r=db();function n(o){var i=t(o);return i.length==1&&i[0][2]?r(i[0][0],i[0][1]):function(a){return a===o||e(a,o,i)}}return Ra=n,Ra}var ka,vh;function kt(){if(vh)return ka;vh=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,xh;function ol(){if(xh)return Pa;xh=1;var e=tr(),t=kt(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,a){if(e(i))return!1;var s=typeof i;return s=="number"||s=="symbol"||s=="boolean"||i==null||t(i)?!0:n.test(i)||!r.test(i)||a!=null&&i in Object(a)}return Pa=o,Pa}var Aa,wh;function c1(){if(wh)return Aa;wh=1;var e=Uu(),t="Expected a function";function r(n,o){if(typeof n!="function"||o!=null&&typeof o!="function")throw new TypeError(t);var i=function(){var a=arguments,s=o?o.apply(this,a):a[0],c=i.cache;if(c.has(s))return c.get(s);var u=n.apply(this,a);return i.cache=c.set(s,u)||c,u};return i.cache=new(r.Cache||e),i}return r.Cache=e,Aa=r,Aa}var Ta,Ch;function u1(){if(Ch)return Ta;Ch=1;var e=c1(),t=500;function r(n){var o=e(n,function(a){return i.size===t&&i.clear(),a}),i=o.cache;return o}return Ta=r,Ta}var Ia,_h;function l1(){if(_h)return Ia;_h=1;var e=u1(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,n=e(function(o){var i=[];return o.charCodeAt(0)===46&&i.push(""),o.replace(t,function(a,s,c,u){i.push(c?u.replace(r,"$1"):s||a)}),i});return Ia=n,Ia}var Oa,Sh;function zn(){if(Sh)return Oa;Sh=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 Ma,Eh;function d1(){if(Eh)return Ma;Eh=1;var e=Et(),t=zn(),r=tr(),n=kt(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function a(s){if(typeof s=="string")return s;if(r(s))return t(s,a)+"";if(n(s))return i?i.call(s):"";var c=s+"";return c=="0"&&1/s==-1/0?"-0":c}return Ma=a,Ma}var qa,jh;function fb(){if(jh)return qa;jh=1;var e=d1();function t(r){return r==null?"":e(r)}return qa=t,qa}var Na,Rh;function Dn(){if(Rh)return Na;Rh=1;var e=tr(),t=ol(),r=l1(),n=fb();function o(i,a){return e(i)?i:t(i,a)?[i]:r(n(i))}return Na=o,Na}var $a,kh;function un(){if(kh)return $a;kh=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,Ph;function Vn(){if(Ph)return La;Ph=1;var e=Dn(),t=un();function r(n,o){o=e(o,n);for(var i=0,a=o.length;n!=null&&i<a;)n=n[t(o[i++])];return i&&i==a?n:void 0}return La=r,La}var Fa,Ah;function f1(){if(Ah)return Fa;Ah=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,Th;function h1(){if(Th)return Ba;Th=1;function e(t,r){return t!=null&&r in Object(t)}return Ba=e,Ba}var za,Ih;function hb(){if(Ih)return za;Ih=1;var e=Dn(),t=sn(),r=tr(),n=Nn(),o=Ku(),i=un();function a(s,c,u){c=e(c,s);for(var l=-1,d=c.length,f=!1;++l<d;){var p=i(c[l]);if(!(f=s!=null&&u(s,p)))break;s=s[p]}return f||++l!=d?f:(d=s==null?0:s.length,!!d&&o(d)&&n(p,d)&&(r(s)||t(s)))}return za=a,za}var Da,Oh;function pb(){if(Oh)return Da;Oh=1;var e=h1(),t=hb();function r(n,o){return n!=null&&t(n,o,e)}return Da=r,Da}var Va,Mh;function p1(){if(Mh)return Va;Mh=1;var e=ub(),t=f1(),r=pb(),n=ol(),o=lb(),i=db(),a=un(),s=1,c=2;function u(l,d){return n(l)&&o(d)?i(a(l),d):function(f){var p=t(f,l);return p===void 0&&p===d?r(f,l):e(d,p,s|c)}}return Va=u,Va}var Wa,qh;function gb(){if(qh)return Wa;qh=1;function e(t){return function(r){return r==null?void 0:r[t]}}return Wa=e,Wa}var Ga,Nh;function g1(){if(Nh)return Ga;Nh=1;var e=Vn();function t(r){return function(n){return e(n,r)}}return Ga=t,Ga}var Ua,$h;function y1(){if($h)return Ua;$h=1;var e=gb(),t=g1(),r=ol(),n=un();function o(i){return r(i)?e(n(i)):t(i)}return Ua=o,Ua}var Ha,Lh;function Nr(){if(Lh)return Ha;Lh=1;var e=s1(),t=p1(),r=ct(),n=tr(),o=y1();function i(a){return typeof a=="function"?a:a==null?r:typeof a=="object"?n(a)?t(a[0],a[1]):e(a):o(a)}return Ha=i,Ha}var Ka,Fh;function yb(){if(Fh)return Ka;Fh=1;var e=Um(),t=Yw(),r=Nr(),n=tr();function o(i,a){var s=n(i)?e:t;return s(i,r(a,3))}return Ka=o,Ka}var Ja,Bh;function m1(){if(Bh)return Ja;Bh=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,zh;function mb(){if(zh)return Za;zh=1;var e=m1(),t=hb();function r(n,o){return n!=null&&t(n,o,e)}return Za=r,Za}var Ya,Dh;function b1(){if(Dh)return Ya;Dh=1;var e=Zu(),t=Rt(),r=sn(),n=tr(),o=qr(),i=jt(),a=Ln(),s=cn(),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)||s(p)||r(p)))return!p.length;var y=t(p);if(y==c||y==u)return!p.size;if(a(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,Vh;function bb(){if(Vh)return Xa;Vh=1;function e(t){return t===void 0}return Xa=e,Xa}var Qa,Wh;function vb(){if(Wh)return Qa;Wh=1;var e=Bn(),t=qr();function r(n,o){var i=-1,a=t(n)?Array(n.length):[];return e(n,function(s,c,u){a[++i]=o(s,c,u)}),a}return Qa=r,Qa}var es,Gh;function xb(){if(Gh)return es;Gh=1;var e=zn(),t=Nr(),r=vb(),n=tr();function o(i,a){var s=n(i)?e:r;return s(i,t(a,3))}return es=o,es}var rs,Uh;function v1(){if(Uh)return rs;Uh=1;function e(t,r,n,o){var i=-1,a=t==null?0:t.length;for(o&&a&&(n=t[++i]);++i<a;)n=r(n,t[i],i,t);return n}return rs=e,rs}var ts,Hh;function x1(){if(Hh)return ts;Hh=1;function e(t,r,n,o,i){return i(t,function(a,s,c){n=o?(o=!1,a):r(n,a,s,c)}),n}return ts=e,ts}var ns,Kh;function wb(){if(Kh)return ns;Kh=1;var e=v1(),t=Bn(),r=Nr(),n=x1(),o=tr();function i(a,s,c){var u=o(a)?e:n,l=arguments.length<3;return u(a,r(s,4),c,l,t)}return ns=i,ns}var os,Jh;function w1(){if(Jh)return os;Jh=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,Zh;function C1(){if(Zh)return is;Zh=1;var e=gb(),t=e("length");return is=t,is}var as,Yh;function _1(){if(Yh)return as;Yh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",a="\\u200d",s=RegExp("["+a+e+o+i+"]");function c(u){return s.test(u)}return as=c,as}var ss,Xh;function S1(){if(Xh)return ss;Xh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",a="["+e+"]",s="["+o+"]",c="\\ud83c[\\udffb-\\udfff]",u="(?:"+s+"|"+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+s+"?",s,d,f,a].join("|")+")",w=RegExp(c+"(?="+c+")|"+m+x,"g");function v(C){for(var S=w.lastIndex=0;w.test(C);)++S;return S}return ss=v,ss}var cs,Qh;function E1(){if(Qh)return cs;Qh=1;var e=C1(),t=_1(),r=S1();function n(o){return t(o)?r(o):e(o)}return cs=n,cs}var us,ep;function j1(){if(ep)return us;ep=1;var e=Zu(),t=Rt(),r=qr(),n=w1(),o=E1(),i="[object Map]",a="[object Set]";function s(c){if(c==null)return 0;if(r(c))return n(c)?o(c):c.length;var u=t(c);return u==i||u==a?c.size:e(c).length}return us=s,us}var ls,rp;function R1(){if(rp)return ls;rp=1;var e=Hu(),t=eb(),r=tl(),n=Nr(),o=Fn(),i=tr(),a=jt(),s=on(),c=Cr(),u=cn();function l(d,f,p){var y=i(d),g=y||a(d)||u(d);if(f=n(f,4),p==null){var b=d&&d.constructor;g?p=y?new b:[]:c(d)?p=s(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,tp;function k1(){if(tp)return ds;tp=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,np;function il(){if(np)return fs;np=1;var e=Xu(),t=k1();function r(n,o,i,a,s){var c=-1,u=n.length;for(i||(i=t),s||(s=[]);++c<u;){var l=n[c];o>0&&i(l)?o>1?r(l,o-1,i,a,s):e(s,l):a||(s[s.length]=l)}return s}return fs=r,fs}var hs,op;function P1(){if(op)return hs;op=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,ip;function Cb(){if(ip)return ps;ip=1;var e=P1(),t=Math.max;function r(n,o,i){return o=t(o===void 0?n.length-1:o,0),function(){for(var a=arguments,s=-1,c=t(a.length-o,0),u=Array(c);++s<c;)u[s]=a[o+s];s=-1;for(var l=Array(o+1);++s<o;)l[s]=a[s];return l[o]=i(u),e(n,this,l)}}return ps=r,ps}var gs,ap;function A1(){if(ap)return gs;ap=1;var e=el(),t=zm(),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,sp;function T1(){if(sp)return ys;sp=1;var e=800,t=16,r=Date.now;function n(o){var i=0,a=0;return function(){var s=r(),c=t-(s-a);if(a=s,c>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return ys=n,ys}var ms,cp;function _b(){if(cp)return ms;cp=1;var e=A1(),t=T1(),r=t(e);return ms=r,ms}var bs,up;function Wn(){if(up)return bs;up=1;var e=ct(),t=Cb(),r=_b();function n(o,i){return r(t(o,i,e),o+"")}return bs=n,bs}var vs,lp;function Sb(){if(lp)return vs;lp=1;function e(t,r,n,o){for(var i=t.length,a=n+(o?1:-1);o?a--:++a<i;)if(r(t[a],a,t))return a;return-1}return vs=e,vs}var xs,dp;function I1(){if(dp)return xs;dp=1;function e(t){return t!==t}return xs=e,xs}var ws,fp;function O1(){if(fp)return ws;fp=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,hp;function M1(){if(hp)return Cs;hp=1;var e=Sb(),t=I1(),r=O1();function n(o,i,a){return i===i?r(o,i,a):e(o,t,a)}return Cs=n,Cs}var _s,pp;function q1(){if(pp)return _s;pp=1;var e=M1();function t(r,n){var o=r==null?0:r.length;return!!o&&e(r,n,0)>-1}return _s=t,_s}var Ss,gp;function N1(){if(gp)return Ss;gp=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,yp;function $1(){if(yp)return Es;yp=1;function e(){}return Es=e,Es}var js,mp;function L1(){if(mp)return js;mp=1;var e=Ym(),t=$1(),r=nl(),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,bp;function F1(){if(bp)return Rs;bp=1;var e=ab(),t=q1(),r=N1(),n=sb(),o=L1(),i=nl(),a=200;function s(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>=a){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 Rs=s,Rs}var ks,vp;function Eb(){if(vp)return ks;vp=1;var e=qr(),t=Ar();function r(n){return t(n)&&e(n)}return ks=r,ks}var Ps,xp;function B1(){if(xp)return Ps;xp=1;var e=il(),t=Wn(),r=F1(),n=Eb(),o=t(function(i){return r(e(i,1,n,!0))});return Ps=o,Ps}var As,wp;function z1(){if(wp)return As;wp=1;var e=zn();function t(r,n){return e(n,function(o){return r[o]})}return As=t,As}var Ts,Cp;function jb(){if(Cp)return Ts;Cp=1;var e=z1(),t=Kr();function r(n){return n==null?[]:e(n,t(n))}return Ts=r,Ts}var Is,_p;function _r(){if(_p)return Is;_p=1;var e;if(typeof Wu=="function")try{e={clone:Kw(),constant:el(),each:ib(),filter:yb(),has:mb(),isArray:tr(),isEmpty:b1(),isFunction:on(),isUndefined:bb(),keys:Kr(),map:xb(),reduce:wb(),size:j1(),transform:R1(),union:B1(),values:jb()}}catch{}return e||(e=window._),Is=e,Is}var Os,Sp;function al(){if(Sp)return Os;Sp=1;var e=_r();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=s(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]):s(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]):s(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]):s(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],a(this._preds[d],l),a(this._sucs[l],d),delete this._in[d][p],delete this._out[l][p],this._edgeCount--),this},o.prototype.inEdges=function(l,d){var f=this._in[l];if(f){var p=e.values(f);return d?e.filter(p,function(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 a(l,d){--l[d]||delete l[d]}function s(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 s(l,d.v,d.w,d.name)}return Os}var Ms,Ep;function D1(){return Ep||(Ep=1,Ms="2.1.8"),Ms}var qs,jp;function V1(){return jp||(jp=1,qs={Graph:al(),version:D1()}),qs}var Ns,Rp;function W1(){if(Rp)return Ns;Rp=1;var e=_r(),t=al();Ns={write:r,read:i};function r(a){var s={options:{directed:a.isDirected(),multigraph:a.isMultigraph(),compound:a.isCompound()},nodes:n(a),edges:o(a)};return e.isUndefined(a.graph())||(s.value=e.clone(a.graph())),s}function n(a){return e.map(a.nodes(),function(s){var c=a.node(s),u=a.parent(s),l={v:s};return e.isUndefined(c)||(l.value=c),e.isUndefined(u)||(l.parent=u),l})}function o(a){return e.map(a.edges(),function(s){var c=a.edge(s),u={v:s.v,w:s.w};return e.isUndefined(s.name)||(u.name=s.name),e.isUndefined(c)||(u.value=c),u})}function i(a){var s=new t(a.options).setGraph(a.value);return e.each(a.nodes,function(c){s.setNode(c.v,c.value),c.parent&&s.setParent(c.v,c.parent)}),e.each(a.edges,function(c){s.setEdge({v:c.v,w:c.w,name:c.name},c.value)}),s}return Ns}var $s,kp;function G1(){if(kp)return $s;kp=1;var e=_r();$s=t;function t(r){var n={},o=[],i;function a(s){e.has(n,s)||(n[s]=!0,i.push(s),e.each(r.successors(s),a),e.each(r.predecessors(s),a))}return e.each(r.nodes(),function(s){i=[],a(s),i.length&&o.push(i)}),o}return $s}var Ls,Pp;function Rb(){if(Pp)return Ls;Pp=1;var e=_r();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,a=i.length;return o[r]=a,i.push({key:r,priority:n}),this._decrease(a),!0}return!1},t.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var r=this._arr.pop();return delete this._keyIndices[r.key],this._heapify(0),r.key},t.prototype.decrease=function(r,n){var o=this._keyIndices[r];if(n>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+r+" Old: "+this._arr[o].priority+" New: "+n);this._arr[o].priority=n,this._decrease(o)},t.prototype._heapify=function(r){var n=this._arr,o=2*r,i=o+1,a=r;o<n.length&&(a=n[o].priority<n[a].priority?o:a,i<n.length&&(a=n[i].priority<n[a].priority?i:a),a!==r&&(this._swap(r,a),this._heapify(a)))},t.prototype._decrease=function(r){for(var n=this._arr,o=n[r].priority,i;r!==0&&(i=r>>1,!(n[i].priority<o));)this._swap(r,i),r=i},t.prototype._swap=function(r,n){var o=this._arr,i=this._keyIndices,a=o[r],s=o[n];o[r]=s,o[n]=a,i[s.key]=r,i[a.key]=n},Ls}var Fs,Ap;function kb(){if(Ap)return Fs;Ap=1;var e=_r(),t=Rb();Fs=n;var r=e.constant(1);function n(i,a,s,c){return o(i,String(a),s||r,c||function(u){return i.outEdges(u)})}function o(i,a,s,c){var u={},l=new t,d,f,p=function(y){var g=y.v!==d?y.v:y.w,b=u[g],x=s(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===a?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 Fs}var Bs,Tp;function U1(){if(Tp)return Bs;Tp=1;var e=kb(),t=_r();Bs=r;function r(n,o,i){return t.transform(n.nodes(),function(a,s){a[s]=e(n,s,o,i)},{})}return Bs}var zs,Ip;function Pb(){if(Ip)return zs;Ip=1;var e=_r();zs=t;function t(r){var n=0,o=[],i={},a=[];function s(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)):(s(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);a.push(l)}}return r.nodes().forEach(function(c){e.has(i,c)||s(c)}),a}return zs}var Ds,Op;function H1(){if(Op)return Ds;Op=1;var e=_r(),t=Pb();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,Mp;function K1(){if(Mp)return Vs;Mp=1;var e=_r();Vs=r;var t=e.constant(1);function r(o,i,a){return n(o,i||t,a||function(s){return o.outEdges(s)})}function n(o,i,a){var s={},c=o.nodes();return c.forEach(function(u){s[u]={},s[u][u]={distance:0},c.forEach(function(l){u!==l&&(s[u][l]={distance:Number.POSITIVE_INFINITY})}),a(u).forEach(function(l){var d=l.v===u?l.w:l.v,f=i(l);s[u][d]={distance:f,predecessor:u}})}),c.forEach(function(u){var l=s[u];c.forEach(function(d){var f=s[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)})})}),s}return Vs}var Ws,qp;function Ab(){if(qp)return Ws;qp=1;var e=_r();Ws=t,t.CycleException=r;function t(n){var o={},i={},a=[];function s(c){if(e.has(i,c))throw new r;e.has(o,c)||(i[c]=!0,o[c]=!0,e.each(n.predecessors(c),s),delete i[c],a.push(c))}if(e.each(n.sinks(),s),e.size(o)!==n.nodeCount())throw new r;return a}function r(){}return r.prototype=new Error,Ws}var Gs,Np;function J1(){if(Np)return Gs;Np=1;var e=Ab();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,$p;function Tb(){if($p)return Us;$p=1;var e=_r();Us=t;function t(n,o,i){e.isArray(o)||(o=[o]);var a=(n.isDirected()?n.successors:n.neighbors).bind(n),s=[],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,a,s)}),s}function r(n,o,i,a,s,c){e.has(a,o)||(a[o]=!0,i||c.push(o),e.each(s(o),function(u){r(n,u,i,a,s,c)}),i&&c.push(o))}return Us}var Hs,Lp;function Z1(){if(Lp)return Hs;Lp=1;var e=Tb();Hs=t;function t(r,n){return e(r,n,"post")}return Hs}var Ks,Fp;function Y1(){if(Fp)return Ks;Fp=1;var e=Tb();Ks=t;function t(r,n){return e(r,n,"pre")}return Ks}var Js,Bp;function X1(){if(Bp)return Js;Bp=1;var e=_r(),t=al(),r=Rb();Js=n;function n(o,i){var a=new t,s={},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&&(s[p]=u,c.decrease(p,g))}}if(o.nodeCount()===0)return a;e.each(o.nodes(),function(f){c.add(f,Number.POSITIVE_INFINITY),a.setNode(f)}),c.decrease(o.nodes()[0],0);for(var d=!1;c.size()>0;){if(u=c.removeMin(),e.has(s,u))a.setEdge(u,s[u]);else{if(d)throw new Error("Input graph is not connected: "+o);d=!0}o.nodeEdges(u).forEach(l)}return a}return Js}var Zs,zp;function Q1(){return zp||(zp=1,Zs={components:G1(),dijkstra:kb(),dijkstraAll:U1(),findCycles:H1(),floydWarshall:K1(),isAcyclic:J1(),postorder:Z1(),preorder:Y1(),prim:X1(),tarjan:Pb(),topsort:Ab()}),Zs}var Ys,Dp;function eC(){if(Dp)return Ys;Dp=1;var e=V1();return Ys={Graph:e.Graph,json:W1(),alg:Q1(),version:e.version},Ys}var Xs,Vp;function Er(){if(Vp)return Xs;Vp=1;var e;if(typeof Wu=="function")try{e=eC()}catch{}return e||(e=window.graphlib),Xs=e,Xs}var Qs,Wp;function rC(){if(Wp)return Qs;Wp=1;var e=tb(),t=1,r=4;function n(o){return e(o,t|r)}return Qs=n,Qs}var ec,Gp;function Gn(){if(Gp)return ec;Gp=1;var e=St(),t=qr(),r=Nn(),n=Cr();function o(i,a,s){if(!n(s))return!1;var c=typeof a;return(c=="number"?t(s)&&r(a,s.length):c=="string"&&a in s)?e(s[a],i):!1}return ec=o,ec}var rc,Up;function tC(){if(Up)return rc;Up=1;var e=Wn(),t=St(),r=Gn(),n=st(),o=Object.prototype,i=o.hasOwnProperty,a=e(function(s,c){s=Object(s);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=s[b];(x===void 0||t(x,o[b])&&!i.call(s,b))&&(s[b]=f[b])}return s});return rc=a,rc}var tc,Hp;function nC(){if(Hp)return tc;Hp=1;var e=Nr(),t=qr(),r=Kr();function n(o){return function(i,a,s){var c=Object(i);if(!t(i)){var u=e(a,3);i=r(i),a=function(d){return u(c[d],d,c)}}var l=o(i,a,s);return l>-1?c[u?i[l]:l]:void 0}}return tc=n,tc}var nc,Kp;function oC(){if(Kp)return nc;Kp=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,Jp;function iC(){if(Jp)return oc;Jp=1;var e=oC(),t=/^\s+/;function r(n){return n&&n.slice(0,e(n)+1).replace(t,"")}return oc=r,oc}var ic,Zp;function aC(){if(Zp)return ic;Zp=1;var e=iC(),t=Cr(),r=kt(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,a=/^0o[0-7]+$/i,s=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||a.test(u)?s(u.slice(2),d?2:8):o.test(u)?n:+u}return ic=c,ic}var ac,Yp;function Ib(){if(Yp)return ac;Yp=1;var e=aC(),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,Xp;function sC(){if(Xp)return sc;Xp=1;var e=Ib();function t(r){var n=e(r),o=n%1;return n===n?o?n-o:n:0}return sc=t,sc}var cc,Qp;function cC(){if(Qp)return cc;Qp=1;var e=Sb(),t=Nr(),r=sC(),n=Math.max;function o(i,a,s){var c=i==null?0:i.length;if(!c)return-1;var u=s==null?0:r(s);return u<0&&(u=n(c+u,0)),e(i,t(a,3),u)}return cc=o,cc}var uc,eg;function uC(){if(eg)return uc;eg=1;var e=nC(),t=cC(),r=e(t);return uc=r,uc}var lc,rg;function Ob(){if(rg)return lc;rg=1;var e=il();function t(r){var n=r==null?0:r.length;return n?e(r,1):[]}return lc=t,lc}var dc,tg;function lC(){if(tg)return dc;tg=1;var e=rl(),t=nb(),r=st();function n(o,i){return o==null?o:e(o,t(i),r)}return dc=n,dc}var fc,ng;function dC(){if(ng)return fc;ng=1;function e(t){var r=t==null?0:t.length;return r?t[r-1]:void 0}return fc=e,fc}var hc,og;function fC(){if(og)return hc;og=1;var e=Mn(),t=tl(),r=Nr();function n(o,i){var a={};return i=r(i,3),t(o,function(s,c,u){e(a,c,i(s,c,u))}),a}return hc=n,hc}var pc,ig;function sl(){if(ig)return pc;ig=1;var e=kt();function t(r,n,o){for(var i=-1,a=r.length;++i<a;){var s=r[i],c=n(s);if(c!=null&&(u===void 0?c===c&&!e(c):o(c,u)))var u=c,l=s}return l}return pc=t,pc}var gc,ag;function hC(){if(ag)return gc;ag=1;function e(t,r){return t>r}return gc=e,gc}var yc,sg;function pC(){if(sg)return yc;sg=1;var e=sl(),t=hC(),r=ct();function n(o){return o&&o.length?e(o,r,t):void 0}return yc=n,yc}var mc,cg;function Mb(){if(cg)return mc;cg=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,ug;function gC(){if(ug)return bc;ug=1;var e=it(),t=Fn(),r=Ar(),n="[object Object]",o=Function.prototype,i=Object.prototype,a=o.toString,s=i.hasOwnProperty,c=a.call(Object);function u(l){if(!r(l)||e(l)!=n)return!1;var d=t(l);if(d===null)return!0;var f=s.call(d,"constructor")&&d.constructor;return typeof f=="function"&&f instanceof f&&a.call(f)==c}return bc=u,bc}var vc,lg;function qb(){if(lg)return vc;lg=1;function e(t,r){if(!(r==="constructor"&&typeof t[r]=="function")&&r!="__proto__")return t[r]}return vc=e,vc}var xc,dg;function yC(){if(dg)return xc;dg=1;var e=an(),t=st();function r(n){return e(n,t(n))}return xc=r,xc}var wc,fg;function mC(){if(fg)return wc;fg=1;var e=Mb(),t=Wm(),r=Qm(),n=Gm(),o=rb(),i=sn(),a=tr(),s=Eb(),c=jt(),u=on(),l=Cr(),d=gC(),f=cn(),p=qb(),y=yC();function g(b,x,m,w,v,C,S){var j=p(b,m),T=p(x,m),P=S.get(T);if(P){e(b,m,P);return}var M=C?C(j,T,m+"",b,x,S):void 0,R=M===void 0;if(R){var E=a(T),k=!E&&c(T),I=!E&&!k&&f(T);M=T,E||k||I?a(j)?M=j:s(j)?M=n(j):k?(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)||u(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,hg;function bC(){if(hg)return Cc;hg=1;var e=On(),t=Mb(),r=rl(),n=mC(),o=Cr(),i=st(),a=qb();function s(c,u,l,d,f){c!==u&&r(u,function(p,y){if(f||(f=new e),o(p))n(c,u,y,l,s,d,f);else{var g=d?d(a(c,y),p,y+"",c,u,f):void 0;g===void 0&&(g=p),t(c,y,g)}},i)}return Cc=s,Cc}var _c,pg;function vC(){if(pg)return _c;pg=1;var e=Wn(),t=Gn();function r(n){return e(function(o,i){var a=-1,s=i.length,c=s>1?i[s-1]:void 0,u=s>2?i[2]:void 0;for(c=n.length>3&&typeof c=="function"?(s--,c):void 0,u&&t(i[0],i[1],u)&&(c=s<3?void 0:c,s=1),o=Object(o);++a<s;){var l=i[a];l&&n(o,l,a,c)}return o})}return _c=r,_c}var Sc,gg;function xC(){if(gg)return Sc;gg=1;var e=bC(),t=vC(),r=t(function(n,o,i){e(n,o,i)});return Sc=r,Sc}var Ec,yg;function Nb(){if(yg)return Ec;yg=1;function e(t,r){return t<r}return Ec=e,Ec}var jc,mg;function wC(){if(mg)return jc;mg=1;var e=sl(),t=Nb(),r=ct();function n(o){return o&&o.length?e(o,r,t):void 0}return jc=n,jc}var Rc,bg;function CC(){if(bg)return Rc;bg=1;var e=sl(),t=Nr(),r=Nb();function n(o,i){return o&&o.length?e(o,t(i,2),r):void 0}return Rc=n,Rc}var kc,vg;function _C(){if(vg)return kc;vg=1;var e=jr(),t=function(){return e.Date.now()};return kc=t,kc}var Pc,xg;function SC(){if(xg)return Pc;xg=1;var e=qn(),t=Dn(),r=Nn(),n=Cr(),o=un();function i(a,s,c,u){if(!n(a))return a;s=t(s,a);for(var l=-1,d=s.length,f=d-1,p=a;p!=null&&++l<d;){var y=o(s[l]),g=c;if(y==="__proto__"||y==="constructor"||y==="prototype")return a;if(l!=f){var b=p[y];g=u?u(b,y,p):void 0,g===void 0&&(g=n(b)?b:r(s[l+1])?[]:{})}e(p,y,g),p=p[y]}return a}return Pc=i,Pc}var Ac,wg;function EC(){if(wg)return Ac;wg=1;var e=Vn(),t=SC(),r=Dn();function n(o,i,a){for(var s=-1,c=i.length,u={};++s<c;){var l=i[s],d=e(o,l);a(d,l)&&t(u,r(l,o),d)}return u}return Ac=n,Ac}var Tc,Cg;function jC(){if(Cg)return Tc;Cg=1;var e=EC(),t=pb();function r(n,o){return e(n,o,function(i,a){return t(n,a)})}return Tc=r,Tc}var Ic,_g;function RC(){if(_g)return Ic;_g=1;var e=Ob(),t=Cb(),r=_b();function n(o){return r(t(o,void 0,e),o+"")}return Ic=n,Ic}var Oc,Sg;function kC(){if(Sg)return Oc;Sg=1;var e=jC(),t=RC(),r=t(function(n,o){return n==null?{}:e(n,o)});return Oc=r,Oc}var Mc,Eg;function PC(){if(Eg)return Mc;Eg=1;var e=Math.ceil,t=Math.max;function r(n,o,i,a){for(var s=-1,c=t(e((o-n)/(i||1)),0),u=Array(c);c--;)u[a?c:++s]=n,n+=i;return u}return Mc=r,Mc}var qc,jg;function AC(){if(jg)return qc;jg=1;var e=PC(),t=Gn(),r=Ib();function n(o){return function(i,a,s){return s&&typeof s!="number"&&t(i,a,s)&&(a=s=void 0),i=r(i),a===void 0?(a=i,i=0):a=r(a),s=s===void 0?i<a?1:-1:r(s),e(i,a,s,o)}}return qc=n,qc}var Nc,Rg;function TC(){if(Rg)return Nc;Rg=1;var e=AC(),t=e();return Nc=t,Nc}var $c,kg;function IC(){if(kg)return $c;kg=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,Pg;function OC(){if(Pg)return Lc;Pg=1;var e=kt();function t(r,n){if(r!==n){var o=r!==void 0,i=r===null,a=r===r,s=e(r),c=n!==void 0,u=n===null,l=n===n,d=e(n);if(!u&&!d&&!s&&r>n||s&&c&&l&&!u&&!d||i&&c&&l||!o&&l||!a)return 1;if(!i&&!s&&!d&&r<n||d&&o&&a&&!i&&!s||u&&o&&a||!c&&a||!l)return-1}return 0}return Lc=t,Lc}var Fc,Ag;function MC(){if(Ag)return Fc;Ag=1;var e=OC();function t(r,n,o){for(var i=-1,a=r.criteria,s=n.criteria,c=a.length,u=o.length;++i<c;){var l=e(a[i],s[i]);if(l){if(i>=u)return l;var d=o[i];return l*(d=="desc"?-1:1)}}return r.index-n.index}return Fc=t,Fc}var Bc,Tg;function qC(){if(Tg)return Bc;Tg=1;var e=zn(),t=Vn(),r=Nr(),n=vb(),o=IC(),i=$n(),a=MC(),s=ct(),c=tr();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=[s];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 a(g,b,f)})}return Bc=u,Bc}var zc,Ig;function NC(){if(Ig)return zc;Ig=1;var e=il(),t=qC(),r=Wn(),n=Gn(),o=r(function(i,a){if(i==null)return[];var s=a.length;return s>1&&n(i,a[0],a[1])?a=[]:s>2&&n(a[0],a[1],a[2])&&(a=[a[0]]),t(i,e(a,1),[])});return zc=o,zc}var Dc,Og;function $C(){if(Og)return Dc;Og=1;var e=fb(),t=0;function r(n){var o=++t;return e(n)+o}return Dc=r,Dc}var Vc,Mg;function LC(){if(Mg)return Vc;Mg=1;function e(t,r,n){for(var o=-1,i=t.length,a=r.length,s={};++o<i;){var c=o<a?r[o]:void 0;n(s,t[o],c)}return s}return Vc=e,Vc}var Wc,qg;function FC(){if(qg)return Wc;qg=1;var e=qn(),t=LC();function r(n,o){return t(n||[],o||[],e)}return Wc=r,Wc}var Gc,Ng;function Je(){if(Ng)return Gc;Ng=1;var e;if(typeof Wu=="function")try{e={cloneDeep:rC(),constant:el(),defaults:tC(),each:ib(),filter:yb(),find:uC(),flatten:Ob(),forEach:ob(),forIn:lC(),has:mb(),isUndefined:bb(),last:dC(),map:xb(),mapValues:fC(),max:pC(),merge:xC(),min:wC(),minBy:CC(),now:_C(),pick:kC(),range:TC(),reduce:wb(),sortBy:NC(),uniqueId:$C(),values:jb(),zipObject:FC()}}catch{}return e||(e=window._),Gc=e,Gc}var Uc,$g;function BC(){if($g)return Uc;$g=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,Lg;function zC(){if(Lg)return Hc;Lg=1;var e=Je(),t=Er().Graph,r=BC();Hc=o;var n=e.constant(1);function o(u,l){if(u.nodeCount()<=1)return[];var d=s(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();)a(u,l,d,g);for(;g=p.dequeue();)a(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(a(u,l,d,g,!0));break}}}return f}function a(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 s(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 Hc}var Kc,Fg;function DC(){if(Fg)return Kc;Fg=1;var e=Je(),t=zC();Kc={run:r,undo:o};function r(i){var a=i.graph().acyclicer==="greedy"?t(i,s(i)):n(i);e.forEach(a,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 s(c){return function(u){return c.edge(u).weight}}}function n(i){var a=[],s={},c={};function u(l){e.has(c,l)||(c[l]=!0,s[l]=!0,e.forEach(i.outEdges(l),function(d){e.has(s,d.w)?a.push(d):u(d.w)}),delete s[l])}return e.forEach(i.nodes(),u),a}function o(i){e.forEach(i.edges(),function(a){var s=i.edge(a);if(s.reversed){i.removeEdge(a);var c=s.forwardName;delete s.reversed,delete s.forwardName,i.setEdge(a.w,a.v,s,c)}})}return Kc}var Jc,Bg;function pr(){if(Bg)return Jc;Bg=1;var e=Je(),t=Er().Graph;Jc={addDummyNode:r,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:a,intersectRect:s,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 a(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 s(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,P;return Math.abs(C)*S>Math.abs(v)*j?(C<0&&(j=-j),T=j*v/C,P=j):(v<0&&(S=-S),T=S,P=S*C/v),{x:m+T,y:w+P}}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 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,zg;function VC(){if(zg)return Zc;zg=1;var e=Je(),t=pr();Zc={run:r,undo:o};function r(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(a){n(i,a)})}function n(i,a){var s=a.v,c=i.node(s).rank,u=a.w,l=i.node(u).rank,d=a.name,f=i.edge(a),p=f.labelRank;if(l!==c+1){i.removeEdge(a);var y,g,b;for(b=0,++c;c<l;++b,++c)f.points=[],g={width:0,height:0,edgeLabel:f,edgeObj:a,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(s,y,{weight:f.weight},d),b===0&&i.graph().dummyChains.push(y),s=y;i.setEdge(s,u,{weight:f.weight},d)}}function o(i){e.forEach(i.graph().dummyChains,function(a){var s=i.node(a),c=s.edgeLabel,u;for(i.setEdge(s.edgeObj,c);s.dummy;)u=i.successors(a)[0],i.removeNode(a),c.points.push({x:s.x,y:s.y}),s.dummy==="edge-label"&&(c.x=s.x,c.y=s.y,c.width=s.width,c.height=s.height),a=u,s=i.node(a)})}return Zc}var Yc,Dg;function xn(){if(Dg)return Yc;Dg=1;var e=Je();Yc={longestPath:t,slack:r};function t(n){var o={};function i(a){var s=n.node(a);if(e.has(o,a))return s.rank;o[a]=!0;var c=e.min(e.map(n.outEdges(a),function(u){return i(u.w)-n.edge(u).minlen}));return(c===Number.POSITIVE_INFINITY||c===void 0||c===null)&&(c=0),s.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 Yc}var Xc,Vg;function $b(){if(Vg)return Xc;Vg=1;var e=Je(),t=Er().Graph,r=xn().slack;Xc=n;function n(s){var c=new t({directed:!1}),u=s.nodes()[0],l=s.nodeCount();c.setNode(u,{});for(var d,f;o(c,s)<l;)d=i(c,s),f=c.hasNode(d.v)?r(s,d):-r(s,d),a(c,s,f);return c}function o(s,c){function u(l){e.forEach(c.nodeEdges(l),function(d){var f=d.v,p=l===f?d.w:f;!s.hasNode(p)&&!r(c,d)&&(s.setNode(p,{}),s.setEdge(l,p,{}),u(p))})}return e.forEach(s.nodes(),u),s.nodeCount()}function i(s,c){return e.minBy(c.edges(),function(u){if(s.hasNode(u.v)!==s.hasNode(u.w))return r(c,u)})}function a(s,c,u){e.forEach(s.nodes(),function(l){c.node(l).rank+=u})}return Xc}var Qc,Wg;function WC(){if(Wg)return Qc;Wg=1;var e=Je(),t=$b(),r=xn().slack,n=xn().longestPath,o=Er().alg.preorder,i=Er().alg.postorder,a=pr().simplify;Qc=s,s.initLowLimValues=d,s.initCutValues=c,s.calcCutValue=l,s.leaveEdge=p,s.enterEdge=y,s.exchangeEdges=g;function s(w){w=a(w),n(w);var v=t(w);d(v),c(v,w);for(var C,S;C=p(v);)S=y(v,w,C),g(v,w,C,S)}function c(w,v){var C=i(w,w.nodes());C=C.slice(0,C.length-1),e.forEach(C,function(S){u(w,v,S)})}function u(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,P=v.edge(C,j),M=0;return P||(T=!1,P=v.edge(j,C)),M=P.weight,e.forEach(v.nodeEdges(C),function(R){var E=R.v===C,k=E?R.w:R.v;if(k!==j){var I=E===T,q=v.edge(R).weight;if(M+=I?q:-q,x(w,C,k)){var O=w.edge(C,k).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,P=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))}),P.low=T,P.lim=C++,j?P.parent=j:delete P.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),P=w.node(j),M=T,R=!1;T.lim>P.lim&&(M=P,R=!0);var E=e.filter(v.edges(),function(k){return R===m(w,w.node(k.v),M)&&R!==m(w,w.node(k.w),M)});return e.minBy(E,function(k){return r(v,k)})}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),c(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,P=v.edge(j,T),M=!1;P||(P=v.edge(T,j),M=!0),v.node(j).rank=v.node(T).rank+(M?P.minlen:-P.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,Gg;function GC(){if(Gg)return eu;Gg=1;var e=xn(),t=e.longestPath,r=$b(),n=WC();eu=o;function o(c){switch(c.graph().ranker){case"network-simplex":s(c);break;case"tight-tree":a(c);break;case"longest-path":i(c);break;default:s(c)}}var i=t;function a(c){t(c),r(c)}function s(c){n(c)}return eu}var ru,Ug;function UC(){if(Ug)return ru;Ug=1;var e=Je();ru=t;function t(o){var i=n(o);e.forEach(o.graph().dummyChains,function(a){for(var s=o.node(a),c=s.edgeObj,u=r(o,i,c.v,c.w),l=u.path,d=u.lca,f=0,p=l[f],y=!0;a!==c.w;){if(s=o.node(a),y){for(;(p=l[f])!==d&&o.node(p).maxRank<s.rank;)f++;p===d&&(y=!1)}if(!y){for(;f<l.length-1&&o.node(p=l[f+1]).minRank<=s.rank;)f++;p=l[f]}o.setParent(a,p),a=o.successors(a)[0]}})}function r(o,i,a,s){var c=[],u=[],l=Math.min(i[a].low,i[s].low),d=Math.max(i[a].lim,i[s].lim),f,p;f=a;do f=o.parent(f),c.push(f);while(f&&(i[f].low>l||d>i[f].lim));for(p=f,f=s;(f=o.parent(f))!==p;)u.push(f);return{path:c.concat(u.reverse()),lca:p}}function n(o){var i={},a=0;function s(c){var u=a;e.forEach(o.children(c),s),i[c]={low:u,lim:a++}}return e.forEach(o.children(),s),i}return ru}var tu,Hg;function HC(){if(Hg)return tu;Hg=1;var e=Je(),t=pr();tu={run:r,cleanup:a};function r(s){var c=t.addDummyNode(s,"root",{},"_root"),u=o(s),l=e.max(e.values(u))-1,d=2*l+1;s.graph().nestingRoot=c,e.forEach(s.edges(),function(p){s.edge(p).minlen*=d});var f=i(s)+1;e.forEach(s.children(),function(p){n(s,c,d,f,l,u,p)}),s.graph().nodeRankFactor=d}function n(s,c,u,l,d,f,p){var y=s.children(p);if(!y.length){p!==c&&s.setEdge(c,p,{weight:0,minlen:u});return}var g=t.addBorderNode(s,"_bt"),b=t.addBorderNode(s,"_bb"),x=s.node(p);s.setParent(g,p),x.borderTop=g,s.setParent(b,p),x.borderBottom=b,e.forEach(y,function(m){n(s,c,u,l,d,f,m);var w=s.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;s.setEdge(g,v,{weight:S,minlen:j,nestingEdge:!0}),s.setEdge(C,b,{weight:S,minlen:j,nestingEdge:!0})}),s.parent(p)||s.setEdge(c,g,{weight:0,minlen:d+f[p]})}function o(s){var c={};function u(l,d){var f=s.children(l);f&&f.length&&e.forEach(f,function(p){u(p,d+1)}),c[l]=d}return e.forEach(s.children(),function(l){u(l,1)}),c}function i(s){return e.reduce(s.edges(),function(c,u){return c+s.edge(u).weight},0)}function a(s){var c=s.graph();s.removeNode(c.nestingRoot),delete c.nestingRoot,e.forEach(s.edges(),function(u){var l=s.edge(u);l.nestingEdge&&s.removeEdge(u)})}return tu}var nu,Kg;function KC(){if(Kg)return nu;Kg=1;var e=Je(),t=pr();nu=r;function r(o){function i(a){var s=o.children(a),c=o.node(a);if(s.length&&e.forEach(s,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",a,c,u),n(o,"borderRight","_br",a,c,u)}}e.forEach(o.children(),i)}function n(o,i,a,s,c,u){var l={width:0,height:0,rank:u,borderType:i},d=c[i][u-1],f=t.addDummyNode(o,"border",l,a);c[i][u]=f,o.setParent(f,s),d&&o.setEdge(d,f,{weight:1})}return nu}var ou,Jg;function JC(){if(Jg)return ou;Jg=1;var e=Je();ou={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")&&(s(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){a(u.node(l))}),e.forEach(u.edges(),function(l){var d=u.edge(l);e.forEach(d.points,a),e.has(d,"y")&&a(d)})}function a(u){u.y=-u.y}function s(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 ou}var iu,Zg;function ZC(){if(Zg)return iu;Zg=1;var e=Je();iu=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})),a=e.map(e.range(i+1),function(){return[]});function s(u){if(!e.has(n,u)){n[u]=!0;var l=r.node(u);a[l.rank].push(u),e.forEach(r.successors(u),s)}}var c=e.sortBy(o,function(u){return r.node(u).rank});return e.forEach(c,s),a}return iu}var au,Yg;function YC(){if(Yg)return au;Yg=1;var e=Je();au=t;function t(n,o){for(var i=0,a=1;a<o.length;++a)i+=r(n,o[a-1],o[a]);return i}function r(n,o,i){for(var a=e.zipObject(i,e.map(i,function(f,p){return p})),s=e.flatten(e.map(o,function(f){return e.sortBy(e.map(n.outEdges(f),function(p){return{pos:a[p.w],weight:n.edge(p).weight}}),"pos")}),!0),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(s.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 au}var su,Xg;function XC(){if(Xg)return su;Xg=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 a=e.reduce(i,function(s,c){var u=r.edge(c),l=r.node(c.v);return{sum:s.sum+u.weight*l.order,weight:s.weight+u.weight}},{sum:0,weight:0});return{v:o,barycenter:a.sum/a.weight,weight:a.weight}}else return{v:o}})}return su}var cu,Qg;function QC(){if(Qg)return cu;Qg=1;var e=Je();cu=t;function t(o,i){var a={};e.forEach(o,function(c,u){var l=a[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=a[c.v],l=a[c.w];!e.isUndefined(u)&&!e.isUndefined(l)&&(l.indegree++,u.out.push(a[c.w]))});var s=e.filter(a,function(c){return!c.indegree});return r(s)}function r(o){var i=[];function a(u){return function(l){l.merged||(e.isUndefined(l.barycenter)||e.isUndefined(u.barycenter)||l.barycenter>=u.barycenter)&&n(u,l)}}function s(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(),a(c)),e.forEach(c.out,s(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 a=0,s=0;o.weight&&(a+=o.barycenter*o.weight,s+=o.weight),i.weight&&(a+=i.barycenter*i.weight,s+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=a/s,o.weight=s,o.i=Math.min(i.i,o.i),i.merged=!0}return cu}var uu,ey;function e_(){if(ey)return uu;ey=1;var e=Je(),t=pr();uu=r;function r(i,a){var s=t.partition(i,function(g){return e.has(g,"barycenter")}),c=s.lhs,u=e.sortBy(s.rhs,function(g){return-g.i}),l=[],d=0,f=0,p=0;c.sort(o(!!a)),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,a,s){for(var c;a.length&&(c=e.last(a)).i<=s;)a.pop(),i.push(c.vs),s++;return s}function o(i){return function(a,s){return a.barycenter<s.barycenter?-1:a.barycenter>s.barycenter?1:i?s.i-a.i:a.i-s.i}}return uu}var lu,ry;function r_(){if(ry)return lu;ry=1;var e=Je(),t=XC(),r=QC(),n=e_();lu=o;function o(s,c,u,l){var d=s.children(c),f=s.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(s,d);e.forEach(b,function(C){if(s.children(C.v).length){var S=o(s,C.v,u,l);g[C.v]=S,e.has(S,"barycenter")&&a(C,S)}});var x=r(b,u);i(x,g);var m=n(x,l);if(p&&(m.vs=e.flatten([p,m.vs,y],!0),s.predecessors(p).length)){var w=s.node(s.predecessors(p)[0]),v=s.node(s.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(s,c){e.forEach(s,function(u){u.vs=e.flatten(u.vs.map(function(l){return c[l]?c[l].vs:l}),!0)})}function a(s,c){e.isUndefined(s.barycenter)?(s.barycenter=c.barycenter,s.weight=c.weight):(s.barycenter=(s.barycenter*s.weight+c.barycenter*c.weight)/(s.weight+c.weight),s.weight+=c.weight)}return lu}var du,ty;function t_(){if(ty)return du;ty=1;var e=Je(),t=Er().Graph;du=r;function r(o,i,a){var s=n(o),c=new t({compound:!0}).setGraph({root:s}).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||s),e.forEach(o[a](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 du}var fu,ny;function n_(){if(ny)return fu;ny=1;var e=Je();fu=t;function t(r,n,o){var i={},a;e.forEach(o,function(s){for(var c=r.parent(s),u,l;c;){if(u=r.parent(c),u?(l=i[u],i[u]=c):(l=a,a=c),l&&l!==c){n.setEdge(l,c);return}c=u}})}return fu}var hu,oy;function o_(){if(oy)return hu;oy=1;var e=Je(),t=ZC(),r=YC(),n=r_(),o=t_(),i=n_(),a=Er().Graph,s=pr();hu=c;function c(f){var p=s.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=s.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 a;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,iy;function i_(){if(iy)return pu;iy=1;var e=Je(),t=Er().Graph,r=pr();pu={positionX:y,findType1Conflicts:n,findType2Conflicts:o,addConflict:a,hasConflict:s,verticalAlignment:c,horizontalCompaction:u,alignCoordinates:f,findSmallestWidthAlignment:d,balance:p};function n(x,m){var w={};function v(C,S){var j=0,T=0,P=C.length,M=e.last(S);return e.forEach(S,function(R,E){var k=i(x,R),I=k?x.node(k).order:P;(k||R===M)&&(e.forEach(S.slice(T,E+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)&&a(w,O,q)})}),T=E+1,j=I)}),S}return e.reduce(m,v),w}function o(x,m){var w={};function v(S,j,T,P,M){var R;e.forEach(e.range(j,T),function(E){R=S[E],x.node(R).dummy&&e.forEach(x.predecessors(R),function(k){var I=x.node(k);I.dummy&&(I.order<P||I.order>M)&&a(w,k,R)})})}function C(S,j){var T=-1,P,M=0;return e.forEach(j,function(R,E){if(x.node(R).dummy==="border"){var k=x.predecessors(R);k.length&&(P=x.node(k[0]).order,v(j,M,E,T,P),M=E,T=P)}v(j,M,j.length,P,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 a(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 s(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={},S={},j={};return e.forEach(m,function(T){e.forEach(T,function(P,M){C[P]=P,S[P]=P,j[P]=M})}),e.forEach(m,function(T){var P=-1;e.forEach(T,function(M){var R=v(M);if(R.length){R=e.sortBy(R,function(O){return j[O]});for(var E=(R.length-1)/2,k=Math.floor(E),I=Math.ceil(E);k<=I;++k){var q=R[k];S[M]===M&&P<j[q]&&!s(w,M,q)&&(S[q]=M,S[M]=C[M]=C[q],P=j[q])}}})}),{root:C,align:S}}function u(x,m,w,v,C){var S={},j=l(x,m,w,C),T=C?"borderLeft":"borderRight";function P(E,k){for(var I=j.nodes(),q=I.pop(),O={};q;)O[q]?E(q):(O[q]=!0,I.push(q),I=I.concat(k(q))),q=I.pop()}function M(E){S[E]=j.inEdges(E).reduce(function(k,I){return Math.max(k,S[I.v]+j.edge(I))},0)}function R(E){var k=j.outEdges(E).reduce(function(q,O){return Math.min(q,S[O.w]-j.edge(O))},Number.POSITIVE_INFINITY),I=x.node(E);k!==Number.POSITIVE_INFINITY&&I.borderType!==T&&(S[E]=Math.max(S[E],k))}return P(M,j.predecessors.bind(j)),P(R,j.successors.bind(j)),e.forEach(v,function(E){S[E]=S[w[E]]}),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 P;e.forEach(T,function(M){var R=w[M];if(C.setNode(R),P){var E=w[P],k=C.edge(E,R);C.setEdge(E,R,Math.max(j(x,M,P),k||0))}P=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,P=x[T],M;if(P!==m){var R=e.values(P);M=j==="l"?v-e.min(R):C-e.max(R),M&&(x[T]=e.mapValues(P,function(E){return E+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(E){return e.values(E).reverse()}));var P=(j==="u"?x.predecessors:x.successors).bind(x),M=c(x,C,w,P),R=u(x,C,M.root,M.align,T==="r");T==="r"&&(R=e.mapValues(R,function(E){return-E})),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),P=0,M;if(P+=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&&(P+=w?M:-M),M=0,P+=(j.dummy?m:x)/2,P+=(T.dummy?m:x)/2,P+=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&&(P+=w?M:-M),M=0,P}}function b(x,m){return x.node(m).width}return pu}var gu,ay;function a_(){if(ay)return gu;ay=1;var e=Je(),t=pr(),r=i_().positionX;gu=n;function n(i){i=t.asNonCompoundGraph(i),o(i),e.forEach(r(i),function(a,s){i.node(s).x=a})}function o(i){var a=t.buildLayerMatrix(i),s=i.graph().ranksep,c=0;e.forEach(a,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+s})}return gu}var yu,sy;function s_(){if(sy)return yu;sy=1;var e=Je(),t=DC(),r=VC(),n=GC(),o=pr().normalizeRanks,i=UC(),a=pr().removeEmptyRanks,s=HC(),c=KC(),u=JC(),l=o_(),d=a_(),f=pr(),p=Er().Graph;yu=y;function y($,D){var G=D&&D.debugTiming?f.time:f.notime;G("layout",function(){var N=G(" buildLayoutGraph",function(){return P($)});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(){s.run($)}),D(" rank",function(){n(f.asNonCompoundGraph($))}),D(" injectEdgeLabelProxies",function(){R($)}),D(" removeEmptyRanks",function(){a($)}),D(" nestingGraph.cleanup",function(){s.cleanup($)}),D(" normalizeRanks",function(){o($)}),D(" assignRankMinMax",function(){E($)}),D(" removeEdgeLabelProxies",function(){k($)}),D(" normalize.run",function(){r.run($)}),D(" parentDummyChains",function(){i($)}),D(" addBorderSegments",function(){c($)}),D(" order",function(){l($)}),D(" insertSelfEdges",function(){ne($)}),D(" adjustCoordinateSystem",function(){u.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(){u.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 P($){var D=new p({multigraph:!0,compound:!0}),G=le($.graph());return D.setGraph(e.merge({},m,pe(G,x),e.pick(G,w))),e.forEach($.nodes(),function(N){var ee=le($.node(N));D.setNode(N,e.defaults(pe(ee,v),C)),D.setParent(N,$.parent(N))}),e.forEach($.edges(),function(N){var ee=le($.edge(N));D.setEdge(N,e.merge({},j,pe(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),ye={rank:(ee.rank-N.rank)/2+N.rank,e:D};f.addDummyNode($,"edge-proxy",ye,"_ep")}})}function E($){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 k($){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,ye=$.graph(),fe=ye.marginx||0,J=ye.marginy||0;function Y(U){var se=U.x,te=U.y,xe=U.width,ge=U.height;D=Math.min(D,se-xe/2),G=Math.max(G,se+xe/2),N=Math.min(N,te-ge/2),ee=Math.max(ee,te+ge/2)}e.forEach($.nodes(),function(U){Y($.node(U))}),e.forEach($.edges(),function(U){var se=$.edge(U);e.has(se,"x")&&Y(se)}),D-=fe,N-=J,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)}),ye.width=G-D+fe,ye.height=ee-N+J}function q($){e.forEach($.edges(),function(D){var G=$.edge(D),N=$.node(D.v),ee=$.node(D.w),ye,fe;G.points?(ye=G.points[0],fe=G.points[G.points.length-1]):(G.points=[],ye=ee,fe=N),G.points.unshift(f.intersectRect(N,ye)),G.points.push(f.intersectRect(ee,fe))})}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),ye=$.node(e.last(G.borderLeft)),fe=$.node(e.last(G.borderRight));G.width=Math.abs(fe.x-ye.x),G.height=Math.abs(ee.y-N.y),G.x=ye.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,ye){var fe=$.node(ee);fe.order=ye+N,e.forEach(fe.selfEdges,function(J){f.addDummyNode($,"selfedge",{width:J.label.width,height:J.label.height,rank:fe.rank,order:ye+ ++N,e:J.e,label:J.label},"_se")}),delete fe.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,ye=N.y,fe=G.x-ee,J=N.height/2;$.setEdge(G.e,G.label),$.removeNode(D),G.label.points=[{x:ee+2*fe/3,y:ye-J},{x:ee+5*fe/6,y:ye-J},{x:ee+fe,y:ye},{x:ee+5*fe/6,y:ye+J},{x:ee+2*fe/3,y:ye+J}],G.label.x=G.x,G.label.y=G.y}})}function pe($,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,cy;function c_(){if(cy)return mu;cy=1;var e=Je(),t=pr(),r=Er().Graph;mu={debugOrdering:n};function n(o){var i=t.buildLayerMatrix(o),a=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(s){a.setNode(s,{label:s}),a.setParent(s,"layer"+o.node(s).rank)}),e.forEach(o.edges(),function(s){a.setEdge(s.v,s.w,{},s.name)}),e.forEach(i,function(s,c){var u="layer"+c;a.setNode(u,{rank:"same"}),e.reduce(s,function(l,d){return a.setEdge(l,d,{style:"invis"}),d})}),a}return mu}var bu,uy;function u_(){return uy||(uy=1,bu="0.8.5"),bu}var vu,ly;function l_(){return ly||(ly=1,vu={graphlib:Er(),layout:s_(),debug:c_(),util:{time:pr().time,notime:pr().notime},version:u_()}),vu}var d_=l_();const dy=J0(d_);function f_(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 dy.graphlib.Graph({multigraph:!0,compound:!0}),a=r.compactSpacingScale??(r.spacingFactor>0?r.spacingFactor/1.3:1);i.setGraph({rankdir:r.rankDir,nodesep:r.compact?Math.max(r.nodeSep,24*a):r.nodeSep,edgesep:r.compact?Math.min(r.edgeSep,24*a):r.edgeSep,ranksep:r.compact?Math.min(r.rankSep,80*a):r.rankSep,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({})),i.setDefaultNodeLabel(()=>({}));for(const d of e)i.setNode(d.id,{width:d.width+2,height:d.height+2});for(const d of e)d.parent&&n.has(d.parent)&&i.setParent(d.id,d.parent);for(const d of t){if(!n.has(d.source)||!n.has(d.target)||o.has(d.source)||o.has(d.target))continue;const f=Nm(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*qm: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)}dy.layout(i);const s=new Map;for(const d of e){if(o.has(d.id))continue;const f=i.node(d.id);f&&Number.isFinite(f.x)&&Number.isFinite(f.y)&&s.set(d.id,{x:f.x,y:f.y})}const c=r.compact?1:r.spacingFactor;if(c&&c!==1&&s.size){let d=1/0,f=1/0,p=-1/0,y=-1/0;s.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;s.forEach((x,m)=>s.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=s.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=s.get(x.id);if(!m)continue;const w=m[f],v=(b.get(w)-x[p])/2;s.set(x.id,{...m,[f]:w+g*v})}}return s}function h_(e,t,r,n,o){const i=new Map,a=new Map(e.map(l=>[l.id,l]));for(const l of e){if(!l.parent||!a.has(l.parent))continue;const d=i.get(l.parent);d?d.push(l.id):i.set(l.parent,[l.id])}const s=(l,d=new Set)=>{var p;const f=(p=a.get(l))==null?void 0:p.parent;return!f||!a.has(f)||d.has(l)?0:(d.add(l),1+s(f,d))},c=[...i.keys()].sort((l,d)=>s(d)-s(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 p_(e){const t=e.getBoundingClientRect(),r=t.height/e.offsetHeight;if(!Number.isFinite(r)||r<=0)return[];const n=Om(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],a=new Set(i.filter(s=>s.hasAttribute("data-flow-inspection-row")&&s.getBoundingClientRect().height>0).map(s=>s.dataset.flowProperty));return i.flatMap(s=>{if(s.closest(".flow-sdk-node")!==e)return[];if(a.has(s.dataset.flowProperty)&&!s.hasAttribute("data-flow-inspection-row"))return[];const c=s.dataset.flowPortSide;if(c&&["top","right","bottom","left"].includes(c)){const l=Am(n?Gt(o,n):o,c,Number(s.dataset.flowPortPosition??.5));return[{property:s.getAttribute("data-flow-property"),top:l.y,height:0,anchor:l,...s.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...s.dataset.flowPortRole==="source"||s.dataset.flowPortRole==="target"?{role:s.dataset.flowPortRole}:{}}]}const u=s.getBoundingClientRect();return!u.width||!u.height?[]:[{property:s.getAttribute("data-flow-property"),top:Math.round((u.top-t.top)/r*1e3)/1e3,height:Math.round(u.height/r*1e3)/1e3,...s.dataset.flowPortRole==="source"||s.dataset.flowPortRole==="target"?{role:s.dataset.flowPortRole}:{}}]})}function g_({id:e,x:t,y:r,placed:n,hidden:o,onMount:i,drawHandles:a,drawMode:s,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:S,children:j}){const T=_.useRef(null),[P,M]=_.useState([]),R=u??P,[E,k]=_.useState();return _.useLayoutEffect(()=>{const I=T.current;if(!I)return;const q=()=>{const V=Om(I);k(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]),_.useLayoutEffect(()=>(i(e,T.current),()=>{i(e,null),S==null||S(e,void 0)}),[e,i,S]),_.useLayoutEffect(()=>{const I=T.current;if(!I)return;let q="";const O=()=>{const ne=p_(I),Q=m?ne:ne.filter(le=>le.anchor),pe=JSON.stringify(Q);pe!==q&&(q=pe,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(Pm,{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})}),a&&m&&R.map(I=>["source","target"].filter(q=>!I.role||I.role===q).filter(q=>s||(c==null?void 0:c.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}`)})),a&&!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:((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(K.PiPlusBold,{size:24})})]})}const y_=_.memo(g_);function m_(e,t,r){const[n,o]=_.useState(()=>({nodes:new Set,edges:new Set})),i=_.useMemo(()=>{const s=new Set(e.map(p=>p.id)),c=t.filter(p=>s.has(p.source)&&s.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=>s.has(p))),d=new Set([...n.edges].filter(p=>u.has(p)));if(!r)return{nodes:s,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<s.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]);_.useLayoutEffect(()=>{o(s=>{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(s.nodes,c.nodes)&&u(s.edges,c.edges)?s:{nodes:c.nodes,edges:c.edges}})},[i,r]);const a=_.useCallback(s=>{o(c=>c.edges.has(s)?c:{...c,edges:new Set([...c.edges,s])})},[]);return{shown:i.nodes,ready:i.ready,complete:a}}class b_{constructor(t,r,n){Ir(this,"_pan");Ir(this,"_zoom");Ir(this,"minZoom");Ir(this,"maxZoom");Ir(this,"size",{w:0,h:0});Ir(this,"listeners",new Set);Ir(this,"animationFrame");Ir(this,"animationTimer");this.minZoom=r,this.maxZoom=n,this._pan={...t.pan},this._zoom=this.clamp(t.zoom)}cancelAnimation(){this.animationFrame!==void 0&&cancelAnimationFrame(this.animationFrame),clearTimeout(this.animationTimer),this.animationFrame=void 0,this.animationTimer=void 0}transition(t,r=!1){if(this.cancelAnimation(),!r||typeof requestAnimationFrame>"u"||typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches){this.set(t.pan,t.zoom);return}const n=this.state,o={pan:{...t.pan},zoom:this.clamp(t.zoom)},i=performance.now(),a=300/1.4,s=()=>{this.cancelAnimation(),this.set(o.pan,o.zoom)},c=u=>{const l=Math.min(1,(u-i)/a);if(l>=1){s();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(s,a+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,a=t.y2-t.y1;if(!(i>0)||!(a>0)||!this.size.w||!this.size.h)return;const s=this.clamp(this.clamp(Math.min((this.size.w-2*r)/i,(this.size.h-2*r)/a))*o);this.transition({pan:{x:(this.size.w-s*(t.x1+t.x2))/2,y:(this.size.h-s*(t.y1+t.y2))/2},zoom:s},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 v_={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},xu={w:60,h:60},fy=4,x_=30,hy=300,w_=500,C_=45,__=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2;function py(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 S_(e){var hl;const{nodes:t,edges:r,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:a=!1,rankSep:s,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]=_.useState(null),S=_.useMemo(()=>v?(v.mode==="connections"?zl:ql)(v.id,t,r):null,[v,t,r]),j=i==="auto"||i==="properties",T=_.useMemo(()=>r.filter(A=>ku(A,i)&&(!S||S.has(A.source)&&S.has(A.target))),[r,i,S]),P=_.useMemo(()=>V0(t,r,i,a,S),[t,r,i,a,S]),M=_.useRef(P);M.current=P;const R=_.useRef(e);R.current=e;const E=_.useRef(null),k=_.useRef(null),I=_.useRef(null),q=_.useRef(null),O=_.useMemo(()=>new b_(p,d,f),[]);_.useEffect(()=>{O.minZoom=d,O.maxZoom=f},[O,d,f]);const W=_.useRef(new Map),V=_.useRef(new Map),ue=_.useRef(new Map),ne=_.useRef(null),[Q,pe]=_.useState(new Map),le=_.useCallback((A,L)=>{pe(z=>{if(JSON.stringify(z.get(A))===JSON.stringify(L))return z;const H=new Map(z);return L?H.set(A,L):H.delete(A),H})},[]),[$,D]=_.useState(new Map),G=_.useRef($),N=_.useCallback((A,L)=>{D(z=>{if(JSON.stringify(z.get(A)??[])===JSON.stringify(L))return z;const H=new Map(z);return L.length?H.set(A,L):H.delete(A),H})},[]),[ee,ye]=_.useState(()=>new Map),fe=_.useRef(ee);fe.current=ee;const J=_.useRef(new Map),Y=_.useRef(!1),[U,se]=_.useState(0),te=_.useRef(),xe=_.useRef(),ge=_.useRef(null),De=_.useRef(),Z=_.useRef(!1),de=_.useRef(null),Ce=_.useRef(u),Oe=a,qe=_.useRef(Oe),[Ue,Qe]=_.useState(!0),We=_.useRef(null);We.current=S;const we=_.useRef(1);we.current=(v==null?void 0:v.mode)==="connections"?1.25:1;const Se=_.useRef(null),He=_.useRef(t),Xe=_.useRef([]),ur=_.useRef(!1),er=()=>{ge.current!==null&&cancelAnimationFrame(ge.current),ge.current=null,clearTimeout(De.current)},sr=()=>{Xe.current.length&&(ur.current=!0),!Y.current&&R.current.fitOnInit!==!1&&(Z.current=!0),clearTimeout(xe.current),xe.current=setTimeout(()=>{Y.current=fe.current.size>0,se(A=>A+1)},w_)},Ee=A=>{er();const L=new Map(fe.current),z=performance.now(),H=()=>{er(),ye(A),sr()},oe=be=>{const Ie=Math.min(1,(be-z)/hy);if(Ie>=1)return H();const Le=__(Ie),ie=new Map;A.forEach((ce,he)=>{const ve=L.get(he);ie.set(he,ve?{x:ve.x+(ce.x-ve.x)*Le,y:ve.y+(ce.y-ve.y)*Le}:ce)}),ye(ie),ge.current=requestAnimationFrame(oe)};ge.current=requestAnimationFrame(oe),De.current=setTimeout(H,hy+100)},ut=()=>{const A=R.current,L=we.current,z=M.current,H=z.nodes.map(be=>{const Ie=W.current.get(be.id)||xu;return{id:be.id,parent:be.parent,width:Ie.w,height:Ie.h}});let oe;try{const be=A.compactPropertyLayout,Ie=A.edgeMode!=="nodes"&&A.edgeMode!=="workflow",Le=z.edges.map(ie=>({...ie,connectorClearance:be?Ie&&(ie.sourceProperty!==void 0||ie.targetProperty!==void 0)?D0:z0:0}));oe=f_(H,Le,{edgeLabelFontSize:A.edgeMode==="nodes"||A.edgeMode==="workflow"?Mm:vn,rankDir:A.direction,compact:be,nodeAlignment:A.nodeAlignment,rankSep:A.rankSep*L,edgeSep:A.edgeSep*L,nodeSep:5*L,spacingFactor:A.spacingFactor??1.3,compactSpacingScale:(A.compactSpacingScale??(A.spacingFactor??1.3)/1.3)*L})}catch(be){console.warn("[flow-sdk] layout failed",be);return}for(const[be,Ie]of J.current)oe.has(be)?oe.set(be,Ie):A.nodes.some(Le=>Le.id===be)||J.current.delete(be);Y.current&&!A.isPerformanceMode?Ee(oe):(er(),ye(oe),sr())},fr=_.useCallback(()=>{clearTimeout(xe.current),clearTimeout(te.current),te.current=setTimeout(ut,R.current.layoutDebounce)},[]);_.useEffect(()=>{const A=new Map(He.current.map(L=>[L.id,L]));t.some(L=>{var z;return((z=A.get(L.id))==null?void 0:z.collapsed)===!0&&!L.collapsed})&&(Xe.current=t.filter(L=>!A.has(L.id)).map(L=>L.id)),He.current=t,Ce.current!==u&&fe.current.size>0&&(Y.current=!0,Z.current=!1,clearTimeout(xe.current)),Ce.current=u,qe.current!==Oe&&(Z.current=!de.current),qe.current=Oe,fr()},[t,r,P.nodes,P.edges,Oe,n,o,s,c,fr,u,l]),_.useEffect(()=>()=>{clearTimeout(te.current),clearTimeout(xe.current),er()},[]);const Pt=_.useCallback((A,L)=>{var z,H;if(!ne.current&&typeof ResizeObserver<"u"&&(ne.current=new ResizeObserver(oe=>{let be=!1;for(const Ie of oe){const Le=ue.current.get(Ie.target);if(!Le)continue;const ie=Ie.target,ce=ie.offsetWidth,he=ie.offsetHeight;if(!ce&&!he)continue;const ve=W.current.get(Le);ve&&ve.w===ce&&ve.h===he||(W.current.set(Le,{w:ce,h:he}),be=!0)}be&&fr()})),L){V.current.set(A,L),ue.current.set(L,A),(z=ne.current)==null||z.observe(L);const oe=L.offsetWidth,be=L.offsetHeight;(oe||be)&&W.current.set(A,{w:oe,h:be})}else{const oe=V.current.get(A);oe&&((H=ne.current)==null||H.unobserve(oe),ue.current.delete(oe)),V.current.delete(A),W.current.delete(A),G.current.has(A)&&N(A,[])}fr()},[fr,N]);_.useEffect(()=>()=>{var A;return(A=ne.current)==null?void 0:A.disconnect()},[]);const ae=_.useMemo(()=>{const A=new Map;for(const L of t)L.label&&A.set(L.id,L.label);return A},[t]),Fe=_.useMemo(()=>h_(P.nodes,ee,W.current,A=>y(A).padding,A=>{const L=ae.get(A);if(!L)return;const z=y(A);return{w:kn(L,`bold ${z.fontSize}px ${ot}`)+2*C_,h:0}}),[P.nodes,ee,y,ae]),Ze=_.useRef(Fe);Ze.current=Fe;const Be=_.useCallback(A=>{const L=Ze.current.get(A);if(L)return R0(L);const z=fe.current.get(A);if(!z)return;const H=W.current.get(A)||xu;return{x:z.x,y:z.y,w:H.w,h:H.h}},[]),lr=_.useMemo(()=>{const A=new Map;for(const L of t){const z=Be(L.id);z&&A.set(L.id,z)}return N0($,A,Q,r,n)},[$,t,ee,Fe,Q,r,n,Be]);G.current=lr;const re=(A,L)=>{var oe;if(!j||L===void 0)return;const z=(oe=lr.get(A))==null?void 0:oe.find(be=>be.property===L),H=Be(A);return z&&!z.anchor&&H?H.y-H.h/2+z.top+z.height/2:void 0},F=(A,L)=>{var oe,be;if(L===void 0)return;const z=(be=(oe=lr.get(A))==null?void 0:oe.find(Ie=>Ie.property===L))==null?void 0:be.anchor,H=Be(A);return z&&H?{x:H.x-H.w/2+z.x,y:H.y-H.h/2+z.y,side:z.side}:void 0},X=(A,L)=>{const z=Be(A),H=Q.get(A);return z&&H&&!Fe.has(A)&&re(A,L)===void 0?Gt(z,H):z},Re=()=>{const A=[];fe.current.forEach((L,z)=>{if(Ze.current.has(z))return;const H=W.current.get(z)||xu;A.push(ft({x:L.x,y:L.y,w:H.w,h:H.h}))}),Ze.current.forEach(L=>A.push(L));try{for(const L of[k.current,I.current]){const z=L==null?void 0:L.getBBox();z&&z.width>0&&z.height>0&&A.push({x1:z.x,y1:z.y,x2:z.x+z.width,y2:z.y+z.height})}}catch{}return ro(A)},Pe=()=>{var z,H;const{pan:A,zoom:L}=O;q.current&&(q.current.style.transform=`translate3d(${A.x}px, ${A.y}px, 0) scale(${L})`),(z=k.current)==null||z.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`),(H=I.current)==null||H.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`)};_.useEffect(()=>{Pe();let A=null,L;const z=O.onChange(()=>{Pe();const H=E.current;H&&(H.classList.add("flow-sdk-busy"),clearTimeout(L),L=setTimeout(()=>H.classList.remove("flow-sdk-busy"),150)),A===null&&(A=requestAnimationFrame(()=>{var oe,be;A=null,(be=(oe=R.current).onViewportChange)==null||be.call(oe,O.state)}))});return()=>{z(),clearTimeout(L),A!==null&&cancelAnimationFrame(A)}},[]),_.useLayoutEffect(()=>{const A=E.current;if(!A)return;const L=()=>{let H=A.clientWidth,oe=A.clientHeight;oe||(oe=Math.max(0,window.innerHeight-A.getBoundingClientRect().top-100),oe&&(A.style.height=`${oe}px`)),H||(H=window.innerWidth,H&&(A.style.width=`${H}px`)),O.size={w:H,h:oe},!Y.current&&!fe.current.size&&R.current.fitOnInit!==!1&&(O.set({x:H/2,y:oe/2}),Pe())};if(L(),typeof ResizeObserver>"u")return;const z=new ResizeObserver(L);return z.observe(A),()=>z.disconnect()},[O]),_.useLayoutEffect(()=>{if(ur.current){ur.current=!1;const L=Xe.current.flatMap(H=>{const oe=Be(H);return oe?[ft(oe)]:[]});Xe.current=[];const z=ro(L);if(z){Z.current=!1,O.center(z,R.current.animateViewport);return}}if(!Z.current)return;Z.current=!1;const A=Re();A&&(O.fit(A,50,Y.current&&R.current.animateViewport),Y.current||Pe())},[ee]);const ke=_.useMemo(()=>{const A=ie=>ql(ie,R.current.nodes,R.current.edges),L=(ie,ce=50,he=R.current.animateViewport,ve=1)=>{const nr=ro([...ie].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,he,ve))},z=(ie,ce,he,ve)=>{var Zr;if(!Be(ie))return;const nr=ce==="connections"?oe(ie):A(ie);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:ie,mode:ce});return}Se.current||(Se.current={pan:{...O.pan},zoom:O.zoom}),We.current=nr,R.current.compactPropertyLayout&&(Z.current=!1,de.current=()=>L(We.current??nr,he,ve)),C({id:ie,mode:ce}),R.current.compactPropertyLayout||L(nr,he,ve)},H=ie=>{de.current?de.current=ie:ie()},oe=ie=>zl(ie,R.current.nodes,R.current.edges),be=(ie=>{if(ie===void 0)return O.zoom;O.set(void 0,ie)}),Ie=(ie=>{if(ie===void 0)return O.pan;O.set(ie)}),Le=(ie,ce)=>{var ve;const he=(ve=E.current)==null?void 0:ve.getBoundingClientRect();return{x:ie-((he==null?void 0:he.left)??0),y:ce-((he==null?void 0:he.top)??0)}};return{zoom:be,pan:Ie,setEdgesVisible:Qe,focusNode:(ie,ce,he)=>H(()=>L(new Set([ie]),ce,he,.6)),focusBranch:(ie,ce,he)=>H(()=>L(A(ie),ce,he)),focusConnections:(ie,ce,he)=>H(()=>L(oe(ie),ce,he)),isolateConnections:(ie,ce,he)=>z(ie,"connections",ce,he),isolateBranch:(ie,ce,he)=>z(ie,"branch",ce,he),restoreView:(ie=R.current.animateViewport,ce)=>{const he=R.current.compactPropertyLayout&&!!We.current;We.current=null,C(null);const ve=ce??Se.current;Se.current=null,he?de.current=()=>{ve&&O.transition(ve,ie)}:ve&&H(()=>O.transition(ve,ie))},zoomAt:(ie,ce)=>O.zoomAt(ie,ce),fit:(ie=0,ce=R.current.animateViewport)=>{H(()=>{const he=Re();he&&O.fit(he,ie,ce)})},centerAndFit:(ie=0,ce=R.current.animateViewport)=>{H(()=>{const he=Re();he&&O.fit(he,ie,ce)})},center:(ie=R.current.animateViewport)=>{const ce=Re();ce&&O.center(ce,ie)},clientToModel:(ie,ce)=>O.renderedToModel(Le(ie,ce)),modelToClient:ie=>{var ve;const ce=(ve=E.current)==null?void 0:ve.getBoundingClientRect(),he=O.modelToRendered(ie);return{x:he.x+((ce==null?void 0:ce.left)??0),y:he.y+((ce==null?void 0:ce.top)??0)}},getNodeBox:ie=>Be(ie),setNodePosition:(ie,ce,he)=>{if(!fe.current.has(ie)||ce&&(!Number.isFinite(ce.x)||!Number.isFinite(ce.y)))return!1;if(er(),!ce)return J.current.delete(ie),fr(),!0;const ve=new Map(fe.current);return ve.set(ie,{...ce}),(he==null?void 0:he.persist)===!1?J.current.delete(ie):J.current.set(ie,{...ce}),fe.current=ve,ye(ve),(he==null?void 0:he.persist)===!1&&fr(),!0},onViewportChange:ie=>O.onChange(ie)}},[]);_.useEffect(()=>{var A,L;return(L=(A=R.current).onInit)==null||L.call(A,ke),()=>O.cancelAnimation()},[ke]),_.useEffect(()=>{var A,L;if(U>0){const z=de.current;de.current=null,z==null||z(),(L=(A=R.current).onLayoutComplete)==null||L.call(A,ke)}},[ke,U]);const Me=_.useRef(null),ze=_.useRef(new Map),Ke=_.useRef(!1),[Ge,Rr]=_.useState(null),[Ae,gr]=_.useState(null),$r=A=>{const L=E.current.getBoundingClientRect();return{x:A.clientX-L.left,y:A.clientY-L.top}},Tr=(A,L)=>{const z=R.current.nodes;for(let H=z.length-1;H>=0;H--){const oe=z[H].id;if(!ht(oe,R.current.edges,R.current.edgeMode)||We.current&&!We.current.has(oe)||oe===L||Ze.current.has(oe))continue;const be=Be(oe);if(be&&Nl(A,ft(be)))return oe}for(const[H,oe]of Ze.current)if(ht(H,R.current.edges,R.current.edgeMode)&&!(We.current&&!We.current.has(H))&&H!==L&&Nl(A,oe))return H;return null},Lr=(A,L)=>{if(R.current.edgeMode==="nodes"||R.current.edgeMode==="workflow")return null;const z=R.current.direction==="RL",H=Math.max(16,6/O.zoom);let oe=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 Ie=Be(be.id),Le=G.current.get(be.id);if(!Ie||!Le||Ze.current.has(be.id))continue;const ie=Ie.x+(L==="source"!==z?1:-1)*Ie.w/2;for(const ce of Le){if(ce.role&&ce.role!==L)continue;const he=Ie.y-Ie.h/2+ce.top,ve=Math.hypot(A.x-(ce.anchor?Ie.x-Ie.w/2+ce.anchor.x:ie),A.y-he-ce.height/2);if(!ce.anchor&&A.x>=Ie.x-Ie.w/2&&A.x<=Ie.x+Ie.w/2&&A.y>=he&&A.y<=he+ce.height)return{nodeId:be.id,property:ce.property};ve<=H&&(!oe||ve<oe.distance)&&(oe={nodeId:be.id,property:ce.property,distance:ve})}}return oe},Hb=A=>{var Ie;if(!A.currentTarget.contains(A.target)||A.button!==0||R.current.readOnly)return;Me.current||(Ke.current=!1);const L=A.target;if(L.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const z=R.current,H=$r(A);if(A.pointerType==="touch"){ze.current.set(A.pointerId,H);const Le=py(ze.current);if(Le){Me.current={kind:"pinch",distance:Le.distance,zoom:O.zoom,anchor:O.renderedToModel(Le.center)},gr(null),Rr(null),Ke.current=!0;for(const ie of ze.current.keys())A.currentTarget.setPointerCapture(ie);return}}if(Me.current)return;const oe=z.drawHandles&&L.closest(".flow-sdk-handle"),be=z.drawHandles&&L.closest(".flow-sdk-property-port");if(z.drawMode||oe||be){const Le=O.renderedToModel(H),ie=z.drawMode?Lr(Le,"source"):null,ce=be||oe,he=ce?(Ie=ce.closest("[data-node-id]"))==null?void 0:Ie.dataset.nodeId:(ie==null?void 0:ie.nodeId)??Tr(Le),ve=be?be.dataset.property:ie==null?void 0:ie.property;if(he){Me.current={kind:"draw",pointerId:A.pointerId,source:he,sourceProperty:ve,reverse:(be==null?void 0:be.dataset.portRole)==="target",startClient:{x:A.clientX,y:A.clientY}},Ke.current=!0,gr({source:he,sourceProperty:ve,point:Le,target:null}),A.currentTarget.setPointerCapture(A.pointerId);return}}L.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(z.multiSelect?Me.current={kind:"box",pointerId:A.pointerId,start:H,current:H}:z.dragMode?Me.current={kind:"pan",pointerId:A.pointerId,start:H,pan0:O.pan,moved:!1}:Me.current={kind:"tap",pointerId:A.pointerId,start:H,moved:!1},A.currentTarget.setPointerCapture(A.pointerId))},Kb=A=>{const L=Me.current;if(!L||R.current.readOnly)return;const z=$r(A);if(ze.current.has(A.pointerId)&&ze.current.set(A.pointerId,z),L.kind==="pinch"){const H=py(ze.current);if(!H)return;const oe=Math.max(O.minZoom,Math.min(O.maxZoom,L.zoom*H.distance/L.distance));O.set({x:H.center.x-L.anchor.x*oe,y:H.center.y-L.anchor.y*oe},oe);return}if(L.pointerId===A.pointerId)switch(L.kind){case"pan":{const H=z.x-L.start.x,oe=z.y-L.start.y;if(!L.moved&&Math.hypot(H,oe)<=fy)return;L.moved=!0,Ke.current=!0,O.set({x:L.pan0.x+H,y:L.pan0.y+oe});break}case"tap":{Math.hypot(z.x-L.start.x,z.y-L.start.y)>fy&&(L.moved=!0);break}case"box":{Ke.current=!0,L.current=z,Rr({x1:Math.min(L.start.x,z.x),y1:Math.min(L.start.y,z.y),x2:Math.max(L.start.x,z.x),y2:Math.max(L.start.y,z.y)});break}case"draw":{const H=O.renderedToModel(z),oe=Lr(H,L.reverse?"source":"target");gr(L.reverse&&oe?{source:oe.nodeId,sourceProperty:oe.property,point:H,target:L.source,targetProperty:L.sourceProperty}:{source:L.source,sourceProperty:L.sourceProperty,point:H,target:(oe==null?void 0:oe.nodeId)??Tr(H,L.source),targetProperty:oe==null?void 0:oe.property});break}}},ll=(A,L)=>{var oe,be,Ie,Le,ie;ze.current.delete(A.pointerId);const z=Me.current;if(!z)return;if(z.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(z.pointerId!==A.pointerId)return;Me.current=null;try{A.currentTarget.releasePointerCapture(A.pointerId)}catch{}const H=R.current;switch(L=L||!!H.readOnly,z.kind){case"pan":case"tap":!L&&!z.moved&&((oe=H.onBackgroundTap)==null||oe.call(H));break;case"box":{if(Rr(null),L)break;const ce=O.renderedToModel(z.start),he=O.renderedToModel(z.current),ve={x1:Math.min(ce.x,he.x),y1:Math.min(ce.y,he.y),x2:Math.max(ce.x,he.x),y2:Math.max(ce.y,he.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&&k0(ft(Yr),ve)&&nr.push(Zr.id)}nr.length&&((Ie=H.onBoxSelect)==null||Ie.call(H,nr));break}case"draw":{if(gr(null),L)break;const ce=$r(A),he=O.renderedToModel(ce),ve=Lr(he,z.reverse?"source":"target"),nr=(ve==null?void 0:ve.nodeId)??Tr(he);if(nr===z.source&&(z.sourceProperty===void 0||(ve==null?void 0:ve.property)===void 0||ve.property===z.sourceProperty))break;nr?(Le=H.onEdgeDraw)==null||Le.call(H,z.reverse?nr:z.source,z.reverse?z.source:nr,z.sourceProperty!==void 0||(ve==null?void 0:ve.property)!==void 0?{sourceProperty:z.reverse?ve==null?void 0:ve.property:z.sourceProperty,targetProperty:z.reverse?z.sourceProperty:ve==null?void 0:ve.property}:void 0):Math.max(Math.abs(A.clientX-z.startClient.x),Math.abs(A.clientY-z.startClient.y))>x_&&((ie=H.onDrawIntoSpace)==null||ie.call(H,z.source,he,z.sourceProperty,z.reverse));break}}},Jr=_.useCallback(()=>{var z;const A=Me.current,L=[...ze.current.keys()];A&&A.kind!=="pinch"&&L.push(A.pointerId),Me.current=null,ze.current.clear(),gr(null),Rr(null);for(const H of L)(z=E.current)!=null&&z.hasPointerCapture(H)&&E.current.releasePointerCapture(H)},[]);_.useEffect(()=>{const A=L=>{L.key==="Escape"&&Jr()};return window.addEventListener("keydown",A),window.addEventListener("blur",Jr),()=>{window.removeEventListener("keydown",A),window.removeEventListener("blur",Jr),Me.current=null,ze.current.clear()}},[Jr]),_.useEffect(()=>{Jr()},[b,x,m,i,n,e.drawHandles,e.readOnly,Jr]);const Jb=_.useMemo(()=>{const A=new Map,L=new Map;for(const z of T){if(z.source!==z.target)continue;const H=A.get(z.source)??0;A.set(z.source,H+1),L.set(z.id,H)}return L},[T]),Kn=v_[n],[Jn,Zb]=_.useState(null),Zn=m_(t,T,!!((hl=e.edgeReveal)!=null&&hl.revealNodes));_.useLayoutEffect(()=>{E.current&&Jn&&K0(E.current)});const Yn=j0(T,X,Kn),Yb=e.onEdgeSelect,Xb=e.onContainerSelect,dl=Ae?Ae.target&&X(Ae.target,Ae.targetProperty)||{x:Ae.point.x,y:Ae.point.y,w:1,h:1}:null,fl=Ae?X(Ae.source,Ae.sourceProperty):null,Qb=["flow-sdk-canvas",b?"flow-sdk-draw":"",w?"flow-sdk-perf":""].filter(Boolean).join(" ");return h.jsxs("div",{ref:E,className:Qb,"data-edge-mode":i,onPointerDownCapture:Hb,onPointerMove:Kb,onPointerUp:A=>ll(A,!1),onPointerCancel:A=>ll(A,!0),onLostPointerCapture:A=>{const L=Me.current;L&&(L.kind==="pinch"||L.pointerId===A.pointerId)&&Jr()},onClickCapture:A=>{A.currentTarget.contains(A.target)&&(Ke.current||e.readOnly)&&(A.preventDefault(),A.stopPropagation())},children:[h.jsx("svg",{className:"flow-sdk-svg",children:h.jsxs("g",{ref:k,children:[h.jsx("g",{className:"flow-sdk-containers",children:[...Fe].filter(([A])=>ht(A,r,i)).filter(([A])=>!S||S.has(A)).map(([A,L])=>{var z;return h.jsx(B0,{id:A,rect:L,label:ae.get(A),labelLayer:Jn,style:y(A),onSelect:Xb,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(z=e.selectedNodeIds)==null?void 0:z.includes(A)},A)})}),h.jsx("g",{className:"flow-sdk-edges",children:Ue&&T.map(A=>{var H,oe,be;if(!Zn.ready.has(A.id)||S&&(!S.has(A.source)||!S.has(A.target)))return null;const L=X(A.source,A.sourceProperty),z=X(A.target,A.targetProperty);return!L||!z?null:h.jsx(Dl,{id:A.id,edgeData:A.data,validationIssue:A.validationIssue,edgeType:A.type,edgeRadius:e.edgeRadius,propertyMode:j,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:Zn.complete,source:L,target:z,sourceProperty:A.sourceProperty,targetProperty:A.targetProperty,sourceY:re(A.source,A.sourceProperty),targetY:re(A.target,A.targetProperty),sourcePort:F(A.source,A.sourceProperty),targetPort:F(A.target,A.targetProperty),dir:Kn,turn:((H=Yn.get(A.id))==null?void 0:H.turn)??A.turn,labelAtTarget:(oe=Yn.get(A.id))==null?void 0:oe.labelAtTarget,labelFraction:(be=Yn.get(A.id))==null?void 0:be.labelFraction,color:A.color,connectorColor:A.connectorColor,labelBg:A.labelBg,label:A.label,labelLayer:Jn,dashed:A.dashed,animated:A.animated&&!w,inverted:A.inverted,loopIndex:Jb.get(A.id)??0,onSelect:Yb},A.id)})}),Ue&&Ae&&ku(Ae,i)&&fl&&dl&&h.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:h.jsx(Dl,{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:fl,target:dl,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(A=>{var be,Ie;const L=ee.get(A.id),z=Fe.get(A.id),H=(L==null?void 0:L.x)??(z?(z.x1+z.x2)/2:0),oe=(L==null?void 0:L.y)??(z?(z.y1+z.y2)/2:0);return h.jsx(y_,{id:A.id,x:H,y:oe,placed:!!L||!!z,hidden:!Zn.shown.has(A.id)||!ht(A.id,r,i)||!!S&&!S.has(A.id),onMount:Pt,drawHandles:e.drawHandles&&!e.readOnly,drawMode:b,connectedPorts:new Set(T.flatMap(Le=>[...Le.source===A.id&&Le.sourceProperty!==void 0?[`source:${Le.sourceProperty}`]:[],...Le.target===A.id&&Le.targetProperty!==void 0?[`target:${Le.targetProperty}`]:[]])),hasCollapseControl:A.hasCollapseControl,handleColor:g,animated:A.animated&&!z&&!w,animationColor:A.animationColor,animationWidth:A.animationWidth,animationVariant:A.animationVariant,width:(be=W.current.get(A.id))==null?void 0:be.w,height:(Ie=W.current.get(A.id))==null?void 0:Ie.h,propertyMode:j,resolvedRows:lr.get(A.id),reversePorts:n==="RL",direction:n,onPropertyRows:N,onSurface:le,children:A.element},A.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:Zb,className:"flow-sdk-labels",style:{pointerEvents:b?"none":"visiblePainted",outline:"none"}})})})]})}const E_=_.memo(S_);function Lb({id:e,label:t,role:r,side:n,position:o=.5,placement:i,children:a,style:s}){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",...s,...n?{display:"none"}:{}},children:a??t??e})}const j_=wn.default.dialog`
208
+ `;function Ml({request:e,property:t,config:r,value:n,disabled:o}){var ue,se,we,pe,ze;const{callbacks:i,structured:a,references:s}=_.useContext(wr),{themeColor:c}=qe(),{background:u}=Xe(),l=_.useId(),d=t.type.kind==="object"||t.type.kind==="array"||t.type.kind==="json",h=n===void 0?"":d?JSON.stringify(n,null,2):String(n),[p,g]=_.useState(h),[m,y]=_.useState(""),[v,b]=_.useState(0),w=_.useRef(null),x=_.useRef(),[C,S]=_.useState(!1),[j,T]=_.useState(!1),[k,M]=_.useState(),R=((ue=r.$options)==null?void 0:ue.$source)==="callback",E=i.resolveFormOptions,{data:P,address:I,nodeAddress:q,nodeId:O}=e;_.useEffect(()=>(S(!1),T(!1),()=>{var Y;(Y=x.current)==null||Y.abort(),x.current=void 0}),[I,q,O,o,h,r.$control,(se=r.$upload)==null?void 0:se.accept,(we=r.$upload)==null?void 0:we.maxSizeBytes]);const V=_.useRef(P);V.current=P;const W=JSON.stringify([I,O,(pe=r.$options)!=null&&pe.$dependsOn?r.$options.$dependsOn.map(Y=>je(P,Y)):je(P,q)]);_.useEffect(()=>{g(h),y("")},[h,I,O]),_.useEffect(()=>{if(!R)return;const Y=new AbortController;return Promise.resolve().then(()=>{if(!E)throw new Error("No options resolver configured");return E({address:I,nodeAddress:q,nodeId:O,data:vt(V.current),signal:Y.signal})}).then(fe=>{if(!Array.isArray(fe)||fe.some(_e=>!_e||typeof _e.label!="string"||!["string","number","boolean"].includes(typeof _e.value)&&_e.value!==null))throw new Error("Invalid options response");Y.signal.aborted||M({key:W,options:fe})}).catch(fe=>{Y.signal.aborted||M({key:W,options:[],error:fe instanceof Error?fe.message:"Options unavailable"})}),()=>Y.abort()},[R,E,W,I,q,O,v]);const te=R&&(k==null?void 0:k.key)!==W,ne=R?(k==null?void 0:k.key)===W?k.options:[]:t.type.kind==="null"?[{label:"Null",value:null}]:t.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:Wt(t.type),ee=t.type.kind==="array",be=(r.$control==="upload"?"upload":a&&d||r.$control==="checkbox"?"pills":r.$control)??(ne?ee||t.type.kind==="boolean"?"pills":"select":t.type.kind==="boolean"?"checkbox":d?"textarea":"input"),le=!t.optional||!!r.$requiredWhen&&jn(r.$requiredWhen,P),$=le?"Required":"Optional",z=be!=="upload"&&!!(s!=null&&s.length)&&typeof n=="string"&&n.includes("{{"),G=m||R&&(k==null?void 0:k.key)===W&&k.error||!z&&jr(t.type,n,le),N=vr(r.$label??I.split(".").pop()),re=Y=>{var fe;if(!(o||Object.is(Y,n)))try{(fe=i.onFormChange)==null||fe.call(i,{...e,previousValue:n,value:Y}),y("")}catch(_e){y(_e instanceof Error?_e.message:"Unable to update field")}},ye=_.useRef(re);_.useLayoutEffect(()=>{ye.current=re});const de=()=>{if(d){try{const Ie=p===""&&t.optional?void 0:JSON.parse(p),Oe=jr(t.type,Ie,le);if(Oe){y(Oe);return}re(Ie)}catch{y("Enter valid JSON")}return}const Y=t.type.kind==="number"||t.type.kind==="integer",fe=p===""&&t.optional?void 0:Y&&p!==""?Number(p):p,_e=jr(t.type,fe,le);if(Y&&_e&&p!==""){y(_e);return}re(fe)},J=async Y=>{var _e,Ie,Oe;if(o||x.current||!Y.length)return;const fe=new AbortController;x.current=fe,y(""),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(!ee&&Y.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=(_e=r.$upload)==null?void 0:_e.accept)==null?void 0:Ie.split(",").map(he=>he.trim().toLowerCase()).filter(Boolean);for(const he of Y){if(((Oe=r.$upload)==null?void 0:Oe.maxSizeBytes)!==void 0&&he.size>r.$upload.maxSizeBytes)throw new Error(`${he.name} exceeds the file size limit.`);if(Ue!=null&&Ue.length&&!Ue.some(Re=>Re.startsWith(".")?he.name.toLowerCase().endsWith(Re):Re.endsWith("/*")?he.type.toLowerCase().startsWith(Re.slice(0,-1)):he.type.toLowerCase()===Re))throw new Error(`${he.name} is not an accepted file type.`)}const er=await Promise.all(Y.map(async he=>{const Re=await i.uploadFormFile({...e,data:vt(P),file:he,signal:fe.signal});if(typeof Re!="string")throw new Error("Upload handler must return an HTTP or HTTPS URL.");let Ze;try{Ze=new URL(Re)}catch{throw new Error("Upload handler must return an HTTP or HTTPS URL.")}if(!["http:","https:"].includes(Ze.protocol)||Ze.username||Ze.password)throw new Error("Upload handler must return an HTTP or HTTPS URL.");return Re}));if(fe.signal.aborted||x.current!==fe)return;const De=ee?[...Array.isArray(n)?n:[],...er]:er[0],tr=jr(t.type,De,le);if(tr)throw new Error(tr);ye.current(De)}catch(Ue){fe.signal.aborted||y(Ue instanceof Error?Ue.message:"Unable to upload file."),fe.abort()}finally{x.current===fe&&(x.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(c);return f.jsxs("div",{"data-form-field":I,"data-flow-property":I.slice(q.length+1),children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[f.jsxs("label",{htmlFor:l,children:[N,le?" *":""]}),t.optional&&n!==void 0&&f.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:()=>re(void 0),children:f.jsx(K.PiArrowCounterClockwise,{size:14})})]}),!!(s!=null&&s.length)&&!d&&be!=="upload"&&f.jsx(d0,{label:N,value:n,references:s,disabled:o,onChange:re}),be==="upload"?f.jsxs("div",{"data-form-upload":ee?"multiple":"single","aria-busy":C,style:{"--flow-upload-surface":me(u),outline:j?"2px dashed var(--flow-form-input-background)":void 0,borderRadius:"var(--flow-form-input-radius)"},onDragOver:Y=>{Y.preventDefault(),Y.stopPropagation(),!o&&!C&&(Y.dataTransfer.dropEffect="copy",T(!0))},onDragLeave:Y=>{Y.currentTarget.contains(Y.relatedTarget)||T(!1)},onDrop:Y=>{Y.preventDefault(),Y.stopPropagation(),T(!1),J(Array.from(Y.dataTransfer.files))},children:[f.jsx("input",{ref:w,type:"file",hidden:!0,"aria-label":`Upload ${N}`,accept:(ze=r.$upload)==null?void 0:ze.accept,multiple:ee,disabled:o||C,onChange:Y=>{const fe=Array.from(Y.target.files??[]);Y.target.value="",J(fe)}}),f.jsxs("div",{"data-upload-items":"",children:[(ee?Array.isArray(n)?n:[]:n?[n]:[]).map((Y,fe)=>f.jsxs("div",{"data-upload-preview":"",children:[typeof Y=="string"&&Fr(Y)&&f.jsxs("a",{href:Y,target:"_blank",rel:"noopener noreferrer","aria-label":`${N} file ${fe+1}`,children:[f.jsx(K.PiFile,{size:32,"aria-hidden":"true"}),f.jsx(Ar,{name:Y,size:120,onError:_e=>{_e.currentTarget.style.visibility="hidden"}})]}),f.jsxs("div",{"data-upload-actions":"",children:[!ee&&f.jsx(Se,{"aria-label":`Replace ${N}`,title:`Replace ${N}`,icon:f.jsx(K.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>{var _e;return(_e=w.current)==null?void 0:_e.click()}}),f.jsx(Se,{"aria-label":`Remove ${N} file ${fe+1}`,title:"Remove file",icon:f.jsx(K.PiTrash,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>re(ee&&Array.isArray(n)?n.filter((_e,Ie)=>Ie!==fe):"")})]})]},`${fe}:${Y}`)),(ee||!n)&&f.jsx("button",{...X,type:"button","data-upload-drop":"",title:`Upload ${N}`,disabled:o||C,onClick:()=>{var Y;return(Y=w.current)==null?void 0:Y.click()},children:f.jsx(K.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&f.jsx("span",{role:"status",children:"Uploading..."})]}):z?null:be==="select"?f.jsx("div",{"data-form-select":"",children:f.jsxs(xr,{...X,disabled:o||te||!!(k!=null&&k.error),labelCase:"preserve",value:String((ne==null?void 0:ne.findIndex(Y=>Object.is(Y.value,n)))??-1),onValueChange:Y=>{const fe=ne==null?void 0:ne[Number(Y)];fe&&re(fe.value)},children:[f.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):$}),ne==null?void 0:ne.map((Y,fe)=>f.jsx("option",{value:fe,children:vr(Y.label)||Y.label},fe))]})}):be==="pills"?f.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((Y,fe)=>{const _e=ee?Array.isArray(n)&&n.includes(Y.value):Object.is(n,Y.value);return f.jsx("button",{type:"button",disabled:o||te,"aria-pressed":_e,style:{padding:"8px 16px",borderRadius:24,border:0,color:_e?U:"inherit",background:_e?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>re(ee?_e?n.filter(Ie=>Ie!==Y.value):[...Array.isArray(n)?n:[],Y.value]:Y.value),children:vr(Y.label)||Y.label},fe)}),te&&f.jsx("span",{role:"status",children:"Loading..."})]}):be==="textarea"?f.jsx("textarea",{...X,placeholder:$,value:p,onChange:Y=>g(Y.target.value),onBlur:de}):f.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:Y=>g(Y.target.value),onBlur:de,onKeyDown:Y=>{Y.key==="Enter"&&de(),Y.key==="Escape"&&g(n===void 0?"":String(n))}}),G&&f.jsx("div",{role:"alert",id:`${l}-error`,children:G}),R&&(k==null?void 0:k.error)&&f.jsx("button",{type:"button",disabled:o,onClick:()=>{M(void 0),b(v+1)},children:"Retry"})]})}function dm({nodeAddress:e,structured:t=!1}){return t?f.jsx(h0,{nodeAddress:e},e):f.jsx(ju,{nodeAddress:e})}function h0({nodeAddress:e}){var d,h,p;const t=_.useContext(wr),[r,n]=_.useState([]),o=((d=t.structured)==null?void 0:d.sourceSchema)??t.schema,i=((h=t.structured)==null?void 0:h.sourceBindings)??t.bindings,a=_.useMemo(()=>{if(!(!t.data||!o||!i))return um(t.data,i,o,[{data:{id:e,type:"objectView"}}])},[t.data,i,o,e]);if(!a)return f.jsx(ju,{nodeAddress:e});const s=r.findIndex(g=>!a.containers.has(g)),c=s<0?r:r.slice(0,s),u=c.at(-1)??e,l=(p=[...a.slots.values()].find(g=>g.nodeId===u))==null?void 0:p.label;return f.jsxs(wr.Provider,{value:{...t,structured:a,schema:a.schema,bindings:a.bindings,renderForm:void 0,onFieldCreate:u===e?t.onFieldCreate:void 0},children:[!!c.length&&f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[f.jsx(Se,{"aria-label":"Back to parent fields",title:"Back to parent fields",icon:f.jsx(K.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:()=>n(c.slice(0,-1))}),f.jsx("strong",{style:{minWidth:0,overflowWrap:"anywhere"},children:vr(l)})]}),f.jsx(ju,{nodeAddress:u,onOpen:g=>n([...c,g])},u)]})}function ju({nodeAddress:e,onOpen:t}){var C,S;const{data:r,schema:n,callbacks:o,bindings:i,editable:a,renderForm:s,structured:c}=_.useContext(wr),{readOnly:u,config:l}=qe(),d=s==null?void 0:s(e);if(d!==void 0)return f.jsx("fieldset",{"data-flow-form":e,disabled:u||l.editable===!1||!a,style:{border:0,margin:0,padding:0,minWidth:0},children:d});if(!r)return f.jsx(dn,{role:"alert",children:"Forms require a JSON document."});const h=i?on(i,e,n):void 0,p=i?h:n&&St(r,e,n);if(!p)return f.jsx(dn,{role:"status",children:"Form schema unavailable."});const g=(h==null?void 0:h.address)??e,m=je(r,g),y=(C=c==null?void 0:c.containers.get(e))==null?void 0:C.scalar;if(m===void 0||typeof m!="object"&&!y)return f.jsx(dn,{role:"alert",children:"Bound form state is unavailable."});const v=Object.entries(p.type.properties).filter(([j])=>{var T;return jn((T=p.fields[j])==null?void 0:T.$visibleWhen,r)}),b=v.length>8||v.some(([j])=>{var T;return(T=p.fields[j])==null?void 0:T.$section}),w=new Map;for(const j of v){const[T,k]=j,M=b?vr(((S=p.fields[T])==null?void 0:S.$section)??(k.type.kind==="object"||k.type.kind==="array"?T:k.optional?"Options":"General")):"";w.has(M)||w.set(M,[]),w.get(M).push(j)}const x=([j,T])=>f.jsx(Ml,{request:{data:r,address:y?g:`${g}.${j}`,nodeAddress:g,nodeId:typeof(m==null?void 0:m.id)=="string"?m.id:void 0},property:T,config:p.fields[j]??{},value:y?m:m==null?void 0:m[j],disabled:u||l.editable===!1||!(a??!!o.onJsonChange)},`${(m==null?void 0:m.id)??e}:${j}`);return f.jsxs(dn,{"data-flow-form":e,onClick:j=>j.stopPropagation(),onDoubleClick:j=>j.stopPropagation(),children:[c&&f.jsx(f0,{nodeAddress:e,onOpen:t}),!c&&h&&p.type.additionalProperties&&v.length===0&&f.jsx(Ml,{request:{data:r,address:g,nodeAddress:g},property:{type:p.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:m,disabled:u||l.editable===!1||!a}),[...w].map(([j,T])=>b&&T.length>1?f.jsxs("details",{open:!0,children:[f.jsxs("summary",{children:[f.jsx("span",{children:j}),f.jsx(K.PiCaretDown,{size:16,"aria-hidden":"true"})]}),T.map(x)]},j):T.map(x))]})}function fm(e){const{viewData:t}=_.useContext(wr),{nodeById:r,edgeById:n,parentIds:o}=Hr();if(t){const i=je(t,e),a=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(a)?a.length>0:!!a&&typeof a=="object"&&Object.entries(a).some(([s,c])=>!s.startsWith("$")&&c!==null&&typeof c=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const a=i.isInverted?i.target:i.source,s=i.isInverted?i.source:i.target;return a===e&&s!==e&&r.has(s)})}function rn(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:t}function bn(e,t,r,n){return{borderColor:t,borderWidth:rn(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",...Cy(t==="transparent"?"currentColor":t,r,".flow-sdk-node:hover &",!r)}}function hm({label:e,value:t,options:r,onChange:n,disabled:o}){var i;return f.jsxs(xr,{"aria-label":e,title:`Animation: ${((i=r.find(a=>a.value===t))==null?void 0:i.label)??"Mixed"}`,value:t,style:{width:104},disabled:o,onValueChange:a=>{const s=r.find(c=>c.value===a);s&&n(s.value)},children:[t===""&&f.jsx("option",{value:"",disabled:!0,children:"Mixed"}),r.map(a=>f.jsx("option",{value:a.value,children:a.label},a.value))]})}function Vu({nodeId:e,edgeId:t,value:r,open:n,onOpenChange:o}){const{callbacks:i,readOnly:a,themeColor:s,colorMode:c}=qe(),{background:u,backgroundSecondary:l,border:d,colorText:h,colorInactive:p}=Xe(),g=c==="dark"?Ct:me(p),m=_.useRef(null),y=_.useRef(null),v=_.useRef(0),[b,w]=_.useState(!1),[x,C]=_.useState("icons"),[S,j]=_.useState([]),[T,k]=_.useState("loading"),[M,R]=_.useState(""),[E,P]=_.useState(0),[I,q]=_.useState(""),[O,V]=_.useState(""),[W,te]=_.useState(!1);_.useEffect(()=>()=>{v.current++},[]),_.useEffect(()=>{if(!b)return;let N=!0;return import("react-icons/pi").then(re=>{N&&(j(Object.keys(re).filter(ye=>ye.startsWith("Pi")).sort()),k("ready"))}).catch(()=>{N&&k("unavailable")}),()=>{N=!1}},[b]),_.useEffect(()=>{var N;a&&((N=m.current)==null||N.close())},[a]),_.useEffect(()=>{var N,re,ye;if(n!==void 0){if(!n||a){(N=m.current)==null||N.close();return}(re=m.current)!=null&&re.open||(V(""),C(r==="PiFileSvg"||r&&Fr(r)?"custom":"icons"),q(r&&!r.startsWith(Gt)&&Fr(r)?r:""),w(!0),(ye=m.current)==null||ye.showModal())}},[n,a,r]);const ne=N=>{var re,ye,de;a||(t?(re=i.onEdgeIconChange)==null||re.call(i,t,N):e&&((ye=i.onNodeIconChange)==null||ye.call(i,e,N)),o==null||o(!1),(de=m.current)==null||de.close())},ee=S.filter(N=>N.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(M.trim().toLowerCase())),be=36,le=Math.max(1,Math.ceil(ee.length/be)),$=Math.min(E,le-1),z=ee.slice($*be,($+1)*be),G={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${me(d)}`,borderRadius:30};return f.jsxs(f.Fragment,{children:[n===void 0&&f.jsx(Ae,{label:t?"Choose edge icon":"Choose node icon",children:f.jsx(Se,{"aria-label":t?"Choose edge icon":"Choose node icon",icon:f.jsx(K.PiShapes,{size:20}),size:"sm",variant:"ghost",color:me(s),disabled:a,onClick:()=>{var N;V(""),C(r&&Fr(r)?"custom":"icons"),q(r&&!r.startsWith(Gt)&&Fr(r)?r:""),w(!0),(N=m.current)==null||N.showModal()}})}),f.jsx(F.chakra.dialog,{ref:m,"aria-label":t?"Choose edge icon":"Choose node icon",css:Vr(me(u),me(d)),onClose:()=>{w(!1),o==null||o(!1),v.current++,te(!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(u),color:me(h)},children:b&&f.jsxs("div",{style:{display:"grid",gap:8},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[f.jsx("strong",{children:t?"Edge icon":"Node icon"}),f.jsxs("div",{style:{display:"flex",alignItems:"center",marginLeft:"auto",gap:4},children:[r&&f.jsx(Ae,{label:"Remove icon",children:f.jsx(Se,{"aria-label":t?"Remove edge icon":"Remove node icon",icon:f.jsx(K.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:a||W,onClick:()=>ne("")})}),f.jsx(_t,{"aria-label":"Close icon picker",onClick:()=>{var N;return(N=m.current)==null?void 0:N.close()}})]})]}),f.jsxs(F.Tabs.Root,{value:x,onValueChange:({value:N})=>{C(N),V("")},display:"contents",css:{"--indicator-thickness":"1px"},children:[f.jsx(F.Tabs.List,{"aria-label":"Icon source",width:"100%",borderBottomWidth:0,children:["icons","custom"].map(N=>f.jsx(F.Tabs.Trigger,{value:N,flex:1,minW:0,justifyContent:"center",px:3,py:2,fontSize:"13px",_selected:{color:s,borderColor:g,"--indicator-color":g},children:N==="icons"?"React icons":"Custom SVG"},N))}),f.jsx("input",{ref:y,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:W||a,onChange:async N=>{var de;const re=(de=N.target.files)==null?void 0:de[0];if(N.target.value="",!re)return;const ye=++v.current;te(!0),V("");try{const J=await n0(re);ye===v.current&&ne(J)}catch(J){ye===v.current&&V(J instanceof Error?J.message:"Unable to read SVG.")}finally{ye===v.current&&te(!1)}}}),f.jsx(F.Tabs.Content,{value:x,p:0,style:{display:"grid",gap:8},children:x==="icons"?f.jsxs(f.Fragment,{children:[f.jsx("input",{"aria-label":"Search icons",placeholder:"Search icons...",value:M,onChange:N=>{R(N.target.value),P(0)},style:G}),f.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[z.map(N=>f.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?s:d)}`,background:me(r===N?u:l),color:"inherit",cursor:"pointer"},children:f.jsx(Ar,{name:N,size:24})},N)),z.length===0&&f.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:T==="loading"?"Loading icons...":T==="unavailable"?"React icons unavailable":"No icons found"})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[f.jsxs("span",{role:"status",style:{fontSize:12},children:[ee.length," icons · ",$+1," / ",le]}),f.jsxs("div",{style:{display:"flex",gap:4},children:[f.jsx(Ae,{label:"Previous icons",children:f.jsx(Se,{"aria-label":"Previous icons",icon:f.jsx(K.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:$===0,onClick:()=>P($-1)})}),f.jsx(Ae,{label:"Next icons",children:f.jsx(Se,{"aria-label":"Next icons",icon:f.jsx(K.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:$+1>=le,onClick:()=>P($+1)})})]})]})]}):f.jsxs(f.Fragment,{children:[r&&Fr(r)&&f.jsx(Ar,{name:r,size:64}),f.jsxs("button",{type:"button",disabled:W||a,onClick:()=>{var N;return(N=y.current)==null?void 0:N.click()},style:{...G,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[f.jsx(K.PiUploadSimple,{}),W?"Uploading...":"Upload SVG"]}),f.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:N=>{N.preventDefault(),!(W||a)&&(!Fr(I.trim())||I.trim().startsWith(Gt)?V("Enter an HTTP or HTTPS image URL."):ne(I.trim()))},children:[f.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:I,disabled:W||a,onChange:N=>q(N.target.value),style:{...G,flex:1,minWidth:0}}),f.jsx(Ae,{label:"Apply URL",children:f.jsx(Se,{type:"submit","aria-label":"Apply URL",icon:f.jsx(K.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:W||a||!I.trim(),style:{flexShrink:0}})})]})]})})]}),O&&f.jsx("div",{role:"alert",style:{fontSize:13},children:O})]})})]})}const vn=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500",Ct],pm=["gray.900",Ct,"gray.600","gray.200","white"];function gm(){const{config:e}=qe(),t=e.selectionToolbar||{},r=new Set(t.hide||[]);return{palette:t.palette||vn,show:n=>!r.has(n)}}function fr(){const{border:e}=Xe();return f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:e})}function nt({value:e,placeholder:t,ariaLabel:r,width:n="140px",type:o="text",min:i,onCommit:a}){const{colorText:s}=Xe(),[c,u]=_.useState(e),l=_.useRef(!1);_.useEffect(()=>u(e),[e]);const d=()=>{if(l.current)return;l.current=!0;const h=c.trim();if(o==="number"&&h!==""&&(!Number.isFinite(Number(h))||Number(h)<(i??0))){u(e);return}h!==e&&a(h)};return f.jsx(F.Input,{"aria-label":r,type:o,min:i,size:"xs",fontSize:"16px",w:n,value:c,placeholder:t,color:s,borderWidth:0,_focusVisible:{boxShadow:"none",outline:"none"},borderRadius:"8px",onFocus:()=>{l.current=!1},onChange:h=>u(h.target.value),onBlur:d,onKeyDown:h=>{h.key==="Enter"&&(d(),h.target.blur()),h.key==="Escape"&&(l.current=!0,u(e),h.target.blur())}})}function xt({colors:e,value:t,label:r,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:a,colorText:s}=Xe(),[c,u]=_.useState(!1),l=_.useId(),d=_.useRef(null),h=t??e[0]??"transparent";return f.jsxs(F.HStack,{gap:1,"aria-label":r,role:"group",onKeyDown:p=>{var g;p.key==="Escape"&&(u(!1),(g=d.current)==null||g.focus())},children:[f.jsx(Ae,{label:`${r}: ${h}`,children:f.jsx(F.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:me(h),...h==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${me(s)}`,outlineOffset:"1px",onClick:()=>u(p=>!p)})}),c&&f.jsxs(F.HStack,{id:l,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(p=>{const g=t===p;return f.jsx(Ae,{label:`${r}: ${p}`,children:f.jsx(F.Box,{as:"button","aria-label":`${r} ${p}`,"aria-pressed":g,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:g?`2px solid ${me(s)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>n(p),onDoubleClick:m=>{var y;m.stopPropagation(),u(!1),(y=d.current)==null||y.focus()}})},p)}),o&&f.jsx(Ae,{label:`Reset ${r.toLowerCase()}`,children:f.jsx(Se,{"aria-label":`Reset ${r}`,icon:f.jsx(F.Icon,{as:K.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:a,onClick:()=>{var p;o(),u(!1),(p=d.current)==null||p.focus()}})})]})]})}function ym({edgeId:e,onClose:t}){var p;const{callbacks:r,themeColor:n,config:o}=qe(),{colorInactive:i}=Xe(),{edgeById:a}=Hr(),{palette:s,show:c}=gm(),u=(p=a.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",h=[{key:"solid",icon:K.PiLineSegment,label:"Solid"},{key:"dashed",icon:K.PiLineSegments,label:"Dashed"},{key:"animated",icon:K.PiFastForward,label:"Animated"}];return f.jsxs(f.Fragment,{children:[f.jsx(_t,{onClick:t}),c("label")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(nt,{ariaLabel:"Edge label",placeholder:"Edge label",value:(u==null?void 0:u.label)||"",onCommit:g=>{var m;return(m=r.onEdgeLabelChange)==null?void 0:m.call(r,e,g)}})]}),c("style")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),h.map(g=>f.jsx(Ae,{label:g.label,children:f.jsx(Se,{"aria-label":`Edge style ${g.key}`,"aria-pressed":d===g.key,icon:f.jsx(F.Icon,{as:g.icon,boxSize:5}),size:"sm",variant:"ghost",color:d===g.key?n:i,onClick:()=>{var m;return(m=r.onEdgeStyleChange)==null?void 0:m.call(r,e,g.key)}})},g.key)),d==="animated"&&f.jsx(hm,{label:"Edge animation",value:(u==null?void 0:u.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:o.readOnly,onChange:g=>{var m;return(m=r.onEdgeAnimationVariantChange)==null?void 0:m.call(r,e,g)}}),f.jsxs(xr,{"aria-label":"Edge shape",title:`Edge shape: ${(u==null?void 0:u.type)??"Default"}`,icon:f.jsx(K.PiBezierCurve,{size:20}),style:{width:36},value:(u==null?void 0:u.type)??"",disabled:o.readOnly,onValueChange:g=>{var m;return(m=r.onEdgeTypeChange)==null?void 0:m.call(r,e,g||void 0)},children:[f.jsx("option",{value:"",children:"Default"}),l.map(g=>f.jsx("option",{value:g,children:g},g))]})]}),c("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(Vu,{edgeId:e,value:u==null?void 0:u.icon},e),f.jsx(nt,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(u==null?void 0:u.icon)??"",onCommit:g=>{var m;return(m=r.onEdgeIconChange)==null?void 0:m.call(r,e,g)}})]}),c("color")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(xt,{label:"Edge color",colors:s,value:u==null?void 0:u.color,onPick:g=>{var m;return(m=r.onEdgeColorChange)==null?void 0:m.call(r,e,g)},onReset:()=>{var g;return(g=r.onEdgeColorChange)==null?void 0:g.call(r,e,"")}})]}),c("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(Ae,{label:"Delete edge",children:f.jsx(Se,{"aria-label":"Delete edge",icon:f.jsx(F.Icon,{as:K.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var g;(g=r.onEdgeDelete)==null||g.call(r,e,u),t()}})})]})]})}function mm({ids:e,showDivider:t=!0}){const{callbacks:r,config:n}=qe(),{colorInactive:o}=Xe(),{nodeById:i}=Hr(),[a,s]=_.useState(!1),c=e.map(g=>{var m,y;return(y=(m=i.get(g))==null?void 0:m.data.viewProps)==null?void 0:y.borderRadius}),u=!c.every(g=>g===c[0]),l=u?"mixed":String(c[0]??""),d=["0","8","16","30","53","100"],h=a||!u&&l!==""&&!d.includes(l),p=g=>e.forEach(m=>{var y;return(y=r.onNodeBorderRadiusChange)==null?void 0:y.call(r,m,g)});return f.jsxs(f.Fragment,{children:[t&&f.jsx(fr,{}),f.jsx(F.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:f.jsxs(xr,{icon:f.jsx(F.Icon,{as:cv.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:h?"custom":l,disabled:n.readOnly,onValueChange:g=>{s(g==="custom"),g!=="custom"&&p(g===""?void 0:Number(g))},children:[f.jsx("option",{value:"",children:"Default radius"}),u&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed radii"}),d.map(g=>f.jsxs("option",{value:g,children:[g,"px radius"]},g)),f.jsx("option",{value:"custom",children:"Custom radius"})]})}),h&&f.jsx(nt,{ariaLabel:"Custom border radius",placeholder:u?"Mixed":"Auto",type:"number",min:0,width:"72px",value:u?"":l,onCommit:g=>p(g===""?void 0:Number(g))})]})}function bm({ids:e,onClose:t}){var le,$,z,G,N,re,ye,de;const{callbacks:r,colorMode:n,themeColor:o,config:i,setNodeViewMode:a}=qe(),{colorText:s,colorInactive:c}=Xe(),{nodeById:u,parentIds:l}=Hr(),{palette:d,show:h}=gm(),p=e.length===1,g=p?(le=u.get(e[0]))==null?void 0:le.data:void 0,m=e.map(J=>{var X,U;return((U=(X=u.get(J))==null?void 0:X.data.config)==null?void 0:U.typeView)??""}),y=m.some(J=>J!==m[0]),v=y?"mixed":m[0]??"",b=e.some(J=>{var U,ue;const X=(U=u.get(J))==null?void 0:U.data;return X&&(l.has(J)||((ue=X.config)==null?void 0:ue.parentContainer)||Object.prototype.hasOwnProperty.call(i.customViews??{},X.type))}),w=($=g==null?void 0:g.config)==null?void 0:$.collapsed,x=fm(e[0]),C=J=>{var X,U,ue;return(((U=(X=u.get(J))==null?void 0:X.data.viewProps)==null?void 0:U.outline)??(l.has(J)?(ue=i.parentNodeStyle)==null?void 0:ue.outline:!1))===!0},S=e.every(C),j=!S&&e.some(C),T=J=>{var X;return((X=u.get(J))==null?void 0:X.data.isNodeAnimated)===!0},k=e.every(T),M=!k&&e.some(T),R=e.map(J=>{var X;return((X=u.get(J))==null?void 0:X.data.nodeAnimationVariant)??"traveling"}),E=R.every(J=>J===R[0])?R[0]:"",P=J=>e.forEach(J),[I,q]=_.useState(!1),O=I&&h("color")&&h("borderColor"),V=J=>{var X,U,ue;return(((U=(X=u.get(J))==null?void 0:X.data.viewProps)==null?void 0:U.borderStyle)??(l.has(J)?(ue=i.parentNodeStyle)==null?void 0:ue.borderStyle:"solid"))==="dashed"},W=e.every(V),te=!W&&e.some(V),ne=e.map(J=>{var ue,se,we;const X=(ue=u.get(J))==null?void 0:ue.data,U=l.has(J)?rn((se=i.parentNodeStyle)==null?void 0:se.borderWidth,6):(X==null?void 0:X.type)==="objectView"?3:2;return rn((we=X==null?void 0:X.viewProps)==null?void 0:we.borderWidth,U)}),ee=ne.every(J=>J===ne[0])?String(ne[0]??""):"",be=J=>P(X=>{var U,ue;O?(U=r.onNodeBorderColorChange)==null||U.call(r,X,J):(ue=r.onNodeColorChange)==null||ue.call(r,X,"bg",J)});return f.jsxs(f.Fragment,{children:[f.jsx(_t,{onClick:t}),f.jsx(fr,{}),p&&h("label")?f.jsx(nt,{ariaLabel:"Node label",placeholder:"Node label",value:(g==null?void 0:g.label)??(g==null?void 0:g.headerTitle)??"",onCommit:J=>{var X;return(X=r.onNodeLabelChange)==null?void 0:X.call(r,e[0],J)}}):f.jsxs(F.Text,{fontSize:"xs",color:s,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),h("typeView")&&f.jsxs(xr,{"aria-label":"Type view",title:b?"Type view is managed by the custom renderer or container":`Type view: ${v||"None (default)"}`,icon:f.jsx(K.PiImage,{size:20}),style:{width:36},value:v,disabled:i.readOnly||i.editable===!1||b,onValueChange:J=>{Jt.includes(J)&&P(X=>{var U,ue;(U=r.onNodeTypeViewChange)==null||U.call(r,X,J||void 0),a(X,"default"),(ue=r.onNodeViewToggle)==null||ue.call(r,X)})},children:[y&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),Jt.map(J=>f.jsx("option",{value:J,children:J||"None"},J))]}),h("style")&&f.jsx(mm,{ids:e},e.join("\0")),h("outline")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(Ae,{label:S?"Restore node fill":"Remove node fill",children:f.jsx(Se,{"aria-label":"Toggle node outline","aria-pressed":j?"mixed":S,icon:f.jsx(F.Icon,{as:S?K.PiSquare:K.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:S?o:c,onClick:()=>P(J=>{var X;return(X=r.onNodeOutlineChange)==null?void 0:X.call(r,J,!S)})})})]}),h("color")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),h("borderColor")&&f.jsx(Ae,{label:O?"Edit node colors":"Edit node border",children:f.jsx(Se,{"aria-label":"Edit node border","aria-pressed":O,icon:f.jsx(F.Icon,{as:K.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:O?o:c,bg:O?n==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>q(J=>!J)})}),f.jsx(xt,{label:O?"Border color":"Background",colors:d,value:O?((z=g==null?void 0:g.viewProps)==null?void 0:z.borderColor)??(p&&l.has(e[0])?(G=i.parentNodeStyle)==null?void 0:G.borderColor:void 0):(N=g==null?void 0:g.viewProps)==null?void 0:N.bgColor,onPick:be,onReset:()=>be("")}),O&&h("style")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(Ae,{label:W?"Solid border":"Dashed border",children:f.jsx(Se,{"aria-label":"Toggle dashed border","aria-pressed":te?"mixed":W,icon:f.jsx(F.Icon,{as:W?K.PiLineSegments:K.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:W?o:c,onClick:()=>P(J=>{var X;return(X=r.onNodeBorderStyleChange)==null?void 0:X.call(r,J,W?"solid":"dashed")})})}),f.jsx(nt,{ariaLabel:"Border thickness",placeholder:p?"Auto":"Mixed",width:"64px",type:"number",min:0,value:ee,onCommit:J=>P(X=>{var U;return(U=r.onNodeBorderWidthChange)==null?void 0:U.call(r,X,J===""?void 0:Number(J))})})]})]}),h("animation")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(Ae,{label:k?"Stop border animation":"Animate node border",children:f.jsx(Se,{"aria-label":"Toggle node animation","aria-pressed":M?"mixed":k,icon:f.jsx(F.Icon,{as:K.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:k?o:c,onClick:()=>P(J=>{var X;return(X=r.onNodeAnimationChange)==null?void 0:X.call(r,J,!k)})})}),(k||M)&&f.jsx(hm,{label:"Node animation",value:E,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:i.readOnly,onChange:J=>P(X=>{var U;return(U=r.onNodeAnimationVariantChange)==null?void 0:U.call(r,X,J)})})]}),!O&&h("textColor")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(xt,{label:"Text color",colors:pm,value:(re=g==null?void 0:g.viewProps)==null?void 0:re.textColor,onPick:J=>P(X=>{var U;return(U=r.onNodeColorChange)==null?void 0:U.call(r,X,"text",J)}),onReset:()=>P(J=>{var X;return(X=r.onNodeColorChange)==null?void 0:X.call(r,J,"text","")})})]}),p&&h("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(Vu,{nodeId:e[0],value:(ye=g==null?void 0:g.config)==null?void 0:ye.icon},e[0]),f.jsx(nt,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((de=g==null?void 0:g.config)==null?void 0:de.icon)||"",onCommit:J=>{var X;return(X=r.onNodeIconChange)==null?void 0:X.call(r,e[0],J)}})]}),p&&x&&h("collapse")&&w!==void 0&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(Ae,{label:w?"Expand":"Collapse",children:f.jsx(Se,{"aria-label":w?"Expand node":"Collapse node",icon:f.jsx(F.Icon,{as:w?K.PiArrowsOutLineVertical:K.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:c,onClick:()=>{var J;return(J=r.onNodeCollapse)==null?void 0:J.call(r,e[0],!w)}})})]}),h("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(fr,{}),f.jsx(Ae,{label:p?"Delete node":`Delete ${e.length} nodes`,children:f.jsx(Se,{"aria-label":"Delete selected nodes",icon:f.jsx(F.Icon,{as:K.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:n==="dark"?"red.300":"red.500",onClick:()=>{P(J=>{var X,U;return(U=r.onNodeDelete)==null?void 0:U.call(r,J,((X=u.get(J))==null?void 0:X.data)||{id:J})}),t()}})})]})]})}async function vm(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 xm(e,t="squeed.svg"){const r=document.createElement("a");r.href=await vm(e),r.download=t.endsWith(".svg")?t:`${t}.svg`,r.click()}function wm(){const{themeColor:e}=qe(),[t,r]=_.useState(!1),[n,o]=_.useState("");return f.jsxs(f.Fragment,{children:[f.jsx(Ae,{label:"Download SVG (current view)",children:f.jsx(Se,{"aria-label":"Download SVG",icon:f.jsx(K.PiDownloadSimpleFill,{size:20}),disabled:t,borderRadius:"30%",color:e,variant:"ghost",onClick:async i=>{var s;const a=(s=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:s.querySelector("[data-flow-background]");if(!a){o("Diagram not available for export.");return}r(!0),o("");try{await xm(a)}catch(c){o(c instanceof Error?c.message:"Unable to export SVG.")}finally{r(!1)}}})}),n&&f.jsx("span",{role:"alert",style:{fontSize:12,maxWidth:220},children:n})]})}function Cm({children:e,background:t,border:r,endElement:n}){const o=_.useRef(null),[i,a]=_.useState({left:!1,right:!1});_.useLayoutEffect(()=>{const c=o.current;let u=c.parentElement.offsetWidth;const l=()=>{const p=c.parentElement.offsetWidth;if(p>0&&p!==u){const y=u/p;u=p,y>0&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches&&c.parentElement.animate({transform:[`scaleX(${y})`,"scaleX(1)"],transformOrigin:[n?"right center":"left center",n?"right center":"left center"]},{duration:180,easing:"ease-out",id:"flow-toolbar-grow"})}const g=c.scrollLeft>1,m=c.scrollWidth-c.clientWidth-c.scrollLeft>1;a(y=>y.left===g&&y.right===m?y:{left:g,right:m})},d=p=>{if(p.defaultPrevented||p.ctrlKey||p.deltaX!==0||!p.deltaY||c.scrollWidth<=c.clientWidth)return;p.preventDefault();const g=p.deltaMode===WheelEvent.DOM_DELTA_LINE?16:p.deltaMode===WheelEvent.DOM_DELTA_PAGE?c.clientWidth:1;c.scrollLeft+=p.deltaY*g},h=new ResizeObserver(l);return h.observe(c),c.firstElementChild&&h.observe(c.firstElementChild),c.addEventListener("scroll",l,{passive:!0}),c.addEventListener("wheel",d,{passive:!1}),l(),()=>{h.disconnect(),c.removeEventListener("scroll",l),c.removeEventListener("wheel",d)}},[]);const s=`var(--chakra-colors-${t.replace(".","-")})`;return f.jsxs(F.Box,{position:"relative",bg:t,minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:"30px",css:Vr(s,`var(--chakra-colors-${r.replace(".","-")})`),children:[f.jsx(F.Box,{ref:o,"data-flow-toolbar-scroll":"",h:50,minH:50,alignContent:"center",overflowX:"auto",overflowY:"hidden",mr:n?"44px":void 0,borderRadius:"inherit",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e}),["left","right"].map(c=>f.jsx(F.Box,{"data-flow-toolbar-fade":c,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",borderRadius:c==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[c]:c==="right"&&n?44:0,opacity:i[c]?1:0,background:`linear-gradient(to ${c==="left"?"right":"left"}, ${s}, transparent)`}},c)),n&&f.jsx(F.Box,{position:"absolute",right:"6px",top:0,h:"50px",w:"32px",display:"flex",alignItems:"center",justifyContent:"center",children:n})]})}async function p0(e,t){const r=new Set,n=[],o=(s,c)=>{var l,d,h;if(!s||typeof s!="object")return;const u=s;n.push(c),typeof((l=u.$form)==null?void 0:l.$type)=="string"&&r.add(u.$form.$type),typeof((h=(d=u.$form)==null?void 0:d.$create)==null?void 0:h.$type)=="string"&&r.add(u.$form.$create.$type);for(const[p,g]of Object.entries(u))p==="$"?o(g,c):p.startsWith("$")||o(g,`${c}.${p}`)};if(o(t,"root"),!r.size)return{contract:await sm(e)};const i=await Du(e,[...r]);for(const s of r)if(!Object.prototype.hasOwnProperty.call(i,s))throw new Error(`Missing form type: ${s}`);const a={};for(const s of n){const c=St(t,s,i);c&&(a[s]={type:c.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:a}}}function _m({message:e,onDismiss:t}){const{background:r,colorText:n,border:o}=Xe();return!e||typeof document>"u"?null:Kt.createPortal(f.jsxs(F.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:[f.jsx(K.PiWarningCircle,{size:20,"aria-hidden":"true",style:{flexShrink:0,color:"#ef4444"}}),f.jsxs("div",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:[f.jsx("strong",{children:"Interface upload failed"}),f.jsx("div",{children:e})]}),f.jsx(_t,{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 Sm({showDivider:e=!0,compact:t=!1}={}){const{edgeMode:r,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:a,readOnly:s,themeColor:c}=qe(),{edgeById:u}=Hr(),{data:l,schema:d,setSchema:h,bindings:p,structured:g}=_.useContext(wr),m=(g==null?void 0:g.sourceBindings)??p,y=(g==null?void 0:g.sourceSchema)??d,{colorText:v}=Xe(),b=_.useRef(null),w=_.useRef(0),[x,C]=_.useState(!1),[S,j]=_.useState("");_.useEffect(()=>()=>{w.current++},[]),_.useEffect(()=>{w.current++,C(!1)},[s,l,m]);const T=o?[...u.values()].filter(M=>zu(o,M.data)).length:0,k=o?`${o.name}: ${y?`${Object.keys(y).length} form types loaded; `:""}${T} invalid or unverified connections`:"";return f.jsxs(f.Fragment,{children:[f.jsx(_m,{message:S,onDismiss:()=>j("")}),e&&f.jsx(Bt,{}),f.jsxs(xr,{"aria-label":"Edge mode",title:r==="auto"?"Connections: Auto":r==="properties"?"Connections: Properties":"Connections: Nodes",icon:r==="auto"?f.jsx(K.PiGraph,{size:20}):r==="properties"?f.jsx(K.PiTable,{size:20}):f.jsx(K.PiTreeStructure,{size:20}),style:{width:36},value:r,disabled:s,onValueChange:M=>{var E;const R=M==="auto"?"auto":M==="properties"?"properties":"nodes";n(R),(E=a.onEdgeModeChange)==null||E.call(a,R)},children:[f.jsx("option",{value:"auto",children:"Auto"}),f.jsx("option",{value:"nodes",children:"Nodes"}),f.jsx("option",{value:"properties",children:"Properties"})]}),f.jsxs("span",{style:{display:r==="auto"||r==="properties"?"contents":"none"},children:[f.jsx(Ae,{label:o?`Replace ${o.name}`:"Upload workflow interface",children:f.jsx(Se,{"aria-label":"Upload workflow interface",icon:f.jsx(K.PiUploadSimple,{size:20}),color:me(c),size:"sm",variant:"ghost",disabled:x||s,onClick:()=>{var M;return(M=b.current)==null?void 0:M.click()}})}),f.jsx("input",{ref:b,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:s||x,onChange:async M=>{var P,I;const R=(P=M.target.files)==null?void 0:P[0];if(M.target.value="",!R)return;const E=++w.current;C(!0),j("");try{const q=m?await Du(R,[...new Set(Object.values(m).map(W=>W.schemaType??W.type))]):void 0;if(m&&q){for(const W of Object.values(m))if(!Object.prototype.hasOwnProperty.call(q,W.schemaType??W.type))throw new Error(`Missing form type: ${W.schemaType??W.type}`)}const{contract:O,schema:V}=m&&q?{schema:q,contract:{name:R.name,nodes:Object.fromEntries(Object.entries(m).map(([W,te])=>[W,{type:q[te.schemaType??te.type],optional:!1}]))}}:await p0(R,l);if(E!==w.current)return;h==null||h(V),i(O),(I=a.onWorkflowContractChange)==null||I.call(a,O)}catch(q){E===w.current&&j(`${R.name}: ${q instanceof Error?q.message:"Unable to load interface."}`)}finally{E===w.current&&C(!1)}}}),!t&&(k||x)&&f.jsx("span",{role:"status",title:k,style:{color:me(v),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:x?"Loading interface...":k}),!t&&o&&f.jsx(Ae,{label:"Remove workflow interface",children:f.jsx(Se,{"aria-label":"Remove workflow interface",icon:f.jsx(K.PiX,{size:16}),size:"sm",variant:"ghost",disabled:s||x,onClick:()=>{var M;h==null||h(void 0),i(void 0),(M=a.onWorkflowContractChange)==null||M.call(a,void 0),j("")}})})]})]})}const g0=[{value:"BT",label:"Bottom to Up",icon:K.PiArrowUp,flowType:Ot.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:K.PiArrowDown,flowType:Ot.TOP_DOWN},{value:"LR",label:"Left to Right",icon:K.PiArrowRight,flowType:Ot.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:K.PiArrowLeft,flowType:Ot.RIGHT_LEFT}],Em=()=>{const{engineRef:e,themeColor:t,setThemeColor:r,edgeColor:n,setEdgeColor:o,backgroundSelected:i,setBackgroundSelected:a,direction:s,edgeMode:c,allNodesIconLabel:u,setAllNodesIconLabel:l,selectedNodeIds:d,setSelectedNodeIds:h,selectedEdgeId:p,setSelectedEdgeId:g,isZoomMode:m,setIsZoomMode:y,isMultiSelectMode:v,setIsMultiSelectMode:b,isDragMode:w,setIsDragMode:x,isEdgeHandlesEnabled:C,setIsEdgeHandlesEnabled:S,isArrayNodeMode:j,setIsArrayNodeMode:T,isPinned:k,setIsPinned:M,callbacks:R,config:E,readOnly:P}=qe(),{nodeById:I,edgeById:q,parentIds:O}=Hr(),V=E.colorMode==="dark",{background:W,border:te,colorInactive:ne,colorText:ee,colorActive:be}=Xe(),le=V?te:"gray.300",$=`var(--chakra-colors-${W.replace(".","-")})`,z=`var(--chakra-colors-${(V?te:"gray.300").replace(".","-")})`,[G,N]=_.useState(!1),[re,ye]=_.useState(!0),de=E.bottomBarCollapsed??re,J=_.useRef(null),X=xy({edge:"bottom",enabled:!k,bounds:J,inside:[J]}),U=_.useCallback(he=>{const Re=e.current;if(!Re)return;const Ze=E.minZoom??.01,lr=E.maxZoom??1.5,nr=.02;let He=Re.zoom();switch(he){case"increase":He=Math.min(lr,He+nr),Re.zoom(He),Re.center();break;case"decrease":He=Math.max(Ze,He-nr),Re.zoom(He),Re.center();break;case"reset":Re.fit(50);break}},[e,E.minZoom,E.maxZoom]),ue=E.renderSelectedNodeToolbar,se=d.length>0&&!!ue,we=_.useMemo(()=>se?d.map(he=>{var Ze;return{...((Ze=I.get(he))==null?void 0:Ze.data)??{id:he},isParent:O.has(he)}}):[],[se,d,I,O]),pe=_.useCallback(()=>{var he;h([]),(he=R.onNodeDeselect)==null||he.call(R)},[h,R]),ze=E.renderSelectedEdgeToolbar,Y=!!p&&!!ze,fe=_.useMemo(()=>{var he;return!Y||!p?null:((he=q.get(p))==null?void 0:he.data)??{id:p}},[Y,p,q]),_e=_.useCallback(()=>{var he;g(null),(he=R.onEdgeDeselect)==null||he.call(R)},[g,R]),Ie=E.selectionToolbar!==!1&&!P,Oe=Ie&&!!p&&!ze,Ue=Ie&&!Oe&&d.length>0&&!ue,er=Oe||Ue,De=k||X||G||er||E.bottomBarCollapsed===!1;_.useEffect(()=>{d.length||p?a(!1):P||(i&&M(!0),E.bottomBarCollapsed===void 0&&ye(!i))},[i,d.length,p,P,a,M,E.bottomBarCollapsed]);const tr=E.renderBottomBar;return tr?f.jsxs(f.Fragment,{children:[se&&f.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:ue({selectedNodeIds:d,selectedNodeData:we,onDeselect:pe})}),Y&&fe&&f.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:ze({edgeId:p,edgeData:fe,onDeselect:_e})}),f.jsx(F.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:tr({zoomIn:()=>U("increase"),zoomOut:()=>U("decrease"),resetZoom:()=>U("reset"),direction:s,isZoomMode:m,setIsZoomMode:y,isMultiSelectMode:v,setIsMultiSelectMode:b,isDragMode:w,setIsDragMode:x,isEdgeHandlesEnabled:C,setIsEdgeHandlesEnabled:S,isArrayNodeMode:j,setIsArrayNodeMode:T,selectedNodeIds:d,selectedNodeData:we,selectedEdgeId:p,selectedEdgeData:fe,onNodeDeselect:pe,onEdgeDeselect:_e,callbacks:R})})]}):f.jsxs(f.Fragment,{children:[se&&f.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:ue({selectedNodeIds:d,selectedNodeData:we,onDeselect:pe})}),Y&&fe&&f.jsx(F.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:ze({edgeId:p,edgeData:fe,onDeselect:_e})}),f.jsx(F.Box,{ref:J,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:De?"translateY(0)":"translateY(100%)",pointerEvents:De?"auto":"none",visibility:De?"visible":"hidden",opacity:De?1:0,css:{"@media (hover: none)":{visibility:"visible",opacity:1,transform:"none",pointerEvents:"auto"}},children:f.jsxs(F.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:[f.jsx(Cm,{background:W,border:V?te:"gray.300",children:f.jsxs(F.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[Oe?f.jsx(ym,{edgeId:p,onClose:_e}):Ue?f.jsx(bm,{ids:d,onClose:pe}):null,f.jsxs("div",{style:{display:Oe||Ue?"none":"contents"},children:[f.jsx(Ae,{label:k?"Unpin":"Pin",children:f.jsx(Se,{"aria-label":"Pin",icon:f.jsx(F.Icon,{as:k?K.PiPushPinFill:K.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:k?t:ne,onClick:()=>{M(!k),N(!1)}})}),f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),f.jsx(Ae,{label:"Zoom Out",children:f.jsx(Se,{"aria-label":"Zoom out",icon:f.jsx(F.Icon,{as:K.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:ee,onClick:()=>U("decrease")})}),f.jsx(Ae,{label:"Zoom In",children:f.jsx(Se,{"aria-label":"Zoom in",icon:f.jsx(F.Icon,{as:K.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:ee,onClick:()=>U("increase")})}),f.jsx(Ae,{label:"Reset Zoom",children:f.jsx(Se,{"aria-label":"Reset zoom",icon:f.jsx(F.Icon,{as:K.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:ee,onClick:()=>U("reset")})}),!de&&f.jsxs(f.Fragment,{children:[f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),f.jsx(Ae,{label:m?"Zoom Mode (z)":"Pan Mode (z)",children:f.jsx(Se,{"aria-label":"Toggle zoom mode",icon:f.jsx(F.Icon,{as:m?K.PiMagnifyingGlassPlus:K.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:m?t:ne,onClick:()=>y(!m)})}),f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),f.jsx(Ae,{label:v?"Multi-Select On (m)":"Multi-Select Off (m)",children:f.jsx(Se,{"aria-label":"Toggle multi-select",icon:f.jsx(F.Icon,{as:K.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:v?t:ne,onClick:()=>b(!v)})}),f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),f.jsx(Ae,{label:w?"Drag Mode On (d)":"Drag Mode Off (d)",children:f.jsx(Se,{"aria-label":"Toggle drag mode",icon:f.jsx(F.Icon,{as:K.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:w?t:ne,onClick:()=>x(!w)})}),E.edgeHandles!==!1&&f.jsxs(f.Fragment,{children:[f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),f.jsx(Ae,{label:C?"Draw Mode On":"Draw Mode Off",children:f.jsx(Se,{"aria-label":"Toggle draw mode",icon:f.jsx(F.Icon,{as:K.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:C?t:ne,onClick:()=>S(!C)})})]}),E.bottomBarExtra&&f.jsxs(f.Fragment,{children:[f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le,role:"separator","aria-orientation":"vertical"}),E.bottomBarExtra]}),f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le,role:"separator","aria-orientation":"vertical"}),f.jsx(Ky,{}),f.jsx(Ou,{label:"Collapse all",checked:u,icon:f.jsx(F.Icon,{as:K.PiArrowsInLineVertical,boxSize:5}),onChange:l}),c!=="properties"&&f.jsxs(f.Fragment,{children:[f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),f.jsx(Ae,{label:j?"Array Mode [ ]":"Set Mode { }",children:f.jsx(Se,{"aria-label":"Toggle array mode",icon:f.jsx(F.Icon,{as:j?K.PiBracketsSquare:K.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:j?t:ne,onClick:()=>{var Re;const he=!j;T(he),(Re=R.onArrayModeChange)==null||Re.call(R,he)}})})]}),i&&!P&&f.jsxs(f.Fragment,{children:[f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),f.jsx(xt,{label:"Graph theme",colors:vn,value:t,includeTransparent:!1,onPick:he=>{var Re;r(he),(Re=R.onThemeColorChange)==null||Re.call(R,he)}})]}),f.jsx(Sm,{}),!P&&f.jsx(xt,{label:"Graph edge color",colors:vn,value:n||(V?"gray.500":Ct),onPick:o,onReset:()=>o("")}),f.jsx(Zy,{})]}),f.jsx(F.Icon,{mx:-1,as:K.PiLineVerticalThin,boxSize:5,color:le}),f.jsx(Ae,{label:de?"Expand toolbar":"Collapse toolbar",children:f.jsx(Se,{"aria-label":"Toggle toolbar collapse",icon:f.jsx(F.Icon,{as:de?K.PiCaretRight:K.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:ne,onClick:()=>{var he;E.bottomBarCollapsed===void 0&&ye(!de),a(de),(he=R.onBottomBarCollapsedChange)==null||he.call(R,!de)}})}),!de&&f.jsx(wm,{})]})]})}),!er&&f.jsxs(F.Box,{position:"relative",ml:"auto",flexShrink:0,children:[f.jsx(F.Box,{"data-flow-direction-control":"",bg:W,borderRadius:"30px",h:50,css:Vr($,z),px:3,cursor:"pointer",onClick:()=>N(!G),children:f.jsxs(F.Flex,{align:"center",h:"100%",children:[f.jsx(Ae,{label:"Flow Direction",children:f.jsx(Se,{"aria-label":"Direction",icon:f.jsx(F.Icon,{as:K.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:ne})}),f.jsx(F.Text,{fontSize:"xs",color:V?"whiteAlpha.600":"blackAlpha.500",ml:1,children:s})]})}),G&&f.jsx(F.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:f.jsxs(F.Box,{bg:W,borderRadius:"30px",p:2,minW:"180px",css:Vr($,z),children:[g0.map(he=>f.jsxs(F.Flex,{align:"center",gap:3,px:3,py:2,css:Su,cursor:"pointer",_hover:{bg:V?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Re;(Re=R.onDirectionChange)==null||Re.call(R,he.value),N(!1)},children:[f.jsx(F.Icon,{as:he.icon,boxSize:5,color:ee}),f.jsx(F.Text,{fontSize:"sm",color:ee,flex:1,whiteSpace:"nowrap",children:he.label}),s===he.value&&f.jsx(F.Icon,{as:K.PiCheck,boxSize:4,color:be})]},he.value)),f.jsxs(F.Flex,{align:"center",gap:3,px:3,py:2,css:Su,cursor:"pointer",_hover:{bg:V?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var he;(he=R.onDirectionChange)==null||he.call(R,"C"),N(!1)},children:[f.jsx(F.Icon,{as:K.PiAlignCenterHorizontal,boxSize:5,color:ee}),f.jsx(F.Text,{fontSize:"sm",color:ee,flex:1,whiteSpace:"nowrap",children:"Center"}),s==="C"&&f.jsx(F.Icon,{as:K.PiCheck,boxSize:4,color:be})]})]})})]})]})})]})};Em.displayName="BottomBar";const jm=_.memo(Em);function y0({checked:e,onChange:t,disabled:r,label:n="Connected nodes"}){return f.jsx(Ou,{label:n,checked:e,onChange:t,disabled:r,icon:f.jsx(F.Icon,{as:K.PiGraph,boxSize:5})})}const ql={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function Rm(e,t){const r=new Map,n=(i,a)=>{if(Object.is(i,a))return!0;if(!i||!a||typeof i!="object"||typeof a!="object"||Array.isArray(i)!==Array.isArray(a))return!1;const s=Object.keys(i);return s.length===Object.keys(a).length&&s.every(c=>Object.prototype.hasOwnProperty.call(a,c)&&n(i[c],a[c]))},o=(i,a,s)=>{if(i===a)return!0;if(!i||!a||typeof i!="object"||typeof a!="object"||Array.isArray(i)!==Array.isArray(a))return!1;const c=new Set([...Object.keys(i),...Object.keys(a)]);for(const u of c)if(!n(i[u],a[u])){if(Object.prototype.hasOwnProperty.call(ql,u)){if(typeof a[u]!="string"||!a[u])return!1;r.set(s,{...r.get(s),[ql[u]]:a[u]})}else if(u.startsWith("$")&&u!=="$"||!o(i[u],a[u],u==="$"?s:`${s}.${u}`))return!1}return!0};if(o(e,t,"root"))return r}function m0(e,t){return Rm(e,t)!==void 0}function b0(e,t,r){if(e===t)return r;const n=Rm(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 a=n.get(i.data.id),s=je(e,i.data.id),c=je(t,i.data.id);return!a&&s===c?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(c,null,2)}:{},...a?{viewProps:{...i.data.viewProps,...a},config:{...i.data.config,...a}}:{}}}})}}function Ru(e){return e.kind==="literal"?e.value:e.kind==="union"?Ru(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,t])=>!t.optional).map(([t,r])=>[t,Ru(r.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function km(e,t,r){var y,v,b;const n=(y=je(e,t))==null?void 0:y.$form,o=n==null?void 0:n.$create;if(!o)return;const i=o.$address.split(".");if(i.shift()!=="root"||!i.length||i.some(w=>!/^[A-Za-z0-9_-]+$/.test(w)||["__proto__","constructor","prototype"].includes(w)))throw new Error("Invalid form creation address.");if(!r||!Object.prototype.hasOwnProperty.call(r,o.$type))throw new Error(`Load form type: ${o.$type}`);const a=i.pop(),s=["root",...i].join("."),c=St(e,s,r),u=(v=c==null?void 0:c.type.properties[a])==null?void 0:v.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,x]of Object.entries(d))if(!Object.prototype.hasOwnProperty.call(l.properties,w)||jr(l.properties[w].type,x,!l.properties[w].optional))throw new Error(`Invalid creation default: ${w}`);const h={...Ru(l),...structuredClone(d)};((b=l.properties.id)==null?void 0:b.type.kind)==="string"&&(h.id=Mu());let p=e;const g=je(e,o.$address);if(g===void 0)p=br(e,s,w=>({...w,[a]:[]}));else if(!Array.isArray(g)&&!Array.isArray(g==null?void 0:g.$))throw new Error("Form creation destination is not an array.");const m=$u(p,o.$address,{...h,$label:o.$label??o.$type,...o.$icon?{$icon:o.$icon}:{},$form:{$type:o.$type,$create:o}});return{address:m.address,json:Lu(m.json,t,{target:m.address,label:o.$edgeLabel})}}function v0(e,t){const r=o=>e&&typeof e=="object"&&o in e;let n=1;for(;r(`${t}_${n}`);)n++;return`${t}_${n}`}function Pm(e,t,r,n,o){const i=(s,c)=>{s!==e&&(e=s,n==null||n(s,c))},a=s=>{var u;const c=(u=t.find(l=>l.data.id===s))==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:s=>{const c=je(e,s.nodeAddress);if(!c||s.nodeId!==void 0&&c.id!==s.nodeId)throw new Error("This form node has moved. Retry the edit.");i(Rn(e,s,r.onFormChange),{type:"form",address:s.address,value:s.value})},onNodeLabelChange:(s,c)=>{var u;(u=r.onNodeLabelChange)==null||u.call(r,s,c),i(ur(e,s,"$label",c),{type:"nodeLabel",address:s,key:"$label",value:c})},onNodeContentChange:(s,c)=>{var u;(u=r.onNodeContentChange)==null||u.call(r,s,c),i(ur(e,s,"$content",c),{type:"nodeContent",address:s,key:"$content",value:c})},onNodeTypeViewChange:(s,c)=>{var u;c!==void 0&&!Jt.includes(c)||((u=r.onNodeTypeViewChange)==null||u.call(r,s,c),i(ur(e,s,"$view",c),{type:"nodeStyle",address:s,key:"$view",value:c}))},onNodeColorChange:(s,c,u)=>{var d;(d=r.onNodeColorChange)==null||d.call(r,s,c,u);const l=c==="bg"?"$bgColor":"$textColor";i(ur(e,s,l,u),{type:"nodeColor",address:s,key:l,value:u})},onNodeBorderColorChange:(s,c)=>{var u;(u=r.onNodeBorderColorChange)==null||u.call(r,s,c),i(ur(e,s,"$borderColor",c),{type:"nodeColor",address:s,key:"$borderColor",value:c})},onNodeBorderStyleChange:(s,c)=>{var u;(u=r.onNodeBorderStyleChange)==null||u.call(r,s,c),i(ur(e,s,"$borderStyle",c),{type:"nodeStyle",address:s,key:"$borderStyle",value:c})},onNodeBorderWidthChange:(s,c)=>{var u;c!==void 0&&(!Number.isFinite(c)||c<0)||((u=r.onNodeBorderWidthChange)==null||u.call(r,s,c),i(ur(e,s,"$borderWidth",c),{type:"nodeStyle",address:s,key:"$borderWidth",value:c}))},onNodeBorderRadiusChange:(s,c)=>{var u;c!==void 0&&(!Number.isFinite(c)||c<0)||((u=r.onNodeBorderRadiusChange)==null||u.call(r,s,c),i(ur(e,s,"$borderRadius",c),{type:"nodeStyle",address:s,key:"$borderRadius",value:c}))},onNodeIconChange:(s,c)=>{var u;(u=r.onNodeIconChange)==null||u.call(r,s,c),i(ur(e,s,"$icon",c),{type:"nodeIcon",address:s,key:"$icon",value:c})},onNodeOutlineChange:(s,c)=>{var u;(u=r.onNodeOutlineChange)==null||u.call(r,s,c),i(ur(e,s,"$outline",c),{type:"nodeOutline",address:s,key:"$outline",value:c})},onNodeAnimationChange:(s,c)=>{var u;(u=r.onNodeAnimationChange)==null||u.call(r,s,c),i(ur(e,s,"$isNodeAnimated",c),{type:"nodeAnimation",address:s,key:"$isNodeAnimated",value:c})},onNodeAnimationVariantChange:(s,c)=>{var u;c!=="traveling"&&c!=="pulse"||((u=r.onNodeAnimationVariantChange)==null||u.call(r,s,c),i(ur(e,s,"$nodeAnimationVariant",c),{type:"nodeAnimation",address:s,key:"$nodeAnimationVariant",value:c}))},onNodeCollapse:(s,c)=>{var u;(u=r.onNodeCollapse)==null||u.call(r,s,c),i(rm(e,s,c),{type:"nodeCollapse",address:s,key:"$collapsed",value:c})},onNodeCreate:s=>{var p,g;const c=s.sourceNodeId&&km(e,s.sourceNodeId,o);if(c){(p=r.onNodeCreate)==null||p.call(r,s),i(c.json,{type:"nodeCreate",address:c.address,value:"form"});return}(g=r.onNodeCreate)==null||g.call(r,s);const u=s.sourceNodeId||"root",l=je(e,u),d=v0(l,s.isArrayMode?"list":"node"),h=$u(e,u,s.isArrayMode?[]:{},d);i(h.json,{type:"nodeCreate",address:h.address,value:s.isArrayMode?"array":"set"})},onNodeDelete:(s,c)=>{var u;(u=r.onNodeDelete)==null||u.call(r,s,c),i(nm(e,s),{type:"nodeDelete",address:s})},onEdgeCreate:(s,c,u)=>{var d;(d=r.onEdgeCreate)==null||d.call(r,s,c,u);const l=u&&(u.sourceProperty!==void 0||u.targetProperty!==void 0)?{...u,target:c}:void 0;i(l?Lu(e,s,l):om(e,s,c),{type:"edgeCreate",address:s,key:l?"$connections":"$target",value:l??c})},onEdgeLabelChange:(s,c)=>{var l;(l=r.onEdgeLabelChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$sourceLabel",c),{type:"edgeLabel",edge:u,key:u.connection?"$connections":"$sourceLabel",value:c})},onEdgeStyleChange:(s,c)=>{var l;(l=r.onEdgeStyleChange)==null||l.call(r,s,c);const u=a(s);u&&i(tm(e,u,c),{type:"edgeStyle",edge:u,value:c})},onEdgeAnimationVariantChange:(s,c)=>{var l;if(c!=="dashed"&&c!=="traveling")return;(l=r.onEdgeAnimationVariantChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$edgeAnimationVariant",c),{type:"edgeStyle",edge:u,key:u.connection?"$connections":"$edgeAnimationVariant",value:c})},onEdgeTypeChange:(s,c)=>{var l;(l=r.onEdgeTypeChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$edgeType",c),{type:"edgeStyle",edge:u,key:u.connection?"$connections":"$edgeType",value:c})},onEdgeIconChange:(s,c)=>{var l;(l=r.onEdgeIconChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$edgeIcon",c||void 0),{type:"edgeStyle",edge:u,key:u.connection?"$connections":"$edgeIcon",value:c})},onEdgeColorChange:(s,c)=>{var l;(l=r.onEdgeColorChange)==null||l.call(r,s,c);const u=a(s);u&&i(zr(e,u,"$edgeColor",c),{type:"edgeColor",edge:u,key:u.connection?"$connections":"$edgeColor",value:c})},onEdgeDelete:(s,c)=>{var d;(d=r.onEdgeDelete)==null||d.call(r,s,c);const u=a(s);if(!u)return;const l=im(e,u);l.removed&&i(l.json,{type:"edgeDelete",edge:u,key:u.connection?"$connections":"$target"})}}}const x0=".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 w0({path:e,color:t,width:r,reversed:n}){return f.jsx("path",{className:`flow-sdk-edge-trace${n?" flow-sdk-edge-trace-reverse":""}`,"data-animation-variant":"traveling","aria-hidden":"true",pointerEvents:"none",d:e,fill:"none",stroke:t,strokeWidth:r,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 100"})}const C0=".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 _0({path:e,width:t,reversed:r,children:n,onComplete:o}){const i=`flow-edge-reveal-${_.useId().replace(/:/g,"")}`,a=_.useRef(null),[s,c]=_.useState({x:0,y:0,width:1,height:1});return _.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]),_.useLayoutEffect(()=>{var l;const u=(l=a.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]),f.jsxs(f.Fragment,{children:[f.jsx("defs",{children:f.jsx("mask",{id:i,maskUnits:"userSpaceOnUse",...s,children:f.jsx("path",{ref:a,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"})})}),f.jsx("g",{mask:`url(#${i})`,children:n})]})}const S0=".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 Am({x:e=0,y:t=0,width:r,height:n,radius:o,color:i,strokeWidth:a=8,path:s,variant:c="traveling"}){const u=_.useId(),l=`flow-sdk-node-border-animation${c==="pulse"?" flow-sdk-node-border-pulse":""}`;if(c==="pulse"){const d=s?"path":"rect",h=s?{d:s}:{x:e,y:t,width:Math.max(0,r),height:Math.max(0,n),rx:Math.max(0,Math.min(o,r/2,n/2))},p=a+36,g={x:e-p,y:t-p,width:r+2*p,height:n+2*p};return f.jsxs("g",{"aria-hidden":"true",pointerEvents:"none",children:[f.jsx("defs",{children:f.jsxs("mask",{id:u,maskUnits:"userSpaceOnUse",...g,style:{maskType:"luminance"},children:[f.jsx("rect",{...g,fill:"white"}),f.jsx(d,{...h,fill:"black",stroke:"black",strokeWidth:a,strokeLinejoin:"round"})]})}),f.jsx(d,{...h,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":`${a+16}px`,"--flow-pulse-expanded-width":`${a+36}px`}})]})}return s?f.jsx("path",{className:l,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",d:s,fill:"none",stroke:i,strokeWidth:a,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"}):f.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:a,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const E0=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 Nl(e,t,r){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const a of t)(a.parent===i||a.id.startsWith(`${i}.`)||r.some(c=>(c.inverted?c.target:c.source)===i&&(c.inverted?c.source:c.target)===a.id))&&!n.has(a.id)&&(n.add(a.id),o.push(a.id))}return n}function j0(e,t,r){const n=r==="downward"||r==="upward",o=new Map;for(const a of e){if(a.source===a.target||a.sourceProperty||a.targetProperty)continue;const s=t(a.source),c=t(a.target);if(!s||!c)continue;const u=n?c.y-s.y:c.x-s.x,l=Math.abs(u)-(n?s.h+c.h:s.w+c.w)/2;if(l<=320)continue;const d=JSON.stringify([a.source,Math.sign(u)]),h=o.get(d)??[];h.push({edge:a,gap:l,cross:n?c.x-s.x:c.y-s.y}),o.set(d,h)}const i=new Map;for(const a of o.values()){if(new Set(a.map(({edge:c})=>c.target)).size<2)continue;const s=new Map;for(const{edge:c}of a)s.set(c.target,(s.get(c.target)??0)+1);for(const c of[-1,0,1]){const u=a.filter(({cross:d})=>Math.sign(d)===c);u.sort((d,h)=>Math.abs(h.cross)-Math.abs(d.cross)||d.edge.id.localeCompare(h.edge.id));const l=Math.min(...u.map(({gap:d})=>d));u.forEach(({edge:d,gap:h,cross:p},g)=>{const m=u.length===1?l/2:120+(l-280)*g/(u.length-1),y=u.find(v=>Math.abs(v.cross)<Math.abs(p));i.set(d.id,{turn:m/h,labelAtTarget:s.get(d.target)===1,labelFraction:p?(p+((y==null?void 0:y.cross)??0))/(2*p):.5})})}}return i}const ht=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}),R0=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function to(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 k0=(e,t)=>e.x1<=t.x2&&e.x2>=t.x1&&e.y1<=t.y2&&e.y2>=t.y1,$l=(e,t)=>e.x>=t.x1&&e.x<=t.x2&&e.y>=t.y1&&e.y<=t.y2,pr=e=>(Math.round(e*10)/10).toString(),Qe=e=>`${pr(e.x)} ${pr(e.y)}`,P0=e=>e>0?1:e<0?-1:0,Ll=(e,t)=>e>0?Math.max(e-t,0):Math.min(e+t,0);function A0(e,t,r,n,o=10){const i=t.x-e.x,a=t.y-e.y,s=Ll(i,(e.w+t.w)/2),c=Ll(a,(e.h+t.h)/2),u=r==="downward"||r==="upward",l=u?c:s,d=u?a:i,h=P0(d),p=n*l,g=b=>Math.abs(b)<o||Math.abs(b)>=Math.abs(l),m=g(p)||g(Math.abs(l)-Math.abs(p));let y;if(m)if(u)if(Math.abs(d)<=e.h/2){const b=(e.x+t.x)/2;y=[b,e.y,b,t.y]}else if(Math.abs(i)<=t.w/2){const b=(e.y+t.y)/2;y=[e.x,b,t.x,b]}else y=[e.x,t.y];else if(Math.abs(d)<=e.w/2){const b=(e.y+t.y)/2;y=[e.x,b,t.x,b]}else if(Math.abs(a)<=t.h/2){const b=(e.x+t.x)/2;y=[b,e.y,b,t.y]}else y=[t.x,e.y];else if(u){const b=e.y+p+e.h/2*h;y=[e.x,b,t.x,b]}else{const b=e.x+p+e.w/2*h;y=[b,e.y,b,t.y]}const v=[{x:e.x,y:e.y}];for(let b=0;b<y.length;b+=2)v.push({x:y[b],y:y[b+1]});return v.push({x:t.x,y:t.y}),v}function T0(e,t,r){const n=t.x-e.x,o=t.y-e.y,i=n>0?(r.x2-e.x)/n:n<0?(r.x1-e.x)/n:1/0,a=o>0?(r.y2-e.y)/o:o<0?(r.y1-e.y)/o:1/0,s=Math.min(i,a);return!Number.isFinite(s)||s>=1||s<0?null:{x:e.x+n*s,y:e.y+o*s}}function wt(e,t,r){var a;if(!((a=r.outline)!=null&&a.length))return T0(e,t,ht(r));const n=t.x-e.x,o=t.y-e.y;let i=1/0;return r.outline.forEach((s,c,u)=>{const l=u[(c+1)%u.length],d=l.x-s.x,h=l.y-s.y,p=n*h-o*d;if(Math.abs(p)<1e-9)return;const g=s.x-e.x,m=s.y-e.y,y=(g*h-m*d)/p,v=(g*o-m*n)/p;y>=0&&y<1&&v>=-1e-9&&v<=1+1e-9&&(i=Math.min(i,y))}),Number.isFinite(i)?{x:e.x+n*i,y:e.y+o*i}:null}function Tm(e,t,r=.5){const n=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.5,o=t==="top"||t==="bottom",i=t==="top"||t==="left"?-1:1,a={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},s=Math.max(e.w,e.h)*2+1;return{...wt(a,{x:a.x+(o?0:i*s),y:a.y+(o?i*s:0)},e)??{x:o?a.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:a.y},side:t}}function yt(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 I0(e,t,r,n){const o=yt(e,r.srcDist),i=yt(t,r.tgtDist);if(n==="straight")return Om(o,i,r);const a=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),s=e.side==="bottom"&&t.side==="top"?i.y-o.y:e.side==="top"&&t.side==="bottom"?o.y-i.y:e.side==="right"&&t.side==="left"?i.x-o.x:e.side==="left"&&t.side==="right"?o.x-i.x:void 0,c=s!==void 0&&s>0?Math.min(a,s/2):a,u=yt({...o,side:e.side},c),l=yt({...i,side:t.side},c),d=r.arrowAt==="source"?ir(o,u,r.arrowGap):o,h=r.arrowAt==="target"?ir(i,l,r.arrowGap):i,p=r.arrowAt==="source"?Cr(o,u,r.arrowSize,r.headShape):r.arrowAt==="target"?Cr(i,l,r.arrowSize,r.headShape):void 0;if(n==="bezier")return{d:`M${Qe(d)} C${Qe(u)} ${Qe(l)} ${Qe(h)}`,arrow:p,label:{x:(d.x+3*u.x+3*l.x+h.x)/8,y:(d.y+3*u.y+3*l.y+h.y)/8,angle:0}};const g=e.side==="left"||e.side==="right",m=t.side==="left"||t.side==="right";let y;if(g!==m){const b=g?{x:l.x,y:u.y}:{x:u.x,y:l.y},w=(b.x-u.x)*(u.x-o.x)+(b.y-u.y)*(u.y-o.y)>=0,x=(b.x-l.x)*(l.x-i.x)+(b.y-l.y)*(l.y-i.y)>=0;y=[w&&x?b:g?{x:u.x,y:l.y}:{x:l.x,y:u.y}]}else if(s!==void 0&&s<=0)if(g){const b=(u.y+l.y)/2;y=[{x:u.x,y:b},{x:l.x,y:b}]}else{const b=(u.x+l.x)/2;y=[{x:b,y:u.y},{x:b,y:l.y}]}else if(g){const b=e.side===t.side?e.side==="right"?Math.max(u.x,l.x):Math.min(u.x,l.x):(u.x+l.x)/2;y=[{x:b,y:u.y},{x:b,y:l.y}]}else{const b=e.side===t.side?e.side==="bottom"?Math.max(u.y,l.y):Math.min(u.y,l.y):(u.y+l.y)/2;y=[{x:u.x,y:b},{x:l.x,y:b}]}const v=[u,...y,l].filter((b,w,x)=>w===0||b.x!==x[w-1].x||b.y!==x[w-1].y);return kn(d,v,h,p,n==="orthogonal"?0:r.radius)}function ir(e,t,r){const n=e.x-t.x,o=e.y-t.y,i=Math.hypot(n,o);if(!i)return e;let a=(i-r)/i;return a<0&&(a=1e-5),{x:t.x+a*n,y:t.y+a*o}}function Cr(e,t,r,n="triangle"){const o=e.x-t.x,i=e.y-t.y,a=Math.hypot(o,i)||1,s=o/a,c=i/a,u=(n==="square"?.15:.3)*r,l=.15*r,d=e.x-s*u,h=e.y-c*u;return n==="square"?`M${Qe(e)} L${pr(e.x-c*l)} ${pr(e.y+s*l)} L${pr(d-c*l)} ${pr(h+s*l)} L${pr(d+c*l)} ${pr(h-s*l)} L${pr(e.x+c*l)} ${pr(e.y-s*l)} Z`:`M${Qe(e)} L${pr(d-c*l)} ${pr(h+s*l)} L${pr(d+c*l)} ${pr(h-s*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 O0(e,t,r,n){const o={x:t.x-e.x,y:t.y-e.y},i={x:r.x-t.x,y:r.y-t.y},a=Math.hypot(o.x,o.y),s=Math.hypot(i.x,i.y),c=o.x*i.y-o.y*i.x;if(a<1e-6||s<1e-6||Math.abs(c)<1e-6)return{p1:t,b:t,p2:t,r:0};const u=Math.min(n,a/2,s/2);return{p1:{x:t.x-o.x/a*u,y:t.y-o.y/a*u},b:t,p2:{x:t.x+i.x/s*u,y:t.y+i.y/s*u},r:u}}function Im(e,t,r,n){let o=-1,i=null;for(let g=0;g<e.length-1;g++){const m=wt(e[g],e[g+1],t);if(m){o=g,i=m;break}}let a=-1,s=null;for(let g=e.length-1;g>0;g--){const m=wt(e[g],e[g-1],r);if(m){a=g,s=m;break}}if(!i||!s||o>=a)return null;const c=e.slice(o+1,a),u=c[0]??s,l=c[c.length-1]??i;let d,h,p;if(n.arrowAt==="source"){const g=ir(i,u,n.srcDist);d=ir(i,u,n.srcDist+n.arrowGap),p=Cr(g,u,n.arrowSize,n.headShape)}else d=ir(i,u,n.srcDist);if(n.arrowAt==="target"){const g=ir(s,l,n.tgtDist);h=ir(s,l,n.tgtDist+n.arrowGap),p=Cr(g,l,n.arrowSize,n.headShape)}else h=ir(s,l,n.tgtDist);return kn(d,c,h,p,n.radius,n.labelTargetLength,n.labelFraction)}function kn(e,t,r,n,o,i,a){var h;const s=[e,...t,r],c=[];let u=`M${Qe(e)}`;for(let p=1;p<s.length-1;p++){const g=O0(s[p-1],s[p],s[p+1],o);c.push(g),g.r===0?u+=` L${Qe(g.b)}`:u+=` L${Qe(g.p1)} Q${Qe(g.b)} ${Qe(g.p2)}`}u+=` L${Qe(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],g=t[d/2];l={x:(p.x+g.x)/2,y:(p.y+g.y)/2,angle:Br(g.x-p.x,g.y-p.y)}}else{const p=c[(d-1)/2];if(p.r===0){const g=s[(d-1)/2+2];l={x:p.b.x,y:p.b.y,angle:Br(g.x-p.b.x,g.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(a!==void 0&&c.length===2){const y=c[0].p2,v=c[1].p1,b=Math.hypot(v.x-y.x,v.y-y.y),w=Math.min(.5,i/(2*b)),x=Math.max(w,Math.min(1-w,a));l={x:y.x+(v.x-y.x)*x,y:y.y+(v.y-y.y)*x,angle:Br(v.x-y.x,v.y-y.y)}}const p=((h=c[c.length-1])==null?void 0:h.p2)??e,g=r.x-p.x,m=r.y-p.y;Math.hypot(g,m)>=i&&(l={x:(p.x+r.x)/2,y:(p.y+r.y)/2,angle:Br(g,m)})}return{d:u,arrow:n,label:l}}function Fl(e,t,r,n,o,i,a){const s=r==="leftward"?-1:1,c={x:e.x+s*(e.w/2+a.srcDist),y:n??e.y},u={x:t.x-s*(t.w/2+a.tgtDist),y:o??t.y},l=Math.max(80,a.arrowGap+a.arrowSize*.3),d=c.x+s*l,h=u.x-s*l;let p;if(s*(h-d)>=0){const v=c.x+(u.x-c.x)*i,b=Math.max(Math.min(d,h),Math.min(Math.max(d,h),v));p=[{x:b,y:c.y},{x:b,y:u.y}]}else{const v=Math.min(e.y-e.h/2,t.y-t.h/2)-l*(1+i);p=[{x:d,y:c.y},{x:d,y:v},{x:h,y:v},{x:h,y:u.y}]}const g=a.arrowAt==="source"?ir(c,p[0],a.arrowGap):c,m=a.arrowAt==="target"?ir(u,p[p.length-1],a.arrowGap):u,y=a.arrowAt==="source"?Cr(c,p[0],a.arrowSize,a.headShape):a.arrowAt==="target"?Cr(u,p[p.length-1],a.arrowSize,a.headShape):void 0;return kn(g,p,m,y,a.radius)}function Bl(e,t,r,n,o){return Im(A0(e,t,r,n),e,t,o)}function zl(e,t,r,n,o,i){const a=n===void 0&&o===void 0&&(r==="downward"||r==="upward"),s=r==="leftward"||a&&r==="upward"?-1:1,c=(u,l,d)=>{const h={x:u.x,y:l??u.y},p=Math.max(u.w,u.h)*2+1,g=wt(h,{x:h.x+(a?0:d*p),y:h.y+(a?d*p:0)},u);return g?{x:g.x+(a?0:d*i),y:g.y+(a?d*i:0)}:a?{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,s),targetPoint:c(t,o,-s)}}function M0(e,t,r,n){const o=r==="downward"||r==="upward",i=r==="leftward"||r==="upward"?-1:1,a=Math.max(100,Math.abs(o?t.y-e.y:t.x-e.x)/2),s={x:e.x+(o?0:i*a),y:e.y+(o?i*a:0)},c={x:t.x-(o?0:i*a),y:t.y-(o?i*a:0)},u=n.arrowAt==="source"?ir(e,s,n.arrowGap):e,l=n.arrowAt==="target"?ir(t,c,n.arrowGap):t;return{d:`M${Qe(u)} C${Qe(s)} ${Qe(c)} ${Qe(l)}`,arrow:n.arrowAt==="source"?Cr(e,s,n.arrowSize,n.headShape):n.arrowAt==="target"?Cr(t,c,n.arrowSize,n.headShape):void 0,label:{x:(u.x+3*s.x+3*c.x+l.x)/8,y:(u.y+3*s.y+3*c.y+l.y)/8,angle:Br(l.x+c.x-s.x-u.x,l.y+c.y-s.y-u.y)}}}function Om(e,t,r){const n=r.arrowAt==="source"?ir(e,t,r.arrowGap):e,o=r.arrowAt==="target"?ir(t,e,r.arrowGap):t,i=r.arrowAt==="source"?Cr(e,t,r.arrowSize,r.headShape):r.arrowAt==="target"?Cr(t,e,r.arrowSize,r.headShape):void 0;return kn(n,[],o,i,0)}function q0(e,t,r,n=-90,o=-60,i=350){const a=n*Math.PI/180,s=o*Math.PI/180,c=a-Math.PI/2,u=c-s/2,l=c+s/2,d=1.4*i*(t/3+1),h={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},g={x:e.x,y:e.y},m=wt(g,h,e),y=wt(g,p,e);if(!m||!y)return null;const v={x:(h.x+p.x)/2,y:(h.y+p.y)/2};let b=ir(m,h,r.srcDist),w=ir(y,p,r.tgtDist),x;if(r.arrowAt==="target"){const S=w;w=ir(y,p,r.tgtDist+r.arrowGap),x=Cr(S,p,r.arrowSize,r.headShape)}else if(r.arrowAt==="source"){const S=b;b=ir(m,h,r.srcDist+r.arrowGap),x=Cr(S,h,r.arrowSize,r.headShape)}return{d:`M${Qe(b)} Q${Qe(h)} ${Qe(v)} Q${Qe(p)} ${Qe(w)}`,arrow:x,label:{x:v.x,y:v.y,angle:Br(p.x-h.x,p.y-h.y)}}}const dt=e=>Math.round(e*1e3)/1e3;function Mm(e){const t=e.querySelector("[data-flow-node-surface]");if(!t)return;const r=e.getBoundingClientRect(),n=r.width/e.offsetWidth;if(!Number.isFinite(n)||n<=0)return;const o=t.getBoundingClientRect();if(!o.width||!o.height)return;const i=t,a=typeof i.getScreenCTM=="function"?i.getScreenCTM():null,s=typeof i.getTotalLength=="function"?i.getTotalLength():0,c=i.points,u=(c==null?void 0:c.numberOfItems)||128,l=a&&s>0?Array.from({length:u},(d,h)=>{const p=c!=null&&c.numberOfItems?c.getItem(h):i.getPointAtLength(s*h/u);return{x:dt((a.a*p.x+a.c*p.y+a.e-r.left)/n),y:dt((a.b*p.x+a.d*p.y+a.f-r.top)/n)}}):void 0;return{left:dt((o.left-r.left)/n),top:dt((o.top-r.top)/n),width:t instanceof HTMLElement?t.offsetWidth:dt(o.width/n),height:t instanceof HTMLElement?t.offsetHeight:dt(o.height/n),radius:parseFloat(getComputedStyle(t).borderTopLeftRadius)||0,...l?{outline:l}:{}}}function Ut(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 N0(e,t,r,n,o){var l;const i=o!=="TB"&&o!=="BT",a=i?"top":"left",s=i?"bottom":"right",c=new Map;for(const d of n)for(const[h,p,g]of[[d.source,d.sourceProperty,d.target],[d.target,d.targetProperty,d.source]]){const m=t.get(g);if(p===void 0||!m||g===h)continue;const y=r.get(g),v=JSON.stringify([h,p]),b=c.get(v)??[];b.push(y?Ut(m,y):m),c.set(v,b)}const u=new Map(e);for(const[d,h]of e){const p=t.get(d);if(!p||!h.some(w=>w.placement==="config"))continue;const g=r.get(d),m=g?Ut(p,g):p,y={x:p.w/2,y:p.h/2,w:p.w,h:p.h},v=g?Ut(y,g):y,b=new Map;for(const w of h){if(w.placement!=="config")continue;const C=(c.get(JSON.stringify([d,w.property]))??[]).reduce((j,T)=>j+(i?T.y-m.y:T.x-m.x),0),S=((l=w.anchor)==null?void 0:l.side)===s?s:a;b.set(w,C<-.001?a:C>.001?s:S)}u.set(d,h.map(w=>{const x=b.get(w);if(!x)return w;const C=h.filter(T=>b.get(T)===x),S=(C.indexOf(w)+1)/(C.length+1),j=Tm(v,x,S);return{...w,anchor:j,top:j.y,height:0}}))}return u}function Dl(e,t,r){const n=new Set(t.map(s=>s.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const s of t)!o.has(s.id)&&(o.has(s.parent??"")||s.id.startsWith(`${e}.`))&&(o.add(s.id),i=!0)}const a=new Set(o);for(const s of r)o.has(s.source)&&n.has(s.target)&&a.add(s.target),o.has(s.target)&&n.has(s.source)&&a.add(s.source);return a}const ot='"Helvetica Neue", Helvetica, sans-serif';let It;const fn=new Map;function Pn(e,t){const r=`${t}|${e}`,n=fn.get(r);if(n!==void 0)return n;It===void 0&&(It=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let o;return It?(It.font=t,o=It.measureText(e).width):o=e.length*(parseFloat(t)||16)*.55,fn.size>5e3&&fn.clear(),fn.set(r,o),o}function $0(e,t,r){const n=[];for(const o of String(e).split(`
209
+ `)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let a="";for(const s of i){const c=a?`${a} ${s}`:s;!a||Pn(c,t)<=r?a=c:(n.push(a),a=s)}n.push(a)}return n}const L0=e=>e.stopPropagation();function F0({id:e,rect:t,label:r,labelLayer:n,style:o,onSelect:i,onCollapse:a,selected:s=!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,h=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,g=r?Pn(r,`bold ${o.fontSize}px ${ot}`):0,m=o.fontSize/5,y=r||s&&a?f.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[s&&a&&f.jsx("foreignObject",{x:h+g/2+m+8,y:p-24,width:48,height:48,"data-flow-content-toggle":"",style:{pointerEvents:"auto"},children:f.jsx(Ae,{label:"Show icon",children:f.jsx(Se,{"aria-label":"Show icon",icon:f.jsx(K.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:o.textColor},onClick:v=>{v.stopPropagation(),a(e)}})})}),r&&f.jsxs(f.Fragment,{children:[f.jsx("rect",{x:h-g/2-m,y:p-o.fontSize/2-m,width:g+2*m,height:o.fontSize+2*m,fill:o.textColor==="transparent"?"transparent":o.labelBg}),f.jsx("text",{x:h,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 f.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:L0,onClick:v=>{v.stopPropagation(),i==null||i(e,{shiftKey:v.shiftKey,ctrlKey:v.ctrlKey,metaKey:v.metaKey,altKey:v.altKey})},children:[f.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"&&f.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&&f.jsx(Am,{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&&y?Kt.createPortal(y,n):y]})}const B0=_.memo(F0),xn=45,qm=70,Qr=15,Nm=50;function $m(e,t,r=xn){const n=`${r}px ${ot}`,o=e?$0(e,n,200*r/xn):[],i=t?48+(o.length?12:0):0,a=i+Math.max(0,...o.map(u=>Pn(u,n))),s=Math.max(o.length*r,t?48:0),c=o.length||t?2*Qr:0;return{lines:o,iconWidth:i,contentWidth:a,contentHeight:s,width:a+c,height:s+c}}const Ht=6,Lm=3,Wu=Math.max(Math.pow(Ht*13.37,.9),29)*Lm,Fm=Ht*Lm*2,pn=80,z0=2*pn+Wu*.3+100,D0=36+2*Math.max(80,Fm+Wu*.3);function ku(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function Pu(e,t){return t==="auto"||(t==="properties"?ku(e):!ku(e))}function pt(e,t,r){return r!=="properties"||e!=="root"||t.some(n=>(n.source===e||n.target===e)&&ku(n))}function V0(e,t,r,n=!1,o){if(!n)return{nodes:e,edges:t};const i=e.filter(s=>pt(s.id,t,r)&&(!o||o.has(s.id))),a=new Set(i.map(s=>s.id));return{nodes:i,edges:t.filter(s=>Pu(s,r)&&a.has(s.source)&&a.has(s.target))}}const W0=500,G0="32 18",U0=e=>e.stopPropagation();function H0({id:e,reveal:t,onRevealComplete:r,edgeData:n,validationIssue:o,edgeType:i="rounded-orthogonal",edgeRadius:a,customEdgeTypes:s,source:c,target:u,sourceProperty:l,targetProperty:d,sourceY:h,targetY:p,sourcePort:g,targetPort:m,propertyMode:y=!1,dir:v,turn:b,labelAtTarget:w,labelFraction:x,color:C,connectorColor:S,labelBg:j,labelLayer:T,label:k,dashed:M,animated:R,inverted:E,loopIndex:P=0,onSelect:I}){const q=n==null?void 0:n.icon,O=y?xn:qm,{lines:V,iconWidth:W,contentWidth:te,contentHeight:ne}=_.useMemo(()=>$m(k,q,O),[k,q,O]),ee=_.useMemo(()=>{const U={srcDist:pn,tgtDist:pn,arrowGap:Fm,arrowSize:Wu,headShape:y&&(E?h!==void 0||g:p!==void 0||m)?"square":"triangle",radius:a??(w?40:W0),arrowAt:E?"source":"target",labelTargetLength:w?te+2*Qr:void 0,labelFraction:w?x:void 0},ue=h!==void 0||p!==void 0||!!g||!!m,se=zl(c,u,v,h,p,0),we=h===void 0&&p===void 0&&(v==="downward"||v==="upward"),pe=g??{...se.sourcePoint,side:we?v==="upward"?"top":"bottom":v==="leftward"?"left":"right"},ze=m??{...se.targetPoint,side:we?v==="upward"?"bottom":"top":v==="leftward"?"right":"left"},Y=c.x===u.x&&c.y===u.y,fe=g||m?I0(pe,ze,{...U,srcDist:18,tgtDist:18},i):ue?Fl(c,u,v,h,p,b,{...U,srcDist:18,tgtDist:18,radius:a??Math.min(U.radius,40)}):Y?q0(c,P,{...U,srcDist:0,tgtDist:0}):Bl(c,u,v,b,U);if(!fe)return null;const _e=zl(c,u,v,h,p,ue?18:pn);g&&(_e.sourcePoint=yt(g,18)),m&&(_e.targetPoint=yt(m,18));const Ie=Object.prototype.hasOwnProperty.call(s??{},i)?s==null?void 0:s[i]:void 0;if(Ie){const Oe={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return Ie({edge:n??{id:e,source:"",target:""},source:{...c},target:{...u},..._e,direction:Oe[v],sourceY:h,targetY:p,inverted:!!E,defaultGeometry:fe})??fe}return Y||g||m?fe:i==="straight"?ue?Om(_e.sourcePoint,_e.targetPoint,U):Im([c,u],c,u,U):i==="bezier"?M0(_e.sourcePoint,_e.targetPoint,ue?v==="leftward"?"leftward":"rightward":v,U):i==="orthogonal"?ue?Fl(c,u,v,h,p,b,{...U,srcDist:18,tgtDist:18,radius:0}):Bl(c,u,v,b,{...U,radius:0}):fe},[c,e,n,i,a,s,u,y,h,p,g,m,v,b,E,P,w,x,te]);if(!ee)return null;const be=(v==="rightward"||v==="leftward")&&!Object.prototype.hasOwnProperty.call(s??{},i)&&!(y&&(h!==void 0||p!==void 0||g||m)),le=be?`translate(${ee.label.x} ${ee.label.y-ne/2-2*Qr})`:`translate(${ee.label.x} ${ee.label.y}) rotate(${ee.label.angle}) translate(${w||Object.prototype.hasOwnProperty.call(s??{},i)?0:Nm} 0)`,$=o!=null&&o.startsWith("Unverified:")?"#b45309":"#dc2626",z=o?$:C,G=o?f.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":o,transform:`translate(${ee.label.x} ${ee.label.y-V.length*O/2-55})`,children:[f.jsx("title",{children:o}),f.jsx(Ar,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:$})]}):null,N=R&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",re=!N&&(M||R)?G0:void 0,ye=R&&!N?`flow-sdk-edge-anim${E?" flow-sdk-edge-anim-rev":""}`:void 0;let de=null;const J=t?{"--flow-edge-reveal-duration":`${t.durationMs??600}ms`,"--flow-edge-reveal-state":t.paused?"paused":"running"}:void 0;if(V.length||q){const U=te,ue=ne;de=f.jsxs("g",{className:`flow-sdk-edge-label${t?" flow-sdk-edge-reveal-end":""}`,style:J,"data-label-transform":le,"data-label-horizontal":be||void 0,"data-edge-id":e,"data-source-property":l,"data-target-property":d,transform:le,children:[f.jsx("rect",{x:-U/2-Qr,y:-ue/2-Qr,width:U+2*Qr,height:ue+2*Qr,fill:C==="transparent"?"transparent":j}),f.jsx("text",{fill:C,fontSize:O,style:{fontSize:O,fontFamily:ot},fontFamily:ot,textAnchor:"middle",dominantBaseline:"central",children:V.map((se,we)=>f.jsx("tspan",{x:W/2,y:(we-(V.length-1)/2)*O,children:se},we))}),q&&f.jsxs("g",{className:"flow-sdk-edge-icon",opacity:C==="transparent"?0:1,children:[f.jsx("title",{children:k?`Edge icon: ${k}`:"Edge icon"}),f.jsx("rect",{x:-U/2,y:-24,width:48,height:48,fill:"transparent"}),f.jsx(Ar,{name:q,svg:!0,size:48,x:-U/2,y:-24,color:C})]})]})}const X=f.jsxs(f.Fragment,{children:[f.jsx("path",{d:ee.d,fill:"none",stroke:z,strokeWidth:Ht,strokeOpacity:N?.35:void 0,strokeDasharray:re,className:ye}),N&&f.jsx(w0,{path:ee.d,color:z,width:Ht*1.6,reversed:E})]});return f.jsxs("g",{className:"flow-sdk-edge",style:J,"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:U0,onClick:U=>{U.stopPropagation(),I==null||I(e)},children:[t?f.jsx(_0,{path:ee.d,width:Ht*4,reversed:E,onComplete:()=>r==null?void 0:r(e),children:X}):X,ee.arrow&&f.jsx("path",{className:t?"flow-sdk-edge-reveal-end":void 0,d:ee.arrow,fill:o?$:S??z}),T&&de?Kt.createPortal(de,T):de,T&&G?Kt.createPortal(G,T):G,f.jsx("path",{className:"flow-sdk-edge-hit",d:ee.d,fill:"none",stroke:"transparent"})]})}const Vl=_.memo(H0),Wl=(e,t)=>e.left<t.right&&e.right>t.left&&e.top<t.bottom&&e.bottom>t.top;function K0(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(),h=new DOMPoint(d.left,d.top).matrixTransform(n),p=new DOMPoint(d.right,d.bottom).matrixTransform(n);return{left:h.x-l,right:p.x+l,top:h.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 a=[...t.querySelectorAll(".flow-sdk-edge-label")];for(const u of a)u.setAttribute("transform",u.dataset.labelTransform??"");const s=new Map(a.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 a){const l=u.dataset.labelHorizontal==="true",d=s.get(u);s.delete(u);const h=j=>i.some(T=>Wl(j,T))||[...s.values()].some(T=>Wl(j,T));if(!l&&!h(d)){s.set(u,d);continue}const p=c.get(u.dataset.edgeId),g=u.querySelector("rect");if(!p||!g)continue;const m=g.getBBox(),y=p.getTotalLength();if(!Number.isFinite(y)||y<=0)continue;const v=(d.left+d.right)/2,b=(d.top+d.bottom)/2,w=Math.min(256,Math.max(16,Math.ceil(y/24))),x=Array.from({length:w+1},(j,T)=>p.getPointAtLength(y*T/w)),S=Array.from({length:w+1},(j,T)=>{const k=y*T/w,M=x[T],R=l?{x:M.x,y:M.y-m.height/2-15}:M,E=p.getPointAtLength(Math.max(0,k-2)),P=p.getPointAtLength(Math.min(y,k+2));let I=Math.atan2(P.y-E.y,P.x-E.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,V=Math.abs(Math.cos(O))*m.width+Math.abs(Math.sin(O))*m.height,W=Math.abs(Math.sin(O))*m.width+Math.abs(Math.cos(O))*m.height;return{point:R,angle:I,straight:q,score:Math.hypot(R.x-v,R.y-b),bounds:{left:R.x-V/2-8,right:R.x+V/2+8,top:R.y-W/2-8,bottom:R.y+W/2+8}}}).sort((j,T)=>j.score-T.score).find(j=>!h(j.bounds)&&(!l||j.straight&&!x.some(T=>T.x>j.bounds.left&&T.x<j.bounds.right&&T.y>j.bounds.top&&T.y<j.bounds.bottom)));S?(u.setAttribute("transform",`translate(${S.point.x} ${S.point.y}) rotate(${S.angle})`),s.set(u,S.bounds)):s.set(u,d)}}var hn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function J0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Gu(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 no,Gl;function Z0(){if(Gl)return no;Gl=1;function e(){this.__data__=[],this.size=0}return no=e,no}var oo,Ul;function Et(){if(Ul)return oo;Ul=1;function e(t,r){return t===r||t!==t&&r!==r}return oo=e,oo}var io,Hl;function An(){if(Hl)return io;Hl=1;var e=Et();function t(r,n){for(var o=r.length;o--;)if(e(r[o][0],n))return o;return-1}return io=t,io}var ao,Kl;function Y0(){if(Kl)return ao;Kl=1;var e=An(),t=Array.prototype,r=t.splice;function n(o){var i=this.__data__,a=e(i,o);if(a<0)return!1;var s=i.length-1;return a==s?i.pop():r.call(i,a,1),--this.size,!0}return ao=n,ao}var so,Jl;function X0(){if(Jl)return so;Jl=1;var e=An();function t(r){var n=this.__data__,o=e(n,r);return o<0?void 0:n[o][1]}return so=t,so}var co,Zl;function Q0(){if(Zl)return co;Zl=1;var e=An();function t(r){return e(this.__data__,r)>-1}return co=t,co}var uo,Yl;function ew(){if(Yl)return uo;Yl=1;var e=An();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 uo=t,uo}var lo,Xl;function Tn(){if(Xl)return lo;Xl=1;var e=Z0(),t=Y0(),r=X0(),n=Q0(),o=ew();function i(a){var s=-1,c=a==null?0:a.length;for(this.clear();++s<c;){var u=a[s];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,lo=i,lo}var fo,Ql;function rw(){if(Ql)return fo;Ql=1;var e=Tn();function t(){this.__data__=new e,this.size=0}return fo=t,fo}var ho,ed;function tw(){if(ed)return ho;ed=1;function e(t){var r=this.__data__,n=r.delete(t);return this.size=r.size,n}return ho=e,ho}var po,rd;function nw(){if(rd)return po;rd=1;function e(t){return this.__data__.get(t)}return po=e,po}var go,td;function ow(){if(td)return go;td=1;function e(t){return this.__data__.has(t)}return go=e,go}var yo,nd;function Bm(){if(nd)return yo;nd=1;var e=typeof hn=="object"&&hn&&hn.Object===Object&&hn;return yo=e,yo}var mo,od;function kr(){if(od)return mo;od=1;var e=Bm(),t=typeof self=="object"&&self&&self.Object===Object&&self,r=e||t||Function("return this")();return mo=r,mo}var bo,id;function jt(){if(id)return bo;id=1;var e=kr(),t=e.Symbol;return bo=t,bo}var vo,ad;function iw(){if(ad)return vo;ad=1;var e=jt(),t=Object.prototype,r=t.hasOwnProperty,n=t.toString,o=e?e.toStringTag:void 0;function i(a){var s=r.call(a,o),c=a[o];try{a[o]=void 0;var u=!0}catch{}var l=n.call(a);return u&&(s?a[o]=c:delete a[o]),l}return vo=i,vo}var xo,sd;function aw(){if(sd)return xo;sd=1;var e=Object.prototype,t=e.toString;function r(n){return t.call(n)}return xo=r,xo}var wo,cd;function it(){if(cd)return wo;cd=1;var e=jt(),t=iw(),r=aw(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function a(s){return s==null?s===void 0?o:n:i&&i in Object(s)?t(s):r(s)}return wo=a,wo}var Co,ud;function _r(){if(ud)return Co;ud=1;function e(t){var r=typeof t;return t!=null&&(r=="object"||r=="function")}return Co=e,Co}var _o,ld;function an(){if(ld)return _o;ld=1;var e=it(),t=_r(),r="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function a(s){if(!t(s))return!1;var c=e(s);return c==n||c==o||c==r||c==i}return _o=a,_o}var So,dd;function sw(){if(dd)return So;dd=1;var e=kr(),t=e["__core-js_shared__"];return So=t,So}var Eo,fd;function cw(){if(fd)return Eo;fd=1;var e=sw(),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 Eo=r,Eo}var jo,hd;function zm(){if(hd)return jo;hd=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 jo=r,jo}var Ro,pd;function uw(){if(pd)return Ro;pd=1;var e=an(),t=cw(),r=_r(),n=zm(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,a=Function.prototype,s=Object.prototype,c=a.toString,u=s.hasOwnProperty,l=RegExp("^"+c.call(u).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function d(h){if(!r(h)||t(h))return!1;var p=e(h)?l:i;return p.test(n(h))}return Ro=d,Ro}var ko,gd;function lw(){if(gd)return ko;gd=1;function e(t,r){return t==null?void 0:t[r]}return ko=e,ko}var Po,yd;function at(){if(yd)return Po;yd=1;var e=uw(),t=lw();function r(n,o){var i=t(n,o);return e(i)?i:void 0}return Po=r,Po}var Ao,md;function Uu(){if(md)return Ao;md=1;var e=at(),t=kr(),r=e(t,"Map");return Ao=r,Ao}var To,bd;function In(){if(bd)return To;bd=1;var e=at(),t=e(Object,"create");return To=t,To}var Io,vd;function dw(){if(vd)return Io;vd=1;var e=In();function t(){this.__data__=e?e(null):{},this.size=0}return Io=t,Io}var Oo,xd;function fw(){if(xd)return Oo;xd=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 Mo,wd;function hw(){if(wd)return Mo;wd=1;var e=In(),t="__lodash_hash_undefined__",r=Object.prototype,n=r.hasOwnProperty;function o(i){var a=this.__data__;if(e){var s=a[i];return s===t?void 0:s}return n.call(a,i)?a[i]:void 0}return Mo=o,Mo}var qo,Cd;function pw(){if(Cd)return qo;Cd=1;var e=In(),t=Object.prototype,r=t.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:r.call(i,o)}return qo=n,qo}var No,_d;function gw(){if(_d)return No;_d=1;var e=In(),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 No=r,No}var $o,Sd;function yw(){if(Sd)return $o;Sd=1;var e=dw(),t=fw(),r=hw(),n=pw(),o=gw();function i(a){var s=-1,c=a==null?0:a.length;for(this.clear();++s<c;){var u=a[s];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,$o=i,$o}var Lo,Ed;function mw(){if(Ed)return Lo;Ed=1;var e=yw(),t=Tn(),r=Uu();function n(){this.size=0,this.__data__={hash:new e,map:new(r||t),string:new e}}return Lo=n,Lo}var Fo,jd;function bw(){if(jd)return Fo;jd=1;function e(t){var r=typeof t;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?t!=="__proto__":t===null}return Fo=e,Fo}var Bo,Rd;function On(){if(Rd)return Bo;Rd=1;var e=bw();function t(r,n){var o=r.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return Bo=t,Bo}var zo,kd;function vw(){if(kd)return zo;kd=1;var e=On();function t(r){var n=e(this,r).delete(r);return this.size-=n?1:0,n}return zo=t,zo}var Do,Pd;function xw(){if(Pd)return Do;Pd=1;var e=On();function t(r){return e(this,r).get(r)}return Do=t,Do}var Vo,Ad;function ww(){if(Ad)return Vo;Ad=1;var e=On();function t(r){return e(this,r).has(r)}return Vo=t,Vo}var Wo,Td;function Cw(){if(Td)return Wo;Td=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 Wo=t,Wo}var Go,Id;function Hu(){if(Id)return Go;Id=1;var e=mw(),t=vw(),r=xw(),n=ww(),o=Cw();function i(a){var s=-1,c=a==null?0:a.length;for(this.clear();++s<c;){var u=a[s];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,Go=i,Go}var Uo,Od;function _w(){if(Od)return Uo;Od=1;var e=Tn(),t=Uu(),r=Hu(),n=200;function o(i,a){var s=this.__data__;if(s instanceof e){var c=s.__data__;if(!t||c.length<n-1)return c.push([i,a]),this.size=++s.size,this;s=this.__data__=new r(c)}return s.set(i,a),this.size=s.size,this}return Uo=o,Uo}var Ho,Md;function Mn(){if(Md)return Ho;Md=1;var e=Tn(),t=rw(),r=tw(),n=nw(),o=ow(),i=_w();function a(s){var c=this.__data__=new e(s);this.size=c.size}return a.prototype.clear=t,a.prototype.delete=r,a.prototype.get=n,a.prototype.has=o,a.prototype.set=i,Ho=a,Ho}var Ko,qd;function Ku(){if(qd)return Ko;qd=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 Ko=e,Ko}var Jo,Nd;function Dm(){if(Nd)return Jo;Nd=1;var e=at(),t=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return Jo=t,Jo}var Zo,$d;function qn(){if($d)return Zo;$d=1;var e=Dm();function t(r,n,o){n=="__proto__"&&e?e(r,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):r[n]=o}return Zo=t,Zo}var Yo,Ld;function Nn(){if(Ld)return Yo;Ld=1;var e=qn(),t=Et(),r=Object.prototype,n=r.hasOwnProperty;function o(i,a,s){var c=i[a];(!(n.call(i,a)&&t(c,s))||s===void 0&&!(a in i))&&e(i,a,s)}return Yo=o,Yo}var Xo,Fd;function sn(){if(Fd)return Xo;Fd=1;var e=Nn(),t=qn();function r(n,o,i,a){var s=!i;i||(i={});for(var c=-1,u=o.length;++c<u;){var l=o[c],d=a?a(i[l],n[l],l,i,n):void 0;d===void 0&&(d=n[l]),s?t(i,l,d):e(i,l,d)}return i}return Xo=r,Xo}var Qo,Bd;function Sw(){if(Bd)return Qo;Bd=1;function e(t,r){for(var n=-1,o=Array(t);++n<t;)o[n]=r(n);return o}return Qo=e,Qo}var ei,zd;function Tr(){if(zd)return ei;zd=1;function e(t){return t!=null&&typeof t=="object"}return ei=e,ei}var ri,Dd;function Ew(){if(Dd)return ri;Dd=1;var e=it(),t=Tr(),r="[object Arguments]";function n(o){return t(o)&&e(o)==r}return ri=n,ri}var ti,Vd;function cn(){if(Vd)return ti;Vd=1;var e=Ew(),t=Tr(),r=Object.prototype,n=r.hasOwnProperty,o=r.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(a){return t(a)&&n.call(a,"callee")&&!o.call(a,"callee")};return ti=i,ti}var ni,Wd;function rr(){if(Wd)return ni;Wd=1;var e=Array.isArray;return ni=e,ni}var $t={exports:{}},oi,Gd;function jw(){if(Gd)return oi;Gd=1;function e(){return!1}return oi=e,oi}$t.exports;var Ud;function Rt(){return Ud||(Ud=1,(function(e,t){var r=kr(),n=jw(),o=t&&!t.nodeType&&t,i=o&&!0&&e&&!e.nodeType&&e,a=i&&i.exports===o,s=a?r.Buffer:void 0,c=s?s.isBuffer:void 0,u=c||n;e.exports=u})($t,$t.exports)),$t.exports}var ii,Hd;function $n(){if(Hd)return ii;Hd=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 ii=r,ii}var ai,Kd;function Ju(){if(Kd)return ai;Kd=1;var e=9007199254740991;function t(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return ai=t,ai}var si,Jd;function Rw(){if(Jd)return si;Jd=1;var e=it(),t=Ju(),r=Tr(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",a="[object Date]",s="[object Error]",c="[object Function]",u="[object Map]",l="[object Number]",d="[object Object]",h="[object RegExp]",p="[object Set]",g="[object String]",m="[object WeakMap]",y="[object ArrayBuffer]",v="[object DataView]",b="[object Float32Array]",w="[object Float64Array]",x="[object Int8Array]",C="[object Int16Array]",S="[object Int32Array]",j="[object Uint8Array]",T="[object Uint8ClampedArray]",k="[object Uint16Array]",M="[object Uint32Array]",R={};R[b]=R[w]=R[x]=R[C]=R[S]=R[j]=R[T]=R[k]=R[M]=!0,R[n]=R[o]=R[y]=R[i]=R[v]=R[a]=R[s]=R[c]=R[u]=R[l]=R[d]=R[h]=R[p]=R[g]=R[m]=!1;function E(P){return r(P)&&t(P.length)&&!!R[e(P)]}return si=E,si}var ci,Zd;function Ln(){if(Zd)return ci;Zd=1;function e(t){return function(r){return t(r)}}return ci=e,ci}var Lt={exports:{}};Lt.exports;var Yd;function Zu(){return Yd||(Yd=1,(function(e,t){var r=Bm(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,a=i&&r.process,s=(function(){try{var c=o&&o.require&&o.require("util").types;return c||a&&a.binding&&a.binding("util")}catch{}})();e.exports=s})(Lt,Lt.exports)),Lt.exports}var ui,Xd;function un(){if(Xd)return ui;Xd=1;var e=Rw(),t=Ln(),r=Zu(),n=r&&r.isTypedArray,o=n?t(n):e;return ui=o,ui}var li,Qd;function Vm(){if(Qd)return li;Qd=1;var e=Sw(),t=cn(),r=rr(),n=Rt(),o=$n(),i=un(),a=Object.prototype,s=a.hasOwnProperty;function c(u,l){var d=r(u),h=!d&&t(u),p=!d&&!h&&n(u),g=!d&&!h&&!p&&i(u),m=d||h||p||g,y=m?e(u.length,String):[],v=y.length;for(var b in u)(l||s.call(u,b))&&!(m&&(b=="length"||p&&(b=="offset"||b=="parent")||g&&(b=="buffer"||b=="byteLength"||b=="byteOffset")||o(b,v)))&&y.push(b);return y}return li=c,li}var di,ef;function Fn(){if(ef)return di;ef=1;var e=Object.prototype;function t(r){var n=r&&r.constructor,o=typeof n=="function"&&n.prototype||e;return r===o}return di=t,di}var fi,rf;function Wm(){if(rf)return fi;rf=1;function e(t,r){return function(n){return t(r(n))}}return fi=e,fi}var hi,tf;function kw(){if(tf)return hi;tf=1;var e=Wm(),t=e(Object.keys,Object);return hi=t,hi}var pi,nf;function Yu(){if(nf)return pi;nf=1;var e=Fn(),t=kw(),r=Object.prototype,n=r.hasOwnProperty;function o(i){if(!e(i))return t(i);var a=[];for(var s in Object(i))n.call(i,s)&&s!="constructor"&&a.push(s);return a}return pi=o,pi}var gi,of;function Nr(){if(of)return gi;of=1;var e=an(),t=Ju();function r(n){return n!=null&&t(n.length)&&!e(n)}return gi=r,gi}var yi,af;function Kr(){if(af)return yi;af=1;var e=Vm(),t=Yu(),r=Nr();function n(o){return r(o)?e(o):t(o)}return yi=n,yi}var mi,sf;function Pw(){if(sf)return mi;sf=1;var e=sn(),t=Kr();function r(n,o){return n&&e(o,t(o),n)}return mi=r,mi}var bi,cf;function Aw(){if(cf)return bi;cf=1;function e(t){var r=[];if(t!=null)for(var n in Object(t))r.push(n);return r}return bi=e,bi}var vi,uf;function Tw(){if(uf)return vi;uf=1;var e=_r(),t=Fn(),r=Aw(),n=Object.prototype,o=n.hasOwnProperty;function i(a){if(!e(a))return r(a);var s=t(a),c=[];for(var u in a)u=="constructor"&&(s||!o.call(a,u))||c.push(u);return c}return vi=i,vi}var xi,lf;function st(){if(lf)return xi;lf=1;var e=Vm(),t=Tw(),r=Nr();function n(o){return r(o)?e(o,!0):t(o)}return xi=n,xi}var wi,df;function Iw(){if(df)return wi;df=1;var e=sn(),t=st();function r(n,o){return n&&e(o,t(o),n)}return wi=r,wi}var Ft={exports:{}};Ft.exports;var ff;function Gm(){return ff||(ff=1,(function(e,t){var r=kr(),n=t&&!t.nodeType&&t,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,a=i?r.Buffer:void 0,s=a?a.allocUnsafe:void 0;function c(u,l){if(l)return u.slice();var d=u.length,h=s?s(d):new u.constructor(d);return u.copy(h),h}e.exports=c})(Ft,Ft.exports)),Ft.exports}var Ci,hf;function Um(){if(hf)return Ci;hf=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 Ci=e,Ci}var _i,pf;function Hm(){if(pf)return _i;pf=1;function e(t,r){for(var n=-1,o=t==null?0:t.length,i=0,a=[];++n<o;){var s=t[n];r(s,n,t)&&(a[i++]=s)}return a}return _i=e,_i}var Si,gf;function Km(){if(gf)return Si;gf=1;function e(){return[]}return Si=e,Si}var Ei,yf;function Xu(){if(yf)return Ei;yf=1;var e=Hm(),t=Km(),r=Object.prototype,n=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(a){return a==null?[]:(a=Object(a),e(o(a),function(s){return n.call(a,s)}))}:t;return Ei=i,Ei}var ji,mf;function Ow(){if(mf)return ji;mf=1;var e=sn(),t=Xu();function r(n,o){return e(n,t(n),o)}return ji=r,ji}var Ri,bf;function Qu(){if(bf)return Ri;bf=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 Ri=e,Ri}var ki,vf;function Bn(){if(vf)return ki;vf=1;var e=Wm(),t=e(Object.getPrototypeOf,Object);return ki=t,ki}var Pi,xf;function Jm(){if(xf)return Pi;xf=1;var e=Qu(),t=Bn(),r=Xu(),n=Km(),o=Object.getOwnPropertySymbols,i=o?function(a){for(var s=[];a;)e(s,r(a)),a=t(a);return s}:n;return Pi=i,Pi}var Ai,wf;function Mw(){if(wf)return Ai;wf=1;var e=sn(),t=Jm();function r(n,o){return e(n,t(n),o)}return Ai=r,Ai}var Ti,Cf;function Zm(){if(Cf)return Ti;Cf=1;var e=Qu(),t=rr();function r(n,o,i){var a=o(n);return t(n)?a:e(a,i(n))}return Ti=r,Ti}var Ii,_f;function Ym(){if(_f)return Ii;_f=1;var e=Zm(),t=Xu(),r=Kr();function n(o){return e(o,r,t)}return Ii=n,Ii}var Oi,Sf;function qw(){if(Sf)return Oi;Sf=1;var e=Zm(),t=Jm(),r=st();function n(o){return e(o,r,t)}return Oi=n,Oi}var Mi,Ef;function Nw(){if(Ef)return Mi;Ef=1;var e=at(),t=kr(),r=e(t,"DataView");return Mi=r,Mi}var qi,jf;function $w(){if(jf)return qi;jf=1;var e=at(),t=kr(),r=e(t,"Promise");return qi=r,qi}var Ni,Rf;function Xm(){if(Rf)return Ni;Rf=1;var e=at(),t=kr(),r=e(t,"Set");return Ni=r,Ni}var $i,kf;function Lw(){if(kf)return $i;kf=1;var e=at(),t=kr(),r=e(t,"WeakMap");return $i=r,$i}var Li,Pf;function kt(){if(Pf)return Li;Pf=1;var e=Nw(),t=Uu(),r=$w(),n=Xm(),o=Lw(),i=it(),a=zm(),s="[object Map]",c="[object Object]",u="[object Promise]",l="[object Set]",d="[object WeakMap]",h="[object DataView]",p=a(e),g=a(t),m=a(r),y=a(n),v=a(o),b=i;return(e&&b(new e(new ArrayBuffer(1)))!=h||t&&b(new t)!=s||r&&b(r.resolve())!=u||n&&b(new n)!=l||o&&b(new o)!=d)&&(b=function(w){var x=i(w),C=x==c?w.constructor:void 0,S=C?a(C):"";if(S)switch(S){case p:return h;case g:return s;case m:return u;case y:return l;case v:return d}return x}),Li=b,Li}var Fi,Af;function Fw(){if(Af)return Fi;Af=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 Fi=r,Fi}var Bi,Tf;function Qm(){if(Tf)return Bi;Tf=1;var e=kr(),t=e.Uint8Array;return Bi=t,Bi}var zi,If;function el(){if(If)return zi;If=1;var e=Qm();function t(r){var n=new r.constructor(r.byteLength);return new e(n).set(new e(r)),n}return zi=t,zi}var Di,Of;function Bw(){if(Of)return Di;Of=1;var e=el();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.byteLength)}return Di=t,Di}var Vi,Mf;function zw(){if(Mf)return Vi;Mf=1;var e=/\w*$/;function t(r){var n=new r.constructor(r.source,e.exec(r));return n.lastIndex=r.lastIndex,n}return Vi=t,Vi}var Wi,qf;function Dw(){if(qf)return Wi;qf=1;var e=jt(),t=e?e.prototype:void 0,r=t?t.valueOf:void 0;function n(o){return r?Object(r.call(o)):{}}return Wi=n,Wi}var Gi,Nf;function eb(){if(Nf)return Gi;Nf=1;var e=el();function t(r,n){var o=n?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.length)}return Gi=t,Gi}var Ui,$f;function Vw(){if($f)return Ui;$f=1;var e=el(),t=Bw(),r=zw(),n=Dw(),o=eb(),i="[object Boolean]",a="[object Date]",s="[object Map]",c="[object Number]",u="[object RegExp]",l="[object Set]",d="[object String]",h="[object Symbol]",p="[object ArrayBuffer]",g="[object DataView]",m="[object Float32Array]",y="[object Float64Array]",v="[object Int8Array]",b="[object Int16Array]",w="[object Int32Array]",x="[object Uint8Array]",C="[object Uint8ClampedArray]",S="[object Uint16Array]",j="[object Uint32Array]";function T(k,M,R){var E=k.constructor;switch(M){case p:return e(k);case i:case a:return new E(+k);case g:return t(k,R);case m:case y:case v:case b:case w:case x:case C:case S:case j:return o(k,R);case s:return new E;case c:case d:return new E(k);case u:return r(k);case l:return new E;case h:return n(k)}}return Ui=T,Ui}var Hi,Lf;function rb(){if(Lf)return Hi;Lf=1;var e=_r(),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 Hi=r,Hi}var Ki,Ff;function tb(){if(Ff)return Ki;Ff=1;var e=rb(),t=Bn(),r=Fn();function n(o){return typeof o.constructor=="function"&&!r(o)?e(t(o)):{}}return Ki=n,Ki}var Ji,Bf;function Ww(){if(Bf)return Ji;Bf=1;var e=kt(),t=Tr(),r="[object Map]";function n(o){return t(o)&&e(o)==r}return Ji=n,Ji}var Zi,zf;function Gw(){if(zf)return Zi;zf=1;var e=Ww(),t=Ln(),r=Zu(),n=r&&r.isMap,o=n?t(n):e;return Zi=o,Zi}var Yi,Df;function Uw(){if(Df)return Yi;Df=1;var e=kt(),t=Tr(),r="[object Set]";function n(o){return t(o)&&e(o)==r}return Yi=n,Yi}var Xi,Vf;function Hw(){if(Vf)return Xi;Vf=1;var e=Uw(),t=Ln(),r=Zu(),n=r&&r.isSet,o=n?t(n):e;return Xi=o,Xi}var Qi,Wf;function nb(){if(Wf)return Qi;Wf=1;var e=Mn(),t=Ku(),r=Nn(),n=Pw(),o=Iw(),i=Gm(),a=Um(),s=Ow(),c=Mw(),u=Ym(),l=qw(),d=kt(),h=Fw(),p=Vw(),g=tb(),m=rr(),y=Rt(),v=Gw(),b=_r(),w=Hw(),x=Kr(),C=st(),S=1,j=2,T=4,k="[object Arguments]",M="[object Array]",R="[object Boolean]",E="[object Date]",P="[object Error]",I="[object Function]",q="[object GeneratorFunction]",O="[object Map]",V="[object Number]",W="[object Object]",te="[object RegExp]",ne="[object Set]",ee="[object String]",be="[object Symbol]",le="[object WeakMap]",$="[object ArrayBuffer]",z="[object DataView]",G="[object Float32Array]",N="[object Float64Array]",re="[object Int8Array]",ye="[object Int16Array]",de="[object Int32Array]",J="[object Uint8Array]",X="[object Uint8ClampedArray]",U="[object Uint16Array]",ue="[object Uint32Array]",se={};se[k]=se[M]=se[$]=se[z]=se[R]=se[E]=se[G]=se[N]=se[re]=se[ye]=se[de]=se[O]=se[V]=se[W]=se[te]=se[ne]=se[ee]=se[be]=se[J]=se[X]=se[U]=se[ue]=!0,se[P]=se[I]=se[le]=!1;function we(pe,ze,Y,fe,_e,Ie){var Oe,Ue=ze&S,er=ze&j,De=ze&T;if(Y&&(Oe=_e?Y(pe,fe,_e,Ie):Y(pe)),Oe!==void 0)return Oe;if(!b(pe))return pe;var tr=m(pe);if(tr){if(Oe=h(pe),!Ue)return a(pe,Oe)}else{var he=d(pe),Re=he==I||he==q;if(y(pe))return i(pe,Ue);if(he==W||he==k||Re&&!_e){if(Oe=er||Re?{}:g(pe),!Ue)return er?c(pe,o(Oe,pe)):s(pe,n(Oe,pe))}else{if(!se[he])return _e?pe:{};Oe=p(pe,he,Ue)}}Ie||(Ie=new e);var Ze=Ie.get(pe);if(Ze)return Ze;Ie.set(pe,Oe),w(pe)?pe.forEach(function(He){Oe.add(we(He,ze,Y,He,pe,Ie))}):v(pe)&&pe.forEach(function(He,Ee){Oe.set(Ee,we(He,ze,Y,Ee,pe,Ie))});var lr=De?er?l:u:er?C:x,nr=tr?void 0:lr(pe);return t(nr||pe,function(He,Ee){nr&&(Ee=He,He=pe[Ee]),r(Oe,Ee,we(He,ze,Y,Ee,pe,Ie))}),Oe}return Qi=we,Qi}var ea,Gf;function Kw(){if(Gf)return ea;Gf=1;var e=nb(),t=4;function r(n){return e(n,t)}return ea=r,ea}var ra,Uf;function rl(){if(Uf)return ra;Uf=1;function e(t){return function(){return t}}return ra=e,ra}var ta,Hf;function Jw(){if(Hf)return ta;Hf=1;function e(t){return function(r,n,o){for(var i=-1,a=Object(r),s=o(r),c=s.length;c--;){var u=s[t?c:++i];if(n(a[u],u,a)===!1)break}return r}}return ta=e,ta}var na,Kf;function tl(){if(Kf)return na;Kf=1;var e=Jw(),t=e();return na=t,na}var oa,Jf;function nl(){if(Jf)return oa;Jf=1;var e=tl(),t=Kr();function r(n,o){return n&&e(n,o,t)}return oa=r,oa}var ia,Zf;function Zw(){if(Zf)return ia;Zf=1;var e=Nr();function t(r,n){return function(o,i){if(o==null)return o;if(!e(o))return r(o,i);for(var a=o.length,s=n?a:-1,c=Object(o);(n?s--:++s<a)&&i(c[s],s,c)!==!1;);return o}}return ia=t,ia}var aa,Yf;function zn(){if(Yf)return aa;Yf=1;var e=nl(),t=Zw(),r=t(e);return aa=r,aa}var sa,Xf;function ct(){if(Xf)return sa;Xf=1;function e(t){return t}return sa=e,sa}var ca,Qf;function ob(){if(Qf)return ca;Qf=1;var e=ct();function t(r){return typeof r=="function"?r:e}return ca=t,ca}var ua,eh;function ib(){if(eh)return ua;eh=1;var e=Ku(),t=zn(),r=ob(),n=rr();function o(i,a){var s=n(i)?e:t;return s(i,r(a))}return ua=o,ua}var la,rh;function ab(){return rh||(rh=1,la=ib()),la}var da,th;function Yw(){if(th)return da;th=1;var e=zn();function t(r,n){var o=[];return e(r,function(i,a,s){n(i,a,s)&&o.push(i)}),o}return da=t,da}var fa,nh;function Xw(){if(nh)return fa;nh=1;var e="__lodash_hash_undefined__";function t(r){return this.__data__.set(r,e),this}return fa=t,fa}var ha,oh;function Qw(){if(oh)return ha;oh=1;function e(t){return this.__data__.has(t)}return ha=e,ha}var pa,ih;function sb(){if(ih)return pa;ih=1;var e=Hu(),t=Xw(),r=Qw();function n(o){var i=-1,a=o==null?0:o.length;for(this.__data__=new e;++i<a;)this.add(o[i])}return n.prototype.add=n.prototype.push=t,n.prototype.has=r,pa=n,pa}var ga,ah;function e1(){if(ah)return ga;ah=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 ga=e,ga}var ya,sh;function cb(){if(sh)return ya;sh=1;function e(t,r){return t.has(r)}return ya=e,ya}var ma,ch;function ub(){if(ch)return ma;ch=1;var e=sb(),t=e1(),r=cb(),n=1,o=2;function i(a,s,c,u,l,d){var h=c&n,p=a.length,g=s.length;if(p!=g&&!(h&&g>p))return!1;var m=d.get(a),y=d.get(s);if(m&&y)return m==s&&y==a;var v=-1,b=!0,w=c&o?new e:void 0;for(d.set(a,s),d.set(s,a);++v<p;){var x=a[v],C=s[v];if(u)var S=h?u(C,x,v,s,a,d):u(x,C,v,a,s,d);if(S!==void 0){if(S)continue;b=!1;break}if(w){if(!t(s,function(j,T){if(!r(w,T)&&(x===j||l(x,j,c,u,d)))return w.push(T)})){b=!1;break}}else if(!(x===C||l(x,C,c,u,d))){b=!1;break}}return d.delete(a),d.delete(s),b}return ma=i,ma}var ba,uh;function r1(){if(uh)return ba;uh=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o,i){n[++r]=[i,o]}),n}return ba=e,ba}var va,lh;function ol(){if(lh)return va;lh=1;function e(t){var r=-1,n=Array(t.size);return t.forEach(function(o){n[++r]=o}),n}return va=e,va}var xa,dh;function t1(){if(dh)return xa;dh=1;var e=jt(),t=Qm(),r=Et(),n=ub(),o=r1(),i=ol(),a=1,s=2,c="[object Boolean]",u="[object Date]",l="[object Error]",d="[object Map]",h="[object Number]",p="[object RegExp]",g="[object Set]",m="[object String]",y="[object Symbol]",v="[object ArrayBuffer]",b="[object DataView]",w=e?e.prototype:void 0,x=w?w.valueOf:void 0;function C(S,j,T,k,M,R,E){switch(T){case b:if(S.byteLength!=j.byteLength||S.byteOffset!=j.byteOffset)return!1;S=S.buffer,j=j.buffer;case v:return!(S.byteLength!=j.byteLength||!R(new t(S),new t(j)));case c:case u:case h:return r(+S,+j);case l:return S.name==j.name&&S.message==j.message;case p:case m:return S==j+"";case d:var P=o;case g:var I=k&a;if(P||(P=i),S.size!=j.size&&!I)return!1;var q=E.get(S);if(q)return q==j;k|=s,E.set(S,j);var O=n(P(S),P(j),k,M,R,E);return E.delete(S),O;case y:if(x)return x.call(S)==x.call(j)}return!1}return xa=C,xa}var wa,fh;function n1(){if(fh)return wa;fh=1;var e=Ym(),t=1,r=Object.prototype,n=r.hasOwnProperty;function o(i,a,s,c,u,l){var d=s&t,h=e(i),p=h.length,g=e(a),m=g.length;if(p!=m&&!d)return!1;for(var y=p;y--;){var v=h[y];if(!(d?v in a:n.call(a,v)))return!1}var b=l.get(i),w=l.get(a);if(b&&w)return b==a&&w==i;var x=!0;l.set(i,a),l.set(a,i);for(var C=d;++y<p;){v=h[y];var S=i[v],j=a[v];if(c)var T=d?c(j,S,v,a,i,l):c(S,j,v,i,a,l);if(!(T===void 0?S===j||u(S,j,s,c,l):T)){x=!1;break}C||(C=v=="constructor")}if(x&&!C){var k=i.constructor,M=a.constructor;k!=M&&"constructor"in i&&"constructor"in a&&!(typeof k=="function"&&k instanceof k&&typeof M=="function"&&M instanceof M)&&(x=!1)}return l.delete(i),l.delete(a),x}return wa=o,wa}var Ca,hh;function o1(){if(hh)return Ca;hh=1;var e=Mn(),t=ub(),r=t1(),n=n1(),o=kt(),i=rr(),a=Rt(),s=un(),c=1,u="[object Arguments]",l="[object Array]",d="[object Object]",h=Object.prototype,p=h.hasOwnProperty;function g(m,y,v,b,w,x){var C=i(m),S=i(y),j=C?l:o(m),T=S?l:o(y);j=j==u?d:j,T=T==u?d:T;var k=j==d,M=T==d,R=j==T;if(R&&a(m)){if(!a(y))return!1;C=!0,k=!1}if(R&&!k)return x||(x=new e),C||s(m)?t(m,y,v,b,w,x):r(m,y,j,v,b,w,x);if(!(v&c)){var E=k&&p.call(m,"__wrapped__"),P=M&&p.call(y,"__wrapped__");if(E||P){var I=E?m.value():m,q=P?y.value():y;return x||(x=new e),w(I,q,v,b,x)}}return R?(x||(x=new e),n(m,y,v,b,w,x)):!1}return Ca=g,Ca}var _a,ph;function lb(){if(ph)return _a;ph=1;var e=o1(),t=Tr();function r(n,o,i,a,s){return n===o?!0:n==null||o==null||!t(n)&&!t(o)?n!==n&&o!==o:e(n,o,i,a,r,s)}return _a=r,_a}var Sa,gh;function i1(){if(gh)return Sa;gh=1;var e=Mn(),t=lb(),r=1,n=2;function o(i,a,s,c){var u=s.length,l=u,d=!c;if(i==null)return!l;for(i=Object(i);u--;){var h=s[u];if(d&&h[2]?h[1]!==i[h[0]]:!(h[0]in i))return!1}for(;++u<l;){h=s[u];var p=h[0],g=i[p],m=h[1];if(d&&h[2]){if(g===void 0&&!(p in i))return!1}else{var y=new e;if(c)var v=c(g,m,p,i,a,y);if(!(v===void 0?t(m,g,r|n,c,y):v))return!1}}return!0}return Sa=o,Sa}var Ea,yh;function db(){if(yh)return Ea;yh=1;var e=_r();function t(r){return r===r&&!e(r)}return Ea=t,Ea}var ja,mh;function a1(){if(mh)return ja;mh=1;var e=db(),t=Kr();function r(n){for(var o=t(n),i=o.length;i--;){var a=o[i],s=n[a];o[i]=[a,s,e(s)]}return o}return ja=r,ja}var Ra,bh;function fb(){if(bh)return Ra;bh=1;function e(t,r){return function(n){return n==null?!1:n[t]===r&&(r!==void 0||t in Object(n))}}return Ra=e,Ra}var ka,vh;function s1(){if(vh)return ka;vh=1;var e=i1(),t=a1(),r=fb();function n(o){var i=t(o);return i.length==1&&i[0][2]?r(i[0][0],i[0][1]):function(a){return a===o||e(a,o,i)}}return ka=n,ka}var Pa,xh;function Pt(){if(xh)return Pa;xh=1;var e=it(),t=Tr(),r="[object Symbol]";function n(o){return typeof o=="symbol"||t(o)&&e(o)==r}return Pa=n,Pa}var Aa,wh;function il(){if(wh)return Aa;wh=1;var e=rr(),t=Pt(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,a){if(e(i))return!1;var s=typeof i;return s=="number"||s=="symbol"||s=="boolean"||i==null||t(i)?!0:n.test(i)||!r.test(i)||a!=null&&i in Object(a)}return Aa=o,Aa}var Ta,Ch;function c1(){if(Ch)return Ta;Ch=1;var e=Hu(),t="Expected a function";function r(n,o){if(typeof n!="function"||o!=null&&typeof o!="function")throw new TypeError(t);var i=function(){var a=arguments,s=o?o.apply(this,a):a[0],c=i.cache;if(c.has(s))return c.get(s);var u=n.apply(this,a);return i.cache=c.set(s,u)||c,u};return i.cache=new(r.Cache||e),i}return r.Cache=e,Ta=r,Ta}var Ia,_h;function u1(){if(_h)return Ia;_h=1;var e=c1(),t=500;function r(n){var o=e(n,function(a){return i.size===t&&i.clear(),a}),i=o.cache;return o}return Ia=r,Ia}var Oa,Sh;function l1(){if(Sh)return Oa;Sh=1;var e=u1(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,n=e(function(o){var i=[];return o.charCodeAt(0)===46&&i.push(""),o.replace(t,function(a,s,c,u){i.push(c?u.replace(r,"$1"):s||a)}),i});return Oa=n,Oa}var Ma,Eh;function Dn(){if(Eh)return Ma;Eh=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 Ma=e,Ma}var qa,jh;function d1(){if(jh)return qa;jh=1;var e=jt(),t=Dn(),r=rr(),n=Pt(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function a(s){if(typeof s=="string")return s;if(r(s))return t(s,a)+"";if(n(s))return i?i.call(s):"";var c=s+"";return c=="0"&&1/s==-1/0?"-0":c}return qa=a,qa}var Na,Rh;function hb(){if(Rh)return Na;Rh=1;var e=d1();function t(r){return r==null?"":e(r)}return Na=t,Na}var $a,kh;function Vn(){if(kh)return $a;kh=1;var e=rr(),t=il(),r=l1(),n=hb();function o(i,a){return e(i)?i:t(i,a)?[i]:r(n(i))}return $a=o,$a}var La,Ph;function ln(){if(Ph)return La;Ph=1;var e=Pt();function t(r){if(typeof r=="string"||e(r))return r;var n=r+"";return n=="0"&&1/r==-1/0?"-0":n}return La=t,La}var Fa,Ah;function Wn(){if(Ah)return Fa;Ah=1;var e=Vn(),t=ln();function r(n,o){o=e(o,n);for(var i=0,a=o.length;n!=null&&i<a;)n=n[t(o[i++])];return i&&i==a?n:void 0}return Fa=r,Fa}var Ba,Th;function f1(){if(Th)return Ba;Th=1;var e=Wn();function t(r,n,o){var i=r==null?void 0:e(r,n);return i===void 0?o:i}return Ba=t,Ba}var za,Ih;function h1(){if(Ih)return za;Ih=1;function e(t,r){return t!=null&&r in Object(t)}return za=e,za}var Da,Oh;function pb(){if(Oh)return Da;Oh=1;var e=Vn(),t=cn(),r=rr(),n=$n(),o=Ju(),i=ln();function a(s,c,u){c=e(c,s);for(var l=-1,d=c.length,h=!1;++l<d;){var p=i(c[l]);if(!(h=s!=null&&u(s,p)))break;s=s[p]}return h||++l!=d?h:(d=s==null?0:s.length,!!d&&o(d)&&n(p,d)&&(r(s)||t(s)))}return Da=a,Da}var Va,Mh;function gb(){if(Mh)return Va;Mh=1;var e=h1(),t=pb();function r(n,o){return n!=null&&t(n,o,e)}return Va=r,Va}var Wa,qh;function p1(){if(qh)return Wa;qh=1;var e=lb(),t=f1(),r=gb(),n=il(),o=db(),i=fb(),a=ln(),s=1,c=2;function u(l,d){return n(l)&&o(d)?i(a(l),d):function(h){var p=t(h,l);return p===void 0&&p===d?r(h,l):e(d,p,s|c)}}return Wa=u,Wa}var Ga,Nh;function yb(){if(Nh)return Ga;Nh=1;function e(t){return function(r){return r==null?void 0:r[t]}}return Ga=e,Ga}var Ua,$h;function g1(){if($h)return Ua;$h=1;var e=Wn();function t(r){return function(n){return e(n,r)}}return Ua=t,Ua}var Ha,Lh;function y1(){if(Lh)return Ha;Lh=1;var e=yb(),t=g1(),r=il(),n=ln();function o(i){return r(i)?e(n(i)):t(i)}return Ha=o,Ha}var Ka,Fh;function $r(){if(Fh)return Ka;Fh=1;var e=s1(),t=p1(),r=ct(),n=rr(),o=y1();function i(a){return typeof a=="function"?a:a==null?r:typeof a=="object"?n(a)?t(a[0],a[1]):e(a):o(a)}return Ka=i,Ka}var Ja,Bh;function mb(){if(Bh)return Ja;Bh=1;var e=Hm(),t=Yw(),r=$r(),n=rr();function o(i,a){var s=n(i)?e:t;return s(i,r(a,3))}return Ja=o,Ja}var Za,zh;function m1(){if(zh)return Za;zh=1;var e=Object.prototype,t=e.hasOwnProperty;function r(n,o){return n!=null&&t.call(n,o)}return Za=r,Za}var Ya,Dh;function bb(){if(Dh)return Ya;Dh=1;var e=m1(),t=pb();function r(n,o){return n!=null&&t(n,o,e)}return Ya=r,Ya}var Xa,Vh;function b1(){if(Vh)return Xa;Vh=1;var e=Yu(),t=kt(),r=cn(),n=rr(),o=Nr(),i=Rt(),a=Fn(),s=un(),c="[object Map]",u="[object Set]",l=Object.prototype,d=l.hasOwnProperty;function h(p){if(p==null)return!0;if(o(p)&&(n(p)||typeof p=="string"||typeof p.splice=="function"||i(p)||s(p)||r(p)))return!p.length;var g=t(p);if(g==c||g==u)return!p.size;if(a(p))return!e(p).length;for(var m in p)if(d.call(p,m))return!1;return!0}return Xa=h,Xa}var Qa,Wh;function vb(){if(Wh)return Qa;Wh=1;function e(t){return t===void 0}return Qa=e,Qa}var es,Gh;function xb(){if(Gh)return es;Gh=1;var e=zn(),t=Nr();function r(n,o){var i=-1,a=t(n)?Array(n.length):[];return e(n,function(s,c,u){a[++i]=o(s,c,u)}),a}return es=r,es}var rs,Uh;function wb(){if(Uh)return rs;Uh=1;var e=Dn(),t=$r(),r=xb(),n=rr();function o(i,a){var s=n(i)?e:r;return s(i,t(a,3))}return rs=o,rs}var ts,Hh;function v1(){if(Hh)return ts;Hh=1;function e(t,r,n,o){var i=-1,a=t==null?0:t.length;for(o&&a&&(n=t[++i]);++i<a;)n=r(n,t[i],i,t);return n}return ts=e,ts}var ns,Kh;function x1(){if(Kh)return ns;Kh=1;function e(t,r,n,o,i){return i(t,function(a,s,c){n=o?(o=!1,a):r(n,a,s,c)}),n}return ns=e,ns}var os,Jh;function Cb(){if(Jh)return os;Jh=1;var e=v1(),t=zn(),r=$r(),n=x1(),o=rr();function i(a,s,c){var u=o(a)?e:n,l=arguments.length<3;return u(a,r(s,4),c,l,t)}return os=i,os}var is,Zh;function w1(){if(Zh)return is;Zh=1;var e=it(),t=rr(),r=Tr(),n="[object String]";function o(i){return typeof i=="string"||!t(i)&&r(i)&&e(i)==n}return is=o,is}var as,Yh;function C1(){if(Yh)return as;Yh=1;var e=yb(),t=e("length");return as=t,as}var ss,Xh;function _1(){if(Xh)return ss;Xh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",a="\\u200d",s=RegExp("["+a+e+o+i+"]");function c(u){return s.test(u)}return ss=c,ss}var cs,Qh;function S1(){if(Qh)return cs;Qh=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=t+r+n,i="\\ufe0e\\ufe0f",a="["+e+"]",s="["+o+"]",c="\\ud83c[\\udffb-\\udfff]",u="(?:"+s+"|"+c+")",l="[^"+e+"]",d="(?:\\ud83c[\\udde6-\\uddff]){2}",h="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",g=u+"?",m="["+i+"]?",y="(?:"+p+"(?:"+[l,d,h].join("|")+")"+m+g+")*",v=m+g+y,b="(?:"+[l+s+"?",s,d,h,a].join("|")+")",w=RegExp(c+"(?="+c+")|"+b+v,"g");function x(C){for(var S=w.lastIndex=0;w.test(C);)++S;return S}return cs=x,cs}var us,ep;function E1(){if(ep)return us;ep=1;var e=C1(),t=_1(),r=S1();function n(o){return t(o)?r(o):e(o)}return us=n,us}var ls,rp;function j1(){if(rp)return ls;rp=1;var e=Yu(),t=kt(),r=Nr(),n=w1(),o=E1(),i="[object Map]",a="[object Set]";function s(c){if(c==null)return 0;if(r(c))return n(c)?o(c):c.length;var u=t(c);return u==i||u==a?c.size:e(c).length}return ls=s,ls}var ds,tp;function R1(){if(tp)return ds;tp=1;var e=Ku(),t=rb(),r=nl(),n=$r(),o=Bn(),i=rr(),a=Rt(),s=an(),c=_r(),u=un();function l(d,h,p){var g=i(d),m=g||a(d)||u(d);if(h=n(h,4),p==null){var y=d&&d.constructor;m?p=g?new y:[]:c(d)?p=s(y)?t(o(d)):{}:p={}}return(m?e:r)(d,function(v,b,w){return h(p,v,b,w)}),p}return ds=l,ds}var fs,np;function k1(){if(np)return fs;np=1;var e=jt(),t=cn(),r=rr(),n=e?e.isConcatSpreadable:void 0;function o(i){return r(i)||t(i)||!!(n&&i&&i[n])}return fs=o,fs}var hs,op;function al(){if(op)return hs;op=1;var e=Qu(),t=k1();function r(n,o,i,a,s){var c=-1,u=n.length;for(i||(i=t),s||(s=[]);++c<u;){var l=n[c];o>0&&i(l)?o>1?r(l,o-1,i,a,s):e(s,l):a||(s[s.length]=l)}return s}return hs=r,hs}var ps,ip;function P1(){if(ip)return ps;ip=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 ps=e,ps}var gs,ap;function _b(){if(ap)return gs;ap=1;var e=P1(),t=Math.max;function r(n,o,i){return o=t(o===void 0?n.length-1:o,0),function(){for(var a=arguments,s=-1,c=t(a.length-o,0),u=Array(c);++s<c;)u[s]=a[o+s];s=-1;for(var l=Array(o+1);++s<o;)l[s]=a[s];return l[o]=i(u),e(n,this,l)}}return gs=r,gs}var ys,sp;function A1(){if(sp)return ys;sp=1;var e=rl(),t=Dm(),r=ct(),n=t?function(o,i){return t(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:r;return ys=n,ys}var ms,cp;function T1(){if(cp)return ms;cp=1;var e=800,t=16,r=Date.now;function n(o){var i=0,a=0;return function(){var s=r(),c=t-(s-a);if(a=s,c>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return ms=n,ms}var bs,up;function Sb(){if(up)return bs;up=1;var e=A1(),t=T1(),r=t(e);return bs=r,bs}var vs,lp;function Gn(){if(lp)return vs;lp=1;var e=ct(),t=_b(),r=Sb();function n(o,i){return r(t(o,i,e),o+"")}return vs=n,vs}var xs,dp;function Eb(){if(dp)return xs;dp=1;function e(t,r,n,o){for(var i=t.length,a=n+(o?1:-1);o?a--:++a<i;)if(r(t[a],a,t))return a;return-1}return xs=e,xs}var ws,fp;function I1(){if(fp)return ws;fp=1;function e(t){return t!==t}return ws=e,ws}var Cs,hp;function O1(){if(hp)return Cs;hp=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 Cs=e,Cs}var _s,pp;function M1(){if(pp)return _s;pp=1;var e=Eb(),t=I1(),r=O1();function n(o,i,a){return i===i?r(o,i,a):e(o,t,a)}return _s=n,_s}var Ss,gp;function q1(){if(gp)return Ss;gp=1;var e=M1();function t(r,n){var o=r==null?0:r.length;return!!o&&e(r,n,0)>-1}return Ss=t,Ss}var Es,yp;function N1(){if(yp)return Es;yp=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 Es=e,Es}var js,mp;function $1(){if(mp)return js;mp=1;function e(){}return js=e,js}var Rs,bp;function L1(){if(bp)return Rs;bp=1;var e=Xm(),t=$1(),r=ol(),n=1/0,o=e&&1/r(new e([,-0]))[1]==n?function(i){return new e(i)}:t;return Rs=o,Rs}var ks,vp;function F1(){if(vp)return ks;vp=1;var e=sb(),t=q1(),r=N1(),n=cb(),o=L1(),i=ol(),a=200;function s(c,u,l){var d=-1,h=t,p=c.length,g=!0,m=[],y=m;if(l)g=!1,h=r;else if(p>=a){var v=u?null:o(c);if(v)return i(v);g=!1,h=n,y=new e}else y=u?[]:m;e:for(;++d<p;){var b=c[d],w=u?u(b):b;if(b=l||b!==0?b:0,g&&w===w){for(var x=y.length;x--;)if(y[x]===w)continue e;u&&y.push(w),m.push(b)}else h(y,w,l)||(y!==m&&y.push(w),m.push(b))}return m}return ks=s,ks}var Ps,xp;function jb(){if(xp)return Ps;xp=1;var e=Nr(),t=Tr();function r(n){return t(n)&&e(n)}return Ps=r,Ps}var As,wp;function B1(){if(wp)return As;wp=1;var e=al(),t=Gn(),r=F1(),n=jb(),o=t(function(i){return r(e(i,1,n,!0))});return As=o,As}var Ts,Cp;function z1(){if(Cp)return Ts;Cp=1;var e=Dn();function t(r,n){return e(n,function(o){return r[o]})}return Ts=t,Ts}var Is,_p;function Rb(){if(_p)return Is;_p=1;var e=z1(),t=Kr();function r(n){return n==null?[]:e(n,t(n))}return Is=r,Is}var Os,Sp;function Sr(){if(Sp)return Os;Sp=1;var e;if(typeof Gu=="function")try{e={clone:Kw(),constant:rl(),each:ab(),filter:mb(),has:bb(),isArray:rr(),isEmpty:b1(),isFunction:an(),isUndefined:vb(),keys:Kr(),map:wb(),reduce:Cb(),size:j1(),transform:R1(),union:B1(),values:Rb()}}catch{}return e||(e=window._),Os=e,Os}var Ms,Ep;function sl(){if(Ep)return Ms;Ep=1;var e=Sr();Ms=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 h=arguments,p=this;return e.each(l,function(g){h.length>1?p.setNode(g,d):p.setNode(g)}),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 h=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]),h),delete this._in[l],delete this._preds[l],e.each(e.keys(this._out[l]),h),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 h=d;!e.isUndefined(h);h=this.parent(h))if(h===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 h=this;e.each(this._nodes,function(m,y){l(y)&&d.setNode(y,m)}),e.each(this._edgeObjs,function(m){d.hasNode(m.v)&&d.hasNode(m.w)&&d.setEdge(m,h.edge(m))});var p={};function g(m){var y=h.parent(m);return y===void 0||d.hasNode(y)?(p[m]=y,y):y in p?p[y]:g(y)}return this._isCompound&&e.each(d.nodes(),function(m){d.setParent(m,g(m))}),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 h=this,p=arguments;return e.reduce(l,function(g,m){return p.length>1?h.setEdge(g,m,d):h.setEdge(g,m),m}),this},o.prototype.setEdge=function(){var l,d,h,p,g=!1,m=arguments[0];typeof m=="object"&&m!==null&&"v"in m?(l=m.v,d=m.w,h=m.name,arguments.length===2&&(p=arguments[1],g=!0)):(l=m,d=arguments[1],h=arguments[3],arguments.length>2&&(p=arguments[2],g=!0)),l=""+l,d=""+d,e.isUndefined(h)||(h=""+h);var y=s(this._isDirected,l,d,h);if(e.has(this._edgeLabels,y))return g&&(this._edgeLabels[y]=p),this;if(!e.isUndefined(h)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(l),this.setNode(d),this._edgeLabels[y]=g?p:this._defaultEdgeLabelFn(l,d,h);var v=c(this._isDirected,l,d,h);return l=v.v,d=v.w,Object.freeze(v),this._edgeObjs[y]=v,i(this._preds[d],l),i(this._sucs[l],d),this._in[d][y]=v,this._out[l][y]=v,this._edgeCount++,this},o.prototype.edge=function(l,d,h){var p=arguments.length===1?u(this._isDirected,arguments[0]):s(this._isDirected,l,d,h);return this._edgeLabels[p]},o.prototype.hasEdge=function(l,d,h){var p=arguments.length===1?u(this._isDirected,arguments[0]):s(this._isDirected,l,d,h);return e.has(this._edgeLabels,p)},o.prototype.removeEdge=function(l,d,h){var p=arguments.length===1?u(this._isDirected,arguments[0]):s(this._isDirected,l,d,h),g=this._edgeObjs[p];return g&&(l=g.v,d=g.w,delete this._edgeLabels[p],delete this._edgeObjs[p],a(this._preds[d],l),a(this._sucs[l],d),delete this._in[d][p],delete this._out[l][p],this._edgeCount--),this},o.prototype.inEdges=function(l,d){var h=this._in[l];if(h){var p=e.values(h);return d?e.filter(p,function(g){return g.v===d}):p}},o.prototype.outEdges=function(l,d){var h=this._out[l];if(h){var p=e.values(h);return d?e.filter(p,function(g){return g.w===d}):p}},o.prototype.nodeEdges=function(l,d){var h=this.inEdges(l,d);if(h)return h.concat(this.outEdges(l,d))};function i(l,d){l[d]?l[d]++:l[d]=1}function a(l,d){--l[d]||delete l[d]}function s(l,d,h,p){var g=""+d,m=""+h;if(!l&&g>m){var y=g;g=m,m=y}return g+n+m+n+(e.isUndefined(p)?t:p)}function c(l,d,h,p){var g=""+d,m=""+h;if(!l&&g>m){var y=g;g=m,m=y}var v={v:g,w:m};return p&&(v.name=p),v}function u(l,d){return s(l,d.v,d.w,d.name)}return Ms}var qs,jp;function D1(){return jp||(jp=1,qs="2.1.8"),qs}var Ns,Rp;function V1(){return Rp||(Rp=1,Ns={Graph:sl(),version:D1()}),Ns}var $s,kp;function W1(){if(kp)return $s;kp=1;var e=Sr(),t=sl();$s={write:r,read:i};function r(a){var s={options:{directed:a.isDirected(),multigraph:a.isMultigraph(),compound:a.isCompound()},nodes:n(a),edges:o(a)};return e.isUndefined(a.graph())||(s.value=e.clone(a.graph())),s}function n(a){return e.map(a.nodes(),function(s){var c=a.node(s),u=a.parent(s),l={v:s};return e.isUndefined(c)||(l.value=c),e.isUndefined(u)||(l.parent=u),l})}function o(a){return e.map(a.edges(),function(s){var c=a.edge(s),u={v:s.v,w:s.w};return e.isUndefined(s.name)||(u.name=s.name),e.isUndefined(c)||(u.value=c),u})}function i(a){var s=new t(a.options).setGraph(a.value);return e.each(a.nodes,function(c){s.setNode(c.v,c.value),c.parent&&s.setParent(c.v,c.parent)}),e.each(a.edges,function(c){s.setEdge({v:c.v,w:c.w,name:c.name},c.value)}),s}return $s}var Ls,Pp;function G1(){if(Pp)return Ls;Pp=1;var e=Sr();Ls=t;function t(r){var n={},o=[],i;function a(s){e.has(n,s)||(n[s]=!0,i.push(s),e.each(r.successors(s),a),e.each(r.predecessors(s),a))}return e.each(r.nodes(),function(s){i=[],a(s),i.length&&o.push(i)}),o}return Ls}var Fs,Ap;function kb(){if(Ap)return Fs;Ap=1;var e=Sr();Fs=t;function t(){this._arr=[],this._keyIndices={}}return t.prototype.size=function(){return this._arr.length},t.prototype.keys=function(){return this._arr.map(function(r){return r.key})},t.prototype.has=function(r){return e.has(this._keyIndices,r)},t.prototype.priority=function(r){var n=this._keyIndices[r];if(n!==void 0)return this._arr[n].priority},t.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},t.prototype.add=function(r,n){var o=this._keyIndices;if(r=String(r),!e.has(o,r)){var i=this._arr,a=i.length;return o[r]=a,i.push({key:r,priority:n}),this._decrease(a),!0}return!1},t.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var r=this._arr.pop();return delete this._keyIndices[r.key],this._heapify(0),r.key},t.prototype.decrease=function(r,n){var o=this._keyIndices[r];if(n>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+r+" Old: "+this._arr[o].priority+" New: "+n);this._arr[o].priority=n,this._decrease(o)},t.prototype._heapify=function(r){var n=this._arr,o=2*r,i=o+1,a=r;o<n.length&&(a=n[o].priority<n[a].priority?o:a,i<n.length&&(a=n[i].priority<n[a].priority?i:a),a!==r&&(this._swap(r,a),this._heapify(a)))},t.prototype._decrease=function(r){for(var n=this._arr,o=n[r].priority,i;r!==0&&(i=r>>1,!(n[i].priority<o));)this._swap(r,i),r=i},t.prototype._swap=function(r,n){var o=this._arr,i=this._keyIndices,a=o[r],s=o[n];o[r]=s,o[n]=a,i[s.key]=r,i[a.key]=n},Fs}var Bs,Tp;function Pb(){if(Tp)return Bs;Tp=1;var e=Sr(),t=kb();Bs=n;var r=e.constant(1);function n(i,a,s,c){return o(i,String(a),s||r,c||function(u){return i.outEdges(u)})}function o(i,a,s,c){var u={},l=new t,d,h,p=function(g){var m=g.v!==d?g.v:g.w,y=u[m],v=s(g),b=h.distance+v;if(v<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+g+" Weight: "+v);b<y.distance&&(y.distance=b,y.predecessor=d,l.decrease(m,b))};for(i.nodes().forEach(function(g){var m=g===a?0:Number.POSITIVE_INFINITY;u[g]={distance:m},l.add(g,m)});l.size()>0&&(d=l.removeMin(),h=u[d],h.distance!==Number.POSITIVE_INFINITY);)c(d).forEach(p);return u}return Bs}var zs,Ip;function U1(){if(Ip)return zs;Ip=1;var e=Pb(),t=Sr();zs=r;function r(n,o,i){return t.transform(n.nodes(),function(a,s){a[s]=e(n,s,o,i)},{})}return zs}var Ds,Op;function Ab(){if(Op)return Ds;Op=1;var e=Sr();Ds=t;function t(r){var n=0,o=[],i={},a=[];function s(c){var u=i[c]={onStack:!0,lowlink:n,index:n++};if(o.push(c),r.successors(c).forEach(function(h){e.has(i,h)?i[h].onStack&&(u.lowlink=Math.min(u.lowlink,i[h].index)):(s(h),u.lowlink=Math.min(u.lowlink,i[h].lowlink))}),u.lowlink===u.index){var l=[],d;do d=o.pop(),i[d].onStack=!1,l.push(d);while(c!==d);a.push(l)}}return r.nodes().forEach(function(c){e.has(i,c)||s(c)}),a}return Ds}var Vs,Mp;function H1(){if(Mp)return Vs;Mp=1;var e=Sr(),t=Ab();Vs=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 Vs}var Ws,qp;function K1(){if(qp)return Ws;qp=1;var e=Sr();Ws=r;var t=e.constant(1);function r(o,i,a){return n(o,i||t,a||function(s){return o.outEdges(s)})}function n(o,i,a){var s={},c=o.nodes();return c.forEach(function(u){s[u]={},s[u][u]={distance:0},c.forEach(function(l){u!==l&&(s[u][l]={distance:Number.POSITIVE_INFINITY})}),a(u).forEach(function(l){var d=l.v===u?l.w:l.v,h=i(l);s[u][d]={distance:h,predecessor:u}})}),c.forEach(function(u){var l=s[u];c.forEach(function(d){var h=s[d];c.forEach(function(p){var g=h[u],m=l[p],y=h[p],v=g.distance+m.distance;v<y.distance&&(y.distance=v,y.predecessor=m.predecessor)})})}),s}return Ws}var Gs,Np;function Tb(){if(Np)return Gs;Np=1;var e=Sr();Gs=t,t.CycleException=r;function t(n){var o={},i={},a=[];function s(c){if(e.has(i,c))throw new r;e.has(o,c)||(i[c]=!0,o[c]=!0,e.each(n.predecessors(c),s),delete i[c],a.push(c))}if(e.each(n.sinks(),s),e.size(o)!==n.nodeCount())throw new r;return a}function r(){}return r.prototype=new Error,Gs}var Us,$p;function J1(){if($p)return Us;$p=1;var e=Tb();Us=t;function t(r){try{e(r)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Us}var Hs,Lp;function Ib(){if(Lp)return Hs;Lp=1;var e=Sr();Hs=t;function t(n,o,i){e.isArray(o)||(o=[o]);var a=(n.isDirected()?n.successors:n.neighbors).bind(n),s=[],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,a,s)}),s}function r(n,o,i,a,s,c){e.has(a,o)||(a[o]=!0,i||c.push(o),e.each(s(o),function(u){r(n,u,i,a,s,c)}),i&&c.push(o))}return Hs}var Ks,Fp;function Z1(){if(Fp)return Ks;Fp=1;var e=Ib();Ks=t;function t(r,n){return e(r,n,"post")}return Ks}var Js,Bp;function Y1(){if(Bp)return Js;Bp=1;var e=Ib();Js=t;function t(r,n){return e(r,n,"pre")}return Js}var Zs,zp;function X1(){if(zp)return Zs;zp=1;var e=Sr(),t=sl(),r=kb();Zs=n;function n(o,i){var a=new t,s={},c=new r,u;function l(h){var p=h.v===u?h.w:h.v,g=c.priority(p);if(g!==void 0){var m=i(h);m<g&&(s[p]=u,c.decrease(p,m))}}if(o.nodeCount()===0)return a;e.each(o.nodes(),function(h){c.add(h,Number.POSITIVE_INFINITY),a.setNode(h)}),c.decrease(o.nodes()[0],0);for(var d=!1;c.size()>0;){if(u=c.removeMin(),e.has(s,u))a.setEdge(u,s[u]);else{if(d)throw new Error("Input graph is not connected: "+o);d=!0}o.nodeEdges(u).forEach(l)}return a}return Zs}var Ys,Dp;function Q1(){return Dp||(Dp=1,Ys={components:G1(),dijkstra:Pb(),dijkstraAll:U1(),findCycles:H1(),floydWarshall:K1(),isAcyclic:J1(),postorder:Z1(),preorder:Y1(),prim:X1(),tarjan:Ab(),topsort:Tb()}),Ys}var Xs,Vp;function eC(){if(Vp)return Xs;Vp=1;var e=V1();return Xs={Graph:e.Graph,json:W1(),alg:Q1(),version:e.version},Xs}var Qs,Wp;function Rr(){if(Wp)return Qs;Wp=1;var e;if(typeof Gu=="function")try{e=eC()}catch{}return e||(e=window.graphlib),Qs=e,Qs}var ec,Gp;function rC(){if(Gp)return ec;Gp=1;var e=nb(),t=1,r=4;function n(o){return e(o,t|r)}return ec=n,ec}var rc,Up;function Un(){if(Up)return rc;Up=1;var e=Et(),t=Nr(),r=$n(),n=_r();function o(i,a,s){if(!n(s))return!1;var c=typeof a;return(c=="number"?t(s)&&r(a,s.length):c=="string"&&a in s)?e(s[a],i):!1}return rc=o,rc}var tc,Hp;function tC(){if(Hp)return tc;Hp=1;var e=Gn(),t=Et(),r=Un(),n=st(),o=Object.prototype,i=o.hasOwnProperty,a=e(function(s,c){s=Object(s);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 h=c[u],p=n(h),g=-1,m=p.length;++g<m;){var y=p[g],v=s[y];(v===void 0||t(v,o[y])&&!i.call(s,y))&&(s[y]=h[y])}return s});return tc=a,tc}var nc,Kp;function nC(){if(Kp)return nc;Kp=1;var e=$r(),t=Nr(),r=Kr();function n(o){return function(i,a,s){var c=Object(i);if(!t(i)){var u=e(a,3);i=r(i),a=function(d){return u(c[d],d,c)}}var l=o(i,a,s);return l>-1?c[u?i[l]:l]:void 0}}return nc=n,nc}var oc,Jp;function oC(){if(Jp)return oc;Jp=1;var e=/\s/;function t(r){for(var n=r.length;n--&&e.test(r.charAt(n)););return n}return oc=t,oc}var ic,Zp;function iC(){if(Zp)return ic;Zp=1;var e=oC(),t=/^\s+/;function r(n){return n&&n.slice(0,e(n)+1).replace(t,"")}return ic=r,ic}var ac,Yp;function aC(){if(Yp)return ac;Yp=1;var e=iC(),t=_r(),r=Pt(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,a=/^0o[0-7]+$/i,s=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||a.test(u)?s(u.slice(2),d?2:8):o.test(u)?n:+u}return ac=c,ac}var sc,Xp;function Ob(){if(Xp)return sc;Xp=1;var e=aC(),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 sc=n,sc}var cc,Qp;function sC(){if(Qp)return cc;Qp=1;var e=Ob();function t(r){var n=e(r),o=n%1;return n===n?o?n-o:n:0}return cc=t,cc}var uc,eg;function cC(){if(eg)return uc;eg=1;var e=Eb(),t=$r(),r=sC(),n=Math.max;function o(i,a,s){var c=i==null?0:i.length;if(!c)return-1;var u=s==null?0:r(s);return u<0&&(u=n(c+u,0)),e(i,t(a,3),u)}return uc=o,uc}var lc,rg;function uC(){if(rg)return lc;rg=1;var e=nC(),t=cC(),r=e(t);return lc=r,lc}var dc,tg;function Mb(){if(tg)return dc;tg=1;var e=al();function t(r){var n=r==null?0:r.length;return n?e(r,1):[]}return dc=t,dc}var fc,ng;function lC(){if(ng)return fc;ng=1;var e=tl(),t=ob(),r=st();function n(o,i){return o==null?o:e(o,t(i),r)}return fc=n,fc}var hc,og;function dC(){if(og)return hc;og=1;function e(t){var r=t==null?0:t.length;return r?t[r-1]:void 0}return hc=e,hc}var pc,ig;function fC(){if(ig)return pc;ig=1;var e=qn(),t=nl(),r=$r();function n(o,i){var a={};return i=r(i,3),t(o,function(s,c,u){e(a,c,i(s,c,u))}),a}return pc=n,pc}var gc,ag;function cl(){if(ag)return gc;ag=1;var e=Pt();function t(r,n,o){for(var i=-1,a=r.length;++i<a;){var s=r[i],c=n(s);if(c!=null&&(u===void 0?c===c&&!e(c):o(c,u)))var u=c,l=s}return l}return gc=t,gc}var yc,sg;function hC(){if(sg)return yc;sg=1;function e(t,r){return t>r}return yc=e,yc}var mc,cg;function pC(){if(cg)return mc;cg=1;var e=cl(),t=hC(),r=ct();function n(o){return o&&o.length?e(o,r,t):void 0}return mc=n,mc}var bc,ug;function qb(){if(ug)return bc;ug=1;var e=qn(),t=Et();function r(n,o,i){(i!==void 0&&!t(n[o],i)||i===void 0&&!(o in n))&&e(n,o,i)}return bc=r,bc}var vc,lg;function gC(){if(lg)return vc;lg=1;var e=it(),t=Bn(),r=Tr(),n="[object Object]",o=Function.prototype,i=Object.prototype,a=o.toString,s=i.hasOwnProperty,c=a.call(Object);function u(l){if(!r(l)||e(l)!=n)return!1;var d=t(l);if(d===null)return!0;var h=s.call(d,"constructor")&&d.constructor;return typeof h=="function"&&h instanceof h&&a.call(h)==c}return vc=u,vc}var xc,dg;function Nb(){if(dg)return xc;dg=1;function e(t,r){if(!(r==="constructor"&&typeof t[r]=="function")&&r!="__proto__")return t[r]}return xc=e,xc}var wc,fg;function yC(){if(fg)return wc;fg=1;var e=sn(),t=st();function r(n){return e(n,t(n))}return wc=r,wc}var Cc,hg;function mC(){if(hg)return Cc;hg=1;var e=qb(),t=Gm(),r=eb(),n=Um(),o=tb(),i=cn(),a=rr(),s=jb(),c=Rt(),u=an(),l=_r(),d=gC(),h=un(),p=Nb(),g=yC();function m(y,v,b,w,x,C,S){var j=p(y,b),T=p(v,b),k=S.get(T);if(k){e(y,b,k);return}var M=C?C(j,T,b+"",y,v,S):void 0,R=M===void 0;if(R){var E=a(T),P=!E&&c(T),I=!E&&!P&&h(T);M=T,E||P||I?a(j)?M=j:s(j)?M=n(j):P?(R=!1,M=t(T,!0)):I?(R=!1,M=r(T,!0)):M=[]:d(T)||i(T)?(M=j,i(j)?M=g(j):(!l(j)||u(j))&&(M=o(T))):R=!1}R&&(S.set(T,M),x(M,T,w,C,S),S.delete(T)),e(y,b,M)}return Cc=m,Cc}var _c,pg;function bC(){if(pg)return _c;pg=1;var e=Mn(),t=qb(),r=tl(),n=mC(),o=_r(),i=st(),a=Nb();function s(c,u,l,d,h){c!==u&&r(u,function(p,g){if(h||(h=new e),o(p))n(c,u,g,l,s,d,h);else{var m=d?d(a(c,g),p,g+"",c,u,h):void 0;m===void 0&&(m=p),t(c,g,m)}},i)}return _c=s,_c}var Sc,gg;function vC(){if(gg)return Sc;gg=1;var e=Gn(),t=Un();function r(n){return e(function(o,i){var a=-1,s=i.length,c=s>1?i[s-1]:void 0,u=s>2?i[2]:void 0;for(c=n.length>3&&typeof c=="function"?(s--,c):void 0,u&&t(i[0],i[1],u)&&(c=s<3?void 0:c,s=1),o=Object(o);++a<s;){var l=i[a];l&&n(o,l,a,c)}return o})}return Sc=r,Sc}var Ec,yg;function xC(){if(yg)return Ec;yg=1;var e=bC(),t=vC(),r=t(function(n,o,i){e(n,o,i)});return Ec=r,Ec}var jc,mg;function $b(){if(mg)return jc;mg=1;function e(t,r){return t<r}return jc=e,jc}var Rc,bg;function wC(){if(bg)return Rc;bg=1;var e=cl(),t=$b(),r=ct();function n(o){return o&&o.length?e(o,r,t):void 0}return Rc=n,Rc}var kc,vg;function CC(){if(vg)return kc;vg=1;var e=cl(),t=$r(),r=$b();function n(o,i){return o&&o.length?e(o,t(i,2),r):void 0}return kc=n,kc}var Pc,xg;function _C(){if(xg)return Pc;xg=1;var e=kr(),t=function(){return e.Date.now()};return Pc=t,Pc}var Ac,wg;function SC(){if(wg)return Ac;wg=1;var e=Nn(),t=Vn(),r=$n(),n=_r(),o=ln();function i(a,s,c,u){if(!n(a))return a;s=t(s,a);for(var l=-1,d=s.length,h=d-1,p=a;p!=null&&++l<d;){var g=o(s[l]),m=c;if(g==="__proto__"||g==="constructor"||g==="prototype")return a;if(l!=h){var y=p[g];m=u?u(y,g,p):void 0,m===void 0&&(m=n(y)?y:r(s[l+1])?[]:{})}e(p,g,m),p=p[g]}return a}return Ac=i,Ac}var Tc,Cg;function EC(){if(Cg)return Tc;Cg=1;var e=Wn(),t=SC(),r=Vn();function n(o,i,a){for(var s=-1,c=i.length,u={};++s<c;){var l=i[s],d=e(o,l);a(d,l)&&t(u,r(l,o),d)}return u}return Tc=n,Tc}var Ic,_g;function jC(){if(_g)return Ic;_g=1;var e=EC(),t=gb();function r(n,o){return e(n,o,function(i,a){return t(n,a)})}return Ic=r,Ic}var Oc,Sg;function RC(){if(Sg)return Oc;Sg=1;var e=Mb(),t=_b(),r=Sb();function n(o){return r(t(o,void 0,e),o+"")}return Oc=n,Oc}var Mc,Eg;function kC(){if(Eg)return Mc;Eg=1;var e=jC(),t=RC(),r=t(function(n,o){return n==null?{}:e(n,o)});return Mc=r,Mc}var qc,jg;function PC(){if(jg)return qc;jg=1;var e=Math.ceil,t=Math.max;function r(n,o,i,a){for(var s=-1,c=t(e((o-n)/(i||1)),0),u=Array(c);c--;)u[a?c:++s]=n,n+=i;return u}return qc=r,qc}var Nc,Rg;function AC(){if(Rg)return Nc;Rg=1;var e=PC(),t=Un(),r=Ob();function n(o){return function(i,a,s){return s&&typeof s!="number"&&t(i,a,s)&&(a=s=void 0),i=r(i),a===void 0?(a=i,i=0):a=r(a),s=s===void 0?i<a?1:-1:r(s),e(i,a,s,o)}}return Nc=n,Nc}var $c,kg;function TC(){if(kg)return $c;kg=1;var e=AC(),t=e();return $c=t,$c}var Lc,Pg;function IC(){if(Pg)return Lc;Pg=1;function e(t,r){var n=t.length;for(t.sort(r);n--;)t[n]=t[n].value;return t}return Lc=e,Lc}var Fc,Ag;function OC(){if(Ag)return Fc;Ag=1;var e=Pt();function t(r,n){if(r!==n){var o=r!==void 0,i=r===null,a=r===r,s=e(r),c=n!==void 0,u=n===null,l=n===n,d=e(n);if(!u&&!d&&!s&&r>n||s&&c&&l&&!u&&!d||i&&c&&l||!o&&l||!a)return 1;if(!i&&!s&&!d&&r<n||d&&o&&a&&!i&&!s||u&&o&&a||!c&&a||!l)return-1}return 0}return Fc=t,Fc}var Bc,Tg;function MC(){if(Tg)return Bc;Tg=1;var e=OC();function t(r,n,o){for(var i=-1,a=r.criteria,s=n.criteria,c=a.length,u=o.length;++i<c;){var l=e(a[i],s[i]);if(l){if(i>=u)return l;var d=o[i];return l*(d=="desc"?-1:1)}}return r.index-n.index}return Bc=t,Bc}var zc,Ig;function qC(){if(Ig)return zc;Ig=1;var e=Dn(),t=Wn(),r=$r(),n=xb(),o=IC(),i=Ln(),a=MC(),s=ct(),c=rr();function u(l,d,h){d.length?d=e(d,function(m){return c(m)?function(y){return t(y,m.length===1?m[0]:m)}:m}):d=[s];var p=-1;d=e(d,i(r));var g=n(l,function(m,y,v){var b=e(d,function(w){return w(m)});return{criteria:b,index:++p,value:m}});return o(g,function(m,y){return a(m,y,h)})}return zc=u,zc}var Dc,Og;function NC(){if(Og)return Dc;Og=1;var e=al(),t=qC(),r=Gn(),n=Un(),o=r(function(i,a){if(i==null)return[];var s=a.length;return s>1&&n(i,a[0],a[1])?a=[]:s>2&&n(a[0],a[1],a[2])&&(a=[a[0]]),t(i,e(a,1),[])});return Dc=o,Dc}var Vc,Mg;function $C(){if(Mg)return Vc;Mg=1;var e=hb(),t=0;function r(n){var o=++t;return e(n)+o}return Vc=r,Vc}var Wc,qg;function LC(){if(qg)return Wc;qg=1;function e(t,r,n){for(var o=-1,i=t.length,a=r.length,s={};++o<i;){var c=o<a?r[o]:void 0;n(s,t[o],c)}return s}return Wc=e,Wc}var Gc,Ng;function FC(){if(Ng)return Gc;Ng=1;var e=Nn(),t=LC();function r(n,o){return t(n||[],o||[],e)}return Gc=r,Gc}var Uc,$g;function Je(){if($g)return Uc;$g=1;var e;if(typeof Gu=="function")try{e={cloneDeep:rC(),constant:rl(),defaults:tC(),each:ab(),filter:mb(),find:uC(),flatten:Mb(),forEach:ib(),forIn:lC(),has:bb(),isUndefined:vb(),last:dC(),map:wb(),mapValues:fC(),max:pC(),merge:xC(),min:wC(),minBy:CC(),now:_C(),pick:kC(),range:TC(),reduce:Cb(),sortBy:NC(),uniqueId:$C(),values:Rb(),zipObject:FC()}}catch{}return e||(e=window._),Uc=e,Uc}var Hc,Lg;function BC(){if(Lg)return Hc;Lg=1,Hc=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 Hc}var Kc,Fg;function zC(){if(Fg)return Kc;Fg=1;var e=Je(),t=Rr().Graph,r=BC();Kc=o;var n=e.constant(1);function o(u,l){if(u.nodeCount()<=1)return[];var d=s(u,l||n),h=i(d.graph,d.buckets,d.zeroIdx);return e.flatten(e.map(h,function(p){return u.outEdges(p.v,p.w)}),!0)}function i(u,l,d){for(var h=[],p=l[l.length-1],g=l[0],m;u.nodeCount();){for(;m=g.dequeue();)a(u,l,d,m);for(;m=p.dequeue();)a(u,l,d,m);if(u.nodeCount()){for(var y=l.length-2;y>0;--y)if(m=l[y].dequeue(),m){h=h.concat(a(u,l,d,m,!0));break}}}return h}function a(u,l,d,h,p){var g=p?[]:void 0;return e.forEach(u.inEdges(h.v),function(m){var y=u.edge(m),v=u.node(m.v);p&&g.push({v:m.v,w:m.w}),v.out-=y,c(l,d,v)}),e.forEach(u.outEdges(h.v),function(m){var y=u.edge(m),v=m.w,b=u.node(v);b.in-=y,c(l,d,b)}),u.removeNode(h.v),g}function s(u,l){var d=new t,h=0,p=0;e.forEach(u.nodes(),function(y){d.setNode(y,{v:y,in:0,out:0})}),e.forEach(u.edges(),function(y){var v=d.edge(y.v,y.w)||0,b=l(y),w=v+b;d.setEdge(y.v,y.w,w),p=Math.max(p,d.node(y.v).out+=b),h=Math.max(h,d.node(y.w).in+=b)});var g=e.range(p+h+3).map(function(){return new r}),m=h+1;return e.forEach(d.nodes(),function(y){c(g,m,d.node(y))}),{graph:d,buckets:g,zeroIdx:m}}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 Kc}var Jc,Bg;function DC(){if(Bg)return Jc;Bg=1;var e=Je(),t=zC();Jc={run:r,undo:o};function r(i){var a=i.graph().acyclicer==="greedy"?t(i,s(i)):n(i);e.forEach(a,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 s(c){return function(u){return c.edge(u).weight}}}function n(i){var a=[],s={},c={};function u(l){e.has(c,l)||(c[l]=!0,s[l]=!0,e.forEach(i.outEdges(l),function(d){e.has(s,d.w)?a.push(d):u(d.w)}),delete s[l])}return e.forEach(i.nodes(),u),a}function o(i){e.forEach(i.edges(),function(a){var s=i.edge(a);if(s.reversed){i.removeEdge(a);var c=s.forwardName;delete s.reversed,delete s.forwardName,i.setEdge(a.w,a.v,s,c)}})}return Jc}var Zc,zg;function gr(){if(zg)return Zc;zg=1;var e=Je(),t=Rr().Graph;Zc={addDummyNode:r,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:a,intersectRect:s,buildLayerMatrix:c,normalizeRanks:u,removeEmptyRanks:l,addBorderNode:d,maxRank:h,partition:p,time:g,notime:m};function r(y,v,b,w){var x;do x=e.uniqueId(w);while(y.hasNode(x));return b.dummy=v,y.setNode(x,b),x}function n(y){var v=new t().setGraph(y.graph());return e.forEach(y.nodes(),function(b){v.setNode(b,y.node(b))}),e.forEach(y.edges(),function(b){var w=v.edge(b.v,b.w)||{weight:0,minlen:1},x=y.edge(b);v.setEdge(b.v,b.w,{weight:w.weight+x.weight,minlen:Math.max(w.minlen,x.minlen)})}),v}function o(y){var v=new t({multigraph:y.isMultigraph()}).setGraph(y.graph());return e.forEach(y.nodes(),function(b){y.children(b).length||v.setNode(b,y.node(b))}),e.forEach(y.edges(),function(b){v.setEdge(b,y.edge(b))}),v}function i(y){var v=e.map(y.nodes(),function(b){var w={};return e.forEach(y.outEdges(b),function(x){w[x.w]=(w[x.w]||0)+y.edge(x).weight}),w});return e.zipObject(y.nodes(),v)}function a(y){var v=e.map(y.nodes(),function(b){var w={};return e.forEach(y.inEdges(b),function(x){w[x.v]=(w[x.v]||0)+y.edge(x).weight}),w});return e.zipObject(y.nodes(),v)}function s(y,v){var b=y.x,w=y.y,x=v.x-b,C=v.y-w,S=y.width/2,j=y.height/2;if(!x&&!C)throw new Error("Not possible to find intersection inside of the rectangle");var T,k;return Math.abs(C)*S>Math.abs(x)*j?(C<0&&(j=-j),T=j*x/C,k=j):(x<0&&(S=-S),T=S,k=S*C/x),{x:b+T,y:w+k}}function c(y){var v=e.map(e.range(h(y)+1),function(){return[]});return e.forEach(y.nodes(),function(b){var w=y.node(b),x=w.rank;e.isUndefined(x)||(v[x][w.order]=b)}),v}function u(y){var v=e.min(e.map(y.nodes(),function(b){return y.node(b).rank}));e.forEach(y.nodes(),function(b){var w=y.node(b);e.has(w,"rank")&&(w.rank-=v)})}function l(y){var v=e.min(e.map(y.nodes(),function(C){return y.node(C).rank})),b=[];e.forEach(y.nodes(),function(C){var S=y.node(C).rank-v;b[S]||(b[S]=[]),b[S].push(C)});var w=0,x=y.graph().nodeRankFactor;e.forEach(b,function(C,S){e.isUndefined(C)&&S%x!==0?--w:w&&e.forEach(C,function(j){y.node(j).rank+=w})})}function d(y,v,b,w){var x={width:0,height:0};return arguments.length>=4&&(x.rank=b,x.order=w),r(y,"border",x,v)}function h(y){return e.max(e.map(y.nodes(),function(v){var b=y.node(v).rank;if(!e.isUndefined(b))return b}))}function p(y,v){var b={lhs:[],rhs:[]};return e.forEach(y,function(w){v(w)?b.lhs.push(w):b.rhs.push(w)}),b}function g(y,v){var b=e.now();try{return v()}finally{console.log(y+" time: "+(e.now()-b)+"ms")}}function m(y,v){return v()}return Zc}var Yc,Dg;function VC(){if(Dg)return Yc;Dg=1;var e=Je(),t=gr();Yc={run:r,undo:o};function r(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(a){n(i,a)})}function n(i,a){var s=a.v,c=i.node(s).rank,u=a.w,l=i.node(u).rank,d=a.name,h=i.edge(a),p=h.labelRank;if(l!==c+1){i.removeEdge(a);var g,m,y;for(y=0,++c;c<l;++y,++c)h.points=[],m={width:0,height:0,edgeLabel:h,edgeObj:a,rank:c},g=t.addDummyNode(i,"edge",m,"_d"),c===p&&(m.width=h.width,m.height=h.height,m.dummy="edge-label",m.labelpos=h.labelpos),i.setEdge(s,g,{weight:h.weight},d),y===0&&i.graph().dummyChains.push(g),s=g;i.setEdge(s,u,{weight:h.weight},d)}}function o(i){e.forEach(i.graph().dummyChains,function(a){var s=i.node(a),c=s.edgeLabel,u;for(i.setEdge(s.edgeObj,c);s.dummy;)u=i.successors(a)[0],i.removeNode(a),c.points.push({x:s.x,y:s.y}),s.dummy==="edge-label"&&(c.x=s.x,c.y=s.y,c.width=s.width,c.height=s.height),a=u,s=i.node(a)})}return Yc}var Xc,Vg;function wn(){if(Vg)return Xc;Vg=1;var e=Je();Xc={longestPath:t,slack:r};function t(n){var o={};function i(a){var s=n.node(a);if(e.has(o,a))return s.rank;o[a]=!0;var c=e.min(e.map(n.outEdges(a),function(u){return i(u.w)-n.edge(u).minlen}));return(c===Number.POSITIVE_INFINITY||c===void 0||c===null)&&(c=0),s.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 Xc}var Qc,Wg;function Lb(){if(Wg)return Qc;Wg=1;var e=Je(),t=Rr().Graph,r=wn().slack;Qc=n;function n(s){var c=new t({directed:!1}),u=s.nodes()[0],l=s.nodeCount();c.setNode(u,{});for(var d,h;o(c,s)<l;)d=i(c,s),h=c.hasNode(d.v)?r(s,d):-r(s,d),a(c,s,h);return c}function o(s,c){function u(l){e.forEach(c.nodeEdges(l),function(d){var h=d.v,p=l===h?d.w:h;!s.hasNode(p)&&!r(c,d)&&(s.setNode(p,{}),s.setEdge(l,p,{}),u(p))})}return e.forEach(s.nodes(),u),s.nodeCount()}function i(s,c){return e.minBy(c.edges(),function(u){if(s.hasNode(u.v)!==s.hasNode(u.w))return r(c,u)})}function a(s,c,u){e.forEach(s.nodes(),function(l){c.node(l).rank+=u})}return Qc}var eu,Gg;function WC(){if(Gg)return eu;Gg=1;var e=Je(),t=Lb(),r=wn().slack,n=wn().longestPath,o=Rr().alg.preorder,i=Rr().alg.postorder,a=gr().simplify;eu=s,s.initLowLimValues=d,s.initCutValues=c,s.calcCutValue=l,s.leaveEdge=p,s.enterEdge=g,s.exchangeEdges=m;function s(w){w=a(w),n(w);var x=t(w);d(x),c(x,w);for(var C,S;C=p(x);)S=g(x,w,C),m(x,w,C,S)}function c(w,x){var C=i(w,w.nodes());C=C.slice(0,C.length-1),e.forEach(C,function(S){u(w,x,S)})}function u(w,x,C){var S=w.node(C),j=S.parent;w.edge(C,j).cutvalue=l(w,x,C)}function l(w,x,C){var S=w.node(C),j=S.parent,T=!0,k=x.edge(C,j),M=0;return k||(T=!1,k=x.edge(j,C)),M=k.weight,e.forEach(x.nodeEdges(C),function(R){var E=R.v===C,P=E?R.w:R.v;if(P!==j){var I=E===T,q=x.edge(R).weight;if(M+=I?q:-q,v(w,C,P)){var O=w.edge(C,P).cutvalue;M+=I?-O:O}}}),M}function d(w,x){arguments.length<2&&(x=w.nodes()[0]),h(w,{},1,x)}function h(w,x,C,S,j){var T=C,k=w.node(S);return x[S]=!0,e.forEach(w.neighbors(S),function(M){e.has(x,M)||(C=h(w,x,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(x){return w.edge(x).cutvalue<0})}function g(w,x,C){var S=C.v,j=C.w;x.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=e.filter(x.edges(),function(P){return R===b(w,w.node(P.v),M)&&R!==b(w,w.node(P.w),M)});return e.minBy(E,function(P){return r(x,P)})}function m(w,x,C,S){var j=C.v,T=C.w;w.removeEdge(j,T),w.setEdge(S.v,S.w,{}),d(w),c(w,x),y(w,x)}function y(w,x){var C=e.find(w.nodes(),function(j){return!x.node(j).parent}),S=o(w,C);S=S.slice(1),e.forEach(S,function(j){var T=w.node(j).parent,k=x.edge(j,T),M=!1;k||(k=x.edge(T,j),M=!0),x.node(j).rank=x.node(T).rank+(M?k.minlen:-k.minlen)})}function v(w,x,C){return w.hasEdge(x,C)}function b(w,x,C){return C.low<=x.lim&&x.lim<=C.lim}return eu}var ru,Ug;function GC(){if(Ug)return ru;Ug=1;var e=wn(),t=e.longestPath,r=Lb(),n=WC();ru=o;function o(c){switch(c.graph().ranker){case"network-simplex":s(c);break;case"tight-tree":a(c);break;case"longest-path":i(c);break;default:s(c)}}var i=t;function a(c){t(c),r(c)}function s(c){n(c)}return ru}var tu,Hg;function UC(){if(Hg)return tu;Hg=1;var e=Je();tu=t;function t(o){var i=n(o);e.forEach(o.graph().dummyChains,function(a){for(var s=o.node(a),c=s.edgeObj,u=r(o,i,c.v,c.w),l=u.path,d=u.lca,h=0,p=l[h],g=!0;a!==c.w;){if(s=o.node(a),g){for(;(p=l[h])!==d&&o.node(p).maxRank<s.rank;)h++;p===d&&(g=!1)}if(!g){for(;h<l.length-1&&o.node(p=l[h+1]).minRank<=s.rank;)h++;p=l[h]}o.setParent(a,p),a=o.successors(a)[0]}})}function r(o,i,a,s){var c=[],u=[],l=Math.min(i[a].low,i[s].low),d=Math.max(i[a].lim,i[s].lim),h,p;h=a;do h=o.parent(h),c.push(h);while(h&&(i[h].low>l||d>i[h].lim));for(p=h,h=s;(h=o.parent(h))!==p;)u.push(h);return{path:c.concat(u.reverse()),lca:p}}function n(o){var i={},a=0;function s(c){var u=a;e.forEach(o.children(c),s),i[c]={low:u,lim:a++}}return e.forEach(o.children(),s),i}return tu}var nu,Kg;function HC(){if(Kg)return nu;Kg=1;var e=Je(),t=gr();nu={run:r,cleanup:a};function r(s){var c=t.addDummyNode(s,"root",{},"_root"),u=o(s),l=e.max(e.values(u))-1,d=2*l+1;s.graph().nestingRoot=c,e.forEach(s.edges(),function(p){s.edge(p).minlen*=d});var h=i(s)+1;e.forEach(s.children(),function(p){n(s,c,d,h,l,u,p)}),s.graph().nodeRankFactor=d}function n(s,c,u,l,d,h,p){var g=s.children(p);if(!g.length){p!==c&&s.setEdge(c,p,{weight:0,minlen:u});return}var m=t.addBorderNode(s,"_bt"),y=t.addBorderNode(s,"_bb"),v=s.node(p);s.setParent(m,p),v.borderTop=m,s.setParent(y,p),v.borderBottom=y,e.forEach(g,function(b){n(s,c,u,l,d,h,b);var w=s.node(b),x=w.borderTop?w.borderTop:b,C=w.borderBottom?w.borderBottom:b,S=w.borderTop?l:2*l,j=x!==C?1:d-h[p]+1;s.setEdge(m,x,{weight:S,minlen:j,nestingEdge:!0}),s.setEdge(C,y,{weight:S,minlen:j,nestingEdge:!0})}),s.parent(p)||s.setEdge(c,m,{weight:0,minlen:d+h[p]})}function o(s){var c={};function u(l,d){var h=s.children(l);h&&h.length&&e.forEach(h,function(p){u(p,d+1)}),c[l]=d}return e.forEach(s.children(),function(l){u(l,1)}),c}function i(s){return e.reduce(s.edges(),function(c,u){return c+s.edge(u).weight},0)}function a(s){var c=s.graph();s.removeNode(c.nestingRoot),delete c.nestingRoot,e.forEach(s.edges(),function(u){var l=s.edge(u);l.nestingEdge&&s.removeEdge(u)})}return nu}var ou,Jg;function KC(){if(Jg)return ou;Jg=1;var e=Je(),t=gr();ou=r;function r(o){function i(a){var s=o.children(a),c=o.node(a);if(s.length&&e.forEach(s,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",a,c,u),n(o,"borderRight","_br",a,c,u)}}e.forEach(o.children(),i)}function n(o,i,a,s,c,u){var l={width:0,height:0,rank:u,borderType:i},d=c[i][u-1],h=t.addDummyNode(o,"border",l,a);c[i][u]=h,o.setParent(h,s),d&&o.setEdge(d,h,{weight:1})}return ou}var iu,Zg;function JC(){if(Zg)return iu;Zg=1;var e=Je();iu={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")&&(s(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){a(u.node(l))}),e.forEach(u.edges(),function(l){var d=u.edge(l);e.forEach(d.points,a),e.has(d,"y")&&a(d)})}function a(u){u.y=-u.y}function s(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 iu}var au,Yg;function ZC(){if(Yg)return au;Yg=1;var e=Je();au=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})),a=e.map(e.range(i+1),function(){return[]});function s(u){if(!e.has(n,u)){n[u]=!0;var l=r.node(u);a[l.rank].push(u),e.forEach(r.successors(u),s)}}var c=e.sortBy(o,function(u){return r.node(u).rank});return e.forEach(c,s),a}return au}var su,Xg;function YC(){if(Xg)return su;Xg=1;var e=Je();su=t;function t(n,o){for(var i=0,a=1;a<o.length;++a)i+=r(n,o[a-1],o[a]);return i}function r(n,o,i){for(var a=e.zipObject(i,e.map(i,function(h,p){return p})),s=e.flatten(e.map(o,function(h){return e.sortBy(e.map(n.outEdges(h),function(p){return{pos:a[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(s.forEach(function(h){var p=h.pos+c;l[p]+=h.weight;for(var g=0;p>0;)p%2&&(g+=l[p+1]),p=p-1>>1,l[p]+=h.weight;d+=h.weight*g})),d}return su}var cu,Qg;function XC(){if(Qg)return cu;Qg=1;var e=Je();cu=t;function t(r,n){return e.map(n,function(o){var i=r.inEdges(o);if(i.length){var a=e.reduce(i,function(s,c){var u=r.edge(c),l=r.node(c.v);return{sum:s.sum+u.weight*l.order,weight:s.weight+u.weight}},{sum:0,weight:0});return{v:o,barycenter:a.sum/a.weight,weight:a.weight}}else return{v:o}})}return cu}var uu,ey;function QC(){if(ey)return uu;ey=1;var e=Je();uu=t;function t(o,i){var a={};e.forEach(o,function(c,u){var l=a[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=a[c.v],l=a[c.w];!e.isUndefined(u)&&!e.isUndefined(l)&&(l.indegree++,u.out.push(a[c.w]))});var s=e.filter(a,function(c){return!c.indegree});return r(s)}function r(o){var i=[];function a(u){return function(l){l.merged||(e.isUndefined(l.barycenter)||e.isUndefined(u.barycenter)||l.barycenter>=u.barycenter)&&n(u,l)}}function s(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(),a(c)),e.forEach(c.out,s(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 a=0,s=0;o.weight&&(a+=o.barycenter*o.weight,s+=o.weight),i.weight&&(a+=i.barycenter*i.weight,s+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=a/s,o.weight=s,o.i=Math.min(i.i,o.i),i.merged=!0}return uu}var lu,ry;function e_(){if(ry)return lu;ry=1;var e=Je(),t=gr();lu=r;function r(i,a){var s=t.partition(i,function(m){return e.has(m,"barycenter")}),c=s.lhs,u=e.sortBy(s.rhs,function(m){return-m.i}),l=[],d=0,h=0,p=0;c.sort(o(!!a)),p=n(l,u,p),e.forEach(c,function(m){p+=m.vs.length,l.push(m.vs),d+=m.barycenter*m.weight,h+=m.weight,p=n(l,u,p)});var g={vs:e.flatten(l,!0)};return h&&(g.barycenter=d/h,g.weight=h),g}function n(i,a,s){for(var c;a.length&&(c=e.last(a)).i<=s;)a.pop(),i.push(c.vs),s++;return s}function o(i){return function(a,s){return a.barycenter<s.barycenter?-1:a.barycenter>s.barycenter?1:i?s.i-a.i:a.i-s.i}}return lu}var du,ty;function r_(){if(ty)return du;ty=1;var e=Je(),t=XC(),r=QC(),n=e_();du=o;function o(s,c,u,l){var d=s.children(c),h=s.node(c),p=h?h.borderLeft:void 0,g=h?h.borderRight:void 0,m={};p&&(d=e.filter(d,function(C){return C!==p&&C!==g}));var y=t(s,d);e.forEach(y,function(C){if(s.children(C.v).length){var S=o(s,C.v,u,l);m[C.v]=S,e.has(S,"barycenter")&&a(C,S)}});var v=r(y,u);i(v,m);var b=n(v,l);if(p&&(b.vs=e.flatten([p,b.vs,g],!0),s.predecessors(p).length)){var w=s.node(s.predecessors(p)[0]),x=s.node(s.predecessors(g)[0]);e.has(b,"barycenter")||(b.barycenter=0,b.weight=0),b.barycenter=(b.barycenter*b.weight+w.order+x.order)/(b.weight+2),b.weight+=2}return b}function i(s,c){e.forEach(s,function(u){u.vs=e.flatten(u.vs.map(function(l){return c[l]?c[l].vs:l}),!0)})}function a(s,c){e.isUndefined(s.barycenter)?(s.barycenter=c.barycenter,s.weight=c.weight):(s.barycenter=(s.barycenter*s.weight+c.barycenter*c.weight)/(s.weight+c.weight),s.weight+=c.weight)}return du}var fu,ny;function t_(){if(ny)return fu;ny=1;var e=Je(),t=Rr().Graph;fu=r;function r(o,i,a){var s=n(o),c=new t({compound:!0}).setGraph({root:s}).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||s),e.forEach(o[a](u),function(h){var p=h.v===u?h.w:h.v,g=c.edge(p,u),m=e.isUndefined(g)?0:g.weight;c.setEdge(p,u,{weight:o.edge(h).weight+m})}),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 fu}var hu,oy;function n_(){if(oy)return hu;oy=1;var e=Je();hu=t;function t(r,n,o){var i={},a;e.forEach(o,function(s){for(var c=r.parent(s),u,l;c;){if(u=r.parent(c),u?(l=i[u],i[u]=c):(l=a,a=c),l&&l!==c){n.setEdge(l,c);return}c=u}})}return hu}var pu,iy;function o_(){if(iy)return pu;iy=1;var e=Je(),t=ZC(),r=YC(),n=r_(),o=t_(),i=n_(),a=Rr().Graph,s=gr();pu=c;function c(h){var p=s.maxRank(h),g=u(h,e.range(1,p+1),"inEdges"),m=u(h,e.range(p-1,-1,-1),"outEdges"),y=t(h);d(h,y);for(var v=Number.POSITIVE_INFINITY,b,w=0,x=0;x<4;++w,++x){l(w%2?g:m,w%4>=2),y=s.buildLayerMatrix(h);var C=r(h,y);C<v&&(x=0,b=e.cloneDeep(y),v=C)}d(h,b)}function u(h,p,g){return e.map(p,function(m){return o(h,m,g)})}function l(h,p){var g=new a;e.forEach(h,function(m){var y=m.graph().root,v=n(m,y,g,p);e.forEach(v.vs,function(b,w){m.node(b).order=w}),i(m,g,v.vs)})}function d(h,p){e.forEach(p,function(g){e.forEach(g,function(m,y){h.node(m).order=y})})}return pu}var gu,ay;function i_(){if(ay)return gu;ay=1;var e=Je(),t=Rr().Graph,r=gr();gu={positionX:g,findType1Conflicts:n,findType2Conflicts:o,addConflict:a,hasConflict:s,verticalAlignment:c,horizontalCompaction:u,alignCoordinates:h,findSmallestWidthAlignment:d,balance:p};function n(v,b){var w={};function x(C,S){var j=0,T=0,k=C.length,M=e.last(S);return e.forEach(S,function(R,E){var P=i(v,R),I=P?v.node(P).order:k;(P||R===M)&&(e.forEach(S.slice(T,E+1),function(q){e.forEach(v.predecessors(q),function(O){var V=v.node(O),W=V.order;(W<j||I<W)&&!(V.dummy&&v.node(q).dummy)&&a(w,O,q)})}),T=E+1,j=I)}),S}return e.reduce(b,x),w}function o(v,b){var w={};function x(S,j,T,k,M){var R;e.forEach(e.range(j,T),function(E){R=S[E],v.node(R).dummy&&e.forEach(v.predecessors(R),function(P){var I=v.node(P);I.dummy&&(I.order<k||I.order>M)&&a(w,P,R)})})}function C(S,j){var T=-1,k,M=0;return e.forEach(j,function(R,E){if(v.node(R).dummy==="border"){var P=v.predecessors(R);P.length&&(k=v.node(P[0]).order,x(j,M,E,T,k),M=E,T=k)}x(j,M,j.length,k,S.length)}),j}return e.reduce(b,C),w}function i(v,b){if(v.node(b).dummy)return e.find(v.predecessors(b),function(w){return v.node(w).dummy})}function a(v,b,w){if(b>w){var x=b;b=w,w=x}var C=v[b];C||(v[b]=C={}),C[w]=!0}function s(v,b,w){if(b>w){var x=b;b=w,w=x}return e.has(v[b],w)}function c(v,b,w,x){var C={},S={},j={};return e.forEach(b,function(T){e.forEach(T,function(k,M){C[k]=k,S[k]=k,j[k]=M})}),e.forEach(b,function(T){var k=-1;e.forEach(T,function(M){var R=x(M);if(R.length){R=e.sortBy(R,function(O){return j[O]});for(var E=(R.length-1)/2,P=Math.floor(E),I=Math.ceil(E);P<=I;++P){var q=R[P];S[M]===M&&k<j[q]&&!s(w,M,q)&&(S[q]=M,S[M]=C[M]=C[q],k=j[q])}}})}),{root:C,align:S}}function u(v,b,w,x,C){var S={},j=l(v,b,w,C),T=C?"borderLeft":"borderRight";function k(E,P){for(var I=j.nodes(),q=I.pop(),O={};q;)O[q]?E(q):(O[q]=!0,I.push(q),I=I.concat(P(q))),q=I.pop()}function M(E){S[E]=j.inEdges(E).reduce(function(P,I){return Math.max(P,S[I.v]+j.edge(I))},0)}function R(E){var P=j.outEdges(E).reduce(function(q,O){return Math.min(q,S[O.w]-j.edge(O))},Number.POSITIVE_INFINITY),I=v.node(E);P!==Number.POSITIVE_INFINITY&&I.borderType!==T&&(S[E]=Math.max(S[E],P))}return k(M,j.predecessors.bind(j)),k(R,j.successors.bind(j)),e.forEach(x,function(E){S[E]=S[w[E]]}),S}function l(v,b,w,x){var C=new t,S=v.graph(),j=m(S.nodesep,S.edgesep,x);return e.forEach(b,function(T){var k;e.forEach(T,function(M){var R=w[M];if(C.setNode(R),k){var E=w[k],P=C.edge(E,R);C.setEdge(E,R,Math.max(j(v,M,k),P||0))}k=M})}),C}function d(v,b){return e.minBy(e.values(b),function(w){var x=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY;return e.forIn(w,function(S,j){var T=y(v,j)/2;x=Math.max(S+T,x),C=Math.min(S-T,C)}),x-C})}function h(v,b){var w=e.values(b),x=e.min(w),C=e.max(w);e.forEach(["u","d"],function(S){e.forEach(["l","r"],function(j){var T=S+j,k=v[T],M;if(k!==b){var R=e.values(k);M=j==="l"?x-e.min(R):C-e.max(R),M&&(v[T]=e.mapValues(k,function(E){return E+M}))}})})}function p(v,b){return e.mapValues(v.ul,function(w,x){if(b)return v[b.toLowerCase()][x];var C=e.sortBy(e.map(v,x));return(C[1]+C[2])/2})}function g(v){var b=r.buildLayerMatrix(v),w=e.merge(n(v,b),o(v,b)),x={},C;e.forEach(["u","d"],function(j){C=j==="u"?b:e.values(b).reverse(),e.forEach(["l","r"],function(T){T==="r"&&(C=e.map(C,function(E){return e.values(E).reverse()}));var k=(j==="u"?v.predecessors:v.successors).bind(v),M=c(v,C,w,k),R=u(v,C,M.root,M.align,T==="r");T==="r"&&(R=e.mapValues(R,function(E){return-E})),x[j+T]=R})});var S=d(v,x);return h(x,S),p(x,v.graph().align)}function m(v,b,w){return function(x,C,S){var j=x.node(C),T=x.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?b:v)/2,k+=(T.dummy?b:v)/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 y(v,b){return v.node(b).width}return gu}var yu,sy;function a_(){if(sy)return yu;sy=1;var e=Je(),t=gr(),r=i_().positionX;yu=n;function n(i){i=t.asNonCompoundGraph(i),o(i),e.forEach(r(i),function(a,s){i.node(s).x=a})}function o(i){var a=t.buildLayerMatrix(i),s=i.graph().ranksep,c=0;e.forEach(a,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+s})}return yu}var mu,cy;function s_(){if(cy)return mu;cy=1;var e=Je(),t=DC(),r=VC(),n=GC(),o=gr().normalizeRanks,i=UC(),a=gr().removeEmptyRanks,s=HC(),c=KC(),u=JC(),l=o_(),d=a_(),h=gr(),p=Rr().Graph;mu=g;function g($,z){var G=z&&z.debugTiming?h.time:h.notime;G("layout",function(){var N=G(" buildLayoutGraph",function(){return k($)});G(" runLayout",function(){m(N,G)}),G(" updateInputGraph",function(){y($,N)})})}function m($,z){z(" makeSpaceForEdgeLabels",function(){M($)}),z(" removeSelfEdges",function(){te($)}),z(" acyclic",function(){t.run($)}),z(" nestingGraph.run",function(){s.run($)}),z(" rank",function(){n(h.asNonCompoundGraph($))}),z(" injectEdgeLabelProxies",function(){R($)}),z(" removeEmptyRanks",function(){a($)}),z(" nestingGraph.cleanup",function(){s.cleanup($)}),z(" normalizeRanks",function(){o($)}),z(" assignRankMinMax",function(){E($)}),z(" removeEdgeLabelProxies",function(){P($)}),z(" normalize.run",function(){r.run($)}),z(" parentDummyChains",function(){i($)}),z(" addBorderSegments",function(){c($)}),z(" order",function(){l($)}),z(" insertSelfEdges",function(){ne($)}),z(" adjustCoordinateSystem",function(){u.adjust($)}),z(" position",function(){d($)}),z(" positionSelfEdges",function(){ee($)}),z(" removeBorderNodes",function(){W($)}),z(" normalize.undo",function(){r.undo($)}),z(" fixupEdgeLabelCoords",function(){O($)}),z(" undoCoordinateSystem",function(){u.undo($)}),z(" translateGraph",function(){I($)}),z(" assignNodeIntersects",function(){q($)}),z(" reversePoints",function(){V($)}),z(" acyclic.undo",function(){t.undo($)})}function y($,z){e.forEach($.nodes(),function(G){var N=$.node(G),re=z.node(G);N&&(N.x=re.x,N.y=re.y,z.children(G).length&&(N.width=re.width,N.height=re.height))}),e.forEach($.edges(),function(G){var N=$.edge(G),re=z.edge(G);N.points=re.points,e.has(re,"x")&&(N.x=re.x,N.y=re.y)}),$.graph().width=z.graph().width,$.graph().height=z.graph().height}var v=["nodesep","edgesep","ranksep","marginx","marginy"],b={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},w=["acyclicer","ranker","rankdir","align"],x=["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 z=new p({multigraph:!0,compound:!0}),G=le($.graph());return z.setGraph(e.merge({},b,be(G,v),e.pick(G,w))),e.forEach($.nodes(),function(N){var re=le($.node(N));z.setNode(N,e.defaults(be(re,x),C)),z.setParent(N,$.parent(N))}),e.forEach($.edges(),function(N){var re=le($.edge(N));z.setEdge(N,e.merge({},j,be(re,S),e.pick(re,T)))}),z}function M($){var z=$.graph();z.ranksep/=2,e.forEach($.edges(),function(G){var N=$.edge(G);N.minlen*=2,N.labelpos.toLowerCase()!=="c"&&(z.rankdir==="TB"||z.rankdir==="BT"?N.width+=N.labeloffset:N.height+=N.labeloffset)})}function R($){e.forEach($.edges(),function(z){var G=$.edge(z);if(G.width&&G.height){var N=$.node(z.v),re=$.node(z.w),ye={rank:(re.rank-N.rank)/2+N.rank,e:z};h.addDummyNode($,"edge-proxy",ye,"_ep")}})}function E($){var z=0;e.forEach($.nodes(),function(G){var N=$.node(G);N.borderTop&&(N.minRank=$.node(N.borderTop).rank,N.maxRank=$.node(N.borderBottom).rank,z=e.max(z,N.maxRank))}),$.graph().maxRank=z}function P($){e.forEach($.nodes(),function(z){var G=$.node(z);G.dummy==="edge-proxy"&&($.edge(G.e).labelRank=G.rank,$.removeNode(z))})}function I($){var z=Number.POSITIVE_INFINITY,G=0,N=Number.POSITIVE_INFINITY,re=0,ye=$.graph(),de=ye.marginx||0,J=ye.marginy||0;function X(U){var ue=U.x,se=U.y,we=U.width,pe=U.height;z=Math.min(z,ue-we/2),G=Math.max(G,ue+we/2),N=Math.min(N,se-pe/2),re=Math.max(re,se+pe/2)}e.forEach($.nodes(),function(U){X($.node(U))}),e.forEach($.edges(),function(U){var ue=$.edge(U);e.has(ue,"x")&&X(ue)}),z-=de,N-=J,e.forEach($.nodes(),function(U){var ue=$.node(U);ue.x-=z,ue.y-=N}),e.forEach($.edges(),function(U){var ue=$.edge(U);e.forEach(ue.points,function(se){se.x-=z,se.y-=N}),e.has(ue,"x")&&(ue.x-=z),e.has(ue,"y")&&(ue.y-=N)}),ye.width=G-z+de,ye.height=re-N+J}function q($){e.forEach($.edges(),function(z){var G=$.edge(z),N=$.node(z.v),re=$.node(z.w),ye,de;G.points?(ye=G.points[0],de=G.points[G.points.length-1]):(G.points=[],ye=re,de=N),G.points.unshift(h.intersectRect(N,ye)),G.points.push(h.intersectRect(re,de))})}function O($){e.forEach($.edges(),function(z){var G=$.edge(z);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 V($){e.forEach($.edges(),function(z){var G=$.edge(z);G.reversed&&G.points.reverse()})}function W($){e.forEach($.nodes(),function(z){if($.children(z).length){var G=$.node(z),N=$.node(G.borderTop),re=$.node(G.borderBottom),ye=$.node(e.last(G.borderLeft)),de=$.node(e.last(G.borderRight));G.width=Math.abs(de.x-ye.x),G.height=Math.abs(re.y-N.y),G.x=ye.x+G.width/2,G.y=N.y+G.height/2}}),e.forEach($.nodes(),function(z){$.node(z).dummy==="border"&&$.removeNode(z)})}function te($){e.forEach($.edges(),function(z){if(z.v===z.w){var G=$.node(z.v);G.selfEdges||(G.selfEdges=[]),G.selfEdges.push({e:z,label:$.edge(z)}),$.removeEdge(z)}})}function ne($){var z=h.buildLayerMatrix($);e.forEach(z,function(G){var N=0;e.forEach(G,function(re,ye){var de=$.node(re);de.order=ye+N,e.forEach(de.selfEdges,function(J){h.addDummyNode($,"selfedge",{width:J.label.width,height:J.label.height,rank:de.rank,order:ye+ ++N,e:J.e,label:J.label},"_se")}),delete de.selfEdges})})}function ee($){e.forEach($.nodes(),function(z){var G=$.node(z);if(G.dummy==="selfedge"){var N=$.node(G.e.v),re=N.x+N.width/2,ye=N.y,de=G.x-re,J=N.height/2;$.setEdge(G.e,G.label),$.removeNode(z),G.label.points=[{x:re+2*de/3,y:ye-J},{x:re+5*de/6,y:ye-J},{x:re+de,y:ye},{x:re+5*de/6,y:ye+J},{x:re+2*de/3,y:ye+J}],G.label.x=G.x,G.label.y=G.y}})}function be($,z){return e.mapValues(e.pick($,z),Number)}function le($){var z={};return e.forEach($,function(G,N){z[N.toLowerCase()]=G}),z}return mu}var bu,uy;function c_(){if(uy)return bu;uy=1;var e=Je(),t=gr(),r=Rr().Graph;bu={debugOrdering:n};function n(o){var i=t.buildLayerMatrix(o),a=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(s){a.setNode(s,{label:s}),a.setParent(s,"layer"+o.node(s).rank)}),e.forEach(o.edges(),function(s){a.setEdge(s.v,s.w,{},s.name)}),e.forEach(i,function(s,c){var u="layer"+c;a.setNode(u,{rank:"same"}),e.reduce(s,function(l,d){return a.setEdge(l,d,{style:"invis"}),d})}),a}return bu}var vu,ly;function u_(){return ly||(ly=1,vu="0.8.5"),vu}var xu,dy;function l_(){return dy||(dy=1,xu={graphlib:Rr(),layout:s_(),debug:c_(),util:{time:gr().time,notime:gr().notime},version:u_()}),xu}var d_=l_();const fy=J0(d_);function f_(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 fy.graphlib.Graph({multigraph:!0,compound:!0}),a=r.compactSpacingScale??(r.spacingFactor>0?r.spacingFactor/1.3:1);i.setGraph({rankdir:r.rankDir,nodesep:r.compact?Math.max(r.nodeSep,24*a):r.nodeSep,edgesep:r.compact?Math.min(r.edgeSep,24*a):r.edgeSep,ranksep:r.compact?Math.min(r.rankSep,80*a):r.rankSep,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({})),i.setDefaultNodeLabel(()=>({}));for(const d of e)i.setNode(d.id,{width:d.width+2,height:d.height+2});for(const d of e)d.parent&&n.has(d.parent)&&i.setParent(d.id,d.parent);for(const d of t){if(!n.has(d.source)||!n.has(d.target)||o.has(d.source)||o.has(d.target))continue;const h=$m(d.label,d.icon??((l=d.data)==null?void 0:l.icon),r.edgeLabelFontSize),p=r.rankDir==="LR"||r.rankDir==="RL",g=(h.width?h.width+2*Nm:0)+(d.connectorClearance??0);i.setEdge(d.source,d.target,{minlen:1,weight:1,...g?{width:p?g:Math.max(1,h.height),height:p?Math.max(1,h.height):g,labelpos:"c"}:{}},d.id)}fy.layout(i);const s=new Map;for(const d of e){if(o.has(d.id))continue;const h=i.node(d.id);h&&Number.isFinite(h.x)&&Number.isFinite(h.y)&&s.set(d.id,{x:h.x,y:h.y})}const c=r.compact?1:r.spacingFactor;if(c&&c!==1&&s.size){let d=1/0,h=1/0,p=-1/0,g=-1/0;s.forEach(v=>{d=Math.min(d,v.x),h=Math.min(h,v.y),p=Math.max(p,v.x),g=Math.max(g,v.y)});const m=(d+p)/2,y=(h+g)/2;s.forEach((v,b)=>s.set(b,{x:m+(v.x-m)*c,y:y+(v.y-y)*c}))}const u=r.nodeAlignment??"center";if(u!=="center"){const d=r.rankDir==="LR"||r.rankDir==="RL",h=d?"x":"y",p=d?"width":"height",g=r.rankDir==="RL"||r.rankDir==="BT"?-1:1,m=u==="leading"?-g:g,y=new Map;for(const v of e){const b=s.get(v.id);if(!b)continue;const w=b[h];y.set(w,Math.max(y.get(w)??0,v[p]))}for(const v of e){const b=s.get(v.id);if(!b)continue;const w=b[h],x=(y.get(w)-v[p])/2;s.set(v.id,{...b,[h]:w+m*x})}}return s}function h_(e,t,r,n,o){const i=new Map,a=new Map(e.map(l=>[l.id,l]));for(const l of e){if(!l.parent||!a.has(l.parent))continue;const d=i.get(l.parent);d?d.push(l.id):i.set(l.parent,[l.id])}const s=(l,d=new Set)=>{var p;const h=(p=a.get(l))==null?void 0:p.parent;return!h||!a.has(h)||d.has(l)?0:(d.add(l),1+s(h,d))},c=[...i.keys()].sort((l,d)=>s(d)-s(l)),u=new Map;for(const l of c){let d=null;for(const g of i.get(l)||[]){let m=u.get(g);if(!m){const y=t.get(g);if(!y)continue;const v=r.get(g)||{w:60,h:60};m={x1:y.x-v.w/2,y1:y.y-v.h/2,x2:y.x+v.w/2,y2:y.y+v.h/2}}d=d?{x1:Math.min(d.x1,m.x1),y1:Math.min(d.y1,m.y1),x2:Math.max(d.x2,m.x2),y2:Math.max(d.y2,m.y2)}:{...m}}if(!d)continue;const h=n(l);d={x1:d.x1-h,y1:d.y1-h,x2:d.x2+h,y2:d.y2+h};const p=o(l);if(p){const g=d.x2-d.x1,m=d.y2-d.y1;if(p.w>g){const y=(p.w-g)/2;d.x1-=y,d.x2+=y}if(p.h>m){const y=(p.h-m)/2;d.y1-=y,d.y2+=y}}u.set(l,d)}return u}function p_(e){const t=e.getBoundingClientRect(),r=t.height/e.offsetHeight;if(!Number.isFinite(r)||r<=0)return[];const n=Mm(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],a=new Set(i.filter(s=>s.hasAttribute("data-flow-inspection-row")&&s.getBoundingClientRect().height>0).map(s=>s.dataset.flowProperty));return i.flatMap(s=>{if(s.closest(".flow-sdk-node")!==e)return[];if(a.has(s.dataset.flowProperty)&&!s.hasAttribute("data-flow-inspection-row"))return[];const c=s.dataset.flowPortSide;if(c&&["top","right","bottom","left"].includes(c)){const l=Tm(n?Ut(o,n):o,c,Number(s.dataset.flowPortPosition??.5));return[{property:s.getAttribute("data-flow-property"),top:l.y,height:0,anchor:l,...s.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...s.dataset.flowPortRole==="source"||s.dataset.flowPortRole==="target"?{role:s.dataset.flowPortRole}:{}}]}const u=s.getBoundingClientRect();return!u.width||!u.height?[]:[{property:s.getAttribute("data-flow-property"),top:Math.round((u.top-t.top)/r*1e3)/1e3,height:Math.round(u.height/r*1e3)/1e3,...s.dataset.flowPortRole==="source"||s.dataset.flowPortRole==="target"?{role:s.dataset.flowPortRole}:{}}]})}function g_({id:e,x:t,y:r,placed:n,hidden:o,onMount:i,drawHandles:a,drawMode:s,connectedPorts:c,resolvedRows:u,hasCollapseControl:l,handleColor:d,animated:h,animationColor:p,animationWidth:g=8,animationVariant:m,width:y=0,height:v=0,propertyMode:b,reversePorts:w,direction:x="LR",onPropertyRows:C,onSurface:S,children:j}){const T=_.useRef(null),[k,M]=_.useState([]),R=u??k,[E,P]=_.useState();return _.useLayoutEffect(()=>{const I=T.current;if(!I)return;const q=()=>{const W=Mm(I);P(te=>JSON.stringify(te)===JSON.stringify(W)?te:W),S==null||S(e,W)};q();const O=new ResizeObserver(q);O.observe(I);const V=I.querySelector("[data-flow-node-surface]");return V&&O.observe(V),()=>O.disconnect()},[e,j,S]),_.useLayoutEffect(()=>(i(e,T.current),()=>{i(e,null),S==null||S(e,void 0)}),[e,i,S]),_.useLayoutEffect(()=>{const I=T.current;if(!I)return;let q="";const O=()=>{const ne=p_(I),ee=b?ne:ne.filter(le=>le.anchor),be=JSON.stringify(ee);be!==q&&(q=be,M(ee),C==null||C(e,ee))};if(O(),!b&&!I.querySelector("[data-flow-port-side]"))return;const V=new ResizeObserver(O),W=()=>{V.disconnect(),V.observe(I),I.querySelectorAll("[data-flow-property]").forEach(ne=>V.observe(ne)),O()};W();const te=new MutationObserver(W);return te.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),()=>{V.disconnect(),te.disconnect(),I.removeEventListener("scroll",O,!0)}},[e,b,C,j]),f.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,h&&g>0&&y>0&&v>0&&f.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:f.jsx(Am,{variant:m,x:((E==null?void 0:E.left)??0)+g/2,y:((E==null?void 0:E.top)??0)+g/2,width:((E==null?void 0:E.width)??y)-g,height:((E==null?void 0:E.height)??v)-g,radius:((E==null?void 0:E.radius)??0)-g/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:g})}),a&&b&&R.map(I=>["source","target"].filter(q=>!I.role||I.role===q).filter(q=>s||(c==null?void 0:c.has(`${q}:${I.property}`))).map(q=>{var O;return f.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:V=>V.stopPropagation()},`${I.property}:${q}`)})),a&&!l&&(!b||!R.length)&&(!b||!R.some(I=>I.anchor))&&f.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)+(x==="RL"?-36:x==="LR"?(E==null?void 0:E.width)??y:((E==null?void 0:E.width)??y)/2),top:((E==null?void 0:E.top)??0)+(x==="BT"?-36:x==="TB"?(E==null?void 0:E.height)??v:((E==null?void 0:E.height)??v)/2),transform:x==="BT"||x==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:I=>I.stopPropagation(),children:f.jsx(K.PiPlusBold,{size:24})})]})}const y_=_.memo(g_);function m_(e,t,r){const[n,o]=_.useState(()=>({nodes:new Set,edges:new Set})),i=_.useMemo(()=>{const s=new Set(e.map(p=>p.id)),c=t.filter(p=>s.has(p.source)&&s.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=>s.has(p))),d=new Set([...n.edges].filter(p=>u.has(p)));if(!r)return{nodes:s,edges:u,ready:u};for(const p of e)c.filter(m=>m.target===p.id&&m.source!==m.target).every(m=>d.has(m.id))&&l.add(p.id);let h=new Set(c.filter(p=>l.has(p.source)).map(p=>p.id));if(l.size<s.size&&!c.some(p=>h.has(p.id)&&!d.has(p.id))){const p=e.find(g=>!l.has(g.id));p&&l.add(p.id),h=new Set(c.filter(g=>l.has(g.source)).map(g=>g.id))}return{nodes:l,edges:d,ready:h}},[e,t,r,n]);_.useLayoutEffect(()=>{o(s=>{const c=r?i:{nodes:new Set,edges:new Set},u=(l,d)=>l.size===d.size&&[...l].every(h=>d.has(h));return u(s.nodes,c.nodes)&&u(s.edges,c.edges)?s:{nodes:c.nodes,edges:c.edges}})},[i,r]);const a=_.useCallback(s=>{o(c=>c.edges.has(s)?c:{...c,edges:new Set([...c.edges,s])})},[]);return{shown:i.nodes,ready:i.ready,complete:a}}class b_{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(),a=300/1.4,s=()=>{this.cancelAnimation(),this.set(o.pan,o.zoom)},c=u=>{const l=Math.min(1,(u-i)/a);if(l>=1){s();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(s,a+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,a=t.y2-t.y1;if(!(i>0)||!(a>0)||!this.size.w||!this.size.h)return;const s=this.clamp(this.clamp(Math.min((this.size.w-2*r)/i,(this.size.h-2*r)/a))*o);this.transition({pan:{x:(this.size.w-s*(t.x1+t.x2))/2,y:(this.size.h-s*(t.y1+t.y2))/2},zoom:s},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 v_={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},wu={w:60,h:60},hy=4,x_=30,py=300,w_=500,C_=45,__=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2;function gy(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 S_(e){var pl;const{nodes:t,edges:r,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:a=!1,rankSep:s,edgeSep:c,spacingFactor:u=1.3,compactSpacingScale:l,minZoom:d,maxZoom:h,initialViewport:p,containerStyle:g,lineColor:m,drawMode:y,dragMode:v,multiSelect:b,isPerformanceMode:w}=e,[x,C]=_.useState(null),S=_.useMemo(()=>x?(x.mode==="connections"?Dl:Nl)(x.id,t,r):null,[x,t,r]),j=i==="auto"||i==="properties",T=_.useMemo(()=>r.filter(A=>Pu(A,i)&&(!S||S.has(A.source)&&S.has(A.target))),[r,i,S]),k=_.useMemo(()=>V0(t,r,i,a,S),[t,r,i,a,S]),M=_.useRef(k);M.current=k;const R=_.useRef(e);R.current=e;const E=_.useRef(null),P=_.useRef(null),I=_.useRef(null),q=_.useRef(null),O=_.useMemo(()=>new b_(p,d,h),[]);_.useEffect(()=>{O.minZoom=d,O.maxZoom=h},[O,d,h]);const V=_.useRef(new Map),W=_.useRef(new Map),te=_.useRef(new Map),ne=_.useRef(null),[ee,be]=_.useState(new Map),le=_.useCallback((A,L)=>{be(B=>{if(JSON.stringify(B.get(A))===JSON.stringify(L))return B;const H=new Map(B);return L?H.set(A,L):H.delete(A),H})},[]),[$,z]=_.useState(new Map),G=_.useRef($),N=_.useCallback((A,L)=>{z(B=>{if(JSON.stringify(B.get(A)??[])===JSON.stringify(L))return B;const H=new Map(B);return L.length?H.set(A,L):H.delete(A),H})},[]),[re,ye]=_.useState(()=>new Map),de=_.useRef(re);de.current=re;const J=_.useRef(new Map),X=_.useRef(!1),[U,ue]=_.useState(0),se=_.useRef(),we=_.useRef(),pe=_.useRef(null),ze=_.useRef(),Y=_.useRef(!1),fe=_.useRef(null),_e=_.useRef(u),Ie=a,Oe=_.useRef(Ie),[Ue,er]=_.useState(!0),De=_.useRef(null);De.current=S;const tr=_.useRef(1);tr.current=(x==null?void 0:x.mode)==="connections"?1.25:1;const he=_.useRef(null),Re=_.useRef(t),Ze=_.useRef([]),lr=_.useRef(!1),nr=()=>{pe.current!==null&&cancelAnimationFrame(pe.current),pe.current=null,clearTimeout(ze.current)},He=()=>{Ze.current.length&&(lr.current=!0),!X.current&&R.current.fitOnInit!==!1&&(Y.current=!0),clearTimeout(we.current),we.current=setTimeout(()=>{X.current=de.current.size>0,ue(A=>A+1)},w_)},Ee=A=>{nr();const L=new Map(de.current),B=performance.now(),H=()=>{nr(),ye(A),He()},ie=ve=>{const Te=Math.min(1,(ve-B)/py);if(Te>=1)return H();const $e=__(Te),ae=new Map;A.forEach((ce,ge)=>{const xe=L.get(ge);ae.set(ge,xe?{x:xe.x+(ce.x-xe.x)*$e,y:xe.y+(ce.y-xe.y)*$e}:ce)}),ye(ae),pe.current=requestAnimationFrame(ie)};pe.current=requestAnimationFrame(ie),ze.current=setTimeout(H,py+100)},ut=()=>{const A=R.current,L=tr.current,B=M.current,H=B.nodes.map(ve=>{const Te=V.current.get(ve.id)||wu;return{id:ve.id,parent:ve.parent,width:Te.w,height:Te.h}});let ie;try{const ve=A.compactPropertyLayout,Te=A.edgeMode!=="nodes"&&A.edgeMode!=="workflow",$e=B.edges.map(ae=>({...ae,connectorClearance:ve?Te&&(ae.sourceProperty!==void 0||ae.targetProperty!==void 0)?D0:z0:0}));ie=f_(H,$e,{edgeLabelFontSize:A.edgeMode==="nodes"||A.edgeMode==="workflow"?qm:xn,rankDir:A.direction,compact:ve,nodeAlignment:A.nodeAlignment,rankSep:A.rankSep*L,edgeSep:A.edgeSep*L,nodeSep:5*L,spacingFactor:A.spacingFactor??1.3,compactSpacingScale:(A.compactSpacingScale??(A.spacingFactor??1.3)/1.3)*L})}catch(ve){console.warn("[flow-sdk] layout failed",ve);return}for(const[ve,Te]of J.current)ie.has(ve)?ie.set(ve,Te):A.nodes.some($e=>$e.id===ve)||J.current.delete(ve);X.current&&!A.isPerformanceMode?Ee(ie):(nr(),ye(ie),He())},hr=_.useCallback(()=>{clearTimeout(we.current),clearTimeout(se.current),se.current=setTimeout(ut,R.current.layoutDebounce)},[]);_.useEffect(()=>{const A=new Map(Re.current.map(L=>[L.id,L]));t.some(L=>{var B;return((B=A.get(L.id))==null?void 0:B.collapsed)===!0&&!L.collapsed})&&(Ze.current=t.filter(L=>!A.has(L.id)).map(L=>L.id)),Re.current=t,_e.current!==u&&de.current.size>0&&(X.current=!0,Y.current=!1,clearTimeout(we.current)),_e.current=u,Oe.current!==Ie&&(Y.current=!fe.current),Oe.current=Ie,hr()},[t,r,k.nodes,k.edges,Ie,n,o,s,c,hr,u,l]),_.useEffect(()=>()=>{clearTimeout(se.current),clearTimeout(we.current),nr()},[]);const At=_.useCallback((A,L)=>{var B,H;if(!ne.current&&typeof ResizeObserver<"u"&&(ne.current=new ResizeObserver(ie=>{let ve=!1;for(const Te of ie){const $e=te.current.get(Te.target);if(!$e)continue;const ae=Te.target,ce=ae.offsetWidth,ge=ae.offsetHeight;if(!ce&&!ge)continue;const xe=V.current.get($e);xe&&xe.w===ce&&xe.h===ge||(V.current.set($e,{w:ce,h:ge}),ve=!0)}ve&&hr()})),L){W.current.set(A,L),te.current.set(L,A),(B=ne.current)==null||B.observe(L);const ie=L.offsetWidth,ve=L.offsetHeight;(ie||ve)&&V.current.set(A,{w:ie,h:ve})}else{const ie=W.current.get(A);ie&&((H=ne.current)==null||H.unobserve(ie),te.current.delete(ie)),W.current.delete(A),V.current.delete(A),G.current.has(A)&&N(A,[])}hr()},[hr,N]);_.useEffect(()=>()=>{var A;return(A=ne.current)==null?void 0:A.disconnect()},[]);const oe=_.useMemo(()=>{const A=new Map;for(const L of t)L.label&&A.set(L.id,L.label);return A},[t]),Le=_.useMemo(()=>h_(k.nodes,re,V.current,A=>g(A).padding,A=>{const L=oe.get(A);if(!L)return;const B=g(A);return{w:Pn(L,`bold ${B.fontSize}px ${ot}`)+2*C_,h:0}}),[k.nodes,re,g,oe]),Ye=_.useRef(Le);Ye.current=Le;const Fe=_.useCallback(A=>{const L=Ye.current.get(A);if(L)return R0(L);const B=de.current.get(A);if(!B)return;const H=V.current.get(A)||wu;return{x:B.x,y:B.y,w:H.w,h:H.h}},[]),dr=_.useMemo(()=>{const A=new Map;for(const L of t){const B=Fe(L.id);B&&A.set(L.id,B)}return N0($,A,ee,r,n)},[$,t,re,Le,ee,r,n,Fe]);G.current=dr;const yr=(A,L)=>{var ie;if(!j||L===void 0)return;const B=(ie=dr.get(A))==null?void 0:ie.find(ve=>ve.property===L),H=Fe(A);return B&&!B.anchor&&H?H.y-H.h/2+B.top+B.height/2:void 0},Z=(A,L)=>{var ie,ve;if(L===void 0)return;const B=(ve=(ie=dr.get(A))==null?void 0:ie.find(Te=>Te.property===L))==null?void 0:ve.anchor,H=Fe(A);return B&&H?{x:H.x-H.w/2+B.x,y:H.y-H.h/2+B.y,side:B.side}:void 0},D=(A,L)=>{const B=Fe(A),H=ee.get(A);return B&&H&&!Le.has(A)&&yr(A,L)===void 0?Ut(B,H):B},Q=()=>{const A=[];de.current.forEach((L,B)=>{if(Ye.current.has(B))return;const H=V.current.get(B)||wu;A.push(ht({x:L.x,y:L.y,w:H.w,h:H.h}))}),Ye.current.forEach(L=>A.push(L));try{for(const L of[P.current,I.current]){const B=L==null?void 0:L.getBBox();B&&B.width>0&&B.height>0&&A.push({x1:B.x,y1:B.y,x2:B.x+B.width,y2:B.y+B.height})}}catch{}return to(A)},ke=()=>{var B,H;const{pan:A,zoom:L}=O;q.current&&(q.current.style.transform=`translate3d(${A.x}px, ${A.y}px, 0) scale(${L})`),(B=P.current)==null||B.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`),(H=I.current)==null||H.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`)};_.useEffect(()=>{ke();let A=null,L;const B=O.onChange(()=>{ke();const H=E.current;H&&(H.classList.add("flow-sdk-busy"),clearTimeout(L),L=setTimeout(()=>H.classList.remove("flow-sdk-busy"),150)),A===null&&(A=requestAnimationFrame(()=>{var ie,ve;A=null,(ve=(ie=R.current).onViewportChange)==null||ve.call(ie,O.state)}))});return()=>{B(),clearTimeout(L),A!==null&&cancelAnimationFrame(A)}},[]),_.useLayoutEffect(()=>{const A=E.current;if(!A)return;const L=()=>{let H=A.clientWidth,ie=A.clientHeight;ie||(ie=Math.max(0,window.innerHeight-A.getBoundingClientRect().top-100),ie&&(A.style.height=`${ie}px`)),H||(H=window.innerWidth,H&&(A.style.width=`${H}px`)),O.size={w:H,h:ie},!X.current&&!de.current.size&&R.current.fitOnInit!==!1&&(O.set({x:H/2,y:ie/2}),ke())};if(L(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(L);return B.observe(A),()=>B.disconnect()},[O]),_.useLayoutEffect(()=>{if(lr.current){lr.current=!1;const L=Ze.current.flatMap(H=>{const ie=Fe(H);return ie?[ht(ie)]:[]});Ze.current=[];const B=to(L);if(B){Y.current=!1,O.center(B,R.current.animateViewport);return}}if(!Y.current)return;Y.current=!1;const A=Q();A&&(O.fit(A,50,X.current&&R.current.animateViewport),X.current||ke())},[re]);const Pe=_.useMemo(()=>{const A=ae=>Nl(ae,R.current.nodes,R.current.edges),L=(ae,ce=50,ge=R.current.animateViewport,xe=1)=>{const or=to([...ae].flatMap(Zr=>{const Yr=Fe(Zr);return Yr?[ht(Yr)]:[]}));or&&(Y.current=!1,O.fit(or,Number.isFinite(ce)?Math.max(0,ce):50,ge,xe))},B=(ae,ce,ge,xe)=>{var Zr;if(!Fe(ae))return;const or=ce==="connections"?ie(ae):A(ae);if(ce==="connections"&&tr.current===1.25&&((Zr=De.current)==null?void 0:Zr.size)===or.size&&[...or].every(Yr=>De.current.has(Yr))){C({id:ae,mode:ce});return}he.current||(he.current={pan:{...O.pan},zoom:O.zoom}),De.current=or,R.current.compactPropertyLayout&&(Y.current=!1,fe.current=()=>L(De.current??or,ge,xe)),C({id:ae,mode:ce}),R.current.compactPropertyLayout||L(or,ge,xe)},H=ae=>{fe.current?fe.current=ae:ae()},ie=ae=>Dl(ae,R.current.nodes,R.current.edges),ve=(ae=>{if(ae===void 0)return O.zoom;O.set(void 0,ae)}),Te=(ae=>{if(ae===void 0)return O.pan;O.set(ae)}),$e=(ae,ce)=>{var xe;const ge=(xe=E.current)==null?void 0:xe.getBoundingClientRect();return{x:ae-((ge==null?void 0:ge.left)??0),y:ce-((ge==null?void 0:ge.top)??0)}};return{zoom:ve,pan:Te,setEdgesVisible:er,focusNode:(ae,ce,ge)=>H(()=>L(new Set([ae]),ce,ge,.6)),focusBranch:(ae,ce,ge)=>H(()=>L(A(ae),ce,ge)),focusConnections:(ae,ce,ge)=>H(()=>L(ie(ae),ce,ge)),isolateConnections:(ae,ce,ge)=>B(ae,"connections",ce,ge),isolateBranch:(ae,ce,ge)=>B(ae,"branch",ce,ge),restoreView:(ae=R.current.animateViewport,ce)=>{const ge=R.current.compactPropertyLayout&&!!De.current;De.current=null,C(null);const xe=ce??he.current;he.current=null,ge?fe.current=()=>{xe&&O.transition(xe,ae)}:xe&&H(()=>O.transition(xe,ae))},zoomAt:(ae,ce)=>O.zoomAt(ae,ce),fit:(ae=0,ce=R.current.animateViewport)=>{H(()=>{const ge=Q();ge&&O.fit(ge,ae,ce)})},centerAndFit:(ae=0,ce=R.current.animateViewport)=>{H(()=>{const ge=Q();ge&&O.fit(ge,ae,ce)})},center:(ae=R.current.animateViewport)=>{const ce=Q();ce&&O.center(ce,ae)},clientToModel:(ae,ce)=>O.renderedToModel($e(ae,ce)),modelToClient:ae=>{var xe;const ce=(xe=E.current)==null?void 0:xe.getBoundingClientRect(),ge=O.modelToRendered(ae);return{x:ge.x+((ce==null?void 0:ce.left)??0),y:ge.y+((ce==null?void 0:ce.top)??0)}},getNodeBox:ae=>Fe(ae),setNodePosition:(ae,ce,ge)=>{if(!de.current.has(ae)||ce&&(!Number.isFinite(ce.x)||!Number.isFinite(ce.y)))return!1;if(nr(),!ce)return J.current.delete(ae),hr(),!0;const xe=new Map(de.current);return xe.set(ae,{...ce}),(ge==null?void 0:ge.persist)===!1?J.current.delete(ae):J.current.set(ae,{...ce}),de.current=xe,ye(xe),(ge==null?void 0:ge.persist)===!1&&hr(),!0},onViewportChange:ae=>O.onChange(ae)}},[]);_.useEffect(()=>{var A,L;return(L=(A=R.current).onInit)==null||L.call(A,Pe),()=>O.cancelAnimation()},[Pe]),_.useEffect(()=>{var A,L;if(U>0){const B=fe.current;fe.current=null,B==null||B(),(L=(A=R.current).onLayoutComplete)==null||L.call(A,Pe)}},[Pe,U]);const Ce=_.useRef(null),Be=_.useRef(new Map),We=_.useRef(!1),[Ge,Ke]=_.useState(null),[Ne,ar]=_.useState(null),Er=A=>{const L=E.current.getBoundingClientRect();return{x:A.clientX-L.left,y:A.clientY-L.top}},Lr=(A,L)=>{const B=R.current.nodes;for(let H=B.length-1;H>=0;H--){const ie=B[H].id;if(!pt(ie,R.current.edges,R.current.edgeMode)||De.current&&!De.current.has(ie)||ie===L||Ye.current.has(ie))continue;const ve=Fe(ie);if(ve&&$l(A,ht(ve)))return ie}for(const[H,ie]of Ye.current)if(pt(H,R.current.edges,R.current.edgeMode)&&!(De.current&&!De.current.has(H))&&H!==L&&$l(A,ie))return H;return null},Ir=(A,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 ie=null;for(const ve of[...R.current.nodes].reverse()){if(!pt(ve.id,R.current.edges,R.current.edgeMode)||De.current&&!De.current.has(ve.id))continue;const Te=Fe(ve.id),$e=G.current.get(ve.id);if(!Te||!$e||Ye.current.has(ve.id))continue;const ae=Te.x+(L==="source"!==B?1:-1)*Te.w/2;for(const ce of $e){if(ce.role&&ce.role!==L)continue;const ge=Te.y-Te.h/2+ce.top,xe=Math.hypot(A.x-(ce.anchor?Te.x-Te.w/2+ce.anchor.x:ae),A.y-ge-ce.height/2);if(!ce.anchor&&A.x>=Te.x-Te.w/2&&A.x<=Te.x+Te.w/2&&A.y>=ge&&A.y<=ge+ce.height)return{nodeId:ve.id,property:ce.property};xe<=H&&(!ie||xe<ie.distance)&&(ie={nodeId:ve.id,property:ce.property,distance:xe})}}return ie},lt=A=>{var Te;if(!A.currentTarget.contains(A.target)||A.button!==0||R.current.readOnly)return;Ce.current||(We.current=!1);const L=A.target;if(L.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const B=R.current,H=Er(A);if(A.pointerType==="touch"){Be.current.set(A.pointerId,H);const $e=gy(Be.current);if($e){Ce.current={kind:"pinch",distance:$e.distance,zoom:O.zoom,anchor:O.renderedToModel($e.center)},ar(null),Ke(null),We.current=!0;for(const ae of Be.current.keys())A.currentTarget.setPointerCapture(ae);return}}if(Ce.current)return;const ie=B.drawHandles&&L.closest(".flow-sdk-handle"),ve=B.drawHandles&&L.closest(".flow-sdk-property-port");if(B.drawMode||ie||ve){const $e=O.renderedToModel(H),ae=B.drawMode?Ir($e,"source"):null,ce=ve||ie,ge=ce?(Te=ce.closest("[data-node-id]"))==null?void 0:Te.dataset.nodeId:(ae==null?void 0:ae.nodeId)??Lr($e),xe=ve?ve.dataset.property:ae==null?void 0:ae.property;if(ge){Ce.current={kind:"draw",pointerId:A.pointerId,source:ge,sourceProperty:xe,reverse:(ve==null?void 0:ve.dataset.portRole)==="target",startClient:{x:A.clientX,y:A.clientY}},We.current=!0,ar({source:ge,sourceProperty:xe,point:$e,target:null}),A.currentTarget.setPointerCapture(A.pointerId);return}}L.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(B.multiSelect?Ce.current={kind:"box",pointerId:A.pointerId,start:H,current:H}:B.dragMode?Ce.current={kind:"pan",pointerId:A.pointerId,start:H,pan0:O.pan,moved:!1}:Ce.current={kind:"tap",pointerId:A.pointerId,start:H,moved:!1},A.currentTarget.setPointerCapture(A.pointerId))},Kb=A=>{const L=Ce.current;if(!L||R.current.readOnly)return;const B=Er(A);if(Be.current.has(A.pointerId)&&Be.current.set(A.pointerId,B),L.kind==="pinch"){const H=gy(Be.current);if(!H)return;const ie=Math.max(O.minZoom,Math.min(O.maxZoom,L.zoom*H.distance/L.distance));O.set({x:H.center.x-L.anchor.x*ie,y:H.center.y-L.anchor.y*ie},ie);return}if(L.pointerId===A.pointerId)switch(L.kind){case"pan":{const H=B.x-L.start.x,ie=B.y-L.start.y;if(!L.moved&&Math.hypot(H,ie)<=hy)return;L.moved=!0,We.current=!0,O.set({x:L.pan0.x+H,y:L.pan0.y+ie});break}case"tap":{Math.hypot(B.x-L.start.x,B.y-L.start.y)>hy&&(L.moved=!0);break}case"box":{We.current=!0,L.current=B,Ke({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),ie=Ir(H,L.reverse?"source":"target");ar(L.reverse&&ie?{source:ie.nodeId,sourceProperty:ie.property,point:H,target:L.source,targetProperty:L.sourceProperty}:{source:L.source,sourceProperty:L.sourceProperty,point:H,target:(ie==null?void 0:ie.nodeId)??Lr(H,L.source),targetProperty:ie==null?void 0:ie.property});break}}},dl=(A,L)=>{var ie,ve,Te,$e,ae;Be.current.delete(A.pointerId);const B=Ce.current;if(!B)return;if(B.kind==="pinch"){const ce=[...Be.current][0];Ce.current=ce&&R.current.dragMode&&!L?{kind:"pan",pointerId:ce[0],start:ce[1],pan0:O.pan,moved:!0}:null;return}if(B.pointerId!==A.pointerId)return;Ce.current=null;try{A.currentTarget.releasePointerCapture(A.pointerId)}catch{}const H=R.current;switch(L=L||!!H.readOnly,B.kind){case"pan":case"tap":!L&&!B.moved&&((ie=H.onBackgroundTap)==null||ie.call(H));break;case"box":{if(Ke(null),L)break;const ce=O.renderedToModel(B.start),ge=O.renderedToModel(B.current),xe={x1:Math.min(ce.x,ge.x),y1:Math.min(ce.y,ge.y),x2:Math.max(ce.x,ge.x),y2:Math.max(ce.y,ge.y)};if(xe.x2-xe.x1<1&&xe.y2-xe.y1<1){(ve=H.onBackgroundTap)==null||ve.call(H);break}const or=[];for(const Zr of H.nodes){const Yr=Fe(Zr.id);Yr&&k0(ht(Yr),xe)&&or.push(Zr.id)}or.length&&((Te=H.onBoxSelect)==null||Te.call(H,or));break}case"draw":{if(ar(null),L)break;const ce=Er(A),ge=O.renderedToModel(ce),xe=Ir(ge,B.reverse?"source":"target"),or=(xe==null?void 0:xe.nodeId)??Lr(ge);if(or===B.source&&(B.sourceProperty===void 0||(xe==null?void 0:xe.property)===void 0||xe.property===B.sourceProperty))break;or?($e=H.onEdgeDraw)==null||$e.call(H,B.reverse?or:B.source,B.reverse?B.source:or,B.sourceProperty!==void 0||(xe==null?void 0:xe.property)!==void 0?{sourceProperty:B.reverse?xe==null?void 0:xe.property:B.sourceProperty,targetProperty:B.reverse?B.sourceProperty:xe==null?void 0:xe.property}:void 0):Math.max(Math.abs(A.clientX-B.startClient.x),Math.abs(A.clientY-B.startClient.y))>x_&&((ae=H.onDrawIntoSpace)==null||ae.call(H,B.source,ge,B.sourceProperty,B.reverse));break}}},Jr=_.useCallback(()=>{var B;const A=Ce.current,L=[...Be.current.keys()];A&&A.kind!=="pinch"&&L.push(A.pointerId),Ce.current=null,Be.current.clear(),ar(null),Ke(null);for(const H of L)(B=E.current)!=null&&B.hasPointerCapture(H)&&E.current.releasePointerCapture(H)},[]);_.useEffect(()=>{const A=L=>{L.key==="Escape"&&Jr()};return window.addEventListener("keydown",A),window.addEventListener("blur",Jr),()=>{window.removeEventListener("keydown",A),window.removeEventListener("blur",Jr),Ce.current=null,Be.current.clear()}},[Jr]),_.useEffect(()=>{Jr()},[y,v,b,i,n,e.drawHandles,e.readOnly,Jr]);const Jb=_.useMemo(()=>{const A=new Map,L=new Map;for(const B of T){if(B.source!==B.target)continue;const H=A.get(B.source)??0;A.set(B.source,H+1),L.set(B.id,H)}return L},[T]),Jn=v_[n],[Zn,Zb]=_.useState(null),Yn=m_(t,T,!!((pl=e.edgeReveal)!=null&&pl.revealNodes));_.useLayoutEffect(()=>{E.current&&Zn&&K0(E.current)});const Xn=j0(T,D,Jn),Yb=e.onEdgeSelect,Xb=e.onContainerSelect,fl=Ne?Ne.target&&D(Ne.target,Ne.targetProperty)||{x:Ne.point.x,y:Ne.point.y,w:1,h:1}:null,hl=Ne?D(Ne.source,Ne.sourceProperty):null,Qb=["flow-sdk-canvas",y?"flow-sdk-draw":"",w?"flow-sdk-perf":""].filter(Boolean).join(" ");return f.jsxs("div",{ref:E,className:Qb,"data-edge-mode":i,onPointerDownCapture:lt,onPointerMove:Kb,onPointerUp:A=>dl(A,!1),onPointerCancel:A=>dl(A,!0),onLostPointerCapture:A=>{const L=Ce.current;L&&(L.kind==="pinch"||L.pointerId===A.pointerId)&&Jr()},onClickCapture:A=>{A.currentTarget.contains(A.target)&&(We.current||e.readOnly)&&(A.preventDefault(),A.stopPropagation())},children:[f.jsx("svg",{className:"flow-sdk-svg",children:f.jsxs("g",{ref:P,children:[f.jsx("g",{className:"flow-sdk-containers",children:[...Le].filter(([A])=>pt(A,r,i)).filter(([A])=>!S||S.has(A)).map(([A,L])=>{var B;return f.jsx(B0,{id:A,rect:L,label:oe.get(A),labelLayer:Zn,style:g(A),onSelect:Xb,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(B=e.selectedNodeIds)==null?void 0:B.includes(A)},A)})}),f.jsx("g",{className:"flow-sdk-edges",children:Ue&&T.map(A=>{var H,ie,ve;if(!Yn.ready.has(A.id)||S&&(!S.has(A.source)||!S.has(A.target)))return null;const L=D(A.source,A.sourceProperty),B=D(A.target,A.targetProperty);return!L||!B?null:f.jsx(Vl,{id:A.id,edgeData:A.data,validationIssue:A.validationIssue,edgeType:A.type,edgeRadius:e.edgeRadius,propertyMode:j,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:Yn.complete,source:L,target:B,sourceProperty:A.sourceProperty,targetProperty:A.targetProperty,sourceY:yr(A.source,A.sourceProperty),targetY:yr(A.target,A.targetProperty),sourcePort:Z(A.source,A.sourceProperty),targetPort:Z(A.target,A.targetProperty),dir:Jn,turn:((H=Xn.get(A.id))==null?void 0:H.turn)??A.turn,labelAtTarget:(ie=Xn.get(A.id))==null?void 0:ie.labelAtTarget,labelFraction:(ve=Xn.get(A.id))==null?void 0:ve.labelFraction,color:A.color,connectorColor:A.connectorColor,labelBg:A.labelBg,label:A.label,labelLayer:Zn,dashed:A.dashed,animated:A.animated&&!w,inverted:A.inverted,loopIndex:Jb.get(A.id)??0,onSelect:Yb},A.id)})}),Ue&&Ne&&Pu(Ne,i)&&hl&&fl&&f.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:f.jsx(Vl,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:Ne.source,target:Ne.target??"",sourceProperty:Ne.sourceProperty,targetProperty:Ne.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:j,customEdgeTypes:e.customEdgeTypes,source:hl,target:fl,sourceProperty:Ne.sourceProperty,targetProperty:Ne.targetProperty,sourceY:yr(Ne.source,Ne.sourceProperty),sourcePort:Z(Ne.source,Ne.sourceProperty),targetPort:Ne.target?Z(Ne.target,Ne.targetProperty):void 0,targetY:Ne.target?yr(Ne.target,Ne.targetProperty):void 0,dir:Jn,turn:.5,color:m,labelBg:m})})]})}),f.jsx("div",{ref:q,className:"flow-sdk-nodes",children:t.map(A=>{var ve,Te;const L=re.get(A.id),B=Le.get(A.id),H=(L==null?void 0:L.x)??(B?(B.x1+B.x2)/2:0),ie=(L==null?void 0:L.y)??(B?(B.y1+B.y2)/2:0);return f.jsx(y_,{id:A.id,x:H,y:ie,placed:!!L||!!B,hidden:!Yn.shown.has(A.id)||!pt(A.id,r,i)||!!S&&!S.has(A.id),onMount:At,drawHandles:e.drawHandles&&!e.readOnly,drawMode:y,connectedPorts:new Set(T.flatMap($e=>[...$e.source===A.id&&$e.sourceProperty!==void 0?[`source:${$e.sourceProperty}`]:[],...$e.target===A.id&&$e.targetProperty!==void 0?[`target:${$e.targetProperty}`]:[]])),hasCollapseControl:A.hasCollapseControl,handleColor:m,animated:A.animated&&!B&&!w,animationColor:A.animationColor,animationWidth:A.animationWidth,animationVariant:A.animationVariant,width:(ve=V.current.get(A.id))==null?void 0:ve.w,height:(Te=V.current.get(A.id))==null?void 0:Te.h,propertyMode:j,resolvedRows:dr.get(A.id),reversePorts:n==="RL",direction:n,onPropertyRows:N,onSurface:le,children:A.element},A.id)})}),Ge&&f.jsx("div",{className:"flow-sdk-box",style:{left:Ge.x1,top:Ge.y1,width:Ge.x2-Ge.x1,height:Ge.y2-Ge.y1}}),f.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:f.jsx("g",{ref:I,transform:`translate(${O.pan.x} ${O.pan.y}) scale(${O.zoom})`,children:f.jsx("g",{ref:Zb,className:"flow-sdk-labels",style:{pointerEvents:y?"none":"visiblePainted",outline:"none"}})})})]})}const E_=_.memo(S_);function Fb({id:e,label:t,role:r,side:n,position:o=.5,placement:i,children:a,style:s}){return f.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",...s,...n?{display:"none"}:{}},children:a??t??e})}const j_=Cn.default.dialog`
210
210
  ${e=>Vr(e.$surface,e.$border)}
211
211
  &,
212
212
  &:hover {
@@ -231,7 +231,7 @@
231
231
  & *::-webkit-scrollbar {
232
232
  display: none;
233
233
  }
234
- `,R_=wn.default.div`
234
+ `,R_=Cn.default.div`
235
235
  min-height: 0;
236
236
  container-type: inline-size;
237
237
  @container (min-width: 520px) {
@@ -276,5 +276,5 @@
276
276
  black calc(100% - 32px),
277
277
  transparent
278
278
  );
279
- `;function Fb({nodeAddress:e,active:t,label:r,open:n=!1,onClose:o,children:i,filter:a,height:s}){const{background:c,border:u,colorText:l}=Ye(),{colorMode:d}=$e(),f=_.useRef(null),p=_.useId(),{data:y,schema:g,bindings:b}=_.useContext(xr),x=i!==void 0||!!(y&&g&&(b?nn(b,e,g):_t(y,e,g)));_.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(c);return x?h.jsx(h.Fragment,{children:typeof document<"u"&&Ht.createPortal(h.jsx(j_,{ref:f,id:p,$surface:m,$border:me(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:s,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"})})]}),a&&h.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:a}),h.jsx(R_,{$divider:`var(--chakra-colors-gray-${d==="dark"?"700":"200"})`,"data-form-scroll":"",style:s?{flex:1}:void 0,children:i??h.jsx(lm,{nodeAddress:e})})]})}),document.body)}):null}const Pu=({icon:e,label:t,onClick:r,color:n,boxSize:o=6,...i})=>{const{background:a,border:s,colorText:c}=Ye();return h.jsx(Te,{label:t,children:h.jsx(B.Flex,{children:h.jsx(B.Icon,{as:e,boxSize:o,color:n,cursor:r?"pointer":void 0,onClick:r})})})},k_=({data:e,children:t,isInverted:r,isParent:n,onOpenView:o,editOnMount:i=!1})=>{var N,ee,ye,fe,J,Y;const{selectedNodeIds:a,setSelectedNodeIds:s,selectedEdgeId:c,setSelectedEdgeId:u,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=_.useRef(null),S=_.useRef(null),[j,T]=_.useState(!1),[P,M]=_.useState(i&&!!y.editable&&!y.readOnly),[R,E]=_.useState(!1),k=e==null?void 0:e.id,I=dm(k),q=a.includes(k),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=_.useCallback(U=>{var te,xe,ge,De;if(P||y.readOnly)return;const se={shiftKey:U.shiftKey,ctrlKey:U.ctrlKey,metaKey:U.metaKey,altKey:U.altKey};if(c&&(u(null),(te=p.onEdgeDeselect)==null||te.call(p)),l){const Z=a.includes(k),de=Z?a.filter(Ce=>Ce!==k):[...a,k];s(de),Z?(xe=p.onNodeDeselect)==null||xe.call(p):(ge=p.onNodeSelect)==null||ge.call(p,k,e,se)}else s([k]),(De=p.onNodeSelect)==null||De.call(p,k,e,se)},[k,e,a,c,l,P,s,u,p,y]),ne=_.useCallback(()=>{var U;P||y.readOnly||(U=p.onNodeDoubleClick)==null||U.call(p,k,e)},[k,e,P,p,y]),Q=_.useCallback(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>T(!0),100)},[]),pe=_.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||P||!U.currentTarget.contains(U.target)||U.target instanceof Element&&U.target.closest("button, input, textarea, select, a, [contenteditable=true]")||(U.preventDefault(),U.stopPropagation(),s([k]),o?o():E(!0),(se=p.onNodeDoubleClick)==null||se.call(p,k,e))},onKeyDown:U=>{!le&&!o||y.readOnly||U.target!==U.currentTarget||U.key!=="Enter"||(U.preventDefault(),U.stopPropagation(),s([k]),o?o():E(!0))}},D=le&&h.jsx(Fb,{nodeAddress:k,active:q,label:e.label||e.headerTitle||"Node",open:R,onClose:()=>{var U;E(!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(Lb,{...U},`${U.id}:${U.role}`)):null;return n?h.jsxs(B.Box,{ref:C,...$,onClick:ue,onDoubleClick:ne,onMouseEnter:Q,onMouseLeave:pe,cursor:"pointer",position:"relative",children:[D,!d&&(W||O&&O.length>0)&&j&&!V&&h.jsxs(h.Fragment,{children:[h.jsx(B.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>T(!0),onMouseLeave:pe}),W?h.jsx(B.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>T(!0),onMouseLeave:pe,willChange:"transform",children:W({nodeId:k,nodeData:e,isRoot:k==="root",isParent:!0,isHovered:j,setIsHovered:T})}):h.jsx(B.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:pe,willChange:"transform",children:h.jsx(B.HStack,{px:2,gap:2,children:O.map((U,se)=>h.jsxs(B.Box,{display:"contents",children:[se>0&&h.jsx(B.Box,{borderColor:w,height:5,borderRightWidth:1}),h.jsx(Pu,{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,k,e)}})]},U.id))})})]}),t({id:k,data:e,isActive:q,isLowZoom:V,isEditing:P,onEditStart:()=>M(!0),onEditEnd:()=>M(!1)}),I&&!((ye=e==null?void 0:e.config)!=null&&ye.parentContainer)&&((fe=e==null?void 0:e.config)==null?void 0:fe.collapsed)!==void 0&&(()=>{var te;const U=b==="TB"||b==="BT",se=r||b==="RL";return h.jsx(B.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 ge;xe.stopPropagation(),(ge=p.onNodeCollapse)==null||ge.call(p,k,!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(K.PiPlusBold,{size:30,color:me("gray.800")}):h.jsx(K.PiMinusBold,{size:30,color:me("gray.800")})})})()]}):h.jsxs(B.Box,{ref:C,...$,onClick:ue,onDoubleClick:ne,onMouseEnter:Q,onMouseLeave:pe,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(B.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>T(!0),onMouseLeave:pe}),W?h.jsx(B.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>T(!0),onMouseLeave:pe,willChange:"transform",children:W({nodeId:k,nodeData:e,isRoot:k==="root",isParent:!!n,isHovered:j,setIsHovered:T})}):h.jsx(B.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:pe,willChange:"transform",children:h.jsx(B.HStack,{px:2,gap:2,children:O.map((U,se)=>h.jsxs(B.Box,{display:"contents",children:[se>0&&h.jsx(B.Box,{borderColor:w,height:5,borderRightWidth:1}),h.jsx(Pu,{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,k,e)}})]},U.id))})})]}),h.jsxs(B.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[I&&!((J=e==null?void 0:e.config)!=null&&J.parentContainer)&&((Y=e==null?void 0:e.config)==null?void 0:Y.collapsed)!==void 0&&!n&&(()=>{var xe,ge,De;const U=b==="TB"||b==="BT",se=r||b==="RL",te=(xe=e==null?void 0:e.config)!=null&&xe.labelBelow&&x[k]!=="properties"?((((ge=e==null?void 0:e.viewProps)==null?void 0:ge.fontSize)||1)*100+100)/2:void 0;return h.jsx(B.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,k,!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(K.PiPlusBold,{size:30,color:me("gray.800")}):h.jsx(K.PiMinusBold,{size:30,color:me("gray.800")})})})(),t({id:k,data:e,isActive:q,isLowZoom:V,isEditing:P,onEditStart:()=>M(!0),onEditEnd:()=>M(!1)})]})]})},Un=_.memo(k_);function cl(e=!0){const t=_.useRef(null);return _.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:a,onEditStart:s,onEditEnd:c})=>{const{callbacks:u,config:l,readOnly:d}=$e(),f=l.editable&&!d,[p,y]=_.useState(t),[g,b]=_.useState(),x=_.useRef(null),m=_.useRef(!1),w=cl(a);_.useEffect(()=>{a&&(m.current=!1,x.current&&(x.current.focus(),x.current.select()))},[a]);const v=()=>{var S;if(m.current)return;m.current=!0;const C=p.trim();C&&C!==t&&((S=u.onNodeLabelChange)==null||S.call(u,e,C)),c()};return!f||!a?h.jsx(B.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),s()}: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(B.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),h.jsx(B.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"})]})},P_=({id:e,data:t,isActive:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var g,b,x,m,w,v,C,S;const{themeColor:a}=$e(),{colorText:s}=Ye(),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,{highlightColor:l,borderColor:d,textColor:f}=tn(((x=t==null?void 0:t.viewProps)==null?void 0:x.bgColor)||a),p=me(((m=t==null?void 0:t.viewProps)==null?void 0:m.textColor)||(c||u?s: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)||a:d);return h.jsx(B.Box,{"data-flow-node-surface":"",borderRadius:(C=t==null?void 0:t.viewProps)==null?void 0:C.borderRadius,bgColor:u?"transparent":l,...mn(t==null?void 0:t.viewProps,y,r,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:h.jsxs(B.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(B.Box,{flexShrink:0,children:h.jsx(Pr,{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 A_=({id:e,isActive:t,data:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var w,v,C,S,j,T,P,M,R,E,k,I,q,O,W;const{themeColor:a}=$e(),{colorText:s}=Ye(),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)||a,{borderColor:d,highlightColor:f,textColor:p}=tn(l),y=me(((S=r==null?void 0:r.viewProps)==null?void 0:S.textColor)||(c||u?s:p)),g=c&&!u&&!((j=r==null?void 0:r.viewProps)!=null&&j.borderColor)?"transparent":me(((T=r==null?void 0:r.viewProps)==null?void 0:T.borderColor)||(u?l:d)),b=c||u?"transparent":l!=null&&l.startsWith("#")?l:me(f),x=(P=r==null?void 0:r.config)==null?void 0:P.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(B.Flex,{"data-flow-icon-label":"",direction:"column",align:"center",gap:"24px",width:`${Math.max(V+200,360)}px`,position:"relative",children:[h.jsx(B.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${V+100}px`,height:`${V+100}px`,flexShrink:0,borderRadius:(E=r==null?void 0:r.viewProps)==null?void 0:E.borderRadius,backgroundColor:b,...mn(r==null?void 0:r.viewProps,g,t,2),children:!!x&&h.jsx(Pr,{name:x,size:V,color:y})}),h.jsxs(B.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(((k=r==null?void 0:r.viewProps)==null?void 0:k.textColor)||s),isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0}),typeof((I=r.config)==null?void 0:I.subtitle)=="string"&&r.config.subtitle!==""&&h.jsx(B.Text,{"data-flow-node-subtitle":"",color:me(((q=r==null?void 0:r.viewProps)==null?void 0:q.textColor)||s),opacity:.65,fontSize:"32px",fontWeight:"normal",lineHeight:1.3,width:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",title:r.config.subtitle,children:r.config.subtitle})]})]})}return h.jsxs(B.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(B.Flex,{align:"center",py:14,mr:m?8:0,flexShrink:0,children:h.jsx(Pr,{name:x,size:(((W=r==null?void 0:r.viewProps)==null?void 0:W.fontSize)||1)*100,color:y},y)}),(m||!x)&&h.jsx(B.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 Bb({onExpand:e,toggleLabel:t="Show properties",toggleDisabled:r=!1,renderCompact:n=A_,...o}){const{colorMode:i,callbacks:a}=$e();return h.jsx(Un,{...o,children:s=>h.jsxs(B.Box,{position:"relative",children:[h.jsx(n,{...s}),e&&s.isActive&&h.jsx(B.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:h.jsx(Te,{label:t,children:h.jsx(_e,{"aria-label":t,icon:h.jsx(B.Icon,{as:K.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=a.onNodeViewToggle)==null||u.call(a,o.data.id)}})})})]})})}const gy=1.55;function T_({nodeId:e,content:t,color:r}){const{callbacks:n,config:o,readOnly:i}=$e(),a=!!o.editable&&!i,[s,c]=_.useState(!1),[u,l]=_.useState(t),[d,f]=_.useState(),p=_.useRef(null),y=_.useRef(!1),g=cl(s);_.useLayoutEffect(()=>{const m=p.current;!s||!m||(m.style.height="auto",m.style.height=`${Math.max((d==null?void 0:d.height)??0,m.scrollHeight)}px`)},[u,s,d]),_.useEffect(()=>{var m;a?s&&(y.current=!1,(m=p.current)==null||m.focus()):c(!1)},[s,a]);const b=m=>{a&&(f({width:m.offsetWidth,height:m.offsetHeight}),l(t),c(!0))},x=()=>{var m;y.current||!a||(y.current=!0,u!==t&&((m=n.onNodeContentChange)==null||m.call(n,e,u)),c(!1))};return!s||!a?h.jsx(B.Box,{"data-flow-content":"",color:r,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:gy,overflowWrap:"anywhere",css:{"& > :first-of-type":{marginTop:0},"& > :last-of-type":{marginBottom:0},"& h1, & h2, & h3, & h4, & h5, & h6":{fontWeight:700,lineHeight:1.2,margin:"1em 0 0.45em"},"& h1":{fontSize:"1.5em"},"& h2":{fontSize:"1.3em"},"& h3":{fontSize:"1.1em"},"& p":{margin:"0.65em 0",whiteSpace:"pre-wrap"},"& ul, & ol":{margin:"0.65em 0",paddingInlineStart:"1.6em"},"& ul":{listStyleType:"disc"},"& ol":{listStyleType:"decimal"},"& li":{display:"list-item",margin:"0.3em 0",paddingInlineStart:"0.15em"},"& li > ul, & li > ol":{margin:"0.25em 0"},"& li > p":{margin:0},"& a":{color:"inherit",textDecoration:"underline"},"& code":{fontFamily:"monospace",fontSize:"0.85em"},"& :not(pre) > code":{background:"color-mix(in srgb, currentColor 10%, transparent)",padding:"0.1em 0.25em",borderRadius:"0.2em"},"& pre":{margin:"0.75em 0",padding:"0.75em",background:"color-mix(in srgb, currentColor 8%, transparent)",border:0,borderRadius:"6px",maxWidth:"100%",overflowX:"auto",whiteSpace:"pre",overflowWrap:"normal",lineHeight:1.5},"& pre code":{background:"transparent",padding:0,whiteSpace:"inherit"},"& strong":{fontWeight:700},"& em":{fontStyle:"italic"},"& blockquote":{margin:"0.4em 0",borderInlineStart:"0.1em solid currentColor",paddingInlineStart:"0.6em"},"& table":{width:"100%",tableLayout:"fixed",borderCollapse:"collapse",margin:"0.4em 0"},"& th, & td":{border:"1px solid currentColor",padding:"0.2em 0.3em",textAlign:"left"},"& th":{fontWeight:700},"& img":{maxWidth:"100%",height:"auto"}},cursor:a?"text":void 0,tabIndex:a?0:void 0,onDoubleClick:m=>{m.stopPropagation(),b(m.currentTarget)},onKeyDown:m=>{a&&m.key==="Enter"&&m.target===m.currentTarget&&(m.preventDefault(),m.stopPropagation(),b(m.currentTarget))},children:h.jsx(lv.default,{options:{forceBlock:!0,wrapper:_.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(B.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:gy,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 I_=(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),a=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,s=n==="transparent"||a,c=r==="dark"?"gray.200":"gray.900",u=s?"transparent":n!=null&&n.startsWith("#")?me(n):me(i.bgColor),l=me(((y=e==null?void 0:e.viewProps)==null?void 0:y.textColor)||(s?c:i.textColor)),d=me(((g=e==null?void 0:e.viewProps)==null?void 0:g.borderColor)||(a?n==="transparent"?t:n:i.borderColor));return{...i,bgColor:s?"transparent":i.bgColor,highlightColor:s?"transparent":i.highlightColor,isTransparent:s,propertyColor:s?c:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:u,hextextColor:l,hexborderColor:d}},O_=(e,t=350)=>`${String(e).substring(0,t)}${String(e).length>t?"...":""}`,M_=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,zb=600,q_=3,N_=e=>{const t=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(t*28+30,200)};function $_({headerTitle:e,hasContent:t,data:r,icon:n,colors:o,hasConfig:i,id:a,isActive:s,isEditing:c,onEditStart:u,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)||s&&y)&&h.jsxs(B.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(B.Flex,{mr:6,alignItems:"center",flexShrink:0,children:h.jsx(Pr,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),h.jsx(rn,{nodeId:a,label:M_(e),color:((w=r==null?void 0:r.viewProps)==null?void 0:w.textColor)||o.propertyColor,isEditing:c,onEditStart:u,onEditEnd:l}),s&&(t||b)&&h.jsx(B.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:h.jsx(Te,{label:x,children:h.jsx(_e,{"aria-label":x,icon:h.jsx(B.Icon,{as:K.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,a)}})})})]})})}function L_({data:e,resourcePorts:t,inspecting:r,form:n,inspectionPorts:o,extraPorts:i,colors:a,direction:s,uniformKeyWidth:c}){const{edgeById:u}=Hr(),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(B.Box,{children:Object.entries(e.description||{}).map(([d,f],p)=>{var k,I,q;const y=t&&Object.keys(t).find(O=>O.slice(O.indexOf(":")+1)===d),g=r&&((k=n==null?void 0:n.type.ports)==null?void 0:k[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"!=(s==="RL")?"right":"left":void 0),P=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=kr(a.wordBeforeDot)[typeof f],E=kr(a.wordBeforeDot).property;return h.jsxs(B.Box,{"data-flow-property":y&&(s==="TB"||s==="BT")?void 0:b,"data-flow-port-role":m,"data-flow-inspection-row":r?"":void 0,children:[h.jsxs(B.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[h.jsx(B.Flex,{justifyContent:"start",align:"center",background:a.highlightColor,width:S?"100%":`${c}px`,minWidth:`${c}px`,borderRightColor:a.hexborderColor,borderRightWidth:S?0:1,children:h.jsx(B.Text,{py:5,px:10,w:"100%",textAlign:P,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((I=e==null?void 0:e.viewProps)==null?void 0:I.textColor)||(a.isTransparent?a.hextextColor:E),children:M})}),!S&&h.jsx(B.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:a.hexbgColor,w:zb,maxH:200,children:h.jsx(B.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)||(a.isTransparent?a.hextextColor:R),fontWeight:400,children:O_(f)})})]}),p!==Object.entries(e.description||{}).length-1&&h.jsx(B.Box,{borderTopWidth:1,my:0,borderColor:a.hexborderColor})]},d)})})}function F_(e){var w,v,C;const{themeColor:t,colorMode:r,direction:n}=$e(),o=Hn(),i=o.getNodeViewMode(e.data.id)==="properties",a=S=>o.setNodeViewMode(e.data.id,S?"properties":"default"),s=!!e.onShowIcon||i||typeof((w=e.data.config)==null?void 0:w.content)!="string",{bindings:c,data:u,schema:l}=_.useContext(xr),d=(v=c==null?void 0:c[e.data.id])==null?void 0:v.portResources,f=c?nn(c,e.data.id,l):u&&l?_t(u,e.data.id,l):void 0,p=f&&je(u,"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,u)}).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(u,j))==null?void 0:T.name)??j.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:y,b=s&&!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:a,inspecting:s,resourcePorts:d,form:f,description:m,inspectionPorts:b,extraPorts:x}}const ul=e=>{var b,x,m;const{themeColor:t,colorMode:r,direction:n,objVisible:o,setObjVisible:i,inspecting:a,resourcePorts:s,form:c,description:u,inspectionPorts:l,extraPorts:d}=F_(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(Bb,{...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:u},children:({id:w,data:v,isActive:C,isEditing:S,onEditStart:j,onEditEnd:T})=>{var V,ue,ne,Q,pe,le;const P=I_(v,t,r),M=v.label??v.headerTitle,R=Object.entries(v.description||{}).length>0,E=N_(v.description),k=(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=((pe=v==null?void 0:v.viewProps)==null?void 0:pe.borderRadius)??"53px",W=mn(v==null?void 0:v.viewProps,P.hexborderColor,C,q_);return h.jsx(B.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:P.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:"100%",minW:q||e.onShowIcon?E+zb+W.borderWidth*2:void 0,...W,children:h.jsxs(B.Flex,{width:"100%",direction:"column",borderRadius:O,borderColor:P.hexborderColor,borderWidth:0,overflow:"hidden",children:[h.jsx($_,{headerTitle:M,hasContent:q,data:v,icon:k,colors:P,hasConfig:R,id:w,isActive:C,isEditing:S,onEditStart:j,onEditEnd:T,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:g}),q&&!o?h.jsx(B.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:P.highlightColor,p:12,fontSize:"5xl",lineHeight:"normal",children:h.jsx(T_,{nodeId:w,content:I,color:((le=v==null?void 0:v.viewProps)==null?void 0:le.textColor)||P.hextextColor})}):h.jsx(L_,{data:v,resourcePorts:s,inspecting:a,form:c,inspectionPorts:l,extraPorts:d,colors:P,direction:n,uniformKeyWidth:E})]})})}})};ul.displayName="NodeJsonObjectView";const Db=e=>{var y,g,b,x,m,w,v,C,S,j,T;const t=Hn(),[r,n]=_.useState(!1),o=t.getNodeViewMode(e.data.id)==="properties",i=P=>{n(P),t.setNodeViewMode(e.data.id,P?"properties":"default")},{callbacks:a,readOnly:s,selectedNodeIds:c}=$e(),u=(g=(y=e.data)==null?void 0:y.config)==null?void 0:g.parentContainer,l=c.includes(e.data.id),d=_.useRef(l);_.useEffect(()=>{var P,M;d.current&&!l&&o&&((M=(P=e.data)==null?void 0:P.config)!=null&&M.labelBelow)&&!u&&!s&&i(!1),d.current=l},[l,o,(x=(b=e.data)==null?void 0:b.config)==null?void 0:x.labelBelow,u,s]);const f=u?"Show parent":"Show properties",p=u||((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!u&&p&&o?h.jsx(ul,{...e,editOnMount:r,onShowIcon:()=>i(!1)}):h.jsx(Bb,{...e,onOpenView:!u&&p&&((T=(j=e.data)==null?void 0:j.config)!=null&&T.labelBelow)?()=>{var P;i(!0),(P=a.onNodeViewToggle)==null||P.call(a,e.data.id)}:void 0,toggleLabel:f,toggleDisabled:u&&s,onExpand:p?()=>{var P;u?(P=a.onNodeCollapse)==null||P.call(a,e.data.id,!1):i(!0)}:void 0})},Vb=e=>h.jsx(Db,{...e,renderCompact:P_}),Wb=e=>h.jsx(Db,{...e}),Gb=e=>h.jsx(Un,{...e,children:()=>null});Vb.displayName="text";Wb.displayName="arrayView";Gb.displayName="ParentContainerView";const B_={objectView:ul,arrayView:Wb,text:Vb,parentContainer:Gb},z_=({children:e,pattern:t="dot",backgroundColor:r})=>{const{colorMode:n}=$e(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",a=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return t==="none"?h.jsx(B.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:r,children:e}):h.jsxs(B.Box,{"data-flow-background":t,position:"relative",width:"100%",height:"100%",padding:0,bg:r,children:[h.jsx(B.Box,{position:"absolute",top:0,left:0,right:0,bottom:0,width:"100%",height:"100%",zIndex:0,pointerEvents:"none",style:{backgroundImage:t==="dot"?`radial-gradient(var(${i}) 8%, transparent 8%)`:t==="steel"?`repeating-linear-gradient(45deg, var(${a}) 0, var(${a}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${a}) 1px, transparent 1px), linear-gradient(90deg, var(${a}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),h.jsx(B.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},D_=.4,Xr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},V_=({nodes:e,edges:t})=>{const{themeColor:r,spacing:n,edgeRadius:o,backgroundVariant:i,setBackgroundSelected:a,edgeColor:s,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:S,setIsZoomMode:j,isMultiSelectMode:T,setIsMultiSelectMode:P,isDragMode:M,setIsDragMode:R,isEdgeHandlesEnabled:E,setIsEdgeHandlesEnabled:k,isArrayNodeMode:I}=$e(),q=_.useRef(null),[O,W]=_.useState(null),V=e.length>200;_.useEffect(()=>{C(V)},[V,C]);const{edgeSep:ue,rankSep:ne,spacingFactor:Q}=_.useMemo(()=>{const re=E0(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:pe}=tn(r),{canvas:le,borderSecondary:$,colorText:D}=Ye(),G=i==="transparent"?"transparent":b.backgroundColor||le,N=_.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",ye=ee?me("gray.500"):wt,fe=ee?pe!=null&&pe.includes("gray")?"whitesmoke":N(pe):ye,J=s?N(s):ye,Y=_.useMemo(()=>b.initialViewport||{pan:{x:0,y:0},zoom:.01},[]),U=c==="C"?"LR":c,se=_.useCallback(re=>{const F={...p,...re};return{...F,bgColor:F.bgColor||r,bgOpacity:F.outline?0:F.bgOpacity??D_}},[p,r]),te=_.useMemo(()=>{var F;const re=new Map;for(const X of e)(F=X.data)!=null&&F.id&&re.set(X.data.id,X);return re},[e]),xe=_.useMemo(()=>{var F;const re=new Map;for(const X of t)(F=X.data)!=null&&F.id&&re.set(X.data.id,X);return re},[t]),ge=_.useCallback(re=>{var Pe;const F=(Pe=te.get(re))==null?void 0:Pe.data,X=se(F==null?void 0:F.viewProps),Re=me(X.bgColor);return{animated:!!(F!=null&&F.isNodeAnimated)&&!V,animationVariant:F==null?void 0:F.nodeAnimationVariant,animationColor:me(X.borderColor||r),bgColor:X.outline?"transparent":Re,bgOpacity:X.bgOpacity,borderColor:X.borderColor?me(X.borderColor):X.outline&&X.bgColor==="transparent"?me(r):Re,borderWidth:en(X.borderWidth,Xr.borderWidth),borderStyle:X.borderStyle??Xr.borderStyle,borderRadius:X.borderRadius??Xr.borderRadius,textColor:X.textColor?me(X.textColor):X.outline||X.bgColor==="transparent"?me(D):Re,fontSize:X.fontSize??Xr.fontSize,labelPosition:X.labelPosition??Xr.labelPosition,labelMargin:Xr.labelMargin,labelBg:pl(N("dark"),Re,X.bgOpacity)??N("dark"),padding:X.padding??Xr.padding}},[se,te,D,r,V,N]),De=_.useMemo(()=>{var X,Re;const re=new Map;for(const Pe of t){const ke=(X=Pe.data)==null?void 0:X.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},Rr)=>{const Ae=50+(Rr-(ke.length-1)/2)*ze;F.set(Ke,(Ge===Me?Ae:100-Ae)/100)})}return F},[t]),Z=_.useMemo(()=>{const re=N("dark");return t.filter(F=>{var X;return((X=F.data)==null?void 0:X.id)&&F.data.source&&F.data.target}).map(({data:F})=>{var ke,Me,ze,Ke,Ge,Rr;let X=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((Rr=(Ge=te.get(Re))==null?void 0:Ge.data)==null?void 0:Rr.viewProps),gr=pl(re,me(Ae.bgColor),Ae.bgOpacity);gr&&(X=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?Bu(f,F):void 0,color:s?J:F.color?me(F.color):J,connectorColor:s?J:F.color?me(F.color):fe,labelBg:X,dashed:!!F.isEdgeDashed,animated:!!F.isEdgeAnimated,inverted:!!F.isInverted,turn:De.get(F.id)??.5}})},[t,J,fe,s,De,b.edgeType,l,f,te,se,N]),de=_.useMemo(()=>{var F;const re=new Set;for(const X of e)(F=X.data)!=null&&F.parent&&re.add(X.data.parent);return re},[e]),Ce=_.useMemo(()=>{var F;const re=new Map;for(const X of t)(F=X.data)!=null&&F.source&&!re.has(X.data.source)&&re.set(X.data.source,X.data);return re},[t]),Oe=_.useMemo(()=>{const re={...B_,...b.customViews};return e.filter(F=>{var X;return(X=F.data)==null?void 0:X.id}).map(F=>{var Me,ze,Ke,Ge;const X=de.has(F.data.id)&&!F.data.parent,Re=X?F.data.label??F.data.headerTitle??"Container":void 0,Pe=X?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:_.createElement(Pe,{...F,isInverted:ke==null?void 0:ke.isInverted,isParent:X,key:`${F.data.id}-${r}`})}})},[e,de,Ce,r,b.customViews]),qe=_.useMemo(()=>V?300:e.length>50?150:e.length>20?100:50,[e.length,V]),Ue=_.useRef(b);Ue.current=b;const Qe=_.useRef(S);Qe.current=S;const We=_.useRef(I);We.current=I;const we=_.useRef(x);we.current=x;const Se=_.useRef(w);Se.current=w;const He=_.useRef(T);He.current=T;const Xe=_.useRef(te);Xe.current=te;const ur=_.useRef(xe);ur.current=xe;const er=_.useRef(new Map);_.useEffect(()=>{var X,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)||(Se.current===Pe&&(v(null),(X=g.onEdgeDeselect)==null||X.call(g)),(Re=g.onEdgeRemove)==null||Re.call(g,Pe,ke.data))},[xe,te,g,v]),_.useEffect(()=>{const re=q.current;if(!O||!re)return;let F=null,X=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,X===null&&(X=requestAnimationFrame(()=>{X=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),X!==null&&cancelAnimationFrame(X)}},[O]),_.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const re=F=>{var Re,Pe,ke,Me;if(Ue.current.readOnly)return;const X=F.target;if(!(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)){if((F.key==="z"||F.key==="Z")&&j(!Qe.current),(F.key==="m"||F.key==="M")&&P(!T),(F.key==="d"||F.key==="D")&&R(!M),(F.key==="v"||F.key==="V")&&!F.repeat&&!F.metaKey&&!F.ctrlKey&&!F.altKey&&X.tagName!=="SELECT"&&k(!E),(F.key==="Delete"||F.key==="Backspace")&&Se.current){F.preventDefault();const ze=Se.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,E,k,j,P,R,b.disableKeyboardShortcuts,g,m,v]);const sr=_.useCallback(re=>{var F;y.current=re,W(re),(F=g.onInit)==null||F.call(g,re)},[y,g]),Ee=_.useCallback(re=>{var F;return(F=g.onViewportChange)==null?void 0:F.call(g,re)},[g]),ut=_.useCallback(re=>{var X,Re,Pe;const F=((X=ur.current.get(re))==null?void 0:X.data)??{id:re};if(Se.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=_.useCallback(()=>{var re,F,X;a(!0),(re=g.onBackgroundClick)==null||re.call(g),we.current.length&&(m([]),(F=g.onNodeDeselect)==null||F.call(g)),Se.current&&(v(null),(X=g.onEdgeDeselect)==null||X.call(g))},[g,m,v,a]),Pt=_.useCallback(re=>{var Re,Pe;const F=we.current,X=re.filter(ke=>!F.includes(ke));if(X.length){m([...F,...X]);for(const ke of X)(Pe=g.onNodeSelect)==null||Pe.call(g,ke,((Re=Xe.current.get(ke))==null?void 0:Re.data)??{id:ke})}},[g,m]),ae=_.useCallback((re,F)=>{var X,Re;m([re]),(Re=g.onNodeSelect)==null||Re.call(g,re,((X=Xe.current.get(re))==null?void 0:X.data)??{id:re},F)},[g,m]),Fe=_.useCallback((re,F,X)=>{var Re;return(Re=g.onEdgeCreate)==null?void 0:Re.call(g,re,F,X)},[g]),Ze=_.useCallback((re,F,X,Re=!1)=>{var Pe,ke;l==="properties"&&((Pe=g.onNodeCreateRequest)==null?void 0:Pe.call(g,{sourceNodeId:re,position:F,sourceProperty:X,reverse:Re}))===!0||X!==void 0||Re||(ke=g.onNodeCreate)==null||ke.call(g,{type:"text",sourceNodeId:re,position:F,isArrayMode:We.current})},[g,l]),Be=!b.readOnly&&E&&b.edgeHandles!==!1,lr=i==="transparent"?"none":i;return h.jsx(z_,{pattern:lr,backgroundColor:G,children:h.jsx(B.Box,{ref:q,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:h.jsx(E_,{nodes:Oe,edges:Z,direction:U,nodeAlignment:u,onContainerCollapse:re=>{var F,X;(F=g.onNodeCollapse)==null||F.call(g,re,!0),(X=g.onNodeViewToggle)==null||X.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:Y,fitOnInit:!b.initialViewport,readOnly:!!b.readOnly,containerStyle:ge,lineColor:s?J:fe,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:ae,onEdgeDraw:Fe,onDrawIntoSpace:Ze})})})},Ub=_.memo(V_),W_=".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 yy=!1;function G_(){if(yy||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=W_+S0+x0+C0+".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}',yy=!0}function U_({loading:e=!1,loader:t,...r}){var c,u;const[n,o]=_.useState(null),i=_.useMemo(()=>!!(n!=null&&n.json)&&!!r.json&&m0(n.json,r.json),[n==null?void 0:n.json,r.json]),a=n===null||n.json!==r.json&&!i,s=e||a;return _.useEffect(()=>{!e&&i&&(n==null?void 0:n.json)!==r.json&&o(r)},[e,i,n==null?void 0:n.json,r.json]),_.useEffect(()=>{if(e||!a)return;let l;const d=requestAnimationFrame(()=>{l=requestAnimationFrame(()=>o(r))});return()=>{cancelAnimationFrame(d),l!==void 0&&cancelAnimationFrame(l)}},[e,a,r.json]),h.jsxs(B.Box,{className:r.className,style:r.style,width:"100%",height:"100%",position:"relative","aria-busy":s,children:[h.jsx("div",{style:{width:"100%",height:"100%"},ref:l=>{s?l==null||l.setAttribute("inert",""):l==null||l.removeAttribute("inert")},children:n&&h.jsx(H_,{...a?n:r,className:void 0,style:void 0})}),s&&t!==null&&h.jsx(B.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 H_({title:e="untitled",json:t,forms:r,nodes:n,edges:o,config:i={},callbacks:a={},className:s,style:c,showBottomBar:u=!0,children:l}){G_();const[d,f]=_.useState(),[p,y]=_.useState(!1),g=i.formSchema??d,b=_.useMemo(()=>t&&r?sm(t,r.state):t,[t,r==null?void 0:r.state]),x=i.direction==="C",m=_.useMemo(()=>{let R,E;return k=>(E=R&&E?b0(R,k,E)??Su(k,{title:e,isCenter:x}):Su(k,{title:e,isCenter:x}),R=k,E)},[e,x]),w=_.useMemo(()=>b?m(b):null,[b,m]),v=_.useMemo(()=>r!=null&&r.structured&&!p&&g?cm(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=_.useMemo(()=>[...(w==null?void 0:w.nodes)??n??[],...(v==null?void 0:v.nodes)??[]].map(E=>{var ue,ne,Q,pe;const k=t?(ue=je(t,E.data.id))==null?void 0:ue.$view:(ne=E.data.config)==null?void 0:ne.typeView,I=k&&Kt.includes(k)?k:void 0,q=I?I==="icon-label":(Q=E.data.config)==null?void 0:Q.labelBelow,O=I==="object"?"objectView":I==="text"?"text":q?"arrayView":E.data.type,W=C&&(r?nn(S,E.data.id,C):t&&_t(t,E.data.id,C)),V=(((pe=E.data.config)==null?void 0:pe.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?{...E,data:{...E.data,type:O,...r?{description:Object.fromEntries(Object.entries(E.data.description??{}).filter(([le])=>!le.startsWith("$")&&!(v!=null&&v.slots.has(Mt(E.data.id,le)))))}:{},config:{...E.data.config,...v&&W?{ports:V}:{},...W?{form:!0}:{},...I?{typeView:I,labelBelow:!!q}:q?{labelBelow:!0}:{}}}}:E}),[w,n,t,C,S,v,i.direction]),T=[...(w==null?void 0:w.edges)??o??[],...(v==null?void 0:v.edges)??[]],P=_.useMemo(()=>{const R=t&&w?km(t,w.edges,a,a.onJsonChange,g):{...a};if(v){const E=new Set([...v.nodes.map(k=>k.data.id),...v.edges.map(k=>k.data.id)]);for(const k of Object.keys(R)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(k))continue;const I=R[k];R[k]=(q,...O)=>{if(!E.has(q))return I==null?void 0:I(q,...O)}}}return{...R,onAllNodesIconLabelChange:E=>{var k;y(E),(k=R.onAllNodesIconLabelChange)==null||k.call(R,E)}}},[t,w,a,g,v]),M=_.useMemo(()=>{if(!r)return P;let R=r.state;const E=I=>{if(i.readOnly||i.editable===!1)return;const q=r.onStateChange??r.onChange;if(!q)return;const O=i0(R,I,a.onFormChange);O!==R&&(R=O,q(O,{...I,data:O}))},k=(I,q,O)=>{var V;const W=t&&((V=je(t,I))==null?void 0:V[q]);return!W||typeof W.$state!="string"?!1:(E({address:W.$state,nodeAddress:I,previousValue:je(R,W.$state),value:O,data:R}),!0)};return{...P,onFormChange:E,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||E({data:R,nodeAddress:O.address.split(".").slice(0,-1).join("."),address:O.address,value:qt(O.type),previousValue:void 0}),!0):((V=P.onNodeCreateRequest)==null?void 0:V.call(P,I))??!1},onNodeDelete:(I,q)=>{var Q,pe;if(!(v!=null&&v.nodes.some(le=>le.data.id===I)))return(Q=P.onNodeDelete)==null?void 0:Q.call(P,I,q);const O=v&&[...v.slots.values()].find(le=>le.nodeId===I);if(!O)return(pe=P.onNodeDelete)==null?void 0:pe.call(P,I,q);const W=O.address.split("."),V=W.pop(),ue=W.join("."),ne=je(R,ue);E(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=c0(R,V,W);Q!==void 0&&E({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=P.onEdgeCreate)==null||ne.call(P,I,q,O)},onEdgeDelete:(I,q)=>{var pe;const O=v==null?void 0:v.edges.find(le=>le.data.id===I);if(!O)return(pe=P.onEdgeDelete)==null?void 0:pe.call(P,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);E(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;k(I,"$content",q)?(O=a.onNodeContentChange)==null||O.call(a,I,q):(W=P.onNodeContentChange)==null||W.call(P,I,q)},onNodeLabelChange:(I,q)=>{var O,W;k(I,"$label",q)?(O=a.onNodeLabelChange)==null||O.call(a,I,q):(W=P.onNodeLabelChange)==null||W.call(P,I,q)}}},[P,r,t,a,v,i.readOnly,i.editable]);return h.jsx(xr.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):!!a.onJsonChange,schema:C,setSchema:R=>{var E;f(R),(E=a.onFormSchemaChange)==null||E.call(a,R)},callbacks:M},children:h.jsx(Sy,{config:v?{...i,formSchema:C}:i,callbacks:M,nodes:j,edges:T,children:h.jsxs(B.Box,{className:s,"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(Ub,{nodes:j,edges:T}),u&&h.jsx(Em,{}),l]})})})}function K_(e){return Au(JSON.parse(e))}function Au(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 J_(e){return{replaceJson(t){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const r=Au(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=Au(t);return e.onStateChange(r,{address:"root",nodeAddress:"root",previousValue:e.state,value:r,data:r}),r}}}function Z_(e,t){const r=(n,o)=>{if(n===null||typeof n!="object")return typeof n==typeof o?n:void 0;if(!(!o||typeof o!="object"))return Array.isArray(n)?Array.isArray(o)?n.map((i,a)=>r(i,o[a])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,a])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i.startsWith("$")&&i!=="$")return JSON.stringify(a)===JSON.stringify(o[i])?[[i,a]]:[];const s=r(a,o[i]);return s===void 0?[]:[[i,s]]}))};return r(e,t)??{}}function pn(e){let t="",r=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},a=()=>{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{}},s=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(a,e.intervalMs??150))}};return{snapshot:s,append(c){s(t+c)},flush:a,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 Y_(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,a=!1,s=!1,c;const u=Math.max(1,Math.ceil(t.length*r/n)),l=()=>e.onChange({position:i,total:t.length,playing:a}),d=()=>{clearTimeout(c),c=void 0},f=(g=!1)=>{o.snapshot(t.slice(0,i)),i===t.length?(a=!1,d(),o.finish()):g&&o.flush()},p=g=>{a=!1,d(),o.cancel(),l(),e.onError(g)},y=()=>{if(c=void 0,!(!a||s)){i=Math.min(t.length,i+u);try{f()}catch(g){p(g);return}l(),a&&(c=setTimeout(y,r))}};return{play(){s||a||(i===t.length&&(o.cancel(),o=pn(e),i=0),a=!0,l(),c=setTimeout(y,r))},pause(){s||(a=!1,d(),o.flush(),l())},seek(g){if(!s){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(),a&&(c=setTimeout(y,r))}},dispose(){s=!0,a=!1,d(),o.cancel()}}}function X_({nodeAddress:e,expanded:t=!1}){var u;const{data:r,schema:n,bindings:o}=_.useContext(xr),{colorText:i,background:a}=Ye();if((u=o==null?void 0:o[e])!=null&&u.portResources)return null;const s=o&&nn(o,e,n);if(!r||!s)return null;const c=je(r,s.address);return!c||typeof c!="object"?null:h.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:me(i),background:me(a),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(s.type.properties).map(l=>{const d=s.fields[l]??{};if(!En(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:br(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=Em;exports.CompactPropertyLayoutToggle=Hy;exports.ConnectionsOnlyToggle=y0;exports.DEFAULT_PALETTE=bn;exports.DiagramAppearanceControls=Jy;exports.DynamicIcon=Pr;exports.EdgeTools=gm;exports.EditableLabel=rn;exports.ErrorToast=Cm;exports.FlowDiagram=U_;exports.FlowDiagramProvider=Sy;exports.FlowPort=Lb;exports.FlowView=Ub;exports.FormDocumentContext=xr;exports.LIGHT_BLACK=wt;exports.NODE_TYPE_VIEWS=Kt;exports.NodeBorderRadiusControl=ym;exports.NodeConfigSummary=X_;exports.NodeForm=lm;exports.NodeFormPopover=Fb;exports.NodeIconPicker=Du;exports.NodeTools=mm;exports.NodeView=Un;exports.SvgExportButton=xm;exports.Swatches=vt;exports.TEXT_PALETTE=hm;exports.ToolbarCloseButton=Ct;exports.ToolbarCommitInput=nt;exports.ToolbarDivider=Ft;exports.ToolbarIconButton=_e;exports.ToolbarRangeInput=Ky;exports.ToolbarScrollContainer=wm;exports.ToolbarSelect=vr;exports.ToolbarTooltip=Te;exports.TooltipIconButton=Pu;exports.WorkflowControls=_m;exports.addChild=Nu;exports.addConnection=$u;exports.addTargetEdge=nm;exports.addressToPath=Mr;exports.applyCollapsed=t0;exports.applyFormChange=jn;exports.applyStateEdits=o0;exports.bindSqueedCallbacks=km;exports.compileSqueed=Su;exports.connectionIssue=Bu;exports.contentObjTheme=kr;exports.createFlowDiagram=tt;exports.createFlowDocumentActions=J_;exports.createFormNode=Rm;exports.createJsonPlayback=Y_;exports.createJsonStream=pn;exports.downloadSvg=vm;exports.exportSvg=bm;exports.formValueError=Sr;exports.getChakraColorHex=me;exports.getColorVariant=xy;exports.getDarkerHexColor=gn;exports.getInteractionSurface=Vr;exports.getNode=je;exports.parseFlowDocument=K_;exports.parseJsonContract=Lu;exports.parseTypeScriptContract=im;exports.parseTypeScriptForm=Fu;exports.projectJsonPlaybackPreview=Z_;exports.readFormSchema=zu;exports.readWorkflowContract=am;exports.removeEdge=om;exports.removeNode=tm;exports.resolveEdgeOwner=Yt;exports.resolveStateView=sm;exports.setCollapsed=em;exports.setEdgeProp=zr;exports.setEdgeStyle=rm;exports.setNodeProp=cr;exports.updateNode=mr;exports.useCustomColors=Ye;exports.useEdgeProximity=vy;exports.useFlowData=Hr;exports.useFlowDiagramContext=$e;exports.useNodeViewActions=Hn;exports.useStopPropagation=cl;exports.useThemeContentColors=tn;
279
+ `;function Bb({nodeAddress:e,active:t,label:r,open:n=!1,onClose:o,children:i,filter:a,height:s}){const{background:c,border:u,colorText:l}=Xe(),{colorMode:d}=qe(),h=_.useRef(null),p=_.useId(),{data:g,schema:m,bindings:y}=_.useContext(wr),v=i!==void 0||!!(g&&m&&(y?on(y,e,m):St(g,e,m)));_.useEffect(()=>{var w,x,C,S,j;!t||!v||!n?(w=h.current)==null||w.close():(x=h.current)!=null&&x.open||((C=h.current)==null||C.showModal(),(j=(S=h.current)==null?void 0:S.querySelector("[data-form-filter] input"))==null||j.focus())},[t,v,n]);const b=me(c);return v?f.jsx(f.Fragment,{children:typeof document<"u"&&Kt.createPortal(f.jsx(j_,{ref:h,id:p,$surface:b,$border:me(u),"aria-label":`Configure ${r}`,onClose:o,onPointerDown:w=>w.stopPropagation(),onWheel:w=>w.stopPropagation(),onKeyDown:w=>w.stopPropagation(),onClick:w=>{var x;w.stopPropagation(),w.target===w.currentTarget&&((x=h.current)==null||x.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:s,overflow:"hidden",borderRadius:30,background:b,color:me(l),fontSize:16,textTransform:"none"},children:n&&f.jsxs(f.Fragment,{children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexShrink:0},children:[f.jsx("strong",{style:{overflowWrap:"anywhere",minWidth:0},children:r}),f.jsx("form",{method:"dialog",style:{margin:0},onSubmit:w=>w.stopPropagation(),children:f.jsx(_t,{type:"submit","aria-label":"Close node configuration"})})]}),a&&f.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:a}),f.jsx(R_,{$divider:`var(--chakra-colors-gray-${d==="dark"?"700":"200"})`,"data-form-scroll":"",style:s?{flex:1}:void 0,children:i??f.jsx(dm,{nodeAddress:e})})]})}),document.body)}):null}const Au=({icon:e,label:t,onClick:r,color:n,boxSize:o=6,...i})=>{const{background:a,border:s,colorText:c}=Xe();return f.jsx(Ae,{label:t,children:f.jsx(F.Flex,{children:f.jsx(F.Icon,{as:e,boxSize:o,color:n,cursor:r?"pointer":void 0,onClick:r})})})},k_=({data:e,children:t,isInverted:r,isParent:n,onOpenView:o,editOnMount:i=!1})=>{var N,re,ye,de,J,X;const{selectedNodeIds:a,setSelectedNodeIds:s,selectedEdgeId:c,setSelectedEdgeId:u,isMultiSelectMode:l,isPerformanceMode:d,engineRef:h,callbacks:p,config:g,themeColor:m,direction:y,nodeViewModes:v}=qe(),{background:b,border:w,colorText:x}=Xe(),C=_.useRef(null),S=_.useRef(null),[j,T]=_.useState(!1),[k,M]=_.useState(i&&!!g.editable&&!g.readOnly),[R,E]=_.useState(!1),P=e==null?void 0:e.id,I=fm(P),q=a.includes(P),O=g.nodeOverlayActions,V=g.renderNodeOverlay,W=(()=>{var U;try{const ue=(U=h.current)==null?void 0:U.zoom();return ue!==void 0&&ue<.08}catch{return!1}})(),te=_.useCallback(U=>{var se,we,pe,ze;if(k||g.readOnly)return;const ue={shiftKey:U.shiftKey,ctrlKey:U.ctrlKey,metaKey:U.metaKey,altKey:U.altKey};if(c&&(u(null),(se=p.onEdgeDeselect)==null||se.call(p)),l){const Y=a.includes(P),fe=Y?a.filter(_e=>_e!==P):[...a,P];s(fe),Y?(we=p.onNodeDeselect)==null||we.call(p):(pe=p.onNodeSelect)==null||pe.call(p,P,e,ue)}else s([P]),(ze=p.onNodeSelect)==null||ze.call(p,P,e,ue)},[P,e,a,c,l,k,s,u,p,g]),ne=_.useCallback(()=>{var U;k||g.readOnly||(U=p.onNodeDoubleClick)==null||U.call(p,P,e)},[P,e,k,p,g]),ee=_.useCallback(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>T(!0),100)},[]),be=_.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 ue;!le&&!o||g.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(),s([P]),o?o():E(!0),(ue=p.onNodeDoubleClick)==null||ue.call(p,P,e))},onKeyDown:U=>{!le&&!o||g.readOnly||U.target!==U.currentTarget||U.key!=="Enter"||(U.preventDefault(),U.stopPropagation(),s([P]),o?o():E(!0))}},z=le&&f.jsx(Bb,{nodeAddress:P,active:q,label:e.label||e.headerTitle||"Node",open:R,onClose:()=>{var U;E(!1),q&&((U=C.current)==null||U.focus({preventScroll:!0}))}}),G=Array.isArray((re=e==null?void 0:e.config)==null?void 0:re.ports)?e.config.ports.map(U=>f.jsx(Fb,{...U},`${U.id}:${U.role}`)):null;return n?f.jsxs(F.Box,{ref:C,...$,onClick:te,onDoubleClick:ne,onMouseEnter:ee,onMouseLeave:be,cursor:"pointer",position:"relative",children:[z,!d&&(V||O&&O.length>0)&&j&&!W&&f.jsxs(f.Fragment,{children:[f.jsx(F.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>T(!0),onMouseLeave:be}),V?f.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>T(!0),onMouseLeave:be,willChange:"transform",children:V({nodeId:P,nodeData:e,isRoot:P==="root",isParent:!0,isHovered:j,setIsHovered:T})}):f.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:b,p:3,borderColor:w,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>T(!0),onMouseLeave:be,willChange:"transform",children:f.jsx(F.HStack,{px:2,gap:2,children:O.map((U,ue)=>f.jsxs(F.Box,{display:"contents",children:[ue>0&&f.jsx(F.Box,{borderColor:w,height:5,borderRightWidth:1}),f.jsx(Au,{icon:U.icon,label:U.label,color:x,bgColor:b,borderColor:w,textColor:x,boxSize:5,onClick:se=>{var we;se.stopPropagation(),(we=p.onNodeHoverAction)==null||we.call(p,U.id,P,e)}})]},U.id))})})]}),t({id:P,data:e,isActive:q,isLowZoom:W,isEditing:k,onEditStart:()=>M(!0),onEditEnd:()=>M(!1)}),I&&!((ye=e==null?void 0:e.config)!=null&&ye.parentContainer)&&((de=e==null?void 0:e.config)==null?void 0:de.collapsed)!==void 0&&(()=>{var se;const U=y==="TB"||y==="BT",ue=r||y==="RL";return f.jsx(F.IconButton,{position:"absolute",...U?{[y==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:ue?void 0:"-75px",left:ue?"-75px":void 0,top:"50%",transform:"translateY(-50%)"},"aria-label":e.config.collapsed?"Expand":"Collapse",disabled:g.readOnly,onClick:we=>{var pe;we.stopPropagation(),(pe=p.onNodeCollapse)==null||pe.call(p,P,!e.config.collapsed)},bgColor:me(((se=e==null?void 0:e.viewProps)==null?void 0:se.bgColor)||m),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(K.PiPlusBold,{size:30,color:me("gray.800")}):f.jsx(K.PiMinusBold,{size:30,color:me("gray.800")})})})()]}):f.jsxs(F.Box,{ref:C,...$,onClick:te,onDoubleClick:ne,onMouseEnter:ee,onMouseLeave:be,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[z,G,!d&&(V||O&&O.length>0)&&j&&!W&&f.jsxs(f.Fragment,{children:[f.jsx(F.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>T(!0),onMouseLeave:be}),V?f.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>T(!0),onMouseLeave:be,willChange:"transform",children:V({nodeId:P,nodeData:e,isRoot:P==="root",isParent:!!n,isHovered:j,setIsHovered:T})}):f.jsx(F.Box,{position:"absolute",zIndex:1e3,top:"-100px",left:"50%",bg:b,p:3,borderColor:w,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>T(!0),onMouseLeave:be,willChange:"transform",children:f.jsx(F.HStack,{px:2,gap:2,children:O.map((U,ue)=>f.jsxs(F.Box,{display:"contents",children:[ue>0&&f.jsx(F.Box,{borderColor:w,height:5,borderRightWidth:1}),f.jsx(Au,{icon:U.icon,label:U.label,color:x,bgColor:b,borderColor:w,textColor:x,boxSize:5,onClick:se=>{var we;se.stopPropagation(),(we=p.onNodeHoverAction)==null||we.call(p,U.id,P,e)}})]},U.id))})})]}),f.jsxs(F.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[I&&!((J=e==null?void 0:e.config)!=null&&J.parentContainer)&&((X=e==null?void 0:e.config)==null?void 0:X.collapsed)!==void 0&&!n&&(()=>{var we,pe,ze;const U=y==="TB"||y==="BT",ue=r||y==="RL",se=(we=e==null?void 0:e.config)!=null&&we.labelBelow&&v[P]!=="properties"?((((pe=e==null?void 0:e.viewProps)==null?void 0:pe.fontSize)||1)*100+100)/2:void 0;return f.jsx(F.IconButton,{position:"absolute",...U?{[y==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:ue?void 0:se===void 0?"-75px":`calc(50% - ${se+75}px)`,left:ue?se===void 0?"-75px":`calc(50% - ${se+75}px)`:void 0,alignSelf:se===void 0?"center":void 0,top:se===void 0?void 0:`${se}px`,transform:se===void 0?void 0:"translateY(-50%)",zIndex:se===void 0?void 0:1},"aria-label":e.config.collapsed?"Expand":"Collapse",disabled:g.readOnly,onClick:Y=>{var fe;Y.stopPropagation(),(fe=p.onNodeCollapse)==null||fe.call(p,P,!e.config.collapsed)},bgColor:me(((ze=e==null?void 0:e.viewProps)==null?void 0:ze.bgColor)||m),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(K.PiPlusBold,{size:30,color:me("gray.800")}):f.jsx(K.PiMinusBold,{size:30,color:me("gray.800")})})})(),t({id:P,data:e,isActive:q,isLowZoom:W,isEditing:k,onEditStart:()=>M(!0),onEditEnd:()=>M(!1)})]})]})},Hn=_.memo(k_);function ul(e=!0){const t=_.useRef(null);return _.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 tn=({nodeId:e,label:t,color:r,fontWeight:n="bold",fontSize:o="5xl",wrap:i=!1,isEditing:a,onEditStart:s,onEditEnd:c})=>{const{callbacks:u,config:l,readOnly:d}=qe(),h=l.editable&&!d,[p,g]=_.useState(t),[m,y]=_.useState(),v=_.useRef(null),b=_.useRef(!1),w=ul(a);_.useEffect(()=>{a&&(b.current=!1,v.current&&(v.current.focus(),v.current.select()))},[a]);const x=()=>{var S;if(b.current)return;b.current=!0;const C=p.trim();C&&C!==t&&((S=u.onNodeLabelChange)==null||S.call(u,e,C)),c()};return!h||!a?f.jsx(F.Text,{color:r,fontWeight:n,fontSize:o,minW:0,maxW:"100%",whiteSpace:i?"normal":"nowrap",overflowWrap:i?"anywhere":void 0,overflow:"hidden",textOverflow:"ellipsis",title:t,onDoubleClick:h?C=>{C.stopPropagation(),y({width:C.currentTarget.offsetWidth,height:C.currentTarget.offsetHeight}),g(t),s()}:void 0,cursor:h?"text":void 0,children:t}):f.jsxs("div",{ref:w,style:{position:"relative",width:"max-content",minWidth:m==null?void 0:m.width,maxWidth:900,height:m==null?void 0:m.height},children:[f.jsx(F.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),f.jsx(F.Input,{ref:v,value:p,onChange:C=>g(C.target.value),onBlur:x,onKeyDown:C=>{C.key==="Enter"&&x(),C.key==="Escape"&&(b.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"})]})},P_=({id:e,data:t,isActive:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var m,y,v,b,w,x,C,S;const{themeColor:a}=qe(),{colorText:s}=Xe(),c=((m=t==null?void 0:t.viewProps)==null?void 0:m.bgColor)==="transparent",u=((y=t==null?void 0:t.viewProps)==null?void 0:y.outline)===!0,{highlightColor:l,borderColor:d,textColor:h}=nn(((v=t==null?void 0:t.viewProps)==null?void 0:v.bgColor)||a),p=me(((b=t==null?void 0:t.viewProps)==null?void 0:b.textColor)||(c||u?s:h)),g=((w=t==null?void 0:t.viewProps)==null?void 0:w.borderColor)||(u?!c&&((x=t==null?void 0:t.viewProps)==null?void 0:x.bgColor)||a:d);return f.jsx(F.Box,{"data-flow-node-surface":"",borderRadius:(C=t==null?void 0:t.viewProps)==null?void 0:C.borderRadius,bgColor:u?"transparent":l,...bn(t==null?void 0:t.viewProps,g,r,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:f.jsxs(F.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)&&f.jsx(F.Box,{flexShrink:0,children:f.jsx(Ar,{name:t.config.icon,size:80,color:p})}),f.jsx(tn,{nodeId:e,label:(t==null?void 0:t.label)||(t==null?void 0:t.text)||"",color:p,isEditing:n,onEditStart:o,onEditEnd:i})]})})};function Kn(){const{nodeViewModes:e,setNodeViewMode:t,allNodesIconLabel:r,setAllNodesIconLabel:n}=qe();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 A_=({id:e,isActive:t,data:r,isEditing:n,onEditStart:o,onEditEnd:i})=>{var w,x,C,S,j,T,k,M,R,E,P,I,q,O,V;const{themeColor:a}=qe(),{colorText:s}=Xe(),c=((w=r==null?void 0:r.viewProps)==null?void 0:w.bgColor)==="transparent",u=((x=r==null?void 0:r.viewProps)==null?void 0:x.outline)===!0,l=!c&&((C=r==null?void 0:r.viewProps)==null?void 0:C.bgColor)||a,{borderColor:d,highlightColor:h,textColor:p}=nn(l),g=me(((S=r==null?void 0:r.viewProps)==null?void 0:S.textColor)||(c||u?s:p)),m=c&&!u&&!((j=r==null?void 0:r.viewProps)!=null&&j.borderColor)?"transparent":me(((T=r==null?void 0:r.viewProps)==null?void 0:T.borderColor)||(u?l:d)),y=c||u?"transparent":l!=null&&l.startsWith("#")?l:me(h),v=(k=r==null?void 0:r.config)==null?void 0:k.icon,b=(r==null?void 0:r.label)??(r==null?void 0:r.text)??"";if((M=r==null?void 0:r.config)!=null&&M.labelBelow){const W=(((R=r==null?void 0:r.viewProps)==null?void 0:R.fontSize)||1)*100;return f.jsxs(F.Flex,{"data-flow-icon-label":"",direction:"column",align:"center",gap:"24px",width:`${Math.max(W+200,360)}px`,position:"relative",children:[f.jsx(F.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${W+100}px`,height:`${W+100}px`,flexShrink:0,borderRadius:(E=r==null?void 0:r.viewProps)==null?void 0:E.borderRadius,backgroundColor:y,...bn(r==null?void 0:r.viewProps,m,t,2),children:!!v&&f.jsx(Ar,{name:v,size:W,color:g})}),f.jsxs(F.Flex,{"data-flow-icon-caption":"",direction:"column",align:"center",gap:"8px",justify:"center",width:"100%",minW:0,textAlign:"center",children:[f.jsx(tn,{nodeId:e,label:b,color:me(((P=r==null?void 0:r.viewProps)==null?void 0:P.textColor)||s),isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0}),typeof((I=r.config)==null?void 0:I.subtitle)=="string"&&r.config.subtitle!==""&&f.jsx(F.Text,{"data-flow-node-subtitle":"",color:me(((q=r==null?void 0:r.viewProps)==null?void 0:q.textColor)||s),opacity:.65,fontSize:"32px",fontWeight:"normal",lineHeight:1.3,width:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",title:r.config.subtitle,children:r.config.subtitle})]})]})}return f.jsxs(F.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:(O=r==null?void 0:r.viewProps)==null?void 0:O.borderRadius,bgColor:y,style:{backgroundColor:y},textTransform:"capitalize",...bn(r==null?void 0:r.viewProps,m,t,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!v&&f.jsx(F.Flex,{align:"center",py:14,mr:b?8:0,flexShrink:0,children:f.jsx(Ar,{name:v,size:(((V=r==null?void 0:r.viewProps)==null?void 0:V.fontSize)||1)*100,color:g},g)}),(b||!v)&&f.jsx(F.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:f.jsx(tn,{nodeId:e,label:b,color:g,isEditing:n,onEditStart:o,onEditEnd:i})})]})};function zb({onExpand:e,toggleLabel:t="Show properties",toggleDisabled:r=!1,renderCompact:n=A_,...o}){const{colorMode:i,callbacks:a}=qe();return f.jsx(Hn,{...o,children:s=>f.jsxs(F.Box,{position:"relative",children:[f.jsx(n,{...s}),e&&s.isActive&&f.jsx(F.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:f.jsx(Ae,{label:t,children:f.jsx(Se,{"aria-label":t,icon:f.jsx(F.Icon,{as:K.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=a.onNodeViewToggle)==null||u.call(a,o.data.id)}})})})]})})}const yy=1.55;function T_({nodeId:e,content:t,color:r}){const{callbacks:n,config:o,readOnly:i}=qe(),a=!!o.editable&&!i,[s,c]=_.useState(!1),[u,l]=_.useState(t),[d,h]=_.useState(),p=_.useRef(null),g=_.useRef(!1),m=ul(s);_.useLayoutEffect(()=>{const b=p.current;!s||!b||(b.style.height="auto",b.style.height=`${Math.max((d==null?void 0:d.height)??0,b.scrollHeight)}px`)},[u,s,d]),_.useEffect(()=>{var b;a?s&&(g.current=!1,(b=p.current)==null||b.focus()):c(!1)},[s,a]);const y=b=>{a&&(h({width:b.offsetWidth,height:b.offsetHeight}),l(t),c(!0))},v=()=>{var b;g.current||!a||(g.current=!0,u!==t&&((b=n.onNodeContentChange)==null||b.call(n,e,u)),c(!1))};return!s||!a?f.jsx(F.Box,{"data-flow-content":"",color:r,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:yy,overflowWrap:"anywhere",css:{"& > :first-of-type":{marginTop:0},"& > :last-of-type":{marginBottom:0},"& h1, & h2, & h3, & h4, & h5, & h6":{fontWeight:700,lineHeight:1.2,margin:"1em 0 0.45em"},"& h1":{fontSize:"1.5em"},"& h2":{fontSize:"1.3em"},"& h3":{fontSize:"1.1em"},"& p":{margin:"0.65em 0",whiteSpace:"pre-wrap"},"& ul, & ol":{margin:"0.65em 0",paddingInlineStart:"1.6em"},"& ul":{listStyleType:"disc"},"& ol":{listStyleType:"decimal"},"& li":{display:"list-item",margin:"0.3em 0",paddingInlineStart:"0.15em"},"& li > ul, & li > ol":{margin:"0.25em 0"},"& li > p":{margin:0},"& a":{color:"inherit",textDecoration:"underline"},"& code":{fontFamily:"monospace",fontSize:"0.85em"},"& :not(pre) > code":{background:"color-mix(in srgb, currentColor 10%, transparent)",padding:"0.1em 0.25em",borderRadius:"0.2em"},"& pre":{margin:"0.75em 0",padding:"0.75em",background:"color-mix(in srgb, currentColor 8%, transparent)",border:0,borderRadius:"6px",maxWidth:"100%",overflowX:"auto",whiteSpace:"pre",overflowWrap:"normal",lineHeight:1.5},"& pre code":{background:"transparent",padding:0,whiteSpace:"inherit"},"& strong":{fontWeight:700},"& em":{fontStyle:"italic"},"& blockquote":{margin:"0.4em 0",borderInlineStart:"0.1em solid currentColor",paddingInlineStart:"0.6em"},"& table":{width:"100%",tableLayout:"fixed",borderCollapse:"collapse",margin:"0.4em 0"},"& th, & td":{border:"1px solid currentColor",padding:"0.2em 0.3em",textAlign:"left"},"& th":{fontWeight:700},"& img":{maxWidth:"100%",height:"auto"}},cursor:a?"text":void 0,tabIndex:a?0:void 0,onDoubleClick:b=>{b.stopPropagation(),y(b.currentTarget)},onKeyDown:b=>{a&&b.key==="Enter"&&b.target===b.currentTarget&&(b.preventDefault(),b.stopPropagation(),y(b.currentTarget))},children:f.jsx(lv.default,{options:{forceBlock:!0,wrapper:_.Fragment,disableParsingRawHTML:!0,overrides:{a:{props:{target:"_blank",rel:"noopener noreferrer"}},img:{props:{loading:"lazy",referrerPolicy:"no-referrer"}}}},children:t})}):f.jsx("div",{ref:m,style:{width:d==null?void 0:d.width,minHeight:d==null?void 0:d.height,maxWidth:"100%"},children:f.jsx(F.Textarea,{ref:p,"aria-label":"Node content",value:u,onChange:b=>l(b.target.value),onBlur:v,onKeyDown:b=>{b.stopPropagation(),!b.nativeEvent.isComposing&&(b.key==="Enter"&&(b.ctrlKey||b.metaKey)&&(b.preventDefault(),v()),b.key==="Escape"&&(g.current=!0,c(!1)))},color:r,fontFamily:"inherit",fontSize:"inherit",lineHeight:yy,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 I_=(e,t,r)=>{var h,p,g,m;const n=((h=e==null?void 0:e.viewProps)==null?void 0:h.bgColor)||t,[o]=n.split("."),i=nn(n),a=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,s=n==="transparent"||a,c=r==="dark"?"gray.200":"gray.900",u=s?"transparent":n!=null&&n.startsWith("#")?me(n):me(i.bgColor),l=me(((g=e==null?void 0:e.viewProps)==null?void 0:g.textColor)||(s?c:i.textColor)),d=me(((m=e==null?void 0:e.viewProps)==null?void 0:m.borderColor)||(a?n==="transparent"?t:n:i.borderColor));return{...i,bgColor:s?"transparent":i.bgColor,highlightColor:s?"transparent":i.highlightColor,isTransparent:s,propertyColor:s?c:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:u,hextextColor:l,hexborderColor:d}},O_=(e,t=350)=>`${String(e).substring(0,t)}${String(e).length>t?"...":""}`,M_=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,Db=600,q_=3,N_=e=>{const t=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(t*28+30,200)};function $_({headerTitle:e,hasContent:t,data:r,icon:n,colors:o,hasConfig:i,id:a,isActive:s,isEditing:c,onEditStart:u,onEditEnd:l,props:d,objVisible:h,setObjVisible:p,onShowNativeIcon:g}){var b,w;const{callbacks:m}=qe(),y=d.onShowIcon??g,v=y?"Show icon":h?"Show content":"Show properties";return f.jsx(f.Fragment,{children:(e||t||((b=r.config)==null?void 0:b.form)||s&&g)&&f.jsxs(F.Flex,{justify:"flex-start",direction:"row",p:Object.entries(r.description||{}).length?8:20,borderBottomWidth:1,minWidth:"max-content !important",width:"100%",textTransform:"capitalize",align:"center",textOverflow:"ellipsis",alignItems:"center",fontWeight:"bold",color:o.propertyColor,bgColor:o.highlightColor,borderBottomColor:!i&&!t?"transparent":o.hexborderColor,children:[!!n&&f.jsx(F.Flex,{mr:6,alignItems:"center",flexShrink:0,children:f.jsx(Ar,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),f.jsx(tn,{nodeId:a,label:M_(e),color:((w=r==null?void 0:r.viewProps)==null?void 0:w.textColor)||o.propertyColor,isEditing:c,onEditStart:u,onEditEnd:l}),s&&(t||y)&&f.jsx(F.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:f.jsx(Ae,{label:v,children:f.jsx(Se,{"aria-label":v,icon:f.jsx(F.Icon,{as:K.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:x=>{var C;x.stopPropagation(),y?y():p(!h),(C=m.onNodeViewToggle)==null||C.call(m,a)}})})})]})})}function L_({data:e,resourcePorts:t,inspecting:r,form:n,inspectionPorts:o,extraPorts:i,colors:a,direction:s,uniformKeyWidth:c}){const{edgeById:u}=Hr(),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 f.jsx(F.Box,{children:Object.entries(e.description||{}).map(([d,h],p)=>{var P,I,q;const g=t&&Object.keys(t).find(O=>O.slice(O.indexOf(":")+1)===d),m=r&&((P=n==null?void 0:n.type.ports)==null?void 0:P[d]),y=g??(m?`${m.kind}:${d}`:d),v=o.find(O=>O.id===y),b=g?"source":v==null?void 0:v.role,w=l.has(`source:${y}`),x=l.has(`target:${y}`),C=i.some(O=>O.id===d),S=h===""&&(C||(b?l.has(`${b}:${y}`):w||x)),j=b??(w!==x?w?"source":"target":void 0),T=(v==null?void 0:v.side)??(j?j==="source"!=(s==="RL")?"right":"left":void 0),k=S&&T==="right"?"right":"left",M=(v==null?void 0:v.label)??(m==null?void 0:m.label)??(C?d.replace(/^(template|input|output|config|error):/,""):d),R=Pr(a.wordBeforeDot)[typeof h],E=Pr(a.wordBeforeDot).property;return f.jsxs(F.Box,{"data-flow-property":g&&(s==="TB"||s==="BT")?void 0:y,"data-flow-port-role":b,"data-flow-inspection-row":r?"":void 0,children:[f.jsxs(F.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[f.jsx(F.Flex,{justifyContent:"start",align:"center",background:a.highlightColor,width:S?"100%":`${c}px`,minWidth:`${c}px`,borderRightColor:a.hexborderColor,borderRightWidth:S?0:1,children:f.jsx(F.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)||(a.isTransparent?a.hextextColor:E),children:M})}),!S&&f.jsx(F.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:a.hexbgColor,w:Db,maxH:200,children:f.jsx(F.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)||(a.isTransparent?a.hextextColor:R),fontWeight:400,children:O_(h)})})]}),p!==Object.entries(e.description||{}).length-1&&f.jsx(F.Box,{borderTopWidth:1,my:0,borderColor:a.hexborderColor})]},d)})})}function F_(e){var w,x,C;const{themeColor:t,colorMode:r,direction:n}=qe(),o=Kn(),i=o.getNodeViewMode(e.data.id)==="properties",a=S=>o.setNodeViewMode(e.data.id,S?"properties":"default"),s=!!e.onShowIcon||i||typeof((w=e.data.config)==null?void 0:w.content)!="string",{bindings:c,data:u,schema:l}=_.useContext(wr),d=(x=c==null?void 0:c[e.data.id])==null?void 0:x.portResources,h=c?on(c,e.data.id,l):u&&l?St(u,e.data.id,l):void 0,p=h&&je(u,"address"in h?h.address:e.data.id),g=p&&typeof p=="object"&&h?Object.fromEntries(Object.keys(h.type.properties).filter(S=>{var j;return Object.prototype.hasOwnProperty.call(p,S)&&jn((j=h.fields[S])==null?void 0:j.$visibleWhen,u)}).map(S=>[S,p[S]!==null&&typeof p[S]=="object"?JSON.stringify(p[S],null,2):p[S]===null?"null":p[S]])):{},m=d?Object.fromEntries(Object.entries(d).map(([S,j])=>{var T;return[S.slice(S.indexOf(":")+1),((T=je(u,j))==null?void 0:T.name)??j.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:g,y=s&&!d?((C=e.data.config)==null?void 0:C.ports)??[]:[],v=y.filter(S=>!Object.prototype.hasOwnProperty.call(m,S.id)&&!Object.entries((h==null?void 0:h.type.ports)??{}).some(([j,T])=>`${T.kind}:${j}`===S.id&&Object.prototype.hasOwnProperty.call(m,j))),b={...m,...Object.fromEntries(v.map(S=>[S.id,""]))};return{themeColor:t,colorMode:r,direction:n,objVisible:i,setObjVisible:a,inspecting:s,resourcePorts:d,form:h,description:b,inspectionPorts:y,extraPorts:v}}const ll=e=>{var y,v,b;const{themeColor:t,colorMode:r,direction:n,objVisible:o,setObjVisible:i,inspecting:a,resourcePorts:s,form:c,description:u,inspectionPorts:l,extraPorts:d}=F_(e),h=Kn(),p=h.getNodeViewMode(e.data.id)==="icon-label",m=!e.onShowIcon&&!((y=e.data.config)!=null&&y.parentContainer)&&typeof((v=e.data.config)==null?void 0:v.content)!="string"?()=>h.setNodeViewMode(e.data.id,"icon-label"):void 0;return!e.onShowIcon&&p?f.jsx(zb,{...e,data:{...e.data,label:e.data.label??e.data.headerTitle,config:{...e.data.config,labelBelow:!0,icon:((b=e.data.config)==null?void 0:b.icon)||"PiBracketsCurly"}},onExpand:()=>h.restoreNodeView(e.data.id)}):f.jsx(Hn,{...e,data:{...e.data,description:u},children:({id:w,data:x,isActive:C,isEditing:S,onEditStart:j,onEditEnd:T})=>{var W,te,ne,ee,be,le;const k=I_(x,t,r),M=x.label??x.headerTitle,R=Object.entries(x.description||{}).length>0,E=N_(x.description),P=(te=(W=e.data)==null?void 0:W.config)==null?void 0:te.icon,I=(ee=(ne=e.data)==null?void 0:ne.config)==null?void 0:ee.content,q=typeof I=="string"&&!e.onShowIcon,O=((be=x==null?void 0:x.viewProps)==null?void 0:be.borderRadius)??"53px",V=bn(x==null?void 0:x.viewProps,k.hexborderColor,C,q_);return f.jsx(F.Flex,{justifyContent:"space-between",...x==null?void 0:x.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?E+Db+V.borderWidth*2:void 0,...V,children:f.jsxs(F.Flex,{width:"100%",direction:"column",borderRadius:O,borderColor:k.hexborderColor,borderWidth:0,overflow:"hidden",children:[f.jsx($_,{headerTitle:M,hasContent:q,data:x,icon:P,colors:k,hasConfig:R,id:w,isActive:C,isEditing:S,onEditStart:j,onEditEnd:T,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:m}),q&&!o?f.jsx(F.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:k.highlightColor,p:12,fontSize:"5xl",lineHeight:"normal",children:f.jsx(T_,{nodeId:w,content:I,color:((le=x==null?void 0:x.viewProps)==null?void 0:le.textColor)||k.hextextColor})}):f.jsx(L_,{data:x,resourcePorts:s,inspecting:a,form:c,inspectionPorts:l,extraPorts:d,colors:k,direction:n,uniformKeyWidth:E})]})})}})};ll.displayName="NodeJsonObjectView";const Vb=e=>{var g,m,y,v,b,w,x,C,S,j,T;const t=Kn(),[r,n]=_.useState(!1),o=t.getNodeViewMode(e.data.id)==="properties",i=k=>{n(k),t.setNodeViewMode(e.data.id,k?"properties":"default")},{callbacks:a,readOnly:s,selectedNodeIds:c}=qe(),u=(m=(g=e.data)==null?void 0:g.config)==null?void 0:m.parentContainer,l=c.includes(e.data.id),d=_.useRef(l);_.useEffect(()=>{var k,M;d.current&&!l&&o&&((M=(k=e.data)==null?void 0:k.config)!=null&&M.labelBelow)&&!u&&!s&&i(!1),d.current=l},[l,o,(v=(y=e.data)==null?void 0:y.config)==null?void 0:v.labelBelow,u,s]);const h=u?"Show parent":"Show properties",p=u||((w=(b=e.data)==null?void 0:b.config)==null?void 0:w.form)||((S=(C=(x=e.data)==null?void 0:x.config)==null?void 0:C.ports)==null?void 0:S.length);return!u&&p&&o?f.jsx(ll,{...e,editOnMount:r,onShowIcon:()=>i(!1)}):f.jsx(zb,{...e,onOpenView:!u&&p&&((T=(j=e.data)==null?void 0:j.config)!=null&&T.labelBelow)?()=>{var k;i(!0),(k=a.onNodeViewToggle)==null||k.call(a,e.data.id)}:void 0,toggleLabel:h,toggleDisabled:u&&s,onExpand:p?()=>{var k;u?(k=a.onNodeCollapse)==null||k.call(a,e.data.id,!1):i(!0)}:void 0})},Wb=e=>f.jsx(Vb,{...e,renderCompact:P_}),Gb=e=>f.jsx(Vb,{...e}),Ub=e=>f.jsx(Hn,{...e,children:()=>null});Wb.displayName="text";Gb.displayName="arrayView";Ub.displayName="ParentContainerView";const B_={objectView:ll,arrayView:Gb,text:Wb,parentContainer:Ub},z_=({children:e,pattern:t="dot",backgroundColor:r})=>{const{colorMode:n}=qe(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",a=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return t==="none"?f.jsx(F.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:r,children:e}):f.jsxs(F.Box,{"data-flow-background":t,position:"relative",width:"100%",height:"100%",padding:0,bg:r,children:[f.jsx(F.Box,{position:"absolute",top:0,left:0,right:0,bottom:0,width:"100%",height:"100%",zIndex:0,pointerEvents:"none",style:{backgroundImage:t==="dot"?`radial-gradient(var(${i}) 8%, transparent 8%)`:t==="steel"?`repeating-linear-gradient(45deg, var(${a}) 0, var(${a}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${a}) 1px, transparent 1px), linear-gradient(90deg, var(${a}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),f.jsx(F.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},D_=.4,Xr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},V_=({nodes:e,edges:t})=>{const{themeColor:r,spacing:n,edgeRadius:o,backgroundVariant:i,backgroundSelected:a,setBackgroundSelected:s,edgeColor:c,direction:u,nodeAlignment:l,edgeMode:d,compactPropertyLayout:h,workflowContract:p,parentNodeStyle:g,engineRef:m,callbacks:y,config:v,selectedNodeIds:b,setSelectedNodeIds:w,selectedEdgeId:x,setSelectedEdgeId:C,setIsPerformanceMode:S,isZoomMode:j,setIsZoomMode:T,isMultiSelectMode:k,setIsMultiSelectMode:M,isDragMode:R,setIsDragMode:E,isEdgeHandlesEnabled:P,setIsEdgeHandlesEnabled:I,isArrayNodeMode:q}=qe(),O=_.useRef(null),[V,W]=_.useState(null),te=e.length>200;_.useEffect(()=>{S(te)},[te,S]);const{edgeSep:ne,rankSep:ee,spacingFactor:be}=_.useMemo(()=>{const Z=E0(e.length),D=n<1?.3+.7*n:.5+.5*n;return{edgeSep:Z.edgeSep*D,rankSep:Z.rankSep*D,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n]),{bgColor:le}=nn(r),{canvas:$,borderSecondary:z,colorText:G}=Xe(),N=i==="transparent"?"transparent":v.backgroundColor||$,re=_.useCallback(Z=>{if(!Z)return me(r);switch(Z){case"dark":return me(N);case"light":return me(z);default:return me(Z)}},[r,N,z]),ye=v.colorMode==="dark",de=ye?me("gray.500"):Ct,J=ye?le!=null&&le.includes("gray")?"whitesmoke":re(le):de,X=c?re(c):de,U=_.useMemo(()=>v.initialViewport||{pan:{x:0,y:0},zoom:.01},[]),ue=u==="C"?"LR":u,se=_.useCallback(Z=>{const D={...g,...Z};return{...D,bgColor:D.bgColor||r,bgOpacity:D.outline?0:D.bgOpacity??D_}},[g,r]),we=_.useMemo(()=>{var D;const Z=new Map;for(const Q of e)(D=Q.data)!=null&&D.id&&Z.set(Q.data.id,Q);return Z},[e]),pe=_.useMemo(()=>{var D;const Z=new Map;for(const Q of t)(D=Q.data)!=null&&D.id&&Z.set(Q.data.id,Q);return Z},[t]),ze=_.useCallback(Z=>{var Pe;const D=(Pe=we.get(Z))==null?void 0:Pe.data,Q=se(D==null?void 0:D.viewProps),ke=me(Q.bgColor);return{animated:!!(D!=null&&D.isNodeAnimated)&&!te,animationVariant:D==null?void 0:D.nodeAnimationVariant,animationColor:me(Q.borderColor||r),bgColor:Q.outline?"transparent":ke,bgOpacity:Q.bgOpacity,borderColor:Q.borderColor?me(Q.borderColor):Q.outline&&Q.bgColor==="transparent"?me(r):ke,borderWidth:rn(Q.borderWidth,Xr.borderWidth),borderStyle:Q.borderStyle??Xr.borderStyle,borderRadius:Q.borderRadius??Xr.borderRadius,textColor:Q.textColor?me(Q.textColor):Q.outline||Q.bgColor==="transparent"?me(G):ke,fontSize:Q.fontSize??Xr.fontSize,labelPosition:Q.labelPosition??Xr.labelPosition,labelMargin:Xr.labelMargin,labelBg:gl(re("dark"),ke,Q.bgOpacity)??re("dark"),padding:Q.padding??Xr.padding}},[se,we,G,r,te,re]),Y=_.useMemo(()=>{var Q,ke;const Z=new Map;for(const Pe of t){const Ce=(Q=Pe.data)==null?void 0:Q.source,Be=(ke=Pe.data)==null?void 0:ke.target;if(!Ce||!Be||Ce===Be)continue;const We=Ce<Be?`${Ce}|${Be}`:`${Be}|${Ce}`,Ge=Z.get(We);Ge?Ge.push({id:Pe.data.id,source:Ce}):Z.set(We,[{id:Pe.data.id,source:Ce}])}const D=new Map;for(const[Pe,Ce]of Z){if(Ce.length<2)continue;const Be=Pe.split("|")[0],We=Math.min(20,70/Ce.length);Ce.forEach(({id:Ge,source:Ke},Ne)=>{const ar=50+(Ne-(Ce.length-1)/2)*We;D.set(Ge,(Ke===Be?ar:100-ar)/100)})}return D},[t]),fe=_.useMemo(()=>{const Z=re("dark");return t.filter(D=>{var Q;return((Q=D.data)==null?void 0:Q.id)&&D.data.source&&D.data.target}).map(({data:D})=>{var Ce,Be,We,Ge,Ke,Ne;let Q=Z;const ke=(Be=(Ce=we.get(D.source))==null?void 0:Ce.data)==null?void 0:Be.parent,Pe=(Ge=(We=we.get(D.target))==null?void 0:We.data)==null?void 0:Ge.parent;if(ke&&ke===Pe){const ar=se((Ne=(Ke=we.get(ke))==null?void 0:Ke.data)==null?void 0:Ne.viewProps),Er=gl(Z,me(ar.bgColor),ar.bgOpacity);Er&&(Q=Er)}return{id:D.id,data:D,type:D.type??v.edgeType??"rounded-orthogonal",source:D.source,target:D.target,sourceProperty:D.sourceProperty,targetProperty:D.targetProperty,label:D.label,validationIssue:(d==="auto"||d==="properties")&&(D.sourceProperty!==void 0||D.targetProperty!==void 0)&&p?zu(p,D):void 0,color:c?X:D.color?me(D.color):X,connectorColor:c?X:D.color?me(D.color):J,labelBg:Q,dashed:!!D.isEdgeDashed,animated:!!D.isEdgeAnimated,inverted:!!D.isInverted,turn:Y.get(D.id)??.5}})},[t,X,J,c,Y,v.edgeType,d,p,we,se,re]),_e=_.useMemo(()=>{var D;const Z=new Set;for(const Q of e)(D=Q.data)!=null&&D.parent&&Z.add(Q.data.parent);return Z},[e]),Ie=_.useMemo(()=>{var D;const Z=new Map;for(const Q of t)(D=Q.data)!=null&&D.source&&!Z.has(Q.data.source)&&Z.set(Q.data.source,Q.data);return Z},[t]),Oe=_.useMemo(()=>{const Z={...B_,...v.customViews};return e.filter(D=>{var Q;return(Q=D.data)==null?void 0:Q.id}).map(D=>{var Be,We,Ge,Ke;const Q=_e.has(D.data.id)&&!D.data.parent,ke=Q?D.data.label??D.data.headerTitle??"Container":void 0,Pe=Q?Z.parentContainer:Z[D.data.type]||Z.text,Ce=Ie.get(D.data.id);return{id:D.data.id,collapsed:(Be=D.data.config)==null?void 0:Be.collapsed,parent:D.data.parent,label:ke,animated:!!D.data.isNodeAnimated,animationVariant:D.data.nodeAnimationVariant,hasCollapseControl:((We=D.data.config)==null?void 0:We.collapsed)!==void 0,animationColor:me(((Ge=D.data.viewProps)==null?void 0:Ge.borderColor)||r),animationWidth:rn((Ke=D.data.viewProps)==null?void 0:Ke.borderWidth,8),element:_.createElement(Pe,{...D,isInverted:Ce==null?void 0:Ce.isInverted,isParent:Q,key:`${D.data.id}-${r}`})}})},[e,_e,Ie,r,v.customViews]),Ue=_.useMemo(()=>te?300:e.length>50?150:e.length>20?100:50,[e.length,te]),er=_.useRef(v);er.current=v;const De=_.useRef(j);De.current=j;const tr=_.useRef(q);tr.current=q;const he=_.useRef(b);he.current=b;const Re=_.useRef(x);Re.current=x;const Ze=_.useRef(k);Ze.current=k;const lr=_.useRef(we);lr.current=we;const nr=_.useRef(pe);nr.current=pe;const He=_.useRef(new Map);_.useEffect(()=>{var Q,ke;const Z=new Map([...pe].filter(([,Pe])=>we.has(Pe.data.source)&&we.has(Pe.data.target))),D=He.current;He.current=Z;for(const[Pe,Ce]of D)Z.has(Pe)||(Re.current===Pe&&(C(null),(Q=y.onEdgeDeselect)==null||Q.call(y)),(ke=y.onEdgeRemove)==null||ke.call(y,Pe,Ce.data))},[pe,we,y,C]),_.useEffect(()=>{const Z=O.current;if(!V||!Z)return;let D=null,Q=null,ke=0,Pe=0,Ce=0,Be=0,We=0;const Ge=Ke=>{if(er.current.readOnly)return;Ke.preventDefault(),Ke.stopPropagation(),De.current||Ke.metaKey||Ke.ctrlKey?(Ce+=Ke.deltaY,Be=Ke.clientX,We=Ke.clientY,Q===null&&(Q=requestAnimationFrame(()=>{Q=null;const ar=er.current,Er=V.zoom(),Lr=Ce;Ce=0;let Ir=Er-Lr*.05/100;Ir=Math.max(ar.minZoom??.01,Math.min(ar.maxZoom??1.5,Ir));const lt=Z.getBoundingClientRect();V.zoomAt(Ir,{x:Be-lt.left,y:We-lt.top})}))):(ke+=Ke.deltaX,Pe+=Ke.deltaY,D===null&&(D=requestAnimationFrame(()=>{D=null;const ar=V.pan(),Er=V.zoom(),Lr=.35,Ir=ke,lt=Pe;ke=0,Pe=0,V.pan({x:ar.x+-Ir*Lr/Er,y:ar.y+-lt*Lr/Er})})))};return Z.addEventListener("wheel",Ge,{passive:!1}),()=>{Z.removeEventListener("wheel",Ge),D!==null&&cancelAnimationFrame(D),Q!==null&&cancelAnimationFrame(Q)}},[V]),_.useEffect(()=>{if(v.disableKeyboardShortcuts)return;const Z=D=>{var ke,Pe,Ce,Be;if(er.current.readOnly)return;const Q=D.target;if(!(Q.tagName==="INPUT"||Q.tagName==="TEXTAREA"||Q.isContentEditable)){if((D.key==="z"||D.key==="Z")&&T(!De.current),(D.key==="m"||D.key==="M")&&M(!k),(D.key==="d"||D.key==="D")&&E(!R),(D.key==="v"||D.key==="V")&&!D.repeat&&!D.metaKey&&!D.ctrlKey&&!D.altKey&&Q.tagName!=="SELECT"&&I(!P),(D.key==="Delete"||D.key==="Backspace")&&Re.current){D.preventDefault();const We=Re.current;(Pe=y.onEdgeDelete)==null||Pe.call(y,We,((ke=nr.current.get(We))==null?void 0:ke.data)??{id:We}),C(null);return}if((D.key==="Delete"||D.key==="Backspace")&&he.current.length>0){D.preventDefault();const We=he.current.filter(Ge=>Ge!=="root");if(We.length===0)return;for(const Ge of We){const Ke=(Ce=lr.current.get(Ge))==null?void 0:Ce.data;(Be=y.onNodeDelete)==null||Be.call(y,Ge,Ke||{})}w([])}}};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[k,R,P,I,T,M,E,v.disableKeyboardShortcuts,y,w,C]);const Ee=_.useCallback(Z=>{var D;m.current=Z,W(Z),(D=y.onInit)==null||D.call(y,Z)},[m,y]),ut=_.useCallback(Z=>{var D;return(D=y.onViewportChange)==null?void 0:D.call(y,Z)},[y]),hr=_.useCallback(Z=>{var Q,ke,Pe;const D=((Q=nr.current.get(Z))==null?void 0:Q.data)??{id:Z};if(Re.current===Z&&Ze.current){C(null),(ke=y.onEdgeDeselect)==null||ke.call(y);return}he.current.length&&w([]),C(Z),(Pe=y.onEdgeSelect)==null||Pe.call(y,Z,D)},[y,C,w]),At=_.useCallback(()=>{var Z,D,Q;s(v.bottomBarCollapsed??(he.current.length>0||!!Re.current||!a)),(Z=y.onBackgroundClick)==null||Z.call(y),he.current.length&&(w([]),(D=y.onNodeDeselect)==null||D.call(y)),Re.current&&(C(null),(Q=y.onEdgeDeselect)==null||Q.call(y))},[y,w,C,s,a,v.bottomBarCollapsed]),oe=_.useCallback(Z=>{var ke,Pe;const D=he.current,Q=Z.filter(Ce=>!D.includes(Ce));if(Q.length){w([...D,...Q]);for(const Ce of Q)(Pe=y.onNodeSelect)==null||Pe.call(y,Ce,((ke=lr.current.get(Ce))==null?void 0:ke.data)??{id:Ce})}},[y,w]),Le=_.useCallback((Z,D)=>{var Q,ke;w([Z]),(ke=y.onNodeSelect)==null||ke.call(y,Z,((Q=lr.current.get(Z))==null?void 0:Q.data)??{id:Z},D)},[y,w]),Ye=_.useCallback((Z,D,Q)=>{var ke;return(ke=y.onEdgeCreate)==null?void 0:ke.call(y,Z,D,Q)},[y]),Fe=_.useCallback((Z,D,Q,ke=!1)=>{var Pe,Ce;d==="properties"&&((Pe=y.onNodeCreateRequest)==null?void 0:Pe.call(y,{sourceNodeId:Z,position:D,sourceProperty:Q,reverse:ke}))===!0||Q!==void 0||ke||(Ce=y.onNodeCreate)==null||Ce.call(y,{type:"text",sourceNodeId:Z,position:D,isArrayMode:tr.current})},[y,d]),dr=!v.readOnly&&P&&v.edgeHandles!==!1,yr=i==="transparent"?"none":i;return f.jsx(z_,{pattern:yr,backgroundColor:N,children:f.jsx(F.Box,{ref:O,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:f.jsx(E_,{nodes:Oe,edges:fe,direction:ue,nodeAlignment:l,onContainerCollapse:Z=>{var D,Q;(D=y.onNodeCollapse)==null||D.call(y,Z,!0),(Q=y.onNodeViewToggle)==null||Q.call(y,Z)},selectedNodeIds:b,edgeMode:d,compactPropertyLayout:h,edgeType:v.edgeType,edgeRadius:o,customEdgeTypes:v.customEdgeTypes,edgeReveal:v.edgeReveal,rankSep:ee,edgeSep:ne,spacingFactor:be,compactSpacingScale:n,layoutDebounce:Ue,isPerformanceMode:te,minZoom:v.minZoom??.01,maxZoom:v.maxZoom??1.5,initialViewport:U,fitOnInit:!v.initialViewport,readOnly:!!v.readOnly,containerStyle:ze,lineColor:c?X:J,drawMode:dr,drawHandles:!v.readOnly&&v.edgeHandles!==!1,dragMode:R,multiSelect:!!k,onInit:Ee,onLayoutComplete:y.onLayoutComplete,animateViewport:v.animateViewport,onViewportChange:ut,onBackgroundTap:At,onBoxSelect:oe,onEdgeSelect:hr,onContainerSelect:Le,onEdgeDraw:Ye,onDrawIntoSpace:Fe})})})},Hb=_.memo(V_),W_=".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 my=!1;function G_(){if(my||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=W_+S0+x0+C0+".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}',my=!0}function U_({loading:e=!1,loader:t,...r}){var c,u;const[n,o]=_.useState(null),i=_.useMemo(()=>!!(n!=null&&n.json)&&!!r.json&&m0(n.json,r.json),[n==null?void 0:n.json,r.json]),a=n===null||n.json!==r.json&&!i,s=e||a;return _.useEffect(()=>{!e&&i&&(n==null?void 0:n.json)!==r.json&&o(r)},[e,i,n==null?void 0:n.json,r.json]),_.useEffect(()=>{if(e||!a)return;let l;const d=requestAnimationFrame(()=>{l=requestAnimationFrame(()=>o(r))});return()=>{cancelAnimationFrame(d),l!==void 0&&cancelAnimationFrame(l)}},[e,a,r.json]),f.jsxs(F.Box,{className:r.className,style:r.style,width:"100%",height:"100%",position:"relative","aria-busy":s,children:[f.jsx("div",{style:{width:"100%",height:"100%"},ref:l=>{s?l==null||l.setAttribute("inert",""):l==null||l.removeAttribute("inert")},children:n&&f.jsx(H_,{...a?n:r,className:void 0,style:void 0})}),s&&t!==null&&f.jsx(F.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?f.jsx("span",{children:"Loading diagram..."}):t})]})}function H_({title:e="untitled",json:t,forms:r,nodes:n,edges:o,config:i={},callbacks:a={},className:s,style:c,showBottomBar:u=!0,children:l}){G_();const[d,h]=_.useState(),[p,g]=_.useState(!1),m=i.formSchema??d,y=_.useMemo(()=>t&&r?cm(t,r.state):t,[t,r==null?void 0:r.state]),v=i.direction==="C",b=_.useMemo(()=>{let R,E;return P=>(E=R&&E?b0(R,P,E)??Eu(P,{title:e,isCenter:v}):Eu(P,{title:e,isCenter:v}),R=P,E)},[e,v]),w=_.useMemo(()=>y?b(y):null,[y,b]),x=_.useMemo(()=>r!=null&&r.structured&&!p&&m?um(r.state,r.bindings,m,(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,m,w,n]),C=(x==null?void 0:x.schema)??m,S=(x==null?void 0:x.bindings)??(r==null?void 0:r.bindings),j=_.useMemo(()=>[...(w==null?void 0:w.nodes)??n??[],...(x==null?void 0:x.nodes)??[]].map(E=>{var te,ne,ee,be;const P=t?(te=je(t,E.data.id))==null?void 0:te.$view:(ne=E.data.config)==null?void 0:ne.typeView,I=P&&Jt.includes(P)?P:void 0,q=I?I==="icon-label":(ee=E.data.config)==null?void 0:ee.labelBelow,O=I==="object"?"objectView":I==="text"?"text":q?"arrayView":E.data.type,V=C&&(r?on(S,E.data.id,C):t&&St(t,E.data.id,C)),W=(((be=E.data.config)==null?void 0:be.ports)??[]).map(le=>({...le}));if(x&&V){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[$,z]of Object.entries(V.type.ports??{})){const G=`${z.kind}:${$}`,N=W.find(re=>re.id===G);N?N.label===void 0&&z.label!==void 0&&(N.label=z.label):W.push({id:G,...z.label!==void 0?{label:z.label}:{},role:z.kind==="input"||z.kind==="config"?"target":"source",side:le[z.kind],...z.kind==="config"?{placement:"config"}:{}})}for(const $ of W){const z=W.filter(G=>G.side===$.side);$.position=(z.indexOf($)+1)/(z.length+1)}}return V||q||I?{...E,data:{...E.data,type:O,...r?{description:Object.fromEntries(Object.entries(E.data.description??{}).filter(([le])=>!le.startsWith("$")&&!(x!=null&&x.slots.has(qt(E.data.id,le)))))}:{},config:{...E.data.config,...x&&V?{ports:W}:{},...V?{form:!0}:{},...I?{typeView:I,labelBelow:!!q}:q?{labelBelow:!0}:{}}}}:E}),[w,n,t,C,S,x,i.direction]),T=[...(w==null?void 0:w.edges)??o??[],...(x==null?void 0:x.edges)??[]],k=_.useMemo(()=>{const R=t&&w?Pm(t,w.edges,a,a.onJsonChange,m):{...a};if(x){const E=new Set([...x.nodes.map(P=>P.data.id),...x.edges.map(P=>P.data.id)]);for(const P of Object.keys(R)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(P))continue;const I=R[P];R[P]=(q,...O)=>{if(!E.has(q))return I==null?void 0:I(q,...O)}}}return{...R,onAllNodesIconLabelChange:E=>{var P;g(E),(P=R.onAllNodesIconLabelChange)==null||P.call(R,E)}}},[t,w,a,m,x]),M=_.useMemo(()=>{if(!r)return k;let R=r.state;const E=I=>{if(i.readOnly||i.editable===!1)return;const q=r.onStateChange??r.onChange;if(!q)return;const O=i0(R,I,a.onFormChange);O!==R&&(R=O,q(O,{...I,data:O}))},P=(I,q,O)=>{var W;const V=t&&((W=je(t,I))==null?void 0:W[q]);return!V||typeof V.$state!="string"?!1:(E({address:V.$state,nodeAddress:I,previousValue:je(R,V.$state),value:O,data:R}),!0)};return{...k,onFormChange:E,onNodeCreateRequest:I=>{var V,W;const q=(V=I.sourceProperty)!=null&&V.startsWith("config:")?I.sourceProperty.slice(7):void 0,O=q!==void 0&&(x==null?void 0:x.slots.get(qt(I.sourceNodeId,q)));return O?(O.present||E({data:R,nodeAddress:O.address.split(".").slice(0,-1).join("."),address:O.address,value:Nt(O.type),previousValue:void 0}),!0):((W=k.onNodeCreateRequest)==null?void 0:W.call(k,I))??!1},onNodeDelete:(I,q)=>{var ee,be;if(!(x!=null&&x.nodes.some(le=>le.data.id===I)))return(ee=k.onNodeDelete)==null?void 0:ee.call(k,I,q);const O=x&&[...x.slots.values()].find(le=>le.nodeId===I);if(!O)return(be=k.onNodeDelete)==null?void 0:be.call(k,I,q);const V=O.address.split("."),W=V.pop(),te=V.join("."),ne=je(R,te);E(Array.isArray(ne)?{data:R,nodeAddress:te,address:te,previousValue:ne,value:ne.filter((le,$)=>String($)!==W)}:{data:R,nodeAddress:te,address:O.address,previousValue:je(R,O.address),value:void 0})},onEdgeCreate:(I,q,O)=>{var te,ne;const V=((te=O==null?void 0:O.targetProperty)==null?void 0:te.startsWith("config:"))&&(x==null?void 0:x.slots.get(qt(q,O.targetProperty.slice(7)))),W=x==null?void 0:x.containers.get(I);if(V&&W&&(O==null?void 0:O.sourceProperty)==="output:resource"){const ee=c0(R,W,V);ee!==void 0&&E({data:R,nodeAddress:V.address.split(".").slice(0,-1).join("."),address:V.address,previousValue:je(R,V.address),value:ee});return}V||x!=null&&x.nodes.some(ee=>ee.data.id===I||ee.data.id===q)||(ne=k.onEdgeCreate)==null||ne.call(k,I,q,O)},onEdgeDelete:(I,q)=>{var be;const O=x==null?void 0:x.edges.find(le=>le.data.id===I);if(!O)return(be=k.onEdgeDelete)==null?void 0:be.call(k,I,q);const V=x.slots.get(qt(O.data.target,O.data.targetProperty.slice(7))),W=V.address.split("."),te=W.pop(),ne=W.join("."),ee=je(R,ne);E(Array.isArray(ee)?{data:R,nodeAddress:ne,address:ne,previousValue:ee,value:ee.filter((le,$)=>String($)!==te)}:{data:R,nodeAddress:ne,address:V.address,previousValue:je(R,V.address),value:void 0})},onNodeContentChange:(I,q)=>{var O,V;P(I,"$content",q)?(O=a.onNodeContentChange)==null||O.call(a,I,q):(V=k.onNodeContentChange)==null||V.call(k,I,q)},onNodeLabelChange:(I,q)=>{var O,V;P(I,"$label",q)?(O=a.onNodeLabelChange)==null||O.call(a,I,q):(V=k.onNodeLabelChange)==null||V.call(k,I,q)}}},[k,r,t,a,x,i.readOnly,i.editable]);return f.jsx(wr.Provider,{value:{data:(r==null?void 0:r.state)??t,viewData:t,bindings:S,references:r==null?void 0:r.references,structured:x,renderForm:r==null?void 0:r.renderForm,editable:r?!!(r.onStateChange??r.onChange):!!a.onJsonChange,schema:C,setSchema:R=>{var E;h(R),(E=a.onFormSchemaChange)==null||E.call(a,R)},callbacks:M},children:f.jsx(Ey,{config:x?{...i,formSchema:C}:i,callbacks:M,nodes:j,edges:T,children:f.jsxs(F.Box,{className:s,"data-flow-diagram":"",style:c,width:"100%",height:"100%",position:"relative",overflow:"hidden",css:{"& input, & textarea, & select":{outline:"none !important",boxShadow:"none !important"}},children:[f.jsx(Hb,{nodes:j,edges:T}),u&&f.jsx(jm,{}),l]})})})}function K_(e){return Tu(JSON.parse(e))}function Tu(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 J_(e){return{replaceJson(t){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const r=Tu(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=Tu(t);return e.onStateChange(r,{address:"root",nodeAddress:"root",previousValue:e.state,value:r,data:r}),r}}}function Z_(e,t){const r=(n,o)=>{if(n===null||typeof n!="object")return typeof n==typeof o?n:void 0;if(!(!o||typeof o!="object"))return Array.isArray(n)?Array.isArray(o)?n.map((i,a)=>r(i,o[a])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,a])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i.startsWith("$")&&i!=="$")return JSON.stringify(a)===JSON.stringify(o[i])?[[i,a]]:[];const s=r(a,o[i]);return s===void 0?[]:[[i,s]]}))};return r(e,t)??{}}function gn(e){let t="",r=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},a=()=>{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{}},s=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(a,e.intervalMs??150))}};return{snapshot:s,append(c){s(t+c)},flush:a,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 Y_(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=gn(e),i=0,a=!1,s=!1,c;const u=Math.max(1,Math.ceil(t.length*r/n)),l=()=>e.onChange({position:i,total:t.length,playing:a}),d=()=>{clearTimeout(c),c=void 0},h=(m=!1)=>{o.snapshot(t.slice(0,i)),i===t.length?(a=!1,d(),o.finish()):m&&o.flush()},p=m=>{a=!1,d(),o.cancel(),l(),e.onError(m)},g=()=>{if(c=void 0,!(!a||s)){i=Math.min(t.length,i+u);try{h()}catch(m){p(m);return}l(),a&&(c=setTimeout(g,r))}};return{play(){s||a||(i===t.length&&(o.cancel(),o=gn(e),i=0),a=!0,l(),c=setTimeout(g,r))},pause(){s||(a=!1,d(),o.flush(),l())},seek(m){if(!s){if(!Number.isFinite(m))throw new Error("Playback position must be finite.");d(),i=Math.max(0,Math.min(t.length,Math.round(m))),o.cancel(),o=gn(e);try{h(!0)}catch(y){p(y);return}l(),a&&(c=setTimeout(g,r))}},dispose(){s=!0,a=!1,d(),o.cancel()}}}function X_({nodeAddress:e,expanded:t=!1}){var u;const{data:r,schema:n,bindings:o}=_.useContext(wr),{colorText:i,background:a}=Xe();if((u=o==null?void 0:o[e])!=null&&u.portResources)return null;const s=o&&on(o,e,n);if(!r||!s)return null;const c=je(r,s.address);return!c||typeof c!="object"?null:f.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:me(i),background:me(a),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(s.type.properties).map(l=>{const d=s.fields[l]??{};if(!jn(d.$visibleWhen,r))return null;const h=c[l],p=h==null?"":typeof h=="object"?JSON.stringify(h):String(h);return f.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:[f.jsx("span",{style:{overflowWrap:"anywhere"},children:vr(d.$label??l)}),f.jsx("span",{title:p,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:t?"pre-wrap":"nowrap",overflowWrap:t?"anywhere":void 0},children:p})]},l)})})}exports.BottomBar=jm;exports.CompactPropertyLayoutToggle=Ky;exports.ConnectionsOnlyToggle=y0;exports.DEFAULT_PALETTE=vn;exports.DiagramAppearanceControls=Zy;exports.DynamicIcon=Ar;exports.EdgeTools=ym;exports.EditableLabel=tn;exports.ErrorToast=_m;exports.FlowDiagram=U_;exports.FlowDiagramProvider=Ey;exports.FlowPort=Fb;exports.FlowView=Hb;exports.FormDocumentContext=wr;exports.LIGHT_BLACK=Ct;exports.NODE_TYPE_VIEWS=Jt;exports.NodeBorderRadiusControl=mm;exports.NodeConfigSummary=X_;exports.NodeForm=dm;exports.NodeFormPopover=Bb;exports.NodeIconPicker=Vu;exports.NodeTools=bm;exports.NodeView=Hn;exports.SvgExportButton=wm;exports.Swatches=xt;exports.TEXT_PALETTE=pm;exports.ToolbarCloseButton=_t;exports.ToolbarCommitInput=nt;exports.ToolbarDivider=Bt;exports.ToolbarIconButton=Se;exports.ToolbarRangeInput=Jy;exports.ToolbarScrollContainer=Cm;exports.ToolbarSelect=xr;exports.ToolbarTooltip=Ae;exports.TooltipIconButton=Au;exports.WorkflowControls=Sm;exports.addChild=$u;exports.addConnection=Lu;exports.addTargetEdge=om;exports.addressToPath=qr;exports.applyCollapsed=t0;exports.applyFormChange=Rn;exports.applyStateEdits=o0;exports.bindSqueedCallbacks=Pm;exports.compileSqueed=Eu;exports.connectionIssue=zu;exports.contentObjTheme=Pr;exports.createFlowDiagram=tt;exports.createFlowDocumentActions=J_;exports.createFormNode=km;exports.createJsonPlayback=Y_;exports.createJsonStream=gn;exports.downloadSvg=xm;exports.exportSvg=vm;exports.formValueError=jr;exports.getChakraColorHex=me;exports.getColorVariant=wy;exports.getDarkerHexColor=yn;exports.getInteractionSurface=Vr;exports.getNode=je;exports.parseFlowDocument=K_;exports.parseJsonContract=Fu;exports.parseTypeScriptContract=am;exports.parseTypeScriptForm=Bu;exports.projectJsonPlaybackPreview=Z_;exports.readFormSchema=Du;exports.readWorkflowContract=sm;exports.removeEdge=im;exports.removeNode=nm;exports.resolveEdgeOwner=Xt;exports.resolveStateView=cm;exports.setCollapsed=rm;exports.setEdgeProp=zr;exports.setEdgeStyle=tm;exports.setNodeProp=ur;exports.updateNode=br;exports.useCustomColors=Xe;exports.useEdgeProximity=xy;exports.useFlowData=Hr;exports.useFlowDiagramContext=qe;exports.useNodeViewActions=Kn;exports.useStopPropagation=ul;exports.useThemeContentColors=nn;
280
280
  //# sourceMappingURL=index.cjs.map