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" module>
import type { IconName } from './icons';
import type { Opener } from './open';
import type { Source } from './types';
/** A cover card's data: what a click opens (if anything; a link where it
* has an address), its picture and the sizes it comes in (`srcset`),
* words, count, a stat (such as its favorites) with its icon, date, the
* self-labels that hide its picture until shown, and whether it holds
* more than one picture; while covers are picked, whether it is
* (`picked`, null where it cannot be, which `open` then leaves alone,
* absent while none are picked), a click picking it. */
export type Cover = {
open: Opener | null;
src: Source | null;
title: string | null;
count: string | null;
stat: { value: number; icon: IconName | null } | null;
date: string | null;
labels: string[];
many: boolean;
picked?: boolean | null;
srcset?: string;
};
</script>
<script lang="ts">
import CoverCard from './CoverCard.svelte';
import CoverTile from './CoverTile.svelte';
import { slotOf, tileSlot } from './slot';
import { strays } from './view/taps';
// Cover cards in a grid, such as an account's photo galleries or albums:
// two across in a narrow frame, more as it widens. As `tiles`, square
// pictures alone, close together, three across in a narrow frame and
// more as it widens, reaching the edges of what holds them where it says
// how far (`--hud-bleed`), as a list's rows do. With `min`, a CSS
// width, none narrower than it, as many across as fit; with `columns`,
// at most that many across, sharing the line however wide it is. A
// cover with its sizes (`srcset`) loads the smallest that fills its
// cell: its sizes the slot it is drawn in shared among the cells, as a
// List grid's (./slot.ts). A touch that moved, or stopped the page
// scrolling, opens nothing (./view/taps.ts).
let { covers, tiles = false, min, columns }: { covers: Cover[]; tiles?: boolean; min?: string; columns?: number } = $props();
const slot = slotOf();
/** How wide a cell is at most: its CSS's narrowest (a card's in a wide frame) and gap, below. */
const sizes = $derived(tiles ? tileSlot(slot(), min ?? '7.5rem', '0.125rem', columns) : tileSlot(slot(), min ?? '13rem', '0.75rem', columns));
</script>
{#if covers.length === 0}
<p class="empty">Nothing here yet.</p>
{:else if tiles}
<ul class="tiles" class:sized={min !== undefined} class:capped={columns !== undefined} style:--min={min} style:--columns={columns} {@attach strays}>
{#each covers as cover, i (i)}
<li><CoverTile {cover} {sizes} name={cover.title || `Gallery ${i + 1} of ${covers.length}`} /></li>
{/each}
</ul>
{:else}
<div class="frame">
<ul class="grid" class:capped={columns !== undefined} style:--card={min} style:--columns={columns} {@attach strays}>
{#each covers as cover, i (i)}
<li><CoverCard {cover} {sizes} /></li>
{/each}
</ul>
</div>
{/if}
<style>
p {
margin: 0;
}
.frame {
container-type: inline-size;
}
.grid {
--card: 9.5rem;
--gap: var(--hud-space-3);
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--card)), 1fr));
gap: var(--gap);
margin: 0;
padding: 0;
list-style: none;
}
@container (min-width: 40rem) {
.grid {
--card: 13rem;
}
}
.grid > li {
display: flex;
min-width: 0;
}
/* A cell is 7.5rem at least, but never less than three a line: under
three of those, a little under a third of the line (a gap under, so
rounding never leaves two). First on its screen (`--hud-lead`, the
padding over it), it meets the bar above, as it meets the sides. */
.tiles {
--gap: 0.125rem;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(7.5rem, (100% - 3 * var(--gap)) / 3), 1fr));
gap: var(--gap);
margin: calc(-1 * var(--hud-lead, 0px)) calc(-1 * var(--hud-bleed, 0px)) 0;
padding: 0;
list-style: none;
}
/* Of a given narrowest, as many across as fit. */
.tiles.sized {
grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--min)), 1fr));
}
/* At most `columns` across: no track narrower than the line shared among
that many (a hair less, so that many fit as it rounds); with no `min`,
the tiles' own, three a line at the least. */
.tiles.capped {
grid-template-columns: repeat(auto-fill, minmax(min(100%, max(var(--min, min(7.5rem, (100% - 3 * var(--gap)) / 3)), (100% - (var(--columns) - 1) * var(--gap)) / var(--columns) - 0.5px)), 1fr));
}
.grid.capped {
grid-template-columns: repeat(auto-fill, minmax(min(100%, max(var(--card), (100% - (var(--columns) - 1) * var(--gap)) / var(--columns) - 0.5px)), 1fr));
}
.tiles > li {
min-width: 0;
}
.empty {
padding: var(--hud-space-5) 0;
color: var(--color-text-secondary);
font-size: var(--font-text-sm-size);
text-align: center;
}
</style>