@astl/player 0.0.0-stage → 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.
Files changed (107) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE +202 -0
  3. package/README.md +36 -2
  4. package/dist/a11y.d.ts +41 -0
  5. package/dist/a11y.d.ts.map +1 -0
  6. package/dist/a11y.js +101 -0
  7. package/dist/a11y.js.map +1 -0
  8. package/dist/attempt/controller.d.ts +104 -0
  9. package/dist/attempt/controller.d.ts.map +1 -0
  10. package/dist/attempt/controller.js +325 -0
  11. package/dist/attempt/controller.js.map +1 -0
  12. package/dist/checker/http.d.ts +17 -0
  13. package/dist/checker/http.d.ts.map +1 -0
  14. package/dist/checker/http.js +115 -0
  15. package/dist/checker/http.js.map +1 -0
  16. package/dist/define.d.ts +35 -0
  17. package/dist/define.d.ts.map +1 -0
  18. package/dist/define.js +84 -0
  19. package/dist/define.js.map +1 -0
  20. package/dist/element/base.d.ts +83 -0
  21. package/dist/element/base.d.ts.map +1 -0
  22. package/dist/element/base.js +239 -0
  23. package/dist/element/base.js.map +1 -0
  24. package/dist/index.d.ts +14 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +8 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/interaction/index.d.ts +12 -0
  29. package/dist/interaction/index.d.ts.map +1 -0
  30. package/dist/interaction/index.js +4 -0
  31. package/dist/interaction/index.js.map +1 -0
  32. package/dist/interaction/keys.d.ts +11 -0
  33. package/dist/interaction/keys.d.ts.map +1 -0
  34. package/dist/interaction/keys.js +13 -0
  35. package/dist/interaction/keys.js.map +1 -0
  36. package/dist/interaction/pick-and-place.d.ts +120 -0
  37. package/dist/interaction/pick-and-place.d.ts.map +1 -0
  38. package/dist/interaction/pick-and-place.js +395 -0
  39. package/dist/interaction/pick-and-place.js.map +1 -0
  40. package/dist/interaction/roving-focus.d.ts +44 -0
  41. package/dist/interaction/roving-focus.d.ts.map +1 -0
  42. package/dist/interaction/roving-focus.js +115 -0
  43. package/dist/interaction/roving-focus.js.map +1 -0
  44. package/dist/messages/en.json +53 -0
  45. package/dist/messages/help/en.json +14 -0
  46. package/dist/messages/help/pl.json +14 -0
  47. package/dist/messages/pl.json +53 -0
  48. package/dist/messages.d.ts +7 -0
  49. package/dist/messages.d.ts.map +1 -0
  50. package/dist/messages.js +18 -0
  51. package/dist/messages.js.map +1 -0
  52. package/dist/player/book.d.ts +13 -0
  53. package/dist/player/book.d.ts.map +1 -0
  54. package/dist/player/book.js +65 -0
  55. package/dist/player/book.js.map +1 -0
  56. package/dist/player/help.d.ts +55 -0
  57. package/dist/player/help.d.ts.map +1 -0
  58. package/dist/player/help.js +484 -0
  59. package/dist/player/help.js.map +1 -0
  60. package/dist/player/player.d.ts +87 -0
  61. package/dist/player/player.d.ts.map +1 -0
  62. package/dist/player/player.js +1229 -0
  63. package/dist/player/player.js.map +1 -0
  64. package/dist/player/styled.d.ts +10 -0
  65. package/dist/player/styled.d.ts.map +1 -0
  66. package/dist/player/styled.js +213 -0
  67. package/dist/player/styled.js.map +1 -0
  68. package/dist/player/styles.d.ts +3 -0
  69. package/dist/player/styles.d.ts.map +1 -0
  70. package/dist/player/styles.js +355 -0
  71. package/dist/player/styles.js.map +1 -0
  72. package/dist/player/templates.d.ts +25 -0
  73. package/dist/player/templates.d.ts.map +1 -0
  74. package/dist/player/templates.js +101 -0
  75. package/dist/player/templates.js.map +1 -0
  76. package/dist/player/view.d.ts +44 -0
  77. package/dist/player/view.d.ts.map +1 -0
  78. package/dist/player/view.js +231 -0
  79. package/dist/player/view.js.map +1 -0
  80. package/dist/runtime.d.ts +45 -0
  81. package/dist/runtime.d.ts.map +1 -0
  82. package/dist/runtime.js +48 -0
  83. package/dist/runtime.js.map +1 -0
  84. package/package.json +45 -3
  85. package/src/a11y.ts +134 -0
  86. package/src/attempt/controller.ts +381 -0
  87. package/src/checker/http.ts +149 -0
  88. package/src/define.ts +114 -0
  89. package/src/element/base.ts +310 -0
  90. package/src/index.ts +18 -0
  91. package/src/interaction/index.ts +11 -0
  92. package/src/interaction/keys.ts +16 -0
  93. package/src/interaction/pick-and-place.ts +464 -0
  94. package/src/interaction/roving-focus.ts +133 -0
  95. package/src/messages/en.json +53 -0
  96. package/src/messages/help/en.json +14 -0
  97. package/src/messages/help/pl.json +14 -0
  98. package/src/messages/pl.json +53 -0
  99. package/src/messages.ts +21 -0
  100. package/src/player/book.ts +70 -0
  101. package/src/player/help.ts +585 -0
  102. package/src/player/player.ts +1368 -0
  103. package/src/player/styled.ts +247 -0
  104. package/src/player/styles.ts +355 -0
  105. package/src/player/templates.ts +142 -0
  106. package/src/player/view.ts +294 -0
  107. package/src/runtime.ts +95 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Base classes for component elements. They implement the parts of PlayerElementApi every element shares, so an
3
+ * component author writes rendering and answer mapping only. Elements also work outside a player: until
4
+ * `attach()` is called they use an English context built from their own catalogs.
5
+ */
6
+ import { type Answers, type AttributeSpec, type ComponentManifest, type Direction, type ElementContext, type ElementFeedback, type GroupVerdict, type MessageCatalog, type MessageParams, type PlayerElementApi, type SlotId, type SlotVerdict, type Solution, type Units } from '@astl/core';
7
+ import { LitElement, nothing, type PropertyDeclarations, type TemplateResult } from 'lit';
8
+ import { type VerdictOptions } from '../a11y.js';
9
+ /** Deterministic Fisher-Yates shuffle: the same seed always gives the same order. */
10
+ export declare function seededShuffle<T>(items: readonly T[], seed: string): T[];
11
+ export declare abstract class AstlElement extends LitElement implements PlayerElementApi {
12
+ #private;
13
+ /** The element type's manifest: drives the typed attribute getters and the default message namespace. */
14
+ static manifest: ComponentManifest | null;
15
+ /** Catalogs of the manifest's namespace, used until a player attaches its own context. */
16
+ static messages: readonly MessageCatalog[];
17
+ static properties: PropertyDeclarations;
18
+ /** Verdicts to show; null clears them. Editing a slot clears its own verdict and the group verdict. */
19
+ feedback: ElementFeedback | null;
20
+ /** Correct answers to show next to the student's; null hides them. */
21
+ solution: Solution | null;
22
+ disabled: boolean;
23
+ constructor();
24
+ /**
25
+ * Source content in a player's light DOM (HTML with answers) is input for the compiler and never shown: such
26
+ * elements stay inert, with no shadow root and no render. The player mounts its own copy of the compiled view.
27
+ */
28
+ connectedCallback(): void;
29
+ abstract get slotIds(): readonly SlotId[];
30
+ abstract getAnswers(): Answers;
31
+ abstract setAnswers(answers: Answers): void;
32
+ abstract units(): Units;
33
+ /** The player's context, or the default English one. */
34
+ get context(): ElementContext;
35
+ attach(context: ElementContext): void;
36
+ /** A message in the UI locale: the element's namespace first, then the shared `astl.player` one. */
37
+ protected t(key: string, params?: MessageParams): string;
38
+ protected announce(message: string): void;
39
+ /** UI language and direction (the context locale), for UI strings rendered inside content. */
40
+ protected get uiLanguage(): {
41
+ readonly lang: string;
42
+ readonly dir: Direction;
43
+ };
44
+ /** Content language at this element (closest `lang`), for inputs and spell checking. */
45
+ protected get contentLang(): string;
46
+ /** Reports changed slots (`''` = cleared) to the player and clears their verdicts. */
47
+ protected emitChange(answers: Answers): void;
48
+ protected slotVerdict(id: SlotId): SlotVerdict | null;
49
+ protected get groupVerdict(): GroupVerdict | null;
50
+ /** A verdict's icon and word (`renderVerdict`) in the UI language, as part `verdict`; nothing without a verdict. */
51
+ protected renderVerdict(verdict: GroupVerdict | null, options?: VerdictOptions): TemplateResult | typeof nothing;
52
+ /** The group verdict line of a block (`p.group-verdict`, part `verdict`); nothing without a verdict. */
53
+ protected renderGroupVerdict(verdict?: GroupVerdict | null): TemplateResult | typeof nothing;
54
+ /** The light-DOM children with this tag and an id, in view order. */
55
+ protected childElements(tag: string): HTMLElement[];
56
+ /** `items` in view order, or shuffled per attempt when the context has a seed (stable per seed and id). */
57
+ protected shuffled<T>(items: readonly T[]): readonly T[];
58
+ protected attributeSpec(name: string): AttributeSpec | undefined;
59
+ /** A string, id or enum attribute; enum values outside the manifest's list give the default. */
60
+ protected stringAttribute(name: string): string | null;
61
+ /** An integer or number attribute within the manifest's bounds, else the default (or null). */
62
+ protected numberAttribute(name: string): number | null;
63
+ /** An HTML boolean attribute: present = true. */
64
+ protected booleanAttribute(name: string): boolean;
65
+ }
66
+ /** An element with exactly one slot whose id is the element id (a gap, a single choice, a slider). */
67
+ export declare abstract class SingleSlotElement extends AstlElement {
68
+ static properties: PropertyDeclarations;
69
+ /** The current answer; `''` = unanswered. */
70
+ protected value: string;
71
+ constructor();
72
+ get slotIds(): readonly SlotId[];
73
+ getAnswers(): Answers;
74
+ setAnswers(answers: Answers): void;
75
+ units(): Units;
76
+ /** Sets the answer from student input and reports it. */
77
+ protected updateValue(value: string): void;
78
+ /** The slot verdict, else the group verdict (e.g. `empty`). */
79
+ protected get verdict(): GroupVerdict | null;
80
+ /** The correct answer for this slot, when shown. */
81
+ protected get solutionValue(): string | null;
82
+ }
83
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/element/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,aAAa,EAGlB,KAAK,iBAAiB,EAEtB,KAAK,SAAS,EAEd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EAErB,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,QAAQ,EAEb,KAAK,KAAK,EACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAQ,UAAU,EAAE,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAChG,OAAO,EAA+C,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAmC9F,qFAAqF;AACrF,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,CAQvE;AAED,8BAAsB,WAAY,SAAQ,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,yDAAyD;IACzD,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAIzC;IAED,+DAA+D;IAC/D,SAAS,KAAK,OAAO,IAAI,YAAY,GAAG,IAAI,CAE3C;IAED,oDAAoD;IACpD,SAAS,KAAK,aAAa,IAAI,MAAM,GAAG,IAAI,CAE3C;CACF"}
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Base classes for component elements. They implement the parts of PlayerElementApi every element shares, so an
3
+ * component author writes rendering and answer mapping only. Elements also work outside a player: until
4
+ * `attach()` is called they use an English context built from their own catalogs.
5
+ */
6
+ import { allAttributes, createI18n, directionOf, PlayerEvent, } from '@astl/core';
7
+ import { html, LitElement, nothing } from 'lit';
8
+ import { announce, documentLiveRegion, renderVerdict } from '../a11y.js';
9
+ import { elementTranslator, PLAYER_NAMESPACE, playerMessages } from '../messages.js';
10
+ function defaultContext(type) {
11
+ const i18n = createI18n({ catalogs: [...playerMessages, ...type.messages] });
12
+ return {
13
+ locale: 'en',
14
+ t: elementTranslator(i18n, 'en', type.manifest?.messages ?? PLAYER_NAMESPACE),
15
+ announce: (message) => announce(documentLiveRegion(), message),
16
+ number: 0,
17
+ seed: null,
18
+ };
19
+ }
20
+ /** 32-bit FNV-1a hash of a string. */
21
+ function hash(value) {
22
+ let h = 0x811c9dc5;
23
+ for (let i = 0; i < value.length; i++) {
24
+ h ^= value.charCodeAt(i);
25
+ h = Math.imul(h, 0x01000193);
26
+ }
27
+ return h >>> 0;
28
+ }
29
+ /** mulberry32: a small, good-enough PRNG for UI shuffles (not for anything secret). */
30
+ function random(seed) {
31
+ let a = seed;
32
+ return () => {
33
+ a = (a + 0x6d2b79f5) | 0;
34
+ let t = Math.imul(a ^ (a >>> 15), 1 | a);
35
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
36
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
37
+ };
38
+ }
39
+ /** Deterministic Fisher-Yates shuffle: the same seed always gives the same order. */
40
+ export function seededShuffle(items, seed) {
41
+ const next = random(hash(seed));
42
+ const out = [...items];
43
+ for (let i = out.length - 1; i > 0; i--) {
44
+ const j = Math.floor(next() * (i + 1));
45
+ [out[i], out[j]] = [out[j], out[i]];
46
+ }
47
+ return out;
48
+ }
49
+ export class AstlElement extends LitElement {
50
+ /** The element type's manifest: drives the typed attribute getters and the default message namespace. */
51
+ static manifest = null;
52
+ /** Catalogs of the manifest's namespace, used until a player attaches its own context. */
53
+ static messages = [];
54
+ static properties = {
55
+ feedback: { attribute: false },
56
+ solution: { attribute: false },
57
+ disabled: { type: Boolean },
58
+ };
59
+ #context = null;
60
+ /** `t` as a value, for `renderVerdict`. */
61
+ #t = (key, params) => this.t(key, params);
62
+ constructor() {
63
+ super();
64
+ this.feedback = null;
65
+ this.solution = null;
66
+ this.disabled = false;
67
+ // A controller runs after every render, before the element's own `updated()`, which need not call super.
68
+ this.addController({ hostUpdated: () => this.#assignSlots() });
69
+ }
70
+ /**
71
+ * Source content in a player's light DOM (HTML with answers) is input for the compiler and never shown: such
72
+ * elements stay inert, with no shadow root and no render. The player mounts its own copy of the compiled view.
73
+ */
74
+ connectedCallback() {
75
+ if (this.closest('astl-player') !== null)
76
+ return;
77
+ super.connectedCallback();
78
+ }
79
+ /** The player's context, or the default English one. */
80
+ get context() {
81
+ this.#context ??= defaultContext(this.constructor);
82
+ return this.#context;
83
+ }
84
+ attach(context) {
85
+ this.#context = context;
86
+ this.requestUpdate();
87
+ }
88
+ /** A message in the UI locale: the element's namespace first, then the shared `astl.player` one. */
89
+ t(key, params) {
90
+ return this.context.t(key, params);
91
+ }
92
+ announce(message) {
93
+ this.context.announce(message);
94
+ }
95
+ /** UI language and direction (the context locale), for UI strings rendered inside content. */
96
+ get uiLanguage() {
97
+ const lang = this.context.locale;
98
+ return { lang, dir: directionOf(lang) };
99
+ }
100
+ /** Content language at this element (closest `lang`), for inputs and spell checking. */
101
+ get contentLang() {
102
+ return this.closest('[lang]')?.getAttribute('lang') ?? '';
103
+ }
104
+ /** Reports changed slots (`''` = cleared) to the player and clears their verdicts. */
105
+ emitChange(answers) {
106
+ const feedback = this.feedback;
107
+ if (feedback) {
108
+ const slots = { ...feedback.slots };
109
+ for (const id of Object.keys(answers))
110
+ delete slots[id];
111
+ this.feedback = { slots, group: null };
112
+ }
113
+ this.dispatchEvent(new CustomEvent(PlayerEvent.change, {
114
+ detail: { answers },
115
+ bubbles: true,
116
+ composed: true,
117
+ }));
118
+ }
119
+ slotVerdict(id) {
120
+ return this.feedback?.slots[id] ?? null;
121
+ }
122
+ get groupVerdict() {
123
+ return this.feedback?.group ?? null;
124
+ }
125
+ /** A verdict's icon and word (`renderVerdict`) in the UI language, as part `verdict`; nothing without a verdict. */
126
+ renderVerdict(verdict, options = {}) {
127
+ return verdict === null
128
+ ? nothing
129
+ : renderVerdict(verdict, this.#t, { part: 'verdict', ...this.uiLanguage, ...options });
130
+ }
131
+ /** The group verdict line of a block (`p.group-verdict`, part `verdict`); nothing without a verdict. */
132
+ renderGroupVerdict(verdict = this.groupVerdict) {
133
+ return verdict === null
134
+ ? nothing
135
+ : html `<p class="group-verdict" part="verdict" data-verdict=${verdict}>
136
+ ${renderVerdict(verdict, this.#t, this.uiLanguage)}
137
+ </p>`;
138
+ }
139
+ /** The light-DOM children with this tag and an id, in view order. */
140
+ childElements(tag) {
141
+ return Array.from(this.children).filter((child) => child.localName === tag && child.id !== '');
142
+ }
143
+ /**
144
+ * Manual slot assignment (a shadow root with `slotAssignment: 'manual'`): the light DOM is projected as it is, never
145
+ * moved or rewritten. `<slot data-tag="astl-prompt">` shows the first child with that tag; any other
146
+ * `<slot data-<name>="<id>">` (`data-option`, `data-card`) the child with that id (child ids are unique in an element).
147
+ */
148
+ #assignSlots() {
149
+ const root = this.shadowRoot;
150
+ if (root?.slotAssignment !== 'manual')
151
+ return;
152
+ const children = Array.from(this.children);
153
+ for (const slot of root.querySelectorAll('slot')) {
154
+ const { tag, ...named } = slot.dataset;
155
+ const [id] = Object.values(named);
156
+ const child = children.find((c) => tag === undefined ? id !== '' && c.id === id : c.localName === tag);
157
+ slot.assign(...(child === undefined ? [] : [child]));
158
+ }
159
+ }
160
+ /** `items` in view order, or shuffled per attempt when the context has a seed (stable per seed and id). */
161
+ shuffled(items) {
162
+ const seed = this.context.seed;
163
+ return seed === null ? items : seededShuffle(items, `${seed}:${this.id}`);
164
+ }
165
+ attributeSpec(name) {
166
+ const manifest = this.constructor.manifest;
167
+ return manifest ? allAttributes(manifest).find((a) => a.name === name) : undefined;
168
+ }
169
+ /** A string, id or enum attribute; enum values outside the manifest's list give the default. */
170
+ stringAttribute(name) {
171
+ const spec = this.attributeSpec(name);
172
+ const value = this.getAttribute(name);
173
+ const fallback = spec?.default === undefined ? null : String(spec.default);
174
+ if (value === null)
175
+ return fallback;
176
+ if (spec?.type === 'enum' && !(spec.values ?? []).includes(value))
177
+ return fallback;
178
+ return value;
179
+ }
180
+ /** An integer or number attribute within the manifest's bounds, else the default (or null). */
181
+ numberAttribute(name) {
182
+ const spec = this.attributeSpec(name);
183
+ const fallback = typeof spec?.default === 'number' ? spec.default : null;
184
+ const raw = this.getAttribute(name);
185
+ if (raw === null || raw.trim() === '')
186
+ return fallback;
187
+ const value = Number(raw);
188
+ if (!Number.isFinite(value) || (spec?.type === 'integer' && !Number.isInteger(value)))
189
+ return fallback;
190
+ if ((spec?.min !== undefined && value < spec.min) || (spec?.max !== undefined && value > spec.max)) {
191
+ return fallback;
192
+ }
193
+ return value;
194
+ }
195
+ /** An HTML boolean attribute: present = true. */
196
+ booleanAttribute(name) {
197
+ return this.hasAttribute(name);
198
+ }
199
+ }
200
+ /** An element with exactly one slot whose id is the element id (a gap, a single choice, a slider). */
201
+ export class SingleSlotElement extends AstlElement {
202
+ static properties = {
203
+ value: { state: true },
204
+ };
205
+ constructor() {
206
+ super();
207
+ this.value = '';
208
+ }
209
+ get slotIds() {
210
+ return this.id === '' ? [] : [this.id];
211
+ }
212
+ getAnswers() {
213
+ return this.id === '' || this.value === '' ? {} : { [this.id]: this.value };
214
+ }
215
+ setAnswers(answers) {
216
+ const value = answers[this.id];
217
+ if (value !== undefined)
218
+ this.value = value;
219
+ }
220
+ units() {
221
+ return { answered: this.value.trim() === '' ? 0 : 1, total: 1 };
222
+ }
223
+ /** Sets the answer from student input and reports it. */
224
+ updateValue(value) {
225
+ if (value === this.value)
226
+ return;
227
+ this.value = value;
228
+ this.emitChange({ [this.id]: value });
229
+ }
230
+ /** The slot verdict, else the group verdict (e.g. `empty`). */
231
+ get verdict() {
232
+ return this.slotVerdict(this.id) ?? this.groupVerdict;
233
+ }
234
+ /** The correct answer for this slot, when shown. */
235
+ get solutionValue() {
236
+ return this.solution?.[this.id] ?? null;
237
+ }
238
+ }
239
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/element/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAGL,aAAa,EAGb,UAAU,EAEV,WAAW,EAOX,WAAW,GAMZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAkD,MAAM,KAAK,CAAC;AAChG,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,aAAa,EAAuB,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErF,SAAS,cAAc,CAAC,IAAwB;IAC9C,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,cAAc,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC7E,OAAO;QACL,MAAM,EAAE,IAAI;QACZ,CAAC,EAAE,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,IAAI,gBAAgB,CAAC;QAC7E,QAAQ,EAAE,CAAC,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AU,CAAC,OAAgB;QACzB,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/B,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAC9C,CAAC;IAED,KAAK;QACH,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAClE,CAAC;IAED,yDAAyD;IAC/C,WAAW,CAAC,KAAa;QACjC,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK;YAAE,OAAO;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,+DAA+D;IAC/D,IAAc,OAAO;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC;IACxD,CAAC;IAED,oDAAoD;IACpD,IAAc,aAAa;QACzB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ export type { Verdict, VerdictOptions } from './a11y.js';
2
+ export { announce, renderVerdict, verdictIcon, verdictStyles, visuallyHidden } from './a11y.js';
3
+ export type { AttemptChange, AttemptControllerOptions, AttemptListener, AttemptPage, } from './attempt/controller.js';
4
+ export { AttemptController } from './attempt/controller.js';
5
+ export type { HttpCheckerOptions } from './checker/http.js';
6
+ export { httpChecker } from './checker/http.js';
7
+ export type { DefinePlayerOptions } from './define.js';
8
+ export { definePlayer } from './define.js';
9
+ export { AstlElement, SingleSlotElement, seededShuffle } from './element/base.js';
10
+ export { PLAYER_NAMESPACE, playerMessages } from './messages.js';
11
+ export type { LoadInput } from './player/player.js';
12
+ export { AstlPlayer } from './player/player.js';
13
+ export type { ElementEntry, ElementRegistration, LazyElement } from './runtime.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChG,YAAY,EACV,aAAa,EACb,wBAAwB,EACxB,eAAe,EACf,WAAW,GACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACjE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { announce, renderVerdict, verdictIcon, verdictStyles, visuallyHidden } from './a11y.js';
2
+ export { AttemptController } from './attempt/controller.js';
3
+ export { httpChecker } from './checker/http.js';
4
+ export { definePlayer } from './define.js';
5
+ export { AstlElement, SingleSlotElement, seededShuffle } from './element/base.js';
6
+ export { PLAYER_NAMESPACE, playerMessages } from './messages.js';
7
+ export { AstlPlayer } from './player/player.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAOhG,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@astl/player/interaction`: Lit reactive controllers for component elements that move things (pick and place)
3
+ * or move a roving focus, with keyboard, tap and tap, pointer, touch and announcements done once. A subpath of its
4
+ * own, not the main entry: bundles load it with the element chunks that use it, never with the player.
5
+ */
6
+ export type { Axis } from './keys.js';
7
+ export { arrowDelta } from './keys.js';
8
+ export type { PickAndPlaceHost, PickAndPlaceOptions, PickMoment } from './pick-and-place.js';
9
+ export { DRAG_THRESHOLD, PickAndPlace } from './pick-and-place.js';
10
+ export type { RovingFocusOptions } from './roving-focus.js';
11
+ export { RovingFocus } from './roving-focus.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interaction/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { arrowDelta } from './keys.js';
2
+ export { DRAG_THRESHOLD, PickAndPlace } from './pick-and-place.js';
3
+ export { RovingFocus } from './roving-focus.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interaction/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Arrow keys that move: Up and Down (`block`), Left and Right (`inline`, in the writing direction) or all four
3
+ * (`both`, for destinations laid out in two dimensions).
4
+ */
5
+ export type Axis = 'block' | 'inline' | 'both';
6
+ /**
7
+ * The step an arrow key makes along `axis`: 1 forward (Down, or Right in left-to-right text), -1 back, 0 for any other
8
+ * key. Left and Right swap when `host` is laid out right to left, so the next item is always the one read next.
9
+ */
10
+ export declare function arrowDelta(event: KeyboardEvent, axis: Axis, host: Element): -1 | 0 | 1;
11
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/interaction/keys.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,IAAI,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAKtF"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The step an arrow key makes along `axis`: 1 forward (Down, or Right in left-to-right text), -1 back, 0 for any other
3
+ * key. Left and Right swap when `host` is laid out right to left, so the next item is always the one read next.
4
+ */
5
+ export function arrowDelta(event, axis, host) {
6
+ const key = event.key;
7
+ if (axis !== 'inline' && (key === 'ArrowDown' || key === 'ArrowUp'))
8
+ return key === 'ArrowDown' ? 1 : -1;
9
+ if (axis === 'block' || (key !== 'ArrowRight' && key !== 'ArrowLeft'))
10
+ return 0;
11
+ return (key === 'ArrowRight') === (getComputedStyle(host).direction !== 'rtl') ? 1 : -1;
12
+ }
13
+ //# sourceMappingURL=keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/interaction/keys.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAoB,EAAE,IAAU,EAAE,IAAa;IACxE,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IACtB,IAAI,IAAI,KAAK,QAAQ,IAAI,CAAC,GAAG,KAAK,WAAW,IAAI,GAAG,KAAK,SAAS,CAAC;QAAE,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzG,IAAI,IAAI,KAAK,OAAO,IAAI,CAAC,GAAG,KAAK,YAAY,IAAI,GAAG,KAAK,WAAW,CAAC;QAAE,OAAO,CAAC,CAAC;IAChF,OAAO,CAAC,GAAG,KAAK,YAAY,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,120 @@
1
+ import type { ElementContext } from '@astl/core';
2
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
3
+ import { type Axis } from './keys.js';
4
+ /** Pointer travel (px) that turns a press into a drag; anything shorter is a tap. */
5
+ export declare const DRAG_THRESHOLD = 6;
6
+ /**
7
+ * The moments a student hears: an item is picked, a destination is chosen (arrow keys), the item is put somewhere,
8
+ * or it goes back where it was.
9
+ */
10
+ export type PickMoment = 'pick' | 'target' | 'put' | 'cancel';
11
+ /** The element a PickAndPlace works for: a component element (an `AstlElement`) or anything shaped like one. */
12
+ export interface PickAndPlaceHost extends ReactiveControllerHost, HTMLElement {
13
+ readonly disabled: boolean;
14
+ readonly context: Pick<ElementContext, 'announce'>;
15
+ }
16
+ /** What a component tells PickAndPlace. Read on every use, so a getter can follow an attribute. */
17
+ export interface PickAndPlaceOptions<D> {
18
+ /** Where `item` can go, in the order the arrow keys step through. */
19
+ destinations(item: string): readonly D[];
20
+ /** Where `item` is now (its answer, or where it starts). */
21
+ current(item: string): D;
22
+ /** The destination under a pointer at viewport point `x`, `y` while `item` is dragged, or null. */
23
+ at(x: number, y: number, item: string): D | null;
24
+ /** Puts `item` at `to`: the answer changes (report it with `emitChange`). */
25
+ commit(item: string, to: D): void;
26
+ /**
27
+ * The announcement of a moment, in the component's own messages. `to` is where the item is (or would go: `target`)
28
+ * after the moment; `from` is where the student last knew it to be (where it was picked, or the last target).
29
+ */
30
+ say(moment: PickMoment, item: string, to: D, from: D): string;
31
+ /** After an item is picked, gets a new target, is put or goes back: e.g. to move a roving tab stop along with it. */
32
+ changed?(item: string): void;
33
+ /** The arrow keys that step through the destinations. Default `both`. */
34
+ readonly axis?: Axis;
35
+ /** Past the last destination comes the first, and back. */
36
+ readonly wrap?: boolean;
37
+ /**
38
+ * `follow` (default): a dragged item stays where it is until it is put, `over` names the destination under the
39
+ * pointer and the `box` around the pressed element moves with the pointer; a pick from before the drag stays until
40
+ * the drag ends. Putting an item where it is changes nothing: it goes back.
41
+ * `live`: the item is shown where it would go (a list being reordered): a drag picks the item and its target
42
+ * follows the pointer, and putting it down is an answer even where it started.
43
+ */
44
+ readonly preview?: 'follow' | 'live';
45
+ /** `follow`: a CSS selector for the box, around the pressed element, that moves with the pointer. */
46
+ readonly box?: string;
47
+ /**
48
+ * Focus leaving the host (or a press outside it) with an item picked: `cancel` (default) puts it back without a
49
+ * word; `drop` puts it at its target (announced) when it has one other than where it is, else puts it back.
50
+ */
51
+ readonly leave?: 'cancel' | 'drop';
52
+ /** A touch drags only after it is held this long (ms) without moving; a touch that moves sooner scrolls the page. */
53
+ readonly hold?: number;
54
+ /** Touches drag only from this part of an item (CSS selector); elsewhere they scroll. Mouse and pen drag anywhere. */
55
+ readonly handle?: string | null;
56
+ /**
57
+ * Elements outside the host that take part, such as destinations elsewhere in the page (the gaps of a word bank):
58
+ * focus moving to them and presses on them keep a pick. Items may sit there too (a gap holding a word).
59
+ */
60
+ parts?(): Iterable<Element>;
61
+ }
62
+ /**
63
+ * Pick and place, with every way in (WCAG 2.2: 2.1.1 keyboard, 2.5.7 dragging movements):
64
+ * - keyboard: Space or Enter on an item picks it (a native button click), the arrow keys choose a destination (Home
65
+ * and End: the first and the last), Space or Enter on it again puts it there, Escape puts it back;
66
+ * - one pointer, no dragging: tap an item, then a destination (`put`) or another item (with a `place`: put there;
67
+ * without: pick that one instead);
68
+ * - a drag once the pointer travels DRAG_THRESHOLD px, with pointer capture; the click after a drag is not a tap;
69
+ * a touch drags after a long press (`hold`) or from a handle (`handle`), so other touches scroll the page.
70
+ * Escape and a press outside the host work wherever the focus is; held keys do not repeat a pick; Alt, Ctrl and Meta
71
+ * shortcuts stay with the browser; a disabled host forgets any pick. Announcements go through `context.announce`.
72
+ *
73
+ * Wire each item: `@click=${(e) => pick.click(e, id)}`, `@keydown=${(e) => pick.keydown(e, id)}`,
74
+ * `@pointerdown=${(e) => pick.pointerdown(e, id)}` and, for touches that may scroll first (`hold`),
75
+ * `@touchmove=${pick.touchmove}`. A press's moves, release and menu are heard on the document, also for items outside
76
+ * the host.
77
+ */
78
+ export declare class PickAndPlace<D> implements ReactiveController {
79
+ #private;
80
+ constructor(host: PickAndPlaceHost, options: PickAndPlaceOptions<D>);
81
+ /** The item picked with the keyboard or a tap, waiting for a destination. */
82
+ get picked(): string | null;
83
+ /** The destination the arrow keys chose for the picked item; null: where it is. */
84
+ get target(): D | null;
85
+ /** The item being dragged. */
86
+ get dragging(): string | null;
87
+ /** The destination under the dragged item. */
88
+ get over(): D | null;
89
+ /**
90
+ * While a touch may still scroll (`hold`), the page must not scroll once it drags. Bound on items, not the host:
91
+ * a non-passive touch listener makes the browser wait for it before scrolling.
92
+ */
93
+ readonly touchmove: AddEventListenerOptions & EventListenerObject;
94
+ hostDisconnected(): void;
95
+ hostUpdate(): void;
96
+ /** Picks `item`, announced. */
97
+ pick(item: string): void;
98
+ /** Puts the picked item at `to`, announced; where it already is, it goes back (unless the preview is `live`). */
99
+ put(to: D): void;
100
+ /** Puts the picked item back where it is, announced. */
101
+ cancel(): void;
102
+ /** Forgets any pick and drag without a word, e.g. when answers are set from outside. */
103
+ reset(): void;
104
+ /**
105
+ * A click on `item` (a tap, or Space or Enter on its button) picks it. While an item is picked: with a `place` (the
106
+ * clicked item stands for a destination, like a position in a list) the picked item is put there; without, a click
107
+ * on the picked item puts it at its target (or back), and a click on another item picks that one instead.
108
+ */
109
+ click(event: MouseEvent, item: string, place?: D): void;
110
+ /**
111
+ * Whether a click is a tap (or Space or Enter on a button), not the click a drag's release brings, which it uses up:
112
+ * for clicks that do more than `click`.
113
+ */
114
+ tap(event: MouseEvent): boolean;
115
+ /** Arrow keys (and Home, End) on the picked `item` choose its target; returns true when the key was used. */
116
+ keydown(event: KeyboardEvent, item: string): boolean;
117
+ /** A press on `item` with the primary button, a finger or a pen: a tap or the start of a drag. */
118
+ pointerdown(event: PointerEvent, item: string): void;
119
+ }
120
+ //# s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