@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
package/src/components/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QTI 2.2 Item Player Components
|
|
3
|
-
*
|
|
4
|
-
* Top-level components for rendering complete QTI items and their orchestration.
|
|
5
|
-
* These are player-specific UI components.
|
|
6
|
-
*
|
|
7
|
-
* Note: These exports are for use in Svelte projects.
|
|
8
|
-
* For interaction implementations, use @pie-qti/default-components.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// Top-level player component (recommended for most use cases)
|
|
12
|
-
export { default as ItemPlayer } from './ItemPlayer.svelte';
|
|
13
|
-
|
|
14
|
-
// Player UI components
|
|
15
|
-
export { default as ItemBody } from './ItemBody.svelte';
|
|
16
|
-
export { default as ModalFeedbackDisplay } from './ModalFeedbackDisplay.svelte';
|
|
17
|
-
|
|
18
|
-
// Utility actions (dependency-free)
|
|
19
|
-
export { typesetAction } from './actions/typesetAction';
|
|
20
|
-
|
|
21
|
-
// Catalog actions
|
|
22
|
-
export { glossaryAction, type GlossaryActionParams } from '../catalog/glossaryAction';
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Feedback text utilities for QTI items
|
|
3
|
-
*
|
|
4
|
-
* NOTE: The cleanFeedbackText function contains vendor-specific transforms
|
|
5
|
-
* for content that uses semicolons after "Correct" and "Incorrect" labels.
|
|
6
|
-
* This is common in some QTI authoring tools but not part of the QTI specification.
|
|
7
|
-
*
|
|
8
|
-
* To customize this behavior for your vendor's content, you can:
|
|
9
|
-
* 1. Modify the patterns in this file
|
|
10
|
-
* 2. Create a vendor-specific transform plugin (see VENDOR-TRANSFORM-PLUGIN-GUIDE.md)
|
|
11
|
-
* 3. Pass custom transforms via the feedbackTransforms option
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Text pattern replacement for feedback content
|
|
16
|
-
*/
|
|
17
|
-
export interface FeedbackTransform {
|
|
18
|
-
/** Regular expression to match the pattern */
|
|
19
|
-
pattern: RegExp;
|
|
20
|
-
/** Replacement string (can use capture groups like $1, $2) */
|
|
21
|
-
replacement: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Default feedback text transforms
|
|
26
|
-
* These are vendor-specific patterns commonly found in certain QTI authoring tools
|
|
27
|
-
*/
|
|
28
|
-
export const DEFAULT_FEEDBACK_TRANSFORMS: FeedbackTransform[] = [
|
|
29
|
-
// Remove semicolons after "Incorrect" (with or without <strong> tags)
|
|
30
|
-
{ pattern: /<strong>Incorrect;<\/strong>/gi, replacement: '<strong>Incorrect</strong> ' },
|
|
31
|
-
{ pattern: /Incorrect;/gi, replacement: 'Incorrect ' },
|
|
32
|
-
|
|
33
|
-
// Remove semicolons after "Correct" (with or without <strong> tags)
|
|
34
|
-
{ pattern: /<strong>Correct;<\/strong>/gi, replacement: '<strong>Correct</strong> ' },
|
|
35
|
-
{ pattern: /Correct;/gi, replacement: 'Correct ' },
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Clean up feedback text formatting using configurable transforms
|
|
40
|
-
*
|
|
41
|
-
* @param content - The feedback content HTML string
|
|
42
|
-
* @param transforms - Optional custom transforms (defaults to DEFAULT_FEEDBACK_TRANSFORMS)
|
|
43
|
-
* @returns Cleaned feedback content
|
|
44
|
-
*/
|
|
45
|
-
export function cleanFeedbackText(
|
|
46
|
-
content: string,
|
|
47
|
-
transforms: FeedbackTransform[] = DEFAULT_FEEDBACK_TRANSFORMS
|
|
48
|
-
): string {
|
|
49
|
-
if (!content) return content;
|
|
50
|
-
|
|
51
|
-
let result = content;
|
|
52
|
-
for (const transform of transforms) {
|
|
53
|
-
result = result.replace(transform.pattern, transform.replacement);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Default outcome identifier for feedback display
|
|
61
|
-
* This can be overridden if your QTI content uses a different identifier
|
|
62
|
-
*/
|
|
63
|
-
export const DEFAULT_FEEDBACK_OUTCOME_ID = 'FEEDBACK';
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Options for processing feedbackInline elements
|
|
67
|
-
*/
|
|
68
|
-
export interface ProcessFeedbackInlineOptions {
|
|
69
|
-
/** Outcome values from response processing */
|
|
70
|
-
outcomeValues: Record<string, any>;
|
|
71
|
-
/** Whether to apply feedback text cleaning heuristics */
|
|
72
|
-
applyHeuristics?: boolean;
|
|
73
|
-
/** Whether to wrap feedback content with qti-feedback-inline span */
|
|
74
|
-
wrapWithSpan?: boolean;
|
|
75
|
-
/** Custom feedback transforms (defaults to DEFAULT_FEEDBACK_TRANSFORMS) */
|
|
76
|
-
transforms?: FeedbackTransform[];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Process feedbackInline elements in QTI content
|
|
81
|
-
*
|
|
82
|
-
* Conditionally shows/hides feedback based on outcome values and the showHide attribute.
|
|
83
|
-
* Optionally applies text cleaning heuristics and wraps content with styling span.
|
|
84
|
-
*
|
|
85
|
-
* @param html - The HTML content containing feedbackInline elements
|
|
86
|
-
* @param options - Processing options
|
|
87
|
-
* @returns Modified HTML with processed feedbackInline elements
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```typescript
|
|
91
|
-
* const html = processFeedbackInline(content, {
|
|
92
|
-
* outcomeValues: { FEEDBACK: 'choiceA' },
|
|
93
|
-
* applyHeuristics: true,
|
|
94
|
-
* wrapWithSpan: true
|
|
95
|
-
* });
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
export function processFeedbackInline(
|
|
99
|
-
html: string,
|
|
100
|
-
options: ProcessFeedbackInlineOptions
|
|
101
|
-
): string {
|
|
102
|
-
const { outcomeValues, applyHeuristics = false, wrapWithSpan = false, transforms } = options;
|
|
103
|
-
|
|
104
|
-
if (!html) return html;
|
|
105
|
-
|
|
106
|
-
return html.replace(
|
|
107
|
-
/<feedbackInline[^>]*outcomeIdentifier="([^"]+)"[^>]*identifier="([^"]+)"[^>]*showHide="([^"]+)"[^>]*>([\s\S]*?)<\/feedbackInline>/gi,
|
|
108
|
-
(match, outcomeId, feedbackId, showHide) => {
|
|
109
|
-
const outcomeValue = outcomeValues[outcomeId];
|
|
110
|
-
|
|
111
|
-
// If outcome value is not set (undefined, null, empty string), hide feedback
|
|
112
|
-
if (outcomeValue === undefined || outcomeValue === null || outcomeValue === '') {
|
|
113
|
-
return '';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Determine if feedback should be shown based on showHide attribute
|
|
117
|
-
const shouldShow =
|
|
118
|
-
showHide.toLowerCase() === 'show'
|
|
119
|
-
? outcomeValue === feedbackId
|
|
120
|
-
: outcomeValue !== feedbackId;
|
|
121
|
-
|
|
122
|
-
if (!shouldShow) return '';
|
|
123
|
-
|
|
124
|
-
// Extract content from feedbackInline tags
|
|
125
|
-
let content = match.replace(/<feedbackInline[^>]*>/, '').replace(/<\/feedbackInline>/, '');
|
|
126
|
-
|
|
127
|
-
// Apply text cleaning heuristics if enabled
|
|
128
|
-
if (applyHeuristics) {
|
|
129
|
-
content = cleanFeedbackText(content, transforms);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Wrap with styling span if enabled
|
|
133
|
-
if (wrapWithSpan) {
|
|
134
|
-
return ` <span class="qti-feedback-inline">${content}</span>`;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return content;
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for QTI item component rendering
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { assignProps } from './assignProps';
|
|
6
|
-
export {
|
|
7
|
-
cleanFeedbackText,
|
|
8
|
-
processFeedbackInline,
|
|
9
|
-
DEFAULT_FEEDBACK_OUTCOME_ID,
|
|
10
|
-
DEFAULT_FEEDBACK_TRANSFORMS,
|
|
11
|
-
type FeedbackTransform,
|
|
12
|
-
type ProcessFeedbackInlineOptions,
|
|
13
|
-
} from './feedbackUtils';
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
|
|
2
|
-
|
|
3
|
-
export type StimulusSanitizer = (html: string) => string;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Build the effective stimulus content map for an item render.
|
|
7
|
-
*
|
|
8
|
-
* Resolved delivery-context content is the package/assessment source of truth.
|
|
9
|
-
* Explicit content remains as a compatibility override for older host wiring.
|
|
10
|
-
*/
|
|
11
|
-
export function buildEffectiveStimulusContent(
|
|
12
|
-
deliveryContext: ResolvedItemDeliveryContext | undefined,
|
|
13
|
-
explicitStimulusContent: Record<string, string>,
|
|
14
|
-
sanitize: StimulusSanitizer
|
|
15
|
-
): Record<string, string> {
|
|
16
|
-
const resolved = Object.fromEntries(
|
|
17
|
-
Object.entries(deliveryContext?.stimuli ?? {}).map(([identifier, stimulus]) => [
|
|
18
|
-
identifier,
|
|
19
|
-
sanitize(stimulus.bodyHtml),
|
|
20
|
-
])
|
|
21
|
-
);
|
|
22
|
-
const explicit = Object.fromEntries(
|
|
23
|
-
Object.entries(explicitStimulusContent).map(([identifier, content]) => [identifier, sanitize(content)])
|
|
24
|
-
);
|
|
25
|
-
return { ...resolved, ...explicit };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Inject shared stimulus bodies at QTI refs or host-authored docking points.
|
|
30
|
-
*
|
|
31
|
-
* Any resolved stimulus that has no matching docking point is prepended in
|
|
32
|
-
* delivery-context order so undocked package content is still visible.
|
|
33
|
-
*/
|
|
34
|
-
export function injectStimulusContent(itemBodyHtml: string, stimulusContent: Record<string, string>): string {
|
|
35
|
-
if (Object.keys(stimulusContent).length === 0) return itemBodyHtml;
|
|
36
|
-
|
|
37
|
-
const docked = new Set<string>();
|
|
38
|
-
let html = itemBodyHtml.replace(
|
|
39
|
-
/<([a-z][\w:-]*)([^>]*\bdata-stimulus-idref=(["'])([^"']+)\3[^>]*)>\s*<\/\1>/gi,
|
|
40
|
-
(match, tagName, attrs, _quote, identifier) => {
|
|
41
|
-
const content = stimulusContent[identifier];
|
|
42
|
-
if (!content) return match;
|
|
43
|
-
docked.add(identifier);
|
|
44
|
-
return `<${tagName}${mergeClassAttribute(attrs, 'qti-stimulus-dock')}>${content}</${tagName}>`;
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
html = html.replace(
|
|
49
|
-
/<qti-assessment-stimulus-ref\b([^>]*)\/?>\s*(?:<\/qti-assessment-stimulus-ref>)?/gi,
|
|
50
|
-
(match, attrs) => {
|
|
51
|
-
const identifier = extractAttribute(attrs, 'identifier');
|
|
52
|
-
if (!identifier) return match;
|
|
53
|
-
if (docked.has(identifier)) return '';
|
|
54
|
-
const content = stimulusContent[identifier];
|
|
55
|
-
if (!content) return match;
|
|
56
|
-
docked.add(identifier);
|
|
57
|
-
return `<div data-stimulus-idref="${escapeHtmlAttribute(identifier)}" class="qti-stimulus-dock">${content}</div>`;
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const undocked = Object.entries(stimulusContent)
|
|
62
|
-
.filter(([identifier]) => !docked.has(identifier))
|
|
63
|
-
.map(
|
|
64
|
-
([identifier, content]) =>
|
|
65
|
-
`<div data-stimulus-idref="${escapeHtmlAttribute(identifier)}" class="qti-stimulus-block">${content}</div>`
|
|
66
|
-
)
|
|
67
|
-
.join('');
|
|
68
|
-
|
|
69
|
-
return undocked ? undocked + html : html;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function extractAttribute(attrs: string, name: string): string | null {
|
|
73
|
-
const match = attrs.match(new RegExp(`\\b${name}\\s*=\\s*["']([^"']+)["']`, 'i'));
|
|
74
|
-
return match?.[1] ?? null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function mergeClassAttribute(attrs: string, className: string): string {
|
|
78
|
-
const classMatch = attrs.match(/\bclass\s*=\s*(["'])([^"']*)\1/i);
|
|
79
|
-
if (!classMatch) return `${attrs} class="${className}"`;
|
|
80
|
-
const quote = classMatch[1]!;
|
|
81
|
-
const existing = classMatch[2] ?? '';
|
|
82
|
-
const classes = new Set(existing.split(/\s+/).filter(Boolean));
|
|
83
|
-
classes.add(className);
|
|
84
|
-
return attrs.replace(classMatch[0], `class=${quote}${Array.from(classes).join(' ')}${quote}`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function escapeHtmlAttribute(value: string): string {
|
|
88
|
-
return value
|
|
89
|
-
.replace(/&/g, '&')
|
|
90
|
-
.replace(/"/g, '"')
|
|
91
|
-
.replace(/</g, '<')
|
|
92
|
-
.replace(/>/g, '>');
|
|
93
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { ResolvedItemDeliveryContext, ResolvedQtiStylesheetRef } from '@pie-qti/ims-cp-core';
|
|
2
|
-
|
|
3
|
-
const BLOCKED_CSS = /@import\b|url\s*\(|<\/style|expression\s*\(|javascript\s*:|vbscript\s*:|data\s*:/i;
|
|
4
|
-
|
|
5
|
-
export function buildScopedStylesheetCss(
|
|
6
|
-
deliveryContext: ResolvedItemDeliveryContext | undefined,
|
|
7
|
-
scopeSelector = '[data-qti-item-body-scope]'
|
|
8
|
-
): string {
|
|
9
|
-
if (!deliveryContext) return '';
|
|
10
|
-
return deliveryContext.stylesheets
|
|
11
|
-
.map((stylesheet) => stylesheetToScopedCss(stylesheet, scopeSelector))
|
|
12
|
-
.filter(Boolean)
|
|
13
|
-
.join('\n');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function stylesheetToScopedCss(stylesheet: ResolvedQtiStylesheetRef, scopeSelector: string): string {
|
|
17
|
-
const css = stylesheet.cssText?.trim();
|
|
18
|
-
if (!css || BLOCKED_CSS.test(css)) return '';
|
|
19
|
-
const stylesheetScope = getStylesheetScopeSelector(stylesheet, scopeSelector);
|
|
20
|
-
const scoped = scopeCssRules(css, stylesheetScope);
|
|
21
|
-
if (!scoped) return '';
|
|
22
|
-
return scoped;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function scopeCssRules(css: string, scopeSelector = '[data-qti-item-body-scope]'): string {
|
|
26
|
-
const withoutComments = css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
27
|
-
let scoped = '';
|
|
28
|
-
const rulePattern = /([^{}@]+)\{([^{}]*)\}/g;
|
|
29
|
-
for (const match of withoutComments.matchAll(rulePattern)) {
|
|
30
|
-
const selectorList = match[1]?.trim();
|
|
31
|
-
const declarations = match[2]?.trim();
|
|
32
|
-
if (!selectorList || !declarations) continue;
|
|
33
|
-
const selectors = selectorList
|
|
34
|
-
.split(',')
|
|
35
|
-
.map((selector) => scopeSelectorText(selector.trim(), scopeSelector))
|
|
36
|
-
.filter(Boolean);
|
|
37
|
-
if (selectors.length === 0) continue;
|
|
38
|
-
scoped += `${selectors.join(', ')} { ${declarations} }\n`;
|
|
39
|
-
}
|
|
40
|
-
return scoped.trim();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function getStylesheetScopeSelector(stylesheet: ResolvedQtiStylesheetRef, scopeSelector: string): string {
|
|
44
|
-
if (stylesheet.source !== 'stimulus' || !stylesheet.stimulusIdentifier) return scopeSelector;
|
|
45
|
-
return `${scopeSelector} [data-stimulus-idref="${escapeCssString(stylesheet.stimulusIdentifier)}"]`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function scopeSelectorText(selector: string, scopeSelector: string): string {
|
|
49
|
-
if (!selector) return '';
|
|
50
|
-
if (selector.startsWith(scopeSelector)) return selector;
|
|
51
|
-
if (selector === ':root' || selector === 'html' || selector === 'body') return scopeSelector;
|
|
52
|
-
if (selector.startsWith(':')) return `${scopeSelector}${selector}`;
|
|
53
|
-
return `${scopeSelector} ${selector}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function escapeCssString(value: string): string {
|
|
57
|
-
return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n|\r|\f/g, ' ');
|
|
58
|
-
}
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Component Registry for Web Component-based Interaction Rendering
|
|
3
|
-
*
|
|
4
|
-
* Provides a pluggable system for registering web components to render
|
|
5
|
-
* different QTI interaction types. Uses priority-based dispatch similar to the
|
|
6
|
-
* ExtractionRegistry, but for framework-agnostic web components.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { InteractionData } from '../types/interactions.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Configuration for registering a web component renderer
|
|
13
|
-
*/
|
|
14
|
-
export interface ComponentConfig<TData extends InteractionData = InteractionData> {
|
|
15
|
-
/** Unique name for this renderer (e.g., 'rating-choice', 'standard-choice') */
|
|
16
|
-
name: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Priority for renderer evaluation (higher = checked first)
|
|
20
|
-
* - 100: Very specific custom renderers
|
|
21
|
-
* - 50: Moderately specific custom renderers
|
|
22
|
-
* - 10: Generic custom renderers
|
|
23
|
-
* - 0: Default fallback renderers
|
|
24
|
-
* Default: 0
|
|
25
|
-
*/
|
|
26
|
-
priority?: number;
|
|
27
|
-
|
|
28
|
-
/** Optional description for debugging/error messages */
|
|
29
|
-
description?: string;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Predicate to determine if this component can handle the interaction
|
|
33
|
-
* Evaluated in priority order (highest first)
|
|
34
|
-
* @returns true if this component should be used
|
|
35
|
-
* Default: always true
|
|
36
|
-
*/
|
|
37
|
-
canHandle?: (data: TData) => boolean;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Web component tag name (must contain a hyphen per web component spec)
|
|
41
|
-
* e.g., 'qti-choice-interaction', 'custom-rating-choice'
|
|
42
|
-
*/
|
|
43
|
-
tagName: string;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Optional web component class constructor
|
|
47
|
-
* If provided, the component will be automatically registered with customElements
|
|
48
|
-
*/
|
|
49
|
-
componentClass?: CustomElementConstructor;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Whether to automatically register the component with customElements
|
|
53
|
-
* Default: true if componentClass is provided
|
|
54
|
-
*/
|
|
55
|
-
autoRegister?: boolean;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Internal registered component with metadata
|
|
60
|
-
*/
|
|
61
|
-
interface RegisteredComponent<TData extends InteractionData = InteractionData> {
|
|
62
|
-
config: ComponentConfig<TData> & {
|
|
63
|
-
priority: number;
|
|
64
|
-
canHandle: (data: TData) => boolean;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Registry for web components that render QTI interactions
|
|
70
|
-
*/
|
|
71
|
-
export class ComponentRegistry {
|
|
72
|
-
private components = new Map<string, RegisteredComponent[]>();
|
|
73
|
-
private definedElements = new Set<string>();
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Register a web component for an interaction type with priority-based dispatch
|
|
77
|
-
*
|
|
78
|
-
* @param type - QTI interaction type (e.g., 'choiceInteraction', 'textEntryInteraction')
|
|
79
|
-
* @param config - Component configuration with priority and canHandle predicate
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* // Custom rating choice component with high priority
|
|
83
|
-
* registry.register('choiceInteraction', {
|
|
84
|
-
* name: 'rating-choice',
|
|
85
|
-
* priority: 100,
|
|
86
|
-
* description: 'Star rating interactions',
|
|
87
|
-
* canHandle: (data) => data.interactionClasses?.includes('rating-interaction'),
|
|
88
|
-
* tagName: 'custom-rating-choice',
|
|
89
|
-
* componentClass: RatingChoiceInteraction,
|
|
90
|
-
* autoRegister: true
|
|
91
|
-
* });
|
|
92
|
-
*
|
|
93
|
-
* // Default choice component
|
|
94
|
-
* registry.register('choiceInteraction', {
|
|
95
|
-
* name: 'standard-choice',
|
|
96
|
-
* tagName: 'qti-choice-interaction'
|
|
97
|
-
* });
|
|
98
|
-
*/
|
|
99
|
-
register<TData extends InteractionData>(
|
|
100
|
-
type: string,
|
|
101
|
-
config: ComponentConfig<TData>
|
|
102
|
-
): void {
|
|
103
|
-
// Validate tag name
|
|
104
|
-
if (!config.tagName.includes('-')) {
|
|
105
|
-
throw new Error(
|
|
106
|
-
`Invalid tag name '${config.tagName}'. ` +
|
|
107
|
-
`Web component tag names must contain a hyphen.`
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Auto-register custom element if requested
|
|
112
|
-
if (config.componentClass && config.autoRegister !== false) {
|
|
113
|
-
if (!this.definedElements.has(config.tagName)) {
|
|
114
|
-
if (!customElements.get(config.tagName)) {
|
|
115
|
-
customElements.define(config.tagName, config.componentClass);
|
|
116
|
-
}
|
|
117
|
-
this.definedElements.add(config.tagName);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Get or create component array for this type
|
|
122
|
-
let components = this.components.get(type);
|
|
123
|
-
if (!components) {
|
|
124
|
-
components = [];
|
|
125
|
-
this.components.set(type, components);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Add normalized component and sort by priority (highest first)
|
|
129
|
-
components.push(this.createRegisteredComponent(config) as RegisteredComponent);
|
|
130
|
-
components.sort((a, b) => b.config.priority - a.config.priority);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private createRegisteredComponent<TData extends InteractionData>(
|
|
134
|
-
config: ComponentConfig<TData>
|
|
135
|
-
): RegisteredComponent<TData> {
|
|
136
|
-
return {
|
|
137
|
-
config: {
|
|
138
|
-
...config,
|
|
139
|
-
priority: config.priority ?? 0,
|
|
140
|
-
canHandle: config.canHandle ?? (() => true),
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Get a web component tag name for an interaction type
|
|
147
|
-
* Evaluates canHandle predicates in priority order
|
|
148
|
-
*
|
|
149
|
-
* @param data - Interaction data
|
|
150
|
-
* @returns Web component tag name (e.g., 'qti-choice-interaction')
|
|
151
|
-
* @throws Error if no component matches
|
|
152
|
-
*/
|
|
153
|
-
getTagName<TData extends InteractionData>(data: TData): string {
|
|
154
|
-
const components = this.components.get(data.type);
|
|
155
|
-
|
|
156
|
-
if (!components || components.length === 0) {
|
|
157
|
-
throw new Error(
|
|
158
|
-
`No component registered for '${data.type}' interaction. ` +
|
|
159
|
-
`Available types: ${Array.from(this.components.keys()).join(', ')}`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Evaluate canHandle in priority order
|
|
164
|
-
for (const { config } of components) {
|
|
165
|
-
try {
|
|
166
|
-
if (config.canHandle(data as any)) {
|
|
167
|
-
return config.tagName;
|
|
168
|
-
}
|
|
169
|
-
} catch (error) {
|
|
170
|
-
// Log but continue to next component
|
|
171
|
-
console.warn(
|
|
172
|
-
`canHandle() failed for '${config.name}' component:`,
|
|
173
|
-
error
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// No component matched
|
|
179
|
-
const componentList = components
|
|
180
|
-
.map((c) => {
|
|
181
|
-
const desc = c.config.description ? ` (${c.config.description})` : '';
|
|
182
|
-
return `${c.config.name}${desc}`;
|
|
183
|
-
})
|
|
184
|
-
.join(', ');
|
|
185
|
-
|
|
186
|
-
throw new Error(
|
|
187
|
-
`No component available for '${data.type}' interaction.\n` +
|
|
188
|
-
`Registered components: ${componentList}.\n` +
|
|
189
|
-
`None of these components matched the current interaction.`
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Get all registered interaction types
|
|
195
|
-
* @returns Array of registered interaction type names
|
|
196
|
-
*/
|
|
197
|
-
getRegisteredTypes(): string[] {
|
|
198
|
-
return Array.from(this.components.keys());
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Check if a component is registered for a type
|
|
203
|
-
*/
|
|
204
|
-
hasComponent(type: string): boolean {
|
|
205
|
-
return this.components.has(type) && this.components.get(type)!.length > 0;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Get the tag name for a registered type by name (no canHandle evaluation).
|
|
210
|
-
* Useful for non-interaction components like catalogPopup where the type string
|
|
211
|
-
* is known and there is no InteractionData object to pass.
|
|
212
|
-
*
|
|
213
|
-
* Returns the highest-priority registered tag name for the type, or null if
|
|
214
|
-
* the type is not registered.
|
|
215
|
-
*/
|
|
216
|
-
getTagNameForType(type: string): string | null {
|
|
217
|
-
const components = this.components.get(type);
|
|
218
|
-
if (!components || components.length === 0) return null;
|
|
219
|
-
return components[0].config.tagName;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Create a new component registry
|
|
225
|
-
*/
|
|
226
|
-
export function createComponentRegistry(): ComponentRegistry {
|
|
227
|
-
return new ComponentRegistry();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Plugin interface for registering web components
|
|
232
|
-
*/
|
|
233
|
-
export interface ComponentPlugin {
|
|
234
|
-
/** Plugin name (e.g., '@renaissance/rating-choice') */
|
|
235
|
-
name: string;
|
|
236
|
-
|
|
237
|
-
/** Plugin version (semver) */
|
|
238
|
-
version: string;
|
|
239
|
-
|
|
240
|
-
/** Plugin description */
|
|
241
|
-
description: string;
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Register web components with the registry
|
|
245
|
-
* @param registry - ComponentRegistry instance
|
|
246
|
-
*/
|
|
247
|
-
register(registry: ComponentRegistry): void;
|
|
248
|
-
}
|