@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
package/README.md CHANGED
@@ -1,498 +1,208 @@
1
1
  # @pie-qti/item-player
2
2
 
3
- A modern assessment item player for QTI 2.2 and QTI 3.0 content, with role/view-aware rendering and optional backend scoring support.
3
+ Framework-neutral QTI 2.2/3.0 item compilation, live session state, response processing, and
4
+ render-neutral presentation data.
4
5
 
5
- ## Features
6
+ The primary API has two lifetimes:
6
7
 
7
- - **21 standard interaction extractors** across QTI 2.2/3.0 naming variants; known rendering and conformance gaps are tracked in `docs/SPEC-GAPS-PLAN.md`
8
- - ✅ **QTI Role/View Actors** - candidate, scorer, author, tutor, proctor, testConstructor
9
- - ✅ **Adaptive Items** - Multi-attempt workflow with progressive feedback
10
- - ✅ **Full Keyboard Accessibility** (follows WCAG 2.2 Level AA guidelines)
11
- - ✅ **Client-Side Response Processing** with 45/45 QTI operators
12
- - ✅ **Framework-Agnostic Core** with a **Web Component interaction layer** (default implementations authored in Svelte)
13
- - ✅ **TypeScript** with full type definitions
14
- - **No Svelte dependency for consumers of the framework-agnostic core**
15
- - ✅ **Iframe mode (reference)** - Optional host helper + postMessage protocol for iframe-isolated deployments
8
+ 1. `AssessmentItemDefinition` compiles immutable item XML, security policy, mappings, and plugins.
9
+ 2. `ItemSession` owns one mutable attempt, its variables, lifecycle, responses, and presentation.
16
10
 
17
- > **Security boundary (2026-07-13):** QTI-derived same-DOM sinks, including gap-match prompts and
18
- > section TTS projections, use the shared sanitizer and have executable-markup regression coverage.
19
- > The item custom element enables parsing limits by default. Sanitization is not a JavaScript
20
- > sandbox: for content that is not trusted to run in the host origin, prefer a cross-origin
21
- > sandboxed iframe. See `docs/prds/architecture/security.md` in the repository.
11
+ The implementation engine is private. Browser, assessment, standalone, and server deployments all
12
+ use the definition/session interface.
22
13
 
23
- ## Installation
14
+ ## Install
24
15
 
25
16
  ```bash
26
17
  bun add @pie-qti/item-player
27
18
  ```
28
19
 
29
- Alternatively:
20
+ For the complete browser runtime, prefer `@pie-qti/player-elements`:
30
21
 
31
22
  ```bash
32
- npm install @pie-qti/item-player
23
+ bun add @pie-qti/player-elements
33
24
  ```
34
25
 
35
- ## Quick Start
36
-
37
- ### Web Component Host Integration
38
-
39
- For browser applications, the public rendering boundary is the custom element. The default
40
- interaction implementations are a separate package, so install both packages:
41
-
42
- ```bash
43
- npm install @pie-qti/item-player @pie-qti/default-components
44
- ```
45
-
46
- ```typescript
47
- import '@pie-qti/default-components/plugins';
48
- import '@pie-qti/item-player/element';
49
- ```
50
-
51
- ```html
52
- <pie-qti-item-player item-xml="<assessmentItem ...></assessmentItem>" role="author"></pie-qti-item-player>
26
+ ```ts
27
+ import '@pie-qti/player-elements/register';
53
28
  ```
54
29
 
55
- The package does not require hosts to import Svelte components or install Svelte. Internal Svelte
56
- components are compiled into the custom element bundle. Importing
57
- `@pie-qti/default-components/plugins` is currently required; `@pie-qti/default-components` is not a
58
- dependency of this package.
59
-
60
- ### Core Player (Framework-Agnostic)
30
+ ## Compile a definition and open a session
61
31
 
62
- ```typescript
63
- import { Player } from '@pie-qti/item-player';
32
+ ```ts
33
+ import { createAssessmentItemDefinition } from '@pie-qti/item-player';
64
34
 
65
- // Load QTI XML with role
66
- const qtiXml = `<assessmentItem ...>...</assessmentItem>`;
67
- const player = new Player({
35
+ const definition = createAssessmentItemDefinition({
68
36
  itemXml: qtiXml,
69
- role: 'candidate' // QTI role/view actor
37
+ role: 'candidate',
38
+ security: {
39
+ parsingLimits: { enabled: true, rejectDoctype: true },
40
+ trustedTypesPolicyName: 'qti-content'
41
+ },
42
+ plugins
70
43
  });
71
44
 
72
- // Get interactions
73
- const interactions = player.getInteractions();
74
- // [{ type: 'choiceInteraction', responseIdentifier: 'RESPONSE', element: ... }]
75
-
76
- // Set response
77
- player.setResponse('RESPONSE', 'A');
78
-
79
- // Score the item
80
- const result = player.score();
81
- console.log(result.score); // 0.0 to 1.0
82
- console.log(result.outcomes); // { SCORE: 1.0, ... }
83
- ```
84
-
85
- ### Iframe mode (optional, reference)
86
-
87
- For deployments that need stronger isolation for **untrusted** QTI, you can run the player inside an iframe and communicate via a versioned `postMessage` protocol.
88
-
89
- - Docs: `docs/iframe-mode.md`
90
- - Import: `@pie-qti/item-player/iframe` (browser-only)
91
-
92
- ## QTI Role/View Actors
93
-
94
- QTI roles are primarily audience markers for `view`-controlled content (for example rubric visibility).
95
- This player applies the following runtime behavior policy on top of that:
96
-
97
- | Role | Behavior |
98
- |------|----------|
99
- | `candidate` | Test-taker - inputs editable, no correct answers shown |
100
- | `scorer` | Grader/reviewer - inputs readonly, correct answers shown |
101
- | `author` | Content authoring review - inputs readonly, correct answers shown |
102
- | `tutor` | Instructional review - inputs readonly, correct answers shown |
103
- | `proctor` | Test administration view - inputs readonly, no correct answers shown |
104
- | `testConstructor` | Test construction review - inputs readonly, correct answers shown |
105
-
106
- ### Role-Based Rendering
107
-
108
- ```typescript
109
- // For test-takers (editable inputs)
110
- const player = new Player({
111
- itemXml: qtiXml,
112
- role: 'candidate'
45
+ const session = definition.openSession({
46
+ responses: { RESPONSE: 'A' }
113
47
  });
114
48
 
115
- // For grading/review (readonly, show answers)
116
- const player = new Player({
117
- itemXml: qtiXml,
118
- role: 'scorer'
49
+ const unsubscribe = session.subscribe(({ command, current }) => {
50
+ console.log(command.action, current.revision, current.responses);
119
51
  });
120
52
 
121
- // For instructional use (readonly, show answers)
122
- const player = new Player({
123
- itemXml: qtiXml,
124
- role: 'tutor'
53
+ session.dispatch({
54
+ action: 'setResponse',
55
+ responseIdentifier: 'RESPONSE',
56
+ value: 'B'
125
57
  });
126
- ```
127
-
128
- ## Supported Interaction Types
129
-
130
- | QTI Type | Component | Description |
131
- |----------|-----------|-------------|
132
- | `choiceInteraction` | Built-in | Single/multiple choice |
133
- | `textEntryInteraction` | Built-in | Short text input |
134
- | `extendedTextInteraction` | Built-in | Long-form text (essay) |
135
- | `inlineChoiceInteraction` | `InlineInteractionRenderer` | Dropdown in text |
136
- | `orderInteraction` | `SortableList` | Drag to reorder items |
137
- | `matchInteraction` | `MatchDragDrop` | Match items between sets |
138
- | `associateInteraction` | - | Create associations |
139
- | `gapMatchInteraction` | - | Drag items into text gaps |
140
- | `graphicGapMatchInteraction` | `GraphicGapMatch` | Drag labels onto image hotspots |
141
- | `sliderInteraction` | Built-in | Slider input |
142
- | `hotspotInteraction` | - | Click regions on image |
143
- | `uploadInteraction` | `FileUpload` | Upload a file response |
144
- | `drawingInteraction` | `DrawingCanvas` | Draw/annotate on a canvas |
145
- | `customInteraction` | `CustomInteractionFallback` | Fallback display + optional manual response |
146
-
147
- ## QTI Version Support
148
-
149
- The player supports **QTI 3.0** and **QTI 2.2**, with compatibility support for QTI 2.0/2.1 content:
150
-
151
- - **QTI 3.0**: Supported (kebab-case `qti-` element/attribute forms)
152
- - **QTI 2.2**: Full support (recommended baseline for legacy 2.x ecosystems)
153
- - **QTI 2.1**: Supported with CC2 template aliases (`cc2_match`, `cc2_map_response`, etc.)
154
- - **QTI 2.0**: Limited support - core interactions work, but some features may be unsupported
155
-
156
- ### Version Detection
157
-
158
- The player automatically detects QTI version from:
159
-
160
- 1. Namespace URI (`xmlns="http://www.imsglobal.org/xsd/imsqti_v2pX"`)
161
- 2. Version attribute (`<assessmentItem version="2.X">`)
162
-
163
- Warnings are logged for legacy versions or when version cannot be detected.
164
-
165
- ### Template Processing
166
-
167
- Response processing templates are namespace-agnostic. The player supports:
168
-
169
- - Standard templates: `match_correct`, `map_response`, etc.
170
- - QTI 2.1 CC2 aliases: `cc2_match`, `cc2_map_response`, etc.
171
-
172
- ### Strict Compliance Mode
173
-
174
- For strict QTI 2.2 validation (legacy interoperability mode), enable strict compliance:
175
-
176
- ```typescript
177
- const player = new Player({
178
- itemXml: qtiXml,
179
- strictQtiCompliance: {
180
- enabled: true, // Enable strict QTI 2.2 validation mode
181
- rejectUnknownExtensions: true, // Throw errors on non-2.2 versions
182
- logDeviations: true // Log warnings for spec deviations
183
- }
184
- });
185
- ```
186
-
187
- See [QTI Compliance Documentation](./docs/QTI-COMPLIANCE.md) for details.
188
-
189
- ## Architecture
190
58
 
191
- ### Three-Layer Design
59
+ const presentation = session.present();
60
+ const result = session.dispatch({ action: 'scoreAttempt' }).result?.scoring;
61
+ const saved = session.serialize();
192
62
 
63
+ unsubscribe();
64
+ session.dispose();
193
65
  ```
194
- ┌─────────────────────────────────────────┐
195
- │ Interaction UI (Web Components) │
196
- │ - default implementations authored in │
197
- │ Svelte (`@pie-qti/default-components`) │
198
- └─────────────────────────────────────────┘
199
- ↓
200
- ┌─────────────────────────────────────────┐
201
- │ Extraction │
202
- │ - Player.getInteractionData() │
203
- │ - ExtractionRegistry + extractors │
204
- └─────────────────────────────────────────┘
205
- ↓
206
- ┌─────────────────────────────────────────┐
207
- │ Core Player (Framework-Agnostic) │
208
- │ - XML parsing │
209
- │ - Response processing │
210
- │ - Scoring engine │
211
- │ - Role-based behavior │
212
- └─────────────────────────────────────────┘
213
- ```
214
-
215
- ## API Reference
216
-
217
- ### Player Class
218
-
219
- ```typescript
220
- interface PlayerConfig {
221
- itemXml: string;
222
- role?: QTIRole; // 'candidate' | 'scorer' | 'author' | 'tutor' | 'proctor' | 'testConstructor'
223
- componentRegistry?: ComponentRegistry; // Custom web component registry
224
- extractionRegistry?: ExtractionRegistry; // Custom extractors
225
- plugins?: QTIPlugin[]; // Plugin-based extension point
226
- }
227
-
228
- class Player {
229
- constructor(config: PlayerConfig)
230
66
 
231
- // Get all interactions in the item
232
- getInteractions(): Array<{
233
- type: string;
234
- responseIdentifier: string;
235
- element: HTMLElement;
236
- }>
67
+ `openSession()` accepts an optional serialized `restore` snapshot, response overrides, and
68
+ `activate: true` to resume a suspended handoff as an active session. Response identifiers are
69
+ validated against the compiled declarations.
237
70
 
238
- // Get extracted interaction data (recommended API for UIs)
239
- getInteractionData(): InteractionData[]
71
+ The definition's role is fixed for every session it opens and is visible as `session.state().role`.
72
+ `present()` intentionally does not accept a role override.
240
73
 
241
- // Set a response value
242
- setResponse(identifier: string, value: any): void
74
+ ## Session commands
243
75
 
244
- // Get a response value
245
- getResponse(identifier: string): any
76
+ `ItemSession.dispatch()` is the single mutation boundary:
246
77
 
247
- // Execute response processing and calculate score
248
- score(): {
249
- score: number; // 0.0 to 1.0
250
- outcomes: Record<string, any>;
251
- completed: boolean;
252
- }
253
-
254
- // Get item body HTML
255
- getItemBodyHtml(): string
256
-
257
- // Get rubric blocks for current role
258
- getRubricBlocks(): RubricBlock[]
259
- }
260
- ```
78
+ - `setResponse` and `setResponses` update declared response variables.
79
+ - `updatePnp` applies a partial PNP update.
80
+ - `suspendAttempt` serializes a handoff state.
81
+ - `endAttempt` optionally validates responses and counts an attempt.
82
+ - `scoreAttempt` runs response processing without the adaptive submit guard.
83
+ - `submitAttempt` applies the adaptive attempt workflow.
84
+ - `newTemplate` reruns template processing for a new template instance.
261
85
 
262
- ### Component Props
86
+ Every successful dispatch increments `state().revision` and notifies subscribers with immutable
87
+ previous/current views. Response writes are rejected when the lifecycle is not writable. `dispose()`
88
+ is idempotent. The final `state()` view remains readable with `disposed: true`; later dispatch,
89
+ present, subscribe, and serialize calls are rejected.
263
90
 
264
- #### SortableList
91
+ ## Presentation contract
265
92
 
266
- ```typescript
267
- interface Props {
268
- items: Array<{ id: string; text: string }>;
269
- orderedIds: string[];
270
- orientation?: 'vertical' | 'horizontal';
271
- disabled?: boolean;
272
- onReorder: (newOrder: string[]) => void;
273
- }
274
- ```
93
+ `session.present()` returns an immutable `ItemPresentation` instead of a `Player` adapter:
275
94
 
276
- #### MatchDragDrop
95
+ ```ts
96
+ const presentation = session.present({
97
+ disabled: false,
98
+ renderItemBodyRubrics: true
99
+ });
277
100
 
278
- ```typescript
279
- interface Props {
280
- sourceSet: Array<{ identifier: string; text: string }>;
281
- targetSet: Array<{ identifier: string; text: string }>;
282
- pairs: string[]; // "sourceId targetId"
283
- disabled?: boolean;
284
- onPairsChange: (newPairs: string[]) => void;
101
+ for (const node of presentation.flow) {
102
+ if (node.kind === 'html') renderFinalHtml(node.html);
103
+ else mountInteraction(node.mount);
285
104
  }
286
- ```
287
105
 
288
- #### GraphicGapMatch
289
-
290
- ```typescript
291
- interface Props {
292
- gapTexts: Array<{ identifier: string; text: string; matchMax: number }>;
293
- hotspots: Array<{ identifier: string; shape: string; coords: string; matchMax: number }>;
294
- pairs: string[]; // "gapTextId hotspotId"
295
- imageData: { type: 'svg' | 'image'; content?: string; src?: string; width: string; height: string };
296
- disabled?: boolean;
297
- onPairsChange: (newPairs: string[]) => void;
298
- }
106
+ renderRubrics(presentation.directRubrics);
299
107
  ```
300
108
 
301
- ## Extensibility
302
-
303
- Use plugins/registries (`QTIPlugin`, `ExtractionRegistry`, `ComponentRegistry`) to support vendor extensions or custom rendering.
109
+ The presentation contains role capabilities, disabled state, role-filtered correct responses,
110
+ policy-checked scoped CSS, ordered body flow, and direct `assessmentItem` rubric blocks. HTML values
111
+ use `HtmlContent` (`string | TrustedHTML` when available); `FinalItemBodyHtml` marks content that has
112
+ completed the body transform and delivery pipeline.
304
113
 
305
- **Important**: interaction implementations are treated as **web components** by the player. The player creates elements by tag name and communicates via **standard properties** + the bubbling `qti-change` event. Svelte is an implementation detail of the default component package, not a requirement.
114
+ Section/test-part shared rubrics are not duplicated into item presentation. Assessment and section
115
+ hosts place those through section composition.
306
116
 
307
- For details, see [PLUGGABILITY.md](PLUGGABILITY.md).
117
+ ## Browser element
308
118
 
309
- ## Adaptive Items
119
+ The all-in-one browser package registers `pie-qti-item-player`:
310
120
 
311
- The player fully supports QTI 2.2 adaptive items with multi-attempt workflows:
121
+ ```ts
122
+ import '@pie-qti/player-elements/register';
312
123
 
313
- ### Basic Adaptive Item
314
-
315
- ```typescript
316
- import { Player } from '@pie-qti/item-player';
317
-
318
- const player = new Player({
319
- itemXml: qtiXml, // With adaptive="true"
320
- role: 'candidate'
124
+ const element = document.createElement('pie-qti-item-player');
125
+ element.itemXml = qtiXml;
126
+ element.role = 'candidate';
127
+ element.plugins = plugins;
128
+ element.addEventListener('response-change', (event) => {
129
+ console.log(event.detail.responses);
321
130
  });
322
-
323
- // Check if item is adaptive
324
- if (player.isAdaptive()) {
325
- // Submit first attempt
326
- player.setResponses({ RESPONSE: 'A' });
327
- const result = player.submitAttempt();
328
-
329
- console.log(result.numAttempts); // 1
330
- console.log(result.completionStatus); // 'unknown' or 'completed'
331
- console.log(result.canContinue); // true (if not completed)
332
- console.log(result.modalFeedback); // Progressive feedback/hints
333
-
334
- // Continue submitting until completed
335
- while (!player.isCompleted()) {
336
- player.setResponses({ RESPONSE: nextGuess });
337
- const nextResult = player.submitAttempt();
338
- // Show feedback, allow retry
339
- }
340
- }
131
+ document.body.append(element);
341
132
  ```
342
133
 
343
- ### Hint Buttons (countAttempt="false")
344
-
345
- Adaptive items can have hint buttons that don't increment the attempt counter:
134
+ An orchestrator may inject its exact live session instead of asking the element to create one:
346
135
 
347
- ```xml
348
- <endAttemptInteraction responseIdentifier="HINT"
349
- title="Request Hint"
350
- countAttempt="false"/>
136
+ ```ts
137
+ element.session = session;
351
138
  ```
352
139
 
353
- ```typescript
354
- // Click hint button (doesn't increment attempts)
355
- player.setResponses({ HINT: true });
356
- const hint = player.submitAttempt(false); // Pass false for countAttempt
357
- console.log(hint.numAttempts); // Unchanged
358
- console.log(hint.modalFeedback); // Hint content
359
- ```
360
-
361
- ### Progressive Feedback Example
362
-
363
- ```xml
364
- <assessmentItem identifier="adaptive-item" adaptive="true">
365
- <!-- ... interactions ... -->
366
-
367
- <responseProcessing>
368
- <responseCondition>
369
- <responseIf>
370
- <!-- First attempt: encourage -->
371
- <lt>
372
- <variable identifier="numAttempts"/>
373
- <baseValue baseType="integer">2</baseValue>
374
- </lt>
375
- <setOutcomeValue identifier="FEEDBACK">
376
- <baseValue baseType="identifier">tryagain</baseValue>
377
- </setOutcomeValue>
378
- </responseIf>
379
- <responseElse>
380
- <!-- Second+ attempt: show answer -->
381
- <setOutcomeValue identifier="FEEDBACK">
382
- <baseValue baseType="identifier">answer</baseValue>
383
- </setOutcomeValue>
384
- <setOutcomeValue identifier="completionStatus">
385
- <baseValue baseType="identifier">completed</baseValue>
386
- </setOutcomeValue>
387
- </responseElse>
388
- </responseCondition>
389
- </responseProcessing>
390
-
391
- <modalFeedback outcomeIdentifier="FEEDBACK" identifier="tryagain" showHide="show">
392
- <p>Try again! You have one more attempt.</p>
393
- </modalFeedback>
394
-
395
- <modalFeedback outcomeIdentifier="FEEDBACK" identifier="answer" showHide="show">
396
- <p>The correct answer is C. Here's why...</p>
397
- </modalFeedback>
398
- </assessmentItem>
399
- ```
400
-
401
- ### API Methods
402
-
403
- | Method | Description |
404
- | ---------------------------------------------------------------- | ----------------------------------------- |
405
- | `isAdaptive(): boolean` | Check if item has `adaptive="true"` |
406
- | `isCompleted(): boolean` | Check if `completionStatus="completed"` |
407
- | `getNumAttempts(): number` | Get current attempt count |
408
- | `submitAttempt(countAttempt?: boolean): AdaptiveAttemptResult` | Submit attempt with optional counting |
409
-
410
- For complete documentation, see [ADAPTIVE-ITEMS-DESIGN.md](ADAPTIVE-ITEMS-DESIGN.md).
411
-
412
- ## Accessibility
413
-
414
- All components follow WCAG 2.2 Level AA guidelines:
415
-
416
- - ✅ **Full keyboard navigation** (Tab, Space, Enter, Arrow keys, Escape)
417
- - ✅ **Screen reader support** with ARIA labels and live regions
418
- - ✅ **Focus management** with visible indicators
419
- - ✅ **Alternative to drag-and-drop** for all interactions
420
-
421
- ### Keyboard Shortcuts
422
-
423
- | Component | Keys | Action |
424
- |-----------|------|--------|
425
- | SortableList | Space/Enter | Grab/drop item |
426
- | | Arrow keys | Move grabbed item |
427
- | | Escape | Cancel |
428
- | MatchDragDrop | Space/Enter | Select source |
429
- | | Tab → Space/Enter | Match to target |
430
- | GraphicGapMatch | Space/Enter | Select label |
431
- | | Tab → Space/Enter | Place on hotspot |
432
-
433
- For detailed accessibility analysis, see [WCAG-2.2-COMPLIANCE.md](docs/WCAG-2.2-COMPLIANCE.md).
140
+ `session`, `plugins`, security, PNP, PCI, i18n, processing-fragment resolvers, and response maps are
141
+ JavaScript properties rather than HTML attributes. See
142
+ [`@pie-qti/player-elements`](../player-elements/README.md) for the full element contract.
434
143
 
435
- ## Backend Scoring (Optional)
144
+ The older standalone registration entry remains available when a host intentionally composes the
145
+ interaction implementations itself:
436
146
 
437
- The player supports optional backend scoring for items that require server-side processing:
438
-
439
- ```typescript
440
- // Check if backend scoring is available
441
- if (player.getItemAttribute('adaptive') === 'true') {
442
- // Send to backend for scoring
443
- const response = await fetch('/api/score', {
444
- method: 'POST',
445
- body: JSON.stringify({
446
- itemId: 'item-123',
447
- responses: player.getAllResponses()
448
- })
449
- });
450
-
451
- const result = await response.json();
452
- // Apply backend scores
453
- player.applyOutcomes(result.outcomes);
454
- }
147
+ ```ts
148
+ import '@pie-qti/default-components/plugins';
149
+ import '@pie-qti/item-player/element';
455
150
  ```
456
151
 
457
- For details, see [SERVER-API.md](SERVER-API.md).
152
+ ## Definition plugins
458
153
 
459
- ## Development
154
+ `AssessmentItemDefinitionPlugin` is the primary synchronous extension contract:
460
155
 
461
- ```bash
462
- # Install dependencies
463
- bun install
156
+ ```ts
157
+ import type { AssessmentItemDefinitionPlugin } from '@pie-qti/item-player';
464
158
 
465
- # Build
466
- bun run build
467
-
468
- # Run tests
469
- bun test
470
-
471
- # Type check
472
- bun run typecheck
473
-
474
- # Lint
475
- bun run lint
159
+ export const plugin: AssessmentItemDefinitionPlugin = {
160
+ kind: 'assessment-item-definition-plugin',
161
+ name: '@vendor/interactions',
162
+ version: '1.0.0',
163
+ registerExtractors(registry) {
164
+ registry.register(vendorExtractor);
165
+ },
166
+ registerComponents(registry) {
167
+ registry.register('vendorInteraction', {
168
+ name: 'vendor-interaction',
169
+ tagName: 'vendor-qti-interaction'
170
+ });
171
+ }
172
+ };
476
173
  ```
477
174
 
478
- ## License
175
+ Definition creation registers standard modules and plugins, then seals the registries before a
176
+ session opens. Plugin extractors declare renderer identity with `outputType` and declare all HTML and
177
+ resource URL fields with a `delivery` schema. See
178
+ [Custom extractors](./docs/custom-extractors.md).
179
+
180
+ ## Security boundary
479
181
 
480
- ISC
182
+ The player applies configured HTML sanitation, URL policy, parsing limits, and optional Trusted
183
+ Types finalization to declared delivery fields. Plugins are trusted executable application code and
184
+ are not sandboxed. Sanitized same-DOM content is still not equivalent to isolating untrusted
185
+ JavaScript; use a suitably sandboxed cross-origin iframe when content is not trusted to run in the
186
+ host origin.
481
187
 
482
- ## Related Packages
188
+ Portable Custom Interaction execution is disabled unless the host supplies a trusted
189
+ `pci.moduleResolver`. Authored module paths are never imported directly by default.
483
190
 
484
- - [@pie-qti/assessment-player](../assessment-player) - Multi-item test player
485
- - [@pie-qti/player-elements](../player-elements) - Web components
486
- - [@pie-qti/app-demo](../../apps/demo) - Demo application
487
- - [@pie-qti/to-pie](../to-pie) - QTI to PIE transformer
191
+ ## Server scoring
488
192
 
489
- ## Contributing
193
+ `@pie-qti/item-player/server` exports a DOM-free definition/session interface with the same ownership
194
+ model. It omits presentation, PNP DOM, PCI, catalogs, and browser component types. See the
195
+ [server scoring guide](./docs/server-api.md).
490
196
 
491
- Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
197
+ ## Public entries
492
198
 
493
- ## Resources
199
+ - `@pie-qti/item-player`: definitions, sessions, presentation/extraction/plugin contracts, security
200
+ types, PNP/catalog/PCI helpers.
201
+ - `@pie-qti/item-player/server`: DOM-free definitions, sessions, scoring commands, and persistence.
202
+ - `@pie-qti/item-player/web-components`: interaction element base contracts.
203
+ - `@pie-qti/item-player/element` and `/element-class`: standalone browser element compatibility.
204
+ - `@pie-qti/item-player/iframe`: optional iframe host/protocol helpers.
205
+ - `@pie-qti/item-player/security`: security utilities.
494
206
 
495
- - [QTI 3.0 Specification](https://www.imsglobal.org/spec/qti/v3p0/)
496
- - [QTI 2.2.2 Final](https://www.imsglobal.org/content/question-and-test-interoperability-v222-final)
497
- - [WCAG 2.1 Guidelines](https://www.w3.org/WAI/WCAG21/quickref/)
498
- - [PIE Framework](https://github.com/pie-framework)
207
+ Additional detail: [QTI compliance](./docs/QTI-COMPLIANCE.md),
208
+ [server scoring](./docs/server-api.md), and [iframe mode](./docs/iframe-mode.md).
@@ -1,4 +1,5 @@
1
1
  import type { PnpProfile } from '../pnp/types.js';
2
+ import type { HtmlContent } from '../types/index.js';
2
3
  interface CatalogComponentRegistry {
3
4
  getTagNameForType(type: string): string | null;
4
5
  }
@@ -6,7 +7,7 @@ export interface GlossaryPlayer {
6
7
  getPnp(): PnpProfile | undefined;
7
8
  getCatalogEntry(idref: string, usage: string, lang?: string, options?: {
8
9
  stimulusIdentifier?: string;
9
- }): string | null;
10
+ }): HtmlContent | null;
10
11
  getComponentRegistry(): CatalogComponentRegistry;
11
12
  }
12
13
  /**
@@ -1,3 +1,4 @@
1
+ import { htmlToString } from '../core/trustedTypes.js';
1
2
  const PLATFORM_USAGES = [
2
3
  { usage: 'tts-pronunciation', flag: 'ttsPronunciation', label: 'Request pronunciation', text: 'P' },
3
4
  { usage: 'signing-definition', flag: 'signingDefinition', label: 'Request signing definition', text: 'S' },
@@ -261,10 +262,11 @@ function buildFallbackPopup(label, html, close) {
261
262
  header.appendChild(closeBtn);
262
263
  const body = document.createElement('div');
263
264
  body.className = 'card-body p-3';
264
- const isUrl = /^(https?:\/\/|\/)/i.test(html.trim());
265
+ const htmlString = htmlToString(html);
266
+ const isUrl = /^(https?:\/\/|\/)/i.test(htmlString.trim());
265
267
  if (isUrl) {
266
268
  const img = document.createElement('img');
267
- img.src = html.trim();
269
+ img.src = htmlString.trim();
268
270
  img.alt = label;
269
271
  img.className = 'max-w-full h-auto block mx-auto';
270
272
  body.appendChild(img);