feat(signage): menus play whole rounds, seconds fields with − / +, widget limit setting, widgets as big as their content (owner review 6)

- A menu board with pages plays whole rounds (menuMs rounds its seconds up); the editor says how
  long it really plays under "Seconds on screen", the card and the playlist total use it.
- Seconds on screen / per page: shared NumberInput (− / +, may be emptied: an error under the
  field and Save blocked until filled; 1 s at least, server ge=1).
- Performance (Signage -> Message & settings): widgets per slide (signage.max_widgets, 10
  recommended, up to 50), checked by the server (signage.too_many_widgets) and the editor.
- Text, clock, date, QR, weather, logo placed by hand: the box is exactly the content (its height
  x text size sets the size, the width follows; handles scale keeping the shape; text size grows
  the box); a slide's widget may run off the slide while 5 % stays on it.
- Slider: the value as close to the slider as the frame's padding; floor and table-colour sliders
  use the shared Slider. Timeline cards' ring no longer clipped; larger playlist buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 15:11:48 +02:00
co-authored by Claude Opus 5.5
parent aa3fe85053
commit aa8ba5d1d4
33 changed files with 436 additions and 75 deletions
+24 -6
View File
@@ -6,7 +6,7 @@ import { Cloud, CloudFog, CloudLightning, CloudMoon, CloudRain, CloudSnow, Cloud
import { QRCodeSVG } from 'qrcode.react'
import { BADGE_ICONS } from './badges'
import { useFormat, useTranslation } from '@xenia/i18n'
import { badgeColours, badgeName, cellWidgets, fitUnit, FONTS, itemBadges, menuLook, menuPages, pageAt, priceChars, textWidth, visibleGroups, weatherIcon, widgetAlign } from './logic'
import { badgeColours, badgeName, cellWidgets, TIGHT, fitUnit, FONTS, itemBadges, menuLook, menuPages, pageAt, priceChars, textWidth, visibleGroups, weatherIcon, widgetAlign } from './logic'
/** A slide's background: a colour, or a photo (cover / contain) with a darkening layer. */
export function Background({ bg, media }) {
@@ -165,6 +165,7 @@ const CORNER = {
'bottom-right': { bottom: '3cqmin', right: '3cqmin', alignItems: 'flex-end' },
}
const SELF = { left: 'flex-start', center: 'center', right: 'flex-end' }
const placedBy = w => (w.position === 'custom' && w.box ? (TIGHT.includes(w.kind) ? 'tight' : true) : false)
const VSELF = { top: 'flex-start', middle: 'center', bottom: 'flex-end', auto: 'center' }
/** A widget's own colour and the plate behind it (owner review 5); `pad`: a plate that hugs it. */
const plate = (w, pad) => ({
@@ -186,7 +187,7 @@ export function Widgets({ widgets, media, venue, now, colour, extras, embed }) {
const fmt = useFormat()
if (!widgets?.length) return null
const ctx = { media, venue, now, fmt, extras: extras || {}, embed }
const shown = widgets.map((w, i) => [w, i, widgetBody(w, ctx, w.position === 'custom' && !!w.box, String(i))]).filter(([, , body]) => body)
const shown = widgets.map((w, i) => [w, i, widgetBody(w, ctx, placedBy(w), String(i))]).filter(([, , body]) => body)
const bar = where => shown.filter(([w]) => w.position === where)
const bars = [['top-bar', { top: 0 }], ['bottom-bar', { bottom: 0 }]]
return (
@@ -201,6 +202,16 @@ export function Widgets({ widgets, media, venue, now, colour, extras, embed }) {
</div>
))}
{shown.filter(([w]) => CORNER[w.position] || (w.position === 'custom' && w.box)).map(([w, i, body]) => {
if (w.position === 'custom' && TIGHT.includes(w.kind)) {
// as big as what it shows, from its box's top-left corner (it may run off the slide)
return (
<div key={i} data-widget={i} className="absolute" data-testid="signage-w-box" data-tight=""
style={{ left: `${w.box.x}%`, top: `${w.box.y}%`, width: 'max-content', color: colour || '#fff', display: 'flex', flexDirection: 'column',
alignItems: SELF[widgetAlign(w)], textAlign: widgetAlign(w), ...plate(w, true) }}>
{body}
</div>
)
}
if (w.position === 'custom') {
return (
<div key={i} data-widget={i} className="absolute" data-testid="signage-w-box"
@@ -226,8 +237,10 @@ const OBJECT_POSITION = { left: 'left center', center: 'center', right: 'right c
/**
* What one widget shows, or null when it has nothing to show. Sizes are "usual units" (cqmin of
* the slide at size medium); `fit`: the widget fills its own box instead (fitUnit). `path`: the
* widget's place in the slide ("2", "2.1" inside a stack), for its extras.
* the slide at size medium); `fit`: the widget fills its place instead (fitUnit: a stack's part);
* fit 'tight' (owner review 6): placed by hand, its box is exactly its content: the box's height
* (× its text size) sets the size and its width follows. `path`: the widget's place in the slide
* ("2", "2.1.0" inside a stack), for its extras.
*/
function widgetBody(w, ctx, fit, path) {
const { media, venue, now, fmt, extras } = ctx
@@ -238,6 +251,7 @@ function widgetBody(w, ctx, fit, path) {
// in a box of its own the box sets the size: its text size can only make it smaller there
const unit = (height, width) => {
if (!fit) return n => `${+(n * s).toFixed(3)}cqmin`
if (fit === 'tight') return n => `${+(n * (w.box.h / height) * ts).toFixed(4)}cqh`
const f = fitUnit(height, width)
return n => f(n * Math.min(1, ts))
}
@@ -255,6 +269,7 @@ function widgetBody(w, ctx, fit, path) {
if (w.kind === 'logo') {
const m = media(w.media_id)
if (!m) return null
if (fit === 'tight') return <img src={m.src} alt="" style={{ height: `${+(w.box.h * ts).toFixed(4)}cqh`, width: 'auto', display: 'block' }} data-testid="signage-w-logo" />
return fit
? <img src={m.src} alt="" style={{ width: '100%', height: '100%', objectFit: 'contain', objectPosition: OBJECT_POSITION[widgetAlign(w)] }} data-testid="signage-w-logo" />
: <img src={m.src} alt="" style={{ height: `${9 * s}cqmin`, maxWidth: `${30 * s}cqmin`, objectFit: 'contain' }} data-testid="signage-w-logo" />
@@ -381,12 +396,15 @@ function Stack({ w, path, ctx }) {
const wp = `${cp}.${k}`
const own = cw.position === 'custom' && cw.box
const align = cw.align && cw.align !== 'auto' ? cw.align : 'center'
const body = widgetBody(cw, ctx, true, wp)
const body = widgetBody(cw, ctx, own && TIGHT.includes(cw.kind) ? 'tight' : true, wp)
return (
<div key={k} style={{ flex: '1 1 0%', minWidth: 0, minHeight: 0, overflow: 'hidden', containerType: 'size', position: 'relative',
...(own ? {} : { display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align }) }}
data-testid="signage-stack-place" data-place={wp}>
{body && (own ? (
{body && (own && TIGHT.includes(cw.kind) ? (
<div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: 'max-content', display: 'flex', flexDirection: 'column',
alignItems: SELF[align], textAlign: align, ...plate(cw, true) }} data-testid="signage-w-box" data-tight="">{body}</div>
) : own ? (
<div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: `${cw.box.w}%`, height: `${cw.box.h}%`,
containerType: 'size', display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align, ...plate(cw) }}
data-testid="signage-w-box">{body}</div>
+11 -4
View File
@@ -130,7 +130,7 @@ export function nextSlide(slides, current, local) {
/** How long a slide stays, in ms; null = until its video ends (with a safety limit in the player). */
export function slideMs(slide) {
if (slide.kind === 'video' && slide.video_to_end) return null
return Math.max(2, slide.duration_s || 10) * 1000
return Math.max(1, slide.duration_s || 10) * 1000
}
/** The frame's size and turn for a screen: CSS for the box that holds the slides. */
@@ -215,14 +215,17 @@ export function menuPages(groups, perPage, headings = true) {
/** A menu slide's time: every page for its seconds, at least the slide's own time. */
export function menuMs(slide, pageCount) {
const per = Math.max(3, slide.content?.page_seconds || 10) * 1000
return Math.max(slideMs(slide), pageCount > 1 ? pageCount * per : 0)
// owner review 6 (2026-11-21): a board with pages plays whole rounds of them, never cut in the
// middle: its seconds on screen rounded up to the next full round (10 s, 2 pages of 3 s → 12 s)
if (!(pageCount > 1)) return slideMs(slide)
const round = pageCount * Math.max(1, slide.content?.page_seconds || 10) * 1000
return Math.max(1, Math.ceil(slideMs(slide) / round)) * round
}
/** The page on screen `elapsedMs` into the slide (the pages go round while the slide lasts). */
export function pageAt(pageCount, pageSeconds, elapsedMs) {
if (pageCount <= 1 || !(elapsedMs > 0)) return 0 // the clock's last tick may be just before the slide began
return Math.floor(elapsedMs / (Math.max(3, pageSeconds || 10) * 1000)) % pageCount // round and round while the slide lasts
return Math.floor(elapsedMs / (Math.max(1, pageSeconds || 10) * 1000)) % pageCount // round and round while the slide lasts
}
/** A weather code (WMO, as Open-Meteo sends it) → an icon name for the widget. */
@@ -258,6 +261,10 @@ export function visibleGroups(groups) {
// ── widgets placed by hand (owner 2026-11-21) ─────────────────────────────────
/** Widgets whose box, placed by hand, is exactly their content (owner review 6): its height (× the
* widget's text size) sets the size, its width follows. A menu or a stack fills its box. */
export const TIGHT = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather']
/** The slide kinds that carry widgets. */
export const WIDGET_HOSTS = ['text', 'menu', 'blank']
+5
View File
@@ -101,6 +101,11 @@ test('a menu slide stays for all its pages; the page on screen', () => {
const slide = { kind: 'menu', duration_s: 10, content: { page_seconds: 8 } }
assert.equal(menuMs(slide, 1), 10_000)
assert.equal(menuMs(slide, 3), 24_000)
// owner review 6: whole rounds only (10 s, 2 pages of 3 s → 2 rounds of 6 s = 12 s; 7 s of 2 × 3 s → 12 s; 12 s → 12 s)
assert.equal(menuMs({ kind: 'menu', duration_s: 10, content: { page_seconds: 3 } }, 2), 12_000)
assert.equal(menuMs({ kind: 'menu', duration_s: 7, content: { page_seconds: 3 } }, 2), 12_000)
assert.equal(menuMs({ kind: 'menu', duration_s: 12, content: { page_seconds: 3 } }, 2), 12_000)
assert.equal(menuMs({ kind: 'menu', duration_s: 2, content: { page_seconds: 5 } }, 3), 15_000)
assert.equal(pageAt(3, 8, 0), 0)
assert.equal(pageAt(3, 8, 8_100), 1)
assert.equal(pageAt(3, 8, 16_500), 2)