@qti-components/test 1.10.1 → 2.0.0-next.11
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/dist/components/index.d.ts +0 -11
- package/dist/components/index.js +0 -11
- package/dist/components/index.js.map +1 -1
- package/dist/components/qti-test/getting-started.fixtures.d.ts +7 -0
- package/dist/components/qti-test/getting-started.fixtures.js +8 -0
- package/dist/components/qti-test/getting-started.fixtures.js.map +1 -0
- package/dist/components/qti-test/qti-test.d.ts +1 -0
- package/dist/components/qti-test/showcase.fixtures.d.ts +6 -0
- package/dist/components/qti-test/showcase.fixtures.js +7 -0
- package/dist/components/qti-test/showcase.fixtures.js.map +1 -0
- package/dist/components/styles.d.ts +8 -1
- package/dist/components/styles.js +63 -14
- package/dist/components/styles.js.map +1 -1
- package/dist/components/test-bookmark/test-bookmark.d.ts +48 -0
- package/dist/components/test-bookmark/test-bookmark.js +149 -0
- package/dist/components/test-bookmark/test-bookmark.js.map +1 -0
- package/dist/components/test-check-item/test-check-item.d.ts +9 -2
- package/dist/components/test-check-item/test-check-item.js +19 -13
- package/dist/components/test-check-item/test-check-item.js.map +1 -1
- package/dist/components/test-end-attempt/test-end-attempt.js +7 -2
- package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
- package/dist/components/test-item-link/test-item-link.js +7 -2
- package/dist/components/test-item-link/test-item-link.js.map +1 -1
- package/dist/components/test-navigation/test-navigation.js +8 -2
- package/dist/components/test-navigation/test-navigation.js.map +1 -1
- package/dist/components/test-next/test-next.js +8 -2
- package/dist/components/test-next/test-next.js.map +1 -1
- package/dist/components/test-prev/test-prev.js +7 -2
- package/dist/components/test-prev/test-prev.js.map +1 -1
- package/dist/components/test-print-state/test-print-state.d.ts +27 -0
- package/dist/components/test-print-state/test-print-state.js +87 -0
- package/dist/components/test-print-state/test-print-state.js.map +1 -0
- package/dist/components/test-section-link/test-section-link.js +7 -2
- package/dist/components/test-section-link/test-section-link.js.map +1 -1
- package/dist/components/test-stamp/test-stamp.d.ts +3 -2
- package/dist/components/test-stamp/test-stamp.js +9 -4
- package/dist/components/test-stamp/test-stamp.js.map +1 -1
- package/dist/components/test-submit/test-submit.d.ts +16 -0
- package/dist/components/test-submit/test-submit.js +37 -0
- package/dist/components/test-submit/test-submit.js.map +1 -0
- package/dist/elements.d.ts +37 -44
- package/dist/elements.js +4 -30
- package/dist/elements.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mixins/test-navigation.mixin.js +4 -2
- package/dist/mixins/test-navigation.mixin.js.map +1 -1
- package/dist/mixins/test-processing.mixin.d.ts +1 -0
- package/dist/mixins/test-processing.mixin.js +22 -1
- package/dist/mixins/test-processing.mixin.js.map +1 -1
- package/dist/mixins/test-state.mixin.js +25 -1
- package/dist/mixins/test-state.mixin.js.map +1 -1
- package/dist/plugin-state.d.ts +8 -0
- package/dist/plugin-state.js +7 -0
- package/dist/plugin-state.js.map +1 -0
- package/dist/plugins/elements.d.ts +79 -0
- package/dist/plugins/elements.js +37 -0
- package/dist/plugins/elements.js.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +3 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/public-events.d.ts +9 -0
- package/dist/public-events.js +3 -0
- package/dist/public-events.js.map +1 -1
- package/dist/tts/elements.d.ts +28 -0
- package/dist/tts/elements.js +14 -0
- package/dist/tts/elements.js.map +1 -0
- package/dist/{components/test-item-to-speech → tts}/test-item-to-speech.d.ts +9 -9
- package/dist/{components/test-item-to-speech → tts}/test-item-to-speech.js +81 -92
- package/dist/tts/test-item-to-speech.js.map +1 -0
- package/dist/types/qti-test-state.d.ts +12 -1
- package/dist/types/qti-test-state.js.map +1 -1
- package/package.json +11 -7
- package/dist/components/test-item-to-speech/test-item-to-speech.js.map +0 -1
- package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.d.ts +0 -19
- package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js +0 -39
- package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js.map +0 -1
- package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.d.ts +0 -19
- package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js +0 -39
- package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,cAAc,eAAe,CAAC","sourcesContent":["/** The test plugins: print, scoring, stamp, text-to-speech and view. The core composes them here and nowhere else. */\nexport * from './elements.js';\n"]}
|
package/dist/public-events.d.ts
CHANGED
|
@@ -24,12 +24,21 @@ export interface NavigationFailure {
|
|
|
24
24
|
export interface PublicEventMap {
|
|
25
25
|
'cito-test-navigate': CustomEvent<NavigationTarget>;
|
|
26
26
|
'cito-test-end-attempt': CustomEvent<unknown>;
|
|
27
|
+
/** Scores the test: resets its outcomes to their defaults, runs outcome processing, then `cito-test-submitted`. */
|
|
28
|
+
'cito-test-submit': CustomEvent<Record<string, never>>;
|
|
27
29
|
'cito-test-update-outcome': CustomEvent<{
|
|
28
30
|
assessmentItemRefId: string;
|
|
29
31
|
outcomeVariableId: string;
|
|
30
32
|
value: number | string;
|
|
31
33
|
}>;
|
|
32
34
|
'cito-test-switch-view': CustomEvent<View>;
|
|
35
|
+
/** `value` is JSON; `null` or `undefined` removes the plugin's entry. */
|
|
36
|
+
'cito-test-update-plugin-state': CustomEvent<{
|
|
37
|
+
plugin: string;
|
|
38
|
+
value: unknown;
|
|
39
|
+
}>;
|
|
40
|
+
/** Outcome processing ran after a submit: read the test outcomes now. */
|
|
41
|
+
'cito-test-submitted': CustomEvent<Record<string, never>>;
|
|
33
42
|
'cito-test-navigated': CustomEvent<NavigationTarget>;
|
|
34
43
|
'cito-test-navigation-started': CustomEvent<NavigationTarget>;
|
|
35
44
|
'cito-test-navigation-failed': CustomEvent<NavigationFailure>;
|
package/dist/public-events.js
CHANGED
|
@@ -2,8 +2,11 @@ import { dispatchDeclared, listenDeclared } from '@qti-components/elements/publi
|
|
|
2
2
|
export const PUBLIC_EVENTS = {
|
|
3
3
|
'cito-test-navigate': { kind: 'request', scope: 'test', deprecated: 'qti-request-navigation' },
|
|
4
4
|
'cito-test-end-attempt': { kind: 'request', scope: 'test', deprecated: 'test-end-attempt' },
|
|
5
|
+
'cito-test-submit': { kind: 'request', scope: 'test' },
|
|
5
6
|
'cito-test-update-outcome': { kind: 'request', scope: 'test', deprecated: 'test-update-outcome-variable' },
|
|
7
|
+
'cito-test-update-plugin-state': { kind: 'request', scope: 'test' },
|
|
6
8
|
'cito-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'on-test-switch-view' },
|
|
9
|
+
'cito-test-submitted': { kind: 'notification', scope: 'test' },
|
|
7
10
|
'cito-test-navigated': { kind: 'notification', scope: 'test' },
|
|
8
11
|
'cito-test-navigation-started': {
|
|
9
12
|
kind: 'notification',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-events.js","sourceRoot":"","sources":["../src/public-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"public-events.js","sourceRoot":"","sources":["../src/public-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAyD1F,MAAM,CAAC,MAAM,aAAa,GAAoD;IAC5E,oBAAoB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,wBAAwB,EAAE;IAC9F,uBAAuB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE;IAC3F,kBAAkB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE;IACtD,0BAA0B,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,8BAA8B,EAAE;IAC1G,+BAA+B,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE;IACnE,uBAAuB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,qBAAqB,EAAE;IAC9F,qBAAqB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE;IAC9D,qBAAqB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE;IAC9D,8BAA8B,EAAE;QAC9B,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,gCAAgC;KAC7C;IACD,6BAA6B,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,sBAAsB,EAAE;IAC1G,oBAAoB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE;IAC5F,kBAAkB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,+BAA+B,EAAE;IACxG,yBAAyB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,mBAAmB,EAAE;IACnG,yBAAyB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE;IAClE,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE;IAChE,yBAAyB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,mCAAmC,EAAE;CACpH,CAAC;AAMF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAmB,EACnB,IAAO,EACP,MAAkE;IAElE,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAmB,EACnB,IAAO,EACP,OAAuC;IAEvC,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,OAA6B,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { dispatchDeclared, listenDeclared } from '@qti-components/elements/public-events';\n\nimport type { View } from '@qti-components/base';\nimport type { PublicEventDeclaration } from '@qti-components/elements/public-events';\nimport type { QtiTestState } from './types/qti-test-state';\n\n/**\n * The public events of the test. The name tells you it is public: everything here starts with\n * `cito-`; every other event is internal plumbing and may change in any release.\n *\n * Requests are verbs (a host or plugin dispatches them at the test), notifications are past tense\n * (the test dispatches them). All bubble and are composed.\n *\n * `deprecated` is the name this event had before it became public. One helper (`dispatchPublic`,\n * `listenPublic`) sends or handles both names until the next major, then the field goes.\n */\nexport interface NavigationTarget {\n type: 'item' | 'section';\n id: string;\n}\n\nexport interface NavigationFailure {\n message: string;\n details?: unknown;\n itemId?: string;\n sectionId?: string;\n}\n\nexport interface PublicEventMap {\n 'cito-test-navigate': CustomEvent<NavigationTarget>;\n 'cito-test-end-attempt': CustomEvent<unknown>;\n /** Scores the test: resets its outcomes to their defaults, runs outcome processing, then `cito-test-submitted`. */\n 'cito-test-submit': CustomEvent<Record<string, never>>;\n 'cito-test-update-outcome': CustomEvent<{\n assessmentItemRefId: string;\n outcomeVariableId: string;\n value: number | string;\n }>;\n 'cito-test-switch-view': CustomEvent<View>;\n /** `value` is JSON; `null` or `undefined` removes the plugin's entry. */\n 'cito-test-update-plugin-state': CustomEvent<{ plugin: string; value: unknown }>;\n /** Outcome processing ran after a submit: read the test outcomes now. */\n 'cito-test-submitted': CustomEvent<Record<string, never>>;\n 'cito-test-navigated': CustomEvent<NavigationTarget>;\n 'cito-test-navigation-started': CustomEvent<NavigationTarget>;\n 'cito-test-navigation-failed': CustomEvent<NavigationFailure>;\n 'cito-test-rendered': CustomEvent<{ identifier: string; element: Element }[]>;\n // `cito-test-loaded` (detail: the `QtiAssessmentTest`) is added by qti-assessment-test.ts, so this\n // module imports no element: that import would be a cycle.\n 'cito-test-state-changed': CustomEvent<QtiTestState>;\n 'cito-test-items-skipped': CustomEvent<{ ids: string[] }>;\n 'cito-test-end-reached': CustomEvent<Record<string, never>>;\n 'cito-item-ref-connected': CustomEvent<{ identifier: string; href: string; category: string }>;\n}\n\nexport type PublicEventName = keyof PublicEventMap;\n\nexport const PUBLIC_EVENTS: Record<PublicEventName, PublicEventDeclaration> = {\n 'cito-test-navigate': { kind: 'request', scope: 'test', deprecated: 'qti-request-navigation' },\n 'cito-test-end-attempt': { kind: 'request', scope: 'test', deprecated: 'test-end-attempt' },\n 'cito-test-submit': { kind: 'request', scope: 'test' },\n 'cito-test-update-outcome': { kind: 'request', scope: 'test', deprecated: 'test-update-outcome-variable' },\n 'cito-test-update-plugin-state': { kind: 'request', scope: 'test' },\n 'cito-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'on-test-switch-view' },\n 'cito-test-submitted': { kind: 'notification', scope: 'test' },\n 'cito-test-navigated': { kind: 'notification', scope: 'test' },\n 'cito-test-navigation-started': {\n kind: 'notification',\n scope: 'test',\n deprecated: 'qti-navigation-loading-started'\n },\n 'cito-test-navigation-failed': { kind: 'notification', scope: 'test', deprecated: 'qti-navigation-error' },\n 'cito-test-rendered': { kind: 'notification', scope: 'test', deprecated: 'qti-test-loaded' },\n 'cito-test-loaded': { kind: 'notification', scope: 'test', deprecated: 'qti-assessment-test-connected' },\n 'cito-test-state-changed': { kind: 'notification', scope: 'test', deprecated: 'qti-state-changed' },\n 'cito-test-items-skipped': { kind: 'notification', scope: 'test' },\n 'cito-test-end-reached': { kind: 'notification', scope: 'test' },\n 'cito-item-ref-connected': { kind: 'notification', scope: 'item', deprecated: 'qti-assessment-item-ref-connected' }\n};\n\ndeclare global {\n interface HTMLElementEventMap extends PublicEventMap {}\n}\n\n/**\n * Dispatch a public event, and its deprecated name with the same `detail` object. The detail is\n * always an object so `listenPublic` can tell the two apart from one dispatch.\n */\nexport function dispatchPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n detail: PublicEventMap[K] extends CustomEvent<infer D> ? D : never\n): void {\n dispatchDeclared(target, PUBLIC_EVENTS, name, detail);\n}\n\n/**\n * Listen for a public event and its deprecated name; the handler runs once for a sender that\n * dispatched both. See `listenDeclared`.\n */\nexport function listenPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n handler: (e: PublicEventMap[K]) => void\n): void {\n listenDeclared(target, PUBLIC_EVENTS, name, handler as (e: Event) => void);\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TestItemToSpeech, TestTtsNext, TestTtsPause, TestTtsPick, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop } from './test-item-to-speech';
|
|
2
|
+
export { TestItemToSpeech, TestTtsNext, TestTtsPause, TestTtsPick, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop };
|
|
3
|
+
/** The text-to-speech elements, for registering them yourself (e.g. in a scoped registry). Defines nothing. */
|
|
4
|
+
export declare const ttsElements: readonly [{
|
|
5
|
+
readonly tag: "test-item-to-speech";
|
|
6
|
+
readonly ctor: typeof TestItemToSpeech;
|
|
7
|
+
}, {
|
|
8
|
+
readonly tag: "test-tts-next";
|
|
9
|
+
readonly ctor: typeof TestTtsNext;
|
|
10
|
+
}, {
|
|
11
|
+
readonly tag: "test-tts-pause";
|
|
12
|
+
readonly ctor: typeof TestTtsPause;
|
|
13
|
+
}, {
|
|
14
|
+
readonly tag: "test-tts-pick";
|
|
15
|
+
readonly ctor: typeof TestTtsPick;
|
|
16
|
+
}, {
|
|
17
|
+
readonly tag: "test-tts-play";
|
|
18
|
+
readonly ctor: typeof TestTtsPlay;
|
|
19
|
+
}, {
|
|
20
|
+
readonly tag: "test-tts-prev";
|
|
21
|
+
readonly ctor: typeof TestTtsPrev;
|
|
22
|
+
}, {
|
|
23
|
+
readonly tag: "test-tts-resume";
|
|
24
|
+
readonly ctor: typeof TestTtsResume;
|
|
25
|
+
}, {
|
|
26
|
+
readonly tag: "test-tts-stop";
|
|
27
|
+
readonly ctor: typeof TestTtsStop;
|
|
28
|
+
}];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TestItemToSpeech, TestTtsNext, TestTtsPause, TestTtsPick, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop } from './test-item-to-speech';
|
|
2
|
+
export { TestItemToSpeech, TestTtsNext, TestTtsPause, TestTtsPick, TestTtsPlay, TestTtsPrev, TestTtsResume, TestTtsStop };
|
|
3
|
+
/** The text-to-speech elements, for registering them yourself (e.g. in a scoped registry). Defines nothing. */
|
|
4
|
+
export const ttsElements = [
|
|
5
|
+
{ tag: 'test-item-to-speech', ctor: TestItemToSpeech },
|
|
6
|
+
{ tag: 'test-tts-next', ctor: TestTtsNext },
|
|
7
|
+
{ tag: 'test-tts-pause', ctor: TestTtsPause },
|
|
8
|
+
{ tag: 'test-tts-pick', ctor: TestTtsPick },
|
|
9
|
+
{ tag: 'test-tts-play', ctor: TestTtsPlay },
|
|
10
|
+
{ tag: 'test-tts-prev', ctor: TestTtsPrev },
|
|
11
|
+
{ tag: 'test-tts-resume', ctor: TestTtsResume },
|
|
12
|
+
{ tag: 'test-tts-stop', ctor: TestTtsStop }
|
|
13
|
+
];
|
|
14
|
+
//# sourceMappingURL=elements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elements.js","sourceRoot":"","sources":["../../src/tts/elements.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACZ,CAAC;AAEF,+GAA+G;AAC/G,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,EAAE,GAAG,EAAE,qBAAqB,EAAE,IAAI,EAAE,gBAAgB,EAAE;IACtD,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,YAAY,EAAE;IAC7C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3C,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,aAAa,EAAE;IAC/C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE;CACnC,CAAC","sourcesContent":["import {\n TestItemToSpeech,\n TestTtsNext,\n TestTtsPause,\n TestTtsPick,\n TestTtsPlay,\n TestTtsPrev,\n TestTtsResume,\n TestTtsStop\n} from './test-item-to-speech';\n\nexport {\n TestItemToSpeech,\n TestTtsNext,\n TestTtsPause,\n TestTtsPick,\n TestTtsPlay,\n TestTtsPrev,\n TestTtsResume,\n TestTtsStop\n};\n\n/** The text-to-speech elements, for registering them yourself (e.g. in a scoped registry). Defines nothing. */\nexport const ttsElements = [\n { tag: 'test-item-to-speech', ctor: TestItemToSpeech },\n { tag: 'test-tts-next', ctor: TestTtsNext },\n { tag: 'test-tts-pause', ctor: TestTtsPause },\n { tag: 'test-tts-pick', ctor: TestTtsPick },\n { tag: 'test-tts-play', ctor: TestTtsPlay },\n { tag: 'test-tts-prev', ctor: TestTtsPrev },\n { tag: 'test-tts-resume', ctor: TestTtsResume },\n { tag: 'test-tts-stop', ctor: TestTtsStop }\n] as const;\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
2
|
import type { PropertyValues } from 'lit';
|
|
3
|
-
import type {
|
|
4
|
-
import type { TestHost } from '../../internal/test-host.context';
|
|
3
|
+
import type { ComputedContext } from '@qti-components/base';
|
|
5
4
|
type SpeechState = 'idle' | 'playing' | 'paused';
|
|
6
5
|
export interface TtsContext {
|
|
7
6
|
state: SpeechState;
|
|
@@ -92,10 +91,9 @@ declare abstract class TtsButtonBase extends LitElement {
|
|
|
92
91
|
* 3. **Inside a `qti-assessment-item-ref`** — e.g. in a `<template item-ref>` on `<qti-test>`,
|
|
93
92
|
* so every item gets a player of its own: the player reads that item, and only that item.
|
|
94
93
|
* The navigation cursor is ignored; speech stops when the player leaves the page with its item.
|
|
95
|
-
* 4. **Anywhere else
|
|
96
|
-
* and reads the item
|
|
97
|
-
*
|
|
98
|
-
* item from the top.
|
|
94
|
+
* 4. **Anywhere else inside `<test-navigation>`** — e.g. a toolbar: the player follows the
|
|
95
|
+
* navigation cursor and reads the active item of the computed context. Navigating stops
|
|
96
|
+
* speech and starts the next item from the top.
|
|
99
97
|
*
|
|
100
98
|
* ```html
|
|
101
99
|
* <!-- 1. a player for the shared reading text -->
|
|
@@ -151,9 +149,11 @@ export declare class TestItemToSpeech extends LitElement {
|
|
|
151
149
|
static styles: import("lit").CSSResult;
|
|
152
150
|
/** Fallback language when neither the item content nor the document declares one. */
|
|
153
151
|
language: string;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
/**
|
|
153
|
+
* The test as `test-navigation` computes it: which item is active, and where it is rendered
|
|
154
|
+
* (`itemElement`). Updated on navigation and whenever an item is rendered.
|
|
155
|
+
*/
|
|
156
|
+
protected _computedContext?: ComputedContext;
|
|
157
157
|
_ttsContext: TtsContext;
|
|
158
158
|
constructor();
|
|
159
159
|
willUpdate(changed: PropertyValues): void;
|
|
@@ -8,20 +8,29 @@ import { html, LitElement, css } from 'lit';
|
|
|
8
8
|
import { consume, provide, createContext } from '@lit/context';
|
|
9
9
|
import { property, state } from 'lit/decorators.js';
|
|
10
10
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import * as styles from '../styles';
|
|
11
|
+
import { computedContext } from '@qti-components/base';
|
|
12
|
+
import * as styles from '../components/styles';
|
|
14
13
|
// ─── CSS Custom Highlight ─────────────────────────────────────────────────────
|
|
15
14
|
const HIGHLIGHT_ELEMENT = 'tts-element'; // navigation cursor — whole element
|
|
16
15
|
const HIGHLIGHT_WORD = 'tts-word'; // word boundary during speech
|
|
17
|
-
// Shared across all instances — added to whichever shadow root needs it
|
|
16
|
+
// Shared across all instances — added to whichever shadow root needs it. The two highlights are
|
|
17
|
+
// tints of the theme's info (the element being read) and warning (the word being spoken) colours,
|
|
18
|
+
// see-through so the text and its own background stay visible. Without the theme they fall back to
|
|
19
|
+
// the system Highlight and Mark colours. A host repaints them with --test-tts-element-highlight and
|
|
20
|
+
// --test-tts-word-highlight.
|
|
18
21
|
let highlightSheet = null;
|
|
19
22
|
function getHighlightSheet() {
|
|
20
23
|
if (!highlightSheet) {
|
|
21
24
|
highlightSheet = new CSSStyleSheet();
|
|
22
25
|
highlightSheet.replaceSync(`
|
|
23
|
-
::highlight(${HIGHLIGHT_ELEMENT}) {
|
|
24
|
-
|
|
26
|
+
::highlight(${HIGHLIGHT_ELEMENT}) {
|
|
27
|
+
background-color: var(--test-tts-element-highlight, color-mix(in oklab, var(--qti-color-info, var(--cito-color-info, Highlight)) 15%, transparent));
|
|
28
|
+
color: inherit;
|
|
29
|
+
}
|
|
30
|
+
::highlight(${HIGHLIGHT_WORD}) {
|
|
31
|
+
background-color: var(--test-tts-word-highlight, color-mix(in oklab, var(--qti-color-warning, var(--cito-color-warning, Mark)) 55%, transparent));
|
|
32
|
+
color: inherit;
|
|
33
|
+
}
|
|
25
34
|
`);
|
|
26
35
|
}
|
|
27
36
|
return highlightSheet;
|
|
@@ -66,8 +75,13 @@ class TtsButtonBase extends LitElement {
|
|
|
66
75
|
page as tall as the scrolled content. */
|
|
67
76
|
position: relative;
|
|
68
77
|
}
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
@media (hover: hover) and (pointer: fine) {
|
|
79
|
+
button:hover:not(:disabled) {
|
|
80
|
+
${styles.btnInteractive};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
button:active:not(:disabled) {
|
|
84
|
+
${styles.btnActive};
|
|
71
85
|
}
|
|
72
86
|
button:focus-visible {
|
|
73
87
|
${styles.focusRing};
|
|
@@ -77,8 +91,8 @@ class TtsButtonBase extends LitElement {
|
|
|
77
91
|
}
|
|
78
92
|
button[aria-pressed='true'],
|
|
79
93
|
button[aria-pressed='true']:hover {
|
|
80
|
-
background-color: var(--test-button-selected-background-color, var(--qti-selected-bg,
|
|
81
|
-
color: var(--test-button-selected-color, var(--qti-selected-color,
|
|
94
|
+
background-color: var(--test-button-selected-background-color, var(--qti-selected-bg, Highlight));
|
|
95
|
+
color: var(--test-button-selected-color, var(--qti-selected-color, HighlightText));
|
|
82
96
|
}
|
|
83
97
|
svg,
|
|
84
98
|
::slotted(svg) {
|
|
@@ -176,10 +190,9 @@ __decorate([
|
|
|
176
190
|
* 3. **Inside a `qti-assessment-item-ref`** — e.g. in a `<template item-ref>` on `<qti-test>`,
|
|
177
191
|
* so every item gets a player of its own: the player reads that item, and only that item.
|
|
178
192
|
* The navigation cursor is ignored; speech stops when the player leaves the page with its item.
|
|
179
|
-
* 4. **Anywhere else
|
|
180
|
-
* and reads the item
|
|
181
|
-
*
|
|
182
|
-
* item from the top.
|
|
193
|
+
* 4. **Anywhere else inside `<test-navigation>`** — e.g. a toolbar: the player follows the
|
|
194
|
+
* navigation cursor and reads the active item of the computed context. Navigating stops
|
|
195
|
+
* speech and starts the next item from the top.
|
|
183
196
|
*
|
|
184
197
|
* ```html
|
|
185
198
|
* <!-- 1. a player for the shared reading text -->
|
|
@@ -250,15 +263,17 @@ export class TestItemToSpeech extends LitElement {
|
|
|
250
263
|
#contentMode;
|
|
251
264
|
// Item-ref mode: the item-ref this player sits in, resolved on connect. Null means cursor mode.
|
|
252
265
|
#itemRef;
|
|
253
|
-
//
|
|
266
|
+
// Item-ref mode: our item-ref, for its item-connected event. Cursor mode: where prev/next's
|
|
267
|
+
// navigation request is heard.
|
|
254
268
|
#eventHost;
|
|
255
269
|
#boundHandleItemConnected;
|
|
256
270
|
#boundHandleNavigation;
|
|
257
271
|
// Cursor mode: the previous navigation position, to detect moving to another item or section.
|
|
258
272
|
#prevNavItemRefId;
|
|
259
273
|
#prevNavSectionId;
|
|
260
|
-
// Current set of block-level reading elements for the item
|
|
274
|
+
// Current set of block-level reading elements for the item, and the root they were collected from
|
|
261
275
|
#readingElements;
|
|
276
|
+
#readingRoot;
|
|
262
277
|
#currentElementIndex;
|
|
263
278
|
// Text nodes of the element currently being spoken (for word-boundary highlight)
|
|
264
279
|
#textNodes;
|
|
@@ -290,15 +305,17 @@ export class TestItemToSpeech extends LitElement {
|
|
|
290
305
|
this.#contentMode = false;
|
|
291
306
|
// Item-ref mode: the item-ref this player sits in, resolved on connect. Null means cursor mode.
|
|
292
307
|
this.#itemRef = null;
|
|
293
|
-
//
|
|
308
|
+
// Item-ref mode: our item-ref, for its item-connected event. Cursor mode: where prev/next's
|
|
309
|
+
// navigation request is heard.
|
|
294
310
|
this.#eventHost = null;
|
|
295
311
|
this.#boundHandleItemConnected = this.#handleItemConnected.bind(this);
|
|
296
312
|
this.#boundHandleNavigation = () => this.#stop();
|
|
297
313
|
// Cursor mode: the previous navigation position, to detect moving to another item or section.
|
|
298
314
|
this.#prevNavItemRefId = undefined;
|
|
299
315
|
this.#prevNavSectionId = undefined;
|
|
300
|
-
// Current set of block-level reading elements for the item
|
|
316
|
+
// Current set of block-level reading elements for the item, and the root they were collected from
|
|
301
317
|
this.#readingElements = null;
|
|
318
|
+
this.#readingRoot = null;
|
|
302
319
|
this.#currentElementIndex = 0;
|
|
303
320
|
// Text nodes of the element currently being spoken (for word-boundary highlight)
|
|
304
321
|
this.#textNodes = [];
|
|
@@ -340,13 +357,15 @@ export class TestItemToSpeech extends LitElement {
|
|
|
340
357
|
if (this.#stimulusMode || this.#contentMode || this.#itemRef)
|
|
341
358
|
return;
|
|
342
359
|
// Cursor mode: moving to another item or section stops speech and starts over (ignore the
|
|
343
|
-
// initial undefined → value transition). Section navigation leaves
|
|
360
|
+
// initial undefined → value transition). Section navigation leaves no item active, so it
|
|
344
361
|
// needs its own check.
|
|
345
|
-
const item = this
|
|
346
|
-
const section = this._sessionContext?.navSectionId ?? null;
|
|
362
|
+
const { item, section } = this.#activePosition();
|
|
347
363
|
const itemChanged = this.#prevNavItemRefId !== undefined && this.#prevNavItemRefId !== item;
|
|
348
364
|
const sectionChanged = this.#prevNavSectionId !== undefined && this.#prevNavSectionId !== section;
|
|
349
|
-
|
|
365
|
+
// The same item rendered again (e.g. linking to the item already shown): the elements
|
|
366
|
+
// collected earlier are detached. The context updates when an item renders, so check here.
|
|
367
|
+
const rerendered = this.#readingElements !== null && this.#readingRoot !== null && this.#readingRoot !== this.#resolveReadingRoot();
|
|
368
|
+
if (itemChanged || sectionChanged || rerendered)
|
|
350
369
|
this.#resetReadingPosition();
|
|
351
370
|
this.#prevNavItemRefId = item;
|
|
352
371
|
this.#prevNavSectionId = section;
|
|
@@ -364,7 +383,7 @@ export class TestItemToSpeech extends LitElement {
|
|
|
364
383
|
super.connectedCallback();
|
|
365
384
|
this.#setSpeechState('idle');
|
|
366
385
|
// NOTE: #ensureHighlightStyles() is called lazily on first highlight use
|
|
367
|
-
// because
|
|
386
|
+
// because the item to read may not be in the DOM yet at this point.
|
|
368
387
|
this.#stimulusMode = this.#stimulusPlaceholder() !== null;
|
|
369
388
|
if (this.#stimulusMode) {
|
|
370
389
|
// Stimulus mode: neither items nor navigation decide what is read, only the content of the
|
|
@@ -383,14 +402,16 @@ export class TestItemToSpeech extends LitElement {
|
|
|
383
402
|
if (this.#contentMode)
|
|
384
403
|
return;
|
|
385
404
|
this.#itemRef = this.closest('qti-assessment-item-ref');
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
this.#
|
|
390
|
-
|
|
391
|
-
|
|
405
|
+
if (this.#itemRef) {
|
|
406
|
+
// Item-ref mode: qti-assessment-item-connected (bubbles+composed) passes our own item-ref
|
|
407
|
+
// when our item renders again.
|
|
408
|
+
this.#eventHost = this.#itemRef;
|
|
409
|
+
this.#eventHost.addEventListener('qti-assessment-item-connected', this.#boundHandleItemConnected);
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
392
412
|
// Cursor mode: cito-test-navigate fires synchronously on prev/next — stop right away
|
|
393
|
-
// instead of waiting for the new position to arrive through the
|
|
413
|
+
// instead of waiting for the new position to arrive through the computed context.
|
|
414
|
+
this.#eventHost = this.closest('test-navigation') ?? this.getRootNode();
|
|
394
415
|
this.#eventHost.addEventListener('cito-test-navigate', this.#boundHandleNavigation);
|
|
395
416
|
this.#eventHost.addEventListener('qti-request-navigation', this.#boundHandleNavigation); // deprecated name, still sent by hosts
|
|
396
417
|
}
|
|
@@ -417,19 +438,22 @@ export class TestItemToSpeech extends LitElement {
|
|
|
417
438
|
render() {
|
|
418
439
|
return html `<slot></slot>`;
|
|
419
440
|
}
|
|
420
|
-
/**
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
* the check in updated() does not catch it.
|
|
424
|
-
*/
|
|
425
|
-
#handleItemConnected(event) {
|
|
426
|
-
if (this.#readingElements === null)
|
|
427
|
-
return;
|
|
428
|
-
// In item-ref mode the event came through our own item-ref, so it is always ours.
|
|
429
|
-
const identifier = event.detail?.identifier;
|
|
430
|
-
if (this.#itemRef || identifier === this._sessionContext?.navItemRefId)
|
|
441
|
+
/** Item-ref mode: our item rendered again, so the elements collected earlier are detached. */
|
|
442
|
+
#handleItemConnected() {
|
|
443
|
+
if (this.#readingElements !== null)
|
|
431
444
|
this.#resetReadingPosition();
|
|
432
445
|
}
|
|
446
|
+
/** Cursor mode: the active item and section, from the computed context. */
|
|
447
|
+
#activePosition() {
|
|
448
|
+
for (const part of this._computedContext?.testParts ?? []) {
|
|
449
|
+
for (const section of part.sections) {
|
|
450
|
+
if (!section.active)
|
|
451
|
+
continue;
|
|
452
|
+
return { item: section.items.find(item => item.active)?.identifier ?? null, section: section.identifier };
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return { item: null, section: null };
|
|
456
|
+
}
|
|
433
457
|
/**
|
|
434
458
|
* Stimulus mode: the stimulus next to the player was (re)loaded or swapped. Forget what was
|
|
435
459
|
* collected, so the next play reads the new content from the top. Unlike
|
|
@@ -475,45 +499,16 @@ export class TestItemToSpeech extends LitElement {
|
|
|
475
499
|
return this.#contentElement();
|
|
476
500
|
return this.#resolveItem()?.querySelector('qti-item-body') ?? null;
|
|
477
501
|
}
|
|
478
|
-
/**
|
|
502
|
+
/**
|
|
503
|
+
* The item to read: our item-ref's (item-ref mode), or the active one (cursor mode). The test
|
|
504
|
+
* looks the active one up in its own items (`computedContext.itemElement`), so a page with
|
|
505
|
+
* several tests showing the same item still reads the right one.
|
|
506
|
+
*/
|
|
479
507
|
#resolveItem() {
|
|
480
508
|
if (this.#itemRef)
|
|
481
509
|
return this.#itemRef.assessmentItem;
|
|
482
|
-
const
|
|
483
|
-
return
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* Cursor mode: find the rendered item for an item-ref identifier. Our own `<qti-test>` first —
|
|
487
|
-
* a page can hold several tests showing the same item — then every root from here up to the
|
|
488
|
-
* document; each scope directly and in the `test-container` shadow roots inside it.
|
|
489
|
-
*/
|
|
490
|
-
#findItemInDom(identifier) {
|
|
491
|
-
const selector = `qti-assessment-item-ref[identifier="${CSS.escape(identifier)}"] qti-assessment-item`;
|
|
492
|
-
const search = (scope) => {
|
|
493
|
-
const direct = scope.querySelector(selector);
|
|
494
|
-
if (direct)
|
|
495
|
-
return direct;
|
|
496
|
-
for (const container of Array.from(scope.querySelectorAll('test-container'))) {
|
|
497
|
-
const inShadow = container.shadowRoot?.querySelector(selector);
|
|
498
|
-
if (inShadow)
|
|
499
|
-
return inShadow;
|
|
500
|
-
}
|
|
501
|
-
return null;
|
|
502
|
-
};
|
|
503
|
-
const test = this.closest('qti-test');
|
|
504
|
-
const inTest = test && search(test);
|
|
505
|
-
if (inTest)
|
|
506
|
-
return inTest;
|
|
507
|
-
let root = this.getRootNode();
|
|
508
|
-
for (;;) {
|
|
509
|
-
const found = search(root);
|
|
510
|
-
if (found)
|
|
511
|
-
return found;
|
|
512
|
-
const host = root.host;
|
|
513
|
-
if (!host)
|
|
514
|
-
return null;
|
|
515
|
-
root = host.getRootNode();
|
|
516
|
-
}
|
|
510
|
+
const { item } = this.#activePosition();
|
|
511
|
+
return item ? (this._computedContext?.itemElement?.(item) ?? null) : null;
|
|
517
512
|
}
|
|
518
513
|
/** Update speech state on both the context (notifies children) and the host's CSS custom states. */
|
|
519
514
|
#setSpeechState(state) {
|
|
@@ -553,6 +548,7 @@ export class TestItemToSpeech extends LitElement {
|
|
|
553
548
|
// so the next call retries instead of getting stuck on an empty result forever.
|
|
554
549
|
if (!root)
|
|
555
550
|
return [];
|
|
551
|
+
this.#readingRoot = root;
|
|
556
552
|
// Collect block-level elements (and QTI prompt / choice elements) that contain readable text.
|
|
557
553
|
// Keep only the innermost matches so `<li><p>…</p></li>` is not read twice. Content hidden
|
|
558
554
|
// from assistive technology (`aria-hidden="true"`, e.g. decorative icons) is not read either.
|
|
@@ -852,10 +848,9 @@ export class TestItemToSpeech extends LitElement {
|
|
|
852
848
|
return right < 0 ? text.length - charIndex : right;
|
|
853
849
|
}
|
|
854
850
|
/**
|
|
855
|
-
* Add ::highlight() rules both to
|
|
856
|
-
*
|
|
857
|
-
*
|
|
858
|
-
* guaranteed to be in the DOM by the time navigation or speech starts.
|
|
851
|
+
* Add ::highlight() rules both to the shadow root the highlighted text lives in and to the
|
|
852
|
+
* document (safety net — spec allows document rules to apply across shadow DOM). Called lazily
|
|
853
|
+
* on first highlight use, once the reading elements have been collected.
|
|
859
854
|
*/
|
|
860
855
|
#ensureHighlightStyles() {
|
|
861
856
|
if (!('highlights' in CSS))
|
|
@@ -865,13 +860,10 @@ export class TestItemToSpeech extends LitElement {
|
|
|
865
860
|
if (!document.adoptedStyleSheets.includes(sheet)) {
|
|
866
861
|
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
867
862
|
}
|
|
868
|
-
// 2. Shadow roots the highlighted text may live in: test-container's, and
|
|
869
|
-
// root when the player itself sits inside a shadow tree (e.g. built into
|
|
863
|
+
// 2. Shadow roots the highlighted text may live in: the item's (e.g. test-container's), and
|
|
864
|
+
// the player's own root when the player itself sits inside a shadow tree (e.g. built into
|
|
865
|
+
// an item card).
|
|
870
866
|
const roots = new Set();
|
|
871
|
-
const testContainer = this.closest('test-navigation')?.querySelector('test-container') ??
|
|
872
|
-
this.testHost?.querySelector('test-container');
|
|
873
|
-
if (testContainer?.shadowRoot)
|
|
874
|
-
roots.add(testContainer.shadowRoot);
|
|
875
867
|
const ownRoot = this.getRootNode();
|
|
876
868
|
if (ownRoot instanceof ShadowRoot)
|
|
877
869
|
roots.add(ownRoot);
|
|
@@ -889,11 +881,8 @@ __decorate([
|
|
|
889
881
|
property({ type: String })
|
|
890
882
|
], TestItemToSpeech.prototype, "language", void 0);
|
|
891
883
|
__decorate([
|
|
892
|
-
consume({ context:
|
|
893
|
-
], TestItemToSpeech.prototype, "
|
|
894
|
-
__decorate([
|
|
895
|
-
consume({ context: testHostContext, subscribe: true })
|
|
896
|
-
], TestItemToSpeech.prototype, "testHost", void 0);
|
|
884
|
+
consume({ context: computedContext, subscribe: true })
|
|
885
|
+
], TestItemToSpeech.prototype, "_computedContext", void 0);
|
|
897
886
|
__decorate([
|
|
898
887
|
state(),
|
|
899
888
|
provide({ context: ttsContext })
|