Spaces:
Running
Running
File size: 33,394 Bytes
cf27778 2a1eee8 cf27778 0e5135e cf27778 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 0e5135e cf27778 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 0e5135e cf27778 2a1eee8 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 0e5135e cf27778 2a1eee8 0e5135e cf27778 2a1eee8 0e5135e cf27778 2a1eee8 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 0e5135e cf27778 0e5135e cf27778 2a1eee8 0e5135e cf27778 2a1eee8 0e5135e cf27778 2a1eee8 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 0e5135e 2a1eee8 0e5135e 2a1eee8 0e5135e 2a1eee8 0e5135e 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 0e5135e 2a1eee8 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 0e5135e cf27778 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 0e5135e 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 0e5135e 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 0e5135e 2a1eee8 0e5135e 2a1eee8 0e5135e 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 0e5135e cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 2a1eee8 cf27778 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Local Image Viewer</title>
<!-- Local Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#3B82F6',
}
}
}
}
</script>
<!-- Local Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.dropzone {
border: 3px dashed #9CA3AF;
transition: all 0.3s ease;
}
.dropzone.active {
border-color: #3B82F6;
background-color: rgba(59, 130, 246, 0.1);
}
.image-container {
transition: transform 0.3s ease;
}
.image-container:hover {
transform: scale(1.01);
}
.nav-btn {
transition: all 0.2s ease;
}
.nav-btn:hover {
transform: scale(1.1);
}
.nav-btn:active {
transform: scale(0.95);
}
.file-item:hover {
background-color: rgba(59, 130, 246, 0.1);
}
.file-item.active {
background-color: rgba(59, 130, 246, 0.2);
border-left: 3px solid #3B82F6;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.fade-in {
animation: fadeIn 0.3s ease-in-out;
}
#fullscreenContainer {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
z-index: 1000;
justify-content: center;
align-items: center;
flex-direction: column;
}
#fullscreenImage {
max-width: 90%;
max-height: 90%;
object-fit: contain;
}
#fullscreenControls {
position: absolute;
bottom: 20px;
display: flex;
gap: 10px;
}
.sort-option:hover {
background-color: rgba(59, 130, 246, 0.1);
}
</style>
</head>
<body class="bg-gray-100 min-h-screen">
<div class="container mx-auto px-4 py-8">
<div class="max-w-6xl mx-auto">
<h1 class="text-3xl font-bold text-center text-gray-800 mb-2">Local Image Viewer</h1>
<p class="text-center text-gray-600 mb-8">View your local WebP, PNG, JPEG, AVIF, and HEIC files with ease
</p>
<div class="bg-white rounded-xl shadow-lg overflow-hidden mb-8">
<!-- Dropzone area -->
<div id="dropzone" class="dropzone p-12 text-center cursor-pointer" role="region"
aria-label="File drop zone">
<div class="flex flex-col items-center justify-center">
<i class="fas fa-images text-5xl text-gray-400 mb-4" aria-hidden="true"></i>
<h3 class="text-xl font-semibold text-gray-700 mb-2">Drag & Drop Images Here</h3>
<p class="text-gray-500 mb-4">or</p>
<button id="browseBtn"
class="bg-blue-500 hover:bg-blue-600 text-white font-medium py-2 px-6 rounded-lg transition"
aria-label="Browse files">
Browse Files
</button>
<input type="file" id="fileInput" class="hidden"
accept=".webp,.png,.jpg,.jpeg,.avif,.heic,.heif" multiple>
</div>
</div>
<!-- Main viewer area (hidden initially) -->
<div id="viewerArea" class="hidden">
<div class="flex flex-col md:flex-row">
<!-- Sidebar with file list -->
<div class="w-full md:w-1/4 bg-gray-50 border-r border-gray-200 max-h-[70vh] overflow-y-auto">
<div class="p-4 border-b border-gray-200 flex justify-between items-center">
<h3 class="font-medium text-gray-700">Files (<span id="fileCount">0</span>)</h3>
<div class="relative">
<button id="sortBtn" class="text-gray-600 hover:text-gray-800"
aria-label="Sort options" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-sort" aria-hidden="true"></i>
</button>
<div id="sortDropdown"
class="hidden absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 py-1">
<div class="sort-option px-4 py-2 text-sm text-gray-700 cursor-pointer"
data-sort="name-asc" role="menuitem">Name (A-Z)</div>
<div class="sort-option px-4 py-2 text-sm text-gray-700 cursor-pointer"
data-sort="name-desc" role="menuitem">Name (Z-A)</div>
<div class="sort-option px-4 py-2 text-sm text-gray-700 cursor-pointer"
data-sort="size-asc" role="menuitem">Size (Small to Large)</div>
<div class="sort-option px-4 py-2 text-sm text-gray-700 cursor-pointer"
data-sort="size-desc" role="menuitem">Size (Large to Small)</div>
<div class="sort-option px-4 py-2 text-sm text-gray-700 cursor-pointer"
data-sort="date-asc" role="menuitem">Date (Oldest First)</div>
<div class="sort-option px-4 py-2 text-sm text-gray-700 cursor-pointer"
data-sort="date-desc" role="menuitem">Date (Newest First)</div>
</div>
</div>
</div>
<ul id="fileList" class="divide-y divide-gray-200" role="list">
<!-- Files will be listed here -->
</ul>
</div>
<!-- Main image display -->
<div class="w-full md:w-3/4 p-4 flex flex-col items-center justify-center">
<div class="relative w-full max-w-3xl">
<!-- Navigation buttons -->
<button id="prevBtn"
class="nav-btn absolute left-0 top-1/2 -translate-y-1/2 bg-white/80 hover:bg-white text-gray-800 p-3 rounded-full shadow-md ml-4 z-10"
aria-label="Previous image">
<i class="fas fa-chevron-left text-xl" aria-hidden="true"></i>
</button>
<button id="nextBtn"
class="nav-btn absolute right-0 top-1/2 -translate-y-1/2 bg-white/80 hover:bg-white text-gray-800 p-3 rounded-full shadow-md mr-4 z-10"
aria-label="Next image">
<i class="fas fa-chevron-right text-xl" aria-hidden="true"></i>
</button>
<!-- Image display area -->
<div class="image-container bg-gray-100 rounded-lg overflow-hidden flex items-center justify-center"
style="min-height: 400px;">
<div id="imageDisplay" class="p-4 w-full h-full flex items-center justify-center">
<p class="text-gray-500">Select an image to view</p>
</div>
</div>
<!-- Image info -->
<div class="mt-4 bg-gray-50 rounded-lg p-3">
<div class="flex justify-between items-center">
<div>
<h4 id="fileName" class="font-medium text-gray-800 truncate">No image
selected</h4>
<p id="fileInfo" class="text-sm text-gray-500">-</p>
</div>
<div class="flex space-x-2">
<button id="zoomInBtn"
class="nav-btn bg-gray-200 hover:bg-gray-300 text-gray-700 p-2 rounded"
aria-label="Zoom in">
<i class="fas fa-search-plus" aria-hidden="true"></i>
</button>
<button id="zoomOutBtn"
class="nav-btn bg-gray-200 hover:bg-gray-300 text-gray-700 p-2 rounded"
aria-label="Zoom out">
<i class="fas fa-search-minus" aria-hidden="true"></i>
</button>
<button id="resetZoomBtn"
class="nav-btn bg-gray-200 hover:bg-gray-300 text-gray-700 p-2 rounded"
aria-label="Reset zoom">
<i class="fas fa-expand" aria-hidden="true"></i>
</button>
<button id="fullscreenBtn"
class="nav-btn bg-gray-200 hover:bg-gray-300 text-gray-700 p-2 rounded"
aria-label="Fullscreen">
<i class="fas fa-expand-arrows-alt" aria-hidden="true"></i>
</button>
</div>
</div>
<div class="mt-2">
<div class="w-full bg-gray-200 rounded-full h-2">
<div id="progressBar" class="bg-blue-500 h-2 rounded-full"
style="width: 0%"></div>
</div>
<div class="flex justify-between text-xs text-gray-500 mt-1">
<span id="currentIndex">0</span>
<span id="totalImages">0</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="text-center text-gray-500 text-sm mt-8">
<p>Use arrow keys to navigate between images</p>
<p class="mt-1">Supported formats: WebP, PNG, JPEG, AVIF, HEIC</p>
</div>
</div>
</div>
<!-- Fullscreen container -->
<div id="fullscreenContainer" role="dialog" aria-modal="true" aria-label="Fullscreen image viewer">
<img id="fullscreenImage" src="" alt="Fullscreen Image">
<div id="fullscreenControls">
<button id="fsPrevBtn" class="nav-btn bg-white/20 hover:bg-white/40 text-white p-3 rounded-full"
aria-label="Previous image">
<i class="fas fa-chevron-left text-xl" aria-hidden="true"></i>
</button>
<button id="fsCloseBtn" class="nav-btn bg-white/20 hover:bg-white/40 text-white p-3 rounded-full"
aria-label="Close fullscreen">
<i class="fas fa-times text-xl" aria-hidden="true"></i>
</button>
<button id="fsNextBtn" class="nav-btn bg-white/20 hover:bg-white/40 text-white p-3 rounded-full"
aria-label="Next image">
<i class="fas fa-chevron-right text-xl" aria-hidden="true"></i>
</button>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
// DOM elements
const dropzone = document.getElementById('dropzone');
const browseBtn = document.getElementById('browseBtn');
const fileInput = document.getElementById('fileInput');
const viewerArea = document.getElementById('viewerArea');
const fileList = document.getElementById('fileList');
const imageDisplay = document.getElementById('imageDisplay');
const fileName = document.getElementById('fileName');
const fileInfo = document.getElementById('fileInfo');
const fileCount = document.getElementById('fileCount');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
const zoomInBtn = document.getElementById('zoomInBtn');
const zoomOutBtn = document.getElementById('zoomOutBtn');
const resetZoomBtn = document.getElementById('resetZoomBtn');
const fullscreenBtn = document.getElementById('fullscreenBtn');
const progressBar = document.getElementById('progressBar');
const currentIndex = document.getElementById('currentIndex');
const totalImages = document.getElementById('totalImages');
const sortBtn = document.getElementById('sortBtn');
const sortDropdown = document.getElementById('sortDropdown');
const fullscreenContainer = document.getElementById('fullscreenContainer');
const fullscreenImage = document.getElementById('fullscreenImage');
const fsPrevBtn = document.getElementById('fsPrevBtn');
const fsNextBtn = document.getElementById('fsNextBtn');
const fsCloseBtn = document.getElementById('fsCloseBtn');
// State variables
let files = [];
let currentFileIndex = -1;
let zoomLevel = 1;
const maxZoom = 3;
const minZoom = 0.5;
const zoomStep = 0.1;
let currentSortMethod = 'name-asc';
// Event listeners for dropzone
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
dropzone.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropzone.classList.add('active');
}
function unhighlight() {
dropzone.classList.remove('active');
}
dropzone.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
const dt = e.dataTransfer;
const droppedFiles = dt.files;
handleFiles(droppedFiles);
}
// Browse button click
browseBtn.addEventListener('click', () => {
fileInput.click();
});
// File input change
fileInput.addEventListener('change', () => {
if (fileInput.files.length > 0) {
handleFiles(fileInput.files);
}
});
// Navigation buttons
prevBtn.addEventListener('click', showPreviousImage);
nextBtn.addEventListener('click', showNextImage);
// Zoom buttons
zoomInBtn.addEventListener('click', zoomIn);
zoomOutBtn.addEventListener('click', zoomOut);
resetZoomBtn.addEventListener('click', resetZoom);
fullscreenBtn.addEventListener('click', openFullscreen);
// Sort functionality
sortBtn.addEventListener('click', (e) => {
e.stopPropagation();
const isExpanded = sortDropdown.classList.toggle('hidden');
sortBtn.setAttribute('aria-expanded', !isExpanded);
});
document.querySelectorAll('.sort-option').forEach(option => {
option.addEventListener('click', (e) => {
currentSortMethod = e.target.dataset.sort;
sortFiles();
updateFileList();
showImage(currentFileIndex);
sortDropdown.classList.add('hidden');
sortBtn.setAttribute('aria-expanded', 'false');
});
});
// Close dropdown when clicking outside
document.addEventListener('click', () => {
sortDropdown.classList.add('hidden');
sortBtn.setAttribute('aria-expanded', 'false');
});
// Fullscreen functionality
fsPrevBtn.addEventListener('click', () => {
showPreviousImage();
updateFullscreenImage();
});
fsNextBtn.addEventListener('click', () => {
showNextImage();
updateFullscreenImage();
});
fsCloseBtn.addEventListener('click', closeFullscreen);
// Keyboard navigation
document.addEventListener('keydown', (e) => {
if (files.length === 0) return;
switch (e.key) {
case 'ArrowLeft':
if (fullscreenContainer.style.display === 'flex') {
showPreviousImage();
updateFullscreenImage();
} else {
showPreviousImage();
}
break;
case 'ArrowRight':
if (fullscreenContainer.style.display === 'flex') {
showNextImage();
updateFullscreenImage();
} else {
showNextImage();
}
break;
case '+':
case '=':
zoomIn();
break;
case '-':
zoomOut();
break;
case '0':
resetZoom();
break;
case 'Escape':
if (fullscreenContainer.style.display === 'flex') {
closeFullscreen();
}
break;
case 'f':
case 'F':
if (imageDisplay.querySelector('img')) {
if (fullscreenContainer.style.display === 'flex') {
closeFullscreen();
} else {
openFullscreen();
}
}
break;
}
});
// Handle dropped or selected files
function handleFiles(newFiles) {
// Filter for supported image types
const supportedTypes = [
'image/webp',
'image/png',
'image/jpeg',
'image/avif',
'image/heic',
'image/heif'
];
const imageFiles = Array.from(newFiles).filter(file => {
// Check MIME type first
if (supportedTypes.includes(file.type)) return true;
// Fallback for file extensions (some browsers might not recognize HEIC/AVIF MIME types)
const extension = file.name.split('.').pop().toLowerCase();
return ['webp', 'png', 'jpg', 'jpeg', 'avif', 'heic', 'heif'].includes(extension);
});
if (imageFiles.length === 0) {
alert('No supported image files found. Please upload WebP, PNG, JPEG, AVIF, or HEIC files.');
return;
}
files = imageFiles;
currentFileIndex = 0;
zoomLevel = 1;
// Sort files
sortFiles();
// Update UI
updateFileList();
showImage(currentFileIndex);
viewerArea.classList.remove('hidden');
// Scroll to top
window.scrollTo(0, 0);
}
// Sort files based on current sort method
function sortFiles() {
switch (currentSortMethod) {
case 'name-asc':
files.sort((a, b) => a.name.localeCompare(b.name));
break;
case 'name-desc':
files.sort((a, b) => b.name.localeCompare(a.name));
break;
case 'size-asc':
files.sort((a, b) => a.size - b.size);
break;
case 'size-desc':
files.sort((a, b) => b.size - a.size);
break;
case 'date-asc':
files.sort((a, b) => a.lastModified - b.lastModified);
break;
case 'date-desc':
files.sort((a, b) => b.lastModified - a.lastModified);
break;
}
// Update current file index to maintain selection
if (currentFileIndex >= 0 && files.length > 0) {
currentFileIndex = 0;
}
}
// Update the file list sidebar
function updateFileList() {
fileList.innerHTML = '';
fileCount.textContent = files.length;
totalImages.textContent = files.length;
files.forEach((file, index) => {
const listItem = document.createElement('li');
listItem.className = `file-item cursor-pointer ${index === currentFileIndex ? 'active' : ''}`;
listItem.setAttribute('role', 'listitem');
listItem.innerHTML = `
<div class="flex items-center p-3">
<div class="flex-shrink-0 h-10 w-10 rounded bg-gray-200 overflow-hidden">
<img src="#" alt="Thumbnail" class="h-full w-full object-cover thumbnail" data-index="${index}">
</div>
<div class="ml-3 overflow-hidden">
<p class="text-sm font-medium text-gray-900 truncate">${file.name}</p>
<p class="text-sm text-gray-500">${formatFileSize(file.size)}</p>
</div>
</div>
`;
listItem.addEventListener('click', () => {
showImage(index);
});
// Keyboard navigation for file list items
listItem.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
showImage(index);
}
});
listItem.setAttribute('tabindex', '0');
fileList.appendChild(listItem);
// Load thumbnail
const reader = new FileReader();
reader.onload = (e) => {
const thumbnails = document.querySelectorAll(`.thumbnail[data-index="${index}"]`);
thumbnails.forEach(thumb => {
thumb.src = e.target.result;
});
};
reader.readAsDataURL(file);
});
}
// Show image at specified index
function showImage(index) {
if (index < 0 || index >= files.length) return;
currentFileIndex = index;
const file = files[index];
// Update active item in file list
document.querySelectorAll('.file-item').forEach((item, i) => {
if (i === index) {
item.classList.add('active');
item.setAttribute('aria-selected', 'true');
} else {
item.classList.remove('active');
item.setAttribute('aria-selected', 'false');
}
});
// Update progress
currentIndex.textContent = index + 1;
progressBar.style.width = `${((index + 1) / files.length) * 100}%`;
// Display the image
const reader = new FileReader();
reader.onload = (e) => {
imageDisplay.innerHTML = '';
const img = document.createElement('img');
img.src = e.target.result;
img.className = 'max-w-full max-h-[70vh] object-contain fade-in';
img.style.transform = `scale(${zoomLevel})`;
img.style.transformOrigin = 'center center';
img.style.transition = 'transform 0.2s ease';
img.setAttribute('alt', `Preview of ${file.name}`);
// Add drag to pan functionality
let isDragging = false;
let startX, startY, translateX = 0, translateY = 0;
img.addEventListener('mousedown', (e) => {
if (zoomLevel <= 1) return;
isDragging = true;
startX = e.clientX - translateX;
startY = e.clientY - translateY;
img.style.cursor = 'grabbing';
});
document.addEventListener('mousemove', (e) => {
if (!isDragging) return;
translateX = e.clientX - startX;
translateY = e.clientY - startY;
img.style.transform = `scale(${zoomLevel}) translate(${translateX}px, ${translateY}px)`;
});
document.addEventListener('mouseup', () => {
isDragging = false;
img.style.cursor = 'grab';
});
img.addEventListener('mouseenter', () => {
if (zoomLevel > 1) {
img.style.cursor = 'grab';
}
});
img.addEventListener('mouseleave', () => {
img.style.cursor = 'default';
});
imageDisplay.appendChild(img);
// Update file info
fileName.textContent = file.name;
fileInfo.textContent = `${getFileType(file)} • ${formatFileSize(file.size)}`;
// Load image dimensions after the image is loaded
img.onload = () => {
fileInfo.textContent = `${img.naturalWidth}×${img.naturalHeight} • ${getFileType(file)} • ${formatFileSize(file.size)}`;
};
};
reader.readAsDataURL(file);
// Enable/disable navigation buttons
prevBtn.disabled = index === 0;
nextBtn.disabled = index === files.length - 1;
}
// Helper to get file type
function getFileType(file) {
if (file.type) {
const type = file.type.split('/')[1];
if (type) return type.toUpperCase();
}
// Fallback for file extension
const extension = file.name.split('.').pop().toLowerCase();
switch (extension) {
case 'jpg':
case 'jpeg': return 'JPEG';
case 'png': return 'PNG';
case 'webp': return 'WEBP';
case 'avif': return 'AVIF';
case 'heic':
case 'heif': return 'HEIC';
default: return extension.toUpperCase();
}
}
// Navigation functions
function showPreviousImage() {
if (currentFileIndex > 0) {
showImage(currentFileIndex - 1);
}
}
function showNextImage() {
if (currentFileIndex < files.length - 1) {
showImage(currentFileIndex + 1);
}
}
// Zoom functions
function zoomIn() {
if (zoomLevel < maxZoom) {
zoomLevel += zoomStep;
applyZoom();
}
}
function zoomOut() {
if (zoomLevel > minZoom) {
zoomLevel -= zoomStep;
applyZoom();
}
}
function resetZoom() {
zoomLevel = 1;
applyZoom();
}
function applyZoom() {
const img = imageDisplay.querySelector('img');
if (img) {
img.style.transform = `scale(${zoomLevel})`;
// Reset pan position when zooming
if (zoomLevel <= 1) {
img.style.transform = `scale(${zoomLevel}) translate(0, 0)`;
}
}
}
// Fullscreen functions
function openFullscreen() {
const img = imageDisplay.querySelector('img');
if (!img) return;
fullscreenImage.src = img.src;
fullscreenContainer.style.display = 'flex';
document.body.style.overflow = 'hidden';
fullscreenContainer.setAttribute('aria-hidden', 'false');
}
function closeFullscreen() {
fullscreenContainer.style.display = 'none';
document.body.style.overflow = '';
fullscreenContainer.setAttribute('aria-hidden', 'true');
}
function updateFullscreenImage() {
const img = imageDisplay.querySelector('img');
if (img) {
fullscreenImage.src = img.src;
}
}
// Helper function to format file size
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=jsfs11/local-image-viewer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |