Complete custom ratio resolution controls
This commit is contained in:
+31
-6
@@ -82,6 +82,15 @@ style.textContent = `
|
||||
.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 .custom-row { display:grid; grid-template-columns:1fr 28px 1fr; gap:4px; grid-column:1/-1; }
|
||||
.dumas-res .custom-row button { min-height:28px; }
|
||||
.dumas-res .custom-row input { min-width:0; }
|
||||
.dumas-res .target-row { display:grid; grid-template-columns:repeat(4,1fr); gap:3px; grid-column:1/-1; }
|
||||
.dumas-res .target-row button { min-height:25px; }
|
||||
.dumas-res .dimension-row { display:grid; grid-template-columns:1fr 1fr; gap:4px; grid-column:1/-1; }
|
||||
.dumas-res .dimension-row input { color:#9dd8a5; text-align:center; }
|
||||
.dumas-res .preview { grid-column:1/-1; display:flex; justify-content:center; align-items:center; min-height:38px; margin-top:2px; }
|
||||
.dumas-res .preview-shape { border:1px solid #8cc63f; background:#273b1c; max-width:100%; max-height:42px; }
|
||||
.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:6px; padding-top:5px; border-top:1px solid #444; color:#9dd8a5; font-family:ui-monospace,monospace; }
|
||||
@@ -122,11 +131,25 @@ function render(node, root) {
|
||||
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";
|
||||
panel.append(label);
|
||||
const fields = s.mode === "custom" ? [["custom_w", "Width"],["custom_h", "Height"]] : [["custom_ratio_w", "Ratio W"],["custom_ratio_h", "Ratio H"]];
|
||||
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 label = document.createElement("div"); label.className = "label"; label.textContent = s.mode === "custom" ? "Width · height · snap" : "Ratio · target width · snap"; panel.append(label);
|
||||
if (s.mode === "custom_ratio") {
|
||||
const ratioRow = document.createElement("div"); ratioRow.className = "custom-row";
|
||||
for (const key of ["custom_ratio_w", "custom_ratio_h"]) { const input=document.createElement("input"); input.dataset.key=key; input.type="number"; input.min="1"; input.value=s[key]; ratioRow.append(input); if (key === "custom_ratio_w") { const swap=document.createElement("button"); swap.textContent="⇄"; swap.title="Swap ratio"; swap.dataset.swapRatio="1"; ratioRow.append(swap); } }
|
||||
panel.append(ratioRow);
|
||||
const targetLabel=document.createElement("div"); targetLabel.className="label"; targetLabel.textContent="Target width"; panel.append(targetLabel);
|
||||
const targets=document.createElement("div"); targets.className="target-row";
|
||||
for (const width of [512,768,1024,1536]) { const b=document.createElement("button"); b.textContent=width; b.dataset.widthTarget=width; if(Number(s.w)===width) b.classList.add("active"); targets.append(b); }
|
||||
panel.append(targets);
|
||||
const dimensionLabel=document.createElement("div"); dimensionLabel.className="label"; dimensionLabel.textContent="Output dimensions"; panel.append(dimensionLabel);
|
||||
const dimensions=document.createElement("div"); dimensions.className="dimension-row";
|
||||
const widthInput=document.createElement("input"); widthInput.type="number"; widthInput.dataset.key="w"; widthInput.value=s.w; widthInput.title="Width";
|
||||
const heightInput=document.createElement("input"); heightInput.type="number"; heightInput.value=s.h; heightInput.title="Height"; heightInput.readOnly=true;
|
||||
dimensions.append(widthInput,heightInput); panel.append(dimensions);
|
||||
const preview=document.createElement("div"); preview.className="preview"; const shape=document.createElement("div"); shape.className="preview-shape"; shape.style.aspectRatio=`${Math.max(1,Number(s.w))} / ${Math.max(1,Number(s.h))}`; shape.style.width=`${Math.min(90, Math.max(34, 90 * Number(s.w) / Math.max(Number(s.h), Number(s.w)))}px)`; shape.style.height="42px"; preview.append(shape); panel.append(preview);
|
||||
} else {
|
||||
const fields = [["custom_w", "Width"],["custom_h", "Height"]];
|
||||
for (const [key, text] of fields) { const input=document.createElement("input"); input.dataset.key=key; input.type="number"; 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); }
|
||||
customSection.append(customTitle, panel); root.append(customSection);
|
||||
@@ -152,6 +175,8 @@ function setup(node) {
|
||||
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 (button.dataset.swapRatio) { [s.custom_ratio_w,s.custom_ratio_h]=[s.custom_ratio_h,s.custom_ratio_w]; [s.w,s.h]=ratioPair(s.w,s.custom_ratio_w,s.custom_ratio_h,s.snap); write(node,s); render(node,root); return; }
|
||||
if (button.dataset.widthTarget) { s.w=snap(clamp(Number(button.dataset.widthTarget)),s.snap); [s.w,s.h]=ratioPair(s.w,s.custom_ratio_w,s.custom_ratio_h,s.snap); 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]});
|
||||
@@ -159,7 +184,7 @@ 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=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); });
|
||||
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(key==="w" ? value : s.w,s.custom_ratio_w,s.custom_ratio_h,s.snap); } write(node,s); render(node,root); });
|
||||
node._dumasResolutionRoot=root; node.size=[300,640]; queueMicrotask(()=>render(node,root));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user