@citolab/qti-components 10.0.0-next.3 → 10.0.0-next.30

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 (94) hide show
  1. package/cdn/index.global.js +1 -1
  2. package/cdn/index.js +4334 -2688
  3. package/dist/base.d.ts +39 -13
  4. package/dist/base.js +14 -1
  5. package/dist/{chunk-D3BYGEQU.js → chunk-2ZT47EUK.js} +117 -92
  6. package/dist/chunk-2ZT47EUK.js.map +1 -0
  7. package/dist/{chunk-RU6332MD.js → chunk-566LB3G2.js} +4 -4
  8. package/dist/{chunk-MI7774NV.js → chunk-5BP2A7BI.js} +2 -2
  9. package/dist/{chunk-OQDBARD5.js → chunk-5KNTKBP6.js} +2 -2
  10. package/dist/chunk-7ISPUOJG.js +209 -0
  11. package/dist/chunk-7ISPUOJG.js.map +1 -0
  12. package/dist/{chunk-GBZNFSFY.js → chunk-ADTCTKXS.js} +2 -2
  13. package/dist/{chunk-FD4AB6TM.js → chunk-BBP7QV32.js} +2 -2
  14. package/dist/{chunk-LFVPS7KB.js → chunk-CFTWXYBO.js} +2 -2
  15. package/dist/{chunk-35WWWFS6.js → chunk-DAESCCLR.js} +2 -2
  16. package/dist/chunk-DJ7PB252.js +7 -0
  17. package/dist/chunk-DJ7PB252.js.map +1 -0
  18. package/dist/{chunk-6U3YPHXU.js → chunk-GAPMCYR5.js} +277 -154
  19. package/dist/chunk-GAPMCYR5.js.map +1 -0
  20. package/dist/{chunk-TDWJ6WZA.js → chunk-GPC53O7P.js} +166 -10
  21. package/dist/chunk-GPC53O7P.js.map +1 -0
  22. package/dist/{chunk-6K3QWJHH.js → chunk-LPYZVKHX.js} +48 -7
  23. package/dist/chunk-LPYZVKHX.js.map +1 -0
  24. package/dist/{chunk-TLAVOBEM.js → chunk-O2XRZPKA.js} +356 -62
  25. package/dist/chunk-O2XRZPKA.js.map +1 -0
  26. package/dist/chunk-PZ5AY32C.js +10 -0
  27. package/dist/chunk-PZ5AY32C.js.map +1 -0
  28. package/dist/{chunk-RSMYGGQK.js → chunk-TZCOXFPB.js} +1590 -610
  29. package/dist/chunk-TZCOXFPB.js.map +1 -0
  30. package/dist/chunk-UCXLDQYA.js +56 -0
  31. package/dist/chunk-UCXLDQYA.js.map +1 -0
  32. package/dist/chunk-WWY2H2YO.js +7 -0
  33. package/dist/chunk-WWY2H2YO.js.map +1 -0
  34. package/dist/{chunk-SIE3E4FG.js → chunk-YRR6D6UP.js} +753 -2095
  35. package/dist/chunk-YRR6D6UP.js.map +1 -0
  36. package/dist/computed.types.d-BPzPFX3Z.d.ts +91 -0
  37. package/dist/{config.context.d-BvU9r-Mg.d.ts → config.context.d-Dm11aAuw.d.ts} +21 -3
  38. package/dist/corrections.d.ts +137 -24
  39. package/dist/corrections.js +12 -12
  40. package/dist/corrections.js.map +1 -1
  41. package/dist/elements.d.ts +66 -73
  42. package/dist/elements.js +9 -6
  43. package/dist/index.d.ts +21 -17
  44. package/dist/index.js +50 -61
  45. package/dist/interactions.d.ts +98 -19
  46. package/dist/interactions.js +8 -3
  47. package/dist/item.css +1948 -1946
  48. package/dist/item.d.ts +8 -6
  49. package/dist/item.js +6 -5
  50. package/dist/item.types.d-Zc6ZQDhu.d.ts +25 -0
  51. package/dist/loader.d.ts +5 -3
  52. package/dist/loader.js +3 -2
  53. package/dist/processing.d.ts +19 -7
  54. package/dist/processing.js +4 -3
  55. package/dist/public-events.d-3dGip9pd.d.ts +105 -0
  56. package/dist/qti-components-jsx.d.ts +1725 -1777
  57. package/dist/{qti-condition-expression.d-VJH6cWxf.d.ts → qti-condition-expression.d-7Kd4LBxn.d.ts} +1 -1
  58. package/dist/{qti-expression.d-BPxEp8HU.d.ts → qti-expression.d-iH3w6mqf.d.ts} +2 -1
  59. package/dist/{qti-feedback.d-wMYNVkkj.d.ts → qti-feedback.d-CT0W-8Gm.d.ts} +8 -1
  60. package/dist/{qti-item.d-DgC1AQbY.d.ts → qti-item.d-CxP6KtCH.d.ts} +3 -2
  61. package/dist/{qti-rule-base.d-Bdzg8eGH.d.ts → qti-rule-base.d-CeKP0Ooi.d.ts} +2 -2
  62. package/dist/qti-test-state-ybQ6ausy.d.ts +81 -0
  63. package/dist/qti-test-state.d-CjvdranT.d.ts +61 -0
  64. package/dist/{qti-test.d-86TlaMlI.d.ts → qti-test.d-BbtCG7A-.d.ts} +91 -487
  65. package/dist/{qti-text-entry-interaction.d-q8u5BiVK.d.ts → qti-text-entry-interaction.d-m0EFv9no.d.ts} +221 -73
  66. package/dist/{qti-transform-test.d-BL7GGFJj.d.ts → qti-transform-test.d-CtNaWJr8.d.ts} +9 -0
  67. package/dist/{interaction.d-g6XG0T0Z.d.ts → record.d-N1Bq7e1f.d.ts} +67 -4
  68. package/dist/{session.context.d-D5080LVx.d.ts → session.context.d-9gRdGK4T.d.ts} +7 -1
  69. package/dist/test-plugin-api.d.ts +143 -0
  70. package/dist/test-plugin-api.js +21 -0
  71. package/dist/test-plugin-api.js.map +1 -0
  72. package/dist/test.d.ts +72 -57
  73. package/dist/test.js +22 -48
  74. package/dist/transformers.d.ts +1 -1
  75. package/dist/transformers.js +2 -1
  76. package/dist/{item.types.d-B55QkJ92.d.ts → variables.d-DWHlTszN.d.ts} +8 -24
  77. package/package.json +16 -11
  78. package/dist/chunk-6K3QWJHH.js.map +0 -1
  79. package/dist/chunk-6U3YPHXU.js.map +0 -1
  80. package/dist/chunk-D3BYGEQU.js.map +0 -1
  81. package/dist/chunk-RSMYGGQK.js.map +0 -1
  82. package/dist/chunk-SIE3E4FG.js.map +0 -1
  83. package/dist/chunk-TDWJ6WZA.js.map +0 -1
  84. package/dist/chunk-TLAVOBEM.js.map +0 -1
  85. package/dist/chunk-ZP6QQYSU.js +0 -7
  86. package/dist/chunk-ZP6QQYSU.js.map +0 -1
  87. package/dist/computed.types.d-gJrBeUMG.d.ts +0 -42
  88. /package/dist/{chunk-RU6332MD.js.map → chunk-566LB3G2.js.map} +0 -0
  89. /package/dist/{chunk-MI7774NV.js.map → chunk-5BP2A7BI.js.map} +0 -0
  90. /package/dist/{chunk-OQDBARD5.js.map → chunk-5KNTKBP6.js.map} +0 -0
  91. /package/dist/{chunk-GBZNFSFY.js.map → chunk-ADTCTKXS.js.map} +0 -0
  92. /package/dist/{chunk-FD4AB6TM.js.map → chunk-BBP7QV32.js.map} +0 -0
  93. /package/dist/{chunk-LFVPS7KB.js.map → chunk-CFTWXYBO.js.map} +0 -0
  94. /package/dist/{chunk-35WWWFS6.js.map → chunk-DAESCCLR.js.map} +0 -0
@@ -1,19 +1,27 @@
1
1
  import {
2
- QtiModalFeedback,
3
- dispatchDeclared,
4
- listenDeclared,
2
+ button,
3
+ buttonPrimary,
4
+ control,
5
+ dispatchPublic,
6
+ itemsInOrder,
7
+ listenPublic as listenPublic2
8
+ } from "./chunk-7ISPUOJG.js";
9
+ import {
10
+ QtiModalFeedback
11
+ } from "./chunk-GAPMCYR5.js";
12
+ import {
5
13
  listenPublic
6
- } from "./chunk-6U3YPHXU.js";
14
+ } from "./chunk-UCXLDQYA.js";
7
15
  import {
8
16
  item_css_default
9
- } from "./chunk-ZP6QQYSU.js";
17
+ } from "./chunk-WWY2H2YO.js";
10
18
  import {
11
19
  watch
12
20
  } from "./chunk-4DB4SC5K.js";
13
21
  import {
14
22
  qtiTransformItem,
15
23
  qtiTransformTest
16
- } from "./chunk-TLAVOBEM.js";
24
+ } from "./chunk-O2XRZPKA.js";
17
25
  import {
18
26
  INITIAL_SESSION_CONTEXT,
19
27
  INITIAL_TEST_CONTEXT,
@@ -24,7 +32,7 @@ import {
24
32
  qtiContext,
25
33
  sessionContext,
26
34
  testContext
27
- } from "./chunk-TDWJ6WZA.js";
35
+ } from "./chunk-GPC53O7P.js";
28
36
 
29
37
  // ../qti-test/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js
30
38
  import { LitElement, nothing as nothing2 } from "lit";
@@ -636,18 +644,18 @@ var EvalAstFactory = class {
636
644
  }
637
645
  const value = this.right.evaluate(scope);
638
646
  let receiver = void 0;
639
- let property22;
647
+ let property15;
640
648
  if (this.left.type === "Getter") {
641
649
  receiver = this.left.receiver.evaluate(scope);
642
- property22 = this.left.name;
650
+ property15 = this.left.name;
643
651
  } else if (this.left.type === "Index") {
644
652
  receiver = this.left.receiver.evaluate(scope);
645
- property22 = this.left.argument.evaluate(scope);
653
+ property15 = this.left.argument.evaluate(scope);
646
654
  } else if (this.left.type === "ID") {
647
655
  receiver = scope;
648
- property22 = this.left.value;
656
+ property15 = this.left.value;
649
657
  }
650
- return receiver === void 0 ? void 0 : receiver[property22] = value;
658
+ return receiver === void 0 ? void 0 : receiver[property15] = value;
651
659
  }
652
660
  return f(this.left.evaluate(scope), this.right.evaluate(scope));
653
661
  },
@@ -1103,33 +1111,6 @@ var makeLitTemplate = (template) => {
1103
1111
  import { createContext } from "@lit/context";
1104
1112
  var testHostContext = createContext(/* @__PURE__ */ Symbol("testHost"));
1105
1113
 
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-test-items-skipped": { kind: "notification", scope: "test" },
1123
- "cito-test-end-reached": { kind: "notification", scope: "test" },
1124
- "cito-item-ref-connected": { kind: "notification", scope: "item", deprecated: "qti-assessment-item-ref-connected" }
1125
- };
1126
- function dispatchPublic(target, name, detail) {
1127
- dispatchDeclared(target, PUBLIC_EVENTS, name, detail);
1128
- }
1129
- function listenPublic2(target, name, handler) {
1130
- listenDeclared(target, PUBLIC_EVENTS, name, handler);
1131
- }
1132
-
1133
1114
  // ../qti-test/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js
1134
1115
  var __decorate = function(decorators, target, key, desc) {
1135
1116
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1191,7 +1172,7 @@ var QtiAssessmentItemRef = class extends LitElement {
1191
1172
  this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;
1192
1173
  this.requestUpdate();
1193
1174
  await this.updateComplete;
1194
- dispatchPublic(this, "cito-item-ref-connected", {
1175
+ dispatchPublic(this, "qc-item-ref-connected", {
1195
1176
  identifier: this.identifier,
1196
1177
  href: this.href,
1197
1178
  category: this.category
@@ -1323,12 +1304,6 @@ __decorate2([
1323
1304
  __decorate2([
1324
1305
  property2({ type: Boolean, converter: stringToBooleanConverter2, attribute: "keep-together" })
1325
1306
  ], QtiAssessmentSection.prototype, "keepTogether", void 0);
1326
- __decorate2([
1327
- property2({ type: String, attribute: "navigation-mode" })
1328
- ], QtiAssessmentSection.prototype, "navigationMode", void 0);
1329
- __decorate2([
1330
- property2({ type: String, attribute: "submission-mode" })
1331
- ], QtiAssessmentSection.prototype, "submissionMode", void 0);
1332
1307
  __decorate2([
1333
1308
  consume2({ context: testContext, subscribe: true })
1334
1309
  ], QtiAssessmentSection.prototype, "_testContext", void 0);
@@ -1356,7 +1331,7 @@ var QtiAssessmentTest = class extends LitElement3 {
1356
1331
  async connectedCallback() {
1357
1332
  super.connectedCallback();
1358
1333
  await this.updateComplete;
1359
- dispatchPublic(this, "cito-test-loaded", this);
1334
+ dispatchPublic(this, "qc-test-loaded", this);
1360
1335
  }
1361
1336
  render() {
1362
1337
  return html2` <slot></slot>`;
@@ -1534,7 +1509,7 @@ var QtiNumberPresented = class extends QtiExpression {
1534
1509
  #connectedTest = null;
1535
1510
  constructor() {
1536
1511
  super();
1537
- listenPublic2(this, "cito-test-loaded", (e) => this.#connectedTest = e.detail);
1512
+ listenPublic2(this, "qc-test-loaded", (e) => this.#connectedTest = e.detail);
1538
1513
  }
1539
1514
  /** The test this expression is in: handed over by a test harness, or found up the tree in a real document. */
1540
1515
  get #testElement() {
@@ -1565,10 +1540,10 @@ var QtiNumberSelected = class extends QtiExpression {
1565
1540
  #connectedTest = null;
1566
1541
  constructor() {
1567
1542
  super();
1568
- listenPublic2(this, "cito-test-loaded", (e) => this.#connectedTest = e.detail);
1543
+ listenPublic2(this, "qc-test-loaded", (e) => this.#connectedTest = e.detail);
1569
1544
  }
1570
1545
  /**
1571
- * `qti-assessment-test-connected` bubbles *up* from the test element, and this
1546
+ * `qc-test-loaded` bubbles *up* from the test element, and this
1572
1547
  * expression lives inside that test's `qti-outcome-processing` — so the
1573
1548
  * listener above only ever fires for a test handed to us directly (a test
1574
1549
  * harness). Walking up the tree is what resolves the test in a real document.
@@ -1645,6 +1620,148 @@ var QtiOutcomeProcessingProcessor = class {
1645
1620
  // ../qti-test/dist/components/qti-test-feedback/qti-test-feedback.js
1646
1621
  import { css as css4, html as html7 } from "lit";
1647
1622
  import { property as property6 } from "lit/decorators.js";
1623
+
1624
+ // ../qti-delivery/dist/model/xml-node.js
1625
+ var ELEMENT_NODE = 1;
1626
+ function childElements(parent, ...localNames) {
1627
+ const nodes = parent.childNodes;
1628
+ const children = [];
1629
+ for (let index = 0; index < nodes.length; index++) {
1630
+ const node = nodes[index];
1631
+ if (node.nodeType === ELEMENT_NODE && localNames.includes(node.localName ?? "")) {
1632
+ children.push(node);
1633
+ }
1634
+ }
1635
+ return children;
1636
+ }
1637
+ var childElement = (parent, localName) => childElements(parent, localName)[0] ?? null;
1638
+ function booleanAttribute(element, name) {
1639
+ const value = element.getAttribute(name)?.trim();
1640
+ if (value === "true" || value === "1")
1641
+ return true;
1642
+ if (value === "false" || value === "0")
1643
+ return false;
1644
+ return void 0;
1645
+ }
1646
+ function integerAttribute(element, name) {
1647
+ const value = element.getAttribute(name)?.trim();
1648
+ return value && /^[+-]?\d+$/.test(value) ? Number(value) : void 0;
1649
+ }
1650
+
1651
+ // ../qti-delivery/dist/model/test-model.js
1652
+ var DEFAULT_SESSION_CONTROL = Object.freeze({
1653
+ maxAttempts: 1,
1654
+ showFeedback: false,
1655
+ allowReview: true,
1656
+ showSolution: false,
1657
+ allowComment: false,
1658
+ allowSkipping: true,
1659
+ validateResponses: false
1660
+ });
1661
+ function buildTestModel(test) {
1662
+ if (test.localName !== "qti-assessment-test") {
1663
+ throw new TypeError(`Expected a qti-assessment-test element, not ${String(test.localName)}.`);
1664
+ }
1665
+ return {
1666
+ identifier: test.getAttribute("identifier") ?? "",
1667
+ title: test.getAttribute("title") ?? "",
1668
+ testParts: childElements(test, "qti-test-part").map(buildTestPart)
1669
+ };
1670
+ }
1671
+ function buildTestPart(part) {
1672
+ const sessionControl = resolveSessionControl(DEFAULT_SESSION_CONTROL, part);
1673
+ return {
1674
+ identifier: part.getAttribute("identifier") ?? "",
1675
+ navigationMode: part.getAttribute("navigation-mode") === "linear" ? "linear" : "nonlinear",
1676
+ submissionMode: part.getAttribute("submission-mode") === "simultaneous" ? "simultaneous" : "individual",
1677
+ sessionControl,
1678
+ sections: childElements(part, "qti-assessment-section").map((section) => buildSection(section, sessionControl))
1679
+ };
1680
+ }
1681
+ function buildSection(section, inherited) {
1682
+ const sessionControl = resolveSessionControl(inherited, section);
1683
+ return {
1684
+ kind: "section",
1685
+ identifier: section.getAttribute("identifier") ?? "",
1686
+ title: section.getAttribute("title") ?? "",
1687
+ visible: booleanAttribute(section, "visible") ?? true,
1688
+ sessionControl,
1689
+ content: childElements(section, "qti-assessment-section", "qti-assessment-item-ref").map((child) => child.localName === "qti-assessment-section" ? buildSection(child, sessionControl) : buildItemRef(child, sessionControl))
1690
+ };
1691
+ }
1692
+ function buildItemRef(itemRef, inherited) {
1693
+ const category = itemRef.getAttribute("category")?.trim();
1694
+ return {
1695
+ kind: "itemRef",
1696
+ identifier: itemRef.getAttribute("identifier") ?? "",
1697
+ href: itemRef.getAttribute("href") ?? "",
1698
+ categories: category ? category.split(/\s+/) : [],
1699
+ sessionControl: resolveSessionControl(inherited, itemRef),
1700
+ declaredSessionControl: declaredSessionControl(itemRef)
1701
+ };
1702
+ }
1703
+ function resolveSessionControl(inherited, owner) {
1704
+ return { ...inherited, ...declaredSessionControl(owner) };
1705
+ }
1706
+ function declaredSessionControl(owner) {
1707
+ const element = childElement(owner, "qti-item-session-control");
1708
+ if (!element)
1709
+ return {};
1710
+ const declared = {
1711
+ maxAttempts: integerAttribute(element, "max-attempts"),
1712
+ showFeedback: booleanAttribute(element, "show-feedback"),
1713
+ allowReview: booleanAttribute(element, "allow-review"),
1714
+ showSolution: booleanAttribute(element, "show-solution"),
1715
+ allowComment: booleanAttribute(element, "allow-comment"),
1716
+ allowSkipping: booleanAttribute(element, "allow-skipping"),
1717
+ validateResponses: booleanAttribute(element, "validate-responses")
1718
+ };
1719
+ return Object.fromEntries(Object.entries(declared).filter(([, value]) => value !== void 0));
1720
+ }
1721
+ var ownItemRefs = (section) => section.content.filter((child) => child.kind === "itemRef");
1722
+ function sectionsInOrder(sections) {
1723
+ return sections.flatMap((section) => [
1724
+ section,
1725
+ ...sectionsInOrder(section.content.filter((child) => child.kind === "section"))
1726
+ ]);
1727
+ }
1728
+ function itemRefsInOrder(sections) {
1729
+ return sections.flatMap((child) => child.kind === "itemRef" ? [child] : itemRefsInOrder(child.content));
1730
+ }
1731
+
1732
+ // ../qti-delivery/dist/model/item-facts.js
1733
+ function readItemFacts(item) {
1734
+ if (item.localName !== "qti-assessment-item") {
1735
+ throw new TypeError(`Expected a qti-assessment-item element, not ${String(item.localName)}.`);
1736
+ }
1737
+ const responseDeclarations = childElements(item, "qti-response-declaration");
1738
+ const score = childElements(item, "qti-outcome-declaration").find((declaration) => declaration.getAttribute("identifier") === "SCORE");
1739
+ return {
1740
+ identifier: item.getAttribute("identifier") ?? "",
1741
+ adaptive: booleanAttribute(item, "adaptive") ?? false,
1742
+ timeDependent: booleanAttribute(item, "time-dependent") ?? false,
1743
+ hasCorrectResponse: responseDeclarations.some(hasSomethingToCompareWith),
1744
+ hasResponseProcessing: childElement(item, "qti-response-processing") !== null,
1745
+ externalScored: externalScored(score),
1746
+ label: item.getAttribute("label"),
1747
+ title: item.getAttribute("title") ?? ""
1748
+ };
1749
+ }
1750
+ function hasSomethingToCompareWith(declaration) {
1751
+ if (childElement(declaration, "qti-correct-response"))
1752
+ return true;
1753
+ const mapping = childElement(declaration, "qti-mapping");
1754
+ if (mapping && childElement(mapping, "qti-map-entry"))
1755
+ return true;
1756
+ const areaMapping = childElement(declaration, "qti-area-mapping");
1757
+ return areaMapping !== null && childElement(areaMapping, "qti-area-map-entry") !== null;
1758
+ }
1759
+ function externalScored(declaration) {
1760
+ const value = declaration?.getAttribute("external-scored")?.trim();
1761
+ return value === "human" || value === "externalMachine" ? value : null;
1762
+ }
1763
+
1764
+ // ../qti-test/dist/components/qti-test-feedback/qti-test-feedback.js
1648
1765
  var __decorate7 = function(decorators, target, key, desc) {
1649
1766
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1650
1767
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1743,10 +1860,10 @@ var QtiTestVariables = class extends QtiExpression {
1743
1860
  #connectedTest = null;
1744
1861
  constructor() {
1745
1862
  super();
1746
- listenPublic2(this, "cito-test-loaded", (e) => this.#connectedTest = e.detail);
1863
+ listenPublic2(this, "qc-test-loaded", (e) => this.#connectedTest = e.detail);
1747
1864
  }
1748
1865
  /**
1749
- * `qti-assessment-test-connected` bubbles *up* from the test element, and this
1866
+ * `qc-test-loaded` bubbles *up* from the test element, and this
1750
1867
  * expression lives inside that test's `qti-outcome-processing` — so the
1751
1868
  * listener above only ever fires for a test handed to us directly (a test
1752
1869
  * harness). Walking up the tree is what resolves the test in a real document.
@@ -1789,10 +1906,10 @@ var QtiTestVariablesExpression = class {
1789
1906
  const uniqueItems = [...new Set(this.includedItems.map((item) => item.item))];
1790
1907
  items.forEach((item) => {
1791
1908
  if (uniqueItems.includes(item.identifier)) {
1792
- const variable = item.variables.find((vr) => vr.identifier === this.itemVariable);
1909
+ const variable2 = item.variables.find((vr) => vr.identifier === this.itemVariable);
1793
1910
  const weight = this.includedItems.find((i) => i.item === item.identifier)?.weight ?? 1;
1794
- if (variable) {
1795
- const value = Number(variable.value);
1911
+ if (variable2) {
1912
+ const value = Number(variable2.value);
1796
1913
  if (!Number.isNaN(value)) {
1797
1914
  total += value * weight;
1798
1915
  }
@@ -1806,13 +1923,53 @@ var QtiTestVariablesExpression = class {
1806
1923
  // ../qti-test/dist/types/qti-test-state.js
1807
1924
  var QTI_TEST_STATE_VERSION = 1;
1808
1925
 
1926
+ // ../qti-test/dist/state-from-contexts.js
1927
+ var VARIABLE_TYPES = ["response", "outcome", "template", "context"];
1928
+ var valueOf = (value) => {
1929
+ if (value === null || value === void 0)
1930
+ return null;
1931
+ if (Array.isArray(value))
1932
+ return value.map(String);
1933
+ return String(value);
1934
+ };
1935
+ var variable = ({ identifier, type, value }) => ({
1936
+ identifier,
1937
+ ...VARIABLE_TYPES.includes(type) ? { type } : {},
1938
+ value: valueOf(value)
1939
+ });
1940
+ var stateFromContexts = (testContext2, sessionContext2) => ({
1941
+ version: QTI_TEST_STATE_VERSION,
1942
+ test: {
1943
+ items: (testContext2?.items ?? []).filter((item) => item?.identifier).map((item) => ({
1944
+ identifier: item.identifier,
1945
+ variables: (item.variables ?? []).map(variable),
1946
+ ...item.state ? { state: { ...item.state } } : {}
1947
+ })),
1948
+ outcomes: (testContext2?.testOutcomeVariables ?? []).map((v) => ({
1949
+ identifier: v.identifier,
1950
+ value: valueOf(v.value)
1951
+ }))
1952
+ },
1953
+ session: {
1954
+ ...sessionContext2?.plugins && Object.keys(sessionContext2.plugins).length > 0 ? { plugins: { ...sessionContext2.plugins } } : {},
1955
+ ...sessionContext2?.navPartId !== void 0 ? { navPartId: sessionContext2.navPartId } : {},
1956
+ ...sessionContext2?.navSectionId !== void 0 ? { navSectionId: sessionContext2.navSectionId } : {},
1957
+ ...sessionContext2?.navItemRefId !== void 0 ? { navItemRefId: sessionContext2.navItemRefId } : {}
1958
+ }
1959
+ });
1960
+
1809
1961
  // ../qti-test/dist/components/qti-test/qti-test.js
1810
- import { ContextProvider, provide as provide2 } from "@lit/context";
1962
+ import { ContextProvider, provide as provide3 } from "@lit/context";
1811
1963
  import { html as html9, LitElement as LitElement10 } from "lit";
1812
- import { state as state2 } from "lit/decorators.js";
1964
+ import { state as state3 } from "lit/decorators.js";
1813
1965
 
1814
1966
  // ../qti-test/dist/mixins/test-navigation.mixin.js
1815
- import { property as property8 } from "lit/decorators.js";
1967
+ import { provide } from "@lit/context";
1968
+ import { property as property8, state as state2 } from "lit/decorators.js";
1969
+
1970
+ // ../qti-test/dist/internal/item-facts.context.js
1971
+ import { createContext as createContext2 } from "@lit/context";
1972
+ var itemFactsContext = createContext2(/* @__PURE__ */ Symbol("itemFacts"));
1816
1973
 
1817
1974
  // ../qti-test/dist/internal/item-sequencing.js
1818
1975
  var SECTION = "qti-assessment-section";
@@ -1919,6 +2076,7 @@ var TestNavigationMixin = (superClass) => {
1919
2076
  this.requestTimeout = 3e4;
1920
2077
  this.postLoadTransformCallback = null;
1921
2078
  this.postLoadTestTransformCallback = null;
2079
+ this.itemFacts = /* @__PURE__ */ new Map();
1922
2080
  this._activeController = null;
1923
2081
  this._loadResults = [];
1924
2082
  this._navigationId = 0;
@@ -1944,20 +2102,21 @@ var TestNavigationMixin = (superClass) => {
1944
2102
  navigateTo(type, id) {
1945
2103
  const targetId = id || this._getDefaultNavigationId(type);
1946
2104
  if (targetId) {
1947
- dispatchPublic(this, "cito-test-navigate", { type, id: targetId });
2105
+ dispatchPublic(this, "qc-test-navigate", { type, id: targetId });
1948
2106
  }
1949
2107
  }
1950
2108
  // ===========================================
1951
2109
  // EVENT HANDLER SETUP
1952
2110
  // ===========================================
1953
2111
  _bindEventHandlers() {
1954
- listenPublic2(this, "cito-test-navigate", this._handleNavigationRequest.bind(this));
1955
- listenPublic2(this, "cito-test-loaded", this._handleTestConnected.bind(this));
2112
+ listenPublic2(this, "qc-test-navigate", this._handleNavigationRequest.bind(this));
2113
+ listenPublic2(this, "qc-test-loaded", this._handleTestConnected.bind(this));
1956
2114
  this.addEventListener("qti-assessment-item-connected", this._handleItemConnected.bind(this));
1957
2115
  this.addEventListener("qti-assessment-stimulus-ref-connected", this._handleStimulusRefConnected.bind(this));
1958
2116
  }
1959
2117
  _handleTestConnected(e) {
1960
2118
  this._testElement = e.detail;
2119
+ this.itemFacts = /* @__PURE__ */ new Map();
1961
2120
  this._initializeNavigation();
1962
2121
  }
1963
2122
  /**
@@ -2029,9 +2188,9 @@ var TestNavigationMixin = (superClass) => {
2029
2188
  if (refs[0]?.closest("qti-test-part")?.getAttribute("navigation-mode") === "linear") {
2030
2189
  const first = resolveFirstItem(refs);
2031
2190
  if (first.skipped.length)
2032
- dispatchPublic(this, "cito-test-items-skipped", { ids: first.skipped });
2191
+ dispatchPublic(this, "qc-test-items-skipped", { ids: first.skipped });
2033
2192
  if (first.id === null) {
2034
- dispatchPublic(this, "cito-test-end-reached", {});
2193
+ dispatchPublic(this, "qc-test-end-reached", {});
2035
2194
  return;
2036
2195
  }
2037
2196
  id = first.id;
@@ -2050,10 +2209,7 @@ var TestNavigationMixin = (superClass) => {
2050
2209
  const currentItemRef = this._testElement?.querySelector(`qti-assessment-item-ref[identifier="${currentItemId}"]`);
2051
2210
  if (!currentItemRef)
2052
2211
  return false;
2053
- const section = currentItemRef.closest("qti-assessment-section");
2054
- const testPart = currentItemRef.closest("qti-test-part");
2055
- const navigationMode = section?.navigationMode || section?.getAttribute("navigation-mode") || testPart?.navigationMode || testPart?.getAttribute("navigation-mode") || "nonlinear";
2056
- if (navigationMode !== "linear")
2212
+ if (currentItemRef.closest("qti-test-part")?.getAttribute("navigation-mode") !== "linear")
2057
2213
  return false;
2058
2214
  const allItemRefs = Array.from(this._testElement?.querySelectorAll("qti-assessment-item-ref") || []);
2059
2215
  const currentIndex = allItemRefs.findIndex((ref) => ref.identifier === currentItemId);
@@ -2096,8 +2252,8 @@ var TestNavigationMixin = (superClass) => {
2096
2252
  const resolved = this._resolveLinearNext(detail.type, detail.id);
2097
2253
  if (resolved?.id === null) {
2098
2254
  if (resolved.skipped.length)
2099
- dispatchPublic(this, "cito-test-items-skipped", { ids: resolved.skipped });
2100
- dispatchPublic(this, "cito-test-end-reached", {});
2255
+ dispatchPublic(this, "qc-test-items-skipped", { ids: resolved.skipped });
2256
+ dispatchPublic(this, "qc-test-end-reached", {});
2101
2257
  return;
2102
2258
  }
2103
2259
  const target = resolved?.id ?? detail.id;
@@ -2113,7 +2269,7 @@ var TestNavigationMixin = (superClass) => {
2113
2269
  this._activeController = controller;
2114
2270
  await this._executeNavigation(detail.type, target, navigationId, controller);
2115
2271
  if (resolved?.skipped.length && navigationId === this._navigationId && !controller.signal.aborted) {
2116
- dispatchPublic(this, "cito-test-items-skipped", { ids: resolved.skipped });
2272
+ dispatchPublic(this, "qc-test-items-skipped", { ids: resolved.skipped });
2117
2273
  }
2118
2274
  } catch (error) {
2119
2275
  this._handleNavigationError(error, detail.type, target);
@@ -2156,13 +2312,15 @@ var TestNavigationMixin = (superClass) => {
2156
2312
  async _navigateToSection(sectionId, navigationId, controller) {
2157
2313
  const sectionEl = this._findSection(sectionId);
2158
2314
  const navPartId = sectionEl?.closest("qti-test-part")?.identifier;
2315
+ const itemIds = this._getSectionItemIds(sectionId);
2159
2316
  this.sessionContext = {
2160
2317
  ...this.sessionContext,
2161
2318
  navPartId,
2162
2319
  navSectionId: sectionId,
2163
- navItemRefId: null
2320
+ // with navigate="item", the section's first item is the current position, so test-next/test-prev
2321
+ // and item highlights have an item to work from
2322
+ navItemRefId: this.navigate === "item" ? itemIds[0] ?? null : null
2164
2323
  };
2165
- const itemIds = this._getSectionItemIds(sectionId);
2166
2324
  this._resetLoadingState();
2167
2325
  this._loadingState.expectedItems = itemIds.length;
2168
2326
  await this._loadItems(itemIds, navigationId, controller);
@@ -2290,10 +2448,14 @@ var TestNavigationMixin = (superClass) => {
2290
2448
  const validResults = results.filter(Boolean);
2291
2449
  if (this._isStaleNavigation(navigationId, controller))
2292
2450
  return;
2293
- validResults.forEach(({ itemRef, doc }) => {
2451
+ const itemFacts = new Map(this.itemFacts);
2452
+ validResults.forEach(({ itemRef, doc, facts }) => {
2294
2453
  if (itemRef && doc)
2295
2454
  itemRef.xmlDoc = doc;
2455
+ if (itemRef && facts)
2456
+ itemFacts.set(itemRef.identifier, facts);
2296
2457
  });
2458
+ this.itemFacts = itemFacts;
2297
2459
  validResults.forEach(({ itemRef }) => {
2298
2460
  const itemId = itemRef?.identifier;
2299
2461
  if (!itemRef || !itemId)
@@ -2320,7 +2482,9 @@ var TestNavigationMixin = (superClass) => {
2320
2482
  if (this._isStaleNavigation(navigationId, controller)) {
2321
2483
  return null;
2322
2484
  }
2323
- return { itemRef, doc: transformer.htmlDoc(this._customElementRegistry()) };
2485
+ const item = transformer.xmlDoc().documentElement;
2486
+ const facts = item?.localName === "qti-assessment-item" ? readItemFacts(item) : null;
2487
+ return { itemRef, doc: transformer.htmlDoc(this._customElementRegistry()), facts };
2324
2488
  } catch (error) {
2325
2489
  if (error.name === "AbortError") {
2326
2490
  console.info(`Item load for ${itemRef.identifier} was aborted`);
@@ -2390,7 +2554,7 @@ var TestNavigationMixin = (superClass) => {
2390
2554
  // EVENT DISPATCHING
2391
2555
  // ===========================================
2392
2556
  _dispatchLoadingStarted(type, id) {
2393
- dispatchPublic(this, "cito-test-navigation-started", { type, id });
2557
+ dispatchPublic(this, "qc-test-navigation-started", { type, id });
2394
2558
  }
2395
2559
  _dispatchLoadingEnded(type, id) {
2396
2560
  this.dispatchEvent(new CustomEvent("qti-navigation-loading-ended", {
@@ -2400,16 +2564,16 @@ var TestNavigationMixin = (superClass) => {
2400
2564
  }));
2401
2565
  }
2402
2566
  _dispatchError(error) {
2403
- dispatchPublic(this, "cito-test-navigation-failed", error);
2567
+ dispatchPublic(this, "qc-test-navigation-failed", error);
2404
2568
  }
2405
- /** The items are in the DOM: tell hosts the new position rendered (`cito-test-navigated`) and which items it holds. */
2569
+ /** The items are in the DOM: tell hosts the new position rendered (`qc-test-navigated`) and which items it holds. */
2406
2570
  _dispatchTestLoaded(results, type, id) {
2407
2571
  requestAnimationFrame(() => {
2408
- dispatchPublic(this, "cito-test-rendered", results.map(({ itemRef }) => ({
2572
+ dispatchPublic(this, "qc-test-rendered", results.map(({ itemRef }) => ({
2409
2573
  identifier: itemRef?.identifier,
2410
2574
  element: itemRef
2411
2575
  })));
2412
- dispatchPublic(this, "cito-test-navigated", { type, id });
2576
+ dispatchPublic(this, "qc-test-navigated", { type, id });
2413
2577
  });
2414
2578
  }
2415
2579
  }
@@ -2425,6 +2589,10 @@ var TestNavigationMixin = (superClass) => {
2425
2589
  __decorate10([
2426
2590
  property8({ attribute: false })
2427
2591
  ], TestNavigationClass.prototype, "postLoadTestTransformCallback", void 0);
2592
+ __decorate10([
2593
+ state2(),
2594
+ provide({ context: itemFactsContext })
2595
+ ], TestNavigationClass.prototype, "itemFacts", void 0);
2428
2596
  return TestNavigationClass;
2429
2597
  };
2430
2598
 
@@ -2434,11 +2602,11 @@ var TestViewMixin = (superClass) => {
2434
2602
  constructor(...args) {
2435
2603
  super(...args);
2436
2604
  this.sessionContext = { ...this.sessionContext, view: "candidate" };
2437
- listenPublic2(this, "cito-test-switch-view", (e) => {
2605
+ listenPublic2(this, "qc-test-switch-view", (e) => {
2438
2606
  this.sessionContext = { ...this.sessionContext, view: e.detail };
2439
2607
  this._updateElementView();
2440
2608
  });
2441
- listenPublic2(this, "cito-test-loaded", () => {
2609
+ listenPublic2(this, "qc-test-loaded", () => {
2442
2610
  this._updateElementView();
2443
2611
  });
2444
2612
  this.addEventListener("qti-assessment-item-connected", (e) => {
@@ -2477,7 +2645,7 @@ var TestViewMixin = (superClass) => {
2477
2645
  };
2478
2646
 
2479
2647
  // ../qti-test/dist/mixins/test-base.js
2480
- import { provide } from "@lit/context";
2648
+ import { provide as provide2 } from "@lit/context";
2481
2649
  import { LitElement as LitElement9 } from "lit";
2482
2650
  import { property as property9 } from "lit/decorators.js";
2483
2651
  var __decorate11 = function(decorators, target, key, desc) {
@@ -2505,14 +2673,14 @@ var TestBaseMixin = (superClass) => {
2505
2673
  this._updateItemVariablesInTestContext(identifier, fullVariables, void 0, context.valid);
2506
2674
  } else {
2507
2675
  const newVariables = [...assessmentItem.variables];
2508
- for (const variable of itemContext.variables) {
2509
- if (variable.identifier === "completionStatus" && variable.value === "not_attempted")
2676
+ for (const variable2 of itemContext.variables) {
2677
+ if (variable2.identifier === "completionStatus" && variable2.value === "not_attempted")
2510
2678
  continue;
2511
- const currentVariable = newVariables.find((v) => v.identifier === variable.identifier);
2679
+ const currentVariable = newVariables.find((v) => v.identifier === variable2.identifier);
2512
2680
  if (currentVariable) {
2513
- currentVariable.value = variable.value;
2681
+ currentVariable.value = variable2.value;
2514
2682
  } else {
2515
- newVariables.push(variable);
2683
+ newVariables.push(variable2);
2516
2684
  }
2517
2685
  }
2518
2686
  assessmentItem.variables = newVariables;
@@ -2531,12 +2699,13 @@ var TestBaseMixin = (superClass) => {
2531
2699
  * before the item has loaded. To restore a whole session, assign `state` instead.
2532
2700
  *
2533
2701
  * The test context is replaced rather than changed in place, so its consumers update and
2534
- * `qti-state-changed` fires.
2702
+ * `qc-test-state-changed` fires.
2535
2703
  *
2536
- * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier.
2704
+ * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier; a
2705
+ * `with-replacement` clone's instance id (`item-3#2`).
2537
2706
  * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.
2538
2707
  */
2539
- updateItemVariables(itemRefID, values, state9) {
2708
+ updateItemVariables(itemRefID, values, state6) {
2540
2709
  this.testContext = {
2541
2710
  ...this.testContext,
2542
2711
  items: this.testContext.items.map((item) => {
@@ -2556,22 +2725,22 @@ var TestBaseMixin = (superClass) => {
2556
2725
  else
2557
2726
  variables.push(updated);
2558
2727
  }
2559
- return { ...item, variables, ...state9 ? { state: { ...state9 } } : {} };
2728
+ return { ...item, variables, ...state6 ? { state: { ...state6 } } : {} };
2560
2729
  })
2561
2730
  };
2562
2731
  const assessmentItem = this._testElement?.querySelector(`qti-assessment-item-ref[identifier="${CSS.escape(itemRefID)}"]`)?.assessmentItem;
2563
2732
  if (!assessmentItem)
2564
2733
  return;
2565
2734
  assessmentItem.variables = [...this.testContext.items.find((i) => i.identifier === itemRefID)?.variables ?? []];
2566
- if (state9)
2567
- assessmentItem.state = state9;
2735
+ if (state6)
2736
+ assessmentItem.state = state6;
2568
2737
  }
2569
2738
  _initializeEventListeners() {
2570
2739
  this.addEventListener("qti-testdoc-loaded", () => {
2571
2740
  this.testContext = INITIAL_TEST_CONTEXT;
2572
2741
  this.sessionContext = INITIAL_SESSION_CONTEXT;
2573
2742
  });
2574
- listenPublic2(this, "cito-test-loaded", (e) => {
2743
+ listenPublic2(this, "qc-test-loaded", (e) => {
2575
2744
  this._testElement = e.detail;
2576
2745
  const items = Array.from(this._testElement.querySelectorAll("qti-assessment-item-ref")).map((itemRef) => {
2577
2746
  return {
@@ -2601,7 +2770,7 @@ var TestBaseMixin = (superClass) => {
2601
2770
  this._updateItemVariablesInTestContext(e.detail.itemContext.identifier, e.detail.itemContext.variables, e.detail.itemContext.state, e.detail.itemContext.valid);
2602
2771
  });
2603
2772
  }
2604
- _updateItemVariablesInTestContext(identifier, variables, state9, valid) {
2773
+ _updateItemVariablesInTestContext(identifier, variables, state6, valid) {
2605
2774
  this.testContext = {
2606
2775
  ...this.testContext,
2607
2776
  // Spread existing test context properties
@@ -2612,11 +2781,11 @@ var TestBaseMixin = (superClass) => {
2612
2781
  return {
2613
2782
  ...itemContext,
2614
2783
  // Keep other properties of the item context
2615
- variables: variables.map((variable) => {
2616
- const matchingVariable = itemContext.variables.find((v) => v.identifier === variable.identifier);
2617
- return matchingVariable ? { ...matchingVariable, ...variable } : variable;
2784
+ variables: variables.map((variable2) => {
2785
+ const matchingVariable = itemContext.variables.find((v) => v.identifier === variable2.identifier);
2786
+ return matchingVariable ? { ...matchingVariable, ...variable2 } : variable2;
2618
2787
  }),
2619
- ...state9 !== void 0 ? { state: state9 ? { ...state9 } : void 0 } : {},
2788
+ ...state6 !== void 0 ? { state: state6 ? { ...state6 } : void 0 } : {},
2620
2789
  ...valid !== void 0 ? { valid } : {}
2621
2790
  };
2622
2791
  })
@@ -2642,11 +2811,11 @@ var TestBaseMixin = (superClass) => {
2642
2811
  }
2643
2812
  __decorate11([
2644
2813
  property9({ attribute: false, type: Object }),
2645
- provide({ context: testContext })
2814
+ provide2({ context: testContext })
2646
2815
  ], TestBaseClass.prototype, "testContext", void 0);
2647
2816
  __decorate11([
2648
2817
  property9({ attribute: false, type: Object }),
2649
- provide({ context: sessionContext })
2818
+ provide2({ context: sessionContext })
2650
2819
  ], TestBaseClass.prototype, "sessionContext", void 0);
2651
2820
  return TestBaseClass;
2652
2821
  };
@@ -2656,33 +2825,15 @@ var TestBase = class extends TestBaseMixin(LitElement9) {
2656
2825
  // ../qti-test/dist/mixins/test-state.mixin.js
2657
2826
  var copy = (value) => Array.isArray(value) ? [...value] : value ?? null;
2658
2827
  var isQtiTestState = (value) => {
2659
- const state9 = value;
2660
- return state9?.version === QTI_TEST_STATE_VERSION && Array.isArray(state9.test?.items) && Array.isArray(state9.test?.outcomes) && typeof state9.session === "object" && state9.session !== null;
2828
+ const state6 = value;
2829
+ return state6?.version === QTI_TEST_STATE_VERSION && Array.isArray(state6.test?.items) && Array.isArray(state6.test?.outcomes) && typeof state6.session === "object" && state6.session !== null;
2661
2830
  };
2662
- var toState = (test, session) => ({
2663
- version: QTI_TEST_STATE_VERSION,
2664
- test: {
2665
- items: (test?.items ?? []).filter((item) => item.identifier).map((item) => ({
2666
- identifier: item.identifier,
2667
- variables: (item.variables ?? []).map((v) => ({
2668
- identifier: v.identifier,
2669
- ...v.type ? { type: v.type } : {},
2670
- value: copy(v.value)
2671
- })),
2672
- ...item.state ? { state: { ...item.state } } : {}
2673
- })),
2674
- outcomes: (test?.testOutcomeVariables ?? []).map((v) => ({ identifier: v.identifier, value: copy(v.value) }))
2675
- },
2676
- session: {
2677
- ...session?.navPartId !== void 0 ? { navPartId: session.navPartId } : {},
2678
- ...session?.navSectionId !== void 0 ? { navSectionId: session.navSectionId } : {},
2679
- ...session?.navItemRefId !== void 0 ? { navItemRefId: session.navItemRefId } : {}
2680
- }
2681
- });
2682
2831
  var TestStateMixin = (superClass) => {
2683
2832
  class TestStateClass extends superClass {
2684
2833
  /** A state assigned before the test connected, applied when it does. */
2685
2834
  #pending = null;
2835
+ /** A refused state assigned before the test connected, reported when it does. */
2836
+ #refused = null;
2686
2837
  /**
2687
2838
  * False while a test document is loading. Loading resets both contexts and rebuilds them, so
2688
2839
  * the intermediate states are empty — emitting one would invite a host to save it over the
@@ -2696,20 +2847,46 @@ var TestStateMixin = (superClass) => {
2696
2847
  this.#ready = false;
2697
2848
  this.#lastEmitted = null;
2698
2849
  });
2699
- listenPublic2(this, "cito-test-loaded", () => {
2850
+ listenPublic2(this, "qc-test-update-plugin-state", ({ detail }) => this.#updatePluginState(detail));
2851
+ listenPublic2(this, "qc-test-loaded", () => {
2700
2852
  if (this.#pending) {
2701
2853
  this.#apply(this.#pending);
2702
2854
  this.#pending = null;
2703
2855
  }
2704
2856
  this.#ready = true;
2857
+ if (this.#refused) {
2858
+ dispatchPublic(this, "qc-test-state-refused", this.#refused);
2859
+ this.#refused = null;
2860
+ }
2705
2861
  });
2706
2862
  }
2863
+ /** One plugin's entry, as JSON: the test stores it without reading it. `null` removes it. */
2864
+ #updatePluginState({ plugin, value }) {
2865
+ if (typeof plugin !== "string" || plugin === "")
2866
+ return;
2867
+ const { [plugin]: _removed, ...others } = this.sessionContext.plugins ?? {};
2868
+ let next = others;
2869
+ if (value !== null && value !== void 0) {
2870
+ try {
2871
+ next = { ...others, [plugin]: JSON.parse(JSON.stringify(value)) };
2872
+ } catch {
2873
+ console.warn(`[qti-test] Ignoring plugin state for "${plugin}": it is not JSON.`);
2874
+ return;
2875
+ }
2876
+ }
2877
+ this.sessionContext = { ...this.sessionContext, plugins: next };
2878
+ }
2707
2879
  get state() {
2708
- return toState(this.testContext, this.sessionContext);
2880
+ return stateFromContexts(this.testContext, this.sessionContext);
2709
2881
  }
2710
2882
  set state(value) {
2711
2883
  if (!isQtiTestState(value)) {
2712
- console.warn(`[qti-test] Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`);
2884
+ const message = `Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`;
2885
+ console.warn(`[qti-test] ${message}`);
2886
+ if (this.#ready)
2887
+ dispatchPublic(this, "qc-test-state-refused", { message, state: value });
2888
+ else
2889
+ this.#refused = { message, state: value };
2713
2890
  return;
2714
2891
  }
2715
2892
  if (!this.#ready) {
@@ -2729,22 +2906,39 @@ var TestStateMixin = (superClass) => {
2729
2906
  super.updated(changed);
2730
2907
  if (!this.#ready || !(changed.has("testContext") || changed.has("sessionContext")))
2731
2908
  return;
2732
- const state9 = this.state;
2733
- const serialized = JSON.stringify(state9);
2909
+ const state6 = this.state;
2910
+ const serialized = JSON.stringify(state6);
2734
2911
  if (serialized === this.#lastEmitted)
2735
2912
  return;
2736
2913
  this.#lastEmitted = serialized;
2737
- dispatchPublic(this, "cito-test-state-changed", state9);
2914
+ dispatchPublic(this, "qc-test-state-changed", state6);
2738
2915
  }
2739
- #apply(state9) {
2740
- for (const saved of state9.test.items)
2916
+ #apply(state6) {
2917
+ for (const saved of state6.test.items)
2741
2918
  this.updateItemVariables(saved.identifier, saved.variables, saved.state);
2742
- const savedOutcomes = new Map(state9.test.outcomes.map((outcome) => [outcome.identifier, outcome.value]));
2919
+ this.#warnLeftOut(state6);
2920
+ const savedOutcomes = new Map(state6.test.outcomes.map((outcome) => [outcome.identifier, outcome.value]));
2743
2921
  this.testContext = {
2744
2922
  ...this.testContext,
2745
2923
  testOutcomeVariables: this.testContext.testOutcomeVariables?.map((v) => savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v)
2746
2924
  };
2747
- this.sessionContext = { ...this.sessionContext, ...this.#validSession(state9.session) };
2925
+ this.sessionContext = {
2926
+ ...this.sessionContext,
2927
+ ...this.#validSession(state6.session),
2928
+ plugins: state6.session.plugins && typeof state6.session.plugins === "object" ? { ...state6.session.plugins } : {}
2929
+ };
2930
+ }
2931
+ /**
2932
+ * Answers for items this test does not present are not restored, and the next state leaves them
2933
+ * out: a selection (`qti-selection`) that leaves an item out, or a revised test. Said, not silent
2934
+ * (roadmap 1 T4, `plans/host-api.md` → Decided).
2935
+ */
2936
+ #warnLeftOut(state6) {
2937
+ const presented = new Set(this.testContext.items.map((item) => item.identifier));
2938
+ const leftOut = state6.test.items.map((item) => item.identifier).filter((identifier) => !presented.has(identifier));
2939
+ if (leftOut.length === 0)
2940
+ return;
2941
+ console.warn(`[qti-test] The state has answers for items this test does not present (not selected, or no longer in it); they are not restored: ${leftOut.join(", ")}.`);
2748
2942
  }
2749
2943
  /** A stored position may point at an item or section a revised test no longer has. */
2750
2944
  #validSession(session) {
@@ -2756,7 +2950,7 @@ var TestStateMixin = (superClass) => {
2756
2950
  };
2757
2951
  }
2758
2952
  #requestNavigation(type, id) {
2759
- dispatchPublic(this, "cito-test-navigate", { type, id });
2953
+ dispatchPublic(this, "qc-test-navigate", { type, id });
2760
2954
  }
2761
2955
  }
2762
2956
  return TestStateClass;
@@ -2774,6 +2968,7 @@ var TestProcessingMixin = (superClass) => {
2774
2968
  };
2775
2969
  e.stopPropagation();
2776
2970
  });
2971
+ listenPublic2(this, "qc-test-submit", () => this.submit());
2777
2972
  this.addEventListener("qti-set-outcome-value", (e) => {
2778
2973
  const { outcomeIdentifier, value } = e.detail;
2779
2974
  this.updateOutcomeVariable(outcomeIdentifier, value);
@@ -2784,7 +2979,24 @@ var TestProcessingMixin = (superClass) => {
2784
2979
  const outcomeProcessor = (this._testElement ?? this).querySelector("qti-outcome-processing");
2785
2980
  if (!outcomeProcessor)
2786
2981
  return false;
2787
- outcomeProcessor?.process();
2982
+ this.testContext = {
2983
+ ...this.testContext,
2984
+ testOutcomeVariables: this.testContext.testOutcomeVariables?.map((v) => ({
2985
+ ...v,
2986
+ value: v.defaultValue ?? null
2987
+ }))
2988
+ };
2989
+ outcomeProcessor.process();
2990
+ return true;
2991
+ }
2992
+ /**
2993
+ * Ends the test for scoring: runs `outcomeProcessing()`, then tells the host with
2994
+ * `qc-test-submitted`. Returns false, and sends nothing, when the test has no outcome processing.
2995
+ */
2996
+ submit() {
2997
+ if (!this.outcomeProcessing())
2998
+ return false;
2999
+ dispatchPublic(this, "qc-test-submitted", {});
2788
3000
  return true;
2789
3001
  }
2790
3002
  /**
@@ -2862,114 +3074,26 @@ var QtiTest = class extends TestNavigationMixin(TestViewMixin(TestProcessingMixi
2862
3074
  }
2863
3075
  };
2864
3076
  __decorate12([
2865
- state2(),
2866
- provide2({ context: configContext })
3077
+ state3(),
3078
+ provide3({ context: configContext })
2867
3079
  ], QtiTest.prototype, "configContext", void 0);
2868
3080
  __decorate12([
2869
- state2(),
2870
- provide2({ context: qtiContext })
3081
+ state3(),
3082
+ provide3({ context: qtiContext })
2871
3083
  ], QtiTest.prototype, "qtiContext", void 0);
2872
3084
 
2873
- // ../qti-test/dist/components/test-check-item/test-check-item.js
2874
- import { consume as consume6 } from "@lit/context";
2875
- import { css as css6, html as html10, LitElement as LitElement11 } from "lit";
2876
-
2877
- // ../qti-test/dist/components/styles.js
2878
- import { css as css5 } from "lit";
2879
- var form = css5`
2880
- display: inline-flex;
2881
- align-items: center;
2882
- justify-content: center;
2883
- gap: 0.375em;
2884
- box-sizing: border-box;
2885
- min-block-size: var(--test-button-size, 2.25rem);
2886
- padding: 0 0.875rem;
2887
- font: inherit;
2888
- line-height: 1.25;
2889
- cursor: pointer;
2890
- user-select: none;
2891
- border-radius: var(--test-button-border-radius, var(--qti-component-border-radius, 0.2rem));
2892
- `;
2893
- var btn = css5`
2894
- ${form};
2895
- background-color: var(--test-button-background-color, var(--qti-component-background-color, #fff));
2896
- color: var(--test-button-color, var(--qti-component-color, inherit));
2897
- border: var(--qti-component-border-width, 1px) var(--qti-component-border-style, solid)
2898
- var(--test-button-border-color, var(--qti-component-border-color, #0175aa));
2899
- `;
2900
- var btnInteractive = css5`
2901
- background-color: var(--test-button-hover-background-color, var(--qti-bg-active, #f2f8fb));
2902
- `;
2903
- var focusRing = css5`
2904
- outline: var(--qti-focus-border-width, 2px) solid var(--qti-focus-color, #007ac3);
2905
- outline-offset: 2px;
2906
- `;
2907
- var dis = css5`
2908
- cursor: not-allowed;
2909
- opacity: 0.45;
2910
- `;
2911
- var ind = css5`
2912
- ${form};
2913
- border: 1px solid gray;
2914
- `;
2915
-
2916
- // ../qti-test/dist/components/test-check-item/test-check-item.js
2917
- var __decorate13 = function(decorators, target, key, desc) {
2918
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2919
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2920
- 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;
2921
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2922
- };
2923
- var TestCheckItem = class extends LitElement11 {
2924
- static {
2925
- this.styles = css6`
2926
- :host {
2927
- ${btn};
2928
- }
2929
- :host(:hover:not([disabled])) {
2930
- ${btnInteractive};
2931
- }
2932
- :host(:focus-visible) {
2933
- ${focusRing};
2934
- }
2935
- :host([disabled]) {
2936
- ${dis};
2937
- }
2938
- `;
2939
- }
2940
- constructor() {
2941
- super();
2942
- this.addEventListener("click", () => {
2943
- dispatchPublic(this, "cito-test-end-attempt", {});
2944
- const testContainer = this.testHost?.querySelector("test-container");
2945
- if (!testContainer)
2946
- return;
2947
- const viewElements = Array.from(testContainer.shadowRoot.querySelectorAll("[view]"));
2948
- viewElements.forEach((element) => {
2949
- element.classList.toggle("show", true);
2950
- });
2951
- });
2952
- }
2953
- render() {
2954
- return html10` <slot></slot> `;
2955
- }
2956
- };
2957
- __decorate13([
2958
- consume6({ context: testHostContext, subscribe: true })
2959
- ], TestCheckItem.prototype, "testHost", void 0);
2960
-
2961
3085
  // ../qti-test/dist/components/test-container/test-container.js
2962
- import { consume as consume7 } from "@lit/context";
2963
- import { LitElement as LitElement12, html as html11 } from "lit";
2964
- import { property as property10, state as state3 } from "lit/decorators.js";
3086
+ import { consume as consume6 } from "@lit/context";
3087
+ import { LitElement as LitElement11, html as html10 } from "lit";
3088
+ import { property as property10, state as state4 } from "lit/decorators.js";
2965
3089
  import { until } from "lit/directives/until.js";
2966
- var __decorate14 = function(decorators, target, key, desc) {
3090
+ var __decorate13 = function(decorators, target, key, desc) {
2967
3091
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2968
3092
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2969
3093
  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;
2970
3094
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2971
3095
  };
2972
- var TestContainer = class extends LitElement12 {
3096
+ var TestContainer = class extends LitElement11 {
2973
3097
  constructor() {
2974
3098
  super(...arguments);
2975
3099
  this.customElementRegistry = null;
@@ -3000,7 +3124,7 @@ var TestContainer = class extends LitElement12 {
3000
3124
  return;
3001
3125
  try {
3002
3126
  const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;
3003
- let api = (await qtiTransformTest().load(this.testURL)).shuffleOrdering(explicitSeed);
3127
+ let api = (await qtiTransformTest().load(this.testURL)).applySelection(explicitSeed).shuffleOrdering(explicitSeed);
3004
3128
  const qtiTest = this.testHost;
3005
3129
  if (qtiTest?.postLoadTestTransformCallback) {
3006
3130
  const tempDoc = api.htmlDoc(this.#resolvedCustomElementRegistry ?? void 0);
@@ -3018,7 +3142,7 @@ var TestContainer = class extends LitElement12 {
3018
3142
  * Assign a new test document and announce it.
3019
3143
  *
3020
3144
  * The announcement has to happen here rather than on
3021
- * `qti-assessment-test-connected`, because by then the new document's
3145
+ * `qc-test-loaded`, because by then the new document's
3022
3146
  * children have already connected and registered themselves — a host that
3023
3147
  * resets its context on that event throws those registrations away. Lit's
3024
3148
  * re-render is async, so a handler running now still gets in before any child
@@ -3036,7 +3160,7 @@ var TestContainer = class extends LitElement12 {
3036
3160
  return;
3037
3161
  try {
3038
3162
  const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;
3039
- this.#setTestDoc(qtiTransformTest().parse(this.testXML).shuffleOrdering(explicitSeed).htmlDoc(this.#resolvedCustomElementRegistry ?? void 0));
3163
+ this.#setTestDoc(qtiTransformTest().parse(this.testXML).applySelection(explicitSeed).shuffleOrdering(explicitSeed).htmlDoc(this.#resolvedCustomElementRegistry ?? void 0));
3040
3164
  } catch (error) {
3041
3165
  console.error("Error parsing XML:", error);
3042
3166
  }
@@ -3054,7 +3178,7 @@ var TestContainer = class extends LitElement12 {
3054
3178
  }
3055
3179
  #initializeTemplateContent() {
3056
3180
  const template = this.querySelector("template");
3057
- this.#templateContent = template ? template.content : html11``;
3181
+ this.#templateContent = template ? template.content : html10``;
3058
3182
  }
3059
3183
  #applyStyles() {
3060
3184
  const sheet = new CSSStyleSheet();
@@ -3062,96 +3186,96 @@ var TestContainer = class extends LitElement12 {
3062
3186
  this.shadowRoot.adoptedStyleSheets = [sheet];
3063
3187
  }
3064
3188
  render() {
3065
- return html11`
3189
+ return html10`
3066
3190
  ${this.#templateContent}
3067
3191
  <slot></slot>
3068
- ${until(this.testDoc, html11`<span>Loading...</span>`)}
3192
+ ${until(this.testDoc, html10`<span>Loading...</span>`)}
3069
3193
  `;
3070
3194
  }
3071
3195
  };
3072
- __decorate14([
3196
+ __decorate13([
3073
3197
  property10({ attribute: false })
3074
3198
  ], TestContainer.prototype, "customElementRegistry", void 0);
3075
- __decorate14([
3199
+ __decorate13([
3076
3200
  property10({ type: String, attribute: "test-url" })
3077
3201
  ], TestContainer.prototype, "testURL", void 0);
3078
- __decorate14([
3079
- state3()
3202
+ __decorate13([
3203
+ state4()
3080
3204
  ], TestContainer.prototype, "testDoc", void 0);
3081
- __decorate14([
3082
- state3()
3205
+ __decorate13([
3206
+ state4()
3083
3207
  ], TestContainer.prototype, "testXML", void 0);
3084
- __decorate14([
3085
- consume7({ context: testHostContext, subscribe: true })
3208
+ __decorate13([
3209
+ consume6({ context: testHostContext, subscribe: true })
3086
3210
  ], TestContainer.prototype, "testHost", void 0);
3087
- __decorate14([
3088
- state3(),
3089
- consume7({ context: qtiContext, subscribe: true })
3211
+ __decorate13([
3212
+ state4(),
3213
+ consume6({ context: qtiContext, subscribe: true })
3090
3214
  ], TestContainer.prototype, "qtiContext", void 0);
3091
- __decorate14([
3215
+ __decorate13([
3092
3216
  watch("testURL", { waitUntilFirstUpdate: true })
3093
3217
  ], TestContainer.prototype, "handleTestURLChange", null);
3094
- __decorate14([
3218
+ __decorate13([
3095
3219
  watch("testXML", { waitUntilFirstUpdate: true })
3096
3220
  ], TestContainer.prototype, "handleTestXMLChange", null);
3097
3221
 
3098
3222
  // ../qti-test/dist/components/test-end-attempt/test-end-attempt.js
3099
- import { css as css7, html as html12, LitElement as LitElement13 } from "lit";
3223
+ import { LitElement as LitElement12 } from "lit";
3100
3224
  import { property as property11 } from "lit/decorators.js";
3101
- import { consume as consume8 } from "@lit/context";
3102
- var __decorate15 = function(decorators, target, key, desc) {
3225
+ import { consume as consume7 } from "@lit/context";
3226
+ var __decorate14 = function(decorators, target, key, desc) {
3103
3227
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3104
3228
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3105
3229
  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;
3106
3230
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3107
3231
  };
3108
- var TestEndAttempt = class extends LitElement13 {
3232
+ var itemRefOf = (element) => {
3233
+ const itemRef = element.closest("qti-assessment-item-ref");
3234
+ if (itemRef)
3235
+ return itemRef.getAttribute("identifier") ?? void 0;
3236
+ const root = element.getRootNode();
3237
+ return root instanceof ShadowRoot ? itemRefOf(root.host) : void 0;
3238
+ };
3239
+ var TestEndAttempt = class extends LitElement12 {
3109
3240
  _handleTestElementChange(_oldValue, newValue) {
3110
3241
  if (newValue) {
3111
3242
  this.requestUpdate();
3112
3243
  }
3113
3244
  }
3114
3245
  static {
3115
- this.styles = css7`
3116
- :host {
3117
- ${btn};
3118
- }
3119
- :host(:hover:not([disabled])) {
3120
- ${btnInteractive};
3121
- }
3122
- :host(:focus-visible) {
3123
- ${focusRing};
3124
- }
3125
- :host([disabled]) {
3126
- ${dis};
3127
- }
3128
- `;
3246
+ this.styles = button;
3129
3247
  }
3130
3248
  constructor() {
3131
3249
  super();
3132
3250
  this._internalDisabled = false;
3251
+ this.requireAnswer = false;
3133
3252
  this.addEventListener("click", (e) => {
3134
3253
  e.preventDefault();
3135
3254
  if (!this._internalDisabled) {
3136
- dispatchPublic(this, "cito-test-end-attempt", {});
3255
+ const itemId = this.#ownItem;
3256
+ dispatchPublic(this, "qc-test-end-attempt", itemId ? { itemId } : {});
3137
3257
  }
3138
3258
  });
3139
3259
  }
3260
+ /** The item named by `item`, or else the item-ref it is stamped into. */
3261
+ get #ownItem() {
3262
+ return this.item || itemRefOf(this);
3263
+ }
3140
3264
  willUpdate(_changedProperties) {
3141
3265
  this.checkDisabled();
3142
3266
  }
3143
3267
  checkDisabled() {
3144
- const testPart = this.computedContext?.testParts.find((testPart2) => testPart2.active);
3145
- if (!testPart)
3268
+ const testParts = this.computedContext?.testParts;
3269
+ const ownItem = this.#ownItem;
3270
+ const testPart = testParts?.find((testPart2) => testPart2.active);
3271
+ if (!testParts || !ownItem && !testPart)
3146
3272
  return;
3147
- const sectionItems = testPart.sections.flatMap((section) => section.items);
3148
- const itemIndex = sectionItems.findIndex((item) => item.active);
3149
- const activeItem = sectionItems[itemIndex];
3273
+ const activeItem = ownItem ? testParts.flatMap((part) => part.sections.flatMap((section) => section.items)).find((i) => i.identifier === ownItem) : testPart.sections.flatMap((section) => section.items).find((item) => item.active);
3150
3274
  if (!activeItem) {
3151
3275
  this._internalDisabled = false;
3152
3276
  return;
3153
3277
  }
3154
- const maxAttempts = activeItem.maxAttempts ?? 1;
3278
+ const maxAttempts = activeItem.sessionControl?.maxAttempts ?? 1;
3155
3279
  const numAttempts = activeItem.numAttempts || 0;
3156
3280
  if (!activeItem.adaptive && activeItem.optimal) {
3157
3281
  this._internalDisabled = true;
@@ -3165,923 +3289,234 @@ var TestEndAttempt = class extends LitElement13 {
3165
3289
  this._internalDisabled = true;
3166
3290
  return;
3167
3291
  }
3168
- if (activeItem.allowSkipping === false) {
3292
+ if (this.requireAnswer || activeItem.sessionControl?.allowSkipping === false) {
3169
3293
  this._internalDisabled = activeItem.valid === false || activeItem.isDefaultResponse;
3170
3294
  } else {
3171
3295
  this._internalDisabled = false;
3172
3296
  }
3173
3297
  }
3174
3298
  render() {
3175
- return html12` <slot></slot> `;
3299
+ return control;
3176
3300
  }
3177
3301
  };
3178
- __decorate15([
3179
- consume8({ context: computedContext, subscribe: true }),
3302
+ __decorate14([
3303
+ consume7({ context: computedContext, subscribe: true }),
3180
3304
  property11({ attribute: false })
3181
3305
  ], TestEndAttempt.prototype, "computedContext", void 0);
3182
- __decorate15([
3306
+ __decorate14([
3183
3307
  property11({ type: Boolean, reflect: true, attribute: "disabled" })
3184
3308
  ], TestEndAttempt.prototype, "_internalDisabled", void 0);
3185
- __decorate15([
3309
+ __decorate14([
3310
+ property11({ reflect: true })
3311
+ ], TestEndAttempt.prototype, "item", void 0);
3312
+ __decorate14([
3313
+ property11({ type: Boolean, reflect: true, attribute: "require-answer" })
3314
+ ], TestEndAttempt.prototype, "requireAnswer", void 0);
3315
+ __decorate14([
3186
3316
  watch("computedContext")
3187
3317
  ], TestEndAttempt.prototype, "_handleTestElementChange", null);
3188
3318
 
3189
- // ../qti-test/dist/components/test-item-link/test-item-link.js
3190
- import { css as css8, html as html13, LitElement as LitElement14 } from "lit";
3191
- import { property as property12 } from "lit/decorators.js";
3192
- var __decorate16 = function(decorators, target, key, desc) {
3193
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3194
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3195
- 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;
3196
- return c > 3 && r && Object.defineProperty(target, key, r), r;
3197
- };
3198
- var TestItemLink = class extends LitElement14 {
3199
- static {
3200
- this.styles = css8`
3201
- :host {
3202
- ${btn};
3203
- }
3204
- :host(:hover:not([disabled])) {
3205
- ${btnInteractive};
3319
+ // ../qti-test/dist/components/test-navigation/test-navigation.js
3320
+ import { ContextConsumer, consume as consume8, provide as provide4 } from "@lit/context";
3321
+ import { html as html11, LitElement as LitElement13 } from "lit";
3322
+ import { property as property12, state as state5 } from "lit/decorators.js";
3323
+
3324
+ // ../qti-test/dist/internal/derive-computed-context.js
3325
+ function deriveComputedContext(inputs) {
3326
+ const { model, sessionContext: sessionContext2, itemElement } = inputs;
3327
+ const itemIndexes = indexesInDocumentOrder(model.testParts.flatMap((part) => itemRefsInOrder(part.sections)), inputs.infoItemCategory);
3328
+ return {
3329
+ itemElement,
3330
+ identifier: model.identifier,
3331
+ title: model.title,
3332
+ view: sessionContext2?.view,
3333
+ plugins: sessionContext2?.plugins ?? {},
3334
+ testParts: model.testParts.map((testPart) => ({
3335
+ active: sessionContext2?.navPartId === testPart.identifier,
3336
+ identifier: testPart.identifier,
3337
+ navigationMode: testPart.navigationMode,
3338
+ submissionMode: testPart.submissionMode,
3339
+ allowSkipping: testPart.sessionControl.allowSkipping,
3340
+ itemOrder: itemRefsInOrder(testPart.sections).map((item) => item.identifier),
3341
+ // Flat, depth first: every section once, each with only its own item-refs, so every item is
3342
+ // listed once. Where a section's item-refs and subsections interleave, this list is not in
3343
+ // document order; `index` is.
3344
+ sections: sectionsInOrder(testPart.sections).map((section) => ({
3345
+ active: sessionContext2?.navSectionId === section.identifier,
3346
+ identifier: section.identifier,
3347
+ title: section.title,
3348
+ allowSkipping: section.sessionControl.allowSkipping,
3349
+ // A section that only holds subsections is completed when theirs are.
3350
+ completed: itemRefsInOrder(section.content).every((item) => variableValue(itemContextFor(inputs, item.identifier), "completionStatus") === "completed"),
3351
+ items: ownItemRefs(section).map((item) => deriveItem(inputs, item, itemIndexes.get(item.identifier) ?? null))
3352
+ }))
3353
+ }))
3354
+ };
3355
+ }
3356
+ function deriveItem(inputs, item, index) {
3357
+ const itemContext = itemContextFor(inputs, item.identifier);
3358
+ const computedItem = {
3359
+ active: false,
3360
+ identifier: item.identifier,
3361
+ categories: [...item.categories],
3362
+ href: item.href,
3363
+ variables: [],
3364
+ sessionControl: { ...item.sessionControl },
3365
+ ...factsFor(inputs.itemFacts, item.identifier),
3366
+ ...itemContext,
3367
+ ...inputs.itemData?.find((data) => data.identifier === item.identifier)
3368
+ };
3369
+ const rawScore = variableValue(computedItem, "SCORE");
3370
+ const score = rawScore === void 0 || rawScore === null ? null : parseFloat(rawScore.toString());
3371
+ const rawMaxScore = variableValue(computedItem, "MAXSCORE");
3372
+ const maxScore = rawMaxScore === void 0 || rawMaxScore === null ? null : parseFloat(rawMaxScore.toString());
3373
+ const completionStatus = variableValue(computedItem, "completionStatus");
3374
+ const response = variableValue(computedItem, "RESPONSE") || "";
3375
+ const numAttempts = Number(variableValue(computedItem, "numAttempts")) || 0;
3376
+ const latched = inputs.optimality.get(item.identifier);
3377
+ const optimality = latched ?? (itemContext ? assessOptimality(itemContext) : "unscored");
3378
+ return {
3379
+ ...computedItem,
3380
+ completionStatus,
3381
+ numAttempts,
3382
+ score,
3383
+ response,
3384
+ index,
3385
+ active: inputs.sessionContext?.navItemRefId === item.identifier,
3386
+ // Published by the item. One that is not on screen has nothing to be invalid.
3387
+ valid: itemContext?.valid ?? true,
3388
+ isDefaultResponse: isDefaultResponse(itemContext),
3389
+ maxScore,
3390
+ done: isItemDone(numAttempts, optimality, computedItem.sessionControl?.maxAttempts, computedItem.adaptive, completionStatus),
3391
+ // Reflects the last *ended* attempt only: the latch, not the fallback above.
3392
+ optimal: latched === "optimal"
3393
+ };
3394
+ }
3395
+ function itemContextFor(inputs, identifier) {
3396
+ return inputs.testContext?.items?.find((item) => item.identifier === identifier);
3397
+ }
3398
+ function variableValue(item, identifier) {
3399
+ return item?.variables?.find((variable2) => variable2.identifier === identifier)?.value;
3400
+ }
3401
+ function factsFor(itemFacts, identifier) {
3402
+ const facts = itemFacts?.get(identifier);
3403
+ if (!facts)
3404
+ return {};
3405
+ const { identifier: assessmentItemIdentifier, ...rest } = facts;
3406
+ return { ...rest, assessmentItemIdentifier };
3407
+ }
3408
+ function indexesInDocumentOrder(items, infoItemCategory) {
3409
+ let index = 1;
3410
+ return new Map(items.map((item) => [item.identifier, item.categories.includes(infoItemCategory) ? null : index++]));
3411
+ }
3412
+ function isDefaultResponse(itemContext) {
3413
+ const responseVariables = itemContext?.variables?.filter((v) => v.type === "response" && v.identifier !== "numAttempts") || [];
3414
+ return responseVariables.every((v) => {
3415
+ if (v.value === void 0 || v.value === null)
3416
+ return true;
3417
+ let fallbackValue;
3418
+ switch (v.baseType) {
3419
+ case "integer":
3420
+ case "float":
3421
+ case "duration":
3422
+ fallbackValue = "0";
3423
+ break;
3424
+ case "boolean":
3425
+ fallbackValue = "false";
3426
+ break;
3427
+ default:
3428
+ fallbackValue = "";
3429
+ break;
3206
3430
  }
3207
- :host(:focus-visible) {
3208
- ${focusRing};
3431
+ const defaultValue = v.defaultValue ?? fallbackValue;
3432
+ if (Array.isArray(v.value)) {
3433
+ const dv = Array.isArray(defaultValue) ? defaultValue : [defaultValue];
3434
+ return v.value.length === dv.length && v.value.every((val, i) => val === dv[i]);
3209
3435
  }
3210
- :host([disabled]) {
3211
- ${dis};
3436
+ return v.value === defaultValue;
3437
+ });
3438
+ }
3439
+ function isItemDone(numAttempts, optimality, maxAttempts, adaptive, completionStatus) {
3440
+ if (numAttempts === 0)
3441
+ return false;
3442
+ if (adaptive)
3443
+ return completionStatus === "completed";
3444
+ if (optimality !== "suboptimal")
3445
+ return true;
3446
+ const max = maxAttempts ?? 1;
3447
+ return max > 0 && numAttempts >= max;
3448
+ }
3449
+ function assessOptimality(item) {
3450
+ const variables = item.variables ?? [];
3451
+ const score = numericVariable(variables, "SCORE");
3452
+ const maxScore = numericVariable(variables, "MAXSCORE");
3453
+ if (score !== null && maxScore !== null) {
3454
+ return score >= maxScore ? "optimal" : "suboptimal";
3455
+ }
3456
+ const responseVars = variables.filter((v) => v.type === "response" && v.correctResponse !== void 0 && v.correctResponse !== null);
3457
+ if (responseVars.length === 0)
3458
+ return "unscored";
3459
+ const allMatch = responseVars.every((v) => {
3460
+ const expected = v.correctResponse;
3461
+ const actual = v.value;
3462
+ if (actual === void 0 || actual === null)
3463
+ return false;
3464
+ if (Array.isArray(expected) && Array.isArray(actual)) {
3465
+ return expected.length === actual.length && expected.every((e) => actual.includes(e));
3212
3466
  }
3213
- `;
3214
- }
3215
- constructor() {
3216
- super();
3217
- this.itemId = null;
3218
- this.addEventListener("click", () => this._requestItem(this.itemId));
3219
- }
3220
- _requestItem(identifier) {
3221
- dispatchPublic(this, "cito-test-navigate", { type: "item", id: identifier });
3222
- }
3223
- render() {
3224
- return html13` <slot></slot> `;
3225
- }
3226
- };
3227
- __decorate16([
3228
- property12({ type: String, attribute: "item-id" })
3229
- ], TestItemLink.prototype, "itemId", void 0);
3467
+ if (Array.isArray(expected) || Array.isArray(actual))
3468
+ return false;
3469
+ return expected === actual;
3470
+ });
3471
+ return allMatch ? "optimal" : "suboptimal";
3472
+ }
3473
+ function numericVariable(variables, identifier) {
3474
+ const raw = variables?.find((v) => v.identifier === identifier)?.value;
3475
+ if (raw === void 0 || raw === null || Array.isArray(raw))
3476
+ return null;
3477
+ const parsed = parseFloat(raw.toString());
3478
+ return Number.isNaN(parsed) ? null : parsed;
3479
+ }
3230
3480
 
3231
- // ../qti-test/dist/components/test-item-to-speech/test-item-to-speech.js
3232
- import { html as html14, LitElement as LitElement15, css as css9 } from "lit";
3233
- import { consume as consume9, provide as provide3, createContext as createContext2 } from "@lit/context";
3234
- import { property as property13, state as state4 } from "lit/decorators.js";
3235
- import { ifDefined } from "lit/directives/if-defined.js";
3236
- var __decorate17 = function(decorators, target, key, desc) {
3481
+ // ../qti-test/dist/internal/rendered-markup.js
3482
+ function renderedMarkup(element) {
3483
+ return {
3484
+ nodeType: element.nodeType,
3485
+ localName: element.localName,
3486
+ get childNodes() {
3487
+ return Array.from(element.children, renderedMarkup);
3488
+ },
3489
+ getAttribute: (name) => element.getAttribute(name) ?? (name === "title" ? element.getAttribute("data-title") : null)
3490
+ };
3491
+ }
3492
+
3493
+ // ../qti-test/dist/components/test-navigation/test-navigation.js
3494
+ var __decorate15 = function(decorators, target, key, desc) {
3237
3495
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3238
3496
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3239
3497
  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;
3240
3498
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3241
3499
  };
3242
- var HIGHLIGHT_ELEMENT = "tts-element";
3243
- var HIGHLIGHT_WORD = "tts-word";
3244
- var highlightSheet = null;
3245
- function getHighlightSheet() {
3246
- if (!highlightSheet) {
3247
- highlightSheet = new CSSStyleSheet();
3248
- highlightSheet.replaceSync(`
3249
- ::highlight(${HIGHLIGHT_ELEMENT}) { background-color: #dbeafe; color: inherit; }
3250
- ::highlight(${HIGHLIGHT_WORD}) { background-color: #ffe066; color: inherit; }
3251
- `);
3252
- }
3253
- return highlightSheet;
3254
- }
3255
- var ttsContext = createContext2(/* @__PURE__ */ Symbol("tts-context"));
3256
- var ICONS = {
3257
- play: "M8 5v14l11-7z",
3258
- pause: "M6 5h4v14H6zM14 5h4v14h-4z",
3259
- stop: "M6 6h12v12H6z",
3260
- prev: "M6 5h2v14H6zM20 5v14L9 12z",
3261
- next: "M16 5h2v14h-2zM4 5v14l11-7z",
3262
- pick: "M5 3l13 7-5.5 1.6 3.4 6.6-2.4 1.3-3.4-6.7L6 17z"
3263
- };
3264
- var iconContent = (icon, label) => {
3265
- const svg = html14`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
3266
- <path d="${ICONS[icon]}"></path>
3267
- </svg>`;
3268
- return html14`${svg}<span class="label">${label}</span>`;
3269
- };
3270
- var TtsButtonBase = class extends LitElement15 {
3271
- static {
3272
- this.styles = css9`
3273
- :host {
3274
- display: inline-flex;
3275
- }
3276
- button {
3277
- ${btn};
3278
- min-inline-size: var(--test-button-size, 2.25rem);
3279
- padding-inline: 0.5rem;
3280
- /* Containing block for the visually hidden .label. Without it the label is placed against
3281
- the nearest positioned ancestor, which can sit outside a scroll container and make the
3282
- page as tall as the scrolled content. */
3283
- position: relative;
3284
- }
3285
- button:hover:not(:disabled) {
3286
- ${btnInteractive};
3287
- }
3288
- button:focus-visible {
3289
- ${focusRing};
3290
- }
3291
- button:disabled {
3292
- ${dis};
3293
- }
3294
- button[aria-pressed='true'],
3295
- button[aria-pressed='true']:hover {
3296
- background-color: var(--test-button-selected-background-color, var(--qti-selected-bg, #0175aa));
3297
- color: var(--test-button-selected-color, var(--qti-selected-color, #fff));
3298
- }
3299
- svg,
3300
- ::slotted(svg) {
3301
- flex: none;
3302
- inline-size: var(--test-tts-icon-size, 1.125rem);
3303
- block-size: var(--test-tts-icon-size, 1.125rem);
3304
- }
3305
- svg {
3306
- fill: currentColor;
3307
- }
3308
- /* The default content is icon-only; this keeps the button's accessible name. */
3309
- .label {
3310
- position: absolute;
3311
- inline-size: 1px;
3312
- block-size: 1px;
3313
- overflow: hidden;
3314
- clip-path: inset(50%);
3315
- white-space: nowrap;
3316
- }
3317
- `;
3318
- }
3319
- #internals = this.attachInternals();
3320
- #mirroredState;
3321
- #mirroredPicking = false;
3322
- updated(_changed) {
3323
- const state9 = this._tts?.state;
3324
- const picking = this._tts?.picking ?? false;
3325
- if (state9 === this.#mirroredState && picking === this.#mirroredPicking)
3326
- return;
3327
- this.#mirroredState = state9;
3328
- this.#mirroredPicking = picking;
3329
- this.#internals.states.clear();
3330
- if (state9)
3331
- this.#internals.states.add(state9);
3332
- if (picking)
3333
- this.#internals.states.add("picking");
3500
+ var newQtiContext = () => ({
3501
+ QTI_CONTEXT: { testIdentifier: "", candidateIdentifier: "", environmentIdentifier: "default" }
3502
+ });
3503
+ var TestNavigation = class extends LitElement13 {
3504
+ /**
3505
+ * @deprecated Set `qtiContext` on `qti-test`, which provides it. This is an alias for the
3506
+ * enclosing test's: reading returns it, writing replaces it, so a host that has always set the
3507
+ * shuffle seed here keeps working. Removed in the next major.
3508
+ *
3509
+ * Written before the navigation is inside a test, it waits and is handed over on connect.
3510
+ */
3511
+ get qtiContext() {
3512
+ return this.#owner()?.qtiContext ?? (this.#pendingQtiContext ??= newQtiContext());
3334
3513
  }
3335
- };
3336
- __decorate17([
3337
- property13({ type: String })
3338
- ], TtsButtonBase.prototype, "label", void 0);
3339
- __decorate17([
3340
- consume9({ context: ttsContext, subscribe: true })
3341
- ], TtsButtonBase.prototype, "_tts", void 0);
3342
- var TestItemToSpeech = class extends LitElement15 {
3343
- static {
3344
- this.styles = css9`
3345
- :host {
3346
- display: inline-flex;
3347
- flex-wrap: wrap;
3348
- align-items: center;
3349
- gap: var(--test-tts-gap, 0.25rem);
3514
+ set qtiContext(value) {
3515
+ if (!this.#warnedQtiContext) {
3516
+ this.#warnedQtiContext = true;
3517
+ 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.");
3350
3518
  }
3351
- `;
3352
- }
3353
- #internals;
3354
- // Stimulus mode: set on connect when a stimulus placeholder sits next to the player. The
3355
- // placeholder itself is looked up on every use — a host may swap the element.
3356
- #stimulusMode;
3357
- // Stimulus mode: resets the player when the stimulus content next to it is replaced.
3358
- #stimulusObserver;
3359
- // Content mode: set on connect when a `[data-tts-content]` element sits next to the player.
3360
- // Any HTML, not QTI. No observer: the reading list is rebuilt on demand (#getReadingElements).
3361
- #contentMode;
3362
- // Item-ref mode: the item-ref this player sits in, resolved on connect. Null means cursor mode.
3363
- #itemRef;
3364
- // Where the item-connected (and, in cursor mode, navigation) events are listened for.
3365
- #eventHost;
3366
- #boundHandleItemConnected;
3367
- #boundHandleNavigation;
3368
- // Cursor mode: the previous navigation position, to detect moving to another item or section.
3369
- #prevNavItemRefId;
3370
- #prevNavSectionId;
3371
- // Current set of block-level reading elements for the item
3372
- #readingElements;
3373
- #currentElementIndex;
3374
- // Text nodes of the element currently being spoken (for word-boundary highlight)
3375
- #textNodes;
3376
- // The utterance this player is speaking; lets the error handler tell "our speech was
3377
- // cancelled by another player" apart from a cancel we issued ourselves.
3378
- #currentUtterance;
3379
- // Pick mode: all elements highlighted, a click on one starts reading from there.
3380
- #picking;
3381
- #pickRoot;
3382
- #boundHandlePickClick;
3383
- // Set when the last element has been read: the cursor stays on it (so prev still works),
3384
- // but the next play starts the item over instead of repeating that last element.
3385
- #finished;
3386
- // Two separate CSS Highlight objects
3387
- #elementHighlight;
3388
- // whole-element cursor
3389
- #wordHighlight;
3390
- // current word during speech
3391
- constructor() {
3392
- super();
3393
- this.language = "nl-NL";
3394
- this.#internals = this.attachInternals();
3395
- this.#stimulusMode = false;
3396
- this.#stimulusObserver = null;
3397
- this.#contentMode = false;
3398
- this.#itemRef = null;
3399
- this.#eventHost = null;
3400
- this.#boundHandleItemConnected = this.#handleItemConnected.bind(this);
3401
- this.#boundHandleNavigation = () => this.#stop();
3402
- this.#prevNavItemRefId = void 0;
3403
- this.#prevNavSectionId = void 0;
3404
- this.#readingElements = null;
3405
- this.#currentElementIndex = 0;
3406
- this.#textNodes = [];
3407
- this.#currentUtterance = null;
3408
- this.#picking = false;
3409
- this.#pickRoot = null;
3410
- this.#boundHandlePickClick = this.#handlePickClick.bind(this);
3411
- this.#finished = false;
3412
- this.#elementHighlight = new Highlight();
3413
- this.#wordHighlight = new Highlight();
3414
- this._ttsContext = {
3415
- state: "idle",
3416
- currentElementIndex: 0,
3417
- elementCount: 0,
3418
- play: () => this.#playSpeech(),
3419
- pause: () => this.#pause(),
3420
- resume: () => this.#resume(),
3421
- stop: () => {
3422
- this.#stopPicking();
3423
- this.#stop();
3424
- },
3425
- prevElement: () => this.#prevElement(),
3426
- nextElement: () => this.#nextElement(),
3427
- togglePick: () => this.#togglePick(),
3428
- picking: false
3429
- };
3430
- }
3431
- // willUpdate, not updated: resetting writes _ttsContext, and state set here goes into the
3432
- // render already under way instead of scheduling a second one (Lit's change-in-update).
3433
- willUpdate(changed) {
3434
- super.willUpdate(changed);
3435
- if (this.#stimulusMode || this.#contentMode || this.#itemRef)
3436
- return;
3437
- const item = this._sessionContext?.navItemRefId ?? null;
3438
- const section = this._sessionContext?.navSectionId ?? null;
3439
- const itemChanged = this.#prevNavItemRefId !== void 0 && this.#prevNavItemRefId !== item;
3440
- const sectionChanged = this.#prevNavSectionId !== void 0 && this.#prevNavSectionId !== section;
3441
- if (itemChanged || sectionChanged)
3442
- this.#resetReadingPosition();
3443
- this.#prevNavItemRefId = item;
3444
- this.#prevNavSectionId = section;
3445
- }
3446
- /** Stop speech and forget the collected reading elements, so the next play starts afresh. */
3447
- #resetReadingPosition() {
3448
- this.#stopPicking();
3449
- this.#stop();
3450
- this.#readingElements = null;
3451
- this.#currentElementIndex = 0;
3452
- this.#finished = false;
3453
- this.#updateContext();
3454
- }
3455
- connectedCallback() {
3456
- super.connectedCallback();
3457
- this.#setSpeechState("idle");
3458
- this.#stimulusMode = this.#stimulusPlaceholder() !== null;
3459
- if (this.#stimulusMode) {
3460
- this.#stimulusObserver = new MutationObserver((records) => {
3461
- if (records.some((record) => !this.contains(record.target)))
3462
- this.#handleStimulusReplaced();
3463
- });
3464
- this.#stimulusObserver.observe(this.parentElement, { childList: true, subtree: true });
3465
- return;
3466
- }
3467
- this.#contentMode = this.#contentElement() !== null;
3468
- if (this.#contentMode)
3469
- return;
3470
- this.#itemRef = this.closest("qti-assessment-item-ref");
3471
- this.#eventHost = this.#itemRef ?? this.closest("test-navigation") ?? this.testHost ?? this.getRootNode();
3472
- this.#eventHost.addEventListener("qti-assessment-item-connected", this.#boundHandleItemConnected);
3473
- if (!this.#itemRef) {
3474
- this.#eventHost.addEventListener("cito-test-navigate", this.#boundHandleNavigation);
3475
- this.#eventHost.addEventListener("qti-request-navigation", this.#boundHandleNavigation);
3476
- }
3477
- }
3478
- disconnectedCallback() {
3479
- super.disconnectedCallback();
3480
- if (this.#currentUtterance) {
3481
- this.#currentUtterance = null;
3482
- speechSynthesis.cancel();
3483
- }
3484
- this.#stopPicking();
3485
- this.#clearAllHighlights();
3486
- this.#eventHost?.removeEventListener("qti-assessment-item-connected", this.#boundHandleItemConnected);
3487
- this.#eventHost?.removeEventListener("cito-test-navigate", this.#boundHandleNavigation);
3488
- this.#eventHost?.removeEventListener("qti-request-navigation", this.#boundHandleNavigation);
3489
- this.#eventHost = null;
3490
- this.#itemRef = null;
3491
- this.#stimulusObserver?.disconnect();
3492
- this.#stimulusObserver = null;
3493
- this.#stimulusMode = false;
3494
- this.#contentMode = false;
3495
- }
3496
- render() {
3497
- return html14`<slot></slot>`;
3498
- }
3499
- /**
3500
- * An item (re)rendered. If it is ours — e.g. after navigating to the item already shown — the
3501
- * elements collected earlier are detached now. That does not move the navigation cursor, so
3502
- * the check in updated() does not catch it.
3503
- */
3504
- #handleItemConnected(event) {
3505
- if (this.#readingElements === null)
3506
- return;
3507
- const identifier = event.detail?.identifier;
3508
- if (this.#itemRef || identifier === this._sessionContext?.navItemRefId)
3509
- this.#resetReadingPosition();
3510
- }
3511
- /**
3512
- * Stimulus mode: the stimulus next to the player was (re)loaded or swapped. Forget what was
3513
- * collected, so the next play reads the new content from the top. Unlike
3514
- * #resetReadingPosition this only cancels speech that is ours: a stimulus can finish loading
3515
- * while an item player on the same page is speaking.
3516
- */
3517
- #handleStimulusReplaced() {
3518
- if (this.#currentUtterance) {
3519
- this.#currentUtterance = null;
3520
- speechSynthesis.cancel();
3521
- }
3522
- this.#stopPicking();
3523
- this.#clearAllHighlights();
3524
- this.#setSpeechState("idle");
3525
- this.#readingElements = null;
3526
- this.#currentElementIndex = 0;
3527
- this.#finished = false;
3528
- this.#updateContext();
3529
- }
3530
- /**
3531
- * Stimulus mode: the `[data-stimulus-idref]` placeholder that shares this player's parent, or
3532
- * null. A placeholder holds the stimulus once loaded; the player cannot sit inside it, because
3533
- * loading replaces the placeholder's content.
3534
- */
3535
- #stimulusPlaceholder() {
3536
- return this.parentElement?.querySelector(":scope > [data-stimulus-idref]") ?? null;
3537
- }
3538
- /**
3539
- * Content mode: the `[data-tts-content]` element that shares this player's parent, or null.
3540
- * The marker goes on one container; the player finds the readable elements inside it.
3541
- */
3542
- #contentElement() {
3543
- return this.parentElement?.querySelector(":scope > [data-tts-content]") ?? null;
3544
- }
3545
- /**
3546
- * The element whose text is read: the stimulus body next to the player (stimulus mode), the
3547
- * marked content next to it (content mode), or the item body of the item to read.
3548
- */
3549
- #resolveReadingRoot() {
3550
- if (this.#stimulusMode)
3551
- return this.#stimulusPlaceholder()?.querySelector("qti-stimulus-body") ?? null;
3552
- if (this.#contentMode)
3553
- return this.#contentElement();
3554
- return this.#resolveItem()?.querySelector("qti-item-body") ?? null;
3555
- }
3556
- /** The item to read: our item-ref's (item-ref mode), or the navigated one (cursor mode). */
3557
- #resolveItem() {
3558
- if (this.#itemRef)
3559
- return this.#itemRef.assessmentItem;
3560
- const identifier = this._sessionContext?.navItemRefId;
3561
- return identifier ? this.#findItemInDom(identifier) : null;
3562
- }
3563
- /**
3564
- * Cursor mode: find the rendered item for an item-ref identifier. Our own `<qti-test>` first —
3565
- * a page can hold several tests showing the same item — then every root from here up to the
3566
- * document; each scope directly and in the `test-container` shadow roots inside it.
3567
- */
3568
- #findItemInDom(identifier) {
3569
- const selector = `qti-assessment-item-ref[identifier="${CSS.escape(identifier)}"] qti-assessment-item`;
3570
- const search = (scope) => {
3571
- const direct = scope.querySelector(selector);
3572
- if (direct)
3573
- return direct;
3574
- for (const container of Array.from(scope.querySelectorAll("test-container"))) {
3575
- const inShadow = container.shadowRoot?.querySelector(selector);
3576
- if (inShadow)
3577
- return inShadow;
3578
- }
3579
- return null;
3580
- };
3581
- const test = this.closest("qti-test");
3582
- const inTest = test && search(test);
3583
- if (inTest)
3584
- return inTest;
3585
- let root = this.getRootNode();
3586
- for (; ; ) {
3587
- const found = search(root);
3588
- if (found)
3589
- return found;
3590
- const host = root.host;
3591
- if (!host)
3592
- return null;
3593
- root = host.getRootNode();
3594
- }
3595
- }
3596
- /** Update speech state on both the context (notifies children) and the host's CSS custom states. */
3597
- #setSpeechState(state9) {
3598
- this._ttsContext = { ...this._ttsContext, state: state9 };
3599
- this.#internals.states.delete("idle");
3600
- this.#internals.states.delete("playing");
3601
- this.#internals.states.delete("paused");
3602
- this.#internals.states.add(state9);
3603
- }
3604
- /** Push currentElementIndex and elementCount into context so children can react. */
3605
- #updateContext() {
3606
- this._ttsContext = {
3607
- ...this._ttsContext,
3608
- currentElementIndex: this.#currentElementIndex,
3609
- elementCount: this.#getReadingElements().length
3610
- };
3611
- }
3612
- /**
3613
- * Return the currently readable elements: cached candidates for the item or stimulus (collected lazily on
3614
- * first call), filtered live for visibility on every call. Feedback and other
3615
- * conditionally-shown content (e.g. `qti-feedback-block`, which is `display: none` until a
3616
- * CSS custom state reveals it) is excluded while hidden and picked up again once shown,
3617
- * without needing to re-collect the candidate set.
3618
- */
3619
- #getReadingElements() {
3620
- if (this.#contentMode && this.#readingElements?.some((el) => !el.isConnected)) {
3621
- this.#readingElements = null;
3622
- this.#currentElementIndex = 0;
3623
- this.#finished = false;
3624
- }
3625
- if (this.#readingElements === null) {
3626
- const root = this.#resolveReadingRoot();
3627
- if (!root)
3628
- return [];
3629
- const selector = "p, h1, h2, h3, h4, h5, h6, li, dt, dd, th, td, caption, blockquote, figcaption, qti-prompt, qti-simple-choice";
3630
- this.#readingElements = Array.from(root.querySelectorAll(selector)).filter((el) => (el.textContent ?? "").trim().length > 0 && !el.querySelector(selector) && !el.closest('[aria-hidden="true"]'));
3631
- }
3632
- return this.#readingElements.filter((el) => this.#isVisible(el));
3633
- }
3634
- /** True when an element is actually rendered — not `display: none` (itself or an ancestor). */
3635
- #isVisible(element) {
3636
- if (typeof element.checkVisibility === "function") {
3637
- return element.checkVisibility({ checkOpacity: false, checkVisibilityCSS: true });
3638
- }
3639
- return element.getClientRects().length > 0;
3640
- }
3641
- /**
3642
- * Resolve the speech language for a reading element.
3643
- * Element `lang` → closest ancestor `lang` (crossing shadow hosts) → `<html lang>` → `language` attribute.
3644
- * Empty `lang=""` is treated as absent.
3645
- */
3646
- #resolveLang(element) {
3647
- let node = element;
3648
- while (node) {
3649
- const lang = node.getAttribute("lang") || node.getAttribute("xml:lang");
3650
- if (lang?.trim())
3651
- return lang.trim();
3652
- node = node.parentElement ?? node.getRootNode().host ?? null;
3653
- }
3654
- const documentLang = document.documentElement.getAttribute("lang");
3655
- if (documentLang?.trim())
3656
- return documentLang.trim();
3657
- return this.language;
3658
- }
3659
- #playSpeech() {
3660
- const elements = this.#getReadingElements();
3661
- if (!elements.length) {
3662
- console.warn("test-item-to-speech: no readable elements found");
3663
- return;
3664
- }
3665
- this.#stopPicking();
3666
- speechSynthesis.cancel();
3667
- if (this.#finished) {
3668
- this.#finished = false;
3669
- this.#currentElementIndex = 0;
3670
- }
3671
- if (this.#contentMode && this.#currentElementIndex === 0)
3672
- this.#readingElements = null;
3673
- this.#speakElement(this.#currentElementIndex);
3674
- }
3675
- /** Speak the element at the given index, then auto-advance when it ends. */
3676
- #speakElement(index) {
3677
- const elements = this.#getReadingElements();
3678
- if (index >= elements.length) {
3679
- this.#clearWordHighlight();
3680
- this.#currentElementIndex = elements.length - 1;
3681
- if (elements.length > 0)
3682
- this.#highlightElement(elements[this.#currentElementIndex]);
3683
- this.#finished = true;
3684
- this.#setSpeechState("idle");
3685
- this.#updateContext();
3686
- return;
3687
- }
3688
- this.#currentElementIndex = index;
3689
- this.#finished = false;
3690
- this.#updateContext();
3691
- const element = elements[index];
3692
- element.scrollIntoView({ behavior: "smooth", block: "nearest" });
3693
- this.#highlightElement(element);
3694
- this.#textNodes = this.#collectTextNodes(element);
3695
- const text = this.#textNodes.map((n) => n.textContent ?? "").join("");
3696
- if (!text.trim()) {
3697
- this.#speakElement(index + 1);
3698
- return;
3699
- }
3700
- const utterance = new SpeechSynthesisUtterance(text);
3701
- utterance.lang = this.#resolveLang(element);
3702
- utterance.rate = 1;
3703
- utterance.onboundary = (event) => {
3704
- if (event.name !== "word")
3705
- return;
3706
- this.#updateWordHighlight(event.charIndex, event.charLength ?? 0);
3707
- };
3708
- utterance.onend = () => {
3709
- if (this.#currentUtterance !== utterance)
3710
- return;
3711
- this.#currentUtterance = null;
3712
- this.#clearWordHighlight();
3713
- this.#speakElement(this.#currentElementIndex + 1);
3714
- };
3715
- utterance.onerror = () => {
3716
- if (this.#currentUtterance !== utterance)
3717
- return;
3718
- this.#currentUtterance = null;
3719
- this.#clearAllHighlights();
3720
- this.#setSpeechState("idle");
3721
- };
3722
- this.#currentUtterance = utterance;
3723
- speechSynthesis.speak(utterance);
3724
- this.#setSpeechState("playing");
3725
- }
3726
- #pause() {
3727
- speechSynthesis.pause();
3728
- this.#setSpeechState("paused");
3729
- }
3730
- #resume() {
3731
- speechSynthesis.resume();
3732
- this.#setSpeechState("playing");
3733
- }
3734
- #stop() {
3735
- this.#currentUtterance = null;
3736
- speechSynthesis.cancel();
3737
- this.#clearAllHighlights();
3738
- this.#setSpeechState("idle");
3739
- }
3740
- // ─── Pick mode ────────────────────────────────────────────────────────────
3741
- #togglePick() {
3742
- if (this.#picking)
3743
- this.#stopPicking();
3744
- else
3745
- this.#startPicking();
3746
- }
3747
- /** Highlight every reading element and wait for a click on one of them. */
3748
- #startPicking() {
3749
- if (this.#contentMode)
3750
- this.#readingElements = null;
3751
- const elements = this.#getReadingElements();
3752
- if (!elements.length) {
3753
- console.warn("test-item-to-speech: no readable elements found");
3754
- return;
3755
- }
3756
- this.#stop();
3757
- this.#picking = true;
3758
- this.#internals.states.add("picking");
3759
- this.#highlightElements(elements);
3760
- this.#pickRoot = elements[0].getRootNode();
3761
- this.#pickRoot.addEventListener("click", this.#boundHandlePickClick, true);
3762
- this._ttsContext = { ...this._ttsContext, picking: true };
3763
- }
3764
- #stopPicking() {
3765
- if (!this.#picking)
3766
- return;
3767
- this.#picking = false;
3768
- this.#internals.states.delete("picking");
3769
- this.#pickRoot?.removeEventListener("click", this.#boundHandlePickClick, true);
3770
- this.#pickRoot = null;
3771
- this.#clearAllHighlights();
3772
- this._ttsContext = { ...this._ttsContext, picking: false };
3773
- }
3774
- #handlePickClick(event) {
3775
- const elements = this.#getReadingElements();
3776
- const path = event.composedPath();
3777
- let index = elements.findIndex((el) => path.includes(el));
3778
- if (index < 0) {
3779
- const container = path.find((node) => node instanceof Element && node.matches("qti-simple-choice, li, qti-prompt"));
3780
- if (container)
3781
- index = elements.findIndex((el) => container.contains(el));
3782
- }
3783
- if (index < 0)
3784
- return;
3785
- event.preventDefault();
3786
- event.stopPropagation();
3787
- this.#stopPicking();
3788
- speechSynthesis.cancel();
3789
- this.#speakElement(index);
3790
- }
3791
- #prevElement() {
3792
- const elements = this.#getReadingElements();
3793
- if (!elements.length)
3794
- return;
3795
- this.#currentUtterance = null;
3796
- speechSynthesis.cancel();
3797
- this.#clearWordHighlight();
3798
- this.#currentElementIndex = Math.max(0, this.#currentElementIndex - 1);
3799
- this.#finished = false;
3800
- this.#updateContext();
3801
- const el = elements[this.#currentElementIndex];
3802
- el.scrollIntoView({ behavior: "smooth", block: "nearest" });
3803
- this.#highlightElement(el);
3804
- this.#setSpeechState("idle");
3805
- }
3806
- #nextElement() {
3807
- const elements = this.#getReadingElements();
3808
- if (!elements.length)
3809
- return;
3810
- this.#currentUtterance = null;
3811
- speechSynthesis.cancel();
3812
- this.#clearWordHighlight();
3813
- this.#currentElementIndex = Math.min(elements.length - 1, this.#currentElementIndex + 1);
3814
- this.#finished = false;
3815
- this.#updateContext();
3816
- const el = elements[this.#currentElementIndex];
3817
- el.scrollIntoView({ behavior: "smooth", block: "nearest" });
3818
- this.#highlightElement(el);
3819
- this.#setSpeechState("idle");
3820
- }
3821
- /** Walk text nodes without crossing shadow DOM boundaries. */
3822
- #collectTextNodes(root) {
3823
- const nodes = [];
3824
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
3825
- let node;
3826
- while (node = walker.nextNode()) {
3827
- if ((node.textContent ?? "").length > 0 && !node.parentElement?.closest('[aria-hidden="true"]')) {
3828
- nodes.push(node);
3829
- }
3830
- }
3831
- return nodes;
3832
- }
3833
- /** Highlight the whole element as the navigation cursor (blue). */
3834
- #highlightElement(element) {
3835
- this.#highlightElements([element]);
3836
- }
3837
- /** Put the blue cursor highlight on several elements at once (pick mode). */
3838
- #highlightElements(elements) {
3839
- if (!("highlights" in CSS))
3840
- return;
3841
- this.#ensureHighlightStyles();
3842
- this.#elementHighlight.clear();
3843
- for (const element of elements) {
3844
- const range = new Range();
3845
- range.selectNodeContents(element);
3846
- this.#elementHighlight.add(range);
3847
- }
3848
- CSS.highlights.set(HIGHLIGHT_ELEMENT, this.#elementHighlight);
3849
- }
3850
- /** Highlight the current word within #textNodes (yellow, during speech). */
3851
- #updateWordHighlight(charIndex, charLength) {
3852
- if (!("highlights" in CSS))
3853
- return;
3854
- this.#ensureHighlightStyles();
3855
- this.#wordHighlight.clear();
3856
- const text = this.#textNodes.map((n) => n.textContent ?? "").join("");
3857
- const endIndex = charIndex + (charLength > 0 ? charLength : this.#wordLengthAt(charIndex, text));
3858
- let offset = 0;
3859
- let startNode = null;
3860
- let startOffset = 0;
3861
- let endNode = null;
3862
- let endOffset = 0;
3863
- for (const node of this.#textNodes) {
3864
- const len = node.textContent?.length ?? 0;
3865
- if (!startNode && offset + len > charIndex) {
3866
- startNode = node;
3867
- startOffset = charIndex - offset;
3868
- }
3869
- if (startNode && offset + len >= endIndex) {
3870
- endNode = node;
3871
- endOffset = endIndex - offset;
3872
- break;
3873
- }
3874
- offset += len;
3875
- }
3876
- if (startNode && endNode) {
3877
- const range = new Range();
3878
- range.setStart(startNode, startOffset);
3879
- range.setEnd(endNode, endOffset);
3880
- this.#wordHighlight.add(range);
3881
- CSS.highlights.set(HIGHLIGHT_WORD, this.#wordHighlight);
3882
- }
3883
- }
3884
- #clearWordHighlight() {
3885
- if (!("highlights" in CSS))
3886
- return;
3887
- this.#wordHighlight.clear();
3888
- if (CSS.highlights.get(HIGHLIGHT_WORD) === this.#wordHighlight)
3889
- CSS.highlights.delete(HIGHLIGHT_WORD);
3890
- }
3891
- #clearAllHighlights() {
3892
- if (!("highlights" in CSS))
3893
- return;
3894
- this.#clearWordHighlight();
3895
- this.#elementHighlight.clear();
3896
- if (CSS.highlights.get(HIGHLIGHT_ELEMENT) === this.#elementHighlight)
3897
- CSS.highlights.delete(HIGHLIGHT_ELEMENT);
3898
- }
3899
- /** Fallback word-length when charLength is 0. */
3900
- #wordLengthAt(charIndex, text) {
3901
- const right = text.slice(charIndex).search(/\s/);
3902
- return right < 0 ? text.length - charIndex : right;
3903
- }
3904
- /**
3905
- * Add ::highlight() rules both to test-container's shadow root (where highlighted
3906
- * text lives) and to the document (safety net — spec allows document rules to apply
3907
- * across shadow DOM). Called lazily on first highlight use so test-container is
3908
- * guaranteed to be in the DOM by the time navigation or speech starts.
3909
- */
3910
- #ensureHighlightStyles() {
3911
- if (!("highlights" in CSS))
3912
- return;
3913
- const sheet = getHighlightSheet();
3914
- if (!document.adoptedStyleSheets.includes(sheet)) {
3915
- document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
3916
- }
3917
- const roots = /* @__PURE__ */ new Set();
3918
- const testContainer = this.closest("test-navigation")?.querySelector("test-container") ?? this.testHost?.querySelector("test-container");
3919
- if (testContainer?.shadowRoot)
3920
- roots.add(testContainer.shadowRoot);
3921
- const ownRoot = this.getRootNode();
3922
- if (ownRoot instanceof ShadowRoot)
3923
- roots.add(ownRoot);
3924
- const itemRoot = this.#readingElements?.[0]?.getRootNode();
3925
- if (itemRoot instanceof ShadowRoot)
3926
- roots.add(itemRoot);
3927
- for (const root of roots) {
3928
- if (!root.adoptedStyleSheets.includes(sheet)) {
3929
- root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];
3930
- }
3931
- }
3932
- }
3933
- };
3934
- __decorate17([
3935
- property13({ type: String })
3936
- ], TestItemToSpeech.prototype, "language", void 0);
3937
- __decorate17([
3938
- consume9({ context: sessionContext, subscribe: true })
3939
- ], TestItemToSpeech.prototype, "_sessionContext", void 0);
3940
- __decorate17([
3941
- consume9({ context: testHostContext, subscribe: true })
3942
- ], TestItemToSpeech.prototype, "testHost", void 0);
3943
- __decorate17([
3944
- state4(),
3945
- provide3({ context: ttsContext })
3946
- ], TestItemToSpeech.prototype, "_ttsContext", void 0);
3947
- var TestTtsPlay = class extends TtsButtonBase {
3948
- #toggle() {
3949
- if (!this._tts)
3950
- return;
3951
- if (this._tts.state === "idle")
3952
- this._tts.play();
3953
- else if (this._tts.state === "playing")
3954
- this._tts.pause();
3955
- else
3956
- this._tts.resume();
3957
- }
3958
- render() {
3959
- const playing = this._tts?.state === "playing";
3960
- return html14`
3961
- <button part="button" aria-label=${ifDefined(playing ? this.pauseLabel : this.label)} @click=${this.#toggle}>
3962
- ${playing ? html14`<slot name="pause">${iconContent("pause", this.pauseLabel ?? "Pause")}</slot>` : html14`<slot name="play">${iconContent("play", this.label ?? "Play")}</slot>`}
3963
- </button>
3964
- `;
3965
- }
3966
- };
3967
- __decorate17([
3968
- property13({ type: String, attribute: "pause-label" })
3969
- ], TestTtsPlay.prototype, "pauseLabel", void 0);
3970
- var TestTtsPause = class extends TtsButtonBase {
3971
- render() {
3972
- return html14`
3973
- <button
3974
- part="button"
3975
- aria-label=${ifDefined(this.label)}
3976
- ?disabled=${this._tts?.state !== "playing"}
3977
- @click=${() => this._tts?.pause()}
3978
- >
3979
- <slot>${iconContent("pause", this.label ?? "Pause")}</slot>
3980
- </button>
3981
- `;
3982
- }
3983
- };
3984
- var TestTtsResume = class extends TtsButtonBase {
3985
- render() {
3986
- return html14`
3987
- <button
3988
- part="button"
3989
- aria-label=${ifDefined(this.label)}
3990
- ?disabled=${this._tts?.state !== "paused"}
3991
- @click=${() => this._tts?.resume()}
3992
- >
3993
- <slot>${iconContent("play", this.label ?? "Resume")}</slot>
3994
- </button>
3995
- `;
3996
- }
3997
- };
3998
- var TestTtsStop = class extends TtsButtonBase {
3999
- render() {
4000
- const idle = this._tts?.state === "idle" && !this._tts?.picking;
4001
- return html14`
4002
- <button part="button" aria-label=${ifDefined(this.label)} ?disabled=${idle} @click=${() => this._tts?.stop()}>
4003
- <slot>${iconContent("stop", this.label ?? "Stop")}</slot>
4004
- </button>
4005
- `;
4006
- }
4007
- };
4008
- var TestTtsPrev = class extends TtsButtonBase {
4009
- render() {
4010
- const collected = (this._tts?.elementCount ?? 0) > 0;
4011
- const atStart = (this._tts?.currentElementIndex ?? 0) === 0;
4012
- return html14`
4013
- <button
4014
- part="button"
4015
- aria-label=${ifDefined(this.label)}
4016
- ?disabled=${collected && atStart}
4017
- @click=${() => this._tts?.prevElement()}
4018
- >
4019
- <slot>${iconContent("prev", this.label ?? "Previous sentence")}</slot>
4020
- </button>
4021
- `;
4022
- }
4023
- };
4024
- var TestTtsNext = class extends TtsButtonBase {
4025
- render() {
4026
- const count = this._tts?.elementCount ?? 0;
4027
- const atEnd = count > 0 && (this._tts?.currentElementIndex ?? 0) >= count - 1;
4028
- return html14`
4029
- <button
4030
- part="button"
4031
- aria-label=${ifDefined(this.label)}
4032
- ?disabled=${atEnd}
4033
- @click=${() => this._tts?.nextElement()}
4034
- >
4035
- <slot>${iconContent("next", this.label ?? "Next sentence")}</slot>
4036
- </button>
4037
- `;
4038
- }
4039
- };
4040
- var TestTtsPick = class extends TtsButtonBase {
4041
- render() {
4042
- return html14`
4043
- <button
4044
- part="button"
4045
- aria-label=${ifDefined(this.label)}
4046
- aria-pressed=${this._tts?.picking ? "true" : "false"}
4047
- @click=${() => this._tts?.togglePick()}
4048
- >
4049
- <slot>${iconContent("pick", this.label ?? "Read from here")}</slot>
4050
- </button>
4051
- `;
4052
- }
4053
- };
4054
-
4055
- // ../qti-test/dist/components/test-navigation/test-navigation.js
4056
- import { ContextConsumer, consume as consume10, provide as provide4 } from "@lit/context";
4057
- import { html as html15, LitElement as LitElement16 } from "lit";
4058
- import { property as property14, state as state5 } from "lit/decorators.js";
4059
- var __decorate18 = function(decorators, target, key, desc) {
4060
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4061
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4062
- 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;
4063
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4064
- };
4065
- var newQtiContext = () => ({
4066
- QTI_CONTEXT: { testIdentifier: "", candidateIdentifier: "", environmentIdentifier: "default" }
4067
- });
4068
- var TestNavigation = class extends LitElement16 {
4069
- /**
4070
- * @deprecated Set `qtiContext` on `qti-test`, which provides it. This is an alias for the
4071
- * enclosing test's: reading returns it, writing replaces it, so a host that has always set the
4072
- * shuffle seed here keeps working. Removed in the next major.
4073
- *
4074
- * Written before the navigation is inside a test, it waits and is handed over on connect.
4075
- */
4076
- get qtiContext() {
4077
- return this.#owner()?.qtiContext ?? (this.#pendingQtiContext ??= newQtiContext());
4078
- }
4079
- set qtiContext(value) {
4080
- if (!this.#warnedQtiContext) {
4081
- this.#warnedQtiContext = true;
4082
- 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.");
4083
- }
4084
- this.#writeQtiContext(value);
3519
+ this.#writeQtiContext(value);
4085
3520
  }
4086
3521
  #pendingQtiContext;
4087
3522
  #warnedQtiContext;
@@ -4128,12 +3563,13 @@ var TestNavigation = class extends LitElement16 {
4128
3563
  this.configContext = {};
4129
3564
  this.autoScoreItems = false;
4130
3565
  this.#optimality = /* @__PURE__ */ new Map();
4131
- listenPublic2(this, "cito-test-loaded", this.#handleTestConnected.bind(this));
4132
- this.addEventListener("qti-assessment-item-connected", this.#handleItemConnected.bind(this));
4133
- listenPublic(this, "cito-item-response-changed", this.#handleInteractionChanged.bind(this));
3566
+ this.#itemElement = (identifier) => this.#assessmentItemFor(identifier) ?? null;
3567
+ this.#lockedItems = /* @__PURE__ */ new WeakSet();
3568
+ listenPublic2(this, "qc-test-loaded", this.#handleTestConnected.bind(this));
3569
+ listenPublic(this, "qc-item-response-changed", this.#handleInteractionChanged.bind(this));
4134
3570
  this.addEventListener("qti-item-context-updated", this.#handleItemContextUpdated.bind(this));
4135
- listenPublic2(this, "cito-test-end-attempt", this.#handleTestEndAttempt.bind(this));
4136
- listenPublic2(this, "cito-test-update-outcome", this.#handleTestUpdateOutcomeVariable.bind(this));
3571
+ listenPublic2(this, "qc-test-end-attempt", this.#handleTestEndAttempt.bind(this));
3572
+ listenPublic2(this, "qc-test-update-outcome", this.#handleTestUpdateOutcomeVariable.bind(this));
4137
3573
  }
4138
3574
  /**
4139
3575
  * Latch whether an item reached its optimal outcome whenever it has just ended
@@ -4148,12 +3584,12 @@ var TestNavigation = class extends LitElement16 {
4148
3584
  const itemContext = event.detail.itemContext;
4149
3585
  if (!itemContext?.identifier)
4150
3586
  return;
4151
- const optimality = this.#assessOptimality(itemContext);
3587
+ const optimality = assessOptimality(itemContext);
4152
3588
  this.#optimality.set(itemContext.identifier, optimality);
4153
3589
  const computedItem = this.computedItemFor(itemContext.identifier);
4154
3590
  const numAttempts = Number(itemContext.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
4155
3591
  const completionStatus = itemContext.variables?.find((v) => v.identifier === "completionStatus")?.value;
4156
- this.afterAttemptEnded(event.composedPath()[0]?.closest("qti-assessment-item"), computedItem, this.#isItemDone(numAttempts, optimality, computedItem?.maxAttempts, computedItem?.adaptive, completionStatus));
3592
+ this.afterAttemptEnded(event.composedPath()[0]?.closest("qti-assessment-item"), computedItem, isItemDone(numAttempts, optimality, computedItem?.sessionControl?.maxAttempts, computedItem?.adaptive, completionStatus));
4157
3593
  }
4158
3594
  /**
4159
3595
  * Extension point for presentation packages reacting to an ended attempt.
@@ -4171,9 +3607,11 @@ var TestNavigation = class extends LitElement16 {
4171
3607
  #assessmentItemFor(identifier) {
4172
3608
  if (!identifier)
4173
3609
  return void 0;
4174
- const itemRef = this.#testElement?.querySelector(`qti-assessment-item-ref[identifier="${identifier}"]`);
3610
+ const itemRef = this.#testElement?.querySelector(`qti-assessment-item-ref[identifier="${CSS.escape(identifier)}"]`);
4175
3611
  return itemRef?.assessmentItem ?? void 0;
4176
3612
  }
3613
+ /** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */
3614
+ #itemElement;
4177
3615
  /** The currently active assessment item, exposed for optional presentation extensions. */
4178
3616
  get activeAssessmentItem() {
4179
3617
  if (!this.#testElement || !this._sessionContext?.navItemRefId)
@@ -4181,13 +3619,12 @@ var TestNavigation = class extends LitElement16 {
4181
3619
  return this.#testElement.querySelector(`qti-assessment-item-ref[identifier="${this._sessionContext.navItemRefId}"]`)?.assessmentItem;
4182
3620
  }
4183
3621
  /**
4184
- * Handles the 'test-end-attempt' event.
4185
- * @private
4186
- * @listens TestNavigation#test-end-attempt
4187
- * @param {CustomEvent} event - The custom event object.
3622
+ * Ends an attempt: the item named by `detail.itemId` (a `test-end-attempt` stamped into an item, or
3623
+ * given an `item`), or else the item on screen.
4188
3624
  */
4189
- #handleTestEndAttempt(_event) {
4190
- const qtiAssessmentItemEl = this.activeAssessmentItem;
3625
+ #handleTestEndAttempt(event) {
3626
+ const itemId = event.detail?.itemId;
3627
+ const qtiAssessmentItemEl = itemId ? this.#assessmentItemFor(itemId) : this.activeAssessmentItem;
4191
3628
  if (!qtiAssessmentItemEl)
4192
3629
  return;
4193
3630
  const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;
@@ -4212,7 +3649,7 @@ var TestNavigation = class extends LitElement16 {
4212
3649
  }
4213
3650
  }
4214
3651
  render() {
4215
- return html15`<slot></slot>`;
3652
+ return html11`<slot></slot>`;
4216
3653
  }
4217
3654
  /* PK: on test connected we can build the computed context */
4218
3655
  #handleTestConnected(event) {
@@ -4246,62 +3683,38 @@ var TestNavigation = class extends LitElement16 {
4246
3683
  });
4247
3684
  }
4248
3685
  });
4249
- const testPartElements = Array.from(this.#testElement?.querySelectorAll(`qti-test-part`) || []);
4250
- this.computedContext = {
4251
- identifier: this.#testElement.identifier,
4252
- title: this.#testElement.title,
4253
- view: this._sessionContext?.view,
4254
- testParts: testPartElements.map((testPart) => {
4255
- const sectionElements = [...testPart.querySelectorAll(`qti-assessment-section`)];
4256
- const testPartSessionControl = testPart.querySelector(":scope > qti-item-session-control");
4257
- const partAllowSkipping = testPartSessionControl ? testPartSessionControl.allowSkipping : true;
4258
- const partMaxAttempts = testPartSessionControl ? testPartSessionControl.maxAttempts : 1;
4259
- const partShowFeedback = testPartSessionControl ? testPartSessionControl.showFeedback : false;
4260
- const partShowSolution = testPartSessionControl ? testPartSessionControl.showSolution : false;
4261
- return {
4262
- active: false,
4263
- identifier: testPart.identifier,
4264
- navigationMode: testPart.navigationMode,
4265
- submissionMode: testPart.submissionMode,
4266
- allowSkipping: partAllowSkipping,
4267
- sections: sectionElements.map((section) => {
4268
- const itemElements = [...section.querySelectorAll(`qti-assessment-item-ref`)];
4269
- const sectionSessionControl = section.querySelector(":scope > qti-item-session-control");
4270
- const sectionAllowSkipping = sectionSessionControl ? sectionSessionControl.allowSkipping : partAllowSkipping;
4271
- const sectionMaxAttempts = sectionSessionControl ? sectionSessionControl.maxAttempts : partMaxAttempts;
4272
- const sectionShowFeedback = sectionSessionControl ? sectionSessionControl.showFeedback : partShowFeedback;
4273
- const sectionShowSolution = sectionSessionControl ? sectionSessionControl.showSolution : partShowSolution;
4274
- return {
4275
- active: false,
4276
- identifier: section.identifier,
4277
- title: section.title,
4278
- navigationMode: section.navigationMode,
4279
- submissionMode: section.submissionMode,
4280
- allowSkipping: sectionAllowSkipping,
4281
- items: itemElements.map((item) => {
4282
- const itemSessionControl = item.querySelector(":scope > qti-item-session-control");
4283
- const itemAllowSkipping = itemSessionControl ? itemSessionControl.allowSkipping : sectionAllowSkipping;
4284
- const itemMaxAttempts = itemSessionControl ? itemSessionControl.maxAttempts : sectionMaxAttempts;
4285
- const itemShowFeedback = itemSessionControl ? itemSessionControl.showFeedback : sectionShowFeedback;
4286
- const itemShowSolution = itemSessionControl ? itemSessionControl.showSolution : sectionShowSolution;
4287
- return {
4288
- ...this.initContext?.find((i) => i.identifier === item.identifier),
4289
- active: false,
4290
- identifier: item.identifier,
4291
- categories: item.category ? item.category?.split(" ") : [],
4292
- href: item.href,
4293
- variables: [],
4294
- allowSkipping: itemAllowSkipping,
4295
- maxAttempts: itemMaxAttempts,
4296
- showFeedback: itemShowFeedback,
4297
- showSolution: itemShowSolution
4298
- };
4299
- })
4300
- };
4301
- })
4302
- };
4303
- })
4304
- };
3686
+ this.#model = buildTestModel(renderedMarkup(this.#testElement));
3687
+ this.computedContext = this.#derive();
3688
+ }
3689
+ /** The test's structure and resolved session control, read from its markup when it is connected. */
3690
+ #model;
3691
+ /** `computedContext`, derived anew from its inputs (`deriveComputedContext`), never from the previous one. */
3692
+ #derive() {
3693
+ this.#seedOptimality();
3694
+ return deriveComputedContext({
3695
+ model: this.#model,
3696
+ itemFacts: this._itemFacts,
3697
+ testContext: this._testContext,
3698
+ sessionContext: this._sessionContext,
3699
+ infoItemCategory: this.configContext?.infoItemCategory,
3700
+ itemData: this.initContext,
3701
+ optimality: this.#optimality,
3702
+ itemElement: this.#itemElement
3703
+ });
3704
+ }
3705
+ /**
3706
+ * On a restored session no attempt is ended this run, so the latch is seeded once from the
3707
+ * persisted context, which still holds the submitted response. A later change of the answer
3708
+ * leaves the seeded value alone.
3709
+ */
3710
+ #seedOptimality() {
3711
+ for (const itemContext of this._testContext?.items ?? []) {
3712
+ if (!itemContext.identifier || this.#optimality.has(itemContext.identifier))
3713
+ continue;
3714
+ const numAttempts = Number(itemContext.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
3715
+ if (numAttempts > 0)
3716
+ this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));
3717
+ }
4305
3718
  }
4306
3719
  /**
4307
3720
  * Extract default values from a qti-context-declaration element
@@ -4340,297 +3753,112 @@ var TestNavigation = class extends LitElement16 {
4340
3753
  });
4341
3754
  return defaultValues;
4342
3755
  }
4343
- /* PK: on item connected we can add item only properties in the xml */
4344
- #handleItemConnected(event) {
4345
- const itemElement = event.detail;
4346
- this.computedContext = {
4347
- ...this.computedContext,
4348
- testParts: this.computedContext.testParts.map((testPart) => {
4349
- return {
4350
- ...testPart,
4351
- sections: testPart.sections.map((section) => {
4352
- return {
4353
- ...section,
4354
- items: section.items.map((item) => {
4355
- if (item.identifier !== itemElement.parentElement.getAttribute("identifier")) {
4356
- return item;
4357
- }
4358
- const scoreOutcome = itemElement.querySelector("qti-outcome-declaration[identifier='SCORE']");
4359
- const externalScored = scoreOutcome?.getAttribute("externalScored");
4360
- const responseDeclarations = itemElement.querySelectorAll("qti-response-declaration");
4361
- const containsCorrectResponse = Array.from(responseDeclarations).some((r) => r.querySelector("qti-correct-response"));
4362
- const containsMapping = Array.from(responseDeclarations).some((r) => {
4363
- const mapping = r.querySelector("qti-mapping");
4364
- const areaMapping = r.querySelector("qti-area-mapping");
4365
- return mapping?.querySelector("qti-map-entry") || areaMapping?.querySelector("qti-area-map-entry");
4366
- });
4367
- const hasCorrectResponse = containsCorrectResponse || containsMapping;
4368
- const hasResponseProcessing = itemElement.querySelector("qti-response-processing") ? true : false;
4369
- return {
4370
- ...item,
4371
- assessmentItemIdentifier: itemElement.getAttribute("identifier"),
4372
- label: itemElement.getAttribute("label"),
4373
- title: itemElement.title,
4374
- externalScored,
4375
- adaptive: itemElement.adaptive == "true" || false,
4376
- timeDependent: itemElement.timeDependent == "true" || false,
4377
- variables: itemElement.variables,
4378
- hasCorrectResponse,
4379
- hasResponseProcessing
4380
- };
4381
- })
4382
- };
4383
- })
4384
- };
4385
- })
4386
- };
4387
- }
4388
- /* PK: on every change of the candidate we will recomputed the computedContext */
3756
+ /* On every change of the candidate's state, the context is derived again. */
4389
3757
  willUpdate(_changedProperties) {
4390
- if (!this.computedContext)
3758
+ if (!this.#model)
4391
3759
  return;
4392
- let itemIndex = 1;
4393
- this.computedContext = {
4394
- ...this.computedContext,
4395
- view: this._sessionContext?.view,
4396
- testParts: this.computedContext.testParts.map((testPart) => {
4397
- return {
4398
- ...testPart,
4399
- active: this._sessionContext?.navPartId === testPart.identifier || false,
4400
- sections: testPart.sections.map((section) => {
4401
- return {
4402
- ...section,
4403
- active: this._sessionContext?.navSectionId === section.identifier || false,
4404
- completed: section.items.every((item) => this._testContext.items.find((i) => i.identifier === item.identifier)?.variables.find((v) => v.identifier === "completionStatus").value === "completed"),
4405
- items: section.items.map((item) => {
4406
- const itemContext = this._testContext?.items.find((i) => i.identifier === item.identifier);
4407
- const computedItem = {
4408
- ...item,
4409
- ...itemContext,
4410
- ...this.initContext?.find((i) => i.identifier === item.identifier)
4411
- };
4412
- const rawscore = computedItem.variables?.find((vr) => vr.identifier == "SCORE")?.value;
4413
- const score = rawscore === void 0 || rawscore === null ? null : parseFloat(rawscore?.toString());
4414
- const completionStatus = computedItem.variables?.find((v) => v.identifier === "completionStatus")?.value;
4415
- const response = computedItem.variables?.find((v) => v.identifier === "RESPONSE")?.value || "";
4416
- const numAttempts = Number(computedItem.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
4417
- const active = this._sessionContext?.navItemRefId === computedItem.identifier || false;
4418
- const valid = itemContext?.valid ?? true;
4419
- const responseVars = itemContext?.variables?.filter((v) => v.type === "response") || [];
4420
- const isDefaultResponse = responseVars.every((v) => {
4421
- if (v.value === void 0 || v.value === null) {
4422
- return true;
4423
- }
4424
- let fallbackValue;
4425
- switch (v.baseType) {
4426
- case "integer":
4427
- case "float":
4428
- case "duration":
4429
- fallbackValue = "0";
4430
- break;
4431
- case "boolean":
4432
- fallbackValue = "false";
4433
- break;
4434
- case "string":
4435
- case "directedPair":
4436
- case "identifier":
4437
- case "pair":
4438
- case "record":
4439
- default:
4440
- fallbackValue = "";
4441
- break;
4442
- }
4443
- const defaultValue = v.defaultValue ?? fallbackValue;
4444
- if (Array.isArray(v.value)) {
4445
- const dv = Array.isArray(defaultValue) ? defaultValue : [defaultValue];
4446
- return v.value.length === dv.length && v.value.every((val, i) => val === dv[i]);
4447
- }
4448
- return v.value === defaultValue;
4449
- });
4450
- const index = item.categories.includes(this.configContext?.infoItemCategory) ? null : itemIndex++;
4451
- const rawMaxScore = item.variables?.find((vr) => vr.identifier == "MAXSCORE")?.value;
4452
- const maxScore = rawMaxScore === void 0 || rawMaxScore === null ? null : parseFloat(rawMaxScore?.toString());
4453
- let optimality = this.#optimality.get(computedItem.identifier);
4454
- if (optimality === void 0) {
4455
- optimality = itemContext ? this.#assessOptimality(itemContext) : "unscored";
4456
- if (numAttempts > 0)
4457
- this.#optimality.set(computedItem.identifier, optimality);
4458
- }
4459
- const done = this.#isItemDone(numAttempts, optimality, computedItem.maxAttempts, computedItem.adaptive, completionStatus);
4460
- return {
4461
- ...computedItem,
4462
- completionStatus,
4463
- numAttempts,
4464
- score,
4465
- response,
4466
- index,
4467
- active,
4468
- valid,
4469
- isDefaultResponse,
4470
- maxScore,
4471
- done,
4472
- // Reflects the last *ended* attempt only. Read the latch directly
4473
- // (not the `optimality` local) — the latch is written solely on
4474
- // responseProcessed / restore-seed (line above, guarded by
4475
- // numAttempts > 0), so a freshly-picked mid-attempt selection
4476
- // computed live is never stored and never counts as optimal.
4477
- optimal: this.#optimality.get(computedItem.identifier) === "optimal"
4478
- // type,
4479
- // correct,
4480
- // incorrect,
4481
- // completed
4482
- };
4483
- })
4484
- };
4485
- })
4486
- };
4487
- })
4488
- };
3760
+ this.computedContext = this.#derive();
4489
3761
  this.dispatchEvent(new CustomEvent("qti-computed-context-updated", {
4490
3762
  detail: this.computedContext,
4491
3763
  bubbles: true
4492
3764
  }));
4493
3765
  }
4494
- /**
4495
- * Decide whether an item should be treated as "the candidate is done with it"
4496
- * for the purpose of gating forward navigation and further attempts.
4497
- *
4498
- * - The candidate must have actually ended an attempt (numAttempts > 0).
4499
- * - Once attempted, the item is done if they reached the optimal outcome
4500
- * ('optimal'), or there's nothing to improve on ('unscored'). It is only *not*
4501
- * done while a better attempt is still possible ('suboptimal') and attempts
4502
- * remain — see #assessOptimality for how "optimal" is determined.
4503
- *
4504
- * `optimality` reflects the last *ended attempt* (see #optimality), not the
4505
- * live selection — so a freshly-picked optimal answer doesn't count as done
4506
- * until test-end-attempt evaluates it.
4507
- *
4508
- * Adaptive items decide this themselves: max-attempts does not apply to them
4509
- * (QTI 3, itemSessionControl), and a wrong attempt may be the step that leads
4510
- * on to the next part of the item. They are done once their response
4511
- * processing sets completionStatus to 'completed'.
4512
- */
4513
- #isItemDone(numAttempts, optimality, maxAttempts, adaptive, completionStatus) {
4514
- if (numAttempts === 0)
4515
- return false;
4516
- if (adaptive)
4517
- return completionStatus === "completed";
4518
- if (optimality !== "suboptimal")
4519
- return true;
4520
- const max = maxAttempts ?? 1;
4521
- return max > 0 && numAttempts >= max;
3766
+ updated(changedProperties) {
3767
+ super.updated(changedProperties);
3768
+ this.#lockUsedItems();
4522
3769
  }
3770
+ /** The items this navigation disabled because their attempts are used, so it releases only those. */
3771
+ #lockedItems;
4523
3772
  /**
4524
- * Decide whether an item's submission is as good as it can get — i.e. the
4525
- * candidate reached the *optimal* outcome, so there's no reason to make them
4526
- * try again. 'optimal' means best achievable, 'suboptimal' means a better
4527
- * attempt is still possible, 'unscored' means there's nothing to judge against.
4528
- * ("optimal" is the spec's own word — a qti-correct-response is defined as
4529
- * "the (or an) optimal value".)
4530
- *
4531
- * Two signals, in order of authority:
4532
- * 1. The scored outcome: optimal ⟺ SCORE has reached its maximum (MAXSCORE).
4533
- * This correctly handles partial-credit / qti-mapping items, where an exact
4534
- * response match would under- or over-judge.
4535
- * 2. The declared qti-correct-response, for items that aren't scored (no
4536
- * SCORE/MAXSCORE) — an exact match is the best available proxy. Bookkeeping
4537
- * variables like numAttempts can be typed 'response' but never declare a
4538
- * correctResponse, so we filter on a declared correctResponse.
3773
+ * Disables every rendered item whose attempts are used, from the computed context, so the
3774
+ * candidate cannot change the answer once the last attempt is ended. Runs after every update:
3775
+ * an item rendered later (another item, a section on screen, a restored state) is locked as it
3776
+ * arrives, and one whose attempts are back to zero (a new state) is released.
4539
3777
  *
4540
- * Items with neither a comparable score nor a correctResponse (essays, info
4541
- * items, etc.) are 'unscored' — there's no optimal value to require, so one
4542
- * attempt is enough.
3778
+ * Only `disabled = true` is ever set here, and only on an item that was not disabled already; a
3779
+ * host or view that disables or makes an item read-only itself keeps it so.
4543
3780
  */
4544
- #assessOptimality(item) {
4545
- const variables = item.variables ?? [];
4546
- const score = this.#numericVariable(variables, "SCORE");
4547
- const maxScore = this.#numericVariable(variables, "MAXSCORE");
4548
- if (score !== null && maxScore !== null) {
4549
- return score >= maxScore ? "optimal" : "suboptimal";
4550
- }
4551
- const responseVars = variables.filter((v) => v.type === "response" && v.correctResponse !== void 0 && v.correctResponse !== null);
4552
- if (responseVars.length === 0)
4553
- return "unscored";
4554
- const allMatch = responseVars.every((v) => {
4555
- const expected = v.correctResponse;
4556
- const actual = v.value;
4557
- if (actual === void 0 || actual === null)
4558
- return false;
4559
- if (Array.isArray(expected) && Array.isArray(actual)) {
4560
- return expected.length === actual.length && expected.every((e) => actual.includes(e));
3781
+ #lockUsedItems() {
3782
+ if (!this.#testElement || !this.computedContext)
3783
+ return;
3784
+ const items = new Map(this.computedContext.testParts.flatMap((part) => part.submissionMode === "simultaneous" ? [] : part.sections.flatMap((section) => section.items.map((item) => [item.identifier, item]))));
3785
+ for (const itemRef of this.#testElement.querySelectorAll("qti-assessment-item-ref")) {
3786
+ const element = itemRef.assessmentItem;
3787
+ if (!element)
3788
+ continue;
3789
+ const used = this.#attemptsUsed(items.get(itemRef.identifier), element);
3790
+ if (used && !element.disabled) {
3791
+ element.disabled = true;
3792
+ this.#lockedItems.add(element);
3793
+ } else if (!used && this.#lockedItems.has(element)) {
3794
+ this.#lockedItems.delete(element);
3795
+ element.disabled = false;
4561
3796
  }
4562
- if (Array.isArray(expected) || Array.isArray(actual))
4563
- return false;
4564
- return expected === actual;
4565
- });
4566
- return allMatch ? "optimal" : "suboptimal";
3797
+ }
4567
3798
  }
4568
- /** Read a single numeric outcome value, or null when absent / non-numeric. */
4569
- #numericVariable(variables, identifier) {
4570
- const raw = variables?.find((v) => v.identifier === identifier)?.value;
4571
- if (raw === void 0 || raw === null || Array.isArray(raw))
4572
- return null;
4573
- const parsed = parseFloat(raw.toString());
4574
- return Number.isNaN(parsed) ? null : parsed;
3799
+ /**
3800
+ * The same rule as `test-end-attempt`'s max-attempts guard: a non-adaptive item with a
3801
+ * `max-attempts` above 0 whose attempts reached it. Adaptive items end themselves, and 0 is
3802
+ * unlimited. With `auto-score-items` every change is scored as an attempt, so the count is not
3803
+ * the candidate's and locks nothing.
3804
+ */
3805
+ #attemptsUsed(item, element) {
3806
+ if (!item || this.autoScoreItems)
3807
+ return false;
3808
+ if (item.adaptive || element.adaptive === "true")
3809
+ return false;
3810
+ const maxAttempts = item.sessionControl?.maxAttempts ?? 1;
3811
+ return maxAttempts > 0 && (item.numAttempts ?? 0) >= maxAttempts;
4575
3812
  }
4576
3813
  };
4577
- __decorate18([
4578
- property14({ type: String })
3814
+ __decorate15([
3815
+ property12({ type: String })
4579
3816
  ], TestNavigation.prototype, "identifier", void 0);
4580
- __decorate18([
3817
+ __decorate15([
4581
3818
  state5()
4582
3819
  ], TestNavigation.prototype, "initContext", void 0);
4583
- __decorate18([
3820
+ __decorate15([
4584
3821
  state5(),
4585
- consume10({ context: configContext, subscribe: true })
3822
+ consume8({ context: configContext, subscribe: true })
4586
3823
  ], TestNavigation.prototype, "configContext", void 0);
4587
- __decorate18([
3824
+ __decorate15([
4588
3825
  state5(),
4589
- consume10({ context: testContext, subscribe: true })
3826
+ consume8({ context: testContext, subscribe: true })
4590
3827
  ], TestNavigation.prototype, "_testContext", void 0);
4591
- __decorate18([
3828
+ __decorate15([
4592
3829
  state5(),
4593
- consume10({ context: sessionContext, subscribe: true })
3830
+ consume8({ context: sessionContext, subscribe: true })
4594
3831
  ], TestNavigation.prototype, "_sessionContext", void 0);
4595
- __decorate18([
3832
+ __decorate15([
3833
+ state5(),
3834
+ consume8({ context: itemFactsContext, subscribe: true })
3835
+ ], TestNavigation.prototype, "_itemFacts", void 0);
3836
+ __decorate15([
4596
3837
  state5(),
4597
3838
  provide4({ context: computedContext })
4598
3839
  ], TestNavigation.prototype, "computedContext", void 0);
4599
- __decorate18([
4600
- property14({ type: Boolean, attribute: "auto-score-items" })
3840
+ __decorate15([
3841
+ property12({ type: Boolean, attribute: "auto-score-items" })
4601
3842
  ], TestNavigation.prototype, "autoScoreItems", void 0);
4602
3843
 
4603
3844
  // ../qti-test/dist/components/test-next/test-next.js
4604
- import { css as css10, html as html16, LitElement as LitElement17 } from "lit";
4605
- import { property as property15 } from "lit/decorators.js";
4606
- import { consume as consume11 } from "@lit/context";
4607
- var __decorate19 = function(decorators, target, key, desc) {
3845
+ import { LitElement as LitElement14 } from "lit";
3846
+ import { property as property13 } from "lit/decorators.js";
3847
+ import { consume as consume9 } from "@lit/context";
3848
+ var __decorate16 = function(decorators, target, key, desc) {
4608
3849
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4609
3850
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4610
3851
  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;
4611
3852
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4612
3853
  };
4613
- var TestNext = class extends LitElement17 {
3854
+ var TestNext = class extends LitElement14 {
4614
3855
  _handleTestElementChange(_oldValue, newValue) {
4615
3856
  if (newValue) {
4616
3857
  this.requestUpdate();
4617
3858
  }
4618
3859
  }
4619
3860
  static {
4620
- this.styles = css10`
4621
- :host {
4622
- ${btn};
4623
- }
4624
- :host(:hover:not([disabled])) {
4625
- ${btnInteractive};
4626
- }
4627
- :host(:focus-visible) {
4628
- ${focusRing};
4629
- }
4630
- :host([disabled]) {
4631
- ${dis};
4632
- }
4633
- `;
3861
+ this.styles = [button, buttonPrimary];
4634
3862
  }
4635
3863
  #internals;
4636
3864
  constructor() {
@@ -4655,7 +3883,7 @@ var TestNext = class extends LitElement17 {
4655
3883
  const testPart = this.computedContext?.testParts.find((testPart2) => testPart2.active);
4656
3884
  if (!testPart)
4657
3885
  return;
4658
- this.sectionItems = testPart.sections.flatMap((section) => section.items);
3886
+ this.sectionItems = itemsInOrder(testPart);
4659
3887
  this.itemIndex = this.sectionItems.findIndex((item) => item.active);
4660
3888
  this.checkDisabled();
4661
3889
  }
@@ -4663,96 +3891,45 @@ var TestNext = class extends LitElement17 {
4663
3891
  const testPart = this.computedContext?.testParts.find((testPart2) => testPart2.active);
4664
3892
  if (!testPart)
4665
3893
  return;
4666
- const activeSection = testPart.sections.find((s) => s.active);
4667
- const navigationMode = activeSection?.navigationMode || testPart.navigationMode;
4668
- const submissionMode = activeSection?.submissionMode || testPart.submissionMode;
4669
3894
  const activeItem = this.sectionItems[this.itemIndex];
4670
- const isLinearIndividual = navigationMode === "linear" && submissionMode === "individual";
3895
+ const isLinearIndividual = testPart.navigationMode === "linear" && testPart.submissionMode === "individual";
4671
3896
  this._internalDisabled = !this.computedContext || this.itemIndex < 0 || this.itemIndex >= (this.sectionItems?.length ?? 0) - 1 || isLinearIndividual && !activeItem?.done;
4672
3897
  }
4673
3898
  _requestItem(identifier) {
4674
- dispatchPublic(this, "cito-test-navigate", { type: "item", id: identifier });
3899
+ dispatchPublic(this, "qc-test-navigate", { type: "item", id: identifier });
4675
3900
  }
4676
3901
  render() {
4677
- return html16`<slot></slot>`;
3902
+ return control;
4678
3903
  }
4679
3904
  };
4680
- __decorate19([
4681
- property15({ type: Boolean, reflect: true, attribute: "disabled" })
3905
+ __decorate16([
3906
+ property13({ type: Boolean, reflect: true, attribute: "disabled" })
4682
3907
  ], TestNext.prototype, "_internalDisabled", void 0);
4683
- __decorate19([
4684
- consume11({ context: computedContext, subscribe: true })
3908
+ __decorate16([
3909
+ consume9({ context: computedContext, subscribe: true })
4685
3910
  ], TestNext.prototype, "computedContext", void 0);
4686
- __decorate19([
3911
+ __decorate16([
4687
3912
  watch("computedContext")
4688
3913
  ], TestNext.prototype, "_handleTestElementChange", null);
4689
3914
 
4690
- // ../qti-test/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js
4691
- import { html as html17, LitElement as LitElement18 } from "lit";
4692
- import { consume as consume12 } from "@lit/context";
4693
- var __decorate20 = function(decorators, target, key, desc) {
4694
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4695
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4696
- 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;
4697
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4698
- };
4699
- var TestPagingButtonsStamp = class extends LitElement18 {
4700
- #internals;
4701
- createRenderRoot() {
4702
- return this;
4703
- }
4704
- constructor() {
4705
- super();
4706
- this.#internals = this.attachInternals();
4707
- this.#internals.ariaLabel = "pagination";
4708
- }
4709
- connectedCallback() {
4710
- super.connectedCallback();
4711
- const templateElement = this.querySelector("template");
4712
- this.myTemplate = prepareTemplate(templateElement);
4713
- }
4714
- render() {
4715
- if (!this.computedContext)
4716
- return html17``;
4717
- const items = this.computedContext.testParts.flatMap((testPart) => testPart.sections.flatMap((section) => section.items));
4718
- return html17` ${items.map((item) => this.myTemplate({ item, view: this.computedContext.view }))} `;
4719
- }
4720
- };
4721
- __decorate20([
4722
- consume12({ context: computedContext, subscribe: true })
4723
- ], TestPagingButtonsStamp.prototype, "computedContext", void 0);
4724
-
4725
3915
  // ../qti-test/dist/components/test-prev/test-prev.js
4726
- import { css as css11, html as html18, LitElement as LitElement19 } from "lit";
4727
- import { property as property16 } from "lit/decorators.js";
4728
- import { consume as consume13 } from "@lit/context";
4729
- var __decorate21 = function(decorators, target, key, desc) {
3916
+ import { LitElement as LitElement15 } from "lit";
3917
+ import { property as property14 } from "lit/decorators.js";
3918
+ import { consume as consume10 } from "@lit/context";
3919
+ var __decorate17 = function(decorators, target, key, desc) {
4730
3920
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4731
3921
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4732
3922
  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;
4733
3923
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4734
3924
  };
4735
- var TestPrev = class extends LitElement19 {
3925
+ var TestPrev = class extends LitElement15 {
4736
3926
  _handleTestElementChange(_oldValue, newValue) {
4737
3927
  if (newValue) {
4738
3928
  this.requestUpdate();
4739
3929
  }
4740
3930
  }
4741
3931
  static {
4742
- this.styles = css11`
4743
- :host {
4744
- ${btn};
4745
- }
4746
- :host(:hover:not([disabled])) {
4747
- ${btnInteractive};
4748
- }
4749
- :host(:focus-visible) {
4750
- ${focusRing};
4751
- }
4752
- :host([disabled]) {
4753
- ${dis};
4754
- }
4755
- `;
3932
+ this.styles = button;
4756
3933
  }
4757
3934
  constructor() {
4758
3935
  super();
@@ -4769,531 +3946,49 @@ var TestPrev = class extends LitElement19 {
4769
3946
  const testPart = this.computedContext?.testParts.find((testPart2) => testPart2.active);
4770
3947
  if (!testPart)
4771
3948
  return;
4772
- this.sectionItems = testPart.sections.flatMap((section) => section.items);
3949
+ this.sectionItems = itemsInOrder(testPart);
4773
3950
  this.itemIndex = this.sectionItems.findIndex((item) => item.active);
4774
3951
  this.checkDisabled();
4775
3952
  }
4776
3953
  checkDisabled() {
4777
3954
  const testPart = this.computedContext?.testParts.find((testPart2) => testPart2.active);
4778
- const activeSection = testPart?.sections.find((s) => s.active);
4779
- const navigationMode = activeSection?.navigationMode || testPart?.navigationMode || "nonlinear";
3955
+ const navigationMode = testPart?.navigationMode ?? "nonlinear";
4780
3956
  this._internalDisabled = navigationMode === "linear" || !this.computedContext || this.itemIndex === 0 || this.itemIndex === -1;
4781
3957
  }
4782
3958
  _requestItem(identifier) {
4783
- dispatchPublic(this, "cito-test-navigate", { type: "item", id: identifier });
3959
+ dispatchPublic(this, "qc-test-navigate", { type: "item", id: identifier });
4784
3960
  }
4785
3961
  render() {
4786
- return html18`<slot></slot>`;
3962
+ return control;
4787
3963
  }
4788
3964
  };
4789
- __decorate21([
4790
- property16({ type: Boolean, reflect: true, attribute: "disabled" })
3965
+ __decorate17([
3966
+ property14({ type: Boolean, reflect: true, attribute: "disabled" })
4791
3967
  ], TestPrev.prototype, "_internalDisabled", void 0);
4792
- __decorate21([
4793
- consume13({ context: computedContext, subscribe: true })
3968
+ __decorate17([
3969
+ consume10({ context: computedContext, subscribe: true })
4794
3970
  ], TestPrev.prototype, "computedContext", void 0);
4795
- __decorate21([
3971
+ __decorate17([
4796
3972
  watch("computedContext")
4797
3973
  ], TestPrev.prototype, "_handleTestElementChange", null);
4798
3974
 
4799
- // ../qti-test/dist/components/test-print-context/test-print-context.js
4800
- import { html as html19, LitElement as LitElement20 } from "lit";
4801
- import { consume as consume14 } from "@lit/context";
4802
- import { state as state6 } from "lit/decorators.js";
4803
- var __decorate22 = function(decorators, target, key, desc) {
4804
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4805
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4806
- 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;
4807
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4808
- };
4809
- var TestPrintContext = class extends LitElement20 {
4810
- render() {
4811
- return html19` <small><pre>${JSON.stringify(this.computedContext, null, 2)}</pre></small> `;
4812
- }
4813
- };
4814
- __decorate22([
4815
- state6(),
4816
- consume14({ context: computedContext, subscribe: true })
4817
- ], TestPrintContext.prototype, "computedContext", void 0);
4818
-
4819
- // ../qti-test/dist/components/test-print-item-variables/test-print-item-variables.js
4820
- import { html as html20, css as css12, LitElement as LitElement21 } from "lit";
4821
- import { consume as consume15 } from "@lit/context";
4822
- var __decorate23 = function(decorators, target, key, desc) {
4823
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4824
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4825
- 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;
4826
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4827
- };
4828
- var TestPrintVariables = class extends LitElement21 {
4829
- static {
4830
- this.styles = css12`
4831
- table {
4832
- width: 100%;
4833
- border-collapse: collapse;
4834
- margin: 20px 0;
4835
- font-size: 14px;
4836
- text-align: left;
4837
- }
4838
- th,
4839
- td {
4840
- border: 1px solid #ddd;
4841
- padding: 8px;
4842
- }
4843
- th {
4844
- background-color: #f4f4f4;
4845
- font-weight: bold;
4846
- }
4847
- h3 {
4848
- margin-top: 20px;
4849
- font-size: 16px;
4850
- }
4851
- `;
4852
- }
4853
- render() {
4854
- const activeItem = this.computedContext?.testParts.flatMap((testPart) => testPart.sections.flatMap((section) => section.items)).find((item) => item.active);
4855
- if (!activeItem || !activeItem.variables)
4856
- return html20``;
4857
- const responseVariables = activeItem.variables.filter((v) => v.type === "response");
4858
- const outcomeVariables = activeItem.variables.filter((v) => v.type === "outcome");
4859
- const renderTable = (variables, title) => html20`
4860
- <h3>${title}</h3>
4861
- <table>
4862
- <thead>
4863
- <tr>
4864
- <th>Identifier</th>
4865
- <th>Value</th>
4866
- <th>Cardinality</th>
4867
- <th>Base Type</th>
4868
- <th>Correct Response / Mappings</th>
4869
- </tr>
4870
- </thead>
4871
- <tbody>
4872
- ${variables.map((v) => {
4873
- const correctResponse = v.correctResponse ? Array.isArray(v.correctResponse) ? v.correctResponse.join(", ") : v.correctResponse : "";
4874
- const mapEntries = v.mapping?.mapEntries?.map((m) => `${m.mapKey}=${m.mappedValue}pt`).join(", ") || "";
4875
- const areaMapEntries = v.areaMapping?.areaMapEntries?.map((m) => `${m.shape}(${m.coords})=${m.mappedValue}pt`).join(", ") || "";
4876
- return html20`
4877
- <tr>
4878
- <td>${v.identifier}</td>
4879
- <td>${Array.isArray(v.value) ? v.value.join(", ") : v.value}</td>
4880
- <td>${v.cardinality}</td>
4881
- <td>${v.baseType}</td>
4882
- <td>${correctResponse || mapEntries || areaMapEntries}</td>
4883
- </tr>
4884
- `;
4885
- })}
4886
- </tbody>
4887
- </table>
4888
- `;
4889
- return html20`
4890
- ${renderTable(responseVariables, "Response Variables")} ${renderTable(outcomeVariables, "Outcome Variables")}
4891
- `;
4892
- }
4893
- };
4894
- __decorate23([
4895
- consume15({ context: computedContext, subscribe: true })
4896
- ], TestPrintVariables.prototype, "computedContext", void 0);
4897
-
4898
- // ../qti-test/dist/components/test-scoring-buttons/test-scoring-buttons.js
4899
- import { html as html21, LitElement as LitElement22, nothing as nothing3 } from "lit";
4900
- import { consume as consume16 } from "@lit/context";
4901
- import { property as property17 } from "lit/decorators.js";
4902
- var __decorate24 = function(decorators, target, key, desc) {
4903
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4904
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4905
- 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;
4906
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4907
- };
4908
- var TestScoringButtons = class extends LitElement22 {
4909
- createRenderRoot() {
4910
- return this;
4911
- }
4912
- connectedCallback() {
4913
- super.connectedCallback();
4914
- const templateElement = this.querySelector("template");
4915
- if (!templateElement) {
4916
- this.myTemplate = null;
4917
- return;
4918
- }
4919
- this.myTemplate = prepareTemplate(templateElement);
4920
- }
4921
- #changeOutcomeScore(value) {
4922
- const testPart = this.computedContext?.testParts.find((testPart2) => testPart2.active);
4923
- const sectionItems = testPart.sections.flatMap((section) => section.items);
4924
- const currentItemIdentifier = sectionItems.find((item) => item.active)?.identifier;
4925
- dispatchPublic(this, "cito-test-update-outcome", {
4926
- assessmentItemRefId: currentItemIdentifier,
4927
- outcomeVariableId: "SCORE",
4928
- value
4929
- });
4930
- }
4931
- render() {
4932
- const activeItem = this.computedContext?.testParts.flatMap((testPart) => testPart.sections.flatMap((section) => section.items)).find((item) => item.active);
4933
- if (!activeItem || !activeItem.variables)
4934
- return html21``;
4935
- const maxScore = activeItem.variables.find((vr) => vr.identifier == "MAXSCORE")?.value;
4936
- const scoreOutcome = activeItem.variables.find((vr) => vr.identifier == "SCORE");
4937
- const score = scoreOutcome?.value;
4938
- const disabled = !(scoreOutcome?.externalScored === "human");
4939
- if (!maxScore || !scoreOutcome)
4940
- return nothing3;
4941
- const scores = [...Array(Number(maxScore) + 1).keys()];
4942
- return html21`${this.myTemplate ? this.myTemplate({ scores, score, disabled }) : nothing3}`;
4943
- }
4944
- constructor() {
4945
- super();
4946
- this.view = "";
4947
- this.disabled = false;
4948
- this.myTemplate = null;
4949
- this.addEventListener("click", (e) => {
4950
- const target = e.target;
4951
- const value = parseFloat(target.value);
4952
- if (target.tagName === "INPUT") {
4953
- this.#changeOutcomeScore(value);
4954
- }
4955
- });
4956
- }
4957
- };
4958
- __decorate24([
4959
- property17({ type: String, attribute: "view" })
4960
- ], TestScoringButtons.prototype, "view", void 0);
4961
- __decorate24([
4962
- property17({ type: Boolean })
4963
- ], TestScoringButtons.prototype, "disabled", void 0);
4964
- __decorate24([
4965
- consume16({ context: computedContext, subscribe: true })
4966
- ], TestScoringButtons.prototype, "computedContext", void 0);
4967
-
4968
- // ../qti-test/dist/components/test-scoring-feedback/test-scoring-feedback.js
4969
- import { consume as consume17 } from "@lit/context";
4970
- import { html as html22, LitElement as LitElement23 } from "lit";
4971
- import { property as property18 } from "lit/decorators.js";
4972
- var __decorate25 = function(decorators, target, key, desc) {
4973
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4974
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4975
- 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;
4976
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4977
- };
4978
- var TestScoringFeedback = class extends LitElement23 {
4979
- constructor() {
4980
- super(...arguments);
4981
- this.view = null;
4982
- }
4983
- render() {
4984
- const activeItem = this.computedContext?.testParts.flatMap((testPart) => testPart.sections.flatMap((section) => section.items)).find((item) => item.active);
4985
- if (!activeItem || !activeItem.variables)
4986
- return html22``;
4987
- if (activeItem["category"] === "dep-informational")
4988
- return html22`<div>${this.dataset.informational}</div>`;
4989
- const completionStatus = activeItem?.variables.find((v) => v.identifier === "completionStatus")?.value;
4990
- const scoreOutcome = activeItem?.variables.find((vr) => vr.identifier == "SCORE");
4991
- const score = parseFloat(scoreOutcome?.value);
4992
- const externalScored = activeItem["externalScored"];
4993
- const feedbackText = () => {
4994
- if (completionStatus !== "completed") {
4995
- return this.dataset.textNoResponse;
4996
- }
4997
- if (!externalScored && score !== void 0 && !Number.isNaN(score)) {
4998
- return score > 0 ? this.dataset.textCorrect : this.dataset.textIncorrect;
4999
- }
5000
- if (externalScored === "externalMachine") {
5001
- return Number.isNaN(score) || score === void 0 ? this.dataset.scoreUnknown : `We hebben je antwoord ${score === 0 ? "geen punten" : score == 1 ? "\xE9\xE9n punt" : `${score} punten`} gegeven. Je kunt je score zelf aanpassen als je denkt dat dat niet klopt.`;
5002
- }
5003
- if (externalScored === "human") {
5004
- return Number.isNaN(score) ? "" : "Deze score heb je zelf toegekend.";
5005
- }
5006
- return this.dataset.inProgress;
5007
- };
5008
- return html22`<div>${feedbackText()}</div>`;
5009
- }
5010
- };
5011
- __decorate25([
5012
- consume17({ context: computedContext, subscribe: true })
5013
- ], TestScoringFeedback.prototype, "computedContext", void 0);
5014
- __decorate25([
5015
- property18({ type: String, attribute: "view" })
5016
- ], TestScoringFeedback.prototype, "view", void 0);
5017
-
5018
- // ../qti-test/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js
5019
- import { html as html23, LitElement as LitElement24 } from "lit";
5020
- import { consume as consume18 } from "@lit/context";
5021
- var __decorate26 = function(decorators, target, key, desc) {
5022
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5023
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5024
- 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;
5025
- return c > 3 && r && Object.defineProperty(target, key, r), r;
5026
- };
5027
- var TestSectionButtonsStamp = class extends LitElement24 {
5028
- #internals;
5029
- createRenderRoot() {
5030
- return this;
5031
- }
5032
- constructor() {
5033
- super();
5034
- this.#internals = this.attachInternals();
5035
- this.#internals.ariaLabel = "pagination";
5036
- }
5037
- connectedCallback() {
5038
- super.connectedCallback();
5039
- const templateElement = this.querySelector("template");
5040
- this.myTemplate = prepareTemplate(templateElement);
5041
- }
5042
- render() {
5043
- if (!this.computedContext)
5044
- return html23``;
5045
- const sections = this.computedContext.testParts.flatMap((testPart) => testPart.sections);
5046
- return html23` ${sections.map((item) => this.myTemplate({ item }))} `;
5047
- }
5048
- };
5049
- __decorate26([
5050
- consume18({ context: computedContext, subscribe: true })
5051
- ], TestSectionButtonsStamp.prototype, "computedContext", void 0);
5052
-
5053
- // ../qti-test/dist/components/test-section-link/test-section-link.js
5054
- import { css as css13, html as html24, LitElement as LitElement25 } from "lit";
5055
- import { property as property19 } from "lit/decorators.js";
5056
- var __decorate27 = function(decorators, target, key, desc) {
5057
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5058
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5059
- 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;
5060
- return c > 3 && r && Object.defineProperty(target, key, r), r;
5061
- };
5062
- var TestSectionLink = class extends LitElement25 {
3975
+ // ../qti-test/dist/components/test-submit/test-submit.js
3976
+ import { LitElement as LitElement16 } from "lit";
3977
+ var TestSubmit = class extends LitElement16 {
5063
3978
  static {
5064
- this.styles = css13`
5065
- :host {
5066
- ${btn};
5067
- }
5068
- :host(:hover:not([disabled])) {
5069
- ${btnInteractive};
5070
- }
5071
- :host(:focus-visible) {
5072
- ${focusRing};
5073
- }
5074
- :host([disabled]) {
5075
- ${dis};
5076
- }
5077
- `;
5078
- }
5079
- #requestItem(identifier) {
5080
- dispatchPublic(this, "cito-test-navigate", { type: "section", id: identifier });
3979
+ this.styles = button;
5081
3980
  }
5082
3981
  constructor() {
5083
3982
  super();
5084
- this.sectionId = null;
5085
- this.addEventListener("click", () => this.#requestItem(this.sectionId));
3983
+ this.addEventListener("click", () => dispatchPublic(this, "qc-test-submit", {}));
5086
3984
  }
5087
3985
  render() {
5088
- return html24` <slot></slot> `;
3986
+ return control;
5089
3987
  }
5090
3988
  };
5091
- __decorate27([
5092
- property19({ type: String, attribute: "section-id" })
5093
- ], TestSectionLink.prototype, "sectionId", void 0);
5094
3989
 
5095
- // ../qti-test/dist/components/test-stamp/test-stamp.js
5096
- import { html as html25, LitElement as LitElement26, nothing as nothing4 } from "lit";
5097
- import { property as property20, state as state7 } from "lit/decorators.js";
5098
- import { consume as consume19 } from "@lit/context";
5099
- var __decorate28 = function(decorators, target, key, desc) {
5100
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5101
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5102
- 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;
5103
- return c > 3 && r && Object.defineProperty(target, key, r), r;
5104
- };
5105
- var TestStamp = class extends LitElement26 {
5106
- constructor() {
5107
- super(...arguments);
5108
- this.debug = false;
5109
- this.stampContext = {
5110
- view: "candidate",
5111
- activeItem: {},
5112
- activeSection: {
5113
- items: []
5114
- },
5115
- activeTestpart: {
5116
- items: [],
5117
- sections: []
5118
- },
5119
- test: {}
5120
- };
5121
- }
5122
- createRenderRoot() {
5123
- return this;
5124
- }
5125
- connectedCallback() {
5126
- super.connectedCallback();
5127
- const templateElement = this.querySelector("template");
5128
- if (!templateElement) {
5129
- this.myTemplate = null;
5130
- return;
5131
- }
5132
- this.myTemplate = prepareTemplate(templateElement);
5133
- }
5134
- willUpdate(_changedProperties) {
5135
- if (!this.computedContext) {
5136
- return;
5137
- }
5138
- const activeTestPart = this.computedContext.testParts.find((testPart) => testPart.active);
5139
- const activeSection = activeTestPart?.sections.find((section) => section.active);
5140
- const activeItem = activeSection?.items.find((item) => item.active);
5141
- const { variables, ...augmentedItem } = activeItem || {};
5142
- if (!activeTestPart || !activeSection || !activeItem) {
5143
- return;
5144
- }
5145
- const augmentedTestPart = {
5146
- ...activeTestPart,
5147
- items: activeTestPart.sections.flatMap((section) => section.items.map(({ variables: variables2, ...rest }) => rest)),
5148
- sections: activeTestPart.sections.map((section) => ({
5149
- ...section,
5150
- items: section.items.map(({ variables: variables2, ...rest }) => rest)
5151
- }))
5152
- };
5153
- const augmentedSection = { ...activeSection, items: activeSection.items.map(({ variables: variables2, ...rest }) => rest) };
5154
- const { testParts, ...activeTest } = this.computedContext;
5155
- this.stampContext = {
5156
- view: this.computedContext.view,
5157
- activeItem: augmentedItem,
5158
- activeSection: augmentedSection,
5159
- activeTestpart: augmentedTestPart,
5160
- test: activeTest
5161
- };
5162
- this.dispatchEvent(new CustomEvent("qti-stamp-context-updated", {
5163
- detail: this.stampContext,
5164
- bubbles: true
5165
- }));
5166
- }
5167
- render() {
5168
- return html25` ${this.debug ? html25`<small><pre>${JSON.stringify(this.stampContext, null, 2)}</pre></small>` : nothing4}
5169
- ${this.myTemplate ? this.myTemplate(this.stampContext) : nothing4}`;
5170
- }
5171
- };
5172
- __decorate28([
5173
- property20({ type: Boolean, reflect: true })
5174
- ], TestStamp.prototype, "debug", void 0);
5175
- __decorate28([
5176
- state7(),
5177
- consume19({ context: computedContext, subscribe: true })
5178
- ], TestStamp.prototype, "computedContext", void 0);
5179
- __decorate28([
5180
- state7()
5181
- ], TestStamp.prototype, "stampContext", void 0);
5182
-
5183
- // ../qti-test/dist/components/test-view-toggle/test-view.js
5184
- import { html as html26, LitElement as LitElement27 } from "lit";
5185
- import { property as property21, state as state8 } from "lit/decorators.js";
5186
- import { consume as consume20 } from "@lit/context";
5187
- var __decorate29 = function(decorators, target, key, desc) {
5188
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5189
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5190
- 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;
5191
- return c > 3 && r && Object.defineProperty(target, key, r), r;
5192
- };
5193
- var _a;
5194
- var TestView = class extends LitElement27 {
5195
- constructor() {
5196
- super(...arguments);
5197
- this.label = "view";
5198
- this._handleViewOptionsChange = () => {
5199
- this.#updateViewOptions();
5200
- };
5201
- this._viewOptions = _a.DEFAULT_VIEW_OPTIONS;
5202
- }
5203
- static {
5204
- this.DEFAULT_VIEW_OPTIONS = ["author", "candidate", "proctor", "scorer", "testConstructor", "tutor"];
5205
- }
5206
- connectedCallback() {
5207
- super.connectedCallback();
5208
- this.#updateViewOptions();
5209
- }
5210
- #updateViewOptions() {
5211
- if (this.viewOptions) {
5212
- const options = this.viewOptions.split(",").map((opt) => opt.trim());
5213
- this._viewOptions = options.filter((opt) => _a.DEFAULT_VIEW_OPTIONS.includes(opt));
5214
- } else {
5215
- this._viewOptions = _a.DEFAULT_VIEW_OPTIONS;
5216
- }
5217
- }
5218
- _switchView(view) {
5219
- dispatchPublic(this, "cito-test-switch-view", view);
5220
- }
5221
- render() {
5222
- return html26`
5223
- <label part="label" for="viewSelect">${this.label}</label>
5224
- <select
5225
- part="select"
5226
- id="viewSelect"
5227
- @change=${(e) => {
5228
- const el = e.target;
5229
- this._switchView(el.value);
5230
- }}
5231
- >
5232
- ${this._viewOptions.map((v) => html26`<option value="${v}" ?selected=${v === this.sessionContext.view}>${v}</option>`)}
5233
- </select>
5234
- `;
5235
- }
5236
- };
5237
- _a = TestView;
5238
- __decorate29([
5239
- consume20({ context: sessionContext, subscribe: true })
5240
- ], TestView.prototype, "sessionContext", void 0);
5241
- __decorate29([
5242
- property21({ type: String })
5243
- ], TestView.prototype, "label", void 0);
5244
- __decorate29([
5245
- property21({ type: String, attribute: "view-options" })
5246
- ], TestView.prototype, "viewOptions", void 0);
5247
- __decorate29([
5248
- watch("viewOptions", { waitUntilFirstUpdate: true })
5249
- ], TestView.prototype, "_handleViewOptionsChange", void 0);
5250
- __decorate29([
5251
- state8()
5252
- ], TestView.prototype, "_viewOptions", void 0);
5253
-
5254
- // ../qti-test/dist/components/test-view-toggle/test-view-toggle.js
5255
- import { consume as consume21 } from "@lit/context";
5256
- import { html as html27, LitElement as LitElement28, nothing as nothing5 } from "lit";
5257
- var __decorate30 = function(decorators, target, key, desc) {
5258
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5259
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5260
- 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;
5261
- return c > 3 && r && Object.defineProperty(target, key, r), r;
5262
- };
5263
- var TestViewToggle = class extends LitElement28 {
5264
- createRenderRoot() {
5265
- return this;
5266
- }
5267
- connectedCallback() {
5268
- super.connectedCallback();
5269
- const templateElement = this.querySelector("template");
5270
- if (!templateElement) {
5271
- this.myTemplate = null;
5272
- return;
5273
- }
5274
- this.myTemplate = prepareTemplate(templateElement);
5275
- }
5276
- _switchView(view) {
5277
- dispatchPublic(this, "cito-test-switch-view", view);
5278
- }
5279
- firstUpdated(_changedProperties) {
5280
- this.addEventListener("click", () => {
5281
- if (this.sessionContext?.view === "scorer") {
5282
- this._switchView("candidate");
5283
- } else {
5284
- this._switchView("scorer");
5285
- }
5286
- });
5287
- }
5288
- render() {
5289
- return html27`${this.myTemplate ? this.myTemplate({
5290
- view: this.sessionContext?.view
5291
- }) : nothing5}`;
5292
- }
5293
- };
5294
- __decorate30([
5295
- consume21({ context: sessionContext, subscribe: true })
5296
- ], TestViewToggle.prototype, "sessionContext", void 0);
3990
+ // ../qti-test/dist/plugins/elements.js
3991
+ var pluginElements = [{ tag: "test-submit", ctor: TestSubmit }];
5297
3992
 
5298
3993
  // ../qti-test/dist/elements.js
5299
3994
  var qtiTestElements = [
@@ -5310,31 +4005,12 @@ var qtiTestElements = [
5310
4005
  { tag: "qti-test-feedback", ctor: QtiTestFeedback },
5311
4006
  { tag: "qti-test-part", ctor: QtiTestPart },
5312
4007
  { tag: "qti-test-variables", ctor: QtiTestVariables },
5313
- { tag: "test-check-item", ctor: TestCheckItem },
5314
4008
  { tag: "test-container", ctor: TestContainer },
5315
4009
  { tag: "test-end-attempt", ctor: TestEndAttempt },
5316
- { tag: "test-item-link", ctor: TestItemLink },
5317
- { tag: "test-item-to-speech", ctor: TestItemToSpeech },
5318
4010
  { tag: "test-navigation", ctor: TestNavigation },
5319
4011
  { tag: "test-next", ctor: TestNext },
5320
- { tag: "test-paging-buttons-stamp", ctor: TestPagingButtonsStamp },
5321
4012
  { tag: "test-prev", ctor: TestPrev },
5322
- { tag: "test-print-context", ctor: TestPrintContext },
5323
- { tag: "test-print-item-variables", ctor: TestPrintVariables },
5324
- { tag: "test-scoring-buttons", ctor: TestScoringButtons },
5325
- { tag: "test-scoring-feedback", ctor: TestScoringFeedback },
5326
- { tag: "test-section-buttons-stamp", ctor: TestSectionButtonsStamp },
5327
- { tag: "test-section-link", ctor: TestSectionLink },
5328
- { tag: "test-stamp", ctor: TestStamp },
5329
- { tag: "test-tts-next", ctor: TestTtsNext },
5330
- { tag: "test-tts-pause", ctor: TestTtsPause },
5331
- { tag: "test-tts-pick", ctor: TestTtsPick },
5332
- { tag: "test-tts-play", ctor: TestTtsPlay },
5333
- { tag: "test-tts-prev", ctor: TestTtsPrev },
5334
- { tag: "test-tts-resume", ctor: TestTtsResume },
5335
- { tag: "test-tts-stop", ctor: TestTtsStop },
5336
- { tag: "test-view", ctor: TestView },
5337
- { tag: "test-view-toggle", ctor: TestViewToggle }
4013
+ ...pluginElements
5338
4014
  ];
5339
4015
 
5340
4016
  export {
@@ -5353,33 +4029,15 @@ export {
5353
4029
  QtiTestVariables,
5354
4030
  QtiTestVariablesExpression,
5355
4031
  QTI_TEST_STATE_VERSION,
4032
+ stateFromContexts,
5356
4033
  QtiTest,
5357
- TestCheckItem,
5358
4034
  TestContainer,
5359
4035
  TestEndAttempt,
5360
- TestItemLink,
5361
- ttsContext,
5362
- TestItemToSpeech,
5363
- TestTtsPlay,
5364
- TestTtsPause,
5365
- TestTtsResume,
5366
- TestTtsStop,
5367
- TestTtsPrev,
5368
- TestTtsNext,
5369
- TestTtsPick,
5370
4036
  TestNavigation,
5371
4037
  TestNext,
5372
- TestPagingButtonsStamp,
5373
4038
  TestPrev,
5374
- TestPrintContext,
5375
- TestPrintVariables,
5376
- TestScoringButtons,
5377
- TestScoringFeedback,
5378
- TestSectionButtonsStamp,
5379
- TestSectionLink,
5380
- TestStamp,
5381
- TestView,
5382
- TestViewToggle,
4039
+ TestSubmit,
4040
+ pluginElements,
5383
4041
  qtiTestElements
5384
4042
  };
5385
4043
  /*! Bundled license information:
@@ -5394,4 +4052,4 @@ export {
5394
4052
  * Portions Copyright (c) 2013, the Dart project authors.
5395
4053
  *)
5396
4054
  */
5397
- //# sourceMappingURL=chunk-SIE3E4FG.js.map
4055
+ //# sourceMappingURL=chunk-YRR6D6UP.js.map