import{j as l,c as R,d as j,e as E}from"./reactflow-vendor-DVEEOIVt.js";import{r as h,R as v}from"./react-vendor-4ldeB94U.js";import{a as b,m as I,S as C}from"./index-BXU-m2Zz.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 A={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 M=(e,s,n,a)=>{const t=h.forwardRef(({color:o="currentColor",size:r=24,stroke:i=2,title:d,className:c,children:g,...u},S)=>h.createElement("svg",{ref:S,...A[e],width:r,height:r,className:["tabler-icon",`tabler-icon-${s}`,c].join(" "),...e==="filled"?{fill:o}:{strokeWidth:i,stroke:o},...u},[d&&h.createElement("title",{key:"svg-title"},d),...a.map(([y,_])=>h.createElement(y,_)),...Array.isArray(g)?g:[g]]));return t.displayName=`${n}`,t};/**
 * @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 U=M("outline","loader-2","IconLoader2",[["path",{d:"M12 3a9 9 0 1 0 9 9",key:"svg-0"}]]);const N=h.forwardRef((e,s)=>{let{size:n=18,...a}=e;return typeof n=="string"&&(n=n==="sm"?12:n==="md"?24:18),l.jsxs("div",{...a,children:[l.jsx(U,{className:b("w-4 h-4 animate-spin",e.className)}),l.jsx("span",{className:"sr-only",children:"Loading..."})]})});N.displayName="Spinner";const z=I("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-primary/60 border-2 hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-8 px-4 py-2",sm:"h-6 rounded-md px-3",lg:"h-10 rounded-md px-8",icon:"h-8 w-8"}},defaultVariants:{variant:"default",size:"default"}}),D=h.forwardRef(({className:e,variant:s,size:n,asChild:a=!1,isLoading:t=!1,left:o,...r},i)=>{const d=a?C:"button";return l.jsx(d,{className:b(z({variant:s,size:n,className:e})),ref:i,...r,disabled:t||r.disabled,children:t?l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx(N,{size:n==="default"?"md":n=="sm"?"sm":"lg"}),l.jsx("span",{children:r.children})]}):l.jsxs("div",{className:"flex items-center gap-1",children:[o&&l.jsx("div",{className:"w-4",children:o}),l.jsx("span",{children:r.children})]})})});D.displayName="Button";const V="",K=window.location.host,O=async(e,s)=>fetch(V+e,s),f={fetchApi:O,wsUrl:`ws${window.location.protocol==="https:"?"s":""}://${K}/ws`,graph:{workflow_id:null,job_status:null,nodes:[],edges:[],values:{}},osSep:"."};O("/get_os_sep").then(e=>e.text()).then(e=>{e.length?f.osSep=e:console.error("Failed to get OS separator")});const L=h.forwardRef((e,s)=>l.jsx("div",{ref:s,style:{display:"flex",flexDirection:"row",alignItems:"center",...e.style},...e}));L.displayName="Flex";const w=e=>{let s;const n=new Set,a=(c,g)=>{const u=typeof c=="function"?c(s):c;if(!Object.is(u,s)){const S=s;s=g??(typeof u!="object"||u===null)?u:Object.assign({},s,u),n.forEach(y=>y(s,S))}},t=()=>s,i={setState:a,getState:t,getInitialState:()=>d,subscribe:c=>(n.add(c),()=>n.delete(c))},d=s=e(a,t,i);return i},F=e=>e?w(e):w,G=e=>e;function T(e,s=G){const n=v.useSyncExternalStore(e.subscribe,()=>s(e.getState()),()=>s(e.getInitialState()));return v.useDebugValue(n),n}const k=e=>{const s=F(e),n=a=>T(s,a);return Object.assign(n,s),n},$=e=>e?k(e):k;function H(e,s,n){return"node_"+s+"_"+e+"_"+n}const J="nozy_graph";class P{constructor(){this.undoStack=[],this.redoStack=[],this.nodeMoveOrResizeStorage=[],this.undo=()=>{if(this.undoStack.length){const n=this.undoStack.pop();if(n){const{nodes:a,edges:t}=p.getState();this.redoStack.push({nodes:a,edges:t}),p.setState({nodes:n.nodes,edges:n.edges})}else p.setState({nodes:[],edges:[]})}},this.redo=()=>{const n=this.redoStack.pop();if(n){const{nodes:a,edges:t}=p.getState();this.undoStack.push({nodes:a,edges:t}),p.setState({nodes:n.nodes,edges:n.edges})}},this.addUndoStack=(n,a)=>{const{nodes:t,edges:o}=p.getState();switch(n){case"init":this.undoStack=[];break;case"onNodesChange":if(a){const r=a[0],i=["dimensions","position","select"].includes(r.type),d=r.type==="position"||r.type==="dimensions"&&Object.hasOwn(r,"resizing"),c=r.dragging||r.resizing;if(d&&(c&&this.nodeMoveOrResizeStorage.length===0?this.nodeMoveOrResizeStorage=[...t]:!c&&this.nodeMoveOrResizeStorage.length>0&&(this.undoStack.push({nodes:this.nodeMoveOrResizeStorage,edges:o}),this.nodeMoveOrResizeStorage=[])),i)return}break}this.undoStack.push({nodes:t,edges:o}),this.undoStack.length>30&&this.undoStack.shift()};const s=n=>{const a=(n.ctrlKey||n.metaKey)&&n.key==="z"&&!n.shiftKey,t=(n.ctrlKey||n.metaKey)&&(n.shiftKey&&n.key==="z"||n.key==="y");if(a||t){const o=n.target;if(o.nodeName==="INPUT"||o.nodeName==="TEXTAREA"){document.execCommand(a?"undo":"redo"),n.preventDefault();return}a?this.undo():this.redo(),n.preventDefault()}};window.addEventListener("keydown",s)}}const m=new P,W="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let X=e=>crypto.getRandomValues(new Uint8Array(e)),Y=(e,s,n)=>{let a=(2<<Math.log(e.length-1)/Math.LN2)-1,t=-~(1.6*a*s/e.length);return(o=s)=>{let r="";for(;;){let i=n(t),d=t;for(;d--;)if(r+=e[i[d]&a]||"",r.length===o)return r}}},ne=(e,s=21)=>Y(e,s,X),q=(e=21)=>{let s="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;)s+=W[n[e]&63];return s};const p=$((e,s)=>{const n=()=>{const{workflow_id:t,nodes:o,edges:r,values:i,job_status:d,name:c}=s();f.graph.workflow_id=t,f.graph.nodes=o,f.graph.edges=r,f.graph.values=i,f.graph.job_status=d??null,f.graph.name=c??null,sessionStorage.setItem(J,JSON.stringify({workflow_id:t,nodes:o,edges:r,values:i,name:c}))},a=()=>{const{nodes:t}=s();let o=1;for(;o<t.length+1;){if(t.every(r=>r.id!==o.toString()))return o.toString();o++}return o.toString()};return{getNextNodeID:a,workflow_id:q(),name:"Untitled",nodes:[],edges:[],values:{},selectedNodeIDs:[],setSelectedNodeIDs:t=>{e({selectedNodeIDs:t})},showSearch:null,setShowSearch:t=>{e({showSearch:t})},updateValues:t=>{let o={...s().values};for(const[r,i]of Object.entries(t))i===void 0?delete o[r]:o[r]=i;e({values:o}),n()},onNodesChange:t=>{m.addUndoStack("onNodesChange",t),e({nodes:R(t,s().nodes)});const o=t.filter(i=>i.type==="remove").map(i=>i.id),r={...s().values};o.forEach(i=>{Object.keys(r).forEach(d=>{d.includes(`node_${i}`)&&delete r[d]})}),e({values:r}),n()},onEdgesChange:t=>{m.addUndoStack("onEdgesChange"),e({edges:j(t,s().edges)}),n()},addEdge:t=>{e({edges:s().edges.concat(t)}),n()},onConnect:t=>{m.addUndoStack("onConnect"),e({edges:E(t,s().edges)}),n()},setNodes:t=>{e({nodes:t})},setEdges:t=>{e({edges:t})},addNode:t=>{var r;t.id||(t.id=a()),m.addUndoStack("addNode"),e({nodes:s().nodes.concat(t)});const o={...s().values};return(r=t.data.input)==null||r.forEach(i=>{o[H("input",t.id,i.id)]=i.default??null}),e({values:o}),n(),t},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}),n(),m.addUndoStack("init")},setJobStatus:t=>{e({job_status:t}),n()},setJobID:t=>{e({job_id:t})},setName:t=>{e({name:t}),n()}}}),x=e=>Symbol.iterator in e,B=(e,s)=>{const n=e instanceof Map?e:new Map(e),a=s instanceof Map?s:new Map(s);if(n.size!==a.size)return!1;for(const[t,o]of n)if(!Object.is(o,a.get(t)))return!1;return!0};function Q(e,s){if(Object.is(e,s))return!0;if(typeof e!="object"||e===null||typeof s!="object"||s===null)return!1;if(x(e)&&x(s)){const a=e[Symbol.iterator](),t=s[Symbol.iterator]();let o=a.next(),r=t.next();if(Array.isArray(o.value)&&Array.isArray(r.value)&&o.value.length===2&&r.value.length===2)return B(e,s);for(;!o.done&&!r.done;){if(!Object.is(o.value,r.value))return!1;o=a.next(),r=t.next()}return!!o.done&&!!r.done}const n=Object.keys(e);if(n.length!==Object.keys(s).length)return!1;for(const a of n)if(!Object.hasOwn(s,a)||!Object.is(e[a],s[a]))return!1;return!0}function se(e){const s=v.useRef();return n=>{const a=e(n);return Q(s.current,a)?s.current:s.current=a}}export{D as B,L as F,J as G,N as S,se as a,f as b,M as c,ne as d,V as e,O as f,H as g,m as h,p as u};
