39 lines
67 KiB
JavaScript
39 lines
67 KiB
JavaScript
function getImportPath(filename) {
|
|
return `./${filename}`;
|
|
}
|
|
import{j as e}from"./vendor-markdown-Dek94WS0.js";import{r as w}from"./vendor-react-V04_Axys.js";import{u as ve,a as V,g as ie,W as se}from"./message-components-C_KwPGE8.js";import{m as gt,i as pt,r as ft,g as bt}from"./workflowChat-C3ZWZR1l.js";import"./input.js";/* empty css */const yt=({selectedNodes:t,handleParamSelect:r,selectedParams:s,handleNext:l,handleClose:a})=>{const n=t.flatMap(i=>(i.widgets||[]).map(d=>d.name)).some(i=>s[i]===!0);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Select parameters"}),e.jsx("p",{className:"text-xs text-gray-500",children:"multiple selections supported"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:a,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t.map((i,d)=>{const m=i.title||"Unknown Node",u=i.widgets||[];return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsx("div",{className:"bg-gray-50 px-3 py-2 text-sm font-medium text-gray-700 border-b",children:m}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:u.map((x,g)=>{const f=x.name;return e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border flex items-center justify-center ${s[f]?"border-red-500 bg-red-100":"border-gray-300"}`,onClick:b=>r(f,b),children:s[f]&&e.jsx("div",{className:"w-3 h-3 rounded-full bg-red-500"})}),e.jsx("span",{className:"ml-2 text-gray-700 text-xs",children:f})]},`widget-${g}`)})})})]},`node-${d}`)}),e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx("button",{onClick:i=>l(i),disabled:!n,className:`px-3 py-1.5 text-xs ${n?"bg-pink-200 text-pink-700 hover:bg-pink-300":"bg-gray-200 text-gray-500 cursor-not-allowed"} rounded-md transition-colors`,children:"Next"})})]})},jt=({selectedNodes:t,paramTestValues:r,selectedParams:s,updateParamTestValues:l,toggleDropdown:a,openDropdowns:o,handleTestValueSelect:n,searchTerms:i,handleSearch:d,handleSelectAll:m,handleNext:u,handlePrevious:x,handleClose:g,inputValues:f,setInputValues:b,textInputs:$,handleTextInputChange:k,handleAddTextInput:L,handleRemoveTextInput:P,openAiWritingModal:y})=>{const N=(p,S,O,G=0)=>{if(p=isNaN(p)?0:p,S=isNaN(S)?100:S,O=isNaN(O)||O<=0?1:O,S<p&&(S=p),Math.floor((S-p)/O)+1<=1)return[p];const E=[];let R=p;for(;R<=S;){const v=Math.pow(10,G),T=Math.round(R*v)/v;E.push(T),R+=O}return E};return w.useEffect(()=>{!t||t.length===0||t.forEach(p=>{const S=p.id.toString(),O=p.widgets||{};Object.values(O).forEach(j=>{const E=j.name;if(!s[E])return;if(!(r[S]?.[E]?.length>0)&&j.type==="number"){const v=j.options?.min||0,T=j.options?.max||100;let I=(j.options?.step||10)/10;I<.1&&(I=.1);const _=j.options?.precision||0,B=N(v,T,I,_);if(B.length>0){l(S,E,B);const z=`${S}_${E}`;b(C=>({...C,[z]:{min:v.toString(),max:T.toString(),step:I.toString()}}))}}if(j.type==="customtext"||j.type.toLowerCase().includes("text")){const v=`${S}_${E}`,T=$[v]||[""];JSON.stringify(T)!==JSON.stringify(r[S]?.[E]||[""])&&l(S,E,T)}})})},[t,s,r,$,l,b,N]),e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Set test values"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Configure the test values for each parameter"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:g,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t.length>0?t.map((p,S)=>{const O=p.widgets||{},G=Object.values(O),j=p.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b flex justify-between items-center",children:[e.jsxs("span",{children:[p.type," (ID: ",j,")"]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:E=>g(E,S),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"p-4 space-y-4",children:G.map((E,R)=>{const v=E.name;if(!s[v])return null;const T=`${j}_${v}`;if(E.type==="customtext"||E.type.toLowerCase().includes("text")){const I=$[T]||[""];return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[v,":"]}),e.jsxs("button",{className:"px-2 py-1 bg-blue-100 text-blue-700 rounded text-xs flex items-center hover:bg-blue-200 transition-colors",onClick:()=>y(j,v),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})}),"AI Writing"]})]}),e.jsx("div",{className:"space-y-2",children:I.map((_,B)=>e.jsxs("div",{className:"flex items-start",children:[e.jsx("textarea",{className:`flex-1 border ${_?"border-gray-300":"border-red-500"} rounded p-2 text-xs resize-y`,rows:2,placeholder:"Enter text...",value:_,onChange:z=>k(j,v,B,z.target.value),required:!0}),e.jsx("button",{className:"ml-2 text-red-500 hover:text-red-700",onClick:()=>P(j,v,B),title:"Remove",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},B))}),e.jsxs("button",{className:"mt-2 px-2 py-1 border border-dashed border-gray-300 rounded text-xs text-gray-600 hover:bg-gray-50 flex items-center",onClick:()=>L(j,v),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),"Add Text"]})]},R)}if(E.type==="number"){const I=E.options?.min||0,_=E.options?.max||100,B=(E.options?.step||10)/10,z=E.options?.precision||0,C=N(I,_,B,z),F=f[T]||{min:I.toString(),max:_.toString(),step:B.toString()};return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[v,":"]}),e.jsx("div",{className:"w-4"})]}),e.jsxs("div",{className:"flex space-x-2 items-center",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Min"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:F.min,required:!0,onClick:M=>{M.preventDefault(),M.stopPropagation()},onChange:M=>{M.preventDefault(),M.stopPropagation();const D=M.target.value;if(b(A=>({...A,[T]:{...A[T],min:D}})),D===""||!isNaN(parseFloat(D))){const A=D===""?0:parseFloat(D),H=parseFloat(F.max||_.toString()),U=parseFloat(F.step||B.toString()),J=N(A,H,U,z);l(j,v,J)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Max"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:F.max,onClick:M=>{M.preventDefault(),M.stopPropagation()},required:!0,onChange:M=>{M.preventDefault(),M.stopPropagation();const D=M.target.value;if(b(A=>({...A,[T]:{...A[T],max:D}})),D===""||!isNaN(parseFloat(D))){const A=parseFloat(F.min||I.toString()),H=D===""?A:parseFloat(D),U=parseFloat(F.step||B.toString()),J=N(A,H,U,z);l(j,v,J)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Step"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:F.step,required:!0,onClick:M=>{M.preventDefault(),M.stopPropagation()},onChange:M=>{M.preventDefault(),M.stopPropagation();const D=M.target.value;if(b(A=>({...A,[T]:{...A[T],step:D}})),D===""||!isNaN(parseFloat(D))&&parseFloat(D)>0){const A=parseFloat(F.min||I.toString()),H=parseFloat(F.max||_.toString());let U=D===""?1:parseFloat(D);U<.1&&(U=.1);const J=N(A,H,U,z);l(j,v,J)}}})]}),e.jsxs("div",{className:"mt-1",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(()=>{const M=r[j]?.[v]||C;if(M.length<=10)return M.map((D,A)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:H=>{H.stopPropagation(),n(j,v,D,H)},children:[e.jsx("span",{children:D}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},A));{const D=M.slice(0,5),A=M.slice(M.length-5);return e.jsxs(e.Fragment,{children:[D.map((H,U)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:J=>{J.stopPropagation(),n(j,v,H,J)},children:[e.jsx("span",{children:H}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`first-${U}`)),e.jsx("div",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 rounded-md flex items-center text-xs",children:"..."}),A.map((H,U)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:J=>{J.stopPropagation(),n(j,v,H,J)},children:[e.jsx("span",{children:H}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`last-${U}`))]})}})()})]}),e.jsx("div",{className:"mt-1",children:e.jsx("p",{className:"text-xs text-gray-500",children:"Values are distributed evenly between Min and Max"})})]},R)}else if(E.type==="combo"){const I=E.options?.values||[],_=`${j}_${v}`,B=C=>typeof C=="string"?C:C&&typeof C=="object"&&"name"in C?C.name:String(C),z=C=>typeof C=="object"&&C!==null&&"name"in C?C.name:C;return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("label",{className:"text-xs font-medium text-gray-700",children:v}),e.jsxs("div",{className:"relative dropdown-container",children:[e.jsxs("button",{className:`appearance-none border ${(r[j]?.[v]||[]).length===0?"border-red-500":"border-gray-300"} rounded px-2 py-0.5 pr-6 text-xs flex items-center bg-white text-gray-700`,onClick:C=>{C.preventDefault(),C.stopPropagation(),a(j,v,C)},"data-dropdown":_,children:[e.jsx("span",{children:(r[j]?.[v]||[]).length>0?`${v}: ${(r[j]?.[v]||[]).length} selected`:`Select ${v}`}),e.jsx("div",{className:"ml-2",children:e.jsx("svg",{className:"fill-current h-4 w-4",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",children:e.jsx("path",{d:"M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"})})})]}),o[_]&&e.jsxs("div",{className:"absolute z-[9999] mt-1 w-64 bg-white border border-gray-300 rounded-md shadow-lg dropdown-menu",style:{position:"fixed",top:typeof o[_]=="object"?`${o[_].y}px`:"0px",left:typeof o[_]=="object"?`${o[_].x}px`:"0px",maxHeight:"300px",overflowY:"auto"},children:[e.jsx("div",{className:"p-2 border-b sticky top-0 bg-white",children:e.jsx("input",{type:"text",className:"w-full px-2 py-0.5 text-xs border border-gray-300 rounded",placeholder:"Search...",value:i[_]||"",onChange:C=>{C.preventDefault(),C.stopPropagation(),d(j,v,C.target.value)},onClick:C=>{C.preventDefault(),C.stopPropagation()},autoFocus:!0})}),e.jsxs("div",{className:"px-3 py-1.5 bg-gray-50 border-b cursor-pointer text-xs flex items-center text-gray-700 hover:bg-gray-100",onClick:C=>{C.preventDefault(),C.stopPropagation();const M=I.filter(D=>!i[_]||B(D).toLowerCase().includes((i[_]||"").toLowerCase())).map(z);m(j,v,M)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${I.length>0&&(r[j]?.[v]||[]).length===I.length?"bg-blue-500 border-blue-500":(r[j]?.[v]||[]).length>0?"bg-blue-500 border-blue-500 opacity-50":"border-gray-300"}`,children:(r[j]?.[v]||[]).length>0&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"font-medium",children:I.length>0&&(r[j]?.[v]||[]).length===I.length?"Deselect All":"Select All"})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[I.filter(C=>!i[_]||B(C).toLowerCase().includes((i[_]||"").toLowerCase())).map((C,F)=>e.jsxs("div",{className:"px-3 py-1.5 hover:bg-gray-100 cursor-pointer text-xs flex items-center text-gray-700",onClick:M=>{M.preventDefault(),M.stopPropagation(),n(j,v,z(C),M)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${(r[j]?.[v]||[]).includes(z(C))?"bg-blue-500 border-blue-500":"border-gray-300"}`,children:(r[j]?.[v]||[]).includes(z(C))&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"whitespace-normal overflow-hidden text-ellipsis",children:B(C)})]},F)),I.filter(C=>!i[_]||B(C).toLowerCase().includes((i[_]||"").toLowerCase())).length===0&&e.jsx("div",{className:"px-3 py-4 text-sm text-gray-500 text-center",children:"No matching options"})]})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),(r[j]?.[v]||[]).length===0&&e.jsx("div",{className:"text-xs text-red-500 mt-1",children:"Please select at least one value"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(r[j]?.[v]||[]).map((C,F)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:C}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:M=>{M.preventDefault(),M.stopPropagation(),n(j,v,C,M)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},F))})]})]},R)}else return e.jsxs("div",{className:"border-b pb-3",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsx("label",{className:"text-xs font-medium text-gray-700",children:v})}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[(r[j]?.[v]||[]).map((I,_)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:I}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:B=>{B.preventDefault(),B.stopPropagation(),n(j,v,I,B)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},_)),e.jsxs("button",{className:"px-2 py-0.5 border border-dashed border-blue-300 text-blue-600 rounded-md text-xs flex items-center hover:bg-blue-50",onClick:I=>{I.preventDefault(),I.stopPropagation();const _=`${v}${(r[j]?.[v]||[]).length+1}`;l(j,v,[...r[j]?.[v]||[],_])},children:[e.jsx("svg",{className:"w-4 h-4 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),e.jsx("span",{children:"Add"})]})]})]})]},R)})})]},S)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:p=>x(p),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:p=>u(p),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})]})]})},vt=({selectedNodes:t,paramTestValues:r,selectedParams:s,totalCount:l,errorMessage:a,handlePrevious:o,handleStartGeneration:n,handleClose:i})=>{const[d,m]=w.useState([]),[u,x]=w.useState(null),[g,f]=w.useState(!1);ve();const b=()=>{const k=Object.values(V.graph._nodes_by_id),L=[],P=[];for(const N of k)N.type==="SaveImage"?L.push(N.id):N.type==="PreviewImage"&&P.push(N.id);const y=[...L,...P];m(y),y.length===1?x(y[0]):y.length>1&&(f(!0),x(null))};w.useEffect(()=>{b()},[]),w.useEffect(()=>{const k=()=>{if(!V.canvas.selected_nodes)return;const L=Object.values(V.canvas.selected_nodes);if(L.length===0)return;const P=L[0];P&&(P.type==="SaveImage"||P.type==="PreviewImage")&&(console.log("Selected image node:",P.id),x(P.id))};return document.addEventListener("click",k),()=>{document.removeEventListener("click",k)}},[]);const $=k=>{if(k&&(k.preventDefault(),k.stopPropagation()),d.length>1&&!u){f(!0);return}n(k,u||void 0)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Conform combinations"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",l," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:i,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),g&&d.length>1&&e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 border border-yellow-200 rounded-md text-amber-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:u===null?`Multiple SaveImage and PreviewImage nodes detected with IDs ${d.join(",")}. Please click the node on canvas.`:`Current node ID is ${u}, please click Start Generation again`})]})}),a&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:a})]})}),t.length>0?t.map((k,L)=>{const P=k.type||"Unknown Node",y=k.widgets||[],N=k.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[P," (ID: ",N,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:y.map((p,S)=>{const O=p.name;if(!s[O])return null;const G=r[N]?.[O]||[],j=Array.isArray(G)?`[${G.join(", ")}]`:JSON.stringify(G);return e.jsxs("div",{className:S<y.length-1?"flex justify-between items-center border-b pb-2":"flex justify-between items-center",children:[e.jsx("label",{className:"font-medium text-gray-700 text-xs",children:O}),e.jsx("div",{className:"flex space-x-2 items-center",children:e.jsx("input",{type:"text",className:"w-64 h-7 border border-gray-300 rounded text-xs px-2 bg-gray-50 cursor-not-allowed text-gray-500",readOnly:!0,disabled:!0,value:j,onClick:E=>E.preventDefault()})})]},S)})})]},L)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500 text-xs",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:k=>o(k),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:k=>$(k),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${d.length>1&&!u?"bg-gray-200 text-gray-500 cursor-not-allowed":"bg-pink-200 text-pink-700 hover:bg-pink-300"}`,disabled:d.length>1&&!u,children:"Generate & Compare"})]})]})},Nt=({selectedNodes:t,paramTestValues:r,selectedParams:s,totalCount:l,completedCount:a,errorMessage:o,handleClose:n,setIsProcessing:i,setCurrentScreen:d,cleanupPolling:m})=>{const u=x=>{x.preventDefault(),x.stopPropagation(),gt({clear:!0}),pt(),m&&m(),i(!1),d(2)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4 relative",children:[e.jsx("div",{className:"absolute inset-0 bg-gray-500 bg-opacity-30 flex flex-col items-center justify-center z-10",children:e.jsxs("div",{className:"text-center text-gray-800 bg-white p-4 rounded-lg shadow-lg",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"Processing..."}),e.jsxs("div",{className:"text-xs mb-3",children:["Completed ",a," of ",l," runs"]}),e.jsx("div",{className:"w-48 h-2 bg-gray-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-pink-500 transition-all duration-200",style:{width:`${a/l*100}%`}})}),e.jsxs("div",{className:"mt-2 text-xs text-gray-600",children:["Already generated ",a," images"]}),e.jsx("button",{onClick:u,className:"mt-4 px-3 py-1.5 text-xs bg-gray-200 text-gray-800 rounded-md hover:bg-gray-300 transition-colors",children:"Cancel"})]})}),e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Confirm Test Configuration"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",l," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:n,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),o&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:o})]})}),t.length>0?t.map((x,g)=>{const f=x.type||"Unknown Node",b=x.widgets||[],$=x.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[f," (ID: ",$,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:b.map((k,L)=>{const P=k.name;if(!s[P])return null;const y=r[$]?.[P]||[],N=Array.isArray(y)?`[${y.join(", ")}]`:JSON.stringify(y);return e.jsxs("div",{className:L<b.length-1?"flex justify-between items-center border-b pb-2":"flex justify-between items-center",children:[e.jsx("label",{className:"font-medium text-gray-700",children:P}),e.jsx("div",{className:"flex space-x-2 items-center",children:e.jsx("input",{type:"text",className:"w-64 h-7 border border-gray-300 rounded text-sm px-2 bg-gray-50 cursor-not-allowed text-gray-500",readOnly:!0,disabled:!0,value:N,onClick:p=>p.preventDefault()})})]},L)})})]},g)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."})]})},te=({visible:t,imageUrl:r,params:s,onClose:l})=>{if(!t)return null;const a=()=>{if(!s||!s.nodeParams)return null;const o=Object.entries(s.nodeParams).map(([n,i])=>{const d=s.nodeNames?.[n]||s.selectedNodeInfoMap&&s.selectedNodeInfoMap[n]||(n.includes("text")?"Text Node":`Node ${n}`),m=Object.entries(i).filter(([u,x])=>typeof x!="object"||x===null).map(([u,x])=>e.jsxs("div",{className:"pl-4 text-sm py-1 flex",children:[e.jsx("span",{className:"text-gray-600 dark:text-gray-400 mr-2",children:"-"}),e.jsxs("span",{className:"font-medium mr-1",children:[u,":"]}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300 break-all",children:String(x)})]},u));return e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"font-semibold text-pink-600 dark:text-pink-400 text-base py-1 border-b border-gray-200 dark:border-gray-700 mb-2",children:d}),m.length>0?m:e.jsx("div",{className:"pl-4 text-sm text-gray-500 italic",children:"nodeParams is null"})]},n)});return e.jsx("div",{className:"overflow-y-auto max-h-full",children:o.length>0?o:e.jsx("div",{className:"text-sm text-gray-500 italic",children:"nodeParams is null"})})};return e.jsx("div",{className:"fixed inset-0 bg-black/40 backdrop-blur-sm flex items-center justify-center z-50",onClick:l,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-2xl flex flex-row w-[90%] max-w-6xl max-h-[90vh] relative m-4 overflow-hidden",onClick:o=>o.stopPropagation(),style:{display:"flex",flexDirection:"row"},children:[e.jsx("button",{className:"absolute top-2 right-2 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 p-1 z-10",onClick:l,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),e.jsx("div",{className:"w-[65%] border-r border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"p-4 h-full flex items-center justify-center",children:e.jsx("img",{src:r,alt:"Enlarged image",className:"max-w-full max-h-[calc(90vh-2rem)] object-contain"})})}),e.jsx("div",{className:"w-[35%] h-full overflow-hidden flex flex-col",children:e.jsxs("div",{className:"p-4 flex-1 overflow-y-auto",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-800 dark:text-gray-200 mb-4",children:"Parameters"}),s&&!s.nodeParams&&Object.entries(s).filter(([o,n])=>o!=="nodeParams"&&typeof n!="object").map(([o,n])=>e.jsxs("div",{className:"py-1 text-sm text-gray-600 dark:text-gray-300",children:[e.jsxs("span",{className:"font-medium",children:[o,":"]})," ",String(n)]},o)),e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-300",children:a()})]})})]})})},wt=({generatedImages:t,selectedImageIndex:r,handleSelectImage:s,handleApplySelected:l,handlePrevious:a,handleClose:o,currentPage:n,handlePageChange:i,imagesPerPage:d,notificationVisible:m,modalVisible:u,modalImageUrl:x,modalImageParams:g,openImageModal:f,closeImageModal:b})=>{const $=Math.ceil(t.length/d),k=(n-1)*d,L=Math.min(k+d,t.length),P=t.slice(k,L);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Generation Complete"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["All ",t.length," images have been generated."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:o,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),m&&e.jsx("div",{className:"fixed top-4 right-4 bg-green-100 border-l-4 border-green-500 text-green-700 p-3 shadow-md rounded animate-fade-in-out z-50",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"py-1",children:e.jsx("svg",{className:"h-4 w-4 text-green-500 mr-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("p",{className:"text-xs",children:"Parameters has been applied."})]})}),e.jsx(te,{visible:u,imageUrl:x,params:g||{},onClose:b}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:P.map((y,N)=>{const p=k+N;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${r===p?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:S=>s(p,S),children:[e.jsx("button",{className:"absolute top-2 right-2 bg-white bg-opacity-75 rounded-full p-0.5 text-gray-600 hover:text-gray-900 shadow-sm z-10",onClick:S=>f(y.url,y.params,S),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5v-4m0 4h-4m4 0l-5-5"})})}),e.jsx("div",{className:"aspect-square",children:e.jsx("img",{src:y.url,alt:`Generated image ${p+1}`,className:"w-full h-full object-cover"})}),e.jsx("div",{className:"p-2 text-xs text-gray-600 bg-white max-h-16 overflow-y-auto",children:Object.entries(y.params).filter(([S,O])=>S!=="nodeParams"&&typeof O!="object").map(([S,O])=>e.jsxs("div",{children:[S,": ",String(O)]},S))})]},p)})}),$>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:y=>i(1,y),disabled:n===1,className:`px-2 py-1 rounded ${n===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M15.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M8.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L4.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"})]})}),e.jsx("button",{onClick:y=>i(n-1,y),disabled:n===1,className:`px-2 py-1 rounded ${n===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"px-2 py-1 text-xs text-gray-800",children:["Page ",n," of ",$]}),e.jsx("button",{onClick:y=>i(n+1,y),disabled:n===$,className:`px-2 py-1 rounded ${n===$?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",clipRule:"evenodd"})})}),e.jsx("button",{onClick:y=>i($,y),disabled:n===$,className:`px-2 py-1 rounded ${n===$?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M4.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L8.586 10 4.293 14.293a1 1 0 000 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M11.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L15.586 10l-4.293 4.293a1 1 0 000 1.414z",clipRule:"evenodd"})]})})]}),e.jsx("div",{className:"mt-6 flex justify-end",children:e.jsx("button",{onClick:y=>l(y),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",disabled:r===null,children:"Apply Selected"})})]})},kt=({visible:t,aiWritingModalText:r,setAiWritingModalText:s,aiGeneratedTexts:l,aiSelectedTexts:a,aiWritingLoading:o,aiWritingError:n,handleAiWriting:i,toggleTextSelection:d,addSelectedTexts:m,onClose:u})=>t?e.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-2xl w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"AI Writing Assistant"}),e.jsx("button",{className:"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200",onClick:u,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-4 overflow-y-auto flex-1",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm text-gray-700 dark:text-gray-300 mb-2",children:"Enter text and AI will generate variations"}),e.jsx("textarea",{className:`w-full px-4 py-3 border border-gray-200 dark:border-gray-600 rounded-lg text-gray-900 dark:text-white
|
|
bg-gray-50 dark:bg-gray-700
|
|
placeholder-gray-500 dark:placeholder-gray-400
|
|
focus:border-blue-500 dark:focus:border-blue-400
|
|
focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20
|
|
focus:outline-none`,rows:3,placeholder:"Enter some text here...",value:r,onChange:x=>s(x.target.value)}),e.jsx("button",{className:`mt-2 px-4 py-2 rounded-lg text-sm flex items-center transition-colors ${o?"bg-gray-300 dark:bg-gray-600 text-gray-500 dark:text-gray-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 text-white"}`,onClick:i,disabled:o,children:o?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-gray-500 dark:text-gray-400",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Generating..."]}):e.jsx(e.Fragment,{children:"Generate"})})]}),n&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800/20 rounded-md text-red-700 dark:text-red-400 text-sm",children:n}),l.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Generated variations (select items to add):"}),e.jsx("div",{className:"space-y-2 max-h-[40vh] overflow-y-auto p-2",children:l.map((x,g)=>e.jsxs("div",{className:"flex items-start border border-gray-200 dark:border-gray-600 rounded-md p-2",children:[e.jsx("div",{className:"mr-2 mt-1",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",id:`text${g+1}`,checked:!!a[`text${g+1}`],onChange:()=>d(`text${g+1}`),className:"sr-only"}),e.jsx("div",{className:`h-4 w-4 rounded border ${a[`text${g+1}`]?"bg-blue-600 dark:bg-blue-500 border-blue-600 dark:border-blue-500":"border-gray-300 dark:border-gray-600"} flex items-center justify-center cursor-pointer`,onClick:()=>d(`text${g+1}`),children:a[`text${g+1}`]&&e.jsx("svg",{className:"h-3 w-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})})]})}),e.jsx("label",{htmlFor:`text${g+1}`,className:"text-sm text-gray-700 dark:text-gray-300 cursor-pointer flex-1",children:x})]},g))})]})]}),e.jsxs("div",{className:"p-4 border-t border-gray-200 dark:border-gray-700 flex justify-end flex-shrink-0",children:[e.jsx("button",{className:`px-5 py-2.5 text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700
|
|
rounded-lg font-medium transition-colors mr-3`,onClick:u,children:"Cancel"}),e.jsx("button",{className:`px-5 py-2.5 rounded-lg font-medium transition-colors ${Object.values(a).every(x=>!x)?"bg-gray-300 dark:bg-gray-600 text-gray-500 dark:text-gray-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 text-white"}`,onClick:m,disabled:Object.values(a).every(x=>!x),children:"Add Selected"})]})]})}):null,je=t=>{const r=[],s={};if(Object.keys(t).forEach(o=>{const n=parseInt(o),i=t[o]||{},d=Object.keys(i).filter(u=>i[u]&&i[u].length>0);if(d.length===0)return;const m=[[]];d.forEach(u=>{const x=i[u],g=[];m.forEach(f=>{x.forEach(b=>{const $=[...f,{nodeId:n,paramName:u,paramValue:String(b)}];g.push($)})}),m.length=0,m.push(...g)}),s[o]=m}),Object.keys(s).length===0)return r;if(Object.keys(s).length===1){const o=Object.keys(s)[0];return s[o]}const l=Object.keys(s);let a=s[l[0]];for(let o=1;o<l.length;o++){const n=s[l[o]],i=[];a.forEach(d=>{n.forEach(m=>{i.push([...d,...m])})}),a=i}return a},St=(t,r)=>{const s={};s.nodeParams={};const l=je(t);return r<l.length&&l[r].forEach(o=>{const n=o.nodeId.toString(),i=o.paramName,d=o.paramValue;s.nodeParams[n]||(s.nodeParams[n]={}),s.nodeParams[n][i]=d,s[i]=d}),s},Be="parameter_debug_history",De=30,Ae=async(t,r,s,l,a)=>{try{const o=Re(),n={id:ie(),timestamp:Date.now(),title:Ne(t,r),nodeName:t,params:{...r,nodeNames:{...r.nodeNames||{},[t.split("<")[0]]:t.split("<")[0]}},generatedImages:s,totalCount:l,workflow:a};return o.unshift(n),o.length>De&&o.splice(De),localStorage.setItem(Be,JSON.stringify(o)),n}catch(o){return console.error("Error saving parameter debug history:",o),null}},Re=()=>{try{const t=localStorage.getItem(Be);if(t)return JSON.parse(t)}catch(t){console.error("Error loading parameter debug history:",t)}return[]},ze=t=>{const r=new Date(t);return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")} ${String(r.getHours()).padStart(2,"0")}:${String(r.getMinutes()).padStart(2,"0")}`},Ne=(t,r)=>{if(r.nodeParams)return Object.entries(r.nodeParams).map(([o,n])=>{let i=t;r.selectedNodeInfoMap&&r.selectedNodeInfoMap[o]&&(i=r.selectedNodeInfoMap[o]);const d=Object.keys(n).slice(0,3);return`${i}<${d.join(",")}>`}).join(";");const s=Object.keys(r).filter(l=>l!=="nodeParams"&&l!=="selectedNodeInfoMap").slice(0,3);return`${t}<${s.join(",")}>`},Ct=({historyItems:t,onViewHistoryItem:r,onClose:s})=>e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4 flex flex-col h-full",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Experiments History"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Last ",t.length," experiments"]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:s,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-gray-500 text-sm",children:"No history items found"}):e.jsx("div",{className:"flex-1 overflow-y-auto",children:t.map(l=>e.jsxs("div",{className:"border border-gray-200 rounded-lg mb-3 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 py-2 px-3 flex items-center justify-between border-b",children:[e.jsx("div",{className:"text-[14px] text-gray-600",children:ze(l.timestamp)}),e.jsx("button",{onClick:()=>r(l),className:"px-3 py-1 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"view"})]}),e.jsx("div",{className:"p-3",children:e.jsx("div",{className:"text-[10px] font-medium text-gray-700",children:Ne(l.nodeName,l.params)})})]},l.id))})]}),Lt=({historyItem:t,selectedImageIndex:r,handleSelectImage:s,handleClose:l,currentPage:a,handlePageChange:o,imagesPerPage:n,modalVisible:i,modalImageUrl:d,modalImageParams:m,openImageModal:u,closeImageModal:x})=>{const{timestamp:g,nodeName:f,generatedImages:b,params:$}=t,k=Math.ceil(b.length/n),L=(a-1)*n,P=Math.min(L+n,b.length),y=b.slice(L,P);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:Ne(f,$)}),e.jsxs("p",{className:"text-xs text-gray-500",children:[ze(g)," • ",b.length," images"]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600 mt-0",onClick:l,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx(te,{visible:i,imageUrl:d,params:m?{...m,nodeNames:{[t.nodeName.split("<")[0]]:t.nodeName.split("<")[0]}}:void 0,onClose:x}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:y.map((N,p)=>{const S=L+p;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${r===S?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:O=>s(S,O),children:[e.jsx("button",{className:"absolute top-2 right-2 bg-white bg-opacity-75 rounded-full p-0.5 text-gray-600 hover:text-gray-900 shadow-sm z-10",onClick:O=>u(N.url,N.params,O),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5v-4m0 4h-4m4 0l-5-5"})})}),e.jsx("div",{className:"aspect-square",children:e.jsx("img",{src:N.url,alt:`Generated image ${S+1}`,className:"w-full h-full object-cover"})})]},S)})}),k>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:N=>o(1,N),disabled:a===1,className:`px-2 py-1 rounded ${a===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M15.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M8.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L4.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"})]})}),e.jsx("button",{onClick:N=>o(a-1,N),disabled:a===1,className:`px-2 py-1 rounded ${a===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"px-2 py-1 text-xs text-gray-800",children:["Page ",a," of ",k]}),e.jsx("button",{onClick:N=>o(a+1,N),disabled:a===k,className:`px-2 py-1 rounded ${a===k?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",clipRule:"evenodd"})})}),e.jsx("button",{onClick:N=>o(k,N),disabled:a===k,className:`px-2 py-1 rounded ${a===k?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M4.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L8.586 10 4.293 14.293a1 1 0 000 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M11.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L15.586 10l-4.293 4.293a1 1 0 000 1.414z",clipRule:"evenodd"})]})})]})]})},Mt=`
|
|
@keyframes highlight-pulse {
|
|
0% {
|
|
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5);
|
|
}
|
|
70% {
|
|
box-shadow: 0 0 0 15px rgba(59, 130, 246, 0);
|
|
}
|
|
100% {
|
|
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
|
|
}
|
|
}
|
|
|
|
.highlight-pulse {
|
|
animation: highlight-pulse 1.5s infinite;
|
|
border: 2px solid #3b82f6;
|
|
}
|
|
|
|
@keyframes fade-in-out {
|
|
0% { opacity: 0; transform: translateY(-20px); }
|
|
10% { opacity: 1; transform: translateY(0); }
|
|
90% { opacity: 1; transform: translateY(0); }
|
|
100% { opacity: 0; transform: translateY(-20px); }
|
|
}
|
|
|
|
.animate-fade-in-out {
|
|
animation: fade-in-out 3s forwards;
|
|
}
|
|
`,re="parameter_debug_state",We=t=>{try{localStorage.setItem(re,JSON.stringify(t))}catch(r){console.error("Error saving parameter debug state:",r)}},$t=()=>{try{const t=localStorage.getItem(re);if(t)return JSON.parse(t)}catch(t){console.error("Error loading parameter debug state:",t)}return null},Pt=()=>{try{localStorage.removeItem(re)}catch(t){console.error("Error clearing parameter debug state:",t)}},Et=(t,r,s,l,a,o)=>{const n=`${t}_${r}`;o(d=>{const m=[...d[n]||[]];return m[s]=l,{...d,[n]:m}});const i=[...a[n]||[]];return i[s]=l,i},_t=(t,r,s,l)=>{const a=`${t}_${r}`;return l(o=>{const n=[...o[a]||[]];return n.push(""),{...o,[a]:n}}),[...s[a]||[],""]},It=(t,r,s,l,a)=>{const o=`${t}_${r}`;a(i=>{const d=[...i[o]||[]];return d.splice(s,1),{...i,[o]:d}});const n=[...l[o]||[]];return n.splice(s,1),n},Ot=(t,r,s,l,a)=>{s.preventDefault(),s.stopPropagation();const o=`${t}_${r}`;a(n=>{if(n[o]&&typeof n[o]=="object"?n[o].isOpen:!!n[o])return{...n,[o]:!1};{let d=0,m=0;if(s.currentTarget){const g=s.currentTarget.getBoundingClientRect();d=g.left,m=g.bottom}else d=s.clientX,m=s.clientY+20;const u=window.innerWidth,x=250;return d+x>u&&(d=u-x-10),d<0&&(d=10),{...n,[o]:{isOpen:!0,x:d,y:m}}}})},Dt=(t,r,s,l,a)=>{a(o=>{const n={...o};return n[t]||(n[t]={}),n[t][r]=s,n})},At=(t,r,s,l,a,o)=>{o&&(o.preventDefault(),o.stopPropagation()),a(n=>{const i={...n};i[t]||(i[t]={}),i[t][r]||(i[t][r]=[]);const d=i[t][r];return d.includes(s)?i[t][r]=d.filter(m=>m!==s):i[t][r]=[...d,s],i})},Wt=(t,r,s,l,a)=>{const o=`${t}_${r}`;a(n=>({...n,[o]:s}))},Tt=(t,r,s,l,a)=>{if(!l[t]){a(t,r,s);return}const o=l[t][r]||[];s.length===o.length?a(t,r,[]):a(t,r,[...s])},Bt=(t,r,s,l,a,o)=>{o&&(o.preventDefault(),o.stopPropagation());const n=r[t];if(s(i=>({...i,[t]:!n})),n){const i={...l};Object.keys(i).forEach(d=>{i[d][t]&&delete i[d][t]}),a(i)}},Rt=(t,r,s,l,a,o,n)=>{n.preventDefault(),n.stopPropagation();const i={...r};if(r.nodeParams){const d={};Object.keys(r.nodeParams).forEach(m=>{const u=s.find(x=>x.id.toString()===m);d[m]=u?u.title||`Node ${m}`:`Node ${m}`}),i.nodeNames=d}else if(Object.keys(r).length>0){const d={};Object.entries(r).forEach(([m,u])=>{(typeof u!="object"||u===null)&&(d[m]=u)}),Object.keys(d).length>0&&(i.nodeParams={default:d},i.nodeNames={default:r.node_name||r.nodeName||"参数"})}l(t),a(i),o(!0)},zt=(t,r)=>{r&&(r.preventDefault(),r.stopPropagation()),t(!1)},Ft=(t,r,s,l,a,o,n,i,d,m,u)=>{if(u&&(u.preventDefault(),u.stopPropagation()),t===0){const x={...l};Object.keys(x).forEach(g=>{const f=x[g];Object.keys(f).forEach(b=>{s[b]||delete f[b]})}),a(x)}if(t===1){const x={...l};n.forEach(f=>{const b=f.id.toString(),$=f.widgets||{};Object.values($).forEach(k=>{const L=k.name;if(s[L]&&(k.type==="customtext"||k.type.toLowerCase().includes("text"))){const P=`${b}_${L}`,y=o[P]||[""];x[b]=x[b]||{},x[b][L]=y}})}),a(x);const g=m(x);i(g.length)}d(null),r(x=>Math.min(x+1,2))},Ht=(t,r,s,l,a,o,n,i,d,m)=>{if(m&&(m.preventDefault(),m.stopPropagation()),d(null),n&&i(!1),t===1){const u=s.map(f=>f.id.toString()),x=Object.keys(l),g={...l};x.forEach(f=>{u.includes(f)||delete g[f]}),a(g)}if(t===2||n){const u={...l};Object.entries(o).forEach(([x,g])=>{if(!g||g.length===0)return;const[f,b]=x.split("_");s.some($=>$.id.toString()===f)&&(u[f]=u[f]||{},JSON.stringify(u[f][b])!==JSON.stringify(g)&&(u[f][b]=g))}),a(u)}r(u=>Math.max(u-1,0))},Ut=(t,r,s,l,a)=>{a&&(a.preventDefault(),a.stopPropagation()),l(Math.max(1,Math.min(t,Math.ceil(s.length/r))))};function Gt(t,r){try{if(!t)return console.error("Invalid prompt_output: ",t),t;for(const s of r){if(!t[s.nodeId]){console.error(`Node with ID ${s.nodeId} not found`);continue}if(!t[s.nodeId].inputs){console.error(`Inputs not found for node with ID ${s.nodeId}`);continue}t[s.nodeId].inputs[s.paramName]=s.paramValue}return t}catch(s){return console.error("Error updating prompt:",s),t}}async function Jt(t){const r=await V.graphToPrompt(),s=Gt(r.output,t);console.log("queuePrompt updated_prompt:",s);const l={prompt:s,client_id:V.api.clientId,extra_data:{extra_pageinfo:{workflow:r.workflow}}};console.debug("queuePrompt request_body.prompt:",s);const a=await ft(l);return console.debug("queuePrompt response:",a),a}function Te(t){const r=document.createElement("canvas"),s=r.getContext("2d");if(r.width=512,r.height=512,s){s.fillStyle="#f8d7da",s.fillRect(0,0,r.width,r.height),s.strokeStyle="#dc3545",s.lineWidth=4,s.strokeRect(10,10,r.width-20,r.height-20),s.fillStyle="#dc3545",s.beginPath(),s.arc(r.width/2,150,50,0,2*Math.PI),s.fill(),s.fillStyle="white",s.font="bold 80px Arial",s.textAlign="center",s.textBaseline="middle",s.fillText("!",r.width/2,150),s.fillStyle="#721c24",s.font="20px Arial",s.textAlign="center",s.textBaseline="middle";const l=r.width-60,a=30,o=t.split(" ");let n="",i=250;for(let d=0;d<o.length;d++){const m=n+o[d]+" ";s.measureText(m).width>l&&d>0?(s.fillText(n,r.width/2,i),n=o[d]+" ",i+=a):n=m}s.fillText(n,r.width/2,i)}return r.toDataURL("image/png")}async function Kt(t){try{if(!t||t==="")return console.log("No prompt ID provided"),{1:[Te("Fail to generate prompt ID")]};const r=await bt(t);if(!r||!r[t])return console.log("Not finished for prompt ID:",t),{};const s=r[t];if(s.status&&s.status.status_str==="error"){console.error("Error for prompt ID:",t);const a=s.status.messages;if(a&&a.length>0){const o=a[a.length-1];if(o&&o.length>0){const n=o[0];return{1:[Te(n)]}}}}const l={};if(s.outputs)for(const a in s.outputs){const o=s.outputs[a];if(o&&o.images){l[a]=[];for(const n of o.images)if(n&&n.filename&&n.type){const i=V.graph._nodes_by_id[a].imgs[0].currentSrc.split("?")[0];l[a].push(i+"?filename="+encodeURIComponent(n.filename)+"&type="+encodeURIComponent(n.type)+(n.subfolder?"&subfolder="+encodeURIComponent(n.subfolder):""))}console.log("outputImages for nodeId:",a,l[a])}}return l}catch(r){throw console.error("Error getting output images from prompt:",r),r}}function qt(){const t=Object.values(V.graph._nodes_by_id),r=[],s=[];for(const l of t)l.type==="SaveImage"?r.push(l.id):l.type==="PreviewImage"&&s.push(l.id);if(console.log("saveNodeIds:",r),console.log("previewNodeIds:",s),r.length===0&&s.length===0)throw new Error("No SaveImage or PreviewImage node found, please add one to the graph");return r.length===1?r[0]:r.length==0&&s.length===1?s[0]:null}async function Vt(t,r){const s=await Kt(t);return Object.keys(s).length===0?null:s[r.toString()]&&s[r.toString()].length>0?s[r.toString()][0]:null}const Yt=async(t,r,s,l,a,o,n,i,d,m,u,x,g,f)=>{g&&(g.preventDefault(),g.stopPropagation()),He(m,d);const b=u(t),$=b.length;if($>100){a(`Cannot generate more than 100 images at once (currently: ${$} images)`);return}a(null),s(!0),l(0),console.log("Generated parameter combinations:",b);let k=null;try{k=(await x.graphToPrompt()).output}catch(N){console.error("Error capturing workflow data:",N)}if(se.trackEvent({event_type:"start_generation",message_type:"parameter_debug",message_id:r,data:{workflow:k,all_params:t,count:$}}),b.length===0){a("No valid parameter combinations found. Please check your parameter selections."),s(!1);return}let L=f||null;if(L===null){const N=qt();N!==null&&(L=N)}if(L===null){a("Please select a SaveImage or PreviewImage node first."),s(!1);return}const P={};Object.keys(t).forEach(N=>{const p=x.graph._nodes_by_id[N];p&&(P[N]=p.type||p.comfyClass||"Unknown Node")});const y=[];try{const N=Date.now().toString();d.current=N;for(const E of b){const R=await Jt(E);R.prompt_id?y.push(R.prompt_id):(console.error("Failed to get prompt_id from response:",R),y.push(""))}const p=Array(b.length).fill(null).map((E,R)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:St(t,R)}));o(p);const S=Date.now(),O=5*60*1e3,G=Object.keys(t)[0],j=P[G]||"Unknown Node";Fe(y,L,p,N,S,O,d,m,o,l,s,n,i,j,t,$,k,P)}catch(N){console.error("Error generating images:",N),s(!1)}},Fe=async(t,r,s,l,a,o,n,i,d,m,u,x,g,f,b,$,k,L)=>{if(n.current!==l){console.log("Another polling session has started, stopping this one");return}if(Date.now()-a>o){if(console.log("Timeout reached while waiting for images"),n.current===l&&(u(!1),x(!0),g(1),s.length>0&&f&&b)){const y=s[0].params;L&&(y.selectedNodeInfoMap=L),Ae(f,y,s,$||s.length,k)}return}let P=0;for(let y=0;y<t.length;y++){const N=t[y];if(N)try{const p=await Vt(N,Number(r));p&&(s[y]={...s[y],url:p},P++)}catch(p){console.error(`Error fetching image for prompt ID ${N}:`,p)}}if(d([...s]),m(P),P===t.length){if(console.log("All images have been generated!"),n.current===l&&(u(!1),x(!0),g(1),s.length>0&&f&&b)){const y=s[0].params;L&&(y.selectedNodeInfoMap=L),Ae(f,y,s,$||s.length,k)}return}n.current===l&&(i.current=setTimeout(()=>{Fe(t,r,s,l,a,o,n,i,d,m,u,x,g,f,b,$,k,L)},2e3))},He=(t,r)=>{t.current&&(clearTimeout(t.current),t.current=null),r.current=null},Xt=async(t,r,s,l,a,o)=>{if(!t.trim()){l("Please enter some text to generate variations");return}s(!0),l(null),a([]),o({});try{const n=await se.generateSDPrompts(t);a(n),se.trackEvent({event_type:"prompt_generate",message_type:"parameter_debug",message_id:r,data:{input_text:t,generated_texts:n}});const i={};n.forEach((d,m)=>{i[`text${m+1}`]=!1}),o(i)}catch(n){console.error("Error generating text:",n),l("Failed to generate text variations. Please try again.")}finally{s(!1)}},Qt=(t,r)=>{r(s=>({...s,[t]:!s[t]}))},Zt=(t,r,s,l,a,o,n,i,d,m)=>{const u=`${t}_${r}`,x=Object.entries(s).filter(([f,b])=>b).map(([f])=>{const b=parseInt(f.replace("text",""))-1;return l[b]});if(x.length===0)return;i(f=>{const b=[...f[u]||[]];return{...f,[u]:[...b,...x]}}),se.trackEvent({event_type:"prompt_apply",message_type:"parameter_debug",message_id:o,data:{input_text:a,generated_texts:l,selected_texts:x}});const g=[...n[u]||[],...x];d(t,r,g),m(!1)},es=(t,r,s,l,a,o,n,i,d,m)=>{s(!0),l(t),a(r),o(""),n([]),i({}),d(!1),m(null)},ts=(t,r,s,l,a,o,n,i,d,m,u,x,g,f,b,$,k,L,P,y,N,p,S,O,G,j,E,R,v,T=!1)=>{t(0),r({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),s(ie()),l(),a(!1),o(!1),n(0),i(12),d(null),m(Array(12).fill(null).map((I,_)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:_%3===0?5:_%3===1?10:15,sampler_name:"euler",cfg:1}}))),u({}),x({}),g({}),f({}),b(1),$(null),k(!1),L(!1),P(""),y(null),N({}),p(!1),S(""),O([]),G(!1),j(""),E(""),R(null),v({}),T&&Pt()},ss=(t,r,s)=>{s&&(s.preventDefault(),s.stopPropagation()),r(t)},rs=async(t,r,s,l,a,o,n)=>{if(n&&(n.preventDefault(),n.stopPropagation()),t!==null){console.log(`Applied image ${t+1} with parameters:`,r[t].params);let i=1;if(a){for(const m in a)if(a[m])for(const u in a[m]){const x=a[m][u];if(x){let g=1;Array.isArray(x)?g=x.length>0?x.length:1:typeof x=="object"&&x!==null&&(g=Object.keys(x).length>0?Object.keys(x).length:1),i=i*g}}}se.trackEvent({event_type:"parameter_debug_apply",message_type:"parameter_debug",message_id:l,data:{workflow:(await s.graphToPrompt()).output,selected_params:r[t].params,all_params:a,count:i}});const d=r[t].params;d.nodeParams&&(Object.entries(d.nodeParams).forEach(([m,u])=>{const x=s.graph._nodes_by_id[m];!x||!x.widgets||Object.entries(u).forEach(([g,f])=>{for(const b of x.widgets)if(b.name===g){b.value=f;break}})}),s.graph.setDirtyCanvas(!1,!0),o(!0),setTimeout(()=>{o(!1)},3e3))}},ns=(t,r,s,l,a,o,n)=>{if(n&&(n.preventDefault(),n.stopPropagation()),t===1&&s!==void 0){const i=[...r];i[s],i.splice(s,1),i.length===0?a&&(l({type:"SET_SCREEN_STATE",payload:null}),o(!0),a()):l({type:"SET_SELECTED_NODE",payload:i});return}a&&(l({type:"SET_SCREEN_STATE",payload:null}),o(!0),a())},os=({selectedNodes:t,visible:r,onClose:s})=>{const[l,a]=w.useState(0),[o,n]=w.useState({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),[i,d]=w.useState(ie()),[m,u]=w.useState(!1),[x,g]=w.useState(!1),[f,b]=w.useState(0),[$,k]=w.useState(12),[L,P]=w.useState(null),[y,N]=w.useState(()=>Array(12).fill(null).map((c,h)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:h%3===0?5:h%3===1?10:15,sampler_name:"euler",cfg:1}}))),[p,S]=w.useState({}),[O,G]=w.useState({}),[j,E]=w.useState({}),[R,v]=w.useState({}),[T,I]=w.useState(1),_=6,[B,z]=w.useState(null),[C,F]=w.useState(!1),[M,D]=w.useState(!1),[A,H]=w.useState(""),[U,J]=w.useState(null),[q,Y]=w.useState({}),[Ue,ne]=w.useState(!1),[ce,de]=w.useState(""),[we,xe]=w.useState([]),[Ge,me]=w.useState(!1),[Je,ke]=w.useState(""),[Ke,Se]=w.useState(""),[qe,ue]=w.useState(null),[Ce,oe]=w.useState({}),[he,ge]=w.useState(!1),[Ve,Ye]=w.useState([]),[Le,pe]=w.useState(null),{dispatch:fe}=ve(),Me=w.useRef(null),$e=w.useRef(null),[Xe,ae]=w.useState(()=>r);w.useEffect(()=>{if(he){const c=Re();Ye(c)}},[he]);const Qe=async()=>{Xt(ce,i,me,ue,xe,oe)},Ze=(c,h,W,K)=>{const Z=Et(c,h,W,K,q,Y);X(c,h,Z)},et=(c,h)=>{const W=_t(c,h,q,Y);X(c,h,W)},tt=(c,h,W)=>{const K=It(c,h,W,q,Y);X(c,h,K)},st=c=>{Qt(c,oe)},rt=()=>{Zt(Je,Ke,Ce,we,ce,i,q,Y,X,ne)},nt=(c,h)=>{es(c,h,ne,ke,Se,de,xe,oe,me,ue)},Pe=c=>{c&&(c.preventDefault(),c.stopPropagation()),ge(h=>!h)},ot=c=>{pe(c),ge(!1),N(c.generatedImages||[]),P(null),I(1)},at=c=>{c&&(c.preventDefault(),c.stopPropagation()),pe(null)};w.useEffect(()=>{if(!t||t.length===0)return;const c={...p},h=t.map(K=>K.id.toString());Object.keys(c).forEach(K=>{h.includes(K)||delete c[K]}),t.forEach(K=>{const Z=K.id.toString();c[Z]||(c[Z]={})}),JSON.stringify(c)!==JSON.stringify(p)&&S(c)},[t,p]),w.useEffect(()=>{fe({type:"SET_SCREEN_STATE",payload:{currentScreen:l,isProcessing:m,isCompleted:x}})},[l,m,x,fe]),w.useEffect(()=>{const c=document.createElement("style");return c.textContent=Mt,document.head.appendChild(c),()=>{document.head.removeChild(c)}},[]),w.useEffect(()=>{const c=h=>{if(Object.values(O).some(W=>W)){const W=h.target,K=!!W.closest(".dropdown-menu"),Z=!!W.closest("[data-dropdown]");!K&&!Z&&G({})}};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c)}},[O]),w.useEffect(()=>{r&&(JSON.parse(localStorage.getItem(re)||"{}").task_id||d(ie()))},[r]),w.useEffect(()=>{if(r){ae(!0);try{const c=localStorage.getItem(re);if(c){const h=JSON.parse(c);if(!t||t.length===0){console.log("Not restoring parameter debug state: no nodes selected"),ae(!1);return}h.currentScreen!==void 0&&a(h.currentScreen),h.selectedParams&&n(h.selectedParams),h.task_id&&d(h.task_id);const W=h.generatedImages&&h.generatedImages.length>0;h.isProcessing!==void 0&&!h.isProcessing&&u(!1),h.isCompleted!==void 0&&W&&g(h.isCompleted),h.completedCount!==void 0&&b(h.completedCount),h.totalCount!==void 0&&k(h.totalCount),h.selectedImageIndex!==void 0&&P(h.selectedImageIndex),h.generatedImages&&N(h.generatedImages),h.paramTestValues&&S(h.paramTestValues),h.searchTerms&&E(h.searchTerms),h.inputValues&&v(h.inputValues),h.currentPage!==void 0&&I(h.currentPage),h.textInputs&&Y(h.textInputs)}}catch(c){console.error("Error loading parameter debug state:",c)}finally{setTimeout(()=>{ae(!1)},50)}}else ae(!0);return()=>{if(!r)return;We({currentScreen:l,selectedParams:o,task_id:i,isProcessing:m,isCompleted:x,completedCount:f,totalCount:$,selectedImageIndex:L,generatedImages:y,paramTestValues:p,searchTerms:j,inputValues:R,currentPage:T,textInputs:q})}},[r]);const lt=(c=!1)=>{ts(a,n,d,ye,u,g,b,k,P,N,S,G,E,v,I,z,F,D,H,J,Y,ne,de,xe,me,ke,Se,ue,oe,c),ge(!1),pe(null)};w.useEffect(()=>{if(!r)return;const c=setTimeout(()=>{We({currentScreen:l,selectedParams:o,task_id:i,isProcessing:m,isCompleted:x,completedCount:f,totalCount:$,selectedImageIndex:L,generatedImages:y,paramTestValues:p,searchTerms:j,inputValues:R,currentPage:T,textInputs:q})},500);return()=>clearTimeout(c)},[r,l,o,i,m,x,f,$,L,y,p,j,R,T,q]);const Ee=c=>{Ft(l,a,o,p,S,q,t,k,z,je,c)},be=c=>{Ht(l,a,t,p,S,q,x,g,z,c)},it=(c,h)=>{Bt(c,o,n,p,S,h)},ct=(c,h,W)=>{Ot(c,h,W,O,G)},X=(c,h,W)=>{Dt(c,h,W,p,S)},dt=(c,h,W,K)=>{At(c,h,W,p,S,K)},xt=(c,h,W)=>{Wt(c,h,W,j,E)},mt=(c,h,W)=>{Tt(c,h,W,p,X)},_e=(c,h)=>{Ut(c,_,y,I,h)},ye=()=>{He(Me,$e)};w.useEffect(()=>()=>{ye()},[]);const ut=async(c,h)=>{Yt(p,i,u,b,z,N,g,I,$e,Me,je,V,c,h)},Ie=(c,h)=>{ss(c,P,h)},Oe=(c,h,W)=>{Rt(c,h,t,H,J,D,W)},ee=c=>{zt(D,c)},ht=async c=>{rs(L,y,V,i,p,F,c)},Q=(c,h)=>{ns(l,t,h,fe,s,lt,c)},le=()=>e.jsx(e.Fragment,{children:e.jsx(te,{visible:M,imageUrl:A,params:U||{},onClose:ee})});return Le?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:c=>c.stopPropagation(),children:e.jsx(Lt,{historyItem:Le,selectedImageIndex:L,handleSelectImage:Ie,handleClose:at,currentPage:T,handlePageChange:_e,imagesPerPage:_,modalVisible:M,modalImageUrl:A,modalImageParams:U,openImageModal:Oe,closeImageModal:ee})}):he?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:c=>c.stopPropagation(),children:e.jsx(Ct,{historyItems:Ve,onViewHistoryItem:ot,onClose:Pe})}):Xe&&r&&t.length>0?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:c=>c.stopPropagation(),children:[e.jsxs("div",{className:"p-8 rounded-lg shadow-sm relative flex flex-col items-center",children:[e.jsx("div",{className:"w-8 h-8 border-4 border-blue-500 border-t-transparent rounded-full animate-spin"}),e.jsx("div",{className:"mt-4 text-gray-600 text-sm",children:"Loading interface..."})]}),e.jsx(te,{visible:M,imageUrl:A,params:U||{},onClose:ee})]}):!r||t.length===0?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:c=>c.stopPropagation(),children:[e.jsxs("div",{className:"max-w-lg p-8 rounded-lg shadow-sm border border-blue-100 relative",children:[e.jsxs("div",{className:"absolute top-3 right-3 flex",children:[e.jsx("button",{className:"text-blue-500 hover:text-blue-700 mr-2",onClick:Pe,title:"Show History",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z",clipRule:"evenodd"})})}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:Q,children:e.jsx("svg",{className:"h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"mb-6 text-center",children:[e.jsx("h3",{className:"text-base font-bold text-blue-600 mb-2",children:"GenLab"}),e.jsx("div",{className:"h-1 w-16 bg-blue-500 mx-auto rounded-full mb-4"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-left mb-4",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-800 mb-3",children:"Batch-test parameters & find the best combo in one click."}),e.jsx("div",{className:"h-px w-full bg-gray-200 my-4"})]}),e.jsxs("div",{className:"text-left",children:[e.jsx("h4",{className:"text-base font-medium text-gray-800 mb-4",children:"How to use"}),e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs("p",{className:"text-sm text-gray-700",children:[e.jsx("span",{className:"font-bold",children:"1 - "}),"Click any node(hold Shift to select multiple nodes)"]}),e.jsxs("p",{className:"text-sm text-gray-700",children:[e.jsx("span",{className:"font-bold",children:"2 - "}),"Set parameter ranges and start batch generation."]})]}),e.jsx("div",{className:"h-px w-full bg-gray-200 my-4"}),e.jsx("p",{className:"text-sm text-blue-600 mt-6",children:"Let's select a node to begin!"})]})]})]}),e.jsx(te,{visible:M,imageUrl:A,params:U||{},onClose:ee})]}):x?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:c=>c.stopPropagation(),children:e.jsx(wt,{generatedImages:y,selectedImageIndex:L,handleSelectImage:Ie,handleApplySelected:ht,handlePrevious:be,handleClose:Q,currentPage:T,handlePageChange:_e,imagesPerPage:_,notificationVisible:C,modalVisible:M,modalImageUrl:A,modalImageParams:U,openImageModal:Oe,closeImageModal:ee})}):m?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:c=>c.stopPropagation(),children:[e.jsx(Nt,{selectedNodes:t,paramTestValues:p,selectedParams:o,totalCount:$,completedCount:f,errorMessage:B,handleClose:Q,setIsProcessing:u,setCurrentScreen:a,cleanupPolling:ye}),e.jsx(le,{})]}):l===0?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:c=>c.stopPropagation(),children:[e.jsx(yt,{selectedNodes:t,handleParamSelect:it,selectedParams:o,handleNext:Ee,handleClose:Q}),e.jsx(le,{})]}):l===1?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:c=>c.stopPropagation(),children:[e.jsx(jt,{selectedNodes:t,paramTestValues:p,selectedParams:o,updateParamTestValues:X,toggleDropdown:ct,openDropdowns:O,handleTestValueSelect:dt,searchTerms:j,handleSearch:xt,handleSelectAll:mt,handleNext:Ee,handlePrevious:be,handleClose:Q,inputValues:R,setInputValues:v,textInputs:q,handleTextInputChange:Ze,handleAddTextInput:et,handleRemoveTextInput:tt,openAiWritingModal:nt}),e.jsx(kt,{visible:Ue,aiWritingModalText:ce,setAiWritingModalText:de,aiGeneratedTexts:we,aiSelectedTexts:Ce,aiWritingLoading:Ge,aiWritingError:qe,handleAiWriting:Qe,toggleTextSelection:st,addSelectedTexts:rt,onClose:()=>ne(!1)}),e.jsx(le,{})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:c=>c.stopPropagation(),children:[e.jsx(vt,{selectedNodes:t,paramTestValues:p,selectedParams:o,totalCount:$,errorMessage:B,handlePrevious:be,handleStartGeneration:ut,handleClose:Q}),e.jsx(le,{})]})},ms=t=>{const{dispatch:r}=ve(),[s,l]=w.useState(!1);return w.useEffect(()=>{if(t.visible&&!s){const a=$t();a&&a.screenState&&r({type:"SET_SCREEN_STATE",payload:{currentScreen:a.currentScreen,isProcessing:a.isProcessing,isCompleted:a.isCompleted}}),l(!0)}},[t.visible,s,r]),w.useEffect(()=>()=>{t.visible||r({type:"SET_SCREEN_STATE",payload:null})},[t.visible,r]),e.jsx(os,{...t})};export{ms as ParameterDebugInterface};
|