From fe37025d8ef6fd59dd81efd9f62383454e4cd98d Mon Sep 17 00:00:00 2001 From: Weixuan Fu Date: Fri, 12 Jan 2024 19:34:08 +0800 Subject: [PATCH] cleanup code --- .../workspace_web/{ModelManager.js => ModelManager-TrdKAAkW.js} | 0 .../{RecentFilesDrawer.js => RecentFilesDrawer-fgP2cnuP.js} | 0 dist/workspace_web/input.js | 2 +- entry/entry.js | 1 + ui/src/Api.ts | 1 - ui/vite.config.ts | 2 +- 6 files changed, 3 insertions(+), 3 deletions(-) rename dist/workspace_web/{ModelManager.js => ModelManager-TrdKAAkW.js} (100%) rename dist/workspace_web/{RecentFilesDrawer.js => RecentFilesDrawer-fgP2cnuP.js} (100%) diff --git a/dist/workspace_web/ModelManager.js b/dist/workspace_web/ModelManager-TrdKAAkW.js similarity index 100% rename from dist/workspace_web/ModelManager.js rename to dist/workspace_web/ModelManager-TrdKAAkW.js diff --git a/dist/workspace_web/RecentFilesDrawer.js b/dist/workspace_web/RecentFilesDrawer-fgP2cnuP.js similarity index 100% rename from dist/workspace_web/RecentFilesDrawer.js rename to dist/workspace_web/RecentFilesDrawer-fgP2cnuP.js diff --git a/dist/workspace_web/input.js b/dist/workspace_web/input.js index 967608b..e1dd544 100644 --- a/dist/workspace_web/input.js +++ b/dist/workspace_web/input.js @@ -387,7 +387,7 @@ Error generating stack: `+i.message+` `)},w9=function(e){var t=e.noRelative,r=e.noImportant,n=e.gapMode,o=n===void 0?"margin":n,i=m.useMemo(function(){return y9(o)},[o]);return m.createElement(b9,{styles:x9(i,!t,o,r?"":"!important")})},rm=!1;if(typeof window<"u")try{var gu=Object.defineProperty({},"passive",{get:function(){return rm=!0,!0}});window.addEventListener("test",gu,gu),window.removeEventListener("test",gu,gu)}catch{rm=!1}var di=rm?{passive:!1}:!1,S9=function(e){return e.tagName==="TEXTAREA"},J_=function(e,t){var r=window.getComputedStyle(e);return r[t]!=="hidden"&&!(r.overflowY===r.overflowX&&!S9(e)&&r[t]==="visible")},k9=function(e){return J_(e,"overflowY")},C9=function(e){return J_(e,"overflowX")},Ob=function(e,t){var r=t.ownerDocument,n=t;do{typeof ShadowRoot<"u"&&n instanceof ShadowRoot&&(n=n.host);var o=Z_(e,n);if(o){var i=e2(e,n),a=i[1],s=i[2];if(a>s)return!0}n=n.parentNode}while(n&&n!==r.body);return!1},_9=function(e){var t=e.scrollTop,r=e.scrollHeight,n=e.clientHeight;return[t,r,n]},E9=function(e){var t=e.scrollLeft,r=e.scrollWidth,n=e.clientWidth;return[t,r,n]},Z_=function(e,t){return e==="v"?k9(t):C9(t)},e2=function(e,t){return e==="v"?_9(t):E9(t)},P9=function(e,t){return e==="h"&&t==="rtl"?-1:1},T9=function(e,t,r,n,o){var i=P9(e,window.getComputedStyle(t).direction),a=i*n,s=r.target,l=t.contains(s),u=!1,c=a>0,d=0,f=0;do{var p=e2(e,s),v=p[0],g=p[1],w=p[2],y=g-w-i*v;(v||y)&&Z_(e,s)&&(d+=y,f+=v),s instanceof ShadowRoot?s=s.host:s=s.parentNode}while(!l&&s!==document.body||l&&(t.contains(s)||t===s));return(c&&(o&&Math.abs(d)<1||!o&&a>d)||!c&&(o&&Math.abs(f)<1||!o&&-a>f))&&(u=!0),u},yu=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Db=function(e){return[e.deltaX,e.deltaY]},Rb=function(e){return e&&"current"in e?e.current:e},$9=function(e,t){return e[0]===t[0]&&e[1]===t[1]},A9=function(e){return` .block-interactivity-`.concat(e,` {pointer-events: none;} .allow-interactivity-`).concat(e,` {pointer-events: all;} -`)},M9=0,fi=[];function I9(e){var t=m.useRef([]),r=m.useRef([0,0]),n=m.useRef(),o=m.useState(M9++)[0],i=m.useState(Q_)[0],a=m.useRef(e);m.useEffect(function(){a.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=AB([e.lockRef.current],(e.shards||[]).map(Rb),!0).filter(Boolean);return g.forEach(function(w){return w.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var s=m.useCallback(function(g,w){if("touches"in g&&g.touches.length===2)return!a.current.allowPinchZoom;var y=yu(g),h=r.current,b="deltaX"in g?g.deltaX:h[0]-y[0],S="deltaY"in g?g.deltaY:h[1]-y[1],C,T=g.target,_=Math.abs(b)>Math.abs(S)?"h":"v";if("touches"in g&&_==="h"&&T.type==="range")return!1;var $=Ob(_,T);if(!$)return!0;if($?C=_:(C=_==="v"?"h":"v",$=Ob(_,T)),!$)return!1;if(!n.current&&"changedTouches"in g&&(b||S)&&(n.current=C),!C)return!0;var I=n.current||C;return T9(I,w,g,I==="h"?b:S,!0)},[]),l=m.useCallback(function(g){var w=g;if(!(!fi.length||fi[fi.length-1]!==i)){var y="deltaY"in w?Db(w):yu(w),h=t.current.filter(function(C){return C.name===w.type&&(C.target===w.target||w.target===C.shadowParent)&&$9(C.delta,y)})[0];if(h&&h.should){w.cancelable&&w.preventDefault();return}if(!h){var b=(a.current.shards||[]).map(Rb).filter(Boolean).filter(function(C){return C.contains(w.target)}),S=b.length>0?s(w,b[0]):!a.current.noIsolation;S&&w.cancelable&&w.preventDefault()}}},[]),u=m.useCallback(function(g,w,y,h){var b={name:g,delta:w,target:y,should:h,shadowParent:O9(y)};t.current.push(b),setTimeout(function(){t.current=t.current.filter(function(S){return S!==b})},1)},[]),c=m.useCallback(function(g){r.current=yu(g),n.current=void 0},[]),d=m.useCallback(function(g){u(g.type,Db(g),g.target,s(g,e.lockRef.current))},[]),f=m.useCallback(function(g){u(g.type,yu(g),g.target,s(g,e.lockRef.current))},[]);m.useEffect(function(){return fi.push(i),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",l,di),document.addEventListener("touchmove",l,di),document.addEventListener("touchstart",c,di),function(){fi=fi.filter(function(g){return g!==i}),document.removeEventListener("wheel",l,di),document.removeEventListener("touchmove",l,di),document.removeEventListener("touchstart",c,di)}},[]);var p=e.removeScrollBar,v=e.inert;return m.createElement(m.Fragment,null,v?m.createElement(i,{styles:A9(o)}):null,p?m.createElement(w9,{gapMode:e.gapMode}):null)}function O9(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const D9=MB(X_,I9);var t2=m.forwardRef(function(e,t){return m.createElement(Ud,Nr({},e,{ref:t,sideCar:D9}))});t2.classNames=Ud.classNames;const R9=t2;function F9(e){const{autoFocus:t,trapFocus:r,dialogRef:n,initialFocusRef:o,blockScrollOnMount:i,allowPinchZoom:a,finalFocusRef:s,returnFocusOnClose:l,preserveScrollBarGap:u,lockFocusAcrossFrames:c,isOpen:d}=Jo(),[f,p]=lC();m.useEffect(()=>{!f&&p&&setTimeout(p)},[f,p]);const v=Y_(n,d);return x.jsx(k_,{autoFocus:t,isDisabled:!r,initialFocusRef:o,finalFocusRef:s,restoreFocus:l,contentRef:n,lockFocusAcrossFrames:c,children:x.jsx(R9,{removeScrollBar:!u,allowPinchZoom:a,enabled:v===1&&i,forwardProps:!0,children:e.children})})}var Cl=te((e,t)=>{const{className:r,children:n,containerProps:o,motionProps:i,...a}=e,{getDialogProps:s,getDialogContainerProps:l}=Jo(),u=s(a,t),c=l(o),d=ie("chakra-modal__content",r),f=Ca(),p={display:"flex",flexDirection:"column",position:"relative",width:"100%",outline:0,...f.dialog},v={display:"flex",width:"100vw",height:"$100vh",position:"fixed",left:0,top:0,...f.dialogContainer},{motionPreset:g}=Jo();return x.jsx(F9,{children:x.jsx(H.div,{...c,className:"chakra-modal__content-container",tabIndex:-1,__css:v,children:x.jsx(K_,{preset:g,motionProps:i,className:d,...u,__css:p,children:n})})})});Cl.displayName="ModalContent";function j9(e){const{leastDestructiveRef:t,...r}=e;return x.jsx(kl,{...r,initialFocusRef:t})}var N9=te((e,t)=>x.jsx(Cl,{ref:t,role:"alertdialog",...e})),Hd=te((e,t)=>{const{className:r,...n}=e,o=ie("chakra-modal__footer",r),a={display:"flex",alignItems:"center",justifyContent:"flex-end",...Ca().footer};return x.jsx(H.footer,{ref:t,...n,__css:a,className:o})});Hd.displayName="ModalFooter";var _l=te((e,t)=>{const{className:r,...n}=e,{headerId:o,setHeaderMounted:i}=Jo();m.useEffect(()=>(i(!0),()=>i(!1)),[i]);const a=ie("chakra-modal__header",r),l={flex:0,...Ca().header};return x.jsx(H.header,{ref:t,className:a,id:o,...n,__css:l})});_l.displayName="ModalHeader";var z9=H(co.div),El=te((e,t)=>{const{className:r,transition:n,motionProps:o,...i}=e,a=ie("chakra-modal__overlay",r),l={pos:"fixed",left:"0",top:"0",w:"100vw",h:"100vh",...Ca().overlay},{motionPreset:u}=Jo(),d=o||(u==="none"?{}:AC);return x.jsx(z9,{...d,__css:l,ref:t,className:a,...i})});El.displayName="ModalOverlay";var Pl=te((e,t)=>{const{className:r,...n}=e,{bodyId:o,setBodyMounted:i}=Jo();m.useEffect(()=>(i(!0),()=>i(!1)),[i]);const a=ie("chakra-modal__body",r),s=Ca();return x.jsx(H.div,{ref:t,className:a,id:o,...n,__css:s.body})});Pl.displayName="ModalBody";var Tl=te((e,t)=>{const{onClick:r,className:n,...o}=e,{onClose:i}=Jo(),a=ie("chakra-modal__close-btn",n),s=Ca();return x.jsx(Yv,{ref:t,__css:s.closeButton,className:a,onClick:Ce(r,l=>{l.stopPropagation(),i()}),...o})});Tl.displayName="ModalCloseButton";var L9={exit:{scale:.85,opacity:0,transition:{opacity:{duration:.15,easings:"easeInOut"},scale:{duration:.2,easings:"easeInOut"}}},enter:{scale:1,opacity:1,transition:{opacity:{easings:"easeOut",duration:.2},scale:{duration:.2,ease:[.175,.885,.4,1.1]}}}},nm=e=>{var t;return((t=e.current)==null?void 0:t.ownerDocument)||document},Ju=e=>{var t,r;return((r=(t=e.current)==null?void 0:t.ownerDocument)==null?void 0:r.defaultView)||window};function B9(e={}){const{openDelay:t=0,closeDelay:r=0,closeOnClick:n=!0,closeOnMouseDown:o,closeOnScroll:i,closeOnPointerDown:a=o,closeOnEsc:s=!0,onOpen:l,onClose:u,placement:c,id:d,isOpen:f,defaultIsOpen:p,arrowSize:v=10,arrowShadowColor:g,arrowPadding:w,modifiers:y,isDisabled:h,gutter:b,offset:S,direction:C,...T}=e,{isOpen:_,onOpen:$,onClose:I}=N_({isOpen:f,defaultIsOpen:p,onOpen:l,onClose:u}),{referenceRef:O,getPopperProps:N,getArrowInnerProps:Y,getArrowProps:G}=j_({enabled:_,placement:c,arrowPadding:w,modifiers:y,gutter:b,offset:S,direction:C}),K=m.useId(),R=`tooltip-${d??K}`,A=m.useRef(null),D=m.useRef(),j=m.useCallback(()=>{D.current&&(clearTimeout(D.current),D.current=void 0)},[]),z=m.useRef(),L=m.useCallback(()=>{z.current&&(clearTimeout(z.current),z.current=void 0)},[]),q=m.useCallback(()=>{L(),I()},[I,L]),B=V9(A,q),U=m.useCallback(()=>{if(!h&&!D.current){_&&B();const fe=Ju(A);D.current=fe.setTimeout($,t)}},[B,h,_,$,t]),ee=m.useCallback(()=>{j();const fe=Ju(A);z.current=fe.setTimeout(q,r)},[r,q,j]),re=m.useCallback(()=>{_&&n&&ee()},[n,ee,_]),ye=m.useCallback(()=>{_&&a&&ee()},[a,ee,_]),be=m.useCallback(fe=>{_&&fe.key==="Escape"&&ee()},[_,ee]);ks(()=>nm(A),"keydown",s?be:void 0),ks(()=>{if(!i)return null;const fe=A.current;if(!fe)return null;const Qe=y_(fe);return Qe.localName==="body"?Ju(A):Qe},"scroll",()=>{_&&i&&q()},{passive:!0,capture:!0}),m.useEffect(()=>{h&&(j(),_&&I())},[h,_,I,j]),m.useEffect(()=>()=>{j(),L()},[j,L]),ks(()=>A.current,"pointerleave",ee);const qe=m.useCallback((fe={},Qe=null)=>({...fe,ref:kt(A,Qe,O),onPointerEnter:Ce(fe.onPointerEnter,ne=>{ne.pointerType!=="touch"&&U()}),onClick:Ce(fe.onClick,re),onPointerDown:Ce(fe.onPointerDown,ye),onFocus:Ce(fe.onFocus,U),onBlur:Ce(fe.onBlur,ee),"aria-describedby":_?R:void 0}),[U,ee,ye,_,R,re,O]),rt=m.useCallback((fe={},Qe=null)=>N({...fe,style:{...fe.style,[lt.arrowSize.var]:v?`${v}px`:void 0,[lt.arrowShadowColor.var]:g}},Qe),[N,v,g]),Xe=m.useCallback((fe={},Qe=null)=>{const po={...fe.style,position:"relative",transformOrigin:lt.transformOrigin.varRef};return{ref:Qe,...T,...fe,id:R,role:"tooltip",style:po}},[T,R]);return{isOpen:_,show:U,hide:ee,getTriggerProps:qe,getTooltipProps:Xe,getTooltipPositionerProps:rt,getArrowProps:G,getArrowInnerProps:Y}}var bp="chakra-ui:close-tooltip";function V9(e,t){return m.useEffect(()=>{const r=nm(e);return r.addEventListener(bp,t),()=>r.removeEventListener(bp,t)},[t,e]),()=>{const r=nm(e),n=Ju(e);r.dispatchEvent(new n.CustomEvent(bp))}}function W9(e,t=[]){const r=Object.assign({},e);for(const n of t)n in r&&delete r[n];return r}function U9(e,t){const r={};for(const n of t)n in e&&(r[n]=e[n]);return r}var H9=H(co.div),dn=te((e,t)=>{var r,n;const o=Cn("Tooltip",e),i=Pt(e),a=pv(),{children:s,label:l,shouldWrapChildren:u,"aria-label":c,hasArrow:d,bg:f,portalProps:p,background:v,backgroundColor:g,bgColor:w,motionProps:y,...h}=i,b=(n=(r=v??g)!=null?r:f)!=null?n:w;if(b){o.bg=b;const N=IM(a,"colors",b);o[lt.arrowBg.var]=N}const S=B9({...h,direction:a.direction}),C=typeof s=="string"||u;let T;if(C)T=x.jsx(H.span,{display:"inline-block",tabIndex:0,...S.getTriggerProps(),children:s});else{const N=m.Children.only(s);T=m.cloneElement(N,S.getTriggerProps(N.props,N.ref))}const _=!!c,$=S.getTooltipProps({},t),I=_?W9($,["role","id"]):$,O=U9($,["role","id"]);return l?x.jsxs(x.Fragment,{children:[T,x.jsx(wa,{children:S.isOpen&&x.jsx(so,{...p,children:x.jsx(H.div,{...S.getTooltipPositionerProps(),__css:{zIndex:o.zIndex,pointerEvents:"none"},children:x.jsxs(H9,{variants:L9,initial:"exit",animate:"enter",exit:"exit",...y,...I,__css:o,children:[l,_&&x.jsx(H.span,{srOnly:!0,...O,children:c}),d&&x.jsx(H.div,{"data-popper-arrow":!0,className:"chakra-tooltip__arrow-wrapper",children:x.jsx(H.div,{"data-popper-arrow-inner":!0,className:"chakra-tooltip__arrow",__css:{bg:o.bg}})})]})})})})]}):x.jsx(x.Fragment,{children:s})});dn.displayName="Tooltip";let bu;const G9=new Uint8Array(16);function K9(){if(!bu&&(bu=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!bu))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return bu(G9)}const it=[];for(let e=0;e<256;++e)it.push((e+256).toString(16).slice(1));function Y9(e,t=0){return it[e[t+0]]+it[e[t+1]]+it[e[t+2]]+it[e[t+3]]+"-"+it[e[t+4]]+it[e[t+5]]+"-"+it[e[t+6]]+it[e[t+7]]+"-"+it[e[t+8]]+it[e[t+9]]+"-"+it[e[t+10]]+it[e[t+11]]+it[e[t+12]]+it[e[t+13]]+it[e[t+14]]+it[e[t+15]]}const q9=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Fb={randomUUID:q9};function $l(e,t,r){if(Fb.randomUUID&&!t&&!e)return Fb.randomUUID();e=e||{};const n=e.random||(e.rng||K9)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let o=0;o<16;++o)t[r+o]=n[o];return t}return Y9(n)}async function _a(e){console.warn("getDB ntable",e);try{const t=await fetch(`/workspace/get_db?table=${e}`);return t.ok?await t.json():void 0}catch(t){console.error("Error fetching workspace:",t);return}}async function St(e,t){try{return await(await fetch("/workspace/save_db",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({table:e,json:t})})).text()}catch(r){console.error("Error saving workspace:",r)}}async function X9(e,t){try{return await(await fetch("/workspace/update_file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file_path:e,json_str:t})})).text()}catch(r){alert("Error saving workflow .json file: "+r),console.error("Error saving workspace:",r)}}async function r2(e,t=!0){try{return await(await fetch("/workspace/delete_file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file_path:e,deleteEmptyFolder:t})})).text()}catch(r){console.error("Error deleting file:",r)}}async function h7(e){try{return await(await fetch("/workspace/list_backup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:e})})).text()}catch(t){console.error("Error saving workspace:",t)}}async function Q9(e){try{return await(await fetch("/workspace/get_system_dir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({absolute_dir:e})})).json()}catch(t){console.error("Error getting workflows dir:",t)}}async function m7(){try{return await(await fetch("/workspace/open_workflow_file_browser",{method:"POST",headers:{"Content-Type":"application/json"}})).json()}catch(e){console.error("Error open workflows folder:",e)}}const v7="CWM_WORKFLOWS_SORT_TYPE";var sr=(e=>(e.RECENTLY_MODIFIED="newest",e.OLDEST_MODIFIED="oldest",e.AZ="name A-Z",e.ZA="name Z-A",e))(sr||{});const J9="comfyspace_tracking",Z9="http://localhost:8188/";function yg(e){if(e.name==null)return;const t=bg(e);t!=null&&r2(t)}function bg(e){let t=eW(e.name)+".json",r=e.parentFolderID;for(;r!=null;){const n=Yr==null?void 0:Yr.get(r);if(n==null)break;t=`${n.name}/${t}`,r=n.parentFolderID??void 0}return t??null}function n2(e){const t=bg(e);let r=Se==null?void 0:Se.getSetting("myWorkflowsDir");return r==null?(console.error("myWorkflowsDir is not set"),null):(r.endsWith("/")||(r=r+"/"),r+t)}function eW(e){return e=e.replace(/[\\/:*?"<>|]/g,"_"),e.trim()}function o2(e,t=!1){const r=new Date(e),n=String(r.getDate()).padStart(2,"0"),o=String(r.getMonth()+1).padStart(2,"0"),i=r.getFullYear(),a=String(r.getHours()).padStart(2,"0"),s=String(r.getMinutes()).padStart(2,"0"),l=String(r.getSeconds()).padStart(2,"0");let u=`${o}-${n}-${i} ${a}:${s}`;return t?u+`:${l}`:u}function tW(e=[],t=sr.RECENTLY_MODIFIED){const r=[...e];if(r.length)switch(t){case sr.AZ:r.sort((n,o)=>n.name.localeCompare(o.name));break;case sr.ZA:r.sort((n,o)=>o.name.localeCompare(n.name));break;case sr.RECENTLY_MODIFIED:r.sort((n,o)=>o.updateTime-n.updateTime);break;case sr.OLDEST_MODIFIED:r.sort((n,o)=>n.updateTime-o.updateTime);break}return r}function om(e=!0){Gd().forEach(t=>{const r=n2(t);t.filePath!=r&&(t.filePath!=null&&r2(t.filePath,e),ol(t))})}const rW=(e,t=sr.RECENTLY_MODIFIED)=>{const r=[...e];switch(t){case sr.AZ:r.sort((n,o)=>n.name.localeCompare(o.name));break;case sr.ZA:r.sort((n,o)=>o.name.localeCompare(n.name));break;case sr.RECENTLY_MODIFIED:r.sort((n,o)=>o.updateTime-n.updateTime);break;case sr.OLDEST_MODIFIED:r.sort((n,o)=>n.updateTime-o.updateTime);break}return r};function i2(e){var n;let t=e??"Untitled Flow";const r=(n=Gd())==null?void 0:n.map(o=>o.name);if(r.includes(t)){let o=2,i=!0;for(;i;)r.includes(`${t} ${o}`)?o++:(t=`${t} ${o}`,i=!1)}return t}function g7(e){return new Promise((t,r)=>{const n=new FileReader;n.onload=o=>{const i=new Uint8Array(o.target.result),a=new DataView(i.buffer);a.getUint32(0)!==2303741511&&(console.error("Not a valid PNG file"),r());let s=8;const l={};for(;sString.fromCharCode(g)).join("");l[f]=v}s+=12+u}t(l)},n.readAsArrayBuffer(e)})}const nW=e=>{var r;const t=(r=Se==null?void 0:Se.getSetting("shortcuts"))==null?void 0:r.save;return t?oW(e,t):!1},oW=(e,t)=>{const r=t.split("+"),n={Control:e.ctrlKey,Shift:e.shiftKey,Alt:e.altKey,Command:e.metaKey,[e.key.toUpperCase()]:!0};return r.every(o=>n[o])};function iW(e){const t=["png","jpg","jpeg","gif","bmp","webp"],r=e.split(".").pop();return r!=null&&t.includes(r)}function aW(e){return`/workspace/view_media?filename=${e}`}const a2="backup",va="workspace";let Bn=null;function s2(){return new Promise((e,t)=>{const r=indexedDB.open("WorkspaceDB",3);r.onupgradeneeded=n=>{const o=n.target.result;o.objectStoreNames.contains(va)||o.createObjectStore(va,{keyPath:"id"})},r.onsuccess=n=>{e(n.target.result)},r.onerror=n=>{t(n.target.error)}})}async function sW(e){try{return Bn==null&&(Bn=await s2()),new Promise((t,r)=>{if(Bn==null)return r("indexDB is null");const i=Bn.transaction([va],"readwrite").objectStore(va).put({id:a2,value:e});i.onsuccess=()=>t(),i.onerror=()=>r(i.error)})}catch(t){console.error("Error while opening database:",t)}}async function Gt(){try{const e=await fW();await sW(e)}catch(e){console.error("Error writing to IndexedDB:",e)}}async function lW(){try{return Bn==null&&(Bn=await s2()),new Promise((e,t)=>{if(Bn==null)return t("indexDB is null");const o=Bn.transaction([va],"readonly").objectStore(va).get(a2);o.onsuccess=()=>{o.result?e(o.result.value):e(void 0)},o.onerror=()=>t(o.error)})}catch(e){console.error("Error while reading from database:",e)}}async function Ea(){try{return await lW()}catch(e){console.error("Error retrieving data from IndexedDB:",e)}}const To=class To{constructor(){}static async load(){return new To}async listByWorkflowID(t){const r=await this.getRecords();return Object.values(r).filter(n=>n.workflowID===t).sort((n,o)=>o.createTime-n.createTime)}async getRecords(){let t=await _a(To.TABLE_NAME),r=t!=null?JSON.parse(t):null;if(r==null){const n=await Ea()??"{}";r=JSON.parse(n)[To.TABLE_NAME]}return r??{}}async get(t){return(await this.getRecords())[t]}async getLastestByWorkflowID(t){const r=await this.getRecords();return Object.values(r).filter(o=>o.workflowID===t).sort((o,i)=>i.createTime-o.createTime)[0]}async create(t){const r=await this.getLastestByWorkflowID(t.workflowID);if(r!=null&&r.json===t.json)return null;const n={id:$l(),json:t.json,workflowID:t.workflowID,createTime:Date.now()},o=await this.getRecords();return o[n.id]=n,St(To.TABLE_NAME,JSON.stringify(o)),Gt(),n}};Pn(To,"TABLE_NAME","changelogs");let Hc=To;const ji=class ji{constructor(){Pn(this,"records");this.records={}}static async load(){const t=new ji;let r=await _a(ji.TABLE_NAME),n=r!=null?JSON.parse(r):null;if(n==null){const o=await Ea()??"{}";n=JSON.parse(o)[ji.TABLE_NAME]}return n!=null&&(t.records=n),t}listAll(){return Object.values(this.records)}getRecords(){return this.records}get(t){return this.records[t]}create(t){const r=this.generateUniqueName(t.name),n={id:$l(),name:r,parentFolderID:t.parentFolderID??null,updateTime:Date.now(),createTime:Date.now(),type:"folder"};return this.records[n.id]=n,St("folders",JSON.stringify(this.records)),Gt(),n}update(t){const r=this.records[t.id];if(r==null)return;const n={...r,...t};t.name!=null&&(n.updateTime=Date.now()),this.records[t.id]=n,St("folders",JSON.stringify(this.records)),Gt(),om()}delete(t){delete this.records[t],Gd().filter(n=>n.parentFolderID==t).forEach(n=>no(n.id,{parentFolderID:void 0})),St("folders",JSON.stringify(this.records)),Gt(),om()}generateUniqueName(t){var o;let r=t??"New folder";const n=(o=this.listAll())==null?void 0:o.map(i=>i.name);if(n.includes(r)){let i=2,a=!0;for(;a;)n.includes(`${r} ${i}`)?i++:(r=`${r} ${i}`,a=!1)}return r}};Pn(ji,"TABLE_NAME","folders");let Gc=ji;class uW{constructor(t){Pn(this,"tableName");this.tableName=t}async listAll(){const t=await this.getRecords();return Object.values(t)}async getRecords(){let t=await _a(this.tableName),r;try{r=t!=null?JSON.parse(t):null}catch{}if(r==null){const n=await Ea()??"{}";r=JSON.parse(n)[this.tableName]}return r??{}}async get(t){return(await this.getRecords())[t]}async delete(t){const r=await this.getRecords();delete r[t],St(this.tableName,JSON.stringify(r)),Gt()}}class xg extends uW{constructor(){super("media")}async listByWorkflowID(t){const r=await this.getRecords();return Object.values(r).filter(n=>n.workflowID===t).sort((n,o)=>o.createTime-n.createTime)}async getLastestByWorkflowID(t){const r=await this.getRecords();return Object.values(r).filter(o=>o.workflowID===t).sort((o,i)=>i.createTime-o.createTime)[0]}async create(t){var s;const r=t.localPath.split(".").pop();if(r==null)return null;const n={id:$l(),localPath:t.localPath,workflowID:t.workflowID,createTime:Date.now(),format:r},o=((s=an(t.workflowID))==null?void 0:s.mediaIDs)??[],i=new Set(o).add(n.id);no(t.workflowID,{mediaIDs:Array.from(i),coverMediaPath:n.localPath});const a=await this.getRecords();return a[n.id]=n,St("media",JSON.stringify(a)),Gt(),n}}Pn(xg,"TABLE_NAME","media");async function cW(){const e=await _a("tags");let t;if(e==null){const r=await Ea()??"{}";t=JSON.parse(r).tags||{}}else t=JSON.parse(e??"{}")??{};return{tags:t,listAll(){return Object.values(t).sort((r,n)=>n.updateTime-r.updateTime)},upsert(r){return t[r]==null&&(t[r]={name:r,workflowIDs:[],updateTime:Date.now()}),t[r].updateTime=Date.now(),St("tags",JSON.stringify(t)),t[r]},delete(r){delete t[r],St("tags",JSON.stringify(t))}}}const $o=class $o{constructor(){Pn(this,"records");this.records={topBarStyle:{top:0,left:0},myWorkflowsDir:"",shortcuts:{save:"Shift+S"},autoSave:!0}}listSettings(){return this.records}getSetting(t){return this.records[t]}upsert(t){this.records={...this.records,...t},St($o.TABLE_NAME,JSON.stringify(this.records)),Gt()}static async load(){const t=new $o,r=await _a($o.TABLE_NAME);let n=r!=null?JSON.parse(r):null;if(n==null){const o=await Ea()??"{}";n=JSON.parse(o)[$o.TABLE_NAME]||{}}if(!n.myWorkflowsDir){const o=await Q9();n.myWorkflowsDir=`${o.dir_path}/my_workflows`}return t.records=n,t}};Pn($o,"TABLE_NAME","userSettings");let Kc=$o;function y7(e){return e.type==="folder"}let oe,Zu=null,Se=null,Yr=null,qr=null,Bt=null;async function dW(){const e=async()=>{const a=await _a("workflows");if(a==null){const s=await Ea()??"{}";oe=JSON.parse(s).workflows||{}}else oe=JSON.parse(a)},t=async()=>{Zu=await cW()},r=async()=>{Se=await Kc.load()},n=async()=>{Yr=await Gc.load()},o=async()=>{qr=await Hc.load()},i=async()=>{Bt=new xg};await Promise.all([e(),t(),r(),n(),o(),i()])}function b7(e,t){var i;if(oe==null)return[];const r=Object.values(oe).filter(a=>a.parentFolderID==e),n=((i=Yr==null?void 0:Yr.listAll())==null?void 0:i.filter(a=>a.parentFolderID==e))??[],o=[...r,...n];return rW(o,t??sr.RECENTLY_MODIFIED)}function no(e,t){if(oe==null)return;const r=oe[e];if(r==null)return;const n={...r,...t,id:e},o=JSON.stringify(r),i=JSON.stringify(n);if(o===i)return;let a=n;const s=Object.keys(t);if(s.length===1&&["tags","parentFolderID"].includes(s[0])||(a.updateTime=Date.now()),oe[e]=a,Gt(),St("workflows",JSON.stringify(oe)),t.name!=null||t.parentFolderID!=null){yg(r),ol(n);return}t.json!=null&&ol(n)}function ol(e){const t=bg(e);if(t==null)return;if(oe!=null){const o=n2(e);oe[e.id].filePath=o??void 0,Gt(),St("workflows",JSON.stringify(oe))}const r=e.json,n=JSON.parse(r);n.extra[J9]={id:e.id,name:e.name},X9(t,JSON.stringify(n))}function xp({json:e,name:t,parentFolderID:r,tags:n}){if(oe==null)throw new Error("workspace is not loaded");const o=i2(t),i=$l(),a=Date.now(),s={id:i,name:o,json:e,parentFolderID:r,updateTime:a,createTime:a,tags:n??[]};return oe[i]=s,St("workflows",JSON.stringify(oe)),Gt(),ol(oe[i]),oe[i]}async function x7(e){e.forEach(r=>{if(oe==null)return;const n=i2(r.name),o=$l(),i=Date.now();oe[o]={id:o,name:n,json:r.json,updateTime:i,createTime:i,tags:[]},ol(oe[o])});const t=JSON.stringify(oe);return Gt(),await St("workflows",t)}function Gd(e){if(oe==null)throw new Error("workspace is not loaded");const t=Object.values(oe);return tW(t,e)}function an(e){if(oe==null){console.error("workspace is not loaded");return}return oe[e]}function w7(e){if(oe==null)return;const t=oe[e];t&&yg({...t}),delete oe[e],Gt(),St("workflows",JSON.stringify(oe))}function S7(e){e.forEach(r=>{if(oe==null)return;const n=oe[r];n&&yg({...n}),oe&&delete oe[r]});const t=JSON.stringify(oe);Gt(),St("workflows",t)}async function fW(){const e=await(qr==null?void 0:qr.getRecords()),t=await(Bt==null?void 0:Bt.getRecords());return JSON.stringify({[Kc.TABLE_NAME]:Se==null?void 0:Se.records,tags:Zu==null?void 0:Zu.tags,workflows:oe,[Gc.TABLE_NAME]:Yr==null?void 0:Yr.getRecords(),[Hc.TABLE_NAME]:e,[xg.TABLE_NAME]:t})}const jb={last_node_id:9,last_link_id:9,nodes:[{id:7,type:"CLIPTextEncode",pos:[413,389],size:{0:425.27801513671875,1:180.6060791015625},flags:{},order:3,mode:0,inputs:[{name:"clip",type:"CLIP",link:5}],outputs:[{name:"CONDITIONING",type:"CONDITIONING",links:[6],slot_index:0}],properties:{},widgets_values:["text, watermark"]},{id:6,type:"CLIPTextEncode",pos:[415,186],size:{0:422.84503173828125,1:164.31304931640625},flags:{},order:2,mode:0,inputs:[{name:"clip",type:"CLIP",link:3}],outputs:[{name:"CONDITIONING",type:"CONDITIONING",links:[4],slot_index:0}],properties:{},widgets_values:["beautiful scenery nature glass bottle landscape, , purple galaxy bottle,"]},{id:5,type:"EmptyLatentImage",pos:[473,609],size:{0:315,1:106},flags:{},order:1,mode:0,outputs:[{name:"LATENT",type:"LATENT",links:[2],slot_index:0}],properties:{},widgets_values:[512,512,1]},{id:3,type:"KSampler",pos:[863,186],size:{0:315,1:262},flags:{},order:4,mode:0,inputs:[{name:"model",type:"MODEL",link:1},{name:"positive",type:"CONDITIONING",link:4},{name:"negative",type:"CONDITIONING",link:6},{name:"latent_image",type:"LATENT",link:2}],outputs:[{name:"LATENT",type:"LATENT",links:[7],slot_index:0}],properties:{},widgets_values:[0x8e7ff42ed37e,!0,20,8,"euler","normal",1]},{id:8,type:"VAEDecode",pos:[1209,188],size:{0:210,1:46},flags:{},order:5,mode:0,inputs:[{name:"samples",type:"LATENT",link:7},{name:"vae",type:"VAE",link:8}],outputs:[{name:"IMAGE",type:"IMAGE",links:[9],slot_index:0}],properties:{}},{id:9,type:"SaveImage",pos:[1451,189],size:{0:210,1:26},flags:{},order:6,mode:0,inputs:[{name:"images",type:"IMAGE",link:9}],properties:{}},{id:4,type:"CheckpointLoaderSimple",pos:[26,474],size:{0:315,1:98},flags:{},order:0,mode:0,outputs:[{name:"MODEL",type:"MODEL",links:[1],slot_index:0},{name:"CLIP",type:"CLIP",links:[3,5],slot_index:1},{name:"VAE",type:"VAE",links:[8],slot_index:2}],properties:{},widgets_values:["v1-5-pruned-emaonly.ckpt"]}],links:[[1,4,0,3,0,"MODEL"],[2,5,0,3,3,"LATENT"],[3,4,1,6,0,"CLIP"],[4,6,0,3,1,"CONDITIONING"],[5,4,1,7,0,"CLIP"],[6,7,0,3,2,"CONDITIONING"],[7,3,0,8,0,"LATENT"],[8,4,2,8,1,"VAE"],[9,8,0,9,0,"IMAGE"]],groups:[],config:{},extra:{},version:.4},Pa=m.createContext({curFlowID:null,loadWorkflowID:()=>{},saveCurWorkflow:()=>{},discardUnsavedChanges:()=>{},isDirty:!1,loadNewWorkflow:()=>{},loadFilePath:()=>{},setRoute:()=>{}}),k7=m.createContext({refreshFolderStamp:0,setRefreshFolderStamp:()=>{}});var pW={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"},hW=Object.defineProperty,mW=Object.defineProperties,vW=Object.getOwnPropertyDescriptors,Yc=Object.getOwnPropertySymbols,l2=Object.prototype.hasOwnProperty,u2=Object.prototype.propertyIsEnumerable,Nb=(e,t,r)=>t in e?hW(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,zb=(e,t)=>{for(var r in t||(t={}))l2.call(t,r)&&Nb(e,r,t[r]);if(Yc)for(var r of Yc(t))u2.call(t,r)&&Nb(e,r,t[r]);return e},gW=(e,t)=>mW(e,vW(t)),yW=(e,t)=>{var r={};for(var n in e)l2.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&Yc)for(var n of Yc(e))t.indexOf(n)<0&&u2.call(e,n)&&(r[n]=e[n]);return r},Nt=(e,t,r)=>{const n=m.forwardRef((o,i)=>{var a=o,{color:s="currentColor",size:l=24,stroke:u=2,children:c}=a,d=yW(a,["color","size","stroke","children"]);return m.createElement("svg",zb(gW(zb({ref:i},pW),{width:l,height:l,stroke:s,strokeWidth:u,className:`tabler-icon tabler-icon-${e}`}),d),[...r.map(([f,p])=>m.createElement(f,p)),...c||[]])});return n.propTypes={color:xo.string,size:xo.oneOfType([xo.string,xo.number]),stroke:xo.oneOfType([xo.string,xo.number])},n.displayName=`${t}`,n},bW=Nt("arrow-back-up-double","IconArrowBackUpDouble",[["path",{d:"M13 14l-4 -4l4 -4",key:"svg-0"}],["path",{d:"M8 14l-4 -4l4 -4",key:"svg-1"}],["path",{d:"M9 10h7a4 4 0 1 1 0 8h-1",key:"svg-2"}]]),xW=Nt("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]),im=Nt("device-floppy","IconDeviceFloppy",[["path",{d:"M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2",key:"svg-0"}],["path",{d:"M12 14m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0",key:"svg-1"}],["path",{d:"M14 4l0 4l-6 0l0 -4",key:"svg-2"}]]),wW=Nt("download","IconDownload",[["path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2",key:"svg-0"}],["path",{d:"M7 11l5 5l5 -5",key:"svg-1"}],["path",{d:"M12 4l0 12",key:"svg-2"}]]),SW=Nt("folder","IconFolder",[["path",{d:"M5 4h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2",key:"svg-0"}]]),kW=Nt("grip-vertical","IconGripVertical",[["path",{d:"M9 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-0"}],["path",{d:"M9 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-1"}],["path",{d:"M9 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-2"}],["path",{d:"M15 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-3"}],["path",{d:"M15 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-4"}],["path",{d:"M15 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-5"}]]),CW=Nt("history","IconHistory",[["path",{d:"M12 8l0 4l2 2",key:"svg-0"}],["path",{d:"M3.05 11a9 9 0 1 1 .5 4m-.5 5v-5h5",key:"svg-1"}]]),_W=Nt("photo","IconPhoto",[["path",{d:"M15 8h.01",key:"svg-0"}],["path",{d:"M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12z",key:"svg-1"}],["path",{d:"M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5",key:"svg-2"}],["path",{d:"M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3",key:"svg-3"}]]),EW=Nt("pin-filled","IconPinFilled",[["path",{d:"M15.113 3.21l.094 .083l5.5 5.5a1 1 0 0 1 -1.175 1.59l-3.172 3.171l-1.424 3.797a1 1 0 0 1 -.158 .277l-.07 .08l-1.5 1.5a1 1 0 0 1 -1.32 .082l-.095 -.083l-2.793 -2.792l-3.793 3.792a1 1 0 0 1 -1.497 -1.32l.083 -.094l3.792 -3.793l-2.792 -2.793a1 1 0 0 1 -.083 -1.32l.083 -.094l1.5 -1.5a1 1 0 0 1 .258 -.187l.098 -.042l3.796 -1.425l3.171 -3.17a1 1 0 0 1 1.497 -1.26z",fill:"currentColor",key:"svg-0",strokeWidth:"0"}]]),PW=Nt("pin","IconPin",[["path",{d:"M15 4.5l-4 4l-4 1.5l-1.5 1.5l7 7l1.5 -1.5l1.5 -4l4 -4",key:"svg-0"}],["path",{d:"M9 15l-4.5 4.5",key:"svg-1"}],["path",{d:"M14.5 4l5.5 5.5",key:"svg-2"}]]),TW=Nt("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]),$W=Nt("trash","IconTrash",[["path",{d:"M4 7l16 0",key:"svg-0"}],["path",{d:"M10 11l0 6",key:"svg-1"}],["path",{d:"M14 11l0 6",key:"svg-2"}],["path",{d:"M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12",key:"svg-3"}],["path",{d:"M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3",key:"svg-4"}]]),AW=Nt("triangle-inverted-filled","IconTriangleInvertedFilled",[["path",{d:"M20.118 3h-16.225a2.914 2.914 0 0 0 -2.503 4.371l8.116 13.549a2.917 2.917 0 0 0 4.987 .005l8.11 -13.539a2.914 2.914 0 0 0 -2.486 -4.386z",fill:"currentColor",key:"svg-0",strokeWidth:"0"}]]),c2=Nt("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);const d2=m.createContext(void 0),f2=()=>{const e=m.useContext(d2);if(!e)throw new Error("useDialog must be used within a DialogProvider");return e},MW=({children:e})=>{const[t,r]=m.useState(!1),[n,o]=m.useState(""),[i,a]=m.useState([]),s=Xr.useRef(null),l=m.useCallback((c,d)=>{o(c),a(d),r(!0)},[]),u=m.useCallback(()=>{r(!1)},[]);return x.jsxs(d2.Provider,{value:{showDialog:l},children:[e,t&&x.jsx(j9,{isOpen:t,leastDestructiveRef:s,onClose:u,size:"lg",children:x.jsx(kS,{children:x.jsx(El,{children:x.jsxs(N9,{className:"workspace_manager",children:[x.jsx(_l,{fontSize:"lg",fontWeight:"bold"}),x.jsx(Tl,{}),x.jsx(Pl,{children:n}),x.jsx(Hd,{children:i.map((c,d)=>x.jsx(Tr,{colorScheme:c.colorScheme??"gray",onClick:()=>{c.onClick(),u()},ml:3,children:c.label},d))})]})})})})]})},xu=200;function IW({onclose:e}){const{curFlowID:t,loadNewWorkflow:r,loadFilePath:n}=m.useContext(Pa),o=t!=null?an(t):null,[i,a]=m.useState([]),[s,l]=m.useState(!1),[u,c]=m.useState(o==null?void 0:o.coverMediaPath),[d,f]=m.useState([]),{showDialog:p}=f2(),v=async()=>{if(t==null)return;const h=await(Bt==null?void 0:Bt.listByWorkflowID(t));f(h??[])};if(m.useEffect(()=>{v()},[]),t==null)return null;const g=()=>{v()},w=h=>{if(s){i.includes(h.id)?a(i.filter(b=>b!==h.id)):a([...i,h.id]);return}window.open(`/workspace/view_media?filename=${h.localPath}`)},y=d.length>0&&i.length===d.length;return x.jsxs(kl,{isOpen:!0,onClose:e,blockScrollOnMount:!0,children:[x.jsx(El,{}),x.jsxs(Cl,{width:"90%",maxWidth:"90vw",height:"90vh",children:[x.jsxs(_l,{children:[x.jsx(Lr,{gap:2,mb:2,children:x.jsxs(ug,{size:"md",mr:2,children:["Gallery - ",o==null?void 0:o.name]})}),s&&x.jsxs(Lr,{gap:3,children:[x.jsx(Yu,{isChecked:y,onChange:()=>{a(y?[]:d.map(h=>h.id))},children:"All"}),x.jsxs(da,{fontSize:16,children:[i.length," Selected"]}),x.jsx(Jn,{size:"sm",icon:x.jsx(c2,{size:19}),onClick:()=>l(!1),"aria-label":"cancel"})]})]}),x.jsx(Tl,{}),x.jsx(Pl,{overflowY:"auto",children:x.jsx(Lr,{wrap:"wrap",children:d.map(h=>{if(h.localPath==null)return null;const b=iW(h.localPath)?x.jsxs(Qh,{isExternal:!0,onClick:()=>w(h),position:"relative",children:[s&&x.jsx(Yu,{isChecked:i.includes(h.id),position:"absolute",top:2,left:2}),x.jsx(IC,{borderRadius:3,boxSize:xu+"px",objectFit:"cover",src:`/workspace/view_media?filename=${h.localPath}`,alt:"workflow image renamed or moved from output folder"})]}):x.jsxs(Qh,{isExternal:!0,onClick:()=>w(h),children:[s&&x.jsx(Yu,{isChecked:i.includes(h.id)}),x.jsx("video",{width:xu,height:xu,src:`/workspace/view_media?filename=${h.localPath}`,loop:!0,autoPlay:!0,muted:!0,children:x.jsx("track",{kind:"captions"})})]}),S=u!=null&&u===h.localPath;return x.jsxs(Vd,{width:xu,justifyContent:"space-between",mb:2,children:[x.jsx(dn,{label:o2(h.createTime,!0),children:b}),x.jsx(dn,{label:h.localPath,children:x.jsx(da,{color:"GrayText",noOfLines:1,children:h.localPath})}),x.jsxs(Lr,{justifyContent:"space-between",hidden:s,children:[x.jsx(dn,{label:"Set as cover",children:x.jsx(Jn,{size:"sm",variant:"ghost",icon:S?x.jsx(EW,{size:19}):x.jsx(PW,{size:19}),"aria-label":"set as cover",isActive:S,onClick:()=>{no(t,{coverMediaPath:h.localPath}),c(h.localPath)}})}),x.jsx(Tr,{flexGrow:1,onClick:()=>p("How do you want to load this workflow?",[{label:"Load in new workflow",onClick:()=>{n(h.localPath)},colorScheme:"teal"},{label:"Overwrite current workflow",onClick:()=>n(h.localPath,!0),colorScheme:"red"}]),size:"sm",children:"Load"}),x.jsx(dn,{label:"Remove image from gallery",children:x.jsx(Jn,{size:"sm",variant:"ghost",icon:x.jsx($W,{size:19}),"aria-label":"remove image from gallery",colorScheme:"red",onClick:()=>{confirm("Are you sure to remove this image from gallery? (won't delete image on your disk)")&&(Bt==null||Bt.delete(h.id),S&&(no(t,{coverMediaPath:void 0}),c(void 0)),g())}})})]})]})})})})]})]})}const wp={x:0,y:0};function OW({children:e,onDragEnd:t}){const r=m.useRef(wp),n=m.useRef(!1),[o,i]=m.useState(wp),a=c=>{var d,f,p;if([(d=c.target)==null?void 0:d.id,(p=(f=c.target)==null?void 0:f.parentNode)==null?void 0:p.id].includes("dragPanelIcon")){r.current={x:c.clientX,y:c.clientY},n.current=!0,window.addEventListener("mousemove",s),window.addEventListener("mouseup",l);const v=document.getElementsByTagName("body")[0];v.style.userSelect="none"}},s=m.useCallback(c=>{const d={x:c.clientX-r.current.x,y:c.clientY-r.current.y};i(d)},[]),l=m.useCallback(()=>{i(d=>(t(d),wp)),n.current=!1;const c=document.getElementsByTagName("body")[0];c.style.userSelect="auto",window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",l)},[t,s]),u={transform:`translate(${o.x}px, ${o.y}px)`,zIndex:n.current?1e3:1};return x.jsx("div",{style:u,onMouseDown:a,children:e})}function DW({backgroundColor:e}){const t=e===void 0?"rgba(0,0,0,0.5)":e??void 0;return x.jsx("div",{style:{position:"fixed",top:0,bottom:0,left:0,right:0,backgroundColor:t}})}function RW({onClose:e}){const{curFlowID:t,isDirty:r}=m.useContext(Pa),[n,o]=m.useState(null),i=t!=null?an(t):null,[a,s]=m.useState([]);return t==null||i==null?(alert("No current workflow found!"),null):(m.useEffect(()=>{(async()=>{var f;const u=await(qr==null?void 0:qr.listByWorkflowID(t));s(u??[]);const c=u==null?void 0:u.filter(p=>p.json===i.lastSavedJson),d=(f=c==null?void 0:c[0])==null?void 0:f.id;d&&o(d)})()},[]),x.jsxs(BL,{width:400,height:"100vh",pl:4,pr:5,pt:4,gap:0,position:"fixed",top:0,left:0,zIndex:1e3,children:[x.jsx(LL,{pb:1,mb:0,children:x.jsxs(P_,{justifyContent:"space-between",alignItems:"center",children:[x.jsx(ug,{size:"md",children:"Version History"}),x.jsx(Jn,{size:"sm",icon:x.jsx(c2,{}),onClick:e,variant:"ghost","aria-label":"close version history"})]})}),x.jsxs(zL,{overflowY:"auto",gap:0,children:[x.jsx(da,{mb:4,children:"All the saved changes of this workflow"}),x.jsx(Vd,{divider:x.jsx(C_,{}),spacing:2,children:a==null?void 0:a.map(l=>x.jsxs(Tr,{size:"sm",variant:"ghost",onClick:()=>{if(r){alert("You have unsaved changes, please save or discard your changes to proceed switching version, in case losing your changes.");return}gr.loadGraphData(JSON.parse(l.json)),no(t,{lastSavedJson:l.json}),e()},isActive:l.id===n,children:["Saved at ",o2(l.createTime,!0)]}))})]})]}))}function FW({onClick:e}){var S;const{curFlowID:t,onDuplicateWorkflow:r,discardUnsavedChanges:n,saveCurWorkflow:o}=m.useContext(Pa),[i,a]=m.useState(!1),[s,l]=m.useState(!1),[u,c]=m.useState(""),[d,f]=m.useState(""),[p,v]=m.useState();m.useEffect(()=>{const C=t?an(t):void 0;c((C==null?void 0:C.name)??""),v(C)},[t]);const g=C=>{c(C.target.value),d&&f("")},w=()=>{if(!t){alert("Flow ID is required");return}r==null||r(t,u),y()},y=()=>{a(!1)},h=m.useCallback(()=>{if(!oe||!t){alert("You don't have any workspaces");return}const C=oe[t];if(!C){alert("Workspace does not exist");return}const T=new Blob([C.json],{type:"application/json"}),_=URL.createObjectURL(T),$=document.createElement("a");$.href=_,$.download=`${C.name}.json`,document.body.appendChild($),$.click(),document.body.removeChild($),URL.revokeObjectURL(_)},[t]),b=(S=Se==null?void 0:Se.getSetting("shortcuts"))==null?void 0:S.save;return x.jsxs(x.Fragment,{children:[x.jsx(V_,{isLazy:!0,children:({isOpen:C})=>x.jsxs(x.Fragment,{children:[x.jsx(G_,{onClick:e,children:x.jsx(Jn,{icon:x.jsx(xW,{size:20}),"aria-label":"menu",size:"xs",backgroundColor:"#323232",color:"white"})}),x.jsxs(so,{children:[x.jsxs(H_,{minWidth:150,zIndex:1e3,children:[x.jsx(pi,{onClick:o,icon:x.jsx(im,{size:20}),iconSpacing:1,command:b,children:"Save"}),x.jsx(dn,{label:"This will revert current workflow to your last saved version. You will lose all changes made since your last save.",children:x.jsx(pi,{onClick:n,icon:x.jsx(bW,{size:20}),iconSpacing:1,isDisabled:(p==null?void 0:p.lastSavedJson)==null,children:"Discard unsaved changes"})}),x.jsx(pi,{onClick:h,icon:x.jsx(wW,{size:20}),iconSpacing:1,children:"Download"}),x.jsx(pi,{onClick:()=>a(!0),icon:x.jsx(im,{size:20}),iconSpacing:1,children:"Save As"}),x.jsx(pi,{onClick:()=>l(!0),icon:x.jsx(CW,{size:20}),iconSpacing:1,children:"Versions History"})]}),C&&x.jsx(DW,{backgroundColor:null})]})]})}),s&&x.jsx(RW,{onClose:()=>l(!1)}),i&&x.jsxs(kl,{isOpen:!0,onClose:y,children:[x.jsx(El,{}),x.jsxs(Cl,{children:[x.jsx(_l,{children:"Save As"}),x.jsx(Tl,{}),x.jsx(Pl,{children:x.jsxs(qv,{isInvalid:!!d,children:[x.jsx(Qv,{children:"Workflow name"}),x.jsx(Bd,{value:u,onChange:g,autoFocus:!0,onKeyUp:C=>{C.code==="Enter"&&!d&&w()}}),d&&x.jsx(Xv,{children:d})]})}),x.jsxs(Hd,{children:[x.jsx(Tr,{colorScheme:"teal",mr:3,onClick:w,isDisabled:!u||!!d,children:"Save"}),x.jsx(Tr,{onClick:y,children:"Cancel"})]})]})]})]})}function jW({displayName:e,updateFlowName:t,isDirty:r}){const{isOpen:n,onOpen:o,onClose:i}=G6(),{curFlowID:a}=m.useContext(Pa),[s,l]=m.useState(e),[u,c]=m.useState(""),d=()=>{l(e),o()},f=g=>{l(g.target.value),u&&c("")},p=()=>{var g;if(a){const w=s.trim();if(l(w),e===w)return v();((g=Gd())==null?void 0:g.map(h=>h.name)).includes(w)?c("The name is duplicated, please modify it and submit again."):(no(a,{name:w}),t(w),v())}},v=()=>{c(""),i()};return a==null?null:x.jsxs(Lr,{children:[x.jsx(dn,{label:e,placement:"bottom",children:x.jsxs(da,{color:"white",onClick:d,maxW:240,fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",children:[r&&"* ",e]})}),x.jsxs(kl,{isOpen:n,onClose:v,children:[x.jsx(El,{}),x.jsxs(Cl,{children:[x.jsx(_l,{children:"Edit workflow name"}),x.jsx(Tl,{}),x.jsx(Pl,{children:x.jsxs(qv,{isInvalid:!!u,children:[x.jsx(Qv,{children:"Workflow name"}),x.jsx(Bd,{value:s,onChange:f,autoFocus:!0,onKeyUp:g=>{g.code==="Enter"&&!u&&p()}}),u&&x.jsx(Xv,{children:u})]})}),x.jsxs(Hd,{children:[x.jsx(Tr,{colorScheme:"teal",mr:3,onClick:p,isDisabled:!s||!!u,children:"Save"}),x.jsx(Tr,{onClick:v,children:"Cancel"})]})]})]})]})}function NW({updatePanelPosition:e,positionStyle:t,curFlowName:r,setCurFlowName:n}){const[o,i]=m.useState(!1),{isDirty:a,loadNewWorkflow:s,saveCurWorkflow:l,setRoute:u,curFlowID:c}=m.useContext(Pa);return x.jsx(OW,{onDragEnd:d=>{e({top:d.y,left:d.x},!0)},children:x.jsxs(Lr,{style:{padding:2,position:"fixed",...t},justifyContent:"space-between",alignItems:"center",gap:2,draggable:!1,id:"workspaceManagerPanel",onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[x.jsx(Tr,{size:"sm","aria-label":"workspace folder",onClick:()=>u("recentFlows"),px:2,children:x.jsxs(Lr,{gap:1,children:[x.jsx(SW,{size:21}),x.jsx(AW,{size:8})]})}),x.jsx(Tr,{size:"sm",variant:"outline",colorScheme:"teal","aria-label":"new workflow",onClick:()=>s(),px:2,children:x.jsxs(Lr,{gap:1,children:[x.jsx(TW,{size:16,color:"white"}),x.jsx(da,{color:"white",fontSize:"sm",children:"New"})]})}),x.jsx(jW,{isDirty:a,displayName:r??"",updateFlowName:d=>{n(d),requestAnimationFrame(()=>{e()})}}),c&&x.jsxs(Lr,{gap:"1px",children:[x.jsx(dn,{label:"Open gallery",children:x.jsx(Jn,{onClick:()=>u("gallery"),icon:x.jsx(_W,{size:20,color:"white"}),size:"sm","aria-label":"open gallery",variant:"ghost"})}),x.jsx(FW,{onClick:()=>i(!1)})]}),c&&a&&x.jsx(dn,{label:"Save workflow",children:x.jsx(Jn,{onClick:l,icon:x.jsx(im,{size:22,color:"white"}),size:"xs","aria-label":"save workspace",variant:"ghost"})}),o&&x.jsx(kW,{id:"dragPanelIcon",cursor:"move",size:15,color:"#FFF"})]})})}var zW={BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const LW=zW.VITE_AWS_COGNITO_DOMAIN;function BW(){if(window.location.href.includes(Z9+"#")){const e=window.location.href.split("#")[1];let r=new URLSearchParams(e).get("access_token");window.opener.postMessage({comfyspace_authToken:r},"http://127.0.0.1:8188/"),window.close()}}function Lb(e){const{comfyspace_authToken:t}=e.data;t&&fetch(`${LW}/oauth2/userInfo`,{method:"GET",headers:{Authorization:`Bearer ${t}`}}).then(r=>r.json()).then(r=>{console.log("User Info:",r)}).catch(r=>{console.error("Error fetching user info:",r)})}const VW=Xr.lazy(()=>eS(()=>import("./ModelManager.js"),__vite__mapDeps([]))),WW=Xr.lazy(()=>eS(()=>import("./RecentFilesDrawer.js"),__vite__mapDeps([])));function UW(){const e=m.useRef({}),[t,r]=m.useState(null),[n,o]=m.useState("root"),[i,a]=m.useState(!0),[s,l]=m.useState(null),u=m.useRef(null),[c,d]=m.useState(),[f,p]=m.useState(!1),v=m.useRef(null),{showDialog:g}=f2(),[w,y]=m.useState(!1),h=m.useCallback(()=>{if(u.current){const R=JSON.stringify(gr.graph.serialize());no(u.current,{lastSavedJson:R,json:R}),qr==null||qr.create({workflowID:u.current,json:R})}},[]),b=()=>{if(confirm("Are you sure you want to discard unsaved changes? This will revert current workflow to your last saved version. You will lose all changes made since your last save.")&&u.current){const A=an(u.current);A&&A.lastSavedJson&&gr.loadGraphData(JSON.parse(A.lastSavedJson))}},S=R=>{u.current=R,l(R),an(R)&&localStorage.setItem("curFlowID",R)},C=async()=>{const R={name:"WorkspaceManager",async setup(j){localStorage.removeItem("workspace"),localStorage.removeItem("comfyspace")},async addCustomNodeDefs(j){e.current=j},async afterConfigureGraph(){localStorage.setItem("workflow",JSON.stringify(gr.graph.serialize()))}};gr.registerExtension(R);try{await dW(),Y(Se==null?void 0:Se.getSetting("topBarStyle"),!1)}catch(j){console.error("error loading db",j)}a(!1);const A=localStorage.getItem("curFlowID"),D=A!=null?an(A):null;D&&(D&&localStorage.setItem("workflow",D.json),S(D.id??null),r(D.name??null)),om()};m.useEffect(()=>{C(),y(!0),setInterval(()=>{const R=(Se==null?void 0:Se.getSetting("autoSave"))??!0;if(u.current!=null&&R){const A=JSON.stringify(gr.graph.serialize());A!=null&&no(u.current,{json:A})}p(T())},1e3),BW()},[]);const T=()=>{if(u.current!=null){const R=gr.graph.serialize()??{},A=u.current?an(u.current):null;let D={};try{D=A!=null&&A.lastSavedJson?JSON.parse(A==null?void 0:A.lastSavedJson):{}}catch(z){console.error("error parsing json",z)}return!(JSON.stringify(R)===JSON.stringify(D))}return!1},_=R=>{if(gr.graph==null){console.error("app.graph is null cannot load workflow");return}S(R);const A=an(R);if(A==null){alert("Error: Workflow not found! id: "+R);return}gr.ui.dialog.close(),gr.loadGraphData(JSON.parse(A.json)),r(A.name),o("root")},$=R=>{if(((Se==null?void 0:Se.getSetting("autoSave"))??!0)||!f){_(R);return}g(`Do you want to save the current workflow, ${t}?`,[{label:"Save",colorScheme:"teal",onClick:()=>{h(),_(R)}},{label:"Discard",colorScheme:"red",onClick:()=>{_(R)}}])},I=R=>{const A=(R==null?void 0:R.json)??JSON.stringify(jb),D=xp({json:A,name:R==null?void 0:R.name});$(D.id),o("root")},O=async(R,A=!1)=>{const D=R.split("/").pop()??R;A?h():I({name:D});const j=await fetch(aW(R)),z=await j.blob(),L=new File([z],D,{type:j.headers.get("Content-Type")||""});await gr.handleFile(L),o("root")},N=(R,A)=>{if(oe==null)return;const D=oe[R];if(D==null)return;const j=xp({json:D.json,name:A||D.name,parentFolderID:D.parentFolderID,tags:D.tags});$(j.id)},Y=m.useCallback((R,A=!1)=>{const{top:D=0,left:j=0}=c||{};let{top:z=0,left:L=0}=R??{};z+=D,L+=j;const q=document.documentElement.clientWidth,B=document.documentElement.clientHeight,U=document.getElementById("workspaceManagerPanel"),ee=(U==null?void 0:U.offsetWidth)||392;z+36>B&&(z=B-36),L+ee>=q&&(L=q-ee),d({top:Math.max(0,z),left:Math.max(0,L)}),A&&(Se==null||Se.upsert({topBarStyle:{top:z,left:L}}))},[c]),G=R=>{nW(R)&&h()},K=m.useCallback(R=>{if(u.current==null)return;let A=R.filename;R.subfolder!=null&&R.subfolder!==""&&(A=R.subfolder+"/"+A),Bt==null||Bt.create({workflowID:u.current,localPath:A})},[]),Z=m.useCallback(()=>{o("root")},[]);return m.useEffect(()=>{window.addEventListener("keydown",G),window.addEventListener("message",Lb);const R=document.getElementById("comfy-file-input"),A=()=>{if(R&&R.files&&R.files.length>0){const j=xp({name:R.files[0].name,json:JSON.stringify(jb)});S(j.id),r(j.name??"Unknown name")}};R==null||R.addEventListener("change",A);const D=j=>{!((Se==null?void 0:Se.getSetting("autoSave"))??!0)&&T()&&(j.preventDefault(),j.returnValue="You have unsaved changes")};return window.addEventListener("beforeunload",D),wE.addEventListener("executed",j=>{var z,L,q,B,U,ee;(q=(L=(z=j.detail)==null?void 0:z.output)==null?void 0:L.images)==null||q.forEach(re=>{re.type==="output"&&K(re)}),(ee=(U=(B=j.detail)==null?void 0:B.output)==null?void 0:U.gifs)==null||ee.forEach(re=>{re.type==="output"&&K(re)})}),()=>{window.removeEventListener("message",Lb),window.removeEventListener("keydown",G),window.removeEventListener("change",A),window.removeEventListener("beforeunload",D)}},[]),i||!c?null:x.jsx(Pa.Provider,{value:{curFlowID:s,onDuplicateWorkflow:N,loadWorkflowID:$,discardUnsavedChanges:b,saveCurWorkflow:h,isDirty:f,loadNewWorkflow:I,loadFilePath:O,setRoute:o},children:x.jsx("div",{ref:v,className:"workspace_manager",children:x.jsxs(so,{containerRef:v,children:[w&&x.jsx(m.Suspense,{children:x.jsx(VW,{})}),x.jsxs(cg,{style:{width:"100vh",position:"absolute",top:0,left:0,lineHeight:"24px"},zIndex:1e3,draggable:!1,children:[x.jsx(NW,{curFlowName:t,setCurFlowName:r,updatePanelPosition:Y,positionStyle:c}),w&&n==="recentFlows"&&x.jsx(m.Suspense,{children:x.jsx(WW,{onClose:Z,onClickNewFlow:()=>{I(),o("root")}})}),n==="gallery"&&x.jsx(IW,{onclose:()=>o("root")})]})]})})})}const p2=String.raw,HW=p2` +`)},M9=0,fi=[];function I9(e){var t=m.useRef([]),r=m.useRef([0,0]),n=m.useRef(),o=m.useState(M9++)[0],i=m.useState(Q_)[0],a=m.useRef(e);m.useEffect(function(){a.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=AB([e.lockRef.current],(e.shards||[]).map(Rb),!0).filter(Boolean);return g.forEach(function(w){return w.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var s=m.useCallback(function(g,w){if("touches"in g&&g.touches.length===2)return!a.current.allowPinchZoom;var y=yu(g),h=r.current,b="deltaX"in g?g.deltaX:h[0]-y[0],S="deltaY"in g?g.deltaY:h[1]-y[1],C,T=g.target,_=Math.abs(b)>Math.abs(S)?"h":"v";if("touches"in g&&_==="h"&&T.type==="range")return!1;var $=Ob(_,T);if(!$)return!0;if($?C=_:(C=_==="v"?"h":"v",$=Ob(_,T)),!$)return!1;if(!n.current&&"changedTouches"in g&&(b||S)&&(n.current=C),!C)return!0;var I=n.current||C;return T9(I,w,g,I==="h"?b:S,!0)},[]),l=m.useCallback(function(g){var w=g;if(!(!fi.length||fi[fi.length-1]!==i)){var y="deltaY"in w?Db(w):yu(w),h=t.current.filter(function(C){return C.name===w.type&&(C.target===w.target||w.target===C.shadowParent)&&$9(C.delta,y)})[0];if(h&&h.should){w.cancelable&&w.preventDefault();return}if(!h){var b=(a.current.shards||[]).map(Rb).filter(Boolean).filter(function(C){return C.contains(w.target)}),S=b.length>0?s(w,b[0]):!a.current.noIsolation;S&&w.cancelable&&w.preventDefault()}}},[]),u=m.useCallback(function(g,w,y,h){var b={name:g,delta:w,target:y,should:h,shadowParent:O9(y)};t.current.push(b),setTimeout(function(){t.current=t.current.filter(function(S){return S!==b})},1)},[]),c=m.useCallback(function(g){r.current=yu(g),n.current=void 0},[]),d=m.useCallback(function(g){u(g.type,Db(g),g.target,s(g,e.lockRef.current))},[]),f=m.useCallback(function(g){u(g.type,yu(g),g.target,s(g,e.lockRef.current))},[]);m.useEffect(function(){return fi.push(i),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",l,di),document.addEventListener("touchmove",l,di),document.addEventListener("touchstart",c,di),function(){fi=fi.filter(function(g){return g!==i}),document.removeEventListener("wheel",l,di),document.removeEventListener("touchmove",l,di),document.removeEventListener("touchstart",c,di)}},[]);var p=e.removeScrollBar,v=e.inert;return m.createElement(m.Fragment,null,v?m.createElement(i,{styles:A9(o)}):null,p?m.createElement(w9,{gapMode:e.gapMode}):null)}function O9(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const D9=MB(X_,I9);var t2=m.forwardRef(function(e,t){return m.createElement(Ud,Nr({},e,{ref:t,sideCar:D9}))});t2.classNames=Ud.classNames;const R9=t2;function F9(e){const{autoFocus:t,trapFocus:r,dialogRef:n,initialFocusRef:o,blockScrollOnMount:i,allowPinchZoom:a,finalFocusRef:s,returnFocusOnClose:l,preserveScrollBarGap:u,lockFocusAcrossFrames:c,isOpen:d}=Jo(),[f,p]=lC();m.useEffect(()=>{!f&&p&&setTimeout(p)},[f,p]);const v=Y_(n,d);return x.jsx(k_,{autoFocus:t,isDisabled:!r,initialFocusRef:o,finalFocusRef:s,restoreFocus:l,contentRef:n,lockFocusAcrossFrames:c,children:x.jsx(R9,{removeScrollBar:!u,allowPinchZoom:a,enabled:v===1&&i,forwardProps:!0,children:e.children})})}var Cl=te((e,t)=>{const{className:r,children:n,containerProps:o,motionProps:i,...a}=e,{getDialogProps:s,getDialogContainerProps:l}=Jo(),u=s(a,t),c=l(o),d=ie("chakra-modal__content",r),f=Ca(),p={display:"flex",flexDirection:"column",position:"relative",width:"100%",outline:0,...f.dialog},v={display:"flex",width:"100vw",height:"$100vh",position:"fixed",left:0,top:0,...f.dialogContainer},{motionPreset:g}=Jo();return x.jsx(F9,{children:x.jsx(H.div,{...c,className:"chakra-modal__content-container",tabIndex:-1,__css:v,children:x.jsx(K_,{preset:g,motionProps:i,className:d,...u,__css:p,children:n})})})});Cl.displayName="ModalContent";function j9(e){const{leastDestructiveRef:t,...r}=e;return x.jsx(kl,{...r,initialFocusRef:t})}var N9=te((e,t)=>x.jsx(Cl,{ref:t,role:"alertdialog",...e})),Hd=te((e,t)=>{const{className:r,...n}=e,o=ie("chakra-modal__footer",r),a={display:"flex",alignItems:"center",justifyContent:"flex-end",...Ca().footer};return x.jsx(H.footer,{ref:t,...n,__css:a,className:o})});Hd.displayName="ModalFooter";var _l=te((e,t)=>{const{className:r,...n}=e,{headerId:o,setHeaderMounted:i}=Jo();m.useEffect(()=>(i(!0),()=>i(!1)),[i]);const a=ie("chakra-modal__header",r),l={flex:0,...Ca().header};return x.jsx(H.header,{ref:t,className:a,id:o,...n,__css:l})});_l.displayName="ModalHeader";var z9=H(co.div),El=te((e,t)=>{const{className:r,transition:n,motionProps:o,...i}=e,a=ie("chakra-modal__overlay",r),l={pos:"fixed",left:"0",top:"0",w:"100vw",h:"100vh",...Ca().overlay},{motionPreset:u}=Jo(),d=o||(u==="none"?{}:AC);return x.jsx(z9,{...d,__css:l,ref:t,className:a,...i})});El.displayName="ModalOverlay";var Pl=te((e,t)=>{const{className:r,...n}=e,{bodyId:o,setBodyMounted:i}=Jo();m.useEffect(()=>(i(!0),()=>i(!1)),[i]);const a=ie("chakra-modal__body",r),s=Ca();return x.jsx(H.div,{ref:t,className:a,id:o,...n,__css:s.body})});Pl.displayName="ModalBody";var Tl=te((e,t)=>{const{onClick:r,className:n,...o}=e,{onClose:i}=Jo(),a=ie("chakra-modal__close-btn",n),s=Ca();return x.jsx(Yv,{ref:t,__css:s.closeButton,className:a,onClick:Ce(r,l=>{l.stopPropagation(),i()}),...o})});Tl.displayName="ModalCloseButton";var L9={exit:{scale:.85,opacity:0,transition:{opacity:{duration:.15,easings:"easeInOut"},scale:{duration:.2,easings:"easeInOut"}}},enter:{scale:1,opacity:1,transition:{opacity:{easings:"easeOut",duration:.2},scale:{duration:.2,ease:[.175,.885,.4,1.1]}}}},nm=e=>{var t;return((t=e.current)==null?void 0:t.ownerDocument)||document},Ju=e=>{var t,r;return((r=(t=e.current)==null?void 0:t.ownerDocument)==null?void 0:r.defaultView)||window};function B9(e={}){const{openDelay:t=0,closeDelay:r=0,closeOnClick:n=!0,closeOnMouseDown:o,closeOnScroll:i,closeOnPointerDown:a=o,closeOnEsc:s=!0,onOpen:l,onClose:u,placement:c,id:d,isOpen:f,defaultIsOpen:p,arrowSize:v=10,arrowShadowColor:g,arrowPadding:w,modifiers:y,isDisabled:h,gutter:b,offset:S,direction:C,...T}=e,{isOpen:_,onOpen:$,onClose:I}=N_({isOpen:f,defaultIsOpen:p,onOpen:l,onClose:u}),{referenceRef:O,getPopperProps:N,getArrowInnerProps:Y,getArrowProps:G}=j_({enabled:_,placement:c,arrowPadding:w,modifiers:y,gutter:b,offset:S,direction:C}),K=m.useId(),R=`tooltip-${d??K}`,A=m.useRef(null),D=m.useRef(),j=m.useCallback(()=>{D.current&&(clearTimeout(D.current),D.current=void 0)},[]),z=m.useRef(),L=m.useCallback(()=>{z.current&&(clearTimeout(z.current),z.current=void 0)},[]),q=m.useCallback(()=>{L(),I()},[I,L]),B=V9(A,q),U=m.useCallback(()=>{if(!h&&!D.current){_&&B();const fe=Ju(A);D.current=fe.setTimeout($,t)}},[B,h,_,$,t]),ee=m.useCallback(()=>{j();const fe=Ju(A);z.current=fe.setTimeout(q,r)},[r,q,j]),re=m.useCallback(()=>{_&&n&&ee()},[n,ee,_]),ye=m.useCallback(()=>{_&&a&&ee()},[a,ee,_]),be=m.useCallback(fe=>{_&&fe.key==="Escape"&&ee()},[_,ee]);ks(()=>nm(A),"keydown",s?be:void 0),ks(()=>{if(!i)return null;const fe=A.current;if(!fe)return null;const Qe=y_(fe);return Qe.localName==="body"?Ju(A):Qe},"scroll",()=>{_&&i&&q()},{passive:!0,capture:!0}),m.useEffect(()=>{h&&(j(),_&&I())},[h,_,I,j]),m.useEffect(()=>()=>{j(),L()},[j,L]),ks(()=>A.current,"pointerleave",ee);const qe=m.useCallback((fe={},Qe=null)=>({...fe,ref:kt(A,Qe,O),onPointerEnter:Ce(fe.onPointerEnter,ne=>{ne.pointerType!=="touch"&&U()}),onClick:Ce(fe.onClick,re),onPointerDown:Ce(fe.onPointerDown,ye),onFocus:Ce(fe.onFocus,U),onBlur:Ce(fe.onBlur,ee),"aria-describedby":_?R:void 0}),[U,ee,ye,_,R,re,O]),rt=m.useCallback((fe={},Qe=null)=>N({...fe,style:{...fe.style,[lt.arrowSize.var]:v?`${v}px`:void 0,[lt.arrowShadowColor.var]:g}},Qe),[N,v,g]),Xe=m.useCallback((fe={},Qe=null)=>{const po={...fe.style,position:"relative",transformOrigin:lt.transformOrigin.varRef};return{ref:Qe,...T,...fe,id:R,role:"tooltip",style:po}},[T,R]);return{isOpen:_,show:U,hide:ee,getTriggerProps:qe,getTooltipProps:Xe,getTooltipPositionerProps:rt,getArrowProps:G,getArrowInnerProps:Y}}var bp="chakra-ui:close-tooltip";function V9(e,t){return m.useEffect(()=>{const r=nm(e);return r.addEventListener(bp,t),()=>r.removeEventListener(bp,t)},[t,e]),()=>{const r=nm(e),n=Ju(e);r.dispatchEvent(new n.CustomEvent(bp))}}function W9(e,t=[]){const r=Object.assign({},e);for(const n of t)n in r&&delete r[n];return r}function U9(e,t){const r={};for(const n of t)n in e&&(r[n]=e[n]);return r}var H9=H(co.div),dn=te((e,t)=>{var r,n;const o=Cn("Tooltip",e),i=Pt(e),a=pv(),{children:s,label:l,shouldWrapChildren:u,"aria-label":c,hasArrow:d,bg:f,portalProps:p,background:v,backgroundColor:g,bgColor:w,motionProps:y,...h}=i,b=(n=(r=v??g)!=null?r:f)!=null?n:w;if(b){o.bg=b;const N=IM(a,"colors",b);o[lt.arrowBg.var]=N}const S=B9({...h,direction:a.direction}),C=typeof s=="string"||u;let T;if(C)T=x.jsx(H.span,{display:"inline-block",tabIndex:0,...S.getTriggerProps(),children:s});else{const N=m.Children.only(s);T=m.cloneElement(N,S.getTriggerProps(N.props,N.ref))}const _=!!c,$=S.getTooltipProps({},t),I=_?W9($,["role","id"]):$,O=U9($,["role","id"]);return l?x.jsxs(x.Fragment,{children:[T,x.jsx(wa,{children:S.isOpen&&x.jsx(so,{...p,children:x.jsx(H.div,{...S.getTooltipPositionerProps(),__css:{zIndex:o.zIndex,pointerEvents:"none"},children:x.jsxs(H9,{variants:L9,initial:"exit",animate:"enter",exit:"exit",...y,...I,__css:o,children:[l,_&&x.jsx(H.span,{srOnly:!0,...O,children:c}),d&&x.jsx(H.div,{"data-popper-arrow":!0,className:"chakra-tooltip__arrow-wrapper",children:x.jsx(H.div,{"data-popper-arrow-inner":!0,className:"chakra-tooltip__arrow",__css:{bg:o.bg}})})]})})})})]}):x.jsx(x.Fragment,{children:s})});dn.displayName="Tooltip";let bu;const G9=new Uint8Array(16);function K9(){if(!bu&&(bu=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!bu))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return bu(G9)}const it=[];for(let e=0;e<256;++e)it.push((e+256).toString(16).slice(1));function Y9(e,t=0){return it[e[t+0]]+it[e[t+1]]+it[e[t+2]]+it[e[t+3]]+"-"+it[e[t+4]]+it[e[t+5]]+"-"+it[e[t+6]]+it[e[t+7]]+"-"+it[e[t+8]]+it[e[t+9]]+"-"+it[e[t+10]]+it[e[t+11]]+it[e[t+12]]+it[e[t+13]]+it[e[t+14]]+it[e[t+15]]}const q9=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Fb={randomUUID:q9};function $l(e,t,r){if(Fb.randomUUID&&!t&&!e)return Fb.randomUUID();e=e||{};const n=e.random||(e.rng||K9)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let o=0;o<16;++o)t[r+o]=n[o];return t}return Y9(n)}async function _a(e){try{const t=await fetch(`/workspace/get_db?table=${e}`);return t.ok?await t.json():void 0}catch(t){console.error("Error fetching workspace:",t);return}}async function St(e,t){try{return await(await fetch("/workspace/save_db",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({table:e,json:t})})).text()}catch(r){console.error("Error saving workspace:",r)}}async function X9(e,t){try{return await(await fetch("/workspace/update_file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file_path:e,json_str:t})})).text()}catch(r){alert("Error saving workflow .json file: "+r),console.error("Error saving workspace:",r)}}async function r2(e,t=!0){try{return await(await fetch("/workspace/delete_file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file_path:e,deleteEmptyFolder:t})})).text()}catch(r){console.error("Error deleting file:",r)}}async function h7(e){try{return await(await fetch("/workspace/list_backup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:e})})).text()}catch(t){console.error("Error saving workspace:",t)}}async function Q9(e){try{return await(await fetch("/workspace/get_system_dir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({absolute_dir:e})})).json()}catch(t){console.error("Error getting workflows dir:",t)}}async function m7(){try{return await(await fetch("/workspace/open_workflow_file_browser",{method:"POST",headers:{"Content-Type":"application/json"}})).json()}catch(e){console.error("Error open workflows folder:",e)}}const v7="CWM_WORKFLOWS_SORT_TYPE";var sr=(e=>(e.RECENTLY_MODIFIED="newest",e.OLDEST_MODIFIED="oldest",e.AZ="name A-Z",e.ZA="name Z-A",e))(sr||{});const J9="comfyspace_tracking",Z9="http://localhost:8188/";function yg(e){if(e.name==null)return;const t=bg(e);t!=null&&r2(t)}function bg(e){let t=eW(e.name)+".json",r=e.parentFolderID;for(;r!=null;){const n=Yr==null?void 0:Yr.get(r);if(n==null)break;t=`${n.name}/${t}`,r=n.parentFolderID??void 0}return t??null}function n2(e){const t=bg(e);let r=Se==null?void 0:Se.getSetting("myWorkflowsDir");return r==null?(console.error("myWorkflowsDir is not set"),null):(r.endsWith("/")||(r=r+"/"),r+t)}function eW(e){return e=e.replace(/[\\/:*?"<>|]/g,"_"),e.trim()}function o2(e,t=!1){const r=new Date(e),n=String(r.getDate()).padStart(2,"0"),o=String(r.getMonth()+1).padStart(2,"0"),i=r.getFullYear(),a=String(r.getHours()).padStart(2,"0"),s=String(r.getMinutes()).padStart(2,"0"),l=String(r.getSeconds()).padStart(2,"0");let u=`${o}-${n}-${i} ${a}:${s}`;return t?u+`:${l}`:u}function tW(e=[],t=sr.RECENTLY_MODIFIED){const r=[...e];if(r.length)switch(t){case sr.AZ:r.sort((n,o)=>n.name.localeCompare(o.name));break;case sr.ZA:r.sort((n,o)=>o.name.localeCompare(n.name));break;case sr.RECENTLY_MODIFIED:r.sort((n,o)=>o.updateTime-n.updateTime);break;case sr.OLDEST_MODIFIED:r.sort((n,o)=>n.updateTime-o.updateTime);break}return r}function om(e=!0){Gd().forEach(t=>{const r=n2(t);t.filePath!=r&&(t.filePath!=null&&r2(t.filePath,e),ol(t))})}const rW=(e,t=sr.RECENTLY_MODIFIED)=>{const r=[...e];switch(t){case sr.AZ:r.sort((n,o)=>n.name.localeCompare(o.name));break;case sr.ZA:r.sort((n,o)=>o.name.localeCompare(n.name));break;case sr.RECENTLY_MODIFIED:r.sort((n,o)=>o.updateTime-n.updateTime);break;case sr.OLDEST_MODIFIED:r.sort((n,o)=>n.updateTime-o.updateTime);break}return r};function i2(e){var n;let t=e??"Untitled Flow";const r=(n=Gd())==null?void 0:n.map(o=>o.name);if(r.includes(t)){let o=2,i=!0;for(;i;)r.includes(`${t} ${o}`)?o++:(t=`${t} ${o}`,i=!1)}return t}function g7(e){return new Promise((t,r)=>{const n=new FileReader;n.onload=o=>{const i=new Uint8Array(o.target.result),a=new DataView(i.buffer);a.getUint32(0)!==2303741511&&(console.error("Not a valid PNG file"),r());let s=8;const l={};for(;sString.fromCharCode(g)).join("");l[f]=v}s+=12+u}t(l)},n.readAsArrayBuffer(e)})}const nW=e=>{var r;const t=(r=Se==null?void 0:Se.getSetting("shortcuts"))==null?void 0:r.save;return t?oW(e,t):!1},oW=(e,t)=>{const r=t.split("+"),n={Control:e.ctrlKey,Shift:e.shiftKey,Alt:e.altKey,Command:e.metaKey,[e.key.toUpperCase()]:!0};return r.every(o=>n[o])};function iW(e){const t=["png","jpg","jpeg","gif","bmp","webp"],r=e.split(".").pop();return r!=null&&t.includes(r)}function aW(e){return`/workspace/view_media?filename=${e}`}const a2="backup",va="workspace";let Bn=null;function s2(){return new Promise((e,t)=>{const r=indexedDB.open("WorkspaceDB",3);r.onupgradeneeded=n=>{const o=n.target.result;o.objectStoreNames.contains(va)||o.createObjectStore(va,{keyPath:"id"})},r.onsuccess=n=>{e(n.target.result)},r.onerror=n=>{t(n.target.error)}})}async function sW(e){try{return Bn==null&&(Bn=await s2()),new Promise((t,r)=>{if(Bn==null)return r("indexDB is null");const i=Bn.transaction([va],"readwrite").objectStore(va).put({id:a2,value:e});i.onsuccess=()=>t(),i.onerror=()=>r(i.error)})}catch(t){console.error("Error while opening database:",t)}}async function Gt(){try{const e=await fW();await sW(e)}catch(e){console.error("Error writing to IndexedDB:",e)}}async function lW(){try{return Bn==null&&(Bn=await s2()),new Promise((e,t)=>{if(Bn==null)return t("indexDB is null");const o=Bn.transaction([va],"readonly").objectStore(va).get(a2);o.onsuccess=()=>{o.result?e(o.result.value):e(void 0)},o.onerror=()=>t(o.error)})}catch(e){console.error("Error while reading from database:",e)}}async function Ea(){try{return await lW()}catch(e){console.error("Error retrieving data from IndexedDB:",e)}}const To=class To{constructor(){}static async load(){return new To}async listByWorkflowID(t){const r=await this.getRecords();return Object.values(r).filter(n=>n.workflowID===t).sort((n,o)=>o.createTime-n.createTime)}async getRecords(){let t=await _a(To.TABLE_NAME),r=t!=null?JSON.parse(t):null;if(r==null){const n=await Ea()??"{}";r=JSON.parse(n)[To.TABLE_NAME]}return r??{}}async get(t){return(await this.getRecords())[t]}async getLastestByWorkflowID(t){const r=await this.getRecords();return Object.values(r).filter(o=>o.workflowID===t).sort((o,i)=>i.createTime-o.createTime)[0]}async create(t){const r=await this.getLastestByWorkflowID(t.workflowID);if(r!=null&&r.json===t.json)return null;const n={id:$l(),json:t.json,workflowID:t.workflowID,createTime:Date.now()},o=await this.getRecords();return o[n.id]=n,St(To.TABLE_NAME,JSON.stringify(o)),Gt(),n}};Pn(To,"TABLE_NAME","changelogs");let Hc=To;const ji=class ji{constructor(){Pn(this,"records");this.records={}}static async load(){const t=new ji;let r=await _a(ji.TABLE_NAME),n=r!=null?JSON.parse(r):null;if(n==null){const o=await Ea()??"{}";n=JSON.parse(o)[ji.TABLE_NAME]}return n!=null&&(t.records=n),t}listAll(){return Object.values(this.records)}getRecords(){return this.records}get(t){return this.records[t]}create(t){const r=this.generateUniqueName(t.name),n={id:$l(),name:r,parentFolderID:t.parentFolderID??null,updateTime:Date.now(),createTime:Date.now(),type:"folder"};return this.records[n.id]=n,St("folders",JSON.stringify(this.records)),Gt(),n}update(t){const r=this.records[t.id];if(r==null)return;const n={...r,...t};t.name!=null&&(n.updateTime=Date.now()),this.records[t.id]=n,St("folders",JSON.stringify(this.records)),Gt(),om()}delete(t){delete this.records[t],Gd().filter(n=>n.parentFolderID==t).forEach(n=>no(n.id,{parentFolderID:void 0})),St("folders",JSON.stringify(this.records)),Gt(),om()}generateUniqueName(t){var o;let r=t??"New folder";const n=(o=this.listAll())==null?void 0:o.map(i=>i.name);if(n.includes(r)){let i=2,a=!0;for(;a;)n.includes(`${r} ${i}`)?i++:(r=`${r} ${i}`,a=!1)}return r}};Pn(ji,"TABLE_NAME","folders");let Gc=ji;class uW{constructor(t){Pn(this,"tableName");this.tableName=t}async listAll(){const t=await this.getRecords();return Object.values(t)}async getRecords(){let t=await _a(this.tableName),r;try{r=t!=null?JSON.parse(t):null}catch{}if(r==null){const n=await Ea()??"{}";r=JSON.parse(n)[this.tableName]}return r??{}}async get(t){return(await this.getRecords())[t]}async delete(t){const r=await this.getRecords();delete r[t],St(this.tableName,JSON.stringify(r)),Gt()}}class xg extends uW{constructor(){super("media")}async listByWorkflowID(t){const r=await this.getRecords();return Object.values(r).filter(n=>n.workflowID===t).sort((n,o)=>o.createTime-n.createTime)}async getLastestByWorkflowID(t){const r=await this.getRecords();return Object.values(r).filter(o=>o.workflowID===t).sort((o,i)=>i.createTime-o.createTime)[0]}async create(t){var s;const r=t.localPath.split(".").pop();if(r==null)return null;const n={id:$l(),localPath:t.localPath,workflowID:t.workflowID,createTime:Date.now(),format:r},o=((s=an(t.workflowID))==null?void 0:s.mediaIDs)??[],i=new Set(o).add(n.id);no(t.workflowID,{mediaIDs:Array.from(i),coverMediaPath:n.localPath});const a=await this.getRecords();return a[n.id]=n,St("media",JSON.stringify(a)),Gt(),n}}Pn(xg,"TABLE_NAME","media");async function cW(){const e=await _a("tags");let t;if(e==null){const r=await Ea()??"{}";t=JSON.parse(r).tags||{}}else t=JSON.parse(e??"{}")??{};return{tags:t,listAll(){return Object.values(t).sort((r,n)=>n.updateTime-r.updateTime)},upsert(r){return t[r]==null&&(t[r]={name:r,workflowIDs:[],updateTime:Date.now()}),t[r].updateTime=Date.now(),St("tags",JSON.stringify(t)),t[r]},delete(r){delete t[r],St("tags",JSON.stringify(t))}}}const $o=class $o{constructor(){Pn(this,"records");this.records={topBarStyle:{top:0,left:0},myWorkflowsDir:"",shortcuts:{save:"Shift+S"},autoSave:!0}}listSettings(){return this.records}getSetting(t){return this.records[t]}upsert(t){this.records={...this.records,...t},St($o.TABLE_NAME,JSON.stringify(this.records)),Gt()}static async load(){const t=new $o,r=await _a($o.TABLE_NAME);let n=r!=null?JSON.parse(r):null;if(n==null){const o=await Ea()??"{}";n=JSON.parse(o)[$o.TABLE_NAME]||{}}if(!n.myWorkflowsDir){const o=await Q9();n.myWorkflowsDir=`${o.dir_path}/my_workflows`}return t.records=n,t}};Pn($o,"TABLE_NAME","userSettings");let Kc=$o;function y7(e){return e.type==="folder"}let oe,Zu=null,Se=null,Yr=null,qr=null,Bt=null;async function dW(){const e=async()=>{const a=await _a("workflows");if(a==null){const s=await Ea()??"{}";oe=JSON.parse(s).workflows||{}}else oe=JSON.parse(a)},t=async()=>{Zu=await cW()},r=async()=>{Se=await Kc.load()},n=async()=>{Yr=await Gc.load()},o=async()=>{qr=await Hc.load()},i=async()=>{Bt=new xg};await Promise.all([e(),t(),r(),n(),o(),i()])}function b7(e,t){var i;if(oe==null)return[];const r=Object.values(oe).filter(a=>a.parentFolderID==e),n=((i=Yr==null?void 0:Yr.listAll())==null?void 0:i.filter(a=>a.parentFolderID==e))??[],o=[...r,...n];return rW(o,t??sr.RECENTLY_MODIFIED)}function no(e,t){if(oe==null)return;const r=oe[e];if(r==null)return;const n={...r,...t,id:e},o=JSON.stringify(r),i=JSON.stringify(n);if(o===i)return;let a=n;const s=Object.keys(t);if(s.length===1&&["tags","parentFolderID"].includes(s[0])||(a.updateTime=Date.now()),oe[e]=a,Gt(),St("workflows",JSON.stringify(oe)),t.name!=null||t.parentFolderID!=null){yg(r),ol(n);return}t.json!=null&&ol(n)}function ol(e){const t=bg(e);if(t==null)return;if(oe!=null){const o=n2(e);oe[e.id].filePath=o??void 0,Gt(),St("workflows",JSON.stringify(oe))}const r=e.json,n=JSON.parse(r);n.extra[J9]={id:e.id,name:e.name},X9(t,JSON.stringify(n))}function xp({json:e,name:t,parentFolderID:r,tags:n}){if(oe==null)throw new Error("workspace is not loaded");const o=i2(t),i=$l(),a=Date.now(),s={id:i,name:o,json:e,parentFolderID:r,updateTime:a,createTime:a,tags:n??[]};return oe[i]=s,St("workflows",JSON.stringify(oe)),Gt(),ol(oe[i]),oe[i]}async function x7(e){e.forEach(r=>{if(oe==null)return;const n=i2(r.name),o=$l(),i=Date.now();oe[o]={id:o,name:n,json:r.json,updateTime:i,createTime:i,tags:[]},ol(oe[o])});const t=JSON.stringify(oe);return Gt(),await St("workflows",t)}function Gd(e){if(oe==null)throw new Error("workspace is not loaded");const t=Object.values(oe);return tW(t,e)}function an(e){if(oe==null){console.error("workspace is not loaded");return}return oe[e]}function w7(e){if(oe==null)return;const t=oe[e];t&&yg({...t}),delete oe[e],Gt(),St("workflows",JSON.stringify(oe))}function S7(e){e.forEach(r=>{if(oe==null)return;const n=oe[r];n&&yg({...n}),oe&&delete oe[r]});const t=JSON.stringify(oe);Gt(),St("workflows",t)}async function fW(){const e=await(qr==null?void 0:qr.getRecords()),t=await(Bt==null?void 0:Bt.getRecords());return JSON.stringify({[Kc.TABLE_NAME]:Se==null?void 0:Se.records,tags:Zu==null?void 0:Zu.tags,workflows:oe,[Gc.TABLE_NAME]:Yr==null?void 0:Yr.getRecords(),[Hc.TABLE_NAME]:e,[xg.TABLE_NAME]:t})}const jb={last_node_id:9,last_link_id:9,nodes:[{id:7,type:"CLIPTextEncode",pos:[413,389],size:{0:425.27801513671875,1:180.6060791015625},flags:{},order:3,mode:0,inputs:[{name:"clip",type:"CLIP",link:5}],outputs:[{name:"CONDITIONING",type:"CONDITIONING",links:[6],slot_index:0}],properties:{},widgets_values:["text, watermark"]},{id:6,type:"CLIPTextEncode",pos:[415,186],size:{0:422.84503173828125,1:164.31304931640625},flags:{},order:2,mode:0,inputs:[{name:"clip",type:"CLIP",link:3}],outputs:[{name:"CONDITIONING",type:"CONDITIONING",links:[4],slot_index:0}],properties:{},widgets_values:["beautiful scenery nature glass bottle landscape, , purple galaxy bottle,"]},{id:5,type:"EmptyLatentImage",pos:[473,609],size:{0:315,1:106},flags:{},order:1,mode:0,outputs:[{name:"LATENT",type:"LATENT",links:[2],slot_index:0}],properties:{},widgets_values:[512,512,1]},{id:3,type:"KSampler",pos:[863,186],size:{0:315,1:262},flags:{},order:4,mode:0,inputs:[{name:"model",type:"MODEL",link:1},{name:"positive",type:"CONDITIONING",link:4},{name:"negative",type:"CONDITIONING",link:6},{name:"latent_image",type:"LATENT",link:2}],outputs:[{name:"LATENT",type:"LATENT",links:[7],slot_index:0}],properties:{},widgets_values:[0x8e7ff42ed37e,!0,20,8,"euler","normal",1]},{id:8,type:"VAEDecode",pos:[1209,188],size:{0:210,1:46},flags:{},order:5,mode:0,inputs:[{name:"samples",type:"LATENT",link:7},{name:"vae",type:"VAE",link:8}],outputs:[{name:"IMAGE",type:"IMAGE",links:[9],slot_index:0}],properties:{}},{id:9,type:"SaveImage",pos:[1451,189],size:{0:210,1:26},flags:{},order:6,mode:0,inputs:[{name:"images",type:"IMAGE",link:9}],properties:{}},{id:4,type:"CheckpointLoaderSimple",pos:[26,474],size:{0:315,1:98},flags:{},order:0,mode:0,outputs:[{name:"MODEL",type:"MODEL",links:[1],slot_index:0},{name:"CLIP",type:"CLIP",links:[3,5],slot_index:1},{name:"VAE",type:"VAE",links:[8],slot_index:2}],properties:{},widgets_values:["v1-5-pruned-emaonly.ckpt"]}],links:[[1,4,0,3,0,"MODEL"],[2,5,0,3,3,"LATENT"],[3,4,1,6,0,"CLIP"],[4,6,0,3,1,"CONDITIONING"],[5,4,1,7,0,"CLIP"],[6,7,0,3,2,"CONDITIONING"],[7,3,0,8,0,"LATENT"],[8,4,2,8,1,"VAE"],[9,8,0,9,0,"IMAGE"]],groups:[],config:{},extra:{},version:.4},Pa=m.createContext({curFlowID:null,loadWorkflowID:()=>{},saveCurWorkflow:()=>{},discardUnsavedChanges:()=>{},isDirty:!1,loadNewWorkflow:()=>{},loadFilePath:()=>{},setRoute:()=>{}}),k7=m.createContext({refreshFolderStamp:0,setRefreshFolderStamp:()=>{}});var pW={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"},hW=Object.defineProperty,mW=Object.defineProperties,vW=Object.getOwnPropertyDescriptors,Yc=Object.getOwnPropertySymbols,l2=Object.prototype.hasOwnProperty,u2=Object.prototype.propertyIsEnumerable,Nb=(e,t,r)=>t in e?hW(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,zb=(e,t)=>{for(var r in t||(t={}))l2.call(t,r)&&Nb(e,r,t[r]);if(Yc)for(var r of Yc(t))u2.call(t,r)&&Nb(e,r,t[r]);return e},gW=(e,t)=>mW(e,vW(t)),yW=(e,t)=>{var r={};for(var n in e)l2.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&Yc)for(var n of Yc(e))t.indexOf(n)<0&&u2.call(e,n)&&(r[n]=e[n]);return r},Nt=(e,t,r)=>{const n=m.forwardRef((o,i)=>{var a=o,{color:s="currentColor",size:l=24,stroke:u=2,children:c}=a,d=yW(a,["color","size","stroke","children"]);return m.createElement("svg",zb(gW(zb({ref:i},pW),{width:l,height:l,stroke:s,strokeWidth:u,className:`tabler-icon tabler-icon-${e}`}),d),[...r.map(([f,p])=>m.createElement(f,p)),...c||[]])});return n.propTypes={color:xo.string,size:xo.oneOfType([xo.string,xo.number]),stroke:xo.oneOfType([xo.string,xo.number])},n.displayName=`${t}`,n},bW=Nt("arrow-back-up-double","IconArrowBackUpDouble",[["path",{d:"M13 14l-4 -4l4 -4",key:"svg-0"}],["path",{d:"M8 14l-4 -4l4 -4",key:"svg-1"}],["path",{d:"M9 10h7a4 4 0 1 1 0 8h-1",key:"svg-2"}]]),xW=Nt("chevron-down","IconChevronDown",[["path",{d:"M6 9l6 6l6 -6",key:"svg-0"}]]),im=Nt("device-floppy","IconDeviceFloppy",[["path",{d:"M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2",key:"svg-0"}],["path",{d:"M12 14m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0",key:"svg-1"}],["path",{d:"M14 4l0 4l-6 0l0 -4",key:"svg-2"}]]),wW=Nt("download","IconDownload",[["path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2",key:"svg-0"}],["path",{d:"M7 11l5 5l5 -5",key:"svg-1"}],["path",{d:"M12 4l0 12",key:"svg-2"}]]),SW=Nt("folder","IconFolder",[["path",{d:"M5 4h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2",key:"svg-0"}]]),kW=Nt("grip-vertical","IconGripVertical",[["path",{d:"M9 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-0"}],["path",{d:"M9 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-1"}],["path",{d:"M9 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-2"}],["path",{d:"M15 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-3"}],["path",{d:"M15 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-4"}],["path",{d:"M15 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0",key:"svg-5"}]]),CW=Nt("history","IconHistory",[["path",{d:"M12 8l0 4l2 2",key:"svg-0"}],["path",{d:"M3.05 11a9 9 0 1 1 .5 4m-.5 5v-5h5",key:"svg-1"}]]),_W=Nt("photo","IconPhoto",[["path",{d:"M15 8h.01",key:"svg-0"}],["path",{d:"M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12z",key:"svg-1"}],["path",{d:"M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5",key:"svg-2"}],["path",{d:"M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3",key:"svg-3"}]]),EW=Nt("pin-filled","IconPinFilled",[["path",{d:"M15.113 3.21l.094 .083l5.5 5.5a1 1 0 0 1 -1.175 1.59l-3.172 3.171l-1.424 3.797a1 1 0 0 1 -.158 .277l-.07 .08l-1.5 1.5a1 1 0 0 1 -1.32 .082l-.095 -.083l-2.793 -2.792l-3.793 3.792a1 1 0 0 1 -1.497 -1.32l.083 -.094l3.792 -3.793l-2.792 -2.793a1 1 0 0 1 -.083 -1.32l.083 -.094l1.5 -1.5a1 1 0 0 1 .258 -.187l.098 -.042l3.796 -1.425l3.171 -3.17a1 1 0 0 1 1.497 -1.26z",fill:"currentColor",key:"svg-0",strokeWidth:"0"}]]),PW=Nt("pin","IconPin",[["path",{d:"M15 4.5l-4 4l-4 1.5l-1.5 1.5l7 7l1.5 -1.5l1.5 -4l4 -4",key:"svg-0"}],["path",{d:"M9 15l-4.5 4.5",key:"svg-1"}],["path",{d:"M14.5 4l5.5 5.5",key:"svg-2"}]]),TW=Nt("plus","IconPlus",[["path",{d:"M12 5l0 14",key:"svg-0"}],["path",{d:"M5 12l14 0",key:"svg-1"}]]),$W=Nt("trash","IconTrash",[["path",{d:"M4 7l16 0",key:"svg-0"}],["path",{d:"M10 11l0 6",key:"svg-1"}],["path",{d:"M14 11l0 6",key:"svg-2"}],["path",{d:"M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12",key:"svg-3"}],["path",{d:"M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3",key:"svg-4"}]]),AW=Nt("triangle-inverted-filled","IconTriangleInvertedFilled",[["path",{d:"M20.118 3h-16.225a2.914 2.914 0 0 0 -2.503 4.371l8.116 13.549a2.917 2.917 0 0 0 4.987 .005l8.11 -13.539a2.914 2.914 0 0 0 -2.486 -4.386z",fill:"currentColor",key:"svg-0",strokeWidth:"0"}]]),c2=Nt("x","IconX",[["path",{d:"M18 6l-12 12",key:"svg-0"}],["path",{d:"M6 6l12 12",key:"svg-1"}]]);const d2=m.createContext(void 0),f2=()=>{const e=m.useContext(d2);if(!e)throw new Error("useDialog must be used within a DialogProvider");return e},MW=({children:e})=>{const[t,r]=m.useState(!1),[n,o]=m.useState(""),[i,a]=m.useState([]),s=Xr.useRef(null),l=m.useCallback((c,d)=>{o(c),a(d),r(!0)},[]),u=m.useCallback(()=>{r(!1)},[]);return x.jsxs(d2.Provider,{value:{showDialog:l},children:[e,t&&x.jsx(j9,{isOpen:t,leastDestructiveRef:s,onClose:u,size:"lg",children:x.jsx(kS,{children:x.jsx(El,{children:x.jsxs(N9,{className:"workspace_manager",children:[x.jsx(_l,{fontSize:"lg",fontWeight:"bold"}),x.jsx(Tl,{}),x.jsx(Pl,{children:n}),x.jsx(Hd,{children:i.map((c,d)=>x.jsx(Tr,{colorScheme:c.colorScheme??"gray",onClick:()=>{c.onClick(),u()},ml:3,children:c.label},d))})]})})})})]})},xu=200;function IW({onclose:e}){const{curFlowID:t,loadNewWorkflow:r,loadFilePath:n}=m.useContext(Pa),o=t!=null?an(t):null,[i,a]=m.useState([]),[s,l]=m.useState(!1),[u,c]=m.useState(o==null?void 0:o.coverMediaPath),[d,f]=m.useState([]),{showDialog:p}=f2(),v=async()=>{if(t==null)return;const h=await(Bt==null?void 0:Bt.listByWorkflowID(t));f(h??[])};if(m.useEffect(()=>{v()},[]),t==null)return null;const g=()=>{v()},w=h=>{if(s){i.includes(h.id)?a(i.filter(b=>b!==h.id)):a([...i,h.id]);return}window.open(`/workspace/view_media?filename=${h.localPath}`)},y=d.length>0&&i.length===d.length;return x.jsxs(kl,{isOpen:!0,onClose:e,blockScrollOnMount:!0,children:[x.jsx(El,{}),x.jsxs(Cl,{width:"90%",maxWidth:"90vw",height:"90vh",children:[x.jsxs(_l,{children:[x.jsx(Lr,{gap:2,mb:2,children:x.jsxs(ug,{size:"md",mr:2,children:["Gallery - ",o==null?void 0:o.name]})}),s&&x.jsxs(Lr,{gap:3,children:[x.jsx(Yu,{isChecked:y,onChange:()=>{a(y?[]:d.map(h=>h.id))},children:"All"}),x.jsxs(da,{fontSize:16,children:[i.length," Selected"]}),x.jsx(Jn,{size:"sm",icon:x.jsx(c2,{size:19}),onClick:()=>l(!1),"aria-label":"cancel"})]})]}),x.jsx(Tl,{}),x.jsx(Pl,{overflowY:"auto",children:x.jsx(Lr,{wrap:"wrap",children:d.map(h=>{if(h.localPath==null)return null;const b=iW(h.localPath)?x.jsxs(Qh,{isExternal:!0,onClick:()=>w(h),position:"relative",children:[s&&x.jsx(Yu,{isChecked:i.includes(h.id),position:"absolute",top:2,left:2}),x.jsx(IC,{borderRadius:3,boxSize:xu+"px",objectFit:"cover",src:`/workspace/view_media?filename=${h.localPath}`,alt:"workflow image renamed or moved from output folder"})]}):x.jsxs(Qh,{isExternal:!0,onClick:()=>w(h),children:[s&&x.jsx(Yu,{isChecked:i.includes(h.id)}),x.jsx("video",{width:xu,height:xu,src:`/workspace/view_media?filename=${h.localPath}`,loop:!0,autoPlay:!0,muted:!0,children:x.jsx("track",{kind:"captions"})})]}),S=u!=null&&u===h.localPath;return x.jsxs(Vd,{width:xu,justifyContent:"space-between",mb:2,children:[x.jsx(dn,{label:o2(h.createTime,!0),children:b}),x.jsx(dn,{label:h.localPath,children:x.jsx(da,{color:"GrayText",noOfLines:1,children:h.localPath})}),x.jsxs(Lr,{justifyContent:"space-between",hidden:s,children:[x.jsx(dn,{label:"Set as cover",children:x.jsx(Jn,{size:"sm",variant:"ghost",icon:S?x.jsx(EW,{size:19}):x.jsx(PW,{size:19}),"aria-label":"set as cover",isActive:S,onClick:()=>{no(t,{coverMediaPath:h.localPath}),c(h.localPath)}})}),x.jsx(Tr,{flexGrow:1,onClick:()=>p("How do you want to load this workflow?",[{label:"Load in new workflow",onClick:()=>{n(h.localPath)},colorScheme:"teal"},{label:"Overwrite current workflow",onClick:()=>n(h.localPath,!0),colorScheme:"red"}]),size:"sm",children:"Load"}),x.jsx(dn,{label:"Remove image from gallery",children:x.jsx(Jn,{size:"sm",variant:"ghost",icon:x.jsx($W,{size:19}),"aria-label":"remove image from gallery",colorScheme:"red",onClick:()=>{confirm("Are you sure to remove this image from gallery? (won't delete image on your disk)")&&(Bt==null||Bt.delete(h.id),S&&(no(t,{coverMediaPath:void 0}),c(void 0)),g())}})})]})]})})})})]})]})}const wp={x:0,y:0};function OW({children:e,onDragEnd:t}){const r=m.useRef(wp),n=m.useRef(!1),[o,i]=m.useState(wp),a=c=>{var d,f,p;if([(d=c.target)==null?void 0:d.id,(p=(f=c.target)==null?void 0:f.parentNode)==null?void 0:p.id].includes("dragPanelIcon")){r.current={x:c.clientX,y:c.clientY},n.current=!0,window.addEventListener("mousemove",s),window.addEventListener("mouseup",l);const v=document.getElementsByTagName("body")[0];v.style.userSelect="none"}},s=m.useCallback(c=>{const d={x:c.clientX-r.current.x,y:c.clientY-r.current.y};i(d)},[]),l=m.useCallback(()=>{i(d=>(t(d),wp)),n.current=!1;const c=document.getElementsByTagName("body")[0];c.style.userSelect="auto",window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",l)},[t,s]),u={transform:`translate(${o.x}px, ${o.y}px)`,zIndex:n.current?1e3:1};return x.jsx("div",{style:u,onMouseDown:a,children:e})}function DW({backgroundColor:e}){const t=e===void 0?"rgba(0,0,0,0.5)":e??void 0;return x.jsx("div",{style:{position:"fixed",top:0,bottom:0,left:0,right:0,backgroundColor:t}})}function RW({onClose:e}){const{curFlowID:t,isDirty:r}=m.useContext(Pa),[n,o]=m.useState(null),i=t!=null?an(t):null,[a,s]=m.useState([]);return t==null||i==null?(alert("No current workflow found!"),null):(m.useEffect(()=>{(async()=>{var f;const u=await(qr==null?void 0:qr.listByWorkflowID(t));s(u??[]);const c=u==null?void 0:u.filter(p=>p.json===i.lastSavedJson),d=(f=c==null?void 0:c[0])==null?void 0:f.id;d&&o(d)})()},[]),x.jsxs(BL,{width:400,height:"100vh",pl:4,pr:5,pt:4,gap:0,position:"fixed",top:0,left:0,zIndex:1e3,children:[x.jsx(LL,{pb:1,mb:0,children:x.jsxs(P_,{justifyContent:"space-between",alignItems:"center",children:[x.jsx(ug,{size:"md",children:"Version History"}),x.jsx(Jn,{size:"sm",icon:x.jsx(c2,{}),onClick:e,variant:"ghost","aria-label":"close version history"})]})}),x.jsxs(zL,{overflowY:"auto",gap:0,children:[x.jsx(da,{mb:4,children:"All the saved changes of this workflow"}),x.jsx(Vd,{divider:x.jsx(C_,{}),spacing:2,children:a==null?void 0:a.map(l=>x.jsxs(Tr,{size:"sm",variant:"ghost",onClick:()=>{if(r){alert("You have unsaved changes, please save or discard your changes to proceed switching version, in case losing your changes.");return}gr.loadGraphData(JSON.parse(l.json)),no(t,{lastSavedJson:l.json}),e()},isActive:l.id===n,children:["Saved at ",o2(l.createTime,!0)]}))})]})]}))}function FW({onClick:e}){var S;const{curFlowID:t,onDuplicateWorkflow:r,discardUnsavedChanges:n,saveCurWorkflow:o}=m.useContext(Pa),[i,a]=m.useState(!1),[s,l]=m.useState(!1),[u,c]=m.useState(""),[d,f]=m.useState(""),[p,v]=m.useState();m.useEffect(()=>{const C=t?an(t):void 0;c((C==null?void 0:C.name)??""),v(C)},[t]);const g=C=>{c(C.target.value),d&&f("")},w=()=>{if(!t){alert("Flow ID is required");return}r==null||r(t,u),y()},y=()=>{a(!1)},h=m.useCallback(()=>{if(!oe||!t){alert("You don't have any workspaces");return}const C=oe[t];if(!C){alert("Workspace does not exist");return}const T=new Blob([C.json],{type:"application/json"}),_=URL.createObjectURL(T),$=document.createElement("a");$.href=_,$.download=`${C.name}.json`,document.body.appendChild($),$.click(),document.body.removeChild($),URL.revokeObjectURL(_)},[t]),b=(S=Se==null?void 0:Se.getSetting("shortcuts"))==null?void 0:S.save;return x.jsxs(x.Fragment,{children:[x.jsx(V_,{isLazy:!0,children:({isOpen:C})=>x.jsxs(x.Fragment,{children:[x.jsx(G_,{onClick:e,children:x.jsx(Jn,{icon:x.jsx(xW,{size:20}),"aria-label":"menu",size:"xs",backgroundColor:"#323232",color:"white"})}),x.jsxs(so,{children:[x.jsxs(H_,{minWidth:150,zIndex:1e3,children:[x.jsx(pi,{onClick:o,icon:x.jsx(im,{size:20}),iconSpacing:1,command:b,children:"Save"}),x.jsx(dn,{label:"This will revert current workflow to your last saved version. You will lose all changes made since your last save.",children:x.jsx(pi,{onClick:n,icon:x.jsx(bW,{size:20}),iconSpacing:1,isDisabled:(p==null?void 0:p.lastSavedJson)==null,children:"Discard unsaved changes"})}),x.jsx(pi,{onClick:h,icon:x.jsx(wW,{size:20}),iconSpacing:1,children:"Download"}),x.jsx(pi,{onClick:()=>a(!0),icon:x.jsx(im,{size:20}),iconSpacing:1,children:"Save As"}),x.jsx(pi,{onClick:()=>l(!0),icon:x.jsx(CW,{size:20}),iconSpacing:1,children:"Versions History"})]}),C&&x.jsx(DW,{backgroundColor:null})]})]})}),s&&x.jsx(RW,{onClose:()=>l(!1)}),i&&x.jsxs(kl,{isOpen:!0,onClose:y,children:[x.jsx(El,{}),x.jsxs(Cl,{children:[x.jsx(_l,{children:"Save As"}),x.jsx(Tl,{}),x.jsx(Pl,{children:x.jsxs(qv,{isInvalid:!!d,children:[x.jsx(Qv,{children:"Workflow name"}),x.jsx(Bd,{value:u,onChange:g,autoFocus:!0,onKeyUp:C=>{C.code==="Enter"&&!d&&w()}}),d&&x.jsx(Xv,{children:d})]})}),x.jsxs(Hd,{children:[x.jsx(Tr,{colorScheme:"teal",mr:3,onClick:w,isDisabled:!u||!!d,children:"Save"}),x.jsx(Tr,{onClick:y,children:"Cancel"})]})]})]})]})}function jW({displayName:e,updateFlowName:t,isDirty:r}){const{isOpen:n,onOpen:o,onClose:i}=G6(),{curFlowID:a}=m.useContext(Pa),[s,l]=m.useState(e),[u,c]=m.useState(""),d=()=>{l(e),o()},f=g=>{l(g.target.value),u&&c("")},p=()=>{var g;if(a){const w=s.trim();if(l(w),e===w)return v();((g=Gd())==null?void 0:g.map(h=>h.name)).includes(w)?c("The name is duplicated, please modify it and submit again."):(no(a,{name:w}),t(w),v())}},v=()=>{c(""),i()};return a==null?null:x.jsxs(Lr,{children:[x.jsx(dn,{label:e,placement:"bottom",children:x.jsxs(da,{color:"white",onClick:d,maxW:240,fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",children:[r&&"* ",e]})}),x.jsxs(kl,{isOpen:n,onClose:v,children:[x.jsx(El,{}),x.jsxs(Cl,{children:[x.jsx(_l,{children:"Edit workflow name"}),x.jsx(Tl,{}),x.jsx(Pl,{children:x.jsxs(qv,{isInvalid:!!u,children:[x.jsx(Qv,{children:"Workflow name"}),x.jsx(Bd,{value:s,onChange:f,autoFocus:!0,onKeyUp:g=>{g.code==="Enter"&&!u&&p()}}),u&&x.jsx(Xv,{children:u})]})}),x.jsxs(Hd,{children:[x.jsx(Tr,{colorScheme:"teal",mr:3,onClick:p,isDisabled:!s||!!u,children:"Save"}),x.jsx(Tr,{onClick:v,children:"Cancel"})]})]})]})]})}function NW({updatePanelPosition:e,positionStyle:t,curFlowName:r,setCurFlowName:n}){const[o,i]=m.useState(!1),{isDirty:a,loadNewWorkflow:s,saveCurWorkflow:l,setRoute:u,curFlowID:c}=m.useContext(Pa);return x.jsx(OW,{onDragEnd:d=>{e({top:d.y,left:d.x},!0)},children:x.jsxs(Lr,{style:{padding:2,position:"fixed",...t},justifyContent:"space-between",alignItems:"center",gap:2,draggable:!1,id:"workspaceManagerPanel",onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[x.jsx(Tr,{size:"sm","aria-label":"workspace folder",onClick:()=>u("recentFlows"),px:2,children:x.jsxs(Lr,{gap:1,children:[x.jsx(SW,{size:21}),x.jsx(AW,{size:8})]})}),x.jsx(Tr,{size:"sm",variant:"outline",colorScheme:"teal","aria-label":"new workflow",onClick:()=>s(),px:2,children:x.jsxs(Lr,{gap:1,children:[x.jsx(TW,{size:16,color:"white"}),x.jsx(da,{color:"white",fontSize:"sm",children:"New"})]})}),x.jsx(jW,{isDirty:a,displayName:r??"",updateFlowName:d=>{n(d),requestAnimationFrame(()=>{e()})}}),c&&x.jsxs(Lr,{gap:"1px",children:[x.jsx(dn,{label:"Open gallery",children:x.jsx(Jn,{onClick:()=>u("gallery"),icon:x.jsx(_W,{size:20,color:"white"}),size:"sm","aria-label":"open gallery",variant:"ghost"})}),x.jsx(FW,{onClick:()=>i(!1)})]}),c&&a&&x.jsx(dn,{label:"Save workflow",children:x.jsx(Jn,{onClick:l,icon:x.jsx(im,{size:22,color:"white"}),size:"xs","aria-label":"save workspace",variant:"ghost"})}),o&&x.jsx(kW,{id:"dragPanelIcon",cursor:"move",size:15,color:"#FFF"})]})})}var zW={BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const LW=zW.VITE_AWS_COGNITO_DOMAIN;function BW(){if(window.location.href.includes(Z9+"#")){const e=window.location.href.split("#")[1];let r=new URLSearchParams(e).get("access_token");window.opener.postMessage({comfyspace_authToken:r},"http://127.0.0.1:8188/"),window.close()}}function Lb(e){const{comfyspace_authToken:t}=e.data;t&&fetch(`${LW}/oauth2/userInfo`,{method:"GET",headers:{Authorization:`Bearer ${t}`}}).then(r=>r.json()).then(r=>{console.log("User Info:",r)}).catch(r=>{console.error("Error fetching user info:",r)})}const VW=Xr.lazy(()=>eS(()=>import("./ModelManager-TrdKAAkW.js"),__vite__mapDeps([]))),WW=Xr.lazy(()=>eS(()=>import("./RecentFilesDrawer-fgP2cnuP.js"),__vite__mapDeps([])));function UW(){const e=m.useRef({}),[t,r]=m.useState(null),[n,o]=m.useState("root"),[i,a]=m.useState(!0),[s,l]=m.useState(null),u=m.useRef(null),[c,d]=m.useState(),[f,p]=m.useState(!1),v=m.useRef(null),{showDialog:g}=f2(),[w,y]=m.useState(!1),h=m.useCallback(()=>{if(u.current){const R=JSON.stringify(gr.graph.serialize());no(u.current,{lastSavedJson:R,json:R}),qr==null||qr.create({workflowID:u.current,json:R})}},[]),b=()=>{if(confirm("Are you sure you want to discard unsaved changes? This will revert current workflow to your last saved version. You will lose all changes made since your last save.")&&u.current){const A=an(u.current);A&&A.lastSavedJson&&gr.loadGraphData(JSON.parse(A.lastSavedJson))}},S=R=>{u.current=R,l(R),an(R)&&localStorage.setItem("curFlowID",R)},C=async()=>{const R={name:"WorkspaceManager",async setup(j){localStorage.removeItem("workspace"),localStorage.removeItem("comfyspace")},async addCustomNodeDefs(j){e.current=j},async afterConfigureGraph(){localStorage.setItem("workflow",JSON.stringify(gr.graph.serialize()))}};gr.registerExtension(R);try{await dW(),Y(Se==null?void 0:Se.getSetting("topBarStyle"),!1)}catch(j){console.error("error loading db",j)}a(!1);const A=localStorage.getItem("curFlowID"),D=A!=null?an(A):null;D&&(D&&localStorage.setItem("workflow",D.json),S(D.id??null),r(D.name??null)),om()};m.useEffect(()=>{C(),y(!0),setInterval(()=>{const R=(Se==null?void 0:Se.getSetting("autoSave"))??!0;if(u.current!=null&&R){const A=JSON.stringify(gr.graph.serialize());A!=null&&no(u.current,{json:A})}p(T())},1e3),BW()},[]);const T=()=>{if(u.current!=null){const R=gr.graph.serialize()??{},A=u.current?an(u.current):null;let D={};try{D=A!=null&&A.lastSavedJson?JSON.parse(A==null?void 0:A.lastSavedJson):{}}catch(z){console.error("error parsing json",z)}return!(JSON.stringify(R)===JSON.stringify(D))}return!1},_=R=>{if(gr.graph==null){console.error("app.graph is null cannot load workflow");return}S(R);const A=an(R);if(A==null){alert("Error: Workflow not found! id: "+R);return}gr.ui.dialog.close(),gr.loadGraphData(JSON.parse(A.json)),r(A.name),o("root")},$=R=>{if(((Se==null?void 0:Se.getSetting("autoSave"))??!0)||!f){_(R);return}g(`Do you want to save the current workflow, ${t}?`,[{label:"Save",colorScheme:"teal",onClick:()=>{h(),_(R)}},{label:"Discard",colorScheme:"red",onClick:()=>{_(R)}}])},I=R=>{const A=(R==null?void 0:R.json)??JSON.stringify(jb),D=xp({json:A,name:R==null?void 0:R.name});$(D.id),o("root")},O=async(R,A=!1)=>{const D=R.split("/").pop()??R;A?h():I({name:D});const j=await fetch(aW(R)),z=await j.blob(),L=new File([z],D,{type:j.headers.get("Content-Type")||""});await gr.handleFile(L),o("root")},N=(R,A)=>{if(oe==null)return;const D=oe[R];if(D==null)return;const j=xp({json:D.json,name:A||D.name,parentFolderID:D.parentFolderID,tags:D.tags});$(j.id)},Y=m.useCallback((R,A=!1)=>{const{top:D=0,left:j=0}=c||{};let{top:z=0,left:L=0}=R??{};z+=D,L+=j;const q=document.documentElement.clientWidth,B=document.documentElement.clientHeight,U=document.getElementById("workspaceManagerPanel"),ee=(U==null?void 0:U.offsetWidth)||392;z+36>B&&(z=B-36),L+ee>=q&&(L=q-ee),d({top:Math.max(0,z),left:Math.max(0,L)}),A&&(Se==null||Se.upsert({topBarStyle:{top:z,left:L}}))},[c]),G=R=>{nW(R)&&h()},K=m.useCallback(R=>{if(u.current==null)return;let A=R.filename;R.subfolder!=null&&R.subfolder!==""&&(A=R.subfolder+"/"+A),Bt==null||Bt.create({workflowID:u.current,localPath:A})},[]),Z=m.useCallback(()=>{o("root")},[]);return m.useEffect(()=>{window.addEventListener("keydown",G),window.addEventListener("message",Lb);const R=document.getElementById("comfy-file-input"),A=()=>{if(R&&R.files&&R.files.length>0){const j=xp({name:R.files[0].name,json:JSON.stringify(jb)});S(j.id),r(j.name??"Unknown name")}};R==null||R.addEventListener("change",A);const D=j=>{!((Se==null?void 0:Se.getSetting("autoSave"))??!0)&&T()&&(j.preventDefault(),j.returnValue="You have unsaved changes")};return window.addEventListener("beforeunload",D),wE.addEventListener("executed",j=>{var z,L,q,B,U,ee;(q=(L=(z=j.detail)==null?void 0:z.output)==null?void 0:L.images)==null||q.forEach(re=>{re.type==="output"&&K(re)}),(ee=(U=(B=j.detail)==null?void 0:B.output)==null?void 0:U.gifs)==null||ee.forEach(re=>{re.type==="output"&&K(re)})}),()=>{window.removeEventListener("message",Lb),window.removeEventListener("keydown",G),window.removeEventListener("change",A),window.removeEventListener("beforeunload",D)}},[]),i||!c?null:x.jsx(Pa.Provider,{value:{curFlowID:s,onDuplicateWorkflow:N,loadWorkflowID:$,discardUnsavedChanges:b,saveCurWorkflow:h,isDirty:f,loadNewWorkflow:I,loadFilePath:O,setRoute:o},children:x.jsx("div",{ref:v,className:"workspace_manager",children:x.jsxs(so,{containerRef:v,children:[w&&x.jsx(m.Suspense,{children:x.jsx(VW,{})}),x.jsxs(cg,{style:{width:"100vh",position:"absolute",top:0,left:0,lineHeight:"24px"},zIndex:1e3,draggable:!1,children:[x.jsx(NW,{curFlowName:t,setCurFlowName:r,updatePanelPosition:Y,positionStyle:c}),w&&n==="recentFlows"&&x.jsx(m.Suspense,{children:x.jsx(WW,{onClose:Z,onClickNewFlow:()=>{I(),o("root")}})}),n==="gallery"&&x.jsx(IW,{onclose:()=>o("root")})]})]})})})}const p2=String.raw,HW=p2` :root, :host { --chakra-vh: 100vh; diff --git a/entry/entry.js b/entry/entry.js index e172e1b..236df8a 100644 --- a/entry/entry.js +++ b/entry/entry.js @@ -10,6 +10,7 @@ const callback = function (mutationsList, observer) { // @ts-ignore mutation.addedNodes.forEach((node) => { if (node.nodeName === "CANVAS") { + // @ts-ignore import("/workspace_web/input.js"); observer.disconnect(); } diff --git a/ui/src/Api.ts b/ui/src/Api.ts index 4b354a8..af9feb4 100644 --- a/ui/src/Api.ts +++ b/ui/src/Api.ts @@ -1,7 +1,6 @@ import { Table } from "./db-tables/WorkspaceDB"; export async function getDB(table: Table): Promise { - console.warn("getDB ntable", table); try { const response = await fetch(`/workspace/get_db?table=${table}`); if (!response.ok) { diff --git a/ui/vite.config.ts b/ui/vite.config.ts index 67b97e0..77137c4 100644 --- a/ui/vite.config.ts +++ b/ui/vite.config.ts @@ -30,7 +30,7 @@ export default defineConfig({ dir: "../dist", // assetFileNames: "[name]-[hash][extname]", entryFileNames: "workspace_web/[name].js", - chunkFileNames: `workspace_web/[name].js`, + chunkFileNames: `workspace_web/[name]-[hash].js`, assetFileNames: `assets/[name]-[hash].[ext]`, }, },