@pie-qti/item-player 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/README.md +17 -0
  2. package/dist/catalog/applyGlossaryTriggers.d.ts +13 -2
  3. package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
  4. package/dist/catalog/glossaryAction.d.ts +4 -2
  5. package/dist/catalog/glossaryAction.d.ts.map +1 -1
  6. package/dist/components/utils/index.d.ts +1 -2
  7. package/dist/components/utils/index.d.ts.map +1 -1
  8. package/dist/components/utils/index.js +1 -2
  9. package/dist/core/ComponentRegistry.d.ts +10 -1
  10. package/dist/core/ComponentRegistry.d.ts.map +1 -1
  11. package/dist/core/ComponentRegistry.js +42 -1
  12. package/dist/core/Player.d.ts +10 -2
  13. package/dist/core/Player.d.ts.map +1 -1
  14. package/dist/core/Player.js +54 -46
  15. package/dist/document/AssessmentItemDocument.d.ts +1 -1
  16. package/dist/element.d.ts +15 -0
  17. package/dist/element.js +1817 -1625
  18. package/dist/element.js.map +1 -1
  19. package/dist/extraction/ExtractionRegistry.d.ts +1 -1
  20. package/dist/extraction/createContext.d.ts +1 -1
  21. package/dist/extraction/index.d.ts +2 -2
  22. package/dist/extraction/index.d.ts.map +1 -1
  23. package/dist/extraction/index.js +1 -1
  24. package/dist/extraction/interactionExtractionPipeline.d.ts +1 -1
  25. package/dist/extraction/interactionSecurity.d.ts +1 -1
  26. package/dist/extraction/types.d.ts +1 -1
  27. package/dist/presentation/itemPresentationPlan.d.ts +54 -0
  28. package/dist/presentation/itemPresentationPlan.d.ts.map +1 -0
  29. package/dist/presentation/itemPresentationPlan.js +98 -0
  30. package/dist/types/index.d.ts +17 -2
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/index.js +0 -3
  33. package/dist/web-components/QTIInteractionBase.d.ts +1 -1
  34. package/dist/web-components/QTIInteractionElement.d.ts +1 -1
  35. package/package.json +7 -14
  36. package/src/__tests__/catalog.test.ts +0 -267
  37. package/src/__tests__/fixtures/pci/echo-pci.js +0 -49
  38. package/src/__tests__/pci.test.ts +0 -353
  39. package/src/__tests__/qti3-attribute-extraction.test.ts +0 -174
  40. package/src/__tests__/qti3-debug.test.ts +0 -140
  41. package/src/__tests__/qti3-extraction.test.ts +0 -309
  42. package/src/catalog/applyGlossaryTriggers.ts +0 -372
  43. package/src/catalog/catalogExtractor.ts +0 -130
  44. package/src/catalog/catalogLookup.ts +0 -53
  45. package/src/catalog/glossaryAction.ts +0 -38
  46. package/src/catalog/types.ts +0 -37
  47. package/src/components/ItemBody.svelte +0 -363
  48. package/src/components/ItemPlayer.svelte +0 -163
  49. package/src/components/ModalFeedbackDisplay.svelte +0 -97
  50. package/src/components/actions/typesetAction.ts +0 -74
  51. package/src/components/index.ts +0 -22
  52. package/src/components/utils/assignProps.ts +0 -2
  53. package/src/components/utils/feedbackUtils.ts +0 -140
  54. package/src/components/utils/index.ts +0 -13
  55. package/src/components/utils/stimulusRender.ts +0 -93
  56. package/src/components/utils/stylesheetRender.ts +0 -58
  57. package/src/core/ComponentRegistry.ts +0 -248
  58. package/src/core/Player.ts +0 -1618
  59. package/src/core/Plugin.ts +0 -123
  60. package/src/core/PluginManager.ts +0 -182
  61. package/src/core/constants.ts +0 -117
  62. package/src/core/declarations.ts +0 -171
  63. package/src/core/parsingLimits.ts +0 -62
  64. package/src/core/random.ts +0 -24
  65. package/src/core/rolePolicy.ts +0 -34
  66. package/src/core/sanitizer.ts +0 -305
  67. package/src/core/trustedTypes.ts +0 -63
  68. package/src/core/urlPolicy.ts +0 -98
  69. package/src/document/AssessmentItemDocument.ts +0 -247
  70. package/src/element.ts +0 -128
  71. package/src/extensions/MathLiveEditor.ts +0 -313
  72. package/src/extraction/ExtractionRegistry.ts +0 -335
  73. package/src/extraction/createContext.ts +0 -52
  74. package/src/extraction/extractors/associateExtractor.ts +0 -1
  75. package/src/extraction/extractors/choiceExtractor.ts +0 -1
  76. package/src/extraction/extractors/conformance-qti3-advanced.test.ts +0 -239
  77. package/src/extraction/extractors/conformance-qti3-basic.test.ts +0 -82
  78. package/src/extraction/extractors/conformance.test.ts +0 -208
  79. package/src/extraction/extractors/customExtractor.ts +0 -1
  80. package/src/extraction/extractors/drawingExtractor.ts +0 -1
  81. package/src/extraction/extractors/endAttemptExtractor.ts +0 -1
  82. package/src/extraction/extractors/extendedTextExtractor.ts +0 -1
  83. package/src/extraction/extractors/gapMatchExtractor.ts +0 -1
  84. package/src/extraction/extractors/graphicAssociateExtractor.ts +0 -1
  85. package/src/extraction/extractors/graphicGapMatchExtractor.ts +0 -1
  86. package/src/extraction/extractors/graphicOrderExtractor.ts +0 -1
  87. package/src/extraction/extractors/hotspotExtractor.ts +0 -1
  88. package/src/extraction/extractors/hottextExtractor.ts +0 -1
  89. package/src/extraction/extractors/index.ts +0 -9
  90. package/src/extraction/extractors/inlineChoiceExtractor.ts +0 -1
  91. package/src/extraction/extractors/matchExtractor.ts +0 -1
  92. package/src/extraction/extractors/mediaExtractor.ts +0 -1
  93. package/src/extraction/extractors/orderExtractor.ts +0 -1
  94. package/src/extraction/extractors/portableCustomExtractor.ts +0 -1
  95. package/src/extraction/extractors/positionObjectExtractor.ts +0 -1
  96. package/src/extraction/extractors/selectPointExtractor.ts +0 -1
  97. package/src/extraction/extractors/sliderExtractor.ts +0 -1
  98. package/src/extraction/extractors/textEntryExtractor.ts +0 -1
  99. package/src/extraction/extractors/uploadExtractor.ts +0 -1
  100. package/src/extraction/index.ts +0 -108
  101. package/src/extraction/interactionExtractionPipeline.ts +0 -70
  102. package/src/extraction/interactionSecurity.ts +0 -60
  103. package/src/extraction/types.ts +0 -246
  104. package/src/extraction/utils.ts +0 -243
  105. package/src/iframe/IFramePlayerHost.ts +0 -265
  106. package/src/iframe/index.ts +0 -11
  107. package/src/iframe/protocol.ts +0 -137
  108. package/src/index.ts +0 -101
  109. package/src/interactions/associate/extractor.ts +0 -133
  110. package/src/interactions/associate/index.ts +0 -2
  111. package/src/interactions/associate/types.ts +0 -1
  112. package/src/interactions/choice/extractor.ts +0 -121
  113. package/src/interactions/choice/index.ts +0 -2
  114. package/src/interactions/choice/types.ts +0 -1
  115. package/src/interactions/custom/extractor.ts +0 -72
  116. package/src/interactions/custom/index.ts +0 -2
  117. package/src/interactions/custom/types.ts +0 -1
  118. package/src/interactions/drawing/extractor.ts +0 -113
  119. package/src/interactions/drawing/index.ts +0 -2
  120. package/src/interactions/drawing/types.ts +0 -1
  121. package/src/interactions/end-attempt/extractor.ts +0 -74
  122. package/src/interactions/end-attempt/index.ts +0 -2
  123. package/src/interactions/end-attempt/types.ts +0 -1
  124. package/src/interactions/extended-text/extractor.ts +0 -92
  125. package/src/interactions/extended-text/index.ts +0 -2
  126. package/src/interactions/extended-text/types.ts +0 -1
  127. package/src/interactions/gap-match/extractor.ts +0 -193
  128. package/src/interactions/gap-match/index.ts +0 -2
  129. package/src/interactions/gap-match/types.ts +0 -1
  130. package/src/interactions/graphic-associate/extractor.ts +0 -192
  131. package/src/interactions/graphic-associate/index.ts +0 -2
  132. package/src/interactions/graphic-associate/types.ts +0 -1
  133. package/src/interactions/graphic-gap-match/extractor.ts +0 -257
  134. package/src/interactions/graphic-gap-match/index.ts +0 -2
  135. package/src/interactions/graphic-gap-match/types.ts +0 -1
  136. package/src/interactions/graphic-order/extractor.ts +0 -162
  137. package/src/interactions/graphic-order/index.ts +0 -2
  138. package/src/interactions/graphic-order/types.ts +0 -1
  139. package/src/interactions/hotspot/extractor.ts +0 -208
  140. package/src/interactions/hotspot/index.ts +0 -2
  141. package/src/interactions/hotspot/types.ts +0 -1
  142. package/src/interactions/hottext/extractor.ts +0 -163
  143. package/src/interactions/hottext/index.ts +0 -2
  144. package/src/interactions/hottext/types.ts +0 -1
  145. package/src/interactions/index.ts +0 -52
  146. package/src/interactions/inline/index.ts +0 -1
  147. package/src/interactions/inline/render-plan.ts +0 -105
  148. package/src/interactions/inline-choice/InlineChoice.svelte +0 -57
  149. package/src/interactions/inline-choice/extractor.ts +0 -105
  150. package/src/interactions/inline-choice/index.ts +0 -2
  151. package/src/interactions/inline-choice/types.ts +0 -1
  152. package/src/interactions/match/extractor.ts +0 -187
  153. package/src/interactions/match/index.ts +0 -2
  154. package/src/interactions/match/types.ts +0 -1
  155. package/src/interactions/media/extractor.ts +0 -168
  156. package/src/interactions/media/index.ts +0 -2
  157. package/src/interactions/media/types.ts +0 -1
  158. package/src/interactions/modules.ts +0 -111
  159. package/src/interactions/order/extractor.ts +0 -120
  160. package/src/interactions/order/index.ts +0 -2
  161. package/src/interactions/order/types.ts +0 -1
  162. package/src/interactions/portable-custom/extractor.ts +0 -122
  163. package/src/interactions/portable-custom/index.ts +0 -2
  164. package/src/interactions/portable-custom/types.ts +0 -1
  165. package/src/interactions/position-object/extractor.ts +0 -243
  166. package/src/interactions/position-object/index.ts +0 -2
  167. package/src/interactions/position-object/types.ts +0 -1
  168. package/src/interactions/select-point/extractor.ts +0 -143
  169. package/src/interactions/select-point/index.ts +0 -2
  170. package/src/interactions/select-point/types.ts +0 -1
  171. package/src/interactions/shared/index.ts +0 -1
  172. package/src/interactions/shared/types.ts +0 -430
  173. package/src/interactions/slider/extractor.ts +0 -102
  174. package/src/interactions/slider/index.ts +0 -2
  175. package/src/interactions/slider/types.ts +0 -1
  176. package/src/interactions/text-entry/InlineTextEntry.svelte +0 -75
  177. package/src/interactions/text-entry/extractor.ts +0 -79
  178. package/src/interactions/text-entry/index.ts +0 -2
  179. package/src/interactions/text-entry/types.ts +0 -1
  180. package/src/interactions/upload/extractor.ts +0 -81
  181. package/src/interactions/upload/index.ts +0 -2
  182. package/src/interactions/upload/types.ts +0 -1
  183. package/src/pci/PciHost.ts +0 -138
  184. package/src/pci/types.ts +0 -70
  185. package/src/pnp/applyPnp.ts +0 -29
  186. package/src/pnp/parsePnpXml.ts +0 -215
  187. package/src/pnp/types.ts +0 -75
  188. package/src/server.ts +0 -14
  189. package/src/types/index.ts +0 -388
  190. package/src/types/interactions.ts +0 -8
  191. package/src/types/responseValidation.ts +0 -29
  192. package/src/types/xmldom.d.ts +0 -12
  193. package/src/utils/PerformanceMonitor.ts +0 -335
  194. package/src/utils/drawingUtils.ts +0 -73
  195. package/src/utils/responseUtils.ts +0 -51
  196. package/src/utils/touchDragHelper.ts +0 -1
  197. package/src/web-components/QTIInteractionBase.ts +0 -303
  198. package/src/web-components/QTIInteractionElement.ts +0 -125
  199. package/src/web-components/index.ts +0 -22
@@ -1,265 +0,0 @@
1
- /**
2
- * Browser-only iframe host helper.
3
- *
4
- * This intentionally depends on DOM globals and must be imported via the subpath:
5
- * - `@pie-qti/item-player/iframe`
6
- *
7
- * Do NOT export from the main entrypoint to keep SSR safe.
8
- */
9
-
10
- import type { PlayerSecurityConfig, QTIRole } from '../types/index.js';
11
- import {
12
- createEnvelope,
13
- parseQtiIframeMessage,
14
- type QtiIframeEnvelope,
15
- type QtiIframeInitPayload,
16
- type QtiIframeMessage,
17
- type QtiIframeMessageType,
18
- type QtiIframeProtocolVersion,
19
- } from './protocol.js';
20
-
21
- export interface IFramePlayerHostConfig {
22
- /**
23
- * The URL to load inside the iframe (the integrator-hosted runtime page).
24
- * For best isolation, host this on a separate origin.
25
- */
26
- iframeUrl: string;
27
-
28
- /**
29
- * Allowed runtime origins. Incoming messages from other origins are ignored.
30
- *
31
- * Examples:
32
- * - `['https://player-runtime.example']`
33
- * - `['http://localhost:5173']`
34
- */
35
- allowedOrigins: string[];
36
-
37
- /**
38
- * Either provide an existing iframe, or provide a container and the host will create one.
39
- */
40
- iframe?: HTMLIFrameElement;
41
- container?: HTMLElement;
42
-
43
- /**
44
- * Sandbox attribute value. If not provided, defaults to a safe baseline.
45
- *
46
- * Default: `allow-scripts` (no allow-same-origin).
47
- */
48
- sandbox?: string;
49
-
50
- /**
51
- * When true, automatically sets `iframe.style.height` on RESIZE messages.
52
- * Default: true.
53
- */
54
- autoResize?: boolean;
55
-
56
- /**
57
- * Default: `no-referrer` to reduce leakage when loading assets.
58
- */
59
- referrerPolicy?: HTMLIFrameElement['referrerPolicy'];
60
-
61
- /**
62
- * Milliseconds to wait for READY before rejecting init/commands.
63
- * Default: 10s.
64
- */
65
- readyTimeoutMs?: number;
66
- }
67
-
68
- export type IFramePlayerHostEvent =
69
- | { type: 'ready'; payload: { origin: string; version: QtiIframeProtocolVersion } }
70
- | { type: 'resize'; payload: { height: number } }
71
- | { type: 'responseChange'; payload: { responses: Record<string, unknown> } }
72
- | { type: 'submitResult'; payload: { result: unknown } }
73
- | { type: 'error'; payload: { message: string; code?: string; details?: unknown } };
74
-
75
- export class IFramePlayerHost {
76
- private readonly config: IFramePlayerHostConfig;
77
- private readonly iframe: HTMLIFrameElement;
78
- private readonly pendingReady: Promise<{ origin: string; version: QtiIframeProtocolVersion }>;
79
- private resolveReady!: (value: { origin: string; version: QtiIframeProtocolVersion }) => void;
80
- private rejectReady!: (reason?: unknown) => void;
81
- private lockedOrigin: string | null = null;
82
- private destroyed = false;
83
- private readonly listeners = new Set<(event: IFramePlayerHostEvent) => void>();
84
- private readonly onMessageBound = (event: MessageEvent) => this.onMessage(event);
85
-
86
- constructor(config: IFramePlayerHostConfig) {
87
- this.config = config;
88
-
89
- if (!config.iframe && !config.container) {
90
- throw new Error('IFramePlayerHost requires either `iframe` or `container`.');
91
- }
92
- if (config.allowedOrigins.length === 0) {
93
- throw new Error('IFramePlayerHost requires at least one allowed origin.');
94
- }
95
-
96
- this.iframe = config.iframe ?? document.createElement('iframe');
97
- if (!config.iframe) {
98
- config.container!.appendChild(this.iframe);
99
- }
100
-
101
- this.iframe.src = config.iframeUrl;
102
- this.iframe.sandbox.value = config.sandbox ?? 'allow-scripts';
103
- this.iframe.referrerPolicy = config.referrerPolicy ?? 'no-referrer';
104
- this.iframe.style.width = '100%';
105
- this.iframe.style.border = '0';
106
-
107
- this.pendingReady = new Promise((resolve, reject) => {
108
- this.resolveReady = resolve;
109
- this.rejectReady = reject;
110
- });
111
-
112
- window.addEventListener('message', this.onMessageBound);
113
-
114
- const timeoutMs = config.readyTimeoutMs ?? 10_000;
115
- window.setTimeout(() => {
116
- if (this.destroyed) return;
117
- if (this.lockedOrigin) return;
118
- this.rejectReady(new Error(`Timed out waiting for iframe READY after ${timeoutMs}ms`));
119
- }, timeoutMs);
120
- }
121
-
122
- /**
123
- * Subscribe to host events.
124
- * Returns an unsubscribe function.
125
- */
126
- on(listener: (event: IFramePlayerHostEvent) => void): () => void {
127
- this.listeners.add(listener);
128
- return () => this.listeners.delete(listener);
129
- }
130
-
131
- private emit(event: IFramePlayerHostEvent): void {
132
- for (const listener of this.listeners) listener(event);
133
- }
134
-
135
- getIFrameElement(): HTMLIFrameElement {
136
- return this.iframe;
137
- }
138
-
139
- /**
140
- * Resolves once the runtime has sent READY and origin is locked.
141
- */
142
- ready(): Promise<{ origin: string; version: QtiIframeProtocolVersion }> {
143
- return this.pendingReady;
144
- }
145
-
146
- async init(params: {
147
- itemXml: string;
148
- role?: QTIRole;
149
- seed?: number;
150
- security?: PlayerSecurityConfig;
151
- responses?: Record<string, unknown>;
152
- runtimeConfig?: Record<string, unknown>;
153
- }): Promise<void> {
154
- await this.ready();
155
- const payload: QtiIframeInitPayload = {
156
- itemXml: params.itemXml,
157
- role: params.role,
158
- seed: params.seed,
159
- security: params.security,
160
- responses: params.responses,
161
- runtimeConfig: params.runtimeConfig,
162
- };
163
- this.post('INIT', payload);
164
- }
165
-
166
- async setResponses(responses: Record<string, unknown>): Promise<void> {
167
- await this.ready();
168
- this.post('SET_RESPONSES', { responses });
169
- }
170
-
171
- async submit(): Promise<void> {
172
- await this.ready();
173
- this.post('SUBMIT', {});
174
- }
175
-
176
- async reset(): Promise<void> {
177
- await this.ready();
178
- this.post('RESET', {});
179
- }
180
-
181
- destroy(): void {
182
- if (this.destroyed) return;
183
- this.destroyed = true;
184
- window.removeEventListener('message', this.onMessageBound);
185
- this.listeners.clear();
186
- }
187
-
188
- private post<TType extends QtiIframeMessageType, TPayload>(type: TType, payload: TPayload): void {
189
- const targetWindow = this.iframe.contentWindow;
190
- if (!targetWindow) return;
191
-
192
- const envelope = createEnvelope(type, payload);
193
- const origin = this.lockedOrigin ?? '*';
194
- targetWindow.postMessage(envelope satisfies QtiIframeEnvelope, origin);
195
- }
196
-
197
- private onMessage(event: MessageEvent): void {
198
- if (this.destroyed) return;
199
- if (!this.isAllowedOrigin(event.origin)) return;
200
- // Only accept messages from the intended iframe window.
201
- // This prevents other frames (even on an allowed origin) from spoofing protocol messages.
202
- if (!this.iframe.contentWindow || event.source !== this.iframe.contentWindow) return;
203
-
204
- const msg = parseQtiIframeMessage(event.data);
205
- if (!msg) return;
206
-
207
- // Lock the origin on first valid protocol message (ideally READY)
208
- if (!this.lockedOrigin) {
209
- this.lockedOrigin = event.origin;
210
- }
211
- if (event.origin !== this.lockedOrigin) return;
212
-
213
- this.handleMessage(msg, event.origin);
214
- }
215
-
216
- private isAllowedOrigin(origin: string): boolean {
217
- return this.config.allowedOrigins.includes(origin);
218
- }
219
-
220
- private handleMessage(msg: QtiIframeMessage, origin: string): void {
221
- switch (msg.type) {
222
- case 'READY': {
223
- this.resolveReady({ origin, version: msg.payload.version });
224
- this.emit({ type: 'ready', payload: { origin, version: msg.payload.version } });
225
- return;
226
- }
227
- case 'RESIZE': {
228
- const height = (msg.payload as any)?.height;
229
- if (typeof height === 'number' && Number.isFinite(height) && height >= 0) {
230
- if (this.config.autoResize ?? true) {
231
- this.iframe.style.height = `${height}px`;
232
- }
233
- this.emit({ type: 'resize', payload: { height } });
234
- }
235
- return;
236
- }
237
- case 'RESPONSE_CHANGE': {
238
- const responses = (msg.payload as any)?.responses;
239
- if (responses && typeof responses === 'object') {
240
- this.emit({ type: 'responseChange', payload: { responses } });
241
- }
242
- return;
243
- }
244
- case 'SUBMIT_RESULT': {
245
- this.emit({ type: 'submitResult', payload: { result: (msg.payload as any)?.result } });
246
- return;
247
- }
248
- case 'ERROR': {
249
- this.emit({
250
- type: 'error',
251
- payload: {
252
- message: (msg.payload as any)?.message ?? 'Unknown iframe runtime error',
253
- code: (msg.payload as any)?.code,
254
- details: (msg.payload as any)?.details,
255
- },
256
- });
257
- return;
258
- }
259
- default:
260
- return;
261
- }
262
- }
263
- }
264
-
265
-
@@ -1,11 +0,0 @@
1
- /**
2
- * Browser-only iframe mode exports.
3
- *
4
- * Import via:
5
- * - `@pie-qti/item-player/iframe`
6
- */
7
-
8
- export * from './IFramePlayerHost.js';
9
- export * from './protocol.js';
10
-
11
-
@@ -1,137 +0,0 @@
1
- /**
2
- * item-player iframe mode protocol (reference)
3
- *
4
- * This module defines a versioned postMessage envelope and minimal runtime validators.
5
- * It intentionally contains NO DOM globals, so it can be imported in any environment.
6
- *
7
- * IMPORTANT: This protocol is a contract between:
8
- * - a host application (embedding an iframe)
9
- * - a player runtime hosted inside that iframe
10
- *
11
- * The project ships a host helper to reduce mistakes, and the example app provides a
12
- * reference runtime implementation. Production runtimes are integrator-owned.
13
- */
14
-
15
- import type { PlayerSecurityConfig, QTIRole } from '../types/index.js';
16
-
17
- export const QTI_IFRAME_PROTOCOL = 'pie-qti-iframe' as const;
18
- export const QTI_IFRAME_PROTOCOL_VERSION = '0.1.0' as const;
19
-
20
- export type QtiIframeProtocol = typeof QTI_IFRAME_PROTOCOL;
21
- export type QtiIframeProtocolVersion = typeof QTI_IFRAME_PROTOCOL_VERSION;
22
-
23
- export type QtiIframeMessageType =
24
- | 'READY'
25
- | 'INIT'
26
- | 'SET_RESPONSES'
27
- | 'SUBMIT'
28
- | 'RESET'
29
- | 'RESIZE'
30
- | 'RESPONSE_CHANGE'
31
- | 'SUBMIT_RESULT'
32
- | 'ERROR';
33
-
34
- export interface QtiIframeEnvelope<TType extends QtiIframeMessageType = QtiIframeMessageType, TPayload = unknown> {
35
- protocol: QtiIframeProtocol;
36
- version: QtiIframeProtocolVersion;
37
- /** Correlates request/response pairs. Optional for one-way notifications. */
38
- requestId?: string;
39
- type: TType;
40
- payload: TPayload;
41
- }
42
-
43
- export interface QtiIframeReadyPayload {
44
- /** Optional human-readable runtime identifier (for debugging) */
45
- runtime?: string;
46
- /** Runtime protocol version (echo) */
47
- version: QtiIframeProtocolVersion;
48
- }
49
-
50
- export interface QtiIframeInitPayload {
51
- itemXml: string;
52
- role?: QTIRole;
53
- seed?: number;
54
- security?: PlayerSecurityConfig;
55
- /** Optional initial responses */
56
- responses?: Record<string, unknown>;
57
- /**
58
- * Optional opaque config for the runtime (integrator-defined).
59
- * Must be structured-cloneable.
60
- */
61
- runtimeConfig?: Record<string, unknown>;
62
- }
63
-
64
- export interface QtiIframeSetResponsesPayload {
65
- responses: Record<string, unknown>;
66
- }
67
-
68
- export interface QtiIframeResizePayload {
69
- height: number;
70
- }
71
-
72
- export interface QtiIframeResponseChangePayload {
73
- responses: Record<string, unknown>;
74
- }
75
-
76
- export interface QtiIframeSubmitResultPayload {
77
- result: unknown;
78
- }
79
-
80
- export interface QtiIframeErrorPayload {
81
- message: string;
82
- code?: string;
83
- details?: unknown;
84
- }
85
-
86
- export type QtiIframeMessage =
87
- | QtiIframeEnvelope<'READY', QtiIframeReadyPayload>
88
- | QtiIframeEnvelope<'INIT', QtiIframeInitPayload>
89
- | QtiIframeEnvelope<'SET_RESPONSES', QtiIframeSetResponsesPayload>
90
- | QtiIframeEnvelope<'SUBMIT', Record<string, never>>
91
- | QtiIframeEnvelope<'RESET', Record<string, never>>
92
- | QtiIframeEnvelope<'RESIZE', QtiIframeResizePayload>
93
- | QtiIframeEnvelope<'RESPONSE_CHANGE', QtiIframeResponseChangePayload>
94
- | QtiIframeEnvelope<'SUBMIT_RESULT', QtiIframeSubmitResultPayload>
95
- | QtiIframeEnvelope<'ERROR', QtiIframeErrorPayload>;
96
-
97
- export function createEnvelope<TType extends QtiIframeMessageType, TPayload>(
98
- type: TType,
99
- payload: TPayload,
100
- opts?: { requestId?: string; version?: QtiIframeProtocolVersion }
101
- ): QtiIframeEnvelope<TType, TPayload> {
102
- return {
103
- protocol: QTI_IFRAME_PROTOCOL,
104
- version: opts?.version ?? QTI_IFRAME_PROTOCOL_VERSION,
105
- requestId: opts?.requestId,
106
- type,
107
- payload,
108
- };
109
- }
110
-
111
- function isRecord(value: unknown): value is Record<string, unknown> {
112
- return typeof value === 'object' && value !== null;
113
- }
114
-
115
- export function isQtiIframeEnvelope(value: unknown): value is QtiIframeEnvelope {
116
- if (!isRecord(value)) return false;
117
- if (value.protocol !== QTI_IFRAME_PROTOCOL) return false;
118
- if (value.version !== QTI_IFRAME_PROTOCOL_VERSION) return false;
119
- if (typeof value.type !== 'string') return false;
120
- if (!('payload' in value)) return false;
121
- if ('requestId' in value && value.requestId !== undefined && typeof value.requestId !== 'string') return false;
122
- return true;
123
- }
124
-
125
- /**
126
- * Parse and validate an incoming postMessage `event.data`.
127
- * Returns `null` if the message is not for this protocol/version.
128
- */
129
- export function parseQtiIframeMessage(value: unknown): QtiIframeMessage | null {
130
- if (!isQtiIframeEnvelope(value)) return null;
131
-
132
- // We intentionally do only shallow validation here to keep the protocol evolvable.
133
- // Runtimes/hosts should still validate payload fields for safety.
134
- return value as QtiIframeMessage;
135
- }
136
-
137
-
package/src/index.ts DELETED
@@ -1,101 +0,0 @@
1
- /**
2
- * @pie-qti/item-player
3
- * Modern QTI player (2.2/3.0) - Framework-agnostic with web components
4
- */
5
-
6
-
7
- // Export web component registry for pluggable UI components
8
- export {
9
- type ComponentConfig,
10
- type ComponentPlugin,
11
- ComponentRegistry,
12
- createComponentRegistry,
13
- } from './core/ComponentRegistry.js';
14
- export * from './core/constants.js';
15
- export * from './core/declarations.js';
16
- // Export drawing utilities
17
- export * from './utils/drawingUtils.js';
18
- export { Player } from './core/Player.js';
19
- export { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';
20
- // Plugin system (new extraction-based plugins)
21
- export {
22
- type PluginContext,
23
- type PluginLifecycle,
24
- type QTIPlugin,
25
- type RenderContext,
26
- } from './core/Plugin.js';
27
- export { PluginManager } from './core/PluginManager.js';
28
- // Export extraction system (PUBLIC API)
29
- export * from './interactions/index.js';
30
- export type {
31
- ElementExtractor,
32
- ExtractionContext,
33
- ExtractionResult,
34
- ExtractionUtils,
35
- ValidationResult,
36
- VariableDeclaration,
37
- } from './extraction/index.js';
38
- export {
39
- createExtractionContext,
40
- createExtractionRegistry,
41
- createExtractionUtils,
42
- ExtractionError,
43
- ExtractionRegistry,
44
- isErrorResult,
45
- isSuccessResult,
46
- } from './extraction/index.js';
47
- // NOTE:
48
- // The player’s primary rendering contract is via web components and the Svelte component entrypoint.
49
- // If you need non-web-component rendering, build it externally against the public extraction APIs.
50
- // Export all types including adaptive item types
51
- export * from './types/index.js';
52
- // Export utilities
53
- export {
54
- globalPerformanceMonitor,
55
- type PerformanceEntry,
56
- PerformanceMonitor,
57
- type PerformanceMonitorConfig,
58
- type PerformanceReport,
59
- } from './utils/PerformanceMonitor.js';
60
-
61
- export { isResponseEmpty } from './utils/responseUtils.js';
62
-
63
- // PNP profile (QTI 3.0 §6.2)
64
- export type { PnpProfile } from './pnp/types.js';
65
- export { applyPnpToRoot } from './pnp/applyPnp.js';
66
- export { parsePnpXml } from './pnp/parsePnpXml.js';
67
-
68
- // Catalog (QTI 3.0 §6.3)
69
- export type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js';
70
- export { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';
71
- export { getCatalogEntry } from './catalog/catalogLookup.js';
72
- export type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
73
-
74
- // PCI — Portable Custom Interaction (QTI 3.0 §6.1)
75
- export type { PciModule, PciBoundTo, ExtractedPci } from './pci/types.js';
76
- export { PciLoadError } from './pci/types.js';
77
- export { PciHost } from './pci/PciHost.js';
78
-
79
- // Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience
80
- // (heuristics are now in the shared ingestion layer)
81
- export {
82
- normalizeHeuristicsConfig,
83
- applyFeedbackTextHeuristics,
84
- shouldUseLenientImagePaths,
85
- shouldAutoPopulateFeedbackOutcome,
86
- DEFAULT_HEURISTICS_CONFIG,
87
- STRICT_QTI_CONFIG,
88
- FEEDBACK_TEXT_TRANSFORMS,
89
- type QtiHeuristicsConfig,
90
- type TextTransform,
91
- } from '@pie-qti/ims-cp-core';
92
-
93
- /**
94
- * NOTE (SSR safety):
95
- * Web component base classes depend on DOM globals like `HTMLElement` and must not be
96
- * re-exported from the main entrypoint, otherwise server-side imports of `{ Player }`
97
- * will crash under SSR/Node.
98
- *
99
- * Import web-components from the subpath entry instead:
100
- * - `@pie-qti/item-player/web-components`
101
- */
@@ -1,133 +0,0 @@
1
- /**
2
- * Standard QTI associateInteraction extractor
3
- *
4
- * Extracts data from associateInteraction elements (associating items)
5
- */
6
-
7
- import type { ElementExtractor } from '../../extraction/types.js';
8
-
9
- /**
10
- * Associate data extracted from associateInteraction elements
11
- */
12
- export interface AssociateData {
13
- choices: Array<{
14
- identifier: string;
15
- text: string;
16
- matchMax: number;
17
- matchMin?: number;
18
- matchGroup?: string[];
19
- classes?: string[];
20
- }>;
21
- shuffle: boolean;
22
- maxAssociations: number;
23
- minAssociations?: number;
24
- prompt: string | null;
25
- }
26
-
27
- /**
28
- * Standard QTI associate interaction extractor
29
- * Handles associateInteraction elements (creating associations between items)
30
- */
31
- export const standardAssociateExtractor: ElementExtractor<AssociateData> = {
32
- id: 'qti:associate-interaction',
33
- name: 'QTI Standard Associate Interaction',
34
- priority: 10,
35
- elementTypes: ['associateInteraction'],
36
- description: 'Extracts standard QTI associateInteraction (associating items)',
37
-
38
- canHandle(element, context) {
39
- // All associateInteraction elements with simpleAssociableChoice are standard
40
- return (
41
- element.rawTagName === 'associateInteraction' &&
42
- context.utils.hasChildWithTag(element, 'simpleAssociableChoice')
43
- );
44
- },
45
-
46
- extract(element, context) {
47
- const { utils } = context;
48
-
49
- // Extract simpleAssociableChoice children
50
- const choiceElements = utils.getChildrenByTag(element, 'simpleAssociableChoice');
51
- const choices = choiceElements.map((choice) => {
52
- const classes = utils.getClasses(choice);
53
- const matchMax = utils.getNumberAttribute(choice, 'matchMax', 1);
54
- const matchMin = utils.getNumberAttribute(choice, 'matchMin', 0);
55
- const matchGroupRaw = utils.getAttribute(choice, 'matchGroup', '');
56
- const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
57
-
58
- return {
59
- identifier: utils.getAttribute(choice, 'identifier', ''),
60
- text: utils.getHtmlContent(choice),
61
- matchMax,
62
- ...(matchMin > 0 ? { matchMin } : {}),
63
- ...(matchGroup.length > 0 ? { matchGroup } : {}),
64
- ...(classes.length > 0 ? { classes } : {}),
65
- };
66
- });
67
-
68
- // Extract attributes with proper defaults
69
- const shuffle = utils.getBooleanAttribute(element, 'shuffle');
70
- const maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', 0);
71
- const minAssociations = utils.getNumberAttribute(element, 'minAssociations', 0);
72
-
73
- // Extract prompt (optional)
74
- const promptElements = utils.getChildrenByTag(element, 'prompt');
75
- const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
76
-
77
- return {
78
- choices,
79
- shuffle,
80
- maxAssociations,
81
- ...(minAssociations > 0 ? { minAssociations } : {}),
82
- prompt,
83
- };
84
- },
85
-
86
- validate(data) {
87
- const errors: string[] = [];
88
-
89
- // Validate choices exist
90
- if (!data.choices || data.choices.length < 2) {
91
- errors.push('associateInteraction must have at least 2 choices');
92
- }
93
-
94
- // Validate choice identifiers
95
- if (data.choices) {
96
- const identifiers = new Set<string>();
97
- for (const choice of data.choices) {
98
- if (!choice.identifier) {
99
- errors.push('All choices must have an identifier');
100
- } else if (identifiers.has(choice.identifier)) {
101
- errors.push(`Duplicate choice identifier: ${choice.identifier}`);
102
- } else {
103
- identifiers.add(choice.identifier);
104
- }
105
-
106
- // Validate matchMax
107
- if (choice.matchMax < 0) {
108
- errors.push(`matchMax must be non-negative for choice ${choice.identifier}`);
109
- }
110
-
111
- // Validate matchMin
112
- if (choice.matchMin !== undefined && choice.matchMin < 0) {
113
- errors.push(`matchMin must be non-negative for choice ${choice.identifier}`);
114
- }
115
- }
116
- }
117
-
118
- // Validate maxAssociations
119
- if (data.maxAssociations < 0) {
120
- errors.push('maxAssociations must be non-negative');
121
- }
122
-
123
- // Validate minAssociations
124
- if (data.minAssociations !== undefined && data.minAssociations < 0) {
125
- errors.push('minAssociations must be non-negative');
126
- }
127
-
128
- return {
129
- valid: errors.length === 0,
130
- errors: errors.length > 0 ? errors : undefined,
131
- };
132
- },
133
- };
@@ -1,2 +0,0 @@
1
- export * from './extractor.js';
2
- export type { AssociateInteractionData } from './types.js';
@@ -1 +0,0 @@
1
- export type { AssociateInteractionData, AssociableChoice } from '../shared/types.js';