diff --git a/js/dumas_resolution.js b/js/dumas_resolution.js index 9e3a8b5..62c606b 100644 --- a/js/dumas_resolution.js +++ b/js/dumas_resolution.js @@ -65,22 +65,31 @@ function injectState(result, nodes) { const style = document.createElement("style"); style.textContent = ` .dumas-res { box-sizing:border-box; width:100%; padding:6px; background:#292929; color:#ddd; font:11px system-ui; } -.dumas-res .chips { display:grid; grid-template-columns:repeat(3,1fr); gap:4px; } -.dumas-res button { min-height:26px; padding:2px 5px; border:1px solid #555; border-radius:4px; background:#1d1d1d; color:#ddd; cursor:pointer; } +.dumas-res .section { margin-top:6px; padding-top:5px; border-top:1px solid #444; } +.dumas-res .section:first-child { margin-top:0; padding-top:0; border-top:0; } +.dumas-res .section-title { margin-bottom:4px; color:#aaa; font-size:10px; font-weight:600; letter-spacing:.02em; text-transform:uppercase; } +.dumas-res .chips { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:3px; } +.dumas-res button { min-height:25px; padding:2px 4px; border:1px solid #555; border-radius:4px; background:#1d1d1d; color:#ddd; cursor:pointer; font:inherit; } .dumas-res button.active { background:#b9573d; color:white; border-color:#ef8c6d; } -.dumas-res .wide { grid-column:span 3; } -.dumas-res .sizes { margin-top:6px; display:grid; grid-template-columns:repeat(2,1fr); gap:3px; max-height:170px; overflow:auto; } -.dumas-res .size { text-align:left; font-family:ui-monospace,monospace; } +.dumas-res .sizes { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:3px; max-height:154px; overflow:auto; } +.dumas-res .size { min-height:31px; text-align:left; font-family:ui-monospace,monospace; line-height:1.15; } +.dumas-res .size small { display:block; color:#999; font-size:9px; } +.dumas-res .batch { display:grid; grid-template-columns:26px 1fr 26px; gap:3px; align-items:center; } +.dumas-res .batch button { min-height:24px; font-size:15px; line-height:1; } +.dumas-res .batch input { text-align:center; } .dumas-res .custom { display:grid; grid-template-columns:1fr 1fr; gap:4px; margin-top:6px; } .dumas-res input { width:100%; box-sizing:border-box; background:#181818; color:#eee; border:1px solid #555; border-radius:3px; padding:4px; } .dumas-res .label { grid-column:1/-1; color:#aaa; } -.dumas-res .meta { margin-top:5px; color:#9dd8a5; font-family:ui-monospace,monospace; } +.dumas-res .meta { margin-top:6px; padding-top:5px; border-top:1px solid #444; color:#9dd8a5; font-family:ui-monospace,monospace; } `; document.head.appendChild(style); function render(node, root) { const s = read(node), ratio = s.ratio || "1:1"; root.replaceChildren(); + const ratioSection = document.createElement("div"); ratioSection.className = "section"; + const ratioTitle = document.createElement("div"); ratioTitle.className = "section-title"; ratioTitle.textContent = "Aspect ratio"; + ratioSection.append(ratioTitle); const chips = document.createElement("div"); chips.className = "chips"; [...RATIOS, "custom_ratio", "custom"].forEach((id) => { const button = document.createElement("button"); @@ -88,8 +97,20 @@ function render(node, root) { button.className = (s.mode === "preset" && id === ratio) || (s.mode === id) ? "active" : ""; button.dataset.id = id; chips.append(button); }); - root.append(chips); + ratioSection.append(chips); root.append(ratioSection); + const batchSection = document.createElement("div"); batchSection.className = "section"; + const batchTitle = document.createElement("div"); batchTitle.className = "section-title"; batchTitle.textContent = "Batch"; + const batch = document.createElement("div"); batch.className = "batch"; + for (const [text, delta] of [["−", -1], ["+", 1]]) { + const button = document.createElement("button"); button.textContent = text; button.dataset.batchDelta = delta; batch.append(button); + if (delta < 0) batch.prepend(button); + } + const batchInput = document.createElement("input"); batchInput.type = "number"; batchInput.min = "1"; batchInput.max = "64"; batchInput.step = "1"; batchInput.value = Math.max(1, Math.min(64, Number(s.batch) || 1)); batchInput.dataset.key = "batch"; + batch.insertBefore(batchInput, batch.lastChild); + batchSection.append(batchTitle, batch); root.append(batchSection); if (s.mode === "custom" || s.mode === "custom_ratio") { + const customSection = document.createElement("div"); customSection.className = "section"; + const customTitle = document.createElement("div"); customTitle.className = "section-title"; customTitle.textContent = s.mode === "custom" ? "Custom resolution" : "Custom ratio"; const panel = document.createElement("div"); panel.className = "custom"; const label = document.createElement("div"); label.className = "label"; label.textContent = s.mode === "custom" ? "Custom resolution · snap" : "Custom ratio · width · snap"; @@ -98,11 +119,13 @@ function render(node, root) { for (const [key, text] of fields) { const input=document.createElement("input"); input.dataset.key=key; input.title=text; input.value=s[key]; input.placeholder=text; panel.append(input); } const snapLabel=document.createElement("div"); snapLabel.className="label"; snapLabel.textContent="Snap step"; panel.append(snapLabel); for (const step of [8,16,32,64]) { const b=document.createElement("button"); b.textContent=`${step}px`; b.dataset.snap=step; b.className=Number(s.snap)===step?"active":""; panel.append(b); } - root.append(panel); + customSection.append(customTitle, panel); root.append(customSection); } else { + const sizeSection = document.createElement("div"); sizeSection.className = "section"; + const sizeTitle = document.createElement("div"); sizeTitle.className = "section-title"; sizeTitle.textContent = `Resolution presets · ${ratio}`; const sizes = document.createElement("div"); sizes.className="sizes"; - for (const [w,h] of (SIZES[ratio] || [])) { const b=document.createElement("button"); b.className="size"; b.dataset.w=w; b.dataset.h=h; b.textContent=`${w} × ${h} (${(w*h/1e6).toFixed(2)} MP)`; if (w===Number(s.w)&&h===Number(s.h)) b.classList.add("active"); sizes.append(b); } - root.append(sizes); + for (const [w,h] of (SIZES[ratio] || [])) { const b=document.createElement("button"); b.className="size"; b.dataset.w=w; b.dataset.h=h; b.innerHTML=`${w} × ${h}${(w*h/1e6).toFixed(2)} MP`; if (w===Number(s.w)&&h===Number(s.h)) b.classList.add("active"); sizes.append(b); } + sizeSection.append(sizeTitle, sizes); root.append(sizeSection); } const meta=document.createElement("div"); meta.className="meta"; meta.textContent=`Output ${s.w} × ${s.h} · ${(s.w*s.h/1e6).toFixed(2)} MP · batch ${Math.max(1,Math.min(64,Number(s.batch)||1))}`; root.append(meta); } @@ -115,6 +138,7 @@ function setup(node) { root.addEventListener("click", (event) => { const button=event.target.closest("button"); if (!button) return; const s=read(node), id=button.dataset.id; + if (button.dataset.batchDelta) { s.batch=Math.max(1,Math.min(64,(Number(s.batch)||1)+Number(button.dataset.batchDelta))); write(node,s); render(node,root); return; } if (id && SIZES[id]) { const [w,h]=DEFAULT_SIZE[id]; write(node,{...s,mode:"preset",ratio:id,w,h}); } else if (id === "custom") write(node,{...s,mode:"custom",w:s.custom_w,h:s.custom_h}); else if (id === "custom_ratio") write(node,{...s,mode:"custom_ratio",w:ratioPair(s.w,s.custom_ratio_w,s.custom_ratio_h,s.snap)[0],h:ratioPair(s.w,s.custom_ratio_w,s.custom_ratio_h,s.snap)[1]}); @@ -122,8 +146,8 @@ function setup(node) { else if (button.dataset.snap) { const step=Number(button.dataset.snap); const next={...s,snap:step}; if(s.mode==="custom") { next.w=snap(clamp(s.custom_w),step); next.h=snap(clamp(s.custom_h),step); } else if(s.mode==="custom_ratio") [next.w,next.h]=ratioPair(s.w,s.custom_ratio_w,s.custom_ratio_h,step); write(node,next); return; } render(node,root); }); - root.addEventListener("change", (event) => { const key=event.target.dataset.key; if(!key)return; const s=read(node), value=Math.max(1,Math.min(16384,Number(event.target.value)||1)); s[key]=value; if(s.mode==="custom") { s.w=snap(clamp(s.custom_w),s.snap); s.h=snap(clamp(s.custom_h),s.snap); } else { [s.w,s.h]=ratioPair(s.w,s.custom_ratio_w,s.custom_ratio_h,s.snap); } write(node,s); render(node,root); }); - node._dumasResolutionRoot=root; node.size=[280,300]; queueMicrotask(()=>render(node,root)); + root.addEventListener("change", (event) => { const key=event.target.dataset.key; if(!key)return; const s=read(node), value=key==="batch" ? Math.max(1,Math.min(64,Number(event.target.value)||1)) : Math.max(1,Math.min(16384,Number(event.target.value)||1)); s[key]=value; if(s.mode==="custom") { s.w=snap(clamp(s.custom_w),s.snap); s.h=snap(clamp(s.custom_h),s.snap); } else if(s.mode==="custom_ratio") { [s.w,s.h]=ratioPair(s.w,s.custom_ratio_w,s.custom_ratio_h,s.snap); } write(node,s); render(node,root); }); + node._dumasResolutionRoot=root; node.size=[300,390]; queueMicrotask(()=>render(node,root)); } const originalGraphToPrompt=app.graphToPrompt?.bind(app); @@ -137,7 +161,7 @@ app.registerExtension({ if(nodeData?.name!==CLASS)return; const oldConfigure=nodeType.prototype.onConfigure; nodeType.prototype.onConfigure=function(...args){const result=oldConfigure?.apply(this,args); if(this._dumasResolutionRoot)render(this,this._dumasResolutionRoot); return result;}; - nodeType.prototype.onResize=function(){this.size=[280,300];}; + nodeType.prototype.onResize=function(){this.size=[300,390];}; }, nodeCreated(node){if(node.comfyClass===CLASS)setup(node);}, });