@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,193 +0,0 @@
1
- /**
2
- * Standard QTI gapMatchInteraction extractor
3
- *
4
- * Extracts data from gapMatchInteraction elements (drag words into gaps)
5
- */
6
-
7
- import type { ElementExtractor } from '../../extraction/types.js';
8
-
9
- /**
10
- * Gap match data extracted from gapMatchInteraction elements
11
- */
12
- export interface GapMatchData {
13
- gapTexts: Array<{
14
- identifier: string;
15
- text: string;
16
- matchMax: number;
17
- matchMin?: number;
18
- matchGroup?: string[];
19
- classes?: string[];
20
- }>;
21
- gaps: string[];
22
- shuffle: boolean;
23
- prompt: string | null;
24
- promptText: string;
25
- }
26
-
27
- /**
28
- * Standard QTI gap match interaction extractor
29
- * Handles gapMatchInteraction elements (drag words into gaps in text)
30
- */
31
- export const standardGapMatchExtractor: ElementExtractor<GapMatchData> = {
32
- id: 'qti:gap-match-interaction',
33
- name: 'QTI Standard Gap Match Interaction',
34
- priority: 10,
35
- elementTypes: ['gapMatchInteraction'],
36
- description: 'Extracts standard QTI gapMatchInteraction (drag words into gaps)',
37
-
38
- canHandle(element, _context) {
39
- // All gapMatchInteraction elements are standard
40
- return element.rawTagName === 'gapMatchInteraction';
41
- },
42
-
43
- extract(element, context) {
44
- const { utils } = context;
45
-
46
- // Extract gapText children (draggable items)
47
- const gapTextElements = utils.getChildrenByTag(element, 'gapText');
48
- const gapTexts = gapTextElements.map((gapText) => {
49
- const classes = utils.getClasses(gapText);
50
- const matchMax = utils.getNumberAttribute(gapText, 'matchMax', 1);
51
- const matchMin = utils.getNumberAttribute(gapText, 'matchMin', 0);
52
- const matchGroupRaw = utils.getAttribute(gapText, 'matchGroup', '');
53
- const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
54
-
55
- return {
56
- identifier: utils.getAttribute(gapText, 'identifier', ''),
57
- text: utils.getTextContent(gapText),
58
- matchMax,
59
- ...(matchMin > 0 ? { matchMin } : {}),
60
- ...(matchGroup.length > 0 ? { matchGroup } : {}),
61
- ...(classes.length > 0 ? { classes } : {}),
62
- };
63
- });
64
-
65
- // Extract prompt (optional) and process gap placeholders.
66
- // NOTE: Many QTI items place `<gap>` elements in the interaction content (e.g. a `<p>`/`<blockquote>`)
67
- // rather than inside a `<prompt>` element. Support both patterns.
68
- const promptElements = utils.getChildrenByTag(element, 'prompt');
69
- let prompt: string | null = null;
70
- let promptText = '';
71
- const gaps: string[] = [];
72
-
73
- if (promptElements.length > 0) {
74
- const promptElement = promptElements[0];
75
- prompt = utils.getHtmlContent(promptElement);
76
-
77
- // Get the raw HTML content and extract gaps
78
- const promptHtml = promptElement.outerHTML || promptElement.toString();
79
-
80
- // Extract gap elements from prompt children
81
- const gapElements = utils.getChildrenByTag(promptElement, 'gap');
82
- for (const gap of gapElements) {
83
- gaps.push(utils.getAttribute(gap, 'identifier', ''));
84
- }
85
-
86
- // Replace gap elements with placeholders in the text
87
- promptText = promptHtml
88
- .replace(/<qti-prompt[^>]*>|<prompt[^>]*>/, '')
89
- .replace(/<\/qti-prompt>|<\/prompt>/, '')
90
- .replace(/<(?:qti-)?gap\s+identifier="([^"]+)"[^>]*>/g, '[GAP:$1]')
91
- .replace(/<(?:qti-)?gap\s+identifier='([^']+)'[^>]*>/g, '[GAP:$1]')
92
- .replace(/<\/(?:qti-)?gap>/g, '')
93
- .trim();
94
- }
95
-
96
- // If gaps were not found inside a <prompt>, search the full interaction body.
97
- // This handles items where <gap> elements appear in <p>/<blockquote> siblings of <prompt>.
98
- if (gaps.length === 0) {
99
- const interactionHtml = element.outerHTML || element.toString();
100
- const gapIdMatches = Array.from(
101
- interactionHtml.matchAll(/<(?:qti-)?gap\s+identifier=(?:"([^"]+)"|'([^']+)')[^>]*\/?>/gi)
102
- );
103
- for (const m of gapIdMatches) {
104
- const id = (m[1] || m[2] || '').trim();
105
- if (id) gaps.push(id);
106
- }
107
-
108
- if (!promptText) {
109
- // No prompt element either: build promptText from full interaction content.
110
- const interactionHtml2 = element.outerHTML || element.toString();
111
- promptText = interactionHtml2
112
- .replace(/<(?:qti-)?gap-match-interaction[^>]*>|<gapMatchInteraction[^>]*>/, '')
113
- .replace(/<\/(?:qti-)?gap-match-interaction>|<\/gapMatchInteraction>/, '')
114
- .replace(/<(?:qti-)?gap-text[\s\S]*?<\/(?:qti-)?gap-text>|<gapText[\s\S]*?<\/gapText>/g, '')
115
- .replace(/<(?:qti-)?gap\s+identifier="([^"]+)"[^>]*\/?>/g, '[GAP:$1]')
116
- .replace(/<(?:qti-)?gap\s+identifier='([^']+)'[^>]*\/?>/g, '[GAP:$1]')
117
- .replace(/<\/(?:qti-)?gap>/g, '')
118
- .trim();
119
- }
120
- }
121
-
122
- // Extract attributes
123
- const shuffle = utils.getBooleanAttribute(element, 'shuffle');
124
- const interactionClasses = utils.getClasses(element);
125
- const choicesContainerWidth = utils.getAttribute(element, 'data-choices-container-width', '') || null;
126
- const maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;
127
- const minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;
128
-
129
- return {
130
- gapTexts,
131
- gaps,
132
- shuffle,
133
- prompt,
134
- promptText,
135
- ...(interactionClasses.length > 0 ? { interactionClasses } : {}),
136
- ...(choicesContainerWidth ? { choicesContainerWidth } : {}),
137
- ...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),
138
- ...(minSelectionsMessage ? { minSelectionsMessage } : {}),
139
- };
140
- },
141
-
142
- validate(data) {
143
- const errors: string[] = [];
144
-
145
- // Validate gapTexts exist
146
- if (!data.gapTexts || data.gapTexts.length === 0) {
147
- errors.push('gapMatchInteraction must have at least one gapText');
148
- }
149
-
150
- // Validate gaps exist
151
- if (!data.gaps || data.gaps.length === 0) {
152
- errors.push('gapMatchInteraction must have at least one gap in the prompt');
153
- }
154
-
155
- // Validate gapText identifiers
156
- if (data.gapTexts) {
157
- const identifiers = new Set<string>();
158
- for (const gapText of data.gapTexts) {
159
- if (!gapText.identifier) {
160
- errors.push('All gapTexts must have an identifier');
161
- } else if (identifiers.has(gapText.identifier)) {
162
- errors.push(`Duplicate gapText identifier: ${gapText.identifier}`);
163
- } else {
164
- identifiers.add(gapText.identifier);
165
- }
166
-
167
- // Validate matchMax
168
- if (gapText.matchMax < 0) {
169
- errors.push(`matchMax must be non-negative for gapText ${gapText.identifier}`);
170
- }
171
- }
172
- }
173
-
174
- // Validate gap identifiers
175
- if (data.gaps) {
176
- const identifiers = new Set<string>();
177
- for (const gap of data.gaps) {
178
- if (!gap) {
179
- errors.push('All gaps must have an identifier');
180
- } else if (identifiers.has(gap)) {
181
- errors.push(`Duplicate gap identifier: ${gap}`);
182
- } else {
183
- identifiers.add(gap);
184
- }
185
- }
186
- }
187
-
188
- return {
189
- valid: errors.length === 0,
190
- errors: errors.length > 0 ? errors : undefined,
191
- };
192
- },
193
- };
@@ -1,2 +0,0 @@
1
- export * from './extractor.js';
2
- export type { GapMatchInteractionData } from './types.js';
@@ -1 +0,0 @@
1
- export type { GapMatchInteractionData } from '../shared/types.js';
@@ -1,192 +0,0 @@
1
- /**
2
- * Standard QTI graphicAssociateInteraction extractor
3
- *
4
- * Extracts data from graphicAssociateInteraction elements (associate items on image)
5
- */
6
-
7
- import type { ElementExtractor } from '../../extraction/types.js';
8
-
9
- /**
10
- * Image data for graphic associate 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 associate data extracted from graphicAssociateInteraction elements
22
- */
23
- export interface GraphicAssociateData {
24
- imageData: ImageData | null;
25
- associableHotspots: Array<{
26
- identifier: string;
27
- label: string;
28
- shape: string;
29
- coords: string;
30
- matchMax: number;
31
- matchMin?: number;
32
- matchGroup?: string[];
33
- classes?: string[];
34
- }>;
35
- maxAssociations: number;
36
- minAssociations: number;
37
- prompt: string | null;
38
- }
39
-
40
- /**
41
- * Standard QTI graphic associate interaction extractor
42
- * Handles graphicAssociateInteraction elements (creating associations between hotspots)
43
- */
44
- export const standardGraphicAssociateExtractor: ElementExtractor<GraphicAssociateData> = {
45
- id: 'qti:graphic-associate-interaction',
46
- name: 'QTI Standard Graphic Associate Interaction',
47
- priority: 10,
48
- elementTypes: ['graphicAssociateInteraction'],
49
- description: 'Extracts standard QTI graphicAssociateInteraction (associate items on image)',
50
-
51
- canHandle(element, _context) {
52
- // All graphicAssociateInteraction elements are standard
53
- return element.rawTagName === 'graphicAssociateInteraction';
54
- },
55
-
56
- extract(element, context) {
57
- const { utils } = context;
58
-
59
- // Extract image data from object element
60
- const objectElements = utils.getChildrenByTag(element, 'object');
61
- let imageData: ImageData | null = null;
62
-
63
- if (objectElements.length > 0) {
64
- const objectElement = objectElements[0];
65
- const type = utils.getAttribute(objectElement, 'type', '');
66
- const data = utils.getAttribute(objectElement, 'data', '');
67
- const width = utils.getAttribute(objectElement, 'width', '500');
68
- const height = utils.getAttribute(objectElement, 'height', '300');
69
-
70
- if (type.startsWith('image/svg')) {
71
- // Extract inline SVG content - get full content including <svg> tag
72
- const content = utils.getHtmlContent(objectElement);
73
- imageData = {
74
- type: 'svg',
75
- content,
76
- width,
77
- height,
78
- };
79
- } else {
80
- // External image reference
81
- imageData = {
82
- type: 'image',
83
- src: data,
84
- width,
85
- height,
86
- };
87
- }
88
- }
89
-
90
- // Extract associableHotspot children
91
- const hotspotElements = utils.getChildrenByTag(element, 'associableHotspot');
92
- const associableHotspots = hotspotElements.map((hotspot) => {
93
- const classes = utils.getClasses(hotspot);
94
- const identifier = utils.getAttribute(hotspot, 'identifier', '');
95
- const shape = utils.getAttribute(hotspot, 'shape', 'rect');
96
- const coords = utils.getAttribute(hotspot, 'coords', '0,0,50,50');
97
- const matchMax = utils.getNumberAttribute(hotspot, 'matchMax', 1);
98
- const matchMin = utils.getNumberAttribute(hotspot, 'matchMin', 0);
99
- const matchGroupRaw = utils.getAttribute(hotspot, 'matchGroup', '');
100
- const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
101
-
102
- // Get text content as label, use identifier as fallback
103
- const textContent = utils.getTextContent(hotspot).trim();
104
- const label = textContent || identifier;
105
-
106
- return {
107
- identifier,
108
- label,
109
- shape,
110
- coords,
111
- matchMax,
112
- ...(matchMin > 0 ? { matchMin } : {}),
113
- ...(matchGroup.length > 0 ? { matchGroup } : {}),
114
- ...(classes.length > 0 ? { classes } : {}),
115
- };
116
- });
117
-
118
- // Extract attributes with proper defaults
119
- const maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', 1);
120
- const minAssociations = utils.getNumberAttribute(element, 'minAssociations', 0);
121
-
122
- // Extract prompt (optional)
123
- const promptElements = utils.getChildrenByTag(element, 'prompt');
124
- const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
125
-
126
- return {
127
- imageData,
128
- associableHotspots,
129
- maxAssociations,
130
- minAssociations,
131
- prompt,
132
- };
133
- },
134
-
135
- validate(data) {
136
- const errors: string[] = [];
137
- const warnings: string[] = [];
138
-
139
- // Validate image data
140
- if (!data.imageData) {
141
- warnings.push('graphicAssociateInteraction has no image data');
142
- } else if (data.imageData.type === 'image' && !data.imageData.src) {
143
- errors.push('graphicAssociateInteraction must have an image URL');
144
- } else if (data.imageData.type === 'svg' && !data.imageData.content) {
145
- errors.push('graphicAssociateInteraction must have SVG content');
146
- }
147
-
148
- // Validate hotspots exist
149
- if (!data.associableHotspots || data.associableHotspots.length < 2) {
150
- errors.push('graphicAssociateInteraction must have at least 2 hotspots');
151
- }
152
-
153
- // Validate hotspot identifiers and coords
154
- if (data.associableHotspots && data.associableHotspots.length > 0) {
155
- const identifiers = new Set<string>();
156
- for (const hotspot of data.associableHotspots) {
157
- if (!hotspot.identifier) {
158
- errors.push('All hotspots must have an identifier');
159
- } else if (identifiers.has(hotspot.identifier)) {
160
- errors.push(`Duplicate hotspot identifier: ${hotspot.identifier}`);
161
- } else {
162
- identifiers.add(hotspot.identifier);
163
- }
164
-
165
- if (!hotspot.coords) {
166
- errors.push(`Hotspot ${hotspot.identifier} must have coords`);
167
- }
168
-
169
- // Validate matchMax
170
- if (hotspot.matchMax < 0) {
171
- errors.push(`matchMax must be non-negative for hotspot ${hotspot.identifier}`);
172
- }
173
- }
174
- }
175
-
176
- // Validate maxAssociations
177
- if (data.maxAssociations < 0) {
178
- errors.push('maxAssociations must be non-negative');
179
- }
180
-
181
- // Validate minAssociations
182
- if (data.minAssociations < 0) {
183
- errors.push('minAssociations must be non-negative');
184
- }
185
-
186
- return {
187
- valid: errors.length === 0,
188
- errors: errors.length > 0 ? errors : undefined,
189
- warnings: warnings.length > 0 ? warnings : undefined,
190
- };
191
- },
192
- };
@@ -1,2 +0,0 @@
1
- export * from './extractor.js';
2
- export type { GraphicAssociateInteractionData } from './types.js';
@@ -1 +0,0 @@
1
- export type { GraphicAssociateInteractionData, GraphicAssociateHotspot } from '../shared/types.js';
@@ -1,257 +0,0 @@
1
- /**
2
- * Standard QTI graphicGapMatchInteraction extractor
3
- *
4
- * Extracts data from graphicGapMatchInteraction elements (drag text/images into gaps on image)
5
- */
6
-
7
- import type { ElementExtractor } from '../../extraction/types.js';
8
-
9
- /**
10
- * Image data for graphic gap match interaction
11
- */
12
- export interface ImageData {
13
- type: 'image' | 'svg';
14
- src?: string;
15
- content?: string;
16
- width?: number;
17
- height?: number;
18
- }
19
-
20
- /**
21
- * Graphic gap match data extracted from graphicGapMatchInteraction elements
22
- */
23
- export interface GraphicGapMatchData {
24
- imageData: ImageData | null;
25
- maxAssociations: number;
26
- gapTexts: Array<{
27
- identifier: string;
28
- text: string;
29
- matchMax: number;
30
- matchMin?: number;
31
- matchGroup?: string[];
32
- classes?: string[];
33
- }>;
34
- gapImages: Array<{
35
- identifier: string;
36
- src: string;
37
- alt: string;
38
- matchMax: number;
39
- matchGroup?: string[];
40
- width?: number;
41
- height?: number;
42
- }>;
43
- hotspots: Array<{ identifier: string; shape: string; coords: string; matchMax: number }>;
44
- prompt: string | null;
45
- }
46
-
47
- /**
48
- * Standard QTI graphic gap match interaction extractor
49
- * Handles graphicGapMatchInteraction elements (drag text/images into gaps on an image)
50
- */
51
- export const standardGraphicGapMatchExtractor: ElementExtractor<GraphicGapMatchData> = {
52
- id: 'qti:graphic-gap-match-interaction',
53
- name: 'QTI Standard Graphic Gap Match Interaction',
54
- priority: 10,
55
- elementTypes: ['graphicGapMatchInteraction'],
56
- description: 'Extracts standard QTI graphicGapMatchInteraction (drag text/images into gaps)',
57
-
58
- canHandle(element, _context) {
59
- // All graphicGapMatchInteraction elements are standard
60
- return element.rawTagName === 'graphicGapMatchInteraction';
61
- },
62
-
63
- extract(element, context) {
64
- const { utils } = context;
65
-
66
- // Extract image data from object element
67
- const objectElements = utils.getChildrenByTag(element, 'object');
68
- let imageData: ImageData | null = null;
69
-
70
- if (objectElements.length > 0) {
71
- const objectElement = objectElements[0];
72
- const type = utils.getAttribute(objectElement, 'type', '');
73
- const data = utils.getAttribute(objectElement, 'data', '');
74
- const width = utils.getNumberAttribute(objectElement, 'width', 0);
75
- const height = utils.getNumberAttribute(objectElement, 'height', 0);
76
-
77
- if (type.startsWith('image/svg')) {
78
- // Inline SVG: <object type="image/svg+xml"><svg>...</svg></object>
79
- // External SVG: <object type="image/svg+xml" data="path/to/file.svg"/>
80
- // The <object> may contain alt text (not SVG markup) — only treat as inline if content has <svg.
81
- const content = utils.getHtmlContent(objectElement);
82
- const hasSvgMarkup = /<svg[\s>]/i.test(content);
83
- if (hasSvgMarkup) {
84
- imageData = {
85
- type: 'svg',
86
- content,
87
- ...(width > 0 ? { width } : {}),
88
- ...(height > 0 ? { height } : {}),
89
- };
90
- } else {
91
- // External SVG file reference — render via <img src>
92
- imageData = {
93
- type: 'image',
94
- src: data,
95
- ...(width > 0 ? { width } : {}),
96
- ...(height > 0 ? { height } : {}),
97
- };
98
- }
99
- } else {
100
- // External image reference
101
- imageData = {
102
- type: 'image',
103
- src: data,
104
- ...(width > 0 ? { width } : {}),
105
- ...(height > 0 ? { height } : {}),
106
- };
107
- }
108
- }
109
-
110
- // Extract interaction-level attributes
111
- const maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', 0);
112
-
113
- // Extract gapText children (draggable text labels)
114
- const gapTextElements = utils.getChildrenByTag(element, 'gapText');
115
- const gapTexts = gapTextElements.map((gapText) => {
116
- const classes = utils.getClasses(gapText);
117
- const matchMax = utils.getNumberAttribute(gapText, 'matchMax', 1);
118
- const matchMin = utils.getNumberAttribute(gapText, 'matchMin', 0);
119
- const matchGroupRaw = utils.getAttribute(gapText, 'matchGroup', '');
120
- const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
121
- const text = utils.getHtmlContent(gapText);
122
-
123
- return {
124
- identifier: utils.getAttribute(gapText, 'identifier', ''),
125
- text,
126
- matchMax,
127
- ...(matchMin > 0 ? { matchMin } : {}),
128
- ...(matchGroup.length > 0 ? { matchGroup } : {}),
129
- ...(classes.length > 0 ? { classes } : {}),
130
- };
131
- });
132
-
133
- // Extract gapImg children (draggable image labels)
134
- const gapImgElements = utils.getChildrenByTag(element, 'gapImg');
135
- const gapImages = gapImgElements.map((gapImg) => {
136
- const matchMax = utils.getNumberAttribute(gapImg, 'matchMax', 1);
137
- const matchGroupRaw = utils.getAttribute(gapImg, 'matchGroup', '');
138
- const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
139
- const objectChildren = utils.getChildrenByTag(gapImg, 'object');
140
- let src = '';
141
- let alt = '';
142
- let width: number | undefined;
143
- let height: number | undefined;
144
- if (objectChildren.length > 0) {
145
- const obj = objectChildren[0];
146
- src = utils.getAttribute(obj, 'data', '');
147
- alt = utils.getTextContent(obj);
148
- const w = utils.getNumberAttribute(obj, 'width', 0);
149
- const h = utils.getNumberAttribute(obj, 'height', 0);
150
- if (w > 0) width = w;
151
- if (h > 0) height = h;
152
- }
153
- return {
154
- identifier: utils.getAttribute(gapImg, 'identifier', ''),
155
- src,
156
- alt,
157
- matchMax,
158
- ...(matchGroup.length > 0 ? { matchGroup } : {}),
159
- ...(width !== undefined ? { width } : {}),
160
- ...(height !== undefined ? { height } : {}),
161
- };
162
- });
163
-
164
- // Extract associableHotspot elements (gap targets)
165
- const hotspotElements = utils.getChildrenByTag(element, 'associableHotspot');
166
- const hotspots = hotspotElements.map((hotspot) => ({
167
- identifier: utils.getAttribute(hotspot, 'identifier', ''),
168
- shape: utils.getAttribute(hotspot, 'shape', 'rect'),
169
- coords: utils.getAttribute(hotspot, 'coords', ''),
170
- matchMax: utils.getNumberAttribute(hotspot, 'matchMax', 1),
171
- }));
172
-
173
- // Extract prompt (optional)
174
- const promptElements = utils.getChildrenByTag(element, 'prompt');
175
- const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
176
-
177
- const interactionClasses = utils.getClasses(element);
178
- const choicesContainerWidth = utils.getAttribute(element, 'data-choices-container-width', '') || null;
179
- const maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;
180
- const minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;
181
-
182
- return {
183
- imageData,
184
- maxAssociations,
185
- gapTexts,
186
- gapImages,
187
- hotspots,
188
- prompt,
189
- ...(interactionClasses.length > 0 ? { interactionClasses } : {}),
190
- ...(choicesContainerWidth ? { choicesContainerWidth } : {}),
191
- ...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),
192
- ...(minSelectionsMessage ? { minSelectionsMessage } : {}),
193
- };
194
- },
195
-
196
- validate(data) {
197
- const errors: string[] = [];
198
- const warnings: string[] = [];
199
-
200
- // Validate image data (optional but recommended)
201
- if (!data.imageData) {
202
- warnings.push('graphicGapMatchInteraction has no background image');
203
- } else if (data.imageData.type === 'image' && !data.imageData.src) {
204
- errors.push('graphicGapMatchInteraction must have an image URL');
205
- } else if (data.imageData.type === 'svg' && !data.imageData.content) {
206
- errors.push('graphicGapMatchInteraction must have SVG content');
207
- }
208
-
209
- // Validate that at least one draggable choice type is present
210
- if ((!data.gapTexts || data.gapTexts.length === 0) && (!data.gapImages || data.gapImages.length === 0)) {
211
- errors.push('graphicGapMatchInteraction must have at least one gapText or gapImg');
212
- }
213
-
214
- // Validate hotspots exist
215
- if (!data.hotspots || data.hotspots.length === 0) {
216
- errors.push('graphicGapMatchInteraction must have at least one hotspot');
217
- }
218
-
219
- // Validate gapText identifiers
220
- if (data.gapTexts) {
221
- const identifiers = new Set<string>();
222
- for (const gapText of data.gapTexts) {
223
- if (!gapText.identifier) {
224
- errors.push('All gapTexts must have an identifier');
225
- } else if (identifiers.has(gapText.identifier)) {
226
- errors.push(`Duplicate gapText identifier: ${gapText.identifier}`);
227
- } else {
228
- identifiers.add(gapText.identifier);
229
- }
230
- }
231
- }
232
-
233
- // Validate hotspot identifiers
234
- if (data.hotspots) {
235
- const identifiers = new Set<string>();
236
- for (const hotspot of data.hotspots) {
237
- if (!hotspot.identifier) {
238
- errors.push('All hotspots must have an identifier');
239
- } else if (identifiers.has(hotspot.identifier)) {
240
- errors.push(`Duplicate hotspot identifier: ${hotspot.identifier}`);
241
- } else {
242
- identifiers.add(hotspot.identifier);
243
- }
244
-
245
- if (!hotspot.coords) {
246
- errors.push(`Hotspot ${hotspot.identifier} must have coords`);
247
- }
248
- }
249
- }
250
-
251
- return {
252
- valid: errors.length === 0,
253
- errors: errors.length > 0 ? errors : undefined,
254
- warnings: warnings.length > 0 ? warnings : undefined,
255
- };
256
- },
257
- };
@@ -1,2 +0,0 @@
1
- export * from './extractor.js';
2
- export type { GraphicGapMatchInteractionData } from './types.js';
@@ -1 +0,0 @@
1
- export type { GraphicGapMatchInteractionData, AssociableHotspot, ImageData } from '../shared/types.js';