|
|
|
@@ -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 }
|
|
|
|
|