diff --git a/packages/polymech/src/components/GalleryK.astro b/packages/polymech/src/components/GalleryK.astro index bfd1c25..749a01e 100644 --- a/packages/polymech/src/components/GalleryK.astro +++ b/packages/polymech/src/components/GalleryK.astro @@ -65,16 +65,24 @@ const locale = Astro.currentLocale || "en"; images: ${JSON.stringify(images)}, lastTapTime: 0, doubleTapDelay: 300, + scale: 1, + panX: 0, + panY: 0, + isPanning: false, + startPanX: 0, + startPanY: 0, handleSwipe() { - if (!this.isSwiping) return; + if (!this.isSwiping || this.scale > 1) return; // Disable swipe when zoomed const swipeDistance = this.touchEndX - this.touchStartX; if (Math.abs(swipeDistance) >= this.minSwipeDistance) { if (swipeDistance > 0 && this.currentIndex > 0) { // Swiped right, show previous image this.currentIndex--; + this.resetZoom(); } else if (swipeDistance < 0 && this.currentIndex < this.total - 1) { // Swiped left, show next image this.currentIndex++; + this.resetZoom(); } } this.isSwiping = false; @@ -82,6 +90,7 @@ const locale = Astro.currentLocale || "en"; preloadAndOpen() { if (this.isSwiping) return; this.lightboxLoaded = false; + this.resetZoom(); let img = new Image(); img.src = this.images[this.currentIndex].src; img.onload = () => { @@ -91,11 +100,12 @@ const locale = Astro.currentLocale || "en"; }, preloadImage(index) { // Preload without affecting lightboxLoaded state (for navigation within lightbox) + this.resetZoom(); let img = new Image(); img.src = this.images[index].src; // No need to wait for load when navigating within lightbox }, - handleThumbnailClick(index) { + handleImageInteraction(index) { const currentTime = Date.now(); const timeDiff = currentTime - this.lastTapTime; @@ -109,6 +119,46 @@ const locale = Astro.currentLocale || "en"; } this.lastTapTime = currentTime; + }, + resetZoom() { + this.scale = 1; + this.panX = 0; + this.panY = 0; + this.isPanning = false; + }, + handleWheel(e) { + e.preventDefault(); + const zoomSpeed = 0.1; + const newScale = this.scale - Math.sign(e.deltaY) * zoomSpeed; + this.scale = Math.min(Math.max(1, newScale), 5); // Limit zoom between 1x and 5x + + if (this.scale === 1) { + this.panX = 0; + this.panY = 0; + } + }, + handlePanStart(e) { + if (this.scale <= 1) return; + this.isPanning = true; + this.startPanX = e.clientX - this.panX; + this.startPanY = e.clientY - this.panY; + e.preventDefault(); + }, + handlePanMove(e) { + if (!this.isPanning) return; + e.preventDefault(); + this.panX = e.clientX - this.startPanX; + this.panY = e.clientY - this.startPanY; + }, + handlePanEnd(e) { + this.isPanning = false; + }, + toggleZoom(e) { + if (this.scale > 1) { + this.resetZoom(); + } else { + this.scale = 2; // Zoom to 2x on double click + } } } `} @@ -125,8 +175,8 @@ const locale = Astro.currentLocale || "en"; class="product-gallery bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 overflow-hidden">
(