diff --git a/src/lib/components/gallery-carousel.svelte b/src/lib/components/gallery-carousel.svelte index 431bad7b..5fb92115 100644 --- a/src/lib/components/gallery-carousel.svelte +++ b/src/lib/components/gallery-carousel.svelte @@ -17,6 +17,8 @@ type GalleryImage = (ImageRecord | ImageThumbnails) & { export let images: Array export let initialIndex: number export let onClose: () => void +export let send +export let receive let carousel: HTMLElement @@ -60,6 +62,8 @@ function handleEscape(event: KeyboardEvent) { class="flex snap-center items-center justify-center p-2 md:p-4 xl:p-8" data-index={index} on:click|self|stopPropagation={onClose} + in:receive={{ key: index }} + out:send={{ key: index }} >
diff --git a/src/lib/components/lens-gallery.svelte b/src/lib/components/lens-gallery.svelte index 4b53c8e5..77fbbeea 100644 --- a/src/lib/components/lens-gallery.svelte +++ b/src/lib/components/lens-gallery.svelte @@ -7,6 +7,8 @@ import MasonryGrid from './masonry-grid.svelte' export let images export let isHidden export let onOpen +export let send +export let receive @@ -17,6 +19,8 @@ export let onOpen class:opacity-30={isHidden} data-index={index} on:click={onOpen(index)} + in:receive={{ key: index }} + out:send={{ key: index }} > +import { crossfade, scale } from 'svelte/transition' + import GalleryCarousel from '$lib/components/gallery-carousel.svelte' import LensGallery from '$lib/components/lens-gallery.svelte' import PageIntro from '$lib/components/page-intro.svelte' @@ -9,12 +11,22 @@ export let data $: ({ title, subtitle, description, images, content } = data.json) $: fullTitle = subtitle ? [title, subtitle].join(' ') : title -let isCarouselOpen = false +let isCarouselOpen = null let initialIndex = 0 +const [send, receive] = crossfade({ + duration: 200, + fallback: scale, +}) + async function handleOpenCarousel(index) { - isCarouselOpen = true - initialIndex = index + const image = new Image() + + image.addEventListener('load', () => { + isCarouselOpen = true + initialIndex = index + }) + image.src = `${images[index].path.replace(/^static/, '')}` } function handleCloseCarousel() { @@ -44,13 +56,19 @@ function handleCloseCarousel() { {images} isHidden={isCarouselOpen} onOpen={handleOpenCarousel} + {send} + {receive} /> {#if isCarouselOpen} - + {#await isCarouselOpen then} + + {/await} {/if}
{@html content}