@squeed/flow-sdk 2.0.29 → 2.0.31
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/README.md +55 -1
- package/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +6118 -6029
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ux=Object.create;var Lo=Object.defineProperty;var fx=Object.getOwnPropertyDescriptor;var hx=Object.getOwnPropertyNames;var px=Object.getPrototypeOf,gx=Object.prototype.hasOwnProperty;var yx=(e,r,t)=>r in e?Lo(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var mx=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of hx(r))!gx.call(e,o)&&o!==t&&Lo(e,o,{get:()=>r[o],enumerable:!(n=fx(r,o))||n.enumerable});return e};var nt=(e,r,t)=>(t=e!=null?ux(px(e)):{},mx(r||!e||!e.__esModule?Lo(t,"default",{value:e,enumerable:!0}):t,e));var Nt=(e,r,t)=>yx(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),V=require("@chakra-ui/react"),j=require("react"),Dr=require("react-dom"),Z=require("react-icons/pi"),Sm=require("@emotion/react"),bx=require("@emotion/styled"),vx=require("react-icons/tb"),xx=require("markdown-to-jsx/react"),jm=e=>e&&e.__esModule?e:{default:e},ao=jm(bx),wx=jm(xx);function Cx(e,r){let t,n,o,i;const s=(l=t)=>!!l&&["completed","failed","cancelled"].includes(l.status),a=()=>{const l=i;i=void 0,l==null||l()},c=l=>{if(!n||n.signal.aborted||!t||l.executionId!==t.executionId||s())return;const{step:d,...u}=l;t={...t,...u,steps:d?{...t.steps,[d.id]:{...t.steps[d.id],...d}}:t.steps},n.state=t,s()&&a(),r(t)};return{getState:()=>t,async run(l,d=crypto.randomUUID()){if(n&&!n.signal.aborted&&!s())throw new Error("An execution is already active.");o==null||o.abort(),a(),o=new AbortController;const u={executionId:d,input:l,signal:o.signal,state:{executionId:d,status:"subscribing",steps:{}}};n=u,t=u.state,r(t);try{const h=await e.subscribe(u,m=>{n===u&&c(m)});if(n!==u||u.signal.aborted||s())return h(),u.state;if(i=h,c({executionId:d,status:"running"}),n!==u||u.signal.aborted||s(u.state))return u.state;const p=await e.execute(u);n===u&&p&&c(p)}catch(h){if(s(u.state))return u.state;throw n===u&&!u.signal.aborted&&c({executionId:d,status:"failed",error:h instanceof Error?h.message:String(h)}),h}return u.state},async cancel(){const l=n;if(!(!l||l.signal.aborted||s())){if(!e.cancel)throw new Error("This adapter does not support cancellation.");await e.cancel(l),n===l&&c({executionId:l.executionId,status:"cancelled"})}},dispose(){o==null||o.abort(),n=void 0,a()}}}function _m({edge:e,enabled:r,bounds:t,inside:n=[],threshold:o=80}){const[i,s]=j.useState(!1),[a,c]=j.useState(!1),l=j.useRef(n);return l.current=n,j.useEffect(()=>{if(!r)return;const d=()=>{const h=document.querySelectorAll(':popover-open, dialog[open], [role="dialog"], [role="menu"], [role="listbox"]');c(Array.from(h).some(p=>p.getClientRects().length>0&&!p.closest('[hidden], [aria-hidden="true"], [data-state="closed"]')&&getComputedStyle(p).visibility==="visible"))},u=new MutationObserver(d);return u.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["open","hidden","aria-hidden","data-state"]}),document.addEventListener("toggle",d,!0),d(),()=>{u.disconnect(),document.removeEventListener("toggle",d,!0)}},[r]),j.useEffect(()=>{const d=h=>{var b;const p=(b=t.current)==null?void 0:b.getBoundingClientRect();if(!p)return;const m=h.target instanceof Node?h.target:null,y=!!m&&l.current.some(x=>{var w;return(w=x.current)==null?void 0:w.contains(m)}),g=e==="bottom"?p.bottom-h.clientY:h.clientY-p.top,v=h.clientX>=p.left&&h.clientX<=p.right&&g>=0&&g<=o;s(y||v)},u=()=>s(!1);return document.addEventListener("pointermove",d,!0),document.addEventListener("pointerdown",d,!0),document.documentElement.addEventListener("pointerleave",u),()=>{document.removeEventListener("pointermove",d,!0),document.removeEventListener("pointerdown",d,!0),document.documentElement.removeEventListener("pointerleave",u)}},[e,t,o]),r&&(i||a)}const Jr="#c6c6c6";function eo(e,r=.2){const t=e.replace(/^#/,""),n=parseInt(t,16);let o=n>>16&255,i=n>>8&255,s=n&255;return o=Math.max(0,Math.floor(o*(1-r))),i=Math.max(0,Math.floor(i*(1-r))),s=Math.max(0,Math.floor(s*(1-r))),"#"+((1<<24)+(o<<16)+(i<<8)+s).toString(16).slice(1).toUpperCase()}function xu(e,r,t){const n=a=>{const c=/^#?([0-9a-f]{6})$/i.exec((a==null?void 0:a.trim())??"");return c?parseInt(c[1],16):null},o=n(e),i=n(r);if(o===null||i===null)return null;const s=a=>Math.round((o>>a&255)*(1-t)+(i>>a&255)*t);return"#"+((1<<24)+(s(16)<<16)+(s(8)<<8)+s(0)).toString(16).slice(1).toUpperCase()}const Zt=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:eo(e,.1),border:eo(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"},Em=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let r=e;if(r!=null&&r.startsWith("#"))return{secondary:eo(e)};let t=String(Number(e.slice(-3))+200);t=e.slice(0,-3).concat(t);let n=String(Number(e.slice(-3))-100);return n=e.slice(0,-3).concat(n),{primary:r,secondary:t,light:n}},wu={red:{50:"#FFF5F5",100:"#FED7D7",200:"#FEB2B2",300:"#FC8181",400:"#F56565",500:"#E53E3E",600:"#C53030",700:"#9B2C2C",800:"#822727",900:"#63171B"},orange:{50:"#FFFAF0",100:"#FEEBC8",200:"#FBD38D",300:"#F6AD55",400:"#ED8936",500:"#DD6B20",600:"#C05621",700:"#9C4221",800:"#7B341E",900:"#652B19"},yellow:{50:"#FFFFF0",100:"#FEFCBF",200:"#FAF089",300:"#F6E05E",400:"#ECC94B",500:"#D69E2E",600:"#B7791F",700:"#975A16",800:"#744210",900:"#5F370E"},green:{50:"#F0FFF4",100:"#C6F6D5",200:"#9AE6B4",300:"#68D391",400:"#48BB78",500:"#38A169",600:"#2F855A",700:"#276749",800:"#22543D",900:"#1C4532"},teal:{50:"#E6FFFA",100:"#B2F5EA",200:"#81E6D9",300:"#4FD1C5",400:"#38B2AC",500:"#319795",600:"#2C7A7B",700:"#285E61",800:"#234E52",900:"#1D4044"},blue:{50:"#EBF8FF",100:"#BEE3F8",200:"#90CDF4",300:"#63B3ED",400:"#4299E1",500:"#3182CE",600:"#2B6CB0",700:"#2C5282",800:"#2A4365",900:"#1A365D"},cyan:{50:"#EDFDFD",100:"#C4F1F9",200:"#9DECF9",300:"#76E4F7",400:"#0BC5EA",500:"#00B5D8",600:"#00A3C4",700:"#0987A0",800:"#086F83",900:"#065666"},purple:{50:"#FAF5FF",100:"#E9D8FD",200:"#D6BCFA",300:"#B794F4",400:"#9F7AEA",500:"#805AD5",600:"#6B46C1",700:"#553C9A",800:"#44337A",900:"#322659"},pink:{50:"#FFF5F7",100:"#FED7E2",200:"#FBB6CE",300:"#F687B3",400:"#ED64A6",500:"#D53F8C",600:"#B83280",700:"#97266D",800:"#702459",900:"#521B41"},gray:{50:"#F7FAFC",100:"#EDF2F7",200:"#E2E8F0",300:"#CBD5E0",400:"#A0AEC0",500:"#718096",600:"#4A5568",700:"#2D3748",800:"#1A202C",900:"#171923",950:"#0d1117"}},Me=(e,r)=>{var i;if(e==="transparent"||e!=null&&e.startsWith("#")||e!=null&&e.startsWith("var(--"))return e;if(!e)return"whitesmoke";const t=e.replace(/\./g,"-");try{const a=getComputedStyle(document.documentElement).getPropertyValue(`--chakra-colors-${t}`).trim();if(a&&a!=="")return a}catch{}const[n,o]=e.split(".");return n&&o&&((i=wu[n])!=null&&i[Number(o)])?wu[n][Number(o)]:`var(--chakra-colors-${t})`},Sx=Sm.keyframes`
|
|
2
2
|
0%, 100% { box-shadow: var(--flow-rest-shadow); }
|
|
3
3
|
25%, 50% { box-shadow: var(--flow-hover-shadow); }
|
|
4
|
-
`,
|
|
4
|
+
`,jx=Sm.keyframes`
|
|
5
5
|
from { box-shadow: var(--flow-start-shadow); }
|
|
6
6
|
to { box-shadow: var(--flow-rest-shadow); }
|
|
7
|
-
`;function _m(e,r=!0,t="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,s=`0 0 0 ${r?8:0}px ${o}`,a=`0 0 0 8px ${o}`;return{boxShadow:s,css:{"--flow-rest-shadow":a,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[t]:{boxShadow:a,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${vx} 1200ms steps(10, end) 600ms`:"none"}}}}}}function fr(e,r){const{boxShadow:t,css:n}=_m(e,!1),o=n["@media (hover: hover)"]["&:hover"];return{borderWidth:"1px",borderStyle:"solid",borderColor:"transparent",boxShadow:t,...n,"--flow-start-shadow":t,"@media (hover: hover)":{"&:hover":{...o,borderColor:r,"@media (prefers-reduced-motion: no-preference)":{animation:`${xx} 600ms steps(5, end)`}}}}}const Em=_.createContext(null),km=_.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function yr(){return _.useContext(km)}function Ze(){const e=_.useContext(Em);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function Rm({config:e,callbacks:r,nodes:t=[],edges:n=[],children:o}){var $e;const i=_.useMemo(()=>{var _e,Xe,Qe;const U=new Map;for(const He of t)(_e=He.data)!=null&&_e.id&&U.set(He.data.id,He);const he=new Map;for(const He of n)(Xe=He.data)!=null&&Xe.id&&he.set(He.data.id,He);const Se=new Set;for(const He of t)(Qe=He.data)!=null&&Qe.parent&&Se.add(He.data.parent);return{nodeById:U,edgeById:he,parentIds:Se}},[t,n]),s=_.useRef(null),[a,c]=_.useState([]),[l,d]=_.useState(null),[u,h]=_.useState(!0),[p,m]=_.useState(!1),[y,g]=_.useState(!0),[v,b]=_.useState(!1),[x,w]=_.useState(!1),[C,S]=_.useState(!0),[j,P]=_.useState(!1),[E,O]=_.useState(()=>{var U;return(U=e.nodeGrid)!=null&&U.enabled?{...e.nodeGrid.options,...e.nodeGrid.order?{order:e.nodeGrid.order}:{}}:null}),A=_.useRef(E),[R,M]=_.useState(E??(($e=e.nodeGrid)==null?void 0:$e.options)??{gaps:15,fill:!1,padding:0}),[T,N]=_.useState(()=>new Set),$=_.useCallback(U=>{var he;!!(U!=null&&U.fill)!=!!((he=A.current)!=null&&he.fill)&&N(new Set),A.current=U,U&&M(U),O(U)},[]),[I,K]=_.useState("auto"),[ie,se]=_.useState(!1),te=e.compactPropertyLayout??ie,[me,ve]=_.useState({}),F=e.nodeViewModes??me,[D,W]=_.useState(e.allNodesIconLabel);_.useEffect(()=>W(e.allNodesIconLabel),[e.allNodesIconLabel]);const[B,le]=_.useState({}),Y=_.useCallback((U,he)=>{le(Se=>{const _e={...Se};for(const Xe of U)he===void 0?delete _e[Xe]:_e[Xe]=he;return _e})},[]),ce=[...i.nodeById.values()].filter(U=>{var he;return i.parentIds.has(U.data.id)||((he=U.data.config)==null?void 0:he.parentContainer)||U.data.type==="objectView"||U.data.type==="arrayView"||U.data.type==="grid"}),ue=ce.every(U=>{var he,Se,_e;return i.parentIds.has(U.data.id)||(he=U.data.config)!=null&&he.parentContainer?!!((Se=U.data.config)!=null&&Se.collapsed):F[U.data.id]==="icon-label"||U.data.type==="grid"&&F[U.data.id]===void 0||((_e=U.data.config)==null?void 0:_e.labelBelow)&&F[U.data.id]!=="properties"}),xe=D??e.allNodesIconLabel??ue,[Ce,ye]=_.useState("normal"),[pe,X]=_.useState(),L=e.edgeRadius??pe,ae=L!==void 0&&Number.isFinite(L)?Math.min(500,Math.max(0,L)):void 0,[H,fe]=_.useState(),be=e.spacing??Ce,Ne=typeof be=="number"?Number.isFinite(be)?Math.min(2,Math.max(e.nodeGridSpacing==="layout"?0:.5,be)):1:be==="compact"?.5:be==="spacious"?2:1,Le=e.backgroundVariant??H??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[Be,tt]=_.useState(),Je=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:Be,[yt,Ye]=_.useState("blue.500"),[nt,ht]=_.useState(!1),Te=_.useRef(r);Te.current=r;const Ve=_.useMemo(()=>{const U=he=>(...Se)=>{var _e,Xe;return(Xe=(_e=Te.current)==null?void 0:_e[he])==null?void 0:Xe.call(_e,...Se)};return{onNodeSelect:U("onNodeSelect"),onNodesCopy:U("onNodesCopy"),onNodesDuplicate:U("onNodesDuplicate"),onBackgroundClick:U("onBackgroundClick"),onBottomBarCollapsedChange:U("onBottomBarCollapsedChange"),onNodeGridZoomOut:U("onNodeGridZoomOut"),onNodeGridFillRequest:U("onNodeGridFillRequest"),onNodeGridModeRequest:U("onNodeGridModeRequest"),onNodeGridDrop:U("onNodeGridDrop"),onNodeParentChange:U("onNodeParentChange"),onNodeDeselect:U("onNodeDeselect"),onNodeDoubleClick:U("onNodeDoubleClick"),onNodeViewToggle:U("onNodeViewToggle"),onNodeTypeViewChange:U("onNodeTypeViewChange"),onNodeCreate:U("onNodeCreate"),onNodeCreateRequest:U("onNodeCreateRequest"),onNodeDelete:U("onNodeDelete"),onNodeLabelChange:U("onNodeLabelChange"),onNodeSubtitleChange:U("onNodeSubtitleChange"),onNodeContentChange:U("onNodeContentChange"),onNodeCollapse:U("onNodeCollapse"),onNodeColorChange:U("onNodeColorChange"),onNodeBorderColorChange:U("onNodeBorderColorChange"),onNodeBorderStyleChange:U("onNodeBorderStyleChange"),onNodeBorderWidthChange:U("onNodeBorderWidthChange"),onNodeBorderRadiusChange:(he,Se)=>{var _e,Xe,Qe;(_e=A.current)!=null&&_e.fill&&N(He=>new Set([...He,he])),(Qe=(Xe=Te.current).onNodeBorderRadiusChange)==null||Qe.call(Xe,he,Se)},onNodeIconChange:U("onNodeIconChange"),onNodeOutlineChange:U("onNodeOutlineChange"),onNodeAnimationChange:U("onNodeAnimationChange"),onNodeAnimationVariantChange:U("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:U("onEdgeAnimationVariantChange"),onNodeHoverAction:U("onNodeHoverAction"),onEdgeCreate:U("onEdgeCreate"),onEdgeSelect:U("onEdgeSelect"),onEdgeDeselect:U("onEdgeDeselect"),onEdgeRemove:U("onEdgeRemove"),onEdgeDelete:U("onEdgeDelete"),onEdgeColorChange:U("onEdgeColorChange"),onEdgeTypeChange:U("onEdgeTypeChange"),onEdgeIconChange:U("onEdgeIconChange"),onEdgeLabelChange:U("onEdgeLabelChange"),onEdgeStyleChange:U("onEdgeStyleChange"),onViewportChange:U("onViewportChange"),onDirectionChange:U("onDirectionChange"),onThemeColorChange:U("onThemeColorChange"),onSpacingChange:U("onSpacingChange"),onEdgeRadiusChange:U("onEdgeRadiusChange"),onBackgroundVariantChange:U("onBackgroundVariantChange"),onEdgeModeChange:U("onEdgeModeChange"),onCompactPropertyLayoutChange:U("onCompactPropertyLayoutChange"),onWorkflowContractChange:U("onWorkflowContractChange"),onWorkflowConfigurationOpen:r.onWorkflowConfigurationOpen?U("onWorkflowConfigurationOpen"):void 0,onArrayModeChange:U("onArrayModeChange"),onInit:U("onInit"),onLayoutComplete:U("onLayoutComplete"),onJsonChange:U("onJsonChange")}},[]),st=e.themeColor||yt,[ct,zt]=_.useState(""),Ge=e.edgeColor??ct,De=e.colorMode||"light",Wt=e.direction||"LR",lt=e.nodeAlignment??"center",nr=e.edgeMode==="workflow"?"nodes":e.edgeMode??I,Ut=e.readOnly??!1,Mr=JSON.stringify(e.parentNodeStyle??null),Et=_.useMemo(()=>e.parentNodeStyle,[Mr]),Ht=e.isZoomMode!==void 0?e.isZoomMode:u,Yt=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,Tr=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:v,br=e.isDragMode!==void 0?e.isDragMode:y,Fe=_.useRef(e);Fe.current=e;const re=_.useMemo(()=>({get direction(){return Fe.current.direction},get nodeAlignment(){return Fe.current.nodeAlignment},get edgeMode(){return Fe.current.edgeMode},get compactPropertyLayout(){return Fe.current.compactPropertyLayout},get bottomBarCollapsed(){return Fe.current.bottomBarCollapsed},get bottomBarNavigation(){return Fe.current.bottomBarNavigation},get bottomBarFill(){return Fe.current.bottomBarFill},get bottomBarCollision(){return Fe.current.bottomBarCollision},get nodeGridConnections(){return Fe.current.nodeGridConnections},get nodeGrid(){return Fe.current.nodeGrid},get edgeType(){return Fe.current.edgeType},get edgeReveal(){return Fe.current.edgeReveal},get customEdgeTypes(){return Fe.current.customEdgeTypes},get themeColor(){return Fe.current.themeColor},get colorMode(){return Fe.current.colorMode},get readOnly(){return Fe.current.readOnly},get editable(){return Fe.current.editable},get minZoom(){return Fe.current.minZoom},get nodeGridSpacing(){return Fe.current.nodeGridSpacing},get maxZoom(){return Fe.current.maxZoom},get backgroundPattern(){return Fe.current.backgroundPattern},get edgeColor(){return Fe.current.edgeColor},get parentNodeStyle(){return Fe.current.parentNodeStyle},get backgroundColor(){return Fe.current.backgroundColor},get edgeHandles(){return Fe.current.edgeHandles},get initialViewport(){return Fe.current.initialViewport},get animateViewport(){return Fe.current.animateViewport},get disableAnimations(){return Fe.current.disableAnimations},get nodeOverlayActions(){return Fe.current.nodeOverlayActions},get renderNodeOverlay(){return Fe.current.renderNodeOverlay},get renderSelectedNodeToolbar(){return Fe.current.renderSelectedNodeToolbar},get renderSelectedEdgeToolbar(){return Fe.current.renderSelectedEdgeToolbar},get renderBottomBar(){return Fe.current.renderBottomBar},get bottomBarExtra(){return Fe.current.bottomBarExtra},get selectionToolbar(){return Fe.current.selectionToolbar},get customViews(){return Fe.current.customViews},get disableKeyboardShortcuts(){return Fe.current.disableKeyboardShortcuts},get isZoomMode(){return Fe.current.isZoomMode},get isMultiSelectMode(){return Fe.current.isMultiSelectMode},get isEdgeHandlesEnabled(){return Fe.current.isEdgeHandlesEnabled},get isDragMode(){return Fe.current.isDragMode}}),[]),G=_.useCallback((U,he)=>{var Se;if(he!=="default"&&he!=="properties"&&he!=="icon-label")throw new Error("Unknown node view mode.");W(_e=>_e??xe),ve(_e=>_e[U]===he?_e:{..._e,[U]:he}),(Se=r.onNodeViewModeChange)==null||Se.call(r,U,he)},[r.onNodeViewModeChange,xe]),ne=_.useMemo(()=>({allNodesIconLabel:xe,setAllNodesIconLabel:U=>{var he,Se,_e,Xe,Qe;if(W(U),!U)for(const[He,kt]of Object.entries(F))kt==="icon-label"&&!i.nodeById.has(He)&&G(He,"default");for(const He of ce)i.parentIds.has(He.data.id)||(he=He.data.config)!=null&&he.parentContainer?!Ut&&!!((Se=He.data.config)!=null&&Se.collapsed)!==U&&((_e=r.onNodeCollapse)==null||_e.call(r,He.data.id,U)):G(He.data.id,U?"icon-label":(Xe=He.data.config)!=null&&Xe.labelBelow?"properties":"default");(Qe=r.onAllNodesIconLabelChange)==null||Qe.call(r,U)},nodeViewModes:F,setNodeViewMode:G,nodeRadiusPreviews:B,setNodeRadiusPreview:Y,spacing:Ne,setSpacing:ye,edgeRadius:ae,setEdgeRadius:X,backgroundVariant:Le,setBackgroundVariant:fe,themeColor:st,setThemeColor:Ye,backgroundSelected:nt,setBackgroundSelected:ht,edgeColor:Ge,setEdgeColor:U=>{var he;zt(U),(he=r.onGraphEdgeColorChange)==null||he.call(r,U)},colorMode:De,direction:Wt,nodeAlignment:lt,edgeMode:nr,setEdgeMode:K,compactPropertyLayout:te,setCompactPropertyLayout:se,workflowContract:Je,setWorkflowContract:tt,parentNodeStyle:Et,selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isZoomMode:Ht,setIsZoomMode:h,isMultiSelectMode:Yt,setIsMultiSelectMode:m,isDragMode:br,setIsDragMode:g,isEdgeHandlesEnabled:Tr,setIsEdgeHandlesEnabled:b,isArrayNodeMode:x,setIsArrayNodeMode:w,isPinned:C,setIsPinned:S,isPerformanceMode:j,setIsPerformanceMode:P,nodeGridOptions:E,setNodeGridOptions:$,lastNodeGridOptions:R,fillRadiusEditedIds:T,setFillRadiusEditedIds:N,engineRef:s,callbacks:Ve,config:re,readOnly:Ut}),[xe,i,G,r.onNodeCollapse,r.onAllNodesIconLabelChange,r.onGraphEdgeColorChange,F,r.onNodeViewModeChange,B,Y,st,Ne,Le,ae,e.backgroundColor,nt,Ge,De,Wt,lt,nr,Je,Et,a,l,Ht,Yt,br,Tr,x,C,j,E,R,T,Ut,e.edgeHandles,e.edgeType,e.edgeReveal,e.animateViewport,e.disableAnimations,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.bottomBarCollapsed,e.bottomBarNavigation,e.bottomBarFill,e.bottomBarCollision,e.nodeGridSpacing,e.nodeGridConnections,e.compactPropertyLayout,te,Ve,re]);return f.jsx(Em.Provider,{value:ne,children:f.jsx(km.Provider,{value:i,children:o})})}function xt(e,r,t){return e?t:r}function Tn(e){const[r]=(e==null?void 0:e.split("."))||[],{secondary:t}=jm(e),n=Jt(r).background,o=Jt(r).highlight,i=Jt(r).border,s=Jt(r).property,a=Jt(r).property;let c=Jt(r).background,l=Jt(r).highlight;return c=e==="transparent"?e:Ae(c)+50,l=e==="transparent"?e:Ae(l)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:s,propertyColor:a,secondary:t,bgColorFaint:c,highlightColorFaint:l}}function at(e=null){const{colorMode:r}=Ze(),t=e==null?void 0:e.includes("gray"),n=r==="dark",o=xt(n,"white","gray.900"),i=xt(n,"gray.100","gray.800"),s=xt(n,"gray.200","blackAlpha.400"),a=xt(n,"gray.200","blackAlpha.600"),c=xt(n,"gray.500","gray.700"),l=xt(n,"gray.700","gray.700"),d=xt(n,"gray.900","gray.900"),u=xt(n,"gray.400","gray.500"),h=xt(n,"gray.400","gray.500"),p=xt(n,"gray.900","gray.200"),m=xt(n,t?"gray.900":"gray.200",t?"gray.200":"gray.900"),y=xt(n,"gray.900","gray.200"),g=xt(n,e&&"#000000",e||"#ffffff"),v=xt(n,e||"#ffffff",e?"#000000":"#ffffff"),b=l,x=xt(n,"gray.300","gray.800"),w=xt(n,"white","blackAlpha.400"),C=xt(n,"green.100","green.700");return{canvas:o,background:i,backgroundSecondary:s,darkBackgroundSecondary:a,border:c,darkColor:d,backgroundWhiteColor:w,borderSecondary:l,colorActive:u,colorInactive:h,iconColor:y,moreIconColor:b,colorText:p,themedColorText:m,logoColor:g,logoColorSecondary:v,darkColorActive:x,greenColor:C}}var un=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(un||{});const vd=["","icon-label","object","text","grid","parent"];var wx=typeof global=="object"&&global&&global.Object===Object&&global,Cx=typeof self=="object"&&self&&self.Object===Object&&self,Sx=wx||Cx||Function("return this")(),Vr=Sx.Symbol,Am=Object.prototype,jx=Am.hasOwnProperty,_x=Am.toString,ln=Vr?Vr.toStringTag:void 0;function Ex(e){var r=jx.call(e,ln),t=e[ln];try{e[ln]=void 0;var n=!0}catch{}var o=_x.call(e);return n&&(r?e[ln]=t:delete e[ln]),o}var kx=Object.prototype,Rx=kx.toString;function Ax(e){return Rx.call(e)}var Px="[object Null]",Ix="[object Undefined]",wu=Vr?Vr.toStringTag:void 0;function Mx(e){return e==null?e===void 0?Ix:Px:wu&&wu in Object(e)?Ex(e):Ax(e)}function Tx(e){return e!=null&&typeof e=="object"}var Ox="[object Symbol]";function Nx(e){return typeof e=="symbol"||Tx(e)&&Mx(e)==Ox}function $x(e,r){for(var t=-1,n=e==null?0:e.length,o=Array(n);++t<n;)o[t]=r(e[t],t,e);return o}var et=Array.isArray,Cu=Vr?Vr.prototype:void 0,Su=Cu?Cu.toString:void 0;function Pm(e){if(typeof e=="string")return e;if(et(e))return $x(e,Pm)+"";if(Nx(e))return Su?Su.call(e):"";var r=e+"";return r=="0"&&1/e==-1/0?"-0":r}function xd(e){return e==null?"":Pm(e)}function qx(e,r,t){var n=-1,o=e.length;r<0&&(r=-r>o?0:o+r),t=t>o?o:t,t<0&&(t+=o),o=r>t?0:t-r>>>0,r>>>=0;for(var i=Array(o);++n<o;)i[n]=e[n+r];return i}function Lx(e,r,t){var n=e.length;return t=t===void 0?n:t,!r&&t>=n?e:qx(e,r,t)}var Fx="\\ud800-\\udfff",zx="\\u0300-\\u036f",Bx="\\ufe20-\\ufe2f",Dx="\\u20d0-\\u20ff",Vx=zx+Bx+Dx,Gx="\\ufe0e\\ufe0f",Wx="\\u200d",Ux=RegExp("["+Wx+Fx+Vx+Gx+"]");function Im(e){return Ux.test(e)}function Hx(e){return e.split("")}var Mm="\\ud800-\\udfff",Kx="\\u0300-\\u036f",Jx="\\ufe20-\\ufe2f",Zx="\\u20d0-\\u20ff",Xx=Kx+Jx+Zx,Yx="\\ufe0e\\ufe0f",Qx="["+Mm+"]",cd="["+Xx+"]",ld="\\ud83c[\\udffb-\\udfff]",e0="(?:"+cd+"|"+ld+")",Tm="[^"+Mm+"]",Om="(?:\\ud83c[\\udde6-\\uddff]){2}",Nm="[\\ud800-\\udbff][\\udc00-\\udfff]",t0="\\u200d",$m=e0+"?",qm="["+Yx+"]?",r0="(?:"+t0+"(?:"+[Tm,Om,Nm].join("|")+")"+qm+$m+")*",n0=qm+$m+r0,o0="(?:"+[Tm+cd+"?",cd,Om,Nm,Qx].join("|")+")",i0=RegExp(ld+"(?="+ld+")|"+o0+n0,"g");function a0(e){return e.match(i0)||[]}function s0(e){return Im(e)?a0(e):Hx(e)}function c0(e){return function(r){r=xd(r);var t=Im(r)?s0(r):void 0,n=t?t[0]:r.charAt(0),o=t?Lx(t,1).join(""):r.slice(1);return n[e]()+o}}var l0=c0("toUpperCase");function d0(e,r,t,n){for(var o=-1,i=e==null?0:e.length;++o<i;)t=r(t,e[o],o,e);return t}function u0(e){return function(r){return e==null?void 0:e[r]}}var f0={À:"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"},h0=u0(f0),p0=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,g0="\\u0300-\\u036f",y0="\\ufe20-\\ufe2f",m0="\\u20d0-\\u20ff",b0=g0+y0+m0,v0="["+b0+"]",x0=RegExp(v0,"g");function w0(e){return e=xd(e),e&&e.replace(p0,h0).replace(x0,"")}var C0=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function S0(e){return e.match(C0)||[]}var j0=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function _0(e){return j0.test(e)}var Lm="\\ud800-\\udfff",E0="\\u0300-\\u036f",k0="\\ufe20-\\ufe2f",R0="\\u20d0-\\u20ff",A0=E0+k0+R0,Fm="\\u2700-\\u27bf",zm="a-z\\xdf-\\xf6\\xf8-\\xff",P0="\\xac\\xb1\\xd7\\xf7",I0="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",M0="\\u2000-\\u206f",T0=" \\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",Bm="A-Z\\xc0-\\xd6\\xd8-\\xde",O0="\\ufe0e\\ufe0f",Dm=P0+I0+M0+T0,Vm="['’]",ju="["+Dm+"]",N0="["+A0+"]",Gm="\\d+",$0="["+Fm+"]",Wm="["+zm+"]",Um="[^"+Lm+Dm+Gm+Fm+zm+Bm+"]",q0="\\ud83c[\\udffb-\\udfff]",L0="(?:"+N0+"|"+q0+")",F0="[^"+Lm+"]",Hm="(?:\\ud83c[\\udde6-\\uddff]){2}",Km="[\\ud800-\\udbff][\\udc00-\\udfff]",Nr="["+Bm+"]",z0="\\u200d",_u="(?:"+Wm+"|"+Um+")",B0="(?:"+Nr+"|"+Um+")",Eu="(?:"+Vm+"(?:d|ll|m|re|s|t|ve))?",ku="(?:"+Vm+"(?:D|LL|M|RE|S|T|VE))?",Jm=L0+"?",Zm="["+O0+"]?",D0="(?:"+z0+"(?:"+[F0,Hm,Km].join("|")+")"+Zm+Jm+")*",V0="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",G0="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",W0=Zm+Jm+D0,U0="(?:"+[$0,Hm,Km].join("|")+")"+W0,H0=RegExp([Nr+"?"+Wm+"+"+Eu+"(?="+[ju,Nr,"$"].join("|")+")",B0+"+"+ku+"(?="+[ju,Nr+_u,"$"].join("|")+")",Nr+"?"+_u+"+"+Eu,Nr+"+"+ku,G0,V0,Gm,U0].join("|"),"g");function K0(e){return e.match(H0)||[]}function J0(e,r,t){return e=xd(e),r=r,r===void 0?_0(e)?K0(e):S0(e):e.match(r)||[]}var Z0="['’]",X0=RegExp(Z0,"g");function Y0(e){return function(r){return d0(J0(w0(r).replace(X0,"")),e,"")}}var $t=Y0(function(e,r,t){return e+(t?" ":"")+l0(r)});function Q0(){let e,r=null;const t=new Set,n=o=>{r=o,t.forEach(i=>i())};return{subscribe:o=>(t.add(o),()=>{t.delete(o)}),getSnapshot:()=>r,select(o,i){e=o,n(i)},update(o,i){e===o&&n(i)},remove(o){e===o&&(e=void 0,n(null))}}}const Gr=_.createContext(null),ew=()=>_.useState(Q0)[0];function ao(e,r=!0){const t=_.useContext(Gr),n=_.useId();return _.useEffect(()=>{r?t==null||t.update(n,e):t==null||t.remove(n)}),_.useEffect(()=>()=>t==null?void 0:t.remove(n),[t,n]),()=>{r&&(t==null||t.select(n,e))}}function tw({divider:e,visibleActions:r=[]}){const t=_.useContext(Gr),n=_.useSyncExternalStore(t.subscribe,t.getSnapshot,()=>null),o=n&&r.includes(n.props["aria-label"]??"");return f.jsx(Gr.Provider,{value:null,children:f.jsxs("span",{"data-recent-toolbar-action":"",style:{display:n&&!o?"contents":"none"},children:[n&&!o&&e,!o&&n]})})}function Ue({label:e,children:r}){const t=_.cloneElement(r,{title:r.props.title??e});if(!V.Tooltip.Root){const n=V.Tooltip;return f.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:t})}return f.jsxs(V.Tooltip.Root,{positioning:{placement:"top"},children:[f.jsx(V.Tooltip.Trigger,{asChild:!0,children:t}),f.jsx(V.Portal,{children:f.jsx(V.Tooltip.Positioner,{children:f.jsx(V.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function bn(){const{border:e}=at(),{colorMode:r}=Ze();return f.jsx(V.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:r==="dark"?e:"gray.300"})}function Pt({children:e,value:r,onValueChange:t,disabled:n,style:o,title:i,icon:s,popupContent:a,footer:c,labelCase:l="title","aria-label":d,...u}){var M;const{colorMode:h}=Ze(),{background:p,border:m,colorText:y,colorInactive:g}=at(),v=h==="dark",b=_.useId(),x=_.useRef(null),w=_.useRef(null),[C,S]=_.useState(!1),j=ao(f.jsx(Pt,{value:r,onValueChange:t,disabled:n,style:o,title:i,icon:s,popupContent:a,footer:c,labelCase:l,"aria-label":d,children:e}),!!s);_.useEffect(()=>{const T=w.current;T.setAttribute("popover","auto");const N=$=>S($.newState==="open");return T.addEventListener("toggle",N),()=>T.removeEventListener("toggle",N)},[]);const P=_.Children.toArray(e).filter(_.isValidElement).map(T=>{const N=T.props;return{value:String(N.value),label:typeof N.children=="string"&&l==="title"?$t(N.children):N.children,disabled:N.disabled}}),E=()=>{var T;return(T=w.current)==null?void 0:T.hidePopover()},O=()=>{var ie,se,te,me,ve;const T=(ie=x.current)==null?void 0:ie.getBoundingClientRect(),N=w.current;if(!T||!N)return;if((se=x.current)!=null&&se.closest("[popover]")){const F=window.innerHeight-T.bottom-16,D=T.top-16;N.style.maxHeight=`${Math.max(60,F,D)}px`;const W=N.getBoundingClientRect();N.style.left=`${Math.max(12,Math.min(T.right-W.width,window.innerWidth-W.width-12))}px`,N.style.top=`${Math.max(12,W.height<=F?T.bottom+4:T.top-W.height-4)}px`;return}const $=(ve=(me=(te=x.current)==null?void 0:te.closest("[data-flow-toolbar-scroll]"))==null?void 0:me.parentElement)==null?void 0:ve.getBoundingClientRect(),I=$??T;N.style.maxHeight=`${Math.max(60,Math.max(I.top-40,window.innerHeight-I.bottom-40))}px`;const K=N.getBoundingClientRect();N.style.left=`${Math.max(12,Math.min(Math.max(($==null?void 0:$.left)??12,T.right-K.width),(($==null?void 0:$.right)??window.innerWidth-12)-K.width,window.innerWidth-K.width-12))}px`,N.style.top=`${Math.max(12,I.top>=K.height+36?I.top-K.height-24:Math.min(I.bottom+24,window.innerHeight-K.height-12))}px`},A=()=>{var $,I,K,ie,se,te;if(n)return;if(($=w.current)==null||$.showPopover(),O(),a){(K=(I=w.current)==null?void 0:I.querySelector("input"))==null||K.focus({preventScroll:!0});return}const T=(ie=w.current)==null?void 0:ie.querySelectorAll('[role="option"]:not(:disabled)');(te=((se=w.current)==null?void 0:se.querySelector('[aria-selected="true"]:not(:disabled)'))??(T==null?void 0:T[0]))==null||te.focus()};_.useEffect(()=>{if(C){if(n){E();return}return window.addEventListener("resize",O),window.addEventListener("scroll",O,!0),()=>{window.removeEventListener("resize",O),window.removeEventListener("scroll",O,!0)}}},[C,n]);const R=`var(--chakra-colors-${p.replace(".","-")})`;return f.jsxs(f.Fragment,{children:[f.jsx(Ue,{label:i??d,children:f.jsx(V.chakra.button,{...u,ref:x,type:"button",role:"combobox","data-flow-select-icon":s?"":void 0,"aria-label":d,title:i??d,"aria-haspopup":a?"dialog":"listbox","aria-expanded":C,"aria-controls":b,disabled:n,h:"30px",w:"160px",px:"6px",fontSize:"12px",border:"none",borderRadius:"4px",bg:"transparent",color:s?g:y,display:"flex",alignItems:"center",justifyContent:s?"center":"space-between",gap:2,style:o,onClick:()=>{j(),C?E():A()},onKeyDown:T=>{["ArrowDown","ArrowUp"].includes(T.key)&&(T.preventDefault(),A())},children:s??f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((M=P.find(T=>T.value===r))==null?void 0:M.label)??r}),f.jsx(Z.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),f.jsxs(V.chakra.div,{ref:w,id:b,role:a?"dialog":"listbox","aria-label":d,position:"fixed",m:0,p:2,minW:"180px",maxW:"calc(100vw - 24px)",overflowY:"auto",bg:p,color:y,borderRadius:"30px",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"},'& [role="option"]':eo,'& details [role="option"]:first-child':{borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},...fr(R,`var(--chakra-colors-${(v?m:"gray.300").replace(".","-")})`)},onKeyDown:T=>{var I,K,ie;if(a&&!["Escape","Tab"].includes(T.key))return;const N=[...T.currentTarget.querySelectorAll('[role="option"]:not(:disabled), [data-flow-menu-action]:not(:disabled)')],$=N.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(T.key)){T.preventDefault();const se=T.key==="Home"?0:T.key==="End"?N.length-1:($+(T.key==="ArrowDown"?1:-1)+N.length)%N.length;(I=N[se])==null||I.focus()}else T.key==="Escape"||T.key==="Tab"?(T.key==="Escape"&&(T.preventDefault(),T.stopPropagation()),E(),(K=x.current)==null||K.focus()):T.key.length===1&&T.key!==" "&&((ie=N.find((se,te)=>{var me;return te>$&&((me=se.textContent)==null?void 0:me.toLowerCase().startsWith(T.key.toLowerCase()))}))==null||ie.focus())},children:[a??P.map(T=>f.jsxs(V.chakra.button,{type:"button",role:"option","aria-selected":T.value===r,disabled:T.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:v?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:v?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var N;E(),(N=x.current)==null||N.focus(),t(T.value)},children:[f.jsx("span",{style:{flex:1},children:T.label}),f.jsx(Z.PiCheck,{size:16,color:`var(--chakra-colors-${y.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:T.value===r?"visible":"hidden"}})]},T.value)),c]})]})}const eo={borderRadius:"4px","&:first-child":{borderTopLeftRadius:"22px",borderTopRightRadius:"22px"},"&:last-child":{borderBottomLeftRadius:"22px",borderBottomRightRadius:"22px"}},Me=_.forwardRef(function({icon:r,rememberAction:t=!0,...n},o){const{colorMode:i}=Ze(),s=Object.fromEntries(Object.entries(n).filter(([c])=>c!=="id"&&c!=="aria-describedby"&&!c.startsWith("data-")&&!/^on(Pointer|Mouse|Focus|Blur)/.test(c))),a=ao(f.jsx(Ue,{label:n.title??n["aria-label"]??"Last used action",children:f.jsx(Me,{...s,icon:r})}),t&&!!n.onClick);return f.jsx(V.IconButton,{ref:o,_hover:{bg:i==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:n.title??n["aria-label"],...n,onClick:c=>{var l;a(),(l=n.onClick)==null||l.call(n,c)},children:r})}),Jr=_.forwardRef(function(r,t){const{themeColor:n}=Ze();return f.jsx(Ue,{label:"Close",children:f.jsx(Me,{ref:t,size:"sm",variant:"plain",bg:"transparent",_hover:{bg:"transparent",color:n},color:n,focusRingColor:n,...r,"aria-label":r["aria-label"]??"Close selection tools",icon:f.jsx(Z.PiXLight,{size:20,"aria-hidden":"true"})})})});function Lr({label:e,icon:r,checked:t,onChange:n,disabled:o,hideLabel:i=!1,helper:s=e}){const{themeColor:a,readOnly:c}=Ze(),{colorInactive:l}=at();return f.jsx(Ue,{label:s,children:f.jsx(Me,{"aria-label":e,"aria-pressed":t,icon:f.jsxs(f.Fragment,{children:[r,!i&&f.jsx(V.Text,{as:"span",fontSize:"16px",fontWeight:t?"bold":"normal",whiteSpace:"nowrap",children:e})]}),size:"sm",variant:"ghost",width:"auto",px:2,gap:2,color:t?a:l,disabled:o||c,onClick:()=>n(!t)})})}function Xm({label:e="Compact layout"}={}){const{compactPropertyLayout:r,setCompactPropertyLayout:t,callbacks:n}=Ze();return f.jsx(Lr,{hideLabel:!0,label:e,checked:r,icon:f.jsx(V.Icon,{as:Z.PiArrowsIn,boxSize:5}),onChange:o=>{var i;t(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const rw=io.default.input`
|
|
7
|
+
`;function km(e,r=!0,t="&:hover",n=!0){const o=`color-mix(in srgb, ${e} 60%, transparent)`,s=`0 0 0 ${r?8:0}px ${o}`,a=`0 0 0 8px ${o}`;return{boxShadow:s,css:{"--flow-rest-shadow":a,"--flow-hover-shadow":`0 0 0 18px ${o}`,"@media (hover: hover)":{[t]:{boxShadow:a,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${Sx} 1200ms steps(10, end) 600ms`:"none"}}}}}}function hr(e,r){const{boxShadow:t,css:n}=km(e,!1),o=n["@media (hover: hover)"]["&:hover"];return{borderWidth:"1px",borderStyle:"solid",borderColor:"transparent",boxShadow:t,...n,"--flow-start-shadow":t,"@media (hover: hover)":{"&:hover":{...o,borderColor:r,"@media (prefers-reduced-motion: no-preference)":{animation:`${jx} 600ms steps(5, end)`}}}}}const Rm=j.createContext(null),Am=j.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function mr(){return j.useContext(Am)}function Je(){const e=j.useContext(Rm);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function Pm({config:e,callbacks:r,nodes:t=[],edges:n=[],children:o}){var Le;const i=j.useMemo(()=>{var Ee,Qe,et;const G=new Map;for(const Ze of t)(Ee=Ze.data)!=null&&Ee.id&&G.set(Ze.data.id,Ze);const fe=new Map;for(const Ze of n)(Qe=Ze.data)!=null&&Qe.id&&fe.set(Ze.data.id,Ze);const Se=new Set;for(const Ze of t)(et=Ze.data)!=null&&et.parent&&Se.add(Ze.data.parent);return{nodeById:G,edgeById:fe,parentIds:Se}},[t,n]),s=j.useRef(null),[a,c]=j.useState([]),[l,d]=j.useState(null),[u,h]=j.useState(!0),[p,m]=j.useState(!1),[y,g]=j.useState(!0),[v,b]=j.useState(!1),[x,w]=j.useState(!1),[C,S]=j.useState(!0),[_,I]=j.useState(!1),[E,O]=j.useState(()=>{var G;return(G=e.nodeGrid)!=null&&G.enabled?{...e.nodeGrid.options,...e.nodeGrid.order?{order:e.nodeGrid.order}:{}}:null}),A=j.useRef(E),[R,P]=j.useState(E??((Le=e.nodeGrid)==null?void 0:Le.options)??{gaps:15,fill:!1,padding:0}),[T,N]=j.useState(()=>new Set),$=j.useCallback(G=>{var fe;!!(G!=null&&G.fill)!=!!((fe=A.current)!=null&&fe.fill)&&N(new Set),A.current=G,G&&P(G),O(G)},[]),[M,W]=j.useState("auto"),[ae,se]=j.useState(!1),re=e.compactPropertyLayout??ae,[ye,me]=j.useState({}),L=e.nodeViewModes??ye,[z,U]=j.useState(e.allNodesIconLabel);j.useEffect(()=>U(e.allNodesIconLabel),[e.allNodesIconLabel]);const[B,ce]=j.useState({}),X=j.useCallback((G,fe)=>{ce(Se=>{const Ee={...Se};for(const Qe of G)fe===void 0?delete Ee[Qe]:Ee[Qe]=fe;return Ee})},[]),le=[...i.nodeById.values()].filter(G=>{var fe;return i.parentIds.has(G.data.id)||((fe=G.data.config)==null?void 0:fe.parentContainer)||G.data.type==="objectView"||G.data.type==="arrayView"||G.data.type==="grid"}),ue=le.every(G=>{var fe,Se,Ee;return i.parentIds.has(G.data.id)||(fe=G.data.config)!=null&&fe.parentContainer?!!((Se=G.data.config)!=null&&Se.collapsed):L[G.data.id]==="icon-label"||G.data.type==="grid"&&L[G.data.id]===void 0||((Ee=G.data.config)==null?void 0:Ee.labelBelow)&&L[G.data.id]!=="properties"}),xe=z??e.allNodesIconLabel??ue,[Ce,ge]=j.useState("normal"),[he,Y]=j.useState(),H=e.edgeRadius??he,ve=H!==void 0&&Number.isFinite(H)?Math.min(500,Math.max(0,H)):void 0,[J,be]=j.useState(),Q=e.spacing??Ce,je=typeof Q=="number"?Number.isFinite(Q)?Math.min(2,Math.max(e.nodeGridSpacing==="layout"?0:.5,Q)):1:Q==="compact"?.5:Q==="spacious"?2:1,Pe=e.backgroundVariant??J??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[qe,Xe]=j.useState(),Be=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:qe,[ut,De]=j.useState("blue.500"),[rt,pt]=j.useState(!1),Ne=j.useRef(r);Ne.current=r;const Ge=j.useMemo(()=>{const G=fe=>(...Se)=>{var Ee,Qe;return(Qe=(Ee=Ne.current)==null?void 0:Ee[fe])==null?void 0:Qe.call(Ee,...Se)};return{onNodeSelect:G("onNodeSelect"),onNodesCopy:G("onNodesCopy"),onNodesDuplicate:G("onNodesDuplicate"),onBackgroundClick:G("onBackgroundClick"),onBottomBarCollapsedChange:G("onBottomBarCollapsedChange"),onNodeGridZoomOut:G("onNodeGridZoomOut"),onNodeGridFillRequest:G("onNodeGridFillRequest"),onNodeGridModeRequest:G("onNodeGridModeRequest"),onNodeGridDrop:G("onNodeGridDrop"),onNodeParentChange:G("onNodeParentChange"),onNodeDeselect:G("onNodeDeselect"),onNodeDoubleClick:G("onNodeDoubleClick"),onNodeViewToggle:G("onNodeViewToggle"),onNodeTypeViewChange:G("onNodeTypeViewChange"),onNodeCreate:G("onNodeCreate"),onNodeCreateRequest:G("onNodeCreateRequest"),onNodeDelete:G("onNodeDelete"),onNodeLabelChange:G("onNodeLabelChange"),onNodeSubtitleChange:G("onNodeSubtitleChange"),onNodeContentChange:G("onNodeContentChange"),onNodeCollapse:G("onNodeCollapse"),onNodeColorChange:G("onNodeColorChange"),onNodeBorderColorChange:G("onNodeBorderColorChange"),onNodeBorderStyleChange:G("onNodeBorderStyleChange"),onNodeBorderWidthChange:G("onNodeBorderWidthChange"),onNodeBorderRadiusChange:(fe,Se)=>{var Ee,Qe,et;(Ee=A.current)!=null&&Ee.fill&&N(Ze=>new Set([...Ze,fe])),(et=(Qe=Ne.current).onNodeBorderRadiusChange)==null||et.call(Qe,fe,Se)},onNodeIconChange:G("onNodeIconChange"),onNodeOutlineChange:G("onNodeOutlineChange"),onNodeAnimationChange:G("onNodeAnimationChange"),onNodeAnimationVariantChange:G("onNodeAnimationVariantChange"),onEdgeAnimationVariantChange:G("onEdgeAnimationVariantChange"),onNodeHoverAction:G("onNodeHoverAction"),onEdgeCreate:G("onEdgeCreate"),onEdgeSelect:G("onEdgeSelect"),onEdgeDeselect:G("onEdgeDeselect"),onEdgeRemove:G("onEdgeRemove"),onEdgeDelete:G("onEdgeDelete"),onEdgeColorChange:G("onEdgeColorChange"),onEdgeTypeChange:G("onEdgeTypeChange"),onEdgeIconChange:G("onEdgeIconChange"),onEdgeLabelChange:G("onEdgeLabelChange"),onEdgeStyleChange:G("onEdgeStyleChange"),onViewportChange:G("onViewportChange"),onDirectionChange:G("onDirectionChange"),onThemeColorChange:G("onThemeColorChange"),onSpacingChange:G("onSpacingChange"),onEdgeRadiusChange:G("onEdgeRadiusChange"),onBackgroundVariantChange:G("onBackgroundVariantChange"),onEdgeModeChange:G("onEdgeModeChange"),onCompactPropertyLayoutChange:G("onCompactPropertyLayoutChange"),onWorkflowContractChange:G("onWorkflowContractChange"),onWorkflowConfigurationOpen:r.onWorkflowConfigurationOpen?G("onWorkflowConfigurationOpen"):void 0,onArrayModeChange:G("onArrayModeChange"),onInit:G("onInit"),onLayoutComplete:G("onLayoutComplete"),onJsonChange:G("onJsonChange")}},[]),st=e.themeColor||ut,[ct,Bt]=j.useState(""),Ue=e.edgeColor??ct,We=e.colorMode||"light",Ut=e.direction||"LR",lt=e.nodeAlignment??"center",or=e.edgeMode==="workflow"?"nodes":e.edgeMode??M,Ht=e.readOnly??!1,Or=JSON.stringify(e.parentNodeStyle??null),_t=j.useMemo(()=>e.parentNodeStyle,[Or]),Kt=e.isZoomMode!==void 0?e.isZoomMode:u,Qt=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,Nr=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:v,vr=e.isDragMode!==void 0?e.isDragMode:y,ze=j.useRef(e);ze.current=e;const ne=j.useMemo(()=>({get direction(){return ze.current.direction},get nodeAlignment(){return ze.current.nodeAlignment},get edgeMode(){return ze.current.edgeMode},get compactPropertyLayout(){return ze.current.compactPropertyLayout},get bottomBarCollapsed(){return ze.current.bottomBarCollapsed},get bottomBarNavigation(){return ze.current.bottomBarNavigation},get bottomBarFill(){return ze.current.bottomBarFill},get bottomBarCollision(){return ze.current.bottomBarCollision},get nodeGridConnections(){return ze.current.nodeGridConnections},get nodeGrid(){return ze.current.nodeGrid},get edgeType(){return ze.current.edgeType},get edgeReveal(){return ze.current.edgeReveal},get customEdgeTypes(){return ze.current.customEdgeTypes},get themeColor(){return ze.current.themeColor},get colorMode(){return ze.current.colorMode},get readOnly(){return ze.current.readOnly},get editable(){return ze.current.editable},get minZoom(){return ze.current.minZoom},get nodeGridSpacing(){return ze.current.nodeGridSpacing},get maxZoom(){return ze.current.maxZoom},get backgroundPattern(){return ze.current.backgroundPattern},get edgeColor(){return ze.current.edgeColor},get parentNodeStyle(){return ze.current.parentNodeStyle},get backgroundColor(){return ze.current.backgroundColor},get edgeHandles(){return ze.current.edgeHandles},get initialViewport(){return ze.current.initialViewport},get animateViewport(){return ze.current.animateViewport},get disableAnimations(){return ze.current.disableAnimations},get nodeOverlayActions(){return ze.current.nodeOverlayActions},get renderNodeOverlay(){return ze.current.renderNodeOverlay},get renderSelectedNodeToolbar(){return ze.current.renderSelectedNodeToolbar},get renderSelectedEdgeToolbar(){return ze.current.renderSelectedEdgeToolbar},get renderBottomBar(){return ze.current.renderBottomBar},get bottomBarExtra(){return ze.current.bottomBarExtra},get selectionToolbar(){return ze.current.selectionToolbar},get customViews(){return ze.current.customViews},get disableKeyboardShortcuts(){return ze.current.disableKeyboardShortcuts},get isZoomMode(){return ze.current.isZoomMode},get isMultiSelectMode(){return ze.current.isMultiSelectMode},get isEdgeHandlesEnabled(){return ze.current.isEdgeHandlesEnabled},get isDragMode(){return ze.current.isDragMode}}),[]),D=j.useCallback((G,fe)=>{var Se;if(fe!=="default"&&fe!=="properties"&&fe!=="icon-label")throw new Error("Unknown node view mode.");U(Ee=>Ee??xe),me(Ee=>Ee[G]===fe?Ee:{...Ee,[G]:fe}),(Se=r.onNodeViewModeChange)==null||Se.call(r,G,fe)},[r.onNodeViewModeChange,xe]),oe=j.useMemo(()=>({allNodesIconLabel:xe,setAllNodesIconLabel:G=>{var fe,Se,Ee,Qe,et;if(U(G),!G)for(const[Ze,Et]of Object.entries(L))Et==="icon-label"&&!i.nodeById.has(Ze)&&D(Ze,"default");for(const Ze of le)i.parentIds.has(Ze.data.id)||(fe=Ze.data.config)!=null&&fe.parentContainer?!Ht&&!!((Se=Ze.data.config)!=null&&Se.collapsed)!==G&&((Ee=r.onNodeCollapse)==null||Ee.call(r,Ze.data.id,G)):D(Ze.data.id,G?"icon-label":(Qe=Ze.data.config)!=null&&Qe.labelBelow?"properties":"default");(et=r.onAllNodesIconLabelChange)==null||et.call(r,G)},nodeViewModes:L,setNodeViewMode:D,nodeRadiusPreviews:B,setNodeRadiusPreview:X,spacing:je,setSpacing:ge,edgeRadius:ve,setEdgeRadius:Y,backgroundVariant:Pe,setBackgroundVariant:be,themeColor:st,setThemeColor:De,backgroundSelected:rt,setBackgroundSelected:pt,edgeColor:Ue,setEdgeColor:G=>{var fe;Bt(G),(fe=r.onGraphEdgeColorChange)==null||fe.call(r,G)},colorMode:We,direction:Ut,nodeAlignment:lt,edgeMode:or,setEdgeMode:W,compactPropertyLayout:re,setCompactPropertyLayout:se,workflowContract:Be,setWorkflowContract:Xe,parentNodeStyle:_t,selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isZoomMode:Kt,setIsZoomMode:h,isMultiSelectMode:Qt,setIsMultiSelectMode:m,isDragMode:vr,setIsDragMode:g,isEdgeHandlesEnabled:Nr,setIsEdgeHandlesEnabled:b,isArrayNodeMode:x,setIsArrayNodeMode:w,isPinned:C,setIsPinned:S,isPerformanceMode:_,setIsPerformanceMode:I,nodeGridOptions:E,setNodeGridOptions:$,lastNodeGridOptions:R,fillRadiusEditedIds:T,setFillRadiusEditedIds:N,engineRef:s,callbacks:Ge,config:ne,readOnly:Ht}),[xe,i,D,r.onNodeCollapse,r.onAllNodesIconLabelChange,r.onGraphEdgeColorChange,L,r.onNodeViewModeChange,B,X,st,je,Pe,ve,e.backgroundColor,rt,Ue,We,Ut,lt,or,Be,_t,a,l,Kt,Qt,vr,Nr,x,C,_,E,R,T,Ht,e.edgeHandles,e.edgeType,e.edgeReveal,e.animateViewport,e.disableAnimations,e.customEdgeTypes,e.selectionToolbar,e.bottomBarExtra,e.bottomBarCollapsed,e.bottomBarNavigation,e.bottomBarFill,e.bottomBarCollision,e.nodeGridSpacing,e.nodeGridConnections,e.compactPropertyLayout,re,Ge,ne]);return f.jsx(Rm.Provider,{value:oe,children:f.jsx(Am.Provider,{value:i,children:o})})}function vt(e,r,t){return e?t:r}function On(e){const[r]=(e==null?void 0:e.split("."))||[],{secondary:t}=Em(e),n=Zt(r).background,o=Zt(r).highlight,i=Zt(r).border,s=Zt(r).property,a=Zt(r).property;let c=Zt(r).background,l=Zt(r).highlight;return c=e==="transparent"?e:Me(c)+50,l=e==="transparent"?e:Me(l)+20,{bgColor:n,highlightColor:o,borderColor:i,textColor:s,propertyColor:a,secondary:t,bgColorFaint:c,highlightColorFaint:l}}function at(e=null){const{colorMode:r}=Je(),t=e==null?void 0:e.includes("gray"),n=r==="dark",o=vt(n,"white","gray.900"),i=vt(n,"gray.100","gray.800"),s=vt(n,"gray.200","blackAlpha.400"),a=vt(n,"gray.200","blackAlpha.600"),c=vt(n,"gray.500","gray.700"),l=vt(n,"gray.700","gray.700"),d=vt(n,"gray.900","gray.900"),u=vt(n,"gray.400","gray.500"),h=vt(n,"gray.400","gray.500"),p=vt(n,"gray.900","gray.200"),m=vt(n,t?"gray.900":"gray.200",t?"gray.200":"gray.900"),y=vt(n,"gray.900","gray.200"),g=vt(n,e&&"#000000",e||"#ffffff"),v=vt(n,e||"#ffffff",e?"#000000":"#ffffff"),b=l,x=vt(n,"gray.300","gray.800"),w=vt(n,"white","blackAlpha.400"),C=vt(n,"green.100","green.700");return{canvas:o,background:i,backgroundSecondary:s,darkBackgroundSecondary:a,border:c,darkColor:d,backgroundWhiteColor:w,borderSecondary:l,colorActive:u,colorInactive:h,iconColor:y,moreIconColor:b,colorText:p,themedColorText:m,logoColor:g,logoColorSecondary:v,darkColorActive:x,greenColor:C}}var fn=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(fn||{});const xd=["","icon-label","object","text","grid","parent"];var _x=typeof global=="object"&&global&&global.Object===Object&&global,Ex=typeof self=="object"&&self&&self.Object===Object&&self,kx=_x||Ex||Function("return this")(),Vr=kx.Symbol,Mm=Object.prototype,Rx=Mm.hasOwnProperty,Ax=Mm.toString,dn=Vr?Vr.toStringTag:void 0;function Px(e){var r=Rx.call(e,dn),t=e[dn];try{e[dn]=void 0;var n=!0}catch{}var o=Ax.call(e);return n&&(r?e[dn]=t:delete e[dn]),o}var Mx=Object.prototype,Ix=Mx.toString;function Tx(e){return Ix.call(e)}var Ox="[object Null]",Nx="[object Undefined]",Cu=Vr?Vr.toStringTag:void 0;function $x(e){return e==null?e===void 0?Nx:Ox:Cu&&Cu in Object(e)?Px(e):Tx(e)}function qx(e){return e!=null&&typeof e=="object"}var Lx="[object Symbol]";function Fx(e){return typeof e=="symbol"||qx(e)&&$x(e)==Lx}function zx(e,r){for(var t=-1,n=e==null?0:e.length,o=Array(n);++t<n;)o[t]=r(e[t],t,e);return o}var tt=Array.isArray,Su=Vr?Vr.prototype:void 0,ju=Su?Su.toString:void 0;function Im(e){if(typeof e=="string")return e;if(tt(e))return zx(e,Im)+"";if(Fx(e))return ju?ju.call(e):"";var r=e+"";return r=="0"&&1/e==-1/0?"-0":r}function wd(e){return e==null?"":Im(e)}function Bx(e,r,t){var n=-1,o=e.length;r<0&&(r=-r>o?0:o+r),t=t>o?o:t,t<0&&(t+=o),o=r>t?0:t-r>>>0,r>>>=0;for(var i=Array(o);++n<o;)i[n]=e[n+r];return i}function Dx(e,r,t){var n=e.length;return t=t===void 0?n:t,!r&&t>=n?e:Bx(e,r,t)}var Vx="\\ud800-\\udfff",Wx="\\u0300-\\u036f",Gx="\\ufe20-\\ufe2f",Ux="\\u20d0-\\u20ff",Hx=Wx+Gx+Ux,Kx="\\ufe0e\\ufe0f",Jx="\\u200d",Zx=RegExp("["+Jx+Vx+Hx+Kx+"]");function Tm(e){return Zx.test(e)}function Yx(e){return e.split("")}var Om="\\ud800-\\udfff",Xx="\\u0300-\\u036f",Qx="\\ufe20-\\ufe2f",e0="\\u20d0-\\u20ff",t0=Xx+Qx+e0,r0="\\ufe0e\\ufe0f",n0="["+Om+"]",ld="["+t0+"]",dd="\\ud83c[\\udffb-\\udfff]",o0="(?:"+ld+"|"+dd+")",Nm="[^"+Om+"]",$m="(?:\\ud83c[\\udde6-\\uddff]){2}",qm="[\\ud800-\\udbff][\\udc00-\\udfff]",i0="\\u200d",Lm=o0+"?",Fm="["+r0+"]?",a0="(?:"+i0+"(?:"+[Nm,$m,qm].join("|")+")"+Fm+Lm+")*",s0=Fm+Lm+a0,c0="(?:"+[Nm+ld+"?",ld,$m,qm,n0].join("|")+")",l0=RegExp(dd+"(?="+dd+")|"+c0+s0,"g");function d0(e){return e.match(l0)||[]}function u0(e){return Tm(e)?d0(e):Yx(e)}function f0(e){return function(r){r=wd(r);var t=Tm(r)?u0(r):void 0,n=t?t[0]:r.charAt(0),o=t?Dx(t,1).join(""):r.slice(1);return n[e]()+o}}var h0=f0("toUpperCase");function p0(e,r,t,n){for(var o=-1,i=e==null?0:e.length;++o<i;)t=r(t,e[o],o,e);return t}function g0(e){return function(r){return e==null?void 0:e[r]}}var y0={À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"},m0=g0(y0),b0=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,v0="\\u0300-\\u036f",x0="\\ufe20-\\ufe2f",w0="\\u20d0-\\u20ff",C0=v0+x0+w0,S0="["+C0+"]",j0=RegExp(S0,"g");function _0(e){return e=wd(e),e&&e.replace(b0,m0).replace(j0,"")}var E0=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function k0(e){return e.match(E0)||[]}var R0=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function A0(e){return R0.test(e)}var zm="\\ud800-\\udfff",P0="\\u0300-\\u036f",M0="\\ufe20-\\ufe2f",I0="\\u20d0-\\u20ff",T0=P0+M0+I0,Bm="\\u2700-\\u27bf",Dm="a-z\\xdf-\\xf6\\xf8-\\xff",O0="\\xac\\xb1\\xd7\\xf7",N0="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",$0="\\u2000-\\u206f",q0=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Vm="A-Z\\xc0-\\xd6\\xd8-\\xde",L0="\\ufe0e\\ufe0f",Wm=O0+N0+$0+q0,Gm="['’]",_u="["+Wm+"]",F0="["+T0+"]",Um="\\d+",z0="["+Bm+"]",Hm="["+Dm+"]",Km="[^"+zm+Wm+Um+Bm+Dm+Vm+"]",B0="\\ud83c[\\udffb-\\udfff]",D0="(?:"+F0+"|"+B0+")",V0="[^"+zm+"]",Jm="(?:\\ud83c[\\udde6-\\uddff]){2}",Zm="[\\ud800-\\udbff][\\udc00-\\udfff]",$r="["+Vm+"]",W0="\\u200d",Eu="(?:"+Hm+"|"+Km+")",G0="(?:"+$r+"|"+Km+")",ku="(?:"+Gm+"(?:d|ll|m|re|s|t|ve))?",Ru="(?:"+Gm+"(?:D|LL|M|RE|S|T|VE))?",Ym=D0+"?",Xm="["+L0+"]?",U0="(?:"+W0+"(?:"+[V0,Jm,Zm].join("|")+")"+Xm+Ym+")*",H0="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",K0="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",J0=Xm+Ym+U0,Z0="(?:"+[z0,Jm,Zm].join("|")+")"+J0,Y0=RegExp([$r+"?"+Hm+"+"+ku+"(?="+[_u,$r,"$"].join("|")+")",G0+"+"+Ru+"(?="+[_u,$r+Eu,"$"].join("|")+")",$r+"?"+Eu+"+"+ku,$r+"+"+Ru,K0,H0,Um,Z0].join("|"),"g");function X0(e){return e.match(Y0)||[]}function Q0(e,r,t){return e=wd(e),r=r,r===void 0?A0(e)?X0(e):k0(e):e.match(r)||[]}var ew="['’]",tw=RegExp(ew,"g");function rw(e){return function(r){return p0(Q0(_0(r).replace(tw,"")),e,"")}}var qt=rw(function(e,r,t){return e+(t?" ":"")+h0(r)});function nw(){let e,r=null;const t=new Set,n=o=>{r=o,t.forEach(i=>i())};return{subscribe:o=>(t.add(o),()=>{t.delete(o)}),getSnapshot:()=>r,select(o,i){e=o,n(i)},update(o,i){e===o&&n(i)},remove(o){e===o&&(e=void 0,n(null))}}}const Wr=j.createContext(null),ow=()=>j.useState(nw)[0];function so(e,r=!0){const t=j.useContext(Wr),n=j.useId();return j.useEffect(()=>{r?t==null||t.update(n,e):t==null||t.remove(n)}),j.useEffect(()=>()=>t==null?void 0:t.remove(n),[t,n]),()=>{r&&(t==null||t.select(n,e))}}function iw({divider:e,visibleActions:r=[]}){const t=j.useContext(Wr),n=j.useSyncExternalStore(t.subscribe,t.getSnapshot,()=>null),o=n&&r.includes(n.props["aria-label"]??"");return f.jsx(Wr.Provider,{value:null,children:f.jsxs("span",{"data-recent-toolbar-action":"",style:{display:n&&!o?"contents":"none"},children:[n&&!o&&e,!o&&n]})})}function Ke({label:e,children:r}){const t=j.cloneElement(r,{title:r.props.title??e});if(!V.Tooltip.Root){const n=V.Tooltip;return f.jsx(n,{label:e,placement:"top",fontSize:"xs",borderRadius:"15px",children:t})}return f.jsxs(V.Tooltip.Root,{positioning:{placement:"top"},children:[f.jsx(V.Tooltip.Trigger,{asChild:!0,children:t}),f.jsx(V.Portal,{children:f.jsx(V.Tooltip.Positioner,{children:f.jsx(V.Tooltip.Content,{fontSize:"xs",borderRadius:"15px",children:e})})})]})}function vn(){const{border:e}=at(),{colorMode:r}=Je();return f.jsx(V.chakra.span,{role:"separator","aria-orientation":"vertical",display:"block",flexShrink:0,w:"1px",h:"20px",mx:"4px",bg:r==="dark"?e:"gray.300"})}function Mt({children:e,value:r,onValueChange:t,disabled:n,style:o,title:i,icon:s,popupContent:a,footer:c,labelCase:l="title","aria-label":d,...u}){var P;const{colorMode:h}=Je(),{background:p,border:m,colorText:y,colorInactive:g}=at(),v=h==="dark",b=j.useId(),x=j.useRef(null),w=j.useRef(null),[C,S]=j.useState(!1),_=so(f.jsx(Mt,{value:r,onValueChange:t,disabled:n,style:o,title:i,icon:s,popupContent:a,footer:c,labelCase:l,"aria-label":d,children:e}),!!s);j.useEffect(()=>{const T=w.current;T.setAttribute("popover","auto");const N=$=>S($.newState==="open");return T.addEventListener("toggle",N),()=>T.removeEventListener("toggle",N)},[]);const I=j.Children.toArray(e).filter(j.isValidElement).map(T=>{const N=T.props;return{value:String(N.value),label:typeof N.children=="string"&&l==="title"?qt(N.children):N.children,disabled:N.disabled}}),E=()=>{var T;return(T=w.current)==null?void 0:T.hidePopover()},O=()=>{var ae,se,re,ye,me;const T=(ae=x.current)==null?void 0:ae.getBoundingClientRect(),N=w.current;if(!T||!N)return;if((se=x.current)!=null&&se.closest("[popover]")){const L=window.innerHeight-T.bottom-16,z=T.top-16;N.style.maxHeight=`${Math.max(60,L,z)}px`;const U=N.getBoundingClientRect();N.style.left=`${Math.max(12,Math.min(T.right-U.width,window.innerWidth-U.width-12))}px`,N.style.top=`${Math.max(12,U.height<=L?T.bottom+4:T.top-U.height-4)}px`;return}const $=(me=(ye=(re=x.current)==null?void 0:re.closest("[data-flow-toolbar-scroll]"))==null?void 0:ye.parentElement)==null?void 0:me.getBoundingClientRect(),M=$??T;N.style.maxHeight=`${Math.max(60,Math.max(M.top-40,window.innerHeight-M.bottom-40))}px`;const W=N.getBoundingClientRect();N.style.left=`${Math.max(12,Math.min(Math.max(($==null?void 0:$.left)??12,T.right-W.width),(($==null?void 0:$.right)??window.innerWidth-12)-W.width,window.innerWidth-W.width-12))}px`,N.style.top=`${Math.max(12,M.top>=W.height+36?M.top-W.height-24:Math.min(M.bottom+24,window.innerHeight-W.height-12))}px`},A=()=>{var $,M,W,ae,se,re;if(n)return;if(($=w.current)==null||$.showPopover(),O(),a){(W=(M=w.current)==null?void 0:M.querySelector("input"))==null||W.focus({preventScroll:!0});return}const T=(ae=w.current)==null?void 0:ae.querySelectorAll('[role="option"]:not(:disabled)');(re=((se=w.current)==null?void 0:se.querySelector('[aria-selected="true"]:not(:disabled)'))??(T==null?void 0:T[0]))==null||re.focus()};j.useEffect(()=>{if(C){if(n){E();return}return window.addEventListener("resize",O),window.addEventListener("scroll",O,!0),()=>{window.removeEventListener("resize",O),window.removeEventListener("scroll",O,!0)}}},[C,n]);const R=`var(--chakra-colors-${p.replace(".","-")})`;return f.jsxs(f.Fragment,{children:[f.jsx(Ke,{label:i??d,children:f.jsx(V.chakra.button,{...u,ref:x,type:"button",role:"combobox","data-flow-select-icon":s?"":void 0,"aria-label":d,title:i??d,"aria-haspopup":a?"dialog":"listbox","aria-expanded":C,"aria-controls":b,disabled:n,h:"30px",w:"160px",px:"6px",fontSize:"12px",border:"none",borderRadius:"4px",bg:"transparent",color:s?g:y,display:"flex",alignItems:"center",justifyContent:s?"center":"space-between",gap:2,style:o,onClick:()=>{_(),C?E():A()},onKeyDown:T=>{["ArrowDown","ArrowUp"].includes(T.key)&&(T.preventDefault(),A())},children:s??f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((P=I.find(T=>T.value===r))==null?void 0:P.label)??r}),f.jsx(Z.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),f.jsxs(V.chakra.div,{ref:w,id:b,role:a?"dialog":"listbox","aria-label":d,position:"fixed",m:0,p:2,minW:"180px",maxW:"calc(100vw - 24px)",overflowY:"auto",bg:p,color:y,borderRadius:"30px",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"},'& [role="option"]':to,'& details [role="option"]:first-child':{borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},...hr(R,`var(--chakra-colors-${(v?m:"gray.300").replace(".","-")})`)},onKeyDown:T=>{var M,W,ae;if(a&&!["Escape","Tab"].includes(T.key))return;const N=[...T.currentTarget.querySelectorAll('[role="option"]:not(:disabled), [data-flow-menu-action]:not(:disabled)')],$=N.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(T.key)){T.preventDefault();const se=T.key==="Home"?0:T.key==="End"?N.length-1:($+(T.key==="ArrowDown"?1:-1)+N.length)%N.length;(M=N[se])==null||M.focus()}else T.key==="Escape"||T.key==="Tab"?(T.key==="Escape"&&(T.preventDefault(),T.stopPropagation()),E(),(W=x.current)==null||W.focus()):T.key.length===1&&T.key!==" "&&((ae=N.find((se,re)=>{var ye;return re>$&&((ye=se.textContent)==null?void 0:ye.toLowerCase().startsWith(T.key.toLowerCase()))}))==null||ae.focus())},children:[a??I.map(T=>f.jsxs(V.chakra.button,{type:"button",role:"option","aria-selected":T.value===r,disabled:T.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:v?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:v?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var N;E(),(N=x.current)==null||N.focus(),t(T.value)},children:[f.jsx("span",{style:{flex:1},children:T.label}),f.jsx(Z.PiCheck,{size:16,color:`var(--chakra-colors-${y.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:T.value===r?"visible":"hidden"}})]},T.value)),c]})]})}const to={borderRadius:"4px","&:first-child":{borderTopLeftRadius:"22px",borderTopRightRadius:"22px"},"&:last-child":{borderBottomLeftRadius:"22px",borderBottomRightRadius:"22px"}},Oe=j.forwardRef(function({icon:r,rememberAction:t=!0,...n},o){const{colorMode:i}=Je(),s=Object.fromEntries(Object.entries(n).filter(([c])=>c!=="id"&&c!=="aria-describedby"&&!c.startsWith("data-")&&!/^on(Pointer|Mouse|Focus|Blur)/.test(c))),a=so(f.jsx(Ke,{label:n.title??n["aria-label"]??"Last used action",children:f.jsx(Oe,{...s,icon:r})}),t&&!!n.onClick);return f.jsx(V.IconButton,{ref:o,_hover:{bg:i==="dark"?"whiteAlpha.100":"blackAlpha.50"},title:n.title??n["aria-label"],...n,onClick:c=>{var l;a(),(l=n.onClick)==null||l.call(n,c)},children:r})}),Zr=j.forwardRef(function(r,t){const{themeColor:n}=Je();return f.jsx(Ke,{label:"Close",children:f.jsx(Oe,{ref:t,size:"sm",variant:"plain",bg:"transparent",_hover:{bg:"transparent",color:n},color:n,focusRingColor:n,...r,"aria-label":r["aria-label"]??"Close selection tools",icon:f.jsx(Z.PiXLight,{size:20,"aria-hidden":"true"})})})});function Qm({onBeforeExpand:e}={}){const{allNodesIconLabel:r,setAllNodesIconLabel:t}=Je();return f.jsx(Gr,{label:"Collapse all",hideLabel:!0,checked:r,icon:f.jsx(Z.PiArrowsInLineVertical,{size:20}),onChange:n=>{n||e==null||e(),t(n)}})}function Gr({label:e,icon:r,checked:t,onChange:n,disabled:o,hideLabel:i=!1,helper:s=e}){const{themeColor:a,readOnly:c}=Je(),{colorInactive:l}=at();return f.jsx(Ke,{label:s,children:f.jsx(Oe,{"aria-label":e,"aria-pressed":t,icon:f.jsxs(f.Fragment,{children:[r,!i&&f.jsx(V.Text,{as:"span",fontSize:"16px",fontWeight:t?"bold":"normal",whiteSpace:"nowrap",children:e})]}),size:"sm",variant:"ghost",width:"auto",px:2,gap:2,color:t?a:l,disabled:o||c,onClick:()=>n(!t)})})}function eb({label:e="Compact layout"}={}){const{compactPropertyLayout:r,setCompactPropertyLayout:t,callbacks:n}=Je();return f.jsx(Gr,{hideLabel:!0,label:e,checked:r,icon:f.jsx(V.Icon,{as:Z.PiArrowsIn,boxSize:5}),onChange:o=>{var i;t(o),(i=n.onCompactPropertyLayoutChange)==null||i.call(n,o)}})}const aw=ao.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
|
-
`,wd=_.forwardRef(function({style:r,...t},n){return f.jsx(rw,{...t,ref:n,style:{...r,backgroundImage:"none","--flow-range-track":(r==null?void 0:r.backgroundImage)??"none"}})});function dd({label:e,inputLabel:r,value:t,displayValue:n,min:o,max:i,step:s=5,onChange:a,onChangeEnd:c}){const l=_.useId(),{readOnly:d,themeColor:u}=Ze(),{colorInactive:h}=at(),p=(t-o)/(i-o)*100,m=u.includes(".")?`var(--chakra-colors-${u.replace(".","-")})`:u;return f.jsxs("div",{style:{width:224,maxWidth:"calc(100vw - 64px)",padding:12},children:[f.jsxs("label",{htmlFor:l,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",f.jsx("span",{children:n})]}),f.jsx(wd,{id:l,"aria-label":r,type:"range",min:o,max:i,step:s,value:t,disabled:d,style:{color:m,accentColor:m,backgroundImage:`linear-gradient(to right, currentColor ${p}%, var(--chakra-colors-${h.replace(".","-")}) ${p}%)`},onChange:y=>a(Number(y.target.value)),onPointerUp:c,onKeyUp:c,onBlur:c})]})}const Ru={dot:{label:"Dots",icon:Z.PiDotsNine},grid:{label:"Grid",icon:Z.PiGridFour},steel:{label:"Steel",icon:Z.PiLineSegments},none:{label:"Solid",icon:Z.PiSquareFill},transparent:{label:"Transparent",icon:Z.PiSelection}};function Ym(){const{spacing:e,setSpacing:r,edgeRadius:t,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:s,readOnly:a,config:c}=Ze(),l=Ru[o].icon;return f.jsxs(f.Fragment,{children:[f.jsx(bn,{}),f.jsx(Pt,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:f.jsx(Z.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:a,onValueChange:()=>{},popupContent:f.jsx(dd,{label:"Spacing",inputLabel:"Node spacing percentage",min:c.nodeGridSpacing==="layout"?0:50,max:200,value:Math.round(e*100),displayValue:`${Math.round(e*100)}%`,onChange:d=>{var u;r(d/100),(u=s.onSpacingChange)==null||u.call(s,d/100)}}),children:f.jsx("option",{value:"spacing",children:"Spacing"})}),f.jsx(bn,{}),f.jsx(Pt,{"aria-label":"Edge radius",title:`Edge radius: ${t??"Default"}`,icon:f.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:a,onValueChange:()=>{},popupContent:f.jsx(dd,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:t??500,displayValue:t??"Default",onChange:d=>{var u;n(d),(u=s.onEdgeRadiusChange)==null||u.call(s,d)}}),children:f.jsx("option",{value:"radius",children:"Edge radius"})}),f.jsx(bn,{}),f.jsxs(Pt,{"aria-label":"Background variant",title:`Background: ${Ru[o].label}`,icon:f.jsx(l,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:a,onValueChange:d=>{var u;i(d),(u=s.onBackgroundVariantChange)==null||u.call(s,d)},children:[f.jsx("option",{value:"dot",children:"Dots"}),f.jsx("option",{value:"grid",children:"Grid"}),f.jsx("option",{value:"steel",children:"Steel"}),f.jsx("option",{value:"none",children:"Solid"}),f.jsx("option",{value:"transparent",children:"Transparent"})]})]})}function Fo(){var p;const{engineRef:e,nodeGridOptions:r,lastNodeGridOptions:t,readOnly:n,themeColor:o,callbacks:i,config:s}=Ze(),{colorText:a,colorInactive:c}=at(),l=r??t,d=typeof l.gaps=="object"?l.gaps.x:l.gaps??l.margin??15,u=Math.max(200,d),h=m=>{var y;return(y=e.current)==null?void 0:y.setNodeGridMode(!0,{...l,...m})};return f.jsxs(f.Fragment,{children:[s.bottomBarCollision!==!1&&f.jsx(Lr,{label:"Collision mode",hideLabel:!0,icon:f.jsx(Z.PiGridFour,{size:20}),checked:r!==null,onChange:m=>{var y,g;((y=i.onNodeGridModeRequest)==null?void 0:y.call(i,m,l))!==!0&&((g=e.current)==null||g.setNodeGridMode(m,l))}}),r&&f.jsxs(V.HStack,{role:"group","aria-label":"Collision settings",gap:2,flexShrink:0,children:[r&&s.nodeGridSpacing!=="layout"&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{width:"96px",flexShrink:0,display:"flex",alignItems:"center",children:f.jsx(wd,{type:"range","aria-label":"Collision gap",title:`Gap: ${d}`,min:0,max:u,step:5,value:d,disabled:n,style:{color:Ae(o),backgroundImage:`linear-gradient(to right, currentColor ${d/u*100}%, ${Ae(c)} ${d/u*100}%)`},onChange:m=>h({gaps:Number(m.target.value)})})}),f.jsx(V.Text,{fontSize:"xs",color:a,width:"28px",textAlign:"right",fontVariantNumeric:"tabular-nums",children:d})]}),s.bottomBarFill!==!1&&f.jsx(Lr,{label:"Fill",hideLabel:!0,helper:"Fill available canvas space",icon:f.jsx(Z.PiArrowsOut,{size:18}),checked:!!r&&!!l.fill,onChange:m=>{var y,g;!r&&((y=i.onNodeGridModeRequest)==null?void 0:y.call(i,!0,{...l,fill:m}))===!0||m&&((g=i.onNodeGridFillRequest)==null?void 0:g.call(i,{...l,fill:m}))===!0||h({fill:m})}}),r&&l.fill&&f.jsx(Lr,{label:"Grid adjustment",hideLabel:!0,icon:f.jsx(Z.PiArrowsHorizontal,{size:20}),checked:!!((p=l.adjustment)!=null&&p.enabled),onChange:m=>{n||h({adjustment:{...l.adjustment,enabled:m}})}})]})]})}const wt=[];for(let e=0;e<256;++e)wt.push((e+256).toString(16).slice(1));function nw(e,r=0){return(wt[e[r+0]]+wt[e[r+1]]+wt[e[r+2]]+wt[e[r+3]]+"-"+wt[e[r+4]]+wt[e[r+5]]+"-"+wt[e[r+6]]+wt[e[r+7]]+"-"+wt[e[r+8]]+wt[e[r+9]]+"-"+wt[e[r+10]]+wt[e[r+11]]+wt[e[r+12]]+wt[e[r+13]]+wt[e[r+14]]+wt[e[r+15]]).toLowerCase()}let zo;const ow=new Uint8Array(16);function iw(){if(!zo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");zo=crypto.getRandomValues.bind(crypto)}return zo(ow)}const aw=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Au={randomUUID:aw};function Cd(e,r,t){var o;if(Au.randomUUID&&!e)return Au.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??iw();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,nw(n)}const so={label:"Untitled",description:"",isTask:!1,isLocked:!1},Sd={id:null,type:"text",data:{...so,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"}}},Pu={id:null,type:"objectView",data:{...so,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},sw={id:null,type:"arrayView",data:{...so,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"}}},Iu={id:null,type:"workflowStep",data:{...so,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},It=e=>typeof e=="object",Qm=e=>Array.isArray(e),cw=["order","position","selected","locked","grabbed","grabbable","scratch"],hr=e=>Object.entries(e).reduce((r,[t,n])=>(!It(n)&&!t.startsWith("$")&&(r[t]=n),r),{}),jd=(e,r)=>typeof e=="string"&&e.startsWith("$")?Bo(e,r):It(e)&&!Qm(e)?Object.entries(e).reduce((t,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete t["..."],t[n]={...Bo(o,r),...e}):typeof o=="string"&&o.startsWith("$")?t[n]=Bo(o,r):t[n]=o,t),{}):e,pr=e=>Object.entries(e).reduce((r,[t,n])=>(It(n)&&t&&n&&!t.startsWith("$")&&(cw.includes(t)&&(t=t+"#"),r[t]=n),r),{}),Sr=(e,r,{label:t,parent:n=void 0},o,i=null)=>(i!==null&&(It(i)||Qm(i))&&(i=JSON.stringify(i,null,2)),{data:{parent:n,...e.data,id:r,text:t||"",label:t,code:i||null,type:e.type,description:o}}),lr=(e,r,t=null,n=null,o=null,i=!1,s=null)=>({data:{id:Cd(),source:o?r:e,target:o?e:r,label:n||"",isInverted:o,isEdgeAnimated:i,parent:s}}),gr=(e,r=[])=>{const t={},n={};let o=[];if(e)for(const[i,s]of Object.entries(e))i.startsWith("$")&&i!=="$"?t[i.slice(1)]=s:i!=="$"?n[i]=s:i==="$"&&(o=s);return{newConfig:t,updatedObject:n,arrayObject:o}},$r=(e,r)=>{let t=Pu;const{view:n,borderColor:o,borderRadius:i,bgColor:s,textColor:a,fontSize:c,stepType:l}=r;e=n||e,l?t={...Iu}:e==="object"?t=Pu:e==="text"?t=Sd:e==="array"?t=sw:e==="workflowStep"&&(t={...Iu});const d=t.data.viewProps;return t.data.viewProps={...d,borderRadius:i||(l?15:53),bgColor:s,borderColor:o,textColor:a,fontSize:c},t.data.config=r,{config:t}},kn=(e,r)=>(e=r.find(n=>n.data.id===e)?`${e}.#`:e,e),Bo=(e,{ids:r,jsnObjct:t})=>{if(typeof e=="string"&&(e!=null&&e.startsWith("$"))){const n=e.replace("$","").replace("*","");e==null||e.endsWith("*");const o=r.find(a=>a.split(".").slice(-1)[0]===n||n===a);if(!o)return e;const i=lw(o,t);return JSON.stringify(i).includes(e)?e:i||e}return e},lw=(e,r)=>{let t=e.split(".").splice(1);return t=t[t.length-1]==="#"||t[t.length-1].includes("{")?t.slice(0,-2):t,(i=>t.reduce((s,a)=>{a=a.replace("[","").replace("]","");const{arrayObject:c}=gr(s);return s=c.length?c:s,s[a]},i))(r)};function Fr(e,r="root",t=[]){try{const{arrayObject:n}=gr(e);n.length&&(e=n);const o=hr(e),i=pr(e);return It(e)?(et(e)||et(e)&&r==="root"||!et(e)&&Object.keys(o).length||r==="root")&&t.push(r):t.push(r),Object.keys(i).length&&!et(e)?vn({chldPth:null,itrblObjct:i,nodes:t,path:r}):et(e)&&e.forEach((s,a)=>{const c=hr(s),l=pr(s),{newConfig:d,arrayObject:u}=gr(s);let h=`${r}.${a}`;It(s)?Object.keys(c).length?(Fr(c,h,t),Object.keys(l).length&&!et(s)&&vn({chldPth:h,itrblObjct:l,nodes:t,path:r})):Object.keys(l).length&&!et(s)?vn({chldPth:h,itrblObjct:l,nodes:t,path:r}):et(s)&&eb({chldPth:h,item:s,nodes:t,path:r}):t.push(h)}),{nodes:t}}catch{return{nodes:t}}}const vn=({chldPth:e,itrblObjct:r,nodes:t,path:n})=>Object.entries(r).forEach(([o,i],s)=>{const a=hr(i),c=pr(i),{newConfig:l,arrayObject:d}=gr(i);d.length&&(i=d),n.split(".").slice(0,2).join(".");let u=e?`${e}.${o}`:`${n}.${o}`;if(It(i)&&!et(i)){const h=Object.keys(a).length===0;if(h&&($r("array",l),t.push(u)),Object.keys(a).length){const p=et(i)?`${i.length||""}`:`{${Object.keys(i).length||""}}`;let m=u;h&&(m=`${u}.${p}`),Fr(i,m,t)}else Object.keys(c).length&&!et(i)?vn({chldPth:u,itrblObjct:c,path:u,nodes:t}):Fr(i,u,t)}else et(i)&&Fr(i,u,t)}),eb=({chldPth:e,item:r,nodes:t,path:n})=>r.forEach((o,i)=>{let s=`${e}.${i}`;const a=pr(o),c=hr(o);It(o)?!et(o)&&Object.keys(c).length?Fr(o,s,t):Object.keys(a).length&&!et(o)?vn({chldPth:s,itrblObjct:a,path:n,nodes:t}):et(o)&&eb({chldPth:s,item:o,nodes:t,path:n}):t.push(s)}),xn=[];let wn;function Er(e,r="root",t=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},s={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:t,edges:n};const a=e;if(r==="root"&&(xn.length=0),!wn){const{nodes:d}=Fr(e);wn={ids:d,jsnObjct:e}}let{hideDefaultObject:c,sprtObjctKy:l}=i;try{r=kn(r,t);const{newConfig:d,arrayObject:u}=gr(e),h=Object.keys(s).length>0?s:d;u.length&&(e=u);const p=hr(e),m=pr(e),{label:y,collapsed:g,parent:v}=h;if(!It(e))t.push(Sr(Sd,r,{label:y||r,parent:v},e,a));else if(et(e)||et(e)&&r==="root"){const{config:b}=$r("array",h),x=et(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,w=r==="root"?o:`${o} ${x}`;t.push(Sr(b,r,{label:y||w,parent:v},e,et(a)?{[o]:a}:a))}else if(!et(e)&&Object.keys(p).length||r==="root"){const{config:b}=$r(null,h),x=et(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,w=r.split("."),C=w[w.length-1];let S=isNaN(Number(C))?null:Number(C)+1;const j=isNaN(Number(C))?C:w[w.length-2]+" "+S,P=r==="root"?o:j;let E=!1;Number.isNaN(Number(o))||(E=!0);const O=e;if(y){const{config:A}=$r("object",h);t.push(Sr(A,r,{label:y||`${y} ${x}`,parent:v},p,O))}else b.data.headerTitle=P,t.push(Sr(b,r,{label:y,parent:v},p,O))}return g||(Object.keys(m).length&&!et(e)?Cn({flowConfig:i,chldPth:null,edges:n,isInverted:null,itrblObjct:m,nodes:t,path:r,newConfig:h}):et(e)&&e.forEach((b,x)=>{b=jd(b,wn);const w=b,C=hr(b),S=pr(b),{newConfig:j,arrayObject:P}=gr(b);P.length&&(b=P);const{config:E}=$r(typeof b=="string"?"text":"array",j),{hideConfig:O,sourceLabel:A,label:R,isEdgeAnimated:M,parent:T}=j;c=c||O;const N=r==="root"&&i.isCntr,$=r.split(".").slice(0,2).join("."),I=xn.includes($),K=i.isCntr&&I||x%2===0&&N;let ie=`${r}.${x}`;ie=kn(ie,t),K&&xn.push(ie),It(b)?Object.keys(C).length&&!et(b)?(n.push(lr(r,ie,null,A,K,M)),Er(b,ie,t,n,R||x,i,j)):Object.keys(S).length&&!et(b)?Cn({flowConfig:i,chldPth:ie,isInverted:K,edges:n,itrblObjct:S,nodes:t,path:r,newConfig:j,forceIsInverted:!0}):et(b)?tb({flowConfig:i,chldPth:ie,edges:n,isInverted:K,item:b,nodes:t,path:r}):It(b)&&Cn({flowConfig:i,chldPth:ie,isInverted:K,edges:n,itrblObjct:[b],nodes:t,path:r,newConfig:j}):(n.push(lr(r,ie,null,A,K,M)),t.push(Sr(E,ie,{label:R||String(b),parent:T},b,w)))})),{nodes:t,edges:n}}catch{return{nodes:t,edges:n}}}const Cn=({chldPth:e,flowConfig:r,edges:t,itrblObjct:n,nodes:o,isInverted:i,path:s,newConfig:a,forceIsInverted:c=!1})=>{let{hideDefaultObject:l,sprtObjctKy:d}=r;return Object.entries(n).forEach(([u,h],p)=>{h=jd(h,wn);const m=h,y=hr(h),g=pr(h),{newConfig:v,arrayObject:b}=gr(h);b.length&&(h=b);const{hideConfig:x,sourceLabel:w,label:C,content:S,target:j,targetLabel:P,collapsed:E,isEdgeAnimated:O,parent:A}=v;l=l||x;const R=s==="root"&&r.isCntr,M=s.split(".").slice(0,2).join("."),T=xn.includes(M);c||(i=r.isCntr&&T||p%2===0&&R);let N=e?`${e}.${u}`:`${s}.${u}`;if(N=kn(N,o),i&&xn.push(N),j&&t.push(lr(N,j,null,P,i,O)),It(h)&&!et(h)){t.push(lr(s,N,null,w,i,O));const $=d||Object.keys(y).length===0;if($){const I=S?"object":"array",{config:K}=$r(I,v);K.data.headerTitle=S?C:null,o.push(Sr(K,N,{label:C||u,parent:A},h,m))}if(Object.keys(y).length&&!l){const I=et(h)?` ${h.length||""}`:`{${Object.keys(h).length||""}}`;let K=N;$&&(K=`${N}.${I}`,K=kn(K,o),t.push(lr(N,K,null,w,i,O))),Er(h,K,o,t,C||u,r,v)}else Object.keys(g).length&&!et(h)?Cn({chldPth:N,flowConfig:r,itrblObjct:g,path:N,edges:t,nodes:o,newConfig:v,isInverted:i}):Er(h,N,o,t,u,r,v)}else et(h)&&(t.push(lr(s,N,null,w,i,O)),Er(h,N,o,t,u,r,v))})},tb=({flowConfig:e,chldPth:r,edges:t,isInverted:n,item:o,nodes:i,path:s})=>o.forEach((a,c)=>{let l=`${r}.${c}`;l=kn(l,i);const d=a;a=jd(a,wn);const u=pr(a),h=hr(a),{newConfig:p}=gr(a),{collapsed:m,label:y,parent:g,sourceLabel:v,isEdgeAnimated:b,content:x}=p;It(a)?!et(a)&&Object.keys(h).length?(t.push(lr(s,l,null,v,n,b)),Er(a,l,i,t,c,e,p)):Object.keys(u).length&&!et(a)&&!m?Cn({chldPth:l,flowConfig:e,itrblObjct:u,path:s,edges:t,nodes:i,isInverted:n,newConfig:p}):et(a)&&tb({flowConfig:e,chldPth:l,edges:t,isInverted:n,item:a,nodes:i,path:s}):(t.push(lr(s,l,null,v,n,b)),i.push(Sr(Sd,l,{label:y||String(a),parent:g},a,d)))});function dw(e,r){const t=new Set,n=(l,d="root")=>{if(!(!l||typeof l!="object")){l.$view==="parent"&&t.add(d),typeof l.$parent=="string"&&t.add(l.$parent);for(const[u,h]of Object.entries(l))(!u.startsWith("$")||u==="$")&&n(h,u==="$"?d:`${d}.${u}`)}};if(n(e),!t.size)return r;const o=new Map(r.nodes.map(l=>[l.data.id,l])),i=l=>{var p,m;let d=l.data.id;const u=new Set([l.data.id]);let h=l.data.parent;for(;h&&!u.has(h);)t.has(h)&&o.has(h)&&((p=qe(e,h))!=null&&p.$collapsed)&&(d=h),u.add(h),h=(m=o.get(h))==null?void 0:m.data.parent;return d},s=new Map(r.nodes.map(l=>[l.data.id,i(l)])),a=r.nodes.filter(l=>s.get(l.data.id)===l.data.id).map(l=>{if(!t.has(l.data.id))return l;const d=qe(e,l.data.id),u=!!(d!=null&&d.$collapsed);return{...l,data:{...l.data,...u?{type:"arrayView"}:{},config:{...l.data.config,parentContainer:!0,collapsed:u,...u?{labelBelow:!0,icon:(d==null?void 0:d.$icon)||"PiStack"}:{}}}}}),c=new Set(a.map(l=>l.data.id));return{nodes:a,edges:r.edges.flatMap(l=>{const d=s.get(l.data.source),u=s.get(l.data.target);return!d||!u||!c.has(d)||!c.has(u)?[]:d===l.data.source&&u===l.data.target?[l]:d===u?[]:[{...l,data:{...l.data,source:d,target:u,collapsedEndpoints:l.data.collapsedEndpoints??{source:l.data.source,target:l.data.target}}}]})}}function co(e){if(!Array.isArray(e==null?void 0:e.$connections))return[];const r=new Map;return e.$connections.flatMap((t,n)=>{if(!t||typeof t!="object")return[];const o=t;if(typeof o.target!="string"||!/^root(?:\.|$)/.test(o.target))return[];if(o.sourceProperty!==void 0&&typeof o.sourceProperty!="string")return[];if(o.targetProperty!==void 0&&typeof o.targetProperty!="string")return[];const i=typeof o.id=="string"&&o.id?JSON.stringify(["id",o.id]):JSON.stringify(["ports",o.target,o.sourceProperty??null,o.targetProperty??null]),s=r.get(i)??0;return r.set(i,s+1),[{value:o,key:`${i}#${s}`,index:n}]})}function rb(e,r,t){const n=co(e).find(c=>c.key===r);if(!n)return e;const o=t(n.value),i=e.$connections.flatMap((c,l)=>l===n.index?o?[o]:[]:[c]);if(i.length)return{...e,$connections:i};const{$connections:s,...a}=e;return a}function uw(e){const r=[],t=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,s)=>t(i,`${o}.${s}`));for(const i of co(n)){const s=i.value;r.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:s.target,type:typeof s.type=="string"?s.type:void 0,sourceProperty:s.sourceProperty,targetProperty:s.targetProperty,icon:typeof s.icon=="string"?s.icon:void 0,label:typeof s.label=="string"?s.label:void 0,color:typeof s.color=="string"?s.color:void 0,isEdgeDashed:s.style==="dashed",isEdgeAnimated:s.style==="animated",...["dashed","traveling"].includes(s.animationVariant)?{edgeAnimationVariant:s.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,s])=>[i,i==="$"?t(s,o):i.startsWith("$")?s:t(s,`${o}.${i}`)]))};return{json:t(e,"root"),edges:r}}const zr="root",Mu=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Bt(e){const r=e.split(".");for(r[0]===zr&&r.shift();r.length&&Mu(r[r.length-1]);)r.pop();return r.filter(t=>!Mu(t))}function lo(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function qe(e,r){return Bt(r).reduce((t,n)=>{var o;if(t!=null)return(o=lo(t))==null?void 0:o[n]},e)}function fw(e){return Array.isArray(e)?[...e]:{...e}}function _t(e,r,t){const n=Bt(r),o=(i,s)=>{if(s===n.length)return t(i);const a=n[s],c=lo(i);if(c==null||typeof c!="object")return i;const l=o(c[a],s+1);if(Object.is(l,c[a]))return i;const d=fw(c);return d[a]=l,c!==i?{...i,$:d}:d};return o(e,0)}function er(e,r,t){const n=t===""&&r!=="$content"||t===void 0||t===null;if(Array.isArray(e))return n?e:{[r]:t,$:[...e]};const o=e!=null&&typeof e=="object"?{...e}:{};return e!=null&&typeof e!="object"&&(o.$label=String(e)),n?delete o[r]:o[r]=t,o}function Ct(e,r,t,n){return _t(e,r,o=>t==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:er(o,t,n))}const _d=(e,r,t)=>Ct(e,r,"$collapsed",t);function jr(e){if(e.connection)return{address:e.connection.address,kind:"connection"};const r=e.collapsedEndpoints??e,t=e.isInverted?r.target:r.source,n=e.isInverted?r.source:r.target,o=Bt(t).join("."),i=Bt(n).join(".");return i.startsWith(o?o+".":"")&&i!==o?{address:n,kind:"hierarchy"}:o.startsWith(i?i+".":"")&&o!==i?{address:t,kind:"hierarchy"}:{address:t,kind:"target"}}function cr(e,r,t,n){if(r.connection){const a=r.connection;return _t(e,a.address,c=>rb(c,a.key,l=>{if(t==="$edgeIcon")return er(l,"icon",n);if(t==="$edgeType")return er(l,"type",n);if(t==="$edgeAnimationVariant")return er(l,"animationVariant",n);if(t==="$sourceLabel"||t==="$edgeColor")return er(l,t==="$sourceLabel"?"label":"color",n);const d=t==="$isEdgeAnimated"?"animated":"dashed";return n?{...l,style:d}:l.style===d?er(l,"style",void 0):l}))}const{address:o,kind:i}=jr(r),s=i==="target"&&t==="$sourceLabel"?"$targetLabel":i==="target"&&t==="$edgeType"?"$targetEdgeType":i==="target"&&t==="$edgeIcon"?"$targetIcon":i==="target"&&t==="$edgeAnimationVariant"?"$targetAnimationVariant":t;return _t(e,o,a=>er(a,s,n))}const nb=(e,r,t)=>cr(cr(e,r,"$isEdgeAnimated",t==="animated"||void 0),r,"$isEdgeDashed",t==="dashed"||void 0);function Ed(e,r,t,n){let o=n||"";const i=_t(e,r,a=>{const c=lo(a);if(Array.isArray(c)){o=String(c.length);const d=[...c,t];return c===a?d:{...a,$:d}}const l=a!=null&&typeof a=="object"&&!Array.isArray(a)?{...a}:a!=null&&typeof a!="object"?{$label:String(a)}:{};if(!o){let d=1;for(;`node_${d}`in l;)d++;o=`node_${d}`}return l[o]=t,l}),s=Bt(r);return{json:i,address:[zr,...s,o].join(".")}}function ob(e,r){const t=Bt(r);if(!t.length)return e;const n=t[t.length-1],o=[zr,...t.slice(0,-1)].join(".");return _t(e,o,i=>{const s=lo(i);if(s==null||typeof s!="object"||!Object.prototype.hasOwnProperty.call(s,n))return i;if(Array.isArray(s)){const l=s.filter((d,u)=>String(u)!==n);return s===i?l:{...i,$:l}}const{[n]:a,...c}=i;return c})}const ib=(e,r,t,n)=>Ct(n?_t(e,r,o=>er(o,"$targetLabel",n)):e,r,"$target",t);function kd(e,r,t){const n=qe(e,r);return co(n).some(({value:i})=>i.target===t.target&&i.sourceProperty===t.sourceProperty&&i.targetProperty===t.targetProperty)?e:_t(e,r,i=>er(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...t,id:t.id||Cd()}]))}function ab(e,r){if(r.connection){const i=r.connection;return co(qe(e,i.address)).some(s=>s.key===i.key)?{json:_t(e,i.address,s=>rb(s,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:t,kind:n}=jr(r);return n==="hierarchy"?qe(e,t)===void 0?{json:e,removed:!1}:{json:_t(e,t,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:_t(e,t,i=>{const{$target:s,$targetLabel:a,...c}=i||{};return c}),removed:!0}}function ud(e,r={}){var b;const t=uw(e),{nodes:n,edges:o}=Er(t.json,zr,[],[],r.title||"untitled",{hideDefaultObject:!!r.hideDefaultObject,sprtObjctKy:!!r.separateObjectKeys,isCntr:!!r.isCenter}),i=new Set(n.map(x=>x.data.id)),s=new Map;for(const x of n){const w=x.data.id;if(!w.endsWith(".0")||qe(e,w)!==void 0)continue;const C=w.slice(0,-2),S=qe(e,C);!i.has(C)&&S&&typeof S=="object"&&!Array.isArray(S)&&typeof S.$label=="string"&&Object.keys(S).every(j=>j.startsWith("$")&&j!=="$")&&s.set(w,C)}const a=x=>s.get(x)??x,c=new Set(n.flatMap(x=>x.data.parent?[a(x.data.parent)]:[])),l=new Map;if(r.isCenter){const x=new Map;for(const{data:w}of o){const C=jr(w);if(C.kind==="hierarchy")l.set(a(C.address),!!w.isInverted);else if(!Array.isArray(e)&&e.$hideRoot===!0){const S=a(w.isInverted?w.source:w.target);if(Bt(S).length!==1)continue;const j=!!w.isInverted;x.set(S,x.has(S)&&x.get(S)!==j?null:j)}}for(const[w]of l){const C=`${zr}.${Bt(w)[0]}`,S=x.get(C);typeof S=="boolean"&&l.set(w,S)}}const d=n.map(x=>{var E;const w=a(x.data.id),C=qe(e,w),S={...x.data,id:w};l.has(w)&&(S.config={...S.config,isInverted:l.get(w)});const j=C&&typeof C=="object"&&!Array.isArray(C)&&"$"in C?C.$:C;if((Array.isArray(j)?j.length>0:j&&typeof j=="object"&&Object.keys(j).some(O=>!O.startsWith("$")))&&(S.config={...S.config,collapsed:!!C.$collapsed}),c.has(w)||(S.viewProps={...S.viewProps},delete S.viewProps.borderWidth),!C||typeof C!="object"||Array.isArray(C))return{data:S};if(C.$view==="parent"&&(S.type="objectView",S.config={...S.config,typeView:"parent",parentContainer:!0,collapsed:!!C.$collapsed}),C.$view==="grid"){S.type="grid";const O=C.$gridSize;if(O!==void 0&&(!O||![O.width,O.height].every(A=>Number.isFinite(A)&&A>0&&A<=16384)))throw new Error("Invalid grid frame size.");S.config={...S.config,typeView:"grid",documentId:C.$document,gridSize:O},S.viewProps={...S.viewProps,bgColor:C.$bgColor??"transparent",borderRadius:C.$borderRadius??0,borderWidth:C.$borderWidth??0}}if(C.$form&&typeof C.$form=="object"&&(S.config={...S.config,form:C.$form},S.type="objectView"),Array.isArray(C.$ports)){const O=C.$ports.filter(A=>A&&typeof A.id=="string"&&["source","target"].includes(A.role)&&["top","right","bottom","left"].includes(A.side));S.config={...S.config,ports:O}}if(S.parent&&(S.parent=a(S.parent)),typeof C.$label=="string"&&(S.label=C.$label,S.headerTitle=C.$label),typeof C.$subtitle=="string"&&(S.config={...S.config,subtitle:C.$subtitle}),typeof C.$outline=="boolean"&&(S.viewProps={...S.viewProps,outline:C.$outline}),["solid","dashed","dotted","double"].includes(C.$borderStyle)&&(S.viewProps={...S.viewProps,borderStyle:C.$borderStyle}),Number.isFinite(C.$borderWidth)&&C.$borderWidth>=0&&(S.viewProps={...S.viewProps,borderWidth:C.$borderWidth}),Number.isFinite(C.$borderRadius)&&C.$borderRadius>=0&&(S.viewProps={...S.viewProps,borderRadius:C.$borderRadius}),typeof C.$isNodeAnimated=="boolean"&&(S.isNodeAnimated=C.$isNodeAnimated),["traveling","pulse"].includes(C.$nodeAnimationVariant)&&(S.nodeAnimationVariant=C.$nodeAnimationVariant),typeof C.$content=="string"||C.$contentFormat==="jsx"&&Array.isArray(C.$content)){S.config={...S.config,content:C.$content};const O=C.$contentFormat??"markdown";if(!["markdown","html","jsx"].includes(O))throw new Error("Invalid content format: expected markdown, html, or jsx.");S.config.contentFormat=O,C.$view||(S.type="objectView")}return(((E=S.config)==null?void 0:E.collapsed)!==void 0||C.$collapsed!==void 0||C.$icon!==void 0)&&(S.config={...S.config||{}},(C.$collapsed!==void 0||S.config.collapsed!==void 0)&&(S.config.collapsed=!!C.$collapsed),C.$icon!==void 0&&(S.config.icon=C.$icon)),{data:S}}),u=new Map,h=o.map(x=>{let w=a(x.data.source),C=a(x.data.target),S=x.data.isInverted;const j=jr(x.data),P=l.get(a(j.address));j.kind==="hierarchy"&&P!==void 0&&P!==!!S&&([w,C]=[C,w],S=P);const E=`${w}->${C}`,O=u.get(E)??0;u.set(E,O+1);const A={...x.data,id:O?`${E}#${O}`:E,source:w,target:C,isInverted:S},R=jr(A),M=qe(e,R.address);if(M&&typeof M=="object"){const T=M[R.kind==="target"?"$targetEdgeType":"$edgeType"];typeof T=="string"&&(A.type=T);const N=M[R.kind==="target"?"$targetIcon":"$edgeIcon"];typeof N=="string"&&(A.icon=N),M.$isEdgeAnimated!==void 0&&(A.isEdgeAnimated=!!M.$isEdgeAnimated);const $=M[R.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes($)&&(A.edgeAnimationVariant=$),M.$isEdgeDashed!==void 0&&(A.isEdgeDashed=!!M.$isEdgeDashed),M.$edgeColor&&(A.color=M.$edgeColor)}return{data:A}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const x=d.findIndex(w=>w.data.id===zr);x!==-1&&d.splice(x,1)}const p=new Set(d.map(x=>x.data.id));for(let x=h.length-1;x>=0;x--){const w=h[x].data,C=jr(w);(!p.has(w.source)||!p.has(w.target)||C.kind==="hierarchy"&&((b=qe(e,C.address))==null?void 0:b.$hideParentEdge)===!0)&&h.splice(x,1)}h.push(...t.edges.filter(x=>p.has(x.data.source)&&p.has(x.data.target)));const m=dw(e,{nodes:d,edges:h}),y=m.nodes.filter(x=>{var w;return(w=x.data.config)==null?void 0:w.collapsed}).map(x=>Bt(x.data.id));if(!y.length)return m;const g=m.nodes.filter(x=>{const w=Bt(x.data.id);return!y.some(C=>C.length<w.length&&C.every((S,j)=>S===w[j]))}),v=new Set(g.map(x=>x.data.id));return{nodes:g,edges:m.edges.filter(x=>v.has(x.data.source)&&v.has(x.data.target))}}function hw(e,r){const t=new Set(e.filter(c=>{var l,d;return(d=(l=c.data)==null?void 0:l.config)==null?void 0:d.collapsed}).map(c=>c.data.id));if(!t.size)return{nodes:e,edges:r};const n=new Map(e.map(c=>[c.data.id,c])),o=new Set(e.map(c=>c.data.parent).filter(Boolean)),i=new Map(e.map(c=>{var h;let l=c.data.id,d=c.data.parent;const u=new Set([l]);for(;d&&!u.has(d);)t.has(d)&&(l=d),u.add(d),d=(h=n.get(d))==null?void 0:h.data.parent;return[c.data.id,l]})),s=new Map;for(const c of r){const l=c.data.isInverted?c.data.target:c.data.source,d=c.data.isInverted?c.data.source:c.data.target;(s.get(l)??s.set(l,[]).get(l)).push(d)}const a=new Set(e.filter(c=>i.get(c.data.id)!==c.data.id).map(c=>c.data.id));for(const c of t){if(o.has(c))continue;const l=[...s.get(c)||[]];for(;l.length;){const d=l.pop();t.has(d)||a.has(d)||(a.add(d),l.push(...s.get(d)||[]))}}return{nodes:e.filter(c=>!a.has(c.data.id)).map(c=>{var l;return t.has(c.data.id)&&o.has(c.data.id)?{...c,data:{...c.data,type:"arrayView",label:c.data.label??c.data.headerTitle,config:{...c.data.config,parentContainer:!0,labelBelow:!0,icon:((l=c.data.config)==null?void 0:l.icon)||"PiStack"}}}:c}),edges:r.flatMap(c=>{const l=i.get(c.data.source)??c.data.source,d=i.get(c.data.target)??c.data.target;return a.has(l)||a.has(d)?[]:l===c.data.source&&d===c.data.target?[c]:l===d?[]:[{...c,data:{...c.data,source:l,target:d,collapsedEndpoints:c.data.collapsedEndpoints??{source:c.data.source,target:c.data.target}}}]})}}function Rd(e,r){const t=JSON.parse(e);let n=512;const o=(s,a=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!s||typeof s!="object"||Array.isArray(s))throw new Error("Expected a JSON Schema object.");const c=new Set(["$schema","$id","$defs","definitions","$ref","title","description","default","examples","type","properties","required","items","enum","const","anyOf","additionalProperties"]);for(const d of Object.keys(s))if(!c.has(d))throw new Error(`Unsupported JSON Schema keyword: ${d}`);const l=["$schema","$id","$defs","definitions","title","description","default","examples"];if(s.$ref){if(Object.keys(s).some(u=>!["$ref","title","description"].includes(u)))throw new Error("Use $ref without sibling constraints.");if(typeof s.$ref!="string"||!s.$ref.startsWith("#/")||a.includes(s.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let d=t;for(const u of s.$ref.slice(2).split("/")){const h=u.replace(/~1/g,"/").replace(/~0/g,"~");if(!d||!Object.prototype.hasOwnProperty.call(d,h))throw new Error(`Unresolved reference: ${s.$ref}`);d=d[h]}return o(d,[...a,s.$ref])}if(s.anyOf){if(!Array.isArray(s.anyOf)||!s.anyOf.length||Object.keys(s).some(d=>d!=="anyOf"&&!l.includes(d)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:s.anyOf.map(d=>o(d,a))}}if(Object.prototype.hasOwnProperty.call(s,"const")||s.enum){if(Object.keys(s).some(h=>![...l,"const","enum","type"].includes(h))||s.enum&&Object.prototype.hasOwnProperty.call(s,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const d=Object.prototype.hasOwnProperty.call(s,"const")?[s.const]:s.enum;if(!Array.isArray(d)||!d.length)throw new Error("Expected a nonempty enum.");return{kind:"union",types:d.map(h=>{if(h!==null&&!["string","number","boolean"].includes(typeof h))throw new Error("Only primitive literals are supported.");const p=h===null?"null":typeof h;if(s.type&&!(Array.isArray(s.type)?s.type:[s.type]).some(m=>m===p||m==="integer"&&Number.isInteger(h)))throw new Error("Literal does not match its declared type.");return{kind:"literal",value:h}})}}if(Array.isArray(s.type)){if(!s.type.length||s.type.some(d=>typeof d!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(s).some(d=>d!=="type"&&!l.includes(d)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:s.type.map(d=>o({type:d},a))}}if((s.properties||s.required||s.additionalProperties!==void 0)&&s.type!=="object"&&s.type!==void 0)throw new Error("Object constraints require an object type.");if(s.items&&s.type!=="array")throw new Error("items requires an array type.");if(s.type==="object"||s.properties){if(s.additionalProperties!==void 0&&s.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!s.properties||typeof s.properties!="object"||Array.isArray(s.properties))throw new Error("Object schemas must declare properties.");if(s.required!==void 0&&(!Array.isArray(s.required)||s.required.some(u=>typeof u!="string"||!Object.prototype.hasOwnProperty.call(s.properties,u))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(s.properties).map(([u,h])=>[u,{type:o(h,a),optional:!(s.required??[]).includes(u)}]))}}if(s.type==="array")return{kind:"array",items:o(s.items,a)};if(["string","number","integer","boolean","null"].includes(s.type))return{kind:s.type};throw new Error("Every property must declare a supported type.")},i=o(t);if(i.kind!=="object")throw new Error("The root schema must be an object keyed by node ID.");if(Object.values(i.properties).some(s=>s.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:r,nodes:i.properties}}async function Ad(e,r,t,n={}){var m;let o=512;const i=await import("typescript"),s=i.createSourceFile(r,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),a=s.parseDiagnostics;if(a!=null&&a.length)throw new Error("Invalid TypeScript syntax.");const c=new Map;for(const y of s.statements){if(!i.isInterfaceDeclaration(y)&&!i.isTypeAliasDeclaration(y))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((m=y.typeParameters)!=null&&m.length||c.has(y.name.text))throw new Error("Generics and duplicate declarations are not supported.");c.set(y.name.text,y)}const l=(y,g)=>{var C;const v={},b=y.find(S=>i.isIndexSignatureDeclaration(S));let x;if(b&&n.allowJson&&i.isIndexSignatureDeclaration(b)){if(y.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.");x=u(b.type,g)}return{kind:"object",properties:Object.fromEntries(y.filter(S=>S!==b||!x).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=u(S.type,g),P=n.allowJson?i.getJSDocTags(S).filter(E=>E.tagName.text==="port"):[];if(P.length>1)throw new Error(`Duplicate port declaration: ${S.name.text}`);if(P.length){const[E,O,A]=String(P[0].comment??"").trim().split(/\s+/);if(E!=="config"||!O||A||!c.has(O))throw new Error(`Config port ${S.name.text} requires @port config ResourceType`);const R=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:O,multiple:R}}return[S.name.text,{type:j,optional:!!S.questionToken}]})),...x?{additionalProperties:x}:{},...Object.keys(v).length?{ports:v}:{}}},d=(y,g)=>{var C;if(g.includes(y))throw new Error("Recursive types are not supported.");const v=c.get(y);if(!v)throw new Error(`Unknown type: ${y}`);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=l(v.members,[...g,y])}else b=u(v.type,[...g,y]);const x=n.allowJson?i.getJSDocTags(v).filter(S=>S.tagName.text==="port"):[];if(!x.length)return b;if(b.kind!=="object")throw new Error("Node ports require an object interface");const w={...b.ports};for(const S of x){const[j,P,...E]=String(S.comment??"").trim().split(/\s+/);if(!["input","output","error"].includes(j)||!/^[A-Za-z][\w-]*$/.test(P??""))throw new Error("Node ports require @port input|output|error Name");const O=E.length?JSON.parse(E.join(" ")):void 0;if(O!==void 0&&typeof O!="string")throw new Error("Node port labels must be JSON strings");if(Object.prototype.hasOwnProperty.call(w,P))throw new Error(`Duplicate port declaration: ${P}`);w[P]={kind:j,...typeof O=="string"?{label:O}:{}}}return{...b,ports:w}},u=(y,g)=>{var v,b,x;if(--o<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(y.kind===i.SyntaxKind.StringKeyword)return{kind:"string"};if(y.kind===i.SyntaxKind.NumberKeyword)return{kind:"number"};if(y.kind===i.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[i.SyntaxKind.AnyKeyword,i.SyntaxKind.UnknownKeyword].includes(y.kind))return{kind:"json"};if(i.isParenthesizedTypeNode(y))return u(y.type,g);if(i.isUnionTypeNode(y))return{kind:"union",types:y.types.map(w=>u(w,g))};if(i.isArrayTypeNode(y))return{kind:"array",items:u(y.elementType,g)};if(i.isTypeLiteralNode(y))return l(y.members,g);if(i.isLiteralTypeNode(y)){const w=y.literal;if(i.isStringLiteral(w))return{kind:"literal",value:w.text};if(i.isNumericLiteral(w))return{kind:"literal",value:Number(w.text)};if(w.kind===i.SyntaxKind.NullKeyword)return{kind:"null"};if(w.kind===i.SyntaxKind.TrueKeyword||w.kind===i.SyntaxKind.FalseKeyword)return{kind:"literal",value:w.kind===i.SyntaxKind.TrueKeyword}}if(i.isTypeReferenceNode(y)&&i.isIdentifier(y.typeName)){if(n.allowJson&&y.typeName.text==="Record"&&!c.has("Record")&&((v=y.typeArguments)==null?void 0:v.length)===2&&y.typeArguments[0].kind===i.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:u(y.typeArguments[1],g)};if(y.typeName.text==="Array"&&((b=y.typeArguments)==null?void 0:b.length)===1)return{kind:"array",items:u(y.typeArguments[0],g)};if(!((x=y.typeArguments)!=null&&x.length))return d(y.typeName.text,g)}throw new Error(`Unsupported TypeScript type: ${y.getText(s)}`)},h=t??(c.has("Graph")?"Graph":c.size===1?[...c.keys()][0]:void 0);if(!h)throw new Error("Declare an interface Graph keyed by node ID.");const p=d(h,[]);if(p.kind!=="object")throw new Error("Graph must be an object keyed by node ID.");return p}async function sb(e,r){const t=await Ad(e,r);if(Object.values(t.properties).some(n=>n.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:r,nodes:t.properties}}function fn(e,r){if(e.kind==="json"||r.kind==="json"||e.kind==="object"&&e.additionalProperties||r.kind==="object"&&r.additionalProperties)return!1;if(e.kind==="union")return e.types.every(t=>fn(t,r));if(r.kind==="union")return r.types.some(t=>fn(e,t));if(e.kind==="literal"){if(r.kind==="literal")return e.value===r.value;const t=e.value===null?"null":typeof e.value;return r.kind===t||r.kind==="integer"&&typeof e.value=="number"&&Number.isInteger(e.value)}return e.kind==="integer"&&r.kind==="number"?!0:e.kind==="array"&&r.kind==="array"?fn(e.items,r.items):e.kind==="object"&&r.kind==="object"?Object.entries(r.properties).every(([t,n])=>{const o=Object.prototype.hasOwnProperty.call(e.properties,t)?e.properties[t]:void 0;return o?(n.optional||!o.optional)&&fn(o.type,n.type):n.optional}):e.kind===r.kind}function Pd(e,r){if(!r.sourceProperty&&!r.targetProperty)return;const t=(s,a)=>{var d;const c=Object.prototype.hasOwnProperty.call(e.nodes,s)?s:s.replace(/^root\./,""),l=Object.prototype.hasOwnProperty.call(e.nodes,c)?(d=e.nodes[c])==null?void 0:d.type:void 0;return a&&(l==null?void 0:l.kind)==="object"&&Object.prototype.hasOwnProperty.call(l.properties,a)?l.properties[a]:void 0},n=t(r.source,r.sourceProperty),o=t(r.target,r.targetProperty);if(!n||!o)return"Unverified: source or target property is missing from the interface.";const i=s=>s.kind==="json"||s.kind==="object"&&(!!s.additionalProperties||Object.values(s.properties).some(a=>i(a.type)))||s.kind==="array"&&i(s.items)||s.kind==="union"&&s.types.some(i);if(i(n.type)||i(o.type))return"Unverified: arbitrary JSON or dictionary fields require runtime validation.";if(n.optional&&!o.optional)return"Optional source cannot supply a required target property.";if(!fn(n.type,o.type))return`Incompatible property types: ${r.sourceProperty} -> ${r.targetProperty}.`}async function cb(e){if(e.size>256*1024)throw new Error("Interface must be 256 KB or smaller.");const r=await e.text();if(/\.json$/i.test(e.name))return Rd(r,e.name);if(/\.ts$/i.test(e.name))return sb(r,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Tu=new WeakMap;function Wr(e){if(!e||typeof e!="object")return e;const r=Tu.get(e);if(r)return r;const t=()=>{throw new Error("Form callback data is read-only. Return edits instead.")},n=new Proxy(Array.isArray(e)?[]:{},{get:(o,i)=>Wr(Reflect.get(e,i)),has:(o,i)=>Reflect.has(e,i),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(o,i)=>{const s=Reflect.getOwnPropertyDescriptor(e,i);return s&&{...s,value:Wr(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:t,deleteProperty:t,defineProperty:t,setPrototypeOf:t,preventExtensions:t});return Tu.set(e,n),n}function Zr(e,r,t){var o;const n=r.split(".");for(let i=n.length;i>0;i--){const s=n.slice(0,i).join("."),a=(o=qe(e,s))==null?void 0:o.$form;if(!(a!=null&&a.$type))continue;let c=Object.prototype.hasOwnProperty.call(t,a.$type)?t[a.$type]:void 0;for(const u of n.slice(i))(c==null?void 0:c.kind)==="array"&&/^\d+$/.test(u)?c=c.items:(c==null?void 0:c.kind)==="object"?c=Object.prototype.hasOwnProperty.call(c.properties,u)?c.properties[u].type:void 0:c=void 0;if((c==null?void 0:c.kind)!=="object")return;const l=n.slice(i).join("."),d=Object.fromEntries(Object.entries(a.$fields??{}).filter(([u])=>!l||u.startsWith(`${l}.`)).map(([u,h])=>[l?u.slice(l.length+1):u,h]));return{type:c,fields:d,binding:a}}}async function Id(e,r){if(e.size>256*1024)throw new Error("Form schema exceeds 256 KB.");const t=await e.text();if(e.name.endsWith(".ts")){if(!r.length||r.length>32)throw new Error("Choose between 1 and 32 form interface names.");const o=[],i=new Set(r);for(const s of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const a=await Ad(t,e.name,s,{allowJson:!0});o.push([s,a]);for(const c of Object.values(a.ports??{}))c.resourceType&&i.add(c.resourceType)}return Object.fromEntries(o)}if(!e.name.endsWith(".json"))throw new Error("Choose a .ts interface or .json schema file.");const n=Rd(t,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([o,i])=>[o,i.type]))}function uo(e,r){return!e||("$in"in e?e.$in.includes(qe(r,e.$address)):qe(r,e.$address)===e.$equals)}function Sn(e){const r=e.kind==="array"?e.items:e,t=r.kind==="union"?r.types:[r];if(t.every(n=>n.kind==="literal"))return t.map(n=>({label:String(n.value),value:n.value}))}function Dt(e,r,t){if(r===void 0||r==="")return t?"Required":void 0;if(e.kind==="json"){const n=new Set,o=i=>{if(i===null||typeof i=="string"||typeof i=="boolean")return!0;if(typeof i=="number")return Number.isFinite(i);if(!i||typeof i!="object"||n.has(i)||!Array.isArray(i)&&![Object.prototype,null].includes(Object.getPrototypeOf(i)))return!1;n.add(i);const s=Object.values(i).every(o);return n.delete(i),s};return o(r)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!Dt(n,r,!0))?void 0:"Choose a valid value";if(e.kind==="literal")return r===e.value?void 0:"Choose a valid value";if(e.kind==="array")return Array.isArray(r)&&r.every(n=>!Dt(e.items,n,!0))?void 0:"Invalid list value";if(e.kind==="object")return!r||typeof r!="object"||Array.isArray(r)?"Expected an object":e.additionalProperties&&Object.entries(r).some(([n,o])=>!Object.prototype.hasOwnProperty.call(e.properties,n)&&Dt(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>Dt(o.type,r[n],!o.optional))?"Invalid object fields":void 0;if(e.kind==="null")return r===null?void 0:"Expected null";if(e.kind==="integer")return Number.isInteger(r)?void 0:"Expected a whole number";if(typeof r!==e.kind||typeof r=="number"&&!Number.isFinite(r))return`Expected ${e.kind}`}function Ou(e,r){const t=r.address.split(".");if(t.shift()!=="root"||!t.length||t.some(a=>!a||["__proto__","prototype","constructor","#"].includes(a)))throw new Error("Invalid form field address.");const n=t.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(t.some(a=>a.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...t].join("."),s=qe(e,i);if(!s||typeof s!="object")throw new Error(`Missing form parent: ${i}`);if(o){if(r.op==="set"&&typeof r.value!="string")throw new Error("Node colors must be strings.");return Ct(e,i,n,r.op==="remove"?void 0:r.value)}return _t(e,i,a=>{const c=Array.isArray(a.$)?a.$:a;if(r.op==="remove"&&!Object.prototype.hasOwnProperty.call(c,n)||r.op==="set"&&Object.is(c[n],r.value))return a;const l=Array.isArray(c)?[...c]:{...c};if(Array.isArray(l)&&(!/^(0|[1-9]\d*)$/.test(n)||Number(n)>=l.length))throw new Error("Invalid array address.");return r.op==="remove"?Array.isArray(l)?l.splice(Number(n),1):delete l[n]:Object.defineProperty(l,n,{value:structuredClone(r.value),enumerable:!0,writable:!0,configurable:!0}),c===a?l:{...a,$:l}})}function fo(e,r,t){let n=Ou(e,r.value===void 0?{op:"remove",address:r.address}:{op:"set",address:r.address,value:r.value});const o=t==null?void 0:t({...r,previousValue:Wr(qe(e,r.address)),data:Wr(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=Ou(n,i)}return n}const jn="data:image/svg+xml;base64,";function ar(e){if(e.startsWith(jn))return!0;try{const r=new URL(e);return(r.protocol==="https:"||r.protocol==="http:")&&!r.username&&!r.password}catch{return!1}}async function pw(e){if(e.size>256*1024)throw new Error("SVG must be 256 KB or smaller.");const r=await e.text(),t=new DOMParser().parseFromString(r,"image/svg+xml");if(t.doctype||t.querySelector("parsererror")||t.documentElement.localName!=="svg"||t.documentElement.namespaceURI!=="http://www.w3.org/2000/svg")throw new Error("Choose a valid SVG file.");if(t.querySelector("script, foreignObject")||[...t.querySelectorAll("*")].some(i=>[...i.attributes].some(s=>/^on/i.test(s.name))))throw new Error("SVG scripts and event handlers are not allowed.");const n=new TextEncoder().encode(r);let o="";for(const i of n)o+=String.fromCharCode(i);return jn+btoa(o)}const Zt=({name:e,svg:r=!1,...t})=>{const[n,o]=_.useState(null),[i,s]=_.useState(!0),[a,c]=_.useState(!1),l=typeof e=="string"&&ar(e);if(_.useEffect(()=>{if(l||!e||e.length<2){o(null),s(!1);return}s(!0),c(!1),(async()=>{try{let u;if(e.startsWith("Md"))u="md";else if(e.startsWith("Fa"))u="fa6";else if(e.startsWith("Io5"))u="io5";else if(e.startsWith("Io"))u="io";else if(e.startsWith("Ti"))u="ti";else if(e.startsWith("Go"))u="go";else if(e.startsWith("Fi"))u="fi";else if(e.startsWith("Di"))u="di";else if(e.startsWith("Ai"))u="ai";else if(e.startsWith("Bs"))u="bs";else if(e.startsWith("Ri"))u="ri";else if(e.startsWith("Fc"))u="fc";else if(e.startsWith("Gi"))u="gi";else if(e.startsWith("Hi2"))u="hi2";else if(e.startsWith("Hi"))u="hi";else if(e.startsWith("Si"))u="si";else if(e.startsWith("Sl"))u="sl";else if(e.startsWith("Im"))u="im";else if(e.startsWith("Bi"))u="bi";else if(e.startsWith("Pi"))u="pi";else if(e.startsWith("Vsc"))u="vsc";else if(e.startsWith("Tb"))u="tb";else if(e.startsWith("Tfi"))u="tfi";else if(e.startsWith("Cg"))u="cg";else if(e.startsWith("Lia"))u="lia";else if(e.startsWith("Lu"))u="lu";else throw new Error(`Unknown library prefix for icon: ${e}`);let h;switch(u){case"md":h=await import("react-icons/md");break;case"fa6":h=await import("react-icons/fa6");break;case"io5":h=await import("react-icons/io5");break;case"io":h=await import("react-icons/io");break;case"ti":h=await import("react-icons/ti");break;case"go":h=await import("react-icons/go");break;case"fi":h=await import("react-icons/fi");break;case"di":h=await import("react-icons/di");break;case"ai":h=await import("react-icons/ai");break;case"bs":h=await import("react-icons/bs");break;case"ri":h=await import("react-icons/ri");break;case"fc":h=await import("react-icons/fc");break;case"gi":h=await import("react-icons/gi");break;case"hi2":h=await import("react-icons/hi2");break;case"hi":h=await import("react-icons/hi");break;case"si":h=await import("react-icons/si");break;case"sl":h=await import("react-icons/sl");break;case"im":h=await import("react-icons/im");break;case"bi":h=await import("react-icons/bi");break;case"pi":h=await import("react-icons/pi");break;case"vsc":h=await import("react-icons/vsc");break;case"tb":h=await import("react-icons/tb");break;case"tfi":h=await import("react-icons/tfi");break;case"cg":h=await import("react-icons/cg");break;case"lia":h=await import("react-icons/lia");break;case"lu":h=await import("react-icons/lu");break;default:throw new Error(`Unsupported library: ${u}`)}const p=h[e];if(!p)throw new Error(`Icon ${e} not found in library ${u}`);o(()=>p)}catch(u){console.warn(`Failed to load icon ${e}:`,u.message),c(!0),o(null)}finally{s(!1)}})()},[e,l]),l){const{size:d=80,style:u,...h}=t;return r?f.jsx("image",{...h,href:e,width:d,height:d,preserveAspectRatio:"xMidYMid meet",style:u}):f.jsx("img",{...h,src:e,alt:"",width:d,height:d,referrerPolicy:"no-referrer",style:{objectFit:"contain",...u}})}return i||!n?null:f.jsx(n,{...t})};function gw(e,r){let t=e;for(const n of r){if(n.op!=="set"&&n.op!=="remove")throw new Error("Unsupported state edit.");const o=n.address.split(".");if(o.some(s=>s.startsWith("$")||["__proto__","prototype","constructor"].includes(s)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;Rn(i),t=fo(t,{address:n.address,nodeAddress:o.slice(0,-1).join("."),value:i})}return Rn(t),t}function On(e,r,t){const n=Object.prototype.hasOwnProperty.call(e,r)?e[r]:void 0;if(!(!n||!t||!Object.prototype.hasOwnProperty.call(t,n.type)))return{address:n.address,type:t[n.type],fields:n.fields??{}}}function Rn(e){if(!(!e||typeof e!="object"))for(const[r,t]of Object.entries(e)){if(r.startsWith("$")||["__proto__","prototype","constructor"].includes(r))throw new Error(`Form state cannot contain view metadata or unsafe keys: ${r}`);Rn(t)}}function yw(e,r,t){Rn(r.value);const n=fo(e,r,t);return Rn(n),n}function lb(e,r){const t=(n,o="")=>{if(!n||typeof n!="object")return n;if(["$label","$subtitle","$content","$icon","$bgColor","$textColor","$borderColor"].includes(o)&&typeof n.$state=="string"){const s=qe(r,n.$state);return s==null?"":typeof s=="object"?JSON.stringify(s,null,2):String(s)}let i=n;for(const[s,a]of Object.entries(n)){const c=t(a,s);c!==a&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,s,{value:c,enumerable:!0,writable:!0,configurable:!0}))}return i};return t(e)}const mw=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),bw=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,hn=(e,r)=>JSON.stringify([e,r]);function An(e,r){if(e.kind==="union"){const t=e.types.find(n=>n.kind===(Array.isArray(r)?"array":r===null?"null":typeof r)||n.kind==="literal"&&Object.is(n.value,r));return An(t??e.types.find(n=>n.kind!=="null")??e.types[0]??{kind:"json"},r)}return e.kind!=="json"?e:Array.isArray(r)?{kind:"array",items:{kind:"json"}}:r!==null&&typeof r=="object"||r===void 0?{kind:"object",properties:{},additionalProperties:{kind:"json"}}:{kind:r===null?"null":typeof r}}function pn(e){const r=An(e,void 0);return r.kind==="object"?{}:r.kind==="array"?[]:r.kind==="literal"?r.value:r.kind==="number"||r.kind==="integer"?0:r.kind==="boolean"?!1:r.kind==="null"?null:""}function Nu(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"&&!Sn(e)?e.types:[e]}function vw(e,r,t){if(r.address===t.address)return;const n=qe(e,r.address),o=(i,s)=>s===void 0?!1:i.kind==="union"?i.types.some(a=>o(a,s)):i.kind==="array"?Array.isArray(s)&&s.every(a=>o(i.items,a)):i.kind==="object"?!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(i.properties).every(([a,c])=>c.optional&&s[a]===void 0||o(c.type,s[a]))&&Object.entries(s).every(([a,c])=>Object.prototype.hasOwnProperty.call(i.properties,a)||!i.additionalProperties||o(i.additionalProperties,c)):s===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!Dt(i,s,!0);if(o(t.type,n))return structuredClone(n)}function db(e,r,t,n){var c,l;const o={sourceSchema:t,sourceBindings:r,nodes:[],edges:[],schema:{...t},bindings:{...r},slots:new Map,containers:new Map},i=new Set(n.map(d=>d.data.id)),s=new Map(n.flatMap(d=>{const u=r[d.data.id];return u&&t[u.type]?[[u.address,d.data.id]]:[]})),a=(d,u,h,p,m,y=!1)=>{var j,P,E,O,A;if(m>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const g=qe(e,u),v=An(h,g),b=v.kind!=="object"&&v.kind!=="array";o.containers.set(d,{address:u,type:v,declared:h,scalar:b});const x=`__form:${d}`,w={...(j=o.bindings[d])==null?void 0:j.fields},C={kind:"object",properties:{},ports:{...v.kind==="object"?v.ports:{},...y?{resource:{label:"output",...v.kind==="object"?(P=v.ports)==null?void 0:P.resource:{},kind:"output"}}:{}}},S=v.kind==="object"?{...v.properties,...Object.fromEntries(Object.keys(g??{}).filter(R=>!Object.prototype.hasOwnProperty.call(v.properties,R)&&v.additionalProperties).map(R=>[R,{type:v.additionalProperties,optional:!0}]))}:v.kind==="array"?Object.fromEntries((Array.isArray(g)?g:[]).map((R,M)=>[String(M),{type:v.items,optional:!0}])):{value:{type:Sn(h)?h:v,optional:!1}};for(const[R,M]of Object.entries(S)){if(!mw(R))throw new Error(`Unsupported structured property key: ${R}`);const T=b?u:`${u}.${R}`,N=qe(e,T),$=An(M.type,N),I=$.kind==="object"||$.kind==="array",K=(E=C.ports)==null?void 0:E[R],ie=(K==null?void 0:K.kind)==="config"&&(((O=w[R])==null?void 0:O.$options)||Sn(M.type)),se=M.type.kind==="json"||M.type.kind==="union"&&!Sn(M.type);if(((A=w[R])==null?void 0:A.$control)==="upload"||!I&&v.kind!=="array"&&(!se||b)||ie){C.properties[R]={...M,type:M.type.kind==="json"?$:M.type};continue}const te=s.get(T)??bw(T),me=v.kind==="array"?`Item ${Number(R)+1}`:R,ve={address:T,owner:d,field:R,type:M.type,label:me,nodeId:te,present:N!==void 0};if(o.slots.set(hn(d,R),ve),C.ports[R]={kind:"config",resourceType:`__form:${te}`},N===void 0||(o.edges.push({data:{id:`__form-edge:${d}:${R}`,source:te,target:d,sourceProperty:"output:resource",targetProperty:`config:${R}`,isEdgeDashed:!0}}),o.containers.has(te)||s.has(T)))continue;if(i.has(te))throw new Error(`Structured node identity conflict: ${te}`);i.add(te);const F={data:{id:te,type:"objectView",label:me,headerTitle:me,description:{},config:{form:!0,icon:$.kind==="array"?"PiListNumbers":I?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push(F),a(te,T,M.type,p,m+1,!0);const D=o.schema[`__form:${te}`];F.data.description=Object.fromEntries(Object.keys(D.properties).map(W=>[W,qe(e,$.kind==="array"||$.kind==="object"?`${T}.${W}`:T)]).filter(([,W])=>W!==void 0))}o.schema[x]=C,o.bindings[d]={...o.bindings[d],address:u,type:x,fields:w}};for(const d of n){const u=r[d.data.id];if(u!=null&&u.portResources)continue;const h=u&&t[u.type];!u||!h||qe(e,u.address)===void 0||a(d.data.id,u.address,h,(c=d.data.viewProps)==null?void 0:c.bgColor,0,o.edges.some(p=>p.data.source===d.data.id))}for(const d of o.edges){const u=o.bindings[d.data.source],h=o.schema[u.type].ports;h.resource={...h.resource,kind:"output",label:((l=h.resource)==null?void 0:l.label)??"output"}}return o}const _r=(e="reference")=>({kind:e,text:"",paths:[""]}),ub=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(r=>["__proto__","constructor","prototype"].includes(r));function xw(e,r){const t=new Set(r.map(s=>s.path)),n=s=>{if(!s.paths.length||s.paths.some(a=>!ub(a)||!t.has(a)))throw new Error("Choose an available reference.");return[...s.paths,...s.fallback===void 0?[]:[JSON.stringify(s.fallback)]].join(" || ")},o=s=>{if(s.includes("{{")||s.includes("}}"))throw new Error("Use a reference part for dynamic values.");return s},i=s=>s.map(a=>{if(a.kind==="text")return o(a.text);if(a.kind==="conditional"){if(a.paths.length!==1||a.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(a)}}}${o(a.text)}{{/if}}`}return`{{${n(a)}}}`}).join("");if(e.mode==="reference"||e.mode==="condition"){if(e.parts.length!==1||e.parts[0].kind!=="reference")throw new Error("Choose one reference binding.");const s=i(e.parts);return e.mode==="condition"?`${s} == ${JSON.stringify(e.comparison)}`:s}if(e.mode==="json"){const s=e.fields.map(a=>a.key);if(!s.length||new Set(s).size!==s.length||s.some(a=>!a||["__proto__","constructor","prototype"].includes(a)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(a=>[a.key,i(a.parts)])))}return i(e.parts)}async function ww(e){const r=await import("typescript"),t=s=>{const a=r.createSourceFile("binding.ts",`(${s})`,r.ScriptTarget.Latest,!0,r.ScriptKind.TS);if(a.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const c=a.statements[0];if(!c||!r.isExpressionStatement(c))throw new Error("Unsupported reference expression.");const l=_r();l.paths=[];const d=u=>{if(r.isParenthesizedExpression(u))return d(u.expression);if(r.isBinaryExpression(u)&&u.operatorToken.kind===r.SyntaxKind.BarBarToken){d(u.left),d(u.right);return}if(r.isStringLiteral(u)){if(l.fallback!==void 0)throw new Error("Multiple fallback values.");l.fallback=u.text;return}const h=u.getText(a);if(!ub(h)||l.fallback!==void 0)throw new Error("Unsupported reference expression.");l.paths.push(h)};if(d(c.expression),!l.paths.length)throw new Error("A binding needs a reference.");return l},n=s=>{const a=[];let c=0;const l=/\{\{([\s\S]*?)\}\}/g;for(const d of s.matchAll(l)){const u=d.index;if(u<c)continue;u>c&&a.push({..._r("text"),text:s.slice(c,u)});const h=d[1].trim();if(h.startsWith("#if ")){const p=s.indexOf("{{/if}}",u+d[0].length);if(p<0)throw new Error("Unclosed condition.");a.push({...t(h.slice(4)),kind:"conditional",text:s.slice(u+d[0].length,p)}),c=p+7}else a.push(t(h)),c=u+d[0].length}return c<s.length&&a.push({..._r("text"),text:s.slice(c)}),a},o={mode:"reference",parts:[_r()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const s=JSON.parse(e);if(s&&typeof s=="object"&&!Array.isArray(s)&&Object.values(s).every(a=>typeof a=="string"))return{...o,mode:"json",fields:Object.entries(s).map(([a,c])=>({key:a,parts:n(c)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const s=r.createSourceFile("condition.ts",`value ${i[1].text}`,r.ScriptTarget.Latest,!0,r.ScriptKind.TS),a=s.statements[0];if(s.statements.length===1&&r.isExpressionStatement(a)&&r.isBinaryExpression(a.expression)&&a.expression.operatorToken.kind===r.SyntaxKind.EqualsEqualsToken&&r.isStringLiteral(a.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:a.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function $u({parts:e,references:r,onChange:t,disabled:n}){const o=(i,s)=>t(e.map((a,c)=>c===i?{...a,...s}:a));return f.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,s)=>f.jsxs("fieldset",{"data-binding-part":s,style:{border:0,padding:0,margin:0,minWidth:0},children:[f.jsxs("legend",{children:["Part ",s+1]}),f.jsxs("div",{style:{display:"flex",gap:8},children:[f.jsxs("span",{"data-form-select":"",style:{flex:1},children:[f.jsxs("select",{"aria-label":"Part type",disabled:n,value:i.kind,onChange:a=>o(s,{kind:a.target.value}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"text",children:"Text"}),f.jsx("option",{value:"conditional",children:"Conditional text"})]}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),f.jsx(Me,{"aria-label":`Remove part ${s+1}`,title:"Remove part",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t(e.filter((a,c)=>c!==s))})]}),i.kind!=="text"&&f.jsxs(f.Fragment,{children:[i.paths.map((a,c)=>f.jsxs("label",{children:["Reference ",c+1,f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":`Reference ${c+1}`,disabled:n,value:a,onChange:l=>o(s,{paths:i.paths.map((d,u)=>u===c?l.target.value:d)}),children:[f.jsx("option",{value:"",children:"Select reference"}),r.map(l=>f.jsx("option",{value:l.path,children:l.label},l.path))]}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},c)),i.kind==="reference"&&f.jsxs(f.Fragment,{children:[f.jsx(Me,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>o(s,{paths:[...i.paths,""]})}),f.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center"},children:[f.jsx("input",{type:"checkbox","aria-label":"Default value enabled",disabled:n,checked:i.fallback!==void 0,onChange:a=>o(s,{fallback:a.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&f.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:a=>o(s,{fallback:a.target.value})})]})]}),i.kind!=="reference"&&f.jsxs("label",{children:["Text",f.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:a=>o(s,{text:a.target.value})})]})]},s)),f.jsx(Me,{"aria-label":"Add part",title:"Add part",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t([...e,_r()])})]})}function Cw({label:e,value:r,references:t,disabled:n,onChange:o}){const[i,s]=_.useState(),[a,c]=_.useState(""),[l,d]=_.useState(!1),u=async()=>{d(!0),c("");try{s(await ww(typeof r=="string"?r:""))}catch(h){c(h instanceof Error?h.message:"Unable to read binding.")}finally{d(!1)}};return f.jsxs("div",{"data-runtime-binding":e,style:{marginBottom:8},children:[f.jsx(Me,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:f.jsx(Z.PiLink,{size:18}),size:"sm",variant:"ghost",disabled:n||l,onClick:u}),typeof r=="string"&&r.includes("{{")&&f.jsx("span",{children:"Bound value"}),i&&f.jsxs("fieldset",{disabled:n,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Binding mode",f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":"Binding mode",value:i.mode,onChange:h=>s({...i,mode:h.target.value,parts:[_r()]}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"condition",children:"Equals"}),f.jsx("option",{value:"template",children:"Text template"}),f.jsx("option",{value:"json",children:"JSON output"})]}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),i.mode==="json"?f.jsxs(f.Fragment,{children:[i.fields.map((h,p)=>f.jsxs("fieldset",{"data-output-field":p,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Output field name",f.jsx("input",{"aria-label":"Output field name",value:h.key,onChange:m=>s({...i,fields:i.fields.map((y,g)=>g===p?{...y,key:m.target.value}:y)})})]}),f.jsx($u,{parts:h.parts,references:t,disabled:n,onChange:m=>s({...i,fields:i.fields.map((y,g)=>g===p?{...y,parts:m}:y)})}),f.jsx(Me,{"aria-label":"Remove output field",title:"Remove output field",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:i.fields.filter((m,y)=>y!==p)})})]},p)),f.jsx(Me,{"aria-label":"Add output field",title:"Add output field",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:[...i.fields,{key:"",parts:[_r()]}]})})]}):f.jsx($u,{parts:i.parts,references:t,disabled:n,onChange:h=>s({...i,parts:h})}),i.mode==="condition"&&f.jsxs("label",{children:["Equals",f.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:h=>s({...i,comparison:h.target.value})})]}),f.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[f.jsx(Me,{"aria-label":"Apply binding",title:"Apply binding",icon:f.jsx(Z.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(xw(i,t)),s(void 0),c("")}catch(h){c(h instanceof Error?h.message:"Unable to apply binding.")}}}),f.jsx(Me,{"aria-label":"Cancel binding",title:"Cancel binding",icon:f.jsx(Z.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{s(void 0),c("")}})]})]}),a&&f.jsx("p",{role:"alert",children:a})]})}function Sw({nodeAddress:e,onOpen:r}){const{structured:t,data:n,callbacks:o,editable:i,onFieldCreate:s}=_.useContext(Mt),a=Ze(),[c,l]=_.useState(""),[d,u]=_.useState("0"),[h,p]=_.useState(""),m=t==null?void 0:t.containers.get(e);if(!m||!n||!t)return null;const y=a.readOnly||a.config.editable===!1||!i,g=qe(n,m.address),v=Nu(m.declared),b=m.type.kind==="array"?m.type.items:m.type.kind==="object"?m.type.additionalProperties:void 0,x=b?Nu(b):[],w=!!s&&m.type.kind==="object"&&(b==null?void 0:b.kind)==="json",C=M=>M.kind==="literal"?String(M.value):M.kind==="string"?"Text":$t(M.kind),S=[...t.slots.values()].filter(M=>M.owner===e),j=(M,T)=>{var N;return(N=o.onFormChange)==null?void 0:N.call(o,{data:n,nodeAddress:m.address,address:M,previousValue:qe(n,M),value:T})},P=M=>{var T;a.setSelectedNodeIds([M]),(T=a.engineRef.current)==null||T.focusNode(M,90,!1)},E=(M,T)=>{if(!Array.isArray(g))return;const N=[...g];[N[M],N[M+T]]=[N[M+T],N[M]],j(m.address,N)},O=()=>{const M=x[Number(d)]??x[0];if(M)if(m.type.kind==="array")j(m.address,[...Array.isArray(g)?g:[],pn(M)]);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(g,c)){p("Property already exists.");return}w&&(d==="file"||d==="files")?s==null||s({data:n,nodeAddress:m.address,address:`${m.address}.${c}`,previousValue:void 0,value:d==="files"?[]:""},{$control:"upload"}):j(`${m.address}.${c}`,pn(M)),l(""),p("")}},A=m.type.kind==="object"&&!!m.type.additionalProperties,R=m.type.kind==="array";return f.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[v.length>1&&f.jsxs("label",{children:["Value type",f.jsx("span",{"data-form-select":"",style:{display:"block"},children:f.jsx(Pt,{"aria-label":"Value type",disabled:y,value:String(v.findIndex(M=>An(M,g).kind===m.type.kind)),onValueChange:M=>j(m.address,pn(v[Number(M)])),children:v.map((M,T)=>f.jsx("option",{value:T,children:C(M)},T))})})]}),S.map((M,T)=>f.jsxs("div",{"data-structured-slot":M.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[M.type.kind==="array"?f.jsx(Z.PiListNumbers,{size:20}):f.jsx(Z.PiBracketsCurly,{size:20}),f.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:$t(M.label)}),f.jsx(Me,{"aria-label":`${M.present?r?"Edit":"Focus":"Create"} ${$t(M.label)}`,title:`${M.present?r?"Edit":"Focus":"Create"} ${$t(M.label)}`,icon:M.present?f.jsx(Z.PiMagnifyingGlass,{size:18}):f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:y&&!M.present,onClick:N=>{var $;M.present?r?r(M.nodeId):(($=N.currentTarget.closest("dialog"))==null||$.close(),P(M.nodeId)):j(M.address,pn(M.type))}}),R&&f.jsxs(f.Fragment,{children:[f.jsx(Me,{"aria-label":`Move item ${T+1} up`,icon:f.jsx(Z.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:y||T===0,onClick:()=>E(T,-1)}),f.jsx(Me,{"aria-label":`Move item ${T+1} down`,icon:f.jsx(Z.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:y||T===S.length-1,onClick:()=>E(T,1)})]}),M.present&&f.jsx(Me,{"aria-label":`Remove ${$t(M.label)}`,icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:y,onClick:()=>R?j(m.address,g.filter((N,$)=>$!==T)):j(M.address,void 0)})]},M.address)),(R||A)&&f.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[A&&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:y,onChange:M=>l(M.target.value)})]}),x.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(Pt,{"aria-label":"New value type",value:d,disabled:y,onValueChange:u,children:[x.map((M,T)=>f.jsx("option",{value:T,children:C(M)},T)),w&&f.jsx("option",{value:"file",children:"File"}),w&&f.jsx("option",{value:"files",children:"Files"})]})})]}),f.jsx("span",{style:{display:"flex",alignItems:"center",flexShrink:0,...A||x.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:f.jsx(Me,{"aria-label":R?"Add item":"Add property",icon:f.jsx(Z.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:y,onClick:O})})]}),h&&f.jsx("p",{role:"alert",children:h})]})}const Mt=_.createContext({callbacks:{}}),Hn=io.default.div`
|
|
58
|
+
`,Cd=j.forwardRef(function({style:r,...t},n){return f.jsx(aw,{...t,ref:n,style:{...r,backgroundImage:"none","--flow-range-track":(r==null?void 0:r.backgroundImage)??"none"}})});function ud({label:e,inputLabel:r,value:t,displayValue:n,min:o,max:i,step:s=5,onChange:a,onChangeEnd:c}){const l=j.useId(),{readOnly:d,themeColor:u}=Je(),{colorInactive:h}=at(),p=(t-o)/(i-o)*100,m=u.includes(".")?`var(--chakra-colors-${u.replace(".","-")})`:u;return f.jsxs("div",{style:{width:224,maxWidth:"calc(100vw - 64px)",padding:12},children:[f.jsxs("label",{htmlFor:l,style:{display:"flex",justifyContent:"space-between",fontSize:14,marginBottom:12},children:[e," ",f.jsx("span",{children:n})]}),f.jsx(Cd,{id:l,"aria-label":r,type:"range",min:o,max:i,step:s,value:t,disabled:d,style:{color:m,accentColor:m,backgroundImage:`linear-gradient(to right, currentColor ${p}%, var(--chakra-colors-${h.replace(".","-")}) ${p}%)`},onChange:y=>a(Number(y.target.value)),onPointerUp:c,onKeyUp:c,onBlur:c})]})}const Au={dot:{label:"Dots",icon:Z.PiDotsNine},grid:{label:"Grid",icon:Z.PiGridFour},steel:{label:"Steel",icon:Z.PiLineSegments},none:{label:"Solid",icon:Z.PiSquareFill},transparent:{label:"Transparent",icon:Z.PiSelection}};function tb(){const{spacing:e,setSpacing:r,edgeRadius:t,setEdgeRadius:n,backgroundVariant:o,setBackgroundVariant:i,callbacks:s,readOnly:a,config:c}=Je(),l=Au[o].icon;return f.jsxs(f.Fragment,{children:[f.jsx(vn,{}),f.jsx(Mt,{"aria-label":"Node spacing",title:`Spacing: ${Math.round(e*100)}%`,icon:f.jsx(Z.PiArrowsOutCardinal,{size:20}),style:{width:36},value:"spacing",disabled:a,onValueChange:()=>{},popupContent:f.jsx(ud,{label:"Spacing",inputLabel:"Node spacing percentage",min:c.nodeGridSpacing==="layout"?0:50,max:200,value:Math.round(e*100),displayValue:`${Math.round(e*100)}%`,onChange:d=>{var u;r(d/100),(u=s.onSpacingChange)==null||u.call(s,d/100)}}),children:f.jsx("option",{value:"spacing",children:"Spacing"})}),f.jsx(vn,{}),f.jsx(Mt,{"aria-label":"Edge radius",title:`Edge radius: ${t??"Default"}`,icon:f.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:"radius",disabled:a,onValueChange:()=>{},popupContent:f.jsx(ud,{label:"Edge radius",inputLabel:"Edge corner radius",min:0,max:500,value:t??500,displayValue:t??"Default",onChange:d=>{var u;n(d),(u=s.onEdgeRadiusChange)==null||u.call(s,d)}}),children:f.jsx("option",{value:"radius",children:"Edge radius"})}),f.jsx(vn,{}),f.jsxs(Mt,{"aria-label":"Background variant",title:`Background: ${Au[o].label}`,icon:f.jsx(l,{size:20,"data-background-icon":o}),style:{width:36},value:o,disabled:a,onValueChange:d=>{var u;i(d),(u=s.onBackgroundVariantChange)==null||u.call(s,d)},children:[f.jsx("option",{value:"dot",children:"Dots"}),f.jsx("option",{value:"grid",children:"Grid"}),f.jsx("option",{value:"steel",children:"Steel"}),f.jsx("option",{value:"none",children:"Solid"}),f.jsx("option",{value:"transparent",children:"Transparent"})]})]})}function rb(){var o;const{engineRef:e,nodeGridOptions:r,readOnly:t}=Je(),n=!!(r!=null&&r.fill);return f.jsx(Gr,{label:"Grid adjustment",hideLabel:!0,helper:n?"Grid adjustment":"Enable Collision and Fill to adjust the Grid",icon:f.jsx(Z.PiArrowsHorizontal,{size:20}),checked:n&&!!((o=r==null?void 0:r.adjustment)!=null&&o.enabled),disabled:!n,onChange:i=>{var s;t||!(r!=null&&r.fill)||(s=e.current)==null||s.setNodeGridMode(!0,{...r,adjustment:{...r.adjustment,enabled:i}})}})}function Fo(){const{engineRef:e,nodeGridOptions:r,lastNodeGridOptions:t,readOnly:n,themeColor:o,callbacks:i,config:s}=Je(),{colorText:a,colorInactive:c}=at(),l=r??t,d=typeof l.gaps=="object"?l.gaps.x:l.gaps??l.margin??15,u=Math.max(200,d),h=p=>{var m;return(m=e.current)==null?void 0:m.setNodeGridMode(!0,{...l,...p})};return f.jsxs(f.Fragment,{children:[s.bottomBarCollision!==!1&&f.jsx(Gr,{label:"Collision mode",hideLabel:!0,icon:f.jsx(Z.PiGridFour,{size:20}),checked:r!==null,onChange:p=>{var m,y;((m=i.onNodeGridModeRequest)==null?void 0:m.call(i,p,l))!==!0&&((y=e.current)==null||y.setNodeGridMode(p,l))}}),(r||s.bottomBarFill===!0)&&f.jsxs(V.HStack,{role:"group","aria-label":"Collision settings",gap:2,flexShrink:0,children:[r&&s.nodeGridSpacing!=="layout"&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{width:"96px",flexShrink:0,display:"flex",alignItems:"center",children:f.jsx(Cd,{type:"range","aria-label":"Collision gap",title:`Gap: ${d}`,min:0,max:u,step:5,value:d,disabled:n,style:{color:Me(o),backgroundImage:`linear-gradient(to right, currentColor ${d/u*100}%, ${Me(c)} ${d/u*100}%)`},onChange:p=>h({gaps:Number(p.target.value)})})}),f.jsx(V.Text,{fontSize:"xs",color:a,width:"28px",textAlign:"right",fontVariantNumeric:"tabular-nums",children:d})]}),s.bottomBarFill!==!1&&f.jsx(Gr,{label:"Fill",hideLabel:!0,helper:r?"Fill available canvas space":"Enable Collision mode to use Fill",icon:f.jsx(Z.PiArrowsOut,{size:18}),checked:!!r&&!!l.fill,disabled:!r,onChange:p=>{var m,y;!r&&((m=i.onNodeGridModeRequest)==null?void 0:m.call(i,!0,{...l,fill:p}))===!0||p&&((y=i.onNodeGridFillRequest)==null?void 0:y.call(i,{...l,fill:p}))===!0||h({fill:p})}}),r&&l.fill&&f.jsx(rb,{})]})]})}const xt=[];for(let e=0;e<256;++e)xt.push((e+256).toString(16).slice(1));function sw(e,r=0){return(xt[e[r+0]]+xt[e[r+1]]+xt[e[r+2]]+xt[e[r+3]]+"-"+xt[e[r+4]]+xt[e[r+5]]+"-"+xt[e[r+6]]+xt[e[r+7]]+"-"+xt[e[r+8]]+xt[e[r+9]]+"-"+xt[e[r+10]]+xt[e[r+11]]+xt[e[r+12]]+xt[e[r+13]]+xt[e[r+14]]+xt[e[r+15]]).toLowerCase()}let zo;const cw=new Uint8Array(16);function lw(){if(!zo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");zo=crypto.getRandomValues.bind(crypto)}return zo(cw)}const dw=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Pu={randomUUID:dw};function Sd(e,r,t){var o;if(Pu.randomUUID&&!e)return Pu.randomUUID();e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??lw();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,sw(n)}const co={label:"Untitled",description:"",isTask:!1,isLocked:!1},jd={id:null,type:"text",data:{...co,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"}}},Mu={id:null,type:"objectView",data:{...co,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},uw={id:null,type:"arrayView",data:{...co,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"}}},Iu={id:null,type:"workflowStep",data:{...co,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},It=e=>typeof e=="object",nb=e=>Array.isArray(e),fw=["order","position","selected","locked","grabbed","grabbable","scratch"],pr=e=>Object.entries(e).reduce((r,[t,n])=>(!It(n)&&!t.startsWith("$")&&(r[t]=n),r),{}),_d=(e,r)=>typeof e=="string"&&e.startsWith("$")?Bo(e,r):It(e)&&!nb(e)?Object.entries(e).reduce((t,[n,o])=>(typeof o=="string"&&o.startsWith("$")&&n==="..."?(delete t["..."],t[n]={...Bo(o,r),...e}):typeof o=="string"&&o.startsWith("$")?t[n]=Bo(o,r):t[n]=o,t),{}):e,gr=e=>Object.entries(e).reduce((r,[t,n])=>(It(n)&&t&&n&&!t.startsWith("$")&&(fw.includes(t)&&(t=t+"#"),r[t]=n),r),{}),_r=(e,r,{label:t,parent:n=void 0},o,i=null)=>(i!==null&&(It(i)||nb(i))&&(i=JSON.stringify(i,null,2)),{data:{parent:n,...e.data,id:r,text:t||"",label:t,code:i||null,type:e.type,description:o}}),dr=(e,r,t=null,n=null,o=null,i=!1,s=null)=>({data:{id:Sd(),source:o?r:e,target:o?e:r,label:n||"",isInverted:o,isEdgeAnimated:i,parent:s}}),yr=(e,r=[])=>{const t={},n={};let o=[];if(e)for(const[i,s]of Object.entries(e))i.startsWith("$")&&i!=="$"?t[i.slice(1)]=s:i!=="$"?n[i]=s:i==="$"&&(o=s);return{newConfig:t,updatedObject:n,arrayObject:o}},qr=(e,r)=>{let t=Mu;const{view:n,borderColor:o,borderRadius:i,bgColor:s,textColor:a,fontSize:c,stepType:l}=r;e=n||e,l?t={...Iu}:e==="object"?t=Mu:e==="text"?t=jd:e==="array"?t=uw:e==="workflowStep"&&(t={...Iu});const d=t.data.viewProps;return t.data.viewProps={...d,borderRadius:i||(l?15:53),bgColor:s,borderColor:o,textColor:a,fontSize:c},t.data.config=r,{config:t}},Rn=(e,r)=>(e=r.find(n=>n.data.id===e)?`${e}.#`:e,e),Bo=(e,{ids:r,jsnObjct:t})=>{if(typeof e=="string"&&(e!=null&&e.startsWith("$"))){const n=e.replace("$","").replace("*","");e==null||e.endsWith("*");const o=r.find(a=>a.split(".").slice(-1)[0]===n||n===a);if(!o)return e;const i=hw(o,t);return JSON.stringify(i).includes(e)?e:i||e}return e},hw=(e,r)=>{let t=e.split(".").splice(1);return t=t[t.length-1]==="#"||t[t.length-1].includes("{")?t.slice(0,-2):t,(i=>t.reduce((s,a)=>{a=a.replace("[","").replace("]","");const{arrayObject:c}=yr(s);return s=c.length?c:s,s[a]},i))(r)};function Fr(e,r="root",t=[]){try{const{arrayObject:n}=yr(e);n.length&&(e=n);const o=pr(e),i=gr(e);return It(e)?(tt(e)||tt(e)&&r==="root"||!tt(e)&&Object.keys(o).length||r==="root")&&t.push(r):t.push(r),Object.keys(i).length&&!tt(e)?xn({chldPth:null,itrblObjct:i,nodes:t,path:r}):tt(e)&&e.forEach((s,a)=>{const c=pr(s),l=gr(s),{newConfig:d,arrayObject:u}=yr(s);let h=`${r}.${a}`;It(s)?Object.keys(c).length?(Fr(c,h,t),Object.keys(l).length&&!tt(s)&&xn({chldPth:h,itrblObjct:l,nodes:t,path:r})):Object.keys(l).length&&!tt(s)?xn({chldPth:h,itrblObjct:l,nodes:t,path:r}):tt(s)&&ob({chldPth:h,item:s,nodes:t,path:r}):t.push(h)}),{nodes:t}}catch{return{nodes:t}}}const xn=({chldPth:e,itrblObjct:r,nodes:t,path:n})=>Object.entries(r).forEach(([o,i],s)=>{const a=pr(i),c=gr(i),{newConfig:l,arrayObject:d}=yr(i);d.length&&(i=d),n.split(".").slice(0,2).join(".");let u=e?`${e}.${o}`:`${n}.${o}`;if(It(i)&&!tt(i)){const h=Object.keys(a).length===0;if(h&&(qr("array",l),t.push(u)),Object.keys(a).length){const p=tt(i)?`${i.length||""}`:`{${Object.keys(i).length||""}}`;let m=u;h&&(m=`${u}.${p}`),Fr(i,m,t)}else Object.keys(c).length&&!tt(i)?xn({chldPth:u,itrblObjct:c,path:u,nodes:t}):Fr(i,u,t)}else tt(i)&&Fr(i,u,t)}),ob=({chldPth:e,item:r,nodes:t,path:n})=>r.forEach((o,i)=>{let s=`${e}.${i}`;const a=gr(o),c=pr(o);It(o)?!tt(o)&&Object.keys(c).length?Fr(o,s,t):Object.keys(a).length&&!tt(o)?xn({chldPth:s,itrblObjct:a,path:n,nodes:t}):tt(o)&&ob({chldPth:s,item:o,nodes:t,path:n}):t.push(s)}),wn=[];let Cn;function Rr(e,r="root",t=[],n=[],o="untitled",i={hideDefaultObject:!1,sprtObjctKy:!1,isCntr:!1},s={}){if(!e||typeof e!="object")return console.error("Invalid object passed",e),{nodes:t,edges:n};const a=e;if(r==="root"&&(wn.length=0),!Cn){const{nodes:d}=Fr(e);Cn={ids:d,jsnObjct:e}}let{hideDefaultObject:c,sprtObjctKy:l}=i;try{r=Rn(r,t);const{newConfig:d,arrayObject:u}=yr(e),h=Object.keys(s).length>0?s:d;u.length&&(e=u);const p=pr(e),m=gr(e),{label:y,collapsed:g,parent:v}=h;if(!It(e))t.push(_r(jd,r,{label:y||r,parent:v},e,a));else if(tt(e)||tt(e)&&r==="root"){const{config:b}=qr("array",h),x=tt(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,w=r==="root"?o:`${o} ${x}`;t.push(_r(b,r,{label:y||w,parent:v},e,tt(a)?{[o]:a}:a))}else if(!tt(e)&&Object.keys(p).length||r==="root"){const{config:b}=qr(null,h),x=tt(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,w=r.split("."),C=w[w.length-1];let S=isNaN(Number(C))?null:Number(C)+1;const _=isNaN(Number(C))?C:w[w.length-2]+" "+S,I=r==="root"?o:_;let E=!1;Number.isNaN(Number(o))||(E=!0);const O=e;if(y){const{config:A}=qr("object",h);t.push(_r(A,r,{label:y||`${y} ${x}`,parent:v},p,O))}else b.data.headerTitle=I,t.push(_r(b,r,{label:y,parent:v},p,O))}return g||(Object.keys(m).length&&!tt(e)?Sn({flowConfig:i,chldPth:null,edges:n,isInverted:null,itrblObjct:m,nodes:t,path:r,newConfig:h}):tt(e)&&e.forEach((b,x)=>{b=_d(b,Cn);const w=b,C=pr(b),S=gr(b),{newConfig:_,arrayObject:I}=yr(b);I.length&&(b=I);const{config:E}=qr(typeof b=="string"?"text":"array",_),{hideConfig:O,sourceLabel:A,label:R,isEdgeAnimated:P,parent:T}=_;c=c||O;const N=r==="root"&&i.isCntr,$=r.split(".").slice(0,2).join("."),M=wn.includes($),W=i.isCntr&&M||x%2===0&&N;let ae=`${r}.${x}`;ae=Rn(ae,t),W&&wn.push(ae),It(b)?Object.keys(C).length&&!tt(b)?(n.push(dr(r,ae,null,A,W,P)),Rr(b,ae,t,n,R||x,i,_)):Object.keys(S).length&&!tt(b)?Sn({flowConfig:i,chldPth:ae,isInverted:W,edges:n,itrblObjct:S,nodes:t,path:r,newConfig:_,forceIsInverted:!0}):tt(b)?ib({flowConfig:i,chldPth:ae,edges:n,isInverted:W,item:b,nodes:t,path:r}):It(b)&&Sn({flowConfig:i,chldPth:ae,isInverted:W,edges:n,itrblObjct:[b],nodes:t,path:r,newConfig:_}):(n.push(dr(r,ae,null,A,W,P)),t.push(_r(E,ae,{label:R||String(b),parent:T},b,w)))})),{nodes:t,edges:n}}catch{return{nodes:t,edges:n}}}const Sn=({chldPth:e,flowConfig:r,edges:t,itrblObjct:n,nodes:o,isInverted:i,path:s,newConfig:a,forceIsInverted:c=!1})=>{let{hideDefaultObject:l,sprtObjctKy:d}=r;return Object.entries(n).forEach(([u,h],p)=>{h=_d(h,Cn);const m=h,y=pr(h),g=gr(h),{newConfig:v,arrayObject:b}=yr(h);b.length&&(h=b);const{hideConfig:x,sourceLabel:w,label:C,content:S,target:_,targetLabel:I,collapsed:E,isEdgeAnimated:O,parent:A}=v;l=l||x;const R=s==="root"&&r.isCntr,P=s.split(".").slice(0,2).join("."),T=wn.includes(P);c||(i=r.isCntr&&T||p%2===0&&R);let N=e?`${e}.${u}`:`${s}.${u}`;if(N=Rn(N,o),i&&wn.push(N),_&&t.push(dr(N,_,null,I,i,O)),It(h)&&!tt(h)){t.push(dr(s,N,null,w,i,O));const $=d||Object.keys(y).length===0;if($){const M=S?"object":"array",{config:W}=qr(M,v);W.data.headerTitle=S?C:null,o.push(_r(W,N,{label:C||u,parent:A},h,m))}if(Object.keys(y).length&&!l){const M=tt(h)?` ${h.length||""}`:`{${Object.keys(h).length||""}}`;let W=N;$&&(W=`${N}.${M}`,W=Rn(W,o),t.push(dr(N,W,null,w,i,O))),Rr(h,W,o,t,C||u,r,v)}else Object.keys(g).length&&!tt(h)?Sn({chldPth:N,flowConfig:r,itrblObjct:g,path:N,edges:t,nodes:o,newConfig:v,isInverted:i}):Rr(h,N,o,t,u,r,v)}else tt(h)&&(t.push(dr(s,N,null,w,i,O)),Rr(h,N,o,t,u,r,v))})},ib=({flowConfig:e,chldPth:r,edges:t,isInverted:n,item:o,nodes:i,path:s})=>o.forEach((a,c)=>{let l=`${r}.${c}`;l=Rn(l,i);const d=a;a=_d(a,Cn);const u=gr(a),h=pr(a),{newConfig:p}=yr(a),{collapsed:m,label:y,parent:g,sourceLabel:v,isEdgeAnimated:b,content:x}=p;It(a)?!tt(a)&&Object.keys(h).length?(t.push(dr(s,l,null,v,n,b)),Rr(a,l,i,t,c,e,p)):Object.keys(u).length&&!tt(a)&&!m?Sn({chldPth:l,flowConfig:e,itrblObjct:u,path:s,edges:t,nodes:i,isInverted:n,newConfig:p}):tt(a)&&ib({flowConfig:e,chldPth:l,edges:t,isInverted:n,item:a,nodes:i,path:s}):(t.push(dr(s,l,null,v,n,b)),i.push(_r(jd,l,{label:y||String(a),parent:g},a,d)))});function pw(e,r){const t=new Set,n=(l,d="root")=>{if(!(!l||typeof l!="object")){l.$view==="parent"&&t.add(d),typeof l.$parent=="string"&&t.add(l.$parent);for(const[u,h]of Object.entries(l))(!u.startsWith("$")||u==="$")&&n(h,u==="$"?d:`${d}.${u}`)}};if(n(e),!t.size)return r;const o=new Map(r.nodes.map(l=>[l.data.id,l])),i=l=>{var p,m;let d=l.data.id;const u=new Set([l.data.id]);let h=l.data.parent;for(;h&&!u.has(h);)t.has(h)&&o.has(h)&&((p=Fe(e,h))!=null&&p.$collapsed)&&(d=h),u.add(h),h=(m=o.get(h))==null?void 0:m.data.parent;return d},s=new Map(r.nodes.map(l=>[l.data.id,i(l)])),a=r.nodes.filter(l=>s.get(l.data.id)===l.data.id).map(l=>{if(!t.has(l.data.id))return l;const d=Fe(e,l.data.id),u=!!(d!=null&&d.$collapsed);return{...l,data:{...l.data,...u?{type:"arrayView"}:{},config:{...l.data.config,parentContainer:!0,collapsed:u,...u?{labelBelow:!0,icon:(d==null?void 0:d.$icon)||"PiStack"}:{}}}}}),c=new Set(a.map(l=>l.data.id));return{nodes:a,edges:r.edges.flatMap(l=>{const d=s.get(l.data.source),u=s.get(l.data.target);return!d||!u||!c.has(d)||!c.has(u)?[]:d===l.data.source&&u===l.data.target?[l]:d===u?[]:[{...l,data:{...l.data,source:d,target:u,collapsedEndpoints:l.data.collapsedEndpoints??{source:l.data.source,target:l.data.target}}}]})}}function lo(e){if(!Array.isArray(e==null?void 0:e.$connections))return[];const r=new Map;return e.$connections.flatMap((t,n)=>{if(!t||typeof t!="object")return[];const o=t;if(typeof o.target!="string"||!/^root(?:\.|$)/.test(o.target))return[];if(o.sourceProperty!==void 0&&typeof o.sourceProperty!="string")return[];if(o.targetProperty!==void 0&&typeof o.targetProperty!="string")return[];const i=typeof o.id=="string"&&o.id?JSON.stringify(["id",o.id]):JSON.stringify(["ports",o.target,o.sourceProperty??null,o.targetProperty??null]),s=r.get(i)??0;return r.set(i,s+1),[{value:o,key:`${i}#${s}`,index:n}]})}function ab(e,r,t){const n=lo(e).find(c=>c.key===r);if(!n)return e;const o=t(n.value),i=e.$connections.flatMap((c,l)=>l===n.index?o?[o]:[]:[c]);if(i.length)return{...e,$connections:i};const{$connections:s,...a}=e;return a}function gw(e){const r=[],t=(n,o)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((i,s)=>t(i,`${o}.${s}`));for(const i of lo(n)){const s=i.value;r.push({data:{id:`connection:${JSON.stringify([o,i.key])}`,source:o,target:s.target,type:typeof s.type=="string"?s.type:void 0,sourceProperty:s.sourceProperty,targetProperty:s.targetProperty,icon:typeof s.icon=="string"?s.icon:void 0,label:typeof s.label=="string"?s.label:void 0,color:typeof s.color=="string"?s.color:void 0,isEdgeDashed:s.style==="dashed",isEdgeAnimated:s.style==="animated",...["dashed","traveling"].includes(s.animationVariant)?{edgeAnimationVariant:s.animationVariant}:{},connection:{address:o,key:i.key}}})}return Object.fromEntries(Object.entries(n).filter(([i])=>i!=="$connections").map(([i,s])=>[i,i==="$"?t(s,o):i.startsWith("$")?s:t(s,`${o}.${i}`)]))};return{json:t(e,"root"),edges:r}}const zr="root",Tu=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Dt(e){const r=e.split(".");for(r[0]===zr&&r.shift();r.length&&Tu(r[r.length-1]);)r.pop();return r.filter(t=>!Tu(t))}function uo(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function Fe(e,r){return Dt(r).reduce((t,n)=>{var o;if(t!=null)return(o=uo(t))==null?void 0:o[n]},e)}function yw(e){return Array.isArray(e)?[...e]:{...e}}function jt(e,r,t){const n=Dt(r),o=(i,s)=>{if(s===n.length)return t(i);const a=n[s],c=uo(i);if(c==null||typeof c!="object")return i;const l=o(c[a],s+1);if(Object.is(l,c[a]))return i;const d=yw(c);return d[a]=l,c!==i?{...i,$:d}:d};return o(e,0)}function tr(e,r,t){const n=t===""&&r!=="$content"||t===void 0||t===null;if(Array.isArray(e))return n?e:{[r]:t,$:[...e]};const o=e!=null&&typeof e=="object"?{...e}:{};return e!=null&&typeof e!="object"&&(o.$label=String(e)),n?delete o[r]:o[r]=t,o}function wt(e,r,t,n){return jt(e,r,o=>t==="$label"&&typeof o=="string"&&typeof n=="string"&&n!==""?n:tr(o,t,n))}const Ed=(e,r,t)=>wt(e,r,"$collapsed",t);function Er(e){if(e.connection)return{address:e.connection.address,kind:"connection"};const r=e.collapsedEndpoints??e,t=e.isInverted?r.target:r.source,n=e.isInverted?r.source:r.target,o=Dt(t).join("."),i=Dt(n).join(".");return i.startsWith(o?o+".":"")&&i!==o?{address:n,kind:"hierarchy"}:o.startsWith(i?i+".":"")&&o!==i?{address:t,kind:"hierarchy"}:{address:t,kind:"target"}}function lr(e,r,t,n){if(r.connection){const a=r.connection;return jt(e,a.address,c=>ab(c,a.key,l=>{if(t==="$edgeIcon")return tr(l,"icon",n);if(t==="$edgeType")return tr(l,"type",n);if(t==="$edgeAnimationVariant")return tr(l,"animationVariant",n);if(t==="$sourceLabel"||t==="$edgeColor")return tr(l,t==="$sourceLabel"?"label":"color",n);const d=t==="$isEdgeAnimated"?"animated":"dashed";return n?{...l,style:d}:l.style===d?tr(l,"style",void 0):l}))}const{address:o,kind:i}=Er(r),s=i==="target"&&t==="$sourceLabel"?"$targetLabel":i==="target"&&t==="$edgeType"?"$targetEdgeType":i==="target"&&t==="$edgeIcon"?"$targetIcon":i==="target"&&t==="$edgeAnimationVariant"?"$targetAnimationVariant":t;return jt(e,o,a=>tr(a,s,n))}const sb=(e,r,t)=>lr(lr(e,r,"$isEdgeAnimated",t==="animated"||void 0),r,"$isEdgeDashed",t==="dashed"||void 0);function kd(e,r,t,n){let o=n||"";const i=jt(e,r,a=>{const c=uo(a);if(Array.isArray(c)){o=String(c.length);const d=[...c,t];return c===a?d:{...a,$:d}}const l=a!=null&&typeof a=="object"&&!Array.isArray(a)?{...a}:a!=null&&typeof a!="object"?{$label:String(a)}:{};if(!o){let d=1;for(;`node_${d}`in l;)d++;o=`node_${d}`}return l[o]=t,l}),s=Dt(r);return{json:i,address:[zr,...s,o].join(".")}}function cb(e,r){const t=Dt(r);if(!t.length)return e;const n=t[t.length-1],o=[zr,...t.slice(0,-1)].join(".");return jt(e,o,i=>{const s=uo(i);if(s==null||typeof s!="object"||!Object.prototype.hasOwnProperty.call(s,n))return i;if(Array.isArray(s)){const l=s.filter((d,u)=>String(u)!==n);return s===i?l:{...i,$:l}}const{[n]:a,...c}=i;return c})}const lb=(e,r,t,n)=>wt(n?jt(e,r,o=>tr(o,"$targetLabel",n)):e,r,"$target",t);function Rd(e,r,t){const n=Fe(e,r);return lo(n).some(({value:i})=>i.target===t.target&&i.sourceProperty===t.sourceProperty&&i.targetProperty===t.targetProperty)?e:jt(e,r,i=>tr(i,"$connections",[...Array.isArray(i==null?void 0:i.$connections)?i.$connections:[],{...t,id:t.id||Sd()}]))}function db(e,r){if(r.connection){const i=r.connection;return lo(Fe(e,i.address)).some(s=>s.key===i.key)?{json:jt(e,i.address,s=>ab(s,i.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:t,kind:n}=Er(r);return n==="hierarchy"?Fe(e,t)===void 0?{json:e,removed:!1}:{json:jt(e,t,i=>({...i,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:jt(e,t,i=>{const{$target:s,$targetLabel:a,...c}=i||{};return c}),removed:!0}}function fd(e,r={}){var b;const t=gw(e),{nodes:n,edges:o}=Rr(t.json,zr,[],[],r.title||"untitled",{hideDefaultObject:!!r.hideDefaultObject,sprtObjctKy:!!r.separateObjectKeys,isCntr:!!r.isCenter}),i=new Set(n.map(x=>x.data.id)),s=new Map;for(const x of n){const w=x.data.id;if(!w.endsWith(".0")||Fe(e,w)!==void 0)continue;const C=w.slice(0,-2),S=Fe(e,C);!i.has(C)&&S&&typeof S=="object"&&!Array.isArray(S)&&typeof S.$label=="string"&&Object.keys(S).every(_=>_.startsWith("$")&&_!=="$")&&s.set(w,C)}const a=x=>s.get(x)??x,c=new Set(n.flatMap(x=>x.data.parent?[a(x.data.parent)]:[])),l=new Map;if(r.isCenter){const x=new Map;for(const{data:w}of o){const C=Er(w);if(C.kind==="hierarchy")l.set(a(C.address),!!w.isInverted);else if(!Array.isArray(e)&&e.$hideRoot===!0){const S=a(w.isInverted?w.source:w.target);if(Dt(S).length!==1)continue;const _=!!w.isInverted;x.set(S,x.has(S)&&x.get(S)!==_?null:_)}}for(const[w]of l){const C=`${zr}.${Dt(w)[0]}`,S=x.get(C);typeof S=="boolean"&&l.set(w,S)}}const d=n.map(x=>{var E;const w=a(x.data.id),C=Fe(e,w),S={...x.data,id:w};l.has(w)&&(S.config={...S.config,isInverted:l.get(w)});const _=C&&typeof C=="object"&&!Array.isArray(C)&&"$"in C?C.$:C;if((Array.isArray(_)?_.length>0:_&&typeof _=="object"&&Object.keys(_).some(O=>!O.startsWith("$")))&&(S.config={...S.config,collapsed:!!C.$collapsed}),c.has(w)||(S.viewProps={...S.viewProps},delete S.viewProps.borderWidth),!C||typeof C!="object"||Array.isArray(C))return{data:S};if(C.$view==="parent"&&(S.type="objectView",S.config={...S.config,typeView:"parent",parentContainer:!0,collapsed:!!C.$collapsed}),C.$view==="grid"){S.type="grid";const O=C.$gridSize;if(O!==void 0&&(!O||![O.width,O.height].every(A=>Number.isFinite(A)&&A>0&&A<=16384)))throw new Error("Invalid grid frame size.");S.config={...S.config,typeView:"grid",documentId:C.$document,gridSize:O},S.viewProps={...S.viewProps,bgColor:C.$bgColor??"transparent",borderRadius:C.$borderRadius??0,borderWidth:C.$borderWidth??0}}if(C.$form&&typeof C.$form=="object"&&(S.config={...S.config,form:C.$form},S.type="objectView"),Array.isArray(C.$ports)){const O=C.$ports.filter(A=>A&&typeof A.id=="string"&&["source","target"].includes(A.role)&&["top","right","bottom","left"].includes(A.side));S.config={...S.config,ports:O}}if(S.parent&&(S.parent=a(S.parent)),typeof C.$label=="string"&&(S.label=C.$label,S.headerTitle=C.$label),typeof C.$subtitle=="string"&&(S.config={...S.config,subtitle:C.$subtitle}),typeof C.$outline=="boolean"&&(S.viewProps={...S.viewProps,outline:C.$outline}),["solid","dashed","dotted","double"].includes(C.$borderStyle)&&(S.viewProps={...S.viewProps,borderStyle:C.$borderStyle}),Number.isFinite(C.$borderWidth)&&C.$borderWidth>=0&&(S.viewProps={...S.viewProps,borderWidth:C.$borderWidth}),Number.isFinite(C.$borderRadius)&&C.$borderRadius>=0&&(S.viewProps={...S.viewProps,borderRadius:C.$borderRadius}),typeof C.$isNodeAnimated=="boolean"&&(S.isNodeAnimated=C.$isNodeAnimated),["traveling","pulse"].includes(C.$nodeAnimationVariant)&&(S.nodeAnimationVariant=C.$nodeAnimationVariant),typeof C.$content=="string"||C.$contentFormat==="jsx"&&Array.isArray(C.$content)){S.config={...S.config,content:C.$content};const O=C.$contentFormat??"markdown";if(!["markdown","html","jsx"].includes(O))throw new Error("Invalid content format: expected markdown, html, or jsx.");S.config.contentFormat=O,C.$view||(S.type="objectView")}return(((E=S.config)==null?void 0:E.collapsed)!==void 0||C.$collapsed!==void 0||C.$icon!==void 0)&&(S.config={...S.config||{}},(C.$collapsed!==void 0||S.config.collapsed!==void 0)&&(S.config.collapsed=!!C.$collapsed),C.$icon!==void 0&&(S.config.icon=C.$icon)),{data:S}}),u=new Map,h=o.map(x=>{let w=a(x.data.source),C=a(x.data.target),S=x.data.isInverted;const _=Er(x.data),I=l.get(a(_.address));_.kind==="hierarchy"&&I!==void 0&&I!==!!S&&([w,C]=[C,w],S=I);const E=`${w}->${C}`,O=u.get(E)??0;u.set(E,O+1);const A={...x.data,id:O?`${E}#${O}`:E,source:w,target:C,isInverted:S},R=Er(A),P=Fe(e,R.address);if(P&&typeof P=="object"){const T=P[R.kind==="target"?"$targetEdgeType":"$edgeType"];typeof T=="string"&&(A.type=T);const N=P[R.kind==="target"?"$targetIcon":"$edgeIcon"];typeof N=="string"&&(A.icon=N),P.$isEdgeAnimated!==void 0&&(A.isEdgeAnimated=!!P.$isEdgeAnimated);const $=P[R.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes($)&&(A.edgeAnimationVariant=$),P.$isEdgeDashed!==void 0&&(A.isEdgeDashed=!!P.$isEdgeDashed),P.$edgeColor&&(A.color=P.$edgeColor)}return{data:A}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const x=d.findIndex(w=>w.data.id===zr);x!==-1&&d.splice(x,1)}const p=new Set(d.map(x=>x.data.id));for(let x=h.length-1;x>=0;x--){const w=h[x].data,C=Er(w);(!p.has(w.source)||!p.has(w.target)||C.kind==="hierarchy"&&((b=Fe(e,C.address))==null?void 0:b.$hideParentEdge)===!0)&&h.splice(x,1)}h.push(...t.edges.filter(x=>p.has(x.data.source)&&p.has(x.data.target)));const m=pw(e,{nodes:d,edges:h}),y=m.nodes.filter(x=>{var w;return(w=x.data.config)==null?void 0:w.collapsed}).map(x=>Dt(x.data.id));if(!y.length)return m;const g=m.nodes.filter(x=>{const w=Dt(x.data.id);return!y.some(C=>C.length<w.length&&C.every((S,_)=>S===w[_]))}),v=new Set(g.map(x=>x.data.id));return{nodes:g,edges:m.edges.filter(x=>v.has(x.data.source)&&v.has(x.data.target))}}function mw(e,r){const t=new Set(e.filter(c=>{var l,d;return(d=(l=c.data)==null?void 0:l.config)==null?void 0:d.collapsed}).map(c=>c.data.id));if(!t.size)return{nodes:e,edges:r};const n=new Map(e.map(c=>[c.data.id,c])),o=new Set(e.map(c=>c.data.parent).filter(Boolean)),i=new Map(e.map(c=>{var h;let l=c.data.id,d=c.data.parent;const u=new Set([l]);for(;d&&!u.has(d);)t.has(d)&&(l=d),u.add(d),d=(h=n.get(d))==null?void 0:h.data.parent;return[c.data.id,l]})),s=new Map;for(const c of r){const l=c.data.isInverted?c.data.target:c.data.source,d=c.data.isInverted?c.data.source:c.data.target;(s.get(l)??s.set(l,[]).get(l)).push(d)}const a=new Set(e.filter(c=>i.get(c.data.id)!==c.data.id).map(c=>c.data.id));for(const c of t){if(o.has(c))continue;const l=[...s.get(c)||[]];for(;l.length;){const d=l.pop();t.has(d)||a.has(d)||(a.add(d),l.push(...s.get(d)||[]))}}return{nodes:e.filter(c=>!a.has(c.data.id)).map(c=>{var l;return t.has(c.data.id)&&o.has(c.data.id)?{...c,data:{...c.data,type:"arrayView",label:c.data.label??c.data.headerTitle,config:{...c.data.config,parentContainer:!0,labelBelow:!0,icon:((l=c.data.config)==null?void 0:l.icon)||"PiStack"}}}:c}),edges:r.flatMap(c=>{const l=i.get(c.data.source)??c.data.source,d=i.get(c.data.target)??c.data.target;return a.has(l)||a.has(d)?[]:l===c.data.source&&d===c.data.target?[c]:l===d?[]:[{...c,data:{...c.data,source:l,target:d,collapsedEndpoints:c.data.collapsedEndpoints??{source:c.data.source,target:c.data.target}}}]})}}function Ad(e,r){const t=JSON.parse(e);let n=512;const o=(s,a=[])=>{if(--n<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(!s||typeof s!="object"||Array.isArray(s))throw new Error("Expected a JSON Schema object.");const c=new Set(["$schema","$id","$defs","definitions","$ref","title","description","default","examples","type","properties","required","items","enum","const","anyOf","additionalProperties"]);for(const d of Object.keys(s))if(!c.has(d))throw new Error(`Unsupported JSON Schema keyword: ${d}`);const l=["$schema","$id","$defs","definitions","title","description","default","examples"];if(s.$ref){if(Object.keys(s).some(u=>!["$ref","title","description"].includes(u)))throw new Error("Use $ref without sibling constraints.");if(typeof s.$ref!="string"||!s.$ref.startsWith("#/")||a.includes(s.$ref))throw new Error("Only nonrecursive local $ref references are supported.");let d=t;for(const u of s.$ref.slice(2).split("/")){const h=u.replace(/~1/g,"/").replace(/~0/g,"~");if(!d||!Object.prototype.hasOwnProperty.call(d,h))throw new Error(`Unresolved reference: ${s.$ref}`);d=d[h]}return o(d,[...a,s.$ref])}if(s.anyOf){if(!Array.isArray(s.anyOf)||!s.anyOf.length||Object.keys(s).some(d=>d!=="anyOf"&&!l.includes(d)))throw new Error("Use a nonempty anyOf without sibling type constraints.");return{kind:"union",types:s.anyOf.map(d=>o(d,a))}}if(Object.prototype.hasOwnProperty.call(s,"const")||s.enum){if(Object.keys(s).some(h=>![...l,"const","enum","type"].includes(h))||s.enum&&Object.prototype.hasOwnProperty.call(s,"const"))throw new Error("Use enum or const without sibling constraints other than type.");const d=Object.prototype.hasOwnProperty.call(s,"const")?[s.const]:s.enum;if(!Array.isArray(d)||!d.length)throw new Error("Expected a nonempty enum.");return{kind:"union",types:d.map(h=>{if(h!==null&&!["string","number","boolean"].includes(typeof h))throw new Error("Only primitive literals are supported.");const p=h===null?"null":typeof h;if(s.type&&!(Array.isArray(s.type)?s.type:[s.type]).some(m=>m===p||m==="integer"&&Number.isInteger(h)))throw new Error("Literal does not match its declared type.");return{kind:"literal",value:h}})}}if(Array.isArray(s.type)){if(!s.type.length||s.type.some(d=>typeof d!="string"))throw new Error("Expected a nonempty list of primitive types.");if(Object.keys(s).some(d=>d!=="type"&&!l.includes(d)))throw new Error("Use anyOf for unions with object or array constraints.");return{kind:"union",types:s.type.map(d=>o({type:d},a))}}if((s.properties||s.required||s.additionalProperties!==void 0)&&s.type!=="object"&&s.type!==void 0)throw new Error("Object constraints require an object type.");if(s.items&&s.type!=="array")throw new Error("items requires an array type.");if(s.type==="object"||s.properties){if(s.additionalProperties!==void 0&&s.additionalProperties!==!0)throw new Error("Closed objects and typed additionalProperties are not supported.");if(!s.properties||typeof s.properties!="object"||Array.isArray(s.properties))throw new Error("Object schemas must declare properties.");if(s.required!==void 0&&(!Array.isArray(s.required)||s.required.some(u=>typeof u!="string"||!Object.prototype.hasOwnProperty.call(s.properties,u))))throw new Error("required must list declared property names.");return{kind:"object",properties:Object.fromEntries(Object.entries(s.properties).map(([u,h])=>[u,{type:o(h,a),optional:!(s.required??[]).includes(u)}]))}}if(s.type==="array")return{kind:"array",items:o(s.items,a)};if(["string","number","integer","boolean","null"].includes(s.type))return{kind:s.type};throw new Error("Every property must declare a supported type.")},i=o(t);if(i.kind!=="object")throw new Error("The root schema must be an object keyed by node ID.");if(Object.values(i.properties).some(s=>s.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:r,nodes:i.properties}}async function Pd(e,r,t,n={}){var m;let o=512;const i=await import("typescript"),s=i.createSourceFile(r,e,i.ScriptTarget.Latest,!0,i.ScriptKind.TS),a=s.parseDiagnostics;if(a!=null&&a.length)throw new Error("Invalid TypeScript syntax.");const c=new Map;for(const y of s.statements){if(!i.isInterfaceDeclaration(y)&&!i.isTypeAliasDeclaration(y))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((m=y.typeParameters)!=null&&m.length||c.has(y.name.text))throw new Error("Generics and duplicate declarations are not supported.");c.set(y.name.text,y)}const l=(y,g)=>{var C;const v={},b=y.find(S=>i.isIndexSignatureDeclaration(S));let x;if(b&&n.allowJson&&i.isIndexSignatureDeclaration(b)){if(y.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.");x=u(b.type,g)}return{kind:"object",properties:Object.fromEntries(y.filter(S=>S!==b||!x).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 _=u(S.type,g),I=n.allowJson?i.getJSDocTags(S).filter(E=>E.tagName.text==="port"):[];if(I.length>1)throw new Error(`Duplicate port declaration: ${S.name.text}`);if(I.length){const[E,O,A]=String(I[0].comment??"").trim().split(/\s+/);if(E!=="config"||!O||A||!c.has(O))throw new Error(`Config port ${S.name.text} requires @port config ResourceType`);const R=_.kind==="array";if((_.kind==="array"?_.items.kind:_.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:O,multiple:R}}return[S.name.text,{type:_,optional:!!S.questionToken}]})),...x?{additionalProperties:x}:{},...Object.keys(v).length?{ports:v}:{}}},d=(y,g)=>{var C;if(g.includes(y))throw new Error("Recursive types are not supported.");const v=c.get(y);if(!v)throw new Error(`Unknown type: ${y}`);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=l(v.members,[...g,y])}else b=u(v.type,[...g,y]);const x=n.allowJson?i.getJSDocTags(v).filter(S=>S.tagName.text==="port"):[];if(!x.length)return b;if(b.kind!=="object")throw new Error("Node ports require an object interface");const w={...b.ports};for(const S of x){const[_,I,...E]=String(S.comment??"").trim().split(/\s+/);if(!["input","output","error"].includes(_)||!/^[A-Za-z][\w-]*$/.test(I??""))throw new Error("Node ports require @port input|output|error Name");const O=E.length?JSON.parse(E.join(" ")):void 0;if(O!==void 0&&typeof O!="string")throw new Error("Node port labels must be JSON strings");if(Object.prototype.hasOwnProperty.call(w,I))throw new Error(`Duplicate port declaration: ${I}`);w[I]={kind:_,...typeof O=="string"?{label:O}:{}}}return{...b,ports:w}},u=(y,g)=>{var v,b,x;if(--o<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(y.kind===i.SyntaxKind.StringKeyword)return{kind:"string"};if(y.kind===i.SyntaxKind.NumberKeyword)return{kind:"number"};if(y.kind===i.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[i.SyntaxKind.AnyKeyword,i.SyntaxKind.UnknownKeyword].includes(y.kind))return{kind:"json"};if(i.isParenthesizedTypeNode(y))return u(y.type,g);if(i.isUnionTypeNode(y))return{kind:"union",types:y.types.map(w=>u(w,g))};if(i.isArrayTypeNode(y))return{kind:"array",items:u(y.elementType,g)};if(i.isTypeLiteralNode(y))return l(y.members,g);if(i.isLiteralTypeNode(y)){const w=y.literal;if(i.isStringLiteral(w))return{kind:"literal",value:w.text};if(i.isNumericLiteral(w))return{kind:"literal",value:Number(w.text)};if(w.kind===i.SyntaxKind.NullKeyword)return{kind:"null"};if(w.kind===i.SyntaxKind.TrueKeyword||w.kind===i.SyntaxKind.FalseKeyword)return{kind:"literal",value:w.kind===i.SyntaxKind.TrueKeyword}}if(i.isTypeReferenceNode(y)&&i.isIdentifier(y.typeName)){if(n.allowJson&&y.typeName.text==="Record"&&!c.has("Record")&&((v=y.typeArguments)==null?void 0:v.length)===2&&y.typeArguments[0].kind===i.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:u(y.typeArguments[1],g)};if(y.typeName.text==="Array"&&((b=y.typeArguments)==null?void 0:b.length)===1)return{kind:"array",items:u(y.typeArguments[0],g)};if(!((x=y.typeArguments)!=null&&x.length))return d(y.typeName.text,g)}throw new Error(`Unsupported TypeScript type: ${y.getText(s)}`)},h=t??(c.has("Graph")?"Graph":c.size===1?[...c.keys()][0]:void 0);if(!h)throw new Error("Declare an interface Graph keyed by node ID.");const p=d(h,[]);if(p.kind!=="object")throw new Error("Graph must be an object keyed by node ID.");return p}async function ub(e,r){const t=await Pd(e,r);if(Object.values(t.properties).some(n=>n.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:r,nodes:t.properties}}function hn(e,r){if(e.kind==="json"||r.kind==="json"||e.kind==="object"&&e.additionalProperties||r.kind==="object"&&r.additionalProperties)return!1;if(e.kind==="union")return e.types.every(t=>hn(t,r));if(r.kind==="union")return r.types.some(t=>hn(e,t));if(e.kind==="literal"){if(r.kind==="literal")return e.value===r.value;const t=e.value===null?"null":typeof e.value;return r.kind===t||r.kind==="integer"&&typeof e.value=="number"&&Number.isInteger(e.value)}return e.kind==="integer"&&r.kind==="number"?!0:e.kind==="array"&&r.kind==="array"?hn(e.items,r.items):e.kind==="object"&&r.kind==="object"?Object.entries(r.properties).every(([t,n])=>{const o=Object.prototype.hasOwnProperty.call(e.properties,t)?e.properties[t]:void 0;return o?(n.optional||!o.optional)&&hn(o.type,n.type):n.optional}):e.kind===r.kind}function Md(e,r){if(!r.sourceProperty&&!r.targetProperty)return;const t=(s,a)=>{var d;const c=Object.prototype.hasOwnProperty.call(e.nodes,s)?s:s.replace(/^root\./,""),l=Object.prototype.hasOwnProperty.call(e.nodes,c)?(d=e.nodes[c])==null?void 0:d.type:void 0;return a&&(l==null?void 0:l.kind)==="object"&&Object.prototype.hasOwnProperty.call(l.properties,a)?l.properties[a]:void 0},n=t(r.source,r.sourceProperty),o=t(r.target,r.targetProperty);if(!n||!o)return"Unverified: source or target property is missing from the interface.";const i=s=>s.kind==="json"||s.kind==="object"&&(!!s.additionalProperties||Object.values(s.properties).some(a=>i(a.type)))||s.kind==="array"&&i(s.items)||s.kind==="union"&&s.types.some(i);if(i(n.type)||i(o.type))return"Unverified: arbitrary JSON or dictionary fields require runtime validation.";if(n.optional&&!o.optional)return"Optional source cannot supply a required target property.";if(!hn(n.type,o.type))return`Incompatible property types: ${r.sourceProperty} -> ${r.targetProperty}.`}async function fb(e){if(e.size>256*1024)throw new Error("Interface must be 256 KB or smaller.");const r=await e.text();if(/\.json$/i.test(e.name))return Ad(r,e.name);if(/\.ts$/i.test(e.name))return ub(r,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Ou=new WeakMap;function Ur(e){if(!e||typeof e!="object")return e;const r=Ou.get(e);if(r)return r;const t=()=>{throw new Error("Form callback data is read-only. Return edits instead.")},n=new Proxy(Array.isArray(e)?[]:{},{get:(o,i)=>Ur(Reflect.get(e,i)),has:(o,i)=>Reflect.has(e,i),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(o,i)=>{const s=Reflect.getOwnPropertyDescriptor(e,i);return s&&{...s,value:Ur(Reflect.get(e,i)),configurable:i!=="length"||!Array.isArray(e)}},set:t,deleteProperty:t,defineProperty:t,setPrototypeOf:t,preventExtensions:t});return Ou.set(e,n),n}function Yr(e,r,t){var o;const n=r.split(".");for(let i=n.length;i>0;i--){const s=n.slice(0,i).join("."),a=(o=Fe(e,s))==null?void 0:o.$form;if(!(a!=null&&a.$type))continue;let c=Object.prototype.hasOwnProperty.call(t,a.$type)?t[a.$type]:void 0;for(const u of n.slice(i))(c==null?void 0:c.kind)==="array"&&/^\d+$/.test(u)?c=c.items:(c==null?void 0:c.kind)==="object"?c=Object.prototype.hasOwnProperty.call(c.properties,u)?c.properties[u].type:void 0:c=void 0;if((c==null?void 0:c.kind)!=="object")return;const l=n.slice(i).join("."),d=Object.fromEntries(Object.entries(a.$fields??{}).filter(([u])=>!l||u.startsWith(`${l}.`)).map(([u,h])=>[l?u.slice(l.length+1):u,h]));return{type:c,fields:d,binding:a}}}async function Id(e,r){if(e.size>256*1024)throw new Error("Form schema exceeds 256 KB.");const t=await e.text();if(e.name.endsWith(".ts")){if(!r.length||r.length>32)throw new Error("Choose between 1 and 32 form interface names.");const o=[],i=new Set(r);for(const s of i){if(i.size>32)throw new Error("Choose between 1 and 32 form interface names.");const a=await Pd(t,e.name,s,{allowJson:!0});o.push([s,a]);for(const c of Object.values(a.ports??{}))c.resourceType&&i.add(c.resourceType)}return Object.fromEntries(o)}if(!e.name.endsWith(".json"))throw new Error("Choose a .ts interface or .json schema file.");const n=Ad(t,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([o,i])=>[o,i.type]))}function fo(e,r){return!e||("$in"in e?e.$in.includes(Fe(r,e.$address)):Fe(r,e.$address)===e.$equals)}function jn(e){const r=e.kind==="array"?e.items:e,t=r.kind==="union"?r.types:[r];if(t.every(n=>n.kind==="literal"))return t.map(n=>({label:String(n.value),value:n.value}))}function Vt(e,r,t){if(r===void 0||r==="")return t?"Required":void 0;if(e.kind==="json"){const n=new Set,o=i=>{if(i===null||typeof i=="string"||typeof i=="boolean")return!0;if(typeof i=="number")return Number.isFinite(i);if(!i||typeof i!="object"||n.has(i)||!Array.isArray(i)&&![Object.prototype,null].includes(Object.getPrototypeOf(i)))return!1;n.add(i);const s=Object.values(i).every(o);return n.delete(i),s};return o(r)?void 0:"Expected a JSON value"}if(e.kind==="union")return e.types.some(n=>!Vt(n,r,!0))?void 0:"Choose a valid value";if(e.kind==="literal")return r===e.value?void 0:"Choose a valid value";if(e.kind==="array")return Array.isArray(r)&&r.every(n=>!Vt(e.items,n,!0))?void 0:"Invalid list value";if(e.kind==="object")return!r||typeof r!="object"||Array.isArray(r)?"Expected an object":e.additionalProperties&&Object.entries(r).some(([n,o])=>!Object.prototype.hasOwnProperty.call(e.properties,n)&&Vt(e.additionalProperties,o,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,o])=>Vt(o.type,r[n],!o.optional))?"Invalid object fields":void 0;if(e.kind==="null")return r===null?void 0:"Expected null";if(e.kind==="integer")return Number.isInteger(r)?void 0:"Expected a whole number";if(typeof r!==e.kind||typeof r=="number"&&!Number.isFinite(r))return`Expected ${e.kind}`}function Nu(e,r){const t=r.address.split(".");if(t.shift()!=="root"||!t.length||t.some(a=>!a||["__proto__","prototype","constructor","#"].includes(a)))throw new Error("Invalid form field address.");const n=t.pop(),o=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(t.some(a=>a.startsWith("$"))||n.startsWith("$")&&!o)throw new Error("Unsupported form metadata address.");const i=["root",...t].join("."),s=Fe(e,i);if(!s||typeof s!="object")throw new Error(`Missing form parent: ${i}`);if(o){if(r.op==="set"&&typeof r.value!="string")throw new Error("Node colors must be strings.");return wt(e,i,n,r.op==="remove"?void 0:r.value)}return jt(e,i,a=>{const c=Array.isArray(a.$)?a.$:a;if(r.op==="remove"&&!Object.prototype.hasOwnProperty.call(c,n)||r.op==="set"&&Object.is(c[n],r.value))return a;const l=Array.isArray(c)?[...c]:{...c};if(Array.isArray(l)&&(!/^(0|[1-9]\d*)$/.test(n)||Number(n)>=l.length))throw new Error("Invalid array address.");return r.op==="remove"?Array.isArray(l)?l.splice(Number(n),1):delete l[n]:Object.defineProperty(l,n,{value:structuredClone(r.value),enumerable:!0,writable:!0,configurable:!0}),c===a?l:{...a,$:l}})}function ho(e,r,t){let n=Nu(e,r.value===void 0?{op:"remove",address:r.address}:{op:"set",address:r.address,value:r.value});const o=t==null?void 0:t({...r,previousValue:Ur(Fe(e,r.address)),data:Ur(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=Nu(n,i)}return n}const _n="data:image/svg+xml;base64,";function sr(e){if(e.startsWith(_n))return!0;try{const r=new URL(e);return(r.protocol==="https:"||r.protocol==="http:")&&!r.username&&!r.password}catch{return!1}}async function bw(e){if(e.size>256*1024)throw new Error("SVG must be 256 KB or smaller.");const r=await e.text(),t=new DOMParser().parseFromString(r,"image/svg+xml");if(t.doctype||t.querySelector("parsererror")||t.documentElement.localName!=="svg"||t.documentElement.namespaceURI!=="http://www.w3.org/2000/svg")throw new Error("Choose a valid SVG file.");if(t.querySelector("script, foreignObject")||[...t.querySelectorAll("*")].some(i=>[...i.attributes].some(s=>/^on/i.test(s.name))))throw new Error("SVG scripts and event handlers are not allowed.");const n=new TextEncoder().encode(r);let o="";for(const i of n)o+=String.fromCharCode(i);return _n+btoa(o)}const Yt=({name:e,svg:r=!1,...t})=>{const[n,o]=j.useState(null),[i,s]=j.useState(!0),[a,c]=j.useState(!1),l=typeof e=="string"&&sr(e);if(j.useEffect(()=>{if(l||!e||e.length<2){o(null),s(!1);return}s(!0),c(!1),(async()=>{try{let u;if(e.startsWith("Md"))u="md";else if(e.startsWith("Fa"))u="fa6";else if(e.startsWith("Io5"))u="io5";else if(e.startsWith("Io"))u="io";else if(e.startsWith("Ti"))u="ti";else if(e.startsWith("Go"))u="go";else if(e.startsWith("Fi"))u="fi";else if(e.startsWith("Di"))u="di";else if(e.startsWith("Ai"))u="ai";else if(e.startsWith("Bs"))u="bs";else if(e.startsWith("Ri"))u="ri";else if(e.startsWith("Fc"))u="fc";else if(e.startsWith("Gi"))u="gi";else if(e.startsWith("Hi2"))u="hi2";else if(e.startsWith("Hi"))u="hi";else if(e.startsWith("Si"))u="si";else if(e.startsWith("Sl"))u="sl";else if(e.startsWith("Im"))u="im";else if(e.startsWith("Bi"))u="bi";else if(e.startsWith("Pi"))u="pi";else if(e.startsWith("Vsc"))u="vsc";else if(e.startsWith("Tb"))u="tb";else if(e.startsWith("Tfi"))u="tfi";else if(e.startsWith("Cg"))u="cg";else if(e.startsWith("Lia"))u="lia";else if(e.startsWith("Lu"))u="lu";else throw new Error(`Unknown library prefix for icon: ${e}`);let h;switch(u){case"md":h=await import("react-icons/md");break;case"fa6":h=await import("react-icons/fa6");break;case"io5":h=await import("react-icons/io5");break;case"io":h=await import("react-icons/io");break;case"ti":h=await import("react-icons/ti");break;case"go":h=await import("react-icons/go");break;case"fi":h=await import("react-icons/fi");break;case"di":h=await import("react-icons/di");break;case"ai":h=await import("react-icons/ai");break;case"bs":h=await import("react-icons/bs");break;case"ri":h=await import("react-icons/ri");break;case"fc":h=await import("react-icons/fc");break;case"gi":h=await import("react-icons/gi");break;case"hi2":h=await import("react-icons/hi2");break;case"hi":h=await import("react-icons/hi");break;case"si":h=await import("react-icons/si");break;case"sl":h=await import("react-icons/sl");break;case"im":h=await import("react-icons/im");break;case"bi":h=await import("react-icons/bi");break;case"pi":h=await import("react-icons/pi");break;case"vsc":h=await import("react-icons/vsc");break;case"tb":h=await import("react-icons/tb");break;case"tfi":h=await import("react-icons/tfi");break;case"cg":h=await import("react-icons/cg");break;case"lia":h=await import("react-icons/lia");break;case"lu":h=await import("react-icons/lu");break;default:throw new Error(`Unsupported library: ${u}`)}const p=h[e];if(!p)throw new Error(`Icon ${e} not found in library ${u}`);o(()=>p)}catch(u){console.warn(`Failed to load icon ${e}:`,u.message),c(!0),o(null)}finally{s(!1)}})()},[e,l]),l){const{size:d=80,style:u,...h}=t;return r?f.jsx("image",{...h,href:e,width:d,height:d,preserveAspectRatio:"xMidYMid meet",style:u}):f.jsx("img",{...h,src:e,alt:"",width:d,height:d,referrerPolicy:"no-referrer",style:{objectFit:"contain",...u}})}return i||!n?null:f.jsx(n,{...t})};function vw(e,r){let t=e;for(const n of r){if(n.op!=="set"&&n.op!=="remove")throw new Error("Unsupported state edit.");const o=n.address.split(".");if(o.some(s=>s.startsWith("$")||["__proto__","prototype","constructor"].includes(s)))throw new Error("State edits cannot target view metadata or unsafe keys.");const i=n.op==="remove"?void 0:n.value;An(i),t=ho(t,{address:n.address,nodeAddress:o.slice(0,-1).join("."),value:i})}return An(t),t}function Nn(e,r,t){const n=Object.prototype.hasOwnProperty.call(e,r)?e[r]:void 0;if(!(!n||!t||!Object.prototype.hasOwnProperty.call(t,n.type)))return{address:n.address,type:t[n.type],fields:n.fields??{}}}function An(e){if(!(!e||typeof e!="object"))for(const[r,t]of Object.entries(e)){if(r.startsWith("$")||["__proto__","prototype","constructor"].includes(r))throw new Error(`Form state cannot contain view metadata or unsafe keys: ${r}`);An(t)}}function xw(e,r,t){An(r.value);const n=ho(e,r,t);return An(n),n}function hb(e,r){const t=(n,o="")=>{if(!n||typeof n!="object")return n;if(["$label","$subtitle","$content","$icon","$bgColor","$textColor","$borderColor"].includes(o)&&typeof n.$state=="string"){const s=Fe(r,n.$state);return s==null?"":typeof s=="object"?JSON.stringify(s,null,2):String(s)}let i=n;for(const[s,a]of Object.entries(n)){const c=t(a,s);c!==a&&(i===n&&(i=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(i,s,{value:c,enumerable:!0,writable:!0,configurable:!0}))}return i};return t(e)}const ww=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),Cw=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,pn=(e,r)=>JSON.stringify([e,r]);function Pn(e,r){if(e.kind==="union"){const t=e.types.find(n=>n.kind===(Array.isArray(r)?"array":r===null?"null":typeof r)||n.kind==="literal"&&Object.is(n.value,r));return Pn(t??e.types.find(n=>n.kind!=="null")??e.types[0]??{kind:"json"},r)}return e.kind!=="json"?e:Array.isArray(r)?{kind:"array",items:{kind:"json"}}:r!==null&&typeof r=="object"||r===void 0?{kind:"object",properties:{},additionalProperties:{kind:"json"}}:{kind:r===null?"null":typeof r}}function gn(e){const r=Pn(e,void 0);return r.kind==="object"?{}:r.kind==="array"?[]:r.kind==="literal"?r.value:r.kind==="number"||r.kind==="integer"?0:r.kind==="boolean"?!1:r.kind==="null"?null:""}function $u(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"&&!jn(e)?e.types:[e]}function Sw(e,r,t){if(r.address===t.address)return;const n=Fe(e,r.address),o=(i,s)=>s===void 0?!1:i.kind==="union"?i.types.some(a=>o(a,s)):i.kind==="array"?Array.isArray(s)&&s.every(a=>o(i.items,a)):i.kind==="object"?!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(i.properties).every(([a,c])=>c.optional&&s[a]===void 0||o(c.type,s[a]))&&Object.entries(s).every(([a,c])=>Object.prototype.hasOwnProperty.call(i.properties,a)||!i.additionalProperties||o(i.additionalProperties,c)):s===""?i.kind==="string"||i.kind==="json"||i.kind==="literal"&&i.value==="":!Vt(i,s,!0);if(o(t.type,n))return structuredClone(n)}function pb(e,r,t,n){var c,l;const o={sourceSchema:t,sourceBindings:r,nodes:[],edges:[],schema:{...t},bindings:{...r},slots:new Map,containers:new Map},i=new Set(n.map(d=>d.data.id)),s=new Map(n.flatMap(d=>{const u=r[d.data.id];return u&&t[u.type]?[[u.address,d.data.id]]:[]})),a=(d,u,h,p,m,y=!1)=>{var _,I,E,O,A;if(m>24||o.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const g=Fe(e,u),v=Pn(h,g),b=v.kind!=="object"&&v.kind!=="array";o.containers.set(d,{address:u,type:v,declared:h,scalar:b});const x=`__form:${d}`,w={...(_=o.bindings[d])==null?void 0:_.fields},C={kind:"object",properties:{},ports:{...v.kind==="object"?v.ports:{},...y?{resource:{label:"output",...v.kind==="object"?(I=v.ports)==null?void 0:I.resource:{},kind:"output"}}:{}}},S=v.kind==="object"?{...v.properties,...Object.fromEntries(Object.keys(g??{}).filter(R=>!Object.prototype.hasOwnProperty.call(v.properties,R)&&v.additionalProperties).map(R=>[R,{type:v.additionalProperties,optional:!0}]))}:v.kind==="array"?Object.fromEntries((Array.isArray(g)?g:[]).map((R,P)=>[String(P),{type:v.items,optional:!0}])):{value:{type:jn(h)?h:v,optional:!1}};for(const[R,P]of Object.entries(S)){if(!ww(R))throw new Error(`Unsupported structured property key: ${R}`);const T=b?u:`${u}.${R}`,N=Fe(e,T),$=Pn(P.type,N),M=$.kind==="object"||$.kind==="array",W=(E=C.ports)==null?void 0:E[R],ae=(W==null?void 0:W.kind)==="config"&&(((O=w[R])==null?void 0:O.$options)||jn(P.type)),se=P.type.kind==="json"||P.type.kind==="union"&&!jn(P.type);if(((A=w[R])==null?void 0:A.$control)==="upload"||!M&&v.kind!=="array"&&(!se||b)||ae){C.properties[R]={...P,type:P.type.kind==="json"?$:P.type};continue}const re=s.get(T)??Cw(T),ye=v.kind==="array"?`Item ${Number(R)+1}`:R,me={address:T,owner:d,field:R,type:P.type,label:ye,nodeId:re,present:N!==void 0};if(o.slots.set(pn(d,R),me),C.ports[R]={kind:"config",resourceType:`__form:${re}`},N===void 0||(o.edges.push({data:{id:`__form-edge:${d}:${R}`,source:re,target:d,sourceProperty:"output:resource",targetProperty:`config:${R}`,isEdgeDashed:!0}}),o.containers.has(re)||s.has(T)))continue;if(i.has(re))throw new Error(`Structured node identity conflict: ${re}`);i.add(re);const L={data:{id:re,type:"objectView",label:ye,headerTitle:ye,description:{},config:{form:!0,icon:$.kind==="array"?"PiListNumbers":M?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push(L),a(re,T,P.type,p,m+1,!0);const z=o.schema[`__form:${re}`];L.data.description=Object.fromEntries(Object.keys(z.properties).map(U=>[U,Fe(e,$.kind==="array"||$.kind==="object"?`${T}.${U}`:T)]).filter(([,U])=>U!==void 0))}o.schema[x]=C,o.bindings[d]={...o.bindings[d],address:u,type:x,fields:w}};for(const d of n){const u=r[d.data.id];if(u!=null&&u.portResources)continue;const h=u&&t[u.type];!u||!h||Fe(e,u.address)===void 0||a(d.data.id,u.address,h,(c=d.data.viewProps)==null?void 0:c.bgColor,0,o.edges.some(p=>p.data.source===d.data.id))}for(const d of o.edges){const u=o.bindings[d.data.source],h=o.schema[u.type].ports;h.resource={...h.resource,kind:"output",label:((l=h.resource)==null?void 0:l.label)??"output"}}return o}const kr=(e="reference")=>({kind:e,text:"",paths:[""]}),gb=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(r=>["__proto__","constructor","prototype"].includes(r));function jw(e,r){const t=new Set(r.map(s=>s.path)),n=s=>{if(!s.paths.length||s.paths.some(a=>!gb(a)||!t.has(a)))throw new Error("Choose an available reference.");return[...s.paths,...s.fallback===void 0?[]:[JSON.stringify(s.fallback)]].join(" || ")},o=s=>{if(s.includes("{{")||s.includes("}}"))throw new Error("Use a reference part for dynamic values.");return s},i=s=>s.map(a=>{if(a.kind==="text")return o(a.text);if(a.kind==="conditional"){if(a.paths.length!==1||a.fallback!==void 0)throw new Error("Choose one condition reference.");return`{{#if ${n(a)}}}${o(a.text)}{{/if}}`}return`{{${n(a)}}}`}).join("");if(e.mode==="reference"||e.mode==="condition"){if(e.parts.length!==1||e.parts[0].kind!=="reference")throw new Error("Choose one reference binding.");const s=i(e.parts);return e.mode==="condition"?`${s} == ${JSON.stringify(e.comparison)}`:s}if(e.mode==="json"){const s=e.fields.map(a=>a.key);if(!s.length||new Set(s).size!==s.length||s.some(a=>!a||["__proto__","constructor","prototype"].includes(a)))throw new Error("Output field names must be unique and nonempty.");return JSON.stringify(Object.fromEntries(e.fields.map(a=>[a.key,i(a.parts)])))}return i(e.parts)}async function _w(e){const r=await import("typescript"),t=s=>{const a=r.createSourceFile("binding.ts",`(${s})`,r.ScriptTarget.Latest,!0,r.ScriptKind.TS);if(a.parseDiagnostics.length)throw new Error("Unsupported reference expression.");const c=a.statements[0];if(!c||!r.isExpressionStatement(c))throw new Error("Unsupported reference expression.");const l=kr();l.paths=[];const d=u=>{if(r.isParenthesizedExpression(u))return d(u.expression);if(r.isBinaryExpression(u)&&u.operatorToken.kind===r.SyntaxKind.BarBarToken){d(u.left),d(u.right);return}if(r.isStringLiteral(u)){if(l.fallback!==void 0)throw new Error("Multiple fallback values.");l.fallback=u.text;return}const h=u.getText(a);if(!gb(h)||l.fallback!==void 0)throw new Error("Unsupported reference expression.");l.paths.push(h)};if(d(c.expression),!l.paths.length)throw new Error("A binding needs a reference.");return l},n=s=>{const a=[];let c=0;const l=/\{\{([\s\S]*?)\}\}/g;for(const d of s.matchAll(l)){const u=d.index;if(u<c)continue;u>c&&a.push({...kr("text"),text:s.slice(c,u)});const h=d[1].trim();if(h.startsWith("#if ")){const p=s.indexOf("{{/if}}",u+d[0].length);if(p<0)throw new Error("Unclosed condition.");a.push({...t(h.slice(4)),kind:"conditional",text:s.slice(u+d[0].length,p)}),c=p+7}else a.push(t(h)),c=u+d[0].length}return c<s.length&&a.push({...kr("text"),text:s.slice(c)}),a},o={mode:"reference",parts:[kr()],comparison:"",fields:[]};if(!e)return o;if(e.trim().startsWith("{"))try{const s=JSON.parse(e);if(s&&typeof s=="object"&&!Array.isArray(s)&&Object.values(s).every(a=>typeof a=="string"))return{...o,mode:"json",fields:Object.entries(s).map(([a,c])=>({key:a,parts:n(c)}))}}catch{}const i=n(e);if(i.length===2&&i[0].kind==="reference"&&i[1].kind==="text"){const s=r.createSourceFile("condition.ts",`value ${i[1].text}`,r.ScriptTarget.Latest,!0,r.ScriptKind.TS),a=s.statements[0];if(s.statements.length===1&&r.isExpressionStatement(a)&&r.isBinaryExpression(a.expression)&&a.expression.operatorToken.kind===r.SyntaxKind.EqualsEqualsToken&&r.isStringLiteral(a.expression.right))return{...o,mode:"condition",parts:[i[0]],comparison:a.expression.right.text}}return{...o,mode:i.length===1&&i[0].kind==="reference"?"reference":"template",parts:i}}function qu({parts:e,references:r,onChange:t,disabled:n}){const o=(i,s)=>t(e.map((a,c)=>c===i?{...a,...s}:a));return f.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((i,s)=>f.jsxs("fieldset",{"data-binding-part":s,style:{border:0,padding:0,margin:0,minWidth:0},children:[f.jsxs("legend",{children:["Part ",s+1]}),f.jsxs("div",{style:{display:"flex",gap:8},children:[f.jsxs("span",{"data-form-select":"",style:{flex:1},children:[f.jsxs("select",{"aria-label":"Part type",disabled:n,value:i.kind,onChange:a=>o(s,{kind:a.target.value}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"text",children:"Text"}),f.jsx("option",{value:"conditional",children:"Conditional text"})]}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),f.jsx(Oe,{"aria-label":`Remove part ${s+1}`,title:"Remove part",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t(e.filter((a,c)=>c!==s))})]}),i.kind!=="text"&&f.jsxs(f.Fragment,{children:[i.paths.map((a,c)=>f.jsxs("label",{children:["Reference ",c+1,f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":`Reference ${c+1}`,disabled:n,value:a,onChange:l=>o(s,{paths:i.paths.map((d,u)=>u===c?l.target.value:d)}),children:[f.jsx("option",{value:"",children:"Select reference"}),r.map(l=>f.jsx("option",{value:l.path,children:l.label},l.path))]}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]},c)),i.kind==="reference"&&f.jsxs(f.Fragment,{children:[f.jsx(Oe,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>o(s,{paths:[...i.paths,""]})}),f.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center"},children:[f.jsx("input",{type:"checkbox","aria-label":"Default value enabled",disabled:n,checked:i.fallback!==void 0,onChange:a=>o(s,{fallback:a.target.checked?"":void 0})}),"Default value"]}),i.fallback!==void 0&&f.jsx("input",{"aria-label":"Default value",disabled:n,value:i.fallback,onChange:a=>o(s,{fallback:a.target.value})})]})]}),i.kind!=="reference"&&f.jsxs("label",{children:["Text",f.jsx("textarea",{"aria-label":"Part text",disabled:n,value:i.text,onChange:a=>o(s,{text:a.target.value})})]})]},s)),f.jsx(Oe,{"aria-label":"Add part",title:"Add part",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t([...e,kr()])})]})}function Ew({label:e,value:r,references:t,disabled:n,onChange:o}){const[i,s]=j.useState(),[a,c]=j.useState(""),[l,d]=j.useState(!1),u=async()=>{d(!0),c("");try{s(await _w(typeof r=="string"?r:""))}catch(h){c(h instanceof Error?h.message:"Unable to read binding.")}finally{d(!1)}};return f.jsxs("div",{"data-runtime-binding":e,style:{marginBottom:8},children:[f.jsx(Oe,{"aria-label":`Bind ${e}`,title:`Bind ${e}`,icon:f.jsx(Z.PiLink,{size:18}),size:"sm",variant:"ghost",disabled:n||l,onClick:u}),typeof r=="string"&&r.includes("{{")&&f.jsx("span",{children:"Bound value"}),i&&f.jsxs("fieldset",{disabled:n,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Binding mode",f.jsxs("span",{"data-form-select":"",style:{display:"block"},children:[f.jsxs("select",{"aria-label":"Binding mode",value:i.mode,onChange:h=>s({...i,mode:h.target.value,parts:[kr()]}),children:[f.jsx("option",{value:"reference",children:"Reference"}),f.jsx("option",{value:"condition",children:"Equals"}),f.jsx("option",{value:"template",children:"Text template"}),f.jsx("option",{value:"json",children:"JSON output"})]}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]})]}),i.mode==="json"?f.jsxs(f.Fragment,{children:[i.fields.map((h,p)=>f.jsxs("fieldset",{"data-output-field":p,style:{border:0,margin:0,padding:"8px 0",minWidth:0},children:[f.jsxs("label",{children:["Output field name",f.jsx("input",{"aria-label":"Output field name",value:h.key,onChange:m=>s({...i,fields:i.fields.map((y,g)=>g===p?{...y,key:m.target.value}:y)})})]}),f.jsx(qu,{parts:h.parts,references:t,disabled:n,onChange:m=>s({...i,fields:i.fields.map((y,g)=>g===p?{...y,parts:m}:y)})}),f.jsx(Oe,{"aria-label":"Remove output field",title:"Remove output field",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:i.fields.filter((m,y)=>y!==p)})})]},p)),f.jsx(Oe,{"aria-label":"Add output field",title:"Add output field",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...i,fields:[...i.fields,{key:"",parts:[kr()]}]})})]}):f.jsx(qu,{parts:i.parts,references:t,disabled:n,onChange:h=>s({...i,parts:h})}),i.mode==="condition"&&f.jsxs("label",{children:["Equals",f.jsx("input",{"aria-label":"Comparison value",value:i.comparison,onChange:h=>s({...i,comparison:h.target.value})})]}),f.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[f.jsx(Oe,{"aria-label":"Apply binding",title:"Apply binding",icon:f.jsx(Z.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{o(jw(i,t)),s(void 0),c("")}catch(h){c(h instanceof Error?h.message:"Unable to apply binding.")}}}),f.jsx(Oe,{"aria-label":"Cancel binding",title:"Cancel binding",icon:f.jsx(Z.PiX,{size:20}),size:"sm",variant:"ghost",onClick:()=>{s(void 0),c("")}})]})]}),a&&f.jsx("p",{role:"alert",children:a})]})}function kw({nodeAddress:e,onOpen:r}){const{structured:t,data:n,callbacks:o,editable:i,onFieldCreate:s}=j.useContext(Tt),a=Je(),[c,l]=j.useState(""),[d,u]=j.useState("0"),[h,p]=j.useState(""),m=t==null?void 0:t.containers.get(e);if(!m||!n||!t)return null;const y=a.readOnly||a.config.editable===!1||!i,g=Fe(n,m.address),v=$u(m.declared),b=m.type.kind==="array"?m.type.items:m.type.kind==="object"?m.type.additionalProperties:void 0,x=b?$u(b):[],w=!!s&&m.type.kind==="object"&&(b==null?void 0:b.kind)==="json",C=P=>P.kind==="literal"?String(P.value):P.kind==="string"?"Text":qt(P.kind),S=[...t.slots.values()].filter(P=>P.owner===e),_=(P,T)=>{var N;return(N=o.onFormChange)==null?void 0:N.call(o,{data:n,nodeAddress:m.address,address:P,previousValue:Fe(n,P),value:T})},I=P=>{var T;a.setSelectedNodeIds([P]),(T=a.engineRef.current)==null||T.focusNode(P,90,!1)},E=(P,T)=>{if(!Array.isArray(g))return;const N=[...g];[N[P],N[P+T]]=[N[P+T],N[P]],_(m.address,N)},O=()=>{const P=x[Number(d)]??x[0];if(P)if(m.type.kind==="array")_(m.address,[...Array.isArray(g)?g:[],gn(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(g,c)){p("Property already exists.");return}w&&(d==="file"||d==="files")?s==null||s({data:n,nodeAddress:m.address,address:`${m.address}.${c}`,previousValue:void 0,value:d==="files"?[]:""},{$control:"upload"}):_(`${m.address}.${c}`,gn(P)),l(""),p("")}},A=m.type.kind==="object"&&!!m.type.additionalProperties,R=m.type.kind==="array";return f.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[v.length>1&&f.jsxs("label",{children:["Value type",f.jsx("span",{"data-form-select":"",style:{display:"block"},children:f.jsx(Mt,{"aria-label":"Value type",disabled:y,value:String(v.findIndex(P=>Pn(P,g).kind===m.type.kind)),onValueChange:P=>_(m.address,gn(v[Number(P)])),children:v.map((P,T)=>f.jsx("option",{value:T,children:C(P)},T))})})]}),S.map((P,T)=>f.jsxs("div",{"data-structured-slot":P.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[P.type.kind==="array"?f.jsx(Z.PiListNumbers,{size:20}):f.jsx(Z.PiBracketsCurly,{size:20}),f.jsx("span",{style:{flex:1,overflowWrap:"anywhere"},children:qt(P.label)}),f.jsx(Oe,{"aria-label":`${P.present?r?"Edit":"Focus":"Create"} ${qt(P.label)}`,title:`${P.present?r?"Edit":"Focus":"Create"} ${qt(P.label)}`,icon:P.present?f.jsx(Z.PiMagnifyingGlass,{size:18}):f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:y&&!P.present,onClick:N=>{var $;P.present?r?r(P.nodeId):(($=N.currentTarget.closest("dialog"))==null||$.close(),I(P.nodeId)):_(P.address,gn(P.type))}}),R&&f.jsxs(f.Fragment,{children:[f.jsx(Oe,{"aria-label":`Move item ${T+1} up`,icon:f.jsx(Z.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:y||T===0,onClick:()=>E(T,-1)}),f.jsx(Oe,{"aria-label":`Move item ${T+1} down`,icon:f.jsx(Z.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:y||T===S.length-1,onClick:()=>E(T,1)})]}),P.present&&f.jsx(Oe,{"aria-label":`Remove ${qt(P.label)}`,icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:y,onClick:()=>R?_(m.address,g.filter((N,$)=>$!==T)):_(P.address,void 0)})]},P.address)),(R||A)&&f.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[A&&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:y,onChange:P=>l(P.target.value)})]}),x.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(Mt,{"aria-label":"New value type",value:d,disabled:y,onValueChange:u,children:[x.map((P,T)=>f.jsx("option",{value:T,children:C(P)},T)),w&&f.jsx("option",{value:"file",children:"File"}),w&&f.jsx("option",{value:"files",children:"Files"})]})})]}),f.jsx("span",{style:{display:"flex",alignItems:"center",flexShrink:0,...A||x.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:f.jsx(Oe,{"aria-label":R?"Add item":"Add property",icon:f.jsx(Z.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:y,onClick:O})})]}),h&&f.jsx("p",{role:"alert",children:h})]})}const Tt=j.createContext({callbacks:{}}),Kn=ao.default.div`
|
|
59
59
|
--flow-form-input-radius: 16px;
|
|
60
60
|
--flow-form-input-background: color-mix(
|
|
61
61
|
in srgb,
|
|
@@ -206,9 +206,9 @@
|
|
|
206
206
|
font-size: 14px;
|
|
207
207
|
margin-top: 8px;
|
|
208
208
|
}
|
|
209
|
-
`;function qu({request:e,property:r,config:t,value:n,disabled:o}){var ye,pe,X,L,ae;const{callbacks:i,structured:s,references:a}=_.useContext(Mt),{themeColor:c}=Ze(),{background:l}=at(),d=_.useId(),u=r.type.kind==="object"||r.type.kind==="array"||r.type.kind==="json",h=n===void 0?"":u?JSON.stringify(n,null,2):String(n),[p,m]=_.useState(h),[y,g]=_.useState(""),[v,b]=_.useState(0),x=_.useRef(null),w=_.useRef(),[C,S]=_.useState(!1),[j,P]=_.useState(!1),[E,O]=_.useState(),A=((ye=t.$options)==null?void 0:ye.$source)==="callback",R=i.resolveFormOptions,{data:M,address:T,nodeAddress:N,nodeId:$}=e;_.useEffect(()=>(S(!1),P(!1),()=>{var H;(H=w.current)==null||H.abort(),w.current=void 0}),[T,N,$,o,h,t.$control,(pe=t.$upload)==null?void 0:pe.accept,(X=t.$upload)==null?void 0:X.maxSizeBytes]);const I=_.useRef(M);I.current=M;const K=JSON.stringify([T,$,(L=t.$options)!=null&&L.$dependsOn?t.$options.$dependsOn.map(H=>qe(M,H)):qe(M,N)]);_.useEffect(()=>{m(h),g("")},[h,T,$]),_.useEffect(()=>{if(!A)return;const H=new AbortController;return Promise.resolve().then(()=>{if(!R)throw new Error("No options resolver configured");return R({address:T,nodeAddress:N,nodeId:$,data:Wr(I.current),signal:H.signal})}).then(fe=>{if(!Array.isArray(fe)||fe.some(be=>!be||typeof be.label!="string"||!["string","number","boolean"].includes(typeof be.value)&&be.value!==null))throw new Error("Invalid options response");H.signal.aborted||O({key:K,options:fe})}).catch(fe=>{H.signal.aborted||O({key:K,options:[],error:fe instanceof Error?fe.message:"Options unavailable"})}),()=>H.abort()},[A,R,K,T,N,$,v]);const ie=A&&(E==null?void 0:E.key)!==K,se=A?(E==null?void 0:E.key)===K?E.options:[]:r.type.kind==="null"?[{label:"Null",value:null}]:r.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:Sn(r.type),te=r.type.kind==="array",me=(t.$control==="upload"?"upload":s&&u||t.$control==="checkbox"?"pills":t.$control)??(se?te||r.type.kind==="boolean"?"pills":"select":r.type.kind==="boolean"?"checkbox":u?"textarea":"input"),ve=!r.optional||!!t.$requiredWhen&&uo(t.$requiredWhen,M),F=ve?"Required":"Optional",D=me!=="upload"&&!!(a!=null&&a.length)&&typeof n=="string"&&n.includes("{{"),W=y||A&&(E==null?void 0:E.key)===K&&E.error||!D&&Dt(r.type,n,ve),B=$t(t.$label??T.split(".").pop()),le=H=>{var fe;if(!(o||Object.is(H,n)))try{(fe=i.onFormChange)==null||fe.call(i,{...e,previousValue:n,value:H}),g("")}catch(be){g(be instanceof Error?be.message:"Unable to update field")}},Y=_.useRef(le);_.useLayoutEffect(()=>{Y.current=le});const ce=()=>{if(u){try{const Ne=p===""&&r.optional?void 0:JSON.parse(p),Le=Dt(r.type,Ne,ve);if(Le){g(Le);return}le(Ne)}catch{g("Enter valid JSON")}return}const H=r.type.kind==="number"||r.type.kind==="integer",fe=p===""&&r.optional?void 0:H&&p!==""?Number(p):p,be=Dt(r.type,fe,ve);if(H&&be&&p!==""){g(be);return}le(fe)},ue=async H=>{var be,Ne,Le;if(o||w.current||!H.length)return;const fe=new AbortController;w.current=fe,g(""),S(!0);try{if(r.type.kind!=="string"&&!(r.type.kind==="array"&&r.type.items.kind==="string"))throw new Error("Uploads require a string or string-array field.");if(!te&&H.length!==1)throw new Error("Choose one file for this field.");if(!i.uploadFormFile)throw new Error("No file upload handler configured.");const Be=(Ne=(be=t.$upload)==null?void 0:be.accept)==null?void 0:Ne.split(",").map(Ye=>Ye.trim().toLowerCase()).filter(Boolean);for(const Ye of H){if(((Le=t.$upload)==null?void 0:Le.maxSizeBytes)!==void 0&&Ye.size>t.$upload.maxSizeBytes)throw new Error(`${Ye.name} exceeds the file size limit.`);if(Be!=null&&Be.length&&!Be.some(nt=>nt.startsWith(".")?Ye.name.toLowerCase().endsWith(nt):nt.endsWith("/*")?Ye.type.toLowerCase().startsWith(nt.slice(0,-1)):Ye.type.toLowerCase()===nt))throw new Error(`${Ye.name} is not an accepted file type.`)}const tt=await Promise.all(H.map(async Ye=>{const nt=await i.uploadFormFile({...e,data:Wr(M),file:Ye,signal:fe.signal});if(typeof nt!="string")throw new Error("Upload handler must return an HTTP or HTTPS URL.");let ht;try{ht=new URL(nt)}catch{throw new Error("Upload handler must return an HTTP or HTTPS URL.")}if(!["http:","https:"].includes(ht.protocol)||ht.username||ht.password)throw new Error("Upload handler must return an HTTP or HTTPS URL.");return nt}));if(fe.signal.aborted||w.current!==fe)return;const Je=te?[...Array.isArray(n)?n:[],...tt]:tt[0],yt=Dt(r.type,Je,ve);if(yt)throw new Error(yt);Y.current(Je)}catch(Be){fe.signal.aborted||g(Be instanceof Error?Be.message:"Unable to upload file."),fe.abort()}finally{w.current===fe&&(w.current=void 0,S(!1))}},xe={id:d,disabled:o,"aria-label":B,"aria-required":ve,"aria-invalid":!!W,"aria-describedby":W?`${d}-error`:void 0},Ce=Ae(c);return f.jsxs("div",{"data-form-field":T,"data-flow-property":T.slice(N.length+1),children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[f.jsxs("label",{htmlFor:d,children:[B,ve?" *":""]}),r.optional&&n!==void 0&&f.jsx("button",{type:"button","aria-label":`Reset ${B}`,title:`Reset ${B}`,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:()=>le(void 0),children:f.jsx(Z.PiArrowCounterClockwise,{size:14})})]}),!!(a!=null&&a.length)&&!u&&me!=="upload"&&f.jsx(Cw,{label:B,value:n,references:a,disabled:o,onChange:le}),me==="upload"?f.jsxs("div",{"data-form-upload":te?"multiple":"single","aria-busy":C,style:{"--flow-upload-surface":Ae(l),outline:j?"2px dashed var(--flow-form-input-background)":void 0,borderRadius:"var(--flow-form-input-radius)"},onDragOver:H=>{H.preventDefault(),H.stopPropagation(),!o&&!C&&(H.dataTransfer.dropEffect="copy",P(!0))},onDragLeave:H=>{H.currentTarget.contains(H.relatedTarget)||P(!1)},onDrop:H=>{H.preventDefault(),H.stopPropagation(),P(!1),ue(Array.from(H.dataTransfer.files))},children:[f.jsx("input",{ref:x,type:"file",hidden:!0,"aria-label":`Upload ${B}`,accept:(ae=t.$upload)==null?void 0:ae.accept,multiple:te,disabled:o||C,onChange:H=>{const fe=Array.from(H.target.files??[]);H.target.value="",ue(fe)}}),f.jsxs("div",{"data-upload-items":"",children:[(te?Array.isArray(n)?n:[]:n?[n]:[]).map((H,fe)=>f.jsxs("div",{"data-upload-preview":"",children:[typeof H=="string"&&ar(H)&&f.jsxs("a",{href:H,target:"_blank",rel:"noopener noreferrer","aria-label":`${B} file ${fe+1}`,children:[f.jsx(Z.PiFile,{size:32,"aria-hidden":"true"}),f.jsx(Zt,{name:H,size:120,onError:be=>{be.currentTarget.style.visibility="hidden"}})]}),f.jsxs("div",{"data-upload-actions":"",children:[!te&&f.jsx(Me,{"aria-label":`Replace ${B}`,title:`Replace ${B}`,icon:f.jsx(Z.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>{var be;return(be=x.current)==null?void 0:be.click()}}),f.jsx(Me,{"aria-label":`Remove ${B} file ${fe+1}`,title:"Remove file",icon:f.jsx(Z.PiTrash,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>le(te&&Array.isArray(n)?n.filter((be,Ne)=>Ne!==fe):"")})]})]},`${fe}:${H}`)),(te||!n)&&f.jsx("button",{...xe,type:"button","data-upload-drop":"",title:`Upload ${B}`,disabled:o||C,onClick:()=>{var H;return(H=x.current)==null?void 0:H.click()},children:f.jsx(Z.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&f.jsx("span",{role:"status",children:"Uploading..."})]}):D?null:me==="select"?f.jsx("div",{"data-form-select":"",children:f.jsxs(Pt,{...xe,disabled:o||ie||!!(E!=null&&E.error),labelCase:"preserve",value:String((se==null?void 0:se.findIndex(H=>Object.is(H.value,n)))??-1),onValueChange:H=>{const fe=se==null?void 0:se[Number(H)];fe&&le(fe.value)},children:[f.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):F}),se==null?void 0:se.map((H,fe)=>f.jsx("option",{value:fe,children:$t(H.label)||H.label},fe))]})}):me==="pills"?f.jsxs("div",{id:d,role:"group","aria-label":B,"aria-describedby":xe["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:[se==null?void 0:se.map((H,fe)=>{const be=te?Array.isArray(n)&&n.includes(H.value):Object.is(n,H.value);return f.jsx("button",{type:"button",disabled:o||ie,"aria-pressed":be,style:{padding:"8px 16px",borderRadius:24,border:0,color:be?Ce:"inherit",background:be?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>le(te?be?n.filter(Ne=>Ne!==H.value):[...Array.isArray(n)?n:[],H.value]:H.value),children:$t(H.label)||H.label},fe)}),ie&&f.jsx("span",{role:"status",children:"Loading..."})]}):me==="textarea"?f.jsx("textarea",{...xe,placeholder:F,value:p,onChange:H=>m(H.target.value),onBlur:ce}):f.jsx("input",{...xe,placeholder:F,type:r.type.kind==="number"||r.type.kind==="integer"?"number":"text",step:r.type.kind==="integer"?1:"any",value:p,onChange:H=>m(H.target.value),onBlur:ce,onKeyDown:H=>{H.key==="Enter"&&ce(),H.key==="Escape"&&m(n===void 0?"":String(n))}}),W&&f.jsx("div",{role:"alert",id:`${d}-error`,children:W}),A&&(E==null?void 0:E.error)&&f.jsx("button",{type:"button",disabled:o,onClick:()=>{O(void 0),b(v+1)},children:"Retry"})]})}function Md({nodeAddress:e,structured:r=!1}){return r?f.jsx(jw,{nodeAddress:e},e):f.jsx(fd,{nodeAddress:e})}function jw({nodeAddress:e}){var u,h,p;const r=_.useContext(Mt),[t,n]=_.useState([]),o=((u=r.structured)==null?void 0:u.sourceSchema)??r.schema,i=((h=r.structured)==null?void 0:h.sourceBindings)??r.bindings,s=_.useMemo(()=>{if(!(!r.data||!o||!i))return db(r.data,i,o,[{data:{id:e,type:"objectView"}}])},[r.data,i,o,e]);if(!s)return f.jsx(fd,{nodeAddress:e});const a=t.findIndex(m=>!s.containers.has(m)),c=a<0?t:t.slice(0,a),l=c.at(-1)??e,d=(p=[...s.slots.values()].find(m=>m.nodeId===l))==null?void 0:p.label;return f.jsxs(Mt.Provider,{value:{...r,structured:s,schema:s.schema,bindings:s.bindings,renderForm:void 0,onFieldCreate:l===e?r.onFieldCreate:void 0},children:[!!c.length&&f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[f.jsx(Me,{"aria-label":"Back to parent fields",title:"Back to parent fields",icon:f.jsx(Z.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:()=>n(c.slice(0,-1))}),f.jsx("strong",{style:{minWidth:0,overflowWrap:"anywhere"},children:$t(d)})]}),f.jsx(fd,{nodeAddress:l,onOpen:m=>n([...c,m])},l)]})}function fd({nodeAddress:e,onOpen:r}){var S,j;const{data:t,schema:n,callbacks:o,bindings:i,editable:s,renderForm:a,structured:c}=_.useContext(Mt),{readOnly:l,config:d,colorMode:u}=Ze(),h=a==null?void 0:a(e);if(h!==void 0)return f.jsx("fieldset",{"data-flow-form":e,disabled:l||d.editable===!1||!s,style:{border:0,margin:0,padding:0,minWidth:0},children:h});if(!t)return f.jsx(Hn,{$colorMode:u,role:"alert",children:"Forms require a JSON document."});const p=i?On(i,e,n):void 0,m=i?p:n&&Zr(t,e,n);if(!m)return f.jsx(Hn,{$colorMode:u,role:"status",children:"Form schema unavailable."});const y=(p==null?void 0:p.address)??e,g=qe(t,y),v=(S=c==null?void 0:c.containers.get(e))==null?void 0:S.scalar;if(g===void 0||typeof g!="object"&&!v)return f.jsx(Hn,{$colorMode:u,role:"alert",children:"Bound form state is unavailable."});const b=Object.entries(m.type.properties).filter(([P])=>{var E;return uo((E=m.fields[P])==null?void 0:E.$visibleWhen,t)}),x=b.length>8||b.some(([P])=>{var E;return(E=m.fields[P])==null?void 0:E.$section}),w=new Map;for(const P of b){const[E,O]=P,A=x?$t(((j=m.fields[E])==null?void 0:j.$section)??(O.type.kind==="object"||O.type.kind==="array"?E:O.optional?"Options":"General")):"";w.has(A)||w.set(A,[]),w.get(A).push(P)}const C=([P,E])=>f.jsx(qu,{request:{data:t,address:v?y:`${y}.${P}`,nodeAddress:y,nodeId:typeof(g==null?void 0:g.id)=="string"?g.id:void 0},property:E,config:m.fields[P]??{},value:v?g:g==null?void 0:g[P],disabled:l||d.editable===!1||!(s??!!o.onJsonChange)},`${(g==null?void 0:g.id)??e}:${P}`);return f.jsxs(Hn,{$colorMode:u,"data-flow-form":e,onClick:P=>P.stopPropagation(),onDoubleClick:P=>P.stopPropagation(),children:[c&&f.jsx(Sw,{nodeAddress:e,onOpen:r}),!c&&p&&m.type.additionalProperties&&b.length===0&&f.jsx(qu,{request:{data:t,address:y,nodeAddress:y},property:{type:m.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:g,disabled:l||d.editable===!1||!s}),[...w].map(([P,E])=>x&&E.length>1?f.jsxs("details",{open:!0,children:[f.jsxs("summary",{children:[f.jsx("span",{children:P}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),E.map(C)]},P):E.map(C))]})}function fb(e){const{viewData:r}=_.useContext(Mt),{nodeById:t,edgeById:n,parentIds:o}=yr();if(r){const i=qe(r,e),s=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(s)?s.length>0:!!s&&typeof s=="object"&&Object.entries(s).some(([a,c])=>!a.startsWith("$")&&c!==null&&typeof c=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const s=i.isInverted?i.target:i.source,a=i.isInverted?i.source:i.target;return s===e&&a!==e&&t.has(a)})}function Pn(e,r){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:r}function In(e,r,t,n){return{borderColor:r,borderWidth:Pn(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",..._m(r==="transparent"?"currentColor":r,t,".flow-sdk-node:hover &",!t)}}function hb({label:e,value:r,options:t,onChange:n,disabled:o}){var i;return f.jsxs(Pt,{"aria-label":e,title:`Animation: ${((i=t.find(s=>s.value===r))==null?void 0:i.label)??"Mixed"}`,value:r,style:{width:104},disabled:o,onValueChange:s=>{const a=t.find(c=>c.value===s);a&&n(a.value)},children:[r===""&&f.jsx("option",{value:"",disabled:!0,children:"Mixed"}),t.map(s=>f.jsx("option",{value:s.value,children:s.label},s.value))]})}function Td({nodeId:e,edgeId:r,value:t,open:n,onOpenChange:o}){const{callbacks:i,readOnly:s,themeColor:a,colorMode:c}=Ze(),{background:l,backgroundSecondary:d,border:u,colorText:h,colorInactive:p}=at(),m=c==="dark"?Kr:Ae(p),y=_.useRef(null),g=_.useRef(null),v=_.useRef(0),[b,x]=_.useState(!1),[w,C]=_.useState("icons"),[S,j]=_.useState([]),[P,E]=_.useState("loading"),[O,A]=_.useState(""),[R,M]=_.useState(0),[T,N]=_.useState(""),[$,I]=_.useState(""),[K,ie]=_.useState(!1);_.useEffect(()=>()=>{v.current++},[]),_.useEffect(()=>{if(!b)return;let B=!0;return import("react-icons/pi").then(le=>{B&&(j(Object.keys(le).filter(Y=>Y.startsWith("Pi")).sort()),E("ready"))}).catch(()=>{B&&E("unavailable")}),()=>{B=!1}},[b]),_.useEffect(()=>{var B;s&&((B=y.current)==null||B.close())},[s]),_.useEffect(()=>{var B,le,Y;if(n!==void 0){if(!n||s){(B=y.current)==null||B.close();return}(le=y.current)!=null&&le.open||(I(""),C(t==="PiFileSvg"||t&&ar(t)?"custom":"icons"),N(t&&!t.startsWith(jn)&&ar(t)?t:""),x(!0),(Y=y.current)==null||Y.showModal())}},[n,s,t]);const se=B=>{var le,Y,ce;s||(r?(le=i.onEdgeIconChange)==null||le.call(i,r,B):e&&((Y=i.onNodeIconChange)==null||Y.call(i,e,B)),o==null||o(!1),(ce=y.current)==null||ce.close())},te=S.filter(B=>B.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(O.trim().toLowerCase())),me=36,ve=Math.max(1,Math.ceil(te.length/me)),F=Math.min(R,ve-1),D=te.slice(F*me,(F+1)*me),W={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${Ae(u)}`,borderRadius:30};return f.jsxs(f.Fragment,{children:[n===void 0&&f.jsx(Ue,{label:r?"Choose edge icon":"Choose node icon",children:f.jsx(Me,{"aria-label":r?"Choose edge icon":"Choose node icon",icon:f.jsx(Z.PiShapes,{size:20}),size:"sm",variant:"ghost",color:Ae(a),disabled:s,onClick:()=>{var B;I(""),C(t&&ar(t)?"custom":"icons"),N(t&&!t.startsWith(jn)&&ar(t)?t:""),x(!0),(B=y.current)==null||B.showModal()}})}),f.jsx(V.chakra.dialog,{ref:y,"aria-label":r?"Choose edge icon":"Choose node icon",css:fr(Ae(l),Ae(u)),onClose:()=>{x(!1),o==null||o(!1),v.current++,ie(!1)},onClick:B=>{B.stopPropagation(),B.target===B.currentTarget&&B.currentTarget.close()},onKeyDown:B=>B.stopPropagation(),style:{margin:"auto",padding:12,width:336,maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",borderRadius:30,background:Ae(l),color:Ae(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:r?"Edge icon":"Node icon"}),f.jsxs("div",{style:{display:"flex",alignItems:"center",marginLeft:"auto",gap:4},children:[t&&f.jsx(Ue,{label:"Remove icon",children:f.jsx(Me,{"aria-label":r?"Remove edge icon":"Remove node icon",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:s||K,onClick:()=>se("")})}),f.jsx(Jr,{"aria-label":"Close icon picker",onClick:()=>{var B;return(B=y.current)==null?void 0:B.close()}})]})]}),f.jsxs(V.Tabs.Root,{value:w,onValueChange:({value:B})=>{C(B),I("")},display:"contents",css:{"--indicator-thickness":"1px"},children:[f.jsx(V.Tabs.List,{"aria-label":"Icon source",width:"100%",borderBottomWidth:0,children:["icons","custom"].map(B=>f.jsx(V.Tabs.Trigger,{value:B,flex:1,minW:0,justifyContent:"center",px:3,py:2,fontSize:"13px",_selected:{color:a,borderColor:m,"--indicator-color":m},children:B==="icons"?"React icons":"Custom SVG"},B))}),f.jsx("input",{ref:g,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:K||s,onChange:async B=>{var ce;const le=(ce=B.target.files)==null?void 0:ce[0];if(B.target.value="",!le)return;const Y=++v.current;ie(!0),I("");try{const ue=await pw(le);Y===v.current&&se(ue)}catch(ue){Y===v.current&&I(ue instanceof Error?ue.message:"Unable to read SVG.")}finally{Y===v.current&&ie(!1)}}}),f.jsx(V.Tabs.Content,{value:w,p:0,style:{display:"grid",gap:8},children:w==="icons"?f.jsxs(f.Fragment,{children:[f.jsx("input",{"aria-label":"Search icons",placeholder:"Search icons...",value:O,onChange:B=>{A(B.target.value),M(0)},style:W}),f.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[D.map(B=>f.jsx("button",{type:"button","aria-label":`Choose ${B}`,"aria-pressed":t===B,title:B,onClick:()=>se(B),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${t===B?2:1}px solid ${Ae(t===B?a:u)}`,background:Ae(t===B?l:d),color:"inherit",cursor:"pointer"},children:f.jsx(Zt,{name:B,size:24})},B)),D.length===0&&f.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:P==="loading"?"Loading icons...":P==="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:[te.length," icons · ",F+1," / ",ve]}),f.jsxs("div",{style:{display:"flex",gap:4},children:[f.jsx(Ue,{label:"Previous icons",children:f.jsx(Me,{"aria-label":"Previous icons",icon:f.jsx(Z.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:F===0,onClick:()=>M(F-1)})}),f.jsx(Ue,{label:"Next icons",children:f.jsx(Me,{"aria-label":"Next icons",icon:f.jsx(Z.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:F+1>=ve,onClick:()=>M(F+1)})})]})]})]}):f.jsxs(f.Fragment,{children:[t&&ar(t)&&f.jsx(Zt,{name:t,size:64}),f.jsxs("button",{type:"button",disabled:K||s,onClick:()=>{var B;return(B=g.current)==null?void 0:B.click()},style:{...W,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[f.jsx(Z.PiUploadSimple,{}),K?"Uploading...":"Upload SVG"]}),f.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:B=>{B.preventDefault(),!(K||s)&&(!ar(T.trim())||T.trim().startsWith(jn)?I("Enter an HTTP or HTTPS image URL."):se(T.trim()))},children:[f.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:T,disabled:K||s,onChange:B=>N(B.target.value),style:{...W,flex:1,minWidth:0}}),f.jsx(Ue,{label:"Apply URL",children:f.jsx(Me,{type:"submit","aria-label":"Apply URL",icon:f.jsx(Z.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:K||s||!T.trim(),style:{flexShrink:0}})})]})]})})]}),$&&f.jsx("div",{role:"alert",style:{fontSize:13},children:$})]})})]})}const to=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500",Kr],pb=["gray.900",Kr,"gray.600","gray.200","white"];function gb(){const{config:e}=Ze(),r=e.selectionToolbar||{},t=new Set(r.hide||[]);return{palette:r.palette||to,show:n=>!t.has(n)}}function jt(){const{border:e}=at();return f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:e})}function Br({value:e,placeholder:r,ariaLabel:t,width:n="140px",type:o="text",min:i,onCommit:s}){const{colorText:a}=at(),[c,l]=_.useState(e),d=_.useRef(!1);_.useEffect(()=>l(e),[e]);const u=()=>{if(d.current)return;d.current=!0;const h=c.trim();if(o==="number"&&h!==""&&(!Number.isFinite(Number(h))||Number(h)<(i??0))){l(e);return}h!==e&&s(h)};return f.jsx(V.Input,{"aria-label":t,type:o,min:i,size:"xs",fontSize:"16px",w:n,value:c,placeholder:r,color:a,borderWidth:0,_focusVisible:{boxShadow:"none",outline:"none"},borderRadius:"8px",onFocus:()=>{d.current=!1},onChange:h=>l(h.target.value),onBlur:u,onKeyDown:h=>{h.key==="Enter"&&(u(),h.target.blur()),h.key==="Escape"&&(d.current=!0,l(e),h.target.blur())}})}function kr({colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:s,colorText:a}=at(),[c,l]=_.useState(!1),d=_.useId(),u=_.useRef(null),h=r??e[0]??"transparent",p=ao(f.jsx(kr,{colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i}));return f.jsx(Gr.Provider,{value:null,children:f.jsxs(V.HStack,{gap:1,"aria-label":t,role:"group",onClickCapture:p,onKeyDown:m=>{var y;m.key==="Escape"&&(l(!1),(y=u.current)==null||y.focus())},children:[f.jsx(Ue,{label:`${t}: ${h}`,children:f.jsx(V.chakra.button,{ref:u,type:"button","aria-label":`${t} colors`,"aria-expanded":c,"aria-controls":d,w:4,h:4,flexShrink:0,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Ae(h),...h==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${Ae(a)}`,outlineOffset:"1px",onClick:()=>l(m=>!m)})}),c&&f.jsxs(V.HStack,{id:d,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(m=>{const y=r===m;return f.jsx(Ue,{label:`${t}: ${m}`,children:f.jsx(V.Box,{as:"button","aria-label":`${t} ${m}`,"aria-pressed":y,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Ae(m),...m==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:y?`2px solid ${Ae(a)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>n(m),onDoubleClick:g=>{var v;g.stopPropagation(),l(!1),(v=u.current)==null||v.focus()}})},m)}),o&&f.jsx(Ue,{label:`Reset ${t.toLowerCase()}`,children:f.jsx(Me,{"aria-label":`Reset ${t}`,icon:f.jsx(V.Icon,{as:Z.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:s,onClick:()=>{var m;o(),l(!1),(m=u.current)==null||m.focus()}})})]})]})})}function yb({edgeId:e,onClose:r}){var p;const{callbacks:t,themeColor:n,config:o}=Ze(),{colorInactive:i}=at(),{edgeById:s}=yr(),{palette:a,show:c}=gb(),l=(p=s.get(e))==null?void 0:p.data,d=[...new Set(["rounded-orthogonal","orthogonal","straight","bezier",...Object.keys(o.customEdgeTypes??{}),...l!=null&&l.type?[l.type]:[]])],u=l!=null&&l.isEdgeAnimated?"animated":l!=null&&l.isEdgeDashed?"dashed":"solid",h=[{key:"solid",icon:Z.PiLineSegment,label:"Solid"},{key:"dashed",icon:Z.PiLineSegments,label:"Dashed"},{key:"animated",icon:Z.PiFastForward,label:"Animated"}];return f.jsxs(f.Fragment,{children:[f.jsx(Jr,{onClick:r}),c("label")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Br,{ariaLabel:"Edge label",placeholder:"Edge label",value:(l==null?void 0:l.label)||"",onCommit:m=>{var y;return(y=t.onEdgeLabelChange)==null?void 0:y.call(t,e,m)}})]}),c("style")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),h.map(m=>f.jsx(Ue,{label:m.label,children:f.jsx(Me,{"aria-label":`Edge style ${m.key}`,"aria-pressed":u===m.key,icon:f.jsx(V.Icon,{as:m.icon,boxSize:5}),size:"sm",variant:"ghost",color:u===m.key?n:i,onClick:()=>{var y;return(y=t.onEdgeStyleChange)==null?void 0:y.call(t,e,m.key)}})},m.key)),u==="animated"&&f.jsx(hb,{label:"Edge animation",value:(l==null?void 0:l.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:o.readOnly,onChange:m=>{var y;return(y=t.onEdgeAnimationVariantChange)==null?void 0:y.call(t,e,m)}}),f.jsxs(Pt,{"aria-label":"Edge shape",title:`Edge shape: ${(l==null?void 0:l.type)??"Default"}`,icon:f.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:(l==null?void 0:l.type)??"",disabled:o.readOnly,onValueChange:m=>{var y;return(y=t.onEdgeTypeChange)==null?void 0:y.call(t,e,m||void 0)},children:[f.jsx("option",{value:"",children:"Default"}),d.map(m=>f.jsx("option",{value:m,children:m},m))]})]}),c("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Td,{edgeId:e,value:l==null?void 0:l.icon},e),f.jsx(Br,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(l==null?void 0:l.icon)??"",onCommit:m=>{var y;return(y=t.onEdgeIconChange)==null?void 0:y.call(t,e,m)}})]}),c("color")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(kr,{label:"Edge color",colors:a,value:l==null?void 0:l.color,onPick:m=>{var y;return(y=t.onEdgeColorChange)==null?void 0:y.call(t,e,m)},onReset:()=>{var m;return(m=t.onEdgeColorChange)==null?void 0:m.call(t,e,"")}})]}),c("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Ue,{label:"Delete edge",children:f.jsx(Me,{"aria-label":"Delete edge",icon:f.jsx(V.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var m;(m=t.onEdgeDelete)==null||m.call(t,e,l),r()}})})]})]})}function mb({ids:e,showDivider:r=!0}){const{callbacks:t,config:n,nodeGridOptions:o,fillRadiusEditedIds:i,setNodeRadiusPreview:s}=Ze(),{colorInactive:a}=at(),{nodeById:c}=yr(),[l,d]=_.useState(),u=_.useRef(),h=_.useRef(),p=_.useRef({callbacks:t,readOnly:n.readOnly,nodeById:c});p.current={callbacks:t,readOnly:n.readOnly,nodeById:c};const m=()=>{var C,S;clearTimeout(h.current);const w=u.current;if(u.current=void 0,!!w){if(!p.current.readOnly)for(const j of w.ids)p.current.nodeById.has(j)&&((S=(C=p.current.callbacks).onNodeBorderRadiusChange)==null||S.call(C,j,w.radius));s(w.ids,void 0),d(void 0)}},y=_.useRef(m);y.current=m,_.useEffect(()=>{const w=()=>y.current();return window.addEventListener("pagehide",w),()=>{window.removeEventListener("pagehide",w),w()}},[]);const g=e.map(w=>{var C,S;return o!=null&&o.fill&&!i.has(w)?0:(S=(C=c.get(w))==null?void 0:C.data.viewProps)==null?void 0:S.borderRadius}),v=!g.every(w=>w===g[0]),b=l??g[0]??0,x=w=>{n.readOnly||(w!==void 0&&e.every(C=>{var S;return((S=c.get(C))==null?void 0:S.data.type)==="grid"})?(d(w),s(e,w),u.current={ids:[...e],radius:w},clearTimeout(h.current),h.current=setTimeout(m,150)):(clearTimeout(h.current),u.current=void 0,d(void 0),s(e,void 0),e.forEach(C=>{var S;return(S=t.onNodeBorderRadiusChange)==null?void 0:S.call(t,C,w)})))};return f.jsxs(f.Fragment,{children:[r&&f.jsx(jt,{}),f.jsx(V.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:f.jsx(Pt,{icon:f.jsx(V.Icon,{as:gx.TbBorderRadius,boxSize:5,color:a,"aria-hidden":"true"}),"aria-label":"Node border radius",title:`Border radius: ${v?"Mixed":g[0]===void 0?"Default":`${g[0]}px`}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",cursor:"pointer"},value:"radius",disabled:n.readOnly,onValueChange:()=>{},popupContent:f.jsxs(f.Fragment,{children:[f.jsx(dd,{label:"Border radius",inputLabel:"Node corner radius",min:0,max:Math.max(500,...g.map(w=>w??0)),step:1,value:b,displayValue:l!==void 0?`${l}px`:v?"Mixed":g[0]===void 0?"Default":`${b}px`,onChange:x,onChangeEnd:m}),f.jsx(Ue,{label:"Reset border radius",children:f.jsx(Me,{"aria-label":"Reset border radius",icon:f.jsx(Z.PiEraser,{size:20}),size:"sm",variant:"ghost",color:a,disabled:n.readOnly,onClick:()=>x(void 0)})})]}),children:f.jsx("option",{value:"radius",children:"Border radius"})})})]})}function bb({ids:e,onClose:r,afterLabel:t}){var le,Y,ce,ue,xe,Ce,ye,pe;const{callbacks:n,colorMode:o,themeColor:i,config:s,setNodeViewMode:a,nodeViewModes:c}=Ze(),{colorText:l,colorInactive:d}=at(),{nodeById:u,parentIds:h}=yr(),{palette:p,show:m}=gb(),y=e.length===1,[g,v]=_.useState(""),b=y?(le=u.get(e[0]))==null?void 0:le.data:void 0,x=e.map(X=>{var H,fe,be,Ne,Le,Be;const L=(H=u.get(X))==null?void 0:H.data,ae=((fe=L==null?void 0:L.config)==null?void 0:fe.typeView)??"";return ae==="object"&&((be=L==null?void 0:L.config)==null?void 0:be.content)!==void 0&&c[X]!=="properties"?"content":ae==="icon-label"&&((Ne=L==null?void 0:L.viewProps)==null?void 0:Ne.bgColor)==="transparent"&&((Le=L==null?void 0:L.viewProps)==null?void 0:Le.borderWidth)===0&&((Be=L==null?void 0:L.viewProps)==null?void 0:Be.outline)===!1?"media":ae}),w=x.some(X=>X!==x[0]),C=w?"mixed":x[0]??"",S=[{value:"text",label:"Text",view:"text",icon:Z.PiTextT},{value:"icon-label",label:"Icon Label",view:"icon-label",icon:Z.PiShapes},{value:"object",label:"Object",view:"object",icon:Z.PiBracketsCurly},{value:"grid",label:"Grid",view:"grid",icon:Z.PiGridFour},{value:"parent",label:"Parent",view:"parent",icon:Z.PiStack},{value:"media",label:"Media",view:"icon-label",icon:Z.PiFileSvg},{value:"content",label:"Content",view:"object",icon:Z.PiTextAlignLeft}],j=e.some(X=>{var ae,H,fe,be;const L=(ae=u.get(X))==null?void 0:ae.data;return L&&((H=L.config)==null?void 0:H.typeView)!=="grid"&&((fe=L.config)==null?void 0:fe.typeView)!=="parent"&&(h.has(X)||((be=L.config)==null?void 0:be.parentContainer)||Object.prototype.hasOwnProperty.call(s.customViews??{},L.type))}),P=(Y=b==null?void 0:b.config)==null?void 0:Y.collapsed,E=fb(e[0]),O=X=>{var L,ae,H;return(((ae=(L=u.get(X))==null?void 0:L.data.viewProps)==null?void 0:ae.outline)??(h.has(X)?(H=s.parentNodeStyle)==null?void 0:H.outline:!1))===!0},A=e.every(O),R=!A&&e.some(O),M=X=>{var L;return((L=u.get(X))==null?void 0:L.data.isNodeAnimated)===!0},T=e.every(M),N=!T&&e.some(M),$=e.map(X=>{var L;return((L=u.get(X))==null?void 0:L.data.nodeAnimationVariant)??"traveling"}),I=$.every(X=>X===$[0])?$[0]:"",K=X=>e.forEach(X),[ie,se]=_.useState(!1),te=ie&&m("color")&&m("borderColor"),me=X=>{var L,ae,H;return(((ae=(L=u.get(X))==null?void 0:L.data.viewProps)==null?void 0:ae.borderStyle)??(h.has(X)?(H=s.parentNodeStyle)==null?void 0:H.borderStyle:"solid"))==="dashed"},ve=e.every(me),F=!ve&&e.some(me),D=e.map(X=>{var H,fe,be;const L=(H=u.get(X))==null?void 0:H.data,ae=h.has(X)?Pn((fe=s.parentNodeStyle)==null?void 0:fe.borderWidth,6):(L==null?void 0:L.type)==="objectView"?3:2;return Pn((be=L==null?void 0:L.viewProps)==null?void 0:be.borderWidth,ae)}),W=D.every(X=>X===D[0])?String(D[0]??""):"",B=X=>K(L=>{var ae,H;te?(ae=n.onNodeBorderColorChange)==null||ae.call(n,L,X):(H=n.onNodeColorChange)==null||H.call(n,L,"bg",X)});return f.jsxs(f.Fragment,{children:[f.jsx(Jr,{onClick:r}),f.jsx(jt,{}),y&&m("label")?f.jsx(Br,{ariaLabel:"Node label",placeholder:"Node label",value:(b==null?void 0:b.label)??(b==null?void 0:b.headerTitle)??"",onCommit:X=>{var L;return(L=n.onNodeLabelChange)==null?void 0:L.call(n,e[0],X)}}):f.jsxs(V.Text,{fontSize:"xs",color:l,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),t,m("typeView")&&f.jsxs(Pt,{"aria-label":"Type view",title:j?"Type view is managed by the custom renderer or container":`Type view: ${C||"None (default)"}`,icon:f.jsx(Z.PiCards,{size:20}),style:{width:36},value:C,disabled:s.readOnly||s.editable===!1||j,onValueChange:X=>{var ae;const L=(ae=S.find(H=>H.value===X))==null?void 0:ae.view;L&&K(H=>{var be,Ne,Le,Be,tt,Je,yt,Ye,nt,ht,Te,Ve,st;const fe=(be=u.get(H))==null?void 0:be.data;X==="media"?((Ne=n.onNodeColorChange)==null||Ne.call(n,H,"bg","transparent"),(Le=n.onNodeBorderColorChange)==null||Le.call(n,H,"#00000000"),(Be=n.onNodeBorderWidthChange)==null||Be.call(n,H,0),(tt=n.onNodeOutlineChange)==null||tt.call(n,H,!1)):x[e.indexOf(H)]==="media"&&((Je=n.onNodeColorChange)==null||Je.call(n,H,"bg",""),(yt=n.onNodeBorderColorChange)==null||yt.call(n,H,""),(Ye=n.onNodeBorderWidthChange)==null||Ye.call(n,H,void 0)),X==="content"&&((nt=fe==null?void 0:fe.config)==null?void 0:nt.content)===void 0&&((ht=n.onNodeContentChange)==null||ht.call(n,H,"")),(Te=n.onNodeTypeViewChange)==null||Te.call(n,H,L),a(H,X==="object"&&((Ve=fe==null?void 0:fe.config)==null?void 0:Ve.content)!==void 0?"properties":"default"),(st=n.onNodeViewToggle)==null||st.call(n,H)})},children:[w&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),S.map(X=>f.jsx("option",{value:X.value,children:f.jsxs(V.HStack,{gap:"12px",children:[f.jsx(X.icon,{size:20,"aria-hidden":"true",style:{flexShrink:0}}),f.jsx("span",{children:X.label})]})},X.value))]}),m("style")&&f.jsx(mb,{ids:e},e.join("\0")),m("outline")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Ue,{label:A?"Restore node fill":"Remove node fill",children:f.jsx(Me,{"aria-label":"Toggle node outline","aria-pressed":R?"mixed":A,icon:f.jsx(V.Icon,{as:A?Z.PiSquare:Z.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:A?i:d,onClick:()=>K(X=>{var L;return(L=n.onNodeOutlineChange)==null?void 0:L.call(n,X,!A)})})})]}),m("color")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),m("borderColor")&&f.jsx(Ue,{label:te?"Edit node colors":"Edit node border",children:f.jsx(Me,{"aria-label":"Edit node border","aria-pressed":te,icon:f.jsx(V.Icon,{as:Z.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:te?i:d,bg:te?o==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>se(X=>!X)})}),f.jsx(kr,{label:te?"Border color":"Background",colors:p,value:te?((ce=b==null?void 0:b.viewProps)==null?void 0:ce.borderColor)??(y&&h.has(e[0])?(ue=s.parentNodeStyle)==null?void 0:ue.borderColor:void 0):(xe=b==null?void 0:b.viewProps)==null?void 0:xe.bgColor,onPick:B,onReset:()=>B("")}),te&&m("style")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Ue,{label:ve?"Solid border":"Dashed border",children:f.jsx(Me,{"aria-label":"Toggle dashed border","aria-pressed":F?"mixed":ve,icon:f.jsx(V.Icon,{as:ve?Z.PiLineSegments:Z.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:ve?i:d,onClick:()=>K(X=>{var L;return(L=n.onNodeBorderStyleChange)==null?void 0:L.call(n,X,ve?"solid":"dashed")})})}),f.jsx(Br,{ariaLabel:"Border thickness",placeholder:y?"Auto":"Mixed",width:"64px",type:"number",min:0,value:W,onCommit:X=>K(L=>{var ae;return(ae=n.onNodeBorderWidthChange)==null?void 0:ae.call(n,L,X===""?void 0:Number(X))})})]})]}),m("animation")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Ue,{label:T?"Stop border animation":"Animate node border",children:f.jsx(Me,{"aria-label":"Toggle node animation","aria-pressed":N?"mixed":T,icon:f.jsx(V.Icon,{as:Z.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:T?i:d,onClick:()=>K(X=>{var L;return(L=n.onNodeAnimationChange)==null?void 0:L.call(n,X,!T)})})}),(T||N)&&f.jsx(hb,{label:"Node animation",value:I,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:s.readOnly,onChange:X=>K(L=>{var ae;return(ae=n.onNodeAnimationVariantChange)==null?void 0:ae.call(n,L,X)})})]}),!te&&m("textColor")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(kr,{label:"Text color",colors:pb,value:(Ce=b==null?void 0:b.viewProps)==null?void 0:Ce.textColor,onPick:X=>K(L=>{var ae;return(ae=n.onNodeColorChange)==null?void 0:ae.call(n,L,"text",X)}),onReset:()=>K(X=>{var L;return(L=n.onNodeColorChange)==null?void 0:L.call(n,X,"text","")})})]}),y&&m("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Td,{nodeId:e[0],value:(ye=b==null?void 0:b.config)==null?void 0:ye.icon},e[0]),f.jsx(Br,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((pe=b==null?void 0:b.config)==null?void 0:pe.icon)||"",onCommit:X=>{var L;return(L=n.onNodeIconChange)==null?void 0:L.call(n,e[0],X)}})]}),y&&E&&m("collapse")&&P!==void 0&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Ue,{label:P?"Expand":"Collapse",children:f.jsx(Me,{"aria-label":P?"Expand node":"Collapse node",icon:f.jsx(V.Icon,{as:P?Z.PiArrowsOutLineVertical:Z.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:d,onClick:()=>{var X;return(X=n.onNodeCollapse)==null?void 0:X.call(n,e[0],!P)}})})]}),m("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Ue,{label:y?"Delete node":`Delete ${e.length} nodes`,children:f.jsx(Me,{"aria-label":"Delete selected nodes",icon:f.jsx(V.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:o==="dark"?"red.300":"red.500",onClick:()=>{K(X=>{var L,ae;return(ae=n.onNodeDelete)==null?void 0:ae.call(n,X,((L=u.get(X))==null?void 0:L.data)||{id:X})}),r()}})})]}),f.jsx(jt,{}),f.jsx(Ue,{label:"Copy selection",children:f.jsx(Me,{"aria-label":"Copy selection",icon:f.jsx(Z.PiCopy,{size:20}),size:"sm",variant:"ghost",color:d,onClick:async()=>{var X;try{await((X=n.onNodesCopy)==null?void 0:X.call(n,e)),v("")}catch(L){v(String(L))}}})}),f.jsx(Ue,{label:"Duplicate selection",children:f.jsx(Me,{"aria-label":"Duplicate selection",icon:f.jsx(Z.PiCopySimple,{size:20}),size:"sm",variant:"ghost",color:d,disabled:s.readOnly||s.editable===!1,onClick:()=>{var X;try{(X=n.onNodesDuplicate)==null||X.call(n,e),v("")}catch(L){v(String(L))}}})}),g&&f.jsx(V.Text,{role:"alert",fontSize:"xs",children:g})]})}async function vb(e){const{toSvg:r}=await Promise.resolve().then(()=>require("./index-sHQXTNv9.cjs"));await document.fonts.ready;const t=await r(e,{filter:o=>!(o instanceof Element)||!o.matches("button, iframe, [role=tooltip], .flow-sdk-handle, .flow-sdk-property-port, .flow-sdk-edge-hit, .flow-sdk-ghost, .flow-sdk-node-animation")}),n=new DOMParser().parseFromString(decodeURIComponent(t.slice(t.indexOf(",")+1)),"image/svg+xml");return n.querySelectorAll(".flow-sdk-edge-hit, .flow-sdk-handle, .flow-sdk-property-port, .flow-sdk-ghost").forEach(o=>o.remove()),n.querySelectorAll("[data-flow-preview-source]").forEach(o=>{o.setAttribute("style","display:block;white-space:pre-wrap;font:16px/1.5 monospace;overflow-wrap:anywhere")}),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(n))}`}async function xb(e,r="squeed.svg"){const t=document.createElement("a");t.href=await vb(e),t.download=r.endsWith(".svg")?r:`${r}.svg`,t.click()}function wb(){const{themeColor:e}=Ze(),[r,t]=_.useState(!1),[n,o]=_.useState("");return f.jsxs(f.Fragment,{children:[f.jsx(Ue,{label:"Download SVG (current view)",children:f.jsx(Me,{"aria-label":"Download SVG",icon:f.jsx(Z.PiDownloadSimpleFill,{size:20}),disabled:r,borderRadius:"30%",color:e,variant:"ghost",onClick:async i=>{var a;const s=(a=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:a.querySelector("[data-flow-background]");if(!s){o("Diagram not available for export.");return}t(!0),o("");try{await xb(s)}catch(c){o(c instanceof Error?c.message:"Unable to export SVG.")}finally{t(!1)}}})}),n&&f.jsx("span",{role:"alert",style:{fontSize:12,maxWidth:220},children:n})]})}function Od({children:e,background:r,border:t,endElement:n,startElement:o,startElementWidth:i=44,framed:s=!0}){const a=_.useRef(null),[c,l]=_.useState({left:!1,right:!1});_.useLayoutEffect(()=>{const u=a.current;let h=u.parentElement.offsetWidth;const p=()=>{const g=u.parentElement.offsetWidth;if(g>0&&g!==h){const x=h/g;h=g,x>0&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches&&u.parentElement.animate({transform:[`scaleX(${x})`,"scaleX(1)"],transformOrigin:[n?"right center":"left center",n?"right center":"left center"]},{duration:180,easing:"ease-out",id:"flow-toolbar-grow"})}const v=u.scrollLeft>1,b=u.scrollWidth-u.clientWidth-u.scrollLeft>1;l(x=>x.left===v&&x.right===b?x:{left:v,right:b})},m=g=>{if(g.defaultPrevented||g.ctrlKey||s&&g.deltaX!==0||!(g.deltaX||g.deltaY)||u.scrollWidth<=u.clientWidth)return;g.preventDefault();const v=g.deltaMode===WheelEvent.DOM_DELTA_LINE?16:g.deltaMode===WheelEvent.DOM_DELTA_PAGE?u.clientWidth:1;u.scrollLeft+=(g.deltaX||g.deltaY)*v},y=new ResizeObserver(p);return y.observe(u),u.firstElementChild&&y.observe(u.firstElementChild),u.addEventListener("scroll",p,{passive:!0}),u.addEventListener("wheel",m,{passive:!1}),p(),()=>{y.disconnect(),u.removeEventListener("scroll",p),u.removeEventListener("wheel",m)}},[]);const d=`var(--chakra-colors-${r.replace(".","-")})`;return f.jsxs(V.Box,{position:"relative",bg:s?r:"transparent",minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:s?"30px":0,css:{...s?fr(d,`var(--chakra-colors-${t.replace(".","-")})`):{},...s||o?{"--flow-toolbar-start-width":o?`${i}px`:"0px"}:{}},children:[f.jsx(V.Box,{ref:a,"data-flow-toolbar-scroll":"",h:50,minH:50,alignContent:"center",overflowX:"auto",overflowY:"hidden",mr:n?"44px":void 0,ml:o?`${i}px`:void 0,borderRadius:"inherit",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e}),["left","right"].map(u=>f.jsx(V.Box,{"data-flow-toolbar-fade":u,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",borderRadius:u==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[u]:u==="right"&&n?44:u==="left"&&o?i:0,opacity:c[u]?1:0,background:`linear-gradient(to ${u==="left"?"right":"left"}, ${d}, transparent)`}},u)),n&&f.jsx(V.Box,{position:"absolute",right:"6px",top:0,h:"50px",w:"32px",display:"flex",alignItems:"center",justifyContent:"center",children:n}),o&&f.jsx(V.Box,{position:"absolute",left:"6px",top:0,h:"50px",w:`${i-12}px`,display:"flex",alignItems:"center",justifyContent:"center",children:o})]})}async function _w(e,r){const t=new Set,n=[],o=(a,c)=>{var d,u,h;if(!a||typeof a!="object")return;const l=a;n.push(c),typeof((d=l.$form)==null?void 0:d.$type)=="string"&&t.add(l.$form.$type),typeof((h=(u=l.$form)==null?void 0:u.$create)==null?void 0:h.$type)=="string"&&t.add(l.$form.$create.$type);for(const[p,m]of Object.entries(l))p==="$"?o(m,c):p.startsWith("$")||o(m,`${c}.${p}`)};if(o(r,"root"),!t.size)return{contract:await cb(e)};const i=await Id(e,[...t]);for(const a of t)if(!Object.prototype.hasOwnProperty.call(i,a))throw new Error(`Missing form type: ${a}`);const s={};for(const a of n){const c=Zr(r,a,i);c&&(s[a]={type:c.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:s}}}function Cb({message:e,onDismiss:r}){const{background:t,colorText:n,border:o}=at();return!e||typeof document>"u"?null:Dr.createPortal(f.jsxs(V.chakra.div,{role:"alert","aria-atomic":"true",css:fr(Ae(t),Ae(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:Ae(t),color:Ae(n),fontSize:14,lineHeight:1.5},children:[f.jsx(Z.PiWarningCircle,{size:20,"aria-hidden":"true",style:{flexShrink:0,color:"#ef4444"}}),f.jsxs("div",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:[f.jsx("strong",{children:"Interface upload failed"}),f.jsx("div",{children:e})]}),f.jsx(Jr,{type:"button","aria-label":"Dismiss upload error",title:"Dismiss upload error",onClick:r,flexShrink:0,width:"24px",height:"24px",minWidth:"24px",padding:0})]}),document.body)}function Nd({showDivider:e=!0,compact:r=!1}={}){const{edgeMode:t,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:s,readOnly:a,themeColor:c,colorMode:l}=Ze(),{edgeById:d}=yr(),{data:u,schema:h,setSchema:p,bindings:m,structured:y}=_.useContext(Mt),g=(y==null?void 0:y.sourceBindings)??m,v=(y==null?void 0:y.sourceSchema)??h,{colorText:b}=at(),x=_.useRef(null),w=_.useRef(0),[C,S]=_.useState(!1),[j,P]=_.useState("");_.useEffect(()=>()=>{w.current++},[]),_.useEffect(()=>{w.current++,S(!1)},[a,u,g]);const E=o?[...d.values()].filter(R=>Pd(o,R.data)).length:0,O=o?`${o.name}: ${v?`${Object.keys(v).length} form types loaded; `:""}${E} invalid or unverified connections`:"",A=ao(f.jsx(Nd,{showDivider:!1,compact:!0}));return f.jsx(Gr.Provider,{value:null,children:f.jsxs("span",{style:{display:"contents"},onClickCapture:A,children:[f.jsx(Cb,{message:j,onDismiss:()=>P("")}),e&&f.jsx(bn,{}),f.jsxs(Pt,{"aria-label":"Edge mode",title:t==="auto"?"Connections: Auto":t==="properties"?"Connections: Properties":"Connections: Nodes",icon:t==="auto"?f.jsx(Z.PiGraph,{size:20}):t==="properties"?f.jsx(Z.PiTable,{size:20}):f.jsx(Z.PiTreeStructure,{size:20}),style:{width:36},value:t,disabled:a,footer:s.onWorkflowConfigurationOpen&&f.jsxs(f.Fragment,{children:[f.jsx("hr",{style:{border:0,borderTop:"1px solid currentColor",opacity:.2,margin:"8px 0"}}),f.jsxs(V.Button,{"data-flow-menu-action":"",variant:"ghost",width:"100%",justifyContent:"flex-start",color:"inherit",bg:"transparent",css:eo,_hover:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},onClick:R=>{var M,T;(M=R.currentTarget.closest("[popover]"))==null||M.hidePopover(),(T=s.onWorkflowConfigurationOpen)==null||T.call(s)},children:[f.jsx(Z.PiGear,{}),"Configuration"]})]}),onValueChange:R=>{var T;const M=R==="auto"?"auto":R==="properties"?"properties":"nodes";n(M),(T=s.onEdgeModeChange)==null||T.call(s,M)},children:[f.jsx("option",{value:"auto",children:"Auto"}),f.jsx("option",{value:"nodes",children:"Nodes"}),f.jsx("option",{value:"properties",children:"Properties"})]}),f.jsxs("span",{style:{display:t==="auto"||t==="properties"?"contents":"none"},children:[f.jsx(Ue,{label:o?`Replace ${o.name}`:"Upload workflow interface",children:f.jsx(Me,{"aria-label":"Upload workflow interface",icon:f.jsx(Z.PiUploadSimple,{size:20}),color:Ae(c),size:"sm",variant:"ghost",disabled:C||a,onClick:()=>{var R;return(R=x.current)==null?void 0:R.click()}})}),f.jsx("input",{ref:x,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:a||C,onChange:async R=>{var N,$;const M=(N=R.target.files)==null?void 0:N[0];if(R.target.value="",!M)return;const T=++w.current;S(!0),P("");try{const I=g?await Id(M,[...new Set(Object.values(g).map(se=>se.schemaType??se.type))]):void 0;if(g&&I){for(const se of Object.values(g))if(!Object.prototype.hasOwnProperty.call(I,se.schemaType??se.type))throw new Error(`Missing form type: ${se.schemaType??se.type}`)}const{contract:K,schema:ie}=g&&I?{schema:I,contract:{name:M.name,nodes:Object.fromEntries(Object.entries(g).map(([se,te])=>[se,{type:I[te.schemaType??te.type],optional:!1}]))}}:await _w(M,u);if(T!==w.current)return;p==null||p(ie),i(K),($=s.onWorkflowContractChange)==null||$.call(s,K)}catch(I){T===w.current&&P(`${M.name}: ${I instanceof Error?I.message:"Unable to load interface."}`)}finally{T===w.current&&S(!1)}}}),!r&&(O||C)&&f.jsx("span",{role:"status",title:O,style:{color:Ae(b),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:C?"Loading interface...":O}),!r&&o&&f.jsx(Ue,{label:"Remove workflow interface",children:f.jsx(Me,{"aria-label":"Remove workflow interface",icon:f.jsx(Z.PiX,{size:16}),size:"sm",variant:"ghost",disabled:a||C,onClick:()=>{var R;p==null||p(void 0),i(void 0),(R=s.onWorkflowContractChange)==null||R.call(s,void 0),P("")}})})]})]})})}const Ew=[{value:"BT",label:"Bottom to Up",icon:Z.PiArrowUp,flowType:un.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:Z.PiArrowDown,flowType:un.TOP_DOWN},{value:"LR",label:"Left to Right",icon:Z.PiArrowRight,flowType:un.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:Z.PiArrowLeft,flowType:un.RIGHT_LEFT}],Sb=({nodeGridControlsTarget:e}={})=>{const{engineRef:r,themeColor:t,setThemeColor:n,edgeColor:o,setEdgeColor:i,backgroundSelected:s,setBackgroundSelected:a,direction:c,edgeMode:l,allNodesIconLabel:d,setAllNodesIconLabel:u,nodeGridOptions:h,selectedNodeIds:p,setSelectedNodeIds:m,selectedEdgeId:y,setSelectedEdgeId:g,isZoomMode:v,setIsZoomMode:b,isMultiSelectMode:x,setIsMultiSelectMode:w,isDragMode:C,setIsDragMode:S,isEdgeHandlesEnabled:j,setIsEdgeHandlesEnabled:P,isArrayNodeMode:E,setIsArrayNodeMode:O,isPinned:A,setIsPinned:R,callbacks:M,config:T,readOnly:N}=Ze(),{nodeById:$,edgeById:I,parentIds:K}=yr(),ie=T.colorMode==="dark",{background:se,border:te,colorInactive:me,colorText:ve,colorActive:F}=at(),D=ie?te:"gray.300",W=`var(--chakra-colors-${se.replace(".","-")})`,B=`var(--chakra-colors-${(ie?te:"gray.300").replace(".","-")})`,[le,Y]=_.useState(!1),[ce,ue]=_.useState(!0),xe=T.bottomBarCollapsed??ce,Ce=_.useRef(null),ye=Sm({edge:"bottom",enabled:!A,bounds:Ce,inside:[Ce]}),pe=_.useCallback(Te=>{const Ve=r.current;if(!Ve)return;const st=T.minZoom??.01,ct=T.maxZoom??1.5,zt=.02;let Ge=Ve.zoom();switch(Te){case"increase":Ge=Math.min(ct,Ge+zt),Ve.zoom(Ge),Ve.center(!1);break;case"decrease":Ge=Math.max(st,Ge-zt),Ve.zoom(Ge),Ve.center(!1);break;case"reset":Ve.fit(50);break}},[r,T.minZoom,T.maxZoom]),X=T.renderSelectedNodeToolbar,L=p.length>0&&!!X,ae=_.useMemo(()=>L?p.map(Te=>{var st;return{...((st=$.get(Te))==null?void 0:st.data)??{id:Te},isParent:K.has(Te)}}):[],[L,p,$,K]),H=_.useCallback(()=>{var Te;m([]),(Te=M.onNodeDeselect)==null||Te.call(M)},[m,M]),fe=T.renderSelectedEdgeToolbar,be=!!y&&!!fe,Ne=_.useMemo(()=>{var Te;return!be||!y?null:((Te=I.get(y))==null?void 0:Te.data)??{id:y}},[be,y,I]),Le=_.useCallback(()=>{var Te;g(null),(Te=M.onEdgeDeselect)==null||Te.call(M)},[g,M]),Be=T.selectionToolbar!==!1&&!N,tt=Be&&!!y&&!fe,Je=Be&&!tt&&p.length>0&&!X,yt=tt||Je,Ye=A||ye||le||yt||T.bottomBarCollapsed===!1;_.useEffect(()=>{p.length||y?a(!1):N||(s&&R(!0),T.bottomBarCollapsed===void 0&&ue(!s))},[s,p.length,y,N,a,R,T.bottomBarCollapsed]);const nt=T.renderBottomBar,ht=ew();return nt?f.jsxs(f.Fragment,{children:[L&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:X({selectedNodeIds:p,selectedNodeData:ae,onDeselect:H})}),be&&Ne&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:fe({edgeId:y,edgeData:Ne,onDeselect:Le})}),f.jsx(V.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:nt({zoomIn:()=>pe("increase"),zoomOut:()=>pe("decrease"),resetZoom:()=>pe("reset"),direction:c,isZoomMode:v,setIsZoomMode:b,isMultiSelectMode:x,setIsMultiSelectMode:w,isDragMode:C,setIsDragMode:S,isEdgeHandlesEnabled:j,setIsEdgeHandlesEnabled:P,isArrayNodeMode:E,setIsArrayNodeMode:O,selectedNodeIds:p,selectedNodeData:ae,selectedEdgeId:y,selectedEdgeData:Ne,onNodeDeselect:H,onEdgeDeselect:Le,callbacks:M})})]}):f.jsxs(Gr.Provider,{value:ht,children:[L&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:X({selectedNodeIds:p,selectedNodeData:ae,onDeselect:H})}),be&&Ne&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:fe({edgeId:y,edgeData:Ne,onDeselect:Le})}),f.jsx(V.Box,{ref:Ce,role:"toolbar","aria-label":"Diagram controls",position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",transition:"opacity 0.3s ease-in, transform 0.3s ease",transform:Ye?"translateY(0)":"translateY(100%)",pointerEvents:Ye?"auto":"none",visibility:Ye?"visible":"hidden",opacity:Ye?1:0,css:{"& button > svg:not([popover] *)":{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",flexShrink:0},"@media (hover: none)":{visibility:"visible",opacity:1,transform:"none",pointerEvents:"auto"}},children:f.jsxs(V.Flex,{w:"100%",px:5,position:"absolute",bottom:"calc(20px + env(safe-area-inset-bottom, 0px))",flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:"24px",css:{"@media (min-width: 1024px)":{"& > :first-of-type":{maxWidth:"50vw"}}},children:[f.jsx(Od,{background:se,border:ie?te:"gray.300",children:f.jsxs(V.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[tt?f.jsx(yb,{edgeId:y,onClose:Le}):Je?f.jsx(bb,{ids:p,onClose:H}):null,f.jsxs("div",{style:{display:tt||Je?"none":"contents"},children:[f.jsxs("span",{style:{display:T.bottomBarNavigation===!1?"none":"contents"},children:[f.jsx(Ue,{label:A?"Unpin":"Pin",children:f.jsx(Me,{"aria-label":"Pin",icon:f.jsx(V.Icon,{as:A?Z.PiPushPinFill:Z.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:A?t:me,onClick:()=>{R(!A),Y(!1)}})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ue,{label:"Zoom Out",children:f.jsx(Me,{"aria-label":"Zoom out",rememberAction:!1,icon:f.jsx(V.Icon,{as:Z.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:ve,onClick:()=>pe("decrease")})}),f.jsx(Ue,{label:"Zoom In",children:f.jsx(Me,{"aria-label":"Zoom in",rememberAction:!1,icon:f.jsx(V.Icon,{as:Z.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:ve,onClick:()=>pe("increase")})}),f.jsx(Ue,{label:"Reset Zoom",children:f.jsx(Me,{"aria-label":"Reset zoom",rememberAction:!1,icon:f.jsx(V.Icon,{as:Z.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:ve,onClick:()=>pe("reset")})}),xe&&f.jsx(tw,{visibleActions:h?["Collision mode","Fill",...h.fill?["Grid adjustment"]:[]]:[],divider:f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"})})]}),f.jsxs("span",{style:{display:xe?"none":"contents"},children:[f.jsxs("span",{style:{display:T.bottomBarNavigation===!1?"none":"contents"},children:[T.edgeHandles!==!1&&f.jsx(Ue,{label:j?"Draw Mode On (V)":"Draw Mode Off (V)",children:f.jsx(Me,{"aria-label":"Toggle draw mode","aria-keyshortcuts":"V","aria-pressed":j,icon:f.jsx(V.Icon,{as:Z.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:j?t:me,onClick:()=>P(!j)})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ue,{label:v?"Zoom Mode (z)":"Pan Mode (z)",children:f.jsx(Me,{"aria-label":"Toggle zoom mode",icon:f.jsx(V.Icon,{as:v?Z.PiMagnifyingGlassPlus:Z.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:v?t:me,onClick:()=>b(!v)})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ue,{label:x?"Multi-Select On (m)":"Multi-Select Off (m)",children:f.jsx(Me,{"aria-label":"Toggle multi-select",icon:f.jsx(V.Icon,{as:Z.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:x?t:me,onClick:()=>w(!x)})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ue,{label:C?"Drag Mode On (d)":"Drag Mode Off (d)",children:f.jsx(Me,{"aria-label":"Toggle drag mode",icon:f.jsx(V.Icon,{as:Z.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:C?t:me,onClick:()=>S(!C)})})]}),T.bottomBarNavigation===!1&&(e===void 0?f.jsx(Fo,{}):e?Dr.createPortal(f.jsx(Fo,{}),e):null),T.bottomBarExtra&&f.jsxs(f.Fragment,{children:[T.bottomBarNavigation!==!1&&f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"}),T.bottomBarExtra]}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"}),f.jsx(Xm,{})]}),f.jsx("span",{style:{display:T.bottomBarNavigation===!1||xe&&!h?"none":"contents"},children:f.jsx(Fo,{})}),f.jsxs("span",{style:{display:xe?"none":"contents"},children:[f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"}),f.jsx(Lr,{label:"Collapse all",hideLabel:!0,checked:d,icon:f.jsx(V.Icon,{as:Z.PiArrowsInLineVertical,boxSize:5}),onChange:u}),l!=="properties"&&f.jsxs(f.Fragment,{children:[f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ue,{label:E?"Array Mode [ ]":"Set Mode { }",children:f.jsx(Me,{"aria-label":"Toggle array mode",icon:f.jsx(V.Icon,{as:E?Z.PiBracketsSquare:Z.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:E?t:me,onClick:()=>{var Ve;const Te=!E;O(Te),(Ve=M.onArrayModeChange)==null||Ve.call(M,Te)}})})]}),f.jsx(Nd,{}),!N&&f.jsxs("span",{style:{display:s?"contents":"none"},children:[f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(kr,{label:"Graph theme",colors:to,value:t,includeTransparent:!1,onPick:Te=>{var Ve;n(Te),(Ve=M.onThemeColorChange)==null||Ve.call(M,Te)}})]}),!N&&f.jsxs(f.Fragment,{children:[f.jsx(V.Icon,{as:Z.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"}),f.jsx(kr,{label:"Graph edge color",colors:to,value:o||(ie?"gray.500":Kr),onPick:i,onReset:()=>i("")}),f.jsx(V.Icon,{as:Z.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"})]}),f.jsx(Ym,{})]}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D}),f.jsx(Ue,{label:xe?"Expand toolbar":"Collapse toolbar",children:f.jsx(Me,{"aria-label":"Toggle toolbar collapse",rememberAction:!1,icon:f.jsx(V.Icon,{as:xe?Z.PiCaretRight:Z.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:me,onClick:()=>{var Te;T.bottomBarCollapsed===void 0&&ue(!xe),a(xe),(Te=M.onBottomBarCollapsedChange)==null||Te.call(M,!xe)}})}),!xe&&f.jsx(wb,{})]})]})}),!yt&&f.jsxs(V.Box,{position:"relative",ml:"auto",flexShrink:0,children:[f.jsx(V.Box,{"data-flow-direction-control":"",bg:se,borderRadius:"30px",h:50,css:fr(W,B),px:3,cursor:"pointer",onClick:()=>Y(!le),children:f.jsxs(V.Flex,{align:"center",h:"100%",children:[f.jsx(Ue,{label:"Flow Direction",children:f.jsx(Me,{"aria-label":"Direction",onClick:Te=>{Te.stopPropagation(),Y(!le)},icon:f.jsx(V.Icon,{as:Z.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:me})}),f.jsx(V.Text,{fontSize:"xs",textTransform:"uppercase !important",color:ie?"whiteAlpha.600":"blackAlpha.500",ml:1,children:c.toUpperCase()})]})}),le&&f.jsx(V.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:f.jsxs(V.Box,{bg:se,borderRadius:"30px",p:2,minW:"180px",css:fr(W,B),children:[Ew.map(Te=>f.jsxs(V.Flex,{align:"center",gap:3,px:3,py:2,css:eo,cursor:"pointer",_hover:{bg:ie?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ve;(Ve=M.onDirectionChange)==null||Ve.call(M,Te.value),Y(!1)},children:[f.jsx(V.Icon,{as:Te.icon,boxSize:5,color:ve}),f.jsx(V.Text,{fontSize:"sm",color:ve,flex:1,whiteSpace:"nowrap",children:Te.label}),c===Te.value&&f.jsx(V.Icon,{as:Z.PiCheck,boxSize:4,color:F})]},Te.value)),f.jsxs(V.Flex,{align:"center",gap:3,px:3,py:2,css:eo,cursor:"pointer",_hover:{bg:ie?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Te;(Te=M.onDirectionChange)==null||Te.call(M,"C"),Y(!1)},children:[f.jsx(V.Icon,{as:Z.PiAlignCenterHorizontal,boxSize:5,color:ve}),f.jsx(V.Text,{fontSize:"sm",color:ve,flex:1,whiteSpace:"nowrap",children:"Center"}),c==="C"&&f.jsx(V.Icon,{as:Z.PiCheck,boxSize:4,color:F})]})]})})]})]})})]})};Sb.displayName="BottomBar";const jb=_.memo(Sb);function kw({checked:e,onChange:r,disabled:t,label:n="Connected nodes"}){return f.jsx(Lr,{hideLabel:!0,label:n,helper:`${n}: isolate node and its connections`,checked:e,onChange:r,disabled:t,icon:f.jsx(V.Icon,{as:Z.PiGraph,boxSize:5})})}const Lu={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function _b(e,r){const t=new Map,n=(i,s)=>{if(Object.is(i,s))return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const a=Object.keys(i);return a.length===Object.keys(s).length&&a.every(c=>Object.prototype.hasOwnProperty.call(s,c)&&n(i[c],s[c]))},o=(i,s,a)=>{if(i===s)return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const c=new Set([...Object.keys(i),...Object.keys(s)]);for(const l of c)if(!n(i[l],s[l])){if(Object.prototype.hasOwnProperty.call(Lu,l)){if(typeof s[l]!="string"||!s[l])return!1;t.set(a,{...t.get(a),[Lu[l]]:s[l]})}else if(l.startsWith("$")&&l!=="$"||!o(i[l],s[l],l==="$"?a:`${a}.${l}`))return!1}return!0};if(o(e,r,"root"))return t}function Rw(e,r){return _b(e,r)!==void 0}function Aw(e,r,t){if(e===r)return t;const n=_b(e,r);if(!n)return;const o=new Set(t.nodes.map(i=>i.data.id));for(const i of n.keys())if(!o.has(i)||!qe(r,i))return;return{edges:t.edges,nodes:t.nodes.map(i=>{const s=n.get(i.data.id),a=qe(e,i.data.id),c=qe(r,i.data.id);return!s&&a===c?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(c,null,2)}:{},...s?{viewProps:{...i.data.viewProps,...s},config:{...i.data.config,...s}}:{}}}})}}function hd(e){return e.kind==="literal"?e.value:e.kind==="union"?hd(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,r])=>!r.optional).map(([r,t])=>[r,hd(t.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Eb(e,r,t){var g,v,b;const n=(g=qe(e,r))==null?void 0:g.$form,o=n==null?void 0:n.$create;if(!o)return;const i=o.$address.split(".");if(i.shift()!=="root"||!i.length||i.some(x=>!/^[A-Za-z0-9_-]+$/.test(x)||["__proto__","constructor","prototype"].includes(x)))throw new Error("Invalid form creation address.");if(!t||!Object.prototype.hasOwnProperty.call(t,o.$type))throw new Error(`Load form type: ${o.$type}`);const s=i.pop(),a=["root",...i].join("."),c=Zr(e,a,t),l=(v=c==null?void 0:c.type.properties[s])==null?void 0:v.type;if((l==null?void 0:l.kind)!=="array"||l.items.kind!=="object")throw new Error("Form creation must target an object-array field.");const d=t[o.$type],u=o.$defaults??{};for(const[x,w]of Object.entries(u))if(!Object.prototype.hasOwnProperty.call(d.properties,x)||Dt(d.properties[x].type,w,!d.properties[x].optional))throw new Error(`Invalid creation default: ${x}`);const h={...hd(d),...structuredClone(u)};((b=d.properties.id)==null?void 0:b.type.kind)==="string"&&(h.id=Cd());let p=e;const m=qe(e,o.$address);if(m===void 0)p=_t(e,a,x=>({...x,[s]:[]}));else if(!Array.isArray(m)&&!Array.isArray(m==null?void 0:m.$))throw new Error("Form creation destination is not an array.");const y=Ed(p,o.$address,{...h,$label:o.$label??o.$type,...o.$icon?{$icon:o.$icon}:{},$form:{$type:o.$type,$create:o}});return{address:y.address,json:kd(y.json,r,{target:y.address,label:o.$edgeLabel})}}function kb(e,r,t){var i;if(r==="root"||!qe(e,r)||!qe(e,t))throw new Error("The source or Parent no longer exists.");const n=new Set;let o=t;for(;o;){if(o===r||o.startsWith(`${r}.`)||n.has(o))throw new Error("A node cannot be moved inside itself or its descendants.");n.add(o);const s=(i=qe(e,o))==null?void 0:i.$parent;o=typeof s=="string"?s:o.includes(".")?o.slice(0,o.lastIndexOf(".")):void 0}return _d(_t(e,r,s=>({...s,$parent:t})),t,!1)}function Rb(e,r){const t=new Set(r.filter(a=>qe(e,a)!==void 0)),n=[],o=(a,c)=>{if(!(!a||typeof a!="object")){n.push([c,a]);for(const[l,d]of Object.entries(a))l.startsWith("$")||o(d,`${c}.${l}`)}};o(e,"root");const i=a=>[...t].some(c=>a===c||a.startsWith(`${c}.`));let s=!0;for(;s;){s=!1;for(const[a,c]of n)!i(a)&&typeof c.$parent=="string"&&i(c.$parent)&&(t.add(a),s=!0)}return[...t].filter(a=>![...t].some(c=>c!==a&&a.startsWith(`${c}.`)))}function $d(e,r){const t=Rb(e,r),n=new Map(t.map((a,c)=>[a,`root.node_${c+1}`])),o=a=>{const c=t.find(l=>a===l||a.startsWith(`${l}.`));return c?`${n.get(c)}${a.slice(c.length)}`:void 0},i=a=>{if(!(!a||typeof a!="object")){Array.isArray(a.$connections)&&(a.$connections=a.$connections.flatMap(c=>{const l=typeof c.target=="string"&&o(c.target);return l?[{...c,id:void 0,target:l}]:[]}));for(const c of["$parent","$target"])if(typeof a[c]=="string"){const l=o(a[c]);l?a[c]=l:delete a[c]}for(const[c,l]of Object.entries(a))c.startsWith("$")||i(l)}},s={$hideRoot:!0};return t.forEach((a,c)=>{const l=structuredClone(qe(e,a));i(l),s[`node_${c+1}`]=l}),s}function Ab(e,r){const t=$d(e,r),n=Object.keys(t).filter(a=>!a.startsWith("$")),o=new Map(n.map(a=>[a,`copy_${crypto.randomUUID()}`])),i=a=>{if(!a||typeof a!="object")return;const c=l=>{const d=l.split(".");return d[0]==="root"&&o.has(d[1])&&(d[1]=o.get(d[1])),d.join(".")};for(const l of a.$connections??[])l.target=c(l.target),l.id=crypto.randomUUID();for(const l of["$parent","$target"])typeof a[l]=="string"&&(a[l]=c(a[l]));for(const[l,d]of Object.entries(a))l.startsWith("$")||i(d)},s=Object.fromEntries(n.map(a=>{const c=t[a];return i(c),[o.get(a),c]}));return{json:_t(e,"root",a=>({...a,...s})),ids:[...o.values()].map(a=>`root.${a}`)}}function Pw(e,r){const t=o=>e&&typeof e=="object"&&o in e;let n=1;for(;t(`${r}_${n}`);)n++;return`${r}_${n}`}function Pb(e,r,t,n,o){const i=(a,c)=>{a!==e&&(e=a,n==null||n(a,c))},s=a=>{var l;const c=(l=r.find(d=>d.data.id===a))==null?void 0:l.data;return c&&{source:c.source,target:c.target,isInverted:c.isInverted,sourceProperty:c.sourceProperty,targetProperty:c.targetProperty,connection:c.connection}};return{...t,onNodeParentChange:(a,c)=>{var d;const l=kb(e,a,c);(d=t.onNodeParentChange)==null||d.call(t,a,c),i(l,{type:"nodeStyle",address:a,key:"$parent",value:c})},onNodesCopy:async a=>{var c;await((c=t.onNodesCopy)==null?void 0:c.call(t,a))!==!0&&await navigator.clipboard.writeText(JSON.stringify($d(e,a),null,2))},onNodesDuplicate:a=>{var l;if(((l=t.onNodesDuplicate)==null?void 0:l.call(t,a))===!0)return;const c=Ab(e,a);i(c.json,{type:"nodeCreate",address:c.ids[0]})},onFormChange:a=>{const c=qe(e,a.nodeAddress);if(!c||a.nodeId!==void 0&&c.id!==a.nodeId)throw new Error("This form node has moved. Retry the edit.");i(fo(e,a,t.onFormChange),{type:"form",address:a.address,value:a.value})},onNodeLabelChange:(a,c)=>{var l;(l=t.onNodeLabelChange)==null||l.call(t,a,c),i(Ct(e,a,"$label",c),{type:"nodeLabel",address:a,key:"$label",value:c})},onNodeSubtitleChange:(a,c)=>{var l;(l=t.onNodeSubtitleChange)==null||l.call(t,a,c),i(Ct(e,a,"$subtitle",c),{type:"nodeStyle",address:a,key:"$subtitle",value:c})},onNodeContentChange:(a,c)=>{var l;(l=t.onNodeContentChange)==null||l.call(t,a,c),i(Ct(e,a,"$content",c),{type:"nodeContent",address:a,key:"$content",value:c})},onNodeTypeViewChange:(a,c)=>{var l;c!==void 0&&!vd.includes(c)||((l=t.onNodeTypeViewChange)==null||l.call(t,a,c),i(Ct(e,a,"$view",c),{type:"nodeStyle",address:a,key:"$view",value:c}))},onNodeColorChange:(a,c,l)=>{var u;(u=t.onNodeColorChange)==null||u.call(t,a,c,l);const d=c==="bg"?"$bgColor":"$textColor";i(Ct(e,a,d,l),{type:"nodeColor",address:a,key:d,value:l})},onNodeBorderColorChange:(a,c)=>{var l;(l=t.onNodeBorderColorChange)==null||l.call(t,a,c),i(Ct(e,a,"$borderColor",c),{type:"nodeColor",address:a,key:"$borderColor",value:c})},onNodeBorderStyleChange:(a,c)=>{var l;(l=t.onNodeBorderStyleChange)==null||l.call(t,a,c),i(Ct(e,a,"$borderStyle",c),{type:"nodeStyle",address:a,key:"$borderStyle",value:c})},onNodeBorderWidthChange:(a,c)=>{var l;c!==void 0&&(!Number.isFinite(c)||c<0)||((l=t.onNodeBorderWidthChange)==null||l.call(t,a,c),i(Ct(e,a,"$borderWidth",c),{type:"nodeStyle",address:a,key:"$borderWidth",value:c}))},onNodeBorderRadiusChange:(a,c)=>{var l;c!==void 0&&(!Number.isFinite(c)||c<0)||((l=t.onNodeBorderRadiusChange)==null||l.call(t,a,c),i(Ct(e,a,"$borderRadius",c),{type:"nodeStyle",address:a,key:"$borderRadius",value:c}))},onNodeIconChange:(a,c)=>{var l;(l=t.onNodeIconChange)==null||l.call(t,a,c),i(Ct(e,a,"$icon",c),{type:"nodeIcon",address:a,key:"$icon",value:c})},onNodeOutlineChange:(a,c)=>{var l;(l=t.onNodeOutlineChange)==null||l.call(t,a,c),i(Ct(e,a,"$outline",c),{type:"nodeOutline",address:a,key:"$outline",value:c})},onNodeAnimationChange:(a,c)=>{var l;(l=t.onNodeAnimationChange)==null||l.call(t,a,c),i(Ct(e,a,"$isNodeAnimated",c),{type:"nodeAnimation",address:a,key:"$isNodeAnimated",value:c})},onNodeAnimationVariantChange:(a,c)=>{var l;c!=="traveling"&&c!=="pulse"||((l=t.onNodeAnimationVariantChange)==null||l.call(t,a,c),i(Ct(e,a,"$nodeAnimationVariant",c),{type:"nodeAnimation",address:a,key:"$nodeAnimationVariant",value:c}))},onNodeCollapse:(a,c)=>{var l;(l=t.onNodeCollapse)==null||l.call(t,a,c),i(_d(e,a,c),{type:"nodeCollapse",address:a,key:"$collapsed",value:c})},onNodeCreate:a=>{var p,m;if(((p=t.onNodeCreate)==null?void 0:p.call(t,a))===!0)return;const c=a.sourceNodeId||"root",l=!!a.sourceNodeId&&a.isArrayMode&&!((m=qe(e,c))!=null&&m.$arrayDrawInitialized);let d=e,u,h=a.isArrayMode?"array":"set";for(let y=0;y<(l?2:1);y++){const g=a.sourceNodeId&&Eb(d,a.sourceNodeId,o);if(g)d=g.json,u??(u=g.address),h="form";else{const v=Pw(qe(d,c),a.isArrayMode?"list":"node"),b=a.isArrayMode?{$bgColor:"gray.500",$:[]}:{$bgColor:"gray.500"},x=Ed(d,c,b,v);d=x.json,u??(u=x.address)}}l&&(d=_t(d,c,y=>Array.isArray(y)?{$:y,$arrayDrawInitialized:!0}:{...y,$arrayDrawInitialized:!0})),i(d,{type:"nodeCreate",address:u,value:h})},onNodeDelete:(a,c)=>{var l;(l=t.onNodeDelete)==null||l.call(t,a,c),i(ob(e,a),{type:"nodeDelete",address:a})},onEdgeCreate:(a,c,l)=>{var u;(u=t.onEdgeCreate)==null||u.call(t,a,c,l);const d=l&&(l.sourceProperty!==void 0||l.targetProperty!==void 0)?{...l,target:c}:void 0;i(d?kd(e,a,d):ib(e,a,c),{type:"edgeCreate",address:a,key:d?"$connections":"$target",value:d??c})},onEdgeLabelChange:(a,c)=>{var d;(d=t.onEdgeLabelChange)==null||d.call(t,a,c);const l=s(a);l&&i(cr(e,l,"$sourceLabel",c),{type:"edgeLabel",edge:l,key:l.connection?"$connections":"$sourceLabel",value:c})},onEdgeStyleChange:(a,c)=>{var d;(d=t.onEdgeStyleChange)==null||d.call(t,a,c);const l=s(a);l&&i(nb(e,l,c),{type:"edgeStyle",edge:l,value:c})},onEdgeAnimationVariantChange:(a,c)=>{var d;if(c!=="dashed"&&c!=="traveling")return;(d=t.onEdgeAnimationVariantChange)==null||d.call(t,a,c);const l=s(a);l&&i(cr(e,l,"$edgeAnimationVariant",c),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeAnimationVariant",value:c})},onEdgeTypeChange:(a,c)=>{var d;(d=t.onEdgeTypeChange)==null||d.call(t,a,c);const l=s(a);l&&i(cr(e,l,"$edgeType",c),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeType",value:c})},onEdgeIconChange:(a,c)=>{var d;(d=t.onEdgeIconChange)==null||d.call(t,a,c);const l=s(a);l&&i(cr(e,l,"$edgeIcon",c||void 0),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeIcon",value:c})},onEdgeColorChange:(a,c)=>{var d;(d=t.onEdgeColorChange)==null||d.call(t,a,c);const l=s(a);l&&i(cr(e,l,"$edgeColor",c),{type:"edgeColor",edge:l,key:l.connection?"$connections":"$edgeColor",value:c})},onEdgeDelete:(a,c)=>{var u;(u=t.onEdgeDelete)==null||u.call(t,a,c);const l=s(a);if(!l)return;const d=ab(e,l);d.removed&&i(d.json,{type:"edgeDelete",edge:l,key:l.connection?"$connections":"$target"})}}}const Iw=".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 Mw({path:e,width:r,reversed:t,children:n,onComplete:o}){const i=`flow-edge-reveal-${_.useId().replace(/:/g,"")}`,s=_.useRef(null),[a,c]=_.useState({x:0,y:0,width:1,height:1});return _.useEffect(()=>{const l=matchMedia("(prefers-reduced-motion: reduce)"),d=()=>{l.matches&&(o==null||o())};return d(),l.addEventListener("change",d),()=>l.removeEventListener("change",d)},[o]),_.useLayoutEffect(()=>{var d;const l=(d=s.current)==null?void 0:d.getBBox();l&&c({x:l.x-r,y:l.y-r,width:l.width+r*2,height:l.height+r*2})},[e,r]),f.jsxs(f.Fragment,{children:[f.jsx("defs",{children:f.jsx("mask",{id:i,maskUnits:"userSpaceOnUse",...a,children:f.jsx("path",{ref:s,className:"flow-sdk-edge-reveal",onAnimationEnd:l=>{l.animationName==="flow-sdk-edge-reveal"&&(o==null||o())},"data-reveal-direction":t?"reverse":"forward",style:{"--flow-edge-reveal-from":t?-100:100},d:e,fill:"none",stroke:"white",strokeWidth:r,strokeLinecap:"butt",strokeLinejoin:"round",pathLength:100,strokeDasharray:"100 100"})})}),f.jsx("g",{mask:`url(#${i})`,children:n})]})}const Tw=".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 Ow({path:e,color:r,width:t,reversed:n}){return f.jsx("path",{className:`flow-sdk-edge-trace${n?" flow-sdk-edge-trace-reverse":""}`,"data-animation-variant":"traveling","aria-hidden":"true",pointerEvents:"none",d:e,fill:"none",stroke:r,strokeWidth:t,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 100"})}const Ib=".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 ro({x:e=0,y:r=0,width:t,height:n,radius:o,color:i,strokeWidth:s=8,path:a,variant:c="traveling"}){const l=_.useId(),d=`flow-sdk-node-border-animation${c==="pulse"?" flow-sdk-node-border-pulse":""}`;if(c==="pulse"){const u=a?"path":"rect",h=a?{d:a}:{x:e,y:r,width:Math.max(0,t),height:Math.max(0,n),rx:Math.max(0,Math.min(o,t/2,n/2))},p=s+36,m={x:e-p,y:r-p,width:t+2*p,height:n+2*p};return f.jsxs("g",{"aria-hidden":"true",pointerEvents:"none",children:[f.jsx("defs",{children:f.jsxs("mask",{id:l,maskUnits:"userSpaceOnUse",...m,style:{maskType:"luminance"},children:[f.jsx("rect",{...m,fill:"white"}),f.jsx(u,{...h,fill:"black",stroke:"black",strokeWidth:s,strokeLinejoin:"round"})]})}),f.jsx(u,{...h,className:d,"data-animation-variant":c,fill:"none",stroke:`color-mix(in srgb, ${i} 30%, transparent)`,strokeLinejoin:"round",mask:`url(#${l})`,style:{"--flow-pulse-rest-width":`${s+16}px`,"--flow-pulse-expanded-width":`${s+36}px`}})]})}return a?f.jsx("path",{className:d,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",d:a,fill:"none",stroke:i,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"}):f.jsx("rect",{className:d,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",x:e,y:r,width:Math.max(0,t),height:Math.max(0,n),rx:Math.max(0,Math.min(o,t/2,n/2)),fill:"none",stroke:i,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const Nw=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 Mb(e,r=!1){return e&&!r&&typeof requestAnimationFrame<"u"&&!(typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches)}function Tb(e,r,t=()=>{},n=300){let o,i,s=!1;const a=()=>{s=!0,o!==void 0&&cancelAnimationFrame(o),clearTimeout(i)},c=()=>{s||(a(),r(1),t())};if(!Mb(e))return c(),a;const l=performance.now(),d=u=>{if(s)return;const h=Math.max(0,Math.min(1,(u-l)/n));if(h>=1)return c();r(h<.5?4*h**3:1-(-2*h+2)**3/2),s||(o=requestAnimationFrame(d))};return o=requestAnimationFrame(d),i=setTimeout(c,n+100),a}function Fu(e,r,t){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const s of r)(s.parent===i||s.id.startsWith(`${i}.`)||t.some(c=>(c.inverted?c.target:c.source)===i&&(c.inverted?c.source:c.target)===s.id))&&!n.has(s.id)&&(n.add(s.id),o.push(s.id))}return n}function $w(e,r,t){const n=t==="downward"||t==="upward",o=new Map;for(const s of e){if(s.source===s.target||s.sourceProperty||s.targetProperty)continue;const a=r(s.source),c=r(s.target);if(!a||!c)continue;const l=n?c.y-a.y:c.x-a.x,d=Math.abs(l)-(n?a.h+c.h:a.w+c.w)/2;if(d<=320)continue;const u=JSON.stringify([s.source,Math.sign(l)]),h=o.get(u)??[];h.push({edge:s,gap:d,cross:n?c.x-a.x:c.y-a.y}),o.set(u,h)}const i=new Map;for(const s of o.values()){if(new Set(s.map(({edge:c})=>c.target)).size<2)continue;const a=new Map;for(const{edge:c}of s)a.set(c.target,(a.get(c.target)??0)+1);for(const c of[-1,0,1]){const l=s.filter(({cross:u})=>Math.sign(u)===c);l.sort((u,h)=>Math.abs(h.cross)-Math.abs(u.cross)||u.edge.id.localeCompare(h.edge.id));const d=Math.min(...l.map(({gap:u})=>u));l.forEach(({edge:u,gap:h,cross:p},m)=>{const y=l.length===1?d/2:120+(d-280)*m/(l.length-1),g=l.find(v=>Math.abs(v.cross)<Math.abs(p));i.set(u.id,{turn:y/h,labelAtTarget:a.get(u.target)===1,labelFraction:p?(p+((g==null?void 0:g.cross)??0))/(2*p):.5})})}}return i}const Kt=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}),qw=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function Do(e){if(!e.length)return null;const r={...e[0]};for(let t=1;t<e.length;t++)r.x1=Math.min(r.x1,e[t].x1),r.y1=Math.min(r.y1,e[t].y1),r.x2=Math.max(r.x2,e[t].x2),r.y2=Math.max(r.y2,e[t].y2);return r}const Lw=(e,r)=>e.x1<=r.x2&&e.x2>=r.x1&&e.y1<=r.y2&&e.y2>=r.y1,zu=(e,r)=>e.x>=r.x1&&e.x<=r.x2&&e.y>=r.y1&&e.y<=r.y2,Nt=e=>(Math.round(e*10)/10).toString(),ut=e=>`${Nt(e.x)} ${Nt(e.y)}`,Fw=e=>e>0?1:e<0?-1:0,Bu=(e,r)=>e>0?Math.max(e-r,0):Math.min(e+r,0);function zw(e,r,t,n,o=10){const i=r.x-e.x,s=r.y-e.y,a=Bu(i,(e.w+r.w)/2),c=Bu(s,(e.h+r.h)/2),l=t==="downward"||t==="upward",d=l?c:a,u=l?s:i,h=Fw(u),p=n*d,m=b=>Math.abs(b)<o||Math.abs(b)>=Math.abs(d),y=m(p)||m(Math.abs(d)-Math.abs(p));let g;if(y)if(l)if(Math.abs(u)<=e.h/2){const b=(e.x+r.x)/2;g=[b,e.y,b,r.y]}else if(Math.abs(i)<=r.w/2){const b=(e.y+r.y)/2;g=[e.x,b,r.x,b]}else g=[e.x,r.y];else if(Math.abs(u)<=e.w/2){const b=(e.y+r.y)/2;g=[e.x,b,r.x,b]}else if(Math.abs(s)<=r.h/2){const b=(e.x+r.x)/2;g=[b,e.y,b,r.y]}else g=[r.x,e.y];else if(l){const b=e.y+p+e.h/2*h;g=[e.x,b,r.x,b]}else{const b=e.x+p+e.w/2*h;g=[b,e.y,b,r.y]}const v=[{x:e.x,y:e.y}];for(let b=0;b<g.length;b+=2)v.push({x:g[b],y:g[b+1]});return v.push({x:r.x,y:r.y}),v}function Bw(e,r,t){const n=r.x-e.x,o=r.y-e.y,i=n>0?(t.x2-e.x)/n:n<0?(t.x1-e.x)/n:1/0,s=o>0?(t.y2-e.y)/o:o<0?(t.y1-e.y)/o:1/0,a=Math.min(i,s);return!Number.isFinite(a)||a>=1||a<0?null:{x:e.x+n*a,y:e.y+o*a}}function Ur(e,r,t){var s;if(!((s=t.outline)!=null&&s.length))return Bw(e,r,Kt(t));const n=r.x-e.x,o=r.y-e.y;let i=1/0;return t.outline.forEach((a,c,l)=>{const d=l[(c+1)%l.length],u=d.x-a.x,h=d.y-a.y,p=n*h-o*u;if(Math.abs(p)<1e-9)return;const m=a.x-e.x,y=a.y-e.y,g=(m*h-y*u)/p,v=(m*o-y*n)/p;g>=0&&g<1&&v>=-1e-9&&v<=1+1e-9&&(i=Math.min(i,g))}),Number.isFinite(i)?{x:e.x+n*i,y:e.y+o*i}:null}function Ob(e,r,t=.5){const n=Number.isFinite(t)?Math.max(0,Math.min(1,t)):.5,o=r==="top"||r==="bottom",i=r==="top"||r==="left"?-1:1,s={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},a=Math.max(e.w,e.h)*2+1;return{...Ur(s,{x:s.x+(o?0:i*a),y:s.y+(o?i*a:0)},e)??{x:o?s.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:s.y},side:r}}function qr(e,r){return{x:e.x+(e.side==="right"?r:e.side==="left"?-r:0),y:e.y+(e.side==="bottom"?r:e.side==="top"?-r:0)}}function Dw(e,r,t,n){const o=qr(e,t.srcDist),i=qr(r,t.tgtDist);if(n==="straight")return $b(o,i,t);const s=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),a=e.side==="bottom"&&r.side==="top"?i.y-o.y:e.side==="top"&&r.side==="bottom"?o.y-i.y:e.side==="right"&&r.side==="left"?i.x-o.x:e.side==="left"&&r.side==="right"?o.x-i.x:void 0,c=a!==void 0&&a>0?Math.min(s,a/2):s,l=qr({...o,side:e.side},c),d=qr({...i,side:r.side},c),u=t.arrowAt==="source"?bt(o,l,t.arrowGap):o,h=t.arrowAt==="target"?bt(i,d,t.arrowGap):i,p=t.arrowAt==="source"?qt(o,l,t.arrowSize,t.headShape):t.arrowAt==="target"?qt(i,d,t.arrowSize,t.headShape):void 0;if(n==="bezier")return{d:`M${ut(u)} C${ut(l)} ${ut(d)} ${ut(h)}`,arrow:p,label:{x:(u.x+3*l.x+3*d.x+h.x)/8,y:(u.y+3*l.y+3*d.y+h.y)/8,angle:0}};const m=e.side==="left"||e.side==="right",y=r.side==="left"||r.side==="right";let g;if(m!==y){const b=m?{x:d.x,y:l.y}:{x:l.x,y:d.y},x=(b.x-l.x)*(l.x-o.x)+(b.y-l.y)*(l.y-o.y)>=0,w=(b.x-d.x)*(d.x-i.x)+(b.y-d.y)*(d.y-i.y)>=0;g=[x&&w?b:m?{x:l.x,y:d.y}:{x:d.x,y:l.y}]}else if(a!==void 0&&a<=0)if(m){const b=(l.y+d.y)/2;g=[{x:l.x,y:b},{x:d.x,y:b}]}else{const b=(l.x+d.x)/2;g=[{x:b,y:l.y},{x:b,y:d.y}]}else if(m){const b=e.side===r.side?e.side==="right"?Math.max(l.x,d.x):Math.min(l.x,d.x):(l.x+d.x)/2;g=[{x:b,y:l.y},{x:b,y:d.y}]}else{const b=e.side===r.side?e.side==="bottom"?Math.max(l.y,d.y):Math.min(l.y,d.y):(l.y+d.y)/2;g=[{x:l.x,y:b},{x:d.x,y:b}]}const v=[l,...g,d].filter((b,x,w)=>x===0||b.x!==w[x-1].x||b.y!==w[x-1].y);return ho(u,v,h,p,n==="orthogonal"?0:t.radius)}function bt(e,r,t){const n=e.x-r.x,o=e.y-r.y,i=Math.hypot(n,o);if(!i)return e;let s=(i-t)/i;return s<0&&(s=1e-5),{x:r.x+s*n,y:r.y+s*o}}function qt(e,r,t,n="triangle"){const o=e.x-r.x,i=e.y-r.y,s=Math.hypot(o,i)||1,a=o/s,c=i/s,l=(n==="square"?.15:.3)*t,d=.15*t,u=e.x-a*l,h=e.y-c*l;if(n==="square")return`M${ut(e)} L${Nt(e.x-c*d)} ${Nt(e.y+a*d)} L${Nt(u-c*d)} ${Nt(h+a*d)} L${Nt(u+c*d)} ${Nt(h-a*d)} L${Nt(e.x+c*d)} ${Nt(e.y-a*d)} Z`;const p=[e,{x:u-c*d,y:h+a*d},{x:u+c*d,y:h-a*d}];return p.map((y,g)=>{const v=p[(g+2)%3],b=p[(g+1)%3],x=Math.hypot(v.x-y.x,v.y-y.y),w=Math.hypot(b.x-y.x,b.y-y.y),C={x:(v.x-y.x)/x,y:(v.y-y.y)/x},S={x:(b.x-y.x)/w,y:(b.y-y.y)/w},j=Math.max(-1,Math.min(1,C.x*S.x+C.y*S.y)),P=Math.sqrt((1-j)/(1+j)),E=Math.min(1/P,x/2,w/2);return{start:{x:y.x+C.x*E,y:y.y+C.y*E},end:{x:y.x+S.x*E,y:y.y+S.y*E},radius:E*P}}).map((y,g)=>`${g?"L":"M"}${ut(y.start)} A${Nt(y.radius)} ${Nt(y.radius)} 0 0 1 ${ut(y.end)}`).join(" ")+" Z"}function sr(e,r){let t=Math.atan(r/e);return e===0&&t<0&&(t=-t),Number.isFinite(t)||(t=0),t*180/Math.PI}function Vw(e,r,t,n){const o={x:r.x-e.x,y:r.y-e.y},i={x:t.x-r.x,y:t.y-r.y},s=Math.hypot(o.x,o.y),a=Math.hypot(i.x,i.y),c=o.x*i.y-o.y*i.x;if(s<1e-6||a<1e-6||Math.abs(c)<1e-6)return{p1:r,b:r,p2:r,r:0};const l=Math.min(n,s/2,a/2);return{p1:{x:r.x-o.x/s*l,y:r.y-o.y/s*l},b:r,p2:{x:r.x+i.x/a*l,y:r.y+i.y/a*l},r:l}}function Nb(e,r,t,n){let o=-1,i=null;for(let m=0;m<e.length-1;m++){const y=Ur(e[m],e[m+1],r);if(y){o=m,i=y;break}}let s=-1,a=null;for(let m=e.length-1;m>0;m--){const y=Ur(e[m],e[m-1],t);if(y){s=m,a=y;break}}if(!i||!a||o>=s)return null;const c=e.slice(o+1,s),l=c[0]??a,d=c[c.length-1]??i;let u,h,p;if(n.arrowAt==="source"){const m=bt(i,l,n.srcDist);u=bt(i,l,n.srcDist+n.arrowGap),p=qt(m,l,n.arrowSize,n.headShape)}else u=bt(i,l,n.srcDist);if(n.arrowAt==="target"){const m=bt(a,d,n.tgtDist);h=bt(a,d,n.tgtDist+n.arrowGap),p=qt(m,d,n.arrowSize,n.headShape)}else h=bt(a,d,n.tgtDist);return ho(u,c,h,p,n.radius,n.labelTargetLength,n.labelFraction)}function ho(e,r,t,n,o,i,s){var h;const a=[e,...r,t],c=[];let l=`M${ut(e)}`;for(let p=1;p<a.length-1;p++){const m=Vw(a[p-1],a[p],a[p+1],o);c.push(m),m.r===0?l+=` L${ut(m.b)}`:l+=` L${ut(m.p1)} Q${ut(m.b)} ${ut(m.p2)}`}l+=` L${ut(t)}`;let d;const u=r.length;if(u===0)d={x:(e.x+t.x)/2,y:(e.y+t.y)/2,angle:sr(t.x-e.x,t.y-e.y)};else if(u%2===0){const p=r[u/2-1],m=r[u/2];d={x:(p.x+m.x)/2,y:(p.y+m.y)/2,angle:sr(m.x-p.x,m.y-p.y)}}else{const p=c[(u-1)/2];if(p.r===0){const m=a[(u-1)/2+2];d={x:p.b.x,y:p.b.y,angle:sr(m.x-p.b.x,m.y-p.b.y)}}else d={x:.25*p.p1.x+.5*p.b.x+.25*p.p2.x,y:.25*p.p1.y+.5*p.b.y+.25*p.p2.y,angle:sr(p.p2.x-p.p1.x,p.p2.y-p.p1.y)}}if(i!==void 0){if(s!==void 0&&c.length===2){const g=c[0].p2,v=c[1].p1,b=Math.hypot(v.x-g.x,v.y-g.y),x=Math.min(.5,i/(2*b)),w=Math.max(x,Math.min(1-x,s));d={x:g.x+(v.x-g.x)*w,y:g.y+(v.y-g.y)*w,angle:sr(v.x-g.x,v.y-g.y)}}const p=((h=c[c.length-1])==null?void 0:h.p2)??e,m=t.x-p.x,y=t.y-p.y;Math.hypot(m,y)>=i&&(d={x:(p.x+t.x)/2,y:(p.y+t.y)/2,angle:sr(m,y)})}return{d:l,arrow:n,label:d}}function Du(e,r,t,n,o,i,s){const a=t==="leftward"?-1:1,c={x:e.x+a*(e.w/2+s.srcDist),y:n??e.y},l={x:r.x-a*(r.w/2+s.tgtDist),y:o??r.y},d=Math.max(80,s.arrowGap+s.arrowSize*.3),u=c.x+a*d,h=l.x-a*d;let p;if(a*(h-u)>=0){const v=c.x+(l.x-c.x)*i,b=Math.max(Math.min(u,h),Math.min(Math.max(u,h),v));p=[{x:b,y:c.y},{x:b,y:l.y}]}else{const v=Math.min(e.y-e.h/2,r.y-r.h/2)-d*(1+i);p=[{x:u,y:c.y},{x:u,y:v},{x:h,y:v},{x:h,y:l.y}]}const m=s.arrowAt==="source"?bt(c,p[0],s.arrowGap):c,y=s.arrowAt==="target"?bt(l,p[p.length-1],s.arrowGap):l,g=s.arrowAt==="source"?qt(c,p[0],s.arrowSize,s.headShape):s.arrowAt==="target"?qt(l,p[p.length-1],s.arrowSize,s.headShape):void 0;return ho(m,p,y,g,s.radius)}function Vu(e,r,t,n,o){return Nb(zw(e,r,t,n),e,r,o)}function Gu(e,r,t,n,o,i){const s=n===void 0&&o===void 0&&(t==="downward"||t==="upward"),a=t==="leftward"||s&&t==="upward"?-1:1,c=(l,d,u)=>{const h={x:l.x,y:d??l.y},p=Math.max(l.w,l.h)*2+1,m=Ur(h,{x:h.x+(s?0:u*p),y:h.y+(s?u*p:0)},l);return m?{x:m.x+(s?0:u*i),y:m.y+(s?u*i:0)}:s?{x:l.x,y:l.y+u*(l.h/2+i)}:{x:l.x+u*(l.w/2+i),y:d??l.y}};return{sourcePoint:c(e,n,a),targetPoint:c(r,o,-a)}}function Gw(e,r,t,n){const o=t==="downward"||t==="upward",i=t==="leftward"||t==="upward"?-1:1,s=Math.max(100,Math.abs(o?r.y-e.y:r.x-e.x)/2),a={x:e.x+(o?0:i*s),y:e.y+(o?i*s:0)},c={x:r.x-(o?0:i*s),y:r.y-(o?i*s:0)},l=n.arrowAt==="source"?bt(e,a,n.arrowGap):e,d=n.arrowAt==="target"?bt(r,c,n.arrowGap):r;return{d:`M${ut(l)} C${ut(a)} ${ut(c)} ${ut(d)}`,arrow:n.arrowAt==="source"?qt(e,a,n.arrowSize,n.headShape):n.arrowAt==="target"?qt(r,c,n.arrowSize,n.headShape):void 0,label:{x:(l.x+3*a.x+3*c.x+d.x)/8,y:(l.y+3*a.y+3*c.y+d.y)/8,angle:sr(d.x+c.x-a.x-l.x,d.y+c.y-a.y-l.y)}}}function $b(e,r,t){const n=t.arrowAt==="source"?bt(e,r,t.arrowGap):e,o=t.arrowAt==="target"?bt(r,e,t.arrowGap):r,i=t.arrowAt==="source"?qt(e,r,t.arrowSize,t.headShape):t.arrowAt==="target"?qt(r,e,t.arrowSize,t.headShape):void 0;return ho(n,[],o,i,0)}function Ww(e,r,t,n=-90,o=-60,i=350){const s=n*Math.PI/180,a=o*Math.PI/180,c=s-Math.PI/2,l=c-a/2,d=c+a/2,u=1.4*i*(r/3+1),h={x:e.x+Math.cos(l)*u,y:e.y+Math.sin(l)*u},p={x:e.x+Math.cos(d)*u,y:e.y+Math.sin(d)*u},m={x:e.x,y:e.y},y=Ur(m,h,e),g=Ur(m,p,e);if(!y||!g)return null;const v={x:(h.x+p.x)/2,y:(h.y+p.y)/2};let b=bt(y,h,t.srcDist),x=bt(g,p,t.tgtDist),w;if(t.arrowAt==="target"){const S=x;x=bt(g,p,t.tgtDist+t.arrowGap),w=qt(S,p,t.arrowSize,t.headShape)}else if(t.arrowAt==="source"){const S=b;b=bt(y,h,t.srcDist+t.arrowGap),w=qt(S,h,t.arrowSize,t.headShape)}return{d:`M${ut(b)} Q${ut(h)} ${ut(v)} Q${ut(p)} ${ut(x)}`,arrow:w,label:{x:v.x,y:v.y,angle:sr(p.x-h.x,p.y-h.y)}}}const Or=e=>Math.round(e*1e3)/1e3;function qb(e){const r=e.querySelector("[data-flow-node-surface]");if(!r)return;const t=e.getBoundingClientRect(),n=t.width/e.offsetWidth;if(!Number.isFinite(n)||n<=0)return;const o=r.getBoundingClientRect();if(!o.width||!o.height)return;const i=r,s=typeof i.getScreenCTM=="function"?i.getScreenCTM():null,a=typeof i.getTotalLength=="function"?i.getTotalLength():0,c=i.points,l=(c==null?void 0:c.numberOfItems)||128,d=s&&a>0?Array.from({length:l},(u,h)=>{const p=c!=null&&c.numberOfItems?c.getItem(h):i.getPointAtLength(a*h/l);return{x:Or((s.a*p.x+s.c*p.y+s.e-t.left)/n),y:Or((s.b*p.x+s.d*p.y+s.f-t.top)/n)}}):void 0;return{left:Or((o.left-t.left)/n),top:Or((o.top-t.top)/n),width:r instanceof HTMLElement?r.offsetWidth:Or(o.width/n),height:r instanceof HTMLElement?r.offsetHeight:Or(o.height/n),radius:parseFloat(getComputedStyle(r).borderTopLeftRadius)||0,...d?{outline:d}:{}}}function _n(e,r){const t=e.x-e.w/2,n=e.y-e.h/2;return{x:t+r.left+r.width/2,y:n+r.top+r.height/2,w:r.width,h:r.height,...r.outline?{outline:r.outline.map(o=>({x:t+o.x,y:n+o.y}))}:{}}}function Uw(e,r,t,n,o){var d;const i=o!=="TB"&&o!=="BT",s=i?"top":"left",a=i?"bottom":"right",c=new Map;for(const u of n)for(const[h,p,m]of[[u.source,u.sourceProperty,u.target],[u.target,u.targetProperty,u.source]]){const y=r.get(m);if(p===void 0||!y||m===h)continue;const g=t.get(m),v=JSON.stringify([h,p]),b=c.get(v)??[];b.push(g?_n(y,g):y),c.set(v,b)}const l=new Map(e);for(const[u,h]of e){const p=r.get(u);if(!p||!h.some(x=>x.placement==="config"))continue;const m=t.get(u),y=m?_n(p,m):p,g={x:p.w/2,y:p.h/2,w:p.w,h:p.h},v=m?_n(g,m):g,b=new Map;for(const x of h){if(x.placement!=="config")continue;const C=(c.get(JSON.stringify([u,x.property]))??[]).reduce((j,P)=>j+(i?P.y-y.y:P.x-y.x),0),S=((d=x.anchor)==null?void 0:d.side)===a?a:s;b.set(x,C<-.001?s:C>.001?a:S)}l.set(u,h.map(x=>{const w=b.get(x);if(!w)return x;const C=h.filter(P=>b.get(P)===w),S=(C.indexOf(x)+1)/(C.length+1),j=Ob(v,w,S);return{...x,anchor:j,top:j.y,height:0}}))}return l}function Wu(e,r,t){const n=new Set(r.map(a=>a.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const a of r)!o.has(a.id)&&(o.has(a.parent??"")||a.id.startsWith(`${e}.`))&&(o.add(a.id),i=!0)}const s=new Set(o);for(const a of t)o.has(a.source)&&n.has(a.target)&&s.add(a.target),o.has(a.target)&&n.has(a.source)&&s.add(a.source);return s}const dr='"Helvetica Neue", Helvetica, sans-serif';let dn;const Kn=new Map;function po(e,r){const t=`${r}|${e}`,n=Kn.get(t);if(n!==void 0)return n;dn===void 0&&(dn=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let o;return dn?(dn.font=r,o=dn.measureText(e).width):o=e.length*(parseFloat(r)||16)*.55,Kn.size>5e3&&Kn.clear(),Kn.set(t,o),o}function Hw(e,r,t){const n=[];for(const o of String(e).split(`
|
|
210
|
-
`)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let s="";for(const a of i){const c=s?`${s} ${a}`:a;!s||po(c,r)<=t?s=c:(n.push(s),s=a)}n.push(s)}return n}const Uu=e=>e.stopPropagation();function Kw({id:e,rect:r,label:t,labelLayer:n,labelContent:o,style:i,onSelect:s,onCollapse:a,selected:c=!1}){const l=r.x2-r.x1,d=r.y2-r.y1,u=i.borderWidth,h=i.borderStyle==="dashed"?`${u*4} ${u*2}`:i.borderStyle==="dotted"?`${u} ${u}`:void 0,p=r.x1+l/2,m=i.labelPosition==="top"?r.y1+i.labelMargin-i.fontSize/2:i.labelPosition==="bottom"?r.y2-i.labelMargin+i.fontSize/2:r.y1+d/2,y=t?po(t,`bold ${i.fontSize}px ${dr}`):0,g=i.fontSize/5,v=t||c&&a?f.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[c&&a&&f.jsx("foreignObject",{x:p+y/2+g+8,y:m-24,width:48,height:48,"data-flow-content-toggle":"","data-flow-collapse-control":"",style:{pointerEvents:"auto"},children:f.jsx(Ue,{label:"Show icon",children:f.jsx(Me,{"aria-label":"Show icon",icon:f.jsx(Z.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:i.textColor},onClick:b=>{b.stopPropagation(),a(e)}})})}),o?f.jsx("foreignObject",{x:p-y/2-g,y:m-i.fontSize/2-g,width:y+2*g,height:i.fontSize+2*g,style:{overflow:"visible"},onClick:Uu,children:o}):t&&f.jsxs(f.Fragment,{children:[f.jsx("rect",{x:p-y/2-g,y:m-i.fontSize/2-g,width:y+2*g,height:i.fontSize+2*g,fill:i.textColor==="transparent"?"transparent":i.labelBg}),f.jsx("text",{x:p,y:m,fill:i.textColor,fontSize:i.fontSize,fontWeight:"bold",fontFamily:dr,style:{fontSize:i.fontSize,fontWeight:"bold",fontFamily:dr},textAnchor:"middle",dominantBaseline:"central",children:t})]})]}):null;return f.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:Uu,onClick:b=>{b.stopPropagation(),s==null||s(e,{shiftKey:b.shiftKey,ctrlKey:b.ctrlKey,metaKey:b.metaKey,altKey:b.altKey})},children:[f.jsx("rect",{x:r.x1,y:r.y1,width:l,height:d,rx:i.borderRadius,ry:i.borderRadius,fill:i.bgColor,fillOpacity:i.bgOpacity,stroke:i.borderColor,strokeWidth:i.borderStyle==="double"?u/3:u,strokeDasharray:h}),i.borderStyle==="double"&&f.jsx("rect",{x:r.x1+u*2/3,y:r.y1+u*2/3,width:Math.max(0,l-u*4/3),height:Math.max(0,d-u*4/3),rx:Math.max(0,i.borderRadius-u*2/3),ry:Math.max(0,i.borderRadius-u*2/3),fill:"none",stroke:i.borderColor,strokeWidth:u/3}),i.animated&&u>0&&f.jsx(ro,{variant:i.animationVariant,x:r.x1,y:r.y1,width:l,height:d,radius:i.borderRadius,color:i.animationColor||i.borderColor,strokeWidth:Math.max(8,u*1.6)}),n&&v?Dr.createPortal(v,n):v]})}const Jw=_.memo(Kw),no=45,Lb=70,Cr=15,Fb=50;function zb(e,r,t=no){const n=`${t}px ${dr}`,o=e?Hw(e,n,200*t/no):[],i=r?48+(o.length?12:0):0,s=i+Math.max(0,...o.map(l=>po(l,n))),a=Math.max(o.length*t,r?48:0),c=o.length||r?2*Cr:0;return{lines:o,iconWidth:i,contentWidth:s,contentHeight:a,width:s+c,height:a+c}}const En=6,Bb=3,qd=.3,Zw=8,Ld=Math.max(Math.pow(En*13.37,.9),29)*Bb-Zw/qd,Db=En*Bb*2,Xn=80,Xw=2*Xn+Ld*qd+100,Yw=36+2*Math.max(80,Db+Ld*qd);function pd(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function gd(e,r){return r==="auto"||(r==="properties"?pd(e):!pd(e))}function Qt(e,r,t){return t!=="properties"||e!=="root"||r.some(n=>(n.source===e||n.target===e)&&pd(n))}function Qw(e,r,t,n=!1,o){if(!n)return{nodes:e,edges:r};const i=e.filter(a=>Qt(a.id,r,t)&&(!o||o.has(a.id))),s=new Set(i.map(a=>a.id));return{nodes:i,edges:r.filter(a=>gd(a,t)&&s.has(a.source)&&s.has(a.target))}}const e1=500,t1="32 18",r1=e=>e.stopPropagation();function n1({id:e,reveal:r,onRevealComplete:t,edgeData:n,validationIssue:o,edgeType:i="rounded-orthogonal",edgeRadius:s,customEdgeTypes:a,source:c,target:l,sourceProperty:d,targetProperty:u,sourceY:h,targetY:p,sourcePort:m,targetPort:y,propertyMode:g=!1,dir:v,turn:b,labelAtTarget:x,labelFraction:w,color:C,connectorColor:S,labelBg:j,labelLayer:P,label:E,dashed:O,animated:A,inverted:R,loopIndex:M=0,onSelect:T}){const N=n==null?void 0:n.icon,$=g?no:Lb,{lines:I,iconWidth:K,contentWidth:ie,contentHeight:se}=_.useMemo(()=>zb(E,N,$),[E,N,$]),te=_.useMemo(()=>{const Ce={srcDist:Xn,tgtDist:Xn,arrowGap:Db,arrowSize:Ld,headShape:g&&(R?h!==void 0||m:p!==void 0||y)?"square":"triangle",radius:s??(x?40:e1),arrowAt:R?"source":"target",labelTargetLength:x?ie+2*Cr:void 0,labelFraction:x?w:void 0},ye=h!==void 0||p!==void 0||!!m||!!y,pe=Gu(c,l,v,h,p,0),X=h===void 0&&p===void 0&&(v==="downward"||v==="upward"),L=m??{...pe.sourcePoint,side:X?v==="upward"?"top":"bottom":v==="leftward"?"left":"right"},ae=y??{...pe.targetPoint,side:X?v==="upward"?"bottom":"top":v==="leftward"?"right":"left"},H=c.x===l.x&&c.y===l.y,fe=m||y?Dw(L,ae,{...Ce,srcDist:18,tgtDist:18},i):ye?Du(c,l,v,h,p,b,{...Ce,srcDist:18,tgtDist:18,radius:s??Math.min(Ce.radius,40)}):H?Ww(c,M,{...Ce,srcDist:0,tgtDist:0}):Vu(c,l,v,b,Ce);if(!fe)return null;const be=Gu(c,l,v,h,p,ye?18:Xn);m&&(be.sourcePoint=qr(m,18)),y&&(be.targetPoint=qr(y,18));const Ne=Object.prototype.hasOwnProperty.call(a??{},i)?a==null?void 0:a[i]:void 0;if(Ne){const Le={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return Ne({edge:n??{id:e,source:"",target:""},source:{...c},target:{...l},...be,direction:Le[v],sourceY:h,targetY:p,inverted:!!R,defaultGeometry:fe})??fe}return H||m||y?fe:i==="straight"?ye?$b(be.sourcePoint,be.targetPoint,Ce):Nb([c,l],c,l,Ce):i==="bezier"?Gw(be.sourcePoint,be.targetPoint,ye?v==="leftward"?"leftward":"rightward":v,Ce):i==="orthogonal"?ye?Du(c,l,v,h,p,b,{...Ce,srcDist:18,tgtDist:18,radius:0}):Vu(c,l,v,b,{...Ce,radius:0}):fe},[c,e,n,i,s,a,l,g,h,p,m,y,v,b,R,M,x,w,ie]);if(!te)return null;const me=(v==="rightward"||v==="leftward")&&!Object.prototype.hasOwnProperty.call(a??{},i)&&!(g&&(h!==void 0||p!==void 0||m||y)),ve=me?`translate(${te.label.x} ${te.label.y-se/2-2*Cr})`:`translate(${te.label.x} ${te.label.y}) rotate(${te.label.angle}) translate(${v==="downward"||v==="upward"||x||Object.prototype.hasOwnProperty.call(a??{},i)?0:Fb} 0)`,F=o!=null&&o.startsWith("Unverified:")?"#b45309":"#dc2626",D=o?F:C,W=o?f.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":o,transform:`translate(${te.label.x} ${te.label.y-I.length*$/2-55})`,children:[f.jsx("title",{children:o}),f.jsx(Zt,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:F})]}):null,B=A&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",le=!B&&(O||A)?t1:void 0,Y=A&&!B?`flow-sdk-edge-anim${R?" flow-sdk-edge-anim-rev":""}`:void 0;let ce=null;const ue=r?{"--flow-edge-reveal-duration":`${r.durationMs??600}ms`,"--flow-edge-reveal-state":r.paused?"paused":"running"}:void 0;if(I.length||N){const Ce=ie,ye=se;ce=f.jsxs("g",{className:`flow-sdk-edge-label${r?" flow-sdk-edge-reveal-end":""}`,style:ue,"data-label-transform":ve,"data-label-horizontal":me||void 0,"data-edge-id":e,"data-source-property":d,"data-target-property":u,transform:ve,children:[f.jsx("rect",{x:-Ce/2-Cr,y:-ye/2-Cr,width:Ce+2*Cr,height:ye+2*Cr,fill:C==="transparent"?"transparent":j}),f.jsx("text",{fill:C,fontSize:$,style:{fontSize:$,fontFamily:dr},fontFamily:dr,textAnchor:"middle",dominantBaseline:"central",children:I.map((pe,X)=>f.jsx("tspan",{x:K/2,y:(X-(I.length-1)/2)*$,children:pe},X))}),N&&f.jsxs("g",{className:"flow-sdk-edge-icon",opacity:C==="transparent"?0:1,children:[f.jsx("title",{children:E?`Edge icon: ${E}`:"Edge icon"}),f.jsx("rect",{x:-Ce/2,y:-24,width:48,height:48,fill:"transparent"}),f.jsx(Zt,{name:N,svg:!0,size:48,x:-Ce/2,y:-24,color:C})]})]})}const xe=f.jsxs(f.Fragment,{children:[f.jsx("path",{d:te.d,fill:"none",stroke:D,strokeWidth:En,strokeOpacity:B?.35:void 0,strokeDasharray:le,className:Y}),B&&f.jsx(Ow,{path:te.d,color:D,width:En*1.6,reversed:R})]});return f.jsxs("g",{className:"flow-sdk-edge",style:ue,"data-edge-id":e,"data-source-property":d,"data-target-property":u,"data-validation":o?o.startsWith("Unverified:")?"unverified":"invalid":void 0,"aria-label":o,onPointerDown:r1,onClick:Ce=>{Ce.stopPropagation(),T==null||T(e)},children:[r?f.jsx(Mw,{path:te.d,width:En*4,reversed:R,onComplete:()=>t==null?void 0:t(e),children:xe}):xe,te.arrow&&f.jsx("path",{className:r?"flow-sdk-edge-reveal-end":void 0,d:te.arrow,fill:o?F:S??D}),P&&ce?Dr.createPortal(ce,P):ce,P&&W?Dr.createPortal(W,P):W,f.jsx("path",{className:"flow-sdk-edge-hit",d:te.d,fill:"none",stroke:"transparent"})]})}const Hu=_.memo(n1);var Jn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function o1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Fd(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 Vo,Ku;function i1(){if(Ku)return Vo;Ku=1;function e(){this.__data__=[],this.size=0}return Vo=e,Vo}var Go,Ju;function Xr(){if(Ju)return Go;Ju=1;function e(r,t){return r===t||r!==r&&t!==t}return Go=e,Go}var Wo,Zu;function go(){if(Zu)return Wo;Zu=1;var e=Xr();function r(t,n){for(var o=t.length;o--;)if(e(t[o][0],n))return o;return-1}return Wo=r,Wo}var Uo,Xu;function a1(){if(Xu)return Uo;Xu=1;var e=go(),r=Array.prototype,t=r.splice;function n(o){var i=this.__data__,s=e(i,o);if(s<0)return!1;var a=i.length-1;return s==a?i.pop():t.call(i,s,1),--this.size,!0}return Uo=n,Uo}var Ho,Yu;function s1(){if(Yu)return Ho;Yu=1;var e=go();function r(t){var n=this.__data__,o=e(n,t);return o<0?void 0:n[o][1]}return Ho=r,Ho}var Ko,Qu;function c1(){if(Qu)return Ko;Qu=1;var e=go();function r(t){return e(this.__data__,t)>-1}return Ko=r,Ko}var Jo,ef;function l1(){if(ef)return Jo;ef=1;var e=go();function r(t,n){var o=this.__data__,i=e(o,t);return i<0?(++this.size,o.push([t,n])):o[i][1]=n,this}return Jo=r,Jo}var Zo,tf;function yo(){if(tf)return Zo;tf=1;var e=i1(),r=a1(),t=s1(),n=c1(),o=l1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Zo=i,Zo}var Xo,rf;function d1(){if(rf)return Xo;rf=1;var e=yo();function r(){this.__data__=new e,this.size=0}return Xo=r,Xo}var Yo,nf;function u1(){if(nf)return Yo;nf=1;function e(r){var t=this.__data__,n=t.delete(r);return this.size=t.size,n}return Yo=e,Yo}var Qo,of;function f1(){if(of)return Qo;of=1;function e(r){return this.__data__.get(r)}return Qo=e,Qo}var ei,af;function h1(){if(af)return ei;af=1;function e(r){return this.__data__.has(r)}return ei=e,ei}var ti,sf;function Vb(){if(sf)return ti;sf=1;var e=typeof Jn=="object"&&Jn&&Jn.Object===Object&&Jn;return ti=e,ti}var ri,cf;function Gt(){if(cf)return ri;cf=1;var e=Vb(),r=typeof self=="object"&&self&&self.Object===Object&&self,t=e||r||Function("return this")();return ri=t,ri}var ni,lf;function Yr(){if(lf)return ni;lf=1;var e=Gt(),r=e.Symbol;return ni=r,ni}var oi,df;function p1(){if(df)return oi;df=1;var e=Yr(),r=Object.prototype,t=r.hasOwnProperty,n=r.toString,o=e?e.toStringTag:void 0;function i(s){var a=t.call(s,o),c=s[o];try{s[o]=void 0;var l=!0}catch{}var d=n.call(s);return l&&(a?s[o]=c:delete s[o]),d}return oi=i,oi}var ii,uf;function g1(){if(uf)return ii;uf=1;var e=Object.prototype,r=e.toString;function t(n){return r.call(n)}return ii=t,ii}var ai,ff;function Rr(){if(ff)return ai;ff=1;var e=Yr(),r=p1(),t=g1(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function s(a){return a==null?a===void 0?o:n:i&&i in Object(a)?r(a):t(a)}return ai=s,ai}var si,hf;function Lt(){if(hf)return si;hf=1;function e(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}return si=e,si}var ci,pf;function Nn(){if(pf)return ci;pf=1;var e=Rr(),r=Lt(),t="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function s(a){if(!r(a))return!1;var c=e(a);return c==n||c==o||c==t||c==i}return ci=s,ci}var li,gf;function y1(){if(gf)return li;gf=1;var e=Gt(),r=e["__core-js_shared__"];return li=r,li}var di,yf;function m1(){if(yf)return di;yf=1;var e=y1(),r=(function(){var n=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})();function t(n){return!!r&&r in n}return di=t,di}var ui,mf;function Gb(){if(mf)return ui;mf=1;var e=Function.prototype,r=e.toString;function t(n){if(n!=null){try{return r.call(n)}catch{}try{return n+""}catch{}}return""}return ui=t,ui}var fi,bf;function b1(){if(bf)return fi;bf=1;var e=Nn(),r=m1(),t=Lt(),n=Gb(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,s=Function.prototype,a=Object.prototype,c=s.toString,l=a.hasOwnProperty,d=RegExp("^"+c.call(l).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function u(h){if(!t(h)||r(h))return!1;var p=e(h)?d:i;return p.test(n(h))}return fi=u,fi}var hi,vf;function v1(){if(vf)return hi;vf=1;function e(r,t){return r==null?void 0:r[t]}return hi=e,hi}var pi,xf;function Ar(){if(xf)return pi;xf=1;var e=b1(),r=v1();function t(n,o){var i=r(n,o);return e(i)?i:void 0}return pi=t,pi}var gi,wf;function zd(){if(wf)return gi;wf=1;var e=Ar(),r=Gt(),t=e(r,"Map");return gi=t,gi}var yi,Cf;function mo(){if(Cf)return yi;Cf=1;var e=Ar(),r=e(Object,"create");return yi=r,yi}var mi,Sf;function x1(){if(Sf)return mi;Sf=1;var e=mo();function r(){this.__data__=e?e(null):{},this.size=0}return mi=r,mi}var bi,jf;function w1(){if(jf)return bi;jf=1;function e(r){var t=this.has(r)&&delete this.__data__[r];return this.size-=t?1:0,t}return bi=e,bi}var vi,_f;function C1(){if(_f)return vi;_f=1;var e=mo(),r="__lodash_hash_undefined__",t=Object.prototype,n=t.hasOwnProperty;function o(i){var s=this.__data__;if(e){var a=s[i];return a===r?void 0:a}return n.call(s,i)?s[i]:void 0}return vi=o,vi}var xi,Ef;function S1(){if(Ef)return xi;Ef=1;var e=mo(),r=Object.prototype,t=r.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:t.call(i,o)}return xi=n,xi}var wi,kf;function j1(){if(kf)return wi;kf=1;var e=mo(),r="__lodash_hash_undefined__";function t(n,o){var i=this.__data__;return this.size+=this.has(n)?0:1,i[n]=e&&o===void 0?r:o,this}return wi=t,wi}var Ci,Rf;function _1(){if(Rf)return Ci;Rf=1;var e=x1(),r=w1(),t=C1(),n=S1(),o=j1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Ci=i,Ci}var Si,Af;function E1(){if(Af)return Si;Af=1;var e=_1(),r=yo(),t=zd();function n(){this.size=0,this.__data__={hash:new e,map:new(t||r),string:new e}}return Si=n,Si}var ji,Pf;function k1(){if(Pf)return ji;Pf=1;function e(r){var t=typeof r;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?r!=="__proto__":r===null}return ji=e,ji}var _i,If;function bo(){if(If)return _i;If=1;var e=k1();function r(t,n){var o=t.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return _i=r,_i}var Ei,Mf;function R1(){if(Mf)return Ei;Mf=1;var e=bo();function r(t){var n=e(this,t).delete(t);return this.size-=n?1:0,n}return Ei=r,Ei}var ki,Tf;function A1(){if(Tf)return ki;Tf=1;var e=bo();function r(t){return e(this,t).get(t)}return ki=r,ki}var Ri,Of;function P1(){if(Of)return Ri;Of=1;var e=bo();function r(t){return e(this,t).has(t)}return Ri=r,Ri}var Ai,Nf;function I1(){if(Nf)return Ai;Nf=1;var e=bo();function r(t,n){var o=e(this,t),i=o.size;return o.set(t,n),this.size+=o.size==i?0:1,this}return Ai=r,Ai}var Pi,$f;function Bd(){if($f)return Pi;$f=1;var e=E1(),r=R1(),t=A1(),n=P1(),o=I1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Pi=i,Pi}var Ii,qf;function M1(){if(qf)return Ii;qf=1;var e=yo(),r=zd(),t=Bd(),n=200;function o(i,s){var a=this.__data__;if(a instanceof e){var c=a.__data__;if(!r||c.length<n-1)return c.push([i,s]),this.size=++a.size,this;a=this.__data__=new t(c)}return a.set(i,s),this.size=a.size,this}return Ii=o,Ii}var Mi,Lf;function vo(){if(Lf)return Mi;Lf=1;var e=yo(),r=d1(),t=u1(),n=f1(),o=h1(),i=M1();function s(a){var c=this.__data__=new e(a);this.size=c.size}return s.prototype.clear=r,s.prototype.delete=t,s.prototype.get=n,s.prototype.has=o,s.prototype.set=i,Mi=s,Mi}var Ti,Ff;function Dd(){if(Ff)return Ti;Ff=1;function e(r,t){for(var n=-1,o=r==null?0:r.length;++n<o&&t(r[n],n,r)!==!1;);return r}return Ti=e,Ti}var Oi,zf;function Wb(){if(zf)return Oi;zf=1;var e=Ar(),r=(function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch{}})();return Oi=r,Oi}var Ni,Bf;function xo(){if(Bf)return Ni;Bf=1;var e=Wb();function r(t,n,o){n=="__proto__"&&e?e(t,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):t[n]=o}return Ni=r,Ni}var $i,Df;function wo(){if(Df)return $i;Df=1;var e=xo(),r=Xr(),t=Object.prototype,n=t.hasOwnProperty;function o(i,s,a){var c=i[s];(!(n.call(i,s)&&r(c,a))||a===void 0&&!(s in i))&&e(i,s,a)}return $i=o,$i}var qi,Vf;function $n(){if(Vf)return qi;Vf=1;var e=wo(),r=xo();function t(n,o,i,s){var a=!i;i||(i={});for(var c=-1,l=o.length;++c<l;){var d=o[c],u=s?s(i[d],n[d],d,i,n):void 0;u===void 0&&(u=n[d]),a?r(i,d,u):e(i,d,u)}return i}return qi=t,qi}var Li,Gf;function T1(){if(Gf)return Li;Gf=1;function e(r,t){for(var n=-1,o=Array(r);++n<r;)o[n]=t(n);return o}return Li=e,Li}var Fi,Wf;function Xt(){if(Wf)return Fi;Wf=1;function e(r){return r!=null&&typeof r=="object"}return Fi=e,Fi}var zi,Uf;function O1(){if(Uf)return zi;Uf=1;var e=Rr(),r=Xt(),t="[object Arguments]";function n(o){return r(o)&&e(o)==t}return zi=n,zi}var Bi,Hf;function qn(){if(Hf)return Bi;Hf=1;var e=O1(),r=Xt(),t=Object.prototype,n=t.hasOwnProperty,o=t.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(s){return r(s)&&n.call(s,"callee")&&!o.call(s,"callee")};return Bi=i,Bi}var Di,Kf;function gt(){if(Kf)return Di;Kf=1;var e=Array.isArray;return Di=e,Di}var gn={exports:{}},Vi,Jf;function N1(){if(Jf)return Vi;Jf=1;function e(){return!1}return Vi=e,Vi}gn.exports;var Zf;function Qr(){return Zf||(Zf=1,(function(e,r){var t=Gt(),n=N1(),o=r&&!r.nodeType&&r,i=o&&!0&&e&&!e.nodeType&&e,s=i&&i.exports===o,a=s?t.Buffer:void 0,c=a?a.isBuffer:void 0,l=c||n;e.exports=l})(gn,gn.exports)),gn.exports}var Gi,Xf;function Co(){if(Xf)return Gi;Xf=1;var e=9007199254740991,r=/^(?:0|[1-9]\d*)$/;function t(n,o){var i=typeof n;return o=o??e,!!o&&(i=="number"||i!="symbol"&&r.test(n))&&n>-1&&n%1==0&&n<o}return Gi=t,Gi}var Wi,Yf;function Vd(){if(Yf)return Wi;Yf=1;var e=9007199254740991;function r(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=e}return Wi=r,Wi}var Ui,Qf;function $1(){if(Qf)return Ui;Qf=1;var e=Rr(),r=Vd(),t=Xt(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",s="[object Date]",a="[object Error]",c="[object Function]",l="[object Map]",d="[object Number]",u="[object Object]",h="[object RegExp]",p="[object Set]",m="[object String]",y="[object WeakMap]",g="[object ArrayBuffer]",v="[object DataView]",b="[object Float32Array]",x="[object Float64Array]",w="[object Int8Array]",C="[object Int16Array]",S="[object Int32Array]",j="[object Uint8Array]",P="[object Uint8ClampedArray]",E="[object Uint16Array]",O="[object Uint32Array]",A={};A[b]=A[x]=A[w]=A[C]=A[S]=A[j]=A[P]=A[E]=A[O]=!0,A[n]=A[o]=A[g]=A[i]=A[v]=A[s]=A[a]=A[c]=A[l]=A[d]=A[u]=A[h]=A[p]=A[m]=A[y]=!1;function R(M){return t(M)&&r(M.length)&&!!A[e(M)]}return Ui=R,Ui}var Hi,eh;function So(){if(eh)return Hi;eh=1;function e(r){return function(t){return r(t)}}return Hi=e,Hi}var yn={exports:{}};yn.exports;var th;function Gd(){return th||(th=1,(function(e,r){var t=Vb(),n=r&&!r.nodeType&&r,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i&&t.process,a=(function(){try{var c=o&&o.require&&o.require("util").types;return c||s&&s.binding&&s.binding("util")}catch{}})();e.exports=a})(yn,yn.exports)),yn.exports}var Ki,rh;function Ln(){if(rh)return Ki;rh=1;var e=$1(),r=So(),t=Gd(),n=t&&t.isTypedArray,o=n?r(n):e;return Ki=o,Ki}var Ji,nh;function Ub(){if(nh)return Ji;nh=1;var e=T1(),r=qn(),t=gt(),n=Qr(),o=Co(),i=Ln(),s=Object.prototype,a=s.hasOwnProperty;function c(l,d){var u=t(l),h=!u&&r(l),p=!u&&!h&&n(l),m=!u&&!h&&!p&&i(l),y=u||h||p||m,g=y?e(l.length,String):[],v=g.length;for(var b in l)(d||a.call(l,b))&&!(y&&(b=="length"||p&&(b=="offset"||b=="parent")||m&&(b=="buffer"||b=="byteLength"||b=="byteOffset")||o(b,v)))&&g.push(b);return g}return Ji=c,Ji}var Zi,oh;function jo(){if(oh)return Zi;oh=1;var e=Object.prototype;function r(t){var n=t&&t.constructor,o=typeof n=="function"&&n.prototype||e;return t===o}return Zi=r,Zi}var Xi,ih;function Hb(){if(ih)return Xi;ih=1;function e(r,t){return function(n){return r(t(n))}}return Xi=e,Xi}var Yi,ah;function q1(){if(ah)return Yi;ah=1;var e=Hb(),r=e(Object.keys,Object);return Yi=r,Yi}var Qi,sh;function Wd(){if(sh)return Qi;sh=1;var e=jo(),r=q1(),t=Object.prototype,n=t.hasOwnProperty;function o(i){if(!e(i))return r(i);var s=[];for(var a in Object(i))n.call(i,a)&&a!="constructor"&&s.push(a);return s}return Qi=o,Qi}var ea,ch;function tr(){if(ch)return ea;ch=1;var e=Nn(),r=Vd();function t(n){return n!=null&&r(n.length)&&!e(n)}return ea=t,ea}var ta,lh;function mr(){if(lh)return ta;lh=1;var e=Ub(),r=Wd(),t=tr();function n(o){return t(o)?e(o):r(o)}return ta=n,ta}var ra,dh;function L1(){if(dh)return ra;dh=1;var e=$n(),r=mr();function t(n,o){return n&&e(o,r(o),n)}return ra=t,ra}var na,uh;function F1(){if(uh)return na;uh=1;function e(r){var t=[];if(r!=null)for(var n in Object(r))t.push(n);return t}return na=e,na}var oa,fh;function z1(){if(fh)return oa;fh=1;var e=Lt(),r=jo(),t=F1(),n=Object.prototype,o=n.hasOwnProperty;function i(s){if(!e(s))return t(s);var a=r(s),c=[];for(var l in s)l=="constructor"&&(a||!o.call(s,l))||c.push(l);return c}return oa=i,oa}var ia,hh;function Pr(){if(hh)return ia;hh=1;var e=Ub(),r=z1(),t=tr();function n(o){return t(o)?e(o,!0):r(o)}return ia=n,ia}var aa,ph;function B1(){if(ph)return aa;ph=1;var e=$n(),r=Pr();function t(n,o){return n&&e(o,r(o),n)}return aa=t,aa}var mn={exports:{}};mn.exports;var gh;function Kb(){return gh||(gh=1,(function(e,r){var t=Gt(),n=r&&!r.nodeType&&r,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i?t.Buffer:void 0,a=s?s.allocUnsafe:void 0;function c(l,d){if(d)return l.slice();var u=l.length,h=a?a(u):new l.constructor(u);return l.copy(h),h}e.exports=c})(mn,mn.exports)),mn.exports}var sa,yh;function Jb(){if(yh)return sa;yh=1;function e(r,t){var n=-1,o=r.length;for(t||(t=Array(o));++n<o;)t[n]=r[n];return t}return sa=e,sa}var ca,mh;function Zb(){if(mh)return ca;mh=1;function e(r,t){for(var n=-1,o=r==null?0:r.length,i=0,s=[];++n<o;){var a=r[n];t(a,n,r)&&(s[i++]=a)}return s}return ca=e,ca}var la,bh;function Xb(){if(bh)return la;bh=1;function e(){return[]}return la=e,la}var da,vh;function Ud(){if(vh)return da;vh=1;var e=Zb(),r=Xb(),t=Object.prototype,n=t.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(s){return s==null?[]:(s=Object(s),e(o(s),function(a){return n.call(s,a)}))}:r;return da=i,da}var ua,xh;function D1(){if(xh)return ua;xh=1;var e=$n(),r=Ud();function t(n,o){return e(n,r(n),o)}return ua=t,ua}var fa,wh;function Hd(){if(wh)return fa;wh=1;function e(r,t){for(var n=-1,o=t.length,i=r.length;++n<o;)r[i+n]=t[n];return r}return fa=e,fa}var ha,Ch;function _o(){if(Ch)return ha;Ch=1;var e=Hb(),r=e(Object.getPrototypeOf,Object);return ha=r,ha}var pa,Sh;function Yb(){if(Sh)return pa;Sh=1;var e=Hd(),r=_o(),t=Ud(),n=Xb(),o=Object.getOwnPropertySymbols,i=o?function(s){for(var a=[];s;)e(a,t(s)),s=r(s);return a}:n;return pa=i,pa}var ga,jh;function V1(){if(jh)return ga;jh=1;var e=$n(),r=Yb();function t(n,o){return e(n,r(n),o)}return ga=t,ga}var ya,_h;function Qb(){if(_h)return ya;_h=1;var e=Hd(),r=gt();function t(n,o,i){var s=o(n);return r(n)?s:e(s,i(n))}return ya=t,ya}var ma,Eh;function ev(){if(Eh)return ma;Eh=1;var e=Qb(),r=Ud(),t=mr();function n(o){return e(o,t,r)}return ma=n,ma}var ba,kh;function G1(){if(kh)return ba;kh=1;var e=Qb(),r=Yb(),t=Pr();function n(o){return e(o,t,r)}return ba=n,ba}var va,Rh;function W1(){if(Rh)return va;Rh=1;var e=Ar(),r=Gt(),t=e(r,"DataView");return va=t,va}var xa,Ah;function U1(){if(Ah)return xa;Ah=1;var e=Ar(),r=Gt(),t=e(r,"Promise");return xa=t,xa}var wa,Ph;function tv(){if(Ph)return wa;Ph=1;var e=Ar(),r=Gt(),t=e(r,"Set");return wa=t,wa}var Ca,Ih;function H1(){if(Ih)return Ca;Ih=1;var e=Ar(),r=Gt(),t=e(r,"WeakMap");return Ca=t,Ca}var Sa,Mh;function en(){if(Mh)return Sa;Mh=1;var e=W1(),r=zd(),t=U1(),n=tv(),o=H1(),i=Rr(),s=Gb(),a="[object Map]",c="[object Object]",l="[object Promise]",d="[object Set]",u="[object WeakMap]",h="[object DataView]",p=s(e),m=s(r),y=s(t),g=s(n),v=s(o),b=i;return(e&&b(new e(new ArrayBuffer(1)))!=h||r&&b(new r)!=a||t&&b(t.resolve())!=l||n&&b(new n)!=d||o&&b(new o)!=u)&&(b=function(x){var w=i(x),C=w==c?x.constructor:void 0,S=C?s(C):"";if(S)switch(S){case p:return h;case m:return a;case y:return l;case g:return d;case v:return u}return w}),Sa=b,Sa}var ja,Th;function K1(){if(Th)return ja;Th=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n){var o=n.length,i=new n.constructor(o);return o&&typeof n[0]=="string"&&r.call(n,"index")&&(i.index=n.index,i.input=n.input),i}return ja=t,ja}var _a,Oh;function rv(){if(Oh)return _a;Oh=1;var e=Gt(),r=e.Uint8Array;return _a=r,_a}var Ea,Nh;function Kd(){if(Nh)return Ea;Nh=1;var e=rv();function r(t){var n=new t.constructor(t.byteLength);return new e(n).set(new e(t)),n}return Ea=r,Ea}var ka,$h;function J1(){if($h)return ka;$h=1;var e=Kd();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.byteLength)}return ka=r,ka}var Ra,qh;function Z1(){if(qh)return Ra;qh=1;var e=/\w*$/;function r(t){var n=new t.constructor(t.source,e.exec(t));return n.lastIndex=t.lastIndex,n}return Ra=r,Ra}var Aa,Lh;function X1(){if(Lh)return Aa;Lh=1;var e=Yr(),r=e?e.prototype:void 0,t=r?r.valueOf:void 0;function n(o){return t?Object(t.call(o)):{}}return Aa=n,Aa}var Pa,Fh;function nv(){if(Fh)return Pa;Fh=1;var e=Kd();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}return Pa=r,Pa}var Ia,zh;function Y1(){if(zh)return Ia;zh=1;var e=Kd(),r=J1(),t=Z1(),n=X1(),o=nv(),i="[object Boolean]",s="[object Date]",a="[object Map]",c="[object Number]",l="[object RegExp]",d="[object Set]",u="[object String]",h="[object Symbol]",p="[object ArrayBuffer]",m="[object DataView]",y="[object Float32Array]",g="[object Float64Array]",v="[object Int8Array]",b="[object Int16Array]",x="[object Int32Array]",w="[object Uint8Array]",C="[object Uint8ClampedArray]",S="[object Uint16Array]",j="[object Uint32Array]";function P(E,O,A){var R=E.constructor;switch(O){case p:return e(E);case i:case s:return new R(+E);case m:return r(E,A);case y:case g:case v:case b:case x:case w:case C:case S:case j:return o(E,A);case a:return new R;case c:case u:return new R(E);case l:return t(E);case d:return new R;case h:return n(E)}}return Ia=P,Ia}var Ma,Bh;function ov(){if(Bh)return Ma;Bh=1;var e=Lt(),r=Object.create,t=(function(){function n(){}return function(o){if(!e(o))return{};if(r)return r(o);n.prototype=o;var i=new n;return n.prototype=void 0,i}})();return Ma=t,Ma}var Ta,Dh;function iv(){if(Dh)return Ta;Dh=1;var e=ov(),r=_o(),t=jo();function n(o){return typeof o.constructor=="function"&&!t(o)?e(r(o)):{}}return Ta=n,Ta}var Oa,Vh;function Q1(){if(Vh)return Oa;Vh=1;var e=en(),r=Xt(),t="[object Map]";function n(o){return r(o)&&e(o)==t}return Oa=n,Oa}var Na,Gh;function eC(){if(Gh)return Na;Gh=1;var e=Q1(),r=So(),t=Gd(),n=t&&t.isMap,o=n?r(n):e;return Na=o,Na}var $a,Wh;function tC(){if(Wh)return $a;Wh=1;var e=en(),r=Xt(),t="[object Set]";function n(o){return r(o)&&e(o)==t}return $a=n,$a}var qa,Uh;function rC(){if(Uh)return qa;Uh=1;var e=tC(),r=So(),t=Gd(),n=t&&t.isSet,o=n?r(n):e;return qa=o,qa}var La,Hh;function av(){if(Hh)return La;Hh=1;var e=vo(),r=Dd(),t=wo(),n=L1(),o=B1(),i=Kb(),s=Jb(),a=D1(),c=V1(),l=ev(),d=G1(),u=en(),h=K1(),p=Y1(),m=iv(),y=gt(),g=Qr(),v=eC(),b=Lt(),x=rC(),w=mr(),C=Pr(),S=1,j=2,P=4,E="[object Arguments]",O="[object Array]",A="[object Boolean]",R="[object Date]",M="[object Error]",T="[object Function]",N="[object GeneratorFunction]",$="[object Map]",I="[object Number]",K="[object Object]",ie="[object RegExp]",se="[object Set]",te="[object String]",me="[object Symbol]",ve="[object WeakMap]",F="[object ArrayBuffer]",D="[object DataView]",W="[object Float32Array]",B="[object Float64Array]",le="[object Int8Array]",Y="[object Int16Array]",ce="[object Int32Array]",ue="[object Uint8Array]",xe="[object Uint8ClampedArray]",Ce="[object Uint16Array]",ye="[object Uint32Array]",pe={};pe[E]=pe[O]=pe[F]=pe[D]=pe[A]=pe[R]=pe[W]=pe[B]=pe[le]=pe[Y]=pe[ce]=pe[$]=pe[I]=pe[K]=pe[ie]=pe[se]=pe[te]=pe[me]=pe[ue]=pe[xe]=pe[Ce]=pe[ye]=!0,pe[M]=pe[T]=pe[ve]=!1;function X(L,ae,H,fe,be,Ne){var Le,Be=ae&S,tt=ae&j,Je=ae&P;if(H&&(Le=be?H(L,fe,be,Ne):H(L)),Le!==void 0)return Le;if(!b(L))return L;var yt=y(L);if(yt){if(Le=h(L),!Be)return s(L,Le)}else{var Ye=u(L),nt=Ye==T||Ye==N;if(g(L))return i(L,Be);if(Ye==K||Ye==E||nt&&!be){if(Le=tt||nt?{}:m(L),!Be)return tt?c(L,o(Le,L)):a(L,n(Le,L))}else{if(!pe[Ye])return be?L:{};Le=p(L,Ye,Be)}}Ne||(Ne=new e);var ht=Ne.get(L);if(ht)return ht;Ne.set(L,Le),x(L)?L.forEach(function(st){Le.add(X(st,ae,H,st,L,Ne))}):v(L)&&L.forEach(function(st,ct){Le.set(ct,X(st,ae,H,ct,L,Ne))});var Te=Je?tt?d:l:tt?C:w,Ve=yt?void 0:Te(L);return r(Ve||L,function(st,ct){Ve&&(ct=st,st=L[ct]),t(Le,ct,X(st,ae,H,ct,L,Ne))}),Le}return La=X,La}var Fa,Kh;function nC(){if(Kh)return Fa;Kh=1;var e=av(),r=4;function t(n){return e(n,r)}return Fa=t,Fa}var za,Jh;function Jd(){if(Jh)return za;Jh=1;function e(r){return function(){return r}}return za=e,za}var Ba,Zh;function oC(){if(Zh)return Ba;Zh=1;function e(r){return function(t,n,o){for(var i=-1,s=Object(t),a=o(t),c=a.length;c--;){var l=a[r?c:++i];if(n(s[l],l,s)===!1)break}return t}}return Ba=e,Ba}var Da,Xh;function Zd(){if(Xh)return Da;Xh=1;var e=oC(),r=e();return Da=r,Da}var Va,Yh;function Xd(){if(Yh)return Va;Yh=1;var e=Zd(),r=mr();function t(n,o){return n&&e(n,o,r)}return Va=t,Va}var Ga,Qh;function iC(){if(Qh)return Ga;Qh=1;var e=tr();function r(t,n){return function(o,i){if(o==null)return o;if(!e(o))return t(o,i);for(var s=o.length,a=n?s:-1,c=Object(o);(n?a--:++a<s)&&i(c[a],a,c)!==!1;);return o}}return Ga=r,Ga}var Wa,ep;function Eo(){if(ep)return Wa;ep=1;var e=Xd(),r=iC(),t=r(e);return Wa=t,Wa}var Ua,tp;function Ir(){if(tp)return Ua;tp=1;function e(r){return r}return Ua=e,Ua}var Ha,rp;function sv(){if(rp)return Ha;rp=1;var e=Ir();function r(t){return typeof t=="function"?t:e}return Ha=r,Ha}var Ka,np;function cv(){if(np)return Ka;np=1;var e=Dd(),r=Eo(),t=sv(),n=gt();function o(i,s){var a=n(i)?e:r;return a(i,t(s))}return Ka=o,Ka}var Ja,op;function lv(){return op||(op=1,Ja=cv()),Ja}var Za,ip;function aC(){if(ip)return Za;ip=1;var e=Eo();function r(t,n){var o=[];return e(t,function(i,s,a){n(i,s,a)&&o.push(i)}),o}return Za=r,Za}var Xa,ap;function sC(){if(ap)return Xa;ap=1;var e="__lodash_hash_undefined__";function r(t){return this.__data__.set(t,e),this}return Xa=r,Xa}var Ya,sp;function cC(){if(sp)return Ya;sp=1;function e(r){return this.__data__.has(r)}return Ya=e,Ya}var Qa,cp;function dv(){if(cp)return Qa;cp=1;var e=Bd(),r=sC(),t=cC();function n(o){var i=-1,s=o==null?0:o.length;for(this.__data__=new e;++i<s;)this.add(o[i])}return n.prototype.add=n.prototype.push=r,n.prototype.has=t,Qa=n,Qa}var es,lp;function lC(){if(lp)return es;lp=1;function e(r,t){for(var n=-1,o=r==null?0:r.length;++n<o;)if(t(r[n],n,r))return!0;return!1}return es=e,es}var ts,dp;function uv(){if(dp)return ts;dp=1;function e(r,t){return r.has(t)}return ts=e,ts}var rs,up;function fv(){if(up)return rs;up=1;var e=dv(),r=lC(),t=uv(),n=1,o=2;function i(s,a,c,l,d,u){var h=c&n,p=s.length,m=a.length;if(p!=m&&!(h&&m>p))return!1;var y=u.get(s),g=u.get(a);if(y&&g)return y==a&&g==s;var v=-1,b=!0,x=c&o?new e:void 0;for(u.set(s,a),u.set(a,s);++v<p;){var w=s[v],C=a[v];if(l)var S=h?l(C,w,v,a,s,u):l(w,C,v,s,a,u);if(S!==void 0){if(S)continue;b=!1;break}if(x){if(!r(a,function(j,P){if(!t(x,P)&&(w===j||d(w,j,c,l,u)))return x.push(P)})){b=!1;break}}else if(!(w===C||d(w,C,c,l,u))){b=!1;break}}return u.delete(s),u.delete(a),b}return rs=i,rs}var ns,fp;function dC(){if(fp)return ns;fp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o,i){n[++t]=[i,o]}),n}return ns=e,ns}var os,hp;function Yd(){if(hp)return os;hp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o){n[++t]=o}),n}return os=e,os}var is,pp;function uC(){if(pp)return is;pp=1;var e=Yr(),r=rv(),t=Xr(),n=fv(),o=dC(),i=Yd(),s=1,a=2,c="[object Boolean]",l="[object Date]",d="[object Error]",u="[object Map]",h="[object Number]",p="[object RegExp]",m="[object Set]",y="[object String]",g="[object Symbol]",v="[object ArrayBuffer]",b="[object DataView]",x=e?e.prototype:void 0,w=x?x.valueOf:void 0;function C(S,j,P,E,O,A,R){switch(P){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||!A(new r(S),new r(j)));case c:case l:case h:return t(+S,+j);case d:return S.name==j.name&&S.message==j.message;case p:case y:return S==j+"";case u:var M=o;case m:var T=E&s;if(M||(M=i),S.size!=j.size&&!T)return!1;var N=R.get(S);if(N)return N==j;E|=a,R.set(S,j);var $=n(M(S),M(j),E,O,A,R);return R.delete(S),$;case g:if(w)return w.call(S)==w.call(j)}return!1}return is=C,is}var as,gp;function fC(){if(gp)return as;gp=1;var e=ev(),r=1,t=Object.prototype,n=t.hasOwnProperty;function o(i,s,a,c,l,d){var u=a&r,h=e(i),p=h.length,m=e(s),y=m.length;if(p!=y&&!u)return!1;for(var g=p;g--;){var v=h[g];if(!(u?v in s:n.call(s,v)))return!1}var b=d.get(i),x=d.get(s);if(b&&x)return b==s&&x==i;var w=!0;d.set(i,s),d.set(s,i);for(var C=u;++g<p;){v=h[g];var S=i[v],j=s[v];if(c)var P=u?c(j,S,v,s,i,d):c(S,j,v,i,s,d);if(!(P===void 0?S===j||l(S,j,a,c,d):P)){w=!1;break}C||(C=v=="constructor")}if(w&&!C){var E=i.constructor,O=s.constructor;E!=O&&"constructor"in i&&"constructor"in s&&!(typeof E=="function"&&E instanceof E&&typeof O=="function"&&O instanceof O)&&(w=!1)}return d.delete(i),d.delete(s),w}return as=o,as}var ss,yp;function hC(){if(yp)return ss;yp=1;var e=vo(),r=fv(),t=uC(),n=fC(),o=en(),i=gt(),s=Qr(),a=Ln(),c=1,l="[object Arguments]",d="[object Array]",u="[object Object]",h=Object.prototype,p=h.hasOwnProperty;function m(y,g,v,b,x,w){var C=i(y),S=i(g),j=C?d:o(y),P=S?d:o(g);j=j==l?u:j,P=P==l?u:P;var E=j==u,O=P==u,A=j==P;if(A&&s(y)){if(!s(g))return!1;C=!0,E=!1}if(A&&!E)return w||(w=new e),C||a(y)?r(y,g,v,b,x,w):t(y,g,j,v,b,x,w);if(!(v&c)){var R=E&&p.call(y,"__wrapped__"),M=O&&p.call(g,"__wrapped__");if(R||M){var T=R?y.value():y,N=M?g.value():g;return w||(w=new e),x(T,N,v,b,w)}}return A?(w||(w=new e),n(y,g,v,b,x,w)):!1}return ss=m,ss}var cs,mp;function hv(){if(mp)return cs;mp=1;var e=hC(),r=Xt();function t(n,o,i,s,a){return n===o?!0:n==null||o==null||!r(n)&&!r(o)?n!==n&&o!==o:e(n,o,i,s,t,a)}return cs=t,cs}var ls,bp;function pC(){if(bp)return ls;bp=1;var e=vo(),r=hv(),t=1,n=2;function o(i,s,a,c){var l=a.length,d=l,u=!c;if(i==null)return!d;for(i=Object(i);l--;){var h=a[l];if(u&&h[2]?h[1]!==i[h[0]]:!(h[0]in i))return!1}for(;++l<d;){h=a[l];var p=h[0],m=i[p],y=h[1];if(u&&h[2]){if(m===void 0&&!(p in i))return!1}else{var g=new e;if(c)var v=c(m,y,p,i,s,g);if(!(v===void 0?r(y,m,t|n,c,g):v))return!1}}return!0}return ls=o,ls}var ds,vp;function pv(){if(vp)return ds;vp=1;var e=Lt();function r(t){return t===t&&!e(t)}return ds=r,ds}var us,xp;function gC(){if(xp)return us;xp=1;var e=pv(),r=mr();function t(n){for(var o=r(n),i=o.length;i--;){var s=o[i],a=n[s];o[i]=[s,a,e(a)]}return o}return us=t,us}var fs,wp;function gv(){if(wp)return fs;wp=1;function e(r,t){return function(n){return n==null?!1:n[r]===t&&(t!==void 0||r in Object(n))}}return fs=e,fs}var hs,Cp;function yC(){if(Cp)return hs;Cp=1;var e=pC(),r=gC(),t=gv();function n(o){var i=r(o);return i.length==1&&i[0][2]?t(i[0][0],i[0][1]):function(s){return s===o||e(s,o,i)}}return hs=n,hs}var ps,Sp;function tn(){if(Sp)return ps;Sp=1;var e=Rr(),r=Xt(),t="[object Symbol]";function n(o){return typeof o=="symbol"||r(o)&&e(o)==t}return ps=n,ps}var gs,jp;function Qd(){if(jp)return gs;jp=1;var e=gt(),r=tn(),t=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,s){if(e(i))return!1;var a=typeof i;return a=="number"||a=="symbol"||a=="boolean"||i==null||r(i)?!0:n.test(i)||!t.test(i)||s!=null&&i in Object(s)}return gs=o,gs}var ys,_p;function mC(){if(_p)return ys;_p=1;var e=Bd(),r="Expected a function";function t(n,o){if(typeof n!="function"||o!=null&&typeof o!="function")throw new TypeError(r);var i=function(){var s=arguments,a=o?o.apply(this,s):s[0],c=i.cache;if(c.has(a))return c.get(a);var l=n.apply(this,s);return i.cache=c.set(a,l)||c,l};return i.cache=new(t.Cache||e),i}return t.Cache=e,ys=t,ys}var ms,Ep;function bC(){if(Ep)return ms;Ep=1;var e=mC(),r=500;function t(n){var o=e(n,function(s){return i.size===r&&i.clear(),s}),i=o.cache;return o}return ms=t,ms}var bs,kp;function vC(){if(kp)return bs;kp=1;var e=bC(),r=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,t=/\\(\\)?/g,n=e(function(o){var i=[];return o.charCodeAt(0)===46&&i.push(""),o.replace(r,function(s,a,c,l){i.push(c?l.replace(t,"$1"):a||s)}),i});return bs=n,bs}var vs,Rp;function ko(){if(Rp)return vs;Rp=1;function e(r,t){for(var n=-1,o=r==null?0:r.length,i=Array(o);++n<o;)i[n]=t(r[n],n,r);return i}return vs=e,vs}var xs,Ap;function xC(){if(Ap)return xs;Ap=1;var e=Yr(),r=ko(),t=gt(),n=tn(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function s(a){if(typeof a=="string")return a;if(t(a))return r(a,s)+"";if(n(a))return i?i.call(a):"";var c=a+"";return c=="0"&&1/a==-1/0?"-0":c}return xs=s,xs}var ws,Pp;function yv(){if(Pp)return ws;Pp=1;var e=xC();function r(t){return t==null?"":e(t)}return ws=r,ws}var Cs,Ip;function Ro(){if(Ip)return Cs;Ip=1;var e=gt(),r=Qd(),t=vC(),n=yv();function o(i,s){return e(i)?i:r(i,s)?[i]:t(n(i))}return Cs=o,Cs}var Ss,Mp;function Fn(){if(Mp)return Ss;Mp=1;var e=tn();function r(t){if(typeof t=="string"||e(t))return t;var n=t+"";return n=="0"&&1/t==-1/0?"-0":n}return Ss=r,Ss}var js,Tp;function Ao(){if(Tp)return js;Tp=1;var e=Ro(),r=Fn();function t(n,o){o=e(o,n);for(var i=0,s=o.length;n!=null&&i<s;)n=n[r(o[i++])];return i&&i==s?n:void 0}return js=t,js}var _s,Op;function wC(){if(Op)return _s;Op=1;var e=Ao();function r(t,n,o){var i=t==null?void 0:e(t,n);return i===void 0?o:i}return _s=r,_s}var Es,Np;function CC(){if(Np)return Es;Np=1;function e(r,t){return r!=null&&t in Object(r)}return Es=e,Es}var ks,$p;function mv(){if($p)return ks;$p=1;var e=Ro(),r=qn(),t=gt(),n=Co(),o=Vd(),i=Fn();function s(a,c,l){c=e(c,a);for(var d=-1,u=c.length,h=!1;++d<u;){var p=i(c[d]);if(!(h=a!=null&&l(a,p)))break;a=a[p]}return h||++d!=u?h:(u=a==null?0:a.length,!!u&&o(u)&&n(p,u)&&(t(a)||r(a)))}return ks=s,ks}var Rs,qp;function bv(){if(qp)return Rs;qp=1;var e=CC(),r=mv();function t(n,o){return n!=null&&r(n,o,e)}return Rs=t,Rs}var As,Lp;function SC(){if(Lp)return As;Lp=1;var e=hv(),r=wC(),t=bv(),n=Qd(),o=pv(),i=gv(),s=Fn(),a=1,c=2;function l(d,u){return n(d)&&o(u)?i(s(d),u):function(h){var p=r(h,d);return p===void 0&&p===u?t(h,d):e(u,p,a|c)}}return As=l,As}var Ps,Fp;function vv(){if(Fp)return Ps;Fp=1;function e(r){return function(t){return t==null?void 0:t[r]}}return Ps=e,Ps}var Is,zp;function jC(){if(zp)return Is;zp=1;var e=Ao();function r(t){return function(n){return e(n,t)}}return Is=r,Is}var Ms,Bp;function _C(){if(Bp)return Ms;Bp=1;var e=vv(),r=jC(),t=Qd(),n=Fn();function o(i){return t(i)?e(n(i)):r(i)}return Ms=o,Ms}var Ts,Dp;function rr(){if(Dp)return Ts;Dp=1;var e=yC(),r=SC(),t=Ir(),n=gt(),o=_C();function i(s){return typeof s=="function"?s:s==null?t:typeof s=="object"?n(s)?r(s[0],s[1]):e(s):o(s)}return Ts=i,Ts}var Os,Vp;function xv(){if(Vp)return Os;Vp=1;var e=Zb(),r=aC(),t=rr(),n=gt();function o(i,s){var a=n(i)?e:r;return a(i,t(s,3))}return Os=o,Os}var Ns,Gp;function EC(){if(Gp)return Ns;Gp=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n,o){return n!=null&&r.call(n,o)}return Ns=t,Ns}var $s,Wp;function wv(){if(Wp)return $s;Wp=1;var e=EC(),r=mv();function t(n,o){return n!=null&&r(n,o,e)}return $s=t,$s}var qs,Up;function kC(){if(Up)return qs;Up=1;var e=Wd(),r=en(),t=qn(),n=gt(),o=tr(),i=Qr(),s=jo(),a=Ln(),c="[object Map]",l="[object Set]",d=Object.prototype,u=d.hasOwnProperty;function h(p){if(p==null)return!0;if(o(p)&&(n(p)||typeof p=="string"||typeof p.splice=="function"||i(p)||a(p)||t(p)))return!p.length;var m=r(p);if(m==c||m==l)return!p.size;if(s(p))return!e(p).length;for(var y in p)if(u.call(p,y))return!1;return!0}return qs=h,qs}var Ls,Hp;function Cv(){if(Hp)return Ls;Hp=1;function e(r){return r===void 0}return Ls=e,Ls}var Fs,Kp;function Sv(){if(Kp)return Fs;Kp=1;var e=Eo(),r=tr();function t(n,o){var i=-1,s=r(n)?Array(n.length):[];return e(n,function(a,c,l){s[++i]=o(a,c,l)}),s}return Fs=t,Fs}var zs,Jp;function jv(){if(Jp)return zs;Jp=1;var e=ko(),r=rr(),t=Sv(),n=gt();function o(i,s){var a=n(i)?e:t;return a(i,r(s,3))}return zs=o,zs}var Bs,Zp;function RC(){if(Zp)return Bs;Zp=1;function e(r,t,n,o){var i=-1,s=r==null?0:r.length;for(o&&s&&(n=r[++i]);++i<s;)n=t(n,r[i],i,r);return n}return Bs=e,Bs}var Ds,Xp;function AC(){if(Xp)return Ds;Xp=1;function e(r,t,n,o,i){return i(r,function(s,a,c){n=o?(o=!1,s):t(n,s,a,c)}),n}return Ds=e,Ds}var Vs,Yp;function _v(){if(Yp)return Vs;Yp=1;var e=RC(),r=Eo(),t=rr(),n=AC(),o=gt();function i(s,a,c){var l=o(s)?e:n,d=arguments.length<3;return l(s,t(a,4),c,d,r)}return Vs=i,Vs}var Gs,Qp;function PC(){if(Qp)return Gs;Qp=1;var e=Rr(),r=gt(),t=Xt(),n="[object String]";function o(i){return typeof i=="string"||!r(i)&&t(i)&&e(i)==n}return Gs=o,Gs}var Ws,eg;function IC(){if(eg)return Ws;eg=1;var e=vv(),r=e("length");return Ws=r,Ws}var Us,tg;function MC(){if(tg)return Us;tg=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=r+t+n,i="\\ufe0e\\ufe0f",s="\\u200d",a=RegExp("["+s+e+o+i+"]");function c(l){return a.test(l)}return Us=c,Us}var Hs,rg;function TC(){if(rg)return Hs;rg=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=r+t+n,i="\\ufe0e\\ufe0f",s="["+e+"]",a="["+o+"]",c="\\ud83c[\\udffb-\\udfff]",l="(?:"+a+"|"+c+")",d="[^"+e+"]",u="(?:\\ud83c[\\udde6-\\uddff]){2}",h="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",m=l+"?",y="["+i+"]?",g="(?:"+p+"(?:"+[d,u,h].join("|")+")"+y+m+")*",v=y+m+g,b="(?:"+[d+a+"?",a,u,h,s].join("|")+")",x=RegExp(c+"(?="+c+")|"+b+v,"g");function w(C){for(var S=x.lastIndex=0;x.test(C);)++S;return S}return Hs=w,Hs}var Ks,ng;function OC(){if(ng)return Ks;ng=1;var e=IC(),r=MC(),t=TC();function n(o){return r(o)?t(o):e(o)}return Ks=n,Ks}var Js,og;function NC(){if(og)return Js;og=1;var e=Wd(),r=en(),t=tr(),n=PC(),o=OC(),i="[object Map]",s="[object Set]";function a(c){if(c==null)return 0;if(t(c))return n(c)?o(c):c.length;var l=r(c);return l==i||l==s?c.size:e(c).length}return Js=a,Js}var Zs,ig;function $C(){if(ig)return Zs;ig=1;var e=Dd(),r=ov(),t=Xd(),n=rr(),o=_o(),i=gt(),s=Qr(),a=Nn(),c=Lt(),l=Ln();function d(u,h,p){var m=i(u),y=m||s(u)||l(u);if(h=n(h,4),p==null){var g=u&&u.constructor;y?p=m?new g:[]:c(u)?p=a(g)?r(o(u)):{}:p={}}return(y?e:t)(u,function(v,b,x){return h(p,v,b,x)}),p}return Zs=d,Zs}var Xs,ag;function qC(){if(ag)return Xs;ag=1;var e=Yr(),r=qn(),t=gt(),n=e?e.isConcatSpreadable:void 0;function o(i){return t(i)||r(i)||!!(n&&i&&i[n])}return Xs=o,Xs}var Ys,sg;function eu(){if(sg)return Ys;sg=1;var e=Hd(),r=qC();function t(n,o,i,s,a){var c=-1,l=n.length;for(i||(i=r),a||(a=[]);++c<l;){var d=n[c];o>0&&i(d)?o>1?t(d,o-1,i,s,a):e(a,d):s||(a[a.length]=d)}return a}return Ys=t,Ys}var Qs,cg;function LC(){if(cg)return Qs;cg=1;function e(r,t,n){switch(n.length){case 0:return r.call(t);case 1:return r.call(t,n[0]);case 2:return r.call(t,n[0],n[1]);case 3:return r.call(t,n[0],n[1],n[2])}return r.apply(t,n)}return Qs=e,Qs}var ec,lg;function Ev(){if(lg)return ec;lg=1;var e=LC(),r=Math.max;function t(n,o,i){return o=r(o===void 0?n.length-1:o,0),function(){for(var s=arguments,a=-1,c=r(s.length-o,0),l=Array(c);++a<c;)l[a]=s[o+a];a=-1;for(var d=Array(o+1);++a<o;)d[a]=s[a];return d[o]=i(l),e(n,this,d)}}return ec=t,ec}var tc,dg;function FC(){if(dg)return tc;dg=1;var e=Jd(),r=Wb(),t=Ir(),n=r?function(o,i){return r(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:t;return tc=n,tc}var rc,ug;function zC(){if(ug)return rc;ug=1;var e=800,r=16,t=Date.now;function n(o){var i=0,s=0;return function(){var a=t(),c=r-(a-s);if(s=a,c>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return rc=n,rc}var nc,fg;function kv(){if(fg)return nc;fg=1;var e=FC(),r=zC(),t=r(e);return nc=t,nc}var oc,hg;function Po(){if(hg)return oc;hg=1;var e=Ir(),r=Ev(),t=kv();function n(o,i){return t(r(o,i,e),o+"")}return oc=n,oc}var ic,pg;function Rv(){if(pg)return ic;pg=1;function e(r,t,n,o){for(var i=r.length,s=n+(o?1:-1);o?s--:++s<i;)if(t(r[s],s,r))return s;return-1}return ic=e,ic}var ac,gg;function BC(){if(gg)return ac;gg=1;function e(r){return r!==r}return ac=e,ac}var sc,yg;function DC(){if(yg)return sc;yg=1;function e(r,t,n){for(var o=n-1,i=r.length;++o<i;)if(r[o]===t)return o;return-1}return sc=e,sc}var cc,mg;function VC(){if(mg)return cc;mg=1;var e=Rv(),r=BC(),t=DC();function n(o,i,s){return i===i?t(o,i,s):e(o,r,s)}return cc=n,cc}var lc,bg;function GC(){if(bg)return lc;bg=1;var e=VC();function r(t,n){var o=t==null?0:t.length;return!!o&&e(t,n,0)>-1}return lc=r,lc}var dc,vg;function WC(){if(vg)return dc;vg=1;function e(r,t,n){for(var o=-1,i=r==null?0:r.length;++o<i;)if(n(t,r[o]))return!0;return!1}return dc=e,dc}var uc,xg;function UC(){if(xg)return uc;xg=1;function e(){}return uc=e,uc}var fc,wg;function HC(){if(wg)return fc;wg=1;var e=tv(),r=UC(),t=Yd(),n=1/0,o=e&&1/t(new e([,-0]))[1]==n?function(i){return new e(i)}:r;return fc=o,fc}var hc,Cg;function KC(){if(Cg)return hc;Cg=1;var e=dv(),r=GC(),t=WC(),n=uv(),o=HC(),i=Yd(),s=200;function a(c,l,d){var u=-1,h=r,p=c.length,m=!0,y=[],g=y;if(d)m=!1,h=t;else if(p>=s){var v=l?null:o(c);if(v)return i(v);m=!1,h=n,g=new e}else g=l?[]:y;e:for(;++u<p;){var b=c[u],x=l?l(b):b;if(b=d||b!==0?b:0,m&&x===x){for(var w=g.length;w--;)if(g[w]===x)continue e;l&&g.push(x),y.push(b)}else h(g,x,d)||(g!==y&&g.push(x),y.push(b))}return y}return hc=a,hc}var pc,Sg;function Av(){if(Sg)return pc;Sg=1;var e=tr(),r=Xt();function t(n){return r(n)&&e(n)}return pc=t,pc}var gc,jg;function JC(){if(jg)return gc;jg=1;var e=eu(),r=Po(),t=KC(),n=Av(),o=r(function(i){return t(e(i,1,n,!0))});return gc=o,gc}var yc,_g;function ZC(){if(_g)return yc;_g=1;var e=ko();function r(t,n){return e(n,function(o){return t[o]})}return yc=r,yc}var mc,Eg;function Pv(){if(Eg)return mc;Eg=1;var e=ZC(),r=mr();function t(n){return n==null?[]:e(n,r(n))}return mc=t,mc}var bc,kg;function Ft(){if(kg)return bc;kg=1;var e;if(typeof Fd=="function")try{e={clone:nC(),constant:Jd(),each:lv(),filter:xv(),has:wv(),isArray:gt(),isEmpty:kC(),isFunction:Nn(),isUndefined:Cv(),keys:mr(),map:jv(),reduce:_v(),size:NC(),transform:$C(),union:JC(),values:Pv()}}catch{}return e||(e=window._),bc=e,bc}var vc,Rg;function tu(){if(Rg)return vc;Rg=1;var e=Ft();vc=o;var r="\0",t="\0",n="";function o(d){this._isDirected=e.has(d,"directed")?d.directed:!0,this._isMultigraph=e.has(d,"multigraph")?d.multigraph:!1,this._isCompound=e.has(d,"compound")?d.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[t]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}o.prototype._nodeCount=0,o.prototype._edgeCount=0,o.prototype.isDirected=function(){return this._isDirected},o.prototype.isMultigraph=function(){return this._isMultigraph},o.prototype.isCompound=function(){return this._isCompound},o.prototype.setGraph=function(d){return this._label=d,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultNodeLabelFn=d,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._in[u])})},o.prototype.sinks=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._out[u])})},o.prototype.setNodes=function(d,u){var h=arguments,p=this;return e.each(d,function(m){h.length>1?p.setNode(m,u):p.setNode(m)}),this},o.prototype.setNode=function(d,u){return e.has(this._nodes,d)?(arguments.length>1&&(this._nodes[d]=u),this):(this._nodes[d]=arguments.length>1?u:this._defaultNodeLabelFn(d),this._isCompound&&(this._parent[d]=t,this._children[d]={},this._children[t][d]=!0),this._in[d]={},this._preds[d]={},this._out[d]={},this._sucs[d]={},++this._nodeCount,this)},o.prototype.node=function(d){return this._nodes[d]},o.prototype.hasNode=function(d){return e.has(this._nodes,d)},o.prototype.removeNode=function(d){var u=this;if(e.has(this._nodes,d)){var h=function(p){u.removeEdge(u._edgeObjs[p])};delete this._nodes[d],this._isCompound&&(this._removeFromParentsChildList(d),delete this._parent[d],e.each(this.children(d),function(p){u.setParent(p)}),delete this._children[d]),e.each(e.keys(this._in[d]),h),delete this._in[d],delete this._preds[d],e.each(e.keys(this._out[d]),h),delete this._out[d],delete this._sucs[d],--this._nodeCount}return this},o.prototype.setParent=function(d,u){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(u))u=t;else{u+="";for(var h=u;!e.isUndefined(h);h=this.parent(h))if(h===d)throw new Error("Setting "+u+" as parent of "+d+" would create a cycle");this.setNode(u)}return this.setNode(d),this._removeFromParentsChildList(d),this._parent[d]=u,this._children[u][d]=!0,this},o.prototype._removeFromParentsChildList=function(d){delete this._children[this._parent[d]][d]},o.prototype.parent=function(d){if(this._isCompound){var u=this._parent[d];if(u!==t)return u}},o.prototype.children=function(d){if(e.isUndefined(d)&&(d=t),this._isCompound){var u=this._children[d];if(u)return e.keys(u)}else{if(d===t)return this.nodes();if(this.hasNode(d))return[]}},o.prototype.predecessors=function(d){var u=this._preds[d];if(u)return e.keys(u)},o.prototype.successors=function(d){var u=this._sucs[d];if(u)return e.keys(u)},o.prototype.neighbors=function(d){var u=this.predecessors(d);if(u)return e.union(u,this.successors(d))},o.prototype.isLeaf=function(d){var u;return this.isDirected()?u=this.successors(d):u=this.neighbors(d),u.length===0},o.prototype.filterNodes=function(d){var u=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});u.setGraph(this.graph());var h=this;e.each(this._nodes,function(y,g){d(g)&&u.setNode(g,y)}),e.each(this._edgeObjs,function(y){u.hasNode(y.v)&&u.hasNode(y.w)&&u.setEdge(y,h.edge(y))});var p={};function m(y){var g=h.parent(y);return g===void 0||u.hasNode(g)?(p[y]=g,g):g in p?p[g]:m(g)}return this._isCompound&&e.each(u.nodes(),function(y){u.setParent(y,m(y))}),u},o.prototype.setDefaultEdgeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultEdgeLabelFn=d,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(d,u){var h=this,p=arguments;return e.reduce(d,function(m,y){return p.length>1?h.setEdge(m,y,u):h.setEdge(m,y),y}),this},o.prototype.setEdge=function(){var d,u,h,p,m=!1,y=arguments[0];typeof y=="object"&&y!==null&&"v"in y?(d=y.v,u=y.w,h=y.name,arguments.length===2&&(p=arguments[1],m=!0)):(d=y,u=arguments[1],h=arguments[3],arguments.length>2&&(p=arguments[2],m=!0)),d=""+d,u=""+u,e.isUndefined(h)||(h=""+h);var g=a(this._isDirected,d,u,h);if(e.has(this._edgeLabels,g))return m&&(this._edgeLabels[g]=p),this;if(!e.isUndefined(h)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(d),this.setNode(u),this._edgeLabels[g]=m?p:this._defaultEdgeLabelFn(d,u,h);var v=c(this._isDirected,d,u,h);return d=v.v,u=v.w,Object.freeze(v),this._edgeObjs[g]=v,i(this._preds[u],d),i(this._sucs[d],u),this._in[u][g]=v,this._out[d][g]=v,this._edgeCount++,this},o.prototype.edge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h);return this._edgeLabels[p]},o.prototype.hasEdge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h);return e.has(this._edgeLabels,p)},o.prototype.removeEdge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h),m=this._edgeObjs[p];return m&&(d=m.v,u=m.w,delete this._edgeLabels[p],delete this._edgeObjs[p],s(this._preds[u],d),s(this._sucs[d],u),delete this._in[u][p],delete this._out[d][p],this._edgeCount--),this},o.prototype.inEdges=function(d,u){var h=this._in[d];if(h){var p=e.values(h);return u?e.filter(p,function(m){return m.v===u}):p}},o.prototype.outEdges=function(d,u){var h=this._out[d];if(h){var p=e.values(h);return u?e.filter(p,function(m){return m.w===u}):p}},o.prototype.nodeEdges=function(d,u){var h=this.inEdges(d,u);if(h)return h.concat(this.outEdges(d,u))};function i(d,u){d[u]?d[u]++:d[u]=1}function s(d,u){--d[u]||delete d[u]}function a(d,u,h,p){var m=""+u,y=""+h;if(!d&&m>y){var g=m;m=y,y=g}return m+n+y+n+(e.isUndefined(p)?r:p)}function c(d,u,h,p){var m=""+u,y=""+h;if(!d&&m>y){var g=m;m=y,y=g}var v={v:m,w:y};return p&&(v.name=p),v}function l(d,u){return a(d,u.v,u.w,u.name)}return vc}var xc,Ag;function XC(){return Ag||(Ag=1,xc="2.1.8"),xc}var wc,Pg;function YC(){return Pg||(Pg=1,wc={Graph:tu(),version:XC()}),wc}var Cc,Ig;function QC(){if(Ig)return Cc;Ig=1;var e=Ft(),r=tu();Cc={write:t,read:i};function t(s){var a={options:{directed:s.isDirected(),multigraph:s.isMultigraph(),compound:s.isCompound()},nodes:n(s),edges:o(s)};return e.isUndefined(s.graph())||(a.value=e.clone(s.graph())),a}function n(s){return e.map(s.nodes(),function(a){var c=s.node(a),l=s.parent(a),d={v:a};return e.isUndefined(c)||(d.value=c),e.isUndefined(l)||(d.parent=l),d})}function o(s){return e.map(s.edges(),function(a){var c=s.edge(a),l={v:a.v,w:a.w};return e.isUndefined(a.name)||(l.name=a.name),e.isUndefined(c)||(l.value=c),l})}function i(s){var a=new r(s.options).setGraph(s.value);return e.each(s.nodes,function(c){a.setNode(c.v,c.value),c.parent&&a.setParent(c.v,c.parent)}),e.each(s.edges,function(c){a.setEdge({v:c.v,w:c.w,name:c.name},c.value)}),a}return Cc}var Sc,Mg;function eS(){if(Mg)return Sc;Mg=1;var e=Ft();Sc=r;function r(t){var n={},o=[],i;function s(a){e.has(n,a)||(n[a]=!0,i.push(a),e.each(t.successors(a),s),e.each(t.predecessors(a),s))}return e.each(t.nodes(),function(a){i=[],s(a),i.length&&o.push(i)}),o}return Sc}var jc,Tg;function Iv(){if(Tg)return jc;Tg=1;var e=Ft();jc=r;function r(){this._arr=[],this._keyIndices={}}return r.prototype.size=function(){return this._arr.length},r.prototype.keys=function(){return this._arr.map(function(t){return t.key})},r.prototype.has=function(t){return e.has(this._keyIndices,t)},r.prototype.priority=function(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority},r.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},r.prototype.add=function(t,n){var o=this._keyIndices;if(t=String(t),!e.has(o,t)){var i=this._arr,s=i.length;return o[t]=s,i.push({key:t,priority:n}),this._decrease(s),!0}return!1},r.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key},r.prototype.decrease=function(t,n){var o=this._keyIndices[t];if(n>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[o].priority+" New: "+n);this._arr[o].priority=n,this._decrease(o)},r.prototype._heapify=function(t){var n=this._arr,o=2*t,i=o+1,s=t;o<n.length&&(s=n[o].priority<n[s].priority?o:s,i<n.length&&(s=n[i].priority<n[s].priority?i:s),s!==t&&(this._swap(t,s),this._heapify(s)))},r.prototype._decrease=function(t){for(var n=this._arr,o=n[t].priority,i;t!==0&&(i=t>>1,!(n[i].priority<o));)this._swap(t,i),t=i},r.prototype._swap=function(t,n){var o=this._arr,i=this._keyIndices,s=o[t],a=o[n];o[t]=a,o[n]=s,i[a.key]=t,i[s.key]=n},jc}var _c,Og;function Mv(){if(Og)return _c;Og=1;var e=Ft(),r=Iv();_c=n;var t=e.constant(1);function n(i,s,a,c){return o(i,String(s),a||t,c||function(l){return i.outEdges(l)})}function o(i,s,a,c){var l={},d=new r,u,h,p=function(m){var y=m.v!==u?m.v:m.w,g=l[y],v=a(m),b=h.distance+v;if(v<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+m+" Weight: "+v);b<g.distance&&(g.distance=b,g.predecessor=u,d.decrease(y,b))};for(i.nodes().forEach(function(m){var y=m===s?0:Number.POSITIVE_INFINITY;l[m]={distance:y},d.add(m,y)});d.size()>0&&(u=d.removeMin(),h=l[u],h.distance!==Number.POSITIVE_INFINITY);)c(u).forEach(p);return l}return _c}var Ec,Ng;function tS(){if(Ng)return Ec;Ng=1;var e=Mv(),r=Ft();Ec=t;function t(n,o,i){return r.transform(n.nodes(),function(s,a){s[a]=e(n,a,o,i)},{})}return Ec}var kc,$g;function Tv(){if($g)return kc;$g=1;var e=Ft();kc=r;function r(t){var n=0,o=[],i={},s=[];function a(c){var l=i[c]={onStack:!0,lowlink:n,index:n++};if(o.push(c),t.successors(c).forEach(function(h){e.has(i,h)?i[h].onStack&&(l.lowlink=Math.min(l.lowlink,i[h].index)):(a(h),l.lowlink=Math.min(l.lowlink,i[h].lowlink))}),l.lowlink===l.index){var d=[],u;do u=o.pop(),i[u].onStack=!1,d.push(u);while(c!==u);s.push(d)}}return t.nodes().forEach(function(c){e.has(i,c)||a(c)}),s}return kc}var Rc,qg;function rS(){if(qg)return Rc;qg=1;var e=Ft(),r=Tv();Rc=t;function t(n){return e.filter(r(n),function(o){return o.length>1||o.length===1&&n.hasEdge(o[0],o[0])})}return Rc}var Ac,Lg;function nS(){if(Lg)return Ac;Lg=1;var e=Ft();Ac=t;var r=e.constant(1);function t(o,i,s){return n(o,i||r,s||function(a){return o.outEdges(a)})}function n(o,i,s){var a={},c=o.nodes();return c.forEach(function(l){a[l]={},a[l][l]={distance:0},c.forEach(function(d){l!==d&&(a[l][d]={distance:Number.POSITIVE_INFINITY})}),s(l).forEach(function(d){var u=d.v===l?d.w:d.v,h=i(d);a[l][u]={distance:h,predecessor:l}})}),c.forEach(function(l){var d=a[l];c.forEach(function(u){var h=a[u];c.forEach(function(p){var m=h[l],y=d[p],g=h[p],v=m.distance+y.distance;v<g.distance&&(g.distance=v,g.predecessor=y.predecessor)})})}),a}return Ac}var Pc,Fg;function Ov(){if(Fg)return Pc;Fg=1;var e=Ft();Pc=r,r.CycleException=t;function r(n){var o={},i={},s=[];function a(c){if(e.has(i,c))throw new t;e.has(o,c)||(i[c]=!0,o[c]=!0,e.each(n.predecessors(c),a),delete i[c],s.push(c))}if(e.each(n.sinks(),a),e.size(o)!==n.nodeCount())throw new t;return s}function t(){}return t.prototype=new Error,Pc}var Ic,zg;function oS(){if(zg)return Ic;zg=1;var e=Ov();Ic=r;function r(t){try{e(t)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Ic}var Mc,Bg;function Nv(){if(Bg)return Mc;Bg=1;var e=Ft();Mc=r;function r(n,o,i){e.isArray(o)||(o=[o]);var s=(n.isDirected()?n.successors:n.neighbors).bind(n),a=[],c={};return e.each(o,function(l){if(!n.hasNode(l))throw new Error("Graph does not have node: "+l);t(n,l,i==="post",c,s,a)}),a}function t(n,o,i,s,a,c){e.has(s,o)||(s[o]=!0,i||c.push(o),e.each(a(o),function(l){t(n,l,i,s,a,c)}),i&&c.push(o))}return Mc}var Tc,Dg;function iS(){if(Dg)return Tc;Dg=1;var e=Nv();Tc=r;function r(t,n){return e(t,n,"post")}return Tc}var Oc,Vg;function aS(){if(Vg)return Oc;Vg=1;var e=Nv();Oc=r;function r(t,n){return e(t,n,"pre")}return Oc}var Nc,Gg;function sS(){if(Gg)return Nc;Gg=1;var e=Ft(),r=tu(),t=Iv();Nc=n;function n(o,i){var s=new r,a={},c=new t,l;function d(h){var p=h.v===l?h.w:h.v,m=c.priority(p);if(m!==void 0){var y=i(h);y<m&&(a[p]=l,c.decrease(p,y))}}if(o.nodeCount()===0)return s;e.each(o.nodes(),function(h){c.add(h,Number.POSITIVE_INFINITY),s.setNode(h)}),c.decrease(o.nodes()[0],0);for(var u=!1;c.size()>0;){if(l=c.removeMin(),e.has(a,l))s.setEdge(l,a[l]);else{if(u)throw new Error("Input graph is not connected: "+o);u=!0}o.nodeEdges(l).forEach(d)}return s}return Nc}var $c,Wg;function cS(){return Wg||(Wg=1,$c={components:eS(),dijkstra:Mv(),dijkstraAll:tS(),findCycles:rS(),floydWarshall:nS(),isAcyclic:oS(),postorder:iS(),preorder:aS(),prim:sS(),tarjan:Tv(),topsort:Ov()}),$c}var qc,Ug;function lS(){if(Ug)return qc;Ug=1;var e=YC();return qc={Graph:e.Graph,json:QC(),alg:cS(),version:e.version},qc}var Lc,Hg;function Vt(){if(Hg)return Lc;Hg=1;var e;if(typeof Fd=="function")try{e=lS()}catch{}return e||(e=window.graphlib),Lc=e,Lc}var Fc,Kg;function dS(){if(Kg)return Fc;Kg=1;var e=av(),r=1,t=4;function n(o){return e(o,r|t)}return Fc=n,Fc}var zc,Jg;function Io(){if(Jg)return zc;Jg=1;var e=Xr(),r=tr(),t=Co(),n=Lt();function o(i,s,a){if(!n(a))return!1;var c=typeof s;return(c=="number"?r(a)&&t(s,a.length):c=="string"&&s in a)?e(a[s],i):!1}return zc=o,zc}var Bc,Zg;function uS(){if(Zg)return Bc;Zg=1;var e=Po(),r=Xr(),t=Io(),n=Pr(),o=Object.prototype,i=o.hasOwnProperty,s=e(function(a,c){a=Object(a);var l=-1,d=c.length,u=d>2?c[2]:void 0;for(u&&t(c[0],c[1],u)&&(d=1);++l<d;)for(var h=c[l],p=n(h),m=-1,y=p.length;++m<y;){var g=p[m],v=a[g];(v===void 0||r(v,o[g])&&!i.call(a,g))&&(a[g]=h[g])}return a});return Bc=s,Bc}var Dc,Xg;function fS(){if(Xg)return Dc;Xg=1;var e=rr(),r=tr(),t=mr();function n(o){return function(i,s,a){var c=Object(i);if(!r(i)){var l=e(s,3);i=t(i),s=function(u){return l(c[u],u,c)}}var d=o(i,s,a);return d>-1?c[l?i[d]:d]:void 0}}return Dc=n,Dc}var Vc,Yg;function hS(){if(Yg)return Vc;Yg=1;var e=/\s/;function r(t){for(var n=t.length;n--&&e.test(t.charAt(n)););return n}return Vc=r,Vc}var Gc,Qg;function pS(){if(Qg)return Gc;Qg=1;var e=hS(),r=/^\s+/;function t(n){return n&&n.slice(0,e(n)+1).replace(r,"")}return Gc=t,Gc}var Wc,ey;function gS(){if(ey)return Wc;ey=1;var e=pS(),r=Lt(),t=tn(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,s=/^0o[0-7]+$/i,a=parseInt;function c(l){if(typeof l=="number")return l;if(t(l))return n;if(r(l)){var d=typeof l.valueOf=="function"?l.valueOf():l;l=r(d)?d+"":d}if(typeof l!="string")return l===0?l:+l;l=e(l);var u=i.test(l);return u||s.test(l)?a(l.slice(2),u?2:8):o.test(l)?n:+l}return Wc=c,Wc}var Uc,ty;function $v(){if(ty)return Uc;ty=1;var e=gS(),r=1/0,t=17976931348623157e292;function n(o){if(!o)return o===0?o:0;if(o=e(o),o===r||o===-r){var i=o<0?-1:1;return i*t}return o===o?o:0}return Uc=n,Uc}var Hc,ry;function yS(){if(ry)return Hc;ry=1;var e=$v();function r(t){var n=e(t),o=n%1;return n===n?o?n-o:n:0}return Hc=r,Hc}var Kc,ny;function mS(){if(ny)return Kc;ny=1;var e=Rv(),r=rr(),t=yS(),n=Math.max;function o(i,s,a){var c=i==null?0:i.length;if(!c)return-1;var l=a==null?0:t(a);return l<0&&(l=n(c+l,0)),e(i,r(s,3),l)}return Kc=o,Kc}var Jc,oy;function bS(){if(oy)return Jc;oy=1;var e=fS(),r=mS(),t=e(r);return Jc=t,Jc}var Zc,iy;function qv(){if(iy)return Zc;iy=1;var e=eu();function r(t){var n=t==null?0:t.length;return n?e(t,1):[]}return Zc=r,Zc}var Xc,ay;function vS(){if(ay)return Xc;ay=1;var e=Zd(),r=sv(),t=Pr();function n(o,i){return o==null?o:e(o,r(i),t)}return Xc=n,Xc}var Yc,sy;function xS(){if(sy)return Yc;sy=1;function e(r){var t=r==null?0:r.length;return t?r[t-1]:void 0}return Yc=e,Yc}var Qc,cy;function wS(){if(cy)return Qc;cy=1;var e=xo(),r=Xd(),t=rr();function n(o,i){var s={};return i=t(i,3),r(o,function(a,c,l){e(s,c,i(a,c,l))}),s}return Qc=n,Qc}var el,ly;function ru(){if(ly)return el;ly=1;var e=tn();function r(t,n,o){for(var i=-1,s=t.length;++i<s;){var a=t[i],c=n(a);if(c!=null&&(l===void 0?c===c&&!e(c):o(c,l)))var l=c,d=a}return d}return el=r,el}var tl,dy;function CS(){if(dy)return tl;dy=1;function e(r,t){return r>t}return tl=e,tl}var rl,uy;function SS(){if(uy)return rl;uy=1;var e=ru(),r=CS(),t=Ir();function n(o){return o&&o.length?e(o,t,r):void 0}return rl=n,rl}var nl,fy;function Lv(){if(fy)return nl;fy=1;var e=xo(),r=Xr();function t(n,o,i){(i!==void 0&&!r(n[o],i)||i===void 0&&!(o in n))&&e(n,o,i)}return nl=t,nl}var ol,hy;function jS(){if(hy)return ol;hy=1;var e=Rr(),r=_o(),t=Xt(),n="[object Object]",o=Function.prototype,i=Object.prototype,s=o.toString,a=i.hasOwnProperty,c=s.call(Object);function l(d){if(!t(d)||e(d)!=n)return!1;var u=r(d);if(u===null)return!0;var h=a.call(u,"constructor")&&u.constructor;return typeof h=="function"&&h instanceof h&&s.call(h)==c}return ol=l,ol}var il,py;function Fv(){if(py)return il;py=1;function e(r,t){if(!(t==="constructor"&&typeof r[t]=="function")&&t!="__proto__")return r[t]}return il=e,il}var al,gy;function _S(){if(gy)return al;gy=1;var e=$n(),r=Pr();function t(n){return e(n,r(n))}return al=t,al}var sl,yy;function ES(){if(yy)return sl;yy=1;var e=Lv(),r=Kb(),t=nv(),n=Jb(),o=iv(),i=qn(),s=gt(),a=Av(),c=Qr(),l=Nn(),d=Lt(),u=jS(),h=Ln(),p=Fv(),m=_S();function y(g,v,b,x,w,C,S){var j=p(g,b),P=p(v,b),E=S.get(P);if(E){e(g,b,E);return}var O=C?C(j,P,b+"",g,v,S):void 0,A=O===void 0;if(A){var R=s(P),M=!R&&c(P),T=!R&&!M&&h(P);O=P,R||M||T?s(j)?O=j:a(j)?O=n(j):M?(A=!1,O=r(P,!0)):T?(A=!1,O=t(P,!0)):O=[]:u(P)||i(P)?(O=j,i(j)?O=m(j):(!d(j)||l(j))&&(O=o(P))):A=!1}A&&(S.set(P,O),w(O,P,x,C,S),S.delete(P)),e(g,b,O)}return sl=y,sl}var cl,my;function kS(){if(my)return cl;my=1;var e=vo(),r=Lv(),t=Zd(),n=ES(),o=Lt(),i=Pr(),s=Fv();function a(c,l,d,u,h){c!==l&&t(l,function(p,m){if(h||(h=new e),o(p))n(c,l,m,d,a,u,h);else{var y=u?u(s(c,m),p,m+"",c,l,h):void 0;y===void 0&&(y=p),r(c,m,y)}},i)}return cl=a,cl}var ll,by;function RS(){if(by)return ll;by=1;var e=Po(),r=Io();function t(n){return e(function(o,i){var s=-1,a=i.length,c=a>1?i[a-1]:void 0,l=a>2?i[2]:void 0;for(c=n.length>3&&typeof c=="function"?(a--,c):void 0,l&&r(i[0],i[1],l)&&(c=a<3?void 0:c,a=1),o=Object(o);++s<a;){var d=i[s];d&&n(o,d,s,c)}return o})}return ll=t,ll}var dl,vy;function AS(){if(vy)return dl;vy=1;var e=kS(),r=RS(),t=r(function(n,o,i){e(n,o,i)});return dl=t,dl}var ul,xy;function zv(){if(xy)return ul;xy=1;function e(r,t){return r<t}return ul=e,ul}var fl,wy;function PS(){if(wy)return fl;wy=1;var e=ru(),r=zv(),t=Ir();function n(o){return o&&o.length?e(o,t,r):void 0}return fl=n,fl}var hl,Cy;function IS(){if(Cy)return hl;Cy=1;var e=ru(),r=rr(),t=zv();function n(o,i){return o&&o.length?e(o,r(i,2),t):void 0}return hl=n,hl}var pl,Sy;function MS(){if(Sy)return pl;Sy=1;var e=Gt(),r=function(){return e.Date.now()};return pl=r,pl}var gl,jy;function TS(){if(jy)return gl;jy=1;var e=wo(),r=Ro(),t=Co(),n=Lt(),o=Fn();function i(s,a,c,l){if(!n(s))return s;a=r(a,s);for(var d=-1,u=a.length,h=u-1,p=s;p!=null&&++d<u;){var m=o(a[d]),y=c;if(m==="__proto__"||m==="constructor"||m==="prototype")return s;if(d!=h){var g=p[m];y=l?l(g,m,p):void 0,y===void 0&&(y=n(g)?g:t(a[d+1])?[]:{})}e(p,m,y),p=p[m]}return s}return gl=i,gl}var yl,_y;function OS(){if(_y)return yl;_y=1;var e=Ao(),r=TS(),t=Ro();function n(o,i,s){for(var a=-1,c=i.length,l={};++a<c;){var d=i[a],u=e(o,d);s(u,d)&&r(l,t(d,o),u)}return l}return yl=n,yl}var ml,Ey;function NS(){if(Ey)return ml;Ey=1;var e=OS(),r=bv();function t(n,o){return e(n,o,function(i,s){return r(n,s)})}return ml=t,ml}var bl,ky;function $S(){if(ky)return bl;ky=1;var e=qv(),r=Ev(),t=kv();function n(o){return t(r(o,void 0,e),o+"")}return bl=n,bl}var vl,Ry;function qS(){if(Ry)return vl;Ry=1;var e=NS(),r=$S(),t=r(function(n,o){return n==null?{}:e(n,o)});return vl=t,vl}var xl,Ay;function LS(){if(Ay)return xl;Ay=1;var e=Math.ceil,r=Math.max;function t(n,o,i,s){for(var a=-1,c=r(e((o-n)/(i||1)),0),l=Array(c);c--;)l[s?c:++a]=n,n+=i;return l}return xl=t,xl}var wl,Py;function FS(){if(Py)return wl;Py=1;var e=LS(),r=Io(),t=$v();function n(o){return function(i,s,a){return a&&typeof a!="number"&&r(i,s,a)&&(s=a=void 0),i=t(i),s===void 0?(s=i,i=0):s=t(s),a=a===void 0?i<s?1:-1:t(a),e(i,s,a,o)}}return wl=n,wl}var Cl,Iy;function zS(){if(Iy)return Cl;Iy=1;var e=FS(),r=e();return Cl=r,Cl}var Sl,My;function BS(){if(My)return Sl;My=1;function e(r,t){var n=r.length;for(r.sort(t);n--;)r[n]=r[n].value;return r}return Sl=e,Sl}var jl,Ty;function DS(){if(Ty)return jl;Ty=1;var e=tn();function r(t,n){if(t!==n){var o=t!==void 0,i=t===null,s=t===t,a=e(t),c=n!==void 0,l=n===null,d=n===n,u=e(n);if(!l&&!u&&!a&&t>n||a&&c&&d&&!l&&!u||i&&c&&d||!o&&d||!s)return 1;if(!i&&!a&&!u&&t<n||u&&o&&s&&!i&&!a||l&&o&&s||!c&&s||!d)return-1}return 0}return jl=r,jl}var _l,Oy;function VS(){if(Oy)return _l;Oy=1;var e=DS();function r(t,n,o){for(var i=-1,s=t.criteria,a=n.criteria,c=s.length,l=o.length;++i<c;){var d=e(s[i],a[i]);if(d){if(i>=l)return d;var u=o[i];return d*(u=="desc"?-1:1)}}return t.index-n.index}return _l=r,_l}var El,Ny;function GS(){if(Ny)return El;Ny=1;var e=ko(),r=Ao(),t=rr(),n=Sv(),o=BS(),i=So(),s=VS(),a=Ir(),c=gt();function l(d,u,h){u.length?u=e(u,function(y){return c(y)?function(g){return r(g,y.length===1?y[0]:y)}:y}):u=[a];var p=-1;u=e(u,i(t));var m=n(d,function(y,g,v){var b=e(u,function(x){return x(y)});return{criteria:b,index:++p,value:y}});return o(m,function(y,g){return s(y,g,h)})}return El=l,El}var kl,$y;function WS(){if($y)return kl;$y=1;var e=eu(),r=GS(),t=Po(),n=Io(),o=t(function(i,s){if(i==null)return[];var a=s.length;return a>1&&n(i,s[0],s[1])?s=[]:a>2&&n(s[0],s[1],s[2])&&(s=[s[0]]),r(i,e(s,1),[])});return kl=o,kl}var Rl,qy;function US(){if(qy)return Rl;qy=1;var e=yv(),r=0;function t(n){var o=++r;return e(n)+o}return Rl=t,Rl}var Al,Ly;function HS(){if(Ly)return Al;Ly=1;function e(r,t,n){for(var o=-1,i=r.length,s=t.length,a={};++o<i;){var c=o<s?t[o]:void 0;n(a,r[o],c)}return a}return Al=e,Al}var Pl,Fy;function KS(){if(Fy)return Pl;Fy=1;var e=wo(),r=HS();function t(n,o){return r(n||[],o||[],e)}return Pl=t,Pl}var Il,zy;function dt(){if(zy)return Il;zy=1;var e;if(typeof Fd=="function")try{e={cloneDeep:dS(),constant:Jd(),defaults:uS(),each:lv(),filter:xv(),find:bS(),flatten:qv(),forEach:cv(),forIn:vS(),has:wv(),isUndefined:Cv(),last:xS(),map:jv(),mapValues:wS(),max:SS(),merge:AS(),min:PS(),minBy:IS(),now:MS(),pick:qS(),range:zS(),reduce:_v(),sortBy:WS(),uniqueId:US(),values:Pv(),zipObject:KS()}}catch{}return e||(e=window._),Il=e,Il}var Ml,By;function JS(){if(By)return Ml;By=1,Ml=e;function e(){var n={};n._next=n._prev=n,this._sentinel=n}e.prototype.dequeue=function(){var n=this._sentinel,o=n._prev;if(o!==n)return r(o),o},e.prototype.enqueue=function(n){var o=this._sentinel;n._prev&&n._next&&r(n),n._next=o._next,o._next._prev=n,o._next=n,n._prev=o},e.prototype.toString=function(){for(var n=[],o=this._sentinel,i=o._prev;i!==o;)n.push(JSON.stringify(i,t)),i=i._prev;return"["+n.join(", ")+"]"};function r(n){n._prev._next=n._next,n._next._prev=n._prev,delete n._next,delete n._prev}function t(n,o){if(n!=="_next"&&n!=="_prev")return o}return Ml}var Tl,Dy;function ZS(){if(Dy)return Tl;Dy=1;var e=dt(),r=Vt().Graph,t=JS();Tl=o;var n=e.constant(1);function o(l,d){if(l.nodeCount()<=1)return[];var u=a(l,d||n),h=i(u.graph,u.buckets,u.zeroIdx);return e.flatten(e.map(h,function(p){return l.outEdges(p.v,p.w)}),!0)}function i(l,d,u){for(var h=[],p=d[d.length-1],m=d[0],y;l.nodeCount();){for(;y=m.dequeue();)s(l,d,u,y);for(;y=p.dequeue();)s(l,d,u,y);if(l.nodeCount()){for(var g=d.length-2;g>0;--g)if(y=d[g].dequeue(),y){h=h.concat(s(l,d,u,y,!0));break}}}return h}function s(l,d,u,h,p){var m=p?[]:void 0;return e.forEach(l.inEdges(h.v),function(y){var g=l.edge(y),v=l.node(y.v);p&&m.push({v:y.v,w:y.w}),v.out-=g,c(d,u,v)}),e.forEach(l.outEdges(h.v),function(y){var g=l.edge(y),v=y.w,b=l.node(v);b.in-=g,c(d,u,b)}),l.removeNode(h.v),m}function a(l,d){var u=new r,h=0,p=0;e.forEach(l.nodes(),function(g){u.setNode(g,{v:g,in:0,out:0})}),e.forEach(l.edges(),function(g){var v=u.edge(g.v,g.w)||0,b=d(g),x=v+b;u.setEdge(g.v,g.w,x),p=Math.max(p,u.node(g.v).out+=b),h=Math.max(h,u.node(g.w).in+=b)});var m=e.range(p+h+3).map(function(){return new t}),y=h+1;return e.forEach(u.nodes(),function(g){c(m,y,u.node(g))}),{graph:u,buckets:m,zeroIdx:y}}function c(l,d,u){u.out?u.in?l[u.out-u.in+d].enqueue(u):l[l.length-1].enqueue(u):l[0].enqueue(u)}return Tl}var Ol,Vy;function XS(){if(Vy)return Ol;Vy=1;var e=dt(),r=ZS();Ol={run:t,undo:o};function t(i){var s=i.graph().acyclicer==="greedy"?r(i,a(i)):n(i);e.forEach(s,function(c){var l=i.edge(c);i.removeEdge(c),l.forwardName=c.name,l.reversed=!0,i.setEdge(c.w,c.v,l,e.uniqueId("rev"))});function a(c){return function(l){return c.edge(l).weight}}}function n(i){var s=[],a={},c={};function l(d){e.has(c,d)||(c[d]=!0,a[d]=!0,e.forEach(i.outEdges(d),function(u){e.has(a,u.w)?s.push(u):l(u.w)}),delete a[d])}return e.forEach(i.nodes(),l),s}function o(i){e.forEach(i.edges(),function(s){var a=i.edge(s);if(a.reversed){i.removeEdge(s);var c=a.forwardName;delete a.reversed,delete a.forwardName,i.setEdge(s.w,s.v,a,c)}})}return Ol}var Nl,Gy;function At(){if(Gy)return Nl;Gy=1;var e=dt(),r=Vt().Graph;Nl={addDummyNode:t,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:s,intersectRect:a,buildLayerMatrix:c,normalizeRanks:l,removeEmptyRanks:d,addBorderNode:u,maxRank:h,partition:p,time:m,notime:y};function t(g,v,b,x){var w;do w=e.uniqueId(x);while(g.hasNode(w));return b.dummy=v,g.setNode(w,b),w}function n(g){var v=new r().setGraph(g.graph());return e.forEach(g.nodes(),function(b){v.setNode(b,g.node(b))}),e.forEach(g.edges(),function(b){var x=v.edge(b.v,b.w)||{weight:0,minlen:1},w=g.edge(b);v.setEdge(b.v,b.w,{weight:x.weight+w.weight,minlen:Math.max(x.minlen,w.minlen)})}),v}function o(g){var v=new r({multigraph:g.isMultigraph()}).setGraph(g.graph());return e.forEach(g.nodes(),function(b){g.children(b).length||v.setNode(b,g.node(b))}),e.forEach(g.edges(),function(b){v.setEdge(b,g.edge(b))}),v}function i(g){var v=e.map(g.nodes(),function(b){var x={};return e.forEach(g.outEdges(b),function(w){x[w.w]=(x[w.w]||0)+g.edge(w).weight}),x});return e.zipObject(g.nodes(),v)}function s(g){var v=e.map(g.nodes(),function(b){var x={};return e.forEach(g.inEdges(b),function(w){x[w.v]=(x[w.v]||0)+g.edge(w).weight}),x});return e.zipObject(g.nodes(),v)}function a(g,v){var b=g.x,x=g.y,w=v.x-b,C=v.y-x,S=g.width/2,j=g.height/2;if(!w&&!C)throw new Error("Not possible to find intersection inside of the rectangle");var P,E;return Math.abs(C)*S>Math.abs(w)*j?(C<0&&(j=-j),P=j*w/C,E=j):(w<0&&(S=-S),P=S,E=S*C/w),{x:b+P,y:x+E}}function c(g){var v=e.map(e.range(h(g)+1),function(){return[]});return e.forEach(g.nodes(),function(b){var x=g.node(b),w=x.rank;e.isUndefined(w)||(v[w][x.order]=b)}),v}function l(g){var v=e.min(e.map(g.nodes(),function(b){return g.node(b).rank}));e.forEach(g.nodes(),function(b){var x=g.node(b);e.has(x,"rank")&&(x.rank-=v)})}function d(g){var v=e.min(e.map(g.nodes(),function(C){return g.node(C).rank})),b=[];e.forEach(g.nodes(),function(C){var S=g.node(C).rank-v;b[S]||(b[S]=[]),b[S].push(C)});var x=0,w=g.graph().nodeRankFactor;e.forEach(b,function(C,S){e.isUndefined(C)&&S%w!==0?--x:x&&e.forEach(C,function(j){g.node(j).rank+=x})})}function u(g,v,b,x){var w={width:0,height:0};return arguments.length>=4&&(w.rank=b,w.order=x),t(g,"border",w,v)}function h(g){return e.max(e.map(g.nodes(),function(v){var b=g.node(v).rank;if(!e.isUndefined(b))return b}))}function p(g,v){var b={lhs:[],rhs:[]};return e.forEach(g,function(x){v(x)?b.lhs.push(x):b.rhs.push(x)}),b}function m(g,v){var b=e.now();try{return v()}finally{console.log(g+" time: "+(e.now()-b)+"ms")}}function y(g,v){return v()}return Nl}var $l,Wy;function YS(){if(Wy)return $l;Wy=1;var e=dt(),r=At();$l={run:t,undo:o};function t(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(s){n(i,s)})}function n(i,s){var a=s.v,c=i.node(a).rank,l=s.w,d=i.node(l).rank,u=s.name,h=i.edge(s),p=h.labelRank;if(d!==c+1){i.removeEdge(s);var m,y,g;for(g=0,++c;c<d;++g,++c)h.points=[],y={width:0,height:0,edgeLabel:h,edgeObj:s,rank:c},m=r.addDummyNode(i,"edge",y,"_d"),c===p&&(y.width=h.width,y.height=h.height,y.dummy="edge-label",y.labelpos=h.labelpos),i.setEdge(a,m,{weight:h.weight},u),g===0&&i.graph().dummyChains.push(m),a=m;i.setEdge(a,l,{weight:h.weight},u)}}function o(i){e.forEach(i.graph().dummyChains,function(s){var a=i.node(s),c=a.edgeLabel,l;for(i.setEdge(a.edgeObj,c);a.dummy;)l=i.successors(s)[0],i.removeNode(s),c.points.push({x:a.x,y:a.y}),a.dummy==="edge-label"&&(c.x=a.x,c.y=a.y,c.width=a.width,c.height=a.height),s=l,a=i.node(s)})}return $l}var ql,Uy;function oo(){if(Uy)return ql;Uy=1;var e=dt();ql={longestPath:r,slack:t};function r(n){var o={};function i(s){var a=n.node(s);if(e.has(o,s))return a.rank;o[s]=!0;var c=e.min(e.map(n.outEdges(s),function(l){return i(l.w)-n.edge(l).minlen}));return(c===Number.POSITIVE_INFINITY||c===void 0||c===null)&&(c=0),a.rank=c}e.forEach(n.sources(),i)}function t(n,o){return n.node(o.w).rank-n.node(o.v).rank-n.edge(o).minlen}return ql}var Ll,Hy;function Bv(){if(Hy)return Ll;Hy=1;var e=dt(),r=Vt().Graph,t=oo().slack;Ll=n;function n(a){var c=new r({directed:!1}),l=a.nodes()[0],d=a.nodeCount();c.setNode(l,{});for(var u,h;o(c,a)<d;)u=i(c,a),h=c.hasNode(u.v)?t(a,u):-t(a,u),s(c,a,h);return c}function o(a,c){function l(d){e.forEach(c.nodeEdges(d),function(u){var h=u.v,p=d===h?u.w:h;!a.hasNode(p)&&!t(c,u)&&(a.setNode(p,{}),a.setEdge(d,p,{}),l(p))})}return e.forEach(a.nodes(),l),a.nodeCount()}function i(a,c){return e.minBy(c.edges(),function(l){if(a.hasNode(l.v)!==a.hasNode(l.w))return t(c,l)})}function s(a,c,l){e.forEach(a.nodes(),function(d){c.node(d).rank+=l})}return Ll}var Fl,Ky;function QS(){if(Ky)return Fl;Ky=1;var e=dt(),r=Bv(),t=oo().slack,n=oo().longestPath,o=Vt().alg.preorder,i=Vt().alg.postorder,s=At().simplify;Fl=a,a.initLowLimValues=u,a.initCutValues=c,a.calcCutValue=d,a.leaveEdge=p,a.enterEdge=m,a.exchangeEdges=y;function a(x){x=s(x),n(x);var w=r(x);u(w),c(w,x);for(var C,S;C=p(w);)S=m(w,x,C),y(w,x,C,S)}function c(x,w){var C=i(x,x.nodes());C=C.slice(0,C.length-1),e.forEach(C,function(S){l(x,w,S)})}function l(x,w,C){var S=x.node(C),j=S.parent;x.edge(C,j).cutvalue=d(x,w,C)}function d(x,w,C){var S=x.node(C),j=S.parent,P=!0,E=w.edge(C,j),O=0;return E||(P=!1,E=w.edge(j,C)),O=E.weight,e.forEach(w.nodeEdges(C),function(A){var R=A.v===C,M=R?A.w:A.v;if(M!==j){var T=R===P,N=w.edge(A).weight;if(O+=T?N:-N,v(x,C,M)){var $=x.edge(C,M).cutvalue;O+=T?-$:$}}}),O}function u(x,w){arguments.length<2&&(w=x.nodes()[0]),h(x,{},1,w)}function h(x,w,C,S,j){var P=C,E=x.node(S);return w[S]=!0,e.forEach(x.neighbors(S),function(O){e.has(w,O)||(C=h(x,w,C,O,S))}),E.low=P,E.lim=C++,j?E.parent=j:delete E.parent,C}function p(x){return e.find(x.edges(),function(w){return x.edge(w).cutvalue<0})}function m(x,w,C){var S=C.v,j=C.w;w.hasEdge(S,j)||(S=C.w,j=C.v);var P=x.node(S),E=x.node(j),O=P,A=!1;P.lim>E.lim&&(O=E,A=!0);var R=e.filter(w.edges(),function(M){return A===b(x,x.node(M.v),O)&&A!==b(x,x.node(M.w),O)});return e.minBy(R,function(M){return t(w,M)})}function y(x,w,C,S){var j=C.v,P=C.w;x.removeEdge(j,P),x.setEdge(S.v,S.w,{}),u(x),c(x,w),g(x,w)}function g(x,w){var C=e.find(x.nodes(),function(j){return!w.node(j).parent}),S=o(x,C);S=S.slice(1),e.forEach(S,function(j){var P=x.node(j).parent,E=w.edge(j,P),O=!1;E||(E=w.edge(P,j),O=!0),w.node(j).rank=w.node(P).rank+(O?E.minlen:-E.minlen)})}function v(x,w,C){return x.hasEdge(w,C)}function b(x,w,C){return C.low<=w.lim&&w.lim<=C.lim}return Fl}var zl,Jy;function ej(){if(Jy)return zl;Jy=1;var e=oo(),r=e.longestPath,t=Bv(),n=QS();zl=o;function o(c){switch(c.graph().ranker){case"network-simplex":a(c);break;case"tight-tree":s(c);break;case"longest-path":i(c);break;default:a(c)}}var i=r;function s(c){r(c),t(c)}function a(c){n(c)}return zl}var Bl,Zy;function tj(){if(Zy)return Bl;Zy=1;var e=dt();Bl=r;function r(o){var i=n(o);e.forEach(o.graph().dummyChains,function(s){for(var a=o.node(s),c=a.edgeObj,l=t(o,i,c.v,c.w),d=l.path,u=l.lca,h=0,p=d[h],m=!0;s!==c.w;){if(a=o.node(s),m){for(;(p=d[h])!==u&&o.node(p).maxRank<a.rank;)h++;p===u&&(m=!1)}if(!m){for(;h<d.length-1&&o.node(p=d[h+1]).minRank<=a.rank;)h++;p=d[h]}o.setParent(s,p),s=o.successors(s)[0]}})}function t(o,i,s,a){var c=[],l=[],d=Math.min(i[s].low,i[a].low),u=Math.max(i[s].lim,i[a].lim),h,p;h=s;do h=o.parent(h),c.push(h);while(h&&(i[h].low>d||u>i[h].lim));for(p=h,h=a;(h=o.parent(h))!==p;)l.push(h);return{path:c.concat(l.reverse()),lca:p}}function n(o){var i={},s=0;function a(c){var l=s;e.forEach(o.children(c),a),i[c]={low:l,lim:s++}}return e.forEach(o.children(),a),i}return Bl}var Dl,Xy;function rj(){if(Xy)return Dl;Xy=1;var e=dt(),r=At();Dl={run:t,cleanup:s};function t(a){var c=r.addDummyNode(a,"root",{},"_root"),l=o(a),d=e.max(e.values(l))-1,u=2*d+1;a.graph().nestingRoot=c,e.forEach(a.edges(),function(p){a.edge(p).minlen*=u});var h=i(a)+1;e.forEach(a.children(),function(p){n(a,c,u,h,d,l,p)}),a.graph().nodeRankFactor=u}function n(a,c,l,d,u,h,p){var m=a.children(p);if(!m.length){p!==c&&a.setEdge(c,p,{weight:0,minlen:l});return}var y=r.addBorderNode(a,"_bt"),g=r.addBorderNode(a,"_bb"),v=a.node(p);a.setParent(y,p),v.borderTop=y,a.setParent(g,p),v.borderBottom=g,e.forEach(m,function(b){n(a,c,l,d,u,h,b);var x=a.node(b),w=x.borderTop?x.borderTop:b,C=x.borderBottom?x.borderBottom:b,S=x.borderTop?d:2*d,j=w!==C?1:u-h[p]+1;a.setEdge(y,w,{weight:S,minlen:j,nestingEdge:!0}),a.setEdge(C,g,{weight:S,minlen:j,nestingEdge:!0})}),a.parent(p)||a.setEdge(c,y,{weight:0,minlen:u+h[p]})}function o(a){var c={};function l(d,u){var h=a.children(d);h&&h.length&&e.forEach(h,function(p){l(p,u+1)}),c[d]=u}return e.forEach(a.children(),function(d){l(d,1)}),c}function i(a){return e.reduce(a.edges(),function(c,l){return c+a.edge(l).weight},0)}function s(a){var c=a.graph();a.removeNode(c.nestingRoot),delete c.nestingRoot,e.forEach(a.edges(),function(l){var d=a.edge(l);d.nestingEdge&&a.removeEdge(l)})}return Dl}var Vl,Yy;function nj(){if(Yy)return Vl;Yy=1;var e=dt(),r=At();Vl=t;function t(o){function i(s){var a=o.children(s),c=o.node(s);if(a.length&&e.forEach(a,i),e.has(c,"minRank")){c.borderLeft=[],c.borderRight=[];for(var l=c.minRank,d=c.maxRank+1;l<d;++l)n(o,"borderLeft","_bl",s,c,l),n(o,"borderRight","_br",s,c,l)}}e.forEach(o.children(),i)}function n(o,i,s,a,c,l){var d={width:0,height:0,rank:l,borderType:i},u=c[i][l-1],h=r.addDummyNode(o,"border",d,s);c[i][l]=h,o.setParent(h,a),u&&o.setEdge(u,h,{weight:1})}return Vl}var Gl,Qy;function oj(){if(Qy)return Gl;Qy=1;var e=dt();Gl={adjust:r,undo:t};function r(l){var d=l.graph().rankdir.toLowerCase();(d==="lr"||d==="rl")&&n(l)}function t(l){var d=l.graph().rankdir.toLowerCase();(d==="bt"||d==="rl")&&i(l),(d==="lr"||d==="rl")&&(a(l),n(l))}function n(l){e.forEach(l.nodes(),function(d){o(l.node(d))}),e.forEach(l.edges(),function(d){o(l.edge(d))})}function o(l){var d=l.width;l.width=l.height,l.height=d}function i(l){e.forEach(l.nodes(),function(d){s(l.node(d))}),e.forEach(l.edges(),function(d){var u=l.edge(d);e.forEach(u.points,s),e.has(u,"y")&&s(u)})}function s(l){l.y=-l.y}function a(l){e.forEach(l.nodes(),function(d){c(l.node(d))}),e.forEach(l.edges(),function(d){var u=l.edge(d);e.forEach(u.points,c),e.has(u,"x")&&c(u)})}function c(l){var d=l.x;l.x=l.y,l.y=d}return Gl}var Wl,em;function ij(){if(em)return Wl;em=1;var e=dt();Wl=r;function r(t){var n={},o=e.filter(t.nodes(),function(l){return!t.children(l).length}),i=e.max(e.map(o,function(l){return t.node(l).rank})),s=e.map(e.range(i+1),function(){return[]});function a(l){if(!e.has(n,l)){n[l]=!0;var d=t.node(l);s[d.rank].push(l),e.forEach(t.successors(l),a)}}var c=e.sortBy(o,function(l){return t.node(l).rank});return e.forEach(c,a),s}return Wl}var Ul,tm;function aj(){if(tm)return Ul;tm=1;var e=dt();Ul=r;function r(n,o){for(var i=0,s=1;s<o.length;++s)i+=t(n,o[s-1],o[s]);return i}function t(n,o,i){for(var s=e.zipObject(i,e.map(i,function(h,p){return p})),a=e.flatten(e.map(o,function(h){return e.sortBy(e.map(n.outEdges(h),function(p){return{pos:s[p.w],weight:n.edge(p).weight}}),"pos")}),!0),c=1;c<i.length;)c<<=1;var l=2*c-1;c-=1;var d=e.map(new Array(l),function(){return 0}),u=0;return e.forEach(a.forEach(function(h){var p=h.pos+c;d[p]+=h.weight;for(var m=0;p>0;)p%2&&(m+=d[p+1]),p=p-1>>1,d[p]+=h.weight;u+=h.weight*m})),u}return Ul}var Hl,rm;function sj(){if(rm)return Hl;rm=1;var e=dt();Hl=r;function r(t,n){return e.map(n,function(o){var i=t.inEdges(o);if(i.length){var s=e.reduce(i,function(a,c){var l=t.edge(c),d=t.node(c.v);return{sum:a.sum+l.weight*d.order,weight:a.weight+l.weight}},{sum:0,weight:0});return{v:o,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:o}})}return Hl}var Kl,nm;function cj(){if(nm)return Kl;nm=1;var e=dt();Kl=r;function r(o,i){var s={};e.forEach(o,function(c,l){var d=s[c.v]={indegree:0,in:[],out:[],vs:[c.v],i:l};e.isUndefined(c.barycenter)||(d.barycenter=c.barycenter,d.weight=c.weight)}),e.forEach(i.edges(),function(c){var l=s[c.v],d=s[c.w];!e.isUndefined(l)&&!e.isUndefined(d)&&(d.indegree++,l.out.push(s[c.w]))});var a=e.filter(s,function(c){return!c.indegree});return t(a)}function t(o){var i=[];function s(l){return function(d){d.merged||(e.isUndefined(d.barycenter)||e.isUndefined(l.barycenter)||d.barycenter>=l.barycenter)&&n(l,d)}}function a(l){return function(d){d.in.push(l),--d.indegree===0&&o.push(d)}}for(;o.length;){var c=o.pop();i.push(c),e.forEach(c.in.reverse(),s(c)),e.forEach(c.out,a(c))}return e.map(e.filter(i,function(l){return!l.merged}),function(l){return e.pick(l,["vs","i","barycenter","weight"])})}function n(o,i){var s=0,a=0;o.weight&&(s+=o.barycenter*o.weight,a+=o.weight),i.weight&&(s+=i.barycenter*i.weight,a+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=s/a,o.weight=a,o.i=Math.min(i.i,o.i),i.merged=!0}return Kl}var Jl,om;function lj(){if(om)return Jl;om=1;var e=dt(),r=At();Jl=t;function t(i,s){var a=r.partition(i,function(y){return e.has(y,"barycenter")}),c=a.lhs,l=e.sortBy(a.rhs,function(y){return-y.i}),d=[],u=0,h=0,p=0;c.sort(o(!!s)),p=n(d,l,p),e.forEach(c,function(y){p+=y.vs.length,d.push(y.vs),u+=y.barycenter*y.weight,h+=y.weight,p=n(d,l,p)});var m={vs:e.flatten(d,!0)};return h&&(m.barycenter=u/h,m.weight=h),m}function n(i,s,a){for(var c;s.length&&(c=e.last(s)).i<=a;)s.pop(),i.push(c.vs),a++;return a}function o(i){return function(s,a){return s.barycenter<a.barycenter?-1:s.barycenter>a.barycenter?1:i?a.i-s.i:s.i-a.i}}return Jl}var Zl,im;function dj(){if(im)return Zl;im=1;var e=dt(),r=sj(),t=cj(),n=lj();Zl=o;function o(a,c,l,d){var u=a.children(c),h=a.node(c),p=h?h.borderLeft:void 0,m=h?h.borderRight:void 0,y={};p&&(u=e.filter(u,function(C){return C!==p&&C!==m}));var g=r(a,u);e.forEach(g,function(C){if(a.children(C.v).length){var S=o(a,C.v,l,d);y[C.v]=S,e.has(S,"barycenter")&&s(C,S)}});var v=t(g,l);i(v,y);var b=n(v,d);if(p&&(b.vs=e.flatten([p,b.vs,m],!0),a.predecessors(p).length)){var x=a.node(a.predecessors(p)[0]),w=a.node(a.predecessors(m)[0]);e.has(b,"barycenter")||(b.barycenter=0,b.weight=0),b.barycenter=(b.barycenter*b.weight+x.order+w.order)/(b.weight+2),b.weight+=2}return b}function i(a,c){e.forEach(a,function(l){l.vs=e.flatten(l.vs.map(function(d){return c[d]?c[d].vs:d}),!0)})}function s(a,c){e.isUndefined(a.barycenter)?(a.barycenter=c.barycenter,a.weight=c.weight):(a.barycenter=(a.barycenter*a.weight+c.barycenter*c.weight)/(a.weight+c.weight),a.weight+=c.weight)}return Zl}var Xl,am;function uj(){if(am)return Xl;am=1;var e=dt(),r=Vt().Graph;Xl=t;function t(o,i,s){var a=n(o),c=new r({compound:!0}).setGraph({root:a}).setDefaultNodeLabel(function(l){return o.node(l)});return e.forEach(o.nodes(),function(l){var d=o.node(l),u=o.parent(l);(d.rank===i||d.minRank<=i&&i<=d.maxRank)&&(c.setNode(l),c.setParent(l,u||a),e.forEach(o[s](l),function(h){var p=h.v===l?h.w:h.v,m=c.edge(p,l),y=e.isUndefined(m)?0:m.weight;c.setEdge(p,l,{weight:o.edge(h).weight+y})}),e.has(d,"minRank")&&c.setNode(l,{borderLeft:d.borderLeft[i],borderRight:d.borderRight[i]}))}),c}function n(o){for(var i;o.hasNode(i=e.uniqueId("_root")););return i}return Xl}var Yl,sm;function fj(){if(sm)return Yl;sm=1;var e=dt();Yl=r;function r(t,n,o){var i={},s;e.forEach(o,function(a){for(var c=t.parent(a),l,d;c;){if(l=t.parent(c),l?(d=i[l],i[l]=c):(d=s,s=c),d&&d!==c){n.setEdge(d,c);return}c=l}})}return Yl}var Ql,cm;function hj(){if(cm)return Ql;cm=1;var e=dt(),r=ij(),t=aj(),n=dj(),o=uj(),i=fj(),s=Vt().Graph,a=At();Ql=c;function c(h){var p=a.maxRank(h),m=l(h,e.range(1,p+1),"inEdges"),y=l(h,e.range(p-1,-1,-1),"outEdges"),g=r(h);u(h,g);for(var v=Number.POSITIVE_INFINITY,b,x=0,w=0;w<4;++x,++w){d(x%2?m:y,x%4>=2),g=a.buildLayerMatrix(h);var C=t(h,g);C<v&&(w=0,b=e.cloneDeep(g),v=C)}u(h,b)}function l(h,p,m){return e.map(p,function(y){return o(h,y,m)})}function d(h,p){var m=new s;e.forEach(h,function(y){var g=y.graph().root,v=n(y,g,m,p);e.forEach(v.vs,function(b,x){y.node(b).order=x}),i(y,m,v.vs)})}function u(h,p){e.forEach(p,function(m){e.forEach(m,function(y,g){h.node(y).order=g})})}return Ql}var ed,lm;function pj(){if(lm)return ed;lm=1;var e=dt(),r=Vt().Graph,t=At();ed={positionX:m,findType1Conflicts:n,findType2Conflicts:o,addConflict:s,hasConflict:a,verticalAlignment:c,horizontalCompaction:l,alignCoordinates:h,findSmallestWidthAlignment:u,balance:p};function n(v,b){var x={};function w(C,S){var j=0,P=0,E=C.length,O=e.last(S);return e.forEach(S,function(A,R){var M=i(v,A),T=M?v.node(M).order:E;(M||A===O)&&(e.forEach(S.slice(P,R+1),function(N){e.forEach(v.predecessors(N),function($){var I=v.node($),K=I.order;(K<j||T<K)&&!(I.dummy&&v.node(N).dummy)&&s(x,$,N)})}),P=R+1,j=T)}),S}return e.reduce(b,w),x}function o(v,b){var x={};function w(S,j,P,E,O){var A;e.forEach(e.range(j,P),function(R){A=S[R],v.node(A).dummy&&e.forEach(v.predecessors(A),function(M){var T=v.node(M);T.dummy&&(T.order<E||T.order>O)&&s(x,M,A)})})}function C(S,j){var P=-1,E,O=0;return e.forEach(j,function(A,R){if(v.node(A).dummy==="border"){var M=v.predecessors(A);M.length&&(E=v.node(M[0]).order,w(j,O,R,P,E),O=R,P=E)}w(j,O,j.length,E,S.length)}),j}return e.reduce(b,C),x}function i(v,b){if(v.node(b).dummy)return e.find(v.predecessors(b),function(x){return v.node(x).dummy})}function s(v,b,x){if(b>x){var w=b;b=x,x=w}var C=v[b];C||(v[b]=C={}),C[x]=!0}function a(v,b,x){if(b>x){var w=b;b=x,x=w}return e.has(v[b],x)}function c(v,b,x,w){var C={},S={},j={};return e.forEach(b,function(P){e.forEach(P,function(E,O){C[E]=E,S[E]=E,j[E]=O})}),e.forEach(b,function(P){var E=-1;e.forEach(P,function(O){var A=w(O);if(A.length){A=e.sortBy(A,function($){return j[$]});for(var R=(A.length-1)/2,M=Math.floor(R),T=Math.ceil(R);M<=T;++M){var N=A[M];S[O]===O&&E<j[N]&&!a(x,O,N)&&(S[N]=O,S[O]=C[O]=C[N],E=j[N])}}})}),{root:C,align:S}}function l(v,b,x,w,C){var S={},j=d(v,b,x,C),P=C?"borderLeft":"borderRight";function E(R,M){for(var T=j.nodes(),N=T.pop(),$={};N;)$[N]?R(N):($[N]=!0,T.push(N),T=T.concat(M(N))),N=T.pop()}function O(R){S[R]=j.inEdges(R).reduce(function(M,T){return Math.max(M,S[T.v]+j.edge(T))},0)}function A(R){var M=j.outEdges(R).reduce(function(N,$){return Math.min(N,S[$.w]-j.edge($))},Number.POSITIVE_INFINITY),T=v.node(R);M!==Number.POSITIVE_INFINITY&&T.borderType!==P&&(S[R]=Math.max(S[R],M))}return E(O,j.predecessors.bind(j)),E(A,j.successors.bind(j)),e.forEach(w,function(R){S[R]=S[x[R]]}),S}function d(v,b,x,w){var C=new r,S=v.graph(),j=y(S.nodesep,S.edgesep,w);return e.forEach(b,function(P){var E;e.forEach(P,function(O){var A=x[O];if(C.setNode(A),E){var R=x[E],M=C.edge(R,A);C.setEdge(R,A,Math.max(j(v,O,E),M||0))}E=O})}),C}function u(v,b){return e.minBy(e.values(b),function(x){var w=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY;return e.forIn(x,function(S,j){var P=g(v,j)/2;w=Math.max(S+P,w),C=Math.min(S-P,C)}),w-C})}function h(v,b){var x=e.values(b),w=e.min(x),C=e.max(x);e.forEach(["u","d"],function(S){e.forEach(["l","r"],function(j){var P=S+j,E=v[P],O;if(E!==b){var A=e.values(E);O=j==="l"?w-e.min(A):C-e.max(A),O&&(v[P]=e.mapValues(E,function(R){return R+O}))}})})}function p(v,b){return e.mapValues(v.ul,function(x,w){if(b)return v[b.toLowerCase()][w];var C=e.sortBy(e.map(v,w));return(C[1]+C[2])/2})}function m(v){var b=t.buildLayerMatrix(v),x=e.merge(n(v,b),o(v,b)),w={},C;e.forEach(["u","d"],function(j){C=j==="u"?b:e.values(b).reverse(),e.forEach(["l","r"],function(P){P==="r"&&(C=e.map(C,function(R){return e.values(R).reverse()}));var E=(j==="u"?v.predecessors:v.successors).bind(v),O=c(v,C,x,E),A=l(v,C,O.root,O.align,P==="r");P==="r"&&(A=e.mapValues(A,function(R){return-R})),w[j+P]=A})});var S=u(v,w);return h(w,S),p(w,v.graph().align)}function y(v,b,x){return function(w,C,S){var j=w.node(C),P=w.node(S),E=0,O;if(E+=j.width/2,e.has(j,"labelpos"))switch(j.labelpos.toLowerCase()){case"l":O=-j.width/2;break;case"r":O=j.width/2;break}if(O&&(E+=x?O:-O),O=0,E+=(j.dummy?b:v)/2,E+=(P.dummy?b:v)/2,E+=P.width/2,e.has(P,"labelpos"))switch(P.labelpos.toLowerCase()){case"l":O=P.width/2;break;case"r":O=-P.width/2;break}return O&&(E+=x?O:-O),O=0,E}}function g(v,b){return v.node(b).width}return ed}var td,dm;function gj(){if(dm)return td;dm=1;var e=dt(),r=At(),t=pj().positionX;td=n;function n(i){i=r.asNonCompoundGraph(i),o(i),e.forEach(t(i),function(s,a){i.node(a).x=s})}function o(i){var s=r.buildLayerMatrix(i),a=i.graph().ranksep,c=0;e.forEach(s,function(l){var d=e.max(e.map(l,function(u){return i.node(u).height}));e.forEach(l,function(u){i.node(u).y=c+d/2}),c+=d+a})}return td}var rd,um;function yj(){if(um)return rd;um=1;var e=dt(),r=XS(),t=YS(),n=ej(),o=At().normalizeRanks,i=tj(),s=At().removeEmptyRanks,a=rj(),c=nj(),l=oj(),d=hj(),u=gj(),h=At(),p=Vt().Graph;rd=m;function m(F,D){var W=D&&D.debugTiming?h.time:h.notime;W("layout",function(){var B=W(" buildLayoutGraph",function(){return E(F)});W(" runLayout",function(){y(B,W)}),W(" updateInputGraph",function(){g(F,B)})})}function y(F,D){D(" makeSpaceForEdgeLabels",function(){O(F)}),D(" removeSelfEdges",function(){ie(F)}),D(" acyclic",function(){r.run(F)}),D(" nestingGraph.run",function(){a.run(F)}),D(" rank",function(){n(h.asNonCompoundGraph(F))}),D(" injectEdgeLabelProxies",function(){A(F)}),D(" removeEmptyRanks",function(){s(F)}),D(" nestingGraph.cleanup",function(){a.cleanup(F)}),D(" normalizeRanks",function(){o(F)}),D(" assignRankMinMax",function(){R(F)}),D(" removeEdgeLabelProxies",function(){M(F)}),D(" normalize.run",function(){t.run(F)}),D(" parentDummyChains",function(){i(F)}),D(" addBorderSegments",function(){c(F)}),D(" order",function(){d(F)}),D(" insertSelfEdges",function(){se(F)}),D(" adjustCoordinateSystem",function(){l.adjust(F)}),D(" position",function(){u(F)}),D(" positionSelfEdges",function(){te(F)}),D(" removeBorderNodes",function(){K(F)}),D(" normalize.undo",function(){t.undo(F)}),D(" fixupEdgeLabelCoords",function(){$(F)}),D(" undoCoordinateSystem",function(){l.undo(F)}),D(" translateGraph",function(){T(F)}),D(" assignNodeIntersects",function(){N(F)}),D(" reversePoints",function(){I(F)}),D(" acyclic.undo",function(){r.undo(F)})}function g(F,D){e.forEach(F.nodes(),function(W){var B=F.node(W),le=D.node(W);B&&(B.x=le.x,B.y=le.y,D.children(W).length&&(B.width=le.width,B.height=le.height))}),e.forEach(F.edges(),function(W){var B=F.edge(W),le=D.edge(W);B.points=le.points,e.has(le,"x")&&(B.x=le.x,B.y=le.y)}),F.graph().width=D.graph().width,F.graph().height=D.graph().height}var v=["nodesep","edgesep","ranksep","marginx","marginy"],b={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},x=["acyclicer","ranker","rankdir","align"],w=["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"},P=["labelpos"];function E(F){var D=new p({multigraph:!0,compound:!0}),W=ve(F.graph());return D.setGraph(e.merge({},b,me(W,v),e.pick(W,x))),e.forEach(F.nodes(),function(B){var le=ve(F.node(B));D.setNode(B,e.defaults(me(le,w),C)),D.setParent(B,F.parent(B))}),e.forEach(F.edges(),function(B){var le=ve(F.edge(B));D.setEdge(B,e.merge({},j,me(le,S),e.pick(le,P)))}),D}function O(F){var D=F.graph();D.ranksep/=2,e.forEach(F.edges(),function(W){var B=F.edge(W);B.minlen*=2,B.labelpos.toLowerCase()!=="c"&&(D.rankdir==="TB"||D.rankdir==="BT"?B.width+=B.labeloffset:B.height+=B.labeloffset)})}function A(F){e.forEach(F.edges(),function(D){var W=F.edge(D);if(W.width&&W.height){var B=F.node(D.v),le=F.node(D.w),Y={rank:(le.rank-B.rank)/2+B.rank,e:D};h.addDummyNode(F,"edge-proxy",Y,"_ep")}})}function R(F){var D=0;e.forEach(F.nodes(),function(W){var B=F.node(W);B.borderTop&&(B.minRank=F.node(B.borderTop).rank,B.maxRank=F.node(B.borderBottom).rank,D=e.max(D,B.maxRank))}),F.graph().maxRank=D}function M(F){e.forEach(F.nodes(),function(D){var W=F.node(D);W.dummy==="edge-proxy"&&(F.edge(W.e).labelRank=W.rank,F.removeNode(D))})}function T(F){var D=Number.POSITIVE_INFINITY,W=0,B=Number.POSITIVE_INFINITY,le=0,Y=F.graph(),ce=Y.marginx||0,ue=Y.marginy||0;function xe(Ce){var ye=Ce.x,pe=Ce.y,X=Ce.width,L=Ce.height;D=Math.min(D,ye-X/2),W=Math.max(W,ye+X/2),B=Math.min(B,pe-L/2),le=Math.max(le,pe+L/2)}e.forEach(F.nodes(),function(Ce){xe(F.node(Ce))}),e.forEach(F.edges(),function(Ce){var ye=F.edge(Ce);e.has(ye,"x")&&xe(ye)}),D-=ce,B-=ue,e.forEach(F.nodes(),function(Ce){var ye=F.node(Ce);ye.x-=D,ye.y-=B}),e.forEach(F.edges(),function(Ce){var ye=F.edge(Ce);e.forEach(ye.points,function(pe){pe.x-=D,pe.y-=B}),e.has(ye,"x")&&(ye.x-=D),e.has(ye,"y")&&(ye.y-=B)}),Y.width=W-D+ce,Y.height=le-B+ue}function N(F){e.forEach(F.edges(),function(D){var W=F.edge(D),B=F.node(D.v),le=F.node(D.w),Y,ce;W.points?(Y=W.points[0],ce=W.points[W.points.length-1]):(W.points=[],Y=le,ce=B),W.points.unshift(h.intersectRect(B,Y)),W.points.push(h.intersectRect(le,ce))})}function $(F){e.forEach(F.edges(),function(D){var W=F.edge(D);if(e.has(W,"x"))switch((W.labelpos==="l"||W.labelpos==="r")&&(W.width-=W.labeloffset),W.labelpos){case"l":W.x-=W.width/2+W.labeloffset;break;case"r":W.x+=W.width/2+W.labeloffset;break}})}function I(F){e.forEach(F.edges(),function(D){var W=F.edge(D);W.reversed&&W.points.reverse()})}function K(F){e.forEach(F.nodes(),function(D){if(F.children(D).length){var W=F.node(D),B=F.node(W.borderTop),le=F.node(W.borderBottom),Y=F.node(e.last(W.borderLeft)),ce=F.node(e.last(W.borderRight));W.width=Math.abs(ce.x-Y.x),W.height=Math.abs(le.y-B.y),W.x=Y.x+W.width/2,W.y=B.y+W.height/2}}),e.forEach(F.nodes(),function(D){F.node(D).dummy==="border"&&F.removeNode(D)})}function ie(F){e.forEach(F.edges(),function(D){if(D.v===D.w){var W=F.node(D.v);W.selfEdges||(W.selfEdges=[]),W.selfEdges.push({e:D,label:F.edge(D)}),F.removeEdge(D)}})}function se(F){var D=h.buildLayerMatrix(F);e.forEach(D,function(W){var B=0;e.forEach(W,function(le,Y){var ce=F.node(le);ce.order=Y+B,e.forEach(ce.selfEdges,function(ue){h.addDummyNode(F,"selfedge",{width:ue.label.width,height:ue.label.height,rank:ce.rank,order:Y+ ++B,e:ue.e,label:ue.label},"_se")}),delete ce.selfEdges})})}function te(F){e.forEach(F.nodes(),function(D){var W=F.node(D);if(W.dummy==="selfedge"){var B=F.node(W.e.v),le=B.x+B.width/2,Y=B.y,ce=W.x-le,ue=B.height/2;F.setEdge(W.e,W.label),F.removeNode(D),W.label.points=[{x:le+2*ce/3,y:Y-ue},{x:le+5*ce/6,y:Y-ue},{x:le+ce,y:Y},{x:le+5*ce/6,y:Y+ue},{x:le+2*ce/3,y:Y+ue}],W.label.x=W.x,W.label.y=W.y}})}function me(F,D){return e.mapValues(e.pick(F,D),Number)}function ve(F){var D={};return e.forEach(F,function(W,B){D[B.toLowerCase()]=W}),D}return rd}var nd,fm;function mj(){if(fm)return nd;fm=1;var e=dt(),r=At(),t=Vt().Graph;nd={debugOrdering:n};function n(o){var i=r.buildLayerMatrix(o),s=new t({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(a){s.setNode(a,{label:a}),s.setParent(a,"layer"+o.node(a).rank)}),e.forEach(o.edges(),function(a){s.setEdge(a.v,a.w,{},a.name)}),e.forEach(i,function(a,c){var l="layer"+c;s.setNode(l,{rank:"same"}),e.reduce(a,function(d,u){return s.setEdge(d,u,{style:"invis"}),u})}),s}return nd}var od,hm;function bj(){return hm||(hm=1,od="0.8.5"),od}var id,pm;function vj(){return pm||(pm=1,id={graphlib:Vt(),layout:yj(),debug:mj(),util:{time:At().time,notime:At().notime},version:bj()}),id}var xj=vj();const gm=o1(xj);function wj(e,r,t){var d;const n=new Set(e.map(u=>u.id)),o=new Set;for(const u of e)u.parent&&n.has(u.parent)&&o.add(u.parent);const i=new gm.graphlib.Graph({multigraph:!0,compound:!0}),s=t.compactSpacingScale??(t.spacingFactor>0?t.spacingFactor/1.3:1);i.setGraph({rankdir:t.rankDir,nodesep:t.compact?Math.max(t.nodeSep,24*s):t.nodeSep,edgesep:t.compact?Math.min(t.edgeSep,24*s):t.edgeSep,ranksep:t.compact?Math.min(t.rankSep,80*s):t.rankSep,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({})),i.setDefaultNodeLabel(()=>({}));for(const u of e)i.setNode(u.id,{width:u.width+2,height:u.height+2});for(const u of e)u.parent&&n.has(u.parent)&&i.setParent(u.id,u.parent);for(const u of r){if(!n.has(u.source)||!n.has(u.target)||o.has(u.source)||o.has(u.target))continue;const h=zb(u.label,u.icon??((d=u.data)==null?void 0:d.icon),t.edgeLabelFontSize),p=t.rankDir==="LR"||t.rankDir==="RL",m=(h.width?h.width+2*Fb:0)+(u.connectorClearance??0);i.setEdge(u.source,u.target,{minlen:1,weight:1,...m?{width:p?m:Math.max(1,h.height),height:p?Math.max(1,h.height):m,labelpos:"c"}:{}},u.id)}gm.layout(i);const a=new Map;for(const u of e){if(o.has(u.id))continue;const h=i.node(u.id);h&&Number.isFinite(h.x)&&Number.isFinite(h.y)&&a.set(u.id,{x:h.x,y:h.y})}const c=t.compact?1:t.spacingFactor;if(c&&c!==1&&a.size){let u=1/0,h=1/0,p=-1/0,m=-1/0;a.forEach(v=>{u=Math.min(u,v.x),h=Math.min(h,v.y),p=Math.max(p,v.x),m=Math.max(m,v.y)});const y=(u+p)/2,g=(h+m)/2;a.forEach((v,b)=>a.set(b,{x:y+(v.x-y)*c,y:g+(v.y-g)*c}))}const l=t.nodeAlignment??"center";if(l!=="center"){const u=t.rankDir==="LR"||t.rankDir==="RL",h=u?"x":"y",p=u?"width":"height",m=t.rankDir==="RL"||t.rankDir==="BT"?-1:1,y=l==="leading"?-m:m,g=new Map;for(const v of e){const b=a.get(v.id);if(!b)continue;const x=b[h];g.set(x,Math.max(g.get(x)??0,v[p]))}for(const v of e){const b=a.get(v.id);if(!b)continue;const x=b[h],w=(g.get(x)-v[p])/2;a.set(v.id,{...b,[h]:x+y*w})}}return a}function yd(e,r,t,n,o,i){const s=new Map,a=new Map(e.map(u=>[u.id,u]));for(const u of e){if(!u.parent||!a.has(u.parent))continue;const h=s.get(u.parent);h?h.push(u.id):s.set(u.parent,[u.id])}const c=(u,h=new Set)=>{var m;const p=(m=a.get(u))==null?void 0:m.parent;return!p||!a.has(p)||h.has(u)?0:(h.add(u),1+c(p,h))},l=[...s.keys()].sort((u,h)=>c(h)-c(u)),d=new Map;for(const u of l){const h=i==null?void 0:i.get(u),p=r.get(u);if(h&&p){d.set(u,{x1:p.x-h.w/2,y1:p.y-h.h/2,x2:p.x+h.w/2,y2:p.y+h.h/2});continue}let m=null;for(const v of s.get(u)||[]){let b=d.get(v);if(!b){const x=r.get(v);if(!x)continue;const w=t.get(v)||{w:60,h:60};b={x1:x.x-w.w/2,y1:x.y-w.h/2,x2:x.x+w.w/2,y2:x.y+w.h/2}}m=m?{x1:Math.min(m.x1,b.x1),y1:Math.min(m.y1,b.y1),x2:Math.max(m.x2,b.x2),y2:Math.max(m.y2,b.y2)}:{...b}}if(!m)continue;const y=n(u);m={x1:m.x1-y,y1:m.y1-y,x2:m.x2+y,y2:m.y2+y};const g=o(u);if(g){const v=m.x2-m.x1,b=m.y2-m.y1;if(g.w>v){const x=(g.w-v)/2;m.x1-=x,m.x2+=x}if(g.h>b){const x=(g.h-b)/2;m.y1-=x,m.y2+=x}}d.set(u,m)}return d}function ym(e,r,t){var c,l,d;const n=[...r.weights],o=n.reduce((u,h)=>u+h,0),i=n[r.index]+n[r.index+1],s=Math.min(i*.95,Math.max(i*.05,n[r.index]+t/r.length*o));n[r.index]=s,n[r.index+1]=i-s;const a={...(l=(c=e.adjustment)==null?void 0:c.sections)==null?void 0:l[r.section]};if(r.axis==="y")a.rows=n;else{for(a.columns=[...a.columns??[]];a.columns.length<=r.row;)a.columns.push([]);a.columns[r.row]=n}return{...e,adjustment:{...e.adjustment,sections:{...(d=e.adjustment)==null?void 0:d.sections,[r.section]:a}}}}function Dv(e){if(e===void 0)return;if(!e||typeof e!="object"||Array.isArray(e)||e.enabled!==void 0&&typeof e.enabled!="boolean")throw new RangeError("Invalid grid adjustment.");const r=t=>Array.isArray(t)&&t.length<=1e4&&t.every(n=>typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1e6);if(e.sections!==void 0&&(!e.sections||typeof e.sections!="object"||Array.isArray(e.sections)))throw new RangeError("Invalid grid sections.");for(const[t,n]of Object.entries(e.sections??{}))if(["__proto__","constructor","prototype"].includes(t)||!n||typeof n!="object"||Array.isArray(n)||n.rows!==void 0&&!r(n.rows)||n.columns!==void 0&&(!Array.isArray(n.columns)||n.columns.length>1e4||!n.columns.every(r))||n.members!==void 0&&(!Array.isArray(n.members)||n.members.length>1e4||!n.members.every(o=>Array.isArray(o)&&o.length>0&&o.length<=1e4&&o.every(i=>typeof i=="string"&&i.length>0))||new Set(n.members.flat()).size!==n.members.flat().length))throw new RangeError("Invalid grid section proportions.")}function nu(e){const r=e.margin??15;if(!Number.isFinite(r)||r<0)throw new RangeError("Collision margin must be finite and non-negative.");return r}function zn(e){const r=new Map(e.nodes.map(a=>[a.id,a])),t=new Map;for(const a of e.nodes){const c=a.parent&&r.has(a.parent)?a.parent:void 0,l=t.get(c)??[];l.push(a.id),t.set(c,l)}const n=[],o=new Map,i=a=>{const c=t.get(a),l=c?c.flatMap(i):e.positions.has(a)?[a]:[];return o.set(a,l),c&&n.push(c),l},s=t.get(void 0)??[];return s.forEach(i),n.push(s),{groups:n,leaves:o,children:t,roots:s}}function ur(e,r,t=e.fixedSizes){const n=yd(e.nodes,r,e.sizes,e.padding,e.minSize,t);for(const o of e.nodes){if(n.has(o.id))continue;const i=r.get(o.id),s=e.sizes.get(o.id);i&&s&&n.set(o.id,Kt({...i,...s}))}return n}function Vv(e,r,t,n){const o=t.get(e),i=t.get(r);if(!o||!i)return;const s={x:Math.min(o.x2-i.x1,i.x2-o.x1)+n,y:Math.min(o.y2-i.y1,i.y2-o.y1)+n};if(s.x>.001&&s.y>.001)return{source:e,target:r,overlap:s}}function Mn(e,r,t){const n=[];for(const o of e)for(let i=0;i<o.length;i++)for(let s=i+1;s<o.length;s++){const a=Vv(o[i],o[s],r,t);a&&n.push(a)}return n}function Gv(e,r={}){const t=nu(r),{groups:n}=zn(e);return Mn(n,ur(e,e.positions),t)}function Wv(e,r,t,n){var a,c,l;const o=new Set(e),i=(((l=(c=(a=r.adjustment)==null?void 0:a.sections)==null?void 0:c[t])==null?void 0:l.members)??[]).map(d=>d.filter(u=>o.delete(u))).filter(d=>d.length),s=e.filter(d=>o.has(d));for(let d=0;d<s.length;d+=n)i.push(s.slice(d,d+n));return i}function Cj(e,r,t,n,o){var b,x,w,C;if(t===n)return;const{groups:i,leaves:s}=zn(e),a=i.find(S=>S.includes(t)&&S.includes(n));if(!a||a.some(S=>e.fixedIds.has(S)||(s.get(S)??[]).some(j=>e.fixedIds.has(j))))return;const c=ur(e,e.positions);if(a.some(S=>!c.has(S)))return;const l=((b=e.nodes.find(S=>S.id===t))==null?void 0:b.parent)??"canvas",d=(w=(x=r.adjustment)==null?void 0:x.sections)==null?void 0:w[l],u=[],h=[...a].sort((S,j)=>{const P=c.get(S),E=c.get(j),O=(P.y1+P.y2-E.y1-E.y2)/2;return Math.abs(O)>1?O:P.x1-E.x1});for(const S of h){const j=u.at(-1),P=c.get(S),E=j&&c.get(j[0]);E&&Math.abs(P.y1+P.y2-E.y1-E.y2)<2?j.push(S):u.push([S])}const p=u.map((S,j)=>{var P;return{weight:((P=d==null?void 0:d.rows)==null?void 0:P[j])??1,cells:S.map((E,O)=>{var A,R;return{id:E,weight:((R=(A=d==null?void 0:d.columns)==null?void 0:A[j])==null?void 0:R[O])??1}})}});for(const S of p)S.cells=S.cells.filter(j=>j.id!==t);const m=p.filter(S=>S.cells.length),y=m.findIndex(S=>S.cells.some(j=>j.id===n)),g=m[y];if(!g)return;o==="above"||o==="below"?m.splice(y+(o==="below"?1:0),0,{weight:1,cells:[{id:t,weight:1}]}):g.cells.splice(g.cells.findIndex(S=>S.id===n)+(o==="after"?1:0),0,{id:t,weight:1});const v=m.map(S=>S.cells.map(j=>j.id));if(JSON.stringify(v)!==JSON.stringify(u))return{...r,adjustment:{...r.adjustment,sections:{...(C=r.adjustment)==null?void 0:C.sections,[l]:{...d,members:v,rows:m.map(S=>S.weight),columns:m.map(S=>S.cells.map(j=>j.weight))}}}}}function ad(e,r={}){var d;Dv(r.adjustment);const t=nu(r),n=typeof r.gaps=="object"?r.gaps:{x:r.gaps??t,y:r.gaps??t};if(!n||[n.x,n.y].some(u=>!Number.isFinite(u)||u<0))throw new RangeError("Grid gaps must be finite and non-negative.");const o=r.padding??0;if(!Number.isFinite(o)||o<0)throw new RangeError("Grid padding must be finite and non-negative.");if(r.columns!==void 0&&(!Number.isSafeInteger(r.columns)||r.columns<1))throw new RangeError("Grid columns must be a positive safe integer.");if(r.fill&&e.viewportSize)return Sj(e,r,n,o);const{groups:i,leaves:s}=zn(e),a=new Map([...e.positions].map(([u,h])=>[u,{...h}])),c=new Set;for(const u of i){const h=ur(e,a),p=u.filter(A=>h.has(A));if(p.length<2)continue;if(p.some(A=>e.fixedIds.has(A)||(s.get(A)??[]).some(R=>e.fixedIds.has(R)))){p.forEach(A=>c.add(A));continue}const y=p.map(A=>h.get(A)),g=Math.max(...y.map(A=>A.x2-A.x1)),v=Math.max(...y.map(A=>A.y2-A.y1)),b=Math.min(p.length,r.columns??Math.ceil(Math.sqrt(p.length))),x=((d=e.nodes.find(A=>A.id===p[0]))==null?void 0:d.parent)??"canvas",w=Wv(p,r,x,b),C=Math.max(...w.map(A=>A.length)),S=g+n.x,j=v+n.y,P=y.map(A=>({x:(A.x1+A.x2)/2,y:(A.y1+A.y2)/2})),E=(Math.min(...P.map(A=>A.x))+Math.max(...P.map(A=>A.x)))/2,O=(Math.min(...P.map(A=>A.y))+Math.max(...P.map(A=>A.y)))/2;w.forEach((A,R)=>A.forEach((M,T)=>{const N=h.get(M),$={x:E+(T-(C-1)/2)*S-(N.x1+N.x2)/2,y:O+(R-(w.length-1)/2)*j-(N.y1+N.y2)/2};for(const I of s.get(M)??[]){const K=a.get(I);a.set(I,{x:K.x+$.x,y:K.y+$.y})}}))}const l=[...a].filter(([u,h])=>{const p=e.positions.get(u);return h.x!==p.x||h.y!==p.y}).map(([u])=>u);return{positions:a,movedNodeIds:l,skippedNodeIds:[...c],collisions:Mn(i,ur(e,a),Math.min(n.x,n.y))}}function Sj(e,r,t,n){const{groups:o,children:i,roots:s}=zn(e),a=new Map([...e.positions].map(([g,v])=>[g,{...v}]));if(e.nodes.some(g=>e.fixedIds.has(g.id)))return{positions:a,movedNodeIds:[],skippedNodeIds:e.nodes.map(g=>g.id),collisions:Gv(e,{margin:Math.min(t.x,t.y)})};const c=e.viewportSize,l=Math.min(n,Math.max(0,(c.w-1)/2)),d=Math.min(n,Math.max(0,(c.h-1)/2)),u={x1:l,y1:d,x2:Math.max(l+1,c.w-l),y2:Math.max(d+1,c.h-d)},h=new Map,p=[],m=(g,v,b="canvas")=>{var T,N;if(!g.length)return;const x=v.x2-v.x1,w=v.y2-v.y1,C=Math.min(g.length,r.columns??Math.max(1,Math.round(Math.sqrt(g.length*x/w)))),S=Wv(g,r,b,C),j=S.length,P=Math.min(t.y,w/(2*j)),E=(N=(T=r.adjustment)==null?void 0:T.sections)==null?void 0:N[b],O=Array.from({length:j},($,I)=>{var K;return((K=E==null?void 0:E.rows)==null?void 0:K[I])??1}),A=O.reduce(($,I)=>$+I,0),R=w-(j-1)*P;let M=v.y1;for(let $=0;$<j;$++){const I=R*O[$]/A,K=S[$].length,ie=Math.min(t.x,x/(2*K)),se=Array.from({length:K},(F,D)=>{var W,B;return((B=(W=E==null?void 0:E.columns)==null?void 0:W[$])==null?void 0:B[D])??1}),te=se.reduce((F,D)=>F+D,0),me=x-(K-1)*ie;let ve=v.x1;for(let F=0;F<K;F++){const D=S[$][F],W=me*se[F]/te,B=i.get(D);if(B){a.set(D,{x:ve+W/2,y:M+I/2}),h.set(D,{w:W,h:I});const le=Math.min(e.padding(D),Math.max(0,(Math.min(W,I)-1)/2));m(B,{x1:ve+le,y1:M+le,x2:ve+W-le,y2:M+I-le},D)}else a.has(D)&&(a.set(D,{x:ve+W/2,y:M+I/2}),h.set(D,{w:W,h:I}));F<K-1&&p.push({section:b,axis:"x",row:$,index:F,weights:se,length:me,position:{x:ve+W+ie/2,y:M+I/2}}),ve+=W+ie}$<j-1&&p.push({section:b,axis:"y",row:$,index:$,weights:O,length:R,position:{x:v.x1+x/2,y:M+I+P/2}}),M+=I+P}};m(s,u);const y=[...a].filter(([g,v])=>{const b=e.positions.get(g);return!b||v.x!==b.x||v.y!==b.y}).map(([g])=>g);return{positions:a,movedNodeIds:y,skippedNodeIds:[],bounds:u,sizes:h,dividers:p,collisions:Mn(o,ur({...e,sizes:h},a,h),0)}}function jj(e,r={}){const t=nu(r),n=r.maxIterations??50;if(!Number.isInteger(n)||n<0||n>1e3)throw new RangeError("Collision maxIterations must be an integer between 0 and 1000.");const{groups:o,leaves:i}=zn(e),s=new Map([...e.positions].map(([u,h])=>[u,{...h}])),a=u=>e.fixedIds.has(u)||(i.get(u)??[]).some(h=>e.fixedIds.has(h));let c=Mn(o,ur(e,s),t),l=0;for(;c.length&&l<n;){let u=!1;for(const h of o){if(h.length<2)continue;const p=ur(e,s),m=(y,g,v)=>{for(const x of i.get(y)??[])s.get(x)[g]+=v;const b=p.get(y);g==="x"?(b.x1+=v,b.x2+=v):(b.y1+=v,b.y2+=v)};for(let y=0;y<h.length;y++)for(let g=y+1;g<h.length;g++){const v=h[y],b=h[g],x=Vv(v,b,p,t);if(!x)continue;const w=a(v),C=a(b);if(w&&C)continue;const S=x.overlap.x<=x.overlap.y?"x":"y",j=p.get(v),P=p.get(b),E=S==="x"?j.x1+j.x2<=P.x1+P.x2?-1:1:j.y1+j.y2<=P.y1+P.y2?-1:1,O=x.overlap[S];w||m(v,S,E*O/(C?1:2)),C||m(b,S,-E*O/(w?1:2)),u=!0}}if(l++,c=Mn(o,ur(e,s),t),!u)break}const d=[...s].filter(([u,h])=>{const p=e.positions.get(u);return h.x!==p.x||h.y!==p.y}).map(([u])=>u);return{positions:s,movedNodeIds:d,collisions:c,iterations:l,resolved:c.length===0}}function _j({dividers:e,options:r,zoom:t,onChange:n}){const o=_.useRef();return f.jsx(f.Fragment,{children:e.map(i=>{const s=i.axis==="x",a=s?Z.PiArrowsHorizontal:Z.PiArrowsVertical,c=`${s?"Column":"Row"} divider ${i.index+1}${s?` in row ${i.row+1}`:""}`;return f.jsx("button",{type:"button",role:"separator","aria-label":c,"aria-orientation":s?"vertical":"horizontal","aria-valuemin":5,"aria-valuemax":95,"aria-valuenow":Math.round(100*i.weights[i.index]/(i.weights[i.index]+i.weights[i.index+1])),title:c,"data-flow-grid-adjustment":"",style:{position:"absolute",left:i.position.x,top:i.position.y,transform:"translate(-50%, -50%)",width:28,height:28,padding:3,border:"1px solid currentColor",borderRadius:4,background:"var(--chakra-colors-gray-100)",color:"var(--chakra-colors-gray-800)",display:"grid",placeItems:"center",cursor:s?"col-resize":"row-resize",touchAction:"none",pointerEvents:"auto",zIndex:30},onPointerDown:l=>{if(l.button!==0)return;l.preventDefault(),l.stopPropagation();const d=l.currentTarget.closest(".flow-sdk-canvas"),u=d.getBoundingClientRect();o.current={pointerId:l.pointerId,start:s?l.clientX:l.clientY,scale:t*(s?u.width/d.clientWidth:u.height/d.clientHeight),divider:i,options:r},l.currentTarget.setPointerCapture(l.pointerId)},onPointerMove:l=>{const d=o.current;if(!d||d.pointerId!==l.pointerId)return;l.preventDefault(),l.stopPropagation();const u=((s?l.clientX:l.clientY)-d.start)/d.scale;n(ym(d.options,d.divider,u))},onPointerUp:l=>{o.current&&(l.stopPropagation(),o.current=void 0,l.currentTarget.releasePointerCapture(l.pointerId))},onPointerCancel:()=>{o.current&&n(o.current.options),o.current=void 0},onLostPointerCapture:()=>{o.current=void 0},onClick:l=>l.stopPropagation(),onKeyDown:l=>{l.key==="Escape"&&o.current&&(n(o.current.options),o.current=void 0);const d=(s?["ArrowLeft","ArrowRight"]:["ArrowUp","ArrowDown"]).indexOf(l.key);d<0||(l.preventDefault(),l.stopPropagation(),n(ym(r,i,i.length*(l.shiftKey?.1:.02)*(d===0?-1:1))))},children:f.jsx(a,{size:20,"aria-hidden":"true"})},`${i.section}:${i.axis}:${i.row}:${i.index}`)})})}const mm=(e,r)=>e.left<r.right&&e.right>r.left&&e.top<r.bottom&&e.bottom>r.top;function Ej(e){const r=e.querySelector(".flow-sdk-labels"),t=r==null?void 0:r.getScreenCTM();if(!r||!t)return;const n=t.inverse(),o=(l,d=0)=>{const u=l.getBoundingClientRect(),h=new DOMPoint(u.left,u.top).matrixTransform(n),p=new DOMPoint(u.right,u.bottom).matrixTransform(n);return{left:h.x-d,right:p.x+d,top:h.y-d,bottom:p.y+d}},i=[...e.querySelectorAll(".flow-sdk-node, .flow-sdk-node button")].filter(l=>{const d=l.getBoundingClientRect(),u=getComputedStyle(l);return d.width>0&&d.height>0&&u.visibility!=="hidden"&&u.opacity!=="0"}).map(l=>o(l,24));for(const l of r.querySelectorAll(".flow-sdk-container-label"))i.push(o(l,12));const s=[...r.querySelectorAll(".flow-sdk-edge-label")];for(const l of s)l.setAttribute("transform",l.dataset.labelTransform??"");const a=new Map(s.map(l=>[l,o(l,8)])),c=new Map([...e.querySelectorAll(".flow-sdk-edge")].map(l=>[l.dataset.edgeId,l.querySelector("path")]));for(const l of s){const d=l.dataset.labelHorizontal==="true",u=a.get(l);a.delete(l);const h=j=>i.some(P=>mm(j,P))||[...a.values()].some(P=>mm(j,P));if(!d&&!h(u)){a.set(l,u);continue}const p=c.get(l.dataset.edgeId),m=l.querySelector("rect");if(!p||!m)continue;const y=m.getBBox(),g=p.getTotalLength();if(!Number.isFinite(g)||g<=0)continue;const v=(u.left+u.right)/2,b=(u.top+u.bottom)/2,x=Math.min(256,Math.max(16,Math.ceil(g/24))),w=Array.from({length:x+1},(j,P)=>p.getPointAtLength(g*P/x)),S=Array.from({length:x+1},(j,P)=>{const E=g*P/x,O=w[P],A=d?{x:O.x,y:O.y-y.height/2-15}:O,R=p.getPointAtLength(Math.max(0,E-2)),M=p.getPointAtLength(Math.min(g,E+2));let T=Math.atan2(M.y-R.y,M.x-R.x)*180/Math.PI;T>90&&(T-=180),T<-90&&(T+=180);const N=Math.abs(T)<1;d&&(T=0);const $=T*Math.PI/180,I=Math.abs(Math.cos($))*y.width+Math.abs(Math.sin($))*y.height,K=Math.abs(Math.sin($))*y.width+Math.abs(Math.cos($))*y.height;return{point:A,angle:T,straight:N,score:Math.hypot(A.x-v,A.y-b),bounds:{left:A.x-I/2-8,right:A.x+I/2+8,top:A.y-K/2-8,bottom:A.y+K/2+8}}}).sort((j,P)=>j.score-P.score).find(j=>!h(j.bounds)&&(!d||j.straight&&!w.some(P=>P.x>j.bounds.left&&P.x<j.bounds.right&&P.y>j.bounds.top&&P.y<j.bounds.bottom)));S?(l.setAttribute("transform",`translate(${S.point.x} ${S.point.y}) rotate(${S.angle})`),a.set(l,S.bounds)):a.set(l,u)}}function kj(e){const r=e.getBoundingClientRect(),t=r.height/e.offsetHeight;if(!Number.isFinite(t)||t<=0)return[];const n=qb(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],s=new Set(i.filter(a=>a.hasAttribute("data-flow-inspection-row")&&a.getBoundingClientRect().height>0).map(a=>a.dataset.flowProperty));return i.flatMap(a=>{if(a.closest(".flow-sdk-node")!==e)return[];if(s.has(a.dataset.flowProperty)&&!a.hasAttribute("data-flow-inspection-row"))return[];const c=a.dataset.flowPortSide;if(c&&["top","right","bottom","left"].includes(c)){const d=Ob(n?_n(o,n):o,c,Number(a.dataset.flowPortPosition??.5));return[{property:a.getAttribute("data-flow-property"),top:d.y,height:0,anchor:d,...a.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]}const l=a.getBoundingClientRect();return!l.width||!l.height?[]:[{property:a.getAttribute("data-flow-property"),top:Math.round((l.top-r.top)/t*1e3)/1e3,height:Math.round(l.height/t*1e3)/1e3,...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]})}function Rj({id:e,x:r,y:t,placed:n,hidden:o,gridDraggable:i,gridDragging:s,gridDropTarget:a,gridSize:c,gridPreview:l,onMount:d,drawHandles:u,drawMode:h,connectedPorts:p,resolvedRows:m,hasCollapseControl:y,handleColor:g,animated:v,animationColor:b,animationWidth:x=8,animationVariant:w,width:C=0,height:S=0,propertyMode:j,reversePorts:P,direction:E="LR",onPropertyRows:O,onSurface:A,children:R}){var B,le;const M=_.useRef(null),[T,N]=_.useState([]),$=m??T,[I,K]=_.useState(),ie=_.useId(),se=_.useRef(),te=!!l,me=!!(l!=null&&l.floating);_.useLayoutEffect(()=>{var Ce;const Y=M.current;if(!Y||!te)return;const ce=Y.cloneNode(!0);ce.removeAttribute("data-node-id"),ce.removeAttribute("data-grid-dragging"),ce.removeAttribute("data-grid-draggable"),ce.removeAttribute("data-grid-drop-target"),ce.setAttribute("data-grid-preview",e),ce.setAttribute("aria-hidden","true"),ce.setAttribute("inert","");const ue=[ce,...ce.querySelectorAll("*")],xe=new Map(ue.filter(ye=>ye.id).map(ye=>[ye.id,`${ye.id}-${ie}`]));for(const ye of ue){ye.id&&(ye.id=xe.get(ye.id));for(const pe of[...ye.attributes]){if(pe.name==="id")continue;let X=pe.value;for(const[L,ae]of xe)X===`#${L}`&&(X=`#${ae}`),X=X.split(`url(#${L})`).join(`url(#${ae})`);X!==pe.value&&ye.setAttribute(pe.name,X)}}if(Object.assign(ce.style,{opacity:"0.35",zIndex:me?"2147483647":"11",pointerEvents:"none",outline:"none",visibility:"visible"}),me){const ye=getComputedStyle(Y);ce.setAttribute("data-grid-preview-floating",""),Object.assign(ce.style,{position:"fixed",left:"0",top:"0",transformOrigin:"top left",font:ye.font,color:ye.color});for(const pe of ue)pe.removeAttribute("data-node-id"),pe.style.pointerEvents="none"}return ce.querySelectorAll(".flow-sdk-node-animation, .flow-sdk-handle, .flow-sdk-property-port, [data-flow-collapse-control]").forEach(ye=>ye.remove()),(Ce=me?document.body:Y.parentElement)==null||Ce.appendChild(ce),se.current=ce,()=>{ce.remove(),se.current=void 0}},[e,ie,te,me]),_.useLayoutEffect(()=>{const Y=se.current;if(!Y||!l)return;const{x:ce,y:ue,size:xe}=l;if(me&&M.current){const pe=M.current,X=pe.getBoundingClientRect(),L=X.width/pe.offsetWidth||1,ae=X.height/pe.offsetHeight||1,H=X.left+(ce-r)*L,fe=X.top+(ue-t)*ae;Y.style.transform=`translate3d(${H}px, ${fe}px, 0) scale(${L}, ${ae})`,Y.style.width=`${pe.offsetWidth}px`,Y.style.height=`${pe.offsetHeight}px`;return}const Ce=xe?Math.round(ce-xe.w/2):ce,ye=xe?Math.round(ue-xe.h/2):ue;Y.style.transform=xe?`translate3d(${Ce}px, ${ye}px, 0)`:`translate(-50%, -50%) translate3d(${Ce}px, ${ye}px, 0)`,Y.style.width=xe?`${Math.round(ce+xe.w/2)-Ce}px`:"",Y.style.height=xe?`${Math.round(ue+xe.h/2)-ye}px`:"",xe&&(Y.style.setProperty("--flow-grid-width",`${xe.w}px`),Y.style.setProperty("--flow-grid-height",`${xe.h}px`),Y.style.setProperty("--flow-grid-font",`${Math.max(12,Math.min(48,xe.w/8,xe.h/5))}px`))},[l==null?void 0:l.x,l==null?void 0:l.y,(B=l==null?void 0:l.size)==null?void 0:B.w,(le=l==null?void 0:l.size)==null?void 0:le.h,me,r,t]),_.useLayoutEffect(()=>{const Y=M.current;if(!Y)return;const ce=()=>{const Ce=qb(Y);K(ye=>JSON.stringify(ye)===JSON.stringify(Ce)?ye:Ce),A==null||A(e,Ce)};ce();const ue=new ResizeObserver(ce);ue.observe(Y);const xe=Y.querySelector("[data-flow-node-surface]");return xe&&ue.observe(xe),()=>ue.disconnect()},[e,R,A]),_.useLayoutEffect(()=>(d(e,M.current),()=>{d(e,null),A==null||A(e,void 0)}),[e,d,A]),_.useLayoutEffect(()=>{const Y=M.current;if(!Y)return;let ce="";const ue=()=>{const pe=kj(Y),X=j?pe:pe.filter(ae=>ae.anchor),L=JSON.stringify(X);L!==ce&&(ce=L,N(X),O==null||O(e,X))};if(ue(),!j&&!Y.querySelector("[data-flow-port-side]"))return;const xe=new ResizeObserver(ue),Ce=()=>{xe.disconnect(),xe.observe(Y),Y.querySelectorAll("[data-flow-property]").forEach(pe=>xe.observe(pe)),ue()};Ce();const ye=new MutationObserver(Ce);return ye.observe(Y,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["data-flow-property","data-flow-port-role","data-flow-port-side","data-flow-port-position","data-flow-port-placement"]}),Y.addEventListener("scroll",ue,!0),()=>{xe.disconnect(),ye.disconnect(),Y.removeEventListener("scroll",ue,!0)}},[e,j,O,R]);const ve=c?Math.round(r-c.w/2):0,F=c?Math.round(t-c.h/2):0,D=c?Math.round(r+c.w/2)-ve:void 0,W=c?Math.round(t+c.h/2)-F:void 0;return f.jsxs("div",{ref:M,className:"flow-sdk-node","data-node-id":e,"data-grid-draggable":i||void 0,"data-grid-dragging":s||void 0,"data-grid-drop-target":a||void 0,"data-grid-fill":c?"":void 0,style:{transform:c?`translate3d(${ve}px, ${F}px, 0)`:`translate(-50%, -50%) translate3d(${r.toFixed(2)}px, ${t.toFixed(2)}px, 0)`,visibility:n&&!o?void 0:"hidden",cursor:i?s?"grabbing":"grab":void 0,zIndex:s?12:void 0,opacity:l?0:s?.75:void 0,outline:a?`2px solid ${g||"currentColor"}`:void 0,outlineOffset:a?8:void 0,width:D,height:W,...c?{"--flow-grid-width":`${c.w}px`,"--flow-grid-height":`${c.h}px`,"--flow-grid-font":`${Math.max(12,Math.min(48,c.w/8,c.h/5))}px`}:{}},children:[R,!c&&v&&x>0&&C>0&&S>0&&f.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:f.jsx(ro,{variant:w,x:((I==null?void 0:I.left)??0)+x/2,y:((I==null?void 0:I.top)??0)+x/2,width:((I==null?void 0:I.width)??C)-x,height:((I==null?void 0:I.height)??S)-x,radius:((I==null?void 0:I.radius)??0)-x/2,path:I!=null&&I.outline?`M${I.outline.map(Y=>`${Y.x} ${Y.y}`).join(" L")} Z`:void 0,color:b||g||"currentColor",strokeWidth:x})}),u&&j&&$.map(Y=>["source","target"].filter(ce=>!Y.role||Y.role===ce).filter(ce=>h||(p==null?void 0:p.has(`${ce}:${Y.property}`))).map(ce=>{var ue;return f.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":Y.property,"data-port-role":ce,"data-port-side":(ue=Y.anchor)==null?void 0:ue.side,"aria-label":`${ce==="source"?"Connect":"Input"} ${Y.property}`,title:`${ce==="source"?"Connect":"Input"} ${Y.property}`,style:{color:g,...Y.anchor?{top:Y.anchor.y,left:Y.anchor.x-16}:{top:Y.top+Y.height/2,[ce==="source"!=!!P?"right":"left"]:-16}},onClick:xe=>xe.stopPropagation()},`${Y.property}:${ce}`)})),u&&!y&&(!j||!$.length)&&(!j||!$.some(Y=>Y.anchor))&&f.jsx("button",{type:"button",className:"flow-sdk-handle","aria-label":"Draw edge",title:"Draw edge",style:{color:g,left:((I==null?void 0:I.left)??0)+(E==="RL"?-36:E==="LR"?(I==null?void 0:I.width)??C:((I==null?void 0:I.width)??C)/2),top:((I==null?void 0:I.top)??0)+(E==="BT"?-36:E==="TB"?(I==null?void 0:I.height)??S:((I==null?void 0:I.height)??S)/2),transform:E==="BT"||E==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:Y=>Y.stopPropagation(),children:f.jsx(Z.PiPlusBold,{size:24})})]})}const Aj=_.memo(Rj);function Pj(e,r,t){const[n,o]=_.useState(()=>({nodes:new Set,edges:new Set})),i=_.useMemo(()=>{const a=new Set(e.map(p=>p.id)),c=r.filter(p=>a.has(p.source)&&a.has(p.target)).map(p=>({id:p.id,source:p.inverted?p.target:p.source,target:p.inverted?p.source:p.target})),l=new Set(c.map(p=>p.id)),d=new Set([...n.nodes].filter(p=>a.has(p))),u=new Set([...n.edges].filter(p=>l.has(p)));if(!t)return{nodes:a,edges:l,ready:l};for(const p of e)c.filter(y=>y.target===p.id&&y.source!==y.target).every(y=>u.has(y.id))&&d.add(p.id);let h=new Set(c.filter(p=>d.has(p.source)).map(p=>p.id));if(d.size<a.size&&!c.some(p=>h.has(p.id)&&!u.has(p.id))){const p=e.find(m=>!d.has(m.id));p&&d.add(p.id),h=new Set(c.filter(m=>d.has(m.source)).map(m=>m.id))}return{nodes:d,edges:u,ready:h}},[e,r,t,n]);_.useLayoutEffect(()=>{o(a=>{const c=t?i:{nodes:new Set,edges:new Set},l=(d,u)=>d.size===u.size&&[...d].every(h=>u.has(h));return l(a.nodes,c.nodes)&&l(a.edges,c.edges)?a:{nodes:c.nodes,edges:c.edges}})},[i,t]);const s=_.useCallback(a=>{o(c=>c.edges.has(a)?c:{...c,edges:new Set([...c.edges,a])})},[]);return{shown:i.nodes,ready:i.ready,complete:s}}class Ij{constructor(r,t,n){Ot(this,"_pan");Ot(this,"_zoom");Ot(this,"minZoom");Ot(this,"maxZoom");Ot(this,"size",{w:0,h:0});Ot(this,"listeners",new Set);Ot(this,"cancelTransition");Ot(this,"animationVersion",0);Ot(this,"captureTransition");Ot(this,"animationsDisabled",!1);Ot(this,"finishTransition");this.minZoom=t,this.maxZoom=n,this._pan={...r.pan},this._zoom=this.clamp(r.zoom)}setAnimationsDisabled(r){var t;r!==this.animationsDisabled&&(this.animationsDisabled=r,r&&((t=this.finishTransition)==null||t.call(this),this.cancelAnimation()))}cancelAnimation(){var r;(r=this.cancelTransition)==null||r.call(this),this.cancelTransition=void 0,this.finishTransition=void 0,this.animationVersion++}coordinate(r){let t;this.captureTransition=n=>{t=n};try{r()}finally{this.captureTransition=void 0}return t}transition(r,t=!1){this.cancelAnimation();const n=this.state,o={pan:{...r.pan},zoom:this.clamp(r.zoom)},i=this.animationVersion,s=Mb(t,this.animationsDisabled),a=c=>{if(i!==this.animationVersion)return;const l=s?c:1;this.apply({x:n.pan.x+(o.pan.x-n.pan.x)*l,y:n.pan.y+(o.pan.y-n.pan.y)*l},n.zoom+(o.zoom-n.zoom)*l)};this.finishTransition=()=>a(1),this.captureTransition?this.captureTransition(a):this.cancelTransition=Tb(s,a,void 0,300/1.4)}get pan(){return{...this._pan}}get zoom(){return this._zoom}get state(){return{pan:this.pan,zoom:this._zoom}}clamp(r){return Number.isFinite(r)?Math.max(this.minZoom,Math.min(this.maxZoom,r)):this.minZoom}set(r,t){this.cancelAnimation(),this.apply(r,t)}apply(r,t){let n=!1;if(r&&(r.x!==this._pan.x||r.y!==this._pan.y)&&(this._pan={x:r.x,y:r.y},n=!0),t!==void 0){const o=this.clamp(t);o!==this._zoom&&(this._zoom=o,n=!0)}n&&this.emit()}zoomAt(r,t){const n=this.clamp(r),o=this._zoom;if(n===o)return;const i=n/o;this.set({x:t.x-(t.x-this._pan.x)*i,y:t.y-(t.y-this._pan.y)*i},n)}fit(r,t=0,n=!1,o=1){const i=r.x2-r.x1,s=r.y2-r.y1;if(!(i>0)||!(s>0)||!this.size.w||!this.size.h)return;const a=this.clamp(this.clamp(Math.min((this.size.w-2*t)/i,(this.size.h-2*t)/s))*o);this.transition({pan:{x:(this.size.w-a*(r.x1+r.x2))/2,y:(this.size.h-a*(r.y1+r.y2))/2},zoom:a},n)}center(r,t=!1){if(!this.size.w||!this.size.h)return;const n=this._zoom;this.transition({pan:{x:(this.size.w-n*(r.x1+r.x2))/2,y:(this.size.h-n*(r.y1+r.y2))/2},zoom:n},t)}renderedToModel(r){return{x:(r.x-this._pan.x)/this._zoom,y:(r.y-this._pan.y)/this._zoom}}modelToRendered(r){return{x:r.x*this._zoom+this._pan.x,y:r.y*this._zoom+this._pan.y}}onChange(r){return this.listeners.add(r),()=>{this.listeners.delete(r)}}emit(){const r=this.state;this.listeners.forEach(t=>t(r))}}const Mj={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},Zn={w:60,h:60},sd=4,Tj=30,Oj=500,Nj=45;function bm(e){const[r,t]=[...e.values()];return!r||!t?null:{center:{x:(r.x+t.x)/2,y:(r.y+t.y)/2},distance:Math.max(1,Math.hypot(t.x-r.x,t.y-r.y))}}function $j(e){var pu,gu,yu,mu,bu;const{nodes:r,edges:t,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:s=!1,rankSep:a,edgeSep:c,spacingFactor:l=1.3,compactSpacingScale:d,minZoom:u,maxZoom:h,initialViewport:p,containerStyle:m,lineColor:y,drawMode:g,dragMode:v,multiSelect:b,isPerformanceMode:x,disableAnimations:w=!1}=e,[C,S]=_.useState(null),j=_.useMemo(()=>C?(C.mode==="connections"?Wu:Fu)(C.id,r,t):null,[C,r,t]),P=i==="auto"||i==="properties",E=_.useMemo(()=>t.filter(k=>gd(k,i)&&(!j||j.has(k.source)&&j.has(k.target))),[t,i,j]),O=_.useMemo(()=>Qw(r,t,i,s,j),[r,t,i,s,j]),A=_.useRef(O);A.current=O;const R=_.useRef(e);R.current=e;const M=_.useRef(null),T=_.useRef(null),N=_.useRef(null),$=_.useRef(null),I=_.useMemo(()=>new Ij(p,u,h),[]);_.useEffect(()=>{I.minZoom=u,I.maxZoom=h},[I,u,h]),_.useLayoutEffect(()=>{I.setAnimationsDisabled(w)},[I,w]);const K=_.useRef(new Map),ie=_.useRef(new Map),se=_.useRef(new Map),te=_.useRef(null),[me,ve]=_.useState(new Map),F=_.useCallback((k,q)=>{ve(z=>{if(JSON.stringify(z.get(k))===JSON.stringify(q))return z;const J=new Map(z);return q?J.set(k,q):J.delete(k),J})},[]),[D,W]=_.useState(new Map),B=_.useRef(D),le=_.useCallback((k,q)=>{W(z=>{if(JSON.stringify(z.get(k)??[])===JSON.stringify(q))return z;const J=new Map(z);return q.length?J.set(k,q):J.delete(k),J})},[]),[Y,ce]=_.useState(()=>new Map),ue=_.useRef(Y);ue.current=Y;const[xe,Ce]=_.useState(new Map),ye=_.useRef(xe),pe=()=>{ye.current=new Map,Ce(ye.current)},X=_.useRef(new Map),L=_.useRef(null),ae=_.useRef(!1),[H,fe]=_.useState(0),be=_.useRef(),Ne=_.useRef(),Le=_.useRef(null),Be=_.useRef(!1),tt=_.useRef(null),Je=_.useRef(null),yt=_.useRef(l),Ye=s,nt=_.useRef(Ye),[ht,Te]=_.useState(!0),[Ve,st]=_.useState(!!((pu=e.initialNodeGrid)!=null&&pu.enabled)),[ct,zt]=_.useState([]),Ge=_.useRef((gu=e.initialNodeGrid)!=null&&gu.enabled?{options:{...e.initialNodeGrid.options,animate:!1},order:[...e.initialNodeGrid.order??e.initialNodeGrid.options.order??r.map(k=>k.id)],previousPositions:new Map,previousViewport:p,previousSize:{w:0,h:0},ready:!1}:null),[De,Wt]=_.useState(null),lt=_.useRef(null);lt.current=j;const nr=_.useRef(1);nr.current=(C==null?void 0:C.mode)==="connections"?1.25:1;const Ut=_.useRef(null),Mr=_.useRef(r),Et=_.useRef([]),Ht=_.useRef(!1),Yt=()=>{var k;(k=Le.current)==null||k.call(Le),Le.current=null},Tr=()=>{Je.current=null,Et.current.length&&(Ht.current=!0),!ae.current&&R.current.fitOnInit!==!1&&(Be.current=!0),clearTimeout(Ne.current),Ne.current=setTimeout(()=>{ae.current=ue.current.size>0,fe(k=>k+1)},Oj)},br=(k,q,z,J=Tr,de)=>{Yt();const Pe=new Map(ue.current),we=new Map([...K.current,...ye.current]);Le.current=Tb(q,Ee=>{const Ie=new Map;if(k.forEach((ke,Oe)=>{const Ke=Pe.get(Oe);Ie.set(Oe,Ke?{x:Ke.x+(ke.x-Ke.x)*Ee,y:Ke.y+(ke.y-Ke.y)*Ee}:ke)}),ue.current=Ie,ce(Ie),de){const ke=new Map;for(const[Oe,Ke]of de){const ee=we.get(Oe)??Ke;ke.set(Oe,{w:ee.w+(Ke.w-ee.w)*Ee,h:ee.h+(Ke.h-ee.h)*Ee})}ye.current=ke,Ce(ke)}z==null||z(Ee)},J)},Fe=()=>{if(clearTimeout(be.current),Ge.current){mt.arrangeNodesInGrid(Ge.current.options);return}ye.current.size&&pe();const k=R.current,q=nr.current,z=A.current,J=z.nodes.map(Ie=>{const ke=ie.current.get(Ie.id);ke&&(ke.offsetWidth||ke.offsetHeight)&&K.current.set(Ie.id,{w:ke.offsetWidth,h:ke.offsetHeight});const Oe=K.current.get(Ie.id)||Zn;return{id:Ie.id,parent:Ie.parent,width:Oe.w,height:Oe.h}});let de;try{const Ie=k.compactPropertyLayout,ke=k.edgeMode!=="nodes"&&k.edgeMode!=="workflow",Oe=z.edges.map(Ke=>({...Ke,connectorClearance:Ie?ke&&(Ke.sourceProperty!==void 0||Ke.targetProperty!==void 0)?Yw:Xw:0}));de=wj(J,Oe,{edgeLabelFontSize:k.edgeMode==="nodes"||k.edgeMode==="workflow"?Lb:no,rankDir:k.direction,compact:Ie,nodeAlignment:k.nodeAlignment,rankSep:k.rankSep*q,edgeSep:k.edgeSep*q,nodeSep:5*q,spacingFactor:k.spacingFactor??1.3,compactSpacingScale:(k.compactSpacingScale??(k.spacingFactor??1.3)/1.3)*q})}catch(Ie){console.warn("[flow-sdk] layout failed",Ie);return}const Pe=L.current;L.current=null;const we=Pe&&de.get(Pe.id);if(Pe&&we){const Ie={x:Pe.position.x-we.x,y:Pe.position.y-we.y};de=new Map([...de].map(([ke,Oe])=>[ke,{x:Oe.x+Ie.x,y:Oe.y+Ie.y}]))}for(const[Ie,ke]of X.current)de.has(Ie)?de.set(Ie,ke):k.nodes.some(Oe=>Oe.id===Ie)||X.current.delete(Ie);const Ee=I.coordinate(()=>{var Ie;return(Ie=Je.current)==null?void 0:Ie.call(Je,de)});br(de,ae.current&&!k.isPerformanceMode&&!k.disableAnimations,Ee)},re=_.useCallback(()=>{clearTimeout(Ne.current),clearTimeout(be.current),be.current=setTimeout(Fe,R.current.layoutDebounce)},[]);_.useLayoutEffect(()=>{const k=new Map(Mr.current.map(q=>[q.id,q]));r.some(q=>{var z;return((z=k.get(q.id))==null?void 0:z.collapsed)===!0&&!q.collapsed})&&(Et.current=r.filter(q=>!k.has(q.id)).map(q=>q.id)),Mr.current=r,yt.current!==l&&ue.current.size>0&&(ae.current=!0,Be.current=!1,clearTimeout(Ne.current)),yt.current=l,nt.current!==Ye&&(Be.current=!tt.current),nt.current=Ye,Je.current&&!tt.current?(clearTimeout(be.current),Fe()):re()},[r,t,O.nodes,O.edges,Ye,n,o,a,c,re,l,d,w,e.nodeGridSpacing]),_.useEffect(()=>()=>{clearTimeout(be.current),clearTimeout(Ne.current),Yt()},[]);const G=_.useCallback((k,q)=>{var z,J;if(!te.current&&typeof ResizeObserver<"u"&&(te.current=new ResizeObserver(de=>{let Pe=!1;for(const we of de){const Ee=se.current.get(we.target);if(!Ee||ye.current.has(Ee))continue;const Ie=we.target,ke=Ie.offsetWidth,Oe=Ie.offsetHeight;if(!ke&&!Oe)continue;const Ke=K.current.get(Ee);if(Ke&&Ke.w===ke&&Ke.h===Oe)continue;const ee=ue.current.get(Ee);Ke&&ee&&ae.current&&!L.current&&(L.current={id:Ee,position:{...ee}}),K.current.set(Ee,{w:ke,h:Oe}),Pe=!0}Pe&&(Je.current&&!tt.current?Fe():re())})),q){ie.current.set(k,q),se.current.set(q,k),(z=te.current)==null||z.observe(q);const de=q.offsetWidth,Pe=q.offsetHeight;!ye.current.has(k)&&(de||Pe)&&K.current.set(k,{w:de,h:Pe})}else{const de=ie.current.get(k);de&&((J=te.current)==null||J.unobserve(de),se.current.delete(de)),ie.current.delete(k),K.current.delete(k),B.current.has(k)&&le(k,[])}re()},[re,le]);_.useEffect(()=>()=>{var k;return(k=te.current)==null?void 0:k.disconnect()},[]);const ne=k=>{var J;const q=(J=R.current.nodes.find(de=>de.id===k))==null?void 0:J.label;if(!q)return;const z=R.current.containerStyle(k);return{w:po(q,`bold ${z.fontSize}px ${dr}`)+2*Nj,h:0}},$e=_.useMemo(()=>{const k=new Map;for(const q of r)q.label&&k.set(q.id,q.label);return k},[r]),U=_.useMemo(()=>yd(O.nodes,Y,new Map([...K.current,...xe]),k=>m(k).padding,ne,xe),[O.nodes,Y,m,$e,xe]),he=_.useRef(U);he.current=U;const Se=_.useCallback(k=>{const q=he.current.get(k);if(q)return qw(q);const z=ue.current.get(k);if(!z)return;const J=ye.current.get(k)||K.current.get(k)||Zn;return{x:z.x,y:z.y,w:J.w,h:J.h}},[]),_e=_.useMemo(()=>{const k=new Map;for(const q of r){const z=Se(q.id);z&&k.set(q.id,z)}return Uw(D,k,me,t,n)},[D,r,Y,U,me,t,n,Se]);B.current=_e;const Xe=(k,q)=>{var de;if(!P||q===void 0)return;const z=(de=_e.get(k))==null?void 0:de.find(Pe=>Pe.property===q),J=Se(k);return z&&!z.anchor&&J?J.y-J.h/2+z.top+z.height/2:void 0},Qe=(k,q)=>{var de,Pe;if(q===void 0)return;const z=(Pe=(de=_e.get(k))==null?void 0:de.find(we=>we.property===q))==null?void 0:Pe.anchor,J=Se(k);return z&&J?{x:J.x-J.w/2+z.x,y:J.y-J.h/2+z.y,side:z.side}:void 0},He=(k,q)=>{const z=Se(k),J=me.get(k);return z&&J&&!U.has(k)&&Xe(k,q)===void 0?_n(z,J):z},kt=()=>{const k=[];ue.current.forEach((q,z)=>{if(he.current.has(z))return;const J=Se(z);J&&k.push(Kt(J))}),he.current.forEach(q=>k.push(q));try{for(const q of[T.current,N.current]){const z=q==null?void 0:q.getBBox();z&&z.width>0&&z.height>0&&k.push({x1:z.x,y1:z.y,x2:z.x+z.width,y2:z.y+z.height})}}catch{}return Do(k)},St=()=>{var z,J;const{pan:k,zoom:q}=I;$.current&&($.current.style.transform=`translate3d(${k.x}px, ${k.y}px, 0) scale(${q})`),(z=T.current)==null||z.setAttribute("transform",`translate(${k.x} ${k.y}) scale(${q})`),(J=N.current)==null||J.setAttribute("transform",`translate(${k.x} ${k.y}) scale(${q})`)};_.useEffect(()=>{St();let k=null,q;const z=I.onChange(()=>{St();const J=M.current;J&&(J.classList.add("flow-sdk-busy"),clearTimeout(q),q=setTimeout(()=>J.classList.remove("flow-sdk-busy"),150)),k===null&&(k=requestAnimationFrame(()=>{var de,Pe;k=null,(Pe=(de=R.current).onViewportChange)==null||Pe.call(de,I.state)}))});return()=>{z(),clearTimeout(q),k!==null&&cancelAnimationFrame(k)}},[]),_.useLayoutEffect(()=>{const k=M.current;if(!k)return;const q=()=>{var we;if(!k.getClientRects().length)return;let J=k.clientWidth,de=k.clientHeight;de||(de=Math.max(0,window.innerHeight-k.getBoundingClientRect().top-100),de&&(k.style.height=`${de}px`)),J||(J=window.innerWidth,J&&(k.style.width=`${J}px`));const Pe=I.size.w!==J||I.size.h!==de;I.size={w:J,h:de},Pe&&((we=Ge.current)!=null&&we.options.fill)&&re(),!ae.current&&!ue.current.size&&R.current.fitOnInit!==!1&&(I.set({x:J/2,y:de/2}),St())};if(q(),typeof ResizeObserver>"u")return;const z=new ResizeObserver(q);return z.observe(k),()=>z.disconnect()},[I]),_.useLayoutEffect(()=>{if(Ht.current){Ht.current=!1;const q=Et.current.flatMap(J=>{const de=Se(J);return de?[Kt(de)]:[]});Et.current=[];const z=Do(q);if(z){Be.current=!1,I.center(z,R.current.animateViewport);return}}if(!Be.current)return;Be.current=!1;const k=kt();k&&(I.fit(k,50,ae.current&&R.current.animateViewport),ae.current||St())},[Y]);const mt=_.useMemo(()=>{const k=ee=>{const Q=R.current;if(Q.nodeGridSpacing!=="layout")return ee;const ge=Q.direction==="LR"||Q.direction==="RL";return{...ee,gaps:{x:ge?Q.rankSep:Q.edgeSep,y:ge?Q.edgeSep:Q.rankSep}}},q=()=>{const ee=R.current,Q=A.current.nodes.filter(ge=>Qt(ge.id,ee.edges,ee.edgeMode)&&(!lt.current||lt.current.has(ge.id)));return{nodes:Q,positions:ue.current,sizes:new Map(Q.map(ge=>[ge.id,K.current.get(ge.id)??Zn])),padding:ge=>R.current.containerStyle(ge).padding,minSize:ne,fixedIds:new Set(X.current.keys()),viewportSize:{...I.size}}},z=ee=>Fu(ee,R.current.nodes,R.current.edges),J=(ee,Q=!0,ge=()=>{},oe,We,Re=!1)=>{clearTimeout(be.current),clearTimeout(Ne.current),Re||(Je.current=null),tt.current=null,Be.current=!1,Et.current=[],Ht.current=!1,I.cancelAnimation();const je=Q&&!R.current.isPerformanceMode&&!R.current.disableAnimations,ot=I.coordinate(()=>{var ze;oe?oe(je):Re&&((ze=Je.current)==null||ze.call(Je,ee))});br(new Map([...ee].map(([ze,pt])=>[ze,{...pt}])),je,ot,ge,We)},de=(ee,Q=50,ge=R.current.animateViewport,oe=1,We=!1)=>{const Re=je=>{const ot=A.current,ze=ee??new Set(ot.nodes.map(Rt=>Rt.id)),pt=new Set(ot.nodes.map(Rt=>Rt.parent).filter(Boolean));if(!je&&(!ee||[...ee].some(Rt=>pt.has(Rt))))return;const or=je&&yd(ot.nodes,je,K.current,Rt=>R.current.containerStyle(Rt).padding,ne),ir=Do([...ze].flatMap(Rt=>{const on=or==null?void 0:or.get(Rt);if(on)return[on];const an=je==null?void 0:je.get(Rt),Un=K.current.get(Rt)||Zn,sn=an?{...an,...Un}:Se(Rt);return sn?[Kt(sn)]:[]}));ir&&(Be.current=!1,Et.current=[],Ht.current=!1,I.fit(ir,Number.isFinite(Q)?Math.max(0,Q):50,ge,oe))};Je.current=We?Re:null,We||Re(ue.current)},Pe=(ee,Q,ge,oe)=>{var Re;if(!Se(ee))return;const We=Q==="connections"?Ee(ee):z(ee);if(Q==="connections"&&nr.current===1.25&&((Re=lt.current)==null?void 0:Re.size)===We.size&&[...We].every(je=>lt.current.has(je))){S({id:ee,mode:Q});return}Ut.current||(Ut.current={pan:{...I.pan},zoom:I.zoom}),lt.current=We,R.current.compactPropertyLayout&&(Be.current=!1,tt.current=()=>de(lt.current??We,ge,oe)),S({id:ee,mode:Q}),R.current.compactPropertyLayout||de(We,ge,oe)},we=ee=>{tt.current?tt.current=ee:ee()},Ee=ee=>Wu(ee,R.current.nodes,R.current.edges),Ie=(ee=>{var Q,ge,oe;if(ee===void 0)return I.zoom;ee<I.zoom&&((Q=Ge.current)!=null&&Q.options.fill)&&!R.current.readOnly&&((oe=(ge=R.current).onNodeGridZoomOut)==null?void 0:oe.call(ge,Ge.current.options))===!0||(Je.current=null,I.set(void 0,ee))}),ke=(ee=>{if(ee===void 0)return I.pan;Je.current=null,I.set(ee)}),Oe=(ee,Q)=>{var oe;const ge=(oe=M.current)==null?void 0:oe.getBoundingClientRect();return{x:ee-((ge==null?void 0:ge.left)??0),y:Q-((ge==null?void 0:ge.top)??0)}},Ke=(ee=0,Q=R.current.animateViewport,ge=!1)=>{if(ge){de(void 0,ee,Q,1,!0);return}Je.current=null,we(()=>{const oe=kt();oe&&I.fit(oe,ee,Q)})};return{zoom:Ie,pan:ke,setEdgesVisible:Te,focusNode:(ee,Q,ge,oe)=>we(()=>de(new Set([ee]),Q,ge,.6,oe)),focusBranch:(ee,Q,ge)=>we(()=>de(z(ee),Q,ge)),focusConnections:(ee,Q,ge,oe)=>we(()=>de(Ee(ee),Q,ge,1,oe)),isolateConnections:(ee,Q,ge)=>Pe(ee,"connections",Q,ge),isolateBranch:(ee,Q,ge)=>Pe(ee,"branch",Q,ge),restoreView:(ee=R.current.animateViewport,Q)=>{Je.current=null;const ge=R.current.compactPropertyLayout&&!!lt.current;lt.current=null,S(null);const oe=Q??Ut.current;Ut.current=null,ge?tt.current=()=>{oe&&I.transition(oe,ee)}:oe&&we(()=>I.transition(oe,ee))},zoomAt:(ee,Q)=>{var ge,oe,We;ee<I.zoom&&((ge=Ge.current)!=null&&ge.options.fill)&&!R.current.readOnly&&((We=(oe=R.current).onNodeGridZoomOut)==null?void 0:We.call(oe,Ge.current.options))===!0||(Je.current=null,I.zoomAt(ee,Q))},fit:Ke,centerAndFit:Ke,center:(ee=R.current.animateViewport)=>{Je.current=null;const Q=kt();Q&&I.center(Q,ee)},clientToModel:(ee,Q)=>I.renderedToModel(Oe(ee,Q)),modelToClient:ee=>{var oe;const Q=(oe=M.current)==null?void 0:oe.getBoundingClientRect(),ge=I.modelToRendered(ee);return{x:ge.x+((Q==null?void 0:Q.left)??0),y:ge.y+((Q==null?void 0:Q.top)??0)}},getNodeBox:ee=>Se(ee),detectNodeCollisions:ee=>{const Q=q();return Gv({...Q,sizes:new Map([...Q.sizes,...ye.current]),fixedSizes:ye.current},ee)},resolveNodeCollisions:(ee={})=>{const Q=jj(q(),ee);return Q.movedNodeIds.length&&J(Q.positions,ee.animate),Q},arrangeNodesInGrid:(ee={})=>{const Q=q(),ge=Ge.current;if(ge){Q.positions=new Map(Q.positions);for(const ze of Q.nodes)Q.positions.has(ze.id)||Q.positions.set(ze.id,I.renderedToModel({x:I.size.w/2,y:I.size.h/2}));const Re=new Set(Q.nodes.map(ze=>ze.id));ge.order=ge.order.filter(ze=>Re.has(ze));const je=new Set(ge.order);ge.order.push(...Q.nodes.filter(ze=>!je.has(ze.id)).map(ze=>ze.id));const ot=new Map(ge.order.map((ze,pt)=>[ze,pt]));Q.nodes=[...Q.nodes].sort((ze,pt)=>ot.get(ze.id)-ot.get(pt.id))}const oe=ad(Q,k(ee));zt(oe.dividers??[]),ge&&(ge.ready=!1);const We=()=>{ge&&(ge.ready=!0),ge&&Q.nodes.length&&!ae.current&&(ae.current=!0,R.current.fitOnInit!==!1&&!ee.fill?mt.centerAndFit(50,!1):R.current.fitOnInit===!1&&I.transition(p,!1)),fe(Re=>Re+1)};return!oe.sizes&&ye.current.size&&pe(),Q.nodes.some(Re=>!ue.current.has(Re.id))||oe.movedNodeIds.length||oe.bounds||Je.current?J(oe.positions,ee.animate,We,oe.bounds&&(!ge||!ye.current.size)?()=>I.transition({zoom:1,pan:{x:0,y:0}},!1):void 0,oe.sizes,!!ge&&!oe.bounds):We(),oe},setNodeGridMode:(ee,Q={})=>{var ge,oe,We,Re;if(Q.order&&(!Array.isArray(Q.order)||Q.order.some(je=>typeof je!="string")||new Set(Q.order).size!==Q.order.length))throw new Error("Invalid grid node order.");if(ee){ad(q(),k(Q));const je=!Ge.current||Ge.current.options.fill&&!Q.fill;Je.current=null,Ge.current||(Ge.current={options:Q,order:q().nodes.map(ot=>ot.id),previousPositions:new Map([...ue.current].map(([ot,ze])=>[ot,{...ze}])),previousViewport:{zoom:I.zoom,pan:{...I.pan}},previousSize:{...I.size},ready:!1}),je&&mt.centerAndFit(80,Q.animate,!0),Q.order&&(Ge.current.order=[...Q.order]),Ge.current.options={...Q},st(!0),mt.arrangeNodesInGrid(Q),(oe=(ge=R.current).onNodeGridModeChange)==null||oe.call(ge,{...Q,order:[...Ge.current.order]})}else{const je=Ge.current;if(!je)return;if(I.size.w===je.previousSize.w&&I.size.h===je.previousSize.h&&ue.current.size===je.previousPositions.size&&[...ue.current.keys()].every(pt=>je.previousPositions.has(pt))?Je.current=()=>I.transition(je.previousViewport,Q.animate!==!1&&!R.current.disableAnimations&&!R.current.isPerformanceMode):mt.centerAndFit(80,Q.animate,!0),Ge.current=null,st(!1),pe(),(Re=(We=R.current).onNodeGridModeChange)==null||Re.call(We,null),Wt(null),!je.previousPositions.size){re();return}const ze=new Map([...ue.current].map(([pt,or])=>[pt,je.previousPositions.get(pt)??or]));J(ze,Q.animate,void 0,void 0,void 0,!0)}},swapGridNodes:(ee,Q,ge)=>{var Rt,on,an,Un,sn;const oe=Ge.current;if(!oe||!oe.ready||R.current.readOnly||ee===Q)return!1;const We=q(),Re=We.nodes.find(cn=>cn.id===ee),je=We.nodes.find(cn=>cn.id===Q);if(!Re||!je||Re.parent!==je.parent)return!1;const ot=ad(We,k(oe.options));if(ot.skippedNodeIds.includes(ee)||ot.skippedNodeIds.includes(Q))return!1;const ze=oe.order.indexOf(ee),pt=oe.order.indexOf(Q);if(ze<0||pt<0)return!1;[oe.order[ze],oe.order[pt]]=[oe.order[pt],oe.order[ze]],Je.current=null,oe.options={...oe.options,order:[...oe.order]};const or=Re.parent??"canvas",ir=(on=(Rt=oe.options.adjustment)==null?void 0:Rt.sections)==null?void 0:on[or];return ir!=null&&ir.members&&(oe.options={...oe.options,adjustment:{...oe.options.adjustment,sections:{...(an=oe.options.adjustment)==null?void 0:an.sections,[or]:{...ir,members:ir.members.map(cn=>cn.map(qo=>qo===ee?Q:qo===Q?ee:qo))}}}}),mt.arrangeNodesInGrid({...oe.options,animate:ge??oe.options.animate}),(sn=(Un=R.current).onNodeGridModeChange)==null||sn.call(Un,{...oe.options}),!0},setNodePosition:(ee,Q,ge)=>{if(!ue.current.has(ee)||Q&&(!Number.isFinite(Q.x)||!Number.isFinite(Q.y)))return!1;if(Yt(),!Q)return X.current.delete(ee),re(),!0;const oe=new Map(ue.current);return oe.set(ee,{...Q}),(ge==null?void 0:ge.persist)===!1?X.current.delete(ee):X.current.set(ee,{...Q}),ue.current=oe,ce(oe),(ge==null?void 0:ge.persist)===!1&&re(),!0},onViewportChange:ee=>I.onChange(ee)}},[]);_.useEffect(()=>{var k,q;return(q=(k=R.current).onInit)==null||q.call(k,mt),()=>I.cancelAnimation()},[mt]),_.useEffect(()=>{var k,q;if(H>0){const z=tt.current;tt.current=null,z==null||z(),(q=(k=R.current).onLayoutComplete)==null||q.call(k,mt)}},[mt,H]);const ft=_.useRef(null),vt=_.useRef(new Map),Tt=_.useRef(!1),[vr,Vn]=_.useState(null),[it,rn]=_.useState(null),Gn=k=>{const q=M.current.getBoundingClientRect();return{x:(k.clientX-q.left)*(M.current.clientWidth/q.width||1),y:(k.clientY-q.top)*(M.current.clientHeight/q.height||1)}},Wn=(k,q)=>{const z=R.current.nodes;for(let J=z.length-1;J>=0;J--){const de=z[J].id;if(!Qt(de,R.current.edges,R.current.edgeMode)||lt.current&&!lt.current.has(de)||de===q||he.current.has(de))continue;const Pe=Se(de);if(Pe&&zu(k,Kt(Pe)))return de}for(const[J,de]of he.current)if(Qt(J,R.current.edges,R.current.edgeMode)&&!(lt.current&&!lt.current.has(J))&&J!==q&&zu(k,de))return J;return null},lu=(k,q)=>{const z=R.current.nodes.find(Ee=>Ee.id===k),J=Se(k);if(!z||!J)return null;const de=Kt({...J,x:J.x+q.x,y:J.y+q.y});let Pe=null,we=0;for(const Ee of R.current.nodes){if(Ee.id===k||Ee.parent!==z.parent||X.current.has(Ee.id)||he.current.has(Ee.id)||!Qt(Ee.id,R.current.edges,R.current.edgeMode)||lt.current&&!lt.current.has(Ee.id))continue;const Ie=Se(Ee.id);if(!Ie)continue;const ke=Kt(Ie),Oe=Math.max(0,Math.min(de.x2,ke.x2)-Math.max(de.x1,ke.x1))*Math.max(0,Math.min(de.y2,ke.y2)-Math.max(de.y1,ke.y1));Oe>we&&(we=Oe,Pe=Ee.id)}return Pe},du=(k,q)=>{const z=Ge.current;if(!(z!=null&&z.ready)||R.current.readOnly)return;const J=R.current.nodes.filter(Oe=>Qt(Oe.id,R.current.edges,R.current.edgeMode)&&(!lt.current||lt.current.has(Oe.id))),de=J.find(Oe=>Oe.id===k);if(!de)return;const Pe=M.current,we=I.zoom*(Pe&&Pe.clientWidth?Pe.getBoundingClientRect().width/Pe.clientWidth:1),Ee=24/we;let Ie;for(const Oe of J){if(Oe.id===k||Oe.parent!==de.parent)continue;const Ke=Se(Oe.id);if(!Ke)continue;const ee=Kt(Ke),Q=Math.min(Ke.w/4,Ee),ge=Math.min(Ke.h/4,Ee),oe=3/we,We=[];if(q.y>ee.y1+ge&&q.y<ee.y2-ge)for(const Re of["before","after"]){const je=Re==="before"?ee.x1:ee.x2,ot=Math.abs(q.x-je),ze=Re==="before"?q.x<je:q.x>je;ot<=(ze?Ee:Q)&&We.push({side:Re,distance:ot,marker:{x1:je-oe/2,x2:je+oe/2,y1:ee.y1,y2:ee.y2}})}if(q.x>=ee.x1&&q.x<=ee.x2)for(const Re of["above","below"]){const je=Re==="above"?ee.y1:ee.y2,ot=Math.abs(q.y-je),ze=Re==="above"?q.y<je:q.y>je;ot<=(ze?Ee:ge)&&We.push({side:Re,distance:ot,marker:{x1:ee.x1,x2:ee.x2,y1:je-oe/2,y2:je+oe/2}})}for(const Re of We)(!Ie||Re.distance<Ie.distance)&&(Ie={id:Oe.id,...Re})}if(!Ie)return;const ke=Cj({nodes:J,positions:ue.current,sizes:new Map([...K.current,...ye.current]),fixedSizes:ye.current,padding:Oe=>R.current.containerStyle(Oe).padding,minSize:ne,fixedIds:new Set(X.current.keys())},z.options,k,Ie.id,Ie.side);return ke?{options:ke,marker:Ie.marker}:void 0},Mo=(k,q)=>{if(R.current.edgeMode==="nodes"||R.current.edgeMode==="workflow")return null;const z=R.current.direction==="RL",J=Math.max(16,6/I.zoom);let de=null;for(const Pe of[...R.current.nodes].reverse()){if(!Qt(Pe.id,R.current.edges,R.current.edgeMode)||lt.current&&!lt.current.has(Pe.id))continue;const we=Se(Pe.id),Ee=B.current.get(Pe.id);if(!we||!Ee||he.current.has(Pe.id))continue;const Ie=we.x+(q==="source"!==z?1:-1)*we.w/2;for(const ke of Ee){if(ke.role&&ke.role!==q)continue;const Oe=we.y-we.h/2+ke.top,Ke=Math.hypot(k.x-(ke.anchor?we.x-we.w/2+ke.anchor.x:Ie),k.y-Oe-ke.height/2);if(!ke.anchor&&k.x>=we.x-we.w/2&&k.x<=we.x+we.w/2&&k.y>=Oe&&k.y<=Oe+ke.height)return{nodeId:Pe.id,property:ke.property};Ke<=J&&(!de||Ke<de.distance)&&(de={nodeId:Pe.id,property:ke.property,distance:Ke})}}return de},ex=k=>{var Ee,Ie;if(!k.currentTarget.contains(k.target)||(ft.current||(Tt.current=!1),k.target.closest(".flow-sdk-canvas")!==k.currentTarget)||k.button!==0||R.current.readOnly)return;const q=k.target;if(q.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const z=R.current,J=Gn(k);if(k.pointerType==="touch"){vt.current.set(k.pointerId,J);const ke=bm(vt.current);if(ke){Wt(null),ft.current={kind:"pinch",distance:ke.distance,zoom:I.zoom,anchor:I.renderedToModel(ke.center)},rn(null),Vn(null),Tt.current=!0;for(const Oe of vt.current.keys())k.currentTarget.setPointerCapture(Oe);return}}if(ft.current)return;const de=!Ge.current||!!z.nodeGridConnections,Pe=z.drawHandles&&q.closest(".flow-sdk-handle"),we=z.drawHandles&&q.closest(".flow-sdk-property-port");if((!de||!Pe&&!we&&(!z.drawMode||k.shiftKey))&&(Ge.current||k.shiftKey&&(z.onNodeGridDrop||z.onNodeParentChange))){if(Ge.current&&!Ge.current.ready||q.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]"))return;const ke=(Ee=q.closest("[data-node-id]"))==null?void 0:Ee.dataset.nodeId;if(ke&&!X.current.has(ke)){q.setPointerCapture(k.pointerId),ft.current={kind:"grid",pointerId:k.pointerId,captureTarget:q,source:ke,start:J,moved:!1};return}if(ke)return}if(de&&(z.drawMode||Pe||we)){const ke=I.renderedToModel(J),Oe=z.drawMode?Mo(ke,"source"):null,Ke=we||Pe,ee=Ke?(Ie=Ke.closest("[data-node-id]"))==null?void 0:Ie.dataset.nodeId:(Oe==null?void 0:Oe.nodeId)??Wn(ke),Q=we?we.dataset.property:Oe==null?void 0:Oe.property;if(ee){ft.current={kind:"draw",pointerId:k.pointerId,source:ee,sourceProperty:Q,reverse:(we==null?void 0:we.dataset.portRole)==="target",startClient:{x:k.clientX,y:k.clientY}},Tt.current=!0,rn({source:ee,sourceProperty:Q,point:ke,target:null}),k.currentTarget.setPointerCapture(k.pointerId);return}}q.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(Je.current=null,z.multiSelect?ft.current={kind:"box",pointerId:k.pointerId,start:J,current:J}:z.dragMode?ft.current={kind:"pan",pointerId:k.pointerId,start:J,pan0:I.pan,moved:!1}:ft.current={kind:"tap",pointerId:k.pointerId,start:J,moved:!1},k.currentTarget.setPointerCapture(k.pointerId))},tx=k=>{var J,de,Pe;const q=ft.current;if(!q||R.current.readOnly)return;const z=Gn(k);if(vt.current.has(k.pointerId)&&vt.current.set(k.pointerId,z),q.kind==="pinch"){const we=bm(vt.current);if(!we)return;const Ee=Math.max(I.minZoom,Math.min(I.maxZoom,q.zoom*we.distance/q.distance));if(Ee<I.zoom&&((J=Ge.current)!=null&&J.options.fill)&&((Pe=(de=R.current).onNodeGridZoomOut)==null?void 0:Pe.call(de,Ge.current.options))===!0)return;I.set({x:we.center.x-q.anchor.x*Ee,y:we.center.y-q.anchor.y*Ee},Ee);return}if(q.pointerId===k.pointerId)switch(q.kind){case"grid":{const we={x:z.x-q.start.x,y:z.y-q.start.y};if(!q.moved&&Math.hypot(we.x,we.y)<=sd)return;q.moved||(Yt(),Je.current=null,I.cancelAnimation()),q.moved=!0,Tt.current=!0,k.preventDefault();const Ee={x:we.x/I.zoom,y:we.y/I.zoom},Ie=!k.shiftKey&&z.x>=0&&z.y>=0&&z.x<=I.size.w&&z.y<=I.size.h?du(q.source,I.renderedToModel(z)):void 0;Wt({source:q.source,offset:Ee,target:k.shiftKey||Ie?null:lu(q.source,Ee),shiftKey:k.shiftKey,insertion:Ie});break}case"pan":{const we=z.x-q.start.x,Ee=z.y-q.start.y;if(!q.moved&&Math.hypot(we,Ee)<=sd)return;q.moved=!0,Tt.current=!0,I.set({x:q.pan0.x+we,y:q.pan0.y+Ee});break}case"tap":{Math.hypot(z.x-q.start.x,z.y-q.start.y)>sd&&(q.moved=!0);break}case"box":{Tt.current=!0,q.current=z,Vn({x1:Math.min(q.start.x,z.x),y1:Math.min(q.start.y,z.y),x2:Math.max(q.start.x,z.x),y2:Math.max(q.start.y,z.y)});break}case"draw":{const we=I.renderedToModel(z),Ee=Mo(we,q.reverse?"source":"target");rn(q.reverse&&Ee?{source:Ee.nodeId,sourceProperty:Ee.property,point:we,target:q.source,targetProperty:q.sourceProperty}:{source:q.source,sourceProperty:q.sourceProperty,point:we,target:(Ee==null?void 0:Ee.nodeId)??Wn(we,q.source),targetProperty:Ee==null?void 0:Ee.property});break}}},uu=(k,q)=>{var de,Pe,we,Ee,Ie,ke,Oe,Ke,ee,Q,ge;vt.current.delete(k.pointerId);const z=ft.current;if(!z)return;if(z.kind==="pinch"){const oe=[...vt.current][0];ft.current=oe&&R.current.dragMode&&!q?{kind:"pan",pointerId:oe[0],start:oe[1],pan0:I.pan,moved:!0}:null;return}if(z.pointerId!==k.pointerId)return;ft.current=null;try{(z.kind==="grid"?z.captureTarget:k.currentTarget).releasePointerCapture(k.pointerId)}catch{}const J=R.current;switch(q=q||!!J.readOnly,z.kind){case"grid":{if(Wt(null),q||!z.moved)break;const oe=Gn(k);if(!k.shiftKey&&oe.x>=0&&oe.y>=0&&oe.x<=I.size.w&&oe.y<=I.size.h){const Re=du(z.source,I.renderedToModel(oe));if(Re){mt.setNodeGridMode(!0,{...Re.options,animate:!1});break}}if(((de=J.onNodeGridDrop)==null?void 0:de.call(J,z.source,{x:k.clientX,y:k.clientY},{shiftKey:k.shiftKey,ctrlKey:k.ctrlKey,metaKey:k.metaKey,altKey:k.altKey}))===!0||oe.x<0||oe.y<0||oe.x>I.size.w||oe.y>I.size.h)break;if(k.shiftKey){const Re=new Map(J.nodes.map(ze=>[ze.id,ze]));let je=Wn(I.renderedToModel(oe),z.source);const ot=new Set;for(;je&&!((Pe=Re.get(je))!=null&&Pe.acceptsChildren)&&!ot.has(je);)ot.add(je),je=((we=Re.get(je))==null?void 0:we.parent)??null;if(je&&((Ee=Re.get(je))!=null&&Ee.acceptsChildren)){let ze=je;const pt=new Set;for(;ze&&!pt.has(ze);)pt.add(ze),ze=(Ie=Re.get(ze))==null?void 0:Ie.parent;pt.has(z.source)||(ke=J.onNodeParentChange)==null||ke.call(J,z.source,je)}break}if(!Ge.current)break;const We=lu(z.source,{x:(oe.x-z.start.x)/I.zoom,y:(oe.y-z.start.y)/I.zoom});We&&mt.swapGridNodes(z.source,We,!1);break}case"pan":case"tap":!q&&!z.moved&&((Oe=J.onBackgroundTap)==null||Oe.call(J));break;case"box":{if(Vn(null),q)break;const oe=I.renderedToModel(z.start),We=I.renderedToModel(z.current),Re={x1:Math.min(oe.x,We.x),y1:Math.min(oe.y,We.y),x2:Math.max(oe.x,We.x),y2:Math.max(oe.y,We.y)};if(Re.x2-Re.x1<1&&Re.y2-Re.y1<1){(Ke=J.onBackgroundTap)==null||Ke.call(J);break}const je=[];for(const ot of J.nodes){const ze=Se(ot.id);ze&&Lw(Kt(ze),Re)&&je.push(ot.id)}je.length&&((ee=J.onBoxSelect)==null||ee.call(J,je));break}case"draw":{if(rn(null),q)break;const oe=Gn(k),We=I.renderedToModel(oe),Re=Mo(We,z.reverse?"source":"target"),je=(Re==null?void 0:Re.nodeId)??Wn(We);if(je===z.source&&(z.sourceProperty===void 0||(Re==null?void 0:Re.property)===void 0||Re.property===z.sourceProperty))break;je?(Q=J.onEdgeDraw)==null||Q.call(J,z.reverse?je:z.source,z.reverse?z.source:je,z.sourceProperty!==void 0||(Re==null?void 0:Re.property)!==void 0?{sourceProperty:z.reverse?Re==null?void 0:Re.property:z.sourceProperty,targetProperty:z.reverse?z.sourceProperty:Re==null?void 0:Re.property}:void 0):Math.max(Math.abs(k.clientX-z.startClient.x),Math.abs(k.clientY-z.startClient.y))>Tj&&((ge=J.onDrawIntoSpace)==null||ge.call(J,z.source,We,z.sourceProperty,z.reverse));break}}},xr=_.useCallback(()=>{var z;const k=ft.current,q=[...vt.current.keys()];k&&k.kind!=="pinch"&&q.push(k.pointerId),ft.current=null,vt.current.clear(),Wt(null),rn(null),Vn(null);for(const J of q)(k==null?void 0:k.kind)==="grid"&&k.captureTarget.hasPointerCapture(J)&&k.captureTarget.releasePointerCapture(J),(z=M.current)!=null&&z.hasPointerCapture(J)&&M.current.releasePointerCapture(J)},[]);_.useEffect(()=>{const k=q=>{q.key==="Escape"&&xr()};return window.addEventListener("keydown",k),window.addEventListener("blur",xr),()=>{window.removeEventListener("keydown",k),window.removeEventListener("blur",xr),ft.current=null,vt.current.clear()}},[xr]),_.useEffect(()=>{xr()},[g,v,b,i,n,e.drawHandles,e.readOnly,Ve,xr]);const rx=_.useMemo(()=>{const k=new Map,q=new Map;for(const z of E){if(z.source!==z.target)continue;const J=k.get(z.source)??0;k.set(z.source,J+1),q.set(z.id,J)}return q},[E]),To=Mj[n],[Oo,nx]=_.useState(null),No=Pj(r,E,!!((yu=e.edgeReveal)!=null&&yu.revealNodes));_.useLayoutEffect(()=>{M.current&&Oo&&Ej(M.current)});const $o=$w(E,He,To),ox=e.onEdgeSelect,ix=e.onContainerSelect,fu=it?it.target&&He(it.target,it.targetProperty)||{x:it.point.x,y:it.point.y,w:1,h:1}:null,hu=it?He(it.source,it.sourceProperty):null,nn=!Ve||!!e.nodeGridConnections,ax=["flow-sdk-canvas",g&&nn?"flow-sdk-draw":"",x?"flow-sdk-perf":""].filter(Boolean).join(" ");return f.jsxs("div",{ref:M,className:ax,"data-edge-mode":i,"data-node-grid":Ve||void 0,"data-grid-connections":e.nodeGridConnections||void 0,onPointerDownCapture:ex,onPointerMove:tx,onPointerUp:k=>uu(k,!1),onPointerCancel:k=>uu(k,!0),onLostPointerCapture:k=>{const q=ft.current;q&&(q.kind==="pinch"||q.pointerId===k.pointerId)&&xr()},onClickCapture:k=>{if(!k.currentTarget.contains(k.target))return;const q=k.target instanceof Element&&k.target.closest("button[data-flow-fullscreen]");(Tt.current||e.readOnly&&!q)&&(k.preventDefault(),k.stopPropagation())},children:[f.jsx("svg",{className:"flow-sdk-svg",children:f.jsxs("g",{ref:T,children:[f.jsx("g",{className:"flow-sdk-containers",children:[...U].filter(([k])=>Qt(k,t,i)).filter(([k])=>!j||j.has(k)).map(([k,q])=>{var z,J;return f.jsx(Jw,{id:k,rect:q,label:$e.get(k),labelLayer:Oo,labelContent:(z=r.find(de=>de.id===k&&de.label!==void 0))==null?void 0:z.element,style:m(k),onSelect:ix,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(J=e.selectedNodeIds)==null?void 0:J.includes(k)},k)})}),f.jsx("g",{className:"flow-sdk-edges",children:ht&&nn&&E.map(k=>{var J,de,Pe;if(!No.ready.has(k.id)||j&&(!j.has(k.source)||!j.has(k.target)))return null;const q=He(k.source,k.sourceProperty),z=He(k.target,k.targetProperty);return!q||!z?null:f.jsx(Hu,{id:k.id,edgeData:k.data,validationIssue:k.validationIssue,edgeType:k.type,edgeRadius:e.edgeRadius,propertyMode:P,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:No.complete,source:q,target:z,sourceProperty:k.sourceProperty,targetProperty:k.targetProperty,sourceY:Xe(k.source,k.sourceProperty),targetY:Xe(k.target,k.targetProperty),sourcePort:Qe(k.source,k.sourceProperty),targetPort:Qe(k.target,k.targetProperty),dir:To,turn:((J=$o.get(k.id))==null?void 0:J.turn)??k.turn,labelAtTarget:(de=$o.get(k.id))==null?void 0:de.labelAtTarget,labelFraction:(Pe=$o.get(k.id))==null?void 0:Pe.labelFraction,color:k.color,connectorColor:k.connectorColor,labelBg:k.labelBg,label:k.label,labelLayer:Oo,dashed:k.dashed,animated:k.animated&&!x,inverted:k.inverted,loopIndex:rx.get(k.id)??0,onSelect:ox},k.id)})}),ht&&nn&&it&&gd(it,i)&&hu&&fu&&f.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:f.jsx(Hu,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:it.source,target:it.target??"",sourceProperty:it.sourceProperty,targetProperty:it.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:P,customEdgeTypes:e.customEdgeTypes,source:hu,target:fu,sourceProperty:it.sourceProperty,targetProperty:it.targetProperty,sourceY:Xe(it.source,it.sourceProperty),sourcePort:Qe(it.source,it.sourceProperty),targetPort:it.target?Qe(it.target,it.targetProperty):void 0,targetY:it.target?Xe(it.target,it.targetProperty):void 0,dir:To,turn:.5,color:y,labelBg:y})})]})}),f.jsxs("div",{ref:$,className:"flow-sdk-nodes",children:[(De==null?void 0:De.insertion)&&f.jsx("div",{className:"flow-sdk-box","data-grid-insertion":"",style:{left:De.insertion.marker.x1,top:De.insertion.marker.y1,width:De.insertion.marker.x2-De.insertion.marker.x1,height:De.insertion.marker.y2-De.insertion.marker.y1,background:y,border:0}}),Ve&&((mu=Ge.current)==null?void 0:mu.options.fill)&&((bu=Ge.current.options.adjustment)==null?void 0:bu.enabled)&&!e.readOnly&&f.jsx(_j,{dividers:ct,options:Ge.current.options,zoom:I.zoom,onChange:k=>mt.setNodeGridMode(!0,{...k,animate:!1})}),r.map(k=>{var We,Re;const q=Y.get(k.id),z=U.get(k.id);if(z&&k.label!==void 0)return null;const J=(q==null?void 0:q.x)??(z?(z.x1+z.x2)/2:0),de=(q==null?void 0:q.y)??(z?(z.y1+z.y2)/2:0),Pe=De!=null&&De.target?k.id===De.source?De.target:k.id===De.target?De.source:void 0:void 0,we=Pe?Y.get(Pe):void 0,Ee=De?Y.get(De.source):void 0,Ie=De!=null&&De.target?Y.get(De.target):void 0,ke=Ee&&Ie?{x:Ie.x-Ee.x,y:Ie.y-Ee.y}:void 0,Oe=ke?ke.x**2+ke.y**2:0,Ke=Oe&&De&&ke?Math.max(0,Math.min(1,(De.offset.x*ke.x+De.offset.y*ke.y)/Oe)):0,ee=we?{x:J+(we.x-J)*Ke,y:de+(we.y-de)*Ke}:(De==null?void 0:De.source)===k.id?{x:J+De.offset.x,y:de+De.offset.y}:void 0,Q=xe.get(k.id),ge=Pe?xe.get(Pe):void 0,oe=Q&&ge?{w:Q.w+(ge.w-Q.w)*Ke,h:Q.h+(ge.h-Q.h)*Ke}:Q;return f.jsx(Aj,{id:k.id,x:J,y:de,gridDraggable:Ve&&!e.readOnly&&!X.current.has(k.id),gridDragging:(De==null?void 0:De.source)===k.id,gridDropTarget:(De==null?void 0:De.target)===k.id,gridSize:xe.get(k.id),gridPreview:ee?{...ee,size:oe,floating:De==null?void 0:De.shiftKey}:void 0,placed:!!q||!!z,hidden:!Ve&&!No.shown.has(k.id)||!Qt(k.id,t,i)||!!j&&!j.has(k.id),onMount:G,drawHandles:e.drawHandles&&!e.readOnly&&nn,drawMode:g&&nn,connectedPorts:new Set(E.flatMap(je=>[...je.source===k.id&&je.sourceProperty!==void 0?[`source:${je.sourceProperty}`]:[],...je.target===k.id&&je.targetProperty!==void 0?[`target:${je.targetProperty}`]:[]])),hasCollapseControl:k.hasCollapseControl,handleColor:y,animated:k.animated&&!z&&!x&&!Ve,animationColor:k.animationColor,animationWidth:k.animationWidth,animationVariant:k.animationVariant,width:(We=K.current.get(k.id))==null?void 0:We.w,height:(Re=K.current.get(k.id))==null?void 0:Re.h,propertyMode:P,resolvedRows:_e.get(k.id),reversePorts:n==="RL",direction:n,onPropertyRows:le,onSurface:F,children:Q?k.fillElement??k.element:k.element},k.id)})]}),vr&&f.jsx("div",{className:"flow-sdk-box",style:{left:vr.x1,top:vr.y1,width:vr.x2-vr.x1,height:vr.y2-vr.y1}}),f.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:f.jsx("g",{ref:N,transform:`translate(${I.pan.x} ${I.pan.y}) scale(${I.zoom})`,children:f.jsx("g",{ref:nx,className:"flow-sdk-labels",style:{pointerEvents:g?"none":"visiblePainted",outline:"none"}})})})]})}const qj=_.memo($j);function ou(e=!0){const r=_.useRef(null);return _.useEffect(()=>{if(!e||!r.current)return;const t=i=>{i.stopPropagation()},n=r.current,o=["mousedown","mouseup","click","dblclick","pointerdown","pointerup","wheel"];return o.forEach(i=>n.addEventListener(i,t)),()=>{o.forEach(i=>n.removeEventListener(i,t))}},[e]),r}const Hr=({nodeId:e,label:r,color:t,fontWeight:n="bold",fontSize:o="5xl",wrap:i=!1,isEditing:s,onEditStart:a,onEditEnd:c})=>{const{callbacks:l,config:d,readOnly:u}=Ze(),h=d.editable&&!u,[p,m]=_.useState(r),[y,g]=_.useState(),v=_.useRef(null),b=_.useRef(!1),x=ou(s);_.useEffect(()=>{if(s&&(b.current=!1,v.current)){v.current.focus();const C=v.current.value.length;v.current.setSelectionRange(C,C)}},[s]);const w=()=>{var S;if(b.current)return;b.current=!0;const C=p.trim();C&&C!==r&&((S=l.onNodeLabelChange)==null||S.call(l,e,C)),c()};return!h||!s?f.jsx(V.Text,{color:t,fontWeight:n,fontSize:o,minW:0,maxW:"100%",whiteSpace:i?"normal":"nowrap",overflowWrap:i?"anywhere":void 0,overflow:"hidden",textOverflow:"ellipsis",title:r,onDoubleClick:h?C=>{C.stopPropagation(),g({width:C.currentTarget.offsetWidth,height:C.currentTarget.offsetHeight}),m(r),a()}:void 0,cursor:h?"text":void 0,children:r}):f.jsxs("div",{ref:x,style:{position:"relative",width:"max-content",minWidth:y==null?void 0:y.width,maxWidth:900,height:y==null?void 0:y.height},children:[f.jsx(V.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),f.jsx(V.Input,{ref:v,value:p,onChange:C=>m(C.target.value),onBlur:w,onKeyDown:C=>{C.key==="Enter"&&w(),C.key==="Escape"&&(b.current=!0,c())},color:t,fontWeight:n,fontSize:o,bg:"transparent",borderWidth:0,_focus:{outline:"none",boxShadow:"none"},_focusVisible:{outline:"none",boxShadow:"none"},p:0,display:"block",position:"absolute",top:0,left:0,w:"100%",h:"100%",minW:0,minH:0,lineHeight:"normal"})]})};function Uv({id:e,label:r,role:t,side:n,position:o=.5,placement:i,children:s,style:a}){return f.jsx("div",{"data-flow-property":e,"data-flow-port-role":t,"data-flow-port-side":n,"data-flow-port-position":n?o:void 0,"data-flow-port-placement":i,style:{minHeight:32,display:"flex",alignItems:"center",justifyContent:t==="source"?"flex-end":"flex-start",...a,...n?{display:"none"}:{}},children:s??r??e})}const Lj=io.default.dialog`
|
|
211
|
-
${e=>
|
|
209
|
+
`;function Lu({request:e,property:r,config:t,value:n,disabled:o}){var ge,he,Y,H,ve;const{callbacks:i,structured:s,references:a}=j.useContext(Tt),{themeColor:c}=Je(),{background:l}=at(),d=j.useId(),u=r.type.kind==="object"||r.type.kind==="array"||r.type.kind==="json",h=n===void 0?"":u?JSON.stringify(n,null,2):String(n),[p,m]=j.useState(h),[y,g]=j.useState(""),[v,b]=j.useState(0),x=j.useRef(null),w=j.useRef(),[C,S]=j.useState(!1),[_,I]=j.useState(!1),[E,O]=j.useState(),A=((ge=t.$options)==null?void 0:ge.$source)==="callback",R=i.resolveFormOptions,{data:P,address:T,nodeAddress:N,nodeId:$}=e;j.useEffect(()=>(S(!1),I(!1),()=>{var J;(J=w.current)==null||J.abort(),w.current=void 0}),[T,N,$,o,h,t.$control,(he=t.$upload)==null?void 0:he.accept,(Y=t.$upload)==null?void 0:Y.maxSizeBytes]);const M=j.useRef(P);M.current=P;const W=JSON.stringify([T,$,(H=t.$options)!=null&&H.$dependsOn?t.$options.$dependsOn.map(J=>Fe(P,J)):Fe(P,N)]);j.useEffect(()=>{m(h),g("")},[h,T,$]),j.useEffect(()=>{if(!A)return;const J=new AbortController;return Promise.resolve().then(()=>{if(!R)throw new Error("No options resolver configured");return R({address:T,nodeAddress:N,nodeId:$,data:Ur(M.current),signal:J.signal})}).then(be=>{if(!Array.isArray(be)||be.some(Q=>!Q||typeof Q.label!="string"||!["string","number","boolean"].includes(typeof Q.value)&&Q.value!==null))throw new Error("Invalid options response");J.signal.aborted||O({key:W,options:be})}).catch(be=>{J.signal.aborted||O({key:W,options:[],error:be instanceof Error?be.message:"Options unavailable"})}),()=>J.abort()},[A,R,W,T,N,$,v]);const ae=A&&(E==null?void 0:E.key)!==W,se=A?(E==null?void 0:E.key)===W?E.options:[]:r.type.kind==="null"?[{label:"Null",value:null}]:r.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:jn(r.type),re=r.type.kind==="array",ye=(t.$control==="upload"?"upload":s&&u||t.$control==="checkbox"?"pills":t.$control)??(se?re||r.type.kind==="boolean"?"pills":"select":r.type.kind==="boolean"?"checkbox":u?"textarea":"input"),me=!r.optional||!!t.$requiredWhen&&fo(t.$requiredWhen,P),L=me?"Required":"Optional",z=ye!=="upload"&&!!(a!=null&&a.length)&&typeof n=="string"&&n.includes("{{"),U=y||A&&(E==null?void 0:E.key)===W&&E.error||!z&&Vt(r.type,n,me),B=qt(t.$label??T.split(".").pop()),ce=J=>{var be;if(!(o||Object.is(J,n)))try{(be=i.onFormChange)==null||be.call(i,{...e,previousValue:n,value:J}),g("")}catch(Q){g(Q instanceof Error?Q.message:"Unable to update field")}},X=j.useRef(ce);j.useLayoutEffect(()=>{X.current=ce});const le=()=>{if(u){try{const je=p===""&&r.optional?void 0:JSON.parse(p),Pe=Vt(r.type,je,me);if(Pe){g(Pe);return}ce(je)}catch{g("Enter valid JSON")}return}const J=r.type.kind==="number"||r.type.kind==="integer",be=p===""&&r.optional?void 0:J&&p!==""?Number(p):p,Q=Vt(r.type,be,me);if(J&&Q&&p!==""){g(Q);return}ce(be)},ue=async J=>{var Q,je,Pe;if(o||w.current||!J.length)return;const be=new AbortController;w.current=be,g(""),S(!0);try{if(r.type.kind!=="string"&&!(r.type.kind==="array"&&r.type.items.kind==="string"))throw new Error("Uploads require a string or string-array field.");if(!re&&J.length!==1)throw new Error("Choose one file for this field.");if(!i.uploadFormFile)throw new Error("No file upload handler configured.");const qe=(je=(Q=t.$upload)==null?void 0:Q.accept)==null?void 0:je.split(",").map(De=>De.trim().toLowerCase()).filter(Boolean);for(const De of J){if(((Pe=t.$upload)==null?void 0:Pe.maxSizeBytes)!==void 0&&De.size>t.$upload.maxSizeBytes)throw new Error(`${De.name} exceeds the file size limit.`);if(qe!=null&&qe.length&&!qe.some(rt=>rt.startsWith(".")?De.name.toLowerCase().endsWith(rt):rt.endsWith("/*")?De.type.toLowerCase().startsWith(rt.slice(0,-1)):De.type.toLowerCase()===rt))throw new Error(`${De.name} is not an accepted file type.`)}const Xe=await Promise.all(J.map(async De=>{const rt=await i.uploadFormFile({...e,data:Ur(P),file:De,signal:be.signal});if(typeof rt!="string")throw new Error("Upload handler must return an HTTP or HTTPS URL.");let pt;try{pt=new URL(rt)}catch{throw new Error("Upload handler must return an HTTP or HTTPS URL.")}if(!["http:","https:"].includes(pt.protocol)||pt.username||pt.password)throw new Error("Upload handler must return an HTTP or HTTPS URL.");return rt}));if(be.signal.aborted||w.current!==be)return;const Be=re?[...Array.isArray(n)?n:[],...Xe]:Xe[0],ut=Vt(r.type,Be,me);if(ut)throw new Error(ut);X.current(Be)}catch(qe){be.signal.aborted||g(qe instanceof Error?qe.message:"Unable to upload file."),be.abort()}finally{w.current===be&&(w.current=void 0,S(!1))}},xe={id:d,disabled:o,"aria-label":B,"aria-required":me,"aria-invalid":!!U,"aria-describedby":U?`${d}-error`:void 0},Ce=Me(c);return f.jsxs("div",{"data-form-field":T,"data-flow-property":T.slice(N.length+1),children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[f.jsxs("label",{htmlFor:d,children:[B,me?" *":""]}),r.optional&&n!==void 0&&f.jsx("button",{type:"button","aria-label":`Reset ${B}`,title:`Reset ${B}`,disabled:o||C,style:{width:24,height:24,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:0,background:"transparent",color:"inherit"},onClick:()=>ce(void 0),children:f.jsx(Z.PiArrowCounterClockwise,{size:14})})]}),!!(a!=null&&a.length)&&!u&&ye!=="upload"&&f.jsx(Ew,{label:B,value:n,references:a,disabled:o,onChange:ce}),ye==="upload"?f.jsxs("div",{"data-form-upload":re?"multiple":"single","aria-busy":C,style:{"--flow-upload-surface":Me(l),outline:_?"2px dashed var(--flow-form-input-background)":void 0,borderRadius:"var(--flow-form-input-radius)"},onDragOver:J=>{J.preventDefault(),J.stopPropagation(),!o&&!C&&(J.dataTransfer.dropEffect="copy",I(!0))},onDragLeave:J=>{J.currentTarget.contains(J.relatedTarget)||I(!1)},onDrop:J=>{J.preventDefault(),J.stopPropagation(),I(!1),ue(Array.from(J.dataTransfer.files))},children:[f.jsx("input",{ref:x,type:"file",hidden:!0,"aria-label":`Upload ${B}`,accept:(ve=t.$upload)==null?void 0:ve.accept,multiple:re,disabled:o||C,onChange:J=>{const be=Array.from(J.target.files??[]);J.target.value="",ue(be)}}),f.jsxs("div",{"data-upload-items":"",children:[(re?Array.isArray(n)?n:[]:n?[n]:[]).map((J,be)=>f.jsxs("div",{"data-upload-preview":"",children:[typeof J=="string"&&sr(J)&&f.jsxs("a",{href:J,target:"_blank",rel:"noopener noreferrer","aria-label":`${B} file ${be+1}`,children:[f.jsx(Z.PiFile,{size:32,"aria-hidden":"true"}),f.jsx(Yt,{name:J,size:120,onError:Q=>{Q.currentTarget.style.visibility="hidden"}})]}),f.jsxs("div",{"data-upload-actions":"",children:[!re&&f.jsx(Oe,{"aria-label":`Replace ${B}`,title:`Replace ${B}`,icon:f.jsx(Z.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>{var Q;return(Q=x.current)==null?void 0:Q.click()}}),f.jsx(Oe,{"aria-label":`Remove ${B} file ${be+1}`,title:"Remove file",icon:f.jsx(Z.PiTrash,{}),size:"xs",variant:"ghost",disabled:o||C,onClick:()=>ce(re&&Array.isArray(n)?n.filter((Q,je)=>je!==be):"")})]})]},`${be}:${J}`)),(re||!n)&&f.jsx("button",{...xe,type:"button","data-upload-drop":"",title:`Upload ${B}`,disabled:o||C,onClick:()=>{var J;return(J=x.current)==null?void 0:J.click()},children:f.jsx(Z.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&f.jsx("span",{role:"status",children:"Uploading..."})]}):z?null:ye==="select"?f.jsx("div",{"data-form-select":"",children:f.jsxs(Mt,{...xe,disabled:o||ae||!!(E!=null&&E.error),labelCase:"preserve",value:String((se==null?void 0:se.findIndex(J=>Object.is(J.value,n)))??-1),onValueChange:J=>{const be=se==null?void 0:se[Number(J)];be&&ce(be.value)},children:[f.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):L}),se==null?void 0:se.map((J,be)=>f.jsx("option",{value:be,children:qt(J.label)||J.label},be))]})}):ye==="pills"?f.jsxs("div",{id:d,role:"group","aria-label":B,"aria-describedby":xe["aria-describedby"],style:{display:"flex",flexWrap:"wrap",gap:8},children:[se==null?void 0:se.map((J,be)=>{const Q=re?Array.isArray(n)&&n.includes(J.value):Object.is(n,J.value);return f.jsx("button",{type:"button",disabled:o||ae,"aria-pressed":Q,style:{padding:"8px 16px",borderRadius:24,border:0,color:Q?Ce:"inherit",background:Q?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>ce(re?Q?n.filter(je=>je!==J.value):[...Array.isArray(n)?n:[],J.value]:J.value),children:qt(J.label)||J.label},be)}),ae&&f.jsx("span",{role:"status",children:"Loading..."})]}):ye==="textarea"?f.jsx("textarea",{...xe,placeholder:L,value:p,onChange:J=>m(J.target.value),onBlur:le}):f.jsx("input",{...xe,placeholder:L,type:r.type.kind==="number"||r.type.kind==="integer"?"number":"text",step:r.type.kind==="integer"?1:"any",value:p,onChange:J=>m(J.target.value),onBlur:le,onKeyDown:J=>{J.key==="Enter"&&le(),J.key==="Escape"&&m(n===void 0?"":String(n))}}),U&&f.jsx("div",{role:"alert",id:`${d}-error`,children:U}),A&&(E==null?void 0:E.error)&&f.jsx("button",{type:"button",disabled:o,onClick:()=>{O(void 0),b(v+1)},children:"Retry"})]})}function Td({nodeAddress:e,structured:r=!1}){return r?f.jsx(Rw,{nodeAddress:e},e):f.jsx(hd,{nodeAddress:e})}function Rw({nodeAddress:e}){var u,h,p;const r=j.useContext(Tt),[t,n]=j.useState([]),o=((u=r.structured)==null?void 0:u.sourceSchema)??r.schema,i=((h=r.structured)==null?void 0:h.sourceBindings)??r.bindings,s=j.useMemo(()=>{if(!(!r.data||!o||!i))return pb(r.data,i,o,[{data:{id:e,type:"objectView"}}])},[r.data,i,o,e]);if(!s)return f.jsx(hd,{nodeAddress:e});const a=t.findIndex(m=>!s.containers.has(m)),c=a<0?t:t.slice(0,a),l=c.at(-1)??e,d=(p=[...s.slots.values()].find(m=>m.nodeId===l))==null?void 0:p.label;return f.jsxs(Tt.Provider,{value:{...r,structured:s,schema:s.schema,bindings:s.bindings,renderForm:void 0,onFieldCreate:l===e?r.onFieldCreate:void 0},children:[!!c.length&&f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[f.jsx(Oe,{"aria-label":"Back to parent fields",title:"Back to parent fields",icon:f.jsx(Z.PiArrowLeft,{size:18}),size:"sm",variant:"ghost",onClick:()=>n(c.slice(0,-1))}),f.jsx("strong",{style:{minWidth:0,overflowWrap:"anywhere"},children:qt(d)})]}),f.jsx(hd,{nodeAddress:l,onOpen:m=>n([...c,m])},l)]})}function hd({nodeAddress:e,onOpen:r}){var S,_;const{data:t,schema:n,callbacks:o,bindings:i,editable:s,renderForm:a,structured:c}=j.useContext(Tt),{readOnly:l,config:d,colorMode:u}=Je(),h=a==null?void 0:a(e);if(h!==void 0)return f.jsx("fieldset",{"data-flow-form":e,disabled:l||d.editable===!1||!s,style:{border:0,margin:0,padding:0,minWidth:0},children:h});if(!t)return f.jsx(Kn,{$colorMode:u,role:"alert",children:"Forms require a JSON document."});const p=i?Nn(i,e,n):void 0,m=i?p:n&&Yr(t,e,n);if(!m)return f.jsx(Kn,{$colorMode:u,role:"status",children:"Form schema unavailable."});const y=(p==null?void 0:p.address)??e,g=Fe(t,y),v=(S=c==null?void 0:c.containers.get(e))==null?void 0:S.scalar;if(g===void 0||typeof g!="object"&&!v)return f.jsx(Kn,{$colorMode:u,role:"alert",children:"Bound form state is unavailable."});const b=Object.entries(m.type.properties).filter(([I])=>{var E;return fo((E=m.fields[I])==null?void 0:E.$visibleWhen,t)}),x=b.length>8||b.some(([I])=>{var E;return(E=m.fields[I])==null?void 0:E.$section}),w=new Map;for(const I of b){const[E,O]=I,A=x?qt(((_=m.fields[E])==null?void 0:_.$section)??(O.type.kind==="object"||O.type.kind==="array"?E:O.optional?"Options":"General")):"";w.has(A)||w.set(A,[]),w.get(A).push(I)}const C=([I,E])=>f.jsx(Lu,{request:{data:t,address:v?y:`${y}.${I}`,nodeAddress:y,nodeId:typeof(g==null?void 0:g.id)=="string"?g.id:void 0},property:E,config:m.fields[I]??{},value:v?g:g==null?void 0:g[I],disabled:l||d.editable===!1||!(s??!!o.onJsonChange)},`${(g==null?void 0:g.id)??e}:${I}`);return f.jsxs(Kn,{$colorMode:u,"data-flow-form":e,onClick:I=>I.stopPropagation(),onDoubleClick:I=>I.stopPropagation(),children:[c&&f.jsx(kw,{nodeAddress:e,onOpen:r}),!c&&p&&m.type.additionalProperties&&b.length===0&&f.jsx(Lu,{request:{data:t,address:y,nodeAddress:y},property:{type:m.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:g,disabled:l||d.editable===!1||!s}),[...w].map(([I,E])=>x&&E.length>1?f.jsxs("details",{open:!0,children:[f.jsxs("summary",{children:[f.jsx("span",{children:I}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),E.map(C)]},I):E.map(C))]})}function yb(e){const{viewData:r}=j.useContext(Tt),{nodeById:t,edgeById:n,parentIds:o}=mr();if(r){const i=Fe(r,e),s=i&&typeof i=="object"&&!Array.isArray(i)&&"$"in i?i.$:i;return Array.isArray(s)?s.length>0:!!s&&typeof s=="object"&&Object.entries(s).some(([a,c])=>!a.startsWith("$")&&c!==null&&typeof c=="object")}return o.has(e)?!0:[...n.values()].some(({data:i})=>{const s=i.isInverted?i.target:i.source,a=i.isInverted?i.source:i.target;return s===e&&a!==e&&t.has(a)})}function Mn(e,r){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:r}function In(e,r,t,n){return{borderColor:r,borderWidth:Mn(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",...km(r==="transparent"?"currentColor":r,t,".flow-sdk-node:hover &",!t)}}function mb({label:e,value:r,options:t,onChange:n,disabled:o}){var i;return f.jsxs(Mt,{"aria-label":e,title:`Animation: ${((i=t.find(s=>s.value===r))==null?void 0:i.label)??"Mixed"}`,value:r,style:{width:104},disabled:o,onValueChange:s=>{const a=t.find(c=>c.value===s);a&&n(a.value)},children:[r===""&&f.jsx("option",{value:"",disabled:!0,children:"Mixed"}),t.map(s=>f.jsx("option",{value:s.value,children:s.label},s.value))]})}function Od({nodeId:e,edgeId:r,value:t,open:n,onOpenChange:o}){const{callbacks:i,readOnly:s,themeColor:a,colorMode:c}=Je(),{background:l,backgroundSecondary:d,border:u,colorText:h,colorInactive:p}=at(),m=c==="dark"?Jr:Me(p),y=j.useRef(null),g=j.useRef(null),v=j.useRef(0),[b,x]=j.useState(!1),[w,C]=j.useState("icons"),[S,_]=j.useState([]),[I,E]=j.useState("loading"),[O,A]=j.useState(""),[R,P]=j.useState(0),[T,N]=j.useState(""),[$,M]=j.useState(""),[W,ae]=j.useState(!1);j.useEffect(()=>()=>{v.current++},[]),j.useEffect(()=>{if(!b)return;let B=!0;return import("react-icons/pi").then(ce=>{B&&(_(Object.keys(ce).filter(X=>X.startsWith("Pi")).sort()),E("ready"))}).catch(()=>{B&&E("unavailable")}),()=>{B=!1}},[b]),j.useEffect(()=>{var B;s&&((B=y.current)==null||B.close())},[s]),j.useEffect(()=>{var B,ce,X;if(n!==void 0){if(!n||s){(B=y.current)==null||B.close();return}(ce=y.current)!=null&&ce.open||(M(""),C(t==="PiFileSvg"||t&&sr(t)?"custom":"icons"),N(t&&!t.startsWith(_n)&&sr(t)?t:""),x(!0),(X=y.current)==null||X.showModal())}},[n,s,t]);const se=B=>{var ce,X,le;s||(r?(ce=i.onEdgeIconChange)==null||ce.call(i,r,B):e&&((X=i.onNodeIconChange)==null||X.call(i,e,B)),o==null||o(!1),(le=y.current)==null||le.close())},re=S.filter(B=>B.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(O.trim().toLowerCase())),ye=36,me=Math.max(1,Math.ceil(re.length/ye)),L=Math.min(R,me-1),z=re.slice(L*ye,(L+1)*ye),U={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${Me(u)}`,borderRadius:30};return f.jsxs(f.Fragment,{children:[n===void 0&&f.jsx(Ke,{label:r?"Choose edge icon":"Choose node icon",children:f.jsx(Oe,{"aria-label":r?"Choose edge icon":"Choose node icon",icon:f.jsx(Z.PiShapes,{size:20}),size:"sm",variant:"ghost",color:Me(a),disabled:s,onClick:()=>{var B;M(""),C(t&&sr(t)?"custom":"icons"),N(t&&!t.startsWith(_n)&&sr(t)?t:""),x(!0),(B=y.current)==null||B.showModal()}})}),f.jsx(V.chakra.dialog,{ref:y,"aria-label":r?"Choose edge icon":"Choose node icon",css:hr(Me(l),Me(u)),onClose:()=>{x(!1),o==null||o(!1),v.current++,ae(!1)},onClick:B=>{B.stopPropagation(),B.target===B.currentTarget&&B.currentTarget.close()},onKeyDown:B=>B.stopPropagation(),style:{margin:"auto",padding:12,width:336,maxWidth:"calc(100vw - 32px)",maxHeight:"calc(100vh - 32px)",overflowY:"auto",borderRadius:30,background:Me(l),color:Me(h)},children: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:r?"Edge icon":"Node icon"}),f.jsxs("div",{style:{display:"flex",alignItems:"center",marginLeft:"auto",gap:4},children:[t&&f.jsx(Ke,{label:"Remove icon",children:f.jsx(Oe,{"aria-label":r?"Remove edge icon":"Remove node icon",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:s||W,onClick:()=>se("")})}),f.jsx(Zr,{"aria-label":"Close icon picker",onClick:()=>{var B;return(B=y.current)==null?void 0:B.close()}})]})]}),f.jsxs(V.Tabs.Root,{value:w,onValueChange:({value:B})=>{C(B),M("")},display:"contents",css:{"--indicator-thickness":"1px"},children:[f.jsx(V.Tabs.List,{"aria-label":"Icon source",width:"100%",borderBottomWidth:0,children:["icons","custom"].map(B=>f.jsx(V.Tabs.Trigger,{value:B,flex:1,minW:0,justifyContent:"center",px:3,py:2,fontSize:"13px",_selected:{color:a,borderColor:m,"--indicator-color":m},children:B==="icons"?"React icons":"Custom SVG"},B))}),f.jsx("input",{ref:g,type:"file",accept:".svg,image/svg+xml","aria-label":"Upload SVG icon",hidden:!0,disabled:W||s,onChange:async B=>{var le;const ce=(le=B.target.files)==null?void 0:le[0];if(B.target.value="",!ce)return;const X=++v.current;ae(!0),M("");try{const ue=await bw(ce);X===v.current&&se(ue)}catch(ue){X===v.current&&M(ue instanceof Error?ue.message:"Unable to read SVG.")}finally{X===v.current&&ae(!1)}}}),f.jsx(V.Tabs.Content,{value:w,p:0,style:{display:"grid",gap:8},children:w==="icons"?f.jsxs(f.Fragment,{children:[f.jsx("input",{"aria-label":"Search icons",placeholder:"Search icons...",value:O,onChange:B=>{A(B.target.value),P(0)},style:U}),f.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[z.map(B=>f.jsx("button",{type:"button","aria-label":`Choose ${B}`,"aria-pressed":t===B,title:B,onClick:()=>se(B),style:{display:"grid",placeItems:"center",borderRadius:5,border:`${t===B?2:1}px solid ${Me(t===B?a:u)}`,background:Me(t===B?l:d),color:"inherit",cursor:"pointer"},children:f.jsx(Yt,{name:B,size:24})},B)),z.length===0&&f.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:I==="loading"?"Loading icons...":I==="unavailable"?"React icons unavailable":"No icons found"})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[f.jsxs("span",{role:"status",style:{fontSize:12},children:[re.length," icons · ",L+1," / ",me]}),f.jsxs("div",{style:{display:"flex",gap:4},children:[f.jsx(Ke,{label:"Previous icons",children:f.jsx(Oe,{"aria-label":"Previous icons",icon:f.jsx(Z.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:L===0,onClick:()=>P(L-1)})}),f.jsx(Ke,{label:"Next icons",children:f.jsx(Oe,{"aria-label":"Next icons",icon:f.jsx(Z.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:L+1>=me,onClick:()=>P(L+1)})})]})]})]}):f.jsxs(f.Fragment,{children:[t&&sr(t)&&f.jsx(Yt,{name:t,size:64}),f.jsxs("button",{type:"button",disabled:W||s,onClick:()=>{var B;return(B=g.current)==null?void 0:B.click()},style:{...U,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[f.jsx(Z.PiUploadSimple,{}),W?"Uploading...":"Upload SVG"]}),f.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:B=>{B.preventDefault(),!(W||s)&&(!sr(T.trim())||T.trim().startsWith(_n)?M("Enter an HTTP or HTTPS image URL."):se(T.trim()))},children:[f.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:T,disabled:W||s,onChange:B=>N(B.target.value),style:{...U,flex:1,minWidth:0}}),f.jsx(Ke,{label:"Apply URL",children:f.jsx(Oe,{type:"submit","aria-label":"Apply URL",icon:f.jsx(Z.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:W||s||!T.trim(),style:{flexShrink:0}})})]})]})})]}),$&&f.jsx("div",{role:"alert",style:{fontSize:13},children:$})]})})]})}const ro=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500",Jr],bb=["gray.900",Jr,"gray.600","gray.200","white"];function vb(){const{config:e}=Je(),r=e.selectionToolbar||{},t=new Set(r.hide||[]);return{palette:r.palette||ro,show:n=>!t.has(n)}}function St(){const{border:e}=at();return f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:e})}function Br({value:e,placeholder:r,ariaLabel:t,width:n="140px",type:o="text",min:i,onCommit:s}){const{colorText:a}=at(),[c,l]=j.useState(e),d=j.useRef(!1);j.useEffect(()=>l(e),[e]);const u=()=>{if(d.current)return;d.current=!0;const h=c.trim();if(o==="number"&&h!==""&&(!Number.isFinite(Number(h))||Number(h)<(i??0))){l(e);return}h!==e&&s(h)};return f.jsx(V.Input,{"aria-label":t,type:o,min:i,size:"xs",fontSize:"16px",w:n,value:c,placeholder:r,color:a,borderWidth:0,_focusVisible:{boxShadow:"none",outline:"none"},borderRadius:"8px",onFocus:()=>{d.current=!1},onChange:h=>l(h.target.value),onBlur:u,onKeyDown:h=>{h.key==="Enter"&&(u(),h.target.blur()),h.key==="Escape"&&(d.current=!0,l(e),h.target.blur())}})}function Ar({colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i=!0}){const{colorInactive:s,colorText:a}=at(),[c,l]=j.useState(!1),d=j.useId(),u=j.useRef(null),h=r??e[0]??"transparent",p=so(f.jsx(Ar,{colors:e,value:r,label:t,onPick:n,onReset:o,includeTransparent:i}));return f.jsx(Wr.Provider,{value:null,children:f.jsxs(V.HStack,{gap:1,"aria-label":t,role:"group",onClickCapture:p,onKeyDown:m=>{var y;m.key==="Escape"&&(l(!1),(y=u.current)==null||y.focus())},children:[f.jsx(Ke,{label:`${t}: ${h}`,children:f.jsx(V.chakra.button,{ref:u,type:"button","aria-label":`${t} colors`,"aria-expanded":c,"aria-controls":d,w:4,h:4,flexShrink:0,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Me(h),...h==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${Me(a)}`,outlineOffset:"1px",onClick:()=>l(m=>!m)})}),c&&f.jsxs(V.HStack,{id:d,gap:1,children:[[...new Set([...e,...i?["transparent"]:[]])].map(m=>{const y=r===m;return f.jsx(Ke,{label:`${t}: ${m}`,children:f.jsx(V.Box,{as:"button","aria-label":`${t} ${m}`,"aria-pressed":y,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Me(m),...m==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:y?`2px solid ${Me(a)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>n(m),onDoubleClick:g=>{var v;g.stopPropagation(),l(!1),(v=u.current)==null||v.focus()}})},m)}),o&&f.jsx(Ke,{label:`Reset ${t.toLowerCase()}`,children:f.jsx(Oe,{"aria-label":`Reset ${t}`,icon:f.jsx(V.Icon,{as:Z.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:s,onClick:()=>{var m;o(),l(!1),(m=u.current)==null||m.focus()}})})]})]})})}function xb({edgeId:e,onClose:r}){var p;const{callbacks:t,themeColor:n,config:o}=Je(),{colorInactive:i}=at(),{edgeById:s}=mr(),{palette:a,show:c}=vb(),l=(p=s.get(e))==null?void 0:p.data,d=[...new Set(["rounded-orthogonal","orthogonal","straight","bezier",...Object.keys(o.customEdgeTypes??{}),...l!=null&&l.type?[l.type]:[]])],u=l!=null&&l.isEdgeAnimated?"animated":l!=null&&l.isEdgeDashed?"dashed":"solid",h=[{key:"solid",icon:Z.PiLineSegment,label:"Solid"},{key:"dashed",icon:Z.PiLineSegments,label:"Dashed"},{key:"animated",icon:Z.PiFastForward,label:"Animated"}];return f.jsxs(f.Fragment,{children:[f.jsx(Zr,{onClick:r}),c("label")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Br,{ariaLabel:"Edge label",placeholder:"Edge label",value:(l==null?void 0:l.label)||"",onCommit:m=>{var y;return(y=t.onEdgeLabelChange)==null?void 0:y.call(t,e,m)}})]}),c("style")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),h.map(m=>f.jsx(Ke,{label:m.label,children:f.jsx(Oe,{"aria-label":`Edge style ${m.key}`,"aria-pressed":u===m.key,icon:f.jsx(V.Icon,{as:m.icon,boxSize:5}),size:"sm",variant:"ghost",color:u===m.key?n:i,onClick:()=>{var y;return(y=t.onEdgeStyleChange)==null?void 0:y.call(t,e,m.key)}})},m.key)),u==="animated"&&f.jsx(mb,{label:"Edge animation",value:(l==null?void 0:l.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:o.readOnly,onChange:m=>{var y;return(y=t.onEdgeAnimationVariantChange)==null?void 0:y.call(t,e,m)}}),f.jsxs(Mt,{"aria-label":"Edge shape",title:`Edge shape: ${(l==null?void 0:l.type)??"Default"}`,icon:f.jsx(Z.PiBezierCurve,{size:20}),style:{width:36},value:(l==null?void 0:l.type)??"",disabled:o.readOnly,onValueChange:m=>{var y;return(y=t.onEdgeTypeChange)==null?void 0:y.call(t,e,m||void 0)},children:[f.jsx("option",{value:"",children:"Default"}),d.map(m=>f.jsx("option",{value:m,children:m},m))]})]}),c("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Od,{edgeId:e,value:l==null?void 0:l.icon},e),f.jsx(Br,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(l==null?void 0:l.icon)??"",onCommit:m=>{var y;return(y=t.onEdgeIconChange)==null?void 0:y.call(t,e,m)}})]}),c("color")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Ar,{label:"Edge color",colors:a,value:l==null?void 0:l.color,onPick:m=>{var y;return(y=t.onEdgeColorChange)==null?void 0:y.call(t,e,m)},onReset:()=>{var m;return(m=t.onEdgeColorChange)==null?void 0:m.call(t,e,"")}})]}),c("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Ke,{label:"Delete edge",children:f.jsx(Oe,{"aria-label":"Delete edge",icon:f.jsx(V.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var m;(m=t.onEdgeDelete)==null||m.call(t,e,l),r()}})})]})]})}function wb({ids:e,showDivider:r=!0}){const{callbacks:t,config:n,nodeGridOptions:o,fillRadiusEditedIds:i,setNodeRadiusPreview:s}=Je(),{colorInactive:a}=at(),{nodeById:c}=mr(),[l,d]=j.useState(),u=j.useRef(),h=j.useRef(),p=j.useRef({callbacks:t,readOnly:n.readOnly,nodeById:c});p.current={callbacks:t,readOnly:n.readOnly,nodeById:c};const m=()=>{var C,S;clearTimeout(h.current);const w=u.current;if(u.current=void 0,!!w){if(!p.current.readOnly)for(const _ of w.ids)p.current.nodeById.has(_)&&((S=(C=p.current.callbacks).onNodeBorderRadiusChange)==null||S.call(C,_,w.radius));s(w.ids,void 0),d(void 0)}},y=j.useRef(m);y.current=m,j.useEffect(()=>{const w=()=>y.current();return window.addEventListener("pagehide",w),()=>{window.removeEventListener("pagehide",w),w()}},[]);const g=e.map(w=>{var C,S;return o!=null&&o.fill&&!i.has(w)?0:(S=(C=c.get(w))==null?void 0:C.data.viewProps)==null?void 0:S.borderRadius}),v=!g.every(w=>w===g[0]),b=l??g[0]??0,x=w=>{n.readOnly||(w!==void 0&&e.every(C=>{var S;return((S=c.get(C))==null?void 0:S.data.type)==="grid"})?(d(w),s(e,w),u.current={ids:[...e],radius:w},clearTimeout(h.current),h.current=setTimeout(m,150)):(clearTimeout(h.current),u.current=void 0,d(void 0),s(e,void 0),e.forEach(C=>{var S;return(S=t.onNodeBorderRadiusChange)==null?void 0:S.call(t,C,w)})))};return f.jsxs(f.Fragment,{children:[r&&f.jsx(St,{}),f.jsx(V.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:f.jsx(Mt,{icon:f.jsx(V.Icon,{as:vx.TbBorderRadius,boxSize:5,color:a,"aria-hidden":"true"}),"aria-label":"Node border radius",title:`Border radius: ${v?"Mixed":g[0]===void 0?"Default":`${g[0]}px`}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",cursor:"pointer"},value:"radius",disabled:n.readOnly,onValueChange:()=>{},popupContent:f.jsxs(f.Fragment,{children:[f.jsx(ud,{label:"Border radius",inputLabel:"Node corner radius",min:0,max:Math.max(500,...g.map(w=>w??0)),step:1,value:b,displayValue:l!==void 0?`${l}px`:v?"Mixed":g[0]===void 0?"Default":`${b}px`,onChange:x,onChangeEnd:m}),f.jsx(Ke,{label:"Reset border radius",children:f.jsx(Oe,{"aria-label":"Reset border radius",icon:f.jsx(Z.PiEraser,{size:20}),size:"sm",variant:"ghost",color:a,disabled:n.readOnly,onClick:()=>x(void 0)})})]}),children:f.jsx("option",{value:"radius",children:"Border radius"})})})]})}function Cb({ids:e,onClose:r,afterLabel:t}){var ce,X,le,ue,xe,Ce,ge,he;const{callbacks:n,colorMode:o,themeColor:i,config:s,setNodeViewMode:a,nodeViewModes:c}=Je(),{colorText:l,colorInactive:d}=at(),{nodeById:u,parentIds:h}=mr(),{palette:p,show:m}=vb(),y=e.length===1,[g,v]=j.useState(""),b=y?(ce=u.get(e[0]))==null?void 0:ce.data:void 0,x=e.map(Y=>{var J,be,Q,je,Pe,qe;const H=(J=u.get(Y))==null?void 0:J.data,ve=((be=H==null?void 0:H.config)==null?void 0:be.typeView)??"";return ve==="object"&&((Q=H==null?void 0:H.config)==null?void 0:Q.content)!==void 0&&c[Y]!=="properties"?"content":ve==="icon-label"&&((je=H==null?void 0:H.viewProps)==null?void 0:je.bgColor)==="transparent"&&((Pe=H==null?void 0:H.viewProps)==null?void 0:Pe.borderWidth)===0&&((qe=H==null?void 0:H.viewProps)==null?void 0:qe.outline)===!1?"media":ve}),w=x.some(Y=>Y!==x[0]),C=w?"mixed":x[0]??"",S=[{value:"text",label:"Text",view:"text",icon:Z.PiTextT},{value:"icon-label",label:"Icon Label",view:"icon-label",icon:Z.PiShapes},{value:"object",label:"Object",view:"object",icon:Z.PiBracketsCurly},{value:"grid",label:"Grid",view:"grid",icon:Z.PiGridFour},{value:"parent",label:"Parent",view:"parent",icon:Z.PiStack},{value:"media",label:"Media",view:"icon-label",icon:Z.PiFileSvg},{value:"content",label:"Content",view:"object",icon:Z.PiTextAlignLeft}],_=e.some(Y=>{var ve,J,be,Q;const H=(ve=u.get(Y))==null?void 0:ve.data;return H&&((J=H.config)==null?void 0:J.typeView)!=="grid"&&((be=H.config)==null?void 0:be.typeView)!=="parent"&&(h.has(Y)||((Q=H.config)==null?void 0:Q.parentContainer)||Object.prototype.hasOwnProperty.call(s.customViews??{},H.type))}),I=(X=b==null?void 0:b.config)==null?void 0:X.collapsed,E=yb(e[0]),O=Y=>{var H,ve,J;return(((ve=(H=u.get(Y))==null?void 0:H.data.viewProps)==null?void 0:ve.outline)??(h.has(Y)?(J=s.parentNodeStyle)==null?void 0:J.outline:!1))===!0},A=e.every(O),R=!A&&e.some(O),P=Y=>{var H;return((H=u.get(Y))==null?void 0:H.data.isNodeAnimated)===!0},T=e.every(P),N=!T&&e.some(P),$=e.map(Y=>{var H;return((H=u.get(Y))==null?void 0:H.data.nodeAnimationVariant)??"traveling"}),M=$.every(Y=>Y===$[0])?$[0]:"",W=Y=>e.forEach(Y),[ae,se]=j.useState(!1),re=ae&&m("color")&&m("borderColor"),ye=Y=>{var H,ve,J;return(((ve=(H=u.get(Y))==null?void 0:H.data.viewProps)==null?void 0:ve.borderStyle)??(h.has(Y)?(J=s.parentNodeStyle)==null?void 0:J.borderStyle:"solid"))==="dashed"},me=e.every(ye),L=!me&&e.some(ye),z=e.map(Y=>{var J,be,Q;const H=(J=u.get(Y))==null?void 0:J.data,ve=h.has(Y)?Mn((be=s.parentNodeStyle)==null?void 0:be.borderWidth,6):(H==null?void 0:H.type)==="objectView"?3:2;return Mn((Q=H==null?void 0:H.viewProps)==null?void 0:Q.borderWidth,ve)}),U=z.every(Y=>Y===z[0])?String(z[0]??""):"",B=Y=>W(H=>{var ve,J;re?(ve=n.onNodeBorderColorChange)==null||ve.call(n,H,Y):(J=n.onNodeColorChange)==null||J.call(n,H,"bg",Y)});return f.jsxs(f.Fragment,{children:[f.jsx(Zr,{onClick:r}),f.jsx(St,{}),y&&m("label")?f.jsx(Br,{ariaLabel:"Node label",placeholder:"Node label",value:(b==null?void 0:b.label)??(b==null?void 0:b.headerTitle)??"",onCommit:Y=>{var H;return(H=n.onNodeLabelChange)==null?void 0:H.call(n,e[0],Y)}}):f.jsxs(V.Text,{fontSize:"xs",color:l,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),t,m("typeView")&&f.jsxs(Mt,{"aria-label":"Type view",title:_?"Type view is managed by the custom renderer or container":`Type view: ${C||"None (default)"}`,icon:f.jsx(Z.PiCards,{size:20}),style:{width:36},value:C,disabled:s.readOnly||s.editable===!1||_,onValueChange:Y=>{var ve;const H=(ve=S.find(J=>J.value===Y))==null?void 0:ve.view;H&&W(J=>{var Q,je,Pe,qe,Xe,Be,ut,De,rt,pt,Ne,Ge,st;const be=(Q=u.get(J))==null?void 0:Q.data;Y==="media"?((je=n.onNodeColorChange)==null||je.call(n,J,"bg","transparent"),(Pe=n.onNodeBorderColorChange)==null||Pe.call(n,J,"#00000000"),(qe=n.onNodeBorderWidthChange)==null||qe.call(n,J,0),(Xe=n.onNodeOutlineChange)==null||Xe.call(n,J,!1)):x[e.indexOf(J)]==="media"&&((Be=n.onNodeColorChange)==null||Be.call(n,J,"bg",""),(ut=n.onNodeBorderColorChange)==null||ut.call(n,J,""),(De=n.onNodeBorderWidthChange)==null||De.call(n,J,void 0)),Y==="content"&&((rt=be==null?void 0:be.config)==null?void 0:rt.content)===void 0&&((pt=n.onNodeContentChange)==null||pt.call(n,J,"")),(Ne=n.onNodeTypeViewChange)==null||Ne.call(n,J,H),a(J,Y==="object"&&((Ge=be==null?void 0:be.config)==null?void 0:Ge.content)!==void 0?"properties":"default"),(st=n.onNodeViewToggle)==null||st.call(n,J)})},children:[w&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),S.map(Y=>f.jsx("option",{value:Y.value,children:f.jsxs(V.HStack,{gap:"12px",children:[f.jsx(Y.icon,{size:20,"aria-hidden":"true",style:{flexShrink:0}}),f.jsx("span",{children:Y.label})]})},Y.value))]}),m("style")&&f.jsx(wb,{ids:e},e.join("\0")),m("outline")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Ke,{label:A?"Restore node fill":"Remove node fill",children:f.jsx(Oe,{"aria-label":"Toggle node outline","aria-pressed":R?"mixed":A,icon:f.jsx(V.Icon,{as:A?Z.PiSquare:Z.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:A?i:d,onClick:()=>W(Y=>{var H;return(H=n.onNodeOutlineChange)==null?void 0:H.call(n,Y,!A)})})})]}),m("color")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),m("borderColor")&&f.jsx(Ke,{label:re?"Edit node colors":"Edit node border",children:f.jsx(Oe,{"aria-label":"Edit node border","aria-pressed":re,icon:f.jsx(V.Icon,{as:Z.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:re?i:d,bg:re?o==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>se(Y=>!Y)})}),f.jsx(Ar,{label:re?"Border color":"Background",colors:p,value:re?((le=b==null?void 0:b.viewProps)==null?void 0:le.borderColor)??(y&&h.has(e[0])?(ue=s.parentNodeStyle)==null?void 0:ue.borderColor:void 0):(xe=b==null?void 0:b.viewProps)==null?void 0:xe.bgColor,onPick:B,onReset:()=>B("")}),re&&m("style")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Ke,{label:me?"Solid border":"Dashed border",children:f.jsx(Oe,{"aria-label":"Toggle dashed border","aria-pressed":L?"mixed":me,icon:f.jsx(V.Icon,{as:me?Z.PiLineSegments:Z.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:me?i:d,onClick:()=>W(Y=>{var H;return(H=n.onNodeBorderStyleChange)==null?void 0:H.call(n,Y,me?"solid":"dashed")})})}),f.jsx(Br,{ariaLabel:"Border thickness",placeholder:y?"Auto":"Mixed",width:"64px",type:"number",min:0,value:U,onCommit:Y=>W(H=>{var ve;return(ve=n.onNodeBorderWidthChange)==null?void 0:ve.call(n,H,Y===""?void 0:Number(Y))})})]})]}),m("animation")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Ke,{label:T?"Stop border animation":"Animate node border",children:f.jsx(Oe,{"aria-label":"Toggle node animation","aria-pressed":N?"mixed":T,icon:f.jsx(V.Icon,{as:Z.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:T?i:d,onClick:()=>W(Y=>{var H;return(H=n.onNodeAnimationChange)==null?void 0:H.call(n,Y,!T)})})}),(T||N)&&f.jsx(mb,{label:"Node animation",value:M,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:s.readOnly,onChange:Y=>W(H=>{var ve;return(ve=n.onNodeAnimationVariantChange)==null?void 0:ve.call(n,H,Y)})})]}),!re&&m("textColor")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Ar,{label:"Text color",colors:bb,value:(Ce=b==null?void 0:b.viewProps)==null?void 0:Ce.textColor,onPick:Y=>W(H=>{var ve;return(ve=n.onNodeColorChange)==null?void 0:ve.call(n,H,"text",Y)}),onReset:()=>W(Y=>{var H;return(H=n.onNodeColorChange)==null?void 0:H.call(n,Y,"text","")})})]}),y&&m("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Od,{nodeId:e[0],value:(ge=b==null?void 0:b.config)==null?void 0:ge.icon},e[0]),f.jsx(Br,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((he=b==null?void 0:b.config)==null?void 0:he.icon)||"",onCommit:Y=>{var H;return(H=n.onNodeIconChange)==null?void 0:H.call(n,e[0],Y)}})]}),y&&E&&m("collapse")&&I!==void 0&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Ke,{label:I?"Expand":"Collapse",children:f.jsx(Oe,{"aria-label":I?"Expand node":"Collapse node",icon:f.jsx(V.Icon,{as:I?Z.PiArrowsOutLineVertical:Z.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:d,onClick:()=>{var Y;return(Y=n.onNodeCollapse)==null?void 0:Y.call(n,e[0],!I)}})})]}),m("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(St,{}),f.jsx(Ke,{label:y?"Delete node":`Delete ${e.length} nodes`,children:f.jsx(Oe,{"aria-label":"Delete selected nodes",icon:f.jsx(V.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:o==="dark"?"red.300":"red.500",onClick:()=>{W(Y=>{var H,ve;return(ve=n.onNodeDelete)==null?void 0:ve.call(n,Y,((H=u.get(Y))==null?void 0:H.data)||{id:Y})}),r()}})})]}),f.jsx(St,{}),f.jsx(Ke,{label:"Copy selection",children:f.jsx(Oe,{"aria-label":"Copy selection",icon:f.jsx(Z.PiCopy,{size:20}),size:"sm",variant:"ghost",color:d,onClick:async()=>{var Y;try{await((Y=n.onNodesCopy)==null?void 0:Y.call(n,e)),v("")}catch(H){v(String(H))}}})}),f.jsx(Ke,{label:"Duplicate selection",children:f.jsx(Oe,{"aria-label":"Duplicate selection",icon:f.jsx(Z.PiCopySimple,{size:20}),size:"sm",variant:"ghost",color:d,disabled:s.readOnly||s.editable===!1,onClick:()=>{var Y;try{(Y=n.onNodesDuplicate)==null||Y.call(n,e),v("")}catch(H){v(String(H))}}})}),g&&f.jsx(V.Text,{role:"alert",fontSize:"xs",children:g})]})}async function Sb(e){const{toSvg:r}=await Promise.resolve().then(()=>require("./index-sHQXTNv9.cjs"));await document.fonts.ready;const t=await r(e,{filter:o=>!(o instanceof Element)||!o.matches("button, iframe, [role=tooltip], .flow-sdk-handle, .flow-sdk-property-port, .flow-sdk-edge-hit, .flow-sdk-ghost, .flow-sdk-node-animation")}),n=new DOMParser().parseFromString(decodeURIComponent(t.slice(t.indexOf(",")+1)),"image/svg+xml");return n.querySelectorAll(".flow-sdk-edge-hit, .flow-sdk-handle, .flow-sdk-property-port, .flow-sdk-ghost").forEach(o=>o.remove()),n.querySelectorAll("[data-flow-preview-source]").forEach(o=>{o.setAttribute("style","display:block;white-space:pre-wrap;font:16px/1.5 monospace;overflow-wrap:anywhere")}),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(n))}`}async function jb(e,r="squeed.svg"){const t=document.createElement("a");t.href=await Sb(e),t.download=r.endsWith(".svg")?r:`${r}.svg`,t.click()}function _b(){const{themeColor:e}=Je(),[r,t]=j.useState(!1),[n,o]=j.useState("");return f.jsxs(f.Fragment,{children:[f.jsx(Ke,{label:"Download SVG (current view)",children:f.jsx(Oe,{"aria-label":"Download SVG",icon:f.jsx(Z.PiDownloadSimpleFill,{size:20}),disabled:r,borderRadius:"30%",color:e,variant:"ghost",onClick:async i=>{var a;const s=(a=i.currentTarget.closest("[data-flow-diagram]"))==null?void 0:a.querySelector("[data-flow-background]");if(!s){o("Diagram not available for export.");return}t(!0),o("");try{await jb(s)}catch(c){o(c instanceof Error?c.message:"Unable to export SVG.")}finally{t(!1)}}})}),n&&f.jsx("span",{role:"alert",style:{fontSize:12,maxWidth:220},children:n})]})}function Nd({children:e,background:r,border:t,endElement:n,startElement:o,startElementWidth:i=44,framed:s=!0}){const a=j.useRef(null),[c,l]=j.useState({left:!1,right:!1});j.useLayoutEffect(()=>{const u=a.current;let h=u.parentElement.offsetWidth;const p=()=>{const g=u.parentElement.offsetWidth;if(g>0&&g!==h){const x=h/g;h=g,x>0&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches&&u.parentElement.animate({transform:[`scaleX(${x})`,"scaleX(1)"],transformOrigin:[n?"right center":"left center",n?"right center":"left center"]},{duration:180,easing:"ease-out",id:"flow-toolbar-grow"})}const v=u.scrollLeft>1,b=u.scrollWidth-u.clientWidth-u.scrollLeft>1;l(x=>x.left===v&&x.right===b?x:{left:v,right:b})},m=g=>{if(g.defaultPrevented||g.ctrlKey||s&&g.deltaX!==0||!(g.deltaX||g.deltaY)||u.scrollWidth<=u.clientWidth)return;g.preventDefault();const v=g.deltaMode===WheelEvent.DOM_DELTA_LINE?16:g.deltaMode===WheelEvent.DOM_DELTA_PAGE?u.clientWidth:1;u.scrollLeft+=(g.deltaX||g.deltaY)*v},y=new ResizeObserver(p);return y.observe(u),u.firstElementChild&&y.observe(u.firstElementChild),u.addEventListener("scroll",p,{passive:!0}),u.addEventListener("wheel",m,{passive:!1}),p(),()=>{y.disconnect(),u.removeEventListener("scroll",p),u.removeEventListener("wheel",m)}},[]);const d=`var(--chakra-colors-${r.replace(".","-")})`;return f.jsxs(V.Box,{position:"relative",bg:s?r:"transparent",minW:0,maxW:"100%",flex:"0 1 auto",borderRadius:s?"30px":0,css:{...s?hr(d,`var(--chakra-colors-${t.replace(".","-")})`):{},...s||o?{"--flow-toolbar-start-width":o?`${i}px`:"0px"}:{}},children:[f.jsx(V.Box,{ref:a,"data-flow-toolbar-scroll":"",h:50,minH:50,alignContent:"center",overflowX:"auto",overflowY:"hidden",mr:n?"44px":void 0,ml:o?`${i}px`:void 0,borderRadius:"inherit",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e}),["left","right"].map(u=>f.jsx(V.Box,{"data-flow-toolbar-fade":u,"aria-hidden":"true",position:"absolute",top:0,bottom:0,w:"20px",pointerEvents:"none",borderRadius:u==="left"?"30px 0 0 30px":"0 30px 30px 0",style:{[u]:u==="right"&&n?44:u==="left"&&o?i:0,opacity:c[u]?1:0,background:`linear-gradient(to ${u==="left"?"right":"left"}, ${d}, transparent)`}},u)),n&&f.jsx(V.Box,{position:"absolute",right:"6px",top:0,h:"50px",w:"32px",display:"flex",alignItems:"center",justifyContent:"center",children:n}),o&&f.jsx(V.Box,{position:"absolute",left:"6px",top:0,h:"50px",w:`${i-12}px`,display:"flex",alignItems:"center",justifyContent:"center",children:o})]})}async function Aw(e,r){const t=new Set,n=[],o=(a,c)=>{var d,u,h;if(!a||typeof a!="object")return;const l=a;n.push(c),typeof((d=l.$form)==null?void 0:d.$type)=="string"&&t.add(l.$form.$type),typeof((h=(u=l.$form)==null?void 0:u.$create)==null?void 0:h.$type)=="string"&&t.add(l.$form.$create.$type);for(const[p,m]of Object.entries(l))p==="$"?o(m,c):p.startsWith("$")||o(m,`${c}.${p}`)};if(o(r,"root"),!t.size)return{contract:await fb(e)};const i=await Id(e,[...t]);for(const a of t)if(!Object.prototype.hasOwnProperty.call(i,a))throw new Error(`Missing form type: ${a}`);const s={};for(const a of n){const c=Yr(r,a,i);c&&(s[a]={type:c.type,optional:!1})}return{schema:i,contract:{name:e.name,nodes:s}}}function Eb({message:e,onDismiss:r}){const{background:t,colorText:n,border:o}=at();return!e||typeof document>"u"?null:Dr.createPortal(f.jsxs(V.chakra.div,{role:"alert","aria-atomic":"true",css:hr(Me(t),Me(o)),onPointerDown:i=>i.stopPropagation(),onClick:i=>i.stopPropagation(),style:{position:"fixed",top:20,right:20,zIndex:1e4,width:360,maxWidth:"calc(100vw - 40px)",boxSizing:"border-box",display:"flex",alignItems:"flex-start",gap:10,padding:16,borderRadius:8,background:Me(t),color:Me(n),fontSize:14,lineHeight:1.5},children:[f.jsx(Z.PiWarningCircle,{size:20,"aria-hidden":"true",style:{flexShrink:0,color:"#ef4444"}}),f.jsxs("div",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:[f.jsx("strong",{children:"Interface upload failed"}),f.jsx("div",{children:e})]}),f.jsx(Zr,{type:"button","aria-label":"Dismiss upload error",title:"Dismiss upload error",onClick:r,flexShrink:0,width:"24px",height:"24px",minWidth:"24px",padding:0})]}),document.body)}function $d({showDivider:e=!0,compact:r=!1}={}){const{edgeMode:t,setEdgeMode:n,workflowContract:o,setWorkflowContract:i,callbacks:s,readOnly:a,themeColor:c,colorMode:l}=Je(),{edgeById:d}=mr(),{data:u,schema:h,setSchema:p,bindings:m,structured:y}=j.useContext(Tt),g=(y==null?void 0:y.sourceBindings)??m,v=(y==null?void 0:y.sourceSchema)??h,{colorText:b}=at(),x=j.useRef(null),w=j.useRef(0),[C,S]=j.useState(!1),[_,I]=j.useState("");j.useEffect(()=>()=>{w.current++},[]),j.useEffect(()=>{w.current++,S(!1)},[a,u,g]);const E=o?[...d.values()].filter(R=>Md(o,R.data)).length:0,O=o?`${o.name}: ${v?`${Object.keys(v).length} form types loaded; `:""}${E} invalid or unverified connections`:"",A=so(f.jsx($d,{showDivider:!1,compact:!0}));return f.jsx(Wr.Provider,{value:null,children:f.jsxs("span",{style:{display:"contents"},onClickCapture:A,children:[f.jsx(Eb,{message:_,onDismiss:()=>I("")}),e&&f.jsx(vn,{}),f.jsxs(Mt,{"aria-label":"Edge mode",title:t==="auto"?"Connections: Auto":t==="properties"?"Connections: Properties":"Connections: Nodes",icon:t==="auto"?f.jsx(Z.PiGraph,{size:20}):t==="properties"?f.jsx(Z.PiTable,{size:20}):f.jsx(Z.PiTreeStructure,{size:20}),style:{width:36},value:t,disabled:a,footer:s.onWorkflowConfigurationOpen&&f.jsxs(f.Fragment,{children:[f.jsx("hr",{style:{border:0,borderTop:"1px solid currentColor",opacity:.2,margin:"8px 0"}}),f.jsxs(V.Button,{"data-flow-menu-action":"",variant:"ghost",width:"100%",justifyContent:"flex-start",color:"inherit",bg:"transparent",css:to,_hover:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},onClick:R=>{var P,T;(P=R.currentTarget.closest("[popover]"))==null||P.hidePopover(),(T=s.onWorkflowConfigurationOpen)==null||T.call(s)},children:[f.jsx(Z.PiGear,{}),"Configuration"]})]}),onValueChange:R=>{var T;const P=R==="auto"?"auto":R==="properties"?"properties":"nodes";n(P),(T=s.onEdgeModeChange)==null||T.call(s,P)},children:[f.jsx("option",{value:"auto",children:"Auto"}),f.jsx("option",{value:"nodes",children:"Nodes"}),f.jsx("option",{value:"properties",children:"Properties"})]}),f.jsxs("span",{style:{display:t==="auto"||t==="properties"?"contents":"none"},children:[f.jsx(Ke,{label:o?`Replace ${o.name}`:"Upload workflow interface",children:f.jsx(Oe,{"aria-label":"Upload workflow interface",icon:f.jsx(Z.PiUploadSimple,{size:20}),color:Me(c),size:"sm",variant:"ghost",disabled:C||a,onClick:()=>{var R;return(R=x.current)==null?void 0:R.click()}})}),f.jsx("input",{ref:x,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:a||C,onChange:async R=>{var N,$;const P=(N=R.target.files)==null?void 0:N[0];if(R.target.value="",!P)return;const T=++w.current;S(!0),I("");try{const M=g?await Id(P,[...new Set(Object.values(g).map(se=>se.schemaType??se.type))]):void 0;if(g&&M){for(const se of Object.values(g))if(!Object.prototype.hasOwnProperty.call(M,se.schemaType??se.type))throw new Error(`Missing form type: ${se.schemaType??se.type}`)}const{contract:W,schema:ae}=g&&M?{schema:M,contract:{name:P.name,nodes:Object.fromEntries(Object.entries(g).map(([se,re])=>[se,{type:M[re.schemaType??re.type],optional:!1}]))}}:await Aw(P,u);if(T!==w.current)return;p==null||p(ae),i(W),($=s.onWorkflowContractChange)==null||$.call(s,W)}catch(M){T===w.current&&I(`${P.name}: ${M instanceof Error?M.message:"Unable to load interface."}`)}finally{T===w.current&&S(!1)}}}),!r&&(O||C)&&f.jsx("span",{role:"status",title:O,style:{color:Me(b),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:C?"Loading interface...":O}),!r&&o&&f.jsx(Ke,{label:"Remove workflow interface",children:f.jsx(Oe,{"aria-label":"Remove workflow interface",icon:f.jsx(Z.PiX,{size:16}),size:"sm",variant:"ghost",disabled:a||C,onClick:()=>{var R;p==null||p(void 0),i(void 0),(R=s.onWorkflowContractChange)==null||R.call(s,void 0),I("")}})})]})]})})}const Pw=[{value:"BT",label:"Bottom to Up",icon:Z.PiArrowUp,flowType:fn.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:Z.PiArrowDown,flowType:fn.TOP_DOWN},{value:"LR",label:"Left to Right",icon:Z.PiArrowRight,flowType:fn.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:Z.PiArrowLeft,flowType:fn.RIGHT_LEFT}],kb=({nodeGridControlsTarget:e}={})=>{const{engineRef:r,themeColor:t,setThemeColor:n,edgeColor:o,setEdgeColor:i,backgroundSelected:s,setBackgroundSelected:a,direction:c,edgeMode:l,allNodesIconLabel:d,setAllNodesIconLabel:u,nodeGridOptions:h,selectedNodeIds:p,setSelectedNodeIds:m,selectedEdgeId:y,setSelectedEdgeId:g,isZoomMode:v,setIsZoomMode:b,isMultiSelectMode:x,setIsMultiSelectMode:w,isDragMode:C,setIsDragMode:S,isEdgeHandlesEnabled:_,setIsEdgeHandlesEnabled:I,isArrayNodeMode:E,setIsArrayNodeMode:O,isPinned:A,setIsPinned:R,callbacks:P,config:T,readOnly:N}=Je(),{nodeById:$,edgeById:M,parentIds:W}=mr(),ae=T.colorMode==="dark",{background:se,border:re,colorInactive:ye,colorText:me,colorActive:L}=at(),z=ae?re:"gray.300",U=`var(--chakra-colors-${se.replace(".","-")})`,B=`var(--chakra-colors-${(ae?re:"gray.300").replace(".","-")})`,[ce,X]=j.useState(!1),[le,ue]=j.useState(!0),xe=T.bottomBarCollapsed??le,Ce=j.useRef(null),ge=_m({edge:"bottom",enabled:!A,bounds:Ce,inside:[Ce]}),he=j.useCallback(Ne=>{const Ge=r.current;if(!Ge)return;const st=T.minZoom??.01,ct=T.maxZoom??1.5,Bt=.02;let Ue=Ge.zoom();switch(Ne){case"increase":Ue=Math.min(ct,Ue+Bt),Ge.zoom(Ue),Ge.center(!1);break;case"decrease":Ue=Math.max(st,Ue-Bt),Ge.zoom(Ue),Ge.center(!1);break;case"reset":Ge.fit(50);break}},[r,T.minZoom,T.maxZoom]),Y=T.renderSelectedNodeToolbar,H=p.length>0&&!!Y,ve=j.useMemo(()=>H?p.map(Ne=>{var st;return{...((st=$.get(Ne))==null?void 0:st.data)??{id:Ne},isParent:W.has(Ne)}}):[],[H,p,$,W]),J=j.useCallback(()=>{var Ne;m([]),(Ne=P.onNodeDeselect)==null||Ne.call(P)},[m,P]),be=T.renderSelectedEdgeToolbar,Q=!!y&&!!be,je=j.useMemo(()=>{var Ne;return!Q||!y?null:((Ne=M.get(y))==null?void 0:Ne.data)??{id:y}},[Q,y,M]),Pe=j.useCallback(()=>{var Ne;g(null),(Ne=P.onEdgeDeselect)==null||Ne.call(P)},[g,P]),qe=T.selectionToolbar!==!1&&!N,Xe=qe&&!!y&&!be,Be=qe&&!Xe&&p.length>0&&!Y,ut=Xe||Be,De=A||ge||ce||ut||T.bottomBarCollapsed===!1;j.useEffect(()=>{p.length||y?a(!1):N||(s&&R(!0),T.bottomBarCollapsed===void 0&&ue(!s))},[s,p.length,y,N,a,R,T.bottomBarCollapsed]);const rt=T.renderBottomBar,pt=ow();return rt?f.jsxs(f.Fragment,{children:[H&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Y({selectedNodeIds:p,selectedNodeData:ve,onDeselect:J})}),Q&&je&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:be({edgeId:y,edgeData:je,onDeselect:Pe})}),f.jsx(V.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:rt({zoomIn:()=>he("increase"),zoomOut:()=>he("decrease"),resetZoom:()=>he("reset"),direction:c,isZoomMode:v,setIsZoomMode:b,isMultiSelectMode:x,setIsMultiSelectMode:w,isDragMode:C,setIsDragMode:S,isEdgeHandlesEnabled:_,setIsEdgeHandlesEnabled:I,isArrayNodeMode:E,setIsArrayNodeMode:O,selectedNodeIds:p,selectedNodeData:ve,selectedEdgeId:y,selectedEdgeData:je,onNodeDeselect:J,onEdgeDeselect:Pe,callbacks:P})})]}):f.jsxs(Wr.Provider,{value:pt,children:[H&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:Y({selectedNodeIds:p,selectedNodeData:ve,onDeselect:J})}),Q&&je&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:be({edgeId:y,edgeData:je,onDeselect:Pe})}),f.jsx(V.Box,{ref:Ce,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:{"& button > svg:not([popover] *)":{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",flexShrink:0},"@media (hover: none)":{visibility:"visible",opacity:1,transform:"none",pointerEvents:"auto"}},children:f.jsxs(V.Flex,{w:"100%",px:5,position:"absolute",bottom:"calc(20px + env(safe-area-inset-bottom, 0px))",flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:"24px",css:{"@media (min-width: 1024px)":{"& > :first-of-type":{maxWidth:"50vw"}}},children:[f.jsx(Nd,{background:se,border:ae?re:"gray.300",children:f.jsxs(V.HStack,{px:2,gap:1,flexWrap:"nowrap",w:"max-content",minW:"100%",h:"100%",css:{"& > *":{flexShrink:0}},children:[Xe?f.jsx(xb,{edgeId:y,onClose:Pe}):Be?f.jsx(Cb,{ids:p,onClose:J}):null,f.jsxs("div",{style:{display:Xe||Be?"none":"contents"},children:[f.jsxs("span",{style:{display:T.bottomBarNavigation===!1?"none":"contents"},children:[f.jsx(Ke,{label:A?"Unpin":"Pin",children:f.jsx(Oe,{"aria-label":"Pin",icon:f.jsx(V.Icon,{as:A?Z.PiPushPinFill:Z.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:A?t:ye,onClick:()=>{R(!A),X(!1)}})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ke,{label:"Zoom Out",children:f.jsx(Oe,{"aria-label":"Zoom out",rememberAction:!1,icon:f.jsx(V.Icon,{as:Z.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:me,onClick:()=>he("decrease")})}),f.jsx(Ke,{label:"Zoom In",children:f.jsx(Oe,{"aria-label":"Zoom in",rememberAction:!1,icon:f.jsx(V.Icon,{as:Z.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:me,onClick:()=>he("increase")})}),f.jsx(Ke,{label:"Reset Zoom",children:f.jsx(Oe,{"aria-label":"Reset zoom",rememberAction:!1,icon:f.jsx(V.Icon,{as:Z.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:me,onClick:()=>he("reset")})}),xe&&f.jsx(iw,{visibleActions:h?["Collision mode","Fill",...h.fill?["Grid adjustment"]:[]]:[],divider:f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"})})]}),f.jsxs("span",{style:{display:xe?"none":"contents"},children:[f.jsxs("span",{style:{display:T.bottomBarNavigation===!1?"none":"contents"},children:[T.edgeHandles!==!1&&f.jsx(Ke,{label:_?"Draw Mode On (V)":"Draw Mode Off (V)",children:f.jsx(Oe,{"aria-label":"Toggle draw mode","aria-keyshortcuts":"V","aria-pressed":_,icon:f.jsx(V.Icon,{as:Z.PiPencilSimpleLine,boxSize:5}),size:"sm",variant:"ghost",color:_?t:ye,onClick:()=>I(!_)})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ke,{label:v?"Zoom Mode (z)":"Pan Mode (z)",children:f.jsx(Oe,{"aria-label":"Toggle zoom mode",icon:f.jsx(V.Icon,{as:v?Z.PiMagnifyingGlassPlus:Z.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:v?t:ye,onClick:()=>b(!v)})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ke,{label:x?"Multi-Select On (m)":"Multi-Select Off (m)",children:f.jsx(Oe,{"aria-label":"Toggle multi-select",icon:f.jsx(V.Icon,{as:Z.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:x?t:ye,onClick:()=>w(!x)})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ke,{label:C?"Drag Mode On (d)":"Drag Mode Off (d)",children:f.jsx(Oe,{"aria-label":"Toggle drag mode",icon:f.jsx(V.Icon,{as:Z.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:C?t:ye,onClick:()=>S(!C)})})]}),T.bottomBarNavigation===!1&&(e===void 0?f.jsx(Fo,{}):e?Dr.createPortal(f.jsx(Fo,{}),e):null),T.bottomBarExtra&&f.jsxs(f.Fragment,{children:[T.bottomBarNavigation!==!1&&f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"}),T.bottomBarExtra]}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"}),f.jsx(eb,{})]}),f.jsx("span",{style:{display:T.bottomBarNavigation===!1||xe&&!h?"none":"contents"},children:f.jsx(Fo,{})}),f.jsxs("span",{style:{display:xe?"none":"contents"},children:[f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"}),f.jsx(Qm,{}),l!=="properties"&&f.jsxs(f.Fragment,{children:[f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ke,{label:E?"Array Mode [ ]":"Set Mode { }",children:f.jsx(Oe,{"aria-label":"Toggle array mode",icon:f.jsx(V.Icon,{as:E?Z.PiBracketsSquare:Z.PiBracketsCurly,boxSize:5}),size:"sm",variant:"ghost",color:E?t:ye,onClick:()=>{var Ge;const Ne=!E;O(Ne),(Ge=P.onArrayModeChange)==null||Ge.call(P,Ne)}})})]}),f.jsx($d,{}),!N&&f.jsxs("span",{style:{display:s?"contents":"none"},children:[f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ar,{label:"Graph theme",colors:ro,value:t,includeTransparent:!1,onPick:Ne=>{var Ge;n(Ne),(Ge=P.onThemeColorChange)==null||Ge.call(P,Ne)}})]}),!N&&f.jsxs(f.Fragment,{children:[f.jsx(V.Icon,{as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"}),f.jsx(Ar,{label:"Graph edge color",colors:ro,value:o||(ae?"gray.500":Jr),onPick:i,onReset:()=>i("")}),f.jsx(V.Icon,{as:Z.PiLineVerticalThin,boxSize:5,color:z,role:"separator","aria-orientation":"vertical"})]}),f.jsx(tb,{})]}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:z}),f.jsx(Ke,{label:xe?"Expand toolbar":"Collapse toolbar",children:f.jsx(Oe,{"aria-label":"Toggle toolbar collapse",rememberAction:!1,icon:f.jsx(V.Icon,{as:xe?Z.PiCaretRight:Z.PiCaretLeft,boxSize:5}),size:"sm",variant:"ghost",color:ye,onClick:()=>{var Ne;T.bottomBarCollapsed===void 0&&ue(!xe),a(xe),(Ne=P.onBottomBarCollapsedChange)==null||Ne.call(P,!xe)}})}),!xe&&f.jsx(_b,{})]})]})}),!ut&&f.jsxs(V.Box,{position:"relative",ml:"auto",flexShrink:0,children:[f.jsx(V.Box,{"data-flow-direction-control":"",bg:se,borderRadius:"30px",h:50,css:hr(U,B),px:3,cursor:"pointer",onClick:()=>X(!ce),children:f.jsxs(V.Flex,{align:"center",h:"100%",children:[f.jsx(Ke,{label:"Flow Direction",children:f.jsx(Oe,{"aria-label":"Direction",onClick:Ne=>{Ne.stopPropagation(),X(!ce)},icon:f.jsx(V.Icon,{as:Z.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:ye})}),f.jsx(V.Text,{fontSize:"xs",textTransform:"uppercase !important",color:ae?"whiteAlpha.600":"blackAlpha.500",ml:1,children:c.toUpperCase()})]})}),ce&&f.jsx(V.Box,{position:"absolute",bottom:"100%",right:0,pb:"24px",zIndex:200,children:f.jsxs(V.Box,{bg:se,borderRadius:"30px",p:2,minW:"180px",css:hr(U,B),children:[Pw.map(Ne=>f.jsxs(V.Flex,{align:"center",gap:3,px:3,py:2,css:to,cursor:"pointer",_hover:{bg:ae?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ge;(Ge=P.onDirectionChange)==null||Ge.call(P,Ne.value),X(!1)},children:[f.jsx(V.Icon,{as:Ne.icon,boxSize:5,color:me}),f.jsx(V.Text,{fontSize:"sm",color:me,flex:1,whiteSpace:"nowrap",children:Ne.label}),c===Ne.value&&f.jsx(V.Icon,{as:Z.PiCheck,boxSize:4,color:L})]},Ne.value)),f.jsxs(V.Flex,{align:"center",gap:3,px:3,py:2,css:to,cursor:"pointer",_hover:{bg:ae?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ne;(Ne=P.onDirectionChange)==null||Ne.call(P,"C"),X(!1)},children:[f.jsx(V.Icon,{as:Z.PiAlignCenterHorizontal,boxSize:5,color:me}),f.jsx(V.Text,{fontSize:"sm",color:me,flex:1,whiteSpace:"nowrap",children:"Center"}),c==="C"&&f.jsx(V.Icon,{as:Z.PiCheck,boxSize:4,color:L})]})]})})]})]})})]})};kb.displayName="BottomBar";const Rb=j.memo(kb);function Mw({checked:e,onChange:r,disabled:t,label:n="Connected nodes"}){return f.jsx(Gr,{hideLabel:!0,label:n,helper:`${n}: isolate node and its connections`,checked:e,onChange:r,disabled:t,icon:f.jsx(V.Icon,{as:Z.PiGraph,boxSize:5})})}const Fu={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function Ab(e,r){const t=new Map,n=(i,s)=>{if(Object.is(i,s))return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const a=Object.keys(i);return a.length===Object.keys(s).length&&a.every(c=>Object.prototype.hasOwnProperty.call(s,c)&&n(i[c],s[c]))},o=(i,s,a)=>{if(i===s)return!0;if(!i||!s||typeof i!="object"||typeof s!="object"||Array.isArray(i)!==Array.isArray(s))return!1;const c=new Set([...Object.keys(i),...Object.keys(s)]);for(const l of c)if(!n(i[l],s[l])){if(Object.prototype.hasOwnProperty.call(Fu,l)){if(typeof s[l]!="string"||!s[l])return!1;t.set(a,{...t.get(a),[Fu[l]]:s[l]})}else if(l.startsWith("$")&&l!=="$"||!o(i[l],s[l],l==="$"?a:`${a}.${l}`))return!1}return!0};if(o(e,r,"root"))return t}function Iw(e,r){return Ab(e,r)!==void 0}function Tw(e,r,t){if(e===r)return t;const n=Ab(e,r);if(!n)return;const o=new Set(t.nodes.map(i=>i.data.id));for(const i of n.keys())if(!o.has(i)||!Fe(r,i))return;return{edges:t.edges,nodes:t.nodes.map(i=>{const s=n.get(i.data.id),a=Fe(e,i.data.id),c=Fe(r,i.data.id);return!s&&a===c?i:{...i,data:{...i.data,...typeof i.data.code=="string"?{code:JSON.stringify(c,null,2)}:{},...s?{viewProps:{...i.data.viewProps,...s},config:{...i.data.config,...s}}:{}}}})}}function pd(e){return e.kind==="literal"?e.value:e.kind==="union"?pd(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,r])=>!r.optional).map(([r,t])=>[r,pd(t.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Pb(e,r,t){var g,v,b;const n=(g=Fe(e,r))==null?void 0:g.$form,o=n==null?void 0:n.$create;if(!o)return;const i=o.$address.split(".");if(i.shift()!=="root"||!i.length||i.some(x=>!/^[A-Za-z0-9_-]+$/.test(x)||["__proto__","constructor","prototype"].includes(x)))throw new Error("Invalid form creation address.");if(!t||!Object.prototype.hasOwnProperty.call(t,o.$type))throw new Error(`Load form type: ${o.$type}`);const s=i.pop(),a=["root",...i].join("."),c=Yr(e,a,t),l=(v=c==null?void 0:c.type.properties[s])==null?void 0:v.type;if((l==null?void 0:l.kind)!=="array"||l.items.kind!=="object")throw new Error("Form creation must target an object-array field.");const d=t[o.$type],u=o.$defaults??{};for(const[x,w]of Object.entries(u))if(!Object.prototype.hasOwnProperty.call(d.properties,x)||Vt(d.properties[x].type,w,!d.properties[x].optional))throw new Error(`Invalid creation default: ${x}`);const h={...pd(d),...structuredClone(u)};((b=d.properties.id)==null?void 0:b.type.kind)==="string"&&(h.id=Sd());let p=e;const m=Fe(e,o.$address);if(m===void 0)p=jt(e,a,x=>({...x,[s]:[]}));else if(!Array.isArray(m)&&!Array.isArray(m==null?void 0:m.$))throw new Error("Form creation destination is not an array.");const y=kd(p,o.$address,{...h,$label:o.$label??o.$type,...o.$icon?{$icon:o.$icon}:{},$form:{$type:o.$type,$create:o}});return{address:y.address,json:Rd(y.json,r,{target:y.address,label:o.$edgeLabel})}}function Mb(e,r,t){var i;if(r==="root"||!Fe(e,r)||!Fe(e,t))throw new Error("The source or Parent no longer exists.");const n=new Set;let o=t;for(;o;){if(o===r||o.startsWith(`${r}.`)||n.has(o))throw new Error("A node cannot be moved inside itself or its descendants.");n.add(o);const s=(i=Fe(e,o))==null?void 0:i.$parent;o=typeof s=="string"?s:o.includes(".")?o.slice(0,o.lastIndexOf(".")):void 0}return Ed(jt(e,r,s=>({...s,$parent:t})),t,!1)}function Ib(e,r){const t=new Set(r.filter(a=>Fe(e,a)!==void 0)),n=[],o=(a,c)=>{if(!(!a||typeof a!="object")){n.push([c,a]);for(const[l,d]of Object.entries(a))l.startsWith("$")||o(d,`${c}.${l}`)}};o(e,"root");const i=a=>[...t].some(c=>a===c||a.startsWith(`${c}.`));let s=!0;for(;s;){s=!1;for(const[a,c]of n)!i(a)&&typeof c.$parent=="string"&&i(c.$parent)&&(t.add(a),s=!0)}return[...t].filter(a=>![...t].some(c=>c!==a&&a.startsWith(`${c}.`)))}function qd(e,r){const t=Ib(e,r),n=new Map(t.map((a,c)=>[a,`root.node_${c+1}`])),o=a=>{const c=t.find(l=>a===l||a.startsWith(`${l}.`));return c?`${n.get(c)}${a.slice(c.length)}`:void 0},i=a=>{if(!(!a||typeof a!="object")){Array.isArray(a.$connections)&&(a.$connections=a.$connections.flatMap(c=>{const l=typeof c.target=="string"&&o(c.target);return l?[{...c,id:void 0,target:l}]:[]}));for(const c of["$parent","$target"])if(typeof a[c]=="string"){const l=o(a[c]);l?a[c]=l:delete a[c]}for(const[c,l]of Object.entries(a))c.startsWith("$")||i(l)}},s={$hideRoot:!0};return t.forEach((a,c)=>{const l=structuredClone(Fe(e,a));i(l),s[`node_${c+1}`]=l}),s}function Tb(e,r){const t=qd(e,r),n=Object.keys(t).filter(a=>!a.startsWith("$")),o=new Map(n.map(a=>[a,`copy_${crypto.randomUUID()}`])),i=a=>{if(!a||typeof a!="object")return;const c=l=>{const d=l.split(".");return d[0]==="root"&&o.has(d[1])&&(d[1]=o.get(d[1])),d.join(".")};for(const l of a.$connections??[])l.target=c(l.target),l.id=crypto.randomUUID();for(const l of["$parent","$target"])typeof a[l]=="string"&&(a[l]=c(a[l]));for(const[l,d]of Object.entries(a))l.startsWith("$")||i(d)},s=Object.fromEntries(n.map(a=>{const c=t[a];return i(c),[o.get(a),c]}));return{json:jt(e,"root",a=>({...a,...s})),ids:[...o.values()].map(a=>`root.${a}`)}}function Ow(e,r){const t=o=>e&&typeof e=="object"&&o in e;let n=1;for(;t(`${r}_${n}`);)n++;return`${r}_${n}`}function Ob(e,r,t,n,o){const i=(a,c)=>{a!==e&&(e=a,n==null||n(a,c))},s=a=>{var l;const c=(l=r.find(d=>d.data.id===a))==null?void 0:l.data;return c&&{source:c.source,target:c.target,isInverted:c.isInverted,sourceProperty:c.sourceProperty,targetProperty:c.targetProperty,connection:c.connection}};return{...t,onNodeParentChange:(a,c)=>{var d;const l=Mb(e,a,c);(d=t.onNodeParentChange)==null||d.call(t,a,c),i(l,{type:"nodeStyle",address:a,key:"$parent",value:c})},onNodesCopy:async a=>{var c;await((c=t.onNodesCopy)==null?void 0:c.call(t,a))!==!0&&await navigator.clipboard.writeText(JSON.stringify(qd(e,a),null,2))},onNodesDuplicate:a=>{var l;if(((l=t.onNodesDuplicate)==null?void 0:l.call(t,a))===!0)return;const c=Tb(e,a);i(c.json,{type:"nodeCreate",address:c.ids[0]})},onFormChange:a=>{const c=Fe(e,a.nodeAddress);if(!c||a.nodeId!==void 0&&c.id!==a.nodeId)throw new Error("This form node has moved. Retry the edit.");i(ho(e,a,t.onFormChange),{type:"form",address:a.address,value:a.value})},onNodeLabelChange:(a,c)=>{var l;(l=t.onNodeLabelChange)==null||l.call(t,a,c),i(wt(e,a,"$label",c),{type:"nodeLabel",address:a,key:"$label",value:c})},onNodeSubtitleChange:(a,c)=>{var l;(l=t.onNodeSubtitleChange)==null||l.call(t,a,c),i(wt(e,a,"$subtitle",c),{type:"nodeStyle",address:a,key:"$subtitle",value:c})},onNodeContentChange:(a,c)=>{var l;(l=t.onNodeContentChange)==null||l.call(t,a,c),i(wt(e,a,"$content",c),{type:"nodeContent",address:a,key:"$content",value:c})},onNodeTypeViewChange:(a,c)=>{var l;c!==void 0&&!xd.includes(c)||((l=t.onNodeTypeViewChange)==null||l.call(t,a,c),i(wt(e,a,"$view",c),{type:"nodeStyle",address:a,key:"$view",value:c}))},onNodeColorChange:(a,c,l)=>{var u;(u=t.onNodeColorChange)==null||u.call(t,a,c,l);const d=c==="bg"?"$bgColor":"$textColor";i(wt(e,a,d,l),{type:"nodeColor",address:a,key:d,value:l})},onNodeBorderColorChange:(a,c)=>{var l;(l=t.onNodeBorderColorChange)==null||l.call(t,a,c),i(wt(e,a,"$borderColor",c),{type:"nodeColor",address:a,key:"$borderColor",value:c})},onNodeBorderStyleChange:(a,c)=>{var l;(l=t.onNodeBorderStyleChange)==null||l.call(t,a,c),i(wt(e,a,"$borderStyle",c),{type:"nodeStyle",address:a,key:"$borderStyle",value:c})},onNodeBorderWidthChange:(a,c)=>{var l;c!==void 0&&(!Number.isFinite(c)||c<0)||((l=t.onNodeBorderWidthChange)==null||l.call(t,a,c),i(wt(e,a,"$borderWidth",c),{type:"nodeStyle",address:a,key:"$borderWidth",value:c}))},onNodeBorderRadiusChange:(a,c)=>{var l;c!==void 0&&(!Number.isFinite(c)||c<0)||((l=t.onNodeBorderRadiusChange)==null||l.call(t,a,c),i(wt(e,a,"$borderRadius",c),{type:"nodeStyle",address:a,key:"$borderRadius",value:c}))},onNodeIconChange:(a,c)=>{var l;(l=t.onNodeIconChange)==null||l.call(t,a,c),i(wt(e,a,"$icon",c),{type:"nodeIcon",address:a,key:"$icon",value:c})},onNodeOutlineChange:(a,c)=>{var l;(l=t.onNodeOutlineChange)==null||l.call(t,a,c),i(wt(e,a,"$outline",c),{type:"nodeOutline",address:a,key:"$outline",value:c})},onNodeAnimationChange:(a,c)=>{var l;(l=t.onNodeAnimationChange)==null||l.call(t,a,c),i(wt(e,a,"$isNodeAnimated",c),{type:"nodeAnimation",address:a,key:"$isNodeAnimated",value:c})},onNodeAnimationVariantChange:(a,c)=>{var l;c!=="traveling"&&c!=="pulse"||((l=t.onNodeAnimationVariantChange)==null||l.call(t,a,c),i(wt(e,a,"$nodeAnimationVariant",c),{type:"nodeAnimation",address:a,key:"$nodeAnimationVariant",value:c}))},onNodeCollapse:(a,c)=>{var l;(l=t.onNodeCollapse)==null||l.call(t,a,c),i(Ed(e,a,c),{type:"nodeCollapse",address:a,key:"$collapsed",value:c})},onNodeCreate:a=>{var p,m;if(((p=t.onNodeCreate)==null?void 0:p.call(t,a))===!0)return;const c=a.sourceNodeId||"root",l=!!a.sourceNodeId&&a.isArrayMode&&!((m=Fe(e,c))!=null&&m.$arrayDrawInitialized);let d=e,u,h=a.isArrayMode?"array":"set";for(let y=0;y<(l?2:1);y++){const g=a.sourceNodeId&&Pb(d,a.sourceNodeId,o);if(g)d=g.json,u??(u=g.address),h="form";else{const v=Ow(Fe(d,c),a.isArrayMode?"list":"node"),b=a.isArrayMode?{$bgColor:"gray.500",$:[]}:{$bgColor:"gray.500"},x=kd(d,c,b,v);d=x.json,u??(u=x.address)}}l&&(d=jt(d,c,y=>Array.isArray(y)?{$:y,$arrayDrawInitialized:!0}:{...y,$arrayDrawInitialized:!0})),i(d,{type:"nodeCreate",address:u,value:h})},onNodeDelete:(a,c)=>{var l;(l=t.onNodeDelete)==null||l.call(t,a,c),i(cb(e,a),{type:"nodeDelete",address:a})},onEdgeCreate:(a,c,l)=>{var u;(u=t.onEdgeCreate)==null||u.call(t,a,c,l);const d=l&&(l.sourceProperty!==void 0||l.targetProperty!==void 0)?{...l,target:c}:void 0;i(d?Rd(e,a,d):lb(e,a,c),{type:"edgeCreate",address:a,key:d?"$connections":"$target",value:d??c})},onEdgeLabelChange:(a,c)=>{var d;(d=t.onEdgeLabelChange)==null||d.call(t,a,c);const l=s(a);l&&i(lr(e,l,"$sourceLabel",c),{type:"edgeLabel",edge:l,key:l.connection?"$connections":"$sourceLabel",value:c})},onEdgeStyleChange:(a,c)=>{var d;(d=t.onEdgeStyleChange)==null||d.call(t,a,c);const l=s(a);l&&i(sb(e,l,c),{type:"edgeStyle",edge:l,value:c})},onEdgeAnimationVariantChange:(a,c)=>{var d;if(c!=="dashed"&&c!=="traveling")return;(d=t.onEdgeAnimationVariantChange)==null||d.call(t,a,c);const l=s(a);l&&i(lr(e,l,"$edgeAnimationVariant",c),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeAnimationVariant",value:c})},onEdgeTypeChange:(a,c)=>{var d;(d=t.onEdgeTypeChange)==null||d.call(t,a,c);const l=s(a);l&&i(lr(e,l,"$edgeType",c),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeType",value:c})},onEdgeIconChange:(a,c)=>{var d;(d=t.onEdgeIconChange)==null||d.call(t,a,c);const l=s(a);l&&i(lr(e,l,"$edgeIcon",c||void 0),{type:"edgeStyle",edge:l,key:l.connection?"$connections":"$edgeIcon",value:c})},onEdgeColorChange:(a,c)=>{var d;(d=t.onEdgeColorChange)==null||d.call(t,a,c);const l=s(a);l&&i(lr(e,l,"$edgeColor",c),{type:"edgeColor",edge:l,key:l.connection?"$connections":"$edgeColor",value:c})},onEdgeDelete:(a,c)=>{var u;(u=t.onEdgeDelete)==null||u.call(t,a,c);const l=s(a);if(!l)return;const d=db(e,l);d.removed&&i(d.json,{type:"edgeDelete",edge:l,key:l.connection?"$connections":"$target"})}}}const Nw=".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 $w({path:e,width:r,reversed:t,children:n,onComplete:o}){const i=`flow-edge-reveal-${j.useId().replace(/:/g,"")}`,s=j.useRef(null),[a,c]=j.useState({x:0,y:0,width:1,height:1});return j.useEffect(()=>{const l=matchMedia("(prefers-reduced-motion: reduce)"),d=()=>{l.matches&&(o==null||o())};return d(),l.addEventListener("change",d),()=>l.removeEventListener("change",d)},[o]),j.useLayoutEffect(()=>{var d;const l=(d=s.current)==null?void 0:d.getBBox();l&&c({x:l.x-r,y:l.y-r,width:l.width+r*2,height:l.height+r*2})},[e,r]),f.jsxs(f.Fragment,{children:[f.jsx("defs",{children:f.jsx("mask",{id:i,maskUnits:"userSpaceOnUse",...a,children:f.jsx("path",{ref:s,className:"flow-sdk-edge-reveal",onAnimationEnd:l=>{l.animationName==="flow-sdk-edge-reveal"&&(o==null||o())},"data-reveal-direction":t?"reverse":"forward",style:{"--flow-edge-reveal-from":t?-100:100},d:e,fill:"none",stroke:"white",strokeWidth:r,strokeLinecap:"butt",strokeLinejoin:"round",pathLength:100,strokeDasharray:"100 100"})})}),f.jsx("g",{mask:`url(#${i})`,children:n})]})}const qw=".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 Lw({path:e,color:r,width:t,reversed:n}){return f.jsx("path",{className:`flow-sdk-edge-trace${n?" flow-sdk-edge-trace-reverse":""}`,"data-animation-variant":"traveling","aria-hidden":"true",pointerEvents:"none",d:e,fill:"none",stroke:r,strokeWidth:t,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 100"})}const Nb=".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 no({x:e=0,y:r=0,width:t,height:n,radius:o,color:i,strokeWidth:s=8,path:a,variant:c="traveling"}){const l=j.useId(),d=`flow-sdk-node-border-animation${c==="pulse"?" flow-sdk-node-border-pulse":""}`;if(c==="pulse"){const u=a?"path":"rect",h=a?{d:a}:{x:e,y:r,width:Math.max(0,t),height:Math.max(0,n),rx:Math.max(0,Math.min(o,t/2,n/2))},p=s+36,m={x:e-p,y:r-p,width:t+2*p,height:n+2*p};return f.jsxs("g",{"aria-hidden":"true",pointerEvents:"none",children:[f.jsx("defs",{children:f.jsxs("mask",{id:l,maskUnits:"userSpaceOnUse",...m,style:{maskType:"luminance"},children:[f.jsx("rect",{...m,fill:"white"}),f.jsx(u,{...h,fill:"black",stroke:"black",strokeWidth:s,strokeLinejoin:"round"})]})}),f.jsx(u,{...h,className:d,"data-animation-variant":c,fill:"none",stroke:`color-mix(in srgb, ${i} 30%, transparent)`,strokeLinejoin:"round",mask:`url(#${l})`,style:{"--flow-pulse-rest-width":`${s+16}px`,"--flow-pulse-expanded-width":`${s+36}px`}})]})}return a?f.jsx("path",{className:d,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",d:a,fill:"none",stroke:i,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"}):f.jsx("rect",{className:d,"data-animation-variant":c,"aria-hidden":"true",pointerEvents:"none",x:e,y:r,width:Math.max(0,t),height:Math.max(0,n),rx:Math.max(0,Math.min(o,t/2,n/2)),fill:"none",stroke:i,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const Fw=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 $b(e,r=!1){return e&&!r&&typeof requestAnimationFrame<"u"&&!(typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches)}function qb(e,r,t=()=>{},n=300){let o,i,s=!1;const a=()=>{s=!0,o!==void 0&&cancelAnimationFrame(o),clearTimeout(i)},c=()=>{s||(a(),r(1),t())};if(!$b(e))return c(),a;const l=performance.now(),d=u=>{if(s)return;const h=Math.max(0,Math.min(1,(u-l)/n));if(h>=1)return c();r(h<.5?4*h**3:1-(-2*h+2)**3/2),s||(o=requestAnimationFrame(d))};return o=requestAnimationFrame(d),i=setTimeout(c,n+100),a}function zu(e,r,t){const n=new Set([e]),o=[e];for(;o.length;){const i=o.pop();for(const s of r)(s.parent===i||s.id.startsWith(`${i}.`)||t.some(c=>(c.inverted?c.target:c.source)===i&&(c.inverted?c.source:c.target)===s.id))&&!n.has(s.id)&&(n.add(s.id),o.push(s.id))}return n}function zw(e,r,t){const n=t==="downward"||t==="upward",o=new Map;for(const s of e){if(s.source===s.target||s.sourceProperty||s.targetProperty)continue;const a=r(s.source),c=r(s.target);if(!a||!c)continue;const l=n?c.y-a.y:c.x-a.x,d=Math.abs(l)-(n?a.h+c.h:a.w+c.w)/2;if(d<=320)continue;const u=JSON.stringify([s.source,Math.sign(l)]),h=o.get(u)??[];h.push({edge:s,gap:d,cross:n?c.x-a.x:c.y-a.y}),o.set(u,h)}const i=new Map;for(const s of o.values()){if(new Set(s.map(({edge:c})=>c.target)).size<2)continue;const a=new Map;for(const{edge:c}of s)a.set(c.target,(a.get(c.target)??0)+1);for(const c of[-1,0,1]){const l=s.filter(({cross:u})=>Math.sign(u)===c);l.sort((u,h)=>Math.abs(h.cross)-Math.abs(u.cross)||u.edge.id.localeCompare(h.edge.id));const d=Math.min(...l.map(({gap:u})=>u));l.forEach(({edge:u,gap:h,cross:p},m)=>{const y=l.length===1?d/2:120+(d-280)*m/(l.length-1),g=l.find(v=>Math.abs(v.cross)<Math.abs(p));i.set(u.id,{turn:y/h,labelAtTarget:a.get(u.target)===1,labelFraction:p?(p+((g==null?void 0:g.cross)??0))/(2*p):.5})})}}return i}const Jt=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}),Bw=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function Do(e){if(!e.length)return null;const r={...e[0]};for(let t=1;t<e.length;t++)r.x1=Math.min(r.x1,e[t].x1),r.y1=Math.min(r.y1,e[t].y1),r.x2=Math.max(r.x2,e[t].x2),r.y2=Math.max(r.y2,e[t].y2);return r}const Dw=(e,r)=>e.x1<=r.x2&&e.x2>=r.x1&&e.y1<=r.y2&&e.y2>=r.y1,Bu=(e,r)=>e.x>=r.x1&&e.x<=r.x2&&e.y>=r.y1&&e.y<=r.y2,$t=e=>(Math.round(e*10)/10).toString(),ft=e=>`${$t(e.x)} ${$t(e.y)}`,Vw=e=>e>0?1:e<0?-1:0,Du=(e,r)=>e>0?Math.max(e-r,0):Math.min(e+r,0);function Ww(e,r,t,n,o=10){const i=r.x-e.x,s=r.y-e.y,a=Du(i,(e.w+r.w)/2),c=Du(s,(e.h+r.h)/2),l=t==="downward"||t==="upward",d=l?c:a,u=l?s:i,h=Vw(u),p=n*d,m=b=>Math.abs(b)<o||Math.abs(b)>=Math.abs(d),y=m(p)||m(Math.abs(d)-Math.abs(p));let g;if(y)if(l)if(Math.abs(u)<=e.h/2){const b=(e.x+r.x)/2;g=[b,e.y,b,r.y]}else if(Math.abs(i)<=r.w/2){const b=(e.y+r.y)/2;g=[e.x,b,r.x,b]}else g=[e.x,r.y];else if(Math.abs(u)<=e.w/2){const b=(e.y+r.y)/2;g=[e.x,b,r.x,b]}else if(Math.abs(s)<=r.h/2){const b=(e.x+r.x)/2;g=[b,e.y,b,r.y]}else g=[r.x,e.y];else if(l){const b=e.y+p+e.h/2*h;g=[e.x,b,r.x,b]}else{const b=e.x+p+e.w/2*h;g=[b,e.y,b,r.y]}const v=[{x:e.x,y:e.y}];for(let b=0;b<g.length;b+=2)v.push({x:g[b],y:g[b+1]});return v.push({x:r.x,y:r.y}),v}function Gw(e,r,t){const n=r.x-e.x,o=r.y-e.y,i=n>0?(t.x2-e.x)/n:n<0?(t.x1-e.x)/n:1/0,s=o>0?(t.y2-e.y)/o:o<0?(t.y1-e.y)/o:1/0,a=Math.min(i,s);return!Number.isFinite(a)||a>=1||a<0?null:{x:e.x+n*a,y:e.y+o*a}}function Hr(e,r,t){var s;if(!((s=t.outline)!=null&&s.length))return Gw(e,r,Jt(t));const n=r.x-e.x,o=r.y-e.y;let i=1/0;return t.outline.forEach((a,c,l)=>{const d=l[(c+1)%l.length],u=d.x-a.x,h=d.y-a.y,p=n*h-o*u;if(Math.abs(p)<1e-9)return;const m=a.x-e.x,y=a.y-e.y,g=(m*h-y*u)/p,v=(m*o-y*n)/p;g>=0&&g<1&&v>=-1e-9&&v<=1+1e-9&&(i=Math.min(i,g))}),Number.isFinite(i)?{x:e.x+n*i,y:e.y+o*i}:null}function Lb(e,r,t=.5){const n=Number.isFinite(t)?Math.max(0,Math.min(1,t)):.5,o=r==="top"||r==="bottom",i=r==="top"||r==="left"?-1:1,s={x:o?e.x-e.w/2+e.w*n:e.x,y:o?e.y:e.y-e.h/2+e.h*n},a=Math.max(e.w,e.h)*2+1;return{...Hr(s,{x:s.x+(o?0:i*a),y:s.y+(o?i*a:0)},e)??{x:o?s.x:e.x+i*e.w/2,y:o?e.y+i*e.h/2:s.y},side:r}}function Lr(e,r){return{x:e.x+(e.side==="right"?r:e.side==="left"?-r:0),y:e.y+(e.side==="bottom"?r:e.side==="top"?-r:0)}}function Uw(e,r,t,n){const o=Lr(e,t.srcDist),i=Lr(r,t.tgtDist);if(n==="straight")return zb(o,i,t);const s=Math.max(80,Math.min(300,Math.hypot(i.x-o.x,i.y-o.y)/3)),a=e.side==="bottom"&&r.side==="top"?i.y-o.y:e.side==="top"&&r.side==="bottom"?o.y-i.y:e.side==="right"&&r.side==="left"?i.x-o.x:e.side==="left"&&r.side==="right"?o.x-i.x:void 0,c=a!==void 0&&a>0?Math.min(s,a/2):s,l=Lr({...o,side:e.side},c),d=Lr({...i,side:r.side},c),u=t.arrowAt==="source"?bt(o,l,t.arrowGap):o,h=t.arrowAt==="target"?bt(i,d,t.arrowGap):i,p=t.arrowAt==="source"?Lt(o,l,t.arrowSize,t.headShape):t.arrowAt==="target"?Lt(i,d,t.arrowSize,t.headShape):void 0;if(n==="bezier")return{d:`M${ft(u)} C${ft(l)} ${ft(d)} ${ft(h)}`,arrow:p,label:{x:(u.x+3*l.x+3*d.x+h.x)/8,y:(u.y+3*l.y+3*d.y+h.y)/8,angle:0}};const m=e.side==="left"||e.side==="right",y=r.side==="left"||r.side==="right";let g;if(m!==y){const b=m?{x:d.x,y:l.y}:{x:l.x,y:d.y},x=(b.x-l.x)*(l.x-o.x)+(b.y-l.y)*(l.y-o.y)>=0,w=(b.x-d.x)*(d.x-i.x)+(b.y-d.y)*(d.y-i.y)>=0;g=[x&&w?b:m?{x:l.x,y:d.y}:{x:d.x,y:l.y}]}else if(a!==void 0&&a<=0)if(m){const b=(l.y+d.y)/2;g=[{x:l.x,y:b},{x:d.x,y:b}]}else{const b=(l.x+d.x)/2;g=[{x:b,y:l.y},{x:b,y:d.y}]}else if(m){const b=e.side===r.side?e.side==="right"?Math.max(l.x,d.x):Math.min(l.x,d.x):(l.x+d.x)/2;g=[{x:b,y:l.y},{x:b,y:d.y}]}else{const b=e.side===r.side?e.side==="bottom"?Math.max(l.y,d.y):Math.min(l.y,d.y):(l.y+d.y)/2;g=[{x:l.x,y:b},{x:d.x,y:b}]}const v=[l,...g,d].filter((b,x,w)=>x===0||b.x!==w[x-1].x||b.y!==w[x-1].y);return po(u,v,h,p,n==="orthogonal"?0:t.radius)}function bt(e,r,t){const n=e.x-r.x,o=e.y-r.y,i=Math.hypot(n,o);if(!i)return e;let s=(i-t)/i;return s<0&&(s=1e-5),{x:r.x+s*n,y:r.y+s*o}}function Lt(e,r,t,n="triangle"){const o=e.x-r.x,i=e.y-r.y,s=Math.hypot(o,i)||1,a=o/s,c=i/s,l=(n==="square"?.15:.3)*t,d=.15*t,u=e.x-a*l,h=e.y-c*l;if(n==="square")return`M${ft(e)} L${$t(e.x-c*d)} ${$t(e.y+a*d)} L${$t(u-c*d)} ${$t(h+a*d)} L${$t(u+c*d)} ${$t(h-a*d)} L${$t(e.x+c*d)} ${$t(e.y-a*d)} Z`;const p=[e,{x:u-c*d,y:h+a*d},{x:u+c*d,y:h-a*d}];return p.map((y,g)=>{const v=p[(g+2)%3],b=p[(g+1)%3],x=Math.hypot(v.x-y.x,v.y-y.y),w=Math.hypot(b.x-y.x,b.y-y.y),C={x:(v.x-y.x)/x,y:(v.y-y.y)/x},S={x:(b.x-y.x)/w,y:(b.y-y.y)/w},_=Math.max(-1,Math.min(1,C.x*S.x+C.y*S.y)),I=Math.sqrt((1-_)/(1+_)),E=Math.min(1/I,x/2,w/2);return{start:{x:y.x+C.x*E,y:y.y+C.y*E},end:{x:y.x+S.x*E,y:y.y+S.y*E},radius:E*I}}).map((y,g)=>`${g?"L":"M"}${ft(y.start)} A${$t(y.radius)} ${$t(y.radius)} 0 0 1 ${ft(y.end)}`).join(" ")+" Z"}function cr(e,r){let t=Math.atan(r/e);return e===0&&t<0&&(t=-t),Number.isFinite(t)||(t=0),t*180/Math.PI}function Hw(e,r,t,n){const o={x:r.x-e.x,y:r.y-e.y},i={x:t.x-r.x,y:t.y-r.y},s=Math.hypot(o.x,o.y),a=Math.hypot(i.x,i.y),c=o.x*i.y-o.y*i.x;if(s<1e-6||a<1e-6||Math.abs(c)<1e-6)return{p1:r,b:r,p2:r,r:0};const l=Math.min(n,s/2,a/2);return{p1:{x:r.x-o.x/s*l,y:r.y-o.y/s*l},b:r,p2:{x:r.x+i.x/a*l,y:r.y+i.y/a*l},r:l}}function Fb(e,r,t,n){let o=-1,i=null;for(let m=0;m<e.length-1;m++){const y=Hr(e[m],e[m+1],r);if(y){o=m,i=y;break}}let s=-1,a=null;for(let m=e.length-1;m>0;m--){const y=Hr(e[m],e[m-1],t);if(y){s=m,a=y;break}}if(!i||!a||o>=s)return null;const c=e.slice(o+1,s),l=c[0]??a,d=c[c.length-1]??i;let u,h,p;if(n.arrowAt==="source"){const m=bt(i,l,n.srcDist);u=bt(i,l,n.srcDist+n.arrowGap),p=Lt(m,l,n.arrowSize,n.headShape)}else u=bt(i,l,n.srcDist);if(n.arrowAt==="target"){const m=bt(a,d,n.tgtDist);h=bt(a,d,n.tgtDist+n.arrowGap),p=Lt(m,d,n.arrowSize,n.headShape)}else h=bt(a,d,n.tgtDist);return po(u,c,h,p,n.radius,n.labelTargetLength,n.labelFraction)}function po(e,r,t,n,o,i,s){var h;const a=[e,...r,t],c=[];let l=`M${ft(e)}`;for(let p=1;p<a.length-1;p++){const m=Hw(a[p-1],a[p],a[p+1],o);c.push(m),m.r===0?l+=` L${ft(m.b)}`:l+=` L${ft(m.p1)} Q${ft(m.b)} ${ft(m.p2)}`}l+=` L${ft(t)}`;let d;const u=r.length;if(u===0)d={x:(e.x+t.x)/2,y:(e.y+t.y)/2,angle:cr(t.x-e.x,t.y-e.y)};else if(u%2===0){const p=r[u/2-1],m=r[u/2];d={x:(p.x+m.x)/2,y:(p.y+m.y)/2,angle:cr(m.x-p.x,m.y-p.y)}}else{const p=c[(u-1)/2];if(p.r===0){const m=a[(u-1)/2+2];d={x:p.b.x,y:p.b.y,angle:cr(m.x-p.b.x,m.y-p.b.y)}}else d={x:.25*p.p1.x+.5*p.b.x+.25*p.p2.x,y:.25*p.p1.y+.5*p.b.y+.25*p.p2.y,angle:cr(p.p2.x-p.p1.x,p.p2.y-p.p1.y)}}if(i!==void 0){if(s!==void 0&&c.length===2){const g=c[0].p2,v=c[1].p1,b=Math.hypot(v.x-g.x,v.y-g.y),x=Math.min(.5,i/(2*b)),w=Math.max(x,Math.min(1-x,s));d={x:g.x+(v.x-g.x)*w,y:g.y+(v.y-g.y)*w,angle:cr(v.x-g.x,v.y-g.y)}}const p=((h=c[c.length-1])==null?void 0:h.p2)??e,m=t.x-p.x,y=t.y-p.y;Math.hypot(m,y)>=i&&(d={x:(p.x+t.x)/2,y:(p.y+t.y)/2,angle:cr(m,y)})}return{d:l,arrow:n,label:d}}function Vu(e,r,t,n,o,i,s){const a=t==="leftward"?-1:1,c={x:e.x+a*(e.w/2+s.srcDist),y:n??e.y},l={x:r.x-a*(r.w/2+s.tgtDist),y:o??r.y},d=Math.max(80,s.arrowGap+s.arrowSize*.3),u=c.x+a*d,h=l.x-a*d;let p;if(a*(h-u)>=0){const v=c.x+(l.x-c.x)*i,b=Math.max(Math.min(u,h),Math.min(Math.max(u,h),v));p=[{x:b,y:c.y},{x:b,y:l.y}]}else{const v=Math.min(e.y-e.h/2,r.y-r.h/2)-d*(1+i);p=[{x:u,y:c.y},{x:u,y:v},{x:h,y:v},{x:h,y:l.y}]}const m=s.arrowAt==="source"?bt(c,p[0],s.arrowGap):c,y=s.arrowAt==="target"?bt(l,p[p.length-1],s.arrowGap):l,g=s.arrowAt==="source"?Lt(c,p[0],s.arrowSize,s.headShape):s.arrowAt==="target"?Lt(l,p[p.length-1],s.arrowSize,s.headShape):void 0;return po(m,p,y,g,s.radius)}function Wu(e,r,t,n,o){return Fb(Ww(e,r,t,n),e,r,o)}function Gu(e,r,t,n,o,i){const s=n===void 0&&o===void 0&&(t==="downward"||t==="upward"),a=t==="leftward"||s&&t==="upward"?-1:1,c=(l,d,u)=>{const h={x:l.x,y:d??l.y},p=Math.max(l.w,l.h)*2+1,m=Hr(h,{x:h.x+(s?0:u*p),y:h.y+(s?u*p:0)},l);return m?{x:m.x+(s?0:u*i),y:m.y+(s?u*i:0)}:s?{x:l.x,y:l.y+u*(l.h/2+i)}:{x:l.x+u*(l.w/2+i),y:d??l.y}};return{sourcePoint:c(e,n,a),targetPoint:c(r,o,-a)}}function Kw(e,r,t,n){const o=t==="downward"||t==="upward",i=t==="leftward"||t==="upward"?-1:1,s=Math.max(100,Math.abs(o?r.y-e.y:r.x-e.x)/2),a={x:e.x+(o?0:i*s),y:e.y+(o?i*s:0)},c={x:r.x-(o?0:i*s),y:r.y-(o?i*s:0)},l=n.arrowAt==="source"?bt(e,a,n.arrowGap):e,d=n.arrowAt==="target"?bt(r,c,n.arrowGap):r;return{d:`M${ft(l)} C${ft(a)} ${ft(c)} ${ft(d)}`,arrow:n.arrowAt==="source"?Lt(e,a,n.arrowSize,n.headShape):n.arrowAt==="target"?Lt(r,c,n.arrowSize,n.headShape):void 0,label:{x:(l.x+3*a.x+3*c.x+d.x)/8,y:(l.y+3*a.y+3*c.y+d.y)/8,angle:cr(d.x+c.x-a.x-l.x,d.y+c.y-a.y-l.y)}}}function zb(e,r,t){const n=t.arrowAt==="source"?bt(e,r,t.arrowGap):e,o=t.arrowAt==="target"?bt(r,e,t.arrowGap):r,i=t.arrowAt==="source"?Lt(e,r,t.arrowSize,t.headShape):t.arrowAt==="target"?Lt(r,e,t.arrowSize,t.headShape):void 0;return po(n,[],o,i,0)}function Jw(e,r,t,n=-90,o=-60,i=350){const s=n*Math.PI/180,a=o*Math.PI/180,c=s-Math.PI/2,l=c-a/2,d=c+a/2,u=1.4*i*(r/3+1),h={x:e.x+Math.cos(l)*u,y:e.y+Math.sin(l)*u},p={x:e.x+Math.cos(d)*u,y:e.y+Math.sin(d)*u},m={x:e.x,y:e.y},y=Hr(m,h,e),g=Hr(m,p,e);if(!y||!g)return null;const v={x:(h.x+p.x)/2,y:(h.y+p.y)/2};let b=bt(y,h,t.srcDist),x=bt(g,p,t.tgtDist),w;if(t.arrowAt==="target"){const S=x;x=bt(g,p,t.tgtDist+t.arrowGap),w=Lt(S,p,t.arrowSize,t.headShape)}else if(t.arrowAt==="source"){const S=b;b=bt(y,h,t.srcDist+t.arrowGap),w=Lt(S,h,t.arrowSize,t.headShape)}return{d:`M${ft(b)} Q${ft(h)} ${ft(v)} Q${ft(p)} ${ft(x)}`,arrow:w,label:{x:v.x,y:v.y,angle:cr(p.x-h.x,p.y-h.y)}}}const Cr=e=>Math.round(e*1e3)/1e3;function Bb(e){var h,p;const r=e.querySelector("[data-flow-node-surface]");if(!r)return;const t=e.getBoundingClientRect(),n=t.width/e.offsetWidth;if(!Number.isFinite(n)||n<=0)return;const o=r.getBoundingClientRect();if(!o.width||!o.height)return;const i=(p=(h=r.closest("[data-flow-icon-label]"))==null?void 0:h.querySelector("[data-flow-icon-caption]"))==null?void 0:p.getBoundingClientRect(),s=r,a=typeof s.getScreenCTM=="function"?s.getScreenCTM():null,c=typeof s.getTotalLength=="function"?s.getTotalLength():0,l=s.points,d=(l==null?void 0:l.numberOfItems)||128,u=a&&c>0?Array.from({length:d},(m,y)=>{const g=l!=null&&l.numberOfItems?l.getItem(y):s.getPointAtLength(c*y/d);return{x:Cr((a.a*g.x+a.c*g.y+a.e-t.left)/n),y:Cr((a.b*g.x+a.d*g.y+a.f-t.top)/n)}}):void 0;return{left:Cr((o.left-t.left)/n),top:Cr((o.top-t.top)/n),width:r instanceof HTMLElement?r.offsetWidth:Cr(o.width/n),height:r instanceof HTMLElement?r.offsetHeight:Cr(o.height/n),radius:parseFloat(getComputedStyle(r).borderTopLeftRadius)||0,...i!=null&&i.height?{captionBottom:Cr((i.bottom-t.top)/n)}:{},...u?{outline:u}:{}}}function En(e,r){const t=e.x-e.w/2,n=e.y-e.h/2;return{x:t+r.left+r.width/2,y:n+r.top+r.height/2,w:r.width,h:r.height,...r.outline?{outline:r.outline.map(o=>({x:t+o.x,y:n+o.y}))}:{}}}function Zw(e,r,t,n,o){var d;const i=o!=="TB"&&o!=="BT",s=i?"top":"left",a=i?"bottom":"right",c=new Map;for(const u of n)for(const[h,p,m]of[[u.source,u.sourceProperty,u.target],[u.target,u.targetProperty,u.source]]){const y=r.get(m);if(p===void 0||!y||m===h)continue;const g=t.get(m),v=JSON.stringify([h,p]),b=c.get(v)??[];b.push(g?En(y,g):y),c.set(v,b)}const l=new Map(e);for(const[u,h]of e){const p=r.get(u);if(!p||!h.some(x=>x.placement==="config"))continue;const m=t.get(u),y=m?En(p,m):p,g={x:p.w/2,y:p.h/2,w:p.w,h:p.h},v=m?En(g,m):g,b=new Map;for(const x of h){if(x.placement!=="config")continue;const C=(c.get(JSON.stringify([u,x.property]))??[]).reduce((_,I)=>_+(i?I.y-y.y:I.x-y.x),0),S=((d=x.anchor)==null?void 0:d.side)===a?a:s;b.set(x,C<-.001?s:C>.001?a:S)}l.set(u,h.map(x=>{const w=b.get(x);if(!w)return x;const C=h.filter(I=>b.get(I)===w),S=(C.indexOf(x)+1)/(C.length+1),_=Lb(v,w,S);return{...x,anchor:_,top:_.y,height:0}}))}return l}function Uu(e,r,t){const n=new Set(r.map(a=>a.id));if(!n.has(e))return new Set;const o=new Set([e]);let i=!0;for(;i;){i=!1;for(const a of r)!o.has(a.id)&&(o.has(a.parent??"")||a.id.startsWith(`${e}.`))&&(o.add(a.id),i=!0)}const s=new Set(o);for(const a of t)o.has(a.source)&&n.has(a.target)&&s.add(a.target),o.has(a.target)&&n.has(a.source)&&s.add(a.source);return s}const ur='"Helvetica Neue", Helvetica, sans-serif';let un;const Jn=new Map;function go(e,r){const t=`${r}|${e}`,n=Jn.get(t);if(n!==void 0)return n;un===void 0&&(un=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let o;return un?(un.font=r,o=un.measureText(e).width):o=e.length*(parseFloat(r)||16)*.55,Jn.size>5e3&&Jn.clear(),Jn.set(t,o),o}function Yw(e,r,t){const n=[];for(const o of String(e).split(`
|
|
210
|
+
`)){const i=o.split(/\s+/).filter(Boolean);if(!i.length){n.push("");continue}let s="";for(const a of i){const c=s?`${s} ${a}`:a;!s||go(c,r)<=t?s=c:(n.push(s),s=a)}n.push(s)}return n}const Hu=e=>e.stopPropagation();function Xw({id:e,rect:r,label:t,labelLayer:n,labelContent:o,style:i,onSelect:s,onCollapse:a,selected:c=!1}){const l=r.x2-r.x1,d=r.y2-r.y1,u=i.borderWidth,h=i.borderStyle==="dashed"?`${u*4} ${u*2}`:i.borderStyle==="dotted"?`${u} ${u}`:void 0,p=r.x1+l/2,m=i.labelPosition==="top"?r.y1+i.labelMargin-i.fontSize/2:i.labelPosition==="bottom"?r.y2-i.labelMargin+i.fontSize/2:r.y1+d/2,y=t?go(t,`bold ${i.fontSize}px ${ur}`):0,g=i.fontSize/5,v=t||c&&a?f.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[c&&a&&f.jsx("foreignObject",{x:p+y/2+g+8,y:m-24,width:48,height:48,"data-flow-content-toggle":"","data-flow-collapse-control":"",style:{pointerEvents:"auto"},children:f.jsx(Ke,{label:"Show icon",children:f.jsx(Oe,{"aria-label":"Show icon",icon:f.jsx(Z.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:i.textColor},onClick:b=>{b.stopPropagation(),a(e)}})})}),o?f.jsx("foreignObject",{x:p-y/2-g,y:m-i.fontSize/2-g,width:y+2*g,height:i.fontSize+2*g,style:{overflow:"visible"},onClick:Hu,children:o}):t&&f.jsxs(f.Fragment,{children:[f.jsx("rect",{x:p-y/2-g,y:m-i.fontSize/2-g,width:y+2*g,height:i.fontSize+2*g,fill:i.textColor==="transparent"?"transparent":i.labelBg}),f.jsx("text",{x:p,y:m,fill:i.textColor,fontSize:i.fontSize,fontWeight:"bold",fontFamily:ur,style:{fontSize:i.fontSize,fontWeight:"bold",fontFamily:ur},textAnchor:"middle",dominantBaseline:"central",children:t})]})]}):null;return f.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:Hu,onClick:b=>{b.stopPropagation(),s==null||s(e,{shiftKey:b.shiftKey,ctrlKey:b.ctrlKey,metaKey:b.metaKey,altKey:b.altKey})},children:[f.jsx("rect",{x:r.x1,y:r.y1,width:l,height:d,rx:i.borderRadius,ry:i.borderRadius,fill:i.bgColor,fillOpacity:i.bgOpacity,stroke:i.borderColor,strokeWidth:i.borderStyle==="double"?u/3:u,strokeDasharray:h}),i.borderStyle==="double"&&f.jsx("rect",{x:r.x1+u*2/3,y:r.y1+u*2/3,width:Math.max(0,l-u*4/3),height:Math.max(0,d-u*4/3),rx:Math.max(0,i.borderRadius-u*2/3),ry:Math.max(0,i.borderRadius-u*2/3),fill:"none",stroke:i.borderColor,strokeWidth:u/3}),i.animated&&u>0&&f.jsx(no,{variant:i.animationVariant,x:r.x1,y:r.y1,width:l,height:d,radius:i.borderRadius,color:i.animationColor||i.borderColor,strokeWidth:Math.max(8,u*1.6)}),n&&v?Dr.createPortal(v,n):v]})}const Qw=j.memo(Xw),oo=45,Db=70,jr=15,Vb=50;function Wb(e,r,t=oo){const n=`${t}px ${ur}`,o=e?Yw(e,n,200*t/oo):[],i=r?48+(o.length?12:0):0,s=i+Math.max(0,...o.map(l=>go(l,n))),a=Math.max(o.length*t,r?48:0),c=o.length||r?2*jr:0;return{lines:o,iconWidth:i,contentWidth:s,contentHeight:a,width:s+c,height:a+c}}const kn=6,Gb=3,Ld=.3,e1=8,Fd=Math.max(Math.pow(kn*13.37,.9),29)*Gb-e1/Ld,Ub=kn*Gb*2,Xn=80,t1=2*Xn+Fd*Ld+100,r1=36+2*Math.max(80,Ub+Fd*Ld);function gd(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function yd(e,r){return r==="auto"||(r==="properties"?gd(e):!gd(e))}function er(e,r,t){return t!=="properties"||e!=="root"||r.some(n=>(n.source===e||n.target===e)&&gd(n))}function n1(e,r,t,n=!1,o){if(!n)return{nodes:e,edges:r};const i=e.filter(a=>er(a.id,r,t)&&(!o||o.has(a.id))),s=new Set(i.map(a=>a.id));return{nodes:i,edges:r.filter(a=>yd(a,t)&&s.has(a.source)&&s.has(a.target))}}const o1=500,i1="32 18",a1=e=>e.stopPropagation();function s1({id:e,reveal:r,onRevealComplete:t,edgeData:n,validationIssue:o,edgeType:i="rounded-orthogonal",edgeRadius:s,customEdgeTypes:a,source:c,target:l,sourceProperty:d,targetProperty:u,sourceY:h,targetY:p,sourcePort:m,targetPort:y,propertyMode:g=!1,dir:v,turn:b,labelAtTarget:x,labelFraction:w,color:C,connectorColor:S,labelBg:_,labelLayer:I,label:E,dashed:O,animated:A,inverted:R,loopIndex:P=0,onSelect:T}){const N=n==null?void 0:n.icon,$=g?oo:Db,{lines:M,iconWidth:W,contentWidth:ae,contentHeight:se}=j.useMemo(()=>Wb(E,N,$),[E,N,$]),re=j.useMemo(()=>{const Ce={srcDist:Xn,tgtDist:Xn,arrowGap:Ub,arrowSize:Fd,headShape:g&&(R?h!==void 0||m:p!==void 0||y)?"square":"triangle",radius:s??(x?40:o1),arrowAt:R?"source":"target",labelTargetLength:x?ae+2*jr:void 0,labelFraction:x?w:void 0},ge=h!==void 0||p!==void 0||!!m||!!y,he=Gu(c,l,v,h,p,0),Y=h===void 0&&p===void 0&&(v==="downward"||v==="upward"),H=m??{...he.sourcePoint,side:Y?v==="upward"?"top":"bottom":v==="leftward"?"left":"right"},ve=y??{...he.targetPoint,side:Y?v==="upward"?"bottom":"top":v==="leftward"?"right":"left"},J=c.x===l.x&&c.y===l.y,be=m||y?Uw(H,ve,{...Ce,srcDist:18,tgtDist:18},i):ge?Vu(c,l,v,h,p,b,{...Ce,srcDist:18,tgtDist:18,radius:s??Math.min(Ce.radius,40)}):J?Jw(c,P,{...Ce,srcDist:0,tgtDist:0}):Wu(c,l,v,b,Ce);if(!be)return null;const Q=Gu(c,l,v,h,p,ge?18:Xn);m&&(Q.sourcePoint=Lr(m,18)),y&&(Q.targetPoint=Lr(y,18));const je=Object.prototype.hasOwnProperty.call(a??{},i)?a==null?void 0:a[i]:void 0;if(je){const Pe={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return je({edge:n??{id:e,source:"",target:""},source:{...c},target:{...l},...Q,direction:Pe[v],sourceY:h,targetY:p,inverted:!!R,defaultGeometry:be})??be}return J||m||y?be:i==="straight"?ge?zb(Q.sourcePoint,Q.targetPoint,Ce):Fb([c,l],c,l,Ce):i==="bezier"?Kw(Q.sourcePoint,Q.targetPoint,ge?v==="leftward"?"leftward":"rightward":v,Ce):i==="orthogonal"?ge?Vu(c,l,v,h,p,b,{...Ce,srcDist:18,tgtDist:18,radius:0}):Wu(c,l,v,b,{...Ce,radius:0}):be},[c,e,n,i,s,a,l,g,h,p,m,y,v,b,R,P,x,w,ae]);if(!re)return null;const ye=(v==="rightward"||v==="leftward")&&!Object.prototype.hasOwnProperty.call(a??{},i)&&!(g&&(h!==void 0||p!==void 0||m||y)),me=ye?`translate(${re.label.x} ${re.label.y-se/2-2*jr})`:`translate(${re.label.x} ${re.label.y}) rotate(${re.label.angle}) translate(${v==="downward"||v==="upward"||x||Object.prototype.hasOwnProperty.call(a??{},i)?0:Vb} 0)`,L=o!=null&&o.startsWith("Unverified:")?"#b45309":"#dc2626",z=o?L:C,U=o?f.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":o,transform:`translate(${re.label.x} ${re.label.y-M.length*$/2-55})`,children:[f.jsx("title",{children:o}),f.jsx(Yt,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:L})]}):null,B=A&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",ce=!B&&(O||A)?i1:void 0,X=A&&!B?`flow-sdk-edge-anim${R?" flow-sdk-edge-anim-rev":""}`:void 0;let le=null;const ue=r?{"--flow-edge-reveal-duration":`${r.durationMs??600}ms`,"--flow-edge-reveal-state":r.paused?"paused":"running"}:void 0;if(M.length||N){const Ce=ae,ge=se;le=f.jsxs("g",{className:`flow-sdk-edge-label${r?" flow-sdk-edge-reveal-end":""}`,style:ue,"data-label-transform":me,"data-label-horizontal":ye||void 0,"data-edge-id":e,"data-source-property":d,"data-target-property":u,transform:me,children:[f.jsx("rect",{x:-Ce/2-jr,y:-ge/2-jr,width:Ce+2*jr,height:ge+2*jr,fill:C==="transparent"?"transparent":_}),f.jsx("text",{fill:C,fontSize:$,style:{fontSize:$,fontFamily:ur},fontFamily:ur,textAnchor:"middle",dominantBaseline:"central",children:M.map((he,Y)=>f.jsx("tspan",{x:W/2,y:(Y-(M.length-1)/2)*$,children:he},Y))}),N&&f.jsxs("g",{className:"flow-sdk-edge-icon",opacity:C==="transparent"?0:1,children:[f.jsx("title",{children:E?`Edge icon: ${E}`:"Edge icon"}),f.jsx("rect",{x:-Ce/2,y:-24,width:48,height:48,fill:"transparent"}),f.jsx(Yt,{name:N,svg:!0,size:48,x:-Ce/2,y:-24,color:C})]})]})}const xe=f.jsxs(f.Fragment,{children:[f.jsx("path",{d:re.d,fill:"none",stroke:z,strokeWidth:kn,strokeOpacity:B?.35:void 0,strokeDasharray:ce,className:X}),B&&f.jsx(Lw,{path:re.d,color:z,width:kn*1.6,reversed:R})]});return f.jsxs("g",{className:"flow-sdk-edge",style:ue,"data-edge-id":e,"data-source-property":d,"data-target-property":u,"data-validation":o?o.startsWith("Unverified:")?"unverified":"invalid":void 0,"aria-label":o,onPointerDown:a1,onClick:Ce=>{Ce.stopPropagation(),T==null||T(e)},children:[r?f.jsx($w,{path:re.d,width:kn*4,reversed:R,onComplete:()=>t==null?void 0:t(e),children:xe}):xe,re.arrow&&f.jsx("path",{className:r?"flow-sdk-edge-reveal-end":void 0,d:re.arrow,fill:o?L:S??z}),I&&le?Dr.createPortal(le,I):le,I&&U?Dr.createPortal(U,I):U,f.jsx("path",{className:"flow-sdk-edge-hit",d:re.d,fill:"none",stroke:"transparent"})]})}const Ku=j.memo(s1);var Zn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function c1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function zd(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Vo,Ju;function l1(){if(Ju)return Vo;Ju=1;function e(){this.__data__=[],this.size=0}return Vo=e,Vo}var Wo,Zu;function Xr(){if(Zu)return Wo;Zu=1;function e(r,t){return r===t||r!==r&&t!==t}return Wo=e,Wo}var Go,Yu;function yo(){if(Yu)return Go;Yu=1;var e=Xr();function r(t,n){for(var o=t.length;o--;)if(e(t[o][0],n))return o;return-1}return Go=r,Go}var Uo,Xu;function d1(){if(Xu)return Uo;Xu=1;var e=yo(),r=Array.prototype,t=r.splice;function n(o){var i=this.__data__,s=e(i,o);if(s<0)return!1;var a=i.length-1;return s==a?i.pop():t.call(i,s,1),--this.size,!0}return Uo=n,Uo}var Ho,Qu;function u1(){if(Qu)return Ho;Qu=1;var e=yo();function r(t){var n=this.__data__,o=e(n,t);return o<0?void 0:n[o][1]}return Ho=r,Ho}var Ko,ef;function f1(){if(ef)return Ko;ef=1;var e=yo();function r(t){return e(this.__data__,t)>-1}return Ko=r,Ko}var Jo,tf;function h1(){if(tf)return Jo;tf=1;var e=yo();function r(t,n){var o=this.__data__,i=e(o,t);return i<0?(++this.size,o.push([t,n])):o[i][1]=n,this}return Jo=r,Jo}var Zo,rf;function mo(){if(rf)return Zo;rf=1;var e=l1(),r=d1(),t=u1(),n=f1(),o=h1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Zo=i,Zo}var Yo,nf;function p1(){if(nf)return Yo;nf=1;var e=mo();function r(){this.__data__=new e,this.size=0}return Yo=r,Yo}var Xo,of;function g1(){if(of)return Xo;of=1;function e(r){var t=this.__data__,n=t.delete(r);return this.size=t.size,n}return Xo=e,Xo}var Qo,af;function y1(){if(af)return Qo;af=1;function e(r){return this.__data__.get(r)}return Qo=e,Qo}var ei,sf;function m1(){if(sf)return ei;sf=1;function e(r){return this.__data__.has(r)}return ei=e,ei}var ti,cf;function Hb(){if(cf)return ti;cf=1;var e=typeof Zn=="object"&&Zn&&Zn.Object===Object&&Zn;return ti=e,ti}var ri,lf;function Gt(){if(lf)return ri;lf=1;var e=Hb(),r=typeof self=="object"&&self&&self.Object===Object&&self,t=e||r||Function("return this")();return ri=t,ri}var ni,df;function Qr(){if(df)return ni;df=1;var e=Gt(),r=e.Symbol;return ni=r,ni}var oi,uf;function b1(){if(uf)return oi;uf=1;var e=Qr(),r=Object.prototype,t=r.hasOwnProperty,n=r.toString,o=e?e.toStringTag:void 0;function i(s){var a=t.call(s,o),c=s[o];try{s[o]=void 0;var l=!0}catch{}var d=n.call(s);return l&&(a?s[o]=c:delete s[o]),d}return oi=i,oi}var ii,ff;function v1(){if(ff)return ii;ff=1;var e=Object.prototype,r=e.toString;function t(n){return r.call(n)}return ii=t,ii}var ai,hf;function Pr(){if(hf)return ai;hf=1;var e=Qr(),r=b1(),t=v1(),n="[object Null]",o="[object Undefined]",i=e?e.toStringTag:void 0;function s(a){return a==null?a===void 0?o:n:i&&i in Object(a)?r(a):t(a)}return ai=s,ai}var si,pf;function Ft(){if(pf)return si;pf=1;function e(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}return si=e,si}var ci,gf;function $n(){if(gf)return ci;gf=1;var e=Pr(),r=Ft(),t="[object AsyncFunction]",n="[object Function]",o="[object GeneratorFunction]",i="[object Proxy]";function s(a){if(!r(a))return!1;var c=e(a);return c==n||c==o||c==t||c==i}return ci=s,ci}var li,yf;function x1(){if(yf)return li;yf=1;var e=Gt(),r=e["__core-js_shared__"];return li=r,li}var di,mf;function w1(){if(mf)return di;mf=1;var e=x1(),r=(function(){var n=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})();function t(n){return!!r&&r in n}return di=t,di}var ui,bf;function Kb(){if(bf)return ui;bf=1;var e=Function.prototype,r=e.toString;function t(n){if(n!=null){try{return r.call(n)}catch{}try{return n+""}catch{}}return""}return ui=t,ui}var fi,vf;function C1(){if(vf)return fi;vf=1;var e=$n(),r=w1(),t=Ft(),n=Kb(),o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,s=Function.prototype,a=Object.prototype,c=s.toString,l=a.hasOwnProperty,d=RegExp("^"+c.call(l).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function u(h){if(!t(h)||r(h))return!1;var p=e(h)?d:i;return p.test(n(h))}return fi=u,fi}var hi,xf;function S1(){if(xf)return hi;xf=1;function e(r,t){return r==null?void 0:r[t]}return hi=e,hi}var pi,wf;function Mr(){if(wf)return pi;wf=1;var e=C1(),r=S1();function t(n,o){var i=r(n,o);return e(i)?i:void 0}return pi=t,pi}var gi,Cf;function Bd(){if(Cf)return gi;Cf=1;var e=Mr(),r=Gt(),t=e(r,"Map");return gi=t,gi}var yi,Sf;function bo(){if(Sf)return yi;Sf=1;var e=Mr(),r=e(Object,"create");return yi=r,yi}var mi,jf;function j1(){if(jf)return mi;jf=1;var e=bo();function r(){this.__data__=e?e(null):{},this.size=0}return mi=r,mi}var bi,_f;function _1(){if(_f)return bi;_f=1;function e(r){var t=this.has(r)&&delete this.__data__[r];return this.size-=t?1:0,t}return bi=e,bi}var vi,Ef;function E1(){if(Ef)return vi;Ef=1;var e=bo(),r="__lodash_hash_undefined__",t=Object.prototype,n=t.hasOwnProperty;function o(i){var s=this.__data__;if(e){var a=s[i];return a===r?void 0:a}return n.call(s,i)?s[i]:void 0}return vi=o,vi}var xi,kf;function k1(){if(kf)return xi;kf=1;var e=bo(),r=Object.prototype,t=r.hasOwnProperty;function n(o){var i=this.__data__;return e?i[o]!==void 0:t.call(i,o)}return xi=n,xi}var wi,Rf;function R1(){if(Rf)return wi;Rf=1;var e=bo(),r="__lodash_hash_undefined__";function t(n,o){var i=this.__data__;return this.size+=this.has(n)?0:1,i[n]=e&&o===void 0?r:o,this}return wi=t,wi}var Ci,Af;function A1(){if(Af)return Ci;Af=1;var e=j1(),r=_1(),t=E1(),n=k1(),o=R1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Ci=i,Ci}var Si,Pf;function P1(){if(Pf)return Si;Pf=1;var e=A1(),r=mo(),t=Bd();function n(){this.size=0,this.__data__={hash:new e,map:new(t||r),string:new e}}return Si=n,Si}var ji,Mf;function M1(){if(Mf)return ji;Mf=1;function e(r){var t=typeof r;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?r!=="__proto__":r===null}return ji=e,ji}var _i,If;function vo(){if(If)return _i;If=1;var e=M1();function r(t,n){var o=t.__data__;return e(n)?o[typeof n=="string"?"string":"hash"]:o.map}return _i=r,_i}var Ei,Tf;function I1(){if(Tf)return Ei;Tf=1;var e=vo();function r(t){var n=e(this,t).delete(t);return this.size-=n?1:0,n}return Ei=r,Ei}var ki,Of;function T1(){if(Of)return ki;Of=1;var e=vo();function r(t){return e(this,t).get(t)}return ki=r,ki}var Ri,Nf;function O1(){if(Nf)return Ri;Nf=1;var e=vo();function r(t){return e(this,t).has(t)}return Ri=r,Ri}var Ai,$f;function N1(){if($f)return Ai;$f=1;var e=vo();function r(t,n){var o=e(this,t),i=o.size;return o.set(t,n),this.size+=o.size==i?0:1,this}return Ai=r,Ai}var Pi,qf;function Dd(){if(qf)return Pi;qf=1;var e=P1(),r=I1(),t=T1(),n=O1(),o=N1();function i(s){var a=-1,c=s==null?0:s.length;for(this.clear();++a<c;){var l=s[a];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=r,i.prototype.get=t,i.prototype.has=n,i.prototype.set=o,Pi=i,Pi}var Mi,Lf;function $1(){if(Lf)return Mi;Lf=1;var e=mo(),r=Bd(),t=Dd(),n=200;function o(i,s){var a=this.__data__;if(a instanceof e){var c=a.__data__;if(!r||c.length<n-1)return c.push([i,s]),this.size=++a.size,this;a=this.__data__=new t(c)}return a.set(i,s),this.size=a.size,this}return Mi=o,Mi}var Ii,Ff;function xo(){if(Ff)return Ii;Ff=1;var e=mo(),r=p1(),t=g1(),n=y1(),o=m1(),i=$1();function s(a){var c=this.__data__=new e(a);this.size=c.size}return s.prototype.clear=r,s.prototype.delete=t,s.prototype.get=n,s.prototype.has=o,s.prototype.set=i,Ii=s,Ii}var Ti,zf;function Vd(){if(zf)return Ti;zf=1;function e(r,t){for(var n=-1,o=r==null?0:r.length;++n<o&&t(r[n],n,r)!==!1;);return r}return Ti=e,Ti}var Oi,Bf;function Jb(){if(Bf)return Oi;Bf=1;var e=Mr(),r=(function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch{}})();return Oi=r,Oi}var Ni,Df;function wo(){if(Df)return Ni;Df=1;var e=Jb();function r(t,n,o){n=="__proto__"&&e?e(t,n,{configurable:!0,enumerable:!0,value:o,writable:!0}):t[n]=o}return Ni=r,Ni}var $i,Vf;function Co(){if(Vf)return $i;Vf=1;var e=wo(),r=Xr(),t=Object.prototype,n=t.hasOwnProperty;function o(i,s,a){var c=i[s];(!(n.call(i,s)&&r(c,a))||a===void 0&&!(s in i))&&e(i,s,a)}return $i=o,$i}var qi,Wf;function qn(){if(Wf)return qi;Wf=1;var e=Co(),r=wo();function t(n,o,i,s){var a=!i;i||(i={});for(var c=-1,l=o.length;++c<l;){var d=o[c],u=s?s(i[d],n[d],d,i,n):void 0;u===void 0&&(u=n[d]),a?r(i,d,u):e(i,d,u)}return i}return qi=t,qi}var Li,Gf;function q1(){if(Gf)return Li;Gf=1;function e(r,t){for(var n=-1,o=Array(r);++n<r;)o[n]=t(n);return o}return Li=e,Li}var Fi,Uf;function Xt(){if(Uf)return Fi;Uf=1;function e(r){return r!=null&&typeof r=="object"}return Fi=e,Fi}var zi,Hf;function L1(){if(Hf)return zi;Hf=1;var e=Pr(),r=Xt(),t="[object Arguments]";function n(o){return r(o)&&e(o)==t}return zi=n,zi}var Bi,Kf;function Ln(){if(Kf)return Bi;Kf=1;var e=L1(),r=Xt(),t=Object.prototype,n=t.hasOwnProperty,o=t.propertyIsEnumerable,i=e((function(){return arguments})())?e:function(s){return r(s)&&n.call(s,"callee")&&!o.call(s,"callee")};return Bi=i,Bi}var Di,Jf;function yt(){if(Jf)return Di;Jf=1;var e=Array.isArray;return Di=e,Di}var yn={exports:{}},Vi,Zf;function F1(){if(Zf)return Vi;Zf=1;function e(){return!1}return Vi=e,Vi}yn.exports;var Yf;function en(){return Yf||(Yf=1,(function(e,r){var t=Gt(),n=F1(),o=r&&!r.nodeType&&r,i=o&&!0&&e&&!e.nodeType&&e,s=i&&i.exports===o,a=s?t.Buffer:void 0,c=a?a.isBuffer:void 0,l=c||n;e.exports=l})(yn,yn.exports)),yn.exports}var Wi,Xf;function So(){if(Xf)return Wi;Xf=1;var e=9007199254740991,r=/^(?:0|[1-9]\d*)$/;function t(n,o){var i=typeof n;return o=o??e,!!o&&(i=="number"||i!="symbol"&&r.test(n))&&n>-1&&n%1==0&&n<o}return Wi=t,Wi}var Gi,Qf;function Wd(){if(Qf)return Gi;Qf=1;var e=9007199254740991;function r(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=e}return Gi=r,Gi}var Ui,eh;function z1(){if(eh)return Ui;eh=1;var e=Pr(),r=Wd(),t=Xt(),n="[object Arguments]",o="[object Array]",i="[object Boolean]",s="[object Date]",a="[object Error]",c="[object Function]",l="[object Map]",d="[object Number]",u="[object Object]",h="[object RegExp]",p="[object Set]",m="[object String]",y="[object WeakMap]",g="[object ArrayBuffer]",v="[object DataView]",b="[object Float32Array]",x="[object Float64Array]",w="[object Int8Array]",C="[object Int16Array]",S="[object Int32Array]",_="[object Uint8Array]",I="[object Uint8ClampedArray]",E="[object Uint16Array]",O="[object Uint32Array]",A={};A[b]=A[x]=A[w]=A[C]=A[S]=A[_]=A[I]=A[E]=A[O]=!0,A[n]=A[o]=A[g]=A[i]=A[v]=A[s]=A[a]=A[c]=A[l]=A[d]=A[u]=A[h]=A[p]=A[m]=A[y]=!1;function R(P){return t(P)&&r(P.length)&&!!A[e(P)]}return Ui=R,Ui}var Hi,th;function jo(){if(th)return Hi;th=1;function e(r){return function(t){return r(t)}}return Hi=e,Hi}var mn={exports:{}};mn.exports;var rh;function Gd(){return rh||(rh=1,(function(e,r){var t=Hb(),n=r&&!r.nodeType&&r,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i&&t.process,a=(function(){try{var c=o&&o.require&&o.require("util").types;return c||s&&s.binding&&s.binding("util")}catch{}})();e.exports=a})(mn,mn.exports)),mn.exports}var Ki,nh;function Fn(){if(nh)return Ki;nh=1;var e=z1(),r=jo(),t=Gd(),n=t&&t.isTypedArray,o=n?r(n):e;return Ki=o,Ki}var Ji,oh;function Zb(){if(oh)return Ji;oh=1;var e=q1(),r=Ln(),t=yt(),n=en(),o=So(),i=Fn(),s=Object.prototype,a=s.hasOwnProperty;function c(l,d){var u=t(l),h=!u&&r(l),p=!u&&!h&&n(l),m=!u&&!h&&!p&&i(l),y=u||h||p||m,g=y?e(l.length,String):[],v=g.length;for(var b in l)(d||a.call(l,b))&&!(y&&(b=="length"||p&&(b=="offset"||b=="parent")||m&&(b=="buffer"||b=="byteLength"||b=="byteOffset")||o(b,v)))&&g.push(b);return g}return Ji=c,Ji}var Zi,ih;function _o(){if(ih)return Zi;ih=1;var e=Object.prototype;function r(t){var n=t&&t.constructor,o=typeof n=="function"&&n.prototype||e;return t===o}return Zi=r,Zi}var Yi,ah;function Yb(){if(ah)return Yi;ah=1;function e(r,t){return function(n){return r(t(n))}}return Yi=e,Yi}var Xi,sh;function B1(){if(sh)return Xi;sh=1;var e=Yb(),r=e(Object.keys,Object);return Xi=r,Xi}var Qi,ch;function Ud(){if(ch)return Qi;ch=1;var e=_o(),r=B1(),t=Object.prototype,n=t.hasOwnProperty;function o(i){if(!e(i))return r(i);var s=[];for(var a in Object(i))n.call(i,a)&&a!="constructor"&&s.push(a);return s}return Qi=o,Qi}var ea,lh;function rr(){if(lh)return ea;lh=1;var e=$n(),r=Wd();function t(n){return n!=null&&r(n.length)&&!e(n)}return ea=t,ea}var ta,dh;function br(){if(dh)return ta;dh=1;var e=Zb(),r=Ud(),t=rr();function n(o){return t(o)?e(o):r(o)}return ta=n,ta}var ra,uh;function D1(){if(uh)return ra;uh=1;var e=qn(),r=br();function t(n,o){return n&&e(o,r(o),n)}return ra=t,ra}var na,fh;function V1(){if(fh)return na;fh=1;function e(r){var t=[];if(r!=null)for(var n in Object(r))t.push(n);return t}return na=e,na}var oa,hh;function W1(){if(hh)return oa;hh=1;var e=Ft(),r=_o(),t=V1(),n=Object.prototype,o=n.hasOwnProperty;function i(s){if(!e(s))return t(s);var a=r(s),c=[];for(var l in s)l=="constructor"&&(a||!o.call(s,l))||c.push(l);return c}return oa=i,oa}var ia,ph;function Ir(){if(ph)return ia;ph=1;var e=Zb(),r=W1(),t=rr();function n(o){return t(o)?e(o,!0):r(o)}return ia=n,ia}var aa,gh;function G1(){if(gh)return aa;gh=1;var e=qn(),r=Ir();function t(n,o){return n&&e(o,r(o),n)}return aa=t,aa}var bn={exports:{}};bn.exports;var yh;function Xb(){return yh||(yh=1,(function(e,r){var t=Gt(),n=r&&!r.nodeType&&r,o=n&&!0&&e&&!e.nodeType&&e,i=o&&o.exports===n,s=i?t.Buffer:void 0,a=s?s.allocUnsafe:void 0;function c(l,d){if(d)return l.slice();var u=l.length,h=a?a(u):new l.constructor(u);return l.copy(h),h}e.exports=c})(bn,bn.exports)),bn.exports}var sa,mh;function Qb(){if(mh)return sa;mh=1;function e(r,t){var n=-1,o=r.length;for(t||(t=Array(o));++n<o;)t[n]=r[n];return t}return sa=e,sa}var ca,bh;function ev(){if(bh)return ca;bh=1;function e(r,t){for(var n=-1,o=r==null?0:r.length,i=0,s=[];++n<o;){var a=r[n];t(a,n,r)&&(s[i++]=a)}return s}return ca=e,ca}var la,vh;function tv(){if(vh)return la;vh=1;function e(){return[]}return la=e,la}var da,xh;function Hd(){if(xh)return da;xh=1;var e=ev(),r=tv(),t=Object.prototype,n=t.propertyIsEnumerable,o=Object.getOwnPropertySymbols,i=o?function(s){return s==null?[]:(s=Object(s),e(o(s),function(a){return n.call(s,a)}))}:r;return da=i,da}var ua,wh;function U1(){if(wh)return ua;wh=1;var e=qn(),r=Hd();function t(n,o){return e(n,r(n),o)}return ua=t,ua}var fa,Ch;function Kd(){if(Ch)return fa;Ch=1;function e(r,t){for(var n=-1,o=t.length,i=r.length;++n<o;)r[i+n]=t[n];return r}return fa=e,fa}var ha,Sh;function Eo(){if(Sh)return ha;Sh=1;var e=Yb(),r=e(Object.getPrototypeOf,Object);return ha=r,ha}var pa,jh;function rv(){if(jh)return pa;jh=1;var e=Kd(),r=Eo(),t=Hd(),n=tv(),o=Object.getOwnPropertySymbols,i=o?function(s){for(var a=[];s;)e(a,t(s)),s=r(s);return a}:n;return pa=i,pa}var ga,_h;function H1(){if(_h)return ga;_h=1;var e=qn(),r=rv();function t(n,o){return e(n,r(n),o)}return ga=t,ga}var ya,Eh;function nv(){if(Eh)return ya;Eh=1;var e=Kd(),r=yt();function t(n,o,i){var s=o(n);return r(n)?s:e(s,i(n))}return ya=t,ya}var ma,kh;function ov(){if(kh)return ma;kh=1;var e=nv(),r=Hd(),t=br();function n(o){return e(o,t,r)}return ma=n,ma}var ba,Rh;function K1(){if(Rh)return ba;Rh=1;var e=nv(),r=rv(),t=Ir();function n(o){return e(o,t,r)}return ba=n,ba}var va,Ah;function J1(){if(Ah)return va;Ah=1;var e=Mr(),r=Gt(),t=e(r,"DataView");return va=t,va}var xa,Ph;function Z1(){if(Ph)return xa;Ph=1;var e=Mr(),r=Gt(),t=e(r,"Promise");return xa=t,xa}var wa,Mh;function iv(){if(Mh)return wa;Mh=1;var e=Mr(),r=Gt(),t=e(r,"Set");return wa=t,wa}var Ca,Ih;function Y1(){if(Ih)return Ca;Ih=1;var e=Mr(),r=Gt(),t=e(r,"WeakMap");return Ca=t,Ca}var Sa,Th;function tn(){if(Th)return Sa;Th=1;var e=J1(),r=Bd(),t=Z1(),n=iv(),o=Y1(),i=Pr(),s=Kb(),a="[object Map]",c="[object Object]",l="[object Promise]",d="[object Set]",u="[object WeakMap]",h="[object DataView]",p=s(e),m=s(r),y=s(t),g=s(n),v=s(o),b=i;return(e&&b(new e(new ArrayBuffer(1)))!=h||r&&b(new r)!=a||t&&b(t.resolve())!=l||n&&b(new n)!=d||o&&b(new o)!=u)&&(b=function(x){var w=i(x),C=w==c?x.constructor:void 0,S=C?s(C):"";if(S)switch(S){case p:return h;case m:return a;case y:return l;case g:return d;case v:return u}return w}),Sa=b,Sa}var ja,Oh;function X1(){if(Oh)return ja;Oh=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n){var o=n.length,i=new n.constructor(o);return o&&typeof n[0]=="string"&&r.call(n,"index")&&(i.index=n.index,i.input=n.input),i}return ja=t,ja}var _a,Nh;function av(){if(Nh)return _a;Nh=1;var e=Gt(),r=e.Uint8Array;return _a=r,_a}var Ea,$h;function Jd(){if($h)return Ea;$h=1;var e=av();function r(t){var n=new t.constructor(t.byteLength);return new e(n).set(new e(t)),n}return Ea=r,Ea}var ka,qh;function Q1(){if(qh)return ka;qh=1;var e=Jd();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.byteLength)}return ka=r,ka}var Ra,Lh;function eC(){if(Lh)return Ra;Lh=1;var e=/\w*$/;function r(t){var n=new t.constructor(t.source,e.exec(t));return n.lastIndex=t.lastIndex,n}return Ra=r,Ra}var Aa,Fh;function tC(){if(Fh)return Aa;Fh=1;var e=Qr(),r=e?e.prototype:void 0,t=r?r.valueOf:void 0;function n(o){return t?Object(t.call(o)):{}}return Aa=n,Aa}var Pa,zh;function sv(){if(zh)return Pa;zh=1;var e=Jd();function r(t,n){var o=n?e(t.buffer):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}return Pa=r,Pa}var Ma,Bh;function rC(){if(Bh)return Ma;Bh=1;var e=Jd(),r=Q1(),t=eC(),n=tC(),o=sv(),i="[object Boolean]",s="[object Date]",a="[object Map]",c="[object Number]",l="[object RegExp]",d="[object Set]",u="[object String]",h="[object Symbol]",p="[object ArrayBuffer]",m="[object DataView]",y="[object Float32Array]",g="[object Float64Array]",v="[object Int8Array]",b="[object Int16Array]",x="[object Int32Array]",w="[object Uint8Array]",C="[object Uint8ClampedArray]",S="[object Uint16Array]",_="[object Uint32Array]";function I(E,O,A){var R=E.constructor;switch(O){case p:return e(E);case i:case s:return new R(+E);case m:return r(E,A);case y:case g:case v:case b:case x:case w:case C:case S:case _:return o(E,A);case a:return new R;case c:case u:return new R(E);case l:return t(E);case d:return new R;case h:return n(E)}}return Ma=I,Ma}var Ia,Dh;function cv(){if(Dh)return Ia;Dh=1;var e=Ft(),r=Object.create,t=(function(){function n(){}return function(o){if(!e(o))return{};if(r)return r(o);n.prototype=o;var i=new n;return n.prototype=void 0,i}})();return Ia=t,Ia}var Ta,Vh;function lv(){if(Vh)return Ta;Vh=1;var e=cv(),r=Eo(),t=_o();function n(o){return typeof o.constructor=="function"&&!t(o)?e(r(o)):{}}return Ta=n,Ta}var Oa,Wh;function nC(){if(Wh)return Oa;Wh=1;var e=tn(),r=Xt(),t="[object Map]";function n(o){return r(o)&&e(o)==t}return Oa=n,Oa}var Na,Gh;function oC(){if(Gh)return Na;Gh=1;var e=nC(),r=jo(),t=Gd(),n=t&&t.isMap,o=n?r(n):e;return Na=o,Na}var $a,Uh;function iC(){if(Uh)return $a;Uh=1;var e=tn(),r=Xt(),t="[object Set]";function n(o){return r(o)&&e(o)==t}return $a=n,$a}var qa,Hh;function aC(){if(Hh)return qa;Hh=1;var e=iC(),r=jo(),t=Gd(),n=t&&t.isSet,o=n?r(n):e;return qa=o,qa}var La,Kh;function dv(){if(Kh)return La;Kh=1;var e=xo(),r=Vd(),t=Co(),n=D1(),o=G1(),i=Xb(),s=Qb(),a=U1(),c=H1(),l=ov(),d=K1(),u=tn(),h=X1(),p=rC(),m=lv(),y=yt(),g=en(),v=oC(),b=Ft(),x=aC(),w=br(),C=Ir(),S=1,_=2,I=4,E="[object Arguments]",O="[object Array]",A="[object Boolean]",R="[object Date]",P="[object Error]",T="[object Function]",N="[object GeneratorFunction]",$="[object Map]",M="[object Number]",W="[object Object]",ae="[object RegExp]",se="[object Set]",re="[object String]",ye="[object Symbol]",me="[object WeakMap]",L="[object ArrayBuffer]",z="[object DataView]",U="[object Float32Array]",B="[object Float64Array]",ce="[object Int8Array]",X="[object Int16Array]",le="[object Int32Array]",ue="[object Uint8Array]",xe="[object Uint8ClampedArray]",Ce="[object Uint16Array]",ge="[object Uint32Array]",he={};he[E]=he[O]=he[L]=he[z]=he[A]=he[R]=he[U]=he[B]=he[ce]=he[X]=he[le]=he[$]=he[M]=he[W]=he[ae]=he[se]=he[re]=he[ye]=he[ue]=he[xe]=he[Ce]=he[ge]=!0,he[P]=he[T]=he[me]=!1;function Y(H,ve,J,be,Q,je){var Pe,qe=ve&S,Xe=ve&_,Be=ve&I;if(J&&(Pe=Q?J(H,be,Q,je):J(H)),Pe!==void 0)return Pe;if(!b(H))return H;var ut=y(H);if(ut){if(Pe=h(H),!qe)return s(H,Pe)}else{var De=u(H),rt=De==T||De==N;if(g(H))return i(H,qe);if(De==W||De==E||rt&&!Q){if(Pe=Xe||rt?{}:m(H),!qe)return Xe?c(H,o(Pe,H)):a(H,n(Pe,H))}else{if(!he[De])return Q?H:{};Pe=p(H,De,qe)}}je||(je=new e);var pt=je.get(H);if(pt)return pt;je.set(H,Pe),x(H)?H.forEach(function(st){Pe.add(Y(st,ve,J,st,H,je))}):v(H)&&H.forEach(function(st,ct){Pe.set(ct,Y(st,ve,J,ct,H,je))});var Ne=Be?Xe?d:l:Xe?C:w,Ge=ut?void 0:Ne(H);return r(Ge||H,function(st,ct){Ge&&(ct=st,st=H[ct]),t(Pe,ct,Y(st,ve,J,ct,H,je))}),Pe}return La=Y,La}var Fa,Jh;function sC(){if(Jh)return Fa;Jh=1;var e=dv(),r=4;function t(n){return e(n,r)}return Fa=t,Fa}var za,Zh;function Zd(){if(Zh)return za;Zh=1;function e(r){return function(){return r}}return za=e,za}var Ba,Yh;function cC(){if(Yh)return Ba;Yh=1;function e(r){return function(t,n,o){for(var i=-1,s=Object(t),a=o(t),c=a.length;c--;){var l=a[r?c:++i];if(n(s[l],l,s)===!1)break}return t}}return Ba=e,Ba}var Da,Xh;function Yd(){if(Xh)return Da;Xh=1;var e=cC(),r=e();return Da=r,Da}var Va,Qh;function Xd(){if(Qh)return Va;Qh=1;var e=Yd(),r=br();function t(n,o){return n&&e(n,o,r)}return Va=t,Va}var Wa,ep;function lC(){if(ep)return Wa;ep=1;var e=rr();function r(t,n){return function(o,i){if(o==null)return o;if(!e(o))return t(o,i);for(var s=o.length,a=n?s:-1,c=Object(o);(n?a--:++a<s)&&i(c[a],a,c)!==!1;);return o}}return Wa=r,Wa}var Ga,tp;function ko(){if(tp)return Ga;tp=1;var e=Xd(),r=lC(),t=r(e);return Ga=t,Ga}var Ua,rp;function Tr(){if(rp)return Ua;rp=1;function e(r){return r}return Ua=e,Ua}var Ha,np;function uv(){if(np)return Ha;np=1;var e=Tr();function r(t){return typeof t=="function"?t:e}return Ha=r,Ha}var Ka,op;function fv(){if(op)return Ka;op=1;var e=Vd(),r=ko(),t=uv(),n=yt();function o(i,s){var a=n(i)?e:r;return a(i,t(s))}return Ka=o,Ka}var Ja,ip;function hv(){return ip||(ip=1,Ja=fv()),Ja}var Za,ap;function dC(){if(ap)return Za;ap=1;var e=ko();function r(t,n){var o=[];return e(t,function(i,s,a){n(i,s,a)&&o.push(i)}),o}return Za=r,Za}var Ya,sp;function uC(){if(sp)return Ya;sp=1;var e="__lodash_hash_undefined__";function r(t){return this.__data__.set(t,e),this}return Ya=r,Ya}var Xa,cp;function fC(){if(cp)return Xa;cp=1;function e(r){return this.__data__.has(r)}return Xa=e,Xa}var Qa,lp;function pv(){if(lp)return Qa;lp=1;var e=Dd(),r=uC(),t=fC();function n(o){var i=-1,s=o==null?0:o.length;for(this.__data__=new e;++i<s;)this.add(o[i])}return n.prototype.add=n.prototype.push=r,n.prototype.has=t,Qa=n,Qa}var es,dp;function hC(){if(dp)return es;dp=1;function e(r,t){for(var n=-1,o=r==null?0:r.length;++n<o;)if(t(r[n],n,r))return!0;return!1}return es=e,es}var ts,up;function gv(){if(up)return ts;up=1;function e(r,t){return r.has(t)}return ts=e,ts}var rs,fp;function yv(){if(fp)return rs;fp=1;var e=pv(),r=hC(),t=gv(),n=1,o=2;function i(s,a,c,l,d,u){var h=c&n,p=s.length,m=a.length;if(p!=m&&!(h&&m>p))return!1;var y=u.get(s),g=u.get(a);if(y&&g)return y==a&&g==s;var v=-1,b=!0,x=c&o?new e:void 0;for(u.set(s,a),u.set(a,s);++v<p;){var w=s[v],C=a[v];if(l)var S=h?l(C,w,v,a,s,u):l(w,C,v,s,a,u);if(S!==void 0){if(S)continue;b=!1;break}if(x){if(!r(a,function(_,I){if(!t(x,I)&&(w===_||d(w,_,c,l,u)))return x.push(I)})){b=!1;break}}else if(!(w===C||d(w,C,c,l,u))){b=!1;break}}return u.delete(s),u.delete(a),b}return rs=i,rs}var ns,hp;function pC(){if(hp)return ns;hp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o,i){n[++t]=[i,o]}),n}return ns=e,ns}var os,pp;function Qd(){if(pp)return os;pp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(o){n[++t]=o}),n}return os=e,os}var is,gp;function gC(){if(gp)return is;gp=1;var e=Qr(),r=av(),t=Xr(),n=yv(),o=pC(),i=Qd(),s=1,a=2,c="[object Boolean]",l="[object Date]",d="[object Error]",u="[object Map]",h="[object Number]",p="[object RegExp]",m="[object Set]",y="[object String]",g="[object Symbol]",v="[object ArrayBuffer]",b="[object DataView]",x=e?e.prototype:void 0,w=x?x.valueOf:void 0;function C(S,_,I,E,O,A,R){switch(I){case b:if(S.byteLength!=_.byteLength||S.byteOffset!=_.byteOffset)return!1;S=S.buffer,_=_.buffer;case v:return!(S.byteLength!=_.byteLength||!A(new r(S),new r(_)));case c:case l:case h:return t(+S,+_);case d:return S.name==_.name&&S.message==_.message;case p:case y:return S==_+"";case u:var P=o;case m:var T=E&s;if(P||(P=i),S.size!=_.size&&!T)return!1;var N=R.get(S);if(N)return N==_;E|=a,R.set(S,_);var $=n(P(S),P(_),E,O,A,R);return R.delete(S),$;case g:if(w)return w.call(S)==w.call(_)}return!1}return is=C,is}var as,yp;function yC(){if(yp)return as;yp=1;var e=ov(),r=1,t=Object.prototype,n=t.hasOwnProperty;function o(i,s,a,c,l,d){var u=a&r,h=e(i),p=h.length,m=e(s),y=m.length;if(p!=y&&!u)return!1;for(var g=p;g--;){var v=h[g];if(!(u?v in s:n.call(s,v)))return!1}var b=d.get(i),x=d.get(s);if(b&&x)return b==s&&x==i;var w=!0;d.set(i,s),d.set(s,i);for(var C=u;++g<p;){v=h[g];var S=i[v],_=s[v];if(c)var I=u?c(_,S,v,s,i,d):c(S,_,v,i,s,d);if(!(I===void 0?S===_||l(S,_,a,c,d):I)){w=!1;break}C||(C=v=="constructor")}if(w&&!C){var E=i.constructor,O=s.constructor;E!=O&&"constructor"in i&&"constructor"in s&&!(typeof E=="function"&&E instanceof E&&typeof O=="function"&&O instanceof O)&&(w=!1)}return d.delete(i),d.delete(s),w}return as=o,as}var ss,mp;function mC(){if(mp)return ss;mp=1;var e=xo(),r=yv(),t=gC(),n=yC(),o=tn(),i=yt(),s=en(),a=Fn(),c=1,l="[object Arguments]",d="[object Array]",u="[object Object]",h=Object.prototype,p=h.hasOwnProperty;function m(y,g,v,b,x,w){var C=i(y),S=i(g),_=C?d:o(y),I=S?d:o(g);_=_==l?u:_,I=I==l?u:I;var E=_==u,O=I==u,A=_==I;if(A&&s(y)){if(!s(g))return!1;C=!0,E=!1}if(A&&!E)return w||(w=new e),C||a(y)?r(y,g,v,b,x,w):t(y,g,_,v,b,x,w);if(!(v&c)){var R=E&&p.call(y,"__wrapped__"),P=O&&p.call(g,"__wrapped__");if(R||P){var T=R?y.value():y,N=P?g.value():g;return w||(w=new e),x(T,N,v,b,w)}}return A?(w||(w=new e),n(y,g,v,b,x,w)):!1}return ss=m,ss}var cs,bp;function mv(){if(bp)return cs;bp=1;var e=mC(),r=Xt();function t(n,o,i,s,a){return n===o?!0:n==null||o==null||!r(n)&&!r(o)?n!==n&&o!==o:e(n,o,i,s,t,a)}return cs=t,cs}var ls,vp;function bC(){if(vp)return ls;vp=1;var e=xo(),r=mv(),t=1,n=2;function o(i,s,a,c){var l=a.length,d=l,u=!c;if(i==null)return!d;for(i=Object(i);l--;){var h=a[l];if(u&&h[2]?h[1]!==i[h[0]]:!(h[0]in i))return!1}for(;++l<d;){h=a[l];var p=h[0],m=i[p],y=h[1];if(u&&h[2]){if(m===void 0&&!(p in i))return!1}else{var g=new e;if(c)var v=c(m,y,p,i,s,g);if(!(v===void 0?r(y,m,t|n,c,g):v))return!1}}return!0}return ls=o,ls}var ds,xp;function bv(){if(xp)return ds;xp=1;var e=Ft();function r(t){return t===t&&!e(t)}return ds=r,ds}var us,wp;function vC(){if(wp)return us;wp=1;var e=bv(),r=br();function t(n){for(var o=r(n),i=o.length;i--;){var s=o[i],a=n[s];o[i]=[s,a,e(a)]}return o}return us=t,us}var fs,Cp;function vv(){if(Cp)return fs;Cp=1;function e(r,t){return function(n){return n==null?!1:n[r]===t&&(t!==void 0||r in Object(n))}}return fs=e,fs}var hs,Sp;function xC(){if(Sp)return hs;Sp=1;var e=bC(),r=vC(),t=vv();function n(o){var i=r(o);return i.length==1&&i[0][2]?t(i[0][0],i[0][1]):function(s){return s===o||e(s,o,i)}}return hs=n,hs}var ps,jp;function rn(){if(jp)return ps;jp=1;var e=Pr(),r=Xt(),t="[object Symbol]";function n(o){return typeof o=="symbol"||r(o)&&e(o)==t}return ps=n,ps}var gs,_p;function eu(){if(_p)return gs;_p=1;var e=yt(),r=rn(),t=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function o(i,s){if(e(i))return!1;var a=typeof i;return a=="number"||a=="symbol"||a=="boolean"||i==null||r(i)?!0:n.test(i)||!t.test(i)||s!=null&&i in Object(s)}return gs=o,gs}var ys,Ep;function wC(){if(Ep)return ys;Ep=1;var e=Dd(),r="Expected a function";function t(n,o){if(typeof n!="function"||o!=null&&typeof o!="function")throw new TypeError(r);var i=function(){var s=arguments,a=o?o.apply(this,s):s[0],c=i.cache;if(c.has(a))return c.get(a);var l=n.apply(this,s);return i.cache=c.set(a,l)||c,l};return i.cache=new(t.Cache||e),i}return t.Cache=e,ys=t,ys}var ms,kp;function CC(){if(kp)return ms;kp=1;var e=wC(),r=500;function t(n){var o=e(n,function(s){return i.size===r&&i.clear(),s}),i=o.cache;return o}return ms=t,ms}var bs,Rp;function SC(){if(Rp)return bs;Rp=1;var e=CC(),r=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,t=/\\(\\)?/g,n=e(function(o){var i=[];return o.charCodeAt(0)===46&&i.push(""),o.replace(r,function(s,a,c,l){i.push(c?l.replace(t,"$1"):a||s)}),i});return bs=n,bs}var vs,Ap;function Ro(){if(Ap)return vs;Ap=1;function e(r,t){for(var n=-1,o=r==null?0:r.length,i=Array(o);++n<o;)i[n]=t(r[n],n,r);return i}return vs=e,vs}var xs,Pp;function jC(){if(Pp)return xs;Pp=1;var e=Qr(),r=Ro(),t=yt(),n=rn(),o=e?e.prototype:void 0,i=o?o.toString:void 0;function s(a){if(typeof a=="string")return a;if(t(a))return r(a,s)+"";if(n(a))return i?i.call(a):"";var c=a+"";return c=="0"&&1/a==-1/0?"-0":c}return xs=s,xs}var ws,Mp;function xv(){if(Mp)return ws;Mp=1;var e=jC();function r(t){return t==null?"":e(t)}return ws=r,ws}var Cs,Ip;function Ao(){if(Ip)return Cs;Ip=1;var e=yt(),r=eu(),t=SC(),n=xv();function o(i,s){return e(i)?i:r(i,s)?[i]:t(n(i))}return Cs=o,Cs}var Ss,Tp;function zn(){if(Tp)return Ss;Tp=1;var e=rn();function r(t){if(typeof t=="string"||e(t))return t;var n=t+"";return n=="0"&&1/t==-1/0?"-0":n}return Ss=r,Ss}var js,Op;function Po(){if(Op)return js;Op=1;var e=Ao(),r=zn();function t(n,o){o=e(o,n);for(var i=0,s=o.length;n!=null&&i<s;)n=n[r(o[i++])];return i&&i==s?n:void 0}return js=t,js}var _s,Np;function _C(){if(Np)return _s;Np=1;var e=Po();function r(t,n,o){var i=t==null?void 0:e(t,n);return i===void 0?o:i}return _s=r,_s}var Es,$p;function EC(){if($p)return Es;$p=1;function e(r,t){return r!=null&&t in Object(r)}return Es=e,Es}var ks,qp;function wv(){if(qp)return ks;qp=1;var e=Ao(),r=Ln(),t=yt(),n=So(),o=Wd(),i=zn();function s(a,c,l){c=e(c,a);for(var d=-1,u=c.length,h=!1;++d<u;){var p=i(c[d]);if(!(h=a!=null&&l(a,p)))break;a=a[p]}return h||++d!=u?h:(u=a==null?0:a.length,!!u&&o(u)&&n(p,u)&&(t(a)||r(a)))}return ks=s,ks}var Rs,Lp;function Cv(){if(Lp)return Rs;Lp=1;var e=EC(),r=wv();function t(n,o){return n!=null&&r(n,o,e)}return Rs=t,Rs}var As,Fp;function kC(){if(Fp)return As;Fp=1;var e=mv(),r=_C(),t=Cv(),n=eu(),o=bv(),i=vv(),s=zn(),a=1,c=2;function l(d,u){return n(d)&&o(u)?i(s(d),u):function(h){var p=r(h,d);return p===void 0&&p===u?t(h,d):e(u,p,a|c)}}return As=l,As}var Ps,zp;function Sv(){if(zp)return Ps;zp=1;function e(r){return function(t){return t==null?void 0:t[r]}}return Ps=e,Ps}var Ms,Bp;function RC(){if(Bp)return Ms;Bp=1;var e=Po();function r(t){return function(n){return e(n,t)}}return Ms=r,Ms}var Is,Dp;function AC(){if(Dp)return Is;Dp=1;var e=Sv(),r=RC(),t=eu(),n=zn();function o(i){return t(i)?e(n(i)):r(i)}return Is=o,Is}var Ts,Vp;function nr(){if(Vp)return Ts;Vp=1;var e=xC(),r=kC(),t=Tr(),n=yt(),o=AC();function i(s){return typeof s=="function"?s:s==null?t:typeof s=="object"?n(s)?r(s[0],s[1]):e(s):o(s)}return Ts=i,Ts}var Os,Wp;function jv(){if(Wp)return Os;Wp=1;var e=ev(),r=dC(),t=nr(),n=yt();function o(i,s){var a=n(i)?e:r;return a(i,t(s,3))}return Os=o,Os}var Ns,Gp;function PC(){if(Gp)return Ns;Gp=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n,o){return n!=null&&r.call(n,o)}return Ns=t,Ns}var $s,Up;function _v(){if(Up)return $s;Up=1;var e=PC(),r=wv();function t(n,o){return n!=null&&r(n,o,e)}return $s=t,$s}var qs,Hp;function MC(){if(Hp)return qs;Hp=1;var e=Ud(),r=tn(),t=Ln(),n=yt(),o=rr(),i=en(),s=_o(),a=Fn(),c="[object Map]",l="[object Set]",d=Object.prototype,u=d.hasOwnProperty;function h(p){if(p==null)return!0;if(o(p)&&(n(p)||typeof p=="string"||typeof p.splice=="function"||i(p)||a(p)||t(p)))return!p.length;var m=r(p);if(m==c||m==l)return!p.size;if(s(p))return!e(p).length;for(var y in p)if(u.call(p,y))return!1;return!0}return qs=h,qs}var Ls,Kp;function Ev(){if(Kp)return Ls;Kp=1;function e(r){return r===void 0}return Ls=e,Ls}var Fs,Jp;function kv(){if(Jp)return Fs;Jp=1;var e=ko(),r=rr();function t(n,o){var i=-1,s=r(n)?Array(n.length):[];return e(n,function(a,c,l){s[++i]=o(a,c,l)}),s}return Fs=t,Fs}var zs,Zp;function Rv(){if(Zp)return zs;Zp=1;var e=Ro(),r=nr(),t=kv(),n=yt();function o(i,s){var a=n(i)?e:t;return a(i,r(s,3))}return zs=o,zs}var Bs,Yp;function IC(){if(Yp)return Bs;Yp=1;function e(r,t,n,o){var i=-1,s=r==null?0:r.length;for(o&&s&&(n=r[++i]);++i<s;)n=t(n,r[i],i,r);return n}return Bs=e,Bs}var Ds,Xp;function TC(){if(Xp)return Ds;Xp=1;function e(r,t,n,o,i){return i(r,function(s,a,c){n=o?(o=!1,s):t(n,s,a,c)}),n}return Ds=e,Ds}var Vs,Qp;function Av(){if(Qp)return Vs;Qp=1;var e=IC(),r=ko(),t=nr(),n=TC(),o=yt();function i(s,a,c){var l=o(s)?e:n,d=arguments.length<3;return l(s,t(a,4),c,d,r)}return Vs=i,Vs}var Ws,eg;function OC(){if(eg)return Ws;eg=1;var e=Pr(),r=yt(),t=Xt(),n="[object String]";function o(i){return typeof i=="string"||!r(i)&&t(i)&&e(i)==n}return Ws=o,Ws}var Gs,tg;function NC(){if(tg)return Gs;tg=1;var e=Sv(),r=e("length");return Gs=r,Gs}var Us,rg;function $C(){if(rg)return Us;rg=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=r+t+n,i="\\ufe0e\\ufe0f",s="\\u200d",a=RegExp("["+s+e+o+i+"]");function c(l){return a.test(l)}return Us=c,Us}var Hs,ng;function qC(){if(ng)return Hs;ng=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",o=r+t+n,i="\\ufe0e\\ufe0f",s="["+e+"]",a="["+o+"]",c="\\ud83c[\\udffb-\\udfff]",l="(?:"+a+"|"+c+")",d="[^"+e+"]",u="(?:\\ud83c[\\udde6-\\uddff]){2}",h="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",m=l+"?",y="["+i+"]?",g="(?:"+p+"(?:"+[d,u,h].join("|")+")"+y+m+")*",v=y+m+g,b="(?:"+[d+a+"?",a,u,h,s].join("|")+")",x=RegExp(c+"(?="+c+")|"+b+v,"g");function w(C){for(var S=x.lastIndex=0;x.test(C);)++S;return S}return Hs=w,Hs}var Ks,og;function LC(){if(og)return Ks;og=1;var e=NC(),r=$C(),t=qC();function n(o){return r(o)?t(o):e(o)}return Ks=n,Ks}var Js,ig;function FC(){if(ig)return Js;ig=1;var e=Ud(),r=tn(),t=rr(),n=OC(),o=LC(),i="[object Map]",s="[object Set]";function a(c){if(c==null)return 0;if(t(c))return n(c)?o(c):c.length;var l=r(c);return l==i||l==s?c.size:e(c).length}return Js=a,Js}var Zs,ag;function zC(){if(ag)return Zs;ag=1;var e=Vd(),r=cv(),t=Xd(),n=nr(),o=Eo(),i=yt(),s=en(),a=$n(),c=Ft(),l=Fn();function d(u,h,p){var m=i(u),y=m||s(u)||l(u);if(h=n(h,4),p==null){var g=u&&u.constructor;y?p=m?new g:[]:c(u)?p=a(g)?r(o(u)):{}:p={}}return(y?e:t)(u,function(v,b,x){return h(p,v,b,x)}),p}return Zs=d,Zs}var Ys,sg;function BC(){if(sg)return Ys;sg=1;var e=Qr(),r=Ln(),t=yt(),n=e?e.isConcatSpreadable:void 0;function o(i){return t(i)||r(i)||!!(n&&i&&i[n])}return Ys=o,Ys}var Xs,cg;function tu(){if(cg)return Xs;cg=1;var e=Kd(),r=BC();function t(n,o,i,s,a){var c=-1,l=n.length;for(i||(i=r),a||(a=[]);++c<l;){var d=n[c];o>0&&i(d)?o>1?t(d,o-1,i,s,a):e(a,d):s||(a[a.length]=d)}return a}return Xs=t,Xs}var Qs,lg;function DC(){if(lg)return Qs;lg=1;function e(r,t,n){switch(n.length){case 0:return r.call(t);case 1:return r.call(t,n[0]);case 2:return r.call(t,n[0],n[1]);case 3:return r.call(t,n[0],n[1],n[2])}return r.apply(t,n)}return Qs=e,Qs}var ec,dg;function Pv(){if(dg)return ec;dg=1;var e=DC(),r=Math.max;function t(n,o,i){return o=r(o===void 0?n.length-1:o,0),function(){for(var s=arguments,a=-1,c=r(s.length-o,0),l=Array(c);++a<c;)l[a]=s[o+a];a=-1;for(var d=Array(o+1);++a<o;)d[a]=s[a];return d[o]=i(l),e(n,this,d)}}return ec=t,ec}var tc,ug;function VC(){if(ug)return tc;ug=1;var e=Zd(),r=Jb(),t=Tr(),n=r?function(o,i){return r(o,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:t;return tc=n,tc}var rc,fg;function WC(){if(fg)return rc;fg=1;var e=800,r=16,t=Date.now;function n(o){var i=0,s=0;return function(){var a=t(),c=r-(a-s);if(s=a,c>0){if(++i>=e)return arguments[0]}else i=0;return o.apply(void 0,arguments)}}return rc=n,rc}var nc,hg;function Mv(){if(hg)return nc;hg=1;var e=VC(),r=WC(),t=r(e);return nc=t,nc}var oc,pg;function Mo(){if(pg)return oc;pg=1;var e=Tr(),r=Pv(),t=Mv();function n(o,i){return t(r(o,i,e),o+"")}return oc=n,oc}var ic,gg;function Iv(){if(gg)return ic;gg=1;function e(r,t,n,o){for(var i=r.length,s=n+(o?1:-1);o?s--:++s<i;)if(t(r[s],s,r))return s;return-1}return ic=e,ic}var ac,yg;function GC(){if(yg)return ac;yg=1;function e(r){return r!==r}return ac=e,ac}var sc,mg;function UC(){if(mg)return sc;mg=1;function e(r,t,n){for(var o=n-1,i=r.length;++o<i;)if(r[o]===t)return o;return-1}return sc=e,sc}var cc,bg;function HC(){if(bg)return cc;bg=1;var e=Iv(),r=GC(),t=UC();function n(o,i,s){return i===i?t(o,i,s):e(o,r,s)}return cc=n,cc}var lc,vg;function KC(){if(vg)return lc;vg=1;var e=HC();function r(t,n){var o=t==null?0:t.length;return!!o&&e(t,n,0)>-1}return lc=r,lc}var dc,xg;function JC(){if(xg)return dc;xg=1;function e(r,t,n){for(var o=-1,i=r==null?0:r.length;++o<i;)if(n(t,r[o]))return!0;return!1}return dc=e,dc}var uc,wg;function ZC(){if(wg)return uc;wg=1;function e(){}return uc=e,uc}var fc,Cg;function YC(){if(Cg)return fc;Cg=1;var e=iv(),r=ZC(),t=Qd(),n=1/0,o=e&&1/t(new e([,-0]))[1]==n?function(i){return new e(i)}:r;return fc=o,fc}var hc,Sg;function XC(){if(Sg)return hc;Sg=1;var e=pv(),r=KC(),t=JC(),n=gv(),o=YC(),i=Qd(),s=200;function a(c,l,d){var u=-1,h=r,p=c.length,m=!0,y=[],g=y;if(d)m=!1,h=t;else if(p>=s){var v=l?null:o(c);if(v)return i(v);m=!1,h=n,g=new e}else g=l?[]:y;e:for(;++u<p;){var b=c[u],x=l?l(b):b;if(b=d||b!==0?b:0,m&&x===x){for(var w=g.length;w--;)if(g[w]===x)continue e;l&&g.push(x),y.push(b)}else h(g,x,d)||(g!==y&&g.push(x),y.push(b))}return y}return hc=a,hc}var pc,jg;function Tv(){if(jg)return pc;jg=1;var e=rr(),r=Xt();function t(n){return r(n)&&e(n)}return pc=t,pc}var gc,_g;function QC(){if(_g)return gc;_g=1;var e=tu(),r=Mo(),t=XC(),n=Tv(),o=r(function(i){return t(e(i,1,n,!0))});return gc=o,gc}var yc,Eg;function eS(){if(Eg)return yc;Eg=1;var e=Ro();function r(t,n){return e(n,function(o){return t[o]})}return yc=r,yc}var mc,kg;function Ov(){if(kg)return mc;kg=1;var e=eS(),r=br();function t(n){return n==null?[]:e(n,r(n))}return mc=t,mc}var bc,Rg;function zt(){if(Rg)return bc;Rg=1;var e;if(typeof zd=="function")try{e={clone:sC(),constant:Zd(),each:hv(),filter:jv(),has:_v(),isArray:yt(),isEmpty:MC(),isFunction:$n(),isUndefined:Ev(),keys:br(),map:Rv(),reduce:Av(),size:FC(),transform:zC(),union:QC(),values:Ov()}}catch{}return e||(e=window._),bc=e,bc}var vc,Ag;function ru(){if(Ag)return vc;Ag=1;var e=zt();vc=o;var r="\0",t="\0",n="";function o(d){this._isDirected=e.has(d,"directed")?d.directed:!0,this._isMultigraph=e.has(d,"multigraph")?d.multigraph:!1,this._isCompound=e.has(d,"compound")?d.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[t]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}o.prototype._nodeCount=0,o.prototype._edgeCount=0,o.prototype.isDirected=function(){return this._isDirected},o.prototype.isMultigraph=function(){return this._isMultigraph},o.prototype.isCompound=function(){return this._isCompound},o.prototype.setGraph=function(d){return this._label=d,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultNodeLabelFn=d,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._in[u])})},o.prototype.sinks=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._out[u])})},o.prototype.setNodes=function(d,u){var h=arguments,p=this;return e.each(d,function(m){h.length>1?p.setNode(m,u):p.setNode(m)}),this},o.prototype.setNode=function(d,u){return e.has(this._nodes,d)?(arguments.length>1&&(this._nodes[d]=u),this):(this._nodes[d]=arguments.length>1?u:this._defaultNodeLabelFn(d),this._isCompound&&(this._parent[d]=t,this._children[d]={},this._children[t][d]=!0),this._in[d]={},this._preds[d]={},this._out[d]={},this._sucs[d]={},++this._nodeCount,this)},o.prototype.node=function(d){return this._nodes[d]},o.prototype.hasNode=function(d){return e.has(this._nodes,d)},o.prototype.removeNode=function(d){var u=this;if(e.has(this._nodes,d)){var h=function(p){u.removeEdge(u._edgeObjs[p])};delete this._nodes[d],this._isCompound&&(this._removeFromParentsChildList(d),delete this._parent[d],e.each(this.children(d),function(p){u.setParent(p)}),delete this._children[d]),e.each(e.keys(this._in[d]),h),delete this._in[d],delete this._preds[d],e.each(e.keys(this._out[d]),h),delete this._out[d],delete this._sucs[d],--this._nodeCount}return this},o.prototype.setParent=function(d,u){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(u))u=t;else{u+="";for(var h=u;!e.isUndefined(h);h=this.parent(h))if(h===d)throw new Error("Setting "+u+" as parent of "+d+" would create a cycle");this.setNode(u)}return this.setNode(d),this._removeFromParentsChildList(d),this._parent[d]=u,this._children[u][d]=!0,this},o.prototype._removeFromParentsChildList=function(d){delete this._children[this._parent[d]][d]},o.prototype.parent=function(d){if(this._isCompound){var u=this._parent[d];if(u!==t)return u}},o.prototype.children=function(d){if(e.isUndefined(d)&&(d=t),this._isCompound){var u=this._children[d];if(u)return e.keys(u)}else{if(d===t)return this.nodes();if(this.hasNode(d))return[]}},o.prototype.predecessors=function(d){var u=this._preds[d];if(u)return e.keys(u)},o.prototype.successors=function(d){var u=this._sucs[d];if(u)return e.keys(u)},o.prototype.neighbors=function(d){var u=this.predecessors(d);if(u)return e.union(u,this.successors(d))},o.prototype.isLeaf=function(d){var u;return this.isDirected()?u=this.successors(d):u=this.neighbors(d),u.length===0},o.prototype.filterNodes=function(d){var u=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});u.setGraph(this.graph());var h=this;e.each(this._nodes,function(y,g){d(g)&&u.setNode(g,y)}),e.each(this._edgeObjs,function(y){u.hasNode(y.v)&&u.hasNode(y.w)&&u.setEdge(y,h.edge(y))});var p={};function m(y){var g=h.parent(y);return g===void 0||u.hasNode(g)?(p[y]=g,g):g in p?p[g]:m(g)}return this._isCompound&&e.each(u.nodes(),function(y){u.setParent(y,m(y))}),u},o.prototype.setDefaultEdgeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultEdgeLabelFn=d,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(d,u){var h=this,p=arguments;return e.reduce(d,function(m,y){return p.length>1?h.setEdge(m,y,u):h.setEdge(m,y),y}),this},o.prototype.setEdge=function(){var d,u,h,p,m=!1,y=arguments[0];typeof y=="object"&&y!==null&&"v"in y?(d=y.v,u=y.w,h=y.name,arguments.length===2&&(p=arguments[1],m=!0)):(d=y,u=arguments[1],h=arguments[3],arguments.length>2&&(p=arguments[2],m=!0)),d=""+d,u=""+u,e.isUndefined(h)||(h=""+h);var g=a(this._isDirected,d,u,h);if(e.has(this._edgeLabels,g))return m&&(this._edgeLabels[g]=p),this;if(!e.isUndefined(h)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(d),this.setNode(u),this._edgeLabels[g]=m?p:this._defaultEdgeLabelFn(d,u,h);var v=c(this._isDirected,d,u,h);return d=v.v,u=v.w,Object.freeze(v),this._edgeObjs[g]=v,i(this._preds[u],d),i(this._sucs[d],u),this._in[u][g]=v,this._out[d][g]=v,this._edgeCount++,this},o.prototype.edge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h);return this._edgeLabels[p]},o.prototype.hasEdge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h);return e.has(this._edgeLabels,p)},o.prototype.removeEdge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h),m=this._edgeObjs[p];return m&&(d=m.v,u=m.w,delete this._edgeLabels[p],delete this._edgeObjs[p],s(this._preds[u],d),s(this._sucs[d],u),delete this._in[u][p],delete this._out[d][p],this._edgeCount--),this},o.prototype.inEdges=function(d,u){var h=this._in[d];if(h){var p=e.values(h);return u?e.filter(p,function(m){return m.v===u}):p}},o.prototype.outEdges=function(d,u){var h=this._out[d];if(h){var p=e.values(h);return u?e.filter(p,function(m){return m.w===u}):p}},o.prototype.nodeEdges=function(d,u){var h=this.inEdges(d,u);if(h)return h.concat(this.outEdges(d,u))};function i(d,u){d[u]?d[u]++:d[u]=1}function s(d,u){--d[u]||delete d[u]}function a(d,u,h,p){var m=""+u,y=""+h;if(!d&&m>y){var g=m;m=y,y=g}return m+n+y+n+(e.isUndefined(p)?r:p)}function c(d,u,h,p){var m=""+u,y=""+h;if(!d&&m>y){var g=m;m=y,y=g}var v={v:m,w:y};return p&&(v.name=p),v}function l(d,u){return a(d,u.v,u.w,u.name)}return vc}var xc,Pg;function tS(){return Pg||(Pg=1,xc="2.1.8"),xc}var wc,Mg;function rS(){return Mg||(Mg=1,wc={Graph:ru(),version:tS()}),wc}var Cc,Ig;function nS(){if(Ig)return Cc;Ig=1;var e=zt(),r=ru();Cc={write:t,read:i};function t(s){var a={options:{directed:s.isDirected(),multigraph:s.isMultigraph(),compound:s.isCompound()},nodes:n(s),edges:o(s)};return e.isUndefined(s.graph())||(a.value=e.clone(s.graph())),a}function n(s){return e.map(s.nodes(),function(a){var c=s.node(a),l=s.parent(a),d={v:a};return e.isUndefined(c)||(d.value=c),e.isUndefined(l)||(d.parent=l),d})}function o(s){return e.map(s.edges(),function(a){var c=s.edge(a),l={v:a.v,w:a.w};return e.isUndefined(a.name)||(l.name=a.name),e.isUndefined(c)||(l.value=c),l})}function i(s){var a=new r(s.options).setGraph(s.value);return e.each(s.nodes,function(c){a.setNode(c.v,c.value),c.parent&&a.setParent(c.v,c.parent)}),e.each(s.edges,function(c){a.setEdge({v:c.v,w:c.w,name:c.name},c.value)}),a}return Cc}var Sc,Tg;function oS(){if(Tg)return Sc;Tg=1;var e=zt();Sc=r;function r(t){var n={},o=[],i;function s(a){e.has(n,a)||(n[a]=!0,i.push(a),e.each(t.successors(a),s),e.each(t.predecessors(a),s))}return e.each(t.nodes(),function(a){i=[],s(a),i.length&&o.push(i)}),o}return Sc}var jc,Og;function Nv(){if(Og)return jc;Og=1;var e=zt();jc=r;function r(){this._arr=[],this._keyIndices={}}return r.prototype.size=function(){return this._arr.length},r.prototype.keys=function(){return this._arr.map(function(t){return t.key})},r.prototype.has=function(t){return e.has(this._keyIndices,t)},r.prototype.priority=function(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority},r.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},r.prototype.add=function(t,n){var o=this._keyIndices;if(t=String(t),!e.has(o,t)){var i=this._arr,s=i.length;return o[t]=s,i.push({key:t,priority:n}),this._decrease(s),!0}return!1},r.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key},r.prototype.decrease=function(t,n){var o=this._keyIndices[t];if(n>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[o].priority+" New: "+n);this._arr[o].priority=n,this._decrease(o)},r.prototype._heapify=function(t){var n=this._arr,o=2*t,i=o+1,s=t;o<n.length&&(s=n[o].priority<n[s].priority?o:s,i<n.length&&(s=n[i].priority<n[s].priority?i:s),s!==t&&(this._swap(t,s),this._heapify(s)))},r.prototype._decrease=function(t){for(var n=this._arr,o=n[t].priority,i;t!==0&&(i=t>>1,!(n[i].priority<o));)this._swap(t,i),t=i},r.prototype._swap=function(t,n){var o=this._arr,i=this._keyIndices,s=o[t],a=o[n];o[t]=a,o[n]=s,i[a.key]=t,i[s.key]=n},jc}var _c,Ng;function $v(){if(Ng)return _c;Ng=1;var e=zt(),r=Nv();_c=n;var t=e.constant(1);function n(i,s,a,c){return o(i,String(s),a||t,c||function(l){return i.outEdges(l)})}function o(i,s,a,c){var l={},d=new r,u,h,p=function(m){var y=m.v!==u?m.v:m.w,g=l[y],v=a(m),b=h.distance+v;if(v<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+m+" Weight: "+v);b<g.distance&&(g.distance=b,g.predecessor=u,d.decrease(y,b))};for(i.nodes().forEach(function(m){var y=m===s?0:Number.POSITIVE_INFINITY;l[m]={distance:y},d.add(m,y)});d.size()>0&&(u=d.removeMin(),h=l[u],h.distance!==Number.POSITIVE_INFINITY);)c(u).forEach(p);return l}return _c}var Ec,$g;function iS(){if($g)return Ec;$g=1;var e=$v(),r=zt();Ec=t;function t(n,o,i){return r.transform(n.nodes(),function(s,a){s[a]=e(n,a,o,i)},{})}return Ec}var kc,qg;function qv(){if(qg)return kc;qg=1;var e=zt();kc=r;function r(t){var n=0,o=[],i={},s=[];function a(c){var l=i[c]={onStack:!0,lowlink:n,index:n++};if(o.push(c),t.successors(c).forEach(function(h){e.has(i,h)?i[h].onStack&&(l.lowlink=Math.min(l.lowlink,i[h].index)):(a(h),l.lowlink=Math.min(l.lowlink,i[h].lowlink))}),l.lowlink===l.index){var d=[],u;do u=o.pop(),i[u].onStack=!1,d.push(u);while(c!==u);s.push(d)}}return t.nodes().forEach(function(c){e.has(i,c)||a(c)}),s}return kc}var Rc,Lg;function aS(){if(Lg)return Rc;Lg=1;var e=zt(),r=qv();Rc=t;function t(n){return e.filter(r(n),function(o){return o.length>1||o.length===1&&n.hasEdge(o[0],o[0])})}return Rc}var Ac,Fg;function sS(){if(Fg)return Ac;Fg=1;var e=zt();Ac=t;var r=e.constant(1);function t(o,i,s){return n(o,i||r,s||function(a){return o.outEdges(a)})}function n(o,i,s){var a={},c=o.nodes();return c.forEach(function(l){a[l]={},a[l][l]={distance:0},c.forEach(function(d){l!==d&&(a[l][d]={distance:Number.POSITIVE_INFINITY})}),s(l).forEach(function(d){var u=d.v===l?d.w:d.v,h=i(d);a[l][u]={distance:h,predecessor:l}})}),c.forEach(function(l){var d=a[l];c.forEach(function(u){var h=a[u];c.forEach(function(p){var m=h[l],y=d[p],g=h[p],v=m.distance+y.distance;v<g.distance&&(g.distance=v,g.predecessor=y.predecessor)})})}),a}return Ac}var Pc,zg;function Lv(){if(zg)return Pc;zg=1;var e=zt();Pc=r,r.CycleException=t;function r(n){var o={},i={},s=[];function a(c){if(e.has(i,c))throw new t;e.has(o,c)||(i[c]=!0,o[c]=!0,e.each(n.predecessors(c),a),delete i[c],s.push(c))}if(e.each(n.sinks(),a),e.size(o)!==n.nodeCount())throw new t;return s}function t(){}return t.prototype=new Error,Pc}var Mc,Bg;function cS(){if(Bg)return Mc;Bg=1;var e=Lv();Mc=r;function r(t){try{e(t)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return Mc}var Ic,Dg;function Fv(){if(Dg)return Ic;Dg=1;var e=zt();Ic=r;function r(n,o,i){e.isArray(o)||(o=[o]);var s=(n.isDirected()?n.successors:n.neighbors).bind(n),a=[],c={};return e.each(o,function(l){if(!n.hasNode(l))throw new Error("Graph does not have node: "+l);t(n,l,i==="post",c,s,a)}),a}function t(n,o,i,s,a,c){e.has(s,o)||(s[o]=!0,i||c.push(o),e.each(a(o),function(l){t(n,l,i,s,a,c)}),i&&c.push(o))}return Ic}var Tc,Vg;function lS(){if(Vg)return Tc;Vg=1;var e=Fv();Tc=r;function r(t,n){return e(t,n,"post")}return Tc}var Oc,Wg;function dS(){if(Wg)return Oc;Wg=1;var e=Fv();Oc=r;function r(t,n){return e(t,n,"pre")}return Oc}var Nc,Gg;function uS(){if(Gg)return Nc;Gg=1;var e=zt(),r=ru(),t=Nv();Nc=n;function n(o,i){var s=new r,a={},c=new t,l;function d(h){var p=h.v===l?h.w:h.v,m=c.priority(p);if(m!==void 0){var y=i(h);y<m&&(a[p]=l,c.decrease(p,y))}}if(o.nodeCount()===0)return s;e.each(o.nodes(),function(h){c.add(h,Number.POSITIVE_INFINITY),s.setNode(h)}),c.decrease(o.nodes()[0],0);for(var u=!1;c.size()>0;){if(l=c.removeMin(),e.has(a,l))s.setEdge(l,a[l]);else{if(u)throw new Error("Input graph is not connected: "+o);u=!0}o.nodeEdges(l).forEach(d)}return s}return Nc}var $c,Ug;function fS(){return Ug||(Ug=1,$c={components:oS(),dijkstra:$v(),dijkstraAll:iS(),findCycles:aS(),floydWarshall:sS(),isAcyclic:cS(),postorder:lS(),preorder:dS(),prim:uS(),tarjan:qv(),topsort:Lv()}),$c}var qc,Hg;function hS(){if(Hg)return qc;Hg=1;var e=rS();return qc={Graph:e.Graph,json:nS(),alg:fS(),version:e.version},qc}var Lc,Kg;function Wt(){if(Kg)return Lc;Kg=1;var e;if(typeof zd=="function")try{e=hS()}catch{}return e||(e=window.graphlib),Lc=e,Lc}var Fc,Jg;function pS(){if(Jg)return Fc;Jg=1;var e=dv(),r=1,t=4;function n(o){return e(o,r|t)}return Fc=n,Fc}var zc,Zg;function Io(){if(Zg)return zc;Zg=1;var e=Xr(),r=rr(),t=So(),n=Ft();function o(i,s,a){if(!n(a))return!1;var c=typeof s;return(c=="number"?r(a)&&t(s,a.length):c=="string"&&s in a)?e(a[s],i):!1}return zc=o,zc}var Bc,Yg;function gS(){if(Yg)return Bc;Yg=1;var e=Mo(),r=Xr(),t=Io(),n=Ir(),o=Object.prototype,i=o.hasOwnProperty,s=e(function(a,c){a=Object(a);var l=-1,d=c.length,u=d>2?c[2]:void 0;for(u&&t(c[0],c[1],u)&&(d=1);++l<d;)for(var h=c[l],p=n(h),m=-1,y=p.length;++m<y;){var g=p[m],v=a[g];(v===void 0||r(v,o[g])&&!i.call(a,g))&&(a[g]=h[g])}return a});return Bc=s,Bc}var Dc,Xg;function yS(){if(Xg)return Dc;Xg=1;var e=nr(),r=rr(),t=br();function n(o){return function(i,s,a){var c=Object(i);if(!r(i)){var l=e(s,3);i=t(i),s=function(u){return l(c[u],u,c)}}var d=o(i,s,a);return d>-1?c[l?i[d]:d]:void 0}}return Dc=n,Dc}var Vc,Qg;function mS(){if(Qg)return Vc;Qg=1;var e=/\s/;function r(t){for(var n=t.length;n--&&e.test(t.charAt(n)););return n}return Vc=r,Vc}var Wc,ey;function bS(){if(ey)return Wc;ey=1;var e=mS(),r=/^\s+/;function t(n){return n&&n.slice(0,e(n)+1).replace(r,"")}return Wc=t,Wc}var Gc,ty;function vS(){if(ty)return Gc;ty=1;var e=bS(),r=Ft(),t=rn(),n=NaN,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,s=/^0o[0-7]+$/i,a=parseInt;function c(l){if(typeof l=="number")return l;if(t(l))return n;if(r(l)){var d=typeof l.valueOf=="function"?l.valueOf():l;l=r(d)?d+"":d}if(typeof l!="string")return l===0?l:+l;l=e(l);var u=i.test(l);return u||s.test(l)?a(l.slice(2),u?2:8):o.test(l)?n:+l}return Gc=c,Gc}var Uc,ry;function zv(){if(ry)return Uc;ry=1;var e=vS(),r=1/0,t=17976931348623157e292;function n(o){if(!o)return o===0?o:0;if(o=e(o),o===r||o===-r){var i=o<0?-1:1;return i*t}return o===o?o:0}return Uc=n,Uc}var Hc,ny;function xS(){if(ny)return Hc;ny=1;var e=zv();function r(t){var n=e(t),o=n%1;return n===n?o?n-o:n:0}return Hc=r,Hc}var Kc,oy;function wS(){if(oy)return Kc;oy=1;var e=Iv(),r=nr(),t=xS(),n=Math.max;function o(i,s,a){var c=i==null?0:i.length;if(!c)return-1;var l=a==null?0:t(a);return l<0&&(l=n(c+l,0)),e(i,r(s,3),l)}return Kc=o,Kc}var Jc,iy;function CS(){if(iy)return Jc;iy=1;var e=yS(),r=wS(),t=e(r);return Jc=t,Jc}var Zc,ay;function Bv(){if(ay)return Zc;ay=1;var e=tu();function r(t){var n=t==null?0:t.length;return n?e(t,1):[]}return Zc=r,Zc}var Yc,sy;function SS(){if(sy)return Yc;sy=1;var e=Yd(),r=uv(),t=Ir();function n(o,i){return o==null?o:e(o,r(i),t)}return Yc=n,Yc}var Xc,cy;function jS(){if(cy)return Xc;cy=1;function e(r){var t=r==null?0:r.length;return t?r[t-1]:void 0}return Xc=e,Xc}var Qc,ly;function _S(){if(ly)return Qc;ly=1;var e=wo(),r=Xd(),t=nr();function n(o,i){var s={};return i=t(i,3),r(o,function(a,c,l){e(s,c,i(a,c,l))}),s}return Qc=n,Qc}var el,dy;function nu(){if(dy)return el;dy=1;var e=rn();function r(t,n,o){for(var i=-1,s=t.length;++i<s;){var a=t[i],c=n(a);if(c!=null&&(l===void 0?c===c&&!e(c):o(c,l)))var l=c,d=a}return d}return el=r,el}var tl,uy;function ES(){if(uy)return tl;uy=1;function e(r,t){return r>t}return tl=e,tl}var rl,fy;function kS(){if(fy)return rl;fy=1;var e=nu(),r=ES(),t=Tr();function n(o){return o&&o.length?e(o,t,r):void 0}return rl=n,rl}var nl,hy;function Dv(){if(hy)return nl;hy=1;var e=wo(),r=Xr();function t(n,o,i){(i!==void 0&&!r(n[o],i)||i===void 0&&!(o in n))&&e(n,o,i)}return nl=t,nl}var ol,py;function RS(){if(py)return ol;py=1;var e=Pr(),r=Eo(),t=Xt(),n="[object Object]",o=Function.prototype,i=Object.prototype,s=o.toString,a=i.hasOwnProperty,c=s.call(Object);function l(d){if(!t(d)||e(d)!=n)return!1;var u=r(d);if(u===null)return!0;var h=a.call(u,"constructor")&&u.constructor;return typeof h=="function"&&h instanceof h&&s.call(h)==c}return ol=l,ol}var il,gy;function Vv(){if(gy)return il;gy=1;function e(r,t){if(!(t==="constructor"&&typeof r[t]=="function")&&t!="__proto__")return r[t]}return il=e,il}var al,yy;function AS(){if(yy)return al;yy=1;var e=qn(),r=Ir();function t(n){return e(n,r(n))}return al=t,al}var sl,my;function PS(){if(my)return sl;my=1;var e=Dv(),r=Xb(),t=sv(),n=Qb(),o=lv(),i=Ln(),s=yt(),a=Tv(),c=en(),l=$n(),d=Ft(),u=RS(),h=Fn(),p=Vv(),m=AS();function y(g,v,b,x,w,C,S){var _=p(g,b),I=p(v,b),E=S.get(I);if(E){e(g,b,E);return}var O=C?C(_,I,b+"",g,v,S):void 0,A=O===void 0;if(A){var R=s(I),P=!R&&c(I),T=!R&&!P&&h(I);O=I,R||P||T?s(_)?O=_:a(_)?O=n(_):P?(A=!1,O=r(I,!0)):T?(A=!1,O=t(I,!0)):O=[]:u(I)||i(I)?(O=_,i(_)?O=m(_):(!d(_)||l(_))&&(O=o(I))):A=!1}A&&(S.set(I,O),w(O,I,x,C,S),S.delete(I)),e(g,b,O)}return sl=y,sl}var cl,by;function MS(){if(by)return cl;by=1;var e=xo(),r=Dv(),t=Yd(),n=PS(),o=Ft(),i=Ir(),s=Vv();function a(c,l,d,u,h){c!==l&&t(l,function(p,m){if(h||(h=new e),o(p))n(c,l,m,d,a,u,h);else{var y=u?u(s(c,m),p,m+"",c,l,h):void 0;y===void 0&&(y=p),r(c,m,y)}},i)}return cl=a,cl}var ll,vy;function IS(){if(vy)return ll;vy=1;var e=Mo(),r=Io();function t(n){return e(function(o,i){var s=-1,a=i.length,c=a>1?i[a-1]:void 0,l=a>2?i[2]:void 0;for(c=n.length>3&&typeof c=="function"?(a--,c):void 0,l&&r(i[0],i[1],l)&&(c=a<3?void 0:c,a=1),o=Object(o);++s<a;){var d=i[s];d&&n(o,d,s,c)}return o})}return ll=t,ll}var dl,xy;function TS(){if(xy)return dl;xy=1;var e=MS(),r=IS(),t=r(function(n,o,i){e(n,o,i)});return dl=t,dl}var ul,wy;function Wv(){if(wy)return ul;wy=1;function e(r,t){return r<t}return ul=e,ul}var fl,Cy;function OS(){if(Cy)return fl;Cy=1;var e=nu(),r=Wv(),t=Tr();function n(o){return o&&o.length?e(o,t,r):void 0}return fl=n,fl}var hl,Sy;function NS(){if(Sy)return hl;Sy=1;var e=nu(),r=nr(),t=Wv();function n(o,i){return o&&o.length?e(o,r(i,2),t):void 0}return hl=n,hl}var pl,jy;function $S(){if(jy)return pl;jy=1;var e=Gt(),r=function(){return e.Date.now()};return pl=r,pl}var gl,_y;function qS(){if(_y)return gl;_y=1;var e=Co(),r=Ao(),t=So(),n=Ft(),o=zn();function i(s,a,c,l){if(!n(s))return s;a=r(a,s);for(var d=-1,u=a.length,h=u-1,p=s;p!=null&&++d<u;){var m=o(a[d]),y=c;if(m==="__proto__"||m==="constructor"||m==="prototype")return s;if(d!=h){var g=p[m];y=l?l(g,m,p):void 0,y===void 0&&(y=n(g)?g:t(a[d+1])?[]:{})}e(p,m,y),p=p[m]}return s}return gl=i,gl}var yl,Ey;function LS(){if(Ey)return yl;Ey=1;var e=Po(),r=qS(),t=Ao();function n(o,i,s){for(var a=-1,c=i.length,l={};++a<c;){var d=i[a],u=e(o,d);s(u,d)&&r(l,t(d,o),u)}return l}return yl=n,yl}var ml,ky;function FS(){if(ky)return ml;ky=1;var e=LS(),r=Cv();function t(n,o){return e(n,o,function(i,s){return r(n,s)})}return ml=t,ml}var bl,Ry;function zS(){if(Ry)return bl;Ry=1;var e=Bv(),r=Pv(),t=Mv();function n(o){return t(r(o,void 0,e),o+"")}return bl=n,bl}var vl,Ay;function BS(){if(Ay)return vl;Ay=1;var e=FS(),r=zS(),t=r(function(n,o){return n==null?{}:e(n,o)});return vl=t,vl}var xl,Py;function DS(){if(Py)return xl;Py=1;var e=Math.ceil,r=Math.max;function t(n,o,i,s){for(var a=-1,c=r(e((o-n)/(i||1)),0),l=Array(c);c--;)l[s?c:++a]=n,n+=i;return l}return xl=t,xl}var wl,My;function VS(){if(My)return wl;My=1;var e=DS(),r=Io(),t=zv();function n(o){return function(i,s,a){return a&&typeof a!="number"&&r(i,s,a)&&(s=a=void 0),i=t(i),s===void 0?(s=i,i=0):s=t(s),a=a===void 0?i<s?1:-1:t(a),e(i,s,a,o)}}return wl=n,wl}var Cl,Iy;function WS(){if(Iy)return Cl;Iy=1;var e=VS(),r=e();return Cl=r,Cl}var Sl,Ty;function GS(){if(Ty)return Sl;Ty=1;function e(r,t){var n=r.length;for(r.sort(t);n--;)r[n]=r[n].value;return r}return Sl=e,Sl}var jl,Oy;function US(){if(Oy)return jl;Oy=1;var e=rn();function r(t,n){if(t!==n){var o=t!==void 0,i=t===null,s=t===t,a=e(t),c=n!==void 0,l=n===null,d=n===n,u=e(n);if(!l&&!u&&!a&&t>n||a&&c&&d&&!l&&!u||i&&c&&d||!o&&d||!s)return 1;if(!i&&!a&&!u&&t<n||u&&o&&s&&!i&&!a||l&&o&&s||!c&&s||!d)return-1}return 0}return jl=r,jl}var _l,Ny;function HS(){if(Ny)return _l;Ny=1;var e=US();function r(t,n,o){for(var i=-1,s=t.criteria,a=n.criteria,c=s.length,l=o.length;++i<c;){var d=e(s[i],a[i]);if(d){if(i>=l)return d;var u=o[i];return d*(u=="desc"?-1:1)}}return t.index-n.index}return _l=r,_l}var El,$y;function KS(){if($y)return El;$y=1;var e=Ro(),r=Po(),t=nr(),n=kv(),o=GS(),i=jo(),s=HS(),a=Tr(),c=yt();function l(d,u,h){u.length?u=e(u,function(y){return c(y)?function(g){return r(g,y.length===1?y[0]:y)}:y}):u=[a];var p=-1;u=e(u,i(t));var m=n(d,function(y,g,v){var b=e(u,function(x){return x(y)});return{criteria:b,index:++p,value:y}});return o(m,function(y,g){return s(y,g,h)})}return El=l,El}var kl,qy;function JS(){if(qy)return kl;qy=1;var e=tu(),r=KS(),t=Mo(),n=Io(),o=t(function(i,s){if(i==null)return[];var a=s.length;return a>1&&n(i,s[0],s[1])?s=[]:a>2&&n(s[0],s[1],s[2])&&(s=[s[0]]),r(i,e(s,1),[])});return kl=o,kl}var Rl,Ly;function ZS(){if(Ly)return Rl;Ly=1;var e=xv(),r=0;function t(n){var o=++r;return e(n)+o}return Rl=t,Rl}var Al,Fy;function YS(){if(Fy)return Al;Fy=1;function e(r,t,n){for(var o=-1,i=r.length,s=t.length,a={};++o<i;){var c=o<s?t[o]:void 0;n(a,r[o],c)}return a}return Al=e,Al}var Pl,zy;function XS(){if(zy)return Pl;zy=1;var e=Co(),r=YS();function t(n,o){return r(n||[],o||[],e)}return Pl=t,Pl}var Ml,By;function dt(){if(By)return Ml;By=1;var e;if(typeof zd=="function")try{e={cloneDeep:pS(),constant:Zd(),defaults:gS(),each:hv(),filter:jv(),find:CS(),flatten:Bv(),forEach:fv(),forIn:SS(),has:_v(),isUndefined:Ev(),last:jS(),map:Rv(),mapValues:_S(),max:kS(),merge:TS(),min:OS(),minBy:NS(),now:$S(),pick:BS(),range:WS(),reduce:Av(),sortBy:JS(),uniqueId:ZS(),values:Ov(),zipObject:XS()}}catch{}return e||(e=window._),Ml=e,Ml}var Il,Dy;function QS(){if(Dy)return Il;Dy=1,Il=e;function e(){var n={};n._next=n._prev=n,this._sentinel=n}e.prototype.dequeue=function(){var n=this._sentinel,o=n._prev;if(o!==n)return r(o),o},e.prototype.enqueue=function(n){var o=this._sentinel;n._prev&&n._next&&r(n),n._next=o._next,o._next._prev=n,o._next=n,n._prev=o},e.prototype.toString=function(){for(var n=[],o=this._sentinel,i=o._prev;i!==o;)n.push(JSON.stringify(i,t)),i=i._prev;return"["+n.join(", ")+"]"};function r(n){n._prev._next=n._next,n._next._prev=n._prev,delete n._next,delete n._prev}function t(n,o){if(n!=="_next"&&n!=="_prev")return o}return Il}var Tl,Vy;function ej(){if(Vy)return Tl;Vy=1;var e=dt(),r=Wt().Graph,t=QS();Tl=o;var n=e.constant(1);function o(l,d){if(l.nodeCount()<=1)return[];var u=a(l,d||n),h=i(u.graph,u.buckets,u.zeroIdx);return e.flatten(e.map(h,function(p){return l.outEdges(p.v,p.w)}),!0)}function i(l,d,u){for(var h=[],p=d[d.length-1],m=d[0],y;l.nodeCount();){for(;y=m.dequeue();)s(l,d,u,y);for(;y=p.dequeue();)s(l,d,u,y);if(l.nodeCount()){for(var g=d.length-2;g>0;--g)if(y=d[g].dequeue(),y){h=h.concat(s(l,d,u,y,!0));break}}}return h}function s(l,d,u,h,p){var m=p?[]:void 0;return e.forEach(l.inEdges(h.v),function(y){var g=l.edge(y),v=l.node(y.v);p&&m.push({v:y.v,w:y.w}),v.out-=g,c(d,u,v)}),e.forEach(l.outEdges(h.v),function(y){var g=l.edge(y),v=y.w,b=l.node(v);b.in-=g,c(d,u,b)}),l.removeNode(h.v),m}function a(l,d){var u=new r,h=0,p=0;e.forEach(l.nodes(),function(g){u.setNode(g,{v:g,in:0,out:0})}),e.forEach(l.edges(),function(g){var v=u.edge(g.v,g.w)||0,b=d(g),x=v+b;u.setEdge(g.v,g.w,x),p=Math.max(p,u.node(g.v).out+=b),h=Math.max(h,u.node(g.w).in+=b)});var m=e.range(p+h+3).map(function(){return new t}),y=h+1;return e.forEach(u.nodes(),function(g){c(m,y,u.node(g))}),{graph:u,buckets:m,zeroIdx:y}}function c(l,d,u){u.out?u.in?l[u.out-u.in+d].enqueue(u):l[l.length-1].enqueue(u):l[0].enqueue(u)}return Tl}var Ol,Wy;function tj(){if(Wy)return Ol;Wy=1;var e=dt(),r=ej();Ol={run:t,undo:o};function t(i){var s=i.graph().acyclicer==="greedy"?r(i,a(i)):n(i);e.forEach(s,function(c){var l=i.edge(c);i.removeEdge(c),l.forwardName=c.name,l.reversed=!0,i.setEdge(c.w,c.v,l,e.uniqueId("rev"))});function a(c){return function(l){return c.edge(l).weight}}}function n(i){var s=[],a={},c={};function l(d){e.has(c,d)||(c[d]=!0,a[d]=!0,e.forEach(i.outEdges(d),function(u){e.has(a,u.w)?s.push(u):l(u.w)}),delete a[d])}return e.forEach(i.nodes(),l),s}function o(i){e.forEach(i.edges(),function(s){var a=i.edge(s);if(a.reversed){i.removeEdge(s);var c=a.forwardName;delete a.reversed,delete a.forwardName,i.setEdge(s.w,s.v,a,c)}})}return Ol}var Nl,Gy;function Rt(){if(Gy)return Nl;Gy=1;var e=dt(),r=Wt().Graph;Nl={addDummyNode:t,simplify:n,asNonCompoundGraph:o,successorWeights:i,predecessorWeights:s,intersectRect:a,buildLayerMatrix:c,normalizeRanks:l,removeEmptyRanks:d,addBorderNode:u,maxRank:h,partition:p,time:m,notime:y};function t(g,v,b,x){var w;do w=e.uniqueId(x);while(g.hasNode(w));return b.dummy=v,g.setNode(w,b),w}function n(g){var v=new r().setGraph(g.graph());return e.forEach(g.nodes(),function(b){v.setNode(b,g.node(b))}),e.forEach(g.edges(),function(b){var x=v.edge(b.v,b.w)||{weight:0,minlen:1},w=g.edge(b);v.setEdge(b.v,b.w,{weight:x.weight+w.weight,minlen:Math.max(x.minlen,w.minlen)})}),v}function o(g){var v=new r({multigraph:g.isMultigraph()}).setGraph(g.graph());return e.forEach(g.nodes(),function(b){g.children(b).length||v.setNode(b,g.node(b))}),e.forEach(g.edges(),function(b){v.setEdge(b,g.edge(b))}),v}function i(g){var v=e.map(g.nodes(),function(b){var x={};return e.forEach(g.outEdges(b),function(w){x[w.w]=(x[w.w]||0)+g.edge(w).weight}),x});return e.zipObject(g.nodes(),v)}function s(g){var v=e.map(g.nodes(),function(b){var x={};return e.forEach(g.inEdges(b),function(w){x[w.v]=(x[w.v]||0)+g.edge(w).weight}),x});return e.zipObject(g.nodes(),v)}function a(g,v){var b=g.x,x=g.y,w=v.x-b,C=v.y-x,S=g.width/2,_=g.height/2;if(!w&&!C)throw new Error("Not possible to find intersection inside of the rectangle");var I,E;return Math.abs(C)*S>Math.abs(w)*_?(C<0&&(_=-_),I=_*w/C,E=_):(w<0&&(S=-S),I=S,E=S*C/w),{x:b+I,y:x+E}}function c(g){var v=e.map(e.range(h(g)+1),function(){return[]});return e.forEach(g.nodes(),function(b){var x=g.node(b),w=x.rank;e.isUndefined(w)||(v[w][x.order]=b)}),v}function l(g){var v=e.min(e.map(g.nodes(),function(b){return g.node(b).rank}));e.forEach(g.nodes(),function(b){var x=g.node(b);e.has(x,"rank")&&(x.rank-=v)})}function d(g){var v=e.min(e.map(g.nodes(),function(C){return g.node(C).rank})),b=[];e.forEach(g.nodes(),function(C){var S=g.node(C).rank-v;b[S]||(b[S]=[]),b[S].push(C)});var x=0,w=g.graph().nodeRankFactor;e.forEach(b,function(C,S){e.isUndefined(C)&&S%w!==0?--x:x&&e.forEach(C,function(_){g.node(_).rank+=x})})}function u(g,v,b,x){var w={width:0,height:0};return arguments.length>=4&&(w.rank=b,w.order=x),t(g,"border",w,v)}function h(g){return e.max(e.map(g.nodes(),function(v){var b=g.node(v).rank;if(!e.isUndefined(b))return b}))}function p(g,v){var b={lhs:[],rhs:[]};return e.forEach(g,function(x){v(x)?b.lhs.push(x):b.rhs.push(x)}),b}function m(g,v){var b=e.now();try{return v()}finally{console.log(g+" time: "+(e.now()-b)+"ms")}}function y(g,v){return v()}return Nl}var $l,Uy;function rj(){if(Uy)return $l;Uy=1;var e=dt(),r=Rt();$l={run:t,undo:o};function t(i){i.graph().dummyChains=[],e.forEach(i.edges(),function(s){n(i,s)})}function n(i,s){var a=s.v,c=i.node(a).rank,l=s.w,d=i.node(l).rank,u=s.name,h=i.edge(s),p=h.labelRank;if(d!==c+1){i.removeEdge(s);var m,y,g;for(g=0,++c;c<d;++g,++c)h.points=[],y={width:0,height:0,edgeLabel:h,edgeObj:s,rank:c},m=r.addDummyNode(i,"edge",y,"_d"),c===p&&(y.width=h.width,y.height=h.height,y.dummy="edge-label",y.labelpos=h.labelpos),i.setEdge(a,m,{weight:h.weight},u),g===0&&i.graph().dummyChains.push(m),a=m;i.setEdge(a,l,{weight:h.weight},u)}}function o(i){e.forEach(i.graph().dummyChains,function(s){var a=i.node(s),c=a.edgeLabel,l;for(i.setEdge(a.edgeObj,c);a.dummy;)l=i.successors(s)[0],i.removeNode(s),c.points.push({x:a.x,y:a.y}),a.dummy==="edge-label"&&(c.x=a.x,c.y=a.y,c.width=a.width,c.height=a.height),s=l,a=i.node(s)})}return $l}var ql,Hy;function io(){if(Hy)return ql;Hy=1;var e=dt();ql={longestPath:r,slack:t};function r(n){var o={};function i(s){var a=n.node(s);if(e.has(o,s))return a.rank;o[s]=!0;var c=e.min(e.map(n.outEdges(s),function(l){return i(l.w)-n.edge(l).minlen}));return(c===Number.POSITIVE_INFINITY||c===void 0||c===null)&&(c=0),a.rank=c}e.forEach(n.sources(),i)}function t(n,o){return n.node(o.w).rank-n.node(o.v).rank-n.edge(o).minlen}return ql}var Ll,Ky;function Gv(){if(Ky)return Ll;Ky=1;var e=dt(),r=Wt().Graph,t=io().slack;Ll=n;function n(a){var c=new r({directed:!1}),l=a.nodes()[0],d=a.nodeCount();c.setNode(l,{});for(var u,h;o(c,a)<d;)u=i(c,a),h=c.hasNode(u.v)?t(a,u):-t(a,u),s(c,a,h);return c}function o(a,c){function l(d){e.forEach(c.nodeEdges(d),function(u){var h=u.v,p=d===h?u.w:h;!a.hasNode(p)&&!t(c,u)&&(a.setNode(p,{}),a.setEdge(d,p,{}),l(p))})}return e.forEach(a.nodes(),l),a.nodeCount()}function i(a,c){return e.minBy(c.edges(),function(l){if(a.hasNode(l.v)!==a.hasNode(l.w))return t(c,l)})}function s(a,c,l){e.forEach(a.nodes(),function(d){c.node(d).rank+=l})}return Ll}var Fl,Jy;function nj(){if(Jy)return Fl;Jy=1;var e=dt(),r=Gv(),t=io().slack,n=io().longestPath,o=Wt().alg.preorder,i=Wt().alg.postorder,s=Rt().simplify;Fl=a,a.initLowLimValues=u,a.initCutValues=c,a.calcCutValue=d,a.leaveEdge=p,a.enterEdge=m,a.exchangeEdges=y;function a(x){x=s(x),n(x);var w=r(x);u(w),c(w,x);for(var C,S;C=p(w);)S=m(w,x,C),y(w,x,C,S)}function c(x,w){var C=i(x,x.nodes());C=C.slice(0,C.length-1),e.forEach(C,function(S){l(x,w,S)})}function l(x,w,C){var S=x.node(C),_=S.parent;x.edge(C,_).cutvalue=d(x,w,C)}function d(x,w,C){var S=x.node(C),_=S.parent,I=!0,E=w.edge(C,_),O=0;return E||(I=!1,E=w.edge(_,C)),O=E.weight,e.forEach(w.nodeEdges(C),function(A){var R=A.v===C,P=R?A.w:A.v;if(P!==_){var T=R===I,N=w.edge(A).weight;if(O+=T?N:-N,v(x,C,P)){var $=x.edge(C,P).cutvalue;O+=T?-$:$}}}),O}function u(x,w){arguments.length<2&&(w=x.nodes()[0]),h(x,{},1,w)}function h(x,w,C,S,_){var I=C,E=x.node(S);return w[S]=!0,e.forEach(x.neighbors(S),function(O){e.has(w,O)||(C=h(x,w,C,O,S))}),E.low=I,E.lim=C++,_?E.parent=_:delete E.parent,C}function p(x){return e.find(x.edges(),function(w){return x.edge(w).cutvalue<0})}function m(x,w,C){var S=C.v,_=C.w;w.hasEdge(S,_)||(S=C.w,_=C.v);var I=x.node(S),E=x.node(_),O=I,A=!1;I.lim>E.lim&&(O=E,A=!0);var R=e.filter(w.edges(),function(P){return A===b(x,x.node(P.v),O)&&A!==b(x,x.node(P.w),O)});return e.minBy(R,function(P){return t(w,P)})}function y(x,w,C,S){var _=C.v,I=C.w;x.removeEdge(_,I),x.setEdge(S.v,S.w,{}),u(x),c(x,w),g(x,w)}function g(x,w){var C=e.find(x.nodes(),function(_){return!w.node(_).parent}),S=o(x,C);S=S.slice(1),e.forEach(S,function(_){var I=x.node(_).parent,E=w.edge(_,I),O=!1;E||(E=w.edge(I,_),O=!0),w.node(_).rank=w.node(I).rank+(O?E.minlen:-E.minlen)})}function v(x,w,C){return x.hasEdge(w,C)}function b(x,w,C){return C.low<=w.lim&&w.lim<=C.lim}return Fl}var zl,Zy;function oj(){if(Zy)return zl;Zy=1;var e=io(),r=e.longestPath,t=Gv(),n=nj();zl=o;function o(c){switch(c.graph().ranker){case"network-simplex":a(c);break;case"tight-tree":s(c);break;case"longest-path":i(c);break;default:a(c)}}var i=r;function s(c){r(c),t(c)}function a(c){n(c)}return zl}var Bl,Yy;function ij(){if(Yy)return Bl;Yy=1;var e=dt();Bl=r;function r(o){var i=n(o);e.forEach(o.graph().dummyChains,function(s){for(var a=o.node(s),c=a.edgeObj,l=t(o,i,c.v,c.w),d=l.path,u=l.lca,h=0,p=d[h],m=!0;s!==c.w;){if(a=o.node(s),m){for(;(p=d[h])!==u&&o.node(p).maxRank<a.rank;)h++;p===u&&(m=!1)}if(!m){for(;h<d.length-1&&o.node(p=d[h+1]).minRank<=a.rank;)h++;p=d[h]}o.setParent(s,p),s=o.successors(s)[0]}})}function t(o,i,s,a){var c=[],l=[],d=Math.min(i[s].low,i[a].low),u=Math.max(i[s].lim,i[a].lim),h,p;h=s;do h=o.parent(h),c.push(h);while(h&&(i[h].low>d||u>i[h].lim));for(p=h,h=a;(h=o.parent(h))!==p;)l.push(h);return{path:c.concat(l.reverse()),lca:p}}function n(o){var i={},s=0;function a(c){var l=s;e.forEach(o.children(c),a),i[c]={low:l,lim:s++}}return e.forEach(o.children(),a),i}return Bl}var Dl,Xy;function aj(){if(Xy)return Dl;Xy=1;var e=dt(),r=Rt();Dl={run:t,cleanup:s};function t(a){var c=r.addDummyNode(a,"root",{},"_root"),l=o(a),d=e.max(e.values(l))-1,u=2*d+1;a.graph().nestingRoot=c,e.forEach(a.edges(),function(p){a.edge(p).minlen*=u});var h=i(a)+1;e.forEach(a.children(),function(p){n(a,c,u,h,d,l,p)}),a.graph().nodeRankFactor=u}function n(a,c,l,d,u,h,p){var m=a.children(p);if(!m.length){p!==c&&a.setEdge(c,p,{weight:0,minlen:l});return}var y=r.addBorderNode(a,"_bt"),g=r.addBorderNode(a,"_bb"),v=a.node(p);a.setParent(y,p),v.borderTop=y,a.setParent(g,p),v.borderBottom=g,e.forEach(m,function(b){n(a,c,l,d,u,h,b);var x=a.node(b),w=x.borderTop?x.borderTop:b,C=x.borderBottom?x.borderBottom:b,S=x.borderTop?d:2*d,_=w!==C?1:u-h[p]+1;a.setEdge(y,w,{weight:S,minlen:_,nestingEdge:!0}),a.setEdge(C,g,{weight:S,minlen:_,nestingEdge:!0})}),a.parent(p)||a.setEdge(c,y,{weight:0,minlen:u+h[p]})}function o(a){var c={};function l(d,u){var h=a.children(d);h&&h.length&&e.forEach(h,function(p){l(p,u+1)}),c[d]=u}return e.forEach(a.children(),function(d){l(d,1)}),c}function i(a){return e.reduce(a.edges(),function(c,l){return c+a.edge(l).weight},0)}function s(a){var c=a.graph();a.removeNode(c.nestingRoot),delete c.nestingRoot,e.forEach(a.edges(),function(l){var d=a.edge(l);d.nestingEdge&&a.removeEdge(l)})}return Dl}var Vl,Qy;function sj(){if(Qy)return Vl;Qy=1;var e=dt(),r=Rt();Vl=t;function t(o){function i(s){var a=o.children(s),c=o.node(s);if(a.length&&e.forEach(a,i),e.has(c,"minRank")){c.borderLeft=[],c.borderRight=[];for(var l=c.minRank,d=c.maxRank+1;l<d;++l)n(o,"borderLeft","_bl",s,c,l),n(o,"borderRight","_br",s,c,l)}}e.forEach(o.children(),i)}function n(o,i,s,a,c,l){var d={width:0,height:0,rank:l,borderType:i},u=c[i][l-1],h=r.addDummyNode(o,"border",d,s);c[i][l]=h,o.setParent(h,a),u&&o.setEdge(u,h,{weight:1})}return Vl}var Wl,em;function cj(){if(em)return Wl;em=1;var e=dt();Wl={adjust:r,undo:t};function r(l){var d=l.graph().rankdir.toLowerCase();(d==="lr"||d==="rl")&&n(l)}function t(l){var d=l.graph().rankdir.toLowerCase();(d==="bt"||d==="rl")&&i(l),(d==="lr"||d==="rl")&&(a(l),n(l))}function n(l){e.forEach(l.nodes(),function(d){o(l.node(d))}),e.forEach(l.edges(),function(d){o(l.edge(d))})}function o(l){var d=l.width;l.width=l.height,l.height=d}function i(l){e.forEach(l.nodes(),function(d){s(l.node(d))}),e.forEach(l.edges(),function(d){var u=l.edge(d);e.forEach(u.points,s),e.has(u,"y")&&s(u)})}function s(l){l.y=-l.y}function a(l){e.forEach(l.nodes(),function(d){c(l.node(d))}),e.forEach(l.edges(),function(d){var u=l.edge(d);e.forEach(u.points,c),e.has(u,"x")&&c(u)})}function c(l){var d=l.x;l.x=l.y,l.y=d}return Wl}var Gl,tm;function lj(){if(tm)return Gl;tm=1;var e=dt();Gl=r;function r(t){var n={},o=e.filter(t.nodes(),function(l){return!t.children(l).length}),i=e.max(e.map(o,function(l){return t.node(l).rank})),s=e.map(e.range(i+1),function(){return[]});function a(l){if(!e.has(n,l)){n[l]=!0;var d=t.node(l);s[d.rank].push(l),e.forEach(t.successors(l),a)}}var c=e.sortBy(o,function(l){return t.node(l).rank});return e.forEach(c,a),s}return Gl}var Ul,rm;function dj(){if(rm)return Ul;rm=1;var e=dt();Ul=r;function r(n,o){for(var i=0,s=1;s<o.length;++s)i+=t(n,o[s-1],o[s]);return i}function t(n,o,i){for(var s=e.zipObject(i,e.map(i,function(h,p){return p})),a=e.flatten(e.map(o,function(h){return e.sortBy(e.map(n.outEdges(h),function(p){return{pos:s[p.w],weight:n.edge(p).weight}}),"pos")}),!0),c=1;c<i.length;)c<<=1;var l=2*c-1;c-=1;var d=e.map(new Array(l),function(){return 0}),u=0;return e.forEach(a.forEach(function(h){var p=h.pos+c;d[p]+=h.weight;for(var m=0;p>0;)p%2&&(m+=d[p+1]),p=p-1>>1,d[p]+=h.weight;u+=h.weight*m})),u}return Ul}var Hl,nm;function uj(){if(nm)return Hl;nm=1;var e=dt();Hl=r;function r(t,n){return e.map(n,function(o){var i=t.inEdges(o);if(i.length){var s=e.reduce(i,function(a,c){var l=t.edge(c),d=t.node(c.v);return{sum:a.sum+l.weight*d.order,weight:a.weight+l.weight}},{sum:0,weight:0});return{v:o,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:o}})}return Hl}var Kl,om;function fj(){if(om)return Kl;om=1;var e=dt();Kl=r;function r(o,i){var s={};e.forEach(o,function(c,l){var d=s[c.v]={indegree:0,in:[],out:[],vs:[c.v],i:l};e.isUndefined(c.barycenter)||(d.barycenter=c.barycenter,d.weight=c.weight)}),e.forEach(i.edges(),function(c){var l=s[c.v],d=s[c.w];!e.isUndefined(l)&&!e.isUndefined(d)&&(d.indegree++,l.out.push(s[c.w]))});var a=e.filter(s,function(c){return!c.indegree});return t(a)}function t(o){var i=[];function s(l){return function(d){d.merged||(e.isUndefined(d.barycenter)||e.isUndefined(l.barycenter)||d.barycenter>=l.barycenter)&&n(l,d)}}function a(l){return function(d){d.in.push(l),--d.indegree===0&&o.push(d)}}for(;o.length;){var c=o.pop();i.push(c),e.forEach(c.in.reverse(),s(c)),e.forEach(c.out,a(c))}return e.map(e.filter(i,function(l){return!l.merged}),function(l){return e.pick(l,["vs","i","barycenter","weight"])})}function n(o,i){var s=0,a=0;o.weight&&(s+=o.barycenter*o.weight,a+=o.weight),i.weight&&(s+=i.barycenter*i.weight,a+=i.weight),o.vs=i.vs.concat(o.vs),o.barycenter=s/a,o.weight=a,o.i=Math.min(i.i,o.i),i.merged=!0}return Kl}var Jl,im;function hj(){if(im)return Jl;im=1;var e=dt(),r=Rt();Jl=t;function t(i,s){var a=r.partition(i,function(y){return e.has(y,"barycenter")}),c=a.lhs,l=e.sortBy(a.rhs,function(y){return-y.i}),d=[],u=0,h=0,p=0;c.sort(o(!!s)),p=n(d,l,p),e.forEach(c,function(y){p+=y.vs.length,d.push(y.vs),u+=y.barycenter*y.weight,h+=y.weight,p=n(d,l,p)});var m={vs:e.flatten(d,!0)};return h&&(m.barycenter=u/h,m.weight=h),m}function n(i,s,a){for(var c;s.length&&(c=e.last(s)).i<=a;)s.pop(),i.push(c.vs),a++;return a}function o(i){return function(s,a){return s.barycenter<a.barycenter?-1:s.barycenter>a.barycenter?1:i?a.i-s.i:s.i-a.i}}return Jl}var Zl,am;function pj(){if(am)return Zl;am=1;var e=dt(),r=uj(),t=fj(),n=hj();Zl=o;function o(a,c,l,d){var u=a.children(c),h=a.node(c),p=h?h.borderLeft:void 0,m=h?h.borderRight:void 0,y={};p&&(u=e.filter(u,function(C){return C!==p&&C!==m}));var g=r(a,u);e.forEach(g,function(C){if(a.children(C.v).length){var S=o(a,C.v,l,d);y[C.v]=S,e.has(S,"barycenter")&&s(C,S)}});var v=t(g,l);i(v,y);var b=n(v,d);if(p&&(b.vs=e.flatten([p,b.vs,m],!0),a.predecessors(p).length)){var x=a.node(a.predecessors(p)[0]),w=a.node(a.predecessors(m)[0]);e.has(b,"barycenter")||(b.barycenter=0,b.weight=0),b.barycenter=(b.barycenter*b.weight+x.order+w.order)/(b.weight+2),b.weight+=2}return b}function i(a,c){e.forEach(a,function(l){l.vs=e.flatten(l.vs.map(function(d){return c[d]?c[d].vs:d}),!0)})}function s(a,c){e.isUndefined(a.barycenter)?(a.barycenter=c.barycenter,a.weight=c.weight):(a.barycenter=(a.barycenter*a.weight+c.barycenter*c.weight)/(a.weight+c.weight),a.weight+=c.weight)}return Zl}var Yl,sm;function gj(){if(sm)return Yl;sm=1;var e=dt(),r=Wt().Graph;Yl=t;function t(o,i,s){var a=n(o),c=new r({compound:!0}).setGraph({root:a}).setDefaultNodeLabel(function(l){return o.node(l)});return e.forEach(o.nodes(),function(l){var d=o.node(l),u=o.parent(l);(d.rank===i||d.minRank<=i&&i<=d.maxRank)&&(c.setNode(l),c.setParent(l,u||a),e.forEach(o[s](l),function(h){var p=h.v===l?h.w:h.v,m=c.edge(p,l),y=e.isUndefined(m)?0:m.weight;c.setEdge(p,l,{weight:o.edge(h).weight+y})}),e.has(d,"minRank")&&c.setNode(l,{borderLeft:d.borderLeft[i],borderRight:d.borderRight[i]}))}),c}function n(o){for(var i;o.hasNode(i=e.uniqueId("_root")););return i}return Yl}var Xl,cm;function yj(){if(cm)return Xl;cm=1;var e=dt();Xl=r;function r(t,n,o){var i={},s;e.forEach(o,function(a){for(var c=t.parent(a),l,d;c;){if(l=t.parent(c),l?(d=i[l],i[l]=c):(d=s,s=c),d&&d!==c){n.setEdge(d,c);return}c=l}})}return Xl}var Ql,lm;function mj(){if(lm)return Ql;lm=1;var e=dt(),r=lj(),t=dj(),n=pj(),o=gj(),i=yj(),s=Wt().Graph,a=Rt();Ql=c;function c(h){var p=a.maxRank(h),m=l(h,e.range(1,p+1),"inEdges"),y=l(h,e.range(p-1,-1,-1),"outEdges"),g=r(h);u(h,g);for(var v=Number.POSITIVE_INFINITY,b,x=0,w=0;w<4;++x,++w){d(x%2?m:y,x%4>=2),g=a.buildLayerMatrix(h);var C=t(h,g);C<v&&(w=0,b=e.cloneDeep(g),v=C)}u(h,b)}function l(h,p,m){return e.map(p,function(y){return o(h,y,m)})}function d(h,p){var m=new s;e.forEach(h,function(y){var g=y.graph().root,v=n(y,g,m,p);e.forEach(v.vs,function(b,x){y.node(b).order=x}),i(y,m,v.vs)})}function u(h,p){e.forEach(p,function(m){e.forEach(m,function(y,g){h.node(y).order=g})})}return Ql}var ed,dm;function bj(){if(dm)return ed;dm=1;var e=dt(),r=Wt().Graph,t=Rt();ed={positionX:m,findType1Conflicts:n,findType2Conflicts:o,addConflict:s,hasConflict:a,verticalAlignment:c,horizontalCompaction:l,alignCoordinates:h,findSmallestWidthAlignment:u,balance:p};function n(v,b){var x={};function w(C,S){var _=0,I=0,E=C.length,O=e.last(S);return e.forEach(S,function(A,R){var P=i(v,A),T=P?v.node(P).order:E;(P||A===O)&&(e.forEach(S.slice(I,R+1),function(N){e.forEach(v.predecessors(N),function($){var M=v.node($),W=M.order;(W<_||T<W)&&!(M.dummy&&v.node(N).dummy)&&s(x,$,N)})}),I=R+1,_=T)}),S}return e.reduce(b,w),x}function o(v,b){var x={};function w(S,_,I,E,O){var A;e.forEach(e.range(_,I),function(R){A=S[R],v.node(A).dummy&&e.forEach(v.predecessors(A),function(P){var T=v.node(P);T.dummy&&(T.order<E||T.order>O)&&s(x,P,A)})})}function C(S,_){var I=-1,E,O=0;return e.forEach(_,function(A,R){if(v.node(A).dummy==="border"){var P=v.predecessors(A);P.length&&(E=v.node(P[0]).order,w(_,O,R,I,E),O=R,I=E)}w(_,O,_.length,E,S.length)}),_}return e.reduce(b,C),x}function i(v,b){if(v.node(b).dummy)return e.find(v.predecessors(b),function(x){return v.node(x).dummy})}function s(v,b,x){if(b>x){var w=b;b=x,x=w}var C=v[b];C||(v[b]=C={}),C[x]=!0}function a(v,b,x){if(b>x){var w=b;b=x,x=w}return e.has(v[b],x)}function c(v,b,x,w){var C={},S={},_={};return e.forEach(b,function(I){e.forEach(I,function(E,O){C[E]=E,S[E]=E,_[E]=O})}),e.forEach(b,function(I){var E=-1;e.forEach(I,function(O){var A=w(O);if(A.length){A=e.sortBy(A,function($){return _[$]});for(var R=(A.length-1)/2,P=Math.floor(R),T=Math.ceil(R);P<=T;++P){var N=A[P];S[O]===O&&E<_[N]&&!a(x,O,N)&&(S[N]=O,S[O]=C[O]=C[N],E=_[N])}}})}),{root:C,align:S}}function l(v,b,x,w,C){var S={},_=d(v,b,x,C),I=C?"borderLeft":"borderRight";function E(R,P){for(var T=_.nodes(),N=T.pop(),$={};N;)$[N]?R(N):($[N]=!0,T.push(N),T=T.concat(P(N))),N=T.pop()}function O(R){S[R]=_.inEdges(R).reduce(function(P,T){return Math.max(P,S[T.v]+_.edge(T))},0)}function A(R){var P=_.outEdges(R).reduce(function(N,$){return Math.min(N,S[$.w]-_.edge($))},Number.POSITIVE_INFINITY),T=v.node(R);P!==Number.POSITIVE_INFINITY&&T.borderType!==I&&(S[R]=Math.max(S[R],P))}return E(O,_.predecessors.bind(_)),E(A,_.successors.bind(_)),e.forEach(w,function(R){S[R]=S[x[R]]}),S}function d(v,b,x,w){var C=new r,S=v.graph(),_=y(S.nodesep,S.edgesep,w);return e.forEach(b,function(I){var E;e.forEach(I,function(O){var A=x[O];if(C.setNode(A),E){var R=x[E],P=C.edge(R,A);C.setEdge(R,A,Math.max(_(v,O,E),P||0))}E=O})}),C}function u(v,b){return e.minBy(e.values(b),function(x){var w=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY;return e.forIn(x,function(S,_){var I=g(v,_)/2;w=Math.max(S+I,w),C=Math.min(S-I,C)}),w-C})}function h(v,b){var x=e.values(b),w=e.min(x),C=e.max(x);e.forEach(["u","d"],function(S){e.forEach(["l","r"],function(_){var I=S+_,E=v[I],O;if(E!==b){var A=e.values(E);O=_==="l"?w-e.min(A):C-e.max(A),O&&(v[I]=e.mapValues(E,function(R){return R+O}))}})})}function p(v,b){return e.mapValues(v.ul,function(x,w){if(b)return v[b.toLowerCase()][w];var C=e.sortBy(e.map(v,w));return(C[1]+C[2])/2})}function m(v){var b=t.buildLayerMatrix(v),x=e.merge(n(v,b),o(v,b)),w={},C;e.forEach(["u","d"],function(_){C=_==="u"?b:e.values(b).reverse(),e.forEach(["l","r"],function(I){I==="r"&&(C=e.map(C,function(R){return e.values(R).reverse()}));var E=(_==="u"?v.predecessors:v.successors).bind(v),O=c(v,C,x,E),A=l(v,C,O.root,O.align,I==="r");I==="r"&&(A=e.mapValues(A,function(R){return-R})),w[_+I]=A})});var S=u(v,w);return h(w,S),p(w,v.graph().align)}function y(v,b,x){return function(w,C,S){var _=w.node(C),I=w.node(S),E=0,O;if(E+=_.width/2,e.has(_,"labelpos"))switch(_.labelpos.toLowerCase()){case"l":O=-_.width/2;break;case"r":O=_.width/2;break}if(O&&(E+=x?O:-O),O=0,E+=(_.dummy?b:v)/2,E+=(I.dummy?b:v)/2,E+=I.width/2,e.has(I,"labelpos"))switch(I.labelpos.toLowerCase()){case"l":O=I.width/2;break;case"r":O=-I.width/2;break}return O&&(E+=x?O:-O),O=0,E}}function g(v,b){return v.node(b).width}return ed}var td,um;function vj(){if(um)return td;um=1;var e=dt(),r=Rt(),t=bj().positionX;td=n;function n(i){i=r.asNonCompoundGraph(i),o(i),e.forEach(t(i),function(s,a){i.node(a).x=s})}function o(i){var s=r.buildLayerMatrix(i),a=i.graph().ranksep,c=0;e.forEach(s,function(l){var d=e.max(e.map(l,function(u){return i.node(u).height}));e.forEach(l,function(u){i.node(u).y=c+d/2}),c+=d+a})}return td}var rd,fm;function xj(){if(fm)return rd;fm=1;var e=dt(),r=tj(),t=rj(),n=oj(),o=Rt().normalizeRanks,i=ij(),s=Rt().removeEmptyRanks,a=aj(),c=sj(),l=cj(),d=mj(),u=vj(),h=Rt(),p=Wt().Graph;rd=m;function m(L,z){var U=z&&z.debugTiming?h.time:h.notime;U("layout",function(){var B=U(" buildLayoutGraph",function(){return E(L)});U(" runLayout",function(){y(B,U)}),U(" updateInputGraph",function(){g(L,B)})})}function y(L,z){z(" makeSpaceForEdgeLabels",function(){O(L)}),z(" removeSelfEdges",function(){ae(L)}),z(" acyclic",function(){r.run(L)}),z(" nestingGraph.run",function(){a.run(L)}),z(" rank",function(){n(h.asNonCompoundGraph(L))}),z(" injectEdgeLabelProxies",function(){A(L)}),z(" removeEmptyRanks",function(){s(L)}),z(" nestingGraph.cleanup",function(){a.cleanup(L)}),z(" normalizeRanks",function(){o(L)}),z(" assignRankMinMax",function(){R(L)}),z(" removeEdgeLabelProxies",function(){P(L)}),z(" normalize.run",function(){t.run(L)}),z(" parentDummyChains",function(){i(L)}),z(" addBorderSegments",function(){c(L)}),z(" order",function(){d(L)}),z(" insertSelfEdges",function(){se(L)}),z(" adjustCoordinateSystem",function(){l.adjust(L)}),z(" position",function(){u(L)}),z(" positionSelfEdges",function(){re(L)}),z(" removeBorderNodes",function(){W(L)}),z(" normalize.undo",function(){t.undo(L)}),z(" fixupEdgeLabelCoords",function(){$(L)}),z(" undoCoordinateSystem",function(){l.undo(L)}),z(" translateGraph",function(){T(L)}),z(" assignNodeIntersects",function(){N(L)}),z(" reversePoints",function(){M(L)}),z(" acyclic.undo",function(){r.undo(L)})}function g(L,z){e.forEach(L.nodes(),function(U){var B=L.node(U),ce=z.node(U);B&&(B.x=ce.x,B.y=ce.y,z.children(U).length&&(B.width=ce.width,B.height=ce.height))}),e.forEach(L.edges(),function(U){var B=L.edge(U),ce=z.edge(U);B.points=ce.points,e.has(ce,"x")&&(B.x=ce.x,B.y=ce.y)}),L.graph().width=z.graph().width,L.graph().height=z.graph().height}var v=["nodesep","edgesep","ranksep","marginx","marginy"],b={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},x=["acyclicer","ranker","rankdir","align"],w=["width","height"],C={width:0,height:0},S=["minlen","weight","width","height","labeloffset"],_={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},I=["labelpos"];function E(L){var z=new p({multigraph:!0,compound:!0}),U=me(L.graph());return z.setGraph(e.merge({},b,ye(U,v),e.pick(U,x))),e.forEach(L.nodes(),function(B){var ce=me(L.node(B));z.setNode(B,e.defaults(ye(ce,w),C)),z.setParent(B,L.parent(B))}),e.forEach(L.edges(),function(B){var ce=me(L.edge(B));z.setEdge(B,e.merge({},_,ye(ce,S),e.pick(ce,I)))}),z}function O(L){var z=L.graph();z.ranksep/=2,e.forEach(L.edges(),function(U){var B=L.edge(U);B.minlen*=2,B.labelpos.toLowerCase()!=="c"&&(z.rankdir==="TB"||z.rankdir==="BT"?B.width+=B.labeloffset:B.height+=B.labeloffset)})}function A(L){e.forEach(L.edges(),function(z){var U=L.edge(z);if(U.width&&U.height){var B=L.node(z.v),ce=L.node(z.w),X={rank:(ce.rank-B.rank)/2+B.rank,e:z};h.addDummyNode(L,"edge-proxy",X,"_ep")}})}function R(L){var z=0;e.forEach(L.nodes(),function(U){var B=L.node(U);B.borderTop&&(B.minRank=L.node(B.borderTop).rank,B.maxRank=L.node(B.borderBottom).rank,z=e.max(z,B.maxRank))}),L.graph().maxRank=z}function P(L){e.forEach(L.nodes(),function(z){var U=L.node(z);U.dummy==="edge-proxy"&&(L.edge(U.e).labelRank=U.rank,L.removeNode(z))})}function T(L){var z=Number.POSITIVE_INFINITY,U=0,B=Number.POSITIVE_INFINITY,ce=0,X=L.graph(),le=X.marginx||0,ue=X.marginy||0;function xe(Ce){var ge=Ce.x,he=Ce.y,Y=Ce.width,H=Ce.height;z=Math.min(z,ge-Y/2),U=Math.max(U,ge+Y/2),B=Math.min(B,he-H/2),ce=Math.max(ce,he+H/2)}e.forEach(L.nodes(),function(Ce){xe(L.node(Ce))}),e.forEach(L.edges(),function(Ce){var ge=L.edge(Ce);e.has(ge,"x")&&xe(ge)}),z-=le,B-=ue,e.forEach(L.nodes(),function(Ce){var ge=L.node(Ce);ge.x-=z,ge.y-=B}),e.forEach(L.edges(),function(Ce){var ge=L.edge(Ce);e.forEach(ge.points,function(he){he.x-=z,he.y-=B}),e.has(ge,"x")&&(ge.x-=z),e.has(ge,"y")&&(ge.y-=B)}),X.width=U-z+le,X.height=ce-B+ue}function N(L){e.forEach(L.edges(),function(z){var U=L.edge(z),B=L.node(z.v),ce=L.node(z.w),X,le;U.points?(X=U.points[0],le=U.points[U.points.length-1]):(U.points=[],X=ce,le=B),U.points.unshift(h.intersectRect(B,X)),U.points.push(h.intersectRect(ce,le))})}function $(L){e.forEach(L.edges(),function(z){var U=L.edge(z);if(e.has(U,"x"))switch((U.labelpos==="l"||U.labelpos==="r")&&(U.width-=U.labeloffset),U.labelpos){case"l":U.x-=U.width/2+U.labeloffset;break;case"r":U.x+=U.width/2+U.labeloffset;break}})}function M(L){e.forEach(L.edges(),function(z){var U=L.edge(z);U.reversed&&U.points.reverse()})}function W(L){e.forEach(L.nodes(),function(z){if(L.children(z).length){var U=L.node(z),B=L.node(U.borderTop),ce=L.node(U.borderBottom),X=L.node(e.last(U.borderLeft)),le=L.node(e.last(U.borderRight));U.width=Math.abs(le.x-X.x),U.height=Math.abs(ce.y-B.y),U.x=X.x+U.width/2,U.y=B.y+U.height/2}}),e.forEach(L.nodes(),function(z){L.node(z).dummy==="border"&&L.removeNode(z)})}function ae(L){e.forEach(L.edges(),function(z){if(z.v===z.w){var U=L.node(z.v);U.selfEdges||(U.selfEdges=[]),U.selfEdges.push({e:z,label:L.edge(z)}),L.removeEdge(z)}})}function se(L){var z=h.buildLayerMatrix(L);e.forEach(z,function(U){var B=0;e.forEach(U,function(ce,X){var le=L.node(ce);le.order=X+B,e.forEach(le.selfEdges,function(ue){h.addDummyNode(L,"selfedge",{width:ue.label.width,height:ue.label.height,rank:le.rank,order:X+ ++B,e:ue.e,label:ue.label},"_se")}),delete le.selfEdges})})}function re(L){e.forEach(L.nodes(),function(z){var U=L.node(z);if(U.dummy==="selfedge"){var B=L.node(U.e.v),ce=B.x+B.width/2,X=B.y,le=U.x-ce,ue=B.height/2;L.setEdge(U.e,U.label),L.removeNode(z),U.label.points=[{x:ce+2*le/3,y:X-ue},{x:ce+5*le/6,y:X-ue},{x:ce+le,y:X},{x:ce+5*le/6,y:X+ue},{x:ce+2*le/3,y:X+ue}],U.label.x=U.x,U.label.y=U.y}})}function ye(L,z){return e.mapValues(e.pick(L,z),Number)}function me(L){var z={};return e.forEach(L,function(U,B){z[B.toLowerCase()]=U}),z}return rd}var nd,hm;function wj(){if(hm)return nd;hm=1;var e=dt(),r=Rt(),t=Wt().Graph;nd={debugOrdering:n};function n(o){var i=r.buildLayerMatrix(o),s=new t({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(a){s.setNode(a,{label:a}),s.setParent(a,"layer"+o.node(a).rank)}),e.forEach(o.edges(),function(a){s.setEdge(a.v,a.w,{},a.name)}),e.forEach(i,function(a,c){var l="layer"+c;s.setNode(l,{rank:"same"}),e.reduce(a,function(d,u){return s.setEdge(d,u,{style:"invis"}),u})}),s}return nd}var od,pm;function Cj(){return pm||(pm=1,od="0.8.5"),od}var id,gm;function Sj(){return gm||(gm=1,id={graphlib:Wt(),layout:xj(),debug:wj(),util:{time:Rt().time,notime:Rt().notime},version:Cj()}),id}var jj=Sj();const ym=c1(jj);function _j(e,r,t){var d;const n=new Set(e.map(u=>u.id)),o=new Set;for(const u of e)u.parent&&n.has(u.parent)&&o.add(u.parent);const i=new ym.graphlib.Graph({multigraph:!0,compound:!0}),s=t.compactSpacingScale??(t.spacingFactor>0?t.spacingFactor/1.3:1);i.setGraph({rankdir:t.rankDir,nodesep:t.compact?Math.max(t.nodeSep,24*s):t.nodeSep,edgesep:t.compact?Math.min(t.edgeSep,24*s):t.edgeSep,ranksep:t.compact?Math.min(t.rankSep,80*s):t.rankSep,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({})),i.setDefaultNodeLabel(()=>({}));for(const u of e)i.setNode(u.id,{width:u.width+2,height:u.height+2});for(const u of e)u.parent&&n.has(u.parent)&&i.setParent(u.id,u.parent);for(const u of r){if(!n.has(u.source)||!n.has(u.target)||o.has(u.source)||o.has(u.target))continue;const h=Wb(u.label,u.icon??((d=u.data)==null?void 0:d.icon),t.edgeLabelFontSize),p=t.rankDir==="LR"||t.rankDir==="RL",m=(h.width?h.width+2*Vb:0)+(u.connectorClearance??0);i.setEdge(u.source,u.target,{minlen:1,weight:1,...m?{width:p?m:Math.max(1,h.height),height:p?Math.max(1,h.height):m,labelpos:"c"}:{}},u.id)}ym.layout(i);const a=new Map;for(const u of e){if(o.has(u.id))continue;const h=i.node(u.id);h&&Number.isFinite(h.x)&&Number.isFinite(h.y)&&a.set(u.id,{x:h.x,y:h.y})}const c=t.compact?1:t.spacingFactor;if(c&&c!==1&&a.size){let u=1/0,h=1/0,p=-1/0,m=-1/0;a.forEach(v=>{u=Math.min(u,v.x),h=Math.min(h,v.y),p=Math.max(p,v.x),m=Math.max(m,v.y)});const y=(u+p)/2,g=(h+m)/2;a.forEach((v,b)=>a.set(b,{x:y+(v.x-y)*c,y:g+(v.y-g)*c}))}const l=t.nodeAlignment??"center";if(l!=="center"){const u=t.rankDir==="LR"||t.rankDir==="RL",h=u?"x":"y",p=u?"width":"height",m=t.rankDir==="RL"||t.rankDir==="BT"?-1:1,y=l==="leading"?-m:m,g=new Map;for(const v of e){const b=a.get(v.id);if(!b)continue;const x=b[h];g.set(x,Math.max(g.get(x)??0,v[p]))}for(const v of e){const b=a.get(v.id);if(!b)continue;const x=b[h],w=(g.get(x)-v[p])/2;a.set(v.id,{...b,[h]:x+y*w})}}return a}function md(e,r,t,n,o,i){const s=new Map,a=new Map(e.map(u=>[u.id,u]));for(const u of e){if(!u.parent||!a.has(u.parent))continue;const h=s.get(u.parent);h?h.push(u.id):s.set(u.parent,[u.id])}const c=(u,h=new Set)=>{var m;const p=(m=a.get(u))==null?void 0:m.parent;return!p||!a.has(p)||h.has(u)?0:(h.add(u),1+c(p,h))},l=[...s.keys()].sort((u,h)=>c(h)-c(u)),d=new Map;for(const u of l){const h=i==null?void 0:i.get(u),p=r.get(u);if(h&&p){d.set(u,{x1:p.x-h.w/2,y1:p.y-h.h/2,x2:p.x+h.w/2,y2:p.y+h.h/2});continue}let m=null;for(const v of s.get(u)||[]){let b=d.get(v);if(!b){const x=r.get(v);if(!x)continue;const w=t.get(v)||{w:60,h:60};b={x1:x.x-w.w/2,y1:x.y-w.h/2,x2:x.x+w.w/2,y2:x.y+w.h/2}}m=m?{x1:Math.min(m.x1,b.x1),y1:Math.min(m.y1,b.y1),x2:Math.max(m.x2,b.x2),y2:Math.max(m.y2,b.y2)}:{...b}}if(!m)continue;const y=n(u);m={x1:m.x1-y,y1:m.y1-y,x2:m.x2+y,y2:m.y2+y};const g=o(u);if(g){const v=m.x2-m.x1,b=m.y2-m.y1;if(g.w>v){const x=(g.w-v)/2;m.x1-=x,m.x2+=x}if(g.h>b){const x=(g.h-b)/2;m.y1-=x,m.y2+=x}}d.set(u,m)}return d}function mm(e,r,t){var c,l,d;const n=[...r.weights],o=n.reduce((u,h)=>u+h,0),i=n[r.index]+n[r.index+1],s=Math.min(i*.95,Math.max(i*.05,n[r.index]+t/r.length*o));n[r.index]=s,n[r.index+1]=i-s;const a={...(l=(c=e.adjustment)==null?void 0:c.sections)==null?void 0:l[r.section]};if(r.axis==="y")a.rows=n;else{for(a.columns=[...a.columns??[]];a.columns.length<=r.row;)a.columns.push([]);a.columns[r.row]=n}return{...e,adjustment:{...e.adjustment,sections:{...(d=e.adjustment)==null?void 0:d.sections,[r.section]:a}}}}function Uv(e){if(e===void 0)return;if(!e||typeof e!="object"||Array.isArray(e)||e.enabled!==void 0&&typeof e.enabled!="boolean")throw new RangeError("Invalid grid adjustment.");const r=t=>Array.isArray(t)&&t.length<=1e4&&t.every(n=>typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1e6);if(e.sections!==void 0&&(!e.sections||typeof e.sections!="object"||Array.isArray(e.sections)))throw new RangeError("Invalid grid sections.");for(const[t,n]of Object.entries(e.sections??{}))if(["__proto__","constructor","prototype"].includes(t)||!n||typeof n!="object"||Array.isArray(n)||n.rows!==void 0&&!r(n.rows)||n.columns!==void 0&&(!Array.isArray(n.columns)||n.columns.length>1e4||!n.columns.every(r))||n.members!==void 0&&(!Array.isArray(n.members)||n.members.length>1e4||!n.members.every(o=>Array.isArray(o)&&o.length>0&&o.length<=1e4&&o.every(i=>typeof i=="string"&&i.length>0))||new Set(n.members.flat()).size!==n.members.flat().length))throw new RangeError("Invalid grid section proportions.")}function ou(e){const r=e.margin??15;if(!Number.isFinite(r)||r<0)throw new RangeError("Collision margin must be finite and non-negative.");return r}function Bn(e){const r=new Map(e.nodes.map(a=>[a.id,a])),t=new Map;for(const a of e.nodes){const c=a.parent&&r.has(a.parent)?a.parent:void 0,l=t.get(c)??[];l.push(a.id),t.set(c,l)}const n=[],o=new Map,i=a=>{const c=t.get(a),l=c?c.flatMap(i):e.positions.has(a)?[a]:[];return o.set(a,l),c&&n.push(c),l},s=t.get(void 0)??[];return s.forEach(i),n.push(s),{groups:n,leaves:o,children:t,roots:s}}function fr(e,r,t=e.fixedSizes){const n=md(e.nodes,r,e.sizes,e.padding,e.minSize,t);for(const o of e.nodes){if(n.has(o.id))continue;const i=r.get(o.id),s=e.sizes.get(o.id);i&&s&&n.set(o.id,Jt({...i,...s}))}return n}function Hv(e,r,t,n){const o=t.get(e),i=t.get(r);if(!o||!i)return;const s={x:Math.min(o.x2-i.x1,i.x2-o.x1)+n,y:Math.min(o.y2-i.y1,i.y2-o.y1)+n};if(s.x>.001&&s.y>.001)return{source:e,target:r,overlap:s}}function Tn(e,r,t){const n=[];for(const o of e)for(let i=0;i<o.length;i++)for(let s=i+1;s<o.length;s++){const a=Hv(o[i],o[s],r,t);a&&n.push(a)}return n}function Kv(e,r={}){const t=ou(r),{groups:n}=Bn(e);return Tn(n,fr(e,e.positions),t)}function Jv(e,r,t,n){var a,c,l;const o=new Set(e),i=(((l=(c=(a=r.adjustment)==null?void 0:a.sections)==null?void 0:c[t])==null?void 0:l.members)??[]).map(d=>d.filter(u=>o.delete(u))).filter(d=>d.length),s=e.filter(d=>o.has(d));for(let d=0;d<s.length;d+=n)i.push(s.slice(d,d+n));return i}function Ej(e,r,t,n,o){var b,x,w,C;if(t===n)return;const{groups:i,leaves:s}=Bn(e),a=i.find(S=>S.includes(t)&&S.includes(n));if(!a||a.some(S=>e.fixedIds.has(S)||(s.get(S)??[]).some(_=>e.fixedIds.has(_))))return;const c=fr(e,e.positions);if(a.some(S=>!c.has(S)))return;const l=((b=e.nodes.find(S=>S.id===t))==null?void 0:b.parent)??"canvas",d=(w=(x=r.adjustment)==null?void 0:x.sections)==null?void 0:w[l],u=[],h=[...a].sort((S,_)=>{const I=c.get(S),E=c.get(_),O=(I.y1+I.y2-E.y1-E.y2)/2;return Math.abs(O)>1?O:I.x1-E.x1});for(const S of h){const _=u.at(-1),I=c.get(S),E=_&&c.get(_[0]);E&&Math.abs(I.y1+I.y2-E.y1-E.y2)<2?_.push(S):u.push([S])}const p=u.map((S,_)=>{var I;return{weight:((I=d==null?void 0:d.rows)==null?void 0:I[_])??1,cells:S.map((E,O)=>{var A,R;return{id:E,weight:((R=(A=d==null?void 0:d.columns)==null?void 0:A[_])==null?void 0:R[O])??1}})}});for(const S of p)S.cells=S.cells.filter(_=>_.id!==t);const m=p.filter(S=>S.cells.length),y=m.findIndex(S=>S.cells.some(_=>_.id===n)),g=m[y];if(!g)return;o==="above"||o==="below"?m.splice(y+(o==="below"?1:0),0,{weight:1,cells:[{id:t,weight:1}]}):g.cells.splice(g.cells.findIndex(S=>S.id===n)+(o==="after"?1:0),0,{id:t,weight:1});const v=m.map(S=>S.cells.map(_=>_.id));if(JSON.stringify(v)!==JSON.stringify(u))return{...r,adjustment:{...r.adjustment,sections:{...(C=r.adjustment)==null?void 0:C.sections,[l]:{...d,members:v,rows:m.map(S=>S.weight),columns:m.map(S=>S.cells.map(_=>_.weight))}}}}}function ad(e,r={}){var d;Uv(r.adjustment);const t=ou(r),n=typeof r.gaps=="object"?r.gaps:{x:r.gaps??t,y:r.gaps??t};if(!n||[n.x,n.y].some(u=>!Number.isFinite(u)||u<0))throw new RangeError("Grid gaps must be finite and non-negative.");const o=r.padding??0;if(!Number.isFinite(o)||o<0)throw new RangeError("Grid padding must be finite and non-negative.");if(r.columns!==void 0&&(!Number.isSafeInteger(r.columns)||r.columns<1))throw new RangeError("Grid columns must be a positive safe integer.");if(r.fill&&e.viewportSize)return kj(e,r,n,o);const{groups:i,leaves:s}=Bn(e),a=new Map([...e.positions].map(([u,h])=>[u,{...h}])),c=new Set;for(const u of i){const h=fr(e,a),p=u.filter(A=>h.has(A));if(p.length<2)continue;if(p.some(A=>e.fixedIds.has(A)||(s.get(A)??[]).some(R=>e.fixedIds.has(R)))){p.forEach(A=>c.add(A));continue}const y=p.map(A=>h.get(A)),g=Math.max(...y.map(A=>A.x2-A.x1)),v=Math.max(...y.map(A=>A.y2-A.y1)),b=Math.min(p.length,r.columns??Math.ceil(Math.sqrt(p.length))),x=((d=e.nodes.find(A=>A.id===p[0]))==null?void 0:d.parent)??"canvas",w=Jv(p,r,x,b),C=Math.max(...w.map(A=>A.length)),S=g+n.x,_=v+n.y,I=y.map(A=>({x:(A.x1+A.x2)/2,y:(A.y1+A.y2)/2})),E=(Math.min(...I.map(A=>A.x))+Math.max(...I.map(A=>A.x)))/2,O=(Math.min(...I.map(A=>A.y))+Math.max(...I.map(A=>A.y)))/2;w.forEach((A,R)=>A.forEach((P,T)=>{const N=h.get(P),$={x:E+(T-(C-1)/2)*S-(N.x1+N.x2)/2,y:O+(R-(w.length-1)/2)*_-(N.y1+N.y2)/2};for(const M of s.get(P)??[]){const W=a.get(M);a.set(M,{x:W.x+$.x,y:W.y+$.y})}}))}const l=[...a].filter(([u,h])=>{const p=e.positions.get(u);return h.x!==p.x||h.y!==p.y}).map(([u])=>u);return{positions:a,movedNodeIds:l,skippedNodeIds:[...c],collisions:Tn(i,fr(e,a),Math.min(n.x,n.y))}}function kj(e,r,t,n){const{groups:o,children:i,roots:s}=Bn(e),a=new Map([...e.positions].map(([g,v])=>[g,{...v}]));if(e.nodes.some(g=>e.fixedIds.has(g.id)))return{positions:a,movedNodeIds:[],skippedNodeIds:e.nodes.map(g=>g.id),collisions:Kv(e,{margin:Math.min(t.x,t.y)})};const c=e.viewportSize,l=Math.min(n,Math.max(0,(c.w-1)/2)),d=Math.min(n,Math.max(0,(c.h-1)/2)),u={x1:l,y1:d,x2:Math.max(l+1,c.w-l),y2:Math.max(d+1,c.h-d)},h=new Map,p=[],m=(g,v,b="canvas")=>{var T,N;if(!g.length)return;const x=v.x2-v.x1,w=v.y2-v.y1,C=Math.min(g.length,r.columns??Math.max(1,Math.round(Math.sqrt(g.length*x/w)))),S=Jv(g,r,b,C),_=S.length,I=Math.min(t.y,w/(2*_)),E=(N=(T=r.adjustment)==null?void 0:T.sections)==null?void 0:N[b],O=Array.from({length:_},($,M)=>{var W;return((W=E==null?void 0:E.rows)==null?void 0:W[M])??1}),A=O.reduce(($,M)=>$+M,0),R=w-(_-1)*I;let P=v.y1;for(let $=0;$<_;$++){const M=R*O[$]/A,W=S[$].length,ae=Math.min(t.x,x/(2*W)),se=Array.from({length:W},(L,z)=>{var U,B;return((B=(U=E==null?void 0:E.columns)==null?void 0:U[$])==null?void 0:B[z])??1}),re=se.reduce((L,z)=>L+z,0),ye=x-(W-1)*ae;let me=v.x1;for(let L=0;L<W;L++){const z=S[$][L],U=ye*se[L]/re,B=i.get(z);if(B){a.set(z,{x:me+U/2,y:P+M/2}),h.set(z,{w:U,h:M});const ce=Math.min(e.padding(z),Math.max(0,(Math.min(U,M)-1)/2));m(B,{x1:me+ce,y1:P+ce,x2:me+U-ce,y2:P+M-ce},z)}else a.has(z)&&(a.set(z,{x:me+U/2,y:P+M/2}),h.set(z,{w:U,h:M}));L<W-1&&p.push({section:b,axis:"x",row:$,index:L,weights:se,length:ye,position:{x:me+U+ae/2,y:P+M/2}}),me+=U+ae}$<_-1&&p.push({section:b,axis:"y",row:$,index:$,weights:O,length:R,position:{x:v.x1+x/2,y:P+M+I/2}}),P+=M+I}};m(s,u);const y=[...a].filter(([g,v])=>{const b=e.positions.get(g);return!b||v.x!==b.x||v.y!==b.y}).map(([g])=>g);return{positions:a,movedNodeIds:y,skippedNodeIds:[],bounds:u,sizes:h,dividers:p,collisions:Tn(o,fr({...e,sizes:h},a,h),0)}}function Rj(e,r={}){const t=ou(r),n=r.maxIterations??50;if(!Number.isInteger(n)||n<0||n>1e3)throw new RangeError("Collision maxIterations must be an integer between 0 and 1000.");const{groups:o,leaves:i}=Bn(e),s=new Map([...e.positions].map(([u,h])=>[u,{...h}])),a=u=>e.fixedIds.has(u)||(i.get(u)??[]).some(h=>e.fixedIds.has(h));let c=Tn(o,fr(e,s),t),l=0;for(;c.length&&l<n;){let u=!1;for(const h of o){if(h.length<2)continue;const p=fr(e,s),m=(y,g,v)=>{for(const x of i.get(y)??[])s.get(x)[g]+=v;const b=p.get(y);g==="x"?(b.x1+=v,b.x2+=v):(b.y1+=v,b.y2+=v)};for(let y=0;y<h.length;y++)for(let g=y+1;g<h.length;g++){const v=h[y],b=h[g],x=Hv(v,b,p,t);if(!x)continue;const w=a(v),C=a(b);if(w&&C)continue;const S=x.overlap.x<=x.overlap.y?"x":"y",_=p.get(v),I=p.get(b),E=S==="x"?_.x1+_.x2<=I.x1+I.x2?-1:1:_.y1+_.y2<=I.y1+I.y2?-1:1,O=x.overlap[S];w||m(v,S,E*O/(C?1:2)),C||m(b,S,-E*O/(w?1:2)),u=!0}}if(l++,c=Tn(o,fr(e,s),t),!u)break}const d=[...s].filter(([u,h])=>{const p=e.positions.get(u);return h.x!==p.x||h.y!==p.y}).map(([u])=>u);return{positions:s,movedNodeIds:d,collisions:c,iterations:l,resolved:c.length===0}}function Aj({dividers:e,options:r,zoom:t,onChange:n}){const o=j.useRef();return f.jsx(f.Fragment,{children:e.map(i=>{const s=i.axis==="x",a=s?Z.PiArrowsHorizontal:Z.PiArrowsVertical,c=`${s?"Column":"Row"} divider ${i.index+1}${s?` in row ${i.row+1}`:""}`;return f.jsx("button",{type:"button",role:"separator","aria-label":c,"aria-orientation":s?"vertical":"horizontal","aria-valuemin":5,"aria-valuemax":95,"aria-valuenow":Math.round(100*i.weights[i.index]/(i.weights[i.index]+i.weights[i.index+1])),title:c,"data-flow-grid-adjustment":"",style:{position:"absolute",left:i.position.x,top:i.position.y,transform:"translate(-50%, -50%)",width:28,height:28,padding:3,border:"1px solid currentColor",borderRadius:4,background:"var(--chakra-colors-gray-100)",color:"var(--chakra-colors-gray-800)",display:"grid",placeItems:"center",cursor:s?"col-resize":"row-resize",touchAction:"none",pointerEvents:"auto",zIndex:30},onPointerDown:l=>{if(l.button!==0)return;l.preventDefault(),l.stopPropagation();const d=l.currentTarget.closest(".flow-sdk-canvas"),u=d.getBoundingClientRect();o.current={pointerId:l.pointerId,start:s?l.clientX:l.clientY,scale:t*(s?u.width/d.clientWidth:u.height/d.clientHeight),divider:i,options:r},l.currentTarget.setPointerCapture(l.pointerId)},onPointerMove:l=>{const d=o.current;if(!d||d.pointerId!==l.pointerId)return;l.preventDefault(),l.stopPropagation();const u=((s?l.clientX:l.clientY)-d.start)/d.scale;n(mm(d.options,d.divider,u))},onPointerUp:l=>{o.current&&(l.stopPropagation(),o.current=void 0,l.currentTarget.releasePointerCapture(l.pointerId))},onPointerCancel:()=>{o.current&&n(o.current.options),o.current=void 0},onLostPointerCapture:()=>{o.current=void 0},onClick:l=>l.stopPropagation(),onKeyDown:l=>{l.key==="Escape"&&o.current&&(n(o.current.options),o.current=void 0);const d=(s?["ArrowLeft","ArrowRight"]:["ArrowUp","ArrowDown"]).indexOf(l.key);d<0||(l.preventDefault(),l.stopPropagation(),n(mm(r,i,i.length*(l.shiftKey?.1:.02)*(d===0?-1:1))))},children:f.jsx(a,{size:20,"aria-hidden":"true"})},`${i.section}:${i.axis}:${i.row}:${i.index}`)})})}const bm=(e,r)=>e.left<r.right&&e.right>r.left&&e.top<r.bottom&&e.bottom>r.top,sd=new WeakMap;function vm(e,r){const t=[...r.querySelectorAll(".flow-sdk-edge-label")];if(!t.length){sd.delete(r);return}const n=r==null?void 0:r.getScreenCTM();if(!r||!n)return;const o=n.inverse(),i=(u,h=0)=>{const p=u.getBoundingClientRect(),m=new DOMPoint(p.left,p.top).matrixTransform(o),y=new DOMPoint(p.right,p.bottom).matrixTransform(o);return{left:m.x-h,right:y.x+h,top:m.y-h,bottom:y.y+h}},s=[...e.querySelectorAll(".flow-sdk-node, .flow-sdk-node button")].filter(u=>u.closest(".flow-sdk-canvas")===e).filter(u=>{const h=u.getBoundingClientRect(),p=getComputedStyle(u);return h.width>0&&h.height>0&&p.visibility!=="hidden"&&p.opacity!=="0"}).map(u=>i(u,24));for(const u of r.querySelectorAll(".flow-sdk-container-label"))s.push(i(u,12));const a=new Map([...e.querySelectorAll(".flow-sdk-edge")].filter(u=>u.closest(".flow-sdk-canvas")===e).map(u=>[u.dataset.edgeId,u.querySelector("path")])),c=JSON.stringify([s,[...a].map(([u,h])=>[u,h==null?void 0:h.getAttribute("d")]),t.map(u=>{var m;const h=u.getBBox(),p=(m=u.querySelector("rect"))==null?void 0:m.getBBox();return[u.dataset.edgeId,u.dataset.labelTransform,u.dataset.labelHorizontal,h.x,h.y,h.width,h.height,p==null?void 0:p.width,p==null?void 0:p.height]})],(u,h)=>typeof h=="number"?Math.round(h*1e3)/1e3:h),l=sd.get(r);if((l==null?void 0:l.geometry)===c&&t.every(u=>l.transforms.has(u))){for(const u of t){const h=l.transforms.get(u);u.getAttribute("transform")!==h&&u.setAttribute("transform",h)}return}for(const u of t)u.setAttribute("transform",u.dataset.labelTransform??"");const d=new Map(t.map(u=>[u,i(u,8)]));for(const u of t){const h=u.dataset.labelHorizontal==="true",p=d.get(u);d.delete(u);const m=E=>s.some(O=>bm(E,O))||[...d.values()].some(O=>bm(E,O));if(!h&&!m(p)){d.set(u,p);continue}const y=a.get(u.dataset.edgeId),g=u.querySelector("rect");if(!y||!g)continue;const v=g.getBBox(),b=y.getTotalLength();if(!Number.isFinite(b)||b<=0)continue;const x=(p.left+p.right)/2,w=(p.top+p.bottom)/2,C=Math.min(256,Math.max(16,Math.ceil(b/24))),S=Array.from({length:C+1},(E,O)=>y.getPointAtLength(b*O/C)),I=Array.from({length:C+1},(E,O)=>{const A=b*O/C,R=S[O],P=h?{x:R.x,y:R.y-v.height/2-15}:R,T=y.getPointAtLength(Math.max(0,A-2)),N=y.getPointAtLength(Math.min(b,A+2));let $=Math.atan2(N.y-T.y,N.x-T.x)*180/Math.PI;$>90&&($-=180),$<-90&&($+=180);const M=Math.abs($)<1;h&&($=0);const W=$*Math.PI/180,ae=Math.abs(Math.cos(W))*v.width+Math.abs(Math.sin(W))*v.height,se=Math.abs(Math.sin(W))*v.width+Math.abs(Math.cos(W))*v.height;return{point:P,angle:$,straight:M,score:Math.hypot(P.x-x,P.y-w),bounds:{left:P.x-ae/2-8,right:P.x+ae/2+8,top:P.y-se/2-8,bottom:P.y+se/2+8}}}).sort((E,O)=>E.score-O.score).find(E=>!m(E.bounds)&&(!h||E.straight&&!S.some(O=>O.x>E.bounds.left&&O.x<E.bounds.right&&O.y>E.bounds.top&&O.y<E.bounds.bottom)));I?(u.setAttribute("transform",`translate(${I.point.x} ${I.point.y}) rotate(${I.angle})`),d.set(u,I.bounds)):d.set(u,p)}sd.set(r,{geometry:c,transforms:new Map(t.map(u=>[u,u.getAttribute("transform")??""]))})}function Pj(e){const r=e.getBoundingClientRect(),t=r.height/e.offsetHeight;if(!Number.isFinite(t)||t<=0)return[];const n=Bb(e),o={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},i=[...e.querySelectorAll("[data-flow-property]")],s=new Set(i.filter(a=>a.hasAttribute("data-flow-inspection-row")&&a.getBoundingClientRect().height>0).map(a=>a.dataset.flowProperty));return i.flatMap(a=>{if(a.closest(".flow-sdk-node")!==e)return[];if(s.has(a.dataset.flowProperty)&&!a.hasAttribute("data-flow-inspection-row"))return[];const c=a.dataset.flowPortSide;if(c&&["top","right","bottom","left"].includes(c)){const d=Lb(n?En(o,n):o,c,Number(a.dataset.flowPortPosition??.5));return[{property:a.getAttribute("data-flow-property"),top:d.y,height:0,anchor:d,...a.dataset.flowPortPlacement==="config"?{placement:"config"}:{},...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]}const l=a.getBoundingClientRect();return!l.width||!l.height?[]:[{property:a.getAttribute("data-flow-property"),top:Math.round((l.top-r.top)/t*1e3)/1e3,height:Math.round(l.height/t*1e3)/1e3,...a.dataset.flowPortRole==="source"||a.dataset.flowPortRole==="target"?{role:a.dataset.flowPortRole}:{}}]})}function Mj({id:e,x:r,y:t,placed:n,hidden:o,gridDraggable:i,gridDragging:s,gridDropTarget:a,gridSize:c,gridPreview:l,onMount:d,drawHandles:u,drawMode:h,connectedPorts:p,resolvedRows:m,hasCollapseControl:y,handleColor:g,animated:v,animationColor:b,animationWidth:x=8,animationVariant:w,width:C=0,height:S=0,propertyMode:_,reversePorts:I,direction:E="LR",onPropertyRows:O,onSurface:A,children:R}){var B,ce;const P=j.useRef(null),[T,N]=j.useState([]),$=m??T,[M,W]=j.useState(),ae=j.useId(),se=j.useRef(),re=!!l,ye=!!(l!=null&&l.floating);j.useLayoutEffect(()=>{var Ce;const X=P.current;if(!X||!re)return;const le=X.cloneNode(!0);le.removeAttribute("data-node-id"),le.removeAttribute("data-grid-dragging"),le.removeAttribute("data-grid-draggable"),le.removeAttribute("data-grid-drop-target"),le.setAttribute("data-grid-preview",e),le.setAttribute("aria-hidden","true"),le.setAttribute("inert","");const ue=[le,...le.querySelectorAll("*")],xe=new Map(ue.filter(ge=>ge.id).map(ge=>[ge.id,`${ge.id}-${ae}`]));for(const ge of ue){ge.id&&(ge.id=xe.get(ge.id));for(const he of[...ge.attributes]){if(he.name==="id")continue;let Y=he.value;for(const[H,ve]of xe)Y===`#${H}`&&(Y=`#${ve}`),Y=Y.split(`url(#${H})`).join(`url(#${ve})`);Y!==he.value&&ge.setAttribute(he.name,Y)}}if(Object.assign(le.style,{opacity:"0.35",zIndex:ye?"2147483647":"11",pointerEvents:"none",outline:"none",visibility:"visible"}),ye){const ge=getComputedStyle(X);le.setAttribute("data-grid-preview-floating",""),Object.assign(le.style,{position:"fixed",left:"0",top:"0",transformOrigin:"top left",font:ge.font,color:ge.color});for(const he of ue)he.removeAttribute("data-node-id"),he.style.pointerEvents="none"}return le.querySelectorAll(".flow-sdk-node-animation, .flow-sdk-handle, .flow-sdk-property-port, [data-flow-collapse-control]").forEach(ge=>ge.remove()),(Ce=ye?document.body:X.parentElement)==null||Ce.appendChild(le),se.current=le,()=>{le.remove(),se.current=void 0}},[e,ae,re,ye]),j.useLayoutEffect(()=>{const X=se.current;if(!X||!l)return;const{x:le,y:ue,size:xe}=l;if(ye&&P.current){const he=P.current,Y=he.getBoundingClientRect(),H=Y.width/he.offsetWidth||1,ve=Y.height/he.offsetHeight||1,J=Y.left+(le-r)*H,be=Y.top+(ue-t)*ve;X.style.transform=`translate3d(${J}px, ${be}px, 0) scale(${H}, ${ve})`,X.style.width=`${he.offsetWidth}px`,X.style.height=`${he.offsetHeight}px`;return}const Ce=xe?Math.round(le-xe.w/2):le,ge=xe?Math.round(ue-xe.h/2):ue;X.style.transform=xe?`translate3d(${Ce}px, ${ge}px, 0)`:`translate(-50%, -50%) translate3d(${Ce}px, ${ge}px, 0)`,X.style.width=xe?`${Math.round(le+xe.w/2)-Ce}px`:"",X.style.height=xe?`${Math.round(ue+xe.h/2)-ge}px`:"",xe&&(X.style.setProperty("--flow-grid-width",`${xe.w}px`),X.style.setProperty("--flow-grid-height",`${xe.h}px`),X.style.setProperty("--flow-grid-font",`${Math.max(12,Math.min(48,xe.w/8,xe.h/5))}px`))},[l==null?void 0:l.x,l==null?void 0:l.y,(B=l==null?void 0:l.size)==null?void 0:B.w,(ce=l==null?void 0:l.size)==null?void 0:ce.h,ye,r,t]),j.useLayoutEffect(()=>{const X=P.current;if(!X)return;const le=()=>{const Ce=Bb(X);W(ge=>JSON.stringify(ge)===JSON.stringify(Ce)?ge:Ce),A==null||A(e,Ce)};le();const ue=new ResizeObserver(le);ue.observe(X);const xe=X.querySelector("[data-flow-node-surface]");return xe&&ue.observe(xe),()=>ue.disconnect()},[e,R,A]),j.useLayoutEffect(()=>(d(e,P.current),()=>{d(e,null),A==null||A(e,void 0)}),[e,d,A]),j.useLayoutEffect(()=>{const X=P.current;if(!X)return;let le="";const ue=()=>{const he=Pj(X),Y=_?he:he.filter(ve=>ve.anchor),H=JSON.stringify(Y);H!==le&&(le=H,N(Y),O==null||O(e,Y))};if(ue(),!_&&!X.querySelector("[data-flow-port-side]"))return;const xe=new ResizeObserver(ue),Ce=()=>{xe.disconnect(),xe.observe(X),X.querySelectorAll("[data-flow-property]").forEach(he=>xe.observe(he)),ue()};Ce();const ge=new MutationObserver(Ce);return ge.observe(X,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["data-flow-property","data-flow-port-role","data-flow-port-side","data-flow-port-position","data-flow-port-placement"]}),X.addEventListener("scroll",ue,!0),()=>{xe.disconnect(),ge.disconnect(),X.removeEventListener("scroll",ue,!0)}},[e,_,O,R]);const me=c?Math.round(r-c.w/2):0,L=c?Math.round(t-c.h/2):0,z=c?Math.round(r+c.w/2)-me:void 0,U=c?Math.round(t+c.h/2)-L:void 0;return f.jsxs("div",{ref:P,className:"flow-sdk-node","data-node-id":e,"data-grid-draggable":i||void 0,"data-grid-dragging":s||void 0,"data-grid-drop-target":a||void 0,"data-grid-fill":c?"":void 0,style:{transform:c?`translate3d(${me}px, ${L}px, 0)`:`translate(-50%, -50%) translate3d(${r.toFixed(2)}px, ${t.toFixed(2)}px, 0)`,visibility:n&&!o?void 0:"hidden",cursor:i?s?"grabbing":"grab":void 0,zIndex:s?12:void 0,opacity:l?0:s?.75:void 0,outline:a?`2px solid ${g||"currentColor"}`:void 0,outlineOffset:a?8:void 0,width:z,height:U,...c?{"--flow-grid-width":`${c.w}px`,"--flow-grid-height":`${c.h}px`,"--flow-grid-font":`${Math.max(12,Math.min(48,c.w/8,c.h/5))}px`}:{}},children:[R,!c&&v&&x>0&&C>0&&S>0&&f.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:f.jsx(no,{variant:w,x:((M==null?void 0:M.left)??0)+x/2,y:((M==null?void 0:M.top)??0)+x/2,width:((M==null?void 0:M.width)??C)-x,height:((M==null?void 0:M.height)??S)-x,radius:((M==null?void 0:M.radius)??0)-x/2,path:M!=null&&M.outline?`M${M.outline.map(X=>`${X.x} ${X.y}`).join(" L")} Z`:void 0,color:b||g||"currentColor",strokeWidth:x})}),u&&_&&$.map(X=>["source","target"].filter(le=>!X.role||X.role===le).filter(le=>h||(p==null?void 0:p.has(`${le}:${X.property}`))).map(le=>{var ue;return f.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":X.property,"data-port-role":le,"data-port-side":(ue=X.anchor)==null?void 0:ue.side,"aria-label":`${le==="source"?"Connect":"Input"} ${X.property}`,title:`${le==="source"?"Connect":"Input"} ${X.property}`,style:{color:g,...X.anchor?{top:X.anchor.y,left:X.anchor.x-16}:{top:X.top+X.height/2,[le==="source"!=!!I?"right":"left"]:-16}},onClick:xe=>xe.stopPropagation()},`${X.property}:${le}`)})),u&&!y&&(!_||!$.length)&&(!_||!$.some(X=>X.anchor))&&f.jsx("button",{type:"button",className:"flow-sdk-handle","aria-label":"Draw edge",title:"Draw edge",style:{color:g,left:((M==null?void 0:M.left)??0)+(E==="RL"?-36:E==="LR"?(M==null?void 0:M.width)??C:((M==null?void 0:M.width)??C)/2),top:((M==null?void 0:M.top)??0)+(E==="BT"?-36:E==="TB"?(M==null?void 0:M.height)??S:((M==null?void 0:M.height)??S)/2),transform:E==="BT"||E==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:X=>X.stopPropagation(),children:f.jsx(Z.PiPlusBold,{size:24})})]})}const Ij=j.memo(Mj);function Tj(e,r,t){const[n,o]=j.useState(()=>({nodes:new Set,edges:new Set})),i=j.useMemo(()=>{const a=new Set(e.map(p=>p.id)),c=r.filter(p=>a.has(p.source)&&a.has(p.target)).map(p=>({id:p.id,source:p.inverted?p.target:p.source,target:p.inverted?p.source:p.target})),l=new Set(c.map(p=>p.id)),d=new Set([...n.nodes].filter(p=>a.has(p))),u=new Set([...n.edges].filter(p=>l.has(p)));if(!t)return{nodes:a,edges:l,ready:l};for(const p of e)c.filter(y=>y.target===p.id&&y.source!==y.target).every(y=>u.has(y.id))&&d.add(p.id);let h=new Set(c.filter(p=>d.has(p.source)).map(p=>p.id));if(d.size<a.size&&!c.some(p=>h.has(p.id)&&!u.has(p.id))){const p=e.find(m=>!d.has(m.id));p&&d.add(p.id),h=new Set(c.filter(m=>d.has(m.source)).map(m=>m.id))}return{nodes:d,edges:u,ready:h}},[e,r,t,n]);j.useLayoutEffect(()=>{o(a=>{const c=t?i:{nodes:new Set,edges:new Set},l=(d,u)=>d.size===u.size&&[...d].every(h=>u.has(h));return l(a.nodes,c.nodes)&&l(a.edges,c.edges)?a:{nodes:c.nodes,edges:c.edges}})},[i,t]);const s=j.useCallback(a=>{o(c=>c.edges.has(a)?c:{...c,edges:new Set([...c.edges,a])})},[]);return{shown:i.nodes,ready:i.ready,complete:s}}class Oj{constructor(r,t,n){Nt(this,"_pan");Nt(this,"_zoom");Nt(this,"minZoom");Nt(this,"maxZoom");Nt(this,"size",{w:0,h:0});Nt(this,"listeners",new Set);Nt(this,"cancelTransition");Nt(this,"animationVersion",0);Nt(this,"captureTransition");Nt(this,"animationsDisabled",!1);Nt(this,"finishTransition");this.minZoom=t,this.maxZoom=n,this._pan={...r.pan},this._zoom=this.clamp(r.zoom)}setAnimationsDisabled(r){var t;r!==this.animationsDisabled&&(this.animationsDisabled=r,r&&((t=this.finishTransition)==null||t.call(this),this.cancelAnimation()))}cancelAnimation(){var r;(r=this.cancelTransition)==null||r.call(this),this.cancelTransition=void 0,this.finishTransition=void 0,this.animationVersion++}coordinate(r){let t;this.captureTransition=n=>{t=n};try{r()}finally{this.captureTransition=void 0}return t}transition(r,t=!1){this.cancelAnimation();const n=this.state,o={pan:{...r.pan},zoom:this.clamp(r.zoom)},i=this.animationVersion,s=$b(t,this.animationsDisabled),a=c=>{if(i!==this.animationVersion)return;const l=s?c:1;this.apply({x:n.pan.x+(o.pan.x-n.pan.x)*l,y:n.pan.y+(o.pan.y-n.pan.y)*l},n.zoom+(o.zoom-n.zoom)*l)};this.finishTransition=()=>a(1),this.captureTransition?this.captureTransition(a):this.cancelTransition=qb(s,a,void 0,300/1.4)}get pan(){return{...this._pan}}get zoom(){return this._zoom}get state(){return{pan:this.pan,zoom:this._zoom}}clamp(r){return Number.isFinite(r)?Math.max(this.minZoom,Math.min(this.maxZoom,r)):this.minZoom}set(r,t){this.cancelAnimation(),this.apply(r,t)}apply(r,t){let n=!1;if(r&&(r.x!==this._pan.x||r.y!==this._pan.y)&&(this._pan={x:r.x,y:r.y},n=!0),t!==void 0){const o=this.clamp(t);o!==this._zoom&&(this._zoom=o,n=!0)}n&&this.emit()}zoomAt(r,t){const n=this.clamp(r),o=this._zoom;if(n===o)return;const i=n/o;this.set({x:t.x-(t.x-this._pan.x)*i,y:t.y-(t.y-this._pan.y)*i},n)}fit(r,t=0,n=!1,o=1){const i=r.x2-r.x1,s=r.y2-r.y1;if(!(i>0)||!(s>0)||!this.size.w||!this.size.h)return;const a=this.clamp(this.clamp(Math.min((this.size.w-2*t)/i,(this.size.h-2*t)/s))*o);this.transition({pan:{x:(this.size.w-a*(r.x1+r.x2))/2,y:(this.size.h-a*(r.y1+r.y2))/2},zoom:a},n)}center(r,t=!1){if(!this.size.w||!this.size.h)return;const n=this._zoom;this.transition({pan:{x:(this.size.w-n*(r.x1+r.x2))/2,y:(this.size.h-n*(r.y1+r.y2))/2},zoom:n},t)}renderedToModel(r){return{x:(r.x-this._pan.x)/this._zoom,y:(r.y-this._pan.y)/this._zoom}}modelToRendered(r){return{x:r.x*this._zoom+this._pan.x,y:r.y*this._zoom+this._pan.y}}onChange(r){return this.listeners.add(r),()=>{this.listeners.delete(r)}}emit(){const r=this.state;this.listeners.forEach(t=>t(r))}}const Nj={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},Yn={w:60,h:60},cd=4,$j=30,qj=500,Lj=45;function xm(e){const[r,t]=[...e.values()];return!r||!t?null:{center:{x:(r.x+t.x)/2,y:(r.y+t.y)/2},distance:Math.max(1,Math.hypot(t.x-r.x,t.y-r.y))}}function Fj(e){var gu,yu,mu,bu,vu;const{nodes:r,edges:t,direction:n,nodeAlignment:o="center",edgeMode:i="auto",compactPropertyLayout:s=!1,rankSep:a,edgeSep:c,spacingFactor:l=1.3,compactSpacingScale:d,minZoom:u,maxZoom:h,initialViewport:p,containerStyle:m,lineColor:y,drawMode:g,dragMode:v,multiSelect:b,isPerformanceMode:x,disableAnimations:w=!1}=e,[C,S]=j.useState(null),_=j.useMemo(()=>C?(C.mode==="connections"?Uu:zu)(C.id,r,t):null,[C,r,t]),I=i==="auto"||i==="properties",E=j.useMemo(()=>t.filter(k=>yd(k,i)&&(!_||_.has(k.source)&&_.has(k.target))),[t,i,_]),O=j.useMemo(()=>n1(r,t,i,s,_),[r,t,i,s,_]),A=j.useRef(O);A.current=O;const R=j.useRef(e);R.current=e;const P=j.useRef(null),T=j.useRef(null),N=j.useRef(null),$=j.useRef(null),M=j.useMemo(()=>new Oj(p,u,h),[]);j.useEffect(()=>{M.minZoom=u,M.maxZoom=h},[M,u,h]),j.useLayoutEffect(()=>{M.setAnimationsDisabled(w)},[M,w]);const W=j.useRef(new Map),ae=j.useRef(new Map),se=j.useRef(new Map),re=j.useRef(null),[ye,me]=j.useState(new Map),L=j.useCallback((k,q)=>{me(F=>{if(JSON.stringify(F.get(k))===JSON.stringify(q))return F;const K=new Map(F);return q?K.set(k,q):K.delete(k),K})},[]),[z,U]=j.useState(new Map),B=j.useRef(z),ce=j.useCallback((k,q)=>{U(F=>{if(JSON.stringify(F.get(k)??[])===JSON.stringify(q))return F;const K=new Map(F);return q.length?K.set(k,q):K.delete(k),K})},[]),[X,le]=j.useState(()=>new Map),ue=j.useRef(X);ue.current=X;const[xe,Ce]=j.useState(new Map),ge=j.useRef(xe),he=()=>{ge.current=new Map,Ce(ge.current)},Y=j.useRef(new Map),H=j.useRef(null),ve=j.useRef(!1),[J,be]=j.useState(0),Q=j.useRef(),je=j.useRef(),Pe=j.useRef(null),qe=j.useRef(!1),Xe=j.useRef(null),Be=j.useRef(null),ut=j.useRef(l),De=s,rt=j.useRef(De),[pt,Ne]=j.useState(!0),[Ge,st]=j.useState(!!((gu=e.initialNodeGrid)!=null&&gu.enabled)),[ct,Bt]=j.useState([]),Ue=j.useRef((yu=e.initialNodeGrid)!=null&&yu.enabled?{options:{...e.initialNodeGrid.options,animate:!1},order:[...e.initialNodeGrid.order??e.initialNodeGrid.options.order??r.map(k=>k.id)],previousPositions:new Map,previousViewport:p,previousSize:{w:0,h:0},ready:!1}:null),[We,Ut]=j.useState(null),lt=j.useRef(null);lt.current=_;const or=j.useRef(1);or.current=(C==null?void 0:C.mode)==="connections"?1.25:1;const Ht=j.useRef(null),Or=j.useRef(r),_t=j.useRef([]),Kt=j.useRef(!1),Qt=()=>{var k;(k=Pe.current)==null||k.call(Pe),Pe.current=null},Nr=()=>{Be.current=null,_t.current.length&&(Kt.current=!0),!ve.current&&R.current.fitOnInit!==!1&&(qe.current=!0),clearTimeout(je.current),je.current=setTimeout(()=>{ve.current=ue.current.size>0,be(k=>k+1)},qj)},vr=(k,q,F,K=Nr,de)=>{Qt();const Ie=new Map(ue.current),we=new Map([...W.current,...ge.current]);Pe.current=qb(q,ke=>{const Te=new Map;if(k.forEach((Re,$e)=>{const Ye=Ie.get($e);Te.set($e,Ye?{x:Ye.x+(Re.x-Ye.x)*ke,y:Ye.y+(Re.y-Ye.y)*ke}:Re)}),ue.current=Te,le(Te),de){const Re=new Map;for(const[$e,Ye]of de){const te=we.get($e)??Ye;Re.set($e,{w:te.w+(Ye.w-te.w)*ke,h:te.h+(Ye.h-te.h)*ke})}ge.current=Re,Ce(Re)}F==null||F(ke)},K)},ze=()=>{if(clearTimeout(Q.current),Ue.current){mt.arrangeNodesInGrid(Ue.current.options);return}ge.current.size&&he();const k=R.current,q=or.current,F=A.current,K=F.nodes.map(Te=>{const Re=ae.current.get(Te.id);Re&&(Re.offsetWidth||Re.offsetHeight)&&W.current.set(Te.id,{w:Re.offsetWidth,h:Re.offsetHeight});const $e=W.current.get(Te.id)||Yn;return{id:Te.id,parent:Te.parent,width:$e.w,height:$e.h}});let de;try{const Te=k.compactPropertyLayout,Re=k.edgeMode!=="nodes"&&k.edgeMode!=="workflow",$e=F.edges.map(Ye=>({...Ye,connectorClearance:Te?Re&&(Ye.sourceProperty!==void 0||Ye.targetProperty!==void 0)?r1:t1:0}));de=_j(K,$e,{edgeLabelFontSize:k.edgeMode==="nodes"||k.edgeMode==="workflow"?Db:oo,rankDir:k.direction,compact:Te,nodeAlignment:k.nodeAlignment,rankSep:k.rankSep*q,edgeSep:k.edgeSep*q,nodeSep:5*q,spacingFactor:k.spacingFactor??1.3,compactSpacingScale:(k.compactSpacingScale??(k.spacingFactor??1.3)/1.3)*q})}catch(Te){console.warn("[flow-sdk] layout failed",Te);return}const Ie=H.current;H.current=null;const we=Ie&&de.get(Ie.id);if(Ie&&we){const Te={x:Ie.position.x-we.x,y:Ie.position.y-we.y};de=new Map([...de].map(([Re,$e])=>[Re,{x:$e.x+Te.x,y:$e.y+Te.y}]))}for(const[Te,Re]of Y.current)de.has(Te)?de.set(Te,Re):k.nodes.some($e=>$e.id===Te)||Y.current.delete(Te);const ke=M.coordinate(()=>{var Te;return(Te=Be.current)==null?void 0:Te.call(Be,de)});vr(de,ve.current&&!k.isPerformanceMode&&!k.disableAnimations,ke)},ne=j.useCallback(()=>{clearTimeout(je.current),clearTimeout(Q.current),Q.current=setTimeout(ze,R.current.layoutDebounce)},[]);j.useLayoutEffect(()=>{const k=new Map(Or.current.map(q=>[q.id,q]));r.some(q=>{var F;return((F=k.get(q.id))==null?void 0:F.collapsed)===!0&&!q.collapsed})&&(_t.current=r.filter(q=>!k.has(q.id)).map(q=>q.id)),Or.current=r,ut.current!==l&&ue.current.size>0&&(ve.current=!0,qe.current=!1,clearTimeout(je.current)),ut.current=l,rt.current!==De&&(qe.current=!Xe.current),rt.current=De,Be.current&&!Xe.current?(clearTimeout(Q.current),ze()):ne()},[r,t,O.nodes,O.edges,De,n,o,a,c,ne,l,d,w,e.nodeGridSpacing]),j.useEffect(()=>()=>{clearTimeout(Q.current),clearTimeout(je.current),Qt()},[]);const D=j.useCallback((k,q)=>{var F,K;if(!re.current&&typeof ResizeObserver<"u"&&(re.current=new ResizeObserver(de=>{let Ie=!1;for(const we of de){const ke=se.current.get(we.target);if(!ke||ge.current.has(ke))continue;const Te=we.target,Re=Te.offsetWidth,$e=Te.offsetHeight;if(!Re&&!$e)continue;const Ye=W.current.get(ke);if(Ye&&Ye.w===Re&&Ye.h===$e)continue;const te=ue.current.get(ke);Ye&&te&&ve.current&&!H.current&&(H.current={id:ke,position:{...te}}),W.current.set(ke,{w:Re,h:$e}),Ie=!0}Ie&&(Be.current&&!Xe.current?ze():ne())})),q){ae.current.set(k,q),se.current.set(q,k),(F=re.current)==null||F.observe(q);const de=q.offsetWidth,Ie=q.offsetHeight;!ge.current.has(k)&&(de||Ie)&&W.current.set(k,{w:de,h:Ie})}else{const de=ae.current.get(k);de&&((K=re.current)==null||K.unobserve(de),se.current.delete(de)),ae.current.delete(k),W.current.delete(k),B.current.has(k)&&ce(k,[])}ne()},[ne,ce]);j.useEffect(()=>()=>{var k;return(k=re.current)==null?void 0:k.disconnect()},[]);const oe=k=>{var K;const q=(K=R.current.nodes.find(de=>de.id===k))==null?void 0:K.label;if(!q)return;const F=R.current.containerStyle(k);return{w:go(q,`bold ${F.fontSize}px ${ur}`)+2*Lj,h:0}},Le=j.useMemo(()=>{const k=new Map;for(const q of r)q.label&&k.set(q.id,q.label);return k},[r]),G=j.useMemo(()=>md(O.nodes,X,new Map([...W.current,...xe]),k=>m(k).padding,oe,xe),[O.nodes,X,m,Le,xe]),fe=j.useRef(G);fe.current=G;const Se=j.useCallback(k=>{const q=fe.current.get(k);if(q)return Bw(q);const F=ue.current.get(k);if(!F)return;const K=ge.current.get(k)||W.current.get(k)||Yn;return{x:F.x,y:F.y,w:K.w,h:K.h}},[]),Ee=j.useMemo(()=>{const k=new Map;for(const q of r){const F=Se(q.id);F&&k.set(q.id,F)}return Zw(z,k,ye,t,n)},[z,r,X,G,ye,t,n,Se]);B.current=Ee;const Qe=(k,q)=>{var de;if(!I||q===void 0)return;const F=(de=Ee.get(k))==null?void 0:de.find(Ie=>Ie.property===q),K=Se(k);return F&&!F.anchor&&K?K.y-K.h/2+F.top+F.height/2:void 0},et=(k,q)=>{var de,Ie;if(q===void 0)return;const F=(Ie=(de=Ee.get(k))==null?void 0:de.find(we=>we.property===q))==null?void 0:Ie.anchor,K=Se(k);return F&&K?{x:K.x-K.w/2+F.x,y:K.y-K.h/2+F.y,side:F.side}:void 0},Ze=(k,q)=>{const F=Se(k),K=ye.get(k);return F&&K&&!G.has(k)&&Qe(k,q)===void 0?En(F,(n==="TB"||n==="BT")&&K.captionBottom!==void 0?{...K,height:Math.max(K.height,K.captionBottom-K.top),outline:void 0}:K):F},Et=()=>{const k=[];ue.current.forEach((q,F)=>{if(fe.current.has(F))return;const K=Se(F);K&&k.push(Jt(K))}),fe.current.forEach(q=>k.push(q));try{for(const q of[T.current,N.current]){const F=q==null?void 0:q.getBBox();F&&F.width>0&&F.height>0&&k.push({x1:F.x,y1:F.y,x2:F.x+F.width,y2:F.y+F.height})}}catch{}return Do(k)},At=()=>{var F,K;const{pan:k,zoom:q}=M;$.current&&($.current.style.transform=`translate3d(${k.x}px, ${k.y}px, 0) scale(${q})`),(F=T.current)==null||F.setAttribute("transform",`translate(${k.x} ${k.y}) scale(${q})`),(K=N.current)==null||K.setAttribute("transform",`translate(${k.x} ${k.y}) scale(${q})`)};j.useEffect(()=>{At();let k=null,q;const F=M.onChange(()=>{At();const K=P.current;K&&(K.classList.add("flow-sdk-busy"),clearTimeout(q),q=setTimeout(()=>K.classList.remove("flow-sdk-busy"),150)),k===null&&(k=requestAnimationFrame(()=>{var de,Ie;k=null,(Ie=(de=R.current).onViewportChange)==null||Ie.call(de,M.state)}))});return()=>{F(),clearTimeout(q),k!==null&&cancelAnimationFrame(k)}},[]),j.useLayoutEffect(()=>{const k=P.current;if(!k)return;const q=()=>{var we;if(!k.getClientRects().length)return;let K=k.clientWidth,de=k.clientHeight;de||(de=Math.max(0,window.innerHeight-k.getBoundingClientRect().top-100),de&&(k.style.height=`${de}px`)),K||(K=window.innerWidth,K&&(k.style.width=`${K}px`));const Ie=M.size.w!==K||M.size.h!==de;M.size={w:K,h:de},Ie&&((we=Ue.current)!=null&&we.options.fill)&&ne(),!ve.current&&!ue.current.size&&R.current.fitOnInit!==!1&&(M.set({x:K/2,y:de/2}),At())};if(q(),typeof ResizeObserver>"u")return;const F=new ResizeObserver(q);return F.observe(k),()=>F.disconnect()},[M]),j.useLayoutEffect(()=>{if(Kt.current){Kt.current=!1;const q=_t.current.flatMap(K=>{const de=Se(K);return de?[Jt(de)]:[]});_t.current=[];const F=Do(q);if(F){qe.current=!1,M.center(F,R.current.animateViewport);return}}if(!qe.current)return;qe.current=!1;const k=Et();k&&(M.fit(k,50,ve.current&&R.current.animateViewport),ve.current||At())},[X]);const mt=j.useMemo(()=>{const k=te=>{const ee=R.current;if(ee.nodeGridSpacing!=="layout")return te;const pe=ee.direction==="LR"||ee.direction==="RL";return{...te,gaps:{x:pe?ee.rankSep:ee.edgeSep,y:pe?ee.edgeSep:ee.rankSep}}},q=()=>{const te=R.current,ee=A.current.nodes.filter(pe=>er(pe.id,te.edges,te.edgeMode)&&(!lt.current||lt.current.has(pe.id)));return{nodes:ee,positions:ue.current,sizes:new Map(ee.map(pe=>[pe.id,W.current.get(pe.id)??Yn])),padding:pe=>R.current.containerStyle(pe).padding,minSize:oe,fixedIds:new Set(Y.current.keys()),viewportSize:{...M.size}}},F=te=>zu(te,R.current.nodes,R.current.edges),K=(te,ee=!0,pe=()=>{},ie,He,Ae=!1)=>{clearTimeout(Q.current),clearTimeout(je.current),Ae||(Be.current=null),Xe.current=null,qe.current=!1,_t.current=[],Kt.current=!1,M.cancelAnimation();const _e=ee&&!R.current.isPerformanceMode&&!R.current.disableAnimations,ot=M.coordinate(()=>{var Ve;ie?ie(_e):Ae&&((Ve=Be.current)==null||Ve.call(Be,te))});vr(new Map([...te].map(([Ve,gt])=>[Ve,{...gt}])),_e,ot,pe,He)},de=(te,ee=50,pe=R.current.animateViewport,ie=1,He=!1)=>{const Ae=_e=>{const ot=A.current,Ve=te??new Set(ot.nodes.map(kt=>kt.id)),gt=new Set(ot.nodes.map(kt=>kt.parent).filter(Boolean));if(!_e&&(!te||[...te].some(kt=>gt.has(kt))))return;const ir=_e&&md(ot.nodes,_e,W.current,kt=>R.current.containerStyle(kt).padding,oe),ar=Do([...Ve].flatMap(kt=>{const an=ir==null?void 0:ir.get(kt);if(an)return[an];const sn=_e==null?void 0:_e.get(kt),Hn=W.current.get(kt)||Yn,cn=sn?{...sn,...Hn}:Se(kt);return cn?[Jt(cn)]:[]}));ar&&(qe.current=!1,_t.current=[],Kt.current=!1,M.fit(ar,Number.isFinite(ee)?Math.max(0,ee):50,pe,ie))};Be.current=He?Ae:null,He||Ae(ue.current)},Ie=(te,ee,pe,ie)=>{var Ae;if(!Se(te))return;const He=ee==="connections"?ke(te):F(te);if(ee==="connections"&&or.current===1.25&&((Ae=lt.current)==null?void 0:Ae.size)===He.size&&[...He].every(_e=>lt.current.has(_e))){S({id:te,mode:ee});return}Ht.current||(Ht.current={pan:{...M.pan},zoom:M.zoom}),lt.current=He,R.current.compactPropertyLayout&&(qe.current=!1,Xe.current=()=>de(lt.current??He,pe,ie)),S({id:te,mode:ee}),R.current.compactPropertyLayout||de(He,pe,ie)},we=te=>{Xe.current?Xe.current=te:te()},ke=te=>Uu(te,R.current.nodes,R.current.edges),Te=(te=>{var ee,pe,ie;if(te===void 0)return M.zoom;te<M.zoom&&((ee=Ue.current)!=null&&ee.options.fill)&&!R.current.readOnly&&((ie=(pe=R.current).onNodeGridZoomOut)==null?void 0:ie.call(pe,Ue.current.options))===!0||(Be.current=null,M.set(void 0,te))}),Re=(te=>{if(te===void 0)return M.pan;Be.current=null,M.set(te)}),$e=(te,ee)=>{var ie;const pe=(ie=P.current)==null?void 0:ie.getBoundingClientRect();return{x:te-((pe==null?void 0:pe.left)??0),y:ee-((pe==null?void 0:pe.top)??0)}},Ye=(te=0,ee=R.current.animateViewport,pe=!1)=>{if(pe){de(void 0,te,ee,1,!0);return}Be.current=null,we(()=>{const ie=Et();ie&&M.fit(ie,te,ee)})};return{zoom:Te,pan:Re,setEdgesVisible:Ne,focusNode:(te,ee,pe,ie)=>we(()=>de(new Set([te]),ee,pe,.6,ie)),focusBranch:(te,ee,pe,ie)=>we(()=>de(F(te),ee,pe,1,ie)),focusConnections:(te,ee,pe,ie)=>we(()=>de(ke(te),ee,pe,1,ie)),isolateConnections:(te,ee,pe)=>Ie(te,"connections",ee,pe),isolateBranch:(te,ee,pe)=>Ie(te,"branch",ee,pe),restoreView:(te=R.current.animateViewport,ee)=>{Be.current=null;const pe=R.current.compactPropertyLayout&&!!lt.current;lt.current=null,S(null);const ie=ee??Ht.current;Ht.current=null,pe?Xe.current=()=>{ie&&M.transition(ie,te)}:ie&&we(()=>M.transition(ie,te))},zoomAt:(te,ee)=>{var pe,ie,He;te<M.zoom&&((pe=Ue.current)!=null&&pe.options.fill)&&!R.current.readOnly&&((He=(ie=R.current).onNodeGridZoomOut)==null?void 0:He.call(ie,Ue.current.options))===!0||(Be.current=null,M.zoomAt(te,ee))},fit:Ye,centerAndFit:Ye,center:(te=R.current.animateViewport)=>{Be.current=null;const ee=Et();ee&&M.center(ee,te)},clientToModel:(te,ee)=>M.renderedToModel($e(te,ee)),modelToClient:te=>{var ie;const ee=(ie=P.current)==null?void 0:ie.getBoundingClientRect(),pe=M.modelToRendered(te);return{x:pe.x+((ee==null?void 0:ee.left)??0),y:pe.y+((ee==null?void 0:ee.top)??0)}},getNodeBox:te=>Se(te),detectNodeCollisions:te=>{const ee=q();return Kv({...ee,sizes:new Map([...ee.sizes,...ge.current]),fixedSizes:ge.current},te)},resolveNodeCollisions:(te={})=>{const ee=Rj(q(),te);return ee.movedNodeIds.length&&K(ee.positions,te.animate),ee},arrangeNodesInGrid:(te={})=>{const ee=q(),pe=Ue.current;if(pe){ee.positions=new Map(ee.positions);for(const Ve of ee.nodes)ee.positions.has(Ve.id)||ee.positions.set(Ve.id,M.renderedToModel({x:M.size.w/2,y:M.size.h/2}));const Ae=new Set(ee.nodes.map(Ve=>Ve.id));pe.order=pe.order.filter(Ve=>Ae.has(Ve));const _e=new Set(pe.order);pe.order.push(...ee.nodes.filter(Ve=>!_e.has(Ve.id)).map(Ve=>Ve.id));const ot=new Map(pe.order.map((Ve,gt)=>[Ve,gt]));ee.nodes=[...ee.nodes].sort((Ve,gt)=>ot.get(Ve.id)-ot.get(gt.id))}const ie=ad(ee,k(te));Bt(ie.dividers??[]),pe&&(pe.ready=!1);const He=()=>{pe&&(pe.ready=!0),pe&&ee.nodes.length&&!ve.current&&(ve.current=!0,R.current.fitOnInit!==!1&&!te.fill?mt.centerAndFit(50,!1):R.current.fitOnInit===!1&&M.transition(p,!1)),be(Ae=>Ae+1)};return!ie.sizes&&ge.current.size&&he(),ee.nodes.some(Ae=>!ue.current.has(Ae.id))||ie.movedNodeIds.length||ie.bounds||Be.current?K(ie.positions,te.animate,He,ie.bounds&&(!pe||!ge.current.size)?()=>M.transition({zoom:1,pan:{x:0,y:0}},!1):void 0,ie.sizes,!!pe&&!ie.bounds):He(),ie},setNodeGridMode:(te,ee={})=>{var pe,ie,He,Ae;if(ee.order&&(!Array.isArray(ee.order)||ee.order.some(_e=>typeof _e!="string")||new Set(ee.order).size!==ee.order.length))throw new Error("Invalid grid node order.");if(te){ad(q(),k(ee));const _e=!Ue.current||Ue.current.options.fill&&!ee.fill;Be.current=null,Ue.current||(Ue.current={options:ee,order:q().nodes.map(ot=>ot.id),previousPositions:new Map([...ue.current].map(([ot,Ve])=>[ot,{...Ve}])),previousViewport:{zoom:M.zoom,pan:{...M.pan}},previousSize:{...M.size},ready:!1}),_e&&mt.centerAndFit(80,ee.animate,!0),ee.order&&(Ue.current.order=[...ee.order]),Ue.current.options={...ee},st(!0),mt.arrangeNodesInGrid(ee),(ie=(pe=R.current).onNodeGridModeChange)==null||ie.call(pe,{...ee,order:[...Ue.current.order]})}else{const _e=Ue.current;if(!_e)return;if(M.size.w===_e.previousSize.w&&M.size.h===_e.previousSize.h&&ue.current.size===_e.previousPositions.size&&[...ue.current.keys()].every(gt=>_e.previousPositions.has(gt))?Be.current=()=>M.transition(_e.previousViewport,ee.animate!==!1&&!R.current.disableAnimations&&!R.current.isPerformanceMode):mt.centerAndFit(80,ee.animate,!0),Ue.current=null,st(!1),he(),(Ae=(He=R.current).onNodeGridModeChange)==null||Ae.call(He,null),Ut(null),!_e.previousPositions.size){ne();return}const Ve=new Map([...ue.current].map(([gt,ir])=>[gt,_e.previousPositions.get(gt)??ir]));K(Ve,ee.animate,void 0,void 0,void 0,!0)}},swapGridNodes:(te,ee,pe)=>{var kt,an,sn,Hn,cn;const ie=Ue.current;if(!ie||!ie.ready||R.current.readOnly||te===ee)return!1;const He=q(),Ae=He.nodes.find(ln=>ln.id===te),_e=He.nodes.find(ln=>ln.id===ee);if(!Ae||!_e||Ae.parent!==_e.parent)return!1;const ot=ad(He,k(ie.options));if(ot.skippedNodeIds.includes(te)||ot.skippedNodeIds.includes(ee))return!1;const Ve=ie.order.indexOf(te),gt=ie.order.indexOf(ee);if(Ve<0||gt<0)return!1;[ie.order[Ve],ie.order[gt]]=[ie.order[gt],ie.order[Ve]],Be.current=null,ie.options={...ie.options,order:[...ie.order]};const ir=Ae.parent??"canvas",ar=(an=(kt=ie.options.adjustment)==null?void 0:kt.sections)==null?void 0:an[ir];return ar!=null&&ar.members&&(ie.options={...ie.options,adjustment:{...ie.options.adjustment,sections:{...(sn=ie.options.adjustment)==null?void 0:sn.sections,[ir]:{...ar,members:ar.members.map(ln=>ln.map(qo=>qo===te?ee:qo===ee?te:qo))}}}}),mt.arrangeNodesInGrid({...ie.options,animate:pe??ie.options.animate}),(cn=(Hn=R.current).onNodeGridModeChange)==null||cn.call(Hn,{...ie.options}),!0},setNodePosition:(te,ee,pe)=>{if(!ue.current.has(te)||ee&&(!Number.isFinite(ee.x)||!Number.isFinite(ee.y)))return!1;if(Qt(),!ee)return Y.current.delete(te),ne(),!0;const ie=new Map(ue.current);return ie.set(te,{...ee}),(pe==null?void 0:pe.persist)===!1?Y.current.delete(te):Y.current.set(te,{...ee}),ue.current=ie,le(ie),(pe==null?void 0:pe.persist)===!1&&ne(),!0},onViewportChange:te=>M.onChange(te)}},[]);j.useEffect(()=>{var k,q;return(q=(k=R.current).onInit)==null||q.call(k,mt),()=>M.cancelAnimation()},[mt]),j.useEffect(()=>{var k,q;if(J>0){const F=Xe.current;Xe.current=null,F==null||F(),(q=(k=R.current).onLayoutComplete)==null||q.call(k,mt)}},[mt,J]);const ht=j.useRef(null),Ct=j.useRef(new Map),Pt=j.useRef(!1),[Ot,Wn]=j.useState(null),[it,nn]=j.useState(null),Gn=k=>{const q=P.current.getBoundingClientRect();return{x:(k.clientX-q.left)*(P.current.clientWidth/q.width||1),y:(k.clientY-q.top)*(P.current.clientHeight/q.height||1)}},Un=(k,q)=>{const F=R.current.nodes;for(let K=F.length-1;K>=0;K--){const de=F[K].id;if(!er(de,R.current.edges,R.current.edgeMode)||lt.current&&!lt.current.has(de)||de===q||fe.current.has(de))continue;const Ie=Se(de);if(Ie&&Bu(k,Jt(Ie)))return de}for(const[K,de]of fe.current)if(er(K,R.current.edges,R.current.edgeMode)&&!(lt.current&&!lt.current.has(K))&&K!==q&&Bu(k,de))return K;return null},du=(k,q)=>{const F=R.current.nodes.find(ke=>ke.id===k),K=Se(k);if(!F||!K)return null;const de=Jt({...K,x:K.x+q.x,y:K.y+q.y});let Ie=null,we=0;for(const ke of R.current.nodes){if(ke.id===k||ke.parent!==F.parent||Y.current.has(ke.id)||fe.current.has(ke.id)||!er(ke.id,R.current.edges,R.current.edgeMode)||lt.current&&!lt.current.has(ke.id))continue;const Te=Se(ke.id);if(!Te)continue;const Re=Jt(Te),$e=Math.max(0,Math.min(de.x2,Re.x2)-Math.max(de.x1,Re.x1))*Math.max(0,Math.min(de.y2,Re.y2)-Math.max(de.y1,Re.y1));$e>we&&(we=$e,Ie=ke.id)}return Ie},uu=(k,q)=>{const F=Ue.current;if(!(F!=null&&F.ready)||R.current.readOnly)return;const K=R.current.nodes.filter($e=>er($e.id,R.current.edges,R.current.edgeMode)&&(!lt.current||lt.current.has($e.id))),de=K.find($e=>$e.id===k);if(!de)return;const Ie=P.current,we=M.zoom*(Ie&&Ie.clientWidth?Ie.getBoundingClientRect().width/Ie.clientWidth:1),ke=24/we;let Te;for(const $e of K){if($e.id===k||$e.parent!==de.parent)continue;const Ye=Se($e.id);if(!Ye)continue;const te=Jt(Ye),ee=Math.min(Ye.w/4,ke),pe=Math.min(Ye.h/4,ke),ie=3/we,He=[];if(q.y>te.y1+pe&&q.y<te.y2-pe)for(const Ae of["before","after"]){const _e=Ae==="before"?te.x1:te.x2,ot=Math.abs(q.x-_e),Ve=Ae==="before"?q.x<_e:q.x>_e;ot<=(Ve?ke:ee)&&He.push({side:Ae,distance:ot,marker:{x1:_e-ie/2,x2:_e+ie/2,y1:te.y1,y2:te.y2}})}if(q.x>=te.x1&&q.x<=te.x2)for(const Ae of["above","below"]){const _e=Ae==="above"?te.y1:te.y2,ot=Math.abs(q.y-_e),Ve=Ae==="above"?q.y<_e:q.y>_e;ot<=(Ve?ke:pe)&&He.push({side:Ae,distance:ot,marker:{x1:te.x1,x2:te.x2,y1:_e-ie/2,y2:_e+ie/2}})}for(const Ae of He)(!Te||Ae.distance<Te.distance)&&(Te={id:$e.id,...Ae})}if(!Te)return;const Re=Ej({nodes:K,positions:ue.current,sizes:new Map([...W.current,...ge.current]),fixedSizes:ge.current,padding:$e=>R.current.containerStyle($e).padding,minSize:oe,fixedIds:new Set(Y.current.keys())},F.options,k,Te.id,Te.side);return Re?{options:Re,marker:Te.marker}:void 0},To=(k,q)=>{if(R.current.edgeMode==="nodes"||R.current.edgeMode==="workflow")return null;const F=R.current.direction==="RL",K=Math.max(16,6/M.zoom);let de=null;for(const Ie of[...R.current.nodes].reverse()){if(!er(Ie.id,R.current.edges,R.current.edgeMode)||lt.current&&!lt.current.has(Ie.id))continue;const we=Se(Ie.id),ke=B.current.get(Ie.id);if(!we||!ke||fe.current.has(Ie.id))continue;const Te=we.x+(q==="source"!==F?1:-1)*we.w/2;for(const Re of ke){if(Re.role&&Re.role!==q)continue;const $e=we.y-we.h/2+Re.top,Ye=Math.hypot(k.x-(Re.anchor?we.x-we.w/2+Re.anchor.x:Te),k.y-$e-Re.height/2);if(!Re.anchor&&k.x>=we.x-we.w/2&&k.x<=we.x+we.w/2&&k.y>=$e&&k.y<=$e+Re.height)return{nodeId:Ie.id,property:Re.property};Ye<=K&&(!de||Ye<de.distance)&&(de={nodeId:Ie.id,property:Re.property,distance:Ye})}}return de},ox=k=>{var ke,Te;if(!k.currentTarget.contains(k.target)||(ht.current||(Pt.current=!1),k.target.closest(".flow-sdk-canvas")!==k.currentTarget)||k.button!==0||R.current.readOnly)return;const q=k.target;if(q.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const F=R.current,K=Gn(k);if(k.pointerType==="touch"){Ct.current.set(k.pointerId,K);const Re=xm(Ct.current);if(Re){Ut(null),ht.current={kind:"pinch",distance:Re.distance,zoom:M.zoom,anchor:M.renderedToModel(Re.center)},nn(null),Wn(null),Pt.current=!0;for(const $e of Ct.current.keys())k.currentTarget.setPointerCapture($e);return}}if(ht.current)return;const de=!Ue.current||!!F.nodeGridConnections,Ie=F.drawHandles&&q.closest(".flow-sdk-handle"),we=F.drawHandles&&q.closest(".flow-sdk-property-port");if((!de||!Ie&&!we&&(!F.drawMode||k.shiftKey))&&(Ue.current||k.shiftKey&&(F.onNodeGridDrop||F.onNodeParentChange))){if(Ue.current&&!Ue.current.ready||q.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]"))return;const Re=(ke=q.closest("[data-node-id]"))==null?void 0:ke.dataset.nodeId;if(Re&&!Y.current.has(Re)){q.setPointerCapture(k.pointerId),ht.current={kind:"grid",pointerId:k.pointerId,captureTarget:q,source:Re,start:K,moved:!1};return}if(Re)return}if(de&&(F.drawMode||Ie||we)){const Re=M.renderedToModel(K),$e=F.drawMode?To(Re,"source"):null,Ye=we||Ie,te=Ye?(Te=Ye.closest("[data-node-id]"))==null?void 0:Te.dataset.nodeId:($e==null?void 0:$e.nodeId)??Un(Re),ee=we?we.dataset.property:$e==null?void 0:$e.property;if(te){ht.current={kind:"draw",pointerId:k.pointerId,source:te,sourceProperty:ee,reverse:(we==null?void 0:we.dataset.portRole)==="target",startClient:{x:k.clientX,y:k.clientY}},Pt.current=!0,nn({source:te,sourceProperty:ee,point:Re,target:null}),k.currentTarget.setPointerCapture(k.pointerId);return}}q.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(Be.current=null,F.multiSelect?ht.current={kind:"box",pointerId:k.pointerId,start:K,current:K}:F.dragMode?ht.current={kind:"pan",pointerId:k.pointerId,start:K,pan0:M.pan,moved:!1}:ht.current={kind:"tap",pointerId:k.pointerId,start:K,moved:!1},k.currentTarget.setPointerCapture(k.pointerId))},ix=k=>{var K,de,Ie;const q=ht.current;if(!q||R.current.readOnly)return;const F=Gn(k);if(Ct.current.has(k.pointerId)&&Ct.current.set(k.pointerId,F),q.kind==="pinch"){const we=xm(Ct.current);if(!we)return;const ke=Math.max(M.minZoom,Math.min(M.maxZoom,q.zoom*we.distance/q.distance));if(ke<M.zoom&&((K=Ue.current)!=null&&K.options.fill)&&((Ie=(de=R.current).onNodeGridZoomOut)==null?void 0:Ie.call(de,Ue.current.options))===!0)return;M.set({x:we.center.x-q.anchor.x*ke,y:we.center.y-q.anchor.y*ke},ke);return}if(q.pointerId===k.pointerId)switch(q.kind){case"grid":{const we={x:F.x-q.start.x,y:F.y-q.start.y};if(!q.moved&&Math.hypot(we.x,we.y)<=cd)return;q.moved||(Qt(),Be.current=null,M.cancelAnimation()),q.moved=!0,Pt.current=!0,k.preventDefault();const ke={x:we.x/M.zoom,y:we.y/M.zoom},Te=!k.shiftKey&&F.x>=0&&F.y>=0&&F.x<=M.size.w&&F.y<=M.size.h?uu(q.source,M.renderedToModel(F)):void 0;Ut({source:q.source,offset:ke,target:k.shiftKey||Te?null:du(q.source,ke),shiftKey:k.shiftKey,insertion:Te});break}case"pan":{const we=F.x-q.start.x,ke=F.y-q.start.y;if(!q.moved&&Math.hypot(we,ke)<=cd)return;q.moved=!0,Pt.current=!0,M.set({x:q.pan0.x+we,y:q.pan0.y+ke});break}case"tap":{Math.hypot(F.x-q.start.x,F.y-q.start.y)>cd&&(q.moved=!0);break}case"box":{Pt.current=!0,q.current=F,Wn({x1:Math.min(q.start.x,F.x),y1:Math.min(q.start.y,F.y),x2:Math.max(q.start.x,F.x),y2:Math.max(q.start.y,F.y)});break}case"draw":{const we=M.renderedToModel(F),ke=To(we,q.reverse?"source":"target");nn(q.reverse&&ke?{source:ke.nodeId,sourceProperty:ke.property,point:we,target:q.source,targetProperty:q.sourceProperty}:{source:q.source,sourceProperty:q.sourceProperty,point:we,target:(ke==null?void 0:ke.nodeId)??Un(we,q.source),targetProperty:ke==null?void 0:ke.property});break}}},fu=(k,q)=>{var de,Ie,we,ke,Te,Re,$e,Ye,te,ee,pe;Ct.current.delete(k.pointerId);const F=ht.current;if(!F)return;if(F.kind==="pinch"){const ie=[...Ct.current][0];ht.current=ie&&R.current.dragMode&&!q?{kind:"pan",pointerId:ie[0],start:ie[1],pan0:M.pan,moved:!0}:null;return}if(F.pointerId!==k.pointerId)return;ht.current=null;try{(F.kind==="grid"?F.captureTarget:k.currentTarget).releasePointerCapture(k.pointerId)}catch{}const K=R.current;switch(q=q||!!K.readOnly,F.kind){case"grid":{if(Ut(null),q||!F.moved)break;const ie=Gn(k);if(!k.shiftKey&&ie.x>=0&&ie.y>=0&&ie.x<=M.size.w&&ie.y<=M.size.h){const Ae=uu(F.source,M.renderedToModel(ie));if(Ae){mt.setNodeGridMode(!0,{...Ae.options,animate:!1});break}}if(((de=K.onNodeGridDrop)==null?void 0:de.call(K,F.source,{x:k.clientX,y:k.clientY},{shiftKey:k.shiftKey,ctrlKey:k.ctrlKey,metaKey:k.metaKey,altKey:k.altKey}))===!0||ie.x<0||ie.y<0||ie.x>M.size.w||ie.y>M.size.h)break;if(k.shiftKey){const Ae=new Map(K.nodes.map(Ve=>[Ve.id,Ve]));let _e=Un(M.renderedToModel(ie),F.source);const ot=new Set;for(;_e&&!((Ie=Ae.get(_e))!=null&&Ie.acceptsChildren)&&!ot.has(_e);)ot.add(_e),_e=((we=Ae.get(_e))==null?void 0:we.parent)??null;if(_e&&((ke=Ae.get(_e))!=null&&ke.acceptsChildren)){let Ve=_e;const gt=new Set;for(;Ve&&!gt.has(Ve);)gt.add(Ve),Ve=(Te=Ae.get(Ve))==null?void 0:Te.parent;gt.has(F.source)||(Re=K.onNodeParentChange)==null||Re.call(K,F.source,_e)}break}if(!Ue.current)break;const He=du(F.source,{x:(ie.x-F.start.x)/M.zoom,y:(ie.y-F.start.y)/M.zoom});He&&mt.swapGridNodes(F.source,He,!1);break}case"pan":case"tap":!q&&!F.moved&&(($e=K.onBackgroundTap)==null||$e.call(K));break;case"box":{if(Wn(null),q)break;const ie=M.renderedToModel(F.start),He=M.renderedToModel(F.current),Ae={x1:Math.min(ie.x,He.x),y1:Math.min(ie.y,He.y),x2:Math.max(ie.x,He.x),y2:Math.max(ie.y,He.y)};if(Ae.x2-Ae.x1<1&&Ae.y2-Ae.y1<1){(Ye=K.onBackgroundTap)==null||Ye.call(K);break}const _e=[];for(const ot of K.nodes){const Ve=Se(ot.id);Ve&&Dw(Jt(Ve),Ae)&&_e.push(ot.id)}_e.length&&((te=K.onBoxSelect)==null||te.call(K,_e));break}case"draw":{if(nn(null),q)break;const ie=Gn(k),He=M.renderedToModel(ie),Ae=To(He,F.reverse?"source":"target"),_e=(Ae==null?void 0:Ae.nodeId)??Un(He);if(_e===F.source&&(F.sourceProperty===void 0||(Ae==null?void 0:Ae.property)===void 0||Ae.property===F.sourceProperty))break;_e?(ee=K.onEdgeDraw)==null||ee.call(K,F.reverse?_e:F.source,F.reverse?F.source:_e,F.sourceProperty!==void 0||(Ae==null?void 0:Ae.property)!==void 0?{sourceProperty:F.reverse?Ae==null?void 0:Ae.property:F.sourceProperty,targetProperty:F.reverse?F.sourceProperty:Ae==null?void 0:Ae.property}:void 0):Math.max(Math.abs(k.clientX-F.startClient.x),Math.abs(k.clientY-F.startClient.y))>$j&&((pe=K.onDrawIntoSpace)==null||pe.call(K,F.source,He,F.sourceProperty,F.reverse));break}}},xr=j.useCallback(()=>{var F;const k=ht.current,q=[...Ct.current.keys()];k&&k.kind!=="pinch"&&q.push(k.pointerId),ht.current=null,Ct.current.clear(),Ut(null),nn(null),Wn(null);for(const K of q)(k==null?void 0:k.kind)==="grid"&&k.captureTarget.hasPointerCapture(K)&&k.captureTarget.releasePointerCapture(K),(F=P.current)!=null&&F.hasPointerCapture(K)&&P.current.releasePointerCapture(K)},[]);j.useEffect(()=>{const k=q=>{q.key==="Escape"&&xr()};return window.addEventListener("keydown",k),window.addEventListener("blur",xr),()=>{window.removeEventListener("keydown",k),window.removeEventListener("blur",xr),ht.current=null,Ct.current.clear()}},[xr]),j.useEffect(()=>{xr()},[g,v,b,i,n,e.drawHandles,e.readOnly,Ge,xr]);const ax=j.useMemo(()=>{const k=new Map,q=new Map;for(const F of E){if(F.source!==F.target)continue;const K=k.get(F.source)??0;k.set(F.source,K+1),q.set(F.id,K)}return q},[E]),Oo=Nj[n],[wr,sx]=j.useState(null),No=Tj(r,E,!!((mu=e.edgeReveal)!=null&&mu.revealNodes));j.useLayoutEffect(()=>{P.current&&wr&&vm(P.current,wr)}),j.useEffect(()=>{const k=P.current;if(!k||!wr)return;const q=k.ownerDocument.fonts,F=()=>vm(k,wr);return q==null||q.addEventListener("loadingdone",F),()=>q==null?void 0:q.removeEventListener("loadingdone",F)},[wr]);const $o=zw(E,Ze,Oo),cx=e.onEdgeSelect,lx=e.onContainerSelect,hu=it?it.target&&Ze(it.target,it.targetProperty)||{x:it.point.x,y:it.point.y,w:1,h:1}:null,pu=it?Ze(it.source,it.sourceProperty):null,on=!Ge||!!e.nodeGridConnections,dx=["flow-sdk-canvas",g&&on?"flow-sdk-draw":"",x?"flow-sdk-perf":""].filter(Boolean).join(" ");return f.jsxs("div",{ref:P,className:dx,"data-edge-mode":i,"data-node-grid":Ge||void 0,"data-grid-connections":e.nodeGridConnections||void 0,onPointerDownCapture:ox,onPointerMove:ix,onPointerUp:k=>fu(k,!1),onPointerCancel:k=>fu(k,!0),onLostPointerCapture:k=>{const q=ht.current;q&&(q.kind==="pinch"||q.pointerId===k.pointerId)&&xr()},onClickCapture:k=>{if(!k.currentTarget.contains(k.target))return;const q=k.target instanceof Element&&k.target.closest("button[data-flow-fullscreen]");(Pt.current||e.readOnly&&!q)&&(k.preventDefault(),k.stopPropagation())},children:[f.jsx("svg",{className:"flow-sdk-svg",children:f.jsxs("g",{ref:T,children:[f.jsx("g",{className:"flow-sdk-containers",children:[...G].filter(([k])=>er(k,t,i)).filter(([k])=>!_||_.has(k)).map(([k,q])=>{var F,K;return f.jsx(Qw,{id:k,rect:q,label:Le.get(k),labelLayer:wr,labelContent:(F=r.find(de=>de.id===k&&de.label!==void 0))==null?void 0:F.element,style:m(k),onSelect:lx,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(K=e.selectedNodeIds)==null?void 0:K.includes(k)},k)})}),f.jsx("g",{className:"flow-sdk-edges",children:pt&&on&&E.map(k=>{var K,de,Ie;if(!No.ready.has(k.id)||_&&(!_.has(k.source)||!_.has(k.target)))return null;const q=Ze(k.source,k.sourceProperty),F=Ze(k.target,k.targetProperty);return!q||!F?null:f.jsx(Ku,{id:k.id,edgeData:k.data,validationIssue:k.validationIssue,edgeType:k.type,edgeRadius:e.edgeRadius,propertyMode:I,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:No.complete,source:q,target:F,sourceProperty:k.sourceProperty,targetProperty:k.targetProperty,sourceY:Qe(k.source,k.sourceProperty),targetY:Qe(k.target,k.targetProperty),sourcePort:et(k.source,k.sourceProperty),targetPort:et(k.target,k.targetProperty),dir:Oo,turn:((K=$o.get(k.id))==null?void 0:K.turn)??k.turn,labelAtTarget:(de=$o.get(k.id))==null?void 0:de.labelAtTarget,labelFraction:(Ie=$o.get(k.id))==null?void 0:Ie.labelFraction,color:k.color,connectorColor:k.connectorColor,labelBg:k.labelBg,label:k.label,labelLayer:wr,dashed:k.dashed,animated:k.animated&&!x,inverted:k.inverted,loopIndex:ax.get(k.id)??0,onSelect:cx},k.id)})}),pt&&on&&it&&yd(it,i)&&pu&&hu&&f.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:f.jsx(Ku,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:it.source,target:it.target??"",sourceProperty:it.sourceProperty,targetProperty:it.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:I,customEdgeTypes:e.customEdgeTypes,source:pu,target:hu,sourceProperty:it.sourceProperty,targetProperty:it.targetProperty,sourceY:Qe(it.source,it.sourceProperty),sourcePort:et(it.source,it.sourceProperty),targetPort:it.target?et(it.target,it.targetProperty):void 0,targetY:it.target?Qe(it.target,it.targetProperty):void 0,dir:Oo,turn:.5,color:y,labelBg:y})})]})}),f.jsxs("div",{ref:$,className:"flow-sdk-nodes",children:[(We==null?void 0:We.insertion)&&f.jsx("div",{className:"flow-sdk-box","data-grid-insertion":"",style:{left:We.insertion.marker.x1,top:We.insertion.marker.y1,width:We.insertion.marker.x2-We.insertion.marker.x1,height:We.insertion.marker.y2-We.insertion.marker.y1,background:y,border:0}}),Ge&&((bu=Ue.current)==null?void 0:bu.options.fill)&&((vu=Ue.current.options.adjustment)==null?void 0:vu.enabled)&&!e.readOnly&&f.jsx(Aj,{dividers:ct,options:Ue.current.options,zoom:M.zoom,onChange:k=>mt.setNodeGridMode(!0,{...k,animate:!1})}),r.map(k=>{var He,Ae;const q=X.get(k.id),F=G.get(k.id);if(F&&k.label!==void 0)return null;const K=(q==null?void 0:q.x)??(F?(F.x1+F.x2)/2:0),de=(q==null?void 0:q.y)??(F?(F.y1+F.y2)/2:0),Ie=We!=null&&We.target?k.id===We.source?We.target:k.id===We.target?We.source:void 0:void 0,we=Ie?X.get(Ie):void 0,ke=We?X.get(We.source):void 0,Te=We!=null&&We.target?X.get(We.target):void 0,Re=ke&&Te?{x:Te.x-ke.x,y:Te.y-ke.y}:void 0,$e=Re?Re.x**2+Re.y**2:0,Ye=$e&&We&&Re?Math.max(0,Math.min(1,(We.offset.x*Re.x+We.offset.y*Re.y)/$e)):0,te=we?{x:K+(we.x-K)*Ye,y:de+(we.y-de)*Ye}:(We==null?void 0:We.source)===k.id?{x:K+We.offset.x,y:de+We.offset.y}:void 0,ee=xe.get(k.id),pe=Ie?xe.get(Ie):void 0,ie=ee&&pe?{w:ee.w+(pe.w-ee.w)*Ye,h:ee.h+(pe.h-ee.h)*Ye}:ee;return f.jsx(Ij,{id:k.id,x:K,y:de,gridDraggable:Ge&&!e.readOnly&&!Y.current.has(k.id),gridDragging:(We==null?void 0:We.source)===k.id,gridDropTarget:(We==null?void 0:We.target)===k.id,gridSize:xe.get(k.id),gridPreview:te?{...te,size:ie,floating:We==null?void 0:We.shiftKey}:void 0,placed:!!q||!!F,hidden:!Ge&&!No.shown.has(k.id)||!er(k.id,t,i)||!!_&&!_.has(k.id),onMount:D,drawHandles:e.drawHandles&&!e.readOnly&&on,drawMode:g&&on,connectedPorts:new Set(E.flatMap(_e=>[..._e.source===k.id&&_e.sourceProperty!==void 0?[`source:${_e.sourceProperty}`]:[],..._e.target===k.id&&_e.targetProperty!==void 0?[`target:${_e.targetProperty}`]:[]])),hasCollapseControl:k.hasCollapseControl,handleColor:y,animated:k.animated&&!F&&!x&&!Ge,animationColor:k.animationColor,animationWidth:k.animationWidth,animationVariant:k.animationVariant,width:(He=W.current.get(k.id))==null?void 0:He.w,height:(Ae=W.current.get(k.id))==null?void 0:Ae.h,propertyMode:I,resolvedRows:Ee.get(k.id),reversePorts:n==="RL",direction:n,onPropertyRows:ce,onSurface:L,children:ee?k.fillElement??k.element:k.element},k.id)})]}),Ot&&f.jsx("div",{className:"flow-sdk-box",style:{left:Ot.x1,top:Ot.y1,width:Ot.x2-Ot.x1,height:Ot.y2-Ot.y1}}),f.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:f.jsx("g",{ref:N,transform:`translate(${M.pan.x} ${M.pan.y}) scale(${M.zoom})`,children:f.jsx("g",{ref:sx,className:"flow-sdk-labels",style:{pointerEvents:g?"none":"visiblePainted",outline:"none"}})})})]})}const zj=j.memo(Fj);function iu(e=!0){const r=j.useRef(null);return j.useEffect(()=>{if(!e||!r.current)return;const t=i=>{i.stopPropagation()},n=r.current,o=["mousedown","mouseup","click","dblclick","pointerdown","pointerup","wheel"];return o.forEach(i=>n.addEventListener(i,t)),()=>{o.forEach(i=>n.removeEventListener(i,t))}},[e]),r}const Kr=({nodeId:e,label:r,color:t,fontWeight:n="bold",fontSize:o="5xl",wrap:i=!1,isEditing:s,onEditStart:a,onEditEnd:c})=>{const{callbacks:l,config:d,readOnly:u}=Je(),h=d.editable&&!u,[p,m]=j.useState(r),[y,g]=j.useState(),v=j.useRef(null),b=j.useRef(!1),x=iu(s);j.useEffect(()=>{if(s&&(b.current=!1,v.current)){v.current.focus();const C=v.current.value.length;v.current.setSelectionRange(C,C)}},[s]);const w=()=>{var S;if(b.current)return;b.current=!0;const C=p.trim();C&&C!==r&&((S=l.onNodeLabelChange)==null||S.call(l,e,C)),c()};return!h||!s?f.jsx(V.Text,{color:t,fontWeight:n,fontSize:o,minW:0,maxW:"100%",whiteSpace:i?"normal":"nowrap",overflowWrap:i?"anywhere":void 0,overflow:"hidden",textOverflow:"ellipsis",title:r,onDoubleClick:h?C=>{C.stopPropagation(),g({width:C.currentTarget.offsetWidth,height:C.currentTarget.offsetHeight}),m(r),a()}:void 0,cursor:h?"text":void 0,children:r}):f.jsxs("div",{ref:x,style:{position:"relative",width:"max-content",minWidth:y==null?void 0:y.width,maxWidth:900,height:y==null?void 0:y.height},children:[f.jsx(V.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:o,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),f.jsx(V.Input,{ref:v,value:p,onChange:C=>m(C.target.value),onBlur:w,onKeyDown:C=>{C.key==="Enter"&&w(),C.key==="Escape"&&(b.current=!0,c())},color:t,fontWeight:n,fontSize:o,bg:"transparent",borderWidth:0,_focus:{outline:"none",boxShadow:"none"},_focusVisible:{outline:"none",boxShadow:"none"},p:0,display:"block",position:"absolute",top:0,left:0,w:"100%",h:"100%",minW:0,minH:0,lineHeight:"normal"})]})};function Zv({id:e,label:r,role:t,side:n,position:o=.5,placement:i,children:s,style:a}){return f.jsx("div",{"data-flow-property":e,"data-flow-port-role":t,"data-flow-port-side":n,"data-flow-port-position":n?o:void 0,"data-flow-port-placement":i,style:{minHeight:32,display:"flex",alignItems:"center",justifyContent:t==="source"?"flex-end":"flex-start",...a,...n?{display:"none"}:{}},children:s??r??e})}const Bj=ao.default.dialog`
|
|
211
|
+
${e=>hr(e.$surface,e.$border)}
|
|
212
212
|
&,
|
|
213
213
|
&:hover {
|
|
214
214
|
box-shadow: none !important;
|
|
@@ -232,7 +232,7 @@
|
|
|
232
232
|
& *::-webkit-scrollbar {
|
|
233
233
|
display: none;
|
|
234
234
|
}
|
|
235
|
-
`,
|
|
235
|
+
`,Dj=ao.default.div`
|
|
236
236
|
min-height: 0;
|
|
237
237
|
container-type: inline-size;
|
|
238
238
|
@container (min-width: 520px) {
|
|
@@ -277,8 +277,8 @@
|
|
|
277
277
|
black calc(100% - 32px),
|
|
278
278
|
transparent
|
|
279
279
|
);
|
|
280
|
-
`;function iu({nodeAddress:e,active:r,label:t,open:n=!1,onClose:o,children:i,filter:s,height:a,width:c}){const{background:l,border:d,colorText:u}=at(),{colorMode:h}=Ze(),p=_.useRef(null),m=_.useId(),{data:y,schema:g,bindings:v}=_.useContext(Mt),b=i!==void 0||!!(y&&g&&(v?On(v,e,g):Zr(y,e,g)));_.useEffect(()=>{var w,C,S,j,P;!r||!b||!n?(w=p.current)==null||w.close():(C=p.current)!=null&&C.open||((S=p.current)==null||S.showModal(),(P=(j=p.current)==null?void 0:j.querySelector("[data-form-filter] input"))==null||P.focus())},[r,b,n]);const x=Ae(l);return b?f.jsx(f.Fragment,{children:typeof document<"u"&&Dr.createPortal(f.jsx(Lj,{ref:p,id:m,$surface:x,$border:Ae(d),"aria-label":`Configure ${t}`,onClose:o,onPointerDown:w=>w.stopPropagation(),onWheel:w=>w.stopPropagation(),onKeyDown:w=>w.stopPropagation(),onClick:w=>{var C;w.stopPropagation(),w.target===w.currentTarget&&((C=p.current)==null||C.close())},style:{position:"fixed",inset:"94px 20px auto auto",margin:0,padding:20,width:c??"var(--top-toolbar-width, 360px)",boxSizing:"border-box",maxWidth:"calc(100vw - 40px)",maxHeight:"calc(100dvh - 114px)",height:a,overflow:"hidden",borderRadius:30,background:x,color:Ae(u),fontSize:16,textTransform:"none"},children:n&&f.jsxs(f.Fragment,{children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexShrink:0},children:[f.jsx("strong",{style:{overflowWrap:"anywhere",minWidth:0},children:t}),f.jsx(Jr,{"aria-label":"Close node configuration",onClick:()=>{var w;return(w=p.current)==null?void 0:w.close()}})]}),s&&f.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:s}),f.jsx(Fj,{$divider:`var(--chakra-colors-gray-${h==="dark"?"700":"200"})`,"data-form-scroll":"",style:a?{flex:1}:void 0,children:i??f.jsx(Md,{nodeAddress:e})})]})}),document.body)}):null}const md=({icon:e,label:r,onClick:t,color:n,boxSize:o=6,...i})=>{const{background:s,border:a,colorText:c}=at();return f.jsx(Ue,{label:r,children:f.jsx(V.Flex,{asChild:!0,p:0,border:0,bg:"transparent",children:f.jsx("button",{type:"button","aria-label":r,onClick:t,children:f.jsx(V.Icon,{as:e,boxSize:o,color:n,cursor:t?"pointer":void 0})})})})},zj=({data:e,children:r,isInverted:t,isParent:n,onOpenView:o,editOnMount:i=!1,hoverLeaveDelay:s=0})=>{var ue,xe,Ce,ye,pe,X;const{selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isMultiSelectMode:u,nodeGridOptions:h,isPerformanceMode:p,engineRef:m,callbacks:y,config:g,themeColor:v,direction:b,nodeViewModes:x}=Ze(),{background:w,border:C,colorText:S}=at(),j=_.useRef(null),P=_.useRef(null);_.useEffect(()=>()=>{P.current&&clearTimeout(P.current)},[]);const[E,O]=_.useState(!1),[A,R]=_.useState(i&&!!g.editable&&!g.readOnly),[M,T]=_.useState(!1),N=e==null?void 0:e.id,$=fb(N),I=a.includes(N),K=g.nodeOverlayActions,ie=g.renderNodeOverlay,se=(e==null?void 0:e.type)==="grid"?"20px":"-100px",te=(e==null?void 0:e.type)==="grid"?"top center":void 0,me=(()=>{var L;try{const ae=(L=m.current)==null?void 0:L.zoom();return ae!==void 0&&ae<.08}catch{return!1}})(),ve=_.useCallback(L=>{var H,fe,be,Ne;if(A||g.readOnly)return;const ae={shiftKey:L.shiftKey,ctrlKey:L.ctrlKey,metaKey:L.metaKey,altKey:L.altKey};if(l&&(d(null),(H=y.onEdgeDeselect)==null||H.call(y)),u||L.shiftKey&&(h!=null&&h.fill)){const Le=a.includes(N),Be=Le?a.filter(tt=>tt!==N):[...a,N];c(Be),Le?(fe=y.onNodeDeselect)==null||fe.call(y):(be=y.onNodeSelect)==null||be.call(y,N,e,ae)}else c([N]),(Ne=y.onNodeSelect)==null||Ne.call(y,N,e,ae)},[N,e,a,l,u,h,A,c,d,y,g]),F=_.useCallback(()=>{var L;A||g.readOnly||(L=y.onNodeDoubleClick)==null||L.call(y,N,e)},[N,e,A,y,g]),D=_.useCallback(()=>{P.current&&clearTimeout(P.current),P.current=setTimeout(()=>O(!0),100)},[]),W=_.useCallback(L=>{var ae;L.relatedTarget instanceof Node&&((ae=j.current)!=null&&ae.contains(L.relatedTarget))||(P.current&&clearTimeout(P.current),s?P.current=setTimeout(()=>O(!1),s):O(!1))},[s]),B=!!((ue=e==null?void 0:e.config)!=null&&ue.form),le={tabIndex:B?0:void 0,"aria-haspopup":B?"dialog":void 0,"aria-expanded":B?M:void 0,onDoubleClickCapture:L=>{var ae;!B&&!o||g.readOnly||A||!L.currentTarget.contains(L.target)||L.target instanceof Element&&L.target.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]")||(L.preventDefault(),L.stopPropagation(),c([N]),o?o():T(!0),(ae=y.onNodeDoubleClick)==null||ae.call(y,N,e))},onKeyDown:L=>{!B&&!o||g.readOnly||L.target!==L.currentTarget||L.key!=="Enter"||(L.preventDefault(),L.stopPropagation(),c([N]),o?o():T(!0))}},Y=B&&f.jsx(iu,{nodeAddress:N,active:I,label:e.label||e.headerTitle||"Node",open:M,onClose:()=>{var L;T(!1),I&&((L=j.current)==null||L.focus({preventScroll:!0}))}}),ce=Array.isArray((xe=e==null?void 0:e.config)==null?void 0:xe.ports)?e.config.ports.map(L=>f.jsx(Uv,{...L},`${L.id}:${L.role}`)):null;return n?f.jsxs(V.Box,{ref:j,...le,onClick:ve,onDoubleClick:F,onMouseEnter:D,onMouseLeave:W,cursor:"pointer",position:"relative",children:[Y,!p&&(ie||K&&K.length>0)&&E&&!me&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>O(!0),onMouseLeave:W}),ie?f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:se,transformOrigin:te,left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>O(!0),onMouseLeave:W,willChange:"transform",children:ie({nodeId:N,nodeData:e,isRoot:N==="root",isParent:!0,isHovered:E,setIsHovered:O})}):f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:se,transformOrigin:te,left:"50%",bg:w,p:3,borderColor:C,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>O(!0),onMouseLeave:W,willChange:"transform",children:f.jsx(V.HStack,{px:2,gap:2,children:K.map((L,ae)=>f.jsxs(V.Box,{display:"contents",children:[ae>0&&f.jsx(V.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(md,{icon:L.icon,label:L.label,color:S,bgColor:w,borderColor:C,textColor:S,boxSize:5,onClick:H=>{var fe;H.stopPropagation(),(fe=y.onNodeHoverAction)==null||fe.call(y,L.id,N,e)}})]},L.id))})})]}),r({id:N,data:e,isActive:I,isHovered:E,isLowZoom:me,isEditing:A,onSelect:ve,onEditStart:()=>R(!0),onEditEnd:()=>R(!1)}),$&&!((Ce=e==null?void 0:e.config)!=null&&Ce.parentContainer)&&((ye=e==null?void 0:e.config)==null?void 0:ye.collapsed)!==void 0&&(()=>{var H;const L=b==="TB"||b==="BT",ae=t||b==="RL";return f.jsx(V.IconButton,{position:"absolute",...L?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:ae?void 0:"-75px",left:ae?"-75px":void 0,top:"50%",transform:"translateY(-50%)"},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:g.readOnly,onClick:fe=>{var be;fe.stopPropagation(),(be=y.onNodeCollapse)==null||be.call(y,N,!e.config.collapsed)},bgColor:Ae(((H=e==null?void 0:e.viewProps)==null?void 0:H.bgColor)||v),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Z.PiPlusBold,{size:30,color:Ae("gray.800")}):f.jsx(Z.PiMinusBold,{size:30,color:Ae("gray.800")})})})()]}):f.jsxs(V.Box,{ref:j,...le,onClick:ve,onDoubleClick:F,onMouseEnter:D,onMouseLeave:W,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[Y,ce,!p&&(ie||K&&K.length>0)&&E&&!me&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>O(!0),onMouseLeave:W}),ie?f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:se,transformOrigin:te,left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>O(!0),onMouseLeave:W,willChange:"transform",children:ie({nodeId:N,nodeData:e,isRoot:N==="root",isParent:!!n,isHovered:E,setIsHovered:O})}):f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:se,transformOrigin:te,left:"50%",bg:w,p:3,borderColor:C,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>O(!0),onMouseLeave:W,willChange:"transform",children:f.jsx(V.HStack,{px:2,gap:2,children:K.map((L,ae)=>f.jsxs(V.Box,{display:"contents",children:[ae>0&&f.jsx(V.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(md,{icon:L.icon,label:L.label,color:S,bgColor:w,borderColor:C,textColor:S,boxSize:5,onClick:H=>{var fe;H.stopPropagation(),(fe=y.onNodeHoverAction)==null||fe.call(y,L.id,N,e)}})]},L.id))})})]}),f.jsxs(V.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[$&&!((pe=e==null?void 0:e.config)!=null&&pe.parentContainer)&&((X=e==null?void 0:e.config)==null?void 0:X.collapsed)!==void 0&&!n&&(()=>{var fe,be,Ne;const L=b==="TB"||b==="BT",ae=t||b==="RL",H=(fe=e==null?void 0:e.config)!=null&&fe.labelBelow&&x[N]!=="properties"?((((be=e==null?void 0:e.viewProps)==null?void 0:be.fontSize)||1)*100+100)/2:void 0;return f.jsx(V.IconButton,{position:"absolute",...L?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:ae?void 0:H===void 0?"-75px":`calc(50% - ${H+75}px)`,left:ae?H===void 0?"-75px":`calc(50% - ${H+75}px)`:void 0,alignSelf:H===void 0?"center":void 0,top:H===void 0?void 0:`${H}px`,transform:H===void 0?void 0:"translateY(-50%)",zIndex:H===void 0?void 0:1},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:g.readOnly,onClick:Le=>{var Be;Le.stopPropagation(),(Be=y.onNodeCollapse)==null||Be.call(y,N,!e.config.collapsed)},bgColor:Ae(((Ne=e==null?void 0:e.viewProps)==null?void 0:Ne.bgColor)||v),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Z.PiPlusBold,{size:30,color:Ae("gray.800")}):f.jsx(Z.PiMinusBold,{size:30,color:Ae("gray.800")})})})(),r({id:N,data:e,isActive:I,isHovered:E,isLowZoom:me,isEditing:A,onSelect:ve,onEditStart:()=>R(!0),onEditEnd:()=>R(!1)})]})]})},Bn=_.memo(zj),Bj=({id:e,data:r,isActive:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var y,g,v,b,x,w,C,S;const{themeColor:s}=Ze(),{colorText:a}=at(),c=((y=r==null?void 0:r.viewProps)==null?void 0:y.bgColor)==="transparent",l=((g=r==null?void 0:r.viewProps)==null?void 0:g.outline)===!0,{highlightColor:d,borderColor:u,textColor:h}=Tn(((v=r==null?void 0:r.viewProps)==null?void 0:v.bgColor)||s),p=Ae(((b=r==null?void 0:r.viewProps)==null?void 0:b.textColor)||(c||l?a:h)),m=((x=r==null?void 0:r.viewProps)==null?void 0:x.borderColor)||(l?!c&&((w=r==null?void 0:r.viewProps)==null?void 0:w.bgColor)||s:u);return f.jsx(V.Box,{"data-flow-node-surface":"",borderRadius:(C=r==null?void 0:r.viewProps)==null?void 0:C.borderRadius,bgColor:l?"transparent":d,...In(r==null?void 0:r.viewProps,m,t,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:f.jsxs(V.Flex,{justifyContent:"start",alignItems:"center",gap:8,w:"fit-content",maxW:900,minW:0,fontSize:"5xl",lineHeight:"normal",children:[((S=r==null?void 0:r.config)==null?void 0:S.icon)&&f.jsx(V.Box,{flexShrink:0,children:f.jsx(Zt,{name:r.config.icon,size:80,color:p})}),f.jsx(Hr,{nodeId:e,label:(r==null?void 0:r.label)||(r==null?void 0:r.text)||"",color:p,isEditing:n,onEditStart:o,onEditEnd:i})]})})};function Dn(){const{nodeViewModes:e,setNodeViewMode:r,allNodesIconLabel:t,setAllNodesIconLabel:n}=Ze();return{allNodesIconLabel:t,setAllNodesIconLabel:n,getNodeViewMode:o=>e[o]??"default",showNodeProperties:o=>r(o,"properties"),restoreNodeView:o=>r(o,"default"),toggleNodeView:o=>r(o,e[o]==="properties"?"default":"properties"),setNodeViewMode:r}}function au(e,r,t){const{readOnly:n,selectedNodeIds:o}=Ze(),i=o.includes(e),s=_.useRef(i),a=_.useRef(t);a.current=t,_.useEffect(()=>{s.current&&!i&&r&&!n&&a.current(),s.current=i},[i,r,n])}const Dj=({id:e,isActive:r,data:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var x,w,C,S,j,P,E,O,A,R,M,T,N,$,I;const{themeColor:s}=Ze(),{colorText:a}=at(),c=((x=t==null?void 0:t.viewProps)==null?void 0:x.bgColor)==="transparent",l=((w=t==null?void 0:t.viewProps)==null?void 0:w.outline)===!0,d=!c&&((C=t==null?void 0:t.viewProps)==null?void 0:C.bgColor)||s,{borderColor:u,highlightColor:h,textColor:p}=Tn(d),m=Ae(((S=t==null?void 0:t.viewProps)==null?void 0:S.textColor)||(c||l?a:p)),y=c&&!l&&!((j=t==null?void 0:t.viewProps)!=null&&j.borderColor)?"transparent":Ae(((P=t==null?void 0:t.viewProps)==null?void 0:P.borderColor)||(l?d:u)),g=c||l?"transparent":d!=null&&d.startsWith("#")?d:Ae(h),v=(E=t==null?void 0:t.config)==null?void 0:E.icon,b=(t==null?void 0:t.label)??(t==null?void 0:t.text)??"";if((O=t==null?void 0:t.config)!=null&&O.labelBelow){const K=(((A=t==null?void 0:t.viewProps)==null?void 0:A.fontSize)||1)*100;return f.jsxs(V.Flex,{"data-flow-icon-label":"",css:{"--flow-grid-on-surface-color":m},direction:"column",align:"center",gap:"24px",width:`${Math.max(K+200,360)}px`,position:"relative",children:[f.jsx(V.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${K+100}px`,height:`${K+100}px`,flexShrink:0,borderRadius:(R=t==null?void 0:t.viewProps)==null?void 0:R.borderRadius,backgroundColor:g,...In(t==null?void 0:t.viewProps,y,r,2),children:!!v&&f.jsx(Zt,{name:v,size:K,color:m})}),f.jsxs(V.Flex,{"data-flow-icon-caption":"",direction:"column",align:"center",gap:"8px",justify:"center",width:"100%",minW:0,textAlign:"center",children:[f.jsx(Hr,{nodeId:e,label:b,color:`var(--flow-grid-caption-color, ${Ae(((M=t==null?void 0:t.viewProps)==null?void 0:M.textColor)||a)})`,isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0}),typeof((T=t.config)==null?void 0:T.subtitle)=="string"&&t.config.subtitle!==""&&f.jsx(V.Text,{"data-flow-node-subtitle":"",color:Ae(((N=t==null?void 0:t.viewProps)==null?void 0:N.textColor)||a),opacity:.65,fontSize:"32px",fontWeight:"normal",lineHeight:1.3,width:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",title:t.config.subtitle,children:t.config.subtitle})]})]})}return f.jsxs(V.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:($=t==null?void 0:t.viewProps)==null?void 0:$.borderRadius,bgColor:g,style:{backgroundColor:g},textTransform:"capitalize",...In(t==null?void 0:t.viewProps,y,r,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!v&&f.jsx(V.Flex,{align:"center",py:14,mr:b?8:0,flexShrink:0,children:f.jsx(Zt,{name:v,size:(((I=t==null?void 0:t.viewProps)==null?void 0:I.fontSize)||1)*100,color:m},m)}),(b||!v)&&f.jsx(V.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:f.jsx(Hr,{nodeId:e,label:b,color:m,isEditing:n,onEditStart:o,onEditEnd:i})})]})};function su({onExpand:e,toggleLabel:r="Show properties",toggleDisabled:t=!1,renderCompact:n=Dj,...o}){const{colorMode:i,callbacks:s}=Ze();return f.jsx(Bn,{...o,hoverLeaveDelay:e?350:0,children:a=>f.jsxs(V.Box,{position:"relative",children:[f.jsx(n,{...a}),e&&(a.isHovered||a.isActive)&&f.jsx(V.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:f.jsx(Ue,{label:r,children:f.jsx(Me,{"aria-label":r,icon:f.jsx(V.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:i==="dark"?"gray.100":"gray.800",disabled:t,onClick:c=>{var l;c.stopPropagation(),a.isActive||a.onSelect(c),e(),(l=s.onNodeViewToggle)==null||l.call(s,o.data.id)}})})})]})})}const Vj=`${Ib}
|
|
280
|
+
`;function au({nodeAddress:e,active:r,label:t,open:n=!1,onClose:o,children:i,filter:s,height:a,width:c}){const{background:l,border:d,colorText:u}=at(),{colorMode:h}=Je(),p=j.useRef(null),m=j.useId(),{data:y,schema:g,bindings:v}=j.useContext(Tt),b=i!==void 0||!!(y&&g&&(v?Nn(v,e,g):Yr(y,e,g)));j.useEffect(()=>{var w,C,S,_,I;!r||!b||!n?(w=p.current)==null||w.close():(C=p.current)!=null&&C.open||((S=p.current)==null||S.showModal(),(I=(_=p.current)==null?void 0:_.querySelector("[data-form-filter] input"))==null||I.focus())},[r,b,n]);const x=Me(l);return b?f.jsx(f.Fragment,{children:typeof document<"u"&&Dr.createPortal(f.jsx(Bj,{ref:p,id:m,$surface:x,$border:Me(d),"aria-label":`Configure ${t}`,onClose:o,onPointerDown:w=>w.stopPropagation(),onWheel:w=>w.stopPropagation(),onKeyDown:w=>w.stopPropagation(),onClick:w=>{var C;w.stopPropagation(),w.target===w.currentTarget&&((C=p.current)==null||C.close())},style:{position:"fixed",inset:"94px 20px auto auto",margin:0,padding:20,width:c??"var(--top-toolbar-width, 360px)",boxSizing:"border-box",maxWidth:"calc(100vw - 40px)",maxHeight:"calc(100dvh - 114px)",height:a,overflow:"hidden",borderRadius:30,background:x,color:Me(u),fontSize:16,textTransform:"none"},children:n&&f.jsxs(f.Fragment,{children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexShrink:0},children:[f.jsx("strong",{style:{overflowWrap:"anywhere",minWidth:0},children:t}),f.jsx(Zr,{"aria-label":"Close node configuration",onClick:()=>{var w;return(w=p.current)==null?void 0:w.close()}})]}),s&&f.jsx("div",{"data-form-filter":"",style:{flexShrink:0},children:s}),f.jsx(Dj,{$divider:`var(--chakra-colors-gray-${h==="dark"?"700":"200"})`,"data-form-scroll":"",style:a?{flex:1}:void 0,children:i??f.jsx(Td,{nodeAddress:e})})]})}),document.body)}):null}const bd=({icon:e,label:r,onClick:t,color:n,boxSize:o=6,...i})=>{const{background:s,border:a,colorText:c}=at();return f.jsx(Ke,{label:r,children:f.jsx(V.Flex,{asChild:!0,p:0,border:0,bg:"transparent",children:f.jsx("button",{type:"button","aria-label":r,onClick:t,children:f.jsx(V.Icon,{as:e,boxSize:o,color:n,cursor:t?"pointer":void 0})})})})},Vj=({data:e,children:r,isInverted:t,isParent:n,onOpenView:o,editOnMount:i=!1,hoverLeaveDelay:s=0})=>{var Ce,ge,he,Y,H,ve,J,be;const{selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isMultiSelectMode:u,nodeGridOptions:h,isPerformanceMode:p,engineRef:m,callbacks:y,config:g,themeColor:v,direction:b,nodeViewModes:x}=Je(),{background:w,border:C,colorText:S}=at(),_=j.useRef(null),I=j.useRef(null);j.useEffect(()=>()=>{I.current&&clearTimeout(I.current)},[]);const[E,O]=j.useState(!1),[A,R]=j.useState(i&&!!g.editable&&!g.readOnly),[P,T]=j.useState(!1),N=e==null?void 0:e.id,$=yb(N),M=a.includes(N),W=(Ce=g.nodeOverlayActions)==null?void 0:Ce.filter(Q=>!Q.nodeTypes||Q.nodeTypes.includes(e==null?void 0:e.type)),ae=g.renderNodeOverlay,se=(e==null?void 0:e.type)==="grid"?(ge=g.customViews)==null?void 0:ge.gridHoverControls:void 0,re=(e==null?void 0:e.type)==="grid"?"20px":"-100px",ye=(e==null?void 0:e.type)==="grid"?"top center":void 0,me=(e==null?void 0:e.type)==="grid"?"translateX(-50%) scale3d(1.8, 1.8, 1)":"translateX(-50%) scale3d(3, 3, 1)",L=(()=>{var Q;try{const je=(Q=m.current)==null?void 0:Q.zoom();return je!==void 0&&je<.08}catch{return!1}})(),z=j.useCallback(Q=>{var Pe,qe,Xe,Be;if(A||g.readOnly||h!=null&&h.fill&&!Q.shiftKey)return;const je={shiftKey:Q.shiftKey,ctrlKey:Q.ctrlKey,metaKey:Q.metaKey,altKey:Q.altKey};if(l&&(d(null),(Pe=y.onEdgeDeselect)==null||Pe.call(y)),u||Q.shiftKey&&(h!=null&&h.fill)){const ut=a.includes(N),De=ut?a.filter(rt=>rt!==N):[...a,N];c(De),ut?(qe=y.onNodeDeselect)==null||qe.call(y):(Xe=y.onNodeSelect)==null||Xe.call(y,N,e,je)}else c([N]),(Be=y.onNodeSelect)==null||Be.call(y,N,e,je)},[N,e,a,l,u,h,A,c,d,y,g]),U=j.useCallback(()=>{var Q;A||g.readOnly||(Q=y.onNodeDoubleClick)==null||Q.call(y,N,e)},[N,e,A,y,g]),B=j.useCallback(()=>{I.current&&clearTimeout(I.current),I.current=setTimeout(()=>O(!0),100)},[]),ce=j.useCallback(Q=>{var je;Q.relatedTarget instanceof Node&&((je=_.current)!=null&&je.contains(Q.relatedTarget))||(I.current&&clearTimeout(I.current),s?I.current=setTimeout(()=>O(!1),s):O(!1))},[s]),X=!!((he=e==null?void 0:e.config)!=null&&he.form),le={tabIndex:X?0:void 0,"aria-haspopup":X?"dialog":void 0,"aria-expanded":X?P:void 0,onDoubleClickCapture:Q=>{var je;!X&&!o||g.readOnly||A||!Q.currentTarget.contains(Q.target)||Q.target instanceof Element&&Q.target.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]")||(Q.preventDefault(),Q.stopPropagation(),c([N]),o?o():T(!0),(je=y.onNodeDoubleClick)==null||je.call(y,N,e))},onKeyDown:Q=>{!X&&!o||g.readOnly||Q.target!==Q.currentTarget||Q.key!=="Enter"||(Q.preventDefault(),Q.stopPropagation(),c([N]),o?o():T(!0))}},ue=X&&f.jsx(au,{nodeAddress:N,active:M,label:e.label||e.headerTitle||"Node",open:P,onClose:()=>{var Q;T(!1),M&&((Q=_.current)==null||Q.focus({preventScroll:!0}))}}),xe=Array.isArray((Y=e==null?void 0:e.config)==null?void 0:Y.ports)?e.config.ports.map(Q=>f.jsx(Zv,{...Q},`${Q.id}:${Q.role}`)):null;return n?f.jsxs(V.Box,{ref:_,...le,onClick:z,onDoubleClick:U,onMouseEnter:B,onMouseLeave:ce,cursor:"pointer",position:"relative",children:[ue,!p&&(ae||W&&W.length>0)&&E&&!L&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>O(!0),onMouseLeave:ce}),ae?f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:re,transformOrigin:ye,left:"50%",pointerEvents:"auto",transform:me,onMouseEnter:()=>O(!0),onMouseLeave:ce,willChange:"transform",children:ae({nodeId:N,nodeData:e,isRoot:N==="root",isParent:!0,isHovered:E,setIsHovered:O})}):f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:re,transformOrigin:ye,left:"50%",bg:w,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:me,boxShadow:"lg",onMouseEnter:()=>O(!0),onMouseLeave:ce,willChange:"transform",children:f.jsxs(V.HStack,{px:2,gap:2,children:[W.map((Q,je)=>f.jsxs(V.Box,{display:"contents",children:[je>0&&f.jsx(V.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(bd,{icon:Q.icon,label:Q.label,color:S,bgColor:w,borderColor:C,textColor:S,boxSize:5,onClick:Pe=>{var qe;Pe.stopPropagation(),(qe=y.onNodeHoverAction)==null||qe.call(y,Q.id,N,e)}})]},Q.id)),se&&f.jsx(se,{data:e})]})})]}),r({id:N,data:e,isActive:M,isHovered:E,isLowZoom:L,isEditing:A,onSelect:z,onEditStart:()=>R(!0),onEditEnd:()=>R(!1)}),$&&!((H=e==null?void 0:e.config)!=null&&H.parentContainer)&&((ve=e==null?void 0:e.config)==null?void 0:ve.collapsed)!==void 0&&(()=>{var Pe;const Q=b==="TB"||b==="BT",je=t||b==="RL";return f.jsx(V.IconButton,{position:"absolute",...Q?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:je?void 0:"-75px",left:je?"-75px":void 0,top:"50%",transform:"translateY(-50%)"},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:g.readOnly,onClick:qe=>{var Xe;qe.stopPropagation(),(Xe=y.onNodeCollapse)==null||Xe.call(y,N,!e.config.collapsed)},bgColor:Me(((Pe=e==null?void 0:e.viewProps)==null?void 0:Pe.bgColor)||v),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Z.PiPlusBold,{size:30,color:Me("gray.800")}):f.jsx(Z.PiMinusBold,{size:30,color:Me("gray.800")})})})()]}):f.jsxs(V.Box,{ref:_,...le,onClick:z,onDoubleClick:U,onMouseEnter:B,onMouseLeave:ce,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[ue,xe,!p&&(ae||W&&W.length>0)&&E&&!L&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>O(!0),onMouseLeave:ce}),ae?f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:re,transformOrigin:ye,left:"50%",pointerEvents:"auto",transform:me,onMouseEnter:()=>O(!0),onMouseLeave:ce,willChange:"transform",children:ae({nodeId:N,nodeData:e,isRoot:N==="root",isParent:!!n,isHovered:E,setIsHovered:O})}):f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:re,transformOrigin:ye,left:"50%",bg:w,p:3,borderColor:C,borderWidth:1,borderRadius:"30px",pointerEvents:"auto",transform:me,boxShadow:"lg",onMouseEnter:()=>O(!0),onMouseLeave:ce,willChange:"transform",children:f.jsxs(V.HStack,{px:2,gap:2,children:[W.map((Q,je)=>f.jsxs(V.Box,{display:"contents",children:[je>0&&f.jsx(V.Box,{borderColor:C,height:5,borderRightWidth:1}),f.jsx(bd,{icon:Q.icon,label:Q.label,color:S,bgColor:w,borderColor:C,textColor:S,boxSize:5,onClick:Pe=>{var qe;Pe.stopPropagation(),(qe=y.onNodeHoverAction)==null||qe.call(y,Q.id,N,e)}})]},Q.id)),se&&f.jsx(se,{data:e})]})})]}),f.jsxs(V.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[$&&!((J=e==null?void 0:e.config)!=null&&J.parentContainer)&&((be=e==null?void 0:e.config)==null?void 0:be.collapsed)!==void 0&&!n&&(()=>{var qe,Xe,Be;const Q=b==="TB"||b==="BT",je=t||b==="RL",Pe=(qe=e==null?void 0:e.config)!=null&&qe.labelBelow&&x[N]!=="properties"?((((Xe=e==null?void 0:e.viewProps)==null?void 0:Xe.fontSize)||1)*100+100)/2:void 0;return f.jsx(V.IconButton,{position:"absolute",...Q?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:je?void 0:Pe===void 0?"-75px":`calc(50% - ${Pe+75}px)`,left:je?Pe===void 0?"-75px":`calc(50% - ${Pe+75}px)`:void 0,alignSelf:Pe===void 0?"center":void 0,top:Pe===void 0?void 0:`${Pe}px`,transform:Pe===void 0?void 0:"translateY(-50%)",zIndex:Pe===void 0?void 0:1},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:g.readOnly,onClick:ut=>{var De;ut.stopPropagation(),(De=y.onNodeCollapse)==null||De.call(y,N,!e.config.collapsed)},bgColor:Me(((Be=e==null?void 0:e.viewProps)==null?void 0:Be.bgColor)||v),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Z.PiPlusBold,{size:30,color:Me("gray.800")}):f.jsx(Z.PiMinusBold,{size:30,color:Me("gray.800")})})})(),r({id:N,data:e,isActive:M,isHovered:E,isLowZoom:L,isEditing:A,onSelect:z,onEditStart:()=>R(!0),onEditEnd:()=>R(!1)})]})]})},Dn=j.memo(Vj),Wj=({id:e,data:r,isActive:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var y,g,v,b,x,w,C,S;const{themeColor:s}=Je(),{colorText:a}=at(),c=((y=r==null?void 0:r.viewProps)==null?void 0:y.bgColor)==="transparent",l=((g=r==null?void 0:r.viewProps)==null?void 0:g.outline)===!0,{highlightColor:d,borderColor:u,textColor:h}=On(((v=r==null?void 0:r.viewProps)==null?void 0:v.bgColor)||s),p=Me(((b=r==null?void 0:r.viewProps)==null?void 0:b.textColor)||(c||l?a:h)),m=((x=r==null?void 0:r.viewProps)==null?void 0:x.borderColor)||(l?!c&&((w=r==null?void 0:r.viewProps)==null?void 0:w.bgColor)||s:u);return f.jsx(V.Box,{"data-flow-node-surface":"",borderRadius:(C=r==null?void 0:r.viewProps)==null?void 0:C.borderRadius,bgColor:l?"transparent":d,...In(r==null?void 0:r.viewProps,m,t,2),py:14,px:20,whiteSpace:"nowrap",w:"fit-content",children:f.jsxs(V.Flex,{justifyContent:"start",alignItems:"center",gap:8,w:"fit-content",maxW:900,minW:0,fontSize:"5xl",lineHeight:"normal",children:[((S=r==null?void 0:r.config)==null?void 0:S.icon)&&f.jsx(V.Box,{flexShrink:0,children:f.jsx(Yt,{name:r.config.icon,size:80,color:p})}),f.jsx(Kr,{nodeId:e,label:(r==null?void 0:r.label)||(r==null?void 0:r.text)||"",color:p,isEditing:n,onEditStart:o,onEditEnd:i})]})})};function Vn(){const{nodeViewModes:e,setNodeViewMode:r,allNodesIconLabel:t,setAllNodesIconLabel:n}=Je();return{allNodesIconLabel:t,setAllNodesIconLabel:n,getNodeViewMode:o=>e[o]??"default",showNodeProperties:o=>r(o,"properties"),restoreNodeView:o=>r(o,"default"),toggleNodeView:o=>r(o,e[o]==="properties"?"default":"properties"),setNodeViewMode:r}}function su(e,r,t){const{readOnly:n,selectedNodeIds:o}=Je(),i=o.includes(e),s=j.useRef(i),a=j.useRef(t);a.current=t,j.useEffect(()=>{s.current&&!i&&r&&!n&&a.current(),s.current=i},[i,r,n])}const Gj=({id:e,isActive:r,data:t,isEditing:n,onEditStart:o,onEditEnd:i})=>{var x,w,C,S,_,I,E,O,A,R,P,T,N,$,M;const{themeColor:s}=Je(),{colorText:a}=at(),c=((x=t==null?void 0:t.viewProps)==null?void 0:x.bgColor)==="transparent",l=((w=t==null?void 0:t.viewProps)==null?void 0:w.outline)===!0,d=!c&&((C=t==null?void 0:t.viewProps)==null?void 0:C.bgColor)||s,{borderColor:u,highlightColor:h,textColor:p}=On(d),m=Me(((S=t==null?void 0:t.viewProps)==null?void 0:S.textColor)||(c||l?a:p)),y=c&&!l&&!((_=t==null?void 0:t.viewProps)!=null&&_.borderColor)?"transparent":Me(((I=t==null?void 0:t.viewProps)==null?void 0:I.borderColor)||(l?d:u)),g=c||l?"transparent":d!=null&&d.startsWith("#")?d:Me(h),v=(E=t==null?void 0:t.config)==null?void 0:E.icon,b=(t==null?void 0:t.label)??(t==null?void 0:t.text)??"";if((O=t==null?void 0:t.config)!=null&&O.labelBelow){const W=(((A=t==null?void 0:t.viewProps)==null?void 0:A.fontSize)||1)*100;return f.jsxs(V.Flex,{"data-flow-icon-label":"",css:{"--flow-grid-on-surface-color":m},direction:"column",align:"center",gap:"24px",width:`${Math.max(W+200,360)}px`,position:"relative",children:[f.jsx(V.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${W+100}px`,height:`${W+100}px`,flexShrink:0,borderRadius:(R=t==null?void 0:t.viewProps)==null?void 0:R.borderRadius,backgroundColor:g,...In(t==null?void 0:t.viewProps,y,r,2),children:!!v&&f.jsx(Yt,{name:v,size:W,color:m})}),f.jsxs(V.Flex,{"data-flow-icon-caption":"",direction:"column",align:"center",gap:"8px",justify:"center",width:"100%",minW:0,textAlign:"center",children:[f.jsx(Kr,{nodeId:e,label:b,color:`var(--flow-grid-caption-color, ${Me(((P=t==null?void 0:t.viewProps)==null?void 0:P.textColor)||a)})`,isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0}),typeof((T=t.config)==null?void 0:T.subtitle)=="string"&&t.config.subtitle!==""&&f.jsx(V.Text,{"data-flow-node-subtitle":"",color:Me(((N=t==null?void 0:t.viewProps)==null?void 0:N.textColor)||a),opacity:.65,fontSize:"32px",fontWeight:"normal",lineHeight:1.3,width:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",title:t.config.subtitle,children:t.config.subtitle})]})]})}return f.jsxs(V.Flex,{"data-flow-node-surface":"",align:"center",borderRadius:($=t==null?void 0:t.viewProps)==null?void 0:$.borderRadius,bgColor:g,style:{backgroundColor:g},textTransform:"capitalize",...In(t==null?void 0:t.viewProps,y,r,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!v&&f.jsx(V.Flex,{align:"center",py:14,mr:b?8:0,flexShrink:0,children:f.jsx(Yt,{name:v,size:(((M=t==null?void 0:t.viewProps)==null?void 0:M.fontSize)||1)*100,color:m},m)}),(b||!v)&&f.jsx(V.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:f.jsx(Kr,{nodeId:e,label:b,color:m,isEditing:n,onEditStart:o,onEditEnd:i})})]})};function cu({onExpand:e,toggleLabel:r="Show properties",toggleDisabled:t=!1,renderCompact:n=Gj,...o}){const{colorMode:i,callbacks:s}=Je();return f.jsx(Dn,{...o,hoverLeaveDelay:e?350:0,children:a=>f.jsxs(V.Box,{position:"relative",children:[f.jsx(n,{...a}),e&&(a.isHovered||a.isActive)&&f.jsx(V.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:f.jsx(Ke,{label:r,children:f.jsx(Oe,{"aria-label":r,icon:f.jsx(V.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:i==="dark"?"gray.100":"gray.800",disabled:t,onClick:c=>{var l;c.stopPropagation(),a.isActive||a.onSelect(c),e(),(l=s.onNodeViewToggle)==null||l.call(s,o.data.id)}})})})]})})}const Uj=`${Nb}
|
|
281
281
|
[data-flow-loading-border][data-flow-loading-border] .flow-sdk-node-border-animation{animation:flow-sdk-node-border 2.4s linear infinite!important}
|
|
282
282
|
[data-flow-loading-border][data-flow-loading-border][data-motion-disabled] .flow-sdk-node-border-animation{animation:none!important}
|
|
283
|
-
@media(prefers-reduced-motion:reduce){[data-flow-loading-border][data-flow-loading-border] .flow-sdk-node-border-animation{animation:none!important}}`;function Hv({active:e=!0,label:r="Loading content",radius:t}){const{config:n,themeColor:o}=Ze(),{colorText:i}=at(),s=_.useRef(null),[a,c]=_.useState({width:0,height:0,radius:0});if(_.useLayoutEffect(()=>{const u=s.current;if(!e||!u)return;const h=()=>{const m=u.parentElement,y={width:u.clientWidth,height:u.clientHeight,radius:t??(m&&parseFloat(getComputedStyle(m).borderTopLeftRadius)||0)};c(g=>g.width===y.width&&g.height===y.height&&g.radius===y.radius?g:y)},p=new ResizeObserver(h);return p.observe(u),h(),()=>p.disconnect()},[e,t]),!e)return null;const l=Ae(o||i),d={x:4,y:4,width:a.width-8,height:a.height-8,radius:Math.max(0,a.radius-4),color:l,strokeWidth:2};return f.jsxs("div",{ref:s,role:"status","aria-label":r,"data-flow-loading-border":"","data-motion-disabled":n.disableAnimations||void 0,style:{position:"absolute",inset:0,pointerEvents:"none",borderRadius:"inherit",overflow:"hidden",zIndex:2},children:[f.jsx("style",{children:Vj}),f.jsxs("svg",{width:"100%",height:"100%","aria-hidden":"true",style:{display:"block",pointerEvents:"none"},children:[f.jsx("g",{opacity:.5,style:{filter:"blur(3px)"},children:f.jsx(ro,{...d,strokeWidth:6})}),f.jsx(ro,{...d})]})]})}function Gj({content:e,format:r,onEdit:t}){var N;const{config:n,colorMode:o}=Ze(),{background:i,border:s,colorInactive:a}=at(),c=(N=n.customViews)==null?void 0:N.jsxContent,l=typeof e=="string"?e:JSON.stringify(e,null,2);let d,u;if(r==="jsx")try{const $=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray($)||$.some(I=>!I||typeof I!="object"||Array.isArray(I)||typeof I.type!="string"))throw new Error("JSX content must be an array of components with a type.");d=$}catch($){u=$ instanceof Error?$.message:"Invalid components array."}const h=_.useRef(null),p=_.useRef(null),m=_.useRef(null),y=_.useRef(!1),[g,v]=_.useState(!1),[b,x]=_.useState(""),w=!!t;_.useEffect(()=>{const $=()=>{var K;const I=document.fullscreenElement===p.current;v(I),y.current&&!I&&!document.fullscreenElement&&((K=m.current)==null||K.focus({preventScroll:!0})),y.current=I};return document.addEventListener("fullscreenchange",$),()=>document.removeEventListener("fullscreenchange",$)},[]);const C=async()=>{var $;x("");try{if(document.fullscreenElement===p.current)await document.exitFullscreen();else if(($=p.current)!=null&&$.requestFullscreen)await p.current.requestFullscreen();else throw new Error("Fullscreen is not supported in this browser.")}catch(I){x(I instanceof Error?I.message:"Unable to change fullscreen.")}},[S,j]=_.useState(),[P,E]=_.useState(),[O,A]=_.useState();_.useEffect(()=>{if(r==="jsx")return;let $=!1;return Promise.resolve().then(()=>require("./contentPreviewDocument-BsKd0dD4.cjs")).then(({contentPreviewDocument:I})=>I(l,r,w)).then(I=>{$||j({content:l,format:r,editable:w,document:I})},I=>{$||j({content:l,format:r,editable:w,error:I instanceof Error?I.message:String(I)})}),()=>{$=!0}},[l,r,w]),_.useEffect(()=>{if(!t)return;const $=async I=>{var K,ie;if(!(!((K=h.current)!=null&&K.contentWindow)||I.source!==h.current.contentWindow||((ie=I.data)==null?void 0:ie.type)!=="squeed:content-edit"))try{document.fullscreenElement===p.current&&await document.exitFullscreen(),t()}catch(se){x(se instanceof Error?se.message:"Unable to close fullscreen.")}};return window.addEventListener("message",$),()=>window.removeEventListener("message",$)},[t]);const R=(S==null?void 0:S.content)===l&&S.format===r&&S.editable===w?S:void 0,M=!!R&&R===O,T=r!=="jsx"&&!(R!=null&&R.error)&&!M&&(!R||P!==R);return f.jsxs("div",{"data-flow-content-preview":"",style:{width:"100%",height:360,fontSize:16,overflow:"auto"},children:[f.jsx("pre",{"data-flow-preview-source":"",style:{display:"none",whiteSpace:"pre-wrap"},children:l}),f.jsxs(V.Box,{ref:p,position:"relative",w:"100%",h:"100%","aria-busy":r!=="jsx"?T:void 0,bg:r==="jsx"&&o==="dark"?"gray.900":"white",onDoubleClick:$=>{r!=="jsx"||!t||$.defaultPrevented||$.target.closest('button, a, input, textarea, select, [contenteditable], [role="button"], [role="textbox"]')||($.stopPropagation(),(async()=>{document.fullscreenElement===p.current&&await document.exitFullscreen(),t()})().catch(I=>x(String(I))))},onKeyDownCapture:$=>{$.key!=="Escape"||document.fullscreenElement!==p.current||($.preventDefault(),$.stopPropagation(),C())},css:{"&:fullscreen":{width:"100vw",height:"100dvh",maxWidth:"none",maxHeight:"none",padding:0},"&:hover > [data-flow-content-toolbar], &:focus-within > [data-flow-content-toolbar]":{opacity:1,pointerEvents:"auto"},"@media (hover: none)":{"& > [data-flow-content-toolbar]":{opacity:1,pointerEvents:"auto"}}},children:[f.jsx(V.Box,{role:"toolbar","aria-label":"Content controls","data-flow-content-toolbar":"",position:"absolute",top:"8px",right:"8px",zIndex:1,w:"max-content",maxW:"calc(100% - 16px)",opacity:g?1:0,pointerEvents:g?"auto":"none",children:f.jsx(Od,{background:i,border:o==="dark"?s:"gray.300",children:f.jsxs(V.HStack,{px:"8px",gap:"8px",h:"100%",w:"max-content",css:{"& button > svg":{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",flexShrink:0}},children:[t&&f.jsx(Me,{"data-flow-content-edit":"","aria-label":"Edit content source",title:"Edit content source",icon:f.jsx(Z.PiCode,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:a,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:$=>{$.stopPropagation(),(async()=>{document.fullscreenElement===p.current&&await document.exitFullscreen(),t()})().catch(I=>x(String(I)))}}),f.jsx(Me,{ref:m,"data-flow-fullscreen":"","aria-label":g?"Exit fullscreen":"Expand preview",title:g?"Exit fullscreen":"Expand preview","aria-expanded":g,icon:g?f.jsx(Z.PiArrowsIn,{size:20}):f.jsx(Z.PiArrowsOut,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:a,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:$=>{$.stopPropagation(),C()}})]})})}),b&&f.jsx(V.Box,{role:"alert",position:"absolute",bottom:0,insetInline:0,bg:"white",color:"red.700",fontSize:"14px",children:b}),r==="jsx"?u?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:u}):c&&d?f.jsx(c,{components:d,colorMode:o,fillHeight:!0}):f.jsx(V.Box,{role:"status",fontSize:"14px",children:"JSX content renderer is not available."}):R!=null&&R.error||M?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:(R==null?void 0:R.error)||"Content preview could not be loaded."}):R!=null&&R.document?f.jsx("iframe",{ref:h,title:`${r.toUpperCase()} content preview`,sandbox:w?"allow-scripts":"",allowFullScreen:!0,referrerPolicy:"no-referrer",srcDoc:R.document,onLoad:()=>E(R),onError:()=>A(R),style:{width:"100%",height:"100%",border:0,display:"block",background:"white",visibility:T?"hidden":"visible"}},R.document):null,f.jsx(Hv,{active:T,label:"Loading HTML content"})]})]})}const vm=1.55;function Wj({nodeId:e,content:r,color:t,format:n="markdown"}){const{callbacks:o,config:i,readOnly:s,nodeGridOptions:a}=Ze(),c=!!i.editable&&!s&&!a,l=typeof r=="string"?r:JSON.stringify(r,null,2),[d,u]=_.useState(!1),[h,p]=_.useState(l),[m,y]=_.useState(""),[g,v]=_.useState(),b=_.useRef(null),x=_.useRef(!1),w=ou(d);_.useLayoutEffect(()=>{const j=b.current;!d||!j||(j.style.height="auto",j.style.height=`${Math.max((g==null?void 0:g.height)??0,j.scrollHeight)}px`)},[h,d,g]),_.useEffect(()=>{var j,P;c?d&&(x.current=!1,(j=b.current)==null||j.focus({preventScroll:!0}),(P=b.current)==null||P.select()):u(!1)},[d,c]);const C=j=>{c&&(v({width:j.offsetWidth,height:j.offsetHeight}),p(l),y(""),u(!0))},S=()=>{var P;if(x.current||!c)return;let j=h;if(n==="jsx")try{if(j=JSON.parse(h),!Array.isArray(j)||j.some(E=>!E||typeof E!="object"||Array.isArray(E)||typeof E.type!="string"))throw new Error("JSX content must be an array of components with a type.")}catch(E){y(E instanceof Error?E.message:"Invalid components array.");return}x.current=!0,h!==l&&((P=o.onNodeContentChange)==null||P.call(o,e,j)),u(!1)};return(!d||!c)&&n!=="markdown"?f.jsx(V.Box,{ref:w,w:"100%",position:"relative","data-flow-content":"",children:f.jsx(Gj,{content:r,format:n,onEdit:c?()=>{w.current&&C(w.current)}:void 0})}):!d||!c?f.jsx(V.Box,{"data-flow-content":"",color:t,opacity:r?void 0:.6,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:vm,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:c?"text":void 0,tabIndex:c?0:void 0,outline:"none",_focusVisible:{outline:"none",boxShadow:"none"},onClick:j=>{!c||j.target instanceof Element&&j.target.closest("a, button, input")||(j.stopPropagation(),C(j.currentTarget))},onDoubleClick:j=>{j.stopPropagation(),C(j.currentTarget)},onKeyDown:j=>{c&&j.key==="Enter"&&j.target===j.currentTarget&&(j.preventDefault(),j.stopPropagation(),C(j.currentTarget))},children:f.jsx(mx.default,{options:{forceBlock:!0,wrapper:_.Fragment,disableParsingRawHTML:!0,overrides:{a:{props:{target:"_blank",rel:"noopener noreferrer"}},img:{props:{loading:"lazy",referrerPolicy:"no-referrer"}}}},children:l||(i.editable&&!s?"Write your content here":"")})}):f.jsxs("div",{ref:w,style:{width:g==null?void 0:g.width,minHeight:g==null?void 0:g.height,maxWidth:"100%"},children:[f.jsx(V.Textarea,{ref:b,"aria-label":"Node content",placeholder:"Write your content here",value:h,"aria-invalid":!!m,onChange:j=>p(j.target.value),onBlur:S,onKeyDown:j=>{j.stopPropagation(),!j.nativeEvent.isComposing&&(j.key==="Enter"&&(j.ctrlKey||j.metaKey)&&(j.preventDefault(),S()),j.key==="Escape"&&(x.current=!0,u(!1)))},color:t,fontFamily:"inherit",fontSize:"inherit",lineHeight:vm,overflowWrap:"anywhere",whiteSpace:"pre-wrap",rows:1,bg:"transparent",display:"block",style:{border:0,outline:"none",boxShadow:"none"},_focus:{border:0,outline:"none",boxShadow:"none"},_focusVisible:{border:0,outline:"none",boxShadow:"none"},p:0,w:"100%",h:"100%",minW:0,minH:0,resize:"none"}),m&&f.jsx(V.Box,{role:"alert",fontSize:"14px",color:"red.500",children:m})]})}const Uj=(e,r,t)=>{var h,p,m,y;const n=((h=e==null?void 0:e.viewProps)==null?void 0:h.bgColor)||r,[o]=n.split("."),i=Tn(n),s=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,a=n==="transparent"||s,c=t==="dark"?"gray.200":"gray.900",l=a?"transparent":n!=null&&n.startsWith("#")?Ae(n):Ae(i.bgColor),d=Ae(((m=e==null?void 0:e.viewProps)==null?void 0:m.textColor)||(a?c:i.textColor)),u=Ae(((y=e==null?void 0:e.viewProps)==null?void 0:y.borderColor)||(s?n==="transparent"?r:n:i.borderColor));return{...i,bgColor:a?"transparent":i.bgColor,highlightColor:a?"transparent":i.highlightColor,isTransparent:a,propertyColor:a?c:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:l,hextextColor:d,hexborderColor:u}},Hj=(e,r=350)=>`${String(e).substring(0,r)}${String(e).length>r?"...":""}`,Kj=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,Kv=600,Jj=3,Zj=e=>{const r=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(r*28+30,200)};function Xj({headerTitle:e,hasContent:r,data:t,icon:n,colors:o,hasConfig:i,id:s,isActive:a,isHovered:c,isEditing:l,onSelect:d,onEditStart:u,onEditEnd:h,props:p,objVisible:m,setObjVisible:y,onShowNativeIcon:g}){var w,C;const{callbacks:v}=Ze(),b=p.onShowIcon??g,x=b?"Show icon":m?"Show content":"Show properties";return f.jsx(f.Fragment,{children:(e||r||((w=t.config)==null?void 0:w.form)||(a||c)&&g)&&f.jsxs(V.Flex,{justify:"flex-start",direction:"row",p:r||Object.entries(t.description||{}).length?8:20,borderBottomWidth:1,minWidth:"max-content !important",width:"100%",textTransform:"capitalize",align:"center",textOverflow:"ellipsis",alignItems:"center",fontWeight:"bold",color:o.propertyColor,bgColor:o.highlightColor,borderBottomColor:!i&&!r?"transparent":o.hexborderColor,children:[!!n&&f.jsx(V.Flex,{mr:6,alignItems:"center",flexShrink:0,children:f.jsx(Zt,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),f.jsx(Hr,{nodeId:s,label:Kj(e),color:((C=t==null?void 0:t.viewProps)==null?void 0:C.textColor)||o.propertyColor,isEditing:l,onEditStart:u,onEditEnd:h}),(a||c)&&(r||b)&&f.jsx(V.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:f.jsx(Ue,{label:x,children:f.jsx(Me,{"aria-label":x,icon:f.jsx(V.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:S=>{var j;S.stopPropagation(),a||d(S),b?b():y(!m),(j=v.onNodeViewToggle)==null||j.call(v,s)}})})})]})})}function Yj({data:e,resourcePorts:r,inspecting:t,form:n,inspectionPorts:o,extraPorts:i,colors:s,direction:a,uniformKeyWidth:c}){const{edgeById:l}=yr(),d=new Set;for(const{data:u}of l.values())u.source===e.id&&u.sourceProperty!==void 0&&d.add(`source:${u.sourceProperty}`),u.target===e.id&&u.targetProperty!==void 0&&d.add(`target:${u.targetProperty}`);return f.jsx(V.Box,{children:Object.entries(e.description||{}).map(([u,h],p)=>{var M,T,N;const m=r&&Object.keys(r).find($=>$.slice($.indexOf(":")+1)===u),y=t&&((M=n==null?void 0:n.type.ports)==null?void 0:M[u]),g=m??(y?`${y.kind}:${u}`:u),v=o.find($=>$.id===g),b=m?"source":v==null?void 0:v.role,x=d.has(`source:${g}`),w=d.has(`target:${g}`),C=i.some($=>$.id===u),S=h===""&&(C||(b?d.has(`${b}:${g}`):x||w)),j=b??(x!==w?x?"source":"target":void 0),P=(v==null?void 0:v.side)??(j?j==="source"!=(a==="RL")?"right":"left":void 0),E=S&&P==="right"?"right":"left",O=(v==null?void 0:v.label)??(y==null?void 0:y.label)??(C?u.replace(/^(template|input|output|config|error):/,""):u),A=Jt(s.wordBeforeDot)[typeof h],R=Jt(s.wordBeforeDot).property;return f.jsxs(V.Box,{"data-flow-property":m&&(a==="TB"||a==="BT")?void 0:g,"data-flow-port-role":b,"data-flow-inspection-row":t?"":void 0,children:[f.jsxs(V.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[f.jsx(V.Flex,{justifyContent:"start",align:"center",background:s.highlightColor,width:S?"100%":`${c}px`,minWidth:`${c}px`,borderRightColor:s.hexborderColor,borderRightWidth:S?0:1,children:f.jsx(V.Text,{py:5,px:10,w:"100%",textAlign:E,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((T=e==null?void 0:e.viewProps)==null?void 0:T.textColor)||(s.isTransparent?s.hextextColor:R),children:O})}),!S&&f.jsx(V.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:s.hexbgColor,w:Kv,maxH:200,children:f.jsx(V.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:((N=e==null?void 0:e.viewProps)==null?void 0:N.textColor)||(s.isTransparent?s.hextextColor:A),fontWeight:400,children:Hj(h)})})]}),p!==Object.entries(e.description||{}).length-1&&f.jsx(V.Box,{borderTopWidth:1,my:0,borderColor:s.hexborderColor})]},u)})})}function Qj(e){var x,w,C,S,j;const{themeColor:r,colorMode:t,direction:n}=Ze(),o=Dn(),i=o.getNodeViewMode(e.data.id)==="properties",s=P=>o.setNodeViewMode(e.data.id,P?"properties":"default"),a=!!e.onShowIcon||i||typeof((x=e.data.config)==null?void 0:x.content)!="string"&&!(((w=e.data.config)==null?void 0:w.contentFormat)==="jsx"&&Array.isArray((C=e.data.config)==null?void 0:C.content)),{bindings:c,data:l,schema:d}=_.useContext(Mt),u=(S=c==null?void 0:c[e.data.id])==null?void 0:S.portResources,h=c?On(c,e.data.id,d):l&&d?Zr(l,e.data.id,d):void 0,p=h&&qe(l,"address"in h?h.address:e.data.id),m=p&&typeof p=="object"&&h?Object.fromEntries(Object.keys(h.type.properties).filter(P=>{var E;return Object.prototype.hasOwnProperty.call(p,P)&&uo((E=h.fields[P])==null?void 0:E.$visibleWhen,l)}).map(P=>[P,p[P]!==null&&typeof p[P]=="object"?JSON.stringify(p[P],null,2):p[P]===null?"null":p[P]])):{},y=u?Object.fromEntries(Object.entries(u).map(([P,E])=>{var O;return[P.slice(P.indexOf(":")+1),((O=qe(l,E))==null?void 0:O.name)??E.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:m,g=a&&!u?((j=e.data.config)==null?void 0:j.ports)??[]:[],v=g.filter(P=>!Object.prototype.hasOwnProperty.call(y,P.id)&&!Object.entries((h==null?void 0:h.type.ports)??{}).some(([E,O])=>`${O.kind}:${E}`===P.id&&Object.prototype.hasOwnProperty.call(y,E))),b={...y,...Object.fromEntries(v.map(P=>[P.id,""]))};return{themeColor:r,colorMode:t,direction:n,objVisible:i,setObjVisible:s,inspecting:a,resourcePorts:u,form:h,description:b,inspectionPorts:g,extraPorts:v}}const cu=e=>{var b,x,w,C,S,j;const{themeColor:r,colorMode:t,direction:n,objVisible:o,setObjVisible:i,inspecting:s,resourcePorts:a,form:c,description:l,inspectionPorts:d,extraPorts:u}=Qj(e),h=Dn(),p=h.getNodeViewMode(e.data.id)==="icon-label",m=!e.onShowIcon&&(typeof((b=e.data.config)==null?void 0:b.content)=="string"||((x=e.data.config)==null?void 0:x.contentFormat)==="jsx"&&Array.isArray((w=e.data.config)==null?void 0:w.content)),y=_.useRef(p);p&&(y.current=!0),au(e.data.id,m&&!((C=e.data.config)!=null&&C.parentContainer)&&h.allNodesIconLabel&&!p&&y.current,()=>h.setNodeViewMode(e.data.id,"icon-label"));const v=!e.onShowIcon&&!((S=e.data.config)!=null&&S.parentContainer)&&!m?()=>h.setNodeViewMode(e.data.id,"icon-label"):void 0;return!e.onShowIcon&&p?f.jsx(su,{...e,data:{...e.data,label:e.data.label??e.data.headerTitle,config:{...e.data.config,labelBelow:!0,icon:((j=e.data.config)==null?void 0:j.icon)||"PiBracketsCurly"}},onExpand:()=>h.restoreNodeView(e.data.id)}):f.jsx(Bn,{...e,data:{...e.data,description:l},hoverLeaveDelay:m||e.onShowIcon||v?350:0,children:({id:P,data:E,isActive:O,isHovered:A,isEditing:R,onSelect:M,onEditStart:T,onEditEnd:N})=>{var F,D,W,B,le,Y,ce,ue,xe,Ce;const $=Uj(E,r,t),I=E.label??E.headerTitle,K=Object.entries(E.description||{}).length>0,ie=Zj(E.description),se=(D=(F=e.data)==null?void 0:F.config)==null?void 0:D.icon,te=(B=(W=e.data)==null?void 0:W.config)==null?void 0:B.content,me=((le=E==null?void 0:E.viewProps)==null?void 0:le.borderRadius)??"53px",ve=In(E==null?void 0:E.viewProps,$.hexborderColor,O,Jj);return f.jsx(V.Flex,{justifyContent:"space-between",...E==null?void 0:E.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:me,overflow:"hidden",alignItems:"center",style:{backgroundColor:$.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:"100%",minW:m||e.onShowIcon?ie+Kv+ve.borderWidth*2:void 0,...ve,children:f.jsxs(V.Flex,{width:"100%",direction:"column",borderRadius:me,borderColor:$.hexborderColor,borderWidth:0,overflow:"hidden",children:[f.jsx(Xj,{headerTitle:I,hasContent:m,data:E,icon:se,colors:$,hasConfig:K,id:P,isActive:O,isHovered:A,isEditing:R,onSelect:M,onEditStart:T,onEditEnd:N,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:v}),m&&!o?f.jsx(V.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:$.highlightColor,p:["html","jsx"].includes((ce=(Y=e.data)==null?void 0:Y.config)==null?void 0:ce.contentFormat)?0:12,fontSize:"5xl",lineHeight:"normal",children:f.jsx(Wj,{nodeId:P,content:te,format:(xe=(ue=e.data)==null?void 0:ue.config)==null?void 0:xe.contentFormat,color:((Ce=E==null?void 0:E.viewProps)==null?void 0:Ce.textColor)||$.hextextColor})}):f.jsx(Yj,{data:E,resourcePorts:a,inspecting:s,form:c,inspectionPorts:d,extraPorts:u,colors:$,direction:n,uniformKeyWidth:ie})]})})}})};cu.displayName="NodeJsonObjectView";const Jv=e=>{var h,p,m,y,g,v,b,x,w,C,S;const r=Dn(),[t,n]=_.useState(!1),o=r.getNodeViewMode(e.data.id)==="properties",i=j=>{n(j),r.setNodeViewMode(e.data.id,j?"properties":"default")},{callbacks:s,readOnly:a}=Ze(),c=(p=(h=e.data)==null?void 0:h.config)==null?void 0:p.parentContainer;au(e.data.id,o&&((y=(m=e.data)==null?void 0:m.config)==null?void 0:y.labelBelow)&&!c,()=>i(!1));const l=c?"Show parent":"Show properties",d=c||((v=(g=e.data)==null?void 0:g.config)==null?void 0:v.form)||((w=(x=(b=e.data)==null?void 0:b.config)==null?void 0:x.ports)==null?void 0:w.length),u=d?()=>{var j;c?(j=s.onNodeCollapse)==null||j.call(s,e.data.id,!1):i(!0)}:void 0;return!c&&d&&o?f.jsx(cu,{...e,editOnMount:t,onShowIcon:()=>i(!1)}):f.jsx(su,{...e,onOpenView:u&&(c||(S=(C=e.data)==null?void 0:C.config)!=null&&S.labelBelow)?()=>{var j;u(),(j=s.onNodeViewToggle)==null||j.call(s,e.data.id)}:void 0,toggleLabel:l,toggleDisabled:c&&a,onExpand:u})};function e_(e){var v,b,x,w,C,S;const{config:r,callbacks:t,readOnly:n,selectedNodeIds:o,nodeRadiusPreviews:i,nodeViewModes:s,allNodesIconLabel:a}=Ze(),c=i[e.data.id]??((v=e.data.viewProps)==null?void 0:v.borderRadius),[l,d]=_.useState(!1),u=Dn(),{border:h,colorText:p}=at(),m=(b=r.customViews)==null?void 0:b.gridContent,y=(s[e.data.id]??(a?"icon-label":"default"))==="icon-label",g=_.useRef(y);return y&&(g.current=!0),au(e.data.id,a&&!y&&g.current,()=>u.setNodeViewMode(e.data.id,"icon-label")),y?f.jsx(V.Box,{"data-grid-document":((x=e.data.config)==null?void 0:x.documentId)??"",children:f.jsx(su,{...e,data:{...e.data,viewProps:{...e.data.viewProps,borderRadius:c},config:{...e.data.config,labelBelow:!0,icon:((w=e.data.config)==null?void 0:w.icon)||"PiGridFour"}},toggleLabel:"Show grid",onExpand:()=>u.restoreNodeView(e.data.id)})}):f.jsxs(f.Fragment,{children:[f.jsx(Bn,{...e,onOpenView:()=>d(!0),children:({data:j,isActive:P})=>{var E,O,A,R,M,T,N,$;return f.jsx(V.Box,{"data-flow-node-surface":"","data-grid-document":((E=j.config)==null?void 0:E.documentId)??"",width:`${((A=(O=j.config)==null?void 0:O.gridSize)==null?void 0:A.width)??600}px`,height:`${((M=(R=j.config)==null?void 0:R.gridSize)==null?void 0:M.height)??440}px`,overflow:"hidden",position:"relative",bg:((T=j.viewProps)==null?void 0:T.bgColor)??"transparent",color:((N=j.viewProps)==null?void 0:N.textColor)??p,borderRadius:`${c??0}px`,...In(j.viewProps,Ae((($=j.viewProps)==null?void 0:$.borderColor)??h),P,0),children:m?f.jsx(m,{...e}):f.jsx(V.Box,{p:4,children:j.label??"Grid"})})}}),f.jsx(iu,{nodeAddress:e.data.id,active:o.includes(e.data.id),label:e.data.label??"Grid",open:l&&!n,onClose:()=>d(!1),children:f.jsx(Mt.Provider,{value:{data:{metadata:{label:e.data.label??"",subtitle:((C=e.data.config)==null?void 0:C.subtitle)??"",icon:((S=e.data.config)==null?void 0:S.icon)??"PiGridFour"}},bindings:{[e.data.id]:{address:"root.metadata",type:"GridMetadata"}},schema:{GridMetadata:{kind:"object",properties:{label:{optional:!0,type:{kind:"string"}},subtitle:{optional:!0,type:{kind:"string"}},icon:{optional:!0,type:{kind:"string"}}}}},editable:!!r.editable&&!n,callbacks:{onFormChange:j=>{var E,O,A;if(n||!r.editable)return;const P=String(j.value??"");j.address==="root.metadata.label"?(E=t.onNodeLabelChange)==null||E.call(t,e.data.id,P):j.address==="root.metadata.subtitle"?(O=t.onNodeSubtitleChange)==null||O.call(t,e.data.id,P):j.address==="root.metadata.icon"&&((A=t.onNodeIconChange)==null||A.call(t,e.data.id,P))}}},children:f.jsx(Md,{nodeAddress:e.data.id})})})]})}const Zv=e=>f.jsx(Jv,{...e,renderCompact:Bj}),Xv=e=>f.jsx(Jv,{...e}),Yv=({containerStyle:e,...r})=>{const{selectedNodeIds:t}=Ze();return f.jsx(Bn,{...r,editOnMount:t.includes(r.data.id),children:n=>f.jsx(V.Box,{bg:e.textColor==="transparent"?"transparent":e.labelBg,p:`${e.fontSize/5}px`,fontFamily:dr,lineHeight:1,w:"fit-content",children:f.jsx(Hr,{nodeId:n.id,label:n.data.label??n.data.headerTitle??"Container",color:e.textColor,fontSize:`${e.fontSize}px`,isEditing:n.isEditing,onEditStart:n.onEditStart,onEditEnd:n.onEditEnd})})})};Zv.displayName="text";Xv.displayName="arrayView";Yv.displayName="ParentContainerView";const t_={grid:e_,objectView:cu,arrayView:Xv,text:Zv,parentContainer:Yv},r_=({children:e,pattern:r="dot",backgroundColor:t})=>{const{colorMode:n}=Ze(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",s=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return r==="none"?f.jsx(V.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:t,children:e}):f.jsxs(V.Box,{"data-flow-background":r,position:"relative",width:"100%",height:"100%",padding:0,bg:t,children:[f.jsx(V.Box,{position:"absolute",top:0,left:0,right:0,bottom:0,width:"100%",height:"100%",zIndex:0,pointerEvents:"none",style:{backgroundImage:r==="dot"?`radial-gradient(var(${i}) 8%, transparent 8%)`:r==="steel"?`repeating-linear-gradient(45deg, var(${s}) 0, var(${s}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${s}) 1px, transparent 1px), linear-gradient(90deg, var(${s}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),f.jsx(V.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},n_=.4,wr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},o_=({nodes:e,edges:r})=>{var Fe;const{themeColor:t,spacing:n,edgeRadius:o,backgroundVariant:i,backgroundSelected:s,setBackgroundSelected:a,edgeColor:c,direction:l,nodeAlignment:d,edgeMode:u,compactPropertyLayout:h,workflowContract:p,parentNodeStyle:m,engineRef:y,callbacks:g,config:v,selectedNodeIds:b,setSelectedNodeIds:x,selectedEdgeId:w,setSelectedEdgeId:C,setIsPerformanceMode:S,setNodeGridOptions:j,fillRadiusEditedIds:P,isZoomMode:E,setIsZoomMode:O,isMultiSelectMode:A,setIsMultiSelectMode:R,isDragMode:M,setIsDragMode:T,isEdgeHandlesEnabled:N,setIsEdgeHandlesEnabled:$,isArrayNodeMode:I}=Ze(),K=_.useRef(null),[ie,se]=_.useState(null),te=_.useRef(null),me=e.length>200;_.useEffect(()=>{S(me)},[me,S]);const{edgeSep:ve,rankSep:F,spacingFactor:D}=_.useMemo(()=>{const re=Nw(e.length),G=v.nodeGridSpacing==="layout"&&n<.5?n*1.3:n<1?.3+.7*n:.5+.5*n;return{edgeSep:re.edgeSep*G,rankSep:re.rankSep*G,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n,v.nodeGridSpacing]),{bgColor:W}=Tn(t),{canvas:B,borderSecondary:le,colorText:Y}=at(),ce=i==="transparent"?"transparent":v.backgroundColor||B,ue=_.useCallback(re=>{if(!re)return Ae(t);switch(re){case"dark":return Ae(ce);case"light":return Ae(le);default:return Ae(re)}},[t,ce,le]),xe=v.colorMode==="dark",Ce=xe?Ae("gray.500"):Kr,ye=xe?W!=null&&W.includes("gray")?"whitesmoke":ue(W):Ce,pe=c?ue(c):Ce,X=_.useMemo(()=>{var re;return v.initialViewport||{pan:{x:0,y:0},zoom:(re=v.nodeGrid)!=null&&re.enabled&&v.nodeGrid.options.fill?1:.01}},[]),L=l==="C"?"LR":l,ae=_.useCallback(re=>{const G={...m,...re};return{...G,bgColor:G.bgColor||t,bgOpacity:G.outline?0:G.bgOpacity??n_}},[m,t]),H=_.useMemo(()=>{var G;const re=new Map;for(const ne of e)(G=ne.data)!=null&&G.id&&re.set(ne.data.id,ne);return re},[e]),fe=_.useMemo(()=>{var G;const re=new Map;for(const ne of r)(G=ne.data)!=null&&G.id&&re.set(ne.data.id,ne);return re},[r]),be=_.useCallback(re=>{var U;const G=(U=H.get(re))==null?void 0:U.data,ne=ae(G==null?void 0:G.viewProps),$e=Ae(ne.bgColor);return{animated:!!(G!=null&&G.isNodeAnimated)&&!me,animationVariant:G==null?void 0:G.nodeAnimationVariant,animationColor:Ae(ne.borderColor||t),bgColor:ne.outline?"transparent":$e,bgOpacity:ne.bgOpacity,borderColor:ne.borderColor?Ae(ne.borderColor):ne.outline&&ne.bgColor==="transparent"?Ae(t):$e,borderWidth:Pn(ne.borderWidth,wr.borderWidth),borderStyle:ne.borderStyle??wr.borderStyle,borderRadius:ne.borderRadius??wr.borderRadius,textColor:ne.textColor?Ae(ne.textColor):ne.outline||ne.bgColor==="transparent"?Ae(Y):$e,fontSize:ne.fontSize??wr.fontSize,labelPosition:ne.labelPosition??wr.labelPosition,labelMargin:wr.labelMargin,labelBg:vu(ue("dark"),$e,ne.bgOpacity)??ue("dark"),padding:ne.padding??wr.padding}},[ae,H,Y,t,me,ue]),Ne=_.useMemo(()=>{var ne,$e;const re=new Map;for(const U of r){const he=(ne=U.data)==null?void 0:ne.source,Se=($e=U.data)==null?void 0:$e.target;if(!he||!Se||he===Se)continue;const _e=he<Se?`${he}|${Se}`:`${Se}|${he}`,Xe=re.get(_e);Xe?Xe.push({id:U.data.id,source:he}):re.set(_e,[{id:U.data.id,source:he}])}const G=new Map;for(const[U,he]of re){if(he.length<2)continue;const Se=U.split("|")[0],_e=Math.min(20,70/he.length);he.forEach(({id:Xe,source:Qe},He)=>{const kt=50+(He-(he.length-1)/2)*_e;G.set(Xe,(Qe===Se?kt:100-kt)/100)})}return G},[r]),Le=_.useMemo(()=>{const re=ue("dark");return r.filter(G=>{var ne;return((ne=G.data)==null?void 0:ne.id)&&G.data.source&&G.data.target}).map(({data:G})=>{var he,Se,_e,Xe,Qe,He;let ne=re;const $e=(Se=(he=H.get(G.source))==null?void 0:he.data)==null?void 0:Se.parent,U=(Xe=(_e=H.get(G.target))==null?void 0:_e.data)==null?void 0:Xe.parent;if($e&&$e===U){const kt=ae((He=(Qe=H.get($e))==null?void 0:Qe.data)==null?void 0:He.viewProps),St=vu(re,Ae(kt.bgColor),kt.bgOpacity);St&&(ne=St)}return{id:G.id,data:G,type:G.type??v.edgeType??"rounded-orthogonal",source:G.source,target:G.target,sourceProperty:G.sourceProperty,targetProperty:G.targetProperty,label:G.label,validationIssue:(u==="auto"||u==="properties")&&(G.sourceProperty!==void 0||G.targetProperty!==void 0)&&p?Pd(p,G):void 0,color:c?pe:G.color?Ae(G.color):pe,connectorColor:c?pe:G.color?Ae(G.color):ye,labelBg:ne,dashed:!!G.isEdgeDashed,animated:!!G.isEdgeAnimated,inverted:!!G.isInverted,turn:Ne.get(G.id)??.5}})},[r,pe,ye,c,Ne,v.edgeType,u,p,H,ae,ue]),Be=_.useMemo(()=>{var G;const re=new Set;for(const ne of e)(G=ne.data)!=null&&G.parent&&re.add(ne.data.parent);return re},[e]),tt=_.useMemo(()=>{const re=new Map;for(const G of r){const ne=G.data.isInverted?G.data.target:G.data.source;ne&&!re.has(ne)&&re.set(ne,G.data)}for(const G of r){if(G.data.connection)continue;const ne=G.data.isInverted?G.data.target:G.data.source,$e=G.data.isInverted?G.data.source:G.data.target;$e.startsWith(`${ne}.`)&&(re.set(ne,G.data),re.set($e,G.data))}return re},[r]),Je=_.useMemo(()=>{const re={...t_,...v.customViews};return e.filter(G=>{var ne;return(ne=G.data)==null?void 0:ne.id}).map(G=>{var _e,Xe,Qe,He,kt,St;const ne=Be.has(G.data.id)&&!G.data.parent,$e=ne?G.data.label??G.data.headerTitle??"Container":void 0,U=ne?re.parentContainer:re[G.data.type]||re.text,he=tt.get(G.data.id),Se={...G,isInverted:((_e=G.data.config)==null?void 0:_e.isInverted)??(he==null?void 0:he.isInverted),isParent:ne,containerStyle:ne?be(G.data.id):void 0};return{id:G.data.id,collapsed:(Xe=G.data.config)==null?void 0:Xe.collapsed,parent:G.data.parent,acceptsChildren:!!((Qe=G.data.config)!=null&&Qe.parentContainer)||Be.has(G.data.id),label:$e,animated:!!G.data.isNodeAnimated,animationVariant:G.data.nodeAnimationVariant,hasCollapseControl:((He=G.data.config)==null?void 0:He.collapsed)!==void 0,animationColor:Ae(((kt=G.data.viewProps)==null?void 0:kt.borderColor)||t),animationWidth:Pn((St=G.data.viewProps)==null?void 0:St.borderWidth,8),element:_.createElement(U,{...Se,key:`${G.data.id}-${t}`}),fillElement:P.has(G.data.id)?void 0:_.createElement(U,{...Se,data:{...G.data,viewProps:{...G.data.viewProps,borderRadius:0}},containerStyle:Se.containerStyle?{...Se.containerStyle,borderRadius:0}:void 0,key:`${G.data.id}-${t}`})}})},[e,Be,tt,t,v.customViews,be,P]),yt=_.useMemo(()=>me?300:e.length>50?150:e.length>20?100:50,[e.length,me]),Ye=_.useRef(v);Ye.current=v;const nt=_.useRef(E);nt.current=E;const ht=_.useRef(I);ht.current=I;const Te=_.useRef(b);Te.current=b;const Ve=_.useRef(w);Ve.current=w;const st=_.useRef(A);st.current=A;const ct=_.useRef(H);ct.current=H;const zt=_.useRef(fe);zt.current=fe;const Ge=_.useRef(new Map);_.useEffect(()=>{var ne,$e;const re=new Map([...fe].filter(([,U])=>H.has(U.data.source)&&H.has(U.data.target))),G=Ge.current;Ge.current=re;for(const[U,he]of G)re.has(U)||(Ve.current===U&&(C(null),(ne=g.onEdgeDeselect)==null||ne.call(g)),($e=g.onEdgeRemove)==null||$e.call(g,U,he.data))},[fe,H,g,C]),_.useEffect(()=>{const re=K.current;if(!ie||!re)return;let G=null,ne=null,$e=0,U=0,he=0,Se=0,_e=0;const Xe=Qe=>{if(Ye.current.readOnly)return;const He=re.ownerDocument.fullscreenElement;if(He&&He!==re&&re.contains(He)&&Qe.target instanceof Node&&He.contains(Qe.target))return;Qe.preventDefault(),Qe.stopPropagation(),nt.current||Qe.metaKey||Qe.ctrlKey?(he+=Qe.deltaY,Se=Qe.clientX,_e=Qe.clientY,ne===null&&(ne=requestAnimationFrame(()=>{ne=null;const St=Ye.current,mt=ie.zoom(),ft=he;he=0;let vt=mt-ft*.05/100;vt=Math.max(St.minZoom??.01,Math.min(St.maxZoom??1.5,vt));const Tt=re.getBoundingClientRect();ie.zoomAt(vt,{x:Se-Tt.left,y:_e-Tt.top})}))):($e+=Qe.deltaX,U+=Qe.deltaY,G===null&&(G=requestAnimationFrame(()=>{G=null;const St=ie.pan(),mt=ie.zoom(),ft=.35,vt=$e,Tt=U;$e=0,U=0,ie.pan({x:St.x+-vt*ft/mt,y:St.y+-Tt*ft/mt})})))};return re.addEventListener("wheel",Xe,{passive:!1}),()=>{re.removeEventListener("wheel",Xe),G!==null&&cancelAnimationFrame(G),ne!==null&&cancelAnimationFrame(ne)}},[ie]),_.useEffect(()=>{if(v.disableKeyboardShortcuts)return;const re=G=>{var $e,U,he,Se;if(Ye.current.readOnly)return;const ne=G.target;if(!(ne.tagName==="INPUT"||ne.tagName==="TEXTAREA"||ne.isContentEditable)){if((G.key==="z"||G.key==="Z")&&O(!nt.current),(G.key==="m"||G.key==="M")&&R(!A),(G.key==="d"||G.key==="D")&&T(!M),(G.key==="v"||G.key==="V")&&!G.repeat&&!G.metaKey&&!G.ctrlKey&&!G.altKey&&ne.tagName!=="SELECT"&&$(!N),(G.key==="Delete"||G.key==="Backspace")&&Ve.current){G.preventDefault();const _e=Ve.current;(U=g.onEdgeDelete)==null||U.call(g,_e,(($e=zt.current.get(_e))==null?void 0:$e.data)??{id:_e}),C(null);return}if((G.key==="Delete"||G.key==="Backspace")&&Te.current.length>0){G.preventDefault();const _e=Te.current.filter(Xe=>Xe!=="root");if(_e.length===0)return;for(const Xe of _e){const Qe=(he=ct.current.get(Xe))==null?void 0:he.data;(Se=g.onNodeDelete)==null||Se.call(g,Xe,Qe||{})}x([])}}};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[A,M,N,$,O,R,T,v.disableKeyboardShortcuts,g,x,C]);const De=_.useCallback(re=>{var G;y.current=re,se(re),(G=g.onInit)==null||G.call(g,re)},[y,g]),Wt=_.useCallback(re=>{var G;return(G=g.onViewportChange)==null?void 0:G.call(g,re)},[g]),lt=_.useCallback(re=>{var ne,$e,U;const G=((ne=zt.current.get(re))==null?void 0:ne.data)??{id:re};if(Ve.current===re&&st.current){C(null),($e=g.onEdgeDeselect)==null||$e.call(g);return}Te.current.length&&x([]),C(re),(U=g.onEdgeSelect)==null||U.call(g,re,G)},[g,C,x]),nr=_.useCallback(()=>{var re,G,ne,$e,U;if(a(v.bottomBarCollapsed??(Te.current.length>0||!!Ve.current||!s)),(re=g.onBackgroundClick)==null||re.call(g),!Ye.current.readOnly){const he=new Set;for(const Se of Te.current){let _e=ct.current.get(Se);for(;_e&&!he.has(_e.data.id);)he.add(_e.data.id),Be.has(_e.data.id)&&((G=_e.data.config)==null?void 0:G.collapsed)!==!0&&((ne=g.onNodeCollapse)==null||ne.call(g,_e.data.id,!0)),_e=_e.data.parent?ct.current.get(_e.data.parent):void 0}}Te.current.length&&(x([]),($e=g.onNodeDeselect)==null||$e.call(g)),Ve.current&&(C(null),(U=g.onEdgeDeselect)==null||U.call(g))},[g,x,C,a,s,v.bottomBarCollapsed,Be]),Ut=_.useCallback(re=>{var $e,U;const G=Te.current,ne=re.filter(he=>!G.includes(he));if(ne.length){x([...G,...ne]);for(const he of ne)(U=g.onNodeSelect)==null||U.call(g,he,(($e=ct.current.get(he))==null?void 0:$e.data)??{id:he})}},[g,x]),Mr=_.useCallback((re,G)=>{var ne,$e;x([re]),($e=g.onNodeSelect)==null||$e.call(g,re,((ne=ct.current.get(re))==null?void 0:ne.data)??{id:re},G)},[g,x]),Et=_.useRef(null),Ht=_.useCallback((re,G,ne)=>{var $e;Et.current={source:re,target:G,edgeIds:new Set(zt.current.keys())};try{($e=g.onEdgeCreate)==null||$e.call(g,re,G,ne)}catch(U){throw Et.current=null,U}},[g]),Yt=_.useCallback((re,G,ne,$e=!1)=>{var U,he;if(te.current={sourceId:re,nodeIds:new Set(ct.current.keys()),reverse:$e},!(u==="properties"&&((U=g.onNodeCreateRequest)==null?void 0:U.call(g,{sourceNodeId:re,position:G,sourceProperty:ne,reverse:$e}))===!0)){if(ne!==void 0||$e){te.current=null;return}(he=g.onNodeCreate)==null||he.call(g,{type:"text",sourceNodeId:re,position:G,isArrayMode:ht.current})}},[g,u]),Tr=!v.readOnly&&N&&v.edgeHandles!==!1,br=i==="transparent"?"none":i;return f.jsx(r_,{pattern:br,backgroundColor:ce,children:f.jsx(V.Box,{ref:K,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:f.jsx(qj,{nodes:Je,edges:Le,direction:L,nodeAlignment:d,onContainerCollapse:re=>{var G,ne;(G=g.onNodeCollapse)==null||G.call(g,re,!0),(ne=g.onNodeViewToggle)==null||ne.call(g,re)},selectedNodeIds:b,edgeMode:u,compactPropertyLayout:h,edgeType:v.edgeType,edgeRadius:o,customEdgeTypes:v.customEdgeTypes,edgeReveal:v.disableAnimations?void 0:v.edgeReveal,rankSep:F,edgeSep:ve,nodeGridSpacing:v.nodeGridSpacing,nodeGridConnections:v.nodeGridConnections,initialNodeGrid:v.nodeGrid,spacingFactor:D,compactSpacingScale:n,layoutDebounce:yt,isPerformanceMode:me,minZoom:v.minZoom??.01,maxZoom:v.maxZoom??1.5,initialViewport:X,fitOnInit:!v.initialViewport&&!((Fe=v.nodeGrid)!=null&&Fe.enabled&&v.nodeGrid.options.fill),readOnly:!!v.readOnly,containerStyle:be,lineColor:c?pe:ye,drawMode:Tr,drawHandles:!v.readOnly&&v.edgeHandles!==!1,dragMode:M,multiSelect:!!A,onInit:De,onLayoutComplete:re=>{var he;(he=g.onLayoutComplete)==null||he.call(g,re);const G=Et.current;G&&(!ct.current.has(G.source)||!ct.current.has(G.target)?Et.current=null:r.some(({data:Se})=>Se.source===G.source&&Se.target===G.target&&!G.edgeIds.has(Se.id))&&re.getNodeBox(G.source)&&re.getNodeBox(G.target)&&(Et.current=null,re.focusConnections(G.source)));const ne=te.current;if(!ne)return;if(!ct.current.has(ne.sourceId)){te.current=null;return}const U=e.filter(Se=>!ne.nodeIds.has(Se.data.id)).filter(Se=>r.some(({data:_e})=>_e.source===ne.sourceId&&_e.target===Se.data.id||_e.target===ne.sourceId&&_e.source===Se.data.id));!U.length||U.some(Se=>!re.getNodeBox(Se.data.id))||(te.current=null,re.focusBranch(ne.reverse?U[0].data.id:ne.sourceId))},onNodeGridModeChange:j,onNodeGridZoomOut:g.onNodeGridZoomOut,onNodeGridDrop:g.onNodeGridDrop,onNodeParentChange:g.onNodeParentChange,animateViewport:v.animateViewport,disableAnimations:v.disableAnimations,onViewportChange:Wt,onBackgroundTap:nr,onBoxSelect:Ut,onEdgeSelect:lt,onContainerSelect:Mr,onEdgeDraw:Ht,onDrawIntoSpace:Yt})})})},Qv=_.memo(o_),i_=".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 xm=!1;function a_(){if(xm||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=i_+".flow-sdk-canvas[data-node-grid] .flow-sdk-node,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *::before,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *::after{animation:none!important;transition:none!important}.flow-sdk-node[data-grid-fill] [data-flow-icon-label]{--flow-grid-caption-color:var(--flow-grid-on-surface-color)}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]{border:0;outline:none;box-shadow:none}.flow-sdk-node[data-grid-fill]{box-sizing:border-box}.flow-sdk-node[data-grid-fill] :not(svg):has([data-flow-node-surface]),.flow-sdk-node[data-grid-fill]>:not(svg):not(button){width:100%;height:100%;min-width:0;max-width:none}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]{width:100%;height:100%;min-width:0;max-width:none;box-sizing:border-box;overflow:hidden}.flow-sdk-node[data-grid-fill] [data-flow-icon-label]{gap:0}.flow-sdk-node[data-grid-fill] [data-flow-icon-caption]{position:absolute;bottom:12px;left:12px;width:calc(100% - 24px);max-height:40%;overflow:hidden}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]>svg{max-width:45%;max-height:55%}.flow-sdk-node[data-grid-fill] p{font-size:var(--flow-grid-font);white-space:normal;overflow-wrap:anywhere}.flow-sdk-canvas[data-node-grid]:not([data-grid-connections]) .flow-sdk-property-port,.flow-sdk-canvas[data-node-grid]:not([data-grid-connections]) .flow-sdk-handle,.flow-sdk-canvas[data-node-grid] [data-flow-collapse-control]{display:none}.flow-sdk-node[data-grid-draggable] :not(button):not(input):not(textarea):not(select):not(a){cursor:inherit}"+Ib+Tw+Iw+".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}',xm=!0}function s_({loading:e=!1,loader:r,...t}){var c,l;const[n,o]=_.useState(null),i=_.useMemo(()=>!!(n!=null&&n.json)&&!!t.json&&Rw(n.json,t.json),[n==null?void 0:n.json,t.json]),s=n===null||n.json!==t.json&&!i,a=e||s;return _.useEffect(()=>{!e&&i&&(n==null?void 0:n.json)!==t.json&&o(t)},[e,i,n==null?void 0:n.json,t.json]),_.useEffect(()=>{if(e||!s)return;let d;const u=requestAnimationFrame(()=>{d=requestAnimationFrame(()=>o(t))});return()=>{cancelAnimationFrame(u),d!==void 0&&cancelAnimationFrame(d)}},[e,s,t.json]),f.jsxs(V.Box,{className:t.className,style:t.style,width:"100%",height:"100%",position:"relative","aria-busy":a,children:[f.jsx("div",{style:{width:"100%",height:"100%"},ref:d=>{a?d==null||d.setAttribute("inert",""):d==null||d.removeAttribute("inert")},children:n&&f.jsx(c_,{...s?n:t,children:t.children,config:t.config,className:void 0,style:void 0})}),a&&r!==null&&f.jsx(V.Box,{"data-flow-loader":"",role:"status","aria-label":"Loading diagram",position:"absolute",inset:0,zIndex:1e3,display:"grid",placeItems:"center",background:((c=t.config)==null?void 0:c.colorMode)==="dark"?"gray.800":"gray.100",color:((l=t.config)==null?void 0:l.colorMode)==="dark"?"whiteAlpha.800":"blackAlpha.800",children:r===void 0?f.jsx("span",{children:"Loading diagram..."}):r})]})}function c_({title:e="untitled",json:r,forms:t,nodes:n,edges:o,config:i={},callbacks:s={},className:a,style:c,showBottomBar:l=!0,children:d}){a_();const[u,h]=_.useState(),[p,m]=_.useState(!1),y=i.formSchema??u,g=_.useMemo(()=>r&&t?lb(r,t.state):r,[r,t==null?void 0:t.state]),v=i.direction==="C",b=_.useMemo(()=>{let A,R;return M=>(R=A&&R?Aw(A,M,R)??ud(M,{title:e,isCenter:v}):ud(M,{title:e,isCenter:v}),A=M,R)},[e,v]),x=_.useMemo(()=>g?b(g):null,[g,b]),w=_.useMemo(()=>t!=null&&t.structured&&!p&&y?db(t.state,t.bindings,y,(x==null?void 0:x.nodes)??n??[]):void 0,[t==null?void 0:t.structured,p,t==null?void 0:t.state,t==null?void 0:t.bindings,y,x,n]),C=(w==null?void 0:w.schema)??y,S=(w==null?void 0:w.bindings)??(t==null?void 0:t.bindings),j=_.useMemo(()=>[...(x==null?void 0:x.nodes)??n??[],...(w==null?void 0:w.nodes)??[]].map(R=>{var ie,se,te,me;const M=r?(ie=qe(r,R.data.id))==null?void 0:ie.$view:(se=R.data.config)==null?void 0:se.typeView,T=M&&vd.includes(M)?M:void 0,N=T?T==="icon-label":(te=R.data.config)==null?void 0:te.labelBelow,$=T==="object"?"objectView":T==="text"?"text":N?"arrayView":R.data.type,I=C&&(t?On(S,R.data.id,C):r&&Zr(r,R.data.id,C)),K=(((me=R.data.config)==null?void 0:me.ports)??[]).map(ve=>({...ve}));if(w&&I){const ve=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[F,D]of Object.entries(I.type.ports??{})){const W=`${D.kind}:${F}`,B=K.find(le=>le.id===W);B?B.label===void 0&&D.label!==void 0&&(B.label=D.label):K.push({id:W,...D.label!==void 0?{label:D.label}:{},role:D.kind==="input"||D.kind==="config"?"target":"source",side:ve[D.kind],...D.kind==="config"?{placement:"config"}:{}})}for(const F of K){const D=K.filter(W=>W.side===F.side);F.position=(D.indexOf(F)+1)/(D.length+1)}}return I||N||T?{...R,data:{...R.data,type:$,...t?{description:Object.fromEntries(Object.entries(R.data.description??{}).filter(([ve])=>!ve.startsWith("$")&&!(w!=null&&w.slots.has(hn(R.data.id,ve)))))}:{},config:{...R.data.config,...w&&I?{ports:K}:{},...I?{form:!0}:{},...T?{typeView:T,labelBelow:!!N}:N?{labelBelow:!0}:{}}}}:R}),[x,n,r,C,S,w,i.direction]),P=_.useMemo(()=>[...(x==null?void 0:x.edges)??o??[],...(w==null?void 0:w.edges)??[]],[x==null?void 0:x.edges,o,w==null?void 0:w.edges]),E=_.useMemo(()=>{const A=r&&x?Pb(r,x.edges,s,s.onJsonChange,y):{...s};if(w){const R=new Set([...w.nodes.map(M=>M.data.id),...w.edges.map(M=>M.data.id)]);for(const M of Object.keys(A)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(M))continue;const T=A[M];A[M]=(N,...$)=>{if(!R.has(N))return T==null?void 0:T(N,...$)}}}return{...A,onAllNodesIconLabelChange:R=>{var M;m(R),(M=A.onAllNodesIconLabelChange)==null||M.call(A,R)}}},[r,x,s,y,w]),O=_.useMemo(()=>{if(!t)return E;let A=t.state;const R=T=>{if(i.readOnly||i.editable===!1)return;const N=t.onStateChange??t.onChange;if(!N)return;const $=yw(A,T,s.onFormChange);$!==A&&(A=$,N($,{...T,data:$}))},M=(T,N,$)=>{var K;const I=r&&((K=qe(r,T))==null?void 0:K[N]);return!I||typeof I.$state!="string"?!1:(R({address:I.$state,nodeAddress:T,previousValue:qe(A,I.$state),value:$,data:A}),!0)};return{...E,onFormChange:R,onNodeCreateRequest:T=>{var I,K;const N=(I=T.sourceProperty)!=null&&I.startsWith("config:")?T.sourceProperty.slice(7):void 0,$=N!==void 0&&(w==null?void 0:w.slots.get(hn(T.sourceNodeId,N)));return $?($.present||R({data:A,nodeAddress:$.address.split(".").slice(0,-1).join("."),address:$.address,value:pn($.type),previousValue:void 0}),!0):((K=E.onNodeCreateRequest)==null?void 0:K.call(E,T))??!1},onNodeDelete:(T,N)=>{var te,me;if(!(w!=null&&w.nodes.some(ve=>ve.data.id===T)))return(te=E.onNodeDelete)==null?void 0:te.call(E,T,N);const $=w&&[...w.slots.values()].find(ve=>ve.nodeId===T);if(!$)return(me=E.onNodeDelete)==null?void 0:me.call(E,T,N);const I=$.address.split("."),K=I.pop(),ie=I.join("."),se=qe(A,ie);R(Array.isArray(se)?{data:A,nodeAddress:ie,address:ie,previousValue:se,value:se.filter((ve,F)=>String(F)!==K)}:{data:A,nodeAddress:ie,address:$.address,previousValue:qe(A,$.address),value:void 0})},onEdgeCreate:(T,N,$)=>{var ie,se;const I=((ie=$==null?void 0:$.targetProperty)==null?void 0:ie.startsWith("config:"))&&(w==null?void 0:w.slots.get(hn(N,$.targetProperty.slice(7)))),K=w==null?void 0:w.containers.get(T);if(I&&K&&($==null?void 0:$.sourceProperty)==="output:resource"){const te=vw(A,K,I);te!==void 0&&R({data:A,nodeAddress:I.address.split(".").slice(0,-1).join("."),address:I.address,previousValue:qe(A,I.address),value:te});return}I||w!=null&&w.nodes.some(te=>te.data.id===T||te.data.id===N)||(se=E.onEdgeCreate)==null||se.call(E,T,N,$)},onEdgeDelete:(T,N)=>{var me;const $=w==null?void 0:w.edges.find(ve=>ve.data.id===T);if(!$)return(me=E.onEdgeDelete)==null?void 0:me.call(E,T,N);const I=w.slots.get(hn($.data.target,$.data.targetProperty.slice(7))),K=I.address.split("."),ie=K.pop(),se=K.join("."),te=qe(A,se);R(Array.isArray(te)?{data:A,nodeAddress:se,address:se,previousValue:te,value:te.filter((ve,F)=>String(F)!==ie)}:{data:A,nodeAddress:se,address:I.address,previousValue:qe(A,I.address),value:void 0})},onNodeContentChange:(T,N)=>{var $,I;M(T,"$content",N)?($=s.onNodeContentChange)==null||$.call(s,T,N):(I=E.onNodeContentChange)==null||I.call(E,T,N)},onNodeLabelChange:(T,N)=>{var $,I;M(T,"$label",N)?($=s.onNodeLabelChange)==null||$.call(s,T,N):(I=E.onNodeLabelChange)==null||I.call(E,T,N)}}},[E,t,r,s,w,i.readOnly,i.editable]);return f.jsx(Mt.Provider,{value:{data:(t==null?void 0:t.state)??r,viewData:r,bindings:S,references:t==null?void 0:t.references,structured:w,renderForm:t==null?void 0:t.renderForm,editable:t?!!(t.onStateChange??t.onChange):!!s.onJsonChange,schema:C,setSchema:A=>{var R;h(A),(R=s.onFormSchemaChange)==null||R.call(s,A)},callbacks:O},children:f.jsx(Rm,{config:w?{...i,formSchema:C}:i,callbacks:O,nodes:j,edges:P,children:f.jsxs(V.Box,{className:a,"data-flow-diagram":"","data-animations-disabled":i.disableAnimations||void 0,style:c,width:"100%",height:"100%",position:"relative",overflow:"hidden",css:{"&[data-animations-disabled], &[data-animations-disabled] *, &[data-animations-disabled] *::before, &[data-animations-disabled] *::after":{animation:"none !important",transition:"none !important"},"& input, & textarea, & select":{outline:"none !important",boxShadow:"none !important"}},children:[f.jsx(Qv,{nodes:j,edges:P}),l&&f.jsx(jb,{}),d]})})})}function l_(e){return bd(JSON.parse(e))}function bd(e){if(!e||typeof e!="object")throw new Error("Expected a JSON object or array.");const r=new Set,t=n=>{if(!(n===null||typeof n=="string"||typeof n=="boolean")&&!(typeof n=="number"&&Number.isFinite(n))){if(!n||typeof n!="object"||r.has(n)||!Array.isArray(n)&&![Object.prototype,null].includes(Object.getPrototypeOf(n)))throw new Error("Document must contain only finite, acyclic JSON values.");r.add(n);for(const[o,i]of Object.entries(n)){if(["__proto__","prototype","constructor"].includes(o))throw new Error(`Unsafe document key: ${o}`);t(i)}r.delete(n)}};return t(e),structuredClone(e)}function d_(e){return{replaceJson(r){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const t=bd(r);return e.onJsonChange(t,{type:"documentReplace",address:"root"}),t},replaceState(r){if(e.readOnly||!e.onStateChange)throw new Error("Form state is read-only.");const t=bd(r);return e.onStateChange(t,{address:"root",nodeAddress:"root",previousValue:e.state,value:t,data:t}),t}}}function u_(e,r){const t=(n,o)=>{if(n===null||typeof n!="object")return typeof n==typeof o?n:void 0;if(!(!o||typeof o!="object"))return Array.isArray(n)?Array.isArray(o)?n.map((i,s)=>t(i,o[s])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,s])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i==="$content"&&n.$contentFormat==="jsx"&&o.$contentFormat==="jsx"&&Array.isArray(s)&&Array.isArray(o[i]))return[[i,s.filter((c,l)=>JSON.stringify(c)===JSON.stringify(o[i][l]))]];if(i.startsWith("$")&&i!=="$")return JSON.stringify(s)===JSON.stringify(o[i])?[[i,s]]:[];const a=t(s,o[i]);return a===void 0?[]:[[i,a]]}))};return t(e,r)??{}}function Yn(e){let r="",t=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},s=()=>{if(i(),!(t||!r.trim()))try{const c=e.parse(e.repair(r)),l=JSON.stringify(c);if(l===n)return;e.preview(c),n=l}catch{}},a=c=>{if(!t){if(new TextEncoder().encode(c).byteLength>(e.maxBytes??1024*1024))throw t=!0,i(),new Error("JSON stream exceeds the size limit.");r=c,o||(o=setTimeout(s,e.intervalMs??150))}};return{snapshot:a,append(c){a(r+c)},flush:s,finish(){if(t)throw new Error("JSON stream is closed.");t=!0,i();const c=e.parse(r);return e.commit(c),c},cancel(){t=!0,i(),r=""}}}function f_(e){const{source:r}=e,t=e.tickMs??50,n=e.durationMs??8e3;if(!Number.isFinite(t)||t<=0||!Number.isFinite(n)||n<=0)throw new Error("Playback timing must be positive.");if(new TextEncoder().encode(r).byteLength>(e.maxBytes??1024*1024))throw new Error("JSON stream exceeds the size limit.");e.parse(r);let o=Yn(e),i=0,s=!1,a=!1,c;const l=Math.max(1,Math.ceil(r.length*t/n)),d=()=>e.onChange({position:i,total:r.length,playing:s}),u=()=>{clearTimeout(c),c=void 0},h=(y=!1)=>{o.snapshot(r.slice(0,i)),i===r.length?(s=!1,u(),o.finish()):y&&o.flush()},p=y=>{s=!1,u(),o.cancel(),d(),e.onError(y)},m=()=>{if(c=void 0,!(!s||a)){i=Math.min(r.length,i+l);try{h()}catch(y){p(y);return}d(),s&&(c=setTimeout(m,t))}};return{play(){a||s||(i===r.length&&(o.cancel(),o=Yn(e),i=0),s=!0,d(),c=setTimeout(m,t))},pause(){a||(s=!1,u(),o.flush(),d())},seek(y){if(!a){if(!Number.isFinite(y))throw new Error("Playback position must be finite.");u(),i=Math.max(0,Math.min(r.length,Math.round(y))),o.cancel(),o=Yn(e);try{h(!0)}catch(g){p(g);return}d(),s&&(c=setTimeout(m,t))}},dispose(){a=!0,s=!1,u(),o.cancel()}}}function h_({nodeAddress:e,expanded:r=!1}){var l;const{data:t,schema:n,bindings:o}=_.useContext(Mt),{colorText:i,background:s}=at();if((l=o==null?void 0:o[e])!=null&&l.portResources)return null;const a=o&&On(o,e,n);if(!t||!a)return null;const c=qe(t,a.address);return!c||typeof c!="object"?null:f.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:Ae(i),background:Ae(s),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(a.type.properties).map(d=>{const u=a.fields[d]??{};if(!uo(u.$visibleWhen,t))return null;const h=c[d],p=h==null?"":typeof h=="object"?JSON.stringify(h):String(h);return f.jsxs("div",{"data-flow-property":d,style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:12,padding:"10px 16px",borderTop:"1px solid color-mix(in srgb, currentColor 12%, transparent)"},children:[f.jsx("span",{style:{overflowWrap:"anywhere"},children:$t(u.$label??d)}),f.jsx("span",{title:p,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:r?"pre-wrap":"nowrap",overflowWrap:r?"anywhere":void 0},children:p})]},d)})})}exports.BottomBar=jb;exports.CompactPropertyLayoutToggle=Xm;exports.ConnectionsOnlyToggle=kw;exports.DEFAULT_PALETTE=to;exports.DiagramAppearanceControls=Ym;exports.DynamicIcon=Zt;exports.EdgeTools=yb;exports.EditableLabel=Hr;exports.ErrorToast=Cb;exports.FlowDiagram=s_;exports.FlowDiagramProvider=Rm;exports.FlowPort=Uv;exports.FlowView=Qv;exports.FormDocumentContext=Mt;exports.LIGHT_BLACK=Kr;exports.LoadingBorder=Hv;exports.NODE_TYPE_VIEWS=vd;exports.NodeBorderRadiusControl=mb;exports.NodeConfigSummary=h_;exports.NodeForm=Md;exports.NodeFormPopover=iu;exports.NodeIconPicker=Td;exports.NodeTools=bb;exports.NodeView=Bn;exports.SvgExportButton=wb;exports.Swatches=kr;exports.TEXT_PALETTE=pb;exports.ToolbarCloseButton=Jr;exports.ToolbarCommitInput=Br;exports.ToolbarDivider=bn;exports.ToolbarIconButton=Me;exports.ToolbarRangeInput=wd;exports.ToolbarScrollContainer=Od;exports.ToolbarSelect=Pt;exports.ToolbarTooltip=Ue;exports.TooltipIconButton=md;exports.WorkflowControls=Nd;exports.addChild=Ed;exports.addConnection=kd;exports.addTargetEdge=ib;exports.addressToPath=Bt;exports.applyCollapsed=hw;exports.applyFormChange=fo;exports.applyStateEdits=gw;exports.bindSqueedCallbacks=Pb;exports.compileSqueed=ud;exports.connectionIssue=Pd;exports.contentObjTheme=Jt;exports.copySelection=$d;exports.createFlowDiagram=Er;exports.createFlowDocumentActions=d_;exports.createFormNode=Eb;exports.createJsonPlayback=f_;exports.createJsonStream=Yn;exports.createWorkflowExecution=bx;exports.downloadSvg=xb;exports.duplicateSelection=Ab;exports.exportSvg=vb;exports.formValueError=Dt;exports.getChakraColorHex=Ae;exports.getColorVariant=jm;exports.getDarkerHexColor=Qn;exports.getInteractionSurface=fr;exports.getNode=qe;exports.getSelectionRoots=Rb;exports.parseFlowDocument=l_;exports.parseJsonContract=Rd;exports.parseTypeScriptContract=sb;exports.parseTypeScriptForm=Ad;exports.projectJsonPlaybackPreview=u_;exports.readFormSchema=Id;exports.readWorkflowContract=cb;exports.removeEdge=ab;exports.removeNode=ob;exports.reparentNode=kb;exports.resolveEdgeOwner=jr;exports.resolveStateView=lb;exports.setCollapsed=_d;exports.setEdgeProp=cr;exports.setEdgeStyle=nb;exports.setNodeProp=Ct;exports.updateNode=_t;exports.useCustomColors=at;exports.useEdgeProximity=Sm;exports.useFlowData=yr;exports.useFlowDiagramContext=Ze;exports.useNodeViewActions=Dn;exports.useStopPropagation=ou;exports.useThemeContentColors=Tn;exports.validateGridAdjustment=Dv;
|
|
283
|
+
@media(prefers-reduced-motion:reduce){[data-flow-loading-border][data-flow-loading-border] .flow-sdk-node-border-animation{animation:none!important}}`;function Yv({active:e=!0,label:r="Loading content",radius:t}){const{config:n,themeColor:o}=Je(),{colorText:i}=at(),s=j.useRef(null),[a,c]=j.useState({width:0,height:0,radius:0});if(j.useLayoutEffect(()=>{const u=s.current;if(!e||!u)return;const h=()=>{const m=u.parentElement,y={width:u.clientWidth,height:u.clientHeight,radius:t??(m&&parseFloat(getComputedStyle(m).borderTopLeftRadius)||0)};c(g=>g.width===y.width&&g.height===y.height&&g.radius===y.radius?g:y)},p=new ResizeObserver(h);return p.observe(u),h(),()=>p.disconnect()},[e,t]),!e)return null;const l=Me(o||i),d={x:4,y:4,width:a.width-8,height:a.height-8,radius:Math.max(0,a.radius-4),color:l,strokeWidth:2};return f.jsxs("div",{ref:s,role:"status","aria-label":r,"data-flow-loading-border":"","data-motion-disabled":n.disableAnimations||void 0,style:{position:"absolute",inset:0,pointerEvents:"none",borderRadius:"inherit",overflow:"hidden",zIndex:2},children:[f.jsx("style",{children:Uj}),f.jsxs("svg",{width:"100%",height:"100%","aria-hidden":"true",style:{display:"block",pointerEvents:"none"},children:[f.jsx("g",{opacity:.5,style:{filter:"blur(3px)"},children:f.jsx(no,{...d,strokeWidth:6})}),f.jsx(no,{...d})]})]})}function Hj({content:e,format:r,onEdit:t}){var N;const{config:n,colorMode:o}=Je(),{background:i,border:s,colorInactive:a}=at(),c=(N=n.customViews)==null?void 0:N.jsxContent,l=typeof e=="string"?e:JSON.stringify(e,null,2);let d,u;if(r==="jsx")try{const $=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray($)||$.some(M=>!M||typeof M!="object"||Array.isArray(M)||typeof M.type!="string"))throw new Error("JSX content must be an array of components with a type.");d=$}catch($){u=$ instanceof Error?$.message:"Invalid components array."}const h=j.useRef(null),p=j.useRef(null),m=j.useRef(null),y=j.useRef(!1),[g,v]=j.useState(!1),[b,x]=j.useState(""),w=!!t;j.useEffect(()=>{const $=()=>{var W;const M=document.fullscreenElement===p.current;v(M),y.current&&!M&&!document.fullscreenElement&&((W=m.current)==null||W.focus({preventScroll:!0})),y.current=M};return document.addEventListener("fullscreenchange",$),()=>document.removeEventListener("fullscreenchange",$)},[]);const C=async()=>{var $;x("");try{if(document.fullscreenElement===p.current)await document.exitFullscreen();else if(($=p.current)!=null&&$.requestFullscreen)await p.current.requestFullscreen();else throw new Error("Fullscreen is not supported in this browser.")}catch(M){x(M instanceof Error?M.message:"Unable to change fullscreen.")}},[S,_]=j.useState(),[I,E]=j.useState(),[O,A]=j.useState();j.useEffect(()=>{if(r==="jsx")return;let $=!1;return Promise.resolve().then(()=>require("./contentPreviewDocument-BsKd0dD4.cjs")).then(({contentPreviewDocument:M})=>M(l,r,w)).then(M=>{$||_({content:l,format:r,editable:w,document:M})},M=>{$||_({content:l,format:r,editable:w,error:M instanceof Error?M.message:String(M)})}),()=>{$=!0}},[l,r,w]),j.useEffect(()=>{if(!t)return;const $=async M=>{var W,ae;if(!(!((W=h.current)!=null&&W.contentWindow)||M.source!==h.current.contentWindow||((ae=M.data)==null?void 0:ae.type)!=="squeed:content-edit"))try{document.fullscreenElement===p.current&&await document.exitFullscreen(),t()}catch(se){x(se instanceof Error?se.message:"Unable to close fullscreen.")}};return window.addEventListener("message",$),()=>window.removeEventListener("message",$)},[t]);const R=(S==null?void 0:S.content)===l&&S.format===r&&S.editable===w?S:void 0,P=!!R&&R===O,T=r!=="jsx"&&!(R!=null&&R.error)&&!P&&(!R||I!==R);return f.jsxs("div",{"data-flow-content-preview":"",style:{width:"100%",height:360,fontSize:16,overflow:"auto"},children:[f.jsx("pre",{"data-flow-preview-source":"",style:{display:"none",whiteSpace:"pre-wrap"},children:l}),f.jsxs(V.Box,{ref:p,position:"relative",w:"100%",h:"100%","aria-busy":r!=="jsx"?T:void 0,bg:r==="jsx"&&o==="dark"?"gray.900":"white",onDoubleClick:$=>{r!=="jsx"||!t||$.defaultPrevented||$.target.closest('button, a, input, textarea, select, [contenteditable], [role="button"], [role="textbox"]')||($.stopPropagation(),(async()=>{document.fullscreenElement===p.current&&await document.exitFullscreen(),t()})().catch(M=>x(String(M))))},onKeyDownCapture:$=>{$.key!=="Escape"||document.fullscreenElement!==p.current||($.preventDefault(),$.stopPropagation(),C())},css:{"&:fullscreen":{width:"100vw",height:"100dvh",maxWidth:"none",maxHeight:"none",padding:0},"&:hover > [data-flow-content-toolbar], &:focus-within > [data-flow-content-toolbar]":{opacity:1,pointerEvents:"auto"},"@media (hover: none)":{"& > [data-flow-content-toolbar]":{opacity:1,pointerEvents:"auto"}}},children:[f.jsx(V.Box,{role:"toolbar","aria-label":"Content controls","data-flow-content-toolbar":"",position:"absolute",top:"8px",right:"8px",zIndex:1,w:"max-content",maxW:"calc(100% - 16px)",opacity:g?1:0,pointerEvents:g?"auto":"none",children:f.jsx(Nd,{background:i,border:o==="dark"?s:"gray.300",children:f.jsxs(V.HStack,{px:"8px",gap:"8px",h:"100%",w:"max-content",css:{"& button > svg":{width:"20px",height:"20px",minWidth:"20px",minHeight:"20px",flexShrink:0}},children:[t&&f.jsx(Oe,{"data-flow-content-edit":"","aria-label":"Edit content source",title:"Edit content source",icon:f.jsx(Z.PiCode,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:a,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:$=>{$.stopPropagation(),(async()=>{document.fullscreenElement===p.current&&await document.exitFullscreen(),t()})().catch(M=>x(String(M)))}}),f.jsx(Oe,{ref:m,"data-flow-fullscreen":"","aria-label":g?"Exit fullscreen":"Expand preview",title:g?"Exit fullscreen":"Expand preview","aria-expanded":g,icon:g?f.jsx(Z.PiArrowsIn,{size:20}):f.jsx(Z.PiArrowsOut,{size:20}),size:"sm",variant:"plain",bg:"transparent",color:a,borderRadius:"30px",w:"32px",h:"32px",minW:"32px",p:0,onClick:$=>{$.stopPropagation(),C()}})]})})}),b&&f.jsx(V.Box,{role:"alert",position:"absolute",bottom:0,insetInline:0,bg:"white",color:"red.700",fontSize:"14px",children:b}),r==="jsx"?u?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:u}):c&&d?f.jsx(c,{components:d,colorMode:o,fillHeight:!0}):f.jsx(V.Box,{role:"status",fontSize:"14px",children:"JSX content renderer is not available."}):R!=null&&R.error||P?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:(R==null?void 0:R.error)||"Content preview could not be loaded."}):R!=null&&R.document?f.jsx("iframe",{ref:h,title:`${r.toUpperCase()} content preview`,sandbox:w?"allow-scripts":"",allowFullScreen:!0,referrerPolicy:"no-referrer",srcDoc:R.document,onLoad:()=>E(R),onError:()=>A(R),style:{width:"100%",height:"100%",border:0,display:"block",background:"white",visibility:T?"hidden":"visible"}},R.document):null,f.jsx(Yv,{active:T,label:"Loading HTML content"})]})]})}const wm=1.55;function Kj({nodeId:e,content:r,color:t,format:n="markdown"}){const{callbacks:o,config:i,readOnly:s,nodeGridOptions:a}=Je(),c=!!i.editable&&!s&&!a,l=typeof r=="string"?r:JSON.stringify(r,null,2),[d,u]=j.useState(!1),[h,p]=j.useState(l),[m,y]=j.useState(""),[g,v]=j.useState(),b=j.useRef(null),x=j.useRef(!1),w=iu(d);j.useLayoutEffect(()=>{const _=b.current;!d||!_||(_.style.height="auto",_.style.height=`${Math.max((g==null?void 0:g.height)??0,_.scrollHeight)}px`)},[h,d,g]),j.useEffect(()=>{var _,I;c?d&&(x.current=!1,(_=b.current)==null||_.focus({preventScroll:!0}),(I=b.current)==null||I.select()):u(!1)},[d,c]);const C=_=>{c&&(v({width:_.offsetWidth,height:_.offsetHeight}),p(l),y(""),u(!0))},S=()=>{var I;if(x.current||!c)return;let _=h;if(n==="jsx")try{if(_=JSON.parse(h),!Array.isArray(_)||_.some(E=>!E||typeof E!="object"||Array.isArray(E)||typeof E.type!="string"))throw new Error("JSX content must be an array of components with a type.")}catch(E){y(E instanceof Error?E.message:"Invalid components array.");return}x.current=!0,h!==l&&((I=o.onNodeContentChange)==null||I.call(o,e,_)),u(!1)};return(!d||!c)&&n!=="markdown"?f.jsx(V.Box,{ref:w,w:"100%",position:"relative","data-flow-content":"",children:f.jsx(Hj,{content:r,format:n,onEdit:c?()=>{w.current&&C(w.current)}:void 0})}):!d||!c?f.jsx(V.Box,{"data-flow-content":"",color:t,opacity:r?void 0:.6,w:"100%",minH:"1.2em",whiteSpace:"normal",lineHeight:wm,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:c?"text":void 0,tabIndex:c?0:void 0,outline:"none",_focusVisible:{outline:"none",boxShadow:"none"},onClick:_=>{!c||_.target instanceof Element&&_.target.closest("a, button, input")||(_.stopPropagation(),C(_.currentTarget))},onDoubleClick:_=>{_.stopPropagation(),C(_.currentTarget)},onKeyDown:_=>{c&&_.key==="Enter"&&_.target===_.currentTarget&&(_.preventDefault(),_.stopPropagation(),C(_.currentTarget))},children:f.jsx(wx.default,{options:{forceBlock:!0,wrapper:j.Fragment,disableParsingRawHTML:!0,overrides:{a:{props:{target:"_blank",rel:"noopener noreferrer"}},img:{props:{loading:"lazy",referrerPolicy:"no-referrer"}}}},children:l||(i.editable&&!s?"Write your content here":"")})}):f.jsxs("div",{ref:w,style:{width:g==null?void 0:g.width,minHeight:g==null?void 0:g.height,maxWidth:"100%"},children:[f.jsx(V.Textarea,{ref:b,"aria-label":"Node content",placeholder:"Write your content here",value:h,"aria-invalid":!!m,onChange:_=>p(_.target.value),onBlur:S,onKeyDown:_=>{_.stopPropagation(),!_.nativeEvent.isComposing&&(_.key==="Enter"&&(_.ctrlKey||_.metaKey)&&(_.preventDefault(),S()),_.key==="Escape"&&(x.current=!0,u(!1)))},color:t,fontFamily:"inherit",fontSize:"inherit",lineHeight:wm,overflowWrap:"anywhere",whiteSpace:"pre-wrap",rows:1,bg:"transparent",display:"block",style:{border:0,outline:"none",boxShadow:"none"},_focus:{border:0,outline:"none",boxShadow:"none"},_focusVisible:{border:0,outline:"none",boxShadow:"none"},p:0,w:"100%",h:"100%",minW:0,minH:0,resize:"none"}),m&&f.jsx(V.Box,{role:"alert",fontSize:"14px",color:"red.500",children:m})]})}const Jj=(e,r,t)=>{var h,p,m,y;const n=((h=e==null?void 0:e.viewProps)==null?void 0:h.bgColor)||r,[o]=n.split("."),i=On(n),s=((p=e==null?void 0:e.viewProps)==null?void 0:p.outline)===!0,a=n==="transparent"||s,c=t==="dark"?"gray.200":"gray.900",l=a?"transparent":n!=null&&n.startsWith("#")?Me(n):Me(i.bgColor),d=Me(((m=e==null?void 0:e.viewProps)==null?void 0:m.textColor)||(a?c:i.textColor)),u=Me(((y=e==null?void 0:e.viewProps)==null?void 0:y.borderColor)||(s?n==="transparent"?r:n:i.borderColor));return{...i,bgColor:a?"transparent":i.bgColor,highlightColor:a?"transparent":i.highlightColor,isTransparent:a,propertyColor:a?c:i.propertyColor,bg:n,wordBeforeDot:o,hexbgColor:l,hextextColor:d,hexborderColor:u}},Zj=(e,r=350)=>`${String(e).substring(0,r)}${String(e).length>r?"...":""}`,Yj=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,Xv=600,Xj=3,Qj=e=>{const r=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(r*28+30,200)};function e_({headerTitle:e,hasContent:r,data:t,icon:n,colors:o,hasConfig:i,id:s,isActive:a,isHovered:c,isEditing:l,onSelect:d,onEditStart:u,onEditEnd:h,props:p,objVisible:m,setObjVisible:y,onShowNativeIcon:g}){var w,C;const{callbacks:v}=Je(),b=p.onShowIcon??g,x=b?"Show icon":m?"Show content":"Show properties";return f.jsx(f.Fragment,{children:(e||r||((w=t.config)==null?void 0:w.form)||(a||c)&&g)&&f.jsxs(V.Flex,{justify:"flex-start",direction:"row",p:r||Object.entries(t.description||{}).length?8:20,borderBottomWidth:1,minWidth:"max-content !important",width:"100%",textTransform:"capitalize",align:"center",textOverflow:"ellipsis",alignItems:"center",fontWeight:"bold",color:o.propertyColor,bgColor:o.highlightColor,borderBottomColor:!i&&!r?"transparent":o.hexborderColor,children:[!!n&&f.jsx(V.Flex,{mr:6,alignItems:"center",flexShrink:0,children:f.jsx(Yt,{name:n,size:64,color:o.hextextColor},o.hextextColor)}),f.jsx(Kr,{nodeId:s,label:Yj(e),color:((C=t==null?void 0:t.viewProps)==null?void 0:C.textColor)||o.propertyColor,isEditing:l,onEditStart:u,onEditEnd:h}),(a||c)&&(r||b)&&f.jsx(V.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:f.jsx(Ke,{label:x,children:f.jsx(Oe,{"aria-label":x,icon:f.jsx(V.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:S=>{var _;S.stopPropagation(),a||d(S),b?b():y(!m),(_=v.onNodeViewToggle)==null||_.call(v,s)}})})})]})})}function t_({data:e,resourcePorts:r,inspecting:t,form:n,inspectionPorts:o,extraPorts:i,colors:s,direction:a,uniformKeyWidth:c}){const{edgeById:l}=mr(),d=new Set;for(const{data:u}of l.values())u.source===e.id&&u.sourceProperty!==void 0&&d.add(`source:${u.sourceProperty}`),u.target===e.id&&u.targetProperty!==void 0&&d.add(`target:${u.targetProperty}`);return f.jsx(V.Box,{children:Object.entries(e.description||{}).map(([u,h],p)=>{var P,T,N;const m=r&&Object.keys(r).find($=>$.slice($.indexOf(":")+1)===u),y=t&&((P=n==null?void 0:n.type.ports)==null?void 0:P[u]),g=m??(y?`${y.kind}:${u}`:u),v=o.find($=>$.id===g),b=m?"source":v==null?void 0:v.role,x=d.has(`source:${g}`),w=d.has(`target:${g}`),C=i.some($=>$.id===u),S=h===""&&(C||(b?d.has(`${b}:${g}`):x||w)),_=b??(x!==w?x?"source":"target":void 0),I=(v==null?void 0:v.side)??(_?_==="source"!=(a==="RL")?"right":"left":void 0),E=S&&I==="right"?"right":"left",O=(v==null?void 0:v.label)??(y==null?void 0:y.label)??(C?u.replace(/^(template|input|output|config|error):/,""):u),A=Zt(s.wordBeforeDot)[typeof h],R=Zt(s.wordBeforeDot).property;return f.jsxs(V.Box,{"data-flow-property":m&&(a==="TB"||a==="BT")?void 0:g,"data-flow-port-role":b,"data-flow-inspection-row":t?"":void 0,children:[f.jsxs(V.Flex,{flexWrap:"nowrap",overflow:"hidden",children:[f.jsx(V.Flex,{justifyContent:"start",align:"center",background:s.highlightColor,width:S?"100%":`${c}px`,minWidth:`${c}px`,borderRightColor:s.hexborderColor,borderRightWidth:S?0:1,children:f.jsx(V.Text,{py:5,px:10,w:"100%",textAlign:E,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((T=e==null?void 0:e.viewProps)==null?void 0:T.textColor)||(s.isTransparent?s.hextextColor:R),children:O})}),!S&&f.jsx(V.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:s.hexbgColor,w:Xv,maxH:200,children:f.jsx(V.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:((N=e==null?void 0:e.viewProps)==null?void 0:N.textColor)||(s.isTransparent?s.hextextColor:A),fontWeight:400,children:Zj(h)})})]}),p!==Object.entries(e.description||{}).length-1&&f.jsx(V.Box,{borderTopWidth:1,my:0,borderColor:s.hexborderColor})]},u)})})}function r_(e){var x,w,C,S,_;const{themeColor:r,colorMode:t,direction:n}=Je(),o=Vn(),i=o.getNodeViewMode(e.data.id)==="properties",s=I=>o.setNodeViewMode(e.data.id,I?"properties":"default"),a=!!e.onShowIcon||i||typeof((x=e.data.config)==null?void 0:x.content)!="string"&&!(((w=e.data.config)==null?void 0:w.contentFormat)==="jsx"&&Array.isArray((C=e.data.config)==null?void 0:C.content)),{bindings:c,data:l,schema:d}=j.useContext(Tt),u=(S=c==null?void 0:c[e.data.id])==null?void 0:S.portResources,h=c?Nn(c,e.data.id,d):l&&d?Yr(l,e.data.id,d):void 0,p=h&&Fe(l,"address"in h?h.address:e.data.id),m=p&&typeof p=="object"&&h?Object.fromEntries(Object.keys(h.type.properties).filter(I=>{var E;return Object.prototype.hasOwnProperty.call(p,I)&&fo((E=h.fields[I])==null?void 0:E.$visibleWhen,l)}).map(I=>[I,p[I]!==null&&typeof p[I]=="object"?JSON.stringify(p[I],null,2):p[I]===null?"null":p[I]])):{},y=u?Object.fromEntries(Object.entries(u).map(([I,E])=>{var O;return[I.slice(I.indexOf(":")+1),((O=Fe(l,E))==null?void 0:O.name)??E.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:m,g=a&&!u?((_=e.data.config)==null?void 0:_.ports)??[]:[],v=g.filter(I=>!Object.prototype.hasOwnProperty.call(y,I.id)&&!Object.entries((h==null?void 0:h.type.ports)??{}).some(([E,O])=>`${O.kind}:${E}`===I.id&&Object.prototype.hasOwnProperty.call(y,E))),b={...y,...Object.fromEntries(v.map(I=>[I.id,""]))};return{themeColor:r,colorMode:t,direction:n,objVisible:i,setObjVisible:s,inspecting:a,resourcePorts:u,form:h,description:b,inspectionPorts:g,extraPorts:v}}const lu=e=>{var b,x,w,C,S,_;const{themeColor:r,colorMode:t,direction:n,objVisible:o,setObjVisible:i,inspecting:s,resourcePorts:a,form:c,description:l,inspectionPorts:d,extraPorts:u}=r_(e),h=Vn(),p=h.getNodeViewMode(e.data.id)==="icon-label",m=!e.onShowIcon&&(typeof((b=e.data.config)==null?void 0:b.content)=="string"||((x=e.data.config)==null?void 0:x.contentFormat)==="jsx"&&Array.isArray((w=e.data.config)==null?void 0:w.content)),y=j.useRef(p);p&&(y.current=!0),su(e.data.id,m&&!((C=e.data.config)!=null&&C.parentContainer)&&h.allNodesIconLabel&&!p&&y.current,()=>h.setNodeViewMode(e.data.id,"icon-label"));const v=!e.onShowIcon&&!((S=e.data.config)!=null&&S.parentContainer)&&!m?()=>h.setNodeViewMode(e.data.id,"icon-label"):void 0;return!e.onShowIcon&&p?f.jsx(cu,{...e,data:{...e.data,label:e.data.label??e.data.headerTitle,config:{...e.data.config,labelBelow:!0,icon:((_=e.data.config)==null?void 0:_.icon)||"PiBracketsCurly"}},onExpand:()=>h.restoreNodeView(e.data.id)}):f.jsx(Dn,{...e,data:{...e.data,description:l},hoverLeaveDelay:m||e.onShowIcon||v?350:0,children:({id:I,data:E,isActive:O,isHovered:A,isEditing:R,onSelect:P,onEditStart:T,onEditEnd:N})=>{var L,z,U,B,ce,X,le,ue,xe,Ce;const $=Jj(E,r,t),M=E.label??E.headerTitle,W=Object.entries(E.description||{}).length>0,ae=Qj(E.description),se=(z=(L=e.data)==null?void 0:L.config)==null?void 0:z.icon,re=(B=(U=e.data)==null?void 0:U.config)==null?void 0:B.content,ye=((ce=E==null?void 0:E.viewProps)==null?void 0:ce.borderRadius)??"53px",me=In(E==null?void 0:E.viewProps,$.hexborderColor,O,Xj);return f.jsx(V.Flex,{justifyContent:"space-between",...E==null?void 0:E.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:ye,overflow:"hidden",alignItems:"center",style:{backgroundColor:$.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:"100%",minW:m||e.onShowIcon?ae+Xv+me.borderWidth*2:void 0,...me,children:f.jsxs(V.Flex,{width:"100%",direction:"column",borderRadius:ye,borderColor:$.hexborderColor,borderWidth:0,overflow:"hidden",children:[f.jsx(e_,{headerTitle:M,hasContent:m,data:E,icon:se,colors:$,hasConfig:W,id:I,isActive:O,isHovered:A,isEditing:R,onSelect:P,onEditStart:T,onEditEnd:N,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:v}),m&&!o?f.jsx(V.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:$.highlightColor,p:["html","jsx"].includes((le=(X=e.data)==null?void 0:X.config)==null?void 0:le.contentFormat)?0:12,fontSize:"5xl",lineHeight:"normal",children:f.jsx(Kj,{nodeId:I,content:re,format:(xe=(ue=e.data)==null?void 0:ue.config)==null?void 0:xe.contentFormat,color:((Ce=E==null?void 0:E.viewProps)==null?void 0:Ce.textColor)||$.hextextColor})}):f.jsx(t_,{data:E,resourcePorts:a,inspecting:s,form:c,inspectionPorts:d,extraPorts:u,colors:$,direction:n,uniformKeyWidth:ae})]})})}})};lu.displayName="NodeJsonObjectView";const Qv=e=>{var h,p,m,y,g,v,b,x,w,C,S;const r=Vn(),[t,n]=j.useState(!1),o=r.getNodeViewMode(e.data.id)==="properties",i=_=>{n(_),r.setNodeViewMode(e.data.id,_?"properties":"default")},{callbacks:s,readOnly:a}=Je(),c=(p=(h=e.data)==null?void 0:h.config)==null?void 0:p.parentContainer;su(e.data.id,o&&((y=(m=e.data)==null?void 0:m.config)==null?void 0:y.labelBelow)&&!c,()=>i(!1));const l=c?"Show parent":"Show properties",d=c||((v=(g=e.data)==null?void 0:g.config)==null?void 0:v.form)||((w=(x=(b=e.data)==null?void 0:b.config)==null?void 0:x.ports)==null?void 0:w.length),u=d?()=>{var _;c?(_=s.onNodeCollapse)==null||_.call(s,e.data.id,!1):i(!0)}:void 0;return!c&&d&&o?f.jsx(lu,{...e,editOnMount:t,onShowIcon:()=>i(!1)}):f.jsx(cu,{...e,onOpenView:u&&(c||(S=(C=e.data)==null?void 0:C.config)!=null&&S.labelBelow)?()=>{var _;u(),(_=s.onNodeViewToggle)==null||_.call(s,e.data.id)}:void 0,toggleLabel:l,toggleDisabled:c&&a,onExpand:u})};function n_(e){var v,b,x,w,C,S;const{config:r,callbacks:t,readOnly:n,selectedNodeIds:o,nodeRadiusPreviews:i,nodeViewModes:s,allNodesIconLabel:a}=Je(),c=i[e.data.id]??((v=e.data.viewProps)==null?void 0:v.borderRadius),[l,d]=j.useState(!1),u=Vn(),{border:h,colorText:p}=at(),m=(b=r.customViews)==null?void 0:b.gridContent,y=(s[e.data.id]??(a?"icon-label":"default"))==="icon-label",g=j.useRef(y);return y&&(g.current=!0),su(e.data.id,a&&!y&&g.current,()=>u.setNodeViewMode(e.data.id,"icon-label")),y?f.jsx(V.Box,{"data-grid-document":((x=e.data.config)==null?void 0:x.documentId)??"",children:f.jsx(cu,{...e,data:{...e.data,viewProps:{...e.data.viewProps,borderRadius:c},config:{...e.data.config,labelBelow:!0,icon:((w=e.data.config)==null?void 0:w.icon)||"PiGridFour"}},toggleLabel:"Show grid",onExpand:()=>u.restoreNodeView(e.data.id)})}):f.jsxs(f.Fragment,{children:[f.jsx(Dn,{...e,onOpenView:()=>d(!0),children:({data:_,isActive:I})=>{var E,O,A,R,P,T,N,$;return f.jsx(V.Box,{"data-flow-node-surface":"","data-grid-document":((E=_.config)==null?void 0:E.documentId)??"",width:`${((A=(O=_.config)==null?void 0:O.gridSize)==null?void 0:A.width)??600}px`,height:`${((P=(R=_.config)==null?void 0:R.gridSize)==null?void 0:P.height)??440}px`,overflow:"hidden",position:"relative",bg:((T=_.viewProps)==null?void 0:T.bgColor)??"transparent",color:((N=_.viewProps)==null?void 0:N.textColor)??p,borderRadius:`${c??0}px`,...In(_.viewProps,Me((($=_.viewProps)==null?void 0:$.borderColor)??h),I,0),children:m?f.jsx(m,{...e}):f.jsx(V.Box,{p:4,children:_.label??"Grid"})})}}),f.jsx(au,{nodeAddress:e.data.id,active:o.includes(e.data.id),label:e.data.label??"Grid",open:l&&!n,onClose:()=>d(!1),children:f.jsx(Tt.Provider,{value:{data:{metadata:{label:e.data.label??"",subtitle:((C=e.data.config)==null?void 0:C.subtitle)??"",icon:((S=e.data.config)==null?void 0:S.icon)??"PiGridFour"}},bindings:{[e.data.id]:{address:"root.metadata",type:"GridMetadata"}},schema:{GridMetadata:{kind:"object",properties:{label:{optional:!0,type:{kind:"string"}},subtitle:{optional:!0,type:{kind:"string"}},icon:{optional:!0,type:{kind:"string"}}}}},editable:!!r.editable&&!n,callbacks:{onFormChange:_=>{var E,O,A;if(n||!r.editable)return;const I=String(_.value??"");_.address==="root.metadata.label"?(E=t.onNodeLabelChange)==null||E.call(t,e.data.id,I):_.address==="root.metadata.subtitle"?(O=t.onNodeSubtitleChange)==null||O.call(t,e.data.id,I):_.address==="root.metadata.icon"&&((A=t.onNodeIconChange)==null||A.call(t,e.data.id,I))}}},children:f.jsx(Td,{nodeAddress:e.data.id})})})]})}const ex=e=>f.jsx(Qv,{...e,renderCompact:Wj}),tx=e=>f.jsx(Qv,{...e}),rx=({containerStyle:e,...r})=>{const{selectedNodeIds:t}=Je();return f.jsx(Dn,{...r,editOnMount:t.includes(r.data.id),children:n=>f.jsx(V.Box,{bg:e.textColor==="transparent"?"transparent":e.labelBg,p:`${e.fontSize/5}px`,fontFamily:ur,lineHeight:1,w:"fit-content",children:f.jsx(Kr,{nodeId:n.id,label:n.data.label??n.data.headerTitle??"Container",color:e.textColor,fontSize:`${e.fontSize}px`,isEditing:n.isEditing,onEditStart:n.onEditStart,onEditEnd:n.onEditEnd})})})};ex.displayName="text";tx.displayName="arrayView";rx.displayName="ParentContainerView";const o_={grid:n_,objectView:lu,arrayView:tx,text:ex,parentContainer:rx},i_=({children:e,pattern:r="dot",backgroundColor:t})=>{const{colorMode:n}=Je(),o=n==="dark",i=o?"--chakra-colors-gray-700":"--chakra-colors-gray-500",s=o?"--chakra-colors-gray-700":"--chakra-colors-gray-800";return r==="none"?f.jsx(V.Box,{"data-flow-background":"none",width:"100%",height:"100%",padding:0,bg:t,children:e}):f.jsxs(V.Box,{"data-flow-background":r,position:"relative",width:"100%",height:"100%",padding:0,bg:t,children:[f.jsx(V.Box,{position:"absolute",top:0,left:0,right:0,bottom:0,width:"100%",height:"100%",zIndex:0,pointerEvents:"none",style:{backgroundImage:r==="dot"?`radial-gradient(var(${i}) 8%, transparent 8%)`:r==="steel"?`repeating-linear-gradient(45deg, var(${s}) 0, var(${s}) 1px, transparent 1px, transparent 20px)`:`linear-gradient(var(${s}) 1px, transparent 1px), linear-gradient(90deg, var(${s}) 1px, transparent 1px)`,backgroundSize:"20px 20px",opacity:.3}}),f.jsx(V.Box,{position:"relative",width:"100%",height:"100%",zIndex:1,padding:0,children:e})]})},a_=.4,Sr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},s_=({nodes:e,edges:r})=>{var ze;const{themeColor:t,spacing:n,edgeRadius:o,backgroundVariant:i,backgroundSelected:s,setBackgroundSelected:a,edgeColor:c,direction:l,nodeAlignment:d,edgeMode:u,compactPropertyLayout:h,workflowContract:p,parentNodeStyle:m,engineRef:y,callbacks:g,config:v,selectedNodeIds:b,setSelectedNodeIds:x,selectedEdgeId:w,setSelectedEdgeId:C,setIsPerformanceMode:S,setNodeGridOptions:_,fillRadiusEditedIds:I,isZoomMode:E,setIsZoomMode:O,isMultiSelectMode:A,setIsMultiSelectMode:R,isDragMode:P,setIsDragMode:T,isEdgeHandlesEnabled:N,setIsEdgeHandlesEnabled:$,isArrayNodeMode:M}=Je(),W=j.useRef(null),[ae,se]=j.useState(null),re=j.useRef(null),ye=e.length>200;j.useEffect(()=>{S(ye)},[ye,S]);const{edgeSep:me,rankSep:L,spacingFactor:z}=j.useMemo(()=>{const ne=Fw(e.length),D=v.nodeGridSpacing==="layout"&&n<.5?n*1.3:n<1?.3+.7*n:.5+.5*n;return{edgeSep:ne.edgeSep*D,rankSep:ne.rankSep*D,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n,v.nodeGridSpacing]),{bgColor:U}=On(t),{canvas:B,borderSecondary:ce,colorText:X}=at(),le=i==="transparent"?"transparent":v.backgroundColor||B,ue=j.useCallback(ne=>{if(!ne)return Me(t);switch(ne){case"dark":return Me(le);case"light":return Me(ce);default:return Me(ne)}},[t,le,ce]),xe=v.colorMode==="dark",Ce=xe?Me("gray.500"):Jr,ge=xe?U!=null&&U.includes("gray")?"whitesmoke":ue(U):Ce,he=c?ue(c):Ce,Y=j.useMemo(()=>{var ne;return v.initialViewport||{pan:{x:0,y:0},zoom:(ne=v.nodeGrid)!=null&&ne.enabled&&v.nodeGrid.options.fill?1:.01}},[]),H=l==="C"?"LR":l,ve=j.useCallback(ne=>{const D={...m,...ne};return{...D,bgColor:D.bgColor||t,bgOpacity:D.outline?0:D.bgOpacity??a_}},[m,t]),J=j.useMemo(()=>{var D;const ne=new Map;for(const oe of e)(D=oe.data)!=null&&D.id&&ne.set(oe.data.id,oe);return ne},[e]),be=j.useMemo(()=>{var D;const ne=new Map;for(const oe of r)(D=oe.data)!=null&&D.id&&ne.set(oe.data.id,oe);return ne},[r]),Q=j.useCallback(ne=>{var G;const D=(G=J.get(ne))==null?void 0:G.data,oe=ve(D==null?void 0:D.viewProps),Le=Me(oe.bgColor);return{animated:!!(D!=null&&D.isNodeAnimated)&&!ye,animationVariant:D==null?void 0:D.nodeAnimationVariant,animationColor:Me(oe.borderColor||t),bgColor:oe.outline?"transparent":Le,bgOpacity:oe.bgOpacity,borderColor:oe.borderColor?Me(oe.borderColor):oe.outline&&oe.bgColor==="transparent"?Me(t):Le,borderWidth:Mn(oe.borderWidth,Sr.borderWidth),borderStyle:oe.borderStyle??Sr.borderStyle,borderRadius:oe.borderRadius??Sr.borderRadius,textColor:oe.textColor?Me(oe.textColor):oe.outline||oe.bgColor==="transparent"?Me(X):Le,fontSize:oe.fontSize??Sr.fontSize,labelPosition:oe.labelPosition??Sr.labelPosition,labelMargin:Sr.labelMargin,labelBg:xu(ue("dark"),Le,oe.bgOpacity)??ue("dark"),padding:oe.padding??Sr.padding}},[ve,J,X,t,ye,ue]),je=j.useMemo(()=>{var oe,Le;const ne=new Map;for(const G of r){const fe=(oe=G.data)==null?void 0:oe.source,Se=(Le=G.data)==null?void 0:Le.target;if(!fe||!Se||fe===Se)continue;const Ee=fe<Se?`${fe}|${Se}`:`${Se}|${fe}`,Qe=ne.get(Ee);Qe?Qe.push({id:G.data.id,source:fe}):ne.set(Ee,[{id:G.data.id,source:fe}])}const D=new Map;for(const[G,fe]of ne){if(fe.length<2)continue;const Se=G.split("|")[0],Ee=Math.min(20,70/fe.length);fe.forEach(({id:Qe,source:et},Ze)=>{const Et=50+(Ze-(fe.length-1)/2)*Ee;D.set(Qe,(et===Se?Et:100-Et)/100)})}return D},[r]),Pe=j.useMemo(()=>{const ne=ue("dark");return r.filter(D=>{var oe;return((oe=D.data)==null?void 0:oe.id)&&D.data.source&&D.data.target}).map(({data:D})=>{var fe,Se,Ee,Qe,et,Ze;let oe=ne;const Le=(Se=(fe=J.get(D.source))==null?void 0:fe.data)==null?void 0:Se.parent,G=(Qe=(Ee=J.get(D.target))==null?void 0:Ee.data)==null?void 0:Qe.parent;if(Le&&Le===G){const Et=ve((Ze=(et=J.get(Le))==null?void 0:et.data)==null?void 0:Ze.viewProps),At=xu(ne,Me(Et.bgColor),Et.bgOpacity);At&&(oe=At)}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:(u==="auto"||u==="properties")&&(D.sourceProperty!==void 0||D.targetProperty!==void 0)&&p?Md(p,D):void 0,color:c?he:D.color?Me(D.color):he,connectorColor:c?he:D.color?Me(D.color):ge,labelBg:oe,dashed:!!D.isEdgeDashed,animated:!!D.isEdgeAnimated,inverted:!!D.isInverted,turn:je.get(D.id)??.5}})},[r,he,ge,c,je,v.edgeType,u,p,J,ve,ue]),qe=j.useMemo(()=>{var D;const ne=new Set;for(const oe of e)(D=oe.data)!=null&&D.parent&&ne.add(oe.data.parent);return ne},[e]),Xe=j.useMemo(()=>{const ne=new Map;for(const D of r){const oe=D.data.isInverted?D.data.target:D.data.source;oe&&!ne.has(oe)&&ne.set(oe,D.data)}for(const D of r){if(D.data.connection)continue;const oe=D.data.isInverted?D.data.target:D.data.source,Le=D.data.isInverted?D.data.source:D.data.target;Le.startsWith(`${oe}.`)&&(ne.set(oe,D.data),ne.set(Le,D.data))}return ne},[r]),Be=j.useMemo(()=>{const ne={...o_,...v.customViews};return e.filter(D=>{var oe;return(oe=D.data)==null?void 0:oe.id}).map(D=>{var Ee,Qe,et,Ze,Et,At;const oe=qe.has(D.data.id)&&!D.data.parent,Le=oe?D.data.label??D.data.headerTitle??"Container":void 0,G=oe?ne.parentContainer:ne[D.data.type]||ne.text,fe=Xe.get(D.data.id),Se={...D,isInverted:((Ee=D.data.config)==null?void 0:Ee.isInverted)??(fe==null?void 0:fe.isInverted),isParent:oe,containerStyle:oe?Q(D.data.id):void 0};return{id:D.data.id,collapsed:(Qe=D.data.config)==null?void 0:Qe.collapsed,parent:D.data.parent,acceptsChildren:!!((et=D.data.config)!=null&&et.parentContainer)||qe.has(D.data.id),label:Le,animated:!!D.data.isNodeAnimated,animationVariant:D.data.nodeAnimationVariant,hasCollapseControl:((Ze=D.data.config)==null?void 0:Ze.collapsed)!==void 0,animationColor:Me(((Et=D.data.viewProps)==null?void 0:Et.borderColor)||t),animationWidth:Mn((At=D.data.viewProps)==null?void 0:At.borderWidth,8),element:j.createElement(G,{...Se,key:`${D.data.id}-${t}`}),fillElement:I.has(D.data.id)?void 0:j.createElement(G,{...Se,data:{...D.data,viewProps:{...D.data.viewProps,borderRadius:0}},containerStyle:Se.containerStyle?{...Se.containerStyle,borderRadius:0}:void 0,key:`${D.data.id}-${t}`})}})},[e,qe,Xe,t,v.customViews,Q,I]),ut=j.useMemo(()=>ye?300:e.length>50?150:e.length>20?100:50,[e.length,ye]),De=j.useRef(v);De.current=v;const rt=j.useRef(E);rt.current=E;const pt=j.useRef(M);pt.current=M;const Ne=j.useRef(b);Ne.current=b;const Ge=j.useRef(w);Ge.current=w;const st=j.useRef(A);st.current=A;const ct=j.useRef(J);ct.current=J;const Bt=j.useRef(be);Bt.current=be;const Ue=j.useRef(new Map);j.useEffect(()=>{var oe,Le;const ne=new Map([...be].filter(([,G])=>J.has(G.data.source)&&J.has(G.data.target))),D=Ue.current;Ue.current=ne;for(const[G,fe]of D)ne.has(G)||(Ge.current===G&&(C(null),(oe=g.onEdgeDeselect)==null||oe.call(g)),(Le=g.onEdgeRemove)==null||Le.call(g,G,fe.data))},[be,J,g,C]),j.useEffect(()=>{const ne=W.current;if(!ae||!ne)return;let D=null,oe=null,Le=0,G=0,fe=0,Se=0,Ee=0;const Qe=et=>{var At;if(De.current.readOnly||De.current.minZoom===De.current.maxZoom&&De.current.minZoom!==void 0&&((At=ne.parentElement)!=null&&At.closest(".flow-sdk-canvas")))return;const Ze=ne.ownerDocument.fullscreenElement;if(Ze&&Ze!==ne&&ne.contains(Ze)&&et.target instanceof Node&&Ze.contains(et.target))return;et.preventDefault(),et.stopPropagation(),rt.current||et.metaKey||et.ctrlKey?(fe+=et.deltaY,Se=et.clientX,Ee=et.clientY,oe===null&&(oe=requestAnimationFrame(()=>{oe=null;const mt=De.current,ht=ae.zoom(),Ct=fe;fe=0;let Pt=ht-Ct*.05/100;Pt=Math.max(mt.minZoom??.01,Math.min(mt.maxZoom??1.5,Pt));const Ot=ne.getBoundingClientRect();ae.zoomAt(Pt,{x:Se-Ot.left,y:Ee-Ot.top})}))):(Le+=et.deltaX,G+=et.deltaY,D===null&&(D=requestAnimationFrame(()=>{D=null;const mt=ae.pan(),ht=ae.zoom(),Ct=.35,Pt=Le,Ot=G;Le=0,G=0,ae.pan({x:mt.x+-Pt*Ct/ht,y:mt.y+-Ot*Ct/ht})})))};return ne.addEventListener("wheel",Qe,{passive:!1}),()=>{ne.removeEventListener("wheel",Qe),D!==null&&cancelAnimationFrame(D),oe!==null&&cancelAnimationFrame(oe)}},[ae]),j.useEffect(()=>{if(v.disableKeyboardShortcuts)return;const ne=D=>{var Le,G,fe,Se;if(De.current.readOnly)return;const oe=D.target;if(!(oe.tagName==="INPUT"||oe.tagName==="TEXTAREA"||oe.isContentEditable)){if((D.key==="z"||D.key==="Z")&&O(!rt.current),(D.key==="m"||D.key==="M")&&R(!A),(D.key==="d"||D.key==="D")&&T(!P),(D.key==="v"||D.key==="V")&&!D.repeat&&!D.metaKey&&!D.ctrlKey&&!D.altKey&&oe.tagName!=="SELECT"&&$(!N),(D.key==="Delete"||D.key==="Backspace")&&Ge.current){D.preventDefault();const Ee=Ge.current;(G=g.onEdgeDelete)==null||G.call(g,Ee,((Le=Bt.current.get(Ee))==null?void 0:Le.data)??{id:Ee}),C(null);return}if((D.key==="Delete"||D.key==="Backspace")&&Ne.current.length>0){D.preventDefault();const Ee=Ne.current.filter(Qe=>Qe!=="root");if(Ee.length===0)return;for(const Qe of Ee){const et=(fe=ct.current.get(Qe))==null?void 0:fe.data;(Se=g.onNodeDelete)==null||Se.call(g,Qe,et||{})}x([])}}};return window.addEventListener("keydown",ne),()=>window.removeEventListener("keydown",ne)},[A,P,N,$,O,R,T,v.disableKeyboardShortcuts,g,x,C]);const We=j.useCallback(ne=>{var D;y.current=ne,se(ne),(D=g.onInit)==null||D.call(g,ne)},[y,g]),Ut=j.useCallback(ne=>{var D;return(D=g.onViewportChange)==null?void 0:D.call(g,ne)},[g]),lt=j.useCallback(ne=>{var oe,Le,G;const D=((oe=Bt.current.get(ne))==null?void 0:oe.data)??{id:ne};if(Ge.current===ne&&st.current){C(null),(Le=g.onEdgeDeselect)==null||Le.call(g);return}Ne.current.length&&x([]),C(ne),(G=g.onEdgeSelect)==null||G.call(g,ne,D)},[g,C,x]),or=j.useCallback(()=>{var ne,D,oe,Le,G;if(a(v.bottomBarCollapsed??(Ne.current.length>0||!!Ge.current||!s)),(ne=g.onBackgroundClick)==null||ne.call(g),!De.current.readOnly){const fe=new Set;for(const Se of Ne.current){let Ee=ct.current.get(Se);for(;Ee&&!fe.has(Ee.data.id);)fe.add(Ee.data.id),qe.has(Ee.data.id)&&((D=Ee.data.config)==null?void 0:D.collapsed)!==!0&&((oe=g.onNodeCollapse)==null||oe.call(g,Ee.data.id,!0)),Ee=Ee.data.parent?ct.current.get(Ee.data.parent):void 0}}Ne.current.length&&(x([]),(Le=g.onNodeDeselect)==null||Le.call(g)),Ge.current&&(C(null),(G=g.onEdgeDeselect)==null||G.call(g))},[g,x,C,a,s,v.bottomBarCollapsed,qe]),Ht=j.useCallback(ne=>{var Le,G;const D=Ne.current,oe=ne.filter(fe=>!D.includes(fe));if(oe.length){x([...D,...oe]);for(const fe of oe)(G=g.onNodeSelect)==null||G.call(g,fe,((Le=ct.current.get(fe))==null?void 0:Le.data)??{id:fe})}},[g,x]),Or=j.useCallback((ne,D)=>{var oe,Le;x([ne]),(Le=g.onNodeSelect)==null||Le.call(g,ne,((oe=ct.current.get(ne))==null?void 0:oe.data)??{id:ne},D)},[g,x]),_t=j.useRef(null),Kt=j.useCallback((ne,D,oe)=>{var Le;_t.current={source:ne,target:D,edgeIds:new Set(Bt.current.keys())};try{(Le=g.onEdgeCreate)==null||Le.call(g,ne,D,oe)}catch(G){throw _t.current=null,G}},[g]),Qt=j.useCallback((ne,D,oe,Le=!1)=>{var G,fe;if(re.current={sourceId:ne,nodeIds:new Set(ct.current.keys()),reverse:Le},!(u==="properties"&&((G=g.onNodeCreateRequest)==null?void 0:G.call(g,{sourceNodeId:ne,position:D,sourceProperty:oe,reverse:Le}))===!0)){if(oe!==void 0||Le){re.current=null;return}(fe=g.onNodeCreate)==null||fe.call(g,{type:"text",sourceNodeId:ne,position:D,isArrayMode:pt.current})}},[g,u]),Nr=!v.readOnly&&N&&v.edgeHandles!==!1,vr=i==="transparent"?"none":i;return f.jsx(i_,{pattern:vr,backgroundColor:le,children:f.jsx(V.Box,{ref:W,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:f.jsx(zj,{nodes:Be,edges:Pe,direction:H,nodeAlignment:d,onContainerCollapse:ne=>{var D,oe;(D=g.onNodeCollapse)==null||D.call(g,ne,!0),(oe=g.onNodeViewToggle)==null||oe.call(g,ne)},selectedNodeIds:b,edgeMode:u,compactPropertyLayout:h,edgeType:v.edgeType,edgeRadius:o,customEdgeTypes:v.customEdgeTypes,edgeReveal:v.disableAnimations?void 0:v.edgeReveal,rankSep:L,edgeSep:me,nodeGridSpacing:v.nodeGridSpacing,nodeGridConnections:v.nodeGridConnections,initialNodeGrid:v.nodeGrid,spacingFactor:z,compactSpacingScale:n,layoutDebounce:ut,isPerformanceMode:ye,minZoom:v.minZoom??.01,maxZoom:v.maxZoom??1.5,initialViewport:Y,fitOnInit:!v.initialViewport&&!((ze=v.nodeGrid)!=null&&ze.enabled&&v.nodeGrid.options.fill),readOnly:!!v.readOnly,containerStyle:Q,lineColor:c?he:ge,drawMode:Nr,drawHandles:!v.readOnly&&v.edgeHandles!==!1,dragMode:P,multiSelect:!!A,onInit:We,onLayoutComplete:ne=>{var fe;(fe=g.onLayoutComplete)==null||fe.call(g,ne);const D=_t.current;D&&(!ct.current.has(D.source)||!ct.current.has(D.target)?_t.current=null:r.some(({data:Se})=>Se.source===D.source&&Se.target===D.target&&!D.edgeIds.has(Se.id))&&ne.getNodeBox(D.source)&&ne.getNodeBox(D.target)&&(_t.current=null,ne.focusConnections(D.source)));const oe=re.current;if(!oe)return;if(!ct.current.has(oe.sourceId)){re.current=null;return}const G=e.filter(Se=>!oe.nodeIds.has(Se.data.id)).filter(Se=>r.some(({data:Ee})=>Ee.source===oe.sourceId&&Ee.target===Se.data.id||Ee.target===oe.sourceId&&Ee.source===Se.data.id));!G.length||G.some(Se=>!ne.getNodeBox(Se.data.id))||(re.current=null,ne.focusBranch(oe.reverse?G[0].data.id:oe.sourceId))},onNodeGridModeChange:_,onNodeGridZoomOut:g.onNodeGridZoomOut,onNodeGridDrop:g.onNodeGridDrop,onNodeParentChange:g.onNodeParentChange,animateViewport:v.animateViewport,disableAnimations:v.disableAnimations,onViewportChange:Ut,onBackgroundTap:or,onBoxSelect:Ht,onEdgeSelect:lt,onContainerSelect:Or,onEdgeDraw:Kt,onDrawIntoSpace:Qt})})})},nx=j.memo(s_),c_=".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 Cm=!1;function l_(){if(Cm||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=c_+".flow-sdk-canvas[data-node-grid] .flow-sdk-node,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *::before,.flow-sdk-canvas[data-node-grid] .flow-sdk-node *::after{animation:none!important;transition:none!important}.flow-sdk-node[data-grid-fill] [data-flow-icon-label]{--flow-grid-caption-color:var(--flow-grid-on-surface-color)}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]{border:0;outline:none;box-shadow:none}.flow-sdk-node[data-grid-fill]{box-sizing:border-box}.flow-sdk-node[data-grid-fill] :not(svg):has([data-flow-node-surface]),.flow-sdk-node[data-grid-fill]>:not(svg):not(button){width:100%;height:100%;min-width:0;max-width:none}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]{width:100%;height:100%;min-width:0;max-width:none;box-sizing:border-box;overflow:hidden}.flow-sdk-node[data-grid-fill] [data-flow-icon-label]{gap:0}.flow-sdk-node[data-grid-fill] [data-flow-icon-caption]{position:absolute;bottom:12px;left:12px;width:calc(100% - 24px);max-height:40%;overflow:hidden}.flow-sdk-node[data-grid-fill] [data-flow-node-surface]>svg{max-width:45%;max-height:55%}.flow-sdk-node[data-grid-fill] p{font-size:var(--flow-grid-font);white-space:normal;overflow-wrap:anywhere}.flow-sdk-canvas[data-node-grid]:not([data-grid-connections]) .flow-sdk-property-port,.flow-sdk-canvas[data-node-grid]:not([data-grid-connections]) .flow-sdk-handle,.flow-sdk-canvas[data-node-grid] [data-flow-collapse-control]{display:none}.flow-sdk-node[data-grid-draggable] :not(button):not(input):not(textarea):not(select):not(a){cursor:inherit}"+Nb+qw+Nw+".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}',Cm=!0}function d_({loading:e=!1,loader:r,...t}){var c,l;const[n,o]=j.useState(null),i=j.useMemo(()=>!!(n!=null&&n.json)&&!!t.json&&Iw(n.json,t.json),[n==null?void 0:n.json,t.json]),s=n===null||n.json!==t.json&&!i,a=e||s;return j.useEffect(()=>{!e&&i&&(n==null?void 0:n.json)!==t.json&&o(t)},[e,i,n==null?void 0:n.json,t.json]),j.useEffect(()=>{if(e||!s)return;let d;const u=requestAnimationFrame(()=>{d=requestAnimationFrame(()=>o(t))});return()=>{cancelAnimationFrame(u),d!==void 0&&cancelAnimationFrame(d)}},[e,s,t.json]),f.jsxs(V.Box,{className:t.className,style:t.style,width:"100%",height:"100%",position:"relative","aria-busy":a,children:[f.jsx("div",{style:{width:"100%",height:"100%"},ref:d=>{a?d==null||d.setAttribute("inert",""):d==null||d.removeAttribute("inert")},children:n&&f.jsx(u_,{...s?n:t,children:t.children,config:t.config,className:void 0,style:void 0})}),a&&r!==null&&f.jsx(V.Box,{"data-flow-loader":"",role:"status","aria-label":"Loading diagram",position:"absolute",inset:0,zIndex:1e3,display:"grid",placeItems:"center",background:((c=t.config)==null?void 0:c.colorMode)==="dark"?"gray.800":"gray.100",color:((l=t.config)==null?void 0:l.colorMode)==="dark"?"whiteAlpha.800":"blackAlpha.800",children:r===void 0?f.jsx("span",{children:"Loading diagram..."}):r})]})}function u_({title:e="untitled",json:r,forms:t,nodes:n,edges:o,config:i={},callbacks:s={},className:a,style:c,showBottomBar:l=!0,children:d}){l_();const[u,h]=j.useState(),[p,m]=j.useState(!1),y=i.formSchema??u,g=j.useMemo(()=>r&&t?hb(r,t.state):r,[r,t==null?void 0:t.state]),v=i.direction==="C",b=j.useMemo(()=>{let A,R;return P=>(R=A&&R?Tw(A,P,R)??fd(P,{title:e,isCenter:v}):fd(P,{title:e,isCenter:v}),A=P,R)},[e,v]),x=j.useMemo(()=>g?b(g):null,[g,b]),w=j.useMemo(()=>t!=null&&t.structured&&!p&&y?pb(t.state,t.bindings,y,(x==null?void 0:x.nodes)??n??[]):void 0,[t==null?void 0:t.structured,p,t==null?void 0:t.state,t==null?void 0:t.bindings,y,x,n]),C=(w==null?void 0:w.schema)??y,S=(w==null?void 0:w.bindings)??(t==null?void 0:t.bindings),_=j.useMemo(()=>[...(x==null?void 0:x.nodes)??n??[],...(w==null?void 0:w.nodes)??[]].map(R=>{var ae,se,re,ye;const P=r?(ae=Fe(r,R.data.id))==null?void 0:ae.$view:(se=R.data.config)==null?void 0:se.typeView,T=P&&xd.includes(P)?P:void 0,N=T?T==="icon-label":(re=R.data.config)==null?void 0:re.labelBelow,$=T==="object"?"objectView":T==="text"?"text":N?"arrayView":R.data.type,M=C&&(t?Nn(S,R.data.id,C):r&&Yr(r,R.data.id,C)),W=(((ye=R.data.config)==null?void 0:ye.ports)??[]).map(me=>({...me}));if(w&&M){const me=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[L,z]of Object.entries(M.type.ports??{})){const U=`${z.kind}:${L}`,B=W.find(ce=>ce.id===U);B?B.label===void 0&&z.label!==void 0&&(B.label=z.label):W.push({id:U,...z.label!==void 0?{label:z.label}:{},role:z.kind==="input"||z.kind==="config"?"target":"source",side:me[z.kind],...z.kind==="config"?{placement:"config"}:{}})}for(const L of W){const z=W.filter(U=>U.side===L.side);L.position=(z.indexOf(L)+1)/(z.length+1)}}return M||N||T?{...R,data:{...R.data,type:$,...t?{description:Object.fromEntries(Object.entries(R.data.description??{}).filter(([me])=>!me.startsWith("$")&&!(w!=null&&w.slots.has(pn(R.data.id,me)))))}:{},config:{...R.data.config,...w&&M?{ports:W}:{},...M?{form:!0}:{},...T?{typeView:T,labelBelow:!!N}:N?{labelBelow:!0}:{}}}}:R}),[x,n,r,C,S,w,i.direction]),I=j.useMemo(()=>[...(x==null?void 0:x.edges)??o??[],...(w==null?void 0:w.edges)??[]],[x==null?void 0:x.edges,o,w==null?void 0:w.edges]),E=j.useMemo(()=>{const A=r&&x?Ob(r,x.edges,s,s.onJsonChange,y):{...s};if(w){const R=new Set([...w.nodes.map(P=>P.data.id),...w.edges.map(P=>P.data.id)]);for(const P of Object.keys(A)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(P))continue;const T=A[P];A[P]=(N,...$)=>{if(!R.has(N))return T==null?void 0:T(N,...$)}}}return{...A,onAllNodesIconLabelChange:R=>{var P;m(R),(P=A.onAllNodesIconLabelChange)==null||P.call(A,R)}}},[r,x,s,y,w]),O=j.useMemo(()=>{if(!t)return E;let A=t.state;const R=T=>{if(i.readOnly||i.editable===!1)return;const N=t.onStateChange??t.onChange;if(!N)return;const $=xw(A,T,s.onFormChange);$!==A&&(A=$,N($,{...T,data:$}))},P=(T,N,$)=>{var W;const M=r&&((W=Fe(r,T))==null?void 0:W[N]);return!M||typeof M.$state!="string"?!1:(R({address:M.$state,nodeAddress:T,previousValue:Fe(A,M.$state),value:$,data:A}),!0)};return{...E,onFormChange:R,onNodeCreateRequest:T=>{var M,W;const N=(M=T.sourceProperty)!=null&&M.startsWith("config:")?T.sourceProperty.slice(7):void 0,$=N!==void 0&&(w==null?void 0:w.slots.get(pn(T.sourceNodeId,N)));return $?($.present||R({data:A,nodeAddress:$.address.split(".").slice(0,-1).join("."),address:$.address,value:gn($.type),previousValue:void 0}),!0):((W=E.onNodeCreateRequest)==null?void 0:W.call(E,T))??!1},onNodeDelete:(T,N)=>{var re,ye;if(!(w!=null&&w.nodes.some(me=>me.data.id===T)))return(re=E.onNodeDelete)==null?void 0:re.call(E,T,N);const $=w&&[...w.slots.values()].find(me=>me.nodeId===T);if(!$)return(ye=E.onNodeDelete)==null?void 0:ye.call(E,T,N);const M=$.address.split("."),W=M.pop(),ae=M.join("."),se=Fe(A,ae);R(Array.isArray(se)?{data:A,nodeAddress:ae,address:ae,previousValue:se,value:se.filter((me,L)=>String(L)!==W)}:{data:A,nodeAddress:ae,address:$.address,previousValue:Fe(A,$.address),value:void 0})},onEdgeCreate:(T,N,$)=>{var ae,se;const M=((ae=$==null?void 0:$.targetProperty)==null?void 0:ae.startsWith("config:"))&&(w==null?void 0:w.slots.get(pn(N,$.targetProperty.slice(7)))),W=w==null?void 0:w.containers.get(T);if(M&&W&&($==null?void 0:$.sourceProperty)==="output:resource"){const re=Sw(A,W,M);re!==void 0&&R({data:A,nodeAddress:M.address.split(".").slice(0,-1).join("."),address:M.address,previousValue:Fe(A,M.address),value:re});return}M||w!=null&&w.nodes.some(re=>re.data.id===T||re.data.id===N)||(se=E.onEdgeCreate)==null||se.call(E,T,N,$)},onEdgeDelete:(T,N)=>{var ye;const $=w==null?void 0:w.edges.find(me=>me.data.id===T);if(!$)return(ye=E.onEdgeDelete)==null?void 0:ye.call(E,T,N);const M=w.slots.get(pn($.data.target,$.data.targetProperty.slice(7))),W=M.address.split("."),ae=W.pop(),se=W.join("."),re=Fe(A,se);R(Array.isArray(re)?{data:A,nodeAddress:se,address:se,previousValue:re,value:re.filter((me,L)=>String(L)!==ae)}:{data:A,nodeAddress:se,address:M.address,previousValue:Fe(A,M.address),value:void 0})},onNodeContentChange:(T,N)=>{var $,M;P(T,"$content",N)?($=s.onNodeContentChange)==null||$.call(s,T,N):(M=E.onNodeContentChange)==null||M.call(E,T,N)},onNodeLabelChange:(T,N)=>{var $,M;P(T,"$label",N)?($=s.onNodeLabelChange)==null||$.call(s,T,N):(M=E.onNodeLabelChange)==null||M.call(E,T,N)}}},[E,t,r,s,w,i.readOnly,i.editable]);return f.jsx(Tt.Provider,{value:{data:(t==null?void 0:t.state)??r,viewData:r,bindings:S,references:t==null?void 0:t.references,structured:w,renderForm:t==null?void 0:t.renderForm,editable:t?!!(t.onStateChange??t.onChange):!!s.onJsonChange,schema:C,setSchema:A=>{var R;h(A),(R=s.onFormSchemaChange)==null||R.call(s,A)},callbacks:O},children:f.jsx(Pm,{config:w?{...i,formSchema:C}:i,callbacks:O,nodes:_,edges:I,children:f.jsxs(V.Box,{className:a,"data-flow-diagram":"","data-animations-disabled":i.disableAnimations||void 0,style:c,width:"100%",height:"100%",position:"relative",overflow:"hidden",css:{"&[data-animations-disabled], &[data-animations-disabled] *, &[data-animations-disabled] *::before, &[data-animations-disabled] *::after":{animation:"none !important",transition:"none !important"},"& input, & textarea, & select":{outline:"none !important",boxShadow:"none !important"}},children:[f.jsx(nx,{nodes:_,edges:I}),l&&f.jsx(Rb,{}),d]})})})}function f_(e){return vd(JSON.parse(e))}function vd(e){if(!e||typeof e!="object")throw new Error("Expected a JSON object or array.");const r=new Set,t=n=>{if(!(n===null||typeof n=="string"||typeof n=="boolean")&&!(typeof n=="number"&&Number.isFinite(n))){if(!n||typeof n!="object"||r.has(n)||!Array.isArray(n)&&![Object.prototype,null].includes(Object.getPrototypeOf(n)))throw new Error("Document must contain only finite, acyclic JSON values.");r.add(n);for(const[o,i]of Object.entries(n)){if(["__proto__","prototype","constructor"].includes(o))throw new Error(`Unsafe document key: ${o}`);t(i)}r.delete(n)}};return t(e),structuredClone(e)}function h_(e){return{replaceJson(r){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const t=vd(r);return e.onJsonChange(t,{type:"documentReplace",address:"root"}),t},replaceState(r){if(e.readOnly||!e.onStateChange)throw new Error("Form state is read-only.");const t=vd(r);return e.onStateChange(t,{address:"root",nodeAddress:"root",previousValue:e.state,value:t,data:t}),t}}}function p_(e,r){const t=(n,o)=>{if(n===null||typeof n!="object")return typeof n==typeof o?n:void 0;if(!(!o||typeof o!="object"))return Array.isArray(n)?Array.isArray(o)?n.map((i,s)=>t(i,o[s])).filter(i=>i!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([i,s])=>{if(!Object.prototype.hasOwnProperty.call(o,i))return[];if(i==="$content"&&n.$contentFormat==="jsx"&&o.$contentFormat==="jsx"&&Array.isArray(s)&&Array.isArray(o[i]))return[[i,s.filter((c,l)=>JSON.stringify(c)===JSON.stringify(o[i][l]))]];if(i.startsWith("$")&&i!=="$")return JSON.stringify(s)===JSON.stringify(o[i])?[[i,s]]:[];const a=t(s,o[i]);return a===void 0?[]:[[i,a]]}))};return t(e,r)??{}}function Qn(e){let r="",t=!1,n="",o;const i=()=>{clearTimeout(o),o=void 0},s=()=>{if(i(),!(t||!r.trim()))try{const c=e.parse(e.repair(r)),l=JSON.stringify(c);if(l===n)return;e.preview(c),n=l}catch{}},a=c=>{if(!t){if(new TextEncoder().encode(c).byteLength>(e.maxBytes??1024*1024))throw t=!0,i(),new Error("JSON stream exceeds the size limit.");r=c,o||(o=setTimeout(s,e.intervalMs??150))}};return{snapshot:a,append(c){a(r+c)},flush:s,finish(){if(t)throw new Error("JSON stream is closed.");t=!0,i();const c=e.parse(r);return e.commit(c),c},cancel(){t=!0,i(),r=""}}}function g_(e){const{source:r}=e,t=e.tickMs??50,n=e.durationMs??8e3;if(!Number.isFinite(t)||t<=0||!Number.isFinite(n)||n<=0)throw new Error("Playback timing must be positive.");if(new TextEncoder().encode(r).byteLength>(e.maxBytes??1024*1024))throw new Error("JSON stream exceeds the size limit.");e.parse(r);let o=Qn(e),i=0,s=!1,a=!1,c;const l=Math.max(1,Math.ceil(r.length*t/n)),d=()=>e.onChange({position:i,total:r.length,playing:s}),u=()=>{clearTimeout(c),c=void 0},h=(y=!1)=>{o.snapshot(r.slice(0,i)),i===r.length?(s=!1,u(),o.finish()):y&&o.flush()},p=y=>{s=!1,u(),o.cancel(),d(),e.onError(y)},m=()=>{if(c=void 0,!(!s||a)){i=Math.min(r.length,i+l);try{h()}catch(y){p(y);return}d(),s&&(c=setTimeout(m,t))}};return{play(){a||s||(i===r.length&&(o.cancel(),o=Qn(e),i=0),s=!0,d(),c=setTimeout(m,t))},pause(){a||(s=!1,u(),o.flush(),d())},seek(y){if(!a){if(!Number.isFinite(y))throw new Error("Playback position must be finite.");u(),i=Math.max(0,Math.min(r.length,Math.round(y))),o.cancel(),o=Qn(e);try{h(!0)}catch(g){p(g);return}d(),s&&(c=setTimeout(m,t))}},dispose(){a=!0,s=!1,u(),o.cancel()}}}function y_({nodeAddress:e,expanded:r=!1}){var l;const{data:t,schema:n,bindings:o}=j.useContext(Tt),{colorText:i,background:s}=at();if((l=o==null?void 0:o[e])!=null&&l.portResources)return null;const a=o&&Nn(o,e,n);if(!t||!a)return null;const c=Fe(t,a.address);return!c||typeof c!="object"?null:f.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:Me(i),background:Me(s),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(a.type.properties).map(d=>{const u=a.fields[d]??{};if(!fo(u.$visibleWhen,t))return null;const h=c[d],p=h==null?"":typeof h=="object"?JSON.stringify(h):String(h);return f.jsxs("div",{"data-flow-property":d,style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:12,padding:"10px 16px",borderTop:"1px solid color-mix(in srgb, currentColor 12%, transparent)"},children:[f.jsx("span",{style:{overflowWrap:"anywhere"},children:qt(u.$label??d)}),f.jsx("span",{title:p,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:r?"pre-wrap":"nowrap",overflowWrap:r?"anywhere":void 0},children:p})]},d)})})}exports.BottomBar=Rb;exports.CollapseAllToggle=Qm;exports.CompactPropertyLayoutToggle=eb;exports.ConnectionsOnlyToggle=Mw;exports.DEFAULT_PALETTE=ro;exports.DiagramAppearanceControls=tb;exports.DynamicIcon=Yt;exports.EdgeTools=xb;exports.EditableLabel=Kr;exports.ErrorToast=Eb;exports.FlowDiagram=d_;exports.FlowDiagramProvider=Pm;exports.FlowPort=Zv;exports.FlowView=nx;exports.FormDocumentContext=Tt;exports.GridAdjustmentToggle=rb;exports.LIGHT_BLACK=Jr;exports.LoadingBorder=Yv;exports.NODE_TYPE_VIEWS=xd;exports.NodeBorderRadiusControl=wb;exports.NodeConfigSummary=y_;exports.NodeForm=Td;exports.NodeFormPopover=au;exports.NodeIconPicker=Od;exports.NodeTools=Cb;exports.NodeView=Dn;exports.SvgExportButton=_b;exports.Swatches=Ar;exports.TEXT_PALETTE=bb;exports.ToolbarCloseButton=Zr;exports.ToolbarCommitInput=Br;exports.ToolbarDivider=vn;exports.ToolbarIconButton=Oe;exports.ToolbarRangeInput=Cd;exports.ToolbarScrollContainer=Nd;exports.ToolbarSelect=Mt;exports.ToolbarTooltip=Ke;exports.TooltipIconButton=bd;exports.WorkflowControls=$d;exports.addChild=kd;exports.addConnection=Rd;exports.addTargetEdge=lb;exports.addressToPath=Dt;exports.applyCollapsed=mw;exports.applyFormChange=ho;exports.applyStateEdits=vw;exports.bindSqueedCallbacks=Ob;exports.compileSqueed=fd;exports.connectionIssue=Md;exports.contentObjTheme=Zt;exports.copySelection=qd;exports.createFlowDiagram=Rr;exports.createFlowDocumentActions=h_;exports.createFormNode=Pb;exports.createJsonPlayback=g_;exports.createJsonStream=Qn;exports.createWorkflowExecution=Cx;exports.downloadSvg=jb;exports.duplicateSelection=Tb;exports.exportSvg=Sb;exports.formValueError=Vt;exports.getChakraColorHex=Me;exports.getColorVariant=Em;exports.getDarkerHexColor=eo;exports.getInteractionSurface=hr;exports.getNode=Fe;exports.getSelectionRoots=Ib;exports.parseFlowDocument=f_;exports.parseJsonContract=Ad;exports.parseTypeScriptContract=ub;exports.parseTypeScriptForm=Pd;exports.projectJsonPlaybackPreview=p_;exports.readFormSchema=Id;exports.readWorkflowContract=fb;exports.removeEdge=db;exports.removeNode=cb;exports.reparentNode=Mb;exports.resolveEdgeOwner=Er;exports.resolveStateView=hb;exports.setCollapsed=Ed;exports.setEdgeProp=lr;exports.setEdgeStyle=sb;exports.setNodeProp=wt;exports.updateNode=jt;exports.useCustomColors=at;exports.useEdgeProximity=_m;exports.useFlowData=mr;exports.useFlowDiagramContext=Je;exports.useNodeViewActions=Vn;exports.useStopPropagation=iu;exports.useThemeContentColors=On;exports.validateGridAdjustment=Uv;
|
|
284
284
|
//# sourceMappingURL=index.cjs.map
|