diff --git a/.gitignore b/.gitignore index f25b6a2..01e8619 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.log # Caches and runtime sessions +.superpowers/ /__pycache__/ *.py[cod] .pytest_cache/ diff --git a/cmd/image-manipulator/app.js b/cmd/image-manipulator/app.js index f0df292..8ec8a54 100644 --- a/cmd/image-manipulator/app.js +++ b/cmd/image-manipulator/app.js @@ -313,10 +313,80 @@ function renderActiveImage() { }; } +// ═══════════════════════════════════════════════════════════════════ +// DOWNLOAD / EXPORT UTILITIES (Single & Batch) +// ═══════════════════════════════════════════════════════════════════ +async function downloadImageItem(item) { + if (!item || (!item.dataUrl && !item.file)) { + showToast("No image available to download", "error"); + return; + } + try { + let blob; + if (item.dataUrl) { + const res = await fetch(item.dataUrl); + blob = await res.blob(); + } else if (item.file instanceof Blob) { + blob = item.file; + } + + if (!blob) { + showToast("Failed to prepare image blob for download", "error"); + return; + } + + let filename = item.name || "processed_image"; + if (filename.includes("/")) { + filename = filename.substring(filename.lastIndexOf("/") + 1); + } + const mimeExtMap = { + "image/jpeg": ".jpg", + "image/png": ".png", + "image/webp": ".webp", + "image/avif": ".avif", + "image/bmp": ".bmp", + "image/tiff": ".tiff" + }; + if (blob.type && mimeExtMap[blob.type]) { + const expectedExt = mimeExtMap[blob.type]; + const curExt = filename.substring(filename.lastIndexOf(".")).toLowerCase(); + if (!curExt || (curExt !== expectedExt && !(expectedExt === ".jpg" && curExt === ".jpeg"))) { + filename = filename.replace(/\.[^/.]+$/, "") + expectedExt; + } + } + + const blobUrl = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = blobUrl; + a.download = filename; + document.body.appendChild(a); + a.click(); + a.remove(); + setTimeout(() => window.URL.revokeObjectURL(blobUrl), 2000); + showToast(`Downloaded ${filename}`, "success"); + } catch (err) { + showToast(`Download failed: ${err.message}`, "error"); + } +} +window.downloadImageItem = downloadImageItem; + +function downloadActiveImage() { + if (!filesList || filesList.length === 0) { + showToast("No image open to download", "error"); + return; + } + const cur = filesList[activeIndex]; + if (!cur) return; + downloadImageItem(cur); +} +window.downloadActiveImage = downloadActiveImage; + function updateQueueUI() { const counterPill = document.getElementById("ps-file-counter"); const btnBatchHeader = document.getElementById("btn-batch-all"); const btnBatchFooter = document.getElementById("btn-batch-footer"); + const btnDownloadHeader = document.getElementById("btn-download-active"); + const btnDownloadFooter = document.getElementById("btn-download-footer"); const hubCount = document.getElementById("batch-hub-count"); const hubSize = document.getElementById("batch-hub-size"); @@ -330,6 +400,14 @@ function updateQueueUI() { else counterPill.classList.remove("has-files"); } + // Show Download button whenever there is at least 1 image loaded + if (btnDownloadHeader) { + btnDownloadHeader.style.display = count > 0 ? "inline-flex" : "none"; + } + if (btnDownloadFooter) { + btnDownloadFooter.style.display = count > 0 ? "inline-flex" : "none"; + } + if (btnBatchHeader) { if (count > 1) { btnBatchHeader.style.display = "inline-flex"; @@ -369,9 +447,14 @@ function renderFilmstrip() { ${item.name} ${item.naturalW}×${item.naturalH} · ${sizeKb}KB - +
+ + +
`; tray.appendChild(card); }); @@ -1960,13 +2043,20 @@ async function executeEndpointRequest(endpoint, formData) { // Re-convert data URI to Blob to update File reference const blob = await (await fetch(resItem.image)).blob(); - cur.file = new File([blob], resItem.filename || cur.name, { type: blob.type }); + const finalName = resItem.filename || cur.name; + cur.name = finalName; + cur.file = new File([blob], finalName, { type: blob.type }); cur.size = blob.size; pushHistorySnapshot(currentTool.toUpperCase() + " applied", resItem.image, cur.naturalW, cur.naturalH); renderActiveImage(); updateSplitImages(); - showToast("Transformation applied successfully!", "success"); + renderFilmstrip(); + updateInspectorInfo(cur); + + // Auto-download single image output directly + await downloadImageItem(cur); + showToast("Transformation applied & image downloaded!", "success"); } else { showToast(data.error || "Transformation failed", "error"); } @@ -2372,6 +2462,18 @@ function setupKeyboardShortcuts() { return; } + if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "s") { + e.preventDefault(); + downloadActiveImage(); + return; + } + + // Do NOT intercept any browser or OS modifier shortcuts (Ctrl, Meta/Cmd, Alt) + // This allows Ctrl+R, Ctrl+Shift+R, Ctrl+F, Ctrl+Z, Ctrl+C, etc. to work natively! + if (e.ctrlKey || e.metaKey || e.altKey) { + return; + } + if (e.key === "Escape") { closeBatchModal(); return; diff --git a/cmd/image-manipulator/index.html b/cmd/image-manipulator/index.html index b13ff95..271b443 100644 --- a/cmd/image-manipulator/index.html +++ b/cmd/image-manipulator/index.html @@ -70,6 +70,9 @@ + @@ -379,9 +382,12 @@ - +
+ + +
`; tray.appendChild(card); }); @@ -1960,13 +2043,20 @@ async function executeEndpointRequest(endpoint, formData) { // Re-convert data URI to Blob to update File reference const blob = await (await fetch(resItem.image)).blob(); - cur.file = new File([blob], resItem.filename || cur.name, { type: blob.type }); + const finalName = resItem.filename || cur.name; + cur.name = finalName; + cur.file = new File([blob], finalName, { type: blob.type }); cur.size = blob.size; pushHistorySnapshot(currentTool.toUpperCase() + " applied", resItem.image, cur.naturalW, cur.naturalH); renderActiveImage(); updateSplitImages(); - showToast("Transformation applied successfully!", "success"); + renderFilmstrip(); + updateInspectorInfo(cur); + + // Auto-download single image output directly + await downloadImageItem(cur); + showToast("Transformation applied & image downloaded!", "success"); } else { showToast(data.error || "Transformation failed", "error"); } @@ -2372,6 +2462,18 @@ function setupKeyboardShortcuts() { return; } + if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "s") { + e.preventDefault(); + downloadActiveImage(); + return; + } + + // Do NOT intercept any browser or OS modifier shortcuts (Ctrl, Meta/Cmd, Alt) + // This allows Ctrl+R, Ctrl+Shift+R, Ctrl+F, Ctrl+Z, Ctrl+C, etc. to work natively! + if (e.ctrlKey || e.metaKey || e.altKey) { + return; + } + if (e.key === "Escape") { closeBatchModal(); return; diff --git a/web/image-manipulator/index.html b/web/image-manipulator/index.html index b13ff95..271b443 100644 --- a/web/image-manipulator/index.html +++ b/web/image-manipulator/index.html @@ -70,6 +70,9 @@ + @@ -379,9 +382,12 @@