feat(signage): stacks, menu and text widgets, widget order (owner review 2)

- Stacks: horizontal / vertical, 2-6 parts with % shares; each part shows
  a widget, a stack one level deep, or a whole Slides-library slide
- Menu widget (a board's list in its box), text widget, weather for
  tomorrow / the day after and in picture / degrees / both styles
- Widgets' order (arrows, drag with a drop line), drawn in list order;
  arrow keys move the picked widget from its card too
- Server: extras by widget path (QR links, menus, embedded slides),
  POST /preview/slide, resolve(keep_hidden) so hidden products stay
  greyed in the editor's list; screens told when an embedded slide changes
- Editor rows tidied: framed sliders, colours as fields, text look on one
  row, Switch boxed toggles from its whole frame

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 09:44:23 +02:00
co-authored by Claude Opus 5.5
parent 83551714f7
commit 1b993e4573
23 changed files with 1231 additions and 377 deletions
+33 -4
View File
@@ -1,21 +1,50 @@
// One slide as a TV shows it (plan step 5.6a): picture, video, text, menu board or blank (2026-11-21). Used by the
// player (terminal) and the manager's previews. Needs a parent with `container-type: size`.
// media(id) → { src, url, kind, width, height } | null (src: the address or the TV's kept copy)
import { useEffect, useRef } from 'react'
// slide.extras: what the server added to its widgets by path (QR links, menus, slides inside stacks)
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { boardPages, pageAt } from './logic.js'
import { BlankSlide, MenuSlide, TextSlide } from './Slides.jsx'
export function SlideView({ slide, media, venue, now, pages, page, onEnded, playing = true }) {
const x = slide.extras
return (
<>
{slide.kind === 'image' && <ImageSlide content={slide.content || {}} media={media} />}
{slide.kind === 'video' && <VideoSlide slide={slide} media={media} onEnded={onEnded} playing={playing} />}
{slide.kind === 'text' && <TextSlide content={slide.content || {}} media={media} venue={venue} now={now} />}
{slide.kind === 'blank' && <BlankSlide content={slide.content || {}} media={media} venue={venue} now={now} />}
{slide.kind === 'menu' && <MenuSlide slide={slide} media={media} venue={venue} now={now} pages={pages || []} page={page || 0} />}
{slide.kind === 'text' && <TextSlide content={slide.content || {}} media={media} venue={venue} now={now} extras={x} embed={EmbeddedSlide} />}
{slide.kind === 'blank' && <BlankSlide content={slide.content || {}} media={media} venue={venue} now={now} extras={x} embed={EmbeddedSlide} />}
{slide.kind === 'menu' && <MenuSlide slide={slide} media={media} venue={venue} now={now} pages={pages || []} page={page || 0} extras={x} embed={EmbeddedSlide} />}
</>
)
}
/**
* A library slide drawn whole inside a stack's part (2026-11-21): scaled to the part (its sizes
* are the part's container units); a menu board pages by the clock for the part's own size, a
* video loops.
*/
function EmbeddedSlide({ slide, media, venue, now }) {
const ref = useRef(null)
const [size, setSize] = useState(null)
useLayoutEffect(() => {
const el = ref.current
if (!el) return undefined
const measure = () => setSize(s => (s && s.w === el.clientWidth && s.h === el.clientHeight ? s : { w: el.clientWidth, h: el.clientHeight }))
measure()
const ro = new ResizeObserver(measure)
ro.observe(el)
return () => ro.disconnect()
}, [])
const pages = slide.kind === 'menu' && size ? boardPages(slide, 0, size.w || 16, size.h || 9) : null
const page = pages ? pageAt(pages.length, slide.content?.page_seconds, now.getTime()) : 0
return (
<div ref={ref} style={{ position: 'absolute', inset: 0, overflow: 'hidden', containerType: 'size' }} data-testid="signage-embedded" data-kind={slide.kind} data-id={slide.id}>
{size && <SlideView slide={{ ...slide, video_to_end: false }} media={media} venue={venue} now={now} pages={pages} page={page} />}
</div>
)
}
function ImageSlide({ content, media }) {
const m = content.media_id ? media(content.media_id) : null
return (
+195 -100
View File
@@ -5,7 +5,7 @@
import { Cloud, CloudFog, CloudLightning, CloudMoon, CloudRain, CloudSnow, CloudSun, Moon, Sun } from 'lucide-react'
import { QRCodeSVG } from 'qrcode.react'
import { useFormat, useTranslation } from '@xenia/i18n'
import { fitUnit, FONTS, textWidth, weatherIcon, widgetAlign } from './logic'
import { fitUnit, FONTS, menuPages, pageAt, 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 }) {
@@ -22,7 +22,7 @@ const JUSTIFY = { top: 'flex-start', middle: 'center', bottom: 'flex-end' }
const BOARD_ALIGN = { left: 'flex-start', center: 'center', right: 'flex-end' }
const hasBar = (c, where) => (c.widgets || []).some(w => w.position === where)
export function TextSlide({ content: c, media, venue, now }) {
export function TextSlide({ content: c, media, venue, now, extras, embed }) {
const scale = (c.text_size || 100) / 100
return (
<div className="absolute inset-0" style={{ color: c.text_colour || '#fff', fontFamily: FONTS[c.font] || FONTS.sans }}>
@@ -34,25 +34,23 @@ export function TextSlide({ content: c, media, venue, now }) {
{c.title && <h1 style={{ fontSize: `${9 * scale}cqmin`, lineHeight: 1.1, fontWeight: 800, margin: 0 }} data-testid="signage-title">{c.title}</h1>}
{c.body && <p style={{ fontSize: `${4.5 * scale}cqmin`, lineHeight: 1.35, margin: 0, whiteSpace: 'pre-line' }} data-testid="signage-body">{c.body}</p>}
</div>
<Widgets widgets={c.widgets} media={media} venue={venue} now={now} colour={c.text_colour} />
<Widgets widgets={c.widgets} media={media} venue={venue} now={now} colour={c.text_colour} extras={extras} embed={embed} />
</div>
)
}
/** A blank slide (2026-11-21): its background and its widgets, nothing else. */
export function BlankSlide({ content: c, media, venue, now }) {
export function BlankSlide({ content: c, media, venue, now, extras, embed }) {
return (
<div className="absolute inset-0" data-testid="signage-blank">
<Background bg={c.background} media={media} />
<Widgets widgets={c.widgets} media={media} venue={venue} now={now} />
<Widgets widgets={c.widgets} media={media} venue={venue} now={now} extras={extras} embed={embed} />
</div>
)
}
/** A menu board (5.5b): its page of items (pages flip on their own), photos, descriptions, badges, sold out. */
export function MenuSlide({ slide, media, venue, now, page, pages }) {
const { t } = useTranslation('terminal')
const { formatMoney } = useFormat()
export function MenuSlide({ slide, media, venue, now, page, pages, extras, embed }) {
const c = slide.content
const scale = (c.text_size || 100) / 100
const accent = c.accent_colour || '#f59e0b'
@@ -66,54 +64,64 @@ export function MenuSlide({ slide, media, venue, now, page, pages }) {
{/* the list: the whole width, or narrower and placed left / centre / right (2026-11-21) */}
<div style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column', width: `${c.board_width || 100}%`,
alignSelf: BOARD_ALIGN[c.board_align] || 'flex-start' }} data-testid="signage-menu-board" data-align={c.board_align || 'left'}>
{c.title && <h1 style={{ fontSize: `${7 * scale}cqmin`, fontWeight: 800, margin: '0 0 2cqmin', color: accent, lineHeight: 1.1,
textAlign: c.board_align || 'left' }}>{c.title}</h1>}
<div style={{ columnCount: c.columns || 2, columnGap: '5cqmin', fontSize: `${3.2 * scale}cqmin`, flex: 1, columnFill: 'auto' }}>
{groups.map((g, i) => (
<div key={`${g.category?.id ?? 'all'}-${i}`} style={{ marginBottom: '1.6cqmin' }}>
{g.category && c.category_titles !== false && (
<h2 style={{ fontSize: '1.15em', color: accent, margin: '0 0 0.6cqmin', fontWeight: 700, breakAfter: 'avoid' }}
data-testid="signage-menu-heading">{g.category.name}</h2>
)}
{g.items.map(it => (
<div key={it.id} data-testid="signage-menu-item" data-id={it.id} data-available={it.available ? 'true' : 'false'}
style={{ display: 'flex', alignItems: 'center', gap: '1.5cqmin', breakInside: 'avoid', padding: '0.5cqmin 0',
opacity: it.available ? 1 : 0.5 }}>
{c.show_photos && (it.image
? <img src={it.image} alt="" style={{ width: '7cqmin', height: '7cqmin', objectFit: 'cover', borderRadius: '1cqmin', flexShrink: 0 }} />
: <span style={{ width: '7cqmin', height: '7cqmin', flexShrink: 0 }} />)}
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: '1cqmin' }}>
<span style={{ textDecoration: it.available ? 'none' : 'line-through', fontWeight: 600 }}>{it.name}</span>
{it.badge && (
<span style={{ background: accent, color: '#111', fontSize: '0.55em', fontWeight: 800, padding: '0.2cqmin 0.9cqmin', borderRadius: '99cqmin',
textTransform: 'uppercase', letterSpacing: '0.05em', whiteSpace: 'nowrap' }} data-testid="signage-badge">{t(`signage.badges.${it.badge}`)}</span>
)}
{!it.available && <span style={{ fontSize: '0.6em', whiteSpace: 'nowrap' }} data-testid="signage-sold-out">{t('signage.soldOut')}</span>}
<span style={{ flex: 1, borderBottom: '0.25cqmin dotted currentColor', opacity: 0.35, minWidth: '2cqmin' }} />
{it.price != null && <span style={{ color: accent, fontVariantNumeric: 'tabular-nums', fontWeight: 700, whiteSpace: 'nowrap' }}
data-testid="signage-menu-price">{formatMoney(it.price)}</span>}
</div>
{it.description && <div style={{ fontSize: '0.7em', opacity: 0.75, lineHeight: 1.25 }}>{it.description}</div>}
</div>
</div>
))}
</div>
))}
</div>
{pages.length > 1 && (
<div style={{ display: 'flex', gap: '1cqmin', justifyContent: 'center', paddingTop: '1cqmin' }} aria-hidden="true">
{pages.map((_, i) => <span key={i} style={{ width: '1.2cqmin', height: '1.2cqmin', borderRadius: '50%', background: i === page ? accent : 'currentColor', opacity: i === page ? 1 : 0.3 }} />)}
{c.title && <h1 style={{ fontSize: `${7 * scale}cqmin`, fontWeight: 800, margin: '0 0 2cqmin', color: accent, lineHeight: 1.1,
textAlign: c.board_align || 'left' }}>{c.title}</h1>}
<div style={{ columnCount: c.columns || 2, columnGap: '5cqmin', fontSize: `${3.2 * scale}cqmin`, flex: 1, columnFill: 'auto' }}>
<MenuGroups c={c} groups={groups} accent={accent} />
</div>
)}
{pages.length > 1 && (
<div style={{ display: 'flex', gap: '1cqmin', justifyContent: 'center', paddingTop: '1cqmin' }} aria-hidden="true">
{pages.map((_, i) => <span key={i} style={{ width: '1.2cqmin', height: '1.2cqmin', borderRadius: '50%', background: i === page ? accent : 'currentColor', opacity: i === page ? 1 : 0.3 }} />)}
</div>
)}
</div>
</div>
<Widgets widgets={c.widgets} media={media} venue={venue} now={now} colour={c.text_colour} />
<Widgets widgets={c.widgets} media={media} venue={venue} now={now} colour={c.text_colour} extras={extras} embed={embed} />
</div>
)
}
// ── widgets (5.5b; placed by hand on the editor's preview, owner 2026-11-21) ────
/**
* A board's groups of items (a menu slide's page, a menu widget's page). Sizes are em of the
* list's text, so the same rows fit a whole screen or a widget's box.
*/
export function MenuGroups({ c, groups, accent }) {
const { t } = useTranslation('terminal')
const { formatMoney } = useFormat()
return groups.map((g, i) => (
<div key={`${g.category?.id ?? 'all'}-${i}`} style={{ marginBottom: '0.5em' }}>
{g.category && c.category_titles !== false && (
<h2 style={{ fontSize: '1.15em', color: accent, margin: '0 0 0.19em', fontWeight: 700, breakAfter: 'avoid' }}
data-testid="signage-menu-heading">{g.category.name}</h2>
)}
{g.items.map(it => (
<div key={it.id} data-testid="signage-menu-item" data-id={it.id} data-available={it.available ? 'true' : 'false'}
style={{ display: 'flex', alignItems: 'center', gap: '0.47em', breakInside: 'avoid', padding: '0.16em 0',
opacity: it.available ? 1 : 0.5 }}>
{c.show_photos && (it.image
? <img src={it.image} alt="" style={{ width: '2.2em', height: '2.2em', objectFit: 'cover', borderRadius: '0.3em', flexShrink: 0 }} />
: <span style={{ width: '2.2em', height: '2.2em', flexShrink: 0 }} />)}
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: '0.3em' }}>
<span style={{ textDecoration: it.available ? 'none' : 'line-through', fontWeight: 600 }}>{it.name}</span>
{it.badge && (
<span style={{ background: accent, color: '#111', fontSize: '0.55em', fontWeight: 800, padding: '0.1em 0.5em', borderRadius: '99em',
textTransform: 'uppercase', letterSpacing: '0.05em', whiteSpace: 'nowrap' }} data-testid="signage-badge">{t(`signage.badges.${it.badge}`)}</span>
)}
{!it.available && <span style={{ fontSize: '0.6em', whiteSpace: 'nowrap' }} data-testid="signage-sold-out">{t('signage.soldOut')}</span>}
<span style={{ flex: 1, borderBottom: '0.08em dotted currentColor', opacity: 0.35, minWidth: '0.6em' }} />
{it.price != null && <span style={{ color: accent, fontVariantNumeric: 'tabular-nums', fontWeight: 700, whiteSpace: 'nowrap' }}
data-testid="signage-menu-price">{formatMoney(it.price)}</span>}
</div>
{it.description && <div style={{ fontSize: '0.7em', opacity: 0.75, lineHeight: 1.25 }}>{it.description}</div>}
</div>
</div>
))}
</div>
))
}
// ── widgets (5.5b; placed by hand on the editor's preview, text / menu / stacks: owner 2026-11-21) ──
const SIZE = { small: 0.75, medium: 1, large: 1.4 }
const CORNER = {
@@ -125,17 +133,22 @@ const CORNER = {
'bottom-right': { bottom: '3cqmin', right: '3cqmin', alignItems: 'flex-end' },
}
const SELF = { left: 'flex-start', center: 'center', right: 'flex-end' }
// a menu or a stack in a corner or a bar has no box of its own: it gets one of this size (cqmin)
const BOXED = { menu: [48, 56], stack: [60, 36] }
/**
* The widgets of a slide: in their corners and bars, or (moved and sized by hand: position
* "custom") each in its own box, scaled to fill it. One that has nothing to show is left out.
* Each carries `data-widget` = its index in the slide's list (the editor's handles find it so).
* "custom") each in its own box, scaled to fill it; drawn in the list's order (a later one lies
* over an earlier one). One that has nothing to show is left out. Each carries `data-widget` = its
* index in the slide's list (the editor's handles find it so). `extras`: what the server added by
* widget path (QR links, a menu widget's products, a stack part's library slide); `embed`: draws a
* slide inside a stack's part (SlideView passes it).
*/
export function Widgets({ widgets, media, venue, now, colour }) {
export function Widgets({ widgets, media, venue, now, colour, extras, embed }) {
const fmt = useFormat()
if (!widgets?.length) return null
const ctx = { media, venue, now, fmt }
const shown = widgets.map((w, i) => [w, i, widgetBody(w, ctx, w.position === 'custom' && !!w.box)]).filter(([, , body]) => body)
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 bar = where => shown.filter(([w]) => w.position === where)
const bars = [['top-bar', { top: 0 }], ['bottom-bar', { bottom: 0 }]]
return (
@@ -149,22 +162,24 @@ export function Widgets({ widgets, media, venue, now, colour }) {
))}
</div>
))}
{shown.filter(([w]) => CORNER[w.position]).map(([w, i, body]) => {
{shown.filter(([w]) => CORNER[w.position] || (w.position === 'custom' && w.box)).map(([w, i, body]) => {
if (w.position === 'custom') {
return (
<div key={i} data-widget={i} className="absolute" data-testid="signage-w-box"
style={{ left: `${w.box.x}%`, top: `${w.box.y}%`, width: `${w.box.w}%`, height: `${w.box.h}%`, containerType: 'size', color: colour || '#fff' }}>
<div style={{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: SELF[widgetAlign(w)], textAlign: widgetAlign(w) }}>
{body}
</div>
</div>
)
}
const own = w.align && w.align !== 'auto' ? { alignItems: SELF[w.align], textAlign: w.align } : {}
return (
<div key={`c${i}`} data-widget={i} className="absolute" style={{ ...CORNER[w.position], ...own, display: 'flex', flexDirection: 'column', color: colour || '#fff' }}>
<div key={i} data-widget={i} className="absolute" style={{ ...CORNER[w.position], ...own, display: 'flex', flexDirection: 'column', color: colour || '#fff' }}>
{body}
</div>
)
})}
{shown.filter(([w]) => w.position === 'custom' && w.box).map(([w, i, body]) => (
<div key={`b${i}`} data-widget={i} className="absolute" data-testid="signage-w-box"
style={{ left: `${w.box.x}%`, top: `${w.box.y}%`, width: `${w.box.w}%`, height: `${w.box.h}%`, containerType: 'size', color: colour || '#fff' }}>
<div style={{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: SELF[widgetAlign(w)], textAlign: widgetAlign(w) }}>
{body}
</div>
</div>
))}
</>
)
}
@@ -173,14 +188,25 @@ 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).
* 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.
*/
function widgetBody(w, { media, venue, now, fmt }, fit) {
function widgetBody(w, ctx, fit, path) {
const { media, venue, now, fmt, extras } = ctx
const { formatDate, formatTime } = fmt
const x = extras[path] || {}
const s = SIZE[w.size] || 1
const unit = (height, width) => (fit ? fitUnit(height, width) : n => `${+(n * s).toFixed(3)}cqmin`)
const text = (u, size, weight = 700) => ({ fontSize: u(size), fontWeight: weight, lineHeight: 1.15,
textShadow: '0 0.2cqmin 0.8cqmin rgba(0,0,0,0.35)', whiteSpace: fit ? 'nowrap' : undefined })
const line = (str, testid, weight) => {
const u = unit(3.4 * 1.15, textWidth(str.length, 3.4))
return <span style={text(u, 3.4, weight)} data-testid={testid}>{str}</span>
}
// a menu or a stack fills a box: its own, or (in a corner / bar) one of a usual size
const boxed = (body, kind) => (fit ? body : (
<div style={{ width: `${BOXED[kind][0] * s}cqmin`, height: `${BOXED[kind][1] * s}cqmin`, containerType: 'size' }}>{body}</div>
))
if (w.kind === 'logo') {
const m = media(w.media_id)
if (!m) return null
@@ -193,58 +219,127 @@ function widgetBody(w, { media, venue, now, fmt }, fit) {
const u = unit(4.2 * 1.15, textWidth(venue.name.length, 4.2))
return <span style={text(u, 4.2)} data-testid="signage-w-name">{venue.name}</span>
}
if (w.kind === 'date') {
const str = formatDate(now, w.date_style === 'short' ? 'date' : 'dateLong')
const u = unit(3.4 * 1.15, textWidth(str.length, 3.4))
return <span style={text(u, 3.4)} data-testid="signage-w-date">{str}</span>
}
if (w.kind === 'date') return line(formatDate(now, w.date_style === 'short' ? 'date' : 'dateLong'), 'signage-w-date')
if (w.kind === 'clock') {
const u = unit(4.6 * 1.15, textWidth(w.clock_seconds ? 8 : 5, 4.6)) // its usual width: the size stays as the minutes turn
return <span style={{ ...text(u, 4.6), fontVariantNumeric: 'tabular-nums' }} data-testid="signage-w-clock">{formatTime(now, w.clock_seconds ? 'timeSeconds' : 'time')}</span>
}
if (w.kind === 'message') {
const msg = w.text || venue?.message
if (!msg) return null
const u = unit(3.4 * 1.15, textWidth(msg.length, 3.4))
return <span style={text(u, 3.4, 600)} data-testid="signage-w-message">{msg}</span>
return msg ? line(msg, 'signage-w-message', 600) : null
}
if (w.kind === 'text') return w.text ? line(w.text, 'signage-w-text', 600) : null
if (w.kind === 'qr') {
if (!w.link) return null
const link = x.link || w.link
if (!link) return null
const caption = w.qr_caption ? 2.4 * 1.15 + 0.8 : 0
const u = unit(16 + caption, Math.max(16, w.qr_caption ? textWidth(w.qr_caption.length, 2.4) : 0))
return (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: u(0.8) }} data-testid="signage-w-qr" data-link={w.link}>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: u(0.8) }} data-testid="signage-w-qr" data-link={link}>
<div style={{ background: '#fff', padding: u(1), borderRadius: u(1), lineHeight: 0 }}>
<QRCodeSVG value={w.link} size={256} style={{ width: u(14), height: u(14) }} />
<QRCodeSVG value={link} size={256} style={{ width: u(14), height: u(14) }} />
</div>
{w.qr_caption && <span style={text(u, 2.4)}>{w.qr_caption}</span>}
</div>
)
}
if (w.kind === 'weather') {
const wx = venue?.weather
if (!wx || wx.temperature == null) return null // no internet / no place: hidden (5.4c)
const Icon = ICONS[weatherIcon(wx.code, wx.is_day)] || Cloud
const deg = wx.units === 'fahrenheit' ? '°F' : '°C'
const days = (w.weather_days || 1) > 1 ? (wx.days || []).slice(1, w.weather_days) : []
const u = unit(6, 6 + 1.5 + textWidth(4, 4.4) + days.length * (1.5 + 3.4 + textWidth(12, 2.4)))
return (
<div style={{ display: 'flex', alignItems: 'center', gap: u(1.5) }} data-testid="signage-w-weather">
<Icon style={{ width: u(6), height: u(6), flexShrink: 0 }} aria-hidden="true" />
<span style={text(u, 4.4)}>{Math.round(wx.temperature)}{deg}</span>
{days.map(d => {
const DayIcon = ICONS[weatherIcon(d.code, true)] || Cloud
return (
<span key={d.date} style={{ display: 'flex', alignItems: 'center', gap: u(0.6), ...text(u, 2.4, 600) }}>
{formatDate(`${d.date}T12:00:00Z`, 'weekday').slice(0, 3)} <DayIcon style={{ width: u(3.4), height: u(3.4) }} aria-hidden="true" />
{Math.round(d.max)}° / {Math.round(d.min)}°
</span>
)
})}
</div>
)
}
if (w.kind === 'weather') return weatherBody(w, venue?.weather, unit, text, formatDate)
if (w.kind === 'menu') return boxed(<MenuWidget board={w.board || {}} menu={x.menu} now={now} />, 'menu')
if (w.kind === 'stack') return boxed(<Stack w={w} path={path} ctx={ctx} />, 'stack')
return null
}
/** The weather: now or a day of the forecast (today, tomorrow, the day after), and the next days;
* its picture and degrees, only the picture or only the degrees (2026-11-21). */
function weatherBody(w, wx, unit, text, formatDate) {
if (!wx || wx.temperature == null) return null // no internet / no place: hidden (5.4c)
const from = w.weather_from || 0
const style = w.weather_style || 'both'
const pic = style !== 'text'
const deg = style !== 'icon'
const unitMark = wx.units === 'fahrenheit' ? '°F' : '°C'
const days = wx.days || []
const dayName = d => formatDate(`${d.date}T12:00:00Z`, 'weekday').slice(0, 3)
const main = from === 0
? { icon: weatherIcon(wx.code, wx.is_day), label: `${Math.round(wx.temperature)}${unitMark}` }
: days[from] && { icon: weatherIcon(days[from].code, true), label: `${dayName(days[from])} ${Math.round(days[from].max)}° / ${Math.round(days[from].min)}°` }
if (!main) return null
const rest = days.slice(from + 1, from + (w.weather_days || 1))
const restText = d => `${Math.round(d.max)}° / ${Math.round(d.min)}°`
const u = unit(6, (pic ? 6 + 1.5 : 0) + (deg ? textWidth(main.label.length, 4.4) : 0)
+ rest.length * (1.5 + (pic ? 3.4 : 0) + textWidth(4 + (deg ? 11 : 0), 2.4)))
const MainIcon = ICONS[main.icon] || Cloud
return (
<div style={{ display: 'flex', alignItems: 'center', gap: u(1.5) }} data-testid="signage-w-weather" data-style={style} data-from={from}>
{pic && <MainIcon style={{ width: u(6), height: u(6), flexShrink: 0 }} aria-hidden="true" />}
{deg && <span style={text(u, 4.4)}>{main.label}</span>}
{rest.map(d => {
const DayIcon = ICONS[weatherIcon(d.code, true)] || Cloud
return (
<span key={d.date} style={{ display: 'flex', alignItems: 'center', gap: u(0.6), ...text(u, 2.4, 600) }}>
{dayName(d)} {pic && <DayIcon style={{ width: u(3.4), height: u(3.4) }} aria-hidden="true" />}
{deg && restText(d)}
</span>
)
})}
</div>
)
}
/**
* A menu widget (2026-11-21): a board's list in the widget's box (inside an element with
* `container-type: size`), its pages turning on the clock; the text sized so a page fills the box.
*/
function MenuWidget({ board: b, menu, now }) {
const groups = visibleGroups(menu?.groups)
const per = b.page_size || 8
const headings = b.category_titles !== false
const pages = menuPages(groups, per, headings)
const page = pageAt(pages.length, b.page_seconds, now.getTime())
const cols = b.columns || 1
const scale = (b.text_size || 100) / 100
const rowH = b.show_photos ? 2.6 : b.show_descriptions ? 2.1 : 1.5
const lines = Math.ceil(per / cols) + (headings ? 1 : 0)
const fontSize = `calc(${scale} * min(${(100 / (lines * rowH + (b.title ? 2 : 0) + 0.8)).toFixed(3)}cqh, ${(100 / (cols * 15)).toFixed(3)}cqw))`
const accent = b.accent_colour || '#f59e0b'
return (
<div style={{ width: '100%', height: '100%', overflow: 'hidden', fontSize, color: b.text_colour || '#fff', fontFamily: FONTS[b.font] || FONTS.sans, textAlign: 'left' }}
data-testid="signage-w-menu" data-page={page} data-pages={pages.length}>
{b.title && <div style={{ fontSize: '1.5em', fontWeight: 800, color: accent, lineHeight: 1.15, marginBottom: '0.3em' }}>{b.title}</div>}
<div style={{ columnCount: cols, columnGap: '1.2em', columnFill: 'auto' }}>
<MenuGroups c={b} groups={pages[page] || []} accent={accent} />
</div>
</div>
)
}
/**
* A stack (2026-11-21): parts side by side ("row") or one over the other ("column"), each its share
* of the stack, showing a widget (filling the part) or a whole library slide.
*/
function Stack({ w, path, ctx }) {
const cells = w.cells || []
const Embed = ctx.embed
return (
<div style={{ display: 'flex', flexDirection: w.direction === 'column' ? 'column' : 'row', width: '100%', height: '100%' }}
data-testid="signage-w-stack" data-direction={w.direction || 'row'}>
{cells.map((c, j) => {
const cp = `${path}.${j}`
const slide = c.slide_id ? ctx.extras[cp]?.slide : null
const body = c.widget ? widgetBody(c.widget, ctx, true, cp) : null
const align = c.widget?.align && c.widget.align !== 'auto' ? c.widget.align : 'center'
return (
<div key={j} style={{ flex: `${c.share || 1} 1 0%`, minWidth: 0, minHeight: 0, position: 'relative', overflow: 'hidden', containerType: 'size' }}
data-testid="signage-stack-cell" data-share={c.share}>
{body && (
<div style={{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: SELF[align], textAlign: align }}>{body}</div>
)}
{slide && Embed && <Embed slide={slide} media={ctx.media} venue={ctx.venue} now={ctx.now} />}
</div>
)
})}
</div>
)
}
const ICONS = { sun: Sun, moon: Moon, 'cloud-sun': CloudSun, 'cloud-moon': CloudMoon, cloud: Cloud, fog: CloudFog, rain: CloudRain, snow: CloudSnow, storm: CloudLightning }
+29 -1
View File
@@ -246,7 +246,13 @@ export function boardPages(slide, rotation, w, h) {
const rows = rowsPerColumn({ heightVmin: frameHeightVmin(rotation, w, h), textSize: c.text_size, photos: c.show_photos,
descriptions: c.show_descriptions, title: !!c.title, bars })
const per = c.page_size || rows * (c.columns || 2)
return menuPages(slide.menu?.groups || [], per, c.category_titles !== false)
return menuPages(visibleGroups(slide.menu?.groups), per, c.category_titles !== false)
}
/** A board's groups without the products hidden from it (the editor's list keeps them, marked
* `hidden`, 2026-11-21); groups left empty go too. */
export function visibleGroups(groups) {
return (groups || []).map(g => ({ ...g, items: (g.items || []).filter(i => !i.hidden) })).filter(g => g.items.length)
}
// ── widgets placed by hand (owner 2026-11-21) ─────────────────────────────────
@@ -254,6 +260,28 @@ export function boardPages(slide, rotation, w, h) {
/** The slide kinds that carry widgets. */
export const WIDGET_HOSTS = ['text', 'menu', 'blank']
/** A stack's parts' shares as whole percents adding up to 100 (2026-11-21). */
export function evenShares(n) {
const base = Math.floor(100 / n)
return Array.from({ length: n }, (_, i) => (i < 100 - base * n ? base + 1 : base))
}
/**
* A stack's part `i` set to `value` % (5…): the difference is taken from (or given to) the part
* after it (the one before, for the last part), which keeps at least 5 %; the shares still add up
* to 100. → the new shares.
*/
export function setShare(shares, i, value) {
const out = [...shares]
if (out.length < 2) return [100]
const j = i < out.length - 1 ? i + 1 : i - 1
const room = out[i] + out[j] - 5
const v = Math.max(5, Math.min(room, Math.round(Number(value) || 0)))
out[j] = out[i] + out[j] - v
out[i] = v
return out
}
/** How a widget lines up inside its place: its own choice, else by its corner / its box's side. */
export function widgetAlign(w) {
if (w?.align && w.align !== 'auto') return w.align
+13
View File
@@ -155,3 +155,16 @@ test('a screen whose default is a library slide plays it when no line matches',
playlists: { 1: { id: 1, slides: [] }, 'slide:3': one } }
assert.equal(playlistNow(data, new Date('2026-11-21T12:00:00Z')), one)
})
test('stacks: even shares and a part resized against its neighbour; hidden products never on the TV (2026-11-21)', async () => {
const { boardPages, evenShares, setShare, visibleGroups } = await import('../src/logic.js')
assert.deepEqual(evenShares(3), [34, 33, 33])
assert.deepEqual(evenShares(2), [50, 50])
assert.deepEqual(setShare([50, 50], 0, 25), [25, 75])
assert.deepEqual(setShare([25, 25, 50], 2, 70), [25, 5, 70]) // the last part takes from the one before
assert.deepEqual(setShare([50, 50], 1, 99), [5, 95]) // its neighbour keeps 5 %
const groups = [{ category: { id: 1 }, items: [{ id: 1, hidden: true }] }, { category: { id: 2 }, items: [{ id: 2 }, { id: 3, hidden: true }] }]
assert.deepEqual(visibleGroups(groups), [{ category: { id: 2 }, items: [{ id: 2 }] }])
const pages = boardPages({ content: { columns: 1 }, menu: { groups } }, 0, 1920, 1080)
assert.deepEqual(pages.flat().flatMap(g => g.items.map(i => i.id)), [2])
})