diff --git a/apps/demo/demo/player-page.css b/apps/demo/demo/player-page.css
index 076fbcce..e43617b1 100644
--- a/apps/demo/demo/player-page.css
+++ b/apps/demo/demo/player-page.css
@@ -1,121 +1,10 @@
-/* The hosted player page and the example pages share this sheet. Deliberately a plain
- stylesheet: everything here is the host page's job, not the element's, and the point of the
- demo is to show where that boundary sits. Nothing in here reaches into the element — the
- only rule that names it sets its box, which is exactly what a host page is expected to do. */
-
-:root {
- color-scheme: light dark;
-
- --bg: #ffffff;
- --fg: #15171c;
- --muted: #5b6370;
- --line: #e2e6ec;
- --line-strong: #c9d0d9;
- --surface: #f6f8fa;
- --surface-2: #eef1f5;
- /* Code blocks are an ink panel in both themes, so code never reads as prose; the role colours
- are the panel's and do not change with the page. */
- --code-bg: #141a23;
- --code-head: #1a212c;
- --code-border: #141a23;
- --code-line: #283141;
- --tk-plain: #e2e7ef;
- --tk-punct: #8f9aab;
- --tk-comment: #8793a7;
- --tk-string: #9ad6a8;
- --tk-keyword: #d0a8ff;
- --tk-function: #8db6ff;
- --tk-tag: #7fd1e3;
- --tk-attr: #f2c97d;
- --tk-constant: #f5a97f;
- --accent: #2f6df6;
- --accent-ink: #ffffff;
- --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
- --danger: #b4232a;
- --warn: #8a5a00;
- --ok: #1d7a42;
- --star: #bf8700;
- /* 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;
- --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 10px 28px -18px rgb(0 0 0 / 0.22);
- --gutter: clamp(1rem, 4vw, 2rem);
- --content: 64rem;
- --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:not([data-theme="light"]) {
- --bg: #0f1114;
- --fg: #e8eaee;
- --muted: #98a1ae;
- --line: #262b33;
- --line-strong: #363d47;
- --surface: #171a1f;
- --surface-2: #1e2229;
- --code-bg: #090c11;
- --code-head: #0e1218;
- --code-border: #2a313c;
- --code-line: #222935;
- --accent: #7aa2ff;
- --accent-ink: #0b1a3a;
- --danger: #ff8f8f;
- --warn: #f0c060;
- --ok: #62d094;
- --star: #e3b341;
- --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;
- --code-bg: #090c11;
- --code-head: #0e1218;
- --code-border: #2a313c;
- --code-line: #222935;
- --accent: #7aa2ff;
- --accent-ink: #0b1a3a;
- --danger: #ff8f8f;
- --warn: #f0c060;
- --ok: #62d094;
- --star: #e3b341;
- --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; }
-}
+/* The hosted player page and the example pages share this sheet, on top of the player's
+ page.css: the colours, the bar, the buttons, the status strip, the player's box, cards and
+ messages are there, the same for every page that holds the player. What is here is this site's
+ own. Deliberately a plain stylesheet: everything in it is the host page's job, not the
+ element's, and the point of the demo is to show where that boundary sits. */
+@import "@missing-elements/h5p-offline-player/page.css";
-*, *::before, *::after { box-sizing: border-box; }
-
-/* Hidden means hidden, whatever display a rule gives the element: the browser's own `[hidden]`
- rule loses to any of them, `button`'s `display: inline-flex` below among them, which once left
- the app's Start over button on screen with nothing open. */
-[hidden] { display: none !important; }
-
-html { -webkit-text-size-adjust: 100%; }
/* A link to a heading lands below the sticky bar, not under it: the bar's height at each width,
plus a breath. One row from 64rem; the links on their own row below; two rows of them under
40rem (measured 60, 102 and 129 px, 2026-10-18). */
@@ -123,124 +12,8 @@ html { scroll-padding-top: 9.75rem; }
@media (min-width: 40rem) { html { scroll-padding-top: 8rem; } }
@media (min-width: 64rem) { html { scroll-padding-top: 5.25rem; } }
-body {
- margin: 0;
- min-height: 100dvh;
- background: var(--bg);
- color: var(--fg);
- font: 400 clamp(0.95rem, 0.9rem + 0.25vw, 1.0625rem) / 1.6 system-ui, -apple-system, "Segoe UI",
- Roboto, sans-serif;
- text-rendering: optimizeLegibility;
-}
-
-a { color: var(--accent); text-underline-offset: 0.15em; }
-a:hover { text-decoration-thickness: 2px; }
-
-:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
-
-code, kbd { font: 0.9em / 1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
-p code, li code, .lede code { padding: 0.1em 0.35em; border-radius: 4px; background: var(--surface-2); }
-
/* ---------------------------------------------------------------- shell */
-.topbar {
- position: sticky;
- top: 0;
- z-index: 10;
- display: flex;
- flex-wrap: wrap;
- align-items: center;
- justify-content: space-between;
- gap: 0.5rem 1rem;
- padding: 0.75rem var(--gutter);
- background: color-mix(in srgb, var(--bg) 86%, transparent);
- -webkit-backdrop-filter: blur(10px);
- backdrop-filter: blur(10px);
- border-bottom: 1px solid var(--line);
-}
-
-.brand {
- display: inline-flex;
- align-items: center;
- gap: 0.55rem;
- color: inherit;
- font-weight: 600;
- letter-spacing: -0.01em;
- text-decoration: none;
- 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: block;
- width: 1.7rem;
- height: 1.7rem;
-}
-
-/* The name with its author on a line under it, so the bar is no wider for it. H5P Group's
- trademark policy lets a name lead with "H5P" only beside who made it (h5p.org/trademark; see
- AGENTS.md). The space before the byline keeps the link's name "… by Missing Elements". */
-.brand-name { display: flex; flex-direction: column; line-height: 1.15; }
-.brand-by { color: var(--muted); font-size: 0.72rem; font-weight: 500; letter-spacing: 0; }
-
-/* 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; justify-content: center; gap: 0.25rem; min-width: 0; }
-
-.topbar nav a {
- padding: 0.375rem 0.7rem;
- border-radius: 999px;
- color: var(--muted);
- font-size: 0.9rem;
- text-decoration: none;
- transition: background var(--ease), color var(--ease);
-}
-
-.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 as an icon, and the repository's Star. */
-.topbar-actions { display: flex; align-items: center; gap: 0.25rem; margin-left: auto; }
-
-/* Where the brand, the nav and the actions fit on one line, the nav sits in the middle of the
- bar: three columns, the outer two equal, so the middle one is centred whichever end is wider.
- It needed 57rem with macOS's system font and a four-character star count, and 60rem in the
- app, whose bar carries the menu's icon too (2026-10-17); one width for every page keeps the
- bar the same height wherever a visitor goes, and the rest is room for a wider font. The old
- breakpoint, 44rem, was already short of the 50rem the bar needed before the Star button, and
- between the two the icons dropped to a row of their own at the left. */
-@media (min-width: 64rem) {
- .topbar { display: grid; grid-template-columns: 1fr auto 1fr; }
- .topbar > .brand { justify-self: start; }
-}
-
-/* Below that, the nav takes a row of its own, centred, 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 (width < 64rem) {
- .topbar nav { order: 1; flex-basis: 100%; }
-}
-
-.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); }
-
/* The repository, drawn as GitHub's own Star button is: the mark, the word, and the count behind
a star, so it reads as an invitation to star rather than one more icon. The count is drawn from
`--star-count`, which stars.js puts on before the first paint, and the slot stays out
@@ -446,35 +219,6 @@ p.lede:has(+ .features) { margin-bottom: 1.25rem; }
box-shadow: 0 0 0 3px var(--accent-soft);
}
-button,
-label.file {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- gap: 0.4rem;
- min-height: 2.75rem;
- padding: 0.5rem 1rem;
- border: 1px solid var(--line-strong);
- border-radius: var(--radius-sm);
- background: var(--bg);
- color: inherit;
- font: inherit;
- font-weight: 500;
- cursor: pointer;
- transition: background var(--ease), border-color var(--ease), transform var(--ease);
-}
-
-button:hover, label.file:hover { background: var(--surface-2); }
-button:active, label.file:active { transform: translateY(1px); }
-button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
-button.primary:hover { filter: brightness(1.06); }
-button:disabled { opacity: 0.5; cursor: default; transform: none; }
-/* Out of sight, not out of reach: a label takes no focus of its own, so the input has to, and
- with it at `display: none` no key could open the picker. Enter or Space on it does now. */
-label.file { position: relative; }
-label.file input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
-label.file:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
-
/* The element's two modes, on a row of their own at the foot of the form: a two-part switch and
what the chosen mode does. The radios stay real radios, out of sight, so arrows move between
them and the label is the click target. */
@@ -528,80 +272,9 @@ label.file:has(input:focus-visible) { outline: 2px solid var(--accent); outline-
* state as a small capital label, the progress bar, and the clock on the right. The sample
* buttons above it are pills; nothing here is.
*/
-.status {
- display: flex;
- align-items: center;
- gap: 0.875rem;
- min-height: 2.5rem;
- margin: 1.25rem 0 0.5rem;
- padding: 0.45rem 0.85rem;
- border: 1px solid var(--line);
- border-left: 3px solid var(--line-strong);
- border-radius: var(--radius-sm);
- background: var(--surface);
- font-size: 0.9rem;
- transition: border-color var(--ease);
-}
-
-.status[data-state="ready"] { border-left-color: var(--ok); }
-.status[data-state="error"] { border-left-color: var(--danger); }
-.status[data-state="probing"],
-.status[data-state="downloading"],
-.status[data-state="indexing"],
-.status[data-state="building"] { border-left-color: var(--accent); }
-/* The SCORM page's link to the zip it built, at the strip's right. */
-.status a { margin-left: auto; font-weight: 600; }
-
-.badge {
- display: inline-flex;
- align-items: center;
- gap: 0.5rem;
- min-width: 7.5rem;
- font-size: 0.75rem;
- font-weight: 600;
- letter-spacing: 0.05em;
- text-transform: uppercase;
- color: var(--muted);
-}
-
-.badge::before {
- content: "";
- width: 0.55rem;
- height: 0.55rem;
- border-radius: 50%;
- background: var(--muted);
-}
-
-.badge[data-state="ready"] { color: var(--ok); }
-.badge[data-state="ready"]::before { background: var(--ok); }
-.badge[data-state="error"] { color: var(--danger); }
-.badge[data-state="error"]::before { background: var(--danger); }
-
-.badge[data-state="probing"],
-.badge[data-state="downloading"],
-.badge[data-state="indexing"] { color: var(--accent); }
-
-.badge[data-state="probing"]::before,
-.badge[data-state="downloading"]::before,
-.badge[data-state="indexing"]::before { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
-
-/* Seconds since the load was asked for, frozen when the player is ready or has failed. */
-.timer {
- margin-left: auto;
- font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
- font-size: 0.8rem;
- font-variant-numeric: tabular-nums;
- white-space: nowrap;
- color: var(--muted);
-}
-
-.timer[hidden] { display: none; }
/* Which mode the content up now plays in, at the end of the line. */
.mode-tag { margin-left: auto; color: var(--muted); font-size: 0.85rem; }
.mode-tag[hidden] { display: none; }
-.status[data-state="ready"] .timer { color: var(--fg); }
-
-@keyframes pulse { 50% { opacity: 0.35; } }
progress {
flex: 1 1 12rem;
@@ -614,30 +287,6 @@ progress {
progress[hidden] { display: none; }
-.message {
- margin: 0.75rem 0 0;
- padding: 0.75rem 1rem;
- border: 1px solid transparent;
- border-radius: var(--radius-sm);
- font-size: 0.925rem;
-}
-
-.message[hidden] { display: none; }
-
-.message.error {
- border-color: color-mix(in srgb, var(--danger) 30%, transparent);
- background: color-mix(in srgb, var(--danger) 10%, transparent);
- color: var(--danger);
-}
-
-.message.warning {
- border-color: color-mix(in srgb, var(--warn) 35%, transparent);
- background: color-mix(in srgb, var(--warn) 10%, transparent);
- color: var(--warn);
-}
-
-.message.hint { border-color: var(--line); background: var(--surface); color: var(--muted); }
-
/* The choice of library source. `button`'s own display beats the UA `[hidden]` rule. */
.message.offer:not([hidden]) { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.offer button[hidden] { display: none; }
@@ -759,29 +408,6 @@ button.scorm-row-remove { min-height: 2rem; margin-left: auto; padding: 0.2rem 0
#pass-mark[aria-invalid="true"] { border-color: var(--danger); }
.scorm-options .step-hint { font-size: 0.875rem; }
-/* ---------------------------------------------------------------- the player's box */
-
-h5p-player {
- display: block;
- margin-top: 1.25rem;
-}
-
-/* A box like the page's other boxes only while it is one: empty, loading, or failed, with a
- height of its own since nothing in it gives one. Once content is up the element is as tall as
- the content says — a minimum height left on it showed as empty space under a short quiz, and
- under a video on a phone — and the frame fills it edge to edge while 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"]) {
- min-height: clamp(16rem, 55vh, 28rem);
- border: 1px solid var(--line);
- border-radius: var(--radius);
- overflow: hidden;
- background: var(--surface);
- box-shadow: var(--shadow);
-}
-
.embed-frame {
display: block;
width: 100%;
@@ -905,24 +531,6 @@ h5p-player:not([state="ready"]) {
list-style: none;
}
-.card {
- display: flex;
- flex-direction: column;
- gap: 0.35rem;
- height: 100%;
- padding: 1rem 1.125rem;
- border: 1px solid var(--line);
- border-radius: var(--radius);
- background: var(--surface);
- color: inherit;
- text-decoration: none;
- transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
-}
-
-a.card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
-.card strong { font-weight: 600; }
-.card span { color: var(--muted); font-size: 0.925rem; }
-
footer {
display: flex;
flex-direction: column;
diff --git a/apps/demo/vite.config.ts b/apps/demo/vite.config.ts
index 7e2aadac..7210476e 100644
--- a/apps/demo/vite.config.ts
+++ b/apps/demo/vite.config.ts
@@ -165,6 +165,9 @@ export default defineConfig(({ command }) => ({
// `dist/h5p-plan.js` first (`build` in package.json), as `pnpm dev` does.
alias: [
{ find: /^@missing-elements\/h5p-offline-player$/, replacement: ELEMENT },
+ // The page's stylesheet the same way: player-page.css imports it by the package's name, and
+ // here that is the source, so the demo needs no build of the player for it either.
+ { find: /^@missing-elements\/h5p-offline-player\/page\.css$/, replacement: resolve(playerDir, 'page', 'page.css') },
{ find: /^@missing-elements\/h5p-cmi5$/, replacement: CMI5 }
]
},
diff --git a/design/demo.md b/design/demo.md
index 09c2e357..aa6b9929 100644
--- a/design/demo.md
+++ b/design/demo.md
@@ -294,6 +294,15 @@ SPA-fallback trap described above cannot happen there.
longest prefix of the page's — so a page names no current link. The footers stay in the pages:
each lists its own links. The per-page metadata — title, description, Open Graph and Twitter
tags, each written two or three times — is the obvious next candidate and has not been done.
+- **The page's design is the player's `page.css`** (2026-11-10, #170). The colours for light and
+ dark, the bar, the buttons, the status strip, the player's box, cards and messages moved from
+ `player-page.css` to `packages/player/page/page.css`, which the player ships in `dist/` and the
+ demo imports first; the config aliases the package path to the source, as it does the element's.
+ The verifier's preview, the extension's page and the build page import the same file, so
+ the pages around the player look the same and cannot drift from the demo. The bar's three-column
+ grid applies to a bar with a nav (`.topbar:has(nav)`): a bar of a brand and its actions keeps the
+ actions at its end. The owner asked for it on 2026-11-10, after the verifier's preview opened in
+ Claude's browser panel in the browser's system styles.
- **Caching.** Hashed files under `/assets/` are immutable; `h5p-sw.js` and `frame-assets/` are
`no-cache`; `fixtures/` revalidate hourly. `frame-assets/` was hourly, with a day of
`stale-while-revalidate`, until #49: its file names stay the same from one runtime to the next,
diff --git a/design/layout.md b/design/layout.md
index 5dc1025b..a60b977f 100644
--- a/design/layout.md
+++ b/design/layout.md
@@ -84,6 +84,11 @@ packages/player/ @missing-elements/h5p-offline-player — the published
tests/package-types.ts the published declarations as a caller on `nodenext` sees them, checked by
tsconfig.consumer.json (see *Types for the plain-JS packages*)
public/ generated, not in git: the runtime's dist/ as frame-assets/, and the test fixtures
+ page/ page.css and mark.svg, copied to dist/ by build-workers (#170): the page around the
+ player as the demo draws it — colours for light and dark, the bar, buttons, the
+ status strip, the player's box — exported as `./page.css`; the demo imports the
+ source by alias, h5p-verify's preview, the extension's page and the build
+ page take it from the package, so none of them drifts from the demo
NOTICE.md zip.js's notice, and where the runtime went; shipped with the package
packages/runtime/ @missing-elements/h5p-runtime — the H5P core runtime, GPL-3.0-only, a package of its
diff --git a/design/verify.md b/design/verify.md
index 373b7bbe..644dc016 100644
--- a/design/verify.md
+++ b/design/verify.md
@@ -100,6 +100,12 @@ driver along and the normalizer should not.
download-url`) was the other way: it changes how the content looks, takes two clicks, and its
dialog's button is English whatever the content's language.
+- **The preview page is the demo's page** (2026-11-10, #170): it links the player's `page.css` and
+ `mark.svg`, served from `dist/` as the element's script is, so the bar with the mark, the
+ Download button, the theme switch and the status strip with its state dot and timer are the
+ demo's own rules, not a copy that drifts. The owner found the system-styled page out of place
+ beside the demo and in Claude's browser panel, where the preview opens for them.
+
Not built, deliberately: steps that click through the content and check the xAPI it sends, and a
content digest for reviewing what was generated. A check of library versions against the hub's
catalogue, the commonest reason a package that plays here is refused on upload (h5p-cli builds
diff --git a/design/vscode.md b/design/vscode.md
index 07b4d55c..418a01a6 100644
--- a/design/vscode.md
+++ b/design/vscode.md
@@ -132,7 +132,9 @@ and committed, as are the app's install screenshots (`pnpm demo:screenshots`), w
comes from neither, and played trusted, sharing the page's origin, it can post as the page, so the
most it can do is misreport its own state. Until 2026-10-27 the webview relayed whatever the page
posted, a `mode` among them, which the extension took for the tab's switches and Open in Browser
- played by. `tests/html.test.ts` runs both scripts in Node against stand-ins for their elements.
+ played by. The page takes one message the other way, the theme, from its parent window at the
+ webview's origin, as `light` or `dark` and nothing else. `tests/html.test.ts` runs both scripts
+ in Node against stand-ins for their elements.
- **A file that is not on this computer is copied first.** `extensionKind` is `ui` alone, so the
extension runs beside the webview, which reaches only this computer's loopback; a remote or
virtual workspace's file is copied to a temporary folder through `workspace.fs`, and copied again
@@ -152,6 +154,17 @@ and committed, as are the app's install screenshots (`pnpm demo:screenshots`), w
the pattern is a glob: until 2026-10-27 it was, and `quiz [v2].h5p` never matched itself, so its
previews never played again. The suite's file is named `package [v2] {draft}.h5p` for that.
+- **The page is the demo's page** (2026-11-10, #170): it links the player's `page.css`, carried in
+ `assets/player/` with the element's files, so the player's box while it loads and the page's
+ colours are the demo's rules. The bar above it keeps VS Code's own theme colours, as an editor's
+ page should. The page's colours follow VS Code's theme, not the system's: the page is a frame
+ of its own, and its `prefers-color-scheme` is the system's, which need not be the editor's (found
+ in review, on #171). The webview reads the theme from the class VS Code puts on its body, a
+ high-contrast theme as the light or dark one it is built on, and names it in the page's address,
+ which the server writes onto `` as `data-theme` before anything is drawn; a theme changed
+ while the preview is open goes to the page as a message, since a reload would lose the
+ learner's place.
+
Tests. `tests/*.test.ts` run in Node with the rest of `pnpm test`: the server against the built
player, runtime and pack, with its run of ports and Restricted Mode, and the webview's and the
page's scripts run against stand-ins. `tests/vscode/run.mjs` downloads VS Code into
diff --git a/docs/setup.md b/docs/setup.md
index f1cd28d1..2e27ea81 100644
--- a/docs/setup.md
+++ b/docs/setup.md
@@ -136,6 +136,21 @@ Words and AR Scavenger. A frame from another site gets neither unless the page a
embed package's [README](../packages/embed#readme) has the page's query parameters, the policy
files it writes for each kind of host, and the SCORM package it can write instead.
+## A page in the demo's look
+
+The player ships the demo's page styles as `@missing-elements/h5p-offline-player/page.css`: its
+colours for light and dark, the bar, buttons, the status strip and the player's box while it
+loads; `dist/mark.svg` is the mark. `h5p-verify --preview`, the H5P Preview extension and
+the build page draw their pages with it, and a page of your own can, through a bundler that takes
+CSS (Vite, webpack 5 with a CSS loader):
+
+```js
+import '@missing-elements/h5p-offline-player/page.css'
+```
+
+Without a bundler, copy `dist/page.css` beside your page, as the element's own files are, and link
+it. It names no other file.
+
## When something goes wrong
[Troubleshooting](troubleshooting.md) lists the symptoms, causes and fixes. A site that allows
diff --git a/packages/player/package.json b/packages/player/package.json
index 0a39b8d8..430e7591 100644
--- a/packages/player/package.json
+++ b/packages/player/package.json
@@ -32,6 +32,7 @@
"types": "./types/plan.d.ts",
"default": "./dist/h5p-plan.js"
},
+ "./page.css": "./dist/page.css",
"./dist/*": "./dist/*"
},
"files": [
diff --git a/packages/player/page/mark.svg b/packages/player/page/mark.svg
new file mode 100644
index 00000000..fae4d246
--- /dev/null
+++ b/packages/player/page/mark.svg
@@ -0,0 +1,20 @@
+
diff --git a/packages/player/page/page.css b/packages/player/page/page.css
new file mode 100644
index 00000000..811da548
--- /dev/null
+++ b/packages/player/page/page.css
@@ -0,0 +1,407 @@
+/* The page around the player, as the demo draws it: its colours for light and dark, the bar with
+ the mark and a byline, buttons, the status strip with its state dot and timer, the player's box
+ while it loads, cards and messages. Shipped with the player so that every page that holds it —
+ the demo, h5p-verify's preview, the H5P Preview extension's page, the build page — looks
+ the same and cannot drift: the demo imports this file and adds its own rules after it. Plain
+ CSS, nothing reaches into the element; the one rule that names it sets its box. A page sets
+ `data-theme="light"` or `"dark"` on to pin a theme, and follows the system without. */
+
+:root {
+ color-scheme: light dark;
+
+ --bg: #ffffff;
+ --fg: #15171c;
+ --muted: #5b6370;
+ --line: #e2e6ec;
+ --line-strong: #c9d0d9;
+ --surface: #f6f8fa;
+ --surface-2: #eef1f5;
+ /* Code blocks are an ink panel in both themes, so code never reads as prose; the role colours
+ are the panel's and do not change with the page. */
+ --code-bg: #141a23;
+ --code-head: #1a212c;
+ --code-border: #141a23;
+ --code-line: #283141;
+ --tk-plain: #e2e7ef;
+ --tk-punct: #8f9aab;
+ --tk-comment: #8793a7;
+ --tk-string: #9ad6a8;
+ --tk-keyword: #d0a8ff;
+ --tk-function: #8db6ff;
+ --tk-tag: #7fd1e3;
+ --tk-attr: #f2c97d;
+ --tk-constant: #f5a97f;
+ --accent: #2f6df6;
+ --accent-ink: #ffffff;
+ --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
+ --danger: #b4232a;
+ --warn: #8a5a00;
+ --ok: #1d7a42;
+ --star: #bf8700;
+ /* 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;
+ --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 10px 28px -18px rgb(0 0 0 / 0.22);
+ --gutter: clamp(1rem, 4vw, 2rem);
+ --content: 64rem;
+ --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:not([data-theme="light"]) {
+ --bg: #0f1114;
+ --fg: #e8eaee;
+ --muted: #98a1ae;
+ --line: #262b33;
+ --line-strong: #363d47;
+ --surface: #171a1f;
+ --surface-2: #1e2229;
+ --code-bg: #090c11;
+ --code-head: #0e1218;
+ --code-border: #2a313c;
+ --code-line: #222935;
+ --accent: #7aa2ff;
+ --accent-ink: #0b1a3a;
+ --danger: #ff8f8f;
+ --warn: #f0c060;
+ --ok: #62d094;
+ --star: #e3b341;
+ --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;
+ --code-bg: #090c11;
+ --code-head: #0e1218;
+ --code-border: #2a313c;
+ --code-line: #222935;
+ --accent: #7aa2ff;
+ --accent-ink: #0b1a3a;
+ --danger: #ff8f8f;
+ --warn: #f0c060;
+ --ok: #62d094;
+ --star: #e3b341;
+ --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; }
+}
+
+*, *::before, *::after { box-sizing: border-box; }
+
+/* Hidden means hidden, whatever display a rule gives the element: the browser's own `[hidden]`
+ rule loses to any of them, `button`'s `display: inline-flex` below among them, which once left
+ the app's Start over button on screen with nothing open. */
+[hidden] { display: none !important; }
+
+html { -webkit-text-size-adjust: 100%; }
+
+body {
+ margin: 0;
+ min-height: 100dvh;
+ background: var(--bg);
+ color: var(--fg);
+ font: 400 clamp(0.95rem, 0.9rem + 0.25vw, 1.0625rem) / 1.6 system-ui, -apple-system, "Segoe UI",
+ Roboto, sans-serif;
+ text-rendering: optimizeLegibility;
+}
+
+a { color: var(--accent); text-underline-offset: 0.15em; }
+a:hover { text-decoration-thickness: 2px; }
+
+:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
+
+code, kbd { font: 0.9em / 1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
+p code, li code, .lede code { padding: 0.1em 0.35em; border-radius: 4px; background: var(--surface-2); }
+
+.topbar {
+ position: sticky;
+ top: 0;
+ z-index: 10;
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ justify-content: space-between;
+ gap: 0.5rem 1rem;
+ padding: 0.75rem var(--gutter);
+ background: color-mix(in srgb, var(--bg) 86%, transparent);
+ -webkit-backdrop-filter: blur(10px);
+ backdrop-filter: blur(10px);
+ border-bottom: 1px solid var(--line);
+}
+
+.brand {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.55rem;
+ color: inherit;
+ font-weight: 600;
+ letter-spacing: -0.01em;
+ text-decoration: none;
+ 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: block;
+ width: 1.7rem;
+ height: 1.7rem;
+}
+
+/* The name with its author on a line under it, so the bar is no wider for it. H5P Group's
+ trademark policy lets a name lead with "H5P" only beside who made it (h5p.org/trademark; see
+ AGENTS.md). The space before the byline keeps the link's name "… by Missing Elements". */
+.brand-name { display: flex; flex-direction: column; line-height: 1.15; }
+.brand-by { color: var(--muted); font-size: 0.72rem; font-weight: 500; letter-spacing: 0; }
+
+/* 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; justify-content: center; gap: 0.25rem; min-width: 0; }
+
+.topbar nav a {
+ padding: 0.375rem 0.7rem;
+ border-radius: 999px;
+ color: var(--muted);
+ font-size: 0.9rem;
+ text-decoration: none;
+ transition: background var(--ease), color var(--ease);
+}
+
+.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 as an icon, and the repository's Star. */
+.topbar-actions { display: flex; align-items: center; gap: 0.25rem; margin-left: auto; }
+
+/* Where the brand, the nav and the actions fit on one line, the nav sits in the middle of the
+ bar: three columns, the outer two equal, so the middle one is centred whichever end is wider.
+ It needed 57rem with macOS's system font and a four-character star count, and 60rem in the
+ app, whose bar carries the menu's icon too (2026-10-17); one width for every page keeps the
+ bar the same height wherever a visitor goes, and the rest is room for a wider font. The old
+ breakpoint, 44rem, was already short of the 50rem the bar needed before the Star button, and
+ between the two the icons dropped to a row of their own at the left. */
+@media (min-width: 64rem) {
+ .topbar:has(nav) { display: grid; grid-template-columns: 1fr auto 1fr; }
+ .topbar > .brand { justify-self: start; }
+}
+
+/* Below that, the nav takes a row of its own, centred, 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 (width < 64rem) {
+ .topbar nav { order: 1; flex-basis: 100%; }
+}
+
+.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); }
+
+button,
+.button,
+label.file {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0.4rem;
+ min-height: 2.75rem;
+ padding: 0.5rem 1rem;
+ border: 1px solid var(--line-strong);
+ border-radius: var(--radius-sm);
+ background: var(--bg);
+ color: inherit;
+ font: inherit;
+ font-weight: 500;
+ cursor: pointer;
+ transition: background var(--ease), border-color var(--ease), transform var(--ease);
+}
+
+/* A link drawn as a button, ``: the verifier's Download, the build page's. */
+.button { text-decoration: none; }
+button:hover, .button:hover, label.file:hover { background: var(--surface-2); }
+button:active, .button:active, label.file:active { transform: translateY(1px); }
+button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
+button.primary:hover, .button.primary:hover { filter: brightness(1.06); }
+button:disabled { opacity: 0.5; cursor: default; transform: none; }
+/* Out of sight, not out of reach: a label takes no focus of its own, so the input has to, and
+ with it at `display: none` no key could open the picker. Enter or Space on it does now. */
+label.file { position: relative; }
+label.file input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
+label.file:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
+
+.status {
+ display: flex;
+ align-items: center;
+ gap: 0.875rem;
+ min-height: 2.5rem;
+ margin: 1.25rem 0 0.5rem;
+ padding: 0.45rem 0.85rem;
+ border: 1px solid var(--line);
+ border-left: 3px solid var(--line-strong);
+ border-radius: var(--radius-sm);
+ background: var(--surface);
+ font-size: 0.9rem;
+ transition: border-color var(--ease);
+}
+
+.status[data-state="ready"] { border-left-color: var(--ok); }
+.status[data-state="error"] { border-left-color: var(--danger); }
+.status[data-state="probing"],
+.status[data-state="downloading"],
+.status[data-state="indexing"],
+.status[data-state="building"] { border-left-color: var(--accent); }
+/* The SCORM page's link to the zip it built, at the strip's right. */
+.status a { margin-left: auto; font-weight: 600; }
+
+.badge {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.5rem;
+ min-width: 7.5rem;
+ font-size: 0.75rem;
+ font-weight: 600;
+ letter-spacing: 0.05em;
+ text-transform: uppercase;
+ color: var(--muted);
+}
+
+.badge::before {
+ content: "";
+ width: 0.55rem;
+ height: 0.55rem;
+ border-radius: 50%;
+ background: var(--muted);
+}
+
+.badge[data-state="ready"] { color: var(--ok); }
+.badge[data-state="ready"]::before { background: var(--ok); }
+.badge[data-state="error"] { color: var(--danger); }
+.badge[data-state="error"]::before { background: var(--danger); }
+
+.badge[data-state="probing"],
+.badge[data-state="downloading"],
+.badge[data-state="indexing"] { color: var(--accent); }
+
+.badge[data-state="probing"]::before,
+.badge[data-state="downloading"]::before,
+.badge[data-state="indexing"]::before { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
+
+/* Seconds since the load was asked for, frozen when the player is ready or has failed. */
+.timer {
+ margin-left: auto;
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
+ font-size: 0.8rem;
+ font-variant-numeric: tabular-nums;
+ white-space: nowrap;
+ color: var(--muted);
+}
+
+.timer[hidden] { display: none; }
+
+.status[data-state="ready"] .timer { color: var(--fg); }
+
+@keyframes pulse { 50% { opacity: 0.35; } }
+
+.message {
+ margin: 0.75rem 0 0;
+ padding: 0.75rem 1rem;
+ border: 1px solid transparent;
+ border-radius: var(--radius-sm);
+ font-size: 0.925rem;
+}
+
+.message[hidden] { display: none; }
+
+.message.error {
+ border-color: color-mix(in srgb, var(--danger) 30%, transparent);
+ background: color-mix(in srgb, var(--danger) 10%, transparent);
+ color: var(--danger);
+}
+
+.message.warning {
+ border-color: color-mix(in srgb, var(--warn) 35%, transparent);
+ background: color-mix(in srgb, var(--warn) 10%, transparent);
+ color: var(--warn);
+}
+
+.message.hint { border-color: var(--line); background: var(--surface); color: var(--muted); }
+
+/* ---------------------------------------------------------------- the player's box */
+
+h5p-player {
+ display: block;
+ margin-top: 1.25rem;
+}
+
+/* A box like the page's other boxes only while it is one: empty, loading, or failed, with a
+ height of its own since nothing in it gives one. Once content is up the element is as tall as
+ the content says — a minimum height left on it showed as empty space under a short quiz, and
+ under a video on a phone — and the frame fills it edge to edge while 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"]) {
+ min-height: clamp(16rem, 55vh, 28rem);
+ border: 1px solid var(--line);
+ border-radius: var(--radius);
+ overflow: hidden;
+ background: var(--surface);
+ box-shadow: var(--shadow);
+}
+
+.card {
+ display: flex;
+ flex-direction: column;
+ gap: 0.35rem;
+ height: 100%;
+ padding: 1rem 1.125rem;
+ border: 1px solid var(--line);
+ border-radius: var(--radius);
+ background: var(--surface);
+ color: inherit;
+ text-decoration: none;
+ transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
+}
+
+a.card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
+.card strong { font-weight: 600; }
+.card span { color: var(--muted); font-size: 0.925rem; }
diff --git a/packages/player/scripts/build-workers.mjs b/packages/player/scripts/build-workers.mjs
index 9fe8fd80..d6cba1ae 100644
--- a/packages/player/scripts/build-workers.mjs
+++ b/packages/player/scripts/build-workers.mjs
@@ -1,4 +1,4 @@
-import { readFile, writeFile } from 'node:fs/promises'
+import { copyFile, readFile, writeFile } from 'node:fs/promises'
import { resolve } from 'node:path'
import { transform } from 'esbuild'
import { buildJobsWorker, buildMountModule, buildPlanModule, buildServiceWorker, playerNotice } from './lib/worker-bundle.mjs'
@@ -45,4 +45,9 @@ await writeFile(
'utf8'
)
-console.log(`[build-workers] ${await sizeOf('h5p-player.js')} (minified after Vite), ${await sizeOf('h5p-sw.js')}, ${await sizeOf('h5p-sw-mount.js')}, ${await sizeOf('h5p-jobs.js')}, ${await sizeOf('h5p-plan.js')}`)
+// The page around the player, for the pages that hold it — h5p-verify's preview, the extension's
+// page, the build page, the demo: the demo's tokens and components, and the mark. Copied as
+// they are, so a page imports `@missing-elements/h5p-offline-player/page.css` and nothing drifts.
+for (const name of ['page.css', 'mark.svg']) await copyFile(resolve(rootDir, 'page', name), resolve(distDir, name))
+
+console.log(`[build-workers] ${await sizeOf('h5p-player.js')} (minified after Vite), ${await sizeOf('h5p-sw.js')}, ${await sizeOf('h5p-sw-mount.js')}, ${await sizeOf('h5p-jobs.js')}, ${await sizeOf('h5p-plan.js')}, ${await sizeOf('page.css')}`)
diff --git a/packages/verify/lib/preview.html b/packages/verify/lib/preview.html
index 3e5b815b..f139de88 100644
--- a/packages/verify/lib/preview.html
+++ b/packages/verify/lib/preview.html
@@ -4,30 +4,41 @@
Preview
+
+
-
-
+
+
diff --git a/packages/verify/tests/preview.test.ts b/packages/verify/tests/preview.test.ts
index 3827ff65..324d9c17 100644
--- a/packages/verify/tests/preview.test.ts
+++ b/packages/verify/tests/preview.test.ts
@@ -100,6 +100,10 @@ describe('h5p-verify --preview', () => {
expect(past.status).toBe(416)
expect(past.headers.get('content-range')).toBe(`bytes */${bytes.length}`)
expect((await fetch(`${preview.url}/__package/other.h5p`)).status).toBe(404)
+ // The demo's page styles and mark, from the player's dist/ as the element's script is.
+ const styles = await fetch(`${preview.url}/page.css`)
+ expect([styles.status, styles.headers.get('content-type')]).toEqual([200, 'text/css; charset=utf-8'])
+ expect((await fetch(`${preview.url}/mark.svg`)).headers.get('content-type')).toBe('image/svg+xml')
} finally {
preview.close()
}
@@ -147,6 +151,12 @@ describe('h5p-verify --preview', () => {
try {
const page = await browser.newPage()
await page.goto(`${preview.url}/`)
+ // Drawn by the demo's stylesheet: its sticky bar, and the strip's state once the content is up.
+ expect(await page.evaluate(() => getComputedStyle(document.querySelector('.topbar')!).position)).toBe('sticky')
+ // The file's name is the page's heading, and the live region is the message, not the timer.
+ expect(await page.getByRole('heading', { level: 1 }).textContent()).toBe('quiz.h5p')
+ expect(await page.evaluate(() => [...document.querySelectorAll('[role="status"]')].map((element) => element.id))).toEqual(['message'])
+ await page.waitForFunction(() => document.querySelector('#status')?.getAttribute('data-state') === 'ready', null, { timeout: 60_000 })
const link = page.getByRole('link', { name: 'Download' })
const [download] = await Promise.all([page.waitForEvent('download'), link.click()])
expect(download.suggestedFilename()).toBe('quiz.h5p')
@@ -166,6 +176,25 @@ describe('h5p-verify --preview', () => {
}
}, 60_000)
+ it('follows a theme switched in another tab of the same preview', async () => {
+ const preview = await previewPackage({ file: quiz, port: 0 })
+ const browser = await launch(undefined)
+ try {
+ // One context, so the two tabs share the origin's storage, as a browser's tabs do.
+ const context = await browser.newContext()
+ const [first, second] = [await context.newPage(), await context.newPage()]
+ for (const page of [first, second]) await page.goto(`${preview.url}/`)
+ await first.click('.theme-toggle')
+ const pinned = await first.evaluate(() => document.documentElement.dataset.theme)
+ expect(pinned).toBe('dark')
+ await second.waitForFunction((theme) => document.documentElement.dataset.theme === theme, pinned, { timeout: 5000 })
+ expect(await second.locator('.theme-toggle').getAttribute('aria-label')).toBe('Switch to the light theme')
+ } finally {
+ preview.close()
+ await browser.close()
+ }
+ }, 60_000)
+
it('ends by itself when no tab opens it in time', async () => {
const preview = await previewPackage({ file: quiz, port: 0, openWait: 100 })
expect(await preview.closed).toBe('unopened')
diff --git a/packages/vscode/scripts/build.mjs b/packages/vscode/scripts/build.mjs
index 5d8438ad..4630f576 100644
--- a/packages/vscode/scripts/build.mjs
+++ b/packages/vscode/scripts/build.mjs
@@ -21,8 +21,8 @@ const pack = dirname(require.resolve('@missing-elements/h5p-libraries/parts/inde
const licences = require.resolve('@missing-elements/h5p-libraries/libraries.txt')
const verify = join(root, '..', 'verify', 'lib')
-/** The player's files, by the names the element looks for beside itself. */
-const PLAYER_FILES = ['h5p-player.js', 'h5p-sw.js', 'h5p-jobs.js']
+/** The player's files, by the names the element looks for beside itself, and the page's stylesheet and mark. */
+const PLAYER_FILES = ['h5p-player.js', 'h5p-sw.js', 'h5p-jobs.js', 'page.css', 'mark.svg']
for (const [what, file] of [
['the player', join(player, 'h5p-sw.js')],
diff --git a/packages/vscode/src/page.mjs b/packages/vscode/src/page.mjs
index 8fd76622..cc9d16f9 100644
--- a/packages/vscode/src/page.mjs
+++ b/packages/vscode/src/page.mjs
@@ -9,20 +9,28 @@
* @param {boolean} settings.untrusted
* @param {boolean} settings.newest with the pack's newer libraries
* @param {string | null} settings.lang for a package that names no language
+ * @param {'light' | 'dark' | null} [settings.theme] VS Code's theme, which the page's colours follow
*/
export function viewPage(settings) {
// `<` as an escape, so that no file name can end the script block it is written into.
const json = JSON.stringify(settings).replaceAll('<', '\\u003c')
+ // On before the stylesheet applies, so the page never shows the other theme first; one of
+ // the two names or nothing. Without it the page follows the system, which need not be VS Code's.
+ const theme = settings.theme === 'light' || settings.theme === 'dark' ? settings.theme : null
return `
-
+
Preview
+
+
@@ -37,6 +45,17 @@ export function viewPage(settings) {
if (webview) parent.postMessage({ source: 'h5p-preview', ...message }, webview)
}
+ // VS Code's theme as it changes, sent by the webview so that a switch does not reload the
+ // content: the one message this page takes, from the window around it at the webview's
+ // origin, and as one of the two names only.
+ window.addEventListener('message', (event) => {
+ if (!webview || event.origin !== webview || event.source !== parent) return
+ const message = event.data
+ if (message && message.source === 'h5p-preview-webview' && message.type === 'theme' && (message.theme === 'light' || message.theme === 'dark')) {
+ document.documentElement.dataset.theme = message.theme
+ }
+ })
+
// The library pack the extension carries, for what a package lacks and, unless turned off,
// for newer versions of what it carries.
player.setAttribute('libraries', 'pack')
diff --git a/packages/vscode/src/server.mjs b/packages/vscode/src/server.mjs
index 8ef50079..d26e179d 100644
--- a/packages/vscode/src/server.mjs
+++ b/packages/vscode/src/server.mjs
@@ -41,6 +41,15 @@ export function languageTag(value) {
return value && /^[a-z]{2,3}(?:-[a-z0-9]{1,8})*$/i.test(value) ? value : null
}
+/**
+ * VS Code's theme as the webview names it in the address, `light` or `dark`, and nothing else.
+ * @param {string | null} value
+ * @returns {'light' | 'dark' | null}
+ */
+export function themeName(value) {
+ return value === 'light' || value === 'dark' ? value : null
+}
+
/**
* @typedef {object} PreviewServer
* @property {string} url `http://127.0.0.1:`, no trailing slash
@@ -86,7 +95,8 @@ export async function startServer({ roots, packDir, port = PORTS, restricted = (
// otherwise play it trusted. The tab's switch in a trusted workspace is the address's.
untrusted: restricted() || query.get('untrusted') === '1',
newest: query.get('newest') !== '0',
- lang: languageTag(query.get('lang'))
+ lang: languageTag(query.get('lang')),
+ theme: themeName(query.get('theme'))
})
response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' }).end(page)
return true
diff --git a/packages/vscode/src/webview.mjs b/packages/vscode/src/webview.mjs
index 67043745..bc340292 100644
--- a/packages/vscode/src/webview.mjs
+++ b/packages/vscode/src/webview.mjs
@@ -95,6 +95,17 @@ export function webviewHtml({ nonce, config }) {
const mode = Object.assign({ untrusted: config.untrusted, newest: config.newest }, vscode.getState())
let ready = null
+ // VS Code's theme, for the page's colours: light, or dark, a high-contrast theme as the one it
+ // is built on. VS Code marks the webview's body with it, and a high-contrast light theme with
+ // \`vscode-high-contrast\` too, for older webviews, so light is asked first.
+ function themeOf() {
+ const list = document.body && document.body.classList
+ if (!list) return null
+ if (list.contains('vscode-high-contrast-light') || list.contains('vscode-light')) return 'light'
+ if (list.contains('vscode-dark') || list.contains('vscode-high-contrast')) return 'dark'
+ return null
+ }
+
function play() {
if (config.restricted) mode.untrusted = true
untrustedBox.checked = mode.untrusted
@@ -109,6 +120,8 @@ export function webviewHtml({ nonce, config }) {
if (mode.untrusted) url.searchParams.set('untrusted', '1')
if (!mode.newest) url.searchParams.set('newest', '0')
if (config.lang) url.searchParams.set('lang', config.lang)
+ const theme = themeOf()
+ if (theme) url.searchParams.set('theme', theme)
ready = null
media.hidden = true
say('Opening…')
@@ -211,6 +224,18 @@ export function webviewHtml({ nonce, config }) {
}
})
+ // A theme changed while the preview is open reaches the page at once, as a message to the
+ // frame at the server's origin: reloading it would lose the learner's place.
+ if (typeof MutationObserver === 'function' && document.body) {
+ let shownTheme = themeOf()
+ new MutationObserver(() => {
+ const theme = themeOf()
+ if (!theme || theme === shownTheme) return
+ shownTheme = theme
+ if (frame.contentWindow) frame.contentWindow.postMessage({ source: 'h5p-preview-webview', type: 'theme', theme }, config.origin)
+ }).observe(document.body, { attributes: true, attributeFilter: ['class'] })
+ }
+
play()
diff --git a/packages/vscode/tests/html.test.ts b/packages/vscode/tests/html.test.ts
index 7acfd5bc..4ba3690b 100644
--- a/packages/vscode/tests/html.test.ts
+++ b/packages/vscode/tests/html.test.ts
@@ -59,8 +59,11 @@ class StandIn {
}
}
-/** The webview's script, run against stand-ins: what it posts to the extension, and a way to message it. */
-function runWebview(state?: object) {
+/**
+ * The webview's script, run against stand-ins: what it posts to the extension, and a way to message
+ * it. `environment` gives it a body, as VS Code marks one with its theme, and a MutationObserver.
+ */
+function runWebview(state?: object, environment: { body?: unknown; MutationObserver?: unknown } = {}) {
const html = webviewHtml({ nonce: 'n0nce', config })
const json = /