@qti-components/test 1.10.0 → 2.0.0-next.5

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 (49) hide show
  1. package/dist/components/index.d.ts +0 -11
  2. package/dist/components/index.js +0 -11
  3. package/dist/components/index.js.map +1 -1
  4. package/dist/components/test-bookmark/test-bookmark.d.ts +48 -0
  5. package/dist/components/test-bookmark/test-bookmark.js +144 -0
  6. package/dist/components/test-bookmark/test-bookmark.js.map +1 -0
  7. package/dist/components/test-check-item/test-check-item.d.ts +9 -2
  8. package/dist/components/test-check-item/test-check-item.js +12 -11
  9. package/dist/components/test-check-item/test-check-item.js.map +1 -1
  10. package/dist/components/test-navigation/test-navigation.js +8 -2
  11. package/dist/components/test-navigation/test-navigation.js.map +1 -1
  12. package/dist/components/test-stamp/test-stamp.js +6 -2
  13. package/dist/components/test-stamp/test-stamp.js.map +1 -1
  14. package/dist/elements.d.ts +31 -44
  15. package/dist/elements.js +4 -30
  16. package/dist/elements.js.map +1 -1
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +2 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/mixins/test-state.mixin.js +25 -1
  21. package/dist/mixins/test-state.mixin.js.map +1 -1
  22. package/dist/plugin-state.d.ts +8 -0
  23. package/dist/plugin-state.js +7 -0
  24. package/dist/plugin-state.js.map +1 -0
  25. package/dist/plugins/elements.d.ts +71 -0
  26. package/dist/plugins/elements.js +33 -0
  27. package/dist/plugins/elements.js.map +1 -0
  28. package/dist/plugins/index.d.ts +2 -0
  29. package/dist/plugins/index.js +3 -0
  30. package/dist/plugins/index.js.map +1 -0
  31. package/dist/public-events.d.ts +5 -0
  32. package/dist/public-events.js +1 -0
  33. package/dist/public-events.js.map +1 -1
  34. package/dist/tts/elements.d.ts +28 -0
  35. package/dist/tts/elements.js +14 -0
  36. package/dist/tts/elements.js.map +1 -0
  37. package/dist/{components/test-item-to-speech → tts}/test-item-to-speech.d.ts +9 -9
  38. package/dist/{components/test-item-to-speech → tts}/test-item-to-speech.js +59 -85
  39. package/dist/tts/test-item-to-speech.js.map +1 -0
  40. package/dist/types/qti-test-state.d.ts +12 -1
  41. package/dist/types/qti-test-state.js.map +1 -1
  42. package/package.json +11 -7
  43. package/dist/components/test-item-to-speech/test-item-to-speech.js.map +0 -1
  44. package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.d.ts +0 -19
  45. package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js +0 -39
  46. package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js.map +0 -1
  47. package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.d.ts +0 -19
  48. package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js +0 -39
  49. package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js.map +0 -1
@@ -26,6 +26,7 @@ const toState = (test, session) => ({
26
26
  outcomes: (test?.testOutcomeVariables ?? []).map(v => ({ identifier: v.identifier, value: copy(v.value) }))
27
27
  },
28
28
  session: {
29
+ ...(session?.plugins && Object.keys(session.plugins).length > 0 ? { plugins: { ...session.plugins } } : {}),
29
30
  ...(session?.navPartId !== undefined ? { navPartId: session.navPartId } : {}),
30
31
  ...(session?.navSectionId !== undefined ? { navSectionId: session.navSectionId } : {}),
31
32
  ...(session?.navItemRefId !== undefined ? { navItemRefId: session.navItemRefId } : {})
@@ -56,6 +57,7 @@ export const TestStateMixin = (superClass) => {
56
57
  this.#ready = false;
57
58
  this.#lastEmitted = null;
58
59
  });
60
+ listenPublic(this, 'cito-test-update-plugin-state', ({ detail }) => this.#updatePluginState(detail));
59
61
  listenPublic(this, 'cito-test-loaded', () => {
60
62
  if (this.#pending) {
61
63
  this.#apply(this.#pending);
@@ -64,6 +66,23 @@ export const TestStateMixin = (superClass) => {
64
66
  this.#ready = true;
65
67
  });
66
68
  }
69
+ /** One plugin's entry, as JSON: the test stores it without reading it. `null` removes it. */
70
+ #updatePluginState({ plugin, value }) {
71
+ if (typeof plugin !== 'string' || plugin === '')
72
+ return;
73
+ const { [plugin]: _removed, ...others } = this.sessionContext.plugins ?? {};
74
+ let next = others;
75
+ if (value !== null && value !== undefined) {
76
+ try {
77
+ next = { ...others, [plugin]: JSON.parse(JSON.stringify(value)) };
78
+ }
79
+ catch {
80
+ console.warn(`[qti-test] Ignoring plugin state for "${plugin}": it is not JSON.`);
81
+ return;
82
+ }
83
+ }
84
+ this.sessionContext = { ...this.sessionContext, plugins: next };
85
+ }
67
86
  get state() {
68
87
  return toState(this.testContext, this.sessionContext);
69
88
  }
@@ -109,7 +128,12 @@ export const TestStateMixin = (superClass) => {
109
128
  };
110
129
  // Written before any navigation request, so the linear-mode restriction — which compares
111
130
  // against the current position — sees the restored item as current and lets it load.
112
- this.sessionContext = { ...this.sessionContext, ...this.#validSession(state.session) };
131
+ // Plugins are replaced, not merged: a state without them clears what an earlier one left.
132
+ this.sessionContext = {
133
+ ...this.sessionContext,
134
+ ...this.#validSession(state.session),
135
+ plugins: state.session.plugins && typeof state.session.plugins === 'object' ? { ...state.session.plugins } : {}
136
+ };
113
137
  }
114
138
  /** A stored position may point at an item or section a revised test no longer has. */
115
139
  #validSession(session) {
@@ -1 +1 @@
1
- {"version":3,"file":"test-state.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-state.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAgChE,MAAM,IAAI,GAAG,CAAC,KAAkC,EAAS,EAAE,CACzD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAE,KAAmC,IAAI,IAAI,CAAC,CAAC;AAErF,MAAM,cAAc,GAAG,CAAC,KAAc,EAAyB,EAAE;IAC/D,MAAM,KAAK,GAAG,KAA4B,CAA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,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACzF,CAAC;QAED,sFAAsF;QACtF,aAAa,CAAC,OAA4B;YACxC,MAAM,MAAM,GAAG,CAAC,QAAgB,EAAE,EAA6B,EAAE,EAAE,CACjE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,QAAQ,gBAAgB,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YAC5F,OAAO;gBACL,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvF,GAAG,CAAC,MAAM,CAAC,wBAAwB,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzG,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,OAAO,CAAC,YAAY,CAAC;oBACzE,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE;oBACxC,CAAC,CAAC,EAAE,CAAC;aACR,CAAC;QACJ,CAAC;QAED,kBAAkB,CAAC,IAAwB,EAAE,EAAU;YACrD,cAAc,CAAC,IAAI,EAAE,oBAAoB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAC3D,CAAC;KACF;IAED,OAAO,cAAkD,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\nimport { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { PropertyValues } from 'lit';\nimport type { SessionContext, TestContext } from '@qti-components/base';\nimport type { QtiTestState, QtiTestStateSession } from '../types/qti-test-state';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\ntype Value = string | string[] | null;\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'qti-state-changed': CustomEvent<QtiTestState>;\n }\n}\n\nexport interface ITestStateMixin {\n /**\n * The candidate's persistable state: what they answered and where they are.\n *\n * Assign a stored state to resume. It may be assigned at any time: before the test document\n * has loaded it is held and applied as soon as the test connects — before the first item\n * loads, so items and the initial navigation start from it — and after that it is applied\n * immediately and the test navigates to the restored position.\n *\n * Items are matched by item-ref identifier; items the state does not mention start fresh, and\n * stored items, test outcomes or a position the test no longer has are ignored. Restoring is a\n * resume, so linear-mode navigation restrictions do not apply.\n */\n state: QtiTestState;\n}\n\nconst copy = (value: Readonly<Value> | undefined): Value =>\n Array.isArray(value) ? [...value] : ((value as string | null | undefined) ?? null);\n\nconst isQtiTestState = (value: unknown): value is QtiTestState => {\n const state = value as QtiTestState | null;\n return (\n state?.version === QTI_TEST_STATE_VERSION &&\n Array.isArray(state.test?.items) &&\n Array.isArray(state.test?.outcomes) &&\n typeof state.session === 'object' &&\n state.session !== null\n );\n};\n\nconst toState = (test: Readonly<TestContext>, session: Readonly<SessionContext>): QtiTestState => ({\n version: QTI_TEST_STATE_VERSION,\n test: {\n items: (test?.items ?? [])\n .filter(item => item.identifier)\n .map(item => ({\n identifier: item.identifier,\n variables: (item.variables ?? []).map(v => ({\n identifier: v.identifier,\n ...(v.type ? { type: v.type } : {}),\n value: copy(v.value)\n })),\n ...(item.state ? { state: { ...item.state } } : {})\n })),\n outcomes: (test?.testOutcomeVariables ?? []).map(v => ({ identifier: v.identifier, value: copy(v.value) }))\n },\n session: {\n ...(session?.navPartId !== undefined ? { navPartId: session.navPartId } : {}),\n ...(session?.navSectionId !== undefined ? { navSectionId: session.navSectionId } : {}),\n ...(session?.navItemRefId !== undefined ? { navItemRefId: session.navItemRefId } : {})\n }\n});\n\n/**\n * Persist and resume a test session through one value, `state`, and one event,\n * `qti-state-changed`.\n *\n * Sits directly on top of `TestBaseMixin`, so its `qti-assessment-test-connected` listener runs\n * after the base has built `testContext.items` from the item-refs, and before the navigation\n * mixin's listener picks the first item to load.\n */\nexport const TestStateMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestStateClass extends superClass implements ITestStateMixin {\n /** A state assigned before the test connected, applied when it does. */\n #pending: QtiTestState | null = null;\n\n /**\n * False while a test document is loading. Loading resets both contexts and rebuilds them, so\n * the intermediate states are empty — emitting one would invite a host to save it over the\n * real one.\n */\n #ready = false;\n\n #lastEmitted: string | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-testdoc-loaded', () => {\n this.#ready = false;\n this.#lastEmitted = null;\n });\n listenPublic(this, 'cito-test-loaded', () => {\n if (this.#pending) {\n this.#apply(this.#pending);\n this.#pending = null;\n }\n this.#ready = true;\n });\n }\n\n get state(): QtiTestState {\n return toState(this.testContext, this.sessionContext);\n }\n\n set state(value: QtiTestState) {\n if (!isQtiTestState(value)) {\n console.warn(`[qti-test] Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`);\n return;\n }\n if (!this.#ready) {\n this.#pending = value;\n return;\n }\n\n const { navItemRefId, navSectionId } = this.sessionContext;\n this.#apply(value);\n\n const restored = this.sessionContext;\n if (restored.navItemRefId && restored.navItemRefId !== navItemRefId) {\n this.#requestNavigation('item', restored.navItemRefId);\n } else if (!restored.navItemRefId && restored.navSectionId && restored.navSectionId !== navSectionId) {\n this.#requestNavigation('section', restored.navSectionId);\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (!this.#ready || !(changed.has('testContext') || changed.has('sessionContext'))) return;\n\n const state = this.state;\n const serialized = JSON.stringify(state);\n if (serialized === this.#lastEmitted) return;\n this.#lastEmitted = serialized;\n dispatchPublic(this, 'cito-test-state-changed', state);\n }\n\n #apply(state: QtiTestState): void {\n // Before the items load this only fills the test context; items already on screen are\n // updated too.\n for (const saved of state.test.items) this.updateItemVariables(saved.identifier, saved.variables, saved.state);\n\n const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v =>\n savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v\n )\n };\n\n // Written before any navigation request, so the linear-mode restriction — which compares\n // against the current position — sees the restored item as current and lets it load.\n this.sessionContext = { ...this.sessionContext, ...this.#validSession(state.session) };\n }\n\n /** A stored position may point at an item or section a revised test no longer has. */\n #validSession(session: QtiTestStateSession): QtiTestStateSession {\n const exists = (selector: string, id: string | null | undefined) =>\n !!id && !!this._testElement?.querySelector(`${selector}[identifier=\"${CSS.escape(id)}\"]`);\n return {\n ...(exists('qti-test-part', session.navPartId) ? { navPartId: session.navPartId } : {}),\n ...(exists('qti-assessment-section', session.navSectionId) ? { navSectionId: session.navSectionId } : {}),\n ...(this.testContext.items.some(i => i.identifier === session.navItemRefId)\n ? { navItemRefId: session.navItemRefId }\n : {})\n };\n }\n\n #requestNavigation(type: 'item' | 'section', id: string): void {\n dispatchPublic(this, 'cito-test-navigate', { type, id });\n }\n }\n\n return TestStateClass as Constructor<ITestStateMixin> & T;\n};\n"]}
1
+ {"version":3,"file":"test-state.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-state.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAgChE,MAAM,IAAI,GAAG,CAAC,KAAkC,EAAS,EAAE,CACzD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAE,KAAmC,IA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E,oBAAoB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAC3D,CAAC;KACF;IAED,OAAO,cAAkD,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\nimport { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { PropertyValues } from 'lit';\nimport type { SessionContext, TestContext } from '@qti-components/base';\nimport type { QtiTestState, QtiTestStateSession } from '../types/qti-test-state';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\ntype Value = string | string[] | null;\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'qti-state-changed': CustomEvent<QtiTestState>;\n }\n}\n\nexport interface ITestStateMixin {\n /**\n * The candidate's persistable state: what they answered and where they are.\n *\n * Assign a stored state to resume. It may be assigned at any time: before the test document\n * has loaded it is held and applied as soon as the test connects — before the first item\n * loads, so items and the initial navigation start from it — and after that it is applied\n * immediately and the test navigates to the restored position.\n *\n * Items are matched by item-ref identifier; items the state does not mention start fresh, and\n * stored items, test outcomes or a position the test no longer has are ignored. Restoring is a\n * resume, so linear-mode navigation restrictions do not apply.\n */\n state: QtiTestState;\n}\n\nconst copy = (value: Readonly<Value> | undefined): Value =>\n Array.isArray(value) ? [...value] : ((value as string | null | undefined) ?? null);\n\nconst isQtiTestState = (value: unknown): value is QtiTestState => {\n const state = value as QtiTestState | null;\n return (\n state?.version === QTI_TEST_STATE_VERSION &&\n Array.isArray(state.test?.items) &&\n Array.isArray(state.test?.outcomes) &&\n typeof state.session === 'object' &&\n state.session !== null\n );\n};\n\nconst toState = (test: Readonly<TestContext>, session: Readonly<SessionContext>): QtiTestState => ({\n version: QTI_TEST_STATE_VERSION,\n test: {\n items: (test?.items ?? [])\n .filter(item => item.identifier)\n .map(item => ({\n identifier: item.identifier,\n variables: (item.variables ?? []).map(v => ({\n identifier: v.identifier,\n ...(v.type ? { type: v.type } : {}),\n value: copy(v.value)\n })),\n ...(item.state ? { state: { ...item.state } } : {})\n })),\n outcomes: (test?.testOutcomeVariables ?? []).map(v => ({ identifier: v.identifier, value: copy(v.value) }))\n },\n session: {\n ...(session?.plugins && Object.keys(session.plugins).length > 0 ? { plugins: { ...session.plugins } } : {}),\n ...(session?.navPartId !== undefined ? { navPartId: session.navPartId } : {}),\n ...(session?.navSectionId !== undefined ? { navSectionId: session.navSectionId } : {}),\n ...(session?.navItemRefId !== undefined ? { navItemRefId: session.navItemRefId } : {})\n }\n});\n\n/**\n * Persist and resume a test session through one value, `state`, and one event,\n * `qti-state-changed`.\n *\n * Sits directly on top of `TestBaseMixin`, so its `qti-assessment-test-connected` listener runs\n * after the base has built `testContext.items` from the item-refs, and before the navigation\n * mixin's listener picks the first item to load.\n */\nexport const TestStateMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestStateClass extends superClass implements ITestStateMixin {\n /** A state assigned before the test connected, applied when it does. */\n #pending: QtiTestState | null = null;\n\n /**\n * False while a test document is loading. Loading resets both contexts and rebuilds them, so\n * the intermediate states are empty — emitting one would invite a host to save it over the\n * real one.\n */\n #ready = false;\n\n #lastEmitted: string | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-testdoc-loaded', () => {\n this.#ready = false;\n this.#lastEmitted = null;\n });\n listenPublic(this, 'cito-test-update-plugin-state', ({ detail }) => this.#updatePluginState(detail));\n listenPublic(this, 'cito-test-loaded', () => {\n if (this.#pending) {\n this.#apply(this.#pending);\n this.#pending = null;\n }\n this.#ready = true;\n });\n }\n\n /** One plugin's entry, as JSON: the test stores it without reading it. `null` removes it. */\n #updatePluginState({ plugin, value }: { plugin: string; value: unknown }): void {\n if (typeof plugin !== 'string' || plugin === '') return;\n const { [plugin]: _removed, ...others } = this.sessionContext.plugins ?? {};\n let next: Record<string, unknown> = others;\n if (value !== null && value !== undefined) {\n try {\n next = { ...others, [plugin]: JSON.parse(JSON.stringify(value)) };\n } catch {\n console.warn(`[qti-test] Ignoring plugin state for \"${plugin}\": it is not JSON.`);\n return;\n }\n }\n this.sessionContext = { ...this.sessionContext, plugins: next };\n }\n\n get state(): QtiTestState {\n return toState(this.testContext, this.sessionContext);\n }\n\n set state(value: QtiTestState) {\n if (!isQtiTestState(value)) {\n console.warn(`[qti-test] Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`);\n return;\n }\n if (!this.#ready) {\n this.#pending = value;\n return;\n }\n\n const { navItemRefId, navSectionId } = this.sessionContext;\n this.#apply(value);\n\n const restored = this.sessionContext;\n if (restored.navItemRefId && restored.navItemRefId !== navItemRefId) {\n this.#requestNavigation('item', restored.navItemRefId);\n } else if (!restored.navItemRefId && restored.navSectionId && restored.navSectionId !== navSectionId) {\n this.#requestNavigation('section', restored.navSectionId);\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (!this.#ready || !(changed.has('testContext') || changed.has('sessionContext'))) return;\n\n const state = this.state;\n const serialized = JSON.stringify(state);\n if (serialized === this.#lastEmitted) return;\n this.#lastEmitted = serialized;\n dispatchPublic(this, 'cito-test-state-changed', state);\n }\n\n #apply(state: QtiTestState): void {\n // Before the items load this only fills the test context; items already on screen are\n // updated too.\n for (const saved of state.test.items) this.updateItemVariables(saved.identifier, saved.variables, saved.state);\n\n const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v =>\n savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v\n )\n };\n\n // Written before any navigation request, so the linear-mode restriction — which compares\n // against the current position — sees the restored item as current and lets it load.\n // Plugins are replaced, not merged: a state without them clears what an earlier one left.\n this.sessionContext = {\n ...this.sessionContext,\n ...this.#validSession(state.session),\n plugins: state.session.plugins && typeof state.session.plugins === 'object' ? { ...state.session.plugins } : {}\n };\n }\n\n /** A stored position may point at an item or section a revised test no longer has. */\n #validSession(session: QtiTestStateSession): QtiTestStateSession {\n const exists = (selector: string, id: string | null | undefined) =>\n !!id && !!this._testElement?.querySelector(`${selector}[identifier=\"${CSS.escape(id)}\"]`);\n return {\n ...(exists('qti-test-part', session.navPartId) ? { navPartId: session.navPartId } : {}),\n ...(exists('qti-assessment-section', session.navSectionId) ? { navSectionId: session.navSectionId } : {}),\n ...(this.testContext.items.some(i => i.identifier === session.navItemRefId)\n ? { navItemRefId: session.navItemRefId }\n : {})\n };\n }\n\n #requestNavigation(type: 'item' | 'section', id: string): void {\n dispatchPublic(this, 'cito-test-navigate', { type, id });\n }\n }\n\n return TestStateClass as Constructor<ITestStateMixin> & T;\n};\n"]}
@@ -0,0 +1,8 @@
1
+ import type { ComputedContext } from '@qti-components/base';
2
+ import type { QtiTestPluginState } from './types/qti-test-state';
3
+ /**
4
+ * A plugin's entry in the state, typed through `QtiTestPluginState`, or `undefined` before the
5
+ * plugin has stored anything. Read it from `computedContext`; write it by dispatching
6
+ * `cito-test-update-plugin-state` (`dispatchPublic`).
7
+ */
8
+ export declare const pluginState: <K extends keyof QtiTestPluginState & string>(context: Pick<ComputedContext, "plugins"> | undefined, plugin: K) => QtiTestPluginState[K] | undefined;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A plugin's entry in the state, typed through `QtiTestPluginState`, or `undefined` before the
3
+ * plugin has stored anything. Read it from `computedContext`; write it by dispatching
4
+ * `cito-test-update-plugin-state` (`dispatchPublic`).
5
+ */
6
+ export const pluginState = (context, plugin) => context?.plugins?.[plugin];
7
+ //# sourceMappingURL=plugin-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-state.js","sourceRoot":"","sources":["../src/plugin-state.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,OAAqD,EACrD,MAAS,EAC0B,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,CAAsC,CAAC","sourcesContent":["import type { ComputedContext } from '@qti-components/base';\nimport type { QtiTestPluginState } from './types/qti-test-state';\n\n/**\n * A plugin's entry in the state, typed through `QtiTestPluginState`, or `undefined` before the\n * plugin has stored anything. Read it from `computedContext`; write it by dispatching\n * `cito-test-update-plugin-state` (`dispatchPublic`).\n */\nexport const pluginState = <K extends keyof QtiTestPluginState & string>(\n context: Pick<ComputedContext, 'plugins'> | undefined,\n plugin: K\n): QtiTestPluginState[K] | undefined => context?.plugins?.[plugin] as QtiTestPluginState[K] | undefined;\n"]}
@@ -0,0 +1,71 @@
1
+ import { TestBookmark } from '../components/test-bookmark/test-bookmark';
2
+ import { TestCheckItem } from '../components/test-check-item/test-check-item';
3
+ import { TestPrintContext } from '../components/test-print-context/test-print-context';
4
+ import { TestPrintVariables } from '../components/test-print-item-variables/test-print-item-variables';
5
+ import { TestScoringButtons } from '../components/test-scoring-buttons/test-scoring-buttons';
6
+ import { TestScoringFeedback } from '../components/test-scoring-feedback/test-scoring-feedback';
7
+ import { TestStamp } from '../components/test-stamp/test-stamp';
8
+ import { TestView } from '../components/test-view-toggle/test-view';
9
+ import { TestViewToggle } from '../components/test-view-toggle/test-view-toggle';
10
+ export * from '../tts/elements';
11
+ export { bookmarkedItems } from '../components/test-bookmark/test-bookmark';
12
+ export { TestCheckItem, TestBookmark, TestPrintContext, TestPrintVariables, TestScoringButtons, TestScoringFeedback, TestStamp, TestView, TestViewToggle };
13
+ /**
14
+ * Every test plugin's elements in one list. `qti-test` registers them with the rest of its
15
+ * elements, and a scoped registry can use the list directly. Defines nothing.
16
+ *
17
+ * A plugin is the set of files listed for it in `plugin-boundary.spec.ts` (`PLUGINS`); this file is
18
+ * the one place that names them all.
19
+ */
20
+ export declare const pluginElements: readonly [{
21
+ readonly tag: "test-check-item";
22
+ readonly ctor: typeof TestCheckItem;
23
+ }, {
24
+ readonly tag: "test-bookmark";
25
+ readonly ctor: typeof TestBookmark;
26
+ }, {
27
+ readonly tag: "test-print-context";
28
+ readonly ctor: typeof TestPrintContext;
29
+ }, {
30
+ readonly tag: "test-print-item-variables";
31
+ readonly ctor: typeof TestPrintVariables;
32
+ }, {
33
+ readonly tag: "test-scoring-buttons";
34
+ readonly ctor: typeof TestScoringButtons;
35
+ }, {
36
+ readonly tag: "test-scoring-feedback";
37
+ readonly ctor: typeof TestScoringFeedback;
38
+ }, {
39
+ readonly tag: "test-stamp";
40
+ readonly ctor: typeof TestStamp;
41
+ }, {
42
+ readonly tag: "test-view";
43
+ readonly ctor: typeof TestView;
44
+ }, {
45
+ readonly tag: "test-view-toggle";
46
+ readonly ctor: typeof TestViewToggle;
47
+ }, {
48
+ readonly tag: "test-item-to-speech";
49
+ readonly ctor: typeof import("./elements").TestItemToSpeech;
50
+ }, {
51
+ readonly tag: "test-tts-next";
52
+ readonly ctor: typeof import("./elements").TestTtsNext;
53
+ }, {
54
+ readonly tag: "test-tts-pause";
55
+ readonly ctor: typeof import("./elements").TestTtsPause;
56
+ }, {
57
+ readonly tag: "test-tts-pick";
58
+ readonly ctor: typeof import("./elements").TestTtsPick;
59
+ }, {
60
+ readonly tag: "test-tts-play";
61
+ readonly ctor: typeof import("./elements").TestTtsPlay;
62
+ }, {
63
+ readonly tag: "test-tts-prev";
64
+ readonly ctor: typeof import("./elements").TestTtsPrev;
65
+ }, {
66
+ readonly tag: "test-tts-resume";
67
+ readonly ctor: typeof import("./elements").TestTtsResume;
68
+ }, {
69
+ readonly tag: "test-tts-stop";
70
+ readonly ctor: typeof import("./elements").TestTtsStop;
71
+ }];
@@ -0,0 +1,33 @@
1
+ import { TestBookmark } from '../components/test-bookmark/test-bookmark';
2
+ import { TestCheckItem } from '../components/test-check-item/test-check-item';
3
+ import { TestPrintContext } from '../components/test-print-context/test-print-context';
4
+ import { TestPrintVariables } from '../components/test-print-item-variables/test-print-item-variables';
5
+ import { TestScoringButtons } from '../components/test-scoring-buttons/test-scoring-buttons';
6
+ import { TestScoringFeedback } from '../components/test-scoring-feedback/test-scoring-feedback';
7
+ import { TestStamp } from '../components/test-stamp/test-stamp';
8
+ import { TestView } from '../components/test-view-toggle/test-view';
9
+ import { TestViewToggle } from '../components/test-view-toggle/test-view-toggle';
10
+ import { ttsElements } from '../tts/elements';
11
+ export * from '../tts/elements';
12
+ export { bookmarkedItems } from '../components/test-bookmark/test-bookmark';
13
+ export { TestCheckItem, TestBookmark, TestPrintContext, TestPrintVariables, TestScoringButtons, TestScoringFeedback, TestStamp, TestView, TestViewToggle };
14
+ /**
15
+ * Every test plugin's elements in one list. `qti-test` registers them with the rest of its
16
+ * elements, and a scoped registry can use the list directly. Defines nothing.
17
+ *
18
+ * A plugin is the set of files listed for it in `plugin-boundary.spec.ts` (`PLUGINS`); this file is
19
+ * the one place that names them all.
20
+ */
21
+ export const pluginElements = [
22
+ { tag: 'test-check-item', ctor: TestCheckItem },
23
+ { tag: 'test-bookmark', ctor: TestBookmark },
24
+ { tag: 'test-print-context', ctor: TestPrintContext },
25
+ { tag: 'test-print-item-variables', ctor: TestPrintVariables },
26
+ { tag: 'test-scoring-buttons', ctor: TestScoringButtons },
27
+ { tag: 'test-scoring-feedback', ctor: TestScoringFeedback },
28
+ { tag: 'test-stamp', ctor: TestStamp },
29
+ { tag: 'test-view', ctor: TestView },
30
+ { tag: 'test-view-toggle', ctor: TestViewToggle },
31
+ ...ttsElements
32
+ ];
33
+ //# sourceMappingURL=elements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements.js","sourceRoot":"","sources":["../../src/plugins/elements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mEAAmE,CAAC;AACvG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yDAAyD,CAAC;AAC7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2DAA2D,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,iDAAiD,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAE5E,OAAO,EACL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,QAAQ,EACR,cAAc,EACf,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,aAAa,EAAE;IAC/C,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,YAAY,EAAE;IAC5C,EAAE,GAAG,EAAE,oBAAoB,EAAE,IAAI,EAAE,gBAAgB,EAAE;IACrD,EAAE,GAAG,EAAE,2BAA2B,EAAE,IAAI,EAAE,kBAAkB,EAAE;IAC9D,EAAE,GAAG,EAAE,sBAAsB,EAAE,IAAI,EAAE,kBAAkB,EAAE;IACzD,EAAE,GAAG,EAAE,uBAAuB,EAAE,IAAI,EAAE,mBAAmB,EAAE;IAC3D,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE;IACtC,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;IACpC,EAAE,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,cAAc,EAAE;IACjD,GAAG,WAAW;CACN,CAAC","sourcesContent":["import { TestBookmark } from '../components/test-bookmark/test-bookmark';\nimport { TestCheckItem } from '../components/test-check-item/test-check-item';\nimport { TestPrintContext } from '../components/test-print-context/test-print-context';\nimport { TestPrintVariables } from '../components/test-print-item-variables/test-print-item-variables';\nimport { TestScoringButtons } from '../components/test-scoring-buttons/test-scoring-buttons';\nimport { TestScoringFeedback } from '../components/test-scoring-feedback/test-scoring-feedback';\nimport { TestStamp } from '../components/test-stamp/test-stamp';\nimport { TestView } from '../components/test-view-toggle/test-view';\nimport { TestViewToggle } from '../components/test-view-toggle/test-view-toggle';\nimport { ttsElements } from '../tts/elements';\n\nexport * from '../tts/elements';\n\nexport { bookmarkedItems } from '../components/test-bookmark/test-bookmark';\n\nexport {\n TestCheckItem,\n TestBookmark,\n TestPrintContext,\n TestPrintVariables,\n TestScoringButtons,\n TestScoringFeedback,\n TestStamp,\n TestView,\n TestViewToggle\n};\n\n/**\n * Every test plugin's elements in one list. `qti-test` registers them with the rest of its\n * elements, and a scoped registry can use the list directly. Defines nothing.\n *\n * A plugin is the set of files listed for it in `plugin-boundary.spec.ts` (`PLUGINS`); this file is\n * the one place that names them all.\n */\nexport const pluginElements = [\n { tag: 'test-check-item', ctor: TestCheckItem },\n { tag: 'test-bookmark', ctor: TestBookmark },\n { tag: 'test-print-context', ctor: TestPrintContext },\n { tag: 'test-print-item-variables', ctor: TestPrintVariables },\n { tag: 'test-scoring-buttons', ctor: TestScoringButtons },\n { tag: 'test-scoring-feedback', ctor: TestScoringFeedback },\n { tag: 'test-stamp', ctor: TestStamp },\n { tag: 'test-view', ctor: TestView },\n { tag: 'test-view-toggle', ctor: TestViewToggle },\n ...ttsElements\n] as const;\n"]}
@@ -0,0 +1,2 @@
1
+ /** The test plugins: print, scoring, stamp, text-to-speech and view. The core composes them here and nowhere else. */
2
+ export * from './elements.js';
@@ -0,0 +1,3 @@
1
+ /** The test plugins: print, scoring, stamp, text-to-speech and view. The core composes them here and nowhere else. */
2
+ export * from './elements.js';
3
+ //# sourceMappingURL=index.js.map
@@ -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"]}
@@ -30,6 +30,11 @@ export interface PublicEventMap {
30
30
  value: number | string;
31
31
  }>;
32
32
  'cito-test-switch-view': CustomEvent<View>;
33
+ /** `value` is JSON; `null` or `undefined` removes the plugin's entry. */
34
+ 'cito-test-update-plugin-state': CustomEvent<{
35
+ plugin: string;
36
+ value: unknown;
37
+ }>;
33
38
  'cito-test-navigated': CustomEvent<NavigationTarget>;
34
39
  'cito-test-navigation-started': CustomEvent<NavigationTarget>;
35
40
  'cito-test-navigation-failed': CustomEvent<NavigationFailure>;
@@ -3,6 +3,7 @@ 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
5
  'cito-test-update-outcome': { kind: 'request', scope: 'test', deprecated: 'test-update-outcome-variable' },
6
+ 'cito-test-update-plugin-state': { kind: 'request', scope: 'test' },
6
7
  'cito-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'on-test-switch-view' },
7
8
  'cito-test-navigated': { kind: 'notification', scope: 'test' },
8
9
  'cito-test-navigation-started': {
@@ -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;AAmD1F,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,0BAA0B,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,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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 'cito-test-update-outcome': CustomEvent<{\n assessmentItemRefId: string;\n outcomeVariableId: string;\n value: number | string;\n }>;\n 'cito-test-switch-view': CustomEvent<View>;\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-update-outcome': { kind: 'request', scope: 'test', deprecated: 'test-update-outcome-variable' },\n 'cito-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'on-test-switch-view' },\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"]}
1
+ {"version":3,"file":"public-events.js","sourceRoot":"","sources":["../src/public-events.ts"],"names":[],"mappings":"AAAA,OAA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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 '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 '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-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-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 { SessionContext } from '@qti-components/base';
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** — a toolbar in the page chrome: the player follows the navigation cursor
96
- * and reads the item `navItemRefId` (session context) points at, found in any
97
- * `test-container` reachable from the player. Navigating stops speech and starts the next
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
- protected _sessionContext?: SessionContext;
155
- /** The `qti-test` this player is in, across shadow roots. */
156
- protected testHost?: TestHost;
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;