import{j as m,c as O,d as b,e as R}from"./reactflow-vendor-DYfacRG4.js";import{c as _}from"./index-9ErzGo47.js";import{r as h,R as y}from"./react-vendor-CMZ2fpGT.js";/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var E={outline:{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"},filled:{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none"}};/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */const I=(e,n,s,t)=>{const a=h.forwardRef(({color:r="currentColor",size:o=24,stroke:i=2,title:d,className:l,children:u,...c},S)=>h.createElement("svg",{ref:S,...E[e],width:o,height:o,className:["tabler-icon",`tabler-icon-${n}`,l].join(" "),...e==="filled"?{fill:r}:{strokeWidth:i,stroke:r},...c},[d&&h.createElement("title",{key:"svg-title"},d),...t.map(([w,N])=>h.createElement(w,N)),...Array.isArray(u)?u:[u]]));return a.displayName=`${s}`,a};/**
 * @license @tabler/icons-react v3.18.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var C=I("outline","loader-2","IconLoader2",[["path",{d:"M12 3a9 9 0 1 0 9 9",key:"svg-0"}]]);const j=h.forwardRef((e,n)=>{let{size:s=18,...t}=e;return typeof s=="string"&&(s=s==="sm"?12:s==="md"?24:18),m.jsxs("div",{...t,children:[m.jsx(C,{className:_("w-4 h-4 animate-spin",e.className)}),m.jsx("span",{className:"sr-only",children:"Loading..."})]})});j.displayName="Spinner";let A="";const M=window.location.host,U=async(e,n)=>fetch(A+e,n),f={fetchApi:U,wsUrl:`ws${window.location.protocol==="https:"?"s":""}://${M}/ws`,graph:{workflow_id:null,job_status:null,nodes:[],edges:[],values:{}}},z=h.forwardRef((e,n)=>m.jsx("div",{ref:n,style:{display:"flex",flexDirection:"row",alignItems:"center",...e.style},...e}));z.displayName="Flex";const k=e=>{let n;const s=new Set,t=(l,u)=>{const c=typeof l=="function"?l(n):l;if(!Object.is(c,n)){const S=n;n=u??(typeof c!="object"||c===null)?c:Object.assign({},n,c),s.forEach(w=>w(n,S))}},a=()=>n,i={setState:t,getState:a,getInitialState:()=>d,subscribe:l=>(s.add(l),()=>s.delete(l))},d=n=e(t,a,i);return i},D=e=>e?k(e):k,K=e=>e;function L(e,n=K){const s=y.useSyncExternalStore(e.subscribe,()=>n(e.getState()),()=>n(e.getInitialState()));return y.useDebugValue(s),s}const v=e=>{const n=D(e),s=t=>L(n,t);return Object.assign(s,n),s},V=e=>e?v(e):v;function G(e,n,s){return"node_"+n+"_"+e+"_"+s}const T="nozy_graph";class ${constructor(){this.undoStack=[],this.redoStack=[],this.nodeMoveOrResizeStorage=[],this.undo=()=>{if(this.undoStack.length){const s=this.undoStack.pop();if(s){const{nodes:t,edges:a}=g.getState();this.redoStack.push({nodes:t,edges:a}),g.setState({nodes:s.nodes,edges:s.edges})}else g.setState({nodes:[],edges:[]})}},this.redo=()=>{const s=this.redoStack.pop();if(s){const{nodes:t,edges:a}=g.getState();this.undoStack.push({nodes:t,edges:a}),g.setState({nodes:s.nodes,edges:s.edges})}},this.addUndoStack=(s,t)=>{const{nodes:a,edges:r}=g.getState();switch(s){case"init":this.undoStack=[];break;case"onNodesChange":if(t){const o=t[0],i=["dimensions","position","select"].includes(o.type),d=o.type==="position"||o.type==="dimensions"&&Object.hasOwn(o,"resizing"),l=o.dragging||o.resizing;if(d&&(l&&this.nodeMoveOrResizeStorage.length===0?this.nodeMoveOrResizeStorage=[...a]:!l&&this.nodeMoveOrResizeStorage.length>0&&(this.undoStack.push({nodes:this.nodeMoveOrResizeStorage,edges:r}),this.nodeMoveOrResizeStorage=[])),i)return}break}this.undoStack.push({nodes:a,edges:r}),this.undoStack.length>30&&this.undoStack.shift()};const n=s=>{const t=(s.ctrlKey||s.metaKey)&&s.key==="z"&&!s.shiftKey,a=(s.ctrlKey||s.metaKey)&&(s.shiftKey&&s.key==="z"||s.key==="y");if(t||a){const r=s.target;if(r.nodeName==="INPUT"||r.nodeName==="TEXTAREA"){document.execCommand(t?"undo":"redo"),s.preventDefault();return}t?this.undo():this.redo(),s.preventDefault()}};window.addEventListener("keydown",n)}}const p=new $,F="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let H=e=>crypto.getRandomValues(new Uint8Array(e)),J=(e,n,s)=>{let t=(2<<Math.log(e.length-1)/Math.LN2)-1,a=-~(1.6*t*n/e.length);return(r=n)=>{let o="";for(;;){let i=s(a),d=a;for(;d--;)if(o+=e[i[d]&t]||"",o.length===r)return o}}},Z=(e,n=21)=>J(e,n,H),P=(e=21)=>{let n="",s=crypto.getRandomValues(new Uint8Array(e));for(;e--;)n+=F[s[e]&63];return n};const g=V((e,n)=>{const s=()=>{const{workflow_id:t,nodes:a,edges:r,values:o,job_status:i,name:d}=n();f.graph.workflow_id=t,f.graph.nodes=a,f.graph.edges=r,f.graph.values=o,f.graph.job_status=i??null,f.graph.name=d??null,sessionStorage.setItem(T,JSON.stringify({workflow_id:t,nodes:a,edges:r,values:o,name:d}))};return{workflow_id:P(),name:null,nodes:[],edges:[],values:{},selectedNodeIDs:[],setSelectedNodeIDs:t=>{e({selectedNodeIDs:t})},updateValues:t=>{let a={...n().values};for(const[r,o]of Object.entries(t))o===void 0?delete a[r]:a[r]=o;e({values:a}),s()},onNodesChange:t=>{p.addUndoStack("onNodesChange",t),e({nodes:O(t,n().nodes)});const a=t.filter(o=>o.type==="remove").map(o=>o.id),r={...n().values};a.forEach(o=>{Object.keys(r).forEach(i=>{i.includes(`node_${o}`)&&delete r[i]})}),e({values:r}),s()},onEdgesChange:t=>{p.addUndoStack("onEdgesChange"),e({edges:b(t,n().edges)}),s()},onConnect:t=>{p.addUndoStack("onConnect"),e({edges:R(t,n().edges)}),s()},setNodes:t=>{e({nodes:t})},setEdges:t=>{e({edges:t})},addNode:t=>{var r;p.addUndoStack("addNode"),e({nodes:n().nodes.concat(t)});const a={...n().values};(r=t.data.input)==null||r.forEach(o=>{a[G("input",t.id,o.id)]=o.default??null}),e({values:a}),s()},loadGraph:t=>{console.log("load graph",t),e({workflow_id:t.workflow_id,nodes:t.nodes,edges:t.edges,values:t.values,job_status:t.job_status??null,name:t.name}),s(),p.addUndoStack("init")},setJobStatus:t=>{e({job_status:t}),s()},setJobID:t=>{e({job_id:t})},setName:t=>{e({name:t}),s()}}}),x=e=>Symbol.iterator in e,W=(e,n)=>{const s=e instanceof Map?e:new Map(e),t=n instanceof Map?n:new Map(n);if(s.size!==t.size)return!1;for(const[a,r]of s)if(!Object.is(r,t.get(a)))return!1;return!0};function X(e,n){if(Object.is(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;if(x(e)&&x(n)){const t=e[Symbol.iterator](),a=n[Symbol.iterator]();let r=t.next(),o=a.next();if(Array.isArray(r.value)&&Array.isArray(o.value)&&r.value.length===2&&o.value.length===2)return W(e,n);for(;!r.done&&!o.done;){if(!Object.is(r.value,o.value))return!1;r=t.next(),o=a.next()}return!!r.done&&!!o.done}const s=Object.keys(e);if(s.length!==Object.keys(n).length)return!1;for(const t of s)if(!Object.hasOwn(n,t)||!Object.is(e[t],n[t]))return!1;return!0}function B(e){const n=y.useRef();return s=>{const t=e(s);return X(n.current,t)?n.current:n.current=t}}export{z as F,T as G,j as S,B as a,f as b,I as c,Z as d,p as e,U as f,G as g,g as u};
