2020-11-11 23:45:52 +01:00
|
|
|
<script>
|
2023-05-17 15:34:56 +02:00
|
|
|
import { fs_file_url } from "../FilesystemUtil.js";
|
2020-11-17 23:39:27 +01:00
|
|
|
|
|
|
|
export let state
|
2020-11-11 23:45:52 +01: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
|
|
|
|
on:dblclick={() => {zoom = !zoom}}
|
|
|
|
on:doubletap={() => {zoom = !zoom}}
|
|
|
|
on:mousedown={mousedown}
|
|
|
|
class="image" class:zoom
|
2023-05-17 15:34:56 +02:00
|
|
|
src={fs_file_url(state.root.id, state.base.path)}
|
2020-11-11 23:45:52 +01:00
|
|
|
alt="no description available" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.container {
|
2023-05-19 17:17:05 +02:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
2020-11-11 23:45:52 +01:00
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
.container.zoom {
|
|
|
|
overflow: auto;
|
2023-05-19 17:17:05 +02:00
|
|
|
justify-content: unset;
|
2020-11-11 23:45:52 +01:00
|
|
|
}
|
|
|
|
.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>
|