blob: 449321ca28ee1e82ea895ef83e64225f6034bab4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
<script lang="ts">
import type { PageFragment } from '$gql/graphql';
import { getSelectionContext } from '$lib/Selection';
import SelectionOverlay from '$lib/selection/SelectionOverlay.svelte';
import { src } from '$lib/Utils';
import { createEventDispatcher } from 'svelte';
export let page: PageFragment;
export let index: number;
const selection = getSelectionContext<PageFragment>();
let span: 'single' | 'double' | 'triple';
$: page.image.aspectRatio, updateSpan();
function updateSpan() {
const aspectRatio = page.image.aspectRatio;
if (aspectRatio <= 1) {
span = 'single';
} else if (aspectRatio > 1 && aspectRatio <= 2) {
span = 'double';
} else if (aspectRatio > 2) {
span = 'triple';
}
}
const dispatch = createEventDispatcher<{ open: number; cover: number }>();
function press(event: MouseEvent | KeyboardEvent) {
if (event instanceof KeyboardEvent && event.key !== 'Enter') {
return;
}
if ($selection.active) {
if (event.ctrlKey) {
dispatch('open', index);
} else if (selectable) {
$selection = $selection.update(index, event.shiftKey);
}
} else if (event.ctrlKey) {
dispatch('cover', page.id);
} else {
dispatch('open', index);
}
event.preventDefault();
}
$: selectable = $selection.selectable(page);
$: dim = $selection.active && !selectable;
$: selected = $selection.contains(page.id);
</script>
<div
class:dim
role="button"
tabindex="0"
class="{span} relative overflow-hidden rounded"
on:click={press}
on:keydown={press}
>
<SelectionOverlay position="top" {selected} />
<img
class="h-full w-full object-cover object-[center_top] transition-opacity"
loading="lazy"
alt=""
width={page.image.width}
height={page.image.height}
src={src(page.image)}
title={`${page.path} (${page.image.width} x ${page.image.height})`}
/>
</div>
<style>
.dim {
cursor: not-allowed;
}
.dim > img {
opacity: 0.2;
filter: grayscale(1);
}
.double {
grid-column: span 2;
}
.triple {
grid-column: span 3;
}
</style>
|