@astl/player 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/LICENSE +202 -0
- package/README.md +37 -0
- package/dist/a11y.d.ts +41 -0
- package/dist/a11y.d.ts.map +1 -0
- package/dist/a11y.js +101 -0
- package/dist/a11y.js.map +1 -0
- package/dist/attempt/controller.d.ts +104 -0
- package/dist/attempt/controller.d.ts.map +1 -0
- package/dist/attempt/controller.js +325 -0
- package/dist/attempt/controller.js.map +1 -0
- package/dist/checker/http.d.ts +17 -0
- package/dist/checker/http.d.ts.map +1 -0
- package/dist/checker/http.js +115 -0
- package/dist/checker/http.js.map +1 -0
- package/dist/define.d.ts +35 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +84 -0
- package/dist/define.js.map +1 -0
- package/dist/element/base.d.ts +83 -0
- package/dist/element/base.d.ts.map +1 -0
- package/dist/element/base.js +239 -0
- package/dist/element/base.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction/index.d.ts +12 -0
- package/dist/interaction/index.d.ts.map +1 -0
- package/dist/interaction/index.js +4 -0
- package/dist/interaction/index.js.map +1 -0
- package/dist/interaction/keys.d.ts +11 -0
- package/dist/interaction/keys.d.ts.map +1 -0
- package/dist/interaction/keys.js +13 -0
- package/dist/interaction/keys.js.map +1 -0
- package/dist/interaction/pick-and-place.d.ts +120 -0
- package/dist/interaction/pick-and-place.d.ts.map +1 -0
- package/dist/interaction/pick-and-place.js +395 -0
- package/dist/interaction/pick-and-place.js.map +1 -0
- package/dist/interaction/roving-focus.d.ts +44 -0
- package/dist/interaction/roving-focus.d.ts.map +1 -0
- package/dist/interaction/roving-focus.js +115 -0
- package/dist/interaction/roving-focus.js.map +1 -0
- package/dist/messages/en.json +53 -0
- package/dist/messages/help/en.json +14 -0
- package/dist/messages/help/pl.json +14 -0
- package/dist/messages/pl.json +53 -0
- package/dist/messages.d.ts +7 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +18 -0
- package/dist/messages.js.map +1 -0
- package/dist/player/book.d.ts +13 -0
- package/dist/player/book.d.ts.map +1 -0
- package/dist/player/book.js +65 -0
- package/dist/player/book.js.map +1 -0
- package/dist/player/help.d.ts +55 -0
- package/dist/player/help.d.ts.map +1 -0
- package/dist/player/help.js +484 -0
- package/dist/player/help.js.map +1 -0
- package/dist/player/player.d.ts +87 -0
- package/dist/player/player.d.ts.map +1 -0
- package/dist/player/player.js +1229 -0
- package/dist/player/player.js.map +1 -0
- package/dist/player/styled.d.ts +10 -0
- package/dist/player/styled.d.ts.map +1 -0
- package/dist/player/styled.js +213 -0
- package/dist/player/styled.js.map +1 -0
- package/dist/player/styles.d.ts +3 -0
- package/dist/player/styles.d.ts.map +1 -0
- package/dist/player/styles.js +355 -0
- package/dist/player/styles.js.map +1 -0
- package/dist/player/templates.d.ts +25 -0
- package/dist/player/templates.d.ts.map +1 -0
- package/dist/player/templates.js +101 -0
- package/dist/player/templates.js.map +1 -0
- package/dist/player/view.d.ts +44 -0
- package/dist/player/view.d.ts.map +1 -0
- package/dist/player/view.js +231 -0
- package/dist/player/view.js.map +1 -0
- package/dist/runtime.d.ts +45 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +48 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +45 -4
- package/src/a11y.ts +134 -0
- package/src/attempt/controller.ts +381 -0
- package/src/checker/http.ts +149 -0
- package/src/define.ts +114 -0
- package/src/element/base.ts +310 -0
- package/src/index.ts +18 -0
- package/src/interaction/index.ts +11 -0
- package/src/interaction/keys.ts +16 -0
- package/src/interaction/pick-and-place.ts +464 -0
- package/src/interaction/roving-focus.ts +133 -0
- package/src/messages/en.json +53 -0
- package/src/messages/help/en.json +14 -0
- package/src/messages/help/pl.json +14 -0
- package/src/messages/pl.json +53 -0
- package/src/messages.ts +21 -0
- package/src/player/book.ts +70 -0
- package/src/player/help.ts +585 -0
- package/src/player/player.ts +1368 -0
- package/src/player/styled.ts +247 -0
- package/src/player/styles.ts +355 -0
- package/src/player/templates.ts +142 -0
- package/src/player/view.ts +294 -0
- package/src/runtime.ts +95 -0
|
@@ -0,0 +1,1229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<astl-player>`: mounts a view, attaches component elements, renders the chrome (pages, actions, results) and
|
|
3
|
+
* drives an AttemptController. It never holds answer logic: verdicts come from a Checker.
|
|
4
|
+
*/
|
|
5
|
+
import { CheckerError, COLUMN_TAG, COLUMNS_TAG, createI18n, directionOf, fitsAnswer, isSnapshot, negotiateLocale, OPEN_SLOT_KIND, PlayerEvent, PRACTICE_POLICY, roundScore, STYLE_TEMPLATE_ATTRIBUTE, } from '@astl/core';
|
|
6
|
+
import { html, LitElement, nothing, supportsAdoptingStyleSheets, } from 'lit';
|
|
7
|
+
import { announce, verdictIcon } from '../a11y.js';
|
|
8
|
+
import { AttemptController } from '../attempt/controller.js';
|
|
9
|
+
import { httpChecker } from '../checker/http.js';
|
|
10
|
+
import { elementTranslator, PLAYER_NAMESPACE, playerMessages } from '../messages.js';
|
|
11
|
+
import { loadElements, runtime } from '../runtime.js';
|
|
12
|
+
import { playerStyles } from './styles.js';
|
|
13
|
+
import { refreshStyleTemplateSheet, styleTemplateSheet } from './templates.js';
|
|
14
|
+
import { cleanView, hasHelp, isBook, isStyled, isView, LoadError, readView, sha256Hex, viewTags, } from './view.js';
|
|
15
|
+
const STORAGE_PREFIX = 'astl:snapshot:';
|
|
16
|
+
const SNAPSHOT_DELAY_MS = 300;
|
|
17
|
+
const VERDICTS = ['correct', 'partial', 'incorrect', 'empty'];
|
|
18
|
+
/** Minutes left at which the timer is announced. */
|
|
19
|
+
const TIMER_ALERTS = [5, 1];
|
|
20
|
+
const THEMES = ['light', 'dark', 'hc', 'auto'];
|
|
21
|
+
/**
|
|
22
|
+
* Page progress icons (decorative: the visually hidden text says the same): how full a page is, a circle filled from
|
|
23
|
+
* the bottom, half or whole. Never a verdict glyph (a tick, or the half circle split down the middle): answering says
|
|
24
|
+
* nothing about right or wrong.
|
|
25
|
+
*/
|
|
26
|
+
const PROGRESS_ICONS = {
|
|
27
|
+
done: html `<svg class="segment-icon" data-icon="done" viewBox="0 0 20 20" aria-hidden="true" focusable="false">
|
|
28
|
+
<circle cx="10" cy="10" r="7" fill="currentColor" stroke="currentColor" stroke-width="2.5" />
|
|
29
|
+
</svg>`,
|
|
30
|
+
partial: html `<svg class="segment-icon" data-icon="partial" viewBox="0 0 20 20" aria-hidden="true" focusable="false">
|
|
31
|
+
<circle cx="10" cy="10" r="7" fill="none" stroke="currentColor" stroke-width="2.5" />
|
|
32
|
+
<path d="M3 10a7 7 0 0 0 14 0z" fill="currentColor" />
|
|
33
|
+
</svg>`,
|
|
34
|
+
none: nothing,
|
|
35
|
+
};
|
|
36
|
+
function pick(values, ids) {
|
|
37
|
+
const out = {};
|
|
38
|
+
for (const id of ids) {
|
|
39
|
+
const value = values[id];
|
|
40
|
+
if (value !== undefined)
|
|
41
|
+
out[id] = value;
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
function codeOf(error, fallback) {
|
|
46
|
+
if (error instanceof CheckerError)
|
|
47
|
+
return error.problem.code;
|
|
48
|
+
if (error instanceof LoadError)
|
|
49
|
+
return error.code;
|
|
50
|
+
const code = error?.code;
|
|
51
|
+
return typeof code === 'string' && code !== '' ? code : fallback;
|
|
52
|
+
}
|
|
53
|
+
function clock(ms) {
|
|
54
|
+
const seconds = Math.ceil(ms / 1000);
|
|
55
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
56
|
+
return `${pad(Math.floor(seconds / 60))}:${pad(seconds % 60)}`;
|
|
57
|
+
}
|
|
58
|
+
export class AstlPlayer extends LitElement {
|
|
59
|
+
static properties = {
|
|
60
|
+
view: { attribute: false },
|
|
61
|
+
policy: { attribute: false },
|
|
62
|
+
checker: { attribute: false },
|
|
63
|
+
snapshot: { attribute: false },
|
|
64
|
+
locale: {},
|
|
65
|
+
src: {},
|
|
66
|
+
integrity: {},
|
|
67
|
+
endpoint: {},
|
|
68
|
+
theme: {},
|
|
69
|
+
styleTemplate: { attribute: STYLE_TEMPLATE_ATTRIBUTE, reflect: true },
|
|
70
|
+
persist: { type: Boolean },
|
|
71
|
+
};
|
|
72
|
+
static styles = playerStyles;
|
|
73
|
+
#state = 'loading';
|
|
74
|
+
#generation = 0;
|
|
75
|
+
/** The view string being mounted or mounted. */
|
|
76
|
+
#source = null;
|
|
77
|
+
#viewHash = null;
|
|
78
|
+
/** `style-template` of the mounted view's `<astl-doc>`. */
|
|
79
|
+
#documentTemplate = null;
|
|
80
|
+
#mountedLocale = null;
|
|
81
|
+
#controller = null;
|
|
82
|
+
#unsubscribe = null;
|
|
83
|
+
/** The rows of hints, feedback and explanations, when the view offers help. */
|
|
84
|
+
#help = null;
|
|
85
|
+
#mounted = [];
|
|
86
|
+
#pages = [];
|
|
87
|
+
/** The mounted view's `astl-doc`. */
|
|
88
|
+
#doc = null;
|
|
89
|
+
/** A book's module (`kind="book"`, more than one page), loaded with it (player/book.ts); null for anything else. */
|
|
90
|
+
#book = null;
|
|
91
|
+
/** Whether the book shows two pages side by side now: its module says the player is wide enough. */
|
|
92
|
+
#spread = false;
|
|
93
|
+
#resize = null;
|
|
94
|
+
/** Page headings, null where a page has none (a single page without a label). */
|
|
95
|
+
#headings = [];
|
|
96
|
+
#sourceChecker = null;
|
|
97
|
+
#endpointChecker = null;
|
|
98
|
+
#loadError = null;
|
|
99
|
+
/** Plain-text details of a failed source compile, for the author. */
|
|
100
|
+
#loadDetails = null;
|
|
101
|
+
/** Problem code of the last failed check or submit, shown until the next one. */
|
|
102
|
+
#problem = null;
|
|
103
|
+
#confirming = false;
|
|
104
|
+
#snapshotTimer;
|
|
105
|
+
#clock;
|
|
106
|
+
#alerted = new Set();
|
|
107
|
+
#autoSubmitted = false;
|
|
108
|
+
#i18nCache = null;
|
|
109
|
+
/** The controller's checker: resolves the effective checker on every call. */
|
|
110
|
+
#checkerProxy = {
|
|
111
|
+
check: (request) => this.#requireChecker().check(request),
|
|
112
|
+
submit: (request) => this.#requireChecker().submit(request),
|
|
113
|
+
};
|
|
114
|
+
constructor() {
|
|
115
|
+
super();
|
|
116
|
+
this.view = '';
|
|
117
|
+
this.policy = PRACTICE_POLICY;
|
|
118
|
+
this.checker = null;
|
|
119
|
+
this.snapshot = null;
|
|
120
|
+
this.locale = null;
|
|
121
|
+
this.src = null;
|
|
122
|
+
this.integrity = null;
|
|
123
|
+
this.endpoint = null;
|
|
124
|
+
this.theme = 'auto';
|
|
125
|
+
this.styleTemplate = null;
|
|
126
|
+
this.persist = false;
|
|
127
|
+
}
|
|
128
|
+
/** `loading`, `ready`, `active`, `checking`, `submitting`, `submitted`, `review` or `error`. */
|
|
129
|
+
get state() {
|
|
130
|
+
return this.#state;
|
|
131
|
+
}
|
|
132
|
+
/** Lowercase hex SHA-256 of the mounted view; null before mounting or without WebCrypto. */
|
|
133
|
+
get viewHash() {
|
|
134
|
+
return this.#viewHash;
|
|
135
|
+
}
|
|
136
|
+
/** 0-based index of the current page. */
|
|
137
|
+
get page() {
|
|
138
|
+
return this.#controller?.page ?? 0;
|
|
139
|
+
}
|
|
140
|
+
/** Plays a view. Resolves when it is mounted (`astl-ready`); rejects with the error code when it cannot. */
|
|
141
|
+
async load(input) {
|
|
142
|
+
if (input.policy !== undefined)
|
|
143
|
+
this.policy = input.policy;
|
|
144
|
+
if (input.checker !== undefined)
|
|
145
|
+
this.checker = input.checker;
|
|
146
|
+
if (input.snapshot !== undefined)
|
|
147
|
+
this.snapshot = input.snapshot;
|
|
148
|
+
this.view = input.view;
|
|
149
|
+
await this.#loadView(input.view);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Practice: grades the answers and shows verdicts; with `element` (a view element id, under a policy with
|
|
153
|
+
* `checkScope: 'interaction'`) that interaction only, which is not an `astl-result`. Failures are shown and emitted,
|
|
154
|
+
* never thrown.
|
|
155
|
+
*/
|
|
156
|
+
async check(element) {
|
|
157
|
+
const controller = this.#controller;
|
|
158
|
+
if (controller === null)
|
|
159
|
+
return null;
|
|
160
|
+
this.#problem = null;
|
|
161
|
+
if (this.#effectiveChecker() === null) {
|
|
162
|
+
this.#showProblem('no_checker');
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
return await (element === undefined ? controller.check() : controller.checkElement(element));
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
this.#showProblem(codeOf(error, 'internal_error'));
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** Hands the answers in (final). Failures are shown and emitted, never thrown. */
|
|
174
|
+
async submit() {
|
|
175
|
+
const controller = this.#controller;
|
|
176
|
+
if (controller === null)
|
|
177
|
+
return null;
|
|
178
|
+
this.#problem = null;
|
|
179
|
+
this.#confirming = false;
|
|
180
|
+
if (this.#effectiveChecker() === null) {
|
|
181
|
+
this.#showProblem('no_checker');
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const response = await controller.submit();
|
|
186
|
+
await this.updateComplete;
|
|
187
|
+
this.#query('.result')?.focus();
|
|
188
|
+
return response;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
this.#showProblem(codeOf(error, 'internal_error'));
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
goTo(index) {
|
|
196
|
+
return this.#controller?.goTo(index) ?? false;
|
|
197
|
+
}
|
|
198
|
+
/** The next page, or in a spread the next spread. */
|
|
199
|
+
next() {
|
|
200
|
+
return this.#controller?.goTo(this.#step(1)) ?? false;
|
|
201
|
+
}
|
|
202
|
+
/** The previous page, or in a spread the previous spread. */
|
|
203
|
+
previous() {
|
|
204
|
+
return this.#controller?.goTo(this.#step(-1)) ?? false;
|
|
205
|
+
}
|
|
206
|
+
/** Clears answers and results and goes back to the first page (not after submitting). */
|
|
207
|
+
reset() {
|
|
208
|
+
return this.#controller?.reset() ?? false;
|
|
209
|
+
}
|
|
210
|
+
getAnswers() {
|
|
211
|
+
return this.#controller?.answers ?? {};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Sets answers programmatically (`''` clears); no change events from elements. The attempt keeps what the
|
|
215
|
+
* elements accept (an unknown option id or a flag other than "true" is dropped), so what is checked and handed
|
|
216
|
+
* in is always what the student sees.
|
|
217
|
+
*/
|
|
218
|
+
setAnswers(answers) {
|
|
219
|
+
const controller = this.#controller;
|
|
220
|
+
if (controller === null || controller.readOnly)
|
|
221
|
+
return;
|
|
222
|
+
const accepted = {};
|
|
223
|
+
const touched = [];
|
|
224
|
+
for (const { element } of this.#mounted) {
|
|
225
|
+
const own = pick(answers, element.slotIds);
|
|
226
|
+
if (Object.keys(own).length === 0)
|
|
227
|
+
continue;
|
|
228
|
+
element.setAnswers(own);
|
|
229
|
+
const shown = element.getAnswers();
|
|
230
|
+
for (const id of element.slotIds)
|
|
231
|
+
accepted[id] = shown[id] ?? '';
|
|
232
|
+
touched.push(element);
|
|
233
|
+
}
|
|
234
|
+
const changed = controller.setAnswers(accepted);
|
|
235
|
+
for (const element of touched) {
|
|
236
|
+
if (element.slotIds.some((id) => id in changed))
|
|
237
|
+
element.feedback = null;
|
|
238
|
+
}
|
|
239
|
+
this.requestUpdate();
|
|
240
|
+
}
|
|
241
|
+
getSnapshot() {
|
|
242
|
+
return this.#controller?.snapshot(this.#uiState()) ?? null;
|
|
243
|
+
}
|
|
244
|
+
connectedCallback() {
|
|
245
|
+
super.connectedCallback();
|
|
246
|
+
this.#syncClock();
|
|
247
|
+
this.#resize?.observe(this);
|
|
248
|
+
void this.#autoload();
|
|
249
|
+
}
|
|
250
|
+
/** The shadow root also adopts the style template stylesheet, shared by every player and kept up to date. */
|
|
251
|
+
createRenderRoot() {
|
|
252
|
+
const root = super.createRenderRoot();
|
|
253
|
+
if (supportsAdoptingStyleSheets && root instanceof ShadowRoot) {
|
|
254
|
+
root.adoptedStyleSheets = [...root.adoptedStyleSheets, styleTemplateSheet()];
|
|
255
|
+
}
|
|
256
|
+
return root;
|
|
257
|
+
}
|
|
258
|
+
disconnectedCallback() {
|
|
259
|
+
super.disconnectedCallback();
|
|
260
|
+
this.#flushSnapshot();
|
|
261
|
+
this.#syncClock();
|
|
262
|
+
this.#resize?.disconnect();
|
|
263
|
+
}
|
|
264
|
+
firstUpdated() {
|
|
265
|
+
this.#query('.canvas')?.addEventListener(PlayerEvent.change, (event) => {
|
|
266
|
+
const detail = event.detail;
|
|
267
|
+
if (detail?.answers)
|
|
268
|
+
this.#controller?.setAnswers(detail.answers);
|
|
269
|
+
this.requestUpdate();
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
updated(changed) {
|
|
273
|
+
if (changed.has('theme'))
|
|
274
|
+
this.dataset.theme = this.#theme();
|
|
275
|
+
if (changed.has('view') && this.view !== '' && this.view !== this.#source) {
|
|
276
|
+
void this.#loadView(this.view).catch(() => undefined);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (changed.has('src') && changed.get('src') !== undefined && this.src && this.view === '') {
|
|
280
|
+
void this.#loadSrc(this.src).catch(() => undefined);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const controller = this.#controller;
|
|
284
|
+
const policyChanged = changed.has('policy') && controller !== null && controller.policy !== this.policy;
|
|
285
|
+
const localeChanged = changed.has('locale') && controller !== null && this.#mountedLocale !== this.#uiLocale();
|
|
286
|
+
if ((policyChanged || localeChanged) && this.#source !== null) {
|
|
287
|
+
void this.#loadView(this.#source, this.getSnapshot(), this.#sourceChecker).catch(() => undefined);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
render() {
|
|
291
|
+
const locale = this.#uiLocale();
|
|
292
|
+
const t = this.#i18n().translator(locale, PLAYER_NAMESPACE);
|
|
293
|
+
const controller = this.#controller;
|
|
294
|
+
return html `<div
|
|
295
|
+
class="root"
|
|
296
|
+
part="player"
|
|
297
|
+
lang=${locale}
|
|
298
|
+
dir=${directionOf(locale)}
|
|
299
|
+
data-style-template=${this.#documentTemplate ?? nothing}
|
|
300
|
+
?data-spread=${this.#spread}
|
|
301
|
+
aria-busy=${this.#state === 'loading' ? 'true' : 'false'}
|
|
302
|
+
>
|
|
303
|
+
${this.#state === 'loading' ? html `<p class="status">${t('loading')}</p>` : nothing}
|
|
304
|
+
${this.#loadError === null ? nothing : html `<p class="problem">${this.#errorMessage(t, this.#loadError)}</p>`}
|
|
305
|
+
${this.#loadDetails === null
|
|
306
|
+
? nothing
|
|
307
|
+
: html `<div class="problem-details" part="problem-details" role="alert">${this.#loadDetails}</div>`}
|
|
308
|
+
${controller === null ? nothing : this.#renderHeader(controller, t)}
|
|
309
|
+
<div class="canvas" part="canvas" tabindex="-1" ?hidden=${controller === null}></div>
|
|
310
|
+
${controller === null ? nothing : this.#renderResult(controller, t)}
|
|
311
|
+
${this.#problem === null ? nothing : html `<p class="problem">${this.#errorMessage(t, this.#problem)}</p>`}
|
|
312
|
+
${controller === null ? nothing : this.#renderFooter(controller, t)}
|
|
313
|
+
<div class="astl-vh live" aria-live="polite"></div>
|
|
314
|
+
</div>`;
|
|
315
|
+
}
|
|
316
|
+
#renderHeader(c, t) {
|
|
317
|
+
const pages = c.pageCount > 1;
|
|
318
|
+
const left = c.readOnly ? null : c.timeLeft();
|
|
319
|
+
if (!pages && left === null)
|
|
320
|
+
return nothing;
|
|
321
|
+
return html `<div class="header" part="header">
|
|
322
|
+
${pages
|
|
323
|
+
? html `<p class="counter">${this.#counter(c, t)}</p>
|
|
324
|
+
<nav aria-label=${t('progress.label')}>
|
|
325
|
+
<ol class="progress">
|
|
326
|
+
${c.pages.map((_, index) => this.#renderSegment(c, t, index))}
|
|
327
|
+
</ol>
|
|
328
|
+
</nav>`
|
|
329
|
+
: nothing}
|
|
330
|
+
${left === null
|
|
331
|
+
? nothing
|
|
332
|
+
: html `<p class="timer">
|
|
333
|
+
<span class="timer-label" id="timer-label">${t('timer.label')}</span>
|
|
334
|
+
<span role="timer" aria-labelledby="timer-label">${clock(left)}</span>
|
|
335
|
+
</p>`}
|
|
336
|
+
</div>`;
|
|
337
|
+
}
|
|
338
|
+
/** "Strona 2 z 4", or in a spread "Strony 1-2 z 4". */
|
|
339
|
+
#counter(c, t) {
|
|
340
|
+
const [first, last] = this.#shown(c.page);
|
|
341
|
+
return last > first
|
|
342
|
+
? t('page.counter.spread', { from: first + 1, to: last + 1, total: c.pageCount })
|
|
343
|
+
: t('page.counter', { n: first + 1, total: c.pageCount });
|
|
344
|
+
}
|
|
345
|
+
#renderSegment(c, t, index) {
|
|
346
|
+
const state = this.#pageState(index);
|
|
347
|
+
const [first, last] = this.#shown(c.page);
|
|
348
|
+
// Both pages of a spread are on screen: both are current.
|
|
349
|
+
const current = index >= first && index <= last ? 'step' : nothing;
|
|
350
|
+
const label = html `<span aria-hidden="true">${index + 1}</span>${PROGRESS_ICONS[state]}<span class="astl-vh"
|
|
351
|
+
>${t('progress.item', { n: index + 1, state })}</span
|
|
352
|
+
>`;
|
|
353
|
+
// Linear attempts show progress only: there is nowhere to jump to.
|
|
354
|
+
const linear = c.policy.navigation === 'linear' && !c.readOnly;
|
|
355
|
+
return html `<li>
|
|
356
|
+
${linear
|
|
357
|
+
? html `<span class="segment" data-state=${state} aria-current=${current}>${label}</span>`
|
|
358
|
+
: html `<button
|
|
359
|
+
type="button"
|
|
360
|
+
class="segment"
|
|
361
|
+
data-state=${state}
|
|
362
|
+
aria-current=${current}
|
|
363
|
+
@click=${() => this.goTo(index)}
|
|
364
|
+
>
|
|
365
|
+
${label}
|
|
366
|
+
</button>`}
|
|
367
|
+
</li>`;
|
|
368
|
+
}
|
|
369
|
+
#renderResult(c, t) {
|
|
370
|
+
const response = c.response;
|
|
371
|
+
if (response === null)
|
|
372
|
+
return nothing;
|
|
373
|
+
const result = response.result;
|
|
374
|
+
const passed = 'passed' in response ? response.passed : null;
|
|
375
|
+
const scored = result !== null && this.#scored(result);
|
|
376
|
+
const teacher = this.#teacherText(t, response);
|
|
377
|
+
// Nothing graded and nothing for the teacher (flash cards alone): practice only, instead of a score.
|
|
378
|
+
const practice = result !== null && !scored && teacher === null;
|
|
379
|
+
return html `<section class="result" part="result" tabindex="-1" aria-labelledby="result-title">
|
|
380
|
+
<h2 class="result-title" id="result-title">${t('result.title')}</h2>
|
|
381
|
+
${result === null
|
|
382
|
+
? html `<p>${t('result.submitted')} ${t('result.later')}</p>`
|
|
383
|
+
: html `${scored
|
|
384
|
+
? html `<p class="score">${this.#scoreText(t, result)}</p>
|
|
385
|
+
<ul class="counts">
|
|
386
|
+
${VERDICTS.filter((v) => result.counts[v] > 0).map((v) => html `<li class="astl-verdict" data-verdict=${v}>
|
|
387
|
+
${verdictIcon(v)}<span>${t('result.count', { verdict: t(`verdict.${v}`), count: result.counts[v] })}</span>
|
|
388
|
+
</li>`)}
|
|
389
|
+
</ul>`
|
|
390
|
+
: nothing}
|
|
391
|
+
${teacher === null ? nothing : html `<p class="teacher">${teacher}</p>`}
|
|
392
|
+
${practice ? html `<p class="practice">${t('result.practice')}</p>` : nothing}
|
|
393
|
+
${passed === null || !scored ? nothing : html `<p class="passed">${t(passed ? 'result.passed' : 'result.notPassed')}</p>`}`}
|
|
394
|
+
</section>`;
|
|
395
|
+
}
|
|
396
|
+
/** Whether a result has a score to show: something graded. */
|
|
397
|
+
#scored(result) {
|
|
398
|
+
return result.max > 0;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* The line about the answers of ungraded components (open answers, for the teacher), or null without any: sent to
|
|
402
|
+
* the teacher by a submit (how many, next to a score), not checked by a check.
|
|
403
|
+
*/
|
|
404
|
+
#teacherText(t, response) {
|
|
405
|
+
const open = this.#openAnswers();
|
|
406
|
+
if (open.slots === 0 || response.result === null)
|
|
407
|
+
return null;
|
|
408
|
+
if (!('submittedAt' in response))
|
|
409
|
+
return t('result.teacher.unchecked');
|
|
410
|
+
return response.result.max === 0
|
|
411
|
+
? t('result.teacher.sent')
|
|
412
|
+
: t('result.teacher.count', { count: open.answered });
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Slots of ungraded components (open answers: optional, never graded), and how many hold an answer the server keeps:
|
|
416
|
+
* one longer than its kind allows is never stored, so it never counts as sent.
|
|
417
|
+
*/
|
|
418
|
+
#openAnswers() {
|
|
419
|
+
const answers = this.#controller?.answers ?? {};
|
|
420
|
+
let slots = 0;
|
|
421
|
+
let answered = 0;
|
|
422
|
+
for (const { element, manifest } of this.#mounted) {
|
|
423
|
+
if (manifest.graded)
|
|
424
|
+
continue;
|
|
425
|
+
const kind = manifest.slotKinds[0] ?? OPEN_SLOT_KIND;
|
|
426
|
+
for (const id of element.slotIds) {
|
|
427
|
+
slots++;
|
|
428
|
+
const value = answers[id] ?? '';
|
|
429
|
+
if (value !== '' && fitsAnswer(value, kind))
|
|
430
|
+
answered++;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return { slots, answered };
|
|
434
|
+
}
|
|
435
|
+
#renderFooter(c, t) {
|
|
436
|
+
const pages = c.pageCount > 1;
|
|
437
|
+
const actions = this.#renderActions(c, t);
|
|
438
|
+
if (!pages && actions === nothing)
|
|
439
|
+
return nothing;
|
|
440
|
+
const linear = c.policy.navigation === 'linear' && !c.readOnly;
|
|
441
|
+
return html `<div class="footer" part="footer">
|
|
442
|
+
${pages
|
|
443
|
+
? html `<div class="nav">
|
|
444
|
+
${linear
|
|
445
|
+
? nothing
|
|
446
|
+
: html `<button
|
|
447
|
+
type="button"
|
|
448
|
+
class="button"
|
|
449
|
+
?disabled=${!c.canGoTo(this.#step(-1))}
|
|
450
|
+
@click=${() => this.previous()}
|
|
451
|
+
>
|
|
452
|
+
${t('nav.previous')}
|
|
453
|
+
</button>`}
|
|
454
|
+
<button type="button" class="button" ?disabled=${!c.canGoTo(this.#step(1))} @click=${() => this.next()}>
|
|
455
|
+
${t('nav.next')}
|
|
456
|
+
</button>
|
|
457
|
+
</div>`
|
|
458
|
+
: nothing}
|
|
459
|
+
${actions}
|
|
460
|
+
</div>`;
|
|
461
|
+
}
|
|
462
|
+
#renderActions(c, t) {
|
|
463
|
+
if (c.readOnly)
|
|
464
|
+
return nothing;
|
|
465
|
+
if (this.#confirming) {
|
|
466
|
+
return html `<div
|
|
467
|
+
class="confirm"
|
|
468
|
+
role="group"
|
|
469
|
+
tabindex="-1"
|
|
470
|
+
aria-labelledby="confirm-text"
|
|
471
|
+
@keydown=${(event) => {
|
|
472
|
+
if (event.key === 'Escape')
|
|
473
|
+
this.#cancelConfirm();
|
|
474
|
+
}}
|
|
475
|
+
>
|
|
476
|
+
<p id="confirm-text">${t('confirm.empty', { count: this.#emptyCount() })}</p>
|
|
477
|
+
<div class="actions">
|
|
478
|
+
<button type="button" class="button" @click=${() => this.#cancelConfirm()}>${t('confirm.cancel')}</button>
|
|
479
|
+
<button type="button" class="button primary" @click=${() => void this.submit()}>
|
|
480
|
+
${t('confirm.submit')}
|
|
481
|
+
</button>
|
|
482
|
+
</div>
|
|
483
|
+
</div>`;
|
|
484
|
+
}
|
|
485
|
+
if (c.policy.mode === 'practice') {
|
|
486
|
+
// Nothing to answer (flash cards, media, text alone): no Check and no Start over, which would lead nowhere, but
|
|
487
|
+
// the practice-only line from the start (once a result shows, it says so).
|
|
488
|
+
if (!this.#mounted.some(({ element }) => element.slotIds.length > 0)) {
|
|
489
|
+
return c.result === null ? html `<p class="practice-only">${t('result.practice')}</p>` : nothing;
|
|
490
|
+
}
|
|
491
|
+
const left = c.checksLeft;
|
|
492
|
+
return html `<div class="actions">
|
|
493
|
+
${left === null ? nothing : html `<span class="hint">${t('checks.left', { count: left })}</span>`}
|
|
494
|
+
${c.result === null
|
|
495
|
+
? nothing
|
|
496
|
+
: html `<button type="button" class="button" @click=${() => this.reset()}>${t('action.reset')}</button>`}
|
|
497
|
+
<button
|
|
498
|
+
type="button"
|
|
499
|
+
class="button primary"
|
|
500
|
+
aria-disabled=${c.canCheck() ? nothing : 'true'}
|
|
501
|
+
@click=${() => {
|
|
502
|
+
if (c.canCheck())
|
|
503
|
+
void this.check();
|
|
504
|
+
}}
|
|
505
|
+
>
|
|
506
|
+
${t('action.check')}
|
|
507
|
+
</button>
|
|
508
|
+
</div>`;
|
|
509
|
+
}
|
|
510
|
+
if (c.policy.mode === 'test') {
|
|
511
|
+
return html `<div class="actions">
|
|
512
|
+
<button
|
|
513
|
+
type="button"
|
|
514
|
+
class="button primary"
|
|
515
|
+
aria-disabled=${c.canSubmit() ? nothing : 'true'}
|
|
516
|
+
@click=${() => this.#onSubmit()}
|
|
517
|
+
>
|
|
518
|
+
${t('action.submit')}
|
|
519
|
+
</button>
|
|
520
|
+
</div>`;
|
|
521
|
+
}
|
|
522
|
+
return nothing;
|
|
523
|
+
}
|
|
524
|
+
#onSubmit() {
|
|
525
|
+
if (!this.#controller?.canSubmit())
|
|
526
|
+
return;
|
|
527
|
+
if (this.#emptyCount() === 0) {
|
|
528
|
+
void this.submit();
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
this.#confirming = true;
|
|
532
|
+
this.requestUpdate();
|
|
533
|
+
void this.updateComplete.then(() => this.#query('.confirm')?.focus());
|
|
534
|
+
}
|
|
535
|
+
#cancelConfirm() {
|
|
536
|
+
this.#confirming = false;
|
|
537
|
+
this.requestUpdate();
|
|
538
|
+
void this.updateComplete.then(() => this.#query('.actions .primary')?.focus());
|
|
539
|
+
}
|
|
540
|
+
#scoreText(t, result) {
|
|
541
|
+
return t('result.score', { score: roundScore(result.score), max: roundScore(result.max) });
|
|
542
|
+
}
|
|
543
|
+
#resultAnnouncement(t) {
|
|
544
|
+
const response = this.#controller?.response ?? null;
|
|
545
|
+
if (response === null)
|
|
546
|
+
return null;
|
|
547
|
+
const result = response.result;
|
|
548
|
+
if (result === null)
|
|
549
|
+
return `${t('result.submitted')} ${t('result.later')}`;
|
|
550
|
+
const scored = this.#scored(result);
|
|
551
|
+
const parts = scored ? [t('result.announce', { score: this.#scoreText(t, result) })] : [];
|
|
552
|
+
for (const v of VERDICTS) {
|
|
553
|
+
const count = result.counts[v];
|
|
554
|
+
if (count > 0)
|
|
555
|
+
parts.push(t('result.countAnnounce', { verdict: t(`verdict.${v}`), count }));
|
|
556
|
+
}
|
|
557
|
+
const teacher = this.#teacherText(t, response);
|
|
558
|
+
if (teacher !== null)
|
|
559
|
+
parts.push(teacher);
|
|
560
|
+
else if (!scored)
|
|
561
|
+
parts.push(t('result.practice'));
|
|
562
|
+
const passed = 'passed' in response ? response.passed : null;
|
|
563
|
+
if (passed !== null && scored)
|
|
564
|
+
parts.push(t(passed ? 'result.passed' : 'result.notPassed'));
|
|
565
|
+
return parts.join(' ');
|
|
566
|
+
}
|
|
567
|
+
#errorMessage(t, code) {
|
|
568
|
+
const key = `error.${code}`;
|
|
569
|
+
const message = t(key);
|
|
570
|
+
return message === key ? t('error.internal_error') : message;
|
|
571
|
+
}
|
|
572
|
+
// Loading
|
|
573
|
+
async #autoload() {
|
|
574
|
+
if (document.readyState === 'loading') {
|
|
575
|
+
await new Promise((resolve) => document.addEventListener('DOMContentLoaded', resolve, { once: true }));
|
|
576
|
+
}
|
|
577
|
+
await this.updateComplete;
|
|
578
|
+
if (this.#generation > 0 || this.view !== '')
|
|
579
|
+
return;
|
|
580
|
+
const doc = this.querySelector('astl-doc');
|
|
581
|
+
if (doc !== null)
|
|
582
|
+
await this.#loadLightDom(doc).catch(() => undefined);
|
|
583
|
+
else if (this.src)
|
|
584
|
+
await this.#loadSrc(this.src).catch(() => undefined);
|
|
585
|
+
}
|
|
586
|
+
/** Light-DOM content: a view plays directly, a source (author ids, answers) goes through `compileSource`. */
|
|
587
|
+
async #loadLightDom(doc) {
|
|
588
|
+
if (isView(doc))
|
|
589
|
+
return this.#loadView(doc.outerHTML);
|
|
590
|
+
const generation = this.#begin();
|
|
591
|
+
const compile = runtime.compileSource;
|
|
592
|
+
if (compile === null)
|
|
593
|
+
throw this.#fail('source_needs_compiler');
|
|
594
|
+
const lang = doc.getAttribute('lang') ||
|
|
595
|
+
doc.parentElement?.closest('[lang]')?.getAttribute('lang') ||
|
|
596
|
+
document.documentElement.lang ||
|
|
597
|
+
'';
|
|
598
|
+
// Serialise through an inert template: the page's own DOM stays untouched.
|
|
599
|
+
const template = document.createElement('template');
|
|
600
|
+
template.innerHTML = doc.outerHTML;
|
|
601
|
+
const copy = template.content.firstElementChild;
|
|
602
|
+
if (lang !== '' && copy !== null && !copy.getAttribute('lang'))
|
|
603
|
+
copy.setAttribute('lang', lang);
|
|
604
|
+
let compiled;
|
|
605
|
+
try {
|
|
606
|
+
compiled = await compile(template.innerHTML, { lang, locale: this.#uiLocale() });
|
|
607
|
+
}
|
|
608
|
+
catch (error) {
|
|
609
|
+
// The compiler's message lists the issues for the author; text only, never parsed as HTML.
|
|
610
|
+
const details = error instanceof Error ? error.message : typeof error === 'string' ? error : '';
|
|
611
|
+
if (generation === this.#generation)
|
|
612
|
+
throw this.#fail(codeOf(error, 'source_invalid'), details.trim() || null);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
if (generation !== this.#generation)
|
|
616
|
+
return;
|
|
617
|
+
await this.#loadView(compiled.view, undefined, compiled.checker);
|
|
618
|
+
}
|
|
619
|
+
async #loadSrc(src) {
|
|
620
|
+
const generation = this.#begin();
|
|
621
|
+
let text;
|
|
622
|
+
try {
|
|
623
|
+
const response = await fetch(src);
|
|
624
|
+
if (!response.ok)
|
|
625
|
+
throw new LoadError('load_failed');
|
|
626
|
+
text = await response.text();
|
|
627
|
+
}
|
|
628
|
+
catch {
|
|
629
|
+
if (generation === this.#generation)
|
|
630
|
+
throw this.#fail('load_failed');
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (generation !== this.#generation)
|
|
634
|
+
return;
|
|
635
|
+
if (this.integrity !== null) {
|
|
636
|
+
const actual = await sha256Hex(text).catch(() => null);
|
|
637
|
+
if (generation !== this.#generation)
|
|
638
|
+
return;
|
|
639
|
+
if (actual === null || actual !== this.integrity.trim().toLowerCase())
|
|
640
|
+
throw this.#fail('integrity_mismatch');
|
|
641
|
+
}
|
|
642
|
+
await this.#loadView(text);
|
|
643
|
+
}
|
|
644
|
+
async #loadView(view, snapshot, sourceChecker) {
|
|
645
|
+
const generation = this.#begin();
|
|
646
|
+
this.#source = view;
|
|
647
|
+
this.#sourceChecker = sourceChecker ?? null;
|
|
648
|
+
try {
|
|
649
|
+
await this.#mount(view, generation, snapshot);
|
|
650
|
+
}
|
|
651
|
+
catch (error) {
|
|
652
|
+
if (generation === this.#generation)
|
|
653
|
+
throw this.#fail(codeOf(error, 'view_invalid'));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
/** Tears the current attempt down and starts a new load generation (older loads then stop). */
|
|
657
|
+
#begin() {
|
|
658
|
+
this.#flushSnapshot();
|
|
659
|
+
this.#unsubscribe?.();
|
|
660
|
+
this.#unsubscribe = null;
|
|
661
|
+
this.#help?.destroy();
|
|
662
|
+
this.#help = null;
|
|
663
|
+
this.#controller = null;
|
|
664
|
+
this.#mounted = [];
|
|
665
|
+
this.#pages = [];
|
|
666
|
+
this.#doc = null;
|
|
667
|
+
this.#book = null;
|
|
668
|
+
this.#spread = false;
|
|
669
|
+
this.#resize?.disconnect();
|
|
670
|
+
this.#resize = null;
|
|
671
|
+
this.#headings = [];
|
|
672
|
+
this.#source = null;
|
|
673
|
+
this.#viewHash = null;
|
|
674
|
+
this.#documentTemplate = null;
|
|
675
|
+
this.#loadError = null;
|
|
676
|
+
this.#loadDetails = null;
|
|
677
|
+
this.#problem = null;
|
|
678
|
+
this.#confirming = false;
|
|
679
|
+
this.#alerted.clear();
|
|
680
|
+
this.#autoSubmitted = false;
|
|
681
|
+
this.#query('.canvas')?.replaceChildren();
|
|
682
|
+
this.#syncClock();
|
|
683
|
+
this.#setState('loading');
|
|
684
|
+
return ++this.#generation;
|
|
685
|
+
}
|
|
686
|
+
async #mount(view, generation, snapshotOverride) {
|
|
687
|
+
await this.updateComplete;
|
|
688
|
+
const fragment = readView(view);
|
|
689
|
+
// Never fails the view: without its styles the exercise still plays, unstyled.
|
|
690
|
+
const styling = isStyled(fragment)
|
|
691
|
+
? import('./styled.js').catch((error) => {
|
|
692
|
+
console.error(error);
|
|
693
|
+
return null;
|
|
694
|
+
})
|
|
695
|
+
: null;
|
|
696
|
+
// The same for help: without its module the exercise plays without hints and feedback texts.
|
|
697
|
+
const helping = hasHelp(fragment)
|
|
698
|
+
? import('./help.js').catch((error) => {
|
|
699
|
+
console.error(error);
|
|
700
|
+
return null;
|
|
701
|
+
})
|
|
702
|
+
: null;
|
|
703
|
+
// And for a book: without its module it plays one page at a time, as an exercise.
|
|
704
|
+
const booking = isBook(fragment)
|
|
705
|
+
? import('./book.js').catch((error) => {
|
|
706
|
+
console.error(error);
|
|
707
|
+
return null;
|
|
708
|
+
})
|
|
709
|
+
: null;
|
|
710
|
+
try {
|
|
711
|
+
await loadElements(viewTags(fragment));
|
|
712
|
+
}
|
|
713
|
+
catch (error) {
|
|
714
|
+
// A missing chunk (offline, a new deployment) fails the whole view: without it, its questions would show as
|
|
715
|
+
// notices and grade as unanswered. The cause is for the developer.
|
|
716
|
+
console.error(error);
|
|
717
|
+
throw new LoadError('load_failed');
|
|
718
|
+
}
|
|
719
|
+
const styled = await styling;
|
|
720
|
+
if (generation !== this.#generation)
|
|
721
|
+
return;
|
|
722
|
+
refreshStyleTemplateSheet();
|
|
723
|
+
const styles = styled?.takeStyles(fragment);
|
|
724
|
+
styled?.adoptStyledSheet(this.renderRoot);
|
|
725
|
+
cleanView(fragment, new Map([...runtime.elements].map(([tag, registration]) => [tag, registration.manifest])), runtime.urlPolicy);
|
|
726
|
+
const viewHash = await sha256Hex(view).catch(() => null);
|
|
727
|
+
if (generation !== this.#generation)
|
|
728
|
+
return;
|
|
729
|
+
const locale = this.#uiLocale();
|
|
730
|
+
const i18n = this.#i18n();
|
|
731
|
+
const t = i18n.translator(locale, PLAYER_NAMESPACE);
|
|
732
|
+
const content = document.importNode(fragment, true);
|
|
733
|
+
if (styles !== undefined)
|
|
734
|
+
styled?.applyStyles(styles, fragment, content);
|
|
735
|
+
customElements.upgrade(content);
|
|
736
|
+
const doc = content.firstElementChild;
|
|
737
|
+
if (!doc.dir)
|
|
738
|
+
doc.dir = directionOf(doc.lang || locale);
|
|
739
|
+
const pages = Array.from(doc.children).filter((el) => el.localName === 'astl-page');
|
|
740
|
+
if (pages.length === 0)
|
|
741
|
+
pages.push(doc);
|
|
742
|
+
const found = [];
|
|
743
|
+
this.#collect(doc, found, () => {
|
|
744
|
+
const note = document.createElement('span');
|
|
745
|
+
note.className = 'astl-notice';
|
|
746
|
+
note.setAttribute('role', 'note');
|
|
747
|
+
note.lang = locale;
|
|
748
|
+
note.dir = directionOf(locale);
|
|
749
|
+
note.textContent = t('unsupported');
|
|
750
|
+
return note;
|
|
751
|
+
});
|
|
752
|
+
// A single page without a label gets no "Page 1" heading on top of its own content (the canvas is the focus
|
|
753
|
+
// target then); labelled pages and pages of a multi-page view always have one. The generated "Page n" is for
|
|
754
|
+
// screen readers and for the focus after a page change, not for the eyes: visually hidden, still a heading.
|
|
755
|
+
const headings = pages.map((page, index) => {
|
|
756
|
+
if (pages.length === 1 && !page.getAttribute('label'))
|
|
757
|
+
return null;
|
|
758
|
+
const heading = document.createElement('h2');
|
|
759
|
+
heading.className = 'astl-page-heading';
|
|
760
|
+
heading.tabIndex = -1;
|
|
761
|
+
// The heading follows the content's direction, so it starts where the text starts. An authored label is
|
|
762
|
+
// content. The generated "Page n" is UI text: the UI language on the heading, and a <bdi> that takes its
|
|
763
|
+
// direction from the text itself.
|
|
764
|
+
const label = page.getAttribute('label');
|
|
765
|
+
if (label) {
|
|
766
|
+
heading.textContent = label;
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
heading.lang = locale;
|
|
770
|
+
heading.classList.add('astl-vh');
|
|
771
|
+
const generated = document.createElement('bdi');
|
|
772
|
+
generated.textContent = t('page.heading', { n: index + 1 });
|
|
773
|
+
heading.append(generated);
|
|
774
|
+
}
|
|
775
|
+
page.prepend(heading);
|
|
776
|
+
return heading;
|
|
777
|
+
});
|
|
778
|
+
let inline = 0;
|
|
779
|
+
const mounted = found.map(({ element, manifest }) => {
|
|
780
|
+
element.attach({
|
|
781
|
+
locale,
|
|
782
|
+
t: elementTranslator(i18n, locale, manifest.messages),
|
|
783
|
+
announce: (message) => this.#announce(message),
|
|
784
|
+
number: manifest.display === 'inline' ? ++inline : 0,
|
|
785
|
+
seed: this.policy.seed,
|
|
786
|
+
});
|
|
787
|
+
const page = pages.findIndex((p) => p.contains(element));
|
|
788
|
+
return { element, manifest, page: Math.max(0, page) };
|
|
789
|
+
});
|
|
790
|
+
const canvas = this.#query('.canvas');
|
|
791
|
+
if (canvas === null)
|
|
792
|
+
throw new LoadError('view_invalid');
|
|
793
|
+
canvas.replaceChildren(content);
|
|
794
|
+
const candidate = snapshotOverride !== undefined ? snapshotOverride : (this.snapshot ?? this.#storedSnapshot(viewHash));
|
|
795
|
+
let snapshot = AttemptController.restorable(candidate, viewHash);
|
|
796
|
+
if (snapshot !== null) {
|
|
797
|
+
// A restored answer is what the elements accept (e.g. option ids of an earlier compilation are dropped).
|
|
798
|
+
const accepted = {};
|
|
799
|
+
for (const { element } of mounted) {
|
|
800
|
+
const own = pick(snapshot.answers, element.slotIds);
|
|
801
|
+
if (Object.keys(own).length > 0)
|
|
802
|
+
element.setAnswers(own);
|
|
803
|
+
Object.assign(accepted, pick(element.getAnswers(), element.slotIds));
|
|
804
|
+
}
|
|
805
|
+
snapshot = { ...snapshot, answers: accepted };
|
|
806
|
+
}
|
|
807
|
+
const controller = new AttemptController({
|
|
808
|
+
policy: this.policy,
|
|
809
|
+
checker: this.#checkerProxy,
|
|
810
|
+
pages: pages.map((page, index) => ({
|
|
811
|
+
id: page.id || `page-${index + 1}`,
|
|
812
|
+
slotIds: mounted.filter((m) => m.page === index).flatMap((m) => [...m.element.slotIds]),
|
|
813
|
+
})),
|
|
814
|
+
snapshot,
|
|
815
|
+
viewHash,
|
|
816
|
+
});
|
|
817
|
+
this.#controller = controller;
|
|
818
|
+
this.#mounted = mounted;
|
|
819
|
+
this.#pages = pages;
|
|
820
|
+
this.#doc = doc;
|
|
821
|
+
this.#headings = headings;
|
|
822
|
+
this.#viewHash = viewHash;
|
|
823
|
+
this.#documentTemplate = doc.getAttribute(STYLE_TEMPLATE_ATTRIBUTE);
|
|
824
|
+
this.#mountedLocale = locale;
|
|
825
|
+
for (const { element } of mounted) {
|
|
826
|
+
const ui = controller.restored ? snapshot?.ui[element.id] : undefined;
|
|
827
|
+
if (ui !== undefined)
|
|
828
|
+
element.setUiState?.(ui);
|
|
829
|
+
element.disabled = controller.readOnly;
|
|
830
|
+
}
|
|
831
|
+
this.#unsubscribe = controller.subscribe((change) => this.#onChange(change));
|
|
832
|
+
const help = await helping;
|
|
833
|
+
if (generation !== this.#generation)
|
|
834
|
+
return;
|
|
835
|
+
this.#help =
|
|
836
|
+
help?.mountHelp({
|
|
837
|
+
controller,
|
|
838
|
+
mounted,
|
|
839
|
+
pages,
|
|
840
|
+
locale,
|
|
841
|
+
urlPolicy: runtime.urlPolicy,
|
|
842
|
+
root: this.renderRoot,
|
|
843
|
+
checker: () => this.#effectiveChecker(),
|
|
844
|
+
check: (id) => this.check(id),
|
|
845
|
+
announce: (message) => this.#announce(message),
|
|
846
|
+
}) ?? null;
|
|
847
|
+
const book = pages.length > 1 ? await booking : null;
|
|
848
|
+
if (generation !== this.#generation)
|
|
849
|
+
return;
|
|
850
|
+
if (book) {
|
|
851
|
+
this.#book = book;
|
|
852
|
+
book.adoptBookSheet(this.renderRoot);
|
|
853
|
+
this.#resize = book.watchSpread(this, (spread) => this.#setSpread(spread));
|
|
854
|
+
}
|
|
855
|
+
this.#showPage(controller.page, false);
|
|
856
|
+
this.#setState(controller.state);
|
|
857
|
+
this.#syncClock();
|
|
858
|
+
this.requestUpdate();
|
|
859
|
+
// Ready means rendered: the chrome and every Lit-based element have painted their first frame.
|
|
860
|
+
await this.updateComplete;
|
|
861
|
+
await Promise.all(mounted.map(({ element }) => element.updateComplete));
|
|
862
|
+
if (generation !== this.#generation)
|
|
863
|
+
return;
|
|
864
|
+
const ready = {
|
|
865
|
+
viewHash: viewHash ?? '',
|
|
866
|
+
pages: pages.length,
|
|
867
|
+
slots: mounted.reduce((n, { element }) => n + element.slotIds.length, 0),
|
|
868
|
+
};
|
|
869
|
+
this.#dispatch(PlayerEvent.ready, ready);
|
|
870
|
+
}
|
|
871
|
+
/** Finds component elements; unknown custom elements and too new versions become notices. */
|
|
872
|
+
#collect(parent, found, notice) {
|
|
873
|
+
for (const child of Array.from(parent.children)) {
|
|
874
|
+
const tag = child.localName;
|
|
875
|
+
if (tag === 'astl-page' || tag === COLUMNS_TAG || tag === COLUMN_TAG || !tag.includes('-')) {
|
|
876
|
+
this.#collect(child, found, notice);
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
const registration = runtime.elements.get(tag);
|
|
880
|
+
const version = Number.parseInt(child.getAttribute('v') ?? '1', 10);
|
|
881
|
+
if (registration &&
|
|
882
|
+
child instanceof registration.element &&
|
|
883
|
+
!(version > registration.manifest.version)) {
|
|
884
|
+
found.push({ element: child, manifest: registration.manifest });
|
|
885
|
+
}
|
|
886
|
+
else {
|
|
887
|
+
child.replaceWith(notice());
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
// Attempt changes
|
|
892
|
+
#onChange(change) {
|
|
893
|
+
switch (change.type) {
|
|
894
|
+
case 'state':
|
|
895
|
+
this.#setState(change.state);
|
|
896
|
+
for (const { element } of this.#mounted)
|
|
897
|
+
element.disabled = this.#controller?.readOnly ?? true;
|
|
898
|
+
this.#syncClock();
|
|
899
|
+
break;
|
|
900
|
+
case 'answers':
|
|
901
|
+
this.#scheduleSnapshot();
|
|
902
|
+
break;
|
|
903
|
+
case 'page':
|
|
904
|
+
this.#showPage(change.index, true, change.previous);
|
|
905
|
+
this.#dispatch(PlayerEvent.page, {
|
|
906
|
+
index: change.index,
|
|
907
|
+
count: this.#pages.length,
|
|
908
|
+
id: this.#controller?.pages[change.index]?.id ?? '',
|
|
909
|
+
});
|
|
910
|
+
this.#scheduleSnapshot();
|
|
911
|
+
break;
|
|
912
|
+
case 'result':
|
|
913
|
+
this.#applyResult();
|
|
914
|
+
this.#dispatch(PlayerEvent.result, change.response);
|
|
915
|
+
this.#scheduleSnapshot();
|
|
916
|
+
break;
|
|
917
|
+
case 'element':
|
|
918
|
+
this.#applyResult(change.id, change.response);
|
|
919
|
+
this.#scheduleSnapshot();
|
|
920
|
+
break;
|
|
921
|
+
case 'reset':
|
|
922
|
+
for (const { element } of this.#mounted) {
|
|
923
|
+
element.setAnswers(Object.fromEntries(element.slotIds.map((id) => [id, ''])));
|
|
924
|
+
element.feedback = null;
|
|
925
|
+
element.solution = null;
|
|
926
|
+
}
|
|
927
|
+
this.#removeStored();
|
|
928
|
+
this.#showPage(0, true);
|
|
929
|
+
this.#scheduleSnapshot();
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
this.requestUpdate();
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Pushes verdicts, the help texts the response brings and solutions after a revealing submit to the elements, then
|
|
936
|
+
* announces the summary. With `only`, the response of a check of that one element: its verdicts, no summary.
|
|
937
|
+
*/
|
|
938
|
+
#applyResult(only, checked) {
|
|
939
|
+
const controller = this.#controller;
|
|
940
|
+
if (controller === null)
|
|
941
|
+
return;
|
|
942
|
+
const response = checked ?? controller.response;
|
|
943
|
+
const result = response?.result ?? null;
|
|
944
|
+
const solution = controller.solution;
|
|
945
|
+
const groups = new Map(result?.groups.map((g) => [g.id, g.verdict]) ?? []);
|
|
946
|
+
for (const { element } of this.#mounted) {
|
|
947
|
+
if (only !== undefined && element.id !== only)
|
|
948
|
+
continue;
|
|
949
|
+
if (result === null) {
|
|
950
|
+
element.feedback = null;
|
|
951
|
+
}
|
|
952
|
+
else {
|
|
953
|
+
const slots = {};
|
|
954
|
+
for (const id of element.slotIds) {
|
|
955
|
+
const verdict = result.slots[id];
|
|
956
|
+
if (verdict !== undefined)
|
|
957
|
+
slots[id] = verdict;
|
|
958
|
+
}
|
|
959
|
+
const group = groups.get(element.id) ?? null;
|
|
960
|
+
// An element graded in parts gets the verdicts of the groups it names.
|
|
961
|
+
const named = element.groupIds?.flatMap((id) => {
|
|
962
|
+
const verdict = groups.get(id);
|
|
963
|
+
return verdict === undefined ? [] : [[id, verdict]];
|
|
964
|
+
});
|
|
965
|
+
const help = {
|
|
966
|
+
message: response?.feedback?.[element.id] ?? null,
|
|
967
|
+
explanation: response?.explanations?.[element.id] ?? null,
|
|
968
|
+
};
|
|
969
|
+
element.feedback =
|
|
970
|
+
named === undefined
|
|
971
|
+
? { slots, group, ...help }
|
|
972
|
+
: { slots, group, groups: Object.fromEntries(named), ...help };
|
|
973
|
+
}
|
|
974
|
+
if (only !== undefined)
|
|
975
|
+
continue;
|
|
976
|
+
element.solution = solution === null ? null : pick(solution, element.slotIds);
|
|
977
|
+
element.disabled = controller.readOnly;
|
|
978
|
+
}
|
|
979
|
+
const text = only === undefined
|
|
980
|
+
? this.#resultAnnouncement(this.#i18n().translator(this.#uiLocale(), PLAYER_NAMESPACE))
|
|
981
|
+
: null;
|
|
982
|
+
if (text !== null)
|
|
983
|
+
this.#announce(text);
|
|
984
|
+
}
|
|
985
|
+
/** Shows page `index`, in a spread with its neighbour; `from`, the page before, turns the spread when it changes. */
|
|
986
|
+
#showPage(index, focus, from) {
|
|
987
|
+
const [first, last] = this.#shown(index);
|
|
988
|
+
this.#pages.forEach((page, i) => {
|
|
989
|
+
if (page.localName === 'astl-page')
|
|
990
|
+
page.hidden = i < first || i > last;
|
|
991
|
+
});
|
|
992
|
+
if (from !== undefined && this.#spread && this.#shown(from)[0] !== first) {
|
|
993
|
+
this.#book?.turn(this.#pages.slice(first, last + 1), from < index ? 1 : -1, this.#doc?.dir === 'rtl');
|
|
994
|
+
}
|
|
995
|
+
if (focus)
|
|
996
|
+
(this.#headings[index] ?? this.#query('.canvas'))?.focus();
|
|
997
|
+
}
|
|
998
|
+
/** First and last page shown with page `index`: its spread in a spread (the last one may hold one page), else it. */
|
|
999
|
+
#shown(index) {
|
|
1000
|
+
if (!this.#spread)
|
|
1001
|
+
return [index, index];
|
|
1002
|
+
const first = index - (index % 2);
|
|
1003
|
+
return [first, Math.min(first + 1, this.#pages.length - 1)];
|
|
1004
|
+
}
|
|
1005
|
+
/** The page "Dalej" (1) or "Wstecz" (-1) goes to: the first page of the next or previous spread in a spread. */
|
|
1006
|
+
#step(direction) {
|
|
1007
|
+
const page = this.#controller?.page ?? 0;
|
|
1008
|
+
return this.#spread ? this.#shown(page)[0] + 2 * direction : page + direction;
|
|
1009
|
+
}
|
|
1010
|
+
/** The book's module says whether the player is wide enough for a spread: switching keeps the page, without focus. */
|
|
1011
|
+
#setSpread(spread) {
|
|
1012
|
+
if (spread === this.#spread)
|
|
1013
|
+
return;
|
|
1014
|
+
this.#spread = spread;
|
|
1015
|
+
this.#showPage(this.#controller?.page ?? 0, false);
|
|
1016
|
+
this.requestUpdate();
|
|
1017
|
+
}
|
|
1018
|
+
#setState(state) {
|
|
1019
|
+
const previous = this.#state;
|
|
1020
|
+
if (state === previous)
|
|
1021
|
+
return;
|
|
1022
|
+
this.#state = state;
|
|
1023
|
+
this.#dispatch(PlayerEvent.state, { state, previous });
|
|
1024
|
+
this.requestUpdate();
|
|
1025
|
+
}
|
|
1026
|
+
#fail(code, details = null) {
|
|
1027
|
+
this.#loadError = code;
|
|
1028
|
+
this.#loadDetails = details;
|
|
1029
|
+
this.#setState('error');
|
|
1030
|
+
const message = this.#errorMessage(this.#i18n().translator(this.#uiLocale(), PLAYER_NAMESPACE), code);
|
|
1031
|
+
this.#announce(message);
|
|
1032
|
+
this.#dispatch(PlayerEvent.error, { code, message });
|
|
1033
|
+
return new LoadError(code);
|
|
1034
|
+
}
|
|
1035
|
+
#showProblem(code) {
|
|
1036
|
+
this.#problem = code;
|
|
1037
|
+
const message = this.#errorMessage(this.#i18n().translator(this.#uiLocale(), PLAYER_NAMESPACE), code);
|
|
1038
|
+
this.#announce(message);
|
|
1039
|
+
this.#dispatch(PlayerEvent.error, { code, message });
|
|
1040
|
+
this.requestUpdate();
|
|
1041
|
+
}
|
|
1042
|
+
// Snapshots and storage
|
|
1043
|
+
#uiState() {
|
|
1044
|
+
const ui = {};
|
|
1045
|
+
for (const { element } of this.#mounted) {
|
|
1046
|
+
const state = element.getUiState?.();
|
|
1047
|
+
if (state !== undefined)
|
|
1048
|
+
ui[element.id] = state;
|
|
1049
|
+
}
|
|
1050
|
+
return ui;
|
|
1051
|
+
}
|
|
1052
|
+
#scheduleSnapshot() {
|
|
1053
|
+
clearTimeout(this.#snapshotTimer);
|
|
1054
|
+
this.#snapshotTimer = setTimeout(() => this.#emitSnapshot(), SNAPSHOT_DELAY_MS);
|
|
1055
|
+
}
|
|
1056
|
+
#flushSnapshot() {
|
|
1057
|
+
if (this.#snapshotTimer === undefined)
|
|
1058
|
+
return;
|
|
1059
|
+
clearTimeout(this.#snapshotTimer);
|
|
1060
|
+
this.#emitSnapshot();
|
|
1061
|
+
}
|
|
1062
|
+
#emitSnapshot() {
|
|
1063
|
+
this.#snapshotTimer = undefined;
|
|
1064
|
+
const snapshot = this.getSnapshot();
|
|
1065
|
+
if (snapshot === null)
|
|
1066
|
+
return;
|
|
1067
|
+
this.#store(snapshot);
|
|
1068
|
+
this.#dispatch(PlayerEvent.snapshot, snapshot);
|
|
1069
|
+
}
|
|
1070
|
+
#storageKey(viewHash) {
|
|
1071
|
+
return this.persist && viewHash !== null ? `${STORAGE_PREFIX}${viewHash}` : null;
|
|
1072
|
+
}
|
|
1073
|
+
// Storage can be missing or blocked (private mode, sandboxed frames): persistence is best effort.
|
|
1074
|
+
#storedSnapshot(viewHash) {
|
|
1075
|
+
const key = this.#storageKey(viewHash);
|
|
1076
|
+
if (key === null)
|
|
1077
|
+
return null;
|
|
1078
|
+
try {
|
|
1079
|
+
const raw = localStorage.getItem(key);
|
|
1080
|
+
const value = raw === null ? null : JSON.parse(raw);
|
|
1081
|
+
return isSnapshot(value) && value.viewHash === viewHash ? value : null;
|
|
1082
|
+
}
|
|
1083
|
+
catch {
|
|
1084
|
+
return null;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
#store(snapshot) {
|
|
1088
|
+
const key = this.#storageKey(snapshot.viewHash);
|
|
1089
|
+
if (key === null)
|
|
1090
|
+
return;
|
|
1091
|
+
// Nothing worth restoring: keep storage clean (also what reset leaves behind).
|
|
1092
|
+
const empty = Object.keys(snapshot.answers).length === 0 && snapshot.page === 0 && !snapshot.submitted;
|
|
1093
|
+
try {
|
|
1094
|
+
if (empty)
|
|
1095
|
+
localStorage.removeItem(key);
|
|
1096
|
+
else
|
|
1097
|
+
localStorage.setItem(key, JSON.stringify(snapshot));
|
|
1098
|
+
}
|
|
1099
|
+
catch {
|
|
1100
|
+
// Best effort.
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
#removeStored() {
|
|
1104
|
+
const key = this.#storageKey(this.#viewHash);
|
|
1105
|
+
if (key === null)
|
|
1106
|
+
return;
|
|
1107
|
+
try {
|
|
1108
|
+
localStorage.removeItem(key);
|
|
1109
|
+
}
|
|
1110
|
+
catch {
|
|
1111
|
+
// Best effort.
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
// Deadline
|
|
1115
|
+
#syncClock() {
|
|
1116
|
+
const state = this.#state;
|
|
1117
|
+
const running = this.isConnected &&
|
|
1118
|
+
this.#controller?.policy.deadline != null &&
|
|
1119
|
+
(state === 'ready' || state === 'active' || state === 'checking');
|
|
1120
|
+
if (running && this.#clock === undefined)
|
|
1121
|
+
this.#clock = setInterval(() => this.#tick(), 1000);
|
|
1122
|
+
if (!running && this.#clock !== undefined) {
|
|
1123
|
+
clearInterval(this.#clock);
|
|
1124
|
+
this.#clock = undefined;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
#tick() {
|
|
1128
|
+
const controller = this.#controller;
|
|
1129
|
+
const left = controller?.timeLeft() ?? null;
|
|
1130
|
+
if (controller === null || left === null)
|
|
1131
|
+
return;
|
|
1132
|
+
const t = this.#i18n().translator(this.#uiLocale(), PLAYER_NAMESPACE);
|
|
1133
|
+
const due = TIMER_ALERTS.filter((minutes) => left <= minutes * 60_000);
|
|
1134
|
+
if (left > 0 && due.length > 0 && !this.#alerted.has(Math.min(...due))) {
|
|
1135
|
+
for (const minutes of due)
|
|
1136
|
+
this.#alerted.add(minutes);
|
|
1137
|
+
this.#announce(t('timer.minutes', { minutes: Math.ceil(left / 60_000) }));
|
|
1138
|
+
}
|
|
1139
|
+
if (left === 0 && !this.#autoSubmitted && controller.canSubmit()) {
|
|
1140
|
+
this.#autoSubmitted = true;
|
|
1141
|
+
this.#announce(t('timer.expired'));
|
|
1142
|
+
void this.submit();
|
|
1143
|
+
}
|
|
1144
|
+
this.requestUpdate();
|
|
1145
|
+
}
|
|
1146
|
+
// Helpers
|
|
1147
|
+
#effectiveChecker() {
|
|
1148
|
+
if (this.#sourceChecker !== null)
|
|
1149
|
+
return this.#sourceChecker;
|
|
1150
|
+
if (this.checker !== null)
|
|
1151
|
+
return this.checker;
|
|
1152
|
+
if (this.endpoint) {
|
|
1153
|
+
if (this.#endpointChecker?.endpoint !== this.endpoint) {
|
|
1154
|
+
this.#endpointChecker = {
|
|
1155
|
+
endpoint: this.endpoint,
|
|
1156
|
+
checker: httpChecker({ endpoint: this.endpoint }),
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
return this.#endpointChecker.checker;
|
|
1160
|
+
}
|
|
1161
|
+
return null;
|
|
1162
|
+
}
|
|
1163
|
+
#requireChecker() {
|
|
1164
|
+
const checker = this.#effectiveChecker();
|
|
1165
|
+
if (checker === null)
|
|
1166
|
+
throw new LoadError('no_checker');
|
|
1167
|
+
return checker;
|
|
1168
|
+
}
|
|
1169
|
+
/** Units left empty before a hand-in; answers of ungraded components (open answers) are optional. */
|
|
1170
|
+
#emptyCount() {
|
|
1171
|
+
let empty = 0;
|
|
1172
|
+
for (const { element, manifest } of this.#mounted) {
|
|
1173
|
+
if (!manifest.graded)
|
|
1174
|
+
continue;
|
|
1175
|
+
const units = element.units();
|
|
1176
|
+
empty += Math.max(0, units.total - units.answered);
|
|
1177
|
+
}
|
|
1178
|
+
return empty;
|
|
1179
|
+
}
|
|
1180
|
+
#pageState(index) {
|
|
1181
|
+
let answered = 0;
|
|
1182
|
+
let total = 0;
|
|
1183
|
+
for (const { element, page } of this.#mounted) {
|
|
1184
|
+
if (page !== index)
|
|
1185
|
+
continue;
|
|
1186
|
+
const units = element.units();
|
|
1187
|
+
answered += units.answered;
|
|
1188
|
+
total += units.total;
|
|
1189
|
+
}
|
|
1190
|
+
if (answered >= total)
|
|
1191
|
+
return 'done';
|
|
1192
|
+
return answered === 0 ? 'none' : 'partial';
|
|
1193
|
+
}
|
|
1194
|
+
#i18n() {
|
|
1195
|
+
if (this.#i18nCache?.version !== runtime.version) {
|
|
1196
|
+
const catalogs = [
|
|
1197
|
+
...playerMessages,
|
|
1198
|
+
...[...runtime.elements.values()].flatMap((r) => r.messages),
|
|
1199
|
+
...runtime.catalogs,
|
|
1200
|
+
];
|
|
1201
|
+
this.#i18nCache = { version: runtime.version, i18n: createI18n({ catalogs }) };
|
|
1202
|
+
}
|
|
1203
|
+
return this.#i18nCache.i18n;
|
|
1204
|
+
}
|
|
1205
|
+
#uiLocale() {
|
|
1206
|
+
const requested = this.locale
|
|
1207
|
+
? [this.locale]
|
|
1208
|
+
: this.lang
|
|
1209
|
+
? [this.lang]
|
|
1210
|
+
: [...(navigator.languages ?? []), navigator.language].filter((l) => !!l);
|
|
1211
|
+
return negotiateLocale(requested, this.#i18n().locales(PLAYER_NAMESPACE), 'en');
|
|
1212
|
+
}
|
|
1213
|
+
#theme() {
|
|
1214
|
+
const theme = this.theme;
|
|
1215
|
+
return theme !== null && THEMES.includes(theme) ? theme : 'auto';
|
|
1216
|
+
}
|
|
1217
|
+
#announce(message) {
|
|
1218
|
+
const region = this.#query('.live');
|
|
1219
|
+
if (region !== null)
|
|
1220
|
+
announce(region, message);
|
|
1221
|
+
}
|
|
1222
|
+
#query(selector) {
|
|
1223
|
+
return this.renderRoot?.querySelector(selector) ?? null;
|
|
1224
|
+
}
|
|
1225
|
+
#dispatch(type, detail) {
|
|
1226
|
+
this.dispatchEvent(new CustomEvent(type, { detail, bubbles: true, composed: true }));
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
//# sourceMappingURL=player.js.map
|