feat(signage): slides keep their shape on any screen, custom shapes (21:9, 16:10…), Calibrate the picture edge by edge with presets

A slide is drawn at its playlist's shape, as large as fits the screen's picture,
the bands in its own background (or stretched, the screen's choice). Playlists and
library slides may have a shape of their own (aspect, Alembic 0045). Signage ->
Screens -> Calibrate the picture: the TV outlines its area with arrows and its size,
each edge moves pixel by pixel or a preset centres a shape; the TV follows live
(signage.calibrate) and reports its window (POST /screen/viewport). Plan 6R.13, F-110.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 13:04:24 +02:00
co-authored by Claude Opus 5.5
parent d5c19e17ce
commit 1c8d45e00c
32 changed files with 917 additions and 103 deletions
+71 -12
View File
@@ -6,11 +6,16 @@
// keeps playing (and switching by its schedule) while the server is down, and catches up on
// `signage.changed`, a reconnect, or every few minutes (prices that change by time alone).
// Menu boards page by themselves when they don't fit (5.5b); widgets sit in corners and bars.
// 6R.13: the picture fills the screen's calibrated area (its window minus the insets set in
// Signage → Screens); a slide keeps its playlist's shape inside it (bands in its own background)
// unless the screen stretches it. While the manager calibrates, the area is outlined with arrows
// pointing out and its size; the TV reports its window size for the presets.
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp } from 'lucide-react'
import { useTranslation } from '@xenia/i18n'
import client from '../../api/client'
import { useDevice, useLiveEvent, useLiveEvents } from '../../device/context'
import { boardPages, CQ_BOX, frameStyle, localNow, mediaUrls, menuMs, nextSlide, pageAt, playlistNow, SlideView, slideMs } from '@xenia/signage'
import { Backdrop, boardPages, CQ_BOX, fitBox, frameSize, frameStyle, localNow, mediaUrls, menuMs, nextSlide, pageAt, pictureArea, playlistNow, shapeName, shapeOf, shapeRatio, SlideView, slideMs } from '@xenia/signage'
const quiet = { xenia: { noOverride: true } }
const CACHE_KEY = 'xenia:signage:screen'
@@ -18,6 +23,7 @@ const REFRESH_MS = 5 * 60_000
const VIDEO_MAX_MS = 15 * 60_000 // a video "to its end" that never ends moves on after this
const KEEP_VIDEO_BYTES = 120 * 1024 * 1024 // bigger videos stream from the server (not kept offline)
const TRANSITION_MS = 800
const CALIBRATE_MS = 15 * 60_000 // an outline nobody turns off goes away by itself
function readCache() {
try { return JSON.parse(localStorage.getItem(CACHE_KEY) || 'null') } catch { return null }
@@ -87,22 +93,66 @@ export default function SignageApp() {
return () => clearInterval(id)
}, [])
// the window, for the picture area and the manager's calibration presets (6R.13)
const win = useWindowSize()
const report = useCallback(() => {
client.post('/api/signage/screen/viewport', { width: Math.round(window.innerWidth), height: Math.round(window.innerHeight), ratio: window.devicePixelRatio || 1 }, quiet).catch(() => {})
}, [])
useEffect(() => { report() }, [report, win.w, win.h])
useLiveEvent('ready', report)
const [calib, setCalib] = useState(null) // the last signage.calibrate: { on, area }
useLiveEvent('signage.calibrate', d => setCalib({ on: !!d?.on, area: d?.area || null }))
useEffect(() => {
if (!calib?.on) return undefined
const id = setTimeout(() => setCalib({ on: false, area: null }), CALIBRATE_MS)
return () => clearTimeout(id)
}, [calib])
const kept = useKeptMedia(useMemo(() => mediaUrls(data), [data]))
const playlist = playlistNow(data, now)
const tz = data?.schedule?.timezone
const screen = data?.screen
const calibrating = calib ? calib.on : !!screen?.calibrating
const pic = pictureArea(win, (calib?.on && calib.area) || screen?.area)
const frame = frameSize(screen?.rotation, pic)
return (
<main className="fixed inset-0 overflow-hidden select-none cursor-none" style={{ background: '#000' }}
data-testid="app-signage" data-playlist={playlist?.id ?? ''} data-orientation={screen?.orientation ?? ''} data-offline={offline ? 'true' : 'false'}>
<div style={frameStyle(screen?.rotation)} {...CQ_BOX} data-testid="signage-frame" data-rotation={screen?.rotation ?? 0}>
{playlist?.slides?.length
? <Player key={playlist.id} playlist={playlist} kept={kept} tz={tz} venue={data?.venue} now={now} rotation={screen?.rotation} />
: <Empty text={data ? t('signage.nothing') : t('signage.starting')} />}
<div className="absolute overflow-hidden" style={{ left: pic.left, top: pic.top, width: pic.width, height: pic.height }}
data-testid="signage-area" data-area={`${pic.left},${pic.top},${pic.width},${pic.height}`}>
<div style={frameStyle(screen?.rotation, pic)} {...CQ_BOX} data-testid="signage-frame" data-rotation={screen?.rotation ?? 0}>
{playlist?.slides?.length
? <Player key={playlist.id} playlist={playlist} kept={kept} tz={tz} venue={data?.venue} now={now} frame={frame} fit={screen?.fit} />
: <Empty text={data ? t('signage.nothing') : t('signage.starting')} />}
</div>
{calibrating && <Calibration pic={pic} name={screen?.name} />}
</div>
</main>
)
}
/** The picture area while the manager calibrates it (6R.13): its outline, arrows pointing at the screen's edges, its size. */
function Calibration({ pic, name }) {
const { t } = useTranslation('terminal')
const arrow = 'absolute text-accent'
const size = { width: '8vmin', height: '8vmin' }
return (
<div className="absolute inset-0 border-4 border-accent" data-testid="signage-calibrate" data-size={`${Math.round(pic.width)}x${Math.round(pic.height)}`}>
<ArrowUp className={arrow} style={{ ...size, top: '1vmin', left: 'calc(50% - 4vmin)' }} aria-hidden="true" />
<ArrowDown className={arrow} style={{ ...size, bottom: '1vmin', left: 'calc(50% - 4vmin)' }} aria-hidden="true" />
<ArrowLeft className={arrow} style={{ ...size, left: '1vmin', top: 'calc(50% - 4vmin)' }} aria-hidden="true" />
<ArrowRight className={arrow} style={{ ...size, right: '1vmin', top: 'calc(50% - 4vmin)' }} aria-hidden="true" />
<div className="absolute rounded-card bg-surface text-ink text-center" style={{ left: '50%', top: '50%', transform: 'translate(-50%, -50%)', padding: '2.5vmin 4vmin', maxWidth: '70%' }}>
<div style={{ fontSize: '3.2vmin', fontWeight: 700 }}>{t('signage.calibrate.title', { name: name || '' })}</div>
<div style={{ fontSize: '5vmin', fontWeight: 800, fontVariantNumeric: 'tabular-nums' }} data-testid="signage-calibrate-size">
{Math.round(pic.width)} × {Math.round(pic.height)} px · {shapeName(pic.width, pic.height)}
</div>
<div className="text-ink-2" style={{ fontSize: '2.4vmin' }}>{t('signage.calibrate.hint')}</div>
</div>
</div>
)
}
function Empty({ text }) {
return (
<div className="absolute inset-0 flex items-end justify-end p-4" data-testid="signage-empty">
@@ -122,11 +172,16 @@ function useWindowSize() {
return size
}
function Player({ playlist, kept, tz, venue, now, rotation }) {
function Player({ playlist, kept, tz, venue, now, frame, fit }) {
const local = localNow(tz, now)
const slides = playlist.slides
const size = useWindowSize()
const pagesOf = useCallback(sl => (sl?.kind === 'menu' ? boardPages(sl, rotation, size.w, size.h) : null), [rotation, size])
// the slide's own box: its playlist's shape as large as fits the frame, centred (or the whole frame)
const shape = shapeOf(playlist)
const stretch = fit === 'stretch'
const box = useMemo(() => (stretch ? { left: 0, top: 0, width: frame.w, height: frame.h } : fitBox(frame.w, frame.h, shapeRatio(shape))),
[stretch, frame.w, frame.h, shape])
const banded = box.width < frame.w - 1 || box.height < frame.h - 1
const pagesOf = useCallback(sl => (sl?.kind === 'menu' ? boardPages(sl, 0, box.width, box.height) : null), [box])
const [cur, setCur] = useState(() => ({ index: nextSlide(slides, -1, local), at: Date.now(), n: 0 }))
const [prev, setPrev] = useState(null)
const media = id => {
@@ -171,21 +226,25 @@ function Player({ playlist, kept, tz, venue, now, rotation }) {
return (
<>
{prev && slides[prev.index] && (
<Layer key={`out-${prev.n}`} slide={slides[prev.index]} media={media} venue={venue} now={now} className={`sg-out sg-out-${transition}`}
<Layer key={`out-${prev.n}`} slide={slides[prev.index]} media={media} venue={venue} now={now} className={`sg-out sg-out-${transition}`} box={box} banded={banded} shape={shape}
pages={pagesOf(slides[prev.index])} page={pageAt(pagesOf(slides[prev.index])?.length || 0, slides[prev.index].content?.page_seconds, cur.at - prev.at - 1)} />
)}
<Layer key={`in-${cur.n}`} slide={slide} media={media} venue={venue} now={now} onEnded={advance}
<Layer key={`in-${cur.n}`} slide={slide} media={media} venue={venue} now={now} onEnded={advance} box={box} banded={banded} shape={shape}
className={cur.n === 0 ? '' : `sg-in sg-in-${transition}`} current
pages={pagesOf(slide)} page={pageAt(pagesOf(slide)?.length || 0, slide.content?.page_seconds, now.getTime() - cur.at)} />
</>
)
}
function Layer({ slide, media, venue, now, onEnded, className, current = false, pages, page }) {
function Layer({ slide, media, venue, now, onEnded, className, current = false, pages, page, box, banded, shape }) {
return (
<section className={`absolute inset-0 overflow-hidden ${className}`} style={{ animationDuration: `${TRANSITION_MS}ms` }}
data-testid={current ? 'signage-slide' : 'signage-slide-out'} data-kind={slide.kind} data-slide={slide.id}>
<SlideView slide={slide} media={media} venue={venue} now={now} pages={pages} page={page} onEnded={current ? onEnded : undefined} />
{banded && <Backdrop slide={slide} media={media} />}
<div style={{ position: 'absolute', left: box.left, top: box.top, width: box.width, height: box.height, overflow: 'hidden', containerType: 'size' }}
{...CQ_BOX} data-testid={current ? 'signage-shape' : undefined} data-shape={shape} data-box={`${Math.round(box.width)}x${Math.round(box.height)}`}>
<SlideView slide={slide} media={media} venue={venue} now={now} pages={pages} page={page} onEnded={current ? onEnded : undefined} />
</div>
</section>
)
}