~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
112 lines · 2.6 KB Raw History
<script lang="ts" module>
	import type { Source } from '../types';

	/** One picture of a post, read: drawn small, opened full size, its alt text and shape. */
	export type ShownImage = { src: Source | null; full: string | null; alt: string; ratio: number };
</script>

<script lang="ts">
	import Lightbox from '../Lightbox.svelte';
	import Picture from '../Picture.svelte';

	// A post's pictures, read by the
	// server, in justified rows as the
	// Gallery draws them, each holding its shape before it loads and
	// carrying its alt text. A click opens them in a lightbox at that one.
	let { items }: { items: readonly ShownImage[] } = $props();
	/** The picture the lightbox is open at, while it is. */
	let open: number | null = $state(null);
</script>

{#if items.length > 0}
	<div class="images">
		<ul class="rows" class:single={items.length === 1}>
			{#each items as item, i (i)}
				{@const label = item.alt || `Picture ${i + 1} of ${items.length}`}
				<li style:--ratio={item.ratio} title={item.alt || undefined}>
					{#if item.full}
						<button type="button" class="open" aria-label="Open {label}" onclick={() => (open = i)}>
							<Picture src={item.src} alt={label} />
						</button>
					{:else}
						<Picture src={item.src} alt={label} />
					{/if}
				</li>
			{/each}
		</ul>
	</div>
	{#if open !== null}
		<Lightbox {items} at={open} onclose={() => (open = null)} />
	{/if}
{/if}

<style>
	.images {
		container-type: inline-size;
	}

	/* Justified rows, as the Gallery's: each picture starts at the row
	   height times its ratio and grows in proportion, so a row's pictures
	   share one height. */
	.rows {
		--row: 7.5rem;
		display: flex;
		flex-wrap: wrap;
		gap: 3px;
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.rows::after {
		content: '';
		flex: 1000 1 0;
	}

	.rows > li {
		flex: var(--ratio) 1 calc(var(--row) * var(--ratio));
		min-width: 0;
		max-width: calc(var(--row) * var(--ratio) * 2);
		aspect-ratio: var(--ratio);
		overflow: hidden;
		border-radius: var(--border-radius-xs);
	}

	/* One picture shows whole, as large as its shape allows, no taller than
	   a screenful, centred where its column is wider. */
	.single {
		justify-content: center;
	}

	.single::after {
		display: none;
	}

	.single > li {
		flex: none;
		width: min(100%, calc(min(28rem, 70vh) * var(--ratio)));
		max-width: none;
		border-radius: var(--border-radius-md);
	}

	.open {
		display: block;
		width: 100%;
		height: 100%;
		padding: 0;
		border: 0;
		background: none;
		cursor: zoom-in;
	}

	.open:focus-visible {
		outline: 2px solid var(--color-ring-primary);
		outline-offset: 2px;
	}

	@container (min-width: 36rem) {
		.rows {
			--row: 11rem;
		}
	}
</style>