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

grain.social/grain

photography-focused photo sharing platform

grain.social
1 collaborator
0
2

next: Home's first card loads at once, the page's work after load

Merged chadtmiller.com asked to merge into feature/hud from grain.social/grain:next/perf

Only what this pull adds. It is built on The next grain.social and grain-ios, drawn by HUD.

vendor/hud/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;
}
vendor/hud/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()}
vendor/hud/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
>
vendor/hud/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;
}
vendor/hud/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}
vendor/hud/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}
vendor/hud/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>
vendor/hud/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 });
vendor/hud/web/renderer/src/AltBadge.svelte+21−9
@@ -3,32 +3,44 @@
// bottom-right corner, which shows the text over the picture, and hides
// it again. Its parent is the picture's box, positioned. `shown` bound,
// its owner keeps one of a picture's overlays open at a time (a
// gallery's, with its ⓘ).
// gallery's, with its ⓘ). Each button's name holds the words it shows
// (a voice saying "ALT" finds it), and the badge is a 24px target at
// least, the pill drawn in it as small as its word.
let { alt, shown = $bindable(false) }: { alt: string; shown?: boolean } = $props();
</script>
{#if shown}
<button type="button" class="text" onclick={() => (shown = false)} aria-label="Hide description"><span>{alt}</span></button>
<button type="button" class="text" onclick={() => (shown = false)} title="Hide ALT text"><span>{alt}</span></button>
{/if}
<button type="button" class="badge" aria-label={shown ? 'Hide description' : 'Show description'} aria-expanded={shown} onclick={() => (shown = !shown)}>ALT</button>
<button type="button" class="badge" aria-label={shown ? 'Hide ALT text' : 'Show ALT text'} aria-expanded={shown} onclick={() => (shown = !shown)}><span>ALT</span></button>
<style>
/* Over an ⓘ's text too (InfoBadge), so both stay at hand. */
/* Over an ⓘ's text too (InfoBadge), so both stay at hand: a bare box
24px square at least, reaching a little past the pill it draws. */
.badge {
position: absolute;
z-index: 1;
right: var(--hud-space-2);
bottom: var(--hud-space-2);
padding: 1px var(--hud-space-1);
right: calc(var(--hud-space-2) - 2px);
bottom: calc(var(--hud-space-2) - 2px);
display: grid;
place-items: center;
min-width: 24px;
min-height: 24px;
padding: 2px;
border: 0;
background: none;
font: inherit;
cursor: pointer;
}
.badge > span {
padding: 1px var(--hud-space-1);
border-radius: var(--border-radius-xs);
background: rgb(0 0 0 / 0.7);
color: #fff;
font: inherit;
font-size: var(--font-text-xs-size);
font-weight: var(--font-weight-bold);
letter-spacing: 0.04em;
cursor: pointer;
}
/* The text over the whole picture, centered both ways, scrolling when
vendor/hud/web/renderer/src/format.ts+16−10
@@ -4,14 +4,20 @@
// (`en-US`, in UTC): a page drawn on a server, as the browser writes it
// until it has hydrated the page, so the two agree.
/** The formats dates and counts are written in, in `locale` and `timeZone` (the machine's where not given). */
/** A thing made as it is first asked for, then kept. */
function once<T>(make: () => T): () => T {
let made: T | undefined;
return () => (made ??= make());
}
/** The formats dates and counts are written in, in `locale` and `timeZone` (the machine's where not given): each made as it is first asked for, since making one takes a while (a phone's few milliseconds, as the page's code first runs) and a page uses few. */
function formats(locale?: string, timeZone?: string) {
return {
dateTime: new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short', timeZone }),
date: new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeZone }),
day: new Intl.DateTimeFormat(locale, { month: 'short', day: 'numeric', timeZone }),
dayOfYear: new Intl.DateTimeFormat(locale, { month: 'short', day: 'numeric', year: 'numeric', timeZone }),
compact: new Intl.NumberFormat(locale, { notation: 'compact', maximumFractionDigits: 1 })
dateTime: once(() => new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short', timeZone })),
date: once(() => new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeZone })),
day: once(() => new Intl.DateTimeFormat(locale, { month: 'short', day: 'numeric', timeZone })),
dayOfYear: once(() => new Intl.DateTimeFormat(locale, { month: 'short', day: 'numeric', year: 'numeric', timeZone })),
compact: once(() => new Intl.NumberFormat(locale, { notation: 'compact', maximumFractionDigits: 1 }))
};
}
@@ -21,14 +27,14 @@ const anywhere = formats('en-US', 'UTC');
/** A timestamp as a local date and time, or null when it is no date. */
export function formatDateTime(iso: string, fixed = false): string | null {
const ms = Date.parse(iso);
return Number.isNaN(ms) ? null : (fixed ? anywhere : reader).dateTime.format(ms);
return Number.isNaN(ms) ? null : (fixed ? anywhere : reader).dateTime().format(ms);
}
/** A timestamp as a local date, or null when it is no date. */
export function formatDate(iso: string | null, fixed = false): string | null {
if (iso === null) return null;
const ms = Date.parse(iso);
return Number.isNaN(ms) ? null : (fixed ? anywhere : reader).date.format(ms);
return Number.isNaN(ms) ? null : (fixed ? anywhere : reader).date().format(ms);
}
const DAY = 86_400;
@@ -50,7 +56,7 @@ export function formatShortTime(iso: string, now: number = Date.now(), fixed = f
}
const year = (at: number) => (fixed ? new Date(at).getUTCFullYear() : new Date(at).getFullYear());
const { day, dayOfYear } = fixed ? anywhere : reader;
return (year(ms) === year(now) ? day : dayOfYear).format(ms);
return (year(ms) === year(now) ? day : dayOfYear)().format(ms);
}
/** A size in bytes, in the unit that reads best. */
@@ -68,7 +74,7 @@ export function formatBytes(size: number): string {
/** A count in a few characters: `17`, `1.2K`. */
export function formatCompact(count: number, fixed = false): string {
return (fixed ? anywhere : reader).compact.format(count);
return (fixed ? anywhere : reader).compact().format(count);
}
/** A length in seconds as a clock reads it: `3:07`, or `1:02:45`. */
vendor/hud/web/renderer/src/Gallery.svelte+6−4
vendor/hud/web/renderer/src/hero.ts+14−3
vendor/hud/web/renderer/src/InfoBadge.svelte+20−11
vendor/hud/web/renderer/src/Picture.svelte+17−7
vendor/hud/web/shell/src/prefetch.ts+77−11
vendor/hud/web/shell/src/Stack.svelte+13−3
vendor/hud/COMMIT+1−1