adds waypoint images

This commit is contained in:
Christian Beutel
2024-03-20 20:46:29 +01:00
parent 3e8fb85c05
commit e5b5e50747
26 changed files with 1064 additions and 221 deletions

View File

@@ -0,0 +1,40 @@
<script lang="ts">
import type { DataSource } from "photoswipe";
import PhotoSwipeLightbox from "photoswipe/lightbox";
import { onMount } from "svelte";
export let photos: string[];
export function open(idx: number = 0) {
lightbox.loadAndOpen(idx, lightboxDataSource)
}
let lightbox: PhotoSwipeLightbox;
let lightboxDataSource: DataSource;
onMount(() => {
lightboxDataSource = photos.map((p) => ({
src: p,
}));
lightbox = new PhotoSwipeLightbox({
dataSource: lightboxDataSource,
pswpModule: async () => await import("photoswipe"),
});
lightbox.init();
lightbox.on("beforeOpen", () => {
const pswp = lightbox.pswp;
const ds = pswp?.options?.dataSource;
if (Array.isArray(ds)) {
for (let idx = 0, len = ds.length; idx < len; idx++) {
const item = ds[idx];
const img = new Image();
img.onload = () => {
item.width = img.naturalWidth;
item.height = img.naturalHeight;
pswp?.refreshSlideContent(idx);
};
img.src = item.src as string;
}
}
});
});
</script>