Skip to content

Commit 6acef1c

Browse files
authored
Merge pull request #91 from missing-elements/feat/play-page-ui
feat(play): a stage with a drawn loader, a file's progress and designed states (#90)
2 parents f0bc657 + a705670 commit 6acef1c

4 files changed

Lines changed: 238 additions & 50 deletions

File tree

‎src/_includes/base.njk‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
<meta name="viewport" content="width=device-width, initial-scale=1">
99
<meta name="color-scheme" content="light dark">
1010
<script>
11-
try { document.querySelector('meta[name="color-scheme"]').content = localStorage.getItem("color-scheme") ?? "light dark"; } catch {}
11+
// Only a page in a frame is told its theme in its address (?theme=dark), by the page that frames it, whose
12+
// theme may not be the system's. Opened by itself, a page keeps the visitor's own choice whatever its address says.
13+
try { const asked = window.parent !== window ? new URLSearchParams(location.search).get("theme") : null; document.querySelector('meta[name="color-scheme"]').content = asked === "light" || asked === "dark" ? asked : localStorage.getItem("color-scheme") ?? "light dark"; } catch {}
1214
</script>
1315
<title>{{ title }}</title>
1416
<meta name="description" content="{{ description }}">

‎src/assets/site.css‎

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,13 +1087,68 @@ pre.prompt { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.9375re
10871087
.step-marker::before, .sample-note[data-loading]::before { border-color: GrayText; border-top-color: Highlight; }
10881088
}
10891089

1090-
/* The play page, /h5p/play/: the activity alone, for a chat app's frame. */
1091-
.play { padding: 0.5rem; }
1092-
.play .player-box { margin: 0; }
1093-
.play-status { margin: 0 0 0.5rem; color: var(--muted); font-size: 0.9rem; }
1094-
.play-status[data-state="asking"] { color: inherit; }
1095-
.play-status[data-state="error"] { color: inherit; font-weight: 600; }
1096-
.play-files { margin: 0 0 0.5rem; }
1097-
.play-status[data-state="ready"] { display: none; }
1098-
.play-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0 0; }
1090+
/* The play page, /h5p/play/: the activity alone, for a chat app's frame. Its page has no colour of
1091+
its own, so a frame shows the chat's behind it; opened by itself it gets room around it. */
1092+
body.play-page { background: transparent; }
1093+
.play { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5rem; max-width: 60rem; margin: 0 auto; padding: 0.5rem; }
1094+
html[data-standalone] .play { padding: 1rem; }
1095+
1096+
/* The stage: the player, and over it until it is ready a loader, a question or a problem. Before
1097+
the player has a size of its own it keeps a video's shape, so what follows does not jump. */
1098+
.play-stage { display: grid; border: 1px solid var(--border); border-radius: 12px; overflow: clip; background: var(--surface); }
1099+
.play-stage > * { grid-area: 1 / 1; min-width: 0; }
1100+
.play:not([data-state="ready"]) .play-stage { aspect-ratio: 16 / 9; }
1101+
.play .player-box { margin: 0; border: 0; border-radius: 0; }
1102+
.play:not([data-state="ready"]) .player-box { visibility: hidden; }
1103+
.play-panel { z-index: 1; display: grid; place-items: center; padding: 1.5rem 1rem; background: var(--surface); text-align: center; }
1104+
.play[data-state="ready"] .play-panel, .play-panel [hidden] { display: none; }
1105+
.play[data-state="asking"] .play-stage { border-style: dashed; border-color: var(--control); }
1106+
.play[data-drop] .play-stage { border-color: var(--accent); }
1107+
.play[data-drop] .play-panel { background: var(--tint); }
1108+
1109+
.play-loader, .play-ask, .play-error { display: grid; justify-items: center; gap: 0.75rem; width: 100%; min-width: 0; max-width: 26rem; }
1110+
.play-panel .button { white-space: normal; }
1111+
.play-label, .play-text, .play-note, .play-heading { margin: 0; }
1112+
.play-label { font-size: 0.9375rem; font-weight: 600; line-height: 1.4; }
1113+
.play-heading { font-size: 1.0625rem; font-weight: 650; line-height: 1.3; }
1114+
.play-text { color: var(--muted); font-size: 0.875rem; line-height: 1.5; overflow-wrap: anywhere; }
1115+
.play-note { color: var(--muted); font-size: 0.8125rem; line-height: 1.4; }
1116+
.play-spinner { width: 2rem; height: 2rem; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; }
1117+
.play-progress { width: min(18rem, 100%); height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
1118+
.play-progress span { display: block; width: var(--done, 0%); height: 100%; border-radius: inherit; background: var(--accent); }
1119+
.play-icon { box-sizing: border-box; width: 3rem; height: 3rem; padding: 0.75rem; border-radius: 50%; background: var(--tint); color: var(--accent); fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
1120+
.play-error .play-icon { background: color-mix(in srgb, var(--t-tag) 14%, transparent); color: var(--t-tag); }
1121+
1122+
/* Under the stage: what the activity is, and what to do with it. Until its name is known a bar
1123+
of its size stands there. */
1124+
.play-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; padding: 0.125rem 0.25rem; }
1125+
.play-about { flex: 1 1 12rem; min-width: 0; }
1126+
.play-title, .play-meta { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1127+
.play-title { font-size: 0.9375rem; font-weight: 600; line-height: 1.35; }
1128+
.play-meta { color: var(--muted); font-size: 0.8125rem; line-height: 1.35; }
1129+
.play-title:empty, .play-meta:empty { border-radius: 4px; background: var(--border); }
1130+
.play-title:empty { width: 11rem; height: 0.9rem; margin: 0.2rem 0; }
1131+
/* A link that carried no activity has no name to wait for. */
1132+
.play[data-state="error"] :is(.play-title, .play-meta):empty { display: none; }
1133+
.play-meta:empty { width: 6rem; height: 0.7rem; margin: 0.2rem 0; }
1134+
.play-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0; }
10991135
.play-actions [hidden] { display: none; }
1136+
.button-icon { width: 1.05em; height: 1.05em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
1137+
1138+
@media (prefers-reduced-motion: no-preference) {
1139+
.play-spinner { animation: turn 0.8s linear infinite; }
1140+
.play-progress span { transition: width 0.3s ease-out; }
1141+
.play[data-state="building"] .play-panel, .play[data-state="fetching"] .play-panel {
1142+
background: linear-gradient(100deg, var(--surface) 40%, color-mix(in srgb, var(--raised) 70%, var(--surface)) 50%, var(--surface) 60%) 0 0 / 250% 100%;
1143+
animation: sheen 1.8s linear infinite;
1144+
}
1145+
.play-title:empty, .play-meta:empty { animation: breathe 1.4s ease-in-out infinite alternate; }
1146+
}
1147+
@keyframes sheen { from { background-position: 125% 0; } to { background-position: -125% 0; } }
1148+
@keyframes breathe { from { opacity: 1; } to { opacity: 0.45; } }
1149+
1150+
@media (forced-colors: active) {
1151+
.play-spinner { border-color: GrayText; border-top-color: Highlight; }
1152+
.play-progress { border: 1px solid CanvasText; }
1153+
.play-progress span { background: Highlight; }
1154+
}

‎src/h5p/play/index.njk‎

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: base.njk
33
title: "Play an H5P activity"
4+
bodyClass: play-page
45
description: "An H5P activity an AI chat wrote, built and played in your browser, with its .h5p file to download. Nothing is sent to a server."
56
# Not a page to land on from a search: it is opened with an activity's source in its link.
67
eleventyExcludeFromCollections: true
@@ -10,20 +11,49 @@ csp: "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' da
1011
---
1112
{#- The player alone, for an activity's source in the link (#source=, as the build page takes it),
1213
so that a chat app can show the activity in its reply: play-page.ts builds it and plays it. -#}
13-
<main class="play" id="main">
14-
<p class="play-status" id="status" role="status" data-state="building">Building the activity in your browser…</p>
15-
{#- For a source that names files of the person's own, a video beside it: chosen here, where
16-
they stay in the browser. The field is hidden, and the button opens it. -#}
17-
<p class="play-files" id="files-box" hidden>
18-
<button type="button" class="button button-solid" id="choose">Choose the file</button>
19-
<input type="file" id="files" multiple hidden>
20-
</p>
21-
<div class="player-box" id="player-box" hidden>
22-
<h5p-player id="player"></h5p-player>
14+
<main class="play" id="main" data-state="building">
15+
{#- What a screen reader is told of each step; what is seen is drawn below. -#}
16+
<p class="visually-hidden" id="status" role="status" data-state="building">Building the activity in your browser…</p>
17+
<div class="play-stage" id="stage">
18+
<div class="player-box" id="player-box" hidden>
19+
<h5p-player id="player"></h5p-player>
20+
</div>
21+
{#- Over the player until it is ready: one of the three below. -#}
22+
<div class="play-panel" id="panel">
23+
<div class="play-loader" id="loader">
24+
<span class="play-spinner" aria-hidden="true"></span>
25+
<p class="play-label" id="label">Building the activity in your browser…</p>
26+
<div class="play-progress" id="progress" role="progressbar" aria-label="Getting the file" aria-valuemin="0" aria-valuemax="100" hidden><span id="progress-bar"></span></div>
27+
<p class="play-note" id="note">Nothing is sent to a server.</p>
28+
<button type="button" class="button" id="instead" hidden>Choose it from your computer instead</button>
29+
</div>
30+
{#- For a source that names files of the person's own, a video beside it: chosen here or
31+
dropped, they stay in the browser. The field is hidden, and the button opens it. -#}
32+
<div class="play-ask" id="files-box" hidden>
33+
<svg class="play-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 16V4M7 9l5-5 5 5M5 20h14"/></svg>
34+
<h1 class="play-heading" id="ask-title">Add your file</h1>
35+
<p class="play-text" id="ask-text"></p>
36+
<button type="button" class="button button-solid button-large" id="choose">Choose the file</button>
37+
<p class="play-note">or drop it here</p>
38+
<input type="file" id="files" multiple hidden>
39+
</div>
40+
<div class="play-error" id="error" hidden>
41+
<svg class="play-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 8v5M12 16.5v.5M10.3 3.9 2.6 17.5A2 2 0 0 0 4.3 20.5h15.4a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z"/></svg>
42+
<h1 class="play-heading" id="error-title"></h1>
43+
<p class="play-text" id="error-text"></p>
44+
<a class="button button-solid button-large" id="fix" target="_blank" rel="noopener" hidden>Open in the build page</a>
45+
</div>
46+
</div>
47+
</div>
48+
<div class="play-bar">
49+
<div class="play-about">
50+
<p class="play-title" id="title"></p>
51+
<p class="play-meta" id="meta"></p>
52+
</div>
53+
<p class="play-actions">
54+
<a class="button" id="edit" target="_blank" rel="noopener">Open in the build page</a>
55+
<a class="button button-solid" id="download" download hidden><svg class="button-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 4v12M7 11l5 5 5-5M5 20h14"/></svg>Download .h5p</a>
56+
</p>
2357
</div>
24-
<p class="play-actions">
25-
<a class="button button-solid" id="download" download hidden>Download the .h5p</a>
26-
<a class="button" id="edit" target="_blank" rel="noopener">Open in the build page</a>
27-
</p>
2858
</main>
2959
<script type="module" src="/h5p/play/play-page.js"></script>

0 commit comments

Comments
 (0)