@pie-qti/item-player 0.1.15 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -6
- package/dist/core/ComponentRegistry.js +1 -0
- package/dist/core/ComponentRegistry.js.map +1 -1
- package/dist/core/Player.d.ts +4 -0
- package/dist/core/Player.js +296 -89
- package/dist/core/Player.js.map +1 -1
- package/dist/core/declarations.js +11 -4
- package/dist/core/declarations.js.map +1 -1
- package/dist/core/sanitizer.js +119 -1
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/core/shuffle.d.ts +42 -0
- package/dist/core/shuffle.js +83 -0
- package/dist/core/shuffle.js.map +1 -0
- package/dist/core/urlPolicy.js +34 -23
- package/dist/core/urlPolicy.js.map +1 -1
- package/dist/element-class-BLaOCHDu.js +6926 -0
- package/dist/element-class-BLaOCHDu.js.map +1 -0
- package/dist/element-class.d.ts +73 -0
- package/dist/element-class.js +2 -0
- package/dist/element.d.ts +6 -40
- package/dist/element.js +4 -6299
- package/dist/element.js.map +1 -1
- package/dist/extraction/ExtractionRegistry.js +1 -1
- package/dist/extraction/ExtractionRegistry.js.map +1 -1
- package/dist/extraction/createContext.d.ts +1 -1
- package/dist/extraction/createContext.js +5 -1
- package/dist/extraction/createContext.js.map +1 -1
- package/dist/extraction/interactionExtractionPipeline.d.ts +6 -1
- package/dist/extraction/interactionExtractionPipeline.js +6 -3
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/types.d.ts +10 -0
- package/dist/extraction/types.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interactions/associate/extractor.js +2 -1
- package/dist/interactions/associate/extractor.js.map +1 -1
- package/dist/interactions/choice/extractor.js +2 -1
- package/dist/interactions/choice/extractor.js.map +1 -1
- package/dist/interactions/custom/extractor.js +22 -2
- package/dist/interactions/custom/extractor.js.map +1 -1
- package/dist/interactions/extended-text/extractor.d.ts +6 -0
- package/dist/interactions/extended-text/extractor.js +40 -6
- package/dist/interactions/extended-text/extractor.js.map +1 -1
- package/dist/interactions/extended-text/index.d.ts +1 -0
- package/dist/interactions/extended-text/index.js +1 -0
- package/dist/interactions/extended-text/index.js.map +1 -1
- package/dist/interactions/extended-text/response.d.ts +31 -0
- package/dist/interactions/extended-text/response.js +193 -0
- package/dist/interactions/extended-text/response.js.map +1 -0
- package/dist/interactions/gap-match/extractor.js +8 -7
- package/dist/interactions/gap-match/extractor.js.map +1 -1
- package/dist/interactions/inline-choice/extractor.js +2 -1
- package/dist/interactions/inline-choice/extractor.js.map +1 -1
- package/dist/interactions/match/extractor.js +3 -2
- package/dist/interactions/match/extractor.js.map +1 -1
- package/dist/interactions/modules.d.ts +4 -0
- package/dist/interactions/modules.js +2 -0
- package/dist/interactions/modules.js.map +1 -1
- package/dist/interactions/order/extractor.js +2 -1
- package/dist/interactions/order/extractor.js.map +1 -1
- package/dist/interactions/portable-custom/extractor.d.ts +3 -2
- package/dist/interactions/portable-custom/extractor.js +66 -25
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/portable-custom/index.d.ts +1 -1
- package/dist/interactions/portable-custom/index.js.map +1 -1
- package/dist/interactions/portable-custom/types.d.ts +1 -1
- package/dist/interactions/portable-custom/types.js.map +1 -1
- package/dist/interactions/position-object/extractor.d.ts +5 -35
- package/dist/interactions/position-object/extractor.js +58 -153
- package/dist/interactions/position-object/extractor.js.map +1 -1
- package/dist/interactions/shared/types.d.ts +15 -1
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/pci/PciHost.d.ts +14 -9
- package/dist/pci/PciHost.js +89 -22
- package/dist/pci/PciHost.js.map +1 -1
- package/dist/pci/index.d.ts +3 -0
- package/dist/pci/index.js +3 -0
- package/dist/pci/index.js.map +1 -0
- package/dist/pci/types.d.ts +72 -0
- package/dist/pci/types.js +12 -0
- package/dist/pci/types.js.map +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +2 -0
- package/dist/presentation/itemPresentationPlan.js +6 -0
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/types/index.d.ts +26 -5
- package/dist/types/index.js.map +1 -1
- package/package.json +19 -11
package/dist/pci/PciHost.js
CHANGED
|
@@ -1,51 +1,67 @@
|
|
|
1
|
-
import { PciLoadError } from './types.js';
|
|
1
|
+
import { PciLoadError, PciModuleResolverRequiredError } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Loads, initializes, and manages the lifecycle of a single PCI module.
|
|
4
4
|
*
|
|
5
5
|
* Usage:
|
|
6
|
-
* const host = new PciHost(extractedData, baseUrl);
|
|
6
|
+
* const host = new PciHost(extractedData, { baseUrl, moduleResolver });
|
|
7
7
|
* await host.load();
|
|
8
8
|
* host.initialize(domNode);
|
|
9
9
|
* host.getResponse(); // returns current response
|
|
10
10
|
* host.destroy(); // cleanup on player teardown
|
|
11
11
|
*/
|
|
12
12
|
export class PciHost {
|
|
13
|
-
constructor(data,
|
|
13
|
+
constructor(data, options = {}) {
|
|
14
14
|
this.module = null;
|
|
15
|
+
this.destroyed = false;
|
|
16
|
+
this.loadGeneration = 0;
|
|
15
17
|
this._response = null;
|
|
16
|
-
this.
|
|
18
|
+
this._hasResponse = false;
|
|
19
|
+
this._responseChangeListeners = new Set();
|
|
17
20
|
this.data = data;
|
|
18
|
-
this.baseUrl = baseUrl;
|
|
21
|
+
this.baseUrl = typeof options === 'string' ? options : (options.baseUrl ?? '');
|
|
22
|
+
this.moduleResolver = typeof options === 'string' ? undefined : options.moduleResolver;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* Register a callback to fire when the PCI's response changes.
|
|
22
26
|
* The player calls this to wire the PCI into its internal response map.
|
|
23
27
|
*/
|
|
24
28
|
onResponseChange(callback) {
|
|
25
|
-
this.
|
|
29
|
+
this._responseChangeListeners.add(callback);
|
|
30
|
+
return () => this._responseChangeListeners.delete(callback);
|
|
26
31
|
}
|
|
27
32
|
/**
|
|
28
33
|
* Load the PCI module from primaryPath, falling back to fallbackPath.
|
|
29
34
|
* Throws PciLoadError if both fail.
|
|
30
35
|
*/
|
|
31
36
|
async load() {
|
|
37
|
+
if (this.destroyed) {
|
|
38
|
+
throw new Error('Cannot load a destroyed PciHost');
|
|
39
|
+
}
|
|
40
|
+
if (!this.moduleResolver) {
|
|
41
|
+
throw new PciModuleResolverRequiredError(this.data.responseIdentifier, this.data.primaryPath);
|
|
42
|
+
}
|
|
43
|
+
const generation = ++this.loadGeneration;
|
|
32
44
|
const primary = this.resolveUrl(this.data.primaryPath);
|
|
33
45
|
try {
|
|
34
|
-
const mod = await this.
|
|
35
|
-
this.
|
|
46
|
+
const mod = await this.resolveModule(primary, this.data.primaryPath, 'primary');
|
|
47
|
+
this.adoptResolvedModule(mod, this.data.primaryPath, generation);
|
|
36
48
|
return;
|
|
37
49
|
}
|
|
38
50
|
catch (primaryErr) {
|
|
51
|
+
if (!this.isCurrentLoad(generation))
|
|
52
|
+
throw primaryErr;
|
|
39
53
|
if (!this.data.fallbackPath) {
|
|
40
54
|
throw new PciLoadError(this.data.primaryPath, undefined, primaryErr);
|
|
41
55
|
}
|
|
42
56
|
}
|
|
43
57
|
const fallback = this.resolveUrl(this.data.fallbackPath);
|
|
44
58
|
try {
|
|
45
|
-
const mod = await this.
|
|
46
|
-
this.
|
|
59
|
+
const mod = await this.resolveModule(fallback, this.data.fallbackPath, 'fallback');
|
|
60
|
+
this.adoptResolvedModule(mod, this.data.fallbackPath, generation);
|
|
47
61
|
}
|
|
48
62
|
catch (fallbackErr) {
|
|
63
|
+
if (!this.isCurrentLoad(generation))
|
|
64
|
+
throw fallbackErr;
|
|
49
65
|
throw new PciLoadError(this.data.primaryPath, this.data.fallbackPath, fallbackErr);
|
|
50
66
|
}
|
|
51
67
|
}
|
|
@@ -60,10 +76,24 @@ export class PciHost {
|
|
|
60
76
|
onReady: () => { },
|
|
61
77
|
onResponseChange: (value) => {
|
|
62
78
|
this._response = value;
|
|
63
|
-
this.
|
|
79
|
+
this._hasResponse = true;
|
|
80
|
+
for (const listener of this._responseChangeListeners) {
|
|
81
|
+
listener(this.data.responseIdentifier, value);
|
|
82
|
+
}
|
|
64
83
|
},
|
|
65
84
|
};
|
|
66
|
-
|
|
85
|
+
try {
|
|
86
|
+
this.module.initialize(dom, this.data.config, boundTo);
|
|
87
|
+
if (this._hasResponse) {
|
|
88
|
+
this.module.setResponse(this._response);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
const failedModule = this.module;
|
|
93
|
+
this.module = null;
|
|
94
|
+
failedModule.destroy();
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
67
97
|
}
|
|
68
98
|
/** Return the current response value from the PCI module. */
|
|
69
99
|
getResponse() {
|
|
@@ -72,6 +102,7 @@ export class PciHost {
|
|
|
72
102
|
/** Restore a response value into the PCI module (e.g. from session state). */
|
|
73
103
|
setResponse(value) {
|
|
74
104
|
this._response = value;
|
|
105
|
+
this._hasResponse = true;
|
|
75
106
|
this.module?.setResponse(value);
|
|
76
107
|
}
|
|
77
108
|
/** Disable the PCI (e.g. when role is not candidate, or after final submission). */
|
|
@@ -84,32 +115,68 @@ export class PciHost {
|
|
|
84
115
|
}
|
|
85
116
|
/** Tear down the PCI and release all resources. */
|
|
86
117
|
destroy() {
|
|
118
|
+
this.destroyed = true;
|
|
119
|
+
this.loadGeneration++;
|
|
87
120
|
this.module?.destroy();
|
|
88
121
|
this.module = null;
|
|
122
|
+
this._responseChangeListeners.clear();
|
|
89
123
|
}
|
|
90
124
|
// ---------------------------------------------------------------------------
|
|
91
125
|
// Private helpers
|
|
92
126
|
// ---------------------------------------------------------------------------
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
127
|
+
resolveModule(resolvedUrl, authoredPath, kind) {
|
|
128
|
+
return Promise.resolve(this.moduleResolver(resolvedUrl, {
|
|
129
|
+
authoredPath,
|
|
130
|
+
kind,
|
|
131
|
+
responseIdentifier: this.data.responseIdentifier,
|
|
132
|
+
customInteractionTypeIdentifier: this.data.customInteractionTypeIdentifier,
|
|
133
|
+
}));
|
|
96
134
|
}
|
|
97
135
|
resolveUrl(path) {
|
|
98
|
-
if (/^
|
|
136
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(path) || path.startsWith('//') || path.startsWith('/')) {
|
|
137
|
+
return path;
|
|
138
|
+
}
|
|
139
|
+
if (!this.baseUrl)
|
|
99
140
|
return path;
|
|
100
141
|
// Relative path: resolve against baseUrl
|
|
101
142
|
const base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/';
|
|
102
|
-
|
|
143
|
+
try {
|
|
144
|
+
return new URL(path, base).href;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return base + path;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
isCurrentLoad(generation) {
|
|
151
|
+
return !this.destroyed && generation === this.loadGeneration;
|
|
152
|
+
}
|
|
153
|
+
adoptResolvedModule(mod, authoredPath, generation) {
|
|
154
|
+
const candidate = this.extractPciInterface(mod, authoredPath);
|
|
155
|
+
if (!this.isCurrentLoad(generation)) {
|
|
156
|
+
candidate.destroy();
|
|
157
|
+
throw new Error('PciHost was destroyed before its module finished loading');
|
|
158
|
+
}
|
|
159
|
+
this.module?.destroy();
|
|
160
|
+
this.module = candidate;
|
|
103
161
|
}
|
|
104
162
|
/**
|
|
105
|
-
* Extract a PciModule from
|
|
163
|
+
* Extract a PciModule from the host resolver's result.
|
|
106
164
|
* Supports: default export, named `getInstance` export, or the module itself.
|
|
107
165
|
*/
|
|
108
|
-
extractPciInterface(mod) {
|
|
166
|
+
extractPciInterface(mod, authoredPath) {
|
|
109
167
|
const candidate = mod?.default ?? mod?.getInstance?.() ?? mod;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
168
|
+
const requiredMethods = [
|
|
169
|
+
'initialize',
|
|
170
|
+
'getResponse',
|
|
171
|
+
'setResponse',
|
|
172
|
+
'disable',
|
|
173
|
+
'enable',
|
|
174
|
+
'destroy',
|
|
175
|
+
];
|
|
176
|
+
const missingMethods = requiredMethods.filter((method) => typeof candidate?.[method] !== 'function');
|
|
177
|
+
if (missingMethods.length > 0) {
|
|
178
|
+
throw new Error(`PCI module at '${authoredPath}' does not export a valid PciModule interface; ` +
|
|
179
|
+
`missing: ${missingMethods.join(', ')}`);
|
|
113
180
|
}
|
|
114
181
|
return candidate;
|
|
115
182
|
}
|
package/dist/pci/PciHost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PciHost.js","sourceRoot":"","sources":["../../src/pci/PciHost.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;;;GASG;AACH,MAAM,OAAO,OAAO;IAOnB,YAAY,IAAkB,EAAE,OAAe;QAJvC,WAAM,GAAqB,IAAI,CAAC;QAChC,cAAS,GAAY,IAAI,CAAC;QAC1B,sBAAiB,GAA0D,IAAI,CAAC;QAGvF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED;;;OAGG;IACI,gBAAgB,CAAC,QAAsD;QAC7E,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,IAAI;QAChB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACvD,IAAI,CAAC;YACJ,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC5C,OAAO;QACR,CAAC;QAAC,OAAO,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY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AAgD;gBACtF,iFAAiF,CAClF,CAAC;QACH,CAAC;QACD,OAAO,SAAsB,CAAC;IAC/B,CAAC;CACD","sourcesContent":["import type { ExtractedPci, PciBoundTo, PciModule } from './types.js';\nimport { PciLoadError } from './types.js';\n\n/**\n * Loads, initializes, and manages the lifecycle of a single PCI module.\n *\n * Usage:\n * const host = new PciHost(extractedData, baseUrl);\n * await host.load();\n * host.initialize(domNode);\n * host.getResponse(); // returns current response\n * host.destroy(); // cleanup on player teardown\n */\nexport class PciHost {\n\tprivate readonly data: ExtractedPci;\n\tprivate readonly baseUrl: string;\n\tprivate module: PciModule | null = null;\n\tprivate _response: unknown = null;\n\tprivate _onResponseChange: ((responseId: string, value: unknown) => void) | null = null;\n\n\tconstructor(data: ExtractedPci, baseUrl: string) {\n\t\tthis.data = data;\n\t\tthis.baseUrl = baseUrl;\n\t}\n\n\t/**\n\t * Register a callback to fire when the PCI's response changes.\n\t * The player calls this to wire the PCI into its internal response map.\n\t */\n\tpublic onResponseChange(callback: (responseId: string, value: unknown) => void): void {\n\t\tthis._onResponseChange = callback;\n\t}\n\n\t/**\n\t * Load the PCI module from primaryPath, falling back to fallbackPath.\n\t * Throws PciLoadError if both fail.\n\t */\n\tpublic async load(): Promise<void> {\n\t\tconst primary = this.resolveUrl(this.data.primaryPath);\n\t\ttry {\n\t\t\tconst mod = await this.dynamicImport(primary);\n\t\t\tthis.module = this.extractPciInterface(mod);\n\t\t\treturn;\n\t\t} catch (primaryErr) {\n\t\t\tif (!this.data.fallbackPath) {\n\t\t\t\tthrow new PciLoadError(this.data.primaryPath, undefined, primaryErr as Error);\n\t\t\t}\n\t\t}\n\n\t\tconst fallback = this.resolveUrl(this.data.fallbackPath!);\n\t\ttry {\n\t\t\tconst mod = await this.dynamicImport(fallback);\n\t\t\tthis.module = this.extractPciInterface(mod);\n\t\t} catch (fallbackErr) {\n\t\t\tthrow new PciLoadError(\n\t\t\t\tthis.data.primaryPath,\n\t\t\t\tthis.data.fallbackPath,\n\t\t\t\tfallbackErr as Error\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Initialize the PCI inside the given DOM element.\n\t * Must be called after load() resolves.\n\t */\n\tpublic initialize(dom: HTMLElement): void {\n\t\tif (!this.module) return;\n\n\t\tconst boundTo: PciBoundTo = {\n\t\t\tonReady: () => {},\n\t\t\tonResponseChange: (value: unknown) => {\n\t\t\t\tthis._response = value;\n\t\t\t\tthis._onResponseChange?.(this.data.responseIdentifier, value);\n\t\t\t},\n\t\t};\n\n\t\tthis.module.initialize(dom, this.data.config, boundTo);\n\t}\n\n\t/** Return the current response value from the PCI module. */\n\tpublic getResponse(): unknown {\n\t\treturn this.module ? this.module.getResponse() : this._response;\n\t}\n\n\t/** Restore a response value into the PCI module (e.g. from session state). */\n\tpublic setResponse(value: unknown): void {\n\t\tthis._response = value;\n\t\tthis.module?.setResponse(value);\n\t}\n\n\t/** Disable the PCI (e.g. when role is not candidate, or after final submission). */\n\tpublic disable(): void {\n\t\tthis.module?.disable();\n\t}\n\n\t/** Re-enable the PCI. */\n\tpublic enable(): void {\n\t\tthis.module?.enable();\n\t}\n\n\t/** Tear down the PCI and release all resources. */\n\tpublic destroy(): void {\n\t\tthis.module?.destroy();\n\t\tthis.module = null;\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Private helpers\n\t// ---------------------------------------------------------------------------\n\n\t/** Thin wrapper around dynamic import — overridable in tests. */\n\tprotected dynamicImport(url: string): Promise<any> {\n\t\treturn import(/* @vite-ignore */ url);\n\t}\n\n\tprivate resolveUrl(path: string): string {\n\t\tif (/^https?:\\/\\//.test(path) || path.startsWith('/')) return path;\n\t\t// Relative path: resolve against baseUrl\n\t\tconst base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/';\n\t\treturn base + path;\n\t}\n\n\t/**\n\t * Extract a PciModule from a dynamic import result.\n\t * Supports: default export, named `getInstance` export, or the module itself.\n\t */\n\tprivate extractPciInterface(mod: any): PciModule {\n\t\tconst candidate = mod?.default ?? mod?.getInstance?.() ?? mod;\n\t\tif (typeof candidate?.initialize !== 'function') {\n\t\t\tthrow new Error(\n\t\t\t\t`PCI module at '${this.data.primaryPath}' does not export a valid PciModule interface ` +\n\t\t\t\t\t'(expected .initialize, .getResponse, .setResponse, .disable, .enable, .destroy)'\n\t\t\t);\n\t\t}\n\t\treturn candidate as PciModule;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PciHost.js","sourceRoot":"","sources":["../../src/pci/PciHost.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAE1E;;;;;;;;;GASG;AACH,MAAM,OAAO,OAAO;IAanB,YAAY,IAAkB,EAAE,UAAmC,EAAE;QAT7D,WAAM,GAAqB,IAAI,CAAC;QAChC,cAAS,GAAG,KAAK,CAAC;QAClB,mBAAc,GAAG,CAAC,CAAC;QACnB,cAAS,GAAY,IAAI,CAAC;QAC1B,iBAAY,GAAG,KAAK,CAAC;QACZ,6BAAwB,GAAG,IAAI,GAAG,EAEhD,CAAC;QAGH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,cAAc,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;IACxF,CAAC;IAED;;;OAGG;IACI,gBAAgB,CAAC,QAAsD;QAC7E,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5C,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,IAAI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Ae,GAAG;YACvB,YAAY;YACZ,aAAa;YACb,aAAa;YACb,SAAS;YACT,QAAQ;YACR,SAAS;SACA,CAAC;QACX,MAAM,cAAc,GAAG,eAAe,CAAC,MAAM,CAC5C,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,SAAS,EAAE,CAAC,MAAM,CAAC,KAAK,UAAU,CACrD,CAAC;QACF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACd,kBAAkB,YAAY,iDAAiD;gBAC9E,YAAY,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACxC,CAAC;QACH,CAAC;QACD,OAAO,SAAsB,CAAC;IAC/B,CAAC;CACD","sourcesContent":["import type {\n\tExtractedPci,\n\tPciBoundTo,\n\tPciHostController,\n\tPciHostOptions,\n\tPciModule,\n\tPciModulePathKind,\n\tPciModuleResolver,\n} from './types.js';\nimport { PciLoadError, PciModuleResolverRequiredError } from './types.js';\n\n/**\n * Loads, initializes, and manages the lifecycle of a single PCI module.\n *\n * Usage:\n * const host = new PciHost(extractedData, { baseUrl, moduleResolver });\n * await host.load();\n * host.initialize(domNode);\n * host.getResponse(); // returns current response\n * host.destroy(); // cleanup on player teardown\n */\nexport class PciHost implements PciHostController {\n\tprivate readonly data: ExtractedPci;\n\tprivate readonly baseUrl: string;\n\tprivate readonly moduleResolver: PciModuleResolver | undefined;\n\tprivate module: PciModule | null = null;\n\tprivate destroyed = false;\n\tprivate loadGeneration = 0;\n\tprivate _response: unknown = null;\n\tprivate _hasResponse = false;\n\tprivate readonly _responseChangeListeners = new Set<\n\t\t(responseId: string, value: unknown) => void\n\t>();\n\n\tconstructor(data: ExtractedPci, options: PciHostOptions | string = {}) {\n\t\tthis.data = data;\n\t\tthis.baseUrl = typeof options === 'string' ? options : (options.baseUrl ?? '');\n\t\tthis.moduleResolver = typeof options === 'string' ? undefined : options.moduleResolver;\n\t}\n\n\t/**\n\t * Register a callback to fire when the PCI's response changes.\n\t * The player calls this to wire the PCI into its internal response map.\n\t */\n\tpublic onResponseChange(callback: (responseId: string, value: unknown) => void): () => void {\n\t\tthis._responseChangeListeners.add(callback);\n\t\treturn () => this._responseChangeListeners.delete(callback);\n\t}\n\n\t/**\n\t * Load the PCI module from primaryPath, falling back to fallbackPath.\n\t * Throws PciLoadError if both fail.\n\t */\n\tpublic async load(): Promise<void> {\n\t\tif (this.destroyed) {\n\t\t\tthrow new Error('Cannot load a destroyed PciHost');\n\t\t}\n\t\tif (!this.moduleResolver) {\n\t\t\tthrow new PciModuleResolverRequiredError(\n\t\t\t\tthis.data.responseIdentifier,\n\t\t\t\tthis.data.primaryPath\n\t\t\t);\n\t\t}\n\t\tconst generation = ++this.loadGeneration;\n\n\t\tconst primary = this.resolveUrl(this.data.primaryPath);\n\t\ttry {\n\t\t\tconst mod = await this.resolveModule(primary, this.data.primaryPath, 'primary');\n\t\t\tthis.adoptResolvedModule(mod, this.data.primaryPath, generation);\n\t\t\treturn;\n\t\t} catch (primaryErr) {\n\t\t\tif (!this.isCurrentLoad(generation)) throw primaryErr;\n\t\t\tif (!this.data.fallbackPath) {\n\t\t\t\tthrow new PciLoadError(this.data.primaryPath, undefined, primaryErr as Error);\n\t\t\t}\n\t\t}\n\n\t\tconst fallback = this.resolveUrl(this.data.fallbackPath!);\n\t\ttry {\n\t\t\tconst mod = await this.resolveModule(fallback, this.data.fallbackPath!, 'fallback');\n\t\t\tthis.adoptResolvedModule(mod, this.data.fallbackPath!, generation);\n\t\t} catch (fallbackErr) {\n\t\t\tif (!this.isCurrentLoad(generation)) throw fallbackErr;\n\t\t\tthrow new PciLoadError(\n\t\t\t\tthis.data.primaryPath,\n\t\t\t\tthis.data.fallbackPath,\n\t\t\t\tfallbackErr as Error\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Initialize the PCI inside the given DOM element.\n\t * Must be called after load() resolves.\n\t */\n\tpublic initialize(dom: HTMLElement): void {\n\t\tif (!this.module) return;\n\n\t\tconst boundTo: PciBoundTo = {\n\t\t\tonReady: () => {},\n\t\t\tonResponseChange: (value: unknown) => {\n\t\t\t\tthis._response = value;\n\t\t\t\tthis._hasResponse = true;\n\t\t\t\tfor (const listener of this._responseChangeListeners) {\n\t\t\t\t\tlistener(this.data.responseIdentifier, value);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\n\t\ttry {\n\t\t\tthis.module.initialize(dom, this.data.config, boundTo);\n\t\t\tif (this._hasResponse) {\n\t\t\t\tthis.module.setResponse(this._response);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst failedModule = this.module;\n\t\t\tthis.module = null;\n\t\t\tfailedModule.destroy();\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/** Return the current response value from the PCI module. */\n\tpublic getResponse(): unknown {\n\t\treturn this.module ? this.module.getResponse() : this._response;\n\t}\n\n\t/** Restore a response value into the PCI module (e.g. from session state). */\n\tpublic setResponse(value: unknown): void {\n\t\tthis._response = value;\n\t\tthis._hasResponse = true;\n\t\tthis.module?.setResponse(value);\n\t}\n\n\t/** Disable the PCI (e.g. when role is not candidate, or after final submission). */\n\tpublic disable(): void {\n\t\tthis.module?.disable();\n\t}\n\n\t/** Re-enable the PCI. */\n\tpublic enable(): void {\n\t\tthis.module?.enable();\n\t}\n\n\t/** Tear down the PCI and release all resources. */\n\tpublic destroy(): void {\n\t\tthis.destroyed = true;\n\t\tthis.loadGeneration++;\n\t\tthis.module?.destroy();\n\t\tthis.module = null;\n\t\tthis._responseChangeListeners.clear();\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Private helpers\n\t// ---------------------------------------------------------------------------\n\n\tprivate resolveModule(\n\t\tresolvedUrl: string,\n\t\tauthoredPath: string,\n\t\tkind: PciModulePathKind\n\t): Promise<unknown> {\n\t\treturn Promise.resolve(\n\t\t\tthis.moduleResolver!(resolvedUrl, {\n\t\t\t\tauthoredPath,\n\t\t\t\tkind,\n\t\t\t\tresponseIdentifier: this.data.responseIdentifier,\n\t\t\t\tcustomInteractionTypeIdentifier: this.data.customInteractionTypeIdentifier,\n\t\t\t})\n\t\t);\n\t}\n\n\tprivate resolveUrl(path: string): string {\n\t\tif (/^[a-z][a-z\\d+.-]*:/i.test(path) || path.startsWith('//') || path.startsWith('/')) {\n\t\t\treturn path;\n\t\t}\n\t\tif (!this.baseUrl) return path;\n\t\t// Relative path: resolve against baseUrl\n\t\tconst base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/';\n\t\ttry {\n\t\t\treturn new URL(path, base).href;\n\t\t} catch {\n\t\t\treturn base + path;\n\t\t}\n\t}\n\n\tprivate isCurrentLoad(generation: number): boolean {\n\t\treturn !this.destroyed && generation === this.loadGeneration;\n\t}\n\n\tprivate adoptResolvedModule(mod: unknown, authoredPath: string, generation: number): void {\n\t\tconst candidate = this.extractPciInterface(mod, authoredPath);\n\t\tif (!this.isCurrentLoad(generation)) {\n\t\t\tcandidate.destroy();\n\t\t\tthrow new Error('PciHost was destroyed before its module finished loading');\n\t\t}\n\t\tthis.module?.destroy();\n\t\tthis.module = candidate;\n\t}\n\n\t/**\n\t * Extract a PciModule from the host resolver's result.\n\t * Supports: default export, named `getInstance` export, or the module itself.\n\t */\n\tprivate extractPciInterface(mod: any, authoredPath: string): PciModule {\n\t\tconst candidate = mod?.default ?? mod?.getInstance?.() ?? mod;\n\t\tconst requiredMethods = [\n\t\t\t'initialize',\n\t\t\t'getResponse',\n\t\t\t'setResponse',\n\t\t\t'disable',\n\t\t\t'enable',\n\t\t\t'destroy',\n\t\t] as const;\n\t\tconst missingMethods = requiredMethods.filter(\n\t\t\t(method) => typeof candidate?.[method] !== 'function'\n\t\t);\n\t\tif (missingMethods.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`PCI module at '${authoredPath}' does not export a valid PciModule interface; ` +\n\t\t\t\t\t`missing: ${missingMethods.join(', ')}`\n\t\t\t);\n\t\t}\n\t\treturn candidate as PciModule;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { PciHost } from './PciHost.js';
|
|
2
|
+
export type { ExtractedPci, PciBoundTo, PciConfiguration, PciHostController, PciHostOptions, PciModule, PciModulePathKind, PciModuleResolutionContext, PciModuleResolver, } from './types.js';
|
|
3
|
+
export { PciLoadError, PciModuleResolverRequiredError } from './types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pci/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAYvC,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { PciHost } from './PciHost.js';\nexport type {\n\tExtractedPci,\n\tPciBoundTo,\n\tPciConfiguration,\n\tPciHostController,\n\tPciHostOptions,\n\tPciModule,\n\tPciModulePathKind,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n} from './types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './types.js';\n"]}
|
package/dist/pci/types.d.ts
CHANGED
|
@@ -29,10 +29,74 @@ export interface PciModule {
|
|
|
29
29
|
/** Tear down: remove event listeners, cancel timers, free resources. */
|
|
30
30
|
destroy(): void;
|
|
31
31
|
}
|
|
32
|
+
/** Identifies which authored module path is currently being resolved. */
|
|
33
|
+
export type PciModulePathKind = 'primary' | 'fallback';
|
|
34
|
+
/**
|
|
35
|
+
* Context supplied to a host-owned PCI module resolver.
|
|
36
|
+
*
|
|
37
|
+
* PCI code executes with the authority of the page that loads it. The player therefore
|
|
38
|
+
* never imports an authored URL by itself; an embedding host must decide which URLs or
|
|
39
|
+
* package resources are trusted and return the loaded module explicitly.
|
|
40
|
+
*/
|
|
41
|
+
export interface PciModuleResolutionContext {
|
|
42
|
+
/** Original path exactly as authored in the item. */
|
|
43
|
+
authoredPath: string;
|
|
44
|
+
/** Whether this is the primary module or the authored fallback. */
|
|
45
|
+
kind: PciModulePathKind;
|
|
46
|
+
/** Response variable bound to the interaction. */
|
|
47
|
+
responseIdentifier: string;
|
|
48
|
+
/** Portable interaction type identifier/URN. */
|
|
49
|
+
customInteractionTypeIdentifier: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Host-controlled PCI module resolution hook.
|
|
53
|
+
*
|
|
54
|
+
* The resolver may import an allow-listed URL, read a module from a verified content
|
|
55
|
+
* package, or return a pre-registered module. Its return value may be a PciModule,
|
|
56
|
+
* an ES-module namespace with a default export, or a namespace exposing getInstance().
|
|
57
|
+
*/
|
|
58
|
+
export type PciModuleResolver = (resolvedUrl: string, context: PciModuleResolutionContext) => Promise<unknown> | unknown;
|
|
59
|
+
/** Secure-by-default PCI runtime configuration. */
|
|
60
|
+
export interface PciConfiguration {
|
|
61
|
+
/** Directory URL used to resolve relative authored module paths. */
|
|
62
|
+
baseUrl?: string;
|
|
63
|
+
/** Required host trust decision for loading/executing a PCI module. */
|
|
64
|
+
moduleResolver: PciModuleResolver;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Low-level options accepted by PciHost.
|
|
68
|
+
*
|
|
69
|
+
* `moduleResolver` remains optional here so an unconfigured host can report the
|
|
70
|
+
* secure-default error at load time. Public player configuration requires it.
|
|
71
|
+
*/
|
|
72
|
+
export interface PciHostOptions {
|
|
73
|
+
baseUrl?: string;
|
|
74
|
+
moduleResolver?: PciModuleResolver;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Public, structural contract exposed by a PCI host.
|
|
78
|
+
*
|
|
79
|
+
* Keep component boundaries typed against this interface rather than the concrete
|
|
80
|
+
* PciHost class. That allows consumers to combine source and published package
|
|
81
|
+
* entrypoints without TypeScript treating the class's private state as part of
|
|
82
|
+
* the compatibility check.
|
|
83
|
+
*/
|
|
84
|
+
export interface PciHostController {
|
|
85
|
+
onResponseChange(callback: (responseId: string, value: unknown) => void): () => void;
|
|
86
|
+
load(): Promise<void>;
|
|
87
|
+
initialize(dom: HTMLElement): void;
|
|
88
|
+
getResponse(): unknown;
|
|
89
|
+
setResponse(value: unknown): void;
|
|
90
|
+
disable(): void;
|
|
91
|
+
enable(): void;
|
|
92
|
+
destroy(): void;
|
|
93
|
+
}
|
|
32
94
|
/**
|
|
33
95
|
* Extracted data from a <qti-portable-custom-interaction> element.
|
|
34
96
|
*/
|
|
35
97
|
export interface ExtractedPci {
|
|
98
|
+
/** Canonical renderer type. Present on extractor output, optional for direct PciHost callers. */
|
|
99
|
+
type?: 'portableCustomInteraction';
|
|
36
100
|
/** responseIdentifier attribute value. */
|
|
37
101
|
responseIdentifier: string;
|
|
38
102
|
/** customInteractionTypeIdentifier attribute value (URN identifying the PCI type). */
|
|
@@ -46,6 +110,14 @@ export interface ExtractedPci {
|
|
|
46
110
|
/** Key/value pairs from <qti-pci-properties>/<qti-pci-property>. */
|
|
47
111
|
config: Record<string, string>;
|
|
48
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Raised when PCI content is present but the embedding host has not opted into executing it.
|
|
115
|
+
*/
|
|
116
|
+
export declare class PciModuleResolverRequiredError extends Error {
|
|
117
|
+
readonly responseIdentifier: string;
|
|
118
|
+
readonly authoredPath: string;
|
|
119
|
+
constructor(responseIdentifier: string, authoredPath: string);
|
|
120
|
+
}
|
|
49
121
|
/**
|
|
50
122
|
* Thrown when a PCI module fails to load from both primary and fallback paths.
|
|
51
123
|
*/
|
package/dist/pci/types.js
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
* QTI 3.0 Portable Custom Interaction (PCI) types.
|
|
3
3
|
* Based on IMS QTI 3.0 Portable Custom Interaction specification.
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Raised when PCI content is present but the embedding host has not opted into executing it.
|
|
7
|
+
*/
|
|
8
|
+
export class PciModuleResolverRequiredError extends Error {
|
|
9
|
+
constructor(responseIdentifier, authoredPath) {
|
|
10
|
+
super(`PCI module loading is disabled for response '${responseIdentifier}'. ` +
|
|
11
|
+
`Provide a host-controlled moduleResolver before loading '${authoredPath}'.`);
|
|
12
|
+
this.responseIdentifier = responseIdentifier;
|
|
13
|
+
this.authoredPath = authoredPath;
|
|
14
|
+
this.name = 'PciModuleResolverRequiredError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
5
17
|
/**
|
|
6
18
|
* Thrown when a PCI module fails to load from both primary and fallback paths.
|
|
7
19
|
*/
|
package/dist/pci/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pci/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pci/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0HH;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACxD,YACiB,kBAA0B,EAC1B,YAAoB;QAEpC,KAAK,CACJ,gDAAgD,kBAAkB,KAAK;YACtE,4DAA4D,YAAY,IAAI,CAC7E,CAAC;QANc,uBAAkB,GAAlB,kBAAkB,CAAQ;QAC1B,iBAAY,GAAZ,YAAY,CAAQ;QAMpC,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC9C,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YACiB,WAAmB,EACnB,YAAgC,EAChD,KAAa;QAEb,KAAK,CACJ,YAAY;YACX,CAAC,CAAC,mCAAmC,WAAW,mBAAmB,YAAY,GAAG;YAClF,CAAC,CAAC,mCAAmC,WAAW,GAAG,CACpD,CAAC;QARc,gBAAW,GAAX,WAAW,CAAQ;QACnB,iBAAY,GAAZ,YAAY,CAAoB;QAQhD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,KAAK;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IACvG,CAAC;CACD","sourcesContent":["/**\n * QTI 3.0 Portable Custom Interaction (PCI) types.\n * Based on IMS QTI 3.0 Portable Custom Interaction specification.\n */\n\n/**\n * Callbacks the player provides to a PCI module so it can signal state changes.\n */\nexport interface PciBoundTo {\n\t/** Called when the PCI has finished initializing and is ready to accept responses. */\n\tonReady(): void;\n\t/** Called whenever the candidate's response changes. */\n\tonResponseChange(value: unknown): void;\n}\n\n/**\n * Contract that every PCI module must fulfill.\n * The module's default export (or named `getInstance` export) must implement this interface.\n */\nexport interface PciModule {\n\t/** Initialize the PCI inside the given DOM element. */\n\tinitialize(dom: HTMLElement, config: Record<string, string>, boundTo: PciBoundTo): void;\n\t/** Return the current response value. */\n\tgetResponse(): unknown;\n\t/** Restore a previously-captured response value. */\n\tsetResponse(value: unknown): void;\n\t/** Disable candidate interaction (e.g. after submission or when role is not candidate). */\n\tdisable(): void;\n\t/** Re-enable candidate interaction. */\n\tenable(): void;\n\t/** Tear down: remove event listeners, cancel timers, free resources. */\n\tdestroy(): void;\n}\n\n/** Identifies which authored module path is currently being resolved. */\nexport type PciModulePathKind = 'primary' | 'fallback';\n\n/**\n * Context supplied to a host-owned PCI module resolver.\n *\n * PCI code executes with the authority of the page that loads it. The player therefore\n * never imports an authored URL by itself; an embedding host must decide which URLs or\n * package resources are trusted and return the loaded module explicitly.\n */\nexport interface PciModuleResolutionContext {\n\t/** Original path exactly as authored in the item. */\n\tauthoredPath: string;\n\t/** Whether this is the primary module or the authored fallback. */\n\tkind: PciModulePathKind;\n\t/** Response variable bound to the interaction. */\n\tresponseIdentifier: string;\n\t/** Portable interaction type identifier/URN. */\n\tcustomInteractionTypeIdentifier: string;\n}\n\n/**\n * Host-controlled PCI module resolution hook.\n *\n * The resolver may import an allow-listed URL, read a module from a verified content\n * package, or return a pre-registered module. Its return value may be a PciModule,\n * an ES-module namespace with a default export, or a namespace exposing getInstance().\n */\nexport type PciModuleResolver = (\n\tresolvedUrl: string,\n\tcontext: PciModuleResolutionContext\n) => Promise<unknown> | unknown;\n\n/** Secure-by-default PCI runtime configuration. */\nexport interface PciConfiguration {\n\t/** Directory URL used to resolve relative authored module paths. */\n\tbaseUrl?: string;\n\t/** Required host trust decision for loading/executing a PCI module. */\n\tmoduleResolver: PciModuleResolver;\n}\n\n/**\n * Low-level options accepted by PciHost.\n *\n * `moduleResolver` remains optional here so an unconfigured host can report the\n * secure-default error at load time. Public player configuration requires it.\n */\nexport interface PciHostOptions {\n\tbaseUrl?: string;\n\tmoduleResolver?: PciModuleResolver;\n}\n\n/**\n * Public, structural contract exposed by a PCI host.\n *\n * Keep component boundaries typed against this interface rather than the concrete\n * PciHost class. That allows consumers to combine source and published package\n * entrypoints without TypeScript treating the class's private state as part of\n * the compatibility check.\n */\nexport interface PciHostController {\n\tonResponseChange(callback: (responseId: string, value: unknown) => void): () => void;\n\tload(): Promise<void>;\n\tinitialize(dom: HTMLElement): void;\n\tgetResponse(): unknown;\n\tsetResponse(value: unknown): void;\n\tdisable(): void;\n\tenable(): void;\n\tdestroy(): void;\n}\n\n/**\n * Extracted data from a <qti-portable-custom-interaction> element.\n */\nexport interface ExtractedPci {\n\t/** Canonical renderer type. Present on extractor output, optional for direct PciHost callers. */\n\ttype?: 'portableCustomInteraction';\n\t/** responseIdentifier attribute value. */\n\tresponseIdentifier: string;\n\t/** customInteractionTypeIdentifier attribute value (URN identifying the PCI type). */\n\tcustomInteractionTypeIdentifier: string;\n\t/** Primary JS module path (required). */\n\tprimaryPath: string;\n\t/** Fallback JS module path (optional). */\n\tfallbackPath?: string;\n\t/** Inner HTML of the <qti-interaction-markup> element. */\n\tmarkup: string;\n\t/** Key/value pairs from <qti-pci-properties>/<qti-pci-property>. */\n\tconfig: Record<string, string>;\n}\n\n/**\n * Raised when PCI content is present but the embedding host has not opted into executing it.\n */\nexport class PciModuleResolverRequiredError extends Error {\n\tconstructor(\n\t\tpublic readonly responseIdentifier: string,\n\t\tpublic readonly authoredPath: string\n\t) {\n\t\tsuper(\n\t\t\t`PCI module loading is disabled for response '${responseIdentifier}'. ` +\n\t\t\t\t`Provide a host-controlled moduleResolver before loading '${authoredPath}'.`\n\t\t);\n\t\tthis.name = 'PciModuleResolverRequiredError';\n\t}\n}\n\n/**\n * Thrown when a PCI module fails to load from both primary and fallback paths.\n */\nexport class PciLoadError extends Error {\n\tconstructor(\n\t\tpublic readonly primaryPath: string,\n\t\tpublic readonly fallbackPath: string | undefined,\n\t\tcause?: Error\n\t) {\n\t\tsuper(\n\t\t\tfallbackPath\n\t\t\t\t? `PCI module failed to load from '${primaryPath}' and fallback '${fallbackPath}'`\n\t\t\t\t: `PCI module failed to load from '${primaryPath}'`\n\t\t);\n\t\tthis.name = 'PciLoadError';\n\t\tif (cause) Object.defineProperty(this, 'cause', { value: cause, writable: true, configurable: true });\n\t}\n}\n"]}
|
|
@@ -36,6 +36,8 @@ export interface BlockInteractionPresentation {
|
|
|
36
36
|
tagName: string;
|
|
37
37
|
key: string;
|
|
38
38
|
response: ItemPresentationResponseValue | null;
|
|
39
|
+
/** Lexical companion value used by extendedTextInteraction stringIdentifier. */
|
|
40
|
+
stringResponse?: ItemPresentationResponseValue | null;
|
|
39
41
|
correctResponse: unknown;
|
|
40
42
|
pnp: PnpProfile | undefined;
|
|
41
43
|
eliminationTool: boolean;
|
|
@@ -137,11 +137,17 @@ function createBlockInteractionPresentations({ interactions, player, responses,
|
|
|
137
137
|
.filter((interaction) => !isInlineInteractionType(interaction.type))
|
|
138
138
|
.map((interaction) => {
|
|
139
139
|
try {
|
|
140
|
+
const stringIdentifier = 'stringIdentifier' in interaction && typeof interaction.stringIdentifier === 'string'
|
|
141
|
+
? interaction.stringIdentifier
|
|
142
|
+
: undefined;
|
|
140
143
|
const block = {
|
|
141
144
|
interaction,
|
|
142
145
|
tagName: componentRegistry.getTagName(interaction),
|
|
143
146
|
key: interactionKey(interaction),
|
|
144
147
|
response: responses[interaction.responseId] ?? null,
|
|
148
|
+
...(stringIdentifier
|
|
149
|
+
? { stringResponse: responses[stringIdentifier] ?? null }
|
|
150
|
+
: {}),
|
|
145
151
|
correctResponse: roleCapabilities.canViewCorrectResponses
|
|
146
152
|
? (correctResponses[interaction.responseId] ?? null)
|
|
147
153
|
: null,
|
|
@@ -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;AAsD/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,EAC5B,gBAAgB,GACmB;IACnC,MAAM,YAAY,GAAG,MAAM,CAAC,kBAAkB,EAAE,CAAC;IACjD,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACnD,MAAM,iBAAiB,GAAG,QAAQ,IAAI,gBAAgB,CAAC,UAAU,CAAC;IAClE,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,uBAAuB,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC,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C,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\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, '&')\n\t\t.replace(/\"/g, '"')\n\t\t.replace(/</g, '<')\n\t\t.replace(/>/g, '>');\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 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\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,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,E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","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, '&')\n\t\t.replace(/\"/g, '"')\n\t\t.replace(/</g, '<')\n\t\t.replace(/>/g, '>');\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"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Core QTI types for the player
|
|
3
3
|
*/
|
|
4
|
-
import type { BaseType as ProcessingBaseType, Cardinality as ProcessingCardinality, QtiValue } from '@pie-qti/qti-processing';
|
|
4
|
+
import type { BaseType as ProcessingBaseType, Cardinality as ProcessingCardinality, ProcessingFragmentResolver, QtiValue } from '@pie-qti/qti-processing';
|
|
5
5
|
import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
|
|
6
|
+
import type { PciConfiguration } from '../pci/types.js';
|
|
6
7
|
import type { ResponseValidationResult } from './responseValidation.js';
|
|
7
8
|
/**
|
|
8
9
|
* QTI base type identifier
|
|
@@ -16,7 +17,8 @@ export type VariableBaseType = ProcessingBaseType;
|
|
|
16
17
|
export type VariableCardinality = ProcessingCardinality;
|
|
17
18
|
export interface VariableDeclaration {
|
|
18
19
|
identifier: string;
|
|
19
|
-
|
|
20
|
+
/** Omitted for record cardinality. */
|
|
21
|
+
baseType?: VariableBaseType;
|
|
20
22
|
cardinality: VariableCardinality;
|
|
21
23
|
value: any;
|
|
22
24
|
defaultValue?: any;
|
|
@@ -69,7 +71,8 @@ export type SerializedVariableKind = 'response' | 'outcome' | 'template' | 'cont
|
|
|
69
71
|
export interface SerializedItemSessionVariable {
|
|
70
72
|
identifier: string;
|
|
71
73
|
kind: SerializedVariableKind;
|
|
72
|
-
|
|
74
|
+
/** Omitted for record cardinality. */
|
|
75
|
+
baseType?: VariableBaseType;
|
|
73
76
|
cardinality: VariableCardinality;
|
|
74
77
|
value: any;
|
|
75
78
|
defaultValue?: any;
|
|
@@ -274,8 +277,26 @@ export interface PlayerConfig {
|
|
|
274
277
|
definition?: string;
|
|
275
278
|
}) => QtiValue>;
|
|
276
279
|
/**
|
|
277
|
-
*
|
|
278
|
-
*
|
|
280
|
+
* Host-controlled resolver for xi:include processing fragments.
|
|
281
|
+
* The player never fetches an authored href directly; package hosts must resolve
|
|
282
|
+
* and containment-check it, then return XML synchronously.
|
|
283
|
+
*/
|
|
284
|
+
resolveProcessingFragment?: ProcessingFragmentResolver;
|
|
285
|
+
/** Resource limits applied cumulatively while compiling external processing fragments. */
|
|
286
|
+
processingFragmentLimits?: {
|
|
287
|
+
/** Maximum nested xi:include depth. Default: 16. */
|
|
288
|
+
maxDepth?: number;
|
|
289
|
+
/** Maximum cumulative XML characters. Default: 2 MiB. */
|
|
290
|
+
maxCharacters?: number;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Portable Custom Interaction runtime configuration.
|
|
294
|
+
* A moduleResolver is required before any authored PCI code can execute.
|
|
295
|
+
*/
|
|
296
|
+
pci?: PciConfiguration;
|
|
297
|
+
/**
|
|
298
|
+
* @deprecated Use pci.baseUrl. Retained as a resolution-only compatibility alias;
|
|
299
|
+
* it never enables module loading without pci.moduleResolver.
|
|
279
300
|
*/
|
|
280
301
|
pciBaseUrl?: string;
|
|
281
302
|
/**
|