@pie-qti/item-player 0.1.20 → 0.1.21

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.
@@ -1,2 +1,2 @@
1
- import { t as e } from "./element-class-CILJ4Ls7.js";
1
+ import { t as e } from "./element-class-iN9MRyjF.js";
2
2
  export { e as PieQtiItemPlayerElement };
package/dist/element.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./element-class-CILJ4Ls7.js";
1
+ import { t as e } from "./element-class-iN9MRyjF.js";
2
2
  //#region src/element.ts
3
3
  var t = "pie-qti-item-player";
4
4
  globalThis.customElements && !customElements.get(t) && customElements.define(t, e);
package/dist/index.d.ts CHANGED
@@ -4,7 +4,6 @@
4
4
  */
5
5
  export { type ComponentConfig, type ComponentPlugin, ComponentRegistry, createComponentRegistry, } from './core/ComponentRegistry.js';
6
6
  export * from './core/constants.js';
7
- export * from './core/declarations.js';
8
7
  export * from './utils/drawingUtils.js';
9
8
  export { createAssessmentItemDefinition, type AssessmentItemDefinition, type AssessmentItemDefinitionConfig, type AssessmentItemDefinitionPlugin, } from './core/AssessmentItemDefinition.js';
10
9
  export { type ItemPresentationView, type ItemSession, type ItemSessionCommand, type ItemSessionEventCommand, type ItemSessionListener, type ItemSessionTransition, type ItemSessionView, type OpenItemSessionOptions, } from './core/ItemSession.js';
package/dist/index.js CHANGED
@@ -5,7 +5,6 @@
5
5
  // Export web component registry for pluggable UI components
6
6
  export { ComponentRegistry, createComponentRegistry, } from './core/ComponentRegistry.js';
7
7
  export * from './core/constants.js';
8
- export * from './core/declarations.js';
9
8
  // Export drawing utilities
10
9
  export * from './utils/drawingUtils.js';
11
10
  export { createAssessmentItemDefinition, } from './core/AssessmentItemDefinition.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,4DAA4D;AAC5D,OAAO,EAGN,iBAA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AC;AAE9B;;;;;;;;GAQG","sourcesContent":["/**\n * @pie-qti/item-player\n * Modern QTI player (2.2/3.0) - Framework-agnostic with web components\n */\n\n\n// Export web component registry for pluggable UI components\nexport {\n\ttype ComponentConfig,\n\ttype ComponentPlugin,\n\tComponentRegistry,\n\tcreateComponentRegistry,\n} from './core/ComponentRegistry.js';\nexport * from './core/constants.js';\nexport * from './core/declarations.js';\n// Export drawing utilities\nexport * from './utils/drawingUtils.js';\nexport {\n\tcreateAssessmentItemDefinition,\n\ttype AssessmentItemDefinition,\n\ttype AssessmentItemDefinitionConfig,\n\ttype AssessmentItemDefinitionPlugin,\n} from './core/AssessmentItemDefinition.js';\nexport {\n\ttype ItemPresentationView,\n\ttype ItemSession,\n\ttype ItemSessionCommand,\n\ttype ItemSessionEventCommand,\n\ttype ItemSessionListener,\n\ttype ItemSessionTransition,\n\ttype ItemSessionView,\n\ttype OpenItemSessionOptions,\n} from './core/ItemSession.js';\nexport type {\n\tFinalItemBodyHtml,\n\tItemInteractionMount,\n\tItemPresentation,\n\tItemPresentationFlowNode,\n} from './presentation/itemPresentationPlan.js';\nexport { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';\n// Render-facing interaction contracts. Standard extractors remain implementation details.\nexport type * from './interactions/shared/types.js';\nexport {\n\tcreateExtendedTextNumericRecord,\n\tcreateExtendedTextResponse,\n\tcreateExtendedTextStringResponse,\n\textendedTextResponseToStrings,\n\ttype ExtendedTextNumericRecord,\n\ttype ExtendedTextRecordField,\n} from './interactions/extended-text/response.js';\nexport type {\n\tElementExtractor,\n\tExtractionContext,\n\tExtractionDispatchResult,\n\tExtractionResult,\n\tExtractionUtils,\n\tInteractionDeliveryField,\n\tInteractionDeliveryPathSegment,\n\tInteractionDeliverySchema,\n\tValidationResult,\n\tVariableDeclaration,\n} from './extraction/index.js';\nexport {\n\tcreateExtractionContext,\n\tcreateExtractionRegistry,\n\tcreateExtractionUtils,\n\tExtractionError,\n\tExtractionRegistry,\n\thtmlField,\n\tisErrorResult,\n\tisSuccessResult,\n\turlField,\n} from './extraction/index.js';\n// NOTE:\n// The player’s primary rendering contract is via web components and the Svelte component entrypoint.\n// If you need non-web-component rendering, build it externally against the public extraction APIs.\n// Export all types including adaptive item types\nexport * from './types/index.js';\n// Export utilities\nexport {\n\tglobalPerformanceMonitor,\n\ttype PerformanceEntry,\n\tPerformanceMonitor,\n\ttype PerformanceMonitorConfig,\n\ttype PerformanceReport,\n} from './utils/PerformanceMonitor.js';\n\nexport { isResponseEmpty } from './utils/responseUtils.js';\n\n// PNP profile (QTI 3.0 §6.2)\nexport type { PnpProfile } from './pnp/types.js';\nexport { applyPnpToRoot } from './pnp/applyPnp.js';\nexport { parsePnpXml } from './pnp/parsePnpXml.js';\n\n// Catalog (QTI 3.0 §6.3)\nexport type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js';\nexport { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';\nexport { getCatalogEntry } from './catalog/catalogLookup.js';\nexport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\n\n// PCI — Portable Custom Interaction (QTI 3.0 §6.1)\nexport type {\n\tExtractedPci,\n\tPciBoundTo,\n\tPciConfiguration,\n\tPciHostController,\n\tPciHostOptions,\n\tPciModule,\n\tPciModulePathKind,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n} from './pci/types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';\nexport { PciHost } from './pci/PciHost.js';\n\n// Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience\n// (heuristics are now in the shared ingestion layer)\nexport {\n\tnormalizeHeuristicsConfig,\n\tapplyFeedbackTextHeuristics,\n\tshouldUseLenientImagePaths,\n\tshouldAutoPopulateFeedbackOutcome,\n\tDEFAULT_HEURISTICS_CONFIG,\n\tSTRICT_QTI_CONFIG,\n\tFEEDBACK_TEXT_TRANSFORMS,\n\ttype QtiHeuristicsConfig,\n\ttype TextTransform,\n} from '@pie-qti/ims-cp-core';\n\n/**\n * NOTE (SSR safety):\n * Web component base classes depend on DOM globals like `HTMLElement` and must not be\n * re-exported from the main entrypoint. Item ownership flows through\n * AssessmentItemDefinition and ItemSession in every deployment.\n *\n * Import web-components from the subpath entry instead:\n * - `@pie-qti/item-player/web-components`\n */\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,4DAA4D;AAC5D,OAAO,EAGN,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,6BAA6B,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,2BAA2B;AAC3B,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACN,8BAA8B,GAI9B,MAAM,oCAAoC,CAAC;AAiB5C,OAAO,EAAE,mBAAmB,EAAyB,MAAM,sBAAsB,CAAC;AAGlF,OAAO,EACN,+BAA+B,EAC/B,0BAA0B,EAC1B,gCAAgC,EAChC,6BAA6B,GAG7B,MAAM,0CAA0C,CAAC;AAalD,OAAO,EACN,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,eAAe,EACf,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAC/B,QAAQ;AACR,qGAAqG;AACrG,mGAAmG;AACnG,iDAAiD;AACjD,cAAc,kBAAkB,CAAC;AACjC,mBAAmB;AACnB,OAAO,EACN,wBAAwB,EAExB,kBAAkB,GAGlB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAI3D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACzG,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAe7D,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,qEAAqE;AACrE,qDAAqD;AACrD,OAAO,EACN,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,iCAAiC,EACjC,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,GAGxB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;GAQG","sourcesContent":["/**\n * @pie-qti/item-player\n * Modern QTI player (2.2/3.0) - Framework-agnostic with web components\n */\n\n\n// Export web component registry for pluggable UI components\nexport {\n\ttype ComponentConfig,\n\ttype ComponentPlugin,\n\tComponentRegistry,\n\tcreateComponentRegistry,\n} from './core/ComponentRegistry.js';\nexport * from './core/constants.js';\n// Export drawing utilities\nexport * from './utils/drawingUtils.js';\nexport {\n\tcreateAssessmentItemDefinition,\n\ttype AssessmentItemDefinition,\n\ttype AssessmentItemDefinitionConfig,\n\ttype AssessmentItemDefinitionPlugin,\n} from './core/AssessmentItemDefinition.js';\nexport {\n\ttype ItemPresentationView,\n\ttype ItemSession,\n\ttype ItemSessionCommand,\n\ttype ItemSessionEventCommand,\n\ttype ItemSessionListener,\n\ttype ItemSessionTransition,\n\ttype ItemSessionView,\n\ttype OpenItemSessionOptions,\n} from './core/ItemSession.js';\nexport type {\n\tFinalItemBodyHtml,\n\tItemInteractionMount,\n\tItemPresentation,\n\tItemPresentationFlowNode,\n} from './presentation/itemPresentationPlan.js';\nexport { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';\n// Render-facing interaction contracts. Standard extractors remain implementation details.\nexport type * from './interactions/shared/types.js';\nexport {\n\tcreateExtendedTextNumericRecord,\n\tcreateExtendedTextResponse,\n\tcreateExtendedTextStringResponse,\n\textendedTextResponseToStrings,\n\ttype ExtendedTextNumericRecord,\n\ttype ExtendedTextRecordField,\n} from './interactions/extended-text/response.js';\nexport type {\n\tElementExtractor,\n\tExtractionContext,\n\tExtractionDispatchResult,\n\tExtractionResult,\n\tExtractionUtils,\n\tInteractionDeliveryField,\n\tInteractionDeliveryPathSegment,\n\tInteractionDeliverySchema,\n\tValidationResult,\n\tVariableDeclaration,\n} from './extraction/index.js';\nexport {\n\tcreateExtractionContext,\n\tcreateExtractionRegistry,\n\tcreateExtractionUtils,\n\tExtractionError,\n\tExtractionRegistry,\n\thtmlField,\n\tisErrorResult,\n\tisSuccessResult,\n\turlField,\n} from './extraction/index.js';\n// NOTE:\n// The player’s primary rendering contract is via web components and the Svelte component entrypoint.\n// If you need non-web-component rendering, build it externally against the public extraction APIs.\n// Export all types including adaptive item types\nexport * from './types/index.js';\n// Export utilities\nexport {\n\tglobalPerformanceMonitor,\n\ttype PerformanceEntry,\n\tPerformanceMonitor,\n\ttype PerformanceMonitorConfig,\n\ttype PerformanceReport,\n} from './utils/PerformanceMonitor.js';\n\nexport { isResponseEmpty } from './utils/responseUtils.js';\n\n// PNP profile (QTI 3.0 §6.2)\nexport type { PnpProfile } from './pnp/types.js';\nexport { applyPnpToRoot } from './pnp/applyPnp.js';\nexport { parsePnpXml } from './pnp/parsePnpXml.js';\n\n// Catalog (QTI 3.0 §6.3)\nexport type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js';\nexport { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';\nexport { getCatalogEntry } from './catalog/catalogLookup.js';\nexport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\n\n// PCI — Portable Custom Interaction (QTI 3.0 §6.1)\nexport type {\n\tExtractedPci,\n\tPciBoundTo,\n\tPciConfiguration,\n\tPciHostController,\n\tPciHostOptions,\n\tPciModule,\n\tPciModulePathKind,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n} from './pci/types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';\nexport { PciHost } from './pci/PciHost.js';\n\n// Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience\n// (heuristics are now in the shared ingestion layer)\nexport {\n\tnormalizeHeuristicsConfig,\n\tapplyFeedbackTextHeuristics,\n\tshouldUseLenientImagePaths,\n\tshouldAutoPopulateFeedbackOutcome,\n\tDEFAULT_HEURISTICS_CONFIG,\n\tSTRICT_QTI_CONFIG,\n\tFEEDBACK_TEXT_TRANSFORMS,\n\ttype QtiHeuristicsConfig,\n\ttype TextTransform,\n} from '@pie-qti/ims-cp-core';\n\n/**\n * NOTE (SSR safety):\n * Web component base classes depend on DOM globals like `HTMLElement` and must not be\n * re-exported from the main entrypoint. Item ownership flows through\n * AssessmentItemDefinition and ItemSession in every deployment.\n *\n * Import web-components from the subpath entry instead:\n * - `@pie-qti/item-player/web-components`\n */\n"]}
@@ -167,7 +167,10 @@ function escapeHtmlAttribute(value) {
167
167
  .replace(/>/g, '>');
168
168
  }
169
169
  function hideBlockInteractionMarkup(html) {
170
- return html.replace(/<(\w+Interaction|qti-[\w-]+-interaction)(\s[^>]*)?>[\s\S]*?<\/\1>/gi, (match, tagName) => {
170
+ // positionObjectStage is hidden as a unit: it owns the background object and wraps its
171
+ // interactions, all of which the component renders. Matching only the interaction inside it
172
+ // would leave the stage's background image visible in the item body as well.
173
+ return html.replace(/<(\w+Interaction|qti-[\w-]+-interaction|positionObjectStage|qti-position-object-stage)(\s[^>]*)?>[\s\S]*?<\/\1>/gi, (match, tagName) => {
171
174
  const lower = tagName.toLowerCase();
172
175
  if (isInlineInteractionTagName(lower))
173
176
  return match;
@@ -1 +1 @@
1
- {"version":3,"file":"itemPresentationPlan.js","sourceRoot":"","sources":["../../src/presentation/itemPresentationPlan.ts"],"names":[],"mappings":"AACA,OAAO,EACN,yBAAyB,GAEzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,aAAa,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;AAED,MAAM,UAAU,cAAc,CAAC,WAAgC;IAC9D,MAAM,cAAc,GAAG,WAAkB,CAAC;IAC1C,MAAM,GAAG,GACR,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAC1E,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC3F,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,MAAM,GAAG,OAAO,cAAc,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACvF,OAAO,GAAG,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,UAAU,IAAI,GAAG,IAAI,MAAM,EAAE,CAAC;AACzE,CAAC","sourcesContent":["import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport {\n\tnormalizeHeuristicsConfig,\n\ttype QtiHeuristicsConfig,\n} from '@pie-qti/ims-cp-core';\nimport { parse } from 'node-html-parser';\nimport type { HTMLElement as ParsedHtmlElement } from 'node-html-parser';\nimport type { ComponentRegistry } from '../core/ComponentRegistry.js';\nimport { sanitizeHtml } from '../core/sanitizer.js';\nimport { htmlToString, toTrustedHtml } from '../core/trustedTypes.js';\nimport type { PnpProfile } from '../pnp/types.js';\nimport { getRoleCapabilities, type RoleCapabilities } from '../core/rolePolicy.js';\nimport type {\n\tHtmlContent,\n\tPlayerSecurityConfig,\n\tQTIRole,\n\tRubricBlock,\n} from '../types/index.js';\nimport { processFeedbackInline } from '../components/utils/feedbackUtils.js';\nimport { buildScopedStylesheetCss } from '../components/utils/stylesheetRender.js';\nimport { buildEffectiveStimulusContent, injectStimulusContent } from '../components/utils/stimulusRender.js';\nimport {\n\tcreateInlineRenderPlan,\n\tisInlineInteractionTagName,\n\tisInlineInteractionType,\n} from '../interactions/inline/render-plan.js';\nimport type {\n\tBaseInteractionData,\n\tInlineChoiceInteractionData,\n\tTextEntryInteractionData,\n} from '../interactions/shared/types.js';\n\nexport type ItemPresentationResponseValue = unknown;\nexport type ItemPresentationResponseMap = Record<string, ItemPresentationResponseValue>;\n\n/**\n * Immutable inputs captured from the live item session for one presentation pass.\n *\n * This deliberately contains data rather than a Player-shaped adapter. Presentation\n * cannot reach back into the session midway through a render, and its only live seam\n * is the real component registry used to resolve plugin renderers.\n */\nexport interface ItemPresentationSource {\n\titemBodyHtml: HtmlContent;\n\tinteractions: readonly BaseInteractionData[];\n\tcorrectResponses: Record<string, unknown>;\n\tcomponentRegistry: ComponentRegistry;\n\tdeliveryContext?: ResolvedItemDeliveryContext;\n\tpnp?: PnpProfile;\n\tsecurity?: PlayerSecurityConfig;\n\t/** Role-filtered, finalized direct rubrics for host placement. */\n\tdirectRubrics?: readonly RubricBlock[];\n}\n\nexport interface CreateItemPresentationOptions {\n\tsource: ItemPresentationSource;\n\tresponses?: ItemPresentationResponseMap;\n\tdisabled?: boolean;\n\trole?: QTIRole;\n\toutcomeValues?: Record<string, unknown>;\n\theuristicsConfig?: QtiHeuristicsConfig;\n\titemBodyScopeSelector?: string;\n\trenderItemBodyRubrics?: boolean;\n\tonComponentError?: (interaction: BaseInteractionData, error: unknown) => void;\n}\n\nexport interface BlockInteractionMount {\n\treadonly placement: 'block';\n\treadonly renderer: 'web-component';\n\treadonly interaction: BaseInteractionData;\n\treadonly tagName: string;\n\treadonly key: string;\n\treadonly response: ItemPresentationResponseValue | null;\n\t/** Lexical companion value used by extendedTextInteraction stringIdentifier. */\n\treadonly stringResponse?: ItemPresentationResponseValue | null;\n\treadonly correctResponse: unknown;\n\treadonly pnp: PnpProfile | undefined;\n\treadonly eliminationTool: boolean;\n\treadonly disabled: boolean;\n\treadonly componentRole: 'scorer' | undefined;\n}\n\nexport type InlineInteractionMount =\n\t| {\n\t\t\treadonly placement: 'inline';\n\t\t\treadonly renderer: 'text-entry';\n\t\t\treadonly interaction: TextEntryInteractionData;\n\t }\n\t| {\n\t\t\treadonly placement: 'inline';\n\t\t\treadonly renderer: 'inline-choice';\n\t\t\treadonly interaction: InlineChoiceInteractionData;\n\t };\n\nexport type ItemInteractionMount = InlineInteractionMount | BlockInteractionMount;\n\ndeclare const finalItemBodyHtmlBrand: unique symbol;\n\n/** HTML that has completed every body transform, sanitation, and Trusted Types finalization. */\nexport type FinalItemBodyHtml = HtmlContent & {\n\treadonly [finalItemBodyHtmlBrand]: true;\n};\n\nexport type ItemPresentationFlowNode =\n\t| { readonly kind: 'html'; readonly html: FinalItemBodyHtml }\n\t| { readonly kind: 'interaction'; readonly mount: ItemInteractionMount };\n\nexport interface ItemPresentation {\n\treadonly capabilities: RoleCapabilities;\n\treadonly disabled: boolean;\n\treadonly correctResponses: Readonly<Record<string, unknown>>;\n\t/** Direct assessmentItem rubrics that remain outside the item-body flow. */\n\treadonly directRubrics: readonly RubricBlock[];\n\t/** Ordered, render-neutral body flow. Block mounts follow the authored body HTML. */\n\treadonly flow: readonly ItemPresentationFlowNode[];\n\t/** Policy-checked CSS is kept out of the HTML/Trusted Types pipeline. */\n\treadonly scopedCss: string;\n}\n\nexport function createItemPresentation({\n\tsource,\n\tresponses = {},\n\tdisabled = false,\n\trole = 'candidate',\n\toutcomeValues = {},\n\theuristicsConfig,\n\titemBodyScopeSelector = '[data-qti-item-body-scope]',\n\trenderItemBodyRubrics = true,\n\tonComponentError,\n}: CreateItemPresentationOptions): ItemPresentation {\n\tconst roleCapabilities = getRoleCapabilities(role);\n\tconst effectiveDisabled = disabled || roleCapabilities.isReadOnly;\n\tconst correctResponses = roleCapabilities.canViewCorrectResponses ? source.correctResponses : {};\n\tconst { html, scopedCss } = buildItemBodyPresentation({\n\t\tsource,\n\t\trole,\n\t\toutcomeValues,\n\t\theuristicsConfig,\n\t\titemBodyScopeSelector,\n\t\trenderItemBodyRubrics,\n\t});\n\tconst inlineFlow = createInlineRenderPlan(html, source.interactions).map(\n\t\t(segment): ItemPresentationFlowNode => {\n\t\t\tif (segment.type === 'html') {\n\t\t\t\t// Inline planning parses and reserializes the composed body, so sanitation\n\t\t\t\t// belongs after that final string transform and immediately before TT.\n\t\t\t\tconst sanitized = sanitizeHtml(segment.content, { security: source.security });\n\t\t\t\treturn {\n\t\t\t\t\tkind: 'html',\n\t\t\t\t\thtml: finalizeItemBodyHtml(sanitized, source.security),\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (segment.type === 'textEntry') {\n\t\t\t\treturn {\n\t\t\t\t\tkind: 'interaction',\n\t\t\t\t\tmount: {\n\t\t\t\t\t\tplacement: 'inline',\n\t\t\t\t\t\trenderer: 'text-entry',\n\t\t\t\t\t\tinteraction: segment.interaction,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: 'interaction',\n\t\t\t\tmount: {\n\t\t\t\t\tplacement: 'inline',\n\t\t\t\t\trenderer: 'inline-choice',\n\t\t\t\t\tinteraction: segment.interaction,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t);\n\tconst blockFlow = createBlockInteractionMounts({\n\t\tinteractions: source.interactions,\n\t\tsource,\n\t\tresponses,\n\t\tcorrectResponses,\n\t\troleCapabilities,\n\t\teffectiveDisabled,\n\t\tonComponentError,\n\t}).map(\n\t\t(mount): ItemPresentationFlowNode => ({\n\t\t\tkind: 'interaction',\n\t\t\tmount,\n\t\t})\n\t);\n\n\treturn freezePresentation({\n\t\tcapabilities: roleCapabilities,\n\t\tdisabled: effectiveDisabled,\n\t\tcorrectResponses,\n\t\tdirectRubrics: source.directRubrics ?? [],\n\t\tflow: [...inlineFlow, ...blockFlow],\n\t\tscopedCss,\n\t});\n}\n\nfunction freezePresentation<T>(value: T): T {\n\tif (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return value;\n\tObject.freeze(value);\n\tfor (const child of Object.values(value as Record<string, unknown>)) {\n\t\tfreezePresentation(child);\n\t}\n\treturn value;\n}\n\nfunction buildItemBodyPresentation({\n\tsource,\n\trole,\n\toutcomeValues,\n\theuristicsConfig,\n\titemBodyScopeSelector,\n\trenderItemBodyRubrics,\n}: {\n\tsource: ItemPresentationSource;\n\trole: QTIRole;\n\toutcomeValues: Record<string, unknown>;\n\theuristicsConfig: QtiHeuristicsConfig | undefined;\n\titemBodyScopeSelector: string;\n\trenderItemBodyRubrics: boolean;\n}): { html: string; scopedCss: string } {\n\tlet html = htmlToString(source.itemBodyHtml);\n\tconst scopedCss = buildScopedStylesheetCss(source.deliveryContext, itemBodyScopeSelector);\n\tconst effectiveStimulusContent = buildEffectiveStimulusContent(\n\t\tsource.deliveryContext,\n\t\t(content) => sanitizeHtml(content, { security: source.security })\n\t);\n\n\thtml = injectStimulusContent(html, effectiveStimulusContent);\n\thtml = renderRubricBlocksForRole(html, role, { renderRubrics: renderItemBodyRubrics });\n\n\tconst heuristics = normalizeHeuristicsConfig(heuristicsConfig);\n\thtml = processFeedbackInline(html, {\n\t\toutcomeValues,\n\t\tapplyHeuristics: heuristics.feedbackTextFormatting,\n\t\twrapWithSpan: false,\n\t});\n\n\treturn { html: hideBlockInteractionMarkup(html), scopedCss };\n}\n\nfunction finalizeItemBodyHtml(\n\thtml: string,\n\tsecurity: PlayerSecurityConfig | undefined\n): FinalItemBodyHtml {\n\treturn toTrustedHtml(html, security?.trustedTypesPolicyName) as FinalItemBodyHtml;\n}\n\nfunction renderRubricBlocksForRole(\n\thtml: string,\n\trole: QTIRole,\n\t{ renderRubrics }: { renderRubrics: boolean }\n): string {\n\tif (!html || !/rubric-?block/i.test(html)) {\n\t\treturn html;\n\t}\n\n\ttry {\n\t\tconst root = parse(html, { lowerCaseTagName: false, comment: false });\n\t\trenderRubricBlockChildren(root as unknown as ParsedHtmlElement, role, { renderRubrics });\n\t\treturn root.toString();\n\t} catch {\n\t\treturn html;\n\t}\n}\n\nfunction renderRubricBlockChildren(\n\telement: ParsedHtmlElement,\n\trole: QTIRole,\n\t{ renderRubrics }: { renderRubrics: boolean }\n): void {\n\tconst children = [...element.childNodes] as unknown as ParsedHtmlElement[];\n\tfor (const child of children) {\n\t\tconst tagName = child.rawTagName?.toLowerCase();\n\t\tif (\n\t\t\ttagName &&\n\t\t\tisRubricBlockTag(tagName) &&\n\t\t\t(!renderRubrics || !rubricBlockVisibleToRole(child, role))\n\t\t) {\n\t\t\tchild.remove();\n\t\t\tcontinue;\n\t\t}\n\t\tif (child.childNodes?.length) {\n\t\t\trenderRubricBlockChildren(child, role, { renderRubrics });\n\t\t}\n\t\tif (tagName && isRubricBlockTag(tagName)) {\n\t\t\tchild.replaceWith(renderRubricBlockWrapper(child));\n\t\t}\n\t}\n}\n\nfunction isRubricBlockTag(tagName: string): boolean {\n\treturn tagName === 'rubricblock' || tagName === 'qti-rubric-block';\n}\n\nfunction rubricBlockVisibleToRole(element: ParsedHtmlElement, role: QTIRole): boolean {\n\tconst view = element.getAttribute('view')?.trim();\n\tif (!view) {\n\t\treturn true;\n\t}\n\treturn splitRubricView(view).includes(role);\n}\n\nfunction renderRubricBlockWrapper(element: ParsedHtmlElement): string {\n\tconst view = element.getAttribute('view')?.trim();\n\tconst use = element.getAttribute('use')?.trim();\n\tconst attrs = [\n\t\t'class=\"qti-rubric-block\"',\n\t\tview ? `data-qti-rubric-view=\"${escapeHtmlAttribute(view)}\"` : '',\n\t\tuse ? `data-qti-rubric-use=\"${escapeHtmlAttribute(use)}\"` : '',\n\t]\n\t\t.filter(Boolean)\n\t\t.join(' ');\n\treturn `<div ${attrs}>${serializeHtmlChildren(element)}</div>`;\n}\n\nfunction splitRubricView(view: string): string[] {\n\treturn view.split(/[\\s,]+/).filter(Boolean);\n}\n\nfunction serializeHtmlChildren(element: ParsedHtmlElement): string {\n\treturn ([...element.childNodes] as unknown as ParsedHtmlElement[])\n\t\t.map((child) => child.toString())\n\t\t.join('');\n}\n\nfunction escapeHtmlAttribute(value: string): string {\n\treturn value\n\t\t.replace(/&/g, '&amp;')\n\t\t.replace(/\"/g, '&quot;')\n\t\t.replace(/</g, '&lt;')\n\t\t.replace(/>/g, '&gt;');\n}\n\nfunction hideBlockInteractionMarkup(html: string): string {\n\treturn html.replace(\n\t\t/<(\\w+Interaction|qti-[\\w-]+-interaction)(\\s[^>]*)?>[\\s\\S]*?<\\/\\1>/gi,\n\t\t(match, tagName) => {\n\t\t\tconst lower = tagName.toLowerCase();\n\t\t\tif (isInlineInteractionTagName(lower)) return match;\n\t\t\treturn `<span class=\"qti-hidden-interaction\">${match}</span>`;\n\t\t}\n\t);\n}\n\nfunction createBlockInteractionMounts({\n\tinteractions,\n\tsource,\n\tresponses,\n\tcorrectResponses,\n\troleCapabilities,\n\teffectiveDisabled,\n\tonComponentError,\n}: {\n\tinteractions: readonly BaseInteractionData[];\n\tsource: ItemPresentationSource;\n\tresponses: ItemPresentationResponseMap;\n\tcorrectResponses: Record<string, unknown>;\n\troleCapabilities: RoleCapabilities;\n\teffectiveDisabled: boolean;\n\tonComponentError?: (interaction: BaseInteractionData, error: unknown) => void;\n}): BlockInteractionMount[] {\n\treturn interactions\n\t\t.filter((interaction) => !isInlineInteractionType(interaction.type))\n\t\t.map((interaction) => {\n\t\t\ttry {\n\t\t\t\tconst stringIdentifier =\n\t\t\t\t\t'stringIdentifier' in interaction && typeof interaction.stringIdentifier === 'string'\n\t\t\t\t\t\t? interaction.stringIdentifier\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst block: BlockInteractionMount = {\n\t\t\t\t\tplacement: 'block',\n\t\t\t\t\trenderer: 'web-component',\n\t\t\t\t\tinteraction,\n\t\t\t\t\ttagName: source.componentRegistry.getTagName(interaction),\n\t\t\t\t\tkey: interactionKey(interaction),\n\t\t\t\t\tresponse: responses[interaction.responseId] ?? null,\n\t\t\t\t\t...(stringIdentifier\n\t\t\t\t\t\t? { stringResponse: responses[stringIdentifier] ?? null }\n\t\t\t\t\t\t: {}),\n\t\t\t\t\tcorrectResponse: roleCapabilities.canViewCorrectResponses\n\t\t\t\t\t\t? (correctResponses[interaction.responseId] ?? null)\n\t\t\t\t\t\t: null,\n\t\t\t\t\tpnp: source.pnp,\n\t\t\t\t\teliminationTool: source.pnp?.cognitive?.eliminationTool === true,\n\t\t\t\t\tdisabled: effectiveDisabled,\n\t\t\t\t\tcomponentRole: roleCapabilities.canViewCorrectResponses ? 'scorer' : undefined,\n\t\t\t\t};\n\t\t\t\treturn block;\n\t\t\t} catch (error) {\n\t\t\t\tonComponentError?.(interaction, error);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t})\n\t\t.filter((item): item is BlockInteractionMount => item !== null);\n}\n\nexport function interactionKey(interaction: BaseInteractionData): string {\n\tconst anyInteraction = interaction as any;\n\tconst ids =\n\t\tArray.isArray(anyInteraction?.choices) && anyInteraction.choices.length > 0\n\t\t\t? anyInteraction.choices.map((choice: any) => choice?.identifier).filter(Boolean).join(',')\n\t\t\t: '';\n\tconst prompt = typeof anyInteraction?.prompt === 'string' ? anyInteraction.prompt : '';\n\treturn `${interaction.type}|${interaction.responseId}|${ids}|${prompt}`;\n}\n"]}
1
+ {"version":3,"file":"itemPresentationPlan.js","sourceRoot":"","sources":["../../src/presentation/itemPresentationPlan.ts"],"names":[],"mappings":"AACA,OAAO,EACN,yBAAyB,GAEzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAAE,mBAAmB,EAAyB,MAAM,uBAAuB,CAAC;AAOnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAA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c,EAAE,OAAO,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAC1E,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC3F,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,MAAM,GAAG,OAAO,cAAc,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACvF,OAAO,GAAG,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,UAAU,IAAI,GAAG,IAAI,MAAM,EAAE,CAAC;AACzE,CAAC","sourcesContent":["import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport {\n\tnormalizeHeuristicsConfig,\n\ttype QtiHeuristicsConfig,\n} from '@pie-qti/ims-cp-core';\nimport { parse } from 'node-html-parser';\nimport type { HTMLElement as ParsedHtmlElement } from 'node-html-parser';\nimport type { ComponentRegistry } from '../core/ComponentRegistry.js';\nimport { sanitizeHtml } from '../core/sanitizer.js';\nimport { htmlToString, toTrustedHtml } from '../core/trustedTypes.js';\nimport type { PnpProfile } from '../pnp/types.js';\nimport { getRoleCapabilities, type RoleCapabilities } from '../core/rolePolicy.js';\nimport type {\n\tHtmlContent,\n\tPlayerSecurityConfig,\n\tQTIRole,\n\tRubricBlock,\n} from '../types/index.js';\nimport { processFeedbackInline } from '../components/utils/feedbackUtils.js';\nimport { buildScopedStylesheetCss } from '../components/utils/stylesheetRender.js';\nimport { buildEffectiveStimulusContent, injectStimulusContent } from '../components/utils/stimulusRender.js';\nimport {\n\tcreateInlineRenderPlan,\n\tisInlineInteractionTagName,\n\tisInlineInteractionType,\n} from '../interactions/inline/render-plan.js';\nimport type {\n\tBaseInteractionData,\n\tInlineChoiceInteractionData,\n\tTextEntryInteractionData,\n} from '../interactions/shared/types.js';\n\nexport type ItemPresentationResponseValue = unknown;\nexport type ItemPresentationResponseMap = Record<string, ItemPresentationResponseValue>;\n\n/**\n * Immutable inputs captured from the live item session for one presentation pass.\n *\n * This deliberately contains data rather than a Player-shaped adapter. Presentation\n * cannot reach back into the session midway through a render, and its only live seam\n * is the real component registry used to resolve plugin renderers.\n */\nexport interface ItemPresentationSource {\n\titemBodyHtml: HtmlContent;\n\tinteractions: readonly BaseInteractionData[];\n\tcorrectResponses: Record<string, unknown>;\n\tcomponentRegistry: ComponentRegistry;\n\tdeliveryContext?: ResolvedItemDeliveryContext;\n\tpnp?: PnpProfile;\n\tsecurity?: PlayerSecurityConfig;\n\t/** Role-filtered, finalized direct rubrics for host placement. */\n\tdirectRubrics?: readonly RubricBlock[];\n}\n\nexport interface CreateItemPresentationOptions {\n\tsource: ItemPresentationSource;\n\tresponses?: ItemPresentationResponseMap;\n\tdisabled?: boolean;\n\trole?: QTIRole;\n\toutcomeValues?: Record<string, unknown>;\n\theuristicsConfig?: QtiHeuristicsConfig;\n\titemBodyScopeSelector?: string;\n\trenderItemBodyRubrics?: boolean;\n\tonComponentError?: (interaction: BaseInteractionData, error: unknown) => void;\n}\n\nexport interface BlockInteractionMount {\n\treadonly placement: 'block';\n\treadonly renderer: 'web-component';\n\treadonly interaction: BaseInteractionData;\n\treadonly tagName: string;\n\treadonly key: string;\n\treadonly response: ItemPresentationResponseValue | null;\n\t/** Lexical companion value used by extendedTextInteraction stringIdentifier. */\n\treadonly stringResponse?: ItemPresentationResponseValue | null;\n\treadonly correctResponse: unknown;\n\treadonly pnp: PnpProfile | undefined;\n\treadonly eliminationTool: boolean;\n\treadonly disabled: boolean;\n\treadonly componentRole: 'scorer' | undefined;\n}\n\nexport type InlineInteractionMount =\n\t| {\n\t\t\treadonly placement: 'inline';\n\t\t\treadonly renderer: 'text-entry';\n\t\t\treadonly interaction: TextEntryInteractionData;\n\t }\n\t| {\n\t\t\treadonly placement: 'inline';\n\t\t\treadonly renderer: 'inline-choice';\n\t\t\treadonly interaction: InlineChoiceInteractionData;\n\t };\n\nexport type ItemInteractionMount = InlineInteractionMount | BlockInteractionMount;\n\ndeclare const finalItemBodyHtmlBrand: unique symbol;\n\n/** HTML that has completed every body transform, sanitation, and Trusted Types finalization. */\nexport type FinalItemBodyHtml = HtmlContent & {\n\treadonly [finalItemBodyHtmlBrand]: true;\n};\n\nexport type ItemPresentationFlowNode =\n\t| { readonly kind: 'html'; readonly html: FinalItemBodyHtml }\n\t| { readonly kind: 'interaction'; readonly mount: ItemInteractionMount };\n\nexport interface ItemPresentation {\n\treadonly capabilities: RoleCapabilities;\n\treadonly disabled: boolean;\n\treadonly correctResponses: Readonly<Record<string, unknown>>;\n\t/** Direct assessmentItem rubrics that remain outside the item-body flow. */\n\treadonly directRubrics: readonly RubricBlock[];\n\t/** Ordered, render-neutral body flow. Block mounts follow the authored body HTML. */\n\treadonly flow: readonly ItemPresentationFlowNode[];\n\t/** Policy-checked CSS is kept out of the HTML/Trusted Types pipeline. */\n\treadonly scopedCss: string;\n}\n\nexport function createItemPresentation({\n\tsource,\n\tresponses = {},\n\tdisabled = false,\n\trole = 'candidate',\n\toutcomeValues = {},\n\theuristicsConfig,\n\titemBodyScopeSelector = '[data-qti-item-body-scope]',\n\trenderItemBodyRubrics = true,\n\tonComponentError,\n}: CreateItemPresentationOptions): ItemPresentation {\n\tconst roleCapabilities = getRoleCapabilities(role);\n\tconst effectiveDisabled = disabled || roleCapabilities.isReadOnly;\n\tconst correctResponses = roleCapabilities.canViewCorrectResponses ? source.correctResponses : {};\n\tconst { html, scopedCss } = buildItemBodyPresentation({\n\t\tsource,\n\t\trole,\n\t\toutcomeValues,\n\t\theuristicsConfig,\n\t\titemBodyScopeSelector,\n\t\trenderItemBodyRubrics,\n\t});\n\tconst inlineFlow = createInlineRenderPlan(html, source.interactions).map(\n\t\t(segment): ItemPresentationFlowNode => {\n\t\t\tif (segment.type === 'html') {\n\t\t\t\t// Inline planning parses and reserializes the composed body, so sanitation\n\t\t\t\t// belongs after that final string transform and immediately before TT.\n\t\t\t\tconst sanitized = sanitizeHtml(segment.content, { security: source.security });\n\t\t\t\treturn {\n\t\t\t\t\tkind: 'html',\n\t\t\t\t\thtml: finalizeItemBodyHtml(sanitized, source.security),\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (segment.type === 'textEntry') {\n\t\t\t\treturn {\n\t\t\t\t\tkind: 'interaction',\n\t\t\t\t\tmount: {\n\t\t\t\t\t\tplacement: 'inline',\n\t\t\t\t\t\trenderer: 'text-entry',\n\t\t\t\t\t\tinteraction: segment.interaction,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: 'interaction',\n\t\t\t\tmount: {\n\t\t\t\t\tplacement: 'inline',\n\t\t\t\t\trenderer: 'inline-choice',\n\t\t\t\t\tinteraction: segment.interaction,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t);\n\tconst blockFlow = createBlockInteractionMounts({\n\t\tinteractions: source.interactions,\n\t\tsource,\n\t\tresponses,\n\t\tcorrectResponses,\n\t\troleCapabilities,\n\t\teffectiveDisabled,\n\t\tonComponentError,\n\t}).map(\n\t\t(mount): ItemPresentationFlowNode => ({\n\t\t\tkind: 'interaction',\n\t\t\tmount,\n\t\t})\n\t);\n\n\treturn freezePresentation({\n\t\tcapabilities: roleCapabilities,\n\t\tdisabled: effectiveDisabled,\n\t\tcorrectResponses,\n\t\tdirectRubrics: source.directRubrics ?? [],\n\t\tflow: [...inlineFlow, ...blockFlow],\n\t\tscopedCss,\n\t});\n}\n\nfunction freezePresentation<T>(value: T): T {\n\tif (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return value;\n\tObject.freeze(value);\n\tfor (const child of Object.values(value as Record<string, unknown>)) {\n\t\tfreezePresentation(child);\n\t}\n\treturn value;\n}\n\nfunction buildItemBodyPresentation({\n\tsource,\n\trole,\n\toutcomeValues,\n\theuristicsConfig,\n\titemBodyScopeSelector,\n\trenderItemBodyRubrics,\n}: {\n\tsource: ItemPresentationSource;\n\trole: QTIRole;\n\toutcomeValues: Record<string, unknown>;\n\theuristicsConfig: QtiHeuristicsConfig | undefined;\n\titemBodyScopeSelector: string;\n\trenderItemBodyRubrics: boolean;\n}): { html: string; scopedCss: string } {\n\tlet html = htmlToString(source.itemBodyHtml);\n\tconst scopedCss = buildScopedStylesheetCss(source.deliveryContext, itemBodyScopeSelector);\n\tconst effectiveStimulusContent = buildEffectiveStimulusContent(\n\t\tsource.deliveryContext,\n\t\t(content) => sanitizeHtml(content, { security: source.security })\n\t);\n\n\thtml = injectStimulusContent(html, effectiveStimulusContent);\n\thtml = renderRubricBlocksForRole(html, role, { renderRubrics: renderItemBodyRubrics });\n\n\tconst heuristics = normalizeHeuristicsConfig(heuristicsConfig);\n\thtml = processFeedbackInline(html, {\n\t\toutcomeValues,\n\t\tapplyHeuristics: heuristics.feedbackTextFormatting,\n\t\twrapWithSpan: false,\n\t});\n\n\treturn { html: hideBlockInteractionMarkup(html), scopedCss };\n}\n\nfunction finalizeItemBodyHtml(\n\thtml: string,\n\tsecurity: PlayerSecurityConfig | undefined\n): FinalItemBodyHtml {\n\treturn toTrustedHtml(html, security?.trustedTypesPolicyName) as FinalItemBodyHtml;\n}\n\nfunction renderRubricBlocksForRole(\n\thtml: string,\n\trole: QTIRole,\n\t{ renderRubrics }: { renderRubrics: boolean }\n): string {\n\tif (!html || !/rubric-?block/i.test(html)) {\n\t\treturn html;\n\t}\n\n\ttry {\n\t\tconst root = parse(html, { lowerCaseTagName: false, comment: false });\n\t\trenderRubricBlockChildren(root as unknown as ParsedHtmlElement, role, { renderRubrics });\n\t\treturn root.toString();\n\t} catch {\n\t\treturn html;\n\t}\n}\n\nfunction renderRubricBlockChildren(\n\telement: ParsedHtmlElement,\n\trole: QTIRole,\n\t{ renderRubrics }: { renderRubrics: boolean }\n): void {\n\tconst children = [...element.childNodes] as unknown as ParsedHtmlElement[];\n\tfor (const child of children) {\n\t\tconst tagName = child.rawTagName?.toLowerCase();\n\t\tif (\n\t\t\ttagName &&\n\t\t\tisRubricBlockTag(tagName) &&\n\t\t\t(!renderRubrics || !rubricBlockVisibleToRole(child, role))\n\t\t) {\n\t\t\tchild.remove();\n\t\t\tcontinue;\n\t\t}\n\t\tif (child.childNodes?.length) {\n\t\t\trenderRubricBlockChildren(child, role, { renderRubrics });\n\t\t}\n\t\tif (tagName && isRubricBlockTag(tagName)) {\n\t\t\tchild.replaceWith(renderRubricBlockWrapper(child));\n\t\t}\n\t}\n}\n\nfunction isRubricBlockTag(tagName: string): boolean {\n\treturn tagName === 'rubricblock' || tagName === 'qti-rubric-block';\n}\n\nfunction rubricBlockVisibleToRole(element: ParsedHtmlElement, role: QTIRole): boolean {\n\tconst view = element.getAttribute('view')?.trim();\n\tif (!view) {\n\t\treturn true;\n\t}\n\treturn splitRubricView(view).includes(role);\n}\n\nfunction renderRubricBlockWrapper(element: ParsedHtmlElement): string {\n\tconst view = element.getAttribute('view')?.trim();\n\tconst use = element.getAttribute('use')?.trim();\n\tconst attrs = [\n\t\t'class=\"qti-rubric-block\"',\n\t\tview ? `data-qti-rubric-view=\"${escapeHtmlAttribute(view)}\"` : '',\n\t\tuse ? `data-qti-rubric-use=\"${escapeHtmlAttribute(use)}\"` : '',\n\t]\n\t\t.filter(Boolean)\n\t\t.join(' ');\n\treturn `<div ${attrs}>${serializeHtmlChildren(element)}</div>`;\n}\n\nfunction splitRubricView(view: string): string[] {\n\treturn view.split(/[\\s,]+/).filter(Boolean);\n}\n\nfunction serializeHtmlChildren(element: ParsedHtmlElement): string {\n\treturn ([...element.childNodes] as unknown as ParsedHtmlElement[])\n\t\t.map((child) => child.toString())\n\t\t.join('');\n}\n\nfunction escapeHtmlAttribute(value: string): string {\n\treturn value\n\t\t.replace(/&/g, '&amp;')\n\t\t.replace(/\"/g, '&quot;')\n\t\t.replace(/</g, '&lt;')\n\t\t.replace(/>/g, '&gt;');\n}\n\nfunction hideBlockInteractionMarkup(html: string): string {\n\t// positionObjectStage is hidden as a unit: it owns the background object and wraps its\n\t// interactions, all of which the component renders. Matching only the interaction inside it\n\t// would leave the stage's background image visible in the item body as well.\n\treturn html.replace(\n\t\t/<(\\w+Interaction|qti-[\\w-]+-interaction|positionObjectStage|qti-position-object-stage)(\\s[^>]*)?>[\\s\\S]*?<\\/\\1>/gi,\n\t\t(match, tagName) => {\n\t\t\tconst lower = tagName.toLowerCase();\n\t\t\tif (isInlineInteractionTagName(lower)) return match;\n\t\t\treturn `<span class=\"qti-hidden-interaction\">${match}</span>`;\n\t\t}\n\t);\n}\n\nfunction createBlockInteractionMounts({\n\tinteractions,\n\tsource,\n\tresponses,\n\tcorrectResponses,\n\troleCapabilities,\n\teffectiveDisabled,\n\tonComponentError,\n}: {\n\tinteractions: readonly BaseInteractionData[];\n\tsource: ItemPresentationSource;\n\tresponses: ItemPresentationResponseMap;\n\tcorrectResponses: Record<string, unknown>;\n\troleCapabilities: RoleCapabilities;\n\teffectiveDisabled: boolean;\n\tonComponentError?: (interaction: BaseInteractionData, error: unknown) => void;\n}): BlockInteractionMount[] {\n\treturn interactions\n\t\t.filter((interaction) => !isInlineInteractionType(interaction.type))\n\t\t.map((interaction) => {\n\t\t\ttry {\n\t\t\t\tconst stringIdentifier =\n\t\t\t\t\t'stringIdentifier' in interaction && typeof interaction.stringIdentifier === 'string'\n\t\t\t\t\t\t? interaction.stringIdentifier\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst block: BlockInteractionMount = {\n\t\t\t\t\tplacement: 'block',\n\t\t\t\t\trenderer: 'web-component',\n\t\t\t\t\tinteraction,\n\t\t\t\t\ttagName: source.componentRegistry.getTagName(interaction),\n\t\t\t\t\tkey: interactionKey(interaction),\n\t\t\t\t\tresponse: responses[interaction.responseId] ?? null,\n\t\t\t\t\t...(stringIdentifier\n\t\t\t\t\t\t? { stringResponse: responses[stringIdentifier] ?? null }\n\t\t\t\t\t\t: {}),\n\t\t\t\t\tcorrectResponse: roleCapabilities.canViewCorrectResponses\n\t\t\t\t\t\t? (correctResponses[interaction.responseId] ?? null)\n\t\t\t\t\t\t: null,\n\t\t\t\t\tpnp: source.pnp,\n\t\t\t\t\teliminationTool: source.pnp?.cognitive?.eliminationTool === true,\n\t\t\t\t\tdisabled: effectiveDisabled,\n\t\t\t\t\tcomponentRole: roleCapabilities.canViewCorrectResponses ? 'scorer' : undefined,\n\t\t\t\t};\n\t\t\t\treturn block;\n\t\t\t} catch (error) {\n\t\t\t\tonComponentError?.(interaction, error);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t})\n\t\t.filter((item): item is BlockInteractionMount => item !== null);\n}\n\nexport function interactionKey(interaction: BaseInteractionData): string {\n\tconst anyInteraction = interaction as any;\n\tconst ids =\n\t\tArray.isArray(anyInteraction?.choices) && anyInteraction.choices.length > 0\n\t\t\t? anyInteraction.choices.map((choice: any) => choice?.identifier).filter(Boolean).join(',')\n\t\t\t: '';\n\tconst prompt = typeof anyInteraction?.prompt === 'string' ? anyInteraction.prompt : '';\n\treturn `${interaction.type}|${interaction.responseId}|${ids}|${prompt}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-qti/item-player",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "Modern QTI player supporting QTI 2.2 and 3.0 - Client-side with optional backend hooks",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,10 +27,10 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
- "@pie-qti/i18n": "0.1.20",
31
- "@pie-qti/ims-cp-core": "0.1.20",
32
- "@pie-qti/qti-common": "0.1.20",
33
- "@pie-qti/qti-processing": "0.1.20",
30
+ "@pie-qti/i18n": "0.1.21",
31
+ "@pie-qti/ims-cp-core": "0.1.21",
32
+ "@pie-qti/qti-common": "0.1.21",
33
+ "@pie-qti/qti-processing": "0.1.21",
34
34
  "mathlive": "^0.110.0",
35
35
  "node-html-parser": "^9.0.1"
36
36
  },
@@ -1,44 +0,0 @@
1
- /**
2
- * QTI variable declarations management
3
- * Ported from an earlier implementation
4
- */
5
- import type { AreaMapping, Mapping, VariableDeclaration } from '../types/index.js';
6
- /**
7
- * Declarations storage for an item or section
8
- */
9
- export interface DeclarationsContext {
10
- declarations: Record<string, VariableDeclaration>;
11
- }
12
- /**
13
- * Initialize declarations for an element
14
- */
15
- export declare function initializeDeclarations(declarations: Record<string, VariableDeclaration>): void;
16
- /**
17
- * Add a response or outcome declaration
18
- */
19
- export declare function addDeclaration(declarations: Record<string, VariableDeclaration>, identifier: string, baseType: VariableDeclaration['baseType'], cardinality: VariableDeclaration['cardinality'], defaultValue?: any): void;
20
- /**
21
- * Add a mapping to a response declaration
22
- */
23
- export declare function addMapping(declarations: Record<string, VariableDeclaration>, identifier: string, mapping: Mapping): void;
24
- /**
25
- * Add an area mapping to a response declaration
26
- */
27
- export declare function addAreaMapping(declarations: Record<string, VariableDeclaration>, identifier: string, areaMapping: AreaMapping): void;
28
- /**
29
- * Get a variable value from declarations
30
- * @returns {any} QTI variables can hold any type
31
- */
32
- export declare function getVariableValue(declarations: Record<string, VariableDeclaration>, identifier: string): any;
33
- /**
34
- * Set a variable value in declarations
35
- */
36
- export declare function setVariableValue(declarations: Record<string, VariableDeclaration>, identifier: string, value: any): void;
37
- /**
38
- * Reset declarations to default values
39
- */
40
- export declare function resetDeclarations(declarations: Record<string, VariableDeclaration>): void;
41
- /**
42
- * Clone declarations (useful for creating new sessions)
43
- */
44
- export declare function cloneDeclarations(source: Record<string, VariableDeclaration>): Record<string, VariableDeclaration>;
@@ -1,141 +0,0 @@
1
- /**
2
- * QTI variable declarations management
3
- * Ported from an earlier implementation
4
- */
5
- import { BUILTIN_DECLARATIONS } from './constants.js';
6
- /**
7
- * Initialize declarations for an element
8
- */
9
- export function initializeDeclarations(declarations) {
10
- // Clone built-in declarations
11
- Object.keys(BUILTIN_DECLARATIONS).forEach((id) => {
12
- const builtinDecl = BUILTIN_DECLARATIONS[id];
13
- declarations[id] = { ...builtinDecl };
14
- });
15
- }
16
- /**
17
- * Add a response or outcome declaration
18
- */
19
- export function addDeclaration(declarations, identifier, baseType, cardinality, defaultValue) {
20
- const value = cardinality === 'multiple' || cardinality === 'ordered' ? [] : null;
21
- declarations[identifier] = {
22
- identifier,
23
- baseType,
24
- cardinality,
25
- value: defaultValue ?? value,
26
- defaultValue,
27
- };
28
- }
29
- /**
30
- * Add a mapping to a response declaration
31
- */
32
- export function addMapping(declarations, identifier, mapping) {
33
- const decl = declarations[identifier];
34
- if (decl) {
35
- decl.mapping = mapping;
36
- }
37
- }
38
- /**
39
- * Add an area mapping to a response declaration
40
- */
41
- export function addAreaMapping(declarations, identifier, areaMapping) {
42
- const decl = declarations[identifier];
43
- if (decl) {
44
- decl.areaMapping = areaMapping;
45
- }
46
- }
47
- /**
48
- * Get a variable value from declarations
49
- * @returns {any} QTI variables can hold any type
50
- */
51
- export function getVariableValue(declarations, identifier) {
52
- const decl = declarations[identifier];
53
- return decl ? decl.value : null;
54
- }
55
- /**
56
- * Set a variable value in declarations
57
- */
58
- export function setVariableValue(declarations, identifier, value) {
59
- const decl = declarations[identifier];
60
- if (decl) {
61
- const coerceScalar = (v) => {
62
- if (v === null || v === undefined)
63
- return v;
64
- const baseType = decl.baseType;
65
- if (baseType === 'integer' || baseType === 'float') {
66
- const n = Number(v);
67
- return Number.isNaN(n) ? v : n;
68
- }
69
- if (baseType === 'boolean') {
70
- if (typeof v === 'boolean')
71
- return v;
72
- if (typeof v === 'number')
73
- return v !== 0;
74
- if (typeof v === 'string')
75
- return v.trim().toLowerCase() === 'true';
76
- return Boolean(v);
77
- }
78
- if (baseType === 'string' ||
79
- baseType === 'identifier' ||
80
- baseType === 'uri' ||
81
- baseType === 'pair' ||
82
- baseType === 'directedPair' ||
83
- baseType === 'point') {
84
- return typeof v === 'string' ? v.trim() : String(v);
85
- }
86
- return v;
87
- };
88
- if (decl.cardinality === 'record') {
89
- decl.value = value && typeof value === 'object' && !Array.isArray(value) ? value : null;
90
- }
91
- else if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {
92
- if (Array.isArray(value)) {
93
- decl.value = value.map(coerceScalar);
94
- }
95
- else if (value === null || value === undefined) {
96
- decl.value = [];
97
- }
98
- else {
99
- decl.value = [coerceScalar(value)];
100
- }
101
- }
102
- else {
103
- decl.value = coerceScalar(value);
104
- }
105
- }
106
- }
107
- /**
108
- * Reset declarations to default values
109
- */
110
- export function resetDeclarations(declarations) {
111
- Object.values(declarations).forEach((decl) => {
112
- if (decl.defaultValue !== undefined) {
113
- decl.value = decl.defaultValue;
114
- }
115
- else if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {
116
- decl.value = [];
117
- }
118
- else {
119
- decl.value = null;
120
- }
121
- });
122
- }
123
- /**
124
- * Clone declarations (useful for creating new sessions)
125
- */
126
- export function cloneDeclarations(source) {
127
- const result = {};
128
- Object.keys(source).forEach((id) => {
129
- const decl = source[id];
130
- result[id] = {
131
- ...decl,
132
- value: (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') && Array.isArray(decl.value)
133
- ? [...decl.value]
134
- : decl.cardinality === 'record' && decl.value && typeof decl.value === 'object'
135
- ? { ...decl.value }
136
- : decl.value,
137
- };
138
- });
139
- return result;
140
- }
141
- //# sourceMappingURL=declarations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"declarations.js","sourceRoot":"","sources":["../../src/core/declarations.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAStD;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,YAAiD;IACvF,8BAA8B;IAC9B,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QAChD,MAAM,W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AI,CAAC,KAAK,GAAG,IAAI,CAAC;QACnB,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAA2C;IAE3C,MAAM,MAAM,GAAwC,EAAE,CAAC;IAEvD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QAClC,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,MAAM,CAAC,EAAE,CAAC,GAAG;YACZ,GAAG,IAAI;YACP,KAAK,EACJ,CAAC,IAAI,CAAC,WAAW,KAAK,UAAU,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC/F,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;gBACjB,CAAC,CAAC,IAAI,CAAC,WAAW,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;oBAC9E,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE;oBACnB,CAAC,CAAC,IAAI,CAAC,KAAK;SACf,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * QTI variable declarations management\n * Ported from an earlier implementation\n */\n\nimport type { AreaMapping, Mapping, VariableDeclaration } from '../types/index.js';\nimport { BUILTIN_DECLARATIONS } from './constants.js';\n\n/**\n * Declarations storage for an item or section\n */\nexport interface DeclarationsContext {\n\tdeclarations: Record<string, VariableDeclaration>;\n}\n\n/**\n * Initialize declarations for an element\n */\nexport function initializeDeclarations(declarations: Record<string, VariableDeclaration>): void {\n\t// Clone built-in declarations\n\tObject.keys(BUILTIN_DECLARATIONS).forEach((id) => {\n\t\tconst builtinDecl = BUILTIN_DECLARATIONS[id];\n\t\tdeclarations[id] = { ...builtinDecl };\n\t});\n}\n\n/**\n * Add a response or outcome declaration\n */\nexport function addDeclaration(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string,\n\tbaseType: VariableDeclaration['baseType'],\n\tcardinality: VariableDeclaration['cardinality'],\n\tdefaultValue?: any\n): void {\n\tconst value = cardinality === 'multiple' || cardinality === 'ordered' ? [] : null;\n\n\tdeclarations[identifier] = {\n\t\tidentifier,\n\t\tbaseType,\n\t\tcardinality,\n\t\tvalue: defaultValue ?? value,\n\t\tdefaultValue,\n\t};\n}\n\n/**\n * Add a mapping to a response declaration\n */\nexport function addMapping(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string,\n\tmapping: Mapping\n): void {\n\tconst decl = declarations[identifier];\n\tif (decl) {\n\t\tdecl.mapping = mapping;\n\t}\n}\n\n/**\n * Add an area mapping to a response declaration\n */\nexport function addAreaMapping(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string,\n\tareaMapping: AreaMapping\n): void {\n\tconst decl = declarations[identifier];\n\tif (decl) {\n\t\tdecl.areaMapping = areaMapping;\n\t}\n}\n\n/**\n * Get a variable value from declarations\n * @returns {any} QTI variables can hold any type\n */\nexport function getVariableValue(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string\n): any {\n\tconst decl = declarations[identifier];\n\treturn decl ? decl.value : null;\n}\n\n/**\n * Set a variable value in declarations\n */\nexport function setVariableValue(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string,\n\tvalue: any\n): void {\n\tconst decl = declarations[identifier];\n\tif (decl) {\n\t\tconst coerceScalar = (v: any) => {\n\t\t\tif (v === null || v === undefined) return v;\n\t\t\tconst baseType = decl.baseType;\n\t\t\tif (baseType === 'integer' || baseType === 'float') {\n\t\t\t\tconst n = Number(v);\n\t\t\t\treturn Number.isNaN(n) ? v : n;\n\t\t\t}\n\t\t\tif (baseType === 'boolean') {\n\t\t\t\tif (typeof v === 'boolean') return v;\n\t\t\t\tif (typeof v === 'number') return v !== 0;\n\t\t\t\tif (typeof v === 'string') return v.trim().toLowerCase() === 'true';\n\t\t\t\treturn Boolean(v);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tbaseType === 'string' ||\n\t\t\t\tbaseType === 'identifier' ||\n\t\t\t\tbaseType === 'uri' ||\n\t\t\t\tbaseType === 'pair' ||\n\t\t\t\tbaseType === 'directedPair' ||\n\t\t\t\tbaseType === 'point'\n\t\t\t) {\n\t\t\t\treturn typeof v === 'string' ? v.trim() : String(v);\n\t\t\t}\n\t\t\treturn v;\n\t\t};\n\n\t\tif (decl.cardinality === 'record') {\n\t\t\tdecl.value = value && typeof value === 'object' && !Array.isArray(value) ? value : null;\n\t\t} else if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tdecl.value = value.map(coerceScalar);\n\t\t\t} else if (value === null || value === undefined) {\n\t\t\t\tdecl.value = [];\n\t\t\t} else {\n\t\t\t\tdecl.value = [coerceScalar(value)];\n\t\t\t}\n\t\t} else {\n\t\t\tdecl.value = coerceScalar(value);\n\t\t}\n\t}\n}\n\n/**\n * Reset declarations to default values\n */\nexport function resetDeclarations(declarations: Record<string, VariableDeclaration>): void {\n\tObject.values(declarations).forEach((decl) => {\n\t\tif (decl.defaultValue !== undefined) {\n\t\t\tdecl.value = decl.defaultValue;\n\t\t} else if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {\n\t\t\tdecl.value = [];\n\t\t} else {\n\t\t\tdecl.value = null;\n\t\t}\n\t});\n}\n\n/**\n * Clone declarations (useful for creating new sessions)\n */\nexport function cloneDeclarations(\n\tsource: Record<string, VariableDeclaration>\n): Record<string, VariableDeclaration> {\n\tconst result: Record<string, VariableDeclaration> = {};\n\n\tObject.keys(source).forEach((id) => {\n\t\tconst decl = source[id];\n\t\tresult[id] = {\n\t\t\t...decl,\n\t\t\tvalue:\n\t\t\t\t(decl.cardinality === 'multiple' || decl.cardinality === 'ordered') && Array.isArray(decl.value)\n\t\t\t\t\t? [...decl.value]\n\t\t\t\t\t: decl.cardinality === 'record' && decl.value && typeof decl.value === 'object'\n\t\t\t\t\t\t? { ...decl.value }\n\t\t\t\t\t\t: decl.value,\n\t\t};\n\t});\n\n\treturn result;\n}\n"]}