@pie-qti/item-player 0.1.27 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +35 -6
  2. package/dist/catalog/applyGlossaryTriggers.js +8 -2
  3. package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
  4. package/dist/catalog/catalogExtractor.js +44 -7
  5. package/dist/catalog/catalogExtractor.js.map +1 -1
  6. package/dist/catalog/catalogLookup.d.ts +8 -0
  7. package/dist/catalog/catalogLookup.js +17 -0
  8. package/dist/catalog/catalogLookup.js.map +1 -1
  9. package/dist/catalog/types.d.ts +3 -3
  10. package/dist/catalog/types.js.map +1 -1
  11. package/dist/components/utils/feedbackUtils.d.ts +9 -4
  12. package/dist/components/utils/feedbackUtils.js +67 -34
  13. package/dist/components/utils/feedbackUtils.js.map +1 -1
  14. package/dist/core/AssessmentItemDefinition.js +35 -0
  15. package/dist/core/AssessmentItemDefinition.js.map +1 -1
  16. package/dist/core/ItemSession.d.ts +19 -1
  17. package/dist/core/ItemSession.js +12 -2
  18. package/dist/core/ItemSession.js.map +1 -1
  19. package/dist/core/Player.d.ts +41 -1
  20. package/dist/core/Player.js +216 -48
  21. package/dist/core/Player.js.map +1 -1
  22. package/dist/core/sanitizer.js +16 -3
  23. package/dist/core/sanitizer.js.map +1 -1
  24. package/dist/document/AssessmentItemDocument.d.ts +12 -5
  25. package/dist/document/AssessmentItemDocument.js +28 -19
  26. package/dist/document/AssessmentItemDocument.js.map +1 -1
  27. package/dist/document/contentPass.d.ts +17 -0
  28. package/dist/document/contentPass.js +40 -0
  29. package/dist/document/contentPass.js.map +1 -0
  30. package/dist/document/printedVariable.d.ts +35 -0
  31. package/dist/document/printedVariable.js +215 -0
  32. package/dist/document/printedVariable.js.map +1 -0
  33. package/dist/{element-class-BzATCyhV.js → element-class-D-kJi_w9.js} +3211 -2125
  34. package/dist/element-class-D-kJi_w9.js.map +1 -0
  35. package/dist/element-class.js +1 -1
  36. package/dist/element.js +1 -1
  37. package/dist/extraction/interactionAccessibility.d.ts +14 -0
  38. package/dist/extraction/interactionAccessibility.js +58 -0
  39. package/dist/extraction/interactionAccessibility.js.map +1 -0
  40. package/dist/extraction/interactionExtractionPipeline.d.ts +4 -1
  41. package/dist/extraction/interactionExtractionPipeline.js +7 -2
  42. package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
  43. package/dist/extraction/utils.js +20 -1
  44. package/dist/extraction/utils.js.map +1 -1
  45. package/dist/index.d.ts +9 -3
  46. package/dist/index.js +4 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/interactions/order/extractor.js +2 -0
  49. package/dist/interactions/order/extractor.js.map +1 -1
  50. package/dist/interactions/portable-custom/extractor.js +47 -11
  51. package/dist/interactions/portable-custom/extractor.js.map +1 -1
  52. package/dist/interactions/shared/types.d.ts +16 -0
  53. package/dist/interactions/shared/types.js.map +1 -1
  54. package/dist/pci/PciHost.d.ts +85 -43
  55. package/dist/pci/PciHost.js +229 -148
  56. package/dist/pci/PciHost.js.map +1 -1
  57. package/dist/pci/allowlistResolver.d.ts +10 -1
  58. package/dist/pci/allowlistResolver.js +43 -4
  59. package/dist/pci/allowlistResolver.js.map +1 -1
  60. package/dist/pci/amdLoader.d.ts +23 -0
  61. package/dist/pci/amdLoader.js +190 -0
  62. package/dist/pci/amdLoader.js.map +1 -0
  63. package/dist/pci/index.d.ts +14 -3
  64. package/dist/pci/index.js +8 -1
  65. package/dist/pci/index.js.map +1 -1
  66. package/dist/pci/moduleSession.d.ts +41 -0
  67. package/dist/pci/moduleSession.js +2 -0
  68. package/dist/pci/moduleSession.js.map +1 -0
  69. package/dist/pci/pageRealmSession.d.ts +49 -0
  70. package/dist/pci/pageRealmSession.js +193 -0
  71. package/dist/pci/pageRealmSession.js.map +1 -0
  72. package/dist/pci/qtiVariableJson.d.ts +7 -0
  73. package/dist/pci/qtiVariableJson.js +93 -0
  74. package/dist/pci/qtiVariableJson.js.map +1 -0
  75. package/dist/pci/registry.d.ts +15 -0
  76. package/dist/pci/registry.js +77 -0
  77. package/dist/pci/registry.js.map +1 -0
  78. package/dist/pci/resolutionConfig.d.ts +23 -0
  79. package/dist/pci/resolutionConfig.js +63 -0
  80. package/dist/pci/resolutionConfig.js.map +1 -0
  81. package/dist/pci/sandbox/SandboxedPciSession.d.ts +78 -0
  82. package/dist/pci/sandbox/SandboxedPciSession.js +332 -0
  83. package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -0
  84. package/dist/pci/sandbox/iframeConnector.d.ts +13 -0
  85. package/dist/pci/sandbox/iframeConnector.js +94 -0
  86. package/dist/pci/sandbox/iframeConnector.js.map +1 -0
  87. package/dist/pci/sandbox/protocol.d.ts +117 -0
  88. package/dist/pci/sandbox/protocol.js +49 -0
  89. package/dist/pci/sandbox/protocol.js.map +1 -0
  90. package/dist/pci/types.d.ts +213 -30
  91. package/dist/pci/types.js +8 -1
  92. package/dist/pci/types.js.map +1 -1
  93. package/dist/pnp/applyPnp.d.ts +3 -4
  94. package/dist/pnp/applyPnp.js +54 -8
  95. package/dist/pnp/applyPnp.js.map +1 -1
  96. package/dist/pnp/parsePnpXml.d.ts +2 -2
  97. package/dist/pnp/parsePnpXml.js +146 -4
  98. package/dist/pnp/parsePnpXml.js.map +1 -1
  99. package/dist/pnp/types.d.ts +57 -0
  100. package/dist/pnp/types.js.map +1 -1
  101. package/dist/presentation/itemPresentationPlan.d.ts +12 -1
  102. package/dist/presentation/itemPresentationPlan.js +11 -3
  103. package/dist/presentation/itemPresentationPlan.js.map +1 -1
  104. package/dist/server.d.ts +5 -0
  105. package/dist/server.js.map +1 -1
  106. package/dist/types/index.d.ts +5 -0
  107. package/dist/types/index.js.map +1 -1
  108. package/package.json +6 -6
  109. package/dist/element-class-BzATCyhV.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import { t as e } from "./element-class-BzATCyhV.js";
1
+ import { t as e } from "./element-class-D-kJi_w9.js";
2
2
  export { e as PieQtiItemPlayerElement };
package/dist/element.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./element-class-BzATCyhV.js";
1
+ import { t as e } from "./element-class-D-kJi_w9.js";
2
2
  //#region src/element.ts
3
3
  var t = "pie-qti-item-player";
4
4
  globalThis.customElements && !customElements.get(t) && customElements.define(t, e);
@@ -0,0 +1,14 @@
1
+ import type { InteractionAccessibility, InteractionReadAloud, QTIElement } from '../interactions/shared/types.js';
2
+ /**
3
+ * The interaction's accessible name and description from its `aria-labelledby`, `aria-label`,
4
+ * `aria-describedby` and `aria-description`. Renderers draw interactions in shadow roots, which
5
+ * id references cannot cross, so referenced ids resolve to their text here, within `root`.
6
+ * `aria-labelledby` wins over `aria-label`, as in accessible name computation.
7
+ */
8
+ export declare function interactionAccessibility(element: QTIElement, root: QTIElement): InteractionAccessibility | undefined;
9
+ /**
10
+ * The read-aloud attributes on `element` itself. Markup preparation restates `xml:lang` as `lang`
11
+ * and `data-qti-suppress-tts` as `data-tts-suppress`; the extracted content of an interaction, prompt
12
+ * or choice carries its children only, so a renderer restates these on what it draws.
13
+ */
14
+ export declare function readAloudAttributes(element: QTIElement): InteractionReadAloud | undefined;
@@ -0,0 +1,58 @@
1
+ function normalizeText(text) {
2
+ return (text ?? '').replace(/\s+/g, ' ').trim();
3
+ }
4
+ function findById(root, id) {
5
+ for (const child of root.childNodes ?? []) {
6
+ if (child.nodeType !== 1)
7
+ continue;
8
+ const element = child;
9
+ if (element.getAttribute?.('id') === id)
10
+ return element;
11
+ const found = findById(element, id);
12
+ if (found)
13
+ return found;
14
+ }
15
+ return undefined;
16
+ }
17
+ function referencedText(ids, root) {
18
+ if (!ids)
19
+ return '';
20
+ return ids
21
+ .split(/\s+/)
22
+ .filter(Boolean)
23
+ .map((id) => normalizeText(findById(root, id)?.textContent))
24
+ .filter(Boolean)
25
+ .join(' ');
26
+ }
27
+ /**
28
+ * The interaction's accessible name and description from its `aria-labelledby`, `aria-label`,
29
+ * `aria-describedby` and `aria-description`. Renderers draw interactions in shadow roots, which
30
+ * id references cannot cross, so referenced ids resolve to their text here, within `root`.
31
+ * `aria-labelledby` wins over `aria-label`, as in accessible name computation.
32
+ */
33
+ export function interactionAccessibility(element, root) {
34
+ const label = referencedText(element.getAttribute('aria-labelledby'), root) ||
35
+ normalizeText(element.getAttribute('aria-label'));
36
+ const description = referencedText(element.getAttribute('aria-describedby'), root) ||
37
+ normalizeText(element.getAttribute('aria-description'));
38
+ if (!label && !description)
39
+ return undefined;
40
+ return { ...(label ? { label } : {}), ...(description ? { description } : {}) };
41
+ }
42
+ /** The authored attributes read-aloud resolves on content: its language, catalog idref and suppression. */
43
+ const READ_ALOUD_ATTRIBUTES = ['lang', 'data-catalog-idref', 'data-tts-suppress'];
44
+ /**
45
+ * The read-aloud attributes on `element` itself. Markup preparation restates `xml:lang` as `lang`
46
+ * and `data-qti-suppress-tts` as `data-tts-suppress`; the extracted content of an interaction, prompt
47
+ * or choice carries its children only, so a renderer restates these on what it draws.
48
+ */
49
+ export function readAloudAttributes(element) {
50
+ const attributes = {};
51
+ for (const name of READ_ALOUD_ATTRIBUTES) {
52
+ const value = element.getAttribute?.(name)?.trim();
53
+ if (value)
54
+ attributes[name] = value;
55
+ }
56
+ return Object.keys(attributes).length > 0 ? attributes : undefined;
57
+ }
58
+ //# sourceMappingURL=interactionAccessibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interactionAccessibility.js","sourceRoot":"","sources":["../../src/extraction/interactionAccessibility.ts"],"names":[],"mappings":"AAEA,SAAS,aAAa,CAAC,IAA+B;IACrD,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACjD,CAAC;AAED,SAAS,QAAQ,CAAC,IAAgB,EAAE,EAAU;IAC7C,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QAC3C,IAAI,KAAK,CAAC,QAAQ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AAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACjF,CAAC;AAED,2GAA2G;AAC3G,MAAM,qBAAqB,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,mBAAmB,CAAU,CAAC;AAE3F;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAmB;IACtD,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,KAAK,MAAM,IAAI,IAAI,qBAAqB,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;QACnD,IAAI,KAAK;YAAE,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACrC,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACpE,CAAC","sourcesContent":["import type { InteractionAccessibility, InteractionReadAloud, QTIElement } from '../interactions/shared/types.js';\n\nfunction normalizeText(text: string | null | undefined): string {\n\treturn (text ?? '').replace(/\\s+/g, ' ').trim();\n}\n\nfunction findById(root: QTIElement, id: string): QTIElement | undefined {\n\tfor (const child of root.childNodes ?? []) {\n\t\tif (child.nodeType !== 1) continue;\n\t\tconst element = child as unknown as QTIElement;\n\t\tif (element.getAttribute?.('id') === id) return element;\n\t\tconst found = findById(element, id);\n\t\tif (found) return found;\n\t}\n\treturn undefined;\n}\n\nfunction referencedText(ids: string | undefined, root: QTIElement): string {\n\tif (!ids) return '';\n\treturn ids\n\t\t.split(/\\s+/)\n\t\t.filter(Boolean)\n\t\t.map((id) => normalizeText(findById(root, id)?.textContent))\n\t\t.filter(Boolean)\n\t\t.join(' ');\n}\n\n/**\n * The interaction's accessible name and description from its `aria-labelledby`, `aria-label`,\n * `aria-describedby` and `aria-description`. Renderers draw interactions in shadow roots, which\n * id references cannot cross, so referenced ids resolve to their text here, within `root`.\n * `aria-labelledby` wins over `aria-label`, as in accessible name computation.\n */\nexport function interactionAccessibility(\n\telement: QTIElement,\n\troot: QTIElement,\n): InteractionAccessibility | undefined {\n\tconst label =\n\t\treferencedText(element.getAttribute('aria-labelledby'), root) ||\n\t\tnormalizeText(element.getAttribute('aria-label'));\n\tconst description =\n\t\treferencedText(element.getAttribute('aria-describedby'), root) ||\n\t\tnormalizeText(element.getAttribute('aria-description'));\n\tif (!label && !description) return undefined;\n\treturn { ...(label ? { label } : {}), ...(description ? { description } : {}) };\n}\n\n/** The authored attributes read-aloud resolves on content: its language, catalog idref and suppression. */\nconst READ_ALOUD_ATTRIBUTES = ['lang', 'data-catalog-idref', 'data-tts-suppress'] as const;\n\n/**\n * The read-aloud attributes on `element` itself. Markup preparation restates `xml:lang` as `lang`\n * and `data-qti-suppress-tts` as `data-tts-suppress`; the extracted content of an interaction, prompt\n * or choice carries its children only, so a renderer restates these on what it draws.\n */\nexport function readAloudAttributes(element: QTIElement): InteractionReadAloud | undefined {\n\tconst attributes: Record<string, string> = {};\n\tfor (const name of READ_ALOUD_ATTRIBUTES) {\n\t\tconst value = element.getAttribute?.(name)?.trim();\n\t\tif (value) attributes[name] = value;\n\t}\n\treturn Object.keys(attributes).length > 0 ? attributes : undefined;\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { AssessmentItemDocument } from '../document/AssessmentItemDocument.js';
2
+ import type { ContentHandlers } from '../document/contentPass.js';
2
3
  import type { ExtractionRegistry } from './ExtractionRegistry.js';
3
4
  import type { DeclarationMap } from '@pie-qti/qti-processing';
4
5
  import type { ExtractionConfig } from './types.js';
@@ -13,5 +14,7 @@ export interface InteractionExtractionPipelineInput {
13
14
  * Omit to keep the authored order.
14
15
  */
15
16
  sessionGuid?: string;
17
+ /** The content pass applied to the item body before interactions are extracted. */
18
+ contentHandlers?: ContentHandlers;
16
19
  }
17
- export declare function extractInteractionData({ document, extractionRegistry, declarations, config, sessionGuid, }: InteractionExtractionPipelineInput): readonly BaseInteractionData[];
20
+ export declare function extractInteractionData({ document, extractionRegistry, declarations, config, sessionGuid, contentHandlers, }: InteractionExtractionPipelineInput): readonly BaseInteractionData[];
@@ -1,8 +1,9 @@
1
1
  import { createExtractionContext } from './createContext.js';
2
+ import { interactionAccessibility, readAloudAttributes } from './interactionAccessibility.js';
2
3
  import { finalizeInteractionDelivery } from './interactionSecurity.js';
3
- export function extractInteractionData({ document, extractionRegistry, declarations, config, sessionGuid, }) {
4
+ export function extractInteractionData({ document, extractionRegistry, declarations, config, sessionGuid, contentHandlers, }) {
4
5
  const declMap = projectDeclarationsForExtraction(declarations);
5
- const elements = document.findExtractionElements(getRegisteredElementTypes(extractionRegistry));
6
+ const elements = document.findExtractionElements(getRegisteredElementTypes(extractionRegistry), contentHandlers);
6
7
  const interactions = [];
7
8
  for (const discovered of elements) {
8
9
  const context = createExtractionContext(discovered.element, discovered.responseIdentifier, discovered.contextRoot, declMap, config, sessionGuid);
@@ -11,8 +12,12 @@ export function extractInteractionData({ document, extractionRegistry, declarati
11
12
  throw result.error;
12
13
  const extractor = result.extractor;
13
14
  const outputType = extractor?.outputType ?? discovered.normalizedType;
15
+ const accessibility = interactionAccessibility(discovered.element, discovered.contextRoot);
16
+ const readAloud = readAloudAttributes(discovered.element);
14
17
  const interaction = {
15
18
  ...result.data,
19
+ ...(accessibility ? { accessibility } : {}),
20
+ ...(readAloud ? { readAloud } : {}),
16
21
  // These are framework-owned routing fields. Applying them after the
17
22
  // extractor payload prevents a plugin from redirecting a response or
18
23
  // selecting an undeclared renderer through payload properties.
@@ -1 +1 @@
1
- {"version":3,"file":"interactionExtractionPipeline.js","sourceRoot":"","sources":["../../src/extraction/interactionExtractionPipeline.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,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Q;SAC9B,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { AssessmentItemDocument } from '../document/AssessmentItemDocument.js';\nimport type { ExtractionRegistry } from './ExtractionRegistry.js';\nimport { createExtractionContext } from './createContext.js';\nimport { finalizeInteractionDelivery } from './interactionSecurity.js';\nimport type { VariableDeclaration as ExtractionVariableDeclaration } from './types.js';\nimport type { DeclarationMap } from '@pie-qti/qti-processing';\nimport type { ExtractionConfig } from './types.js';\nimport type {\n\tBaseInteractionData,\n\tDeliveredInteraction,\n} from '../interactions/shared/types.js';\n\nexport interface InteractionExtractionPipelineInput {\n\tdocument: AssessmentItemDocument;\n\textractionRegistry: ExtractionRegistry;\n\tdeclarations: DeclarationMap;\n\tconfig: ExtractionConfig;\n\t/**\n\t * Item session GUID, used to seed `shuffle` for the interactions that support it.\n\t * Omit to keep the authored order.\n\t */\n\tsessionGuid?: string;\n}\n\nexport function extractInteractionData({\n\tdocument,\n\textractionRegistry,\n\tdeclarations,\n\tconfig,\n\tsessionGuid,\n}: InteractionExtractionPipelineInput): readonly BaseInteractionData[] {\n\tconst declMap = projectDeclarationsForExtraction(declarations);\n\tconst elements = document.findExtractionElements(getRegisteredElementTypes(extractionRegistry));\n\n\tconst interactions: BaseInteractionData[] = [];\n\tfor (const discovered of elements) {\n\t\tconst context = createExtractionContext(\n\t\t\tdiscovered.element,\n\t\t\tdiscovered.responseIdentifier,\n\t\t\tdiscovered.contextRoot,\n\t\t\tdeclMap,\n\t\t\tconfig,\n\t\t\tsessionGuid\n\t\t);\n\t\tconst result = extractionRegistry.extract<Record<string, unknown>>(\n\t\t\tdiscovered.element,\n\t\t\tcontext\n\t\t);\n\t\tif (!result.success) throw result.error;\n\n\t\tconst extractor = result.extractor;\n\t\tconst outputType = extractor?.outputType ?? discovered.normalizedType;\n\t\tconst interaction = {\n\t\t\t...result.data,\n\t\t\t// These are framework-owned routing fields. Applying them after the\n\t\t\t// extractor payload prevents a plugin from redirecting a response or\n\t\t\t// selecting an undeclared renderer through payload properties.\n\t\t\ttype: outputType,\n\t\t\tresponseId: discovered.responseIdentifier,\n\t\t} satisfies DeliveredInteraction<string, Record<string, unknown>>;\n\t\t// Sink policy follows the authored interaction kind, while outputType only\n\t\t// selects a renderer. A plugin replacing a standard extractor must not be\n\t\t// able to shed the standard prompt/choice/URL policy by renaming its output.\n\t\tconst standardFields = extractionRegistry.getDeliveryFieldsForType(\n\t\t\tdiscovered.normalizedType,\n\t\t);\n\t\tconst extractorFields = extractor.delivery?.fields ?? [];\n\t\tinteractions.push(\n\t\t\tfinalizeInteractionDelivery(\n\t\t\t\tinteraction,\n\t\t\t\tmergeDeliveryFields(standardFields, extractorFields),\n\t\t\t\tconfig.security,\n\t\t\t\tdiscovered.normalizedType,\n\t\t\t)\n\t\t);\n\t}\n\n\treturn Object.freeze(interactions);\n}\n\nfunction mergeDeliveryFields<T extends { kind: string; path: readonly (string | '*')[] }>(\n\tstandard: readonly T[],\n\textension: readonly T[]\n): T[] {\n\tconst fields = new Map<string, T>();\n\tfor (const field of [...extension, ...standard]) {\n\t\t// An output path has one sink meaning. Authored standard policy is\n\t\t// authoritative even when a plugin tries to change the field kind itself.\n\t\tfields.set(JSON.stringify(field.path), field);\n\t}\n\treturn [...fields.values()];\n}\n\nfunction getRegisteredElementTypes(extractionRegistry: ExtractionRegistry): string[] {\n\tconst elementTypes = new Set<string>();\n\tfor (const extractor of extractionRegistry.getExtractors()) {\n\t\tfor (const elementType of extractor.elementTypes) {\n\t\t\telementTypes.add(elementType);\n\t\t}\n\t}\n\treturn [...elementTypes];\n}\n\nfunction projectDeclarationsForExtraction(\n\tdeclarations: DeclarationMap\n): Map<string, ExtractionVariableDeclaration> {\n\tconst declMap = new Map<string, ExtractionVariableDeclaration>();\n\tfor (const declaration of Object.values(declarations)) {\n\t\tdeclMap.set(declaration.identifier, {\n\t\t\tidentifier: declaration.identifier,\n\t\t\tcardinality: declaration.cardinality as any,\n\t\t\tbaseType: declaration.baseType,\n\t\t});\n\t}\n\treturn declMap;\n}\n"]}
1
+ {"version":3,"file":"interactionExtractionPipeline.js","sourceRoot":"","sources":["../../src/extraction/interactionExtractionPipeline.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAC9F,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAuBvE,MAAM,UAAU,sBAAsB,CAAC,EACtC,QAAQ,EACR,kBAAkB,EAClB,YAAY,EACZ,MAAM,EACN,WAAW,EACX,eAAe,GACqB;IACpC,MAAM,OAAO,GAAG,gCAAgC,CAAC,YAAY,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,CAC/C,yBAAyB,CAAC,kBAAkB,CAAC,EAC7C,eAAe,CACf,CAAC;IAEF,MAAM,YAAY,GAA0B,EAAE,CAAC;IAC/C,KAAK,MAAM,UAAU,IAAI,QAAQ,EAAE,CAAC;QACnC,MAAM,OAAO,GAAG,uBAAuB,CACtC,UAAU,CAAC,OAAO,EAClB,UAAU,CAAC,kBAAkB,EAC7B,UAAU,CAAC,WAAW,EACtB,OAAO,EACP,MAAM,EACN,WAAW,CACX,CAAC;QACF,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,CACxC,UAAU,CAAC,OAAO,EAClB,OAAO,CACP,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,MAAM,MAAM,CAAC,KAAK,CAAC;QAExC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,MAAM,UAAU,GAAG,SAAS,EAAE,UAAU,IAAI,UAAU,CAAC,cAAc,CAAC;QACtE,MAAM,aAAa,GAAG,wBAAwB,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3F,MAAM,SAAS,G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7B,CAAC;AAED,SAAS,yBAAyB,CAAC,kBAAsC;IACxE,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IACvC,KAAK,MAAM,SAAS,IAAI,kBAAkB,CAAC,aAAa,EAAE,EAAE,CAAC;QAC5D,KAAK,MAAM,WAAW,IAAI,SAAS,CAAC,YAAY,EAAE,CAAC;YAClD,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAC/B,CAAC;IACF,CAAC;IACD,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,gCAAgC,CACxC,YAA4B;IAE5B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyC,CAAC;IACjE,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QACvD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,EAAE;YACnC,UAAU,EAAE,WAAW,CAAC,UAAU;YAClC,WAAW,EAAE,WAAW,CAAC,WAAkB;YAC3C,QAAQ,EAAE,WAAW,CAAC,QAAQ;SAC9B,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { AssessmentItemDocument } from '../document/AssessmentItemDocument.js';\nimport type { ContentHandlers } from '../document/contentPass.js';\nimport type { ExtractionRegistry } from './ExtractionRegistry.js';\nimport { createExtractionContext } from './createContext.js';\nimport { interactionAccessibility, readAloudAttributes } from './interactionAccessibility.js';\nimport { finalizeInteractionDelivery } from './interactionSecurity.js';\nimport type { VariableDeclaration as ExtractionVariableDeclaration } from './types.js';\nimport type { DeclarationMap } from '@pie-qti/qti-processing';\nimport type { ExtractionConfig } from './types.js';\nimport type {\n\tBaseInteractionData,\n\tDeliveredInteraction,\n} from '../interactions/shared/types.js';\n\nexport interface InteractionExtractionPipelineInput {\n\tdocument: AssessmentItemDocument;\n\textractionRegistry: ExtractionRegistry;\n\tdeclarations: DeclarationMap;\n\tconfig: ExtractionConfig;\n\t/**\n\t * Item session GUID, used to seed `shuffle` for the interactions that support it.\n\t * Omit to keep the authored order.\n\t */\n\tsessionGuid?: string;\n\t/** The content pass applied to the item body before interactions are extracted. */\n\tcontentHandlers?: ContentHandlers;\n}\n\nexport function extractInteractionData({\n\tdocument,\n\textractionRegistry,\n\tdeclarations,\n\tconfig,\n\tsessionGuid,\n\tcontentHandlers,\n}: InteractionExtractionPipelineInput): readonly BaseInteractionData[] {\n\tconst declMap = projectDeclarationsForExtraction(declarations);\n\tconst elements = document.findExtractionElements(\n\t\tgetRegisteredElementTypes(extractionRegistry),\n\t\tcontentHandlers,\n\t);\n\n\tconst interactions: BaseInteractionData[] = [];\n\tfor (const discovered of elements) {\n\t\tconst context = createExtractionContext(\n\t\t\tdiscovered.element,\n\t\t\tdiscovered.responseIdentifier,\n\t\t\tdiscovered.contextRoot,\n\t\t\tdeclMap,\n\t\t\tconfig,\n\t\t\tsessionGuid\n\t\t);\n\t\tconst result = extractionRegistry.extract<Record<string, unknown>>(\n\t\t\tdiscovered.element,\n\t\t\tcontext\n\t\t);\n\t\tif (!result.success) throw result.error;\n\n\t\tconst extractor = result.extractor;\n\t\tconst outputType = extractor?.outputType ?? discovered.normalizedType;\n\t\tconst accessibility = interactionAccessibility(discovered.element, discovered.contextRoot);\n\t\tconst readAloud = readAloudAttributes(discovered.element);\n\t\tconst interaction = {\n\t\t\t...result.data,\n\t\t\t...(accessibility ? { accessibility } : {}),\n\t\t\t...(readAloud ? { readAloud } : {}),\n\t\t\t// These are framework-owned routing fields. Applying them after the\n\t\t\t// extractor payload prevents a plugin from redirecting a response or\n\t\t\t// selecting an undeclared renderer through payload properties.\n\t\t\ttype: outputType,\n\t\t\tresponseId: discovered.responseIdentifier,\n\t\t} satisfies DeliveredInteraction<string, Record<string, unknown>>;\n\t\t// Sink policy follows the authored interaction kind, while outputType only\n\t\t// selects a renderer. A plugin replacing a standard extractor must not be\n\t\t// able to shed the standard prompt/choice/URL policy by renaming its output.\n\t\tconst standardFields = extractionRegistry.getDeliveryFieldsForType(\n\t\t\tdiscovered.normalizedType,\n\t\t);\n\t\tconst extractorFields = extractor.delivery?.fields ?? [];\n\t\tinteractions.push(\n\t\t\tfinalizeInteractionDelivery(\n\t\t\t\tinteraction,\n\t\t\t\tmergeDeliveryFields(standardFields, extractorFields),\n\t\t\t\tconfig.security,\n\t\t\t\tdiscovered.normalizedType,\n\t\t\t)\n\t\t);\n\t}\n\n\treturn Object.freeze(interactions);\n}\n\nfunction mergeDeliveryFields<T extends { kind: string; path: readonly (string | '*')[] }>(\n\tstandard: readonly T[],\n\textension: readonly T[]\n): T[] {\n\tconst fields = new Map<string, T>();\n\tfor (const field of [...extension, ...standard]) {\n\t\t// An output path has one sink meaning. Authored standard policy is\n\t\t// authoritative even when a plugin tries to change the field kind itself.\n\t\tfields.set(JSON.stringify(field.path), field);\n\t}\n\treturn [...fields.values()];\n}\n\nfunction getRegisteredElementTypes(extractionRegistry: ExtractionRegistry): string[] {\n\tconst elementTypes = new Set<string>();\n\tfor (const extractor of extractionRegistry.getExtractors()) {\n\t\tfor (const elementType of extractor.elementTypes) {\n\t\t\telementTypes.add(elementType);\n\t\t}\n\t}\n\treturn [...elementTypes];\n}\n\nfunction projectDeclarationsForExtraction(\n\tdeclarations: DeclarationMap\n): Map<string, ExtractionVariableDeclaration> {\n\tconst declMap = new Map<string, ExtractionVariableDeclaration>();\n\tfor (const declaration of Object.values(declarations)) {\n\t\tdeclMap.set(declaration.identifier, {\n\t\t\tidentifier: declaration.identifier,\n\t\t\tcardinality: declaration.cardinality as any,\n\t\t\tbaseType: declaration.baseType,\n\t\t});\n\t}\n\treturn declMap;\n}\n"]}
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { Qti2xElementNameMapper, Qti2xAttributeNameMapper } from '@pie-qti/qti-common';
7
7
  import { sanitizeTextContent } from '../core/sanitizer.js';
8
+ import { readAloudAttributes } from './interactionAccessibility.js';
8
9
  /**
9
10
  * Extract text content from QTI elements
10
11
  */
@@ -86,6 +87,12 @@ function matchesTagName(rawTagName, expectedTagName, mapper) {
86
87
  // Check if raw tag name matches the native form (case-insensitive)
87
88
  return rawTagName.toLowerCase() === native.toLowerCase();
88
89
  }
90
+ /** Whether `element`'s content is one element carrying `idref`. */
91
+ function wrapsContentWithIdref(element, idref) {
92
+ const content = element.childNodes.filter((child) => child.nodeType === 1 || child.text.trim() !== '');
93
+ const [only] = content;
94
+ return content.length === 1 && only.getAttribute?.('data-catalog-idref') === idref;
95
+ }
89
96
  /**
90
97
  * Create extraction utilities instance
91
98
  * Provides standard helpers for extracting data from QTI elements.
@@ -141,7 +148,19 @@ export function createExtractionUtils(security, mapper, attributeMapper) {
141
148
  },
142
149
  getHtmlContent(element) {
143
150
  const html = element?.innerHTML?.trim() || '';
144
- return sanitizeTextContent(html, { security });
151
+ // A prompt's or choice's own language, catalog idref and read-aloud suppression would
152
+ // go with its tag, so they wrap its content. An object's markup stays as authored.
153
+ const attributes = element?.rawTagName?.toLowerCase() === 'object' ? undefined : readAloudAttributes(element);
154
+ // Markup preparation docks a choice's idref on a wrapper around its content already.
155
+ if (attributes?.['data-catalog-idref'] && wrapsContentWithIdref(element, attributes['data-catalog-idref'])) {
156
+ delete attributes['data-catalog-idref'];
157
+ }
158
+ const wrapped = html && attributes && Object.keys(attributes).length > 0
159
+ ? `<span ${Object.entries(attributes)
160
+ .map(([name, value]) => `${name}="${value.replace(/&/g, '&amp;').replace(/"/g, '&quot;')}"`)
161
+ .join(' ')}>${html}</span>`
162
+ : html;
163
+ return sanitizeTextContent(wrapped, { security });
145
164
  },
146
165
  getTextContent(element) {
147
166
  return getTextContent(element);
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/extraction/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sB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QACpE,CAAC;QAED,mBAAmB,CAAC,OAAmB,EAAE,IAAY,EAAE,YAAY,GAAG,KAAK;YAC1E,OAAO,mBAAmB,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QACrE,CAAC;QAED,kBAAkB,CAAC,OAAmB,EAAE,IAAY,EAAE,YAAY,GAAG,CAAC;YACrE,OAAO,kBAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QACpE,CAAC;QAED,SAAS,CAAC,OAAmB;YAC5B,MAAM,aAAa,GAAG,0BAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;YACtF,OAAO,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAClE,CAAC;QAED,UAAU,CAAC,OAAmB;YAC7B,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Extraction utilities implementation\n *\n * Provides DOM manipulation and content extraction helpers for extractors\n */\n\nimport type { ElementNameMapper, AttributeNameMapper } from '@pie-qti/qti-common';\nimport { Qti2xElementNameMapper, Qti2xAttributeNameMapper } from '@pie-qti/qti-common';\nimport { sanitizeTextContent } from '../core/sanitizer.js';\nimport type { PlayerSecurityConfig } from '../types/index.js';\nimport type { QTIElement } from '../interactions/shared/types.js';\nimport type { ExtractionUtils } from './types.js';\n\n/**\n * Extract text content from QTI elements\n */\nfunction getTextContent(element: QTIElement | null | undefined): string {\n\treturn element?.textContent?.trim() || '';\n}\n\n/**\n * Get children by tag name with QTI version awareness\n */\nfunction getChildrenByTagWithMapper(\n\telement: QTIElement | null | undefined,\n\ttagName: string,\n\tmapper: ElementNameMapper\n): QTIElement[] {\n\tif (!element?.childNodes) return [];\n\treturn element.childNodes.filter((n) =>\n\t\tmatchesTagName((n as QTIElement).rawTagName, tagName, mapper)\n\t) as QTIElement[];\n}\n\n/**\n * Extract a boolean attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getBooleanAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue = false,\n\tattributeMapper?: AttributeNameMapper\n): boolean {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\tif (value === null || value === undefined) return defaultValue;\n\treturn value === 'true';\n}\n\n/**\n * Extract a number attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getNumberAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue: number,\n\tattributeMapper?: AttributeNameMapper\n): number {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\treturn value ? Number(value) : defaultValue;\n}\n\n/**\n * Extract a string attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getStringAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue = '',\n\tattributeMapper?: AttributeNameMapper\n): string {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\treturn value || defaultValue;\n}\n\n/**\n * Extract CSS classes from an element\n */\nfunction getClasses(element: QTIElement): string[] {\n\tconst classAttr = element.getAttribute('class');\n\treturn classAttr ? classAttr.split(/\\s+/).filter(Boolean) : [];\n}\n\n/**\n * Helper to check if an element's tag name matches a given QTI element name.\n * Handles both QTI 2.x and QTI 3.0 element naming conventions.\n *\n * @param rawTagName - The element's raw tag name from the HTML\n * @param expectedTagName - The tag name to check (in QTI 2.x format, e.g., 'simpleChoice')\n * @param mapper - Optional element name mapper for QTI version handling\n * @returns true if the tag name matches\n */\nfunction matchesTagName(\n\trawTagName: string | undefined,\n\texpectedTagName: string,\n\tmapper: ElementNameMapper\n): boolean {\n\tif (!rawTagName) return false;\n\n\t// Convert expected tag name to canonical form (lowercase)\n\tconst canonical = expectedTagName.toLowerCase();\n\n\t// Get the native form for this QTI version\n\tconst native = mapper.toNative(canonical);\n\n\t// Check if raw tag name matches the native form (case-insensitive)\n\treturn rawTagName.toLowerCase() === native.toLowerCase();\n}\n\n/**\n * Create extraction utilities instance\n * Provides standard helpers for extracting data from QTI elements.\n * Automatically handles both QTI 2.x and QTI 3.0 element and attribute naming conventions.\n */\nexport function createExtractionUtils(\n\tsecurity?: PlayerSecurityConfig,\n\tmapper?: ElementNameMapper,\n\tattributeMapper?: AttributeNameMapper\n): ExtractionUtils {\n\t// Default to QTI 2.x mappers (primary supported QTI format)\n\tconst elementMapper = mapper || new Qti2xElementNameMapper();\n\tconst attrMapper = attributeMapper || new Qti2xAttributeNameMapper();\n\treturn {\n\t\tmatchesTag(element: QTIElement, tagName: string): boolean {\n\t\t\treturn matchesTagName(element.rawTagName, tagName, elementMapper);\n\t\t},\n\n\t\tgetChildrenByTag(element: QTIElement, tagName: string): QTIElement[] {\n\t\t\treturn getChildrenByTagWithMapper(element, tagName, elementMapper);\n\t\t},\n\n\t\tquerySelectorAll(element: QTIElement, selector: string): QTIElement[] {\n\t\t\t// Parse simple selectors like \"choiceInteraction simpleChoice\"\n\t\t\tconst parts = selector.split(/\\s+/);\n\t\t\tlet results: QTIElement[] = [element];\n\n\t\t\tfor (const part of parts) {\n\t\t\t\tconst nextResults: QTIElement[] = [];\n\t\t\t\tfor (const current of results) {\n\t\t\t\t\tif (matchesTagName(current.rawTagName, part, elementMapper)) {\n\t\t\t\t\t\tnextResults.push(current);\n\t\t\t\t\t}\n\t\t\t\t\tif (current.childNodes) {\n\t\t\t\t\t\tfor (const child of current.childNodes) {\n\t\t\t\t\t\t\tif (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, part, elementMapper)) {\n\t\t\t\t\t\t\t\tnextResults.push(child as QTIElement);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresults = nextResults;\n\t\t\t}\n\n\t\t\treturn results;\n\t\t},\n\n\t\tquerySelector(element: QTIElement, selector: string): QTIElement | null {\n\t\t\tconst results = this.querySelectorAll(element, selector);\n\t\t\treturn results.length > 0 ? results[0] : null;\n\t\t},\n\n\t\thasChildWithTag(element: QTIElement, tagName: string): boolean {\n\t\t\t// Fast boolean check without allocation\n\t\t\tif (!element.childNodes) return false;\n\n\t\t\tfor (const child of element.childNodes) {\n\t\t\t\tif (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, tagName, elementMapper)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\n\t\tgetHtmlContent(element: QTIElement): string {\n\t\t\tconst html = element?.innerHTML?.trim() || '';\n\t\t\treturn sanitizeTextContent(html, { security });\n\t\t},\n\n\t\tgetTextContent(element: QTIElement): string {\n\t\t\treturn getTextContent(element);\n\t\t},\n\n\t\tgetAttribute(element: QTIElement, name: string, defaultValue = ''): string {\n\t\t\treturn getStringAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetBooleanAttribute(element: QTIElement, name: string, defaultValue = false): boolean {\n\t\t\treturn getBooleanAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetNumberAttribute(element: QTIElement, name: string, defaultValue = 0): number {\n\t\t\treturn getNumberAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetPrompt(element: QTIElement): string | null {\n\t\t\tconst promptElement = getChildrenByTagWithMapper(element, 'prompt', elementMapper)[0];\n\t\t\treturn promptElement ? this.getHtmlContent(promptElement) : null;\n\t\t},\n\n\t\tgetClasses(element: QTIElement): string[] {\n\t\t\treturn getClasses(element);\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/extraction/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAKpE;;GAEG;AACH,SAAS,cAAc,CAAC,OAAsC;IAC7D,OAAO,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAClC,OAAsC,EACtC,OAAe,EACf,MAAyB;IAEzB,IAAI,CAAC,OAAO,EAAE,UAAU;QAAE,OAAO,EAAE,CAAC;IACpC,OAAO,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACtC,cAAc,CAAE,CAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAC7C,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAC3B,OAAmB,EACnB,IAAY,EACZ,YAAY,GAAG,KAAK,EACpB,eAAqC;IAErC,IAAI,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEvC,gFAAgF;IAChF,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,IAAI,eAAe,EAAE,CAAC;QAChE,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;Q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CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC;qBAC3F,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,SAAS;gBAC7B,CAAC,CAAC,IAAI,CAAC;YACT,OAAO,mBAAmB,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QACnD,CAAC;QAED,cAAc,CAAC,OAAmB;YACjC,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;QAChC,CAAC;QAED,YAAY,CAAC,OAAmB,EAAE,IAAY,EAAE,YAAY,GAAG,EAAE;YAChE,OAAO,kBAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QACpE,CAAC;QAED,mBAAmB,CAAC,OAAmB,EAAE,IAAY,EAAE,YAAY,GAAG,KAAK;YAC1E,OAAO,mBAAmB,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QACrE,CAAC;QAED,kBAAkB,CAAC,OAAmB,EAAE,IAAY,EAAE,YAAY,GAAG,CAAC;YACrE,OAAO,kBAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QACpE,CAAC;QAED,SAAS,CAAC,OAAmB;YAC5B,MAAM,aAAa,GAAG,0BAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;YACtF,OAAO,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAClE,CAAC;QAED,UAAU,CAAC,OAAmB;YAC7B,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Extraction utilities implementation\n *\n * Provides DOM manipulation and content extraction helpers for extractors\n */\n\nimport type { ElementNameMapper, AttributeNameMapper } from '@pie-qti/qti-common';\nimport { Qti2xElementNameMapper, Qti2xAttributeNameMapper } from '@pie-qti/qti-common';\nimport { sanitizeTextContent } from '../core/sanitizer.js';\nimport { readAloudAttributes } from './interactionAccessibility.js';\nimport type { PlayerSecurityConfig } from '../types/index.js';\nimport type { QTIElement } from '../interactions/shared/types.js';\nimport type { ExtractionUtils } from './types.js';\n\n/**\n * Extract text content from QTI elements\n */\nfunction getTextContent(element: QTIElement | null | undefined): string {\n\treturn element?.textContent?.trim() || '';\n}\n\n/**\n * Get children by tag name with QTI version awareness\n */\nfunction getChildrenByTagWithMapper(\n\telement: QTIElement | null | undefined,\n\ttagName: string,\n\tmapper: ElementNameMapper\n): QTIElement[] {\n\tif (!element?.childNodes) return [];\n\treturn element.childNodes.filter((n) =>\n\t\tmatchesTagName((n as QTIElement).rawTagName, tagName, mapper)\n\t) as QTIElement[];\n}\n\n/**\n * Extract a boolean attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getBooleanAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue = false,\n\tattributeMapper?: AttributeNameMapper\n): boolean {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\tif (value === null || value === undefined) return defaultValue;\n\treturn value === 'true';\n}\n\n/**\n * Extract a number attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getNumberAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue: number,\n\tattributeMapper?: AttributeNameMapper\n): number {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\treturn value ? Number(value) : defaultValue;\n}\n\n/**\n * Extract a string attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getStringAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue = '',\n\tattributeMapper?: AttributeNameMapper\n): string {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\treturn value || defaultValue;\n}\n\n/**\n * Extract CSS classes from an element\n */\nfunction getClasses(element: QTIElement): string[] {\n\tconst classAttr = element.getAttribute('class');\n\treturn classAttr ? classAttr.split(/\\s+/).filter(Boolean) : [];\n}\n\n/**\n * Helper to check if an element's tag name matches a given QTI element name.\n * Handles both QTI 2.x and QTI 3.0 element naming conventions.\n *\n * @param rawTagName - The element's raw tag name from the HTML\n * @param expectedTagName - The tag name to check (in QTI 2.x format, e.g., 'simpleChoice')\n * @param mapper - Optional element name mapper for QTI version handling\n * @returns true if the tag name matches\n */\nfunction matchesTagName(\n\trawTagName: string | undefined,\n\texpectedTagName: string,\n\tmapper: ElementNameMapper\n): boolean {\n\tif (!rawTagName) return false;\n\n\t// Convert expected tag name to canonical form (lowercase)\n\tconst canonical = expectedTagName.toLowerCase();\n\n\t// Get the native form for this QTI version\n\tconst native = mapper.toNative(canonical);\n\n\t// Check if raw tag name matches the native form (case-insensitive)\n\treturn rawTagName.toLowerCase() === native.toLowerCase();\n}\n\n/** Whether `element`'s content is one element carrying `idref`. */\nfunction wrapsContentWithIdref(element: QTIElement, idref: string): boolean {\n\tconst content = element.childNodes.filter((child) => child.nodeType === 1 || child.text.trim() !== '');\n\tconst [only] = content;\n\treturn content.length === 1 && (only as QTIElement).getAttribute?.('data-catalog-idref') === idref;\n}\n\n/**\n * Create extraction utilities instance\n * Provides standard helpers for extracting data from QTI elements.\n * Automatically handles both QTI 2.x and QTI 3.0 element and attribute naming conventions.\n */\nexport function createExtractionUtils(\n\tsecurity?: PlayerSecurityConfig,\n\tmapper?: ElementNameMapper,\n\tattributeMapper?: AttributeNameMapper\n): ExtractionUtils {\n\t// Default to QTI 2.x mappers (primary supported QTI format)\n\tconst elementMapper = mapper || new Qti2xElementNameMapper();\n\tconst attrMapper = attributeMapper || new Qti2xAttributeNameMapper();\n\treturn {\n\t\tmatchesTag(element: QTIElement, tagName: string): boolean {\n\t\t\treturn matchesTagName(element.rawTagName, tagName, elementMapper);\n\t\t},\n\n\t\tgetChildrenByTag(element: QTIElement, tagName: string): QTIElement[] {\n\t\t\treturn getChildrenByTagWithMapper(element, tagName, elementMapper);\n\t\t},\n\n\t\tquerySelectorAll(element: QTIElement, selector: string): QTIElement[] {\n\t\t\t// Parse simple selectors like \"choiceInteraction simpleChoice\"\n\t\t\tconst parts = selector.split(/\\s+/);\n\t\t\tlet results: QTIElement[] = [element];\n\n\t\t\tfor (const part of parts) {\n\t\t\t\tconst nextResults: QTIElement[] = [];\n\t\t\t\tfor (const current of results) {\n\t\t\t\t\tif (matchesTagName(current.rawTagName, part, elementMapper)) {\n\t\t\t\t\t\tnextResults.push(current);\n\t\t\t\t\t}\n\t\t\t\t\tif (current.childNodes) {\n\t\t\t\t\t\tfor (const child of current.childNodes) {\n\t\t\t\t\t\t\tif (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, part, elementMapper)) {\n\t\t\t\t\t\t\t\tnextResults.push(child as QTIElement);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresults = nextResults;\n\t\t\t}\n\n\t\t\treturn results;\n\t\t},\n\n\t\tquerySelector(element: QTIElement, selector: string): QTIElement | null {\n\t\t\tconst results = this.querySelectorAll(element, selector);\n\t\t\treturn results.length > 0 ? results[0] : null;\n\t\t},\n\n\t\thasChildWithTag(element: QTIElement, tagName: string): boolean {\n\t\t\t// Fast boolean check without allocation\n\t\t\tif (!element.childNodes) return false;\n\n\t\t\tfor (const child of element.childNodes) {\n\t\t\t\tif (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, tagName, elementMapper)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\n\t\tgetHtmlContent(element: QTIElement): string {\n\t\t\tconst html = element?.innerHTML?.trim() || '';\n\t\t\t// A prompt's or choice's own language, catalog idref and read-aloud suppression would\n\t\t\t// go with its tag, so they wrap its content. An object's markup stays as authored.\n\t\t\tconst attributes = element?.rawTagName?.toLowerCase() === 'object' ? undefined : readAloudAttributes(element);\n\t\t\t// Markup preparation docks a choice's idref on a wrapper around its content already.\n\t\t\tif (attributes?.['data-catalog-idref'] && wrapsContentWithIdref(element, attributes['data-catalog-idref'])) {\n\t\t\t\tdelete attributes['data-catalog-idref'];\n\t\t\t}\n\t\t\tconst wrapped =\n\t\t\t\thtml && attributes && Object.keys(attributes).length > 0\n\t\t\t\t\t? `<span ${Object.entries(attributes)\n\t\t\t\t\t\t\t.map(([name, value]) => `${name}=\"${value.replace(/&/g, '&amp;').replace(/\"/g, '&quot;')}\"`)\n\t\t\t\t\t\t\t.join(' ')}>${html}</span>`\n\t\t\t\t\t: html;\n\t\t\treturn sanitizeTextContent(wrapped, { security });\n\t\t},\n\n\t\tgetTextContent(element: QTIElement): string {\n\t\t\treturn getTextContent(element);\n\t\t},\n\n\t\tgetAttribute(element: QTIElement, name: string, defaultValue = ''): string {\n\t\t\treturn getStringAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetBooleanAttribute(element: QTIElement, name: string, defaultValue = false): boolean {\n\t\t\treturn getBooleanAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetNumberAttribute(element: QTIElement, name: string, defaultValue = 0): number {\n\t\t\treturn getNumberAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetPrompt(element: QTIElement): string | null {\n\t\t\tconst promptElement = getChildrenByTagWithMapper(element, 'prompt', elementMapper)[0];\n\t\t\treturn promptElement ? this.getHtmlContent(promptElement) : null;\n\t\t},\n\n\t\tgetClasses(element: QTIElement): string[] {\n\t\t\treturn getClasses(element);\n\t\t},\n\t};\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { type ComponentConfig, type ComponentPlugin, ComponentRegistry, createCo
6
6
  export * from './core/constants.js';
7
7
  export * from './utils/drawingUtils.js';
8
8
  export { createAssessmentItemDefinition, type AssessmentItemDefinition, type AssessmentItemDefinitionConfig, type AssessmentItemDefinitionPlugin, } from './core/AssessmentItemDefinition.js';
9
- export { type ItemPresentationView, type ItemSession, type ItemSessionCommand, type ItemSessionEventCommand, type ItemSessionListener, type ItemSessionTransition, type ItemSessionView, type OpenItemSessionOptions, } from './core/ItemSession.js';
9
+ export { type ItemPresentationView, type ItemSession, type ItemSessionCommand, type ItemSessionEventCommand, type ItemSessionListener, type ItemSessionPresentationPolicy, type ItemSessionTransition, type ItemSessionView, type OpenItemSessionOptions, } from './core/ItemSession.js';
10
10
  export type { FinalItemBodyHtml, ItemInteractionMount, ItemPresentation, ItemPresentationFlowNode, } from './presentation/itemPresentationPlan.js';
11
11
  export { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';
12
12
  export type * from './interactions/shared/types.js';
@@ -16,7 +16,7 @@ export { createExtractionContext, createExtractionRegistry, createExtractionUtil
16
16
  export * from './types/index.js';
17
17
  export { globalPerformanceMonitor, type PerformanceEntry, PerformanceMonitor, type PerformanceMonitorConfig, type PerformanceReport, } from './utils/PerformanceMonitor.js';
18
18
  export { isResponseEmpty } from './utils/responseUtils.js';
19
- export type { PnpProfile } from './pnp/types.js';
19
+ export type { PnpProfile, PnpTextAppearance, PnpToolSupports } from './pnp/types.js';
20
20
  export { applyPnpToRoot } from './pnp/applyPnp.js';
21
21
  export type { AfaPnpRecord } from './pnp/parsePnpXml.js';
22
22
  export { AFA_PNP_NAMESPACE, parseAfaPnpXml, parsePnpXml, pnpProfileFromAfa } from './pnp/parsePnpXml.js';
@@ -24,11 +24,17 @@ export type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js
24
24
  export { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';
25
25
  export { getCatalogEntry } from './catalog/catalogLookup.js';
26
26
  export type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
27
- export type { ExtractedPci, PciBoundTo, PciConfiguration, PciHostController, PciHostOptions, PciModule, PciModulePathKind, PciModuleResolutionContext, PciModuleResolver, } from './pci/types.js';
27
+ export type { ExtractedPci, PciConfiguration, PciCustomInteractionContext, PciHostController, PciHostOptions, PciInteractionStatus, PciModuleEntry, PciModulePathKind, PciModuleResolutionContext, PciModuleResolver, PciRegistryObservation, PciResponseDeclarationInfo, QtiCustomInteractionRegistration, QtiPciConfiguration, QtiPciInstance, } from './pci/types.js';
28
28
  export { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';
29
29
  export { PciHost } from './pci/PciHost.js';
30
30
  export { createAllowlistPciModuleResolver, PciModuleNotAllowedError, } from './pci/allowlistResolver.js';
31
31
  export type { AllowlistPciResolverOptions } from './pci/allowlistResolver.js';
32
+ export { installPciRegistry, getSharedPciRegistry, PCI_REGISTRY_GLOBAL } from './pci/registry.js';
33
+ export { createAmdLoader } from './pci/amdLoader.js';
34
+ export type { AmdLoader, AmdLoaderOptions } from './pci/amdLoader.js';
35
+ export { DEFAULT_RESOLUTION_CONFIG_PATHS, emptyResolutionConfig, parseModuleResolutionConfig, } from './pci/resolutionConfig.js';
36
+ export type { PciResolutionConfig, PciResolutionShim } from './pci/resolutionConfig.js';
37
+ export { toQtiVariableJson, fromQtiVariableJson } from './pci/qtiVariableJson.js';
32
38
  export { normalizeHeuristicsConfig, applyFeedbackTextHeuristics, shouldUseLenientImagePaths, shouldAutoPopulateFeedbackOutcome, DEFAULT_HEURISTICS_CONFIG, STRICT_QTI_CONFIG, FEEDBACK_TEXT_TRANSFORMS, type QtiHeuristicsConfig, type TextTransform, } from '@pie-qti/ims-cp-core';
33
39
  /**
34
40
  * NOTE (SSR safety):
package/dist/index.js CHANGED
@@ -26,6 +26,10 @@ export { getCatalogEntry } from './catalog/catalogLookup.js';
26
26
  export { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';
27
27
  export { PciHost } from './pci/PciHost.js';
28
28
  export { createAllowlistPciModuleResolver, PciModuleNotAllowedError, } from './pci/allowlistResolver.js';
29
+ export { installPciRegistry, getSharedPciRegistry, PCI_REGISTRY_GLOBAL } from './pci/registry.js';
30
+ export { createAmdLoader } from './pci/amdLoader.js';
31
+ export { DEFAULT_RESOLUTION_CONFIG_PATHS, emptyResolutionConfig, parseModuleResolutionConfig, } from './pci/resolutionConfig.js';
32
+ export { toQtiVariableJson, fromQtiVariableJson } from './pci/qtiVariableJson.js';
29
33
  // Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience
30
34
  // (heuristics are now in the shared ingestion layer)
31
35
  export { normalizeHeuristicsConfig, applyFeedbackTextHeuristics, shouldUseLenientImagePaths, shouldAutoPopulateFeedbackOutcome, DEFAULT_HEURISTICS_CONFIG, STRICT_QTI_CONFIG, FEEDBACK_TEXT_TRANSFORMS, } from '@pie-qti/ims-cp-core';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,4DAA4D;AAC5D,OAAO,EAGN,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,6BAA6B,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,2BAA2B;AAC3B,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACN,8BAA8B,GAI9B,MAAM,oCAAoC,CAAC;AAiB5C,OAAO,EAAE,mBAAmB,EAAyB,MAAM,sBAAsB,CAAC;AAGlF,OAAO,EACN,+BAA+B,EAC/B,0BAA0B,EAC1B,gCAAgC,EAChC,6BAA6B,GAG7B,MAAM,0CAA0C,CAAC;AAalD,OAAO,EACN,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,eAAe,EACf,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAC/B,QAAQ;AACR,qGAAqG;AACrG,mGAAmG;AACnG,iDAAiD;AACjD,cAAc,kBAAkB,CAAC;AACjC,mBAAmB;AACnB,OAAO,EACN,wBAAwB,EAExB,kBAAkB,GAGlB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAI3D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzG,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACzG,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAe7D,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EACN,gCAAgC,EAChC,wBAAwB,GACxB,MAAM,4BAA4B,CAAC;AAGpC,qEAAqE;AACrE,qDAAqD;AACrD,OAAO,EACN,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,iCAAiC,EACjC,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,GAGxB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;GAQG","sourcesContent":["/**\n * @pie-qti/item-player\n * Modern QTI player (2.2/3.0) - Framework-agnostic with web components\n */\n\n\n// Export web component registry for pluggable UI components\nexport {\n\ttype ComponentConfig,\n\ttype ComponentPlugin,\n\tComponentRegistry,\n\tcreateComponentRegistry,\n} from './core/ComponentRegistry.js';\nexport * from './core/constants.js';\n// Export drawing utilities\nexport * from './utils/drawingUtils.js';\nexport {\n\tcreateAssessmentItemDefinition,\n\ttype AssessmentItemDefinition,\n\ttype AssessmentItemDefinitionConfig,\n\ttype AssessmentItemDefinitionPlugin,\n} from './core/AssessmentItemDefinition.js';\nexport {\n\ttype ItemPresentationView,\n\ttype ItemSession,\n\ttype ItemSessionCommand,\n\ttype ItemSessionEventCommand,\n\ttype ItemSessionListener,\n\ttype ItemSessionTransition,\n\ttype ItemSessionView,\n\ttype OpenItemSessionOptions,\n} from './core/ItemSession.js';\nexport type {\n\tFinalItemBodyHtml,\n\tItemInteractionMount,\n\tItemPresentation,\n\tItemPresentationFlowNode,\n} from './presentation/itemPresentationPlan.js';\nexport { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';\n// Render-facing interaction contracts. Standard extractors remain implementation details.\nexport type * from './interactions/shared/types.js';\nexport {\n\tcreateExtendedTextNumericRecord,\n\tcreateExtendedTextResponse,\n\tcreateExtendedTextStringResponse,\n\textendedTextResponseToStrings,\n\ttype ExtendedTextNumericRecord,\n\ttype ExtendedTextRecordField,\n} from './interactions/extended-text/response.js';\nexport type {\n\tElementExtractor,\n\tExtractionContext,\n\tExtractionDispatchResult,\n\tExtractionResult,\n\tExtractionUtils,\n\tInteractionDeliveryField,\n\tInteractionDeliveryPathSegment,\n\tInteractionDeliverySchema,\n\tValidationResult,\n\tVariableDeclaration,\n} from './extraction/index.js';\nexport {\n\tcreateExtractionContext,\n\tcreateExtractionRegistry,\n\tcreateExtractionUtils,\n\tExtractionError,\n\tExtractionRegistry,\n\thtmlField,\n\tisErrorResult,\n\tisSuccessResult,\n\turlField,\n} from './extraction/index.js';\n// NOTE:\n// The player’s primary rendering contract is via web components and the Svelte component entrypoint.\n// If you need non-web-component rendering, build it externally against the public extraction APIs.\n// Export all types including adaptive item types\nexport * from './types/index.js';\n// Export utilities\nexport {\n\tglobalPerformanceMonitor,\n\ttype PerformanceEntry,\n\tPerformanceMonitor,\n\ttype PerformanceMonitorConfig,\n\ttype PerformanceReport,\n} from './utils/PerformanceMonitor.js';\n\nexport { isResponseEmpty } from './utils/responseUtils.js';\n\n// PNP profile (AfA PNP 3.0, QTI 3's per-candidate profile)\nexport type { PnpProfile } from './pnp/types.js';\nexport { applyPnpToRoot } from './pnp/applyPnp.js';\nexport type { AfaPnpRecord } from './pnp/parsePnpXml.js';\nexport { AFA_PNP_NAMESPACE, parseAfaPnpXml, parsePnpXml, pnpProfileFromAfa } from './pnp/parsePnpXml.js';\n\n// Catalog (QTI 3.0 §6.3)\nexport type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js';\nexport { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';\nexport { getCatalogEntry } from './catalog/catalogLookup.js';\nexport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\n\n// PCI — Portable Custom Interaction (QTI 3.0 §6.1)\nexport type {\n\tExtractedPci,\n\tPciBoundTo,\n\tPciConfiguration,\n\tPciHostController,\n\tPciHostOptions,\n\tPciModule,\n\tPciModulePathKind,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n} from './pci/types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';\nexport { PciHost } from './pci/PciHost.js';\nexport {\n\tcreateAllowlistPciModuleResolver,\n\tPciModuleNotAllowedError,\n} from './pci/allowlistResolver.js';\nexport type { AllowlistPciResolverOptions } from './pci/allowlistResolver.js';\n\n// Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience\n// (heuristics are now in the shared ingestion layer)\nexport {\n\tnormalizeHeuristicsConfig,\n\tapplyFeedbackTextHeuristics,\n\tshouldUseLenientImagePaths,\n\tshouldAutoPopulateFeedbackOutcome,\n\tDEFAULT_HEURISTICS_CONFIG,\n\tSTRICT_QTI_CONFIG,\n\tFEEDBACK_TEXT_TRANSFORMS,\n\ttype QtiHeuristicsConfig,\n\ttype TextTransform,\n} from '@pie-qti/ims-cp-core';\n\n/**\n * NOTE (SSR safety):\n * Web component base classes depend on DOM globals like `HTMLElement` and must not be\n * re-exported from the main entrypoint. Item ownership flows through\n * AssessmentItemDefinition and ItemSession in every deployment.\n *\n * Import web-components from the subpath entry instead:\n * - `@pie-qti/item-player/web-components`\n */\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,4DAA4D;AAC5D,OAAO,EAGN,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,6BAA6B,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,2BAA2B;AAC3B,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACN,8BAA8B,GAI9B,MAAM,oCAAoC,CAAC;AAkB5C,OAAO,EAAE,mBAAmB,EAAyB,MAAM,sBAAsB,CAAC;AAGlF,OAAO,EACN,+BAA+B,EAC/B,0BAA0B,EAC1B,gCAAgC,EAChC,6BAA6B,GAG7B,MAAM,0CAA0C,CAAC;AAalD,OAAO,EACN,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,eAAe,EACf,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAC/B,QAAQ;AACR,qGAAqG;AACrG,mGAAmG;AACnG,iDAAiD;AACjD,cAAc,kBAAkB,CAAC;AACjC,mBAAmB;AACnB,OAAO,EACN,wBAAwB,EAExB,kBAAkB,GAGlB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAI3D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzG,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACzG,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAqB7D,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EACN,gCAAgC,EAChC,wBAAwB,GACxB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EACN,+BAA+B,EAC/B,qBAAqB,EACrB,2BAA2B,GAC3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAElF,qEAAqE;AACrE,qDAAqD;AACrD,OAAO,EACN,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,iCAAiC,EACjC,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,GAGxB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;GAQG","sourcesContent":["/**\n * @pie-qti/item-player\n * Modern QTI player (2.2/3.0) - Framework-agnostic with web components\n */\n\n\n// Export web component registry for pluggable UI components\nexport {\n\ttype ComponentConfig,\n\ttype ComponentPlugin,\n\tComponentRegistry,\n\tcreateComponentRegistry,\n} from './core/ComponentRegistry.js';\nexport * from './core/constants.js';\n// Export drawing utilities\nexport * from './utils/drawingUtils.js';\nexport {\n\tcreateAssessmentItemDefinition,\n\ttype AssessmentItemDefinition,\n\ttype AssessmentItemDefinitionConfig,\n\ttype AssessmentItemDefinitionPlugin,\n} from './core/AssessmentItemDefinition.js';\nexport {\n\ttype ItemPresentationView,\n\ttype ItemSession,\n\ttype ItemSessionCommand,\n\ttype ItemSessionEventCommand,\n\ttype ItemSessionListener,\n\ttype ItemSessionPresentationPolicy,\n\ttype ItemSessionTransition,\n\ttype ItemSessionView,\n\ttype OpenItemSessionOptions,\n} from './core/ItemSession.js';\nexport type {\n\tFinalItemBodyHtml,\n\tItemInteractionMount,\n\tItemPresentation,\n\tItemPresentationFlowNode,\n} from './presentation/itemPresentationPlan.js';\nexport { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';\n// Render-facing interaction contracts. Standard extractors remain implementation details.\nexport type * from './interactions/shared/types.js';\nexport {\n\tcreateExtendedTextNumericRecord,\n\tcreateExtendedTextResponse,\n\tcreateExtendedTextStringResponse,\n\textendedTextResponseToStrings,\n\ttype ExtendedTextNumericRecord,\n\ttype ExtendedTextRecordField,\n} from './interactions/extended-text/response.js';\nexport type {\n\tElementExtractor,\n\tExtractionContext,\n\tExtractionDispatchResult,\n\tExtractionResult,\n\tExtractionUtils,\n\tInteractionDeliveryField,\n\tInteractionDeliveryPathSegment,\n\tInteractionDeliverySchema,\n\tValidationResult,\n\tVariableDeclaration,\n} from './extraction/index.js';\nexport {\n\tcreateExtractionContext,\n\tcreateExtractionRegistry,\n\tcreateExtractionUtils,\n\tExtractionError,\n\tExtractionRegistry,\n\thtmlField,\n\tisErrorResult,\n\tisSuccessResult,\n\turlField,\n} from './extraction/index.js';\n// NOTE:\n// The player’s primary rendering contract is via web components and the Svelte component entrypoint.\n// If you need non-web-component rendering, build it externally against the public extraction APIs.\n// Export all types including adaptive item types\nexport * from './types/index.js';\n// Export utilities\nexport {\n\tglobalPerformanceMonitor,\n\ttype PerformanceEntry,\n\tPerformanceMonitor,\n\ttype PerformanceMonitorConfig,\n\ttype PerformanceReport,\n} from './utils/PerformanceMonitor.js';\n\nexport { isResponseEmpty } from './utils/responseUtils.js';\n\n// PNP profile (AfA PNP 3.0, QTI 3's per-candidate profile)\nexport type { PnpProfile, PnpTextAppearance, PnpToolSupports } from './pnp/types.js';\nexport { applyPnpToRoot } from './pnp/applyPnp.js';\nexport type { AfaPnpRecord } from './pnp/parsePnpXml.js';\nexport { AFA_PNP_NAMESPACE, parseAfaPnpXml, parsePnpXml, pnpProfileFromAfa } from './pnp/parsePnpXml.js';\n\n// Catalog (QTI 3.0 §6.3)\nexport type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js';\nexport { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';\nexport { getCatalogEntry } from './catalog/catalogLookup.js';\nexport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\n\n// PCI — Portable Custom Interaction (QTI 3.0 §6.1)\nexport type {\n\tExtractedPci,\n\tPciConfiguration,\n\tPciCustomInteractionContext,\n\tPciHostController,\n\tPciHostOptions,\n\tPciInteractionStatus,\n\tPciModuleEntry,\n\tPciModulePathKind,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n\tPciRegistryObservation,\n\tPciResponseDeclarationInfo,\n\tQtiCustomInteractionRegistration,\n\tQtiPciConfiguration,\n\tQtiPciInstance,\n} from './pci/types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';\nexport { PciHost } from './pci/PciHost.js';\nexport {\n\tcreateAllowlistPciModuleResolver,\n\tPciModuleNotAllowedError,\n} from './pci/allowlistResolver.js';\nexport type { AllowlistPciResolverOptions } from './pci/allowlistResolver.js';\nexport { installPciRegistry, getSharedPciRegistry, PCI_REGISTRY_GLOBAL } from './pci/registry.js';\nexport { createAmdLoader } from './pci/amdLoader.js';\nexport type { AmdLoader, AmdLoaderOptions } from './pci/amdLoader.js';\nexport {\n\tDEFAULT_RESOLUTION_CONFIG_PATHS,\n\temptyResolutionConfig,\n\tparseModuleResolutionConfig,\n} from './pci/resolutionConfig.js';\nexport type { PciResolutionConfig, PciResolutionShim } from './pci/resolutionConfig.js';\nexport { toQtiVariableJson, fromQtiVariableJson } from './pci/qtiVariableJson.js';\n\n// Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience\n// (heuristics are now in the shared ingestion layer)\nexport {\n\tnormalizeHeuristicsConfig,\n\tapplyFeedbackTextHeuristics,\n\tshouldUseLenientImagePaths,\n\tshouldAutoPopulateFeedbackOutcome,\n\tDEFAULT_HEURISTICS_CONFIG,\n\tSTRICT_QTI_CONFIG,\n\tFEEDBACK_TEXT_TRANSFORMS,\n\ttype QtiHeuristicsConfig,\n\ttype TextTransform,\n} from '@pie-qti/ims-cp-core';\n\n/**\n * NOTE (SSR safety):\n * Web component base classes depend on DOM globals like `HTMLElement` and must not be\n * re-exported from the main entrypoint. Item ownership flows through\n * AssessmentItemDefinition and ItemSession in every deployment.\n *\n * Import web-components from the subpath entry instead:\n * - `@pie-qti/item-player/web-components`\n */\n"]}
@@ -40,6 +40,7 @@ export const standardOrderExtractor = {
40
40
  const orientation = utils.getAttribute(element, 'orientation', 'vertical');
41
41
  const minChoices = utils.getNumberAttribute(element, 'minChoices', 0);
42
42
  const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 0);
43
+ const interactionClasses = utils.getClasses(element);
43
44
  return {
44
45
  choices: maybeShuffle(choices, shuffle, context.shuffleRng),
45
46
  shuffle,
@@ -47,6 +48,7 @@ export const standardOrderExtractor = {
47
48
  minChoices,
48
49
  maxChoices,
49
50
  prompt,
51
+ ...(interactionClasses.length > 0 ? { interactionClasses } : {}),
50
52
  };
51
53
  },
52
54
  validate(data) {
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/order/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAcrD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAgC;IAClE,EAAE,EAAE,uBAAuB;IAC3B,IAAI,EAAE,gCAAgC;IACtC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,kBAAkB,CAAC;IAClC,WAAW,EAAE,iEAAiE;IAE9E,SAAS,CAAC,OAAO,EAAE,OAAO;QACzB,6DAA6D;QAC7D,OAAO,OAAO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,CAAC,IAAI,CAAC,gCAAgC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;gBAClE,CAAC;qBAAM,CAAC;oBACP,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACpC,CAAC;YACF,CAAC;QACF,CAAC;QAED,0CAA0C;QAC1C,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;YACrD,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;gBACnD,QAAQ,CAAC,IAAI,CACZ,gBAAgB,IAAI,CAAC,WAAW,gCAAgC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC/F,CAAC;YACH,CAAC;QACF,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI orderInteraction extractor\n *\n * Extracts data from orderInteraction elements (ordering/ranking tasks)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\n\n/**\n * Order data extracted from orderInteraction elements\n */\nexport interface OrderData {\n\tchoices: Array<{ identifier: string; text: string; fixed?: boolean; classes?: string[] }>;\n\tshuffle: boolean;\n\tminChoices: number;\n\tmaxChoices: number;\n\torientation?: string;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI order interaction extractor\n * Handles orderInteraction elements with simpleChoice children\n */\nexport const standardOrderExtractor: ElementExtractor<OrderData> = {\n\tid: 'qti:order-interaction',\n\tname: 'QTI Standard Order Interaction',\n\tpriority: 10,\n\telementTypes: ['orderInteraction'],\n\tdescription: 'Extracts standard QTI orderInteraction (ordering/ranking tasks)',\n\n\tcanHandle(element, context) {\n\t\t// Standard QTI order interactions have simpleChoice children\n\t\treturn context.utils.hasChildWithTag(element, 'simpleChoice');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract choices\n\t\tconst simpleChoices = utils.getChildrenByTag(element, 'simpleChoice');\n\t\tconst choices = simpleChoices.map((choice) => {\n\t\t\tconst classes = utils.getClasses(choice);\n\t\t\tconst fixed = utils.getBooleanAttribute(choice, 'fixed');\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(choice, 'identifier', ''),\n\t\t\t\ttext: utils.getHtmlContent(choice),\n\t\t\t\t...(fixed ? { fixed } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract prompt\n\t\tconst promptElement = utils.querySelector(element, 'prompt');\n\t\tconst prompt = promptElement ? utils.getHtmlContent(promptElement) : null;\n\n\t\t// Extract attributes\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst orientation = utils.getAttribute(element, 'orientation', 'vertical');\n\t\tconst minChoices = utils.getNumberAttribute(element, 'minChoices', 0);\n\t\tconst maxChoices = utils.getNumberAttribute(element, 'maxChoices', 0);\n\n\t\treturn {\n\t\t\tchoices: maybeShuffle(choices, shuffle, context.shuffleRng),\n\t\t\tshuffle,\n\t\t\torientation,\n\t\t\tminChoices,\n\t\t\tmaxChoices,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate choices exist\n\t\tif (!data.choices || data.choices.length < 2) {\n\t\t\terrors.push('orderInteraction must have at least 2 choices');\n\t\t}\n\n\t\t// Warn if too many choices (difficult to order)\n\t\tif (data.choices && data.choices.length > 10) {\n\t\t\twarnings.push(\n\t\t\t\t`orderInteraction has ${data.choices.length} choices - this may be difficult for users to order`\n\t\t\t);\n\t\t}\n\n\t\t// Validate choice identifiers\n\t\tif (data.choices) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const choice of data.choices) {\n\t\t\t\tif (!choice.identifier) {\n\t\t\t\t\terrors.push('All choices must have an identifier');\n\t\t\t\t} else if (identifiers.has(choice.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate choice identifier: ${choice.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(choice.identifier);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate orientation (only if provided)\n\t\tif (data.orientation) {\n\t\t\tconst validOrientations = ['vertical', 'horizontal'];\n\t\t\tif (!validOrientations.includes(data.orientation)) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`orientation '${data.orientation}' is not standard (expected: ${validOrientations.join(', ')})`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
1
+ {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/order/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAcrD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAgC;IAClE,EAAE,EAAE,uBAAuB;IAC3B,IAAI,EAAE,gCAAgC;IACtC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,kBAAkB,CAAC;IAClC,WAAW,EAAE,iEAAiE;IAE9E,SAAS,CAAC,OAAO,EAAE,OAAO;QACzB,6DAA6D;QAC7D,OAAO,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,cAAc,CAAC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IAAI,CAAC,qCAAqC,CAAC,CAAC;gBACpD,CAAC;qBAAM,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC/C,MAAM,CAAC,IAAI,CAAC,gCAAgC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;gBAClE,CAAC;qBAAM,CAAC;oBACP,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACpC,CAAC;YACF,CAAC;QACF,CAAC;QAED,0CAA0C;QAC1C,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;YACrD,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;gBACnD,QAAQ,CAAC,IAAI,CACZ,gBAAgB,IAAI,CAAC,WAAW,gCAAgC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC/F,CAAC;YACH,CAAC;QACF,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI orderInteraction extractor\n *\n * Extracts data from orderInteraction elements (ordering/ranking tasks)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\n\n/**\n * Order data extracted from orderInteraction elements\n */\nexport interface OrderData {\n\tchoices: Array<{ identifier: string; text: string; fixed?: boolean; classes?: string[] }>;\n\tshuffle: boolean;\n\tminChoices: number;\n\tmaxChoices: number;\n\torientation?: string;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI order interaction extractor\n * Handles orderInteraction elements with simpleChoice children\n */\nexport const standardOrderExtractor: ElementExtractor<OrderData> = {\n\tid: 'qti:order-interaction',\n\tname: 'QTI Standard Order Interaction',\n\tpriority: 10,\n\telementTypes: ['orderInteraction'],\n\tdescription: 'Extracts standard QTI orderInteraction (ordering/ranking tasks)',\n\n\tcanHandle(element, context) {\n\t\t// Standard QTI order interactions have simpleChoice children\n\t\treturn context.utils.hasChildWithTag(element, 'simpleChoice');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract choices\n\t\tconst simpleChoices = utils.getChildrenByTag(element, 'simpleChoice');\n\t\tconst choices = simpleChoices.map((choice) => {\n\t\t\tconst classes = utils.getClasses(choice);\n\t\t\tconst fixed = utils.getBooleanAttribute(choice, 'fixed');\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(choice, 'identifier', ''),\n\t\t\t\ttext: utils.getHtmlContent(choice),\n\t\t\t\t...(fixed ? { fixed } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract prompt\n\t\tconst promptElement = utils.querySelector(element, 'prompt');\n\t\tconst prompt = promptElement ? utils.getHtmlContent(promptElement) : null;\n\n\t\t// Extract attributes\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst orientation = utils.getAttribute(element, 'orientation', 'vertical');\n\t\tconst minChoices = utils.getNumberAttribute(element, 'minChoices', 0);\n\t\tconst maxChoices = utils.getNumberAttribute(element, 'maxChoices', 0);\n\t\tconst interactionClasses = utils.getClasses(element);\n\n\t\treturn {\n\t\t\tchoices: maybeShuffle(choices, shuffle, context.shuffleRng),\n\t\t\tshuffle,\n\t\t\torientation,\n\t\t\tminChoices,\n\t\t\tmaxChoices,\n\t\t\tprompt,\n\t\t\t...(interactionClasses.length > 0 ? { interactionClasses } : {}),\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate choices exist\n\t\tif (!data.choices || data.choices.length < 2) {\n\t\t\terrors.push('orderInteraction must have at least 2 choices');\n\t\t}\n\n\t\t// Warn if too many choices (difficult to order)\n\t\tif (data.choices && data.choices.length > 10) {\n\t\t\twarnings.push(\n\t\t\t\t`orderInteraction has ${data.choices.length} choices - this may be difficult for users to order`\n\t\t\t);\n\t\t}\n\n\t\t// Validate choice identifiers\n\t\tif (data.choices) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const choice of data.choices) {\n\t\t\t\tif (!choice.identifier) {\n\t\t\t\t\terrors.push('All choices must have an identifier');\n\t\t\t\t} else if (identifiers.has(choice.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate choice identifier: ${choice.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(choice.identifier);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate orientation (only if provided)\n\t\tif (data.orientation) {\n\t\t\tconst validOrientations = ['vertical', 'horizontal'];\n\t\t\tif (!validOrientations.includes(data.orientation)) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`orientation '${data.orientation}' is not standard (expected: ${validOrientations.join(', ')})`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
@@ -46,21 +46,34 @@ export const portableCustomExtractor = {
46
46
  '';
47
47
  // --- Module paths from <qti-interaction-modules>/<qti-interaction-module> ---
48
48
  // These element names ARE in the standard QTI 3.0 element mapper so utils.querySelector works.
49
- let primaryPath = '';
50
- let fallbackPath;
49
+ // Every authored entry is kept; the entry module — the one whose id matches the
50
+ // customInteractionTypeIdentifier's tail, else the last one — fills primaryPath.
51
+ const modules = [];
52
+ let resolutionConfigPath;
51
53
  const modulesEl = findDescendant(pciElement, ['interactionmodules', 'qti-interaction-modules']);
52
54
  if (modulesEl) {
53
- const moduleEl = findDescendant(modulesEl, ['interactionmodule', 'qti-interaction-module']);
54
- if (moduleEl) {
55
- primaryPath =
56
- utils.getAttribute(moduleEl, 'primaryPath') ||
57
- utils.getAttribute(moduleEl, 'primary-path') || '';
58
- const fb = utils.getAttribute(moduleEl, 'fallbackPath') ||
59
- utils.getAttribute(moduleEl, 'fallback-path') || '';
60
- if (fb)
61
- fallbackPath = fb;
55
+ const configuration = utils.getAttribute(modulesEl, 'primaryConfiguration') ||
56
+ utils.getAttribute(modulesEl, 'primary-configuration') ||
57
+ '';
58
+ if (configuration)
59
+ resolutionConfigPath = configuration;
60
+ for (const moduleEl of findDescendants(modulesEl, ['interactionmodule', 'qti-interaction-module'])) {
61
+ const primary = utils.getAttribute(moduleEl, 'primaryPath') ||
62
+ utils.getAttribute(moduleEl, 'primary-path') ||
63
+ '';
64
+ const fallback = utils.getAttribute(moduleEl, 'fallbackPath') ||
65
+ utils.getAttribute(moduleEl, 'fallback-path') ||
66
+ '';
67
+ modules.push({
68
+ id: utils.getAttribute(moduleEl, 'id') || '',
69
+ primaryPath: primary,
70
+ ...(fallback ? { fallbackPath: fallback } : {}),
71
+ });
62
72
  }
63
73
  }
74
+ const entry = pickEntryModule(modules, customInteractionTypeIdentifier);
75
+ let primaryPath = entry?.primaryPath ?? '';
76
+ let fallbackPath = entry?.fallbackPath;
64
77
  // QTI 2.x PCI v1.0 embeds one or more script hooks in <pci:instance>.
65
78
  // The first external script identifies the resource a host resolver must map.
66
79
  const instanceEl = findDescendant(pciElement, ['instance']);
@@ -93,6 +106,8 @@ export const portableCustomExtractor = {
93
106
  customInteractionTypeIdentifier,
94
107
  primaryPath,
95
108
  fallbackPath,
109
+ modules,
110
+ ...(resolutionConfigPath ? { resolutionConfigPath } : {}),
96
111
  markup,
97
112
  config,
98
113
  };
@@ -112,6 +127,27 @@ export const portableCustomExtractor = {
112
127
  return { valid: errors.length === 0, errors: errors.length ? errors : undefined, warnings: warnings.length ? warnings : undefined };
113
128
  },
114
129
  };
130
+ /**
131
+ * The entry module: the one whose id matches the customInteractionTypeIdentifier's
132
+ * tail (`urn:...:pci:shading` → `shading`), else the last entry with a path, else
133
+ * the last entry. Only the id match is specified; the rest keeps single-module
134
+ * content authored without ids loading.
135
+ */
136
+ function pickEntryModule(modules, customInteractionTypeIdentifier) {
137
+ if (modules.length === 0)
138
+ return undefined;
139
+ const tail = customInteractionTypeIdentifier.split(':').pop()?.trim();
140
+ if (tail) {
141
+ const byId = modules.find((module) => module.id === tail);
142
+ if (byId)
143
+ return byId;
144
+ }
145
+ for (let index = modules.length - 1; index >= 0; index -= 1) {
146
+ if (modules[index].primaryPath)
147
+ return modules[index];
148
+ }
149
+ return modules[modules.length - 1];
150
+ }
115
151
  function localTagName(element) {
116
152
  const raw = element.rawTagName?.toLowerCase() ?? '';
117
153
  return raw.includes(':') ? raw.slice(raw.lastIndexOf(':') + 1) : raw;
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/portable-custom/extractor.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGhC;IACH,EAAE,EAAE,iCAAiC;IACrC,IAAI,EAAE,iCAAiC;IACvC,UAAU,EAAE,2BAA2B;IACvC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE;QACb,mBAAmB;QACnB,2BAA2B;QAC3B,iCAAiC;KACjC;IACD,WAAW,EAAE,mFAAmF;IAEhG,SAAS,CAAC,OAAO,EAAE,QAAQ;QAC1B,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CACN,GAAG,KAAK,2BAA2B;YACnC,GAAG,KAAK,iCAAiC;YACzC,CAAC,GAAG,KAAK,mBAAmB,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC,2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,SAAS,CAAC,CAAC;YACnE,KAAK,CAAC,SAAS,CAAC,CAAC;QAClB,CAAC;IACF,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,CAAC;IACf,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { ElementExtractor } from '../../extraction/types.js';\nimport type { ExtractedPci } from '../../pci/types.js';\n\n/**\n * Extractor for <qti-portable-custom-interaction> (QTI 3.0) and the\n * namespaced <pci:portableCustomInteraction> payload inside a QTI 2.x\n * <customInteraction> wrapper.\n *\n * Extracts the module paths, markup, and config properties needed by PciHost\n * to load and initialize the PCI JavaScript module.\n *\n * Priority 20 > standardCustomExtractor priority 10, so this runs first when\n * both would match the same element.\n */\nexport const portableCustomExtractor: ElementExtractor<\n\tExtractedPci,\n\t'portableCustomInteraction'\n> = {\n\tid: 'qti:portable-custom-interaction',\n\tname: 'QTI Portable Custom Interaction',\n\toutputType: 'portableCustomInteraction',\n\tpriority: 20,\n\telementTypes: [\n\t\t'customInteraction',\n\t\t'portableCustomInteraction',\n\t\t'qti-portable-custom-interaction',\n\t],\n\tdescription: 'Extracts QTI 2.x/3.0 portable custom interaction module paths, markup, and config',\n\n\tcanHandle(element, _context) {\n\t\tconst tag = localTagName(element);\n\t\treturn (\n\t\t\ttag === 'portablecustominteraction' ||\n\t\t\ttag === 'qti-portable-custom-interaction' ||\n\t\t\t(tag === 'custominteraction' && findDescendant(element, ['portablecustominteraction']) !== null)\n\t\t);\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\t\tconst outerTag = localTagName(element);\n\t\tconst pciElement =\n\t\t\touterTag === 'custominteraction'\n\t\t\t\t? findDescendant(element, ['portablecustominteraction'])\n\t\t\t\t: element;\n\n\t\tif (!pciElement) {\n\t\t\tthrow new Error('customInteraction does not contain a portableCustomInteraction payload');\n\t\t}\n\n\t\tconst responseIdentifier =\n\t\t\tutils.getAttribute(element, 'responseIdentifier') ||\n\t\t\tutils.getAttribute(element, 'response-identifier') ||\n\t\t\tcontext.responseId ||\n\t\t\t'';\n\n\t\tconst customInteractionTypeIdentifier =\n\t\t\tutils.getAttribute(pciElement, 'customInteractionTypeIdentifier') ||\n\t\t\tutils.getAttribute(pciElement, 'custom-interaction-type-identifier') ||\n\t\t\tutils.getAttribute(pciElement, 'customInteractionIdentifierType') ||\n\t\t\tutils.getAttribute(pciElement, 'custom-interaction-identifier-type') ||\n\t\t\t'';\n\n\t\t// --- Module paths from <qti-interaction-modules>/<qti-interaction-module> ---\n\t\t// These element names ARE in the standard QTI 3.0 element mapper so utils.querySelector works.\n\t\tlet primaryPath = '';\n\t\tlet fallbackPath: string | undefined;\n\n\t\tconst modulesEl = findDescendant(pciElement, ['interactionmodules', 'qti-interaction-modules']);\n\n\t\tif (modulesEl) {\n\t\t\tconst moduleEl = findDescendant(modulesEl, ['interactionmodule', 'qti-interaction-module']);\n\n\t\t\tif (moduleEl) {\n\t\t\t\tprimaryPath =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primaryPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primary-path') || '';\n\t\t\t\tconst fb =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallbackPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallback-path') || '';\n\t\t\t\tif (fb) fallbackPath = fb;\n\t\t\t}\n\t\t}\n\n\t\t// QTI 2.x PCI v1.0 embeds one or more script hooks in <pci:instance>.\n\t\t// The first external script identifies the resource a host resolver must map.\n\t\tconst instanceEl = findDescendant(pciElement, ['instance']);\n\t\tif (!primaryPath && instanceEl) {\n\t\t\tconst externalScript = findDescendants(instanceEl, ['script']).find((script) =>\n\t\t\t\tBoolean(utils.getAttribute(script, 'src'))\n\t\t\t);\n\t\t\tprimaryPath = externalScript ? utils.getAttribute(externalScript, 'src') : '';\n\t\t}\n\n\t\t// --- Markup from <qti-interaction-markup> ---\n\t\tconst markupEl = findDescendant(pciElement, ['interactionmarkup', 'qti-interaction-markup']);\n\n\t\t// sanitizeHtml removes script hooks from the QTI 2.x instance while preserving\n\t\t// the authored DOM scaffold that the resolved module initializes.\n\t\tconst markupSource = markupEl ?? instanceEl;\n\t\tconst markup = markupSource ? utils.getHtmlContent(markupSource) : '';\n\n\t\t// --- Config from <qti-pci-properties>/<qti-pci-property> ---\n\t\t// qti-pci-properties is NOT in the standard QTI 3.0 element mapper, so we use the\n\t\t// native node-html-parser querySelector (available as element.querySelector on the raw element).\n\t\tconst config: Record<string, string> = {};\n\n\t\tconst propsEl = findDescendant(pciElement, ['pciproperties', 'qti-pci-properties']);\n\n\t\tif (propsEl) {\n\t\t\tconst propEls = findDescendants(propsEl, ['pciproperty', 'qti-pci-property']);\n\t\t\tfor (const propEl of propEls) {\n\t\t\t\tconst key = utils.getAttribute(propEl, 'key') || utils.getAttribute(propEl, 'name') || '';\n\t\t\t\tconst value = utils.getAttribute(propEl, 'value') || (propEl.textContent ?? '').trim() || '';\n\t\t\t\tif (key) config[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tresponseIdentifier,\n\t\t\tcustomInteractionTypeIdentifier,\n\t\t\tprimaryPath,\n\t\t\tfallbackPath,\n\t\t\tmarkup,\n\t\t\tconfig,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\tif (!data.responseIdentifier) {\n\t\t\terrors.push('portableCustomInteraction is missing responseIdentifier');\n\t\t}\n\t\tif (!data.customInteractionTypeIdentifier) {\n\t\t\twarnings.push('portableCustomInteraction is missing customInteractionTypeIdentifier');\n\t\t}\n\t\tif (!data.primaryPath) {\n\t\t\terrors.push('portableCustomInteraction has no primaryPath in qti-interaction-modules');\n\t\t}\n\n\t\treturn { valid: errors.length === 0, errors: errors.length ? errors : undefined, warnings: warnings.length ? warnings : undefined };\n\t},\n};\n\ntype ExtractableElement = Parameters<typeof portableCustomExtractor.canHandle>[0];\n\nfunction localTagName(element: ExtractableElement): string {\n\tconst raw = element.rawTagName?.toLowerCase() ?? '';\n\treturn raw.includes(':') ? raw.slice(raw.lastIndexOf(':') + 1) : raw;\n}\n\nfunction findDescendant(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement | null {\n\treturn findDescendants(element, localNames)[0] ?? null;\n}\n\nfunction findDescendants(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement[] {\n\tconst expected = new Set(localNames.map((name) => name.toLowerCase()));\n\tconst matches: ExtractableElement[] = [];\n\tconst visit = (parent: ExtractableElement) => {\n\t\tfor (const child of parent.childNodes ?? []) {\n\t\t\tconst candidate = child as ExtractableElement;\n\t\t\tif (!candidate.rawTagName) continue;\n\t\t\tif (expected.has(localTagName(candidate))) matches.push(candidate);\n\t\t\tvisit(candidate);\n\t\t}\n\t};\n\tvisit(element);\n\treturn matches;\n}\n"]}
1
+ {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/portable-custom/extractor.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGhC;IACH,EAAE,EAAE,iCAAiC;IACrC,IAAI,EAAE,iCAAiC;IACvC,UAAU,EAAE,2BAA2B;IACvC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE;QACb,mBAAmB;QACnB,2BAA2B;QAC3B,iCAAiC;KACjC;IACD,WAAW,EAAE,mFAAmF;IAEhG,SAAS,CAAC,OAAO,EAAE,QAAQ;QAC1B,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CACN,GAAG,KAAK,2BAA2B;YACnC,GAAG,KAAK,iCAAiC;YACzC,CAAC,GAAG,KAAK,mBAAmB,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC,2BAA2B,CAAC,CAAC,KAAK,IAAI,CAAC,CAChG,CAAC;IACH,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAA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,IAAI,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;gBAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnE,KAAK,CAAC,SAAS,CAAC,CAAC;QAClB,CAAC;IACF,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,CAAC;IACf,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { ElementExtractor } from '../../extraction/types.js';\nimport type { ExtractedPci } from '../../pci/types.js';\n\n/**\n * Extractor for <qti-portable-custom-interaction> (QTI 3.0) and the\n * namespaced <pci:portableCustomInteraction> payload inside a QTI 2.x\n * <customInteraction> wrapper.\n *\n * Extracts the module paths, markup, and config properties needed by PciHost\n * to load and initialize the PCI JavaScript module.\n *\n * Priority 20 > standardCustomExtractor priority 10, so this runs first when\n * both would match the same element.\n */\nexport const portableCustomExtractor: ElementExtractor<\n\tExtractedPci,\n\t'portableCustomInteraction'\n> = {\n\tid: 'qti:portable-custom-interaction',\n\tname: 'QTI Portable Custom Interaction',\n\toutputType: 'portableCustomInteraction',\n\tpriority: 20,\n\telementTypes: [\n\t\t'customInteraction',\n\t\t'portableCustomInteraction',\n\t\t'qti-portable-custom-interaction',\n\t],\n\tdescription: 'Extracts QTI 2.x/3.0 portable custom interaction module paths, markup, and config',\n\n\tcanHandle(element, _context) {\n\t\tconst tag = localTagName(element);\n\t\treturn (\n\t\t\ttag === 'portablecustominteraction' ||\n\t\t\ttag === 'qti-portable-custom-interaction' ||\n\t\t\t(tag === 'custominteraction' && findDescendant(element, ['portablecustominteraction']) !== null)\n\t\t);\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\t\tconst outerTag = localTagName(element);\n\t\tconst pciElement =\n\t\t\touterTag === 'custominteraction'\n\t\t\t\t? findDescendant(element, ['portablecustominteraction'])\n\t\t\t\t: element;\n\n\t\tif (!pciElement) {\n\t\t\tthrow new Error('customInteraction does not contain a portableCustomInteraction payload');\n\t\t}\n\n\t\tconst responseIdentifier =\n\t\t\tutils.getAttribute(element, 'responseIdentifier') ||\n\t\t\tutils.getAttribute(element, 'response-identifier') ||\n\t\t\tcontext.responseId ||\n\t\t\t'';\n\n\t\tconst customInteractionTypeIdentifier =\n\t\t\tutils.getAttribute(pciElement, 'customInteractionTypeIdentifier') ||\n\t\t\tutils.getAttribute(pciElement, 'custom-interaction-type-identifier') ||\n\t\t\tutils.getAttribute(pciElement, 'customInteractionIdentifierType') ||\n\t\t\tutils.getAttribute(pciElement, 'custom-interaction-identifier-type') ||\n\t\t\t'';\n\n\t\t// --- Module paths from <qti-interaction-modules>/<qti-interaction-module> ---\n\t\t// These element names ARE in the standard QTI 3.0 element mapper so utils.querySelector works.\n\t\t// Every authored entry is kept; the entry module — the one whose id matches the\n\t\t// customInteractionTypeIdentifier's tail, else the last one — fills primaryPath.\n\t\tconst modules: ExtractedPci['modules'] = [];\n\t\tlet resolutionConfigPath: string | undefined;\n\n\t\tconst modulesEl = findDescendant(pciElement, ['interactionmodules', 'qti-interaction-modules']);\n\n\t\tif (modulesEl) {\n\t\t\tconst configuration =\n\t\t\t\tutils.getAttribute(modulesEl, 'primaryConfiguration') ||\n\t\t\t\tutils.getAttribute(modulesEl, 'primary-configuration') ||\n\t\t\t\t'';\n\t\t\tif (configuration) resolutionConfigPath = configuration;\n\n\t\t\tfor (const moduleEl of findDescendants(modulesEl, ['interactionmodule', 'qti-interaction-module'])) {\n\t\t\t\tconst primary =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primaryPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primary-path') ||\n\t\t\t\t\t'';\n\t\t\t\tconst fallback =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallbackPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallback-path') ||\n\t\t\t\t\t'';\n\t\t\t\tmodules.push({\n\t\t\t\t\tid: utils.getAttribute(moduleEl, 'id') || '',\n\t\t\t\t\tprimaryPath: primary,\n\t\t\t\t\t...(fallback ? { fallbackPath: fallback } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst entry = pickEntryModule(modules, customInteractionTypeIdentifier);\n\t\tlet primaryPath = entry?.primaryPath ?? '';\n\t\tlet fallbackPath = entry?.fallbackPath;\n\n\t\t// QTI 2.x PCI v1.0 embeds one or more script hooks in <pci:instance>.\n\t\t// The first external script identifies the resource a host resolver must map.\n\t\tconst instanceEl = findDescendant(pciElement, ['instance']);\n\t\tif (!primaryPath && instanceEl) {\n\t\t\tconst externalScript = findDescendants(instanceEl, ['script']).find((script) =>\n\t\t\t\tBoolean(utils.getAttribute(script, 'src'))\n\t\t\t);\n\t\t\tprimaryPath = externalScript ? utils.getAttribute(externalScript, 'src') : '';\n\t\t}\n\n\t\t// --- Markup from <qti-interaction-markup> ---\n\t\tconst markupEl = findDescendant(pciElement, ['interactionmarkup', 'qti-interaction-markup']);\n\n\t\t// sanitizeHtml removes script hooks from the QTI 2.x instance while preserving\n\t\t// the authored DOM scaffold that the resolved module initializes.\n\t\tconst markupSource = markupEl ?? instanceEl;\n\t\tconst markup = markupSource ? utils.getHtmlContent(markupSource) : '';\n\n\t\t// --- Config from <qti-pci-properties>/<qti-pci-property> ---\n\t\t// qti-pci-properties is NOT in the standard QTI 3.0 element mapper, so we use the\n\t\t// native node-html-parser querySelector (available as element.querySelector on the raw element).\n\t\tconst config: Record<string, string> = {};\n\n\t\tconst propsEl = findDescendant(pciElement, ['pciproperties', 'qti-pci-properties']);\n\n\t\tif (propsEl) {\n\t\t\tconst propEls = findDescendants(propsEl, ['pciproperty', 'qti-pci-property']);\n\t\t\tfor (const propEl of propEls) {\n\t\t\t\tconst key = utils.getAttribute(propEl, 'key') || utils.getAttribute(propEl, 'name') || '';\n\t\t\t\tconst value = utils.getAttribute(propEl, 'value') || (propEl.textContent ?? '').trim() || '';\n\t\t\t\tif (key) config[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tresponseIdentifier,\n\t\t\tcustomInteractionTypeIdentifier,\n\t\t\tprimaryPath,\n\t\t\tfallbackPath,\n\t\t\tmodules,\n\t\t\t...(resolutionConfigPath ? { resolutionConfigPath } : {}),\n\t\t\tmarkup,\n\t\t\tconfig,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\tif (!data.responseIdentifier) {\n\t\t\terrors.push('portableCustomInteraction is missing responseIdentifier');\n\t\t}\n\t\tif (!data.customInteractionTypeIdentifier) {\n\t\t\twarnings.push('portableCustomInteraction is missing customInteractionTypeIdentifier');\n\t\t}\n\t\tif (!data.primaryPath) {\n\t\t\terrors.push('portableCustomInteraction has no primaryPath in qti-interaction-modules');\n\t\t}\n\n\t\treturn { valid: errors.length === 0, errors: errors.length ? errors : undefined, warnings: warnings.length ? warnings : undefined };\n\t},\n};\n\ntype ExtractableElement = Parameters<typeof portableCustomExtractor.canHandle>[0];\n\n/**\n * The entry module: the one whose id matches the customInteractionTypeIdentifier's\n * tail (`urn:...:pci:shading` → `shading`), else the last entry with a path, else\n * the last entry. Only the id match is specified; the rest keeps single-module\n * content authored without ids loading.\n */\nfunction pickEntryModule(\n\tmodules: ExtractedPci['modules'],\n\tcustomInteractionTypeIdentifier: string\n): ExtractedPci['modules'][number] | undefined {\n\tif (modules.length === 0) return undefined;\n\tconst tail = customInteractionTypeIdentifier.split(':').pop()?.trim();\n\tif (tail) {\n\t\tconst byId = modules.find((module) => module.id === tail);\n\t\tif (byId) return byId;\n\t}\n\tfor (let index = modules.length - 1; index >= 0; index -= 1) {\n\t\tif (modules[index].primaryPath) return modules[index];\n\t}\n\treturn modules[modules.length - 1];\n}\n\nfunction localTagName(element: ExtractableElement): string {\n\tconst raw = element.rawTagName?.toLowerCase() ?? '';\n\treturn raw.includes(':') ? raw.slice(raw.lastIndexOf(':') + 1) : raw;\n}\n\nfunction findDescendant(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement | null {\n\treturn findDescendants(element, localNames)[0] ?? null;\n}\n\nfunction findDescendants(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement[] {\n\tconst expected = new Set(localNames.map((name) => name.toLowerCase()));\n\tconst matches: ExtractableElement[] = [];\n\tconst visit = (parent: ExtractableElement) => {\n\t\tfor (const child of parent.childNodes ?? []) {\n\t\t\tconst candidate = child as ExtractableElement;\n\t\t\tif (!candidate.rawTagName) continue;\n\t\t\tif (expected.has(localTagName(candidate))) matches.push(candidate);\n\t\t\tvisit(candidate);\n\t\t}\n\t};\n\tvisit(element);\n\treturn matches;\n}\n"]}