feat(terminal): older TVs get a legacy build with a compatibility layer; modern output unchanged

- @vitejs/plugin-legacy: browsers without import.meta.resolve (older than Chrome 105 /
  Firefox 106 / Safari 16.4) load a second copy built for Chrome 79 / Firefox 78 / Safari 13
  with polyfills. The modern targets and the stylesheet stay on Vite's own defaults, so modern
  chunks are byte-identical to before (only plugin-legacy's 230-byte guard in the entry).
- terminal/src/compat.js (legacy copy only): swaps in <name>.compat.css (lightningcss for the
  older targets), sets container-size variables for signage slides, emulates flex gap.
- @xenia/signage cq()/CQ_BOX: container units as before where supported, calc(var()) fallback
  otherwise; EmbeddedSlide no longer uses inline `inset`.
- Shared Notice (@xenia/ui); "Devices that work" in Pair a device and Signage -> Screens (EN/EL).
- tests/e2e/compat.mjs: modern browser loads nothing extra; a simulated older TV runs the legacy
  copy and the layer, pairs, and plays a slide at the same sizes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 17:26:16 +02:00
co-authored by Claude Opus 5.5
parent aa8ba5d1d4
commit 14d592d963
23 changed files with 625 additions and 40 deletions
+1
View File
@@ -52,6 +52,7 @@ Every page is on `<Page>` except Inventory → Stock (a placeholder). Two-column
| A colour (a venue's: data) | `ColourField` (`auto`, `opacity`, `presets`) | a field with its swatch and code; its panel (over the page) has 12 ready colours, the picker, the opacity (`#rrggbbaa`) and the code. `auto` = a first choice that leaves it to something else ("As the slide"). **Never** a bare `<input type="color">` | | A colour (a venue's: data) | `ColourField` (`auto`, `opacity`, `presets`) | a field with its swatch and code; its panel (over the page) has 12 ready colours, the picker, the opacity (`#rrggbbaa`) and the code. `auto` = a first choice that leaves it to something else ("As the slide"). **Never** a bare `<input type="color">` |
| An icon from a set | `IconPicker` (`icons` = { key: component }) | a field showing the icon; a grid of the set over the page, "No icon" first | | An icon from a set | `IconPicker` (`icons` = { key: component }) | a field showing the icon; a grid of the set over the page, "No icon" first |
| A whole number (seconds, counts) | `NumberInput` (`min`, `max`, `suffix`) | − / + on its sides, as tall as an input; it may be emptied while typing (`onChange(null)`): the form shows the error and blocks saving. **Never** clamp on every key (the user can't clear the field) | | A whole number (seconds, counts) | `NumberInput` (`min`, `max`, `suffix`) | − / + on its sides, as tall as an input; it may be emptied while typing (`onChange(null)`): the form shows the error and blocks saving. **Never** clamp on every key (the user can't clear the field) |
| A note in a box (what works, a caution) | `Notice` (`tone`, `title`, `icon`, `items` = [{ tone, label, text }]) | a tinted box with a bar on its left; `items` are points with a tone dot and a bold label. **Never** a local `bg-info-soft` paragraph rebuilt per page |
| A slider with its value | `Slider` (`suffix`) | framed and as tall as the fields beside it; the value sits as close to it as the frame's padding. **Never** a bare `<input type="range">` | | A slider with its value | `Slider` (`suffix`) | framed and as tall as the fields beside it; the value sits as close to it as the frame's padding. **Never** a bare `<input type="range">` |
| Fields that should wrap | `FieldRow` (`min`, `shade` on every other row) | each field keeps its least width; a row that wraps is framed (and tinted with `shade`), a row on one line looks like any row | | Fields that should wrap | `FieldRow` (`min`, `shade` on every other row) | each field keeps its least width; a row that wraps is framed (and tinted with `shade`), a row on one line looks like any row |
| Toggles that go together (bold / italic / underline) | `Segmented multiple` | value is an array | | Toggles that go together (bold / italic / underline) | `Segmented multiple` | value is an array |
@@ -0,0 +1,18 @@
// Which devices run the apps (2026-11-21): modern browsers run everything; older ones (a TV's built-in
// browser from 2021–2023) get the compatibility layer (terminal/vite.config.js, terminal/src/compat.js);
// older still, a blank page. Shown in the "Pair a device" dialog and on Signage → Screens.
import { useTranslation } from '@xenia/i18n'
import { Notice } from '@xenia/ui'
import { MonitorSmartphone } from 'lucide-react'
export function DeviceSupport({ className }) {
const { t } = useTranslation('manager')
return (
<Notice tone="info" icon={<MonitorSmartphone size={16} />} title={t('devices.support.title')} className={className} data-testid="device-support"
items={[
{ tone: 'success', label: t('devices.support.bestLabel'), text: t('devices.support.best') },
{ tone: 'warning', label: t('devices.support.compatLabel'), text: t('devices.support.compat') },
{ tone: 'danger', label: t('devices.support.oldLabel'), text: t('devices.support.old') },
]} />
)
}
@@ -12,6 +12,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
import { useSearchParams } from 'react-router-dom' import { useSearchParams } from 'react-router-dom'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { MonitorSmartphone, Plus } from 'lucide-react' import { MonitorSmartphone, Plus } from 'lucide-react'
import { DeviceSupport } from './DeviceSupport'
import { errorMessage, parseError } from '@xenia/api' import { errorMessage, parseError } from '@xenia/api'
import { useTranslation, useFormat } from '@xenia/i18n' import { useTranslation, useFormat } from '@xenia/i18n'
import { Button, Dialog, EmptyState, Field, Input, Page, Select, Spinner } from '@xenia/ui' import { Button, Dialog, EmptyState, Field, Input, Page, Select, Spinner } from '@xenia/ui'
@@ -244,6 +245,7 @@ function PairDialog({ apps, usage, devices, appName, limitLabel, initialApp, onC
<Input value={code} onChange={e => setCode(normalizeCode(e.target.value))} autoComplete="off" spellCheck={false} <Input value={code} onChange={e => setCode(normalizeCode(e.target.value))} autoComplete="off" spellCheck={false}
className="font-mono tracking-[0.3em] text-center uppercase" autoFocus /> className="font-mono tracking-[0.3em] text-center uppercase" autoFocus />
</Field> </Field>
<DeviceSupport />
<Field label={t('devices.form.app')} error={full ? t('devices.form.full', { label: limitLabel(appKey), max: usage[appKey].max }) : undefined}> <Field label={t('devices.form.app')} error={full ? t('devices.form.full', { label: limitLabel(appKey), max: usage[appKey].max }) : undefined}>
<Select value={appKey} onChange={e => { <Select value={appKey} onChange={e => {
const next = e.target.value const next = e.target.value
@@ -10,6 +10,7 @@ import { AlertTriangle, CalendarClock, Monitor, Smartphone } from 'lucide-react'
import { errorMessage } from '@xenia/api' import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n' import { useTranslation } from '@xenia/i18n'
import { Dropdown, EmptyState, Field, Spinner } from '@xenia/ui' import { Dropdown, EmptyState, Field, Spinner } from '@xenia/ui'
import { DeviceSupport } from '../platform/DeviceSupport'
import * as api from './signageApi' import * as api from './signageApi'
export default function ScreensTab() { export default function ScreensTab() {
@@ -30,12 +31,18 @@ export default function ScreensTab() {
} }
if (!screens) return <div className="flex justify-center p-6"><Spinner /></div> if (!screens) return <div className="flex justify-center p-6"><Spinner /></div>
if (!screens.length) { if (!screens.length) {
return <EmptyState title={t('signage.screens.none')} description={t('signage.screens.noneHint')} return (
action={<Link to="/devices?pair=signage" className="text-accent-ink font-medium">{t('signage.screens.pair')}</Link>} /> <div className="grid gap-4">
<EmptyState title={t('signage.screens.none')} description={t('signage.screens.noneHint')}
action={<Link to="/devices?pair=signage" className="text-accent-ink font-medium">{t('signage.screens.pair')}</Link>} />
<DeviceSupport className="max-w-3xl" />
</div>
)
} }
return ( return (
<div className="grid gap-3"> <div className="grid gap-3">
<p className="text-label text-ink-2 max-w-3xl">{t('signage.screens.intro')}</p> <p className="text-label text-ink-2 max-w-3xl">{t('signage.screens.intro')}</p>
<DeviceSupport className="max-w-3xl" />
<ul className="grid gap-3 xl:grid-cols-2" data-testid="signage-screens"> <ul className="grid gap-3 xl:grid-cols-2" data-testid="signage-screens">
{screens.map(s => { {screens.map(s => {
const Icon = s.orientation === 'portrait' ? Smartphone : Monitor const Icon = s.orientation === 'portrait' ? Smartphone : Monitor
+114 -3
View File
@@ -3210,6 +3210,47 @@
"integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==", "integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@vitejs/plugin-legacy": {
"version": "8.2.4",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-legacy/-/plugin-legacy-8.2.4.tgz",
"integrity": "sha512-EGXOSY2HLuYfta1e3Y1z+kEiQK0clJoO22L4z13SyzhM+9cL9Xa3MSvxlawflGU2n2rHzMcmjC94yWjLa3UjoQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/core": "^7.29.7",
"@babel/plugin-transform-dynamic-import": "^7.29.7",
"@babel/plugin-transform-modules-systemjs": "^7.29.8",
"@babel/preset-env": "^7.29.7",
"babel-plugin-polyfill-corejs3": "^0.14.2",
"babel-plugin-polyfill-regenerator": "^0.6.8",
"browserslist": "^4.29.5",
"browserslist-to-esbuild": "^2.1.1",
"core-js": "^3.51.0",
"magic-string": "^1.4.5",
"regenerator-runtime": "^0.14.1",
"systemjs": "^6.15.1"
},
"engines": {
"node": "^20.19.0 || >=22.12.0"
},
"funding": {
"url": "https://github.com/vitejs/vite?sponsor=1"
},
"peerDependencies": {
"terser": "^5.16.0",
"vite": "^8.0.0"
}
},
"node_modules/@vitejs/plugin-legacy/node_modules/magic-string": {
"version": "1.4.5",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz",
"integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==",
"dev": true,
"license": "MIT",
"dependencies": {
"@jridgewell/sourcemap-codec": "^1.6.0"
}
},
"node_modules/@xenia/access": { "node_modules/@xenia/access": {
"resolved": "packages/access", "resolved": "packages/access",
"link": true "link": true
@@ -3699,6 +3740,25 @@
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
} }
}, },
"node_modules/browserslist-to-esbuild": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/browserslist-to-esbuild/-/browserslist-to-esbuild-2.1.1.tgz",
"integrity": "sha512-KN+mty6C3e9AN8Z5dI1xeN15ExcRNeISoC3g7V0Kax/MMF9MSoYA2G7lkTTcVUFntiEjkpI0HNgqJC1NjdyNUw==",
"dev": true,
"license": "MIT",
"dependencies": {
"meow": "^13.0.0"
},
"bin": {
"browserslist-to-esbuild": "cli/index.js"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
"browserslist": "*"
}
},
"node_modules/buffer-crc32": { "node_modules/buffer-crc32": {
"version": "0.2.13", "version": "0.2.13",
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
@@ -3953,6 +4013,21 @@
"url": "https://opencollective.com/express" "url": "https://opencollective.com/express"
} }
}, },
"node_modules/core-js": {
"version": "3.51.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.51.0.tgz",
"integrity": "sha512-7bDKx/5jm5MxzsXxc93g6Z2+4ZsuT/MddrfRmTDJNAkWsYWHU8EVNEsBiIEWnMAMCHMmRfUEjkuo3jeNBOIHRw==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"engines": {
"node": "*"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
}
},
"node_modules/core-js-compat": { "node_modules/core-js-compat": {
"version": "3.51.0", "version": "3.51.0",
"resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.51.0.tgz", "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.51.0.tgz",
@@ -6570,6 +6645,19 @@
"node": ">= 0.4" "node": ">= 0.4"
} }
}, },
"node_modules/meow": {
"version": "13.2.0",
"resolved": "https://registry.npmjs.org/meow/-/meow-13.2.0.tgz",
"integrity": "sha512-pxQJQzB6djGPXh08dacEloMFopsOqGVRKFPYvPOt9XDZ1HasbgDZA74CJGreSU4G3Ak7EFJGoiH2auq+yXISgA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/merge2": { "node_modules/merge2": {
"version": "1.4.1", "version": "1.4.1",
"resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
@@ -7552,6 +7640,13 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/regenerator-runtime": {
"version": "0.14.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz",
"integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==",
"dev": true,
"license": "MIT"
},
"node_modules/regexp.prototype.flags": { "node_modules/regexp.prototype.flags": {
"version": "1.5.4", "version": "1.5.4",
"resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.4.tgz", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.4.tgz",
@@ -8388,6 +8483,13 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/systemjs": {
"version": "6.15.1",
"resolved": "https://registry.npmjs.org/systemjs/-/systemjs-6.15.1.tgz",
"integrity": "sha512-Nk8c4lXvMB98MtbmjX7JwJRgJOL8fluecYCfCeYBznwmpOs8Bf15hLM6z4z71EDAhQVrQrI+wt1aLWSXZq+hXA==",
"dev": true,
"license": "MIT"
},
"node_modules/tailwindcss": { "node_modules/tailwindcss": {
"version": "3.4.19", "version": "3.4.19",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.19.tgz", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.19.tgz",
@@ -8485,9 +8587,9 @@
"link": true "link": true
}, },
"node_modules/terser": { "node_modules/terser": {
"version": "5.51.2", "version": "5.51.4",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.51.2.tgz", "resolved": "https://registry.npmjs.org/terser/-/terser-5.51.4.tgz",
"integrity": "sha512-bWnjSNscmuI+GJze6ZupnHP8G/cTcsJF+bXCeQknk2SHQsgbNJnLrqiH9jZ2W4STPVXH2mDKKRX3iwPhc9Cn/Q==", "integrity": "sha512-VPi1CkDvCWLGUVIToctNBG+NdHbSXwOPjHJnQ3pdB0XknaldnI76wSkAFOGxV2ZdkzOP5d6gpQ5c58XvDghRvw==",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"dependencies": { "dependencies": {
"@jridgewell/source-map": "^0.3.3", "@jridgewell/source-map": "^0.3.3",
@@ -9627,8 +9729,14 @@
"name": "@xenia/ui", "name": "@xenia/ui",
"version": "0.0.0", "version": "0.0.0",
"peerDependencies": { "peerDependencies": {
"qrcode.react": "^4.2.0",
"react": "^19.0.0", "react": "^19.0.0",
"react-dom": "^19.0.0" "react-dom": "^19.0.0"
},
"peerDependenciesMeta": {
"qrcode.react": {
"optional": true
}
} }
}, },
"terminal": { "terminal": {
@@ -9650,14 +9758,17 @@
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.39.5", "@eslint/js": "^9.39.5",
"@vitejs/plugin-legacy": "^8.2.4",
"@vitejs/plugin-react": "^6.3.0", "@vitejs/plugin-react": "^6.3.0",
"autoprefixer": "^10.6.2", "autoprefixer": "^10.6.2",
"eslint": "^9.39.5", "eslint": "^9.39.5",
"eslint-plugin-react-hooks": "^7.1.1", "eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.7", "eslint-plugin-react-refresh": "^0.5.7",
"globals": "^17.14.0", "globals": "^17.14.0",
"lightningcss": "^1.33.0",
"postcss": "^8.5.33", "postcss": "^8.5.33",
"tailwindcss": "^3.4.16", "tailwindcss": "^3.4.16",
"terser": "^5.51.4",
"vite": "^8.3.8" "vite": "^8.3.8"
} }
}, },
+10 -1
View File
@@ -234,7 +234,16 @@
"removeTitle": "Αφαίρεση: {{name}};", "removeTitle": "Αφαίρεση: {{name}};",
"removeBody": "Σταματά αμέσως και δείχνει την οθόνη σύζευξης. Για να ξαναχρησιμοποιηθεί, κάντε ξανά σύζευξη.", "removeBody": "Σταματά αμέσως και δείχνει την οθόνη σύζευξης. Για να ξαναχρησιμοποιηθεί, κάντε ξανά σύζευξη.",
"changeAppBody": "Όποιος είναι συνδεδεμένος σε αυτή αποσυνδέεται.", "changeAppBody": "Όποιος είναι συνδεδεμένος σε αυτή αποσυνδέεται.",
"limitReached": "{{label}}: η άδεια επιτρέπει {{max}}. Αφαιρέστε μία ή ζητήστε μεγαλύτερη άδεια." "limitReached": "{{label}}: η άδεια επιτρέπει {{max}}. Αφαιρέστε μία ή ζητήστε μεγαλύτερη άδεια.",
"support": {
"title": "Συσκευές που λειτουργούν",
"bestLabel": "Ιδανικά:",
"best": "Chrome ή Edge 111, Firefox 114, Safari 16.4 ή νεότερα: ενημερωμένα κινητά, tablet και υπολογιστές, Android TV box, οι περισσότερες τηλεοράσεις από το 2024 και μετά. Όλα τρέχουν σε πλήρη ταχύτητα.",
"compatLabel": "Λειτουργεί, με επίπεδο συμβατότητας:",
"compat": "Chrome 79, Firefox 78, Safari 13 ή νεότερα, π.χ. ο ενσωματωμένος browser τηλεοράσεων LG και Samsung από το 2021 έως το 2023. Φτιαγμένο για οθόνες ψηφιακής σήμανσης: μπορεί να φορτώνει και να παίζει πιο αργά. Για ταμεία, οθόνες κουζίνας και tablet μενού χρησιμοποιήστε νεότερη συσκευή.",
"oldLabel": "Πολύ παλιό:",
"old": "οτιδήποτε παλαιότερο (π.χ. τηλεοράσεις LG του 2020 ή παλαιότερες) δείχνει λευκή σελίδα. Συνδέστε στην τηλεόραση ένα Android TV box ή stick (οποιοδήποτε πρόσφατο κάνει) και ανοίξτε εκεί τη διεύθυνση."
}
}, },
"roles": { "roles": {
"superadmin": "Superadmin", "superadmin": "Superadmin",
+10 -1
View File
@@ -234,7 +234,16 @@
"removeTitle": "Remove {{name}}?", "removeTitle": "Remove {{name}}?",
"removeBody": "It stops at once and shows the pairing screen. To use it again, pair it again.", "removeBody": "It stops at once and shows the pairing screen. To use it again, pair it again.",
"changeAppBody": "Whoever is signed in on it is signed out.", "changeAppBody": "Whoever is signed in on it is signed out.",
"limitReached": "{{label}}: the license allows {{max}}. Remove one or ask for a bigger license." "limitReached": "{{label}}: the license allows {{max}}. Remove one or ask for a bigger license.",
"support": {
"title": "Devices that work",
"bestLabel": "Best:",
"best": "Chrome or Edge 111, Firefox 114, Safari 16.4 or newer: phones, tablets and computers that are up to date, Android TV boxes, most TVs from 2024 on. Everything runs at full speed.",
"compatLabel": "Works, with a compatibility layer:",
"compat": "Chrome 79, Firefox 78, Safari 13 or newer, e.g. the built-in browser of LG and Samsung TVs from 2021 to 2023. Made for screens with signage: it may load and play more slowly. For tills, kitchen screens and menu tablets use a newer device.",
"oldLabel": "Too old:",
"old": "anything older (e.g. LG TVs from 2020 or before) shows a blank page. Plug an Android TV box or stick into the TV (any recent one is fine) and open the address there."
}
}, },
"roles": { "roles": {
"superadmin": "Superadmin", "superadmin": "Superadmin",
+2 -1
View File
@@ -4,6 +4,7 @@
// slide.extras: what the server added to its widgets by path (QR links, menus, slides inside stacks) // slide.extras: what the server added to its widgets by path (QR links, menus, slides inside stacks)
import { useEffect, useLayoutEffect, useRef, useState } from 'react' import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { boardPages, pageAt } from './logic.js' import { boardPages, pageAt } from './logic.js'
import { CQ_BOX } from './cq.js'
import { BlankSlide, MenuSlide, TextSlide } from './Slides.jsx' import { BlankSlide, MenuSlide, TextSlide } from './Slides.jsx'
export function SlideView({ slide, media, venue, now, pages, page, onEnded, playing = true }) { export function SlideView({ slide, media, venue, now, pages, page, onEnded, playing = true }) {
@@ -39,7 +40,7 @@ function EmbeddedSlide({ slide, media, venue, now }) {
const pages = slide.kind === 'menu' && size ? boardPages(slide, 0, size.w || 16, size.h || 9) : null const pages = slide.kind === 'menu' && size ? boardPages(slide, 0, size.w || 16, size.h || 9) : null
const page = pages ? pageAt(pages.length, slide.content?.page_seconds, now.getTime()) : 0 const page = pages ? pageAt(pages.length, slide.content?.page_seconds, now.getTime()) : 0
return ( return (
<div ref={ref} style={{ position: 'absolute', inset: 0, overflow: 'hidden', containerType: 'size' }} data-testid="signage-embedded" data-embedded="" data-kind={slide.kind} data-id={slide.id}> <div ref={ref} style={{ position: 'absolute', top: 0, right: 0, bottom: 0, left: 0, overflow: 'hidden', containerType: 'size' }} {...CQ_BOX} data-testid="signage-embedded" data-embedded="" data-kind={slide.kind} data-id={slide.id}>
{size && <SlideView slide={{ ...slide, video_to_end: false }} media={media} venue={venue} now={now} pages={pages} page={page} />} {size && <SlideView slide={{ ...slide, video_to_end: false }} media={media} venue={venue} now={now} pages={pages} page={page} />}
</div> </div>
) )
+29 -28
View File
@@ -5,6 +5,7 @@
import { Cloud, CloudFog, CloudLightning, CloudMoon, CloudRain, CloudSnow, CloudSun, Moon, Sun } from 'lucide-react' import { Cloud, CloudFog, CloudLightning, CloudMoon, CloudRain, CloudSnow, CloudSun, Moon, Sun } from 'lucide-react'
import { QRCodeSVG } from 'qrcode.react' import { QRCodeSVG } from 'qrcode.react'
import { BADGE_ICONS } from './badges' import { BADGE_ICONS } from './badges'
import { cq, CQ_BOX } from './cq'
import { useFormat, useTranslation } from '@xenia/i18n' import { useFormat, useTranslation } from '@xenia/i18n'
import { badgeColours, badgeName, cellWidgets, TIGHT, fitUnit, FONTS, itemBadges, menuLook, menuPages, pageAt, priceChars, textWidth, visibleGroups, weatherIcon, widgetAlign } from './logic' import { badgeColours, badgeName, cellWidgets, TIGHT, fitUnit, FONTS, itemBadges, menuLook, menuPages, pageAt, priceChars, textWidth, visibleGroups, weatherIcon, widgetAlign } from './logic'
@@ -30,10 +31,10 @@ export function TextSlide({ content: c, media, venue, now, extras, embed }) {
<Background bg={c.background} media={media} /> <Background bg={c.background} media={media} />
<div className="absolute inset-0 flex flex-col" style={{ <div className="absolute inset-0 flex flex-col" style={{
justifyContent: JUSTIFY[c.vertical] || 'center', textAlign: c.align || 'center', justifyContent: JUSTIFY[c.vertical] || 'center', textAlign: c.align || 'center',
padding: `${hasBar(c, 'top-bar') ? 14 : 8}cqmin 8cqmin ${hasBar(c, 'bottom-bar') ? 14 : 8}cqmin`, gap: `${3 * scale}cqmin`, padding: `${cq(hasBar(c, 'top-bar') ? 14 : 8)} ${cq(8)} ${cq(hasBar(c, 'bottom-bar') ? 14 : 8)}`, gap: cq(3 * scale),
}}> }}>
{c.title && <h1 style={{ fontSize: `${9 * scale}cqmin`, lineHeight: 1.1, fontWeight: 800, margin: 0 }} data-testid="signage-title">{c.title}</h1>} {c.title && <h1 style={{ fontSize: cq(9 * scale), lineHeight: 1.1, fontWeight: 800, margin: 0 }} data-testid="signage-title">{c.title}</h1>}
{c.body && <p style={{ fontSize: `${4.5 * scale}cqmin`, lineHeight: 1.35, margin: 0, whiteSpace: 'pre-line' }} data-testid="signage-body">{c.body}</p>} {c.body && <p style={{ fontSize: cq(4.5 * scale), lineHeight: 1.35, margin: 0, whiteSpace: 'pre-line' }} data-testid="signage-body">{c.body}</p>}
</div> </div>
<Widgets widgets={c.widgets} media={media} venue={venue} now={now} colour={c.text_colour} extras={extras} embed={embed} /> <Widgets widgets={c.widgets} media={media} venue={venue} now={now} colour={c.text_colour} extras={extras} embed={embed} />
</div> </div>
@@ -60,23 +61,23 @@ export function MenuSlide({ slide, media, venue, now, page, pages, extras, embed
<div className="absolute inset-0" style={{ color: c.text_colour || '#fff', fontFamily: FONTS[c.font] || FONTS.sans }}> <div className="absolute inset-0" style={{ color: c.text_colour || '#fff', fontFamily: FONTS[c.font] || FONTS.sans }}>
<Background bg={c.background} media={media} /> <Background bg={c.background} media={media} />
<div className="absolute inset-0 flex flex-col" <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` }} style={{ padding: `${cq(hasBar(c, 'top-bar') ? 12 : 5)} ${cq(5)} ${cq(hasBar(c, 'bottom-bar') ? 12 : 5)}` }}
data-testid="signage-menu" data-page={page} data-pages={pages.length}> data-testid="signage-menu" data-page={page} data-pages={pages.length}>
{/* the list: the whole width, or narrower and placed left / centre / right (2026-11-21) */} {/* 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}%`, <div style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column', width: `${c.board_width || 100}%`,
alignSelf: BOARD_ALIGN[c.board_align] || 'flex-start', justifyContent: VSELF[c.board_valign] || 'flex-start' }} alignSelf: BOARD_ALIGN[c.board_align] || 'flex-start', justifyContent: VSELF[c.board_valign] || 'flex-start' }}
data-testid="signage-menu-board" data-align={c.board_align || 'left'} data-valign={c.board_valign || 'top'}> data-testid="signage-menu-board" data-align={c.board_align || 'left'} data-valign={c.board_valign || 'top'}>
{c.title && <h1 style={{ fontSize: `${7 * scale}cqmin`, fontWeight: 800, margin: '0 0 2cqmin', color: c.heading_style?.colour || accent, lineHeight: 1.1, {c.title && <h1 style={{ fontSize: cq(7 * scale), fontWeight: 800, margin: `0 0 ${cq(2)}`, color: c.heading_style?.colour || accent, lineHeight: 1.1,
textAlign: c.board_align || 'left' }}>{c.title}</h1>} textAlign: c.board_align || 'left' }}>{c.title}</h1>}
{/* top: the list takes the height (columns fill one after the other); middle / bottom: as tall as it is, placed (owner review 5) */} {/* top: the list takes the height (columns fill one after the other); middle / bottom: as tall as it is, placed (owner review 5) */}
<div style={{ columnCount: c.columns || 2, columnGap: '5cqmin', fontSize: `${3.2 * scale}cqmin`, flex: (c.board_valign || 'top') === 'top' ? 1 : '0 1 auto', <div style={{ columnCount: c.columns || 2, columnGap: cq(5), fontSize: cq(3.2 * scale), flex: (c.board_valign || 'top') === 'top' ? 1 : '0 1 auto',
minHeight: 0, overflow: 'hidden', columnFill: 'auto', ...listSpacing(c) }} minHeight: 0, overflow: 'hidden', columnFill: 'auto', ...listSpacing(c) }}
data-testid="signage-menu-list"> data-testid="signage-menu-list">
<MenuGroups c={c} groups={groups} badges={venue?.badges} /> <MenuGroups c={c} groups={groups} badges={venue?.badges} />
</div> </div>
{pages.length > 1 && ( {pages.length > 1 && (
<div style={{ display: 'flex', gap: '1cqmin', justifyContent: 'center', paddingTop: '1cqmin' }} aria-hidden="true"> <div style={{ display: 'flex', gap: cq(1), justifyContent: 'center', paddingTop: cq(1) }} aria-hidden="true">
{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 }} />)} {pages.map((_, i) => <span key={i} style={{ width: cq(1.2), height: cq(1.2), borderRadius: '50%', background: i === page ? accent : 'currentColor', opacity: i === page ? 1 : 0.3 }} />)}
</div> </div>
)} )}
</div> </div>
@@ -157,12 +158,12 @@ export function MenuGroups({ c, groups, badges }) {
const SIZE = { small: 0.75, medium: 1, large: 1.4 } const SIZE = { small: 0.75, medium: 1, large: 1.4 }
const CORNER = { const CORNER = {
'top-left': { top: '3cqmin', left: '3cqmin', alignItems: 'flex-start' }, 'top-left': { top: cq(3), left: cq(3), alignItems: 'flex-start' },
'top-center': { top: '3cqmin', left: '50%', transform: 'translateX(-50%)', alignItems: 'center' }, 'top-center': { top: cq(3), left: '50%', transform: 'translateX(-50%)', alignItems: 'center' },
'top-right': { top: '3cqmin', right: '3cqmin', alignItems: 'flex-end' }, 'top-right': { top: cq(3), right: cq(3), alignItems: 'flex-end' },
'bottom-left': { bottom: '3cqmin', left: '3cqmin', alignItems: 'flex-start' }, 'bottom-left': { bottom: cq(3), left: cq(3), alignItems: 'flex-start' },
'bottom-center': { bottom: '3cqmin', left: '50%', transform: 'translateX(-50%)', alignItems: 'center' }, 'bottom-center': { bottom: cq(3), left: '50%', transform: 'translateX(-50%)', alignItems: 'center' },
'bottom-right': { bottom: '3cqmin', right: '3cqmin', alignItems: 'flex-end' }, 'bottom-right': { bottom: cq(3), right: cq(3), alignItems: 'flex-end' },
} }
const SELF = { left: 'flex-start', center: 'center', right: 'flex-end' } const SELF = { left: 'flex-start', center: 'center', right: 'flex-end' }
const placedBy = w => (w.position === 'custom' && w.box ? (TIGHT.includes(w.kind) ? 'tight' : true) : false) const placedBy = w => (w.position === 'custom' && w.box ? (TIGHT.includes(w.kind) ? 'tight' : true) : false)
@@ -170,7 +171,7 @@ const VSELF = { top: 'flex-start', middle: 'center', bottom: 'flex-end', auto: '
/** A widget's own colour and the plate behind it (owner review 5); `pad`: a plate that hugs it. */ /** A widget's own colour and the plate behind it (owner review 5); `pad`: a plate that hugs it. */
const plate = (w, pad) => ({ const plate = (w, pad) => ({
...(w.colour ? { color: w.colour } : {}), ...(w.colour ? { color: w.colour } : {}),
...(w.background_colour ? { background: w.background_colour, borderRadius: '1.2cqmin', ...(pad ? { padding: '0.8cqmin 1.6cqmin' } : {}) } : {}), ...(w.background_colour ? { background: w.background_colour, borderRadius: cq(1.2), ...(pad ? { padding: `${cq(0.8)} ${cq(1.6)}` } : {}) } : {}),
}) })
// a menu or a stack in a corner or a bar has no box of its own: it gets one of this size (cqmin) // a menu or a stack in a corner or a bar has no box of its own: it gets one of this size (cqmin)
const BOXED = { menu: [48, 56], stack: [60, 36] } const BOXED = { menu: [48, 56], stack: [60, 36] }
@@ -194,8 +195,8 @@ export function Widgets({ widgets, media, venue, now, colour, extras, embed }) {
<> <>
{bars.map(([where, pos]) => bar(where).length > 0 && ( {bars.map(([where, pos]) => bar(where).length > 0 && (
<div key={where} className="absolute inset-x-0" data-testid={`signage-${where}`} <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', style={{ ...pos, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: cq(3), padding: `${cq(2)} ${cq(4)}`,
background: 'rgba(0,0,0,0.35)', color: colour || '#fff', minHeight: '9cqmin' }}> background: 'rgba(0,0,0,0.35)', color: colour || '#fff', minHeight: cq(9) }}>
{bar(where).map(([w, i, body]) => ( {bar(where).map(([w, i, body]) => (
<div key={i} data-widget={i} style={{ display: 'flex', flexDirection: 'column', alignItems: SELF[widgetAlign(w)], textAlign: widgetAlign(w), ...plate(w, true) }}>{body}</div> <div key={i} data-widget={i} style={{ display: 'flex', flexDirection: 'column', alignItems: SELF[widgetAlign(w)], textAlign: widgetAlign(w), ...plate(w, true) }}>{body}</div>
))} ))}
@@ -215,7 +216,7 @@ export function Widgets({ widgets, media, venue, now, colour, extras, embed }) {
if (w.position === 'custom') { if (w.position === 'custom') {
return ( return (
<div key={i} data-widget={i} className="absolute" data-testid="signage-w-box" <div key={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' }}> style={{ left: `${w.box.x}%`, top: `${w.box.y}%`, width: `${w.box.w}%`, height: `${w.box.h}%`, containerType: 'size', color: colour || '#fff' }} {...CQ_BOX}>
<div style={{ width: '100%', height: '100%', display: 'flex', alignItems: VSELF[w.vertical] || 'center', justifyContent: SELF[widgetAlign(w)], textAlign: widgetAlign(w), ...plate(w) }}> <div style={{ width: '100%', height: '100%', display: 'flex', alignItems: VSELF[w.vertical] || 'center', justifyContent: SELF[widgetAlign(w)], textAlign: widgetAlign(w), ...plate(w) }}>
{body} {body}
</div> </div>
@@ -250,13 +251,13 @@ function widgetBody(w, ctx, fit, path) {
const s = (SIZE[w.size] || 1) * ts const s = (SIZE[w.size] || 1) * ts
// in a box of its own the box sets the size: its text size can only make it smaller there // in a box of its own the box sets the size: its text size can only make it smaller there
const unit = (height, width) => { const unit = (height, width) => {
if (!fit) return n => `${+(n * s).toFixed(3)}cqmin` if (!fit) return n => cq(+(n * s).toFixed(3))
if (fit === 'tight') return n => `${+(n * (w.box.h / height) * ts).toFixed(4)}cqh` if (fit === 'tight') return n => cq(+(n * (w.box.h / height) * ts).toFixed(4), 'h')
const f = fitUnit(height, width) const f = fitUnit(height, width)
return n => f(n * Math.min(1, ts)) return n => f(n * Math.min(1, ts))
} }
const text = (u, size, weight = 700) => ({ fontSize: u(size), fontWeight: w.bold === false ? 400 : w.bold ? Math.max(weight, 800) : weight, lineHeight: 1.15, const text = (u, size, weight = 700) => ({ fontSize: u(size), fontWeight: w.bold === false ? 400 : w.bold ? Math.max(weight, 800) : weight, lineHeight: 1.15,
textShadow: w.background_colour ? undefined : '0 0.2cqmin 0.8cqmin rgba(0,0,0,0.35)', whiteSpace: fit ? 'nowrap' : undefined, textShadow: w.background_colour ? undefined : `0 ${cq(0.2)} ${cq(0.8)} rgba(0,0,0,0.35)`, whiteSpace: fit ? 'nowrap' : undefined,
...(w.font ? { fontFamily: FONTS[w.font] } : {}), ...(w.italic ? { fontStyle: 'italic' } : {}), ...(w.underline ? { textDecoration: 'underline' } : {}) }) ...(w.font ? { fontFamily: FONTS[w.font] } : {}), ...(w.italic ? { fontStyle: 'italic' } : {}), ...(w.underline ? { textDecoration: 'underline' } : {}) })
const line = (str, testid, weight) => { const line = (str, testid, weight) => {
const u = unit(3.4 * 1.15, textWidth(str.length, 3.4)) const u = unit(3.4 * 1.15, textWidth(str.length, 3.4))
@@ -264,15 +265,15 @@ function widgetBody(w, ctx, fit, path) {
} }
// a menu or a stack fills a box: its own, or (in a corner / bar) one of a usual size // a menu or a stack fills a box: its own, or (in a corner / bar) one of a usual size
const boxed = (body, kind) => (fit ? body : ( const boxed = (body, kind) => (fit ? body : (
<div style={{ width: `${BOXED[kind][0] * s}cqmin`, height: `${BOXED[kind][1] * s}cqmin`, containerType: 'size' }}>{body}</div> <div style={{ width: cq(BOXED[kind][0] * s), height: cq(BOXED[kind][1] * s), containerType: 'size' }} {...CQ_BOX}>{body}</div>
)) ))
if (w.kind === 'logo') { if (w.kind === 'logo') {
const m = media(w.media_id) const m = media(w.media_id)
if (!m) return null if (!m) return null
if (fit === 'tight') return <img src={m.src} alt="" style={{ height: `${+(w.box.h * ts).toFixed(4)}cqh`, width: 'auto', display: 'block' }} data-testid="signage-w-logo" /> if (fit === 'tight') return <img src={m.src} alt="" style={{ height: cq(+(w.box.h * ts).toFixed(4), 'h'), width: 'auto', display: 'block' }} data-testid="signage-w-logo" />
return fit 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={{ 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" /> : <img src={m.src} alt="" style={{ height: cq(9 * s), maxWidth: cq(30 * s), objectFit: 'contain' }} data-testid="signage-w-logo" />
} }
if (w.kind === 'name') { if (w.kind === 'name') {
if (!venue?.name) return null if (!venue?.name) return null
@@ -360,7 +361,7 @@ function MenuWidget({ board: b, menu, now, badges }) {
const scale = (b.text_size || 100) / 100 const scale = (b.text_size || 100) / 100
const rowH = (b.show_photos ? 2.6 * (b.photo_size || 100) / 100 : b.show_descriptions ? 2.1 : 1.5) * menuLook(b).rowScale const rowH = (b.show_photos ? 2.6 * (b.photo_size || 100) / 100 : b.show_descriptions ? 2.1 : 1.5) * menuLook(b).rowScale
const lines = Math.ceil(per / cols) + (headings ? 1 : 0) const lines = Math.ceil(per / cols) + (headings ? 1 : 0)
const fontSize = `calc(${scale} * min(${(100 / (lines * rowH + (b.title ? 2 : 0) + 0.8)).toFixed(3)}cqh, ${(100 / (cols * 15)).toFixed(3)}cqw))` const fontSize = `calc(${scale} * min(${cq((100 / (lines * rowH + (b.title ? 2 : 0) + 0.8)).toFixed(3), 'h')}, ${cq((100 / (cols * 15)).toFixed(3), 'w')}))`
const accent = b.accent_colour || '#f59e0b' const accent = b.accent_colour || '#f59e0b'
return ( return (
<div style={{ width: '100%', height: '100%', overflow: 'hidden', fontSize, color: b.text_colour || '#fff', fontFamily: FONTS[b.font] || FONTS.sans, textAlign: 'left' }} <div style={{ width: '100%', height: '100%', overflow: 'hidden', fontSize, color: b.text_colour || '#fff', fontFamily: FONTS[b.font] || FONTS.sans, textAlign: 'left' }}
@@ -391,7 +392,7 @@ function Stack({ w, path, ctx }) {
const slide = !ws.length && c.slide_id ? ctx.extras[cp]?.slide : null const slide = !ws.length && c.slide_id ? ctx.extras[cp]?.slide : null
return ( return (
<div key={j} style={{ flex: `${c.share || 1} 1 0%`, minWidth: 0, minHeight: 0, position: 'relative', overflow: 'hidden', containerType: 'size', <div key={j} style={{ flex: `${c.share || 1} 1 0%`, minWidth: 0, minHeight: 0, position: 'relative', overflow: 'hidden', containerType: 'size',
display: 'flex', flexDirection: across }} data-testid="signage-stack-cell" data-share={c.share}> display: 'flex', flexDirection: across }} {...CQ_BOX} data-testid="signage-stack-cell" data-share={c.share}>
{ws.map((cw, k) => { {ws.map((cw, k) => {
const wp = `${cp}.${k}` const wp = `${cp}.${k}`
const own = cw.position === 'custom' && cw.box const own = cw.position === 'custom' && cw.box
@@ -400,14 +401,14 @@ function Stack({ w, path, ctx }) {
return ( return (
<div key={k} style={{ flex: '1 1 0%', minWidth: 0, minHeight: 0, overflow: 'hidden', containerType: 'size', position: 'relative', <div key={k} style={{ flex: '1 1 0%', minWidth: 0, minHeight: 0, overflow: 'hidden', containerType: 'size', position: 'relative',
...(own ? {} : { display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align }) }} ...(own ? {} : { display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align }) }}
data-testid="signage-stack-place" data-place={wp}> {...CQ_BOX} data-testid="signage-stack-place" data-place={wp}>
{body && (own && TIGHT.includes(cw.kind) ? ( {body && (own && TIGHT.includes(cw.kind) ? (
<div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: 'max-content', display: 'flex', flexDirection: 'column', <div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: 'max-content', display: 'flex', flexDirection: 'column',
alignItems: SELF[align], textAlign: align, ...plate(cw, true) }} data-testid="signage-w-box" data-tight="">{body}</div> alignItems: SELF[align], textAlign: align, ...plate(cw, true) }} data-testid="signage-w-box" data-tight="">{body}</div>
) : own ? ( ) : own ? (
<div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: `${cw.box.w}%`, height: `${cw.box.h}%`, <div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: `${cw.box.w}%`, height: `${cw.box.h}%`,
containerType: 'size', display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align, ...plate(cw) }} containerType: 'size', display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align, ...plate(cw) }}
data-testid="signage-w-box">{body}</div> {...CQ_BOX} data-testid="signage-w-box">{body}</div>
) : ( ) : (
<div data-widget={wp} style={{ display: 'flex', maxWidth: '100%', maxHeight: '100%', ...(cw.kind === 'menu' || cw.kind === 'stack' ? { width: '100%', height: '100%' } : {}), ...plate(cw, true) }}>{body}</div> <div data-widget={wp} style={{ display: 'flex', maxWidth: '100%', maxHeight: '100%', ...(cw.kind === 'menu' || cw.kind === 'stack' ? { width: '100%', height: '100%' } : {}), ...plate(cw, true) }}>{body}</div>
))} ))}
+21
View File
@@ -0,0 +1,21 @@
// Container units with a fallback for older TV browsers (2026-11-21). A slide is sized in container units
// (cqmin, cqh, cqw: Chrome 105, Firefox 110, Safari 16). Where the browser has them, cq() writes them
// exactly as before. On older browsers (an LG / Samsung TV from 2021–2023) it writes
// calc(n * var(--xcqmin)) instead. The terminal's compatibility layer (terminal/src/compat.js) then
// measures every container (an element marked with CQ_BOX) and gives its children those variables, so
// each size refers to the nearest container, as the real units do.
const NATIVE = typeof CSS === 'undefined' || typeof CSS.supports !== 'function' || CSS.supports('width', '1cqmin')
/** True where the browser has container units: no fallback at all. */
export const CQ_NATIVE = NATIVE
const VIEWPORT = { min: 'vmin', h: 'vh', w: 'vw' }
/** `n` container units: cq(3) → "3cqmin", cq(4, 'h') → "4cqh" (or the fallback on an older browser). */
export function cq(n, unit = 'min') {
return NATIVE ? `${n}cq${unit}` : `calc(${n} * var(--xcq${unit}, 1${VIEWPORT[unit]}))`
}
/** Spread on every element with `container-type: size`: nothing where the browser has container units. */
export const CQ_BOX = NATIVE ? {} : { 'data-cq': '' }
+1
View File
@@ -2,6 +2,7 @@
// player (terminal/src/apps/signage) and in the manager's live previews. Sizes are container // player (terminal/src/apps/signage) and in the manager's live previews. Sizes are container
// units (cqmin): put a slide inside an element with `container-type: size` (frameStyle() does). // units (cqmin): put a slide inside an element with `container-type: size` (frameStyle() does).
export * from './logic.js' export * from './logic.js'
export { cq, CQ_BOX, CQ_NATIVE } from './cq.js'
export { BADGE_ICONS } from './badges.js' export { BADGE_ICONS } from './badges.js'
export { Background, BlankSlide, MenuSlide, TextSlide, Widgets } from './Slides.jsx' export { Background, BlankSlide, MenuSlide, TextSlide, Widgets } from './Slides.jsx'
export { SlideView } from './SlideView.jsx' export { SlideView } from './SlideView.jsx'
+2 -1
View File
@@ -2,6 +2,7 @@
// Node (packages/signage/tests/logic.test.mjs). // Node (packages/signage/tests/logic.test.mjs).
// The schedule rules are the server's (local_backend/services/signage_schedule.py) so a screen // The schedule rules are the server's (local_backend/services/signage_schedule.py) so a screen
// switches playlists by itself while the server is down; the same cases are tested on both sides. // switches playlists by itself while the server is down; the same cases are tested on both sides.
import { cq } from './cq.js'
/** The venue's local clock at `date`: { weekday (0 = Monday), minutes, date: "YYYY-MM-DD" }. */ /** The venue's local clock at `date`: { weekday (0 = Monday), minutes, date: "YYYY-MM-DD" }. */
export function localNow(timeZone, date = new Date()) { export function localNow(timeZone, date = new Date()) {
@@ -309,7 +310,7 @@ export function widgetAlign(w) {
export function fitUnit(height, width) { export function fitUnit(height, width) {
const byH = 100 / Math.max(0.1, height) const byH = 100 / Math.max(0.1, height)
const byW = 100 / Math.max(0.1, width) const byW = 100 / Math.max(0.1, width)
return n => `calc(${+n.toFixed(3)} * min(${+byH.toFixed(4)}cqh, ${+byW.toFixed(4)}cqw))` return n => `calc(${+n.toFixed(3)} * min(${cq(+byH.toFixed(4), 'h')}, ${cq(+byW.toFixed(4), 'w')}))`
} }
/** A line of `chars` characters at `size` usual units: about how wide it is (bold sans). */ /** A line of `chars` characters at `size` usual units: about how wide it is (bold sans). */
+22
View File
@@ -221,3 +221,25 @@ test('owner review 5: the venue badges, several per product; a board with its ow
assert.equal(badgeName(mine[0], 'el'), 'Gluten free') assert.equal(badgeName(mine[0], 'el'), 'Gluten free')
assert.equal(badgeName(DEFAULT_BADGES[1], 'el'), 'Πρόταση σεφ') assert.equal(badgeName(DEFAULT_BADGES[1], 'el'), 'Πρόταση σεφ')
}) })
test('container units: written exactly as before where the browser has them (older TVs, 2026-11-21)', async () => {
const { cq, CQ_BOX, CQ_NATIVE } = await import('../src/cq.js')
const { fitUnit } = await import('../src/logic.js')
assert.equal(CQ_NATIVE, true)
assert.equal(cq(3), '3cqmin')
assert.equal(cq(4.5, 'h'), '4.5cqh')
assert.equal(cq(0.25, 'w'), '0.25cqw')
assert.deepEqual(CQ_BOX, {})
assert.equal(fitUnit(4, 20)(2), 'calc(2 * min(25cqh, 5cqw))')
})
test('container units: an older browser gets calc() of the variables the compat layer sets', async () => {
globalThis.CSS = { supports: () => false }
try {
const { cq, CQ_BOX, CQ_NATIVE } = await import('../src/cq.js?older')
assert.equal(CQ_NATIVE, false)
assert.equal(cq(3), 'calc(3 * var(--xcqmin, 1vmin))')
assert.equal(cq(4.5, 'h'), 'calc(4.5 * var(--xcqh, 1vh))')
assert.deepEqual(CQ_BOX, { 'data-cq': '' })
} finally { delete globalThis.CSS }
})
+23
View File
@@ -679,3 +679,26 @@
border-right: 1px dashed #888; border-bottom: 1px dashed #888; border-right: 1px dashed #888; border-bottom: 1px dashed #888;
padding: 6mm 4mm; display: grid; justify-items: center; align-content: start; gap: 2mm; text-align: center; padding: 6mm 4mm; display: grid; justify-items: center; align-content: start; gap: 2mm; text-align: center;
} }
/* ── Notice (2026-11-21) ─────────────────────────────────────────────────── */
.x-notice {
--x-notice-tone: var(--x-info); --x-notice-soft: var(--x-info-soft); --x-notice-ink: var(--x-info-ink);
display: grid; gap: 6px; padding: 10px 14px; border-radius: var(--x-radius-control);
border: 1px solid var(--x-notice-tone); border-left-width: 4px; background: var(--x-notice-soft);
color: var(--x-ink); font-size: var(--x-text-label); line-height: var(--x-leading-label);
}
.x-notice--success { --x-notice-tone: var(--x-success); --x-notice-soft: var(--x-success-soft); --x-notice-ink: var(--x-success-ink); }
.x-notice--warning { --x-notice-tone: var(--x-warning); --x-notice-soft: var(--x-warning-soft); --x-notice-ink: var(--x-warning-ink); }
.x-notice--danger { --x-notice-tone: var(--x-danger); --x-notice-soft: var(--x-danger-soft); --x-notice-ink: var(--x-danger-ink); }
.x-notice--neutral { --x-notice-tone: var(--x-line-strong); --x-notice-soft: var(--x-surface-2); --x-notice-ink: var(--x-ink); }
.x-notice__title { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--x-notice-ink); }
.x-notice__icon { display: inline-flex; }
.x-notice__body { color: var(--x-ink-2); }
.x-notice__items { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.x-notice__item { display: grid; grid-template-columns: 8px 1fr; gap: 10px; align-items: baseline; color: var(--x-ink-2); }
.x-notice__dot { width: 8px; height: 8px; border-radius: var(--x-radius-full); background: var(--x-notice-item, var(--x-ink-3)); transform: translateY(-1px); }
.x-notice__item--success { --x-notice-item: var(--x-success); }
.x-notice__item--warning { --x-notice-item: var(--x-warning); }
.x-notice__item--danger { --x-notice-item: var(--x-danger); }
.x-notice__item--info { --x-notice-item: var(--x-info); }
.x-notice__label { color: var(--x-ink); font-weight: 600; }
+32
View File
@@ -0,0 +1,32 @@
import { cx } from '../internal/cx.js'
/**
* A boxed note in a tone (2026-11-21): a title, text, and an optional list of points, each with a tone
* dot and a short label (e.g. what works, what works with limits, what doesn't).
* <Notice tone="info" title="Devices that work">Some text</Notice>
* <Notice title="…" items={[{ tone: 'success', label: 'Best', text: 'Chrome 111+' }, …]} />
* Tones: info (default), success, warning, danger, neutral.
*/
export function Notice({ tone = 'info', title, icon, items, className, children, ...rest }) {
return (
<div className={cx('x-notice', `x-notice--${tone}`, className)} {...rest}>
{(title || icon) && (
<div className="x-notice__title">
{icon && <span className="x-notice__icon" aria-hidden="true">{icon}</span>}
{title}
</div>
)}
{children && <div className="x-notice__body">{children}</div>}
{items?.length > 0 && (
<ul className="x-notice__items">
{items.map((it, i) => (
<li key={i} className={cx('x-notice__item', `x-notice__item--${it.tone || 'neutral'}`)} data-tone={it.tone || 'neutral'}>
<span className="x-notice__dot" aria-hidden="true" />
<span>{it.label && <strong className="x-notice__label">{it.label}</strong>}{it.label && ' '}{it.text}</span>
</li>
))}
</ul>
)}
</div>
)
}
+1
View File
@@ -28,6 +28,7 @@ export { COLOUR_PRESETS, joinAlpha, splitAlpha, typedColour } from './components
export { FieldRow } from './components/FieldRow.jsx' export { FieldRow } from './components/FieldRow.jsx'
export { Slider } from './components/Slider.jsx' export { Slider } from './components/Slider.jsx'
export { NumberInput } from './components/NumberInput.jsx' export { NumberInput } from './components/NumberInput.jsx'
export { Notice } from './components/Notice.jsx'
export { IconPicker } from './components/IconPicker.jsx' export { IconPicker } from './components/IconPicker.jsx'
export { Page, PageHeader, Pane, Toolbar, ToolbarSpacer } from './components/Page.jsx' export { Page, PageHeader, Pane, Toolbar, ToolbarSpacer } from './components/Page.jsx'
export { SearchInput, FilterChip, Segmented, Tabs } from './components/Controls.jsx' export { SearchInput, FilterChip, Segmented, Tabs } from './components/Controls.jsx'
+3
View File
@@ -28,14 +28,17 @@
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.39.5", "@eslint/js": "^9.39.5",
"@vitejs/plugin-legacy": "^8.2.4",
"@vitejs/plugin-react": "^6.3.0", "@vitejs/plugin-react": "^6.3.0",
"autoprefixer": "^10.6.2", "autoprefixer": "^10.6.2",
"eslint": "^9.39.5", "eslint": "^9.39.5",
"eslint-plugin-react-hooks": "^7.1.1", "eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.7", "eslint-plugin-react-refresh": "^0.5.7",
"globals": "^17.14.0", "globals": "^17.14.0",
"lightningcss": "^1.33.0",
"postcss": "^8.5.33", "postcss": "^8.5.33",
"tailwindcss": "^3.4.16", "tailwindcss": "^3.4.16",
"terser": "^5.51.4",
"vite": "^8.3.8" "vite": "^8.3.8"
} }
} }
+2 -2
View File
@@ -10,7 +10,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useTranslation } from '@xenia/i18n' import { useTranslation } from '@xenia/i18n'
import client from '../../api/client' import client from '../../api/client'
import { useDevice, useLiveEvent, useLiveEvents } from '../../device/context' import { useDevice, useLiveEvent, useLiveEvents } from '../../device/context'
import { boardPages, frameStyle, localNow, mediaUrls, menuMs, nextSlide, pageAt, playlistNow, SlideView, slideMs } from '@xenia/signage' import { boardPages, CQ_BOX, frameStyle, localNow, mediaUrls, menuMs, nextSlide, pageAt, playlistNow, SlideView, slideMs } from '@xenia/signage'
const quiet = { xenia: { noOverride: true } } const quiet = { xenia: { noOverride: true } }
const CACHE_KEY = 'xenia:signage:screen' const CACHE_KEY = 'xenia:signage:screen'
@@ -94,7 +94,7 @@ export default function SignageApp() {
return ( return (
<main className="fixed inset-0 overflow-hidden select-none cursor-none" style={{ background: '#000' }} <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'}> data-testid="app-signage" data-playlist={playlist?.id ?? ''} data-orientation={screen?.orientation ?? ''} data-offline={offline ? 'true' : 'false'}>
<div style={frameStyle(screen?.rotation)} data-testid="signage-frame" data-rotation={screen?.rotation ?? 0}> <div style={frameStyle(screen?.rotation)} {...CQ_BOX} data-testid="signage-frame" data-rotation={screen?.rotation ?? 0}>
{playlist?.slides?.length {playlist?.slides?.length
? <Player key={playlist.id} playlist={playlist} kept={kept} tz={tz} venue={data?.venue} now={now} rotation={screen?.rotation} /> ? <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')} />} : <Empty text={data ? t('signage.nothing') : t('signage.starting')} />}
+144
View File
@@ -0,0 +1,144 @@
// The older-browser layer (2026-11-21). It is loaded only by the legacy build, which a browser runs when it
// can't run the modern one (a TV's built-in browser from 2021–2023). Modern browsers never download it.
// It does three things:
// - swaps the stylesheet for its copy rewritten for older browsers (built by vite.config.js), e.g. `inset`
// becomes top/right/bottom/left;
// - gives the signage slides their container sizes (startCqShim: the fallback of cq() in @xenia/signage);
// - spaces flex items where the browser has no flex `gap` (Chrome before 84): it adds the gap as a margin
// on each item after the first.
// It imports nothing from the apps' code, so the modern build's files stay exactly as they were.
// the same check as @xenia/signage's cq()
const CQ_NATIVE = typeof CSS === 'undefined' || typeof CSS.supports !== 'function' || CSS.supports('width', '1cqmin')
/** What runs here, for the support page and the tests: <html data-compat="legacy css cq gap">. */
const active = ['legacy']
function swapStylesheets() {
for (const link of document.querySelectorAll('link[rel="stylesheet"]')) {
const href = link.getAttribute('href') || ''
if (!/\/assets\/[^/]+\.css$/.test(href) || href.endsWith('.compat.css')) continue
const copy = link.cloneNode()
copy.setAttribute('href', href.replace(/\.css$/, '.compat.css'))
// the old sheet stays until the new one has loaded: no unstyled flash
copy.onload = () => link.remove()
copy.onerror = () => copy.remove()
link.after(copy)
if (!active.includes('css')) active.push('css')
}
}
function hasFlexGap() {
const box = document.createElement('div')
box.style.cssText = 'display:flex;flex-direction:column;row-gap:1px;position:absolute;visibility:hidden'
box.appendChild(document.createElement('div'))
box.appendChild(document.createElement('div'))
document.body.appendChild(box)
const ok = box.scrollHeight === 1
box.remove()
return ok
}
function setVars(el, size) {
if (!size || el.nodeType !== 1) return
el.style.setProperty('--xcqw', `${size.w / 100}px`)
el.style.setProperty('--xcqh', `${size.h / 100}px`)
el.style.setProperty('--xcqmin', `${Math.min(size.w, size.h) / 100}px`)
}
/**
* Older browsers only: give the children of every container its size as --xcqw / --xcqh / --xcqmin.
* The variables are on the children, not on the container: the container's own sizes refer to the
* container around it, as with the real units. Nothing happens where the browser has container units.
* Returns a stop function.
*/
function startCqShim(root = document.body) {
if ( !root || typeof ResizeObserver === 'undefined' || typeof MutationObserver === 'undefined') return () => {}
const sizes = new WeakMap()
const watched = new WeakSet()
const ro = new ResizeObserver(entries => {
for (const e of entries) {
const size = { w: e.contentRect.width, h: e.contentRect.height }
sizes.set(e.target, size)
for (const child of e.target.children) setVars(child, size)
}
})
const watch = el => {
if (watched.has(el)) return
watched.add(el)
ro.observe(el)
}
const scan = node => {
if (node.nodeType !== 1) return
const parent = node.parentElement
if (parent && parent.hasAttribute('data-cq')) setVars(node, sizes.get(parent))
if (node.hasAttribute('data-cq')) watch(node)
for (const el of node.querySelectorAll('[data-cq]')) watch(el)
}
const mo = new MutationObserver(list => {
for (const m of list) for (const n of m.addedNodes) scan(n)
})
mo.observe(root, { childList: true, subtree: true })
scan(root)
return () => { mo.disconnect(); ro.disconnect() }
}
const SIDE = { row: 'marginLeft', 'row-reverse': 'marginRight', column: 'marginTop', 'column-reverse': 'marginBottom' }
function gapItems(el) {
const cs = getComputedStyle(el)
if (cs.display !== 'flex' && cs.display !== 'inline-flex') return
const dir = cs.flexDirection || 'row'
const gap = dir.startsWith('row') ? cs.columnGap : cs.rowGap
const side = SIDE[dir]
let first = true
for (const child of el.children) {
const ccs = getComputedStyle(child)
if (ccs.display === 'none' || ccs.position === 'absolute' || ccs.position === 'fixed') continue
const want = !first && gap && gap !== 'normal' && gap !== '0px' ? gap : ''
// an item's own margin stays (a zero one doesn't count); a write only when it changes, as a
// write fires the observer again
if (want && (child.dataset.xgap || !parseFloat(child.style[side]))) {
if (child.style[side] !== want) child.style[side] = want
child.dataset.xgap = '1'
} else if (!want && child.dataset.xgap) { child.style[side] = ''; delete child.dataset.xgap }
first = false
}
}
function startGapShim() {
const dirty = new Set()
let queued = false
const flush = () => {
queued = false
const els = [...dirty]
dirty.clear()
for (const el of els) if (el.isConnected) gapItems(el)
}
const mark = el => {
if (!el || el.nodeType !== 1) return
dirty.add(el)
if (!queued) { queued = true; requestAnimationFrame(flush) }
}
const markTree = el => {
if (el.nodeType !== 1) return
mark(el)
for (const d of el.querySelectorAll('*')) mark(d)
}
new MutationObserver(list => {
for (const m of list) {
if (m.type === 'attributes') { mark(m.target); mark(m.target.parentElement) }
else { mark(m.target); for (const n of m.addedNodes) markTree(n) }
}
}).observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['class', 'style'] })
markTree(document.body)
}
export function startCompat() {
// the tests force a part on a modern browser: window.__XENIA_COMPAT_FORCE = ['gap']
const force = window.__XENIA_COMPAT_FORCE || []
swapStylesheets()
if (!CQ_NATIVE) { startCqShim(); active.push('cq') }
if (force.includes('gap') || !hasFlexGap()) { startGapShim(); active.push('gap') }
document.documentElement.setAttribute('data-compat', active.join(' '))
}
+3
View File
@@ -8,6 +8,9 @@ import { applyTheme, getStoredTheme } from '@xenia/ui'
// New code uses the tokens only, so every theme works; a per-screen choice comes with each app. // New code uses the tokens only, so every theme works; a per-screen choice comes with each app.
applyTheme(getStoredTheme()) applyTheme(getStoredTheme())
// The legacy build only (a TV's older browser): the compatibility layer. Modern browsers never load it.
if (import.meta.env.LEGACY) import('./compat.js').then(m => m.startCompat())
ReactDOM.createRoot(document.getElementById('root')).render( ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode> <React.StrictMode>
<App /> <App />
+33 -1
View File
@@ -1,10 +1,42 @@
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import legacy from '@vitejs/plugin-legacy'
import { transform } from 'lightningcss'
const BACKEND = process.env.XENIA_BACKEND || 'http://localhost:8000' const BACKEND = process.env.XENIA_BACKEND || 'http://localhost:8000'
// Older TVs (2026-11-21). Modern browsers get exactly the build they always had: Vite's own targets
// (Baseline widely available) for the code and the stylesheet. A browser that can't run it (the
// check is plugin-legacy's: import.meta.resolve, Chrome 105 / Firefox 106 / Safari 16.4) gets a second
// copy of the code, made for LEGACY_TARGETS with the missing pieces added. That copy also loads
// src/compat.js. Modern browsers never download any of it.
const MODERN = ['chrome111', 'edge111', 'firefox114', 'safari16.4', 'ios16.4']
const LEGACY_TARGETS = ['chrome >= 79', 'firefox >= 78', 'safari >= 13']
const COMPAT_CSS = { chrome: 79 << 16, firefox: 78 << 16, safari: 13 << 16 }
/** Each stylesheet again as <name>.compat.css, rewritten for the older browsers (compat.js swaps it in). */
function compatCss() {
return {
name: 'xenia:compat-css',
apply: 'build',
generateBundle(_opts, bundle) {
for (const [name, file] of Object.entries(bundle)) {
if (file.type !== 'asset' || !name.endsWith('.css') || name.endsWith('.compat.css') || name.includes('-legacy')) continue
const { code } = transform({ filename: name, code: Buffer.from(String(file.source)), minify: true, targets: COMPAT_CSS })
this.emitFile({ type: 'asset', fileName: name.replace(/\.css$/, '.compat.css'), source: code })
}
},
}
}
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [
react(),
legacy({ targets: LEGACY_TARGETS, modernTargets: MODERN.map(t => t.replace(/(\D)(\d)/, '$1>=$2')).join(', ') }),
compatCss(),
],
// plugin-legacy would lower the shared stylesheet for everyone; it keeps Vite's own target instead
build: { cssTarget: MODERN },
// npm workspace (D-15): shared packages are imported from source; one React for all. // npm workspace (D-15): shared packages are imported from source; one React for all.
resolve: { resolve: {
dedupe: ['react', 'react-dom'], dedupe: ['react', 'react-dom'],
+142
View File
@@ -0,0 +1,142 @@
// Older TVs (2026-11-21): the terminal's production build has a second copy for older browsers (a TV's
// built-in browser from 2021–2023), and modern browsers never load it. This suite builds the terminal
// and serves the build. A modern browser must get the same files as always: no "-legacy" chunk, no
// compat layer, no .compat.css. Then it plays an "older TV": the same page with the modern scripts
// taken out, container units reported missing and the flex-gap fix forced. That run must load the legacy
// copy and the compat layer, show the pairing screen, play the signage slide at the same sizes as
// the modern browser, and space flex items itself.
// A real Chrome 79 isn't driven here: syntax and missing APIs are the legacy build's job (Babel +
// core-js for LEGACY_TARGETS in terminal/vite.config.js); what's checked is our layer.
// node compat.mjs
import { execFileSync, spawn } from 'node:child_process'
import { openSync } from 'node:fs'
import path from 'node:path'
import { chromium } from 'playwright'
import { BROWSER_CHANNEL, CS, OUT, reporter, waitFor } from './lib/env.mjs'
import { killTree, startBackend, waitHttp } from './lib/proc.mjs'
import { supportLogin } from './lib/support.mjs'
const PORT = 5196
const DIST = path.join(OUT, 'compat-dist')
const r = reporter('older TVs: the legacy build and the compat layer (terminal)')
const errors = []
execFileSync('npx', ['vite', 'build', '--outDir', DIST, '--emptyOutDir'], { cwd: path.join(CS, 'terminal'), shell: process.platform === 'win32', stdio: 'ignore' })
const backend = await startBackend({ port: 8066, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } })
const log = openSync(path.join(OUT, `vite-${PORT}.log`), 'w')
const preview = spawn('npx', ['vite', 'preview', '--outDir', DIST, '--port', String(PORT), '--strictPort'], {
cwd: path.join(CS, 'terminal'), shell: process.platform === 'win32', detached: process.platform !== 'win32',
stdio: ['ignore', log, log], env: { ...process.env, XENIA_BACKEND: backend.url },
})
const URL = `http://localhost:${PORT}`
await waitHttp(URL + '/')
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
let failures = 0
async function api(method, url, { token, body } = {}) {
const res = await fetch(backend.url + url, {
method, headers: { 'content-type': 'application/json', ...(token ? { authorization: `Bearer ${token}` } : {}) },
body: body === undefined ? undefined : JSON.stringify(body),
})
const text = await res.text()
if (!res.ok) throw new Error(`${method} ${url} → ${res.status} ${text.slice(0, 200)}`)
return JSON.parse(text)
}
const shown = (page, testId, timeout = 15_000) => page.getByTestId(testId).first().waitFor({ timeout }).then(() => true).catch(() => false)
/** The page as an older browser runs it: no module scripts, the nomodule ones run (polyfills + SystemJS). */
function asOldBrowser(html) {
return html
.replace(/<script type="module"[^>]*>[\s\S]*?<\/script>/g, '')
.replace(/<link rel="modulepreload"[^>]*>/g, '')
.replace(/<script nomodule/g, '<script')
}
async function tv({ old }) {
const ctx = await browser.newContext({ viewport: { width: 1280, height: 720 } })
const page = await ctx.newPage()
page.on('pageerror', e => errors.push(`${old ? 'old' : 'modern'}: ${e.message}`))
const fetched = []
page.on('request', q => fetched.push(q.url()))
if (old) {
await page.addInitScript(() => {
const real = CSS.supports.bind(CSS)
CSS.supports = (...a) => (a.join(':').includes('cq') ? false : real(...a))
window.__XENIA_COMPAT_FORCE = ['gap']
})
await page.route(u => new globalThis.URL(u).pathname === '/', async route => {
const res = await route.fetch()
await route.fulfill({ response: res, body: asOldBrowser(await res.text()) })
})
}
await page.goto(URL + '/')
return { page, fetched }
}
try {
const boss = await supportLogin(backend.url)
await api('PUT', '/api/platform/modules/signage', { token: boss, body: { enabled: true } }).catch(() => {})
const pl = await api('POST', '/api/signage/playlists', { token: boss, body: { name: 'Window', orientation: 'landscape' } })
await api('POST', `/api/signage/playlists/${pl.id}/slides`, { token: boss, body: { kind: 'text', duration_s: 60, content: {
title: 'Happy hour', body: '17:00 - 19:00', background: { kind: 'colour', colour: '#1e3a8a' },
widgets: [
{ kind: 'clock', position: 'top-right' },
{ kind: 'stack', direction: 'row', position: 'custom', box: { x: 5, y: 60, w: 40, h: 30 }, cells: [
{ share: 50, widgets: [{ kind: 'clock' }] }, { share: 50, widgets: [{ kind: 'date' }] }] },
] } } })
const modern = await tv({ old: false })
r.check('modern: the pairing screen', await shown(modern.page, 'pairing-code'))
const flags = await modern.page.evaluate(() => ({ modern: window.__vite_is_modern_browser === true, compat: document.documentElement.getAttribute('data-compat') }))
r.check('modern: runs the modern build, without the compat layer', flags.modern && flags.compat === null, JSON.stringify(flags))
const extra = modern.fetched.filter(u => /-legacy|compat|polyfills/.test(u))
r.check('modern: downloads nothing of the older-browser copy', extra.length === 0, extra.join(' '))
const old = await tv({ old: true })
r.check('older TV: the pairing screen', await shown(old.page, 'pairing-code'))
r.check('older TV: runs the legacy copy with the compat layer (stylesheet, container sizes, flex gaps)',
await waitFor(async () => (await old.page.getAttribute('html', 'data-compat')) === 'legacy css cq gap', 10_000, 300),
String(await old.page.getAttribute('html', 'data-compat')))
r.check('older TV: the legacy chunks and the rewritten stylesheet were loaded',
old.fetched.some(u => /index-legacy-.*\.js$/.test(u)) && old.fetched.some(u => u.endsWith('.compat.css')) && !old.fetched.some(u => /\/assets\/index-[\w-]+\.js$/.test(u) && !u.includes('-legacy')))
for (const [t, label] of [[modern, 'modern'], [old, 'older TV']]) {
const code = await t.page.getByTestId('pairing-code').getAttribute('data-code')
await api('POST', '/api/devices', { token: boss, body: { code, app_key: 'signage', name: `TV ${label}` } })
.then(dev => api('PUT', `/api/signage/screens/${dev.id}`, { token: boss, body: { playlist_id: pl.id } }))
r.check(`${label}: plays the slide`, await shown(t.page, 'signage-title', 30_000))
}
const sizes = page => page.evaluate(() => {
const px = el => (el ? parseFloat(getComputedStyle(el).fontSize) : null)
const box = el => { const b = el?.getBoundingClientRect(); return b ? [Math.round(b.width), Math.round(b.height)] : null }
const clocks = [...document.querySelectorAll('[data-testid="signage-w-clock"]')]
return { title: px(document.querySelector('[data-testid="signage-title"]')), body: px(document.querySelector('[data-testid="signage-body"]')),
clocks: clocks.map(px), cell: box(document.querySelector('[data-testid="signage-stack-cell"]')),
vars: document.querySelector('[data-testid="signage-stack-place"]')?.style.getPropertyValue('--xcqmin') || '',
unit: document.querySelector('[data-testid="signage-title"]')?.getAttribute('style') || '',
gap: !!document.querySelector('[data-testid="signage-body"][data-xgap]') }
})
await waitFor(async () => (await sizes(old.page)).clocks.length === 2, 10_000, 300)
const a = await sizes(modern.page)
const b = await sizes(old.page)
const near = (x, y) => x != null && y != null && Math.abs(x - y) <= 0.6
r.check('older TV: title and text the same size as on a modern browser', near(a.title, b.title) && near(a.body, b.body), `${JSON.stringify(a)} | ${JSON.stringify(b)}`)
r.check('older TV: corner clock and clock inside a stack the same size (nested containers)',
a.clocks.length === 2 && b.clocks.length === 2 && near(a.clocks[0], b.clocks[0]) && near(a.clocks[1], b.clocks[1]), `${a.clocks} | ${b.clocks}`)
r.check('older TV: the sizes come from the layer (container variables, calc() instead of cqmin)',
b.vars.endsWith('px') && a.vars === '' && b.unit.includes('var(--xcqmin') && a.unit.includes('cqmin') && !a.unit.includes('var('), `${b.vars} | ${a.unit} | ${b.unit}`)
r.check('older TV: flex items spaced by the layer (title and text)', b.gap && !a.gap)
await old.page.screenshot({ path: path.join(OUT, 'compat-old-tv.png') })
await modern.page.screenshot({ path: path.join(OUT, 'compat-modern.png') })
} catch (e) {
failures++
console.log('FAIL (crashed)', e.stack || e)
} finally {
const real = errors.filter(e => !/import\.meta\.resolve not supported/.test(e))
r.check('no page errors', real.length === 0, real.join(' | '))
await browser.close()
killTree(preview)
await backend.stop?.()
}
failures += r.done()
process.exit(failures ? 1 : 0)
+1
View File
@@ -34,6 +34,7 @@ const suites = [
['media (Media page, product photos, waiter offline photos)', 'node', ['media.mjs'], E2E], ['media (Media page, product photos, waiter offline photos)', 'node', ['media.mjs'], E2E],
['terminal (pairing, sign-in, states)', 'node', ['terminal.mjs'], E2E], ['terminal (pairing, sign-in, states)', 'node', ['terminal.mjs'], E2E],
['signage (the player on a TV, the editor)', 'node', ['signage.mjs'], E2E], ['signage (the player on a TV, the editor)', 'node', ['signage.mjs'], E2E],
['older TVs (legacy build, compat layer)', 'node', ['compat.mjs'], E2E],
['menu tablet (menu, search, views, live prices)', 'node', ['menu_tablet.mjs'], E2E], ['menu tablet (menu, search, views, live prices)', 'node', ['menu_tablet.mjs'], E2E],
['printing problems (phone + manager: not printed, sent elsewhere, handled)', 'node', ['print_problems.mjs'], E2E], ['printing problems (phone + manager: not printed, sent elsewhere, handled)', 'node', ['print_problems.mjs'], E2E],
['order app (cloud: takeaway + delivery + bookings)', 'node', ['order_app.mjs'], E2E], ['order app (cloud: takeaway + delivery + bookings)', 'node', ['order_app.mjs'], E2E],