17 lines
45 KiB
JavaScript
17 lines
45 KiB
JavaScript
import {app as app$1}from'../../scripts/app.js';var X=e=>{throw TypeError(e)};var E=(e,t,n)=>t.has(e)||X("Cannot "+n);var G=(e,t,n)=>(E(e,t,"read from private field"),n?n.call(e):t.get(e)),F=(e,t,n)=>t.has(e)?X("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),V=(e,t,n,i)=>(E(e,t,"write to private field"),t.set(e,n),n),ee=(e,t,n)=>(E(e,t,"access private method"),n);var D=window.comfyAPI.app.app,w,L,te,U=class{constructor(){F(this,L);F(this,w,null);}async updateNodes(){if(!(D.configuringGraph||!D.graph))return G(this,w)||V(this,w,new Promise(t=>{setTimeout(()=>{V(this,w,null),ee(this,L,te).call(this).then(()=>t());},10);})),G(this,w)}};w=new WeakMap,L=new WeakSet,te=async function(){let t=ne(D.graph).filter(s=>s.isDtServerNode!==void 0),n=t.filter(s=>s.isDtServerNode);if(console.log(t,n),!n.length)return;let i=new Map(t.map(s=>[s,false])),o=new Map;for(let s of n){let{server:r,port:l,useTls:u}=s.getServer();if(!r||!l||u===void 0)continue;let c=P(r,l,u);o.has(c)||o.set(c,await Ce(r,l,u));let g=o.get(c);s.updateModels?.(g),i.set(s,true);}for(let s of t){if(i.get(s))continue;let r=s?.findServerNodes?.();if(!r||!r.length)continue;let l={};for(let c of r){let{server:g,port:f,useTls:v}=c.getServer();if(!g||!f||v===void 0)continue;let _=o.get(P(g,f,v));l=ke(l,_);}let u=r.map(c=>c?.getModelVersion?.()).filter(c=>c);s.updateModels?.(l,u),i.set(s,true);}let a=o.size===1?o.values().next().value:null;for(let s of i.keys())i.get(s)===false&&(i.set(s,true),s.updateModels?.(a));};function ne(e){let t=[];for(let n of e.nodes)"subgraph"in n?t.push(...ne(n.subgraph)):t.push(n);return t}var m=new U;function ie(e,t,n,i){return {widget:e.addWidget("combo",t,"(None selected)",((a,s,r)=>{r.saveSelectedModels?.(),m.updateNodes();}),{values:["(None selected)"],modelType:n[1].model_type})}}async function Ne(e,t,n){let i=new FormData;return i.append("server",e),i.append("port",String(t)),i.append("use_tls",String(n)),await window.comfyAPI.api.api.fetchApi("/dt_grpc/files_info",{method:"POST",body:i})}var B=[null,null],C=null;async function Se(){let e=D.extensionManager.setting.get("drawthings.bridge_mode.community"),t=D.extensionManager.setting.get("drawthings.bridge_mode.uncurated");if(C&&B[0]===e&&B[1]===t)return C;let o=await(await window.comfyAPI.api.api.fetchApi("/dt_grpc/bridge_models")).json(),a=e?_=>o.includes(_.file):_=>o.includes(_.file)&&_.official,r=await(await import('./models/index.esm.js')).getBridgeModeModels(),l=r.models,u=r.uncurated,c=r.controlNets,g=r.loras,f=r.textualInversions,v=r.upscalers;return C={models:[...l,...t?u:[]].filter(a),controlNets:c.filter(a),loras:g.filter(a),textualInversions:f.filter(a),upscalers:v.filter(a)},B=[e,t],C}var I=new Map,M=new Map,P=(e,t,n)=>`${e}:${t}${n?":tls":""}`,xe=["Couldn't connect to server","Check server and click to retry"].map((e,t)=>({name:e,file:"",version:"fail",order:t+1})),k=["Not connected to sampler node","Connect to a sampler node to list available models"].map(e=>({name:e,file:"",version:"fail"}));async function Ce(e,t,n){if(!e||!t||n===void 0)return;if(D.extensionManager.setting.get("drawthings.bridge_mode.enabled"))return Se();let i=P(e,t,n);if(M.has(i))await M.get(i);else {let o=new Promise(a=>{Ne(e,t,n).then(async s=>{if(!s.ok)I.set(i,null);else {let r=await s.json();Le(r),I.set(i,r);}M.delete(i),a();});});M.set(i,o),await o;}return I.get(i)||void 0}var Me={models:xe,controlNets:k,loras:k,upscalers:k,textualInversions:k};I.set(P(),Me);function A(e,t){return {value:e,content:e.version&&e.version!=="fail"?`${e.name} (${Pe(e.version)})`:e.name,toString(){return e.name},disabled:t,callback(...n){return false}}}function ke(e,t){let n={},i=new Set(Object.keys(e??{}).concat(Object.keys(t??{})));for(let o of i.values()){n[o]=e[o]??[];let a=n[o].map(r=>r.file),s=(t[o]??[]).filter(r=>!a.includes(r.file));n[o]=n[o].concat(s);}return n}var Ie={v1:"SD",v2:"SD2","kandinsky2.1":"Kan","sdxl_base_v0.9":"SDXL","sdxl_refiner_v0.9":"SDXL",ssd_1b:"SSD",svd_i2v:"SVD","wurstchen_v3.0_stage_c":"Wur","wurstchen_v3.0_stage_b":"Wur",sd3:"SD3",pixart:"Pix",auraflow:"AF",flux1:"F1",sd3_large:"SD3L",hunyuan_video:"Hun","wan_v2.1_1.3b":"Wan","wan_v2.1_14b":"Wan",hidream_i1:"HiD",qwen_image:"Qwen"};function Pe(e){return Ie[e]??e}function Le(e){try{new URL(document.location.href).searchParams.has("dtgrpctesthack")&&Array.isArray(e?.models)&&(e.models.push({file:"fake_qwen.ckpt",version:"qwen_image",name:"Qwen Image Fake"}),e.models.push({file:"fake_wan.ckpt",version:"wan_v2.1_14b",name:"Wan Fake"}));}catch{}}var z=["DPM++ 2M Karras","Euler A","DDIM","PLMS","DPM++ SDE Karras","UniPC","LCM","Euler A Substep","DPM++ SDE Substep","TCD","Euler A Trailing","DPM++ SDE Trailing","DPM++ 2M AYS","Euler A AYS","DPM++ SDE AYS","DPM++ 2M Trailing","DDIM Trailing","UniPC Trailing","UniPC AYS"],W=["Legacy","TorchCpuCompatible","ScaleAlike","NvidiaGpuCompatible"];function H(e,t){let n=e*t/256,i=(1.15-.5)/3840,a=(n-256)*i+.5,s=Math.exp(a);return Math.round(s*100)/100}var Ae={"wan_v2.1_1.3b":81,"wan_v2.1_14b":81,hunyuan_video:129,svd_i2v:14},We=[["start_width","width","DrawThingsSampler","width","int",512,128,2048,64,"roundTo64"],["start_height","height","DrawThingsSampler","height","int",512,128,2048,64,"roundTo64"],["seed","seed","DrawThingsSampler","seed","int",-1,-1,null,1,"modulo=4294967295"],["steps","steps","DrawThingsSampler","steps","int",16,1,150,1],["guidance_scale","cfg","DrawThingsSampler","guidanceScale","float",5,0,50,.1],["strength","strength","DrawThingsSampler","strength","float",1,0,1,.01],["model","model","DrawThingsSampler","model","DT_MODEL",null],["sampler","sampler_name","DrawThingsSampler","sampler","index",0,z],["batch_count","batch_count","DrawThingsSampler","batchCount","int",1,1,4,1],["batch_size","batch_size","DrawThingsSampler","batchSize","int",1,1,1,1],["hires_fix","high_res_fix","DrawThingsSampler","hiresFix","bool",false],["hires_fix_start_width","high_res_fix_start_width","DrawThingsSampler","hiresFixWidth","int",512,128,2048,64,"roundTo64,ifTrue=hiresFix"],["hires_fix_start_height","high_res_fix_start_height","DrawThingsSampler","hiresFixHeight","int",512,128,2048,64,"roundTo64,ifTrue=hiresFix"],["hires_fix_strength","high_res_fix_strength","DrawThingsSampler","hiresFixStrength","float",.7,0,1,.01,"ifTrue=hiresFix"],["image_guidance_scale","image_guidance_scale","DrawThingsSampler","imageGuidanceScale","float",5,0,50,.1],["seed_mode","seed_mode","DrawThingsSampler","seedMode","index",2,W],["clip_skip","clip_skip","DrawThingsSampler","clipSkip","int",1,1,23,1],["controls",null,"DrawThingsControlNet","controls"],["loras",null,"DrawThingsLoRA","loras"],["mask_blur","mask_blur","DrawThingsSampler","maskBlur","float",2.5,0,15,.1],["face_restoration",null,null,"faceRestoration"],["decode_with_attention",null,null],["hires_fix_decode_with_attention",null,null],["clip_weight",null,null],["negative_prompt_for_image_prior",null,null],["image_prior_steps",null,null],["original_image_height",null,null,"originalImageHeight"],["original_image_width",null,null,"originalImageWidth"],["crop_top",null,null,"cropTop"],["crop_left",null,null,"cropLeft"],["target_image_height",null,null,"targetImageHeight"],["target_image_width",null,null,"targetImageWidth"],["aesthetic_score",null,null,"aestheticScore"],["negative_aesthetic_score",null,null,"negativeAestheticScore"],["zero_negative_prompt",null,null,"zeroNegativePrompt"],["negative_original_image_height",null,null,"negativeOriginalImageHeight"],["negative_original_image_width",null,null,"negativeOriginalImageWidth"],["name",null,null,null],["fps_id","fps","DrawThingsSampler","fps","int",12,1,30,1],["motion_bucket_id","motion_scale","DrawThingsSampler","motionScale","int",127,0,255,1],["cond_aug","guiding_frame_noise","DrawThingsSampler","guidingFrameNoise","float",.02,0,1,.01],["start_frame_cfg","start_frame_guidance","DrawThingsSampler","startFrameGuidance","float",1,0,15,.1],["num_frames","num_frames","DrawThingsSampler","numFrames","int",25,1,Ae,1],["mask_blur_outset","mask_blur_outset","DrawThingsSampler","maskBlurOutset","float",0,-100,100,.1],["sharpness","sharpness","DrawThingsSampler","sharpness","float",0,0,30,.1],["shift","shift","DrawThingsSampler","shift","float",1,0,16,.01],["stage_2_steps",null,null,"stage2Steps"],["stage_2_cfg",null,null,"stage2Guidance"],["stage_2_shift",null,null,"stage2Shift"],["tiled_decoding","tiled_decoding","DrawThingsSampler","tiledDecoding","bool",false],["decoding_tile_width","decoding_tile_width","DrawThingsSampler","decodingTileWidth","int",512,128,2048,64,"roundTo64,ifTrue=tiledDecoding"],["decoding_tile_height","decoding_tile_height","DrawThingsSampler","decodingTileHeight","int",512,128,2048,64,"roundTo64,ifTrue=tiledDecoding"],["decoding_tile_overlap","decoding_tile_overlap","DrawThingsSampler","decodingTileOverlap","int",512,64,1024,64,"roundTo64,ifTrue=tiledDecoding"],["stochastic_sampling_gamma","stochastic_sampling_gamma","DrawThingsSampler","stochasticSamplingGamma","float",.3,0,1,.01],["preserve_original_after_inpaint","preserve_original","DrawThingsSampler","preserveOriginalAfterInpaint","bool",true],["tiled_diffusion","tiled_diffusion","DrawThingsSampler","tiledDiffusion","bool",false],["diffusion_tile_width","diffusion_tile_width","DrawThingsSampler","diffusionTileWidth","int",512,128,2048,64,"roundTo64,ifTrue=tiledDiffusion"],["diffusion_tile_height","diffusion_tile_height","DrawThingsSampler","diffusionTileHeight","int",512,128,2048,64,"roundTo64,ifTrue=tiledDiffusion"],["diffusion_tile_overlap","diffusion_tile_overlap","DrawThingsSampler","diffusionTileOverlap","int",512,64,1024,64,"roundTo64,ifTrue=tiledDiffusion"],["t5_text_encoder",null,null,"t5TextEncoder"],["separate_clip_l","separate_clip_l","DrawThingsSampler","separateClipL","bool",false],["clip_l_text","clip_l_text","DrawThingsSampler","clipLText","string","","ifTrue=separateClipL"],["separate_open_clip_g","separate_open_clip_g","DrawThingsSampler","separateOpenClipG","bool",false],["open_clip_g_text","open_clip_g_text","DrawThingsSampler","openClipGText","string","","ifTrue=separateOpenClipG"],["speed_up_with_guidance_embed","speed_up","DrawThingsSampler","speedUpWithGuidanceEmbed","bool",true],["guidance_embed","guidance_embed","DrawThingsSampler","guidanceEmbed","float",4.5,0,50,.1,"ifFalse=speedUpWithGuidanceEmbed"],["resolution_dependent_shift","res_dpt_shift","DrawThingsSampler","resolutionDependentShift","bool",true],["tea_cache_start","tea_cache_start","DrawThingsSampler","teaCacheStart","int",5,0,150,1,"ifTrue=teaCache"],["tea_cache_end","tea_cache_end","DrawThingsSampler","teaCacheEnd","int",-1,-151,150,1,"ifTrue=teaCache"],["tea_cache_threshold","tea_cache_threshold","DrawThingsSampler","teaCacheThreshold","float",.06,0,1,.01,"ifTrue=teaCache"],["tea_cache","tea_cache","DrawThingsSampler","teaCache","bool",false],["separate_t5",null,null,"separateT5"],["t5_text",null,null,null],["tea_cache_max_skip_steps","tea_cache_max_skip_steps","DrawThingsSampler","teaCacheMaxSkipSteps","int",3,1,50,1,"ifTrue=teaCache"],["causal_inference_enabled",null,null,null],["causal_inference","causal_inference","DrawThingsSampler","causalInference","int",0,0,129,4,"ifPos=set(causalInference, true),causInfConvert"],["causal_inference_pad","causal_inference_pad","DrawThingsSampler","causalInferencePad","int",0,0,129,4,"causInfConvert"],["upscaler","upscaler_model","DrawThingsUpscaler","upscaler"],["upscaler_scale_factor","upscaler_scale_factor","DrawThingsUpscaler","upscalerScaleFactor","int",4,2,4,2],["refiner_model","refiner_model","DrawThingsRefiner","refinerModel"],["refiner_start","refiner_start","DrawThingsRefiner","refinerStart","int",.85,0,1,.01],["cfg_zero_star","cfg_zero_star","DrawThingsSampler","cfgZeroStar","bool",false],["cfg_zero_star_init_steps","cfg_zero_star_init_steps","DrawThingsSampler","cfgZeroInitSteps","int",0,0,"ref=steps",1,"ifTrue=cfgZeroStar"]];function y(e){return Math.round(e/64)*64}var Re={model:async(e,t,n,i,o)=>{await m.updateNodes();let s=n?.options?.values?.find(r=>r.value?.file===t);s&&(n.value=s);},refiner_model:(e,t,n)=>{let o=n?.options?.values?.find(a=>a.value?.file===t);o&&(n.value=o);},upscaler:(e,t,n)=>{let o=n?.options?.values?.find(a=>a.value?.file===t);o&&(n.value=o);},start_width:(e,t,n)=>{n&&(n.value=y(t));},start_height:(e,t,n)=>{n&&(n.value=y(t));},sampler:(e,t,n)=>{n.value=z[t];},seed:(e,t,n,i)=>{typeof t=="number"&&t>=0&&(n.value=t);},hires_fix_start_width:(e,t,n,i,o)=>{o.hiresFix&&n&&(n.value=y(t));},hires_fix_start_height:(e,t,n,i,o)=>{o.hiresFix&&n&&(n.value=y(t));},hires_fix_strength:(e,t,n,i,o)=>{o.hiresFix&&n&&(n.value=t);},seed_mode:(e,t,n)=>{n&&W[t]&&(n.value=W[t]);},decoding_tile_width:(e,t,n,i,o)=>{o.tiledDecoding&&n&&(n.value=y(t));},decoding_tile_height:(e,t,n,i,o)=>{o.tiledDecoding&&n&&(n.value=y(t));},decoding_tile_overlap:(e,t,n,i,o)=>{o.tiledDecoding&&n&&(n.value=y(t));},diffusion_tile_width:(e,t,n,i,o)=>{o.tiledDiffusion&&n&&(n.value=y(t));},diffusion_tile_height:(e,t,n,i,o)=>{o.tiledDiffusion&&n&&(n.value=y(t));},diffusion_tile_overlap:(e,t,n,i,o)=>{o.tiledDiffusion&&n&&(n.value=y(t));},guidance_embed:(e,t,n,i,o)=>{n&&(n.value=t);},resolution_dependent_shift:(e,t,n,i,o)=>{if(n&&(n.value=t),t){let a=i.widgets?.find(l=>l.name==="shift"),s=o.width||i.widgets?.find(l=>l.name==="width")?.value,r=o.height||i.widgets?.find(l=>l.name==="height")?.value;a&&s&&r&&(a.value=H(s,r));}},causal_inference:function(e,t,n,i,o){Number.isFinite(t)?n.value=t*4-3:n.value=0;},causal_inference_pad:(e,t,n,i,o)=>{n&&typeof t=="number"&&(n.value=t*4);},upscaler_scale_factor:(e,t,n)=>{t===2?n.value=2:n.value=4;},refiner_start:(e,t,n)=>{typeof t=="number"?n.value=Math.min(1,Math.max(0,t)):n.value=.85;}},Oe={model:async(e,t,n)=>{let i=e.value;e&&i&&i.value&&(n.model=i.value.file??i.value.name);},sampler:(e,t,n)=>{e&&typeof e.value=="string"&&(n.sampler=z.indexOf(e.value));},seed_mode:(e,t,n)=>{e&&typeof e.value=="string"&&(n.seed_mode=W.indexOf(e.value));},causal_inference:(e,t,n)=>{e&&typeof e.value=="number"&&(n.causal_inference=Math.floor((e.value+3)/4));}},j=class{constructor(t,n,i,o,a,s,...r){this.customImport=void 0;this.customExport=void 0;this.fbs=t,this.python=n,this.node=i,this.json=o,this.type=a,this.defaultValue=s,(a==="int"||a==="float")&&(this.min=r[0],this.max=r[1],this.step=r[2],this.spec=r[3]),a==="bool"&&(this.spec=r[0]),a==="index"&&(this.values=r[0],this.spec=r[1]),a==="string"&&(this.spec=r[0]);}async import(t,n,i,o,a){!i||!o||(this.customImport?await this.customImport(t,n,i,o,a):i.value=n??this.defaultValue);}async export(t,n,i){this.customExport?await this.customExport(t,n,i):this.json&&t&&t.value!==void 0&&(i[this.json]=t.value);}coerce(t){return this.type==="int"||this.type==="float"?typeof t!="number"?this.defaultValue||0:typeof this.min=="number"&&Number.isFinite(this.min)&&t<this.min?this.min:typeof this.max=="number"&&Number.isFinite(this.max)&&t>this.max?this.max:this.type==="int"?Math.round(t):t:this.type==="bool"?typeof t!="boolean"?this.defaultValue||false:t:this.type==="string"?typeof t!="string"?this.defaultValue||"":t:this.type==="index"?typeof t=="number"&&t>=0&&this.values&&t<this.values.length?this.values[t]:typeof t=="string"&&this.values&&this.values.includes(t)?t:this.values?this.values[this.defaultValue]:void 0:t}getRequiredNodes(t,n){return this.node?[this.node]:[]}},K=We.map(([e,...t])=>{let n=new j(e,...t);return n.customImport=Re[e],n.customExport=Oe[e],n});function $(e){return K.find(t=>t.json===e)}function q(e){return K.find(t=>t.python===e)}function oe(e){return K.filter(t=>t.node===e)}N("loras","getRequiredNodes",e=>Array.isArray(e)&&e.length>0?Array(Math.ceil(e.length/8)).fill("DrawThingsLoRA"):[]);N("controls","getRequiredNodes",e=>Array.isArray(e)?e.map(t=>"DrawThingsControlNet"):[]);N("upscaler","getRequiredNodes",e=>e?["DrawThingsUpscaler"]:[]);N("upscaler_scale_factor","getRequiredNodes",()=>[]);N("refinerModel","getRequiredNodes",e=>e?["DrawThingsRefiner"]:[]);N("refinerStart","getRequiredNodes",()=>[]);function N(e,t,n){let i=$(e);i&&(i[t]=n);}function ae(e){navigator.clipboard.readText().then(async t=>{try{let n=JSON.parse(t),i=[];for(let[s,r]of Object.entries(n)){let l=$(s);if(!l)continue;if(l.node!==e.type){i.push(...l.getRequiredNodes(r,n));continue}let u=e.widgets?.find(c=>c.name===l.python);u&&await l.import(s,r,u,e,n);}e.coerceWidgetValues(),e.updateDynamicWidgets?.();let o=e.getConfigInputNodes(),a=[];if(i.includes("DrawThingsUpscaler")&&(o.DrawThingsUpscaler.length?se(o.DrawThingsUpscaler[0],n):a.push("DrawThingsUpscaler")),i.includes("DrawThingsRefiner")&&(o.DrawThingsRefiner.length?se(o.DrawThingsRefiner[0],n):a.push("DrawThingsRefiner")),i.includes("DrawThingsControlNet")){let s=i.filter(l=>l==="DrawThingsControlNet").length;s>o.DrawThingsControlNet.length&&a.push(`${s-o.DrawThingsControlNet.length} x DrawThingsControlNet`);let r=0;for(let l of o.DrawThingsControlNet)Ee(l,n.controls[r++]);}if(i.includes("DrawThingsLoRA")){let s=i.filter(r=>r==="DrawThingsLoRA").length;s>o.DrawThingsLoRA.length&&a.push(`${s-o.DrawThingsLoRA.length} x DrawThingsLoRA`),Ge(o.DrawThingsLoRA,n.loras);}a.length&&window.app?.extensionManager.toast.add({severity:"warn",summary:"Draw Things gRPC",detail:[`The Draw Things config has been partially loaded. To load the full config, add the following nodes:
|
|
`,...a.map(s=>`\u2022 ${s}`)].join(`
|
|
`),life:8e3});}catch(n){alert(`Failed to parse Draw Things config from clipboard
|
|
|
|
`+n),console.warn(n);}});}function se(e,t){let n=oe(e.type);for(let i of n){let o=e.widgets?.find(a=>a.name===i.python);!o||!i.json||i.import(i.json,t[i.json],o,e,t);}}function Ee(e,t){let n=e.widgets?.reduce((i,o)=>(i[o.name]=o,i),{})??{};if("file"in t){let o=(n.control_name?.options).values?.find(a=>a.value?.file===t.file);o&&(n.control_name.value=o);}if("globalAveragePooling"in t&&(n.global_average_pooling.value=!!t.globalAveragePooling),"weight"in t&&typeof t.weight=="number"?n.control_weight.value=Math.min(Math.max(t.weight,0),1.5):n.control_weight.value=1,"guidanceStart"in t&&typeof t.guidanceStart=="number"?n.control_start.value=Math.min(Math.max(t.guidanceStart,0),1):n.control_start.value=0,"guidanceEnd"in t&&typeof t.guidanceEnd=="number"?n.control_end.value=Math.min(Math.max(t.guidanceEnd,0),1):n.control_end.value=1,"downSamplingRate"in t&&typeof t.downSamplingRate=="number"?n.down_sampling_rate.value=t.downSamplingRate:n.down_sampling_rate.value=1,"inputOverride"in t&&typeof t.inputOverride=="string"){let i=t.inputOverride.charAt(0).toUpperCase()+t.inputOverride.slice(1);n.control_input_type?.options?.values?.includes(i)?n.control_input_type.value=i:n.control_input_type.value="Unspecified";}else n.control_input_type.value="Unspecified";if("controlImportance"in t&&typeof t.controlImportance=="string"){let i=t.controlImportance.charAt(0).toUpperCase()+t.controlImportance.slice(1);n.control_mode?.options?.values?.includes(i)?n.control_mode.value=i:n.control_mode.value="Balanced";}else n.control_mode.value="Balanced";"targetBlocks"in t&&Array.isArray(t.targetBlocks)?(t.targetBlocks.length===0&&(n.target_blocks.value="All"),t.targetBlocks.length===1&&(n.target_blocks.value="Style"),t.targetBlocks.length>1&&(n.target_blocks.value="Style and Layout")):n.target_blocks.value="All";}async function Ge(e,t){for(let n=0;n<e.length;n++){let i=e[n],o=n*8+8;t.length>o?i.loraCount=8:i.loraCount=8-(o-t.length);for(let a=0;a<8;a++){let s=t[a+n*8],{file:r,weight:l,mode:u}=Fe(i,a);if(!s||!s.file){r.value="(None selected)",l.value=1,u.value="All";continue}let g=r?.options?.values?.find(f=>f.value?.file===s.file);if(g&&(r.value=g),"weight"in s&&typeof s.weight=="number"?l.value=Math.min(Math.max(s.weight,-5),5):l.value=1,"mode"in s&&typeof s.mode=="string"){let f=s.mode.charAt(0).toUpperCase()+s.mode.slice(1);u?.options?.values?.includes(f)?u.value=f:u.value="All";}else u.value="All";}}}function Fe(e,t){let n=e.widgets?.slice(t*3+1,t*3+4)??[];return {file:n[0],weight:n[1],mode:n[2]}}function re(e,t,n){let i=e[t];e[t]=function(...o){let a=i?.apply(this,o);return n?.apply(this,o),a};}function h(e,t){let n=e.prototype;for(let i in t){let o=t[i];if(typeof o=="function"&&typeof n[i]=="function"){let a=n[i],s=o;n[i]=function(...r){let l=a.apply(this,r);try{s.apply(this,r);}finally{return l}};}else Ve(o)?Object.defineProperty(n,i,o):n[i]=o;}}function Ve(e){if(e==null)return false;let t="value"in e||"get"in e||"set"in e||"writable"in e||"enumerable"in e||"configurable"in e;return typeof e=="object"&&t}var Be={preserveOriginalAfterInpaint:"preserve_original",hiresFix:"high_res_fix",sampler:"sampler_name"};Object.fromEntries(Object.entries(Be).map(([e,t])=>[t,e]));function p(e,t){return e.widgets?.find(n=>n.name===t)}var J=window.comfyAPI.app.app,Ue=["server","port","use_tls","strength","seed","control_after_generate","width","height","steps","cfg","sampler_name","res_dpt_shift","shift","batch_size","num_frames"],je=["seed_mode","speed_up","guidance_embed","fps","motion_scale","guiding_frame_noise","start_frame_guidance","causal_inference","causal_inference_pad","clip_skip","sharpness","mask_blur","mask_blur_outset","preserve_original","separate_clip_l","clip_l_text","separate_open_clip_g","open_clip_g_text","high_res_fix","high_res_fix_start_width","high_res_fix_start_height","high_res_fix_strength","upscaler","image_guidance_scale","tiled_decoding","decoding_tile_width","decoding_tile_height","decoding_tile_overlap","tiled_diffusion","diffusion_tile_width","diffusion_tile_height","diffusion_tile_overlap","tea_cache","tea_cache_start","tea_cache_end","tea_cache_threshold","tea_cache_max_skip_steps"],R={};function ze(e,t){if(!(!e||!e.widget||!t||!t.getWidgetFromSlot)&&e._origPos===void 0){e._origPos=e.pos;let n=t.getWidgetFromSlot(e);Object.defineProperty(e,"pos",{get(){return n.hidden?this.collapsedPos:e._origPos},set(i){e._origPos=i;}});}}function d(e,t,n=false,i=""){let o=p(e,t);if(!o||(R[o.name]||(R[o.name]={origComputeSize:o.computeSize,origComputedHeight:o.computedHeight}),!o.hidden===n))return;o.computeSize=n?R[o.name].origComputeSize:()=>[0,-4],o.computedHeight=n?R[o.name].origComputedHeight:0,o.hidden=!n,o.linkedWidgets?.forEach(r=>d(e,r,n,":"+o.name));let s=e.computeSize()[1];s>e.size[1]&&e.setSize([e.size[0],s]),J.extensionManager.setting.get("drawthings.node.keep_shrunk")&&s<e.size[1]&&e.setSize([e.size[0],s]),setTimeout(()=>J.canvas.setDirty(true,true),10);}function b(e,t,...n){n.forEach(i=>d(e,i,t));}function He(e){let n=p(e,"model")?.value?.value?.version??e?._lastSelectedModel?.model?.value?.version,i=p(e,"settings")?.value,o=i==="Basic"||i==="All",a=i==="Advanced"||i==="All";if(b(e,o,...Ue),b(e,a,...je),o){let s=p(e,"sampler_name")?.value==="TCD";d(e,"stochastic_sampling_gamma",s);let r=["flux1","sd3","hidream_i1","qwen_image"].includes(n);d(e,"res_dpt_shift",r);let l=r&&p(e,"res_dpt_shift")?.value,u=p(e,"shift");u&&(u.disabled=l);let c=["hunyuan_video","wan_v2.1_1.3b","wan_v2.1_14b","svd_i2v"].includes(n);d(e,"num_frames",c);let g=["flux1","hidream_i1","wan_v2.1_1.3b","wan_v2.1_14b","sd3","hunyuan_video","qwen_image"].includes(n),f=g&&p(e,"cfg_zero_star")?.value;d(e,"cfg_zero_star",g),d(e,"cfg_zero_star_init_steps",!!f);}if(a){let s=["flux1","hidream_i1","wan_v2.1_1.3b","wan_v2.1_14b","hunyuan_video"].includes(n),r=s&&p(e,"tea_cache")?.value;d(e,"tea_cache",s),b(e,!!r,"tea_cache_start","tea_cache_end","tea_cache_threshold","tea_cache_max_skip_steps");let l=["flux1","hidream_i1","hunyuan_video"].includes(n);d(e,"speed_up",l);let u=p(e,"speed_up")?.value;d(e,"guidance_embed",l&&!u);let c=["flux1","hidream_i1","sd3"].includes(n);d(e,"separate_clip_l",c);let g=c&&p(e,"separate_clip_l")?.value;d(e,"clip_l_text",!!g);let f=["sd3"].includes(n);d(e,"separate_open_clip_g",f);let v=f&&p(e,"separate_open_clip_g")?.value;d(e,"open_clip_g_text",!!v);let _=["svd_i2v"].includes(n);b(e,_,"fps","motion_scale","guiding_frame_noise","start_frame_guidance");let Q=n?.toLowerCase().startsWith("wan");d(e,"causal_inference",!!Q),d(e,"causal_inference_pad",!!Q);let be=p(e,"high_res_fix")?.value;b(e,!!be,"high_res_fix_start_width","high_res_fix_start_height","high_res_fix_strength");let Te=p(e,"tiled_decoding")?.value;b(e,!!Te,"decoding_tile_width","decoding_tile_height","decoding_tile_overlap");let De=p(e,"tiled_diffusion")?.value;b(e,!!De,"diffusion_tile_width","diffusion_tile_height","diffusion_tile_overlap");}}var Ke={name:"widgets",settings:[{id:"drawthings.node.keep_shrunk",type:"boolean",name:"Keep node shrunk when widgets change",defaultValue:true,category:["DrawThings","Nodes","Keep node shrunk"],onChange:(e,t)=>{t===false&&e===true&&J.graph.nodes.filter(n=>n.type==="DrawThingsSampler").forEach(n=>{setTimeout(()=>n.updateDynamicWidgets(),10);});}}],async beforeRegisterNodeDef(e,t,n){e.comfyClass==="DrawThingsSampler"&&h(e,$e);}},le=Ke,$e={updateDynamicWidgets(){He(this);},onNodeCreated(){this.updateDynamicWidgets();},onConfigure(e){this.updateDynamicWidgets();},onInputAdded(e){e.widget&&ze(e,this);},onWidgetChanged(e,t,n,i){if(this.updateDynamicWidgets(),e==="res_dpt_shift"&&["flux1","sd3","hidream_i1"].includes(this.getModelVersion())&&p(this,"res_dpt_shift")?.value){let s=p(this,"height")?.value,r=p(this,"width")?.value,l=p(this,"shift");l&&typeof s=="number"&&typeof r=="number"&&(l.value=H(s,r));}}};function de(e,t,n,i){let{container:o,buttons:a}=Ze([{label:"Show Mode",callback:()=>{e.showMode=!e.showMode;},dataTestId:"dtgrpc-lora-show-mode"},{label:"Less",callback:()=>{e.loraCount-=1;},dataTestId:"dtgrpc-lora-less"},{label:"More",callback:()=>{e.loraCount+=1;},dataTestId:"dtgrpc-lora-more"}]),s={hideOnZoom:false,getValue:()=>{},setValue:l=>{},getMinHeight:()=>36,getMaxHeight:()=>36,getHeight:()=>36,margin:4},r=e.addDOMWidget("buttons","DT_BUTTONS",o,s);return r._buttonElements=a,r.value=null,{widget:r}}var qe={onNodeCreated(e){this.loraCount=1,this.showMode=false;},onConfigure(e){if("loraCount"in e&&(this.loraCount=e.loraCount),"showMode"in e&&(this.showMode=e.showMode),e.widget_values_keyed&&this.widgets)for(let[t,n]of Object.entries(e.widget_values_keyed)){let i=this.widgets.find(o=>o.name===t);i&&(i.value=n);}else if(e.widgets_values&&e.widgets_values.length===2&&this.widgets){this.widgets[0].value=null;let t=this.widgets.find(s=>s.name==="lora");t&&(t.value=e.widgets_values[0]);let n=this.widgets.find(s=>s.name==="weight");n&&(n.value=e.widgets_values[1]);let o=this.inputs.map((s,r)=>({slot:r,input:s})).filter(({input:s})=>s.link!==null).map(({input:s,slot:r})=>({node:this.getInputNode(r),input:s,slot:r}));for(let{node:s,input:r,slot:l}of o)s&&s.type==="DrawThingsLoRA"&&r.link!==null?(this.disconnectInput(l),this.graph?.removeLink(r.link),s.connect(0,this,0)):r.link!==null&&(this.disconnectInput(l),this.graph?.removeLink(r.link));let a=this.inputs.findIndex(s=>s.name==="control_image");a!==-1&&this.removeInput(a);}delete this.widget_values_keyed;},onSerialize(e){e.loraCount=this._loraCount,e.showMode=this._showMode,e.nodePackVersion=T,this.widgets&&(e.widget_values_keyed=Object.fromEntries(this.widgets.map(t=>[t.name,t.value])));},loraCount:{get(){return this._loraCount},set(e){if(this._loraCount===e)return;this._loraCount=Math.max(0,Math.min(e,8)),this.updateWidgets();let t=this.widgets?.[0]?._buttonElements;t&&(t[1].disabled=this._loraCount<=1,t[2].disabled=this._loraCount>=8);},enumerable:true},showMode:{get(){return this._showMode},set(e){if(this._showMode===e)return;this._showMode=e,this.updateWidgets();let t=this.widgets?.[0]?._buttonElements;t&&(t[0].textContent=e?"Hide Mode":"Show Mode");},enumerable:true},updateWidgets(){if(this.widgets)for(let e=0;e<8;e++){let t=e*3+1,n=e*3+2,i=e*3+3;e<this.loraCount?(d(this,this.widgets[t].name,true),d(this,this.widgets[n].name,true),d(this,this.widgets[i].name,this.showMode),this.widgets[t].value||(this.widgets[t].value="(None selected)")):(d(this,this.widgets[t].name,false),d(this,this.widgets[n].name,false),d(this,this.widgets[i].name,false),this.widgets[t].value=null);}}},Je={name:"loraNode",beforeRegisterNodeDef(e,t,n){e.comfyClass==="DrawThingsLoRA"&&h(e,qe);}},ue=Je;function Ze(e){let t=document.createElement("div");t.classList.add("dt-buttons-container");let n=[];for(let i of e){let o=document.createElement("button");n.push(o),o.classList.add("dt-button"),i.label&&(o.innerText=i.label),o.addEventListener("click",()=>{i.callback();}),i.style&&(o.style.cssText=i.style),i.classList&&o.classList.add(...i.classList),i.dataTestId&&o.setAttribute("data-testid",i.dataTestId),t.appendChild(o);}return {container:t,buttons:n}}var pe="./drawthings-grpc/data.json";async function ge(){let e=await Ye(),t=ce[ce.length-1];e.includes(t.version)||(await Qe(t.version),app$1.extensionManager.toast.add({summary:t.title,detail:t.detail,severity:"success",life:0}));}async function Ye(){return (await fe())?.announced??[]}async function Qe(e){let t=await fe();(!t?.announced||!Array.isArray(t?.announced))&&(t.announced=[]),t.announced.push(e),await app$1.api.storeUserData(pe,t);}async function fe(){try{let t=await app$1.api.getUserData(pe);if(t.status===200)return await t.json()}catch(t){console.error(`Error getting user data: ${t}`);}return {announced:[]}}var ce=[{version:"1.6.0",title:"DrawThings-gRPC 1.6.0",detail:["The Draw Things Sampler has a new input and corresponding node: Hints!","Hints are Draw Thing's control images, used by ControlNets, Flux Kontext,","Hi-Dream E1 and a handful of LoRAs. Use this node to add references images,",'like the "Moodboard" in the Draw Things App.',`
|
|
|
|
For ControlNets, images can be added with either the ControlNet node,`,"or with the Hints node. For LoRAs (like Flux Depth), use the Hints node with the","appropriate hint type. For Flux Kontext or Hi-Dream E1, use the Hints node with",'"Shuffle (Moodboard)" as the hint type.',`
|
|
|
|
Note: Currently pose or scribble images are not working correctly, but depth or`,"moodboard images should work as expected."].join(" ")},{version:"1.7.0",title:"DrawThings-gRPC 1.7.0",detail:["\u2022 Response compression is now supported! It's no longer necessary to disable this option in Draw Things or the gRPC CLI.","\u2022 Added hi res fix support for hint images","\u2022 Add support for pose hint images","\u2022 Fix: Model widgets should no longer show[object Object] when loading a workflow while disconnected","\u2022 Fix: The Draw Things Sampler Node now shows the correct error when running a workflow while not connected.","\u2022 Fix: Hint images are provided in both sizes when HiResFix is enabled","\u2022 Fix: When loading a workflow while disconnected, the widgets for the last selected model version will be shown.","\u2022 Fix: Update notes messages should only appear once"].join(`
|
|
`)},{version:"1.8.0",title:"DrawThings-gRPC 1.8.0",detail:`- Bridge Mode support: For DT+ subscribers interested in using Bridge Mode, you can now list all official, community, and uncurated models available in Cloud Compute. Right click the sampler node, or go to the Draw Things tab in Settings, to enable. Make sure to enable Bridge Mode in the API settings of your Draw Things app (only available for DT+ subscribers). (User uploaded loras are currently unsupported.)
|
|
- Note: We have no way of knowing if bridge mode is enabled from ComfyUI. Enabling bridge mode in Comfy simply changes the list of models that are shown - it's up to your DT app or CLI how to handle the request.
|
|
- Draw Things config import has been improved. Configs that use additional nodes (LoRA, ControlNet, Upscaler, or Refiner) will apply their values to existing, connected nodes. If the node isn't available, a message will be displayed listing the missing nodes.`}];var T="1.8.2",he,S={name:"core",getCustomWidgets(){return {DT_MODEL:ie,DT_BUTTONS:de}},beforeConfigureGraph(e){for(let t of e.nodes)(t.type==="DrawThingsPositive"||t.type==="DrawThingsNegative")&&(t.type="DrawThingsPrompt",t.properties["Node name for S&R"]="DrawThingsPrompt",delete t.properties.ver,t.widgets_values.unshift("..."));},async beforeRegisterNodeDef(e,t,n){"comfyClass"in e&&e.comfyClass==="DrawThingsSampler"&&h(e,Xe);},async setup(e){await me();let t=async()=>{await me();};setTimeout(()=>document.querySelector('button[title="ComfyUI Manager"]')?.addEventListener("click",async()=>{document.getElementById("cm-close-button")?.addEventListener("click",t,{once:true});}),3e3),re(e.api,"interrupt",async n=>{e.rootGraph?.nodes.some(i=>i.type==="DrawThingsSampler")&&await e.api.fetchApi("/dt_grpc/interrupt",{method:"POST"});});}},Xe={async onNodeCreated(){let e=this.inputs?.find(n=>n.name=="positive"),t=this.inputs?.find(n=>n.name=="negative");app.canvas&&(e.color_on=e.color_off=t.color_on=t.color_off=app.canvas.default_connection_color_byType.CONDITIONING,app.canvas.default_connection_color_byType.DT_LORA=app.canvas.default_connection_color_byType.MODEL,app.canvas.default_connection_color_byType.DT_CNET=app.canvas.default_connection_color_byType.CONTROL_NET),setTimeout(()=>ge(),2e3);},onSerialize(e){let t=e;t.nodePackVersion=T;let n=this.widgets?.map(i=>[i.name,i.value]);t.widget_values_keyed=Object.fromEntries(n??[]);},onConfigure(e){if("widget_values_keyed"in e&&e.widget_values_keyed&&typeof e.widget_values_keyed=="object")for(let[t,n]of Object.entries(e.widget_values_keyed)){let i=this.widgets?.find(o=>o.name===t);i&&(i.value=n);}this.coerceWidgetValues(),"widget_values_keyed"in this&&delete this.widget_values_keyed,this.updateDynamicWidgets?.();},coerceWidgetValues(){let e=[];for(let t of this.widgets??[]){let n=q(t.name);if(!n)continue;let i=n.coerce(t.value);i!==t.value&&(e.push({name:t.name,value:t.value,coerced:i}),t.value=i);}if(e.length){let t="The Draw Things Sampler node contained invalid values - they have been corrected:",n=e.map(o=>`${o.name}: ${o.value} -> ${o.coerced}`),i=t+`
|
|
|
|
`+n.join(`
|
|
`);app.extensionManager.toast.add({severity:"info",summary:"Draw Things gRPC",detail:i,life:8e3});}},getConfigInputNodes(){let e={DrawThingsLoRA:[],DrawThingsControlNet:[],DrawThingsUpscaler:[],DrawThingsRefiner:[]},t=this.getInputNode(this.findInputSlot("upscaler"));t&&e.DrawThingsUpscaler.push(t);let n=this.getInputNode(this.findInputSlot("refiner"));n&&e.DrawThingsRefiner.push(n);let i=this.getInputNode(this.findInputSlot("control_net"));for(;i;)e.DrawThingsControlNet.push(i),i=i.getInputNode(i.findInputSlot("control_net"));let o=this.getInputNode(this.findInputSlot("lora"));for(;o;)e.DrawThingsLoRA.push(o),o=o.getInputNode(o.findInputSlot("lora_stack"));return e},getExtraMenuOptions(e,t){let n=app.extensionManager.setting.get("drawthings.node.keep_shrunk"),i=app.extensionManager.setting.get("drawthings.bridge_mode.enabled"),o=app.extensionManager.setting.get("drawthings.bridge_mode.community"),a=app.extensionManager.setting.get("drawthings.bridge_mode.uncurated");return t.push(null),t.push({content:"Paste Draw Things config",callback:()=>ae(this)}),t.push({content:"Copy Draw Things config",callback:()=>{let s={};for(let r of this.widgets??[]){let l=q(r.name);l&&l.export(r,this,s);}s.loras=[],s.control=[],navigator.clipboard.writeText(JSON.stringify(s));}}),t.push({content:(n?"\u2713 ":"")+"Keep node shrunk when widgets change",callback:()=>{app.extensionManager.setting.set("drawthings.node.keep_shrunk",!n);}}),t.push({content:(i?"\u2713 ":"")+"Use bridge mode",callback:()=>{app.extensionManager.setting.set("drawthings.bridge_mode.enabled",!i);}}),i&&(t.push({content:(o?"\u2713 ":"")+"Show community models",callback:()=>{app.extensionManager.setting.set("drawthings.bridge_mode.community",!o);}}),t.push({content:(a?"\u2713 ":"")+"Show uncurated models",callback:()=>{app.extensionManager.setting.set("drawthings.bridge_mode.uncurated",!a);}})),t.push(null),t}};async function me(){let e=window.comfyAPI.api.api;he=await(await e.fetchApi("/manager/preview_method")).text();let n=new FormData;n.append("preview",he),await e.fetchApi("/dt_grpc/preview",{method:"POST",body:n});}function et(e){let i=p(e,"control_name")?.value?.value,o=!!i,a=i?.modifier,s=i?.type,r=p(e,"control_input_type");d(e,"control_input_type",o&&(!a||s==="controlnetunion"));let u=i?.global_average_pooling;d(e,"global_average_pooling",u);let c=["lowquality","blur","tile"],g=r?.value,f=c.includes(a)||(g?c.includes(g.toLowerCase()):false);d(e,"down_sampling_rate",f);let _=["ipadapterplus","ipadapterfull","ipadapterfaceidplus"].includes(s)&&(i?.version==="v1"||i?.version?.startsWith("sdxl"));d(e,"target_blocks",_);}var tt={updateDynamicWidgets(){try{et(this);}catch(e){console.error(e);}},onNodeCreated(){this.updateDynamicWidgets();},onSerialize(e){e.nodePackVersion=T,this.widgets&&(e.widget_values_keyed=Object.fromEntries(this.widgets.map(t=>[t.name,t.value])));},onConfigure(e){if(e.widget_values_keyed&&this.widgets)for(let[t,n]of Object.entries(e.widget_values_keyed)){let i=this.widgets.find(o=>o.name===t);i&&(i.value=n);}else if(e.widgets_values&&e.widgets_values.length===8&&this.widgets){let t=["control_name","control_input_type","control_mode","control_weight","control_start","control_end","global_average_pooling","invert_image"];for(let n=0;n<t.length;n++){let i=this.widgets.find(o=>o.name===t[n]);i&&(i.value=e.widgets_values[n]);}}delete this.widget_values_keyed,this.updateDynamicWidgets();},onWidgetChanged(e,t,n,i){if(e==="control_name"){let o=t?.value?.modifier,a=p(this,"control_input_type");o&&a?.value!==_e(o)&&a&&(a.value=_e(o));}this.updateDynamicWidgets();}},nt={name:"controlNetNode",beforeRegisterNodeDef(e,t,n){e.comfyClass==="DrawThingsControlNet"&&h(e,tt);}},ye=nt;function _e(e){return e.charAt(0).toUpperCase()+e.slice(1)}function O(e,t,n){let i=e[t];e[t]=function(...o){let a=i?.apply(this,o);return n?.apply(this,o),a};}var it=["DrawThingsSampler","DrawThingsControlNet","DrawThingsLoRA","DrawThingsUpscaler","DrawThingsRefiner","DrawThingsPrompt"],Y=["DrawThingsSampler"],ot={name:"modelNodes",beforeRegisterNodeDef:(e,t,n)=>{it.includes(e.comfyClass)&&(h(e,st),Y.includes(e.comfyClass)?h(e,at):e.comfyClass==="DrawThingsPrompt"?h(e,lt):h(e,rt));},afterConfigureGraph(){m.updateNodes();},settings:[{id:"drawthings.bridge_mode.enabled",type:"boolean",name:"Enable bridge mode",defaultValue:true,category:["DrawThings","Bridge mode","Bridge mode"],sortOrder:2,tooltip:"With bridge mode enabled, your local models will be hidden and the official models available to DT+ will be listed. Be sure to enable Bridge Mode in your Draw Things API settings (DT+ only)",onChange:e=>{m.updateNodes();}},{id:"drawthings.bridge_mode.community",type:"boolean",name:"Show community models",defaultValue:true,category:["DrawThings","Bridge mode","Community"],sortOrder:1,tooltip:"When bridge mode is enabled, also list community models",onChange:e=>{m.updateNodes();}},{id:"drawthings.bridge_mode.uncurated",type:"boolean",name:"Show uncurated models",defaultValue:false,category:["DrawThings","Bridge mode","Uncurated"],sortOrder:0,tooltip:"When bridge mode is enabled, also list uncurated models",onChange:e=>{m.updateNodes();}}]},ve=ot,st={saveSelectedModels(){let t=(this.widgets?.filter(n=>n.options?.modelType)||[]).reduce((n,i)=>(typeof i.value=="object"||i.value==="(None selected)"?n[i.name]=i.value:n[i.name]=this._lastSelectedModel?.[i.name],n),{});this._lastSelectedModel=t;},lastSelectedModel:{get(){return this._lastSelectedModel},enumerable:true},isDtServerNode:{get(){return Y.includes(this?.comfyClass)},enumerable:true},onSerialize(e){e._lastSelectedModel=JSON.parse(JSON.stringify(this._lastSelectedModel??{}));},onConfigure(e){this._lastSelectedModel=e._lastSelectedModel||{};},getModelWidgets(){return this.widgets?.filter(e=>e.options?.modelType)||[]},onAdded(){m.updateNodes();},findServerNodes(){if(Y.includes(this.comfyClass))return [this];if(this.outputs?.length!==1)throw new Error("what node is this? Should only have a single output");function e(t){let n=[],i=t.getOutputNodes(0)??[];for(let o of i)o.isDtServerNode?n.push(o):n.push(...e(o));return n}return e(this)}},at={onNodeCreated(){let e=this.widgets?.find(i=>i.name==="server");e&&O(e,"callback",()=>m.updateNodes());let t=this.widgets?.find(i=>i.name==="port");t&&O(t,"callback",()=>m.updateNodes());let n=this.widgets?.find(i=>i.name==="use_tls");n&&O(n,"callback",()=>m.updateNodes());},getServer(){let e=this.widgets?.find(i=>i.name==="server")?.value,t=this.widgets?.find(i=>i.name==="port")?.value,n=this.widgets?.find(i=>i.name==="use_tls")?.value;return {server:e,port:t,useTls:n}},getModelVersion(){return this.widgets?.find(e=>e.options?.modelType==="models")?.value?.value?.version},updateModels(e,t){let n=this.getModelWidgets();for(let i of n){if(!i)return;if(e===null){i.options&&(i.options.values=["Not connected","Click to retry"]),i.value="Not connected";continue}if(i.options&&(i.options.values=["(None selected)",...e.models.map(o=>A(o,false)).sort((o,a)=>o.content.localeCompare(a.content))]),(i.value==="Click to retry"||i.value==="Not connected")&&(this._lastSelectedModel?.model?i.value=this._lastSelectedModel.model:i.value="(None selected)"),i.value?.toString()==="[object Object]"){let o={...i.value,toString(){return this.value.name}};i.value=o;}}}},rt={onConnectionsChange(e,t,n,i,o){n&&m.updateNodes();},updateModels(e,t=[]){let n=this.getModelWidgets();for(let i of n){if(!i)return;let o=i?.options?.modelType;if(!e?.[o]){i.options&&(i.options.values=["Not connected","Click to retry"]),i.value="Not connected";continue}if(i.options&&(i.options.values=["(None selected)",...e[o].map(a=>A(a,a.version&&t.length>0&&!t.includes(a.version))).sort((a,s)=>a.disabled&&!s.disabled?1:!a.disabled&&s.disabled?-1:a.content.toUpperCase().localeCompare(s.content.toUpperCase()))]),(i.value==="Click to retry"||i.value==="Not connected")&&(this._lastSelectedModel?.[i.name]?i.value=dt(this._lastSelectedModel[i.name]):i.value="(None selected)"),i.value?.toString()==="[object Object]"){let a={...i.value,toString(){return this.value.name}};i.value=a;}}}},lt={onConnectionsChange(e,t,n,i,o){n&&m.updateNodes();},updateModels(e,t){this._models=e?.textualInversions||null,this._version=t,this.updateOptions();},updateOptions(){let e=this.getModelWidgets();for(let t of e){if(!t)return;if(this._models===null){t.options&&(t.options.values=["Not connected","Click to retry"]),t.value="Not connected";return}let o=[...(this.widgets.find(a=>a.name==="prompt")?.value).matchAll(/<(.*?)>/gm)].map(a=>a[1]);t.options&&(t.options.values=["...",...this._models.map(a=>A(a,this._version&&this._version.length>0&&!this._version.includes(a.version)&&!o.includes(a.keyword))).map(a=>(Object.defineProperty(a,"content",{get(){return `${o.includes(a.value.keyword)?"\u2713 ":""}${a.value.name} (${a.value.version})`}}),a)).sort((a,s)=>a.disabled&&!s.disabled?1:!a.disabled&&s.disabled?-1:a.content.toUpperCase().localeCompare(s.content.toUpperCase()))]),t.value="...";}}};function dt(e){return e?.toString()==="[object Object]"?{...e,toString(){return this.value.name}}:e}var ut={onWidgetChanged(e,t,n,i){if(e==="insert_textual_inversion"){let o=t?.value?.keyword;if(!o)return;let a=`<${o}>`,s=this.widgets?.find(l=>l.name==="prompt"),r=s?.value??"";typeof r=="string"&&s&&(r.includes(a)?s.value=r.split(a).join(""):s.value=`<${o}> ${r}`),i.value="...";}},onConnectionsChange(e,t,n,i,o){if(app.extensionManager.setting.get("drawthings.node.color_prompts")===false)return;let a=false,s=false;for(let r of this.outputs?.[0]?.links??[]){let l=this.graph?.getLink(r);if(!l)continue;let u=l.target_id,c=this.graph?.getNodeById(u);if(c?.comfyClass==="DrawThingsSampler"){let g=c?.inputs?.[l.target_slot];g?.name==="positive"&&(a=true),g?.name==="negative"&&(s=true);}}a&&s?(this.color=window.LGraphCanvas.node_colors.purple.color,this.bgcolor=window.LGraphCanvas.node_colors.purple.bgcolor):a?(this.color=window.LGraphCanvas.node_colors.green.color,this.bgcolor=window.LGraphCanvas.node_colors.green.bgcolor):s?(this.color=window.LGraphCanvas.node_colors.red.color,this.bgcolor=window.LGraphCanvas.node_colors.red.bgcolor):(this.color=void 0,this.bgcolor=void 0);},onNodeCreated(){let e=this.outputs?.find(i=>i.name=="PROMPT");e&&(e.color_on=e.color_off=app.canvas.default_connection_color_byType.CONDITIONING);let t=this.widgets?.find(i=>i.name==="prompt"),n=this;t?.element&&t.element.addEventListener("change",()=>{n.updateOptions();});},getExtraMenuOptions(e,t){let n=app.extensionManager.setting.get("drawthings.node.color_prompts");t.push(null,{content:(n?"\u2713 ":"")+"Change colors when connections change",callback:async()=>{try{await app.extensionManager.setting.set("drawthings.node.color_prompts",!n);}catch(i){console.error(`Error changing setting: ${i}`);}}},null);}},ct={name:"promptNode",beforeRegisterNodeDef(e,t,n){e.comfyClass==="DrawThingsPrompt"&&h(e,ut);},settings:[{id:"drawthings.node.color_prompts",type:"boolean",name:"Change prompt node colors when connections change",defaultValue:true,category:["DrawThings","Nodes","Change prompt"],onChange:(e,t)=>{t===false&&e===true&&app.graph.nodes.filter(n=>n.type==="DrawThingsPrompt").forEach(n=>{setTimeout(()=>n.onConnectionsChange(),10);});}}]},we=ct;var x=[S,we,ve,le,ue,ye];app$1.registerExtension({name:"DrawThings-gRPC",getCustomWidgets(...e){return S.getCustomWidgets?S.getCustomWidgets.apply(S,e):{}},beforeConfigureGraph(...e){for(let t of x)try{t.beforeConfigureGraph?.apply(t,e);}catch(n){console.error(`Error in ${t.name} beforeConfigureGraph:`,n);}},beforeRegisterNodeDef(...e){for(let t of x)try{t.beforeRegisterNodeDef?.apply(t,e);}catch(n){console.error(`Error in ${t.name} beforeConfigureGraph:`,n);}},afterConfigureGraph(...e){for(let t of x)try{t.afterConfigureGraph?.apply(t,e);}catch(n){console.error(`Error in ${t.name} afterConfigureGraph:`,n);}},setup(...e){for(let t of x)try{t.setup?.apply(t,e);}catch(n){console.error(`Error in ${t.name} beforeConfigureGraph:`,n);}gt("extensions/drawthings-grpc/drawThings.css");},settings:x.flatMap(e=>e.settings??[]),aboutPageBadges:[{label:`DrawThings-gRPC v${T}`,url:"https://github.com/Jokimbe/ComfyUI-DrawThings-gRPC",icon:"dt-grpc-about-badge-logo"}]});function gt(e){return document.querySelector(`link[href^="${e}"]`)?Promise.resolve():new Promise(t=>{let n=document.createElement("link");n.setAttribute("rel","stylesheet"),n.setAttribute("type","text/css");let i=setTimeout(t,1e3);n.addEventListener("load",o=>{clearInterval(i),t();}),n.href=e,document.head.appendChild(n);})}
|
|
export{gt as injectCss};//# sourceMappingURL=extension.esm.js.map
|
|
//# sourceMappingURL=extension.esm.js.map
|