Portal demo for Vercel

- The real portal over a router that lives in the page
  (web/src/portal/demo): "User" on "Dawnline Preview", ten scenarios
  (first visit, settings changed, out of data, outside the hours, paused,
  ended, plain HTTP, plain WireGuard, no free slots), devices kept per
  visitor in localStorage. Keys are random and the server's address never
  resolves: nothing is installed and nothing connects
- A "Demo" chip after the breadcrumb opens a drawer with the scenarios and
  Start over; a new device "connects" a few seconds after its settings
- A GitHub pill beside the page's QR knob; on a phone, where the names
  need the room, a GitHub button in the drawer instead
- npm run build:demo builds the static site into web/dist/demo;
  web/vercel.json deploys it with the portal's CSP and headers, and builds
  only commits on main that change web/
- README links to the live demo (dawnline-demo.vercel.app)
- Tests for the demo router (tests/demo.test.ts)
This commit is contained in:
Aemeath committed 2026-10-19 23:08:06 +03:00
1 parent 8e7c15ad56
commit caed976e63
14 files changed
+1007 -3

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
// What the demo adds to the breadcrumb: the scenario chip right after the path,
// and a GitHub pill just before the page's QR knob (at the end where there is
// none: a card alone). On a phone the pill would crowd out the names, so it
// gives way to a button in the scenario drawer (demo.css). The portal redraws
// the breadcrumb with the page and knows nothing of either, so both go back in
// place after each redraw.
import { h, ic } from '../dom';
import { REPO } from './data';
import { scenarioChip } from './picker';
import type { DemoRouter } from './router';
export function mountCrumbs(router: DemoRouter) {
const app = document.getElementById('app')!;
const chip = scenarioChip(router);
const gh = h(
'a',
{ class: 'dm-gh', href: REPO, target: '_blank', rel: 'noopener', 'aria-label': 'Dawnline on GitHub' },
ic('github'),
h('span', {}, 'GitHub'),
);
// Our own insertions call this again: by then both are in place and nothing moves.
const keep = () => {
const crumbs = app.querySelector('.crumbs');
const path = crumbs?.querySelector('.cr-path');
if (!crumbs || !path) return;
if (path.nextElementSibling !== chip) path.after(chip);
const qr = crumbs.querySelector('.cr-qr');
if (qr && qr.previousElementSibling !== gh) qr.before(gh);
else if (!qr && crumbs.lastElementChild !== gh) crumbs.append(gh);
};
new MutationObserver(keep).observe(app, { childList: true, subtree: true });
keep();
}