@pie-qti/player-elements 0.1.18 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +122 -127
  2. package/dist/{define-CLdVOnMl.js → define-BwFVHv-A.js} +4160 -3090
  3. package/dist/define-BwFVHv-A.js.map +1 -0
  4. package/dist/dist-DswyTalX.js +6731 -0
  5. package/dist/dist-DswyTalX.js.map +1 -0
  6. package/dist/{dist-CHcxiby5.js → dist-oe9UH-A2.js} +628 -583
  7. package/dist/dist-oe9UH-A2.js.map +1 -0
  8. package/dist/{element-Bekvepqe.js → element-BiInkn5Q.js} +2 -2
  9. package/dist/{element-Bekvepqe.js.map → element-BiInkn5Q.js.map} +1 -1
  10. package/dist/{element-class-C8OTgYHE-DsvwOAOP.js → element-class-CILJ4Ls7-rJWb-Gwb.js} +12421 -11624
  11. package/dist/element-class-CILJ4Ls7-rJWb-Gwb.js.map +1 -0
  12. package/dist/elements.js +3 -3
  13. package/dist/index.js +3 -3
  14. package/dist/item-toolbar-element-t_zI1vE6.js +1892 -0
  15. package/dist/item-toolbar-element-t_zI1vE6.js.map +1 -0
  16. package/dist/{mathlive.min-DeR46YTX-DamfKay_.js → mathlive.min-DeR46YTX-D-KAmiue.js} +1 -1
  17. package/dist/{mathlive.min-DeR46YTX-DamfKay_.js.map → mathlive.min-DeR46YTX-D-KAmiue.js.map} +1 -1
  18. package/dist/pie-assessment-toolkit-element-RzBk8WVs.js +7113 -0
  19. package/dist/pie-assessment-toolkit-element-RzBk8WVs.js.map +1 -0
  20. package/dist/pie-tool-calculator-GW-LhvB_.js +6905 -0
  21. package/dist/pie-tool-calculator-GW-LhvB_.js.map +1 -0
  22. package/dist/public/api.d.ts +25 -11
  23. package/dist/public/elements.d.ts +1 -1
  24. package/dist/public/index.d.ts +1 -1
  25. package/dist/register-players.js +1 -1
  26. package/dist/register.js +50707 -49652
  27. package/dist/register.js.map +1 -1
  28. package/dist/resolveItems-DHNyVysE.js +7627 -0
  29. package/dist/resolveItems-DHNyVysE.js.map +1 -0
  30. package/dist/{root--0fyaoNu.js → root-CYGgRw16.js} +3 -3
  31. package/dist/root-CYGgRw16.js.map +1 -0
  32. package/dist/sre-CgK32OcY.js +17228 -0
  33. package/dist/sre-CgK32OcY.js.map +1 -0
  34. package/dist/{tag-names-ClLtKtXt.js → tag-names-OgMDHLpx.js} +2 -2
  35. package/dist/tag-names-OgMDHLpx.js.map +1 -0
  36. package/dist/tool-tts-inline-drDEIti_.js +3724 -0
  37. package/dist/tool-tts-inline-drDEIti_.js.map +1 -0
  38. package/package.json +11 -9
  39. package/dist/define-CLdVOnMl.js.map +0 -1
  40. package/dist/dist-CHcxiby5.js.map +0 -1
  41. package/dist/dist-DjmdIRjq.js +0 -1241
  42. package/dist/dist-DjmdIRjq.js.map +0 -1
  43. package/dist/element-class-C8OTgYHE-DsvwOAOP.js.map +0 -1
  44. package/dist/item-toolbar-element-CjJkgFQ3.js +0 -6086
  45. package/dist/item-toolbar-element-CjJkgFQ3.js.map +0 -1
  46. package/dist/pie-assessment-toolkit-element-DMRNOwrK.js +0 -28516
  47. package/dist/pie-assessment-toolkit-element-DMRNOwrK.js.map +0 -1
  48. package/dist/pie-tool-calculator-DBfkllu3.js +0 -2309
  49. package/dist/pie-tool-calculator-DBfkllu3.js.map +0 -1
  50. package/dist/resolveItems-Bp65Mj_Z.js +0 -7030
  51. package/dist/resolveItems-Bp65Mj_Z.js.map +0 -1
  52. package/dist/root--0fyaoNu.js.map +0 -1
  53. package/dist/tag-names-ClLtKtXt.js.map +0 -1
  54. package/dist/tool-tts-inline-BNjR51Di.js +0 -2641
  55. package/dist/tool-tts-inline-BNjR51Di.js.map +0 -1
package/README.md CHANGED
@@ -1,80 +1,75 @@
1
1
  # @pie-qti/player-elements
2
2
 
3
- Framework-agnostic **Web Components (Custom Elements)** for the QTI players in this repo.
3
+ Framework-neutral custom elements for item, section, and assessment delivery.
4
4
 
5
5
  ## Elements
6
6
 
7
7
  - `pie-qti-item-player`
8
8
  - `pie-qti-assessment-player`
9
+ - `pie-qti-section-player-splitpane`
10
+ - `pie-qti-section-player-vertical`
9
11
 
10
- ## Install
12
+ ## Install and register
11
13
 
12
14
  ```bash
13
15
  npm install @pie-qti/player-elements
14
16
  ```
15
17
 
16
- ## Register elements
17
-
18
18
  ```js
19
19
  import '@pie-qti/player-elements/register';
20
20
  ```
21
21
 
22
- `@pie-qti/player-elements/register` is the complete default browser runtime. It defines the player,
23
- section, and standard QTI interaction custom elements. Svelte and the default interaction
24
- implementation are bundled behind this entry and are not application imports. The published
25
- package has no runtime dependencies, and its public declarations use framework-neutral browser
26
- contracts rather than exposing Svelte or internal workspace packages.
22
+ The registration entry bundles the player, section, and standard interaction implementations. The
23
+ published package declares `@pie-qti/item-player` as its runtime dependency; package managers install
24
+ it automatically. Public declarations use framework-neutral browser contracts and do not expose
25
+ Svelte types.
27
26
 
28
- Alternatively, install the loader and make one idempotent load call:
27
+ The main `@pie-qti/player-elements` entry is registration-free and SSR-safe. Import constructors and
28
+ definition helpers from `@pie-qti/player-elements/elements` for manual registration. Advanced hosts
29
+ that provide their own interaction elements can import `@pie-qti/player-elements/register-players`
30
+ to register only the four player/section elements.
29
31
 
30
- ```bash
31
- npm install @pie-qti/web-component-loaders
32
- ```
32
+ ## Item element
33
33
 
34
34
  ```js
35
- import { loadPieQtiPlayerElements } from '@pie-qti/web-component-loaders';
36
-
37
- await loadPieQtiPlayerElements();
35
+ const item = document.createElement('pie-qti-item-player');
36
+ item.itemXml = qtiItemXml;
37
+ item.role = 'candidate';
38
+ item.plugins = definitionPlugins;
39
+ item.security = securityPolicy;
40
+ item.addEventListener('response-change', (event) => {
41
+ console.log(event.detail.responseId, event.detail.responses);
42
+ });
43
+ document.body.append(item);
44
+
45
+ const result = item.submit();
38
46
  ```
39
47
 
40
- The main `@pie-qti/player-elements` entry is registration-free and safe to import during SSR; it
41
- retains the item element class without defining its tag. Import all browser constructors and
42
- definition helpers from `@pie-qti/player-elements/elements` when you need manual registration.
43
- Advanced hosts that provide their own interaction elements can import
44
- `@pie-qti/player-elements/register-players`, which registers only the player and section elements.
45
-
46
- > **Security boundary (2026-07-13):** the former gap-match and section-TTS raw-markup paths now use
47
- > the shared sanitizer, and custom-element parsing/resource limits are enabled by default. Same-DOM
48
- > sanitization is not a JavaScript sandbox; content that is not trusted to run in the host origin
49
- > should still be delivered through a suitably sandboxed, cross-origin iframe.
48
+ Attribute-backed properties are `itemXml`, `role`, and `disabled`. JavaScript-only properties are:
50
49
 
51
- ## `pie-qti-item-player`
50
+ - `session` — an existing authoritative `ItemSession`; the element borrows it and never owns an
51
+ injected session;
52
+ - `plugins` — immutable `AssessmentItemDefinitionPlugin` descriptors used only when the element
53
+ creates its own definition/session;
54
+ - `renderItemBodyRubrics`, `typeset`, `i18n`, `security`, `pnp`, `deliveryContext`, `pci`,
55
+ `resolveProcessingFragment`, `processingFragmentLimits`, and `responses`.
52
56
 
53
- ### Pass QTI
57
+ When `session` is supplied, its definition-fixed role and mutable state are authoritative. Do not
58
+ create a second session for the same rendered attempt.
54
59
 
55
- Prefer setting the XML via property (attributes are awkward for large XML strings):
60
+ Events are typed, bubbling, and composed:
56
61
 
57
62
  ```js
58
- import '@pie-qti/player-elements/register';
59
-
60
- const el = document.querySelector('pie-qti-item-player');
61
- el.itemXml = qtiItemXmlString;
62
- el.role = 'candidate'; // QTI role/view actor
63
+ item.addEventListener('ready', () => {});
64
+ item.addEventListener('response-change', (event) => {});
65
+ item.addEventListener('submit', (event) => {});
66
+ item.addEventListener('complete', (event) => {});
63
67
  ```
64
68
 
65
- Attribute-backed properties are `itemXml`, `role`, and `disabled`. JS-only properties currently
66
- include `renderItemBodyRubrics`, `typeset`, `i18n`, `security`, `pnp`, `deliveryContext`,
67
- `resolveProcessingFragment`, `processingFragmentLimits`, `pci`, and `responses`.
68
-
69
- Portable Custom Interaction execution is disabled by default. Opt in with a host-owned allow-list;
70
- the player does not import authored module paths itself:
69
+ Portable Custom Interaction execution is disabled until the host supplies an allow-listed resolver:
71
70
 
72
71
  ```js
73
- const trustedPciModules = new Map([
74
- ['modules/chem-editor.js', () => import('./trusted-pci/chem-editor.js')]
75
- ]);
76
-
77
- el.pci = {
72
+ item.pci = {
78
73
  baseUrl: 'https://content.example/items/item-1/',
79
74
  moduleResolver(_resolvedUrl, { authoredPath }) {
80
75
  const load = trustedPciModules.get(authoredPath);
@@ -84,113 +79,113 @@ el.pci = {
84
79
  };
85
80
  ```
86
81
 
87
- ### Listen for interactions/responses
82
+ ## Assessment element
88
83
 
89
- ```js
90
- el.addEventListener('ready', () => console.log('ready'));
91
- el.addEventListener('response-change', (event) => console.log(event.detail));
92
- el.addEventListener('submit', (event) => console.log(event.detail));
93
- el.addEventListener('complete', (event) => console.log(event.detail));
94
- ```
95
-
96
- These custom events are typed, bubbling, and composed. Existing `onResponseChange`, `onSubmit`, and
97
- `onComplete` callback properties remain available for compatibility.
98
-
99
- Score the current responses imperatively when the host owns the submit UI:
84
+ ### Authoritative backend delivery
100
85
 
101
86
  ```js
102
- const result = el.submit();
87
+ const assessment = document.createElement('pie-qti-assessment-player');
88
+ assessment.backend = backend;
89
+ assessment.initSession = {
90
+ assessmentId: 'assessment-1',
91
+ candidateId: 'candidate-1'
92
+ };
93
+ assessment.config = {
94
+ plugins: definitionPlugins,
95
+ showSections: true,
96
+ allowSectionNavigation: true,
97
+ showProgress: true
98
+ };
99
+ document.body.append(assessment);
103
100
  ```
104
101
 
105
- TypeScript users get `HTMLElementTagNameMap` inference for all four player element tag names. Import
106
- runtime constructors from the browser-only entry when needed:
102
+ `backend`, `initSession`, `assessmentId`, `candidateId`, `config`, `security`, and `pci` are
103
+ JavaScript properties. `config.plugins` is propagated to every compiled item definition.
107
104
 
108
- ```ts
109
- import { QtiItemPlayerElement } from '@pie-qti/player-elements/elements';
110
- ```
105
+ ### Explicit reference/preview delivery
111
106
 
112
- ## `pie-qti-assessment-player`
113
-
114
- ### Standard (B): pass `assessmentTest` XML + base URL for `href` item resolution
107
+ Raw assessment XML must opt into the local answer-bearing adapter:
115
108
 
116
109
  ```js
117
- import '@pie-qti/player-elements/register';
118
-
119
- const el = document.querySelector('pie-qti-assessment-player');
120
- el.referenceMode = true; // explicit preview/offline mode; see security boundary below
121
- el.assessmentTestXml = assessmentTestXmlString; // QTI <assessmentTest>...</assessmentTest>
122
- el.itemBaseUrl = 'https://my-cdn.example.com/qti/'; // used to resolve assessmentItemRef@href
123
- ```
124
-
125
- ### Fallback/convenience (A): pass `assessmentTest` XML + an in-memory item map
126
-
127
- ```js
128
- import '@pie-qti/player-elements/register';
129
-
130
- const el = document.querySelector('pie-qti-assessment-player');
131
- el.referenceMode = true; // explicit preview/offline mode
132
- el.assessmentTestXml = assessmentTestXmlString;
133
-
134
- // Map keys can be either the assessmentItemRef@href value OR the assessmentItemRef@identifier
135
- el.items = {
110
+ const assessment = document.createElement('pie-qti-assessment-player');
111
+ assessment.referenceMode = true;
112
+ assessment.assessmentTestXml = assessmentTestXml;
113
+ assessment.items = {
136
114
  'items/item-1.xml': item1Xml,
137
115
  'ITEM-2': item2Xml
138
116
  };
117
+ document.body.append(assessment);
139
118
  ```
140
119
 
141
- ### (Optional) config
120
+ Instead of `items`, set `itemBaseUrl` for bounded `assessmentItemRef@href` resolution and optionally
121
+ configure `itemFetchPolicy`. Reference mode puts item XML, correct answers, and scoring rules in the
122
+ browser. It is for demos/offline preview, not authoritative assessment delivery.
123
+
124
+ Navigation and submission modes come from the QTI assessment structure; `config` does not override
125
+ them.
142
126
 
143
127
  ```js
144
- el.config = {
145
- role: 'candidate', // QTI role/view actor
146
- showSections: true
147
- };
128
+ assessment.addEventListener('ready', () => {});
129
+ assessment.addEventListener('load-start', () => {});
130
+ assessment.addEventListener('load-end', () => {});
131
+ assessment.addEventListener('load-error', (event) => console.error(event.detail.message));
132
+ assessment.addEventListener('item-change', (event) => {});
133
+ assessment.addEventListener('section-change', (event) => {});
134
+ assessment.addEventListener('response-change', (event) => {});
135
+ assessment.addEventListener('submit', (event) => {});
136
+ assessment.addEventListener('complete', () => {});
137
+
138
+ await assessment.next();
139
+ await assessment.previous();
140
+ await assessment.navigateTo(0);
141
+ await assessment.navigateToSection('section-1');
142
+ const results = await assessment.submit();
143
+ const state = assessment.getState();
144
+ await assessment.restoreState(state);
148
145
  ```
149
146
 
150
- The assessment element also exposes the same JS-only `.pci` property. It is propagated through
151
- section rendering to every item player, so no Svelte API or implementation package is required:
147
+ ## Section elements
148
+
149
+ Section elements are standalone render adapters for a resolved section composition:
152
150
 
153
151
  ```js
154
- el.pci = {
155
- baseUrl: 'https://content.example/assessment/',
156
- moduleResolver: trustedPciResolver
157
- };
152
+ const section = document.createElement('pie-qti-section-player-splitpane');
153
+ section.composition = resolvedComposition;
154
+ section.security = securityPolicy;
155
+ section.pci = pciPolicy;
156
+ section.typeset = typesetMath;
157
+ section.addEventListener('qti-section-response-delta', (event) => {
158
+ console.log(event.detail);
159
+ });
160
+ document.body.append(section);
158
161
  ```
159
162
 
160
- The standalone split-pane and vertical section elements expose `.pci` with the same shape.
163
+ Use `pie-qti-section-player-vertical` with the same `composition`, `security`, `pci`, and `typeset`
164
+ properties for a vertical layout. The composition may carry the active item's live `session`; other
165
+ item refs carry response snapshots. Shared passages/rubrics and direct item rubrics remain separate
166
+ placement surfaces.
161
167
 
162
- Navigation and submission modes are read from the `assessmentTest` XML; setting them in `config`
163
- does not override the document.
168
+ ## TypeScript and manual registration
164
169
 
165
- > **Reference/demo boundary:** raw `assessmentTest` XML is accepted only after explicitly enabling
166
- > `referenceMode`; that mode uses the client-side `ReferenceBackendAdapter`, so correct responses,
167
- > scoring rules, and item XML reach the browser. For authoritative delivery, set the element's
168
- > `backend` and `initSession` properties (or `assessmentId` plus `candidateId`) instead. The local
169
- > XML facade still parses only a limited subset of `assessmentTest` semantics.
170
+ All four tags participate in `HTMLElementTagNameMap` inference:
170
171
 
171
- ### Listen for lifecycle + state events
172
-
173
- ```js
174
- el.addEventListener('item-change', (e) => console.log('item', e.detail));
175
- el.addEventListener('section-change', (e) => console.log('section', e.detail));
176
- el.addEventListener('response-change', (e) => console.log('responses', e.detail.responses));
177
- el.addEventListener('submit', (e) => console.log('results', e.detail.results));
178
- el.addEventListener('complete', () => console.log('complete'));
179
-
180
- // Optional loading lifecycle (useful if you rely on base-url fetching)
181
- el.addEventListener('load-start', () => console.log('loading...'));
182
- el.addEventListener('load-end', () => console.log('loaded'));
183
- el.addEventListener('load-error', (e) => console.error(e.detail.message));
172
+ ```ts
173
+ import {
174
+ QtiAssessmentPlayerElement,
175
+ QtiItemPlayerElement,
176
+ QtiSectionPlayerSplitPaneElement,
177
+ defineQtiPlayerElements
178
+ } from '@pie-qti/player-elements/elements';
179
+
180
+ defineQtiPlayerElements();
184
181
  ```
185
182
 
186
- ### Imperative API
183
+ The `/elements` entry is browser-only. Use the package root when only constants, parser helpers, or
184
+ public types are needed in SSR/tooling code.
187
185
 
188
- ```js
189
- await el.next();
190
- await el.previous();
191
- await el.navigateTo(0);
192
- await el.navigateToSection('section-1');
193
- const results = await el.submit();
194
- const state = el.getState();
195
- el.restoreState(state);
196
- ```
186
+ ## Security boundary
187
+
188
+ The runtime applies the shared sanitizer, URL policy, parsing limits, and optional Trusted Types
189
+ finalization to declared content sinks. Same-DOM sanitization is not a JavaScript sandbox. Content
190
+ that is not trusted to execute in the host origin should be delivered through a suitably sandboxed,
191
+ cross-origin iframe.