feat: the venue's identity in every app: its colour as the accent of the waiters' phones and every terminal screen, customer display looks on the identity, the signage logo widget falls back to the venue's logo

Settings -> Venue -> accent "The venue's identity" (venue.theme = identity): bootstrap
carries the identity's first colour and logos; @xenia/ui applyVenueTheme makes the
accent tokens (light and dark, readable foregrounds) from it. A display look's
"Colours and logo" can be the venue's identity. Plan 6R.20, F-117.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 15:30:14 +02:00
co-authored by Claude Opus 5.5
parent 0bd32d9171
commit 1b111c0e27
20 changed files with 229 additions and 28 deletions
+1
View File
@@ -38,4 +38,5 @@ export { Stepper } from './components/Stepper.jsx'
export { ReasonPicker, reasonText } from './components/ReasonPicker.jsx'
export { UiLabelsProvider, DEFAULT_LABELS } from './components/labels.js'
export { cx } from './internal/cx.js'
export { accentCss, accentTokens, applyVenueTheme } from './venueAccent.js'
export { THEMES, PALETTES, STYLES, THEME_STORAGE_KEY, PALETTE_STORAGE_KEY, STYLE_STORAGE_KEY, applyLook, applyTheme, getStoredLook, getStoredTheme, resolveMode } from './theme.js'
+68
View File
@@ -0,0 +1,68 @@
// The staff apps' accent from the venue's own colour (6R.20): Settings → Venue → "The venue's
// identity" makes the accent tokens (accent, strong, fg, soft, ink; light and dark) from the first
// colour of the venue's identity instead of a ready-made accent (data-venue-theme="teal"…). The
// tokens come from a <style> the page gets once; data-venue-theme="identity" turns them on. No React.
//
// applyVenueTheme('identity', '#1e3a8a') the identity's colour
// applyVenueTheme('amber') a ready-made accent (tokens.css)
const STYLE_ID = 'x-venue-accent'
const rgb = hex => {
const h = String(hex || '').replace('#', '').slice(0, 6)
return /^[0-9a-fA-F]{6}$/.test(h) ? [0, 2, 4].map(i => parseInt(h.slice(i, i + 2), 16)) : null
}
const mix = (a, b, t) => a.map((v, i) => Math.round(v + (b[i] - v) * t))
const lum = c => {
const [r, g, b] = c.map(v => { const s = v / 255; return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4 })
return 0.2126 * r + 0.7152 * g + 0.0722 * b
}
const WHITE = [255, 255, 255]
const BLACK = [0, 0, 0]
const ratio = (a, b) => { const [x, y] = [lum(a), lum(b)].sort((m, n) => n - m); return (x + 0.05) / (y + 0.05) }
/** White or a near-black of the colour, whichever reads better on it. */
const fgOn = c => { const dark = mix(c, BLACK, 0.85); return ratio(c, WHITE) >= ratio(c, dark) ? WHITE : dark }
/** Darker until it reads on white (text, buttons on a light page). */
const deepen = c => { let x = c; for (let i = 0; i < 12 && ratio(x, WHITE) < 4.5; i++) x = mix(x, BLACK, 0.12); return x }
const str = c => c.join(' ')
/** The accent tokens for a colour: { light: {name: "r g b"}, dark: {…} }, or null for a bad colour. */
export function accentTokens(hex) {
const c = rgb(hex)
if (!c) return null
// light: the colour, kept dark enough to read on white
const base = deepen(c)
const light = { accent: base, 'accent-strong': mix(base, BLACK, 0.2), 'accent-soft': mix(c, WHITE, 0.85), 'accent-ink': mix(base, BLACK, 0.3) }
light['accent-fg'] = fgOn(light.accent)
// dark: lighter, to read on the dark surfaces
const up = lum(c) < 0.25 ? mix(c, WHITE, 0.45) : c
const dark = { accent: up, 'accent-strong': mix(up, WHITE, 0.25), 'accent-soft': mix(c, BLACK, 0.65), 'accent-ink': mix(up, WHITE, 0.55) }
dark['accent-fg'] = fgOn(dark.accent)
const out = m => Object.fromEntries(Object.entries(m).map(([k, v]) => [k, str(v)]))
return { light: out(light), dark: out(dark) }
}
/** The CSS that turns the tokens on under data-venue-theme="identity". */
export function accentCss(hex) {
const t = accentTokens(hex)
if (!t) return ''
const block = m => Object.entries(m).map(([k, v]) => `--x-${k}-rgb: ${v};`).join(' ')
return `[data-venue-theme="identity"] { ${block(t.light)} }\n`
+ `[data-theme="dark"][data-venue-theme="identity"], [data-theme="dark"] [data-venue-theme="identity"] { ${block(t.dark)} }\n`
}
/** The venue's accent on <html>: a ready-made one, or "identity" with its colour (no colour: as before). */
export function applyVenueTheme(theme, colour, { root = globalThis.document?.documentElement } = {}) {
if (!root) return
const doc = root.ownerDocument
let el = doc.getElementById(STYLE_ID)
const css = theme === 'identity' ? accentCss(colour) : ''
if (css) {
if (!el) { el = doc.createElement('style'); el.id = STYLE_ID; doc.head.appendChild(el) }
if (el.textContent !== css) el.textContent = css
root.setAttribute('data-venue-theme', 'identity')
} else {
if (theme && theme !== 'identity') root.setAttribute('data-venue-theme', theme)
else root.removeAttribute('data-venue-theme')
}
}
+19
View File
@@ -0,0 +1,19 @@
// The accent from the venue's identity colour (6R.20).
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { accentCss, accentTokens } from '../src/venueAccent.js'
const lum = s => { const [r, g, b] = s.split(' ').map(Number).map(v => { const x = v / 255; return x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4 }); return 0.2126 * r + 0.7152 * g + 0.0722 * b }
const contrast = (a, b) => { const [x, y] = [lum(a), lum(b)].sort((m, n) => n - m); return (x + 0.05) / (y + 0.05) }
test('tokens from a colour: text on the accent reads, light and dark', () => {
for (const hex of ['#1e3a8a', '#f59e0b', '#ffffff', '#000000', '#22c55e', '#e63946']) {
const t = accentTokens(hex)
assert.ok(contrast(t.light.accent, t.light['accent-fg']) >= 3, `${hex} light ${JSON.stringify(t.light)}`)
assert.ok(contrast(t.dark.accent, t.dark['accent-fg']) >= 3, `${hex} dark ${JSON.stringify(t.dark)}`)
assert.ok(contrast(t.light['accent-ink'], '255 255 255') >= 3, `${hex} ink on white`)
}
assert.equal(accentTokens('red'), null)
assert.equal(accentCss('nope'), '')
assert.match(accentCss('#1e3a8a'), /\[data-venue-theme="identity"\] \{ --x-accent-rgb: 30 58 138;/)
})