@pie-qti/item-player 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -18
- package/dist/catalog/applyGlossaryTriggers.d.ts +15 -0
- package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -0
- package/dist/catalog/applyGlossaryTriggers.js +193 -0
- package/dist/catalog/catalogExtractor.d.ts +18 -0
- package/dist/catalog/catalogExtractor.d.ts.map +1 -0
- package/dist/catalog/catalogExtractor.js +114 -0
- package/dist/catalog/catalogLookup.d.ts +18 -0
- package/dist/catalog/catalogLookup.d.ts.map +1 -0
- package/dist/catalog/catalogLookup.js +44 -0
- package/dist/catalog/glossaryAction.d.ts +17 -0
- package/dist/catalog/glossaryAction.d.ts.map +1 -0
- package/dist/catalog/glossaryAction.js +21 -0
- package/dist/catalog/types.d.ts +26 -0
- package/dist/catalog/types.d.ts.map +1 -0
- package/dist/catalog/types.js +6 -0
- package/dist/core/ComponentRegistry.d.ts +9 -0
- package/dist/core/ComponentRegistry.d.ts.map +1 -1
- package/dist/core/ComponentRegistry.js +14 -0
- package/dist/core/ItemRenderer.d.ts.map +1 -1
- package/dist/core/ItemRenderer.js +3 -0
- package/dist/core/Player.d.ts +52 -0
- package/dist/core/Player.d.ts.map +1 -1
- package/dist/core/Player.js +158 -4
- package/dist/core/rolePolicy.d.ts +16 -0
- package/dist/core/rolePolicy.d.ts.map +1 -0
- package/dist/core/rolePolicy.js +15 -0
- package/dist/core/urlPolicy.d.ts.map +1 -1
- package/dist/core/urlPolicy.js +5 -2
- package/dist/element.d.ts +22 -0
- package/dist/element.js +5327 -0
- package/dist/element.js.map +1 -0
- package/dist/extraction/ExtractionRegistry.d.ts.map +1 -1
- package/dist/extraction/ExtractionRegistry.js +3 -1
- package/dist/extraction/extractors/associateExtractor.d.ts +1 -0
- package/dist/extraction/extractors/associateExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/associateExtractor.js +3 -0
- package/dist/extraction/extractors/choiceExtractor.d.ts +2 -0
- package/dist/extraction/extractors/choiceExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/choiceExtractor.js +10 -0
- package/dist/extraction/extractors/extendedTextExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/extendedTextExtractor.js +6 -0
- package/dist/extraction/extractors/gapMatchExtractor.d.ts +1 -0
- package/dist/extraction/extractors/gapMatchExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/gapMatchExtractor.js +33 -20
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts +1 -0
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/graphicAssociateExtractor.js +3 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts +11 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/graphicGapMatchExtractor.js +71 -10
- package/dist/extraction/extractors/hotspotExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/hotspotExtractor.js +27 -8
- package/dist/extraction/extractors/hottextExtractor.d.ts +1 -1
- package/dist/extraction/extractors/hottextExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/hottextExtractor.js +12 -4
- package/dist/extraction/extractors/index.d.ts +1 -0
- package/dist/extraction/extractors/index.d.ts.map +1 -1
- package/dist/extraction/extractors/index.js +4 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts +3 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/inlineChoiceExtractor.js +17 -4
- package/dist/extraction/extractors/matchExtractor.d.ts +5 -0
- package/dist/extraction/extractors/matchExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/matchExtractor.js +26 -0
- package/dist/extraction/extractors/orderExtractor.d.ts +2 -0
- package/dist/extraction/extractors/orderExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/orderExtractor.js +4 -0
- package/dist/extraction/extractors/portableCustomExtractor.d.ts +14 -0
- package/dist/extraction/extractors/portableCustomExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/portableCustomExtractor.js +96 -0
- package/dist/extraction/extractors/selectPointExtractor.js +5 -5
- package/dist/extraction/extractors/textEntryExtractor.d.ts +1 -0
- package/dist/extraction/extractors/textEntryExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/textEntryExtractor.js +6 -0
- package/dist/extraction/extractors/uploadExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/uploadExtractor.js +9 -2
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/pci/PciHost.d.ts +53 -0
- package/dist/pci/PciHost.d.ts.map +1 -0
- package/dist/pci/PciHost.js +116 -0
- package/dist/pci/types.d.ts +57 -0
- package/dist/pci/types.d.ts.map +1 -0
- package/dist/pci/types.js +19 -0
- package/dist/pnp/applyPnp.d.ts +9 -0
- package/dist/pnp/applyPnp.d.ts.map +1 -0
- package/dist/pnp/applyPnp.js +19 -0
- package/dist/pnp/parsePnpXml.d.ts +9 -0
- package/dist/pnp/parsePnpXml.d.ts.map +1 -0
- package/dist/pnp/parsePnpXml.js +101 -0
- package/dist/pnp/types.d.ts +40 -0
- package/dist/pnp/types.d.ts.map +1 -0
- package/dist/pnp/types.js +1 -0
- package/dist/types/index.d.ts +22 -8
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interactions.d.ts +90 -1
- package/dist/types/interactions.d.ts.map +1 -1
- package/package.json +19 -9
- package/src/__tests__/catalog.test.ts +267 -0
- package/src/__tests__/fixtures/pci/echo-pci.js +49 -0
- package/src/__tests__/glossaryTriggers.test.ts +411 -0
- package/src/__tests__/pci.test.ts +353 -0
- package/src/__tests__/pnp.test.ts +250 -0
- package/src/__tests__/qti3-extraction.test.ts +5 -5
- package/src/catalog/applyGlossaryTriggers.ts +232 -0
- package/src/catalog/catalogExtractor.ts +130 -0
- package/src/catalog/catalogLookup.ts +53 -0
- package/src/catalog/glossaryAction.ts +28 -0
- package/src/catalog/types.ts +37 -0
- package/src/components/ItemBody.svelte +134 -26
- package/src/components/ItemPlayer.svelte +6 -2
- package/src/components/index.ts +3 -0
- package/src/core/ComponentRegistry.ts +14 -0
- package/src/core/ItemRenderer.ts +4 -0
- package/src/core/Player.ts +174 -4
- package/src/core/rolePolicy.ts +34 -0
- package/src/core/urlPolicy.ts +5 -2
- package/src/element.ts +128 -0
- package/src/extraction/ExtractionRegistry.ts +5 -1
- package/src/extraction/extractors/associateExtractor.ts +4 -0
- package/src/extraction/extractors/choiceExtractor.ts +12 -1
- package/src/extraction/extractors/conformance-qti3-advanced.test.ts +239 -0
- package/src/extraction/extractors/conformance-qti3-basic.test.ts +82 -0
- package/src/extraction/extractors/conformance.test.ts +208 -0
- package/src/extraction/extractors/extendedTextExtractor.ts +6 -0
- package/src/extraction/extractors/gapMatchExtractor.ts +36 -21
- package/src/extraction/extractors/graphicAssociateExtractor.ts +4 -0
- package/src/extraction/extractors/graphicGapMatchExtractor.ts +82 -10
- package/src/extraction/extractors/hotspotExtractor.ts +26 -8
- package/src/extraction/extractors/hottextExtractor.ts +15 -5
- package/src/extraction/extractors/index.ts +4 -0
- package/src/extraction/extractors/inlineChoiceExtractor.ts +22 -5
- package/src/extraction/extractors/matchExtractor.ts +31 -4
- package/src/extraction/extractors/orderExtractor.ts +6 -0
- package/src/extraction/extractors/portableCustomExtractor.ts +122 -0
- package/src/extraction/extractors/selectPointExtractor.ts +5 -5
- package/src/extraction/extractors/textEntryExtractor.ts +7 -0
- package/src/extraction/extractors/uploadExtractor.ts +10 -2
- package/src/index.ts +17 -1
- package/src/pci/PciHost.ts +138 -0
- package/src/pci/types.ts +70 -0
- package/src/pnp/applyPnp.ts +23 -0
- package/src/pnp/parsePnpXml.ts +118 -0
- package/src/pnp/types.ts +33 -0
- package/src/types/index.ts +22 -8
- package/src/types/interactions.ts +81 -6
package/src/element.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pie-qti-item-player custom element.
|
|
3
|
+
*
|
|
4
|
+
* Side-effect import that registers <pie-qti-item-player>:
|
|
5
|
+
* import '@pie-qti/item-player/element';
|
|
6
|
+
*
|
|
7
|
+
* String/boolean props map to HTML attributes (item-xml, role, disabled).
|
|
8
|
+
* Complex props (typeset, i18n, security, onResponseChange, onSubmit, onComplete)
|
|
9
|
+
* are JS-only properties — set them on the element instance directly.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { mount, unmount } from 'svelte';
|
|
13
|
+
import ItemPlayer from './components/ItemPlayer.svelte';
|
|
14
|
+
import type { AdaptiveAttemptResult, PlayerSecurityConfig, QTIRole } from './types/index.js';
|
|
15
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
16
|
+
|
|
17
|
+
const TAG = 'pie-qti-item-player';
|
|
18
|
+
|
|
19
|
+
class PieQtiItemPlayerElement extends HTMLElement {
|
|
20
|
+
static observedAttributes = ['item-xml', 'role', 'disabled'];
|
|
21
|
+
|
|
22
|
+
#container: HTMLDivElement | null = null;
|
|
23
|
+
#instance: any = null;
|
|
24
|
+
|
|
25
|
+
// Attribute-backed props
|
|
26
|
+
#itemXml = '';
|
|
27
|
+
#role: QTIRole = 'candidate';
|
|
28
|
+
#disabled = false;
|
|
29
|
+
|
|
30
|
+
// JS-only props
|
|
31
|
+
#typeset: ((el: HTMLElement) => void) | undefined;
|
|
32
|
+
#i18n: I18nProvider | undefined;
|
|
33
|
+
#security: PlayerSecurityConfig | undefined;
|
|
34
|
+
#onResponseChange: ((id: string, value: unknown) => void) | undefined;
|
|
35
|
+
#onSubmit: ((responses: Record<string, unknown>, result: unknown) => void) | undefined;
|
|
36
|
+
#onComplete: ((result: AdaptiveAttemptResult) => void) | undefined;
|
|
37
|
+
|
|
38
|
+
// --- JS-only property accessors ---
|
|
39
|
+
|
|
40
|
+
get typeset() { return this.#typeset; }
|
|
41
|
+
set typeset(v: ((el: HTMLElement) => void) | undefined) { this.#typeset = v; this.#update(); }
|
|
42
|
+
|
|
43
|
+
get i18n() { return this.#i18n; }
|
|
44
|
+
set i18n(v: I18nProvider | undefined) { this.#i18n = v; this.#update(); }
|
|
45
|
+
|
|
46
|
+
get security() { return this.#security; }
|
|
47
|
+
set security(v: PlayerSecurityConfig | undefined) { this.#security = v; this.#update(); }
|
|
48
|
+
|
|
49
|
+
get onResponseChange() { return this.#onResponseChange; }
|
|
50
|
+
set onResponseChange(v: ((id: string, value: unknown) => void) | undefined) { this.#onResponseChange = v; this.#update(); }
|
|
51
|
+
|
|
52
|
+
get onSubmit() { return this.#onSubmit; }
|
|
53
|
+
set onSubmit(v: ((responses: Record<string, unknown>, result: unknown) => void) | undefined) { this.#onSubmit = v; this.#update(); }
|
|
54
|
+
|
|
55
|
+
get onComplete() { return this.#onComplete; }
|
|
56
|
+
set onComplete(v: ((result: AdaptiveAttemptResult) => void) | undefined) { this.#onComplete = v; this.#update(); }
|
|
57
|
+
|
|
58
|
+
// --- Lifecycle ---
|
|
59
|
+
|
|
60
|
+
connectedCallback() {
|
|
61
|
+
this.#mount();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
disconnectedCallback() {
|
|
65
|
+
this.#teardown();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
attributeChangedCallback(name: string, _old: string | null, value: string | null) {
|
|
69
|
+
if (name === 'item-xml') this.#itemXml = value ?? '';
|
|
70
|
+
else if (name === 'role') this.#role = (value ?? 'candidate') as QTIRole;
|
|
71
|
+
else if (name === 'disabled') this.#disabled = value !== null;
|
|
72
|
+
this.#update();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// --- Private helpers ---
|
|
76
|
+
|
|
77
|
+
#getProps() {
|
|
78
|
+
return {
|
|
79
|
+
itemXml: this.#itemXml,
|
|
80
|
+
role: this.#role,
|
|
81
|
+
disabled: this.#disabled,
|
|
82
|
+
typeset: this.#typeset,
|
|
83
|
+
i18n: this.#i18n,
|
|
84
|
+
security: this.#security,
|
|
85
|
+
onResponseChange: this.#onResponseChange,
|
|
86
|
+
onSubmit: this.#onSubmit,
|
|
87
|
+
onComplete: this.#onComplete,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#mount() {
|
|
92
|
+
if (this.#instance) return;
|
|
93
|
+
if (!this.#container) {
|
|
94
|
+
this.#container = document.createElement('div');
|
|
95
|
+
this.#container.style.display = 'contents';
|
|
96
|
+
this.appendChild(this.#container);
|
|
97
|
+
}
|
|
98
|
+
this.#instance = mount(ItemPlayer, { target: this.#container, props: this.#getProps() });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#update() {
|
|
102
|
+
if (!this.#instance) return;
|
|
103
|
+
if (typeof this.#instance.$set === 'function') {
|
|
104
|
+
this.#instance.$set(this.#getProps());
|
|
105
|
+
} else {
|
|
106
|
+
// Svelte 5 runes components: remount with new props
|
|
107
|
+
this.#teardown();
|
|
108
|
+
this.#mount();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#teardown() {
|
|
113
|
+
if (this.#instance) {
|
|
114
|
+
try { unmount(this.#instance); } catch { /* ignore */ }
|
|
115
|
+
this.#instance = null;
|
|
116
|
+
}
|
|
117
|
+
if (this.#container) {
|
|
118
|
+
this.#container.remove();
|
|
119
|
+
this.#container = null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!customElements.get(TAG)) {
|
|
125
|
+
customElements.define(TAG, PieQtiItemPlayerElement);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { PieQtiItemPlayerElement };
|
|
@@ -179,7 +179,11 @@ export class ExtractionRegistry {
|
|
|
179
179
|
// Evaluate canHandle in priority order (O(M) where M = extractors for this type)
|
|
180
180
|
for (const extractor of extractors) {
|
|
181
181
|
try {
|
|
182
|
-
|
|
182
|
+
const canHandle = extractor.canHandle(element, context);
|
|
183
|
+
const typeMatchedThroughMapper = !!this.elementNameMapper && extractor.elementTypes.some(
|
|
184
|
+
(type) => this.qti2xMapper.toCanonical(type) === lookupKey
|
|
185
|
+
);
|
|
186
|
+
if (canHandle || typeMatchedThroughMapper) {
|
|
183
187
|
// Cache the result
|
|
184
188
|
this.extractorCache.set(element, extractor);
|
|
185
189
|
return extractor;
|
|
@@ -15,6 +15,7 @@ export interface AssociateData {
|
|
|
15
15
|
text: string;
|
|
16
16
|
matchMax: number;
|
|
17
17
|
matchMin?: number;
|
|
18
|
+
matchGroup?: string[];
|
|
18
19
|
classes?: string[];
|
|
19
20
|
}>;
|
|
20
21
|
shuffle: boolean;
|
|
@@ -51,12 +52,15 @@ export const standardAssociateExtractor: ElementExtractor<AssociateData> = {
|
|
|
51
52
|
const classes = utils.getClasses(choice);
|
|
52
53
|
const matchMax = utils.getNumberAttribute(choice, 'matchMax', 1);
|
|
53
54
|
const matchMin = utils.getNumberAttribute(choice, 'matchMin', 0);
|
|
55
|
+
const matchGroupRaw = utils.getAttribute(choice, 'matchGroup', '');
|
|
56
|
+
const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
|
|
54
57
|
|
|
55
58
|
return {
|
|
56
59
|
identifier: utils.getAttribute(choice, 'identifier', ''),
|
|
57
60
|
text: utils.getHtmlContent(choice),
|
|
58
61
|
matchMax,
|
|
59
62
|
...(matchMin > 0 ? { matchMin } : {}),
|
|
63
|
+
...(matchGroup.length > 0 ? { matchGroup } : {}),
|
|
60
64
|
...(classes.length > 0 ? { classes } : {}),
|
|
61
65
|
};
|
|
62
66
|
});
|
|
@@ -11,9 +11,10 @@ import type { ElementExtractor, ExtractionContext } from '../types.js';
|
|
|
11
11
|
* Choice data extracted from simpleChoice elements
|
|
12
12
|
*/
|
|
13
13
|
export interface ChoiceData {
|
|
14
|
-
choices: Array<{ identifier: string; text: string; classes?: string[] }>;
|
|
14
|
+
choices: Array<{ identifier: string; text: string; fixed?: boolean; classes?: string[] }>;
|
|
15
15
|
shuffle: boolean;
|
|
16
16
|
maxChoices: number;
|
|
17
|
+
minChoices: number;
|
|
17
18
|
prompt: string | null;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -40,9 +41,11 @@ export const standardChoiceExtractor: ElementExtractor<ChoiceData> = {
|
|
|
40
41
|
const simpleChoices = utils.getChildrenByTag(element, 'simpleChoice');
|
|
41
42
|
const choices = simpleChoices.map((choice) => {
|
|
42
43
|
const classes = utils.getClasses(choice);
|
|
44
|
+
const fixed = utils.getBooleanAttribute(choice, 'fixed');
|
|
43
45
|
return {
|
|
44
46
|
identifier: utils.getAttribute(choice, 'identifier', ''),
|
|
45
47
|
text: utils.getHtmlContent(choice),
|
|
48
|
+
...(fixed ? { fixed } : {}),
|
|
46
49
|
...(classes.length > 0 ? { classes } : {}),
|
|
47
50
|
};
|
|
48
51
|
});
|
|
@@ -54,12 +57,20 @@ export const standardChoiceExtractor: ElementExtractor<ChoiceData> = {
|
|
|
54
57
|
// Extract attributes
|
|
55
58
|
const shuffle = utils.getBooleanAttribute(element, 'shuffle');
|
|
56
59
|
const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);
|
|
60
|
+
const minChoices = utils.getNumberAttribute(element, 'minChoices', 0);
|
|
61
|
+
const interactionClasses = utils.getClasses(element);
|
|
62
|
+
const maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;
|
|
63
|
+
const minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;
|
|
57
64
|
|
|
58
65
|
return {
|
|
59
66
|
choices,
|
|
60
67
|
shuffle,
|
|
61
68
|
maxChoices,
|
|
69
|
+
minChoices,
|
|
62
70
|
prompt,
|
|
71
|
+
...(interactionClasses.length > 0 ? { interactionClasses } : {}),
|
|
72
|
+
...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),
|
|
73
|
+
...(minSelectionsMessage ? { minSelectionsMessage } : {}),
|
|
63
74
|
};
|
|
64
75
|
},
|
|
65
76
|
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { describe, expect, it } 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 Advanced clean-room item extraction', () => {
|
|
12
|
+
it('Q6: extracts gap match selection messages and gap choices', () => {
|
|
13
|
+
const xml = qti3Item(
|
|
14
|
+
'qti3-gap-match',
|
|
15
|
+
`<qti-gap-match-interaction response-identifier="RESPONSE"
|
|
16
|
+
class="qti-choices-top"
|
|
17
|
+
data-max-selections-message="You have used all labels."
|
|
18
|
+
data-min-selections-message="Use at least one label.">
|
|
19
|
+
<qti-prompt>Complete the sentence.</qti-prompt>
|
|
20
|
+
<qti-gap-text identifier="producer" match-max="1">producer</qti-gap-text>
|
|
21
|
+
<qti-gap-text identifier="consumer" match-max="1">consumer</qti-gap-text>
|
|
22
|
+
<p>A plant is a <qti-gap identifier="gap_1"/>.</p>
|
|
23
|
+
</qti-gap-match-interaction>`,
|
|
24
|
+
'<qti-response-declaration identifier="RESPONSE" cardinality="multiple" base-type="directedPair"/>'
|
|
25
|
+
);
|
|
26
|
+
const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
|
|
27
|
+
|
|
28
|
+
expect(interaction.type).toBe('gapMatchInteraction');
|
|
29
|
+
expect(interaction.interactionClasses).toContain('qti-choices-top');
|
|
30
|
+
expect(interaction.maxSelectionsMessage).toBe('You have used all labels.');
|
|
31
|
+
expect(interaction.minSelectionsMessage).toBe('Use at least one label.');
|
|
32
|
+
expect(interaction.gaps).toHaveLength(1);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('Q8: extracts graphic gap match choices and hotspots', () => {
|
|
36
|
+
const xml = qti3Item(
|
|
37
|
+
'qti3-graphic-gap',
|
|
38
|
+
`<qti-graphic-gap-match-interaction response-identifier="RESPONSE">
|
|
39
|
+
<qti-object data="images/food-web.svg" type="image/svg+xml" width="500" height="300">Food web</qti-object>
|
|
40
|
+
<qti-gap-text identifier="grass" match-max="1">Grass</qti-gap-text>
|
|
41
|
+
<qti-gap-img identifier="hawk" match-max="1" src="images/hawk.svg"/>
|
|
42
|
+
<qti-associable-hotspot identifier="A" match-max="1" shape="rect" coords="20,20,120,80"/>
|
|
43
|
+
<qti-associable-hotspot identifier="B" match-max="1" shape="circle" coords="350,140,32"/>
|
|
44
|
+
</qti-graphic-gap-match-interaction>`,
|
|
45
|
+
'<qti-response-declaration identifier="RESPONSE" cardinality="multiple" base-type="directedPair"/>'
|
|
46
|
+
);
|
|
47
|
+
const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
|
|
48
|
+
|
|
49
|
+
expect(interaction.type).toBe('graphicGapMatchInteraction');
|
|
50
|
+
expect(interaction.imageData.src).toBe('images/food-web.svg');
|
|
51
|
+
expect(interaction.gapTexts).toHaveLength(1);
|
|
52
|
+
expect(interaction.gapImages).toHaveLength(1);
|
|
53
|
+
expect(interaction.hotspots).toHaveLength(2);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('Q10: extracts hotspot shapes from QTI 3.0 element names', () => {
|
|
57
|
+
const xml = qti3Item(
|
|
58
|
+
'qti3-hotspot',
|
|
59
|
+
`<qti-hotspot-interaction response-identifier="RESPONSE" max-choices="1">
|
|
60
|
+
<qti-object data="images/water-cycle.svg" type="image/svg+xml" width="400" height="300">Water cycle</qti-object>
|
|
61
|
+
<qti-hotspot-choice identifier="evaporation" shape="circle" coords="100,200,35"/>
|
|
62
|
+
<qti-hotspot-choice identifier="condensation" shape="poly" coords="210,60,260,70,250,120,205,115"/>
|
|
63
|
+
</qti-hotspot-interaction>`,
|
|
64
|
+
'<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
|
|
65
|
+
);
|
|
66
|
+
const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
|
|
67
|
+
|
|
68
|
+
expect(interaction.type).toBe('hotspotInteraction');
|
|
69
|
+
expect(interaction.maxChoices).toBe(1);
|
|
70
|
+
expect(interaction.hotspotChoices.map((h: any) => h.shape)).toEqual(['circle', 'poly']);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('Q11: extracts hottext choices from QTI 3.0 markup', () => {
|
|
74
|
+
const xml = qti3Item(
|
|
75
|
+
'qti3-hottext',
|
|
76
|
+
`<qti-hottext-interaction response-identifier="RESPONSE" max-choices="1">
|
|
77
|
+
<qti-prompt>Select the adjective.</qti-prompt>
|
|
78
|
+
<p>The <qti-hottext identifier="word_1">bright</qti-hottext> star <qti-hottext identifier="word_2">shines</qti-hottext>.</p>
|
|
79
|
+
</qti-hottext-interaction>`,
|
|
80
|
+
'<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
|
|
81
|
+
);
|
|
82
|
+
const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
|
|
83
|
+
|
|
84
|
+
expect(interaction.type).toBe('hottextInteraction');
|
|
85
|
+
expect(interaction.hottextChoices.map((h: any) => h.identifier)).toEqual(['word_1', 'word_2']);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('Q12: extracts inline choices with MathML content', () => {
|
|
89
|
+
const xml = qti3Item(
|
|
90
|
+
'qti3-inline-choice',
|
|
91
|
+
`<p>The value of
|
|
92
|
+
<math xmlns="http://www.w3.org/1998/Math/MathML"><mn>2</mn><mo>+</mo><mn>3</mn></math>
|
|
93
|
+
is <qti-inline-choice-interaction response-identifier="RESPONSE">
|
|
94
|
+
<qti-inline-choice identifier="five">5</qti-inline-choice>
|
|
95
|
+
<qti-inline-choice identifier="six">6</qti-inline-choice>
|
|
96
|
+
</qti-inline-choice-interaction>.
|
|
97
|
+
</p>`,
|
|
98
|
+
'<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
|
|
99
|
+
);
|
|
100
|
+
const player = new Player({ itemXml: xml });
|
|
101
|
+
const interaction = player.getInteractionData()[0] as any;
|
|
102
|
+
|
|
103
|
+
expect(interaction.type).toBe('inlineChoiceInteraction');
|
|
104
|
+
expect(interaction.choices).toHaveLength(2);
|
|
105
|
+
expect(player.getItemBodyHtml()).toContain('<math');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('Q13: extracts tabular match shared vocabulary classes', () => {
|
|
109
|
+
const xml = qti3Item(
|
|
110
|
+
'qti3-match',
|
|
111
|
+
`<qti-match-interaction response-identifier="RESPONSE" max-associations="2"
|
|
112
|
+
class="qti-match-tabular qti-header-hidden">
|
|
113
|
+
<qti-simple-match-set>
|
|
114
|
+
<qti-simple-associable-choice identifier="herbivore" match-max="1">Herbivore</qti-simple-associable-choice>
|
|
115
|
+
<qti-simple-associable-choice identifier="carnivore" match-max="1">Carnivore</qti-simple-associable-choice>
|
|
116
|
+
</qti-simple-match-set>
|
|
117
|
+
<qti-simple-match-set>
|
|
118
|
+
<qti-simple-associable-choice identifier="eats_plants" match-max="1">Eats plants</qti-simple-associable-choice>
|
|
119
|
+
<qti-simple-associable-choice identifier="eats_animals" match-max="1">Eats animals</qti-simple-associable-choice>
|
|
120
|
+
</qti-simple-match-set>
|
|
121
|
+
</qti-match-interaction>`,
|
|
122
|
+
'<qti-response-declaration identifier="RESPONSE" cardinality="multiple" base-type="directedPair"/>'
|
|
123
|
+
);
|
|
124
|
+
const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
|
|
125
|
+
|
|
126
|
+
expect(interaction.type).toBe('matchInteraction');
|
|
127
|
+
expect(interaction.interactionClasses).toContain('qti-match-tabular');
|
|
128
|
+
expect(interaction.interactionClasses).toContain('qti-header-hidden');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('I17: extracts composite QTI 3.0 items with multiple interactions', () => {
|
|
132
|
+
const xml = qti3Item(
|
|
133
|
+
'qti3-composite',
|
|
134
|
+
`<qti-choice-interaction response-identifier="CHOICE" max-choices="1">
|
|
135
|
+
<qti-simple-choice identifier="A">A</qti-simple-choice>
|
|
136
|
+
<qti-simple-choice identifier="B">B</qti-simple-choice>
|
|
137
|
+
</qti-choice-interaction>
|
|
138
|
+
<p>Short answer: <qti-text-entry-interaction response-identifier="TEXT" expected-length="12"/></p>
|
|
139
|
+
<qti-extended-text-interaction response-identifier="ESSAY" expected-lines="4"/>`,
|
|
140
|
+
`<qti-response-declaration identifier="CHOICE" cardinality="single" base-type="identifier"/>
|
|
141
|
+
<qti-response-declaration identifier="TEXT" cardinality="single" base-type="string"/>
|
|
142
|
+
<qti-response-declaration identifier="ESSAY" cardinality="single" base-type="string"/>`
|
|
143
|
+
);
|
|
144
|
+
const types = new Player({ itemXml: xml }).getInteractionData().map((i) => i.type).sort();
|
|
145
|
+
|
|
146
|
+
expect(types).toEqual(['choiceInteraction', 'extendedTextInteraction', 'textEntryInteraction']);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('QTI 3.0 Advanced clean-room content preservation', () => {
|
|
151
|
+
it('I4: preserves shared stimulus references for package-level stimulus loading', () => {
|
|
152
|
+
const xml = qti3Item(
|
|
153
|
+
'qti3-shared-stimulus',
|
|
154
|
+
`<qti-assessment-stimulus-ref identifier="stimulus_1" href="../stimuli/river-study.xml" data-stimulus-idref="stimulus_1"/>
|
|
155
|
+
<p data-stimulus-idref="stimulus_1"></p>
|
|
156
|
+
<qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
|
|
157
|
+
<qti-simple-choice identifier="A">Erosion</qti-simple-choice>
|
|
158
|
+
<qti-simple-choice identifier="B">Condensation</qti-simple-choice>
|
|
159
|
+
</qti-choice-interaction>`,
|
|
160
|
+
'<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
|
|
161
|
+
);
|
|
162
|
+
const html = new Player({ itemXml: xml }).getItemBodyHtml();
|
|
163
|
+
|
|
164
|
+
expect(html).toContain('qti-assessment-stimulus-ref');
|
|
165
|
+
expect(html).toContain('data-stimulus-idref="stimulus_1"');
|
|
166
|
+
expect(html).toContain('../stimuli/river-study.xml');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('I19b/I20: preserves full Shared Vocabulary classes in item body HTML', () => {
|
|
170
|
+
const xml = qti3Item(
|
|
171
|
+
'qti3-shared-vocabulary',
|
|
172
|
+
`<div class="qti-align-center qti-fullwidth">
|
|
173
|
+
<p class="qti-underline qti-italic">Observe the emphasized vocabulary.</p>
|
|
174
|
+
</div>
|
|
175
|
+
<qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
|
|
176
|
+
<qti-simple-choice identifier="A">Kept</qti-simple-choice>
|
|
177
|
+
</qti-choice-interaction>`,
|
|
178
|
+
'<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
|
|
179
|
+
);
|
|
180
|
+
const html = new Player({ itemXml: xml }).getItemBodyHtml();
|
|
181
|
+
|
|
182
|
+
expect(html).toContain('qti-underline');
|
|
183
|
+
expect(html).toContain('qti-italic');
|
|
184
|
+
expect(html).toContain('qti-align-center');
|
|
185
|
+
expect(html).toContain('qti-fullwidth');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('P7: tolerates QTI metadata while delivering item content', () => {
|
|
189
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
190
|
+
<qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
|
|
191
|
+
xmlns:lom="http://ltsc.ieee.org/xsd/LOM"
|
|
192
|
+
identifier="qti3-metadata" title="Metadata Item" adaptive="false" time-dependent="false">
|
|
193
|
+
<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>
|
|
194
|
+
<lom:lom><lom:general><lom:title><lom:string>Clean-room metadata</lom:string></lom:title></lom:general></lom:lom>
|
|
195
|
+
<qti-item-body>
|
|
196
|
+
<qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
|
|
197
|
+
<qti-simple-choice identifier="A">Metadata is not candidate-visible.</qti-simple-choice>
|
|
198
|
+
</qti-choice-interaction>
|
|
199
|
+
</qti-item-body>
|
|
200
|
+
</qti-assessment-item>`;
|
|
201
|
+
const player = new Player({ itemXml: xml });
|
|
202
|
+
|
|
203
|
+
expect(player.getInteractionData()).toHaveLength(1);
|
|
204
|
+
expect(player.getItemBodyHtml()).toContain('Metadata is not candidate-visible');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('A13/A15: preserves caption tracks and glossary catalog references', () => {
|
|
208
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
209
|
+
<qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
|
|
210
|
+
identifier="qti3-captions-glossary" title="Captions and Glossary" adaptive="false" time-dependent="false">
|
|
211
|
+
<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>
|
|
212
|
+
<qti-catalog-info>
|
|
213
|
+
<qti-card identifier="word-delta">
|
|
214
|
+
<qti-card-entry usage="glossary-on-screen">
|
|
215
|
+
<qti-html-content>A landform where a river divides before entering a larger body of water.</qti-html-content>
|
|
216
|
+
</qti-card-entry>
|
|
217
|
+
</qti-card>
|
|
218
|
+
</qti-catalog-info>
|
|
219
|
+
<qti-item-body>
|
|
220
|
+
<video controls="controls" width="320">
|
|
221
|
+
<source src="media/river-delta.mp4" type="video/mp4"/>
|
|
222
|
+
<track kind="captions" srclang="en" src="media/river-delta-captions.vtt" label="English captions"/>
|
|
223
|
+
</video>
|
|
224
|
+
<p>The <span data-catalog-idref="word-delta">delta</span> changes over time.</p>
|
|
225
|
+
<qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
|
|
226
|
+
<qti-simple-choice identifier="A">True</qti-simple-choice>
|
|
227
|
+
</qti-choice-interaction>
|
|
228
|
+
</qti-item-body>
|
|
229
|
+
</qti-assessment-item>`;
|
|
230
|
+
const player = new Player({ itemXml: xml });
|
|
231
|
+
const html = player.getItemBodyHtml();
|
|
232
|
+
|
|
233
|
+
expect(html).toContain('<video');
|
|
234
|
+
expect(html).toContain('<track');
|
|
235
|
+
expect(html).toContain('kind="captions"');
|
|
236
|
+
expect(html).toContain('data-catalog-idref="word-delta"');
|
|
237
|
+
expect(player.getCatalogEntry('word-delta', 'glossary-on-screen')).toContain('river divides');
|
|
238
|
+
});
|
|
239
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
});
|