Spaces:
Running
Running
Update index.html
Browse files- index.html +317 -231
index.html
CHANGED
|
@@ -4,264 +4,323 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>فتوشاپ هوش مصنوعی (نسخه گالری)</title>
|
| 7 |
-
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700
|
| 8 |
<style>
|
| 9 |
:root {
|
| 10 |
-
--bg-
|
| 11 |
-
--
|
| 12 |
-
--text-color: #1e293b;
|
| 13 |
--card-bg: #ffffff;
|
| 14 |
-
--border-color: #
|
| 15 |
-
--primary-color-start: #
|
| 16 |
-
--primary-color-end: #
|
| 17 |
-
--shadow-color
|
| 18 |
-
--
|
| 19 |
-
--drop-zone-
|
| 20 |
-
--ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
|
| 21 |
}
|
| 22 |
|
|
|
|
| 23 |
.dark {
|
| 24 |
-
--bg-
|
| 25 |
-
--
|
| 26 |
-
--
|
| 27 |
-
--
|
| 28 |
-
--
|
| 29 |
-
--
|
| 30 |
-
--
|
| 31 |
-
--drop-zone-bg: #111827;
|
| 32 |
}
|
| 33 |
|
|
|
|
| 34 |
@keyframes fadeInUp {
|
| 35 |
-
from {
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
body {
|
| 40 |
font-family: 'Vazirmatn', sans-serif;
|
| 41 |
-
background-color: var(--bg-
|
| 42 |
-
background-image: radial-gradient(circle at top left, var(--bg-start), var(--bg-end));
|
| 43 |
color: var(--text-color);
|
| 44 |
margin: 0;
|
| 45 |
-
padding:
|
| 46 |
display: flex;
|
| 47 |
justify-content: center;
|
| 48 |
align-items: flex-start;
|
| 49 |
min-height: 100vh;
|
| 50 |
-
transition: background-color 0.
|
| 51 |
}
|
| 52 |
|
| 53 |
.container {
|
| 54 |
-
max-width:
|
| 55 |
width: 100%;
|
| 56 |
}
|
| 57 |
|
|
|
|
| 58 |
header {
|
| 59 |
text-align: center;
|
| 60 |
-
margin-bottom:
|
| 61 |
-
animation: fadeInUp 0.
|
| 62 |
}
|
| 63 |
|
| 64 |
h1 {
|
| 65 |
-
font-size:
|
| 66 |
-
font-weight:
|
| 67 |
-
letter-spacing: -1px;
|
| 68 |
margin: 0;
|
| 69 |
background: linear-gradient(45deg, var(--primary-color-start), var(--primary-color-end));
|
| 70 |
-webkit-background-clip: text;
|
| 71 |
-webkit-text-fill-color: transparent;
|
|
|
|
|
|
|
| 72 |
}
|
| 73 |
|
| 74 |
p.subtitle {
|
| 75 |
-
font-size: 1.
|
| 76 |
-
color: #
|
| 77 |
-
margin-top: 0.
|
| 78 |
}
|
| 79 |
-
.dark p.subtitle { color: #94a3b8; }
|
| 80 |
|
|
|
|
|
|
|
|
|
|
| 81 |
main {
|
| 82 |
background-color: var(--card-bg);
|
| 83 |
-
border-radius:
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
opacity: 0;
|
| 90 |
}
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
.panel:last-child { margin-bottom: 0; }
|
| 94 |
-
.controls { margin-bottom: 2.5rem; }
|
| 95 |
|
| 96 |
h2 {
|
| 97 |
-
font-size: 1.
|
| 98 |
-
font-weight:
|
| 99 |
-
margin: 0
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
display: flex;
|
| 102 |
align-items: center;
|
| 103 |
gap: 0.75rem;
|
| 104 |
-
border-bottom: 1px solid var(--border-color);
|
| 105 |
}
|
| 106 |
-
h2 svg { color: var(--primary-color-start); }
|
| 107 |
|
|
|
|
| 108 |
#drop-zone {
|
| 109 |
-
border:
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
-
|
| 120 |
-
|
| 121 |
-
-
|
| 122 |
-
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
#drop-zone-icon {
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
#image-preview {
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
}
|
| 141 |
-
#image-preview.visible { opacity: 1; transform: scale(1); pointer-events: auto; }
|
| 142 |
|
|
|
|
| 143 |
textarea {
|
| 144 |
-
width: 100%;
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
|
|
|
| 150 |
textarea:focus {
|
| 151 |
-
outline: none;
|
| 152 |
-
|
|
|
|
| 153 |
}
|
| 154 |
|
| 155 |
button#submit-btn {
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
}
|
|
|
|
| 164 |
button#submit-btn:hover:not(:disabled) {
|
| 165 |
-
transform: translateY(-
|
| 166 |
-
box-shadow: 0
|
| 167 |
background-position: right center;
|
| 168 |
}
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
}
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
| 177 |
}
|
| 178 |
-
.loader-dots .dot1 { animation-delay: -0.32s; }
|
| 179 |
-
.loader-dots .dot2 { animation-delay: -0.16s; }
|
| 180 |
-
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } }
|
| 181 |
-
#btn-text.hidden { visibility: hidden; }
|
| 182 |
|
| 183 |
#result-container {
|
| 184 |
-
border:
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
|
|
|
| 189 |
position: relative;
|
| 190 |
-
background-color: var(--drop-zone-bg);
|
| 191 |
-
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
display: none; /* Initially hidden */
|
| 197 |
-
flex-direction: column;
|
| 198 |
-
align-items: center;
|
| 199 |
-
gap: 1.5rem;
|
| 200 |
-
opacity: 0;
|
| 201 |
-
animation: fadeIn 0.5s ease forwards;
|
| 202 |
-
|
| 203 |
-
/* Positioning logic for perfect centering */
|
| 204 |
-
position: absolute;
|
| 205 |
-
top: 50%;
|
| 206 |
-
left: 50%;
|
| 207 |
-
transform: translate(-50%, -50%);
|
| 208 |
-
width: 100%; /* Ensure it takes space to center its content */
|
| 209 |
-
text-align: center;
|
| 210 |
}
|
| 211 |
-
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
| 212 |
-
#result-container.loading #loading-placeholder { display: flex; }
|
| 213 |
-
|
| 214 |
-
.loading-animation { width: 120px; height: 120px; }
|
| 215 |
-
.loading-text { font-weight: 500; color: #64748b; }
|
| 216 |
-
.dark .loading-text { color: #94a3b8; }
|
| 217 |
|
| 218 |
#result-grid {
|
| 219 |
-
display: grid;
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
| 221 |
}
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
}
|
|
|
|
| 227 |
#result-grid img {
|
| 228 |
-
width: 100%;
|
| 229 |
-
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
}
|
|
|
|
| 232 |
#result-grid img:hover {
|
| 233 |
-
transform: scale(1.05)
|
| 234 |
-
box-shadow: 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
}
|
| 236 |
|
| 237 |
-
|
| 238 |
-
|
| 239 |
#lightbox {
|
| 240 |
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
| 241 |
-
background-color: rgba(
|
| 242 |
justify-content: center; align-items: center; padding: 2rem;
|
| 243 |
-
box-sizing: border-box; backdrop-filter: blur(
|
| 244 |
-
}
|
| 245 |
-
#lightbox-img {
|
| 246 |
-
max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 1rem;
|
| 247 |
-
box-shadow: 0 20px 50px rgba(0,0,0,0.5);
|
| 248 |
}
|
|
|
|
|
|
|
| 249 |
#lightbox-close, #lightbox-download {
|
| 250 |
-
position: absolute; top: -
|
| 251 |
-
color: white; border:
|
| 252 |
-
|
| 253 |
-
|
| 254 |
}
|
| 255 |
#lightbox-close { left: 10px; }
|
| 256 |
#lightbox-download { right: 10px; }
|
| 257 |
-
#lightbox-close:hover, #lightbox-download:hover {
|
| 258 |
-
background-color: rgba(255, 255, 255, 0.2); transform: scale(1.1);
|
| 259 |
-
}
|
| 260 |
|
|
|
|
| 261 |
@media (max-width: 600px) {
|
| 262 |
-
body { padding:
|
| 263 |
main { padding: 1.5rem; }
|
| 264 |
-
h1 { font-size:
|
|
|
|
| 265 |
}
|
| 266 |
</style>
|
| 267 |
</head>
|
|
@@ -274,65 +333,46 @@
|
|
| 274 |
</header>
|
| 275 |
|
| 276 |
<main>
|
|
|
|
| 277 |
<div class="panel">
|
| 278 |
<h2>
|
| 279 |
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21
|
| 280 |
-
۱. تصویر خود را
|
| 281 |
</h2>
|
| 282 |
<div id="drop-zone">
|
| 283 |
-
<
|
| 284 |
-
|
| 285 |
-
<span id="drop-zone-text">تصویر را اینجا بکشید یا برای انتخاب کلیک کنید</span>
|
| 286 |
-
</div>
|
| 287 |
<img id="image-preview" src="#" alt="پیشنمایش تصویر" />
|
| 288 |
</div>
|
| 289 |
<input type="file" id="file-input" accept="image/*" hidden>
|
| 290 |
</div>
|
| 291 |
|
|
|
|
| 292 |
<div class="controls">
|
| 293 |
<h2>
|
| 294 |
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="
|
| 295 |
-
۲. دستور ویرایش را
|
| 296 |
</h2>
|
| 297 |
<textarea id="prompt-input" rows="3" placeholder="مثال: پسزمینه را حذف کن و یک ساحل آفتابی قرار بده"></textarea>
|
| 298 |
-
<button id="submit-btn" disabled>
|
| 299 |
-
<span id="btn-text">خلق کن</span>
|
| 300 |
-
</button>
|
| 301 |
<p id="error-message"></p>
|
| 302 |
</div>
|
| 303 |
|
|
|
|
| 304 |
<div class="panel">
|
| 305 |
<h2>
|
| 306 |
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="
|
| 307 |
-
۳. نتیجه را
|
| 308 |
</h2>
|
| 309 |
<div id="result-container">
|
| 310 |
-
<div id="
|
| 311 |
-
<svg class="loading-animation" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
| 312 |
-
<style>
|
| 313 |
-
.circle { animation: a 4s cubic-bezier(.5,0,.5,1) infinite; transform-origin: 50px 50px; }
|
| 314 |
-
.p1 { animation-duration: 2s; stroke: #a855f7; }
|
| 315 |
-
.p2 { animation-duration: 3s; stroke: #8b5cf6; }
|
| 316 |
-
.p3 { animation-duration: 4s; stroke: #6366f1; }
|
| 317 |
-
.p4 { animation-duration: 5s; stroke: #4f46e5; }
|
| 318 |
-
@keyframes a { to { transform: rotate(300deg) scale(0.8); } }
|
| 319 |
-
</style>
|
| 320 |
-
<g>
|
| 321 |
-
<path class="circle p1" d="M50,50 m0,-45 a45,45 0 1 1 0,90 a45,45 0 1 1 0,-90" fill="none" stroke-width="3" stroke-dasharray="282.74" stroke-dashoffset="212.05" stroke-linecap="round"></path>
|
| 322 |
-
<path class="circle p2" d="M50,50 m0,-35 a35,35 0 1 1 0,70 a35,35 0 1 1 0,-70" fill="none" stroke-width="3" stroke-dasharray="219.91" stroke-dashoffset="164.93" stroke-linecap="round"></path>
|
| 323 |
-
<path class="circle p3" d="M50,50 m0,-25 a25,25 0 1 1 0,50 a25,25 0 1 1 0,-50" fill="none" stroke-width="3" stroke-dasharray="157.08" stroke-dashoffset="117.81" stroke-linecap="round"></path>
|
| 324 |
-
<path class="circle p4" d="M50,50 m0,-15 a15,15 0 1 1 0,30 a15,15 0 1 1 0,-30" fill="none" stroke-width="3" stroke-dasharray="94.24" stroke-dashoffset="70.68" stroke-linecap="round"></path>
|
| 325 |
-
</g>
|
| 326 |
-
</svg>
|
| 327 |
-
<p class="loading-text">هوش مصنوعی در حال خلق اثر شماست...</p>
|
| 328 |
-
</div>
|
| 329 |
<div id="result-grid"></div>
|
| 330 |
</div>
|
| 331 |
</div>
|
| 332 |
</main>
|
| 333 |
</div>
|
| 334 |
|
| 335 |
-
<!-- Lightbox Structure -->
|
| 336 |
<div id="lightbox">
|
| 337 |
<div id="lightbox-content">
|
| 338 |
<img id="lightbox-img" src="">
|
|
@@ -342,20 +382,22 @@
|
|
| 342 |
</a>
|
| 343 |
</div>
|
| 344 |
</div>
|
| 345 |
-
|
| 346 |
<script>
|
|
|
|
| 347 |
const API_URL = 'https://alfa-editor-worker.onrender.com/api/edit';
|
| 348 |
|
| 349 |
// --- DOM Elements ---
|
| 350 |
const dropZone = document.getElementById('drop-zone');
|
| 351 |
-
const dropZoneContent = document.getElementById('drop-zone-content');
|
| 352 |
const fileInput = document.getElementById('file-input');
|
| 353 |
const imagePreview = document.getElementById('image-preview');
|
|
|
|
|
|
|
| 354 |
const promptInput = document.getElementById('prompt-input');
|
| 355 |
const submitBtn = document.getElementById('submit-btn');
|
| 356 |
-
const
|
| 357 |
-
const resultContainer = document.getElementById('result-container');
|
| 358 |
const resultGrid = document.getElementById('result-grid');
|
|
|
|
| 359 |
const errorMessage = document.getElementById('error-message');
|
| 360 |
const lightbox = document.getElementById('lightbox');
|
| 361 |
const lightboxImg = document.getElementById('lightbox-img');
|
|
@@ -364,50 +406,88 @@
|
|
| 364 |
|
| 365 |
let uploadedFile = null;
|
| 366 |
|
| 367 |
-
// ---
|
| 368 |
dropZone.addEventListener('click', () => fileInput.click());
|
| 369 |
-
fileInput.addEventListener('change', (e) =>
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
|
| 375 |
function handleFile(file) {
|
| 376 |
-
if (!file
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
uploadedFile = file;
|
|
|
|
| 378 |
const reader = new FileReader();
|
| 379 |
reader.onload = (e) => {
|
| 380 |
imagePreview.src = e.target.result;
|
| 381 |
-
imagePreview.
|
| 382 |
-
|
| 383 |
-
|
|
|
|
| 384 |
clearResult();
|
| 385 |
};
|
| 386 |
reader.readAsDataURL(file);
|
| 387 |
}
|
| 388 |
|
|
|
|
| 389 |
function checkFormState() {
|
| 390 |
submitBtn.disabled = !uploadedFile || promptInput.value.trim() === '';
|
| 391 |
}
|
|
|
|
|
|
|
| 392 |
|
|
|
|
| 393 |
submitBtn.addEventListener('click', async () => {
|
| 394 |
if (submitBtn.disabled) return;
|
|
|
|
| 395 |
setLoading(true);
|
|
|
|
| 396 |
const formData = new FormData();
|
| 397 |
formData.append('image', uploadedFile);
|
| 398 |
formData.append('prompt', promptInput.value.trim());
|
|
|
|
| 399 |
try {
|
| 400 |
-
const response = await fetch(API_URL, {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
if (!response.ok) {
|
| 402 |
const errorData = await response.json().catch(() => ({ error: `خطای سرور: ${response.statusText}` }));
|
| 403 |
throw new Error(errorData.error || `یک خطای ناشناخته رخ داد.`);
|
| 404 |
}
|
|
|
|
| 405 |
const result = await response.json();
|
|
|
|
| 406 |
if (result.image_urls && Array.isArray(result.image_urls) && result.image_urls.length > 0) {
|
| 407 |
displayResult(result.image_urls);
|
| 408 |
} else {
|
| 409 |
throw new Error('پاسخ معتبری از سرور دریافت نشد. ممکن است سرور موقتا با مشکل مواجه شده باشد.');
|
| 410 |
}
|
|
|
|
| 411 |
} catch (error) {
|
| 412 |
displayError(error.message);
|
| 413 |
} finally {
|
|
@@ -415,34 +495,32 @@
|
|
| 415 |
}
|
| 416 |
});
|
| 417 |
|
| 418 |
-
// --- UI Helper Functions (
|
| 419 |
function setLoading(isLoading) {
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
const loader = document.createElement('div');
|
| 424 |
-
loader.className = 'loader-dots';
|
| 425 |
-
loader.innerHTML = '<div class="dot1"></div><div class="dot2"></div><div class="dot3"></div>';
|
| 426 |
-
submitBtn.appendChild(loader);
|
| 427 |
submitBtn.disabled = true;
|
|
|
|
| 428 |
resultGrid.innerHTML = '';
|
| 429 |
errorMessage.style.display = 'none';
|
| 430 |
} else {
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
checkFormState();
|
| 436 |
}
|
| 437 |
}
|
| 438 |
|
| 439 |
function displayResult(imageUrls) {
|
| 440 |
-
resultGrid.innerHTML = '';
|
| 441 |
imageUrls.forEach((url, index) => {
|
| 442 |
const img = document.createElement('img');
|
| 443 |
img.src = url;
|
| 444 |
img.alt = 'تصویر ویرایش شده';
|
| 445 |
-
|
|
|
|
| 446 |
img.addEventListener('click', () => openLightbox(url));
|
| 447 |
resultGrid.appendChild(img);
|
| 448 |
});
|
|
@@ -458,17 +536,25 @@
|
|
| 458 |
errorMessage.style.display = 'block';
|
| 459 |
}
|
| 460 |
|
| 461 |
-
// --- Lightbox Functions (
|
| 462 |
function openLightbox(url) {
|
| 463 |
lightboxImg.src = url;
|
| 464 |
lightboxDownload.href = url;
|
| 465 |
lightbox.style.display = 'flex';
|
| 466 |
}
|
| 467 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
lightboxClose.addEventListener('click', closeLightbox);
|
| 469 |
-
lightbox.addEventListener('click', (e) => {
|
|
|
|
|
|
|
| 470 |
|
|
|
|
| 471 |
checkFormState();
|
|
|
|
| 472 |
</script>
|
| 473 |
</body>
|
| 474 |
</html>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>فتوشاپ هوش مصنوعی (نسخه گالری)</title>
|
| 7 |
+
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 8 |
<style>
|
| 9 |
:root {
|
| 10 |
+
--bg-color: #f8f9fa;
|
| 11 |
+
--text-color: #212529;
|
|
|
|
| 12 |
--card-bg: #ffffff;
|
| 13 |
+
--border-color: #dee2e6;
|
| 14 |
+
--primary-color-start: #3b82f6;
|
| 15 |
+
--primary-color-end: #8b5cf6;
|
| 16 |
+
--shadow-color: rgba(0, 0, 0, 0.08);
|
| 17 |
+
--drop-zone-bg: #f1f5f9;
|
| 18 |
+
--drop-zone-border-active: #a5b4fc;
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
+
/* --- Dark Mode --- */
|
| 22 |
.dark {
|
| 23 |
+
--bg-color: #111827;
|
| 24 |
+
--text-color: #d1d5db;
|
| 25 |
+
--card-bg: #1f2937;
|
| 26 |
+
--border-color: #374151;
|
| 27 |
+
--shadow-color: rgba(0, 0, 0, 0.25);
|
| 28 |
+
--drop-zone-bg: #374151;
|
| 29 |
+
--drop-zone-border-active: #6366f1;
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
+
/* --- Base Styles & Animations --- */
|
| 33 |
@keyframes fadeInUp {
|
| 34 |
+
from {
|
| 35 |
+
opacity: 0;
|
| 36 |
+
transform: translateY(20px);
|
| 37 |
+
}
|
| 38 |
+
to {
|
| 39 |
+
opacity: 1;
|
| 40 |
+
transform: translateY(0);
|
| 41 |
+
}
|
| 42 |
}
|
| 43 |
|
| 44 |
body {
|
| 45 |
font-family: 'Vazirmatn', sans-serif;
|
| 46 |
+
background-color: var(--bg-color);
|
|
|
|
| 47 |
color: var(--text-color);
|
| 48 |
margin: 0;
|
| 49 |
+
padding: 2rem;
|
| 50 |
display: flex;
|
| 51 |
justify-content: center;
|
| 52 |
align-items: flex-start;
|
| 53 |
min-height: 100vh;
|
| 54 |
+
transition: background-color 0.3s, color 0.3s;
|
| 55 |
}
|
| 56 |
|
| 57 |
.container {
|
| 58 |
+
max-width: 700px; /* Reduced width for a more focused single-column layout */
|
| 59 |
width: 100%;
|
| 60 |
}
|
| 61 |
|
| 62 |
+
/* --- Header --- */
|
| 63 |
header {
|
| 64 |
text-align: center;
|
| 65 |
+
margin-bottom: 2.5rem;
|
| 66 |
+
animation: fadeInUp 0.5s ease-out forwards;
|
| 67 |
}
|
| 68 |
|
| 69 |
h1 {
|
| 70 |
+
font-size: 2.5rem;
|
| 71 |
+
font-weight: 700;
|
|
|
|
| 72 |
margin: 0;
|
| 73 |
background: linear-gradient(45deg, var(--primary-color-start), var(--primary-color-end));
|
| 74 |
-webkit-background-clip: text;
|
| 75 |
-webkit-text-fill-color: transparent;
|
| 76 |
+
background-clip: text;
|
| 77 |
+
color: transparent;
|
| 78 |
}
|
| 79 |
|
| 80 |
p.subtitle {
|
| 81 |
+
font-size: 1.1rem;
|
| 82 |
+
color: #6b7280;
|
| 83 |
+
margin-top: 0.5rem;
|
| 84 |
}
|
|
|
|
| 85 |
|
| 86 |
+
.dark p.subtitle { color: #9ca3af; }
|
| 87 |
+
|
| 88 |
+
/* --- Main Content Card --- */
|
| 89 |
main {
|
| 90 |
background-color: var(--card-bg);
|
| 91 |
+
border-radius: 1.5rem;
|
| 92 |
+
box-shadow: 0 20px 50px -10px var(--shadow-color);
|
| 93 |
+
padding: 2.5rem;
|
| 94 |
+
transition: background-color 0.3s, box-shadow 0.3s;
|
| 95 |
+
animation: fadeInUp 0.5s ease-out 0.2s forwards;
|
| 96 |
+
opacity: 0; /* Initially hidden for animation */
|
|
|
|
| 97 |
}
|
| 98 |
|
| 99 |
+
/* --- Section Styling (Panel, Controls) --- */
|
| 100 |
+
.panel, .controls {
|
| 101 |
+
margin-bottom: 2.5rem;
|
| 102 |
+
}
|
| 103 |
+
.controls { margin-bottom: 2rem; }
|
| 104 |
.panel:last-child { margin-bottom: 0; }
|
|
|
|
| 105 |
|
| 106 |
h2 {
|
| 107 |
+
font-size: 1.25rem;
|
| 108 |
+
font-weight: 600;
|
| 109 |
+
margin-top: 0;
|
| 110 |
+
margin-bottom: 1.5rem;
|
| 111 |
+
border-bottom: 2px solid var(--border-color);
|
| 112 |
+
padding-bottom: 0.75rem;
|
| 113 |
display: flex;
|
| 114 |
align-items: center;
|
| 115 |
gap: 0.75rem;
|
|
|
|
| 116 |
}
|
|
|
|
| 117 |
|
| 118 |
+
/* --- Drop Zone & Image Preview --- */
|
| 119 |
#drop-zone {
|
| 120 |
+
border: 3px dashed var(--border-color);
|
| 121 |
+
border-radius: 1rem;
|
| 122 |
+
padding: 2rem;
|
| 123 |
+
text-align: center;
|
| 124 |
+
cursor: pointer;
|
| 125 |
+
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
|
| 126 |
+
position: relative;
|
| 127 |
+
overflow: hidden;
|
| 128 |
+
background-color: var(--drop-zone-bg);
|
| 129 |
+
display: flex;
|
| 130 |
+
flex-direction: column;
|
| 131 |
+
justify-content: center;
|
| 132 |
+
align-items: center;
|
| 133 |
+
min-height: 250px;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
#drop-zone.dragover {
|
| 137 |
+
border-color: var(--drop-zone-border-active);
|
| 138 |
+
background-color: rgba(99, 102, 241, 0.1);
|
| 139 |
+
transform: scale(1.02);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
#drop-zone-icon {
|
| 143 |
+
width: 50px;
|
| 144 |
+
height: 50px;
|
| 145 |
+
margin-bottom: 1rem;
|
| 146 |
+
color: #9ca3af;
|
| 147 |
+
transition: transform 0.3s ease;
|
| 148 |
+
}
|
| 149 |
+
.dark #drop-zone-icon { color: #6b7280; }
|
| 150 |
+
#drop-zone:hover #drop-zone-icon { transform: translateY(-5px); }
|
| 151 |
+
|
| 152 |
+
#drop-zone-text {
|
| 153 |
+
color: #4b5563;
|
| 154 |
+
font-weight: 500;
|
| 155 |
+
}
|
| 156 |
+
.dark #drop-zone-text { color: #d1d5db; }
|
| 157 |
+
|
| 158 |
#image-preview {
|
| 159 |
+
max-width: 100%;
|
| 160 |
+
max-height: 300px;
|
| 161 |
+
border-radius: 0.75rem;
|
| 162 |
+
object-fit: contain;
|
| 163 |
+
display: none;
|
| 164 |
}
|
|
|
|
| 165 |
|
| 166 |
+
/* --- Controls (Textarea & Button) --- */
|
| 167 |
textarea {
|
| 168 |
+
width: 100%;
|
| 169 |
+
padding: 1rem;
|
| 170 |
+
border: 2px solid var(--border-color);
|
| 171 |
+
border-radius: 0.75rem;
|
| 172 |
+
background-color: var(--bg-color);
|
| 173 |
+
color: var(--text-color);
|
| 174 |
+
font-family: 'Vazirmatn', sans-serif;
|
| 175 |
+
font-size: 1rem;
|
| 176 |
+
resize: vertical;
|
| 177 |
+
min-height: 80px;
|
| 178 |
+
box-sizing: border-box;
|
| 179 |
+
transition: all 0.3s ease;
|
| 180 |
}
|
| 181 |
+
|
| 182 |
textarea:focus {
|
| 183 |
+
outline: none;
|
| 184 |
+
border-color: var(--primary-color-start);
|
| 185 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
|
| 186 |
}
|
| 187 |
|
| 188 |
button#submit-btn {
|
| 189 |
+
width: 100%;
|
| 190 |
+
padding: 1rem;
|
| 191 |
+
border: none;
|
| 192 |
+
border-radius: 0.75rem;
|
| 193 |
+
background-image: linear-gradient(45deg, var(--primary-color-start), var(--primary-color-end));
|
| 194 |
+
background-size: 150% 150%;
|
| 195 |
+
color: white;
|
| 196 |
+
font-size: 1.1rem;
|
| 197 |
+
font-weight: 600;
|
| 198 |
+
cursor: pointer;
|
| 199 |
+
margin-top: 1rem;
|
| 200 |
+
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
|
| 201 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
| 202 |
}
|
| 203 |
+
|
| 204 |
button#submit-btn:hover:not(:disabled) {
|
| 205 |
+
transform: translateY(-3px) scale(1.01);
|
| 206 |
+
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
|
| 207 |
background-position: right center;
|
| 208 |
}
|
| 209 |
+
|
| 210 |
+
button#submit-btn:disabled {
|
| 211 |
+
opacity: 0.5;
|
| 212 |
+
cursor: not-allowed;
|
| 213 |
}
|
| 214 |
+
|
| 215 |
+
/* --- Result Area & Loading Animation --- */
|
| 216 |
+
@keyframes pulse-bg {
|
| 217 |
+
0% { background-color: var(--drop-zone-bg); }
|
| 218 |
+
50% { background-color: color-mix(in srgb, var(--drop-zone-bg) 85%, var(--primary-color-start)); }
|
| 219 |
+
100% { background-color: var(--drop-zone-bg); }
|
| 220 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
#result-container {
|
| 223 |
+
border: 3px solid var(--border-color);
|
| 224 |
+
border-radius: 1rem;
|
| 225 |
+
min-height: 300px;
|
| 226 |
+
display: flex;
|
| 227 |
+
justify-content: center;
|
| 228 |
+
align-items: center;
|
| 229 |
position: relative;
|
| 230 |
+
background-color: var(--drop-zone-bg);
|
| 231 |
+
overflow: hidden;
|
| 232 |
+
padding: 0.5rem;
|
| 233 |
+
transition: border-color 0.3s ease;
|
| 234 |
}
|
| 235 |
|
| 236 |
+
#result-container.loading {
|
| 237 |
+
animation: pulse-bg 2s infinite ease-in-out;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
#result-grid {
|
| 241 |
+
display: grid;
|
| 242 |
+
grid-template-columns: repeat(2, 1fr);
|
| 243 |
+
gap: 0.5rem;
|
| 244 |
+
width: 100%;
|
| 245 |
+
height: 100%;
|
| 246 |
}
|
| 247 |
+
|
| 248 |
+
@keyframes popIn {
|
| 249 |
+
from {
|
| 250 |
+
transform: scale(0.8) translateY(10px);
|
| 251 |
+
opacity: 0;
|
| 252 |
+
}
|
| 253 |
+
to {
|
| 254 |
+
transform: scale(1) translateY(0);
|
| 255 |
+
opacity: 1;
|
| 256 |
+
}
|
| 257 |
}
|
| 258 |
+
|
| 259 |
#result-grid img {
|
| 260 |
+
width: 100%;
|
| 261 |
+
height: 100%;
|
| 262 |
+
object-fit: cover;
|
| 263 |
+
border-radius: 0.75rem;
|
| 264 |
+
cursor: pointer;
|
| 265 |
+
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
| 266 |
+
opacity: 0; /* Hidden for animation */
|
| 267 |
+
animation: popIn 0.5s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
|
| 268 |
}
|
| 269 |
+
|
| 270 |
#result-grid img:hover {
|
| 271 |
+
transform: scale(1.05);
|
| 272 |
+
box-shadow: 0 5px 15px var(--shadow-color);
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
.spinner {
|
| 276 |
+
width: 50px;
|
| 277 |
+
height: 50px;
|
| 278 |
+
border: 5px solid rgba(0,0,0,0.1);
|
| 279 |
+
border-left-color: var(--primary-color-start);
|
| 280 |
+
border-radius: 50%;
|
| 281 |
+
animation: spin 1s linear infinite;
|
| 282 |
+
position: absolute;
|
| 283 |
+
display: none;
|
| 284 |
+
z-index: 10;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
@keyframes spin {
|
| 288 |
+
to { transform: rotate(360deg); }
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
#error-message {
|
| 292 |
+
color: #ef4444;
|
| 293 |
+
text-align: center;
|
| 294 |
+
margin-top: 1rem;
|
| 295 |
+
display: none;
|
| 296 |
+
font-weight: 500;
|
| 297 |
}
|
| 298 |
|
| 299 |
+
/* --- Lightbox Styles (Unchanged) --- */
|
|
|
|
| 300 |
#lightbox {
|
| 301 |
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
| 302 |
+
background-color: rgba(0, 0, 0, 0.85); z-index: 1000; display: none;
|
| 303 |
justify-content: center; align-items: center; padding: 2rem;
|
| 304 |
+
box-sizing: border-box; backdrop-filter: blur(5px);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
}
|
| 306 |
+
#lightbox-content { position: relative; max-width: 80vw; max-height: 90vh; }
|
| 307 |
+
#lightbox-img { max-width: 100%; max-height: 90vh; object-fit: contain; border-radius: 1rem; }
|
| 308 |
#lightbox-close, #lightbox-download {
|
| 309 |
+
position: absolute; top: -40px; background-color: rgba(255, 255, 255, 0.2);
|
| 310 |
+
color: white; border: none; width: 35px; height: 35px; border-radius: 50%;
|
| 311 |
+
cursor: pointer; font-size: 1.5rem; display: flex; justify-content: center;
|
| 312 |
+
align-items: center; transition: background-color 0.2s;
|
| 313 |
}
|
| 314 |
#lightbox-close { left: 10px; }
|
| 315 |
#lightbox-download { right: 10px; }
|
| 316 |
+
#lightbox-close:hover, #lightbox-download:hover { background-color: rgba(255, 255, 255, 0.4); }
|
|
|
|
|
|
|
| 317 |
|
| 318 |
+
/* --- Responsive Design --- */
|
| 319 |
@media (max-width: 600px) {
|
| 320 |
+
body { padding: 1rem; }
|
| 321 |
main { padding: 1.5rem; }
|
| 322 |
+
h1 { font-size: 2rem; }
|
| 323 |
+
h2 { font-size: 1.1rem; }
|
| 324 |
}
|
| 325 |
</style>
|
| 326 |
</head>
|
|
|
|
| 333 |
</header>
|
| 334 |
|
| 335 |
<main>
|
| 336 |
+
<!-- 1. Upload Section -->
|
| 337 |
<div class="panel">
|
| 338 |
<h2>
|
| 339 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" 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>
|
| 340 |
+
۱. تصویر خود را آپلود کنید
|
| 341 |
</h2>
|
| 342 |
<div id="drop-zone">
|
| 343 |
+
<svg id="drop-zone-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.2 15c.7-1.2 1-2.5.7-3.9-.6-2.4-2.5-4.2-4.9-4.6-1.1-.2-2.2.3-3.1.9-1.4-2.4-4.1-3.9-7-3.9-4.4 0-8 3.6-8 8 0 1.9.7 3.7 1.8 5.1"></path><path d="M9.5 16.5 12 14l2.5 2.5"></path><path d="M12 14v7"></path></svg>
|
| 344 |
+
<span id="drop-zone-text">تصویر را اینجا بکشید یا برای انتخاب کلیک کنید</span>
|
|
|
|
|
|
|
| 345 |
<img id="image-preview" src="#" alt="پیشنمایش تصویر" />
|
| 346 |
</div>
|
| 347 |
<input type="file" id="file-input" accept="image/*" hidden>
|
| 348 |
</div>
|
| 349 |
|
| 350 |
+
<!-- 2. Controls Section -->
|
| 351 |
<div class="controls">
|
| 352 |
<h2>
|
| 353 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 5-3-3-6 6 3 3Z"></path><path d="m6 8-3-3 6-6 3 3Z"></path><path d="M14 4 12 6"></path><path d="m6 16 6 6"></path><path d="M11 11 8 8"></path></svg>
|
| 354 |
+
۲. دستور ویرایش را وارد کنید
|
| 355 |
</h2>
|
| 356 |
<textarea id="prompt-input" rows="3" placeholder="مثال: پسزمینه را حذف کن و یک ساحل آفتابی قرار بده"></textarea>
|
| 357 |
+
<button id="submit-btn" disabled>ویرایش کن</button>
|
|
|
|
|
|
|
| 358 |
<p id="error-message"></p>
|
| 359 |
</div>
|
| 360 |
|
| 361 |
+
<!-- 3. Result Section -->
|
| 362 |
<div class="panel">
|
| 363 |
<h2>
|
| 364 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.5 22h-6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v7.5"></path><path d="M2 15h20"></path><path d="M18 22a4 4 0 1 0 0-8 4 4 0 0 0 0 8Z"></path><path d="m22 22-1.5-1.5"></path></svg>
|
| 365 |
+
۳. نتیجه را مشاهده کنید
|
| 366 |
</h2>
|
| 367 |
<div id="result-container">
|
| 368 |
+
<div class="spinner" id="loader"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
<div id="result-grid"></div>
|
| 370 |
</div>
|
| 371 |
</div>
|
| 372 |
</main>
|
| 373 |
</div>
|
| 374 |
|
| 375 |
+
<!-- Lightbox Structure (Unchanged) -->
|
| 376 |
<div id="lightbox">
|
| 377 |
<div id="lightbox-content">
|
| 378 |
<img id="lightbox-img" src="">
|
|
|
|
| 382 |
</a>
|
| 383 |
</div>
|
| 384 |
</div>
|
| 385 |
+
|
| 386 |
<script>
|
| 387 |
+
// --- API Endpoint (Unchanged) ---
|
| 388 |
const API_URL = 'https://alfa-editor-worker.onrender.com/api/edit';
|
| 389 |
|
| 390 |
// --- DOM Elements ---
|
| 391 |
const dropZone = document.getElementById('drop-zone');
|
|
|
|
| 392 |
const fileInput = document.getElementById('file-input');
|
| 393 |
const imagePreview = document.getElementById('image-preview');
|
| 394 |
+
const dropZoneText = document.getElementById('drop-zone-text');
|
| 395 |
+
const dropZoneIcon = document.getElementById('drop-zone-icon'); // New element
|
| 396 |
const promptInput = document.getElementById('prompt-input');
|
| 397 |
const submitBtn = document.getElementById('submit-btn');
|
| 398 |
+
const resultContainer = document.getElementById('result-container'); // New reference
|
|
|
|
| 399 |
const resultGrid = document.getElementById('result-grid');
|
| 400 |
+
const loader = document.getElementById('loader');
|
| 401 |
const errorMessage = document.getElementById('error-message');
|
| 402 |
const lightbox = document.getElementById('lightbox');
|
| 403 |
const lightboxImg = document.getElementById('lightbox-img');
|
|
|
|
| 406 |
|
| 407 |
let uploadedFile = null;
|
| 408 |
|
| 409 |
+
// --- File Upload Logic (Updated for better UI feedback) ---
|
| 410 |
dropZone.addEventListener('click', () => fileInput.click());
|
| 411 |
+
fileInput.addEventListener('change', (e) => {
|
| 412 |
+
const file = e.target.files[0];
|
| 413 |
+
if (file) handleFile(file);
|
| 414 |
+
});
|
| 415 |
+
|
| 416 |
+
['dragenter', 'dragover'].forEach(eventName => {
|
| 417 |
+
dropZone.addEventListener(eventName, (e) => {
|
| 418 |
+
e.preventDefault();
|
| 419 |
+
dropZone.classList.add('dragover');
|
| 420 |
+
}, false);
|
| 421 |
+
});
|
| 422 |
+
|
| 423 |
+
['dragleave', 'drop'].forEach(eventName => {
|
| 424 |
+
dropZone.addEventListener(eventName, (e) => {
|
| 425 |
+
e.preventDefault();
|
| 426 |
+
dropZone.classList.remove('dragover');
|
| 427 |
+
}, false);
|
| 428 |
+
});
|
| 429 |
+
|
| 430 |
+
dropZone.addEventListener('drop', (e) => {
|
| 431 |
+
const file = e.dataTransfer.files[0];
|
| 432 |
+
if (file) handleFile(file);
|
| 433 |
+
});
|
| 434 |
|
| 435 |
function handleFile(file) {
|
| 436 |
+
if (!file.type.startsWith('image/')) {
|
| 437 |
+
displayError('لطفا یک فایل تصویری انتخاب کن��د.');
|
| 438 |
+
return;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
uploadedFile = file;
|
| 442 |
+
|
| 443 |
const reader = new FileReader();
|
| 444 |
reader.onload = (e) => {
|
| 445 |
imagePreview.src = e.target.result;
|
| 446 |
+
imagePreview.style.display = 'block';
|
| 447 |
+
dropZoneText.style.display = 'none';
|
| 448 |
+
dropZoneIcon.style.display = 'none'; // Hide icon
|
| 449 |
+
submitBtn.disabled = promptInput.value.trim() === ''; // Enable if prompt is already filled
|
| 450 |
clearResult();
|
| 451 |
};
|
| 452 |
reader.readAsDataURL(file);
|
| 453 |
}
|
| 454 |
|
| 455 |
+
// --- Enable/Disable button based on both inputs ---
|
| 456 |
function checkFormState() {
|
| 457 |
submitBtn.disabled = !uploadedFile || promptInput.value.trim() === '';
|
| 458 |
}
|
| 459 |
+
promptInput.addEventListener('input', checkFormState);
|
| 460 |
+
|
| 461 |
|
| 462 |
+
// --- API Call Logic (Unchanged core logic) ---
|
| 463 |
submitBtn.addEventListener('click', async () => {
|
| 464 |
if (submitBtn.disabled) return;
|
| 465 |
+
|
| 466 |
setLoading(true);
|
| 467 |
+
|
| 468 |
const formData = new FormData();
|
| 469 |
formData.append('image', uploadedFile);
|
| 470 |
formData.append('prompt', promptInput.value.trim());
|
| 471 |
+
|
| 472 |
try {
|
| 473 |
+
const response = await fetch(API_URL, {
|
| 474 |
+
method: 'POST',
|
| 475 |
+
body: formData,
|
| 476 |
+
});
|
| 477 |
+
|
| 478 |
if (!response.ok) {
|
| 479 |
const errorData = await response.json().catch(() => ({ error: `خطای سرور: ${response.statusText}` }));
|
| 480 |
throw new Error(errorData.error || `یک خطای ناشناخته رخ داد.`);
|
| 481 |
}
|
| 482 |
+
|
| 483 |
const result = await response.json();
|
| 484 |
+
|
| 485 |
if (result.image_urls && Array.isArray(result.image_urls) && result.image_urls.length > 0) {
|
| 486 |
displayResult(result.image_urls);
|
| 487 |
} else {
|
| 488 |
throw new Error('پاسخ معتبری از سرور دریافت نشد. ممکن است سرور موقتا با مشکل مواجه شده باشد.');
|
| 489 |
}
|
| 490 |
+
|
| 491 |
} catch (error) {
|
| 492 |
displayError(error.message);
|
| 493 |
} finally {
|
|
|
|
| 495 |
}
|
| 496 |
});
|
| 497 |
|
| 498 |
+
// --- UI Helper Functions (Updated for animations) ---
|
| 499 |
function setLoading(isLoading) {
|
| 500 |
+
if (isLoading) {
|
| 501 |
+
loader.style.display = 'block';
|
| 502 |
+
resultContainer.classList.add('loading'); // Add loading class for pulse animation
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
submitBtn.disabled = true;
|
| 504 |
+
submitBtn.textContent = 'در حال پردازش...';
|
| 505 |
resultGrid.innerHTML = '';
|
| 506 |
errorMessage.style.display = 'none';
|
| 507 |
} else {
|
| 508 |
+
loader.style.display = 'none';
|
| 509 |
+
resultContainer.classList.remove('loading');
|
| 510 |
+
submitBtn.disabled = false;
|
| 511 |
+
submitBtn.textContent = 'ویرایش کن';
|
| 512 |
+
checkFormState(); // Re-check state after loading
|
| 513 |
}
|
| 514 |
}
|
| 515 |
|
| 516 |
function displayResult(imageUrls) {
|
| 517 |
+
resultGrid.innerHTML = ''; // Clear previous results
|
| 518 |
imageUrls.forEach((url, index) => {
|
| 519 |
const img = document.createElement('img');
|
| 520 |
img.src = url;
|
| 521 |
img.alt = 'تصویر ویرایش شده';
|
| 522 |
+
// Staggered animation delay
|
| 523 |
+
img.style.animationDelay = `${index * 100}ms`;
|
| 524 |
img.addEventListener('click', () => openLightbox(url));
|
| 525 |
resultGrid.appendChild(img);
|
| 526 |
});
|
|
|
|
| 536 |
errorMessage.style.display = 'block';
|
| 537 |
}
|
| 538 |
|
| 539 |
+
// --- Lightbox Functions (Unchanged) ---
|
| 540 |
function openLightbox(url) {
|
| 541 |
lightboxImg.src = url;
|
| 542 |
lightboxDownload.href = url;
|
| 543 |
lightbox.style.display = 'flex';
|
| 544 |
}
|
| 545 |
+
|
| 546 |
+
function closeLightbox() {
|
| 547 |
+
lightbox.style.display = 'none';
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
lightboxClose.addEventListener('click', closeLightbox);
|
| 551 |
+
lightbox.addEventListener('click', (e) => {
|
| 552 |
+
if (e.target === lightbox) { closeLightbox(); }
|
| 553 |
+
});
|
| 554 |
|
| 555 |
+
// Initial check in case of page refresh with filled form
|
| 556 |
checkFormState();
|
| 557 |
+
|
| 558 |
</script>
|
| 559 |
</body>
|
| 560 |
</html>
|