@pie-qti/item-player 0.1.18 → 0.1.20
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 +137 -427
- package/dist/catalog/applyGlossaryTriggers.d.ts +2 -1
- package/dist/catalog/applyGlossaryTriggers.js +4 -2
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/components/utils/stimulusRender.d.ts +1 -2
- package/dist/components/utils/stimulusRender.js +2 -5
- package/dist/components/utils/stimulusRender.js.map +1 -1
- package/dist/core/AssessmentItemDefinition.d.ts +69 -0
- package/dist/core/AssessmentItemDefinition.js +149 -0
- package/dist/core/AssessmentItemDefinition.js.map +1 -0
- package/dist/core/ComponentRegistry.d.ts +11 -5
- package/dist/core/ComponentRegistry.js +44 -17
- package/dist/core/ComponentRegistry.js.map +1 -1
- package/dist/core/ItemSession.d.ts +58 -0
- package/dist/core/ItemSession.js +286 -0
- package/dist/core/ItemSession.js.map +1 -0
- package/dist/core/Player.d.ts +9 -8
- package/dist/core/Player.js +182 -163
- package/dist/core/Player.js.map +1 -1
- package/dist/core/sanitizer.js +33 -10
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/document/AssessmentItemDocument.d.ts +32 -10
- package/dist/document/AssessmentItemDocument.js +80 -23
- package/dist/document/AssessmentItemDocument.js.map +1 -1
- package/dist/{element-class-C8OTgYHE.js → element-class-CILJ4Ls7.js} +3583 -2779
- package/dist/element-class-CILJ4Ls7.js.map +1 -0
- package/dist/element-class.d.ts +17 -13
- package/dist/element-class.js +1 -1
- package/dist/element.js +1 -1
- package/dist/extraction/ExtractionRegistry.d.ts +34 -11
- package/dist/extraction/ExtractionRegistry.js +122 -19
- package/dist/extraction/ExtractionRegistry.js.map +1 -1
- package/dist/extraction/createContext.d.ts +5 -6
- package/dist/extraction/createContext.js +2 -2
- package/dist/extraction/createContext.js.map +1 -1
- package/dist/extraction/deliveryTypes.d.ts +26 -0
- package/dist/extraction/deliveryTypes.js +7 -0
- package/dist/extraction/deliveryTypes.js.map +1 -0
- package/dist/extraction/index.d.ts +3 -3
- package/dist/extraction/index.js +1 -2
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/interactionExtractionPipeline.d.ts +4 -4
- package/dist/extraction/interactionExtractionPipeline.js +27 -10
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/interactionSecurity.d.ts +11 -2
- package/dist/extraction/interactionSecurity.js +105 -40
- package/dist/extraction/interactionSecurity.js.map +1 -1
- package/dist/extraction/types.d.ts +44 -7
- package/dist/extraction/types.js.map +1 -1
- package/dist/extraction/utils.js +4 -16
- package/dist/extraction/utils.js.map +1 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/interactions/associate/extractor.js +1 -1
- package/dist/interactions/associate/extractor.js.map +1 -1
- package/dist/interactions/drawing/extractor.js +5 -4
- package/dist/interactions/drawing/extractor.js.map +1 -1
- package/dist/interactions/end-attempt/extractor.js +2 -2
- package/dist/interactions/end-attempt/extractor.js.map +1 -1
- package/dist/interactions/gap-match/extractor.js +4 -3
- package/dist/interactions/gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-associate/extractor.js +5 -4
- package/dist/interactions/graphic-associate/extractor.js.map +1 -1
- package/dist/interactions/graphic-gap-match/extractor.js +20 -17
- package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-order/extractor.js +5 -4
- package/dist/interactions/graphic-order/extractor.js.map +1 -1
- package/dist/interactions/hotspot/extractor.js +11 -10
- package/dist/interactions/hotspot/extractor.js.map +1 -1
- package/dist/interactions/inline/render-plan.d.ts +3 -5
- package/dist/interactions/inline/render-plan.js.map +1 -1
- package/dist/interactions/media/extractor.js +2 -2
- package/dist/interactions/media/extractor.js.map +1 -1
- package/dist/interactions/modules.d.ts +11 -91
- package/dist/interactions/modules.js +185 -45
- package/dist/interactions/modules.js.map +1 -1
- package/dist/interactions/portable-custom/extractor.d.ts +1 -1
- package/dist/interactions/portable-custom/extractor.js +1 -1
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/position-object/extractor.js +3 -2
- package/dist/interactions/position-object/extractor.js.map +1 -1
- package/dist/interactions/select-point/extractor.js +7 -6
- package/dist/interactions/select-point/extractor.js.map +1 -1
- package/dist/interactions/shared/types.d.ts +59 -70
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/interactions/slider/extractor.js +2 -2
- package/dist/interactions/slider/extractor.js.map +1 -1
- package/dist/interactions/upload/extractor.js +2 -2
- package/dist/interactions/upload/extractor.js.map +1 -1
- package/dist/pci/types.d.ts +2 -3
- package/dist/pci/types.js.map +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +71 -38
- package/dist/presentation/itemPresentationPlan.js +78 -34
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/security/index.d.ts +1 -1
- package/dist/security/index.js +1 -1
- package/dist/security/index.js.map +1 -1
- package/dist/security/styleValues.d.ts +20 -0
- package/dist/security/styleValues.js +49 -0
- package/dist/security/styleValues.js.map +1 -0
- package/dist/server.d.ts +188 -9
- package/dist/server.js +32 -7
- package/dist/server.js.map +1 -1
- package/dist/types/index.d.ts +1 -110
- package/dist/types/index.js.map +1 -1
- package/dist/web-components/QTIInteractionBase.d.ts +2 -2
- package/dist/web-components/QTIInteractionBase.js.map +1 -1
- package/dist/web-components/QTIInteractionElement.d.ts +3 -3
- package/dist/web-components/QTIInteractionElement.js.map +1 -1
- package/package.json +11 -11
- package/dist/core/Plugin.d.ts +0 -104
- package/dist/core/Plugin.js +0 -8
- package/dist/core/Plugin.js.map +0 -1
- package/dist/core/PluginManager.d.ts +0 -55
- package/dist/core/PluginManager.js +0 -148
- package/dist/core/PluginManager.js.map +0 -1
- package/dist/element-class-C8OTgYHE.js.map +0 -1
- package/dist/interactions/associate/index.d.ts +0 -2
- package/dist/interactions/associate/index.js +0 -2
- package/dist/interactions/associate/index.js.map +0 -1
- package/dist/interactions/associate/types.d.ts +0 -1
- package/dist/interactions/associate/types.js +0 -2
- package/dist/interactions/associate/types.js.map +0 -1
- package/dist/interactions/choice/index.d.ts +0 -2
- package/dist/interactions/choice/index.js +0 -2
- package/dist/interactions/choice/index.js.map +0 -1
- package/dist/interactions/choice/types.d.ts +0 -1
- package/dist/interactions/choice/types.js +0 -2
- package/dist/interactions/choice/types.js.map +0 -1
- package/dist/interactions/custom/index.d.ts +0 -2
- package/dist/interactions/custom/index.js +0 -2
- package/dist/interactions/custom/index.js.map +0 -1
- package/dist/interactions/custom/types.d.ts +0 -1
- package/dist/interactions/custom/types.js +0 -2
- package/dist/interactions/custom/types.js.map +0 -1
- package/dist/interactions/drawing/index.d.ts +0 -2
- package/dist/interactions/drawing/index.js +0 -2
- package/dist/interactions/drawing/index.js.map +0 -1
- package/dist/interactions/drawing/types.d.ts +0 -1
- package/dist/interactions/drawing/types.js +0 -2
- package/dist/interactions/drawing/types.js.map +0 -1
- package/dist/interactions/end-attempt/index.d.ts +0 -2
- package/dist/interactions/end-attempt/index.js +0 -2
- package/dist/interactions/end-attempt/index.js.map +0 -1
- package/dist/interactions/end-attempt/types.d.ts +0 -1
- package/dist/interactions/end-attempt/types.js +0 -2
- package/dist/interactions/end-attempt/types.js.map +0 -1
- package/dist/interactions/extended-text/index.d.ts +0 -3
- package/dist/interactions/extended-text/index.js +0 -3
- package/dist/interactions/extended-text/index.js.map +0 -1
- package/dist/interactions/extended-text/types.d.ts +0 -1
- package/dist/interactions/extended-text/types.js +0 -2
- package/dist/interactions/extended-text/types.js.map +0 -1
- package/dist/interactions/gap-match/index.d.ts +0 -2
- package/dist/interactions/gap-match/index.js +0 -2
- package/dist/interactions/gap-match/index.js.map +0 -1
- package/dist/interactions/gap-match/types.d.ts +0 -1
- package/dist/interactions/gap-match/types.js +0 -2
- package/dist/interactions/gap-match/types.js.map +0 -1
- package/dist/interactions/graphic-associate/index.d.ts +0 -2
- package/dist/interactions/graphic-associate/index.js +0 -2
- package/dist/interactions/graphic-associate/index.js.map +0 -1
- package/dist/interactions/graphic-associate/types.d.ts +0 -1
- package/dist/interactions/graphic-associate/types.js +0 -2
- package/dist/interactions/graphic-associate/types.js.map +0 -1
- package/dist/interactions/graphic-gap-match/index.d.ts +0 -2
- package/dist/interactions/graphic-gap-match/index.js +0 -2
- package/dist/interactions/graphic-gap-match/index.js.map +0 -1
- package/dist/interactions/graphic-gap-match/types.d.ts +0 -1
- package/dist/interactions/graphic-gap-match/types.js +0 -2
- package/dist/interactions/graphic-gap-match/types.js.map +0 -1
- package/dist/interactions/graphic-order/index.d.ts +0 -2
- package/dist/interactions/graphic-order/index.js +0 -2
- package/dist/interactions/graphic-order/index.js.map +0 -1
- package/dist/interactions/graphic-order/types.d.ts +0 -1
- package/dist/interactions/graphic-order/types.js +0 -2
- package/dist/interactions/graphic-order/types.js.map +0 -1
- package/dist/interactions/hotspot/index.d.ts +0 -2
- package/dist/interactions/hotspot/index.js +0 -2
- package/dist/interactions/hotspot/index.js.map +0 -1
- package/dist/interactions/hotspot/types.d.ts +0 -1
- package/dist/interactions/hotspot/types.js +0 -2
- package/dist/interactions/hotspot/types.js.map +0 -1
- package/dist/interactions/hottext/index.d.ts +0 -2
- package/dist/interactions/hottext/index.js +0 -2
- package/dist/interactions/hottext/index.js.map +0 -1
- package/dist/interactions/hottext/types.d.ts +0 -1
- package/dist/interactions/hottext/types.js +0 -2
- package/dist/interactions/hottext/types.js.map +0 -1
- package/dist/interactions/index.d.ts +0 -32
- package/dist/interactions/index.js +0 -31
- package/dist/interactions/index.js.map +0 -1
- package/dist/interactions/inline/index.d.ts +0 -1
- package/dist/interactions/inline/index.js +0 -2
- package/dist/interactions/inline/index.js.map +0 -1
- package/dist/interactions/inline-choice/index.d.ts +0 -2
- package/dist/interactions/inline-choice/index.js +0 -2
- package/dist/interactions/inline-choice/index.js.map +0 -1
- package/dist/interactions/inline-choice/types.d.ts +0 -1
- package/dist/interactions/inline-choice/types.js +0 -2
- package/dist/interactions/inline-choice/types.js.map +0 -1
- package/dist/interactions/match/index.d.ts +0 -2
- package/dist/interactions/match/index.js +0 -2
- package/dist/interactions/match/index.js.map +0 -1
- package/dist/interactions/match/types.d.ts +0 -1
- package/dist/interactions/match/types.js +0 -2
- package/dist/interactions/match/types.js.map +0 -1
- package/dist/interactions/media/index.d.ts +0 -2
- package/dist/interactions/media/index.js +0 -2
- package/dist/interactions/media/index.js.map +0 -1
- package/dist/interactions/media/types.d.ts +0 -1
- package/dist/interactions/media/types.js +0 -2
- package/dist/interactions/media/types.js.map +0 -1
- package/dist/interactions/order/index.d.ts +0 -2
- package/dist/interactions/order/index.js +0 -2
- package/dist/interactions/order/index.js.map +0 -1
- package/dist/interactions/order/types.d.ts +0 -1
- package/dist/interactions/order/types.js +0 -2
- package/dist/interactions/order/types.js.map +0 -1
- package/dist/interactions/portable-custom/index.d.ts +0 -2
- package/dist/interactions/portable-custom/index.js +0 -2
- package/dist/interactions/portable-custom/index.js.map +0 -1
- package/dist/interactions/portable-custom/types.d.ts +0 -1
- package/dist/interactions/portable-custom/types.js +0 -2
- package/dist/interactions/portable-custom/types.js.map +0 -1
- package/dist/interactions/position-object/index.d.ts +0 -2
- package/dist/interactions/position-object/index.js +0 -2
- package/dist/interactions/position-object/index.js.map +0 -1
- package/dist/interactions/position-object/types.d.ts +0 -1
- package/dist/interactions/position-object/types.js +0 -2
- package/dist/interactions/position-object/types.js.map +0 -1
- package/dist/interactions/select-point/index.d.ts +0 -2
- package/dist/interactions/select-point/index.js +0 -2
- package/dist/interactions/select-point/index.js.map +0 -1
- package/dist/interactions/select-point/types.d.ts +0 -1
- package/dist/interactions/select-point/types.js +0 -2
- package/dist/interactions/select-point/types.js.map +0 -1
- package/dist/interactions/shared/index.d.ts +0 -1
- package/dist/interactions/shared/index.js +0 -2
- package/dist/interactions/shared/index.js.map +0 -1
- package/dist/interactions/slider/index.d.ts +0 -2
- package/dist/interactions/slider/index.js +0 -2
- package/dist/interactions/slider/index.js.map +0 -1
- package/dist/interactions/slider/types.d.ts +0 -1
- package/dist/interactions/slider/types.js +0 -2
- package/dist/interactions/slider/types.js.map +0 -1
- package/dist/interactions/text-entry/index.d.ts +0 -2
- package/dist/interactions/text-entry/index.js +0 -2
- package/dist/interactions/text-entry/index.js.map +0 -1
- package/dist/interactions/text-entry/types.d.ts +0 -1
- package/dist/interactions/text-entry/types.js +0 -2
- package/dist/interactions/text-entry/types.js.map +0 -1
- package/dist/interactions/upload/index.d.ts +0 -2
- package/dist/interactions/upload/index.js +0 -2
- package/dist/interactions/upload/index.js.map +0 -1
- package/dist/interactions/upload/types.d.ts +0 -1
- package/dist/interactions/upload/types.js +0 -2
- package/dist/interactions/upload/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentRegistry.js","sourceRoot":"","sources":["../../src/core/ComponentRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA6DH,MAAM,8BAA8B,GAAG;IACtC,iBAAiB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IACxE,iBAAiB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IACxE,gBAAgB,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE;IACrE,gBAAgB,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE;IACrE,oBAAoB,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,mBAAmB,EAAE;IACjF,mBAAmB,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,mBAAmB,EAAE;IAChF,kBAAkB,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,EAAE;IAC3E,kBAAkB,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,EAAE;IAC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AW,EAAE,iCAAiC,IAAI,EAAE;YACpD,QAAQ,EAAE,CAAC,GAAG;SACd,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["/**\n * Component Registry for Web Component-based Interaction Rendering\n *\n * Provides a pluggable system for registering web components to render\n * different QTI interaction types. Uses priority-based dispatch similar to the\n * ExtractionRegistry, but for framework-agnostic web components.\n */\n\nimport type { InteractionData } from '../interactions/index.js';\n\n/**\n * Configuration for registering a web component renderer\n */\nexport interface ComponentConfig<TData extends InteractionData = InteractionData> {\n\t/** Unique name for this renderer (e.g., 'rating-choice', 'standard-choice') */\n\tname: string;\n\n\t/**\n\t * Priority for renderer evaluation (higher = checked first)\n\t * - 100: Very specific custom renderers\n\t * - 50: Moderately specific custom renderers\n\t * - 10: Generic custom renderers\n\t * - 0: Default fallback renderers\n\t * Default: 0\n\t */\n\tpriority?: number;\n\n\t/** Optional description for debugging/error messages */\n\tdescription?: string;\n\n\t/**\n\t * Predicate to determine if this component can handle the interaction\n\t * Evaluated in priority order (highest first)\n\t * @returns true if this component should be used\n\t * Default: always true\n\t */\n\tcanHandle?: (data: TData) => boolean;\n\n\t/**\n\t * Web component tag name (must contain a hyphen per web component spec)\n\t * e.g., 'qti-choice-interaction', 'custom-rating-choice'\n\t */\n\ttagName: string;\n\n\t/**\n\t * Optional web component class constructor\n\t * If provided, the component will be automatically registered with customElements\n\t */\n\tcomponentClass?: CustomElementConstructor;\n\n\t/**\n\t * Whether to automatically register the component with customElements\n\t * Default: true if componentClass is provided\n\t */\n\tautoRegister?: boolean;\n}\n\n/**\n * Internal registered component with metadata\n */\ninterface RegisteredComponent<TData extends InteractionData = InteractionData> {\n\tconfig: ComponentConfig<TData> & {\n\t\tpriority: number;\n\t\tcanHandle: (data: TData) => boolean;\n\t};\n}\n\nconst DEFAULT_COMPONENT_TAGS_BY_TYPE = {\n\tchoiceInteraction: { name: 'default-choice', tagName: 'pie-qti-choice' },\n\tsliderInteraction: { name: 'default-slider', tagName: 'pie-qti-slider' },\n\torderInteraction: { name: 'default-order', tagName: 'pie-qti-order' },\n\tmatchInteraction: { name: 'default-match', tagName: 'pie-qti-match' },\n\tassociateInteraction: { name: 'default-associate', tagName: 'pie-qti-associate' },\n\tgapMatchInteraction: { name: 'default-gap-match', tagName: 'pie-qti-gap-match' },\n\thotspotInteraction: { name: 'default-hotspot', tagName: 'pie-qti-hotspot' },\n\thottextInteraction: { name: 'default-hottext', tagName: 'pie-qti-hottext' },\n\tmediaInteraction: { name: 'default-media', tagName: 'pie-qti-media' },\n\tcustomInteraction: { name: 'default-custom', tagName: 'pie-qti-custom' },\n\tportableCustomInteraction: { name: 'default-portable-custom', tagName: 'pie-qti-portable-custom' },\n\tendAttemptInteraction: { name: 'default-end-attempt', tagName: 'pie-qti-end-attempt' },\n\tpositionObjectInteraction: { name: 'default-position-object', tagName: 'pie-qti-position-object' },\n\tgraphicGapMatchInteraction: { name: 'default-graphic-gap-match', tagName: 'pie-qti-graphic-gap-match' },\n\tgraphicOrderInteraction: { name: 'default-graphic-order', tagName: 'pie-qti-graphic-order' },\n\tgraphicAssociateInteraction: { name: 'default-graphic-associate', tagName: 'pie-qti-graphic-associate' },\n\tselectPointInteraction: { name: 'default-select-point', tagName: 'pie-qti-select-point' },\n\textendedTextInteraction: { name: 'default-extended-text', tagName: 'pie-qti-extended-text' },\n\tuploadInteraction: { name: 'default-upload', tagName: 'pie-qti-upload' },\n\tdrawingInteraction: { name: 'default-drawing', tagName: 'pie-qti-drawing' },\n\tcatalogPopup: { name: 'default-catalog-popup', tagName: 'pie-qti-catalog-popup' },\n} satisfies Record<string, { name: string; tagName: string }>;\n\n/**\n * Registry for web components that render QTI interactions\n */\nexport class ComponentRegistry {\n\tprivate components = new Map<string, RegisteredComponent[]>();\n\tprivate definedElements = new Set<string>();\n\n\t/**\n\t * Register a web component for an interaction type with priority-based dispatch\n\t *\n\t * @param type - QTI interaction type (e.g., 'choiceInteraction', 'textEntryInteraction')\n\t * @param config - Component configuration with priority and canHandle predicate\n\t *\n\t * @example\n\t * // Custom rating choice component with high priority\n\t * registry.register('choiceInteraction', {\n\t * name: 'rating-choice',\n\t * priority: 100,\n\t * description: 'Star rating interactions',\n\t * canHandle: (data) => data.interactionClasses?.includes('rating-interaction'),\n\t * tagName: 'custom-rating-choice',\n\t * componentClass: RatingChoiceInteraction,\n\t * autoRegister: true\n\t * });\n\t *\n\t * // Default choice component\n\t * registry.register('choiceInteraction', {\n\t * name: 'standard-choice',\n\t * tagName: 'qti-choice-interaction'\n\t * });\n\t */\n\tregister<TData extends InteractionData>(\n\t\ttype: string,\n\t\tconfig: ComponentConfig<TData>\n\t): void {\n\t\t// Validate tag name\n\t\tif (!config.tagName.includes('-')) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid tag name '${config.tagName}'. ` +\n\t\t\t\t\t`Web component tag names must contain a hyphen.`\n\t\t\t);\n\t\t}\n\n\t\t// Auto-register custom element if requested\n\t\tif (config.componentClass && config.autoRegister !== false) {\n\t\t\tif (!this.definedElements.has(config.tagName)) {\n\t\t\t\tif (!customElements.get(config.tagName)) {\n\t\t\t\t\tcustomElements.define(config.tagName, config.componentClass);\n\t\t\t\t}\n\t\t\t\tthis.definedElements.add(config.tagName);\n\t\t\t}\n\t\t}\n\n\t\t// Get or create component array for this type\n\t\tlet components = this.components.get(type);\n\t\tif (!components) {\n\t\t\tcomponents = [];\n\t\t\tthis.components.set(type, components);\n\t\t}\n\n\t\t// Add normalized component and sort by priority (highest first)\n\t\tcomponents.push(this.createRegisteredComponent(config) as RegisteredComponent);\n\t\tcomponents.sort((a, b) => b.config.priority - a.config.priority);\n\t}\n\n\tprivate createRegisteredComponent<TData extends InteractionData>(\n\t\tconfig: ComponentConfig<TData>\n\t): RegisteredComponent<TData> {\n\t\treturn {\n\t\t\tconfig: {\n\t\t\t\t...config,\n\t\t\t\tpriority: config.priority ?? 0,\n\t\t\t\tcanHandle: config.canHandle ?? (() => true),\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Get a web component tag name for an interaction type\n\t * Evaluates canHandle predicates in priority order\n\t *\n\t * @param data - Interaction data\n\t * @returns Web component tag name (e.g., 'qti-choice-interaction')\n\t * @throws Error if no component matches\n\t */\n\tgetTagName<TData extends InteractionData>(data: TData): string {\n\t\tconst components = this.components.get(data.type);\n\n\t\tif (!components || components.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`No component registered for '${data.type}' interaction. ` +\n\t\t\t\t\t`Available types: ${Array.from(this.components.keys()).join(', ')}`\n\t\t\t);\n\t\t}\n\n\t\t// Evaluate canHandle in priority order\n\t\tfor (const { config } of components) {\n\t\t\ttry {\n\t\t\t\tif (config.canHandle(data as any)) {\n\t\t\t\t\treturn config.tagName;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Log but continue to next component\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`canHandle() failed for '${config.name}' component:`,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// No component matched\n\t\tconst componentList = components\n\t\t\t.map((c) => {\n\t\t\t\tconst desc = c.config.description ? ` (${c.config.description})` : '';\n\t\t\t\treturn `${c.config.name}${desc}`;\n\t\t\t})\n\t\t\t.join(', ');\n\n\t\tthrow new Error(\n\t\t\t`No component available for '${data.type}' interaction.\\n` +\n\t\t\t\t`Registered components: ${componentList}.\\n` +\n\t\t\t\t`None of these components matched the current interaction.`\n\t\t);\n\t}\n\n\t/**\n\t * Get all registered interaction types\n\t * @returns Array of registered interaction type names\n\t */\n\tgetRegisteredTypes(): string[] {\n\t\treturn Array.from(this.components.keys());\n\t}\n\n\t/**\n\t * Check if a component is registered for a type\n\t */\n\thasComponent(type: string): boolean {\n\t\treturn this.components.has(type) && this.components.get(type)!.length > 0;\n\t}\n\n\t/**\n\t * Get the tag name for a registered type by name (no canHandle evaluation).\n\t * Useful for non-interaction components like catalogPopup where the type string\n\t * is known and there is no InteractionData object to pass.\n\t *\n\t * Returns the highest-priority registered tag name for the type, or null if\n\t * the type is not registered.\n\t */\n\tgetTagNameForType(type: string): string | null {\n\t\tconst components = this.components.get(type);\n\t\tif (!components || components.length === 0) return null;\n\t\treturn components[0].config.tagName;\n\t}\n}\n\n/**\n * Create a new component registry\n */\nexport function createComponentRegistry(): ComponentRegistry {\n\tconst registry = new ComponentRegistry();\n\tregisterDefaultComponentTags(registry);\n\treturn registry;\n}\n\n/**\n * Register the default QTI interaction tag names without importing their implementations.\n *\n * Hosts still choose the implementation bundle, typically by importing\n * `@pie-qti/default-components/plugins` in the browser. Keeping only tag metadata here lets\n * the item-player custom element remain the public rendering boundary without depending on\n * Svelte-authored default components.\n */\nexport function registerDefaultComponentTags(registry: ComponentRegistry): void {\n\tfor (const [type, component] of Object.entries(DEFAULT_COMPONENT_TAGS_BY_TYPE)) {\n\t\tregistry.register(type, {\n\t\t\t...component,\n\t\t\tdescription: `Default web component tag for ${type}`,\n\t\t\tpriority: -100,\n\t\t});\n\t}\n}\n\n/**\n * Plugin interface for registering web components\n */\nexport interface ComponentPlugin {\n\t/** Plugin name (e.g., '@renaissance/rating-choice') */\n\tname: string;\n\n\t/** Plugin version (semver) */\n\tversion: string;\n\n\t/** Plugin description */\n\tdescription: string;\n\n\t/**\n\t * Register web components with the registry\n\t * @param registry - ComponentRegistry instance\n\t */\n\tregister(registry: ComponentRegistry): void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ComponentRegistry.js","sourceRoot":"","sources":["../../src/core/ComponentRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiEH,MAAM,8BAA8B,GAAG;IACtC,iBAAiB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IACxE,iBAAiB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IACxE,gBAAgB,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE;IACrE,gBAAgB,EAAE,EAA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AG;SACd,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["/**\n * Component Registry for Web Component-based Interaction Rendering\n *\n * Provides a pluggable system for registering web components to render\n * different QTI interaction types. Uses priority-based dispatch similar to the\n * ExtractionRegistry, but for framework-agnostic web components.\n */\n\nimport type { BaseInteractionData } from '../interactions/shared/types.js';\n\n/**\n * Configuration for registering a web component renderer\n */\nexport interface ComponentConfig<\n\tTData extends BaseInteractionData = BaseInteractionData,\n> {\n\t/** Unique name for this renderer (e.g., 'rating-choice', 'standard-choice') */\n\tname: string;\n\n\t/**\n\t * Priority for renderer evaluation (higher = checked first)\n\t * - 100: Very specific custom renderers\n\t * - 50: Moderately specific custom renderers\n\t * - 10: Generic custom renderers\n\t * - 0: Default fallback renderers\n\t * Default: 0\n\t */\n\tpriority?: number;\n\n\t/** Optional description for debugging/error messages */\n\tdescription?: string;\n\n\t/**\n\t * Predicate to determine if this component can handle the interaction\n\t * Evaluated in priority order (highest first)\n\t * @returns true if this component should be used\n\t * Default: always true\n\t */\n\tcanHandle?: (data: TData) => boolean;\n\n\t/**\n\t * Web component tag name (must contain a hyphen per web component spec)\n\t * e.g., 'qti-choice-interaction', 'custom-rating-choice'\n\t */\n\ttagName: string;\n\n\t/**\n\t * Optional web component class constructor\n\t * If provided, the component will be automatically registered with customElements\n\t */\n\tcomponentClass?: CustomElementConstructor;\n\n\t/**\n\t * Whether to automatically register the component with customElements\n\t * Default: true if componentClass is provided\n\t */\n\tautoRegister?: boolean;\n}\n\n/**\n * Internal registered component with metadata\n */\ninterface RegisteredComponent<\n\tTData extends BaseInteractionData = BaseInteractionData,\n> {\n\tconfig: ComponentConfig<TData> & {\n\t\tpriority: number;\n\t\tcanHandle: (data: TData) => boolean;\n\t};\n}\n\nconst DEFAULT_COMPONENT_TAGS_BY_TYPE = {\n\tchoiceInteraction: { name: 'default-choice', tagName: 'pie-qti-choice' },\n\tsliderInteraction: { name: 'default-slider', tagName: 'pie-qti-slider' },\n\torderInteraction: { name: 'default-order', tagName: 'pie-qti-order' },\n\tmatchInteraction: { name: 'default-match', tagName: 'pie-qti-match' },\n\tassociateInteraction: { name: 'default-associate', tagName: 'pie-qti-associate' },\n\tgapMatchInteraction: { name: 'default-gap-match', tagName: 'pie-qti-gap-match' },\n\thotspotInteraction: { name: 'default-hotspot', tagName: 'pie-qti-hotspot' },\n\thottextInteraction: { name: 'default-hottext', tagName: 'pie-qti-hottext' },\n\tmediaInteraction: { name: 'default-media', tagName: 'pie-qti-media' },\n\tcustomInteraction: { name: 'default-custom', tagName: 'pie-qti-custom' },\n\tportableCustomInteraction: { name: 'default-portable-custom', tagName: 'pie-qti-portable-custom' },\n\tendAttemptInteraction: { name: 'default-end-attempt', tagName: 'pie-qti-end-attempt' },\n\tpositionObjectInteraction: { name: 'default-position-object', tagName: 'pie-qti-position-object' },\n\tgraphicGapMatchInteraction: { name: 'default-graphic-gap-match', tagName: 'pie-qti-graphic-gap-match' },\n\tgraphicOrderInteraction: { name: 'default-graphic-order', tagName: 'pie-qti-graphic-order' },\n\tgraphicAssociateInteraction: { name: 'default-graphic-associate', tagName: 'pie-qti-graphic-associate' },\n\tselectPointInteraction: { name: 'default-select-point', tagName: 'pie-qti-select-point' },\n\textendedTextInteraction: { name: 'default-extended-text', tagName: 'pie-qti-extended-text' },\n\tuploadInteraction: { name: 'default-upload', tagName: 'pie-qti-upload' },\n\tdrawingInteraction: { name: 'default-drawing', tagName: 'pie-qti-drawing' },\n\tcatalogPopup: { name: 'default-catalog-popup', tagName: 'pie-qti-catalog-popup' },\n} satisfies Record<string, { name: string; tagName: string }>;\n\n/**\n * Registry for web components that render QTI interactions\n */\nexport class ComponentRegistry {\n\tprivate components = new Map<string, RegisteredComponent<any>[]>();\n\tprivate definedElements = new Set<string>();\n\tprivate sealed = false;\n\n\t/**\n\t * Register a web component for an interaction type with priority-based dispatch\n\t *\n\t * @param type - QTI interaction type (e.g., 'choiceInteraction', 'textEntryInteraction')\n\t * @param config - Component configuration with priority and canHandle predicate\n\t *\n\t * @example\n\t * // Custom rating choice component with high priority\n\t * registry.register('choiceInteraction', {\n\t * name: 'rating-choice',\n\t * priority: 100,\n\t * description: 'Star rating interactions',\n\t * canHandle: (data) => data.interactionClasses?.includes('rating-interaction'),\n\t * tagName: 'custom-rating-choice',\n\t * componentClass: RatingChoiceInteraction,\n\t * autoRegister: true\n\t * });\n\t *\n\t * // Default choice component\n\t * registry.register('choiceInteraction', {\n\t * name: 'standard-choice',\n\t * tagName: 'qti-choice-interaction'\n\t * });\n\t */\n\tregister<TData extends BaseInteractionData>(\n\t\ttype: string,\n\t\tconfig: ComponentConfig<TData>\n\t): void {\n\t\tthis.assertMutable();\n\t\t// Validate tag name\n\t\tif (!config.tagName.includes('-')) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid tag name '${config.tagName}'. ` +\n\t\t\t\t\t`Web component tag names must contain a hyphen.`\n\t\t\t);\n\t\t}\n\n\t\tconst registered = this.createRegisteredComponent(config);\n\t\t// Define eagerly in a browser. In a headless compiler there is no custom\n\t\t// element registry, so registration is deferred until the renderer is used.\n\t\tthis.ensureCustomElementDefined(registered.config);\n\n\t\t// Get or create component array for this type\n\t\tlet components = this.components.get(type);\n\t\tif (!components) {\n\t\t\tcomponents = [];\n\t\t\tthis.components.set(type, components);\n\t\t}\n\n\t\t// Add normalized component and sort by priority (highest first)\n\t\tcomponents.push(registered as RegisteredComponent);\n\t\tcomponents.sort((a, b) => b.config.priority - a.config.priority);\n\t}\n\n\tprivate createRegisteredComponent<TData extends BaseInteractionData>(\n\t\tconfig: ComponentConfig<TData>\n\t): RegisteredComponent<TData> {\n\t\treturn Object.freeze({\n\t\t\tconfig: Object.freeze({\n\t\t\t\t...config,\n\t\t\t\tpriority: config.priority ?? 0,\n\t\t\t\tcanHandle: config.canHandle?.bind(config) ?? (() => true),\n\t\t\t}),\n\t\t});\n\t}\n\n\tprivate ensureCustomElementDefined<TData extends BaseInteractionData>(\n\t\tconfig: RegisteredComponent<TData>['config'],\n\t): void {\n\t\tif (\n\t\t\t!config.componentClass ||\n\t\t\tconfig.autoRegister === false ||\n\t\t\tthis.definedElements.has(config.tagName)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst registry = globalThis.customElements;\n\t\tif (!registry) return;\n\t\tif (!registry.get(config.tagName)) {\n\t\t\tregistry.define(config.tagName, config.componentClass);\n\t\t}\n\t\tthis.definedElements.add(config.tagName);\n\t}\n\n\t/**\n\t * Get a web component tag name for an interaction type\n\t * Evaluates canHandle predicates in priority order\n\t *\n\t * @param data - Interaction data\n\t * @returns Web component tag name (e.g., 'qti-choice-interaction')\n\t * @throws Error if no component matches\n\t */\n\tgetTagName<TData extends BaseInteractionData>(data: TData): string {\n\t\tconst components = this.components.get(data.type);\n\n\t\tif (!components || components.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`No component registered for '${data.type}' interaction. ` +\n\t\t\t\t\t`Available types: ${Array.from(this.components.keys()).join(', ')}`\n\t\t\t);\n\t\t}\n\n\t\t// Evaluate canHandle in priority order\n\t\tfor (const { config } of components) {\n\t\t\ttry {\n\t\t\t\tif (config.canHandle(data as any)) {\n\t\t\t\t\tthis.ensureCustomElementDefined(config);\n\t\t\t\t\treturn config.tagName;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Log but continue to next component\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`canHandle() failed for '${config.name}' component:`,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// No component matched\n\t\tconst componentList = components\n\t\t\t.map((c) => {\n\t\t\t\tconst desc = c.config.description ? ` (${c.config.description})` : '';\n\t\t\t\treturn `${c.config.name}${desc}`;\n\t\t\t})\n\t\t\t.join(', ');\n\n\t\tthrow new Error(\n\t\t\t`No component available for '${data.type}' interaction.\\n` +\n\t\t\t\t`Registered components: ${componentList}.\\n` +\n\t\t\t\t`None of these components matched the current interaction.`\n\t\t);\n\t}\n\n\t/**\n\t * Get all registered interaction types\n\t * @returns Array of registered interaction type names\n\t */\n\tgetRegisteredTypes(): string[] {\n\t\treturn Array.from(this.components.keys());\n\t}\n\n\t/**\n\t * Check if a component is registered for a type\n\t */\n\thasComponent(type: string): boolean {\n\t\treturn this.components.has(type) && this.components.get(type)!.length > 0;\n\t}\n\n\t/**\n\t * Get the tag name for a registered type by name (no canHandle evaluation).\n\t * Useful for non-interaction components like catalogPopup where the type string\n\t * is known and there is no delivered interaction object to pass.\n\t *\n\t * Returns the highest-priority registered tag name for the type, or null if\n\t * the type is not registered.\n\t */\n\tgetTagNameForType(type: string): string | null {\n\t\tconst components = this.components.get(type);\n\t\tif (!components || components.length === 0) return null;\n\t\tconst config = components[0].config;\n\t\tthis.ensureCustomElementDefined(config);\n\t\treturn config.tagName;\n\t}\n\n\t/** Freeze renderer selection for a compiled AssessmentItem definition. */\n\tseal(): this {\n\t\tthis.sealed = true;\n\t\treturn this;\n\t}\n\n\tisSealed(): boolean {\n\t\treturn this.sealed;\n\t}\n\n\tprivate assertMutable(): void {\n\t\tif (this.sealed) {\n\t\t\tthrow new Error(\n\t\t\t\t'ComponentRegistry is sealed for this AssessmentItem; create a new definition to change renderers',\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Create a new component registry\n */\nexport function createComponentRegistry(): ComponentRegistry {\n\tconst registry = new ComponentRegistry();\n\tregisterDefaultComponentTags(registry);\n\treturn registry;\n}\n\n/**\n * Register the default QTI interaction tag names without importing their implementations.\n *\n * Hosts still choose the implementation bundle, typically by importing\n * `@pie-qti/default-components/plugins` in the browser. Keeping only tag metadata here lets\n * the item-player custom element remain the public rendering boundary without depending on\n * Svelte-authored default components.\n */\nexport function registerDefaultComponentTags(registry: ComponentRegistry): void {\n\tfor (const [type, component] of Object.entries(DEFAULT_COMPONENT_TAGS_BY_TYPE)) {\n\t\tregistry.register(type, {\n\t\t\t...component,\n\t\t\tdescription: `Default web component tag for ${type}`,\n\t\t\tpriority: -100,\n\t\t});\n\t}\n}\n\n/**\n * Plugin interface for registering web components\n */\nexport interface ComponentPlugin {\n\t/** Plugin name (e.g., '@renaissance/rating-choice') */\n\tname: string;\n\n\t/** Plugin version (semver) */\n\tversion: string;\n\n\t/** Plugin description */\n\tdescription: string;\n\n\t/**\n\t * Register web components with the registry\n\t * @param registry - ComponentRegistry instance\n\t */\n\tregister(registry: ComponentRegistry): void;\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PnpProfile } from '../pnp/types.js';
|
|
2
|
+
import { type CreateItemPresentationOptions, type ItemPresentation } from '../presentation/itemPresentationPlan.js';
|
|
3
|
+
import type { CompletionStatus, ItemLifecycleStatus, ItemSessionActionCommand, ItemSessionActionResult, QTIRole, SerializedItemSessionState } from '../types/index.js';
|
|
4
|
+
export interface OpenItemSessionOptions {
|
|
5
|
+
/** Restore a previously serialized state before applying response overrides. */
|
|
6
|
+
restore?: SerializedItemSessionState;
|
|
7
|
+
/** Initial responses, or overrides applied after restore. */
|
|
8
|
+
responses?: Readonly<Record<string, unknown>>;
|
|
9
|
+
/** Resume a suspended handoff as an active interaction session. */
|
|
10
|
+
activate?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type ItemSessionCommand = ItemSessionActionCommand | {
|
|
13
|
+
action: 'setResponse';
|
|
14
|
+
responseIdentifier: string;
|
|
15
|
+
value: unknown;
|
|
16
|
+
} | {
|
|
17
|
+
action: 'setResponses';
|
|
18
|
+
responses: Readonly<Record<string, unknown>>;
|
|
19
|
+
} | {
|
|
20
|
+
action: 'updatePnp';
|
|
21
|
+
profile: Partial<PnpProfile>;
|
|
22
|
+
};
|
|
23
|
+
export type ItemSessionEventCommand = ItemSessionCommand | {
|
|
24
|
+
action: 'dispose';
|
|
25
|
+
};
|
|
26
|
+
export interface ItemSessionView {
|
|
27
|
+
readonly revision: number;
|
|
28
|
+
readonly itemIdentifier?: string;
|
|
29
|
+
readonly role: QTIRole;
|
|
30
|
+
readonly lifecycleStatus: ItemLifecycleStatus;
|
|
31
|
+
readonly completionStatus: CompletionStatus;
|
|
32
|
+
readonly numAttempts: number;
|
|
33
|
+
readonly duration: number;
|
|
34
|
+
readonly adaptive: boolean;
|
|
35
|
+
readonly completed: boolean;
|
|
36
|
+
readonly canSubmit: boolean;
|
|
37
|
+
readonly disposed: boolean;
|
|
38
|
+
readonly responses: Readonly<Record<string, unknown>>;
|
|
39
|
+
readonly outcomes: Readonly<Record<string, unknown>>;
|
|
40
|
+
readonly templates: Readonly<Record<string, unknown>>;
|
|
41
|
+
readonly context: Readonly<Record<string, unknown>>;
|
|
42
|
+
}
|
|
43
|
+
export interface ItemSessionTransition {
|
|
44
|
+
readonly command: ItemSessionEventCommand;
|
|
45
|
+
readonly previous: ItemSessionView;
|
|
46
|
+
readonly current: ItemSessionView;
|
|
47
|
+
readonly result?: ItemSessionActionResult;
|
|
48
|
+
}
|
|
49
|
+
export type ItemSessionListener = (transition: ItemSessionTransition) => void;
|
|
50
|
+
export type ItemPresentationView = Omit<CreateItemPresentationOptions, 'outcomeValues' | 'responses' | 'role' | 'source'>;
|
|
51
|
+
export interface ItemSession {
|
|
52
|
+
state(): ItemSessionView;
|
|
53
|
+
dispatch(command: ItemSessionCommand): ItemSessionTransition;
|
|
54
|
+
present(view?: ItemPresentationView): ItemPresentation;
|
|
55
|
+
subscribe(listener: ItemSessionListener): () => void;
|
|
56
|
+
serialize(): SerializedItemSessionState;
|
|
57
|
+
dispose(): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { createItemPresentation, } from '../presentation/itemPresentationPlan.js';
|
|
2
|
+
import { createPlayerFromPreparedInternal, Player } from './Player.js';
|
|
3
|
+
/**
|
|
4
|
+
* Browser adapters use this without gaining access to the private session engine.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export function getItemSessionBinding(session) {
|
|
8
|
+
const runtimeSession = session;
|
|
9
|
+
if (typeof runtimeSession.getRuntimeBinding !== 'function') {
|
|
10
|
+
throw new Error('ItemSession runtime binding is unavailable');
|
|
11
|
+
}
|
|
12
|
+
return runtimeSession.getRuntimeBinding();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Construct sessions through AssessmentItemDefinition.openSession().
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export class LiveItemSession {
|
|
19
|
+
/** @internal Construct sessions through AssessmentItemDefinition.openSession(). */
|
|
20
|
+
constructor(itemIdentifier, config, options = {}, prepared) {
|
|
21
|
+
this.itemIdentifier = itemIdentifier;
|
|
22
|
+
this.listeners = new Set();
|
|
23
|
+
this.revision = 0;
|
|
24
|
+
this.disposed = false;
|
|
25
|
+
this.defaultRole = config.role ?? 'candidate';
|
|
26
|
+
const playerConfig = { ...config };
|
|
27
|
+
this.player = prepared
|
|
28
|
+
? createPlayerFromPreparedInternal(playerConfig, prepared, Boolean(options.restore))
|
|
29
|
+
: new Player(playerConfig);
|
|
30
|
+
try {
|
|
31
|
+
if (options.responses) {
|
|
32
|
+
this.assertKnownResponseIdentifiers(Object.keys(options.responses));
|
|
33
|
+
}
|
|
34
|
+
if (options.restore)
|
|
35
|
+
this.player.restoreItemSession(options.restore);
|
|
36
|
+
if (options.activate && this.player.getLifecycleStatus() === 'suspended') {
|
|
37
|
+
this.player.activateAttempt();
|
|
38
|
+
}
|
|
39
|
+
if (options.responses) {
|
|
40
|
+
const lifecycle = this.player.getLifecycleStatus();
|
|
41
|
+
if (!isResponseWritableLifecycle(lifecycle)) {
|
|
42
|
+
throw new Error(`Cannot override responses while item session is ${lifecycle}`);
|
|
43
|
+
}
|
|
44
|
+
this.player.setResponses({ ...options.responses });
|
|
45
|
+
}
|
|
46
|
+
this.currentView = this.captureView();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
this.player.destroy();
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
this.runtimeBinding = this.createBinding();
|
|
53
|
+
}
|
|
54
|
+
state() {
|
|
55
|
+
return immutableSnapshot(this.currentView);
|
|
56
|
+
}
|
|
57
|
+
dispatch(command) {
|
|
58
|
+
this.assertActive();
|
|
59
|
+
if (commandRequiresWritableLifecycle(command) &&
|
|
60
|
+
!isResponseWritableLifecycle(this.currentView.lifecycleStatus)) {
|
|
61
|
+
throw new Error(`Cannot ${describeCommand(command)} while item session is ${this.currentView.lifecycleStatus}`);
|
|
62
|
+
}
|
|
63
|
+
const previous = this.currentView;
|
|
64
|
+
let result;
|
|
65
|
+
switch (command.action) {
|
|
66
|
+
case 'setResponse':
|
|
67
|
+
this.assertKnownResponseIdentifiers([command.responseIdentifier]);
|
|
68
|
+
this.player.setResponses({ [command.responseIdentifier]: command.value });
|
|
69
|
+
break;
|
|
70
|
+
case 'setResponses':
|
|
71
|
+
this.assertKnownResponseIdentifiers(Object.keys(command.responses));
|
|
72
|
+
this.player.setResponses({ ...command.responses });
|
|
73
|
+
break;
|
|
74
|
+
case 'updatePnp':
|
|
75
|
+
this.player.updatePnp(command.profile);
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
result = this.player.runItemSessionAction(command);
|
|
79
|
+
}
|
|
80
|
+
this.revision += 1;
|
|
81
|
+
this.currentView = this.captureView(result?.sessionState);
|
|
82
|
+
const transition = freezeTransition({ command, previous, current: this.currentView, result });
|
|
83
|
+
this.notify(transition);
|
|
84
|
+
return transition;
|
|
85
|
+
}
|
|
86
|
+
present(view = {}) {
|
|
87
|
+
this.assertActive();
|
|
88
|
+
return createItemPresentation({
|
|
89
|
+
...view,
|
|
90
|
+
disabled: view.disabled === true || !isResponseWritableLifecycle(this.currentView.lifecycleStatus),
|
|
91
|
+
source: {
|
|
92
|
+
itemBodyHtml: this.player.getItemBodyHtml(),
|
|
93
|
+
interactions: this.player.getInteractionData(),
|
|
94
|
+
correctResponses: this.player.getCorrectResponses(),
|
|
95
|
+
componentRegistry: this.player.getComponentRegistry(),
|
|
96
|
+
deliveryContext: this.player.getDeliveryContext(),
|
|
97
|
+
pnp: this.player.getPnp(),
|
|
98
|
+
security: this.player.getSecurityConfig(),
|
|
99
|
+
directRubrics: this.player.getRubrics({ scope: 'direct' }),
|
|
100
|
+
},
|
|
101
|
+
responses: immutableSnapshot(this.currentView.responses),
|
|
102
|
+
outcomeValues: immutableSnapshot(this.currentView.outcomes),
|
|
103
|
+
role: this.defaultRole,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
subscribe(listener) {
|
|
107
|
+
this.assertActive();
|
|
108
|
+
this.listeners.add(listener);
|
|
109
|
+
return () => this.listeners.delete(listener);
|
|
110
|
+
}
|
|
111
|
+
serialize() {
|
|
112
|
+
this.assertActive();
|
|
113
|
+
return immutableSnapshot(this.player.saveItemSession());
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Browser/runtime capabilities carried by the session across package bundles.
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
119
|
+
getRuntimeBinding() {
|
|
120
|
+
this.assertActive();
|
|
121
|
+
return this.runtimeBinding;
|
|
122
|
+
}
|
|
123
|
+
dispose() {
|
|
124
|
+
if (this.disposed)
|
|
125
|
+
return;
|
|
126
|
+
const previous = this.currentView;
|
|
127
|
+
this.disposed = true;
|
|
128
|
+
this.revision += 1;
|
|
129
|
+
this.currentView = immutableSnapshot({
|
|
130
|
+
...previous,
|
|
131
|
+
revision: this.revision,
|
|
132
|
+
disposed: true,
|
|
133
|
+
});
|
|
134
|
+
this.player.destroy();
|
|
135
|
+
this.notify(freezeTransition({
|
|
136
|
+
command: { action: 'dispose' },
|
|
137
|
+
previous,
|
|
138
|
+
current: this.currentView,
|
|
139
|
+
}));
|
|
140
|
+
this.listeners.clear();
|
|
141
|
+
}
|
|
142
|
+
captureView(serialized = this.player.saveItemSession()) {
|
|
143
|
+
const responses = valuesOf(serialized.responseVariables);
|
|
144
|
+
return immutableSnapshot({
|
|
145
|
+
revision: this.revision,
|
|
146
|
+
itemIdentifier: serialized.itemIdentifier || this.itemIdentifier || undefined,
|
|
147
|
+
role: this.defaultRole,
|
|
148
|
+
lifecycleStatus: serialized.lifecycleStatus,
|
|
149
|
+
completionStatus: serialized.completionStatus,
|
|
150
|
+
numAttempts: serialized.numAttempts,
|
|
151
|
+
duration: serialized.duration,
|
|
152
|
+
adaptive: this.player.isAdaptive(),
|
|
153
|
+
completed: this.player.isCompleted(),
|
|
154
|
+
canSubmit: this.player.canSubmitResponses(responses),
|
|
155
|
+
disposed: this.disposed,
|
|
156
|
+
responses,
|
|
157
|
+
outcomes: valuesOf(serialized.outcomeVariables),
|
|
158
|
+
templates: valuesOf(serialized.templateVariables),
|
|
159
|
+
context: valuesOf(serialized.contextVariables),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
createBinding() {
|
|
163
|
+
return Object.freeze({
|
|
164
|
+
role: this.defaultRole,
|
|
165
|
+
applyPnp: (root) => {
|
|
166
|
+
this.assertActive();
|
|
167
|
+
this.player.applyPnp(root);
|
|
168
|
+
},
|
|
169
|
+
getPnp: () => {
|
|
170
|
+
this.assertActive();
|
|
171
|
+
return this.player.getPnp();
|
|
172
|
+
},
|
|
173
|
+
onPnpChange: (listener) => {
|
|
174
|
+
this.assertActive();
|
|
175
|
+
return this.player.onPnpChange(() => listener());
|
|
176
|
+
},
|
|
177
|
+
getCatalogEntry: (idref, usage, lang, options) => {
|
|
178
|
+
this.assertActive();
|
|
179
|
+
return this.player.getCatalogEntry(idref, usage, lang, options);
|
|
180
|
+
},
|
|
181
|
+
getComponentRegistry: () => {
|
|
182
|
+
this.assertActive();
|
|
183
|
+
return this.player.getComponentRegistry();
|
|
184
|
+
},
|
|
185
|
+
getDeliveryContext: () => {
|
|
186
|
+
this.assertActive();
|
|
187
|
+
return this.player.getDeliveryContext();
|
|
188
|
+
},
|
|
189
|
+
getSecurityConfig: () => {
|
|
190
|
+
this.assertActive();
|
|
191
|
+
return this.player.getSecurityConfig();
|
|
192
|
+
},
|
|
193
|
+
getI18nProvider: () => {
|
|
194
|
+
this.assertActive();
|
|
195
|
+
return this.player.getI18nProvider();
|
|
196
|
+
},
|
|
197
|
+
createPciHost: (data) => {
|
|
198
|
+
this.assertActive();
|
|
199
|
+
const host = this.player.createPciHost(data);
|
|
200
|
+
host.onResponseChange(() => {
|
|
201
|
+
if (this.disposed ||
|
|
202
|
+
!isResponseWritableLifecycle(this.currentView.lifecycleStatus))
|
|
203
|
+
return;
|
|
204
|
+
const previous = this.currentView;
|
|
205
|
+
this.revision += 1;
|
|
206
|
+
this.currentView = this.captureView();
|
|
207
|
+
this.notify(freezeTransition({
|
|
208
|
+
command: {
|
|
209
|
+
action: 'setResponse',
|
|
210
|
+
responseIdentifier: data.responseIdentifier,
|
|
211
|
+
value: host.getResponse(),
|
|
212
|
+
},
|
|
213
|
+
previous,
|
|
214
|
+
current: this.currentView,
|
|
215
|
+
}));
|
|
216
|
+
});
|
|
217
|
+
return host;
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
notify(transition) {
|
|
222
|
+
for (const listener of [...this.listeners]) {
|
|
223
|
+
try {
|
|
224
|
+
listener(immutableSnapshot(transition));
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
console.error('[QTI ItemSession] subscriber failed:', error);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
assertActive() {
|
|
232
|
+
if (this.disposed)
|
|
233
|
+
throw new Error('ItemSession has been disposed');
|
|
234
|
+
}
|
|
235
|
+
assertKnownResponseIdentifiers(responseIdentifiers) {
|
|
236
|
+
const knownIdentifiers = new Set(Object.keys(this.player.getResponses()));
|
|
237
|
+
const unknown = responseIdentifiers.find((identifier) => !knownIdentifiers.has(identifier));
|
|
238
|
+
if (unknown)
|
|
239
|
+
throw new Error(`Unknown response identifier '${unknown}'`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function isResponseWritableLifecycle(status) {
|
|
243
|
+
return status === 'initial' || status === 'interacting';
|
|
244
|
+
}
|
|
245
|
+
function commandRequiresWritableLifecycle(command) {
|
|
246
|
+
return command.action === 'setResponse' ||
|
|
247
|
+
command.action === 'setResponses' ||
|
|
248
|
+
command.action === 'suspendAttempt' ||
|
|
249
|
+
command.action === 'endAttempt' ||
|
|
250
|
+
command.action === 'submitAttempt';
|
|
251
|
+
}
|
|
252
|
+
function describeCommand(command) {
|
|
253
|
+
return command.action === 'setResponse' || command.action === 'setResponses'
|
|
254
|
+
? 'update responses'
|
|
255
|
+
: `run ${command.action}`;
|
|
256
|
+
}
|
|
257
|
+
function valuesOf(variables) {
|
|
258
|
+
return Object.fromEntries(Object.entries(variables).map(([identifier, variable]) => [
|
|
259
|
+
identifier,
|
|
260
|
+
immutableSnapshot(variable.value),
|
|
261
|
+
]));
|
|
262
|
+
}
|
|
263
|
+
function freezeTransition(transition) {
|
|
264
|
+
return immutableSnapshot(transition);
|
|
265
|
+
}
|
|
266
|
+
/** Clone and freeze plain data without mutating values owned by the caller or a PCI module. */
|
|
267
|
+
function immutableSnapshot(value) {
|
|
268
|
+
if (Array.isArray(value)) {
|
|
269
|
+
return Object.freeze(value.map((entry) => immutableSnapshot(entry)));
|
|
270
|
+
}
|
|
271
|
+
if (!value || typeof value !== 'object')
|
|
272
|
+
return value;
|
|
273
|
+
if (ArrayBuffer.isView(value))
|
|
274
|
+
return structuredClone(value);
|
|
275
|
+
if (value instanceof ArrayBuffer)
|
|
276
|
+
return value.slice(0);
|
|
277
|
+
const prototype = Object.getPrototypeOf(value);
|
|
278
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
279
|
+
return value;
|
|
280
|
+
const snapshot = Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
281
|
+
key,
|
|
282
|
+
immutableSnapshot(entry),
|
|
283
|
+
]));
|
|
284
|
+
return Object.freeze(snapshot);
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=ItemSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemSession.js","sourceRoot":"","sources":["../../src/core/ItemSession.ts"],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AC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QACtE,GAAG;QACH,iBAAiB,CAAC,KAAK,CAAC;KACxB,CAAC,CACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAM,CAAC;AACrC,CAAC","sourcesContent":["import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport type { PnpProfile } from '../pnp/types.js';\nimport type { ExtractedPci, PciHostController } from '../pci/types.js';\nimport {\n\tcreateItemPresentation,\n\ttype CreateItemPresentationOptions,\n\ttype ItemPresentation,\n} from '../presentation/itemPresentationPlan.js';\nimport type {\n\tCompletionStatus,\n\tHtmlContent,\n\tItemLifecycleStatus,\n\tItemSessionActionCommand,\n\tItemSessionActionResult,\n\tItemSessionEngineConfig,\n\tPlayerSecurityConfig,\n\tQTIRole,\n\tSerializedItemSessionState,\n\tSerializedItemSessionVariable,\n} from '../types/index.js';\nimport type { BaseInteractionData } from '../interactions/shared/types.js';\nimport { createPlayerFromPreparedInternal, Player } from './Player.js';\n\nexport interface OpenItemSessionOptions {\n\t/** Restore a previously serialized state before applying response overrides. */\n\trestore?: SerializedItemSessionState;\n\t/** Initial responses, or overrides applied after restore. */\n\tresponses?: Readonly<Record<string, unknown>>;\n\t/** Resume a suspended handoff as an active interaction session. */\n\tactivate?: boolean;\n}\n\nexport type ItemSessionCommand =\n\t| ItemSessionActionCommand\n\t| { action: 'setResponse'; responseIdentifier: string; value: unknown }\n\t| { action: 'setResponses'; responses: Readonly<Record<string, unknown>> }\n\t| { action: 'updatePnp'; profile: Partial<PnpProfile> };\n\nexport type ItemSessionEventCommand = ItemSessionCommand | { action: 'dispose' };\n\nexport interface ItemSessionView {\n\treadonly revision: number;\n\treadonly itemIdentifier?: string;\n\treadonly role: QTIRole;\n\treadonly lifecycleStatus: ItemLifecycleStatus;\n\treadonly completionStatus: CompletionStatus;\n\treadonly numAttempts: number;\n\treadonly duration: number;\n\treadonly adaptive: boolean;\n\treadonly completed: boolean;\n\treadonly canSubmit: boolean;\n\treadonly disposed: boolean;\n\treadonly responses: Readonly<Record<string, unknown>>;\n\treadonly outcomes: Readonly<Record<string, unknown>>;\n\treadonly templates: Readonly<Record<string, unknown>>;\n\treadonly context: Readonly<Record<string, unknown>>;\n}\n\nexport interface ItemSessionTransition {\n\treadonly command: ItemSessionEventCommand;\n\treadonly previous: ItemSessionView;\n\treadonly current: ItemSessionView;\n\treadonly result?: ItemSessionActionResult;\n}\n\nexport type ItemSessionListener = (transition: ItemSessionTransition) => void;\n\nexport type ItemPresentationView = Omit<\n\tCreateItemPresentationOptions,\n\t'outcomeValues' | 'responses' | 'role' | 'source'\n>;\n\nexport interface ItemSession {\n\tstate(): ItemSessionView;\n\tdispatch(command: ItemSessionCommand): ItemSessionTransition;\n\tpresent(view?: ItemPresentationView): ItemPresentation;\n\tsubscribe(listener: ItemSessionListener): () => void;\n\tserialize(): SerializedItemSessionState;\n\tdispose(): void;\n}\n\n/**\n * Narrow browser/runtime capabilities needed after a presentation has been produced.\n * This interface deliberately excludes Player, parser nodes, declarations, and extraction registries.\n * @internal\n */\nexport interface ItemSessionBinding {\n\treadonly role: QTIRole;\n\tapplyPnp(root: HTMLElement): void;\n\tgetPnp(): PnpProfile | undefined;\n\tonPnpChange(listener: () => void): () => void;\n\tgetCatalogEntry(\n\t\tidref: string,\n\t\tusage: string,\n\t\tlang?: string,\n\t\toptions?: { stimulusIdentifier?: string }\n\t): HtmlContent | null;\n\tgetComponentRegistry(): ItemSessionComponentRegistry;\n\tgetDeliveryContext(): ResolvedItemDeliveryContext | undefined;\n\tgetSecurityConfig(): PlayerSecurityConfig | undefined;\n\tgetI18nProvider(): unknown;\n\tcreatePciHost(data: ExtractedPci): PciHostController;\n}\n\n/** @internal */\nexport interface ItemSessionComponentRegistry {\n\tgetTagName(interaction: BaseInteractionData): string;\n\tgetTagNameForType(type: string): string | null;\n}\n\n/**\n * Browser adapters use this without gaining access to the private session engine.\n * @internal\n */\nexport function getItemSessionBinding(session: ItemSession): ItemSessionBinding {\n\tconst runtimeSession = session as ItemSession & {\n\t\tgetRuntimeBinding?: () => ItemSessionBinding;\n\t};\n\tif (typeof runtimeSession.getRuntimeBinding !== 'function') {\n\t\tthrow new Error('ItemSession runtime binding is unavailable');\n\t}\n\treturn runtimeSession.getRuntimeBinding();\n}\n\n/**\n * Construct sessions through AssessmentItemDefinition.openSession().\n * @internal\n */\nexport class LiveItemSession implements ItemSession {\n\tprivate readonly player: Player;\n\tprivate readonly listeners = new Set<ItemSessionListener>();\n\tprivate readonly defaultRole: QTIRole;\n\tprivate revision = 0;\n\tprivate disposed = false;\n\tprivate currentView: ItemSessionView;\n\tprivate readonly runtimeBinding: ItemSessionBinding;\n\n\t/** @internal Construct sessions through AssessmentItemDefinition.openSession(). */\n\tconstructor(\n\t\tprivate readonly itemIdentifier: string,\n\t\tconfig: ItemSessionEngineConfig,\n\t\toptions: OpenItemSessionOptions = {},\n\t\tprepared?: unknown,\n\t) {\n\t\tthis.defaultRole = config.role ?? 'candidate';\n\t\tconst playerConfig = { ...config };\n\t\tthis.player = prepared\n\t\t\t? createPlayerFromPreparedInternal(playerConfig, prepared, Boolean(options.restore))\n\t\t\t: new Player(playerConfig);\n\n\t\ttry {\n\t\t\tif (options.responses) {\n\t\t\t\tthis.assertKnownResponseIdentifiers(Object.keys(options.responses));\n\t\t\t}\n\t\t\tif (options.restore) this.player.restoreItemSession(options.restore);\n\t\t\tif (options.activate && this.player.getLifecycleStatus() === 'suspended') {\n\t\t\t\tthis.player.activateAttempt();\n\t\t\t}\n\t\t\tif (options.responses) {\n\t\t\t\tconst lifecycle = this.player.getLifecycleStatus();\n\t\t\t\tif (!isResponseWritableLifecycle(lifecycle)) {\n\t\t\t\t\tthrow new Error(`Cannot override responses while item session is ${lifecycle}`);\n\t\t\t\t}\n\t\t\t\tthis.player.setResponses({ ...options.responses });\n\t\t\t}\n\t\t\tthis.currentView = this.captureView();\n\t\t} catch (error) {\n\t\t\tthis.player.destroy();\n\t\t\tthrow error;\n\t\t}\n\n\t\tthis.runtimeBinding = this.createBinding();\n\t}\n\n\tstate(): ItemSessionView {\n\t\treturn immutableSnapshot(this.currentView);\n\t}\n\n\tdispatch(command: ItemSessionCommand): ItemSessionTransition {\n\t\tthis.assertActive();\n\t\tif (\n\t\t\tcommandRequiresWritableLifecycle(command) &&\n\t\t\t!isResponseWritableLifecycle(this.currentView.lifecycleStatus)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot ${describeCommand(command)} while item session is ${this.currentView.lifecycleStatus}`\n\t\t\t);\n\t\t}\n\t\tconst previous = this.currentView;\n\t\tlet result: ItemSessionActionResult | undefined;\n\n\t\tswitch (command.action) {\n\t\t\tcase 'setResponse':\n\t\t\t\tthis.assertKnownResponseIdentifiers([command.responseIdentifier]);\n\t\t\t\tthis.player.setResponses({ [command.responseIdentifier]: command.value });\n\t\t\t\tbreak;\n\t\t\tcase 'setResponses':\n\t\t\t\tthis.assertKnownResponseIdentifiers(Object.keys(command.responses));\n\t\t\t\tthis.player.setResponses({ ...command.responses });\n\t\t\t\tbreak;\n\t\t\tcase 'updatePnp':\n\t\t\t\tthis.player.updatePnp(command.profile);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tresult = this.player.runItemSessionAction(command);\n\t\t}\n\n\t\tthis.revision += 1;\n\t\tthis.currentView = this.captureView(result?.sessionState);\n\t\tconst transition = freezeTransition({ command, previous, current: this.currentView, result });\n\t\tthis.notify(transition);\n\t\treturn transition;\n\t}\n\n\tpresent(view: ItemPresentationView = {}): ItemPresentation {\n\t\tthis.assertActive();\n\t\treturn createItemPresentation({\n\t\t\t...view,\n\t\t\tdisabled:\n\t\t\t\tview.disabled === true || !isResponseWritableLifecycle(this.currentView.lifecycleStatus),\n\t\t\tsource: {\n\t\t\t\titemBodyHtml: this.player.getItemBodyHtml(),\n\t\t\t\tinteractions: this.player.getInteractionData(),\n\t\t\t\tcorrectResponses: this.player.getCorrectResponses(),\n\t\t\t\tcomponentRegistry: this.player.getComponentRegistry(),\n\t\t\t\tdeliveryContext: this.player.getDeliveryContext(),\n\t\t\t\tpnp: this.player.getPnp(),\n\t\t\t\tsecurity: this.player.getSecurityConfig(),\n\t\t\t\tdirectRubrics: this.player.getRubrics({ scope: 'direct' }),\n\t\t\t},\n\t\t\tresponses: immutableSnapshot(this.currentView.responses),\n\t\t\toutcomeValues: immutableSnapshot(this.currentView.outcomes),\n\t\t\trole: this.defaultRole,\n\t\t});\n\t}\n\n\tsubscribe(listener: ItemSessionListener): () => void {\n\t\tthis.assertActive();\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\tserialize(): SerializedItemSessionState {\n\t\tthis.assertActive();\n\t\treturn immutableSnapshot(this.player.saveItemSession());\n\t}\n\n\t/**\n\t * Browser/runtime capabilities carried by the session across package bundles.\n\t * @internal\n\t */\n\tgetRuntimeBinding(): ItemSessionBinding {\n\t\tthis.assertActive();\n\t\treturn this.runtimeBinding;\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tconst previous = this.currentView;\n\t\tthis.disposed = true;\n\t\tthis.revision += 1;\n\t\tthis.currentView = immutableSnapshot({\n\t\t\t...previous,\n\t\t\trevision: this.revision,\n\t\t\tdisposed: true,\n\t\t});\n\t\tthis.player.destroy();\n\t\tthis.notify(\n\t\t\tfreezeTransition({\n\t\t\t\tcommand: { action: 'dispose' },\n\t\t\t\tprevious,\n\t\t\t\tcurrent: this.currentView,\n\t\t\t})\n\t\t);\n\t\tthis.listeners.clear();\n\t}\n\n\tprivate captureView(serialized = this.player.saveItemSession()): ItemSessionView {\n\t\tconst responses = valuesOf(serialized.responseVariables);\n\t\treturn immutableSnapshot({\n\t\t\trevision: this.revision,\n\t\t\titemIdentifier: serialized.itemIdentifier || this.itemIdentifier || undefined,\n\t\t\trole: this.defaultRole,\n\t\t\tlifecycleStatus: serialized.lifecycleStatus,\n\t\t\tcompletionStatus: serialized.completionStatus,\n\t\t\tnumAttempts: serialized.numAttempts,\n\t\t\tduration: serialized.duration,\n\t\t\tadaptive: this.player.isAdaptive(),\n\t\t\tcompleted: this.player.isCompleted(),\n\t\t\tcanSubmit: this.player.canSubmitResponses(responses),\n\t\t\tdisposed: this.disposed,\n\t\t\tresponses,\n\t\t\toutcomes: valuesOf(serialized.outcomeVariables),\n\t\t\ttemplates: valuesOf(serialized.templateVariables),\n\t\t\tcontext: valuesOf(serialized.contextVariables),\n\t\t});\n\t}\n\n\tprivate createBinding(): ItemSessionBinding {\n\t\treturn Object.freeze({\n\t\t\trole: this.defaultRole,\n\t\t\tapplyPnp: (root: HTMLElement) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\tthis.player.applyPnp(root);\n\t\t\t},\n\t\t\tgetPnp: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getPnp();\n\t\t\t},\n\t\t\tonPnpChange: (listener: () => void) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.onPnpChange(() => listener());\n\t\t\t},\n\t\t\tgetCatalogEntry: (\n\t\t\t\tidref: string,\n\t\t\t\tusage: string,\n\t\t\t\tlang?: string,\n\t\t\t\toptions?: { stimulusIdentifier?: string }\n\t\t\t) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getCatalogEntry(idref, usage, lang, options);\n\t\t\t},\n\t\t\tgetComponentRegistry: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getComponentRegistry();\n\t\t\t},\n\t\t\tgetDeliveryContext: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getDeliveryContext();\n\t\t\t},\n\t\t\tgetSecurityConfig: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getSecurityConfig();\n\t\t\t},\n\t\t\tgetI18nProvider: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getI18nProvider();\n\t\t\t},\n\t\t\tcreatePciHost: (data: ExtractedPci) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\tconst host = this.player.createPciHost(data);\n\t\t\t\thost.onResponseChange(() => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.disposed ||\n\t\t\t\t\t\t!isResponseWritableLifecycle(this.currentView.lifecycleStatus)\n\t\t\t\t\t) return;\n\t\t\t\t\tconst previous = this.currentView;\n\t\t\t\t\tthis.revision += 1;\n\t\t\t\t\tthis.currentView = this.captureView();\n\t\t\t\t\tthis.notify(\n\t\t\t\t\t\tfreezeTransition({\n\t\t\t\t\t\t\tcommand: {\n\t\t\t\t\t\t\t\taction: 'setResponse',\n\t\t\t\t\t\t\t\tresponseIdentifier: data.responseIdentifier,\n\t\t\t\t\t\t\t\tvalue: host.getResponse(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tprevious,\n\t\t\t\t\t\t\tcurrent: this.currentView,\n\t\t\t\t\t\t})\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\treturn host;\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate notify(transition: ItemSessionTransition): void {\n\t\tfor (const listener of [...this.listeners]) {\n\t\t\ttry {\n\t\t\t\tlistener(immutableSnapshot(transition));\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('[QTI ItemSession] subscriber failed:', error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate assertActive(): void {\n\t\tif (this.disposed) throw new Error('ItemSession has been disposed');\n\t}\n\n\tprivate assertKnownResponseIdentifiers(responseIdentifiers: readonly string[]): void {\n\t\tconst knownIdentifiers = new Set(Object.keys(this.player.getResponses()));\n\t\tconst unknown = responseIdentifiers.find((identifier) => !knownIdentifiers.has(identifier));\n\t\tif (unknown) throw new Error(`Unknown response identifier '${unknown}'`);\n\t}\n}\n\nfunction isResponseWritableLifecycle(status: ItemLifecycleStatus): boolean {\n\treturn status === 'initial' || status === 'interacting';\n}\n\nfunction commandRequiresWritableLifecycle(command: ItemSessionCommand): boolean {\n\treturn command.action === 'setResponse' ||\n\t\tcommand.action === 'setResponses' ||\n\t\tcommand.action === 'suspendAttempt' ||\n\t\tcommand.action === 'endAttempt' ||\n\t\tcommand.action === 'submitAttempt';\n}\n\nfunction describeCommand(command: ItemSessionCommand): string {\n\treturn command.action === 'setResponse' || command.action === 'setResponses'\n\t\t? 'update responses'\n\t\t: `run ${command.action}`;\n}\n\nfunction valuesOf(\n\tvariables: Record<string, SerializedItemSessionVariable>\n): Readonly<Record<string, unknown>> {\n\treturn Object.fromEntries(\n\t\tObject.entries(variables).map(([identifier, variable]) => [\n\t\t\tidentifier,\n\t\t\timmutableSnapshot(variable.value),\n\t\t])\n\t);\n}\n\nfunction freezeTransition(transition: ItemSessionTransition): ItemSessionTransition {\n\treturn immutableSnapshot(transition);\n}\n\n/** Clone and freeze plain data without mutating values owned by the caller or a PCI module. */\nfunction immutableSnapshot<T>(value: T): T {\n\tif (Array.isArray(value)) {\n\t\treturn Object.freeze(value.map((entry) => immutableSnapshot(entry))) as T;\n\t}\n\tif (!value || typeof value !== 'object') return value;\n\tif (ArrayBuffer.isView(value)) return structuredClone(value);\n\tif (value instanceof ArrayBuffer) return value.slice(0) as T;\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) return value;\n\tconst snapshot = Object.fromEntries(\n\t\tObject.entries(value as Record<string, unknown>).map(([key, entry]) => [\n\t\t\tkey,\n\t\t\timmutableSnapshot(entry),\n\t\t])\n\t);\n\treturn Object.freeze(snapshot) as T;\n}\n"]}
|
package/dist/core/Player.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type DeclarationMap } from '@pie-qti/qti-processing';
|
|
2
2
|
import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
|
|
3
|
-
import type
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
3
|
+
import { type ExtractionRegistry } from '../extraction/ExtractionRegistry.js';
|
|
4
|
+
import type { CompletionStatus, HtmlContent, ItemSessionActionCommand, ItemSessionActionResult, ItemSessionState, ItemSessionEngineConfig, PlayerSecurityConfig, RubricBlock, RubricBlockOptions, ScoringResult, SerializedItemSessionState } from '../types/index.js';
|
|
5
|
+
import type { BaseInteractionData } from '../interactions/shared/types.js';
|
|
6
6
|
import type { ResponseValidationResult } from '../types/responseValidation.js';
|
|
7
7
|
import type { ComponentRegistry } from './ComponentRegistry.js';
|
|
8
8
|
import type { PnpProfile } from '../pnp/types.js';
|
|
@@ -13,16 +13,18 @@ export declare class Player {
|
|
|
13
13
|
private config;
|
|
14
14
|
private itemXml;
|
|
15
15
|
private itemDocument;
|
|
16
|
-
private assessmentItem;
|
|
17
16
|
private decls;
|
|
17
|
+
private sourceDeclarations;
|
|
18
18
|
private ctx;
|
|
19
19
|
private rng;
|
|
20
20
|
private ops;
|
|
21
21
|
private extractionRegistry;
|
|
22
|
+
private interactionDataCache;
|
|
22
23
|
private componentRegistry;
|
|
23
24
|
private i18nProvider;
|
|
24
25
|
private mapper;
|
|
25
26
|
private responseProcessingProgram;
|
|
27
|
+
private responseProcessing;
|
|
26
28
|
private templateProcessingProgram;
|
|
27
29
|
private outcomeProcessingProgram;
|
|
28
30
|
private _pnp;
|
|
@@ -35,7 +37,7 @@ export declare class Player {
|
|
|
35
37
|
private lifecycleStatus;
|
|
36
38
|
private sessionStartedAt;
|
|
37
39
|
private accumulatedDurationMs;
|
|
38
|
-
constructor(config:
|
|
40
|
+
constructor(config: ItemSessionEngineConfig);
|
|
39
41
|
/**
|
|
40
42
|
* Apply the PNP profile to a player root element.
|
|
41
43
|
* Call this once the root DOM element is available (e.g. after mounting).
|
|
@@ -60,7 +62,7 @@ export declare class Player {
|
|
|
60
62
|
*/
|
|
61
63
|
getCatalogEntry(idref: string, usage: string, lang?: string, options?: {
|
|
62
64
|
stimulusIdentifier?: string;
|
|
63
|
-
}):
|
|
65
|
+
}): HtmlContent | null;
|
|
64
66
|
/** Sanitize externally resolved item-adjacent HTML before it reaches a rendering sink. */
|
|
65
67
|
sanitizeHtmlContent(html: string): string;
|
|
66
68
|
/**
|
|
@@ -161,7 +163,7 @@ export declare class Player {
|
|
|
161
163
|
/**
|
|
162
164
|
* Canonical interaction API (new): extracted, typed interaction data.
|
|
163
165
|
*/
|
|
164
|
-
getInteractionData():
|
|
166
|
+
getInteractionData(): readonly BaseInteractionData[];
|
|
165
167
|
/**
|
|
166
168
|
* Convenience API (used by tests/bench): returns a minimal interaction list with QTI-ish field names.
|
|
167
169
|
*/
|
|
@@ -183,7 +185,6 @@ export declare class Player {
|
|
|
183
185
|
getNumAttempts(): number;
|
|
184
186
|
getCompletionStatus(): CompletionStatus;
|
|
185
187
|
isCompleted(): boolean;
|
|
186
|
-
submitAttempt(countAttempt?: boolean): AdaptiveAttemptResult;
|
|
187
188
|
private runAdaptiveSubmitAttempt;
|
|
188
189
|
getResponses(): Record<string, any>;
|
|
189
190
|
/**
|