chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.3.1 Latest 5 packages
0
0
<script lang="ts">
import Picture from './Picture.svelte';
import PickMark from './PickMark.svelte';
import Stat from './Stat.svelte';
import { formatDate } from './format';
import { opens } from './open';
import { clock } from './view/clock.svelte';
import type { Cover } from './Covers.svelte';
// One cover card: a picture over a title, then a count, a stat (such as
// its favorites) and a date. A click opens what it opens (a link, where
// it has an address). One its author labelled shows a content warning
// instead of its picture, and loads none of it: the first click shows
// it, the next opens it. While covers are picked (`picked` there), a
// click picks it or lets it go, its mark over its picture; one that
// can't be picked is dimmed.
let { cover, sizes }: { cover: Cover; sizes?: string } = $props();
let revealed = $state(false);
const picking = $derived(cover.picked !== undefined);
const hidden = $derived(cover.labels.length > 0 && !revealed);
const date = $derived(formatDate(cover.date, clock.fixed));
const clickable = $derived(picking ? cover.picked !== null : hidden || cover.open !== null);
/** What a click opens as a link: its open, where it has an address, and a click opens it (none picked, nothing hidden). */
const link = $derived(!picking && !hidden && cover.open?.href !== undefined ? cover.open : null);
function click() {
if (!picking && hidden) revealed = true;
else cover.open?.run();
}
</script>
{#snippet body()}
{#if hidden}
<span class="cover warning">
<span class="warning-title">Content warning</span>
<span class="labels">{cover.labels.join(', ')}</span>
<span class="hint">Click to show</span>
</span>
{:else}
<span class="cover"><Picture src={cover.src} alt="" placeholder={cover.src === null ? 'No picture' : undefined} srcset={cover.srcset} {sizes} /></span>
{/if}
<span class="text">
<span class="title" class:untitled={!cover.title}>{cover.title || 'Untitled'}</span>
{#if cover.count || cover.stat || date}
<span class="meta">
{#if cover.count}<span>{cover.count}</span>{/if}
{#if cover.stat}<Stat value={cover.stat.value} icon={cover.stat.icon} />{/if}
{#if date}<span>{date}</span>{/if}
</span>
{/if}
</span>
{#if picking && cover.picked !== null}<PickMark picked={cover.picked === true} />{/if}
{/snippet}
{#if clickable}
<svelte:element
this={link ? 'a' : 'button'}
{...link ? opens(link) : { type: 'button', onclick: click }}
class="card"
class:picked={cover.picked === true}
aria-pressed={picking ? cover.picked === true : undefined}
aria-label={!picking && hidden ? `Show ${cover.title || 'Untitled'}: content warning, ${cover.labels.join(', ')}` : undefined}
>
{@render body()}
</svelte:element>
{:else}
<div class="card" class:dimmed={picking}>{@render body()}</div>
{/if}
<style>
.card {
position: relative;
display: flex;
flex-direction: column;
width: 100%;
padding: 0;
border: var(--border-width-regular) solid var(--color-border-secondary);
border-radius: var(--border-radius-lg);
background: var(--color-background-primary);
color: var(--color-text-primary);
font: inherit;
text-align: start;
overflow: hidden;
}
:is(a, button).card {
cursor: pointer;
}
/* A link: sized as the button is, its words in the card's colour, no line under them. */
a.card {
box-sizing: border-box;
text-decoration: none;
}
:is(a, button).card:hover {
border-color: var(--color-border-primary);
box-shadow: var(--shadow-sm);
}
/* Picked: framed in the accent; one that can't be picked, faded. */
.card.picked,
button.card.picked:hover {
border-color: var(--color-text-info);
box-shadow: 0 0 0 1px var(--color-text-info);
}
.card.dimmed {
opacity: 0.4;
}
.cover {
display: grid;
/* overflow other than visible drops the content-based minimum height an
aspect-ratio box would have, so large images cannot stretch it. */
aspect-ratio: 4 / 3;
overflow: hidden;
background: var(--color-background-tertiary);
}
.warning {
align-content: center;
justify-items: center;
gap: var(--hud-space-1);
padding: var(--hud-space-3);
background: var(--color-background-warning);
text-align: center;
}
.warning-title {
color: var(--color-text-warning);
font-size: var(--font-text-sm-size);
font-weight: var(--font-weight-semibold);
}
.labels {
color: var(--color-text-primary);
font-size: var(--font-text-xs-size);
overflow-wrap: anywhere;
}
.hint {
color: var(--color-text-secondary);
font-size: var(--font-text-xs-size);
}
.text {
display: flex;
flex-direction: column;
gap: 0.125rem;
padding: var(--hud-space-2) var(--hud-space-3) var(--hud-space-3);
}
.title {
font-size: var(--font-text-sm-size);
font-weight: var(--font-weight-semibold);
line-height: var(--font-text-sm-line-height);
overflow-wrap: anywhere;
}
.untitled {
color: var(--color-text-secondary);
font-style: italic;
}
/* The count, stat and date in a line, spaced apart, wrapping as needed
(no separators, which would start a wrapped line). */
.meta {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.125rem 0.75em;
color: var(--color-text-secondary);
font-size: var(--font-text-xs-size);
}
.meta :global(.stat) {
font-size: inherit;
}
</style>