@pie-qti/qti-common 1.0.0-beta.4 → 1.0.0-beta.6

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.
@@ -1,3 +1,10 @@
1
+ /** The namespace each QTI version's items and tests declare. */
2
+ const QTI_NAMESPACES = {
3
+ '2.0': 'http://www.imsglobal.org/xsd/imsqti_v2p0',
4
+ '2.1': 'http://www.imsglobal.org/xsd/imsqti_v2p1',
5
+ '2.2': 'http://www.imsglobal.org/xsd/imsqti_v2p2',
6
+ '3.0': 'http://www.imsglobal.org/xsd/imsqtiasi_v3p0',
7
+ };
1
8
  /**
2
9
  * Detect the QTI version from XML content.
3
10
  *
@@ -5,7 +12,9 @@
5
12
  * 1. Check XML namespace URI for version indicators (v2p0, v2p1, v2p2, v3p0)
6
13
  * 2. Check root element name (qti-assessment-item => 3.0, assessmentItem => 2.x)
7
14
  * 3. Check version attribute on root element
8
- * 4. Fall back to 'unknown'
15
+ * 4. Fall back to '2.2' for a camelCase assessmentItem/assessmentTest root, else 'unknown'
16
+ *
17
+ * Use {@link detectQtiVersionDetailed} to learn whether the result was assumed.
9
18
  *
10
19
  * @param xml - QTI XML content as string
11
20
  * @returns Detected QTI version or 'unknown'
@@ -17,6 +26,23 @@
17
26
  * ```
18
27
  */
19
28
  export function detectQtiVersion(xml) {
29
+ return detectQtiVersionDetailed(xml).version;
30
+ }
31
+ /**
32
+ * Detect the QTI version from XML content, with what decided it and how far to trust it.
33
+ *
34
+ * The version is the one {@link detectQtiVersion} returns. An unversioned or unknown-namespace
35
+ * camelCase root still reads as QTI 2.2, but with `basis: 'default'`, `confidence: 'low'` and a
36
+ * warning, so callers can tell an assumption from a declaration and surface it.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * detectQtiVersionDetailed('<assessmentItem identifier="a"/>');
41
+ * // => { version: '2.2', basis: 'default', confidence: 'low',
42
+ * // warnings: ['Root <assessmentItem> declares no QTI namespace; assuming QTI 2.2.'] }
43
+ * ```
44
+ */
45
+ export function detectQtiVersionDetailed(xml) {
20
46
  try {
21
47
  // Check if we're in a browser environment
22
48
  if (typeof window !== 'undefined' && typeof window.DOMParser !== 'undefined') {
@@ -24,7 +50,7 @@ export function detectQtiVersion(xml) {
24
50
  const doc = parser.parseFromString(xml, 'text/xml');
25
51
  return detectFromDocument(doc);
26
52
  }
27
- // In Node.js environment, fall back to regex detection
53
+ // In Node.js environment, fall back to string-based detection
28
54
  // (xmldom can be optionally imported by consumers if needed)
29
55
  return detectFromString(xml);
30
56
  }
@@ -35,95 +61,197 @@ export function detectQtiVersion(xml) {
35
61
  }
36
62
  /**
37
63
  * Detect QTI version from a parsed Document.
38
- * @param doc - Parsed XML document
39
- * @returns Detected QTI version
40
64
  * @private
41
65
  */
42
66
  function detectFromDocument(doc) {
43
67
  const root = doc.documentElement;
44
68
  // Check for parse errors
45
- if (root.tagName === 'parsererror') {
46
- return 'unknown';
69
+ if (!root || root.tagName === 'parsererror') {
70
+ return unknown('The XML could not be parsed.');
47
71
  }
48
72
  // Strategy 1: Check namespace URI
49
73
  if (root.namespaceURI) {
50
- if (root.namespaceURI.includes('v3p0') || root.namespaceURI.includes('imsqtiasi_v3p0')) {
51
- return '3.0';
52
- }
53
- if (root.namespaceURI.includes('v2p2')) {
54
- return '2.2';
55
- }
56
- if (root.namespaceURI.includes('v2p1')) {
57
- return '2.1';
58
- }
59
- if (root.namespaceURI.includes('v2p0')) {
60
- return '2.0';
61
- }
74
+ const fromNamespace = namespaceDetection(root.namespaceURI);
75
+ if (fromNamespace)
76
+ return fromNamespace;
62
77
  }
63
- // Strategy 2: Check root element name (any qti- prefixed element indicates QTI 3.0)
78
+ // Strategies 2 and 3: root element name, then its version attribute
64
79
  const localName = root.localName || root.tagName;
65
- if (localName === 'qti-assessment-item' || localName === 'qti-assessment-test' || localName.startsWith('qti-')) {
66
- return '3.0';
67
- }
68
- // Strategy 3: Check version attribute
69
- if (localName === 'assessmentItem' || localName === 'assessmentTest') {
70
- const version = root.getAttribute('version');
71
- if (version) {
72
- if (version.startsWith('3.'))
73
- return '3.0';
74
- if (version.startsWith('2.2'))
75
- return '2.2';
76
- if (version.startsWith('2.1'))
77
- return '2.1';
78
- if (version.startsWith('2.0'))
79
- return '2.0';
80
- }
81
- // If no version attribute, assume 2.2 (most common)
82
- return '2.2';
83
- }
84
- return 'unknown';
80
+ return detectFromRoot(localName, root.getAttribute('version'), root.namespaceURI ?? null);
85
81
  }
86
82
  /**
87
83
  * Detect QTI version using string matching (fallback method).
88
- * @param xml - XML string
89
- * @returns Detected QTI version
90
84
  * @private
91
85
  */
92
86
  function detectFromString(xml) {
93
- // Check namespace declarations
94
- if (xml.includes('imsqtiasi_v3p0') || xml.includes('/v3p0/')) {
95
- return '3.0';
96
- }
97
- if (xml.includes('imsqti_v2p2') || xml.includes('/v2p2/')) {
98
- return '2.2';
99
- }
100
- if (xml.includes('imsqti_v2p1') || xml.includes('/v2p1/')) {
101
- return '2.1';
87
+ const root = readRootStartTag(xml);
88
+ // The root's own namespace declaration is authoritative.
89
+ if (root?.namespace) {
90
+ const fromNamespace = namespaceDetection(root.namespace);
91
+ if (fromNamespace)
92
+ return fromNamespace;
102
93
  }
103
- if (xml.includes('imsqti_v2p0') || xml.includes('/v2p0/')) {
104
- return '2.0';
94
+ // A QTI namespace elsewhere in the document (a prefixed or nested declaration, a schema
95
+ // location, even a comment) decides at medium confidence when the root declares none.
96
+ for (const [version, tokens] of DOCUMENT_NAMESPACE_TOKENS) {
97
+ if (tokens.some((token) => xml.includes(token))) {
98
+ return {
99
+ version,
100
+ basis: 'namespace',
101
+ confidence: 'medium',
102
+ warnings: [
103
+ `The QTI ${version} namespace appears in the document but is not the root element's namespace; read as QTI ${version}.`,
104
+ ],
105
+ };
106
+ }
105
107
  }
106
108
  // Check root element or any QTI 3.0 element (kebab-case with qti- prefix)
107
109
  if (/<qti-assessment-(item|test)[\s>]/.test(xml) || /<qti-[a-z-]+[\s>]/.test(xml)) {
108
- return '3.0';
110
+ return {
111
+ version: '3.0',
112
+ basis: 'root-element',
113
+ confidence: 'medium',
114
+ warnings: [missingNamespaceWarning(root?.localName ?? 'qti-*', root?.namespace ?? null, '3.0')],
115
+ };
109
116
  }
110
117
  if (/<assessment(Item|Test)[\s>]/.test(xml)) {
111
- // Try to find version attribute
112
- const versionMatch = xml.match(/version=["']([^"']+)["']/);
113
- if (versionMatch) {
114
- const version = versionMatch[1];
115
- if (version.startsWith('3.'))
116
- return '3.0';
117
- if (version.startsWith('2.2'))
118
- return '2.2';
119
- if (version.startsWith('2.1'))
120
- return '2.1';
121
- if (version.startsWith('2.0'))
122
- return '2.0';
118
+ const localName = root && /^assessment(Item|Test)$/.test(root.localName) ? root.localName : 'assessmentItem';
119
+ // The root's own version attribute, else the first version="…" in the document.
120
+ const rootVersion = root?.attributes.get('version');
121
+ const versionAttribute = rootVersion ?? xml.match(/version=["']([^"']+)["']/)?.[1] ?? null;
122
+ return detectFromRoot(localName, versionAttribute, root?.namespace ?? null, rootVersion !== undefined);
123
+ }
124
+ return unknown(root ? `<${root.name}> is not a QTI assessmentItem or assessmentTest root.` : 'No XML root element found.');
125
+ }
126
+ /** The search order and namespace tokens of the document-wide check. */
127
+ const DOCUMENT_NAMESPACE_TOKENS = [
128
+ ['3.0', ['imsqtiasi_v3p0', '/v3p0/']],
129
+ ['2.2', ['imsqti_v2p2', '/v2p2/']],
130
+ ['2.1', ['imsqti_v2p1', '/v2p1/']],
131
+ ['2.0', ['imsqti_v2p0', '/v2p0/']],
132
+ ];
133
+ /** A root namespace that names a QTI version; null when it names none. */
134
+ function namespaceDetection(namespace) {
135
+ const version = namespace.includes('v3p0') || namespace.includes('imsqtiasi_v3p0')
136
+ ? '3.0'
137
+ : namespace.includes('v2p2')
138
+ ? '2.2'
139
+ : namespace.includes('v2p1')
140
+ ? '2.1'
141
+ : namespace.includes('v2p0')
142
+ ? '2.0'
143
+ : null;
144
+ if (!version)
145
+ return null;
146
+ if (namespace === QTI_NAMESPACES[version]) {
147
+ return { version, basis: 'namespace', confidence: 'high', warnings: [] };
148
+ }
149
+ return {
150
+ version,
151
+ basis: 'namespace',
152
+ confidence: 'medium',
153
+ warnings: [
154
+ `Root namespace "${namespace}" is not the QTI ${version} namespace "${QTI_NAMESPACES[version]}"; read as QTI ${version}.`,
155
+ ],
156
+ };
157
+ }
158
+ /** Strategies 2 to 4, for a root whose namespace names no QTI version. */
159
+ function detectFromRoot(localName, versionAttribute, namespace, versionOnRoot = true) {
160
+ // Strategy 2: any qti- prefixed root indicates QTI 3.0
161
+ if (localName === 'qti-assessment-item' || localName === 'qti-assessment-test' || localName.startsWith('qti-')) {
162
+ return {
163
+ version: '3.0',
164
+ basis: 'root-element',
165
+ confidence: 'medium',
166
+ warnings: [missingNamespaceWarning(localName, namespace, '3.0')],
167
+ };
168
+ }
169
+ if (localName === 'assessmentItem' || localName === 'assessmentTest') {
170
+ // Strategy 3: version attribute
171
+ const fromAttribute = versionFromAttribute(versionAttribute);
172
+ if (fromAttribute) {
173
+ const source = versionOnRoot ? 'its' : 'a';
174
+ return {
175
+ version: fromAttribute,
176
+ basis: 'version-attribute',
177
+ confidence: 'medium',
178
+ warnings: [
179
+ `${missingNamespaceWarning(localName, namespace, fromAttribute)} The version comes from ${source} version="${versionAttribute}" attribute.`,
180
+ ],
181
+ };
123
182
  }
124
- // Assume 2.2 if no version specified
183
+ // Strategy 4: a camelCase root names no version; assume 2.2 (most common)
184
+ const unread = versionAttribute && versionOnRoot ? ` Its version="${versionAttribute}" names no QTI version.` : '';
185
+ return {
186
+ version: '2.2',
187
+ basis: 'default',
188
+ confidence: 'low',
189
+ warnings: [
190
+ `${namespace ? `Root <${localName}> is in namespace "${namespace}", which is not a QTI namespace` : `Root <${localName}> declares no QTI namespace`}; assuming QTI 2.2.${unread}`,
191
+ ],
192
+ };
193
+ }
194
+ return unknown(`<${localName}> is not a QTI assessmentItem or assessmentTest root.`);
195
+ }
196
+ function versionFromAttribute(version) {
197
+ if (!version)
198
+ return null;
199
+ if (version.startsWith('3.'))
200
+ return '3.0';
201
+ if (version.startsWith('2.2'))
125
202
  return '2.2';
203
+ if (version.startsWith('2.1'))
204
+ return '2.1';
205
+ if (version.startsWith('2.0'))
206
+ return '2.0';
207
+ return null;
208
+ }
209
+ function missingNamespaceWarning(localName, namespace, version) {
210
+ const found = namespace ? `is in namespace "${namespace}"` : 'declares no namespace';
211
+ return `Root <${localName}> ${found}, not the QTI ${version} namespace "${QTI_NAMESPACES[version]}".`;
212
+ }
213
+ function unknown(warning) {
214
+ return { version: 'unknown', basis: 'none', confidence: 'low', warnings: [warning] };
215
+ }
216
+ /** The document element's start tag, read without a parser: after any prolog, comments and PIs. */
217
+ function readRootStartTag(xml) {
218
+ let rest = xml.replace(/^\uFEFF/, '');
219
+ for (;;) {
220
+ rest = rest.trimStart();
221
+ if (rest.startsWith('<?')) {
222
+ const end = rest.indexOf('?>');
223
+ if (end < 0)
224
+ return null;
225
+ rest = rest.slice(end + 2);
226
+ }
227
+ else if (rest.startsWith('<!--')) {
228
+ const end = rest.indexOf('-->');
229
+ if (end < 0)
230
+ return null;
231
+ rest = rest.slice(end + 3);
232
+ }
233
+ else if (rest.startsWith('<!')) {
234
+ const end = rest.indexOf('>');
235
+ if (end < 0)
236
+ return null;
237
+ rest = rest.slice(end + 1);
238
+ }
239
+ else {
240
+ break;
241
+ }
242
+ }
243
+ const tag = /^<([A-Za-z_][\w.:-]*)((?:\s+[^\s=/>]+\s*=\s*(?:"[^"]*"|'[^']*'))*)\s*\/?>/.exec(rest);
244
+ if (!tag)
245
+ return null;
246
+ const name = tag[1];
247
+ const attributes = new Map();
248
+ for (const attribute of (tag[2] ?? '').matchAll(/([^\s=/>]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) {
249
+ attributes.set(attribute[1], attribute[2] ?? attribute[3] ?? '');
126
250
  }
127
- return 'unknown';
251
+ const colon = name.indexOf(':');
252
+ const prefix = colon > 0 ? name.slice(0, colon) : null;
253
+ const localName = prefix ? name.slice(colon + 1) : name;
254
+ const namespace = attributes.get(prefix ? `xmlns:${prefix}` : 'xmlns') ?? null;
255
+ return { name, localName, attributes, namespace: namespace || null };
128
256
  }
129
257
  //# sourceMappingURL=detectQtiVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"detectQtiVersion.js","sourceRoot":"","sources":["../../src/version-detection/detectQtiVersion.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC3C,IAAI,CAAC;QACJ,0CAA0C;QAC1C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW,EAAE,CAAC;YAC9E,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACtC,MAAM,GAAG,GAAG,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;YACpD,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;QAED,uDAAuD;QACvD,6DAA6D;QAC7D,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,+CAA+C;QAC/C,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;AACF,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,GAAQ;IACnC,MAAM,IAAI,GAAG,GAAG,CAAC,eAAe,CAAC;IAEjC,yBAAyB;IACzB,IAAI,IAAI,CAAC,OAAO,KAAK,aAAa,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,kCAAkC;IAClC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACxF,OAAO,KAAK,C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AAC;QAC7C,CAAC;QAED,qCAAqC;QACrC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * QTI version identifiers\n */\nexport type QtiVersion = '2.0' | '2.1' | '2.2' | '3.0' | 'unknown';\n\n/**\n * Detect the QTI version from XML content.\n *\n * Detection strategy (in priority order):\n * 1. Check XML namespace URI for version indicators (v2p0, v2p1, v2p2, v3p0)\n * 2. Check root element name (qti-assessment-item => 3.0, assessmentItem => 2.x)\n * 3. Check version attribute on root element\n * 4. Fall back to 'unknown'\n *\n * @param xml - QTI XML content as string\n * @returns Detected QTI version or 'unknown'\n *\n * @example\n * ```typescript\n * const xml = `<qti-assessment-item xmlns=\"http://www.imsglobal.org/xsd/imsqtiasi_v3p0\">`;\n * detectQtiVersion(xml); // => '3.0'\n * ```\n */\nexport function detectQtiVersion(xml: string): QtiVersion {\n\ttry {\n\t\t// Check if we're in a browser environment\n\t\tif (typeof window !== 'undefined' && typeof window.DOMParser !== 'undefined') {\n\t\t\tconst parser = new window.DOMParser();\n\t\t\tconst doc = parser.parseFromString(xml, 'text/xml');\n\t\t\treturn detectFromDocument(doc);\n\t\t}\n\n\t\t// In Node.js environment, fall back to regex detection\n\t\t// (xmldom can be optionally imported by consumers if needed)\n\t\treturn detectFromString(xml);\n\t} catch {\n\t\t// If parsing fails, try string-based detection\n\t\treturn detectFromString(xml);\n\t}\n}\n\n/**\n * Detect QTI version from a parsed Document.\n * @param doc - Parsed XML document\n * @returns Detected QTI version\n * @private\n */\nfunction detectFromDocument(doc: any): QtiVersion {\n\tconst root = doc.documentElement;\n\n\t// Check for parse errors\n\tif (root.tagName === 'parsererror') {\n\t\treturn 'unknown';\n\t}\n\n\t// Strategy 1: Check namespace URI\n\tif (root.namespaceURI) {\n\t\tif (root.namespaceURI.includes('v3p0') || root.namespaceURI.includes('imsqtiasi_v3p0')) {\n\t\t\treturn '3.0';\n\t\t}\n\t\tif (root.namespaceURI.includes('v2p2')) {\n\t\t\treturn '2.2';\n\t\t}\n\t\tif (root.namespaceURI.includes('v2p1')) {\n\t\t\treturn '2.1';\n\t\t}\n\t\tif (root.namespaceURI.includes('v2p0')) {\n\t\t\treturn '2.0';\n\t\t}\n\t}\n\n\t// Strategy 2: Check root element name (any qti- prefixed element indicates QTI 3.0)\n\tconst localName = root.localName || root.tagName;\n\tif (localName === 'qti-assessment-item' || localName === 'qti-assessment-test' || localName.startsWith('qti-')) {\n\t\treturn '3.0';\n\t}\n\n\t// Strategy 3: Check version attribute\n\tif (localName === 'assessmentItem' || localName === 'assessmentTest') {\n\t\tconst version = root.getAttribute('version');\n\t\tif (version) {\n\t\t\tif (version.startsWith('3.')) return '3.0';\n\t\t\tif (version.startsWith('2.2')) return '2.2';\n\t\t\tif (version.startsWith('2.1')) return '2.1';\n\t\t\tif (version.startsWith('2.0')) return '2.0';\n\t\t}\n\n\t\t// If no version attribute, assume 2.2 (most common)\n\t\treturn '2.2';\n\t}\n\n\treturn 'unknown';\n}\n\n/**\n * Detect QTI version using string matching (fallback method).\n * @param xml - XML string\n * @returns Detected QTI version\n * @private\n */\nfunction detectFromString(xml: string): QtiVersion {\n\t// Check namespace declarations\n\tif (xml.includes('imsqtiasi_v3p0') || xml.includes('/v3p0/')) {\n\t\treturn '3.0';\n\t}\n\tif (xml.includes('imsqti_v2p2') || xml.includes('/v2p2/')) {\n\t\treturn '2.2';\n\t}\n\tif (xml.includes('imsqti_v2p1') || xml.includes('/v2p1/')) {\n\t\treturn '2.1';\n\t}\n\tif (xml.includes('imsqti_v2p0') || xml.includes('/v2p0/')) {\n\t\treturn '2.0';\n\t}\n\n\t// Check root element or any QTI 3.0 element (kebab-case with qti- prefix)\n\tif (/<qti-assessment-(item|test)[\\s>]/.test(xml) || /<qti-[a-z-]+[\\s>]/.test(xml)) {\n\t\treturn '3.0';\n\t}\n\n\tif (/<assessment(Item|Test)[\\s>]/.test(xml)) {\n\t\t// Try to find version attribute\n\t\tconst versionMatch = xml.match(/version=[\"']([^\"']+)[\"']/);\n\t\tif (versionMatch) {\n\t\t\tconst version = versionMatch[1];\n\t\t\tif (version.startsWith('3.')) return '3.0';\n\t\t\tif (version.startsWith('2.2')) return '2.2';\n\t\t\tif (version.startsWith('2.1')) return '2.1';\n\t\t\tif (version.startsWith('2.0')) return '2.0';\n\t\t}\n\n\t\t// Assume 2.2 if no version specified\n\t\treturn '2.2';\n\t}\n\n\treturn 'unknown';\n}\n"]}
1
+ {"version":3,"file":"detectQtiVersion.js","sourceRoot":"","sources":["../../src/version-detection/detectQtiVersion.ts"],"names":[],"mappings":"AAkCA,gEAAgE;AAChE,MAAM,cAAc,GAA8C;IACjE,KAAK,EAAE,0CAA0C;IACjD,KAAK,EAAE,0CAA0C;IACjD,KAAK,EAAE,0CAA0C;IACjD,KAAK,EAAE,6CAA6C;CACpD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC3C,OAAO,wBAAwB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAW;IACnD,IAAI,CAAC;QACJ,0CAA0C;QAC1C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW,EAAE,CAAC;YAC9E,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACtC,MAAM,GAAG,GAAG,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;YACpD,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;QAED,8DAA8D;QAC9D,6DAA6D;QAC7D,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,+CAA+C;QAC/C,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC9B,CA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CAAC;IAChC,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACxD,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;IAC/E,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,IAAI,IAAI,EAAE,CAAC;AACtE,CAAC","sourcesContent":["/**\n * QTI version identifiers\n */\nexport type QtiVersion = '2.0' | '2.1' | '2.2' | '3.0' | 'unknown';\n\n/** What decided a detected QTI version. */\nexport type QtiVersionDetectionBasis =\n\t/** The root element's namespace names a QTI version. */\n\t| 'namespace'\n\t/** A QTI 3.0 `qti-` element name, without a QTI namespace. */\n\t| 'root-element'\n\t/** A `version` attribute on a camelCase root, without a QTI namespace. */\n\t| 'version-attribute'\n\t/** Nothing named a version; a camelCase `assessmentItem`/`assessmentTest` is assumed to be 2.2. */\n\t| 'default'\n\t/** Not recognizable as QTI. */\n\t| 'none';\n\n/**\n * How far to trust a detected version: `high` when the root declares the version's QTI namespace,\n * `medium` when another signal decided it, `low` when the version is an assumption.\n */\nexport type QtiVersionDetectionConfidence = 'high' | 'medium' | 'low';\n\nexport interface QtiVersionDetection {\n\treadonly version: QtiVersion;\n\treadonly basis: QtiVersionDetectionBasis;\n\treadonly confidence: QtiVersionDetectionConfidence;\n\t/** Why the result may be wrong, for callers to surface. Empty when the namespace decided. */\n\treadonly warnings: readonly string[];\n}\n\ntype DetectedVersion = Exclude<QtiVersion, 'unknown'>;\n\n/** The namespace each QTI version's items and tests declare. */\nconst QTI_NAMESPACES: Readonly<Record<DetectedVersion, string>> = {\n\t'2.0': 'http://www.imsglobal.org/xsd/imsqti_v2p0',\n\t'2.1': 'http://www.imsglobal.org/xsd/imsqti_v2p1',\n\t'2.2': 'http://www.imsglobal.org/xsd/imsqti_v2p2',\n\t'3.0': 'http://www.imsglobal.org/xsd/imsqtiasi_v3p0',\n};\n\n/**\n * Detect the QTI version from XML content.\n *\n * Detection strategy (in priority order):\n * 1. Check XML namespace URI for version indicators (v2p0, v2p1, v2p2, v3p0)\n * 2. Check root element name (qti-assessment-item => 3.0, assessmentItem => 2.x)\n * 3. Check version attribute on root element\n * 4. Fall back to '2.2' for a camelCase assessmentItem/assessmentTest root, else 'unknown'\n *\n * Use {@link detectQtiVersionDetailed} to learn whether the result was assumed.\n *\n * @param xml - QTI XML content as string\n * @returns Detected QTI version or 'unknown'\n *\n * @example\n * ```typescript\n * const xml = `<qti-assessment-item xmlns=\"http://www.imsglobal.org/xsd/imsqtiasi_v3p0\">`;\n * detectQtiVersion(xml); // => '3.0'\n * ```\n */\nexport function detectQtiVersion(xml: string): QtiVersion {\n\treturn detectQtiVersionDetailed(xml).version;\n}\n\n/**\n * Detect the QTI version from XML content, with what decided it and how far to trust it.\n *\n * The version is the one {@link detectQtiVersion} returns. An unversioned or unknown-namespace\n * camelCase root still reads as QTI 2.2, but with `basis: 'default'`, `confidence: 'low'` and a\n * warning, so callers can tell an assumption from a declaration and surface it.\n *\n * @example\n * ```typescript\n * detectQtiVersionDetailed('<assessmentItem identifier=\"a\"/>');\n * // => { version: '2.2', basis: 'default', confidence: 'low',\n * // warnings: ['Root <assessmentItem> declares no QTI namespace; assuming QTI 2.2.'] }\n * ```\n */\nexport function detectQtiVersionDetailed(xml: string): QtiVersionDetection {\n\ttry {\n\t\t// Check if we're in a browser environment\n\t\tif (typeof window !== 'undefined' && typeof window.DOMParser !== 'undefined') {\n\t\t\tconst parser = new window.DOMParser();\n\t\t\tconst doc = parser.parseFromString(xml, 'text/xml');\n\t\t\treturn detectFromDocument(doc);\n\t\t}\n\n\t\t// In Node.js environment, fall back to string-based detection\n\t\t// (xmldom can be optionally imported by consumers if needed)\n\t\treturn detectFromString(xml);\n\t} catch {\n\t\t// If parsing fails, try string-based detection\n\t\treturn detectFromString(xml);\n\t}\n}\n\n/**\n * Detect QTI version from a parsed Document.\n * @private\n */\nfunction detectFromDocument(doc: any): QtiVersionDetection {\n\tconst root = doc.documentElement;\n\n\t// Check for parse errors\n\tif (!root || root.tagName === 'parsererror') {\n\t\treturn unknown('The XML could not be parsed.');\n\t}\n\n\t// Strategy 1: Check namespace URI\n\tif (root.namespaceURI) {\n\t\tconst fromNamespace = namespaceDetection(root.namespaceURI);\n\t\tif (fromNamespace) return fromNamespace;\n\t}\n\n\t// Strategies 2 and 3: root element name, then its version attribute\n\tconst localName = root.localName || root.tagName;\n\treturn detectFromRoot(localName, root.getAttribute('version'), root.namespaceURI ?? null);\n}\n\n/**\n * Detect QTI version using string matching (fallback method).\n * @private\n */\nfunction detectFromString(xml: string): QtiVersionDetection {\n\tconst root = readRootStartTag(xml);\n\n\t// The root's own namespace declaration is authoritative.\n\tif (root?.namespace) {\n\t\tconst fromNamespace = namespaceDetection(root.namespace);\n\t\tif (fromNamespace) return fromNamespace;\n\t}\n\n\t// A QTI namespace elsewhere in the document (a prefixed or nested declaration, a schema\n\t// location, even a comment) decides at medium confidence when the root declares none.\n\tfor (const [version, tokens] of DOCUMENT_NAMESPACE_TOKENS) {\n\t\tif (tokens.some((token) => xml.includes(token))) {\n\t\t\treturn {\n\t\t\t\tversion,\n\t\t\t\tbasis: 'namespace',\n\t\t\t\tconfidence: 'medium',\n\t\t\t\twarnings: [\n\t\t\t\t\t`The QTI ${version} namespace appears in the document but is not the root element's namespace; read as QTI ${version}.`,\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t}\n\n\t// Check root element or any QTI 3.0 element (kebab-case with qti- prefix)\n\tif (/<qti-assessment-(item|test)[\\s>]/.test(xml) || /<qti-[a-z-]+[\\s>]/.test(xml)) {\n\t\treturn {\n\t\t\tversion: '3.0',\n\t\t\tbasis: 'root-element',\n\t\t\tconfidence: 'medium',\n\t\t\twarnings: [missingNamespaceWarning(root?.localName ?? 'qti-*', root?.namespace ?? null, '3.0')],\n\t\t};\n\t}\n\n\tif (/<assessment(Item|Test)[\\s>]/.test(xml)) {\n\t\tconst localName = root && /^assessment(Item|Test)$/.test(root.localName) ? root.localName : 'assessmentItem';\n\t\t// The root's own version attribute, else the first version=\"…\" in the document.\n\t\tconst rootVersion = root?.attributes.get('version');\n\t\tconst versionAttribute = rootVersion ?? xml.match(/version=[\"']([^\"']+)[\"']/)?.[1] ?? null;\n\t\treturn detectFromRoot(localName, versionAttribute, root?.namespace ?? null, rootVersion !== undefined);\n\t}\n\n\treturn unknown(root ? `<${root.name}> is not a QTI assessmentItem or assessmentTest root.` : 'No XML root element found.');\n}\n\n/** The search order and namespace tokens of the document-wide check. */\nconst DOCUMENT_NAMESPACE_TOKENS: ReadonlyArray<readonly [DetectedVersion, readonly string[]]> = [\n\t['3.0', ['imsqtiasi_v3p0', '/v3p0/']],\n\t['2.2', ['imsqti_v2p2', '/v2p2/']],\n\t['2.1', ['imsqti_v2p1', '/v2p1/']],\n\t['2.0', ['imsqti_v2p0', '/v2p0/']],\n];\n\n/** A root namespace that names a QTI version; null when it names none. */\nfunction namespaceDetection(namespace: string): QtiVersionDetection | null {\n\tconst version: DetectedVersion | null =\n\t\tnamespace.includes('v3p0') || namespace.includes('imsqtiasi_v3p0')\n\t\t\t? '3.0'\n\t\t\t: namespace.includes('v2p2')\n\t\t\t\t? '2.2'\n\t\t\t\t: namespace.includes('v2p1')\n\t\t\t\t\t? '2.1'\n\t\t\t\t\t: namespace.includes('v2p0')\n\t\t\t\t\t\t? '2.0'\n\t\t\t\t\t\t: null;\n\tif (!version) return null;\n\tif (namespace === QTI_NAMESPACES[version]) {\n\t\treturn { version, basis: 'namespace', confidence: 'high', warnings: [] };\n\t}\n\treturn {\n\t\tversion,\n\t\tbasis: 'namespace',\n\t\tconfidence: 'medium',\n\t\twarnings: [\n\t\t\t`Root namespace \"${namespace}\" is not the QTI ${version} namespace \"${QTI_NAMESPACES[version]}\"; read as QTI ${version}.`,\n\t\t],\n\t};\n}\n\n/** Strategies 2 to 4, for a root whose namespace names no QTI version. */\nfunction detectFromRoot(\n\tlocalName: string,\n\tversionAttribute: string | null,\n\tnamespace: string | null,\n\tversionOnRoot = true,\n): QtiVersionDetection {\n\t// Strategy 2: any qti- prefixed root indicates QTI 3.0\n\tif (localName === 'qti-assessment-item' || localName === 'qti-assessment-test' || localName.startsWith('qti-')) {\n\t\treturn {\n\t\t\tversion: '3.0',\n\t\t\tbasis: 'root-element',\n\t\t\tconfidence: 'medium',\n\t\t\twarnings: [missingNamespaceWarning(localName, namespace, '3.0')],\n\t\t};\n\t}\n\n\tif (localName === 'assessmentItem' || localName === 'assessmentTest') {\n\t\t// Strategy 3: version attribute\n\t\tconst fromAttribute = versionFromAttribute(versionAttribute);\n\t\tif (fromAttribute) {\n\t\t\tconst source = versionOnRoot ? 'its' : 'a';\n\t\t\treturn {\n\t\t\t\tversion: fromAttribute,\n\t\t\t\tbasis: 'version-attribute',\n\t\t\t\tconfidence: 'medium',\n\t\t\t\twarnings: [\n\t\t\t\t\t`${missingNamespaceWarning(localName, namespace, fromAttribute)} The version comes from ${source} version=\"${versionAttribute}\" attribute.`,\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\n\t\t// Strategy 4: a camelCase root names no version; assume 2.2 (most common)\n\t\tconst unread = versionAttribute && versionOnRoot ? ` Its version=\"${versionAttribute}\" names no QTI version.` : '';\n\t\treturn {\n\t\t\tversion: '2.2',\n\t\t\tbasis: 'default',\n\t\t\tconfidence: 'low',\n\t\t\twarnings: [\n\t\t\t\t`${namespace ? `Root <${localName}> is in namespace \"${namespace}\", which is not a QTI namespace` : `Root <${localName}> declares no QTI namespace`}; assuming QTI 2.2.${unread}`,\n\t\t\t],\n\t\t};\n\t}\n\n\treturn unknown(`<${localName}> is not a QTI assessmentItem or assessmentTest root.`);\n}\n\nfunction versionFromAttribute(version: string | null): DetectedVersion | null {\n\tif (!version) return null;\n\tif (version.startsWith('3.')) return '3.0';\n\tif (version.startsWith('2.2')) return '2.2';\n\tif (version.startsWith('2.1')) return '2.1';\n\tif (version.startsWith('2.0')) return '2.0';\n\treturn null;\n}\n\nfunction missingNamespaceWarning(localName: string, namespace: string | null, version: DetectedVersion): string {\n\tconst found = namespace ? `is in namespace \"${namespace}\"` : 'declares no namespace';\n\treturn `Root <${localName}> ${found}, not the QTI ${version} namespace \"${QTI_NAMESPACES[version]}\".`;\n}\n\nfunction unknown(warning: string): QtiVersionDetection {\n\treturn { version: 'unknown', basis: 'none', confidence: 'low', warnings: [warning] };\n}\n\ninterface RootStartTag {\n\t/** The qualified name as written. */\n\treadonly name: string;\n\treadonly localName: string;\n\treadonly attributes: ReadonlyMap<string, string>;\n\t/** The namespace the root's prefix (or the default namespace) is bound to on the root itself. */\n\treadonly namespace: string | null;\n}\n\n/** The document element's start tag, read without a parser: after any prolog, comments and PIs. */\nfunction readRootStartTag(xml: string): RootStartTag | null {\n\tlet rest = xml.replace(/^\\uFEFF/, '');\n\tfor (;;) {\n\t\trest = rest.trimStart();\n\t\tif (rest.startsWith('<?')) {\n\t\t\tconst end = rest.indexOf('?>');\n\t\t\tif (end < 0) return null;\n\t\t\trest = rest.slice(end + 2);\n\t\t} else if (rest.startsWith('<!--')) {\n\t\t\tconst end = rest.indexOf('-->');\n\t\t\tif (end < 0) return null;\n\t\t\trest = rest.slice(end + 3);\n\t\t} else if (rest.startsWith('<!')) {\n\t\t\tconst end = rest.indexOf('>');\n\t\t\tif (end < 0) return null;\n\t\t\trest = rest.slice(end + 1);\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\tconst tag = /^<([A-Za-z_][\\w.:-]*)((?:\\s+[^\\s=/>]+\\s*=\\s*(?:\"[^\"]*\"|'[^']*'))*)\\s*\\/?>/.exec(rest);\n\tif (!tag) return null;\n\tconst name = tag[1] as string;\n\tconst attributes = new Map<string, string>();\n\tfor (const attribute of (tag[2] ?? '').matchAll(/([^\\s=/>]+)\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/g)) {\n\t\tattributes.set(attribute[1] as string, attribute[2] ?? attribute[3] ?? '');\n\t}\n\tconst colon = name.indexOf(':');\n\tconst prefix = colon > 0 ? name.slice(0, colon) : null;\n\tconst localName = prefix ? name.slice(colon + 1) : name;\n\tconst namespace = attributes.get(prefix ? `xmlns:${prefix}` : 'xmlns') ?? null;\n\treturn { name, localName, attributes, namespace: namespace || null };\n}\n"]}
@@ -1,2 +1,3 @@
1
- export { detectQtiVersion } from './detectQtiVersion.js';
2
- export type { QtiVersion } from './detectQtiVersion.js';
1
+ export { detectQtiVersion, detectQtiVersionDetailed } from './detectQtiVersion.js';
2
+ export type { QtiVersion, QtiVersionDetection, QtiVersionDetectionBasis, QtiVersionDetectionConfidence, } from './detectQtiVersion.js';
3
+ export { isQtiVocabularyElement, QTI2_ELEMENTS, QTI2_XHTML_ELEMENTS, QTI3_ELEMENTS, type QtiVocabularyVersion, } from './vocabulary.js';
@@ -1,2 +1,3 @@
1
- export { detectQtiVersion } from './detectQtiVersion.js';
1
+ export { detectQtiVersion, detectQtiVersionDetailed } from './detectQtiVersion.js';
2
+ export { isQtiVocabularyElement, QTI2_ELEMENTS, QTI2_XHTML_ELEMENTS, QTI3_ELEMENTS, } from './vocabulary.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/version-detection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export { detectQtiVersion } from './detectQtiVersion.js';\nexport type { QtiVersion } from './detectQtiVersion.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/version-detection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAOnF,OAAO,EACN,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,aAAa,GAEb,MAAM,iBAAiB,CAAC","sourcesContent":["export { detectQtiVersion, detectQtiVersionDetailed } from './detectQtiVersion.js';\nexport type {\n\tQtiVersion,\n\tQtiVersionDetection,\n\tQtiVersionDetectionBasis,\n\tQtiVersionDetectionConfidence,\n} from './detectQtiVersion.js';\nexport {\n\tisQtiVocabularyElement,\n\tQTI2_ELEMENTS,\n\tQTI2_XHTML_ELEMENTS,\n\tQTI3_ELEMENTS,\n\ttype QtiVocabularyVersion,\n} from './vocabulary.js';\n"]}
@@ -0,0 +1,14 @@
1
+ /** The vocabularies distinguished here. QTI 2.0 and 2.1 items are checked against QTI 2.2's. */
2
+ export type QtiVocabularyVersion = '2.x' | '3.0';
3
+ /** XHTML elements the QTI 2.2 schema declares in its own namespace. */
4
+ export declare const QTI2_XHTML_ELEMENTS: ReadonlySet<string>;
5
+ /** QTI-defined QTI 2.x element names, exactly as the QTI 2.2 schema spells them. */
6
+ export declare const QTI2_ELEMENTS: ReadonlySet<string>;
7
+ /** QTI-defined QTI 3.0 element names (`qti-*`), as the QTI 3.0 ASI schema declares them. */
8
+ export declare const QTI3_ELEMENTS: ReadonlySet<string>;
9
+ /**
10
+ * Whether `localName` is an element the version's schema declares in the QTI namespace: a
11
+ * QTI-defined element, or one of the HTML elements the schema admits there. Names are compared
12
+ * exactly; XML element names are case-sensitive.
13
+ */
14
+ export declare function isQtiVocabularyElement(localName: string, version: QtiVocabularyVersion): boolean;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The element vocabulary each QTI version defines, for checking authored element names without
3
+ * an XSD engine. Built on the XSD-verified QTI 3.0 element map (`qti3-element-mappings.ts`),
4
+ * which `qti3-xsd-conformance.test.ts` checks against the vendored QTI 3.0 ASI schema and the
5
+ * QTI 2.2 schema; `vocabulary.test.ts` checks the QTI 2.x reading below against the QTI 2.2 schema.
6
+ *
7
+ * Only element names in the QTI namespace are QTI vocabulary. MathML, SSML, PCI, APIP, XInclude
8
+ * and other foreign vocabularies keep their own namespaces and are not checked here.
9
+ */
10
+ import { QTI3_HTML_ELEMENTS } from '../element-mapper/qti2-to-qti3.js';
11
+ import { QTI3_ELEMENT_MAPPINGS } from '../element-mapper/qti3-element-mappings.js';
12
+ /** XHTML elements the QTI 2.2 schema declares in its own namespace. */
13
+ export const QTI2_XHTML_ELEMENTS = new Set(('a abbr acronym address b bdo big blockquote br caption cite code col colgroup dd dfn div dl dt em ' +
14
+ 'h1 h2 h3 h4 h5 h6 hr i img kbd label li object ol p param pre q samp small span strong sub sup ' +
15
+ 'table tbody td tfoot th thead tr tt ul var').split(' '));
16
+ /** QTI 3.0 elements with no QTI 2.2 counterpart, by canonical (lowercase) name. */
17
+ const QTI3_ONLY_CANONICAL_ELEMENTS = new Set(('contentbody contextdeclaration portablecustominteraction interactionmodules interactionmodule ' +
18
+ 'interactionmarkup catalog cataloginfo card cardentry htmlcontent filehref contextvariable ' +
19
+ 'templatevariable companionmaterialsinfo calculator calculatorinfo calculatortype description ' +
20
+ 'digitalmaterial physicalmaterial label protractor rule rulesystemsi rulesystemus incrementsi ' +
21
+ 'incrementus majorincrement minorincrement minimumlength adaptiveselection adaptiveengineref ' +
22
+ 'adaptivesettingsref metadataref usagedataref resourceicon').split(' '));
23
+ /** QTI 2.2 elements that QTI 3.0 removed. */
24
+ const QTI2_ONLY_ELEMENTS = ['infoControl'];
25
+ /** QTI 2.x names that are not the mechanical camelCase reading of their QTI 3.0 name. */
26
+ const QTI2_IRREGULAR_NAMES = {
27
+ 'qti-duration-gte': 'durationGTE',
28
+ 'qti-duration-lt': 'durationLT',
29
+ };
30
+ const qti2Name = (qti3Name) => QTI2_IRREGULAR_NAMES[qti3Name] ??
31
+ qti3Name.slice('qti-'.length).replace(/-([a-z0-9])/g, (_match, character) => character.toUpperCase());
32
+ /** QTI-defined QTI 2.x element names, exactly as the QTI 2.2 schema spells them. */
33
+ export const QTI2_ELEMENTS = new Set([
34
+ ...Object.entries(QTI3_ELEMENT_MAPPINGS)
35
+ .filter(([, canonical]) => !QTI3_ONLY_CANONICAL_ELEMENTS.has(canonical))
36
+ .map(([qti3Name]) => qti2Name(qti3Name)),
37
+ ...QTI2_ONLY_ELEMENTS,
38
+ ]);
39
+ /** QTI-defined QTI 3.0 element names (`qti-*`), as the QTI 3.0 ASI schema declares them. */
40
+ export const QTI3_ELEMENTS = new Set(Object.keys(QTI3_ELEMENT_MAPPINGS));
41
+ /**
42
+ * Whether `localName` is an element the version's schema declares in the QTI namespace: a
43
+ * QTI-defined element, or one of the HTML elements the schema admits there. Names are compared
44
+ * exactly; XML element names are case-sensitive.
45
+ */
46
+ export function isQtiVocabularyElement(localName, version) {
47
+ if (version === '3.0')
48
+ return QTI3_ELEMENTS.has(localName) || QTI3_HTML_ELEMENTS.has(localName);
49
+ return QTI2_ELEMENTS.has(localName) || QTI2_XHTML_ELEMENTS.has(localName);
50
+ }
51
+ //# sourceMappingURL=vocabulary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocabulary.js","sourceRoot":"","sources":["../../src/version-detection/vocabulary.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAKnF,uEAAuE;AACvE,MAAM,CAAC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAC9D,CACC,oGAAoG;IACpG,iGAAiG;IACjG,4CAA4C,CAC5C,CAAC,KAAK,CAAC,GAAG,CAAC,CACZ,CAAC;AAEF,mFAAmF;AACnF,MAAM,4BAA4B,GAAwB,IAAI,GAAG,CAChE,CACC,gGAAgG;IAChG,4FAA4F;IAC5F,+FAA+F;IAC/F,+FAA+F;IAC/F,8FAA8F;IAC9F,2DAA2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,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["/**\n * The element vocabulary each QTI version defines, for checking authored element names without\n * an XSD engine. Built on the XSD-verified QTI 3.0 element map (`qti3-element-mappings.ts`),\n * which `qti3-xsd-conformance.test.ts` checks against the vendored QTI 3.0 ASI schema and the\n * QTI 2.2 schema; `vocabulary.test.ts` checks the QTI 2.x reading below against the QTI 2.2 schema.\n *\n * Only element names in the QTI namespace are QTI vocabulary. MathML, SSML, PCI, APIP, XInclude\n * and other foreign vocabularies keep their own namespaces and are not checked here.\n */\nimport { QTI3_HTML_ELEMENTS } from '../element-mapper/qti2-to-qti3.js';\nimport { QTI3_ELEMENT_MAPPINGS } from '../element-mapper/qti3-element-mappings.js';\n\n/** The vocabularies distinguished here. QTI 2.0 and 2.1 items are checked against QTI 2.2's. */\nexport type QtiVocabularyVersion = '2.x' | '3.0';\n\n/** XHTML elements the QTI 2.2 schema declares in its own namespace. */\nexport const QTI2_XHTML_ELEMENTS: ReadonlySet<string> = new Set(\n\t(\n\t\t'a abbr acronym address b bdo big blockquote br caption cite code col colgroup dd dfn div dl dt em ' +\n\t\t'h1 h2 h3 h4 h5 h6 hr i img kbd label li object ol p param pre q samp small span strong sub sup ' +\n\t\t'table tbody td tfoot th thead tr tt ul var'\n\t).split(' '),\n);\n\n/** QTI 3.0 elements with no QTI 2.2 counterpart, by canonical (lowercase) name. */\nconst QTI3_ONLY_CANONICAL_ELEMENTS: ReadonlySet<string> = new Set(\n\t(\n\t\t'contentbody contextdeclaration portablecustominteraction interactionmodules interactionmodule ' +\n\t\t'interactionmarkup catalog cataloginfo card cardentry htmlcontent filehref contextvariable ' +\n\t\t'templatevariable companionmaterialsinfo calculator calculatorinfo calculatortype description ' +\n\t\t'digitalmaterial physicalmaterial label protractor rule rulesystemsi rulesystemus incrementsi ' +\n\t\t'incrementus majorincrement minorincrement minimumlength adaptiveselection adaptiveengineref ' +\n\t\t'adaptivesettingsref metadataref usagedataref resourceicon'\n\t).split(' '),\n);\n\n/** QTI 2.2 elements that QTI 3.0 removed. */\nconst QTI2_ONLY_ELEMENTS: readonly string[] = ['infoControl'];\n\n/** QTI 2.x names that are not the mechanical camelCase reading of their QTI 3.0 name. */\nconst QTI2_IRREGULAR_NAMES: Readonly<Record<string, string>> = {\n\t'qti-duration-gte': 'durationGTE',\n\t'qti-duration-lt': 'durationLT',\n};\n\nconst qti2Name = (qti3Name: string): string =>\n\tQTI2_IRREGULAR_NAMES[qti3Name] ??\n\tqti3Name.slice('qti-'.length).replace(/-([a-z0-9])/g, (_match, character: string) => character.toUpperCase());\n\n/** QTI-defined QTI 2.x element names, exactly as the QTI 2.2 schema spells them. */\nexport const QTI2_ELEMENTS: ReadonlySet<string> = new Set([\n\t...Object.entries(QTI3_ELEMENT_MAPPINGS)\n\t\t.filter(([, canonical]) => !QTI3_ONLY_CANONICAL_ELEMENTS.has(canonical))\n\t\t.map(([qti3Name]) => qti2Name(qti3Name)),\n\t...QTI2_ONLY_ELEMENTS,\n]);\n\n/** QTI-defined QTI 3.0 element names (`qti-*`), as the QTI 3.0 ASI schema declares them. */\nexport const QTI3_ELEMENTS: ReadonlySet<string> = new Set(Object.keys(QTI3_ELEMENT_MAPPINGS));\n\n/**\n * Whether `localName` is an element the version's schema declares in the QTI namespace: a\n * QTI-defined element, or one of the HTML elements the schema admits there. Names are compared\n * exactly; XML element names are case-sensitive.\n */\nexport function isQtiVocabularyElement(localName: string, version: QtiVocabularyVersion): boolean {\n\tif (version === '3.0') return QTI3_ELEMENTS.has(localName) || QTI3_HTML_ELEMENTS.has(localName);\n\treturn QTI2_ELEMENTS.has(localName) || QTI2_XHTML_ELEMENTS.has(localName);\n}\n"]}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@pie-qti/qti-common",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.6",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
- "node-html-parser": "^9.0.5"
6
+ "node-html-parser": "^9.0.7"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@types/bun": "^1.4.4",
10
10
  "@xmldom/xmldom": "^0.9.12",
11
- "typescript": "^5.9.3"
11
+ "typescript": "^6.0.3"
12
12
  },
13
13
  "exports": {
14
14
  ".": {