2021-10-26 22:15:01 +02:00
|
|
|
<script>
|
2021-12-28 13:56:24 +01:00
|
|
|
import { createEventDispatcher } from "svelte"
|
|
|
|
let dispatch = createEventDispatcher()
|
|
|
|
|
2021-12-13 16:33:23 +01:00
|
|
|
export const set_file = f => file = f
|
|
|
|
let file = {
|
2021-10-26 22:15:01 +02:00
|
|
|
id: "",
|
|
|
|
name: "",
|
|
|
|
mime_type: "",
|
|
|
|
get_href: "",
|
|
|
|
}
|
2021-12-13 16:33:23 +01:00
|
|
|
|
2021-10-26 22:15:01 +02:00
|
|
|
let container
|
|
|
|
let zoom = false
|
|
|
|
let x, y = 0
|
|
|
|
let dragging = false
|
|
|
|
|
|
|
|
const mousedown = (e) => {
|
|
|
|
if (!dragging && e.which === 1 && zoom) {
|
|
|
|
x = e.pageX
|
|
|
|
y = e.pageY
|
|
|
|
dragging = true
|
|
|
|
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const mousemove = (e) => {
|
|
|
|
if (dragging) {
|
|
|
|
container.scrollLeft = container.scrollLeft - (e.pageX - x)
|
|
|
|
container.scrollTop = container.scrollTop - (e.pageY - y)
|
|
|
|
|
|
|
|
x = e.pageX
|
|
|
|
y = e.pageY
|
|
|
|
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const mouseup = (e) => {
|
|
|
|
if (dragging) {
|
|
|
|
dragging = false
|
|
|
|
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<svelte:window on:mousemove={mousemove} on:mouseup={mouseup} />
|
|
|
|
|
|
|
|
<div bind:this={container} class="container" class:zoom>
|
|
|
|
<img
|
2021-12-28 13:56:24 +01:00
|
|
|
on:loadstart={() => {dispatch("loading", true)}}
|
|
|
|
on:load={() => {dispatch("loading", false)}}
|
2021-12-28 17:04:00 +01:00
|
|
|
on:error={() => {dispatch("loading", false)}}
|
2021-10-26 22:15:01 +02:00
|
|
|
on:dblclick={() => {zoom = !zoom}}
|
|
|
|
on:doubletap={() => {zoom = !zoom}}
|
|
|
|
on:mousedown={mousedown}
|
|
|
|
class="image" class:zoom
|
|
|
|
src={file.get_href}
|
|
|
|
alt={file.name} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.container {
|
2022-10-25 12:13:50 +02:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
2021-10-26 22:15:01 +02:00
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
.container.zoom {
|
|
|
|
overflow: auto;
|
|
|
|
}
|
|
|
|
.image {
|
|
|
|
position: relative;
|
|
|
|
display: block;
|
|
|
|
margin: auto;
|
|
|
|
max-width: 100%;
|
|
|
|
max-height: 100%;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
.image.zoom {
|
|
|
|
max-width: none;
|
|
|
|
max-height: none;
|
|
|
|
cursor: move;
|
|
|
|
}
|
|
|
|
</style>
|