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
// The tree's hero (`_meta.ui.hero`): the first picture it draws large,
// which the server names. `Tree` says it to the pictures under it, and the
// one drawing it loads at once and first; the rest load as they near the
// screen, but those first on the screen by their place (`setFirst`): the
// tree's top, and in it the first item of each list and the first picture
// of each gallery, as a feed's first card, its face and first photo. An
// app drawing pages preloads the hero from its head too (`heroPreload`), at
// the `area` it gives `Tree` (./slot.ts), so the browser takes the same size
// of it for both.
import { getContext, setContext } from 'svelte';
import { SCREEN_WIDE } from './slot';
import type { UiTree } from './tree/types';
const HERO = Symbol('hero');
const FIRST = Symbol('first');
type Hero = () => string | undefined;
type First = () => boolean;
/** Says to the pictures under the caller which one is the hero, by its src: a getter, so a tree drawn anew says its own. */
export const setHero = (src: Hero): void => void setContext(HERO, src);
/** The hero of the tree the caller is drawn in, read as it changes; none outside a tree. Called as a component starts. */
export const heroOf = (): Hero => getContext<Hero | undefined>(HERO) ?? (() => undefined);
/** Says to the pictures under the caller whether they are first on the screen by their place, where they load at once: a getter. */
export const setFirst = (first: First): void => void setContext(FIRST, first);
/** Whether what the caller is drawn in is first on the screen by its place; never outside a tree. Called as a component starts. */
export const firstOf = (): First => getContext<First | undefined>(FIRST) ?? (() => false);
/** The attributes of the `<link rel="preload" as="image">` that loads `ui`'s hero first: its src, and where it has sizes, them and the `area` the app gives `Tree` as its sizes; none where it has no hero. */
export function heroPreload(
ui: UiTree,
area: string = SCREEN_WIDE
): { href: string; imagesrcset?: string; imagesizes?: string; fetchpriority: 'high' } | null {
if (ui.hero === undefined) return null;
if (ui.heroSrcset === undefined) return { href: ui.hero, fetchpriority: 'high' };
return { href: ui.hero, imagesrcset: ui.heroSrcset, imagesizes: area, fetchpriority: 'high' };
}