chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.3.0 Latest 5 packages
0
0
Home loads fast: its first photo first, the rest when idle
crates/hud-core/src/ui/mod.rs+16−6
| @@ -205,7 +205,9 @@ pub fn measure<'a>(doc: &'a Value, scope: &Value) -> Option<&'a str> { | ||
/// avatar, an icon, a thumbnail), the first item with a picture of a | ||
/// `Gallery`, `Slides` or `Covers`, or a `Profile`'s banner, else its | ||
/// avatar: its src, and a gallery photo's sizes (`srcset`) where it has | ||
/// them. None where it draws none. | ||
/// them. A `List` scrolled sideways (a `strip` or a `shelf`, a photo app's | ||
/// stories over its feed) draws each item small, so nothing in it is the | ||
/// hero. None where it draws none. | ||
pub fn hero(tree: &Value) -> Option<(&str, Option<&str>)> { | ||
fn src(picture: &Value) -> Option<(&str, Option<&str>)> { | ||
picture["src"].as_str().map(|s| (s, None)) | ||
| @@ -218,6 +220,9 @@ pub fn hero(tree: &Value) -> Option<(&str, Option<&str>)> { | ||
Some("avatar" | "face" | "icon" | "thumb") | ||
); | ||
let own = match o.get("c").and_then(Value::as_str) { | ||
Some("List") if matches!(p["style"].as_str(), Some("strip" | "shelf")) => { | ||
return None; | ||
} | ||
Some("Image") if !small => src(&p["src"]), | ||
Some("Gallery" | "Slides" | "Covers") => { | ||
tree["items"].as_array().and_then(|items| { | ||
| @@ -2590,18 +2595,23 @@ mod tests { | ||
} | ||
| ||
/// The hero: the first picture drawn large, in drawing order, past | ||
/// pictures drawn small, with a gallery photo's sizes; a profile's | ||
/// banner, else its avatar; none where nothing is drawn large. | ||
/// pictures drawn small and lists scrolled sideways (stories over a | ||
/// feed), with a gallery photo's sizes; a profile's banner, else its | ||
/// avatar; none where nothing is drawn large. | ||
#[test] | ||
fn a_tree_names_its_hero() { | ||
let image = |size: Option<&str>, src: &str| json!({ "c": "Image", "p": { "src": { "src": src, "fallback": null }, "size": size } }); | ||
let items = |c: &str| json!({ "c": c, "items": [{ "src": null }, { "src": { "src": "g1" }, "srcset": "g0 1000w, g1 2000w" }, { "src": { "src": "g2" } }] }); | ||
let stack = |k: Value| json!({ "c": "Stack", "k": k }); | ||
let feed = stack( | ||
json!([{ "c": "List", "items": [{ "k": [image(Some("face"), "avatar"), image(None, "photo")] }] }]), | ||
); | ||
let card = json!({ "k": [image(Some("face"), "avatar"), image(None, "photo")] }); | ||
let feed = stack(json!([{ "c": "List", "items": [card] }])); | ||
let alone = |s| Some((s, None)); | ||
assert_eq!(hero(&feed), alone("photo")); | ||
let sideways = |style: &str| json!({ "c": "List", "p": { "style": style }, "items": [{ "k": [image(Some("large"), "story")] }] }); | ||
for style in ["strip", "shelf"] { | ||
assert_eq!(hero(&stack(json!([sideways(style), feed]))), alone("photo")); | ||
assert_eq!(hero(&sideways(style)), None); | ||
} | ||
let sized = Some(("g1", Some("g0 1000w, g1 2000w"))); | ||
assert_eq!( | ||
hero(&stack(json!([image(Some("thumb"), "t"), items("Gallery")]))), | ||
docs/views.md+17−6
| @@ -85,11 +85,18 @@ A page's largest paint is usually its first big picture, so a page should load t | ||
the rest as they near the screen. Every tree a view draws names it as `_meta.ui.hero`, the `src` of the first | ||
picture it draws large, in drawing order. That's an `Image` not drawn small (`avatar`, `face`, | ||
`icon` and `thumb` are small), the first picture of a `Gallery`, `Slides` or `Covers`, or a | ||
`Profile`'s banner, else its avatar. So a Grain feed's hero is its first card's first photo (past | ||
the photographer's face), and a gallery's is its first photo. | ||
| ||
The web renderer draws the hero with `loading="eager"` and `fetchpriority="high"`, and every other | ||
picture lazily. A page drawn on a server should also preload it from its head | ||
`Profile`'s banner, else its avatar. A `List` that scrolls sideways (`strip` or `shelf`) draws | ||
its items small, so nothing in it is the hero. So a Grain feed's hero is its first card's first | ||
photo (past the stories over it and the photographer's face), and a gallery's is its first photo. | ||
| ||
The web renderer draws the hero with `loading="eager"` and `fetchpriority="high"`. The pictures | ||
first on the screen by their place load at once too: an `Image` and a `Gallery`'s first picture, | ||
at the tree's top, in a list's first item, in the pane shown. Beside a hero they load with | ||
`fetchpriority="low"`, so a gallery's author's face doesn't slow its first photo. In a tree with no | ||
hero they have no priority of their own. A feed's first card is drawn so, its face and first | ||
photo, and its carousel's next photo isn't. A `Covers` waits, but for its hero, since one under a | ||
gallery is far down its page. Every other picture loads lazily. A page drawn on a server should | ||
also preload the hero from its head | ||
(`<link rel="preload" as="image" href="…" fetchpriority="high">`), so the browser fetches it before | ||
it reaches the `<img>`. Where the hero is a gallery photo with its sizes, the tree says them too | ||
(`_meta.ui.heroSrcset`). Then the preload gives them as `imagesrcset`, with `imagesizes` the `area` | ||
| @@ -1429,7 +1436,11 @@ of the entry on show, so the browser's back still goes where it went. A step bac | ||
from each entry, so a pager of pages closes to the screen it was opened over even when asked to | ||
close twice at once, such as a story running out as ✕ is tapped. A screen under the one on top, and | ||
a pager's pages beside the one in front, are `inert`: out of reach of the keyboard and of screen | ||
readers. Focus follows the screen on top, as a native stack's does. A screen opened from a link or | ||
readers. A screen under the one on top that has never shown, such as a destination's root under a | ||
page loaded at a screen over it, is drawn only once it shows, so loading the page never draws a | ||
screen nobody sees. On a phone, the links that show a while are read ahead, but only once the page | ||
has loaded and the browser is idle, two calls at a time, and never a link on a screen out of | ||
reach. Focus follows the screen on top, as a native stack's does. A screen opened from a link or | ||
button takes it at its title, and the screen gone back to gets it back where it was left. Signed | ||
out, forms aren't offered: a `Compose` with a count shows as that count. An `Action` that creates | ||
or deletes a record (a ♡, a Follow) goes to sign in when it's pressed, as Grain's web asks, rather | ||
web/renderer/src/tree/compose/text.ts+3−2
| @@ -54,12 +54,13 @@ export function firstLink(text: string): string | null { | ||
return marks(text).find((m) => m.kind === 'link')?.value ?? null; | ||
} | ||
| ||
const graphemes = new Intl.Segmenter(undefined, { granularity: 'grapheme' }); | ||
/** Splits text into graphemes: made as a form first counts, not as the page's code first runs (making one takes a while). */ | ||
let graphemes: Intl.Segmenter | undefined; | ||
| ||
/** How long `text` is as people count it: its graphemes (an emoji, a letter with its accent, one each). */ | ||
export function length(text: string): number { | ||
let n = 0; | ||
for (const _ of graphemes.segment(text)) n++; | ||
for (const _ of (graphemes ??= new Intl.Segmenter(undefined, { granularity: 'grapheme' })).segment(text)) n++; | ||
return n; | ||
} | ||
| ||
web/renderer/src/tree/First.sveltenew+13−0
| @@ -0,0 +1,13 @@ | ||
<script lang="ts"> | ||
import type { Snippet } from 'svelte'; | ||
import { firstOf, setFirst } from '../hero'; | ||
| ||
// What it holds is first on the screen by its place (../hero.ts), its | ||
// pictures loading at once, only where it is first where it is | ||
// (`first`: a list's first item) and what holds it is first too. | ||
let { first, children }: { first: boolean; children: Snippet } = $props(); | ||
const outer = firstOf(); | ||
setFirst(() => first && outer()); | ||
</script> | ||
| ||
{@render children()} | ||
web/renderer/src/tree/Image.svelte+1−1
| @@ -37,7 +37,7 @@ | ||
| ||
{#snippet picture()} | ||
<span class="image" class:avatar class:face class:large class:icon class:thumb class:bleed={p.bleed} class:ring={p.ring} class:plus={p.plus} style:--ratio={p.ratio} | ||
><Picture src={p.src} alt={p.alt} {fit} person={avatar} placeholder={icon ? '·' : thumb ? '' : undefined} />{#if p.showAlt}<AltBadge alt={p.alt} />{/if}{#if p.plus}<span class="add" aria-hidden="true" | ||
><Picture src={p.src} alt={p.alt} {fit} person={avatar} placeholder={icon ? '·' : thumb ? '' : undefined} eager />{#if p.showAlt}<AltBadge alt={p.alt} />{/if}{#if p.plus}<span class="add" aria-hidden="true" | ||
><svg viewBox="0 0 24 24">{#each ICONS.plus as d (d)}<path {d} />{/each}</svg></span | ||
>{/if}</span | ||
> | ||
web/renderer/src/tree/Link.svelte+10−0
| @@ -237,6 +237,16 @@ | ||
color: var(--color-text-info); | ||
} | ||
| ||
/* A name or a muted line that opens is a 24px target at least, however | ||
small its words (a feed card's place under its author's name): where | ||
its line is shorter, padded to that, the padding taken back from its | ||
margins so it lays out and looks as before. */ | ||
.name, | ||
:is(a, button).muted { | ||
padding-block: max(0px, (24px - 1lh) / 2); | ||
margin-block: min(0px, (1lh - 24px) / 2); | ||
} | ||
| ||
span { | ||
overflow-wrap: anywhere; | ||
} | ||
web/renderer/src/tree/List.svelte+6−2
| @@ -6,6 +6,7 @@ | ||
import Glyph from '../Glyph.svelte'; | ||
import { getTreeContext, opener, stamp, unhosted } from './context'; | ||
import DoubleTaps from './DoubleTaps.svelte'; | ||
import First from './First.svelte'; | ||
import Node from './Node.svelte'; | ||
import type { UiListProps, UiNode } from './types'; | ||
| ||
| @@ -29,7 +30,10 @@ | ||
// A grid's tiles are as many across as fit at its `min` (../slot.ts), at | ||
// most `columns`, each sharing the line evenly; the pictures in them are | ||
// told how wide that is at most. Each item hears its own double-tap | ||
// (./DoubleTaps.svelte): a feed card's photo double-tapped, its ♡. Rows | ||
// (./DoubleTaps.svelte): a feed card's photo double-tapped, its ♡. Its | ||
// first item alone is first on the screen by its place (./First.svelte), | ||
// where the list is: its pictures load at once, the rest's as they near | ||
// the screen. Rows | ||
// with `chevrons` end each that opens something with a chevron, as a | ||
// settings page's rows that open pages of their own. Chips are each a | ||
// filled pill, under a small capital title, their `more` (See all) a | ||
| @@ -134,7 +138,7 @@ | ||
<svelte:element this={tagOf(open)} {...opens(open)} class="open" aria-label={open.label}></svelte:element> | ||
{/if} | ||
<div class="content"> | ||
<DoubleTaps>{#each item.k ?? [] as child, j (j)}<Node node={child} />{/each}</DoubleTaps> | ||
<First first={i === 0}><DoubleTaps>{#each item.k ?? [] as child, j (j)}<Node node={child} />{/each}</DoubleTaps></First> | ||
</div> | ||
{#if open && chevrons}<svg class="chevron" viewBox="0 0 24 24" aria-hidden="true"><Glyph name="chevronRight" /></svg>{/if} | ||
{/if} | ||
web/renderer/src/tree/PaneBody.svelte+6−1
| @@ -1,4 +1,5 @@ | ||
<script lang="ts"> | ||
import { firstOf, setFirst } from '../hero'; | ||
import { setPaneEnd, type PaneEndSlot } from './Panes.svelte'; | ||
import Node from './Node.svelte'; | ||
import type { UiNode } from './types'; | ||
| @@ -6,9 +7,13 @@ | ||
// What one `Pane` of a `Panes` holds, drawn as anything else is, with | ||
// the slot its content puts its control in (`getPaneEnd`): each pane | ||
// its own, so a pane drawn beside the shown one puts nothing in the row. | ||
let { pane, slot }: { pane: UiNode; slot: PaneEndSlot } = $props(); | ||
// Only the pane shown (`first`) is first on the screen by its place | ||
// (../hero.ts), its pictures loading at once where the Panes is. | ||
let { pane, slot, first = true }: { pane: UiNode; slot: PaneEndSlot; first?: boolean } = $props(); | ||
| ||
setPaneEnd(() => slot); | ||
const outer = firstOf(); | ||
setFirst(() => first && outer()); | ||
</script> | ||
| ||
{#each pane.k ?? [] as child, i (i)}<Node node={child} />{/each} | ||
web/renderer/src/tree/Panes.svelte+1−1
| @@ -226,7 +226,7 @@ | ||
aria-labelledby="{id}-tab-{i}" | ||
inert={live && i !== at} | ||
> | ||
<PaneBody {pane} slot={slotOf(i)} /> | ||
<PaneBody {pane} slot={slotOf(i)} first={i === at} /> | ||
</div> | ||
{/each} | ||
</div> | ||
web/renderer/src/tree/Tree.svelte+3−1
| @@ -1,7 +1,7 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import type { PlayerHost } from '../player-host.svelte'; | ||
import { setHero } from '../hero'; | ||
import { setFirst, setHero } from '../hero'; | ||
import { SCREEN_WIDE, setSlot } from '../slot'; | ||
import { settle } from '../view/clock.svelte'; | ||
import { seenTracker, type SeenTracker } from '../view/seen'; | ||
| @@ -161,6 +161,8 @@ | ||
}); | ||
| ||
setHero(() => ui.hero); | ||
// Its top is first on the screen: its pictures there load at once (../hero.ts). | ||
setFirst(() => true); | ||
setSlot(() => area); | ||
// The view's own double-tap, outside any list item (a gallery's page, its photos and its ♡). | ||
const tap = $state({ label: '', taps: 0 }); | ||