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 Avatar from '../atoms/Avatar.svelte';
import Icon from '../atoms/Icon.svelte';
import MapChip from '../molecules/MapChip.svelte';
import { chains, widthOf, type Column, type Member, type Tile } from '../model';
import type { StripView } from '../workspace.svelte';
/**
* The strip map, under the tabs: a chip per column, as wide as the
* column's share, in its chain's colour; a box around what the strip
* shows now; a chip clicked goes to its column. + opens a launcher, and
* Share, with the faces of the canvas's members, its share dialog.
*/
let {
columns,
title,
focus,
zoomed,
arrived,
colours,
view,
members,
me,
readonly,
onjump,
onlaunch,
onshare
}: {
columns: Column[];
/** A tile's title, as people read it. */
title: (tile: Tile) => string;
focus: string | null;
zoomed: string | null;
arrived: Set<string>;
colours: Map<string, number>;
view: StripView | null;
members: Member[];
me: string;
/** A viewer adds nothing: no +, but a note that the canvas is theirs to look at. */
readonly: boolean;
onjump: (column: Column) => void;
onlaunch: () => void;
onshare: () => void;
} = $props();
const linked = $derived(chains(columns, colours));
const others = $derived(members.filter((member) => member.did !== me && !member.pending));
let row: HTMLElement | undefined = $state();
/** The box: the strip's view, mapped from its columns onto their chips. */
const box = $derived.by(() => {
if (!row || !view || view.columns.length === 0) return null;
const chips = [...row.querySelectorAll<HTMLElement>('.chip')];
if (chips.length !== view.columns.length) return null;
const xs = [0];
const ms = [chips[0].offsetLeft - 3];
view.columns.forEach((c, i) => {
xs.push(c.left, c.left + c.width);
ms.push(chips[i].offsetLeft, chips[i].offsetLeft + chips[i].offsetWidth);
});
xs.push(view.total);
ms.push(chips.at(-1)!.offsetLeft + chips.at(-1)!.offsetWidth + 3);
const map = (x: number) => {
for (let i = 1; i < xs.length; i++) if (x <= xs[i]) return ms[i - 1] + (ms[i] - ms[i - 1]) * ((x - xs[i - 1]) / (xs[i] - xs[i - 1] || 1));
return ms.at(-1)!;
};
const a = map(view.scroll);
return { left: a, width: map(view.scroll + view.room) - a };
});
// The chips scroll, on a phone, to keep the box in view.
$effect(() => {
if (!row || !box) return;
if (box.left < row.scrollLeft) row.scrollLeft = box.left;
else if (box.left + box.width > row.scrollLeft + row.clientWidth) row.scrollLeft = box.left + box.width - row.clientWidth;
});
</script>
<nav class="map" aria-label="Strip map">
{#if readonly}
<span class="view-only" title="You can look at this canvas; only its owner and editors change it"><Icon name="view" />View only</span>
{:else}
<button type="button" class="icon-button add" title="New tile (T)" aria-label="New tile" onclick={onlaunch}><Icon name="add" /></button>
{/if}
<div class="chips" class:none={columns.length === 0} bind:this={row}>
{#each columns as column (column.key)}
{@const head = column.slots[0]}
<MapChip
share={zoomed === column.key ? 1 : widthOf(column.width).share}
segments={column.slots.map((slot) => (slot.kind === 'tile' ? slot.tile : null))}
chain={head.kind === 'tile' ? linked.colour.get(head.key) : undefined}
focused={column.slots.some((slot) => slot.key === focus)}
arrived={column.slots.some((slot) => arrived.has(slot.key))}
zoomed={zoomed === column.key}
label={column.slots.map((slot) => (slot.kind === 'tile' ? title(slot.tile) : 'Open')).join(' / ')}
onclick={() => onjump(column)}
/>
{/each}
{#if box}<span class="box" style:transform="translateX({box.left}px)" style:width="{box.width}px"></span>{/if}
</div>
<button type="button" class="share" onclick={onshare}>
<Icon name="share" />
<span>Share</span>
{#if others.length > 0}
<span class="faces">
{#each others.slice(0, 3) as member (member.did)}
<Avatar did={member.did} handle={member.handle} size="sm" />
{/each}
</span>
{/if}
</button>
</nav>
<style>
.map {
display: flex;
align-items: center;
gap: var(--space-1);
min-width: 0;
max-width: 100%;
height: calc(var(--map-chip) + 2 * var(--space-1-5));
padding: 0 var(--space-0-5);
border: var(--border);
border-radius: var(--radius-md);
background: var(--bg);
}
.add {
width: var(--avatar);
height: var(--avatar);
}
.view-only {
display: inline-flex;
flex: none;
align-items: center;
gap: var(--space-1);
padding: 0 var(--space-2) 0 var(--space-1-5);
border-right: var(--border);
color: var(--mute);
font-size: var(--text-xs);
white-space: nowrap;
}
.chips {
position: relative;
display: flex;
align-items: center;
gap: var(--space-0-5);
min-width: 0;
padding: var(--space-1);
overflow-x: auto;
scrollbar-width: none;
}
.chips.none {
display: none;
}
.chips::-webkit-scrollbar {
display: none;
}
.box {
position: absolute;
top: var(--space-0-5);
bottom: var(--space-0-5);
left: 0;
border: 1.5px solid var(--faint);
border-radius: var(--radius-md);
pointer-events: none;
}
.share {
display: inline-flex;
flex: none;
align-items: center;
gap: var(--space-1-5);
height: var(--control-sm);
padding: 0 var(--space-2);
border: 0;
border-left: var(--border);
border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
background: none;
color: var(--mute);
font: inherit;
font-size: var(--text-sm);
cursor: pointer;
}
.share:hover {
background: var(--hover);
color: var(--fg);
}
.faces {
display: inline-flex;
gap: var(--space-0-5);
}
</style>