chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
hud.hudkit 0.4.0 Latest 5 packages
0
0
<script lang="ts">
import LinkButton from './LinkButton.svelte';
import Marked from './Marked.svelte';
import type { Opener } from './open';
import type { Run } from './richtext';
import { spacing, translateOf } from './translate';
// Runs of text, inline: links, mentions, tags and plain text, each in
// its formatting when it has any (`marks`). A link opens through the app
// when it says how (the host's openLink), else in a new tab; a mention
// opens the account when the app can (`onopenactor`, what opens it); a
// tag that opens something (a search for it) reads as a link; either is
// a link where the app has an address for what it opens. A page's
// translation keeps off mentions, tags and links that show their
// address, and off the spaces and line breaks beside and between them,
// which it would drop (`spacing`, ./translate.ts).
let {
runs,
onopenlink,
onopenactor
}: { runs: Run[]; onopenlink?: (url: string) => void; onopenactor?: (actor: string) => Opener } = $props();
function openLink(event: MouseEvent, url: string) {
if (!onopenlink) return;
event.preventDefault();
onopenlink(url);
}
</script>
{#snippet words(run: Run)}{#if run.marks}<Marked text={run.text} marks={run.marks} />{:else}{run.text}{/if}{/snippet}
{#snippet spaced(run: Run)}{#if run.marks}<Marked text={run.text} marks={run.marks} />{:else}{#each spacing(run.text) as part, i (i)}{#if part.kept}<span translate="no">{part.text}</span>{:else}{part.text}{/if}{/each}{/if}{/snippet}
{#each runs as run, i (i)}
{#if run.kind === 'link'}
{@const url = run.url}
<a href={url} target="_blank" rel="noopener noreferrer" translate={translateOf(run.text)} onclick={(event) => openLink(event, url)}>{@render words(run)}</a>
{:else if run.kind === 'mention'}
{@const actor = run.actor}
{#if onopenactor}
{@const open = onopenactor(actor)}
<LinkButton onclick={open.run} href={open.href} title={actor} translate="no">{@render words(run)}</LinkButton>
{:else}
<span class="mention" title={actor} translate="no">{@render words(run)}</span>
{/if}
{:else if run.kind === 'tag'}
{#if run.open}
{@const open = run.open}
<LinkButton onclick={open.run} href={open.href} title={open.label} translate="no">{@render words(run)}</LinkButton>
{:else}
<span class="tag" translate="no">{@render words(run)}</span>
{/if}
{:else}
{@render spaced(run)}
{/if}
{/each}
<style>
a {
color: var(--color-text-info);
overflow-wrap: anywhere;
text-decoration: none;
text-underline-offset: 0.15em;
}
a:hover,
a:focus-visible {
text-decoration: underline;
}
.tag,
.mention {
color: var(--color-text-info);
}
</style>