@pie-qti/item-player 0.1.8 → 0.1.10

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 (199) hide show
  1. package/README.md +17 -0
  2. package/dist/catalog/applyGlossaryTriggers.d.ts +13 -2
  3. package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
  4. package/dist/catalog/glossaryAction.d.ts +4 -2
  5. package/dist/catalog/glossaryAction.d.ts.map +1 -1
  6. package/dist/components/utils/index.d.ts +1 -2
  7. package/dist/components/utils/index.d.ts.map +1 -1
  8. package/dist/components/utils/index.js +1 -2
  9. package/dist/core/ComponentRegistry.d.ts +10 -1
  10. package/dist/core/ComponentRegistry.d.ts.map +1 -1
  11. package/dist/core/ComponentRegistry.js +42 -1
  12. package/dist/core/Player.d.ts +10 -2
  13. package/dist/core/Player.d.ts.map +1 -1
  14. package/dist/core/Player.js +54 -46
  15. package/dist/document/AssessmentItemDocument.d.ts +1 -1
  16. package/dist/element.d.ts +15 -0
  17. package/dist/element.js +1921 -1785
  18. package/dist/element.js.map +1 -1
  19. package/dist/extraction/ExtractionRegistry.d.ts +1 -1
  20. package/dist/extraction/createContext.d.ts +1 -1
  21. package/dist/extraction/index.d.ts +2 -2
  22. package/dist/extraction/index.d.ts.map +1 -1
  23. package/dist/extraction/index.js +1 -1
  24. package/dist/extraction/interactionExtractionPipeline.d.ts +1 -1
  25. package/dist/extraction/interactionSecurity.d.ts +1 -1
  26. package/dist/extraction/types.d.ts +1 -1
  27. package/dist/presentation/itemPresentationPlan.d.ts +54 -0
  28. package/dist/presentation/itemPresentationPlan.d.ts.map +1 -0
  29. package/dist/presentation/itemPresentationPlan.js +98 -0
  30. package/dist/types/index.d.ts +17 -2
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/index.js +0 -3
  33. package/dist/web-components/QTIInteractionBase.d.ts +1 -1
  34. package/dist/web-components/QTIInteractionElement.d.ts +1 -1
  35. package/package.json +10 -12
  36. package/src/__tests__/catalog.test.ts +0 -267
  37. package/src/__tests__/fixtures/pci/echo-pci.js +0 -49
  38. package/src/__tests__/pci.test.ts +0 -353
  39. package/src/__tests__/qti3-attribute-extraction.test.ts +0 -174
  40. package/src/__tests__/qti3-debug.test.ts +0 -140
  41. package/src/__tests__/qti3-extraction.test.ts +0 -309
  42. package/src/catalog/applyGlossaryTriggers.ts +0 -372
  43. package/src/catalog/catalogExtractor.ts +0 -130
  44. package/src/catalog/catalogLookup.ts +0 -53
  45. package/src/catalog/glossaryAction.ts +0 -38
  46. package/src/catalog/types.ts +0 -37
  47. package/src/components/ItemBody.svelte +0 -363
  48. package/src/components/ItemPlayer.svelte +0 -163
  49. package/src/components/ModalFeedbackDisplay.svelte +0 -97
  50. package/src/components/actions/typesetAction.ts +0 -74
  51. package/src/components/index.ts +0 -22
  52. package/src/components/utils/assignProps.ts +0 -2
  53. package/src/components/utils/feedbackUtils.ts +0 -140
  54. package/src/components/utils/index.ts +0 -13
  55. package/src/components/utils/stimulusRender.ts +0 -93
  56. package/src/components/utils/stylesheetRender.ts +0 -58
  57. package/src/core/ComponentRegistry.ts +0 -248
  58. package/src/core/Player.ts +0 -1618
  59. package/src/core/Plugin.ts +0 -123
  60. package/src/core/PluginManager.ts +0 -182
  61. package/src/core/constants.ts +0 -117
  62. package/src/core/declarations.ts +0 -171
  63. package/src/core/parsingLimits.ts +0 -62
  64. package/src/core/random.ts +0 -24
  65. package/src/core/rolePolicy.ts +0 -34
  66. package/src/core/sanitizer.ts +0 -305
  67. package/src/core/trustedTypes.ts +0 -63
  68. package/src/core/urlPolicy.ts +0 -98
  69. package/src/document/AssessmentItemDocument.ts +0 -247
  70. package/src/element.ts +0 -128
  71. package/src/extensions/MathLiveEditor.ts +0 -313
  72. package/src/extraction/ExtractionRegistry.ts +0 -335
  73. package/src/extraction/createContext.ts +0 -52
  74. package/src/extraction/extractors/associateExtractor.ts +0 -1
  75. package/src/extraction/extractors/choiceExtractor.ts +0 -1
  76. package/src/extraction/extractors/conformance-qti3-advanced.test.ts +0 -239
  77. package/src/extraction/extractors/conformance-qti3-basic.test.ts +0 -82
  78. package/src/extraction/extractors/conformance.test.ts +0 -208
  79. package/src/extraction/extractors/customExtractor.ts +0 -1
  80. package/src/extraction/extractors/drawingExtractor.ts +0 -1
  81. package/src/extraction/extractors/endAttemptExtractor.ts +0 -1
  82. package/src/extraction/extractors/extendedTextExtractor.ts +0 -1
  83. package/src/extraction/extractors/gapMatchExtractor.ts +0 -1
  84. package/src/extraction/extractors/graphicAssociateExtractor.ts +0 -1
  85. package/src/extraction/extractors/graphicGapMatchExtractor.ts +0 -1
  86. package/src/extraction/extractors/graphicOrderExtractor.ts +0 -1
  87. package/src/extraction/extractors/hotspotExtractor.ts +0 -1
  88. package/src/extraction/extractors/hottextExtractor.ts +0 -1
  89. package/src/extraction/extractors/index.ts +0 -9
  90. package/src/extraction/extractors/inlineChoiceExtractor.ts +0 -1
  91. package/src/extraction/extractors/matchExtractor.ts +0 -1
  92. package/src/extraction/extractors/mediaExtractor.ts +0 -1
  93. package/src/extraction/extractors/orderExtractor.ts +0 -1
  94. package/src/extraction/extractors/portableCustomExtractor.ts +0 -1
  95. package/src/extraction/extractors/positionObjectExtractor.ts +0 -1
  96. package/src/extraction/extractors/selectPointExtractor.ts +0 -1
  97. package/src/extraction/extractors/sliderExtractor.ts +0 -1
  98. package/src/extraction/extractors/textEntryExtractor.ts +0 -1
  99. package/src/extraction/extractors/uploadExtractor.ts +0 -1
  100. package/src/extraction/index.ts +0 -108
  101. package/src/extraction/interactionExtractionPipeline.ts +0 -70
  102. package/src/extraction/interactionSecurity.ts +0 -60
  103. package/src/extraction/types.ts +0 -246
  104. package/src/extraction/utils.ts +0 -243
  105. package/src/iframe/IFramePlayerHost.ts +0 -265
  106. package/src/iframe/index.ts +0 -11
  107. package/src/iframe/protocol.ts +0 -137
  108. package/src/index.ts +0 -101
  109. package/src/interactions/associate/extractor.ts +0 -133
  110. package/src/interactions/associate/index.ts +0 -2
  111. package/src/interactions/associate/types.ts +0 -1
  112. package/src/interactions/choice/extractor.ts +0 -121
  113. package/src/interactions/choice/index.ts +0 -2
  114. package/src/interactions/choice/types.ts +0 -1
  115. package/src/interactions/custom/extractor.ts +0 -72
  116. package/src/interactions/custom/index.ts +0 -2
  117. package/src/interactions/custom/types.ts +0 -1
  118. package/src/interactions/drawing/extractor.ts +0 -113
  119. package/src/interactions/drawing/index.ts +0 -2
  120. package/src/interactions/drawing/types.ts +0 -1
  121. package/src/interactions/end-attempt/extractor.ts +0 -74
  122. package/src/interactions/end-attempt/index.ts +0 -2
  123. package/src/interactions/end-attempt/types.ts +0 -1
  124. package/src/interactions/extended-text/extractor.ts +0 -92
  125. package/src/interactions/extended-text/index.ts +0 -2
  126. package/src/interactions/extended-text/types.ts +0 -1
  127. package/src/interactions/gap-match/extractor.ts +0 -193
  128. package/src/interactions/gap-match/index.ts +0 -2
  129. package/src/interactions/gap-match/types.ts +0 -1
  130. package/src/interactions/graphic-associate/extractor.ts +0 -192
  131. package/src/interactions/graphic-associate/index.ts +0 -2
  132. package/src/interactions/graphic-associate/types.ts +0 -1
  133. package/src/interactions/graphic-gap-match/extractor.ts +0 -257
  134. package/src/interactions/graphic-gap-match/index.ts +0 -2
  135. package/src/interactions/graphic-gap-match/types.ts +0 -1
  136. package/src/interactions/graphic-order/extractor.ts +0 -162
  137. package/src/interactions/graphic-order/index.ts +0 -2
  138. package/src/interactions/graphic-order/types.ts +0 -1
  139. package/src/interactions/hotspot/extractor.ts +0 -208
  140. package/src/interactions/hotspot/index.ts +0 -2
  141. package/src/interactions/hotspot/types.ts +0 -1
  142. package/src/interactions/hottext/extractor.ts +0 -163
  143. package/src/interactions/hottext/index.ts +0 -2
  144. package/src/interactions/hottext/types.ts +0 -1
  145. package/src/interactions/index.ts +0 -52
  146. package/src/interactions/inline/index.ts +0 -1
  147. package/src/interactions/inline/render-plan.ts +0 -105
  148. package/src/interactions/inline-choice/InlineChoice.svelte +0 -57
  149. package/src/interactions/inline-choice/extractor.ts +0 -105
  150. package/src/interactions/inline-choice/index.ts +0 -2
  151. package/src/interactions/inline-choice/types.ts +0 -1
  152. package/src/interactions/match/extractor.ts +0 -187
  153. package/src/interactions/match/index.ts +0 -2
  154. package/src/interactions/match/types.ts +0 -1
  155. package/src/interactions/media/extractor.ts +0 -168
  156. package/src/interactions/media/index.ts +0 -2
  157. package/src/interactions/media/types.ts +0 -1
  158. package/src/interactions/modules.ts +0 -111
  159. package/src/interactions/order/extractor.ts +0 -120
  160. package/src/interactions/order/index.ts +0 -2
  161. package/src/interactions/order/types.ts +0 -1
  162. package/src/interactions/portable-custom/extractor.ts +0 -122
  163. package/src/interactions/portable-custom/index.ts +0 -2
  164. package/src/interactions/portable-custom/types.ts +0 -1
  165. package/src/interactions/position-object/extractor.ts +0 -243
  166. package/src/interactions/position-object/index.ts +0 -2
  167. package/src/interactions/position-object/types.ts +0 -1
  168. package/src/interactions/select-point/extractor.ts +0 -143
  169. package/src/interactions/select-point/index.ts +0 -2
  170. package/src/interactions/select-point/types.ts +0 -1
  171. package/src/interactions/shared/index.ts +0 -1
  172. package/src/interactions/shared/types.ts +0 -430
  173. package/src/interactions/slider/extractor.ts +0 -102
  174. package/src/interactions/slider/index.ts +0 -2
  175. package/src/interactions/slider/types.ts +0 -1
  176. package/src/interactions/text-entry/InlineTextEntry.svelte +0 -75
  177. package/src/interactions/text-entry/extractor.ts +0 -79
  178. package/src/interactions/text-entry/index.ts +0 -2
  179. package/src/interactions/text-entry/types.ts +0 -1
  180. package/src/interactions/upload/extractor.ts +0 -81
  181. package/src/interactions/upload/index.ts +0 -2
  182. package/src/interactions/upload/types.ts +0 -1
  183. package/src/pci/PciHost.ts +0 -138
  184. package/src/pci/types.ts +0 -70
  185. package/src/pnp/applyPnp.ts +0 -29
  186. package/src/pnp/parsePnpXml.ts +0 -215
  187. package/src/pnp/types.ts +0 -75
  188. package/src/server.ts +0 -14
  189. package/src/types/index.ts +0 -388
  190. package/src/types/interactions.ts +0 -8
  191. package/src/types/responseValidation.ts +0 -29
  192. package/src/types/xmldom.d.ts +0 -12
  193. package/src/utils/PerformanceMonitor.ts +0 -335
  194. package/src/utils/drawingUtils.ts +0 -73
  195. package/src/utils/responseUtils.ts +0 -51
  196. package/src/utils/touchDragHelper.ts +0 -1
  197. package/src/web-components/QTIInteractionBase.ts +0 -303
  198. package/src/web-components/QTIInteractionElement.ts +0 -125
  199. package/src/web-components/index.ts +0 -22
@@ -1,82 +0,0 @@
1
- import { describe, it, expect } from 'bun:test';
2
- import { Player } from '../../core/Player.js';
3
-
4
- const qti3Item = (identifier: string, body: string, declarations = '') => `<?xml version="1.0" encoding="UTF-8"?>
5
- <qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
6
- identifier="${identifier}" title="${identifier}" adaptive="false" time-dependent="false">
7
- ${declarations}
8
- <qti-item-body>${body}</qti-item-body>
9
- </qti-assessment-item>`;
10
-
11
- describe('QTI 3.0 Basic/Advanced Shared Vocabulary clean-room extraction', () => {
12
- it('Q2: extracts qti-labels-none and qti-orientation-horizontal from choice interaction', () => {
13
- const xml = qti3Item(
14
- 'qti3-choice-sv',
15
- `<qti-choice-interaction response-identifier="RESPONSE" max-choices="1"
16
- class="qti-labels-none qti-orientation-horizontal qti-choices-stacking-2">
17
- <qti-prompt>Select the renewable energy source.</qti-prompt>
18
- <qti-simple-choice identifier="solar">Solar</qti-simple-choice>
19
- <qti-simple-choice identifier="coal">Coal</qti-simple-choice>
20
- </qti-choice-interaction>`,
21
- '<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
22
- );
23
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
24
-
25
- expect(interaction.type).toBe('choiceInteraction');
26
- expect(interaction.maxChoices).toBe(1);
27
- expect(interaction.interactionClasses).toContain('qti-labels-none');
28
- expect(interaction.interactionClasses).toContain('qti-orientation-horizontal');
29
- expect(interaction.interactionClasses).toContain('qti-choices-stacking-2');
30
- });
31
-
32
- it('Q2: treats max-choices="0" as unlimited for multiple cardinality', () => {
33
- const xml = qti3Item(
34
- 'qti3-choice-multiple',
35
- `<qti-choice-interaction response-identifier="RESPONSE" max-choices="0">
36
- <qti-simple-choice identifier="oxygen">Oxygen</qti-simple-choice>
37
- <qti-simple-choice identifier="nitrogen">Nitrogen</qti-simple-choice>
38
- <qti-simple-choice identifier="water">Water vapor</qti-simple-choice>
39
- </qti-choice-interaction>`,
40
- '<qti-response-declaration identifier="RESPONSE" cardinality="multiple" base-type="identifier"/>'
41
- );
42
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
43
-
44
- expect(interaction.type).toBe('choiceInteraction');
45
- expect(interaction.maxChoices).toBe(0);
46
- expect(interaction.choices).toHaveLength(3);
47
- });
48
-
49
- it('Q5: extracts qti-height-lines and qti-counter classes from extended text', () => {
50
- const xml = qti3Item(
51
- 'qti3-extended-text-sv',
52
- `<qti-extended-text-interaction response-identifier="RESPONSE"
53
- class="qti-height-lines-6 qti-counter-down"
54
- expected-lines="6" expected-length="600"/>`,
55
- '<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="string"/>'
56
- );
57
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
58
-
59
- expect(interaction.type).toBe('extendedTextInteraction');
60
- expect(interaction.expectedLines).toBe(6);
61
- expect(interaction.interactionClasses).toContain('qti-height-lines-6');
62
- expect(interaction.interactionClasses).toContain('qti-counter-down');
63
- });
64
-
65
- it('Q20: extracts qti-input-width and data-patternmask-message from text entry', () => {
66
- const xml = qti3Item(
67
- 'qti3-text-entry-sv',
68
- `<p>Enter the three-letter code:
69
- <qti-text-entry-interaction response-identifier="RESPONSE"
70
- class="qti-input-width-6"
71
- pattern-mask="[A-Z]{3}"
72
- data-patternmask-message="Use exactly three uppercase letters."/>
73
- </p>`,
74
- '<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="string"/>'
75
- );
76
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
77
-
78
- expect(interaction.type).toBe('textEntryInteraction');
79
- expect(interaction.interactionClasses).toContain('qti-input-width-6');
80
- expect(interaction.patternMaskMessage).toBe('Use exactly three uppercase letters.');
81
- });
82
- });
@@ -1,208 +0,0 @@
1
- import { describe, it, expect } from 'bun:test';
2
- import { Player } from '../../core/Player.js';
3
-
4
- const wrapItem = (identifier: string, body: string, declarations = '') => `<?xml version="1.0" encoding="UTF-8"?>
5
- <assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2"
6
- identifier="${identifier}" title="${identifier}" adaptive="false" timeDependent="false">
7
- ${declarations}
8
- <itemBody>${body}</itemBody>
9
- </assessmentItem>`;
10
-
11
- describe('QTI 2.2 Advanced clean-room extraction coverage', () => {
12
- it('Q2 Advanced: extracts a choiceInteraction with bounded single selection', () => {
13
- const xml = wrapItem(
14
- 'q2-advanced-choice',
15
- `<choiceInteraction responseIdentifier="RESPONSE" shuffle="false" maxChoices="1">
16
- <prompt>Select the measurement tool for temperature.</prompt>
17
- <simpleChoice identifier="thermometer">Thermometer</simpleChoice>
18
- <simpleChoice identifier="ruler">Ruler</simpleChoice>
19
- </choiceInteraction>`,
20
- '<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>'
21
- );
22
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
23
-
24
- expect(interaction.type).toBe('choiceInteraction');
25
- expect(interaction.responseId).toBe('RESPONSE');
26
- expect(interaction.maxChoices).toBe(1);
27
- expect(interaction.choices.map((c: any) => c.identifier)).toEqual(['thermometer', 'ruler']);
28
- });
29
-
30
- it('Q6: extracts gap choices, gaps, and unlimited matchMax values', () => {
31
- const xml = wrapItem(
32
- 'q6-gap-match',
33
- `<p>Complete the energy chain:
34
- <gapMatchInteraction responseIdentifier="RESPONSE">
35
- <prompt>Drag each source into the correct gap.</prompt>
36
- <gapText identifier="sunlight" matchMax="0">sunlight</gapText>
37
- <gapText identifier="plants" matchMax="1">plants</gapText>
38
- <blockquote>
39
- <gap identifier="gap_1"/> is captured by <gap identifier="gap_2"/>.
40
- </blockquote>
41
- </gapMatchInteraction>
42
- </p>`,
43
- '<responseDeclaration identifier="RESPONSE" cardinality="multiple" baseType="directedPair"/>'
44
- );
45
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
46
-
47
- expect(interaction.type).toBe('gapMatchInteraction');
48
- expect(interaction.gapTexts).toHaveLength(2);
49
- expect(interaction.gapTexts.find((g: any) => g.identifier === 'sunlight')?.matchMax).toBe(0);
50
- expect(interaction.gaps).toEqual(['gap_1', 'gap_2']);
51
- });
52
-
53
- it('Q8: extracts graphic gap match background, text/image choices, and hotspots', () => {
54
- const xml = wrapItem(
55
- 'q8-graphic-gap-match',
56
- `<graphicGapMatchInteraction responseIdentifier="RESPONSE">
57
- <prompt>Label the parts of the diagram.</prompt>
58
- <object data="images/cell-diagram.svg" type="image/svg+xml" width="400" height="300">Cell diagram</object>
59
- <gapText identifier="nucleus" matchMax="1">Nucleus</gapText>
60
- <gapImg identifier="membrane" matchMax="1" src="images/membrane-label.svg"/>
61
- <associableHotspot identifier="A" matchMax="1" shape="rect" coords="20,30,120,90"/>
62
- <associableHotspot identifier="B" matchMax="1" shape="circle" coords="250,150,35"/>
63
- </graphicGapMatchInteraction>`,
64
- '<responseDeclaration identifier="RESPONSE" cardinality="multiple" baseType="directedPair"/>'
65
- );
66
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
67
-
68
- expect(interaction.type).toBe('graphicGapMatchInteraction');
69
- expect(interaction.imageData.src).toBe('images/cell-diagram.svg');
70
- expect(interaction.imageData.width).toBe(400);
71
- expect(interaction.gapTexts).toHaveLength(1);
72
- expect(interaction.gapImages).toHaveLength(1);
73
- expect(interaction.hotspots.map((h: any) => h.shape)).toEqual(['rect', 'circle']);
74
- });
75
-
76
- it('Q10: extracts hotspot choices with single and multiple cardinality metadata', () => {
77
- const xml = wrapItem(
78
- 'q10-hotspot',
79
- `<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="0" minChoices="1">
80
- <prompt>Select all shaded regions.</prompt>
81
- <object data="images/region-map.svg" type="image/svg+xml" width="320" height="240">Region map</object>
82
- <hotspotChoice identifier="north" shape="rect" coords="10,10,110,80"/>
83
- <hotspotChoice identifier="south" shape="poly" coords="20,160,90,150,110,210,30,220"/>
84
- </hotspotInteraction>`,
85
- '<responseDeclaration identifier="RESPONSE" cardinality="multiple" baseType="identifier"/>'
86
- );
87
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
88
-
89
- expect(interaction.type).toBe('hotspotInteraction');
90
- expect(interaction.maxChoices).toBe(0);
91
- expect(interaction.minChoices).toBe(1);
92
- expect(interaction.hotspotChoices.map((h: any) => h.shape)).toEqual(['rect', 'poly']);
93
- });
94
-
95
- it('Q11: extracts single and multiple hottext choices', () => {
96
- const xml = wrapItem(
97
- 'q11-hottext',
98
- `<hottextInteraction responseIdentifier="RESPONSE" maxChoices="2">
99
- <prompt>Select the two facts.</prompt>
100
- <p><hottext identifier="fact_1">Water freezes at 0 degrees Celsius.</hottext></p>
101
- <p><hottext identifier="opinion_1">Winter is the best season.</hottext></p>
102
- <p><hottext identifier="fact_2">The Moon orbits Earth.</hottext></p>
103
- </hottextInteraction>`,
104
- '<responseDeclaration identifier="RESPONSE" cardinality="multiple" baseType="identifier"/>'
105
- );
106
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
107
-
108
- expect(interaction.type).toBe('hottextInteraction');
109
- expect(interaction.maxChoices).toBe(2);
110
- expect(interaction.hottextChoices.map((h: any) => h.identifier)).toEqual([
111
- 'fact_1',
112
- 'opinion_1',
113
- 'fact_2',
114
- ]);
115
- });
116
-
117
- it('Q12: extracts inline choices and leaves placeholders in item body HTML', () => {
118
- const xml = wrapItem(
119
- 'q12-inline-choice',
120
- `<p>A triangle with three equal sides is
121
- <inlineChoiceInteraction responseIdentifier="RESPONSE" shuffle="false">
122
- <inlineChoice identifier="equilateral">equilateral</inlineChoice>
123
- <inlineChoice identifier="scalene">scalene</inlineChoice>
124
- </inlineChoiceInteraction>.
125
- </p>`,
126
- '<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>'
127
- );
128
- const player = new Player({ itemXml: xml });
129
- const interaction = player.getInteractionData()[0] as any;
130
-
131
- expect(interaction.type).toBe('inlineChoiceInteraction');
132
- expect(interaction.choices.map((c: any) => c.identifier)).toEqual(['equilateral', 'scalene']);
133
- expect(player.getItemBodyHtml()).toContain('inlineChoiceInteraction');
134
- });
135
-
136
- it('Q13: extracts match sets and maxAssociations', () => {
137
- const xml = wrapItem(
138
- 'q13-match',
139
- `<matchInteraction responseIdentifier="RESPONSE" shuffle="false" maxAssociations="3">
140
- <prompt>Match each process to its description.</prompt>
141
- <simpleMatchSet>
142
- <simpleAssociableChoice identifier="evaporation" matchMax="1">Evaporation</simpleAssociableChoice>
143
- <simpleAssociableChoice identifier="condensation" matchMax="1">Condensation</simpleAssociableChoice>
144
- </simpleMatchSet>
145
- <simpleMatchSet>
146
- <simpleAssociableChoice identifier="liquid_to_gas" matchMax="1">Liquid changes to gas</simpleAssociableChoice>
147
- <simpleAssociableChoice identifier="gas_to_liquid" matchMax="1">Gas changes to liquid</simpleAssociableChoice>
148
- </simpleMatchSet>
149
- </matchInteraction>`,
150
- '<responseDeclaration identifier="RESPONSE" cardinality="multiple" baseType="directedPair"/>'
151
- );
152
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
153
-
154
- expect(interaction.type).toBe('matchInteraction');
155
- expect(interaction.maxAssociations).toBe(3);
156
- expect(interaction.sourceSet).toHaveLength(2);
157
- expect(interaction.targetSet).toHaveLength(2);
158
- });
159
-
160
- it('I17: extracts multiple interactions from one composite item', () => {
161
- const xml = wrapItem(
162
- 'i17-composite',
163
- `<p>The state of matter with a fixed volume but no fixed shape is
164
- <inlineChoiceInteraction responseIdentifier="STATE" shuffle="false">
165
- <inlineChoice identifier="liquid">liquid</inlineChoice>
166
- <inlineChoice identifier="solid">solid</inlineChoice>
167
- </inlineChoiceInteraction>.
168
- </p>
169
- <p>Write the freezing point of water in Celsius:
170
- <textEntryInteraction responseIdentifier="TEMP" expectedLength="3"/>
171
- </p>
172
- <choiceInteraction responseIdentifier="UNIT" maxChoices="1">
173
- <simpleChoice identifier="celsius">Celsius</simpleChoice>
174
- <simpleChoice identifier="fahrenheit">Fahrenheit</simpleChoice>
175
- </choiceInteraction>`,
176
- `<responseDeclaration identifier="STATE" cardinality="single" baseType="identifier"/>
177
- <responseDeclaration identifier="TEMP" cardinality="single" baseType="string"/>
178
- <responseDeclaration identifier="UNIT" cardinality="single" baseType="identifier"/>`
179
- );
180
- const interactions = new Player({ itemXml: xml }).getInteractionData();
181
- const types = interactions.map((i) => i.type).sort();
182
-
183
- expect(interactions).toHaveLength(3);
184
- expect(types).toEqual(['choiceInteraction', 'inlineChoiceInteraction', 'textEntryInteraction']);
185
- });
186
-
187
- it('P7: ignores metadata while preserving deliverable item content', () => {
188
- const xml = `<?xml version="1.0" encoding="UTF-8"?>
189
- <assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2"
190
- xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
191
- identifier="p7-metadata" title="Metadata Item" adaptive="false" timeDependent="false">
192
- <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
193
- <imsmd:lom>
194
- <imsmd:general><imsmd:title><imsmd:string>Clean-room metadata fixture</imsmd:string></imsmd:title></imsmd:general>
195
- </imsmd:lom>
196
- <itemBody>
197
- <choiceInteraction responseIdentifier="RESPONSE" maxChoices="1">
198
- <simpleChoice identifier="A">A public fixture can include metadata.</simpleChoice>
199
- <simpleChoice identifier="B">Metadata prevents delivery.</simpleChoice>
200
- </choiceInteraction>
201
- </itemBody>
202
- </assessmentItem>`;
203
- const player = new Player({ itemXml: xml });
204
-
205
- expect(player.getInteractionData()).toHaveLength(1);
206
- expect(player.getItemBodyHtml()).toContain('public fixture');
207
- });
208
- });
@@ -1 +0,0 @@
1
- export * from '../../interactions/custom/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/drawing/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/end-attempt/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/extended-text/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/gap-match/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/graphic-associate/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/graphic-gap-match/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/graphic-order/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/hotspot/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/hottext/extractor.js';
@@ -1,9 +0,0 @@
1
- /**
2
- * Compatibility barrel for standard QTI extractors.
3
- *
4
- * New code should import from `../../interactions/index.js` or the specific
5
- * `../../interactions/<interaction>/index.js` module. This path remains for
6
- * existing tests and public consumers.
7
- */
8
-
9
- export * from '../../interactions/index.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/inline-choice/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/match/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/media/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/order/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/portable-custom/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/position-object/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/select-point/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/slider/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/text-entry/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/upload/extractor.js';
@@ -1,108 +0,0 @@
1
- /**
2
- * Plugin-based element extraction system
3
- *
4
- * Provides a pluggable architecture for extracting data from QTI XML elements
5
- * with priority-based dispatch, validation, and type safety.
6
- *
7
- * @example Basic usage
8
- * ```typescript
9
- * import { ExtractionRegistry, createExtractionContext } from '@pie-qti/item-player';
10
- *
11
- * const registry = new ExtractionRegistry();
12
- * registry.register(myExtractor);
13
- *
14
- * const context = createExtractionContext(element, 'RESPONSE', dom, declarations, config);
15
- * const result = registry.extract<MyData>(element, context);
16
- *
17
- * if (result.success) {
18
- * console.log('Extracted:', result.data);
19
- * }
20
- * ```
21
- *
22
- * @example Custom extractor
23
- * ```typescript
24
- * const myExtractor: ElementExtractor<ChoiceData> = {
25
- * id: 'custom:my-choice',
26
- * name: 'My Custom Choice',
27
- * priority: 100,
28
- * elementTypes: ['choiceInteraction'],
29
- * canHandle: (element, context) => {
30
- * return context.utils.hasChildWithTag(element, 'customChoice');
31
- * },
32
- * extract: (element, context) => {
33
- * return {
34
- * choices: [...],
35
- * shuffle: false,
36
- * maxChoices: 1
37
- * };
38
- * }
39
- * };
40
- * ```
41
- */
42
-
43
- export { createExtractionContext } from './createContext.js';
44
- // Registry
45
- export { createExtractionRegistry, ExtractionRegistry } from './ExtractionRegistry.js';
46
-
47
- // Standard extractor data types (all 21 extractors)
48
- export type {
49
- AssociateData,
50
- ChoiceData,
51
- CustomData,
52
- DrawingData,
53
- EndAttemptData,
54
- ExtendedTextData,
55
- GapMatchData,
56
- GraphicAssociateData,
57
- GraphicGapMatchData,
58
- GraphicOrderData,
59
- HotspotData,
60
- HottextData,
61
- InlineChoiceData,
62
- MatchData,
63
- MediaData,
64
- OrderData,
65
- PositionObjectData,
66
- SelectPointData,
67
- SliderData,
68
- TextEntryData,
69
- UploadData,
70
- } from './extractors/index.js';
71
-
72
- // Standard extractors
73
- export {
74
- standardAssociateExtractor,
75
- standardChoiceExtractor,
76
- standardCustomExtractor,
77
- standardDrawingExtractor,
78
- standardEndAttemptExtractor,
79
- standardExtendedTextExtractor,
80
- standardGapMatchExtractor,
81
- standardGraphicAssociateExtractor,
82
- standardGraphicGapMatchExtractor,
83
- standardGraphicOrderExtractor,
84
- standardHotspotExtractor,
85
- standardHottextExtractor,
86
- standardInlineChoiceExtractor,
87
- standardMatchExtractor,
88
- standardMediaExtractor,
89
- standardOrderExtractor,
90
- standardPositionObjectExtractor,
91
- standardSelectPointExtractor,
92
- standardSliderExtractor,
93
- standardTextEntryExtractor,
94
- standardUploadExtractor,
95
- } from './extractors/index.js';
96
-
97
- // Core types
98
- export type {
99
- ElementExtractor,
100
- ExtractionContext,
101
- ExtractionResult,
102
- ExtractionUtils,
103
- ValidationResult,
104
- VariableDeclaration,
105
- } from './types.js';
106
- export { ExtractionError, isErrorResult, isSuccessResult } from './types.js';
107
- // Utilities
108
- export { createExtractionUtils } from './utils.js';
@@ -1,70 +0,0 @@
1
- import type { AssessmentItemDocument } from '../document/AssessmentItemDocument.js';
2
- import type { ExtractionRegistry } from './ExtractionRegistry.js';
3
- import { createExtractionContext } from './createContext.js';
4
- import { applyInteractionSecurity } from './interactionSecurity.js';
5
- import type { VariableDeclaration as ExtractionVariableDeclaration } from './types.js';
6
- import type { DeclarationMap } from '@pie-qti/qti-processing';
7
- import type { PlayerConfig } from '../types/index.js';
8
- import type { InteractionData } from '../types/interactions.js';
9
-
10
- export interface InteractionExtractionPipelineInput {
11
- document: AssessmentItemDocument;
12
- extractionRegistry: ExtractionRegistry;
13
- declarations: DeclarationMap;
14
- config: PlayerConfig;
15
- }
16
-
17
- export function extractInteractionData({
18
- document,
19
- extractionRegistry,
20
- declarations,
21
- config,
22
- }: InteractionExtractionPipelineInput): InteractionData[] {
23
- const declMap = projectDeclarationsForExtraction(declarations);
24
- const elements = document.findExtractionElements(getRegisteredElementTypes(extractionRegistry));
25
-
26
- const interactions: InteractionData[] = [];
27
- for (const discovered of elements) {
28
- const context = createExtractionContext(
29
- discovered.element,
30
- discovered.responseIdentifier,
31
- discovered.contextRoot,
32
- declMap,
33
- config
34
- );
35
- const result = extractionRegistry.extract<any>(discovered.element, context);
36
- if (!result.success) continue;
37
-
38
- interactions.push({
39
- type: discovered.normalizedType as any,
40
- responseId: discovered.responseIdentifier,
41
- ...result.data,
42
- });
43
- }
44
-
45
- return applyInteractionSecurity(interactions, config.security);
46
- }
47
-
48
- function getRegisteredElementTypes(extractionRegistry: ExtractionRegistry): string[] {
49
- const elementTypes = new Set<string>();
50
- for (const extractor of extractionRegistry.getExtractors()) {
51
- for (const elementType of extractor.elementTypes) {
52
- elementTypes.add(elementType);
53
- }
54
- }
55
- return [...elementTypes];
56
- }
57
-
58
- function projectDeclarationsForExtraction(
59
- declarations: DeclarationMap
60
- ): Map<string, ExtractionVariableDeclaration> {
61
- const declMap = new Map<string, ExtractionVariableDeclaration>();
62
- for (const declaration of Object.values(declarations)) {
63
- declMap.set(declaration.identifier, {
64
- identifier: declaration.identifier,
65
- cardinality: declaration.cardinality as any,
66
- baseType: declaration.baseType,
67
- });
68
- }
69
- return declMap;
70
- }
@@ -1,60 +0,0 @@
1
- import type { InteractionData } from '../types/interactions.js';
2
- import type { PlayerSecurityConfig } from '../types/index.js';
3
- import { toTrustedHtml } from '../core/trustedTypes.js';
4
- import { sanitizeResourceUrl } from '../core/urlPolicy.js';
5
-
6
- export function applyInteractionSecurity(
7
- interactions: InteractionData[],
8
- security?: PlayerSecurityConfig
9
- ): InteractionData[] {
10
- const policy = security?.urlPolicy;
11
- const allowObjectEmbeds = security?.allowObjectEmbeds === true;
12
- const ttPolicyName = security?.trustedTypesPolicyName;
13
-
14
- for (const interaction of interactions as any[]) {
15
- // Wrap known HTML injection fields in TrustedHTML (when enabled).
16
- // Important: do NOT wrap fields rendered as plain text (e.g. prompt).
17
- if (interaction.type === 'choiceInteraction' && Array.isArray(interaction.choices)) {
18
- for (const choice of interaction.choices) {
19
- if (typeof choice?.text === 'string') {
20
- choice.text = toTrustedHtml(choice.text, ttPolicyName);
21
- }
22
- }
23
- }
24
-
25
- // Shared ImageData shape.
26
- if (interaction.imageData?.src) {
27
- interaction.imageData.src = sanitizeResourceUrl(interaction.imageData.src, policy, 'img') ?? '';
28
- }
29
- if (interaction.imageData?.content && typeof interaction.imageData.content === 'string') {
30
- interaction.imageData.content = toTrustedHtml(interaction.imageData.content, ttPolicyName);
31
- }
32
-
33
- // positionObject stages.
34
- if (Array.isArray(interaction.positionObjectStages)) {
35
- for (const stage of interaction.positionObjectStages) {
36
- if (stage?.objectData?.src) {
37
- stage.objectData.src = sanitizeResourceUrl(stage.objectData.src, policy, 'img') ?? '';
38
- }
39
- if (stage?.objectData?.content && typeof stage.objectData.content === 'string') {
40
- stage.objectData.content = toTrustedHtml(stage.objectData.content, ttPolicyName);
41
- }
42
- }
43
- }
44
-
45
- // mediaInteraction.
46
- if (interaction.type === 'mediaInteraction' && interaction.mediaElement?.src) {
47
- const kind = interaction.mediaElement.type === 'object' ? 'object' : 'media';
48
- interaction.mediaElement.src =
49
- sanitizeResourceUrl(interaction.mediaElement.src, policy, kind) ?? '';
50
- interaction.allowObjectEmbeds = allowObjectEmbeds;
51
- }
52
-
53
- // hottextInteraction content is injected via {@html}.
54
- if (interaction.type === 'hottextInteraction' && typeof interaction.contentHtml === 'string') {
55
- interaction.contentHtml = toTrustedHtml(interaction.contentHtml, ttPolicyName);
56
- }
57
- }
58
-
59
- return interactions;
60
- }