blob: 68cb15047a02b645facb90f545b75121f6bd7e39 (
plain)
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
|
<!--
The modifier-card zoom (the reference `ModifierCardZoom`): the top card
at ~3x scale (shrunk to fit the screen width), tap (or Escape) to close.
-->
<script lang="ts">
import type { ModifierCard as Card } from '$lib/protocol/types';
import ModifierCard from '../cards/ModifierCard.svelte';
const DEFAULT_ZOOM = 3.0;
const CARD_WIDTH = 58.6666;
let {
card,
name,
perks = null,
open = $bindable(true)
}: {
card: Card;
/** The deck name ("" party, "allies", or a character id). */
name: string;
perks?: string[][] | null;
open?: boolean;
} = $props();
// Fit the card into the viewport (the reference shrinks the zoom to fit).
function scaleFor(): number {
if (typeof window === 'undefined') return DEFAULT_ZOOM;
return Math.min(DEFAULT_ZOOM, window.innerWidth / (CARD_WIDTH + 80));
}
const scale = $state(scaleFor());
</script>
{#if open}
<div
class="zoom"
role="dialog"
aria-modal="true"
onclick={() => (open = false)}
onkeydown={(e) => e.key === 'Escape' && (open = false)}
>
<ModifierCard {card} {name} revealed {perks} {scale} />
</div>
{/if}
<style>
.zoom {
position: fixed;
inset: 0;
z-index: 40;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0, 0, 0, 0.75);
cursor: pointer;
}
</style>
|