@citolab/qti-components 9.3.0 → 10.0.0-next.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 (64) hide show
  1. package/cdn/index.global.js +1 -1
  2. package/cdn/index.js +258 -206
  3. package/dist/base.d.ts +10 -10
  4. package/dist/base.js +1 -1
  5. package/dist/{chunk-G5RQ5GKG.js → chunk-3BAQWO5C.js} +2 -2
  6. package/dist/{chunk-ZG7FBQFP.js → chunk-ACRN7YJM.js} +2 -2
  7. package/dist/{chunk-REKCRWJV.js → chunk-AWTQKBC4.js} +231 -129
  8. package/dist/chunk-AWTQKBC4.js.map +1 -0
  9. package/dist/{chunk-JGPWBIVD.js → chunk-CNFVA3AA.js} +128 -48
  10. package/dist/chunk-CNFVA3AA.js.map +1 -0
  11. package/dist/{chunk-CQHGVPOT.js → chunk-EPSUZIWL.js} +6 -6
  12. package/dist/{chunk-TDWLV5OD.js → chunk-EUKU5QKV.js} +633 -352
  13. package/dist/chunk-EUKU5QKV.js.map +1 -0
  14. package/dist/{chunk-RAJQKCQ3.js → chunk-F7R7GSWL.js} +3 -3
  15. package/dist/{chunk-FG5JAWSN.js → chunk-GPNWMLLA.js} +2 -2
  16. package/dist/{chunk-7VDR765S.js → chunk-QD3Y6UK3.js} +2 -2
  17. package/dist/{chunk-YVZWNLF4.js → chunk-R7MMMDP7.js} +139 -18
  18. package/dist/chunk-R7MMMDP7.js.map +1 -0
  19. package/dist/{chunk-JLZCZVRX.js → chunk-SVYHZIJ7.js} +2 -2
  20. package/dist/{chunk-YIYHCHHM.js → chunk-WNAOVXXN.js} +2 -2
  21. package/dist/chunk-ZP6QQYSU.js +7 -0
  22. package/dist/chunk-ZP6QQYSU.js.map +1 -0
  23. package/dist/{computed.types.d-DB5gfOh9.d.ts → computed.types.d-gJrBeUMG.d.ts} +1 -1
  24. package/dist/corrections.d.ts +9 -9
  25. package/dist/corrections.js +8 -8
  26. package/dist/elements.d.ts +108 -6
  27. package/dist/elements.js +17 -5
  28. package/dist/index.d.ts +12 -12
  29. package/dist/index.js +28 -14
  30. package/dist/{interaction.d-DegNJ5ZA.d.ts → interaction.d-g6XG0T0Z.d.ts} +2 -2
  31. package/dist/interactions.d.ts +4 -4
  32. package/dist/interactions.js +3 -3
  33. package/dist/item.css +11 -0
  34. package/dist/item.d.ts +4 -4
  35. package/dist/item.js +4 -4
  36. package/dist/{item.types.d-BDFrq19E.d.ts → item.types.d-B55QkJ92.d.ts} +10 -0
  37. package/dist/loader.d.ts +2 -2
  38. package/dist/processing.d.ts +3 -3
  39. package/dist/processing.js +3 -3
  40. package/dist/qti-components-jsx.d.ts +354 -440
  41. package/dist/{qti-condition-expression.d-DLboq8bR.d.ts → qti-condition-expression.d-L7yb3Rzy.d.ts} +1 -1
  42. package/dist/{qti-expression.d-BksT9iLB.d.ts → qti-expression.d-CuaLjZ6g.d.ts} +1 -1
  43. package/dist/{qti-feedback.d-D-w6-mJv.d.ts → qti-feedback.d-wMYNVkkj.d.ts} +2 -3
  44. package/dist/{qti-item.d-D_-9_0e6.d.ts → qti-item.d-DgC1AQbY.d.ts} +1 -1
  45. package/dist/{qti-test.d-D-ELy0Mr.d.ts → qti-test.d-_THYXPzd.d.ts} +206 -46
  46. package/dist/{qti-text-entry-interaction.d-CATtcPyX.d.ts → qti-text-entry-interaction.d-q8u5BiVK.d.ts} +13 -4
  47. package/dist/{session.context.d-Cjs0BkJB.d.ts → session.context.d-D5080LVx.d.ts} +3 -1
  48. package/dist/test.d.ts +58 -11
  49. package/dist/test.js +7 -5
  50. package/package.json +9 -9
  51. package/dist/chunk-A32YH4H5.js +0 -7
  52. package/dist/chunk-A32YH4H5.js.map +0 -1
  53. package/dist/chunk-JGPWBIVD.js.map +0 -1
  54. package/dist/chunk-REKCRWJV.js.map +0 -1
  55. package/dist/chunk-TDWLV5OD.js.map +0 -1
  56. package/dist/chunk-YVZWNLF4.js.map +0 -1
  57. /package/dist/{chunk-G5RQ5GKG.js.map → chunk-3BAQWO5C.js.map} +0 -0
  58. /package/dist/{chunk-ZG7FBQFP.js.map → chunk-ACRN7YJM.js.map} +0 -0
  59. /package/dist/{chunk-CQHGVPOT.js.map → chunk-EPSUZIWL.js.map} +0 -0
  60. /package/dist/{chunk-RAJQKCQ3.js.map → chunk-F7R7GSWL.js.map} +0 -0
  61. /package/dist/{chunk-FG5JAWSN.js.map → chunk-GPNWMLLA.js.map} +0 -0
  62. /package/dist/{chunk-7VDR765S.js.map → chunk-QD3Y6UK3.js.map} +0 -0
  63. /package/dist/{chunk-JLZCZVRX.js.map → chunk-SVYHZIJ7.js.map} +0 -0
  64. /package/dist/{chunk-YIYHCHHM.js.map → chunk-WNAOVXXN.js.map} +0 -0
@@ -1,9 +1,12 @@
1
1
  import {
2
- QtiModalFeedback
3
- } from "./chunk-REKCRWJV.js";
2
+ QtiModalFeedback,
3
+ dispatchDeclared,
4
+ listenDeclared,
5
+ listenPublic
6
+ } from "./chunk-AWTQKBC4.js";
4
7
  import {
5
8
  item_css_default
6
- } from "./chunk-A32YH4H5.js";
9
+ } from "./chunk-ZP6QQYSU.js";
7
10
  import {
8
11
  watch
9
12
  } from "./chunk-4DB4SC5K.js";
@@ -21,7 +24,7 @@ import {
21
24
  qtiContext,
22
25
  sessionContext,
23
26
  testContext
24
- } from "./chunk-YVZWNLF4.js";
27
+ } from "./chunk-R7MMMDP7.js";
25
28
 
26
29
  // ../qti-test/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js
27
30
  import { LitElement, nothing as nothing2 } from "lit";
@@ -1096,6 +1099,35 @@ var makeLitTemplate = (template) => {
1096
1099
  return litTemplate;
1097
1100
  };
1098
1101
 
1102
+ // ../qti-test/dist/internal/test-host.context.js
1103
+ import { createContext } from "@lit/context";
1104
+ var testHostContext = createContext(/* @__PURE__ */ Symbol("testHost"));
1105
+
1106
+ // ../qti-test/dist/public-events.js
1107
+ var PUBLIC_EVENTS = {
1108
+ "cito-test-navigate": { kind: "request", scope: "test", deprecated: "qti-request-navigation" },
1109
+ "cito-test-end-attempt": { kind: "request", scope: "test", deprecated: "test-end-attempt" },
1110
+ "cito-test-update-outcome": { kind: "request", scope: "test", deprecated: "test-update-outcome-variable" },
1111
+ "cito-test-switch-view": { kind: "request", scope: "test", deprecated: "on-test-switch-view" },
1112
+ "cito-test-navigated": { kind: "notification", scope: "test" },
1113
+ "cito-test-navigation-started": {
1114
+ kind: "notification",
1115
+ scope: "test",
1116
+ deprecated: "qti-navigation-loading-started"
1117
+ },
1118
+ "cito-test-navigation-failed": { kind: "notification", scope: "test", deprecated: "qti-navigation-error" },
1119
+ "cito-test-rendered": { kind: "notification", scope: "test", deprecated: "qti-test-loaded" },
1120
+ "cito-test-loaded": { kind: "notification", scope: "test", deprecated: "qti-assessment-test-connected" },
1121
+ "cito-test-state-changed": { kind: "notification", scope: "test", deprecated: "qti-state-changed" },
1122
+ "cito-item-ref-connected": { kind: "notification", scope: "item", deprecated: "qti-assessment-item-ref-connected" }
1123
+ };
1124
+ function dispatchPublic(target, name, detail) {
1125
+ dispatchDeclared(target, PUBLIC_EVENTS, name, detail);
1126
+ }
1127
+ function listenPublic2(target, name, handler) {
1128
+ listenDeclared(target, PUBLIC_EVENTS, name, handler);
1129
+ }
1130
+
1099
1131
  // ../qti-test/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js
1100
1132
  var __decorate = function(decorators, target, key, desc) {
1101
1133
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1147,39 +1179,21 @@ var QtiAssessmentItemRef = class extends LitElement {
1147
1179
  get assessmentItem() {
1148
1180
  return this.renderRoot?.querySelector("qti-assessment-item");
1149
1181
  }
1150
- /**
1151
- * The `<qti-test>` this ref belongs to, crossing shadow boundaries on the way
1152
- * up.
1153
- *
1154
- * `<test-container>` renders its items into a shadow root, so an item-ref is
1155
- * usually one hop below one; but it is also valid in plain light DOM, and a
1156
- * host is free to nest it deeper. Climbing root by root covers all three
1157
- * without assuming any of them.
1158
- */
1159
- #findTestElement() {
1160
- const own = this.closest("qti-test");
1161
- if (own)
1162
- return own;
1163
- let root = this.getRootNode();
1164
- while (root instanceof ShadowRoot) {
1165
- const test = root.host.closest("qti-test");
1166
- if (test)
1167
- return test;
1168
- root = root.host.getRootNode();
1169
- }
1170
- return null;
1182
+ disconnectedCallback() {
1183
+ super.disconnectedCallback();
1184
+ this.testHost = void 0;
1171
1185
  }
1172
1186
  async connectedCallback() {
1173
1187
  super.connectedCallback();
1174
- const templateElement = this.#findTestElement()?.querySelector("template[item-ref]");
1188
+ const templateElement = this.testHost?.querySelector("template[item-ref]");
1175
1189
  this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;
1176
1190
  this.requestUpdate();
1177
1191
  await this.updateComplete;
1178
- this.dispatchEvent(new CustomEvent("qti-assessment-item-ref-connected", {
1179
- bubbles: true,
1180
- composed: true,
1181
- detail: { identifier: this.identifier, href: this.href, category: this.category }
1182
- }));
1192
+ dispatchPublic(this, "cito-item-ref-connected", {
1193
+ identifier: this.identifier,
1194
+ href: this.href,
1195
+ category: this.category
1196
+ });
1183
1197
  }
1184
1198
  #computedItem() {
1185
1199
  for (const testPart of this.computedContext?.testParts ?? []) {
@@ -1247,6 +1261,9 @@ __decorate([
1247
1261
  __decorate([
1248
1262
  property({ type: Object, attribute: false })
1249
1263
  ], QtiAssessmentItemRef.prototype, "xmlDoc", void 0);
1264
+ __decorate([
1265
+ consume({ context: testHostContext, subscribe: true })
1266
+ ], QtiAssessmentItemRef.prototype, "testHost", void 0);
1250
1267
 
1251
1268
  // ../qti-test/dist/components/qti-assessment-section/qti-assessment-section.js
1252
1269
  import { consume as consume2 } from "@lit/context";
@@ -1337,11 +1354,7 @@ var QtiAssessmentTest = class extends LitElement3 {
1337
1354
  async connectedCallback() {
1338
1355
  super.connectedCallback();
1339
1356
  await this.updateComplete;
1340
- this.dispatchEvent(new CustomEvent("qti-assessment-test-connected", {
1341
- detail: this,
1342
- bubbles: true,
1343
- composed: true
1344
- }));
1357
+ dispatchPublic(this, "cito-test-loaded", this);
1345
1358
  }
1346
1359
  render() {
1347
1360
  return html2` <slot></slot>`;
@@ -1450,7 +1463,7 @@ var QtiNumberSelected = class extends QtiExpression {
1450
1463
  #connectedTest = null;
1451
1464
  constructor() {
1452
1465
  super();
1453
- this.addEventListener("qti-assessment-test-connected", (e) => this.#connectedTest = e.detail);
1466
+ listenPublic2(this, "cito-test-loaded", (e) => this.#connectedTest = e.detail);
1454
1467
  }
1455
1468
  /**
1456
1469
  * `qti-assessment-test-connected` bubbles *up* from the test element, and this
@@ -1587,7 +1600,7 @@ var QtiTestVariables = class extends QtiExpression {
1587
1600
  #connectedTest = null;
1588
1601
  constructor() {
1589
1602
  super();
1590
- this.addEventListener("qti-assessment-test-connected", (e) => this.#connectedTest = e.detail);
1603
+ listenPublic2(this, "cito-test-loaded", (e) => this.#connectedTest = e.detail);
1591
1604
  }
1592
1605
  /**
1593
1606
  * `qti-assessment-test-connected` bubbles *up* from the test element, and this
@@ -1647,8 +1660,11 @@ var QtiTestVariablesExpression = class {
1647
1660
  }
1648
1661
  };
1649
1662
 
1663
+ // ../qti-test/dist/types/qti-test-state.js
1664
+ var QTI_TEST_STATE_VERSION = 1;
1665
+
1650
1666
  // ../qti-test/dist/components/qti-test/qti-test.js
1651
- import { provide as provide2 } from "@lit/context";
1667
+ import { ContextProvider, provide as provide2 } from "@lit/context";
1652
1668
  import { html as html7, LitElement as LitElement8 } from "lit";
1653
1669
  import { state as state2 } from "lit/decorators.js";
1654
1670
 
@@ -1688,24 +1704,20 @@ var TestNavigationMixin = (superClass) => {
1688
1704
  /**
1689
1705
  * Navigate to a specific item or section
1690
1706
  * @param type - Navigation type ('item' or 'section')
1691
- * @param id - Target identifier (optional, falls back to first available)
1707
+ * @param id - Target identifier (optional, falls back to the current position, or the first one before there is any)
1692
1708
  */
1693
1709
  navigateTo(type, id) {
1694
1710
  const targetId = id || this._getDefaultNavigationId(type);
1695
1711
  if (targetId) {
1696
- this.dispatchEvent(new CustomEvent("qti-request-navigation", {
1697
- detail: { type, id: targetId },
1698
- bubbles: true,
1699
- composed: true
1700
- }));
1712
+ dispatchPublic(this, "cito-test-navigate", { type, id: targetId });
1701
1713
  }
1702
1714
  }
1703
1715
  // ===========================================
1704
1716
  // EVENT HANDLER SETUP
1705
1717
  // ===========================================
1706
1718
  _bindEventHandlers() {
1707
- this.addEventListener("qti-request-navigation", this._handleNavigationRequest.bind(this));
1708
- this.addEventListener("qti-assessment-test-connected", this._handleTestConnected.bind(this));
1719
+ listenPublic2(this, "cito-test-navigate", this._handleNavigationRequest.bind(this));
1720
+ listenPublic2(this, "cito-test-loaded", this._handleTestConnected.bind(this));
1709
1721
  this.addEventListener("qti-assessment-item-connected", this._handleItemConnected.bind(this));
1710
1722
  this.addEventListener("qti-assessment-stimulus-ref-connected", this._handleStimulusRefConnected.bind(this));
1711
1723
  }
@@ -1769,7 +1781,7 @@ var TestNavigationMixin = (superClass) => {
1769
1781
  // ===========================================
1770
1782
  _getDefaultNavigationId(type) {
1771
1783
  if (type === "section") {
1772
- return this._testElement?.querySelector("qti-assessment-section")?.identifier;
1784
+ return this.sessionContext?.navSectionId ?? this._testElement?.querySelector("qti-assessment-section")?.identifier;
1773
1785
  }
1774
1786
  return this.sessionContext?.navItemRefId ?? this._testElement?.querySelector("qti-assessment-item-ref")?.identifier;
1775
1787
  }
@@ -1855,7 +1867,7 @@ var TestNavigationMixin = (superClass) => {
1855
1867
  await this._waitForLoadingComplete(navigationId, controller);
1856
1868
  if (this._isStaleNavigation(navigationId, controller))
1857
1869
  return;
1858
- this._dispatchTestLoaded(this._loadResults);
1870
+ this._dispatchTestLoaded(this._loadResults, "item", itemId);
1859
1871
  }
1860
1872
  /**
1861
1873
  * Navigate to section with simple state tracking
@@ -1876,7 +1888,7 @@ var TestNavigationMixin = (superClass) => {
1876
1888
  await this._waitForLoadingComplete(navigationId, controller);
1877
1889
  if (this._isStaleNavigation(navigationId, controller))
1878
1890
  return;
1879
- this._dispatchTestLoaded(this._loadResults);
1891
+ this._dispatchTestLoaded(this._loadResults, "section", sectionId);
1880
1892
  }
1881
1893
  // ===========================================
1882
1894
  // LOADING STATE MANAGEMENT
@@ -1935,10 +1947,9 @@ var TestNavigationMixin = (superClass) => {
1935
1947
  console.warn("No stimulus content to apply");
1936
1948
  return;
1937
1949
  }
1938
- const elements = stimulus.querySelectorAll("qti-stimulus-body, qti-stylesheet");
1939
- console.info(`Found ${elements.length} stimulus elements to apply for ${element.identifier}`);
1940
- if (elements.length === 0) {
1941
- console.warn("No qti-stimulus-body or qti-stylesheet elements found in stimulus");
1950
+ const root = stimulus.querySelector("qti-assessment-stimulus");
1951
+ if (!root) {
1952
+ console.warn("No qti-assessment-stimulus element found in stimulus");
1942
1953
  return;
1943
1954
  }
1944
1955
  let targets = [];
@@ -1963,8 +1974,7 @@ var TestNavigationMixin = (superClass) => {
1963
1974
  }
1964
1975
  targets.forEach((target, index) => {
1965
1976
  target.innerHTML = "";
1966
- const clonedElements = Array.from(elements).map((el) => el.cloneNode(true));
1967
- target.append(...clonedElements);
1977
+ target.append(root.cloneNode(true));
1968
1978
  console.info(`Applied stimulus content to target ${index + 1}/${targets.length}`);
1969
1979
  });
1970
1980
  }
@@ -2021,7 +2031,7 @@ var TestNavigationMixin = (superClass) => {
2021
2031
  }
2022
2032
  async _loadSingleItem(itemRef, navigationId, controller) {
2023
2033
  try {
2024
- const seed = this.querySelector("test-navigation")?.qtiContext?.QTI_CONTEXT?.seed;
2034
+ const seed = this.qtiContext?.QTI_CONTEXT?.seed;
2025
2035
  let transformer = (await qtiTransformItem().load(itemRef.href, controller.signal)).shuffleInteractions(seed);
2026
2036
  if (this.postLoadTransformCallback) {
2027
2037
  transformer = await this.postLoadTransformCallback(transformer, itemRef);
@@ -2099,11 +2109,7 @@ var TestNavigationMixin = (superClass) => {
2099
2109
  // EVENT DISPATCHING
2100
2110
  // ===========================================
2101
2111
  _dispatchLoadingStarted(type, id) {
2102
- this.dispatchEvent(new CustomEvent("qti-navigation-loading-started", {
2103
- detail: { type, id },
2104
- bubbles: true,
2105
- composed: true
2106
- }));
2112
+ dispatchPublic(this, "cito-test-navigation-started", { type, id });
2107
2113
  }
2108
2114
  _dispatchLoadingEnded(type, id) {
2109
2115
  this.dispatchEvent(new CustomEvent("qti-navigation-loading-ended", {
@@ -2113,22 +2119,16 @@ var TestNavigationMixin = (superClass) => {
2113
2119
  }));
2114
2120
  }
2115
2121
  _dispatchError(error) {
2116
- this.dispatchEvent(new CustomEvent("qti-navigation-error", {
2117
- detail: error,
2118
- bubbles: true,
2119
- composed: true
2120
- }));
2122
+ dispatchPublic(this, "cito-test-navigation-failed", error);
2121
2123
  }
2122
- _dispatchTestLoaded(results) {
2124
+ /** The items are in the DOM: tell hosts the new position rendered (`cito-test-navigated`) and which items it holds. */
2125
+ _dispatchTestLoaded(results, type, id) {
2123
2126
  requestAnimationFrame(() => {
2124
- this.dispatchEvent(new CustomEvent("qti-test-loaded", {
2125
- detail: results.map(({ itemRef }) => ({
2126
- identifier: itemRef?.identifier,
2127
- element: itemRef
2128
- })),
2129
- bubbles: true,
2130
- composed: true
2131
- }));
2127
+ dispatchPublic(this, "cito-test-rendered", results.map(({ itemRef }) => ({
2128
+ identifier: itemRef?.identifier,
2129
+ element: itemRef
2130
+ })));
2131
+ dispatchPublic(this, "cito-test-navigated", { type, id });
2132
2132
  });
2133
2133
  }
2134
2134
  }
@@ -2153,11 +2153,11 @@ var TestViewMixin = (superClass) => {
2153
2153
  constructor(...args) {
2154
2154
  super(...args);
2155
2155
  this.sessionContext = { ...this.sessionContext, view: "candidate" };
2156
- this.addEventListener("on-test-switch-view", (e) => {
2156
+ listenPublic2(this, "cito-test-switch-view", (e) => {
2157
2157
  this.sessionContext = { ...this.sessionContext, view: e.detail };
2158
2158
  this._updateElementView();
2159
2159
  });
2160
- this.addEventListener("qti-assessment-test-connected", () => {
2160
+ listenPublic2(this, "cito-test-loaded", () => {
2161
2161
  this._updateElementView();
2162
2162
  });
2163
2163
  this.addEventListener("qti-assessment-item-connected", (e) => {
@@ -2212,7 +2212,7 @@ var TestBaseMixin = (superClass) => {
2212
2212
  this.testContext = INITIAL_TEST_CONTEXT;
2213
2213
  this.sessionContext = INITIAL_SESSION_CONTEXT;
2214
2214
  this._updateItemInTestContext = (assessmentItem) => {
2215
- const context = assessmentItem._context;
2215
+ const context = assessmentItem.itemContext;
2216
2216
  const identifier = context.identifier;
2217
2217
  const fullVariables = context.variables;
2218
2218
  const itemContext = this.testContext.items.find((i) => i?.identifier === identifier);
@@ -2221,7 +2221,7 @@ var TestBaseMixin = (superClass) => {
2221
2221
  return;
2222
2222
  }
2223
2223
  if (itemContext.variables?.length === 1) {
2224
- this._updateItemVariablesInTestContext(identifier, fullVariables);
2224
+ this._updateItemVariablesInTestContext(identifier, fullVariables, void 0, context.valid);
2225
2225
  } else {
2226
2226
  const newVariables = [...assessmentItem.variables];
2227
2227
  for (const variable of itemContext.variables) {
@@ -2233,29 +2233,61 @@ var TestBaseMixin = (superClass) => {
2233
2233
  }
2234
2234
  }
2235
2235
  assessmentItem.variables = newVariables;
2236
+ if (itemContext.state) {
2237
+ assessmentItem.state = itemContext.state;
2238
+ }
2236
2239
  }
2237
2240
  };
2238
2241
  this._initializeEventListeners();
2239
2242
  }
2240
- updateItemVariables(itemRefID, variables) {
2241
- const itemContext = this.testContext.items.find((item) => item.identifier === itemRefID);
2242
- if (itemContext) {
2243
- itemContext.variables = itemContext.variables.map((variable) => {
2244
- const updatedVariable = variables.find((v) => v.identifier === variable.identifier);
2245
- return updatedVariable ? { ...variable, ...updatedVariable } : variable;
2246
- });
2247
- }
2248
- const itemRef = this._testElement.querySelector(`qti-assessment-item-ref[identifier="${itemRefID}"]`);
2249
- if (itemRef && itemRef.assessmentItem) {
2250
- itemRef.assessmentItem.variables = variables;
2251
- }
2243
+ /**
2244
+ * Sets values on one item from outside the candidate's session, e.g. a score from manual
2245
+ * scoring. Values are merged into the item's entry in the test context, and into the item
2246
+ * itself if it is on screen; a value the item has not seen yet is added, so this also works
2247
+ * before the item has loaded. To restore a whole session, assign `state` instead.
2248
+ *
2249
+ * The test context is replaced rather than changed in place, so its consumers update and
2250
+ * `qti-state-changed` fires.
2251
+ *
2252
+ * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier.
2253
+ * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.
2254
+ */
2255
+ updateItemVariables(itemRefID, values, state9) {
2256
+ this.testContext = {
2257
+ ...this.testContext,
2258
+ items: this.testContext.items.map((item) => {
2259
+ if (item.identifier !== itemRefID)
2260
+ return item;
2261
+ const variables = [...item.variables ?? []];
2262
+ for (const { identifier, type, value } of values) {
2263
+ const index = variables.findIndex((v) => v.identifier === identifier);
2264
+ const updated = {
2265
+ ...index >= 0 ? variables[index] : {},
2266
+ identifier,
2267
+ ...type ? { type } : {},
2268
+ value: Array.isArray(value) ? [...value] : value
2269
+ };
2270
+ if (index >= 0)
2271
+ variables[index] = updated;
2272
+ else
2273
+ variables.push(updated);
2274
+ }
2275
+ return { ...item, variables, ...state9 ? { state: { ...state9 } } : {} };
2276
+ })
2277
+ };
2278
+ const assessmentItem = this._testElement?.querySelector(`qti-assessment-item-ref[identifier="${CSS.escape(itemRefID)}"]`)?.assessmentItem;
2279
+ if (!assessmentItem)
2280
+ return;
2281
+ assessmentItem.variables = [...this.testContext.items.find((i) => i.identifier === itemRefID)?.variables ?? []];
2282
+ if (state9)
2283
+ assessmentItem.state = state9;
2252
2284
  }
2253
2285
  _initializeEventListeners() {
2254
2286
  this.addEventListener("qti-testdoc-loaded", () => {
2255
2287
  this.testContext = INITIAL_TEST_CONTEXT;
2256
2288
  this.sessionContext = INITIAL_SESSION_CONTEXT;
2257
2289
  });
2258
- this.addEventListener("qti-assessment-test-connected", (e) => {
2290
+ listenPublic2(this, "cito-test-loaded", (e) => {
2259
2291
  this._testElement = e.detail;
2260
2292
  const items = Array.from(this._testElement.querySelectorAll("qti-assessment-item-ref")).map((itemRef) => {
2261
2293
  return {
@@ -2282,10 +2314,10 @@ var TestBaseMixin = (superClass) => {
2282
2314
  this._updateItemInTestContext(e.detail);
2283
2315
  });
2284
2316
  this.addEventListener("qti-item-context-updated", (e) => {
2285
- this._updateItemVariablesInTestContext(e.detail.itemContext.identifier, e.detail.itemContext.variables, e.detail.itemContext.state);
2317
+ this._updateItemVariablesInTestContext(e.detail.itemContext.identifier, e.detail.itemContext.variables, e.detail.itemContext.state, e.detail.itemContext.valid);
2286
2318
  });
2287
2319
  }
2288
- _updateItemVariablesInTestContext(identifier, variables, state9) {
2320
+ _updateItemVariablesInTestContext(identifier, variables, state9, valid) {
2289
2321
  this.testContext = {
2290
2322
  ...this.testContext,
2291
2323
  // Spread existing test context properties
@@ -2300,7 +2332,8 @@ var TestBaseMixin = (superClass) => {
2300
2332
  const matchingVariable = itemContext.variables.find((v) => v.identifier === variable.identifier);
2301
2333
  return matchingVariable ? { ...matchingVariable, ...variable } : variable;
2302
2334
  }),
2303
- ...state9 !== void 0 ? { state: state9 ? { ...state9 } : void 0 } : {}
2335
+ ...state9 !== void 0 ? { state: state9 ? { ...state9 } : void 0 } : {},
2336
+ ...valid !== void 0 ? { valid } : {}
2304
2337
  };
2305
2338
  })
2306
2339
  };
@@ -2320,6 +2353,115 @@ var TestBaseMixin = (superClass) => {
2320
2353
  var TestBase = class extends TestBaseMixin(LitElement7) {
2321
2354
  };
2322
2355
 
2356
+ // ../qti-test/dist/mixins/test-state.mixin.js
2357
+ var copy = (value) => Array.isArray(value) ? [...value] : value ?? null;
2358
+ var isQtiTestState = (value) => {
2359
+ const state9 = value;
2360
+ return state9?.version === QTI_TEST_STATE_VERSION && Array.isArray(state9.test?.items) && Array.isArray(state9.test?.outcomes) && typeof state9.session === "object" && state9.session !== null;
2361
+ };
2362
+ var toState = (test, session) => ({
2363
+ version: QTI_TEST_STATE_VERSION,
2364
+ test: {
2365
+ items: (test?.items ?? []).filter((item) => item.identifier).map((item) => ({
2366
+ identifier: item.identifier,
2367
+ variables: (item.variables ?? []).map((v) => ({
2368
+ identifier: v.identifier,
2369
+ ...v.type ? { type: v.type } : {},
2370
+ value: copy(v.value)
2371
+ })),
2372
+ ...item.state ? { state: { ...item.state } } : {}
2373
+ })),
2374
+ outcomes: (test?.testOutcomeVariables ?? []).map((v) => ({ identifier: v.identifier, value: copy(v.value) }))
2375
+ },
2376
+ session: {
2377
+ ...session?.navPartId !== void 0 ? { navPartId: session.navPartId } : {},
2378
+ ...session?.navSectionId !== void 0 ? { navSectionId: session.navSectionId } : {},
2379
+ ...session?.navItemRefId !== void 0 ? { navItemRefId: session.navItemRefId } : {}
2380
+ }
2381
+ });
2382
+ var TestStateMixin = (superClass) => {
2383
+ class TestStateClass extends superClass {
2384
+ /** A state assigned before the test connected, applied when it does. */
2385
+ #pending = null;
2386
+ /**
2387
+ * False while a test document is loading. Loading resets both contexts and rebuilds them, so
2388
+ * the intermediate states are empty — emitting one would invite a host to save it over the
2389
+ * real one.
2390
+ */
2391
+ #ready = false;
2392
+ #lastEmitted = null;
2393
+ constructor(...args) {
2394
+ super(...args);
2395
+ this.addEventListener("qti-testdoc-loaded", () => {
2396
+ this.#ready = false;
2397
+ this.#lastEmitted = null;
2398
+ });
2399
+ listenPublic2(this, "cito-test-loaded", () => {
2400
+ if (this.#pending) {
2401
+ this.#apply(this.#pending);
2402
+ this.#pending = null;
2403
+ }
2404
+ this.#ready = true;
2405
+ });
2406
+ }
2407
+ get state() {
2408
+ return toState(this.testContext, this.sessionContext);
2409
+ }
2410
+ set state(value) {
2411
+ if (!isQtiTestState(value)) {
2412
+ console.warn(`[qti-test] Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`);
2413
+ return;
2414
+ }
2415
+ if (!this.#ready) {
2416
+ this.#pending = value;
2417
+ return;
2418
+ }
2419
+ const { navItemRefId, navSectionId } = this.sessionContext;
2420
+ this.#apply(value);
2421
+ const restored = this.sessionContext;
2422
+ if (restored.navItemRefId && restored.navItemRefId !== navItemRefId) {
2423
+ this.#requestNavigation("item", restored.navItemRefId);
2424
+ } else if (!restored.navItemRefId && restored.navSectionId && restored.navSectionId !== navSectionId) {
2425
+ this.#requestNavigation("section", restored.navSectionId);
2426
+ }
2427
+ }
2428
+ updated(changed) {
2429
+ super.updated(changed);
2430
+ if (!this.#ready || !(changed.has("testContext") || changed.has("sessionContext")))
2431
+ return;
2432
+ const state9 = this.state;
2433
+ const serialized = JSON.stringify(state9);
2434
+ if (serialized === this.#lastEmitted)
2435
+ return;
2436
+ this.#lastEmitted = serialized;
2437
+ dispatchPublic(this, "cito-test-state-changed", state9);
2438
+ }
2439
+ #apply(state9) {
2440
+ for (const saved of state9.test.items)
2441
+ this.updateItemVariables(saved.identifier, saved.variables, saved.state);
2442
+ const savedOutcomes = new Map(state9.test.outcomes.map((outcome) => [outcome.identifier, outcome.value]));
2443
+ this.testContext = {
2444
+ ...this.testContext,
2445
+ testOutcomeVariables: this.testContext.testOutcomeVariables?.map((v) => savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v)
2446
+ };
2447
+ this.sessionContext = { ...this.sessionContext, ...this.#validSession(state9.session) };
2448
+ }
2449
+ /** A stored position may point at an item or section a revised test no longer has. */
2450
+ #validSession(session) {
2451
+ const exists = (selector, id) => !!id && !!this._testElement?.querySelector(`${selector}[identifier="${CSS.escape(id)}"]`);
2452
+ return {
2453
+ ...exists("qti-test-part", session.navPartId) ? { navPartId: session.navPartId } : {},
2454
+ ...exists("qti-assessment-section", session.navSectionId) ? { navSectionId: session.navSectionId } : {},
2455
+ ...this.testContext.items.some((i) => i.identifier === session.navItemRefId) ? { navItemRefId: session.navItemRefId } : {}
2456
+ };
2457
+ }
2458
+ #requestNavigation(type, id) {
2459
+ dispatchPublic(this, "cito-test-navigate", { type, id });
2460
+ }
2461
+ }
2462
+ return TestStateClass;
2463
+ };
2464
+
2323
2465
  // ../qti-test/dist/mixins/test-processing.mixin.js
2324
2466
  var TestProcessingMixin = (superClass) => {
2325
2467
  class TestProcessingElement extends superClass {
@@ -2339,7 +2481,7 @@ var TestProcessingMixin = (superClass) => {
2339
2481
  });
2340
2482
  }
2341
2483
  outcomeProcessing() {
2342
- const outcomeProcessor = this.querySelector("qti-outcome-processing");
2484
+ const outcomeProcessor = (this._testElement ?? this).querySelector("qti-outcome-processing");
2343
2485
  if (!outcomeProcessor)
2344
2486
  return false;
2345
2487
  outcomeProcessor?.process();
@@ -2382,10 +2524,20 @@ var __decorate9 = function(decorators, target, key, desc) {
2382
2524
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2383
2525
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2384
2526
  };
2385
- var QtiTest = class extends TestNavigationMixin(TestViewMixin(TestProcessingMixin(TestBaseMixin(LitElement8)))) {
2527
+ var QtiTest = class extends TestNavigationMixin(TestViewMixin(TestProcessingMixin(TestStateMixin(TestBaseMixin(LitElement8))))) {
2528
+ // TODO: Properly implement IQtiTest interface
2529
+ // export class QtiTest extends TestLoaderMixin(TestNavigationMixin(TestViewMixin(TestBase))) {
2386
2530
  constructor() {
2387
- super(...arguments);
2531
+ super();
2388
2532
  this.configContext = {};
2533
+ this.qtiContext = {
2534
+ QTI_CONTEXT: {
2535
+ testIdentifier: "",
2536
+ candidateIdentifier: "",
2537
+ environmentIdentifier: "default"
2538
+ }
2539
+ };
2540
+ new ContextProvider(this, { context: testHostContext, initialValue: this });
2389
2541
  }
2390
2542
  /**
2391
2543
  * Renders the component's template.
@@ -2404,8 +2556,13 @@ __decorate9([
2404
2556
  state2(),
2405
2557
  provide2({ context: configContext })
2406
2558
  ], QtiTest.prototype, "configContext", void 0);
2559
+ __decorate9([
2560
+ state2(),
2561
+ provide2({ context: qtiContext })
2562
+ ], QtiTest.prototype, "qtiContext", void 0);
2407
2563
 
2408
2564
  // ../qti-test/dist/components/test-check-item/test-check-item.js
2565
+ import { consume as consume5 } from "@lit/context";
2409
2566
  import { css as css4, html as html8, LitElement as LitElement9 } from "lit";
2410
2567
 
2411
2568
  // ../qti-test/dist/components/styles.js
@@ -2448,6 +2605,12 @@ var ind = css3`
2448
2605
  `;
2449
2606
 
2450
2607
  // ../qti-test/dist/components/test-check-item/test-check-item.js
2608
+ var __decorate10 = function(decorators, target, key, desc) {
2609
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2610
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2611
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2612
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2613
+ };
2451
2614
  var TestCheckItem = class extends LitElement9 {
2452
2615
  static {
2453
2616
  this.styles = css4`
@@ -2468,9 +2631,10 @@ var TestCheckItem = class extends LitElement9 {
2468
2631
  constructor() {
2469
2632
  super();
2470
2633
  this.addEventListener("click", () => {
2471
- this.dispatchEvent(new CustomEvent("test-end-attempt", { bubbles: true }));
2472
- const qtiTest = this.closest("qti-test");
2473
- const testContainer = qtiTest.querySelector("test-container");
2634
+ dispatchPublic(this, "cito-test-end-attempt", {});
2635
+ const testContainer = this.testHost?.querySelector("test-container");
2636
+ if (!testContainer)
2637
+ return;
2474
2638
  const viewElements = Array.from(testContainer.shadowRoot.querySelectorAll("[view]"));
2475
2639
  viewElements.forEach((element) => {
2476
2640
  element.classList.toggle("show", true);
@@ -2481,13 +2645,16 @@ var TestCheckItem = class extends LitElement9 {
2481
2645
  return html8` <slot></slot> `;
2482
2646
  }
2483
2647
  };
2648
+ __decorate10([
2649
+ consume5({ context: testHostContext, subscribe: true })
2650
+ ], TestCheckItem.prototype, "testHost", void 0);
2484
2651
 
2485
2652
  // ../qti-test/dist/components/test-container/test-container.js
2486
- import { consume as consume5 } from "@lit/context";
2653
+ import { consume as consume6 } from "@lit/context";
2487
2654
  import { LitElement as LitElement10, html as html9 } from "lit";
2488
2655
  import { property as property8, state as state3 } from "lit/decorators.js";
2489
2656
  import { until } from "lit/directives/until.js";
2490
- var __decorate10 = function(decorators, target, key, desc) {
2657
+ var __decorate11 = function(decorators, target, key, desc) {
2491
2658
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2492
2659
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2493
2660
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -2525,7 +2692,7 @@ var TestContainer = class extends LitElement10 {
2525
2692
  try {
2526
2693
  const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;
2527
2694
  let api = (await qtiTransformTest().load(this.testURL)).shuffleOrdering(explicitSeed);
2528
- const qtiTest = this.closest("qti-test");
2695
+ const qtiTest = this.testHost;
2529
2696
  if (qtiTest?.postLoadTestTransformCallback) {
2530
2697
  const tempDoc = api.htmlDoc(this.#resolvedCustomElementRegistry ?? void 0);
2531
2698
  const testElement = tempDoc.querySelector("qti-assessment-test");
@@ -2593,34 +2760,37 @@ var TestContainer = class extends LitElement10 {
2593
2760
  `;
2594
2761
  }
2595
2762
  };
2596
- __decorate10([
2763
+ __decorate11([
2597
2764
  property8({ attribute: false })
2598
2765
  ], TestContainer.prototype, "customElementRegistry", void 0);
2599
- __decorate10([
2766
+ __decorate11([
2600
2767
  property8({ type: String, attribute: "test-url" })
2601
2768
  ], TestContainer.prototype, "testURL", void 0);
2602
- __decorate10([
2769
+ __decorate11([
2603
2770
  state3()
2604
2771
  ], TestContainer.prototype, "testDoc", void 0);
2605
- __decorate10([
2772
+ __decorate11([
2606
2773
  state3()
2607
2774
  ], TestContainer.prototype, "testXML", void 0);
2608
- __decorate10([
2775
+ __decorate11([
2776
+ consume6({ context: testHostContext, subscribe: true })
2777
+ ], TestContainer.prototype, "testHost", void 0);
2778
+ __decorate11([
2609
2779
  state3(),
2610
- consume5({ context: qtiContext, subscribe: true })
2780
+ consume6({ context: qtiContext, subscribe: true })
2611
2781
  ], TestContainer.prototype, "qtiContext", void 0);
2612
- __decorate10([
2782
+ __decorate11([
2613
2783
  watch("testURL", { waitUntilFirstUpdate: true })
2614
2784
  ], TestContainer.prototype, "handleTestURLChange", null);
2615
- __decorate10([
2785
+ __decorate11([
2616
2786
  watch("testXML", { waitUntilFirstUpdate: true })
2617
2787
  ], TestContainer.prototype, "handleTestXMLChange", null);
2618
2788
 
2619
2789
  // ../qti-test/dist/components/test-end-attempt/test-end-attempt.js
2620
2790
  import { css as css5, html as html10, LitElement as LitElement11 } from "lit";
2621
2791
  import { property as property9 } from "lit/decorators.js";
2622
- import { consume as consume6 } from "@lit/context";
2623
- var __decorate11 = function(decorators, target, key, desc) {
2792
+ import { consume as consume7 } from "@lit/context";
2793
+ var __decorate12 = function(decorators, target, key, desc) {
2624
2794
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2625
2795
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2626
2796
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -2654,7 +2824,7 @@ var TestEndAttempt = class extends LitElement11 {
2654
2824
  this.addEventListener("click", (e) => {
2655
2825
  e.preventDefault();
2656
2826
  if (!this._internalDisabled) {
2657
- this.dispatchEvent(new CustomEvent("test-end-attempt", { bubbles: true }));
2827
+ dispatchPublic(this, "cito-test-end-attempt", {});
2658
2828
  }
2659
2829
  });
2660
2830
  }
@@ -2692,21 +2862,21 @@ var TestEndAttempt = class extends LitElement11 {
2692
2862
  return html10` <slot></slot> `;
2693
2863
  }
2694
2864
  };
2695
- __decorate11([
2696
- consume6({ context: computedContext, subscribe: true }),
2865
+ __decorate12([
2866
+ consume7({ context: computedContext, subscribe: true }),
2697
2867
  property9({ attribute: false })
2698
2868
  ], TestEndAttempt.prototype, "computedContext", void 0);
2699
- __decorate11([
2869
+ __decorate12([
2700
2870
  property9({ type: Boolean, reflect: true, attribute: "disabled" })
2701
2871
  ], TestEndAttempt.prototype, "_internalDisabled", void 0);
2702
- __decorate11([
2872
+ __decorate12([
2703
2873
  watch("computedContext")
2704
2874
  ], TestEndAttempt.prototype, "_handleTestElementChange", null);
2705
2875
 
2706
2876
  // ../qti-test/dist/components/test-item-link/test-item-link.js
2707
2877
  import { css as css6, html as html11, LitElement as LitElement12 } from "lit";
2708
2878
  import { property as property10 } from "lit/decorators.js";
2709
- var __decorate12 = function(decorators, target, key, desc) {
2879
+ var __decorate13 = function(decorators, target, key, desc) {
2710
2880
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2711
2881
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2712
2882
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -2735,29 +2905,22 @@ var TestItemLink = class extends LitElement12 {
2735
2905
  this.addEventListener("click", () => this._requestItem(this.itemId));
2736
2906
  }
2737
2907
  _requestItem(identifier) {
2738
- this.dispatchEvent(new CustomEvent("qti-request-navigation", {
2739
- composed: true,
2740
- bubbles: true,
2741
- detail: {
2742
- type: "item",
2743
- id: identifier
2744
- }
2745
- }));
2908
+ dispatchPublic(this, "cito-test-navigate", { type: "item", id: identifier });
2746
2909
  }
2747
2910
  render() {
2748
2911
  return html11` <slot></slot> `;
2749
2912
  }
2750
2913
  };
2751
- __decorate12([
2914
+ __decorate13([
2752
2915
  property10({ type: String, attribute: "item-id" })
2753
2916
  ], TestItemLink.prototype, "itemId", void 0);
2754
2917
 
2755
2918
  // ../qti-test/dist/components/test-item-to-speech/test-item-to-speech.js
2756
2919
  import { html as html12, LitElement as LitElement13, css as css7 } from "lit";
2757
- import { consume as consume7, provide as provide3, createContext } from "@lit/context";
2920
+ import { consume as consume8, provide as provide3, createContext as createContext2 } from "@lit/context";
2758
2921
  import { property as property11, state as state4 } from "lit/decorators.js";
2759
2922
  import { ifDefined } from "lit/directives/if-defined.js";
2760
- var __decorate13 = function(decorators, target, key, desc) {
2923
+ var __decorate14 = function(decorators, target, key, desc) {
2761
2924
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2762
2925
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2763
2926
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -2776,7 +2939,7 @@ function getHighlightSheet() {
2776
2939
  }
2777
2940
  return highlightSheet;
2778
2941
  }
2779
- var ttsContext = createContext(/* @__PURE__ */ Symbol("tts-context"));
2942
+ var ttsContext = createContext2(/* @__PURE__ */ Symbol("tts-context"));
2780
2943
  var ICONS = {
2781
2944
  play: "M8 5v14l11-7z",
2782
2945
  pause: "M6 5h4v14H6zM14 5h4v14h-4z",
@@ -2785,8 +2948,12 @@ var ICONS = {
2785
2948
  next: "M16 5h2v14h-2zM4 5v14l11-7z",
2786
2949
  pick: "M5 3l13 7-5.5 1.6 3.4 6.6-2.4 1.3-3.4-6.7L6 17z"
2787
2950
  };
2788
- var iconContent = (icon, label) => html12`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d=${ICONS[icon]}></path></svg
2789
- ><span class="label">${label}</span>`;
2951
+ var iconContent = (icon, label) => {
2952
+ const svg = html12`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
2953
+ <path d="${ICONS[icon]}"></path>
2954
+ </svg>`;
2955
+ return html12`${svg}<span class="label">${label}</span>`;
2956
+ };
2790
2957
  var TtsButtonBase = class extends LitElement13 {
2791
2958
  static {
2792
2959
  this.styles = css7`
@@ -2797,6 +2964,10 @@ var TtsButtonBase = class extends LitElement13 {
2797
2964
  ${btn};
2798
2965
  min-inline-size: var(--test-button-size, 2.25rem);
2799
2966
  padding-inline: 0.5rem;
2967
+ /* Containing block for the visually hidden .label. Without it the label is placed against
2968
+ the nearest positioned ancestor, which can sit outside a scroll container and make the
2969
+ page as tall as the scrolled content. */
2970
+ position: relative;
2800
2971
  }
2801
2972
  button:hover:not(:disabled) {
2802
2973
  ${btnInteractive};
@@ -2849,11 +3020,11 @@ var TtsButtonBase = class extends LitElement13 {
2849
3020
  this.#internals.states.add("picking");
2850
3021
  }
2851
3022
  };
2852
- __decorate13([
3023
+ __decorate14([
2853
3024
  property11({ type: String })
2854
3025
  ], TtsButtonBase.prototype, "label", void 0);
2855
- __decorate13([
2856
- consume7({ context: ttsContext, subscribe: true })
3026
+ __decorate14([
3027
+ consume8({ context: ttsContext, subscribe: true })
2857
3028
  ], TtsButtonBase.prototype, "_tts", void 0);
2858
3029
  var TestItemToSpeech = class extends LitElement13 {
2859
3030
  static {
@@ -2867,10 +3038,24 @@ var TestItemToSpeech = class extends LitElement13 {
2867
3038
  `;
2868
3039
  }
2869
3040
  #internals;
2870
- #itemElements;
2871
- #boundHandleItemConnected;
3041
+ // Stimulus mode: set on connect when a stimulus placeholder sits next to the player. The
3042
+ // placeholder itself is looked up on every use — a host may swap the element.
3043
+ #stimulusMode;
3044
+ // Stimulus mode: resets the player when the stimulus content next to it is replaced.
3045
+ #stimulusObserver;
3046
+ // Content mode: set on connect when a `[data-tts-content]` element sits next to the player.
3047
+ // Any HTML, not QTI. No observer: the reading list is rebuilt on demand (#getReadingElements).
3048
+ #contentMode;
3049
+ // Item-ref mode: the item-ref this player sits in, resolved on connect. Null means cursor mode.
3050
+ #itemRef;
3051
+ // Where the item-connected (and, in cursor mode, navigation) events are listened for.
2872
3052
  #eventHost;
2873
- // Current set of block-level reading elements for the active item
3053
+ #boundHandleItemConnected;
3054
+ #boundHandleNavigation;
3055
+ // Cursor mode: the previous navigation position, to detect moving to another item or section.
3056
+ #prevNavItemRefId;
3057
+ #prevNavSectionId;
3058
+ // Current set of block-level reading elements for the item
2874
3059
  #readingElements;
2875
3060
  #currentElementIndex;
2876
3061
  // Text nodes of the element currently being spoken (for word-boundary highlight)
@@ -2890,17 +3075,19 @@ var TestItemToSpeech = class extends LitElement13 {
2890
3075
  // whole-element cursor
2891
3076
  #wordHighlight;
2892
3077
  // current word during speech
2893
- // Tracks previous navItemRefId to detect item switches
2894
- #prevNavItemRefId;
2895
- #prevNavSectionId;
2896
- #boundHandleNavigation;
2897
3078
  constructor() {
2898
3079
  super();
2899
3080
  this.language = "nl-NL";
2900
3081
  this.#internals = this.attachInternals();
2901
- this.#itemElements = /* @__PURE__ */ new Map();
2902
- this.#boundHandleItemConnected = this.#handleItemConnected.bind(this);
3082
+ this.#stimulusMode = false;
3083
+ this.#stimulusObserver = null;
3084
+ this.#contentMode = false;
3085
+ this.#itemRef = null;
2903
3086
  this.#eventHost = null;
3087
+ this.#boundHandleItemConnected = this.#handleItemConnected.bind(this);
3088
+ this.#boundHandleNavigation = () => this.#stop();
3089
+ this.#prevNavItemRefId = void 0;
3090
+ this.#prevNavSectionId = void 0;
2904
3091
  this.#readingElements = null;
2905
3092
  this.#currentElementIndex = 0;
2906
3093
  this.#textNodes = [];
@@ -2911,9 +3098,6 @@ var TestItemToSpeech = class extends LitElement13 {
2911
3098
  this.#finished = false;
2912
3099
  this.#elementHighlight = new Highlight();
2913
3100
  this.#wordHighlight = new Highlight();
2914
- this.#prevNavItemRefId = void 0;
2915
- this.#prevNavSectionId = void 0;
2916
- this.#boundHandleNavigation = () => this.#stop();
2917
3101
  this._ttsContext = {
2918
3102
  state: "idle",
2919
3103
  currentElementIndex: 0,
@@ -2931,21 +3115,19 @@ var TestItemToSpeech = class extends LitElement13 {
2931
3115
  picking: false
2932
3116
  };
2933
3117
  }
3118
+ // willUpdate, not updated: resetting writes _ttsContext, and state set here goes into the
3119
+ // render already under way instead of scheduling a second one (Lit's change-in-update).
2934
3120
  willUpdate(changed) {
2935
- void changed;
2936
- }
2937
- updated(changed) {
2938
- if (changed.has("itemRefId") && changed.get("itemRefId") !== void 0) {
2939
- this.#resetReadingPosition();
2940
- }
2941
- const current = this._sessionContext?.navItemRefId ?? null;
3121
+ super.willUpdate(changed);
3122
+ if (this.#stimulusMode || this.#contentMode || this.#itemRef)
3123
+ return;
3124
+ const item = this._sessionContext?.navItemRefId ?? null;
2942
3125
  const section = this._sessionContext?.navSectionId ?? null;
2943
- const itemChanged = this.#prevNavItemRefId !== void 0 && this.#prevNavItemRefId !== current;
3126
+ const itemChanged = this.#prevNavItemRefId !== void 0 && this.#prevNavItemRefId !== item;
2944
3127
  const sectionChanged = this.#prevNavSectionId !== void 0 && this.#prevNavSectionId !== section;
2945
- if (sectionChanged || itemChanged && !this.itemRefId) {
3128
+ if (itemChanged || sectionChanged)
2946
3129
  this.#resetReadingPosition();
2947
- }
2948
- this.#prevNavItemRefId = current;
3130
+ this.#prevNavItemRefId = item;
2949
3131
  this.#prevNavSectionId = section;
2950
3132
  }
2951
3133
  /** Stop speech and forget the collected reading elements, so the next play starts afresh. */
@@ -2960,9 +3142,25 @@ var TestItemToSpeech = class extends LitElement13 {
2960
3142
  connectedCallback() {
2961
3143
  super.connectedCallback();
2962
3144
  this.#setSpeechState("idle");
2963
- this.#eventHost = this.closest("test-navigation") ?? this.closest("qti-test") ?? this.getRootNode();
3145
+ this.#stimulusMode = this.#stimulusPlaceholder() !== null;
3146
+ if (this.#stimulusMode) {
3147
+ this.#stimulusObserver = new MutationObserver((records) => {
3148
+ if (records.some((record) => !this.contains(record.target)))
3149
+ this.#handleStimulusReplaced();
3150
+ });
3151
+ this.#stimulusObserver.observe(this.parentElement, { childList: true, subtree: true });
3152
+ return;
3153
+ }
3154
+ this.#contentMode = this.#contentElement() !== null;
3155
+ if (this.#contentMode)
3156
+ return;
3157
+ this.#itemRef = this.closest("qti-assessment-item-ref");
3158
+ this.#eventHost = this.#itemRef ?? this.closest("test-navigation") ?? this.testHost ?? this.getRootNode();
2964
3159
  this.#eventHost.addEventListener("qti-assessment-item-connected", this.#boundHandleItemConnected);
2965
- this.#eventHost.addEventListener("qti-request-navigation", this.#boundHandleNavigation);
3160
+ if (!this.#itemRef) {
3161
+ this.#eventHost.addEventListener("cito-test-navigate", this.#boundHandleNavigation);
3162
+ this.#eventHost.addEventListener("qti-request-navigation", this.#boundHandleNavigation);
3163
+ }
2966
3164
  }
2967
3165
  disconnectedCallback() {
2968
3166
  super.disconnectedCallback();
@@ -2973,53 +3171,114 @@ var TestItemToSpeech = class extends LitElement13 {
2973
3171
  this.#stopPicking();
2974
3172
  this.#clearAllHighlights();
2975
3173
  this.#eventHost?.removeEventListener("qti-assessment-item-connected", this.#boundHandleItemConnected);
3174
+ this.#eventHost?.removeEventListener("cito-test-navigate", this.#boundHandleNavigation);
2976
3175
  this.#eventHost?.removeEventListener("qti-request-navigation", this.#boundHandleNavigation);
2977
3176
  this.#eventHost = null;
2978
- this.#itemElements.clear();
3177
+ this.#itemRef = null;
3178
+ this.#stimulusObserver?.disconnect();
3179
+ this.#stimulusObserver = null;
3180
+ this.#stimulusMode = false;
3181
+ this.#contentMode = false;
2979
3182
  }
2980
3183
  render() {
2981
3184
  return html12`<slot></slot>`;
2982
3185
  }
3186
+ /**
3187
+ * An item (re)rendered. If it is ours — e.g. after navigating to the item already shown — the
3188
+ * elements collected earlier are detached now. That does not move the navigation cursor, so
3189
+ * the check in updated() does not catch it.
3190
+ */
2983
3191
  #handleItemConnected(event) {
2984
- const item = event.detail;
2985
- if (item?.identifier) {
2986
- this.#itemElements.set(item.identifier, item);
2987
- if (this.itemRefId && item.identifier === this.itemRefId && this.#readingElements !== null) {
2988
- this.#resetReadingPosition();
2989
- }
3192
+ if (this.#readingElements === null)
3193
+ return;
3194
+ const identifier = event.detail?.identifier;
3195
+ if (this.#itemRef || identifier === this._sessionContext?.navItemRefId)
3196
+ this.#resetReadingPosition();
3197
+ }
3198
+ /**
3199
+ * Stimulus mode: the stimulus next to the player was (re)loaded or swapped. Forget what was
3200
+ * collected, so the next play reads the new content from the top. Unlike
3201
+ * #resetReadingPosition this only cancels speech that is ours: a stimulus can finish loading
3202
+ * while an item player on the same page is speaking.
3203
+ */
3204
+ #handleStimulusReplaced() {
3205
+ if (this.#currentUtterance) {
3206
+ this.#currentUtterance = null;
3207
+ speechSynthesis.cancel();
2990
3208
  }
3209
+ this.#stopPicking();
3210
+ this.#clearAllHighlights();
3211
+ this.#setSpeechState("idle");
3212
+ this.#readingElements = null;
3213
+ this.#currentElementIndex = 0;
3214
+ this.#finished = false;
3215
+ this.#updateContext();
3216
+ }
3217
+ /**
3218
+ * Stimulus mode: the `[data-stimulus-idref]` placeholder that shares this player's parent, or
3219
+ * null. A placeholder holds the stimulus once loaded; the player cannot sit inside it, because
3220
+ * loading replaces the placeholder's content.
3221
+ */
3222
+ #stimulusPlaceholder() {
3223
+ return this.parentElement?.querySelector(":scope > [data-stimulus-idref]") ?? null;
3224
+ }
3225
+ /**
3226
+ * Content mode: the `[data-tts-content]` element that shares this player's parent, or null.
3227
+ * The marker goes on one container; the player finds the readable elements inside it.
3228
+ */
3229
+ #contentElement() {
3230
+ return this.parentElement?.querySelector(":scope > [data-tts-content]") ?? null;
3231
+ }
3232
+ /**
3233
+ * The element whose text is read: the stimulus body next to the player (stimulus mode), the
3234
+ * marked content next to it (content mode), or the item body of the item to read.
3235
+ */
3236
+ #resolveReadingRoot() {
3237
+ if (this.#stimulusMode)
3238
+ return this.#stimulusPlaceholder()?.querySelector("qti-stimulus-body") ?? null;
3239
+ if (this.#contentMode)
3240
+ return this.#contentElement();
3241
+ return this.#resolveItem()?.querySelector("qti-item-body") ?? null;
3242
+ }
3243
+ /** The item to read: our item-ref's (item-ref mode), or the navigated one (cursor mode). */
3244
+ #resolveItem() {
3245
+ if (this.#itemRef)
3246
+ return this.#itemRef.assessmentItem;
3247
+ const identifier = this._sessionContext?.navItemRefId;
3248
+ return identifier ? this.#findItemInDom(identifier) : null;
2991
3249
  }
2992
3250
  /**
2993
- * Find the rendered `qti-assessment-item` for an item-ref identifier without relying on the
2994
- * connected-event cache — the player may be added after the item rendered (a header built
2995
- * around an existing item) or sit in a shadow root the event never bubbled through.
3251
+ * Cursor mode: find the rendered item for an item-ref identifier. Our own `<qti-test>` first —
3252
+ * a page can hold several tests showing the same item — then every root from here up to the
3253
+ * document; each scope directly and in the `test-container` shadow roots inside it.
2996
3254
  */
2997
3255
  #findItemInDom(identifier) {
2998
- const esc = (v) => typeof CSS !== "undefined" && CSS.escape ? CSS.escape(v) : v.replace(/"/g, '\\"');
2999
- const selector = `qti-assessment-item-ref[identifier="${esc(identifier)}"] qti-assessment-item, qti-assessment-item[identifier="${esc(identifier)}"]`;
3000
- const ownRef = this.closest("qti-assessment-item-ref");
3001
- if (ownRef?.getAttribute("identifier") === identifier) {
3002
- const own = ownRef.querySelector("qti-assessment-item");
3003
- if (own)
3004
- return own;
3005
- }
3006
- let root = this.getRootNode();
3007
- while (root) {
3008
- const scope = root;
3009
- const direct = scope.querySelector?.(selector);
3256
+ const selector = `qti-assessment-item-ref[identifier="${CSS.escape(identifier)}"] qti-assessment-item`;
3257
+ const search = (scope) => {
3258
+ const direct = scope.querySelector(selector);
3010
3259
  if (direct)
3011
3260
  return direct;
3012
- for (const container of Array.from(scope.querySelectorAll?.("test-container") ?? [])) {
3261
+ for (const container of Array.from(scope.querySelectorAll("test-container"))) {
3013
3262
  const inShadow = container.shadowRoot?.querySelector(selector);
3014
3263
  if (inShadow)
3015
3264
  return inShadow;
3016
3265
  }
3266
+ return null;
3267
+ };
3268
+ const test = this.closest("qti-test");
3269
+ const inTest = test && search(test);
3270
+ if (inTest)
3271
+ return inTest;
3272
+ let root = this.getRootNode();
3273
+ for (; ; ) {
3274
+ const found = search(root);
3275
+ if (found)
3276
+ return found;
3017
3277
  const host = root.host;
3018
3278
  if (!host)
3019
- break;
3279
+ return null;
3020
3280
  root = host.getRootNode();
3021
3281
  }
3022
- return null;
3023
3282
  }
3024
3283
  /** Update speech state on both the context (notifies children) and the host's CSS custom states. */
3025
3284
  #setSpeechState(state9) {
@@ -3034,26 +3293,37 @@ var TestItemToSpeech = class extends LitElement13 {
3034
3293
  this._ttsContext = {
3035
3294
  ...this._ttsContext,
3036
3295
  currentElementIndex: this.#currentElementIndex,
3037
- elementCount: this.#readingElements?.length ?? 0
3296
+ elementCount: this.#getReadingElements().length
3038
3297
  };
3039
3298
  }
3040
- /** Return cached reading elements, collecting them lazily on first call for the active item. */
3299
+ /**
3300
+ * Return the currently readable elements: cached candidates for the item or stimulus (collected lazily on
3301
+ * first call), filtered live for visibility on every call. Feedback and other
3302
+ * conditionally-shown content (e.g. `qti-feedback-block`, which is `display: none` until a
3303
+ * CSS custom state reveals it) is excluded while hidden and picked up again once shown,
3304
+ * without needing to re-collect the candidate set.
3305
+ */
3041
3306
  #getReadingElements() {
3042
- if (this.#readingElements !== null)
3043
- return this.#readingElements;
3044
- const identifier = this.itemRefId || this._sessionContext?.navItemRefId;
3045
- if (!identifier)
3046
- return [];
3047
- const cached = this.#itemElements.get(identifier);
3048
- const assessmentItem = cached?.isConnected ? cached : this.#findItemInDom(identifier);
3049
- if (!assessmentItem)
3050
- return [];
3051
- const itemBody = assessmentItem.querySelector("qti-item-body");
3052
- if (!itemBody)
3053
- return [];
3054
- const selector = "p, h1, h2, h3, h4, h5, h6, li, blockquote, figcaption, qti-prompt, qti-simple-choice";
3055
- this.#readingElements = Array.from(itemBody.querySelectorAll(selector)).filter((el) => (el.textContent ?? "").trim().length > 0 && !el.querySelector(selector));
3056
- return this.#readingElements;
3307
+ if (this.#contentMode && this.#readingElements?.some((el) => !el.isConnected)) {
3308
+ this.#readingElements = null;
3309
+ this.#currentElementIndex = 0;
3310
+ this.#finished = false;
3311
+ }
3312
+ if (this.#readingElements === null) {
3313
+ const root = this.#resolveReadingRoot();
3314
+ if (!root)
3315
+ return [];
3316
+ const selector = "p, h1, h2, h3, h4, h5, h6, li, dt, dd, th, td, caption, blockquote, figcaption, qti-prompt, qti-simple-choice";
3317
+ this.#readingElements = Array.from(root.querySelectorAll(selector)).filter((el) => (el.textContent ?? "").trim().length > 0 && !el.querySelector(selector) && !el.closest('[aria-hidden="true"]'));
3318
+ }
3319
+ return this.#readingElements.filter((el) => this.#isVisible(el));
3320
+ }
3321
+ /** True when an element is actually rendered — not `display: none` (itself or an ancestor). */
3322
+ #isVisible(element) {
3323
+ if (typeof element.checkVisibility === "function") {
3324
+ return element.checkVisibility({ checkOpacity: false, checkVisibilityCSS: true });
3325
+ }
3326
+ return element.getClientRects().length > 0;
3057
3327
  }
3058
3328
  /**
3059
3329
  * Resolve the speech language for a reading element.
@@ -3076,7 +3346,7 @@ var TestItemToSpeech = class extends LitElement13 {
3076
3346
  #playSpeech() {
3077
3347
  const elements = this.#getReadingElements();
3078
3348
  if (!elements.length) {
3079
- console.warn("test-item-to-speech: no readable elements found in qti-item-body");
3349
+ console.warn("test-item-to-speech: no readable elements found");
3080
3350
  return;
3081
3351
  }
3082
3352
  this.#stopPicking();
@@ -3085,11 +3355,13 @@ var TestItemToSpeech = class extends LitElement13 {
3085
3355
  this.#finished = false;
3086
3356
  this.#currentElementIndex = 0;
3087
3357
  }
3358
+ if (this.#contentMode && this.#currentElementIndex === 0)
3359
+ this.#readingElements = null;
3088
3360
  this.#speakElement(this.#currentElementIndex);
3089
3361
  }
3090
3362
  /** Speak the element at the given index, then auto-advance when it ends. */
3091
3363
  #speakElement(index) {
3092
- const elements = this.#readingElements ?? [];
3364
+ const elements = this.#getReadingElements();
3093
3365
  if (index >= elements.length) {
3094
3366
  this.#clearWordHighlight();
3095
3367
  this.#currentElementIndex = elements.length - 1;
@@ -3161,9 +3433,11 @@ var TestItemToSpeech = class extends LitElement13 {
3161
3433
  }
3162
3434
  /** Highlight every reading element and wait for a click on one of them. */
3163
3435
  #startPicking() {
3436
+ if (this.#contentMode)
3437
+ this.#readingElements = null;
3164
3438
  const elements = this.#getReadingElements();
3165
3439
  if (!elements.length) {
3166
- console.warn("test-item-to-speech: no readable elements found in qti-item-body");
3440
+ console.warn("test-item-to-speech: no readable elements found");
3167
3441
  return;
3168
3442
  }
3169
3443
  this.#stop();
@@ -3185,7 +3459,7 @@ var TestItemToSpeech = class extends LitElement13 {
3185
3459
  this._ttsContext = { ...this._ttsContext, picking: false };
3186
3460
  }
3187
3461
  #handlePickClick(event) {
3188
- const elements = this.#readingElements ?? [];
3462
+ const elements = this.#getReadingElements();
3189
3463
  const path = event.composedPath();
3190
3464
  let index = elements.findIndex((el) => path.includes(el));
3191
3465
  if (index < 0) {
@@ -3237,7 +3511,7 @@ var TestItemToSpeech = class extends LitElement13 {
3237
3511
  const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
3238
3512
  let node;
3239
3513
  while (node = walker.nextNode()) {
3240
- if ((node.textContent ?? "").length > 0) {
3514
+ if ((node.textContent ?? "").length > 0 && !node.parentElement?.closest('[aria-hidden="true"]')) {
3241
3515
  nodes.push(node);
3242
3516
  }
3243
3517
  }
@@ -3328,7 +3602,7 @@ var TestItemToSpeech = class extends LitElement13 {
3328
3602
  document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
3329
3603
  }
3330
3604
  const roots = /* @__PURE__ */ new Set();
3331
- const testContainer = this.closest("test-navigation")?.querySelector("test-container") ?? this.closest("qti-test")?.querySelector("test-container");
3605
+ const testContainer = this.closest("test-navigation")?.querySelector("test-container") ?? this.testHost?.querySelector("test-container");
3332
3606
  if (testContainer?.shadowRoot)
3333
3607
  roots.add(testContainer.shadowRoot);
3334
3608
  const ownRoot = this.getRootNode();
@@ -3344,16 +3618,16 @@ var TestItemToSpeech = class extends LitElement13 {
3344
3618
  }
3345
3619
  }
3346
3620
  };
3347
- __decorate13([
3621
+ __decorate14([
3348
3622
  property11({ type: String })
3349
3623
  ], TestItemToSpeech.prototype, "language", void 0);
3350
- __decorate13([
3351
- property11({ type: String, attribute: "item-ref-id" })
3352
- ], TestItemToSpeech.prototype, "itemRefId", void 0);
3353
- __decorate13([
3354
- consume7({ context: sessionContext, subscribe: true })
3624
+ __decorate14([
3625
+ consume8({ context: sessionContext, subscribe: true })
3355
3626
  ], TestItemToSpeech.prototype, "_sessionContext", void 0);
3356
- __decorate13([
3627
+ __decorate14([
3628
+ consume8({ context: testHostContext, subscribe: true })
3629
+ ], TestItemToSpeech.prototype, "testHost", void 0);
3630
+ __decorate14([
3357
3631
  state4(),
3358
3632
  provide3({ context: ttsContext })
3359
3633
  ], TestItemToSpeech.prototype, "_ttsContext", void 0);
@@ -3377,7 +3651,7 @@ var TestTtsPlay = class extends TtsButtonBase {
3377
3651
  `;
3378
3652
  }
3379
3653
  };
3380
- __decorate13([
3654
+ __decorate14([
3381
3655
  property11({ type: String, attribute: "pause-label" })
3382
3656
  ], TestTtsPlay.prototype, "pauseLabel", void 0);
3383
3657
  var TestTtsPause = class extends TtsButtonBase {
@@ -3466,16 +3740,54 @@ var TestTtsPick = class extends TtsButtonBase {
3466
3740
  };
3467
3741
 
3468
3742
  // ../qti-test/dist/components/test-navigation/test-navigation.js
3469
- import { consume as consume8, provide as provide4 } from "@lit/context";
3743
+ import { ContextConsumer, consume as consume9, provide as provide4 } from "@lit/context";
3470
3744
  import { html as html13, LitElement as LitElement14 } from "lit";
3471
3745
  import { property as property12, state as state5 } from "lit/decorators.js";
3472
- var __decorate14 = function(decorators, target, key, desc) {
3746
+ var __decorate15 = function(decorators, target, key, desc) {
3473
3747
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3474
3748
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3475
3749
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3476
3750
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3477
3751
  };
3752
+ var newQtiContext = () => ({
3753
+ QTI_CONTEXT: { testIdentifier: "", candidateIdentifier: "", environmentIdentifier: "default" }
3754
+ });
3478
3755
  var TestNavigation = class extends LitElement14 {
3756
+ /**
3757
+ * @deprecated Set `qtiContext` on `qti-test`, which provides it. This is an alias for the
3758
+ * enclosing test's: reading returns it, writing replaces it, so a host that has always set the
3759
+ * shuffle seed here keeps working. Removed in the next major.
3760
+ *
3761
+ * Written before the navigation is inside a test, it waits and is handed over on connect.
3762
+ */
3763
+ get qtiContext() {
3764
+ return this.#owner()?.qtiContext ?? (this.#pendingQtiContext ??= newQtiContext());
3765
+ }
3766
+ set qtiContext(value) {
3767
+ if (!this.#warnedQtiContext) {
3768
+ this.#warnedQtiContext = true;
3769
+ console.warn("[qti-components] `test-navigation.qtiContext` is deprecated and will be removed in the next major release. Set `qtiContext` on `<qti-test>` instead; it is the same value.");
3770
+ }
3771
+ this.#writeQtiContext(value);
3772
+ }
3773
+ #pendingQtiContext;
3774
+ #warnedQtiContext;
3775
+ /** The write the library itself makes. Not the deprecated setter, so it never warns about itself. */
3776
+ #writeQtiContext(value) {
3777
+ const owner = this.#owner();
3778
+ if (owner)
3779
+ owner.qtiContext = value;
3780
+ else
3781
+ this.#pendingQtiContext = value;
3782
+ }
3783
+ /**
3784
+ * The `qti-test` this navigation is in, found through context so it works across shadow roots.
3785
+ * A write made before it is known waits in `#pendingQtiContext` and is handed over on arrival.
3786
+ */
3787
+ #testHost;
3788
+ #owner() {
3789
+ return this.#testHost.value ?? null;
3790
+ }
3479
3791
  #testElement;
3480
3792
  /**
3481
3793
  * Whether each item's last *ended attempt* reached the optimal outcome, keyed
@@ -3489,22 +3801,26 @@ var TestNavigation = class extends LitElement14 {
3489
3801
  super();
3490
3802
  this.identifier = void 0;
3491
3803
  this.initContext = [];
3492
- this.qtiContext = {
3493
- QTI_CONTEXT: {
3494
- testIdentifier: "",
3495
- candidateIdentifier: "",
3496
- environmentIdentifier: "default"
3804
+ this.#warnedQtiContext = false;
3805
+ this.#testHost = new ContextConsumer(this, {
3806
+ context: testHostContext,
3807
+ subscribe: true,
3808
+ callback: (host) => {
3809
+ if (host && this.#pendingQtiContext) {
3810
+ host.qtiContext = this.#pendingQtiContext;
3811
+ this.#pendingQtiContext = void 0;
3812
+ }
3497
3813
  }
3498
- };
3814
+ });
3499
3815
  this.configContext = {};
3500
3816
  this.autoScoreItems = false;
3501
3817
  this.#optimality = /* @__PURE__ */ new Map();
3502
- this.addEventListener("qti-assessment-test-connected", this.#handleTestConnected.bind(this));
3818
+ listenPublic2(this, "cito-test-loaded", this.#handleTestConnected.bind(this));
3503
3819
  this.addEventListener("qti-assessment-item-connected", this.#handleItemConnected.bind(this));
3504
- this.addEventListener("qti-interaction-changed", this.#handleInteractionChanged.bind(this));
3820
+ listenPublic(this, "cito-item-response-changed", this.#handleInteractionChanged.bind(this));
3505
3821
  this.addEventListener("qti-item-context-updated", this.#handleItemContextUpdated.bind(this));
3506
- this.addEventListener("test-end-attempt", this.#handleTestEndAttempt.bind(this));
3507
- this.addEventListener("test-update-outcome-variable", this.#handleTestUpdateOutcomeVariable.bind(this));
3822
+ listenPublic2(this, "cito-test-end-attempt", this.#handleTestEndAttempt.bind(this));
3823
+ listenPublic2(this, "cito-test-update-outcome", this.#handleTestUpdateOutcomeVariable.bind(this));
3508
3824
  }
3509
3825
  /**
3510
3826
  * Latch whether an item reached its optimal outcome whenever it has just ended
@@ -3594,26 +3910,26 @@ var TestNavigation = class extends LitElement14 {
3594
3910
  candidateIdentifier: "not set",
3595
3911
  environmentIdentifier: "default"
3596
3912
  };
3597
- this.qtiContext = {
3913
+ this.#writeQtiContext({
3598
3914
  QTI_CONTEXT: {
3599
3915
  ...currentContext,
3600
3916
  testIdentifier: this.#testElement.identifier,
3601
3917
  environmentIdentifier: currentContext.environmentIdentifier || "default"
3602
3918
  }
3603
- };
3919
+ });
3604
3920
  }
3605
3921
  const contextDeclarations = this.#testElement.querySelectorAll('qti-context-declaration[identifier="QTI_CONTEXT"]');
3606
3922
  contextDeclarations.forEach((declaration) => {
3607
3923
  const defaultValues = this.#extractDefaultValues(declaration);
3608
3924
  if (Object.keys(defaultValues).length > 0) {
3609
- this.qtiContext = {
3925
+ this.#writeQtiContext({
3610
3926
  QTI_CONTEXT: {
3611
3927
  ...defaultValues,
3612
3928
  // Default values first
3613
3929
  ...this.qtiContext.QTI_CONTEXT
3614
3930
  // Runtime values override defaults
3615
3931
  }
3616
- };
3932
+ });
3617
3933
  }
3618
3934
  });
3619
3935
  const testPartElements = Array.from(this.#testElement?.querySelectorAll(`qti-test-part`) || []);
@@ -3785,7 +4101,7 @@ var TestNavigation = class extends LitElement14 {
3785
4101
  const response = computedItem.variables?.find((v) => v.identifier === "RESPONSE")?.value || "";
3786
4102
  const numAttempts = Number(computedItem.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
3787
4103
  const active = this._sessionContext?.navItemRefId === computedItem.identifier || false;
3788
- const valid = this.#assessmentItemFor(computedItem.identifier)?.validate(false) ?? true;
4104
+ const valid = itemContext?.valid ?? true;
3789
4105
  const responseVars = itemContext?.variables?.filter((v) => v.type === "response") || [];
3790
4106
  const isDefaultResponse = responseVars.every((v) => {
3791
4107
  if (v.value === void 0 || v.value === null) {
@@ -3937,41 +4253,37 @@ var TestNavigation = class extends LitElement14 {
3937
4253
  return Number.isNaN(parsed) ? null : parsed;
3938
4254
  }
3939
4255
  };
3940
- __decorate14([
4256
+ __decorate15([
3941
4257
  property12({ type: String })
3942
4258
  ], TestNavigation.prototype, "identifier", void 0);
3943
- __decorate14([
4259
+ __decorate15([
3944
4260
  state5()
3945
4261
  ], TestNavigation.prototype, "initContext", void 0);
3946
- __decorate14([
3947
- state5(),
3948
- provide4({ context: qtiContext })
3949
- ], TestNavigation.prototype, "qtiContext", void 0);
3950
- __decorate14([
4262
+ __decorate15([
3951
4263
  state5(),
3952
- consume8({ context: configContext, subscribe: true })
4264
+ consume9({ context: configContext, subscribe: true })
3953
4265
  ], TestNavigation.prototype, "configContext", void 0);
3954
- __decorate14([
4266
+ __decorate15([
3955
4267
  state5(),
3956
- consume8({ context: testContext, subscribe: true })
4268
+ consume9({ context: testContext, subscribe: true })
3957
4269
  ], TestNavigation.prototype, "_testContext", void 0);
3958
- __decorate14([
4270
+ __decorate15([
3959
4271
  state5(),
3960
- consume8({ context: sessionContext, subscribe: true })
4272
+ consume9({ context: sessionContext, subscribe: true })
3961
4273
  ], TestNavigation.prototype, "_sessionContext", void 0);
3962
- __decorate14([
4274
+ __decorate15([
3963
4275
  state5(),
3964
4276
  provide4({ context: computedContext })
3965
4277
  ], TestNavigation.prototype, "computedContext", void 0);
3966
- __decorate14([
4278
+ __decorate15([
3967
4279
  property12({ type: Boolean, attribute: "auto-score-items" })
3968
4280
  ], TestNavigation.prototype, "autoScoreItems", void 0);
3969
4281
 
3970
4282
  // ../qti-test/dist/components/test-next/test-next.js
3971
4283
  import { css as css8, html as html14, LitElement as LitElement15 } from "lit";
3972
4284
  import { property as property13 } from "lit/decorators.js";
3973
- import { consume as consume9 } from "@lit/context";
3974
- var __decorate15 = function(decorators, target, key, desc) {
4285
+ import { consume as consume10 } from "@lit/context";
4286
+ var __decorate16 = function(decorators, target, key, desc) {
3975
4287
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3976
4288
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3977
4289
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4038,33 +4350,26 @@ var TestNext = class extends LitElement15 {
4038
4350
  this._internalDisabled = !this.computedContext || this.itemIndex < 0 || this.itemIndex >= (this.sectionItems?.length ?? 0) - 1 || isLinearIndividual && !activeItem?.done;
4039
4351
  }
4040
4352
  _requestItem(identifier) {
4041
- this.dispatchEvent(new CustomEvent("qti-request-navigation", {
4042
- composed: true,
4043
- bubbles: true,
4044
- detail: {
4045
- type: "item",
4046
- id: identifier
4047
- }
4048
- }));
4353
+ dispatchPublic(this, "cito-test-navigate", { type: "item", id: identifier });
4049
4354
  }
4050
4355
  render() {
4051
4356
  return html14`<slot></slot>`;
4052
4357
  }
4053
4358
  };
4054
- __decorate15([
4359
+ __decorate16([
4055
4360
  property13({ type: Boolean, reflect: true, attribute: "disabled" })
4056
4361
  ], TestNext.prototype, "_internalDisabled", void 0);
4057
- __decorate15([
4058
- consume9({ context: computedContext, subscribe: true })
4362
+ __decorate16([
4363
+ consume10({ context: computedContext, subscribe: true })
4059
4364
  ], TestNext.prototype, "computedContext", void 0);
4060
- __decorate15([
4365
+ __decorate16([
4061
4366
  watch("computedContext")
4062
4367
  ], TestNext.prototype, "_handleTestElementChange", null);
4063
4368
 
4064
4369
  // ../qti-test/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js
4065
4370
  import { html as html15, LitElement as LitElement16 } from "lit";
4066
- import { consume as consume10 } from "@lit/context";
4067
- var __decorate16 = function(decorators, target, key, desc) {
4371
+ import { consume as consume11 } from "@lit/context";
4372
+ var __decorate17 = function(decorators, target, key, desc) {
4068
4373
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4069
4374
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4070
4375
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4092,15 +4397,15 @@ var TestPagingButtonsStamp = class extends LitElement16 {
4092
4397
  return html15` ${items.map((item) => this.myTemplate({ item, view: this.computedContext.view }))} `;
4093
4398
  }
4094
4399
  };
4095
- __decorate16([
4096
- consume10({ context: computedContext, subscribe: true })
4400
+ __decorate17([
4401
+ consume11({ context: computedContext, subscribe: true })
4097
4402
  ], TestPagingButtonsStamp.prototype, "computedContext", void 0);
4098
4403
 
4099
4404
  // ../qti-test/dist/components/test-prev/test-prev.js
4100
4405
  import { css as css9, html as html16, LitElement as LitElement17 } from "lit";
4101
4406
  import { property as property14 } from "lit/decorators.js";
4102
- import { consume as consume11 } from "@lit/context";
4103
- var __decorate17 = function(decorators, target, key, desc) {
4407
+ import { consume as consume12 } from "@lit/context";
4408
+ var __decorate18 = function(decorators, target, key, desc) {
4104
4409
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4105
4410
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4106
4411
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4154,34 +4459,27 @@ var TestPrev = class extends LitElement17 {
4154
4459
  this._internalDisabled = navigationMode === "linear" || !this.computedContext || this.itemIndex === 0 || this.itemIndex === -1;
4155
4460
  }
4156
4461
  _requestItem(identifier) {
4157
- this.dispatchEvent(new CustomEvent("qti-request-navigation", {
4158
- composed: true,
4159
- bubbles: true,
4160
- detail: {
4161
- type: "item",
4162
- id: identifier
4163
- }
4164
- }));
4462
+ dispatchPublic(this, "cito-test-navigate", { type: "item", id: identifier });
4165
4463
  }
4166
4464
  render() {
4167
4465
  return html16`<slot></slot>`;
4168
4466
  }
4169
4467
  };
4170
- __decorate17([
4468
+ __decorate18([
4171
4469
  property14({ type: Boolean, reflect: true, attribute: "disabled" })
4172
4470
  ], TestPrev.prototype, "_internalDisabled", void 0);
4173
- __decorate17([
4174
- consume11({ context: computedContext, subscribe: true })
4471
+ __decorate18([
4472
+ consume12({ context: computedContext, subscribe: true })
4175
4473
  ], TestPrev.prototype, "computedContext", void 0);
4176
- __decorate17([
4474
+ __decorate18([
4177
4475
  watch("computedContext")
4178
4476
  ], TestPrev.prototype, "_handleTestElementChange", null);
4179
4477
 
4180
4478
  // ../qti-test/dist/components/test-print-context/test-print-context.js
4181
4479
  import { html as html17, LitElement as LitElement18 } from "lit";
4182
- import { consume as consume12 } from "@lit/context";
4480
+ import { consume as consume13 } from "@lit/context";
4183
4481
  import { state as state6 } from "lit/decorators.js";
4184
- var __decorate18 = function(decorators, target, key, desc) {
4482
+ var __decorate19 = function(decorators, target, key, desc) {
4185
4483
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4186
4484
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4187
4485
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4192,15 +4490,15 @@ var TestPrintContext = class extends LitElement18 {
4192
4490
  return html17` <small><pre>${JSON.stringify(this.computedContext, null, 2)}</pre></small> `;
4193
4491
  }
4194
4492
  };
4195
- __decorate18([
4493
+ __decorate19([
4196
4494
  state6(),
4197
- consume12({ context: computedContext, subscribe: true })
4495
+ consume13({ context: computedContext, subscribe: true })
4198
4496
  ], TestPrintContext.prototype, "computedContext", void 0);
4199
4497
 
4200
4498
  // ../qti-test/dist/components/test-print-item-variables/test-print-item-variables.js
4201
4499
  import { html as html18, css as css10, LitElement as LitElement19 } from "lit";
4202
- import { consume as consume13 } from "@lit/context";
4203
- var __decorate19 = function(decorators, target, key, desc) {
4500
+ import { consume as consume14 } from "@lit/context";
4501
+ var __decorate20 = function(decorators, target, key, desc) {
4204
4502
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4205
4503
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4206
4504
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4272,15 +4570,15 @@ var TestPrintVariables = class extends LitElement19 {
4272
4570
  `;
4273
4571
  }
4274
4572
  };
4275
- __decorate19([
4276
- consume13({ context: computedContext, subscribe: true })
4573
+ __decorate20([
4574
+ consume14({ context: computedContext, subscribe: true })
4277
4575
  ], TestPrintVariables.prototype, "computedContext", void 0);
4278
4576
 
4279
4577
  // ../qti-test/dist/components/test-scoring-buttons/test-scoring-buttons.js
4280
4578
  import { html as html19, LitElement as LitElement20, nothing as nothing3 } from "lit";
4281
- import { consume as consume14 } from "@lit/context";
4579
+ import { consume as consume15 } from "@lit/context";
4282
4580
  import { property as property15 } from "lit/decorators.js";
4283
- var __decorate20 = function(decorators, target, key, desc) {
4581
+ var __decorate21 = function(decorators, target, key, desc) {
4284
4582
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4285
4583
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4286
4584
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4303,14 +4601,11 @@ var TestScoringButtons = class extends LitElement20 {
4303
4601
  const testPart = this.computedContext?.testParts.find((testPart2) => testPart2.active);
4304
4602
  const sectionItems = testPart.sections.flatMap((section) => section.items);
4305
4603
  const currentItemIdentifier = sectionItems.find((item) => item.active)?.identifier;
4306
- this.dispatchEvent(new CustomEvent("test-update-outcome-variable", {
4307
- detail: {
4308
- assessmentItemRefId: currentItemIdentifier,
4309
- outcomeVariableId: "SCORE",
4310
- value
4311
- },
4312
- bubbles: true
4313
- }));
4604
+ dispatchPublic(this, "cito-test-update-outcome", {
4605
+ assessmentItemRefId: currentItemIdentifier,
4606
+ outcomeVariableId: "SCORE",
4607
+ value
4608
+ });
4314
4609
  }
4315
4610
  render() {
4316
4611
  const activeItem = this.computedContext?.testParts.flatMap((testPart) => testPart.sections.flatMap((section) => section.items)).find((item) => item.active);
@@ -4339,21 +4634,21 @@ var TestScoringButtons = class extends LitElement20 {
4339
4634
  });
4340
4635
  }
4341
4636
  };
4342
- __decorate20([
4637
+ __decorate21([
4343
4638
  property15({ type: String, attribute: "view" })
4344
4639
  ], TestScoringButtons.prototype, "view", void 0);
4345
- __decorate20([
4640
+ __decorate21([
4346
4641
  property15({ type: Boolean })
4347
4642
  ], TestScoringButtons.prototype, "disabled", void 0);
4348
- __decorate20([
4349
- consume14({ context: computedContext, subscribe: true })
4643
+ __decorate21([
4644
+ consume15({ context: computedContext, subscribe: true })
4350
4645
  ], TestScoringButtons.prototype, "computedContext", void 0);
4351
4646
 
4352
4647
  // ../qti-test/dist/components/test-scoring-feedback/test-scoring-feedback.js
4353
- import { consume as consume15 } from "@lit/context";
4648
+ import { consume as consume16 } from "@lit/context";
4354
4649
  import { html as html20, LitElement as LitElement21 } from "lit";
4355
4650
  import { property as property16 } from "lit/decorators.js";
4356
- var __decorate21 = function(decorators, target, key, desc) {
4651
+ var __decorate22 = function(decorators, target, key, desc) {
4357
4652
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4358
4653
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4359
4654
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4392,17 +4687,17 @@ var TestScoringFeedback = class extends LitElement21 {
4392
4687
  return html20`<div>${feedbackText()}</div>`;
4393
4688
  }
4394
4689
  };
4395
- __decorate21([
4396
- consume15({ context: computedContext, subscribe: true })
4690
+ __decorate22([
4691
+ consume16({ context: computedContext, subscribe: true })
4397
4692
  ], TestScoringFeedback.prototype, "computedContext", void 0);
4398
- __decorate21([
4693
+ __decorate22([
4399
4694
  property16({ type: String, attribute: "view" })
4400
4695
  ], TestScoringFeedback.prototype, "view", void 0);
4401
4696
 
4402
4697
  // ../qti-test/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js
4403
4698
  import { html as html21, LitElement as LitElement22 } from "lit";
4404
- import { consume as consume16 } from "@lit/context";
4405
- var __decorate22 = function(decorators, target, key, desc) {
4699
+ import { consume as consume17 } from "@lit/context";
4700
+ var __decorate23 = function(decorators, target, key, desc) {
4406
4701
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4407
4702
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4408
4703
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4430,14 +4725,14 @@ var TestSectionButtonsStamp = class extends LitElement22 {
4430
4725
  return html21` ${sections.map((item) => this.myTemplate({ item }))} `;
4431
4726
  }
4432
4727
  };
4433
- __decorate22([
4434
- consume16({ context: computedContext, subscribe: true })
4728
+ __decorate23([
4729
+ consume17({ context: computedContext, subscribe: true })
4435
4730
  ], TestSectionButtonsStamp.prototype, "computedContext", void 0);
4436
4731
 
4437
4732
  // ../qti-test/dist/components/test-section-link/test-section-link.js
4438
4733
  import { css as css11, html as html22, LitElement as LitElement23 } from "lit";
4439
4734
  import { property as property17 } from "lit/decorators.js";
4440
- var __decorate23 = function(decorators, target, key, desc) {
4735
+ var __decorate24 = function(decorators, target, key, desc) {
4441
4736
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4442
4737
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4443
4738
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4461,14 +4756,7 @@ var TestSectionLink = class extends LitElement23 {
4461
4756
  `;
4462
4757
  }
4463
4758
  #requestItem(identifier) {
4464
- this.dispatchEvent(new CustomEvent("qti-request-navigation", {
4465
- composed: true,
4466
- bubbles: true,
4467
- detail: {
4468
- type: "section",
4469
- id: identifier
4470
- }
4471
- }));
4759
+ dispatchPublic(this, "cito-test-navigate", { type: "section", id: identifier });
4472
4760
  }
4473
4761
  constructor() {
4474
4762
  super();
@@ -4479,15 +4767,15 @@ var TestSectionLink = class extends LitElement23 {
4479
4767
  return html22` <slot></slot> `;
4480
4768
  }
4481
4769
  };
4482
- __decorate23([
4770
+ __decorate24([
4483
4771
  property17({ type: String, attribute: "section-id" })
4484
4772
  ], TestSectionLink.prototype, "sectionId", void 0);
4485
4773
 
4486
4774
  // ../qti-test/dist/components/test-stamp/test-stamp.js
4487
4775
  import { html as html23, LitElement as LitElement24, nothing as nothing4 } from "lit";
4488
4776
  import { property as property18, state as state7 } from "lit/decorators.js";
4489
- import { consume as consume17 } from "@lit/context";
4490
- var __decorate24 = function(decorators, target, key, desc) {
4777
+ import { consume as consume18 } from "@lit/context";
4778
+ var __decorate25 = function(decorators, target, key, desc) {
4491
4779
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4492
4780
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4493
4781
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4560,22 +4848,22 @@ var TestStamp = class extends LitElement24 {
4560
4848
  ${this.myTemplate ? this.myTemplate(this.stampContext) : nothing4}`;
4561
4849
  }
4562
4850
  };
4563
- __decorate24([
4851
+ __decorate25([
4564
4852
  property18({ type: Boolean, reflect: true })
4565
4853
  ], TestStamp.prototype, "debug", void 0);
4566
- __decorate24([
4854
+ __decorate25([
4567
4855
  state7(),
4568
- consume17({ context: computedContext, subscribe: true })
4856
+ consume18({ context: computedContext, subscribe: true })
4569
4857
  ], TestStamp.prototype, "computedContext", void 0);
4570
- __decorate24([
4858
+ __decorate25([
4571
4859
  state7()
4572
4860
  ], TestStamp.prototype, "stampContext", void 0);
4573
4861
 
4574
4862
  // ../qti-test/dist/components/test-view-toggle/test-view.js
4575
4863
  import { html as html24, LitElement as LitElement25 } from "lit";
4576
4864
  import { property as property19, state as state8 } from "lit/decorators.js";
4577
- import { consume as consume18 } from "@lit/context";
4578
- var __decorate25 = function(decorators, target, key, desc) {
4865
+ import { consume as consume19 } from "@lit/context";
4866
+ var __decorate26 = function(decorators, target, key, desc) {
4579
4867
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4580
4868
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4581
4869
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4607,11 +4895,7 @@ var TestView = class extends LitElement25 {
4607
4895
  }
4608
4896
  }
4609
4897
  _switchView(view) {
4610
- this.dispatchEvent(new CustomEvent("on-test-switch-view", {
4611
- composed: true,
4612
- bubbles: true,
4613
- detail: view
4614
- }));
4898
+ dispatchPublic(this, "cito-test-switch-view", view);
4615
4899
  }
4616
4900
  render() {
4617
4901
  return html24`
@@ -4630,26 +4914,26 @@ var TestView = class extends LitElement25 {
4630
4914
  }
4631
4915
  };
4632
4916
  _a = TestView;
4633
- __decorate25([
4634
- consume18({ context: sessionContext, subscribe: true })
4917
+ __decorate26([
4918
+ consume19({ context: sessionContext, subscribe: true })
4635
4919
  ], TestView.prototype, "sessionContext", void 0);
4636
- __decorate25([
4920
+ __decorate26([
4637
4921
  property19({ type: String })
4638
4922
  ], TestView.prototype, "label", void 0);
4639
- __decorate25([
4923
+ __decorate26([
4640
4924
  property19({ type: String, attribute: "view-options" })
4641
4925
  ], TestView.prototype, "viewOptions", void 0);
4642
- __decorate25([
4926
+ __decorate26([
4643
4927
  watch("viewOptions", { waitUntilFirstUpdate: true })
4644
4928
  ], TestView.prototype, "_handleViewOptionsChange", void 0);
4645
- __decorate25([
4929
+ __decorate26([
4646
4930
  state8()
4647
4931
  ], TestView.prototype, "_viewOptions", void 0);
4648
4932
 
4649
4933
  // ../qti-test/dist/components/test-view-toggle/test-view-toggle.js
4650
- import { consume as consume19 } from "@lit/context";
4934
+ import { consume as consume20 } from "@lit/context";
4651
4935
  import { html as html25, LitElement as LitElement26, nothing as nothing5 } from "lit";
4652
- var __decorate26 = function(decorators, target, key, desc) {
4936
+ var __decorate27 = function(decorators, target, key, desc) {
4653
4937
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4654
4938
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4655
4939
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -4669,11 +4953,7 @@ var TestViewToggle = class extends LitElement26 {
4669
4953
  this.myTemplate = prepareTemplate(templateElement);
4670
4954
  }
4671
4955
  _switchView(view) {
4672
- this.dispatchEvent(new CustomEvent("on-test-switch-view", {
4673
- composed: true,
4674
- bubbles: true,
4675
- detail: view
4676
- }));
4956
+ dispatchPublic(this, "cito-test-switch-view", view);
4677
4957
  }
4678
4958
  firstUpdated(_changedProperties) {
4679
4959
  this.addEventListener("click", () => {
@@ -4690,8 +4970,8 @@ var TestViewToggle = class extends LitElement26 {
4690
4970
  }) : nothing5}`;
4691
4971
  }
4692
4972
  };
4693
- __decorate26([
4694
- consume19({ context: sessionContext, subscribe: true })
4973
+ __decorate27([
4974
+ consume20({ context: sessionContext, subscribe: true })
4695
4975
  ], TestViewToggle.prototype, "sessionContext", void 0);
4696
4976
 
4697
4977
  // ../qti-test/dist/elements.js
@@ -4745,6 +5025,7 @@ export {
4745
5025
  QtiTestPart,
4746
5026
  QtiTestVariables,
4747
5027
  QtiTestVariablesExpression,
5028
+ QTI_TEST_STATE_VERSION,
4748
5029
  QtiTest,
4749
5030
  TestCheckItem,
4750
5031
  TestContainer,
@@ -4786,4 +5067,4 @@ export {
4786
5067
  * Portions Copyright (c) 2013, the Dart project authors.
4787
5068
  *)
4788
5069
  */
4789
- //# sourceMappingURL=chunk-TDWLV5OD.js.map
5070
+ //# sourceMappingURL=chunk-EUKU5QKV.js.map