Files
commander/frontend/app/components/CardHover.vue
2026-10-27 12:42:57 +01:00

78 lines
1.5 KiB
Vue

<script setup lang="ts">
const props = defineProps<{ oracleId: string; name: string }>()
const { public: { apiBase } } = useRuntimeConfig()
const PREVIEW_WIDTH = 244
const PREVIEW_HEIGHT = 340
const visible = ref(false)
const failed = ref(false)
const left = ref(0)
const top = ref(0)
const src = computed(() => `${apiBase}/cards/${encodeURIComponent(props.oracleId)}/image`)
function follow(event: MouseEvent) {
left.value = Math.max(8, Math.min(
event.clientX + 20,
window.innerWidth - PREVIEW_WIDTH - 8,
))
top.value = Math.max(8, Math.min(
event.clientY - PREVIEW_HEIGHT / 2,
window.innerHeight - PREVIEW_HEIGHT - 8,
))
}
function enter(event: MouseEvent) {
failed.value = false
follow(event)
visible.value = true
}
</script>
<template>
<span
class="card-hover"
@mouseenter="enter"
@mousemove="follow"
@mouseleave="visible = false"
@pointerdown="visible = false"
>
<slot />
<Teleport to="body">
<img
v-if="visible && !failed"
class="card-art"
:src="src"
:alt="`${name} card art`"
:style="{ left: `${left}px`, top: `${top}px` }"
@error="failed = true"
>
</Teleport>
</span>
</template>
<style scoped>
.card-hover {
display: block;
}
.card-art {
position: fixed;
z-index: 100;
width: 244px;
height: auto;
border-radius: 12px;
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
pointer-events: none;
animation: card-art-in 140ms ease-out;
}
@keyframes card-art-in {
from {
opacity: 0;
transform: scale(0.96);
}
}
</style>