diff --git a/static/app.js b/static/app.js index 4711fc8..0d12eae 100644 --- a/static/app.js +++ b/static/app.js @@ -80,6 +80,9 @@ fileInput.addEventListener('change', () => { if (fileInput.files.length) setFile(fileInput.files[0]); }); +// Reset file input after each use so re-selecting the same file triggers change +fileInput.addEventListener('click', () => { fileInput.value = ''; }); + clearFile.addEventListener('click', e => { e.stopPropagation(); currentFile = null; @@ -105,6 +108,11 @@ function setFile(file) { dropZone.style.display = 'none'; fileInfo.style.display = 'flex'; generateBtn.disabled = false; + + // Auto-generate immediately on file select + if (currentMode === 'image') { + generateImage(); + } } // ── Sliders ────────────────────────────── @@ -317,14 +325,21 @@ function setZoom(scale) { function autoFitZoom() { requestAnimationFrame(() => { - const containerWidth = previewArea.clientWidth - 24; + // Reset to base size to measure natural dimensions previewArea.style.fontSize = '5px'; zoomScale = 1.0; - const artWidth = previewArea.scrollWidth; - if (artWidth > containerWidth && artWidth > 0) { - setZoom(containerWidth / artWidth); - } else { - zoomLevel.textContent = '100%'; + + const containerW = previewArea.clientWidth - 16; + const containerH = previewArea.clientHeight - 16; + const artW = previewArea.scrollWidth; + const artH = previewArea.scrollHeight; + + if (artW > 0 && artH > 0) { + // Scale to fill the preview area (fit the limiting dimension) + const scaleW = containerW / artW; + const scaleH = containerH / artH; + const fitScale = Math.min(scaleW, scaleH); + setZoom(Math.max(0.1, fitScale)); } }); }