Route shell and system icons through registry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWYNS1qAMRdgAtbr5Rq
This commit is contained in:
Krzysztof Rudnicki 2026-11-16 10:51:22 +01:00
parent 6aa40636e7
commit 173d296517
15 changed files with 348 additions and 62 deletions

View File

@ -1,10 +1,14 @@
---
// Any address with no page (the server serves this with a real 404).
import PageHead from '../components/PageHead.astro'
import { iconEntry } from '../icons/registry'
import Shell from '../layouts/Shell.astro'
---
<Shell title="Not found">
<PageHead title="Not found" sub="There is no screen at this address." />
<div class="actions"><a href="/" class="btn btn-primary" aria-label="Back to the dashboard"><span aria-hidden="true">🏠</span></a></div>
{/* data-static-icons: boot decorates the icon with the user's word and glyph (icons/render.ts). */}
<div class="actions" data-static-icons>
<a href="/" class="btn btn-primary" aria-label="Back to the dashboard"><span aria-hidden="true" data-icon="nav.dashboard">{iconEntry('nav.dashboard').glyph}</span></a>
</div>
</Shell>

View File

@ -19,8 +19,8 @@ export class BacklogOverviewElement extends LiveElement {
protected update(): void {
const { data, error } = q.dataset.state
const aside = link('/backlog/', glyph('➡️', 'Open the planner'))
const icon = '📚'
const aside = link('/backlog/', glyph('action.open', 'Open the planner'))
const icon = 'dash.outlook'
if (!data) {
this.replaceChildren(card('Backlog outlook', error ? errorNotice(error) : loading('backlog'), { aside, icon }))
return

View File

@ -0,0 +1,104 @@
// Pass 2 wiring for the dashboard, picks, store, setup and library pages:
// a ledger word shows right of its icon, a chosen alternative glyph replaces
// the default, and the spoken text is unchanged.
import { screen, waitFor } from '@testing-library/dom'
import { describe, expect, it } from 'vitest'
import { makeInstalled, makeLibGame, makeStatus } from '../test/fixtures'
import { mount, stubApi } from '../test/harness'
import { useIcons } from '../test/iconLedger'
import './dashboard'
import './library'
import './picks'
import './setup'
import './store'
const word = (el: Element | null | undefined) => el?.nextElementSibling?.textContent
const markOf = (root: ParentNode, id: string) => root.querySelector(`[data-icon="${id}"], [data-icon-word="${id}"]`)
describe('dashboard icons', () => {
it('a fact row paints its icon word and chosen glyph, the label stays spoken', async () => {
useIcons({ 'dash.finished': { word: 'trophies', glyph: '🥇' }, 'state.yes': { word: 'yes' } })
stubApi({ 'GET /api/status': makeStatus(), 'GET /api/commands': [] })
mount('<dashboard-status></dashboard-status>')
const label = await screen.findByText('Games finished', { selector: 'dt .sr-only' })
const icon = label.closest('dt')?.querySelector('[data-icon="dash.finished"]')
expect(icon?.textContent).toBe('🥇')
expect(word(icon)).toBe('Trophies')
expect(label).toHaveClass('sr-only')
const installed = screen.getByText('Installed', { selector: 'dt .sr-only' }).closest('dt')?.nextElementSibling
expect(word(installed?.querySelector('[data-icon="state.yes"]'))).toBe('Yes')
})
it('the store row and the block countdown use their own icons', async () => {
useIcons({ 'dash.store-blocked': { word: 'shut' }, 'dash.block-left': { word: 'left' } })
stubApi({
'GET /api/status': makeStatus({ total_block: { active: true, days_remaining: 2, until: null } }),
'GET /api/commands': [],
})
const el = mount('<dashboard-status></dashboard-status>')
await screen.findAllByText('Store', { selector: 'dt .sr-only' })
expect(word(markOf(el, 'dash.store-blocked'))).toBe('Shut')
expect(word(markOf(el, 'dash.block-left'))).toBe('Left')
})
})
describe('store notice icon', () => {
it('paints the store-lock icon, its word and glyph, the sentence stays spoken', async () => {
useIcons({ 'store.blocked': { word: 'sealed', glyph: '🛑' } })
stubApi({ 'GET /api/status': makeStatus({ store_blocked: true }) })
mount('<store-notice></store-notice>')
const notice = await screen.findByRole('status')
const icon = markOf(notice, 'store.blocked')
expect(icon?.textContent).toBe('🛑')
expect(word(icon)).toBe('Sealed')
expect(screen.getByText(/Store blocked\./)).toHaveClass('sr-only')
})
})
describe('picks icons', () => {
it('a pick row paints the age icon and the kept pin with their words', async () => {
const pick = (app_id: number, name: string) => ({ app_id, name, age_days: 3 })
useIcons({ 'picks.age': { word: 'picked' }, 'picks.kept': { word: 'kept', glyph: '💚' } })
stubApi({
'GET /api/status': makeStatus({ manual_picks: [pick(1, 'Celeste')], kept_picks: [pick(2, 'Hades')] }),
'GET /api/commands': [],
})
const el = mount('<manual-picks></manual-picks>')
await screen.findByText('Celeste')
expect(word(markOf(el, 'picks.age'))).toBe('Picked')
const kept = markOf(el, 'picks.kept')
expect(kept?.textContent).toBe('💚')
expect(word(kept)).toBe('Kept')
expect(screen.getByText('· picked 3 d ago · 1')).toHaveClass('sr-only')
})
})
describe('setup icons', () => {
it('the field icons and the stored-key placeholder follow the ledger', async () => {
useIcons({ 'setup.api-key': { word: 'key' }, 'setup.key-stored': { word: 'stored', glyph: '🔐' } })
stubApi({ 'GET /api/setup': { configured: true, has_api_key: true, steam_id: '76561198000000000' } })
const el = mount('<setup-form></setup-form>')
expect(word(markOf(el, 'setup.api-key'))).toBe('Key')
expect(screen.getByLabelText<HTMLInputElement>('Steam Web API key')).toBeInTheDocument()
await waitFor(() => {
expect(screen.getByLabelText<HTMLInputElement>('Steam Web API key').placeholder).toBe(`🔐 Stored ${'•'.repeat(32)}`)
})
})
})
describe('library page icons', () => {
it('the installed table headers and the view switch paint their words', async () => {
useIcons({ 'libpage.size': { word: 'space', glyph: '📏' }, 'libpage.all': { word: 'covers' } })
stubApi({
'GET /api/library': { games: [makeLibGame({ app_id: 1, name: 'Hollow Knight' })] },
'GET /api/installed': { games: [makeInstalled({ app_id: 5, name: 'Portal' })] },
'GET /api/commands': [],
})
mount('<library-view></library-view>')
const th = (await screen.findByText('Size', { selector: 'th .sr-only' })).closest('th')
expect(th?.querySelector('[data-icon="libpage.size"]')?.textContent).toBe('📏')
expect(word(th?.querySelector('[data-icon="libpage.size"]'))).toBe('Space')
expect(screen.getByRole('button', { name: 'All games' })).toHaveTextContent('Covers')
})
})

View File

@ -7,6 +7,8 @@
import { api } from '../api/client'
import { q } from '../api/queries'
import { Action } from '../lib/action'
import type { IconId } from '../icons/registry'
import { iconFor, iconInline } from '../icons/render'
import { append, define, h, type Child } from '../lib/dom'
import { LiveElement } from '../lib/element'
import { invalidateAll } from '../lib/query'
@ -27,9 +29,9 @@ export function idError(id: string): string | null {
return ID_RE.test(id.trim()) ? null : 'A SteamID64 is 17 digits and starts with 7656.'
}
// Textgate: help is a 🔗 to where the value comes from; its sentence is spoken only.
// Textgate: help is a link icon to where the value comes from; its sentence is spoken only.
const helpLink = (href: string, spoken: string, sentence: string): Child[] => [
h('a', { href, target: '_blank', rel: 'noreferrer', class: 'setup-link', 'aria-label': spoken }, '🔗'),
h('a', { href, target: '_blank', rel: 'noreferrer', class: 'setup-link', 'aria-label': spoken }, iconInline('setup.help')),
h('span', { class: 'sr-only' }, sentence),
]
const KEY_HELP = (): Child[] =>
@ -38,19 +40,24 @@ const ID_HELP = (): Child[] => helpLink('https://steamid.io', 'steamid.io', 'You
/** Placeholders paint the expected shape: one dot per character, the fixed 7656 prefix. */
const KEY_SHAPE = '·'.repeat(32)
const KEY_STORED = `🔒 ${'•'.repeat(32)}`
const ID_SHAPE = `7656${'·'.repeat(13)}`
/** A placeholder is plain text: the stored-key icon (and its word, if any) then filled dots. */
function keyStored(): string {
const { glyph: mark, word } = iconFor('setup.key-stored')
return `${mark}${word ? ` ${word}` : ''} ${'•'.repeat(32)}`
}
interface Field {
input: HTMLInputElement
help: HTMLParagraphElement
hint: () => Child[]
baseClass: string
/** Characters a valid value has; a bad value paints `⚠️ typed/want`. */
/** Characters a valid value has; a bad value paints the warning icon and `typed/want`. */
want: number
}
function field(id: string, label: string, icon: string, input: HTMLInputElement, hint: () => Child[], want: number): { el: HTMLDivElement; f: Field } {
function field(id: string, label: string, icon: IconId, input: HTMLInputElement, hint: () => Child[], want: number): { el: HTMLDivElement; f: Field } {
const help = h('p', { id: `${id}-help`, class: 'field-help' }, hint())
input.id = id
input.setAttribute('aria-describedby', `${id}-help`)
@ -59,7 +66,7 @@ function field(id: string, label: string, icon: string, input: HTMLInputElement,
'div',
{ class: 'form-field' },
// The glyph is painted beside a spoken-only <label>, so the label's text stays exactly `label`.
h('span', { class: 'field-label', 'aria-hidden': 'true' }, icon),
h('span', { class: 'field-label', 'aria-hidden': 'true' }, iconInline(icon)),
h('label', { for: id, class: 'sr-only' }, label),
input,
help,
@ -92,7 +99,7 @@ export class SetupFormElement extends LiveElement {
const key = field(
'setup-key',
'Steam Web API key',
'🔑',
'setup.api-key',
h('input', { class: 'input mono', type: 'password', autocomplete: 'off', spellcheck: 'false', autofocus: true }),
KEY_HELP,
32,
@ -100,7 +107,7 @@ export class SetupFormElement extends LiveElement {
const id = field(
'setup-id',
'SteamID64',
'🆔',
'setup.steam-id',
h('input', { class: 'input mono input-num', inputmode: 'numeric', placeholder: ID_SHAPE }),
ID_HELP,
17,
@ -149,8 +156,8 @@ export class SetupFormElement extends LiveElement {
? [notice('warning', null, spoken('Not configured yet', 'Every other screen needs these two values first.'))]
: []),
)
// 🔒 + filled dots: a key is stored (typing replaces it); hollow dots: none yet.
this.keyField.input.placeholder = data?.has_api_key ? KEY_STORED : KEY_SHAPE
// Lock icon + filled dots: a key is stored (typing replaces it); hollow dots: none yet.
this.keyField.input.placeholder = data?.has_api_key ? keyStored() : KEY_SHAPE
this.keyField.input.dataset.stored = String(data?.has_api_key ?? false)
if (!this.idEdited) this.idField.input.value = data?.steam_id ?? ''
this.render()
@ -167,30 +174,30 @@ export class SetupFormElement extends LiveElement {
'success',
null,
spoken('Saved', 'Steam accepted the key.'),
h('a', { href: '/', class: 'btn btn-ghost btn-small', 'aria-label': 'Go to the dashboard' }, '🏠'),
h('a', { href: '/', class: 'btn btn-ghost btn-small', 'aria-label': 'Go to the dashboard' }, iconInline('nav.dashboard')),
),
]
: []),
)
this.failure.replaceChildren(...(this.save.error ? [errorNotice(this.save.error)] : []))
this.submit.disabled = this.save.pending
// ⏳ while Steam checks, ✔️ to save; the words are spoken only.
this.submit.replaceChildren(this.save.pending ? glyph('⏳', 'Checking with Steam…') : glyph('✔️', 'Save and verify'))
// The busy icon while Steam checks, the confirm icon to save; the words are spoken only.
this.submit.replaceChildren(this.save.pending ? glyph('state.wait', 'Checking with Steam…') : glyph('action.confirm', 'Save and verify'))
}
private mark(f: Field, problem: string | null): void {
const bad = this.touched && problem !== null
f.input.className = bad ? `${f.baseClass} input-bad` : f.baseClass
f.input.setAttribute('aria-invalid', String(bad))
// A bad value paints ⚠️ and how many characters it has of the `want` it needs.
const count = `⚠️ ${f.input.value.trim().length}/${f.want}`
// A bad value paints the warning icon and how many characters it has of the `want` it needs.
const count = `${f.input.value.trim().length}/${f.want}`
const state = bad ? `${problem}|${count}` : 'ok'
if (f.help.dataset.state === state) return
f.help.dataset.state = state
f.help.dataset.bad = String(bad)
f.help.className = bad ? 'field-help text-danger' : 'field-help'
f.help.replaceChildren()
append(f.help, bad ? [h('span', { 'aria-hidden': 'true', class: 'mono' }, count), h('span', { class: 'sr-only' }, problem)] : f.hint())
append(f.help, bad ? [h('span', { 'aria-hidden': 'true', class: 'mono' }, iconInline('state.warn'), ` ${count}`), h('span', { class: 'sr-only' }, problem)] : f.hint())
}
private async store(): Promise<void> {

View File

@ -8,6 +8,8 @@ import { explain } from '../../api/errors'
import type { StateBackup } from '../../api/contract'
import type { Job } from '../../api/jobContract'
import { q } from '../../api/queries'
import type { IconId } from '../../icons/registry'
import { iconInline } from '../../icons/render'
import { phraseMatches } from '../../commands/catalog'
import '../../commands/commandButton'
import { PhraseField } from '../../commands/phraseField'
@ -24,8 +26,9 @@ import { bytes, dateTime } from '../../ui/format'
export const restorePhrase = (id: string): string => `restore backup ${id}`
/** Why a backup was taken, as a glyph (reason words spoken only). */
const REASON_ICON: Record<string, string> = { 'before reset': '♻️', nightly: '🌙' }
const reasonGlyph = (reason: string): HTMLSpanElement => glyph(REASON_ICON[reason] ?? '🗄️', reason)
const REASON_ICON: Readonly<Partial<Record<string, IconId>>> = { 'before reset': 'backup.reason.reset', nightly: 'backup.reason.nightly' }
const reasonIcon = (reason: string): IconId => REASON_ICON[reason] ?? 'backup.reason.other'
const reasonGlyph = (reason: string): HTMLSpanElement => glyph(reasonIcon(reason), reason)
/** One restore: phrase form, then the job it started. */
export class RestoreDialog {
@ -66,8 +69,8 @@ export class RestoreDialog {
'p',
{ class: 'm0 row' },
h('span', { class: 'sr-only' }, `Replaces the current state with the backup from ${dateTime(backup.created_at)} (${backup.reason}).`),
h('span', { 'aria-hidden': 'true', class: 'mono' }, `🗄️ ${backup.id} · ${dateTime(backup.created_at)}`),
h('span', { 'aria-hidden': 'true' }, REASON_ICON[backup.reason] ?? '🗄️'),
h('span', { 'aria-hidden': 'true', class: 'mono' }, iconInline('backup.item'), ` ${backup.id} · ${dateTime(backup.created_at)}`),
h('span', { 'aria-hidden': 'true' }, iconInline(reasonIcon(backup.reason))),
),
this.field.el,
this.failure,
@ -75,7 +78,7 @@ export class RestoreDialog {
'div',
{ class: 'actions' },
this.submit,
h('button', { type: 'button', class: 'btn btn-ghost', onclick: onClose }, glyph('✖️', 'Cancel')),
h('button', { type: 'button', class: 'btn btn-ghost', onclick: onClose }, glyph('action.cancel', 'Cancel')),
),
)
this.modal.render(form)
@ -88,7 +91,7 @@ export class RestoreDialog {
private sync(): void {
this.submit.disabled = !this.matches() || this.restore.pending
this.submit.replaceChildren(this.restore.pending ? glyph('⏳', 'Restoring…') : glyph('⏮️', 'Restore'))
this.submit.replaceChildren(this.restore.pending ? glyph('state.wait', 'Restoring…') : glyph('backup.restore', 'Restore'))
this.failure.replaceChildren(...(this.restore.error ? [errorNotice(this.restore.error)] : []))
}
@ -101,7 +104,7 @@ export class RestoreDialog {
'div',
{ class: 'stack' },
hx('job-progress', { 'job-id': out.value.id }),
h('div', { class: 'actions' }, h('button', { type: 'button', class: 'btn btn-ghost', onclick: onClose }, glyph('✖️', 'Close'))),
h('div', { class: 'actions' }, h('button', { type: 'button', class: 'btn btn-ghost', onclick: onClose }, glyph('action.cancel', 'Close'))),
),
)
this.modal.focusFirst()
@ -114,7 +117,7 @@ export class BackupsCardElement extends LiveElement {
private readonly root = card(
'State backups',
[h('p', { class: 'sr-only' }, 'Reset takes a timestamped backup first, so it can be undone here.'), this.status, this.list],
{ aside: hx('command-button', { name: 'reset', label: 'Reset all state…' }), icon: '🗄️' },
{ aside: hx('command-button', { name: 'reset', label: 'Reset all state…' }), icon: 'backup.item' },
)
private dialog: RestoreDialog | null = null
private shownKey = ''
@ -161,7 +164,7 @@ export class BackupsCardElement extends LiveElement {
this.open(b)
},
},
glyph('⏮️', 'Restore…'),
glyph('backup.restore', 'Restore…'),
),
),
),

View File

@ -5,6 +5,8 @@
// focus from a button or yanks the journal while it is being read.
import { q } from '../../api/queries'
import type { IconId } from '../../icons/registry'
import { iconInline } from '../../icons/render'
import { define, h } from '../../lib/dom'
import { LiveElement } from '../../lib/element'
import { runner } from '../../lib/runner'
@ -25,7 +27,11 @@ export function restartWaitMs(availableAt: string | null, now: number = Date.now
}
/** Daemon state: glyph painted, the state word spoken. */
const STATE_ICON: Record<DaemonState, string> = { running: '🟢', restarting: '🔄', unreachable: '🔴' }
const STATE_ICON = {
running: 'daemon.running',
restarting: 'daemon.restarting',
unreachable: 'daemon.unreachable',
} as const satisfies Record<DaemonState, IconId>
function unreachableNotice(): HTMLDivElement {
// Textgate: ⛔ + the command to run are painted; the explanation is spoken only.
@ -66,16 +72,16 @@ export class DaemonCardElement extends LiveElement {
runner.run('enforce', { demo: 1 })
},
},
glyph('🧪', 'Demo run (enforce --demo)…'),
glyph('daemon.demo_run', 'Demo run (enforce --demo)…'),
)
private readonly parts = [
this.alert,
this.factsSlot,
h('div', { class: 'actions' }, this.restart, this.demo),
h('h3', { class: 'h3' }, glyph('📜', 'Journal')),
h('h3', { class: 'h3' }, glyph('daemon.journal', 'Journal')),
this.journal,
]
private readonly root = card('Enforcer daemon', [this.status, this.body], { icon: '🛡️' })
private readonly root = card('Enforcer daemon', [this.status, this.body], { icon: 'daemon.heading' })
private shown = false
private canRestart = false
private unreachable = false
@ -104,19 +110,19 @@ export class DaemonCardElement extends LiveElement {
}
this.factsSlot.replaceChildren(
facts([
[glyph('📡', 'State'), h('span', { 'data-state': data.state }, glyph(STATE_ICON[data.state], data.state))],
[glyph('#️⃣', 'PID'), data.pid ?? '—'],
[glyph('⏱️', 'Up since'), data.started_at ? since(data.started_at) : '—'],
[glyph('daemon.state', 'State'), h('span', { 'data-state': data.state }, glyph(STATE_ICON[data.state], data.state))],
[glyph('daemon.pid', 'PID'), data.pid ?? '—'],
[glyph('daemon.up_since', 'Up since'), data.started_at ? since(data.started_at) : '—'],
]),
)
this.canRestart = waitMs === 0 && data.state === 'running'
this.restart.setAttribute('aria-disabled', String(!this.canRestart))
// Rate limited: ⏳ + the clock counting down; free: 🔄. Words spoken only.
// Rate limited: the busy icon + the clock counting down; free: the restart icon. Words spoken only.
const wait = clock(waitMs / 1000)
this.restart.replaceChildren(
waitMs > 0
? h('span', { 'aria-label': `Restart available in ${wait}` }, h('span', { 'aria-hidden': 'true' }, `⏳ ${wait}`))
: glyph('🔄', 'Restart daemon…'),
? h('span', { 'aria-label': `Restart available in ${wait}` }, h('span', { 'aria-hidden': 'true' }, iconInline('state.wait'), ` ${wait}`))
: glyph('daemon.restart', 'Restart daemon…'),
)
this.fillJournal(data.journal_tail)
}

View File

@ -0,0 +1,83 @@
// The system page paints every icon through the registry: the user's word
// shows right of the icon, a chosen alternative glyph replaces the default,
// and the spoken names stay as they were.
import { screen, waitFor } from '@testing-library/dom'
import { beforeEach, describe, expect, it } from 'vitest'
import type { DaemonStatus } from '../../api/contract'
import { makeSpec } from '../../test/fixtures'
import { installEventSource, mount, stubApi } from '../../test/harness'
import { useIcons } from '../../test/iconLedger'
import './backupsCard'
import './daemonCard'
import './serverCard'
import './setupCard'
const daemon = (over: Partial<DaemonStatus> = {}): DaemonStatus => ({
state: 'running',
started_at: '2026-10-10T10:00:00Z',
pid: 4242,
journal_tail: [],
restart_available_at: null,
...over,
})
const words = (root: Element) => [...root.querySelectorAll('.icon-word')].map((w) => w.textContent)
const marks = (root: Element) => [...root.querySelectorAll('[data-icon]')].map((m) => m.textContent)
beforeEach(installEventSource)
describe('system page icons', () => {
it('daemon card: state, pid and restart icons carry words and glyphs, names spoken', async () => {
useIcons({ 'daemon.running': { word: 'alive', glyph: '💚' }, 'daemon.pid': { word: 'process' }, 'daemon.restart': { word: 'restart' } })
stubApi({ 'GET /api/daemon': daemon() })
const el = mount('<daemon-card></daemon-card>')
await screen.findByText('4242')
expect(words(el)).toEqual(expect.arrayContaining(['Alive', 'Process', 'Restart']))
expect(marks(el)).toContain('💚')
expect(screen.getByText('PID')).toHaveClass('sr-only')
expect(screen.getByRole('button', { name: /Restart daemon/ })).toBeInTheDocument()
})
it('daemon card: the rate-limit countdown keeps the busy icon and its word', async () => {
useIcons({ 'state.wait': { word: 'busy' } })
const later = new Date(Date.now() + 90_000).toISOString()
stubApi({ 'GET /api/daemon': daemon({ restart_available_at: later }) })
const el = mount('<daemon-card></daemon-card>')
await waitFor(() => {
expect(words(el)).toEqual(['Busy'])
})
expect(screen.getByLabelText(/Restart available in/)).toBeInTheDocument()
})
it('server card: version, code state and restart carry the chosen icons', async () => {
useIcons({ 'server.version': { word: 'build' }, 'state.yes': { word: 'fresh' }, 'server.restart': { glyph: '🚀' } })
stubApi({ 'GET /api/server': { stale: false, started_at: '2026-10-10T10:00:00Z', version: '9.9.9' } })
const el = mount('<server-card></server-card>')
await screen.findByText('9.9.9')
expect(words(el)).toEqual(['Build', 'Fresh'])
expect(screen.getByRole('button', { name: 'Restart server' }).querySelector('[data-icon]')?.textContent).toBe('🚀')
expect(screen.getByText('current')).toHaveClass('sr-only')
})
it('backups card: reason, restore and cancel icons go through the registry', async () => {
useIcons({ 'backup.reason.reset': { word: 'wipe' }, 'backup.restore': { glyph: '⏪' }, 'action.cancel': { word: 'cancel' } })
stubApi({
'GET /api/backups': [{ id: '20261010-100000', created_at: '2026-10-10T10:00:00Z', reason: 'before reset', size_bytes: 2048 }],
'GET /api/commands': [makeSpec('reset')],
'GET /api/jobs': [],
})
const el = mount('<backups-card></backups-card>')
await screen.findByText('20261010-100000')
expect(words(el)).toEqual(['Wipe'])
expect(screen.getByRole('button', { name: 'Restore…' }).querySelector('[data-icon]')?.textContent).toBe('⏪')
})
it('setup card: key, stored and edit icons carry the words, sentences stay spoken', async () => {
useIcons({ 'setup.api-key': { word: 'key' }, 'setup.key-stored': { word: 'safe' },'syssetup.edit': { glyph: '📝' } })
stubApi({ 'GET /api/setup': { configured: true, has_api_key: true, steam_id: '7656119800000000' } })
const el = mount('<setup-card></setup-card>')
await screen.findByText('Stored (never shown)')
expect(words(el)).toEqual(['Key', 'Safe'])
expect(screen.getByRole('link', { name: 'Open setup' }).querySelector('[data-icon]')?.textContent).toBe('📝')
})
})

View File

@ -19,7 +19,7 @@ export class ServerCardElement extends LiveElement {
void this.restart.action.run()
},
})
private readonly root = card('Web server', [this.info, this.failure, h('div', { class: 'actions' }, this.button)], { icon: '🌐' })
private readonly root = card('Web server', [this.info, this.failure, h('div', { class: 'actions' }, this.button)], { icon: 'server.heading' })
private readonly restart = new ServerRestart(() => {
this.update()
})
@ -41,9 +41,9 @@ export class ServerCardElement extends LiveElement {
...(data
? [
facts([
[glyph('🏷️', 'Version'), h('span', { class: 'mono' }, data.version)],
[glyph('🕒', 'Started'), h('span', { 'aria-label': `${dateTime(data.started_at)} (${ago(data.started_at)})` }, dateTime(data.started_at))],
[glyph('💾', 'Code'), data.stale ? glyph('⚠️', 'stale') : glyph('✅', 'current')],
[glyph('server.version', 'Version'), h('span', { class: 'mono' }, data.version)],
[glyph('server.started', 'Started'), h('span', { 'aria-label': `${dateTime(data.started_at)} (${ago(data.started_at)})` }, dateTime(data.started_at))],
[glyph('server.code', 'Code'), data.stale ? glyph('state.warn', 'stale') : glyph('state.yes', 'current')],
]),
]
: []),
@ -52,7 +52,7 @@ export class ServerCardElement extends LiveElement {
this.failure.replaceChildren(...(action.error ? [errorNotice(action.error)] : []))
this.button.disabled = restarting || action.pending
this.button.dataset.restarting = String(restarting)
this.button.replaceChildren(restarting ? glyph('⏳', 'Restarting… the page reloads when it is back') : glyph('🔄', 'Restart server'))
this.button.replaceChildren(restarting ? glyph('state.wait', 'Restarting… the page reloads when it is back') : glyph('server.restart', 'Restart server'))
}
}

View File

@ -18,11 +18,11 @@ export class SetupCardElement extends LiveElement {
card(
'Setup',
facts([
[glyph('⚙️', 'Configured'), data ? (data.configured ? glyph('✅', 'Yes') : glyph('❌', 'No')) : '…'],
[glyph('🔑', 'Steam API key'), data ? (data.has_api_key ? glyph('🔒', 'Stored (never shown)') : glyph('❌', 'Missing')) : '…'],
[glyph('🆔', 'Steam ID'), h('span', { class: 'mono' }, data?.steam_id ?? '—')],
[glyph('syssetup.configured', 'Configured'), data ? (data.configured ? glyph('state.yes', 'Yes') : glyph('state.no', 'No')) : '…'],
[glyph('setup.api-key', 'Steam API key'), data ? (data.has_api_key ? glyph('setup.key-stored','Stored (never shown)') : glyph('state.no', 'Missing')) : '…'],
[glyph('setup.steam-id', 'Steam ID'), h('span', { class: 'mono' }, data?.steam_id ?? '—')],
]),
{ aside: link(pageHref('/setup'), glyph('✏️', 'Open setup')), icon: '🔧' },
{ aside: link(pageHref('/setup'), glyph('syssetup.edit', 'Open setup')), icon: 'cmd.setup' },
),
)
}

View File

@ -0,0 +1,53 @@
// Pass-2 icon wiring for the health badges and the stale banner: subject and
// state are separate ids, the user's words show right of them, the spoken
// text (pill text, aria-label) stays.
import { describe, expect, it, vi } from 'vitest'
import { button } from '../test/events'
import { mount, stubApi } from '../test/harness'
import { useIcons } from '../test/iconLedger'
import { painted } from '../test/painted'
import { visibleWords } from '../test/visibleWords'
import './health'
const server = (over = {}) => ({ stale: false, started_at: '2026-10-10T10:00:00Z', version: '1.2.3', ...over })
const daemon = (state: string) => ({ state, started_at: null, pid: null, journal_tail: [], restart_available_at: null })
describe('health badges by id', () => {
it('draws the subject and the state with their words and glyphs', async () => {
useIcons({
'server.heading': { word: 'web' },
'health.ok': { word: 'fine', glyph: '🟢' },
'daemon.heading': { word: 'guard' },
'health.warn': { word: 'shaky' },
})
stubApi({ 'GET /api/server': server(), 'GET /api/daemon': daemon('restarting') })
const el = mount('<health-badges></health-badges>')
await vi.waitFor(() => { expect(el.querySelector('[data-state="Daemon restarting"]')).not.toBeNull() })
const pills = [...el.querySelectorAll<HTMLElement>('.pill')]
expect(painted(pills[0])).toBe('🌐Web🟢Fine')
expect(painted(pills[1])).toBe('🛡️Guard⚠️Shaky')
expect(pills[0]?.querySelector('.sr-only')?.textContent).toContain('Server ok')
expect(pills[1]).toHaveAttribute('data-state', 'Daemon restarting')
expect(visibleWords(el)).toEqual([])
})
it('keeps the plain glyphs without words, the unknown state as the ellipsis', () => {
stubApi({ 'GET /api/server': () => new Promise(() => undefined), 'GET /api/daemon': () => new Promise(() => undefined) })
const el = mount('<health-badges></health-badges>')
expect(painted(el.querySelector('[data-state="Daemon …"]'))).toBe('🛡️…')
})
})
describe('stale banner by id', () => {
it('draws the stale mark and the restart icon from the ledger', async () => {
useIcons({ 'health.stale': { word: 'old' }, 'server.restart': { word: 'reload', glyph: '♻️' } })
stubApi({ 'GET /api/server': server({ stale: true }) })
const el = mount('<stale-banner></stale-banner>')
await vi.waitFor(() => { expect(el).toHaveTextContent('The web server is running stale code.') })
const banner = el.firstElementChild
expect(banner?.querySelector('.glyph [data-icon="health.stale"]')?.textContent).toBe('⚠️🌐')
expect(banner?.querySelector('.glyph .icon-word')?.textContent).toBe('Old')
expect(button(el, 'Restart server').textContent).toBe('♻️Reload')
})
})

View File

@ -2,20 +2,22 @@
// every page while the running server is older than the code on disk).
import { q } from '../api/queries'
import type { IconId } from '../icons/registry'
import { iconInline } from '../icons/render'
import { define, h } from '../lib/dom'
import { LiveElement } from '../lib/element'
import { errorNotice, glyph } from '../ui/build'
import { ServerRestart } from './serverRestart'
const DAEMON_TONE = { running: 'success', restarting: 'warning', unreachable: 'danger' } as const
const STATE_GLYPH: Record<string, string> = { success: '✅', warning: '⚠️', danger: '⛔', neutral: '…' }
const STATE_ICON: Record<string, IconId> = { success: 'health.ok', warning: 'health.warn', danger: 'health.bad', neutral: 'health.unknown' }
/** A health pill: glyphs painted, `text` (+ `extra`) spoken. `data-state` holds the words for tests. */
function badge(tone: string, icons: string, text: string, extra = ''): HTMLSpanElement {
/** A health pill: the subject and state icons painted, `text` (+ `extra`) spoken. `data-state` holds the words for tests. */
function badge(tone: string, subject: IconId, text: string, extra = ''): HTMLSpanElement {
return h(
'span',
{ class: `pill pill-${tone}`, 'data-state': text },
h('span', { 'aria-hidden': 'true' }, icons),
h('span', { class: 'has-word', 'aria-hidden': 'true' }, iconInline(subject), iconInline(STATE_ICON[tone] ?? 'health.unknown')),
h('span', { class: 'sr-only' }, text + extra),
)
}
@ -31,15 +33,15 @@ export class HealthBadgesElement extends LiveElement {
const d = q.daemon.state.data?.state
const serverTone = server.error ? 'danger' : server.data?.stale ? 'warning' : 'success'
const serverText = server.error ? 'Server down' : server.data?.stale ? 'Server stale' : 'Server ok'
// Textgate: 🌐 server / 🛡️ daemon + a state glyph, on the tone colour; the
// words (and the version, formerly a tooltip) are spoken only.
// Textgate: the server / daemon icon + a state icon, on the tone colour;
// the words (and the version, formerly a tooltip) are spoken only.
const version = server.data ? ` v${server.data.version}` : ''
this.replaceChildren(
h(
'div',
{ class: 'health', 'aria-label': 'Health' },
badge(serverTone, `🌐${STATE_GLYPH[serverTone]}`, serverText, version),
badge(d ? DAEMON_TONE[d] : 'neutral', `🛡️${STATE_GLYPH[d ? DAEMON_TONE[d] : 'neutral']}`, `Daemon ${d ?? '…'}`),
badge(serverTone, 'server.heading', serverText, version),
badge(d ? DAEMON_TONE[d] : 'neutral', 'daemon.heading',`Daemon ${d ?? '…'}`),
),
)
}
@ -67,7 +69,7 @@ export class StaleBannerElement extends LiveElement {
h(
'div',
{ class: 'banner banner-warning', role: 'status' },
glyph('⚠️🌐', 'The web server is running stale code. Restart it to pick up the new version.'),
glyph('health.stale', 'The web server is running stale code. Restart it to pick up the new version.'),
h(
'button',
{
@ -77,7 +79,7 @@ export class StaleBannerElement extends LiveElement {
onclick: () => void action.run(),
'aria-label': this.restart.restarting ? 'Restarting…' : 'Restart server',
},
h('span', { 'aria-hidden': 'true' }, this.restart.restarting ? '⏳' : '🔄'),
iconInline(this.restart.restarting ? 'state.wait' : 'server.restart'),
),
action.error ? errorNotice(action.error) : null,
),

View File

@ -30,7 +30,7 @@ export function jobChip(job: Job): HTMLAnchorElement {
'span',
{ class: 'jobchip-label' },
glyph(commandIcon(job.command), label),
h('span', { class: 'jobchip-sub' }, waiting ? glyph('✋', 'needs input') : p?.total ? `${p.step}/${p.total}` : '…'),
h('span', { class: 'jobchip-sub' }, waiting ? glyph('jobchip.needs-input', 'needs input') : p?.total ? `${p.step}/${p.total}` : '…'),
),
progressBar(fraction, label, waiting ? 'warning' : 'accent', true),
)

View File

@ -27,10 +27,9 @@ export interface PalettePage {
to: string
label: string
blurb: string
/** A raw glyph: these pages are not in the icon registry yet. */
icon: string
icon: IconId
}
export const PALETTE_PAGES: PalettePage[] = [
{ to: '/words', label: 'Icon words', blurb: 'Pick the word shown next to each icon', icon: '🏷️' },
{ to: '/words', label: 'Icon words', blurb: 'Pick the word shown next to each icon', icon: 'words.page' },
]

View File

@ -0,0 +1,24 @@
// The dialog's close button is a registered icon: his word beside it, his
// glyph in place of the default, the aria-label stays "Close".
import { describe, expect, it, vi } from 'vitest'
import { useIcons } from '../test/iconLedger'
import { Modal } from './dialog'
describe('Modal close button by id', () => {
it('paints the default cross, spoken name Close', () => {
const modal = new Modal({ title: 'Hello', onClose: vi.fn() })
const close = modal.el.querySelector('.dialog-close')
expect(close?.textContent).toBe('×')
expect(close).toHaveAttribute('aria-label', 'Close')
})
it('paints the user word right of his chosen glyph', () => {
useIcons({ 'dialog.close': { word: 'exit', glyph: '❌' } })
const modal = new Modal({ title: 'Hello', onClose: vi.fn() })
const close = modal.el.querySelector('.dialog-close')
expect(close?.textContent).toBe('❌Exit')
expect(close?.querySelector('.icon-word')).toHaveAttribute('data-icon-word', 'dialog.close')
expect(close).toHaveAttribute('aria-label', 'Close')
})
})

View File

@ -2,6 +2,7 @@
// inert background and Escape (routed through `onClose` so the owner decides
// what closing means). Focus returns to the opener when it closes.
import { iconInline } from '../icons/render'
import { append, h, type Child } from '../lib/dom'
export interface ModalOptions {
@ -23,7 +24,7 @@ export class Modal {
const close = h(
'button',
{ type: 'button', class: 'btn btn-ghost btn-icon dialog-close', 'aria-label': 'Close', onclick: onClose },
h('span', { 'aria-hidden': 'true' }, '×'),
iconInline('dialog.close'),
)
this.head = h('header', { class: 'dialog-head' }, this.heading, close)
this.body = h('div', { class: 'dialog-body' }, this.head)