chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.4.0 Latest 5 packages
0
0
<script lang="ts">
import { Picture } from '@hud/renderer';
import Icon from '../atoms/Icon.svelte';
import { chains, widthOf, type Column, type Tile } from '../model';
import TileMark from '../molecules/TileMark.svelte';
import type { Preview } from '../preview';
import { summary } from '../tiles';
/**
* The overview (O, or a pinch): every column as a card as wide as its
* share, its tiles in it in their mini form (what each is, its title, a
* line of what it shows and a picture from it, where it has one), as
* large as the screen lets them all show. A card clicked goes to its
* tile; Escape, or Back, goes back. On a phone, a column of cards.
*/
let {
name,
columns,
title,
focus,
arrived,
colours,
previews,
onjump
}: {
/** The canvas's name. */
name: string;
columns: Column[];
/** A tile's title, as people read it. */
title: (tile: Tile) => string;
focus: string | null;
arrived: Set<string>;
colours: Map<string, number>;
/** What each tile last drew, in short, by its id. */
previews: Map<string, Preview>;
/** Go to a column's tile, or back to the focused one with null. */
onjump: (key: string | null) => void;
} = $props();
const linked = $derived(chains(columns, colours));
let box: HTMLElement | undefined = $state();
let cards: HTMLElement | undefined = $state();
// The cards' unit (a third-wide column's width), as large as lets every
// card show at once, from --card down to half of it; on a phone, where
// a card is the screen's width, the cards scroll instead.
$effect(() => {
if (!box || !cards) return;
const area = box;
const list = cards;
void columns.length;
const fit = () => {
list.style.removeProperty('--unit');
if (window.matchMedia('(max-width: 640px)').matches) return;
// The most, --card, in px: a length in rem, as tokens are.
const card = getComputedStyle(list).getPropertyValue('--unit').trim();
const most = parseFloat(card) * (card.endsWith('rem') ? parseFloat(getComputedStyle(document.documentElement).fontSize) : 1);
const room = area.clientHeight - list.offsetTop - parseFloat(getComputedStyle(area).paddingBottom);
for (let unit = most; unit >= most / 2; unit -= 8) {
list.style.setProperty('--unit', `${unit}px`);
if (list.offsetHeight <= room) return;
}
};
fit();
const observer = new ResizeObserver(fit);
observer.observe(area);
return () => observer.disconnect();
});
</script>
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_noninteractive_element_interactions (Escape and Enter close it; each card is a button) -->
<div bind:this={box} class="overview" role="region" aria-labelledby="overview-title" onclick={(event) => event.target === event.currentTarget && onjump(null)}>
<header class="head">
<Icon name="overview" />
<h2 id="overview-title">Overview of “{name}”</h2>
<span class="hint">Pick a tile to go to it</span>
<button type="button" class="btn sm" title="Back to the strip (Esc)" onclick={() => onjump(null)}>Back</button>
</header>
<ul bind:this={cards} class="cards">
{#each columns as column (column.key)}
<li class="column" style:--share={widthOf(column.width).share}>
{#each column.slots as slot (slot.key)}
{@const chain = linked.colour.get(slot.key)}
{@const shows = slot.kind === 'tile' ? previews.get(slot.key) : undefined}
<button
type="button"
class="card"
class:focused={slot.key === focus}
class:arrived={arrived.has(slot.key)}
class:chained={chain !== undefined}
style:--chain={chain === undefined ? undefined : `var(--chain-${chain})`}
onclick={() => onjump(slot.key)}
>
{#if slot.kind === 'tile'}
<span class="title">
<TileMark tile={slot.tile} />
<strong>{title(slot.tile)}</strong>
{#if slot.tile.by === 'agent'}<span class="agent"><Icon name="agent" label="Added by an agent" /></span>{/if}
</span>
{#if shows?.text}
<span class="text">{shows.text}</span>
{:else}
<span class="call">{summary(slot.tile.tool, slot.tile.arguments)}</span>
{/if}
{#if shows?.image}<span class="thumb"><Picture src={shows.image} alt="" /></span>{/if}
{:else}
<span class="title"><Icon name="add" /><strong>New tile</strong></span>
<span class="text">A launcher: search, or pick from your atproto</span>
{/if}
</button>
{/each}
</li>
{/each}
</ul>
</div>
<style>
.overview {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
gap: var(--space-5);
padding: var(--space-2) var(--space-6) var(--space-6);
overflow: auto;
}
.head {
display: flex;
flex: none;
align-items: center;
gap: var(--space-2);
width: 100%;
max-width: 60rem;
color: var(--mute);
}
.head h2 {
min-width: 0;
overflow: hidden;
color: var(--fg);
font-size: var(--text-base);
text-overflow: ellipsis;
white-space: nowrap;
}
.hint {
flex: 1;
min-width: 0;
overflow: hidden;
font-size: var(--text-sm);
text-overflow: ellipsis;
white-space: nowrap;
}
.cards {
--unit: var(--card);
display: flex;
flex: none;
flex-wrap: wrap;
justify-content: center;
gap: var(--space-5) var(--space-3);
width: 100%;
margin: 0;
padding: 0;
list-style: none;
}
.column {
display: flex;
flex-direction: column;
gap: var(--space-1-5);
width: calc(var(--share) * 3 * var(--unit));
height: calc(var(--unit) * 1.45);
}
.card {
position: relative;
display: flex;
flex: 1 1 0;
flex-direction: column;
gap: var(--space-1-5);
min-height: 0;
padding: var(--space-2-5);
border: var(--border);
border-radius: var(--radius-md);
background: var(--bg);
color: var(--fg);
font: inherit;
font-size: var(--text-sm);
text-align: left;
overflow: hidden;
cursor: pointer;
}
.card:hover {
border-color: var(--line-strong);
}
.card.chained::before {
content: '';
position: absolute;
inset: 0 0 auto;
height: 3px;
background: var(--chain);
}
.card.focused {
border-color: var(--primary);
box-shadow: 0 0 0 1px var(--primary);
}
.card.arrived {
border-color: var(--agent);
box-shadow: 0 0 0 2px var(--agent);
}
.title {
display: flex;
flex: none;
align-items: center;
gap: var(--space-1-5);
min-width: 0;
}
.title strong {
overflow: hidden;
font-weight: var(--weight-semibold);
text-overflow: ellipsis;
white-space: nowrap;
}
.agent {
display: inline-flex;
flex: none;
color: var(--notice-fg);
}
.text {
display: -webkit-box;
flex: none;
overflow: hidden;
color: var(--mute);
font-size: var(--text-xs);
line-height: var(--leading-tight);
overflow-wrap: anywhere;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
line-clamp: 3;
}
.call {
flex: none;
overflow: hidden;
color: var(--mute);
font: var(--text-xs) var(--font-mono);
text-overflow: ellipsis;
white-space: nowrap;
}
.thumb {
flex: 1 1 0;
min-height: var(--space-8);
border-radius: var(--radius-sm);
overflow: hidden;
}
@media (max-width: 640px) {
.overview {
padding: var(--space-2) var(--space-3) var(--space-6);
}
.hint {
display: none;
}
.cards {
flex-direction: column;
flex-wrap: nowrap;
}
.column {
width: 100%;
height: auto;
}
.card {
flex: none;
height: 11rem;
}
}
</style>