diff --git a/README.md b/README.md index a82abe8..753bb92 100644 --- a/README.md +++ b/README.md @@ -259,9 +259,6 @@ The source codes used from third party projects are: - [images.ts](src/helpers/images.ts) from [vercel/next.js](https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/image-blur-svg.ts) with [license](licenses/LICENSE.vercel.txt) -- [photoswipe-auto-hide-ui.js](src/assets/scripts/photoswipe/photoswipe-auto-hide-ui.js) - from [arnowelzel/photoswipe-auto-hide-ui](https://github.com/arnowelzel/photoswipe-auto-hide-ui) - with [license](licenses/LICENSE.arnowelzel.txt) -- [photoswipe-slideshow.js](src/assets/scripts/photoswipe/photoswipe-slideshow.js) +- [photoswipe-slideshow.js](src/assets/scripts/photoswipe-slideshow.js) from [junkfix/photoswipe-slideshow](https://github.com/junkfix/photoswipe-slideshow) with [license](licenses/LICENSE.junkfix.txt) diff --git a/package-lock.json b/package-lock.json index 093c352..9b716d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "unist-util-select": "^5.1.0" }, "engines": { - "node": "22.11.0" + "node": "22.12.0" } }, "node_modules/@astrojs/check": { diff --git a/package.json b/package.json index 3adbf7a..acf3be5 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,6 @@ }, "packageManager": "npm@10.9.1", "engines": { - "node": "22.11.0" + "node": "22.12.0" } } diff --git a/src/assets/scripts/photoswipe/photoswipe-slideshow.js b/src/assets/scripts/photoswipe-slideshow.js similarity index 100% rename from src/assets/scripts/photoswipe/photoswipe-slideshow.js rename to src/assets/scripts/photoswipe-slideshow.js diff --git a/src/assets/scripts/photoswipe/photoswipe-auto-hide-ui.js b/src/assets/scripts/photoswipe/photoswipe-auto-hide-ui.js deleted file mode 100644 index e0ac2de..0000000 --- a/src/assets/scripts/photoswipe/photoswipe-auto-hide-ui.js +++ /dev/null @@ -1,92 +0,0 @@ -/** - * PhotoSwipe Auto Hide UI plugin v1.0.1 - * - * https://github.com/arnowelzel/photoswipe-auto-hide-ui - */ -const defaultOptions = { - idleTime: 4000, -}; - -class PhotoSwipeAutoHideUI { - constructor(lightbox, options) { - this.options = { - ...defaultOptions, - ...options, - }; - - this.captionTimer = false; - - this.lightbox = lightbox; - - this.hasTouch = false; - - this.lightbox.on('change', () => { - document.addEventListener( - 'touchstart', - () => { - this.stopHideTimer(); - this.hasTouch = true; - }, - { once: true }, - ); - document.addEventListener( - 'mousemove', - () => { - this.startHideTimer(); - }, - { once: true }, - ); - }); - - this.lightbox.on('destroy', () => { - this.stopHideTimer(); - }); - } - - showUI() { - if (this.lightbox?.pswp?.element) { - this.lightbox.pswp.element.classList.add('pswp--ui-visible'); - } - } - - hideUI() { - if (this.lightbox?.pswp?.element) { - this.lightbox.pswp.element.classList.remove('pswp--ui-visible'); - } - } - - mouseMove() { - this.stopHideTimer(); - if (this.lightbox) { - this.showUI(); - this.startHideTimer(); - } - } - - startHideTimer() { - if (this.hasTouch) { - return; - } - - this.stopHideTimer(); - this.captionTimer = window.setTimeout(() => { - this.hideUI(); - }, this.options.idleTime); - document.addEventListener( - 'mousemove', - () => { - this.mouseMove(); - }, - { once: true }, - ); - } - - stopHideTimer() { - if (this.captionTimer) { - window.clearTimeout(this.captionTimer); - this.captionTimer = false; - } - } -} - -export default PhotoSwipeAutoHideUI; diff --git a/src/assets/scripts/yufan.me.js b/src/assets/scripts/yufan.me.js index d7c376b..9405dda 100644 --- a/src/assets/scripts/yufan.me.js +++ b/src/assets/scripts/yufan.me.js @@ -4,8 +4,7 @@ import PhotoSwipe from 'photoswipe'; import PhotoSwipeDynamicCaption from 'photoswipe-dynamic-caption-plugin'; import PhotoSwipeVideo from 'photoswipe-video-plugin'; import PhotoSwipeLightbox from 'photoswipe/lightbox'; -import PhotoSwipeAutoHideUI from './photoswipe/photoswipe-auto-hide-ui.js'; -import PhotoSwipeSlideshow from './photoswipe/photoswipe-slideshow.js'; +import PhotoSwipeSlideshow from './photoswipe-slideshow.js'; import stickySidebar from './sticky-sidebar.js'; // Slideshow for Album. @@ -15,6 +14,8 @@ for (const album of document.querySelectorAll('.post-content .album')) { gallery: album, pswpModule: PhotoSwipe, children: 'a', + showHideAnimationType: 'zoom', + zoomAnimationDuration: 400, bgOpacity: 1, }); @@ -25,7 +26,7 @@ for (const album of document.querySelectorAll('.post-content .album')) { // Add a slideshow to the PhotoSwipe gallery. new PhotoSwipeSlideshow(lightbox, { - defaultDelayMs: 7000, // 7 seconds + defaultDelayMs: 7000, restartOnSlideChange: true, progressBarPosition: 'top', autoHideProgressBar: false, @@ -34,9 +35,6 @@ for (const album of document.querySelectorAll('.post-content .album')) { // Plugin to display video. new PhotoSwipeVideo(lightbox, {}); - // Hide the PhotoSwipe UI after some time of inactivity. - new PhotoSwipeAutoHideUI(lightbox, {}); - lightbox.init(); } diff --git a/src/components/album/Album.astro b/src/components/album/Album.astro index 3e54417..65323ba 100644 --- a/src/components/album/Album.astro +++ b/src/components/album/Album.astro @@ -9,6 +9,23 @@ interface Props { const { id } = Astro.props; const album = getAlbum(id); + +const calculateCroppedWidth = (width: number, height: number, first: boolean): number => { + // 300 * 300 + if (!first) { + if (width < 300 || height < 300) { + return width; + } + return width > height ? Math.round((300.0 / height) * width) : 300; + } + // 600 * 300 + if (width < 600 || height < 300) { + return width; + } + return width > height ? (600.0 / width > 300.0 / height ? 600 : Math.round((300.0 / height) * width)) : 600; +}; +const calculateCroppedHeight = (width: number, height: number, croppedWidth: number): number => + croppedWidth === width ? height : Math.round(((1.0 * croppedWidth) / width) * height); --- { @@ -25,8 +42,18 @@ const album = getAlbum(id); class="media-content album-picture" data-pswp-width={picture.width} data-pswp-height={picture.height} + data-cropped="true" > - {picture.title + {picture.title
{picture.title &&

{picture.title}

} diff --git a/src/components/album/UnstyledAlbum.astro b/src/components/album/UnstyledAlbum.astro index 2abc521..0488013 100644 --- a/src/components/album/UnstyledAlbum.astro +++ b/src/components/album/UnstyledAlbum.astro @@ -13,7 +13,6 @@ const album = getAlbum(id); { album !== undefined && ( -

{album.title}

{album.description && } {album.pictures.map((picture) => (