@pie-qti/item-player 1.0.0-beta.3 → 1.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -5
- package/dist/catalog/applyGlossaryTriggers.js +14 -2
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/catalog/catalogExtractor.js +2 -4
- package/dist/catalog/catalogExtractor.js.map +1 -1
- package/dist/catalog/sessionCatalog.d.ts +46 -0
- package/dist/catalog/sessionCatalog.js +87 -0
- package/dist/catalog/sessionCatalog.js.map +1 -0
- package/dist/components/utils/endAttempt.d.ts +16 -0
- package/dist/components/utils/endAttempt.js +28 -0
- package/dist/components/utils/endAttempt.js.map +1 -0
- package/dist/components/utils/focus.d.ts +19 -0
- package/dist/components/utils/focus.js +67 -0
- package/dist/components/utils/focus.js.map +1 -0
- package/dist/components/utils/itemBodyRenderer.d.ts +44 -0
- package/dist/components/utils/itemBodyRenderer.js +177 -0
- package/dist/components/utils/itemBodyRenderer.js.map +1 -0
- package/dist/components/utils/sentenceContext.d.ts +6 -0
- package/dist/components/utils/sentenceContext.js +16 -0
- package/dist/components/utils/sentenceContext.js.map +1 -0
- package/dist/core/AssessmentItemDefinition.d.ts +20 -1
- package/dist/core/AssessmentItemDefinition.js +12 -31
- package/dist/core/AssessmentItemDefinition.js.map +1 -1
- package/dist/core/ComponentRegistry.d.ts +92 -0
- package/dist/core/ComponentRegistry.js +7 -1
- package/dist/core/ComponentRegistry.js.map +1 -1
- package/dist/core/ItemSession.d.ts +18 -1
- package/dist/core/ItemSession.js +79 -41
- package/dist/core/ItemSession.js.map +1 -1
- package/dist/core/Player.d.ts +118 -141
- package/dist/core/Player.js +387 -1233
- package/dist/core/Player.js.map +1 -1
- package/dist/core/compliance.d.ts +72 -0
- package/dist/core/compliance.js +147 -0
- package/dist/core/compliance.js.map +1 -0
- package/dist/core/declarations/declarationBuilder.d.ts +29 -0
- package/dist/core/declarations/declarationBuilder.js +284 -0
- package/dist/core/declarations/declarationBuilder.js.map +1 -0
- package/dist/core/declarations/declarationValues.d.ts +11 -0
- package/dist/core/declarations/declarationValues.js +168 -0
- package/dist/core/declarations/declarationValues.js.map +1 -0
- package/dist/core/matchGroups.d.ts +36 -0
- package/dist/core/matchGroups.js +100 -0
- package/dist/core/matchGroups.js.map +1 -0
- package/dist/core/nameMappers.d.ts +35 -0
- package/dist/core/nameMappers.js +47 -0
- package/dist/core/nameMappers.js.map +1 -0
- package/dist/core/parsingLimits.d.ts +4 -0
- package/dist/core/parsingLimits.js +5 -2
- package/dist/core/parsingLimits.js.map +1 -1
- package/dist/core/processing/responseProcessing.d.ts +88 -0
- package/dist/core/processing/responseProcessing.js +317 -0
- package/dist/core/processing/responseProcessing.js.map +1 -0
- package/dist/core/processing/responseValidation.d.ts +55 -0
- package/dist/core/processing/responseValidation.js +335 -0
- package/dist/core/processing/responseValidation.js.map +1 -0
- package/dist/core/rendering/contentPass.d.ts +31 -0
- package/dist/core/rendering/contentPass.js +152 -0
- package/dist/core/rendering/contentPass.js.map +1 -0
- package/dist/core/rendering/htmlRender.d.ts +21 -0
- package/dist/core/rendering/htmlRender.js +56 -0
- package/dist/core/rendering/htmlRender.js.map +1 -0
- package/dist/core/responseProcessingTemplates.d.ts +23 -0
- package/dist/core/responseProcessingTemplates.js +45 -0
- package/dist/core/responseProcessingTemplates.js.map +1 -0
- package/dist/core/rolePolicy.d.ts +5 -0
- package/dist/core/rolePolicy.js +21 -0
- package/dist/core/rolePolicy.js.map +1 -1
- package/dist/core/sanitizer.js +8 -14
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/core/serialization/sessionState.d.ts +56 -0
- package/dist/core/serialization/sessionState.js +139 -0
- package/dist/core/serialization/sessionState.js.map +1 -0
- package/dist/core/serialization/valueForms.d.ts +32 -0
- package/dist/core/serialization/valueForms.js +112 -0
- package/dist/core/serialization/valueForms.js.map +1 -0
- package/dist/document/AssessmentItemDocument.d.ts +27 -1
- package/dist/document/AssessmentItemDocument.js +67 -31
- package/dist/document/AssessmentItemDocument.js.map +1 -1
- package/dist/element-class-BbF4Dj7F.js +3773 -0
- package/dist/element-class-BbF4Dj7F.js.map +1 -0
- package/dist/element-class.d.ts +34 -1
- package/dist/element-class.js +1 -1
- package/dist/element.js +1 -1
- package/dist/extraction/ExtractionRegistry.js +6 -12
- package/dist/extraction/ExtractionRegistry.js.map +1 -1
- package/dist/extraction/createContext.d.ts +2 -2
- package/dist/extraction/createContext.js.map +1 -1
- package/dist/extraction/index.d.ts +2 -2
- package/dist/extraction/index.js +1 -1
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/interactionCoverage.d.ts +31 -0
- package/dist/extraction/interactionCoverage.js +40 -0
- package/dist/extraction/interactionCoverage.js.map +1 -0
- package/dist/extraction/interactionExtractionPipeline.js +5 -10
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/interactionSecurity.js +1 -28
- package/dist/extraction/interactionSecurity.js.map +1 -1
- package/dist/extraction/mergeDeliveryFields.d.ts +13 -0
- package/dist/extraction/mergeDeliveryFields.js +17 -0
- package/dist/extraction/mergeDeliveryFields.js.map +1 -0
- package/dist/extraction/responseIdentifier.d.ts +19 -0
- package/dist/extraction/responseIdentifier.js +29 -0
- package/dist/extraction/responseIdentifier.js.map +1 -0
- package/dist/extraction/types.d.ts +11 -18
- package/dist/extraction/types.js +0 -12
- package/dist/extraction/types.js.map +1 -1
- package/dist/extraction/utils.d.ts +14 -0
- package/dist/extraction/utils.js +35 -5
- package/dist/extraction/utils.js.map +1 -1
- package/dist/index.d.ts +16 -10
- package/dist/index.js +19 -8
- package/dist/index.js.map +1 -1
- package/dist/interactions/associate/extractor.d.ts +1 -0
- package/dist/interactions/associate/extractor.js +10 -12
- package/dist/interactions/associate/extractor.js.map +1 -1
- package/dist/interactions/choice/extractor.js +6 -13
- package/dist/interactions/choice/extractor.js.map +1 -1
- package/dist/interactions/drawing/extractor.d.ts +6 -0
- package/dist/interactions/drawing/extractor.js +30 -9
- package/dist/interactions/drawing/extractor.js.map +1 -1
- package/dist/interactions/end-attempt/extractor.js +2 -1
- package/dist/interactions/end-attempt/extractor.js.map +1 -1
- package/dist/interactions/extended-text/extractor.d.ts +6 -1
- package/dist/interactions/extended-text/extractor.js +10 -5
- package/dist/interactions/extended-text/extractor.js.map +1 -1
- package/dist/interactions/extended-text/response.js +18 -18
- package/dist/interactions/extended-text/response.js.map +1 -1
- package/dist/interactions/gap-match/extractor.d.ts +40 -2
- package/dist/interactions/gap-match/extractor.js +197 -39
- package/dist/interactions/gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-associate/extractor.d.ts +11 -0
- package/dist/interactions/graphic-associate/extractor.js +35 -24
- package/dist/interactions/graphic-associate/extractor.js.map +1 -1
- package/dist/interactions/graphic-gap-match/extractor.d.ts +21 -0
- package/dist/interactions/graphic-gap-match/extractor.js +79 -43
- package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-order/extractor.d.ts +15 -0
- package/dist/interactions/graphic-order/extractor.js +39 -24
- package/dist/interactions/graphic-order/extractor.js.map +1 -1
- package/dist/interactions/hotspot/extractor.d.ts +6 -0
- package/dist/interactions/hotspot/extractor.js +31 -16
- package/dist/interactions/hotspot/extractor.js.map +1 -1
- package/dist/interactions/hottext/extractor.js +2 -12
- package/dist/interactions/hottext/extractor.js.map +1 -1
- package/dist/interactions/inline/accessibleName.d.ts +29 -0
- package/dist/interactions/inline/accessibleName.js +35 -0
- package/dist/interactions/inline/accessibleName.js.map +1 -0
- package/dist/interactions/inline/render-plan.d.ts +5 -14
- package/dist/interactions/inline/render-plan.js +5 -56
- package/dist/interactions/inline/render-plan.js.map +1 -1
- package/dist/interactions/inline-choice/extractor.d.ts +4 -0
- package/dist/interactions/inline-choice/extractor.js +13 -12
- package/dist/interactions/inline-choice/extractor.js.map +1 -1
- package/dist/interactions/match/extractor.d.ts +2 -0
- package/dist/interactions/match/extractor.js +14 -28
- package/dist/interactions/match/extractor.js.map +1 -1
- package/dist/interactions/media/extractor.d.ts +5 -11
- package/dist/interactions/media/extractor.js +100 -36
- package/dist/interactions/media/extractor.js.map +1 -1
- package/dist/interactions/modules.js +8 -2
- package/dist/interactions/modules.js.map +1 -1
- package/dist/interactions/order/extractor.d.ts +2 -0
- package/dist/interactions/order/extractor.js +8 -12
- package/dist/interactions/order/extractor.js.map +1 -1
- package/dist/interactions/order/limits.d.ts +29 -0
- package/dist/interactions/order/limits.js +28 -0
- package/dist/interactions/order/limits.js.map +1 -0
- package/dist/interactions/portable-custom/extractor.js +4 -2
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/position-object/extractor.d.ts +18 -1
- package/dist/interactions/position-object/extractor.js +81 -22
- package/dist/interactions/position-object/extractor.js.map +1 -1
- package/dist/interactions/select-point/extractor.d.ts +6 -0
- package/dist/interactions/select-point/extractor.js +31 -19
- package/dist/interactions/select-point/extractor.js.map +1 -1
- package/dist/interactions/shared/imageAlt.d.ts +54 -0
- package/dist/interactions/shared/imageAlt.js +84 -0
- package/dist/interactions/shared/imageAlt.js.map +1 -0
- package/dist/interactions/shared/interactionImage.d.ts +32 -0
- package/dist/interactions/shared/interactionImage.js +39 -0
- package/dist/interactions/shared/interactionImage.js.map +1 -0
- package/dist/interactions/shared/specDefaults.d.ts +20 -0
- package/dist/interactions/shared/specDefaults.js +25 -0
- package/dist/interactions/shared/specDefaults.js.map +1 -0
- package/dist/interactions/shared/types.d.ts +212 -40
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/interactions/text-entry/extractor.d.ts +9 -0
- package/dist/interactions/text-entry/extractor.js +9 -0
- package/dist/interactions/text-entry/extractor.js.map +1 -1
- package/dist/interactions/text-entry/inlineInputStyle.d.ts +10 -0
- package/dist/interactions/text-entry/inlineInputStyle.js +12 -0
- package/dist/interactions/text-entry/inlineInputStyle.js.map +1 -0
- package/dist/interactions/text-entry/inputMode.d.ts +35 -0
- package/dist/interactions/text-entry/inputMode.js +134 -0
- package/dist/interactions/text-entry/inputMode.js.map +1 -0
- package/dist/interactions/text-entry/response.d.ts +15 -0
- package/dist/interactions/text-entry/response.js +25 -0
- package/dist/interactions/text-entry/response.js.map +1 -0
- package/dist/interactions/upload/extractor.js +2 -2
- package/dist/interactions/upload/extractor.js.map +1 -1
- package/dist/pci/PciHost.d.ts +1 -1
- package/dist/pci/PciHost.js +11 -11
- package/dist/pci/PciHost.js.map +1 -1
- package/dist/pci/index.d.ts +1 -0
- package/dist/pci/index.js.map +1 -1
- package/dist/pci/modulePaths.d.ts +16 -0
- package/dist/pci/modulePaths.js +33 -0
- package/dist/pci/modulePaths.js.map +1 -0
- package/dist/pci/pageRealmSession.js +3 -15
- package/dist/pci/pageRealmSession.js.map +1 -1
- package/dist/pci/qtiVariableJson.d.ts +46 -3
- package/dist/pci/qtiVariableJson.js +247 -53
- package/dist/pci/qtiVariableJson.js.map +1 -1
- package/dist/pci/sandbox/SandboxedPciSession.d.ts +3 -0
- package/dist/pci/sandbox/SandboxedPciSession.js +15 -14
- package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -1
- package/dist/pci/sandbox/iframeConnector.d.ts +18 -4
- package/dist/pci/sandbox/iframeConnector.js +35 -6
- package/dist/pci/sandbox/iframeConnector.js.map +1 -1
- package/dist/pci/sandbox/protocol.d.ts +14 -0
- package/dist/pci/sandbox/protocol.js.map +1 -1
- package/dist/pci/sessionHosts.d.ts +47 -0
- package/dist/pci/sessionHosts.js +66 -0
- package/dist/pci/sessionHosts.js.map +1 -0
- package/dist/pci/types.d.ts +7 -1
- package/dist/pci/types.js.map +1 -1
- package/dist/pnp/applyPnp.d.ts +20 -3
- package/dist/pnp/applyPnp.js +84 -9
- package/dist/pnp/applyPnp.js.map +1 -1
- package/dist/pnp/parsePnpXml.js +2 -0
- package/dist/pnp/parsePnpXml.js.map +1 -1
- package/dist/pnp/types.d.ts +16 -8
- package/dist/pnp/types.js.map +1 -1
- package/dist/presentation/feedbackAnnouncement.d.ts +56 -0
- package/dist/presentation/feedbackAnnouncement.js +150 -0
- package/dist/presentation/feedbackAnnouncement.js.map +1 -0
- package/dist/presentation/interactionSlots.d.ts +31 -0
- package/dist/presentation/interactionSlots.js +101 -0
- package/dist/presentation/interactionSlots.js.map +1 -0
- package/dist/presentation/itemPresentationPlan.d.ts +69 -6
- package/dist/presentation/itemPresentationPlan.js +93 -81
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/{components/utils → presentation}/stimulusRender.js +3 -12
- package/dist/presentation/stimulusRender.js.map +1 -0
- package/dist/presentation/stylesheetRender.js.map +1 -0
- package/dist/security/escapeHtml.d.ts +15 -0
- package/dist/security/escapeHtml.js +22 -0
- package/dist/security/escapeHtml.js.map +1 -0
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.js +1 -0
- package/dist/security/index.js.map +1 -1
- package/dist/server.d.ts +8 -1
- package/dist/server.js.map +1 -1
- package/dist/session-inputs.d.ts +108 -0
- package/dist/session-inputs.js +130 -0
- package/dist/session-inputs.js.map +1 -0
- package/dist/types/index.d.ts +67 -35
- package/dist/types/index.js.map +1 -1
- package/dist/utils/cloneFreeze.d.ts +52 -0
- package/dist/utils/cloneFreeze.js +113 -0
- package/dist/utils/cloneFreeze.js.map +1 -0
- package/dist/utils/htmlAttributes.d.ts +13 -0
- package/dist/utils/htmlAttributes.js +22 -0
- package/dist/utils/htmlAttributes.js.map +1 -0
- package/dist/web-components/QTIInteractionElement.d.ts +0 -29
- package/dist/web-components/QTIInteractionElement.js +0 -32
- package/dist/web-components/QTIInteractionElement.js.map +1 -1
- package/dist/web-components/index.d.ts +1 -2
- package/dist/web-components/index.js +2 -3
- package/dist/web-components/index.js.map +1 -1
- package/package.json +15 -18
- package/dist/components/utils/feedbackUtils.d.ts +0 -77
- package/dist/components/utils/feedbackUtils.js +0 -138
- package/dist/components/utils/feedbackUtils.js.map +0 -1
- package/dist/components/utils/index.d.ts +0 -4
- package/dist/components/utils/index.js +0 -5
- package/dist/components/utils/index.js.map +0 -1
- package/dist/components/utils/stimulusRender.js.map +0 -1
- package/dist/components/utils/stylesheetRender.js.map +0 -1
- package/dist/core/constants.d.ts +0 -65
- package/dist/core/constants.js +0 -74
- package/dist/core/constants.js.map +0 -1
- package/dist/element-class-X2XXDa29.js +0 -9299
- package/dist/element-class-X2XXDa29.js.map +0 -1
- package/dist/extensions/MathLiveEditor.d.ts +0 -31
- package/dist/extensions/MathLiveEditor.js +0 -248
- package/dist/extensions/MathLiveEditor.js.map +0 -1
- package/dist/utils/PerformanceMonitor.d.ts +0 -169
- package/dist/utils/PerformanceMonitor.js +0 -243
- package/dist/utils/PerformanceMonitor.js.map +0 -1
- package/dist/utils/responseUtils.d.ts +0 -15
- package/dist/utils/responseUtils.js +0 -46
- package/dist/utils/responseUtils.js.map +0 -1
- package/dist/web-components/QTIInteractionBase.d.ts +0 -119
- package/dist/web-components/QTIInteractionBase.js +0 -244
- package/dist/web-components/QTIInteractionBase.js.map +0 -1
- /package/dist/{components/utils → presentation}/stimulusRender.d.ts +0 -0
- /package/dist/{components/utils → presentation}/stylesheetRender.d.ts +0 -0
- /package/dist/{components/utils → presentation}/stylesheetRender.js +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** The focused element, looking through open shadow roots. */
|
|
2
|
+
export function deepActiveElement(root) {
|
|
3
|
+
let active = root.activeElement;
|
|
4
|
+
while (active?.shadowRoot?.activeElement)
|
|
5
|
+
active = active.shadowRoot.activeElement;
|
|
6
|
+
return active;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Focus `target` when it can still take focus, and report whether it did. A disabled, hidden or
|
|
10
|
+
* removed element cannot, nor can the document body stand in for "where the user was".
|
|
11
|
+
*/
|
|
12
|
+
export function restoreFocus(target) {
|
|
13
|
+
const element = target;
|
|
14
|
+
if (!element?.isConnected || typeof element.focus !== 'function')
|
|
15
|
+
return false;
|
|
16
|
+
if (element === element.ownerDocument.body || element === element.ownerDocument.documentElement)
|
|
17
|
+
return false;
|
|
18
|
+
element.focus({ preventScroll: true });
|
|
19
|
+
return deepActiveElement(element.ownerDocument) === element;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Move focus to a container that is not otherwise focusable, for as long as it holds focus: it is
|
|
23
|
+
* made programmatically focusable and loses that again on blur, so it never joins the tab order.
|
|
24
|
+
*/
|
|
25
|
+
export function focusContainer(element) {
|
|
26
|
+
if (!element?.isConnected)
|
|
27
|
+
return;
|
|
28
|
+
if (!element.hasAttribute('tabindex')) {
|
|
29
|
+
element.setAttribute('tabindex', '-1');
|
|
30
|
+
element.addEventListener('blur', () => element.removeAttribute('tabindex'), { once: true });
|
|
31
|
+
}
|
|
32
|
+
element.focus({ preventScroll: true });
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Open `dialog` as a modal. `showModal()` places it in the top layer, makes the rest of the page
|
|
36
|
+
* inert and turns Escape into a `cancel` event. Where it is not implemented (jsdom, very old
|
|
37
|
+
* engines) the dialog opens in place instead; the caller still handles Escape and focus.
|
|
38
|
+
*/
|
|
39
|
+
export function openModalDialog(dialog) {
|
|
40
|
+
if (typeof dialog.showModal === 'function') {
|
|
41
|
+
try {
|
|
42
|
+
if (!dialog.open)
|
|
43
|
+
dialog.showModal();
|
|
44
|
+
return 'modal';
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Not connected, or already open without being modal.
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
dialog.setAttribute('open', '');
|
|
51
|
+
return 'non-modal';
|
|
52
|
+
}
|
|
53
|
+
export function closeModalDialog(dialog) {
|
|
54
|
+
if (!dialog.open)
|
|
55
|
+
return;
|
|
56
|
+
if (typeof dialog.close === 'function') {
|
|
57
|
+
try {
|
|
58
|
+
dialog.close();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Fall through to removing the attribute.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
dialog.removeAttribute('open');
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus.js","sourceRoot":"","sources":["../../../src/components/utils/focus.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAAC,IAA2B;IAC5D,IAAI,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;IAChC,OAAO,MAAM,EAAE,UAAU,EAAE,aAAa;QAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC;IACnF,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkC;IAC9D,MAAM,OAAO,GAAG,MAAwC,CAAC;IACzD,IAAI,CAAC,OAAO,EAAE,WAAW,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IAC/E,IAAI,OAAO,KAAK,OAAO,CAAC,aAAa,CAAC,IAAI,IAAI,OAAO,KAAK,OAAO,CAAC,aAAa,CAAC,eAAe;QAAE,OAAO,KAAK,CAAC;IAC9G,OAAO,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,OAAO,iBAAiB,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,OAAO,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAuC;IACrE,IAAI,CAAC,OAAO,EAAE,WAAW;QAAE,OAAO;IAClC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QACvC,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACvC,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAyB;IACxD,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;QAC5C,IAAI,CAAC;YACJ,IAAI,CAAC,MAAM,CAAC,IAAI;gBAAE,MAAM,CAAC,SAAS,EAAE,CAAC;YACrC,OAAO,OAAO,CAAC;QAChB,CAAC;QAAC,MAAM,CAAC;YACR,sDAAsD;QACvD,CAAC;IACF,CAAC;IACD,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChC,OAAO,WAAW,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAyB;IACzD,IAAI,CAAC,MAAM,CAAC,IAAI;QAAE,OAAO;IACzB,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QACxC,IAAI,CAAC;YACJ,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,OAAO;QACR,CAAC;QAAC,MAAM,CAAC;YACR,0CAA0C;QAC3C,CAAC;IACF,CAAC;IACD,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/** The focused element, looking through open shadow roots. */\nexport function deepActiveElement(root: Document | ShadowRoot): Element | null {\n\tlet active = root.activeElement;\n\twhile (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;\n\treturn active;\n}\n\n/**\n * Focus `target` when it can still take focus, and report whether it did. A disabled, hidden or\n * removed element cannot, nor can the document body stand in for \"where the user was\".\n */\nexport function restoreFocus(target: Element | null | undefined): boolean {\n\tconst element = target as HTMLElement | null | undefined;\n\tif (!element?.isConnected || typeof element.focus !== 'function') return false;\n\tif (element === element.ownerDocument.body || element === element.ownerDocument.documentElement) return false;\n\telement.focus({ preventScroll: true });\n\treturn deepActiveElement(element.ownerDocument) === element;\n}\n\n/**\n * Move focus to a container that is not otherwise focusable, for as long as it holds focus: it is\n * made programmatically focusable and loses that again on blur, so it never joins the tab order.\n */\nexport function focusContainer(element: HTMLElement | null | undefined): void {\n\tif (!element?.isConnected) return;\n\tif (!element.hasAttribute('tabindex')) {\n\t\telement.setAttribute('tabindex', '-1');\n\t\telement.addEventListener('blur', () => element.removeAttribute('tabindex'), { once: true });\n\t}\n\telement.focus({ preventScroll: true });\n}\n\n/**\n * Open `dialog` as a modal. `showModal()` places it in the top layer, makes the rest of the page\n * inert and turns Escape into a `cancel` event. Where it is not implemented (jsdom, very old\n * engines) the dialog opens in place instead; the caller still handles Escape and focus.\n */\nexport function openModalDialog(dialog: HTMLDialogElement): 'modal' | 'non-modal' {\n\tif (typeof dialog.showModal === 'function') {\n\t\ttry {\n\t\t\tif (!dialog.open) dialog.showModal();\n\t\t\treturn 'modal';\n\t\t} catch {\n\t\t\t// Not connected, or already open without being modal.\n\t\t}\n\t}\n\tdialog.setAttribute('open', '');\n\treturn 'non-modal';\n}\n\nexport function closeModalDialog(dialog: HTMLDialogElement): void {\n\tif (!dialog.open) return;\n\tif (typeof dialog.close === 'function') {\n\t\ttry {\n\t\t\tdialog.close();\n\t\t\treturn;\n\t\t} catch {\n\t\t\t// Fall through to removing the attribute.\n\t\t}\n\t}\n\tdialog.removeAttribute('open');\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { HtmlContent } from '../../types/index.js';
|
|
2
|
+
/** The part of an interaction mount the renderer needs: its identity and where it goes. */
|
|
3
|
+
export interface SlottedMount {
|
|
4
|
+
readonly key: string;
|
|
5
|
+
/** The slot in the body HTML; null renders the interaction after the body. */
|
|
6
|
+
readonly slot: string | null;
|
|
7
|
+
}
|
|
8
|
+
/** One live interaction: the element placed at its slot, kept while its key is stable. */
|
|
9
|
+
export interface MountedInteraction<M extends SlottedMount> {
|
|
10
|
+
readonly element: HTMLElement;
|
|
11
|
+
/** Apply a newer presentation of the same interaction. */
|
|
12
|
+
update(mount: M): void;
|
|
13
|
+
/** After every render, the slot the element sits in, or null when it renders after the body. */
|
|
14
|
+
placed?(slot: Element | null): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
export interface ItemBodyRendererOptions<M extends SlottedMount> {
|
|
18
|
+
create(mount: M): MountedInteraction<M>;
|
|
19
|
+
onError?(mount: M, error: unknown): void;
|
|
20
|
+
}
|
|
21
|
+
export interface ItemBodyRenderer<M extends SlottedMount> {
|
|
22
|
+
/** Render the finalized body HTML and place every mount at its slot. */
|
|
23
|
+
render(html: HtmlContent, mounts: readonly M[]): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
}
|
|
26
|
+
/** Class of the area after the body where an interaction with no slot renders. */
|
|
27
|
+
export declare const UNSLOTTED_CLASS = "qti-item-body-unslotted";
|
|
28
|
+
/**
|
|
29
|
+
* Renders an item presentation into `container`: the body HTML once, with every interaction
|
|
30
|
+
* mounted into the slot element that marks its authored position.
|
|
31
|
+
*
|
|
32
|
+
* Interactions are keyed. A response change re-renders nothing but the changed props, and the
|
|
33
|
+
* body HTML is only replaced when its markup changes (feedback, template or printed-variable
|
|
34
|
+
* content after response processing). Then the new body is inserted before the old one is
|
|
35
|
+
* removed and each live interaction is moved into its new slot — with `moveBefore` where the
|
|
36
|
+
* browser has it, which keeps focus, iframes and media state — so interactions never remount
|
|
37
|
+
* and focus is restored if the move dropped it.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createItemBodyRenderer<M extends SlottedMount>(container: HTMLElement, options: ItemBodyRendererOptions<M>): ItemBodyRenderer<M>;
|
|
40
|
+
/**
|
|
41
|
+
* Move `node` under `parent`. `moveBefore` moves a connected node without disconnecting it, so an
|
|
42
|
+
* iframe does not reload, media keeps playing and focus stays; elsewhere it is a plain insert.
|
|
43
|
+
*/
|
|
44
|
+
export declare function moveInto(parent: Node & ParentNode, node: Node, before: Node | null): void;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { INTERACTION_SLOT_ATTRIBUTE } from '../../presentation/interactionSlots.js';
|
|
2
|
+
import { deepActiveElement } from './focus.js';
|
|
3
|
+
/** Class of the area after the body where an interaction with no slot renders. */
|
|
4
|
+
export const UNSLOTTED_CLASS = 'qti-item-body-unslotted';
|
|
5
|
+
/**
|
|
6
|
+
* Renders an item presentation into `container`: the body HTML once, with every interaction
|
|
7
|
+
* mounted into the slot element that marks its authored position.
|
|
8
|
+
*
|
|
9
|
+
* Interactions are keyed. A response change re-renders nothing but the changed props, and the
|
|
10
|
+
* body HTML is only replaced when its markup changes (feedback, template or printed-variable
|
|
11
|
+
* content after response processing). Then the new body is inserted before the old one is
|
|
12
|
+
* removed and each live interaction is moved into its new slot — with `moveBefore` where the
|
|
13
|
+
* browser has it, which keeps focus, iframes and media state — so interactions never remount
|
|
14
|
+
* and focus is restored if the move dropped it.
|
|
15
|
+
*/
|
|
16
|
+
export function createItemBodyRenderer(container, options) {
|
|
17
|
+
const entries = new Map();
|
|
18
|
+
let renderedMarkup = null;
|
|
19
|
+
let unslotted = null;
|
|
20
|
+
let destroyed = false;
|
|
21
|
+
const ensureUnslotted = () => {
|
|
22
|
+
if (!unslotted) {
|
|
23
|
+
unslotted = container.ownerDocument.createElement('div');
|
|
24
|
+
unslotted.className = UNSLOTTED_CLASS;
|
|
25
|
+
container.append(unslotted);
|
|
26
|
+
}
|
|
27
|
+
return unslotted;
|
|
28
|
+
};
|
|
29
|
+
const retire = (key, entry) => {
|
|
30
|
+
entries.delete(key);
|
|
31
|
+
try {
|
|
32
|
+
entry.destroy();
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
entry.element.remove();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const replaceBody = (html, nextSlots) => {
|
|
39
|
+
const focus = captureFocus(container);
|
|
40
|
+
const template = container.ownerDocument.createElement('template');
|
|
41
|
+
// A TrustedHTML value is assigned as-is, so an enforcing Trusted Types policy governs it.
|
|
42
|
+
template.innerHTML = html;
|
|
43
|
+
const freshSlots = collectSlots(template.content);
|
|
44
|
+
const previous = Array.from(container.childNodes).filter((node) => node !== unslotted);
|
|
45
|
+
container.insertBefore(template.content, unslotted);
|
|
46
|
+
for (const [key, entry] of entries) {
|
|
47
|
+
const slot = nextSlots.get(key);
|
|
48
|
+
const target = slot == null ? undefined : freshSlots.get(slot);
|
|
49
|
+
if (target)
|
|
50
|
+
moveInto(target, entry.element, null);
|
|
51
|
+
else if (previous.some((node) => node.contains(entry.element))) {
|
|
52
|
+
moveInto(ensureUnslotted(), entry.element, null);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const node of previous)
|
|
56
|
+
node.remove();
|
|
57
|
+
focus.restore();
|
|
58
|
+
};
|
|
59
|
+
const placeUnslotted = (order) => {
|
|
60
|
+
if (order.length === 0) {
|
|
61
|
+
if (unslotted && !unslotted.hasChildNodes()) {
|
|
62
|
+
unslotted.remove();
|
|
63
|
+
unslotted = null;
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const area = ensureUnslotted();
|
|
68
|
+
let cursor = area.firstChild;
|
|
69
|
+
for (const element of order) {
|
|
70
|
+
if (element === cursor) {
|
|
71
|
+
cursor = cursor.nextSibling;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
moveInto(area, element, cursor);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
render(html, mounts) {
|
|
79
|
+
if (destroyed)
|
|
80
|
+
return;
|
|
81
|
+
const nextSlots = new Map(mounts.map((mount) => [mount.key, mount.slot]));
|
|
82
|
+
// Retire interactions that went away first, so what they render never coexists with
|
|
83
|
+
// a replacement that renders the same ids.
|
|
84
|
+
for (const [key, entry] of [...entries]) {
|
|
85
|
+
if (!nextSlots.has(key))
|
|
86
|
+
retire(key, entry);
|
|
87
|
+
}
|
|
88
|
+
const markup = typeof html === 'string' ? html : String(html);
|
|
89
|
+
if (markup !== renderedMarkup) {
|
|
90
|
+
replaceBody(html, nextSlots);
|
|
91
|
+
renderedMarkup = markup;
|
|
92
|
+
}
|
|
93
|
+
const slots = collectSlots(container);
|
|
94
|
+
const unslottedOrder = [];
|
|
95
|
+
const placements = [];
|
|
96
|
+
for (const mount of mounts) {
|
|
97
|
+
let entry = entries.get(mount.key);
|
|
98
|
+
try {
|
|
99
|
+
if (entry)
|
|
100
|
+
entry.update(mount);
|
|
101
|
+
else {
|
|
102
|
+
entry = options.create(mount);
|
|
103
|
+
entries.set(mount.key, entry);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
options.onError?.(mount, error);
|
|
108
|
+
}
|
|
109
|
+
if (!entry)
|
|
110
|
+
continue;
|
|
111
|
+
const slot = mount.slot === null ? null : (slots.get(mount.slot) ?? null);
|
|
112
|
+
if (slot) {
|
|
113
|
+
if (entry.element.parentNode !== slot)
|
|
114
|
+
moveInto(slot, entry.element, null);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
unslottedOrder.push(entry.element);
|
|
118
|
+
}
|
|
119
|
+
placements.push([entry, slot]);
|
|
120
|
+
}
|
|
121
|
+
placeUnslotted(unslottedOrder);
|
|
122
|
+
for (const [entry, slot] of placements)
|
|
123
|
+
entry.placed?.(slot);
|
|
124
|
+
},
|
|
125
|
+
destroy() {
|
|
126
|
+
destroyed = true;
|
|
127
|
+
for (const [key, entry] of [...entries])
|
|
128
|
+
retire(key, entry);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** The slot elements under `root`, keyed by slot id; the first wins should an id repeat. */
|
|
133
|
+
function collectSlots(root) {
|
|
134
|
+
const slots = new Map();
|
|
135
|
+
for (const element of Array.from(root.querySelectorAll(`[${INTERACTION_SLOT_ATTRIBUTE}]`))) {
|
|
136
|
+
const slot = element.getAttribute(INTERACTION_SLOT_ATTRIBUTE);
|
|
137
|
+
if (slot !== null && !slots.has(slot))
|
|
138
|
+
slots.set(slot, element);
|
|
139
|
+
}
|
|
140
|
+
return slots;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Move `node` under `parent`. `moveBefore` moves a connected node without disconnecting it, so an
|
|
144
|
+
* iframe does not reload, media keeps playing and focus stays; elsewhere it is a plain insert.
|
|
145
|
+
*/
|
|
146
|
+
export function moveInto(parent, node, before) {
|
|
147
|
+
const movable = parent;
|
|
148
|
+
if (typeof movable.moveBefore === 'function' && node.isConnected && parent.isConnected) {
|
|
149
|
+
try {
|
|
150
|
+
movable.moveBefore(node, before);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Different trees, or a node the browser cannot move atomically.
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
parent.insertBefore(node, before);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Remember the focused element inside `container`, to give focus back to it should replacing
|
|
161
|
+
* the body take it away (a plain DOM move blurs the moved subtree).
|
|
162
|
+
*/
|
|
163
|
+
function captureFocus(container) {
|
|
164
|
+
const root = container.getRootNode();
|
|
165
|
+
const outer = root.activeElement;
|
|
166
|
+
if (!outer || !container.contains(outer))
|
|
167
|
+
return { restore() { } };
|
|
168
|
+
const focused = deepActiveElement(root);
|
|
169
|
+
return {
|
|
170
|
+
restore() {
|
|
171
|
+
if (!focused?.isConnected || deepActiveElement(root) === focused)
|
|
172
|
+
return;
|
|
173
|
+
focused.focus?.({ preventScroll: true });
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=itemBodyRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itemBodyRenderer.js","sourceRoot":"","sources":["../../../src/components/utils/itemBodyRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAEpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,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AI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,OAAO,KAAI,CAAC,EAAE,CAAC;IAClE,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAuB,CAAC;IAC9D,OAAO;QACN,OAAO;YACN,IAAI,CAAC,OAAO,EAAE,WAAW,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,OAAO;gBAAE,OAAO;YACzE,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { INTERACTION_SLOT_ATTRIBUTE } from '../../presentation/interactionSlots.js';\nimport type { HtmlContent } from '../../types/index.js';\nimport { deepActiveElement } from './focus.js';\n\n/** The part of an interaction mount the renderer needs: its identity and where it goes. */\nexport interface SlottedMount {\n\treadonly key: string;\n\t/** The slot in the body HTML; null renders the interaction after the body. */\n\treadonly slot: string | null;\n}\n\n/** One live interaction: the element placed at its slot, kept while its key is stable. */\nexport interface MountedInteraction<M extends SlottedMount> {\n\treadonly element: HTMLElement;\n\t/** Apply a newer presentation of the same interaction. */\n\tupdate(mount: M): void;\n\t/** After every render, the slot the element sits in, or null when it renders after the body. */\n\tplaced?(slot: Element | null): void;\n\tdestroy(): void;\n}\n\nexport interface ItemBodyRendererOptions<M extends SlottedMount> {\n\tcreate(mount: M): MountedInteraction<M>;\n\tonError?(mount: M, error: unknown): void;\n}\n\nexport interface ItemBodyRenderer<M extends SlottedMount> {\n\t/** Render the finalized body HTML and place every mount at its slot. */\n\trender(html: HtmlContent, mounts: readonly M[]): void;\n\tdestroy(): void;\n}\n\n/** Class of the area after the body where an interaction with no slot renders. */\nexport const UNSLOTTED_CLASS = 'qti-item-body-unslotted';\n\n/**\n * Renders an item presentation into `container`: the body HTML once, with every interaction\n * mounted into the slot element that marks its authored position.\n *\n * Interactions are keyed. A response change re-renders nothing but the changed props, and the\n * body HTML is only replaced when its markup changes (feedback, template or printed-variable\n * content after response processing). Then the new body is inserted before the old one is\n * removed and each live interaction is moved into its new slot — with `moveBefore` where the\n * browser has it, which keeps focus, iframes and media state — so interactions never remount\n * and focus is restored if the move dropped it.\n */\nexport function createItemBodyRenderer<M extends SlottedMount>(\n\tcontainer: HTMLElement,\n\toptions: ItemBodyRendererOptions<M>\n): ItemBodyRenderer<M> {\n\tconst entries = new Map<string, MountedInteraction<M>>();\n\tlet renderedMarkup: string | null = null;\n\tlet unslotted: HTMLElement | null = null;\n\tlet destroyed = false;\n\n\tconst ensureUnslotted = (): HTMLElement => {\n\t\tif (!unslotted) {\n\t\t\tunslotted = container.ownerDocument.createElement('div');\n\t\t\tunslotted.className = UNSLOTTED_CLASS;\n\t\t\tcontainer.append(unslotted);\n\t\t}\n\t\treturn unslotted;\n\t};\n\n\tconst retire = (key: string, entry: MountedInteraction<M>) => {\n\t\tentries.delete(key);\n\t\ttry {\n\t\t\tentry.destroy();\n\t\t} finally {\n\t\t\tentry.element.remove();\n\t\t}\n\t};\n\n\tconst replaceBody = (html: HtmlContent, nextSlots: ReadonlyMap<string, string | null>) => {\n\t\tconst focus = captureFocus(container);\n\t\tconst template = container.ownerDocument.createElement('template');\n\t\t// A TrustedHTML value is assigned as-is, so an enforcing Trusted Types policy governs it.\n\t\ttemplate.innerHTML = html as unknown as string;\n\t\tconst freshSlots = collectSlots(template.content);\n\t\tconst previous = Array.from(container.childNodes).filter((node) => node !== unslotted);\n\t\tcontainer.insertBefore(template.content, unslotted);\n\t\tfor (const [key, entry] of entries) {\n\t\t\tconst slot = nextSlots.get(key);\n\t\t\tconst target = slot == null ? undefined : freshSlots.get(slot);\n\t\t\tif (target) moveInto(target, entry.element, null);\n\t\t\telse if (previous.some((node) => node.contains(entry.element))) {\n\t\t\t\tmoveInto(ensureUnslotted(), entry.element, null);\n\t\t\t}\n\t\t}\n\t\tfor (const node of previous) node.remove();\n\t\tfocus.restore();\n\t};\n\n\tconst placeUnslotted = (order: readonly HTMLElement[]) => {\n\t\tif (order.length === 0) {\n\t\t\tif (unslotted && !unslotted.hasChildNodes()) {\n\t\t\t\tunslotted.remove();\n\t\t\t\tunslotted = null;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst area = ensureUnslotted();\n\t\tlet cursor = area.firstChild;\n\t\tfor (const element of order) {\n\t\t\tif (element === cursor) {\n\t\t\t\tcursor = cursor.nextSibling;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmoveInto(area, element, cursor);\n\t\t}\n\t};\n\n\treturn {\n\t\trender(html, mounts) {\n\t\t\tif (destroyed) return;\n\t\t\tconst nextSlots = new Map(mounts.map((mount) => [mount.key, mount.slot]));\n\t\t\t// Retire interactions that went away first, so what they render never coexists with\n\t\t\t// a replacement that renders the same ids.\n\t\t\tfor (const [key, entry] of [...entries]) {\n\t\t\t\tif (!nextSlots.has(key)) retire(key, entry);\n\t\t\t}\n\n\t\t\tconst markup = typeof html === 'string' ? html : String(html);\n\t\t\tif (markup !== renderedMarkup) {\n\t\t\t\treplaceBody(html, nextSlots);\n\t\t\t\trenderedMarkup = markup;\n\t\t\t}\n\n\t\t\tconst slots = collectSlots(container);\n\t\t\tconst unslottedOrder: HTMLElement[] = [];\n\t\t\tconst placements: Array<[MountedInteraction<M>, Element | null]> = [];\n\t\t\tfor (const mount of mounts) {\n\t\t\t\tlet entry = entries.get(mount.key);\n\t\t\t\ttry {\n\t\t\t\t\tif (entry) entry.update(mount);\n\t\t\t\t\telse {\n\t\t\t\t\t\tentry = options.create(mount);\n\t\t\t\t\t\tentries.set(mount.key, entry);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\toptions.onError?.(mount, error);\n\t\t\t\t}\n\t\t\t\tif (!entry) continue;\n\t\t\t\tconst slot = mount.slot === null ? null : (slots.get(mount.slot) ?? null);\n\t\t\t\tif (slot) {\n\t\t\t\t\tif (entry.element.parentNode !== slot) moveInto(slot, entry.element, null);\n\t\t\t\t} else {\n\t\t\t\t\tunslottedOrder.push(entry.element);\n\t\t\t\t}\n\t\t\t\tplacements.push([entry, slot]);\n\t\t\t}\n\t\t\tplaceUnslotted(unslottedOrder);\n\t\t\tfor (const [entry, slot] of placements) entry.placed?.(slot);\n\t\t},\n\t\tdestroy() {\n\t\t\tdestroyed = true;\n\t\t\tfor (const [key, entry] of [...entries]) retire(key, entry);\n\t\t},\n\t};\n}\n\n/** The slot elements under `root`, keyed by slot id; the first wins should an id repeat. */\nfunction collectSlots(root: ParentNode): Map<string, Element> {\n\tconst slots = new Map<string, Element>();\n\tfor (const element of Array.from(root.querySelectorAll(`[${INTERACTION_SLOT_ATTRIBUTE}]`))) {\n\t\tconst slot = element.getAttribute(INTERACTION_SLOT_ATTRIBUTE);\n\t\tif (slot !== null && !slots.has(slot)) slots.set(slot, element);\n\t}\n\treturn slots;\n}\n\ntype MoveCapableParent = ParentNode & { moveBefore?: (node: Node, child: Node | null) => void };\n\n/**\n * Move `node` under `parent`. `moveBefore` moves a connected node without disconnecting it, so an\n * iframe does not reload, media keeps playing and focus stays; elsewhere it is a plain insert.\n */\nexport function moveInto(parent: Node & ParentNode, node: Node, before: Node | null): void {\n\tconst movable = parent as MoveCapableParent;\n\tif (typeof movable.moveBefore === 'function' && node.isConnected && parent.isConnected) {\n\t\ttry {\n\t\t\tmovable.moveBefore(node, before);\n\t\t\treturn;\n\t\t} catch {\n\t\t\t// Different trees, or a node the browser cannot move atomically.\n\t\t}\n\t}\n\tparent.insertBefore(node, before);\n}\n\n/**\n * Remember the focused element inside `container`, to give focus back to it should replacing\n * the body take it away (a plain DOM move blurs the moved subtree).\n */\nfunction captureFocus(container: HTMLElement): { restore(): void } {\n\tconst root = container.getRootNode() as Document | ShadowRoot;\n\tconst outer = root.activeElement;\n\tif (!outer || !container.contains(outer)) return { restore() {} };\n\tconst focused = deepActiveElement(root) as HTMLElement | null;\n\treturn {\n\t\trestore() {\n\t\t\tif (!focused?.isConnected || deepActiveElement(root) === focused) return;\n\t\t\tfocused.focus?.({ preventScroll: true });\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The id of the sentence or paragraph an inline interaction's slot sits in, which describes the
|
|
3
|
+
* blank to assistive technology ("The capital of France is …"), giving that element an id from
|
|
4
|
+
* `nextId` when it has none. Undefined when the slot is in no such block inside `root`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sentenceContextId(slot: Element, root: Element, nextId: () => string): string | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Blocks of running text an inline interaction can sit in. */
|
|
2
|
+
const SENTENCE_CONTAINERS = 'p, li, dt, dd, td, th, caption, figcaption, blockquote, h1, h2, h3, h4, h5, h6, legend, summary';
|
|
3
|
+
/**
|
|
4
|
+
* The id of the sentence or paragraph an inline interaction's slot sits in, which describes the
|
|
5
|
+
* blank to assistive technology ("The capital of France is …"), giving that element an id from
|
|
6
|
+
* `nextId` when it has none. Undefined when the slot is in no such block inside `root`.
|
|
7
|
+
*/
|
|
8
|
+
export function sentenceContextId(slot, root, nextId) {
|
|
9
|
+
const context = slot.parentElement?.closest(SENTENCE_CONTAINERS);
|
|
10
|
+
if (!context || context === root || !root.contains(context))
|
|
11
|
+
return undefined;
|
|
12
|
+
if (!context.id)
|
|
13
|
+
context.id = nextId();
|
|
14
|
+
return context.id;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=sentenceContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentenceContext.js","sourceRoot":"","sources":["../../../src/components/utils/sentenceContext.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,MAAM,mBAAmB,GACxB,iGAAiG,CAAC;AAEnG;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAChC,IAAa,EACb,IAAa,EACb,MAAoB;IAEpB,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACjE,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9E,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC;IACvC,OAAO,OAAO,CAAC,EAAE,CAAC;AACnB,CAAC","sourcesContent":["/** Blocks of running text an inline interaction can sit in. */\nconst SENTENCE_CONTAINERS =\n\t'p, li, dt, dd, td, th, caption, figcaption, blockquote, h1, h2, h3, h4, h5, h6, legend, summary';\n\n/**\n * The id of the sentence or paragraph an inline interaction's slot sits in, which describes the\n * blank to assistive technology (\"The capital of France is …\"), giving that element an id from\n * `nextId` when it has none. Undefined when the slot is in no such block inside `root`.\n */\nexport function sentenceContextId(\n\tslot: Element,\n\troot: Element,\n\tnextId: () => string\n): string | undefined {\n\tconst context = slot.parentElement?.closest(SENTENCE_CONTAINERS);\n\tif (!context || context === root || !root.contains(context)) return undefined;\n\tif (!context.id) context.id = nextId();\n\treturn context.id;\n}\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type AttributeNameMapper, type ElementNameMapper } from '@pie-qti/qti-common';
|
|
2
2
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
3
3
|
import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
|
|
4
|
-
import type { ProcessingFragmentResolver, QtiValue } from '@pie-qti/qti-processing';
|
|
4
|
+
import type { ProcessingFragmentResolver, QtiValue, StringComparisonOptions } from '@pie-qti/qti-processing';
|
|
5
5
|
import { type ExtractionRegistry } from '../extraction/ExtractionRegistry.js';
|
|
6
6
|
import type { PciConfiguration } from '../pci/types.js';
|
|
7
7
|
import type { PnpProfile } from '../pnp/types.js';
|
|
8
8
|
import type { PlayerSecurityConfig, QTIComplianceConfig, QTIRole } from '../types/index.js';
|
|
9
9
|
import type { ComponentRegistry } from './ComponentRegistry.js';
|
|
10
|
+
import type { QtiItemDiagnostic } from './compliance.js';
|
|
10
11
|
import { type ItemSession, type OpenItemSessionOptions } from './ItemSession.js';
|
|
11
12
|
/**
|
|
12
13
|
* Synchronous, definition-lifetime extension contract.
|
|
@@ -45,6 +46,17 @@ export interface AssessmentItemDefinitionConfig {
|
|
|
45
46
|
class?: string;
|
|
46
47
|
definition?: string;
|
|
47
48
|
}) => QtiValue>>;
|
|
49
|
+
/**
|
|
50
|
+
* How response processing compares `string` values, for the input the host's candidates use.
|
|
51
|
+
* By default it compares as QTI defines (`match` is true when the values are "the same value",
|
|
52
|
+
* QTI 3.0 §6.9.21): exactly, up to Unicode canonical equivalence, with case folded only where
|
|
53
|
+
* the item asks for it (`stringMatch` and `mapEntry` caseSensitive false). Set
|
|
54
|
+
* `foldScriptInput` for input methods that add bidi marks, tatweel or presentation forms to
|
|
55
|
+
* right-to-left text, or to accept other scripts' digits in string answers; set
|
|
56
|
+
* `foldLetterVariants` to also accept Arabic spelling variants. Numbers typed into integer and
|
|
57
|
+
* float responses read digits in any script either way.
|
|
58
|
+
*/
|
|
59
|
+
readonly stringComparison?: Readonly<StringComparisonOptions>;
|
|
48
60
|
readonly resolveProcessingFragment?: ProcessingFragmentResolver;
|
|
49
61
|
readonly processingFragmentLimits?: Readonly<{
|
|
50
62
|
/** Maximum nested xi:include depth. Default: 16. */
|
|
@@ -61,6 +73,13 @@ export interface AssessmentItemDefinitionConfig {
|
|
|
61
73
|
}
|
|
62
74
|
export interface AssessmentItemDefinition {
|
|
63
75
|
readonly identifier: string;
|
|
76
|
+
/**
|
|
77
|
+
* QTI compliance findings from compiling the item: version assumptions, element names outside
|
|
78
|
+
* the item's QTI vocabulary, interactions bound to no response declaration, and interactions no
|
|
79
|
+
* registered extractor renders. Errors under `strictQtiCompliance.enabled`, warnings otherwise;
|
|
80
|
+
* empty when the item compiled cleanly. See `QTIComplianceConfig`.
|
|
81
|
+
*/
|
|
82
|
+
readonly diagnostics: readonly QtiItemDiagnostic[];
|
|
64
83
|
openSession(options?: OpenItemSessionOptions): ItemSession;
|
|
65
84
|
}
|
|
66
85
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Qti2xAttributeNameMapper, Qti2xElementNameMapper, Qti3AttributeNameMapper, Qti3ElementNameMapper, detectQtiVersion, } from '@pie-qti/qti-common';
|
|
2
1
|
import { resolveCheckedPackagePathFromFile } from '@pie-qti/ims-cp-core';
|
|
3
2
|
import { createExtractionRegistry, registerFrameworkDeliveryFields, } from '../extraction/ExtractionRegistry.js';
|
|
4
3
|
import { getStandardInteractionModules } from '../interactions/modules.js';
|
|
4
|
+
import { frozenSnapshot } from '../utils/cloneFreeze.js';
|
|
5
|
+
import { resolveNameMappers } from './nameMappers.js';
|
|
5
6
|
import { createComponentRegistry } from './ComponentRegistry.js';
|
|
6
7
|
import { preparePlayerDefinitionInternal } from './Player.js';
|
|
7
8
|
import { LiveItemSession, } from './ItemSession.js';
|
|
@@ -26,6 +27,7 @@ class CompiledAssessmentItemDefinition {
|
|
|
26
27
|
}, plugins);
|
|
27
28
|
this.prepared = preparePlayerDefinitionInternal({ ...config });
|
|
28
29
|
this.identifier = readPreparedIdentifier(this.prepared);
|
|
30
|
+
this.diagnostics = readPreparedDiagnostics(this.prepared);
|
|
29
31
|
this.playerConfig = config;
|
|
30
32
|
Object.freeze(this);
|
|
31
33
|
}
|
|
@@ -47,19 +49,9 @@ function readPreparedIdentifier(prepared) {
|
|
|
47
49
|
}
|
|
48
50
|
return prepared.identifier;
|
|
49
51
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
elementNameMapper: config.elementNameMapper,
|
|
54
|
-
attributeNameMapper: config.attributeNameMapper,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const qti3 = detectQtiVersion(config.itemXml ?? '') === '3.0';
|
|
58
|
-
return {
|
|
59
|
-
elementNameMapper: config.elementNameMapper ?? (qti3 ? new Qti3ElementNameMapper() : new Qti2xElementNameMapper()),
|
|
60
|
-
attributeNameMapper: config.attributeNameMapper ??
|
|
61
|
-
(qti3 ? new Qti3AttributeNameMapper() : new Qti2xAttributeNameMapper()),
|
|
62
|
-
};
|
|
52
|
+
function readPreparedDiagnostics(prepared) {
|
|
53
|
+
const diagnostics = prepared && typeof prepared === 'object' && 'diagnostics' in prepared ? prepared.diagnostics : undefined;
|
|
54
|
+
return Array.isArray(diagnostics) ? diagnostics : Object.freeze([]);
|
|
63
55
|
}
|
|
64
56
|
function snapshotDefinitionConfig(input) {
|
|
65
57
|
const { plugins, rngFactory, ...baseConfig } = input;
|
|
@@ -75,10 +67,13 @@ function snapshotDefinitionConfig(input) {
|
|
|
75
67
|
...(input.customOperators
|
|
76
68
|
? { customOperators: Object.freeze({ ...input.customOperators }) }
|
|
77
69
|
: {}),
|
|
78
|
-
...(input.
|
|
79
|
-
|
|
70
|
+
...(input.stringComparison
|
|
71
|
+
? { stringComparison: Object.freeze({ ...input.stringComparison }) }
|
|
72
|
+
: {}),
|
|
73
|
+
...(input.security ? { security: frozenSnapshot(input.security) } : {}),
|
|
74
|
+
...(input.pnp ? { pnp: frozenSnapshot(input.pnp) } : {}),
|
|
80
75
|
...(input.deliveryContext
|
|
81
|
-
? { deliveryContext:
|
|
76
|
+
? { deliveryContext: frozenSnapshot(input.deliveryContext) }
|
|
82
77
|
: {}),
|
|
83
78
|
};
|
|
84
79
|
if (!config.resolveProcessingFragment && config.deliveryContext) {
|
|
@@ -167,18 +162,4 @@ function createSessionPlayerConfig(config, rngFactory) {
|
|
|
167
162
|
// and its sealed extension registries remain shared and immutable.
|
|
168
163
|
};
|
|
169
164
|
}
|
|
170
|
-
function freezePlainSnapshot(value) {
|
|
171
|
-
if (Array.isArray(value)) {
|
|
172
|
-
return Object.freeze(value.map((entry) => freezePlainSnapshot(entry)));
|
|
173
|
-
}
|
|
174
|
-
if (!value || typeof value !== 'object')
|
|
175
|
-
return value;
|
|
176
|
-
if (Object.getPrototypeOf(value) !== Object.prototype)
|
|
177
|
-
return value;
|
|
178
|
-
const snapshot = Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
179
|
-
key,
|
|
180
|
-
freezePlainSnapshot(entry),
|
|
181
|
-
]));
|
|
182
|
-
return Object.freeze(snapshot);
|
|
183
|
-
}
|
|
184
165
|
//# sourceMappingURL=AssessmentItemDefinition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssessmentItemDefinition.js","sourceRoot":"","sources":["../../src/core/AssessmentItemDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EACN,wBAAwB,EACxB,+BAA+B,GAE/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAS3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EACN,eAAe,GAGf,MAAM,kBAAkB,CAAC;AA8D1B;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC7C,KAAqC;IAErC,OAAO,IAAI,gCAAgC,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,gCAAgC;IAMrC,YAAY,KAAqC;QAChD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACxE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QAEnC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,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,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAClC,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QACtE,GAAG;QACH,mBAAmB,CAAC,KAAK,CAAC;KAC1B,CAAC,CACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAM,CAAC;AACrC,CAAC","sourcesContent":["import {\n\ttype AttributeNameMapper,\n\ttype ElementNameMapper,\n\tQti2xAttributeNameMapper,\n\tQti2xElementNameMapper,\n\tQti3AttributeNameMapper,\n\tQti3ElementNameMapper,\n\tdetectQtiVersion,\n} from '@pie-qti/qti-common';\nimport type { I18nProvider } from '@pie-qti/i18n';\nimport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport { resolveCheckedPackagePathFromFile } from '@pie-qti/ims-cp-core';\nimport type { ProcessingFragmentResolver, QtiValue } from '@pie-qti/qti-processing';\nimport {\n\tcreateExtractionRegistry,\n\tregisterFrameworkDeliveryFields,\n\ttype ExtractionRegistry,\n} from '../extraction/ExtractionRegistry.js';\nimport { getStandardInteractionModules } from '../interactions/modules.js';\nimport type { PciConfiguration } from '../pci/types.js';\nimport type { PnpProfile } from '../pnp/types.js';\nimport type {\n\tItemSessionEngineConfig,\n\tPlayerSecurityConfig,\n\tQTIComplianceConfig,\n\tQTIRole,\n} from '../types/index.js';\nimport { createComponentRegistry } from './ComponentRegistry.js';\nimport type { ComponentRegistry } from './ComponentRegistry.js';\nimport { preparePlayerDefinitionInternal } from './Player.js';\nimport {\n\tLiveItemSession,\n\ttype ItemSession,\n\ttype OpenItemSessionOptions,\n} from './ItemSession.js';\n\n/**\n * Synchronous, definition-lifetime extension contract.\n *\n * Definition plugins describe immutable extraction and rendering extensions. Any\n * asynchronous setup must finish before definition construction.\n */\nexport interface AssessmentItemDefinitionPlugin {\n\treadonly kind: 'assessment-item-definition-plugin';\n\treadonly name: string;\n\treadonly version: string;\n\treadonly description?: string;\n\treadonly dependencies?: readonly string[];\n\tregisterExtractors?(registry: ExtractionRegistry): void;\n\tregisterComponents?(registry: ComponentRegistry): void;\n}\n\n/**\n * Configuration compiled into an immutable assessment-item definition.\n *\n * Mutable registry instances are deliberately not accepted here. Extensions are\n * described as plugins, applied once to definition-owned registries, then sealed\n * before those registries are shared by live sessions.\n */\nexport interface AssessmentItemDefinitionConfig {\n\treadonly itemXml: string;\n\treadonly pnp?: PnpProfile;\n\treadonly catalogXml?: string;\n\treadonly deliveryContext?: ResolvedItemDeliveryContext;\n\treadonly role?: QTIRole;\n\t/** Optional seed for deterministic template-processing random operations. */\n\treadonly seed?: number;\n\treadonly elementNameMapper?: ElementNameMapper;\n\treadonly attributeNameMapper?: AttributeNameMapper;\n\treadonly i18nProvider?: I18nProvider;\n\treadonly customOperators?: Readonly<\n\t\tRecord<\n\t\t\tstring,\n\t\t\t(args: QtiValue[], meta: { class?: string; definition?: string }) => QtiValue\n\t\t>\n\t>;\n\treadonly resolveProcessingFragment?: ProcessingFragmentResolver;\n\treadonly processingFragmentLimits?: Readonly<{\n\t\t/** Maximum nested xi:include depth. Default: 16. */\n\t\tmaxDepth?: number;\n\t\t/** Maximum cumulative XML characters. Default: 2 MiB. */\n\t\tmaxCharacters?: number;\n\t}>;\n\treadonly pci?: PciConfiguration;\n\treadonly security?: PlayerSecurityConfig;\n\treadonly strictQtiCompliance?: QTIComplianceConfig;\n\treadonly plugins?: readonly AssessmentItemDefinitionPlugin[];\n\t/** Creates an independent random stream for each opened live session. */\n\treadonly rngFactory?: () => () => number;\n}\n\nexport interface AssessmentItemDefinition {\n\treadonly identifier: string;\n\topenSession(options?: OpenItemSessionOptions): ItemSession;\n}\n\n/**\n * Compile QTI source and immutable delivery configuration into a reusable item definition.\n */\nexport function createAssessmentItemDefinition(\n\tinput: AssessmentItemDefinitionConfig\n): AssessmentItemDefinition {\n\treturn new CompiledAssessmentItemDefinition(input);\n}\n\nclass CompiledAssessmentItemDefinition implements AssessmentItemDefinition {\n\treadonly identifier: string;\n\tprivate readonly playerConfig: Readonly<ItemSessionEngineConfig>;\n\tprivate readonly prepared: unknown;\n\tprivate readonly rngFactory?: () => () => number;\n\n\tconstructor(input: AssessmentItemDefinitionConfig) {\n\t\tif (!input.itemXml.trim()) {\n\t\t\tthrow new Error('AssessmentItemDefinition requires non-empty itemXml');\n\t\t}\n\t\tthis.rngFactory = input.rngFactory;\n\n\t\tconst plugins = input.plugins ? Object.freeze([...input.plugins]) : Object.freeze([]);\n\t\tconst snapshot = snapshotDefinitionConfig(input);\n\t\tconst { elementNameMapper, attributeNameMapper } = resolveNameMappers(snapshot);\n\t\tconst config = compileDefinitionConfig(\n\t\t\tsnapshot,\n\t\t\t{\n\t\t\t\telementNameMapper,\n\t\t\t\tattributeNameMapper,\n\t\t\t},\n\t\t\tplugins,\n\t\t);\n\t\tthis.prepared = preparePlayerDefinitionInternal({ ...config });\n\t\tthis.identifier = readPreparedIdentifier(this.prepared);\n\t\tthis.playerConfig = config;\n\t\tObject.freeze(this);\n\t}\n\n\topenSession(options: OpenItemSessionOptions = {}): ItemSession {\n\t\tif (\n\t\t\toptions.restore?.itemIdentifier &&\n\t\t\tthis.identifier &&\n\t\t\toptions.restore.itemIdentifier !== this.identifier\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot restore item session for '${options.restore.itemIdentifier}' into '${this.identifier}'`\n\t\t\t);\n\t\t}\n\n\t\treturn new LiveItemSession(\n\t\t\tthis.identifier,\n\t\t\tcreateSessionPlayerConfig(this.playerConfig, this.rngFactory),\n\t\t\toptions,\n\t\t\tthis.prepared,\n\t\t);\n\t}\n}\n\nfunction readPreparedIdentifier(prepared: unknown): string {\n\tif (\n\t\t!prepared ||\n\t\ttypeof prepared !== 'object' ||\n\t\t!('identifier' in prepared) ||\n\t\ttypeof prepared.identifier !== 'string'\n\t) {\n\t\tthrow new Error('AssessmentItemDefinition compilation did not produce an identifier');\n\t}\n\treturn prepared.identifier;\n}\n\nfunction resolveNameMappers(config: Readonly<ItemSessionEngineConfig>) {\n\tif (config.elementNameMapper && config.attributeNameMapper) {\n\t\treturn {\n\t\t\telementNameMapper: config.elementNameMapper,\n\t\t\tattributeNameMapper: config.attributeNameMapper,\n\t\t};\n\t}\n\n\tconst qti3 = detectQtiVersion(config.itemXml ?? '') === '3.0';\n\treturn {\n\t\telementNameMapper:\n\t\t\tconfig.elementNameMapper ?? (qti3 ? new Qti3ElementNameMapper() : new Qti2xElementNameMapper()),\n\t\tattributeNameMapper:\n\t\t\tconfig.attributeNameMapper ??\n\t\t\t(qti3 ? new Qti3AttributeNameMapper() : new Qti2xAttributeNameMapper()),\n\t};\n}\n\nfunction snapshotDefinitionConfig(input: AssessmentItemDefinitionConfig): Readonly<ItemSessionEngineConfig> {\n\tconst { plugins, rngFactory, ...baseConfig } = input;\n\tvoid plugins;\n\tvoid rngFactory;\n\tconst config: ItemSessionEngineConfig = {\n\t\t...baseConfig,\n\t\titemXml: input.itemXml,\n\t\t...(input.processingFragmentLimits\n\t\t\t? { processingFragmentLimits: Object.freeze({ ...input.processingFragmentLimits }) }\n\t\t\t: {}),\n\t\t...(input.pci ? { pci: Object.freeze({ ...input.pci }) } : {}),\n\t\t...(input.customOperators\n\t\t\t? { customOperators: Object.freeze({ ...input.customOperators }) }\n\t\t\t: {}),\n\t\t...(input.security ? { security: freezePlainSnapshot(input.security) } : {}),\n\t\t...(input.pnp ? { pnp: freezePlainSnapshot(input.pnp) } : {}),\n\t\t...(input.deliveryContext\n\t\t\t? { deliveryContext: freezePlainSnapshot(input.deliveryContext) }\n\t\t\t: {}),\n\t};\n\tif (!config.resolveProcessingFragment && config.deliveryContext) {\n\t\tconst derived = createPackageFragmentResolver(config.deliveryContext);\n\t\tif (derived) config.resolveProcessingFragment = derived;\n\t}\n\treturn Object.freeze(config);\n}\n\n/**\n * Builds a synchronous, package-contained processing fragment resolver from the\n * preloaded fragment texts of an item delivery context. The resolver resolves each\n * authored href against the item's package path; because include resolution is\n * depth-first and synchronous, it also tracks the resolved path per nesting level so\n * includes authored inside a fragment resolve relative to that fragment.\n */\nfunction createPackageFragmentResolver(\n\tdeliveryContext: Readonly<ResolvedItemDeliveryContext>,\n): ProcessingFragmentResolver | undefined {\n\tconst fragments = deliveryContext.processingFragments;\n\tif (!fragments || Object.keys(fragments).length === 0) return undefined;\n\tconst itemHref = deliveryContext.itemHref ?? '';\n\tconst baseByDepth: string[] = [itemHref];\n\treturn (request) => {\n\t\t// Drop stale deeper levels so fallback content resolves against the item again.\n\t\tbaseByDepth.length = request.depth + 1;\n\t\tconst base = baseByDepth[request.depth] ?? itemHref;\n\t\tconst path = base ? resolveCheckedPackagePathFromFile(base, request.href) : null;\n\t\tif (path !== null && fragments[path] !== undefined) {\n\t\t\tbaseByDepth[request.depth + 1] = path;\n\t\t\treturn fragments[path];\n\t\t}\n\t\tif (fragments[request.href] !== undefined) {\n\t\t\tbaseByDepth[request.depth + 1] = request.href;\n\t\t\treturn fragments[request.href];\n\t\t}\n\t\treturn null;\n\t};\n}\n\nfunction compileDefinitionConfig(\n\tconfig: Readonly<ItemSessionEngineConfig>,\n\tmappers: ReturnType<typeof resolveNameMappers>,\n\tplugins: readonly AssessmentItemDefinitionPlugin[],\n): Readonly<ItemSessionEngineConfig> {\n\tconst extractionRegistry = createExtractionRegistry(mappers.elementNameMapper);\n\tfor (const module of getStandardInteractionModules()) {\n\t\textractionRegistry.register(module.extractor);\n\t\tregisterFrameworkDeliveryFields(extractionRegistry, module.type, module.delivery);\n\t}\n\tconst componentRegistry = createComponentRegistry();\n\n\tconst registeredPluginNames = new Set<string>();\n\tfor (const plugin of plugins) {\n\t\tvalidateDefinitionPlugin(plugin, registeredPluginNames);\n\t\tplugin.registerExtractors?.(extractionRegistry);\n\t\tplugin.registerComponents?.(componentRegistry);\n\t\tregisteredPluginNames.add(plugin.name);\n\t}\n\n\textractionRegistry.seal();\n\tcomponentRegistry.seal();\n\treturn Object.freeze({\n\t\t...config,\n\t\telementNameMapper: mappers.elementNameMapper,\n\t\tattributeNameMapper: mappers.attributeNameMapper,\n\t\textractionRegistry,\n\t\tcomponentRegistry,\n\t});\n}\n\nfunction validateDefinitionPlugin(\n\tplugin: AssessmentItemDefinitionPlugin,\n\tregisteredPluginNames: ReadonlySet<string>,\n): void {\n\tif (plugin.kind !== 'assessment-item-definition-plugin') {\n\t\tthrow new Error(\n\t\t\t`Definition plugin '${plugin.name || '<unnamed>'}' must declare kind 'assessment-item-definition-plugin'`,\n\t\t);\n\t}\n\tif (!plugin.name || typeof plugin.name !== 'string') {\n\t\tthrow new Error('AssessmentItemDefinition plugin must have a valid name');\n\t}\n\tif (!/^\\d+\\.\\d+\\.\\d+/.test(plugin.version)) {\n\t\tthrow new Error(\n\t\t\t`Definition plugin '${plugin.name}' has invalid version format: ${plugin.version}`,\n\t\t);\n\t}\n\tif (registeredPluginNames.has(plugin.name)) {\n\t\tthrow new Error(`Definition plugin '${plugin.name}' is registered more than once`);\n\t}\n\tconst missing = (plugin.dependencies ?? []).filter(\n\t\t(dependency) => !registeredPluginNames.has(dependency),\n\t);\n\tif (missing.length > 0) {\n\t\tthrow new Error(\n\t\t\t`Definition plugin '${plugin.name}' has missing dependencies: ${missing.join(', ')}`,\n\t\t);\n\t}\n}\n\nfunction createSessionPlayerConfig(\n\tconfig: Readonly<ItemSessionEngineConfig>,\n\trngFactory?: () => () => number,\n): ItemSessionEngineConfig {\n\treturn {\n\t\t...config,\n\t\t...(rngFactory ? { rng: rngFactory() } : {}),\n\t\t// Give each session a private top-level object while the compiled definition\n\t\t// and its sealed extension registries remain shared and immutable.\n\t};\n}\n\nfunction freezePlainSnapshot<T>(value: T): T {\n\tif (Array.isArray(value)) {\n\t\treturn Object.freeze(value.map((entry) => freezePlainSnapshot(entry))) as T;\n\t}\n\tif (!value || typeof value !== 'object') return value;\n\tif (Object.getPrototypeOf(value) !== Object.prototype) return value;\n\n\tconst snapshot = Object.fromEntries(\n\t\tObject.entries(value as Record<string, unknown>).map(([key, entry]) => [\n\t\t\tkey,\n\t\t\tfreezePlainSnapshot(entry),\n\t\t])\n\t);\n\treturn Object.freeze(snapshot) as T;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AssessmentItemDefinition.js","sourceRoot":"","sources":["../../src/core/AssessmentItemDefinition.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EACN,wBAAwB,EACxB,+BAA+B,GAE/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAG3E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EACN,eAAe,GAGf,MAAM,kBAAkB,CAAC;AAgF1B;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC7C,KAAqC;IAErC,OAAO,IAAI,gCAAgC,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,gCAAgC;IAOrC,YAAY,KAAqC;QAChD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACxE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QAEnC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACtF,MAAM,QAAQ,GAAG,wBAAwB,CAAC,KAAK,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AAI,gCAAgC,CAAC,CAAC;IACpF,CAAC;IACD,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,MAAM,CACjD,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAC,CACtD,CAAC;IACF,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACd,sBAAsB,MAAM,CAAC,IAAI,+BAA+B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACpF,CAAC;IACH,CAAC;AACF,CAAC;AAED,SAAS,yBAAyB,CACjC,MAAyC,EACzC,UAA+B;IAE/B,OAAO;QACN,GAAG,MAAM;QACT,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,6EAA6E;QAC7E,mEAAmE;KACnE,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype AttributeNameMapper,\n\ttype ElementNameMapper,\n} from '@pie-qti/qti-common';\nimport type { I18nProvider } from '@pie-qti/i18n';\nimport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport { resolveCheckedPackagePathFromFile } from '@pie-qti/ims-cp-core';\nimport type { ProcessingFragmentResolver, QtiValue, StringComparisonOptions } from '@pie-qti/qti-processing';\nimport {\n\tcreateExtractionRegistry,\n\tregisterFrameworkDeliveryFields,\n\ttype ExtractionRegistry,\n} from '../extraction/ExtractionRegistry.js';\nimport { getStandardInteractionModules } from '../interactions/modules.js';\nimport type { PciConfiguration } from '../pci/types.js';\nimport type { PnpProfile } from '../pnp/types.js';\nimport { frozenSnapshot } from '../utils/cloneFreeze.js';\nimport { resolveNameMappers } from './nameMappers.js';\nimport type {\n\tItemSessionEngineConfig,\n\tPlayerSecurityConfig,\n\tQTIComplianceConfig,\n\tQTIRole,\n} from '../types/index.js';\nimport { createComponentRegistry } from './ComponentRegistry.js';\nimport type { ComponentRegistry } from './ComponentRegistry.js';\nimport type { QtiItemDiagnostic } from './compliance.js';\nimport { preparePlayerDefinitionInternal } from './Player.js';\nimport {\n\tLiveItemSession,\n\ttype ItemSession,\n\ttype OpenItemSessionOptions,\n} from './ItemSession.js';\n\n/**\n * Synchronous, definition-lifetime extension contract.\n *\n * Definition plugins describe immutable extraction and rendering extensions. Any\n * asynchronous setup must finish before definition construction.\n */\nexport interface AssessmentItemDefinitionPlugin {\n\treadonly kind: 'assessment-item-definition-plugin';\n\treadonly name: string;\n\treadonly version: string;\n\treadonly description?: string;\n\treadonly dependencies?: readonly string[];\n\tregisterExtractors?(registry: ExtractionRegistry): void;\n\tregisterComponents?(registry: ComponentRegistry): void;\n}\n\n/**\n * Configuration compiled into an immutable assessment-item definition.\n *\n * Mutable registry instances are deliberately not accepted here. Extensions are\n * described as plugins, applied once to definition-owned registries, then sealed\n * before those registries are shared by live sessions.\n */\nexport interface AssessmentItemDefinitionConfig {\n\treadonly itemXml: string;\n\treadonly pnp?: PnpProfile;\n\treadonly catalogXml?: string;\n\treadonly deliveryContext?: ResolvedItemDeliveryContext;\n\treadonly role?: QTIRole;\n\t/** Optional seed for deterministic template-processing random operations. */\n\treadonly seed?: number;\n\treadonly elementNameMapper?: ElementNameMapper;\n\treadonly attributeNameMapper?: AttributeNameMapper;\n\treadonly i18nProvider?: I18nProvider;\n\treadonly customOperators?: Readonly<\n\t\tRecord<\n\t\t\tstring,\n\t\t\t(args: QtiValue[], meta: { class?: string; definition?: string }) => QtiValue\n\t\t>\n\t>;\n\t/**\n\t * How response processing compares `string` values, for the input the host's candidates use.\n\t * By default it compares as QTI defines (`match` is true when the values are \"the same value\",\n\t * QTI 3.0 §6.9.21): exactly, up to Unicode canonical equivalence, with case folded only where\n\t * the item asks for it (`stringMatch` and `mapEntry` caseSensitive false). Set\n\t * `foldScriptInput` for input methods that add bidi marks, tatweel or presentation forms to\n\t * right-to-left text, or to accept other scripts' digits in string answers; set\n\t * `foldLetterVariants` to also accept Arabic spelling variants. Numbers typed into integer and\n\t * float responses read digits in any script either way.\n\t */\n\treadonly stringComparison?: Readonly<StringComparisonOptions>;\n\treadonly resolveProcessingFragment?: ProcessingFragmentResolver;\n\treadonly processingFragmentLimits?: Readonly<{\n\t\t/** Maximum nested xi:include depth. Default: 16. */\n\t\tmaxDepth?: number;\n\t\t/** Maximum cumulative XML characters. Default: 2 MiB. */\n\t\tmaxCharacters?: number;\n\t}>;\n\treadonly pci?: PciConfiguration;\n\treadonly security?: PlayerSecurityConfig;\n\treadonly strictQtiCompliance?: QTIComplianceConfig;\n\treadonly plugins?: readonly AssessmentItemDefinitionPlugin[];\n\t/** Creates an independent random stream for each opened live session. */\n\treadonly rngFactory?: () => () => number;\n}\n\nexport interface AssessmentItemDefinition {\n\treadonly identifier: string;\n\t/**\n\t * QTI compliance findings from compiling the item: version assumptions, element names outside\n\t * the item's QTI vocabulary, interactions bound to no response declaration, and interactions no\n\t * registered extractor renders. Errors under `strictQtiCompliance.enabled`, warnings otherwise;\n\t * empty when the item compiled cleanly. See `QTIComplianceConfig`.\n\t */\n\treadonly diagnostics: readonly QtiItemDiagnostic[];\n\topenSession(options?: OpenItemSessionOptions): ItemSession;\n}\n\n/**\n * Compile QTI source and immutable delivery configuration into a reusable item definition.\n */\nexport function createAssessmentItemDefinition(\n\tinput: AssessmentItemDefinitionConfig\n): AssessmentItemDefinition {\n\treturn new CompiledAssessmentItemDefinition(input);\n}\n\nclass CompiledAssessmentItemDefinition implements AssessmentItemDefinition {\n\treadonly identifier: string;\n\treadonly diagnostics: readonly QtiItemDiagnostic[];\n\tprivate readonly playerConfig: Readonly<ItemSessionEngineConfig>;\n\tprivate readonly prepared: unknown;\n\tprivate readonly rngFactory?: () => () => number;\n\n\tconstructor(input: AssessmentItemDefinitionConfig) {\n\t\tif (!input.itemXml.trim()) {\n\t\t\tthrow new Error('AssessmentItemDefinition requires non-empty itemXml');\n\t\t}\n\t\tthis.rngFactory = input.rngFactory;\n\n\t\tconst plugins = input.plugins ? Object.freeze([...input.plugins]) : Object.freeze([]);\n\t\tconst snapshot = snapshotDefinitionConfig(input);\n\t\tconst { elementNameMapper, attributeNameMapper } = resolveNameMappers(snapshot);\n\t\tconst config = compileDefinitionConfig(\n\t\t\tsnapshot,\n\t\t\t{\n\t\t\t\telementNameMapper,\n\t\t\t\tattributeNameMapper,\n\t\t\t},\n\t\t\tplugins,\n\t\t);\n\t\tthis.prepared = preparePlayerDefinitionInternal({ ...config });\n\t\tthis.identifier = readPreparedIdentifier(this.prepared);\n\t\tthis.diagnostics = readPreparedDiagnostics(this.prepared);\n\t\tthis.playerConfig = config;\n\t\tObject.freeze(this);\n\t}\n\n\topenSession(options: OpenItemSessionOptions = {}): ItemSession {\n\t\tif (\n\t\t\toptions.restore?.itemIdentifier &&\n\t\t\tthis.identifier &&\n\t\t\toptions.restore.itemIdentifier !== this.identifier\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot restore item session for '${options.restore.itemIdentifier}' into '${this.identifier}'`\n\t\t\t);\n\t\t}\n\n\t\treturn new LiveItemSession(\n\t\t\tthis.identifier,\n\t\t\tcreateSessionPlayerConfig(this.playerConfig, this.rngFactory),\n\t\t\toptions,\n\t\t\tthis.prepared,\n\t\t);\n\t}\n}\n\nfunction readPreparedIdentifier(prepared: unknown): string {\n\tif (\n\t\t!prepared ||\n\t\ttypeof prepared !== 'object' ||\n\t\t!('identifier' in prepared) ||\n\t\ttypeof prepared.identifier !== 'string'\n\t) {\n\t\tthrow new Error('AssessmentItemDefinition compilation did not produce an identifier');\n\t}\n\treturn prepared.identifier;\n}\n\nfunction readPreparedDiagnostics(prepared: unknown): readonly QtiItemDiagnostic[] {\n\tconst diagnostics =\n\t\tprepared && typeof prepared === 'object' && 'diagnostics' in prepared ? prepared.diagnostics : undefined;\n\treturn Array.isArray(diagnostics) ? (diagnostics as readonly QtiItemDiagnostic[]) : Object.freeze([]);\n}\n\nfunction snapshotDefinitionConfig(input: AssessmentItemDefinitionConfig): Readonly<ItemSessionEngineConfig> {\n\tconst { plugins, rngFactory, ...baseConfig } = input;\n\tvoid plugins;\n\tvoid rngFactory;\n\tconst config: ItemSessionEngineConfig = {\n\t\t...baseConfig,\n\t\titemXml: input.itemXml,\n\t\t...(input.processingFragmentLimits\n\t\t\t? { processingFragmentLimits: Object.freeze({ ...input.processingFragmentLimits }) }\n\t\t\t: {}),\n\t\t...(input.pci ? { pci: Object.freeze({ ...input.pci }) } : {}),\n\t\t...(input.customOperators\n\t\t\t? { customOperators: Object.freeze({ ...input.customOperators }) }\n\t\t\t: {}),\n\t\t...(input.stringComparison\n\t\t\t? { stringComparison: Object.freeze({ ...input.stringComparison }) }\n\t\t\t: {}),\n\t\t...(input.security ? { security: frozenSnapshot(input.security) } : {}),\n\t\t...(input.pnp ? { pnp: frozenSnapshot(input.pnp) } : {}),\n\t\t...(input.deliveryContext\n\t\t\t? { deliveryContext: frozenSnapshot(input.deliveryContext) }\n\t\t\t: {}),\n\t};\n\tif (!config.resolveProcessingFragment && config.deliveryContext) {\n\t\tconst derived = createPackageFragmentResolver(config.deliveryContext);\n\t\tif (derived) config.resolveProcessingFragment = derived;\n\t}\n\treturn Object.freeze(config);\n}\n\n/**\n * Builds a synchronous, package-contained processing fragment resolver from the\n * preloaded fragment texts of an item delivery context. The resolver resolves each\n * authored href against the item's package path; because include resolution is\n * depth-first and synchronous, it also tracks the resolved path per nesting level so\n * includes authored inside a fragment resolve relative to that fragment.\n */\nfunction createPackageFragmentResolver(\n\tdeliveryContext: Readonly<ResolvedItemDeliveryContext>,\n): ProcessingFragmentResolver | undefined {\n\tconst fragments = deliveryContext.processingFragments;\n\tif (!fragments || Object.keys(fragments).length === 0) return undefined;\n\tconst itemHref = deliveryContext.itemHref ?? '';\n\tconst baseByDepth: string[] = [itemHref];\n\treturn (request) => {\n\t\t// Drop stale deeper levels so fallback content resolves against the item again.\n\t\tbaseByDepth.length = request.depth + 1;\n\t\tconst base = baseByDepth[request.depth] ?? itemHref;\n\t\tconst path = base ? resolveCheckedPackagePathFromFile(base, request.href) : null;\n\t\tif (path !== null && fragments[path] !== undefined) {\n\t\t\tbaseByDepth[request.depth + 1] = path;\n\t\t\treturn fragments[path];\n\t\t}\n\t\tif (fragments[request.href] !== undefined) {\n\t\t\tbaseByDepth[request.depth + 1] = request.href;\n\t\t\treturn fragments[request.href];\n\t\t}\n\t\treturn null;\n\t};\n}\n\nfunction compileDefinitionConfig(\n\tconfig: Readonly<ItemSessionEngineConfig>,\n\tmappers: ReturnType<typeof resolveNameMappers>,\n\tplugins: readonly AssessmentItemDefinitionPlugin[],\n): Readonly<ItemSessionEngineConfig> {\n\tconst extractionRegistry = createExtractionRegistry(mappers.elementNameMapper);\n\tfor (const module of getStandardInteractionModules()) {\n\t\textractionRegistry.register(module.extractor);\n\t\tregisterFrameworkDeliveryFields(extractionRegistry, module.type, module.delivery);\n\t}\n\tconst componentRegistry = createComponentRegistry();\n\n\tconst registeredPluginNames = new Set<string>();\n\tfor (const plugin of plugins) {\n\t\tvalidateDefinitionPlugin(plugin, registeredPluginNames);\n\t\tplugin.registerExtractors?.(extractionRegistry);\n\t\tplugin.registerComponents?.(componentRegistry);\n\t\tregisteredPluginNames.add(plugin.name);\n\t}\n\n\textractionRegistry.seal();\n\tcomponentRegistry.seal();\n\treturn Object.freeze({\n\t\t...config,\n\t\telementNameMapper: mappers.elementNameMapper,\n\t\tattributeNameMapper: mappers.attributeNameMapper,\n\t\textractionRegistry,\n\t\tcomponentRegistry,\n\t});\n}\n\nfunction validateDefinitionPlugin(\n\tplugin: AssessmentItemDefinitionPlugin,\n\tregisteredPluginNames: ReadonlySet<string>,\n): void {\n\tif (plugin.kind !== 'assessment-item-definition-plugin') {\n\t\tthrow new Error(\n\t\t\t`Definition plugin '${plugin.name || '<unnamed>'}' must declare kind 'assessment-item-definition-plugin'`,\n\t\t);\n\t}\n\tif (!plugin.name || typeof plugin.name !== 'string') {\n\t\tthrow new Error('AssessmentItemDefinition plugin must have a valid name');\n\t}\n\tif (!/^\\d+\\.\\d+\\.\\d+/.test(plugin.version)) {\n\t\tthrow new Error(\n\t\t\t`Definition plugin '${plugin.name}' has invalid version format: ${plugin.version}`,\n\t\t);\n\t}\n\tif (registeredPluginNames.has(plugin.name)) {\n\t\tthrow new Error(`Definition plugin '${plugin.name}' is registered more than once`);\n\t}\n\tconst missing = (plugin.dependencies ?? []).filter(\n\t\t(dependency) => !registeredPluginNames.has(dependency),\n\t);\n\tif (missing.length > 0) {\n\t\tthrow new Error(\n\t\t\t`Definition plugin '${plugin.name}' has missing dependencies: ${missing.join(', ')}`,\n\t\t);\n\t}\n}\n\nfunction createSessionPlayerConfig(\n\tconfig: Readonly<ItemSessionEngineConfig>,\n\trngFactory?: () => () => number,\n): ItemSessionEngineConfig {\n\treturn {\n\t\t...config,\n\t\t...(rngFactory ? { rng: rngFactory() } : {}),\n\t\t// Give each session a private top-level object while the compiled definition\n\t\t// and its sealed extension registries remain shared and immutable.\n\t};\n}\n"]}
|