Auto-generate on upload, fill preview, fix re-upload

- Auto-generate: selecting a file immediately renders it (no separate
  Generate click needed)
- Auto-fit zoom now scales UP to fill the preview area, not just down
  to fit width. Uses min(scaleW, scaleH) to fit the limiting dimension.
- Fix re-upload: reset fileInput.value on click so selecting the same
  file again triggers the change event
- Patterns also auto-fit to fill the preview

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-04-02 17:06:25 +00:00
parent 3176a36ce6
commit 82192346d0
1 changed files with 21 additions and 6 deletions

View File

@ -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));
}
});
}