@pie-qti/item-player 0.1.6 → 0.1.7

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 (40) hide show
  1. package/dist/catalog/applyGlossaryTriggers.d.ts +2 -1
  2. package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
  3. package/dist/catalog/applyGlossaryTriggers.js +145 -30
  4. package/dist/catalog/glossaryAction.d.ts.map +1 -1
  5. package/dist/catalog/glossaryAction.js +14 -4
  6. package/dist/components/utils/stimulusRender.d.ts +17 -0
  7. package/dist/components/utils/stimulusRender.d.ts.map +1 -0
  8. package/dist/components/utils/stimulusRender.js +70 -0
  9. package/dist/components/utils/stylesheetRender.d.ts +4 -0
  10. package/dist/components/utils/stylesheetRender.d.ts.map +1 -0
  11. package/dist/components/utils/stylesheetRender.js +57 -0
  12. package/dist/core/Player.d.ts +37 -2
  13. package/dist/core/Player.d.ts.map +1 -1
  14. package/dist/core/Player.js +320 -48
  15. package/dist/element.js +1288 -924
  16. package/dist/element.js.map +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/pnp/applyPnp.d.ts.map +1 -1
  20. package/dist/pnp/applyPnp.js +9 -2
  21. package/dist/pnp/parsePnpXml.d.ts.map +1 -1
  22. package/dist/pnp/parsePnpXml.js +91 -3
  23. package/dist/pnp/types.d.ts +24 -1
  24. package/dist/pnp/types.d.ts.map +1 -1
  25. package/dist/types/index.d.ts +47 -0
  26. package/dist/types/index.d.ts.map +1 -1
  27. package/package.json +6 -6
  28. package/src/catalog/applyGlossaryTriggers.ts +174 -34
  29. package/src/catalog/glossaryAction.ts +14 -4
  30. package/src/components/ItemBody.svelte +36 -27
  31. package/src/components/utils/stimulusRender.ts +93 -0
  32. package/src/components/utils/stylesheetRender.ts +58 -0
  33. package/src/core/Player.ts +355 -48
  34. package/src/index.ts +1 -0
  35. package/src/pnp/applyPnp.ts +8 -2
  36. package/src/pnp/parsePnpXml.ts +102 -5
  37. package/src/pnp/types.ts +43 -1
  38. package/src/types/index.ts +53 -0
  39. package/src/__tests__/glossaryTriggers.test.ts +0 -411
  40. package/src/__tests__/pnp.test.ts +0 -250
@@ -1,250 +0,0 @@
1
- import { describe, it, expect } from 'bun:test';
2
- import { parsePnpXml } from '../pnp/parsePnpXml.js';
3
- import { applyPnpToRoot } from '../pnp/applyPnp.js';
4
- import { Player } from '../core/Player.js';
5
- import type { PnpProfile } from '../pnp/types.js';
6
-
7
- // ---------------------------------------------------------------------------
8
- // parsePnpXml
9
- // ---------------------------------------------------------------------------
10
-
11
- describe('parsePnpXml', () => {
12
- it('parses default color scheme', () => {
13
- const profile = parsePnpXml(`
14
- <personalNeedsProfile>
15
- <display>
16
- <colorScheme value="default"/>
17
- </display>
18
- </personalNeedsProfile>
19
- `);
20
- expect(profile.display?.colorScheme).toBe('default');
21
- });
22
-
23
- it.each(['blackwhite', 'whitenav', 'blackcream', 'yellowblue', 'medgray'] as const)(
24
- 'parses color scheme "%s"',
25
- (scheme) => {
26
- const profile = parsePnpXml(`
27
- <personalNeedsProfile>
28
- <display>
29
- <colorScheme value="${scheme}"/>
30
- </display>
31
- </personalNeedsProfile>
32
- `);
33
- expect(profile.display?.colorScheme).toBe(scheme);
34
- }
35
- );
36
-
37
- it('ignores unknown color scheme values', () => {
38
- const profile = parsePnpXml(`
39
- <personalNeedsProfile>
40
- <display>
41
- <colorScheme value="neon-pink"/>
42
- </display>
43
- </personalNeedsProfile>
44
- `);
45
- expect(profile.display?.colorScheme).toBeUndefined();
46
- });
47
-
48
- it('parses extendedTime', () => {
49
- const profile = parsePnpXml(`
50
- <personalNeedsProfile>
51
- <content>
52
- <extendedTime active="true" multiplier="1.5"/>
53
- </content>
54
- </personalNeedsProfile>
55
- `);
56
- expect(profile.content?.extendedTime).toEqual({ active: true, multiplier: 1.5 });
57
- });
58
-
59
- it('parses extendedTime with Infinity multiplier', () => {
60
- const profile = parsePnpXml(`
61
- <personalNeedsProfile>
62
- <content>
63
- <extendedTime active="true" multiplier="Infinity"/>
64
- </content>
65
- </personalNeedsProfile>
66
- `);
67
- expect(profile.content?.extendedTime?.multiplier).toBe(Infinity);
68
- });
69
-
70
- it('parses glossaryOnScreen', () => {
71
- const profile = parsePnpXml(`
72
- <personalNeedsProfile>
73
- <content>
74
- <glossaryOnScreen enabled="true"/>
75
- </content>
76
- </personalNeedsProfile>
77
- `);
78
- expect(profile.content?.glossaryOnScreen).toBe(true);
79
- });
80
-
81
- it('parses keywordTranslation', () => {
82
- const profile = parsePnpXml(`
83
- <personalNeedsProfile>
84
- <content>
85
- <keywordTranslation active="true" languageCode="es"/>
86
- </content>
87
- </personalNeedsProfile>
88
- `);
89
- expect(profile.content?.keywordTranslation).toEqual({ active: true, languageCode: 'es' });
90
- });
91
-
92
- it('parses eliminationTool', () => {
93
- const profile = parsePnpXml(`
94
- <personalNeedsProfile>
95
- <cognitive>
96
- <eliminationTool enabled="true"/>
97
- </cognitive>
98
- </personalNeedsProfile>
99
- `);
100
- expect(profile.cognitive?.eliminationTool).toBe(true);
101
- });
102
-
103
- it('silently ignores unknown child elements', () => {
104
- expect(() =>
105
- parsePnpXml(`
106
- <personalNeedsProfile>
107
- <display>
108
- <unknownFutureThing value="42"/>
109
- </display>
110
- <futureSection>
111
- <anotherThing/>
112
- </futureSection>
113
- </personalNeedsProfile>
114
- `)
115
- ).not.toThrow();
116
- });
117
-
118
- it('returns empty profile for empty input', () => {
119
- const profile = parsePnpXml('');
120
- expect(profile).toEqual({});
121
- });
122
-
123
- it('returns empty profile when no recognized root element', () => {
124
- // parsePnpXml with an unrecognised root gracefully returns {}
125
- const profile = parsePnpXml('<somethingElse><display/></somethingElse>');
126
- expect(profile).toEqual({});
127
- });
128
- });
129
-
130
- // ---------------------------------------------------------------------------
131
- // applyPnpToRoot — uses a minimal object that satisfies the HTMLElement contract
132
- // ---------------------------------------------------------------------------
133
-
134
- function makeEl(): HTMLElement {
135
- const attrs: Record<string, string> = {};
136
- return {
137
- setAttribute(k: string, v: string) { attrs[k] = v; },
138
- removeAttribute(k: string) { delete attrs[k]; },
139
- hasAttribute(k: string) { return k in attrs; },
140
- getAttribute(k: string) { return attrs[k] ?? null; },
141
- } as unknown as HTMLElement;
142
- }
143
-
144
- describe('applyPnpToRoot', () => {
145
- it('sets data-qti-colorscheme for a non-default scheme', () => {
146
- const el = makeEl();
147
- applyPnpToRoot(el, { display: { colorScheme: 'blackwhite' } });
148
- expect(el.getAttribute('data-qti-colorscheme')).toBe('blackwhite');
149
- });
150
-
151
- it('removes the attribute for "default" scheme', () => {
152
- const el = makeEl();
153
- el.setAttribute('data-qti-colorscheme', 'blackwhite');
154
- applyPnpToRoot(el, { display: { colorScheme: 'default' } });
155
- expect(el.hasAttribute('data-qti-colorscheme')).toBe(false);
156
- });
157
-
158
- it('removes the attribute when pnp is undefined', () => {
159
- const el = makeEl();
160
- el.setAttribute('data-qti-colorscheme', 'blackwhite');
161
- applyPnpToRoot(el, undefined);
162
- expect(el.hasAttribute('data-qti-colorscheme')).toBe(false);
163
- });
164
-
165
- it('removes the attribute when colorScheme is undefined', () => {
166
- const el = makeEl();
167
- el.setAttribute('data-qti-colorscheme', 'blackwhite');
168
- applyPnpToRoot(el, { display: {} });
169
- expect(el.hasAttribute('data-qti-colorscheme')).toBe(false);
170
- });
171
-
172
- it.each(['blackwhite', 'whitenav', 'blackcream', 'yellowblue', 'medgray'] as const)(
173
- 'sets correct attribute value for scheme "%s"',
174
- (scheme) => {
175
- const el = makeEl();
176
- applyPnpToRoot(el, { display: { colorScheme: scheme } });
177
- expect(el.getAttribute('data-qti-colorscheme')).toBe(scheme);
178
- }
179
- );
180
- });
181
-
182
- // ---------------------------------------------------------------------------
183
- // Player.applyPnp / Player.updatePnp
184
- // ---------------------------------------------------------------------------
185
-
186
- const MINIMAL_ITEM_XML = `<?xml version="1.0" encoding="UTF-8"?>
187
- <assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2"
188
- identifier="test" title="Test" adaptive="false" timeDependent="false">
189
- <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
190
- <outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float"/>
191
- <itemBody><choiceInteraction responseIdentifier="RESPONSE" maxChoices="1">
192
- <simpleChoice identifier="A">Alpha</simpleChoice>
193
- <simpleChoice identifier="B">Beta</simpleChoice>
194
- </choiceInteraction></itemBody>
195
- </assessmentItem>`;
196
-
197
- describe('Player PNP integration', () => {
198
- it('applyPnp sets the color scheme attribute on the root element', () => {
199
- const player = new Player({
200
- itemXml: MINIMAL_ITEM_XML,
201
- pnp: { display: { colorScheme: 'yellowblue' } },
202
- });
203
- const root = makeEl();
204
- player.applyPnp(root);
205
- expect(root.getAttribute('data-qti-colorscheme')).toBe('yellowblue');
206
- });
207
-
208
- it('updatePnp changes the attribute without re-parsing the item', () => {
209
- const player = new Player({ itemXml: MINIMAL_ITEM_XML });
210
- const root = makeEl();
211
- player.applyPnp(root);
212
-
213
- expect(root.hasAttribute('data-qti-colorscheme')).toBe(false);
214
-
215
- player.updatePnp({ display: { colorScheme: 'blackwhite' } });
216
- expect(root.getAttribute('data-qti-colorscheme')).toBe('blackwhite');
217
- });
218
-
219
- it('updatePnp deep-merges without losing other fields', () => {
220
- const player = new Player({
221
- itemXml: MINIMAL_ITEM_XML,
222
- pnp: { cognitive: { eliminationTool: true }, display: { colorScheme: 'blackwhite' } },
223
- });
224
- const root = makeEl();
225
- player.applyPnp(root);
226
-
227
- player.updatePnp({ display: { colorScheme: 'medgray' } });
228
-
229
- expect(root.getAttribute('data-qti-colorscheme')).toBe('medgray');
230
- expect(player.getPnp()?.cognitive?.eliminationTool).toBe(true);
231
- });
232
-
233
- it('updatePnp to default removes the attribute', () => {
234
- const player = new Player({
235
- itemXml: MINIMAL_ITEM_XML,
236
- pnp: { display: { colorScheme: 'blackwhite' } },
237
- });
238
- const root = makeEl();
239
- player.applyPnp(root);
240
-
241
- player.updatePnp({ display: { colorScheme: 'default' } });
242
- expect(root.hasAttribute('data-qti-colorscheme')).toBe(false);
243
- });
244
-
245
- it('getPnp returns the current profile', () => {
246
- const pnp: PnpProfile = { cognitive: { eliminationTool: true } };
247
- const player = new Player({ itemXml: MINIMAL_ITEM_XML, pnp });
248
- expect(player.getPnp()?.cognitive?.eliminationTool).toBe(true);
249
- });
250
- });