feat(manager): the signage editor: playlists, the timeline, slides with a live preview, templates (platform-v2 step 5.6a)

Management → Signage: playlists (name, landscape / portrait, default
transition, duplicate, delete with the screens it plays on); the timeline
(drag or arrows to reorder, duplicate, remove, on / off, time and when it
shows at a glance, a round's total time); a slide's settings (name, seconds or
a video to its end, transition, days / hours / dates, the picture or video,
fit, text, alignment, font, colour, size, background colour or photo with
darkening; a menu board's title, columns and colours) with a live preview drawn
by @xenia/signage at 1920 × 1080 and scaled down; new slides empty or from
templates (promotion, announcement, happy hour 17-19, welcome, menu board,
video); a warning on the slide and its card when a picture or video doesn't
fit the playlist's shape. Unit tests (4), e2e signage.mjs builds a playlist in
the manager and the TV plays it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 20:59:33 +02:00
co-authored by Claude Opus 5.5
parent 4d63216167
commit 152388321e
15 changed files with 1175 additions and 9 deletions
@@ -0,0 +1,117 @@
// The signage editor's pure helpers (plan step 5.6a): unit-tested in tests/signage.test.mjs.
export const KINDS = ['image', 'video', 'text', 'menu']
export const TRANSITIONS = ['fade', 'slide', 'zoom', 'none']
export const FONT_KEYS = ['sans', 'serif', 'rounded', 'condensed', 'display']
/** Ready-made slides to start from: { key, kind, slide fields, content }. '@x' texts are filled from
* `signage.templates.<key>.<x>` in the manager's language when the slide is made. */
export const TEMPLATES = [
{ key: 'promo', kind: 'image', duration_s: 8, content: { fit: 'cover' } },
{ key: 'announcement', kind: 'text', duration_s: 10, content: {
title: '', body: '', align: 'center', vertical: 'middle', font: 'sans', text_colour: '#ffffff', text_size: 100,
background: { kind: 'colour', colour: '#1e293b', media_id: null, dim: 0, fit: 'cover' },
widgets: [{ kind: 'name', position: 'top-left' }, { kind: 'clock', position: 'top-right' }],
} },
{ key: 'happyHour', kind: 'text', duration_s: 10, time_from: '17:00', time_to: '19:00', content: {
title: '@title', body: '@body', align: 'center', vertical: 'middle', font: 'display', text_colour: '#fde68a', text_size: 120,
background: { kind: 'colour', colour: '#7c2d12', media_id: null, dim: 0, fit: 'cover' },
} },
{ key: 'welcome', kind: 'text', duration_s: 10, content: {
title: '@title', body: '', align: 'center', vertical: 'middle', font: 'serif', text_colour: '#ffffff', text_size: 110,
background: { kind: 'colour', colour: '#14532d', media_id: null, dim: 0, fit: 'cover' },
widgets: [{ kind: 'logo', position: 'top-center', size: 'large' }, { kind: 'message', position: 'bottom-bar' }, { kind: 'date', position: 'bottom-bar' }],
} },
{ key: 'menuBoard', kind: 'menu', duration_s: 20, content: {
title: '@title', select: 'all', group_by_category: true, columns: 2, sales_point: 'in_store', sold_out: 'strike',
background: { kind: 'colour', colour: '#111827', media_id: null, dim: 0, fit: 'cover' }, accent_colour: '#f59e0b',
widgets: [{ kind: 'clock', position: 'top-right' }, { kind: 'message', position: 'bottom-bar' }],
} },
{ key: 'video', kind: 'video', video_to_end: true, content: { fit: 'cover', muted: true } },
]
/** The body to create a slide from a template; `t` fills its '@' texts. */
export function slideFromTemplate(tpl, t = k => k) {
const { key, kind, content, ...fields } = tpl
const filled = JSON.parse(JSON.stringify(content || {}), (_, v) =>
(typeof v === 'string' && v.startsWith('@') ? t(`signage.templates.${key}.${v.slice(1)}`) : v))
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) {
if (!media?.width || !media?.height) return null
const wide = media.width >= media.height
return orientation === 'portrait' ? !wide || media.width === media.height : wide
}
/** The media ids a slide shows big (its picture / video and its background): what must fit the shape. */
export function bigMedia(slide) {
const c = slide?.content || {}
return [c.media_id, c.background?.kind === 'media' ? c.background.media_id : null].filter(Boolean)
}
/** The slides whose big media doesn't fit the playlist's orientation: { slideId: [mediaId] }. */
export function misfits(slides, media, orientation) {
const out = {}
for (const s of slides || []) {
const bad = bigMedia(s).filter(id => fitsOrientation(media?.[String(id)], orientation) === false)
if (bad.length) out[s.id] = bad
}
return out
}
/** A short line about when a slide shows: [{ key, params }] for the timeline card ([] = always). */
export function windowParts(slide) {
const parts = []
if (slide.days?.length && slide.days.length < 7) parts.push({ key: 'days', params: { days: slide.days } })
if (slide.time_from || slide.time_to) parts.push({ key: 'hours', params: { from: slide.time_from || '00:00', to: slide.time_to || '24:00' } })
if (slide.date_from || slide.date_to) parts.push({ key: 'dates', params: { from: slide.date_from || '…', to: slide.date_to || '…' } })
return parts
}
/** The playlist's total time for one round (videos to their end count by their length if known). */
export function totalSeconds(slides, media) {
let total = 0
for (const s of slides || []) {
if (!s.enabled) continue
if (s.kind === 'video' && s.video_to_end) {
const ms = media?.[String(s.content?.media_id)]?.duration_ms
total += ms ? Math.round(ms / 1000) : s.duration_s || 10
} else total += s.duration_s || 10
}
return total
}
/** Move the item at `from` to `to` in a copy of `list`. */
export function moved(list, from, to) {
const out = [...list]
if (from === to || from < 0 || to < 0 || from >= out.length || to >= out.length) return out
const [x] = out.splice(from, 1)
out.splice(to, 0, x)
return out
}
/** The fields of a slide that the editor sends back (PUT /api/signage/slides/{id}). */
export function slideBody(s) {
return {
name: s.name || null, duration_s: s.duration_s, transition: s.transition || null, video_to_end: !!s.video_to_end, enabled: !!s.enabled,
days: s.days || [], time_from: s.time_from || null, time_to: s.time_to || null, date_from: s.date_from || null, date_to: s.date_to || null,
content: s.content || {},
}
}
/** A library item as the slide views need it (the same shape as the playlist's media map). */
export function mediaEntry(item) {
const u = item.urls || {}
return { id: item.id, kind: item.kind, name: item.name, width: item.width, height: item.height, duration_ms: item.duration_ms,
url: u.full || u.original, thumb: u.thumb, builtin: !!item.builtin }
}
/** media(id) for the slide views: the playlist's media map (+ what the editor just picked). */
export function mediaLookup(map) {
return id => {
const m = map?.[String(id)]
return m ? { ...m, src: m.url } : null
}
}