@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,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"loading": "Wczytywanie zadania…",
|
|
3
|
+
"page.heading": "Strona {n}",
|
|
4
|
+
"page.counter": "Strona {n} z {total}",
|
|
5
|
+
"page.counter.spread": "Strony {from}-{to} z {total}",
|
|
6
|
+
"progress.label": "Strony",
|
|
7
|
+
"progress.item": "Strona {n}, {state, select, done {wszystko uzupełnione} partial {częściowo uzupełniona} other {bez odpowiedzi}}",
|
|
8
|
+
"nav.previous": "Wstecz",
|
|
9
|
+
"nav.next": "Dalej",
|
|
10
|
+
"action.check": "Sprawdź",
|
|
11
|
+
"action.reset": "Zacznij od nowa",
|
|
12
|
+
"action.submit": "Oddaj",
|
|
13
|
+
"confirm.empty": "{count, plural, one {Masz # pustą odpowiedź.} few {Masz # puste odpowiedzi.} many {Masz # pustych odpowiedzi.} other {Masz # pustej odpowiedzi.}} Oddać mimo to?",
|
|
14
|
+
"confirm.submit": "Oddaj mimo to",
|
|
15
|
+
"confirm.cancel": "Wróć do odpowiedzi",
|
|
16
|
+
"checks.left": "{count, plural, =0 {Nie masz już sprawdzeń} one {Zostało # sprawdzenie} few {Zostały # sprawdzenia} many {Zostało # sprawdzeń} other {Zostało # sprawdzenia}}",
|
|
17
|
+
"result.title": "Wynik",
|
|
18
|
+
"result.score": "{score} z {max, plural, one {# punktu} few {# punktów} many {# punktów} other {# punktu}}",
|
|
19
|
+
"result.count": "{verdict}: {count}",
|
|
20
|
+
"result.passed": "Zaliczone",
|
|
21
|
+
"result.notPassed": "Jeszcze nie zaliczone",
|
|
22
|
+
"result.submitted": "Twoje odpowiedzi zostały oddane.",
|
|
23
|
+
"result.later": "Wyniki zobaczysz później.",
|
|
24
|
+
"result.teacher.sent": "Twoje odpowiedzi trafiły do nauczyciela.",
|
|
25
|
+
"result.teacher.count": "{count, plural, =0 {Żadna odpowiedź nie trafia do nauczyciela do oceny.} one {# odpowiedź trafia do nauczyciela do oceny.} few {# odpowiedzi trafiają do nauczyciela do oceny.} many {# odpowiedzi trafia do nauczyciela do oceny.} other {# odpowiedzi trafia do nauczyciela do oceny.}}",
|
|
26
|
+
"result.teacher.unchecked": "Odpowiedzi dla nauczyciela nie są tu sprawdzane.",
|
|
27
|
+
"result.practice": "Tylko do ćwiczeń: nic tu nie jest oceniane.",
|
|
28
|
+
"result.announce": "Wynik: {score}.",
|
|
29
|
+
"result.countAnnounce": "{verdict}: {count}.",
|
|
30
|
+
"verdict.correct": "Dobrze",
|
|
31
|
+
"verdict.partial": "Częściowo dobrze",
|
|
32
|
+
"verdict.incorrect": "Jeszcze nie",
|
|
33
|
+
"verdict.empty": "Brak odpowiedzi",
|
|
34
|
+
"timer.label": "Pozostały czas",
|
|
35
|
+
"timer.minutes": "{minutes, plural, one {Została # minuta} few {Zostały # minuty} many {Zostało # minut} other {Zostało # minuty}}",
|
|
36
|
+
"timer.expired": "Czas minął. Oddajemy twoje odpowiedzi.",
|
|
37
|
+
"unsupported": "Ta część zadania nie działa w tym odtwarzaczu.",
|
|
38
|
+
"error.invalid_request": "Nie udało się wysłać odpowiedzi. Spróbuj jeszcze raz.",
|
|
39
|
+
"error.unauthorized": "Nie udało się potwierdzić, kim jesteś. Zaloguj się i spróbuj jeszcze raz.",
|
|
40
|
+
"error.check_not_allowed": "W tym zadaniu nie można sprawdzać odpowiedzi.",
|
|
41
|
+
"error.checks_exhausted": "Nie masz już sprawdzeń.",
|
|
42
|
+
"error.not_found": "Nie znaleziono tego zadania.",
|
|
43
|
+
"error.method_not_allowed": "Serwer zadania odrzucił prośbę.",
|
|
44
|
+
"error.attempt_closed": "Te odpowiedzi zostały już oddane.",
|
|
45
|
+
"error.payload_too_large": "Odpowiedzi są za długie, żeby je wysłać.",
|
|
46
|
+
"error.internal_error": "Nie udało się połączyć z serwerem zadania. Spróbuj za chwilę.",
|
|
47
|
+
"error.no_checker": "Tego zadania nie można tu sprawdzić.",
|
|
48
|
+
"error.load_failed": "Nie udało się wczytać zadania.",
|
|
49
|
+
"error.view_invalid": "Plik zadania jest uszkodzony.",
|
|
50
|
+
"error.integrity_mismatch": "Plik zadania nie przeszedł weryfikacji, więc nie został otwarty.",
|
|
51
|
+
"error.source_needs_compiler": "To zadanie wymaga pełnej wersji skryptu Astrolabe.",
|
|
52
|
+
"error.source_invalid": "To zadanie nie jest poprawnie zapisane, więc nie da się go wyświetlić."
|
|
53
|
+
}
|
package/src/messages.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { I18n, MessageCatalog, Translate } from '@astl/core';
|
|
2
|
+
import en from './messages/en.json' with { type: 'json' };
|
|
3
|
+
import pl from './messages/pl.json' with { type: 'json' };
|
|
4
|
+
|
|
5
|
+
/** i18n namespace of the player chrome and of strings shared by all elements (verdict words). */
|
|
6
|
+
export const PLAYER_NAMESPACE = 'astl.player';
|
|
7
|
+
|
|
8
|
+
export const playerMessages: readonly MessageCatalog[] = [
|
|
9
|
+
{ namespace: PLAYER_NAMESPACE, locale: 'en', messages: en },
|
|
10
|
+
{ namespace: PLAYER_NAMESPACE, locale: 'pl', messages: pl },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/** Looks a key up in `namespace` first, then in the shared player namespace, else returns the key. */
|
|
14
|
+
export function elementTranslator(i18n: I18n, locale: string, namespace: string): Translate {
|
|
15
|
+
return (key, params) => {
|
|
16
|
+
const own = i18n.t(locale, namespace, key, params);
|
|
17
|
+
return own !== key || namespace === PLAYER_NAMESPACE
|
|
18
|
+
? own
|
|
19
|
+
: i18n.t(locale, PLAYER_NAMESPACE, key, params);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A book (`kind="book"`) in the player, in a module of its own: a view that is no book never loads it. It says when the
|
|
3
|
+
* player is wide enough for a spread, two pages side by side, draws the spread and slides the pages of a new one in.
|
|
4
|
+
* Without it (or when its chunk fails) a book plays one page at a time, as an exercise.
|
|
5
|
+
*/
|
|
6
|
+
import { css } from 'lit';
|
|
7
|
+
|
|
8
|
+
/** Narrowest player (rem) that shows a book a spread at a time; narrower, one page at a time. */
|
|
9
|
+
const SPREAD_MIN_REM = 56;
|
|
10
|
+
/** A spread's turn: its pages come in from the side of travel. */
|
|
11
|
+
const TURN_MS = 240;
|
|
12
|
+
const TURN_DISTANCE_REM = 1.5;
|
|
13
|
+
|
|
14
|
+
/** A spread: two pages side by side (the first on the start side), a line between them as the spine. */
|
|
15
|
+
const bookSheet = css`
|
|
16
|
+
.root[data-spread] > * {
|
|
17
|
+
max-inline-size: 1240px;
|
|
18
|
+
}
|
|
19
|
+
.root[data-spread] astl-doc {
|
|
20
|
+
display: grid;
|
|
21
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
22
|
+
column-gap: var(--astl-space-5);
|
|
23
|
+
}
|
|
24
|
+
.root[data-spread] astl-doc > astl-page:not([hidden]) + astl-page:not([hidden]) {
|
|
25
|
+
border-inline-start: var(--astl-outline-width) solid var(--astl-line);
|
|
26
|
+
padding-inline-start: var(--astl-space-5);
|
|
27
|
+
}
|
|
28
|
+
`.styleSheet;
|
|
29
|
+
|
|
30
|
+
/** Adopts the stylesheet of spreads in a player's root, once. */
|
|
31
|
+
export function adoptBookSheet(root: Node): void {
|
|
32
|
+
if (bookSheet !== undefined && root instanceof ShadowRoot && !root.adoptedStyleSheets.includes(bookSheet)) {
|
|
33
|
+
root.adoptedStyleSheets = [...root.adoptedStyleSheets, bookSheet];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Tells `spread` whether `host` is wide enough for a spread (in the root font size), now and on every resize. The
|
|
39
|
+
* observer is the caller's to disconnect, and to observe `host` again when it is connected again.
|
|
40
|
+
*/
|
|
41
|
+
export function watchSpread(host: HTMLElement, spread: (wide: boolean) => void): ResizeObserver {
|
|
42
|
+
const measure = (width: number) => {
|
|
43
|
+
const rem = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
44
|
+
spread(width >= SPREAD_MIN_REM * rem);
|
|
45
|
+
};
|
|
46
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
47
|
+
if (entry !== undefined) measure(entry.contentRect.width);
|
|
48
|
+
});
|
|
49
|
+
observer.observe(host);
|
|
50
|
+
measure(host.clientWidth);
|
|
51
|
+
return observer;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The pages of a new spread come in from the side of travel (`direction` 1 forwards, mirrored right to left); they just
|
|
56
|
+
* appear with reduced motion or forced colours.
|
|
57
|
+
*/
|
|
58
|
+
export function turn(pages: readonly HTMLElement[], direction: 1 | -1, rtl: boolean): void {
|
|
59
|
+
if (matchMedia('(prefers-reduced-motion: reduce), (forced-colors: active)').matches) return;
|
|
60
|
+
const offset = `translateX(${(rtl ? -direction : direction) * TURN_DISTANCE_REM}rem)`;
|
|
61
|
+
for (const page of pages) {
|
|
62
|
+
page.animate(
|
|
63
|
+
[
|
|
64
|
+
{ opacity: 0, transform: offset },
|
|
65
|
+
{ opacity: 1, transform: 'none' },
|
|
66
|
+
],
|
|
67
|
+
{ duration: TURN_MS, easing: 'ease-out' },
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|