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:
@@ -134,13 +134,24 @@ export function slideMs(slide) {
|
||||
return Math.max(1, slide.duration_s || 10) * 1000
|
||||
}
|
||||
|
||||
/** The frame's size and turn for a screen: CSS for the box that holds the slides. */
|
||||
export function frameStyle(rotation) {
|
||||
/**
|
||||
* The frame's size and turn for a screen: CSS for the box that holds the slides. `size` (6R.13):
|
||||
* the picture area in px it fills (its parent), else the whole window.
|
||||
*/
|
||||
export function frameStyle(rotation, size) {
|
||||
const r = Number(rotation) || 0
|
||||
const W = size ? `${size.width}px` : '100vw'
|
||||
const H = size ? `${size.height}px` : '100vh'
|
||||
if (r === 90 || r === 270) {
|
||||
return { width: '100vh', height: '100vw', transform: `translate(-50%, -50%) rotate(${r}deg)`, top: '50%', left: '50%', position: 'absolute', containerType: 'size' }
|
||||
return { width: H, height: W, transform: `translate(-50%, -50%) rotate(${r}deg)`, top: '50%', left: '50%', position: 'absolute', containerType: 'size' }
|
||||
}
|
||||
return { width: '100vw', height: '100vh', transform: r === 180 ? 'rotate(180deg)' : undefined, top: 0, left: 0, position: 'absolute', containerType: 'size' }
|
||||
return { width: W, height: H, transform: r === 180 ? 'rotate(180deg)' : undefined, top: 0, left: 0, position: 'absolute', containerType: 'size' }
|
||||
}
|
||||
|
||||
/** The frame's own width × height (after its turn) for a picture area. */
|
||||
export function frameSize(rotation, size) {
|
||||
const r = Number(rotation) || 0
|
||||
return r === 90 || r === 270 ? { w: size.height, h: size.width } : { w: size.width, h: size.height }
|
||||
}
|
||||
|
||||
/** Every media address a playlist (or a schedule's playlists) needs, to keep on the device. */
|
||||
@@ -425,3 +436,75 @@ export function priceChars(groups, format) {
|
||||
for (const g of groups || []) for (const it of g.items || []) if (it.price != null) n = Math.max(n, String(format(it.price)).length)
|
||||
return n
|
||||
}
|
||||
|
||||
// ── slide shapes and the screen's picture area (6R.13, owner 2026-11-22) ─────────
|
||||
|
||||
/** Shapes offered for a playlist / a library slide beyond landscape and portrait (and the calibration presets). */
|
||||
export const SHAPES = ['16:9', '16:10', '21:9', '32:9', '4:3', '5:4', '1:1', '9:16', '10:16', '3:4']
|
||||
|
||||
/** "21:9" → [21, 9]; anything else → null. Shapes from 1:4 to 4:1. */
|
||||
export function parseAspect(a) {
|
||||
const m = /^(\d{1,2}):(\d{1,2})$/.exec(String(a || ''))
|
||||
if (!m) return null
|
||||
const w = Number(m[1])
|
||||
const h = Number(m[2])
|
||||
if (!w || !h || w / h > 4 || h / w > 4) return null
|
||||
return [w, h]
|
||||
}
|
||||
|
||||
/** What a playlist / library slide is built for: its custom shape ("21:9"), else landscape / portrait. */
|
||||
export const shapeOf = x => (x && parseAspect(x.aspect) ? x.aspect : x?.orientation === 'portrait' ? 'portrait' : 'landscape')
|
||||
|
||||
/** Width ÷ height of a shape ("landscape", "portrait" or "W:H"). */
|
||||
export function shapeRatio(shape) {
|
||||
if (shape === 'portrait') return 9 / 16
|
||||
const a = parseAspect(shape)
|
||||
return a ? a[0] / a[1] : 16 / 9
|
||||
}
|
||||
|
||||
/** The size a slide of this shape is laid out at (its long side 1920 px, as the editor's previews). */
|
||||
export function canvasOf(shape) {
|
||||
const r = shapeRatio(shape)
|
||||
return r >= 1 ? { w: 1920, h: Math.round(1920 / r) } : { w: Math.round(1920 * r), h: 1920 }
|
||||
}
|
||||
|
||||
/** The largest box of `ratio` (w ÷ h) inside W × H, centred: { left, top, width, height } in px. */
|
||||
export function fitBox(W, H, ratio) {
|
||||
if (!(W > 0) || !(H > 0) || !(ratio > 0)) return { left: 0, top: 0, width: Math.max(0, W || 0), height: Math.max(0, H || 0) }
|
||||
let width = W
|
||||
let height = W / ratio
|
||||
if (height > H) { height = H; width = H * ratio }
|
||||
return { left: (W - width) / 2, top: (H - height) / 2, width, height }
|
||||
}
|
||||
|
||||
/** A screen's picture area in its window: the window minus the calibrated insets (never smaller than 50 px). */
|
||||
export function pictureArea(win, area = {}) {
|
||||
const l = Math.max(0, area.left || 0)
|
||||
const t = Math.max(0, area.top || 0)
|
||||
const width = Math.max(50, win.w - l - Math.max(0, area.right || 0))
|
||||
const height = Math.max(50, win.h - t - Math.max(0, area.bottom || 0))
|
||||
return { left: l, top: t, width, height }
|
||||
}
|
||||
|
||||
/**
|
||||
* Calibration presets (6R.13): the insets that leave the largest box of a shape in the middle of
|
||||
* the window ("full": the whole window). → { left, top, right, bottom } in whole px.
|
||||
*/
|
||||
export function presetInsets(win, shape) {
|
||||
if (shape === 'full' || !win?.w || !win?.h) return { left: 0, top: 0, right: 0, bottom: 0 }
|
||||
const b = fitBox(win.w, win.h, shapeRatio(shape))
|
||||
const left = Math.floor(b.left)
|
||||
const top = Math.floor(b.top)
|
||||
return { left, top, right: Math.max(0, win.w - left - Math.round(b.width)), bottom: Math.max(0, win.h - top - Math.round(b.height)) }
|
||||
}
|
||||
|
||||
/** "1920 × 1080" → its nearest named shape ("16:9") when within 2 % (a "21:9" monitor is really 64:27), else "W:H" reduced (e.g. "43:18"). */
|
||||
export function shapeName(w, h) {
|
||||
if (!(w > 0) || !(h > 0)) return ''
|
||||
const r = w / h
|
||||
const near = SHAPES.find(s => Math.abs(shapeRatio(s) - r) / r < 0.02)
|
||||
if (near) return near
|
||||
const g = (a, b) => (b ? g(b, a % b) : a)
|
||||
const d = g(Math.round(w), Math.round(h)) || 1
|
||||
return `${Math.round(w) / d}:${Math.round(h) / d}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user