feat(signage): Slides library, widgets placed on the preview, blank slides, slide editor rework

- Slides library (Alembic 0044, /api/signage/library): slides kept with a name and a
  description, added to playlists as copies ("Add a slide" → Your slides, "Keep in Slides"),
  or shown alone as a screen's default (device config `slide`, played as "slide:<id>",
  also as a schedule's fallback). Signage → Slides: gallery + a two-pane editor.
- Widgets moved and sized by hand on the preview (WidgetCanvas: handles, snapping, arrow
  keys): position/size "custom" with a box the TV draws the same; alignment per widget.
- Blank slides (background + widgets); menu boards narrower and placed left/centre/right.
- Slide editor reworked: name | show, transition effect | seconds; sections; text look on
  one row with ready colours; one card per widget, settings on one row.
- Questions inside the page (@xenia/ui ConfirmDialog/useConfirm), Switch boxed, Segmented
  fill; the timeline's drop line; schedule lines run on weekdays or smart days, not both;
  the playlist editor stays within 1080p with a long timeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 07:53:27 +02:00
co-authored by Claude Opus 5.5
parent 60e6a16217
commit 83551714f7
46 changed files with 1934 additions and 431 deletions
+3 -2
View File
@@ -1,8 +1,8 @@
// One slide as a TV shows it (plan step 5.6a): picture, video, text or menu board. Used by the
// 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'
import { MenuSlide, TextSlide } from './Slides.jsx'
import { BlankSlide, MenuSlide, TextSlide } from './Slides.jsx'
export function SlideView({ slide, media, venue, now, pages, page, onEnded, playing = true }) {
return (
@@ -10,6 +10,7 @@ export function SlideView({ slide, media, venue, now, pages, page, onEnded, play
{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} />}
</>
)
+96 -30
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 { FONTS, weatherIcon } from './logic'
import { fitUnit, FONTS, textWidth, weatherIcon, widgetAlign } from './logic'
/** A slide's background: a colour, or a photo (cover / contain) with a darkening layer. */
export function Background({ bg, media }) {
@@ -19,6 +19,7 @@ export function Background({ bg, media }) {
}
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 }) {
@@ -38,6 +39,16 @@ export function TextSlide({ content: c, media, venue, now }) {
)
}
/** A blank slide (2026-11-21): its background and its widgets, nothing else. */
export function BlankSlide({ content: c, media, venue, now }) {
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} />
</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')
@@ -52,7 +63,11 @@ export function MenuSlide({ slide, media, venue, now, page, pages }) {
<div className="absolute inset-0 flex flex-col"
style={{ padding: `${hasBar(c, 'top-bar') ? 12 : 5}cqmin 5cqmin ${hasBar(c, 'bottom-bar') ? 12 : 5}cqmin` }}
data-testid="signage-menu" data-page={page} data-pages={pages.length}>
{c.title && <h1 style={{ fontSize: `${7 * scale}cqmin`, fontWeight: 800, margin: '0 0 2cqmin', color: accent, lineHeight: 1.1 }}>{c.title}</h1>}
{/* 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' }}>
@@ -91,13 +106,14 @@ export function MenuSlide({ slide, media, venue, now, page, pages }) {
{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} />
</div>
)
}
// ── widgets (5.5b) ──────────────────────────────────────────────────────────
// ── widgets (5.5b; placed by hand on the editor's preview, owner 2026-11-21) ────
const SIZE = { small: 0.75, medium: 1, large: 1.4 }
const CORNER = {
@@ -108,11 +124,19 @@ const CORNER = {
'bottom-center': { bottom: '3cqmin', left: '50%', transform: 'translateX(-50%)', alignItems: 'center' },
'bottom-right': { bottom: '3cqmin', right: '3cqmin', alignItems: 'flex-end' },
}
const SELF = { left: 'flex-start', center: 'center', right: 'flex-end' }
/** The widgets of a slide, in their corners and bars. One that has nothing to show is left out. */
/**
* 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).
*/
export function Widgets({ widgets, media, venue, now, colour }) {
const fmt = useFormat()
if (!widgets?.length) return null
const bar = where => widgets.filter(w => w.position === where)
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 bar = where => shown.filter(([w]) => w.position === where)
const bars = [['top-bar', { top: 0 }], ['bottom-bar', { bottom: 0 }]]
return (
<>
@@ -120,59 +144,99 @@ export function Widgets({ widgets, media, venue, now, colour }) {
<div key={where} className="absolute inset-x-0" data-testid={`signage-${where}`}
style={{ ...pos, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '3cqmin', padding: '2cqmin 4cqmin',
background: 'rgba(0,0,0,0.35)', color: colour || '#fff', minHeight: '9cqmin' }}>
{bar(where).map((w, i) => <Widget key={i} w={w} media={media} venue={venue} now={now} />)}
{bar(where).map(([w, i, body]) => (
<div key={i} data-widget={i} style={{ display: 'flex', flexDirection: 'column', alignItems: SELF[widgetAlign(w)], textAlign: widgetAlign(w) }}>{body}</div>
))}
</div>
))}
{widgets.filter(w => CORNER[w.position]).map((w, i) => (
<div key={`c${i}`} className="absolute" style={{ ...CORNER[w.position], display: 'flex', flexDirection: 'column', color: colour || '#fff' }}>
<Widget w={w} media={media} venue={venue} now={now} />
{shown.filter(([w]) => CORNER[w.position]).map(([w, i, body]) => {
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' }}>
{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>
))}
</>
)
}
const ICONS = { sun: Sun, moon: Moon, 'cloud-sun': CloudSun, 'cloud-moon': CloudMoon, cloud: Cloud, fog: CloudFog, rain: CloudRain, snow: CloudSnow, storm: CloudLightning }
const OBJECT_POSITION = { left: 'left center', center: 'center', right: 'right center' }
function Widget({ w, media, venue, now }) {
const { formatDate, formatTime } = useFormat()
/**
* 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).
*/
function widgetBody(w, { media, venue, now, fmt }, fit) {
const { formatDate, formatTime } = fmt
const s = SIZE[w.size] || 1
const text = { fontSize: `${3.4 * s}cqmin`, fontWeight: 700, lineHeight: 1.15, textShadow: '0 0.2cqmin 0.8cqmin rgba(0,0,0,0.35)' }
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 })
if (w.kind === 'logo') {
const m = media(w.media_id)
return m ? <img src={m.src} alt="" style={{ height: `${9 * s}cqmin`, maxWidth: `${30 * s}cqmin`, objectFit: 'contain' }} data-testid="signage-w-logo" /> : null
if (!m) return null
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" />
}
if (w.kind === 'name') {
if (!venue?.name) return null
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 === '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 === 'name') return venue?.name ? <span style={{ ...text, fontSize: `${4.2 * s}cqmin` }} data-testid="signage-w-name">{venue.name}</span> : null
if (w.kind === 'date') return <span style={text} data-testid="signage-w-date">{formatDate(now, w.date_style === 'short' ? 'date' : 'dateLong')}</span>
if (w.kind === 'clock') return <span style={{ ...text, fontSize: `${4.6 * s}cqmin`, 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
return msg ? <span style={{ ...text, fontWeight: 600 }} data-testid="signage-w-message">{msg}</span> : null
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>
}
if (w.kind === 'qr') {
return w.link ? (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '0.8cqmin' }} data-testid="signage-w-qr" data-link={w.link}>
<div style={{ background: '#fff', padding: '1cqmin', borderRadius: '1cqmin', lineHeight: 0 }}>
<QRCodeSVG value={w.link} size={256} style={{ width: `${14 * s}cqmin`, height: `${14 * s}cqmin` }} />
if (!w.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={{ background: '#fff', padding: u(1), borderRadius: u(1), lineHeight: 0 }}>
<QRCodeSVG value={w.link} size={256} style={{ width: u(14), height: u(14) }} />
</div>
{w.qr_caption && <span style={{ ...text, fontSize: `${2.4 * s}cqmin` }}>{w.qr_caption}</span>}
{w.qr_caption && <span style={text(u, 2.4)}>{w.qr_caption}</span>}
</div>
) : null
)
}
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: '1.5cqmin' }} data-testid="signage-w-weather">
<Icon style={{ width: `${6 * s}cqmin`, height: `${6 * s}cqmin` }} aria-hidden="true" />
<span style={{ ...text, fontSize: `${4.4 * s}cqmin` }}>{Math.round(wx.temperature)}{deg}</span>
{(w.weather_days || 1) > 1 && (wx.days || []).slice(1, w.weather_days).map(d => {
<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: '0.6cqmin', ...text, fontSize: `${2.4 * s}cqmin`, fontWeight: 600 }}>
{formatDate(`${d.date}T12:00:00Z`, 'weekday').slice(0, 3)} <DayIcon style={{ width: `${3.4 * s}cqmin`, height: `${3.4 * s}cqmin` }} aria-hidden="true" />
<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>
)
@@ -182,3 +246,5 @@ function Widget({ w, media, venue, now }) {
}
return null
}
const ICONS = { sun: Sun, moon: Moon, 'cloud-sun': CloudSun, 'cloud-moon': CloudMoon, cloud: Cloud, fog: CloudFog, rain: CloudRain, snow: CloudSnow, storm: CloudLightning }
+1 -1
View File
@@ -2,5 +2,5 @@
// player (terminal/src/apps/signage) and in the manager's live previews. Sizes are container
// units (cqmin): put a slide inside an element with `container-type: size` (frameStyle() does).
export * from './logic.js'
export { Background, MenuSlide, TextSlide, Widgets } from './Slides.jsx'
export { Background, BlankSlide, MenuSlide, TextSlide, Widgets } from './Slides.jsx'
export { SlideView } from './SlideView.jsx'
+32
View File
@@ -248,3 +248,35 @@ export function boardPages(slide, rotation, w, h) {
const per = c.page_size || rows * (c.columns || 2)
return menuPages(slide.menu?.groups || [], per, c.category_titles !== false)
}
// ── widgets placed by hand (owner 2026-11-21) ─────────────────────────────────
/** The slide kinds that carry widgets. */
export const WIDGET_HOSTS = ['text', 'menu', 'blank']
/** 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
if (w?.position === 'custom' && w.box) {
const mid = w.box.x + w.box.w / 2
return mid < 100 / 3 ? 'left' : mid > 200 / 3 ? 'right' : 'center'
}
const p = w?.position || ''
return p.endsWith('left') ? 'left' : p.endsWith('right') ? 'right' : p.endsWith('center') ? 'center' : 'left'
}
/**
* A size unit for a widget that fills its own box: `n` units of its usual size (cqmin at "medium")
* scaled so the whole widget, `height` × `width` usual units, fits the box (inside an element with
* `container-type: size`). → n → CSS length.
*/
export function fitUnit(height, width) {
const byH = 100 / Math.max(0.1, height)
const byW = 100 / Math.max(0.1, width)
return n => `calc(${+n.toFixed(3)} * min(${+byH.toFixed(4)}cqh, ${+byW.toFixed(4)}cqw))`
}
/** A line of `chars` characters at `size` usual units: about how wide it is (bold sans). */
export function textWidth(chars, size) {
return Math.max(1, chars) * size * 0.6
}
+19
View File
@@ -136,3 +136,22 @@ test('smart days and scenes, the same dates as the server (owner 2026-11-21)', a
assert.equal(pick(entries, 99, sat, [1]), 50)
assert.ok(!matches({ scene_id: 2 }, sat, [1]))
})
test('widgets placed by hand: how they line up, and a unit that fills their box (2026-11-21)', async () => {
const { fitUnit, textWidth, widgetAlign } = await import('../src/logic.js')
assert.equal(widgetAlign({ position: 'top-right' }), 'right')
assert.equal(widgetAlign({ position: 'bottom-center' }), 'center')
assert.equal(widgetAlign({ position: 'top-bar' }), 'left')
assert.equal(widgetAlign({ position: 'top-left', align: 'center' }), 'center') // its own choice
assert.equal(widgetAlign({ position: 'custom', box: { x: 70, y: 0, w: 25, h: 10 } }), 'right') // by its box's side
assert.equal(widgetAlign({ position: 'custom', box: { x: 40, y: 0, w: 20, h: 10 } }), 'center')
assert.equal(fitUnit(5, 20)(2.5), 'calc(2.5 * min(20cqh, 5cqw))')
assert.equal(textWidth(5, 4), 12)
})
test('a screen whose default is a library slide plays it when no line matches', () => {
const one = { id: 'slide:3', slides: [{ id: 3 }] }
const data = { schedule: { entries: [{ playlist_id: 1, date_from: '2000-01-01', date_to: '2000-01-01' }], fallback_playlist_id: 'slide:3', scenes: [], timezone: 'Europe/Athens' },
playlists: { 1: { id: 1, slides: [] }, 'slide:3': one } }
assert.equal(playlistNow(data, new Date('2026-11-21T12:00:00Z')), one)
})