@pie-qti/qti-common 0.1.28 → 1.0.0-beta.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 +31 -86
- package/package.json +2 -3
- package/dist/accessibility/apip.d.ts +0 -66
- package/dist/accessibility/apip.js +0 -576
- package/dist/accessibility/apip.js.map +0 -1
- package/dist/accessibility/catalog-info.d.ts +0 -17
- package/dist/accessibility/catalog-info.js +0 -60
- package/dist/accessibility/catalog-info.js.map +0 -1
- package/dist/accessibility/catalog.d.ts +0 -53
- package/dist/accessibility/catalog.js +0 -68
- package/dist/accessibility/catalog.js.map +0 -1
- package/dist/accessibility/index.d.ts +0 -3
- package/dist/accessibility/index.js +0 -4
- package/dist/accessibility/index.js.map +0 -1
- package/dist/dom/assignProps.d.ts +0 -4
- package/dist/dom/assignProps.js +0 -9
- package/dist/dom/assignProps.js.map +0 -1
- package/dist/dom/svelteMountController.d.ts +0 -25
- package/dist/dom/svelteMountController.js +0 -131
- package/dist/dom/svelteMountController.js.map +0 -1
- package/dist/dom/touchDrag.d.ts +0 -10
- package/dist/dom/touchDrag.js +0 -141
- package/dist/dom/touchDrag.js.map +0 -1
- package/dist/element-mapper/AttributeNameMapper.d.ts +0 -66
- package/dist/element-mapper/AttributeNameMapper.js +0 -2
- package/dist/element-mapper/AttributeNameMapper.js.map +0 -1
- package/dist/element-mapper/ElementNameMapper.d.ts +0 -66
- package/dist/element-mapper/ElementNameMapper.js +0 -2
- package/dist/element-mapper/ElementNameMapper.js.map +0 -1
- package/dist/element-mapper/Qti2xAttributeNameMapper.d.ts +0 -27
- package/dist/element-mapper/Qti2xAttributeNameMapper.js +0 -38
- package/dist/element-mapper/Qti2xAttributeNameMapper.js.map +0 -1
- package/dist/element-mapper/Qti2xElementNameMapper.d.ts +0 -37
- package/dist/element-mapper/Qti2xElementNameMapper.js +0 -47
- package/dist/element-mapper/Qti2xElementNameMapper.js.map +0 -1
- package/dist/element-mapper/Qti3AttributeNameMapper.d.ts +0 -40
- package/dist/element-mapper/Qti3AttributeNameMapper.js +0 -87
- package/dist/element-mapper/Qti3AttributeNameMapper.js.map +0 -1
- package/dist/element-mapper/Qti3ElementNameMapper.d.ts +0 -14
- package/dist/element-mapper/Qti3ElementNameMapper.js +0 -39
- package/dist/element-mapper/Qti3ElementNameMapper.js.map +0 -1
- package/dist/element-mapper/index.d.ts +0 -8
- package/dist/element-mapper/index.js +0 -7
- package/dist/element-mapper/index.js.map +0 -1
- package/dist/element-mapper/qti2-to-qti3.d.ts +0 -36
- package/dist/element-mapper/qti2-to-qti3.js +0 -228
- package/dist/element-mapper/qti2-to-qti3.js.map +0 -1
- package/dist/element-mapper/qti3-attribute-map.d.ts +0 -8
- package/dist/element-mapper/qti3-attribute-map.js +0 -115
- package/dist/element-mapper/qti3-attribute-map.js.map +0 -1
- package/dist/element-mapper/qti3-element-mappings.d.ts +0 -538
- package/dist/element-mapper/qti3-element-mappings.js +0 -381
- package/dist/element-mapper/qti3-element-mappings.js.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -17
- package/dist/index.js.map +0 -1
- package/dist/parser-factory.d.ts +0 -137
- package/dist/parser-factory.js +0 -146
- package/dist/parser-factory.js.map +0 -1
- package/dist/version-detection/detectQtiVersion.d.ts +0 -23
- package/dist/version-detection/detectQtiVersion.js +0 -129
- package/dist/version-detection/detectQtiVersion.js.map +0 -1
- package/dist/version-detection/index.d.ts +0 -2
- package/dist/version-detection/index.js +0 -2
- package/dist/version-detection/index.js.map +0 -1
- package/dist/xml/attributes.d.ts +0 -77
- package/dist/xml/attributes.js +0 -120
- package/dist/xml/attributes.js.map +0 -1
package/README.md
CHANGED
|
@@ -41,26 +41,16 @@ const nativeName = mapper.toNative('choiceinteraction');
|
|
|
41
41
|
|
|
42
42
|
### Element Name Mapping
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { Qti2xElementNameMapper, Qti3ElementNameMapper } from '@pie-qti/qti-common';
|
|
48
|
-
|
|
49
|
-
// QTI 2.x (camelCase)
|
|
50
|
-
const qti2Mapper = new Qti2xElementNameMapper();
|
|
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
|
-
```
|
|
44
|
+
Mappers convert between QTI version-specific element names and the canonical internal form, so the
|
|
45
|
+
same processing code handles both versions. One round-trip caveat applies to QTI 2.x:
|
|
59
46
|
|
|
60
47
|
`Qti2xElementNameMapper.toNative()` returns the lowercase canonical spelling because the parser's
|
|
61
48
|
QTI 2.x matching is case-insensitive; it cannot reconstruct the original camelCase from a lowercase
|
|
62
49
|
name. Preserve the source spelling separately when exact XML serialization matters.
|
|
63
50
|
|
|
51
|
+
The full element and attribute naming tables, plus step-by-step migration guidance, are in
|
|
52
|
+
[`docs/QTI-3-MIGRATION-GUIDE.md`](../../docs/QTI-3-MIGRATION-GUIDE.md).
|
|
53
|
+
|
|
64
54
|
### Smart Attribute Accessors
|
|
65
55
|
|
|
66
56
|
The package provides attribute accessors that work with both naming conventions:
|
|
@@ -84,28 +74,14 @@ getBooleanAttribute(element, 'shuffle'); // Returns boolean
|
|
|
84
74
|
|
|
85
75
|
## QTI 2.x vs 3.0 Naming Differences
|
|
86
76
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
| `itembody` | `itemBody` | `qti-item-body` |
|
|
93
|
-
| `responsedeclaration` | `responseDeclaration` | `qti-response-declaration` |
|
|
94
|
-
| `choiceinteraction` | `choiceInteraction` | `qti-choice-interaction` |
|
|
95
|
-
| `simplechoice` | `simpleChoice` | `qti-simple-choice` |
|
|
96
|
-
| `matchinteraction` | `matchInteraction` | `qti-match-interaction` |
|
|
97
|
-
| `textentryinteraction` | `textEntryInteraction` | `qti-text-entry-interaction` |
|
|
98
|
-
|
|
99
|
-
### Attribute Names
|
|
100
|
-
|
|
101
|
-
| Canonical (Internal) | QTI 2.x | QTI 3.0 |
|
|
102
|
-
|---------------------|---------|---------|
|
|
103
|
-
| `baseType` | `baseType` | `base-type` |
|
|
104
|
-
| `responseIdentifier` | `responseIdentifier` | `response-identifier` |
|
|
105
|
-
| `maxChoices` | `maxChoices` | `max-choices` |
|
|
106
|
-
| `cardinality` | `cardinality` | `cardinality` |
|
|
77
|
+
QTI 2.x uses camelCase element and attribute names (`choiceInteraction`, `baseType`), while QTI 3.0
|
|
78
|
+
uses kebab-case names with a `qti-` prefix (`qti-choice-interaction`, `base-type`). The canonical
|
|
79
|
+
layer hides these differences: extractors and response processing always operate on canonical names,
|
|
80
|
+
and the mappers translate to and from the version-specific spelling. A few simple attributes
|
|
81
|
+
(`identifier`, `shuffle`, `cardinality`) are spelled the same in both versions.
|
|
107
82
|
|
|
108
|
-
|
|
83
|
+
For the complete element and attribute naming tables, see
|
|
84
|
+
[`docs/QTI-3-MIGRATION-GUIDE.md`](../../docs/QTI-3-MIGRATION-GUIDE.md).
|
|
109
85
|
|
|
110
86
|
## Architecture
|
|
111
87
|
|
|
@@ -286,67 +262,36 @@ session.dispose();
|
|
|
286
262
|
|
|
287
263
|
### Transform Integration
|
|
288
264
|
|
|
265
|
+
`@pie-qti/qti-common` also powers the QTI → PIE transformation in `@pie-qti/to-pie`. To transform
|
|
266
|
+
QTI XML directly, use the plugin:
|
|
267
|
+
|
|
289
268
|
```typescript
|
|
290
|
-
import { TransformEngine } from '@pie-qti/transform-core';
|
|
291
269
|
import { QtiToPiePlugin } from '@pie-qti/to-pie';
|
|
292
|
-
import { createQtiParser } from '@pie-qti/qti-common';
|
|
293
270
|
|
|
294
271
|
const xml = `...(QTI 2.x or 3.0)...`;
|
|
295
|
-
const { version } = createQtiParser(xml);
|
|
296
|
-
|
|
297
|
-
const engine = new TransformEngine();
|
|
298
|
-
engine.use(new QtiToPiePlugin());
|
|
299
|
-
|
|
300
|
-
const handle = await engine.transform(xml, {
|
|
301
|
-
sourceFormat: version.startsWith('3') ? 'qti30' : 'qti22',
|
|
302
|
-
targetFormat: 'pie'
|
|
303
|
-
});
|
|
304
|
-
const result = await handle.result();
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
## Migration Guide
|
|
308
|
-
|
|
309
|
-
### From QTI 2.x-only Code
|
|
310
272
|
|
|
311
|
-
|
|
273
|
+
const plugin = new QtiToPiePlugin();
|
|
274
|
+
const result = await plugin.transform(
|
|
275
|
+
{ content: xml, format: 'qti22' }, // format is optional; qti30 is detected the same way
|
|
276
|
+
{ logger: console }
|
|
277
|
+
);
|
|
312
278
|
|
|
313
|
-
|
|
314
|
-
const elements = doc.getElementsByTagName('choiceInteraction');
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
**After** (QTI 2.x + 3.0):
|
|
318
|
-
|
|
319
|
-
```typescript
|
|
320
|
-
import { createQtiParser } from '@pie-qti/qti-common';
|
|
321
|
-
|
|
322
|
-
const { mapper } = createQtiParser(xml);
|
|
323
|
-
const tagName = mapper.toNative('choiceinteraction');
|
|
324
|
-
const elements = doc.getElementsByTagName(tagName);
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
**Even Better** (using existing extraction layer):
|
|
328
|
-
|
|
329
|
-
```typescript
|
|
330
|
-
// No changes needed! Extraction layer already uses mappers internally
|
|
331
|
-
const definition = createAssessmentItemDefinition({ itemXml: xml });
|
|
332
|
-
const session = definition.openSession(); // Works with both QTI 2.x and 3.0
|
|
279
|
+
console.log(result.items); // PIE items
|
|
333
280
|
```
|
|
334
281
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
**Before** (QTI 2.x only):
|
|
282
|
+
For engine-level usage (multi-plugin pipelines and PIE ⇄ QTI round-trips), see
|
|
283
|
+
[`docs/PIE-QTI-TRANSFORMATION-GUIDE.md`](../../docs/PIE-QTI-TRANSFORMATION-GUIDE.md).
|
|
338
284
|
|
|
339
|
-
|
|
340
|
-
const baseType = element.getAttribute('baseType');
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
**After** (QTI 2.x + 3.0):
|
|
285
|
+
## Migration Guide
|
|
344
286
|
|
|
345
|
-
|
|
346
|
-
|
|
287
|
+
Migrating existing QTI 2.x-only code usually means replacing hard-coded `getElementsByTagName`
|
|
288
|
+
lookups and direct `getAttribute` reads with `createQtiParser(...)` plus the mapper and smart
|
|
289
|
+
attribute accessors, so the same code handles QTI 2.x and 3.0. Code that already goes through the
|
|
290
|
+
extraction layer (`createAssessmentItemDefinition`) uses the mappers internally and needs no
|
|
291
|
+
changes.
|
|
347
292
|
|
|
348
|
-
|
|
349
|
-
|
|
293
|
+
See [`docs/QTI-3-MIGRATION-GUIDE.md`](../../docs/QTI-3-MIGRATION-GUIDE.md) for the full naming
|
|
294
|
+
tables and before/after migration examples.
|
|
350
295
|
|
|
351
296
|
## Testing
|
|
352
297
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-qti/qti-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"node-html-parser": "^9.0.4"
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@types/bun": "^1.4.2",
|
|
10
10
|
"@xmldom/xmldom": "^0.9.12",
|
|
11
|
-
"typescript": "^5.9.3"
|
|
12
|
-
"vitest": "^4.1.11"
|
|
11
|
+
"typescript": "^5.9.3"
|
|
13
12
|
},
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* APIP accessibility
|
|
3
|
-
*
|
|
4
|
-
* QTI 2.x carries accessibility content as APIP 1.0: an `apip:apipAccessibility` element whose
|
|
5
|
-
* `accessElement`s each link content elements, by `id`, to the supports that describe them. A
|
|
6
|
-
* catalog is the same thing in QTI 3's terms, so an access element maps to one catalog by its
|
|
7
|
-
* `identifier`, its supports to cards under the support names QTI 3 uses, as 1EdTech's
|
|
8
|
-
* APIP-to-QTI 3 migration guide maps them:
|
|
9
|
-
*
|
|
10
|
-
* - `spoken`: one script card, the first of `textToSpeechPronunciationSSML` (as `<speak>`),
|
|
11
|
-
* `textToSpeechPronunciation` and `spokenText`, the others kept as `ext:custom-` cards, and a
|
|
12
|
-
* card per `audioFileInfo` recording, its `startTime` and `duration` the time range;
|
|
13
|
-
* - `brailleText` as `braille`, `tactileFile` as `tactile`;
|
|
14
|
-
* - `signing` as `sign-language` video, `ase` for ASL and `eng-US` for Signed English, with the
|
|
15
|
-
* cues as the time range;
|
|
16
|
-
* - `keyWordTranslation` as `keyword-translation`, one card per language;
|
|
17
|
-
* - `guidance`'s `languageLearnerSupport` as `linguistic-guidance`.
|
|
18
|
-
*
|
|
19
|
-
* QTI 3 has no counterpart for the other supports, which the reader reports as unmapped;
|
|
20
|
-
* `voiceType`, `voiceSpeed` and `supportOrder` are dropped, the last because document order is the
|
|
21
|
-
* order.
|
|
22
|
-
*
|
|
23
|
-
* The writer maps the other way. A card APIP has no element for, a card past the one an element
|
|
24
|
-
* holds, and a card missing what its element requires (a `tactile` recording without its text, an
|
|
25
|
-
* audio file whose MIME type is unknown) are unwritten, and the result names their supports.
|
|
26
|
-
* SSML elements APIP does not admit are unwrapped to their content. Plain-text APIP elements take
|
|
27
|
-
* the card's text, its markup dropped.
|
|
28
|
-
*/
|
|
29
|
-
import { type HTMLElement } from 'node-html-parser';
|
|
30
|
-
import { type CatalogCard, type TextRange } from './catalog.js';
|
|
31
|
-
export declare const APIP_NAMESPACE = "http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0";
|
|
32
|
-
export declare const SSML_NAMESPACE = "http://www.w3.org/2001/10/synthesis";
|
|
33
|
-
/** An APIP link from an access element to the content it describes. */
|
|
34
|
-
export interface ApipContentLink {
|
|
35
|
-
/** The `id` of the content element, from `qtiLinkIdentifierRef`; empty when it names none. */
|
|
36
|
-
target: string;
|
|
37
|
-
/** The word or character range of the element's text, when the link has one. */
|
|
38
|
-
range?: TextRange;
|
|
39
|
-
/** The link names the element as an object (`objectLink`): an image, a media player. */
|
|
40
|
-
object?: boolean;
|
|
41
|
-
}
|
|
42
|
-
export interface ApipAccessElement {
|
|
43
|
-
identifier: string;
|
|
44
|
-
links: ApipContentLink[];
|
|
45
|
-
cards: CatalogCard[];
|
|
46
|
-
/** The supports QTI 3 has no counterpart for, by element name. */
|
|
47
|
-
unmapped: string[];
|
|
48
|
-
}
|
|
49
|
-
export type ApipAccessElementSource = Pick<ApipAccessElement, 'identifier' | 'links' | 'cards'>;
|
|
50
|
-
export interface ApipAccessibilityXml {
|
|
51
|
-
/** The `apip:apipAccessibility` element, its namespaces declared on it; absent when nothing is written. */
|
|
52
|
-
xml?: string;
|
|
53
|
-
/** The supports of the cards not written, by access element identifier. */
|
|
54
|
-
unwritten: Map<string, string[]>;
|
|
55
|
-
}
|
|
56
|
-
export interface ApipWriteOptions {
|
|
57
|
-
/** The `id`s the document uses already, which the access elements and labels must not take. */
|
|
58
|
-
reservedIds?: Iterable<string>;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The APIP access elements a QTI 2.x document declares, in document order. A string is parsed
|
|
62
|
-
* with its CDATA sections unwrapped; a parsed root must keep tag names as authored.
|
|
63
|
-
*/
|
|
64
|
-
export declare function readApipAccessElements(source: string | HTMLElement): ApipAccessElement[];
|
|
65
|
-
/** Write access elements as `apip:apipAccessibility`, for the end of an item or stimulus. */
|
|
66
|
-
export declare function writeApipAccessibility(elements: ApipAccessElementSource[], options?: ApipWriteOptions): ApipAccessibilityXml;
|