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
@@ -5,6 +5,7 @@
import { Film, ImageIcon, LayoutDashboard, LayoutList, Square, Type } from 'lucide-react'
import { useTranslation } from '@xenia/i18n'
import { Button, Dialog, Spinner } from '@xenia/ui'
import { shapeRatio } from '@xenia/signage'
import { BLANK_WITH_WIDGETS, mediaLookup, slideFromSaved, slideFromTemplate, TEMPLATES } from './signageLogic'
import SlidePreview from './SlidePreview'
@@ -28,7 +29,7 @@ function Heading({ children, hint }) {
export default function AddSlideDialog({ onClose, onPick, orientation = 'landscape', venue, library = null, libraryMedia = {}, title }) {
const { t } = useTranslation('manager')
const tall = orientation === 'portrait'
const tall = shapeRatio(orientation) < 1
return (
<Dialog open size="xl" title={title || t('signage.addSlide')} onClose={onClose}
footer={<Button variant="secondary" onClick={onClose}>{t('fees.cancel')}</Button>}>
@@ -0,0 +1,113 @@
// Calibrating a screen's picture (6R.13, owner 2026-11-22). While this is open the TV outlines its
// picture area with four arrows pointing out and shows its size; each edge moves in or out here
// pixel by pixel (or in steps of 10 / 50 px), or a preset sets the largest box of a common shape in
// the middle of the TV's window (it reports its size). Every change reaches the TV at once; closing
// ends the calibration (the TV also stops by itself after 15 min).
import { useCallback, useEffect, useRef, useState } from 'react'
import toast from 'react-hot-toast'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Dialog, Field, NumberInput, Segmented } from '@xenia/ui'
import { pictureArea, presetInsets, shapeName } from '@xenia/signage'
import * as api from './signageApi'
import { ShapeMark } from './ShapeField'
const EDGES = ['top', 'right', 'bottom', 'left']
const PRESETS = ['full', '16:9', '16:10', '21:9', '32:9', '4:3', '9:16']
const SAVE_MS = 200
export default function CalibrateDialog({ screen, onClose, onSaved }) {
const { t } = useTranslation('manager')
const [area, setArea] = useState(screen.area || { left: 0, top: 0, right: 0, bottom: 0 })
const [viewport, setViewport] = useState(screen.viewport || null)
const [step, setStep] = useState(1)
const timer = useRef(null)
const latest = useRef(area)
// on while open; off when closed
useEffect(() => {
api.calibrateScreen(screen.id, true).catch(err => toast.error(errorMessage(err, t)))
return () => { api.calibrateScreen(screen.id, false).catch(() => {}) }
}, [screen.id]) // eslint-disable-line react-hooks/exhaustive-deps
// the TV's window size (it reports it when it starts and when it changes)
useEffect(() => {
const id = setInterval(() => {
api.listScreens().then(list => setViewport(list.find(s => s.id === screen.id)?.viewport || null)).catch(() => {})
}, 2000)
return () => clearInterval(id)
}, [screen.id])
const send = useCallback(() => {
const a = latest.current
api.updateScreen(screen.id, { area_left: a.left, area_top: a.top, area_right: a.right, area_bottom: a.bottom })
.then(onSaved).catch(err => toast.error(errorMessage(err, t)))
}, [screen.id, onSaved, t])
const change = next => {
latest.current = next
setArea(next)
clearTimeout(timer.current)
timer.current = setTimeout(send, SAVE_MS)
}
useEffect(() => () => clearTimeout(timer.current), [])
const win = viewport ? { w: viewport.width, h: viewport.height } : null
const pic = win ? pictureArea(win, area) : null
const setEdge = (edge, v) => change({ ...area, [edge]: Math.max(0, Math.min(4000, v ?? 0)) })
// the diagram: the TV's window and the picture inside it, to scale
const W = 320
const H = win ? Math.round(W * win.h / win.w) : 180
const k = win ? W / win.w : 0
const edge = e => (
<Field label={t(`signage.calibrate.edges.${e}`)} className="w-36">
<NumberInput size="sm" value={area[e]} min={0} max={4000} step={step} suffix="px" onChange={v => setEdge(e, v)} data-testid={`signage-calibrate-${e}`} />
</Field>
)
return (
<Dialog open size="lg" onClose={onClose} title={t('signage.calibrate.title', { name: screen.name })} description={t('signage.calibrate.intro')}
footer={<>
<Button variant="secondary" onClick={() => change({ left: 0, top: 0, right: 0, bottom: 0 })} data-testid="signage-calibrate-reset">{t('signage.calibrate.reset')}</Button>
<Button onClick={onClose} data-testid="signage-calibrate-done">{t('signage.calibrate.done')}</Button>
</>}>
<div className="grid gap-5" data-testid="signage-calibrate-dialog">
<p className="text-label text-ink-2" data-testid="signage-calibrate-window">
{win ? t('signage.calibrate.window', { w: win.w, h: win.h, shape: shapeName(win.w, win.h) }) : t('signage.calibrate.waiting')}
</p>
<div className="grid gap-2">
<span className="text-label font-medium text-ink">{t('signage.calibrate.presets')}</span>
<div className="flex flex-wrap gap-1.5">
{PRESETS.map(p => (
<Button key={p} size="sm" variant="secondary" disabled={!win} onClick={() => change(presetInsets(win, p))} data-preset={p}
icon={p === 'full' ? undefined : <ShapeMark shape={p} size={16} />}>
{p === 'full' ? t('signage.calibrate.full') : p}
</Button>
))}
</div>
</div>
<div className="flex flex-wrap items-center gap-3">
<span className="text-label font-medium text-ink">{t('signage.calibrate.step')}</span>
<Segmented value={step} onChange={setStep} options={[1, 10, 50].map(n => ({ value: n, label: `${n} px` }))} data-testid="signage-calibrate-step" />
</div>
<div className="grid justify-items-center gap-2">
{edge('top')}
<div className="flex items-center gap-3 flex-wrap justify-center">
{edge('left')}
<div className="relative rounded-control border border-line-strong bg-surface-2" style={{ width: W, height: H }} aria-hidden="true">
{pic && (
<div className="absolute border-2 border-accent bg-accent-soft grid place-items-center text-caption text-accent-ink tabular-nums"
style={{ left: pic.left * k, top: pic.top * k, width: pic.width * k, height: pic.height * k }}>
{Math.round(pic.width)} × {Math.round(pic.height)}
</div>
)}
</div>
{edge('right')}
</div>
{edge('bottom')}
</div>
<p className="text-label text-ink-2 text-center" data-testid="signage-calibrate-picture">
{pic ? t('signage.calibrate.picture', { w: Math.round(pic.width), h: Math.round(pic.height), shape: shapeName(pic.width, pic.height) }) : ''}
</p>
{EDGES.some(e => area[e] > 0) && <p className="text-caption text-ink-3">{t('signage.calibrate.outside')}</p>}
</div>
</Dialog>
)
}
@@ -12,6 +12,7 @@ import toast from 'react-hot-toast'
import { AlertTriangle, ArrowLeft, ArrowRight, BookmarkPlus, Copy, ImageIcon, Plus, Trash2 } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { shapeOf, shapeRatio } from '@xenia/signage'
import { Button, Dialog, Dropdown, Field, IconButton, Input, Spinner, Textarea, useConfirm } from '@xenia/ui'
import * as api from './signageApi'
import { mediaEntry, mediaLookup, misfits, moved, secondsMissing, slideBody, totalSeconds, TRANSITIONS, windowParts } from './signageLogic'
@@ -19,6 +20,7 @@ import { playSeconds } from './timing'
import AddSlideDialog, { KIND_ICON } from './AddSlideDialog'
import SlideEditor, { SlideBasics } from './SlideEditor'
import SlidePreview from './SlidePreview'
import ShapeField from './ShapeField'
import { useSlidePreview, useWidgetEditor } from './useSlideDraft'
/** The preview as big as its box allows (the box is as tall as the basics beside it). */
@@ -32,7 +34,7 @@ export function FitPreview({ orientation, children }) {
ro.observe(el)
return () => ro.disconnect()
}, [])
const ratio = orientation === 'portrait' ? 9 / 16 : 16 / 9
const ratio = shapeRatio(orientation)
const width = Math.max(0, Math.min(size.w, size.h * ratio))
return (
<div ref={box} className="h-full min-h-[16rem] min-w-0 grid place-items-center" data-testid="signage-preview-box">
@@ -77,8 +79,8 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
const saved = pl?.slides.find(s => s.id === selected)
const dirty = useMemo(() => !!(draft && saved && JSON.stringify(slideBody(draft)) !== JSON.stringify(slideBody(saved))), [draft, saved])
const bad = useMemo(() => misfits(pl?.slides, media, pl?.orientation), [pl, media])
const draftBad = useMemo(() => (draft ? misfits([draft], media, pl?.orientation)[draft.id] || [] : []), [draft, media, pl])
const bad = useMemo(() => misfits(pl?.slides, media, shapeOf(pl)), [pl, media])
const draftBad = useMemo(() => (draft ? misfits([draft], media, shapeOf(pl))[draft.id] || [] : []), [draft, media, pl])
if (!pl) return <div className="flex justify-center p-8"><Spinner /></div>
const run = async (fn, done, select) => {
@@ -135,7 +137,9 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
const made = await run(() => api.addSlide(pl.id, body), t('signage.added'))
if (made) await load(made.id)
}
const total = totalSeconds(pl.slides, media, s => playSeconds(s, pl.orientation))
const shape = shapeOf(pl)
const tall = shapeRatio(shape) < 1
const total = totalSeconds(pl.slides, media, s => playSeconds(s, shape))
const marker = i => drag && drag.at === i && drag.at !== drag.from && drag.at !== drag.from + 1
return (
@@ -146,10 +150,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
onBlur={() => name.trim() && name.trim() !== pl.name && savePlaylist({ name: name.trim() })}
onKeyDown={e => { if (e.key === 'Enter') e.currentTarget.blur() }} />
</Field>
<Field label={t('signage.orientation')} className="w-52">
<Dropdown value={pl.orientation} onChange={v => savePlaylist({ orientation: v })} data-testid="signage-orientation"
options={['landscape', 'portrait'].map(o => ({ value: o, label: t(`signage.orientations.${o}`) }))} />
</Field>
<ShapeField value={pl} onChange={savePlaylist} />
<Field label={t('signage.defaultTransition')} className="w-44">
<Dropdown value={pl.transition} onChange={v => savePlaylist({ transition: v })}
options={TRANSITIONS.map(x => ({ value: x, label: t(`signage.transitions.${x}`) }))} />
@@ -179,8 +180,8 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
{marker(i) && <DropLine side="left" />}
{marker(i + 1) && i === pl.slides.length - 1 && <DropLine side="right" />}
<div className="pointer-events-none h-28 grid place-items-center rounded-control bg-surface-2">
<div style={{ width: pl.orientation === 'portrait' ? 63 : '100%' }}>
<SlidePreview slide={s} media={mediaLookup(media)} venue={venue} orientation={pl.orientation} testid="signage-card-preview" />
<div style={{ width: tall ? Math.round(112 * shapeRatio(shape)) : '100%' }}>
<SlidePreview slide={s} media={mediaLookup(media)} venue={venue} orientation={shape} testid="signage-card-preview" />
</div>
</div>
<div className="grid gap-0.5 min-w-0">
@@ -191,7 +192,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
{bad[s.id] && <AlertTriangle size={14} className="text-warning-ink shrink-0" aria-label={t('signage.misfit')} data-testid="signage-card-misfit" />}
</span>
<span className="text-caption text-ink-3 truncate">
{s.kind === 'video' && s.video_to_end ? t('signage.toTheEnd') : t('signage.seconds', { count: playSeconds(s, pl.orientation) })}
{s.kind === 'video' && s.video_to_end ? t('signage.toTheEnd') : t('signage.seconds', { count: playSeconds(s, shape) })}
{!s.enabled && <> · {t('signage.off')}</>}
{parts.map(p => <span key={p.key}> · {p.key === 'days' ? p.params.days.map(d => t(`signage.weekdays.${d}`)).join(' ') : t(`signage.window.${p.key}`, p.params)}</span>)}
</span>
@@ -219,9 +220,9 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
{/* the picked slide: its basics beside its preview (one height), then what it shows */}
{draft ? <>
<section className="grid gap-6 lg:grid-cols-2 items-stretch rounded-card border border-line bg-surface shadow-raised p-card min-w-0" data-testid="signage-slide-top">
<SlideBasics slide={draft} onChange={setDraft} orientation={pl.orientation} />
<FitPreview orientation={pl.orientation}>
<SlidePreview slide={draft} media={mediaLookup(media)} venue={venue} orientation={pl.orientation} playing editor={editor} />
<SlideBasics slide={draft} onChange={setDraft} orientation={shape} />
<FitPreview orientation={shape}>
<SlidePreview slide={draft} media={mediaLookup(media)} venue={venue} orientation={shape} playing editor={editor} />
</FitPreview>
</section>
<section className="rounded-card border border-line bg-surface shadow-raised p-card min-w-0">
@@ -239,9 +240,9 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
</> : <p className="text-body text-ink-3 p-6 text-center">{t(pl.slides.length ? 'signage.pickSlide' : 'signage.noSlides')}</p>}
{adding !== null && (
<AddSlideDialog onClose={() => setAdding(null)} onPick={addSlide} orientation={pl.orientation} venue={venue} library={adding} libraryMedia={libMedia} />
<AddSlideDialog onClose={() => setAdding(null)} onPick={addSlide} orientation={shape} venue={venue} library={adding} libraryMedia={libMedia} />
)}
{keeping && draft && <KeepDialog draft={draft} orientation={pl.orientation} onClose={() => setKeeping(false)} />}
{keeping && draft && <KeepDialog draft={draft} shape={{ orientation: pl.orientation, aspect: pl.aspect || null }} onClose={() => setKeeping(false)} />}
{confirmDialog}
{confirmDelete && (
@@ -265,7 +266,7 @@ function DropLine({ side }) {
}
/** Keep the slide (as it is now, saved or not) in the Slides library, with a name and a description. */
function KeepDialog({ draft, orientation, onClose }) {
function KeepDialog({ draft, shape, onClose }) {
const { t } = useTranslation('manager')
const [name, setName] = useState(draft.name || '')
const [description, setDescription] = useState('')
@@ -273,7 +274,7 @@ function KeepDialog({ draft, orientation, onClose }) {
const keep = async () => {
setBusy(true)
try {
await api.createSaved({ ...slideBody(draft), kind: draft.kind, name: name.trim(), description: description.trim() || null, orientation })
await api.createSaved({ ...slideBody(draft), kind: draft.kind, name: name.trim(), description: description.trim() || null, ...shape })
toast.success(t('signage.library.kept'))
onClose()
} catch (err) { toast.error(errorMessage(err, t)) }
@@ -2,14 +2,17 @@
// playlist, or one slide from the Slides library shown alone), its shape and how its picture is
// turned, and what plays on it now. A schedule line for a screen
// (Schedules) wins over its default while it matches. A warning when a playlist it may play was
// made for the other shape. New TVs are paired in Devices.
// made for the other shape. New TVs are paired in Devices. 6R.13: how slides of another shape fit
// (keep their shape with bands, or stretch) and Calibrate the picture (CalibrateDialog).
import { useCallback, useEffect, useState } from 'react'
import toast from 'react-hot-toast'
import { Link } from 'react-router-dom'
import { AlertTriangle, CalendarClock, Monitor, Smartphone } from 'lucide-react'
import { AlertTriangle, CalendarClock, Monitor, Scan, Smartphone } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Dropdown, EmptyState, Field, Spinner } from '@xenia/ui'
import { Button, Dropdown, EmptyState, Field, Spinner } from '@xenia/ui'
import { pictureArea, shapeName } from '@xenia/signage'
import CalibrateDialog from './CalibrateDialog'
import { DeviceSupport } from '../platform/DeviceSupport'
import * as api from './signageApi'
@@ -18,6 +21,7 @@ export default function ScreensTab() {
const [screens, setScreens] = useState(null)
const [playlists, setPlaylists] = useState([])
const [slides, setSlides] = useState([])
const [calibrating, setCalibrating] = useState(null) // the screen whose picture is being calibrated
const load = useCallback(async () => {
try {
const [s, p, l] = await Promise.all([api.listScreens(), api.listPlaylists(), api.listSaved().catch(() => ({ slides: [] }))])
@@ -25,6 +29,7 @@ export default function ScreensTab() {
} catch (err) { toast.error(errorMessage(err, t)) }
}, [t])
useEffect(() => { load() }, [load])
const replace = useCallback(s => setScreens(list => list.map(x => (x.id === s.id ? s : x))), [])
const save = async (id, body) => {
try { const s = await api.updateScreen(id, body); setScreens(list => list.map(x => (x.id === id ? s : x))); toast.success(t('settings.saved')) }
catch (err) { toast.error(errorMessage(err, t)) }
@@ -61,7 +66,7 @@ export default function ScreensTab() {
{s.now?.scheduled && <CalendarClock size={14} className="text-accent-ink" aria-hidden="true" />}
{s.now ? t(s.now.scheduled ? 'signage.screens.nowScheduled' : s.now.slide ? 'signage.screens.nowSlide' : 'signage.screens.nowDefault', { name: s.now.name }) : t('signage.screens.nowNothing')}
</p>
<div className="grid gap-3 sm:grid-cols-3 max-w-4xl">
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-4 max-w-5xl">
<Field label={t('signage.screens.default')} hint={t('signage.screens.defaultHint')}>
<Dropdown value={s.playlist_id ? `p:${s.playlist_id}` : s.slide_id ? `s:${s.slide_id}` : ''} data-testid="signage-screen-playlist"
onChange={v => save(s.id, v.startsWith('s:') ? { slide_id: Number(v.slice(2)) } : { playlist_id: v ? Number(v.slice(2)) : null, slide_id: null })}
@@ -77,11 +82,32 @@ export default function ScreensTab() {
<Dropdown value={s.rotation} onChange={v => save(s.id, { rotation: Number(v) })} data-testid="signage-screen-rotation"
options={[0, 90, 180, 270].map(r => ({ value: r, label: t(`signage.screens.rotations.${r}`) }))} />
</Field>
<Field label={t('signage.screens.fit')} hint={t('signage.screens.fitHint')}>
<Dropdown value={s.fit || 'keep'} onChange={v => save(s.id, { fit: v })} data-testid="signage-screen-fit"
options={['keep', 'stretch'].map(f => ({ value: f, label: t(`signage.screens.fits.${f}`) }))} />
</Field>
</div>
<div className="flex flex-wrap items-center gap-3">
<Button variant="secondary" icon={<Scan size={16} />} onClick={() => setCalibrating(s)} data-testid="signage-screen-calibrate">{t('signage.calibrate.open')}</Button>
<span className="text-label text-ink-2" data-testid="signage-screen-picture">{pictureText(s, t)}</span>
</div>
</li>
)
})}
</ul>
{calibrating && <CalibrateDialog screen={calibrating} onSaved={replace} onClose={() => { setCalibrating(null); load() }} />}
</div>
)
}
/** "The whole window (2560 × 1080 px, 21:9)" / "1920 × 1080 px of its 2560 × 1080 window" / nothing known yet. */
function pictureText(s, t) {
const a = s.area || {}
const cut = a.left || a.top || a.right || a.bottom
if (!s.viewport) return cut ? t('signage.screens.pictureCut') : t('signage.screens.pictureWhole')
const win = { w: s.viewport.width, h: s.viewport.height }
const pic = pictureArea(win, a)
return cut
? t('signage.screens.pictureOf', { w: Math.round(pic.width), h: Math.round(pic.height), shape: shapeName(pic.width, pic.height), ww: win.w, wh: win.h })
: t('signage.screens.pictureWindow', { w: win.w, h: win.h, shape: shapeName(win.w, win.h) })
}
@@ -0,0 +1,59 @@
// A playlist's or library slide's shape (6R.13, owner 2026-11-22): landscape, portrait, or a shape of
// its own (21:9, 16:10…) picked from the common ones or typed as W : H, behind the icon beside the
// list. The previews and the TVs draw the slides at that shape.
import { useRef, useState } from 'react'
import { Proportions } from 'lucide-react'
import { useTranslation } from '@xenia/i18n'
import { Button, Dropdown, Field, IconButton, NumberInput, Popover } from '@xenia/ui'
import { parseAspect, shapeOf, shapeRatio, SHAPES } from '@xenia/signage'
/** A small rectangle of a shape, for the presets. */
export function ShapeMark({ shape, size = 22 }) {
const r = shapeRatio(shape)
const w = r >= 1 ? size : Math.round(size * r)
const h = r >= 1 ? Math.round(size / r) : size
return <span className="inline-block rounded-[3px] border-2 border-current shrink-0" style={{ width: w, height: h }} aria-hidden="true" />
}
export default function ShapeField({ value, onChange, label, className = 'w-60', testId = 'signage-orientation' }) {
const { t } = useTranslation('manager')
const shape = shapeOf(value)
const custom = shape !== 'landscape' && shape !== 'portrait'
const btn = useRef(null)
const [open, setOpen] = useState(false)
const [own, setOwn] = useState(() => parseAspect(value?.aspect) || [21, 9])
const ok = parseAspect(`${own[0]}:${own[1]}`)
const pick = aspect => { setOpen(false); onChange({ aspect }) }
const options = [
...['landscape', 'portrait'].map(o => ({ value: o, label: t(`signage.orientations.${o}`) })),
...(custom ? [{ value: shape, label: t('signage.shape.custom', { shape }) }] : []),
]
return (
<Field label={label || t('signage.orientation')} className={className}>
<div className="flex gap-1.5 items-center">
<Dropdown className="flex-1 min-w-0" value={shape} data-testid={testId} data-shape={shape}
onChange={v => (v === 'landscape' || v === 'portrait') && onChange({ orientation: v, aspect: null })} options={options} />
<IconButton ref={btn} label={t('signage.shape.own')} onClick={() => setOpen(o => !o)} aria-expanded={open}
tone={custom ? 'info' : undefined} data-testid={`${testId}-custom`}><Proportions size={16} /></IconButton>
<Popover open={open} anchor={btn} onClose={() => setOpen(false)} className="w-72 p-3 grid gap-3" data-testid="signage-shape-panel">
<p className="text-caption text-ink-2">{t('signage.shape.hint')}</p>
<div className="grid grid-cols-5 gap-1.5">
{SHAPES.map(s => (
<button key={s} type="button" onClick={() => pick(s)} data-shape={s}
className={`flex flex-col items-center justify-center gap-1 h-14 rounded-control border text-caption ${s === shape || (s === '16:9' && shape === 'landscape') || (s === '9:16' && shape === 'portrait') ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line text-ink-2 hover:bg-surface-2'}`}>
<ShapeMark shape={s} />{s}
</button>
))}
</div>
<div className="flex items-end gap-1.5">
<Field label={t('signage.shape.width')} className="flex-1"><NumberInput size="sm" value={own[0]} min={1} max={99} onChange={v => setOwn([v, own[1]])} data-testid="signage-shape-w" /></Field>
<span className="pb-2 text-ink-3">:</span>
<Field label={t('signage.shape.height')} className="flex-1"><NumberInput size="sm" value={own[1]} min={1} max={99} onChange={v => setOwn([own[0], v])} data-testid="signage-shape-h" /></Field>
</div>
{!ok && <p className="text-caption text-danger-ink">{t('signage.shape.invalid')}</p>}
<Button size="sm" disabled={!ok} onClick={() => pick(`${own[0]}:${own[1]}`)} data-testid="signage-shape-apply">{t('signage.shape.use', { shape: ok ? `${own[0]}:${own[1]}` : '' })}</Button>
</Popover>
</div>
</Field>
)
}
@@ -12,8 +12,10 @@ import toast from 'react-hot-toast'
import { Monitor, Plus, Smartphone } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Dialog, Dropdown, EmptyState, Field, Input, Page, PageHeader, Spinner, Tabs } from '@xenia/ui'
import { Button, Dialog, EmptyState, Field, Input, Page, PageHeader, Spinner, Tabs } from '@xenia/ui'
import { shapeRatio } from '@xenia/signage'
import * as api from './signageApi'
import ShapeField from './ShapeField'
import PlaylistEditor from './PlaylistEditor'
import SchedulesTab from './SchedulesTab'
import ScreensTab from './ScreensTab'
@@ -86,21 +88,20 @@ export default function SignagePage() {
function NewPlaylist({ onClose, onCreate }) {
const { t } = useTranslation('manager')
const [name, setName] = useState('')
const [orientation, setOrientation] = useState('landscape')
const [shape, setShape] = useState({ orientation: 'landscape', aspect: null })
return (
<Dialog open size="sm" title={t('signage.newPlaylist')} onClose={onClose}
footer={<>
<Button variant="secondary" onClick={onClose}>{t('fees.cancel')}</Button>
<Button disabled={!name.trim()} onClick={() => onCreate({ name: name.trim(), orientation })} data-testid="signage-create-playlist">{t('display.looks.create')}</Button>
<Button disabled={!name.trim()} onClick={() => onCreate({ name: name.trim(), orientation: shape.orientation || 'landscape', aspect: shape.aspect || null })} data-testid="signage-create-playlist">{t('display.looks.create')}</Button>
</>}>
<div className="grid gap-3">
<Field label={t('signage.playlistName')}>
<Input value={name} autoFocus maxLength={80} onChange={e => setName(e.target.value)} placeholder={t('signage.playlistPlaceholder')} data-testid="signage-new-name" />
</Field>
<Field label={t('signage.orientation')} hint={t('signage.orientationHint')}>
<Dropdown value={orientation} onChange={setOrientation} data-testid="signage-new-orientation"
options={['landscape', 'portrait'].map(o => ({ value: o, label: t(`signage.orientations.${o}`) }))} />
</Field>
<ShapeField value={shape} className="" testId="signage-new-orientation"
onChange={v => setShape({ orientation: v.orientation || (shapeRatio(v.aspect) < 1 ? 'portrait' : 'landscape'), aspect: v.aspect ?? null })} />
<p className="text-caption text-ink-3 -mt-1">{t('signage.orientationHint')}</p>
</div>
</Dialog>
)
@@ -1,15 +1,13 @@
// A slide drawn exactly as the TV draws it (@xenia/signage), in a box of the playlist's shape
// (plan step 5.6a). The slide is laid out on a full-size 1920 × 1080 (or 1080 × 1920) frame and
// scaled down to the box, so text, rows and menu pages match a real TV, not a small window.
// (plan step 5.6a). The slide is laid out on a full-size frame (1920 × 1080, 1080 × 1920, or a
// custom shape with its long side 1920: 6R.13) and scaled down to the box, so text, rows and menu
// pages match a real TV, not a small window. `orientation` is the shape: landscape, portrait, "21:9".
// `editor` = { selected, onSelect, onPlace, label } (2026-11-21): the widgets can be picked, moved
// and sized on it (WidgetCanvas).
import { useEffect, useRef, useState } from 'react'
import { boardPages, SlideView, WIDGET_HOSTS } from '@xenia/signage'
import { boardPages, canvasOf, SlideView, WIDGET_HOSTS } from '@xenia/signage'
import WidgetCanvas from './WidgetCanvas'
const LONG = 1920
const SHORT = 1080
export default function SlidePreview({ slide, media, venue, orientation = 'landscape', page = 0, playing = false, className = '', testid = 'signage-preview', editor = null }) {
const [now, setNow] = useState(() => new Date())
const box = useRef(null)
@@ -18,9 +16,7 @@ export default function SlidePreview({ slide, media, venue, orientation = 'lands
const id = setInterval(() => setNow(new Date()), 1000)
return () => clearInterval(id)
}, [])
const tall = orientation === 'portrait'
const w = tall ? SHORT : LONG
const h = tall ? LONG : SHORT
const { w, h } = canvasOf(orientation)
useEffect(() => {
const el = box.current
if (!el) return undefined
@@ -33,7 +29,7 @@ export default function SlidePreview({ slide, media, venue, orientation = 'lands
const pages = slide?.kind === 'menu' ? boardPages(slide, 0, w, h) : null
return (
<div ref={box} className={`relative rounded-control ${className}`} data-testid={testid} data-orientation={orientation}
style={{ aspectRatio: tall ? '9 / 16' : '16 / 9' }}>
style={{ aspectRatio: `${w} / ${h}` }}>
{/* the slide is clipped to its frame; the editor's handles may stick out of it */}
<div className="absolute inset-0 overflow-hidden rounded-control bg-black">
{slide && scale > 0 && (
@@ -9,12 +9,14 @@ import toast from 'react-hot-toast'
import { ArrowLeft, Copy, Layers, Monitor, Pencil, Plus, Smartphone, Trash2 } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, EmptyState, Field, IconButton, Input, Pane, Segmented, Spinner, Textarea, useConfirm } from '@xenia/ui'
import { shapeOf, shapeRatio } from '@xenia/signage'
import { Button, EmptyState, Field, IconButton, Input, Pane, Spinner, Textarea, useConfirm } from '@xenia/ui'
import * as api from './signageApi'
import { mediaEntry, mediaLookup, misfits, savedBody, secondsMissing } from './signageLogic'
import AddSlideDialog, { KIND_ICON } from './AddSlideDialog'
import SlideEditor, { SlideBasics } from './SlideEditor'
import SlidePreview from './SlidePreview'
import ShapeField from './ShapeField'
import { useSlidePreview, useWidgetEditor } from './useSlideDraft'
export default function SlidesTab({ open, onOpen }) {
@@ -61,19 +63,20 @@ export default function SlidesTab({ open, onOpen }) {
<ul className="grid gap-4 grid-cols-[repeat(auto-fill,minmax(17rem,1fr))]" data-testid="signage-saved-list">
{list.map(s => {
const Icon = KIND_ICON[s.kind]
const Shape = s.orientation === 'portrait' ? Smartphone : Monitor
const shape = shapeOf(s)
const Shape = shapeRatio(shape) < 1 ? Smartphone : Monitor
return (
<li key={s.id} className="rounded-card border border-line bg-surface shadow-raised overflow-hidden grid content-start" data-testid="signage-saved" data-name={s.name}>
<button type="button" onClick={() => onOpen(s.id)} className="block bg-surface-2 p-3" aria-label={t('signage.library.edit', { name: s.name })}>
<div className="pointer-events-none mx-auto" style={{ width: s.orientation === 'portrait' ? '40%' : '100%' }}>
<SlidePreview slide={s} media={mediaLookup(media)} venue={venue} orientation={s.orientation} testid="signage-saved-preview" />
<div className="pointer-events-none mx-auto" style={{ width: shapeRatio(shape) < 1 ? `${Math.round(71 * shapeRatio(shape))}%` : '100%' }}>
<SlidePreview slide={s} media={mediaLookup(media)} venue={venue} orientation={shape} testid="signage-saved-preview" />
</div>
</button>
<div className="p-card grid gap-1 min-w-0">
<span className="flex items-center gap-1.5 min-w-0">
<Icon size={15} className="text-ink-2 shrink-0" aria-hidden="true" />
<span className="text-body font-semibold text-ink truncate">{s.name}</span>
<Shape size={14} className="text-ink-3 shrink-0 ml-auto" aria-label={t(`signage.orientations.${s.orientation}`)} />
<Shape size={14} className="text-ink-3 shrink-0 ml-auto" aria-label={shape === s.orientation ? t(`signage.orientations.${s.orientation}`) : shape} />
</span>
<span className="text-caption text-ink-3 line-clamp-2 min-h-[2.2em]">{s.description || t(`signage.kinds.${s.kind}`)}</span>
{s.screens?.length > 0 && <span className="text-caption text-success-ink truncate">{t('signage.library.onScreens', { names: s.screens.map(x => x.name).join(', ') })}</span>}
@@ -109,7 +112,7 @@ function SavedSlideEditor({ id, venue, onClose }) {
}, [id]) // eslint-disable-line react-hooks/exhaustive-deps
useSlidePreview(draft, setDraft, more => setMedia(m => ({ ...m, ...more })))
const dirty = useMemo(() => !!(draft && saved && JSON.stringify(savedBody(draft)) !== JSON.stringify(savedBody(saved))), [draft, saved])
const draftBad = useMemo(() => (draft ? misfits([draft], media, draft.orientation)[draft.id] || [] : []), [draft, media])
const draftBad = useMemo(() => (draft ? misfits([draft], media, shapeOf(draft))[draft.id] || [] : []), [draft, media])
if (!draft) return <div className="flex justify-center p-6"><Spinner /></div>
const set = patch => setDraft(d => ({ ...d, ...patch }))
@@ -130,7 +133,8 @@ function SavedSlideEditor({ id, venue, onClose }) {
}
onClose()
}
const tall = draft.orientation === 'portrait'
const shape = shapeOf(draft)
const tall = shapeRatio(shape) < 1
return (
<div className="x-page__fill grid gap-5 lg:grid-cols-2" data-testid="signage-saved-editor" data-id={id}>
@@ -145,16 +149,14 @@ function SavedSlideEditor({ id, venue, onClose }) {
}>
<div className="p-card grid gap-6 content-start">
<div className="mx-auto w-full" style={{ maxWidth: tall ? '22rem' : undefined }}>
<SlidePreview slide={draft} media={mediaLookup(media)} venue={venue} orientation={draft.orientation} playing editor={editor} testid="signage-saved-live" />
<SlidePreview slide={draft} media={mediaLookup(media)} venue={venue} orientation={shape} playing editor={editor} testid="signage-saved-live" />
</div>
<div className="grid gap-4 sm:grid-cols-[minmax(0,1fr)_auto] items-end">
<Field label={t('signage.library.name')}>
<Input value={draft.name || ''} maxLength={80} onChange={e => set({ name: e.target.value })} data-testid="signage-saved-name" />
</Field>
<Field label={t('signage.orientation')}>
<Segmented value={draft.orientation} onChange={v => set({ orientation: v })} data-testid="signage-saved-orientation"
options={['landscape', 'portrait'].map(o => ({ value: o, label: t(`signage.orientations.${o}`), icon: o === 'portrait' ? <Smartphone size={15} aria-hidden="true" /> : <Monitor size={15} aria-hidden="true" /> }))} />
</Field>
<ShapeField value={draft} testId="signage-saved-orientation"
onChange={v => set({ orientation: v.orientation || (shapeRatio(v.aspect) < 1 ? 'portrait' : 'landscape'), aspect: v.aspect ?? null })} />
</div>
<Field label={t('signage.library.description')} hint={t('signage.library.descriptionHint')}>
<Textarea rows={3} value={draft.description || ''} maxLength={300} onChange={e => set({ description: e.target.value })} data-testid="signage-saved-description" />
@@ -167,7 +169,7 @@ function SavedSlideEditor({ id, venue, onClose }) {
</Pane>
<Pane header={<h3 className="px-card py-card-y text-body font-semibold text-ink">{t('signage.library.settings')}</h3>}>
<div className="p-card grid gap-7 content-start">
<SlideBasics slide={draft} onChange={setDraft} showName={false} orientation={draft.orientation} />
<SlideBasics slide={draft} onChange={setDraft} showName={false} orientation={shape} />
<SlideEditor slide={draft} onChange={setDraft} media={media} onMedia={item => setMedia(m => ({ ...m, [String(item.id)]: mediaEntry(item) }))}
misfit={draftBad} widget={widget} onWidget={setWidget} />
</div>
@@ -30,6 +30,8 @@ export const duplicateSaved = id => client.post(`/api/signage/library/${id}/dupl
export const listScreens = () => client.get('/api/signage/screens').then(data)
export const updateScreen = (id, body) => client.put(`/api/signage/screens/${id}`, body).then(data)
// calibrating a screen's picture (6R.13): the TV outlines its area while on
export const calibrateScreen = (id, on) => client.post(`/api/signage/screens/${id}/calibrate`, { on }).then(data)
// the schedule lines (2026-11-21): all of them, saved together
export const listSchedules = () => client.get('/api/signage/schedules').then(data)
@@ -1,4 +1,5 @@
// The signage editor's pure helpers (plan step 5.6a): unit-tested in tests/signage.test.mjs.
import { shapeRatio } from '@xenia/signage/logic'
export const KINDS = ['image', 'video', 'text', 'menu', 'blank'] // blank: a background and widgets (2026-11-21)
export const TRANSITIONS = ['fade', 'slide', 'zoom', 'none']
@@ -44,11 +45,11 @@ export function slideFromTemplate(tpl, t = k => k) {
return { kind, ...fields, content: filled }
}
/** Does a picture / video fit a playlist's orientation? null when its size isn't known. */
export function fitsOrientation(media, orientation) {
/** Does a picture / video fit a playlist's shape ("landscape", "portrait", "21:9")? null when its size isn't known. */
export function fitsOrientation(media, shape) {
if (!media?.width || !media?.height) return null
const wide = media.width >= media.height
return orientation === 'portrait' ? !wide || media.width === media.height : wide
return shapeRatio(shape) < 1 ? !wide || media.width === media.height : wide
}
/** The media ids a slide shows big (its picture / video and its background): what must fit the shape. */
@@ -210,7 +211,7 @@ export function toggled(list, id) {
/** What a library slide sends back (PUT /api/signage/library/{id}): a slide's fields, its name, description and shape. */
export function savedBody(s) {
return { ...slideBody(s), name: (s.name || '').trim(), description: (s.description || '').trim() || null, orientation: s.orientation || 'landscape' }
return { ...slideBody(s), name: (s.name || '').trim(), description: (s.description || '').trim() || null, orientation: s.orientation || 'landscape', aspect: s.aspect || null }
}
/** A library slide added to a playlist: a copy of its fields (the playlist's slide is then its own). */
@@ -1,11 +1,11 @@
// How long a slide really plays (owner review 6, 2026-11-21): a menu board with pages plays whole
// rounds of them, so its seconds on screen are rounded up (the TV does the same: menuMs).
import { boardPages, menuMs } from '@xenia/signage'
import { boardPages, canvasOf, menuMs } from '@xenia/signage'
/** A menu board's pages on a TV of this shape (1 when it fits, or without its products yet). */
export function pagesOn(slide, orientation = 'landscape') {
/** A menu board's pages on a TV of this shape ("landscape", "portrait" or "21:9"; 1 when it fits, or without its products yet). */
export function pagesOn(slide, shape = 'landscape') {
if (slide?.kind !== 'menu' || !slide.menu) return 1
const [w, h] = orientation === 'portrait' ? [1080, 1920] : [1920, 1080]
const { w, h } = canvasOf(shape)
return Math.max(1, boardPages(slide, 0, w, h).length)
}