@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,162 +0,0 @@
1
- /**
2
- * Standard QTI graphicOrderInteraction extractor
3
- *
4
- * Extracts data from graphicOrderInteraction elements (order items on image)
5
- */
6
-
7
- import type { ElementExtractor } from '../../extraction/types.js';
8
-
9
- /**
10
- * Image data for graphic order interaction
11
- */
12
- export interface ImageData {
13
- type: 'image' | 'svg';
14
- src?: string;
15
- content?: string;
16
- width?: string;
17
- height?: string;
18
- }
19
-
20
- /**
21
- * Graphic order data extracted from graphicOrderInteraction elements
22
- */
23
- export interface GraphicOrderData {
24
- imageData: ImageData | null;
25
- hotspotChoices: Array<{
26
- identifier: string;
27
- label: string;
28
- shape: string;
29
- coords: string;
30
- fixed?: boolean;
31
- classes?: string[];
32
- }>;
33
- prompt: string | null;
34
- }
35
-
36
- /**
37
- * Standard QTI graphic order interaction extractor
38
- * Handles graphicOrderInteraction elements (ordering hotspots on an image)
39
- */
40
- export const standardGraphicOrderExtractor: ElementExtractor<GraphicOrderData> = {
41
- id: 'qti:graphic-order-interaction',
42
- name: 'QTI Standard Graphic Order Interaction',
43
- priority: 10,
44
- elementTypes: ['graphicOrderInteraction'],
45
- description: 'Extracts standard QTI graphicOrderInteraction (order items on image)',
46
-
47
- canHandle(element, _context) {
48
- // All graphicOrderInteraction elements are standard
49
- return element.rawTagName === 'graphicOrderInteraction';
50
- },
51
-
52
- extract(element, context) {
53
- const { utils } = context;
54
-
55
- // Extract image data from object element
56
- const objectElements = utils.getChildrenByTag(element, 'object');
57
- let imageData: ImageData | null = null;
58
-
59
- if (objectElements.length > 0) {
60
- const objectElement = objectElements[0];
61
- const type = utils.getAttribute(objectElement, 'type', '');
62
- const data = utils.getAttribute(objectElement, 'data', '');
63
- const width = utils.getAttribute(objectElement, 'width', '500');
64
- const height = utils.getAttribute(objectElement, 'height', '300');
65
-
66
- if (type.startsWith('image/svg')) {
67
- // Extract inline SVG content - get full content including <svg> tag
68
- const content = utils.getHtmlContent(objectElement);
69
- imageData = {
70
- type: 'svg',
71
- content,
72
- width,
73
- height,
74
- };
75
- } else {
76
- // External image reference
77
- imageData = {
78
- type: 'image',
79
- src: data,
80
- width,
81
- height,
82
- };
83
- }
84
- }
85
-
86
- // Extract hotspotChoice children
87
- const hotspotElements = utils.getChildrenByTag(element, 'hotspotChoice');
88
- const hotspotChoices = hotspotElements.map((hotspot) => {
89
- const classes = utils.getClasses(hotspot);
90
- const identifier = utils.getAttribute(hotspot, 'identifier', '');
91
- const shape = utils.getAttribute(hotspot, 'shape', 'rect');
92
- const coords = utils.getAttribute(hotspot, 'coords', '0,0,50,50');
93
- const fixed = utils.getBooleanAttribute(hotspot, 'fixed');
94
-
95
- // Get text content as label, use identifier as fallback
96
- const textContent = utils.getTextContent(hotspot).trim();
97
- const label = textContent || identifier;
98
-
99
- return {
100
- identifier,
101
- label,
102
- shape,
103
- coords,
104
- ...(fixed ? { fixed } : {}),
105
- ...(classes.length > 0 ? { classes } : {}),
106
- };
107
- });
108
-
109
- // Extract prompt (optional)
110
- const promptElements = utils.getChildrenByTag(element, 'prompt');
111
- const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
112
-
113
- return {
114
- imageData,
115
- hotspotChoices,
116
- prompt,
117
- };
118
- },
119
-
120
- validate(data) {
121
- const errors: string[] = [];
122
- const warnings: string[] = [];
123
-
124
- // Validate image data
125
- if (!data.imageData) {
126
- warnings.push('graphicOrderInteraction has no image data');
127
- } else if (data.imageData.type === 'image' && !data.imageData.src) {
128
- errors.push('graphicOrderInteraction must have an image URL');
129
- } else if (data.imageData.type === 'svg' && !data.imageData.content) {
130
- errors.push('graphicOrderInteraction must have SVG content');
131
- }
132
-
133
- // Validate hotspot choices exist
134
- if (!data.hotspotChoices || data.hotspotChoices.length < 2) {
135
- errors.push('graphicOrderInteraction must have at least 2 hotspots');
136
- }
137
-
138
- // Validate hotspot choice identifiers and coords
139
- if (data.hotspotChoices) {
140
- const identifiers = new Set<string>();
141
- for (const hotspot of data.hotspotChoices) {
142
- if (!hotspot.identifier) {
143
- errors.push('All hotspot choices must have an identifier');
144
- } else if (identifiers.has(hotspot.identifier)) {
145
- errors.push(`Duplicate hotspot identifier: ${hotspot.identifier}`);
146
- } else {
147
- identifiers.add(hotspot.identifier);
148
- }
149
-
150
- if (!hotspot.coords) {
151
- errors.push(`Hotspot ${hotspot.identifier} must have coords`);
152
- }
153
- }
154
- }
155
-
156
- return {
157
- valid: errors.length === 0,
158
- errors: errors.length > 0 ? errors : undefined,
159
- warnings: warnings.length > 0 ? warnings : undefined,
160
- };
161
- },
162
- };
@@ -1,2 +0,0 @@
1
- export * from './extractor.js';
2
- export type { GraphicOrderInteractionData } from './types.js';
@@ -1 +0,0 @@
1
- export type { GraphicOrderInteractionData, GraphicOrderChoice } from '../shared/types.js';
@@ -1,208 +0,0 @@
1
- /**
2
- * Standard QTI hotspotInteraction extractor
3
- *
4
- * Extracts data from hotspotInteraction elements (clickable areas on image)
5
- */
6
-
7
- import type { ElementExtractor } from '../../extraction/types.js';
8
-
9
- /**
10
- * Image data for hotspot interaction
11
- */
12
- export interface ImageData {
13
- type: 'image' | 'svg';
14
- src?: string;
15
- content?: string;
16
- width?: string;
17
- height?: string;
18
- }
19
-
20
- /**
21
- * Hotspot data extracted from hotspotInteraction elements
22
- */
23
- export interface HotspotData {
24
- imageData: ImageData | null;
25
- hotspotChoices: Array<{
26
- identifier: string;
27
- shape: 'circle' | 'rect' | 'poly' | 'ellipse' | 'default';
28
- coords: string;
29
- hotspotLabel?: string;
30
- classes?: string[];
31
- }>;
32
- maxChoices: number;
33
- minChoices?: number;
34
- prompt: string | null;
35
- }
36
-
37
- /**
38
- * Standard QTI hotspot interaction extractor
39
- * Handles hotspotInteraction elements (clickable areas on an image)
40
- */
41
- export const standardHotspotExtractor: ElementExtractor<HotspotData> = {
42
- id: 'qti:hotspot-interaction',
43
- name: 'QTI Standard Hotspot Interaction',
44
- priority: 10,
45
- elementTypes: ['hotspotInteraction'],
46
- description: 'Extracts standard QTI hotspotInteraction (clickable areas on image)',
47
-
48
- canHandle(element, _context) {
49
- // All hotspotInteraction elements are standard
50
- return element.rawTagName === 'hotspotInteraction';
51
- },
52
-
53
- extract(element, context) {
54
- const { utils } = context;
55
-
56
- // Extract image data from object element
57
- const objectElements = utils.getChildrenByTag(element, 'object');
58
- let imageData: ImageData | null = null;
59
-
60
- if (objectElements.length > 0) {
61
- const objectElement = objectElements[0];
62
- const type = utils.getAttribute(objectElement, 'type', '');
63
- const data = utils.getAttribute(objectElement, 'data', '');
64
- const width = utils.getAttribute(objectElement, 'width', 'auto');
65
- const height = utils.getAttribute(objectElement, 'height', 'auto');
66
-
67
- if (type.startsWith('image/svg')) {
68
- // Inline SVG: <object type="image/svg+xml"><svg>...</svg></object>
69
- // External SVG: <object type="image/svg+xml" data="path/to/file.svg"/>
70
- // The <object> may contain alt text (not SVG markup) — only treat as inline if content has <svg.
71
- const content = utils.getHtmlContent(objectElement);
72
- const hasSvgMarkup = /<svg[\s>]/i.test(content);
73
- if (hasSvgMarkup) {
74
- imageData = {
75
- type: 'svg',
76
- content,
77
- width,
78
- height,
79
- };
80
- } else {
81
- // External SVG file reference — render via <img src> (SVG renders in img tags)
82
- imageData = {
83
- type: 'image',
84
- src: data,
85
- width,
86
- height,
87
- };
88
- }
89
- } else {
90
- // External image reference
91
- imageData = {
92
- type: 'image',
93
- src: data,
94
- width,
95
- height,
96
- };
97
- }
98
- }
99
-
100
- // Extract hotspotChoice children
101
- const hotspotElements = utils.getChildrenByTag(element, 'hotspotChoice');
102
- const hotspotChoices = hotspotElements.map((hotspot) => {
103
- const classes = utils.getClasses(hotspot);
104
- const shape = utils.getAttribute(hotspot, 'shape', 'rect');
105
- const coords = utils.getAttribute(hotspot, 'coords', '');
106
- const hotspotLabel = utils.getAttribute(hotspot, 'hotspotLabel', '');
107
-
108
- return {
109
- identifier: utils.getAttribute(hotspot, 'identifier', ''),
110
- shape: shape as 'circle' | 'rect' | 'poly' | 'ellipse' | 'default',
111
- coords,
112
- ...(hotspotLabel ? { hotspotLabel } : {}),
113
- ...(classes.length > 0 ? { classes } : {}),
114
- };
115
- });
116
-
117
- // Extract attributes
118
- const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);
119
- const minChoices = utils.getNumberAttribute(element, 'minChoices', 0);
120
- const interactionClasses = utils.getClasses(element);
121
- const maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;
122
- const minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;
123
-
124
- // Extract prompt (optional)
125
- const promptElements = utils.getChildrenByTag(element, 'prompt');
126
- const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
127
-
128
- return {
129
- imageData,
130
- hotspotChoices,
131
- maxChoices,
132
- ...(minChoices > 0 ? { minChoices } : {}),
133
- prompt,
134
- ...(interactionClasses.length > 0 ? { interactionClasses } : {}),
135
- ...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),
136
- ...(minSelectionsMessage ? { minSelectionsMessage } : {}),
137
- };
138
- },
139
-
140
- validate(data) {
141
- const errors: string[] = [];
142
- const warnings: string[] = [];
143
-
144
- // Validate image data
145
- if (!data.imageData) {
146
- warnings.push('hotspotInteraction has no image data');
147
- } else if (data.imageData.type === 'image' && !data.imageData.src) {
148
- errors.push('hotspotInteraction must have an image URL');
149
- } else if (data.imageData.type === 'svg' && !data.imageData.content) {
150
- errors.push('hotspotInteraction must have SVG content');
151
- }
152
-
153
- // Validate hotspots exist
154
- if (!data.hotspotChoices || data.hotspotChoices.length === 0) {
155
- errors.push('hotspotInteraction must have at least one hotspot');
156
- }
157
-
158
- // Validate hotspot identifiers and coords
159
- if (data.hotspotChoices && data.hotspotChoices.length > 0) {
160
- const identifiers = new Set<string>();
161
- for (const hotspot of data.hotspotChoices) {
162
- if (!hotspot.identifier) {
163
- errors.push('All hotspots must have an identifier');
164
- } else if (identifiers.has(hotspot.identifier)) {
165
- errors.push(`Duplicate hotspot identifier: ${hotspot.identifier}`);
166
- } else {
167
- identifiers.add(hotspot.identifier);
168
- }
169
-
170
- if (!hotspot.coords) {
171
- errors.push(`Hotspot ${hotspot.identifier} must have coords`);
172
- }
173
- }
174
-
175
- // Warn if maxChoices exceeds hotspot count
176
- if (data.maxChoices > data.hotspotChoices.length) {
177
- warnings.push(
178
- `maxChoices (${data.maxChoices}) exceeds the number of hotspots (${data.hotspotChoices.length})`
179
- );
180
- }
181
- }
182
-
183
- // Validate maxChoices
184
- if (data.maxChoices < 0) {
185
- errors.push('maxChoices must be non-negative');
186
- }
187
-
188
- // Validate minChoices
189
- if (data.minChoices !== undefined && data.minChoices < 0) {
190
- errors.push('minChoices must be non-negative');
191
- }
192
-
193
- // Validate minChoices <= maxChoices
194
- if (
195
- data.minChoices !== undefined &&
196
- data.maxChoices > 0 &&
197
- data.minChoices > data.maxChoices
198
- ) {
199
- errors.push('minChoices cannot exceed maxChoices');
200
- }
201
-
202
- return {
203
- valid: errors.length === 0,
204
- errors: errors.length > 0 ? errors : undefined,
205
- warnings: warnings.length > 0 ? warnings : undefined,
206
- };
207
- },
208
- };
@@ -1,2 +0,0 @@
1
- export * from './extractor.js';
2
- export type { HotspotInteractionData } from './types.js';
@@ -1 +0,0 @@
1
- export type { HotspotInteractionData, HotspotChoice, ImageData } from '../shared/types.js';
@@ -1,163 +0,0 @@
1
- /**
2
- * Standard QTI hottextInteraction extractor
3
- *
4
- * Extracts data from hottextInteraction elements (select text spans)
5
- */
6
-
7
- import { sanitizeHtml } from '../../core/sanitizer.js';
8
- import type { QTIElement } from '../shared/types.js';
9
- import type { ElementExtractor } from '../../extraction/types.js';
10
-
11
- /**
12
- * Hottext data extracted from hottextInteraction elements
13
- */
14
- export interface HottextData {
15
- hottextChoices: Array<{ identifier: string; text: string; classes?: string[] }>;
16
- contentHtml: string;
17
- maxChoices: number;
18
- minChoices: number;
19
- prompt: string | null;
20
- }
21
-
22
- /**
23
- * Standard QTI hottext interaction extractor
24
- * Handles hottextInteraction elements (selectable text spans)
25
- */
26
- export const standardHottextExtractor: ElementExtractor<HottextData> = {
27
- id: 'qti:hottext-interaction',
28
- name: 'QTI Standard Hottext Interaction',
29
- priority: 10,
30
- elementTypes: ['hottextInteraction'],
31
- description: 'Extracts standard QTI hottextInteraction (select text spans)',
32
-
33
- canHandle(element, _context) {
34
- // All hottextInteraction elements are standard
35
- return element.rawTagName === 'hottextInteraction' || element.rawTagName === 'qti-hottext-interaction';
36
- },
37
-
38
- extract(element, context) {
39
- const { utils } = context;
40
-
41
- // Extract hottext children (selectable text spans) - recursively search entire tree
42
- const findHottextElements = (el: any): any[] => {
43
- const results: any[] = [];
44
- if (el.rawTagName === 'hottext' || el.rawTagName === 'qti-hottext') {
45
- results.push(el);
46
- }
47
- if (el.childNodes) {
48
- for (const child of el.childNodes) {
49
- if (typeof child !== 'string') {
50
- results.push(...findHottextElements(child));
51
- }
52
- }
53
- }
54
- return results;
55
- };
56
-
57
- const hottextElements = findHottextElements(element);
58
- const hottextChoices = hottextElements.map((hottext) => {
59
- const classes = utils.getClasses(hottext);
60
- return {
61
- identifier: utils.getAttribute(hottext, 'identifier', ''),
62
- text: utils.getTextContent(hottext),
63
- ...(classes.length > 0 ? { classes } : {}),
64
- };
65
- });
66
-
67
- // Extract attributes
68
- const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);
69
- const minChoices = utils.getNumberAttribute(element, 'minChoices', 0);
70
- const interactionClasses = utils.getClasses(element);
71
- const maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;
72
- const minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;
73
-
74
- // Extract prompt (optional)
75
- const promptElements = utils.getChildrenByTag(element, 'prompt');
76
- const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
77
-
78
- // Extract content HTML (all content except prompt)
79
- let contentHtml = '';
80
- for (const child of element.childNodes) {
81
- // Skip prompt elements
82
- if (
83
- typeof child !== 'string' &&
84
- (child as QTIElement).rawTagName !== 'prompt' &&
85
- (child as QTIElement).rawTagName !== 'qti-prompt'
86
- ) {
87
- contentHtml += (child as QTIElement).outerHTML || child.toString();
88
- } else if (typeof child === 'string') {
89
- contentHtml += child;
90
- }
91
- }
92
-
93
- // Sanitize extracted HTML before rendering via {@html} in the component.
94
- contentHtml = sanitizeHtml(contentHtml, { security: context.config.security });
95
-
96
- return {
97
- hottextChoices,
98
- contentHtml,
99
- maxChoices,
100
- minChoices,
101
- prompt,
102
- ...(interactionClasses.length > 0 ? { interactionClasses } : {}),
103
- ...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),
104
- ...(minSelectionsMessage ? { minSelectionsMessage } : {}),
105
- };
106
- },
107
-
108
- validate(data) {
109
- const errors: string[] = [];
110
- const warnings: string[] = [];
111
-
112
- // Validate hottextChoices exist
113
- if (!data.hottextChoices || data.hottextChoices.length === 0) {
114
- errors.push('hottextInteraction must have at least one hottext');
115
- }
116
-
117
- // Validate hottext identifiers
118
- if (data.hottextChoices) {
119
- const identifiers = new Set<string>();
120
- for (const hottext of data.hottextChoices) {
121
- if (!hottext.identifier) {
122
- errors.push('All hottext elements must have an identifier');
123
- } else if (identifiers.has(hottext.identifier)) {
124
- errors.push(`Duplicate hottext identifier: ${hottext.identifier}`);
125
- } else {
126
- identifiers.add(hottext.identifier);
127
- }
128
- }
129
- }
130
-
131
- // Validate maxChoices
132
- if (data.maxChoices < 0) {
133
- errors.push('maxChoices must be non-negative');
134
- }
135
-
136
- // Warn if maxChoices exceeds hottext count
137
- if (data.hottextChoices && data.maxChoices > data.hottextChoices.length) {
138
- warnings.push(
139
- `maxChoices (${data.maxChoices}) exceeds the number of hottext choices (${data.hottextChoices.length})`
140
- );
141
- }
142
-
143
- // Validate minChoices
144
- if (data.minChoices !== undefined && data.minChoices < 0) {
145
- errors.push('minChoices must be non-negative');
146
- }
147
-
148
- // Validate minChoices <= maxChoices
149
- if (
150
- data.minChoices !== undefined &&
151
- data.maxChoices > 0 &&
152
- data.minChoices > data.maxChoices
153
- ) {
154
- errors.push('minChoices cannot exceed maxChoices');
155
- }
156
-
157
- return {
158
- valid: errors.length === 0,
159
- errors: errors.length > 0 ? errors : undefined,
160
- warnings: warnings.length > 0 ? warnings : undefined,
161
- };
162
- },
163
- };
@@ -1,2 +0,0 @@
1
- export * from './extractor.js';
2
- export type { HottextInteractionData } from './types.js';
@@ -1 +0,0 @@
1
- export type { HottextInteractionData, HottextChoice } from '../shared/types.js';
@@ -1,52 +0,0 @@
1
- /**
2
- * Vertical QTI interaction modules.
3
- *
4
- * Each interaction folder owns the extractor entrypoint and interaction-specific
5
- * type exports. Legacy extractor and type paths re-export from this module layer.
6
- */
7
-
8
- export type {
9
- AssociableChoice,
10
- AssociableHotspot,
11
- BaseInteractionData,
12
- GraphicAssociateHotspot,
13
- GraphicOrderChoice,
14
- HotspotChoice,
15
- ImageData,
16
- MediaElement,
17
- Point,
18
- PositionObjectStage,
19
- QTIElement,
20
- } from './shared/index.js';
21
-
22
- export * from './associate/index.js';
23
- export * from './choice/index.js';
24
- export * from './custom/index.js';
25
- export * from './drawing/index.js';
26
- export * from './end-attempt/index.js';
27
- export * from './extended-text/index.js';
28
- export * from './gap-match/index.js';
29
- export * from './graphic-associate/index.js';
30
- export * from './graphic-gap-match/index.js';
31
- export * from './graphic-order/index.js';
32
- export * from './hotspot/index.js';
33
- export * from './hottext/index.js';
34
- export * from './inline/index.js';
35
- export * from './inline-choice/index.js';
36
- export * from './match/index.js';
37
- export * from './media/index.js';
38
- export * from './modules.js';
39
- export * from './order/index.js';
40
- export * from './portable-custom/index.js';
41
- export * from './position-object/index.js';
42
- export * from './select-point/index.js';
43
- export * from './slider/index.js';
44
- export * from './text-entry/index.js';
45
- export * from './upload/index.js';
46
-
47
- export type {
48
- InteractionData,
49
- InteractionDataMap,
50
- InteractionType,
51
- InteractionValueMap,
52
- } from './shared/types.js';
@@ -1 +0,0 @@
1
- export * from './render-plan.js';