2023-12-05 18:35:18 +01:00
|
|
|
<script lang="ts">
|
2023-12-19 22:08:00 +01:00
|
|
|
/**
|
|
|
|
* Shows an image with attribution
|
|
|
|
*/
|
|
|
|
import ImageAttribution from "./ImageAttribution.svelte"
|
|
|
|
import type { ProvidedImage } from "../../Logic/ImageProviders/ImageProvider"
|
|
|
|
import { Mapillary } from "../../Logic/ImageProviders/Mapillary"
|
2023-12-19 23:02:02 +01:00
|
|
|
import { UIEventSource } from "../../Logic/UIEventSource"
|
2024-08-28 15:07:18 +02:00
|
|
|
import { MagnifyingGlassPlusIcon } from "@babeard/svelte-heroicons/outline"
|
2024-09-04 01:50:34 +02:00
|
|
|
import { CloseButton, Modal } from "flowbite-svelte"
|
|
|
|
import ImageOperations from "./ImageOperations.svelte"
|
|
|
|
import Popup from "../Base/Popup.svelte"
|
|
|
|
import { onDestroy } from "svelte"
|
2023-12-05 18:35:18 +01:00
|
|
|
|
2024-02-26 02:24:46 +01:00
|
|
|
export let image: Partial<ProvidedImage>
|
2023-12-19 22:08:00 +01:00
|
|
|
let fallbackImage: string = undefined
|
|
|
|
if (image.provider === Mapillary.singleton) {
|
|
|
|
fallbackImage = "./assets/svg/blocked.svg"
|
|
|
|
}
|
2023-12-05 18:35:18 +01:00
|
|
|
|
2023-12-19 22:08:00 +01:00
|
|
|
let imgEl: HTMLImageElement
|
|
|
|
export let imgClass: string = undefined
|
2024-08-28 15:07:18 +02:00
|
|
|
export let attributionFormat: "minimal" | "medium" | "large" = "medium"
|
2024-09-04 01:50:34 +02:00
|
|
|
export let previewedImage: UIEventSource<ProvidedImage>
|
|
|
|
export let canZoom = previewedImage !== undefined
|
2024-08-29 23:12:25 +02:00
|
|
|
let loaded = false
|
2024-09-04 01:50:34 +02:00
|
|
|
let showBigPreview = new UIEventSource(false)
|
|
|
|
onDestroy(showBigPreview.addCallbackAndRun(shown=>{
|
|
|
|
if(!shown){
|
|
|
|
previewedImage.set(false)
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
onDestroy(previewedImage.addCallbackAndRun(previewedImage => {
|
|
|
|
showBigPreview.set(previewedImage?.id === image.id)
|
|
|
|
}))
|
2023-12-05 18:35:18 +01:00
|
|
|
</script>
|
|
|
|
|
2024-09-04 02:51:21 +02:00
|
|
|
<Popup shown={showBigPreview} bodyPadding="p-0" dismissable={true}>
|
2024-09-04 01:50:34 +02:00
|
|
|
<div slot="close" />
|
|
|
|
<div style="height: 80vh">
|
|
|
|
<ImageOperations {image}>
|
|
|
|
<slot name="preview-action" />
|
|
|
|
</ImageOperations>
|
|
|
|
</div>
|
|
|
|
<div class="absolute top-4 right-4">
|
|
|
|
<CloseButton class="normal-background"
|
|
|
|
on:click={() => {console.log("Closing");previewedImage.set(undefined)}}></CloseButton>
|
|
|
|
</div>
|
|
|
|
</Popup>
|
2024-01-16 04:21:46 +01:00
|
|
|
<div class="relative shrink-0">
|
2024-08-28 15:07:18 +02:00
|
|
|
<div class="relative w-fit">
|
|
|
|
<img
|
|
|
|
bind:this={imgEl}
|
2024-09-02 12:48:15 +02:00
|
|
|
on:load={() => (loaded = true)}
|
2024-08-28 15:07:18 +02:00
|
|
|
class={imgClass ?? ""}
|
2024-09-04 01:50:34 +02:00
|
|
|
class:cursor-zoom-in={canZoom}
|
2024-08-28 15:07:18 +02:00
|
|
|
on:click={() => {
|
2024-09-04 02:56:01 +02:00
|
|
|
previewedImage?.set(image)
|
2023-12-21 01:46:18 +01:00
|
|
|
}}
|
2024-08-28 15:07:18 +02:00
|
|
|
on:error={() => {
|
2024-09-02 12:48:15 +02:00
|
|
|
if (fallbackImage) {
|
|
|
|
imgEl.src = fallbackImage
|
|
|
|
}
|
|
|
|
}}
|
2024-08-28 15:07:18 +02:00
|
|
|
src={image.url}
|
|
|
|
/>
|
2023-12-05 18:35:18 +01:00
|
|
|
|
2024-08-29 23:12:25 +02:00
|
|
|
{#if canZoom && loaded}
|
2024-09-02 12:48:15 +02:00
|
|
|
<div
|
|
|
|
class="bg-black-transparent absolute right-0 top-0 rounded-bl-full"
|
2024-09-04 01:50:34 +02:00
|
|
|
on:click={() => previewedImage.set(image)}>
|
2024-09-02 12:48:15 +02:00
|
|
|
<MagnifyingGlassPlusIcon class="h-8 w-8 cursor-zoom-in pl-3 pb-3" color="white" />
|
2024-08-28 15:07:18 +02:00
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2023-12-05 18:35:18 +01:00
|
|
|
<div class="absolute bottom-0 left-0">
|
2024-08-28 15:07:18 +02:00
|
|
|
<ImageAttribution {image} {attributionFormat} />
|
2023-12-05 18:35:18 +01:00
|
|
|
</div>
|
|
|
|
</div>
|