@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
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
import { normalizeHeuristicsConfig, type QtiHeuristicsConfig } from '@pie-qti/ims-cp-core';
|
|
6
6
|
import { processFeedbackInline } from './utils/feedbackUtils';
|
|
7
7
|
import { typesetAction } from './actions/typesetAction';
|
|
8
|
+
import { glossaryAction } from '../catalog/glossaryAction';
|
|
8
9
|
import { assignProps } from './utils/assignProps';
|
|
10
|
+
import { getRoleCapabilities } from '../core/rolePolicy';
|
|
9
11
|
|
|
10
12
|
interface Props {
|
|
11
13
|
player: Player;
|
|
@@ -17,6 +19,8 @@
|
|
|
17
19
|
onResponseChange?: (responseId: string, value: any) => void;
|
|
18
20
|
outcomeValues?: Record<string, any>; // Needed for feedbackInline visibility
|
|
19
21
|
heuristicsConfig?: QtiHeuristicsConfig; // Optional heuristics configuration
|
|
22
|
+
/** QTI 3.0 shared stimulus content: map of stimulus identifier → HTML string */
|
|
23
|
+
stimulusContent?: Record<string, string>;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
let {
|
|
@@ -29,6 +33,7 @@
|
|
|
29
33
|
onResponseChange = () => {},
|
|
30
34
|
outcomeValues = {},
|
|
31
35
|
heuristicsConfig,
|
|
36
|
+
stimulusContent = {},
|
|
32
37
|
}: Props = $props();
|
|
33
38
|
|
|
34
39
|
// Normalize heuristics configuration with defaults
|
|
@@ -36,17 +41,19 @@
|
|
|
36
41
|
|
|
37
42
|
// Get the component registry from the player
|
|
38
43
|
const componentRegistry = $derived(player.getComponentRegistry());
|
|
44
|
+
const roleCapabilities = $derived(getRoleCapabilities(role));
|
|
45
|
+
const effectiveDisabled = $derived(disabled || roleCapabilities.isReadOnly);
|
|
39
46
|
|
|
40
47
|
// Process interactions
|
|
41
48
|
const interactions = $derived<InteractionData[]>(player.getInteractionData());
|
|
42
49
|
|
|
43
|
-
// Get correct responses
|
|
50
|
+
// Get correct responses for roles allowed by policy.
|
|
44
51
|
const correctResponses = $derived.by(() => {
|
|
45
|
-
return
|
|
52
|
+
return roleCapabilities.canViewCorrectResponses ? player.getCorrectResponses() : {};
|
|
46
53
|
});
|
|
47
54
|
|
|
48
|
-
// Get components for block-level interactions only (not inline interactions)
|
|
49
|
-
//
|
|
55
|
+
// Get components for block-level interactions only (not inline interactions).
|
|
56
|
+
// Type is always normalized to QTI 2.x camelCase by Player (qti-text-entry-interaction → textEntryInteraction).
|
|
50
57
|
const interactionComponents = $derived(
|
|
51
58
|
interactions
|
|
52
59
|
.filter(
|
|
@@ -76,15 +83,55 @@
|
|
|
76
83
|
const itemBodyHtml = $derived.by(() => {
|
|
77
84
|
let html = player.getItemBodyHtml();
|
|
78
85
|
|
|
79
|
-
//
|
|
86
|
+
// QTI 3.0 Shared Stimulus: inject stimulus HTML at data-stimulus-idref docking points.
|
|
87
|
+
// Any stimulus identifier that has no docking div is prepended to the body.
|
|
88
|
+
if (stimulusContent && Object.keys(stimulusContent).length > 0) {
|
|
89
|
+
const docked = new Set<string>();
|
|
90
|
+
// Replace docking divs: <div ... data-stimulus-idref="ID" ...></div>
|
|
91
|
+
html = html.replace(
|
|
92
|
+
/<div([^>]*)\bdata-stimulus-idref="([^"]+)"([^>]*)>\s*<\/div>/gi,
|
|
93
|
+
(match, before, identifier, after) => {
|
|
94
|
+
const content = stimulusContent[identifier];
|
|
95
|
+
if (content) {
|
|
96
|
+
docked.add(identifier);
|
|
97
|
+
// Preserve any other attributes on the docking div
|
|
98
|
+
return `<div${before} data-stimulus-idref="${identifier}"${after} class="qti-stimulus-dock">${content}</div>`;
|
|
99
|
+
}
|
|
100
|
+
return match; // no content found — leave as-is
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
// Prepend any stimuli that had no docking div
|
|
104
|
+
const undocked = Object.entries(stimulusContent)
|
|
105
|
+
.filter(([id]) => !docked.has(id))
|
|
106
|
+
.map(([, content]) => `<div class="qti-stimulus-block">${content}</div>`)
|
|
107
|
+
.join('');
|
|
108
|
+
if (undocked) {
|
|
109
|
+
html = undocked + html;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Replace inline interactions with placeholders (they need to be rendered in-flow).
|
|
114
|
+
// Handles both QTI 2.x camelCase and QTI 3.0 kebab-case element names.
|
|
80
115
|
html = html
|
|
116
|
+
// QTI 2.x: <textEntryInteraction responseIdentifier="..." />
|
|
81
117
|
.replace(
|
|
82
118
|
/<textEntryInteraction[^>]*responseIdentifier="([^"]+)"[^>]*?(?:\/>|><\/textEntryInteraction>)/gi,
|
|
83
119
|
'[TEXTENTRY:$1]'
|
|
84
120
|
)
|
|
121
|
+
// QTI 3.0: <qti-text-entry-interaction response-identifier="..." />
|
|
122
|
+
.replace(
|
|
123
|
+
/<qti-text-entry-interaction[^>]*response-identifier="([^"]+)"[^>]*?(?:\/>|><\/qti-text-entry-interaction>)/gi,
|
|
124
|
+
'[TEXTENTRY:$1]'
|
|
125
|
+
)
|
|
126
|
+
// QTI 2.x: <inlineChoiceInteraction responseIdentifier="...">...</inlineChoiceInteraction>
|
|
85
127
|
.replace(
|
|
86
128
|
/<inlineChoiceInteraction[^>]*responseIdentifier="([^"]+)"[^>]*>[\s\S]*?<\/inlineChoiceInteraction>/gi,
|
|
87
129
|
'[INLINECHOICE:$1]'
|
|
130
|
+
)
|
|
131
|
+
// QTI 3.0: <qti-inline-choice-interaction response-identifier="...">...</qti-inline-choice-interaction>
|
|
132
|
+
.replace(
|
|
133
|
+
/<qti-inline-choice-interaction[^>]*response-identifier="([^"]+)"[^>]*>[\s\S]*?<\/qti-inline-choice-interaction>/gi,
|
|
134
|
+
'[INLINECHOICE:$1]'
|
|
88
135
|
);
|
|
89
136
|
|
|
90
137
|
// Process feedbackInline elements - conditionally show/hide based on outcome values
|
|
@@ -94,14 +141,15 @@
|
|
|
94
141
|
wrapWithSpan: false
|
|
95
142
|
});
|
|
96
143
|
|
|
97
|
-
// Wrap all block-level
|
|
98
|
-
//
|
|
144
|
+
// Wrap all block-level interaction elements with a hidden marker.
|
|
145
|
+
// Matches both QTI 2.x camelCase (*Interaction) and QTI 3.0 kebab-case (qti-*-interaction).
|
|
99
146
|
html = html.replace(
|
|
100
|
-
/<(\w+Interaction)(\s[^>]*)?>[\s\S]*?<\/\1>/gi,
|
|
147
|
+
/<(\w+Interaction|qti-[\w-]+-interaction)(\s[^>]*)?>[\s\S]*?<\/\1>/gi,
|
|
101
148
|
(match, tagName) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
149
|
+
const lower = tagName.toLowerCase();
|
|
150
|
+
// Skip inline interactions (already replaced with placeholders above)
|
|
151
|
+
if (lower === 'textentryinteraction' || lower === 'inlinechoiceinteraction' ||
|
|
152
|
+
lower === 'qti-text-entry-interaction' || lower === 'qti-inline-choice-interaction') {
|
|
105
153
|
return match;
|
|
106
154
|
}
|
|
107
155
|
// Wrap block interactions with a hidden span
|
|
@@ -163,9 +211,29 @@
|
|
|
163
211
|
onResponseChange(responseId, value);
|
|
164
212
|
}
|
|
165
213
|
|
|
214
|
+
let textEntryErrors = $state<Map<string, string>>(new Map());
|
|
215
|
+
|
|
166
216
|
function handleTextEntryInput(responseId: string, e: Event) {
|
|
167
|
-
const
|
|
217
|
+
const input = e.currentTarget as HTMLInputElement | null;
|
|
218
|
+
const value = input?.value ?? '';
|
|
168
219
|
handleResponseChange(responseId, value);
|
|
220
|
+
if (input?.validity.valid) {
|
|
221
|
+
const m = new Map(textEntryErrors);
|
|
222
|
+
m.delete(responseId);
|
|
223
|
+
textEntryErrors = m;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function handleTextEntryInvalid(responseId: string, e: Event, customMessage?: string | null) {
|
|
228
|
+
e.preventDefault();
|
|
229
|
+
const msg = customMessage
|
|
230
|
+
?? i18n?.t('interactions.textEntry.patternError', 'Please match the required format')
|
|
231
|
+
?? 'Please match the required format';
|
|
232
|
+
textEntryErrors = new Map(textEntryErrors).set(responseId, msg);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function handleTextEntryBlur(e: Event) {
|
|
236
|
+
(e.currentTarget as HTMLInputElement | null)?.checkValidity();
|
|
169
237
|
}
|
|
170
238
|
|
|
171
239
|
function handleInlineChoiceChange(responseId: string, e: Event) {
|
|
@@ -241,7 +309,7 @@
|
|
|
241
309
|
}
|
|
242
310
|
</script>
|
|
243
311
|
|
|
244
|
-
<div bind:this={rootEl} class="qti-item-body" use:typesetAction={{ typeset }}>
|
|
312
|
+
<div bind:this={rootEl} class="qti-item-body" use:typesetAction={{ typeset }} use:glossaryAction={{ player }}>
|
|
245
313
|
<!-- Item body with inline interactions -->
|
|
246
314
|
<div class="prose max-w-none mb-4">
|
|
247
315
|
<div class="inline-interaction-container">
|
|
@@ -249,25 +317,42 @@
|
|
|
249
317
|
{#if segment.type === 'html'}
|
|
250
318
|
{@html segment.content}
|
|
251
319
|
{:else if segment.type === 'textEntry'}
|
|
252
|
-
{@const correctAnswer =
|
|
253
|
-
{@const displayValue =
|
|
320
|
+
{@const correctAnswer = roleCapabilities.canViewCorrectResponses ? (correctResponses[segment.interaction.responseId] ?? null) : null}
|
|
321
|
+
{@const displayValue = roleCapabilities.canViewCorrectResponses && correctAnswer !== null ? correctAnswer : (responses[segment.interaction.responseId] || '')}
|
|
322
|
+
{@const inputWidthClass = (segment.interaction.interactionClasses ?? []).find((c: string) => c.startsWith('qti-input-width-'))}
|
|
323
|
+
{@const extraClasses = (segment.interaction.interactionClasses ?? []).filter((c: string) => !c.startsWith('qti-input-width-')).join(' ')}
|
|
254
324
|
<input
|
|
255
325
|
type="text"
|
|
256
|
-
class=
|
|
326
|
+
class={['input input-bordered input-sm inline-input', inputWidthClass ?? '', extraClasses].filter(Boolean).join(' ')}
|
|
257
327
|
class:border-success={correctAnswer !== null}
|
|
258
328
|
class:bg-success={correctAnswer !== null}
|
|
259
329
|
class:bg-opacity-10={correctAnswer !== null}
|
|
260
|
-
style=
|
|
261
|
-
placeholder=
|
|
330
|
+
style={inputWidthClass ? 'min-width: 100px; display: inline-block; margin: 0 4px;' : `width: ${segment.interaction.expectedLength * 8}px; min-width: 100px; display: inline-block; margin: 0 4px;`}
|
|
331
|
+
placeholder={segment.interaction.placeholderText || '...'}
|
|
332
|
+
pattern={segment.interaction.patternMask || undefined}
|
|
333
|
+
title={segment.interaction.patternMask ? `Format: ${segment.interaction.patternMask}` : undefined}
|
|
334
|
+
data-format={segment.interaction.format || undefined}
|
|
262
335
|
aria-label={`Text entry ${segment.interaction.responseId}${correctAnswer ? '. Correct answer: ' + correctAnswer : ''}`}
|
|
336
|
+
aria-invalid={textEntryErrors.has(segment.interaction.responseId) ? 'true' : undefined}
|
|
337
|
+
aria-describedby={textEntryErrors.has(segment.interaction.responseId) ? `${segment.interaction.responseId}-error` : undefined}
|
|
263
338
|
value={displayValue}
|
|
264
339
|
oninput={(e) => handleTextEntryInput(segment.interaction.responseId, e)}
|
|
265
|
-
{
|
|
340
|
+
oninvalid={(e) => handleTextEntryInvalid(segment.interaction.responseId, e, segment.interaction.patternMaskMessage)}
|
|
341
|
+
onblur={handleTextEntryBlur}
|
|
342
|
+
disabled={effectiveDisabled}
|
|
266
343
|
/>
|
|
344
|
+
{#if textEntryErrors.has(segment.interaction.responseId)}
|
|
345
|
+
<span
|
|
346
|
+
id="{segment.interaction.responseId}-error"
|
|
347
|
+
role="alert"
|
|
348
|
+
class="qti-text-entry-error text-error text-xs"
|
|
349
|
+
style="display: block;"
|
|
350
|
+
>{textEntryErrors.get(segment.interaction.responseId)}</span>
|
|
351
|
+
{/if}
|
|
267
352
|
{:else if segment.type === 'inlineChoice'}
|
|
268
|
-
{@const correctAnswer =
|
|
353
|
+
{@const correctAnswer = roleCapabilities.canViewCorrectResponses ? (correctResponses[segment.interaction.responseId] ?? null) : null}
|
|
269
354
|
{@const userResponse = responses[segment.interaction.responseId] || ''}
|
|
270
|
-
{@const displayValue =
|
|
355
|
+
{@const displayValue = roleCapabilities.canViewCorrectResponses && correctAnswer !== null ? correctAnswer : userResponse}
|
|
271
356
|
{@const correctChoice = findCorrectChoice(segment.interaction.choices, correctAnswer)}
|
|
272
357
|
<span class="inline-choice-wrapper" style="display: inline-block; position: relative;">
|
|
273
358
|
<select
|
|
@@ -279,9 +364,9 @@
|
|
|
279
364
|
aria-label={`Inline choice ${segment.interaction.responseId}${correctAnswer && correctChoice ? '. Correct answer: ' + (correctChoice as any).text : ''}`}
|
|
280
365
|
value={displayValue}
|
|
281
366
|
onchange={(e) => handleInlineChoiceChange(segment.interaction.responseId, e)}
|
|
282
|
-
{
|
|
367
|
+
disabled={effectiveDisabled}
|
|
283
368
|
>
|
|
284
|
-
<option value="">{i18n?.t('interactions.inline.selectPlaceholder', 'Select...')}</option>
|
|
369
|
+
<option value="">{segment.interaction.label ?? i18n?.t('interactions.inline.selectPlaceholder', 'Select...')}</option>
|
|
285
370
|
{#each segment.interaction.choices as choice}
|
|
286
371
|
{@const isCorrect = correctAnswer === choice.identifier}
|
|
287
372
|
<option value={choice.identifier}>
|
|
@@ -310,11 +395,11 @@
|
|
|
310
395
|
typeset,
|
|
311
396
|
interaction,
|
|
312
397
|
response: responses[interaction.responseId] ?? null,
|
|
313
|
-
correctResponse:
|
|
314
|
-
disabled,
|
|
398
|
+
correctResponse: roleCapabilities.canViewCorrectResponses ? correctRespForInteraction : null,
|
|
399
|
+
disabled: effectiveDisabled,
|
|
315
400
|
// Avoid invalid ARIA role values on custom-element hosts.
|
|
316
401
|
// Components default to candidate when role is omitted.
|
|
317
|
-
role:
|
|
402
|
+
role: roleCapabilities.canViewCorrectResponses ? 'scorer' : undefined,
|
|
318
403
|
}}
|
|
319
404
|
/>
|
|
320
405
|
{/each}
|
|
@@ -381,4 +466,27 @@
|
|
|
381
466
|
border-left: 2px solid var(--color-base-content, currentColor);
|
|
382
467
|
opacity: 0.8;
|
|
383
468
|
}
|
|
469
|
+
|
|
470
|
+
/* QTI 3.0 Shared Stimulus: stimulus blocks that were prepended before the item body */
|
|
471
|
+
:global(.qti-stimulus-block) {
|
|
472
|
+
margin-bottom: 1rem;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/* QTI 3.0 Shared Vocabulary: qti-input-width-N sets minimum input width in character units. */
|
|
476
|
+
:global(.qti-input-width-1) { min-width: 1ch; }
|
|
477
|
+
:global(.qti-input-width-2) { min-width: 2ch; }
|
|
478
|
+
:global(.qti-input-width-3) { min-width: 3ch; }
|
|
479
|
+
:global(.qti-input-width-4) { min-width: 4ch; }
|
|
480
|
+
:global(.qti-input-width-5) { min-width: 5ch; }
|
|
481
|
+
:global(.qti-input-width-6) { min-width: 6ch; }
|
|
482
|
+
:global(.qti-input-width-10) { min-width: 10ch; }
|
|
483
|
+
:global(.qti-input-width-15) { min-width: 15ch; }
|
|
484
|
+
:global(.qti-input-width-20) { min-width: 20ch; }
|
|
485
|
+
:global(.qti-input-width-25) { min-width: 25ch; }
|
|
486
|
+
:global(.qti-input-width-30) { min-width: 30ch; }
|
|
487
|
+
:global(.qti-input-width-35) { min-width: 35ch; }
|
|
488
|
+
:global(.qti-input-width-40) { min-width: 40ch; }
|
|
489
|
+
:global(.qti-input-width-45) { min-width: 45ch; }
|
|
490
|
+
:global(.qti-input-width-50) { min-width: 50ch; }
|
|
491
|
+
:global(.qti-input-width-72) { min-width: 72ch; }
|
|
384
492
|
</style>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Player } from '../core/Player';
|
|
3
3
|
import type { AdaptiveAttemptResult, ModalFeedback, PlayerSecurityConfig, QTIRole } from '../types';
|
|
4
4
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
5
|
+
import { typesetMathInElement } from '@pie-qti/typeset-katex';
|
|
5
6
|
import ItemBody from './ItemBody.svelte';
|
|
6
7
|
import ModalFeedbackDisplay from './ModalFeedbackDisplay.svelte';
|
|
7
8
|
|
|
@@ -31,6 +32,9 @@
|
|
|
31
32
|
onComplete,
|
|
32
33
|
}: Props = $props();
|
|
33
34
|
|
|
35
|
+
// Use host-provided typeset if given, otherwise fall back to the built-in KaTeX typesetter.
|
|
36
|
+
const effectiveTypeset = $derived(typeset ?? typesetMathInElement);
|
|
37
|
+
|
|
34
38
|
// Create player instance
|
|
35
39
|
let player = $state<Player | null>(null);
|
|
36
40
|
let responses = $state<Record<string, any>>({});
|
|
@@ -116,7 +120,7 @@
|
|
|
116
120
|
{responses}
|
|
117
121
|
{disabled}
|
|
118
122
|
{role}
|
|
119
|
-
{
|
|
123
|
+
typeset={effectiveTypeset}
|
|
120
124
|
{i18n}
|
|
121
125
|
{outcomeValues}
|
|
122
126
|
onResponseChange={handleResponseChange}
|
|
@@ -146,7 +150,7 @@
|
|
|
146
150
|
{/if}
|
|
147
151
|
|
|
148
152
|
<!-- Modal feedback display -->
|
|
149
|
-
<ModalFeedbackDisplay feedback={modalFeedback} onClose={closeFeedback} {
|
|
153
|
+
<ModalFeedbackDisplay feedback={modalFeedback} onClose={closeFeedback} typeset={effectiveTypeset} {i18n} />
|
|
150
154
|
{:else}
|
|
151
155
|
<div class="alert alert-info">
|
|
152
156
|
<span>{i18n?.t('item.loading') ?? 'item.loading'}</span>
|
package/src/components/index.ts
CHANGED
|
@@ -17,3 +17,6 @@ export { default as ModalFeedbackDisplay } from './ModalFeedbackDisplay.svelte';
|
|
|
17
17
|
|
|
18
18
|
// Utility actions (dependency-free)
|
|
19
19
|
export { typesetAction } from './actions/typesetAction';
|
|
20
|
+
|
|
21
|
+
// Catalog actions
|
|
22
|
+
export { glossaryAction, type GlossaryActionParams } from '../catalog/glossaryAction';
|
|
@@ -189,6 +189,20 @@ export class ComponentRegistry {
|
|
|
189
189
|
hasComponent(type: string): boolean {
|
|
190
190
|
return this.components.has(type) && this.components.get(type)!.length > 0;
|
|
191
191
|
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Get the tag name for a registered type by name (no canHandle evaluation).
|
|
195
|
+
* Useful for non-interaction components like catalogPopup where the type string
|
|
196
|
+
* is known and there is no InteractionData object to pass.
|
|
197
|
+
*
|
|
198
|
+
* Returns the highest-priority registered tag name for the type, or null if
|
|
199
|
+
* the type is not registered.
|
|
200
|
+
*/
|
|
201
|
+
getTagNameForType(type: string): string | null {
|
|
202
|
+
const components = this.components.get(type);
|
|
203
|
+
if (!components || components.length === 0) return null;
|
|
204
|
+
return components[0].config.tagName;
|
|
205
|
+
}
|
|
192
206
|
}
|
|
193
207
|
|
|
194
208
|
/**
|
package/src/core/ItemRenderer.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { QTIChangeEvent } from '../web-components/QTIInteractionElement.js'
|
|
|
11
11
|
import type { ComponentRegistry } from './ComponentRegistry.js';
|
|
12
12
|
import type { Player } from './Player.js';
|
|
13
13
|
import { htmlToString, toTrustedHtml } from './trustedTypes.js';
|
|
14
|
+
import { applyGlossaryTriggers } from '../catalog/applyGlossaryTriggers.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Configuration for ItemRenderer
|
|
@@ -105,6 +106,9 @@ export class ItemRenderer {
|
|
|
105
106
|
);
|
|
106
107
|
proseContainer.innerHTML = toTrustedHtml(processedHtml, this.player.getTrustedTypesPolicyName()) as any;
|
|
107
108
|
|
|
109
|
+
// Inject glossary/keyword-translation trigger buttons for [data-catalog-idref] terms
|
|
110
|
+
applyGlossaryTriggers(proseContainer, this.player);
|
|
111
|
+
|
|
108
112
|
wrapper.appendChild(proseContainer);
|
|
109
113
|
|
|
110
114
|
// Render block interactions as web components
|
package/src/core/Player.ts
CHANGED
|
@@ -61,6 +61,13 @@ import { createSeededRng } from './random.js';
|
|
|
61
61
|
import { sanitizeHtml } from './sanitizer.js';
|
|
62
62
|
import { toTrustedHtml } from './trustedTypes.js';
|
|
63
63
|
import { sanitizeResourceUrl } from './urlPolicy.js';
|
|
64
|
+
import type { PnpProfile } from '../pnp/types.js';
|
|
65
|
+
import { applyPnpToRoot } from '../pnp/applyPnp.js';
|
|
66
|
+
import type { CatalogIndex } from '../catalog/types.js';
|
|
67
|
+
import { extractCatalogFromItemXml, mergeCatalogs } from '../catalog/catalogExtractor.js';
|
|
68
|
+
import { getCatalogEntry } from '../catalog/catalogLookup.js';
|
|
69
|
+
import { PciHost } from '../pci/PciHost.js';
|
|
70
|
+
import type { ExtractedPci } from '../pci/types.js';
|
|
64
71
|
|
|
65
72
|
type DeclKind = 'response' | 'outcome' | 'template';
|
|
66
73
|
|
|
@@ -82,6 +89,10 @@ export class Player {
|
|
|
82
89
|
private responseProcessingProgram: ProcessingProgram | null = null;
|
|
83
90
|
private templateProcessingProgram: ProcessingProgram | null = null;
|
|
84
91
|
private outcomeProcessingProgram: ProcessingProgram | null = null;
|
|
92
|
+
private _pnp: PnpProfile | undefined;
|
|
93
|
+
private _rootEl: HTMLElement | undefined;
|
|
94
|
+
private _catalogIndex: CatalogIndex = new Map();
|
|
95
|
+
private _pciHosts: Map<string, PciHost> = new Map();
|
|
85
96
|
|
|
86
97
|
constructor(config: PlayerConfig) {
|
|
87
98
|
this.config = config;
|
|
@@ -196,12 +207,111 @@ export class Player {
|
|
|
196
207
|
);
|
|
197
208
|
}
|
|
198
209
|
|
|
210
|
+
// Store PNP profile for later use (applyPnpToRoot is called once a root element is available).
|
|
211
|
+
this._pnp = config.pnp;
|
|
212
|
+
|
|
213
|
+
// Build catalog index from item XML and optional shared catalog.
|
|
214
|
+
const itemCatalog = extractCatalogFromItemXml(this.itemXml);
|
|
215
|
+
if (config.catalogXml) {
|
|
216
|
+
const sharedCatalog = extractCatalogFromItemXml(config.catalogXml);
|
|
217
|
+
// Item-level wins on collision: merge shared first, then override with item entries.
|
|
218
|
+
this._catalogIndex = mergeCatalogs(sharedCatalog, itemCatalog);
|
|
219
|
+
} else {
|
|
220
|
+
this._catalogIndex = itemCatalog;
|
|
221
|
+
}
|
|
222
|
+
|
|
199
223
|
// Check strict compliance if enabled
|
|
200
224
|
if (this.config.strictQtiCompliance?.enabled) {
|
|
201
225
|
this.validateStrictCompliance();
|
|
202
226
|
}
|
|
203
227
|
}
|
|
204
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Apply the PNP profile to a player root element.
|
|
231
|
+
* Call this once the root DOM element is available (e.g. after mounting).
|
|
232
|
+
* The player stores the element reference so updatePnp() can re-apply without re-parsing the item.
|
|
233
|
+
*/
|
|
234
|
+
public applyPnp(rootEl: HTMLElement): void {
|
|
235
|
+
this._rootEl = rootEl;
|
|
236
|
+
applyPnpToRoot(rootEl, this._pnp);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Update the PNP profile mid-session without re-parsing the item XML.
|
|
241
|
+
* Deep-merges the partial profile into the current profile and re-applies.
|
|
242
|
+
*/
|
|
243
|
+
public updatePnp(partial: Partial<PnpProfile>): void {
|
|
244
|
+
this._pnp = mergePnp(this._pnp, partial);
|
|
245
|
+
if (this._rootEl) {
|
|
246
|
+
applyPnpToRoot(this._rootEl, this._pnp);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Return the current resolved PNP profile. */
|
|
251
|
+
public getPnp(): PnpProfile | undefined {
|
|
252
|
+
return this._pnp;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Look up a catalog entry by card identifier, usage type, and optional language.
|
|
257
|
+
* Returns the HTML string for the matched entry, or null if not found.
|
|
258
|
+
*
|
|
259
|
+
* Language fallback: exact match → prefix match → no-lang entry → null.
|
|
260
|
+
*/
|
|
261
|
+
public getCatalogEntry(idref: string, usage: string, lang?: string): string | null {
|
|
262
|
+
return getCatalogEntry(this._catalogIndex, idref, usage, lang);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Create a PciHost for an extracted PCI and register it for response tracking.
|
|
267
|
+
* The caller (typically ItemRenderer) is responsible for calling host.load() and
|
|
268
|
+
* host.initialize(domNode) once the DOM element is available.
|
|
269
|
+
*/
|
|
270
|
+
public createPciHost(data: ExtractedPci): PciHost {
|
|
271
|
+
const baseUrl = this.config.pciBaseUrl ?? (typeof document !== 'undefined' ? document.baseURI : '');
|
|
272
|
+
const host = new PciHost(data, baseUrl);
|
|
273
|
+
|
|
274
|
+
// Wire response changes back into the player's declaration context
|
|
275
|
+
host.onResponseChange((responseId: string, value: unknown) => {
|
|
276
|
+
const d = this.decls[responseId];
|
|
277
|
+
if (d) {
|
|
278
|
+
d.value = this.coerceToDeclarationValue(d.baseType, d.cardinality, value);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
this._pciHosts.set(data.responseIdentifier, host);
|
|
283
|
+
return host;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Push a response value into the PCI identified by responseIdentifier.
|
|
288
|
+
* Called from setResponses() so session restore reaches PCI modules.
|
|
289
|
+
*/
|
|
290
|
+
public setPciResponse(responseIdentifier: string, value: unknown): void {
|
|
291
|
+
this._pciHosts.get(responseIdentifier)?.setResponse(value);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Disable/enable all PCI hosts based on role.
|
|
296
|
+
* 'candidate' = enabled; any other role = disabled.
|
|
297
|
+
*/
|
|
298
|
+
public syncPciDisabledState(): void {
|
|
299
|
+
const disabled = this.role !== 'candidate';
|
|
300
|
+
for (const host of this._pciHosts.values()) {
|
|
301
|
+
if (disabled) host.disable(); else host.enable();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Destroy all PCI hosts. Call on player teardown.
|
|
307
|
+
*/
|
|
308
|
+
public destroyPciHosts(): void {
|
|
309
|
+
for (const host of this._pciHosts.values()) {
|
|
310
|
+
host.destroy();
|
|
311
|
+
}
|
|
312
|
+
this._pciHosts.clear();
|
|
313
|
+
}
|
|
314
|
+
|
|
205
315
|
/** Breaking-change API: returns the typed declaration map */
|
|
206
316
|
public getDeclarations(): DeclarationMap {
|
|
207
317
|
return this.decls;
|
|
@@ -212,9 +322,19 @@ export class Player {
|
|
|
212
322
|
const d = this.decls[id];
|
|
213
323
|
if (!d) continue;
|
|
214
324
|
d.value = this.coerceToDeclarationValue(d.baseType, d.cardinality, raw);
|
|
325
|
+
// Push restored responses into any mounted PCI modules
|
|
326
|
+
this.setPciResponse(id, raw);
|
|
215
327
|
}
|
|
216
328
|
}
|
|
217
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Destroy all resources owned by this player instance (PCI modules, etc.).
|
|
332
|
+
* Call when unmounting to prevent memory leaks.
|
|
333
|
+
*/
|
|
334
|
+
public destroy(): void {
|
|
335
|
+
this.destroyPciHosts();
|
|
336
|
+
}
|
|
337
|
+
|
|
218
338
|
public processResponses(): ScoringResult {
|
|
219
339
|
// Spec-aligned behavior: each processing run starts from outcome defaults.
|
|
220
340
|
// This prevents stale outcomes when response/outcome processing doesn't set every variable.
|
|
@@ -483,8 +603,16 @@ export class Player {
|
|
|
483
603
|
const res = this.extractionRegistry.extract<any>(el, ctx);
|
|
484
604
|
if (!res.success) continue;
|
|
485
605
|
|
|
606
|
+
// Normalize raw tag to QTI 2.x camelCase for ComponentRegistry compatibility.
|
|
607
|
+
// QTI 3.0 elements use kebab-case with 'qti-' prefix:
|
|
608
|
+
// 'qti-choice-interaction' → 'choiceInteraction'
|
|
609
|
+
const rawTag = el.rawTagName;
|
|
610
|
+
const normalizedType = rawTag.startsWith('qti-')
|
|
611
|
+
? rawTag.slice(4).replace(/-([a-z])/g, (_: string, c: string) => c.toUpperCase())
|
|
612
|
+
: rawTag;
|
|
613
|
+
|
|
486
614
|
interactions.push({
|
|
487
|
-
type:
|
|
615
|
+
type: normalizedType as any,
|
|
488
616
|
responseId,
|
|
489
617
|
...res.data,
|
|
490
618
|
});
|
|
@@ -697,8 +825,40 @@ export class Player {
|
|
|
697
825
|
const minPlays = Number(i.minPlays || 0);
|
|
698
826
|
complete = Number(value || 0) >= minPlays;
|
|
699
827
|
} else if (required) {
|
|
700
|
-
if (Array.isArray(value))
|
|
701
|
-
|
|
828
|
+
if (Array.isArray(value)) {
|
|
829
|
+
complete = value.length > 0;
|
|
830
|
+
// Enforce minChoices / minAssociations where applicable
|
|
831
|
+
const minChoices = Number(i.minChoices || i.minAssociations || 0);
|
|
832
|
+
if (complete && minChoices > 0) {
|
|
833
|
+
complete = value.length >= minChoices;
|
|
834
|
+
}
|
|
835
|
+
// Enforce matchMin per-choice: each pairing entry "id1 id2" in value must
|
|
836
|
+
// appear at least matchMin times for the relevant choice.
|
|
837
|
+
// Collect all choice arrays that can carry matchMin across all pairing interaction types.
|
|
838
|
+
const choices: Array<{ identifier: string; matchMin?: number }> = [
|
|
839
|
+
...(i.choices ?? []),
|
|
840
|
+
...(i.gapTexts ?? []),
|
|
841
|
+
...(i.gapImages ?? []),
|
|
842
|
+
...(i.sourceSet ?? []),
|
|
843
|
+
...(i.targetSet ?? []),
|
|
844
|
+
...(i.associableHotspots ?? []),
|
|
845
|
+
];
|
|
846
|
+
for (const choice of choices) {
|
|
847
|
+
const min = Number(choice.matchMin || 0);
|
|
848
|
+
if (min > 0) {
|
|
849
|
+
const count = (value as string[]).filter((p) => {
|
|
850
|
+
const parts = p.split(' ');
|
|
851
|
+
return parts[0] === choice.identifier || parts[1] === choice.identifier;
|
|
852
|
+
}).length;
|
|
853
|
+
if (count < min) {
|
|
854
|
+
complete = false;
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
} else {
|
|
860
|
+
complete = value !== null && value !== undefined && value !== '';
|
|
861
|
+
}
|
|
702
862
|
}
|
|
703
863
|
|
|
704
864
|
const errors: string[] = [];
|
|
@@ -820,7 +980,7 @@ export class Player {
|
|
|
820
980
|
}
|
|
821
981
|
|
|
822
982
|
private execResponseProcessingTemplate(templateUrl: string): void {
|
|
823
|
-
const name = templateUrl.split('/').pop()?.toLowerCase();
|
|
983
|
+
const name = templateUrl.split('/').pop()?.toLowerCase().replace(/\.xml$/, '');
|
|
824
984
|
if (!name) {
|
|
825
985
|
console.warn(`[QTI Player] Could not extract template name from URL: ${templateUrl}`);
|
|
826
986
|
return;
|
|
@@ -1253,4 +1413,14 @@ export class Player {
|
|
|
1253
1413
|
}
|
|
1254
1414
|
}
|
|
1255
1415
|
|
|
1416
|
+
// ---------------------------------------------------------------------------
|
|
1417
|
+
// Module-level helpers
|
|
1418
|
+
// ---------------------------------------------------------------------------
|
|
1256
1419
|
|
|
1420
|
+
function mergePnp(base: PnpProfile | undefined, partial: Partial<PnpProfile>): PnpProfile {
|
|
1421
|
+
return {
|
|
1422
|
+
display: { ...(base?.display ?? {}), ...(partial.display ?? {}) },
|
|
1423
|
+
content: { ...(base?.content ?? {}), ...(partial.content ?? {}) },
|
|
1424
|
+
cognitive: { ...(base?.cognitive ?? {}), ...(partial.cognitive ?? {}) },
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { QTIRole } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Product policy layered on top of QTI role/view semantics.
|
|
5
|
+
*
|
|
6
|
+
* QTI defines these roles as audience markers for view-controlled content
|
|
7
|
+
* (for example rubric/outcome visibility). It does not define a universal
|
|
8
|
+
* interaction UI behavior matrix. The player policy below keeps runtime
|
|
9
|
+
* behavior explicit and consistent across integrations.
|
|
10
|
+
*/
|
|
11
|
+
export interface RoleCapabilities {
|
|
12
|
+
isCandidate: boolean;
|
|
13
|
+
isReadOnly: boolean;
|
|
14
|
+
canViewCorrectResponses: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ROLES_WITH_CORRECT_RESPONSE_ACCESS: ReadonlySet<QTIRole> = new Set([
|
|
18
|
+
'scorer',
|
|
19
|
+
'author',
|
|
20
|
+
'tutor',
|
|
21
|
+
'testConstructor',
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
export function getRoleCapabilities(role: QTIRole): RoleCapabilities {
|
|
25
|
+
const isCandidate = role === 'candidate';
|
|
26
|
+
const canViewCorrectResponses = ROLES_WITH_CORRECT_RESPONSE_ACCESS.has(role);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
isCandidate,
|
|
30
|
+
isReadOnly: !isCandidate,
|
|
31
|
+
canViewCorrectResponses,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
package/src/core/urlPolicy.ts
CHANGED
|
@@ -62,14 +62,17 @@ export function sanitizeResourceUrl(raw: string, policy?: UrlPolicyConfig, kind:
|
|
|
62
62
|
if (s.startsWith('//')) return p.allowProtocolRelative ? `https:${s}` : null;
|
|
63
63
|
|
|
64
64
|
// Relative/absolute-path URLs: allow and optionally resolve.
|
|
65
|
-
|
|
65
|
+
// Bare relative paths (e.g. "images/foo.png" from IMS CP manifests) are treated
|
|
66
|
+
// the same as "./" paths — they have no scheme and are safe to pass through.
|
|
67
|
+
if (s.startsWith('/') || s.startsWith('./') || s.startsWith('../') || !/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(s)) {
|
|
66
68
|
if (p.assetBaseUrl) {
|
|
67
69
|
try {
|
|
68
70
|
// Strip leading '/' to make URL constructor resolve relative to base path, not origin
|
|
69
71
|
const relativePath = s.startsWith('/') ? s.slice(1) : s;
|
|
70
72
|
return new URL(relativePath, p.assetBaseUrl).toString();
|
|
71
73
|
} catch {
|
|
72
|
-
return
|
|
74
|
+
// assetBaseUrl resolution failed; return the raw relative path as-is
|
|
75
|
+
return s;
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
return s;
|