@pie-qti/item-player 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/catalog/applyGlossaryTriggers.d.ts +13 -2
- package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
- package/dist/catalog/glossaryAction.d.ts +4 -2
- package/dist/catalog/glossaryAction.d.ts.map +1 -1
- package/dist/components/utils/index.d.ts +1 -2
- package/dist/components/utils/index.d.ts.map +1 -1
- package/dist/components/utils/index.js +1 -2
- package/dist/core/ComponentRegistry.d.ts +10 -1
- package/dist/core/ComponentRegistry.d.ts.map +1 -1
- package/dist/core/ComponentRegistry.js +42 -1
- package/dist/core/Player.d.ts +10 -2
- package/dist/core/Player.d.ts.map +1 -1
- package/dist/core/Player.js +54 -46
- package/dist/document/AssessmentItemDocument.d.ts +1 -1
- package/dist/element.d.ts +15 -0
- package/dist/element.js +1817 -1625
- package/dist/element.js.map +1 -1
- package/dist/extraction/ExtractionRegistry.d.ts +1 -1
- package/dist/extraction/createContext.d.ts +1 -1
- package/dist/extraction/index.d.ts +2 -2
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +1 -1
- package/dist/extraction/interactionExtractionPipeline.d.ts +1 -1
- package/dist/extraction/interactionSecurity.d.ts +1 -1
- package/dist/extraction/types.d.ts +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +54 -0
- package/dist/presentation/itemPresentationPlan.d.ts.map +1 -0
- package/dist/presentation/itemPresentationPlan.js +98 -0
- package/dist/types/index.d.ts +17 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -3
- package/dist/web-components/QTIInteractionBase.d.ts +1 -1
- package/dist/web-components/QTIInteractionElement.d.ts +1 -1
- package/package.json +7 -14
- package/src/__tests__/catalog.test.ts +0 -267
- package/src/__tests__/fixtures/pci/echo-pci.js +0 -49
- package/src/__tests__/pci.test.ts +0 -353
- package/src/__tests__/qti3-attribute-extraction.test.ts +0 -174
- package/src/__tests__/qti3-debug.test.ts +0 -140
- package/src/__tests__/qti3-extraction.test.ts +0 -309
- package/src/catalog/applyGlossaryTriggers.ts +0 -372
- package/src/catalog/catalogExtractor.ts +0 -130
- package/src/catalog/catalogLookup.ts +0 -53
- package/src/catalog/glossaryAction.ts +0 -38
- package/src/catalog/types.ts +0 -37
- package/src/components/ItemBody.svelte +0 -363
- package/src/components/ItemPlayer.svelte +0 -163
- package/src/components/ModalFeedbackDisplay.svelte +0 -97
- package/src/components/actions/typesetAction.ts +0 -74
- package/src/components/index.ts +0 -22
- package/src/components/utils/assignProps.ts +0 -2
- package/src/components/utils/feedbackUtils.ts +0 -140
- package/src/components/utils/index.ts +0 -13
- package/src/components/utils/stimulusRender.ts +0 -93
- package/src/components/utils/stylesheetRender.ts +0 -58
- package/src/core/ComponentRegistry.ts +0 -248
- package/src/core/Player.ts +0 -1618
- package/src/core/Plugin.ts +0 -123
- package/src/core/PluginManager.ts +0 -182
- package/src/core/constants.ts +0 -117
- package/src/core/declarations.ts +0 -171
- package/src/core/parsingLimits.ts +0 -62
- package/src/core/random.ts +0 -24
- package/src/core/rolePolicy.ts +0 -34
- package/src/core/sanitizer.ts +0 -305
- package/src/core/trustedTypes.ts +0 -63
- package/src/core/urlPolicy.ts +0 -98
- package/src/document/AssessmentItemDocument.ts +0 -247
- package/src/element.ts +0 -128
- package/src/extensions/MathLiveEditor.ts +0 -313
- package/src/extraction/ExtractionRegistry.ts +0 -335
- package/src/extraction/createContext.ts +0 -52
- package/src/extraction/extractors/associateExtractor.ts +0 -1
- package/src/extraction/extractors/choiceExtractor.ts +0 -1
- package/src/extraction/extractors/conformance-qti3-advanced.test.ts +0 -239
- package/src/extraction/extractors/conformance-qti3-basic.test.ts +0 -82
- package/src/extraction/extractors/conformance.test.ts +0 -208
- package/src/extraction/extractors/customExtractor.ts +0 -1
- package/src/extraction/extractors/drawingExtractor.ts +0 -1
- package/src/extraction/extractors/endAttemptExtractor.ts +0 -1
- package/src/extraction/extractors/extendedTextExtractor.ts +0 -1
- package/src/extraction/extractors/gapMatchExtractor.ts +0 -1
- package/src/extraction/extractors/graphicAssociateExtractor.ts +0 -1
- package/src/extraction/extractors/graphicGapMatchExtractor.ts +0 -1
- package/src/extraction/extractors/graphicOrderExtractor.ts +0 -1
- package/src/extraction/extractors/hotspotExtractor.ts +0 -1
- package/src/extraction/extractors/hottextExtractor.ts +0 -1
- package/src/extraction/extractors/index.ts +0 -9
- package/src/extraction/extractors/inlineChoiceExtractor.ts +0 -1
- package/src/extraction/extractors/matchExtractor.ts +0 -1
- package/src/extraction/extractors/mediaExtractor.ts +0 -1
- package/src/extraction/extractors/orderExtractor.ts +0 -1
- package/src/extraction/extractors/portableCustomExtractor.ts +0 -1
- package/src/extraction/extractors/positionObjectExtractor.ts +0 -1
- package/src/extraction/extractors/selectPointExtractor.ts +0 -1
- package/src/extraction/extractors/sliderExtractor.ts +0 -1
- package/src/extraction/extractors/textEntryExtractor.ts +0 -1
- package/src/extraction/extractors/uploadExtractor.ts +0 -1
- package/src/extraction/index.ts +0 -108
- package/src/extraction/interactionExtractionPipeline.ts +0 -70
- package/src/extraction/interactionSecurity.ts +0 -60
- package/src/extraction/types.ts +0 -246
- package/src/extraction/utils.ts +0 -243
- package/src/iframe/IFramePlayerHost.ts +0 -265
- package/src/iframe/index.ts +0 -11
- package/src/iframe/protocol.ts +0 -137
- package/src/index.ts +0 -101
- package/src/interactions/associate/extractor.ts +0 -133
- package/src/interactions/associate/index.ts +0 -2
- package/src/interactions/associate/types.ts +0 -1
- package/src/interactions/choice/extractor.ts +0 -121
- package/src/interactions/choice/index.ts +0 -2
- package/src/interactions/choice/types.ts +0 -1
- package/src/interactions/custom/extractor.ts +0 -72
- package/src/interactions/custom/index.ts +0 -2
- package/src/interactions/custom/types.ts +0 -1
- package/src/interactions/drawing/extractor.ts +0 -113
- package/src/interactions/drawing/index.ts +0 -2
- package/src/interactions/drawing/types.ts +0 -1
- package/src/interactions/end-attempt/extractor.ts +0 -74
- package/src/interactions/end-attempt/index.ts +0 -2
- package/src/interactions/end-attempt/types.ts +0 -1
- package/src/interactions/extended-text/extractor.ts +0 -92
- package/src/interactions/extended-text/index.ts +0 -2
- package/src/interactions/extended-text/types.ts +0 -1
- package/src/interactions/gap-match/extractor.ts +0 -193
- package/src/interactions/gap-match/index.ts +0 -2
- package/src/interactions/gap-match/types.ts +0 -1
- package/src/interactions/graphic-associate/extractor.ts +0 -192
- package/src/interactions/graphic-associate/index.ts +0 -2
- package/src/interactions/graphic-associate/types.ts +0 -1
- package/src/interactions/graphic-gap-match/extractor.ts +0 -257
- package/src/interactions/graphic-gap-match/index.ts +0 -2
- package/src/interactions/graphic-gap-match/types.ts +0 -1
- package/src/interactions/graphic-order/extractor.ts +0 -162
- package/src/interactions/graphic-order/index.ts +0 -2
- package/src/interactions/graphic-order/types.ts +0 -1
- package/src/interactions/hotspot/extractor.ts +0 -208
- package/src/interactions/hotspot/index.ts +0 -2
- package/src/interactions/hotspot/types.ts +0 -1
- package/src/interactions/hottext/extractor.ts +0 -163
- package/src/interactions/hottext/index.ts +0 -2
- package/src/interactions/hottext/types.ts +0 -1
- package/src/interactions/index.ts +0 -52
- package/src/interactions/inline/index.ts +0 -1
- package/src/interactions/inline/render-plan.ts +0 -105
- package/src/interactions/inline-choice/InlineChoice.svelte +0 -57
- package/src/interactions/inline-choice/extractor.ts +0 -105
- package/src/interactions/inline-choice/index.ts +0 -2
- package/src/interactions/inline-choice/types.ts +0 -1
- package/src/interactions/match/extractor.ts +0 -187
- package/src/interactions/match/index.ts +0 -2
- package/src/interactions/match/types.ts +0 -1
- package/src/interactions/media/extractor.ts +0 -168
- package/src/interactions/media/index.ts +0 -2
- package/src/interactions/media/types.ts +0 -1
- package/src/interactions/modules.ts +0 -111
- package/src/interactions/order/extractor.ts +0 -120
- package/src/interactions/order/index.ts +0 -2
- package/src/interactions/order/types.ts +0 -1
- package/src/interactions/portable-custom/extractor.ts +0 -122
- package/src/interactions/portable-custom/index.ts +0 -2
- package/src/interactions/portable-custom/types.ts +0 -1
- package/src/interactions/position-object/extractor.ts +0 -243
- package/src/interactions/position-object/index.ts +0 -2
- package/src/interactions/position-object/types.ts +0 -1
- package/src/interactions/select-point/extractor.ts +0 -143
- package/src/interactions/select-point/index.ts +0 -2
- package/src/interactions/select-point/types.ts +0 -1
- package/src/interactions/shared/index.ts +0 -1
- package/src/interactions/shared/types.ts +0 -430
- package/src/interactions/slider/extractor.ts +0 -102
- package/src/interactions/slider/index.ts +0 -2
- package/src/interactions/slider/types.ts +0 -1
- package/src/interactions/text-entry/InlineTextEntry.svelte +0 -75
- package/src/interactions/text-entry/extractor.ts +0 -79
- package/src/interactions/text-entry/index.ts +0 -2
- package/src/interactions/text-entry/types.ts +0 -1
- package/src/interactions/upload/extractor.ts +0 -81
- package/src/interactions/upload/index.ts +0 -2
- package/src/interactions/upload/types.ts +0 -1
- package/src/pci/PciHost.ts +0 -138
- package/src/pci/types.ts +0 -70
- package/src/pnp/applyPnp.ts +0 -29
- package/src/pnp/parsePnpXml.ts +0 -215
- package/src/pnp/types.ts +0 -75
- package/src/server.ts +0 -14
- package/src/types/index.ts +0 -388
- package/src/types/interactions.ts +0 -8
- package/src/types/responseValidation.ts +0 -29
- package/src/types/xmldom.d.ts +0 -12
- package/src/utils/PerformanceMonitor.ts +0 -335
- package/src/utils/drawingUtils.ts +0 -73
- package/src/utils/responseUtils.ts +0 -51
- package/src/utils/touchDragHelper.ts +0 -1
- package/src/web-components/QTIInteractionBase.ts +0 -303
- package/src/web-components/QTIInteractionElement.ts +0 -125
- package/src/web-components/index.ts +0 -22
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
3
|
-
import type { TextEntryInteractionData } from './types.js';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
interaction: TextEntryInteractionData;
|
|
7
|
-
response?: string;
|
|
8
|
-
correctAnswer?: string | null;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
i18n?: I18nProvider;
|
|
11
|
-
onResponseChange?: (responseId: string, value: string) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let {
|
|
15
|
-
interaction,
|
|
16
|
-
response = '',
|
|
17
|
-
correctAnswer = null,
|
|
18
|
-
disabled = false,
|
|
19
|
-
i18n,
|
|
20
|
-
onResponseChange = () => {},
|
|
21
|
-
}: Props = $props();
|
|
22
|
-
|
|
23
|
-
let validationError = $state<string | null>(null);
|
|
24
|
-
const displayValue = $derived(correctAnswer !== null ? correctAnswer : response);
|
|
25
|
-
const inputWidthClass = $derived((interaction.interactionClasses ?? []).find((className) => className.startsWith('qti-input-width-')));
|
|
26
|
-
const extraClasses = $derived((interaction.interactionClasses ?? []).filter((className) => !className.startsWith('qti-input-width-')).join(' '));
|
|
27
|
-
const errorId = $derived(`${interaction.responseId}-error`);
|
|
28
|
-
|
|
29
|
-
function handleInput(event: Event) {
|
|
30
|
-
const input = event.currentTarget as HTMLInputElement | null;
|
|
31
|
-
const value = input?.value ?? '';
|
|
32
|
-
onResponseChange(interaction.responseId, value);
|
|
33
|
-
if (input?.validity.valid) {
|
|
34
|
-
validationError = null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function handleInvalid(event: Event) {
|
|
39
|
-
event.preventDefault();
|
|
40
|
-
validationError =
|
|
41
|
-
interaction.patternMaskMessage ??
|
|
42
|
-
i18n?.t('interactions.textEntry.patternError', 'Please match the required format') ??
|
|
43
|
-
'Please match the required format';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function handleBlur(event: Event) {
|
|
47
|
-
(event.currentTarget as HTMLInputElement | null)?.checkValidity();
|
|
48
|
-
}
|
|
49
|
-
</script>
|
|
50
|
-
|
|
51
|
-
<input
|
|
52
|
-
type="text"
|
|
53
|
-
class={['input input-bordered input-sm inline-input', inputWidthClass ?? '', extraClasses].filter(Boolean).join(' ')}
|
|
54
|
-
class:border-success={correctAnswer !== null}
|
|
55
|
-
class:bg-success={correctAnswer !== null}
|
|
56
|
-
class:bg-opacity-10={correctAnswer !== null}
|
|
57
|
-
style={inputWidthClass ? 'min-width: 100px; display: inline-block; margin: 0 4px;' : `width: ${interaction.expectedLength * 8}px; min-width: 100px; display: inline-block; margin: 0 4px;`}
|
|
58
|
-
placeholder={interaction.placeholderText || '...'}
|
|
59
|
-
pattern={interaction.patternMask || undefined}
|
|
60
|
-
title={interaction.patternMask ? `Format: ${interaction.patternMask}` : undefined}
|
|
61
|
-
data-format={interaction.format || undefined}
|
|
62
|
-
aria-label={`Text entry ${interaction.responseId}${correctAnswer ? '. Correct answer: ' + correctAnswer : ''}`}
|
|
63
|
-
aria-invalid={validationError ? 'true' : undefined}
|
|
64
|
-
aria-describedby={validationError ? errorId : undefined}
|
|
65
|
-
value={displayValue}
|
|
66
|
-
oninput={handleInput}
|
|
67
|
-
oninvalid={handleInvalid}
|
|
68
|
-
onblur={handleBlur}
|
|
69
|
-
{disabled}
|
|
70
|
-
/>
|
|
71
|
-
{#if validationError}
|
|
72
|
-
<span id={errorId} role="alert" class="qti-text-entry-error text-error text-xs" style="display: block;">
|
|
73
|
-
{validationError}
|
|
74
|
-
</span>
|
|
75
|
-
{/if}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standard QTI textEntryInteraction extractor
|
|
3
|
-
*
|
|
4
|
-
* Extracts data from textEntryInteraction elements (inline text input)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { ElementExtractor } from '../../extraction/types.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Text entry data extracted from textEntryInteraction elements
|
|
11
|
-
*/
|
|
12
|
-
export interface TextEntryData {
|
|
13
|
-
expectedLength: number;
|
|
14
|
-
patternMask: string | null;
|
|
15
|
-
placeholderText: string;
|
|
16
|
-
format?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Standard QTI text entry interaction extractor
|
|
21
|
-
* Handles textEntryInteraction elements (inline text input)
|
|
22
|
-
*/
|
|
23
|
-
export const standardTextEntryExtractor: ElementExtractor<TextEntryData> = {
|
|
24
|
-
id: 'qti:text-entry-interaction',
|
|
25
|
-
name: 'QTI Standard Text Entry Interaction',
|
|
26
|
-
priority: 10,
|
|
27
|
-
elementTypes: ['textEntryInteraction'],
|
|
28
|
-
description: 'Extracts standard QTI textEntryInteraction (inline text input)',
|
|
29
|
-
|
|
30
|
-
canHandle(element, _context) {
|
|
31
|
-
// All textEntryInteraction elements are standard (both QTI 2.x and 3.0)
|
|
32
|
-
return (
|
|
33
|
-
element.rawTagName === 'textEntryInteraction' || element.rawTagName === 'qti-text-entry-interaction'
|
|
34
|
-
);
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
extract(element, context) {
|
|
38
|
-
const { utils } = context;
|
|
39
|
-
|
|
40
|
-
// Extract attributes
|
|
41
|
-
const expectedLength = utils.getNumberAttribute(element, 'expectedLength', 20);
|
|
42
|
-
const patternMask = utils.getAttribute(element, 'patternMask', '');
|
|
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;
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
expectedLength,
|
|
50
|
-
patternMask: patternMask || null,
|
|
51
|
-
placeholderText,
|
|
52
|
-
...(format ? { format } : {}),
|
|
53
|
-
...(interactionClasses.length > 0 ? { interactionClasses } : {}),
|
|
54
|
-
...(patternMaskMessage ? { patternMaskMessage } : {}),
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
validate(data) {
|
|
59
|
-
const errors: string[] = [];
|
|
60
|
-
const warnings: string[] = [];
|
|
61
|
-
|
|
62
|
-
// Validate expectedLength
|
|
63
|
-
if (data.expectedLength < 1) {
|
|
64
|
-
errors.push('expectedLength must be positive');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (data.expectedLength > 1000) {
|
|
68
|
-
warnings.push(
|
|
69
|
-
`expectedLength (${data.expectedLength}) is very large - consider using extendedTextInteraction`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
valid: errors.length === 0,
|
|
75
|
-
errors: errors.length > 0 ? errors : undefined,
|
|
76
|
-
warnings: warnings.length > 0 ? warnings : undefined,
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { TextEntryInteractionData } from '../shared/types.js';
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standard QTI uploadInteraction extractor
|
|
3
|
-
*
|
|
4
|
-
* Extracts data from uploadInteraction elements (file upload)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { ElementExtractor } from '../../extraction/types.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Upload data extracted from uploadInteraction elements
|
|
11
|
-
*/
|
|
12
|
-
export interface UploadData {
|
|
13
|
-
fileTypes: string[];
|
|
14
|
-
rawAttributes: Record<string, string>;
|
|
15
|
-
prompt: string | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Standard QTI upload interaction extractor
|
|
20
|
-
* Handles uploadInteraction elements (file upload)
|
|
21
|
-
*/
|
|
22
|
-
export const standardUploadExtractor: ElementExtractor<UploadData> = {
|
|
23
|
-
id: 'qti:upload-interaction',
|
|
24
|
-
name: 'QTI Standard Upload Interaction',
|
|
25
|
-
priority: 10,
|
|
26
|
-
elementTypes: ['uploadInteraction'],
|
|
27
|
-
description: 'Extracts standard QTI uploadInteraction (file upload)',
|
|
28
|
-
|
|
29
|
-
canHandle(element, _context) {
|
|
30
|
-
// All uploadInteraction elements are standard
|
|
31
|
-
return element.rawTagName === 'uploadInteraction';
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
extract(element, context) {
|
|
35
|
-
const { utils } = context;
|
|
36
|
-
|
|
37
|
-
// Extract fileType child elements (vendor / QTI 3.0 style)
|
|
38
|
-
const fileTypeElements = utils.getChildrenByTag(element, 'fileType');
|
|
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
|
-
}
|
|
48
|
-
|
|
49
|
-
// Extract all attributes
|
|
50
|
-
const rawAttributes: Record<string, string> = {};
|
|
51
|
-
if (element.attributes) {
|
|
52
|
-
for (const [key, value] of Object.entries(element.attributes)) {
|
|
53
|
-
rawAttributes[key] = String(value);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Extract prompt (optional)
|
|
58
|
-
const promptElements = utils.getChildrenByTag(element, 'prompt');
|
|
59
|
-
const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
fileTypes,
|
|
63
|
-
rawAttributes,
|
|
64
|
-
prompt,
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
validate(data) {
|
|
69
|
-
const warnings: string[] = [];
|
|
70
|
-
|
|
71
|
-
// Warn if no file type restrictions
|
|
72
|
-
if (!data.fileTypes || data.fileTypes.length === 0) {
|
|
73
|
-
warnings.push('uploadInteraction has no fileTypes - any file type will be accepted');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
valid: true,
|
|
78
|
-
warnings: warnings.length > 0 ? warnings : undefined,
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { UploadInteractionData } from '../shared/types.js';
|
package/src/pci/PciHost.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
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
|
-
}
|
package/src/pci/types.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
}
|
package/src/pnp/applyPnp.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { PnpProfile } from './types.js';
|
|
2
|
-
|
|
3
|
-
const ATTR = 'data-qti-colorscheme';
|
|
4
|
-
const MAGNIFICATION_ATTR = 'data-qti-magnification';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Apply a PNP profile to the player root element.
|
|
8
|
-
*
|
|
9
|
-
* Currently handles color scheme (data-qti-colorscheme attribute).
|
|
10
|
-
* Magnification is intentionally deferred — host stylesheets / browser zoom are sufficient for now.
|
|
11
|
-
*/
|
|
12
|
-
export function applyPnpToRoot(rootEl: HTMLElement, pnp: PnpProfile | undefined): void {
|
|
13
|
-
const scheme = pnp?.display?.colorScheme;
|
|
14
|
-
|
|
15
|
-
if (!scheme || scheme === 'default') {
|
|
16
|
-
rootEl.removeAttribute(ATTR);
|
|
17
|
-
} else {
|
|
18
|
-
rootEl.setAttribute(ATTR, scheme);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const magnification = pnp?.display?.magnification;
|
|
22
|
-
if (magnification !== undefined && Number.isFinite(magnification) && magnification > 0) {
|
|
23
|
-
rootEl.setAttribute(MAGNIFICATION_ATTR, String(magnification));
|
|
24
|
-
rootEl.style?.setProperty?.('--qti-magnification', String(magnification));
|
|
25
|
-
} else {
|
|
26
|
-
rootEl.removeAttribute(MAGNIFICATION_ATTR);
|
|
27
|
-
rootEl.style?.removeProperty?.('--qti-magnification');
|
|
28
|
-
}
|
|
29
|
-
}
|