feat(theming): server-resolved theme engine and admin appearance UI

Phases 3-4 of docs/website/THEMING_AND_NAV.md. Three presets, the curated font
shortlist, and /admin/appearance to drive them.

The design put the presets in theme.css as [data-theme] blocks. That does not
work: SiteContext writes --accent as an inline style on <html>, which beats any
attribute-selector block, so a preset's accent would have been painted over by
BRAND_ACCENT_COLOR while getPublic().brand.accent -- the value the Android app
themes itself from -- reported the other one.

Presets now live in server/src/config/themePresets.js. themeResolve.js layers
:root <- preset <- custom per field into a token map, getPublic() returns it as
`theme`, and the client writes it onto <html>. One authority for the merge, and
brand.accent is by construction the accent the site paints. theme.css's :root is
untouched, so an instance with no row gets no theme block and renders as today.

Also: presets carry the full 15-token palette (eight would have left Fantasy
with blue-grey borders); the option catalog is served from
GET /settings/theme/options so the form cannot offer what the server rejects;
validation is strict on write and forgiving on read; and the Discord bot now
fetches the effective accent instead of its boot-time env copy.

Fixes a Phase 0 bug in passing: settings/nav.controller.js imported the logger
factory rather than calling it, so a DB fault would have thrown a TypeError
inside the catch instead of returning 500.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-08-07 19:16:23 -05:00
parent 0a2ccafff6
commit 3d6b2e23a7
26 changed files with 2113 additions and 28 deletions

View File

@@ -12772,6 +12772,51 @@
}
]
}
},
"/api/v1/settings/theme/options": {
"get": {
"tags": [
"Settings"
],
"summary": "Theme presets and the curated option lists",
"description": "The closed sets an admin may choose from when theming the site: the three presets (with swatch colors), the curated Google Fonts shortlist per role, the shadow depths, and the editable color/radius field names. Served so the admin form can never offer a value the server would reject. Static — no database read.",
"responses": {
"200": {
"description": "Theme option catalog",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ThemeOptions"
}
}
}
},
"401": {
"description": "Not authenticated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Internal Server Error"
}
},
"security": [
{
"cookieAuth": []
},
{
"bearerAuth": []
}
]
}
}
},
"components": {
@@ -17720,7 +17765,7 @@
},
"description": {
"type": "string",
"example": "Seed/accent color (hex) for theming."
"example": "Seed/accent color (hex) for theming. **Effective** value: the admin theme (theme_visual) wins over BRAND_ACCENT_COLOR, so a client that themes from this tracks admin theming with no change."
}
}
},
@@ -17737,7 +17782,7 @@
},
"description": {
"type": "string",
"example": "Logo URL or site-relative path; empty = no logo."
"example": "Logo URL or site-relative path; empty = no logo. An uploaded brand_assets.logo overrides BRAND_LOGO."
}
}
},
@@ -17754,7 +17799,7 @@
},
"description": {
"type": "string",
"example": "Hero image URL or site-relative path."
"example": "Hero image URL or site-relative path. An uploaded brand_assets.hero overrides BRAND_HERO."
}
}
},
@@ -17771,7 +17816,7 @@
},
"description": {
"type": "string",
"example": "Favicon URL or site-relative path."
"example": "Favicon URL or site-relative path. An uploaded brand_assets.favicon overrides BRAND_FAVICON."
}
}
}
@@ -17880,6 +17925,49 @@
"brand": {
"$ref": "#/components/schemas/Brand"
},
"theme": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"nullable": {
"type": "boolean",
"example": true
},
"description": {
"type": "string",
"example": "The effective CSS custom properties for the admin theme, resolved server-side (:root ← preset ← custom). **Absent** when the admin never set a theme, which is what makes an untouched instance render from the shipped stylesheet unchanged. Keys are CSS variable names; every value comes from a closed set (hex color, curated font stack, bounded px length, listed shadow)."
},
"additionalProperties": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
}
}
},
"example": {
"type": "object",
"properties": {
"--accent": {
"type": "string",
"example": "#c9973f"
},
"--bg": {
"type": "string",
"example": "#1a120b"
},
"--radius-card": {
"type": "string",
"example": "2px"
}
}
}
}
},
"push": {
"type": "object",
"properties": {
@@ -17972,6 +18060,344 @@
}
}
},
"ThemeOptions": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"description": {
"type": "string",
"example": "The closed sets an admin may choose from when theming the site (GET /settings/theme-options). Served so the admin form cannot offer a value PUT /admin/settings would reject. Static — derived from the server theme config, not the database."
},
"properties": {
"type": "object",
"properties": {
"presets": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "array"
},
"description": {
"type": "string",
"example": "Selectable presets and their full token maps, so a form can show what an unset field currently resolves to. `custom` has null tokens and means \"no preset base — the shipped theme plus whatever custom fields are set\"."
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"properties": {
"type": "object",
"properties": {
"id": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"example": {
"type": "string",
"example": "fantasy"
}
}
},
"label": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"example": {
"type": "string",
"example": "Fantasy"
}
}
},
"tokens": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"nullable": {
"type": "boolean",
"example": true
},
"additionalProperties": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
}
}
},
"example": {
"type": "object",
"properties": {
"--bg": {
"type": "string",
"example": "#1a120b"
},
"--accent": {
"type": "string",
"example": "#c9973f"
}
}
}
}
}
}
}
}
}
}
},
"colorFields": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "array"
},
"description": {
"type": "string",
"example": "Editable color fields, each paired with the CSS variable it drives."
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"properties": {
"type": "object",
"properties": {
"name": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"example": {
"type": "string",
"example": "accent"
}
}
},
"token": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"example": {
"type": "string",
"example": "--accent"
}
}
}
}
}
}
}
}
},
"radiusFields": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "array"
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"properties": {
"type": "object",
"properties": {
"name": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"example": {
"type": "string",
"example": "radiusCard"
}
}
},
"token": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
},
"example": {
"type": "string",
"example": "--radius-card"
}
}
}
}
}
}
}
}
},
"shippedTokens": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"description": {
"type": "string",
"example": "What the stylesheet declares by default — the values an unset field resolves to when no preset is selected."
},
"additionalProperties": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
}
}
}
}
},
"fonts": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"description": {
"type": "string",
"example": "Curated Google Fonts shortlist per role. Each option's `value` is the full CSS font-family stack exactly as it will be applied — the stored value, so no stack is ever built from admin input."
},
"additionalProperties": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "array"
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"properties": {
"type": "object",
"properties": {
"value": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
}
}
},
"label": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
}
}
}
}
}
}
}
}
}
}
},
"shadows": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "array"
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "object"
},
"properties": {
"type": "object",
"properties": {
"value": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
}
}
},
"label": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "string"
}
}
}
}
}
}
}
}
},
"radiusMaxPx": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "integer"
},
"example": {
"type": "number",
"example": 999
}
}
}
}
}
}
},
"DeletedId": {
"type": "object",
"properties": {

View File

@@ -748,10 +748,15 @@ const doc = {
description: { type: 'string' },
contactEmail: { type: 'string', example: '' },
url: { type: 'string', example: '' },
accent: { type: 'string', example: '#7f99bd', description: 'Seed/accent color (hex) for theming.' },
logo: { type: 'string', example: '', description: 'Logo URL or site-relative path; empty = no logo.' },
hero: { type: 'string', example: '/assets/img/runic-emblem.png', description: 'Hero image URL or site-relative path.' },
favicon: { type: 'string', example: '/assets/img/favicon.ico', description: 'Favicon URL or site-relative path.' },
accent: {
type: 'string',
example: '#7f99bd',
description:
'Seed/accent color (hex) for theming. **Effective** value: the admin theme (theme_visual) wins over BRAND_ACCENT_COLOR, so a client that themes from this tracks admin theming with no change.',
},
logo: { type: 'string', example: '', description: 'Logo URL or site-relative path; empty = no logo. An uploaded brand_assets.logo overrides BRAND_LOGO.' },
hero: { type: 'string', example: '/assets/img/runic-emblem.png', description: 'Hero image URL or site-relative path. An uploaded brand_assets.hero overrides BRAND_HERO.' },
favicon: { type: 'string', example: '/assets/img/favicon.ico', description: 'Favicon URL or site-relative path. An uploaded brand_assets.favicon overrides BRAND_FAVICON.' },
},
},
PublicSettings: {
@@ -768,6 +773,14 @@ const doc = {
},
gameAccountSignup: { type: 'boolean', example: false },
brand: { $ref: '#/components/schemas/Brand' },
theme: {
type: 'object',
nullable: true,
description:
'The effective CSS custom properties for the admin theme, resolved server-side (:root ← preset ← custom). **Absent** when the admin never set a theme, which is what makes an untouched instance render from the shipped stylesheet unchanged. Keys are CSS variable names; every value comes from a closed set (hex color, curated font stack, bounded px length, listed shadow).',
additionalProperties: { type: 'string' },
example: { '--accent': '#c9973f', '--bg': '#1a120b', '--radius-card': '2px' },
},
push: {
type: 'object',
description:
@@ -792,6 +805,70 @@ const doc = {
nav_player: { type: 'string', nullable: true, example: null },
},
},
ThemeOptions: {
type: 'object',
description:
'The closed sets an admin may choose from when theming the site (GET /settings/theme-options). Served so the admin form cannot offer a value PUT /admin/settings would reject. Static — derived from the server theme config, not the database.',
properties: {
presets: {
type: 'array',
description:
'Selectable presets and their full token maps, so a form can show what an unset field currently resolves to. `custom` has null tokens and means "no preset base — the shipped theme plus whatever custom fields are set".',
items: {
type: 'object',
properties: {
id: { type: 'string', example: 'fantasy' },
label: { type: 'string', example: 'Fantasy' },
tokens: {
type: 'object',
nullable: true,
additionalProperties: { type: 'string' },
example: { '--bg': '#1a120b', '--accent': '#c9973f' },
},
},
},
},
colorFields: {
type: 'array',
description: 'Editable color fields, each paired with the CSS variable it drives.',
items: {
type: 'object',
properties: { name: { type: 'string', example: 'accent' }, token: { type: 'string', example: '--accent' } },
},
},
radiusFields: {
type: 'array',
items: {
type: 'object',
properties: { name: { type: 'string', example: 'radiusCard' }, token: { type: 'string', example: '--radius-card' } },
},
},
shippedTokens: {
type: 'object',
description: 'What the stylesheet declares by default — the values an unset field resolves to when no preset is selected.',
additionalProperties: { type: 'string' },
},
fonts: {
type: 'object',
description: 'Curated Google Fonts shortlist per role. Each option\'s `value` is the full CSS font-family stack exactly as it will be applied — the stored value, so no stack is ever built from admin input.',
additionalProperties: {
type: 'array',
items: {
type: 'object',
properties: { value: { type: 'string' }, label: { type: 'string' } },
},
},
},
shadows: {
type: 'array',
items: {
type: 'object',
properties: { value: { type: 'string' }, label: { type: 'string' } },
},
},
radiusMaxPx: { type: 'integer', example: 999 },
},
},
// Delete/mutation acknowledgements — each echoes the affected resource key
// or a boolean flag rather than a { message } string.
DeletedId: {