~ 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
206 lines · 4.5 KB Raw History
<script lang="ts">
	import { Picture, type Source } from '@hud/renderer';
	import Icon from '../atoms/Icon.svelte';

	/**
	 * What plays, wherever one is in the workspace: its art, its title and
	 * artist (or why it could not play), play and pause, the next track, a
	 * thin line of how far it is, and stop, which forgets it. The title goes
	 * to the tile it came from (`ongoto`), while that tile is open. In the
	 * tab bar on a desktop; a slim bar across the foot of the screen on a
	 * phone (`bar`).
	 */
	let {
		title,
		artist,
		art,
		paused,
		time,
		duration,
		error,
		bar = false,
		ontoggle,
		onnext,
		ongoto,
		onstop
	}: {
		title: string;
		artist: string | null;
		art: Source | null;
		paused: boolean;
		time: number;
		duration: number;
		/** Why the track could not play, if it could not. */
		error: string | null;
		bar?: boolean;
		ontoggle: () => void;
		onnext: () => void;
		/** Show the tile it came from; null when that tile is gone. */
		ongoto: (() => void) | null;
		onstop: () => void;
	} = $props();

	const progress = $derived(duration > 0 ? Math.min(time / duration, 1) : 0);
	const full = $derived(artist ? `${title}, ${artist}` : title);
</script>

{#snippet words()}
	<span class="art">
		{#if art}<Picture src={art} alt="" placeholder="♪" />{:else}<Icon name="music" />{/if}
	</span>
	<span class="words">
		<span class="title">{title}</span>
		{#if error}
			<span class="error" role="alert">{error}</span>
		{:else if artist}
			<span class="artist">{artist}</span>
		{/if}
	</span>
{/snippet}

<div class="mini" class:bar role="region" aria-label="Now playing">
	{#if ongoto}
		<button type="button" class="goto" title="Go to its tile: {full}" aria-label="Go to {full}" onclick={ongoto}>{@render words()}</button>
	{:else}
		<span class="goto" title={full}>{@render words()}</span>
	{/if}
	<button type="button" class="icon-button" aria-label={paused ? 'Play' : 'Pause'} title={paused ? 'Play' : 'Pause'} onclick={ontoggle}>
		<Icon name={paused ? 'play' : 'pause'} />
	</button>
	<button type="button" class="icon-button" aria-label="Next" title="Next" onclick={onnext}><Icon name="next" /></button>
	<button type="button" class="icon-button" aria-label="Stop" title="Stop" onclick={onstop}><Icon name="stop" /></button>
	<span class="line" aria-hidden="true"><span class="progress" style:--played={progress}></span></span>
</div>

<style>
	.mini {
		position: relative;
		display: flex;
		flex: none;
		align-items: center;
		gap: var(--space-0-5);
		height: var(--control);
		padding-right: var(--space-0-5);
		border-radius: var(--radius-md);
		background: var(--panel);
	}

	.goto {
		display: flex;
		align-items: center;
		gap: var(--space-2);
		min-width: 0;
		max-width: var(--now-playing);
		height: 100%;
		padding: 0 var(--space-2) 0 var(--space-1);
		border: 0;
		border-radius: var(--radius-md);
		background: none;
		color: var(--fg);
		font: inherit;
		text-align: start;
	}

	button.goto {
		cursor: pointer;
	}

	button.goto:hover {
		background: var(--hover);
	}

	.art {
		display: grid;
		flex: none;
		place-items: center;
		width: var(--avatar);
		height: var(--avatar);
		border-radius: var(--radius-xs);
		background: var(--soft);
		color: var(--mute);
		overflow: hidden;
	}

	.words {
		display: flex;
		flex-direction: column;
		min-width: 0;
		line-height: var(--leading-tight);
	}

	.title,
	.artist,
	.error {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.title {
		font-size: var(--text-sm);
		font-weight: var(--weight-medium);
	}

	.artist,
	.error {
		font-size: var(--text-xs);
	}

	.artist {
		color: var(--mute);
	}

	.error {
		color: var(--danger);
	}

	/* How far it is: a line along the foot, clipped to the player's corners
	   apart from its buttons, whose focus rings show whole. */
	.line {
		position: absolute;
		inset: 0;
		border-radius: var(--radius-md);
		overflow: hidden;
		pointer-events: none;
	}

	.progress {
		position: absolute;
		right: 0;
		bottom: 0;
		left: 0;
		height: var(--progress);
		background: var(--accent);
		transform: scaleX(var(--played));
		transform-origin: left;
	}

	/* A phone's: across the foot of the screen, the words taking the room,
	   the line along its top edge. */
	.bar {
		gap: var(--space-2);
		height: auto;
		padding: var(--space-1-5) var(--space-2);
		border-top: var(--border);
		background: var(--panel);
	}

	.bar .goto {
		flex: 1;
		max-width: none;
	}

	.bar .art {
		width: var(--avatar-md);
		height: var(--avatar-md);
	}

	.bar .line {
		border-radius: 0;
	}

	.bar .progress {
		top: 0;
		bottom: auto;
	}
</style>