diff --git a/AGENTS.md b/AGENTS.md index 792a3f6c..c35e06b1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -106,7 +106,11 @@ apps/demo/ the demo app: the dev server for the whole repository, demo/cmi5.html with demo/cmi5-page.js is a cmi5 assignable unit around the element, on @missing-elements/h5p-cmi5, and demo/cmi5-course.zip the course structure for importing it into an LMS, naming the hosted page; - demo/element.js is the one import of the element every page loads + demo/element.js is the one import of the element every page loads; + demo/theme.js the light/dark switch, a classic script every page + loads in its head before the stylesheet, since the CSP allows no + inline script and a pinned theme has to be on before the + first paint tests/ cmi5.test.ts: the cmi5 page against a mock LMS and LRS on a second origin, through the dev server and a real browser cmi5-catapult/ docker-compose.yml for ADL's CATAPULT player, MySQL and the SQL LRS; @@ -1175,7 +1179,8 @@ SPA-fallback trap described above cannot happen there. fallback stays for those, and for an in-app browser. - **The pages carry their metadata, and the origin is filled in at build time.** Titles, descriptions, canonical links, Open Graph and Twitter tags, JSON-LD for the software on the - front page, `robots.txt` and `sitemap.xml`, and the GitHub link in every page's navigation. The + front page, `robots.txt` and `sitemap.xml`, and the GitHub link at the right of every page's + header, an icon beside the theme switch. The absolute URLs are written as `%SITE_URL%` in the HTML and replaced by `siteUrlPlugin` (`apps/demo/vite.config.ts`), which runs before Vite's own `%ENV%` pass so Vite does not warn about a name it does not know. `build-demo.mjs` decides the origin — `SITE_URL` if set, else Vercel's diff --git a/apps/demo/app/icons/icon-192.png b/apps/demo/app/icons/icon-192.png index 87fa414f..007e9b98 100644 Binary files a/apps/demo/app/icons/icon-192.png and b/apps/demo/app/icons/icon-192.png differ diff --git a/apps/demo/app/icons/icon-512.png b/apps/demo/app/icons/icon-512.png index ba379c97..2ab95307 100644 Binary files a/apps/demo/app/icons/icon-512.png and b/apps/demo/app/icons/icon-512.png differ diff --git a/apps/demo/app/icons/icon-maskable-512.png b/apps/demo/app/icons/icon-maskable-512.png index 0c3ea902..43e74cf2 100644 Binary files a/apps/demo/app/icons/icon-maskable-512.png and b/apps/demo/app/icons/icon-maskable-512.png differ diff --git a/apps/demo/app/index.html b/apps/demo/app/index.html index 3e444d68..bde6f819 100644 --- a/apps/demo/app/index.html +++ b/apps/demo/app/index.html @@ -35,6 +35,9 @@ under /assets/ would point them at nothing. The build copies both as they are. --> + + @@ -44,15 +47,25 @@
- H5P Offline Player + H5P Offline Player +
+ + + + +
diff --git a/apps/demo/demo/cmi5.html b/apps/demo/demo/cmi5.html index 6f44f808..75e2b45a 100644 --- a/apps/demo/demo/cmi5.html +++ b/apps/demo/demo/cmi5.html @@ -22,6 +22,9 @@ + + @@ -30,15 +33,25 @@
- h5p-offline-player + h5p-offline-player +
+ + + + +
diff --git a/apps/demo/demo/embed.html b/apps/demo/demo/embed.html index f3f3f7ea..1d71a0d9 100644 --- a/apps/demo/demo/embed.html +++ b/apps/demo/demo/embed.html @@ -22,21 +22,34 @@ + +
- h5p-offline-player + h5p-offline-player +
+ + + + +
@@ -104,6 +117,8 @@

What this page received

if (data.action === 'hello') source.postMessage({ context: 'h5p', action: 'hello' }, origin) if (data.action === 'resize') { frame.style.height = `${data.scrollHeight}px` + // Content is up: the box around it goes, so its rounded corners stop clipping it (player-page.css). + frame.dataset.loaded = '' write(`resize ${data.scrollHeight}px`) } } diff --git a/apps/demo/demo/favicon.svg b/apps/demo/demo/favicon.svg index 6595fa3e..f7d947b2 100644 --- a/apps/demo/demo/favicon.svg +++ b/apps/demo/demo/favicon.svg @@ -1,4 +1,4 @@ - H5 + H5P diff --git a/apps/demo/demo/index.html b/apps/demo/demo/index.html index 5249d68a..00f32fea 100644 --- a/apps/demo/demo/index.html +++ b/apps/demo/demo/index.html @@ -22,6 +22,9 @@ + + @@ -29,15 +32,25 @@
- h5p-offline-player + h5p-offline-player +
+ + + + +
diff --git a/apps/demo/demo/local-file.html b/apps/demo/demo/local-file.html index 68756a03..5cf45686 100644 --- a/apps/demo/demo/local-file.html +++ b/apps/demo/demo/local-file.html @@ -22,6 +22,9 @@ + + @@ -29,15 +32,25 @@
- h5p-offline-player + h5p-offline-player +
+ + + + +
diff --git a/apps/demo/demo/normalize.html b/apps/demo/demo/normalize.html index b173f5ad..0ac96744 100644 --- a/apps/demo/demo/normalize.html +++ b/apps/demo/demo/normalize.html @@ -22,21 +22,34 @@ + +
- h5p-offline-player + h5p-offline-player +
+ + + + +
diff --git a/apps/demo/demo/og-image.png b/apps/demo/demo/og-image.png index ea18fa09..5af151dc 100644 Binary files a/apps/demo/demo/og-image.png and b/apps/demo/demo/og-image.png differ diff --git a/apps/demo/demo/player-page.css b/apps/demo/demo/player-page.css index 12310c53..83a2adbe 100644 --- a/apps/demo/demo/player-page.css +++ b/apps/demo/demo/player-page.css @@ -19,6 +19,9 @@ --danger: #b4232a; --warn: #8a5a00; --ok: #1d7a42; + /* Which of the switch's two icons shows: the theme a press would bring. */ + --icon-sun: none; + --icon-moon: inline; --radius: 12px; --radius-sm: 8px; @@ -28,8 +31,13 @@ --ease: 160ms ease; } +/* The dark tokens, twice, because they apply in two cases that no one selector covers: the + system prefers dark and the visitor has not pinned light, or the visitor has pinned dark + whatever the system says. `data-theme` is set by demo/theme.js; with no script the first rule + is the whole theme and follows the system. `color-scheme` travels with a pin so the browser's + own parts — scrollbars, form controls, the canvas behind the page — follow it too. */ @media (prefers-color-scheme: dark) { - :root { + :root:not([data-theme="light"]) { --bg: #0f1114; --fg: #e8eaee; --muted: #98a1ae; @@ -42,10 +50,33 @@ --danger: #ff8f8f; --warn: #f0c060; --ok: #62d094; + --icon-sun: inline; + --icon-moon: none; --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 14px 36px -20px rgb(0 0 0 / 0.7); } } +:root[data-theme="dark"] { + color-scheme: dark; + --bg: #0f1114; + --fg: #e8eaee; + --muted: #98a1ae; + --line: #262b33; + --line-strong: #363d47; + --surface: #171a1f; + --surface-2: #1e2229; + --accent: #7aa2ff; + --accent-ink: #0b1a3a; + --danger: #ff8f8f; + --warn: #f0c060; + --ok: #62d094; + --icon-sun: inline; + --icon-moon: none; + --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 14px 36px -20px rgb(0 0 0 / 0.7); +} + +:root[data-theme="light"] { color-scheme: light; } + @media (prefers-reduced-motion: reduce) { :root { --ease: 0ms; } .badge::before { animation: none !important; } @@ -102,20 +133,16 @@ p code, li code, .lede code { padding: 0.1em 0.35em; border-radius: 4px; backgro white-space: nowrap; } +/* The favicon, drawn at header size: one file for the tab and the mark, so the two cannot drift. */ .brand-mark { - display: grid; - place-items: center; - width: 1.6rem; - height: 1.6rem; - border-radius: 7px; - background: var(--accent); - color: var(--accent-ink); - font: 700 0.7rem / 1 ui-monospace, SFMono-Regular, Menlo, monospace; + display: block; + width: 1.7rem; + height: 1.7rem; } /* Wraps rather than overflows: a wider system font or a larger text setting on a narrow phone pushed the fourth link past the edge, and the whole page scrolled sideways. */ -.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem; min-width: 0; } +.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem; min-width: 0; margin-left: auto; } .topbar nav a { padding: 0.375rem 0.7rem; @@ -129,6 +156,37 @@ p code, li code, .lede code { padding: 0.1em 0.35em; border-radius: 4px; backgro .topbar nav a:hover { background: var(--surface-2); color: var(--fg); } .topbar nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); } +/* The right-hand end: the theme switch and the repository, as icons, after the nav. */ +.topbar-actions { display: flex; align-items: center; gap: 0.25rem; } + +/* Where the three do not fit on one line, the nav takes a line of its own under the brand and + the icons; left to wrap by itself it took the second line and pushed the icons to a third, + at the left. */ +@media (max-width: 44rem) { + .topbar nav { order: 1; flex-basis: 100%; margin-left: 0; } + .topbar-actions { margin-left: auto; } +} + +.icon-button { + display: inline-grid; + place-items: center; + width: 2.1rem; + height: 2.1rem; + padding: 0; + border: 0; + border-radius: 999px; + background: transparent; + color: var(--muted); + cursor: pointer; + min-height: 0; + transition: background var(--ease), color var(--ease); +} +.icon-button:hover { background: var(--surface-2); color: var(--fg); } +.icon-button svg { width: 1.15rem; height: 1.15rem; } +/* The two icons ride on the theme tokens, so the swap needs no selector of its own. */ +.icon-sun { display: var(--icon-sun); } +.icon-moon { display: var(--icon-moon); } + main { width: min(100% - 2 * var(--gutter), var(--content)); margin: 0 auto; @@ -358,6 +416,14 @@ h5p-player { display: block; margin-top: 1.25rem; min-height: clamp(16rem, 55vh, 28rem); +} + +/* A box like the page's other boxes only while it is one: empty, loading, or failed. Once + content is up the frame fills the element edge to edge and the content draws its own chrome, + so the border and shadow would double it, and a rounded box that clips cuts the corners out + of whatever the content puts there — a Question Set's footer bar, a presentation's controls, + a video's picture. The element reflects its state as an attribute. */ +h5p-player:not([state="ready"]) { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; @@ -371,6 +437,11 @@ h5p-player { /* A starting height only: the embedded page reports its own, and the listener applies it. */ height: 20rem; transition: height 0.15s ease-out; +} + +/* Same rule as the player's box, by the one signal this page gets from inside the frame: the + first height report means the content is standing. An iframe clips its own corners. */ +.embed-frame:not([data-loaded]) { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); diff --git a/apps/demo/demo/setup.html b/apps/demo/demo/setup.html index 71ac9531..f72a007f 100644 --- a/apps/demo/demo/setup.html +++ b/apps/demo/demo/setup.html @@ -22,21 +22,34 @@ + +
- h5p-offline-player + h5p-offline-player +
+ + + + +
diff --git a/apps/demo/demo/theme.js b/apps/demo/demo/theme.js new file mode 100644 index 00000000..661beea4 --- /dev/null +++ b/apps/demo/demo/theme.js @@ -0,0 +1,67 @@ +// The site's light/dark switch. A classic script, not a module, linked in ahead of the +// stylesheet: it has to put a pinned theme on before anything is painted, or a visitor who +// pinned the opposite of their system setting sees every page flash the wrong way as it loads. +// The CSP allows no inline script, so it is a file, linked with `vite-ignore` and copied by the +// build as it is. Without it — blocked, or not yet run — the stylesheet follows the system +// setting on its own, which is also what it does with no pin. +// +// Two states, not three: following the system, or pinned to the other theme. A press pins the +// theme the visitor is not seeing; a press that would pin the system's own theme clears the pin +// instead, so the page follows the system again and a pin never outlives its point. +;(() => { + const KEY = 'theme' + const root = document.documentElement + const system = matchMedia('(prefers-color-scheme: dark)') + + const stored = () => { + try { + const value = localStorage.getItem(KEY) + return value === 'light' || value === 'dark' ? value : null + } catch { + return null + } + } + const show = (pin) => { + if (pin) root.dataset.theme = pin + else delete root.dataset.theme + } + const shown = () => root.dataset.theme || (system.matches ? 'dark' : 'light') + + show(stored()) + + addEventListener('DOMContentLoaded', () => { + const button = document.querySelector('.theme-toggle') + if (!button) return + + // The label names what a press does, which is the one thing an icon cannot say. + const describe = () => { + const text = `Switch to the ${shown() === 'dark' ? 'light' : 'dark'} theme` + button.setAttribute('aria-label', text) + button.title = text + } + + button.addEventListener('click', () => { + const next = shown() === 'dark' ? 'light' : 'dark' + const pin = next === (system.matches ? 'dark' : 'light') ? null : next + show(pin) + try { + if (pin) localStorage.setItem(KEY, pin) + else localStorage.removeItem(KEY) + } catch { + // No storage: the choice holds for this page and no longer. + } + describe() + }) + + // The system setting can change under a page that follows it, and another tab can change + // the pin; the stylesheet follows both by itself, the label and the icon follow here. + system.addEventListener('change', describe) + addEventListener('storage', (event) => { + if (event.key !== KEY && event.key !== null) return + show(stored()) + describe() + }) + + describe() + }) +})() diff --git a/apps/demo/demo/two-players.html b/apps/demo/demo/two-players.html index 32eb08a9..a159fd19 100644 --- a/apps/demo/demo/two-players.html +++ b/apps/demo/demo/two-players.html @@ -22,6 +22,9 @@ + + @@ -29,15 +32,25 @@
- h5p-offline-player + h5p-offline-player +
+ + + + +
diff --git a/apps/demo/demo/xapi.html b/apps/demo/demo/xapi.html index b61442aa..88770522 100644 --- a/apps/demo/demo/xapi.html +++ b/apps/demo/demo/xapi.html @@ -22,6 +22,9 @@ + + @@ -29,15 +32,25 @@
- h5p-offline-player + h5p-offline-player +
+ + + + +
diff --git a/apps/demo/index.html b/apps/demo/index.html index 9b0ece3e..24a8e499 100644 --- a/apps/demo/index.html +++ b/apps/demo/index.html @@ -23,6 +23,9 @@ + +