@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.
Files changed (259) hide show
  1. package/README.md +137 -427
  2. package/dist/catalog/applyGlossaryTriggers.d.ts +2 -1
  3. package/dist/catalog/applyGlossaryTriggers.js +4 -2
  4. package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
  5. package/dist/components/utils/stimulusRender.d.ts +1 -2
  6. package/dist/components/utils/stimulusRender.js +2 -5
  7. package/dist/components/utils/stimulusRender.js.map +1 -1
  8. package/dist/core/AssessmentItemDefinition.d.ts +69 -0
  9. package/dist/core/AssessmentItemDefinition.js +149 -0
  10. package/dist/core/AssessmentItemDefinition.js.map +1 -0
  11. package/dist/core/ComponentRegistry.d.ts +11 -5
  12. package/dist/core/ComponentRegistry.js +44 -17
  13. package/dist/core/ComponentRegistry.js.map +1 -1
  14. package/dist/core/ItemSession.d.ts +58 -0
  15. package/dist/core/ItemSession.js +286 -0
  16. package/dist/core/ItemSession.js.map +1 -0
  17. package/dist/core/Player.d.ts +9 -8
  18. package/dist/core/Player.js +182 -163
  19. package/dist/core/Player.js.map +1 -1
  20. package/dist/core/sanitizer.js +33 -10
  21. package/dist/core/sanitizer.js.map +1 -1
  22. package/dist/document/AssessmentItemDocument.d.ts +32 -10
  23. package/dist/document/AssessmentItemDocument.js +80 -23
  24. package/dist/document/AssessmentItemDocument.js.map +1 -1
  25. package/dist/{element-class-C8OTgYHE.js → element-class-CILJ4Ls7.js} +3583 -2779
  26. package/dist/element-class-CILJ4Ls7.js.map +1 -0
  27. package/dist/element-class.d.ts +17 -13
  28. package/dist/element-class.js +1 -1
  29. package/dist/element.js +1 -1
  30. package/dist/extraction/ExtractionRegistry.d.ts +34 -11
  31. package/dist/extraction/ExtractionRegistry.js +122 -19
  32. package/dist/extraction/ExtractionRegistry.js.map +1 -1
  33. package/dist/extraction/createContext.d.ts +5 -6
  34. package/dist/extraction/createContext.js +2 -2
  35. package/dist/extraction/createContext.js.map +1 -1
  36. package/dist/extraction/deliveryTypes.d.ts +26 -0
  37. package/dist/extraction/deliveryTypes.js +7 -0
  38. package/dist/extraction/deliveryTypes.js.map +1 -0
  39. package/dist/extraction/index.d.ts +3 -3
  40. package/dist/extraction/index.js +1 -2
  41. package/dist/extraction/index.js.map +1 -1
  42. package/dist/extraction/interactionExtractionPipeline.d.ts +4 -4
  43. package/dist/extraction/interactionExtractionPipeline.js +27 -10
  44. package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
  45. package/dist/extraction/interactionSecurity.d.ts +11 -2
  46. package/dist/extraction/interactionSecurity.js +105 -40
  47. package/dist/extraction/interactionSecurity.js.map +1 -1
  48. package/dist/extraction/types.d.ts +44 -7
  49. package/dist/extraction/types.js.map +1 -1
  50. package/dist/extraction/utils.js +4 -16
  51. package/dist/extraction/utils.js.map +1 -1
  52. package/dist/index.d.ts +9 -8
  53. package/dist/index.js +5 -7
  54. package/dist/index.js.map +1 -1
  55. package/dist/interactions/associate/extractor.js +1 -1
  56. package/dist/interactions/associate/extractor.js.map +1 -1
  57. package/dist/interactions/drawing/extractor.js +5 -4
  58. package/dist/interactions/drawing/extractor.js.map +1 -1
  59. package/dist/interactions/end-attempt/extractor.js +2 -2
  60. package/dist/interactions/end-attempt/extractor.js.map +1 -1
  61. package/dist/interactions/gap-match/extractor.js +4 -3
  62. package/dist/interactions/gap-match/extractor.js.map +1 -1
  63. package/dist/interactions/graphic-associate/extractor.js +5 -4
  64. package/dist/interactions/graphic-associate/extractor.js.map +1 -1
  65. package/dist/interactions/graphic-gap-match/extractor.js +20 -17
  66. package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
  67. package/dist/interactions/graphic-order/extractor.js +5 -4
  68. package/dist/interactions/graphic-order/extractor.js.map +1 -1
  69. package/dist/interactions/hotspot/extractor.js +11 -10
  70. package/dist/interactions/hotspot/extractor.js.map +1 -1
  71. package/dist/interactions/inline/render-plan.d.ts +3 -5
  72. package/dist/interactions/inline/render-plan.js.map +1 -1
  73. package/dist/interactions/media/extractor.js +2 -2
  74. package/dist/interactions/media/extractor.js.map +1 -1
  75. package/dist/interactions/modules.d.ts +11 -91
  76. package/dist/interactions/modules.js +185 -45
  77. package/dist/interactions/modules.js.map +1 -1
  78. package/dist/interactions/portable-custom/extractor.d.ts +1 -1
  79. package/dist/interactions/portable-custom/extractor.js +1 -1
  80. package/dist/interactions/portable-custom/extractor.js.map +1 -1
  81. package/dist/interactions/position-object/extractor.js +3 -2
  82. package/dist/interactions/position-object/extractor.js.map +1 -1
  83. package/dist/interactions/select-point/extractor.js +7 -6
  84. package/dist/interactions/select-point/extractor.js.map +1 -1
  85. package/dist/interactions/shared/types.d.ts +59 -70
  86. package/dist/interactions/shared/types.js.map +1 -1
  87. package/dist/interactions/slider/extractor.js +2 -2
  88. package/dist/interactions/slider/extractor.js.map +1 -1
  89. package/dist/interactions/upload/extractor.js +2 -2
  90. package/dist/interactions/upload/extractor.js.map +1 -1
  91. package/dist/pci/types.d.ts +2 -3
  92. package/dist/pci/types.js.map +1 -1
  93. package/dist/presentation/itemPresentationPlan.d.ts +71 -38
  94. package/dist/presentation/itemPresentationPlan.js +78 -34
  95. package/dist/presentation/itemPresentationPlan.js.map +1 -1
  96. package/dist/security/index.d.ts +1 -1
  97. package/dist/security/index.js +1 -1
  98. package/dist/security/index.js.map +1 -1
  99. package/dist/security/styleValues.d.ts +20 -0
  100. package/dist/security/styleValues.js +49 -0
  101. package/dist/security/styleValues.js.map +1 -0
  102. package/dist/server.d.ts +188 -9
  103. package/dist/server.js +32 -7
  104. package/dist/server.js.map +1 -1
  105. package/dist/types/index.d.ts +1 -110
  106. package/dist/types/index.js.map +1 -1
  107. package/dist/web-components/QTIInteractionBase.d.ts +2 -2
  108. package/dist/web-components/QTIInteractionBase.js.map +1 -1
  109. package/dist/web-components/QTIInteractionElement.d.ts +3 -3
  110. package/dist/web-components/QTIInteractionElement.js.map +1 -1
  111. package/package.json +11 -11
  112. package/dist/core/Plugin.d.ts +0 -104
  113. package/dist/core/Plugin.js +0 -8
  114. package/dist/core/Plugin.js.map +0 -1
  115. package/dist/core/PluginManager.d.ts +0 -55
  116. package/dist/core/PluginManager.js +0 -148
  117. package/dist/core/PluginManager.js.map +0 -1
  118. package/dist/element-class-C8OTgYHE.js.map +0 -1
  119. package/dist/interactions/associate/index.d.ts +0 -2
  120. package/dist/interactions/associate/index.js +0 -2
  121. package/dist/interactions/associate/index.js.map +0 -1
  122. package/dist/interactions/associate/types.d.ts +0 -1
  123. package/dist/interactions/associate/types.js +0 -2
  124. package/dist/interactions/associate/types.js.map +0 -1
  125. package/dist/interactions/choice/index.d.ts +0 -2
  126. package/dist/interactions/choice/index.js +0 -2
  127. package/dist/interactions/choice/index.js.map +0 -1
  128. package/dist/interactions/choice/types.d.ts +0 -1
  129. package/dist/interactions/choice/types.js +0 -2
  130. package/dist/interactions/choice/types.js.map +0 -1
  131. package/dist/interactions/custom/index.d.ts +0 -2
  132. package/dist/interactions/custom/index.js +0 -2
  133. package/dist/interactions/custom/index.js.map +0 -1
  134. package/dist/interactions/custom/types.d.ts +0 -1
  135. package/dist/interactions/custom/types.js +0 -2
  136. package/dist/interactions/custom/types.js.map +0 -1
  137. package/dist/interactions/drawing/index.d.ts +0 -2
  138. package/dist/interactions/drawing/index.js +0 -2
  139. package/dist/interactions/drawing/index.js.map +0 -1
  140. package/dist/interactions/drawing/types.d.ts +0 -1
  141. package/dist/interactions/drawing/types.js +0 -2
  142. package/dist/interactions/drawing/types.js.map +0 -1
  143. package/dist/interactions/end-attempt/index.d.ts +0 -2
  144. package/dist/interactions/end-attempt/index.js +0 -2
  145. package/dist/interactions/end-attempt/index.js.map +0 -1
  146. package/dist/interactions/end-attempt/types.d.ts +0 -1
  147. package/dist/interactions/end-attempt/types.js +0 -2
  148. package/dist/interactions/end-attempt/types.js.map +0 -1
  149. package/dist/interactions/extended-text/index.d.ts +0 -3
  150. package/dist/interactions/extended-text/index.js +0 -3
  151. package/dist/interactions/extended-text/index.js.map +0 -1
  152. package/dist/interactions/extended-text/types.d.ts +0 -1
  153. package/dist/interactions/extended-text/types.js +0 -2
  154. package/dist/interactions/extended-text/types.js.map +0 -1
  155. package/dist/interactions/gap-match/index.d.ts +0 -2
  156. package/dist/interactions/gap-match/index.js +0 -2
  157. package/dist/interactions/gap-match/index.js.map +0 -1
  158. package/dist/interactions/gap-match/types.d.ts +0 -1
  159. package/dist/interactions/gap-match/types.js +0 -2
  160. package/dist/interactions/gap-match/types.js.map +0 -1
  161. package/dist/interactions/graphic-associate/index.d.ts +0 -2
  162. package/dist/interactions/graphic-associate/index.js +0 -2
  163. package/dist/interactions/graphic-associate/index.js.map +0 -1
  164. package/dist/interactions/graphic-associate/types.d.ts +0 -1
  165. package/dist/interactions/graphic-associate/types.js +0 -2
  166. package/dist/interactions/graphic-associate/types.js.map +0 -1
  167. package/dist/interactions/graphic-gap-match/index.d.ts +0 -2
  168. package/dist/interactions/graphic-gap-match/index.js +0 -2
  169. package/dist/interactions/graphic-gap-match/index.js.map +0 -1
  170. package/dist/interactions/graphic-gap-match/types.d.ts +0 -1
  171. package/dist/interactions/graphic-gap-match/types.js +0 -2
  172. package/dist/interactions/graphic-gap-match/types.js.map +0 -1
  173. package/dist/interactions/graphic-order/index.d.ts +0 -2
  174. package/dist/interactions/graphic-order/index.js +0 -2
  175. package/dist/interactions/graphic-order/index.js.map +0 -1
  176. package/dist/interactions/graphic-order/types.d.ts +0 -1
  177. package/dist/interactions/graphic-order/types.js +0 -2
  178. package/dist/interactions/graphic-order/types.js.map +0 -1
  179. package/dist/interactions/hotspot/index.d.ts +0 -2
  180. package/dist/interactions/hotspot/index.js +0 -2
  181. package/dist/interactions/hotspot/index.js.map +0 -1
  182. package/dist/interactions/hotspot/types.d.ts +0 -1
  183. package/dist/interactions/hotspot/types.js +0 -2
  184. package/dist/interactions/hotspot/types.js.map +0 -1
  185. package/dist/interactions/hottext/index.d.ts +0 -2
  186. package/dist/interactions/hottext/index.js +0 -2
  187. package/dist/interactions/hottext/index.js.map +0 -1
  188. package/dist/interactions/hottext/types.d.ts +0 -1
  189. package/dist/interactions/hottext/types.js +0 -2
  190. package/dist/interactions/hottext/types.js.map +0 -1
  191. package/dist/interactions/index.d.ts +0 -32
  192. package/dist/interactions/index.js +0 -31
  193. package/dist/interactions/index.js.map +0 -1
  194. package/dist/interactions/inline/index.d.ts +0 -1
  195. package/dist/interactions/inline/index.js +0 -2
  196. package/dist/interactions/inline/index.js.map +0 -1
  197. package/dist/interactions/inline-choice/index.d.ts +0 -2
  198. package/dist/interactions/inline-choice/index.js +0 -2
  199. package/dist/interactions/inline-choice/index.js.map +0 -1
  200. package/dist/interactions/inline-choice/types.d.ts +0 -1
  201. package/dist/interactions/inline-choice/types.js +0 -2
  202. package/dist/interactions/inline-choice/types.js.map +0 -1
  203. package/dist/interactions/match/index.d.ts +0 -2
  204. package/dist/interactions/match/index.js +0 -2
  205. package/dist/interactions/match/index.js.map +0 -1
  206. package/dist/interactions/match/types.d.ts +0 -1
  207. package/dist/interactions/match/types.js +0 -2
  208. package/dist/interactions/match/types.js.map +0 -1
  209. package/dist/interactions/media/index.d.ts +0 -2
  210. package/dist/interactions/media/index.js +0 -2
  211. package/dist/interactions/media/index.js.map +0 -1
  212. package/dist/interactions/media/types.d.ts +0 -1
  213. package/dist/interactions/media/types.js +0 -2
  214. package/dist/interactions/media/types.js.map +0 -1
  215. package/dist/interactions/order/index.d.ts +0 -2
  216. package/dist/interactions/order/index.js +0 -2
  217. package/dist/interactions/order/index.js.map +0 -1
  218. package/dist/interactions/order/types.d.ts +0 -1
  219. package/dist/interactions/order/types.js +0 -2
  220. package/dist/interactions/order/types.js.map +0 -1
  221. package/dist/interactions/portable-custom/index.d.ts +0 -2
  222. package/dist/interactions/portable-custom/index.js +0 -2
  223. package/dist/interactions/portable-custom/index.js.map +0 -1
  224. package/dist/interactions/portable-custom/types.d.ts +0 -1
  225. package/dist/interactions/portable-custom/types.js +0 -2
  226. package/dist/interactions/portable-custom/types.js.map +0 -1
  227. package/dist/interactions/position-object/index.d.ts +0 -2
  228. package/dist/interactions/position-object/index.js +0 -2
  229. package/dist/interactions/position-object/index.js.map +0 -1
  230. package/dist/interactions/position-object/types.d.ts +0 -1
  231. package/dist/interactions/position-object/types.js +0 -2
  232. package/dist/interactions/position-object/types.js.map +0 -1
  233. package/dist/interactions/select-point/index.d.ts +0 -2
  234. package/dist/interactions/select-point/index.js +0 -2
  235. package/dist/interactions/select-point/index.js.map +0 -1
  236. package/dist/interactions/select-point/types.d.ts +0 -1
  237. package/dist/interactions/select-point/types.js +0 -2
  238. package/dist/interactions/select-point/types.js.map +0 -1
  239. package/dist/interactions/shared/index.d.ts +0 -1
  240. package/dist/interactions/shared/index.js +0 -2
  241. package/dist/interactions/shared/index.js.map +0 -1
  242. package/dist/interactions/slider/index.d.ts +0 -2
  243. package/dist/interactions/slider/index.js +0 -2
  244. package/dist/interactions/slider/index.js.map +0 -1
  245. package/dist/interactions/slider/types.d.ts +0 -1
  246. package/dist/interactions/slider/types.js +0 -2
  247. package/dist/interactions/slider/types.js.map +0 -1
  248. package/dist/interactions/text-entry/index.d.ts +0 -2
  249. package/dist/interactions/text-entry/index.js +0 -2
  250. package/dist/interactions/text-entry/index.js.map +0 -1
  251. package/dist/interactions/text-entry/types.d.ts +0 -1
  252. package/dist/interactions/text-entry/types.js +0 -2
  253. package/dist/interactions/text-entry/types.js.map +0 -1
  254. package/dist/interactions/upload/index.d.ts +0 -2
  255. package/dist/interactions/upload/index.js +0 -2
  256. package/dist/interactions/upload/index.js.map +0 -1
  257. package/dist/interactions/upload/types.d.ts +0 -1
  258. package/dist/interactions/upload/types.js +0 -2
  259. package/dist/interactions/upload/types.js.map +0 -1
@@ -1,56 +1,89 @@
1
1
  import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
2
2
  import { type QtiHeuristicsConfig } from '@pie-qti/ims-cp-core';
3
+ import type { ComponentRegistry } from '../core/ComponentRegistry.js';
3
4
  import type { PnpProfile } from '../pnp/types.js';
4
5
  import { type RoleCapabilities } from '../core/rolePolicy.js';
5
- import type { InteractionData, HtmlContent, QTIRole } from '../types/index.js';
6
- import { type InlineRenderSegment } from '../interactions/inline/render-plan.js';
6
+ import type { HtmlContent, PlayerSecurityConfig, QTIRole, RubricBlock } from '../types/index.js';
7
+ import type { BaseInteractionData, InlineChoiceInteractionData, TextEntryInteractionData } from '../interactions/shared/types.js';
7
8
  export type ItemPresentationResponseValue = unknown;
8
9
  export type ItemPresentationResponseMap = Record<string, ItemPresentationResponseValue>;
9
- export interface ItemPresentationComponentRegistry {
10
- getTagName(interaction: InteractionData): string;
11
- }
12
- export interface ItemPresentationPlayer {
13
- getComponentRegistry(): ItemPresentationComponentRegistry;
14
- getInteractionData(): InteractionData[];
15
- getCorrectResponses(): Record<string, unknown>;
16
- getItemBodyHtml(): HtmlContent;
17
- getDeliveryContext(): ResolvedItemDeliveryContext | undefined;
18
- sanitizeHtmlContent(html: string): string;
19
- getPnp(): PnpProfile | undefined;
10
+ /**
11
+ * Immutable inputs captured from the live item session for one presentation pass.
12
+ *
13
+ * This deliberately contains data rather than a Player-shaped adapter. Presentation
14
+ * cannot reach back into the session midway through a render, and its only live seam
15
+ * is the real component registry used to resolve plugin renderers.
16
+ */
17
+ export interface ItemPresentationSource {
18
+ itemBodyHtml: HtmlContent;
19
+ interactions: readonly BaseInteractionData[];
20
+ correctResponses: Record<string, unknown>;
21
+ componentRegistry: ComponentRegistry;
22
+ deliveryContext?: ResolvedItemDeliveryContext;
23
+ pnp?: PnpProfile;
24
+ security?: PlayerSecurityConfig;
25
+ /** Role-filtered, finalized direct rubrics for host placement. */
26
+ directRubrics?: readonly RubricBlock[];
20
27
  }
21
- export interface CreateItemPresentationPlanOptions {
22
- player: ItemPresentationPlayer;
28
+ export interface CreateItemPresentationOptions {
29
+ source: ItemPresentationSource;
23
30
  responses?: ItemPresentationResponseMap;
24
31
  disabled?: boolean;
25
32
  role?: QTIRole;
26
33
  outcomeValues?: Record<string, unknown>;
27
34
  heuristicsConfig?: QtiHeuristicsConfig;
28
- stimulusContent?: Record<string, string>;
29
- deliveryContext?: ResolvedItemDeliveryContext;
30
35
  itemBodyScopeSelector?: string;
31
36
  renderItemBodyRubrics?: boolean;
32
- onComponentError?: (interaction: InteractionData, error: unknown) => void;
37
+ onComponentError?: (interaction: BaseInteractionData, error: unknown) => void;
33
38
  }
34
- export interface BlockInteractionPresentation {
35
- interaction: InteractionData;
36
- tagName: string;
37
- key: string;
38
- response: ItemPresentationResponseValue | null;
39
+ export interface BlockInteractionMount {
40
+ readonly placement: 'block';
41
+ readonly renderer: 'web-component';
42
+ readonly interaction: BaseInteractionData;
43
+ readonly tagName: string;
44
+ readonly key: string;
45
+ readonly response: ItemPresentationResponseValue | null;
39
46
  /** Lexical companion value used by extendedTextInteraction stringIdentifier. */
40
- stringResponse?: ItemPresentationResponseValue | null;
41
- correctResponse: unknown;
42
- pnp: PnpProfile | undefined;
43
- eliminationTool: boolean;
44
- disabled: boolean;
45
- componentRole: 'scorer' | undefined;
47
+ readonly stringResponse?: ItemPresentationResponseValue | null;
48
+ readonly correctResponse: unknown;
49
+ readonly pnp: PnpProfile | undefined;
50
+ readonly eliminationTool: boolean;
51
+ readonly disabled: boolean;
52
+ readonly componentRole: 'scorer' | undefined;
46
53
  }
47
- export interface ItemPresentationPlan {
48
- roleCapabilities: RoleCapabilities;
49
- effectiveDisabled: boolean;
50
- correctResponses: Record<string, unknown>;
51
- itemBodyHtml: string;
52
- inlineSegments: InlineRenderSegment[];
53
- blockInteractions: BlockInteractionPresentation[];
54
+ export type InlineInteractionMount = {
55
+ readonly placement: 'inline';
56
+ readonly renderer: 'text-entry';
57
+ readonly interaction: TextEntryInteractionData;
58
+ } | {
59
+ readonly placement: 'inline';
60
+ readonly renderer: 'inline-choice';
61
+ readonly interaction: InlineChoiceInteractionData;
62
+ };
63
+ export type ItemInteractionMount = InlineInteractionMount | BlockInteractionMount;
64
+ declare const finalItemBodyHtmlBrand: unique symbol;
65
+ /** HTML that has completed every body transform, sanitation, and Trusted Types finalization. */
66
+ export type FinalItemBodyHtml = HtmlContent & {
67
+ readonly [finalItemBodyHtmlBrand]: true;
68
+ };
69
+ export type ItemPresentationFlowNode = {
70
+ readonly kind: 'html';
71
+ readonly html: FinalItemBodyHtml;
72
+ } | {
73
+ readonly kind: 'interaction';
74
+ readonly mount: ItemInteractionMount;
75
+ };
76
+ export interface ItemPresentation {
77
+ readonly capabilities: RoleCapabilities;
78
+ readonly disabled: boolean;
79
+ readonly correctResponses: Readonly<Record<string, unknown>>;
80
+ /** Direct assessmentItem rubrics that remain outside the item-body flow. */
81
+ readonly directRubrics: readonly RubricBlock[];
82
+ /** Ordered, render-neutral body flow. Block mounts follow the authored body HTML. */
83
+ readonly flow: readonly ItemPresentationFlowNode[];
84
+ /** Policy-checked CSS is kept out of the HTML/Trusted Types pipeline. */
85
+ readonly scopedCss: string;
54
86
  }
55
- export declare function createItemPresentationPlan({ player, responses, disabled, role, outcomeValues, heuristicsConfig, stimulusContent, deliveryContext, itemBodyScopeSelector, renderItemBodyRubrics, onComponentError, }: CreateItemPresentationPlanOptions): ItemPresentationPlan;
56
- export declare function interactionKey(interaction: InteractionData): string;
87
+ export declare function createItemPresentation({ source, responses, disabled, role, outcomeValues, heuristicsConfig, itemBodyScopeSelector, renderItemBodyRubrics, onComponentError, }: CreateItemPresentationOptions): ItemPresentation;
88
+ export declare function interactionKey(interaction: BaseInteractionData): string;
89
+ export {};
@@ -1,51 +1,91 @@
1
1
  import { normalizeHeuristicsConfig, } from '@pie-qti/ims-cp-core';
2
2
  import { parse } from 'node-html-parser';
3
+ import { sanitizeHtml } from '../core/sanitizer.js';
4
+ import { htmlToString, toTrustedHtml } from '../core/trustedTypes.js';
3
5
  import { getRoleCapabilities } from '../core/rolePolicy.js';
4
6
  import { processFeedbackInline } from '../components/utils/feedbackUtils.js';
5
7
  import { buildScopedStylesheetCss } from '../components/utils/stylesheetRender.js';
6
8
  import { buildEffectiveStimulusContent, injectStimulusContent } from '../components/utils/stimulusRender.js';
7
9
  import { createInlineRenderPlan, isInlineInteractionTagName, isInlineInteractionType, } from '../interactions/inline/render-plan.js';
8
- export function createItemPresentationPlan({ player, responses = {}, disabled = false, role = 'candidate', outcomeValues = {}, heuristicsConfig, stimulusContent = {}, deliveryContext, itemBodyScopeSelector = '[data-qti-item-body-scope]', renderItemBodyRubrics = true, onComponentError, }) {
9
- const interactions = player.getInteractionData();
10
+ export function createItemPresentation({ source, responses = {}, disabled = false, role = 'candidate', outcomeValues = {}, heuristicsConfig, itemBodyScopeSelector = '[data-qti-item-body-scope]', renderItemBodyRubrics = true, onComponentError, }) {
10
11
  const roleCapabilities = getRoleCapabilities(role);
11
12
  const effectiveDisabled = disabled || roleCapabilities.isReadOnly;
12
- const correctResponses = roleCapabilities.canViewCorrectResponses ? player.getCorrectResponses() : {};
13
- const itemBodyHtml = buildItemBodyPresentationHtml({
14
- player,
13
+ const correctResponses = roleCapabilities.canViewCorrectResponses ? source.correctResponses : {};
14
+ const { html, scopedCss } = buildItemBodyPresentation({
15
+ source,
15
16
  role,
16
17
  outcomeValues,
17
18
  heuristicsConfig,
18
- stimulusContent,
19
- deliveryContext,
20
19
  itemBodyScopeSelector,
21
20
  renderItemBodyRubrics,
22
21
  });
23
- return {
22
+ const inlineFlow = createInlineRenderPlan(html, source.interactions).map((segment) => {
23
+ if (segment.type === 'html') {
24
+ // Inline planning parses and reserializes the composed body, so sanitation
25
+ // belongs after that final string transform and immediately before TT.
26
+ const sanitized = sanitizeHtml(segment.content, { security: source.security });
27
+ return {
28
+ kind: 'html',
29
+ html: finalizeItemBodyHtml(sanitized, source.security),
30
+ };
31
+ }
32
+ if (segment.type === 'textEntry') {
33
+ return {
34
+ kind: 'interaction',
35
+ mount: {
36
+ placement: 'inline',
37
+ renderer: 'text-entry',
38
+ interaction: segment.interaction,
39
+ },
40
+ };
41
+ }
42
+ return {
43
+ kind: 'interaction',
44
+ mount: {
45
+ placement: 'inline',
46
+ renderer: 'inline-choice',
47
+ interaction: segment.interaction,
48
+ },
49
+ };
50
+ });
51
+ const blockFlow = createBlockInteractionMounts({
52
+ interactions: source.interactions,
53
+ source,
54
+ responses,
55
+ correctResponses,
24
56
  roleCapabilities,
25
57
  effectiveDisabled,
58
+ onComponentError,
59
+ }).map((mount) => ({
60
+ kind: 'interaction',
61
+ mount,
62
+ }));
63
+ return freezePresentation({
64
+ capabilities: roleCapabilities,
65
+ disabled: effectiveDisabled,
26
66
  correctResponses,
27
- itemBodyHtml,
28
- inlineSegments: createInlineRenderPlan(itemBodyHtml, interactions),
29
- blockInteractions: createBlockInteractionPresentations({
30
- interactions,
31
- player,
32
- responses,
33
- correctResponses,
34
- roleCapabilities,
35
- effectiveDisabled,
36
- onComponentError,
37
- }),
38
- };
67
+ directRubrics: source.directRubrics ?? [],
68
+ flow: [...inlineFlow, ...blockFlow],
69
+ scopedCss,
70
+ });
39
71
  }
40
- function buildItemBodyPresentationHtml({ player, role, outcomeValues, heuristicsConfig, stimulusContent, deliveryContext, itemBodyScopeSelector, renderItemBodyRubrics, }) {
41
- let html = String(player.getItemBodyHtml());
42
- const resolvedDeliveryContext = deliveryContext ?? player.getDeliveryContext();
43
- const stylesheetCss = buildScopedStylesheetCss(resolvedDeliveryContext, itemBodyScopeSelector);
44
- const effectiveStimulusContent = buildEffectiveStimulusContent(resolvedDeliveryContext, stimulusContent, (content) => player.sanitizeHtmlContent(content));
45
- html = injectStimulusContent(html, effectiveStimulusContent);
46
- if (stylesheetCss) {
47
- html = `<style data-qti-stylesheets="resolved">${stylesheetCss}</style>${html}`;
72
+ function freezePresentation(value) {
73
+ if (!value || typeof value !== 'object' || Object.isFrozen(value))
74
+ return value;
75
+ const prototype = Object.getPrototypeOf(value);
76
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null)
77
+ return value;
78
+ Object.freeze(value);
79
+ for (const child of Object.values(value)) {
80
+ freezePresentation(child);
48
81
  }
82
+ return value;
83
+ }
84
+ function buildItemBodyPresentation({ source, role, outcomeValues, heuristicsConfig, itemBodyScopeSelector, renderItemBodyRubrics, }) {
85
+ let html = htmlToString(source.itemBodyHtml);
86
+ const scopedCss = buildScopedStylesheetCss(source.deliveryContext, itemBodyScopeSelector);
87
+ const effectiveStimulusContent = buildEffectiveStimulusContent(source.deliveryContext, (content) => sanitizeHtml(content, { security: source.security }));
88
+ html = injectStimulusContent(html, effectiveStimulusContent);
49
89
  html = renderRubricBlocksForRole(html, role, { renderRubrics: renderItemBodyRubrics });
50
90
  const heuristics = normalizeHeuristicsConfig(heuristicsConfig);
51
91
  html = processFeedbackInline(html, {
@@ -53,7 +93,10 @@ function buildItemBodyPresentationHtml({ player, role, outcomeValues, heuristics
53
93
  applyHeuristics: heuristics.feedbackTextFormatting,
54
94
  wrapWithSpan: false,
55
95
  });
56
- return hideBlockInteractionMarkup(html);
96
+ return { html: hideBlockInteractionMarkup(html), scopedCss };
97
+ }
98
+ function finalizeItemBodyHtml(html, security) {
99
+ return toTrustedHtml(html, security?.trustedTypesPolicyName);
57
100
  }
58
101
  function renderRubricBlocksForRole(html, role, { renderRubrics }) {
59
102
  if (!html || !/rubric-?block/i.test(html)) {
@@ -131,8 +174,7 @@ function hideBlockInteractionMarkup(html) {
131
174
  return `<span class="qti-hidden-interaction">${match}</span>`;
132
175
  });
133
176
  }
134
- function createBlockInteractionPresentations({ interactions, player, responses, correctResponses, roleCapabilities, effectiveDisabled, onComponentError, }) {
135
- const componentRegistry = player.getComponentRegistry();
177
+ function createBlockInteractionMounts({ interactions, source, responses, correctResponses, roleCapabilities, effectiveDisabled, onComponentError, }) {
136
178
  return interactions
137
179
  .filter((interaction) => !isInlineInteractionType(interaction.type))
138
180
  .map((interaction) => {
@@ -141,8 +183,10 @@ function createBlockInteractionPresentations({ interactions, player, responses,
141
183
  ? interaction.stringIdentifier
142
184
  : undefined;
143
185
  const block = {
186
+ placement: 'block',
187
+ renderer: 'web-component',
144
188
  interaction,
145
- tagName: componentRegistry.getTagName(interaction),
189
+ tagName: source.componentRegistry.getTagName(interaction),
146
190
  key: interactionKey(interaction),
147
191
  response: responses[interaction.responseId] ?? null,
148
192
  ...(stringIdentifier
@@ -151,8 +195,8 @@ function createBlockInteractionPresentations({ interactions, player, responses,
151
195
  correctResponse: roleCapabilities.canViewCorrectResponses
152
196
  ? (correctResponses[interaction.responseId] ?? null)
153
197
  : null,
154
- pnp: player.getPnp(),
155
- eliminationTool: player.getPnp()?.cognitive?.eliminationTool === true,
198
+ pnp: source.pnp,
199
+ eliminationTool: source.pnp?.cognitive?.eliminationTool === true,
156
200
  disabled: effectiveDisabled,
157
201
  componentRole: roleCapabilities.canViewCorrectResponses ? 'scorer' : undefined,
158
202
  };
@@ -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,mBAAmB,EAAyB,MAAM,uBAAuB,CAAC;AAEnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC7G,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,GAEvB,MAAM,uCAAuC,CAAC;AAwD/C,MAAM,UAAU,0BAA0B,CAAC,EAC1C,MAAM,EACN,SAAS,GAAG,EAAE,EACd,QAAQ,GAAG,KAAK,EAChB,IAAI,GAAG,WAAW,EAClB,aAAa,GAAG,EAAE,EAClB,gBAAgB,EAChB,eAAe,GAAG,EAAE,EACpB,eAAe,EACf,qBAAqB,GAAG,4BAA4B,EACpD,qBAAqB,GAAG,IAAI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CAAC,CAAC,CAAC,SAAS;aAC9E,CAAC;YACF,OAAO,KAAK,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,gBAAgB,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YACvC,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,IAAI,EAAwC,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,WAA4B;IAC1D,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 { PnpProfile } from '../pnp/types.js';\nimport { getRoleCapabilities, type RoleCapabilities } from '../core/rolePolicy.js';\nimport type { InteractionData, HtmlContent, QTIRole } 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\ttype InlineRenderSegment,\n} from '../interactions/inline/render-plan.js';\n\nexport type ItemPresentationResponseValue = unknown;\nexport type ItemPresentationResponseMap = Record<string, ItemPresentationResponseValue>;\n\nexport interface ItemPresentationComponentRegistry {\n\tgetTagName(interaction: InteractionData): string;\n}\n\nexport interface ItemPresentationPlayer {\n\tgetComponentRegistry(): ItemPresentationComponentRegistry;\n\tgetInteractionData(): InteractionData[];\n\tgetCorrectResponses(): Record<string, unknown>;\n\tgetItemBodyHtml(): HtmlContent;\n\tgetDeliveryContext(): ResolvedItemDeliveryContext | undefined;\n\tsanitizeHtmlContent(html: string): string;\n\tgetPnp(): PnpProfile | undefined;\n}\n\nexport interface CreateItemPresentationPlanOptions {\n\tplayer: ItemPresentationPlayer;\n\tresponses?: ItemPresentationResponseMap;\n\tdisabled?: boolean;\n\trole?: QTIRole;\n\toutcomeValues?: Record<string, unknown>;\n\theuristicsConfig?: QtiHeuristicsConfig;\n\tstimulusContent?: Record<string, string>;\n\tdeliveryContext?: ResolvedItemDeliveryContext;\n\titemBodyScopeSelector?: string;\n\trenderItemBodyRubrics?: boolean;\n\tonComponentError?: (interaction: InteractionData, error: unknown) => void;\n}\n\nexport interface BlockInteractionPresentation {\n\tinteraction: InteractionData;\n\ttagName: string;\n\tkey: string;\n\tresponse: ItemPresentationResponseValue | null;\n\t/** Lexical companion value used by extendedTextInteraction stringIdentifier. */\n\tstringResponse?: ItemPresentationResponseValue | null;\n\tcorrectResponse: unknown;\n\tpnp: PnpProfile | undefined;\n\teliminationTool: boolean;\n\tdisabled: boolean;\n\tcomponentRole: 'scorer' | undefined;\n}\n\nexport interface ItemPresentationPlan {\n\troleCapabilities: RoleCapabilities;\n\teffectiveDisabled: boolean;\n\tcorrectResponses: Record<string, unknown>;\n\titemBodyHtml: string;\n\tinlineSegments: InlineRenderSegment[];\n\tblockInteractions: BlockInteractionPresentation[];\n}\n\nexport function createItemPresentationPlan({\n\tplayer,\n\tresponses = {},\n\tdisabled = false,\n\trole = 'candidate',\n\toutcomeValues = {},\n\theuristicsConfig,\n\tstimulusContent = {},\n\tdeliveryContext,\n\titemBodyScopeSelector = '[data-qti-item-body-scope]',\n\trenderItemBodyRubrics = true,\n\tonComponentError,\n}: CreateItemPresentationPlanOptions): ItemPresentationPlan {\n\tconst interactions = player.getInteractionData();\n\tconst roleCapabilities = getRoleCapabilities(role);\n\tconst effectiveDisabled = disabled || roleCapabilities.isReadOnly;\n\tconst correctResponses = roleCapabilities.canViewCorrectResponses ? player.getCorrectResponses() : {};\n\tconst itemBodyHtml = buildItemBodyPresentationHtml({\n\t\tplayer,\n\t\trole,\n\t\toutcomeValues,\n\t\theuristicsConfig,\n\t\tstimulusContent,\n\t\tdeliveryContext,\n\t\titemBodyScopeSelector,\n\t\trenderItemBodyRubrics,\n\t});\n\n\treturn {\n\t\troleCapabilities,\n\t\teffectiveDisabled,\n\t\tcorrectResponses,\n\t\titemBodyHtml,\n\t\tinlineSegments: createInlineRenderPlan(itemBodyHtml, interactions),\n\t\tblockInteractions: createBlockInteractionPresentations({\n\t\t\tinteractions,\n\t\t\tplayer,\n\t\t\tresponses,\n\t\t\tcorrectResponses,\n\t\t\troleCapabilities,\n\t\t\teffectiveDisabled,\n\t\t\tonComponentError,\n\t\t}),\n\t};\n}\n\nfunction buildItemBodyPresentationHtml({\n\tplayer,\n\trole,\n\toutcomeValues,\n\theuristicsConfig,\n\tstimulusContent,\n\tdeliveryContext,\n\titemBodyScopeSelector,\n\trenderItemBodyRubrics,\n}: {\n\tplayer: ItemPresentationPlayer;\n\trole: QTIRole;\n\toutcomeValues: Record<string, unknown>;\n\theuristicsConfig: QtiHeuristicsConfig | undefined;\n\tstimulusContent: Record<string, string>;\n\tdeliveryContext: ResolvedItemDeliveryContext | undefined;\n\titemBodyScopeSelector: string;\n\trenderItemBodyRubrics: boolean;\n}): string {\n\tlet html = String(player.getItemBodyHtml());\n\tconst resolvedDeliveryContext = deliveryContext ?? player.getDeliveryContext();\n\tconst stylesheetCss = buildScopedStylesheetCss(resolvedDeliveryContext, itemBodyScopeSelector);\n\tconst effectiveStimulusContent = buildEffectiveStimulusContent(\n\t\tresolvedDeliveryContext,\n\t\tstimulusContent,\n\t\t(content) => player.sanitizeHtmlContent(content)\n\t);\n\n\thtml = injectStimulusContent(html, effectiveStimulusContent);\n\tif (stylesheetCss) {\n\t\thtml = `<style data-qti-stylesheets=\"resolved\">${stylesheetCss}</style>${html}`;\n\t}\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 hideBlockInteractionMarkup(html);\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 createBlockInteractionPresentations({\n\tinteractions,\n\tplayer,\n\tresponses,\n\tcorrectResponses,\n\troleCapabilities,\n\teffectiveDisabled,\n\tonComponentError,\n}: {\n\tinteractions: InteractionData[];\n\tplayer: ItemPresentationPlayer;\n\tresponses: ItemPresentationResponseMap;\n\tcorrectResponses: Record<string, unknown>;\n\troleCapabilities: RoleCapabilities;\n\teffectiveDisabled: boolean;\n\tonComponentError?: (interaction: InteractionData, error: unknown) => void;\n}): BlockInteractionPresentation[] {\n\tconst componentRegistry = player.getComponentRegistry();\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: BlockInteractionPresentation = {\n\t\t\t\t\tinteraction,\n\t\t\t\t\ttagName: 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: player.getPnp(),\n\t\t\t\t\teliminationTool: player.getPnp()?.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 BlockInteractionPresentation => item !== null);\n}\n\nexport function interactionKey(interaction: InteractionData): 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,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC7G,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,GACvB,MAAM,uCAAuC,CAAC;AA8F/C,MAAM,UAAU,sBAAsB,CAAC,EACtC,MAAM,EACN,SAAS,GAAG,EAAE,EACd,QAAQ,GAAG,KAAK,EAChB,IAAI,GAAG,WAAW,EAClB,aAAa,GAAG,EAAE,EAClB,gBA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,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"]}
@@ -6,7 +6,7 @@ export { sanitizeHtml, sanitizeTextContent, type SanitizeHtmlOptions };
6
6
  export { sanitizeResourceUrl, type UrlKind };
7
7
  export { enforceItemXmlLimits, normalizeParsingLimits, type NormalizedParsingLimits, } from '../core/parsingLimits.js';
8
8
  export { toTrustedHtml, htmlToString };
9
- export { applyInteractionSecurity } from '../extraction/interactionSecurity.js';
9
+ export { normalizeCssPixelLength, normalizePixelDimension, type CssPixelLength, } from './styleValues.js';
10
10
  export type { HtmlContent, ParsingLimitsConfig, PlayerSecurityConfig, TrustedTypesHtml, UrlPolicyConfig, } from '../types/index.js';
11
11
  export interface SanitizeSharedHtmlOptions {
12
12
  sanitizeUrl?: SanitizeHtmlOptions['sanitizeUrl'];
@@ -5,7 +5,7 @@ export { sanitizeHtml, sanitizeTextContent };
5
5
  export { sanitizeResourceUrl };
6
6
  export { enforceItemXmlLimits, normalizeParsingLimits, } from '../core/parsingLimits.js';
7
7
  export { toTrustedHtml, htmlToString };
8
- export { applyInteractionSecurity } from '../extraction/interactionSecurity.js';
8
+ export { normalizeCssPixelLength, normalizePixelDimension, } from './styleValues.js';
9
9
  export function sanitizeSharedHtml(html, security, options) {
10
10
  const sanitized = sanitizeHtml(html, { security, sanitizeUrl: options?.sanitizeUrl });
11
11
  return toTrustedHtml(sanitized, security?.trustedTypesPolicyName);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAA4B,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,mBAAmB,EAAgB,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGtE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAA4B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAgB,CAAC;AAC7C,OAAO,EACN,oBAAoB,EACpB,sBAAsB,GAEtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAahF,MAAM,UAAU,kBAAkB,CACjC,IAAY,EACZ,QAA+B,EAC/B,OAAmC;IAEnC,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IACtF,OAAO,aAAa,CAAC,SAAS,EAAE,QAAQ,EAAE,sBAAsB,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { sanitizeHtml, sanitizeTextContent, type SanitizeHtmlOptions } from '../core/sanitizer.js';\nimport { sanitizeResourceUrl, type UrlKind } from '../core/urlPolicy.js';\nimport { toTrustedHtml, htmlToString } from '../core/trustedTypes.js';\nimport type { HtmlContent, PlayerSecurityConfig } from '../types/index.js';\n\nexport { sanitizeHtml, sanitizeTextContent, type SanitizeHtmlOptions };\nexport { sanitizeResourceUrl, type UrlKind };\nexport {\n\tenforceItemXmlLimits,\n\tnormalizeParsingLimits,\n\ttype NormalizedParsingLimits,\n} from '../core/parsingLimits.js';\nexport { toTrustedHtml, htmlToString };\nexport { applyInteractionSecurity } from '../extraction/interactionSecurity.js';\nexport type {\n\tHtmlContent,\n\tParsingLimitsConfig,\n\tPlayerSecurityConfig,\n\tTrustedTypesHtml,\n\tUrlPolicyConfig,\n} from '../types/index.js';\n\nexport interface SanitizeSharedHtmlOptions {\n\tsanitizeUrl?: SanitizeHtmlOptions['sanitizeUrl'];\n}\n\nexport function sanitizeSharedHtml(\n\thtml: string,\n\tsecurity?: PlayerSecurityConfig,\n\toptions?: SanitizeSharedHtmlOptions\n): HtmlContent {\n\tconst sanitized = sanitizeHtml(html, { security, sanitizeUrl: options?.sanitizeUrl });\n\treturn toTrustedHtml(sanitized, security?.trustedTypesPolicyName);\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAA4B,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,mBAAmB,EAAgB,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGtE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAA4B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAgB,CAAC;AAC7C,OAAO,EACN,oBAAoB,EACpB,sBAAsB,GAEtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AACvC,OAAO,EACN,uBAAuB,EACvB,uBAAuB,GAEvB,MAAM,kBAAkB,CAAC;AAa1B,MAAM,UAAU,kBAAkB,CACjC,IAAY,EACZ,QAA+B,EAC/B,OAAmC;IAEnC,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IACtF,OAAO,aAAa,CAAC,SAAS,EAAE,QAAQ,EAAE,sBAAsB,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { sanitizeHtml, sanitizeTextContent, type SanitizeHtmlOptions } from '../core/sanitizer.js';\nimport { sanitizeResourceUrl, type UrlKind } from '../core/urlPolicy.js';\nimport { toTrustedHtml, htmlToString } from '../core/trustedTypes.js';\nimport type { HtmlContent, PlayerSecurityConfig } from '../types/index.js';\n\nexport { sanitizeHtml, sanitizeTextContent, type SanitizeHtmlOptions };\nexport { sanitizeResourceUrl, type UrlKind };\nexport {\n\tenforceItemXmlLimits,\n\tnormalizeParsingLimits,\n\ttype NormalizedParsingLimits,\n} from '../core/parsingLimits.js';\nexport { toTrustedHtml, htmlToString };\nexport {\n\tnormalizeCssPixelLength,\n\tnormalizePixelDimension,\n\ttype CssPixelLength,\n} from './styleValues.js';\nexport type {\n\tHtmlContent,\n\tParsingLimitsConfig,\n\tPlayerSecurityConfig,\n\tTrustedTypesHtml,\n\tUrlPolicyConfig,\n} from '../types/index.js';\n\nexport interface SanitizeSharedHtmlOptions {\n\tsanitizeUrl?: SanitizeHtmlOptions['sanitizeUrl'];\n}\n\nexport function sanitizeSharedHtml(\n\thtml: string,\n\tsecurity?: PlayerSecurityConfig,\n\toptions?: SanitizeSharedHtmlOptions\n): HtmlContent {\n\tconst sanitized = sanitizeHtml(html, { security, sanitizeUrl: options?.sanitizeUrl });\n\treturn toTrustedHtml(sanitized, security?.trustedTypesPolicyName);\n}\n"]}
@@ -0,0 +1,20 @@
1
+ /** A canonical, declaration-safe CSS pixel length. */
2
+ export type CssPixelLength = `${number}px`;
3
+ /**
4
+ * Normalize an authored palette width to one complete CSS value.
5
+ *
6
+ * Palette widths are a player extension expressed in pixels. Restricting the
7
+ * grammar to a non-negative decimal with an optional `px` suffix prevents an
8
+ * authored value from terminating the width declaration and introducing a
9
+ * second declaration such as `background-image: url(...)`.
10
+ */
11
+ export declare function normalizeCssPixelLength(value: unknown): CssPixelLength | null;
12
+ /**
13
+ * Normalize QTI image/object width and height attributes to a positive pixel
14
+ * count without a unit. Callers can safely append `px` in a style value.
15
+ *
16
+ * QTI dimensions use the integer-like HTML width/height attribute shape, so
17
+ * unit-bearing values are rejected. Decimal values remain accepted for
18
+ * compatibility and are emitted in canonical numeric form.
19
+ */
20
+ export declare function normalizePixelDimension(value: unknown, fallback?: string | number): string | undefined;
@@ -0,0 +1,49 @@
1
+ const UNSIGNED_DECIMAL = /^(?:\d+(?:\.\d*)?|\.\d+)$/;
2
+ const MAX_AUTHORED_PIXEL_LENGTH = 100000;
3
+ function parseUnsignedDecimal(value, allowPixelSuffix) {
4
+ if (typeof value === 'number') {
5
+ return Number.isFinite(value) && value >= 0 ? value : null;
6
+ }
7
+ if (typeof value !== 'string')
8
+ return null;
9
+ let token = value.trim();
10
+ if (allowPixelSuffix && token.toLowerCase().endsWith('px')) {
11
+ token = token.slice(0, -2).trim();
12
+ }
13
+ if (!UNSIGNED_DECIMAL.test(token))
14
+ return null;
15
+ const parsed = Number(token);
16
+ return Number.isFinite(parsed) && parsed >= 0 && parsed <= MAX_AUTHORED_PIXEL_LENGTH
17
+ ? parsed
18
+ : null;
19
+ }
20
+ /**
21
+ * Normalize an authored palette width to one complete CSS value.
22
+ *
23
+ * Palette widths are a player extension expressed in pixels. Restricting the
24
+ * grammar to a non-negative decimal with an optional `px` suffix prevents an
25
+ * authored value from terminating the width declaration and introducing a
26
+ * second declaration such as `background-image: url(...)`.
27
+ */
28
+ export function normalizeCssPixelLength(value) {
29
+ const parsed = parseUnsignedDecimal(value, true);
30
+ return parsed === null ? null : `${parsed}px`;
31
+ }
32
+ /**
33
+ * Normalize QTI image/object width and height attributes to a positive pixel
34
+ * count without a unit. Callers can safely append `px` in a style value.
35
+ *
36
+ * QTI dimensions use the integer-like HTML width/height attribute shape, so
37
+ * unit-bearing values are rejected. Decimal values remain accepted for
38
+ * compatibility and are emitted in canonical numeric form.
39
+ */
40
+ export function normalizePixelDimension(value, fallback) {
41
+ const parsed = parseUnsignedDecimal(value, false);
42
+ if (parsed !== null && parsed > 0)
43
+ return String(parsed);
44
+ if (fallback === undefined)
45
+ return undefined;
46
+ const parsedFallback = parseUnsignedDecimal(fallback, false);
47
+ return parsedFallback !== null && parsedFallback > 0 ? String(parsedFallback) : undefined;
48
+ }
49
+ //# sourceMappingURL=styleValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styleVal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;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACtC,KAAc,EACd,QAA0B;IAE1B,MAAM,MAAM,GAAG,oBAAoB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAClD,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;IACzD,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAE7C,MAAM,cAAc,GAAG,oBAAoB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC7D,OAAO,cAAc,KAAK,IAAI,IAAI,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3F,CAAC","sourcesContent":["/** A canonical, declaration-safe CSS pixel length. */\nexport type CssPixelLength = `${number}px`;\n\nconst UNSIGNED_DECIMAL = /^(?:\\d+(?:\\.\\d*)?|\\.\\d+)$/;\nconst MAX_AUTHORED_PIXEL_LENGTH = 100_000;\n\nfunction parseUnsignedDecimal(value: unknown, allowPixelSuffix: boolean): number | null {\n\tif (typeof value === 'number') {\n\t\treturn Number.isFinite(value) && value >= 0 ? value : null;\n\t}\n\tif (typeof value !== 'string') return null;\n\n\tlet token = value.trim();\n\tif (allowPixelSuffix && token.toLowerCase().endsWith('px')) {\n\t\ttoken = token.slice(0, -2).trim();\n\t}\n\tif (!UNSIGNED_DECIMAL.test(token)) return null;\n\n\tconst parsed = Number(token);\n\treturn Number.isFinite(parsed) && parsed >= 0 && parsed <= MAX_AUTHORED_PIXEL_LENGTH\n\t\t? parsed\n\t\t: null;\n}\n\n/**\n * Normalize an authored palette width to one complete CSS value.\n *\n * Palette widths are a player extension expressed in pixels. Restricting the\n * grammar to a non-negative decimal with an optional `px` suffix prevents an\n * authored value from terminating the width declaration and introducing a\n * second declaration such as `background-image: url(...)`.\n */\nexport function normalizeCssPixelLength(value: unknown): CssPixelLength | null {\n\tconst parsed = parseUnsignedDecimal(value, true);\n\treturn parsed === null ? null : (`${parsed}px` as CssPixelLength);\n}\n\n/**\n * Normalize QTI image/object width and height attributes to a positive pixel\n * count without a unit. Callers can safely append `px` in a style value.\n *\n * QTI dimensions use the integer-like HTML width/height attribute shape, so\n * unit-bearing values are rejected. Decimal values remain accepted for\n * compatibility and are emitted in canonical numeric form.\n */\nexport function normalizePixelDimension(\n\tvalue: unknown,\n\tfallback?: string | number,\n): string | undefined {\n\tconst parsed = parseUnsignedDecimal(value, false);\n\tif (parsed !== null && parsed > 0) return String(parsed);\n\tif (fallback === undefined) return undefined;\n\n\tconst parsedFallback = parseUnsignedDecimal(fallback, false);\n\treturn parsedFallback !== null && parsedFallback > 0 ? String(parsedFallback) : undefined;\n}\n"]}