@pie-qti/qti-common 0.1.0
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 +356 -0
- package/dist/element-mapper/ElementNameMapper.d.ts +67 -0
- package/dist/element-mapper/ElementNameMapper.d.ts.map +1 -0
- package/dist/element-mapper/ElementNameMapper.js +2 -0
- package/dist/element-mapper/ElementNameMapper.js.map +1 -0
- package/dist/element-mapper/Qti2xElementNameMapper.d.ts +38 -0
- package/dist/element-mapper/Qti2xElementNameMapper.d.ts.map +1 -0
- package/dist/element-mapper/Qti2xElementNameMapper.js +47 -0
- package/dist/element-mapper/Qti2xElementNameMapper.js.map +1 -0
- package/dist/element-mapper/Qti3ElementNameMapper.d.ts +50 -0
- package/dist/element-mapper/Qti3ElementNameMapper.d.ts.map +1 -0
- package/dist/element-mapper/Qti3ElementNameMapper.js +224 -0
- package/dist/element-mapper/Qti3ElementNameMapper.js.map +1 -0
- package/dist/element-mapper/index.d.ts +4 -0
- package/dist/element-mapper/index.d.ts.map +1 -0
- package/dist/element-mapper/index.js +3 -0
- package/dist/element-mapper/index.js.map +1 -0
- package/dist/element-mapper/qti3-element-mappings.d.ts +448 -0
- package/dist/element-mapper/qti3-element-mappings.d.ts.map +1 -0
- package/dist/element-mapper/qti3-element-mappings.js +320 -0
- package/dist/element-mapper/qti3-element-mappings.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/parser-factory.d.ts +111 -0
- package/dist/parser-factory.d.ts.map +1 -0
- package/dist/parser-factory.js +120 -0
- package/dist/parser-factory.js.map +1 -0
- package/dist/version-detection/detectQtiVersion.d.ts +24 -0
- package/dist/version-detection/detectQtiVersion.d.ts.map +1 -0
- package/dist/version-detection/detectQtiVersion.js +129 -0
- package/dist/version-detection/detectQtiVersion.js.map +1 -0
- package/dist/version-detection/index.d.ts +3 -0
- package/dist/version-detection/index.d.ts.map +1 -0
- package/dist/version-detection/index.js +2 -0
- package/dist/version-detection/index.js.map +1 -0
- package/dist/xml/attributes.d.ts +78 -0
- package/dist/xml/attributes.d.ts.map +1 -0
- package/dist/xml/attributes.js +120 -0
- package/dist/xml/attributes.js.map +1 -0
- package/dist/xml/index.d.ts +2 -0
- package/dist/xml/index.d.ts.map +1 -0
- package/dist/xml/index.js +2 -0
- package/dist/xml/index.js.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# @pie-qti/qti-common
|
|
2
|
+
|
|
3
|
+
Shared utilities and abstractions for QTI 2.x and QTI 3.0 support.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides the foundational layer for version-agnostic QTI processing in PIE-QTI. It handles the naming differences between QTI 2.x (camelCase) and QTI 3.0 (kebab-case with `qti-` prefix) through a unified abstraction layer.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **Element Name Mapping** — Convert between QTI version-specific element names and canonical form
|
|
12
|
+
- **Version Detection** — Auto-detect QTI 2.0, 2.1, 2.2, or 3.0 from XML
|
|
13
|
+
- **Smart Attribute Accessors** — Case-insensitive attribute lookup (handles both camelCase and kebab-case)
|
|
14
|
+
- **Parser Factory** — Automatic parser configuration based on QTI version
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### Auto-detect QTI Version
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { createQtiParser, isQti3 } from '@pie-qti/qti-common';
|
|
22
|
+
|
|
23
|
+
const xml = `
|
|
24
|
+
<qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0">
|
|
25
|
+
...
|
|
26
|
+
</qti-assessment-item>
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
// Detect version and get appropriate mapper
|
|
30
|
+
const { mapper, version } = createQtiParser(xml);
|
|
31
|
+
console.log(version); // "3.0"
|
|
32
|
+
console.log(isQti3(xml)); // true
|
|
33
|
+
|
|
34
|
+
// Use mapper to convert element names
|
|
35
|
+
const canonicalName = mapper.toCanonical('qti-choice-interaction');
|
|
36
|
+
// → "choiceinteraction"
|
|
37
|
+
|
|
38
|
+
const nativeName = mapper.toNative('choiceinteraction');
|
|
39
|
+
// → "qti-choice-interaction" (QTI 3.0) or "choiceInteraction" (QTI 2.x)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Element Name Mapping
|
|
43
|
+
|
|
44
|
+
The package provides mappers for both QTI versions:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { Qti2ElementNameMapper, Qti3ElementNameMapper } from '@pie-qti/qti-common';
|
|
48
|
+
|
|
49
|
+
// QTI 2.x (camelCase)
|
|
50
|
+
const qti2Mapper = new Qti2ElementNameMapper();
|
|
51
|
+
qti2Mapper.toCanonical('choiceInteraction'); // → "choiceinteraction"
|
|
52
|
+
qti2Mapper.toNative('choiceinteraction'); // → "choiceInteraction"
|
|
53
|
+
|
|
54
|
+
// QTI 3.0 (kebab-case with qti- prefix)
|
|
55
|
+
const qti3Mapper = new Qti3ElementNameMapper();
|
|
56
|
+
qti3Mapper.toCanonical('qti-choice-interaction'); // → "choiceinteraction"
|
|
57
|
+
qti3Mapper.toNative('choiceinteraction'); // → "qti-choice-interaction"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Smart Attribute Accessors
|
|
61
|
+
|
|
62
|
+
The package provides attribute accessors that work with both naming conventions:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { getAttribute, getNumberAttribute, getBooleanAttribute } from '@pie-qti/qti-common';
|
|
66
|
+
|
|
67
|
+
// Works with both QTI 2.x and 3.0 attributes
|
|
68
|
+
const element = doc.querySelector('qti-response-declaration');
|
|
69
|
+
|
|
70
|
+
// QTI 3.0 uses kebab-case: base-type
|
|
71
|
+
getAttribute(element, 'base-type'); // ✓ Returns "identifier"
|
|
72
|
+
|
|
73
|
+
// But camelCase also works (smart fallback)
|
|
74
|
+
getAttribute(element, 'baseType'); // ✓ Also returns "identifier"
|
|
75
|
+
|
|
76
|
+
// Typed accessors
|
|
77
|
+
getNumberAttribute(element, 'max-choices', 1); // Returns number
|
|
78
|
+
getBooleanAttribute(element, 'shuffle'); // Returns boolean
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## QTI 2.x vs 3.0 Naming Differences
|
|
82
|
+
|
|
83
|
+
### Element Names
|
|
84
|
+
|
|
85
|
+
| Canonical (Internal) | QTI 2.x | QTI 3.0 |
|
|
86
|
+
|---------------------|---------|---------|
|
|
87
|
+
| `assessmentitem` | `assessmentItem` | `qti-assessment-item` |
|
|
88
|
+
| `itembody` | `itemBody` | `qti-item-body` |
|
|
89
|
+
| `responsedeclaration` | `responseDeclaration` | `qti-response-declaration` |
|
|
90
|
+
| `choiceinteraction` | `choiceInteraction` | `qti-choice-interaction` |
|
|
91
|
+
| `simplechoice` | `simpleChoice` | `qti-simple-choice` |
|
|
92
|
+
| `matchinteraction` | `matchInteraction` | `qti-match-interaction` |
|
|
93
|
+
| `textentryinteraction` | `textEntryInteraction` | `qti-text-entry-interaction` |
|
|
94
|
+
|
|
95
|
+
### Attribute Names
|
|
96
|
+
|
|
97
|
+
| Canonical (Internal) | QTI 2.x | QTI 3.0 |
|
|
98
|
+
|---------------------|---------|---------|
|
|
99
|
+
| `baseType` | `baseType` | `base-type` |
|
|
100
|
+
| `responseIdentifier` | `responseIdentifier` | `response-identifier` |
|
|
101
|
+
| `maxChoices` | `maxChoices` | `max-choices` |
|
|
102
|
+
| `cardinality` | `cardinality` | `cardinality` |
|
|
103
|
+
|
|
104
|
+
**Note:** Not all attributes changed in QTI 3.0. Simple names like `identifier`, `shuffle`, and `cardinality` remain the same.
|
|
105
|
+
|
|
106
|
+
## Architecture
|
|
107
|
+
|
|
108
|
+
### How Version-Agnostic Processing Works
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
┌────────────────┐
|
|
112
|
+
│ QTI 2.x XML │
|
|
113
|
+
│ <choiceInter- │
|
|
114
|
+
│ action> │
|
|
115
|
+
└────────┬───────┘
|
|
116
|
+
│
|
|
117
|
+
├──► Qti2ElementNameMapper
|
|
118
|
+
│ toCanonical('choiceInteraction')
|
|
119
|
+
│ ↓
|
|
120
|
+
│ "choiceinteraction"
|
|
121
|
+
│ ↓
|
|
122
|
+
└──► Common Processing (AST, Extractors)
|
|
123
|
+
↓
|
|
124
|
+
InteractionData
|
|
125
|
+
↓
|
|
126
|
+
UI Components
|
|
127
|
+
|
|
128
|
+
┌────────────────┐
|
|
129
|
+
│ QTI 3.0 XML │
|
|
130
|
+
│ <qti-choice- │
|
|
131
|
+
│ interaction> │
|
|
132
|
+
└────────┬───────┘
|
|
133
|
+
│
|
|
134
|
+
├──► Qti3ElementNameMapper
|
|
135
|
+
│ toCanonical('qti-choice-interaction')
|
|
136
|
+
│ ↓
|
|
137
|
+
│ "choiceinteraction"
|
|
138
|
+
│ ↓
|
|
139
|
+
└──► Common Processing (AST, Extractors)
|
|
140
|
+
↓
|
|
141
|
+
InteractionData
|
|
142
|
+
↓
|
|
143
|
+
UI Components
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Benefits of This Architecture
|
|
147
|
+
|
|
148
|
+
1. **Single Codebase** — Processing logic works for both QTI 2.x and 3.0
|
|
149
|
+
2. **Zero Breaking Changes** — Existing QTI 2.x code continues to work
|
|
150
|
+
3. **Feature Detection** — Version-specific features (PCI, PNP) detected automatically
|
|
151
|
+
4. **Extensibility** — New QTI versions can be added by implementing `ElementNameMapper`
|
|
152
|
+
|
|
153
|
+
## Version Detection
|
|
154
|
+
|
|
155
|
+
The package auto-detects QTI version from:
|
|
156
|
+
|
|
157
|
+
1. **XML Namespace**:
|
|
158
|
+
- QTI 3.0: `http://www.imsglobal.org/xsd/imsqtiasi_v3p0`
|
|
159
|
+
- QTI 2.2: `http://www.imsglobal.org/xsd/imsqti_v2p2`
|
|
160
|
+
- QTI 2.1: `http://www.imsglobal.org/xsd/imsqti_v2p1`
|
|
161
|
+
- QTI 2.0: `http://www.imsglobal.org/xsd/imsqti_v2p0`
|
|
162
|
+
|
|
163
|
+
2. **Root Element Name**:
|
|
164
|
+
- QTI 3.0: `<qti-assessment-item>`
|
|
165
|
+
- QTI 2.x: `<assessmentItem>`
|
|
166
|
+
|
|
167
|
+
3. **Version Attribute** (if namespace/element name unclear):
|
|
168
|
+
- `version="2.2"`, `version="2.1"`, etc.
|
|
169
|
+
|
|
170
|
+
## API Reference
|
|
171
|
+
|
|
172
|
+
### Parser Factory
|
|
173
|
+
|
|
174
|
+
#### `createQtiParser(xml: string, options?: { version?: string })`
|
|
175
|
+
|
|
176
|
+
Creates appropriate parser configuration for the given QTI XML.
|
|
177
|
+
|
|
178
|
+
**Returns**: `{ mapper: ElementNameMapper, version: string }`
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
const { mapper, version } = createQtiParser(xml);
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### `isQti3(xml: string): boolean`
|
|
185
|
+
|
|
186
|
+
Quick check if XML is QTI 3.0.
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
if (isQti3(xml)) {
|
|
190
|
+
console.log('This is QTI 3.0 content');
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Element Name Mappers
|
|
195
|
+
|
|
196
|
+
#### `ElementNameMapper` (interface)
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
interface ElementNameMapper {
|
|
200
|
+
/** Convert version-specific name to canonical form */
|
|
201
|
+
toCanonical(elementName: string): string;
|
|
202
|
+
|
|
203
|
+
/** Convert canonical name to version-specific form */
|
|
204
|
+
toNative(canonicalName: string): string;
|
|
205
|
+
|
|
206
|
+
/** Check if element name matches expected pattern */
|
|
207
|
+
isValidElementName(elementName: string): boolean;
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
#### `Qti2ElementNameMapper`
|
|
212
|
+
|
|
213
|
+
Handles QTI 2.x camelCase element names.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const mapper = new Qti2ElementNameMapper();
|
|
217
|
+
mapper.toCanonical('choiceInteraction'); // → "choiceinteraction"
|
|
218
|
+
mapper.toNative('choiceinteraction'); // → "choiceInteraction"
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### `Qti3ElementNameMapper`
|
|
222
|
+
|
|
223
|
+
Handles QTI 3.0 kebab-case with `qti-` prefix.
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
const mapper = new Qti3ElementNameMapper();
|
|
227
|
+
mapper.toCanonical('qti-choice-interaction'); // → "choiceinteraction"
|
|
228
|
+
mapper.toNative('choiceinteraction'); // → "qti-choice-interaction"
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Attribute Accessors
|
|
232
|
+
|
|
233
|
+
#### `getAttribute(element: Element, name: string): string | null`
|
|
234
|
+
|
|
235
|
+
Smart attribute accessor that tries multiple naming conventions.
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
// Works with both 'base-type' and 'baseType'
|
|
239
|
+
const baseType = getAttribute(element, 'base-type');
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### `getNumberAttribute(element: Element, name: string, defaultValue?: number): number | null`
|
|
243
|
+
|
|
244
|
+
Get attribute as number.
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
const maxChoices = getNumberAttribute(element, 'max-choices', 1);
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### `getBooleanAttribute(element: Element, name: string, defaultValue?: boolean): boolean`
|
|
251
|
+
|
|
252
|
+
Get attribute as boolean.
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
const shuffle = getBooleanAttribute(element, 'shuffle', false);
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Integration with Players
|
|
259
|
+
|
|
260
|
+
### Item Player Integration
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { Player } from '@pie-qti/item-player';
|
|
264
|
+
import { createQtiParser } from '@pie-qti/qti-common';
|
|
265
|
+
|
|
266
|
+
const xml = `...(QTI 2.x or 3.0)...`;
|
|
267
|
+
const { mapper, version } = createQtiParser(xml);
|
|
268
|
+
|
|
269
|
+
const player = new Player(xml, {
|
|
270
|
+
elementNameMapper: mapper // Optional - auto-detected if not provided
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
console.log(`Playing ${version} content`);
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Transform Integration
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import { transformQtiToPie } from '@pie-qti/to-pie';
|
|
280
|
+
import { createQtiParser } from '@pie-qti/qti-common';
|
|
281
|
+
|
|
282
|
+
const xml = `...(QTI 2.x or 3.0)...`;
|
|
283
|
+
const { mapper, version } = createQtiParser(xml);
|
|
284
|
+
|
|
285
|
+
const pieItem = await transformQtiToPie(xml, {
|
|
286
|
+
elementNameMapper: mapper
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Migration Guide
|
|
291
|
+
|
|
292
|
+
### From QTI 2.x-only Code
|
|
293
|
+
|
|
294
|
+
**Before** (QTI 2.x only):
|
|
295
|
+
```typescript
|
|
296
|
+
const elements = doc.getElementsByTagName('choiceInteraction');
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**After** (QTI 2.x + 3.0):
|
|
300
|
+
```typescript
|
|
301
|
+
import { createQtiParser } from '@pie-qti/qti-common';
|
|
302
|
+
|
|
303
|
+
const { mapper } = createQtiParser(xml);
|
|
304
|
+
const tagName = mapper.toNative('choiceinteraction');
|
|
305
|
+
const elements = doc.getElementsByTagName(tagName);
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
**Even Better** (using existing extraction layer):
|
|
309
|
+
```typescript
|
|
310
|
+
// No changes needed! Extraction layer already uses mappers internally
|
|
311
|
+
const player = new Player(xml); // Works with both QTI 2.x and 3.0
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Attribute Handling Migration
|
|
315
|
+
|
|
316
|
+
**Before** (QTI 2.x only):
|
|
317
|
+
```typescript
|
|
318
|
+
const baseType = element.getAttribute('baseType');
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**After** (QTI 2.x + 3.0):
|
|
322
|
+
```typescript
|
|
323
|
+
import { getAttribute } from '@pie-qti/qti-common';
|
|
324
|
+
|
|
325
|
+
const baseType = getAttribute(element, 'baseType'); // Works for both!
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Testing
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
# Run tests
|
|
332
|
+
bun test
|
|
333
|
+
|
|
334
|
+
# Run with coverage
|
|
335
|
+
bun test --coverage
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Test fixtures are available in `src/__tests__/fixtures/`:
|
|
339
|
+
- `qti3-choice-single.xml` — Single-selection choice
|
|
340
|
+
- `qti3-choice-multiple.xml` — Multiple-selection choice
|
|
341
|
+
- `qti3-match-interaction.xml` — Match interaction
|
|
342
|
+
- `qti3-text-entry.xml` — Inline text entry
|
|
343
|
+
- `qti3-extended-text.xml` — Extended text response
|
|
344
|
+
- `qti3-order-interaction.xml` — Ordering interaction
|
|
345
|
+
- `qti3-hotspot-interaction.xml` — Image hotspot
|
|
346
|
+
|
|
347
|
+
## Related Packages
|
|
348
|
+
|
|
349
|
+
- [`@pie-qti/item-player`](../item-player/) — QTI 2.x and 3.0 item player
|
|
350
|
+
- [`@pie-qti/assessment-player`](../assessment-player/) — Multi-item assessment orchestration
|
|
351
|
+
- [`@pie-qti/qti-processing`](../qti-processing/) — Response processing engine
|
|
352
|
+
- [`@pie-qti/to-pie`](../to-pie/) — QTI → PIE transformation
|
|
353
|
+
|
|
354
|
+
## License
|
|
355
|
+
|
|
356
|
+
MIT
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for mapping between QTI version-specific element names and canonical forms.
|
|
3
|
+
*
|
|
4
|
+
* QTI 2.x uses camelCase (e.g., 'choiceInteraction', 'simpleChoice')
|
|
5
|
+
* QTI 3.0 uses kebab-case with qti- prefix (e.g., 'qti-choice-interaction', 'qti-simple-choice')
|
|
6
|
+
*
|
|
7
|
+
* This abstraction allows the parser and player to work with both versions
|
|
8
|
+
* by converting to/from a canonical lowercase form.
|
|
9
|
+
*/
|
|
10
|
+
export interface ElementNameMapper {
|
|
11
|
+
/**
|
|
12
|
+
* Convert QTI-version-specific element name to canonical lowercase form.
|
|
13
|
+
*
|
|
14
|
+
* @param elementName - The element name as it appears in the XML
|
|
15
|
+
* @returns Canonical lowercase name for internal processing
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // QTI 2.x
|
|
19
|
+
* toCanonical('choiceInteraction') // => 'choiceinteraction'
|
|
20
|
+
* toCanonical('simpleChoice') // => 'simplechoice'
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // QTI 3.0
|
|
24
|
+
* toCanonical('qti-choice-interaction') // => 'choiceinteraction'
|
|
25
|
+
* toCanonical('qti-simple-choice') // => 'simplechoice'
|
|
26
|
+
*/
|
|
27
|
+
toCanonical(elementName: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Convert canonical name back to version-specific form.
|
|
30
|
+
*
|
|
31
|
+
* @param canonicalName - Lowercase canonical name
|
|
32
|
+
* @returns Version-specific element name
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // QTI 2.x
|
|
36
|
+
* toNative('choiceinteraction') // => 'choiceInteraction'
|
|
37
|
+
* toNative('simplechoice') // => 'simpleChoice'
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // QTI 3.0
|
|
41
|
+
* toNative('choiceinteraction') // => 'qti-choice-interaction'
|
|
42
|
+
* toNative('simplechoice') // => 'qti-simple-choice'
|
|
43
|
+
*/
|
|
44
|
+
toNative(canonicalName: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Check if element name matches expected pattern for this QTI version.
|
|
47
|
+
*
|
|
48
|
+
* @param elementName - Element name to validate
|
|
49
|
+
* @returns true if valid for this version
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // QTI 2.x mapper
|
|
53
|
+
* isValidElementName('choiceInteraction') // => true
|
|
54
|
+
* isValidElementName('qti-choice-interaction') // => false
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // QTI 3.0 mapper
|
|
58
|
+
* isValidElementName('qti-choice-interaction') // => true
|
|
59
|
+
* isValidElementName('choiceInteraction') // => false
|
|
60
|
+
*/
|
|
61
|
+
isValidElementName(elementName: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Get the QTI version this mapper handles.
|
|
64
|
+
*/
|
|
65
|
+
readonly version: string;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=ElementNameMapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElementNameMapper.d.ts","sourceRoot":"","sources":["../../src/element-mapper/ElementNameMapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IACjC;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzC;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;IAExC;;;;;;;;;;;;;;;OAeG;IACH,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAEjD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElementNameMapper.js","sourceRoot":"","sources":["../../src/element-mapper/ElementNameMapper.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ElementNameMapper } from './ElementNameMapper.js';
|
|
2
|
+
/**
|
|
3
|
+
* Element name mapper for QTI 2.x (versions 2.0, 2.1, 2.2).
|
|
4
|
+
*
|
|
5
|
+
* QTI 2.x uses camelCase element names:
|
|
6
|
+
* - assessmentItem, itemBody, responseDeclaration
|
|
7
|
+
* - choiceInteraction, simpleChoice
|
|
8
|
+
* - responseProcessing, setOutcomeValue
|
|
9
|
+
*
|
|
10
|
+
* This mapper converts to/from lowercase canonical form for internal processing.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Qti2xElementNameMapper implements ElementNameMapper {
|
|
13
|
+
readonly version = "2.x";
|
|
14
|
+
/**
|
|
15
|
+
* Convert QTI 2.x camelCase name to canonical lowercase.
|
|
16
|
+
* @param elementName - camelCase element name
|
|
17
|
+
* @returns lowercase canonical name
|
|
18
|
+
*/
|
|
19
|
+
toCanonical(elementName: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Convert canonical lowercase to QTI 2.x camelCase.
|
|
22
|
+
* Note: This is a best-effort conversion. The original casing
|
|
23
|
+
* should be preserved when possible by the parser.
|
|
24
|
+
*
|
|
25
|
+
* @param canonicalName - lowercase canonical name
|
|
26
|
+
* @returns camelCase element name
|
|
27
|
+
*/
|
|
28
|
+
toNative(canonicalName: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Validate QTI 2.x element name pattern.
|
|
31
|
+
* QTI 2.x uses camelCase starting with lowercase letter.
|
|
32
|
+
*
|
|
33
|
+
* @param elementName - Element name to validate
|
|
34
|
+
* @returns true if valid camelCase pattern
|
|
35
|
+
*/
|
|
36
|
+
isValidElementName(elementName: string): boolean;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=Qti2xElementNameMapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Qti2xElementNameMapper.d.ts","sourceRoot":"","sources":["../../src/element-mapper/Qti2xElementNameMapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;;;;;;GASG;AACH,qBAAa,sBAAuB,YAAW,iBAAiB;IAC/D,QAAQ,CAAC,OAAO,SAAS;IAEzB;;;;OAIG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAIxC;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAMvC;;;;;;OAMG;IACH,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;CAKhD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Element name mapper for QTI 2.x (versions 2.0, 2.1, 2.2).
|
|
3
|
+
*
|
|
4
|
+
* QTI 2.x uses camelCase element names:
|
|
5
|
+
* - assessmentItem, itemBody, responseDeclaration
|
|
6
|
+
* - choiceInteraction, simpleChoice
|
|
7
|
+
* - responseProcessing, setOutcomeValue
|
|
8
|
+
*
|
|
9
|
+
* This mapper converts to/from lowercase canonical form for internal processing.
|
|
10
|
+
*/
|
|
11
|
+
export class Qti2xElementNameMapper {
|
|
12
|
+
version = '2.x';
|
|
13
|
+
/**
|
|
14
|
+
* Convert QTI 2.x camelCase name to canonical lowercase.
|
|
15
|
+
* @param elementName - camelCase element name
|
|
16
|
+
* @returns lowercase canonical name
|
|
17
|
+
*/
|
|
18
|
+
toCanonical(elementName) {
|
|
19
|
+
return elementName.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Convert canonical lowercase to QTI 2.x camelCase.
|
|
23
|
+
* Note: This is a best-effort conversion. The original casing
|
|
24
|
+
* should be preserved when possible by the parser.
|
|
25
|
+
*
|
|
26
|
+
* @param canonicalName - lowercase canonical name
|
|
27
|
+
* @returns camelCase element name
|
|
28
|
+
*/
|
|
29
|
+
toNative(canonicalName) {
|
|
30
|
+
// For QTI 2.x, we can return lowercase since XML is case-insensitive
|
|
31
|
+
// and our parser uses case-insensitive matching anyway
|
|
32
|
+
return canonicalName;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validate QTI 2.x element name pattern.
|
|
36
|
+
* QTI 2.x uses camelCase starting with lowercase letter.
|
|
37
|
+
*
|
|
38
|
+
* @param elementName - Element name to validate
|
|
39
|
+
* @returns true if valid camelCase pattern
|
|
40
|
+
*/
|
|
41
|
+
isValidElementName(elementName) {
|
|
42
|
+
// QTI 2.x: starts with lowercase, can contain uppercase letters and numbers
|
|
43
|
+
// Examples: assessmentItem, choiceInteraction, simpleChoice, html5div
|
|
44
|
+
return /^[a-z][a-zA-Z0-9]*$/.test(elementName);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=Qti2xElementNameMapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Qti2xElementNameMapper.js","sourceRoot":"","sources":["../../src/element-mapper/Qti2xElementNameMapper.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,OAAO,sBAAsB;IACzB,OAAO,GAAG,KAAK,CAAC;IAEzB;;;;OAIG;IACH,WAAW,CAAC,WAAmB;QAC9B,OAAO,WAAW,CAAC,WAAW,EAAE,CAAC;IAClC,CAAC;IAED;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAqB;QAC7B,qEAAqE;QACrE,uDAAuD;QACvD,OAAO,aAAa,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACH,kBAAkB,CAAC,WAAmB;QACrC,4EAA4E;QAC5E,sEAAsE;QACtE,OAAO,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAChD,CAAC;CACD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ElementNameMapper } from './ElementNameMapper.js';
|
|
2
|
+
/**
|
|
3
|
+
* Element name mapper for QTI 3.0.
|
|
4
|
+
*
|
|
5
|
+
* QTI 3.0 uses kebab-case element names with 'qti-' prefix:
|
|
6
|
+
* - qti-assessment-item, qti-item-body, qti-response-declaration
|
|
7
|
+
* - qti-choice-interaction, qti-simple-choice
|
|
8
|
+
* - qti-response-processing, qti-set-outcome-value
|
|
9
|
+
*
|
|
10
|
+
* This mapper converts to/from lowercase canonical form (without prefix) for internal processing.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Qti3ElementNameMapper implements ElementNameMapper {
|
|
13
|
+
readonly version = "3.0";
|
|
14
|
+
private readonly PREFIX;
|
|
15
|
+
/**
|
|
16
|
+
* Convert QTI 3.0 kebab-case name to canonical lowercase.
|
|
17
|
+
* Removes 'qti-' prefix and converts to lowercase.
|
|
18
|
+
*
|
|
19
|
+
* @param elementName - kebab-case element name with qti- prefix
|
|
20
|
+
* @returns lowercase canonical name without prefix
|
|
21
|
+
*/
|
|
22
|
+
toCanonical(elementName: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Convert canonical lowercase to QTI 3.0 kebab-case with qti- prefix.
|
|
25
|
+
*
|
|
26
|
+
* This converts canonical names like 'choiceinteraction' to 'qti-choice-interaction'.
|
|
27
|
+
*
|
|
28
|
+
* @param canonicalName - lowercase canonical name
|
|
29
|
+
* @returns kebab-case element name with qti- prefix
|
|
30
|
+
*/
|
|
31
|
+
toNative(canonicalName: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Validate QTI 3.0 element name pattern.
|
|
34
|
+
* QTI 3.0 uses kebab-case with 'qti-' prefix.
|
|
35
|
+
*
|
|
36
|
+
* @param elementName - Element name to validate
|
|
37
|
+
* @returns true if valid kebab-case pattern with qti- prefix
|
|
38
|
+
*/
|
|
39
|
+
isValidElementName(elementName: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Convert a canonical name to kebab-case.
|
|
42
|
+
* This is a best-effort conversion based on known QTI element patterns.
|
|
43
|
+
*
|
|
44
|
+
* @param name - Canonical lowercase name
|
|
45
|
+
* @returns kebab-case version
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
private toKebabCase;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=Qti3ElementNameMapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Qti3ElementNameMapper.d.ts","sourceRoot":"","sources":["../../src/element-mapper/Qti3ElementNameMapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;;;;;;GASG;AACH,qBAAa,qBAAsB,YAAW,iBAAiB;IAC9D,QAAQ,CAAC,OAAO,SAAS;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC;;;;;;OAMG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAWxC;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAWvC;;;;;;OAMG;IACH,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAWhD;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;CAuKnB"}
|