@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.
Files changed (148) hide show
  1. package/README.md +21 -18
  2. package/dist/catalog/applyGlossaryTriggers.d.ts +15 -0
  3. package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -0
  4. package/dist/catalog/applyGlossaryTriggers.js +193 -0
  5. package/dist/catalog/catalogExtractor.d.ts +18 -0
  6. package/dist/catalog/catalogExtractor.d.ts.map +1 -0
  7. package/dist/catalog/catalogExtractor.js +114 -0
  8. package/dist/catalog/catalogLookup.d.ts +18 -0
  9. package/dist/catalog/catalogLookup.d.ts.map +1 -0
  10. package/dist/catalog/catalogLookup.js +44 -0
  11. package/dist/catalog/glossaryAction.d.ts +17 -0
  12. package/dist/catalog/glossaryAction.d.ts.map +1 -0
  13. package/dist/catalog/glossaryAction.js +21 -0
  14. package/dist/catalog/types.d.ts +26 -0
  15. package/dist/catalog/types.d.ts.map +1 -0
  16. package/dist/catalog/types.js +6 -0
  17. package/dist/core/ComponentRegistry.d.ts +9 -0
  18. package/dist/core/ComponentRegistry.d.ts.map +1 -1
  19. package/dist/core/ComponentRegistry.js +14 -0
  20. package/dist/core/ItemRenderer.d.ts.map +1 -1
  21. package/dist/core/ItemRenderer.js +3 -0
  22. package/dist/core/Player.d.ts +52 -0
  23. package/dist/core/Player.d.ts.map +1 -1
  24. package/dist/core/Player.js +158 -4
  25. package/dist/core/rolePolicy.d.ts +16 -0
  26. package/dist/core/rolePolicy.d.ts.map +1 -0
  27. package/dist/core/rolePolicy.js +15 -0
  28. package/dist/core/urlPolicy.d.ts.map +1 -1
  29. package/dist/core/urlPolicy.js +5 -2
  30. package/dist/element.d.ts +22 -0
  31. package/dist/element.js +5327 -0
  32. package/dist/element.js.map +1 -0
  33. package/dist/extraction/ExtractionRegistry.d.ts.map +1 -1
  34. package/dist/extraction/ExtractionRegistry.js +3 -1
  35. package/dist/extraction/extractors/associateExtractor.d.ts +1 -0
  36. package/dist/extraction/extractors/associateExtractor.d.ts.map +1 -1
  37. package/dist/extraction/extractors/associateExtractor.js +3 -0
  38. package/dist/extraction/extractors/choiceExtractor.d.ts +2 -0
  39. package/dist/extraction/extractors/choiceExtractor.d.ts.map +1 -1
  40. package/dist/extraction/extractors/choiceExtractor.js +10 -0
  41. package/dist/extraction/extractors/extendedTextExtractor.d.ts.map +1 -1
  42. package/dist/extraction/extractors/extendedTextExtractor.js +6 -0
  43. package/dist/extraction/extractors/gapMatchExtractor.d.ts +1 -0
  44. package/dist/extraction/extractors/gapMatchExtractor.d.ts.map +1 -1
  45. package/dist/extraction/extractors/gapMatchExtractor.js +33 -20
  46. package/dist/extraction/extractors/graphicAssociateExtractor.d.ts +1 -0
  47. package/dist/extraction/extractors/graphicAssociateExtractor.d.ts.map +1 -1
  48. package/dist/extraction/extractors/graphicAssociateExtractor.js +3 -0
  49. package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts +11 -0
  50. package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts.map +1 -1
  51. package/dist/extraction/extractors/graphicGapMatchExtractor.js +71 -10
  52. package/dist/extraction/extractors/hotspotExtractor.d.ts.map +1 -1
  53. package/dist/extraction/extractors/hotspotExtractor.js +27 -8
  54. package/dist/extraction/extractors/hottextExtractor.d.ts +1 -1
  55. package/dist/extraction/extractors/hottextExtractor.d.ts.map +1 -1
  56. package/dist/extraction/extractors/hottextExtractor.js +12 -4
  57. package/dist/extraction/extractors/index.d.ts +1 -0
  58. package/dist/extraction/extractors/index.d.ts.map +1 -1
  59. package/dist/extraction/extractors/index.js +4 -0
  60. package/dist/extraction/extractors/inlineChoiceExtractor.d.ts +3 -0
  61. package/dist/extraction/extractors/inlineChoiceExtractor.d.ts.map +1 -1
  62. package/dist/extraction/extractors/inlineChoiceExtractor.js +17 -4
  63. package/dist/extraction/extractors/matchExtractor.d.ts +5 -0
  64. package/dist/extraction/extractors/matchExtractor.d.ts.map +1 -1
  65. package/dist/extraction/extractors/matchExtractor.js +26 -0
  66. package/dist/extraction/extractors/orderExtractor.d.ts +2 -0
  67. package/dist/extraction/extractors/orderExtractor.d.ts.map +1 -1
  68. package/dist/extraction/extractors/orderExtractor.js +4 -0
  69. package/dist/extraction/extractors/portableCustomExtractor.d.ts +14 -0
  70. package/dist/extraction/extractors/portableCustomExtractor.d.ts.map +1 -0
  71. package/dist/extraction/extractors/portableCustomExtractor.js +96 -0
  72. package/dist/extraction/extractors/selectPointExtractor.js +5 -5
  73. package/dist/extraction/extractors/textEntryExtractor.d.ts +1 -0
  74. package/dist/extraction/extractors/textEntryExtractor.d.ts.map +1 -1
  75. package/dist/extraction/extractors/textEntryExtractor.js +6 -0
  76. package/dist/extraction/extractors/uploadExtractor.d.ts.map +1 -1
  77. package/dist/extraction/extractors/uploadExtractor.js +9 -2
  78. package/dist/index.d.ts +11 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +8 -1
  81. package/dist/pci/PciHost.d.ts +53 -0
  82. package/dist/pci/PciHost.d.ts.map +1 -0
  83. package/dist/pci/PciHost.js +116 -0
  84. package/dist/pci/types.d.ts +57 -0
  85. package/dist/pci/types.d.ts.map +1 -0
  86. package/dist/pci/types.js +19 -0
  87. package/dist/pnp/applyPnp.d.ts +9 -0
  88. package/dist/pnp/applyPnp.d.ts.map +1 -0
  89. package/dist/pnp/applyPnp.js +19 -0
  90. package/dist/pnp/parsePnpXml.d.ts +9 -0
  91. package/dist/pnp/parsePnpXml.d.ts.map +1 -0
  92. package/dist/pnp/parsePnpXml.js +101 -0
  93. package/dist/pnp/types.d.ts +40 -0
  94. package/dist/pnp/types.d.ts.map +1 -0
  95. package/dist/pnp/types.js +1 -0
  96. package/dist/types/index.d.ts +22 -8
  97. package/dist/types/index.d.ts.map +1 -1
  98. package/dist/types/interactions.d.ts +90 -1
  99. package/dist/types/interactions.d.ts.map +1 -1
  100. package/package.json +19 -9
  101. package/src/__tests__/catalog.test.ts +267 -0
  102. package/src/__tests__/fixtures/pci/echo-pci.js +49 -0
  103. package/src/__tests__/glossaryTriggers.test.ts +411 -0
  104. package/src/__tests__/pci.test.ts +353 -0
  105. package/src/__tests__/pnp.test.ts +250 -0
  106. package/src/__tests__/qti3-extraction.test.ts +5 -5
  107. package/src/catalog/applyGlossaryTriggers.ts +232 -0
  108. package/src/catalog/catalogExtractor.ts +130 -0
  109. package/src/catalog/catalogLookup.ts +53 -0
  110. package/src/catalog/glossaryAction.ts +28 -0
  111. package/src/catalog/types.ts +37 -0
  112. package/src/components/ItemBody.svelte +134 -26
  113. package/src/components/ItemPlayer.svelte +6 -2
  114. package/src/components/index.ts +3 -0
  115. package/src/core/ComponentRegistry.ts +14 -0
  116. package/src/core/ItemRenderer.ts +4 -0
  117. package/src/core/Player.ts +174 -4
  118. package/src/core/rolePolicy.ts +34 -0
  119. package/src/core/urlPolicy.ts +5 -2
  120. package/src/element.ts +128 -0
  121. package/src/extraction/ExtractionRegistry.ts +5 -1
  122. package/src/extraction/extractors/associateExtractor.ts +4 -0
  123. package/src/extraction/extractors/choiceExtractor.ts +12 -1
  124. package/src/extraction/extractors/conformance-qti3-advanced.test.ts +239 -0
  125. package/src/extraction/extractors/conformance-qti3-basic.test.ts +82 -0
  126. package/src/extraction/extractors/conformance.test.ts +208 -0
  127. package/src/extraction/extractors/extendedTextExtractor.ts +6 -0
  128. package/src/extraction/extractors/gapMatchExtractor.ts +36 -21
  129. package/src/extraction/extractors/graphicAssociateExtractor.ts +4 -0
  130. package/src/extraction/extractors/graphicGapMatchExtractor.ts +82 -10
  131. package/src/extraction/extractors/hotspotExtractor.ts +26 -8
  132. package/src/extraction/extractors/hottextExtractor.ts +15 -5
  133. package/src/extraction/extractors/index.ts +4 -0
  134. package/src/extraction/extractors/inlineChoiceExtractor.ts +22 -5
  135. package/src/extraction/extractors/matchExtractor.ts +31 -4
  136. package/src/extraction/extractors/orderExtractor.ts +6 -0
  137. package/src/extraction/extractors/portableCustomExtractor.ts +122 -0
  138. package/src/extraction/extractors/selectPointExtractor.ts +5 -5
  139. package/src/extraction/extractors/textEntryExtractor.ts +7 -0
  140. package/src/extraction/extractors/uploadExtractor.ts +10 -2
  141. package/src/index.ts +17 -1
  142. package/src/pci/PciHost.ts +138 -0
  143. package/src/pci/types.ts +70 -0
  144. package/src/pnp/applyPnp.ts +23 -0
  145. package/src/pnp/parsePnpXml.ts +118 -0
  146. package/src/pnp/types.ts +33 -0
  147. package/src/types/index.ts +22 -8
  148. package/src/types/interactions.ts +81 -6
@@ -10,8 +10,10 @@ import type { ElementExtractor } from '../types.js';
10
10
  * Inline choice data extracted from inlineChoiceInteraction elements
11
11
  */
12
12
  export interface InlineChoiceData {
13
- choices: Array<{ identifier: string; text: string }>;
13
+ choices: Array<{ identifier: string; text: string; fixed?: boolean }>;
14
14
  shuffle: boolean;
15
+ /** Text from the QTI <label> child element; used as the placeholder "Select…" option */
16
+ label: string | null;
15
17
  }
16
18
 
17
19
  /**
@@ -35,17 +37,32 @@ export const standardInlineChoiceExtractor: ElementExtractor<InlineChoiceData> =
35
37
 
36
38
  // Extract choices (inlineChoice children)
37
39
  const inlineChoices = utils.getChildrenByTag(element, 'inlineChoice');
38
- const choices = inlineChoices.map((choice) => ({
39
- identifier: utils.getAttribute(choice, 'identifier', ''),
40
- text: utils.getTextContent(choice),
41
- }));
40
+ const choices = inlineChoices.map((choice) => {
41
+ const fixed = utils.getBooleanAttribute(choice, 'fixed');
42
+ return {
43
+ identifier: utils.getAttribute(choice, 'identifier', ''),
44
+ text: utils.getTextContent(choice),
45
+ ...(fixed ? { fixed } : {}),
46
+ };
47
+ });
48
+
49
+ // Extract <label> child — used as placeholder text in the dropdown
50
+ const labelElements = utils.getChildrenByTag(element, 'label');
51
+ const label = labelElements.length > 0 ? utils.getTextContent(labelElements[0]) : null;
52
+
53
+ // data-prompt: alternative placeholder for the dropdown default option
54
+ const dataPrompt = utils.getAttribute(element, 'data-prompt', '') || null;
42
55
 
43
56
  // Extract attributes
44
57
  const shuffle = utils.getBooleanAttribute(element, 'shuffle');
58
+ const interactionClasses = utils.getClasses(element);
45
59
 
46
60
  return {
47
61
  choices,
48
62
  shuffle,
63
+ label,
64
+ ...(dataPrompt ? { dataPrompt } : {}),
65
+ ...(interactionClasses.length > 0 ? { interactionClasses } : {}),
49
66
  };
50
67
  },
51
68
 
@@ -10,10 +10,11 @@ import type { ElementExtractor } from '../types.js';
10
10
  * Match data extracted from matchInteraction elements
11
11
  */
12
12
  export interface MatchData {
13
- sourceSet: Array<{ identifier: string; text: string; matchMax: number; classes?: string[] }>;
14
- targetSet: Array<{ identifier: string; text: string; matchMax: number; classes?: string[] }>;
13
+ sourceSet: Array<{ identifier: string; text: string; matchMax: number; matchMin?: number; matchGroup?: string[]; classes?: string[] }>;
14
+ targetSet: Array<{ identifier: string; text: string; matchMax: number; matchMin?: number; matchGroup?: string[]; classes?: string[] }>;
15
15
  shuffle: boolean;
16
16
  maxAssociations: number;
17
+ minAssociations?: number;
17
18
  prompt: string | null;
18
19
  }
19
20
 
@@ -43,8 +44,8 @@ export const standardMatchExtractor: ElementExtractor<MatchData> = {
43
44
  // In QTI, matchInteraction can have two simpleMatchSet elements
44
45
  const matchSets = utils.getChildrenByTag(element, 'simpleMatchSet');
45
46
 
46
- let sourceSet: Array<{ identifier: string; text: string; matchMax: number; classes?: string[] }> = [];
47
- let targetSet: Array<{ identifier: string; text: string; matchMax: number; classes?: string[] }> = [];
47
+ let sourceSet: Array<{ identifier: string; text: string; matchMax: number; matchMin?: number; matchGroup?: string[]; classes?: string[] }> = [];
48
+ let targetSet: Array<{ identifier: string; text: string; matchMax: number; matchMin?: number; matchGroup?: string[]; classes?: string[] }> = [];
48
49
 
49
50
  if (matchSets.length >= 2) {
50
51
  // Extract choices from first matchSet (source)
@@ -53,10 +54,15 @@ export const standardMatchExtractor: ElementExtractor<MatchData> = {
53
54
  sourceSet = sourceElements.map((choice) => {
54
55
  const classes = utils.getClasses(choice);
55
56
  const matchMax = utils.getNumberAttribute(choice, 'matchMax', 1);
57
+ const matchMin = utils.getNumberAttribute(choice, 'matchMin', 0);
58
+ const matchGroupRaw = utils.getAttribute(choice, 'matchGroup', '');
59
+ const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
56
60
  return {
57
61
  identifier: utils.getAttribute(choice, 'identifier', ''),
58
62
  text: utils.getHtmlContent(choice),
59
63
  matchMax,
64
+ ...(matchMin > 0 ? { matchMin } : {}),
65
+ ...(matchGroup.length > 0 ? { matchGroup } : {}),
60
66
  ...(classes.length > 0 ? { classes } : {}),
61
67
  };
62
68
  });
@@ -67,10 +73,15 @@ export const standardMatchExtractor: ElementExtractor<MatchData> = {
67
73
  targetSet = targetElements.map((choice) => {
68
74
  const classes = utils.getClasses(choice);
69
75
  const matchMax = utils.getNumberAttribute(choice, 'matchMax', 1);
76
+ const matchMin = utils.getNumberAttribute(choice, 'matchMin', 0);
77
+ const matchGroupRaw = utils.getAttribute(choice, 'matchGroup', '');
78
+ const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
70
79
  return {
71
80
  identifier: utils.getAttribute(choice, 'identifier', ''),
72
81
  text: utils.getHtmlContent(choice),
73
82
  matchMax,
83
+ ...(matchMin > 0 ? { matchMin } : {}),
84
+ ...(matchGroup.length > 0 ? { matchGroup } : {}),
74
85
  ...(classes.length > 0 ? { classes } : {}),
75
86
  };
76
87
  });
@@ -79,10 +90,15 @@ export const standardMatchExtractor: ElementExtractor<MatchData> = {
79
90
  const extractedChoices = allChoices.map((choice) => {
80
91
  const classes = utils.getClasses(choice);
81
92
  const matchMax = utils.getNumberAttribute(choice, 'matchMax', 1);
93
+ const matchMin = utils.getNumberAttribute(choice, 'matchMin', 0);
94
+ const matchGroupRaw = utils.getAttribute(choice, 'matchGroup', '');
95
+ const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
82
96
  return {
83
97
  identifier: utils.getAttribute(choice, 'identifier', ''),
84
98
  text: utils.getHtmlContent(choice),
85
99
  matchMax,
100
+ ...(matchMin > 0 ? { matchMin } : {}),
101
+ ...(matchGroup.length > 0 ? { matchGroup } : {}),
86
102
  ...(classes.length > 0 ? { classes } : {}),
87
103
  };
88
104
  });
@@ -93,6 +109,12 @@ export const standardMatchExtractor: ElementExtractor<MatchData> = {
93
109
  // Extract attributes
94
110
  const shuffle = utils.getBooleanAttribute(element, 'shuffle');
95
111
  const maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', 1);
112
+ const minAssociationsRaw = utils.getNumberAttribute(element, 'minAssociations', 0);
113
+ const minAssociations = minAssociationsRaw > 0 ? minAssociationsRaw : undefined;
114
+ const interactionClasses = utils.getClasses(element);
115
+ const maxSelectionsMessage = utils.getAttribute(element, 'data-qti-max-selections-message', '') || null;
116
+ const minSelectionsMessage = utils.getAttribute(element, 'data-qti-min-selections-message', '') || null;
117
+ const firstColumnHeader = utils.getAttribute(element, 'data-qti-first-column-header', '') || null;
96
118
 
97
119
  // Extract prompt (optional)
98
120
  const promptElements = utils.getChildrenByTag(element, 'prompt');
@@ -103,7 +125,12 @@ export const standardMatchExtractor: ElementExtractor<MatchData> = {
103
125
  targetSet,
104
126
  shuffle,
105
127
  maxAssociations,
128
+ ...(minAssociations !== undefined ? { minAssociations } : {}),
106
129
  prompt,
130
+ ...(interactionClasses.length > 0 ? { interactionClasses } : {}),
131
+ ...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),
132
+ ...(minSelectionsMessage ? { minSelectionsMessage } : {}),
133
+ ...(firstColumnHeader ? { firstColumnHeader } : {}),
107
134
  };
108
135
  },
109
136
 
@@ -12,6 +12,8 @@ import type { ElementExtractor } from '../types.js';
12
12
  export interface OrderData {
13
13
  choices: Array<{ identifier: string; text: string; fixed?: boolean; classes?: string[] }>;
14
14
  shuffle: boolean;
15
+ minChoices: number;
16
+ maxChoices: number;
15
17
  orientation?: string;
16
18
  prompt: string | null;
17
19
  }
@@ -56,11 +58,15 @@ export const standardOrderExtractor: ElementExtractor<OrderData> = {
56
58
  // Extract attributes
57
59
  const shuffle = utils.getBooleanAttribute(element, 'shuffle');
58
60
  const orientation = utils.getAttribute(element, 'orientation', 'vertical');
61
+ const minChoices = utils.getNumberAttribute(element, 'minChoices', 0);
62
+ const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 0);
59
63
 
60
64
  return {
61
65
  choices,
62
66
  shuffle,
63
67
  orientation,
68
+ minChoices,
69
+ maxChoices,
64
70
  prompt,
65
71
  };
66
72
  },
@@ -0,0 +1,122 @@
1
+ import type { ElementExtractor } from '../types.js';
2
+ import type { ExtractedPci } from '../../pci/types.js';
3
+
4
+ /**
5
+ * Extractor for <qti-portable-custom-interaction> (QTI 3.0) and
6
+ * <portableCustomInteraction> (QTI 2.x vendor extension).
7
+ *
8
+ * Extracts the module paths, markup, and config properties needed by PciHost
9
+ * to load and initialize the PCI JavaScript module.
10
+ *
11
+ * Priority 20 > standardCustomExtractor priority 10, so this runs first when
12
+ * both would match the same element.
13
+ */
14
+ export const portableCustomExtractor: ElementExtractor<ExtractedPci> = {
15
+ id: 'qti:portable-custom-interaction',
16
+ name: 'QTI Portable Custom Interaction',
17
+ priority: 20,
18
+ elementTypes: [
19
+ 'portableCustomInteraction',
20
+ 'qti-portable-custom-interaction',
21
+ ],
22
+ description: 'Extracts QTI 3.0 portable custom interaction module paths, markup, and config',
23
+
24
+ canHandle(element, _context) {
25
+ const tag = element.rawTagName?.toLowerCase() ?? '';
26
+ return (
27
+ tag === 'qti-portable-custom-interaction' ||
28
+ tag === 'portablecustominteraction'
29
+ );
30
+ },
31
+
32
+ extract(element, context) {
33
+ const { utils } = context;
34
+
35
+ const responseIdentifier = utils.getAttribute(element, 'responseIdentifier') ||
36
+ utils.getAttribute(element, 'response-identifier') || '';
37
+
38
+ const customInteractionTypeIdentifier =
39
+ utils.getAttribute(element, 'customInteractionTypeIdentifier') ||
40
+ utils.getAttribute(element, 'custom-interaction-type-identifier') || '';
41
+
42
+ // --- Module paths from <qti-interaction-modules>/<qti-interaction-module> ---
43
+ // These element names ARE in the standard QTI 3.0 element mapper so utils.querySelector works.
44
+ let primaryPath = '';
45
+ let fallbackPath: string | undefined;
46
+
47
+ const modulesEl =
48
+ utils.querySelector(element, 'qti-interaction-modules') ??
49
+ utils.querySelector(element, 'interactionmodules');
50
+
51
+ if (modulesEl) {
52
+ const moduleEl =
53
+ utils.querySelector(modulesEl, 'qti-interaction-module') ??
54
+ utils.querySelector(modulesEl, 'interactionmodule');
55
+
56
+ if (moduleEl) {
57
+ primaryPath =
58
+ utils.getAttribute(moduleEl, 'primaryPath') ||
59
+ utils.getAttribute(moduleEl, 'primary-path') || '';
60
+ const fb =
61
+ utils.getAttribute(moduleEl, 'fallbackPath') ||
62
+ utils.getAttribute(moduleEl, 'fallback-path') || '';
63
+ if (fb) fallbackPath = fb;
64
+ }
65
+ }
66
+
67
+ // --- Markup from <qti-interaction-markup> ---
68
+ const markupEl =
69
+ utils.querySelector(element, 'qti-interaction-markup') ??
70
+ utils.querySelector(element, 'interactionmarkup');
71
+
72
+ const markup = markupEl ? utils.getHtmlContent(markupEl) : '';
73
+
74
+ // --- Config from <qti-pci-properties>/<qti-pci-property> ---
75
+ // qti-pci-properties is NOT in the standard QTI 3.0 element mapper, so we use the
76
+ // native node-html-parser querySelector (available as element.querySelector on the raw element).
77
+ const config: Record<string, string> = {};
78
+
79
+ const rawEl = element as any;
80
+ const propsEl =
81
+ rawEl.querySelector?.('qti-pci-properties') ??
82
+ rawEl.querySelector?.('pciproperties');
83
+
84
+ if (propsEl) {
85
+ const propEls: any[] = [
86
+ ...(propsEl.querySelectorAll?.('qti-pci-property') ?? []),
87
+ ...(propsEl.querySelectorAll?.('pciproperty') ?? []),
88
+ ];
89
+ for (const propEl of propEls) {
90
+ const key = propEl.getAttribute?.('key') || propEl.getAttribute?.('name') || '';
91
+ const value = propEl.getAttribute?.('value') || (propEl.textContent ?? '').trim() || '';
92
+ if (key) config[key] = value;
93
+ }
94
+ }
95
+
96
+ return {
97
+ responseIdentifier,
98
+ customInteractionTypeIdentifier,
99
+ primaryPath,
100
+ fallbackPath,
101
+ markup,
102
+ config,
103
+ };
104
+ },
105
+
106
+ validate(data) {
107
+ const errors: string[] = [];
108
+ const warnings: string[] = [];
109
+
110
+ if (!data.responseIdentifier) {
111
+ errors.push('portableCustomInteraction is missing responseIdentifier');
112
+ }
113
+ if (!data.customInteractionTypeIdentifier) {
114
+ warnings.push('portableCustomInteraction is missing customInteractionTypeIdentifier');
115
+ }
116
+ if (!data.primaryPath) {
117
+ errors.push('portableCustomInteraction has no primaryPath in qti-interaction-modules');
118
+ }
119
+
120
+ return { valid: errors.length === 0, errors: errors.length ? errors : undefined, warnings: warnings.length ? warnings : undefined };
121
+ },
122
+ };
@@ -119,9 +119,9 @@ export const standardSelectPointExtractor: ElementExtractor<SelectPointData> = {
119
119
  errors.push('selectPointInteraction must have SVG content');
120
120
  }
121
121
 
122
- // Validate maxChoices
123
- if (data.maxChoices <= 0) {
124
- errors.push('maxChoices must be at least 1');
122
+ // Validate maxChoices — 0 means unlimited per QTI spec
123
+ if (data.maxChoices < 0) {
124
+ errors.push('maxChoices must be non-negative');
125
125
  }
126
126
 
127
127
  // Validate minChoices
@@ -129,8 +129,8 @@ export const standardSelectPointExtractor: ElementExtractor<SelectPointData> = {
129
129
  errors.push('minChoices must be non-negative');
130
130
  }
131
131
 
132
- // Validate minChoices <= maxChoices
133
- if (data.minChoices > data.maxChoices) {
132
+ // Validate minChoices <= maxChoices (skip when maxChoices=0, meaning unlimited)
133
+ if (data.maxChoices > 0 && data.minChoices > data.maxChoices) {
134
134
  errors.push(`minChoices (${data.minChoices}) must be less than or equal to maxChoices (${data.maxChoices})`);
135
135
  }
136
136
 
@@ -13,6 +13,7 @@ export interface TextEntryData {
13
13
  expectedLength: number;
14
14
  patternMask: string | null;
15
15
  placeholderText: string;
16
+ format?: string;
16
17
  }
17
18
 
18
19
  /**
@@ -40,11 +41,17 @@ export const standardTextEntryExtractor: ElementExtractor<TextEntryData> = {
40
41
  const expectedLength = utils.getNumberAttribute(element, 'expectedLength', 20);
41
42
  const patternMask = utils.getAttribute(element, 'patternMask', '');
42
43
  const placeholderText = utils.getAttribute(element, 'placeholderText', '');
44
+ const format = utils.getAttribute(element, 'format', '');
45
+ const interactionClasses = utils.getClasses(element);
46
+ const patternMaskMessage = utils.getAttribute(element, 'data-patternmask-message', '') || null;
43
47
 
44
48
  return {
45
49
  expectedLength,
46
50
  patternMask: patternMask || null,
47
51
  placeholderText,
52
+ ...(format ? { format } : {}),
53
+ ...(interactionClasses.length > 0 ? { interactionClasses } : {}),
54
+ ...(patternMaskMessage ? { patternMaskMessage } : {}),
48
55
  };
49
56
  },
50
57
 
@@ -34,9 +34,17 @@ export const standardUploadExtractor: ElementExtractor<UploadData> = {
34
34
  extract(element, context) {
35
35
  const { utils } = context;
36
36
 
37
- // Extract fileType child elements
37
+ // Extract fileType child elements (vendor / QTI 3.0 style)
38
38
  const fileTypeElements = utils.getChildrenByTag(element, 'fileType');
39
- const fileTypes = fileTypeElements.map((el) => utils.getTextContent(el));
39
+ let fileTypes = fileTypeElements.map((el) => utils.getTextContent(el));
40
+
41
+ // Fall back to QTI 2.x `type` attribute when no <fileType> children are present
42
+ if (fileTypes.length === 0) {
43
+ const typeAttr = utils.getAttribute(element, 'type', '');
44
+ if (typeAttr) {
45
+ fileTypes = typeAttr.split(/\s+/).filter(Boolean);
46
+ }
47
+ }
40
48
 
41
49
  // Extract all attributes
42
50
  const rawAttributes: Record<string, string> = {};
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @pie-qti/item-player
3
- * Modern QTI 2.2 player - Framework-agnostic with web components
3
+ * Modern QTI player (2.2/3.0) - Framework-agnostic with web components
4
4
  */
5
5
 
6
6
 
@@ -22,6 +22,7 @@ export {
22
22
  type ItemRendererConfig,
23
23
  } from './core/ItemRenderer.js';
24
24
  export { Player } from './core/Player.js';
25
+ export { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';
25
26
  // Plugin system (new extraction-based plugins)
26
27
  export {
27
28
  type PluginContext,
@@ -64,6 +65,21 @@ export {
64
65
 
65
66
  export { isResponseEmpty } from './utils/responseUtils.js';
66
67
 
68
+ // PNP profile (QTI 3.0 §6.2)
69
+ export type { PnpProfile } from './pnp/types.js';
70
+ export { applyPnpToRoot } from './pnp/applyPnp.js';
71
+ export { parsePnpXml } from './pnp/parsePnpXml.js';
72
+
73
+ // Catalog (QTI 3.0 §6.3)
74
+ export type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js';
75
+ export { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';
76
+ export { getCatalogEntry } from './catalog/catalogLookup.js';
77
+
78
+ // PCI — Portable Custom Interaction (QTI 3.0 §6.1)
79
+ export type { PciModule, PciBoundTo, ExtractedPci } from './pci/types.js';
80
+ export { PciLoadError } from './pci/types.js';
81
+ export { PciHost } from './pci/PciHost.js';
82
+
67
83
  // Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience
68
84
  // (heuristics are now in the shared ingestion layer)
69
85
  export {
@@ -0,0 +1,138 @@
1
+ import type { ExtractedPci, PciBoundTo, PciModule } from './types.js';
2
+ import { PciLoadError } from './types.js';
3
+
4
+ /**
5
+ * Loads, initializes, and manages the lifecycle of a single PCI module.
6
+ *
7
+ * Usage:
8
+ * const host = new PciHost(extractedData, baseUrl);
9
+ * await host.load();
10
+ * host.initialize(domNode);
11
+ * host.getResponse(); // returns current response
12
+ * host.destroy(); // cleanup on player teardown
13
+ */
14
+ export class PciHost {
15
+ private readonly data: ExtractedPci;
16
+ private readonly baseUrl: string;
17
+ private module: PciModule | null = null;
18
+ private _response: unknown = null;
19
+ private _onResponseChange: ((responseId: string, value: unknown) => void) | null = null;
20
+
21
+ constructor(data: ExtractedPci, baseUrl: string) {
22
+ this.data = data;
23
+ this.baseUrl = baseUrl;
24
+ }
25
+
26
+ /**
27
+ * Register a callback to fire when the PCI's response changes.
28
+ * The player calls this to wire the PCI into its internal response map.
29
+ */
30
+ public onResponseChange(callback: (responseId: string, value: unknown) => void): void {
31
+ this._onResponseChange = callback;
32
+ }
33
+
34
+ /**
35
+ * Load the PCI module from primaryPath, falling back to fallbackPath.
36
+ * Throws PciLoadError if both fail.
37
+ */
38
+ public async load(): Promise<void> {
39
+ const primary = this.resolveUrl(this.data.primaryPath);
40
+ try {
41
+ const mod = await this.dynamicImport(primary);
42
+ this.module = this.extractPciInterface(mod);
43
+ return;
44
+ } catch (primaryErr) {
45
+ if (!this.data.fallbackPath) {
46
+ throw new PciLoadError(this.data.primaryPath, undefined, primaryErr as Error);
47
+ }
48
+ }
49
+
50
+ const fallback = this.resolveUrl(this.data.fallbackPath!);
51
+ try {
52
+ const mod = await this.dynamicImport(fallback);
53
+ this.module = this.extractPciInterface(mod);
54
+ } catch (fallbackErr) {
55
+ throw new PciLoadError(
56
+ this.data.primaryPath,
57
+ this.data.fallbackPath,
58
+ fallbackErr as Error
59
+ );
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Initialize the PCI inside the given DOM element.
65
+ * Must be called after load() resolves.
66
+ */
67
+ public initialize(dom: HTMLElement): void {
68
+ if (!this.module) return;
69
+
70
+ const boundTo: PciBoundTo = {
71
+ onReady: () => {},
72
+ onResponseChange: (value: unknown) => {
73
+ this._response = value;
74
+ this._onResponseChange?.(this.data.responseIdentifier, value);
75
+ },
76
+ };
77
+
78
+ this.module.initialize(dom, this.data.config, boundTo);
79
+ }
80
+
81
+ /** Return the current response value from the PCI module. */
82
+ public getResponse(): unknown {
83
+ return this.module ? this.module.getResponse() : this._response;
84
+ }
85
+
86
+ /** Restore a response value into the PCI module (e.g. from session state). */
87
+ public setResponse(value: unknown): void {
88
+ this._response = value;
89
+ this.module?.setResponse(value);
90
+ }
91
+
92
+ /** Disable the PCI (e.g. when role is not candidate, or after final submission). */
93
+ public disable(): void {
94
+ this.module?.disable();
95
+ }
96
+
97
+ /** Re-enable the PCI. */
98
+ public enable(): void {
99
+ this.module?.enable();
100
+ }
101
+
102
+ /** Tear down the PCI and release all resources. */
103
+ public destroy(): void {
104
+ this.module?.destroy();
105
+ this.module = null;
106
+ }
107
+
108
+ // ---------------------------------------------------------------------------
109
+ // Private helpers
110
+ // ---------------------------------------------------------------------------
111
+
112
+ /** Thin wrapper around dynamic import — overridable in tests. */
113
+ protected dynamicImport(url: string): Promise<any> {
114
+ return import(/* @vite-ignore */ url);
115
+ }
116
+
117
+ private resolveUrl(path: string): string {
118
+ if (/^https?:\/\//.test(path) || path.startsWith('/')) return path;
119
+ // Relative path: resolve against baseUrl
120
+ const base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/';
121
+ return base + path;
122
+ }
123
+
124
+ /**
125
+ * Extract a PciModule from a dynamic import result.
126
+ * Supports: default export, named `getInstance` export, or the module itself.
127
+ */
128
+ private extractPciInterface(mod: any): PciModule {
129
+ const candidate = mod?.default ?? mod?.getInstance?.() ?? mod;
130
+ if (typeof candidate?.initialize !== 'function') {
131
+ throw new Error(
132
+ `PCI module at '${this.data.primaryPath}' does not export a valid PciModule interface ` +
133
+ '(expected .initialize, .getResponse, .setResponse, .disable, .enable, .destroy)'
134
+ );
135
+ }
136
+ return candidate as PciModule;
137
+ }
138
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * QTI 3.0 Portable Custom Interaction (PCI) types.
3
+ * Based on IMS QTI 3.0 Portable Custom Interaction specification.
4
+ */
5
+
6
+ /**
7
+ * Callbacks the player provides to a PCI module so it can signal state changes.
8
+ */
9
+ export interface PciBoundTo {
10
+ /** Called when the PCI has finished initializing and is ready to accept responses. */
11
+ onReady(): void;
12
+ /** Called whenever the candidate's response changes. */
13
+ onResponseChange(value: unknown): void;
14
+ }
15
+
16
+ /**
17
+ * Contract that every PCI module must fulfill.
18
+ * The module's default export (or named `getInstance` export) must implement this interface.
19
+ */
20
+ export interface PciModule {
21
+ /** Initialize the PCI inside the given DOM element. */
22
+ initialize(dom: HTMLElement, config: Record<string, string>, boundTo: PciBoundTo): void;
23
+ /** Return the current response value. */
24
+ getResponse(): unknown;
25
+ /** Restore a previously-captured response value. */
26
+ setResponse(value: unknown): void;
27
+ /** Disable candidate interaction (e.g. after submission or when role is not candidate). */
28
+ disable(): void;
29
+ /** Re-enable candidate interaction. */
30
+ enable(): void;
31
+ /** Tear down: remove event listeners, cancel timers, free resources. */
32
+ destroy(): void;
33
+ }
34
+
35
+ /**
36
+ * Extracted data from a <qti-portable-custom-interaction> element.
37
+ */
38
+ export interface ExtractedPci {
39
+ /** responseIdentifier attribute value. */
40
+ responseIdentifier: string;
41
+ /** customInteractionTypeIdentifier attribute value (URN identifying the PCI type). */
42
+ customInteractionTypeIdentifier: string;
43
+ /** Primary JS module path (required). */
44
+ primaryPath: string;
45
+ /** Fallback JS module path (optional). */
46
+ fallbackPath?: string;
47
+ /** Inner HTML of the <qti-interaction-markup> element. */
48
+ markup: string;
49
+ /** Key/value pairs from <qti-pci-properties>/<qti-pci-property>. */
50
+ config: Record<string, string>;
51
+ }
52
+
53
+ /**
54
+ * Thrown when a PCI module fails to load from both primary and fallback paths.
55
+ */
56
+ export class PciLoadError extends Error {
57
+ constructor(
58
+ public readonly primaryPath: string,
59
+ public readonly fallbackPath: string | undefined,
60
+ cause?: Error
61
+ ) {
62
+ super(
63
+ fallbackPath
64
+ ? `PCI module failed to load from '${primaryPath}' and fallback '${fallbackPath}'`
65
+ : `PCI module failed to load from '${primaryPath}'`
66
+ );
67
+ this.name = 'PciLoadError';
68
+ if (cause) Object.defineProperty(this, 'cause', { value: cause, writable: true, configurable: true });
69
+ }
70
+ }
@@ -0,0 +1,23 @@
1
+ import type { PnpProfile } from './types.js';
2
+
3
+ const ATTR = 'data-qti-colorscheme';
4
+
5
+ /**
6
+ * Apply a PNP profile to the player root element.
7
+ *
8
+ * Currently handles color scheme (data-qti-colorscheme attribute).
9
+ * Magnification is intentionally deferred — host stylesheets / browser zoom are sufficient for now.
10
+ */
11
+ export function applyPnpToRoot(rootEl: HTMLElement, pnp: PnpProfile | undefined): void {
12
+ const scheme = pnp?.display?.colorScheme;
13
+
14
+ if (!scheme || scheme === 'default') {
15
+ rootEl.removeAttribute(ATTR);
16
+ } else {
17
+ rootEl.setAttribute(ATTR, scheme);
18
+ }
19
+
20
+ if (pnp?.display?.magnification !== undefined) {
21
+ console.warn('[QTI Player] PnpProfile.display.magnification is not yet applied by the player. Use browser zoom or a host stylesheet instead.');
22
+ }
23
+ }