@squeed/flow-sdk 2.0.26 → 2.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";var nx=Object.create;var Mo=Object.defineProperty;var ox=Object.getOwnPropertyDescriptor;var ix=Object.getOwnPropertyNames;var ax=Object.getPrototypeOf,sx=Object.prototype.hasOwnProperty;var cx=(e,r,t)=>r in e?Mo(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var lx=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of ix(r))!sx.call(e,i)&&i!==t&&Mo(e,i,{get:()=>r[i],enumerable:!(n=ox(r,i))||n.enumerable});return e};var rt=(e,r,t)=>(t=e!=null?nx(ax(e)):{},lx(r||!e||!e.__esModule?Mo(t,"default",{value:e,enumerable:!0}):t,e));var Ot=(e,r,t)=>cx(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"),S=require("react"),Br=require("react-dom"),Z=require("react-icons/pi"),mm=require("@emotion/react"),dx=require("@emotion/styled"),ux=require("react-icons/tb"),fx=require("markdown-to-jsx/react"),bm=e=>e&&e.__esModule?e:{default:e},Qn=bm(dx),hx=bm(fx);function px(e,r){let t,n,i,o;const s=(l=t)=>!!l&&["completed","failed","cancelled"].includes(l.status),a=()=>{const l=o;o=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.");i==null||i.abort(),a(),i=new AbortController;const u={executionId:d,input:l,signal:i.signal,state:{executionId:d,status:"subscribing",steps:{}}};n=u,t=u.state,r(t);try{const h=await e.subscribe(u,y=>{n===u&&c(y)});if(n!==u||u.signal.aborted||s())return h(),u.state;if(o=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(){i==null||i.abort(),n=void 0,a()}}}function vm({edge:e,enabled:r,bounds:t,inside:n=[],threshold:i=80}){const[o,s]=S.useState(!1),[a,c]=S.useState(!1),l=S.useRef(n);return l.current=n,S.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]),S.useEffect(()=>{const d=h=>{var v;const p=(v=t.current)==null?void 0:v.getBoundingClientRect();if(!p)return;const y=h.target instanceof Node?h.target:null,m=!!y&&l.current.some(x=>{var w;return(w=x.current)==null?void 0:w.contains(y)}),g=e==="bottom"?p.bottom-h.clientY:h.clientY-p.top,b=h.clientX>=p.left&&h.clientX<=p.right&&g>=0&&g<=i;s(m||b)},u=()=>s(!1);return document.addEventListener("pointermove",d,!0),document.addEventListener("pointerdown",d,!0),document.documentElement.addEventListener("pointerleave",u),()=>{document.removeEventListener("pointermove",d,!0),document.removeEventListener("pointerdown",d,!0),document.documentElement.removeEventListener("pointerleave",u)}},[e,t,i]),r&&(o||a)}const Hr="#c6c6c6";function Hn(e,r=.2){const t=e.replace(/^#/,""),n=parseInt(t,16);let i=n>>16&255,o=n>>8&255,s=n&255;return i=Math.max(0,Math.floor(i*(1-r))),o=Math.max(0,Math.floor(o*(1-r))),s=Math.max(0,Math.floor(s*(1-r))),"#"+((1<<24)+(i<<16)+(o<<8)+s).toString(16).slice(1).toUpperCase()}function gu(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},i=n(e),o=n(r);if(i===null||o===null)return null;const s=a=>Math.round((i>>a&255)*(1-t)+(o>>a&255)*t);return"#"+((1<<24)+(s(16)<<16)+(s(8)<<8)+s(0)).toString(16).slice(1).toUpperCase()}const Kt=e=>e==="transparent"?{background:"transparent",highlight:"transparent",border:"transparent",property:"gray.900",boolean:"green.800",string:"gray.900",number:"orange.800"}:e!=null&&e.startsWith("#")?{background:e,highlight:Hn(e,.1),border:Hn(e,.5),property:"gray.900",boolean:"green.200",string:"gray.900",number:"orange.800"}:e==="gray"?{background:"gray.950",highlight:"gray.800",border:"gray.700",property:"gray.200",boolean:"green.400",string:"gray.200",number:"orange.600"}:e==="white"?{background:"white",highlight:"gray.200",border:"gray.400",property:"gray.900",boolean:"green.400",string:"gray.900",number:"orange.600"}:{background:e+".100",highlight:e+".200",border:e+".700",property:"gray.900",boolean:"green.800",string:"gray.900",number:"orange.800"},xm=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let r=e;if(r!=null&&r.startsWith("#"))return{secondary:Hn(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}},yu={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"}},Ee=(e,r)=>{var o;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,i]=e.split(".");return n&&i&&((o=yu[n])!=null&&o[Number(i)])?yu[n][Number(i)]:`var(--chakra-colors-${t})`},gx=mm.keyframes`
1
+ "use strict";var sx=Object.create;var Lo=Object.defineProperty;var cx=Object.getOwnPropertyDescriptor;var lx=Object.getOwnPropertyNames;var dx=Object.getPrototypeOf,ux=Object.prototype.hasOwnProperty;var fx=(e,r,t)=>r in e?Lo(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var hx=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of lx(r))!ux.call(e,o)&&o!==t&&Lo(e,o,{get:()=>r[o],enumerable:!(n=cx(r,o))||n.enumerable});return e};var rt=(e,r,t)=>(t=e!=null?sx(dx(e)):{},hx(r||!e||!e.__esModule?Lo(t,"default",{value:e,enumerable:!0}):t,e));var Ot=(e,r,t)=>fx(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"),_=require("react"),Dr=require("react-dom"),Z=require("react-icons/pi"),wm=require("@emotion/react"),px=require("@emotion/styled"),gx=require("react-icons/tb"),yx=require("markdown-to-jsx/react"),Cm=e=>e&&e.__esModule?e:{default:e},io=Cm(px),mx=Cm(yx);function bx(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 Sm({edge:e,enabled:r,bounds:t,inside:n=[],threshold:o=80}){const[i,s]=_.useState(!1),[a,c]=_.useState(!1),l=_.useRef(n);return l.current=n,_.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]),_.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 Kr="#c6c6c6";function Qn(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 vu(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 Jt=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:Qn(e,.1),border:Qn(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"},jm=e=>{if(e==="transparent")return{primary:e,secondary:e,light:e};let r=e;if(r!=null&&r.startsWith("#"))return{secondary:Qn(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}},xu={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"}},Ae=(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=xu[n])!=null&&i[Number(o)])?xu[n][Number(o)]:`var(--chakra-colors-${t})`},vx=wm.keyframes`
2
2
  0%, 100% { box-shadow: var(--flow-rest-shadow); }
3
3
  25%, 50% { box-shadow: var(--flow-hover-shadow); }
4
- `,yx=mm.keyframes`
4
+ `,xx=wm.keyframes`
5
5
  from { box-shadow: var(--flow-start-shadow); }
6
6
  to { box-shadow: var(--flow-rest-shadow); }
7
- `;function wm(e,r=!0,t="&:hover",n=!0){const i=`color-mix(in srgb, ${e} 60%, transparent)`,s=`0 0 0 ${r?8:0}px ${i}`,a=`0 0 0 8px ${i}`;return{boxShadow:s,css:{"--flow-rest-shadow":a,"--flow-hover-shadow":`0 0 0 18px ${i}`,"@media (hover: hover)":{[t]:{boxShadow:a,"@media (prefers-reduced-motion: no-preference)":{animation:n?`${gx} 1200ms steps(10, end) 600ms`:"none"}}}}}}function dr(e,r){const{boxShadow:t,css:n}=wm(e,!1),i=n["@media (hover: hover)"]["&:hover"];return{borderWidth:"1px",borderStyle:"solid",borderColor:"transparent",boxShadow:t,...n,"--flow-start-shadow":t,"@media (hover: hover)":{"&:hover":{...i,borderColor:r,"@media (prefers-reduced-motion: no-preference)":{animation:`${yx} 600ms steps(5, end)`}}}}}const Cm=S.createContext(null),Sm=S.createContext({nodeById:new Map,edgeById:new Map,parentIds:new Set});function pr(){return S.useContext(Sm)}function He(){const e=S.useContext(Cm);if(!e)throw new Error("useFlowDiagramContext must be used within FlowDiagram");return e}function jm({config:e,callbacks:r,nodes:t=[],edges:n=[],children:i}){var Me;const o=S.useMemo(()=>{var Se,Ke,Qe;const U=new Map;for(const Ge of t)(Se=Ge.data)!=null&&Se.id&&U.set(Ge.data.id,Ge);const fe=new Map;for(const Ge of n)(Ke=Ge.data)!=null&&Ke.id&&fe.set(Ge.data.id,Ge);const we=new Set;for(const Ge of t)(Qe=Ge.data)!=null&&Qe.parent&&we.add(Ge.data.parent);return{nodeById:U,edgeById:fe,parentIds:we}},[t,n]),s=S.useRef(null),[a,c]=S.useState([]),[l,d]=S.useState(null),[u,h]=S.useState(!0),[p,y]=S.useState(!1),[m,g]=S.useState(!0),[b,v]=S.useState(!1),[x,w]=S.useState(!1),[C,j]=S.useState(!0),[_,k]=S.useState(!1),[E,O]=S.useState(()=>{var U;return(U=e.nodeGrid)!=null&&U.enabled?{...e.nodeGrid.options,...e.nodeGrid.order?{order:e.nodeGrid.order}:{}}:null}),T=S.useRef(E),[P,I]=S.useState(E??((Me=e.nodeGrid)==null?void 0:Me.options)??{gaps:15,fill:!1,padding:0}),[R,$]=S.useState(()=>new Set),N=S.useCallback(U=>{var fe;!!(U!=null&&U.fill)!=!!((fe=T.current)!=null&&fe.fill)&&$(new Set),T.current=U,U&&I(U),O(U)},[]),[M,J]=S.useState("auto"),[ae,se]=S.useState(!1),ee=e.compactPropertyLayout??ae,[pe,me]=S.useState({}),q=e.nodeViewModes??pe,[F,H]=S.useState(e.allNodesIconLabel);S.useEffect(()=>H(e.allNodesIconLabel),[e.allNodesIconLabel]);const[B,de]=S.useState({}),Y=S.useCallback((U,fe)=>{de(we=>{const Se={...we};for(const Ke of U)fe===void 0?delete Se[Ke]:Se[Ke]=fe;return Se})},[]),oe=[...o.nodeById.values()].filter(U=>{var fe;return o.parentIds.has(U.data.id)||((fe=U.data.config)==null?void 0:fe.parentContainer)||U.data.type==="objectView"||U.data.type==="arrayView"||U.data.type==="grid"}),ce=oe.every(U=>{var fe,we,Se;return o.parentIds.has(U.data.id)||(fe=U.data.config)!=null&&fe.parentContainer?!!((we=U.data.config)!=null&&we.collapsed):q[U.data.id]==="icon-label"||U.data.type==="grid"&&q[U.data.id]===void 0||((Se=U.data.config)==null?void 0:Se.labelBelow)&&q[U.data.id]!=="properties"}),xe=F??e.allNodesIconLabel??ce,[je,ye]=S.useState("normal"),[ge,z]=S.useState(),W=e.edgeRadius??ge,ie=W!==void 0&&Number.isFinite(W)?Math.min(500,Math.max(0,W)):void 0,[K,ue]=S.useState(),ve=e.spacing??je,Oe=typeof ve=="number"?Number.isFinite(ve)?Math.min(2,Math.max(e.nodeGridSpacing==="layout"?0:.5,ve)):1:ve==="compact"?.5:ve==="spacious"?2:1,$e=e.backgroundVariant??K??(e.backgroundPattern==="none"&&e.backgroundColor==="transparent"?"transparent":e.backgroundPattern??"dot"),[De,tt]=S.useState(),Ue=Object.prototype.hasOwnProperty.call(e,"workflowContract")?e.workflowContract:De,[yt,Je]=S.useState("blue.500"),[nt,ht]=S.useState(!1),Ie=S.useRef(r);Ie.current=r;const ze=S.useMemo(()=>{const U=fe=>(...we)=>{var Se,Ke;return(Ke=(Se=Ie.current)==null?void 0:Se[fe])==null?void 0:Ke.call(Se,...we)};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:(fe,we)=>{var Se,Ke,Qe;(Se=T.current)!=null&&Se.fill&&$(Ge=>new Set([...Ge,fe])),(Qe=(Ke=Ie.current).onNodeBorderRadiusChange)==null||Qe.call(Ke,fe,we)},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")}},[]),at=e.themeColor||yt,[st,zt]=S.useState(""),Ve=e.edgeColor??st,Ye=e.colorMode||"light",Wt=e.direction||"LR",lt=e.nodeAlignment??"center",rr=e.edgeMode==="workflow"?"nodes":e.edgeMode??M,Ut=e.readOnly??!1,Ir=JSON.stringify(e.parentNodeStyle??null),Rt=S.useMemo(()=>e.parentNodeStyle,[Ir]),Ht=e.isZoomMode!==void 0?e.isZoomMode:u,Xt=e.isMultiSelectMode!==void 0?e.isMultiSelectMode:p,Mr=e.isEdgeHandlesEnabled!==void 0?e.isEdgeHandlesEnabled:b,yr=e.isDragMode!==void 0?e.isDragMode:m,qe=S.useRef(e);qe.current=e;const te=S.useMemo(()=>({get direction(){return qe.current.direction},get nodeAlignment(){return qe.current.nodeAlignment},get edgeMode(){return qe.current.edgeMode},get compactPropertyLayout(){return qe.current.compactPropertyLayout},get bottomBarCollapsed(){return qe.current.bottomBarCollapsed},get bottomBarNavigation(){return qe.current.bottomBarNavigation},get bottomBarFill(){return qe.current.bottomBarFill},get bottomBarCollision(){return qe.current.bottomBarCollision},get nodeGridConnections(){return qe.current.nodeGridConnections},get nodeGrid(){return qe.current.nodeGrid},get edgeType(){return qe.current.edgeType},get edgeReveal(){return qe.current.edgeReveal},get customEdgeTypes(){return qe.current.customEdgeTypes},get themeColor(){return qe.current.themeColor},get colorMode(){return qe.current.colorMode},get readOnly(){return qe.current.readOnly},get editable(){return qe.current.editable},get minZoom(){return qe.current.minZoom},get nodeGridSpacing(){return qe.current.nodeGridSpacing},get maxZoom(){return qe.current.maxZoom},get backgroundPattern(){return qe.current.backgroundPattern},get edgeColor(){return qe.current.edgeColor},get parentNodeStyle(){return qe.current.parentNodeStyle},get backgroundColor(){return qe.current.backgroundColor},get edgeHandles(){return qe.current.edgeHandles},get initialViewport(){return qe.current.initialViewport},get animateViewport(){return qe.current.animateViewport},get disableAnimations(){return qe.current.disableAnimations},get nodeOverlayActions(){return qe.current.nodeOverlayActions},get renderNodeOverlay(){return qe.current.renderNodeOverlay},get renderSelectedNodeToolbar(){return qe.current.renderSelectedNodeToolbar},get renderSelectedEdgeToolbar(){return qe.current.renderSelectedEdgeToolbar},get renderBottomBar(){return qe.current.renderBottomBar},get bottomBarExtra(){return qe.current.bottomBarExtra},get selectionToolbar(){return qe.current.selectionToolbar},get customViews(){return qe.current.customViews},get disableKeyboardShortcuts(){return qe.current.disableKeyboardShortcuts},get isZoomMode(){return qe.current.isZoomMode},get isMultiSelectMode(){return qe.current.isMultiSelectMode},get isEdgeHandlesEnabled(){return qe.current.isEdgeHandlesEnabled},get isDragMode(){return qe.current.isDragMode}}),[]),G=S.useCallback((U,fe)=>{var we;if(fe!=="default"&&fe!=="properties"&&fe!=="icon-label")throw new Error("Unknown node view mode.");H(Se=>Se??xe),me(Se=>Se[U]===fe?Se:{...Se,[U]:fe}),(we=r.onNodeViewModeChange)==null||we.call(r,U,fe)},[r.onNodeViewModeChange,xe]),ne=S.useMemo(()=>({allNodesIconLabel:xe,setAllNodesIconLabel:U=>{var fe,we,Se,Ke,Qe;if(H(U),!U)for(const[Ge,kt]of Object.entries(q))kt==="icon-label"&&!o.nodeById.has(Ge)&&G(Ge,"default");for(const Ge of oe)o.parentIds.has(Ge.data.id)||(fe=Ge.data.config)!=null&&fe.parentContainer?!Ut&&!!((we=Ge.data.config)!=null&&we.collapsed)!==U&&((Se=r.onNodeCollapse)==null||Se.call(r,Ge.data.id,U)):G(Ge.data.id,U?"icon-label":(Ke=Ge.data.config)!=null&&Ke.labelBelow?"properties":"default");(Qe=r.onAllNodesIconLabelChange)==null||Qe.call(r,U)},nodeViewModes:q,setNodeViewMode:G,nodeRadiusPreviews:B,setNodeRadiusPreview:Y,spacing:Oe,setSpacing:ye,edgeRadius:ie,setEdgeRadius:z,backgroundVariant:$e,setBackgroundVariant:ue,themeColor:at,setThemeColor:Je,backgroundSelected:nt,setBackgroundSelected:ht,edgeColor:Ve,setEdgeColor:U=>{var fe;zt(U),(fe=r.onGraphEdgeColorChange)==null||fe.call(r,U)},colorMode:Ye,direction:Wt,nodeAlignment:lt,edgeMode:rr,setEdgeMode:J,compactPropertyLayout:ee,setCompactPropertyLayout:se,workflowContract:Ue,setWorkflowContract:tt,parentNodeStyle:Rt,selectedNodeIds:a,setSelectedNodeIds:c,selectedEdgeId:l,setSelectedEdgeId:d,isZoomMode:Ht,setIsZoomMode:h,isMultiSelectMode:Xt,setIsMultiSelectMode:y,isDragMode:yr,setIsDragMode:g,isEdgeHandlesEnabled:Mr,setIsEdgeHandlesEnabled:v,isArrayNodeMode:x,setIsArrayNodeMode:w,isPinned:C,setIsPinned:j,isPerformanceMode:_,setIsPerformanceMode:k,nodeGridOptions:E,setNodeGridOptions:N,lastNodeGridOptions:P,fillRadiusEditedIds:R,setFillRadiusEditedIds:$,engineRef:s,callbacks:ze,config:te,readOnly:Ut}),[xe,o,G,r.onNodeCollapse,r.onAllNodesIconLabelChange,r.onGraphEdgeColorChange,q,r.onNodeViewModeChange,B,Y,at,Oe,$e,ie,e.backgroundColor,nt,Ve,Ye,Wt,lt,rr,Ue,Rt,a,l,Ht,Xt,yr,Mr,x,C,_,E,P,R,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,ee,ze,te]);return f.jsx(Cm.Provider,{value:ne,children:f.jsx(Sm.Provider,{value:o,children:i})})}function xt(e,r,t){return e?t:r}function An(e){const[r]=(e==null?void 0:e.split("."))||[],{secondary:t}=xm(e),n=Kt(r).background,i=Kt(r).highlight,o=Kt(r).border,s=Kt(r).property,a=Kt(r).property;let c=Kt(r).background,l=Kt(r).highlight;return c=e==="transparent"?e:Ee(c)+50,l=e==="transparent"?e:Ee(l)+20,{bgColor:n,highlightColor:i,borderColor:o,textColor:s,propertyColor:a,secondary:t,bgColorFaint:c,highlightColorFaint:l}}function it(e=null){const{colorMode:r}=He(),t=e==null?void 0:e.includes("gray"),n=r==="dark",i=xt(n,"white","gray.900"),o=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"),y=xt(n,t?"gray.900":"gray.200",t?"gray.200":"gray.900"),m=xt(n,"gray.900","gray.200"),g=xt(n,e&&"#000000",e||"#ffffff"),b=xt(n,e||"#ffffff",e?"#000000":"#ffffff"),v=l,x=xt(n,"gray.300","gray.800"),w=xt(n,"white","blackAlpha.400"),C=xt(n,"green.100","green.700");return{canvas:i,background:o,backgroundSecondary:s,darkBackgroundSecondary:a,border:c,darkColor:d,backgroundWhiteColor:w,borderSecondary:l,colorActive:u,colorInactive:h,iconColor:m,moreIconColor:v,colorText:p,themedColorText:y,logoColor:g,logoColorSecondary:b,darkColorActive:x,greenColor:C}}var sn=(e=>(e.TOP_DOWN="TB",e.BOTTOM_UP="BT",e.LEFT_RIGHT="LR",e.RIGHT_LEFT="RL",e.CENTER="C",e))(sn||{});const hd=["","icon-label","object","text","grid","parent"];var mx=typeof global=="object"&&global&&global.Object===Object&&global,bx=typeof self=="object"&&self&&self.Object===Object&&self,vx=mx||bx||Function("return this")(),Dr=vx.Symbol,_m=Object.prototype,xx=_m.hasOwnProperty,wx=_m.toString,on=Dr?Dr.toStringTag:void 0;function Cx(e){var r=xx.call(e,on),t=e[on];try{e[on]=void 0;var n=!0}catch{}var i=wx.call(e);return n&&(r?e[on]=t:delete e[on]),i}var Sx=Object.prototype,jx=Sx.toString;function _x(e){return jx.call(e)}var Ex="[object Null]",Rx="[object Undefined]",mu=Dr?Dr.toStringTag:void 0;function kx(e){return e==null?e===void 0?Rx:Ex:mu&&mu in Object(e)?Cx(e):_x(e)}function Ax(e){return e!=null&&typeof e=="object"}var Px="[object Symbol]";function Ix(e){return typeof e=="symbol"||Ax(e)&&kx(e)==Px}function Mx(e,r){for(var t=-1,n=e==null?0:e.length,i=Array(n);++t<n;)i[t]=r(e[t],t,e);return i}var et=Array.isArray,bu=Dr?Dr.prototype:void 0,vu=bu?bu.toString:void 0;function Em(e){if(typeof e=="string")return e;if(et(e))return Mx(e,Em)+"";if(Ix(e))return vu?vu.call(e):"";var r=e+"";return r=="0"&&1/e==-1/0?"-0":r}function pd(e){return e==null?"":Em(e)}function Tx(e,r,t){var n=-1,i=e.length;r<0&&(r=-r>i?0:i+r),t=t>i?i:t,t<0&&(t+=i),i=r>t?0:t-r>>>0,r>>>=0;for(var o=Array(i);++n<i;)o[n]=e[n+r];return o}function Ox(e,r,t){var n=e.length;return t=t===void 0?n:t,!r&&t>=n?e:Tx(e,r,t)}var Nx="\\ud800-\\udfff",$x="\\u0300-\\u036f",qx="\\ufe20-\\ufe2f",Lx="\\u20d0-\\u20ff",Fx=$x+qx+Lx,zx="\\ufe0e\\ufe0f",Bx="\\u200d",Dx=RegExp("["+Bx+Nx+Fx+zx+"]");function Rm(e){return Dx.test(e)}function Vx(e){return e.split("")}var km="\\ud800-\\udfff",Gx="\\u0300-\\u036f",Wx="\\ufe20-\\ufe2f",Ux="\\u20d0-\\u20ff",Hx=Gx+Wx+Ux,Kx="\\ufe0e\\ufe0f",Jx="["+km+"]",rd="["+Hx+"]",nd="\\ud83c[\\udffb-\\udfff]",Zx="(?:"+rd+"|"+nd+")",Am="[^"+km+"]",Pm="(?:\\ud83c[\\udde6-\\uddff]){2}",Im="[\\ud800-\\udbff][\\udc00-\\udfff]",Xx="\\u200d",Mm=Zx+"?",Tm="["+Kx+"]?",Yx="(?:"+Xx+"(?:"+[Am,Pm,Im].join("|")+")"+Tm+Mm+")*",Qx=Tm+Mm+Yx,e0="(?:"+[Am+rd+"?",rd,Pm,Im,Jx].join("|")+")",t0=RegExp(nd+"(?="+nd+")|"+e0+Qx,"g");function r0(e){return e.match(t0)||[]}function n0(e){return Rm(e)?r0(e):Vx(e)}function o0(e){return function(r){r=pd(r);var t=Rm(r)?n0(r):void 0,n=t?t[0]:r.charAt(0),i=t?Ox(t,1).join(""):r.slice(1);return n[e]()+i}}var i0=o0("toUpperCase");function a0(e,r,t,n){for(var i=-1,o=e==null?0:e.length;++i<o;)t=r(t,e[i],i,e);return t}function s0(e){return function(r){return e==null?void 0:e[r]}}var c0={À:"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"},l0=s0(c0),d0=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,u0="\\u0300-\\u036f",f0="\\ufe20-\\ufe2f",h0="\\u20d0-\\u20ff",p0=u0+f0+h0,g0="["+p0+"]",y0=RegExp(g0,"g");function m0(e){return e=pd(e),e&&e.replace(d0,l0).replace(y0,"")}var b0=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function v0(e){return e.match(b0)||[]}var x0=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function w0(e){return x0.test(e)}var Om="\\ud800-\\udfff",C0="\\u0300-\\u036f",S0="\\ufe20-\\ufe2f",j0="\\u20d0-\\u20ff",_0=C0+S0+j0,Nm="\\u2700-\\u27bf",$m="a-z\\xdf-\\xf6\\xf8-\\xff",E0="\\xac\\xb1\\xd7\\xf7",R0="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",k0="\\u2000-\\u206f",A0=" \\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",qm="A-Z\\xc0-\\xd6\\xd8-\\xde",P0="\\ufe0e\\ufe0f",Lm=E0+R0+k0+A0,Fm="['’]",xu="["+Lm+"]",I0="["+_0+"]",zm="\\d+",M0="["+Nm+"]",Bm="["+$m+"]",Dm="[^"+Om+Lm+zm+Nm+$m+qm+"]",T0="\\ud83c[\\udffb-\\udfff]",O0="(?:"+I0+"|"+T0+")",N0="[^"+Om+"]",Vm="(?:\\ud83c[\\udde6-\\uddff]){2}",Gm="[\\ud800-\\udbff][\\udc00-\\udfff]",Or="["+qm+"]",$0="\\u200d",wu="(?:"+Bm+"|"+Dm+")",q0="(?:"+Or+"|"+Dm+")",Cu="(?:"+Fm+"(?:d|ll|m|re|s|t|ve))?",Su="(?:"+Fm+"(?:D|LL|M|RE|S|T|VE))?",Wm=O0+"?",Um="["+P0+"]?",L0="(?:"+$0+"(?:"+[N0,Vm,Gm].join("|")+")"+Um+Wm+")*",F0="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",z0="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",B0=Um+Wm+L0,D0="(?:"+[M0,Vm,Gm].join("|")+")"+B0,V0=RegExp([Or+"?"+Bm+"+"+Cu+"(?="+[xu,Or,"$"].join("|")+")",q0+"+"+Su+"(?="+[xu,Or+wu,"$"].join("|")+")",Or+"?"+wu+"+"+Cu,Or+"+"+Su,z0,F0,zm,D0].join("|"),"g");function G0(e){return e.match(V0)||[]}function W0(e,r,t){return e=pd(e),r=r,r===void 0?w0(e)?G0(e):v0(e):e.match(r)||[]}var U0="['’]",H0=RegExp(U0,"g");function K0(e){return function(r){return a0(W0(m0(r).replace(H0,"")),e,"")}}var $t=K0(function(e,r,t){return e+(t?" ":"")+i0(r)});function J0(){let e,r=null;const t=new Set,n=i=>{r=i,t.forEach(o=>o())};return{subscribe:i=>(t.add(i),()=>{t.delete(i)}),getSnapshot:()=>r,select(i,o){e=i,n(o)},update(i,o){e===i&&n(o)},remove(i){e===i&&(e=void 0,n(null))}}}const Vr=S.createContext(null),Z0=()=>S.useState(J0)[0];function eo(e,r=!0){const t=S.useContext(Vr),n=S.useId();return S.useEffect(()=>{r?t==null||t.update(n,e):t==null||t.remove(n)}),S.useEffect(()=>()=>t==null?void 0:t.remove(n),[t,n]),()=>{r&&(t==null||t.select(n,e))}}function X0({divider:e,visibleActions:r=[]}){const t=S.useContext(Vr),n=S.useSyncExternalStore(t.subscribe,t.getSnapshot,()=>null),i=n&&r.includes(n.props["aria-label"]??"");return f.jsx(Vr.Provider,{value:null,children:f.jsxs("span",{"data-recent-toolbar-action":"",style:{display:n&&!i?"contents":"none"},children:[n&&!i&&e,!i&&n]})})}function Be({label:e,children:r}){const t=S.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 pn(){const{border:e}=it(),{colorMode:r}=He();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:i,title:o,icon:s,popupContent:a,footer:c,labelCase:l="title","aria-label":d,...u}){var I;const{colorMode:h}=He(),{background:p,border:y,colorText:m,colorInactive:g}=it(),b=h==="dark",v=S.useId(),x=S.useRef(null),w=S.useRef(null),[C,j]=S.useState(!1),_=eo(f.jsx(Pt,{value:r,onValueChange:t,disabled:n,style:i,title:o,icon:s,popupContent:a,footer:c,labelCase:l,"aria-label":d,children:e}),!!s);S.useEffect(()=>{const R=w.current;R.setAttribute("popover","auto");const $=N=>j(N.newState==="open");return R.addEventListener("toggle",$),()=>R.removeEventListener("toggle",$)},[]);const k=S.Children.toArray(e).filter(S.isValidElement).map(R=>{const $=R.props;return{value:String($.value),label:typeof $.children=="string"&&l==="title"?$t($.children):$.children,disabled:$.disabled}}),E=()=>{var R;return(R=w.current)==null?void 0:R.hidePopover()},O=()=>{var ae,se,ee,pe,me;const R=(ae=x.current)==null?void 0:ae.getBoundingClientRect(),$=w.current;if(!R||!$)return;if((se=x.current)!=null&&se.closest("[popover]")){const q=window.innerHeight-R.bottom-16,F=R.top-16;$.style.maxHeight=`${Math.max(60,q,F)}px`;const H=$.getBoundingClientRect();$.style.left=`${Math.max(12,Math.min(R.right-H.width,window.innerWidth-H.width-12))}px`,$.style.top=`${Math.max(12,H.height<=q?R.bottom+4:R.top-H.height-4)}px`;return}const N=(me=(pe=(ee=x.current)==null?void 0:ee.closest("[data-flow-toolbar-scroll]"))==null?void 0:pe.parentElement)==null?void 0:me.getBoundingClientRect(),M=N??R;$.style.maxHeight=`${Math.max(60,Math.max(M.top-40,window.innerHeight-M.bottom-40))}px`;const J=$.getBoundingClientRect();$.style.left=`${Math.max(12,Math.min(Math.max((N==null?void 0:N.left)??12,R.right-J.width),((N==null?void 0:N.right)??window.innerWidth-12)-J.width,window.innerWidth-J.width-12))}px`,$.style.top=`${Math.max(12,M.top>=J.height+36?M.top-J.height-24:Math.min(M.bottom+24,window.innerHeight-J.height-12))}px`},T=()=>{var N,M,J,ae,se,ee;if(n)return;if((N=w.current)==null||N.showPopover(),O(),a){(J=(M=w.current)==null?void 0:M.querySelector("input"))==null||J.focus({preventScroll:!0});return}const R=(ae=w.current)==null?void 0:ae.querySelectorAll('[role="option"]:not(:disabled)');(ee=((se=w.current)==null?void 0:se.querySelector('[aria-selected="true"]:not(:disabled)'))??(R==null?void 0:R[0]))==null||ee.focus()};S.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 P=`var(--chakra-colors-${p.replace(".","-")})`;return f.jsxs(f.Fragment,{children:[f.jsx(Be,{label:o??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:o??d,"aria-haspopup":a?"dialog":"listbox","aria-expanded":C,"aria-controls":v,disabled:n,h:"30px",w:"160px",px:"6px",fontSize:"12px",border:"none",borderRadius:"4px",bg:"transparent",color:s?g:m,display:"flex",alignItems:"center",justifyContent:s?"center":"space-between",gap:2,style:i,onClick:()=>{_(),C?E():T()},onKeyDown:R=>{["ArrowDown","ArrowUp"].includes(R.key)&&(R.preventDefault(),T())},children:s??f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((I=k.find(R=>R.value===r))==null?void 0:I.label)??r}),f.jsx(Z.PiCaretUp,{size:16,style:{flexShrink:0}})]})})}),f.jsxs(V.chakra.div,{ref:w,id:v,role:a?"dialog":"listbox","aria-label":d,position:"fixed",m:0,p:2,minW:"180px",maxW:"calc(100vw - 24px)",overflowY:"auto",bg:p,color:m,borderRadius:"30px",css:{scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"},'& [role="option"]':Kn,'& details [role="option"]:first-child':{borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},...dr(P,`var(--chakra-colors-${(b?y:"gray.300").replace(".","-")})`)},onKeyDown:R=>{var M,J,ae;if(a&&!["Escape","Tab"].includes(R.key))return;const $=[...R.currentTarget.querySelectorAll('[role="option"]:not(:disabled), [data-flow-menu-action]:not(:disabled)')],N=$.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(R.key)){R.preventDefault();const se=R.key==="Home"?0:R.key==="End"?$.length-1:(N+(R.key==="ArrowDown"?1:-1)+$.length)%$.length;(M=$[se])==null||M.focus()}else R.key==="Escape"||R.key==="Tab"?(R.key==="Escape"&&(R.preventDefault(),R.stopPropagation()),E(),(J=x.current)==null||J.focus()):R.key.length===1&&R.key!==" "&&((ae=$.find((se,ee)=>{var pe;return ee>N&&((pe=se.textContent)==null?void 0:pe.toLowerCase().startsWith(R.key.toLowerCase()))}))==null||ae.focus())},children:[a??k.map(R=>f.jsxs(V.chakra.button,{type:"button",role:"option","aria-selected":R.value===r,disabled:R.disabled,tabIndex:-1,display:"flex",alignItems:"center",gap:3,px:3,py:2,w:"100%",fontSize:"sm",textAlign:"left",bg:"transparent",color:m,_hover:{bg:b?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:b?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var $;E(),($=x.current)==null||$.focus(),t(R.value)},children:[f.jsx("span",{style:{flex:1},children:R.label}),f.jsx(Z.PiCheck,{size:16,color:`var(--chakra-colors-${m.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:R.value===r?"visible":"hidden"}})]},R.value)),c]})]})}const Kn={borderRadius:"4px","&:first-child":{borderTopLeftRadius:"22px",borderTopRightRadius:"22px"},"&:last-child":{borderBottomLeftRadius:"22px",borderBottomRightRadius:"22px"}},Pe=S.forwardRef(function({icon:r,rememberAction:t=!0,...n},i){const{colorMode:o}=He(),s=Object.fromEntries(Object.entries(n).filter(([c])=>c!=="id"&&c!=="aria-describedby"&&!c.startsWith("data-")&&!/^on(Pointer|Mouse|Focus|Blur)/.test(c))),a=eo(f.jsx(Be,{label:n.title??n["aria-label"]??"Last used action",children:f.jsx(Pe,{...s,icon:r})}),t&&!!n.onClick);return f.jsx(V.IconButton,{ref:i,_hover:{bg:o==="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})}),Kr=S.forwardRef(function(r,t){const{themeColor:n}=He();return f.jsx(Be,{label:"Close",children:f.jsx(Pe,{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 qr({label:e,icon:r,checked:t,onChange:n,disabled:i,hideLabel:o=!1,helper:s=e}){const{themeColor:a,readOnly:c}=He(),{colorInactive:l}=it();return f.jsx(Be,{label:s,children:f.jsx(Pe,{"aria-label":e,"aria-pressed":t,icon:f.jsxs(f.Fragment,{children:[r,!o&&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:i||c,onClick:()=>n(!t)})})}function Hm({label:e="Compact layout"}={}){const{compactPropertyLayout:r,setCompactPropertyLayout:t,callbacks:n}=He();return f.jsx(qr,{hideLabel:!0,label:e,checked:r,icon:f.jsx(V.Icon,{as:Z.PiArrowsIn,boxSize:5}),onChange:i=>{var o;t(i),(o=n.onCompactPropertyLayoutChange)==null||o.call(n,i)}})}const Y0=Qn.default.input`
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 je,Xe,Qe;const U=new Map;for(const He of t)(je=He.data)!=null&&je.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 Ce=new Set;for(const He of t)(Qe=He.data)!=null&&Qe.parent&&Ce.add(He.data.parent);return{nodeById:U,edgeById:he,parentIds:Ce}},[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,T]=_.useState(E??(($e=e.nodeGrid)==null?void 0:$e.options)??{gaps:15,fill:!1,padding:0}),[I,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&&T(U),O(U)},[]),[M,K]=_.useState("auto"),[ae,se]=_.useState(!1),te=e.compactPropertyLayout??ae,[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(Ce=>{const je={...Ce};for(const Xe of U)he===void 0?delete je[Xe]:je[Xe]=he;return je})},[]),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,Ce,je;return i.parentIds.has(U.data.id)||(he=U.data.config)!=null&&he.parentContainer?!!((Ce=U.data.config)!=null&&Ce.collapsed):F[U.data.id]==="icon-label"||U.data.type==="grid"&&F[U.data.id]===void 0||((je=U.data.config)==null?void 0:je.labelBelow)&&F[U.data.id]!=="properties"}),xe=D??e.allNodesIconLabel??ue,[ke,ye]=_.useState("normal"),[pe,X]=_.useState(),L=e.edgeRadius??pe,ie=L!==void 0&&Number.isFinite(L)?Math.min(500,Math.max(0,L)):void 0,[H,fe]=_.useState(),be=e.spacing??ke,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=>(...Ce)=>{var je,Xe;return(Xe=(je=Te.current)==null?void 0:je[he])==null?void 0:Xe.call(je,...Ce)};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,Ce)=>{var je,Xe,Qe;(je=A.current)!=null&&je.fill&&N(He=>new Set([...He,he])),(Qe=(Xe=Te.current).onNodeBorderRadiusChange)==null||Qe.call(Xe,he,Ce)},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??M,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 Ce;if(he!=="default"&&he!=="properties"&&he!=="icon-label")throw new Error("Unknown node view mode.");W(je=>je??xe),ve(je=>je[U]===he?je:{...je,[U]:he}),(Ce=r.onNodeViewModeChange)==null||Ce.call(r,U,he)},[r.onNodeViewModeChange,xe]),ne=_.useMemo(()=>({allNodesIconLabel:xe,setAllNodesIconLabel:U=>{var he,Ce,je,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&&!!((Ce=He.data.config)!=null&&Ce.collapsed)!==U&&((je=r.onNodeCollapse)==null||je.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:ie,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:I,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,ie,e.backgroundColor,nt,Ge,De,Wt,lt,nr,Je,Et,a,l,Ht,Yt,br,Tr,x,C,j,E,R,I,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 T;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 I=w.current;I.setAttribute("popover","auto");const N=$=>S($.newState==="open");return I.addEventListener("toggle",N),()=>I.removeEventListener("toggle",N)},[]);const P=_.Children.toArray(e).filter(_.isValidElement).map(I=>{const N=I.props;return{value:String(N.value),label:typeof N.children=="string"&&l==="title"?$t(N.children):N.children,disabled:N.disabled}}),E=()=>{var I;return(I=w.current)==null?void 0:I.hidePopover()},O=()=>{var ae,se,te,me,ve;const I=(ae=x.current)==null?void 0:ae.getBoundingClientRect(),N=w.current;if(!I||!N)return;if((se=x.current)!=null&&se.closest("[popover]")){const F=window.innerHeight-I.bottom-16,D=I.top-16;N.style.maxHeight=`${Math.max(60,F,D)}px`;const W=N.getBoundingClientRect();N.style.left=`${Math.max(12,Math.min(I.right-W.width,window.innerWidth-W.width-12))}px`,N.style.top=`${Math.max(12,W.height<=F?I.bottom+4:I.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(),M=$??I;N.style.maxHeight=`${Math.max(60,Math.max(M.top-40,window.innerHeight-M.bottom-40))}px`;const K=N.getBoundingClientRect();N.style.left=`${Math.max(12,Math.min(Math.max(($==null?void 0:$.left)??12,I.right-K.width),(($==null?void 0:$.right)??window.innerWidth-12)-K.width,window.innerWidth-K.width-12))}px`,N.style.top=`${Math.max(12,M.top>=K.height+36?M.top-K.height-24:Math.min(M.bottom+24,window.innerHeight-K.height-12))}px`},A=()=>{var $,M,K,ae,se,te;if(n)return;if(($=w.current)==null||$.showPopover(),O(),a){(K=(M=w.current)==null?void 0:M.querySelector("input"))==null||K.focus({preventScroll:!0});return}const I=(ae=w.current)==null?void 0:ae.querySelectorAll('[role="option"]:not(:disabled)');(te=((se=w.current)==null?void 0:se.querySelector('[aria-selected="true"]:not(:disabled)'))??(I==null?void 0:I[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:I=>{["ArrowDown","ArrowUp"].includes(I.key)&&(I.preventDefault(),A())},children:s??f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((T=P.find(I=>I.value===r))==null?void 0:T.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:I=>{var M,K,ae;if(a&&!["Escape","Tab"].includes(I.key))return;const N=[...I.currentTarget.querySelectorAll('[role="option"]:not(:disabled), [data-flow-menu-action]:not(:disabled)')],$=N.indexOf(document.activeElement);if(["ArrowDown","ArrowUp","Home","End"].includes(I.key)){I.preventDefault();const se=I.key==="Home"?0:I.key==="End"?N.length-1:($+(I.key==="ArrowDown"?1:-1)+N.length)%N.length;(M=N[se])==null||M.focus()}else I.key==="Escape"||I.key==="Tab"?(I.key==="Escape"&&(I.preventDefault(),I.stopPropagation()),E(),(K=x.current)==null||K.focus()):I.key.length===1&&I.key!==" "&&((ae=N.find((se,te)=>{var me;return te>$&&((me=se.textContent)==null?void 0:me.toLowerCase().startsWith(I.key.toLowerCase()))}))==null||ae.focus())},children:[a??P.map(I=>f.jsxs(V.chakra.button,{type:"button",role:"option","aria-selected":I.value===r,disabled:I.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(I.value)},children:[f.jsx("span",{style:{flex:1},children:I.label}),f.jsx(Z.PiCheck,{size:16,color:`var(--chakra-colors-${y.replace(".","-")})`,"aria-hidden":"true",style:{flexShrink:0,visibility:I.value===r?"visible":"hidden"}})]},I.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`
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
- `,gd=S.forwardRef(function({style:r,...t},n){return f.jsx(Y0,{...t,ref:n,style:{...r,backgroundImage:"none","--flow-range-track":(r==null?void 0:r.backgroundImage)??"none"}})});function od({label:e,inputLabel:r,value:t,displayValue:n,min:i,max:o,step:s=5,onChange:a,onChangeEnd:c}){const l=S.useId(),{readOnly:d,themeColor:u}=He(),{colorInactive:h}=it(),p=(t-i)/(o-i)*100,y=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(gd,{id:l,"aria-label":r,type:"range",min:i,max:o,step:s,value:t,disabled:d,style:{color:y,accentColor:y,backgroundImage:`linear-gradient(to right, currentColor ${p}%, var(--chakra-colors-${h.replace(".","-")}) ${p}%)`},onChange:m=>a(Number(m.target.value)),onPointerUp:c,onKeyUp:c,onBlur:c})]})}const ju={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 Km(){const{spacing:e,setSpacing:r,edgeRadius:t,setEdgeRadius:n,backgroundVariant:i,setBackgroundVariant:o,callbacks:s,readOnly:a,config:c}=He(),l=ju[i].icon;return f.jsxs(f.Fragment,{children:[f.jsx(pn,{}),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(od,{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(pn,{}),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(od,{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(pn,{}),f.jsxs(Pt,{"aria-label":"Background variant",title:`Background: ${ju[i].label}`,icon:f.jsx(l,{size:20,"data-background-icon":i}),style:{width:36},value:i,disabled:a,onValueChange:d=>{var u;o(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 To(){var p;const{engineRef:e,nodeGridOptions:r,lastNodeGridOptions:t,readOnly:n,themeColor:i,callbacks:o,config:s}=He(),{colorText:a,colorInactive:c}=it(),l=r??t,d=typeof l.gaps=="object"?l.gaps.x:l.gaps??l.margin??15,u=Math.max(200,d),h=y=>{var m;return(m=e.current)==null?void 0:m.setNodeGridMode(!0,{...l,...y})};return f.jsxs(f.Fragment,{children:[s.bottomBarCollision!==!1&&f.jsx(qr,{label:"Collision mode",hideLabel:!0,icon:f.jsx(Z.PiGridFour,{size:20}),checked:r!==null,onChange:y=>{var m,g;((m=o.onNodeGridModeRequest)==null?void 0:m.call(o,y,l))!==!0&&((g=e.current)==null||g.setNodeGridMode(y,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(gd,{type:"range","aria-label":"Collision gap",title:`Gap: ${d}`,min:0,max:u,step:5,value:d,disabled:n,style:{color:Ee(i),backgroundImage:`linear-gradient(to right, currentColor ${d/u*100}%, ${Ee(c)} ${d/u*100}%)`},onChange:y=>h({gaps:Number(y.target.value)})})}),f.jsx(V.Text,{fontSize:"xs",color:a,width:"28px",textAlign:"right",fontVariantNumeric:"tabular-nums",children:d})]}),s.bottomBarFill!==!1&&f.jsx(qr,{label:"Fill",hideLabel:!0,helper:"Fill available canvas space",icon:f.jsx(Z.PiArrowsOut,{size:18}),checked:!!r&&!!l.fill,onChange:y=>{var m,g;!r&&((m=o.onNodeGridModeRequest)==null?void 0:m.call(o,!0,{...l,fill:y}))===!0||y&&((g=o.onNodeGridFillRequest)==null?void 0:g.call(o,{...l,fill:y}))===!0||h({fill:y})}}),r&&l.fill&&f.jsx(qr,{label:"Grid adjustment",hideLabel:!0,icon:f.jsx(Z.PiArrowsHorizontal,{size:20}),checked:!!((p=l.adjustment)!=null&&p.enabled),onChange:y=>{n||h({adjustment:{...l.adjustment,enabled:y}})}})]})]})}const wt=[];for(let e=0;e<256;++e)wt.push((e+256).toString(16).slice(1));function Q0(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 Oo;const ew=new Uint8Array(16);function tw(){if(!Oo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Oo=crypto.getRandomValues.bind(crypto)}return Oo(ew)}const rw=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),_u={randomUUID:rw};function yd(e,r,t){var i;if(_u.randomUUID&&!e)return _u.randomUUID();e=e||{};const n=e.random??((i=e.rng)==null?void 0:i.call(e))??tw();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,Q0(n)}const to={label:"Untitled",description:"",isTask:!1,isLocked:!1},md={id:null,type:"text",data:{...to,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"}}},Eu={id:null,type:"objectView",data:{...to,headerTitle:null,viewProps:{width:"100%",borderWidth:2,borderRadius:53,height:"100%",justifyContent:"space-between",flexDirection:"row",textColor:"gray.900"}}},nw={id:null,type:"arrayView",data:{...to,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"}}},Ru={id:null,type:"workflowStep",data:{...to,viewProps:{width:"max-content !important",maxWidth:350,minWidth:280,height:"100%",borderRadius:15,borderWidth:3}}},It=e=>typeof e=="object",Jm=e=>Array.isArray(e),ow=["order","position","selected","locked","grabbed","grabbable","scratch"],ur=e=>Object.entries(e).reduce((r,[t,n])=>(!It(n)&&!t.startsWith("$")&&(r[t]=n),r),{}),bd=(e,r)=>typeof e=="string"&&e.startsWith("$")?No(e,r):It(e)&&!Jm(e)?Object.entries(e).reduce((t,[n,i])=>(typeof i=="string"&&i.startsWith("$")&&n==="..."?(delete t["..."],t[n]={...No(i,r),...e}):typeof i=="string"&&i.startsWith("$")?t[n]=No(i,r):t[n]=i,t),{}):e,fr=e=>Object.entries(e).reduce((r,[t,n])=>(It(n)&&t&&n&&!t.startsWith("$")&&(ow.includes(t)&&(t=t+"#"),r[t]=n),r),{}),wr=(e,r,{label:t,parent:n=void 0},i,o=null)=>(o!==null&&(It(o)||Jm(o))&&(o=JSON.stringify(o,null,2)),{data:{parent:n,...e.data,id:r,text:t||"",label:t,code:o||null,type:e.type,description:i}}),cr=(e,r,t=null,n=null,i=null,o=!1,s=null)=>({data:{id:yd(),source:i?r:e,target:i?e:r,label:n||"",isInverted:i,isEdgeAnimated:o,parent:s}}),hr=(e,r=[])=>{const t={},n={};let i=[];if(e)for(const[o,s]of Object.entries(e))o.startsWith("$")&&o!=="$"?t[o.slice(1)]=s:o!=="$"?n[o]=s:o==="$"&&(i=s);return{newConfig:t,updatedObject:n,arrayObject:i}},Nr=(e,r)=>{let t=Eu;const{view:n,borderColor:i,borderRadius:o,bgColor:s,textColor:a,fontSize:c,stepType:l}=r;e=n||e,l?t={...Ru}:e==="object"?t=Eu:e==="text"?t=md:e==="array"?t=nw:e==="workflowStep"&&(t={...Ru});const d=t.data.viewProps;return t.data.viewProps={...d,borderRadius:o||(l?15:53),bgColor:s,borderColor:i,textColor:a,fontSize:c},t.data.config=r,{config:t}},Sn=(e,r)=>(e=r.find(n=>n.data.id===e)?`${e}.#`:e,e),No=(e,{ids:r,jsnObjct:t})=>{if(typeof e=="string"&&(e!=null&&e.startsWith("$"))){const n=e.replace("$","").replace("*","");e==null||e.endsWith("*");const i=r.find(a=>a.split(".").slice(-1)[0]===n||n===a);if(!i)return e;const o=iw(i,t);return JSON.stringify(o).includes(e)?e:o||e}return e},iw=(e,r)=>{let t=e.split(".").splice(1);return t=t[t.length-1]==="#"||t[t.length-1].includes("{")?t.slice(0,-2):t,(o=>t.reduce((s,a)=>{a=a.replace("[","").replace("]","");const{arrayObject:c}=hr(s);return s=c.length?c:s,s[a]},o))(r)};function Lr(e,r="root",t=[]){try{const{arrayObject:n}=hr(e);n.length&&(e=n);const i=ur(e),o=fr(e);return It(e)?(et(e)||et(e)&&r==="root"||!et(e)&&Object.keys(i).length||r==="root")&&t.push(r):t.push(r),Object.keys(o).length&&!et(e)?gn({chldPth:null,itrblObjct:o,nodes:t,path:r}):et(e)&&e.forEach((s,a)=>{const c=ur(s),l=fr(s),{newConfig:d,arrayObject:u}=hr(s);let h=`${r}.${a}`;It(s)?Object.keys(c).length?(Lr(c,h,t),Object.keys(l).length&&!et(s)&&gn({chldPth:h,itrblObjct:l,nodes:t,path:r})):Object.keys(l).length&&!et(s)?gn({chldPth:h,itrblObjct:l,nodes:t,path:r}):et(s)&&Zm({chldPth:h,item:s,nodes:t,path:r}):t.push(h)}),{nodes:t}}catch{return{nodes:t}}}const gn=({chldPth:e,itrblObjct:r,nodes:t,path:n})=>Object.entries(r).forEach(([i,o],s)=>{const a=ur(o),c=fr(o),{newConfig:l,arrayObject:d}=hr(o);d.length&&(o=d),n.split(".").slice(0,2).join(".");let u=e?`${e}.${i}`:`${n}.${i}`;if(It(o)&&!et(o)){const h=Object.keys(a).length===0;if(h&&(Nr("array",l),t.push(u)),Object.keys(a).length){const p=et(o)?`${o.length||""}`:`{${Object.keys(o).length||""}}`;let y=u;h&&(y=`${u}.${p}`),Lr(o,y,t)}else Object.keys(c).length&&!et(o)?gn({chldPth:u,itrblObjct:c,path:u,nodes:t}):Lr(o,u,t)}else et(o)&&Lr(o,u,t)}),Zm=({chldPth:e,item:r,nodes:t,path:n})=>r.forEach((i,o)=>{let s=`${e}.${o}`;const a=fr(i),c=ur(i);It(i)?!et(i)&&Object.keys(c).length?Lr(i,s,t):Object.keys(a).length&&!et(i)?gn({chldPth:s,itrblObjct:a,path:n,nodes:t}):et(i)&&Zm({chldPth:s,item:i,nodes:t,path:n}):t.push(s)}),yn=[];let mn;function jr(e,r="root",t=[],n=[],i="untitled",o={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"&&(yn.length=0),!mn){const{nodes:d}=Lr(e);mn={ids:d,jsnObjct:e}}let{hideDefaultObject:c,sprtObjctKy:l}=o;try{r=Sn(r,t);const{newConfig:d,arrayObject:u}=hr(e),h=Object.keys(s).length>0?s:d;u.length&&(e=u);const p=ur(e),y=fr(e),{label:m,collapsed:g,parent:b}=h;if(!It(e))t.push(wr(md,r,{label:m||r,parent:b},e,a));else if(et(e)||et(e)&&r==="root"){const{config:v}=Nr("array",h),x=et(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,w=r==="root"?i:`${i} ${x}`;t.push(wr(v,r,{label:m||w,parent:b},e,et(a)?{[i]:a}:a))}else if(!et(e)&&Object.keys(p).length||r==="root"){const{config:v}=Nr(null,h),x=et(e)?`${e.length||""}`:`{${Object.keys(e).length||""}}`,w=r.split("."),C=w[w.length-1];let j=isNaN(Number(C))?null:Number(C)+1;const _=isNaN(Number(C))?C:w[w.length-2]+" "+j,k=r==="root"?i:_;let E=!1;Number.isNaN(Number(i))||(E=!0);const O=e;if(m){const{config:T}=Nr("object",h);t.push(wr(T,r,{label:m||`${m} ${x}`,parent:b},p,O))}else v.data.headerTitle=k,t.push(wr(v,r,{label:m,parent:b},p,O))}return g||(Object.keys(y).length&&!et(e)?bn({flowConfig:o,chldPth:null,edges:n,isInverted:null,itrblObjct:y,nodes:t,path:r,newConfig:h}):et(e)&&e.forEach((v,x)=>{v=bd(v,mn);const w=v,C=ur(v),j=fr(v),{newConfig:_,arrayObject:k}=hr(v);k.length&&(v=k);const{config:E}=Nr(typeof v=="string"?"text":"array",_),{hideConfig:O,sourceLabel:T,label:P,isEdgeAnimated:I,parent:R}=_;c=c||O;const $=r==="root"&&o.isCntr,N=r.split(".").slice(0,2).join("."),M=yn.includes(N),J=o.isCntr&&M||x%2===0&&$;let ae=`${r}.${x}`;ae=Sn(ae,t),J&&yn.push(ae),It(v)?Object.keys(C).length&&!et(v)?(n.push(cr(r,ae,null,T,J,I)),jr(v,ae,t,n,P||x,o,_)):Object.keys(j).length&&!et(v)?bn({flowConfig:o,chldPth:ae,isInverted:J,edges:n,itrblObjct:j,nodes:t,path:r,newConfig:_,forceIsInverted:!0}):et(v)?Xm({flowConfig:o,chldPth:ae,edges:n,isInverted:J,item:v,nodes:t,path:r}):It(v)&&bn({flowConfig:o,chldPth:ae,isInverted:J,edges:n,itrblObjct:[v],nodes:t,path:r,newConfig:_}):(n.push(cr(r,ae,null,T,J,I)),t.push(wr(E,ae,{label:P||String(v),parent:R},v,w)))})),{nodes:t,edges:n}}catch{return{nodes:t,edges:n}}}const bn=({chldPth:e,flowConfig:r,edges:t,itrblObjct:n,nodes:i,isInverted:o,path:s,newConfig:a,forceIsInverted:c=!1})=>{let{hideDefaultObject:l,sprtObjctKy:d}=r;return Object.entries(n).forEach(([u,h],p)=>{h=bd(h,mn);const y=h,m=ur(h),g=fr(h),{newConfig:b,arrayObject:v}=hr(h);v.length&&(h=v);const{hideConfig:x,sourceLabel:w,label:C,content:j,target:_,targetLabel:k,collapsed:E,isEdgeAnimated:O,parent:T}=b;l=l||x;const P=s==="root"&&r.isCntr,I=s.split(".").slice(0,2).join("."),R=yn.includes(I);c||(o=r.isCntr&&R||p%2===0&&P);let $=e?`${e}.${u}`:`${s}.${u}`;if($=Sn($,i),o&&yn.push($),_&&t.push(cr($,_,null,k,o,O)),It(h)&&!et(h)){t.push(cr(s,$,null,w,o,O));const N=d||Object.keys(m).length===0;if(N){const M=j?"object":"array",{config:J}=Nr(M,b);J.data.headerTitle=j?C:null,i.push(wr(J,$,{label:C||u,parent:T},h,y))}if(Object.keys(m).length&&!l){const M=et(h)?` ${h.length||""}`:`{${Object.keys(h).length||""}}`;let J=$;N&&(J=`${$}.${M}`,J=Sn(J,i),t.push(cr($,J,null,w,o,O))),jr(h,J,i,t,C||u,r,b)}else Object.keys(g).length&&!et(h)?bn({chldPth:$,flowConfig:r,itrblObjct:g,path:$,edges:t,nodes:i,newConfig:b,isInverted:o}):jr(h,$,i,t,u,r,b)}else et(h)&&(t.push(cr(s,$,null,w,o,O)),jr(h,$,i,t,u,r,b))})},Xm=({flowConfig:e,chldPth:r,edges:t,isInverted:n,item:i,nodes:o,path:s})=>i.forEach((a,c)=>{let l=`${r}.${c}`;l=Sn(l,o);const d=a;a=bd(a,mn);const u=fr(a),h=ur(a),{newConfig:p}=hr(a),{collapsed:y,label:m,parent:g,sourceLabel:b,isEdgeAnimated:v,content:x}=p;It(a)?!et(a)&&Object.keys(h).length?(t.push(cr(s,l,null,b,n,v)),jr(a,l,o,t,c,e,p)):Object.keys(u).length&&!et(a)&&!y?bn({chldPth:l,flowConfig:e,itrblObjct:u,path:s,edges:t,nodes:o,isInverted:n,newConfig:p}):et(a)&&Xm({flowConfig:e,chldPth:l,edges:t,isInverted:n,item:a,nodes:o,path:s}):(t.push(cr(s,l,null,b,n,v)),o.push(wr(md,l,{label:m||String(a),parent:g},a,d)))});function aw(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 i=new Map(r.nodes.map(l=>[l.data.id,l])),o=l=>{var p,y;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)&&i.has(h)&&((p=Te(e,h))!=null&&p.$collapsed)&&(d=h),u.add(h),h=(y=i.get(h))==null?void 0:y.data.parent;return d},s=new Map(r.nodes.map(l=>[l.data.id,o(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=Te(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 ro(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 i=t;if(typeof i.target!="string"||!/^root(?:\.|$)/.test(i.target))return[];if(i.sourceProperty!==void 0&&typeof i.sourceProperty!="string")return[];if(i.targetProperty!==void 0&&typeof i.targetProperty!="string")return[];const o=typeof i.id=="string"&&i.id?JSON.stringify(["id",i.id]):JSON.stringify(["ports",i.target,i.sourceProperty??null,i.targetProperty??null]),s=r.get(o)??0;return r.set(o,s+1),[{value:i,key:`${o}#${s}`,index:n}]})}function Ym(e,r,t){const n=ro(e).find(c=>c.key===r);if(!n)return e;const i=t(n.value),o=e.$connections.flatMap((c,l)=>l===n.index?i?[i]:[]:[c]);if(o.length)return{...e,$connections:o};const{$connections:s,...a}=e;return a}function sw(e){const r=[],t=(n,i)=>{if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map((o,s)=>t(o,`${i}.${s}`));for(const o of ro(n)){const s=o.value;r.push({data:{id:`connection:${JSON.stringify([i,o.key])}`,source:i,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:i,key:o.key}}})}return Object.fromEntries(Object.entries(n).filter(([o])=>o!=="$connections").map(([o,s])=>[o,o==="$"?t(s,i):o.startsWith("$")?s:t(s,`${i}.${o}`)]))};return{json:t(e,"root"),edges:r}}const Fr="root",ku=e=>e==="#"||e.startsWith("{")||/^\s\d*$/.test(e);function Bt(e){const r=e.split(".");for(r[0]===Fr&&r.shift();r.length&&ku(r[r.length-1]);)r.pop();return r.filter(t=>!ku(t))}function no(e){return e==null||typeof e!="object"?e:Array.isArray(e.$)?e.$:e}function Te(e,r){return Bt(r).reduce((t,n)=>{var i;if(t!=null)return(i=no(t))==null?void 0:i[n]},e)}function cw(e){return Array.isArray(e)?[...e]:{...e}}function Et(e,r,t){const n=Bt(r),i=(o,s)=>{if(s===n.length)return t(o);const a=n[s],c=no(o);if(c==null||typeof c!="object")return o;const l=i(c[a],s+1);if(Object.is(l,c[a]))return o;const d=cw(c);return d[a]=l,c!==o?{...o,$:d}:d};return i(e,0)}function Qt(e,r,t){const n=t===""&&r!=="$content"||t===void 0||t===null;if(Array.isArray(e))return n?e:{[r]:t,$:[...e]};const i=e!=null&&typeof e=="object"?{...e}:{};return e!=null&&typeof e!="object"&&(i.$label=String(e)),n?delete i[r]:i[r]=t,i}function Ct(e,r,t,n){return Et(e,r,i=>t==="$label"&&typeof i=="string"&&typeof n=="string"&&n!==""?n:Qt(i,t,n))}const vd=(e,r,t)=>Ct(e,r,"$collapsed",t);function Cr(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,i=Bt(t).join("."),o=Bt(n).join(".");return o.startsWith(i?i+".":"")&&o!==i?{address:n,kind:"hierarchy"}:i.startsWith(o?o+".":"")&&i!==o?{address:t,kind:"hierarchy"}:{address:t,kind:"target"}}function sr(e,r,t,n){if(r.connection){const a=r.connection;return Et(e,a.address,c=>Ym(c,a.key,l=>{if(t==="$edgeIcon")return Qt(l,"icon",n);if(t==="$edgeType")return Qt(l,"type",n);if(t==="$edgeAnimationVariant")return Qt(l,"animationVariant",n);if(t==="$sourceLabel"||t==="$edgeColor")return Qt(l,t==="$sourceLabel"?"label":"color",n);const d=t==="$isEdgeAnimated"?"animated":"dashed";return n?{...l,style:d}:l.style===d?Qt(l,"style",void 0):l}))}const{address:i,kind:o}=Cr(r),s=o==="target"&&t==="$sourceLabel"?"$targetLabel":o==="target"&&t==="$edgeType"?"$targetEdgeType":o==="target"&&t==="$edgeIcon"?"$targetIcon":o==="target"&&t==="$edgeAnimationVariant"?"$targetAnimationVariant":t;return Et(e,i,a=>Qt(a,s,n))}const Qm=(e,r,t)=>sr(sr(e,r,"$isEdgeAnimated",t==="animated"||void 0),r,"$isEdgeDashed",t==="dashed"||void 0);function xd(e,r,t,n){let i=n||"";const o=Et(e,r,a=>{const c=no(a);if(Array.isArray(c)){i=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(!i){let d=1;for(;`node_${d}`in l;)d++;i=`node_${d}`}return l[i]=t,l}),s=Bt(r);return{json:o,address:[Fr,...s,i].join(".")}}function eb(e,r){const t=Bt(r);if(!t.length)return e;const n=t[t.length-1],i=[Fr,...t.slice(0,-1)].join(".");return Et(e,i,o=>{const s=no(o);if(s==null||typeof s!="object"||!Object.prototype.hasOwnProperty.call(s,n))return o;if(Array.isArray(s)){const l=s.filter((d,u)=>String(u)!==n);return s===o?l:{...o,$:l}}const{[n]:a,...c}=o;return c})}const tb=(e,r,t,n)=>Ct(n?Et(e,r,i=>Qt(i,"$targetLabel",n)):e,r,"$target",t);function wd(e,r,t){const n=Te(e,r);return ro(n).some(({value:o})=>o.target===t.target&&o.sourceProperty===t.sourceProperty&&o.targetProperty===t.targetProperty)?e:Et(e,r,o=>Qt(o,"$connections",[...Array.isArray(o==null?void 0:o.$connections)?o.$connections:[],{...t,id:t.id||yd()}]))}function rb(e,r){if(r.connection){const o=r.connection;return ro(Te(e,o.address)).some(s=>s.key===o.key)?{json:Et(e,o.address,s=>Ym(s,o.key,()=>null)),removed:!0}:{json:e,removed:!1}}const{address:t,kind:n}=Cr(r);return n==="hierarchy"?Te(e,t)===void 0?{json:e,removed:!1}:{json:Et(e,t,o=>({...o,$hideParentEdge:!0})),removed:!0}:n!=="target"?{json:e,removed:!1}:{json:Et(e,t,o=>{const{$target:s,$targetLabel:a,...c}=o||{};return c}),removed:!0}}function id(e,r={}){var v;const t=sw(e),{nodes:n,edges:i}=jr(t.json,Fr,[],[],r.title||"untitled",{hideDefaultObject:!!r.hideDefaultObject,sprtObjctKy:!!r.separateObjectKeys,isCntr:!!r.isCenter}),o=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")||Te(e,w)!==void 0)continue;const C=w.slice(0,-2),j=Te(e,C);!o.has(C)&&j&&typeof j=="object"&&!Array.isArray(j)&&typeof j.$label=="string"&&Object.keys(j).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 i){const C=Cr(w);if(C.kind==="hierarchy")l.set(a(C.address),!!w.isInverted);else if(!Array.isArray(e)&&e.$hideRoot===!0){const j=a(w.isInverted?w.source:w.target);if(Bt(j).length!==1)continue;const _=!!w.isInverted;x.set(j,x.has(j)&&x.get(j)!==_?null:_)}}for(const[w]of l){const C=`${Fr}.${Bt(w)[0]}`,j=x.get(C);typeof j=="boolean"&&l.set(w,j)}}const d=n.map(x=>{var E;const w=a(x.data.id),C=Te(e,w),j={...x.data,id:w};l.has(w)&&(j.config={...j.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("$")))&&(j.config={...j.config,collapsed:!!C.$collapsed}),c.has(w)||(j.viewProps={...j.viewProps},delete j.viewProps.borderWidth),!C||typeof C!="object"||Array.isArray(C))return{data:j};if(C.$view==="parent"&&(j.type="objectView",j.config={...j.config,typeView:"parent",parentContainer:!0,collapsed:!!C.$collapsed}),C.$view==="grid"){j.type="grid";const O=C.$gridSize;if(O!==void 0&&(!O||![O.width,O.height].every(T=>Number.isFinite(T)&&T>0&&T<=16384)))throw new Error("Invalid grid frame size.");j.config={...j.config,typeView:"grid",documentId:C.$document,gridSize:O},j.viewProps={...j.viewProps,bgColor:C.$bgColor??"transparent",borderRadius:C.$borderRadius??0,borderWidth:C.$borderWidth??0}}if(C.$form&&typeof C.$form=="object"&&(j.config={...j.config,form:C.$form},j.type="objectView"),Array.isArray(C.$ports)){const O=C.$ports.filter(T=>T&&typeof T.id=="string"&&["source","target"].includes(T.role)&&["top","right","bottom","left"].includes(T.side));j.config={...j.config,ports:O}}if(j.parent&&(j.parent=a(j.parent)),typeof C.$label=="string"&&(j.label=C.$label,j.headerTitle=C.$label),typeof C.$subtitle=="string"&&(j.config={...j.config,subtitle:C.$subtitle}),typeof C.$outline=="boolean"&&(j.viewProps={...j.viewProps,outline:C.$outline}),["solid","dashed","dotted","double"].includes(C.$borderStyle)&&(j.viewProps={...j.viewProps,borderStyle:C.$borderStyle}),Number.isFinite(C.$borderWidth)&&C.$borderWidth>=0&&(j.viewProps={...j.viewProps,borderWidth:C.$borderWidth}),Number.isFinite(C.$borderRadius)&&C.$borderRadius>=0&&(j.viewProps={...j.viewProps,borderRadius:C.$borderRadius}),typeof C.$isNodeAnimated=="boolean"&&(j.isNodeAnimated=C.$isNodeAnimated),["traveling","pulse"].includes(C.$nodeAnimationVariant)&&(j.nodeAnimationVariant=C.$nodeAnimationVariant),typeof C.$content=="string"||C.$contentFormat==="jsx"&&Array.isArray(C.$content)){j.config={...j.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.");j.config.contentFormat=O,C.$view||(j.type="objectView")}return(((E=j.config)==null?void 0:E.collapsed)!==void 0||C.$collapsed!==void 0||C.$icon!==void 0)&&(j.config={...j.config||{}},(C.$collapsed!==void 0||j.config.collapsed!==void 0)&&(j.config.collapsed=!!C.$collapsed),C.$icon!==void 0&&(j.config.icon=C.$icon)),{data:j}}),u=new Map,h=i.map(x=>{let w=a(x.data.source),C=a(x.data.target),j=x.data.isInverted;const _=Cr(x.data),k=l.get(a(_.address));_.kind==="hierarchy"&&k!==void 0&&k!==!!j&&([w,C]=[C,w],j=k);const E=`${w}->${C}`,O=u.get(E)??0;u.set(E,O+1);const T={...x.data,id:O?`${E}#${O}`:E,source:w,target:C,isInverted:j},P=Cr(T),I=Te(e,P.address);if(I&&typeof I=="object"){const R=I[P.kind==="target"?"$targetEdgeType":"$edgeType"];typeof R=="string"&&(T.type=R);const $=I[P.kind==="target"?"$targetIcon":"$edgeIcon"];typeof $=="string"&&(T.icon=$),I.$isEdgeAnimated!==void 0&&(T.isEdgeAnimated=!!I.$isEdgeAnimated);const N=I[P.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes(N)&&(T.edgeAnimationVariant=N),I.$isEdgeDashed!==void 0&&(T.isEdgeDashed=!!I.$isEdgeDashed),I.$edgeColor&&(T.color=I.$edgeColor)}return{data:T}});if(!Array.isArray(e)&&(e==null?void 0:e.$hideRoot)===!0){const x=d.findIndex(w=>w.data.id===Fr);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=Cr(w);(!p.has(w.source)||!p.has(w.target)||C.kind==="hierarchy"&&((v=Te(e,C.address))==null?void 0:v.$hideParentEdge)===!0)&&h.splice(x,1)}h.push(...t.edges.filter(x=>p.has(x.data.source)&&p.has(x.data.target)));const y=aw(e,{nodes:d,edges:h}),m=y.nodes.filter(x=>{var w;return(w=x.data.config)==null?void 0:w.collapsed}).map(x=>Bt(x.data.id));if(!m.length)return y;const g=y.nodes.filter(x=>{const w=Bt(x.data.id);return!m.some(C=>C.length<w.length&&C.every((j,_)=>j===w[_]))}),b=new Set(g.map(x=>x.data.id));return{nodes:g,edges:y.edges.filter(x=>b.has(x.data.source)&&b.has(x.data.target))}}function lw(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])),i=new Set(e.map(c=>c.data.parent).filter(Boolean)),o=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=>o.get(c.data.id)!==c.data.id).map(c=>c.data.id));for(const c of t){if(i.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)&&i.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=o.get(c.data.source)??c.data.source,d=o.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 Cd(e,r){const t=JSON.parse(e);let n=512;const i=(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 i(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=>i(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(y=>y===p||y==="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=>i({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:i(h,a),optional:!(s.required??[]).includes(u)}]))}}if(s.type==="array")return{kind:"array",items:i(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.")},o=i(t);if(o.kind!=="object")throw new Error("The root schema must be an object keyed by node ID.");if(Object.values(o.properties).some(s=>s.type.kind!=="object"))throw new Error("Each node must declare an object of property types.");return{name:r,nodes:o.properties}}async function Sd(e,r,t,n={}){var y;let i=512;const o=await import("typescript"),s=o.createSourceFile(r,e,o.ScriptTarget.Latest,!0,o.ScriptKind.TS),a=s.parseDiagnostics;if(a!=null&&a.length)throw new Error("Invalid TypeScript syntax.");const c=new Map;for(const m of s.statements){if(!o.isInterfaceDeclaration(m)&&!o.isTypeAliasDeclaration(m))throw new Error("Upload interfaces/type aliases only; imports and executable code are not supported.");if((y=m.typeParameters)!=null&&y.length||c.has(m.name.text))throw new Error("Generics and duplicate declarations are not supported.");c.set(m.name.text,m)}const l=(m,g)=>{var C;const b={},v=m.find(j=>o.isIndexSignatureDeclaration(j));let x;if(v&&n.allowJson&&o.isIndexSignatureDeclaration(v)){if(m.filter(j=>o.isIndexSignatureDeclaration(j)).length!==1||v.parameters.length!==1||((C=v.parameters[0].type)==null?void 0:C.kind)!==o.SyntaxKind.StringKeyword||!v.type)throw new Error("Only one string-keyed index signature is supported for forms.");x=u(v.type,g)}return{kind:"object",properties:Object.fromEntries(m.filter(j=>j!==v||!x).map(j=>{if(!o.isPropertySignature(j)||!j.type||!j.name||!o.isIdentifier(j.name)&&!o.isStringLiteral(j.name))throw new Error("Only explicitly typed named properties are supported.");const _=u(j.type,g),k=n.allowJson?o.getJSDocTags(j).filter(E=>E.tagName.text==="port"):[];if(k.length>1)throw new Error(`Duplicate port declaration: ${j.name.text}`);if(k.length){const[E,O,T]=String(k[0].comment??"").trim().split(/\s+/);if(E!=="config"||!O||T||!c.has(O))throw new Error(`Config port ${j.name.text} requires @port config ResourceType`);const P=_.kind==="array";if((_.kind==="array"?_.items.kind:_.kind)!=="string")throw new Error(`Config port ${j.name.text} must be a string or string array reference`);b[j.name.text]={kind:"config",resourceType:O,multiple:P}}return[j.name.text,{type:_,optional:!!j.questionToken}]})),...x?{additionalProperties:x}:{},...Object.keys(b).length?{ports:b}:{}}},d=(m,g)=>{var C;if(g.includes(m))throw new Error("Recursive types are not supported.");const b=c.get(m);if(!b)throw new Error(`Unknown type: ${m}`);let v;if(o.isInterfaceDeclaration(b)){if((C=b.heritageClauses)!=null&&C.length)throw new Error("Interface inheritance is not supported; declare properties explicitly.");v=l(b.members,[...g,m])}else v=u(b.type,[...g,m]);const x=n.allowJson?o.getJSDocTags(b).filter(j=>j.tagName.text==="port"):[];if(!x.length)return v;if(v.kind!=="object")throw new Error("Node ports require an object interface");const w={...v.ports};for(const j of x){const[_,k,...E]=String(j.comment??"").trim().split(/\s+/);if(!["input","output","error"].includes(_)||!/^[A-Za-z][\w-]*$/.test(k??""))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,k))throw new Error(`Duplicate port declaration: ${k}`);w[k]={kind:_,...typeof O=="string"?{label:O}:{}}}return{...v,ports:w}},u=(m,g)=>{var b,v,x;if(--i<0)throw new Error("Interface exceeds the 512-type expansion limit.");if(m.kind===o.SyntaxKind.StringKeyword)return{kind:"string"};if(m.kind===o.SyntaxKind.NumberKeyword)return{kind:"number"};if(m.kind===o.SyntaxKind.BooleanKeyword)return{kind:"boolean"};if(n.allowJson&&[o.SyntaxKind.AnyKeyword,o.SyntaxKind.UnknownKeyword].includes(m.kind))return{kind:"json"};if(o.isParenthesizedTypeNode(m))return u(m.type,g);if(o.isUnionTypeNode(m))return{kind:"union",types:m.types.map(w=>u(w,g))};if(o.isArrayTypeNode(m))return{kind:"array",items:u(m.elementType,g)};if(o.isTypeLiteralNode(m))return l(m.members,g);if(o.isLiteralTypeNode(m)){const w=m.literal;if(o.isStringLiteral(w))return{kind:"literal",value:w.text};if(o.isNumericLiteral(w))return{kind:"literal",value:Number(w.text)};if(w.kind===o.SyntaxKind.NullKeyword)return{kind:"null"};if(w.kind===o.SyntaxKind.TrueKeyword||w.kind===o.SyntaxKind.FalseKeyword)return{kind:"literal",value:w.kind===o.SyntaxKind.TrueKeyword}}if(o.isTypeReferenceNode(m)&&o.isIdentifier(m.typeName)){if(n.allowJson&&m.typeName.text==="Record"&&!c.has("Record")&&((b=m.typeArguments)==null?void 0:b.length)===2&&m.typeArguments[0].kind===o.SyntaxKind.StringKeyword)return{kind:"object",properties:{},additionalProperties:u(m.typeArguments[1],g)};if(m.typeName.text==="Array"&&((v=m.typeArguments)==null?void 0:v.length)===1)return{kind:"array",items:u(m.typeArguments[0],g)};if(!((x=m.typeArguments)!=null&&x.length))return d(m.typeName.text,g)}throw new Error(`Unsupported TypeScript type: ${m.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 nb(e,r){const t=await Sd(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 cn(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=>cn(t,r));if(r.kind==="union")return r.types.some(t=>cn(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"?cn(e.items,r.items):e.kind==="object"&&r.kind==="object"?Object.entries(r.properties).every(([t,n])=>{const i=Object.prototype.hasOwnProperty.call(e.properties,t)?e.properties[t]:void 0;return i?(n.optional||!i.optional)&&cn(i.type,n.type):n.optional}):e.kind===r.kind}function jd(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),i=t(r.target,r.targetProperty);if(!n||!i)return"Unverified: source or target property is missing from the interface.";const o=s=>s.kind==="json"||s.kind==="object"&&(!!s.additionalProperties||Object.values(s.properties).some(a=>o(a.type)))||s.kind==="array"&&o(s.items)||s.kind==="union"&&s.types.some(o);if(o(n.type)||o(i.type))return"Unverified: arbitrary JSON or dictionary fields require runtime validation.";if(n.optional&&!i.optional)return"Optional source cannot supply a required target property.";if(!cn(n.type,i.type))return`Incompatible property types: ${r.sourceProperty} -> ${r.targetProperty}.`}async function ob(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 Cd(r,e.name);if(/\.ts$/i.test(e.name))return nb(r,e.name);throw new Error("Choose a .ts interface or .json JSON Schema file.")}const Au=new WeakMap;function Gr(e){if(!e||typeof e!="object")return e;const r=Au.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:(i,o)=>Gr(Reflect.get(e,o)),has:(i,o)=>Reflect.has(e,o),ownKeys:()=>Reflect.ownKeys(e),getOwnPropertyDescriptor:(i,o)=>{const s=Reflect.getOwnPropertyDescriptor(e,o);return s&&{...s,value:Gr(Reflect.get(e,o)),configurable:o!=="length"||!Array.isArray(e)}},set:t,deleteProperty:t,defineProperty:t,setPrototypeOf:t,preventExtensions:t});return Au.set(e,n),n}function Jr(e,r,t){var i;const n=r.split(".");for(let o=n.length;o>0;o--){const s=n.slice(0,o).join("."),a=(i=Te(e,s))==null?void 0:i.$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(o))(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(o).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 _d(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 i=[],o=new Set(r);for(const s of o){if(o.size>32)throw new Error("Choose between 1 and 32 form interface names.");const a=await Sd(t,e.name,s,{allowJson:!0});i.push([s,a]);for(const c of Object.values(a.ports??{}))c.resourceType&&o.add(c.resourceType)}return Object.fromEntries(i)}if(!e.name.endsWith(".json"))throw new Error("Choose a .ts interface or .json schema file.");const n=Cd(t,e.name);return Object.fromEntries(Object.entries(n.nodes).map(([i,o])=>[i,o.type]))}function oo(e,r){return!e||("$in"in e?e.$in.includes(Te(r,e.$address)):Te(r,e.$address)===e.$equals)}function vn(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,i=o=>{if(o===null||typeof o=="string"||typeof o=="boolean")return!0;if(typeof o=="number")return Number.isFinite(o);if(!o||typeof o!="object"||n.has(o)||!Array.isArray(o)&&![Object.prototype,null].includes(Object.getPrototypeOf(o)))return!1;n.add(o);const s=Object.values(o).every(i);return n.delete(o),s};return i(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,i])=>!Object.prototype.hasOwnProperty.call(e.properties,n)&&Dt(e.additionalProperties,i,!0))?"Invalid dictionary value":Object.entries(e.properties).some(([n,i])=>Dt(i.type,r[n],!i.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 Pu(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(),i=n==="$bgColor"||n==="$textColor"||n==="$borderColor";if(t.some(a=>a.startsWith("$"))||n.startsWith("$")&&!i)throw new Error("Unsupported form metadata address.");const o=["root",...t].join("."),s=Te(e,o);if(!s||typeof s!="object")throw new Error(`Missing form parent: ${o}`);if(i){if(r.op==="set"&&typeof r.value!="string")throw new Error("Node colors must be strings.");return Ct(e,o,n,r.op==="remove"?void 0:r.value)}return Et(e,o,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 io(e,r,t){let n=Pu(e,r.value===void 0?{op:"remove",address:r.address}:{op:"set",address:r.address,value:r.value});const i=t==null?void 0:t({...r,previousValue:Gr(Te(e,r.address)),data:Gr(n)});if(i&&!Array.isArray(i))throw new Error("Form change handlers must return edits synchronously.");for(const o of Array.isArray(i)?i:[]){if(o.op!=="set"&&o.op!=="remove")throw new Error("Unsupported form edit.");n=Pu(n,o)}return n}const xn="data:image/svg+xml;base64,";function ir(e){if(e.startsWith(xn))return!0;try{const r=new URL(e);return(r.protocol==="https:"||r.protocol==="http:")&&!r.username&&!r.password}catch{return!1}}async function dw(e){if(e.size>256*1024)throw new Error("SVG must be 256 KB or smaller.");const r=await e.text(),t=new DOMParser().parseFromString(r,"image/svg+xml");if(t.doctype||t.querySelector("parsererror")||t.documentElement.localName!=="svg"||t.documentElement.namespaceURI!=="http://www.w3.org/2000/svg")throw new Error("Choose a valid SVG file.");if(t.querySelector("script, foreignObject")||[...t.querySelectorAll("*")].some(o=>[...o.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 i="";for(const o of n)i+=String.fromCharCode(o);return xn+btoa(i)}const Jt=({name:e,svg:r=!1,...t})=>{const[n,i]=S.useState(null),[o,s]=S.useState(!0),[a,c]=S.useState(!1),l=typeof e=="string"&&ir(e);if(S.useEffect(()=>{if(l||!e||e.length<2){i(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}`);i(()=>p)}catch(u){console.warn(`Failed to load icon ${e}:`,u.message),c(!0),i(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 o||!n?null:f.jsx(n,{...t})};function uw(e,r){let t=e;for(const n of r){if(n.op!=="set"&&n.op!=="remove")throw new Error("Unsupported state edit.");const i=n.address.split(".");if(i.some(s=>s.startsWith("$")||["__proto__","prototype","constructor"].includes(s)))throw new Error("State edits cannot target view metadata or unsafe keys.");const o=n.op==="remove"?void 0:n.value;jn(o),t=io(t,{address:n.address,nodeAddress:i.slice(0,-1).join("."),value:o})}return jn(t),t}function Pn(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 jn(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}`);jn(t)}}function fw(e,r,t){jn(r.value);const n=io(e,r,t);return jn(n),n}function ib(e,r){const t=(n,i="")=>{if(!n||typeof n!="object")return n;if(["$label","$subtitle","$content","$icon","$bgColor","$textColor","$borderColor"].includes(i)&&typeof n.$state=="string"){const s=Te(r,n.$state);return s==null?"":typeof s=="object"?JSON.stringify(s,null,2):String(s)}let o=n;for(const[s,a]of Object.entries(n)){const c=t(a,s);c!==a&&(o===n&&(o=Array.isArray(n)?[...n]:{...n}),Object.defineProperty(o,s,{value:c,enumerable:!0,writable:!0,configurable:!0}))}return o};return t(e)}const hw=e=>!!e&&!e.includes(".")&&!e.startsWith("$")&&!["__proto__","constructor","prototype"].includes(e),pw=e=>`root.__form_${encodeURIComponent(e).replace(/\./g,"%2E")}`,ln=(e,r)=>JSON.stringify([e,r]);function _n(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 _n(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 dn(e){const r=_n(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 Iu(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"&&!vn(e)?e.types:[e]}function gw(e,r,t){if(r.address===t.address)return;const n=Te(e,r.address),i=(o,s)=>s===void 0?!1:o.kind==="union"?o.types.some(a=>i(a,s)):o.kind==="array"?Array.isArray(s)&&s.every(a=>i(o.items,a)):o.kind==="object"?!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(o.properties).every(([a,c])=>c.optional&&s[a]===void 0||i(c.type,s[a]))&&Object.entries(s).every(([a,c])=>Object.prototype.hasOwnProperty.call(o.properties,a)||!o.additionalProperties||i(o.additionalProperties,c)):s===""?o.kind==="string"||o.kind==="json"||o.kind==="literal"&&o.value==="":!Dt(o,s,!0);if(i(t.type,n))return structuredClone(n)}function ab(e,r,t,n){var c,l;const i={sourceSchema:t,sourceBindings:r,nodes:[],edges:[],schema:{...t},bindings:{...r},slots:new Map,containers:new Map},o=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,y,m=!1)=>{var _,k,E,O,T;if(y>24||i.containers.size>512)throw new Error("Structured form exceeds the flow node limit.");const g=Te(e,u),b=_n(h,g),v=b.kind!=="object"&&b.kind!=="array";i.containers.set(d,{address:u,type:b,declared:h,scalar:v});const x=`__form:${d}`,w={...(_=i.bindings[d])==null?void 0:_.fields},C={kind:"object",properties:{},ports:{...b.kind==="object"?b.ports:{},...m?{resource:{label:"output",...b.kind==="object"?(k=b.ports)==null?void 0:k.resource:{},kind:"output"}}:{}}},j=b.kind==="object"?{...b.properties,...Object.fromEntries(Object.keys(g??{}).filter(P=>!Object.prototype.hasOwnProperty.call(b.properties,P)&&b.additionalProperties).map(P=>[P,{type:b.additionalProperties,optional:!0}]))}:b.kind==="array"?Object.fromEntries((Array.isArray(g)?g:[]).map((P,I)=>[String(I),{type:b.items,optional:!0}])):{value:{type:vn(h)?h:b,optional:!1}};for(const[P,I]of Object.entries(j)){if(!hw(P))throw new Error(`Unsupported structured property key: ${P}`);const R=v?u:`${u}.${P}`,$=Te(e,R),N=_n(I.type,$),M=N.kind==="object"||N.kind==="array",J=(E=C.ports)==null?void 0:E[P],ae=(J==null?void 0:J.kind)==="config"&&(((O=w[P])==null?void 0:O.$options)||vn(I.type)),se=I.type.kind==="json"||I.type.kind==="union"&&!vn(I.type);if(((T=w[P])==null?void 0:T.$control)==="upload"||!M&&b.kind!=="array"&&(!se||v)||ae){C.properties[P]={...I,type:I.type.kind==="json"?N:I.type};continue}const ee=s.get(R)??pw(R),pe=b.kind==="array"?`Item ${Number(P)+1}`:P,me={address:R,owner:d,field:P,type:I.type,label:pe,nodeId:ee,present:$!==void 0};if(i.slots.set(ln(d,P),me),C.ports[P]={kind:"config",resourceType:`__form:${ee}`},$===void 0||(i.edges.push({data:{id:`__form-edge:${d}:${P}`,source:ee,target:d,sourceProperty:"output:resource",targetProperty:`config:${P}`,isEdgeDashed:!0}}),i.containers.has(ee)||s.has(R)))continue;if(o.has(ee))throw new Error(`Structured node identity conflict: ${ee}`);o.add(ee);const q={data:{id:ee,type:"objectView",label:pe,headerTitle:pe,description:{},config:{form:!0,icon:N.kind==="array"?"PiListNumbers":M?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};i.nodes.push(q),a(ee,R,I.type,p,y+1,!0);const F=i.schema[`__form:${ee}`];q.data.description=Object.fromEntries(Object.keys(F.properties).map(H=>[H,Te(e,N.kind==="array"||N.kind==="object"?`${R}.${H}`:R)]).filter(([,H])=>H!==void 0))}i.schema[x]=C,i.bindings[d]={...i.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||Te(e,u.address)===void 0||a(d.data.id,u.address,h,(c=d.data.viewProps)==null?void 0:c.bgColor,0,i.edges.some(p=>p.data.source===d.data.id))}for(const d of i.edges){const u=i.bindings[d.data.source],h=i.schema[u.type].ports;h.resource={...h.resource,kind:"output",label:((l=h.resource)==null?void 0:l.label)??"output"}}return i}const Sr=(e="reference")=>({kind:e,text:"",paths:[""]}),sb=e=>/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\.\d+)+$/.test(e)&&!e.split(".").some(r=>["__proto__","constructor","prototype"].includes(r));function yw(e,r){const t=new Set(r.map(s=>s.path)),n=s=>{if(!s.paths.length||s.paths.some(a=>!sb(a)||!t.has(a)))throw new Error("Choose an available reference.");return[...s.paths,...s.fallback===void 0?[]:[JSON.stringify(s.fallback)]].join(" || ")},i=s=>{if(s.includes("{{")||s.includes("}}"))throw new Error("Use a reference part for dynamic values.");return s},o=s=>s.map(a=>{if(a.kind==="text")return i(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)}}}${i(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=o(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,o(a.parts)])))}return o(e.parts)}async function mw(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=Sr();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(!sb(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({...Sr("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({...Sr("text"),text:s.slice(c)}),a},i={mode:"reference",parts:[Sr()],comparison:"",fields:[]};if(!e)return i;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{...i,mode:"json",fields:Object.entries(s).map(([a,c])=>({key:a,parts:n(c)}))}}catch{}const o=n(e);if(o.length===2&&o[0].kind==="reference"&&o[1].kind==="text"){const s=r.createSourceFile("condition.ts",`value ${o[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{...i,mode:"condition",parts:[o[0]],comparison:a.expression.right.text}}return{...i,mode:o.length===1&&o[0].kind==="reference"?"reference":"template",parts:o}}function Mu({parts:e,references:r,onChange:t,disabled:n}){const i=(o,s)=>t(e.map((a,c)=>c===o?{...a,...s}:a));return f.jsxs("div",{style:{display:"grid",gap:12},children:[e.map((o,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:o.kind,onChange:a=>i(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(Pe,{"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))})]}),o.kind!=="text"&&f.jsxs(f.Fragment,{children:[o.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=>i(s,{paths:o.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)),o.kind==="reference"&&f.jsxs(f.Fragment,{children:[f.jsx(Pe,{"aria-label":"Add fallback reference",title:"Add fallback reference",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>i(s,{paths:[...o.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:o.fallback!==void 0,onChange:a=>i(s,{fallback:a.target.checked?"":void 0})}),"Default value"]}),o.fallback!==void 0&&f.jsx("input",{"aria-label":"Default value",disabled:n,value:o.fallback,onChange:a=>i(s,{fallback:a.target.value})})]})]}),o.kind!=="reference"&&f.jsxs("label",{children:["Text",f.jsx("textarea",{"aria-label":"Part text",disabled:n,value:o.text,onChange:a=>i(s,{text:a.target.value})})]})]},s)),f.jsx(Pe,{"aria-label":"Add part",title:"Add part",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:n,onClick:()=>t([...e,Sr()])})]})}function bw({label:e,value:r,references:t,disabled:n,onChange:i}){const[o,s]=S.useState(),[a,c]=S.useState(""),[l,d]=S.useState(!1),u=async()=>{d(!0),c("");try{s(await mw(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(Pe,{"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"}),o&&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:o.mode,onChange:h=>s({...o,mode:h.target.value,parts:[Sr()]}),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"})]})]}),o.mode==="json"?f.jsxs(f.Fragment,{children:[o.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:y=>s({...o,fields:o.fields.map((m,g)=>g===p?{...m,key:y.target.value}:m)})})]}),f.jsx(Mu,{parts:h.parts,references:t,disabled:n,onChange:y=>s({...o,fields:o.fields.map((m,g)=>g===p?{...m,parts:y}:m)})}),f.jsx(Pe,{"aria-label":"Remove output field",title:"Remove output field",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...o,fields:o.fields.filter((y,m)=>m!==p)})})]},p)),f.jsx(Pe,{"aria-label":"Add output field",title:"Add output field",icon:f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",onClick:()=>s({...o,fields:[...o.fields,{key:"",parts:[Sr()]}]})})]}):f.jsx(Mu,{parts:o.parts,references:t,disabled:n,onChange:h=>s({...o,parts:h})}),o.mode==="condition"&&f.jsxs("label",{children:["Equals",f.jsx("input",{"aria-label":"Comparison value",value:o.comparison,onChange:h=>s({...o,comparison:h.target.value})})]}),f.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[f.jsx(Pe,{"aria-label":"Apply binding",title:"Apply binding",icon:f.jsx(Z.PiCheck,{size:20}),size:"sm",variant:"ghost",onClick:()=>{try{i(yw(o,t)),s(void 0),c("")}catch(h){c(h instanceof Error?h.message:"Unable to apply binding.")}}}),f.jsx(Pe,{"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 vw({nodeAddress:e,onOpen:r}){const{structured:t,data:n,callbacks:i,editable:o,onFieldCreate:s}=S.useContext(Mt),a=He(),[c,l]=S.useState(""),[d,u]=S.useState("0"),[h,p]=S.useState(""),y=t==null?void 0:t.containers.get(e);if(!y||!n||!t)return null;const m=a.readOnly||a.config.editable===!1||!o,g=Te(n,y.address),b=Iu(y.declared),v=y.type.kind==="array"?y.type.items:y.type.kind==="object"?y.type.additionalProperties:void 0,x=v?Iu(v):[],w=!!s&&y.type.kind==="object"&&(v==null?void 0:v.kind)==="json",C=I=>I.kind==="literal"?String(I.value):I.kind==="string"?"Text":$t(I.kind),j=[...t.slots.values()].filter(I=>I.owner===e),_=(I,R)=>{var $;return($=i.onFormChange)==null?void 0:$.call(i,{data:n,nodeAddress:y.address,address:I,previousValue:Te(n,I),value:R})},k=I=>{var R;a.setSelectedNodeIds([I]),(R=a.engineRef.current)==null||R.focusNode(I,90,!1)},E=(I,R)=>{if(!Array.isArray(g))return;const $=[...g];[$[I],$[I+R]]=[$[I+R],$[I]],_(y.address,$)},O=()=>{const I=x[Number(d)]??x[0];if(I)if(y.type.kind==="array")_(y.address,[...Array.isArray(g)?g:[],dn(I)]);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:y.address,address:`${y.address}.${c}`,previousValue:void 0,value:d==="files"?[]:""},{$control:"upload"}):_(`${y.address}.${c}`,dn(I)),l(""),p("")}},T=y.type.kind==="object"&&!!y.type.additionalProperties,P=y.type.kind==="array";return f.jsxs("div",{"data-structured-controls":"",style:{display:"grid",gap:8,minWidth:0},children:[b.length>1&&f.jsxs("label",{children:["Value type",f.jsx("span",{"data-form-select":"",style:{display:"block"},children:f.jsx(Pt,{"aria-label":"Value type",disabled:m,value:String(b.findIndex(I=>_n(I,g).kind===y.type.kind)),onValueChange:I=>_(y.address,dn(b[Number(I)])),children:b.map((I,R)=>f.jsx("option",{value:R,children:C(I)},R))})})]}),j.map((I,R)=>f.jsxs("div",{"data-structured-slot":I.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[I.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(I.label)}),f.jsx(Pe,{"aria-label":`${I.present?r?"Edit":"Focus":"Create"} ${$t(I.label)}`,title:`${I.present?r?"Edit":"Focus":"Create"} ${$t(I.label)}`,icon:I.present?f.jsx(Z.PiMagnifyingGlass,{size:18}):f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:m&&!I.present,onClick:$=>{var N;I.present?r?r(I.nodeId):((N=$.currentTarget.closest("dialog"))==null||N.close(),k(I.nodeId)):_(I.address,dn(I.type))}}),P&&f.jsxs(f.Fragment,{children:[f.jsx(Pe,{"aria-label":`Move item ${R+1} up`,icon:f.jsx(Z.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:m||R===0,onClick:()=>E(R,-1)}),f.jsx(Pe,{"aria-label":`Move item ${R+1} down`,icon:f.jsx(Z.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:m||R===j.length-1,onClick:()=>E(R,1)})]}),I.present&&f.jsx(Pe,{"aria-label":`Remove ${$t(I.label)}`,icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:m,onClick:()=>P?_(y.address,g.filter(($,N)=>N!==R)):_(I.address,void 0)})]},I.address)),(P||T)&&f.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"end"},children:[T&&f.jsxs("label",{style:{flex:"1 1 120px",minWidth:0,display:"grid",gap:8},children:["Property name",f.jsx("input",{"aria-label":"Property name",placeholder:"Required",value:c,disabled:m,onChange:I=>l(I.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:m,onValueChange:u,children:[x.map((I,R)=>f.jsx("option",{value:R,children:C(I)},R)),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,...T||x.length>1?{height:"calc(1.4em + 20px)",fontSize:15,marginBottom:6}:{}},children:f.jsx(Pe,{"aria-label":P?"Add item":"Add property",icon:f.jsx(Z.PiPlus,{size:20}),size:"sm",variant:"ghost",disabled:m,onClick:O})})]}),h&&f.jsx("p",{role:"alert",children:h})]})}const Mt=S.createContext({callbacks:{}}),Bn=Qn.default.div`
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:T,parent:I}=j;c=c||O;const N=r==="root"&&i.isCntr,$=r.split(".").slice(0,2).join("."),M=xn.includes($),K=i.isCntr&&M||x%2===0&&N;let ae=`${r}.${x}`;ae=kn(ae,t),K&&xn.push(ae),It(b)?Object.keys(C).length&&!et(b)?(n.push(lr(r,ae,null,A,K,T)),Er(b,ae,t,n,R||x,i,j)):Object.keys(S).length&&!et(b)?Cn({flowConfig:i,chldPth:ae,isInverted:K,edges:n,itrblObjct:S,nodes:t,path:r,newConfig:j,forceIsInverted:!0}):et(b)?tb({flowConfig:i,chldPth:ae,edges:n,isInverted:K,item:b,nodes:t,path:r}):It(b)&&Cn({flowConfig:i,chldPth:ae,isInverted:K,edges:n,itrblObjct:[b],nodes:t,path:r,newConfig:j}):(n.push(lr(r,ae,null,A,K,T)),t.push(Sr(E,ae,{label:R||String(b),parent:I},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,T=s.split(".").slice(0,2).join("."),I=xn.includes(T);c||(i=r.isCntr&&I||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 M=S?"object":"array",{config:K}=$r(M,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 M=et(h)?` ${h.length||""}`:`{${Object.keys(h).length||""}}`;let K=N;$&&(K=`${N}.${M}`,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),T=qe(e,R.address);if(T&&typeof T=="object"){const I=T[R.kind==="target"?"$targetEdgeType":"$edgeType"];typeof I=="string"&&(A.type=I);const N=T[R.kind==="target"?"$targetIcon":"$edgeIcon"];typeof N=="string"&&(A.icon=N),T.$isEdgeAnimated!==void 0&&(A.isEdgeAnimated=!!T.$isEdgeAnimated);const $=T[R.kind==="target"?"$targetAnimationVariant":"$edgeAnimationVariant"];["dashed","traveling"].includes($)&&(A.edgeAnimationVariant=$),T.$isEdgeDashed!==void 0&&(A.isEdgeDashed=!!T.$isEdgeDashed),T.$edgeColor&&(A.color=T.$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,T)=>[String(T),{type:v.items,optional:!0}])):{value:{type:Sn(h)?h:v,optional:!1}};for(const[R,T]of Object.entries(S)){if(!mw(R))throw new Error(`Unsupported structured property key: ${R}`);const I=b?u:`${u}.${R}`,N=qe(e,I),$=An(T.type,N),M=$.kind==="object"||$.kind==="array",K=(E=C.ports)==null?void 0:E[R],ae=(K==null?void 0:K.kind)==="config"&&(((O=w[R])==null?void 0:O.$options)||Sn(T.type)),se=T.type.kind==="json"||T.type.kind==="union"&&!Sn(T.type);if(((A=w[R])==null?void 0:A.$control)==="upload"||!M&&v.kind!=="array"&&(!se||b)||ae){C.properties[R]={...T,type:T.type.kind==="json"?$:T.type};continue}const te=s.get(I)??bw(I),me=v.kind==="array"?`Item ${Number(R)+1}`:R,ve={address:I,owner:d,field:R,type:T.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(I)))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":M?"PiBracketsCurly":"PiTextT"},viewProps:{bgColor:p}}};o.nodes.push(F),a(te,I,T.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"?`${I}.${W}`:I)]).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=T=>T.kind==="literal"?String(T.value):T.kind==="string"?"Text":$t(T.kind),S=[...t.slots.values()].filter(T=>T.owner===e),j=(T,I)=>{var N;return(N=o.onFormChange)==null?void 0:N.call(o,{data:n,nodeAddress:m.address,address:T,previousValue:qe(n,T),value:I})},P=T=>{var I;a.setSelectedNodeIds([T]),(I=a.engineRef.current)==null||I.focusNode(T,90,!1)},E=(T,I)=>{if(!Array.isArray(g))return;const N=[...g];[N[T],N[T+I]]=[N[T+I],N[T]],j(m.address,N)},O=()=>{const T=x[Number(d)]??x[0];if(T)if(m.type.kind==="array")j(m.address,[...Array.isArray(g)?g:[],pn(T)]);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(T)),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(T=>An(T,g).kind===m.type.kind)),onValueChange:T=>j(m.address,pn(v[Number(T)])),children:v.map((T,I)=>f.jsx("option",{value:I,children:C(T)},I))})})]}),S.map((T,I)=>f.jsxs("div",{"data-structured-slot":T.address,style:{display:"flex",gap:6,alignItems:"center",minWidth:0},children:[T.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(T.label)}),f.jsx(Me,{"aria-label":`${T.present?r?"Edit":"Focus":"Create"} ${$t(T.label)}`,title:`${T.present?r?"Edit":"Focus":"Create"} ${$t(T.label)}`,icon:T.present?f.jsx(Z.PiMagnifyingGlass,{size:18}):f.jsx(Z.PiPlus,{size:18}),size:"sm",variant:"ghost",disabled:y&&!T.present,onClick:N=>{var $;T.present?r?r(T.nodeId):(($=N.currentTarget.closest("dialog"))==null||$.close(),P(T.nodeId)):j(T.address,pn(T.type))}}),R&&f.jsxs(f.Fragment,{children:[f.jsx(Me,{"aria-label":`Move item ${I+1} up`,icon:f.jsx(Z.PiArrowUp,{size:18}),size:"sm",variant:"ghost",disabled:y||I===0,onClick:()=>E(I,-1)}),f.jsx(Me,{"aria-label":`Move item ${I+1} down`,icon:f.jsx(Z.PiArrowDown,{size:18}),size:"sm",variant:"ghost",disabled:y||I===S.length-1,onClick:()=>E(I,1)})]}),T.present&&f.jsx(Me,{"aria-label":`Remove ${$t(T.label)}`,icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:y,onClick:()=>R?j(m.address,g.filter((N,$)=>$!==I)):j(T.address,void 0)})]},T.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:T=>l(T.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((T,I)=>f.jsx("option",{value:I,children:C(T)},I)),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`
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 Tu({request:e,property:r,config:t,value:n,disabled:i}){var ye,ge,z,W,ie;const{callbacks:o,structured:s,references:a}=S.useContext(Mt),{themeColor:c}=He(),{background:l}=it(),d=S.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,y]=S.useState(h),[m,g]=S.useState(""),[b,v]=S.useState(0),x=S.useRef(null),w=S.useRef(),[C,j]=S.useState(!1),[_,k]=S.useState(!1),[E,O]=S.useState(),T=((ye=t.$options)==null?void 0:ye.$source)==="callback",P=o.resolveFormOptions,{data:I,address:R,nodeAddress:$,nodeId:N}=e;S.useEffect(()=>(j(!1),k(!1),()=>{var K;(K=w.current)==null||K.abort(),w.current=void 0}),[R,$,N,i,h,t.$control,(ge=t.$upload)==null?void 0:ge.accept,(z=t.$upload)==null?void 0:z.maxSizeBytes]);const M=S.useRef(I);M.current=I;const J=JSON.stringify([R,N,(W=t.$options)!=null&&W.$dependsOn?t.$options.$dependsOn.map(K=>Te(I,K)):Te(I,$)]);S.useEffect(()=>{y(h),g("")},[h,R,N]),S.useEffect(()=>{if(!T)return;const K=new AbortController;return Promise.resolve().then(()=>{if(!P)throw new Error("No options resolver configured");return P({address:R,nodeAddress:$,nodeId:N,data:Gr(M.current),signal:K.signal})}).then(ue=>{if(!Array.isArray(ue)||ue.some(ve=>!ve||typeof ve.label!="string"||!["string","number","boolean"].includes(typeof ve.value)&&ve.value!==null))throw new Error("Invalid options response");K.signal.aborted||O({key:J,options:ue})}).catch(ue=>{K.signal.aborted||O({key:J,options:[],error:ue instanceof Error?ue.message:"Options unavailable"})}),()=>K.abort()},[T,P,J,R,$,N,b]);const ae=T&&(E==null?void 0:E.key)!==J,se=T?(E==null?void 0:E.key)===J?E.options:[]:r.type.kind==="null"?[{label:"Null",value:null}]:r.type.kind==="boolean"?[{label:"Yes",value:!0},{label:"No",value:!1}]:vn(r.type),ee=r.type.kind==="array",pe=(t.$control==="upload"?"upload":s&&u||t.$control==="checkbox"?"pills":t.$control)??(se?ee||r.type.kind==="boolean"?"pills":"select":r.type.kind==="boolean"?"checkbox":u?"textarea":"input"),me=!r.optional||!!t.$requiredWhen&&oo(t.$requiredWhen,I),q=me?"Required":"Optional",F=pe!=="upload"&&!!(a!=null&&a.length)&&typeof n=="string"&&n.includes("{{"),H=m||T&&(E==null?void 0:E.key)===J&&E.error||!F&&Dt(r.type,n,me),B=$t(t.$label??R.split(".").pop()),de=K=>{var ue;if(!(i||Object.is(K,n)))try{(ue=o.onFormChange)==null||ue.call(o,{...e,previousValue:n,value:K}),g("")}catch(ve){g(ve instanceof Error?ve.message:"Unable to update field")}},Y=S.useRef(de);S.useLayoutEffect(()=>{Y.current=de});const oe=()=>{if(u){try{const Oe=p===""&&r.optional?void 0:JSON.parse(p),$e=Dt(r.type,Oe,me);if($e){g($e);return}de(Oe)}catch{g("Enter valid JSON")}return}const K=r.type.kind==="number"||r.type.kind==="integer",ue=p===""&&r.optional?void 0:K&&p!==""?Number(p):p,ve=Dt(r.type,ue,me);if(K&&ve&&p!==""){g(ve);return}de(ue)},ce=async K=>{var ve,Oe,$e;if(i||w.current||!K.length)return;const ue=new AbortController;w.current=ue,g(""),j(!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(!ee&&K.length!==1)throw new Error("Choose one file for this field.");if(!o.uploadFormFile)throw new Error("No file upload handler configured.");const De=(Oe=(ve=t.$upload)==null?void 0:ve.accept)==null?void 0:Oe.split(",").map(Je=>Je.trim().toLowerCase()).filter(Boolean);for(const Je of K){if((($e=t.$upload)==null?void 0:$e.maxSizeBytes)!==void 0&&Je.size>t.$upload.maxSizeBytes)throw new Error(`${Je.name} exceeds the file size limit.`);if(De!=null&&De.length&&!De.some(nt=>nt.startsWith(".")?Je.name.toLowerCase().endsWith(nt):nt.endsWith("/*")?Je.type.toLowerCase().startsWith(nt.slice(0,-1)):Je.type.toLowerCase()===nt))throw new Error(`${Je.name} is not an accepted file type.`)}const tt=await Promise.all(K.map(async Je=>{const nt=await o.uploadFormFile({...e,data:Gr(I),file:Je,signal:ue.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(ue.signal.aborted||w.current!==ue)return;const Ue=ee?[...Array.isArray(n)?n:[],...tt]:tt[0],yt=Dt(r.type,Ue,me);if(yt)throw new Error(yt);Y.current(Ue)}catch(De){ue.signal.aborted||g(De instanceof Error?De.message:"Unable to upload file."),ue.abort()}finally{w.current===ue&&(w.current=void 0,j(!1))}},xe={id:d,disabled:i,"aria-label":B,"aria-required":me,"aria-invalid":!!H,"aria-describedby":H?`${d}-error`:void 0},je=Ee(c);return f.jsxs("div",{"data-form-field":R,"data-flow-property":R.slice($.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:i||C,style:{width:24,height:24,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:0,background:"transparent",color:"inherit"},onClick:()=>de(void 0),children:f.jsx(Z.PiArrowCounterClockwise,{size:14})})]}),!!(a!=null&&a.length)&&!u&&pe!=="upload"&&f.jsx(bw,{label:B,value:n,references:a,disabled:i,onChange:de}),pe==="upload"?f.jsxs("div",{"data-form-upload":ee?"multiple":"single","aria-busy":C,style:{"--flow-upload-surface":Ee(l),outline:_?"2px dashed var(--flow-form-input-background)":void 0,borderRadius:"var(--flow-form-input-radius)"},onDragOver:K=>{K.preventDefault(),K.stopPropagation(),!i&&!C&&(K.dataTransfer.dropEffect="copy",k(!0))},onDragLeave:K=>{K.currentTarget.contains(K.relatedTarget)||k(!1)},onDrop:K=>{K.preventDefault(),K.stopPropagation(),k(!1),ce(Array.from(K.dataTransfer.files))},children:[f.jsx("input",{ref:x,type:"file",hidden:!0,"aria-label":`Upload ${B}`,accept:(ie=t.$upload)==null?void 0:ie.accept,multiple:ee,disabled:i||C,onChange:K=>{const ue=Array.from(K.target.files??[]);K.target.value="",ce(ue)}}),f.jsxs("div",{"data-upload-items":"",children:[(ee?Array.isArray(n)?n:[]:n?[n]:[]).map((K,ue)=>f.jsxs("div",{"data-upload-preview":"",children:[typeof K=="string"&&ir(K)&&f.jsxs("a",{href:K,target:"_blank",rel:"noopener noreferrer","aria-label":`${B} file ${ue+1}`,children:[f.jsx(Z.PiFile,{size:32,"aria-hidden":"true"}),f.jsx(Jt,{name:K,size:120,onError:ve=>{ve.currentTarget.style.visibility="hidden"}})]}),f.jsxs("div",{"data-upload-actions":"",children:[!ee&&f.jsx(Pe,{"aria-label":`Replace ${B}`,title:`Replace ${B}`,icon:f.jsx(Z.PiUploadSimple,{}),size:"xs",variant:"ghost",disabled:i||C,onClick:()=>{var ve;return(ve=x.current)==null?void 0:ve.click()}}),f.jsx(Pe,{"aria-label":`Remove ${B} file ${ue+1}`,title:"Remove file",icon:f.jsx(Z.PiTrash,{}),size:"xs",variant:"ghost",disabled:i||C,onClick:()=>de(ee&&Array.isArray(n)?n.filter((ve,Oe)=>Oe!==ue):"")})]})]},`${ue}:${K}`)),(ee||!n)&&f.jsx("button",{...xe,type:"button","data-upload-drop":"",title:`Upload ${B}`,disabled:i||C,onClick:()=>{var K;return(K=x.current)==null?void 0:K.click()},children:f.jsx(Z.PiPlus,{size:28,"aria-hidden":"true"})})]}),C&&f.jsx("span",{role:"status",children:"Uploading..."})]}):F?null:pe==="select"?f.jsx("div",{"data-form-select":"",children:f.jsxs(Pt,{...xe,disabled:i||ae||!!(E!=null&&E.error),labelCase:"preserve",value:String((se==null?void 0:se.findIndex(K=>Object.is(K.value,n)))??-1),onValueChange:K=>{const ue=se==null?void 0:se[Number(K)];ue&&de(ue.value)},children:[f.jsx("option",{value:-1,disabled:!0,children:n!==void 0&&n!==""?String(n):q}),se==null?void 0:se.map((K,ue)=>f.jsx("option",{value:ue,children:$t(K.label)||K.label},ue))]})}):pe==="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((K,ue)=>{const ve=ee?Array.isArray(n)&&n.includes(K.value):Object.is(n,K.value);return f.jsx("button",{type:"button",disabled:i||ae,"aria-pressed":ve,style:{padding:"8px 16px",borderRadius:24,border:0,color:ve?je:"inherit",background:ve?"color-mix(in srgb, currentColor 12%, transparent)":"color-mix(in srgb, currentColor 7%, transparent)"},onClick:()=>de(ee?ve?n.filter(Oe=>Oe!==K.value):[...Array.isArray(n)?n:[],K.value]:K.value),children:$t(K.label)||K.label},ue)}),ae&&f.jsx("span",{role:"status",children:"Loading..."})]}):pe==="textarea"?f.jsx("textarea",{...xe,placeholder:q,value:p,onChange:K=>y(K.target.value),onBlur:oe}):f.jsx("input",{...xe,placeholder:q,type:r.type.kind==="number"||r.type.kind==="integer"?"number":"text",step:r.type.kind==="integer"?1:"any",value:p,onChange:K=>y(K.target.value),onBlur:oe,onKeyDown:K=>{K.key==="Enter"&&oe(),K.key==="Escape"&&y(n===void 0?"":String(n))}}),H&&f.jsx("div",{role:"alert",id:`${d}-error`,children:H}),T&&(E==null?void 0:E.error)&&f.jsx("button",{type:"button",disabled:i,onClick:()=>{O(void 0),v(b+1)},children:"Retry"})]})}function Ed({nodeAddress:e,structured:r=!1}){return r?f.jsx(xw,{nodeAddress:e},e):f.jsx(ad,{nodeAddress:e})}function xw({nodeAddress:e}){var u,h,p;const r=S.useContext(Mt),[t,n]=S.useState([]),i=((u=r.structured)==null?void 0:u.sourceSchema)??r.schema,o=((h=r.structured)==null?void 0:h.sourceBindings)??r.bindings,s=S.useMemo(()=>{if(!(!r.data||!i||!o))return ab(r.data,o,i,[{data:{id:e,type:"objectView"}}])},[r.data,o,i,e]);if(!s)return f.jsx(ad,{nodeAddress:e});const a=t.findIndex(y=>!s.containers.has(y)),c=a<0?t:t.slice(0,a),l=c.at(-1)??e,d=(p=[...s.slots.values()].find(y=>y.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(Pe,{"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(ad,{nodeAddress:l,onOpen:y=>n([...c,y])},l)]})}function ad({nodeAddress:e,onOpen:r}){var j,_;const{data:t,schema:n,callbacks:i,bindings:o,editable:s,renderForm:a,structured:c}=S.useContext(Mt),{readOnly:l,config:d,colorMode:u}=He(),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(Bn,{$colorMode:u,role:"alert",children:"Forms require a JSON document."});const p=o?Pn(o,e,n):void 0,y=o?p:n&&Jr(t,e,n);if(!y)return f.jsx(Bn,{$colorMode:u,role:"status",children:"Form schema unavailable."});const m=(p==null?void 0:p.address)??e,g=Te(t,m),b=(j=c==null?void 0:c.containers.get(e))==null?void 0:j.scalar;if(g===void 0||typeof g!="object"&&!b)return f.jsx(Bn,{$colorMode:u,role:"alert",children:"Bound form state is unavailable."});const v=Object.entries(y.type.properties).filter(([k])=>{var E;return oo((E=y.fields[k])==null?void 0:E.$visibleWhen,t)}),x=v.length>8||v.some(([k])=>{var E;return(E=y.fields[k])==null?void 0:E.$section}),w=new Map;for(const k of v){const[E,O]=k,T=x?$t(((_=y.fields[E])==null?void 0:_.$section)??(O.type.kind==="object"||O.type.kind==="array"?E:O.optional?"Options":"General")):"";w.has(T)||w.set(T,[]),w.get(T).push(k)}const C=([k,E])=>f.jsx(Tu,{request:{data:t,address:b?m:`${m}.${k}`,nodeAddress:m,nodeId:typeof(g==null?void 0:g.id)=="string"?g.id:void 0},property:E,config:y.fields[k]??{},value:b?g:g==null?void 0:g[k],disabled:l||d.editable===!1||!(s??!!i.onJsonChange)},`${(g==null?void 0:g.id)??e}:${k}`);return f.jsxs(Bn,{$colorMode:u,"data-flow-form":e,onClick:k=>k.stopPropagation(),onDoubleClick:k=>k.stopPropagation(),children:[c&&f.jsx(vw,{nodeAddress:e,onOpen:r}),!c&&p&&y.type.additionalProperties&&v.length===0&&f.jsx(Tu,{request:{data:t,address:m,nodeAddress:m},property:{type:y.type,optional:!1},config:{$label:"Configuration",$control:"textarea"},value:g,disabled:l||d.editable===!1||!s}),[...w].map(([k,E])=>x&&E.length>1?f.jsxs("details",{open:!0,children:[f.jsxs("summary",{children:[f.jsx("span",{children:k}),f.jsx(Z.PiCaretDown,{size:16,"aria-hidden":"true"})]}),E.map(C)]},k):E.map(C))]})}function cb(e){const{viewData:r}=S.useContext(Mt),{nodeById:t,edgeById:n,parentIds:i}=pr();if(r){const o=Te(r,e),s=o&&typeof o=="object"&&!Array.isArray(o)&&"$"in o?o.$:o;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 i.has(e)?!0:[...n.values()].some(({data:o})=>{const s=o.isInverted?o.target:o.source,a=o.isInverted?o.source:o.target;return s===e&&a!==e&&t.has(a)})}function En(e,r){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:r}function Rn(e,r,t,n){return{borderColor:r,borderWidth:En(e==null?void 0:e.borderWidth,n),borderStyle:(e==null?void 0:e.borderStyle)??"solid",...wm(r==="transparent"?"currentColor":r,t,".flow-sdk-node:hover &",!t)}}function lb({label:e,value:r,options:t,onChange:n,disabled:i}){var o;return f.jsxs(Pt,{"aria-label":e,title:`Animation: ${((o=t.find(s=>s.value===r))==null?void 0:o.label)??"Mixed"}`,value:r,style:{width:104},disabled:i,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 Rd({nodeId:e,edgeId:r,value:t,open:n,onOpenChange:i}){const{callbacks:o,readOnly:s,themeColor:a,colorMode:c}=He(),{background:l,backgroundSecondary:d,border:u,colorText:h,colorInactive:p}=it(),y=c==="dark"?Hr:Ee(p),m=S.useRef(null),g=S.useRef(null),b=S.useRef(0),[v,x]=S.useState(!1),[w,C]=S.useState("icons"),[j,_]=S.useState([]),[k,E]=S.useState("loading"),[O,T]=S.useState(""),[P,I]=S.useState(0),[R,$]=S.useState(""),[N,M]=S.useState(""),[J,ae]=S.useState(!1);S.useEffect(()=>()=>{b.current++},[]),S.useEffect(()=>{if(!v)return;let B=!0;return import("react-icons/pi").then(de=>{B&&(_(Object.keys(de).filter(Y=>Y.startsWith("Pi")).sort()),E("ready"))}).catch(()=>{B&&E("unavailable")}),()=>{B=!1}},[v]),S.useEffect(()=>{var B;s&&((B=m.current)==null||B.close())},[s]),S.useEffect(()=>{var B,de,Y;if(n!==void 0){if(!n||s){(B=m.current)==null||B.close();return}(de=m.current)!=null&&de.open||(M(""),C(t==="PiFileSvg"||t&&ir(t)?"custom":"icons"),$(t&&!t.startsWith(xn)&&ir(t)?t:""),x(!0),(Y=m.current)==null||Y.showModal())}},[n,s,t]);const se=B=>{var de,Y,oe;s||(r?(de=o.onEdgeIconChange)==null||de.call(o,r,B):e&&((Y=o.onNodeIconChange)==null||Y.call(o,e,B)),i==null||i(!1),(oe=m.current)==null||oe.close())},ee=j.filter(B=>B.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().includes(O.trim().toLowerCase())),pe=36,me=Math.max(1,Math.ceil(ee.length/pe)),q=Math.min(P,me-1),F=ee.slice(q*pe,(q+1)*pe),H={width:"100%",padding:"8px 14px",background:"transparent",color:"inherit",border:`1px solid ${Ee(u)}`,borderRadius:30};return f.jsxs(f.Fragment,{children:[n===void 0&&f.jsx(Be,{label:r?"Choose edge icon":"Choose node icon",children:f.jsx(Pe,{"aria-label":r?"Choose edge icon":"Choose node icon",icon:f.jsx(Z.PiShapes,{size:20}),size:"sm",variant:"ghost",color:Ee(a),disabled:s,onClick:()=>{var B;M(""),C(t&&ir(t)?"custom":"icons"),$(t&&!t.startsWith(xn)&&ir(t)?t:""),x(!0),(B=m.current)==null||B.showModal()}})}),f.jsx(V.chakra.dialog,{ref:m,"aria-label":r?"Choose edge icon":"Choose node icon",css:dr(Ee(l),Ee(u)),onClose:()=>{x(!1),i==null||i(!1),b.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:Ee(l),color:Ee(h)},children:v&&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(Be,{label:"Remove icon",children:f.jsx(Pe,{"aria-label":r?"Remove edge icon":"Remove node icon",icon:f.jsx(Z.PiTrash,{size:18}),size:"sm",variant:"ghost",disabled:s||J,onClick:()=>se("")})}),f.jsx(Kr,{"aria-label":"Close icon picker",onClick:()=>{var B;return(B=m.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:y,"--indicator-color":y},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:J||s,onChange:async B=>{var oe;const de=(oe=B.target.files)==null?void 0:oe[0];if(B.target.value="",!de)return;const Y=++b.current;ae(!0),M("");try{const ce=await dw(de);Y===b.current&&se(ce)}catch(ce){Y===b.current&&M(ce instanceof Error?ce.message:"Unable to read SVG.")}finally{Y===b.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=>{T(B.target.value),I(0)},style:H}),f.jsxs("div",{style:{height:244,overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(6, minmax(0, 1fr))",gridAutoRows:36,gap:4},children:[F.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 ${Ee(t===B?a:u)}`,background:Ee(t===B?l:d),color:"inherit",cursor:"pointer"},children:f.jsx(Jt,{name:B,size:24})},B)),F.length===0&&f.jsx("span",{role:"status",style:{gridColumn:"1 / -1"},children:k==="loading"?"Loading icons...":k==="unavailable"?"React icons unavailable":"No icons found"})]}),f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[f.jsxs("span",{role:"status",style:{fontSize:12},children:[ee.length," icons · ",q+1," / ",me]}),f.jsxs("div",{style:{display:"flex",gap:4},children:[f.jsx(Be,{label:"Previous icons",children:f.jsx(Pe,{"aria-label":"Previous icons",icon:f.jsx(Z.PiCaretLeft,{size:18}),size:"sm",variant:"ghost",disabled:q===0,onClick:()=>I(q-1)})}),f.jsx(Be,{label:"Next icons",children:f.jsx(Pe,{"aria-label":"Next icons",icon:f.jsx(Z.PiCaretRight,{size:18}),size:"sm",variant:"ghost",disabled:q+1>=me,onClick:()=>I(q+1)})})]})]})]}):f.jsxs(f.Fragment,{children:[t&&ir(t)&&f.jsx(Jt,{name:t,size:64}),f.jsxs("button",{type:"button",disabled:J||s,onClick:()=>{var B;return(B=g.current)==null?void 0:B.click()},style:{...H,display:"flex",justifyContent:"center",gap:8,alignItems:"center",cursor:"pointer"},children:[f.jsx(Z.PiUploadSimple,{}),J?"Uploading...":"Upload SVG"]}),f.jsxs("form",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},onSubmit:B=>{B.preventDefault(),!(J||s)&&(!ir(R.trim())||R.trim().startsWith(xn)?M("Enter an HTTP or HTTPS image URL."):se(R.trim()))},children:[f.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:R,disabled:J||s,onChange:B=>$(B.target.value),style:{...H,flex:1,minWidth:0}}),f.jsx(Be,{label:"Apply URL",children:f.jsx(Pe,{type:"submit","aria-label":"Apply URL",icon:f.jsx(Z.PiArrowRight,{size:20}),size:"sm",variant:"ghost",disabled:J||s||!R.trim(),style:{flexShrink:0}})})]})]})})]}),N&&f.jsx("div",{role:"alert",style:{fontSize:13},children:N})]})})]})}const Jn=["white","blue.500","teal.500","green.500","yellow.500","orange.500","red.500","purple.500","pink.500","gray.500",Hr],db=["gray.900",Hr,"gray.600","gray.200","white"];function ub(){const{config:e}=He(),r=e.selectionToolbar||{},t=new Set(r.hide||[]);return{palette:r.palette||Jn,show:n=>!t.has(n)}}function _t(){const{border:e}=it();return f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:e})}function zr({value:e,placeholder:r,ariaLabel:t,width:n="140px",type:i="text",min:o,onCommit:s}){const{colorText:a}=it(),[c,l]=S.useState(e),d=S.useRef(!1);S.useEffect(()=>l(e),[e]);const u=()=>{if(d.current)return;d.current=!0;const h=c.trim();if(i==="number"&&h!==""&&(!Number.isFinite(Number(h))||Number(h)<(o??0))){l(e);return}h!==e&&s(h)};return f.jsx(V.Input,{"aria-label":t,type:i,min:o,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 Er({colors:e,value:r,label:t,onPick:n,onReset:i,includeTransparent:o=!0}){const{colorInactive:s,colorText:a}=it(),[c,l]=S.useState(!1),d=S.useId(),u=S.useRef(null),h=r??e[0]??"transparent",p=eo(f.jsx(Er,{colors:e,value:r,label:t,onPick:n,onReset:i,includeTransparent:o}));return f.jsx(Vr.Provider,{value:null,children:f.jsxs(V.HStack,{gap:1,"aria-label":t,role:"group",onClickCapture:p,onKeyDown:y=>{var m;y.key==="Escape"&&(l(!1),(m=u.current)==null||m.focus())},children:[f.jsx(Be,{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:Ee(h),...h==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:`2px solid ${Ee(a)}`,outlineOffset:"1px",onClick:()=>l(y=>!y)})}),c&&f.jsxs(V.HStack,{id:d,gap:1,children:[[...new Set([...e,...o?["transparent"]:[]])].map(y=>{const m=r===y;return f.jsx(Be,{label:`${t}: ${y}`,children:f.jsx(V.Box,{as:"button","aria-label":`${t} ${y}`,"aria-pressed":m,w:4,h:4,borderRadius:"full",cursor:"pointer",style:{backgroundColor:Ee(y),...y==="transparent"?{backgroundImage:"conic-gradient(#fff 25%, #a0aec0 0 50%, #fff 0 75%, #a0aec0 0)",backgroundSize:"8px 8px"}:{}},outline:m?`2px solid ${Ee(a)}`:"none",outlineOffset:"1px",_hover:{transform:"scale(1.15)"},onClick:()=>n(y),onDoubleClick:g=>{var b;g.stopPropagation(),l(!1),(b=u.current)==null||b.focus()}})},y)}),i&&f.jsx(Be,{label:`Reset ${t.toLowerCase()}`,children:f.jsx(Pe,{"aria-label":`Reset ${t}`,icon:f.jsx(V.Icon,{as:Z.PiEraser,boxSize:4}),size:"xs",variant:"ghost",color:s,onClick:()=>{var y;i(),l(!1),(y=u.current)==null||y.focus()}})})]})]})})}function fb({edgeId:e,onClose:r}){var p;const{callbacks:t,themeColor:n,config:i}=He(),{colorInactive:o}=it(),{edgeById:s}=pr(),{palette:a,show:c}=ub(),l=(p=s.get(e))==null?void 0:p.data,d=[...new Set(["rounded-orthogonal","orthogonal","straight","bezier",...Object.keys(i.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(Kr,{onClick:r}),c("label")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(zr,{ariaLabel:"Edge label",placeholder:"Edge label",value:(l==null?void 0:l.label)||"",onCommit:y=>{var m;return(m=t.onEdgeLabelChange)==null?void 0:m.call(t,e,y)}})]}),c("style")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),h.map(y=>f.jsx(Be,{label:y.label,children:f.jsx(Pe,{"aria-label":`Edge style ${y.key}`,"aria-pressed":u===y.key,icon:f.jsx(V.Icon,{as:y.icon,boxSize:5}),size:"sm",variant:"ghost",color:u===y.key?n:o,onClick:()=>{var m;return(m=t.onEdgeStyleChange)==null?void 0:m.call(t,e,y.key)}})},y.key)),u==="animated"&&f.jsx(lb,{label:"Edge animation",value:(l==null?void 0:l.edgeAnimationVariant)??"dashed",options:[{value:"dashed",label:"Dash"},{value:"traveling",label:"Trace"}],disabled:i.readOnly,onChange:y=>{var m;return(m=t.onEdgeAnimationVariantChange)==null?void 0:m.call(t,e,y)}}),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:i.readOnly,onValueChange:y=>{var m;return(m=t.onEdgeTypeChange)==null?void 0:m.call(t,e,y||void 0)},children:[f.jsx("option",{value:"",children:"Default"}),d.map(y=>f.jsx("option",{value:y,children:y},y))]})]}),c("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Rd,{edgeId:e,value:l==null?void 0:l.icon},e),f.jsx(zr,{ariaLabel:"Edge icon",placeholder:"Icon name or SVG URL",value:(l==null?void 0:l.icon)??"",onCommit:y=>{var m;return(m=t.onEdgeIconChange)==null?void 0:m.call(t,e,y)}})]}),c("color")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Er,{label:"Edge color",colors:a,value:l==null?void 0:l.color,onPick:y=>{var m;return(m=t.onEdgeColorChange)==null?void 0:m.call(t,e,y)},onReset:()=>{var y;return(y=t.onEdgeColorChange)==null?void 0:y.call(t,e,"")}})]}),c("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Be,{label:"Delete edge",children:f.jsx(Pe,{"aria-label":"Delete edge",icon:f.jsx(V.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:"red.400",onClick:()=>{var y;(y=t.onEdgeDelete)==null||y.call(t,e,l),r()}})})]})]})}function hb({ids:e,showDivider:r=!0}){const{callbacks:t,config:n,nodeGridOptions:i,fillRadiusEditedIds:o,setNodeRadiusPreview:s}=He(),{colorInactive:a}=it(),{nodeById:c}=pr(),[l,d]=S.useState(),u=S.useRef(),h=S.useRef(),p=S.useRef({callbacks:t,readOnly:n.readOnly,nodeById:c});p.current={callbacks:t,readOnly:n.readOnly,nodeById:c};const y=()=>{var C,j;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(_)&&((j=(C=p.current.callbacks).onNodeBorderRadiusChange)==null||j.call(C,_,w.radius));s(w.ids,void 0),d(void 0)}},m=S.useRef(y);m.current=y,S.useEffect(()=>{const w=()=>m.current();return window.addEventListener("pagehide",w),()=>{window.removeEventListener("pagehide",w),w()}},[]);const g=e.map(w=>{var C,j;return i!=null&&i.fill&&!o.has(w)?0:(j=(C=c.get(w))==null?void 0:C.data.viewProps)==null?void 0:j.borderRadius}),b=!g.every(w=>w===g[0]),v=l??g[0]??0,x=w=>{n.readOnly||(w!==void 0&&e.every(C=>{var j;return((j=c.get(C))==null?void 0:j.data.type)==="grid"})?(d(w),s(e,w),u.current={ids:[...e],radius:w},clearTimeout(h.current),h.current=setTimeout(y,150)):(clearTimeout(h.current),u.current=void 0,d(void 0),s(e,void 0),e.forEach(C=>{var j;return(j=t.onNodeBorderRadiusChange)==null?void 0:j.call(t,C,w)})))};return f.jsxs(f.Fragment,{children:[r&&f.jsx(_t,{}),f.jsx(V.Box,{position:"relative",w:"36px",h:"30px",display:"grid",placeItems:"center",children:f.jsx(Pt,{icon:f.jsx(V.Icon,{as:ux.TbBorderRadius,boxSize:5,color:a,"aria-hidden":"true"}),"aria-label":"Node border radius",title:`Border radius: ${b?"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(od,{label:"Border radius",inputLabel:"Node corner radius",min:0,max:Math.max(500,...g.map(w=>w??0)),step:1,value:v,displayValue:l!==void 0?`${l}px`:b?"Mixed":g[0]===void 0?"Default":`${v}px`,onChange:x,onChangeEnd:y}),f.jsx(Be,{label:"Reset border radius",children:f.jsx(Pe,{"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 pb({ids:e,onClose:r,afterLabel:t}){var de,Y,oe,ce,xe,je,ye,ge;const{callbacks:n,colorMode:i,themeColor:o,config:s,setNodeViewMode:a,nodeViewModes:c}=He(),{colorText:l,colorInactive:d}=it(),{nodeById:u,parentIds:h}=pr(),{palette:p,show:y}=ub(),m=e.length===1,[g,b]=S.useState(""),v=m?(de=u.get(e[0]))==null?void 0:de.data:void 0,x=e.map(z=>{var K,ue,ve,Oe,$e,De;const W=(K=u.get(z))==null?void 0:K.data,ie=((ue=W==null?void 0:W.config)==null?void 0:ue.typeView)??"";return ie==="object"&&((ve=W==null?void 0:W.config)==null?void 0:ve.content)!==void 0&&c[z]!=="properties"?"content":ie==="icon-label"&&((Oe=W==null?void 0:W.viewProps)==null?void 0:Oe.bgColor)==="transparent"&&(($e=W==null?void 0:W.viewProps)==null?void 0:$e.borderWidth)===0&&((De=W==null?void 0:W.viewProps)==null?void 0:De.outline)===!1?"media":ie}),w=x.some(z=>z!==x[0]),C=w?"mixed":x[0]??"",j=[{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(z=>{var ie,K,ue,ve;const W=(ie=u.get(z))==null?void 0:ie.data;return W&&((K=W.config)==null?void 0:K.typeView)!=="grid"&&((ue=W.config)==null?void 0:ue.typeView)!=="parent"&&(h.has(z)||((ve=W.config)==null?void 0:ve.parentContainer)||Object.prototype.hasOwnProperty.call(s.customViews??{},W.type))}),k=(Y=v==null?void 0:v.config)==null?void 0:Y.collapsed,E=cb(e[0]),O=z=>{var W,ie,K;return(((ie=(W=u.get(z))==null?void 0:W.data.viewProps)==null?void 0:ie.outline)??(h.has(z)?(K=s.parentNodeStyle)==null?void 0:K.outline:!1))===!0},T=e.every(O),P=!T&&e.some(O),I=z=>{var W;return((W=u.get(z))==null?void 0:W.data.isNodeAnimated)===!0},R=e.every(I),$=!R&&e.some(I),N=e.map(z=>{var W;return((W=u.get(z))==null?void 0:W.data.nodeAnimationVariant)??"traveling"}),M=N.every(z=>z===N[0])?N[0]:"",J=z=>e.forEach(z),[ae,se]=S.useState(!1),ee=ae&&y("color")&&y("borderColor"),pe=z=>{var W,ie,K;return(((ie=(W=u.get(z))==null?void 0:W.data.viewProps)==null?void 0:ie.borderStyle)??(h.has(z)?(K=s.parentNodeStyle)==null?void 0:K.borderStyle:"solid"))==="dashed"},me=e.every(pe),q=!me&&e.some(pe),F=e.map(z=>{var K,ue,ve;const W=(K=u.get(z))==null?void 0:K.data,ie=h.has(z)?En((ue=s.parentNodeStyle)==null?void 0:ue.borderWidth,6):(W==null?void 0:W.type)==="objectView"?3:2;return En((ve=W==null?void 0:W.viewProps)==null?void 0:ve.borderWidth,ie)}),H=F.every(z=>z===F[0])?String(F[0]??""):"",B=z=>J(W=>{var ie,K;ee?(ie=n.onNodeBorderColorChange)==null||ie.call(n,W,z):(K=n.onNodeColorChange)==null||K.call(n,W,"bg",z)});return f.jsxs(f.Fragment,{children:[f.jsx(Kr,{onClick:r}),f.jsx(_t,{}),m&&y("label")?f.jsx(zr,{ariaLabel:"Node label",placeholder:"Node label",value:(v==null?void 0:v.label)??(v==null?void 0:v.headerTitle)??"",onCommit:z=>{var W;return(W=n.onNodeLabelChange)==null?void 0:W.call(n,e[0],z)}}):f.jsxs(V.Text,{fontSize:"xs",color:l,whiteSpace:"nowrap",px:1,children:[e.length," selected"]}),t,y("typeView")&&f.jsxs(Pt,{"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:z=>{var ie;const W=(ie=j.find(K=>K.value===z))==null?void 0:ie.view;W&&J(K=>{var ve,Oe,$e,De,tt,Ue,yt,Je,nt,ht,Ie,ze,at;const ue=(ve=u.get(K))==null?void 0:ve.data;z==="media"?((Oe=n.onNodeColorChange)==null||Oe.call(n,K,"bg","transparent"),($e=n.onNodeBorderColorChange)==null||$e.call(n,K,"#00000000"),(De=n.onNodeBorderWidthChange)==null||De.call(n,K,0),(tt=n.onNodeOutlineChange)==null||tt.call(n,K,!1)):x[e.indexOf(K)]==="media"&&((Ue=n.onNodeColorChange)==null||Ue.call(n,K,"bg",""),(yt=n.onNodeBorderColorChange)==null||yt.call(n,K,""),(Je=n.onNodeBorderWidthChange)==null||Je.call(n,K,void 0)),z==="content"&&((nt=ue==null?void 0:ue.config)==null?void 0:nt.content)===void 0&&((ht=n.onNodeContentChange)==null||ht.call(n,K,"")),(Ie=n.onNodeTypeViewChange)==null||Ie.call(n,K,W),a(K,z==="object"&&((ze=ue==null?void 0:ue.config)==null?void 0:ze.content)!==void 0?"properties":"default"),(at=n.onNodeViewToggle)==null||at.call(n,K)})},children:[w&&f.jsx("option",{value:"mixed",disabled:!0,children:"Mixed"}),j.map(z=>f.jsx("option",{value:z.value,children:f.jsxs(V.HStack,{gap:"12px",children:[f.jsx(z.icon,{size:20,"aria-hidden":"true",style:{flexShrink:0}}),f.jsx("span",{children:z.label})]})},z.value))]}),y("style")&&f.jsx(hb,{ids:e},e.join("\0")),y("outline")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Be,{label:T?"Restore node fill":"Remove node fill",children:f.jsx(Pe,{"aria-label":"Toggle node outline","aria-pressed":P?"mixed":T,icon:f.jsx(V.Icon,{as:T?Z.PiSquare:Z.PiSquareFill,boxSize:5}),size:"sm",variant:"ghost",color:T?o:d,onClick:()=>J(z=>{var W;return(W=n.onNodeOutlineChange)==null?void 0:W.call(n,z,!T)})})})]}),y("color")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),y("borderColor")&&f.jsx(Be,{label:ee?"Edit node colors":"Edit node border",children:f.jsx(Pe,{"aria-label":"Edit node border","aria-pressed":ee,icon:f.jsx(V.Icon,{as:Z.PiBoundingBox,boxSize:5}),size:"sm",variant:"ghost",color:ee?o:d,bg:ee?i==="dark"?"whiteAlpha.200":"blackAlpha.100":void 0,onClick:()=>se(z=>!z)})}),f.jsx(Er,{label:ee?"Border color":"Background",colors:p,value:ee?((oe=v==null?void 0:v.viewProps)==null?void 0:oe.borderColor)??(m&&h.has(e[0])?(ce=s.parentNodeStyle)==null?void 0:ce.borderColor:void 0):(xe=v==null?void 0:v.viewProps)==null?void 0:xe.bgColor,onPick:B,onReset:()=>B("")}),ee&&y("style")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Be,{label:me?"Solid border":"Dashed border",children:f.jsx(Pe,{"aria-label":"Toggle dashed border","aria-pressed":q?"mixed":me,icon:f.jsx(V.Icon,{as:me?Z.PiLineSegments:Z.PiLineSegment,boxSize:5}),size:"sm",variant:"ghost",color:me?o:d,onClick:()=>J(z=>{var W;return(W=n.onNodeBorderStyleChange)==null?void 0:W.call(n,z,me?"solid":"dashed")})})}),f.jsx(zr,{ariaLabel:"Border thickness",placeholder:m?"Auto":"Mixed",width:"64px",type:"number",min:0,value:H,onCommit:z=>J(W=>{var ie;return(ie=n.onNodeBorderWidthChange)==null?void 0:ie.call(n,W,z===""?void 0:Number(z))})})]})]}),y("animation")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Be,{label:R?"Stop border animation":"Animate node border",children:f.jsx(Pe,{"aria-label":"Toggle node animation","aria-pressed":$?"mixed":R,icon:f.jsx(V.Icon,{as:Z.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:R?o:d,onClick:()=>J(z=>{var W;return(W=n.onNodeAnimationChange)==null?void 0:W.call(n,z,!R)})})}),(R||$)&&f.jsx(lb,{label:"Node animation",value:M,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:s.readOnly,onChange:z=>J(W=>{var ie;return(ie=n.onNodeAnimationVariantChange)==null?void 0:ie.call(n,W,z)})})]}),!ee&&y("textColor")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Er,{label:"Text color",colors:db,value:(je=v==null?void 0:v.viewProps)==null?void 0:je.textColor,onPick:z=>J(W=>{var ie;return(ie=n.onNodeColorChange)==null?void 0:ie.call(n,W,"text",z)}),onReset:()=>J(z=>{var W;return(W=n.onNodeColorChange)==null?void 0:W.call(n,z,"text","")})})]}),m&&y("icon")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Rd,{nodeId:e[0],value:(ye=v==null?void 0:v.config)==null?void 0:ye.icon},e[0]),f.jsx(zr,{ariaLabel:"Node icon",placeholder:"(e.g. PiGear)",width:"120px",value:((ge=v==null?void 0:v.config)==null?void 0:ge.icon)||"",onCommit:z=>{var W;return(W=n.onNodeIconChange)==null?void 0:W.call(n,e[0],z)}})]}),m&&E&&y("collapse")&&k!==void 0&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Be,{label:k?"Expand":"Collapse",children:f.jsx(Pe,{"aria-label":k?"Expand node":"Collapse node",icon:f.jsx(V.Icon,{as:k?Z.PiArrowsOutLineVertical:Z.PiArrowsInLineVertical,boxSize:5}),size:"sm",variant:"ghost",color:d,onClick:()=>{var z;return(z=n.onNodeCollapse)==null?void 0:z.call(n,e[0],!k)}})})]}),y("delete")&&f.jsxs(f.Fragment,{children:[f.jsx(_t,{}),f.jsx(Be,{label:m?"Delete node":`Delete ${e.length} nodes`,children:f.jsx(Pe,{"aria-label":"Delete selected nodes",icon:f.jsx(V.Icon,{as:Z.PiTrash,boxSize:5}),size:"sm",variant:"ghost",color:i==="dark"?"red.300":"red.500",onClick:()=>{J(z=>{var W,ie;return(ie=n.onNodeDelete)==null?void 0:ie.call(n,z,((W=u.get(z))==null?void 0:W.data)||{id:z})}),r()}})})]}),f.jsx(_t,{}),f.jsx(Be,{label:"Copy selection",children:f.jsx(Pe,{"aria-label":"Copy selection",icon:f.jsx(Z.PiCopy,{size:20}),size:"sm",variant:"ghost",color:d,onClick:async()=>{var z;try{await((z=n.onNodesCopy)==null?void 0:z.call(n,e)),b("")}catch(W){b(String(W))}}})}),f.jsx(Be,{label:"Duplicate selection",children:f.jsx(Pe,{"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 z;try{(z=n.onNodesDuplicate)==null||z.call(n,e),b("")}catch(W){b(String(W))}}})}),g&&f.jsx(V.Text,{role:"alert",fontSize:"xs",children:g})]})}async function gb(e){const{toSvg:r}=await Promise.resolve().then(()=>require("./index-sHQXTNv9.cjs"));await document.fonts.ready;const t=await r(e,{filter:i=>!(i instanceof Element)||!i.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(i=>i.remove()),n.querySelectorAll("[data-flow-preview-source]").forEach(i=>{i.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 yb(e,r="squeed.svg"){const t=document.createElement("a");t.href=await gb(e),t.download=r.endsWith(".svg")?r:`${r}.svg`,t.click()}function mb(){const{themeColor:e}=He(),[r,t]=S.useState(!1),[n,i]=S.useState("");return f.jsxs(f.Fragment,{children:[f.jsx(Be,{label:"Download SVG (current view)",children:f.jsx(Pe,{"aria-label":"Download SVG",icon:f.jsx(Z.PiDownloadSimpleFill,{size:20}),disabled:r,borderRadius:"30%",color:e,variant:"ghost",onClick:async o=>{var a;const s=(a=o.currentTarget.closest("[data-flow-diagram]"))==null?void 0:a.querySelector("[data-flow-background]");if(!s){i("Diagram not available for export.");return}t(!0),i("");try{await yb(s)}catch(c){i(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 kd({children:e,background:r,border:t,endElement:n,startElement:i,startElementWidth:o=44,framed:s=!0}){const a=S.useRef(null),[c,l]=S.useState({left:!1,right:!1});S.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 b=u.scrollLeft>1,v=u.scrollWidth-u.clientWidth-u.scrollLeft>1;l(x=>x.left===b&&x.right===v?x:{left:b,right:v})},y=g=>{if(g.defaultPrevented||g.ctrlKey||s&&g.deltaX!==0||!(g.deltaX||g.deltaY)||u.scrollWidth<=u.clientWidth)return;g.preventDefault();const b=g.deltaMode===WheelEvent.DOM_DELTA_LINE?16:g.deltaMode===WheelEvent.DOM_DELTA_PAGE?u.clientWidth:1;u.scrollLeft+=(g.deltaX||g.deltaY)*b},m=new ResizeObserver(p);return m.observe(u),u.firstElementChild&&m.observe(u.firstElementChild),u.addEventListener("scroll",p,{passive:!0}),u.addEventListener("wheel",y,{passive:!1}),p(),()=>{m.disconnect(),u.removeEventListener("scroll",p),u.removeEventListener("wheel",y)}},[]);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?dr(d,`var(--chakra-colors-${t.replace(".","-")})`):{},...s||i?{"--flow-toolbar-start-width":i?`${o}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:i?`${o}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"&&i?o: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}),i&&f.jsx(V.Box,{position:"absolute",left:"6px",top:0,h:"50px",w:`${o-12}px`,display:"flex",alignItems:"center",justifyContent:"center",children:i})]})}async function ww(e,r){const t=new Set,n=[],i=(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,y]of Object.entries(l))p==="$"?i(y,c):p.startsWith("$")||i(y,`${c}.${p}`)};if(i(r,"root"),!t.size)return{contract:await ob(e)};const o=await _d(e,[...t]);for(const a of t)if(!Object.prototype.hasOwnProperty.call(o,a))throw new Error(`Missing form type: ${a}`);const s={};for(const a of n){const c=Jr(r,a,o);c&&(s[a]={type:c.type,optional:!1})}return{schema:o,contract:{name:e.name,nodes:s}}}function bb({message:e,onDismiss:r}){const{background:t,colorText:n,border:i}=it();return!e||typeof document>"u"?null:Br.createPortal(f.jsxs(V.chakra.div,{role:"alert","aria-atomic":"true",css:dr(Ee(t),Ee(i)),onPointerDown:o=>o.stopPropagation(),onClick:o=>o.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:Ee(t),color:Ee(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(Kr,{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 Ad({showDivider:e=!0,compact:r=!1}={}){const{edgeMode:t,setEdgeMode:n,workflowContract:i,setWorkflowContract:o,callbacks:s,readOnly:a,themeColor:c,colorMode:l}=He(),{edgeById:d}=pr(),{data:u,schema:h,setSchema:p,bindings:y,structured:m}=S.useContext(Mt),g=(m==null?void 0:m.sourceBindings)??y,b=(m==null?void 0:m.sourceSchema)??h,{colorText:v}=it(),x=S.useRef(null),w=S.useRef(0),[C,j]=S.useState(!1),[_,k]=S.useState("");S.useEffect(()=>()=>{w.current++},[]),S.useEffect(()=>{w.current++,j(!1)},[a,u,g]);const E=i?[...d.values()].filter(P=>jd(i,P.data)).length:0,O=i?`${i.name}: ${b?`${Object.keys(b).length} form types loaded; `:""}${E} invalid or unverified connections`:"",T=eo(f.jsx(Ad,{showDivider:!1,compact:!0}));return f.jsx(Vr.Provider,{value:null,children:f.jsxs("span",{style:{display:"contents"},onClickCapture:T,children:[f.jsx(bb,{message:_,onDismiss:()=>k("")}),e&&f.jsx(pn,{}),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:Kn,_hover:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},_focusVisible:{bg:l==="dark"?"whiteAlpha.100":"blackAlpha.50"},onClick:P=>{var I,R;(I=P.currentTarget.closest("[popover]"))==null||I.hidePopover(),(R=s.onWorkflowConfigurationOpen)==null||R.call(s)},children:[f.jsx(Z.PiGear,{}),"Configuration"]})]}),onValueChange:P=>{var R;const I=P==="auto"?"auto":P==="properties"?"properties":"nodes";n(I),(R=s.onEdgeModeChange)==null||R.call(s,I)},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(Be,{label:i?`Replace ${i.name}`:"Upload workflow interface",children:f.jsx(Pe,{"aria-label":"Upload workflow interface",icon:f.jsx(Z.PiUploadSimple,{size:20}),color:Ee(c),size:"sm",variant:"ghost",disabled:C||a,onClick:()=>{var P;return(P=x.current)==null?void 0:P.click()}})}),f.jsx("input",{ref:x,type:"file",hidden:!0,accept:".ts,.json","aria-label":"Workflow interface file",disabled:a||C,onChange:async P=>{var $,N;const I=($=P.target.files)==null?void 0:$[0];if(P.target.value="",!I)return;const R=++w.current;j(!0),k("");try{const M=g?await _d(I,[...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:J,schema:ae}=g&&M?{schema:M,contract:{name:I.name,nodes:Object.fromEntries(Object.entries(g).map(([se,ee])=>[se,{type:M[ee.schemaType??ee.type],optional:!1}]))}}:await ww(I,u);if(R!==w.current)return;p==null||p(ae),o(J),(N=s.onWorkflowContractChange)==null||N.call(s,J)}catch(M){R===w.current&&k(`${I.name}: ${M instanceof Error?M.message:"Unable to load interface."}`)}finally{R===w.current&&j(!1)}}}),!r&&(O||C)&&f.jsx("span",{role:"status",title:O,style:{color:Ee(v),fontSize:12,maxWidth:180,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:C?"Loading interface...":O}),!r&&i&&f.jsx(Be,{label:"Remove workflow interface",children:f.jsx(Pe,{"aria-label":"Remove workflow interface",icon:f.jsx(Z.PiX,{size:16}),size:"sm",variant:"ghost",disabled:a||C,onClick:()=>{var P;p==null||p(void 0),o(void 0),(P=s.onWorkflowContractChange)==null||P.call(s,void 0),k("")}})})]})]})})}const Cw=[{value:"BT",label:"Bottom to Up",icon:Z.PiArrowUp,flowType:sn.BOTTOM_UP},{value:"TB",label:"Top to Bottom",icon:Z.PiArrowDown,flowType:sn.TOP_DOWN},{value:"LR",label:"Left to Right",icon:Z.PiArrowRight,flowType:sn.LEFT_RIGHT},{value:"RL",label:"Right to Left",icon:Z.PiArrowLeft,flowType:sn.RIGHT_LEFT}],vb=({nodeGridControlsTarget:e}={})=>{const{engineRef:r,themeColor:t,setThemeColor:n,edgeColor:i,setEdgeColor:o,backgroundSelected:s,setBackgroundSelected:a,direction:c,edgeMode:l,allNodesIconLabel:d,setAllNodesIconLabel:u,nodeGridOptions:h,selectedNodeIds:p,setSelectedNodeIds:y,selectedEdgeId:m,setSelectedEdgeId:g,isZoomMode:b,setIsZoomMode:v,isMultiSelectMode:x,setIsMultiSelectMode:w,isDragMode:C,setIsDragMode:j,isEdgeHandlesEnabled:_,setIsEdgeHandlesEnabled:k,isArrayNodeMode:E,setIsArrayNodeMode:O,isPinned:T,setIsPinned:P,callbacks:I,config:R,readOnly:$}=He(),{nodeById:N,edgeById:M,parentIds:J}=pr(),ae=R.colorMode==="dark",{background:se,border:ee,colorInactive:pe,colorText:me,colorActive:q}=it(),F=ae?ee:"gray.300",H=`var(--chakra-colors-${se.replace(".","-")})`,B=`var(--chakra-colors-${(ae?ee:"gray.300").replace(".","-")})`,[de,Y]=S.useState(!1),[oe,ce]=S.useState(!0),xe=R.bottomBarCollapsed??oe,je=S.useRef(null),ye=vm({edge:"bottom",enabled:!T,bounds:je,inside:[je]}),ge=S.useCallback(Ie=>{const ze=r.current;if(!ze)return;const at=R.minZoom??.01,st=R.maxZoom??1.5,zt=.02;let Ve=ze.zoom();switch(Ie){case"increase":Ve=Math.min(st,Ve+zt),ze.zoom(Ve),ze.center(!1);break;case"decrease":Ve=Math.max(at,Ve-zt),ze.zoom(Ve),ze.center(!1);break;case"reset":ze.fit(50);break}},[r,R.minZoom,R.maxZoom]),z=R.renderSelectedNodeToolbar,W=p.length>0&&!!z,ie=S.useMemo(()=>W?p.map(Ie=>{var at;return{...((at=N.get(Ie))==null?void 0:at.data)??{id:Ie},isParent:J.has(Ie)}}):[],[W,p,N,J]),K=S.useCallback(()=>{var Ie;y([]),(Ie=I.onNodeDeselect)==null||Ie.call(I)},[y,I]),ue=R.renderSelectedEdgeToolbar,ve=!!m&&!!ue,Oe=S.useMemo(()=>{var Ie;return!ve||!m?null:((Ie=M.get(m))==null?void 0:Ie.data)??{id:m}},[ve,m,M]),$e=S.useCallback(()=>{var Ie;g(null),(Ie=I.onEdgeDeselect)==null||Ie.call(I)},[g,I]),De=R.selectionToolbar!==!1&&!$,tt=De&&!!m&&!ue,Ue=De&&!tt&&p.length>0&&!z,yt=tt||Ue,Je=T||ye||de||yt||R.bottomBarCollapsed===!1;S.useEffect(()=>{p.length||m?a(!1):$||(s&&P(!0),R.bottomBarCollapsed===void 0&&ce(!s))},[s,p.length,m,$,a,P,R.bottomBarCollapsed]);const nt=R.renderBottomBar,ht=Z0();return nt?f.jsxs(f.Fragment,{children:[W&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:z({selectedNodeIds:p,selectedNodeData:ie,onDeselect:K})}),ve&&Oe&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:ue({edgeId:m,edgeData:Oe,onDeselect:$e})}),f.jsx(V.Box,{position:"absolute",bottom:0,left:0,right:0,zIndex:100,w:"100%",children:nt({zoomIn:()=>ge("increase"),zoomOut:()=>ge("decrease"),resetZoom:()=>ge("reset"),direction:c,isZoomMode:b,setIsZoomMode:v,isMultiSelectMode:x,setIsMultiSelectMode:w,isDragMode:C,setIsDragMode:j,isEdgeHandlesEnabled:_,setIsEdgeHandlesEnabled:k,isArrayNodeMode:E,setIsArrayNodeMode:O,selectedNodeIds:p,selectedNodeData:ie,selectedEdgeId:m,selectedEdgeData:Oe,onNodeDeselect:K,onEdgeDeselect:$e,callbacks:I})})]}):f.jsxs(Vr.Provider,{value:ht,children:[W&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:z({selectedNodeIds:p,selectedNodeData:ie,onDeselect:K})}),ve&&Oe&&f.jsx(V.Box,{position:"absolute",bottom:5,left:"50%",transform:"translateX(-50%)",zIndex:101,children:ue({edgeId:m,edgeData:Oe,onDeselect:$e})}),f.jsx(V.Box,{ref:je,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:Je?"translateY(0)":"translateY(100%)",pointerEvents:Je?"auto":"none",visibility:Je?"visible":"hidden",opacity:Je?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(kd,{background:se,border:ae?ee:"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(fb,{edgeId:m,onClose:$e}):Ue?f.jsx(pb,{ids:p,onClose:K}):null,f.jsxs("div",{style:{display:tt||Ue?"none":"contents"},children:[f.jsxs("span",{style:{display:R.bottomBarNavigation===!1?"none":"contents"},children:[f.jsx(Be,{label:T?"Unpin":"Pin",children:f.jsx(Pe,{"aria-label":"Pin",icon:f.jsx(V.Icon,{as:T?Z.PiPushPinFill:Z.PiPushPin,boxSize:5}),size:"sm",variant:"ghost",color:T?t:pe,onClick:()=>{P(!T),Y(!1)}})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Be,{label:"Zoom Out",children:f.jsx(Pe,{"aria-label":"Zoom out",rememberAction:!1,icon:f.jsx(V.Icon,{as:Z.PiMinus,boxSize:5}),size:"sm",variant:"ghost",color:me,onClick:()=>ge("decrease")})}),f.jsx(Be,{label:"Zoom In",children:f.jsx(Pe,{"aria-label":"Zoom in",rememberAction:!1,icon:f.jsx(V.Icon,{as:Z.PiPlus,boxSize:5}),size:"sm",variant:"ghost",color:me,onClick:()=>ge("increase")})}),f.jsx(Be,{label:"Reset Zoom",children:f.jsx(Pe,{"aria-label":"Reset zoom",rememberAction:!1,icon:f.jsx(V.Icon,{as:Z.PiArrowCounterClockwise,boxSize:5}),size:"sm",variant:"ghost",color:me,onClick:()=>ge("reset")})}),xe&&f.jsx(X0,{visibleActions:h?["Collision mode","Fill",...h.fill?["Grid adjustment"]:[]]:[],divider:f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"})})]}),f.jsxs("span",{style:{display:xe?"none":"contents"},children:[f.jsxs("span",{style:{display:R.bottomBarNavigation===!1?"none":"contents"},children:[R.edgeHandles!==!1&&f.jsx(Be,{label:_?"Draw Mode On (V)":"Draw Mode Off (V)",children:f.jsx(Pe,{"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:pe,onClick:()=>k(!_)})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Be,{label:b?"Zoom Mode (z)":"Pan Mode (z)",children:f.jsx(Pe,{"aria-label":"Toggle zoom mode",icon:f.jsx(V.Icon,{as:b?Z.PiMagnifyingGlassPlus:Z.PiArrowsOutCardinal,boxSize:5}),size:"sm",variant:"ghost",color:b?t:pe,onClick:()=>v(!b)})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Be,{label:x?"Multi-Select On (m)":"Multi-Select Off (m)",children:f.jsx(Pe,{"aria-label":"Toggle multi-select",icon:f.jsx(V.Icon,{as:Z.PiSelectionPlus,boxSize:5}),size:"sm",variant:"ghost",color:x?t:pe,onClick:()=>w(!x)})}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Be,{label:C?"Drag Mode On (d)":"Drag Mode Off (d)",children:f.jsx(Pe,{"aria-label":"Toggle drag mode",icon:f.jsx(V.Icon,{as:Z.PiHandGrabbing,boxSize:5}),size:"sm",variant:"ghost",color:C?t:pe,onClick:()=>j(!C)})})]}),R.bottomBarNavigation===!1&&(e===void 0?f.jsx(To,{}):e?Br.createPortal(f.jsx(To,{}),e):null),R.bottomBarExtra&&f.jsxs(f.Fragment,{children:[R.bottomBarNavigation!==!1&&f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),R.bottomBarExtra]}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),f.jsx(Hm,{})]}),f.jsx("span",{style:{display:R.bottomBarNavigation===!1||xe&&!h?"none":"contents"},children:f.jsx(To,{})}),f.jsxs("span",{style:{display:xe?"none":"contents"},children:[f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),f.jsx(qr,{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:F}),f.jsx(Be,{label:E?"Array Mode [ ]":"Set Mode { }",children:f.jsx(Pe,{"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:pe,onClick:()=>{var ze;const Ie=!E;O(Ie),(ze=I.onArrayModeChange)==null||ze.call(I,Ie)}})})]}),f.jsx(Ad,{}),!$&&f.jsxs("span",{style:{display:s?"contents":"none"},children:[f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Er,{label:"Graph theme",colors:Jn,value:t,includeTransparent:!1,onPick:Ie=>{var ze;n(Ie),(ze=I.onThemeColorChange)==null||ze.call(I,Ie)}})]}),!$&&f.jsxs(f.Fragment,{children:[f.jsx(V.Icon,{as:Z.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"}),f.jsx(Er,{label:"Graph edge color",colors:Jn,value:i||(ae?"gray.500":Hr),onPick:o,onReset:()=>o("")}),f.jsx(V.Icon,{as:Z.PiLineVerticalThin,boxSize:5,color:F,role:"separator","aria-orientation":"vertical"})]}),f.jsx(Km,{})]}),f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:F}),f.jsx(Be,{label:xe?"Expand toolbar":"Collapse toolbar",children:f.jsx(Pe,{"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:pe,onClick:()=>{var Ie;R.bottomBarCollapsed===void 0&&ce(!xe),a(xe),(Ie=I.onBottomBarCollapsedChange)==null||Ie.call(I,!xe)}})}),!xe&&f.jsx(mb,{})]})]})}),!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:dr(H,B),px:3,cursor:"pointer",onClick:()=>Y(!de),children:f.jsxs(V.Flex,{align:"center",h:"100%",children:[f.jsx(Be,{label:"Flow Direction",children:f.jsx(Pe,{"aria-label":"Direction",onClick:Ie=>{Ie.stopPropagation(),Y(!de)},icon:f.jsx(V.Icon,{as:Z.PiCaretUp,boxSize:5}),size:"sm",variant:"ghost",color:pe})}),f.jsx(V.Text,{fontSize:"xs",textTransform:"uppercase !important",color:ae?"whiteAlpha.600":"blackAlpha.500",ml:1,children:c.toUpperCase()})]})}),de&&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:dr(H,B),children:[Cw.map(Ie=>f.jsxs(V.Flex,{align:"center",gap:3,px:3,py:2,css:Kn,cursor:"pointer",_hover:{bg:ae?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var ze;(ze=I.onDirectionChange)==null||ze.call(I,Ie.value),Y(!1)},children:[f.jsx(V.Icon,{as:Ie.icon,boxSize:5,color:me}),f.jsx(V.Text,{fontSize:"sm",color:me,flex:1,whiteSpace:"nowrap",children:Ie.label}),c===Ie.value&&f.jsx(V.Icon,{as:Z.PiCheck,boxSize:4,color:q})]},Ie.value)),f.jsxs(V.Flex,{align:"center",gap:3,px:3,py:2,css:Kn,cursor:"pointer",_hover:{bg:ae?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ie;(Ie=I.onDirectionChange)==null||Ie.call(I,"C"),Y(!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:q})]})]})})]})]})})]})};vb.displayName="BottomBar";const xb=S.memo(vb);function Sw({checked:e,onChange:r,disabled:t,label:n="Connected nodes"}){return f.jsx(qr,{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 Ou={$bgColor:"bgColor",$textColor:"textColor",$borderColor:"borderColor"};function wb(e,r){const t=new Map,n=(o,s)=>{if(Object.is(o,s))return!0;if(!o||!s||typeof o!="object"||typeof s!="object"||Array.isArray(o)!==Array.isArray(s))return!1;const a=Object.keys(o);return a.length===Object.keys(s).length&&a.every(c=>Object.prototype.hasOwnProperty.call(s,c)&&n(o[c],s[c]))},i=(o,s,a)=>{if(o===s)return!0;if(!o||!s||typeof o!="object"||typeof s!="object"||Array.isArray(o)!==Array.isArray(s))return!1;const c=new Set([...Object.keys(o),...Object.keys(s)]);for(const l of c)if(!n(o[l],s[l])){if(Object.prototype.hasOwnProperty.call(Ou,l)){if(typeof s[l]!="string"||!s[l])return!1;t.set(a,{...t.get(a),[Ou[l]]:s[l]})}else if(l.startsWith("$")&&l!=="$"||!i(o[l],s[l],l==="$"?a:`${a}.${l}`))return!1}return!0};if(i(e,r,"root"))return t}function jw(e,r){return wb(e,r)!==void 0}function _w(e,r,t){if(e===r)return t;const n=wb(e,r);if(!n)return;const i=new Set(t.nodes.map(o=>o.data.id));for(const o of n.keys())if(!i.has(o)||!Te(r,o))return;return{edges:t.edges,nodes:t.nodes.map(o=>{const s=n.get(o.data.id),a=Te(e,o.data.id),c=Te(r,o.data.id);return!s&&a===c?o:{...o,data:{...o.data,...typeof o.data.code=="string"?{code:JSON.stringify(c,null,2)}:{},...s?{viewProps:{...o.data.viewProps,...s},config:{...o.data.config,...s}}:{}}}})}}function sd(e){return e.kind==="literal"?e.value:e.kind==="union"?sd(e.types[0]):e.kind==="array"?[]:e.kind==="object"?Object.fromEntries(Object.entries(e.properties).filter(([,r])=>!r.optional).map(([r,t])=>[r,sd(t.type)])):e.kind==="boolean"?!1:e.kind==="number"||e.kind==="integer"?0:e.kind==="null"?null:""}function Cb(e,r,t){var g,b,v;const n=(g=Te(e,r))==null?void 0:g.$form,i=n==null?void 0:n.$create;if(!i)return;const o=i.$address.split(".");if(o.shift()!=="root"||!o.length||o.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,i.$type))throw new Error(`Load form type: ${i.$type}`);const s=o.pop(),a=["root",...o].join("."),c=Jr(e,a,t),l=(b=c==null?void 0:c.type.properties[s])==null?void 0:b.type;if((l==null?void 0:l.kind)!=="array"||l.items.kind!=="object")throw new Error("Form creation must target an object-array field.");const d=t[i.$type],u=i.$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={...sd(d),...structuredClone(u)};((v=d.properties.id)==null?void 0:v.type.kind)==="string"&&(h.id=yd());let p=e;const y=Te(e,i.$address);if(y===void 0)p=Et(e,a,x=>({...x,[s]:[]}));else if(!Array.isArray(y)&&!Array.isArray(y==null?void 0:y.$))throw new Error("Form creation destination is not an array.");const m=xd(p,i.$address,{...h,$label:i.$label??i.$type,...i.$icon?{$icon:i.$icon}:{},$form:{$type:i.$type,$create:i}});return{address:m.address,json:wd(m.json,r,{target:m.address,label:i.$edgeLabel})}}function Sb(e,r,t){var o;if(r==="root"||!Te(e,r)||!Te(e,t))throw new Error("The source or Parent no longer exists.");const n=new Set;let i=t;for(;i;){if(i===r||i.startsWith(`${r}.`)||n.has(i))throw new Error("A node cannot be moved inside itself or its descendants.");n.add(i);const s=(o=Te(e,i))==null?void 0:o.$parent;i=typeof s=="string"?s:i.includes(".")?i.slice(0,i.lastIndexOf(".")):void 0}return vd(Et(e,r,s=>({...s,$parent:t})),t,!1)}function jb(e,r){const t=new Set(r.filter(a=>Te(e,a)!==void 0)),n=[],i=(a,c)=>{if(!(!a||typeof a!="object")){n.push([c,a]);for(const[l,d]of Object.entries(a))l.startsWith("$")||i(d,`${c}.${l}`)}};i(e,"root");const o=a=>[...t].some(c=>a===c||a.startsWith(`${c}.`));let s=!0;for(;s;){s=!1;for(const[a,c]of n)!o(a)&&typeof c.$parent=="string"&&o(c.$parent)&&(t.add(a),s=!0)}return[...t].filter(a=>![...t].some(c=>c!==a&&a.startsWith(`${c}.`)))}function Pd(e,r){const t=jb(e,r),n=new Map(t.map((a,c)=>[a,`root.node_${c+1}`])),i=a=>{const c=t.find(l=>a===l||a.startsWith(`${l}.`));return c?`${n.get(c)}${a.slice(c.length)}`:void 0},o=a=>{if(!(!a||typeof a!="object")){Array.isArray(a.$connections)&&(a.$connections=a.$connections.flatMap(c=>{const l=typeof c.target=="string"&&i(c.target);return l?[{...c,id:void 0,target:l}]:[]}));for(const c of["$parent","$target"])if(typeof a[c]=="string"){const l=i(a[c]);l?a[c]=l:delete a[c]}for(const[c,l]of Object.entries(a))c.startsWith("$")||o(l)}},s={$hideRoot:!0};return t.forEach((a,c)=>{const l=structuredClone(Te(e,a));o(l),s[`node_${c+1}`]=l}),s}function _b(e,r){const t=Pd(e,r),n=Object.keys(t).filter(a=>!a.startsWith("$")),i=new Map(n.map(a=>[a,`copy_${crypto.randomUUID()}`])),o=a=>{if(!a||typeof a!="object")return;const c=l=>{const d=l.split(".");return d[0]==="root"&&i.has(d[1])&&(d[1]=i.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("$")||o(d)},s=Object.fromEntries(n.map(a=>{const c=t[a];return o(c),[i.get(a),c]}));return{json:Et(e,"root",a=>({...a,...s})),ids:[...i.values()].map(a=>`root.${a}`)}}function Ew(e,r){const t=i=>e&&typeof e=="object"&&i in e;let n=1;for(;t(`${r}_${n}`);)n++;return`${r}_${n}`}function Eb(e,r,t,n,i){const o=(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=Sb(e,a,c);(d=t.onNodeParentChange)==null||d.call(t,a,c),o(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(Pd(e,a),null,2))},onNodesDuplicate:a=>{var l;if(((l=t.onNodesDuplicate)==null?void 0:l.call(t,a))===!0)return;const c=_b(e,a);o(c.json,{type:"nodeCreate",address:c.ids[0]})},onFormChange:a=>{const c=Te(e,a.nodeAddress);if(!c||a.nodeId!==void 0&&c.id!==a.nodeId)throw new Error("This form node has moved. Retry the edit.");o(io(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),o(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),o(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),o(Ct(e,a,"$content",c),{type:"nodeContent",address:a,key:"$content",value:c})},onNodeTypeViewChange:(a,c)=>{var l;c!==void 0&&!hd.includes(c)||((l=t.onNodeTypeViewChange)==null||l.call(t,a,c),o(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";o(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),o(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),o(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),o(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),o(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),o(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),o(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),o(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),o(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),o(vd(e,a,c),{type:"nodeCollapse",address:a,key:"$collapsed",value:c})},onNodeCreate:a=>{var p,y;if(((p=t.onNodeCreate)==null?void 0:p.call(t,a))===!0)return;const c=a.sourceNodeId||"root",l=!!a.sourceNodeId&&a.isArrayMode&&!((y=Te(e,c))!=null&&y.$arrayDrawInitialized);let d=e,u,h=a.isArrayMode?"array":"set";for(let m=0;m<(l?2:1);m++){const g=a.sourceNodeId&&Cb(d,a.sourceNodeId,i);if(g)d=g.json,u??(u=g.address),h="form";else{const b=Ew(Te(d,c),a.isArrayMode?"list":"node"),v=a.isArrayMode?{$bgColor:"gray.500",$:[]}:{$bgColor:"gray.500"},x=xd(d,c,v,b);d=x.json,u??(u=x.address)}}l&&(d=Et(d,c,m=>Array.isArray(m)?{$:m,$arrayDrawInitialized:!0}:{...m,$arrayDrawInitialized:!0})),o(d,{type:"nodeCreate",address:u,value:h})},onNodeDelete:(a,c)=>{var l;(l=t.onNodeDelete)==null||l.call(t,a,c),o(eb(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;o(d?wd(e,a,d):tb(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&&o(sr(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&&o(Qm(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&&o(sr(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&&o(sr(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&&o(sr(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&&o(sr(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=rb(e,l);d.removed&&o(d.json,{type:"edgeDelete",edge:l,key:l.connection?"$connections":"$target"})}}}const Rw=".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 kw({path:e,width:r,reversed:t,children:n,onComplete:i}){const o=`flow-edge-reveal-${S.useId().replace(/:/g,"")}`,s=S.useRef(null),[a,c]=S.useState({x:0,y:0,width:1,height:1});return S.useEffect(()=>{const l=matchMedia("(prefers-reduced-motion: reduce)"),d=()=>{l.matches&&(i==null||i())};return d(),l.addEventListener("change",d),()=>l.removeEventListener("change",d)},[i]),S.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:o,maskUnits:"userSpaceOnUse",...a,children:f.jsx("path",{ref:s,className:"flow-sdk-edge-reveal",onAnimationEnd:l=>{l.animationName==="flow-sdk-edge-reveal"&&(i==null||i())},"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(#${o})`,children:n})]})}const Aw=".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 Pw({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 Rb=".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 Zn({x:e=0,y:r=0,width:t,height:n,radius:i,color:o,strokeWidth:s=8,path:a,variant:c="traveling"}){const l=S.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(i,t/2,n/2))},p=s+36,y={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",...y,style:{maskType:"luminance"},children:[f.jsx("rect",{...y,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, ${o} 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:o,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(i,t/2,n/2)),fill:"none",stroke:o,strokeWidth:s,strokeLinecap:"round",pathLength:100,strokeDasharray:"18 82"})}const Iw=e=>{const n=1/(Math.cbrt(e)*.8);let i=Math.round(650*n),o=Math.round(350*n);return i=Math.max(40,Math.min(450,i)),o=Math.max(30,Math.min(300,o)),{edgeSep:i,rankSep:o}};function kb(e,r=!1){return e&&!r&&typeof requestAnimationFrame<"u"&&!(typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches)}function Ab(e,r,t=()=>{},n=300){let i,o,s=!1;const a=()=>{s=!0,i!==void 0&&cancelAnimationFrame(i),clearTimeout(o)},c=()=>{s||(a(),r(1),t())};if(!kb(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||(i=requestAnimationFrame(d))};return i=requestAnimationFrame(d),o=setTimeout(c,n+100),a}function Nu(e,r,t){const n=new Set([e]),i=[e];for(;i.length;){const o=i.pop();for(const s of r)(s.parent===o||s.id.startsWith(`${o}.`)||t.some(c=>(c.inverted?c.target:c.source)===o&&(c.inverted?c.source:c.target)===s.id))&&!n.has(s.id)&&(n.add(s.id),i.push(s.id))}return n}function Mw(e,r,t){const n=t==="downward"||t==="upward",i=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=i.get(u)??[];h.push({edge:s,gap:d,cross:n?c.x-a.x:c.y-a.y}),i.set(u,h)}const o=new Map;for(const s of i.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},y)=>{const m=l.length===1?d/2:120+(d-280)*y/(l.length-1),g=l.find(b=>Math.abs(b.cross)<Math.abs(p));o.set(u.id,{turn:m/h,labelAtTarget:a.get(u.target)===1,labelFraction:p?(p+((g==null?void 0:g.cross)??0))/(2*p):.5})})}}return o}const Yt=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}),Tw=e=>({x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2,w:e.x2-e.x1,h:e.y2-e.y1});function $o(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 Ow=(e,r)=>e.x1<=r.x2&&e.x2>=r.x1&&e.y1<=r.y2&&e.y2>=r.y1,$u=(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)}`,Nw=e=>e>0?1:e<0?-1:0,qu=(e,r)=>e>0?Math.max(e-r,0):Math.min(e+r,0);function $w(e,r,t,n,i=10){const o=r.x-e.x,s=r.y-e.y,a=qu(o,(e.w+r.w)/2),c=qu(s,(e.h+r.h)/2),l=t==="downward"||t==="upward",d=l?c:a,u=l?s:o,h=Nw(u),p=n*d,y=v=>Math.abs(v)<i||Math.abs(v)>=Math.abs(d),m=y(p)||y(Math.abs(d)-Math.abs(p));let g;if(m)if(l)if(Math.abs(u)<=e.h/2){const v=(e.x+r.x)/2;g=[v,e.y,v,r.y]}else if(Math.abs(o)<=r.w/2){const v=(e.y+r.y)/2;g=[e.x,v,r.x,v]}else g=[e.x,r.y];else if(Math.abs(u)<=e.w/2){const v=(e.y+r.y)/2;g=[e.x,v,r.x,v]}else if(Math.abs(s)<=r.h/2){const v=(e.x+r.x)/2;g=[v,e.y,v,r.y]}else g=[r.x,e.y];else if(l){const v=e.y+p+e.h/2*h;g=[e.x,v,r.x,v]}else{const v=e.x+p+e.w/2*h;g=[v,e.y,v,r.y]}const b=[{x:e.x,y:e.y}];for(let v=0;v<g.length;v+=2)b.push({x:g[v],y:g[v+1]});return b.push({x:r.x,y:r.y}),b}function qw(e,r,t){const n=r.x-e.x,i=r.y-e.y,o=n>0?(t.x2-e.x)/n:n<0?(t.x1-e.x)/n:1/0,s=i>0?(t.y2-e.y)/i:i<0?(t.y1-e.y)/i:1/0,a=Math.min(o,s);return!Number.isFinite(a)||a>=1||a<0?null:{x:e.x+n*a,y:e.y+i*a}}function Wr(e,r,t){var s;if(!((s=t.outline)!=null&&s.length))return qw(e,r,Yt(t));const n=r.x-e.x,i=r.y-e.y;let o=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-i*u;if(Math.abs(p)<1e-9)return;const y=a.x-e.x,m=a.y-e.y,g=(y*h-m*u)/p,b=(y*i-m*n)/p;g>=0&&g<1&&b>=-1e-9&&b<=1+1e-9&&(o=Math.min(o,g))}),Number.isFinite(o)?{x:e.x+n*o,y:e.y+i*o}:null}function Pb(e,r,t=.5){const n=Number.isFinite(t)?Math.max(0,Math.min(1,t)):.5,i=r==="top"||r==="bottom",o=r==="top"||r==="left"?-1:1,s={x:i?e.x-e.w/2+e.w*n:e.x,y:i?e.y:e.y-e.h/2+e.h*n},a=Math.max(e.w,e.h)*2+1;return{...Wr(s,{x:s.x+(i?0:o*a),y:s.y+(i?o*a:0)},e)??{x:i?s.x:e.x+o*e.w/2,y:i?e.y+o*e.h/2:s.y},side:r}}function $r(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 Lw(e,r,t,n){const i=$r(e,t.srcDist),o=$r(r,t.tgtDist);if(n==="straight")return Mb(i,o,t);const s=Math.max(80,Math.min(300,Math.hypot(o.x-i.x,o.y-i.y)/3)),a=e.side==="bottom"&&r.side==="top"?o.y-i.y:e.side==="top"&&r.side==="bottom"?i.y-o.y:e.side==="right"&&r.side==="left"?o.x-i.x:e.side==="left"&&r.side==="right"?i.x-o.x:void 0,c=a!==void 0&&a>0?Math.min(s,a/2):s,l=$r({...i,side:e.side},c),d=$r({...o,side:r.side},c),u=t.arrowAt==="source"?mt(i,l,t.arrowGap):i,h=t.arrowAt==="target"?mt(o,d,t.arrowGap):o,p=t.arrowAt==="source"?qt(i,l,t.arrowSize,t.headShape):t.arrowAt==="target"?qt(o,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 y=e.side==="left"||e.side==="right",m=r.side==="left"||r.side==="right";let g;if(y!==m){const v=y?{x:d.x,y:l.y}:{x:l.x,y:d.y},x=(v.x-l.x)*(l.x-i.x)+(v.y-l.y)*(l.y-i.y)>=0,w=(v.x-d.x)*(d.x-o.x)+(v.y-d.y)*(d.y-o.y)>=0;g=[x&&w?v:y?{x:l.x,y:d.y}:{x:d.x,y:l.y}]}else if(a!==void 0&&a<=0)if(y){const v=(l.y+d.y)/2;g=[{x:l.x,y:v},{x:d.x,y:v}]}else{const v=(l.x+d.x)/2;g=[{x:v,y:l.y},{x:v,y:d.y}]}else if(y){const v=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:v,y:l.y},{x:v,y:d.y}]}else{const v=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:v},{x:d.x,y:v}]}const b=[l,...g,d].filter((v,x,w)=>x===0||v.x!==w[x-1].x||v.y!==w[x-1].y);return ao(u,b,h,p,n==="orthogonal"?0:t.radius)}function mt(e,r,t){const n=e.x-r.x,i=e.y-r.y,o=Math.hypot(n,i);if(!o)return e;let s=(o-t)/o;return s<0&&(s=1e-5),{x:r.x+s*n,y:r.y+s*i}}function qt(e,r,t,n="triangle"){const i=e.x-r.x,o=e.y-r.y,s=Math.hypot(i,o)||1,a=i/s,c=o/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((m,g)=>{const b=p[(g+2)%3],v=p[(g+1)%3],x=Math.hypot(b.x-m.x,b.y-m.y),w=Math.hypot(v.x-m.x,v.y-m.y),C={x:(b.x-m.x)/x,y:(b.y-m.y)/x},j={x:(v.x-m.x)/w,y:(v.y-m.y)/w},_=Math.max(-1,Math.min(1,C.x*j.x+C.y*j.y)),k=Math.sqrt((1-_)/(1+_)),E=Math.min(1/k,x/2,w/2);return{start:{x:m.x+C.x*E,y:m.y+C.y*E},end:{x:m.x+j.x*E,y:m.y+j.y*E},radius:E*k}}).map((m,g)=>`${g?"L":"M"}${ut(m.start)} A${Nt(m.radius)} ${Nt(m.radius)} 0 0 1 ${ut(m.end)}`).join(" ")+" Z"}function ar(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 Fw(e,r,t,n){const i={x:r.x-e.x,y:r.y-e.y},o={x:t.x-r.x,y:t.y-r.y},s=Math.hypot(i.x,i.y),a=Math.hypot(o.x,o.y),c=i.x*o.y-i.y*o.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-i.x/s*l,y:r.y-i.y/s*l},b:r,p2:{x:r.x+o.x/a*l,y:r.y+o.y/a*l},r:l}}function Ib(e,r,t,n){let i=-1,o=null;for(let y=0;y<e.length-1;y++){const m=Wr(e[y],e[y+1],r);if(m){i=y,o=m;break}}let s=-1,a=null;for(let y=e.length-1;y>0;y--){const m=Wr(e[y],e[y-1],t);if(m){s=y,a=m;break}}if(!o||!a||i>=s)return null;const c=e.slice(i+1,s),l=c[0]??a,d=c[c.length-1]??o;let u,h,p;if(n.arrowAt==="source"){const y=mt(o,l,n.srcDist);u=mt(o,l,n.srcDist+n.arrowGap),p=qt(y,l,n.arrowSize,n.headShape)}else u=mt(o,l,n.srcDist);if(n.arrowAt==="target"){const y=mt(a,d,n.tgtDist);h=mt(a,d,n.tgtDist+n.arrowGap),p=qt(y,d,n.arrowSize,n.headShape)}else h=mt(a,d,n.tgtDist);return ao(u,c,h,p,n.radius,n.labelTargetLength,n.labelFraction)}function ao(e,r,t,n,i,o,s){var h;const a=[e,...r,t],c=[];let l=`M${ut(e)}`;for(let p=1;p<a.length-1;p++){const y=Fw(a[p-1],a[p],a[p+1],i);c.push(y),y.r===0?l+=` L${ut(y.b)}`:l+=` L${ut(y.p1)} Q${ut(y.b)} ${ut(y.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:ar(t.x-e.x,t.y-e.y)};else if(u%2===0){const p=r[u/2-1],y=r[u/2];d={x:(p.x+y.x)/2,y:(p.y+y.y)/2,angle:ar(y.x-p.x,y.y-p.y)}}else{const p=c[(u-1)/2];if(p.r===0){const y=a[(u-1)/2+2];d={x:p.b.x,y:p.b.y,angle:ar(y.x-p.b.x,y.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:ar(p.p2.x-p.p1.x,p.p2.y-p.p1.y)}}if(o!==void 0){if(s!==void 0&&c.length===2){const g=c[0].p2,b=c[1].p1,v=Math.hypot(b.x-g.x,b.y-g.y),x=Math.min(.5,o/(2*v)),w=Math.max(x,Math.min(1-x,s));d={x:g.x+(b.x-g.x)*w,y:g.y+(b.y-g.y)*w,angle:ar(b.x-g.x,b.y-g.y)}}const p=((h=c[c.length-1])==null?void 0:h.p2)??e,y=t.x-p.x,m=t.y-p.y;Math.hypot(y,m)>=o&&(d={x:(p.x+t.x)/2,y:(p.y+t.y)/2,angle:ar(y,m)})}return{d:l,arrow:n,label:d}}function Lu(e,r,t,n,i,o,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:i??r.y},d=Math.max(80,s.arrowGap+s.arrowSize*.3),u=c.x+a*d,h=l.x-a*d;let p;if(a*(h-u)>=0){const b=c.x+(l.x-c.x)*o,v=Math.max(Math.min(u,h),Math.min(Math.max(u,h),b));p=[{x:v,y:c.y},{x:v,y:l.y}]}else{const b=Math.min(e.y-e.h/2,r.y-r.h/2)-d*(1+o);p=[{x:u,y:c.y},{x:u,y:b},{x:h,y:b},{x:h,y:l.y}]}const y=s.arrowAt==="source"?mt(c,p[0],s.arrowGap):c,m=s.arrowAt==="target"?mt(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 ao(y,p,m,g,s.radius)}function Fu(e,r,t,n,i){return Ib($w(e,r,t,n),e,r,i)}function zu(e,r,t,n,i,o){const s=n===void 0&&i===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,y=Wr(h,{x:h.x+(s?0:u*p),y:h.y+(s?u*p:0)},l);return y?{x:y.x+(s?0:u*o),y:y.y+(s?u*o:0)}:s?{x:l.x,y:l.y+u*(l.h/2+o)}:{x:l.x+u*(l.w/2+o),y:d??l.y}};return{sourcePoint:c(e,n,a),targetPoint:c(r,i,-a)}}function zw(e,r,t,n){const i=t==="downward"||t==="upward",o=t==="leftward"||t==="upward"?-1:1,s=Math.max(100,Math.abs(i?r.y-e.y:r.x-e.x)/2),a={x:e.x+(i?0:o*s),y:e.y+(i?o*s:0)},c={x:r.x-(i?0:o*s),y:r.y-(i?o*s:0)},l=n.arrowAt==="source"?mt(e,a,n.arrowGap):e,d=n.arrowAt==="target"?mt(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:ar(d.x+c.x-a.x-l.x,d.y+c.y-a.y-l.y)}}}function Mb(e,r,t){const n=t.arrowAt==="source"?mt(e,r,t.arrowGap):e,i=t.arrowAt==="target"?mt(r,e,t.arrowGap):r,o=t.arrowAt==="source"?qt(e,r,t.arrowSize,t.headShape):t.arrowAt==="target"?qt(r,e,t.arrowSize,t.headShape):void 0;return ao(n,[],i,o,0)}function Bw(e,r,t,n=-90,i=-60,o=350){const s=n*Math.PI/180,a=i*Math.PI/180,c=s-Math.PI/2,l=c-a/2,d=c+a/2,u=1.4*o*(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},y={x:e.x,y:e.y},m=Wr(y,h,e),g=Wr(y,p,e);if(!m||!g)return null;const b={x:(h.x+p.x)/2,y:(h.y+p.y)/2};let v=mt(m,h,t.srcDist),x=mt(g,p,t.tgtDist),w;if(t.arrowAt==="target"){const j=x;x=mt(g,p,t.tgtDist+t.arrowGap),w=qt(j,p,t.arrowSize,t.headShape)}else if(t.arrowAt==="source"){const j=v;v=mt(m,h,t.srcDist+t.arrowGap),w=qt(j,h,t.arrowSize,t.headShape)}return{d:`M${ut(v)} Q${ut(h)} ${ut(b)} Q${ut(p)} ${ut(x)}`,arrow:w,label:{x:b.x,y:b.y,angle:ar(p.x-h.x,p.y-h.y)}}}const Tr=e=>Math.round(e*1e3)/1e3;function Tb(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 i=r.getBoundingClientRect();if(!i.width||!i.height)return;const o=r,s=typeof o.getScreenCTM=="function"?o.getScreenCTM():null,a=typeof o.getTotalLength=="function"?o.getTotalLength():0,c=o.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):o.getPointAtLength(a*h/l);return{x:Tr((s.a*p.x+s.c*p.y+s.e-t.left)/n),y:Tr((s.b*p.x+s.d*p.y+s.f-t.top)/n)}}):void 0;return{left:Tr((i.left-t.left)/n),top:Tr((i.top-t.top)/n),width:r instanceof HTMLElement?r.offsetWidth:Tr(i.width/n),height:r instanceof HTMLElement?r.offsetHeight:Tr(i.height/n),radius:parseFloat(getComputedStyle(r).borderTopLeftRadius)||0,...d?{outline:d}:{}}}function wn(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(i=>({x:t+i.x,y:n+i.y}))}:{}}}function Dw(e,r,t,n,i){var d;const o=i!=="TB"&&i!=="BT",s=o?"top":"left",a=o?"bottom":"right",c=new Map;for(const u of n)for(const[h,p,y]of[[u.source,u.sourceProperty,u.target],[u.target,u.targetProperty,u.source]]){const m=r.get(y);if(p===void 0||!m||y===h)continue;const g=t.get(y),b=JSON.stringify([h,p]),v=c.get(b)??[];v.push(g?wn(m,g):m),c.set(b,v)}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 y=t.get(u),m=y?wn(p,y):p,g={x:p.w/2,y:p.h/2,w:p.w,h:p.h},b=y?wn(g,y):g,v=new Map;for(const x of h){if(x.placement!=="config")continue;const C=(c.get(JSON.stringify([u,x.property]))??[]).reduce((_,k)=>_+(o?k.y-m.y:k.x-m.x),0),j=((d=x.anchor)==null?void 0:d.side)===a?a:s;v.set(x,C<-.001?s:C>.001?a:j)}l.set(u,h.map(x=>{const w=v.get(x);if(!w)return x;const C=h.filter(k=>v.get(k)===w),j=(C.indexOf(x)+1)/(C.length+1),_=Pb(b,w,j);return{...x,anchor:_,top:_.y,height:0}}))}return l}function Bu(e,r,t){const n=new Set(r.map(a=>a.id));if(!n.has(e))return new Set;const i=new Set([e]);let o=!0;for(;o;){o=!1;for(const a of r)!i.has(a.id)&&(i.has(a.parent??"")||a.id.startsWith(`${e}.`))&&(i.add(a.id),o=!0)}const s=new Set(i);for(const a of t)i.has(a.source)&&n.has(a.target)&&s.add(a.target),i.has(a.target)&&n.has(a.source)&&s.add(a.source);return s}const lr='"Helvetica Neue", Helvetica, sans-serif';let an;const Dn=new Map;function so(e,r){const t=`${r}|${e}`,n=Dn.get(t);if(n!==void 0)return n;an===void 0&&(an=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let i;return an?(an.font=r,i=an.measureText(e).width):i=e.length*(parseFloat(r)||16)*.55,Dn.size>5e3&&Dn.clear(),Dn.set(t,i),i}function Vw(e,r,t){const n=[];for(const i of String(e).split(`
210
- `)){const o=i.split(/\s+/).filter(Boolean);if(!o.length){n.push("");continue}let s="";for(const a of o){const c=s?`${s} ${a}`:a;!s||so(c,r)<=t?s=c:(n.push(s),s=a)}n.push(s)}return n}const Du=e=>e.stopPropagation();function Gw({id:e,rect:r,label:t,labelLayer:n,labelContent:i,style:o,onSelect:s,onCollapse:a,selected:c=!1}){const l=r.x2-r.x1,d=r.y2-r.y1,u=o.borderWidth,h=o.borderStyle==="dashed"?`${u*4} ${u*2}`:o.borderStyle==="dotted"?`${u} ${u}`:void 0,p=r.x1+l/2,y=o.labelPosition==="top"?r.y1+o.labelMargin-o.fontSize/2:o.labelPosition==="bottom"?r.y2-o.labelMargin+o.fontSize/2:r.y1+d/2,m=t?so(t,`bold ${o.fontSize}px ${lr}`):0,g=o.fontSize/5,b=t||c&&a?f.jsxs("g",{className:"flow-sdk-container-label","data-node-id":e,children:[c&&a&&f.jsx("foreignObject",{x:p+m/2+g+8,y:y-24,width:48,height:48,"data-flow-content-toggle":"","data-flow-collapse-control":"",style:{pointerEvents:"auto"},children:f.jsx(Be,{label:"Show icon",children:f.jsx(Pe,{"aria-label":"Show icon",icon:f.jsx(Z.PiCircleFill,{}),variant:"ghost",style:{width:48,height:48,color:o.textColor},onClick:v=>{v.stopPropagation(),a(e)}})})}),i?f.jsx("foreignObject",{x:p-m/2-g,y:y-o.fontSize/2-g,width:m+2*g,height:o.fontSize+2*g,style:{overflow:"visible"},onClick:Du,children:i}):t&&f.jsxs(f.Fragment,{children:[f.jsx("rect",{x:p-m/2-g,y:y-o.fontSize/2-g,width:m+2*g,height:o.fontSize+2*g,fill:o.textColor==="transparent"?"transparent":o.labelBg}),f.jsx("text",{x:p,y,fill:o.textColor,fontSize:o.fontSize,fontWeight:"bold",fontFamily:lr,style:{fontSize:o.fontSize,fontWeight:"bold",fontFamily:lr},textAnchor:"middle",dominantBaseline:"central",children:t})]})]}):null;return f.jsxs("g",{className:"flow-sdk-container","data-node-id":e,onPointerDown:Du,onClick:v=>{v.stopPropagation(),s==null||s(e,{shiftKey:v.shiftKey,ctrlKey:v.ctrlKey,metaKey:v.metaKey,altKey:v.altKey})},children:[f.jsx("rect",{x:r.x1,y:r.y1,width:l,height:d,rx:o.borderRadius,ry:o.borderRadius,fill:o.bgColor,fillOpacity:o.bgOpacity,stroke:o.borderColor,strokeWidth:o.borderStyle==="double"?u/3:u,strokeDasharray:h}),o.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,o.borderRadius-u*2/3),ry:Math.max(0,o.borderRadius-u*2/3),fill:"none",stroke:o.borderColor,strokeWidth:u/3}),o.animated&&u>0&&f.jsx(Zn,{variant:o.animationVariant,x:r.x1,y:r.y1,width:l,height:d,radius:o.borderRadius,color:o.animationColor||o.borderColor,strokeWidth:Math.max(8,u*1.6)}),n&&b?Br.createPortal(b,n):b]})}const Ww=S.memo(Gw),Xn=45,Ob=70,xr=15,Nb=50;function $b(e,r,t=Xn){const n=`${t}px ${lr}`,i=e?Vw(e,n,200*t/Xn):[],o=r?48+(i.length?12:0):0,s=o+Math.max(0,...i.map(l=>so(l,n))),a=Math.max(i.length*t,r?48:0),c=i.length||r?2*xr:0;return{lines:i,iconWidth:o,contentWidth:s,contentHeight:a,width:s+c,height:a+c}}const Cn=6,qb=3,Id=.3,Uw=8,Md=Math.max(Math.pow(Cn*13.37,.9),29)*qb-Uw/Id,Lb=Cn*qb*2,Wn=80,Hw=2*Wn+Md*Id+100,Kw=36+2*Math.max(80,Lb+Md*Id);function cd(e){return e.sourceProperty!==void 0||e.targetProperty!==void 0}function ld(e,r){return r==="auto"||(r==="properties"?cd(e):!cd(e))}function or(e,r,t){return t!=="properties"||e!=="root"||r.some(n=>(n.source===e||n.target===e)&&cd(n))}function Jw(e,r,t,n=!1,i){if(!n)return{nodes:e,edges:r};const o=e.filter(a=>or(a.id,r,t)&&(!i||i.has(a.id))),s=new Set(o.map(a=>a.id));return{nodes:o,edges:r.filter(a=>ld(a,t)&&s.has(a.source)&&s.has(a.target))}}const Zw=500,Xw="32 18",Yw=e=>e.stopPropagation();function Qw({id:e,reveal:r,onRevealComplete:t,edgeData:n,validationIssue:i,edgeType:o="rounded-orthogonal",edgeRadius:s,customEdgeTypes:a,source:c,target:l,sourceProperty:d,targetProperty:u,sourceY:h,targetY:p,sourcePort:y,targetPort:m,propertyMode:g=!1,dir:b,turn:v,labelAtTarget:x,labelFraction:w,color:C,connectorColor:j,labelBg:_,labelLayer:k,label:E,dashed:O,animated:T,inverted:P,loopIndex:I=0,onSelect:R}){const $=n==null?void 0:n.icon,N=g?Xn:Ob,{lines:M,iconWidth:J,contentWidth:ae,contentHeight:se}=S.useMemo(()=>$b(E,$,N),[E,$,N]),ee=S.useMemo(()=>{const je={srcDist:Wn,tgtDist:Wn,arrowGap:Lb,arrowSize:Md,headShape:g&&(P?h!==void 0||y:p!==void 0||m)?"square":"triangle",radius:s??(x?40:Zw),arrowAt:P?"source":"target",labelTargetLength:x?ae+2*xr:void 0,labelFraction:x?w:void 0},ye=h!==void 0||p!==void 0||!!y||!!m,ge=zu(c,l,b,h,p,0),z=h===void 0&&p===void 0&&(b==="downward"||b==="upward"),W=y??{...ge.sourcePoint,side:z?b==="upward"?"top":"bottom":b==="leftward"?"left":"right"},ie=m??{...ge.targetPoint,side:z?b==="upward"?"bottom":"top":b==="leftward"?"right":"left"},K=c.x===l.x&&c.y===l.y,ue=y||m?Lw(W,ie,{...je,srcDist:18,tgtDist:18},o):ye?Lu(c,l,b,h,p,v,{...je,srcDist:18,tgtDist:18,radius:s??Math.min(je.radius,40)}):K?Bw(c,I,{...je,srcDist:0,tgtDist:0}):Fu(c,l,b,v,je);if(!ue)return null;const ve=zu(c,l,b,h,p,ye?18:Wn);y&&(ve.sourcePoint=$r(y,18)),m&&(ve.targetPoint=$r(m,18));const Oe=Object.prototype.hasOwnProperty.call(a??{},o)?a==null?void 0:a[o]:void 0;if(Oe){const $e={rightward:"LR",leftward:"RL",downward:"TB",upward:"BT"};return Oe({edge:n??{id:e,source:"",target:""},source:{...c},target:{...l},...ve,direction:$e[b],sourceY:h,targetY:p,inverted:!!P,defaultGeometry:ue})??ue}return K||y||m?ue:o==="straight"?ye?Mb(ve.sourcePoint,ve.targetPoint,je):Ib([c,l],c,l,je):o==="bezier"?zw(ve.sourcePoint,ve.targetPoint,ye?b==="leftward"?"leftward":"rightward":b,je):o==="orthogonal"?ye?Lu(c,l,b,h,p,v,{...je,srcDist:18,tgtDist:18,radius:0}):Fu(c,l,b,v,{...je,radius:0}):ue},[c,e,n,o,s,a,l,g,h,p,y,m,b,v,P,I,x,w,ae]);if(!ee)return null;const pe=(b==="rightward"||b==="leftward")&&!Object.prototype.hasOwnProperty.call(a??{},o)&&!(g&&(h!==void 0||p!==void 0||y||m)),me=pe?`translate(${ee.label.x} ${ee.label.y-se/2-2*xr})`:`translate(${ee.label.x} ${ee.label.y}) rotate(${ee.label.angle}) translate(${b==="downward"||b==="upward"||x||Object.prototype.hasOwnProperty.call(a??{},o)?0:Nb} 0)`,q=i!=null&&i.startsWith("Unverified:")?"#b45309":"#dc2626",F=i?q:C,H=i?f.jsxs("g",{className:"flow-sdk-edge-validation",role:"img","aria-label":i,transform:`translate(${ee.label.x} ${ee.label.y-M.length*N/2-55})`,children:[f.jsx("title",{children:i}),f.jsx(Jt,{name:"PiWarningCircleFill",svg:!0,size:48,x:-24,y:-24,color:q})]}):null,B=T&&(n==null?void 0:n.edgeAnimationVariant)==="traveling",de=!B&&(O||T)?Xw:void 0,Y=T&&!B?`flow-sdk-edge-anim${P?" flow-sdk-edge-anim-rev":""}`:void 0;let oe=null;const ce=r?{"--flow-edge-reveal-duration":`${r.durationMs??600}ms`,"--flow-edge-reveal-state":r.paused?"paused":"running"}:void 0;if(M.length||$){const je=ae,ye=se;oe=f.jsxs("g",{className:`flow-sdk-edge-label${r?" flow-sdk-edge-reveal-end":""}`,style:ce,"data-label-transform":me,"data-label-horizontal":pe||void 0,"data-edge-id":e,"data-source-property":d,"data-target-property":u,transform:me,children:[f.jsx("rect",{x:-je/2-xr,y:-ye/2-xr,width:je+2*xr,height:ye+2*xr,fill:C==="transparent"?"transparent":_}),f.jsx("text",{fill:C,fontSize:N,style:{fontSize:N,fontFamily:lr},fontFamily:lr,textAnchor:"middle",dominantBaseline:"central",children:M.map((ge,z)=>f.jsx("tspan",{x:J/2,y:(z-(M.length-1)/2)*N,children:ge},z))}),$&&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:-je/2,y:-24,width:48,height:48,fill:"transparent"}),f.jsx(Jt,{name:$,svg:!0,size:48,x:-je/2,y:-24,color:C})]})]})}const xe=f.jsxs(f.Fragment,{children:[f.jsx("path",{d:ee.d,fill:"none",stroke:F,strokeWidth:Cn,strokeOpacity:B?.35:void 0,strokeDasharray:de,className:Y}),B&&f.jsx(Pw,{path:ee.d,color:F,width:Cn*1.6,reversed:P})]});return f.jsxs("g",{className:"flow-sdk-edge",style:ce,"data-edge-id":e,"data-source-property":d,"data-target-property":u,"data-validation":i?i.startsWith("Unverified:")?"unverified":"invalid":void 0,"aria-label":i,onPointerDown:Yw,onClick:je=>{je.stopPropagation(),R==null||R(e)},children:[r?f.jsx(kw,{path:ee.d,width:Cn*4,reversed:P,onComplete:()=>t==null?void 0:t(e),children:xe}):xe,ee.arrow&&f.jsx("path",{className:r?"flow-sdk-edge-reveal-end":void 0,d:ee.arrow,fill:i?q:j??F}),k&&oe?Br.createPortal(oe,k):oe,k&&H?Br.createPortal(H,k):H,f.jsx("path",{className:"flow-sdk-edge-hit",d:ee.d,fill:"none",stroke:"transparent"})]})}const Vu=S.memo(Qw);var Vn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function e1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Td(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 qo,Gu;function t1(){if(Gu)return qo;Gu=1;function e(){this.__data__=[],this.size=0}return qo=e,qo}var Lo,Wu;function Zr(){if(Wu)return Lo;Wu=1;function e(r,t){return r===t||r!==r&&t!==t}return Lo=e,Lo}var Fo,Uu;function co(){if(Uu)return Fo;Uu=1;var e=Zr();function r(t,n){for(var i=t.length;i--;)if(e(t[i][0],n))return i;return-1}return Fo=r,Fo}var zo,Hu;function r1(){if(Hu)return zo;Hu=1;var e=co(),r=Array.prototype,t=r.splice;function n(i){var o=this.__data__,s=e(o,i);if(s<0)return!1;var a=o.length-1;return s==a?o.pop():t.call(o,s,1),--this.size,!0}return zo=n,zo}var Bo,Ku;function n1(){if(Ku)return Bo;Ku=1;var e=co();function r(t){var n=this.__data__,i=e(n,t);return i<0?void 0:n[i][1]}return Bo=r,Bo}var Do,Ju;function o1(){if(Ju)return Do;Ju=1;var e=co();function r(t){return e(this.__data__,t)>-1}return Do=r,Do}var Vo,Zu;function i1(){if(Zu)return Vo;Zu=1;var e=co();function r(t,n){var i=this.__data__,o=e(i,t);return o<0?(++this.size,i.push([t,n])):i[o][1]=n,this}return Vo=r,Vo}var Go,Xu;function lo(){if(Xu)return Go;Xu=1;var e=t1(),r=r1(),t=n1(),n=o1(),i=i1();function o(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 o.prototype.clear=e,o.prototype.delete=r,o.prototype.get=t,o.prototype.has=n,o.prototype.set=i,Go=o,Go}var Wo,Yu;function a1(){if(Yu)return Wo;Yu=1;var e=lo();function r(){this.__data__=new e,this.size=0}return Wo=r,Wo}var Uo,Qu;function s1(){if(Qu)return Uo;Qu=1;function e(r){var t=this.__data__,n=t.delete(r);return this.size=t.size,n}return Uo=e,Uo}var Ho,ef;function c1(){if(ef)return Ho;ef=1;function e(r){return this.__data__.get(r)}return Ho=e,Ho}var Ko,tf;function l1(){if(tf)return Ko;tf=1;function e(r){return this.__data__.has(r)}return Ko=e,Ko}var Jo,rf;function Fb(){if(rf)return Jo;rf=1;var e=typeof Vn=="object"&&Vn&&Vn.Object===Object&&Vn;return Jo=e,Jo}var Zo,nf;function Gt(){if(nf)return Zo;nf=1;var e=Fb(),r=typeof self=="object"&&self&&self.Object===Object&&self,t=e||r||Function("return this")();return Zo=t,Zo}var Xo,of;function Xr(){if(of)return Xo;of=1;var e=Gt(),r=e.Symbol;return Xo=r,Xo}var Yo,af;function d1(){if(af)return Yo;af=1;var e=Xr(),r=Object.prototype,t=r.hasOwnProperty,n=r.toString,i=e?e.toStringTag:void 0;function o(s){var a=t.call(s,i),c=s[i];try{s[i]=void 0;var l=!0}catch{}var d=n.call(s);return l&&(a?s[i]=c:delete s[i]),d}return Yo=o,Yo}var Qo,sf;function u1(){if(sf)return Qo;sf=1;var e=Object.prototype,r=e.toString;function t(n){return r.call(n)}return Qo=t,Qo}var ei,cf;function Rr(){if(cf)return ei;cf=1;var e=Xr(),r=d1(),t=u1(),n="[object Null]",i="[object Undefined]",o=e?e.toStringTag:void 0;function s(a){return a==null?a===void 0?i:n:o&&o in Object(a)?r(a):t(a)}return ei=s,ei}var ti,lf;function Lt(){if(lf)return ti;lf=1;function e(r){var t=typeof r;return r!=null&&(t=="object"||t=="function")}return ti=e,ti}var ri,df;function In(){if(df)return ri;df=1;var e=Rr(),r=Lt(),t="[object AsyncFunction]",n="[object Function]",i="[object GeneratorFunction]",o="[object Proxy]";function s(a){if(!r(a))return!1;var c=e(a);return c==n||c==i||c==t||c==o}return ri=s,ri}var ni,uf;function f1(){if(uf)return ni;uf=1;var e=Gt(),r=e["__core-js_shared__"];return ni=r,ni}var oi,ff;function h1(){if(ff)return oi;ff=1;var e=f1(),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 oi=t,oi}var ii,hf;function zb(){if(hf)return ii;hf=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 ii=t,ii}var ai,pf;function p1(){if(pf)return ai;pf=1;var e=In(),r=h1(),t=Lt(),n=zb(),i=/[\\^$.*+?()[\]{}|]/g,o=/^\[object .+?Constructor\]$/,s=Function.prototype,a=Object.prototype,c=s.toString,l=a.hasOwnProperty,d=RegExp("^"+c.call(l).replace(i,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function u(h){if(!t(h)||r(h))return!1;var p=e(h)?d:o;return p.test(n(h))}return ai=u,ai}var si,gf;function g1(){if(gf)return si;gf=1;function e(r,t){return r==null?void 0:r[t]}return si=e,si}var ci,yf;function kr(){if(yf)return ci;yf=1;var e=p1(),r=g1();function t(n,i){var o=r(n,i);return e(o)?o:void 0}return ci=t,ci}var li,mf;function Od(){if(mf)return li;mf=1;var e=kr(),r=Gt(),t=e(r,"Map");return li=t,li}var di,bf;function uo(){if(bf)return di;bf=1;var e=kr(),r=e(Object,"create");return di=r,di}var ui,vf;function y1(){if(vf)return ui;vf=1;var e=uo();function r(){this.__data__=e?e(null):{},this.size=0}return ui=r,ui}var fi,xf;function m1(){if(xf)return fi;xf=1;function e(r){var t=this.has(r)&&delete this.__data__[r];return this.size-=t?1:0,t}return fi=e,fi}var hi,wf;function b1(){if(wf)return hi;wf=1;var e=uo(),r="__lodash_hash_undefined__",t=Object.prototype,n=t.hasOwnProperty;function i(o){var s=this.__data__;if(e){var a=s[o];return a===r?void 0:a}return n.call(s,o)?s[o]:void 0}return hi=i,hi}var pi,Cf;function v1(){if(Cf)return pi;Cf=1;var e=uo(),r=Object.prototype,t=r.hasOwnProperty;function n(i){var o=this.__data__;return e?o[i]!==void 0:t.call(o,i)}return pi=n,pi}var gi,Sf;function x1(){if(Sf)return gi;Sf=1;var e=uo(),r="__lodash_hash_undefined__";function t(n,i){var o=this.__data__;return this.size+=this.has(n)?0:1,o[n]=e&&i===void 0?r:i,this}return gi=t,gi}var yi,jf;function w1(){if(jf)return yi;jf=1;var e=y1(),r=m1(),t=b1(),n=v1(),i=x1();function o(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 o.prototype.clear=e,o.prototype.delete=r,o.prototype.get=t,o.prototype.has=n,o.prototype.set=i,yi=o,yi}var mi,_f;function C1(){if(_f)return mi;_f=1;var e=w1(),r=lo(),t=Od();function n(){this.size=0,this.__data__={hash:new e,map:new(t||r),string:new e}}return mi=n,mi}var bi,Ef;function S1(){if(Ef)return bi;Ef=1;function e(r){var t=typeof r;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?r!=="__proto__":r===null}return bi=e,bi}var vi,Rf;function fo(){if(Rf)return vi;Rf=1;var e=S1();function r(t,n){var i=t.__data__;return e(n)?i[typeof n=="string"?"string":"hash"]:i.map}return vi=r,vi}var xi,kf;function j1(){if(kf)return xi;kf=1;var e=fo();function r(t){var n=e(this,t).delete(t);return this.size-=n?1:0,n}return xi=r,xi}var wi,Af;function _1(){if(Af)return wi;Af=1;var e=fo();function r(t){return e(this,t).get(t)}return wi=r,wi}var Ci,Pf;function E1(){if(Pf)return Ci;Pf=1;var e=fo();function r(t){return e(this,t).has(t)}return Ci=r,Ci}var Si,If;function R1(){if(If)return Si;If=1;var e=fo();function r(t,n){var i=e(this,t),o=i.size;return i.set(t,n),this.size+=i.size==o?0:1,this}return Si=r,Si}var ji,Mf;function Nd(){if(Mf)return ji;Mf=1;var e=C1(),r=j1(),t=_1(),n=E1(),i=R1();function o(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 o.prototype.clear=e,o.prototype.delete=r,o.prototype.get=t,o.prototype.has=n,o.prototype.set=i,ji=o,ji}var _i,Tf;function k1(){if(Tf)return _i;Tf=1;var e=lo(),r=Od(),t=Nd(),n=200;function i(o,s){var a=this.__data__;if(a instanceof e){var c=a.__data__;if(!r||c.length<n-1)return c.push([o,s]),this.size=++a.size,this;a=this.__data__=new t(c)}return a.set(o,s),this.size=a.size,this}return _i=i,_i}var Ei,Of;function ho(){if(Of)return Ei;Of=1;var e=lo(),r=a1(),t=s1(),n=c1(),i=l1(),o=k1();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=i,s.prototype.set=o,Ei=s,Ei}var Ri,Nf;function $d(){if(Nf)return Ri;Nf=1;function e(r,t){for(var n=-1,i=r==null?0:r.length;++n<i&&t(r[n],n,r)!==!1;);return r}return Ri=e,Ri}var ki,$f;function Bb(){if($f)return ki;$f=1;var e=kr(),r=(function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch{}})();return ki=r,ki}var Ai,qf;function po(){if(qf)return Ai;qf=1;var e=Bb();function r(t,n,i){n=="__proto__"&&e?e(t,n,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[n]=i}return Ai=r,Ai}var Pi,Lf;function go(){if(Lf)return Pi;Lf=1;var e=po(),r=Zr(),t=Object.prototype,n=t.hasOwnProperty;function i(o,s,a){var c=o[s];(!(n.call(o,s)&&r(c,a))||a===void 0&&!(s in o))&&e(o,s,a)}return Pi=i,Pi}var Ii,Ff;function Mn(){if(Ff)return Ii;Ff=1;var e=go(),r=po();function t(n,i,o,s){var a=!o;o||(o={});for(var c=-1,l=i.length;++c<l;){var d=i[c],u=s?s(o[d],n[d],d,o,n):void 0;u===void 0&&(u=n[d]),a?r(o,d,u):e(o,d,u)}return o}return Ii=t,Ii}var Mi,zf;function A1(){if(zf)return Mi;zf=1;function e(r,t){for(var n=-1,i=Array(r);++n<r;)i[n]=t(n);return i}return Mi=e,Mi}var Ti,Bf;function Zt(){if(Bf)return Ti;Bf=1;function e(r){return r!=null&&typeof r=="object"}return Ti=e,Ti}var Oi,Df;function P1(){if(Df)return Oi;Df=1;var e=Rr(),r=Zt(),t="[object Arguments]";function n(i){return r(i)&&e(i)==t}return Oi=n,Oi}var Ni,Vf;function Tn(){if(Vf)return Ni;Vf=1;var e=P1(),r=Zt(),t=Object.prototype,n=t.hasOwnProperty,i=t.propertyIsEnumerable,o=e((function(){return arguments})())?e:function(s){return r(s)&&n.call(s,"callee")&&!i.call(s,"callee")};return Ni=o,Ni}var $i,Gf;function gt(){if(Gf)return $i;Gf=1;var e=Array.isArray;return $i=e,$i}var un={exports:{}},qi,Wf;function I1(){if(Wf)return qi;Wf=1;function e(){return!1}return qi=e,qi}un.exports;var Uf;function Yr(){return Uf||(Uf=1,(function(e,r){var t=Gt(),n=I1(),i=r&&!r.nodeType&&r,o=i&&!0&&e&&!e.nodeType&&e,s=o&&o.exports===i,a=s?t.Buffer:void 0,c=a?a.isBuffer:void 0,l=c||n;e.exports=l})(un,un.exports)),un.exports}var Li,Hf;function yo(){if(Hf)return Li;Hf=1;var e=9007199254740991,r=/^(?:0|[1-9]\d*)$/;function t(n,i){var o=typeof n;return i=i??e,!!i&&(o=="number"||o!="symbol"&&r.test(n))&&n>-1&&n%1==0&&n<i}return Li=t,Li}var Fi,Kf;function qd(){if(Kf)return Fi;Kf=1;var e=9007199254740991;function r(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=e}return Fi=r,Fi}var zi,Jf;function M1(){if(Jf)return zi;Jf=1;var e=Rr(),r=qd(),t=Zt(),n="[object Arguments]",i="[object Array]",o="[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]",y="[object String]",m="[object WeakMap]",g="[object ArrayBuffer]",b="[object DataView]",v="[object Float32Array]",x="[object Float64Array]",w="[object Int8Array]",C="[object Int16Array]",j="[object Int32Array]",_="[object Uint8Array]",k="[object Uint8ClampedArray]",E="[object Uint16Array]",O="[object Uint32Array]",T={};T[v]=T[x]=T[w]=T[C]=T[j]=T[_]=T[k]=T[E]=T[O]=!0,T[n]=T[i]=T[g]=T[o]=T[b]=T[s]=T[a]=T[c]=T[l]=T[d]=T[u]=T[h]=T[p]=T[y]=T[m]=!1;function P(I){return t(I)&&r(I.length)&&!!T[e(I)]}return zi=P,zi}var Bi,Zf;function mo(){if(Zf)return Bi;Zf=1;function e(r){return function(t){return r(t)}}return Bi=e,Bi}var fn={exports:{}};fn.exports;var Xf;function Ld(){return Xf||(Xf=1,(function(e,r){var t=Fb(),n=r&&!r.nodeType&&r,i=n&&!0&&e&&!e.nodeType&&e,o=i&&i.exports===n,s=o&&t.process,a=(function(){try{var c=i&&i.require&&i.require("util").types;return c||s&&s.binding&&s.binding("util")}catch{}})();e.exports=a})(fn,fn.exports)),fn.exports}var Di,Yf;function On(){if(Yf)return Di;Yf=1;var e=M1(),r=mo(),t=Ld(),n=t&&t.isTypedArray,i=n?r(n):e;return Di=i,Di}var Vi,Qf;function Db(){if(Qf)return Vi;Qf=1;var e=A1(),r=Tn(),t=gt(),n=Yr(),i=yo(),o=On(),s=Object.prototype,a=s.hasOwnProperty;function c(l,d){var u=t(l),h=!u&&r(l),p=!u&&!h&&n(l),y=!u&&!h&&!p&&o(l),m=u||h||p||y,g=m?e(l.length,String):[],b=g.length;for(var v in l)(d||a.call(l,v))&&!(m&&(v=="length"||p&&(v=="offset"||v=="parent")||y&&(v=="buffer"||v=="byteLength"||v=="byteOffset")||i(v,b)))&&g.push(v);return g}return Vi=c,Vi}var Gi,eh;function bo(){if(eh)return Gi;eh=1;var e=Object.prototype;function r(t){var n=t&&t.constructor,i=typeof n=="function"&&n.prototype||e;return t===i}return Gi=r,Gi}var Wi,th;function Vb(){if(th)return Wi;th=1;function e(r,t){return function(n){return r(t(n))}}return Wi=e,Wi}var Ui,rh;function T1(){if(rh)return Ui;rh=1;var e=Vb(),r=e(Object.keys,Object);return Ui=r,Ui}var Hi,nh;function Fd(){if(nh)return Hi;nh=1;var e=bo(),r=T1(),t=Object.prototype,n=t.hasOwnProperty;function i(o){if(!e(o))return r(o);var s=[];for(var a in Object(o))n.call(o,a)&&a!="constructor"&&s.push(a);return s}return Hi=i,Hi}var Ki,oh;function er(){if(oh)return Ki;oh=1;var e=In(),r=qd();function t(n){return n!=null&&r(n.length)&&!e(n)}return Ki=t,Ki}var Ji,ih;function gr(){if(ih)return Ji;ih=1;var e=Db(),r=Fd(),t=er();function n(i){return t(i)?e(i):r(i)}return Ji=n,Ji}var Zi,ah;function O1(){if(ah)return Zi;ah=1;var e=Mn(),r=gr();function t(n,i){return n&&e(i,r(i),n)}return Zi=t,Zi}var Xi,sh;function N1(){if(sh)return Xi;sh=1;function e(r){var t=[];if(r!=null)for(var n in Object(r))t.push(n);return t}return Xi=e,Xi}var Yi,ch;function $1(){if(ch)return Yi;ch=1;var e=Lt(),r=bo(),t=N1(),n=Object.prototype,i=n.hasOwnProperty;function o(s){if(!e(s))return t(s);var a=r(s),c=[];for(var l in s)l=="constructor"&&(a||!i.call(s,l))||c.push(l);return c}return Yi=o,Yi}var Qi,lh;function Ar(){if(lh)return Qi;lh=1;var e=Db(),r=$1(),t=er();function n(i){return t(i)?e(i,!0):r(i)}return Qi=n,Qi}var ea,dh;function q1(){if(dh)return ea;dh=1;var e=Mn(),r=Ar();function t(n,i){return n&&e(i,r(i),n)}return ea=t,ea}var hn={exports:{}};hn.exports;var uh;function Gb(){return uh||(uh=1,(function(e,r){var t=Gt(),n=r&&!r.nodeType&&r,i=n&&!0&&e&&!e.nodeType&&e,o=i&&i.exports===n,s=o?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})(hn,hn.exports)),hn.exports}var ta,fh;function Wb(){if(fh)return ta;fh=1;function e(r,t){var n=-1,i=r.length;for(t||(t=Array(i));++n<i;)t[n]=r[n];return t}return ta=e,ta}var ra,hh;function Ub(){if(hh)return ra;hh=1;function e(r,t){for(var n=-1,i=r==null?0:r.length,o=0,s=[];++n<i;){var a=r[n];t(a,n,r)&&(s[o++]=a)}return s}return ra=e,ra}var na,ph;function Hb(){if(ph)return na;ph=1;function e(){return[]}return na=e,na}var oa,gh;function zd(){if(gh)return oa;gh=1;var e=Ub(),r=Hb(),t=Object.prototype,n=t.propertyIsEnumerable,i=Object.getOwnPropertySymbols,o=i?function(s){return s==null?[]:(s=Object(s),e(i(s),function(a){return n.call(s,a)}))}:r;return oa=o,oa}var ia,yh;function L1(){if(yh)return ia;yh=1;var e=Mn(),r=zd();function t(n,i){return e(n,r(n),i)}return ia=t,ia}var aa,mh;function Bd(){if(mh)return aa;mh=1;function e(r,t){for(var n=-1,i=t.length,o=r.length;++n<i;)r[o+n]=t[n];return r}return aa=e,aa}var sa,bh;function vo(){if(bh)return sa;bh=1;var e=Vb(),r=e(Object.getPrototypeOf,Object);return sa=r,sa}var ca,vh;function Kb(){if(vh)return ca;vh=1;var e=Bd(),r=vo(),t=zd(),n=Hb(),i=Object.getOwnPropertySymbols,o=i?function(s){for(var a=[];s;)e(a,t(s)),s=r(s);return a}:n;return ca=o,ca}var la,xh;function F1(){if(xh)return la;xh=1;var e=Mn(),r=Kb();function t(n,i){return e(n,r(n),i)}return la=t,la}var da,wh;function Jb(){if(wh)return da;wh=1;var e=Bd(),r=gt();function t(n,i,o){var s=i(n);return r(n)?s:e(s,o(n))}return da=t,da}var ua,Ch;function Zb(){if(Ch)return ua;Ch=1;var e=Jb(),r=zd(),t=gr();function n(i){return e(i,t,r)}return ua=n,ua}var fa,Sh;function z1(){if(Sh)return fa;Sh=1;var e=Jb(),r=Kb(),t=Ar();function n(i){return e(i,t,r)}return fa=n,fa}var ha,jh;function B1(){if(jh)return ha;jh=1;var e=kr(),r=Gt(),t=e(r,"DataView");return ha=t,ha}var pa,_h;function D1(){if(_h)return pa;_h=1;var e=kr(),r=Gt(),t=e(r,"Promise");return pa=t,pa}var ga,Eh;function Xb(){if(Eh)return ga;Eh=1;var e=kr(),r=Gt(),t=e(r,"Set");return ga=t,ga}var ya,Rh;function V1(){if(Rh)return ya;Rh=1;var e=kr(),r=Gt(),t=e(r,"WeakMap");return ya=t,ya}var ma,kh;function Qr(){if(kh)return ma;kh=1;var e=B1(),r=Od(),t=D1(),n=Xb(),i=V1(),o=Rr(),s=zb(),a="[object Map]",c="[object Object]",l="[object Promise]",d="[object Set]",u="[object WeakMap]",h="[object DataView]",p=s(e),y=s(r),m=s(t),g=s(n),b=s(i),v=o;return(e&&v(new e(new ArrayBuffer(1)))!=h||r&&v(new r)!=a||t&&v(t.resolve())!=l||n&&v(new n)!=d||i&&v(new i)!=u)&&(v=function(x){var w=o(x),C=w==c?x.constructor:void 0,j=C?s(C):"";if(j)switch(j){case p:return h;case y:return a;case m:return l;case g:return d;case b:return u}return w}),ma=v,ma}var ba,Ah;function G1(){if(Ah)return ba;Ah=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n){var i=n.length,o=new n.constructor(i);return i&&typeof n[0]=="string"&&r.call(n,"index")&&(o.index=n.index,o.input=n.input),o}return ba=t,ba}var va,Ph;function Yb(){if(Ph)return va;Ph=1;var e=Gt(),r=e.Uint8Array;return va=r,va}var xa,Ih;function Dd(){if(Ih)return xa;Ih=1;var e=Yb();function r(t){var n=new t.constructor(t.byteLength);return new e(n).set(new e(t)),n}return xa=r,xa}var wa,Mh;function W1(){if(Mh)return wa;Mh=1;var e=Dd();function r(t,n){var i=n?e(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.byteLength)}return wa=r,wa}var Ca,Th;function U1(){if(Th)return Ca;Th=1;var e=/\w*$/;function r(t){var n=new t.constructor(t.source,e.exec(t));return n.lastIndex=t.lastIndex,n}return Ca=r,Ca}var Sa,Oh;function H1(){if(Oh)return Sa;Oh=1;var e=Xr(),r=e?e.prototype:void 0,t=r?r.valueOf:void 0;function n(i){return t?Object(t.call(i)):{}}return Sa=n,Sa}var ja,Nh;function Qb(){if(Nh)return ja;Nh=1;var e=Dd();function r(t,n){var i=n?e(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}return ja=r,ja}var _a,$h;function K1(){if($h)return _a;$h=1;var e=Dd(),r=W1(),t=U1(),n=H1(),i=Qb(),o="[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]",y="[object DataView]",m="[object Float32Array]",g="[object Float64Array]",b="[object Int8Array]",v="[object Int16Array]",x="[object Int32Array]",w="[object Uint8Array]",C="[object Uint8ClampedArray]",j="[object Uint16Array]",_="[object Uint32Array]";function k(E,O,T){var P=E.constructor;switch(O){case p:return e(E);case o:case s:return new P(+E);case y:return r(E,T);case m:case g:case b:case v:case x:case w:case C:case j:case _:return i(E,T);case a:return new P;case c:case u:return new P(E);case l:return t(E);case d:return new P;case h:return n(E)}}return _a=k,_a}var Ea,qh;function ev(){if(qh)return Ea;qh=1;var e=Lt(),r=Object.create,t=(function(){function n(){}return function(i){if(!e(i))return{};if(r)return r(i);n.prototype=i;var o=new n;return n.prototype=void 0,o}})();return Ea=t,Ea}var Ra,Lh;function tv(){if(Lh)return Ra;Lh=1;var e=ev(),r=vo(),t=bo();function n(i){return typeof i.constructor=="function"&&!t(i)?e(r(i)):{}}return Ra=n,Ra}var ka,Fh;function J1(){if(Fh)return ka;Fh=1;var e=Qr(),r=Zt(),t="[object Map]";function n(i){return r(i)&&e(i)==t}return ka=n,ka}var Aa,zh;function Z1(){if(zh)return Aa;zh=1;var e=J1(),r=mo(),t=Ld(),n=t&&t.isMap,i=n?r(n):e;return Aa=i,Aa}var Pa,Bh;function X1(){if(Bh)return Pa;Bh=1;var e=Qr(),r=Zt(),t="[object Set]";function n(i){return r(i)&&e(i)==t}return Pa=n,Pa}var Ia,Dh;function Y1(){if(Dh)return Ia;Dh=1;var e=X1(),r=mo(),t=Ld(),n=t&&t.isSet,i=n?r(n):e;return Ia=i,Ia}var Ma,Vh;function rv(){if(Vh)return Ma;Vh=1;var e=ho(),r=$d(),t=go(),n=O1(),i=q1(),o=Gb(),s=Wb(),a=L1(),c=F1(),l=Zb(),d=z1(),u=Qr(),h=G1(),p=K1(),y=tv(),m=gt(),g=Yr(),b=Z1(),v=Lt(),x=Y1(),w=gr(),C=Ar(),j=1,_=2,k=4,E="[object Arguments]",O="[object Array]",T="[object Boolean]",P="[object Date]",I="[object Error]",R="[object Function]",$="[object GeneratorFunction]",N="[object Map]",M="[object Number]",J="[object Object]",ae="[object RegExp]",se="[object Set]",ee="[object String]",pe="[object Symbol]",me="[object WeakMap]",q="[object ArrayBuffer]",F="[object DataView]",H="[object Float32Array]",B="[object Float64Array]",de="[object Int8Array]",Y="[object Int16Array]",oe="[object Int32Array]",ce="[object Uint8Array]",xe="[object Uint8ClampedArray]",je="[object Uint16Array]",ye="[object Uint32Array]",ge={};ge[E]=ge[O]=ge[q]=ge[F]=ge[T]=ge[P]=ge[H]=ge[B]=ge[de]=ge[Y]=ge[oe]=ge[N]=ge[M]=ge[J]=ge[ae]=ge[se]=ge[ee]=ge[pe]=ge[ce]=ge[xe]=ge[je]=ge[ye]=!0,ge[I]=ge[R]=ge[me]=!1;function z(W,ie,K,ue,ve,Oe){var $e,De=ie&j,tt=ie&_,Ue=ie&k;if(K&&($e=ve?K(W,ue,ve,Oe):K(W)),$e!==void 0)return $e;if(!v(W))return W;var yt=m(W);if(yt){if($e=h(W),!De)return s(W,$e)}else{var Je=u(W),nt=Je==R||Je==$;if(g(W))return o(W,De);if(Je==J||Je==E||nt&&!ve){if($e=tt||nt?{}:y(W),!De)return tt?c(W,i($e,W)):a(W,n($e,W))}else{if(!ge[Je])return ve?W:{};$e=p(W,Je,De)}}Oe||(Oe=new e);var ht=Oe.get(W);if(ht)return ht;Oe.set(W,$e),x(W)?W.forEach(function(at){$e.add(z(at,ie,K,at,W,Oe))}):b(W)&&W.forEach(function(at,st){$e.set(st,z(at,ie,K,st,W,Oe))});var Ie=Ue?tt?d:l:tt?C:w,ze=yt?void 0:Ie(W);return r(ze||W,function(at,st){ze&&(st=at,at=W[st]),t($e,st,z(at,ie,K,st,W,Oe))}),$e}return Ma=z,Ma}var Ta,Gh;function Q1(){if(Gh)return Ta;Gh=1;var e=rv(),r=4;function t(n){return e(n,r)}return Ta=t,Ta}var Oa,Wh;function Vd(){if(Wh)return Oa;Wh=1;function e(r){return function(){return r}}return Oa=e,Oa}var Na,Uh;function eC(){if(Uh)return Na;Uh=1;function e(r){return function(t,n,i){for(var o=-1,s=Object(t),a=i(t),c=a.length;c--;){var l=a[r?c:++o];if(n(s[l],l,s)===!1)break}return t}}return Na=e,Na}var $a,Hh;function Gd(){if(Hh)return $a;Hh=1;var e=eC(),r=e();return $a=r,$a}var qa,Kh;function Wd(){if(Kh)return qa;Kh=1;var e=Gd(),r=gr();function t(n,i){return n&&e(n,i,r)}return qa=t,qa}var La,Jh;function tC(){if(Jh)return La;Jh=1;var e=er();function r(t,n){return function(i,o){if(i==null)return i;if(!e(i))return t(i,o);for(var s=i.length,a=n?s:-1,c=Object(i);(n?a--:++a<s)&&o(c[a],a,c)!==!1;);return i}}return La=r,La}var Fa,Zh;function xo(){if(Zh)return Fa;Zh=1;var e=Wd(),r=tC(),t=r(e);return Fa=t,Fa}var za,Xh;function Pr(){if(Xh)return za;Xh=1;function e(r){return r}return za=e,za}var Ba,Yh;function nv(){if(Yh)return Ba;Yh=1;var e=Pr();function r(t){return typeof t=="function"?t:e}return Ba=r,Ba}var Da,Qh;function ov(){if(Qh)return Da;Qh=1;var e=$d(),r=xo(),t=nv(),n=gt();function i(o,s){var a=n(o)?e:r;return a(o,t(s))}return Da=i,Da}var Va,ep;function iv(){return ep||(ep=1,Va=ov()),Va}var Ga,tp;function rC(){if(tp)return Ga;tp=1;var e=xo();function r(t,n){var i=[];return e(t,function(o,s,a){n(o,s,a)&&i.push(o)}),i}return Ga=r,Ga}var Wa,rp;function nC(){if(rp)return Wa;rp=1;var e="__lodash_hash_undefined__";function r(t){return this.__data__.set(t,e),this}return Wa=r,Wa}var Ua,np;function oC(){if(np)return Ua;np=1;function e(r){return this.__data__.has(r)}return Ua=e,Ua}var Ha,op;function av(){if(op)return Ha;op=1;var e=Nd(),r=nC(),t=oC();function n(i){var o=-1,s=i==null?0:i.length;for(this.__data__=new e;++o<s;)this.add(i[o])}return n.prototype.add=n.prototype.push=r,n.prototype.has=t,Ha=n,Ha}var Ka,ip;function iC(){if(ip)return Ka;ip=1;function e(r,t){for(var n=-1,i=r==null?0:r.length;++n<i;)if(t(r[n],n,r))return!0;return!1}return Ka=e,Ka}var Ja,ap;function sv(){if(ap)return Ja;ap=1;function e(r,t){return r.has(t)}return Ja=e,Ja}var Za,sp;function cv(){if(sp)return Za;sp=1;var e=av(),r=iC(),t=sv(),n=1,i=2;function o(s,a,c,l,d,u){var h=c&n,p=s.length,y=a.length;if(p!=y&&!(h&&y>p))return!1;var m=u.get(s),g=u.get(a);if(m&&g)return m==a&&g==s;var b=-1,v=!0,x=c&i?new e:void 0;for(u.set(s,a),u.set(a,s);++b<p;){var w=s[b],C=a[b];if(l)var j=h?l(C,w,b,a,s,u):l(w,C,b,s,a,u);if(j!==void 0){if(j)continue;v=!1;break}if(x){if(!r(a,function(_,k){if(!t(x,k)&&(w===_||d(w,_,c,l,u)))return x.push(k)})){v=!1;break}}else if(!(w===C||d(w,C,c,l,u))){v=!1;break}}return u.delete(s),u.delete(a),v}return Za=o,Za}var Xa,cp;function aC(){if(cp)return Xa;cp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(i,o){n[++t]=[o,i]}),n}return Xa=e,Xa}var Ya,lp;function Ud(){if(lp)return Ya;lp=1;function e(r){var t=-1,n=Array(r.size);return r.forEach(function(i){n[++t]=i}),n}return Ya=e,Ya}var Qa,dp;function sC(){if(dp)return Qa;dp=1;var e=Xr(),r=Yb(),t=Zr(),n=cv(),i=aC(),o=Ud(),s=1,a=2,c="[object Boolean]",l="[object Date]",d="[object Error]",u="[object Map]",h="[object Number]",p="[object RegExp]",y="[object Set]",m="[object String]",g="[object Symbol]",b="[object ArrayBuffer]",v="[object DataView]",x=e?e.prototype:void 0,w=x?x.valueOf:void 0;function C(j,_,k,E,O,T,P){switch(k){case v:if(j.byteLength!=_.byteLength||j.byteOffset!=_.byteOffset)return!1;j=j.buffer,_=_.buffer;case b:return!(j.byteLength!=_.byteLength||!T(new r(j),new r(_)));case c:case l:case h:return t(+j,+_);case d:return j.name==_.name&&j.message==_.message;case p:case m:return j==_+"";case u:var I=i;case y:var R=E&s;if(I||(I=o),j.size!=_.size&&!R)return!1;var $=P.get(j);if($)return $==_;E|=a,P.set(j,_);var N=n(I(j),I(_),E,O,T,P);return P.delete(j),N;case g:if(w)return w.call(j)==w.call(_)}return!1}return Qa=C,Qa}var es,up;function cC(){if(up)return es;up=1;var e=Zb(),r=1,t=Object.prototype,n=t.hasOwnProperty;function i(o,s,a,c,l,d){var u=a&r,h=e(o),p=h.length,y=e(s),m=y.length;if(p!=m&&!u)return!1;for(var g=p;g--;){var b=h[g];if(!(u?b in s:n.call(s,b)))return!1}var v=d.get(o),x=d.get(s);if(v&&x)return v==s&&x==o;var w=!0;d.set(o,s),d.set(s,o);for(var C=u;++g<p;){b=h[g];var j=o[b],_=s[b];if(c)var k=u?c(_,j,b,s,o,d):c(j,_,b,o,s,d);if(!(k===void 0?j===_||l(j,_,a,c,d):k)){w=!1;break}C||(C=b=="constructor")}if(w&&!C){var E=o.constructor,O=s.constructor;E!=O&&"constructor"in o&&"constructor"in s&&!(typeof E=="function"&&E instanceof E&&typeof O=="function"&&O instanceof O)&&(w=!1)}return d.delete(o),d.delete(s),w}return es=i,es}var ts,fp;function lC(){if(fp)return ts;fp=1;var e=ho(),r=cv(),t=sC(),n=cC(),i=Qr(),o=gt(),s=Yr(),a=On(),c=1,l="[object Arguments]",d="[object Array]",u="[object Object]",h=Object.prototype,p=h.hasOwnProperty;function y(m,g,b,v,x,w){var C=o(m),j=o(g),_=C?d:i(m),k=j?d:i(g);_=_==l?u:_,k=k==l?u:k;var E=_==u,O=k==u,T=_==k;if(T&&s(m)){if(!s(g))return!1;C=!0,E=!1}if(T&&!E)return w||(w=new e),C||a(m)?r(m,g,b,v,x,w):t(m,g,_,b,v,x,w);if(!(b&c)){var P=E&&p.call(m,"__wrapped__"),I=O&&p.call(g,"__wrapped__");if(P||I){var R=P?m.value():m,$=I?g.value():g;return w||(w=new e),x(R,$,b,v,w)}}return T?(w||(w=new e),n(m,g,b,v,x,w)):!1}return ts=y,ts}var rs,hp;function lv(){if(hp)return rs;hp=1;var e=lC(),r=Zt();function t(n,i,o,s,a){return n===i?!0:n==null||i==null||!r(n)&&!r(i)?n!==n&&i!==i:e(n,i,o,s,t,a)}return rs=t,rs}var ns,pp;function dC(){if(pp)return ns;pp=1;var e=ho(),r=lv(),t=1,n=2;function i(o,s,a,c){var l=a.length,d=l,u=!c;if(o==null)return!d;for(o=Object(o);l--;){var h=a[l];if(u&&h[2]?h[1]!==o[h[0]]:!(h[0]in o))return!1}for(;++l<d;){h=a[l];var p=h[0],y=o[p],m=h[1];if(u&&h[2]){if(y===void 0&&!(p in o))return!1}else{var g=new e;if(c)var b=c(y,m,p,o,s,g);if(!(b===void 0?r(m,y,t|n,c,g):b))return!1}}return!0}return ns=i,ns}var os,gp;function dv(){if(gp)return os;gp=1;var e=Lt();function r(t){return t===t&&!e(t)}return os=r,os}var is,yp;function uC(){if(yp)return is;yp=1;var e=dv(),r=gr();function t(n){for(var i=r(n),o=i.length;o--;){var s=i[o],a=n[s];i[o]=[s,a,e(a)]}return i}return is=t,is}var as,mp;function uv(){if(mp)return as;mp=1;function e(r,t){return function(n){return n==null?!1:n[r]===t&&(t!==void 0||r in Object(n))}}return as=e,as}var ss,bp;function fC(){if(bp)return ss;bp=1;var e=dC(),r=uC(),t=uv();function n(i){var o=r(i);return o.length==1&&o[0][2]?t(o[0][0],o[0][1]):function(s){return s===i||e(s,i,o)}}return ss=n,ss}var cs,vp;function en(){if(vp)return cs;vp=1;var e=Rr(),r=Zt(),t="[object Symbol]";function n(i){return typeof i=="symbol"||r(i)&&e(i)==t}return cs=n,cs}var ls,xp;function Hd(){if(xp)return ls;xp=1;var e=gt(),r=en(),t=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function i(o,s){if(e(o))return!1;var a=typeof o;return a=="number"||a=="symbol"||a=="boolean"||o==null||r(o)?!0:n.test(o)||!t.test(o)||s!=null&&o in Object(s)}return ls=i,ls}var ds,wp;function hC(){if(wp)return ds;wp=1;var e=Nd(),r="Expected a function";function t(n,i){if(typeof n!="function"||i!=null&&typeof i!="function")throw new TypeError(r);var o=function(){var s=arguments,a=i?i.apply(this,s):s[0],c=o.cache;if(c.has(a))return c.get(a);var l=n.apply(this,s);return o.cache=c.set(a,l)||c,l};return o.cache=new(t.Cache||e),o}return t.Cache=e,ds=t,ds}var us,Cp;function pC(){if(Cp)return us;Cp=1;var e=hC(),r=500;function t(n){var i=e(n,function(s){return o.size===r&&o.clear(),s}),o=i.cache;return i}return us=t,us}var fs,Sp;function gC(){if(Sp)return fs;Sp=1;var e=pC(),r=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,t=/\\(\\)?/g,n=e(function(i){var o=[];return i.charCodeAt(0)===46&&o.push(""),i.replace(r,function(s,a,c,l){o.push(c?l.replace(t,"$1"):a||s)}),o});return fs=n,fs}var hs,jp;function wo(){if(jp)return hs;jp=1;function e(r,t){for(var n=-1,i=r==null?0:r.length,o=Array(i);++n<i;)o[n]=t(r[n],n,r);return o}return hs=e,hs}var ps,_p;function yC(){if(_p)return ps;_p=1;var e=Xr(),r=wo(),t=gt(),n=en(),i=e?e.prototype:void 0,o=i?i.toString:void 0;function s(a){if(typeof a=="string")return a;if(t(a))return r(a,s)+"";if(n(a))return o?o.call(a):"";var c=a+"";return c=="0"&&1/a==-1/0?"-0":c}return ps=s,ps}var gs,Ep;function fv(){if(Ep)return gs;Ep=1;var e=yC();function r(t){return t==null?"":e(t)}return gs=r,gs}var ys,Rp;function Co(){if(Rp)return ys;Rp=1;var e=gt(),r=Hd(),t=gC(),n=fv();function i(o,s){return e(o)?o:r(o,s)?[o]:t(n(o))}return ys=i,ys}var ms,kp;function Nn(){if(kp)return ms;kp=1;var e=en();function r(t){if(typeof t=="string"||e(t))return t;var n=t+"";return n=="0"&&1/t==-1/0?"-0":n}return ms=r,ms}var bs,Ap;function So(){if(Ap)return bs;Ap=1;var e=Co(),r=Nn();function t(n,i){i=e(i,n);for(var o=0,s=i.length;n!=null&&o<s;)n=n[r(i[o++])];return o&&o==s?n:void 0}return bs=t,bs}var vs,Pp;function mC(){if(Pp)return vs;Pp=1;var e=So();function r(t,n,i){var o=t==null?void 0:e(t,n);return o===void 0?i:o}return vs=r,vs}var xs,Ip;function bC(){if(Ip)return xs;Ip=1;function e(r,t){return r!=null&&t in Object(r)}return xs=e,xs}var ws,Mp;function hv(){if(Mp)return ws;Mp=1;var e=Co(),r=Tn(),t=gt(),n=yo(),i=qd(),o=Nn();function s(a,c,l){c=e(c,a);for(var d=-1,u=c.length,h=!1;++d<u;){var p=o(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&&i(u)&&n(p,u)&&(t(a)||r(a)))}return ws=s,ws}var Cs,Tp;function pv(){if(Tp)return Cs;Tp=1;var e=bC(),r=hv();function t(n,i){return n!=null&&r(n,i,e)}return Cs=t,Cs}var Ss,Op;function vC(){if(Op)return Ss;Op=1;var e=lv(),r=mC(),t=pv(),n=Hd(),i=dv(),o=uv(),s=Nn(),a=1,c=2;function l(d,u){return n(d)&&i(u)?o(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 Ss=l,Ss}var js,Np;function gv(){if(Np)return js;Np=1;function e(r){return function(t){return t==null?void 0:t[r]}}return js=e,js}var _s,$p;function xC(){if($p)return _s;$p=1;var e=So();function r(t){return function(n){return e(n,t)}}return _s=r,_s}var Es,qp;function wC(){if(qp)return Es;qp=1;var e=gv(),r=xC(),t=Hd(),n=Nn();function i(o){return t(o)?e(n(o)):r(o)}return Es=i,Es}var Rs,Lp;function tr(){if(Lp)return Rs;Lp=1;var e=fC(),r=vC(),t=Pr(),n=gt(),i=wC();function o(s){return typeof s=="function"?s:s==null?t:typeof s=="object"?n(s)?r(s[0],s[1]):e(s):i(s)}return Rs=o,Rs}var ks,Fp;function yv(){if(Fp)return ks;Fp=1;var e=Ub(),r=rC(),t=tr(),n=gt();function i(o,s){var a=n(o)?e:r;return a(o,t(s,3))}return ks=i,ks}var As,zp;function CC(){if(zp)return As;zp=1;var e=Object.prototype,r=e.hasOwnProperty;function t(n,i){return n!=null&&r.call(n,i)}return As=t,As}var Ps,Bp;function mv(){if(Bp)return Ps;Bp=1;var e=CC(),r=hv();function t(n,i){return n!=null&&r(n,i,e)}return Ps=t,Ps}var Is,Dp;function SC(){if(Dp)return Is;Dp=1;var e=Fd(),r=Qr(),t=Tn(),n=gt(),i=er(),o=Yr(),s=bo(),a=On(),c="[object Map]",l="[object Set]",d=Object.prototype,u=d.hasOwnProperty;function h(p){if(p==null)return!0;if(i(p)&&(n(p)||typeof p=="string"||typeof p.splice=="function"||o(p)||a(p)||t(p)))return!p.length;var y=r(p);if(y==c||y==l)return!p.size;if(s(p))return!e(p).length;for(var m in p)if(u.call(p,m))return!1;return!0}return Is=h,Is}var Ms,Vp;function bv(){if(Vp)return Ms;Vp=1;function e(r){return r===void 0}return Ms=e,Ms}var Ts,Gp;function vv(){if(Gp)return Ts;Gp=1;var e=xo(),r=er();function t(n,i){var o=-1,s=r(n)?Array(n.length):[];return e(n,function(a,c,l){s[++o]=i(a,c,l)}),s}return Ts=t,Ts}var Os,Wp;function xv(){if(Wp)return Os;Wp=1;var e=wo(),r=tr(),t=vv(),n=gt();function i(o,s){var a=n(o)?e:t;return a(o,r(s,3))}return Os=i,Os}var Ns,Up;function jC(){if(Up)return Ns;Up=1;function e(r,t,n,i){var o=-1,s=r==null?0:r.length;for(i&&s&&(n=r[++o]);++o<s;)n=t(n,r[o],o,r);return n}return Ns=e,Ns}var $s,Hp;function _C(){if(Hp)return $s;Hp=1;function e(r,t,n,i,o){return o(r,function(s,a,c){n=i?(i=!1,s):t(n,s,a,c)}),n}return $s=e,$s}var qs,Kp;function wv(){if(Kp)return qs;Kp=1;var e=jC(),r=xo(),t=tr(),n=_C(),i=gt();function o(s,a,c){var l=i(s)?e:n,d=arguments.length<3;return l(s,t(a,4),c,d,r)}return qs=o,qs}var Ls,Jp;function EC(){if(Jp)return Ls;Jp=1;var e=Rr(),r=gt(),t=Zt(),n="[object String]";function i(o){return typeof o=="string"||!r(o)&&t(o)&&e(o)==n}return Ls=i,Ls}var Fs,Zp;function RC(){if(Zp)return Fs;Zp=1;var e=gv(),r=e("length");return Fs=r,Fs}var zs,Xp;function kC(){if(Xp)return zs;Xp=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",i=r+t+n,o="\\ufe0e\\ufe0f",s="\\u200d",a=RegExp("["+s+e+i+o+"]");function c(l){return a.test(l)}return zs=c,zs}var Bs,Yp;function AC(){if(Yp)return Bs;Yp=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",t="\\ufe20-\\ufe2f",n="\\u20d0-\\u20ff",i=r+t+n,o="\\ufe0e\\ufe0f",s="["+e+"]",a="["+i+"]",c="\\ud83c[\\udffb-\\udfff]",l="(?:"+a+"|"+c+")",d="[^"+e+"]",u="(?:\\ud83c[\\udde6-\\uddff]){2}",h="[\\ud800-\\udbff][\\udc00-\\udfff]",p="\\u200d",y=l+"?",m="["+o+"]?",g="(?:"+p+"(?:"+[d,u,h].join("|")+")"+m+y+")*",b=m+y+g,v="(?:"+[d+a+"?",a,u,h,s].join("|")+")",x=RegExp(c+"(?="+c+")|"+v+b,"g");function w(C){for(var j=x.lastIndex=0;x.test(C);)++j;return j}return Bs=w,Bs}var Ds,Qp;function PC(){if(Qp)return Ds;Qp=1;var e=RC(),r=kC(),t=AC();function n(i){return r(i)?t(i):e(i)}return Ds=n,Ds}var Vs,eg;function IC(){if(eg)return Vs;eg=1;var e=Fd(),r=Qr(),t=er(),n=EC(),i=PC(),o="[object Map]",s="[object Set]";function a(c){if(c==null)return 0;if(t(c))return n(c)?i(c):c.length;var l=r(c);return l==o||l==s?c.size:e(c).length}return Vs=a,Vs}var Gs,tg;function MC(){if(tg)return Gs;tg=1;var e=$d(),r=ev(),t=Wd(),n=tr(),i=vo(),o=gt(),s=Yr(),a=In(),c=Lt(),l=On();function d(u,h,p){var y=o(u),m=y||s(u)||l(u);if(h=n(h,4),p==null){var g=u&&u.constructor;m?p=y?new g:[]:c(u)?p=a(g)?r(i(u)):{}:p={}}return(m?e:t)(u,function(b,v,x){return h(p,b,v,x)}),p}return Gs=d,Gs}var Ws,rg;function TC(){if(rg)return Ws;rg=1;var e=Xr(),r=Tn(),t=gt(),n=e?e.isConcatSpreadable:void 0;function i(o){return t(o)||r(o)||!!(n&&o&&o[n])}return Ws=i,Ws}var Us,ng;function Kd(){if(ng)return Us;ng=1;var e=Bd(),r=TC();function t(n,i,o,s,a){var c=-1,l=n.length;for(o||(o=r),a||(a=[]);++c<l;){var d=n[c];i>0&&o(d)?i>1?t(d,i-1,o,s,a):e(a,d):s||(a[a.length]=d)}return a}return Us=t,Us}var Hs,og;function OC(){if(og)return Hs;og=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 Hs=e,Hs}var Ks,ig;function Cv(){if(ig)return Ks;ig=1;var e=OC(),r=Math.max;function t(n,i,o){return i=r(i===void 0?n.length-1:i,0),function(){for(var s=arguments,a=-1,c=r(s.length-i,0),l=Array(c);++a<c;)l[a]=s[i+a];a=-1;for(var d=Array(i+1);++a<i;)d[a]=s[a];return d[i]=o(l),e(n,this,d)}}return Ks=t,Ks}var Js,ag;function NC(){if(ag)return Js;ag=1;var e=Vd(),r=Bb(),t=Pr(),n=r?function(i,o){return r(i,"toString",{configurable:!0,enumerable:!1,value:e(o),writable:!0})}:t;return Js=n,Js}var Zs,sg;function $C(){if(sg)return Zs;sg=1;var e=800,r=16,t=Date.now;function n(i){var o=0,s=0;return function(){var a=t(),c=r-(a-s);if(s=a,c>0){if(++o>=e)return arguments[0]}else o=0;return i.apply(void 0,arguments)}}return Zs=n,Zs}var Xs,cg;function Sv(){if(cg)return Xs;cg=1;var e=NC(),r=$C(),t=r(e);return Xs=t,Xs}var Ys,lg;function jo(){if(lg)return Ys;lg=1;var e=Pr(),r=Cv(),t=Sv();function n(i,o){return t(r(i,o,e),i+"")}return Ys=n,Ys}var Qs,dg;function jv(){if(dg)return Qs;dg=1;function e(r,t,n,i){for(var o=r.length,s=n+(i?1:-1);i?s--:++s<o;)if(t(r[s],s,r))return s;return-1}return Qs=e,Qs}var ec,ug;function qC(){if(ug)return ec;ug=1;function e(r){return r!==r}return ec=e,ec}var tc,fg;function LC(){if(fg)return tc;fg=1;function e(r,t,n){for(var i=n-1,o=r.length;++i<o;)if(r[i]===t)return i;return-1}return tc=e,tc}var rc,hg;function FC(){if(hg)return rc;hg=1;var e=jv(),r=qC(),t=LC();function n(i,o,s){return o===o?t(i,o,s):e(i,r,s)}return rc=n,rc}var nc,pg;function zC(){if(pg)return nc;pg=1;var e=FC();function r(t,n){var i=t==null?0:t.length;return!!i&&e(t,n,0)>-1}return nc=r,nc}var oc,gg;function BC(){if(gg)return oc;gg=1;function e(r,t,n){for(var i=-1,o=r==null?0:r.length;++i<o;)if(n(t,r[i]))return!0;return!1}return oc=e,oc}var ic,yg;function DC(){if(yg)return ic;yg=1;function e(){}return ic=e,ic}var ac,mg;function VC(){if(mg)return ac;mg=1;var e=Xb(),r=DC(),t=Ud(),n=1/0,i=e&&1/t(new e([,-0]))[1]==n?function(o){return new e(o)}:r;return ac=i,ac}var sc,bg;function GC(){if(bg)return sc;bg=1;var e=av(),r=zC(),t=BC(),n=sv(),i=VC(),o=Ud(),s=200;function a(c,l,d){var u=-1,h=r,p=c.length,y=!0,m=[],g=m;if(d)y=!1,h=t;else if(p>=s){var b=l?null:i(c);if(b)return o(b);y=!1,h=n,g=new e}else g=l?[]:m;e:for(;++u<p;){var v=c[u],x=l?l(v):v;if(v=d||v!==0?v:0,y&&x===x){for(var w=g.length;w--;)if(g[w]===x)continue e;l&&g.push(x),m.push(v)}else h(g,x,d)||(g!==m&&g.push(x),m.push(v))}return m}return sc=a,sc}var cc,vg;function _v(){if(vg)return cc;vg=1;var e=er(),r=Zt();function t(n){return r(n)&&e(n)}return cc=t,cc}var lc,xg;function WC(){if(xg)return lc;xg=1;var e=Kd(),r=jo(),t=GC(),n=_v(),i=r(function(o){return t(e(o,1,n,!0))});return lc=i,lc}var dc,wg;function UC(){if(wg)return dc;wg=1;var e=wo();function r(t,n){return e(n,function(i){return t[i]})}return dc=r,dc}var uc,Cg;function Ev(){if(Cg)return uc;Cg=1;var e=UC(),r=gr();function t(n){return n==null?[]:e(n,r(n))}return uc=t,uc}var fc,Sg;function Ft(){if(Sg)return fc;Sg=1;var e;if(typeof Td=="function")try{e={clone:Q1(),constant:Vd(),each:iv(),filter:yv(),has:mv(),isArray:gt(),isEmpty:SC(),isFunction:In(),isUndefined:bv(),keys:gr(),map:xv(),reduce:wv(),size:IC(),transform:MC(),union:WC(),values:Ev()}}catch{}return e||(e=window._),fc=e,fc}var hc,jg;function Jd(){if(jg)return hc;jg=1;var e=Ft();hc=i;var r="\0",t="\0",n="";function i(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={}}i.prototype._nodeCount=0,i.prototype._edgeCount=0,i.prototype.isDirected=function(){return this._isDirected},i.prototype.isMultigraph=function(){return this._isMultigraph},i.prototype.isCompound=function(){return this._isCompound},i.prototype.setGraph=function(d){return this._label=d,this},i.prototype.graph=function(){return this._label},i.prototype.setDefaultNodeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultNodeLabelFn=d,this},i.prototype.nodeCount=function(){return this._nodeCount},i.prototype.nodes=function(){return e.keys(this._nodes)},i.prototype.sources=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._in[u])})},i.prototype.sinks=function(){var d=this;return e.filter(this.nodes(),function(u){return e.isEmpty(d._out[u])})},i.prototype.setNodes=function(d,u){var h=arguments,p=this;return e.each(d,function(y){h.length>1?p.setNode(y,u):p.setNode(y)}),this},i.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)},i.prototype.node=function(d){return this._nodes[d]},i.prototype.hasNode=function(d){return e.has(this._nodes,d)},i.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},i.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},i.prototype._removeFromParentsChildList=function(d){delete this._children[this._parent[d]][d]},i.prototype.parent=function(d){if(this._isCompound){var u=this._parent[d];if(u!==t)return u}},i.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[]}},i.prototype.predecessors=function(d){var u=this._preds[d];if(u)return e.keys(u)},i.prototype.successors=function(d){var u=this._sucs[d];if(u)return e.keys(u)},i.prototype.neighbors=function(d){var u=this.predecessors(d);if(u)return e.union(u,this.successors(d))},i.prototype.isLeaf=function(d){var u;return this.isDirected()?u=this.successors(d):u=this.neighbors(d),u.length===0},i.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(m,g){d(g)&&u.setNode(g,m)}),e.each(this._edgeObjs,function(m){u.hasNode(m.v)&&u.hasNode(m.w)&&u.setEdge(m,h.edge(m))});var p={};function y(m){var g=h.parent(m);return g===void 0||u.hasNode(g)?(p[m]=g,g):g in p?p[g]:y(g)}return this._isCompound&&e.each(u.nodes(),function(m){u.setParent(m,y(m))}),u},i.prototype.setDefaultEdgeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultEdgeLabelFn=d,this},i.prototype.edgeCount=function(){return this._edgeCount},i.prototype.edges=function(){return e.values(this._edgeObjs)},i.prototype.setPath=function(d,u){var h=this,p=arguments;return e.reduce(d,function(y,m){return p.length>1?h.setEdge(y,m,u):h.setEdge(y,m),m}),this},i.prototype.setEdge=function(){var d,u,h,p,y=!1,m=arguments[0];typeof m=="object"&&m!==null&&"v"in m?(d=m.v,u=m.w,h=m.name,arguments.length===2&&(p=arguments[1],y=!0)):(d=m,u=arguments[1],h=arguments[3],arguments.length>2&&(p=arguments[2],y=!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 y&&(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]=y?p:this._defaultEdgeLabelFn(d,u,h);var b=c(this._isDirected,d,u,h);return d=b.v,u=b.w,Object.freeze(b),this._edgeObjs[g]=b,o(this._preds[u],d),o(this._sucs[d],u),this._in[u][g]=b,this._out[d][g]=b,this._edgeCount++,this},i.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]},i.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)},i.prototype.removeEdge=function(d,u,h){var p=arguments.length===1?l(this._isDirected,arguments[0]):a(this._isDirected,d,u,h),y=this._edgeObjs[p];return y&&(d=y.v,u=y.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},i.prototype.inEdges=function(d,u){var h=this._in[d];if(h){var p=e.values(h);return u?e.filter(p,function(y){return y.v===u}):p}},i.prototype.outEdges=function(d,u){var h=this._out[d];if(h){var p=e.values(h);return u?e.filter(p,function(y){return y.w===u}):p}},i.prototype.nodeEdges=function(d,u){var h=this.inEdges(d,u);if(h)return h.concat(this.outEdges(d,u))};function o(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 y=""+u,m=""+h;if(!d&&y>m){var g=y;y=m,m=g}return y+n+m+n+(e.isUndefined(p)?r:p)}function c(d,u,h,p){var y=""+u,m=""+h;if(!d&&y>m){var g=y;y=m,m=g}var b={v:y,w:m};return p&&(b.name=p),b}function l(d,u){return a(d,u.v,u.w,u.name)}return hc}var pc,_g;function HC(){return _g||(_g=1,pc="2.1.8"),pc}var gc,Eg;function KC(){return Eg||(Eg=1,gc={Graph:Jd(),version:HC()}),gc}var yc,Rg;function JC(){if(Rg)return yc;Rg=1;var e=Ft(),r=Jd();yc={write:t,read:o};function t(s){var a={options:{directed:s.isDirected(),multigraph:s.isMultigraph(),compound:s.isCompound()},nodes:n(s),edges:i(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 i(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 o(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 yc}var mc,kg;function ZC(){if(kg)return mc;kg=1;var e=Ft();mc=r;function r(t){var n={},i=[],o;function s(a){e.has(n,a)||(n[a]=!0,o.push(a),e.each(t.successors(a),s),e.each(t.predecessors(a),s))}return e.each(t.nodes(),function(a){o=[],s(a),o.length&&i.push(o)}),i}return mc}var bc,Ag;function Rv(){if(Ag)return bc;Ag=1;var e=Ft();bc=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 i=this._keyIndices;if(t=String(t),!e.has(i,t)){var o=this._arr,s=o.length;return i[t]=s,o.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 i=this._keyIndices[t];if(n>this._arr[i].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[i].priority+" New: "+n);this._arr[i].priority=n,this._decrease(i)},r.prototype._heapify=function(t){var n=this._arr,i=2*t,o=i+1,s=t;i<n.length&&(s=n[i].priority<n[s].priority?i:s,o<n.length&&(s=n[o].priority<n[s].priority?o:s),s!==t&&(this._swap(t,s),this._heapify(s)))},r.prototype._decrease=function(t){for(var n=this._arr,i=n[t].priority,o;t!==0&&(o=t>>1,!(n[o].priority<i));)this._swap(t,o),t=o},r.prototype._swap=function(t,n){var i=this._arr,o=this._keyIndices,s=i[t],a=i[n];i[t]=a,i[n]=s,o[a.key]=t,o[s.key]=n},bc}var vc,Pg;function kv(){if(Pg)return vc;Pg=1;var e=Ft(),r=Rv();vc=n;var t=e.constant(1);function n(o,s,a,c){return i(o,String(s),a||t,c||function(l){return o.outEdges(l)})}function i(o,s,a,c){var l={},d=new r,u,h,p=function(y){var m=y.v!==u?y.v:y.w,g=l[m],b=a(y),v=h.distance+b;if(b<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+y+" Weight: "+b);v<g.distance&&(g.distance=v,g.predecessor=u,d.decrease(m,v))};for(o.nodes().forEach(function(y){var m=y===s?0:Number.POSITIVE_INFINITY;l[y]={distance:m},d.add(y,m)});d.size()>0&&(u=d.removeMin(),h=l[u],h.distance!==Number.POSITIVE_INFINITY);)c(u).forEach(p);return l}return vc}var xc,Ig;function XC(){if(Ig)return xc;Ig=1;var e=kv(),r=Ft();xc=t;function t(n,i,o){return r.transform(n.nodes(),function(s,a){s[a]=e(n,a,i,o)},{})}return xc}var wc,Mg;function Av(){if(Mg)return wc;Mg=1;var e=Ft();wc=r;function r(t){var n=0,i=[],o={},s=[];function a(c){var l=o[c]={onStack:!0,lowlink:n,index:n++};if(i.push(c),t.successors(c).forEach(function(h){e.has(o,h)?o[h].onStack&&(l.lowlink=Math.min(l.lowlink,o[h].index)):(a(h),l.lowlink=Math.min(l.lowlink,o[h].lowlink))}),l.lowlink===l.index){var d=[],u;do u=i.pop(),o[u].onStack=!1,d.push(u);while(c!==u);s.push(d)}}return t.nodes().forEach(function(c){e.has(o,c)||a(c)}),s}return wc}var Cc,Tg;function YC(){if(Tg)return Cc;Tg=1;var e=Ft(),r=Av();Cc=t;function t(n){return e.filter(r(n),function(i){return i.length>1||i.length===1&&n.hasEdge(i[0],i[0])})}return Cc}var Sc,Og;function QC(){if(Og)return Sc;Og=1;var e=Ft();Sc=t;var r=e.constant(1);function t(i,o,s){return n(i,o||r,s||function(a){return i.outEdges(a)})}function n(i,o,s){var a={},c=i.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=o(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 y=h[l],m=d[p],g=h[p],b=y.distance+m.distance;b<g.distance&&(g.distance=b,g.predecessor=m.predecessor)})})}),a}return Sc}var jc,Ng;function Pv(){if(Ng)return jc;Ng=1;var e=Ft();jc=r,r.CycleException=t;function r(n){var i={},o={},s=[];function a(c){if(e.has(o,c))throw new t;e.has(i,c)||(o[c]=!0,i[c]=!0,e.each(n.predecessors(c),a),delete o[c],s.push(c))}if(e.each(n.sinks(),a),e.size(i)!==n.nodeCount())throw new t;return s}function t(){}return t.prototype=new Error,jc}var _c,$g;function eS(){if($g)return _c;$g=1;var e=Pv();_c=r;function r(t){try{e(t)}catch(n){if(n instanceof e.CycleException)return!1;throw n}return!0}return _c}var Ec,qg;function Iv(){if(qg)return Ec;qg=1;var e=Ft();Ec=r;function r(n,i,o){e.isArray(i)||(i=[i]);var s=(n.isDirected()?n.successors:n.neighbors).bind(n),a=[],c={};return e.each(i,function(l){if(!n.hasNode(l))throw new Error("Graph does not have node: "+l);t(n,l,o==="post",c,s,a)}),a}function t(n,i,o,s,a,c){e.has(s,i)||(s[i]=!0,o||c.push(i),e.each(a(i),function(l){t(n,l,o,s,a,c)}),o&&c.push(i))}return Ec}var Rc,Lg;function tS(){if(Lg)return Rc;Lg=1;var e=Iv();Rc=r;function r(t,n){return e(t,n,"post")}return Rc}var kc,Fg;function rS(){if(Fg)return kc;Fg=1;var e=Iv();kc=r;function r(t,n){return e(t,n,"pre")}return kc}var Ac,zg;function nS(){if(zg)return Ac;zg=1;var e=Ft(),r=Jd(),t=Rv();Ac=n;function n(i,o){var s=new r,a={},c=new t,l;function d(h){var p=h.v===l?h.w:h.v,y=c.priority(p);if(y!==void 0){var m=o(h);m<y&&(a[p]=l,c.decrease(p,m))}}if(i.nodeCount()===0)return s;e.each(i.nodes(),function(h){c.add(h,Number.POSITIVE_INFINITY),s.setNode(h)}),c.decrease(i.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: "+i);u=!0}i.nodeEdges(l).forEach(d)}return s}return Ac}var Pc,Bg;function oS(){return Bg||(Bg=1,Pc={components:ZC(),dijkstra:kv(),dijkstraAll:XC(),findCycles:YC(),floydWarshall:QC(),isAcyclic:eS(),postorder:tS(),preorder:rS(),prim:nS(),tarjan:Av(),topsort:Pv()}),Pc}var Ic,Dg;function iS(){if(Dg)return Ic;Dg=1;var e=KC();return Ic={Graph:e.Graph,json:JC(),alg:oS(),version:e.version},Ic}var Mc,Vg;function Vt(){if(Vg)return Mc;Vg=1;var e;if(typeof Td=="function")try{e=iS()}catch{}return e||(e=window.graphlib),Mc=e,Mc}var Tc,Gg;function aS(){if(Gg)return Tc;Gg=1;var e=rv(),r=1,t=4;function n(i){return e(i,r|t)}return Tc=n,Tc}var Oc,Wg;function _o(){if(Wg)return Oc;Wg=1;var e=Zr(),r=er(),t=yo(),n=Lt();function i(o,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],o):!1}return Oc=i,Oc}var Nc,Ug;function sS(){if(Ug)return Nc;Ug=1;var e=jo(),r=Zr(),t=_o(),n=Ar(),i=Object.prototype,o=i.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),y=-1,m=p.length;++y<m;){var g=p[y],b=a[g];(b===void 0||r(b,i[g])&&!o.call(a,g))&&(a[g]=h[g])}return a});return Nc=s,Nc}var $c,Hg;function cS(){if(Hg)return $c;Hg=1;var e=tr(),r=er(),t=gr();function n(i){return function(o,s,a){var c=Object(o);if(!r(o)){var l=e(s,3);o=t(o),s=function(u){return l(c[u],u,c)}}var d=i(o,s,a);return d>-1?c[l?o[d]:d]:void 0}}return $c=n,$c}var qc,Kg;function lS(){if(Kg)return qc;Kg=1;var e=/\s/;function r(t){for(var n=t.length;n--&&e.test(t.charAt(n)););return n}return qc=r,qc}var Lc,Jg;function dS(){if(Jg)return Lc;Jg=1;var e=lS(),r=/^\s+/;function t(n){return n&&n.slice(0,e(n)+1).replace(r,"")}return Lc=t,Lc}var Fc,Zg;function uS(){if(Zg)return Fc;Zg=1;var e=dS(),r=Lt(),t=en(),n=NaN,i=/^[-+]0x[0-9a-f]+$/i,o=/^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=o.test(l);return u||s.test(l)?a(l.slice(2),u?2:8):i.test(l)?n:+l}return Fc=c,Fc}var zc,Xg;function Mv(){if(Xg)return zc;Xg=1;var e=uS(),r=1/0,t=17976931348623157e292;function n(i){if(!i)return i===0?i:0;if(i=e(i),i===r||i===-r){var o=i<0?-1:1;return o*t}return i===i?i:0}return zc=n,zc}var Bc,Yg;function fS(){if(Yg)return Bc;Yg=1;var e=Mv();function r(t){var n=e(t),i=n%1;return n===n?i?n-i:n:0}return Bc=r,Bc}var Dc,Qg;function hS(){if(Qg)return Dc;Qg=1;var e=jv(),r=tr(),t=fS(),n=Math.max;function i(o,s,a){var c=o==null?0:o.length;if(!c)return-1;var l=a==null?0:t(a);return l<0&&(l=n(c+l,0)),e(o,r(s,3),l)}return Dc=i,Dc}var Vc,ey;function pS(){if(ey)return Vc;ey=1;var e=cS(),r=hS(),t=e(r);return Vc=t,Vc}var Gc,ty;function Tv(){if(ty)return Gc;ty=1;var e=Kd();function r(t){var n=t==null?0:t.length;return n?e(t,1):[]}return Gc=r,Gc}var Wc,ry;function gS(){if(ry)return Wc;ry=1;var e=Gd(),r=nv(),t=Ar();function n(i,o){return i==null?i:e(i,r(o),t)}return Wc=n,Wc}var Uc,ny;function yS(){if(ny)return Uc;ny=1;function e(r){var t=r==null?0:r.length;return t?r[t-1]:void 0}return Uc=e,Uc}var Hc,oy;function mS(){if(oy)return Hc;oy=1;var e=po(),r=Wd(),t=tr();function n(i,o){var s={};return o=t(o,3),r(i,function(a,c,l){e(s,c,o(a,c,l))}),s}return Hc=n,Hc}var Kc,iy;function Zd(){if(iy)return Kc;iy=1;var e=en();function r(t,n,i){for(var o=-1,s=t.length;++o<s;){var a=t[o],c=n(a);if(c!=null&&(l===void 0?c===c&&!e(c):i(c,l)))var l=c,d=a}return d}return Kc=r,Kc}var Jc,ay;function bS(){if(ay)return Jc;ay=1;function e(r,t){return r>t}return Jc=e,Jc}var Zc,sy;function vS(){if(sy)return Zc;sy=1;var e=Zd(),r=bS(),t=Pr();function n(i){return i&&i.length?e(i,t,r):void 0}return Zc=n,Zc}var Xc,cy;function Ov(){if(cy)return Xc;cy=1;var e=po(),r=Zr();function t(n,i,o){(o!==void 0&&!r(n[i],o)||o===void 0&&!(i in n))&&e(n,i,o)}return Xc=t,Xc}var Yc,ly;function xS(){if(ly)return Yc;ly=1;var e=Rr(),r=vo(),t=Zt(),n="[object Object]",i=Function.prototype,o=Object.prototype,s=i.toString,a=o.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 Yc=l,Yc}var Qc,dy;function Nv(){if(dy)return Qc;dy=1;function e(r,t){if(!(t==="constructor"&&typeof r[t]=="function")&&t!="__proto__")return r[t]}return Qc=e,Qc}var el,uy;function wS(){if(uy)return el;uy=1;var e=Mn(),r=Ar();function t(n){return e(n,r(n))}return el=t,el}var tl,fy;function CS(){if(fy)return tl;fy=1;var e=Ov(),r=Gb(),t=Qb(),n=Wb(),i=tv(),o=Tn(),s=gt(),a=_v(),c=Yr(),l=In(),d=Lt(),u=xS(),h=On(),p=Nv(),y=wS();function m(g,b,v,x,w,C,j){var _=p(g,v),k=p(b,v),E=j.get(k);if(E){e(g,v,E);return}var O=C?C(_,k,v+"",g,b,j):void 0,T=O===void 0;if(T){var P=s(k),I=!P&&c(k),R=!P&&!I&&h(k);O=k,P||I||R?s(_)?O=_:a(_)?O=n(_):I?(T=!1,O=r(k,!0)):R?(T=!1,O=t(k,!0)):O=[]:u(k)||o(k)?(O=_,o(_)?O=y(_):(!d(_)||l(_))&&(O=i(k))):T=!1}T&&(j.set(k,O),w(O,k,x,C,j),j.delete(k)),e(g,v,O)}return tl=m,tl}var rl,hy;function SS(){if(hy)return rl;hy=1;var e=ho(),r=Ov(),t=Gd(),n=CS(),i=Lt(),o=Ar(),s=Nv();function a(c,l,d,u,h){c!==l&&t(l,function(p,y){if(h||(h=new e),i(p))n(c,l,y,d,a,u,h);else{var m=u?u(s(c,y),p,y+"",c,l,h):void 0;m===void 0&&(m=p),r(c,y,m)}},o)}return rl=a,rl}var nl,py;function jS(){if(py)return nl;py=1;var e=jo(),r=_o();function t(n){return e(function(i,o){var s=-1,a=o.length,c=a>1?o[a-1]:void 0,l=a>2?o[2]:void 0;for(c=n.length>3&&typeof c=="function"?(a--,c):void 0,l&&r(o[0],o[1],l)&&(c=a<3?void 0:c,a=1),i=Object(i);++s<a;){var d=o[s];d&&n(i,d,s,c)}return i})}return nl=t,nl}var ol,gy;function _S(){if(gy)return ol;gy=1;var e=SS(),r=jS(),t=r(function(n,i,o){e(n,i,o)});return ol=t,ol}var il,yy;function $v(){if(yy)return il;yy=1;function e(r,t){return r<t}return il=e,il}var al,my;function ES(){if(my)return al;my=1;var e=Zd(),r=$v(),t=Pr();function n(i){return i&&i.length?e(i,t,r):void 0}return al=n,al}var sl,by;function RS(){if(by)return sl;by=1;var e=Zd(),r=tr(),t=$v();function n(i,o){return i&&i.length?e(i,r(o,2),t):void 0}return sl=n,sl}var cl,vy;function kS(){if(vy)return cl;vy=1;var e=Gt(),r=function(){return e.Date.now()};return cl=r,cl}var ll,xy;function AS(){if(xy)return ll;xy=1;var e=go(),r=Co(),t=yo(),n=Lt(),i=Nn();function o(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 y=i(a[d]),m=c;if(y==="__proto__"||y==="constructor"||y==="prototype")return s;if(d!=h){var g=p[y];m=l?l(g,y,p):void 0,m===void 0&&(m=n(g)?g:t(a[d+1])?[]:{})}e(p,y,m),p=p[y]}return s}return ll=o,ll}var dl,wy;function PS(){if(wy)return dl;wy=1;var e=So(),r=AS(),t=Co();function n(i,o,s){for(var a=-1,c=o.length,l={};++a<c;){var d=o[a],u=e(i,d);s(u,d)&&r(l,t(d,i),u)}return l}return dl=n,dl}var ul,Cy;function IS(){if(Cy)return ul;Cy=1;var e=PS(),r=pv();function t(n,i){return e(n,i,function(o,s){return r(n,s)})}return ul=t,ul}var fl,Sy;function MS(){if(Sy)return fl;Sy=1;var e=Tv(),r=Cv(),t=Sv();function n(i){return t(r(i,void 0,e),i+"")}return fl=n,fl}var hl,jy;function TS(){if(jy)return hl;jy=1;var e=IS(),r=MS(),t=r(function(n,i){return n==null?{}:e(n,i)});return hl=t,hl}var pl,_y;function OS(){if(_y)return pl;_y=1;var e=Math.ceil,r=Math.max;function t(n,i,o,s){for(var a=-1,c=r(e((i-n)/(o||1)),0),l=Array(c);c--;)l[s?c:++a]=n,n+=o;return l}return pl=t,pl}var gl,Ey;function NS(){if(Ey)return gl;Ey=1;var e=OS(),r=_o(),t=Mv();function n(i){return function(o,s,a){return a&&typeof a!="number"&&r(o,s,a)&&(s=a=void 0),o=t(o),s===void 0?(s=o,o=0):s=t(s),a=a===void 0?o<s?1:-1:t(a),e(o,s,a,i)}}return gl=n,gl}var yl,Ry;function $S(){if(Ry)return yl;Ry=1;var e=NS(),r=e();return yl=r,yl}var ml,ky;function qS(){if(ky)return ml;ky=1;function e(r,t){var n=r.length;for(r.sort(t);n--;)r[n]=r[n].value;return r}return ml=e,ml}var bl,Ay;function LS(){if(Ay)return bl;Ay=1;var e=en();function r(t,n){if(t!==n){var i=t!==void 0,o=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||o&&c&&d||!i&&d||!s)return 1;if(!o&&!a&&!u&&t<n||u&&i&&s&&!o&&!a||l&&i&&s||!c&&s||!d)return-1}return 0}return bl=r,bl}var vl,Py;function FS(){if(Py)return vl;Py=1;var e=LS();function r(t,n,i){for(var o=-1,s=t.criteria,a=n.criteria,c=s.length,l=i.length;++o<c;){var d=e(s[o],a[o]);if(d){if(o>=l)return d;var u=i[o];return d*(u=="desc"?-1:1)}}return t.index-n.index}return vl=r,vl}var xl,Iy;function zS(){if(Iy)return xl;Iy=1;var e=wo(),r=So(),t=tr(),n=vv(),i=qS(),o=mo(),s=FS(),a=Pr(),c=gt();function l(d,u,h){u.length?u=e(u,function(m){return c(m)?function(g){return r(g,m.length===1?m[0]:m)}:m}):u=[a];var p=-1;u=e(u,o(t));var y=n(d,function(m,g,b){var v=e(u,function(x){return x(m)});return{criteria:v,index:++p,value:m}});return i(y,function(m,g){return s(m,g,h)})}return xl=l,xl}var wl,My;function BS(){if(My)return wl;My=1;var e=Kd(),r=zS(),t=jo(),n=_o(),i=t(function(o,s){if(o==null)return[];var a=s.length;return a>1&&n(o,s[0],s[1])?s=[]:a>2&&n(s[0],s[1],s[2])&&(s=[s[0]]),r(o,e(s,1),[])});return wl=i,wl}var Cl,Ty;function DS(){if(Ty)return Cl;Ty=1;var e=fv(),r=0;function t(n){var i=++r;return e(n)+i}return Cl=t,Cl}var Sl,Oy;function VS(){if(Oy)return Sl;Oy=1;function e(r,t,n){for(var i=-1,o=r.length,s=t.length,a={};++i<o;){var c=i<s?t[i]:void 0;n(a,r[i],c)}return a}return Sl=e,Sl}var jl,Ny;function GS(){if(Ny)return jl;Ny=1;var e=go(),r=VS();function t(n,i){return r(n||[],i||[],e)}return jl=t,jl}var _l,$y;function ct(){if($y)return _l;$y=1;var e;if(typeof Td=="function")try{e={cloneDeep:aS(),constant:Vd(),defaults:sS(),each:iv(),filter:yv(),find:pS(),flatten:Tv(),forEach:ov(),forIn:gS(),has:mv(),isUndefined:bv(),last:yS(),map:xv(),mapValues:mS(),max:vS(),merge:_S(),min:ES(),minBy:RS(),now:kS(),pick:TS(),range:$S(),reduce:wv(),sortBy:BS(),uniqueId:DS(),values:Ev(),zipObject:GS()}}catch{}return e||(e=window._),_l=e,_l}var El,qy;function WS(){if(qy)return El;qy=1,El=e;function e(){var n={};n._next=n._prev=n,this._sentinel=n}e.prototype.dequeue=function(){var n=this._sentinel,i=n._prev;if(i!==n)return r(i),i},e.prototype.enqueue=function(n){var i=this._sentinel;n._prev&&n._next&&r(n),n._next=i._next,i._next._prev=n,i._next=n,n._prev=i},e.prototype.toString=function(){for(var n=[],i=this._sentinel,o=i._prev;o!==i;)n.push(JSON.stringify(o,t)),o=o._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,i){if(n!=="_next"&&n!=="_prev")return i}return El}var Rl,Ly;function US(){if(Ly)return Rl;Ly=1;var e=ct(),r=Vt().Graph,t=WS();Rl=i;var n=e.constant(1);function i(l,d){if(l.nodeCount()<=1)return[];var u=a(l,d||n),h=o(u.graph,u.buckets,u.zeroIdx);return e.flatten(e.map(h,function(p){return l.outEdges(p.v,p.w)}),!0)}function o(l,d,u){for(var h=[],p=d[d.length-1],y=d[0],m;l.nodeCount();){for(;m=y.dequeue();)s(l,d,u,m);for(;m=p.dequeue();)s(l,d,u,m);if(l.nodeCount()){for(var g=d.length-2;g>0;--g)if(m=d[g].dequeue(),m){h=h.concat(s(l,d,u,m,!0));break}}}return h}function s(l,d,u,h,p){var y=p?[]:void 0;return e.forEach(l.inEdges(h.v),function(m){var g=l.edge(m),b=l.node(m.v);p&&y.push({v:m.v,w:m.w}),b.out-=g,c(d,u,b)}),e.forEach(l.outEdges(h.v),function(m){var g=l.edge(m),b=m.w,v=l.node(b);v.in-=g,c(d,u,v)}),l.removeNode(h.v),y}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 b=u.edge(g.v,g.w)||0,v=d(g),x=b+v;u.setEdge(g.v,g.w,x),p=Math.max(p,u.node(g.v).out+=v),h=Math.max(h,u.node(g.w).in+=v)});var y=e.range(p+h+3).map(function(){return new t}),m=h+1;return e.forEach(u.nodes(),function(g){c(y,m,u.node(g))}),{graph:u,buckets:y,zeroIdx:m}}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 Rl}var kl,Fy;function HS(){if(Fy)return kl;Fy=1;var e=ct(),r=US();kl={run:t,undo:i};function t(o){var s=o.graph().acyclicer==="greedy"?r(o,a(o)):n(o);e.forEach(s,function(c){var l=o.edge(c);o.removeEdge(c),l.forwardName=c.name,l.reversed=!0,o.setEdge(c.w,c.v,l,e.uniqueId("rev"))});function a(c){return function(l){return c.edge(l).weight}}}function n(o){var s=[],a={},c={};function l(d){e.has(c,d)||(c[d]=!0,a[d]=!0,e.forEach(o.outEdges(d),function(u){e.has(a,u.w)?s.push(u):l(u.w)}),delete a[d])}return e.forEach(o.nodes(),l),s}function i(o){e.forEach(o.edges(),function(s){var a=o.edge(s);if(a.reversed){o.removeEdge(s);var c=a.forwardName;delete a.reversed,delete a.forwardName,o.setEdge(s.w,s.v,a,c)}})}return kl}var Al,zy;function At(){if(zy)return Al;zy=1;var e=ct(),r=Vt().Graph;Al={addDummyNode:t,simplify:n,asNonCompoundGraph:i,successorWeights:o,predecessorWeights:s,intersectRect:a,buildLayerMatrix:c,normalizeRanks:l,removeEmptyRanks:d,addBorderNode:u,maxRank:h,partition:p,time:y,notime:m};function t(g,b,v,x){var w;do w=e.uniqueId(x);while(g.hasNode(w));return v.dummy=b,g.setNode(w,v),w}function n(g){var b=new r().setGraph(g.graph());return e.forEach(g.nodes(),function(v){b.setNode(v,g.node(v))}),e.forEach(g.edges(),function(v){var x=b.edge(v.v,v.w)||{weight:0,minlen:1},w=g.edge(v);b.setEdge(v.v,v.w,{weight:x.weight+w.weight,minlen:Math.max(x.minlen,w.minlen)})}),b}function i(g){var b=new r({multigraph:g.isMultigraph()}).setGraph(g.graph());return e.forEach(g.nodes(),function(v){g.children(v).length||b.setNode(v,g.node(v))}),e.forEach(g.edges(),function(v){b.setEdge(v,g.edge(v))}),b}function o(g){var b=e.map(g.nodes(),function(v){var x={};return e.forEach(g.outEdges(v),function(w){x[w.w]=(x[w.w]||0)+g.edge(w).weight}),x});return e.zipObject(g.nodes(),b)}function s(g){var b=e.map(g.nodes(),function(v){var x={};return e.forEach(g.inEdges(v),function(w){x[w.v]=(x[w.v]||0)+g.edge(w).weight}),x});return e.zipObject(g.nodes(),b)}function a(g,b){var v=g.x,x=g.y,w=b.x-v,C=b.y-x,j=g.width/2,_=g.height/2;if(!w&&!C)throw new Error("Not possible to find intersection inside of the rectangle");var k,E;return Math.abs(C)*j>Math.abs(w)*_?(C<0&&(_=-_),k=_*w/C,E=_):(w<0&&(j=-j),k=j,E=j*C/w),{x:v+k,y:x+E}}function c(g){var b=e.map(e.range(h(g)+1),function(){return[]});return e.forEach(g.nodes(),function(v){var x=g.node(v),w=x.rank;e.isUndefined(w)||(b[w][x.order]=v)}),b}function l(g){var b=e.min(e.map(g.nodes(),function(v){return g.node(v).rank}));e.forEach(g.nodes(),function(v){var x=g.node(v);e.has(x,"rank")&&(x.rank-=b)})}function d(g){var b=e.min(e.map(g.nodes(),function(C){return g.node(C).rank})),v=[];e.forEach(g.nodes(),function(C){var j=g.node(C).rank-b;v[j]||(v[j]=[]),v[j].push(C)});var x=0,w=g.graph().nodeRankFactor;e.forEach(v,function(C,j){e.isUndefined(C)&&j%w!==0?--x:x&&e.forEach(C,function(_){g.node(_).rank+=x})})}function u(g,b,v,x){var w={width:0,height:0};return arguments.length>=4&&(w.rank=v,w.order=x),t(g,"border",w,b)}function h(g){return e.max(e.map(g.nodes(),function(b){var v=g.node(b).rank;if(!e.isUndefined(v))return v}))}function p(g,b){var v={lhs:[],rhs:[]};return e.forEach(g,function(x){b(x)?v.lhs.push(x):v.rhs.push(x)}),v}function y(g,b){var v=e.now();try{return b()}finally{console.log(g+" time: "+(e.now()-v)+"ms")}}function m(g,b){return b()}return Al}var Pl,By;function KS(){if(By)return Pl;By=1;var e=ct(),r=At();Pl={run:t,undo:i};function t(o){o.graph().dummyChains=[],e.forEach(o.edges(),function(s){n(o,s)})}function n(o,s){var a=s.v,c=o.node(a).rank,l=s.w,d=o.node(l).rank,u=s.name,h=o.edge(s),p=h.labelRank;if(d!==c+1){o.removeEdge(s);var y,m,g;for(g=0,++c;c<d;++g,++c)h.points=[],m={width:0,height:0,edgeLabel:h,edgeObj:s,rank:c},y=r.addDummyNode(o,"edge",m,"_d"),c===p&&(m.width=h.width,m.height=h.height,m.dummy="edge-label",m.labelpos=h.labelpos),o.setEdge(a,y,{weight:h.weight},u),g===0&&o.graph().dummyChains.push(y),a=y;o.setEdge(a,l,{weight:h.weight},u)}}function i(o){e.forEach(o.graph().dummyChains,function(s){var a=o.node(s),c=a.edgeLabel,l;for(o.setEdge(a.edgeObj,c);a.dummy;)l=o.successors(s)[0],o.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=o.node(s)})}return Pl}var Il,Dy;function Yn(){if(Dy)return Il;Dy=1;var e=ct();Il={longestPath:r,slack:t};function r(n){var i={};function o(s){var a=n.node(s);if(e.has(i,s))return a.rank;i[s]=!0;var c=e.min(e.map(n.outEdges(s),function(l){return o(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(),o)}function t(n,i){return n.node(i.w).rank-n.node(i.v).rank-n.edge(i).minlen}return Il}var Ml,Vy;function qv(){if(Vy)return Ml;Vy=1;var e=ct(),r=Vt().Graph,t=Yn().slack;Ml=n;function n(a){var c=new r({directed:!1}),l=a.nodes()[0],d=a.nodeCount();c.setNode(l,{});for(var u,h;i(c,a)<d;)u=o(c,a),h=c.hasNode(u.v)?t(a,u):-t(a,u),s(c,a,h);return c}function i(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 o(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 Ml}var Tl,Gy;function JS(){if(Gy)return Tl;Gy=1;var e=ct(),r=qv(),t=Yn().slack,n=Yn().longestPath,i=Vt().alg.preorder,o=Vt().alg.postorder,s=At().simplify;Tl=a,a.initLowLimValues=u,a.initCutValues=c,a.calcCutValue=d,a.leaveEdge=p,a.enterEdge=y,a.exchangeEdges=m;function a(x){x=s(x),n(x);var w=r(x);u(w),c(w,x);for(var C,j;C=p(w);)j=y(w,x,C),m(w,x,C,j)}function c(x,w){var C=o(x,x.nodes());C=C.slice(0,C.length-1),e.forEach(C,function(j){l(x,w,j)})}function l(x,w,C){var j=x.node(C),_=j.parent;x.edge(C,_).cutvalue=d(x,w,C)}function d(x,w,C){var j=x.node(C),_=j.parent,k=!0,E=w.edge(C,_),O=0;return E||(k=!1,E=w.edge(_,C)),O=E.weight,e.forEach(w.nodeEdges(C),function(T){var P=T.v===C,I=P?T.w:T.v;if(I!==_){var R=P===k,$=w.edge(T).weight;if(O+=R?$:-$,b(x,C,I)){var N=x.edge(C,I).cutvalue;O+=R?-N:N}}}),O}function u(x,w){arguments.length<2&&(w=x.nodes()[0]),h(x,{},1,w)}function h(x,w,C,j,_){var k=C,E=x.node(j);return w[j]=!0,e.forEach(x.neighbors(j),function(O){e.has(w,O)||(C=h(x,w,C,O,j))}),E.low=k,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 y(x,w,C){var j=C.v,_=C.w;w.hasEdge(j,_)||(j=C.w,_=C.v);var k=x.node(j),E=x.node(_),O=k,T=!1;k.lim>E.lim&&(O=E,T=!0);var P=e.filter(w.edges(),function(I){return T===v(x,x.node(I.v),O)&&T!==v(x,x.node(I.w),O)});return e.minBy(P,function(I){return t(w,I)})}function m(x,w,C,j){var _=C.v,k=C.w;x.removeEdge(_,k),x.setEdge(j.v,j.w,{}),u(x),c(x,w),g(x,w)}function g(x,w){var C=e.find(x.nodes(),function(_){return!w.node(_).parent}),j=i(x,C);j=j.slice(1),e.forEach(j,function(_){var k=x.node(_).parent,E=w.edge(_,k),O=!1;E||(E=w.edge(k,_),O=!0),w.node(_).rank=w.node(k).rank+(O?E.minlen:-E.minlen)})}function b(x,w,C){return x.hasEdge(w,C)}function v(x,w,C){return C.low<=w.lim&&w.lim<=C.lim}return Tl}var Ol,Wy;function ZS(){if(Wy)return Ol;Wy=1;var e=Yn(),r=e.longestPath,t=qv(),n=JS();Ol=i;function i(c){switch(c.graph().ranker){case"network-simplex":a(c);break;case"tight-tree":s(c);break;case"longest-path":o(c);break;default:a(c)}}var o=r;function s(c){r(c),t(c)}function a(c){n(c)}return Ol}var Nl,Uy;function XS(){if(Uy)return Nl;Uy=1;var e=ct();Nl=r;function r(i){var o=n(i);e.forEach(i.graph().dummyChains,function(s){for(var a=i.node(s),c=a.edgeObj,l=t(i,o,c.v,c.w),d=l.path,u=l.lca,h=0,p=d[h],y=!0;s!==c.w;){if(a=i.node(s),y){for(;(p=d[h])!==u&&i.node(p).maxRank<a.rank;)h++;p===u&&(y=!1)}if(!y){for(;h<d.length-1&&i.node(p=d[h+1]).minRank<=a.rank;)h++;p=d[h]}i.setParent(s,p),s=i.successors(s)[0]}})}function t(i,o,s,a){var c=[],l=[],d=Math.min(o[s].low,o[a].low),u=Math.max(o[s].lim,o[a].lim),h,p;h=s;do h=i.parent(h),c.push(h);while(h&&(o[h].low>d||u>o[h].lim));for(p=h,h=a;(h=i.parent(h))!==p;)l.push(h);return{path:c.concat(l.reverse()),lca:p}}function n(i){var o={},s=0;function a(c){var l=s;e.forEach(i.children(c),a),o[c]={low:l,lim:s++}}return e.forEach(i.children(),a),o}return Nl}var $l,Hy;function YS(){if(Hy)return $l;Hy=1;var e=ct(),r=At();$l={run:t,cleanup:s};function t(a){var c=r.addDummyNode(a,"root",{},"_root"),l=i(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=o(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 y=a.children(p);if(!y.length){p!==c&&a.setEdge(c,p,{weight:0,minlen:l});return}var m=r.addBorderNode(a,"_bt"),g=r.addBorderNode(a,"_bb"),b=a.node(p);a.setParent(m,p),b.borderTop=m,a.setParent(g,p),b.borderBottom=g,e.forEach(y,function(v){n(a,c,l,d,u,h,v);var x=a.node(v),w=x.borderTop?x.borderTop:v,C=x.borderBottom?x.borderBottom:v,j=x.borderTop?d:2*d,_=w!==C?1:u-h[p]+1;a.setEdge(m,w,{weight:j,minlen:_,nestingEdge:!0}),a.setEdge(C,g,{weight:j,minlen:_,nestingEdge:!0})}),a.parent(p)||a.setEdge(c,m,{weight:0,minlen:u+h[p]})}function i(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 o(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 $l}var ql,Ky;function QS(){if(Ky)return ql;Ky=1;var e=ct(),r=At();ql=t;function t(i){function o(s){var a=i.children(s),c=i.node(s);if(a.length&&e.forEach(a,o),e.has(c,"minRank")){c.borderLeft=[],c.borderRight=[];for(var l=c.minRank,d=c.maxRank+1;l<d;++l)n(i,"borderLeft","_bl",s,c,l),n(i,"borderRight","_br",s,c,l)}}e.forEach(i.children(),o)}function n(i,o,s,a,c,l){var d={width:0,height:0,rank:l,borderType:o},u=c[o][l-1],h=r.addDummyNode(i,"border",d,s);c[o][l]=h,i.setParent(h,a),u&&i.setEdge(u,h,{weight:1})}return ql}var Ll,Jy;function ej(){if(Jy)return Ll;Jy=1;var e=ct();Ll={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")&&o(l),(d==="lr"||d==="rl")&&(a(l),n(l))}function n(l){e.forEach(l.nodes(),function(d){i(l.node(d))}),e.forEach(l.edges(),function(d){i(l.edge(d))})}function i(l){var d=l.width;l.width=l.height,l.height=d}function o(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 Ll}var Fl,Zy;function tj(){if(Zy)return Fl;Zy=1;var e=ct();Fl=r;function r(t){var n={},i=e.filter(t.nodes(),function(l){return!t.children(l).length}),o=e.max(e.map(i,function(l){return t.node(l).rank})),s=e.map(e.range(o+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(i,function(l){return t.node(l).rank});return e.forEach(c,a),s}return Fl}var zl,Xy;function rj(){if(Xy)return zl;Xy=1;var e=ct();zl=r;function r(n,i){for(var o=0,s=1;s<i.length;++s)o+=t(n,i[s-1],i[s]);return o}function t(n,i,o){for(var s=e.zipObject(o,e.map(o,function(h,p){return p})),a=e.flatten(e.map(i,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<o.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 y=0;p>0;)p%2&&(y+=d[p+1]),p=p-1>>1,d[p]+=h.weight;u+=h.weight*y})),u}return zl}var Bl,Yy;function nj(){if(Yy)return Bl;Yy=1;var e=ct();Bl=r;function r(t,n){return e.map(n,function(i){var o=t.inEdges(i);if(o.length){var s=e.reduce(o,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:i,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:i}})}return Bl}var Dl,Qy;function oj(){if(Qy)return Dl;Qy=1;var e=ct();Dl=r;function r(i,o){var s={};e.forEach(i,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(o.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(i){var o=[];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&&i.push(d)}}for(;i.length;){var c=i.pop();o.push(c),e.forEach(c.in.reverse(),s(c)),e.forEach(c.out,a(c))}return e.map(e.filter(o,function(l){return!l.merged}),function(l){return e.pick(l,["vs","i","barycenter","weight"])})}function n(i,o){var s=0,a=0;i.weight&&(s+=i.barycenter*i.weight,a+=i.weight),o.weight&&(s+=o.barycenter*o.weight,a+=o.weight),i.vs=o.vs.concat(i.vs),i.barycenter=s/a,i.weight=a,i.i=Math.min(o.i,i.i),o.merged=!0}return Dl}var Vl,em;function ij(){if(em)return Vl;em=1;var e=ct(),r=At();Vl=t;function t(o,s){var a=r.partition(o,function(m){return e.has(m,"barycenter")}),c=a.lhs,l=e.sortBy(a.rhs,function(m){return-m.i}),d=[],u=0,h=0,p=0;c.sort(i(!!s)),p=n(d,l,p),e.forEach(c,function(m){p+=m.vs.length,d.push(m.vs),u+=m.barycenter*m.weight,h+=m.weight,p=n(d,l,p)});var y={vs:e.flatten(d,!0)};return h&&(y.barycenter=u/h,y.weight=h),y}function n(o,s,a){for(var c;s.length&&(c=e.last(s)).i<=a;)s.pop(),o.push(c.vs),a++;return a}function i(o){return function(s,a){return s.barycenter<a.barycenter?-1:s.barycenter>a.barycenter?1:o?a.i-s.i:s.i-a.i}}return Vl}var Gl,tm;function aj(){if(tm)return Gl;tm=1;var e=ct(),r=nj(),t=oj(),n=ij();Gl=i;function i(a,c,l,d){var u=a.children(c),h=a.node(c),p=h?h.borderLeft:void 0,y=h?h.borderRight:void 0,m={};p&&(u=e.filter(u,function(C){return C!==p&&C!==y}));var g=r(a,u);e.forEach(g,function(C){if(a.children(C.v).length){var j=i(a,C.v,l,d);m[C.v]=j,e.has(j,"barycenter")&&s(C,j)}});var b=t(g,l);o(b,m);var v=n(b,d);if(p&&(v.vs=e.flatten([p,v.vs,y],!0),a.predecessors(p).length)){var x=a.node(a.predecessors(p)[0]),w=a.node(a.predecessors(y)[0]);e.has(v,"barycenter")||(v.barycenter=0,v.weight=0),v.barycenter=(v.barycenter*v.weight+x.order+w.order)/(v.weight+2),v.weight+=2}return v}function o(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 Gl}var Wl,rm;function sj(){if(rm)return Wl;rm=1;var e=ct(),r=Vt().Graph;Wl=t;function t(i,o,s){var a=n(i),c=new r({compound:!0}).setGraph({root:a}).setDefaultNodeLabel(function(l){return i.node(l)});return e.forEach(i.nodes(),function(l){var d=i.node(l),u=i.parent(l);(d.rank===o||d.minRank<=o&&o<=d.maxRank)&&(c.setNode(l),c.setParent(l,u||a),e.forEach(i[s](l),function(h){var p=h.v===l?h.w:h.v,y=c.edge(p,l),m=e.isUndefined(y)?0:y.weight;c.setEdge(p,l,{weight:i.edge(h).weight+m})}),e.has(d,"minRank")&&c.setNode(l,{borderLeft:d.borderLeft[o],borderRight:d.borderRight[o]}))}),c}function n(i){for(var o;i.hasNode(o=e.uniqueId("_root")););return o}return Wl}var Ul,nm;function cj(){if(nm)return Ul;nm=1;var e=ct();Ul=r;function r(t,n,i){var o={},s;e.forEach(i,function(a){for(var c=t.parent(a),l,d;c;){if(l=t.parent(c),l?(d=o[l],o[l]=c):(d=s,s=c),d&&d!==c){n.setEdge(d,c);return}c=l}})}return Ul}var Hl,om;function lj(){if(om)return Hl;om=1;var e=ct(),r=tj(),t=rj(),n=aj(),i=sj(),o=cj(),s=Vt().Graph,a=At();Hl=c;function c(h){var p=a.maxRank(h),y=l(h,e.range(1,p+1),"inEdges"),m=l(h,e.range(p-1,-1,-1),"outEdges"),g=r(h);u(h,g);for(var b=Number.POSITIVE_INFINITY,v,x=0,w=0;w<4;++x,++w){d(x%2?y:m,x%4>=2),g=a.buildLayerMatrix(h);var C=t(h,g);C<b&&(w=0,v=e.cloneDeep(g),b=C)}u(h,v)}function l(h,p,y){return e.map(p,function(m){return i(h,m,y)})}function d(h,p){var y=new s;e.forEach(h,function(m){var g=m.graph().root,b=n(m,g,y,p);e.forEach(b.vs,function(v,x){m.node(v).order=x}),o(m,y,b.vs)})}function u(h,p){e.forEach(p,function(y){e.forEach(y,function(m,g){h.node(m).order=g})})}return Hl}var Kl,im;function dj(){if(im)return Kl;im=1;var e=ct(),r=Vt().Graph,t=At();Kl={positionX:y,findType1Conflicts:n,findType2Conflicts:i,addConflict:s,hasConflict:a,verticalAlignment:c,horizontalCompaction:l,alignCoordinates:h,findSmallestWidthAlignment:u,balance:p};function n(b,v){var x={};function w(C,j){var _=0,k=0,E=C.length,O=e.last(j);return e.forEach(j,function(T,P){var I=o(b,T),R=I?b.node(I).order:E;(I||T===O)&&(e.forEach(j.slice(k,P+1),function($){e.forEach(b.predecessors($),function(N){var M=b.node(N),J=M.order;(J<_||R<J)&&!(M.dummy&&b.node($).dummy)&&s(x,N,$)})}),k=P+1,_=R)}),j}return e.reduce(v,w),x}function i(b,v){var x={};function w(j,_,k,E,O){var T;e.forEach(e.range(_,k),function(P){T=j[P],b.node(T).dummy&&e.forEach(b.predecessors(T),function(I){var R=b.node(I);R.dummy&&(R.order<E||R.order>O)&&s(x,I,T)})})}function C(j,_){var k=-1,E,O=0;return e.forEach(_,function(T,P){if(b.node(T).dummy==="border"){var I=b.predecessors(T);I.length&&(E=b.node(I[0]).order,w(_,O,P,k,E),O=P,k=E)}w(_,O,_.length,E,j.length)}),_}return e.reduce(v,C),x}function o(b,v){if(b.node(v).dummy)return e.find(b.predecessors(v),function(x){return b.node(x).dummy})}function s(b,v,x){if(v>x){var w=v;v=x,x=w}var C=b[v];C||(b[v]=C={}),C[x]=!0}function a(b,v,x){if(v>x){var w=v;v=x,x=w}return e.has(b[v],x)}function c(b,v,x,w){var C={},j={},_={};return e.forEach(v,function(k){e.forEach(k,function(E,O){C[E]=E,j[E]=E,_[E]=O})}),e.forEach(v,function(k){var E=-1;e.forEach(k,function(O){var T=w(O);if(T.length){T=e.sortBy(T,function(N){return _[N]});for(var P=(T.length-1)/2,I=Math.floor(P),R=Math.ceil(P);I<=R;++I){var $=T[I];j[O]===O&&E<_[$]&&!a(x,O,$)&&(j[$]=O,j[O]=C[O]=C[$],E=_[$])}}})}),{root:C,align:j}}function l(b,v,x,w,C){var j={},_=d(b,v,x,C),k=C?"borderLeft":"borderRight";function E(P,I){for(var R=_.nodes(),$=R.pop(),N={};$;)N[$]?P($):(N[$]=!0,R.push($),R=R.concat(I($))),$=R.pop()}function O(P){j[P]=_.inEdges(P).reduce(function(I,R){return Math.max(I,j[R.v]+_.edge(R))},0)}function T(P){var I=_.outEdges(P).reduce(function($,N){return Math.min($,j[N.w]-_.edge(N))},Number.POSITIVE_INFINITY),R=b.node(P);I!==Number.POSITIVE_INFINITY&&R.borderType!==k&&(j[P]=Math.max(j[P],I))}return E(O,_.predecessors.bind(_)),E(T,_.successors.bind(_)),e.forEach(w,function(P){j[P]=j[x[P]]}),j}function d(b,v,x,w){var C=new r,j=b.graph(),_=m(j.nodesep,j.edgesep,w);return e.forEach(v,function(k){var E;e.forEach(k,function(O){var T=x[O];if(C.setNode(T),E){var P=x[E],I=C.edge(P,T);C.setEdge(P,T,Math.max(_(b,O,E),I||0))}E=O})}),C}function u(b,v){return e.minBy(e.values(v),function(x){var w=Number.NEGATIVE_INFINITY,C=Number.POSITIVE_INFINITY;return e.forIn(x,function(j,_){var k=g(b,_)/2;w=Math.max(j+k,w),C=Math.min(j-k,C)}),w-C})}function h(b,v){var x=e.values(v),w=e.min(x),C=e.max(x);e.forEach(["u","d"],function(j){e.forEach(["l","r"],function(_){var k=j+_,E=b[k],O;if(E!==v){var T=e.values(E);O=_==="l"?w-e.min(T):C-e.max(T),O&&(b[k]=e.mapValues(E,function(P){return P+O}))}})})}function p(b,v){return e.mapValues(b.ul,function(x,w){if(v)return b[v.toLowerCase()][w];var C=e.sortBy(e.map(b,w));return(C[1]+C[2])/2})}function y(b){var v=t.buildLayerMatrix(b),x=e.merge(n(b,v),i(b,v)),w={},C;e.forEach(["u","d"],function(_){C=_==="u"?v:e.values(v).reverse(),e.forEach(["l","r"],function(k){k==="r"&&(C=e.map(C,function(P){return e.values(P).reverse()}));var E=(_==="u"?b.predecessors:b.successors).bind(b),O=c(b,C,x,E),T=l(b,C,O.root,O.align,k==="r");k==="r"&&(T=e.mapValues(T,function(P){return-P})),w[_+k]=T})});var j=u(b,w);return h(w,j),p(w,b.graph().align)}function m(b,v,x){return function(w,C,j){var _=w.node(C),k=w.node(j),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?v:b)/2,E+=(k.dummy?v:b)/2,E+=k.width/2,e.has(k,"labelpos"))switch(k.labelpos.toLowerCase()){case"l":O=k.width/2;break;case"r":O=-k.width/2;break}return O&&(E+=x?O:-O),O=0,E}}function g(b,v){return b.node(v).width}return Kl}var Jl,am;function uj(){if(am)return Jl;am=1;var e=ct(),r=At(),t=dj().positionX;Jl=n;function n(o){o=r.asNonCompoundGraph(o),i(o),e.forEach(t(o),function(s,a){o.node(a).x=s})}function i(o){var s=r.buildLayerMatrix(o),a=o.graph().ranksep,c=0;e.forEach(s,function(l){var d=e.max(e.map(l,function(u){return o.node(u).height}));e.forEach(l,function(u){o.node(u).y=c+d/2}),c+=d+a})}return Jl}var Zl,sm;function fj(){if(sm)return Zl;sm=1;var e=ct(),r=HS(),t=KS(),n=ZS(),i=At().normalizeRanks,o=XS(),s=At().removeEmptyRanks,a=YS(),c=QS(),l=ej(),d=lj(),u=uj(),h=At(),p=Vt().Graph;Zl=y;function y(q,F){var H=F&&F.debugTiming?h.time:h.notime;H("layout",function(){var B=H(" buildLayoutGraph",function(){return E(q)});H(" runLayout",function(){m(B,H)}),H(" updateInputGraph",function(){g(q,B)})})}function m(q,F){F(" makeSpaceForEdgeLabels",function(){O(q)}),F(" removeSelfEdges",function(){ae(q)}),F(" acyclic",function(){r.run(q)}),F(" nestingGraph.run",function(){a.run(q)}),F(" rank",function(){n(h.asNonCompoundGraph(q))}),F(" injectEdgeLabelProxies",function(){T(q)}),F(" removeEmptyRanks",function(){s(q)}),F(" nestingGraph.cleanup",function(){a.cleanup(q)}),F(" normalizeRanks",function(){i(q)}),F(" assignRankMinMax",function(){P(q)}),F(" removeEdgeLabelProxies",function(){I(q)}),F(" normalize.run",function(){t.run(q)}),F(" parentDummyChains",function(){o(q)}),F(" addBorderSegments",function(){c(q)}),F(" order",function(){d(q)}),F(" insertSelfEdges",function(){se(q)}),F(" adjustCoordinateSystem",function(){l.adjust(q)}),F(" position",function(){u(q)}),F(" positionSelfEdges",function(){ee(q)}),F(" removeBorderNodes",function(){J(q)}),F(" normalize.undo",function(){t.undo(q)}),F(" fixupEdgeLabelCoords",function(){N(q)}),F(" undoCoordinateSystem",function(){l.undo(q)}),F(" translateGraph",function(){R(q)}),F(" assignNodeIntersects",function(){$(q)}),F(" reversePoints",function(){M(q)}),F(" acyclic.undo",function(){r.undo(q)})}function g(q,F){e.forEach(q.nodes(),function(H){var B=q.node(H),de=F.node(H);B&&(B.x=de.x,B.y=de.y,F.children(H).length&&(B.width=de.width,B.height=de.height))}),e.forEach(q.edges(),function(H){var B=q.edge(H),de=F.edge(H);B.points=de.points,e.has(de,"x")&&(B.x=de.x,B.y=de.y)}),q.graph().width=F.graph().width,q.graph().height=F.graph().height}var b=["nodesep","edgesep","ranksep","marginx","marginy"],v={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},x=["acyclicer","ranker","rankdir","align"],w=["width","height"],C={width:0,height:0},j=["minlen","weight","width","height","labeloffset"],_={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},k=["labelpos"];function E(q){var F=new p({multigraph:!0,compound:!0}),H=me(q.graph());return F.setGraph(e.merge({},v,pe(H,b),e.pick(H,x))),e.forEach(q.nodes(),function(B){var de=me(q.node(B));F.setNode(B,e.defaults(pe(de,w),C)),F.setParent(B,q.parent(B))}),e.forEach(q.edges(),function(B){var de=me(q.edge(B));F.setEdge(B,e.merge({},_,pe(de,j),e.pick(de,k)))}),F}function O(q){var F=q.graph();F.ranksep/=2,e.forEach(q.edges(),function(H){var B=q.edge(H);B.minlen*=2,B.labelpos.toLowerCase()!=="c"&&(F.rankdir==="TB"||F.rankdir==="BT"?B.width+=B.labeloffset:B.height+=B.labeloffset)})}function T(q){e.forEach(q.edges(),function(F){var H=q.edge(F);if(H.width&&H.height){var B=q.node(F.v),de=q.node(F.w),Y={rank:(de.rank-B.rank)/2+B.rank,e:F};h.addDummyNode(q,"edge-proxy",Y,"_ep")}})}function P(q){var F=0;e.forEach(q.nodes(),function(H){var B=q.node(H);B.borderTop&&(B.minRank=q.node(B.borderTop).rank,B.maxRank=q.node(B.borderBottom).rank,F=e.max(F,B.maxRank))}),q.graph().maxRank=F}function I(q){e.forEach(q.nodes(),function(F){var H=q.node(F);H.dummy==="edge-proxy"&&(q.edge(H.e).labelRank=H.rank,q.removeNode(F))})}function R(q){var F=Number.POSITIVE_INFINITY,H=0,B=Number.POSITIVE_INFINITY,de=0,Y=q.graph(),oe=Y.marginx||0,ce=Y.marginy||0;function xe(je){var ye=je.x,ge=je.y,z=je.width,W=je.height;F=Math.min(F,ye-z/2),H=Math.max(H,ye+z/2),B=Math.min(B,ge-W/2),de=Math.max(de,ge+W/2)}e.forEach(q.nodes(),function(je){xe(q.node(je))}),e.forEach(q.edges(),function(je){var ye=q.edge(je);e.has(ye,"x")&&xe(ye)}),F-=oe,B-=ce,e.forEach(q.nodes(),function(je){var ye=q.node(je);ye.x-=F,ye.y-=B}),e.forEach(q.edges(),function(je){var ye=q.edge(je);e.forEach(ye.points,function(ge){ge.x-=F,ge.y-=B}),e.has(ye,"x")&&(ye.x-=F),e.has(ye,"y")&&(ye.y-=B)}),Y.width=H-F+oe,Y.height=de-B+ce}function $(q){e.forEach(q.edges(),function(F){var H=q.edge(F),B=q.node(F.v),de=q.node(F.w),Y,oe;H.points?(Y=H.points[0],oe=H.points[H.points.length-1]):(H.points=[],Y=de,oe=B),H.points.unshift(h.intersectRect(B,Y)),H.points.push(h.intersectRect(de,oe))})}function N(q){e.forEach(q.edges(),function(F){var H=q.edge(F);if(e.has(H,"x"))switch((H.labelpos==="l"||H.labelpos==="r")&&(H.width-=H.labeloffset),H.labelpos){case"l":H.x-=H.width/2+H.labeloffset;break;case"r":H.x+=H.width/2+H.labeloffset;break}})}function M(q){e.forEach(q.edges(),function(F){var H=q.edge(F);H.reversed&&H.points.reverse()})}function J(q){e.forEach(q.nodes(),function(F){if(q.children(F).length){var H=q.node(F),B=q.node(H.borderTop),de=q.node(H.borderBottom),Y=q.node(e.last(H.borderLeft)),oe=q.node(e.last(H.borderRight));H.width=Math.abs(oe.x-Y.x),H.height=Math.abs(de.y-B.y),H.x=Y.x+H.width/2,H.y=B.y+H.height/2}}),e.forEach(q.nodes(),function(F){q.node(F).dummy==="border"&&q.removeNode(F)})}function ae(q){e.forEach(q.edges(),function(F){if(F.v===F.w){var H=q.node(F.v);H.selfEdges||(H.selfEdges=[]),H.selfEdges.push({e:F,label:q.edge(F)}),q.removeEdge(F)}})}function se(q){var F=h.buildLayerMatrix(q);e.forEach(F,function(H){var B=0;e.forEach(H,function(de,Y){var oe=q.node(de);oe.order=Y+B,e.forEach(oe.selfEdges,function(ce){h.addDummyNode(q,"selfedge",{width:ce.label.width,height:ce.label.height,rank:oe.rank,order:Y+ ++B,e:ce.e,label:ce.label},"_se")}),delete oe.selfEdges})})}function ee(q){e.forEach(q.nodes(),function(F){var H=q.node(F);if(H.dummy==="selfedge"){var B=q.node(H.e.v),de=B.x+B.width/2,Y=B.y,oe=H.x-de,ce=B.height/2;q.setEdge(H.e,H.label),q.removeNode(F),H.label.points=[{x:de+2*oe/3,y:Y-ce},{x:de+5*oe/6,y:Y-ce},{x:de+oe,y:Y},{x:de+5*oe/6,y:Y+ce},{x:de+2*oe/3,y:Y+ce}],H.label.x=H.x,H.label.y=H.y}})}function pe(q,F){return e.mapValues(e.pick(q,F),Number)}function me(q){var F={};return e.forEach(q,function(H,B){F[B.toLowerCase()]=H}),F}return Zl}var Xl,cm;function hj(){if(cm)return Xl;cm=1;var e=ct(),r=At(),t=Vt().Graph;Xl={debugOrdering:n};function n(i){var o=r.buildLayerMatrix(i),s=new t({compound:!0,multigraph:!0}).setGraph({});return e.forEach(i.nodes(),function(a){s.setNode(a,{label:a}),s.setParent(a,"layer"+i.node(a).rank)}),e.forEach(i.edges(),function(a){s.setEdge(a.v,a.w,{},a.name)}),e.forEach(o,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 Xl}var Yl,lm;function pj(){return lm||(lm=1,Yl="0.8.5"),Yl}var Ql,dm;function gj(){return dm||(dm=1,Ql={graphlib:Vt(),layout:fj(),debug:hj(),util:{time:At().time,notime:At().notime},version:pj()}),Ql}var yj=gj();const um=e1(yj);function mj(e,r,t){var d;const n=new Set(e.map(u=>u.id)),i=new Set;for(const u of e)u.parent&&n.has(u.parent)&&i.add(u.parent);const o=new um.graphlib.Graph({multigraph:!0,compound:!0}),s=t.compactSpacingScale??(t.spacingFactor>0?t.spacingFactor/1.3:1);o.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"}),o.setDefaultEdgeLabel(()=>({})),o.setDefaultNodeLabel(()=>({}));for(const u of e)o.setNode(u.id,{width:u.width+2,height:u.height+2});for(const u of e)u.parent&&n.has(u.parent)&&o.setParent(u.id,u.parent);for(const u of r){if(!n.has(u.source)||!n.has(u.target)||i.has(u.source)||i.has(u.target))continue;const h=$b(u.label,u.icon??((d=u.data)==null?void 0:d.icon),t.edgeLabelFontSize),p=t.rankDir==="LR"||t.rankDir==="RL",y=(h.width?h.width+2*Nb:0)+(u.connectorClearance??0);o.setEdge(u.source,u.target,{minlen:1,weight:1,...y?{width:p?y:Math.max(1,h.height),height:p?Math.max(1,h.height):y,labelpos:"c"}:{}},u.id)}um.layout(o);const a=new Map;for(const u of e){if(i.has(u.id))continue;const h=o.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,y=-1/0;a.forEach(b=>{u=Math.min(u,b.x),h=Math.min(h,b.y),p=Math.max(p,b.x),y=Math.max(y,b.y)});const m=(u+p)/2,g=(h+y)/2;a.forEach((b,v)=>a.set(v,{x:m+(b.x-m)*c,y:g+(b.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",y=t.rankDir==="RL"||t.rankDir==="BT"?-1:1,m=l==="leading"?-y:y,g=new Map;for(const b of e){const v=a.get(b.id);if(!v)continue;const x=v[h];g.set(x,Math.max(g.get(x)??0,b[p]))}for(const b of e){const v=a.get(b.id);if(!v)continue;const x=v[h],w=(g.get(x)-b[p])/2;a.set(b.id,{...v,[h]:x+m*w})}}return a}function dd(e,r,t,n,i,o){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 y;const p=(y=a.get(u))==null?void 0:y.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=o==null?void 0:o.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 y=null;for(const b of s.get(u)||[]){let v=d.get(b);if(!v){const x=r.get(b);if(!x)continue;const w=t.get(b)||{w:60,h:60};v={x1:x.x-w.w/2,y1:x.y-w.h/2,x2:x.x+w.w/2,y2:x.y+w.h/2}}y=y?{x1:Math.min(y.x1,v.x1),y1:Math.min(y.y1,v.y1),x2:Math.max(y.x2,v.x2),y2:Math.max(y.y2,v.y2)}:{...v}}if(!y)continue;const m=n(u);y={x1:y.x1-m,y1:y.y1-m,x2:y.x2+m,y2:y.y2+m};const g=i(u);if(g){const b=y.x2-y.x1,v=y.y2-y.y1;if(g.w>b){const x=(g.w-b)/2;y.x1-=x,y.x2+=x}if(g.h>v){const x=(g.h-v)/2;y.y1-=x,y.y2+=x}}d.set(u,y)}return d}function fm(e,r,t){var c,l,d;const n=[...r.weights],i=n.reduce((u,h)=>u+h,0),o=n[r.index]+n[r.index+1],s=Math.min(o*.95,Math.max(o*.05,n[r.index]+t/r.length*i));n[r.index]=s,n[r.index+1]=o-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 Lv(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)))throw new RangeError("Invalid grid section proportions.")}function Xd(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 Eo(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=[],i=new Map,o=a=>{const c=t.get(a),l=c?c.flatMap(o):e.positions.has(a)?[a]:[];return i.set(a,l),c&&n.push(c),l},s=t.get(void 0)??[];return s.forEach(o),n.push(s),{groups:n,leaves:i,children:t,roots:s}}function _r(e,r,t=e.fixedSizes){const n=dd(e.nodes,r,e.sizes,e.padding,e.minSize,t);for(const i of e.nodes){if(n.has(i.id))continue;const o=r.get(i.id),s=e.sizes.get(i.id);o&&s&&n.set(i.id,Yt({...o,...s}))}return n}function Fv(e,r,t,n){const i=t.get(e),o=t.get(r);if(!i||!o)return;const s={x:Math.min(i.x2-o.x1,o.x2-i.x1)+n,y:Math.min(i.y2-o.y1,o.y2-i.y1)+n};if(s.x>.001&&s.y>.001)return{source:e,target:r,overlap:s}}function kn(e,r,t){const n=[];for(const i of e)for(let o=0;o<i.length;o++)for(let s=o+1;s<i.length;s++){const a=Fv(i[o],i[s],r,t);a&&n.push(a)}return n}function zv(e,r={}){const t=Xd(r),{groups:n}=Eo(e);return kn(n,_r(e,e.positions),t)}function ed(e,r={}){Lv(r.adjustment);const t=Xd(r),n=typeof r.gaps=="object"?r.gaps:{x:r.gaps??t,y:r.gaps??t};if(!n||[n.x,n.y].some(d=>!Number.isFinite(d)||d<0))throw new RangeError("Grid gaps must be finite and non-negative.");const i=r.padding??0;if(!Number.isFinite(i)||i<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 bj(e,r,n,i);const{groups:o,leaves:s}=Eo(e),a=new Map([...e.positions].map(([d,u])=>[d,{...u}])),c=new Set;for(const d of o){const u=_r(e,a),h=d.filter(k=>u.has(k));if(h.length<2)continue;if(h.some(k=>e.fixedIds.has(k)||(s.get(k)??[]).some(E=>e.fixedIds.has(E)))){h.forEach(k=>c.add(k));continue}const y=h.map(k=>u.get(k)),m=Math.max(...y.map(k=>k.x2-k.x1)),g=Math.max(...y.map(k=>k.y2-k.y1)),b=Math.min(h.length,r.columns??Math.ceil(Math.sqrt(h.length))),v=Math.ceil(h.length/b),x=m+n.x,w=g+n.y,C=y.map(k=>({x:(k.x1+k.x2)/2,y:(k.y1+k.y2)/2})),j=(Math.min(...C.map(k=>k.x))+Math.max(...C.map(k=>k.x)))/2,_=(Math.min(...C.map(k=>k.y))+Math.max(...C.map(k=>k.y)))/2;h.forEach((k,E)=>{const O=u.get(k),T={x:j+(E%b-(b-1)/2)*x-(O.x1+O.x2)/2,y:_+(Math.floor(E/b)-(v-1)/2)*w-(O.y1+O.y2)/2};for(const P of s.get(k)??[]){const I=a.get(P);a.set(P,{x:I.x+T.x,y:I.y+T.y})}})}const l=[...a].filter(([d,u])=>{const h=e.positions.get(d);return u.x!==h.x||u.y!==h.y}).map(([d])=>d);return{positions:a,movedNodeIds:l,skippedNodeIds:[...c],collisions:kn(o,_r(e,a),Math.min(n.x,n.y))}}function bj(e,r,t,n){const{groups:i,children:o,roots:s}=Eo(e),a=new Map([...e.positions].map(([g,b])=>[g,{...b}]));if(e.nodes.some(g=>e.fixedIds.has(g.id)))return{positions:a,movedNodeIds:[],skippedNodeIds:e.nodes.map(g=>g.id),collisions:zv(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=[],y=(g,b,v="canvas")=>{var I,R;if(!g.length)return;const x=b.x2-b.x1,w=b.y2-b.y1,C=Math.min(g.length,r.columns??Math.max(1,Math.round(Math.sqrt(g.length*x/w)))),j=Math.ceil(g.length/C),_=Math.min(t.y,w/(2*j)),k=(R=(I=r.adjustment)==null?void 0:I.sections)==null?void 0:R[v],E=Array.from({length:j},($,N)=>{var M;return((M=k==null?void 0:k.rows)==null?void 0:M[N])??1}),O=E.reduce(($,N)=>$+N,0),T=w-(j-1)*_;let P=b.y1;for(let $=0;$<j;$++){const N=T*E[$]/O,M=Math.min(C,g.length-$*C),J=Math.min(t.x,x/(2*M)),ae=Array.from({length:M},(me,q)=>{var F,H;return((H=(F=k==null?void 0:k.columns)==null?void 0:F[$])==null?void 0:H[q])??1}),se=ae.reduce((me,q)=>me+q,0),ee=x-(M-1)*J;let pe=b.x1;for(let me=0;me<M;me++){const q=g[$*C+me],F=ee*ae[me]/se,H=o.get(q);if(H){a.set(q,{x:pe+F/2,y:P+N/2}),h.set(q,{w:F,h:N});const B=Math.min(e.padding(q),Math.max(0,(Math.min(F,N)-1)/2));y(H,{x1:pe+B,y1:P+B,x2:pe+F-B,y2:P+N-B},q)}else a.has(q)&&(a.set(q,{x:pe+F/2,y:P+N/2}),h.set(q,{w:F,h:N}));me<M-1&&p.push({section:v,axis:"x",row:$,index:me,weights:ae,length:ee,position:{x:pe+F+J/2,y:P+N/2}}),pe+=F+J}$<j-1&&p.push({section:v,axis:"y",row:$,index:$,weights:E,length:T,position:{x:b.x1+x/2,y:P+N+_/2}}),P+=N+_}};y(s,u);const m=[...a].filter(([g,b])=>{const v=e.positions.get(g);return!v||b.x!==v.x||b.y!==v.y}).map(([g])=>g);return{positions:a,movedNodeIds:m,skippedNodeIds:[],bounds:u,sizes:h,dividers:p,collisions:kn(i,_r({...e,sizes:h},a,h),0)}}function vj(e,r={}){const t=Xd(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:i,leaves:o}=Eo(e),s=new Map([...e.positions].map(([u,h])=>[u,{...h}])),a=u=>e.fixedIds.has(u)||(o.get(u)??[]).some(h=>e.fixedIds.has(h));let c=kn(i,_r(e,s),t),l=0;for(;c.length&&l<n;){let u=!1;for(const h of i){if(h.length<2)continue;const p=_r(e,s),y=(m,g,b)=>{for(const x of o.get(m)??[])s.get(x)[g]+=b;const v=p.get(m);g==="x"?(v.x1+=b,v.x2+=b):(v.y1+=b,v.y2+=b)};for(let m=0;m<h.length;m++)for(let g=m+1;g<h.length;g++){const b=h[m],v=h[g],x=Fv(b,v,p,t);if(!x)continue;const w=a(b),C=a(v);if(w&&C)continue;const j=x.overlap.x<=x.overlap.y?"x":"y",_=p.get(b),k=p.get(v),E=j==="x"?_.x1+_.x2<=k.x1+k.x2?-1:1:_.y1+_.y2<=k.y1+k.y2?-1:1,O=x.overlap[j];w||y(b,j,E*O/(C?1:2)),C||y(v,j,-E*O/(w?1:2)),u=!0}}if(l++,c=kn(i,_r(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 xj({dividers:e,options:r,zoom:t,onChange:n}){const i=S.useRef();return f.jsx(f.Fragment,{children:e.map(o=>{const s=o.axis==="x",a=s?Z.PiArrowsHorizontal:Z.PiArrowsVertical,c=`${s?"Column":"Row"} divider ${o.index+1}${s?` in row ${o.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*o.weights[o.index]/(o.weights[o.index]+o.weights[o.index+1])),title:c,"data-flow-grid-adjustment":"",style:{position:"absolute",left:o.position.x,top:o.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();i.current={pointerId:l.pointerId,start:s?l.clientX:l.clientY,scale:t*(s?u.width/d.clientWidth:u.height/d.clientHeight),divider:o,options:r},l.currentTarget.setPointerCapture(l.pointerId)},onPointerMove:l=>{const d=i.current;if(!d||d.pointerId!==l.pointerId)return;l.preventDefault(),l.stopPropagation();const u=((s?l.clientX:l.clientY)-d.start)/d.scale;n(fm(d.options,d.divider,u))},onPointerUp:l=>{i.current&&(l.stopPropagation(),i.current=void 0,l.currentTarget.releasePointerCapture(l.pointerId))},onPointerCancel:()=>{i.current&&n(i.current.options),i.current=void 0},onLostPointerCapture:()=>{i.current=void 0},onClick:l=>l.stopPropagation(),onKeyDown:l=>{l.key==="Escape"&&i.current&&(n(i.current.options),i.current=void 0);const d=(s?["ArrowLeft","ArrowRight"]:["ArrowUp","ArrowDown"]).indexOf(l.key);d<0||(l.preventDefault(),l.stopPropagation(),n(fm(r,o,o.length*(l.shiftKey?.1:.02)*(d===0?-1:1))))},children:f.jsx(a,{size:20,"aria-hidden":"true"})},`${o.section}:${o.axis}:${o.row}:${o.index}`)})})}const hm=(e,r)=>e.left<r.right&&e.right>r.left&&e.top<r.bottom&&e.bottom>r.top;function wj(e){const r=e.querySelector(".flow-sdk-labels"),t=r==null?void 0:r.getScreenCTM();if(!r||!t)return;const n=t.inverse(),i=(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}},o=[...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=>i(l,24));for(const l of r.querySelectorAll(".flow-sdk-container-label"))o.push(i(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,i(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=_=>o.some(k=>hm(_,k))||[...a.values()].some(k=>hm(_,k));if(!d&&!h(u)){a.set(l,u);continue}const p=c.get(l.dataset.edgeId),y=l.querySelector("rect");if(!p||!y)continue;const m=y.getBBox(),g=p.getTotalLength();if(!Number.isFinite(g)||g<=0)continue;const b=(u.left+u.right)/2,v=(u.top+u.bottom)/2,x=Math.min(256,Math.max(16,Math.ceil(g/24))),w=Array.from({length:x+1},(_,k)=>p.getPointAtLength(g*k/x)),j=Array.from({length:x+1},(_,k)=>{const E=g*k/x,O=w[k],T=d?{x:O.x,y:O.y-m.height/2-15}:O,P=p.getPointAtLength(Math.max(0,E-2)),I=p.getPointAtLength(Math.min(g,E+2));let R=Math.atan2(I.y-P.y,I.x-P.x)*180/Math.PI;R>90&&(R-=180),R<-90&&(R+=180);const $=Math.abs(R)<1;d&&(R=0);const N=R*Math.PI/180,M=Math.abs(Math.cos(N))*m.width+Math.abs(Math.sin(N))*m.height,J=Math.abs(Math.sin(N))*m.width+Math.abs(Math.cos(N))*m.height;return{point:T,angle:R,straight:$,score:Math.hypot(T.x-b,T.y-v),bounds:{left:T.x-M/2-8,right:T.x+M/2+8,top:T.y-J/2-8,bottom:T.y+J/2+8}}}).sort((_,k)=>_.score-k.score).find(_=>!h(_.bounds)&&(!d||_.straight&&!w.some(k=>k.x>_.bounds.left&&k.x<_.bounds.right&&k.y>_.bounds.top&&k.y<_.bounds.bottom)));j?(l.setAttribute("transform",`translate(${j.point.x} ${j.point.y}) rotate(${j.angle})`),a.set(l,j.bounds)):a.set(l,u)}}function Cj(e){const r=e.getBoundingClientRect(),t=r.height/e.offsetHeight;if(!Number.isFinite(t)||t<=0)return[];const n=Tb(e),i={x:e.offsetWidth/2,y:e.offsetHeight/2,w:e.offsetWidth,h:e.offsetHeight},o=[...e.querySelectorAll("[data-flow-property]")],s=new Set(o.filter(a=>a.hasAttribute("data-flow-inspection-row")&&a.getBoundingClientRect().height>0).map(a=>a.dataset.flowProperty));return o.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=Pb(n?wn(i,n):i,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 Sj({id:e,x:r,y:t,placed:n,hidden:i,gridDraggable:o,gridDragging:s,gridDropTarget:a,gridSize:c,gridPreview:l,onMount:d,drawHandles:u,drawMode:h,connectedPorts:p,resolvedRows:y,hasCollapseControl:m,handleColor:g,animated:b,animationColor:v,animationWidth:x=8,animationVariant:w,width:C=0,height:j=0,propertyMode:_,reversePorts:k,direction:E="LR",onPropertyRows:O,onSurface:T,children:P}){var B,de;const I=S.useRef(null),[R,$]=S.useState([]),N=y??R,[M,J]=S.useState(),ae=S.useId(),se=S.useRef(),ee=!!l,pe=!!(l!=null&&l.floating);S.useLayoutEffect(()=>{var je;const Y=I.current;if(!Y||!ee)return;const oe=Y.cloneNode(!0);oe.removeAttribute("data-node-id"),oe.removeAttribute("data-grid-dragging"),oe.removeAttribute("data-grid-draggable"),oe.removeAttribute("data-grid-drop-target"),oe.setAttribute("data-grid-preview",e),oe.setAttribute("aria-hidden","true"),oe.setAttribute("inert","");const ce=[oe,...oe.querySelectorAll("*")],xe=new Map(ce.filter(ye=>ye.id).map(ye=>[ye.id,`${ye.id}-${ae}`]));for(const ye of ce){ye.id&&(ye.id=xe.get(ye.id));for(const ge of[...ye.attributes]){if(ge.name==="id")continue;let z=ge.value;for(const[W,ie]of xe)z===`#${W}`&&(z=`#${ie}`),z=z.split(`url(#${W})`).join(`url(#${ie})`);z!==ge.value&&ye.setAttribute(ge.name,z)}}if(Object.assign(oe.style,{opacity:"0.35",zIndex:pe?"2147483647":"11",pointerEvents:"none",outline:"none",visibility:"visible"}),pe){const ye=getComputedStyle(Y);oe.setAttribute("data-grid-preview-floating",""),Object.assign(oe.style,{position:"fixed",left:"0",top:"0",transformOrigin:"top left",font:ye.font,color:ye.color});for(const ge of ce)ge.removeAttribute("data-node-id"),ge.style.pointerEvents="none"}return oe.querySelectorAll(".flow-sdk-node-animation, .flow-sdk-handle, .flow-sdk-property-port, [data-flow-collapse-control]").forEach(ye=>ye.remove()),(je=pe?document.body:Y.parentElement)==null||je.appendChild(oe),se.current=oe,()=>{oe.remove(),se.current=void 0}},[e,ae,ee,pe]),S.useLayoutEffect(()=>{const Y=se.current;if(!Y||!l)return;const{x:oe,y:ce,size:xe}=l;if(pe&&I.current){const ge=I.current,z=ge.getBoundingClientRect(),W=z.width/ge.offsetWidth||1,ie=z.height/ge.offsetHeight||1,K=z.left+(oe-r)*W,ue=z.top+(ce-t)*ie;Y.style.transform=`translate3d(${K}px, ${ue}px, 0) scale(${W}, ${ie})`,Y.style.width=`${ge.offsetWidth}px`,Y.style.height=`${ge.offsetHeight}px`;return}const je=xe?Math.round(oe-xe.w/2):oe,ye=xe?Math.round(ce-xe.h/2):ce;Y.style.transform=xe?`translate3d(${je}px, ${ye}px, 0)`:`translate(-50%, -50%) translate3d(${je}px, ${ye}px, 0)`,Y.style.width=xe?`${Math.round(oe+xe.w/2)-je}px`:"",Y.style.height=xe?`${Math.round(ce+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,(de=l==null?void 0:l.size)==null?void 0:de.h,pe,r,t]),S.useLayoutEffect(()=>{const Y=I.current;if(!Y)return;const oe=()=>{const je=Tb(Y);J(ye=>JSON.stringify(ye)===JSON.stringify(je)?ye:je),T==null||T(e,je)};oe();const ce=new ResizeObserver(oe);ce.observe(Y);const xe=Y.querySelector("[data-flow-node-surface]");return xe&&ce.observe(xe),()=>ce.disconnect()},[e,P,T]),S.useLayoutEffect(()=>(d(e,I.current),()=>{d(e,null),T==null||T(e,void 0)}),[e,d,T]),S.useLayoutEffect(()=>{const Y=I.current;if(!Y)return;let oe="";const ce=()=>{const ge=Cj(Y),z=_?ge:ge.filter(ie=>ie.anchor),W=JSON.stringify(z);W!==oe&&(oe=W,$(z),O==null||O(e,z))};if(ce(),!_&&!Y.querySelector("[data-flow-port-side]"))return;const xe=new ResizeObserver(ce),je=()=>{xe.disconnect(),xe.observe(Y),Y.querySelectorAll("[data-flow-property]").forEach(ge=>xe.observe(ge)),ce()};je();const ye=new MutationObserver(je);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",ce,!0),()=>{xe.disconnect(),ye.disconnect(),Y.removeEventListener("scroll",ce,!0)}},[e,_,O,P]);const me=c?Math.round(r-c.w/2):0,q=c?Math.round(t-c.h/2):0,F=c?Math.round(r+c.w/2)-me:void 0,H=c?Math.round(t+c.h/2)-q:void 0;return f.jsxs("div",{ref:I,className:"flow-sdk-node","data-node-id":e,"data-grid-draggable":o||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, ${q}px, 0)`:`translate(-50%, -50%) translate3d(${r.toFixed(2)}px, ${t.toFixed(2)}px, 0)`,visibility:n&&!i?void 0:"hidden",cursor:o?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:F,height:H,...c?{"--flow-grid-width":`${c.w}px`,"--flow-grid-height":`${c.h}px`,"--flow-grid-font":`${Math.max(12,Math.min(48,c.w/8,c.h/5))}px`}:{}},children:[P,!c&&b&&x>0&&C>0&&j>0&&f.jsx("svg",{className:"flow-sdk-node-animation","aria-hidden":"true",pointerEvents:"none",children:f.jsx(Zn,{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)??j)-x,radius:((M==null?void 0:M.radius)??0)-x/2,path:M!=null&&M.outline?`M${M.outline.map(Y=>`${Y.x} ${Y.y}`).join(" L")} Z`:void 0,color:v||g||"currentColor",strokeWidth:x})}),u&&_&&N.map(Y=>["source","target"].filter(oe=>!Y.role||Y.role===oe).filter(oe=>h||(p==null?void 0:p.has(`${oe}:${Y.property}`))).map(oe=>{var ce;return f.jsx("button",{type:"button",className:"flow-sdk-property-port","data-property":Y.property,"data-port-role":oe,"data-port-side":(ce=Y.anchor)==null?void 0:ce.side,"aria-label":`${oe==="source"?"Connect":"Input"} ${Y.property}`,title:`${oe==="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,[oe==="source"!=!!k?"right":"left"]:-16}},onClick:xe=>xe.stopPropagation()},`${Y.property}:${oe}`)})),u&&!m&&(!_||!N.length)&&(!_||!N.some(Y=>Y.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)??j:((M==null?void 0:M.height)??j)/2),transform:E==="BT"||E==="TB"?"translateX(-50%)":"translateY(-50%)"},onClick:Y=>Y.stopPropagation(),children:f.jsx(Z.PiPlusBold,{size:24})})]})}const jj=S.memo(Sj);function _j(e,r,t){const[n,i]=S.useState(()=>({nodes:new Set,edges:new Set})),o=S.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(m=>m.target===p.id&&m.source!==m.target).every(m=>u.has(m.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(y=>!d.has(y.id));p&&d.add(p.id),h=new Set(c.filter(y=>d.has(y.source)).map(y=>y.id))}return{nodes:d,edges:u,ready:h}},[e,r,t,n]);S.useLayoutEffect(()=>{i(a=>{const c=t?o:{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}})},[o,t]);const s=S.useCallback(a=>{i(c=>c.edges.has(a)?c:{...c,edges:new Set([...c.edges,a])})},[]);return{shown:o.nodes,ready:o.ready,complete:s}}class Ej{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,i={pan:{...r.pan},zoom:this.clamp(r.zoom)},o=this.animationVersion,s=kb(t,this.animationsDisabled),a=c=>{if(o!==this.animationVersion)return;const l=s?c:1;this.apply({x:n.pan.x+(i.pan.x-n.pan.x)*l,y:n.pan.y+(i.pan.y-n.pan.y)*l},n.zoom+(i.zoom-n.zoom)*l)};this.finishTransition=()=>a(1),this.captureTransition?this.captureTransition(a):this.cancelTransition=Ab(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 i=this.clamp(t);i!==this._zoom&&(this._zoom=i,n=!0)}n&&this.emit()}zoomAt(r,t){const n=this.clamp(r),i=this._zoom;if(n===i)return;const o=n/i;this.set({x:t.x-(t.x-this._pan.x)*o,y:t.y-(t.y-this._pan.y)*o},n)}fit(r,t=0,n=!1,i=1){const o=r.x2-r.x1,s=r.y2-r.y1;if(!(o>0)||!(s>0)||!this.size.w||!this.size.h)return;const a=this.clamp(this.clamp(Math.min((this.size.w-2*t)/o,(this.size.h-2*t)/s))*i);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 Rj={LR:"rightward",RL:"leftward",TB:"downward",BT:"upward"},Gn={w:60,h:60},td=4,kj=30,Aj=500,Pj=45;function pm(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 Ij(e){var su,cu,lu,du,uu;const{nodes:r,edges:t,direction:n,nodeAlignment:i="center",edgeMode:o="auto",compactPropertyLayout:s=!1,rankSep:a,edgeSep:c,spacingFactor:l=1.3,compactSpacingScale:d,minZoom:u,maxZoom:h,initialViewport:p,containerStyle:y,lineColor:m,drawMode:g,dragMode:b,multiSelect:v,isPerformanceMode:x,disableAnimations:w=!1}=e,[C,j]=S.useState(null),_=S.useMemo(()=>C?(C.mode==="connections"?Bu:Nu)(C.id,r,t):null,[C,r,t]),k=o==="auto"||o==="properties",E=S.useMemo(()=>t.filter(A=>ld(A,o)&&(!_||_.has(A.source)&&_.has(A.target))),[t,o,_]),O=S.useMemo(()=>Jw(r,t,o,s,_),[r,t,o,s,_]),T=S.useRef(O);T.current=O;const P=S.useRef(e);P.current=e;const I=S.useRef(null),R=S.useRef(null),$=S.useRef(null),N=S.useRef(null),M=S.useMemo(()=>new Ej(p,u,h),[]);S.useEffect(()=>{M.minZoom=u,M.maxZoom=h},[M,u,h]),S.useLayoutEffect(()=>{M.setAnimationsDisabled(w)},[M,w]);const J=S.useRef(new Map),ae=S.useRef(new Map),se=S.useRef(new Map),ee=S.useRef(null),[pe,me]=S.useState(new Map),q=S.useCallback((A,L)=>{me(D=>{if(JSON.stringify(D.get(A))===JSON.stringify(L))return D;const X=new Map(D);return L?X.set(A,L):X.delete(A),X})},[]),[F,H]=S.useState(new Map),B=S.useRef(F),de=S.useCallback((A,L)=>{H(D=>{if(JSON.stringify(D.get(A)??[])===JSON.stringify(L))return D;const X=new Map(D);return L.length?X.set(A,L):X.delete(A),X})},[]),[Y,oe]=S.useState(()=>new Map),ce=S.useRef(Y);ce.current=Y;const[xe,je]=S.useState(new Map),ye=S.useRef(xe),ge=()=>{ye.current=new Map,je(ye.current)},z=S.useRef(new Map),W=S.useRef(null),ie=S.useRef(!1),[K,ue]=S.useState(0),ve=S.useRef(),Oe=S.useRef(),$e=S.useRef(null),De=S.useRef(!1),tt=S.useRef(null),Ue=S.useRef(null),yt=S.useRef(l),Je=s,nt=S.useRef(Je),[ht,Ie]=S.useState(!0),[ze,at]=S.useState(!!((su=e.initialNodeGrid)!=null&&su.enabled)),[st,zt]=S.useState([]),Ve=S.useRef((cu=e.initialNodeGrid)!=null&&cu.enabled?{options:{...e.initialNodeGrid.options,animate:!1},order:[...e.initialNodeGrid.order??e.initialNodeGrid.options.order??r.map(A=>A.id)],previousPositions:new Map,previousViewport:p,previousSize:{w:0,h:0},ready:!1}:null),[Ye,Wt]=S.useState(null),lt=S.useRef(null);lt.current=_;const rr=S.useRef(1);rr.current=(C==null?void 0:C.mode)==="connections"?1.25:1;const Ut=S.useRef(null),Ir=S.useRef(r),Rt=S.useRef([]),Ht=S.useRef(!1),Xt=()=>{var A;(A=$e.current)==null||A.call($e),$e.current=null},Mr=()=>{Ue.current=null,Rt.current.length&&(Ht.current=!0),!ie.current&&P.current.fitOnInit!==!1&&(De.current=!0),clearTimeout(Oe.current),Oe.current=setTimeout(()=>{ie.current=ce.current.size>0,ue(A=>A+1)},Aj)},yr=(A,L,D,X=Mr,le)=>{Xt();const ke=new Map(ce.current),Ce=new Map([...J.current,...ye.current]);$e.current=Ab(L,Re=>{const Le=new Map;if(A.forEach((_e,Fe)=>{const Xe=ke.get(Fe);Le.set(Fe,Xe?{x:Xe.x+(_e.x-Xe.x)*Re,y:Xe.y+(_e.y-Xe.y)*Re}:_e)}),ce.current=Le,oe(Le),le){const _e=new Map;for(const[Fe,Xe]of le){const re=Ce.get(Fe)??Xe;_e.set(Fe,{w:re.w+(Xe.w-re.w)*Re,h:re.h+(Xe.h-re.h)*Re})}ye.current=_e,je(_e)}D==null||D(Re)},X)},qe=()=>{if(clearTimeout(ve.current),Ve.current){bt.arrangeNodesInGrid(Ve.current.options);return}ye.current.size&&ge();const A=P.current,L=rr.current,D=T.current,X=D.nodes.map(Le=>{const _e=ae.current.get(Le.id);_e&&(_e.offsetWidth||_e.offsetHeight)&&J.current.set(Le.id,{w:_e.offsetWidth,h:_e.offsetHeight});const Fe=J.current.get(Le.id)||Gn;return{id:Le.id,parent:Le.parent,width:Fe.w,height:Fe.h}});let le;try{const Le=A.compactPropertyLayout,_e=A.edgeMode!=="nodes"&&A.edgeMode!=="workflow",Fe=D.edges.map(Xe=>({...Xe,connectorClearance:Le?_e&&(Xe.sourceProperty!==void 0||Xe.targetProperty!==void 0)?Kw:Hw:0}));le=mj(X,Fe,{edgeLabelFontSize:A.edgeMode==="nodes"||A.edgeMode==="workflow"?Ob:Xn,rankDir:A.direction,compact:Le,nodeAlignment:A.nodeAlignment,rankSep:A.rankSep*L,edgeSep:A.edgeSep*L,nodeSep:5*L,spacingFactor:A.spacingFactor??1.3,compactSpacingScale:(A.compactSpacingScale??(A.spacingFactor??1.3)/1.3)*L})}catch(Le){console.warn("[flow-sdk] layout failed",Le);return}const ke=W.current;W.current=null;const Ce=ke&&le.get(ke.id);if(ke&&Ce){const Le={x:ke.position.x-Ce.x,y:ke.position.y-Ce.y};le=new Map([...le].map(([_e,Fe])=>[_e,{x:Fe.x+Le.x,y:Fe.y+Le.y}]))}for(const[Le,_e]of z.current)le.has(Le)?le.set(Le,_e):A.nodes.some(Fe=>Fe.id===Le)||z.current.delete(Le);const Re=M.coordinate(()=>{var Le;return(Le=Ue.current)==null?void 0:Le.call(Ue,le)});yr(le,ie.current&&!A.isPerformanceMode&&!A.disableAnimations,Re)},te=S.useCallback(()=>{clearTimeout(Oe.current),clearTimeout(ve.current),ve.current=setTimeout(qe,P.current.layoutDebounce)},[]);S.useLayoutEffect(()=>{const A=new Map(Ir.current.map(L=>[L.id,L]));r.some(L=>{var D;return((D=A.get(L.id))==null?void 0:D.collapsed)===!0&&!L.collapsed})&&(Rt.current=r.filter(L=>!A.has(L.id)).map(L=>L.id)),Ir.current=r,yt.current!==l&&ce.current.size>0&&(ie.current=!0,De.current=!1,clearTimeout(Oe.current)),yt.current=l,nt.current!==Je&&(De.current=!tt.current),nt.current=Je,Ue.current&&!tt.current?(clearTimeout(ve.current),qe()):te()},[r,t,O.nodes,O.edges,Je,n,i,a,c,te,l,d,w,e.nodeGridSpacing]),S.useEffect(()=>()=>{clearTimeout(ve.current),clearTimeout(Oe.current),Xt()},[]);const G=S.useCallback((A,L)=>{var D,X;if(!ee.current&&typeof ResizeObserver<"u"&&(ee.current=new ResizeObserver(le=>{let ke=!1;for(const Ce of le){const Re=se.current.get(Ce.target);if(!Re||ye.current.has(Re))continue;const Le=Ce.target,_e=Le.offsetWidth,Fe=Le.offsetHeight;if(!_e&&!Fe)continue;const Xe=J.current.get(Re);if(Xe&&Xe.w===_e&&Xe.h===Fe)continue;const re=ce.current.get(Re);Xe&&re&&ie.current&&!W.current&&(W.current={id:Re,position:{...re}}),J.current.set(Re,{w:_e,h:Fe}),ke=!0}ke&&(Ue.current&&!tt.current?qe():te())})),L){ae.current.set(A,L),se.current.set(L,A),(D=ee.current)==null||D.observe(L);const le=L.offsetWidth,ke=L.offsetHeight;!ye.current.has(A)&&(le||ke)&&J.current.set(A,{w:le,h:ke})}else{const le=ae.current.get(A);le&&((X=ee.current)==null||X.unobserve(le),se.current.delete(le)),ae.current.delete(A),J.current.delete(A),B.current.has(A)&&de(A,[])}te()},[te,de]);S.useEffect(()=>()=>{var A;return(A=ee.current)==null?void 0:A.disconnect()},[]);const ne=A=>{var X;const L=(X=P.current.nodes.find(le=>le.id===A))==null?void 0:X.label;if(!L)return;const D=P.current.containerStyle(A);return{w:so(L,`bold ${D.fontSize}px ${lr}`)+2*Pj,h:0}},Me=S.useMemo(()=>{const A=new Map;for(const L of r)L.label&&A.set(L.id,L.label);return A},[r]),U=S.useMemo(()=>dd(O.nodes,Y,new Map([...J.current,...xe]),A=>y(A).padding,ne,xe),[O.nodes,Y,y,Me,xe]),fe=S.useRef(U);fe.current=U;const we=S.useCallback(A=>{const L=fe.current.get(A);if(L)return Tw(L);const D=ce.current.get(A);if(!D)return;const X=ye.current.get(A)||J.current.get(A)||Gn;return{x:D.x,y:D.y,w:X.w,h:X.h}},[]),Se=S.useMemo(()=>{const A=new Map;for(const L of r){const D=we(L.id);D&&A.set(L.id,D)}return Dw(F,A,pe,t,n)},[F,r,Y,U,pe,t,n,we]);B.current=Se;const Ke=(A,L)=>{var le;if(!k||L===void 0)return;const D=(le=Se.get(A))==null?void 0:le.find(ke=>ke.property===L),X=we(A);return D&&!D.anchor&&X?X.y-X.h/2+D.top+D.height/2:void 0},Qe=(A,L)=>{var le,ke;if(L===void 0)return;const D=(ke=(le=Se.get(A))==null?void 0:le.find(Ce=>Ce.property===L))==null?void 0:ke.anchor,X=we(A);return D&&X?{x:X.x-X.w/2+D.x,y:X.y-X.h/2+D.y,side:D.side}:void 0},Ge=(A,L)=>{const D=we(A),X=pe.get(A);return D&&X&&!U.has(A)&&Ke(A,L)===void 0?wn(D,X):D},kt=()=>{const A=[];ce.current.forEach((L,D)=>{if(fe.current.has(D))return;const X=we(D);X&&A.push(Yt(X))}),fe.current.forEach(L=>A.push(L));try{for(const L of[R.current,$.current]){const D=L==null?void 0:L.getBBox();D&&D.width>0&&D.height>0&&A.push({x1:D.x,y1:D.y,x2:D.x+D.width,y2:D.y+D.height})}}catch{}return $o(A)},St=()=>{var D,X;const{pan:A,zoom:L}=M;N.current&&(N.current.style.transform=`translate3d(${A.x}px, ${A.y}px, 0) scale(${L})`),(D=R.current)==null||D.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`),(X=$.current)==null||X.setAttribute("transform",`translate(${A.x} ${A.y}) scale(${L})`)};S.useEffect(()=>{St();let A=null,L;const D=M.onChange(()=>{St();const X=I.current;X&&(X.classList.add("flow-sdk-busy"),clearTimeout(L),L=setTimeout(()=>X.classList.remove("flow-sdk-busy"),150)),A===null&&(A=requestAnimationFrame(()=>{var le,ke;A=null,(ke=(le=P.current).onViewportChange)==null||ke.call(le,M.state)}))});return()=>{D(),clearTimeout(L),A!==null&&cancelAnimationFrame(A)}},[]),S.useLayoutEffect(()=>{const A=I.current;if(!A)return;const L=()=>{var Ce;if(!A.getClientRects().length)return;let X=A.clientWidth,le=A.clientHeight;le||(le=Math.max(0,window.innerHeight-A.getBoundingClientRect().top-100),le&&(A.style.height=`${le}px`)),X||(X=window.innerWidth,X&&(A.style.width=`${X}px`));const ke=M.size.w!==X||M.size.h!==le;M.size={w:X,h:le},ke&&((Ce=Ve.current)!=null&&Ce.options.fill)&&te(),!ie.current&&!ce.current.size&&P.current.fitOnInit!==!1&&(M.set({x:X/2,y:le/2}),St())};if(L(),typeof ResizeObserver>"u")return;const D=new ResizeObserver(L);return D.observe(A),()=>D.disconnect()},[M]),S.useLayoutEffect(()=>{if(Ht.current){Ht.current=!1;const L=Rt.current.flatMap(X=>{const le=we(X);return le?[Yt(le)]:[]});Rt.current=[];const D=$o(L);if(D){De.current=!1,M.center(D,P.current.animateViewport);return}}if(!De.current)return;De.current=!1;const A=kt();A&&(M.fit(A,50,ie.current&&P.current.animateViewport),ie.current||St())},[Y]);const bt=S.useMemo(()=>{const A=re=>{const Q=P.current;if(Q.nodeGridSpacing!=="layout")return re;const be=Q.direction==="LR"||Q.direction==="RL";return{...re,gaps:{x:be?Q.rankSep:Q.edgeSep,y:be?Q.edgeSep:Q.rankSep}}},L=()=>{const re=P.current,Q=T.current.nodes.filter(be=>or(be.id,re.edges,re.edgeMode)&&(!lt.current||lt.current.has(be.id)));return{nodes:Q,positions:ce.current,sizes:new Map(Q.map(be=>[be.id,J.current.get(be.id)??Gn])),padding:be=>P.current.containerStyle(be).padding,minSize:ne,fixedIds:new Set(z.current.keys()),viewportSize:{...M.size}}},D=re=>Nu(re,P.current.nodes,P.current.edges),X=(re,Q=!0,be=()=>{},he,Ze,Ne=!1)=>{clearTimeout(ve.current),clearTimeout(Oe.current),Ne||(Ue.current=null),tt.current=null,De.current=!1,Rt.current=[],Ht.current=!1,M.cancelAnimation();const Ae=Q&&!P.current.isPerformanceMode&&!P.current.disableAnimations,dt=M.coordinate(()=>{var We;he?he(Ae):Ne&&((We=Ue.current)==null||We.call(Ue,re))});yr(new Map([...re].map(([We,pt])=>[We,{...pt}])),Ae,dt,be,Ze)},le=(re,Q=50,be=P.current.animateViewport,he=1,Ze=!1)=>{const Ne=Ae=>{const dt=T.current,We=re??new Set(dt.nodes.map(jt=>jt.id)),pt=new Set(dt.nodes.map(jt=>jt.parent).filter(Boolean));if(!Ae&&(!re||[...re].some(jt=>pt.has(jt))))return;const nr=Ae&&dd(dt.nodes,Ae,J.current,jt=>P.current.containerStyle(jt).padding,ne),nn=$o([...We].flatMap(jt=>{const fu=nr==null?void 0:nr.get(jt);if(fu)return[fu];const hu=Ae==null?void 0:Ae.get(jt),rx=J.current.get(jt)||Gn,pu=hu?{...hu,...rx}:we(jt);return pu?[Yt(pu)]:[]}));nn&&(De.current=!1,Rt.current=[],Ht.current=!1,M.fit(nn,Number.isFinite(Q)?Math.max(0,Q):50,be,he))};Ue.current=Ze?Ne:null,Ze||Ne(ce.current)},ke=(re,Q,be,he)=>{var Ne;if(!we(re))return;const Ze=Q==="connections"?Re(re):D(re);if(Q==="connections"&&rr.current===1.25&&((Ne=lt.current)==null?void 0:Ne.size)===Ze.size&&[...Ze].every(Ae=>lt.current.has(Ae))){j({id:re,mode:Q});return}Ut.current||(Ut.current={pan:{...M.pan},zoom:M.zoom}),lt.current=Ze,P.current.compactPropertyLayout&&(De.current=!1,tt.current=()=>le(lt.current??Ze,be,he)),j({id:re,mode:Q}),P.current.compactPropertyLayout||le(Ze,be,he)},Ce=re=>{tt.current?tt.current=re:re()},Re=re=>Bu(re,P.current.nodes,P.current.edges),Le=(re=>{var Q,be,he;if(re===void 0)return M.zoom;re<M.zoom&&((Q=Ve.current)!=null&&Q.options.fill)&&!P.current.readOnly&&((he=(be=P.current).onNodeGridZoomOut)==null?void 0:he.call(be,Ve.current.options))===!0||(Ue.current=null,M.set(void 0,re))}),_e=(re=>{if(re===void 0)return M.pan;Ue.current=null,M.set(re)}),Fe=(re,Q)=>{var he;const be=(he=I.current)==null?void 0:he.getBoundingClientRect();return{x:re-((be==null?void 0:be.left)??0),y:Q-((be==null?void 0:be.top)??0)}},Xe=(re=0,Q=P.current.animateViewport,be=!1)=>{if(be){le(void 0,re,Q,1,!0);return}Ue.current=null,Ce(()=>{const he=kt();he&&M.fit(he,re,Q)})};return{zoom:Le,pan:_e,setEdgesVisible:Ie,focusNode:(re,Q,be,he)=>Ce(()=>le(new Set([re]),Q,be,.6,he)),focusBranch:(re,Q,be)=>Ce(()=>le(D(re),Q,be)),focusConnections:(re,Q,be,he)=>Ce(()=>le(Re(re),Q,be,1,he)),isolateConnections:(re,Q,be)=>ke(re,"connections",Q,be),isolateBranch:(re,Q,be)=>ke(re,"branch",Q,be),restoreView:(re=P.current.animateViewport,Q)=>{Ue.current=null;const be=P.current.compactPropertyLayout&&!!lt.current;lt.current=null,j(null);const he=Q??Ut.current;Ut.current=null,be?tt.current=()=>{he&&M.transition(he,re)}:he&&Ce(()=>M.transition(he,re))},zoomAt:(re,Q)=>{var be,he,Ze;re<M.zoom&&((be=Ve.current)!=null&&be.options.fill)&&!P.current.readOnly&&((Ze=(he=P.current).onNodeGridZoomOut)==null?void 0:Ze.call(he,Ve.current.options))===!0||(Ue.current=null,M.zoomAt(re,Q))},fit:Xe,centerAndFit:Xe,center:(re=P.current.animateViewport)=>{Ue.current=null;const Q=kt();Q&&M.center(Q,re)},clientToModel:(re,Q)=>M.renderedToModel(Fe(re,Q)),modelToClient:re=>{var he;const Q=(he=I.current)==null?void 0:he.getBoundingClientRect(),be=M.modelToRendered(re);return{x:be.x+((Q==null?void 0:Q.left)??0),y:be.y+((Q==null?void 0:Q.top)??0)}},getNodeBox:re=>we(re),detectNodeCollisions:re=>{const Q=L();return zv({...Q,sizes:new Map([...Q.sizes,...ye.current]),fixedSizes:ye.current},re)},resolveNodeCollisions:(re={})=>{const Q=vj(L(),re);return Q.movedNodeIds.length&&X(Q.positions,re.animate),Q},arrangeNodesInGrid:(re={})=>{const Q=L(),be=Ve.current;if(be){Q.positions=new Map(Q.positions);for(const We of Q.nodes)Q.positions.has(We.id)||Q.positions.set(We.id,M.renderedToModel({x:M.size.w/2,y:M.size.h/2}));const Ne=new Set(Q.nodes.map(We=>We.id));be.order=be.order.filter(We=>Ne.has(We));const Ae=new Set(be.order);be.order.push(...Q.nodes.filter(We=>!Ae.has(We.id)).map(We=>We.id));const dt=new Map(be.order.map((We,pt)=>[We,pt]));Q.nodes=[...Q.nodes].sort((We,pt)=>dt.get(We.id)-dt.get(pt.id))}const he=ed(Q,A(re));zt(he.dividers??[]),be&&(be.ready=!1);const Ze=()=>{be&&(be.ready=!0),be&&Q.nodes.length&&!ie.current&&(ie.current=!0,P.current.fitOnInit!==!1&&!re.fill?bt.centerAndFit(50,!1):P.current.fitOnInit===!1&&M.transition(p,!1)),ue(Ne=>Ne+1)};return!he.sizes&&ye.current.size&&ge(),Q.nodes.some(Ne=>!ce.current.has(Ne.id))||he.movedNodeIds.length||he.bounds||Ue.current?X(he.positions,re.animate,Ze,he.bounds&&(!be||!ye.current.size)?()=>M.transition({zoom:1,pan:{x:0,y:0}},!1):void 0,he.sizes,!!be&&!he.bounds):Ze(),he},setNodeGridMode:(re,Q={})=>{var be,he,Ze,Ne;if(Q.order&&(!Array.isArray(Q.order)||Q.order.some(Ae=>typeof Ae!="string")||new Set(Q.order).size!==Q.order.length))throw new Error("Invalid grid node order.");if(re){ed(L(),A(Q));const Ae=!Ve.current||Ve.current.options.fill&&!Q.fill;Ue.current=null,Ve.current||(Ve.current={options:Q,order:L().nodes.map(dt=>dt.id),previousPositions:new Map([...ce.current].map(([dt,We])=>[dt,{...We}])),previousViewport:{zoom:M.zoom,pan:{...M.pan}},previousSize:{...M.size},ready:!1}),Ae&&bt.centerAndFit(80,Q.animate,!0),Q.order&&(Ve.current.order=[...Q.order]),Ve.current.options={...Q},at(!0),bt.arrangeNodesInGrid(Q),(he=(be=P.current).onNodeGridModeChange)==null||he.call(be,{...Q,order:[...Ve.current.order]})}else{const Ae=Ve.current;if(!Ae)return;if(M.size.w===Ae.previousSize.w&&M.size.h===Ae.previousSize.h&&ce.current.size===Ae.previousPositions.size&&[...ce.current.keys()].every(pt=>Ae.previousPositions.has(pt))?Ue.current=()=>M.transition(Ae.previousViewport,Q.animate!==!1&&!P.current.disableAnimations&&!P.current.isPerformanceMode):bt.centerAndFit(80,Q.animate,!0),Ve.current=null,at(!1),ge(),(Ne=(Ze=P.current).onNodeGridModeChange)==null||Ne.call(Ze,null),Wt(null),!Ae.previousPositions.size){te();return}const We=new Map([...ce.current].map(([pt,nr])=>[pt,Ae.previousPositions.get(pt)??nr]));X(We,Q.animate,void 0,void 0,void 0,!0)}},swapGridNodes:(re,Q,be)=>{var nr,nn;const he=Ve.current;if(!he||!he.ready||P.current.readOnly||re===Q)return!1;const Ze=L(),Ne=Ze.nodes.find(jt=>jt.id===re),Ae=Ze.nodes.find(jt=>jt.id===Q);if(!Ne||!Ae||Ne.parent!==Ae.parent)return!1;const dt=ed(Ze,A(he.options));if(dt.skippedNodeIds.includes(re)||dt.skippedNodeIds.includes(Q))return!1;const We=he.order.indexOf(re),pt=he.order.indexOf(Q);return We<0||pt<0?!1:([he.order[We],he.order[pt]]=[he.order[pt],he.order[We]],Ue.current=null,he.options={...he.options,order:[...he.order]},bt.arrangeNodesInGrid({...he.options,animate:be??he.options.animate}),(nn=(nr=P.current).onNodeGridModeChange)==null||nn.call(nr,{...he.options}),!0)},setNodePosition:(re,Q,be)=>{if(!ce.current.has(re)||Q&&(!Number.isFinite(Q.x)||!Number.isFinite(Q.y)))return!1;if(Xt(),!Q)return z.current.delete(re),te(),!0;const he=new Map(ce.current);return he.set(re,{...Q}),(be==null?void 0:be.persist)===!1?z.current.delete(re):z.current.set(re,{...Q}),ce.current=he,oe(he),(be==null?void 0:be.persist)===!1&&te(),!0},onViewportChange:re=>M.onChange(re)}},[]);S.useEffect(()=>{var A,L;return(L=(A=P.current).onInit)==null||L.call(A,bt),()=>M.cancelAnimation()},[bt]),S.useEffect(()=>{var A,L;if(K>0){const D=tt.current;tt.current=null,D==null||D(),(L=(A=P.current).onLayoutComplete)==null||L.call(A,bt)}},[bt,K]);const ft=S.useRef(null),vt=S.useRef(new Map),Tt=S.useRef(!1),[mr,Ln]=S.useState(null),[ot,tn]=S.useState(null),Fn=A=>{const L=I.current.getBoundingClientRect();return{x:(A.clientX-L.left)*(I.current.clientWidth/L.width||1),y:(A.clientY-L.top)*(I.current.clientHeight/L.height||1)}},zn=(A,L)=>{const D=P.current.nodes;for(let X=D.length-1;X>=0;X--){const le=D[X].id;if(!or(le,P.current.edges,P.current.edgeMode)||lt.current&&!lt.current.has(le)||le===L||fe.current.has(le))continue;const ke=we(le);if(ke&&$u(A,Yt(ke)))return le}for(const[X,le]of fe.current)if(or(X,P.current.edges,P.current.edgeMode)&&!(lt.current&&!lt.current.has(X))&&X!==L&&$u(A,le))return X;return null},nu=(A,L)=>{const D=P.current.nodes.find(Re=>Re.id===A),X=we(A);if(!D||!X)return null;const le=Yt({...X,x:X.x+L.x,y:X.y+L.y});let ke=null,Ce=0;for(const Re of P.current.nodes){if(Re.id===A||Re.parent!==D.parent||z.current.has(Re.id)||fe.current.has(Re.id)||!or(Re.id,P.current.edges,P.current.edgeMode)||lt.current&&!lt.current.has(Re.id))continue;const Le=we(Re.id);if(!Le)continue;const _e=Yt(Le),Fe=Math.max(0,Math.min(le.x2,_e.x2)-Math.max(le.x1,_e.x1))*Math.max(0,Math.min(le.y2,_e.y2)-Math.max(le.y1,_e.y1));Fe>Ce&&(Ce=Fe,ke=Re.id)}return ke},Ro=(A,L)=>{if(P.current.edgeMode==="nodes"||P.current.edgeMode==="workflow")return null;const D=P.current.direction==="RL",X=Math.max(16,6/M.zoom);let le=null;for(const ke of[...P.current.nodes].reverse()){if(!or(ke.id,P.current.edges,P.current.edgeMode)||lt.current&&!lt.current.has(ke.id))continue;const Ce=we(ke.id),Re=B.current.get(ke.id);if(!Ce||!Re||fe.current.has(ke.id))continue;const Le=Ce.x+(L==="source"!==D?1:-1)*Ce.w/2;for(const _e of Re){if(_e.role&&_e.role!==L)continue;const Fe=Ce.y-Ce.h/2+_e.top,Xe=Math.hypot(A.x-(_e.anchor?Ce.x-Ce.w/2+_e.anchor.x:Le),A.y-Fe-_e.height/2);if(!_e.anchor&&A.x>=Ce.x-Ce.w/2&&A.x<=Ce.x+Ce.w/2&&A.y>=Fe&&A.y<=Fe+_e.height)return{nodeId:ke.id,property:_e.property};Xe<=X&&(!le||Xe<le.distance)&&(le={nodeId:ke.id,property:_e.property,distance:Xe})}}return le},Jv=A=>{var Re,Le;if(!A.currentTarget.contains(A.target)||(ft.current||(Tt.current=!1),A.target.closest(".flow-sdk-canvas")!==A.currentTarget)||A.button!==0||P.current.readOnly)return;const L=A.target;if(L.closest('input, textarea, select, [contenteditable="true"], [data-flow-content-toggle]'))return;const D=P.current,X=Fn(A);if(A.pointerType==="touch"){vt.current.set(A.pointerId,X);const _e=pm(vt.current);if(_e){Wt(null),ft.current={kind:"pinch",distance:_e.distance,zoom:M.zoom,anchor:M.renderedToModel(_e.center)},tn(null),Ln(null),Tt.current=!0;for(const Fe of vt.current.keys())A.currentTarget.setPointerCapture(Fe);return}}if(ft.current)return;const le=!Ve.current||!!D.nodeGridConnections,ke=D.drawHandles&&L.closest(".flow-sdk-handle"),Ce=D.drawHandles&&L.closest(".flow-sdk-property-port");if((!le||!ke&&!Ce&&(!D.drawMode||A.shiftKey))&&(Ve.current||A.shiftKey&&(D.onNodeGridDrop||D.onNodeParentChange))){if(Ve.current&&!Ve.current.ready||L.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]"))return;const _e=(Re=L.closest("[data-node-id]"))==null?void 0:Re.dataset.nodeId;if(_e&&!z.current.has(_e)){L.setPointerCapture(A.pointerId),ft.current={kind:"grid",pointerId:A.pointerId,captureTarget:L,source:_e,start:X,moved:!1};return}if(_e)return}if(le&&(D.drawMode||ke||Ce)){const _e=M.renderedToModel(X),Fe=D.drawMode?Ro(_e,"source"):null,Xe=Ce||ke,re=Xe?(Le=Xe.closest("[data-node-id]"))==null?void 0:Le.dataset.nodeId:(Fe==null?void 0:Fe.nodeId)??zn(_e),Q=Ce?Ce.dataset.property:Fe==null?void 0:Fe.property;if(re){ft.current={kind:"draw",pointerId:A.pointerId,source:re,sourceProperty:Q,reverse:(Ce==null?void 0:Ce.dataset.portRole)==="target",startClient:{x:A.clientX,y:A.clientY}},Tt.current=!0,tn({source:re,sourceProperty:Q,point:_e,target:null}),A.currentTarget.setPointerCapture(A.pointerId);return}}L.closest(".flow-sdk-node, .flow-sdk-container, .flow-sdk-edge, .flow-sdk-edge-label, .flow-sdk-container-label")||(Ue.current=null,D.multiSelect?ft.current={kind:"box",pointerId:A.pointerId,start:X,current:X}:D.dragMode?ft.current={kind:"pan",pointerId:A.pointerId,start:X,pan0:M.pan,moved:!1}:ft.current={kind:"tap",pointerId:A.pointerId,start:X,moved:!1},A.currentTarget.setPointerCapture(A.pointerId))},Zv=A=>{var X,le,ke;const L=ft.current;if(!L||P.current.readOnly)return;const D=Fn(A);if(vt.current.has(A.pointerId)&&vt.current.set(A.pointerId,D),L.kind==="pinch"){const Ce=pm(vt.current);if(!Ce)return;const Re=Math.max(M.minZoom,Math.min(M.maxZoom,L.zoom*Ce.distance/L.distance));if(Re<M.zoom&&((X=Ve.current)!=null&&X.options.fill)&&((ke=(le=P.current).onNodeGridZoomOut)==null?void 0:ke.call(le,Ve.current.options))===!0)return;M.set({x:Ce.center.x-L.anchor.x*Re,y:Ce.center.y-L.anchor.y*Re},Re);return}if(L.pointerId===A.pointerId)switch(L.kind){case"grid":{const Ce={x:D.x-L.start.x,y:D.y-L.start.y};if(!L.moved&&Math.hypot(Ce.x,Ce.y)<=td)return;L.moved||(Xt(),Ue.current=null,M.cancelAnimation()),L.moved=!0,Tt.current=!0,A.preventDefault();const Re={x:Ce.x/M.zoom,y:Ce.y/M.zoom};Wt({source:L.source,offset:Re,target:A.shiftKey?null:nu(L.source,Re),shiftKey:A.shiftKey});break}case"pan":{const Ce=D.x-L.start.x,Re=D.y-L.start.y;if(!L.moved&&Math.hypot(Ce,Re)<=td)return;L.moved=!0,Tt.current=!0,M.set({x:L.pan0.x+Ce,y:L.pan0.y+Re});break}case"tap":{Math.hypot(D.x-L.start.x,D.y-L.start.y)>td&&(L.moved=!0);break}case"box":{Tt.current=!0,L.current=D,Ln({x1:Math.min(L.start.x,D.x),y1:Math.min(L.start.y,D.y),x2:Math.max(L.start.x,D.x),y2:Math.max(L.start.y,D.y)});break}case"draw":{const Ce=M.renderedToModel(D),Re=Ro(Ce,L.reverse?"source":"target");tn(L.reverse&&Re?{source:Re.nodeId,sourceProperty:Re.property,point:Ce,target:L.source,targetProperty:L.sourceProperty}:{source:L.source,sourceProperty:L.sourceProperty,point:Ce,target:(Re==null?void 0:Re.nodeId)??zn(Ce,L.source),targetProperty:Re==null?void 0:Re.property});break}}},ou=(A,L)=>{var le,ke,Ce,Re,Le,_e,Fe,Xe,re,Q,be;vt.current.delete(A.pointerId);const D=ft.current;if(!D)return;if(D.kind==="pinch"){const he=[...vt.current][0];ft.current=he&&P.current.dragMode&&!L?{kind:"pan",pointerId:he[0],start:he[1],pan0:M.pan,moved:!0}:null;return}if(D.pointerId!==A.pointerId)return;ft.current=null;try{(D.kind==="grid"?D.captureTarget:A.currentTarget).releasePointerCapture(A.pointerId)}catch{}const X=P.current;switch(L=L||!!X.readOnly,D.kind){case"grid":{if(Wt(null),L||!D.moved||((le=X.onNodeGridDrop)==null?void 0:le.call(X,D.source,{x:A.clientX,y:A.clientY},{shiftKey:A.shiftKey,ctrlKey:A.ctrlKey,metaKey:A.metaKey,altKey:A.altKey}))===!0)break;const he=Fn(A);if(he.x<0||he.y<0||he.x>M.size.w||he.y>M.size.h)break;if(A.shiftKey){const Ne=new Map(X.nodes.map(We=>[We.id,We]));let Ae=zn(M.renderedToModel(he),D.source);const dt=new Set;for(;Ae&&!((ke=Ne.get(Ae))!=null&&ke.acceptsChildren)&&!dt.has(Ae);)dt.add(Ae),Ae=((Ce=Ne.get(Ae))==null?void 0:Ce.parent)??null;if(Ae&&((Re=Ne.get(Ae))!=null&&Re.acceptsChildren)){let We=Ae;const pt=new Set;for(;We&&!pt.has(We);)pt.add(We),We=(Le=Ne.get(We))==null?void 0:Le.parent;pt.has(D.source)||(_e=X.onNodeParentChange)==null||_e.call(X,D.source,Ae)}break}if(!Ve.current)break;const Ze=nu(D.source,{x:(he.x-D.start.x)/M.zoom,y:(he.y-D.start.y)/M.zoom});Ze&&bt.swapGridNodes(D.source,Ze,!1);break}case"pan":case"tap":!L&&!D.moved&&((Fe=X.onBackgroundTap)==null||Fe.call(X));break;case"box":{if(Ln(null),L)break;const he=M.renderedToModel(D.start),Ze=M.renderedToModel(D.current),Ne={x1:Math.min(he.x,Ze.x),y1:Math.min(he.y,Ze.y),x2:Math.max(he.x,Ze.x),y2:Math.max(he.y,Ze.y)};if(Ne.x2-Ne.x1<1&&Ne.y2-Ne.y1<1){(Xe=X.onBackgroundTap)==null||Xe.call(X);break}const Ae=[];for(const dt of X.nodes){const We=we(dt.id);We&&Ow(Yt(We),Ne)&&Ae.push(dt.id)}Ae.length&&((re=X.onBoxSelect)==null||re.call(X,Ae));break}case"draw":{if(tn(null),L)break;const he=Fn(A),Ze=M.renderedToModel(he),Ne=Ro(Ze,D.reverse?"source":"target"),Ae=(Ne==null?void 0:Ne.nodeId)??zn(Ze);if(Ae===D.source&&(D.sourceProperty===void 0||(Ne==null?void 0:Ne.property)===void 0||Ne.property===D.sourceProperty))break;Ae?(Q=X.onEdgeDraw)==null||Q.call(X,D.reverse?Ae:D.source,D.reverse?D.source:Ae,D.sourceProperty!==void 0||(Ne==null?void 0:Ne.property)!==void 0?{sourceProperty:D.reverse?Ne==null?void 0:Ne.property:D.sourceProperty,targetProperty:D.reverse?D.sourceProperty:Ne==null?void 0:Ne.property}:void 0):Math.max(Math.abs(A.clientX-D.startClient.x),Math.abs(A.clientY-D.startClient.y))>kj&&((be=X.onDrawIntoSpace)==null||be.call(X,D.source,Ze,D.sourceProperty,D.reverse));break}}},br=S.useCallback(()=>{var D;const A=ft.current,L=[...vt.current.keys()];A&&A.kind!=="pinch"&&L.push(A.pointerId),ft.current=null,vt.current.clear(),Wt(null),tn(null),Ln(null);for(const X of L)(A==null?void 0:A.kind)==="grid"&&A.captureTarget.hasPointerCapture(X)&&A.captureTarget.releasePointerCapture(X),(D=I.current)!=null&&D.hasPointerCapture(X)&&I.current.releasePointerCapture(X)},[]);S.useEffect(()=>{const A=L=>{L.key==="Escape"&&br()};return window.addEventListener("keydown",A),window.addEventListener("blur",br),()=>{window.removeEventListener("keydown",A),window.removeEventListener("blur",br),ft.current=null,vt.current.clear()}},[br]),S.useEffect(()=>{br()},[g,b,v,o,n,e.drawHandles,e.readOnly,ze,br]);const Xv=S.useMemo(()=>{const A=new Map,L=new Map;for(const D of E){if(D.source!==D.target)continue;const X=A.get(D.source)??0;A.set(D.source,X+1),L.set(D.id,X)}return L},[E]),ko=Rj[n],[Ao,Yv]=S.useState(null),Po=_j(r,E,!!((lu=e.edgeReveal)!=null&&lu.revealNodes));S.useLayoutEffect(()=>{I.current&&Ao&&wj(I.current)});const Io=Mw(E,Ge,ko),Qv=e.onEdgeSelect,ex=e.onContainerSelect,iu=ot?ot.target&&Ge(ot.target,ot.targetProperty)||{x:ot.point.x,y:ot.point.y,w:1,h:1}:null,au=ot?Ge(ot.source,ot.sourceProperty):null,rn=!ze||!!e.nodeGridConnections,tx=["flow-sdk-canvas",g&&rn?"flow-sdk-draw":"",x?"flow-sdk-perf":""].filter(Boolean).join(" ");return f.jsxs("div",{ref:I,className:tx,"data-edge-mode":o,"data-node-grid":ze||void 0,"data-grid-connections":e.nodeGridConnections||void 0,onPointerDownCapture:Jv,onPointerMove:Zv,onPointerUp:A=>ou(A,!1),onPointerCancel:A=>ou(A,!0),onLostPointerCapture:A=>{const L=ft.current;L&&(L.kind==="pinch"||L.pointerId===A.pointerId)&&br()},onClickCapture:A=>{if(!A.currentTarget.contains(A.target))return;const L=A.target instanceof Element&&A.target.closest("button[data-flow-fullscreen]");(Tt.current||e.readOnly&&!L)&&(A.preventDefault(),A.stopPropagation())},children:[f.jsx("svg",{className:"flow-sdk-svg",children:f.jsxs("g",{ref:R,children:[f.jsx("g",{className:"flow-sdk-containers",children:[...U].filter(([A])=>or(A,t,o)).filter(([A])=>!_||_.has(A)).map(([A,L])=>{var D,X;return f.jsx(Ww,{id:A,rect:L,label:Me.get(A),labelLayer:Ao,labelContent:(D=r.find(le=>le.id===A&&le.label!==void 0))==null?void 0:D.element,style:y(A),onSelect:ex,onCollapse:e.readOnly?void 0:e.onContainerCollapse,selected:(X=e.selectedNodeIds)==null?void 0:X.includes(A)},A)})}),f.jsx("g",{className:"flow-sdk-edges",children:ht&&rn&&E.map(A=>{var X,le,ke;if(!Po.ready.has(A.id)||_&&(!_.has(A.source)||!_.has(A.target)))return null;const L=Ge(A.source,A.sourceProperty),D=Ge(A.target,A.targetProperty);return!L||!D?null:f.jsx(Vu,{id:A.id,edgeData:A.data,validationIssue:A.validationIssue,edgeType:A.type,edgeRadius:e.edgeRadius,propertyMode:k,customEdgeTypes:e.customEdgeTypes,reveal:e.edgeReveal,onRevealComplete:Po.complete,source:L,target:D,sourceProperty:A.sourceProperty,targetProperty:A.targetProperty,sourceY:Ke(A.source,A.sourceProperty),targetY:Ke(A.target,A.targetProperty),sourcePort:Qe(A.source,A.sourceProperty),targetPort:Qe(A.target,A.targetProperty),dir:ko,turn:((X=Io.get(A.id))==null?void 0:X.turn)??A.turn,labelAtTarget:(le=Io.get(A.id))==null?void 0:le.labelAtTarget,labelFraction:(ke=Io.get(A.id))==null?void 0:ke.labelFraction,color:A.color,connectorColor:A.connectorColor,labelBg:A.labelBg,label:A.label,labelLayer:Ao,dashed:A.dashed,animated:A.animated&&!x,inverted:A.inverted,loopIndex:Xv.get(A.id)??0,onSelect:Qv},A.id)})}),ht&&rn&&ot&&ld(ot,o)&&au&&iu&&f.jsx("g",{className:"flow-sdk-ghost",pointerEvents:"none",children:f.jsx(Vu,{id:"__flow-sdk-ghost",edgeData:{id:"__flow-sdk-ghost",source:ot.source,target:ot.target??"",sourceProperty:ot.sourceProperty,targetProperty:ot.targetProperty},edgeType:e.edgeType,edgeRadius:e.edgeRadius,propertyMode:k,customEdgeTypes:e.customEdgeTypes,source:au,target:iu,sourceProperty:ot.sourceProperty,targetProperty:ot.targetProperty,sourceY:Ke(ot.source,ot.sourceProperty),sourcePort:Qe(ot.source,ot.sourceProperty),targetPort:ot.target?Qe(ot.target,ot.targetProperty):void 0,targetY:ot.target?Ke(ot.target,ot.targetProperty):void 0,dir:ko,turn:.5,color:m,labelBg:m})})]})}),f.jsxs("div",{ref:N,className:"flow-sdk-nodes",children:[ze&&((du=Ve.current)==null?void 0:du.options.fill)&&((uu=Ve.current.options.adjustment)==null?void 0:uu.enabled)&&!e.readOnly&&f.jsx(xj,{dividers:st,options:Ve.current.options,zoom:M.zoom,onChange:A=>bt.setNodeGridMode(!0,{...A,animate:!1})}),r.map(A=>{var Ze,Ne;const L=Y.get(A.id),D=U.get(A.id);if(D&&A.label!==void 0)return null;const X=(L==null?void 0:L.x)??(D?(D.x1+D.x2)/2:0),le=(L==null?void 0:L.y)??(D?(D.y1+D.y2)/2:0),ke=Ye!=null&&Ye.target?A.id===Ye.source?Ye.target:A.id===Ye.target?Ye.source:void 0:void 0,Ce=ke?Y.get(ke):void 0,Re=Ye?Y.get(Ye.source):void 0,Le=Ye!=null&&Ye.target?Y.get(Ye.target):void 0,_e=Re&&Le?{x:Le.x-Re.x,y:Le.y-Re.y}:void 0,Fe=_e?_e.x**2+_e.y**2:0,Xe=Fe&&Ye&&_e?Math.max(0,Math.min(1,(Ye.offset.x*_e.x+Ye.offset.y*_e.y)/Fe)):0,re=Ce?{x:X+(Ce.x-X)*Xe,y:le+(Ce.y-le)*Xe}:(Ye==null?void 0:Ye.source)===A.id?{x:X+Ye.offset.x,y:le+Ye.offset.y}:void 0,Q=xe.get(A.id),be=ke?xe.get(ke):void 0,he=Q&&be?{w:Q.w+(be.w-Q.w)*Xe,h:Q.h+(be.h-Q.h)*Xe}:Q;return f.jsx(jj,{id:A.id,x:X,y:le,gridDraggable:ze&&!e.readOnly&&!z.current.has(A.id),gridDragging:(Ye==null?void 0:Ye.source)===A.id,gridDropTarget:(Ye==null?void 0:Ye.target)===A.id,gridSize:xe.get(A.id),gridPreview:re?{...re,size:he,floating:Ye==null?void 0:Ye.shiftKey}:void 0,placed:!!L||!!D,hidden:!ze&&!Po.shown.has(A.id)||!or(A.id,t,o)||!!_&&!_.has(A.id),onMount:G,drawHandles:e.drawHandles&&!e.readOnly&&rn,drawMode:g&&rn,connectedPorts:new Set(E.flatMap(Ae=>[...Ae.source===A.id&&Ae.sourceProperty!==void 0?[`source:${Ae.sourceProperty}`]:[],...Ae.target===A.id&&Ae.targetProperty!==void 0?[`target:${Ae.targetProperty}`]:[]])),hasCollapseControl:A.hasCollapseControl,handleColor:m,animated:A.animated&&!D&&!x&&!ze,animationColor:A.animationColor,animationWidth:A.animationWidth,animationVariant:A.animationVariant,width:(Ze=J.current.get(A.id))==null?void 0:Ze.w,height:(Ne=J.current.get(A.id))==null?void 0:Ne.h,propertyMode:k,resolvedRows:Se.get(A.id),reversePorts:n==="RL",direction:n,onPropertyRows:de,onSurface:q,children:Q?A.fillElement??A.element:A.element},A.id)})]}),mr&&f.jsx("div",{className:"flow-sdk-box",style:{left:mr.x1,top:mr.y1,width:mr.x2-mr.x1,height:mr.y2-mr.y1}}),f.jsx("svg",{className:"flow-sdk-svg flow-sdk-label-overlay",style:{zIndex:11,pointerEvents:"none"},children:f.jsx("g",{ref:$,transform:`translate(${M.pan.x} ${M.pan.y}) scale(${M.zoom})`,children:f.jsx("g",{ref:Yv,className:"flow-sdk-labels",style:{pointerEvents:g?"none":"visiblePainted",outline:"none"}})})})]})}const Mj=S.memo(Ij);function Yd(e=!0){const r=S.useRef(null);return S.useEffect(()=>{if(!e||!r.current)return;const t=o=>{o.stopPropagation()},n=r.current,i=["mousedown","mouseup","click","dblclick","pointerdown","pointerup","wheel"];return i.forEach(o=>n.addEventListener(o,t)),()=>{i.forEach(o=>n.removeEventListener(o,t))}},[e]),r}const Ur=({nodeId:e,label:r,color:t,fontWeight:n="bold",fontSize:i="5xl",wrap:o=!1,isEditing:s,onEditStart:a,onEditEnd:c})=>{const{callbacks:l,config:d,readOnly:u}=He(),h=d.editable&&!u,[p,y]=S.useState(r),[m,g]=S.useState(),b=S.useRef(null),v=S.useRef(!1),x=Yd(s);S.useEffect(()=>{if(s&&(v.current=!1,b.current)){b.current.focus();const C=b.current.value.length;b.current.setSelectionRange(C,C)}},[s]);const w=()=>{var j;if(v.current)return;v.current=!0;const C=p.trim();C&&C!==r&&((j=l.onNodeLabelChange)==null||j.call(l,e,C)),c()};return!h||!s?f.jsx(V.Text,{color:t,fontWeight:n,fontSize:i,minW:0,maxW:"100%",whiteSpace:o?"normal":"nowrap",overflowWrap:o?"anywhere":void 0,overflow:"hidden",textOverflow:"ellipsis",title:r,onDoubleClick:h?C=>{C.stopPropagation(),g({width:C.currentTarget.offsetWidth,height:C.currentTarget.offsetHeight}),y(r),a()}:void 0,cursor:h?"text":void 0,children:r}):f.jsxs("div",{ref:x,style:{position:"relative",width:"max-content",minWidth:m==null?void 0:m.width,maxWidth:900,height:m==null?void 0:m.height},children:[f.jsx(V.Text,{as:"span","aria-hidden":"true",display:"block",visibility:"hidden",fontWeight:n,fontSize:i,lineHeight:"normal",whiteSpace:"pre",overflow:"hidden",children:p||" "}),f.jsx(V.Input,{ref:b,value:p,onChange:C=>y(C.target.value),onBlur:w,onKeyDown:C=>{C.key==="Enter"&&w(),C.key==="Escape"&&(v.current=!0,c())},color:t,fontWeight:n,fontSize:i,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 Bv({id:e,label:r,role:t,side:n,position:i=.5,placement:o,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?i:void 0,"data-flow-port-placement":o,style:{minHeight:32,display:"flex",alignItems:"center",justifyContent:t==="source"?"flex-end":"flex-start",...a,...n?{display:"none"}:{}},children:s??r??e})}const Tj=Qn.default.dialog`
211
- ${e=>dr(e.$surface,e.$border)}
209
+ `;function qu({request:e,property:r,config:t,value:n,disabled:o}){var ye,pe,X,L,ie;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:T,address:I,nodeAddress:N,nodeId:$}=e;_.useEffect(()=>(S(!1),P(!1),()=>{var H;(H=w.current)==null||H.abort(),w.current=void 0}),[I,N,$,o,h,t.$control,(pe=t.$upload)==null?void 0:pe.accept,(X=t.$upload)==null?void 0:X.maxSizeBytes]);const M=_.useRef(T);M.current=T;const K=JSON.stringify([I,$,(L=t.$options)!=null&&L.$dependsOn?t.$options.$dependsOn.map(H=>qe(T,H)):qe(T,N)]);_.useEffect(()=>{m(h),g("")},[h,I,$]),_.useEffect(()=>{if(!A)return;const H=new AbortController;return Promise.resolve().then(()=>{if(!R)throw new Error("No options resolver configured");return R({address:I,nodeAddress:N,nodeId:$,data:Wr(M.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,I,N,$,v]);const ae=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,T),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??I.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(T),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},ke=Ae(c);return f.jsxs("div",{"data-form-field":I,"data-flow-property":I.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:(ie=t.$upload)==null?void 0:ie.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||ae||!!(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||ae,"aria-pressed":be,style:{padding:"8px 16px",borderRadius:24,border:0,color:be?ke:"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)}),ae&&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,T]=_.useState(0),[I,N]=_.useState(""),[$,M]=_.useState(""),[K,ae]=_.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||(M(""),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;M(""),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++,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: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),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: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;ae(!0),M("");try{const ue=await pw(le);Y===v.current&&se(ue)}catch(ue){Y===v.current&&M(ue instanceof Error?ue.message:"Unable to read SVG.")}finally{Y===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),T(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:()=>T(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:()=>T(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(I.trim())||I.trim().startsWith(jn)?M("Enter an HTTP or HTTPS image URL."):se(I.trim()))},children:[f.jsx("input",{type:"url","aria-label":"SVG URL",placeholder:"https://example.com/icon.svg",value:I,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||!I.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,ke,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,ie=((fe=L==null?void 0:L.config)==null?void 0:fe.typeView)??"";return ie==="object"&&((be=L==null?void 0:L.config)==null?void 0:be.content)!==void 0&&c[X]!=="properties"?"content":ie==="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":ie}),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 ie,H,fe,be;const L=(ie=u.get(X))==null?void 0:ie.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,ie,H;return(((ie=(L=u.get(X))==null?void 0:L.data.viewProps)==null?void 0:ie.outline)??(h.has(X)?(H=s.parentNodeStyle)==null?void 0:H.outline:!1))===!0},A=e.every(O),R=!A&&e.some(O),T=X=>{var L;return((L=u.get(X))==null?void 0:L.data.isNodeAnimated)===!0},I=e.every(T),N=!I&&e.some(T),$=e.map(X=>{var L;return((L=u.get(X))==null?void 0:L.data.nodeAnimationVariant)??"traveling"}),M=$.every(X=>X===$[0])?$[0]:"",K=X=>e.forEach(X),[ae,se]=_.useState(!1),te=ae&&m("color")&&m("borderColor"),me=X=>{var L,ie,H;return(((ie=(L=u.get(X))==null?void 0:L.data.viewProps)==null?void 0:ie.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,ie=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,ie)}),W=D.every(X=>X===D[0])?String(D[0]??""):"",B=X=>K(L=>{var ie,H;te?(ie=n.onNodeBorderColorChange)==null||ie.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 ie;const L=(ie=S.find(H=>H.value===X))==null?void 0:ie.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 ie;return(ie=n.onNodeBorderWidthChange)==null?void 0:ie.call(n,L,X===""?void 0:Number(X))})})]})]}),m("animation")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(Ue,{label:I?"Stop border animation":"Animate node border",children:f.jsx(Me,{"aria-label":"Toggle node animation","aria-pressed":N?"mixed":I,icon:f.jsx(V.Icon,{as:Z.PiSpinnerGap,boxSize:5}),size:"sm",variant:"ghost",color:I?i:d,onClick:()=>K(X=>{var L;return(L=n.onNodeAnimationChange)==null?void 0:L.call(n,X,!I)})})}),(I||N)&&f.jsx(hb,{label:"Node animation",value:M,options:[{value:"traveling",label:"Trace"},{value:"pulse",label:"Pulse"}],disabled:s.readOnly,onChange:X=>K(L=>{var ie;return(ie=n.onNodeAnimationVariantChange)==null?void 0:ie.call(n,L,X)})})]}),!te&&m("textColor")&&f.jsxs(f.Fragment,{children:[f.jsx(jt,{}),f.jsx(kr,{label:"Text color",colors:pb,value:(ke=b==null?void 0:b.viewProps)==null?void 0:ke.textColor,onPick:X=>K(L=>{var ie;return(ie=n.onNodeColorChange)==null?void 0:ie.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,ie;return(ie=n.onNodeDelete)==null?void 0:ie.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 T,I;(T=R.currentTarget.closest("[popover]"))==null||T.hidePopover(),(I=s.onWorkflowConfigurationOpen)==null||I.call(s)},children:[f.jsx(Z.PiGear,{}),"Configuration"]})]}),onValueChange:R=>{var I;const T=R==="auto"?"auto":R==="properties"?"properties":"nodes";n(T),(I=s.onEdgeModeChange)==null||I.call(s,T)},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 T=(N=R.target.files)==null?void 0:N[0];if(R.target.value="",!T)return;const I=++w.current;S(!0),P("");try{const M=g?await Id(T,[...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:K,schema:ae}=g&&M?{schema:M,contract:{name:T.name,nodes:Object.fromEntries(Object.entries(g).map(([se,te])=>[se,{type:M[te.schemaType??te.type],optional:!1}]))}}:await _w(T,u);if(I!==w.current)return;p==null||p(ae),i(K),($=s.onWorkflowContractChange)==null||$.call(s,K)}catch(M){I===w.current&&P(`${T.name}: ${M instanceof Error?M.message:"Unable to load interface."}`)}finally{I===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:T,config:I,readOnly:N}=Ze(),{nodeById:$,edgeById:M,parentIds:K}=yr(),ae=I.colorMode==="dark",{background:se,border:te,colorInactive:me,colorText:ve,colorActive:F}=at(),D=ae?te:"gray.300",W=`var(--chakra-colors-${se.replace(".","-")})`,B=`var(--chakra-colors-${(ae?te:"gray.300").replace(".","-")})`,[le,Y]=_.useState(!1),[ce,ue]=_.useState(!0),xe=I.bottomBarCollapsed??ce,ke=_.useRef(null),ye=Sm({edge:"bottom",enabled:!A,bounds:ke,inside:[ke]}),pe=_.useCallback(Te=>{const Ve=r.current;if(!Ve)return;const st=I.minZoom??.01,ct=I.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,I.minZoom,I.maxZoom]),X=I.renderSelectedNodeToolbar,L=p.length>0&&!!X,ie=_.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=T.onNodeDeselect)==null||Te.call(T)},[m,T]),fe=I.renderSelectedEdgeToolbar,be=!!y&&!!fe,Ne=_.useMemo(()=>{var Te;return!be||!y?null:((Te=M.get(y))==null?void 0:Te.data)??{id:y}},[be,y,M]),Le=_.useCallback(()=>{var Te;g(null),(Te=T.onEdgeDeselect)==null||Te.call(T)},[g,T]),Be=I.selectionToolbar!==!1&&!N,tt=Be&&!!y&&!fe,Je=Be&&!tt&&p.length>0&&!X,yt=tt||Je,Ye=A||ye||le||yt||I.bottomBarCollapsed===!1;_.useEffect(()=>{p.length||y?a(!1):N||(s&&R(!0),I.bottomBarCollapsed===void 0&&ue(!s))},[s,p.length,y,N,a,R,I.bottomBarCollapsed]);const nt=I.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:ie,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:ie,selectedEdgeId:y,selectedEdgeData:Ne,onNodeDeselect:H,onEdgeDeselect:Le,callbacks:T})})]}):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:ie,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:ke,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:ae?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:I.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:I.bottomBarNavigation===!1?"none":"contents"},children:[I.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)})})]}),I.bottomBarNavigation===!1&&(e===void 0?f.jsx(Fo,{}):e?Dr.createPortal(f.jsx(Fo,{}),e):null),I.bottomBarExtra&&f.jsxs(f.Fragment,{children:[I.bottomBarNavigation!==!1&&f.jsx(V.Icon,{mx:-1,as:Z.PiLineVerticalThin,boxSize:5,color:D,role:"separator","aria-orientation":"vertical"}),I.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:I.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=T.onArrayModeChange)==null||Ve.call(T,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=T.onThemeColorChange)==null||Ve.call(T,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||(ae?"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;I.bottomBarCollapsed===void 0&&ue(!xe),a(xe),(Te=T.onBottomBarCollapsedChange)==null||Te.call(T,!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:ae?"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:ae?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Ve;(Ve=T.onDirectionChange)==null||Ve.call(T,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:ae?"whiteAlpha.100":"blackAlpha.50"},onClick:()=>{var Te;(Te=T.onDirectionChange)==null||Te.call(T,"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:T=0,onSelect:I}){const N=n==null?void 0:n.icon,$=g?no:Lb,{lines:M,iconWidth:K,contentWidth:ae,contentHeight:se}=_.useMemo(()=>zb(E,N,$),[E,N,$]),te=_.useMemo(()=>{const ke={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?ae+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"},ie=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,ie,{...ke,srcDist:18,tgtDist:18},i):ye?Du(c,l,v,h,p,b,{...ke,srcDist:18,tgtDist:18,radius:s??Math.min(ke.radius,40)}):H?Ww(c,T,{...ke,srcDist:0,tgtDist:0}):Vu(c,l,v,b,ke);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,ke):Nb([c,l],c,l,ke):i==="bezier"?Gw(be.sourcePoint,be.targetPoint,ye?v==="leftward"?"leftward":"rightward":v,ke):i==="orthogonal"?ye?Du(c,l,v,h,p,b,{...ke,srcDist:18,tgtDist:18,radius:0}):Vu(c,l,v,b,{...ke,radius:0}):fe},[c,e,n,i,s,a,l,g,h,p,m,y,v,b,R,T,x,w,ae]);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-M.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(M.length||N){const ke=ae,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:-ke/2-Cr,y:-ye/2-Cr,width:ke+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:M.map((pe,X)=>f.jsx("tspan",{x:K/2,y:(X-(M.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:-ke/2,y:-24,width:48,height:48,fill:"transparent"}),f.jsx(Zt,{name:N,svg:!0,size:48,x:-ke/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:ke=>{ke.stopPropagation(),I==null||I(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(T){return t(T)&&r(T.length)&&!!A[e(T)]}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]",T="[object Error]",I="[object Function]",N="[object GeneratorFunction]",$="[object Map]",M="[object Number]",K="[object Object]",ae="[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]",ke="[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[M]=pe[K]=pe[ae]=pe[se]=pe[te]=pe[me]=pe[ue]=pe[xe]=pe[ke]=pe[ye]=!0,pe[T]=pe[I]=pe[ve]=!1;function X(L,ie,H,fe,be,Ne){var Le,Be=ie&S,tt=ie&j,Je=ie&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==I||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,ie,H,st,L,Ne))}):v(L)&&L.forEach(function(st,ct){Le.set(ct,X(st,ie,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,ie,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 T=o;case m:var I=E&s;if(T||(T=i),S.size!=j.size&&!I)return!1;var N=R.get(S);if(N)return N==j;E|=a,R.set(S,j);var $=n(T(S),T(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__"),T=O&&p.call(g,"__wrapped__");if(R||T){var I=R?y.value():y,N=T?g.value():g;return w||(w=new e),x(I,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),T=!R&&c(P),I=!R&&!T&&h(P);O=P,R||T||I?s(j)?O=j:a(j)?O=n(j):T?(A=!1,O=r(P,!0)):I?(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,T=R?A.w:A.v;if(T!==j){var I=R===P,N=w.edge(A).weight;if(O+=I?N:-N,v(x,C,T)){var $=x.edge(C,T).cutvalue;O+=I?-$:$}}}),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(T){return A===b(x,x.node(T.v),O)&&A!==b(x,x.node(T.w),O)});return e.minBy(R,function(T){return t(w,T)})}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 T=i(v,A),I=T?v.node(T).order:E;(T||A===O)&&(e.forEach(S.slice(P,R+1),function(N){e.forEach(v.predecessors(N),function($){var M=v.node($),K=M.order;(K<j||I<K)&&!(M.dummy&&v.node(N).dummy)&&s(x,$,N)})}),P=R+1,j=I)}),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(T){var I=v.node(T);I.dummy&&(I.order<E||I.order>O)&&s(x,T,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 T=v.predecessors(A);T.length&&(E=v.node(T[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,T=Math.floor(R),I=Math.ceil(R);T<=I;++T){var N=A[T];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,T){for(var I=j.nodes(),N=I.pop(),$={};N;)$[N]?R(N):($[N]=!0,I.push(N),I=I.concat(T(N))),N=I.pop()}function O(R){S[R]=j.inEdges(R).reduce(function(T,I){return Math.max(T,S[I.v]+j.edge(I))},0)}function A(R){var T=j.outEdges(R).reduce(function(N,$){return Math.min(N,S[$.w]-j.edge($))},Number.POSITIVE_INFINITY),I=v.node(R);T!==Number.POSITIVE_INFINITY&&I.borderType!==P&&(S[R]=Math.max(S[R],T))}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],T=C.edge(R,A);C.setEdge(R,A,Math.max(j(v,O,E),T||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(){ae(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(){T(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(){I(F)}),D(" assignNodeIntersects",function(){N(F)}),D(" reversePoints",function(){M(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 T(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 I(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(ke){var ye=ke.x,pe=ke.y,X=ke.width,L=ke.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(ke){xe(F.node(ke))}),e.forEach(F.edges(),function(ke){var ye=F.edge(ke);e.has(ye,"x")&&xe(ye)}),D-=ce,B-=ue,e.forEach(F.nodes(),function(ke){var ye=F.node(ke);ye.x-=D,ye.y-=B}),e.forEach(F.edges(),function(ke){var ye=F.edge(ke);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 M(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 ae(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((T,I)=>{const N=h.get(T),$={x:E+(I-(C-1)/2)*S-(N.x1+N.x2)/2,y:O+(R-(w.length-1)/2)*j-(N.y1+N.y2)/2};for(const M of s.get(T)??[]){const K=a.get(M);a.set(M,{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 I,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=(I=r.adjustment)==null?void 0:I.sections)==null?void 0:N[b],O=Array.from({length:j},($,M)=>{var K;return((K=E==null?void 0:E.rows)==null?void 0:K[M])??1}),A=O.reduce(($,M)=>$+M,0),R=w-(j-1)*P;let T=v.y1;for(let $=0;$<j;$++){const M=R*O[$]/A,K=S[$].length,ae=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)*ae;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:T+M/2}),h.set(D,{w:W,h:M});const le=Math.min(e.padding(D),Math.max(0,(Math.min(W,M)-1)/2));m(B,{x1:ve+le,y1:T+le,x2:ve+W-le,y2:T+M-le},D)}else a.has(D)&&(a.set(D,{x:ve+W/2,y:T+M/2}),h.set(D,{w:W,h:M}));F<K-1&&p.push({section:b,axis:"x",row:$,index:F,weights:se,length:me,position:{x:ve+W+ae/2,y:T+M/2}}),ve+=W+ae}$<j-1&&p.push({section:b,axis:"y",row:$,index:$,weights:O,length:R,position:{x:v.x1+x/2,y:T+M+P/2}}),T+=M+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)),T=p.getPointAtLength(Math.min(g,E+2));let I=Math.atan2(T.y-R.y,T.x-R.x)*180/Math.PI;I>90&&(I-=180),I<-90&&(I+=180);const N=Math.abs(I)<1;d&&(I=0);const $=I*Math.PI/180,M=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:I,straight:N,score:Math.hypot(A.x-v,A.y-b),bounds:{left:A.x-M/2-8,right:A.x+M/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 T=_.useRef(null),[I,N]=_.useState([]),$=m??I,[M,K]=_.useState(),ae=_.useId(),se=_.useRef(),te=!!l,me=!!(l!=null&&l.floating);_.useLayoutEffect(()=>{var ke;const Y=T.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}-${ae}`]));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,ie]of xe)X===`#${L}`&&(X=`#${ie}`),X=X.split(`url(#${L})`).join(`url(#${ie})`);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()),(ke=me?document.body:Y.parentElement)==null||ke.appendChild(ce),se.current=ce,()=>{ce.remove(),se.current=void 0}},[e,ae,te,me]),_.useLayoutEffect(()=>{const Y=se.current;if(!Y||!l)return;const{x:ce,y:ue,size:xe}=l;if(me&&T.current){const pe=T.current,X=pe.getBoundingClientRect(),L=X.width/pe.offsetWidth||1,ie=X.height/pe.offsetHeight||1,H=X.left+(ce-r)*L,fe=X.top+(ue-t)*ie;Y.style.transform=`translate3d(${H}px, ${fe}px, 0) scale(${L}, ${ie})`,Y.style.width=`${pe.offsetWidth}px`,Y.style.height=`${pe.offsetHeight}px`;return}const ke=xe?Math.round(ce-xe.w/2):ce,ye=xe?Math.round(ue-xe.h/2):ue;Y.style.transform=xe?`translate3d(${ke}px, ${ye}px, 0)`:`translate(-50%, -50%) translate3d(${ke}px, ${ye}px, 0)`,Y.style.width=xe?`${Math.round(ce+xe.w/2)-ke}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=T.current;if(!Y)return;const ce=()=>{const ke=qb(Y);K(ye=>JSON.stringify(ye)===JSON.stringify(ke)?ye:ke),A==null||A(e,ke)};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,T.current),()=>{d(e,null),A==null||A(e,void 0)}),[e,d,A]),_.useLayoutEffect(()=>{const Y=T.current;if(!Y)return;let ce="";const ue=()=>{const pe=kj(Y),X=j?pe:pe.filter(ie=>ie.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),ke=()=>{xe.disconnect(),xe.observe(Y),Y.querySelectorAll("[data-flow-property]").forEach(pe=>xe.observe(pe)),ue()};ke();const ye=new MutationObserver(ke);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:T,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:((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(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:((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: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 T=_.useRef(null),I=_.useRef(null),N=_.useRef(null),$=_.useRef(null),M=_.useMemo(()=>new Ij(p,u,h),[]);_.useEffect(()=>{M.minZoom=u,M.maxZoom=h},[M,u,h]),_.useLayoutEffect(()=>{M.setAnimationsDisabled(w)},[M,w]);const K=_.useRef(new Map),ae=_.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,ke]=_.useState(new Map),ye=_.useRef(xe),pe=()=>{ye.current=new Map,ke(ye.current)},X=_.useRef(new Map),L=_.useRef(null),ie=_.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),!ie.current&&R.current.fitOnInit!==!1&&(Be.current=!0),clearTimeout(Ne.current),Ne.current=setTimeout(()=>{ie.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,_e=>{const Ie=new Map;if(k.forEach((Ee,Oe)=>{const Ke=Pe.get(Oe);Ie.set(Oe,Ke?{x:Ke.x+(Ee.x-Ke.x)*_e,y:Ke.y+(Ee.y-Ke.y)*_e}:Ee)}),ue.current=Ie,ce(Ie),de){const Ee=new Map;for(const[Oe,Ke]of de){const ee=we.get(Oe)??Ke;Ee.set(Oe,{w:ee.w+(Ke.w-ee.w)*_e,h:ee.h+(Ke.h-ee.h)*_e})}ye.current=Ee,ke(Ee)}z==null||z(_e)},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 Ee=ae.current.get(Ie.id);Ee&&(Ee.offsetWidth||Ee.offsetHeight)&&K.current.set(Ie.id,{w:Ee.offsetWidth,h:Ee.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,Ee=k.edgeMode!=="nodes"&&k.edgeMode!=="workflow",Oe=z.edges.map(Ke=>({...Ke,connectorClearance:Ie?Ee&&(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(([Ee,Oe])=>[Ee,{x:Oe.x+Ie.x,y:Oe.y+Ie.y}]))}for(const[Ie,Ee]of X.current)de.has(Ie)?de.set(Ie,Ee):k.nodes.some(Oe=>Oe.id===Ie)||X.current.delete(Ie);const _e=M.coordinate(()=>{var Ie;return(Ie=Je.current)==null?void 0:Ie.call(Je,de)});br(de,ie.current&&!k.isPerformanceMode&&!k.disableAnimations,_e)},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&&(ie.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 _e=se.current.get(we.target);if(!_e||ye.current.has(_e))continue;const Ie=we.target,Ee=Ie.offsetWidth,Oe=Ie.offsetHeight;if(!Ee&&!Oe)continue;const Ke=K.current.get(_e);if(Ke&&Ke.w===Ee&&Ke.h===Oe)continue;const ee=ue.current.get(_e);Ke&&ee&&ie.current&&!L.current&&(L.current={id:_e,position:{...ee}}),K.current.set(_e,{w:Ee,h:Oe}),Pe=!0}Pe&&(Je.current&&!tt.current?Fe():re())})),q){ae.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=ae.current.get(k);de&&((J=te.current)==null||J.unobserve(de),se.current.delete(de)),ae.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 Ce=_.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}},[]),je=_.useMemo(()=>{const k=new Map;for(const q of r){const z=Ce(q.id);z&&k.set(q.id,z)}return Uw(D,k,me,t,n)},[D,r,Y,U,me,t,n,Ce]);B.current=je;const Xe=(k,q)=>{var de;if(!P||q===void 0)return;const z=(de=je.get(k))==null?void 0:de.find(Pe=>Pe.property===q),J=Ce(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=je.get(k))==null?void 0:de.find(we=>we.property===q))==null?void 0:Pe.anchor,J=Ce(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=Ce(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=Ce(z);J&&k.push(Kt(J))}),he.current.forEach(q=>k.push(q));try{for(const q of[I.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}=M;$.current&&($.current.style.transform=`translate3d(${k.x}px, ${k.y}px, 0) scale(${q})`),(z=I.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=M.onChange(()=>{St();const J=T.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,M.state)}))});return()=>{z(),clearTimeout(q),k!==null&&cancelAnimationFrame(k)}},[]),_.useLayoutEffect(()=>{const k=T.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=M.size.w!==J||M.size.h!==de;M.size={w:J,h:de},Pe&&((we=Ge.current)!=null&&we.options.fill)&&re(),!ie.current&&!ue.current.size&&R.current.fitOnInit!==!1&&(M.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()},[M]),_.useLayoutEffect(()=>{if(Ht.current){Ht.current=!1;const q=Et.current.flatMap(J=>{const de=Ce(J);return de?[Kt(de)]:[]});Et.current=[];const z=Do(q);if(z){Be.current=!1,M.center(z,R.current.animateViewport);return}}if(!Be.current)return;Be.current=!1;const k=kt();k&&(M.fit(k,50,ie.current&&R.current.animateViewport),ie.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:{...M.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,M.cancelAnimation();const Se=Q&&!R.current.isPerformanceMode&&!R.current.disableAnimations,ot=M.coordinate(()=>{var ze;oe?oe(Se):Re&&((ze=Je.current)==null||ze.call(Je,ee))});br(new Map([...ee].map(([ze,pt])=>[ze,{...pt}])),Se,ot,ge,We)},de=(ee,Q=50,ge=R.current.animateViewport,oe=1,We=!1)=>{const Re=Se=>{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(!Se&&(!ee||[...ee].some(Rt=>pt.has(Rt))))return;const or=Se&&yd(ot.nodes,Se,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=Se==null?void 0:Se.get(Rt),Un=K.current.get(Rt)||Zn,sn=an?{...an,...Un}:Ce(Rt);return sn?[Kt(sn)]:[]}));ir&&(Be.current=!1,Et.current=[],Ht.current=!1,M.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(!Ce(ee))return;const We=Q==="connections"?_e(ee):z(ee);if(Q==="connections"&&nr.current===1.25&&((Re=lt.current)==null?void 0:Re.size)===We.size&&[...We].every(Se=>lt.current.has(Se))){S({id:ee,mode:Q});return}Ut.current||(Ut.current={pan:{...M.pan},zoom:M.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()},_e=ee=>Wu(ee,R.current.nodes,R.current.edges),Ie=(ee=>{var Q,ge,oe;if(ee===void 0)return M.zoom;ee<M.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,M.set(void 0,ee))}),Ee=(ee=>{if(ee===void 0)return M.pan;Je.current=null,M.set(ee)}),Oe=(ee,Q)=>{var oe;const ge=(oe=T.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&&M.fit(oe,ee,Q)})};return{zoom:Ie,pan:Ee,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(_e(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&&M.transition(oe,ee)}:oe&&we(()=>M.transition(oe,ee))},zoomAt:(ee,Q)=>{var ge,oe,We;ee<M.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,M.zoomAt(ee,Q))},fit:Ke,centerAndFit:Ke,center:(ee=R.current.animateViewport)=>{Je.current=null;const Q=kt();Q&&M.center(Q,ee)},clientToModel:(ee,Q)=>M.renderedToModel(Oe(ee,Q)),modelToClient:ee=>{var oe;const Q=(oe=T.current)==null?void 0:oe.getBoundingClientRect(),ge=M.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=>Ce(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,M.renderedToModel({x:M.size.w/2,y:M.size.h/2}));const Re=new Set(Q.nodes.map(ze=>ze.id));ge.order=ge.order.filter(ze=>Re.has(ze));const Se=new Set(ge.order);ge.order.push(...Q.nodes.filter(ze=>!Se.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&&!ie.current&&(ie.current=!0,R.current.fitOnInit!==!1&&!ee.fill?mt.centerAndFit(50,!1):R.current.fitOnInit===!1&&M.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)?()=>M.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(Se=>typeof Se!="string")||new Set(Q.order).size!==Q.order.length))throw new Error("Invalid grid node order.");if(ee){ad(q(),k(Q));const Se=!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:M.zoom,pan:{...M.pan}},previousSize:{...M.size},ready:!1}),Se&&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 Se=Ge.current;if(!Se)return;if(M.size.w===Se.previousSize.w&&M.size.h===Se.previousSize.h&&ue.current.size===Se.previousPositions.size&&[...ue.current.keys()].every(pt=>Se.previousPositions.has(pt))?Je.current=()=>M.transition(Se.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),!Se.previousPositions.size){re();return}const ze=new Map([...ue.current].map(([pt,or])=>[pt,Se.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),Se=We.nodes.find(cn=>cn.id===Q);if(!Re||!Se||Re.parent!==Se.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=>M.onChange(ee)}},[]);_.useEffect(()=>{var k,q;return(q=(k=R.current).onInit)==null||q.call(k,mt),()=>M.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=T.current.getBoundingClientRect();return{x:(k.clientX-q.left)*(T.current.clientWidth/q.width||1),y:(k.clientY-q.top)*(T.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=Ce(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(_e=>_e.id===k),J=Ce(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 _e of R.current.nodes){if(_e.id===k||_e.parent!==z.parent||X.current.has(_e.id)||he.current.has(_e.id)||!Qt(_e.id,R.current.edges,R.current.edgeMode)||lt.current&&!lt.current.has(_e.id))continue;const Ie=Ce(_e.id);if(!Ie)continue;const Ee=Kt(Ie),Oe=Math.max(0,Math.min(de.x2,Ee.x2)-Math.max(de.x1,Ee.x1))*Math.max(0,Math.min(de.y2,Ee.y2)-Math.max(de.y1,Ee.y1));Oe>we&&(we=Oe,Pe=_e.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=T.current,we=M.zoom*(Pe&&Pe.clientWidth?Pe.getBoundingClientRect().width/Pe.clientWidth:1),_e=24/we;let Ie;for(const Oe of J){if(Oe.id===k||Oe.parent!==de.parent)continue;const Ke=Ce(Oe.id);if(!Ke)continue;const ee=Kt(Ke),Q=Math.min(Ke.w/4,_e),ge=Math.min(Ke.h/4,_e),oe=3/we,We=[];if(q.y>ee.y1+ge&&q.y<ee.y2-ge)for(const Re of["before","after"]){const Se=Re==="before"?ee.x1:ee.x2,ot=Math.abs(q.x-Se),ze=Re==="before"?q.x<Se:q.x>Se;ot<=(ze?_e:Q)&&We.push({side:Re,distance:ot,marker:{x1:Se-oe/2,x2:Se+oe/2,y1:ee.y1,y2:ee.y2}})}if(q.x>=ee.x1&&q.x<=ee.x2)for(const Re of["above","below"]){const Se=Re==="above"?ee.y1:ee.y2,ot=Math.abs(q.y-Se),ze=Re==="above"?q.y<Se:q.y>Se;ot<=(ze?_e:ge)&&We.push({side:Re,distance:ot,marker:{x1:ee.x1,x2:ee.x2,y1:Se-oe/2,y2:Se+oe/2}})}for(const Re of We)(!Ie||Re.distance<Ie.distance)&&(Ie={id:Oe.id,...Re})}if(!Ie)return;const Ee=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 Ee?{options:Ee,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/M.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=Ce(Pe.id),_e=B.current.get(Pe.id);if(!we||!_e||he.current.has(Pe.id))continue;const Ie=we.x+(q==="source"!==z?1:-1)*we.w/2;for(const Ee of _e){if(Ee.role&&Ee.role!==q)continue;const Oe=we.y-we.h/2+Ee.top,Ke=Math.hypot(k.x-(Ee.anchor?we.x-we.w/2+Ee.anchor.x:Ie),k.y-Oe-Ee.height/2);if(!Ee.anchor&&k.x>=we.x-we.w/2&&k.x<=we.x+we.w/2&&k.y>=Oe&&k.y<=Oe+Ee.height)return{nodeId:Pe.id,property:Ee.property};Ke<=J&&(!de||Ke<de.distance)&&(de={nodeId:Pe.id,property:Ee.property,distance:Ke})}}return de},ex=k=>{var _e,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 Ee=bm(vt.current);if(Ee){Wt(null),ft.current={kind:"pinch",distance:Ee.distance,zoom:M.zoom,anchor:M.renderedToModel(Ee.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 Ee=(_e=q.closest("[data-node-id]"))==null?void 0:_e.dataset.nodeId;if(Ee&&!X.current.has(Ee)){q.setPointerCapture(k.pointerId),ft.current={kind:"grid",pointerId:k.pointerId,captureTarget:q,source:Ee,start:J,moved:!1};return}if(Ee)return}if(de&&(z.drawMode||Pe||we)){const Ee=M.renderedToModel(J),Oe=z.drawMode?Mo(Ee,"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(Ee),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:Ee,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:M.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 _e=Math.max(M.minZoom,Math.min(M.maxZoom,q.zoom*we.distance/q.distance));if(_e<M.zoom&&((J=Ge.current)!=null&&J.options.fill)&&((Pe=(de=R.current).onNodeGridZoomOut)==null?void 0:Pe.call(de,Ge.current.options))===!0)return;M.set({x:we.center.x-q.anchor.x*_e,y:we.center.y-q.anchor.y*_e},_e);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,M.cancelAnimation()),q.moved=!0,Tt.current=!0,k.preventDefault();const _e={x:we.x/M.zoom,y:we.y/M.zoom},Ie=!k.shiftKey&&z.x>=0&&z.y>=0&&z.x<=M.size.w&&z.y<=M.size.h?du(q.source,M.renderedToModel(z)):void 0;Wt({source:q.source,offset:_e,target:k.shiftKey||Ie?null:lu(q.source,_e),shiftKey:k.shiftKey,insertion:Ie});break}case"pan":{const we=z.x-q.start.x,_e=z.y-q.start.y;if(!q.moved&&Math.hypot(we,_e)<=sd)return;q.moved=!0,Tt.current=!0,M.set({x:q.pan0.x+we,y:q.pan0.y+_e});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=M.renderedToModel(z),_e=Mo(we,q.reverse?"source":"target");rn(q.reverse&&_e?{source:_e.nodeId,sourceProperty:_e.property,point:we,target:q.source,targetProperty:q.sourceProperty}:{source:q.source,sourceProperty:q.sourceProperty,point:we,target:(_e==null?void 0:_e.nodeId)??Wn(we,q.source),targetProperty:_e==null?void 0:_e.property});break}}},uu=(k,q)=>{var de,Pe,we,_e,Ie,Ee,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:M.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<=M.size.w&&oe.y<=M.size.h){const Re=du(z.source,M.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>M.size.w||oe.y>M.size.h)break;if(k.shiftKey){const Re=new Map(J.nodes.map(ze=>[ze.id,ze]));let Se=Wn(M.renderedToModel(oe),z.source);const ot=new Set;for(;Se&&!((Pe=Re.get(Se))!=null&&Pe.acceptsChildren)&&!ot.has(Se);)ot.add(Se),Se=((we=Re.get(Se))==null?void 0:we.parent)??null;if(Se&&((_e=Re.get(Se))!=null&&_e.acceptsChildren)){let ze=Se;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)||(Ee=J.onNodeParentChange)==null||Ee.call(J,z.source,Se)}break}if(!Ge.current)break;const We=lu(z.source,{x:(oe.x-z.start.x)/M.zoom,y:(oe.y-z.start.y)/M.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=M.renderedToModel(z.start),We=M.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 Se=[];for(const ot of J.nodes){const ze=Ce(ot.id);ze&&Lw(Kt(ze),Re)&&Se.push(ot.id)}Se.length&&((ee=J.onBoxSelect)==null||ee.call(J,Se));break}case"draw":{if(rn(null),q)break;const oe=Gn(k),We=M.renderedToModel(oe),Re=Mo(We,z.reverse?"source":"target"),Se=(Re==null?void 0:Re.nodeId)??Wn(We);if(Se===z.source&&(z.sourceProperty===void 0||(Re==null?void 0:Re.property)===void 0||Re.property===z.sourceProperty))break;Se?(Q=J.onEdgeDraw)==null||Q.call(J,z.reverse?Se:z.source,z.reverse?z.source:Se,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=T.current)!=null&&z.hasPointerCapture(J)&&T.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(()=>{T.current&&Oo&&Ej(T.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:T,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:I,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:M.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,_e=De?Y.get(De.source):void 0,Ie=De!=null&&De.target?Y.get(De.target):void 0,Ee=_e&&Ie?{x:Ie.x-_e.x,y:Ie.y-_e.y}:void 0,Oe=Ee?Ee.x**2+Ee.y**2:0,Ke=Oe&&De&&Ee?Math.max(0,Math.min(1,(De.offset.x*Ee.x+De.offset.y*Ee.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(Se=>[...Se.source===k.id&&Se.sourceProperty!==void 0?[`source:${Se.sourceProperty}`]:[],...Se.target===k.id&&Se.targetProperty!==void 0?[`target:${Se.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:je.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(${M.pan.x} ${M.pan.y}) scale(${M.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=>fr(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
- `,Oj=Qn.default.div`
235
+ `,Fj=io.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 Qd({nodeAddress:e,active:r,label:t,open:n=!1,onClose:i,children:o,filter:s,height:a,width:c}){const{background:l,border:d,colorText:u}=it(),{colorMode:h}=He(),p=S.useRef(null),y=S.useId(),{data:m,schema:g,bindings:b}=S.useContext(Mt),v=o!==void 0||!!(m&&g&&(b?Pn(b,e,g):Jr(m,e,g)));S.useEffect(()=>{var w,C,j,_,k;!r||!v||!n?(w=p.current)==null||w.close():(C=p.current)!=null&&C.open||((j=p.current)==null||j.showModal(),(k=(_=p.current)==null?void 0:_.querySelector("[data-form-filter] input"))==null||k.focus())},[r,v,n]);const x=Ee(l);return v?f.jsx(f.Fragment,{children:typeof document<"u"&&Br.createPortal(f.jsx(Tj,{ref:p,id:y,$surface:x,$border:Ee(d),"aria-label":`Configure ${t}`,onClose:i,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:Ee(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(Kr,{"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(Oj,{$divider:`var(--chakra-colors-gray-${h==="dark"?"700":"200"})`,"data-form-scroll":"",style:a?{flex:1}:void 0,children:o??f.jsx(Ed,{nodeAddress:e})})]})}),document.body)}):null}const ud=({icon:e,label:r,onClick:t,color:n,boxSize:i=6,...o})=>{const{background:s,border:a,colorText:c}=it();return f.jsx(Be,{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:i,color:n,cursor:t?"pointer":void 0})})})})},Nj=({data:e,children:r,isInverted:t,isParent:n,onOpenView:i,editOnMount:o=!1})=>{var oe,ce,xe,je,ye,ge;const{selectedNodeIds:s,setSelectedNodeIds:a,selectedEdgeId:c,setSelectedEdgeId:l,isMultiSelectMode:d,nodeGridOptions:u,isPerformanceMode:h,engineRef:p,callbacks:y,config:m,themeColor:g,direction:b,nodeViewModes:v}=He(),{background:x,border:w,colorText:C}=it(),j=S.useRef(null),_=S.useRef(null),[k,E]=S.useState(!1),[O,T]=S.useState(o&&!!m.editable&&!m.readOnly),[P,I]=S.useState(!1),R=e==null?void 0:e.id,$=cb(R),N=s.includes(R),M=m.nodeOverlayActions,J=m.renderNodeOverlay,ae=(e==null?void 0:e.type)==="grid"?"20px":"-100px",se=(e==null?void 0:e.type)==="grid"?"top center":void 0,ee=(()=>{var z;try{const W=(z=p.current)==null?void 0:z.zoom();return W!==void 0&&W<.08}catch{return!1}})(),pe=S.useCallback(z=>{var ie,K,ue,ve;if(O||m.readOnly)return;const W={shiftKey:z.shiftKey,ctrlKey:z.ctrlKey,metaKey:z.metaKey,altKey:z.altKey};if(c&&(l(null),(ie=y.onEdgeDeselect)==null||ie.call(y)),d||z.shiftKey&&(u!=null&&u.fill)){const Oe=s.includes(R),$e=Oe?s.filter(De=>De!==R):[...s,R];a($e),Oe?(K=y.onNodeDeselect)==null||K.call(y):(ue=y.onNodeSelect)==null||ue.call(y,R,e,W)}else a([R]),(ve=y.onNodeSelect)==null||ve.call(y,R,e,W)},[R,e,s,c,d,u,O,a,l,y,m]),me=S.useCallback(()=>{var z;O||m.readOnly||(z=y.onNodeDoubleClick)==null||z.call(y,R,e)},[R,e,O,y,m]),q=S.useCallback(()=>{_.current&&clearTimeout(_.current),_.current=setTimeout(()=>E(!0),100)},[]),F=S.useCallback(()=>{_.current&&clearTimeout(_.current),E(!1)},[]),H=!!((oe=e==null?void 0:e.config)!=null&&oe.form),B={tabIndex:H?0:void 0,"aria-haspopup":H?"dialog":void 0,"aria-expanded":H?P:void 0,onDoubleClickCapture:z=>{var W;!H&&!i||m.readOnly||O||!z.currentTarget.contains(z.target)||z.target instanceof Element&&z.target.closest("button, input, textarea, select, a, [contenteditable=true], [data-flow-content]")||(z.preventDefault(),z.stopPropagation(),a([R]),i?i():I(!0),(W=y.onNodeDoubleClick)==null||W.call(y,R,e))},onKeyDown:z=>{!H&&!i||m.readOnly||z.target!==z.currentTarget||z.key!=="Enter"||(z.preventDefault(),z.stopPropagation(),a([R]),i?i():I(!0))}},de=H&&f.jsx(Qd,{nodeAddress:R,active:N,label:e.label||e.headerTitle||"Node",open:P,onClose:()=>{var z;I(!1),N&&((z=j.current)==null||z.focus({preventScroll:!0}))}}),Y=Array.isArray((ce=e==null?void 0:e.config)==null?void 0:ce.ports)?e.config.ports.map(z=>f.jsx(Bv,{...z},`${z.id}:${z.role}`)):null;return n?f.jsxs(V.Box,{ref:j,...B,onClick:pe,onDoubleClick:me,onMouseEnter:q,onMouseLeave:F,cursor:"pointer",position:"relative",children:[de,!h&&(J||M&&M.length>0)&&k&&!ee&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>E(!0),onMouseLeave:F}),J?f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:ae,transformOrigin:se,left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>E(!0),onMouseLeave:F,willChange:"transform",children:J({nodeId:R,nodeData:e,isRoot:R==="root",isParent:!0,isHovered:k,setIsHovered:E})}):f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:ae,transformOrigin:se,left:"50%",bg:x,p:3,borderColor:w,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>E(!0),onMouseLeave:F,willChange:"transform",children:f.jsx(V.HStack,{px:2,gap:2,children:M.map((z,W)=>f.jsxs(V.Box,{display:"contents",children:[W>0&&f.jsx(V.Box,{borderColor:w,height:5,borderRightWidth:1}),f.jsx(ud,{icon:z.icon,label:z.label,color:C,bgColor:x,borderColor:w,textColor:C,boxSize:5,onClick:ie=>{var K;ie.stopPropagation(),(K=y.onNodeHoverAction)==null||K.call(y,z.id,R,e)}})]},z.id))})})]}),r({id:R,data:e,isActive:N,isLowZoom:ee,isEditing:O,onEditStart:()=>T(!0),onEditEnd:()=>T(!1)}),$&&!((xe=e==null?void 0:e.config)!=null&&xe.parentContainer)&&((je=e==null?void 0:e.config)==null?void 0:je.collapsed)!==void 0&&(()=>{var ie;const z=b==="TB"||b==="BT",W=t||b==="RL";return f.jsx(V.IconButton,{position:"absolute",...z?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:W?void 0:"-75px",left:W?"-75px":void 0,top:"50%",transform:"translateY(-50%)"},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:m.readOnly,onClick:K=>{var ue;K.stopPropagation(),(ue=y.onNodeCollapse)==null||ue.call(y,R,!e.config.collapsed)},bgColor:Ee(((ie=e==null?void 0:e.viewProps)==null?void 0:ie.bgColor)||g),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Z.PiPlusBold,{size:30,color:Ee("gray.800")}):f.jsx(Z.PiMinusBold,{size:30,color:Ee("gray.800")})})})()]}):f.jsxs(V.Box,{ref:j,...B,onClick:pe,onDoubleClick:me,onMouseEnter:q,onMouseLeave:F,cursor:"pointer",transition:"transform 0.1s ease",position:"relative",children:[de,Y,!h&&(J||M&&M.length>0)&&k&&!ee&&f.jsxs(f.Fragment,{children:[f.jsx(V.Box,{position:"absolute",top:-150,left:"0",right:"0",height:"150px",pointerEvents:"auto",onMouseEnter:()=>E(!0),onMouseLeave:F}),J?f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:ae,transformOrigin:se,left:"50%",pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",onMouseEnter:()=>E(!0),onMouseLeave:F,willChange:"transform",children:J({nodeId:R,nodeData:e,isRoot:R==="root",isParent:!!n,isHovered:k,setIsHovered:E})}):f.jsx(V.Box,{position:"absolute",zIndex:1e3,top:ae,transformOrigin:se,left:"50%",bg:x,p:3,borderColor:w,borderWidth:1,borderRadius:15,pointerEvents:"auto",transform:"translateX(-50%) scale3d(3, 3, 1)",boxShadow:"lg",onMouseEnter:()=>E(!0),onMouseLeave:F,willChange:"transform",children:f.jsx(V.HStack,{px:2,gap:2,children:M.map((z,W)=>f.jsxs(V.Box,{display:"contents",children:[W>0&&f.jsx(V.Box,{borderColor:w,height:5,borderRightWidth:1}),f.jsx(ud,{icon:z.icon,label:z.label,color:C,bgColor:x,borderColor:w,textColor:C,boxSize:5,onClick:ie=>{var K;ie.stopPropagation(),(K=y.onNodeHoverAction)==null||K.call(y,z.id,R,e)}})]},z.id))})})]}),f.jsxs(V.Box,{position:"relative",display:"flex",h:"100%",w:"100%",children:[$&&!((ye=e==null?void 0:e.config)!=null&&ye.parentContainer)&&((ge=e==null?void 0:e.config)==null?void 0:ge.collapsed)!==void 0&&!n&&(()=>{var K,ue,ve;const z=b==="TB"||b==="BT",W=t||b==="RL",ie=(K=e==null?void 0:e.config)!=null&&K.labelBelow&&v[R]!=="properties"?((((ue=e==null?void 0:e.viewProps)==null?void 0:ue.fontSize)||1)*100+100)/2:void 0;return f.jsx(V.IconButton,{position:"absolute",...z?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:W?void 0:ie===void 0?"-75px":`calc(50% - ${ie+75}px)`,left:W?ie===void 0?"-75px":`calc(50% - ${ie+75}px)`:void 0,alignSelf:ie===void 0?"center":void 0,top:ie===void 0?void 0:`${ie}px`,transform:ie===void 0?void 0:"translateY(-50%)",zIndex:ie===void 0?void 0:1},"data-flow-collapse-control":"","aria-label":e.config.collapsed?"Expand":"Collapse",disabled:m.readOnly,onClick:Oe=>{var $e;Oe.stopPropagation(),($e=y.onNodeCollapse)==null||$e.call(y,R,!e.config.collapsed)},bgColor:Ee(((ve=e==null?void 0:e.viewProps)==null?void 0:ve.bgColor)||g),size:"md",color:"gray.100",rounded:"full",mr:2,px:2,py:4,children:e.config.collapsed?f.jsx(Z.PiPlusBold,{size:30,color:Ee("gray.800")}):f.jsx(Z.PiMinusBold,{size:30,color:Ee("gray.800")})})})(),r({id:R,data:e,isActive:N,isLowZoom:ee,isEditing:O,onEditStart:()=>T(!0),onEditEnd:()=>T(!1)})]})]})},$n=S.memo(Nj),$j=({id:e,data:r,isActive:t,isEditing:n,onEditStart:i,onEditEnd:o})=>{var m,g,b,v,x,w,C,j;const{themeColor:s}=He(),{colorText:a}=it(),c=((m=r==null?void 0:r.viewProps)==null?void 0:m.bgColor)==="transparent",l=((g=r==null?void 0:r.viewProps)==null?void 0:g.outline)===!0,{highlightColor:d,borderColor:u,textColor:h}=An(((b=r==null?void 0:r.viewProps)==null?void 0:b.bgColor)||s),p=Ee(((v=r==null?void 0:r.viewProps)==null?void 0:v.textColor)||(c||l?a:h)),y=((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,...Rn(r==null?void 0:r.viewProps,y,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:[((j=r==null?void 0:r.config)==null?void 0:j.icon)&&f.jsx(V.Box,{flexShrink:0,children:f.jsx(Jt,{name:r.config.icon,size:80,color:p})}),f.jsx(Ur,{nodeId:e,label:(r==null?void 0:r.label)||(r==null?void 0:r.text)||"",color:p,isEditing:n,onEditStart:i,onEditEnd:o})]})})};function qn(){const{nodeViewModes:e,setNodeViewMode:r,allNodesIconLabel:t,setAllNodesIconLabel:n}=He();return{allNodesIconLabel:t,setAllNodesIconLabel:n,getNodeViewMode:i=>e[i]??"default",showNodeProperties:i=>r(i,"properties"),restoreNodeView:i=>r(i,"default"),toggleNodeView:i=>r(i,e[i]==="properties"?"default":"properties"),setNodeViewMode:r}}function eu(e,r,t){const{readOnly:n,selectedNodeIds:i}=He(),o=i.includes(e),s=S.useRef(o),a=S.useRef(t);a.current=t,S.useEffect(()=>{s.current&&!o&&r&&!n&&a.current(),s.current=o},[o,r,n])}const qj=({id:e,isActive:r,data:t,isEditing:n,onEditStart:i,onEditEnd:o})=>{var x,w,C,j,_,k,E,O,T,P,I,R,$,N,M;const{themeColor:s}=He(),{colorText:a}=it(),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}=An(d),y=Ee(((j=t==null?void 0:t.viewProps)==null?void 0:j.textColor)||(c||l?a:p)),m=c&&!l&&!((_=t==null?void 0:t.viewProps)!=null&&_.borderColor)?"transparent":Ee(((k=t==null?void 0:t.viewProps)==null?void 0:k.borderColor)||(l?d:u)),g=c||l?"transparent":d!=null&&d.startsWith("#")?d:Ee(h),b=(E=t==null?void 0:t.config)==null?void 0:E.icon,v=(t==null?void 0:t.label)??(t==null?void 0:t.text)??"";if((O=t==null?void 0:t.config)!=null&&O.labelBelow){const J=(((T=t==null?void 0:t.viewProps)==null?void 0:T.fontSize)||1)*100;return f.jsxs(V.Flex,{"data-flow-icon-label":"",css:{"--flow-grid-on-surface-color":y},direction:"column",align:"center",gap:"24px",width:`${Math.max(J+200,360)}px`,position:"relative",children:[f.jsx(V.Flex,{"data-flow-node-surface":"",align:"center",justify:"center",width:`${J+100}px`,height:`${J+100}px`,flexShrink:0,borderRadius:(P=t==null?void 0:t.viewProps)==null?void 0:P.borderRadius,backgroundColor:g,...Rn(t==null?void 0:t.viewProps,m,r,2),children:!!b&&f.jsx(Jt,{name:b,size:J,color:y})}),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(Ur,{nodeId:e,label:v,color:`var(--flow-grid-caption-color, ${Ee(((I=t==null?void 0:t.viewProps)==null?void 0:I.textColor)||a)})`,isEditing:n,onEditStart:i,onEditEnd:o,wrap:!0}),typeof((R=t.config)==null?void 0:R.subtitle)=="string"&&t.config.subtitle!==""&&f.jsx(V.Text,{"data-flow-node-subtitle":"",color:Ee((($=t==null?void 0:t.viewProps)==null?void 0:$.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:(N=t==null?void 0:t.viewProps)==null?void 0:N.borderRadius,bgColor:g,style:{backgroundColor:g},textTransform:"capitalize",...Rn(t==null?void 0:t.viewProps,m,r,2),px:50,w:"fit-content",whiteSpace:"nowrap",children:[!!b&&f.jsx(V.Flex,{align:"center",py:14,mr:v?8:0,flexShrink:0,children:f.jsx(Jt,{name:b,size:(((M=t==null?void 0:t.viewProps)==null?void 0:M.fontSize)||1)*100,color:y},y)}),(v||!b)&&f.jsx(V.Flex,{justifyContent:"start",py:14,fontSize:"5xl",lineHeight:"normal",w:"fit-content",maxW:900,minW:0,children:f.jsx(Ur,{nodeId:e,label:v,color:y,isEditing:n,onEditStart:i,onEditEnd:o})})]})};function tu({onExpand:e,toggleLabel:r="Show properties",toggleDisabled:t=!1,renderCompact:n=qj,...i}){const{colorMode:o,callbacks:s}=He();return f.jsx($n,{...i,children:a=>f.jsxs(V.Box,{position:"relative",children:[f.jsx(n,{...a}),e&&a.isActive&&f.jsx(V.Box,{position:"absolute",top:"-24px",right:"-48px","data-flow-content-toggle":"",children:f.jsx(Be,{label:r,children:f.jsx(Pe,{"aria-label":r,icon:f.jsx(V.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o==="dark"?"gray.100":"gray.800",disabled:t,onClick:c=>{var l;c.stopPropagation(),e(),(l=s.onNodeViewToggle)==null||l.call(s,i.data.id)}})})})]})})}const Lj=`${Rb}
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,ke,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),[T,I]=_.useState(!1),N=e==null?void 0:e.id,$=fb(N),M=a.includes(N),K=g.nodeOverlayActions,ae=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 ie=(L=m.current)==null?void 0:L.zoom();return ie!==void 0&&ie<.08}catch{return!1}})(),ve=_.useCallback(L=>{var H,fe,be,Ne;if(A||g.readOnly)return;const ie={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,ie)}else c([N]),(Ne=y.onNodeSelect)==null||Ne.call(y,N,e,ie)},[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 ie;L.relatedTarget instanceof Node&&((ie=j.current)!=null&&ie.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?T:void 0,onDoubleClickCapture:L=>{var ie;!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():I(!0),(ie=y.onNodeDoubleClick)==null||ie.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():I(!0))}},Y=B&&f.jsx(iu,{nodeAddress:N,active:M,label:e.label||e.headerTitle||"Node",open:T,onClose:()=>{var L;I(!1),M&&((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&&(ae||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}),ae?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:ae({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,ie)=>f.jsxs(V.Box,{display:"contents",children:[ie>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:M,isHovered:E,isLowZoom:me,isEditing:A,onSelect:ve,onEditStart:()=>R(!0),onEditEnd:()=>R(!1)}),$&&!((ke=e==null?void 0:e.config)!=null&&ke.parentContainer)&&((ye=e==null?void 0:e.config)==null?void 0:ye.collapsed)!==void 0&&(()=>{var H;const L=b==="TB"||b==="BT",ie=t||b==="RL";return f.jsx(V.IconButton,{position:"absolute",...L?{[b==="BT"?"top":"bottom"]:"-75px",left:"50%",transform:"translateX(-50%)"}:{right:ie?void 0:"-75px",left:ie?"-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&&(ae||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}),ae?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:ae({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,ie)=>f.jsxs(V.Box,{display:"contents",children:[ie>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",ie=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:ie?void 0:H===void 0?"-75px":`calc(50% - ${H+75}px)`,left:ie?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:M,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,T,I,N,$,M;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(((T=t==null?void 0:t.viewProps)==null?void 0:T.textColor)||a)})`,isEditing:n,onEditStart:o,onEditEnd:i,wrap:!0}),typeof((I=t.config)==null?void 0:I.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:(((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(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}
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 Dv({active:e=!0,label:r="Loading content",radius:t}){const{config:n,themeColor:i}=He(),{colorText:o}=it(),s=S.useRef(null),[a,c]=S.useState({width:0,height:0,radius:0});if(S.useLayoutEffect(()=>{const u=s.current;if(!e||!u)return;const h=()=>{const y=u.parentElement,m={width:u.clientWidth,height:u.clientHeight,radius:t??(y&&parseFloat(getComputedStyle(y).borderTopLeftRadius)||0)};c(g=>g.width===m.width&&g.height===m.height&&g.radius===m.radius?g:m)},p=new ResizeObserver(h);return p.observe(u),h(),()=>p.disconnect()},[e,t]),!e)return null;const l=Ee(i||o),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:Lj}),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(Zn,{...d,strokeWidth:6})}),f.jsx(Zn,{...d})]})]})}function Fj({content:e,format:r,onEdit:t}){var $;const{config:n,colorMode:i}=He(),{background:o,border:s,colorInactive:a}=it(),c=($=n.customViews)==null?void 0:$.jsxContent,l=typeof e=="string"?e:JSON.stringify(e,null,2);let d,u;if(r==="jsx")try{const N=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(N)||N.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=N}catch(N){u=N instanceof Error?N.message:"Invalid components array."}const h=S.useRef(null),p=S.useRef(null),y=S.useRef(null),m=S.useRef(!1),[g,b]=S.useState(!1),[v,x]=S.useState(""),w=!!t;S.useEffect(()=>{const N=()=>{var J;const M=document.fullscreenElement===p.current;b(M),m.current&&!M&&!document.fullscreenElement&&((J=y.current)==null||J.focus({preventScroll:!0})),m.current=M};return document.addEventListener("fullscreenchange",N),()=>document.removeEventListener("fullscreenchange",N)},[]);const C=async()=>{var N;x("");try{if(document.fullscreenElement===p.current)await document.exitFullscreen();else if((N=p.current)!=null&&N.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.")}},[j,_]=S.useState(),[k,E]=S.useState(),[O,T]=S.useState();S.useEffect(()=>{if(r==="jsx")return;let N=!1;return Promise.resolve().then(()=>require("./contentPreviewDocument-BsKd0dD4.cjs")).then(({contentPreviewDocument:M})=>M(l,r,w)).then(M=>{N||_({content:l,format:r,editable:w,document:M})},M=>{N||_({content:l,format:r,editable:w,error:M instanceof Error?M.message:String(M)})}),()=>{N=!0}},[l,r,w]),S.useEffect(()=>{if(!t)return;const N=async M=>{var J,ae;if(!(!((J=h.current)!=null&&J.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",N),()=>window.removeEventListener("message",N)},[t]);const P=(j==null?void 0:j.content)===l&&j.format===r&&j.editable===w?j:void 0,I=!!P&&P===O,R=r!=="jsx"&&!(P!=null&&P.error)&&!I&&(!P||k!==P);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"?R:void 0,bg:r==="jsx"&&i==="dark"?"gray.900":"white",onDoubleClick:N=>{r!=="jsx"||!t||N.defaultPrevented||N.target.closest('button, a, input, textarea, select, [contenteditable], [role="button"], [role="textbox"]')||(N.stopPropagation(),(async()=>{document.fullscreenElement===p.current&&await document.exitFullscreen(),t()})().catch(M=>x(String(M))))},onKeyDownCapture:N=>{N.key!=="Escape"||document.fullscreenElement!==p.current||(N.preventDefault(),N.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(kd,{background:o,border:i==="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(Pe,{"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:N=>{N.stopPropagation(),(async()=>{document.fullscreenElement===p.current&&await document.exitFullscreen(),t()})().catch(M=>x(String(M)))}}),f.jsx(Pe,{ref:y,"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:N=>{N.stopPropagation(),C()}})]})})}),v&&f.jsx(V.Box,{role:"alert",position:"absolute",bottom:0,insetInline:0,bg:"white",color:"red.700",fontSize:"14px",children:v}),r==="jsx"?u?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:u}):c&&d?f.jsx(c,{components:d,colorMode:i,fillHeight:!0}):f.jsx(V.Box,{role:"status",fontSize:"14px",children:"JSX content renderer is not available."}):P!=null&&P.error||I?f.jsx("pre",{role:"alert",style:{whiteSpace:"pre-wrap"},children:(P==null?void 0:P.error)||"Content preview could not be loaded."}):P!=null&&P.document?f.jsx("iframe",{ref:h,title:`${r.toUpperCase()} content preview`,sandbox:w?"allow-scripts":"",allowFullScreen:!0,referrerPolicy:"no-referrer",srcDoc:P.document,onLoad:()=>E(P),onError:()=>T(P),style:{width:"100%",height:"100%",border:0,display:"block",background:"white",visibility:R?"hidden":"visible"}},P.document):null,f.jsx(Dv,{active:R,label:"Loading HTML content"})]})]})}const gm=1.55;function zj({nodeId:e,content:r,color:t,format:n="markdown"}){const{callbacks:i,config:o,readOnly:s,nodeGridOptions:a}=He(),c=!!o.editable&&!s&&!a,l=typeof r=="string"?r:JSON.stringify(r,null,2),[d,u]=S.useState(!1),[h,p]=S.useState(l),[y,m]=S.useState(""),[g,b]=S.useState(),v=S.useRef(null),x=S.useRef(!1),w=Yd(d);S.useLayoutEffect(()=>{const _=v.current;!d||!_||(_.style.height="auto",_.style.height=`${Math.max((g==null?void 0:g.height)??0,_.scrollHeight)}px`)},[h,d,g]),S.useEffect(()=>{var _,k;c?d&&(x.current=!1,(_=v.current)==null||_.focus({preventScroll:!0}),(k=v.current)==null||k.select()):u(!1)},[d,c]);const C=_=>{c&&(b({width:_.offsetWidth,height:_.offsetHeight}),p(l),m(""),u(!0))},j=()=>{var k;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){m(E instanceof Error?E.message:"Invalid components array.");return}x.current=!0,h!==l&&((k=i.onNodeContentChange)==null||k.call(i,e,_)),u(!1)};return(!d||!c)&&n!=="markdown"?f.jsx(V.Box,{ref:w,w:"100%",position:"relative","data-flow-content":"",children:f.jsx(Fj,{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:gm,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(hx.default,{options:{forceBlock:!0,wrapper:S.Fragment,disableParsingRawHTML:!0,overrides:{a:{props:{target:"_blank",rel:"noopener noreferrer"}},img:{props:{loading:"lazy",referrerPolicy:"no-referrer"}}}},children:l||(c?"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:v,"aria-label":"Node content",placeholder:"Write your content here",value:h,"aria-invalid":!!y,onChange:_=>p(_.target.value),onBlur:j,onKeyDown:_=>{_.stopPropagation(),!_.nativeEvent.isComposing&&(_.key==="Enter"&&(_.ctrlKey||_.metaKey)&&(_.preventDefault(),j()),_.key==="Escape"&&(x.current=!0,u(!1)))},color:t,fontFamily:"inherit",fontSize:"inherit",lineHeight:gm,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"}),y&&f.jsx(V.Box,{role:"alert",fontSize:"14px",color:"red.500",children:y})]})}const Bj=(e,r,t)=>{var h,p,y,m;const n=((h=e==null?void 0:e.viewProps)==null?void 0:h.bgColor)||r,[i]=n.split("."),o=An(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("#")?Ee(n):Ee(o.bgColor),d=Ee(((y=e==null?void 0:e.viewProps)==null?void 0:y.textColor)||(a?c:o.textColor)),u=Ee(((m=e==null?void 0:e.viewProps)==null?void 0:m.borderColor)||(s?n==="transparent"?r:n:o.borderColor));return{...o,bgColor:a?"transparent":o.bgColor,highlightColor:a?"transparent":o.highlightColor,isTransparent:a,propertyColor:a?c:o.propertyColor,bg:n,wordBeforeDot:i,hexbgColor:l,hextextColor:d,hexborderColor:u}},Dj=(e,r=350)=>`${String(e).substring(0,r)}${String(e).length>r?"...":""}`,Vj=e=>e!=null&&e.includes("root")?e.replace("root","untitled"):e,Vv=600,Gj=3,Wj=e=>{const r=Math.max(...Object.keys(e||{}).map(n=>n.length),0);return Math.max(r*28+30,200)};function Uj({headerTitle:e,hasContent:r,data:t,icon:n,colors:i,hasConfig:o,id:s,isActive:a,isEditing:c,onEditStart:l,onEditEnd:d,props:u,objVisible:h,setObjVisible:p,onShowNativeIcon:y}){var v,x;const{callbacks:m}=He(),g=u.onShowIcon??y,b=g?"Show icon":h?"Show content":"Show properties";return f.jsx(f.Fragment,{children:(e||r||((v=t.config)==null?void 0:v.form)||a&&y)&&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:i.propertyColor,bgColor:i.highlightColor,borderBottomColor:!o&&!r?"transparent":i.hexborderColor,children:[!!n&&f.jsx(V.Flex,{mr:6,alignItems:"center",flexShrink:0,children:f.jsx(Jt,{name:n,size:64,color:i.hextextColor},i.hextextColor)}),f.jsx(Ur,{nodeId:s,label:Vj(e),color:((x=t==null?void 0:t.viewProps)==null?void 0:x.textColor)||i.propertyColor,isEditing:c,onEditStart:l,onEditEnd:d}),a&&(r||g)&&f.jsx(V.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:f.jsx(Be,{label:b,children:f.jsx(Pe,{"aria-label":b,icon:f.jsx(V.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:i.hextextColor,onClick:w=>{var C;w.stopPropagation(),g?g():p(!h),(C=m.onNodeViewToggle)==null||C.call(m,s)}})})})]})})}function Hj({data:e,resourcePorts:r,inspecting:t,form:n,inspectionPorts:i,extraPorts:o,colors:s,direction:a,uniformKeyWidth:c}){const{edgeById:l}=pr(),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 I,R,$;const y=r&&Object.keys(r).find(N=>N.slice(N.indexOf(":")+1)===u),m=t&&((I=n==null?void 0:n.type.ports)==null?void 0:I[u]),g=y??(m?`${m.kind}:${u}`:u),b=i.find(N=>N.id===g),v=y?"source":b==null?void 0:b.role,x=d.has(`source:${g}`),w=d.has(`target:${g}`),C=o.some(N=>N.id===u),j=h===""&&(C||(v?d.has(`${v}:${g}`):x||w)),_=v??(x!==w?x?"source":"target":void 0),k=(b==null?void 0:b.side)??(_?_==="source"!=(a==="RL")?"right":"left":void 0),E=j&&k==="right"?"right":"left",O=(b==null?void 0:b.label)??(m==null?void 0:m.label)??(C?u.replace(/^(template|input|output|config|error):/,""):u),T=Kt(s.wordBeforeDot)[typeof h],P=Kt(s.wordBeforeDot).property;return f.jsxs(V.Box,{"data-flow-property":y&&(a==="TB"||a==="BT")?void 0:g,"data-flow-port-role":v,"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:j?"100%":`${c}px`,minWidth:`${c}px`,borderRightColor:s.hexborderColor,borderRightWidth:j?0:1,children:f.jsx(V.Text,{py:5,px:10,w:"100%",textAlign:E,whiteSpace:"nowrap",fontWeight:"bold",fontSize:"4xl",color:((R=e==null?void 0:e.viewProps)==null?void 0:R.textColor)||(s.isTransparent?s.hextextColor:P),children:O})}),!j&&f.jsx(V.Flex,{flex:1,justifyContent:"start",overflow:"hidden",p:4,background:s.hexbgColor,w:Vv,maxH:200,children:f.jsx(V.Text,{overflow:"hidden",py:3,px:4,whiteSpace:"normal",textOverflow:"ellipsis",fontSize:"4xl",color:(($=e==null?void 0:e.viewProps)==null?void 0:$.textColor)||(s.isTransparent?s.hextextColor:T),fontWeight:400,children:Dj(h)})})]}),p!==Object.entries(e.description||{}).length-1&&f.jsx(V.Box,{borderTopWidth:1,my:0,borderColor:s.hexborderColor})]},u)})})}function Kj(e){var x,w,C,j,_;const{themeColor:r,colorMode:t,direction:n}=He(),i=qn(),o=i.getNodeViewMode(e.data.id)==="properties",s=k=>i.setNodeViewMode(e.data.id,k?"properties":"default"),a=!!e.onShowIcon||o||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}=S.useContext(Mt),u=(j=c==null?void 0:c[e.data.id])==null?void 0:j.portResources,h=c?Pn(c,e.data.id,d):l&&d?Jr(l,e.data.id,d):void 0,p=h&&Te(l,"address"in h?h.address:e.data.id),y=p&&typeof p=="object"&&h?Object.fromEntries(Object.keys(h.type.properties).filter(k=>{var E;return Object.prototype.hasOwnProperty.call(p,k)&&oo((E=h.fields[k])==null?void 0:E.$visibleWhen,l)}).map(k=>[k,p[k]!==null&&typeof p[k]=="object"?JSON.stringify(p[k],null,2):p[k]===null?"null":p[k]])):{},m=u?Object.fromEntries(Object.entries(u).map(([k,E])=>{var O;return[k.slice(k.indexOf(":")+1),((O=Te(l,E))==null?void 0:O.name)??E.split(".").at(-1)]})):Object.keys(e.data.description??{}).length?e.data.description:y,g=a&&!u?((_=e.data.config)==null?void 0:_.ports)??[]:[],b=g.filter(k=>!Object.prototype.hasOwnProperty.call(m,k.id)&&!Object.entries((h==null?void 0:h.type.ports)??{}).some(([E,O])=>`${O.kind}:${E}`===k.id&&Object.prototype.hasOwnProperty.call(m,E))),v={...m,...Object.fromEntries(b.map(k=>[k.id,""]))};return{themeColor:r,colorMode:t,direction:n,objVisible:o,setObjVisible:s,inspecting:a,resourcePorts:u,form:h,description:v,inspectionPorts:g,extraPorts:b}}const ru=e=>{var v,x,w,C,j,_;const{themeColor:r,colorMode:t,direction:n,objVisible:i,setObjVisible:o,inspecting:s,resourcePorts:a,form:c,description:l,inspectionPorts:d,extraPorts:u}=Kj(e),h=qn(),p=h.getNodeViewMode(e.data.id)==="icon-label",y=!e.onShowIcon&&(typeof((v=e.data.config)==null?void 0:v.content)=="string"||((x=e.data.config)==null?void 0:x.contentFormat)==="jsx"&&Array.isArray((w=e.data.config)==null?void 0:w.content)),m=S.useRef(p);p&&(m.current=!0),eu(e.data.id,y&&!((C=e.data.config)!=null&&C.parentContainer)&&h.allNodesIconLabel&&!p&&m.current,()=>h.setNodeViewMode(e.data.id,"icon-label"));const b=!e.onShowIcon&&!((j=e.data.config)!=null&&j.parentContainer)&&!y?()=>h.setNodeViewMode(e.data.id,"icon-label"):void 0;return!e.onShowIcon&&p?f.jsx(tu,{...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($n,{...e,data:{...e.data,description:l},children:({id:k,data:E,isActive:O,isEditing:T,onEditStart:P,onEditEnd:I})=>{var pe,me,q,F,H,B,de,Y,oe,ce;const R=Bj(E,r,t),$=E.label??E.headerTitle,N=Object.entries(E.description||{}).length>0,M=Wj(E.description),J=(me=(pe=e.data)==null?void 0:pe.config)==null?void 0:me.icon,ae=(F=(q=e.data)==null?void 0:q.config)==null?void 0:F.content,se=((H=E==null?void 0:E.viewProps)==null?void 0:H.borderRadius)??"53px",ee=Rn(E==null?void 0:E.viewProps,R.hexborderColor,O,Gj);return f.jsx(V.Flex,{justifyContent:"space-between",...E==null?void 0:E.viewProps,"data-flow-node-surface":"",direction:"column",p:0,borderRadius:se,overflow:"hidden",alignItems:"center",style:{backgroundColor:R.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:"100%",minW:y||e.onShowIcon?M+Vv+ee.borderWidth*2:void 0,...ee,children:f.jsxs(V.Flex,{width:"100%",direction:"column",borderRadius:se,borderColor:R.hexborderColor,borderWidth:0,overflow:"hidden",children:[f.jsx(Uj,{headerTitle:$,hasContent:y,data:E,icon:J,colors:R,hasConfig:N,id:k,isActive:O,isEditing:T,onEditStart:P,onEditEnd:I,props:e,objVisible:i,setObjVisible:o,onShowNativeIcon:b}),y&&!i?f.jsx(V.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:R.highlightColor,p:["html","jsx"].includes((de=(B=e.data)==null?void 0:B.config)==null?void 0:de.contentFormat)?0:12,fontSize:"5xl",lineHeight:"normal",children:f.jsx(zj,{nodeId:k,content:ae,format:(oe=(Y=e.data)==null?void 0:Y.config)==null?void 0:oe.contentFormat,color:((ce=E==null?void 0:E.viewProps)==null?void 0:ce.textColor)||R.hextextColor})}):f.jsx(Hj,{data:E,resourcePorts:a,inspecting:s,form:c,inspectionPorts:d,extraPorts:u,colors:R,direction:n,uniformKeyWidth:M})]})})}})};ru.displayName="NodeJsonObjectView";const Gv=e=>{var h,p,y,m,g,b,v,x,w,C,j;const r=qn(),[t,n]=S.useState(!1),i=r.getNodeViewMode(e.data.id)==="properties",o=_=>{n(_),r.setNodeViewMode(e.data.id,_?"properties":"default")},{callbacks:s,readOnly:a}=He(),c=(p=(h=e.data)==null?void 0:h.config)==null?void 0:p.parentContainer;eu(e.data.id,i&&((m=(y=e.data)==null?void 0:y.config)==null?void 0:m.labelBelow)&&!c,()=>o(!1));const l=c?"Show parent":"Show properties",d=c||((b=(g=e.data)==null?void 0:g.config)==null?void 0:b.form)||((w=(x=(v=e.data)==null?void 0:v.config)==null?void 0:x.ports)==null?void 0:w.length),u=d?()=>{var _;c?(_=s.onNodeCollapse)==null||_.call(s,e.data.id,!1):o(!0)}:void 0;return!c&&d&&i?f.jsx(ru,{...e,editOnMount:t,onShowIcon:()=>o(!1)}):f.jsx(tu,{...e,onOpenView:u&&(c||(j=(C=e.data)==null?void 0:C.config)!=null&&j.labelBelow)?()=>{var _;u(),(_=s.onNodeViewToggle)==null||_.call(s,e.data.id)}:void 0,toggleLabel:l,toggleDisabled:c&&a,onExpand:u})};function Jj(e){var b,v,x,w,C,j;const{config:r,callbacks:t,readOnly:n,selectedNodeIds:i,nodeRadiusPreviews:o,nodeViewModes:s,allNodesIconLabel:a}=He(),c=o[e.data.id]??((b=e.data.viewProps)==null?void 0:b.borderRadius),[l,d]=S.useState(!1),u=qn(),{border:h,colorText:p}=it(),y=(v=r.customViews)==null?void 0:v.gridContent,m=(s[e.data.id]??(a?"icon-label":"default"))==="icon-label",g=S.useRef(m);return m&&(g.current=!0),eu(e.data.id,a&&!m&&g.current,()=>u.setNodeViewMode(e.data.id,"icon-label")),m?f.jsx(V.Box,{"data-grid-document":((x=e.data.config)==null?void 0:x.documentId)??"",children:f.jsx(tu,{...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($n,{...e,onOpenView:()=>d(!0),children:({data:_,isActive:k})=>{var E,O,T,P,I,R,$,N;return f.jsx(V.Box,{"data-flow-node-surface":"","data-grid-document":((E=_.config)==null?void 0:E.documentId)??"",width:`${((T=(O=_.config)==null?void 0:O.gridSize)==null?void 0:T.width)??600}px`,height:`${((I=(P=_.config)==null?void 0:P.gridSize)==null?void 0:I.height)??440}px`,overflow:"hidden",position:"relative",bg:((R=_.viewProps)==null?void 0:R.bgColor)??"transparent",color:(($=_.viewProps)==null?void 0:$.textColor)??p,borderRadius:`${c??0}px`,...Rn(_.viewProps,Ee(((N=_.viewProps)==null?void 0:N.borderColor)??h),k,0),children:y?f.jsx(y,{...e}):f.jsx(V.Box,{p:4,children:_.label??"Grid"})})}}),f.jsx(Qd,{nodeAddress:e.data.id,active:i.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:((j=e.data.config)==null?void 0:j.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,T;if(n||!r.editable)return;const k=String(_.value??"");_.address==="root.metadata.label"?(E=t.onNodeLabelChange)==null||E.call(t,e.data.id,k):_.address==="root.metadata.subtitle"?(O=t.onNodeSubtitleChange)==null||O.call(t,e.data.id,k):_.address==="root.metadata.icon"&&((T=t.onNodeIconChange)==null||T.call(t,e.data.id,k))}}},children:f.jsx(Ed,{nodeAddress:e.data.id})})})]})}const Wv=e=>f.jsx(Gv,{...e,renderCompact:$j}),Uv=e=>f.jsx(Gv,{...e}),Hv=({containerStyle:e,...r})=>{const{selectedNodeIds:t}=He();return f.jsx($n,{...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:lr,lineHeight:1,w:"fit-content",children:f.jsx(Ur,{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})})})};Wv.displayName="text";Uv.displayName="arrayView";Hv.displayName="ParentContainerView";const Zj={grid:Jj,objectView:ru,arrayView:Uv,text:Wv,parentContainer:Hv},Xj=({children:e,pattern:r="dot",backgroundColor:t})=>{const{colorMode:n}=He(),i=n==="dark",o=i?"--chakra-colors-gray-700":"--chakra-colors-gray-500",s=i?"--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(${o}) 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})]})},Yj=.4,vr={borderWidth:6,borderStyle:"solid",borderRadius:50,fontSize:70,padding:120,labelPosition:"top",labelMargin:90},Qj=({nodes:e,edges:r})=>{var qe;const{themeColor:t,spacing:n,edgeRadius:i,backgroundVariant:o,backgroundSelected:s,setBackgroundSelected:a,edgeColor:c,direction:l,nodeAlignment:d,edgeMode:u,compactPropertyLayout:h,workflowContract:p,parentNodeStyle:y,engineRef:m,callbacks:g,config:b,selectedNodeIds:v,setSelectedNodeIds:x,selectedEdgeId:w,setSelectedEdgeId:C,setIsPerformanceMode:j,setNodeGridOptions:_,fillRadiusEditedIds:k,isZoomMode:E,setIsZoomMode:O,isMultiSelectMode:T,setIsMultiSelectMode:P,isDragMode:I,setIsDragMode:R,isEdgeHandlesEnabled:$,setIsEdgeHandlesEnabled:N,isArrayNodeMode:M}=He(),J=S.useRef(null),[ae,se]=S.useState(null),ee=S.useRef(null),pe=e.length>200;S.useEffect(()=>{j(pe)},[pe,j]);const{edgeSep:me,rankSep:q,spacingFactor:F}=S.useMemo(()=>{const te=Iw(e.length),G=b.nodeGridSpacing==="layout"&&n<.5?n*1.3:n<1?.3+.7*n:.5+.5*n;return{edgeSep:te.edgeSep*G,rankSep:te.rankSep*G,spacingFactor:1.3+(n-1)*(n<1?.4:.3)}},[e.length,n,b.nodeGridSpacing]),{bgColor:H}=An(t),{canvas:B,borderSecondary:de,colorText:Y}=it(),oe=o==="transparent"?"transparent":b.backgroundColor||B,ce=S.useCallback(te=>{if(!te)return Ee(t);switch(te){case"dark":return Ee(oe);case"light":return Ee(de);default:return Ee(te)}},[t,oe,de]),xe=b.colorMode==="dark",je=xe?Ee("gray.500"):Hr,ye=xe?H!=null&&H.includes("gray")?"whitesmoke":ce(H):je,ge=c?ce(c):je,z=S.useMemo(()=>{var te;return b.initialViewport||{pan:{x:0,y:0},zoom:(te=b.nodeGrid)!=null&&te.enabled&&b.nodeGrid.options.fill?1:.01}},[]),W=l==="C"?"LR":l,ie=S.useCallback(te=>{const G={...y,...te};return{...G,bgColor:G.bgColor||t,bgOpacity:G.outline?0:G.bgOpacity??Yj}},[y,t]),K=S.useMemo(()=>{var G;const te=new Map;for(const ne of e)(G=ne.data)!=null&&G.id&&te.set(ne.data.id,ne);return te},[e]),ue=S.useMemo(()=>{var G;const te=new Map;for(const ne of r)(G=ne.data)!=null&&G.id&&te.set(ne.data.id,ne);return te},[r]),ve=S.useCallback(te=>{var U;const G=(U=K.get(te))==null?void 0:U.data,ne=ie(G==null?void 0:G.viewProps),Me=Ee(ne.bgColor);return{animated:!!(G!=null&&G.isNodeAnimated)&&!pe,animationVariant:G==null?void 0:G.nodeAnimationVariant,animationColor:Ee(ne.borderColor||t),bgColor:ne.outline?"transparent":Me,bgOpacity:ne.bgOpacity,borderColor:ne.borderColor?Ee(ne.borderColor):ne.outline&&ne.bgColor==="transparent"?Ee(t):Me,borderWidth:En(ne.borderWidth,vr.borderWidth),borderStyle:ne.borderStyle??vr.borderStyle,borderRadius:ne.borderRadius??vr.borderRadius,textColor:ne.textColor?Ee(ne.textColor):ne.outline||ne.bgColor==="transparent"?Ee(Y):Me,fontSize:ne.fontSize??vr.fontSize,labelPosition:ne.labelPosition??vr.labelPosition,labelMargin:vr.labelMargin,labelBg:gu(ce("dark"),Me,ne.bgOpacity)??ce("dark"),padding:ne.padding??vr.padding}},[ie,K,Y,t,pe,ce]),Oe=S.useMemo(()=>{var ne,Me;const te=new Map;for(const U of r){const fe=(ne=U.data)==null?void 0:ne.source,we=(Me=U.data)==null?void 0:Me.target;if(!fe||!we||fe===we)continue;const Se=fe<we?`${fe}|${we}`:`${we}|${fe}`,Ke=te.get(Se);Ke?Ke.push({id:U.data.id,source:fe}):te.set(Se,[{id:U.data.id,source:fe}])}const G=new Map;for(const[U,fe]of te){if(fe.length<2)continue;const we=U.split("|")[0],Se=Math.min(20,70/fe.length);fe.forEach(({id:Ke,source:Qe},Ge)=>{const kt=50+(Ge-(fe.length-1)/2)*Se;G.set(Ke,(Qe===we?kt:100-kt)/100)})}return G},[r]),$e=S.useMemo(()=>{const te=ce("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 fe,we,Se,Ke,Qe,Ge;let ne=te;const Me=(we=(fe=K.get(G.source))==null?void 0:fe.data)==null?void 0:we.parent,U=(Ke=(Se=K.get(G.target))==null?void 0:Se.data)==null?void 0:Ke.parent;if(Me&&Me===U){const kt=ie((Ge=(Qe=K.get(Me))==null?void 0:Qe.data)==null?void 0:Ge.viewProps),St=gu(te,Ee(kt.bgColor),kt.bgOpacity);St&&(ne=St)}return{id:G.id,data:G,type:G.type??b.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?jd(p,G):void 0,color:c?ge:G.color?Ee(G.color):ge,connectorColor:c?ge:G.color?Ee(G.color):ye,labelBg:ne,dashed:!!G.isEdgeDashed,animated:!!G.isEdgeAnimated,inverted:!!G.isInverted,turn:Oe.get(G.id)??.5}})},[r,ge,ye,c,Oe,b.edgeType,u,p,K,ie,ce]),De=S.useMemo(()=>{var G;const te=new Set;for(const ne of e)(G=ne.data)!=null&&G.parent&&te.add(ne.data.parent);return te},[e]),tt=S.useMemo(()=>{const te=new Map;for(const G of r){const ne=G.data.isInverted?G.data.target:G.data.source;ne&&!te.has(ne)&&te.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,Me=G.data.isInverted?G.data.source:G.data.target;Me.startsWith(`${ne}.`)&&(te.set(ne,G.data),te.set(Me,G.data))}return te},[r]),Ue=S.useMemo(()=>{const te={...Zj,...b.customViews};return e.filter(G=>{var ne;return(ne=G.data)==null?void 0:ne.id}).map(G=>{var Se,Ke,Qe,Ge,kt,St;const ne=De.has(G.data.id)&&!G.data.parent,Me=ne?G.data.label??G.data.headerTitle??"Container":void 0,U=ne?te.parentContainer:te[G.data.type]||te.text,fe=tt.get(G.data.id),we={...G,isInverted:((Se=G.data.config)==null?void 0:Se.isInverted)??(fe==null?void 0:fe.isInverted),isParent:ne,containerStyle:ne?ve(G.data.id):void 0};return{id:G.data.id,collapsed:(Ke=G.data.config)==null?void 0:Ke.collapsed,parent:G.data.parent,acceptsChildren:!!((Qe=G.data.config)!=null&&Qe.parentContainer)||De.has(G.data.id),label:Me,animated:!!G.data.isNodeAnimated,animationVariant:G.data.nodeAnimationVariant,hasCollapseControl:((Ge=G.data.config)==null?void 0:Ge.collapsed)!==void 0,animationColor:Ee(((kt=G.data.viewProps)==null?void 0:kt.borderColor)||t),animationWidth:En((St=G.data.viewProps)==null?void 0:St.borderWidth,8),element:S.createElement(U,{...we,key:`${G.data.id}-${t}`}),fillElement:k.has(G.data.id)?void 0:S.createElement(U,{...we,data:{...G.data,viewProps:{...G.data.viewProps,borderRadius:0}},containerStyle:we.containerStyle?{...we.containerStyle,borderRadius:0}:void 0,key:`${G.data.id}-${t}`})}})},[e,De,tt,t,b.customViews,ve,k]),yt=S.useMemo(()=>pe?300:e.length>50?150:e.length>20?100:50,[e.length,pe]),Je=S.useRef(b);Je.current=b;const nt=S.useRef(E);nt.current=E;const ht=S.useRef(M);ht.current=M;const Ie=S.useRef(v);Ie.current=v;const ze=S.useRef(w);ze.current=w;const at=S.useRef(T);at.current=T;const st=S.useRef(K);st.current=K;const zt=S.useRef(ue);zt.current=ue;const Ve=S.useRef(new Map);S.useEffect(()=>{var ne,Me;const te=new Map([...ue].filter(([,U])=>K.has(U.data.source)&&K.has(U.data.target))),G=Ve.current;Ve.current=te;for(const[U,fe]of G)te.has(U)||(ze.current===U&&(C(null),(ne=g.onEdgeDeselect)==null||ne.call(g)),(Me=g.onEdgeRemove)==null||Me.call(g,U,fe.data))},[ue,K,g,C]),S.useEffect(()=>{const te=J.current;if(!ae||!te)return;let G=null,ne=null,Me=0,U=0,fe=0,we=0,Se=0;const Ke=Qe=>{if(Je.current.readOnly)return;const Ge=te.ownerDocument.fullscreenElement;if(Ge&&Ge!==te&&te.contains(Ge)&&Qe.target instanceof Node&&Ge.contains(Qe.target))return;Qe.preventDefault(),Qe.stopPropagation(),nt.current||Qe.metaKey||Qe.ctrlKey?(fe+=Qe.deltaY,we=Qe.clientX,Se=Qe.clientY,ne===null&&(ne=requestAnimationFrame(()=>{ne=null;const St=Je.current,bt=ae.zoom(),ft=fe;fe=0;let vt=bt-ft*.05/100;vt=Math.max(St.minZoom??.01,Math.min(St.maxZoom??1.5,vt));const Tt=te.getBoundingClientRect();ae.zoomAt(vt,{x:we-Tt.left,y:Se-Tt.top})}))):(Me+=Qe.deltaX,U+=Qe.deltaY,G===null&&(G=requestAnimationFrame(()=>{G=null;const St=ae.pan(),bt=ae.zoom(),ft=.35,vt=Me,Tt=U;Me=0,U=0,ae.pan({x:St.x+-vt*ft/bt,y:St.y+-Tt*ft/bt})})))};return te.addEventListener("wheel",Ke,{passive:!1}),()=>{te.removeEventListener("wheel",Ke),G!==null&&cancelAnimationFrame(G),ne!==null&&cancelAnimationFrame(ne)}},[ae]),S.useEffect(()=>{if(b.disableKeyboardShortcuts)return;const te=G=>{var Me,U,fe,we;if(Je.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")&&P(!T),(G.key==="d"||G.key==="D")&&R(!I),(G.key==="v"||G.key==="V")&&!G.repeat&&!G.metaKey&&!G.ctrlKey&&!G.altKey&&ne.tagName!=="SELECT"&&N(!$),(G.key==="Delete"||G.key==="Backspace")&&ze.current){G.preventDefault();const Se=ze.current;(U=g.onEdgeDelete)==null||U.call(g,Se,((Me=zt.current.get(Se))==null?void 0:Me.data)??{id:Se}),C(null);return}if((G.key==="Delete"||G.key==="Backspace")&&Ie.current.length>0){G.preventDefault();const Se=Ie.current.filter(Ke=>Ke!=="root");if(Se.length===0)return;for(const Ke of Se){const Qe=(fe=st.current.get(Ke))==null?void 0:fe.data;(we=g.onNodeDelete)==null||we.call(g,Ke,Qe||{})}x([])}}};return window.addEventListener("keydown",te),()=>window.removeEventListener("keydown",te)},[T,I,$,N,O,P,R,b.disableKeyboardShortcuts,g,x,C]);const Ye=S.useCallback(te=>{var G;m.current=te,se(te),(G=g.onInit)==null||G.call(g,te)},[m,g]),Wt=S.useCallback(te=>{var G;return(G=g.onViewportChange)==null?void 0:G.call(g,te)},[g]),lt=S.useCallback(te=>{var ne,Me,U;const G=((ne=zt.current.get(te))==null?void 0:ne.data)??{id:te};if(ze.current===te&&at.current){C(null),(Me=g.onEdgeDeselect)==null||Me.call(g);return}Ie.current.length&&x([]),C(te),(U=g.onEdgeSelect)==null||U.call(g,te,G)},[g,C,x]),rr=S.useCallback(()=>{var te,G,ne,Me,U;if(a(b.bottomBarCollapsed??(Ie.current.length>0||!!ze.current||!s)),(te=g.onBackgroundClick)==null||te.call(g),!Je.current.readOnly){const fe=new Set;for(const we of Ie.current){let Se=st.current.get(we);for(;Se&&!fe.has(Se.data.id);)fe.add(Se.data.id),De.has(Se.data.id)&&((G=Se.data.config)==null?void 0:G.collapsed)!==!0&&((ne=g.onNodeCollapse)==null||ne.call(g,Se.data.id,!0)),Se=Se.data.parent?st.current.get(Se.data.parent):void 0}}Ie.current.length&&(x([]),(Me=g.onNodeDeselect)==null||Me.call(g)),ze.current&&(C(null),(U=g.onEdgeDeselect)==null||U.call(g))},[g,x,C,a,s,b.bottomBarCollapsed,De]),Ut=S.useCallback(te=>{var Me,U;const G=Ie.current,ne=te.filter(fe=>!G.includes(fe));if(ne.length){x([...G,...ne]);for(const fe of ne)(U=g.onNodeSelect)==null||U.call(g,fe,((Me=st.current.get(fe))==null?void 0:Me.data)??{id:fe})}},[g,x]),Ir=S.useCallback((te,G)=>{var ne,Me;x([te]),(Me=g.onNodeSelect)==null||Me.call(g,te,((ne=st.current.get(te))==null?void 0:ne.data)??{id:te},G)},[g,x]),Rt=S.useRef(null),Ht=S.useCallback((te,G,ne)=>{var Me;Rt.current={source:te,target:G,edgeIds:new Set(zt.current.keys())};try{(Me=g.onEdgeCreate)==null||Me.call(g,te,G,ne)}catch(U){throw Rt.current=null,U}},[g]),Xt=S.useCallback((te,G,ne,Me=!1)=>{var U,fe;if(ee.current={sourceId:te,nodeIds:new Set(st.current.keys()),reverse:Me},!(u==="properties"&&((U=g.onNodeCreateRequest)==null?void 0:U.call(g,{sourceNodeId:te,position:G,sourceProperty:ne,reverse:Me}))===!0)){if(ne!==void 0||Me){ee.current=null;return}(fe=g.onNodeCreate)==null||fe.call(g,{type:"text",sourceNodeId:te,position:G,isArrayMode:ht.current})}},[g,u]),Mr=!b.readOnly&&$&&b.edgeHandles!==!1,yr=o==="transparent"?"none":o;return f.jsx(Xj,{pattern:yr,backgroundColor:oe,children:f.jsx(V.Box,{ref:J,padding:0,width:"100%",height:"100%",flex:1,position:"relative",children:f.jsx(Mj,{nodes:Ue,edges:$e,direction:W,nodeAlignment:d,onContainerCollapse:te=>{var G,ne;(G=g.onNodeCollapse)==null||G.call(g,te,!0),(ne=g.onNodeViewToggle)==null||ne.call(g,te)},selectedNodeIds:v,edgeMode:u,compactPropertyLayout:h,edgeType:b.edgeType,edgeRadius:i,customEdgeTypes:b.customEdgeTypes,edgeReveal:b.disableAnimations?void 0:b.edgeReveal,rankSep:q,edgeSep:me,nodeGridSpacing:b.nodeGridSpacing,nodeGridConnections:b.nodeGridConnections,initialNodeGrid:b.nodeGrid,spacingFactor:F,compactSpacingScale:n,layoutDebounce:yt,isPerformanceMode:pe,minZoom:b.minZoom??.01,maxZoom:b.maxZoom??1.5,initialViewport:z,fitOnInit:!b.initialViewport&&!((qe=b.nodeGrid)!=null&&qe.enabled&&b.nodeGrid.options.fill),readOnly:!!b.readOnly,containerStyle:ve,lineColor:c?ge:ye,drawMode:Mr,drawHandles:!b.readOnly&&b.edgeHandles!==!1,dragMode:I,multiSelect:!!T,onInit:Ye,onLayoutComplete:te=>{var fe;(fe=g.onLayoutComplete)==null||fe.call(g,te);const G=Rt.current;G&&(!st.current.has(G.source)||!st.current.has(G.target)?Rt.current=null:r.some(({data:we})=>we.source===G.source&&we.target===G.target&&!G.edgeIds.has(we.id))&&te.getNodeBox(G.source)&&te.getNodeBox(G.target)&&(Rt.current=null,te.focusConnections(G.source)));const ne=ee.current;if(!ne)return;if(!st.current.has(ne.sourceId)){ee.current=null;return}const U=e.filter(we=>!ne.nodeIds.has(we.data.id)).filter(we=>r.some(({data:Se})=>Se.source===ne.sourceId&&Se.target===we.data.id||Se.target===ne.sourceId&&Se.source===we.data.id));!U.length||U.some(we=>!te.getNodeBox(we.data.id))||(ee.current=null,te.focusBranch(ne.reverse?U[0].data.id:ne.sourceId))},onNodeGridModeChange:_,onNodeGridZoomOut:g.onNodeGridZoomOut,onNodeGridDrop:g.onNodeGridDrop,onNodeParentChange:g.onNodeParentChange,animateViewport:b.animateViewport,disableAnimations:b.disableAnimations,onViewportChange:Wt,onBackgroundTap:rr,onBoxSelect:Ut,onEdgeSelect:lt,onContainerSelect:Ir,onEdgeDraw:Ht,onDrawIntoSpace:Xt})})})},Kv=S.memo(Qj),e_=".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 ym=!1;function t_(){if(ym||typeof document>"u")return;const e=document.createElement("style");e.setAttribute("data-flow-sdk",""),e.textContent=e_+".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}"+Rb+Aw+Rw+".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}',ym=!0}function r_({loading:e=!1,loader:r,...t}){var c,l;const[n,i]=S.useState(null),o=S.useMemo(()=>!!(n!=null&&n.json)&&!!t.json&&jw(n.json,t.json),[n==null?void 0:n.json,t.json]),s=n===null||n.json!==t.json&&!o,a=e||s;return S.useEffect(()=>{!e&&o&&(n==null?void 0:n.json)!==t.json&&i(t)},[e,o,n==null?void 0:n.json,t.json]),S.useEffect(()=>{if(e||!s)return;let d;const u=requestAnimationFrame(()=>{d=requestAnimationFrame(()=>i(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(n_,{...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 n_({title:e="untitled",json:r,forms:t,nodes:n,edges:i,config:o={},callbacks:s={},className:a,style:c,showBottomBar:l=!0,children:d}){t_();const[u,h]=S.useState(),[p,y]=S.useState(!1),m=o.formSchema??u,g=S.useMemo(()=>r&&t?ib(r,t.state):r,[r,t==null?void 0:t.state]),b=o.direction==="C",v=S.useMemo(()=>{let T,P;return I=>(P=T&&P?_w(T,I,P)??id(I,{title:e,isCenter:b}):id(I,{title:e,isCenter:b}),T=I,P)},[e,b]),x=S.useMemo(()=>g?v(g):null,[g,v]),w=S.useMemo(()=>t!=null&&t.structured&&!p&&m?ab(t.state,t.bindings,m,(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,m,x,n]),C=(w==null?void 0:w.schema)??m,j=(w==null?void 0:w.bindings)??(t==null?void 0:t.bindings),_=S.useMemo(()=>[...(x==null?void 0:x.nodes)??n??[],...(w==null?void 0:w.nodes)??[]].map(P=>{var ae,se,ee,pe;const I=r?(ae=Te(r,P.data.id))==null?void 0:ae.$view:(se=P.data.config)==null?void 0:se.typeView,R=I&&hd.includes(I)?I:void 0,$=R?R==="icon-label":(ee=P.data.config)==null?void 0:ee.labelBelow,N=R==="object"?"objectView":R==="text"?"text":$?"arrayView":P.data.type,M=C&&(t?Pn(j,P.data.id,C):r&&Jr(r,P.data.id,C)),J=(((pe=P.data.config)==null?void 0:pe.ports)??[]).map(me=>({...me}));if(w&&M){const me=o.direction==="RL"?{input:"right",output:"left",config:"bottom",error:"top"}:o.direction==="TB"?{input:"top",output:"bottom",config:"right",error:"left"}:o.direction==="BT"?{input:"bottom",output:"top",config:"left",error:"right"}:{input:"left",output:"right",config:"top",error:"bottom"};for(const[q,F]of Object.entries(M.type.ports??{})){const H=`${F.kind}:${q}`,B=J.find(de=>de.id===H);B?B.label===void 0&&F.label!==void 0&&(B.label=F.label):J.push({id:H,...F.label!==void 0?{label:F.label}:{},role:F.kind==="input"||F.kind==="config"?"target":"source",side:me[F.kind],...F.kind==="config"?{placement:"config"}:{}})}for(const q of J){const F=J.filter(H=>H.side===q.side);q.position=(F.indexOf(q)+1)/(F.length+1)}}return M||$||R?{...P,data:{...P.data,type:N,...t?{description:Object.fromEntries(Object.entries(P.data.description??{}).filter(([me])=>!me.startsWith("$")&&!(w!=null&&w.slots.has(ln(P.data.id,me)))))}:{},config:{...P.data.config,...w&&M?{ports:J}:{},...M?{form:!0}:{},...R?{typeView:R,labelBelow:!!$}:$?{labelBelow:!0}:{}}}}:P}),[x,n,r,C,j,w,o.direction]),k=S.useMemo(()=>[...(x==null?void 0:x.edges)??i??[],...(w==null?void 0:w.edges)??[]],[x==null?void 0:x.edges,i,w==null?void 0:w.edges]),E=S.useMemo(()=>{const T=r&&x?Eb(r,x.edges,s,s.onJsonChange,m):{...s};if(w){const P=new Set([...w.nodes.map(I=>I.data.id),...w.edges.map(I=>I.data.id)]);for(const I of Object.keys(T)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(I))continue;const R=T[I];T[I]=($,...N)=>{if(!P.has($))return R==null?void 0:R($,...N)}}}return{...T,onAllNodesIconLabelChange:P=>{var I;y(P),(I=T.onAllNodesIconLabelChange)==null||I.call(T,P)}}},[r,x,s,m,w]),O=S.useMemo(()=>{if(!t)return E;let T=t.state;const P=R=>{if(o.readOnly||o.editable===!1)return;const $=t.onStateChange??t.onChange;if(!$)return;const N=fw(T,R,s.onFormChange);N!==T&&(T=N,$(N,{...R,data:N}))},I=(R,$,N)=>{var J;const M=r&&((J=Te(r,R))==null?void 0:J[$]);return!M||typeof M.$state!="string"?!1:(P({address:M.$state,nodeAddress:R,previousValue:Te(T,M.$state),value:N,data:T}),!0)};return{...E,onFormChange:P,onNodeCreateRequest:R=>{var M,J;const $=(M=R.sourceProperty)!=null&&M.startsWith("config:")?R.sourceProperty.slice(7):void 0,N=$!==void 0&&(w==null?void 0:w.slots.get(ln(R.sourceNodeId,$)));return N?(N.present||P({data:T,nodeAddress:N.address.split(".").slice(0,-1).join("."),address:N.address,value:dn(N.type),previousValue:void 0}),!0):((J=E.onNodeCreateRequest)==null?void 0:J.call(E,R))??!1},onNodeDelete:(R,$)=>{var ee,pe;if(!(w!=null&&w.nodes.some(me=>me.data.id===R)))return(ee=E.onNodeDelete)==null?void 0:ee.call(E,R,$);const N=w&&[...w.slots.values()].find(me=>me.nodeId===R);if(!N)return(pe=E.onNodeDelete)==null?void 0:pe.call(E,R,$);const M=N.address.split("."),J=M.pop(),ae=M.join("."),se=Te(T,ae);P(Array.isArray(se)?{data:T,nodeAddress:ae,address:ae,previousValue:se,value:se.filter((me,q)=>String(q)!==J)}:{data:T,nodeAddress:ae,address:N.address,previousValue:Te(T,N.address),value:void 0})},onEdgeCreate:(R,$,N)=>{var ae,se;const M=((ae=N==null?void 0:N.targetProperty)==null?void 0:ae.startsWith("config:"))&&(w==null?void 0:w.slots.get(ln($,N.targetProperty.slice(7)))),J=w==null?void 0:w.containers.get(R);if(M&&J&&(N==null?void 0:N.sourceProperty)==="output:resource"){const ee=gw(T,J,M);ee!==void 0&&P({data:T,nodeAddress:M.address.split(".").slice(0,-1).join("."),address:M.address,previousValue:Te(T,M.address),value:ee});return}M||w!=null&&w.nodes.some(ee=>ee.data.id===R||ee.data.id===$)||(se=E.onEdgeCreate)==null||se.call(E,R,$,N)},onEdgeDelete:(R,$)=>{var pe;const N=w==null?void 0:w.edges.find(me=>me.data.id===R);if(!N)return(pe=E.onEdgeDelete)==null?void 0:pe.call(E,R,$);const M=w.slots.get(ln(N.data.target,N.data.targetProperty.slice(7))),J=M.address.split("."),ae=J.pop(),se=J.join("."),ee=Te(T,se);P(Array.isArray(ee)?{data:T,nodeAddress:se,address:se,previousValue:ee,value:ee.filter((me,q)=>String(q)!==ae)}:{data:T,nodeAddress:se,address:M.address,previousValue:Te(T,M.address),value:void 0})},onNodeContentChange:(R,$)=>{var N,M;I(R,"$content",$)?(N=s.onNodeContentChange)==null||N.call(s,R,$):(M=E.onNodeContentChange)==null||M.call(E,R,$)},onNodeLabelChange:(R,$)=>{var N,M;I(R,"$label",$)?(N=s.onNodeLabelChange)==null||N.call(s,R,$):(M=E.onNodeLabelChange)==null||M.call(E,R,$)}}},[E,t,r,s,w,o.readOnly,o.editable]);return f.jsx(Mt.Provider,{value:{data:(t==null?void 0:t.state)??r,viewData:r,bindings:j,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:T=>{var P;h(T),(P=s.onFormSchemaChange)==null||P.call(s,T)},callbacks:O},children:f.jsx(jm,{config:w?{...o,formSchema:C}:o,callbacks:O,nodes:_,edges:k,children:f.jsxs(V.Box,{className:a,"data-flow-diagram":"","data-animations-disabled":o.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(Kv,{nodes:_,edges:k}),l&&f.jsx(xb,{}),d]})})})}function o_(e){return fd(JSON.parse(e))}function fd(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[i,o]of Object.entries(n)){if(["__proto__","prototype","constructor"].includes(i))throw new Error(`Unsafe document key: ${i}`);t(o)}r.delete(n)}};return t(e),structuredClone(e)}function i_(e){return{replaceJson(r){if(e.readOnly||!e.onJsonChange)throw new Error("JSON document is read-only.");const t=fd(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=fd(r);return e.onStateChange(t,{address:"root",nodeAddress:"root",previousValue:e.state,value:t,data:t}),t}}}function a_(e,r){const t=(n,i)=>{if(n===null||typeof n!="object")return typeof n==typeof i?n:void 0;if(!(!i||typeof i!="object"))return Array.isArray(n)?Array.isArray(i)?n.map((o,s)=>t(o,i[s])).filter(o=>o!==void 0):void 0:Object.fromEntries(Object.entries(n).flatMap(([o,s])=>{if(!Object.prototype.hasOwnProperty.call(i,o))return[];if(o==="$content"&&n.$contentFormat==="jsx"&&i.$contentFormat==="jsx"&&Array.isArray(s)&&Array.isArray(i[o]))return[[o,s.filter((c,l)=>JSON.stringify(c)===JSON.stringify(i[o][l]))]];if(o.startsWith("$")&&o!=="$")return JSON.stringify(s)===JSON.stringify(i[o])?[[o,s]]:[];const a=t(s,i[o]);return a===void 0?[]:[[o,a]]}))};return t(e,r)??{}}function Un(e){let r="",t=!1,n="",i;const o=()=>{clearTimeout(i),i=void 0},s=()=>{if(o(),!(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,o(),new Error("JSON stream exceeds the size limit.");r=c,i||(i=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,o();const c=e.parse(r);return e.commit(c),c},cancel(){t=!0,o(),r=""}}}function s_(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 i=Un(e),o=0,s=!1,a=!1,c;const l=Math.max(1,Math.ceil(r.length*t/n)),d=()=>e.onChange({position:o,total:r.length,playing:s}),u=()=>{clearTimeout(c),c=void 0},h=(m=!1)=>{i.snapshot(r.slice(0,o)),o===r.length?(s=!1,u(),i.finish()):m&&i.flush()},p=m=>{s=!1,u(),i.cancel(),d(),e.onError(m)},y=()=>{if(c=void 0,!(!s||a)){o=Math.min(r.length,o+l);try{h()}catch(m){p(m);return}d(),s&&(c=setTimeout(y,t))}};return{play(){a||s||(o===r.length&&(i.cancel(),i=Un(e),o=0),s=!0,d(),c=setTimeout(y,t))},pause(){a||(s=!1,u(),i.flush(),d())},seek(m){if(!a){if(!Number.isFinite(m))throw new Error("Playback position must be finite.");u(),o=Math.max(0,Math.min(r.length,Math.round(m))),i.cancel(),i=Un(e);try{h(!0)}catch(g){p(g);return}d(),s&&(c=setTimeout(y,t))}},dispose(){a=!0,s=!1,u(),i.cancel()}}}function c_({nodeAddress:e,expanded:r=!1}){var l;const{data:t,schema:n,bindings:i}=S.useContext(Mt),{colorText:o,background:s}=it();if((l=i==null?void 0:i[e])!=null&&l.portResources)return null;const a=i&&Pn(i,e,n);if(!t||!a)return null;const c=Te(t,a.address);return!c||typeof c!="object"?null:f.jsx("div",{"data-flow-config-summary":"",style:{width:"100%",minWidth:0,color:Ee(o),background:Ee(s),fontSize:24,lineHeight:1.4,textTransform:"none"},children:Object.keys(a.type.properties).map(d=>{const u=a.fields[d]??{};if(!oo(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=xb;exports.CompactPropertyLayoutToggle=Hm;exports.ConnectionsOnlyToggle=Sw;exports.DEFAULT_PALETTE=Jn;exports.DiagramAppearanceControls=Km;exports.DynamicIcon=Jt;exports.EdgeTools=fb;exports.EditableLabel=Ur;exports.ErrorToast=bb;exports.FlowDiagram=r_;exports.FlowDiagramProvider=jm;exports.FlowPort=Bv;exports.FlowView=Kv;exports.FormDocumentContext=Mt;exports.LIGHT_BLACK=Hr;exports.LoadingBorder=Dv;exports.NODE_TYPE_VIEWS=hd;exports.NodeBorderRadiusControl=hb;exports.NodeConfigSummary=c_;exports.NodeForm=Ed;exports.NodeFormPopover=Qd;exports.NodeIconPicker=Rd;exports.NodeTools=pb;exports.NodeView=$n;exports.SvgExportButton=mb;exports.Swatches=Er;exports.TEXT_PALETTE=db;exports.ToolbarCloseButton=Kr;exports.ToolbarCommitInput=zr;exports.ToolbarDivider=pn;exports.ToolbarIconButton=Pe;exports.ToolbarRangeInput=gd;exports.ToolbarScrollContainer=kd;exports.ToolbarSelect=Pt;exports.ToolbarTooltip=Be;exports.TooltipIconButton=ud;exports.WorkflowControls=Ad;exports.addChild=xd;exports.addConnection=wd;exports.addTargetEdge=tb;exports.addressToPath=Bt;exports.applyCollapsed=lw;exports.applyFormChange=io;exports.applyStateEdits=uw;exports.bindSqueedCallbacks=Eb;exports.compileSqueed=id;exports.connectionIssue=jd;exports.contentObjTheme=Kt;exports.copySelection=Pd;exports.createFlowDiagram=jr;exports.createFlowDocumentActions=i_;exports.createFormNode=Cb;exports.createJsonPlayback=s_;exports.createJsonStream=Un;exports.createWorkflowExecution=px;exports.downloadSvg=yb;exports.duplicateSelection=_b;exports.exportSvg=gb;exports.formValueError=Dt;exports.getChakraColorHex=Ee;exports.getColorVariant=xm;exports.getDarkerHexColor=Hn;exports.getInteractionSurface=dr;exports.getNode=Te;exports.getSelectionRoots=jb;exports.parseFlowDocument=o_;exports.parseJsonContract=Cd;exports.parseTypeScriptContract=nb;exports.parseTypeScriptForm=Sd;exports.projectJsonPlaybackPreview=a_;exports.readFormSchema=_d;exports.readWorkflowContract=ob;exports.removeEdge=rb;exports.removeNode=eb;exports.reparentNode=Sb;exports.resolveEdgeOwner=Cr;exports.resolveStateView=ib;exports.setCollapsed=vd;exports.setEdgeProp=sr;exports.setEdgeStyle=Qm;exports.setNodeProp=Ct;exports.updateNode=Et;exports.useCustomColors=it;exports.useEdgeProximity=vm;exports.useFlowData=pr;exports.useFlowDiagramContext=He;exports.useNodeViewActions=qn;exports.useStopPropagation=Yd;exports.useThemeContentColors=An;exports.validateGridAdjustment=Lv;
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(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=_.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 M=document.fullscreenElement===p.current;v(M),y.current&&!M&&!document.fullscreenElement&&((K=m.current)==null||K.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(),[P,E]=_.useState(),[O,A]=_.useState();_.useEffect(()=>{if(r==="jsx")return;let $=!1;return Promise.resolve().then(()=>require("./contentPreviewDocument-BsKd0dD4.cjs")).then(({contentPreviewDocument:M})=>M(l,r,w)).then(M=>{$||j({content:l,format:r,editable:w,document:M})},M=>{$||j({content:l,format:r,editable:w,error:M instanceof Error?M.message:String(M)})}),()=>{$=!0}},[l,r,w]),_.useEffect(()=>{if(!t)return;const $=async M=>{var K,ae;if(!(!((K=h.current)!=null&&K.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,T=!!R&&R===O,I=r!=="jsx"&&!(R!=null&&R.error)&&!T&&(!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"?I: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(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(M=>x(String(M)))}}),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||T?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:I?"hidden":"visible"}},R.document):null,f.jsx(Hv,{active:I,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,isEditing:c,onEditStart:l,onEditEnd:d,props:u,objVisible:h,setObjVisible:p,onShowNativeIcon:m}){var b,x;const{callbacks:y}=Ze(),g=u.onShowIcon??m,v=g?"Show icon":h?"Show content":"Show properties";return f.jsx(f.Fragment,{children:(e||r||((b=t.config)==null?void 0:b.form)||a&&m)&&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:((x=t==null?void 0:t.viewProps)==null?void 0:x.textColor)||o.propertyColor,isEditing:c,onEditStart:l,onEditEnd:d}),a&&(r||g)&&f.jsx(V.Box,{ml:"auto",pl:6,flexShrink:0,"data-flow-content-toggle":"",children:f.jsx(Ue,{label:v,children:f.jsx(Me,{"aria-label":v,icon:f.jsx(V.Icon,{as:Z.PiCircleFill,boxSize:4}),variant:"ghost",w:12,h:12,minW:12,color:o.hextextColor,onClick:w=>{var C;w.stopPropagation(),g?g():p(!h),(C=y.onNodeViewToggle)==null||C.call(y,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 T,I,N;const m=r&&Object.keys(r).find($=>$.slice($.indexOf(":")+1)===u),y=t&&((T=n==null?void 0:n.type.ports)==null?void 0:T[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:((I=e==null?void 0:e.viewProps)==null?void 0:I.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},children:({id:P,data:E,isActive:O,isEditing:A,onEditStart:R,onEditEnd:T})=>{var me,ve,F,D,W,B,le,Y,ce,ue;const I=Uj(E,r,t),N=E.label??E.headerTitle,$=Object.entries(E.description||{}).length>0,M=Zj(E.description),K=(ve=(me=e.data)==null?void 0:me.config)==null?void 0:ve.icon,ae=(D=(F=e.data)==null?void 0:F.config)==null?void 0:D.content,se=((W=E==null?void 0:E.viewProps)==null?void 0:W.borderRadius)??"53px",te=In(E==null?void 0:E.viewProps,I.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:se,overflow:"hidden",alignItems:"center",style:{backgroundColor:I.hexbgColor,transition:"border-color 0.2s ease-in-out"},width:"100%",minW:m||e.onShowIcon?M+Kv+te.borderWidth*2:void 0,...te,children:f.jsxs(V.Flex,{width:"100%",direction:"column",borderRadius:se,borderColor:I.hexborderColor,borderWidth:0,overflow:"hidden",children:[f.jsx(Xj,{headerTitle:N,hasContent:m,data:E,icon:K,colors:I,hasConfig:$,id:P,isActive:O,isEditing:A,onEditStart:R,onEditEnd:T,props:e,objVisible:o,setObjVisible:i,onShowNativeIcon:v}),m&&!o?f.jsx(V.Flex,{w:"100%",overflow:"auto",justifyContent:"start",background:I.highlightColor,p:["html","jsx"].includes((le=(B=e.data)==null?void 0:B.config)==null?void 0:le.contentFormat)?0:12,fontSize:"5xl",lineHeight:"normal",children:f.jsx(Wj,{nodeId:P,content:ae,format:(ce=(Y=e.data)==null?void 0:Y.config)==null?void 0:ce.contentFormat,color:((ue=E==null?void 0:E.viewProps)==null?void 0:ue.textColor)||I.hextextColor})}):f.jsx(Yj,{data:E,resourcePorts:a,inspecting:s,form:c,inspectionPorts:d,extraPorts:u,colors:I,direction:n,uniformKeyWidth:M})]})})}})};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,T,I,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:`${((T=(R=j.config)==null?void 0:R.gridSize)==null?void 0:T.height)??440}px`,overflow:"hidden",position:"relative",bg:((I=j.viewProps)==null?void 0:I.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:T,setIsDragMode:I,isEdgeHandlesEnabled:N,setIsEdgeHandlesEnabled:$,isArrayNodeMode:M}=Ze(),K=_.useRef(null),[ae,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",ke=xe?Ae("gray.500"):Kr,ye=xe?W!=null&&W.includes("gray")?"whitesmoke":ue(W):ke,pe=c?ue(c):ke,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,ie=_.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=ie(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}},[ie,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,Ce=($e=U.data)==null?void 0:$e.target;if(!he||!Ce||he===Ce)continue;const je=he<Ce?`${he}|${Ce}`:`${Ce}|${he}`,Xe=re.get(je);Xe?Xe.push({id:U.data.id,source:he}):re.set(je,[{id:U.data.id,source:he}])}const G=new Map;for(const[U,he]of re){if(he.length<2)continue;const Ce=U.split("|")[0],je=Math.min(20,70/he.length);he.forEach(({id:Xe,source:Qe},He)=>{const kt=50+(He-(he.length-1)/2)*je;G.set(Xe,(Qe===Ce?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,Ce,je,Xe,Qe,He;let ne=re;const $e=(Ce=(he=H.get(G.source))==null?void 0:he.data)==null?void 0:Ce.parent,U=(Xe=(je=H.get(G.target))==null?void 0:je.data)==null?void 0:Xe.parent;if($e&&$e===U){const kt=ie((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,ie,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 je,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),Ce={...G,isInverted:((je=G.data.config)==null?void 0:je.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,{...Ce,key:`${G.data.id}-${t}`}),fillElement:P.has(G.data.id)?void 0:_.createElement(U,{...Ce,data:{...G.data,viewProps:{...G.data.viewProps,borderRadius:0}},containerStyle:Ce.containerStyle?{...Ce.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(M);ht.current=M;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(!ae||!re)return;let G=null,ne=null,$e=0,U=0,he=0,Ce=0,je=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,Ce=Qe.clientX,je=Qe.clientY,ne===null&&(ne=requestAnimationFrame(()=>{ne=null;const St=Ye.current,mt=ae.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();ae.zoomAt(vt,{x:Ce-Tt.left,y:je-Tt.top})}))):($e+=Qe.deltaX,U+=Qe.deltaY,G===null&&(G=requestAnimationFrame(()=>{G=null;const St=ae.pan(),mt=ae.zoom(),ft=.35,vt=$e,Tt=U;$e=0,U=0,ae.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)}},[ae]),_.useEffect(()=>{if(v.disableKeyboardShortcuts)return;const re=G=>{var $e,U,he,Ce;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")&&I(!T),(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 je=Ve.current;(U=g.onEdgeDelete)==null||U.call(g,je,(($e=zt.current.get(je))==null?void 0:$e.data)??{id:je}),C(null);return}if((G.key==="Delete"||G.key==="Backspace")&&Te.current.length>0){G.preventDefault();const je=Te.current.filter(Xe=>Xe!=="root");if(je.length===0)return;for(const Xe of je){const Qe=(he=ct.current.get(Xe))==null?void 0:he.data;(Ce=g.onNodeDelete)==null||Ce.call(g,Xe,Qe||{})}x([])}}};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[A,T,N,$,O,R,I,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 Ce of Te.current){let je=ct.current.get(Ce);for(;je&&!he.has(je.data.id);)he.add(je.data.id),Be.has(je.data.id)&&((G=je.data.config)==null?void 0:G.collapsed)!==!0&&((ne=g.onNodeCollapse)==null||ne.call(g,je.data.id,!0)),je=je.data.parent?ct.current.get(je.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:T,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:Ce})=>Ce.source===G.source&&Ce.target===G.target&&!G.edgeIds.has(Ce.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(Ce=>!ne.nodeIds.has(Ce.data.id)).filter(Ce=>r.some(({data:je})=>je.source===ne.sourceId&&je.target===Ce.data.id||je.target===ne.sourceId&&je.source===Ce.data.id));!U.length||U.some(Ce=>!re.getNodeBox(Ce.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 T=>(R=A&&R?Aw(A,T,R)??ud(T,{title:e,isCenter:v}):ud(T,{title:e,isCenter:v}),A=T,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 ae,se,te,me;const T=r?(ae=qe(r,R.data.id))==null?void 0:ae.$view:(se=R.data.config)==null?void 0:se.typeView,I=T&&vd.includes(T)?T:void 0,N=I?I==="icon-label":(te=R.data.config)==null?void 0:te.labelBelow,$=I==="object"?"objectView":I==="text"?"text":N?"arrayView":R.data.type,M=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&&M){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(M.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 M||N||I?{...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&&M?{ports:K}:{},...M?{form:!0}:{},...I?{typeView:I,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(T=>T.data.id),...w.edges.map(T=>T.data.id)]);for(const T of Object.keys(A)){if(!/^on(?:Node|Edge).*(?:Change|Collapse)$/.test(T))continue;const I=A[T];A[T]=(N,...$)=>{if(!R.has(N))return I==null?void 0:I(N,...$)}}}return{...A,onAllNodesIconLabelChange:R=>{var T;m(R),(T=A.onAllNodesIconLabelChange)==null||T.call(A,R)}}},[r,x,s,y,w]),O=_.useMemo(()=>{if(!t)return E;let A=t.state;const R=I=>{if(i.readOnly||i.editable===!1)return;const N=t.onStateChange??t.onChange;if(!N)return;const $=yw(A,I,s.onFormChange);$!==A&&(A=$,N($,{...I,data:$}))},T=(I,N,$)=>{var K;const M=r&&((K=qe(r,I))==null?void 0:K[N]);return!M||typeof M.$state!="string"?!1:(R({address:M.$state,nodeAddress:I,previousValue:qe(A,M.$state),value:$,data:A}),!0)};return{...E,onFormChange:R,onNodeCreateRequest:I=>{var M,K;const N=(M=I.sourceProperty)!=null&&M.startsWith("config:")?I.sourceProperty.slice(7):void 0,$=N!==void 0&&(w==null?void 0:w.slots.get(hn(I.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,I))??!1},onNodeDelete:(I,N)=>{var te,me;if(!(w!=null&&w.nodes.some(ve=>ve.data.id===I)))return(te=E.onNodeDelete)==null?void 0:te.call(E,I,N);const $=w&&[...w.slots.values()].find(ve=>ve.nodeId===I);if(!$)return(me=E.onNodeDelete)==null?void 0:me.call(E,I,N);const M=$.address.split("."),K=M.pop(),ae=M.join("."),se=qe(A,ae);R(Array.isArray(se)?{data:A,nodeAddress:ae,address:ae,previousValue:se,value:se.filter((ve,F)=>String(F)!==K)}:{data:A,nodeAddress:ae,address:$.address,previousValue:qe(A,$.address),value:void 0})},onEdgeCreate:(I,N,$)=>{var ae,se;const M=((ae=$==null?void 0:$.targetProperty)==null?void 0:ae.startsWith("config:"))&&(w==null?void 0:w.slots.get(hn(N,$.targetProperty.slice(7)))),K=w==null?void 0:w.containers.get(I);if(M&&K&&($==null?void 0:$.sourceProperty)==="output:resource"){const te=vw(A,K,M);te!==void 0&&R({data:A,nodeAddress:M.address.split(".").slice(0,-1).join("."),address:M.address,previousValue:qe(A,M.address),value:te});return}M||w!=null&&w.nodes.some(te=>te.data.id===I||te.data.id===N)||(se=E.onEdgeCreate)==null||se.call(E,I,N,$)},onEdgeDelete:(I,N)=>{var me;const $=w==null?void 0:w.edges.find(ve=>ve.data.id===I);if(!$)return(me=E.onEdgeDelete)==null?void 0:me.call(E,I,N);const M=w.slots.get(hn($.data.target,$.data.targetProperty.slice(7))),K=M.address.split("."),ae=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)!==ae)}:{data:A,nodeAddress:se,address:M.address,previousValue:qe(A,M.address),value:void 0})},onNodeContentChange:(I,N)=>{var $,M;T(I,"$content",N)?($=s.onNodeContentChange)==null||$.call(s,I,N):(M=E.onNodeContentChange)==null||M.call(E,I,N)},onNodeLabelChange:(I,N)=>{var $,M;T(I,"$label",N)?($=s.onNodeLabelChange)==null||$.call(s,I,N):(M=E.onNodeLabelChange)==null||M.call(E,I,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;
284
284
  //# sourceMappingURL=index.cjs.map