Files

2 lines
2.4 KiB
JavaScript

(function(z,k){"use strict";const w={name:"smallutility.choose_latent_size",beforeRegisterNodeDef(o,s,t){if(s.name==="EmptyLatentImage"){const e=o.prototype.getExtraMenuOptions;o.prototype.getExtraMenuOptions=function(n,i){return e==null||e.apply(this,[n,i]),i.push({content:"SDXL Sizes",has_submenu:!0,callback(a,p,l,c,r){new k.ContextMenu(["768x1344","1024x1024","1344x768"],{event:l,callback(u,f,g,C,h){var b,x;const[N,D]=u.split("x").map(m=>parseInt(m)),v=(b=h==null?void 0:h.widgets)==null?void 0:b.find(m=>m.name==="width"),y=(x=h==null?void 0:h.widgets)==null?void 0:x.find(m=>m.name==="height");v&&(v.value=N),y&&(y.value=D)},parentMenu:c,node:r})}}),i}}}},d={name:"smallutility.eval_node",beforeRegisterNodeDef(o,s,t){if(s.name==="Eval"){const e=o.prototype.onNodeCreated;o.prototype.onNodeCreated=function(){e==null||e.apply(this),this.addWidget("STRING","result_type","*",function(n,i,a){if(typeof n=="string"||!a)return;const p=a.outputs;for(const l of p)l.name=n,l.type=n,l.localized_name=n})},o.prototype.onConnectionsChange=function(n,i,a,p,l){if(p&&n==1){!a&&this.inputs[i].name!=="cmd"&&this.removeInput(i);let c=0;for(let u=0;u<this.inputs.length;u++)this.inputs[u].name!=="cmd"&&(c++,this.inputs[u].name=`input${c}`);let r=this.inputs[this.inputs.length-1];r.name==="cmd"&&(r=this.inputs[this.inputs.length-2]),r.link&&(c++,this.addInput(`input${c}`,"*",{shape:7}))}}}}},E={name:"smallutility.sort_prompt",beforeRegisterNodeDef(o,s,t){const e=o.prototype.getExtraMenuOptions;o.prototype.getExtraMenuOptions=function(n,i){return e==null||e.apply(this,[n,i]),i.push({content:"sort prompt",callback(a,p,l,c,r){var u;(u=r==null?void 0:r.widgets)==null||u.forEach(f=>{if(typeof f.value=="string"&&f.type!=="combo")try{f&&(f.value=I(f.value))}catch(g){console.log(g)}})}}),i}}},I=o=>{let s=[],t="",e=!1;const n=[];for(const i of o)switch(i){case"(":if(e)t+=i,e=!1;else{const a=s;s=[],n.push(a),a.push(s)}break;case")":if(e)t+=i,e=!1;else{t=t.trim();let a=/:\d+(\.\d+)?/.exec(t),p=null;for(a&&(t=t.substring(0,a.index),p=a[0]),t&&s.push(t),t=s.sort().join(", "),p&&(t+=p);s.length>0;)s.pop();s=n.pop(),s.pop(),s.push(`(${t})`),t=""}break;case",":e=!1,t=t.trim(),t&&s.push(t),t="";break;case"\\":e=!e,t+=i;break;default:t+=i,e=!1;break}return t=t.trim(),t&&s.push(t),t=s.sort().join(", "),t&&(t+=", "),t},_=window.comfyAPI.app.app;_.registerExtension(w),_.registerExtension(E),_.registerExtension(d)})(null,LiteGraph);