Files
AIDC-AI-ComfyUI-Copilot/dist/copilot_web/ParameterDebugInterfaceNew--d3dp9od.js
T

30 lines
50 KiB
JavaScript

import{j as e}from"./vendor-markdown-Dek94WS0.js";import{r as b}from"./vendor-react-V04_Axys.js";import{r as Qe,g as Xe,m as Ze,i as et}from"./workflowChat-DFouB6P4.js";import{a as Z,u as Ie,W as Me,g as tt}from"./message-components-B3k4U96-.js";import"./input.js";import"./App-CCFLr34u.js";function st(l,n){try{if(!l)return console.error("Invalid prompt_output: ",l),l;for(const r of n){if(!l[r.nodeId]){console.error(`Node with ID ${r.nodeId} not found`);continue}if(!l[r.nodeId].inputs){console.error(`Inputs not found for node with ID ${r.nodeId}`);continue}l[r.nodeId].inputs[r.paramName]=r.paramValue}return l}catch(r){return console.error("Error updating prompt:",r),l}}async function rt(l){const n=await Z.graphToPrompt(),r=st(n.output,l);console.log("queuePrompt updated_prompt:",r);const u={prompt:r,client_id:Z.api.clientId,extra_data:{extra_pageinfo:{workflow:n.workflow}}};console.debug("queuePrompt request_body.prompt:",r);const h=await Qe(u);return console.debug("queuePrompt response:",h),h}function Pe(l){const n=document.createElement("canvas"),r=n.getContext("2d");if(n.width=512,n.height=512,r){r.fillStyle="#f8d7da",r.fillRect(0,0,n.width,n.height),r.strokeStyle="#dc3545",r.lineWidth=4,r.strokeRect(10,10,n.width-20,n.height-20),r.fillStyle="#dc3545",r.beginPath(),r.arc(n.width/2,150,50,0,2*Math.PI),r.fill(),r.fillStyle="white",r.font="bold 80px Arial",r.textAlign="center",r.textBaseline="middle",r.fillText("!",n.width/2,150),r.fillStyle="#721c24",r.font="20px Arial",r.textAlign="center",r.textBaseline="middle";const u=n.width-60,h=30,d=l.split(" ");let c="",g=250;for(let f=0;f<d.length;f++){const M=c+d[f]+" ";r.measureText(M).width>u&&f>0?(r.fillText(c,n.width/2,g),c=d[f]+" ",g+=h):c=M}r.fillText(c,n.width/2,g)}return n.toDataURL("image/png")}async function nt(l){try{if(!l||l==="")return console.log("No prompt ID provided"),{1:[Pe("Fail to generate prompt ID")]};const n=await Xe(l);if(!n||!n[l])return console.log("Not finished for prompt ID:",l),{};const r=n[l];if(r.status&&r.status.status_str==="error"){console.error("Error for prompt ID:",l);const h=r.status.messages;if(h&&h.length>0){const d=h[h.length-1];if(d&&d.length>0){const c=d[0];return{1:[Pe(c)]}}}}const u={};if(r.outputs)for(const h in r.outputs){const d=r.outputs[h];if(d&&d.images){u[h]=[];for(const c of d.images)if(c&&c.filename&&c.type){const g=Z.graph._nodes_by_id[h].imgs[0].currentSrc.split("?")[0];u[h].push(g+"?filename="+encodeURIComponent(c.filename)+"&type="+encodeURIComponent(c.type)+(c.subfolder?"&subfolder="+encodeURIComponent(c.subfolder):""))}console.log("outputImages for nodeId:",h,u[h])}}return u}catch(n){throw console.error("Error getting output images from prompt:",n),n}}function ot(){const l=Object.values(Z.graph._nodes_by_id),n=[],r=[];for(const u of l)u.type==="SaveImage"?n.push(u.id):u.type==="PreviewImage"&&r.push(u.id);if(console.log("saveNodeIds:",n),console.log("previewNodeIds:",r),n.length===0&&r.length===0)throw new Error("No SaveImage or PreviewImage node found, please add one to the graph");return n.length===1?n[0]:n.length==0&&r.length===1?r[0]:null}async function at(l,n){const r=await nt(l);return Object.keys(r).length===0?null:r[n.toString()]&&r[n.toString()].length>0?r[n.toString()][0]:null}const lt=({selectedNodes:l,handleParamSelect:n,selectedParams:r,handleNext:u,handleClose:h})=>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 for Testing"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Choose the parameters you want to include in your batch test"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:h,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"})})})]}),l.map((d,c)=>{const g=d.title||"Unknown Node",f=d.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:g}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:f.map((M,L)=>{const S=M.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 ${r[S]?"border-red-500 bg-red-100":"border-gray-300"}`,onClick:W=>n(S,W),children:r[S]&&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:S})]},`widget-${L}`)})})})]},`node-${c}`)}),e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx("button",{onClick:d=>u(d),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})})]}),it=({selectedNodes:l,paramTestValues:n,selectedParams:r,updateParamTestValues:u,toggleDropdown:h,openDropdowns:d,handleTestValueSelect:c,searchTerms:g,handleSearch:f,handleSelectAll:M,handleNext:L,handlePrevious:S,handleClose:W,inputValues:K,setInputValues:A,textInputs:B,handleTextInputChange:_,handleAddTextInput:T,handleRemoveTextInput:j,openAiWritingModal:w})=>{const C=(v,P,V,q=0)=>{if(v=isNaN(v)?0:v,P=isNaN(P)?100:P,V=isNaN(V)||V<=0?1:V,P<v&&(P=v),Math.floor((P-v)/V)+1<=1)return[v];const I=[];let Y=v;for(;Y<=P;){const x=Math.pow(10,q),F=Math.round(Y*x)/x;I.push(F),Y+=V}return I};return b.useEffect(()=>{!l||l.length===0||l.forEach(v=>{const P=v.id.toString(),V=v.widgets||{};Object.values(V).forEach(m=>{const I=m.name;if(!r[I])return;if(!(n[P]?.[I]?.length>0)&&m.type==="number"){const x=m.options?.min||0,F=m.options?.max||100,D=(m.options?.step||10)/10,N=m.options?.precision||0,p=C(x,F,D,N);if(p.length>0){u(P,I,p);const G=`${P}_${I}`;A(H=>({...H,[G]:{min:x.toString(),max:F.toString(),step:D.toString()}}))}}if(m.type==="customtext"||m.type.toLowerCase().includes("text")){const x=`${P}_${I}`,F=B[x]||[""];JSON.stringify(F)!==JSON.stringify(n[P]?.[I]||[""])&&u(P,I,F)}})})},[l,r,n,B,u,A,C]),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:"Parameter Options"}),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:W,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"})})})]}),l.length>0?l.map((v,P)=>{const V=v.widgets||{},q=Object.values(V),m=v.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:[v.type," (ID: ",m,")"]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:I=>W(I,P),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:q.map((I,Y)=>{const x=I.name;if(!r[x])return null;const F=`${m}_${x}`;if(I.type==="customtext"||I.type.toLowerCase().includes("text")){const D=B[F]||[""];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:[x,":"]}),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:()=>w(m,x),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:D.map((N,p)=>e.jsxs("div",{className:"flex items-start",children:[e.jsx("textarea",{className:"flex-1 border border-gray-300 rounded p-2 text-xs resize-y",rows:2,placeholder:"Enter text...",value:N,onChange:G=>_(m,x,p,G.target.value)}),e.jsx("button",{className:"ml-2 text-red-500 hover:text-red-700",onClick:()=>j(m,x,p),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"})})})]},p))}),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:()=>T(m,x),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"]})]},Y)}if(I.type==="number"){const D=I.options?.min||0,N=I.options?.max||100,p=(I.options?.step||10)/10,G=I.options?.precision||0,H=C(D,N,p,G),J=K[F]||{min:D.toString(),max:N.toString(),step:p.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:[x,":"]}),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:J.min,onClick:E=>{E.preventDefault(),E.stopPropagation()},onChange:E=>{E.preventDefault(),E.stopPropagation();const O=E.target.value;if(A($=>({...$,[F]:{...$[F],min:O}})),O===""||!isNaN(parseFloat(O))){const $=O===""?0:parseFloat(O),R=parseFloat(J.max||N.toString()),Q=parseFloat(J.step||p.toString()),U=C($,R,Q,G);u(m,x,U)}}}),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:J.max,onClick:E=>{E.preventDefault(),E.stopPropagation()},onChange:E=>{E.preventDefault(),E.stopPropagation();const O=E.target.value;if(A($=>({...$,[F]:{...$[F],max:O}})),O===""||!isNaN(parseFloat(O))){const $=parseFloat(J.min||D.toString()),R=O===""?$:parseFloat(O),Q=parseFloat(J.step||p.toString()),U=C($,R,Q,G);u(m,x,U)}}}),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:J.step,onClick:E=>{E.preventDefault(),E.stopPropagation()},onChange:E=>{E.preventDefault(),E.stopPropagation();const O=E.target.value;if(A($=>({...$,[F]:{...$[F],step:O}})),O===""||!isNaN(parseFloat(O))&&parseFloat(O)>0){const $=parseFloat(J.min||D.toString()),R=parseFloat(J.max||N.toString()),Q=O===""?1:parseFloat(O),U=C($,R,Q,G);u(m,x,U)}}})]}),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 E=n[m]?.[x]||H;if(E.length<=10)return E.map((O,$)=>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:R=>{R.stopPropagation(),c(m,x,O,R)},children:[e.jsx("span",{children:O}),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"})})]},$));{const O=E.slice(0,5),$=E.slice(E.length-5);return e.jsxs(e.Fragment,{children:[O.map((R,Q)=>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:U=>{U.stopPropagation(),c(m,x,R,U)},children:[e.jsx("span",{children:R}),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-${Q}`)),e.jsx("div",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 rounded-md flex items-center text-xs",children:"..."}),$.map((R,Q)=>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:U=>{U.stopPropagation(),c(m,x,R,U)},children:[e.jsx("span",{children:R}),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-${Q}`))]})}})()})]}),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"})})]},Y)}else if(I.type==="combo"){const D=I.options?.values||[],N=`${m}_${x}`;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:x}),e.jsxs("div",{className:"relative dropdown-container",children:[e.jsxs("button",{className:"appearance-none border border-gray-300 rounded px-2 py-0.5 pr-6 text-xs flex items-center bg-white text-gray-700",onClick:p=>{p.preventDefault(),p.stopPropagation(),h(m,x,p)},"data-dropdown":N,children:[e.jsx("span",{children:(n[m]?.[x]||[]).length>0?`${x}: ${(n[m]?.[x]||[]).length} selected`:`Select ${x}`}),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"})})})]}),d[N]&&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 d[N]=="object"?`${d[N].y}px`:"0px",left:typeof d[N]=="object"?`${d[N].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:g[N]||"",onChange:p=>{p.preventDefault(),p.stopPropagation(),f(m,x,p.target.value)},onClick:p=>{p.preventDefault(),p.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:p=>{p.preventDefault(),p.stopPropagation();const G=D.filter(H=>!g[N]||H.toLowerCase().includes((g[N]||"").toLowerCase()));M(m,x,G)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${D.length>0&&(n[m]?.[x]||[]).length===D.length?"bg-blue-500 border-blue-500":(n[m]?.[x]||[]).length>0?"bg-blue-500 border-blue-500 opacity-50":"border-gray-300"}`,children:(n[m]?.[x]||[]).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:D.length>0&&(n[m]?.[x]||[]).length===D.length?"Deselect All":"Select All"})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[D.filter(p=>!g[N]||p.toLowerCase().includes((g[N]||"").toLowerCase())).map((p,G)=>e.jsxs("div",{className:"px-3 py-1.5 hover:bg-gray-100 cursor-pointer text-xs flex items-center text-gray-700",onClick:H=>{H.preventDefault(),H.stopPropagation(),c(m,x,p,H)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${(n[m]?.[x]||[]).includes(p)?"bg-blue-500 border-blue-500":"border-gray-300"}`,children:(n[m]?.[x]||[]).includes(p)&&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:p})]},G)),D.filter(p=>!g[N]||p.toLowerCase().includes((g[N]||"").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"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(n[m]?.[x]||[]).map((p,G)=>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:p}),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:H=>{H.preventDefault(),H.stopPropagation(),c(m,x,p,H)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},G))})]})]},Y)}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:x})}),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:[(n[m]?.[x]||[]).map((D,N)=>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:D}),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:p=>{p.preventDefault(),p.stopPropagation(),c(m,x,D,p)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},N)),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:D=>{D.preventDefault(),D.stopPropagation();const N=`${x}${(n[m]?.[x]||[]).length+1}`;u(m,x,[...n[m]?.[x]||[],N])},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"})]})]})]})]},Y)})})]},P)}):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:v=>S(v),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:v=>L(v),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})]})]})},ct=({selectedNodes:l,paramTestValues:n,selectedParams:r,totalCount:u,errorMessage:h,handlePrevious:d,handleStartGeneration:c,handleClose:g})=>{const[f,M]=b.useState([]),[L,S]=b.useState(null),[W,K]=b.useState(!1);Ie();const A=()=>{const _=Object.values(Z.graph._nodes_by_id),T=[],j=[];for(const C of _)C.type==="SaveImage"?T.push(C.id):C.type==="PreviewImage"&&j.push(C.id);const w=[...T,...j];M(w),w.length===1?S(w[0]):w.length>1&&(K(!0),S(null))};b.useEffect(()=>{A()},[]),b.useEffect(()=>{const _=()=>{if(!Z.canvas.selected_nodes)return;const T=Object.values(Z.canvas.selected_nodes);if(T.length===0)return;const j=T[0];j&&(j.type==="SaveImage"||j.type==="PreviewImage")&&(console.log("Selected image node:",j.id),S(j.id))};return document.addEventListener("click",_),()=>{document.removeEventListener("click",_)}},[]);const B=_=>{if(_&&(_.preventDefault(),_.stopPropagation()),f.length>1&&!L){K(!0);return}c(_,L||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:"Confirm Test Configuration"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",u," total runs. Each run will generate a separate image."]})]}),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"})})})]}),W&&f.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:L===null?`Multiple SaveImage and PreviewImage nodes detected with IDs ${f.join(",")}. Please click the node on canvas.`:`Current node ID is ${L}, please click Start Generation again`})]})}),h&&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:h})]})}),l.length>0?l.map((_,T)=>{const j=_.type||"Unknown Node",w=_.widgets||[],C=_.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:[j," (ID: ",C,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:w.map((v,P)=>{const V=v.name;if(!r[V])return null;const q=n[C]?.[V]||[],m=Array.isArray(q)?`[${q.join(", ")}]`:JSON.stringify(q);return e.jsxs("div",{className:P<w.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:V}),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:m,onClick:I=>I.preventDefault()})})]},P)})})]},T)}):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:_=>d(_),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:_=>B(_),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${f.length>1&&!L?"bg-gray-200 text-gray-500 cursor-not-allowed":"bg-pink-200 text-pink-700 hover:bg-pink-300"}`,disabled:f.length>1&&!L,children:"Start Generation"})]})]})},dt=({selectedNodes:l,paramTestValues:n,selectedParams:r,totalCount:u,completedCount:h,errorMessage:d,handleClose:c,setIsProcessing:g,setCurrentScreen:f,cleanupPolling:M})=>{const L=S=>{S.preventDefault(),S.stopPropagation(),Ze({clear:!0}),et(),M&&M(),g(!1),f(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 ",h," of ",u," 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:`${h/u*100}%`}})}),e.jsxs("div",{className:"mt-2 text-xs text-gray-600",children:["Already generated ",h," images"]}),e.jsx("button",{onClick:L,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 ",u," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:c,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"})})})]}),d&&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:d})]})}),l.length>0?l.map((S,W)=>{const K=S.type||"Unknown Node",A=S.widgets||[],B=S.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:[K," (ID: ",B,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:A.map((_,T)=>{const j=_.name;if(!r[j])return null;const w=n[B]?.[j]||[],C=Array.isArray(w)?`[${w.join(", ")}]`:JSON.stringify(w);return e.jsxs("div",{className:T<A.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:j}),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:C,onClick:v=>v.preventDefault()})})]},T)})})]},W)}):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."})]})},xt=({generatedImages:l,selectedImageIndex:n,handleSelectImage:r,handleApplySelected:u,handlePrevious:h,handleClose:d,currentPage:c,handlePageChange:g,imagesPerPage:f,notificationVisible:M,modalVisible:L,modalImageUrl:S,openImageModal:W,closeImageModal:K})=>{const A=Math.ceil(l.length/f),B=(c-1)*f,_=Math.min(B+f,l.length),T=l.slice(B,_);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 ",l.length," images have been generated."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:d,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."})]})}),L&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50",onClick:K,children:e.jsxs("div",{className:"bg-white rounded-lg p-2 max-w-4xl max-h-[90vh] relative",onClick:j=>j.stopPropagation(),children:[e.jsx("button",{className:"absolute top-2 right-2 text-gray-700 hover:text-gray-900 rounded-full hover:bg-gray-200 p-1",onClick:K,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:"overflow-auto max-h-[calc(90vh-4rem)]",children:e.jsx("img",{src:S,alt:"Enlarged image",className:"max-w-full h-auto"})})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:T.map((j,w)=>{const C=B+w;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${n===C?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:v=>r(C,v),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:v=>W(j.url,v),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:j.url,alt:`Generated image ${C+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(j.params).filter(([v,P])=>v!=="nodeParams"&&typeof P!="object").map(([v,P])=>e.jsxs("div",{children:[v,": ",String(P)]},v))})]},C)})}),A>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:j=>g(1,j),disabled:c===1,className:`px-2 py-1 rounded ${c===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:j=>g(c-1,j),disabled:c===1,className:`px-2 py-1 rounded ${c===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 ",c," of ",A]}),e.jsx("button",{onClick:j=>g(c+1,j),disabled:c===A,className:`px-2 py-1 rounded ${c===A?"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:j=>g(A,j),disabled:c===A,className:`px-2 py-1 rounded ${c===A?"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.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:j=>h(j),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:j=>u(j),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",disabled:n===null,children:"Apply Selected"})]})]})},ut=({visible:l,aiWritingModalText:n,setAiWritingModalText:r,aiGeneratedTexts:u,aiSelectedTexts:h,aiWritingLoading:d,aiWritingError:c,handleAiWriting:g,toggleTextSelection:f,addSelectedTexts:M,onClose:L})=>l?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-medium",children:"AI Writing Assistant"}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",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.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-600 mb-2",children:"Enter text and AI will generate variations"}),e.jsx("textarea",{className:"w-full border border-gray-300 rounded-md p-2 text-sm",rows:3,placeholder:"Enter some text here...",value:n,onChange:S=>r(S.target.value)}),e.jsx("button",{className:"mt-2 px-4 py-2 bg-blue-100 text-blue-700 rounded-md text-sm flex items-center hover:bg-blue-200 transition-colors",onClick:g,disabled:d,children:d?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-blue-700",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"})})]}),c&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-sm",children:c}),u.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm font-medium 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:u.map((S,W)=>e.jsxs("div",{className:"flex items-start border border-gray-200 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${W+1}`,checked:!!h[`text${W+1}`],onChange:()=>f(`text${W+1}`),className:"sr-only"}),e.jsx("div",{className:`h-4 w-4 rounded border ${h[`text${W+1}`]?"bg-blue-600 border-blue-600":"bg-white border-gray-300"} flex items-center justify-center`,onClick:()=>f(`text${W+1}`),children:h[`text${W+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${W+1}`,className:"text-sm text-gray-700 cursor-pointer flex-1",children:S})]},W))})]})]}),e.jsxs("div",{className:"p-4 border-t flex justify-end flex-shrink-0",children:[e.jsx("button",{className:"px-4 py-2 bg-gray-100 text-gray-700 rounded-md text-sm mr-2 hover:bg-gray-200 transition-colors",onClick:L,children:"Cancel"}),e.jsx("button",{className:"px-4 py-2 bg-blue-500 text-white rounded-md text-sm hover:bg-blue-600 transition-colors",onClick:M,disabled:Object.values(h).every(S=>!S),children:"Add Selected"})]})]})}):null,ye=l=>{const n=[],r={};if(Object.keys(l).forEach(d=>{const c=parseInt(d),g=l[d]||{},f=Object.keys(g).filter(L=>g[L]&&g[L].length>0);if(f.length===0)return;const M=[[]];f.forEach(L=>{const S=g[L],W=[];M.forEach(K=>{S.forEach(A=>{const B=[...K,{nodeId:c,paramName:L,paramValue:String(A)}];W.push(B)})}),M.length=0,M.push(...W)}),r[d]=M}),Object.keys(r).length===0)return n;if(Object.keys(r).length===1){const d=Object.keys(r)[0];return r[d]}const u=Object.keys(r);let h=r[u[0]];for(let d=1;d<u.length;d++){const c=r[u[d]],g=[];h.forEach(f=>{c.forEach(M=>{g.push([...f,...M])})}),h=g}return h},mt=(l,n)=>{const r={};r.nodeParams={};const u=ye(l);return n<u.length&&u[n].forEach(d=>{const c=d.nodeId.toString(),g=d.paramName,f=d.paramValue;r.nodeParams[c]||(r.nodeParams[c]={}),r.nodeParams[c][g]=f,r[g]=f}),r},ht=`
@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;
}
`,vt=({selectedNodes:l,visible:n,onClose:r})=>{const[u,h]=b.useState(0),[d,c]=b.useState({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),[g,f]=b.useState(!1),[M,L]=b.useState(!1),[S,W]=b.useState(0),[K,A]=b.useState(12),[B,_]=b.useState(null),[T,j]=b.useState(()=>Array(12).fill(null).map((t,s)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:s%3===0?5:s%3===1?10:15,sampler_name:"euler",cfg:1}}))),[w,C]=b.useState({}),[v,P]=b.useState({}),[V,q]=b.useState({}),[m,I]=b.useState({}),[Y,x]=b.useState(1),F=6,[D,N]=b.useState(null),[p,G]=b.useState(!1),[H,J]=b.useState(!1),[E,O]=b.useState(""),[$,R]=b.useState({}),[Q,U]=b.useState(!1),[pe,ge]=b.useState(""),[ve,de]=b.useState([]),[Ee,xe]=b.useState(!1),[we,Ne]=b.useState(""),[ke,Ce]=b.useState(""),[$e,ne]=b.useState(null),[Se,oe]=b.useState({}),{dispatch:ae}=Ie(),ue=b.useRef(null),le=b.useRef(null),We=async()=>{if(!pe.trim()){ne("Please enter some text to generate variations");return}xe(!0),ne(null),de([]),oe({});try{const t=await Me.generateSDPrompts(pe);de(t);const s={};t.forEach((i,o)=>{s[`text${o+1}`]=!1}),oe(s)}catch(t){console.error("Error generating text:",t),ne("Failed to generate text variations. Please try again.")}finally{xe(!1)}},_e=(t,s,i,o)=>{const a=`${t}_${s}`;R(y=>{const z=[...y[a]||[]];return z[i]=o,{...y,[a]:z}});const k=[...$[a]||[]];k[i]=o,ee(t,s,k)},De=(t,s)=>{const i=`${t}_${s}`;R(a=>{const k=[...a[i]||[]];return k.push(""),{...a,[i]:k}});const o=[...$[i]||[],""];ee(t,s,o)},Oe=(t,s,i)=>{const o=`${t}_${s}`;R(k=>{const y=[...k[o]||[]];return y.splice(i,1),{...k,[o]:y}});const a=[...$[o]||[]];a.splice(i,1),ee(t,s,a)},Ae=t=>{oe(s=>({...s,[t]:!s[t]}))},Be=()=>{const t=`${we}_${ke}`,s=Object.entries(Se).filter(([o,a])=>a).map(([o])=>{const a=parseInt(o.replace("text",""))-1;return ve[a]});if(s.length===0)return;R(o=>{const a=[...o[t]||[]];return{...o,[t]:[...a,...s]}});const i=[...$[t]||[],...s];ee(we,ke,i),U(!1)},Te=(t,s)=>{U(!0),Ne(t),Ce(s),ge(""),de([]),oe({}),xe(!1),ne(null)};b.useEffect(()=>{if(!l||l.length===0)return;const t={...w},s=l.map(o=>o.id.toString());Object.keys(t).forEach(o=>{s.includes(o)||delete t[o]}),l.forEach(o=>{const a=o.id.toString();t[a]||(t[a]={})}),JSON.stringify(t)!==JSON.stringify(w)&&C(t)},[l,w]),b.useEffect(()=>{ae({type:"SET_SCREEN_STATE",payload:{currentScreen:u,isProcessing:g,isCompleted:M}})},[u,g,M,ae]),b.useEffect(()=>{const t=document.createElement("style");return t.textContent=ht,document.head.appendChild(t),()=>{document.head.removeChild(t)}},[]),b.useEffect(()=>{const t=s=>{if(Object.values(v).some(i=>i)){const i=s.target,o=!!i.closest(".dropdown-menu"),a=!!i.closest("[data-dropdown]");!o&&!a&&P({})}};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[v]);const Le=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),u===0){const s={...w};Object.keys(s).forEach(i=>{const o=s[i];Object.keys(o).forEach(a=>{d[a]||delete o[a]})}),C(s)}if(u===1){const s={...w};l.forEach(o=>{const a=o.id.toString(),k=o.widgets||{};Object.values(k).forEach(y=>{const z=y.name;if(d[z]&&(y.type==="customtext"||y.type.toLowerCase().includes("text"))){const te=`${a}_${z}`,se=$[te]||[""];s[a]=s[a]||{},s[a][z]=se}})}),C(s);const i=ye(s);A(i.length)}N(null),h(s=>Math.min(s+1,2))},fe=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),N(null),M&&L(!1),u===1){const s=l.map(a=>a.id.toString()),i=Object.keys(w),o={...w};i.forEach(a=>{s.includes(a)||delete o[a]}),C(o)}if(u===2||M){const s={...w};Object.entries($).forEach(([i,o])=>{if(!o||o.length===0)return;const[a,k]=i.split("_");l.some(y=>y.id.toString()===a)&&(s[a]=s[a]||{},JSON.stringify(s[a][k])!==JSON.stringify(o)&&(s[a][k]=o))}),C(s)}h(s=>Math.max(s-1,0))},Re=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation());const i=d[t];if(c(o=>({...o,[t]:!i})),i){const o={...w};Object.keys(o).forEach(a=>{o[a][t]&&delete o[a][t]}),C(o)}},ze=(t,s,i)=>{i.preventDefault(),i.stopPropagation();const o=`${t}_${s}`;P(a=>{if(a[o]&&typeof a[o]=="object"?a[o].isOpen:!!a[o])return{...a,[o]:!1};{let y=0,z=0;if(i.currentTarget){const ce=i.currentTarget.getBoundingClientRect();y=ce.left,z=ce.bottom}else y=i.clientX,z=i.clientY+20;const te=window.innerWidth,se=250;return y+se>te&&(y=te-se-10),y<0&&(y=10),{...a,[o]:{isOpen:!0,x:y,y:z}}}})},ee=(t,s,i)=>{C(o=>{const a={...o};return a[t]||(a[t]={}),a[t][s]=i,a})},Fe=(t,s,i,o)=>{o&&(o.preventDefault(),o.stopPropagation()),C(a=>{const k={...a};k[t]||(k[t]={}),k[t][s]||(k[t][s]=[]);const y=k[t][s];return y.includes(i)?k[t][s]=y.filter(z=>z!==i):k[t][s]=[...y,i],k})},Ge=(t,s,i)=>{const o=`${t}_${s}`;q(a=>({...a,[o]:i}))},Ve=(t,s,i)=>{if(!w[t]){ee(t,s,i);return}const o=w[t][s]||[];i.length===o.length?ee(t,s,[]):ee(t,s,[...i])},Ue=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation()),x(Math.max(1,Math.min(t,Math.ceil(T.length/F))))},me=()=>{ue.current&&(clearTimeout(ue.current),ue.current=null),le.current=null};b.useEffect(()=>()=>{me()},[]);const He=async(t,s)=>{t&&(t.preventDefault(),t.stopPropagation()),me();const i=ye(w),o=i.length;if(o>100){N(`Cannot generate more than 100 images at once (currently: ${o} images)`);return}if(N(null),f(!0),W(0),console.log("Generated parameter combinations:",i),i.length===0){N("No valid parameter combinations found. Please check your parameter selections."),f(!1);return}let a=s||null;if(a===null){const y=ot();y!==null&&(a=y)}if(a===null){N("Please select a SaveImage or PreviewImage node first."),f(!1);return}const k=[];try{const y=Date.now().toString();le.current=y;for(const re of i){const X=await rt(re);X.prompt_id?k.push(X.prompt_id):(console.error("Failed to get prompt_id from response:",X),k.push(""))}const z=Array(i.length).fill(null).map((re,X)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:mt(w,X)}));j(z);const te=Date.now(),se=5*60*1e3,ce=async()=>{if(le.current!==y){console.log("Another polling session has started, stopping this one");return}if(Date.now()-te>se){console.log("Timeout reached while waiting for images"),le.current===y&&(f(!1),L(!0),x(1));return}let re=0;for(let X=0;X<k.length;X++){const je=k[X];if(je)try{const he=await at(je,Number(a));he&&(z[X]={...z[X],url:he},re++)}catch(he){console.error(`Error fetching image for prompt ID ${je}:`,he)}}le.current===y&&(j([...z]),W(re),re===k.length?(console.log("All images ready, completing session"),f(!1),L(!0),x(1)):ue.current=setTimeout(ce,3e3))};ce()}catch(y){console.error("Error generating images:",y),f(!1)}},Ke=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation()),_(t)},Je=(t,s)=>{s.preventDefault(),s.stopPropagation(),O(t),J(!0)},qe=t=>{t&&(t.preventDefault(),t.stopPropagation()),J(!1)},Ye=async t=>{if(t&&(t.preventDefault(),t.stopPropagation()),B!==null){console.log(`Applied image ${B+1} with parameters:`,T[B].params),Me.trackEvent({event_type:"parameter_debug_apply",message_type:"parameter_debug",message_id:tt(),data:{workflow:(await Z.graphToPrompt()).output,selected_params:T[B].params,all_params:w,count:Object.keys(w).length}});const s=T[B].params;s.nodeParams&&(Object.entries(s.nodeParams).forEach(([i,o])=>{const a=Z.graph._nodes_by_id[i];!a||!a.widgets||Object.entries(o).forEach(([k,y])=>{for(const z of a.widgets)if(z.name===k){z.value=y;break}})}),Z.graph.setDirtyCanvas(!1,!0),G(!0),setTimeout(()=>{G(!1)},3e3))}},ie=(t,s)=>{if(t&&(t.preventDefault(),t.stopPropagation()),u===1&&s!==void 0){const i=[...l],o=i[s];if(i.splice(s,1),o){const a=o.id.toString();C(k=>{const y={...k};return delete y[a],y})}i.length===0?r&&(ae({type:"SET_SCREEN_STATE",payload:null}),be(),r()):ae({type:"SET_SELECTED_NODE",payload:i});return}r?(ae({type:"SET_SCREEN_STATE",payload:null}),be(),r()):be()},be=()=>{h(0),c({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),me(),f(!1),L(!1),W(0),A(12),_(null),j(Array(12).fill(null).map((t,s)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:s%3===0?5:s%3===1?10:15,sampler_name:"euler",cfg:1}}))),C({}),P({}),q({}),I({}),x(1),N(null),G(!1),J(!1),O(""),R({}),U(!1),ge(""),de([]),xe(!1),Ne(""),Ce(""),ne(null),oe({})};return!n||l.length===0?e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:t=>t.stopPropagation(),children:e.jsxs("div",{className:"max-w-lg p-8 bg-white rounded-lg shadow-sm border border-blue-100 relative",children:[e.jsxs("div",{className:"mb-6 text-center",children:[e.jsx("h3",{className:"text-base font-bold text-blue-800 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:"flex items-start space-x-3",children:[e.jsx("div",{className:"bg-blue-100 p-2 rounded-full text-blue-600",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M5 3a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2V5a2 2 0 00-2-2H5zM5 11a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2v-2a2 2 0 00-2-2H5zM11 5a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V5zM11 13a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-800",children:"Batch Test Parameter Pairs"}),e.jsx("p",{className:"text-xs text-gray-600",children:"Select a node to batch test parameter pairs"})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx("div",{className:"bg-indigo-100 p-2 rounded-full text-indigo-600",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-800",children:"How To Use"}),e.jsx("p",{className:"text-xs text-gray-600",children:"Click on any node in your workflow to start the parameter testing process"})]})]}),e.jsx("div",{className:"mt-6 text-center",children:e.jsx("p",{className:"text-xs text-gray-600 mb-3",children:"No node is currently selected"})})]})]})}):M?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(xt,{generatedImages:T,selectedImageIndex:B,handleSelectImage:Ke,handleApplySelected:Ye,handlePrevious:fe,handleClose:ie,currentPage:Y,handlePageChange:Ue,imagesPerPage:F,notificationVisible:p,modalVisible:H,modalImageUrl:E,openImageModal:Je,closeImageModal:qe})}):g?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(dt,{selectedNodes:l,paramTestValues:w,selectedParams:d,totalCount:K,completedCount:S,errorMessage:D,handleClose:ie,setIsProcessing:f,setCurrentScreen:h,cleanupPolling:me})}):u===0?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(lt,{selectedNodes:l,handleParamSelect:Re,selectedParams:d,handleNext:Le,handleClose:ie})}):u===1?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:[e.jsx(it,{selectedNodes:l,paramTestValues:w,selectedParams:d,updateParamTestValues:ee,toggleDropdown:ze,openDropdowns:v,handleTestValueSelect:Fe,searchTerms:V,handleSearch:Ge,handleSelectAll:Ve,handleNext:Le,handlePrevious:fe,handleClose:ie,inputValues:m,setInputValues:I,textInputs:$,handleTextInputChange:_e,handleAddTextInput:De,handleRemoveTextInput:Oe,openAiWritingModal:Te}),e.jsx(ut,{visible:Q,aiWritingModalText:pe,setAiWritingModalText:ge,aiGeneratedTexts:ve,aiSelectedTexts:Se,aiWritingLoading:Ee,aiWritingError:$e,handleAiWriting:We,toggleTextSelection:Ae,addSelectedTexts:Be,onClose:()=>U(!1)})]}):e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(ct,{selectedNodes:l,paramTestValues:w,selectedParams:d,totalCount:K,errorMessage:D,handlePrevious:fe,handleStartGeneration:He,handleClose:ie})})};export{vt as ParameterDebugInterface};