Spaces:
Running
Running
Update index.html
Browse files- index.html +28 -34
index.html
CHANGED
|
@@ -87,7 +87,6 @@
|
|
| 87 |
}
|
| 88 |
.form-label svg { width: 24px; height: 24px; color: var(--accent-primary); }
|
| 89 |
|
| 90 |
-
/* --- CHANGE 1: Uploader styles completely reworked for single-panel preview --- */
|
| 91 |
#upload-area {
|
| 92 |
position: relative;
|
| 93 |
border: 2px dashed var(--input-border);
|
|
@@ -102,7 +101,7 @@
|
|
| 102 |
flex-direction: column;
|
| 103 |
justify-content: center;
|
| 104 |
align-items: center;
|
| 105 |
-
overflow: hidden;
|
| 106 |
}
|
| 107 |
#upload-area.drag-over, #upload-area:hover:not(.has-file) {
|
| 108 |
border-color: var(--accent-primary);
|
|
@@ -126,16 +125,16 @@
|
|
| 126 |
#upload-area p { margin: 0; color: var(--text-secondary); font-weight: 500; }
|
| 127 |
|
| 128 |
#preview-image-main {
|
| 129 |
-
display: none;
|
| 130 |
width: 100%;
|
| 131 |
height: 100%;
|
| 132 |
-
object-fit: contain;
|
| 133 |
position: absolute;
|
| 134 |
top: 0;
|
| 135 |
left: 0;
|
| 136 |
}
|
| 137 |
#remove-file-btn-main {
|
| 138 |
-
display: none;
|
| 139 |
position: absolute;
|
| 140 |
top: 12px;
|
| 141 |
right: 12px;
|
|
@@ -157,13 +156,11 @@
|
|
| 157 |
transform: scale(1.1);
|
| 158 |
}
|
| 159 |
|
| 160 |
-
/* Logic to show/hide elements based on state */
|
| 161 |
#upload-area.has-file #upload-content { display: none; }
|
| 162 |
#upload-area.has-file #preview-image-main,
|
| 163 |
#upload-area.has-file #remove-file-btn-main {
|
| 164 |
display: block;
|
| 165 |
}
|
| 166 |
-
/* End of CHANGE 1 */
|
| 167 |
|
| 168 |
textarea { width: 100%; padding: 1rem 1.2rem; border-radius: var(--radius-input); border: 1px solid var(--input-border); background-color: var(--input-bg); color: var(--text-primary); box-shadow: var(--shadow-sm) inset; font-family: var(--app-font); font-size: 1rem; box-sizing: border-box; transition: var(--transition-smooth); min-height: 90px; resize: vertical; }
|
| 169 |
textarea:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-primary-glow), var(--shadow-sm) inset; background-color: var(--panel-bg); }
|
|
@@ -189,21 +186,33 @@
|
|
| 189 |
#result-grid img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: var(--radius-input); cursor: pointer; transition: var(--transition-smooth); box-shadow: var(--shadow-md); border: 1px solid var(--panel-border); }
|
| 190 |
#result-grid img:hover { transform: scale(1.05); box-shadow: var(--shadow-lg); z-index: 10; position: relative; }
|
| 191 |
#error-message { color: var(--danger-color); text-align: center; margin-top: 1rem; display: none; font-weight: 500; }
|
|
|
|
|
|
|
| 192 |
.gallery-header { display: flex; justify-content: space-between; align-items: center; }
|
| 193 |
#clear-history-btn { background: none; border: 1px solid var(--panel-border); color: var(--text-secondary); padding: 0.5rem 1rem; border-radius: var(--radius-btn); cursor: pointer; display: none; align-items: center; gap: 0.5rem; font-family: var(--app-font); font-weight: 500; transition: all 0.2s; }
|
| 194 |
#clear-history-btn:hover { border-color: var(--danger-color); color: var(--danger-color); }
|
| 195 |
#clear-history-btn svg { width: 18px; height: 18px; }
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
#history-grid:empty::before { content: 'هنوز تصویری خلق نکردهاید. اولین ویرایش شما اینجا ذخیره خواهد شد.'; color: var(--text-secondary); grid-column: 1 / -1; text-align: center; padding: 3rem 1rem; background-color: var(--input-bg); border-radius: var(--radius-card); }
|
| 198 |
-
.history-item { position: relative; background-color: var(--input-bg); border-radius: var(--radius-card); border: 1px solid var(--panel-border); padding: 1.5rem; transition: var(--transition-smooth); }
|
| 199 |
.history-item:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }
|
| 200 |
.history-item-prompt { font-weight: 600; margin: 0 0 1rem 0; word-break: break-word; padding-left: 30px; }
|
| 201 |
-
.history-item-grid { display: grid; grid-template-columns: repeat(
|
| 202 |
.history-item-grid img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: var(--radius-input); cursor: pointer; transition: transform 0.2s ease, box-shadow 0.2s ease; border: 1px solid var(--panel-border); }
|
| 203 |
.history-item-grid img:hover { transform: scale(1.1); box-shadow: var(--shadow-md); z-index: 5; position: relative; }
|
| 204 |
.history-delete-btn { position: absolute; top: 1rem; left: 1rem; background: none; border: none; cursor: pointer; padding: 0.5rem; border-radius: 50%; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--text-tertiary); transition: var(--transition-smooth); }
|
| 205 |
.history-delete-btn:hover { background-color: var(--panel-border); color: var(--danger-color); }
|
| 206 |
.history-delete-btn svg { width: 18px; height: 18px; }
|
|
|
|
|
|
|
| 207 |
#lightbox { position: fixed; inset: 0; background-color: rgba(18, 24, 38, 0.6); backdrop-filter: blur(10px) saturate(150%); display: none; align-items: center; justify-content: center; z-index: 1000; opacity: 0; transition: opacity 0.3s; }
|
| 208 |
#lightbox.visible { display: flex; opacity: 1; }
|
| 209 |
#lightbox-content { position: relative; animation: fadeIn 0.3s ease; }
|
|
@@ -213,13 +222,15 @@
|
|
| 213 |
#lightbox-close { top: -50px; right: 0; font-size: 1.8rem; }
|
| 214 |
#lightbox-download { top: -50px; left: 0; }
|
| 215 |
#lightbox-download svg { width: 22px; height: 22px; }
|
| 216 |
-
/* --- CHANGE 2: Restored spinner for download button --- */
|
| 217 |
#lightbox-download .spinner { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: none; }
|
| 218 |
|
| 219 |
@media (max-width: 768px) {
|
| 220 |
main, .gallery-section { padding: 1.5rem; }
|
| 221 |
h1 { font-size: 2.2rem; }
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
| 223 |
}
|
| 224 |
</style>
|
| 225 |
</head>
|
|
@@ -236,14 +247,11 @@
|
|
| 236 |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4Z"/></svg>
|
| 237 |
۱. تصویر خود را انتخاب کنید
|
| 238 |
</div>
|
| 239 |
-
<!-- --- CHANGE 1: Reworked HTML for single-panel uploader/preview --- -->
|
| 240 |
<label id="upload-area" for="file-input">
|
| 241 |
-
<!-- State 1: Uploader prompt -->
|
| 242 |
<div id="upload-content">
|
| 243 |
<div id="upload-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg></div>
|
| 244 |
<p>فایل تصویر را اینجا بکشید یا برای انتخاب کلیک کنید</p>
|
| 245 |
</div>
|
| 246 |
-
<!-- State 2: Image Preview -->
|
| 247 |
<img id="preview-image-main" src="" alt="Preview">
|
| 248 |
<button type="button" id="remove-file-btn-main" title="حذف تصویر">×</button>
|
| 249 |
</label>
|
|
@@ -297,7 +305,6 @@
|
|
| 297 |
<div id="lightbox-content">
|
| 298 |
<img id="lightbox-img" src="">
|
| 299 |
<button id="lightbox-close" class="lightbox-btn">×</button>
|
| 300 |
-
<!-- --- CHANGE 2: Download button is now a button, not a link, and will be handled by JS --- -->
|
| 301 |
<button id="lightbox-download" title="دانلود تصویر" class="lightbox-btn">
|
| 302 |
<svg fill="white" viewBox="0 0 24 24"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"/></svg>
|
| 303 |
<div class="spinner"></div>
|
|
@@ -308,7 +315,6 @@
|
|
| 308 |
<script>
|
| 309 |
const API_URL = 'https://alfa-editor-worker.onrender.com/api/edit';
|
| 310 |
|
| 311 |
-
// --- CHANGE 1: Updated element selectors for the new uploader ---
|
| 312 |
const uploadArea = document.getElementById('upload-area');
|
| 313 |
const fileInput = document.getElementById('file-input');
|
| 314 |
const previewImage = document.getElementById('preview-image-main');
|
|
@@ -329,9 +335,8 @@
|
|
| 329 |
const clearHistoryBtn = document.getElementById('clear-history-btn');
|
| 330 |
|
| 331 |
let uploadedFile = null;
|
| 332 |
-
let currentLightboxUrl = null;
|
| 333 |
|
| 334 |
-
// --- Uploader Logic (Reworked for new structure) ---
|
| 335 |
const resetUploader = () => {
|
| 336 |
uploadedFile = null;
|
| 337 |
fileInput.value = '';
|
|
@@ -353,9 +358,8 @@
|
|
| 353 |
clearResult();
|
| 354 |
};
|
| 355 |
|
| 356 |
-
// Event listener for the new remove button
|
| 357 |
removeFileBtn.addEventListener('click', (e) => {
|
| 358 |
-
e.preventDefault();
|
| 359 |
e.stopPropagation();
|
| 360 |
resetUploader();
|
| 361 |
});
|
|
@@ -366,7 +370,6 @@
|
|
| 366 |
['dragleave', 'drop'].forEach(e => uploadArea.addEventListener(e, () => uploadArea.classList.remove('drag-over')));
|
| 367 |
uploadArea.addEventListener('drop', e => { if (!uploadArea.classList.contains('has-file')) handleFile(e.dataTransfer.files[0]); });
|
| 368 |
|
| 369 |
-
// --- Form & Submission ---
|
| 370 |
promptInput.addEventListener('input', checkFormState);
|
| 371 |
function checkFormState() { submitBtn.disabled = !uploadedFile || promptInput.value.trim() === ''; }
|
| 372 |
submitBtn.addEventListener('click', async () => {
|
|
@@ -427,15 +430,14 @@
|
|
| 427 |
errorMessage.style.display = 'block';
|
| 428 |
}
|
| 429 |
|
| 430 |
-
// --- CHANGE 2: Re-implemented robust download and lightbox logic ---
|
| 431 |
function openLightbox(url) {
|
| 432 |
-
currentLightboxUrl = url;
|
| 433 |
lightboxImg.src = url;
|
| 434 |
lightbox.classList.add('visible');
|
| 435 |
}
|
| 436 |
function closeLightbox() {
|
| 437 |
lightbox.classList.remove('visible');
|
| 438 |
-
currentLightboxUrl = null;
|
| 439 |
}
|
| 440 |
async function handleDownload() {
|
| 441 |
if (!currentLightboxUrl) return;
|
|
@@ -448,22 +450,15 @@
|
|
| 448 |
lightboxDownload.disabled = true;
|
| 449 |
|
| 450 |
try {
|
| 451 |
-
// Fetch the image data
|
| 452 |
const response = await fetch(currentLightboxUrl);
|
| 453 |
if (!response.ok) throw new Error('Network response was not ok.');
|
| 454 |
-
|
| 455 |
-
// Convert it to a blob
|
| 456 |
const blob = await response.blob();
|
| 457 |
-
|
| 458 |
-
// Create a temporary link to trigger the download
|
| 459 |
const objectUrl = URL.createObjectURL(blob);
|
| 460 |
const a = document.createElement('a');
|
| 461 |
a.href = objectUrl;
|
| 462 |
-
a.download = `ai-edited-image-${Date.now()}.png`;
|
| 463 |
document.body.appendChild(a);
|
| 464 |
a.click();
|
| 465 |
-
|
| 466 |
-
// Clean up
|
| 467 |
document.body.removeChild(a);
|
| 468 |
URL.revokeObjectURL(objectUrl);
|
| 469 |
} catch (e) {
|
|
@@ -479,7 +474,6 @@
|
|
| 479 |
lightbox.addEventListener('click', (e) => { if (e.target === lightbox) closeLightbox(); });
|
| 480 |
lightboxDownload.addEventListener('click', handleDownload);
|
| 481 |
|
| 482 |
-
// --- History Management (No changes needed here) ---
|
| 483 |
const getHistory = () => JSON.parse(localStorage.getItem('aiPhotoshopHistory') || '[]');
|
| 484 |
const saveHistory = (history) => {
|
| 485 |
localStorage.setItem('aiPhotoshopHistory', JSON.stringify(history));
|
|
|
|
| 87 |
}
|
| 88 |
.form-label svg { width: 24px; height: 24px; color: var(--accent-primary); }
|
| 89 |
|
|
|
|
| 90 |
#upload-area {
|
| 91 |
position: relative;
|
| 92 |
border: 2px dashed var(--input-border);
|
|
|
|
| 101 |
flex-direction: column;
|
| 102 |
justify-content: center;
|
| 103 |
align-items: center;
|
| 104 |
+
overflow: hidden;
|
| 105 |
}
|
| 106 |
#upload-area.drag-over, #upload-area:hover:not(.has-file) {
|
| 107 |
border-color: var(--accent-primary);
|
|
|
|
| 125 |
#upload-area p { margin: 0; color: var(--text-secondary); font-weight: 500; }
|
| 126 |
|
| 127 |
#preview-image-main {
|
| 128 |
+
display: none;
|
| 129 |
width: 100%;
|
| 130 |
height: 100%;
|
| 131 |
+
object-fit: contain;
|
| 132 |
position: absolute;
|
| 133 |
top: 0;
|
| 134 |
left: 0;
|
| 135 |
}
|
| 136 |
#remove-file-btn-main {
|
| 137 |
+
display: none;
|
| 138 |
position: absolute;
|
| 139 |
top: 12px;
|
| 140 |
right: 12px;
|
|
|
|
| 156 |
transform: scale(1.1);
|
| 157 |
}
|
| 158 |
|
|
|
|
| 159 |
#upload-area.has-file #upload-content { display: none; }
|
| 160 |
#upload-area.has-file #preview-image-main,
|
| 161 |
#upload-area.has-file #remove-file-btn-main {
|
| 162 |
display: block;
|
| 163 |
}
|
|
|
|
| 164 |
|
| 165 |
textarea { width: 100%; padding: 1rem 1.2rem; border-radius: var(--radius-input); border: 1px solid var(--input-border); background-color: var(--input-bg); color: var(--text-primary); box-shadow: var(--shadow-sm) inset; font-family: var(--app-font); font-size: 1rem; box-sizing: border-box; transition: var(--transition-smooth); min-height: 90px; resize: vertical; }
|
| 166 |
textarea:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-primary-glow), var(--shadow-sm) inset; background-color: var(--panel-bg); }
|
|
|
|
| 186 |
#result-grid img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: var(--radius-input); cursor: pointer; transition: var(--transition-smooth); box-shadow: var(--shadow-md); border: 1px solid var(--panel-border); }
|
| 187 |
#result-grid img:hover { transform: scale(1.05); box-shadow: var(--shadow-lg); z-index: 10; position: relative; }
|
| 188 |
#error-message { color: var(--danger-color); text-align: center; margin-top: 1rem; display: none; font-weight: 500; }
|
| 189 |
+
|
| 190 |
+
/* --- History Gallery Styles --- */
|
| 191 |
.gallery-header { display: flex; justify-content: space-between; align-items: center; }
|
| 192 |
#clear-history-btn { background: none; border: 1px solid var(--panel-border); color: var(--text-secondary); padding: 0.5rem 1rem; border-radius: var(--radius-btn); cursor: pointer; display: none; align-items: center; gap: 0.5rem; font-family: var(--app-font); font-weight: 500; transition: all 0.2s; }
|
| 193 |
#clear-history-btn:hover { border-color: var(--danger-color); color: var(--danger-color); }
|
| 194 |
#clear-history-btn svg { width: 18px; height: 18px; }
|
| 195 |
+
|
| 196 |
+
/* --- CHANGE: Changed to a two-column layout --- */
|
| 197 |
+
#history-grid {
|
| 198 |
+
display: grid;
|
| 199 |
+
grid-template-columns: repeat(2, 1fr);
|
| 200 |
+
gap: 1.5rem;
|
| 201 |
+
margin-top: 1.5rem;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
#history-grid:empty::before { content: 'هنوز تصویری خلق نکردهاید. اولین ویرایش شما اینجا ذخیره خواهد شد.'; color: var(--text-secondary); grid-column: 1 / -1; text-align: center; padding: 3rem 1rem; background-color: var(--input-bg); border-radius: var(--radius-card); }
|
| 205 |
+
.history-item { position: relative; background-color: var(--input-bg); border-radius: var(--radius-card); border: 1px solid var(--panel-border); padding: 1.5rem; transition: var(--transition-smooth); display: flex; flex-direction: column; }
|
| 206 |
.history-item:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }
|
| 207 |
.history-item-prompt { font-weight: 600; margin: 0 0 1rem 0; word-break: break-word; padding-left: 30px; }
|
| 208 |
+
.history-item-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); gap: 0.75rem; margin-top: auto; }
|
| 209 |
.history-item-grid img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: var(--radius-input); cursor: pointer; transition: transform 0.2s ease, box-shadow 0.2s ease; border: 1px solid var(--panel-border); }
|
| 210 |
.history-item-grid img:hover { transform: scale(1.1); box-shadow: var(--shadow-md); z-index: 5; position: relative; }
|
| 211 |
.history-delete-btn { position: absolute; top: 1rem; left: 1rem; background: none; border: none; cursor: pointer; padding: 0.5rem; border-radius: 50%; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--text-tertiary); transition: var(--transition-smooth); }
|
| 212 |
.history-delete-btn:hover { background-color: var(--panel-border); color: var(--danger-color); }
|
| 213 |
.history-delete-btn svg { width: 18px; height: 18px; }
|
| 214 |
+
|
| 215 |
+
/* --- Lightbox Styles --- */
|
| 216 |
#lightbox { position: fixed; inset: 0; background-color: rgba(18, 24, 38, 0.6); backdrop-filter: blur(10px) saturate(150%); display: none; align-items: center; justify-content: center; z-index: 1000; opacity: 0; transition: opacity 0.3s; }
|
| 217 |
#lightbox.visible { display: flex; opacity: 1; }
|
| 218 |
#lightbox-content { position: relative; animation: fadeIn 0.3s ease; }
|
|
|
|
| 222 |
#lightbox-close { top: -50px; right: 0; font-size: 1.8rem; }
|
| 223 |
#lightbox-download { top: -50px; left: 0; }
|
| 224 |
#lightbox-download svg { width: 22px; height: 22px; }
|
|
|
|
| 225 |
#lightbox-download .spinner { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: none; }
|
| 226 |
|
| 227 |
@media (max-width: 768px) {
|
| 228 |
main, .gallery-section { padding: 1.5rem; }
|
| 229 |
h1 { font-size: 2.2rem; }
|
| 230 |
+
/* --- CHANGE: Revert history grid to single column on mobile --- */
|
| 231 |
+
#history-grid {
|
| 232 |
+
grid-template-columns: 1fr;
|
| 233 |
+
}
|
| 234 |
}
|
| 235 |
</style>
|
| 236 |
</head>
|
|
|
|
| 247 |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4Z"/></svg>
|
| 248 |
۱. تصویر خود را انتخاب کنید
|
| 249 |
</div>
|
|
|
|
| 250 |
<label id="upload-area" for="file-input">
|
|
|
|
| 251 |
<div id="upload-content">
|
| 252 |
<div id="upload-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg></div>
|
| 253 |
<p>فایل تصویر را اینجا بکشید یا برای انتخاب کلیک کنید</p>
|
| 254 |
</div>
|
|
|
|
| 255 |
<img id="preview-image-main" src="" alt="Preview">
|
| 256 |
<button type="button" id="remove-file-btn-main" title="حذف تصویر">×</button>
|
| 257 |
</label>
|
|
|
|
| 305 |
<div id="lightbox-content">
|
| 306 |
<img id="lightbox-img" src="">
|
| 307 |
<button id="lightbox-close" class="lightbox-btn">×</button>
|
|
|
|
| 308 |
<button id="lightbox-download" title="دانلود تصویر" class="lightbox-btn">
|
| 309 |
<svg fill="white" viewBox="0 0 24 24"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"/></svg>
|
| 310 |
<div class="spinner"></div>
|
|
|
|
| 315 |
<script>
|
| 316 |
const API_URL = 'https://alfa-editor-worker.onrender.com/api/edit';
|
| 317 |
|
|
|
|
| 318 |
const uploadArea = document.getElementById('upload-area');
|
| 319 |
const fileInput = document.getElementById('file-input');
|
| 320 |
const previewImage = document.getElementById('preview-image-main');
|
|
|
|
| 335 |
const clearHistoryBtn = document.getElementById('clear-history-btn');
|
| 336 |
|
| 337 |
let uploadedFile = null;
|
| 338 |
+
let currentLightboxUrl = null;
|
| 339 |
|
|
|
|
| 340 |
const resetUploader = () => {
|
| 341 |
uploadedFile = null;
|
| 342 |
fileInput.value = '';
|
|
|
|
| 358 |
clearResult();
|
| 359 |
};
|
| 360 |
|
|
|
|
| 361 |
removeFileBtn.addEventListener('click', (e) => {
|
| 362 |
+
e.preventDefault();
|
| 363 |
e.stopPropagation();
|
| 364 |
resetUploader();
|
| 365 |
});
|
|
|
|
| 370 |
['dragleave', 'drop'].forEach(e => uploadArea.addEventListener(e, () => uploadArea.classList.remove('drag-over')));
|
| 371 |
uploadArea.addEventListener('drop', e => { if (!uploadArea.classList.contains('has-file')) handleFile(e.dataTransfer.files[0]); });
|
| 372 |
|
|
|
|
| 373 |
promptInput.addEventListener('input', checkFormState);
|
| 374 |
function checkFormState() { submitBtn.disabled = !uploadedFile || promptInput.value.trim() === ''; }
|
| 375 |
submitBtn.addEventListener('click', async () => {
|
|
|
|
| 430 |
errorMessage.style.display = 'block';
|
| 431 |
}
|
| 432 |
|
|
|
|
| 433 |
function openLightbox(url) {
|
| 434 |
+
currentLightboxUrl = url;
|
| 435 |
lightboxImg.src = url;
|
| 436 |
lightbox.classList.add('visible');
|
| 437 |
}
|
| 438 |
function closeLightbox() {
|
| 439 |
lightbox.classList.remove('visible');
|
| 440 |
+
currentLightboxUrl = null;
|
| 441 |
}
|
| 442 |
async function handleDownload() {
|
| 443 |
if (!currentLightboxUrl) return;
|
|
|
|
| 450 |
lightboxDownload.disabled = true;
|
| 451 |
|
| 452 |
try {
|
|
|
|
| 453 |
const response = await fetch(currentLightboxUrl);
|
| 454 |
if (!response.ok) throw new Error('Network response was not ok.');
|
|
|
|
|
|
|
| 455 |
const blob = await response.blob();
|
|
|
|
|
|
|
| 456 |
const objectUrl = URL.createObjectURL(blob);
|
| 457 |
const a = document.createElement('a');
|
| 458 |
a.href = objectUrl;
|
| 459 |
+
a.download = `ai-edited-image-${Date.now()}.png`;
|
| 460 |
document.body.appendChild(a);
|
| 461 |
a.click();
|
|
|
|
|
|
|
| 462 |
document.body.removeChild(a);
|
| 463 |
URL.revokeObjectURL(objectUrl);
|
| 464 |
} catch (e) {
|
|
|
|
| 474 |
lightbox.addEventListener('click', (e) => { if (e.target === lightbox) closeLightbox(); });
|
| 475 |
lightboxDownload.addEventListener('click', handleDownload);
|
| 476 |
|
|
|
|
| 477 |
const getHistory = () => JSON.parse(localStorage.getItem('aiPhotoshopHistory') || '[]');
|
| 478 |
const saveHistory = (history) => {
|
| 479 |
localStorage.setItem('aiPhotoshopHistory', JSON.stringify(history));
|