@pie-qti/qti-common 0.1.27 → 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.
Files changed (62) hide show
  1. package/README.md +31 -86
  2. package/package.json +2 -3
  3. package/dist/accessibility/apip.d.ts +0 -66
  4. package/dist/accessibility/apip.js +0 -596
  5. package/dist/accessibility/apip.js.map +0 -1
  6. package/dist/accessibility/catalog.d.ts +0 -51
  7. package/dist/accessibility/catalog.js +0 -41
  8. package/dist/accessibility/catalog.js.map +0 -1
  9. package/dist/accessibility/index.d.ts +0 -2
  10. package/dist/accessibility/index.js +0 -3
  11. package/dist/accessibility/index.js.map +0 -1
  12. package/dist/dom/assignProps.d.ts +0 -4
  13. package/dist/dom/assignProps.js +0 -9
  14. package/dist/dom/assignProps.js.map +0 -1
  15. package/dist/dom/svelteMountController.d.ts +0 -25
  16. package/dist/dom/svelteMountController.js +0 -131
  17. package/dist/dom/svelteMountController.js.map +0 -1
  18. package/dist/dom/touchDrag.d.ts +0 -10
  19. package/dist/dom/touchDrag.js +0 -141
  20. package/dist/dom/touchDrag.js.map +0 -1
  21. package/dist/element-mapper/AttributeNameMapper.d.ts +0 -66
  22. package/dist/element-mapper/AttributeNameMapper.js +0 -2
  23. package/dist/element-mapper/AttributeNameMapper.js.map +0 -1
  24. package/dist/element-mapper/ElementNameMapper.d.ts +0 -66
  25. package/dist/element-mapper/ElementNameMapper.js +0 -2
  26. package/dist/element-mapper/ElementNameMapper.js.map +0 -1
  27. package/dist/element-mapper/Qti2xAttributeNameMapper.d.ts +0 -27
  28. package/dist/element-mapper/Qti2xAttributeNameMapper.js +0 -38
  29. package/dist/element-mapper/Qti2xAttributeNameMapper.js.map +0 -1
  30. package/dist/element-mapper/Qti2xElementNameMapper.d.ts +0 -37
  31. package/dist/element-mapper/Qti2xElementNameMapper.js +0 -47
  32. package/dist/element-mapper/Qti2xElementNameMapper.js.map +0 -1
  33. package/dist/element-mapper/Qti3AttributeNameMapper.d.ts +0 -40
  34. package/dist/element-mapper/Qti3AttributeNameMapper.js +0 -87
  35. package/dist/element-mapper/Qti3AttributeNameMapper.js.map +0 -1
  36. package/dist/element-mapper/Qti3ElementNameMapper.d.ts +0 -14
  37. package/dist/element-mapper/Qti3ElementNameMapper.js +0 -39
  38. package/dist/element-mapper/Qti3ElementNameMapper.js.map +0 -1
  39. package/dist/element-mapper/index.d.ts +0 -7
  40. package/dist/element-mapper/index.js +0 -6
  41. package/dist/element-mapper/index.js.map +0 -1
  42. package/dist/element-mapper/qti3-attribute-map.d.ts +0 -8
  43. package/dist/element-mapper/qti3-attribute-map.js +0 -115
  44. package/dist/element-mapper/qti3-attribute-map.js.map +0 -1
  45. package/dist/element-mapper/qti3-element-mappings.d.ts +0 -459
  46. package/dist/element-mapper/qti3-element-mappings.js +0 -328
  47. package/dist/element-mapper/qti3-element-mappings.js.map +0 -1
  48. package/dist/index.d.ts +0 -14
  49. package/dist/index.js +0 -16
  50. package/dist/index.js.map +0 -1
  51. package/dist/parser-factory.d.ts +0 -137
  52. package/dist/parser-factory.js +0 -146
  53. package/dist/parser-factory.js.map +0 -1
  54. package/dist/version-detection/detectQtiVersion.d.ts +0 -23
  55. package/dist/version-detection/detectQtiVersion.js +0 -129
  56. package/dist/version-detection/detectQtiVersion.js.map +0 -1
  57. package/dist/version-detection/index.d.ts +0 -2
  58. package/dist/version-detection/index.js +0 -2
  59. package/dist/version-detection/index.js.map +0 -1
  60. package/dist/xml/attributes.d.ts +0 -77
  61. package/dist/xml/attributes.js +0 -120
  62. package/dist/xml/attributes.js.map +0 -1
@@ -1,146 +0,0 @@
1
- /**
2
- * Parser factory for creating version-appropriate QTI parsers.
3
- *
4
- * This module provides a unified entry point for detecting QTI version
5
- * and creating appropriate element name mappers.
6
- */
7
- import { detectQtiVersion } from './version-detection/detectQtiVersion.js';
8
- import { Qti2xElementNameMapper } from './element-mapper/Qti2xElementNameMapper.js';
9
- import { Qti3ElementNameMapper } from './element-mapper/Qti3ElementNameMapper.js';
10
- import { Qti2xAttributeNameMapper } from './element-mapper/Qti2xAttributeNameMapper.js';
11
- import { Qti3AttributeNameMapper } from './element-mapper/Qti3AttributeNameMapper.js';
12
- /**
13
- * Create a QTI parser with appropriate element name mapper for the given XML.
14
- *
15
- * This function automatically detects the QTI version and returns the appropriate
16
- * element name mapper. It can be used as the primary entry point for parsing
17
- * any QTI content.
18
- *
19
- * @param xml - QTI XML content as string
20
- * @param options - Optional configuration
21
- * @returns Parser result with version plus element and attribute mappers
22
- *
23
- * @example
24
- * ```typescript
25
- * // Auto-detect version and create appropriate parser
26
- * const { version, mapper, attributeMapper } = createQtiParser(xml);
27
- * console.log(`Detected QTI ${version}`);
28
- *
29
- * // Use with qti-processing
30
- * const program = buildResponseProcessingAst(responseProcessing, { elementNameMapper: mapper });
31
- *
32
- * // Use with item-player
33
- * const definition = createAssessmentItemDefinition({
34
- * itemXml: xml,
35
- * elementNameMapper: mapper,
36
- * attributeNameMapper: attributeMapper
37
- * });
38
- * ```
39
- *
40
- * @example
41
- * ```typescript
42
- * // Force specific version
43
- * const { mapper } = createQtiParser(xml, { version: '3.0' });
44
- * ```
45
- */
46
- export function createQtiParser(xml, options) {
47
- // Detect or use specified version
48
- const version = options?.version ?? detectQtiVersion(xml);
49
- // Use custom mappers if provided, otherwise create appropriate ones
50
- const mapper = options?.mapper ?? createMapperForVersion(version);
51
- const attributeMapper = options?.attributeMapper ?? createAttributeMapperForVersion(version);
52
- return {
53
- version,
54
- mapper,
55
- attributeMapper,
56
- };
57
- }
58
- /**
59
- * Create element name mapper for a specific QTI version.
60
- *
61
- * @param version - QTI version
62
- * @returns Element name mapper for the version
63
- *
64
- * @example
65
- * ```typescript
66
- * const qti2Mapper = createMapperForVersion('2.2');
67
- * const qti3Mapper = createMapperForVersion('3.0');
68
- * ```
69
- */
70
- export function createMapperForVersion(version) {
71
- switch (version) {
72
- case '2.0':
73
- case '2.1':
74
- case '2.2':
75
- return new Qti2xElementNameMapper();
76
- case '3.0':
77
- return new Qti3ElementNameMapper();
78
- case 'unknown':
79
- default:
80
- // Default to QTI 2.x mapper for unknown versions
81
- // (most existing content is QTI 2.x)
82
- return new Qti2xElementNameMapper();
83
- }
84
- }
85
- /**
86
- * Create attribute name mapper for a specific QTI version.
87
- *
88
- * @param version - QTI version
89
- * @returns Attribute name mapper for the version
90
- *
91
- * @example
92
- * ```typescript
93
- * const qti2AttrMapper = createAttributeMapperForVersion('2.2');
94
- * const qti3AttrMapper = createAttributeMapperForVersion('3.0');
95
- * ```
96
- */
97
- export function createAttributeMapperForVersion(version) {
98
- switch (version) {
99
- case '2.0':
100
- case '2.1':
101
- case '2.2':
102
- return new Qti2xAttributeNameMapper();
103
- case '3.0':
104
- return new Qti3AttributeNameMapper();
105
- case 'unknown':
106
- default:
107
- // Default to QTI 2.x mapper for unknown versions
108
- return new Qti2xAttributeNameMapper();
109
- }
110
- }
111
- /**
112
- * Check if XML content is QTI 3.0.
113
- *
114
- * Convenience function for quickly checking if content uses QTI 3.0.
115
- *
116
- * @param xml - QTI XML content
117
- * @returns true if QTI 3.0, false otherwise
118
- *
119
- * @example
120
- * ```typescript
121
- * if (isQti3(xml)) {
122
- * console.log('This is QTI 3.0 content');
123
- * }
124
- * ```
125
- */
126
- export function isQti3(xml) {
127
- return detectQtiVersion(xml) === '3.0';
128
- }
129
- /**
130
- * Check if XML content is QTI 2.x (2.0, 2.1, or 2.2).
131
- *
132
- * @param xml - QTI XML content
133
- * @returns true if QTI 2.x, false otherwise
134
- *
135
- * @example
136
- * ```typescript
137
- * if (isQti2(xml)) {
138
- * console.log('This is QTI 2.x content');
139
- * }
140
- * ```
141
- */
142
- export function isQti2(xml) {
143
- const version = detectQtiVersion(xml);
144
- return version === '2.0' || version === '2.1' || version === '2.2';
145
- }
146
- //# sourceMappingURL=parser-factory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parser-factory.js","sourceRoot":"","sources":["../src/parser-factory.ts"],"names":[],"mappings":"AAAA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,KAAK,KAAK;YACT,OAAO,IAAI,wBAAwB,EAAE,CAAC;QAEvC,KAAK,KAAK;YACT,OAAO,IAAI,uBAAuB,EAAE,CAAC;QAEtC,KAAK,SAAS,CAAC;QACf;YACC,iDAAiD;YACjD,OAAO,IAAI,wBAAwB,EAAE,CAAC;IACxC,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW;IACjC,OAAO,gBAAgB,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW;IACjC,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,CAAC;AACpE,CAAC","sourcesContent":["/**\n * Parser factory for creating version-appropriate QTI parsers.\n *\n * This module provides a unified entry point for detecting QTI version\n * and creating appropriate element name mappers.\n */\n\nimport { detectQtiVersion, type QtiVersion } from './version-detection/detectQtiVersion.js';\nimport { Qti2xElementNameMapper } from './element-mapper/Qti2xElementNameMapper.js';\nimport { Qti3ElementNameMapper } from './element-mapper/Qti3ElementNameMapper.js';\nimport type { ElementNameMapper } from './element-mapper/ElementNameMapper.js';\nimport { Qti2xAttributeNameMapper } from './element-mapper/Qti2xAttributeNameMapper.js';\nimport { Qti3AttributeNameMapper } from './element-mapper/Qti3AttributeNameMapper.js';\nimport type { AttributeNameMapper } from './element-mapper/AttributeNameMapper.js';\n\n/**\n * Result of creating a QTI parser.\n */\nexport interface QtiParserResult {\n\t/**\n\t * Detected or specified QTI version\n\t */\n\tversion: QtiVersion;\n\n\t/**\n\t * Element name mapper appropriate for the detected version\n\t */\n\tmapper: ElementNameMapper;\n\n\t/**\n\t * Attribute name mapper appropriate for the detected version\n\t */\n\tattributeMapper: AttributeNameMapper;\n}\n\n/**\n * Options for creating a QTI parser.\n */\nexport interface CreateParserOptions {\n\t/**\n\t * Override automatic version detection.\n\t * If not provided, version will be detected from XML content.\n\t */\n\tversion?: QtiVersion;\n\n\t/**\n\t * Custom element name mapper to use.\n\t * If provided, overrides automatic mapper selection.\n\t */\n\tmapper?: ElementNameMapper;\n\n\t/**\n\t * Custom attribute name mapper to use.\n\t * If provided, overrides automatic mapper selection.\n\t */\n\tattributeMapper?: AttributeNameMapper;\n}\n\n/**\n * Create a QTI parser with appropriate element name mapper for the given XML.\n *\n * This function automatically detects the QTI version and returns the appropriate\n * element name mapper. It can be used as the primary entry point for parsing\n * any QTI content.\n *\n * @param xml - QTI XML content as string\n * @param options - Optional configuration\n * @returns Parser result with version plus element and attribute mappers\n *\n * @example\n * ```typescript\n * // Auto-detect version and create appropriate parser\n * const { version, mapper, attributeMapper } = createQtiParser(xml);\n * console.log(`Detected QTI ${version}`);\n *\n * // Use with qti-processing\n * const program = buildResponseProcessingAst(responseProcessing, { elementNameMapper: mapper });\n *\n * // Use with item-player\n * const definition = createAssessmentItemDefinition({\n * itemXml: xml,\n * elementNameMapper: mapper,\n * attributeNameMapper: attributeMapper\n * });\n * ```\n *\n * @example\n * ```typescript\n * // Force specific version\n * const { mapper } = createQtiParser(xml, { version: '3.0' });\n * ```\n */\nexport function createQtiParser(xml: string, options?: CreateParserOptions): QtiParserResult {\n\t// Detect or use specified version\n\tconst version = options?.version ?? detectQtiVersion(xml);\n\n\t// Use custom mappers if provided, otherwise create appropriate ones\n\tconst mapper = options?.mapper ?? createMapperForVersion(version);\n\tconst attributeMapper = options?.attributeMapper ?? createAttributeMapperForVersion(version);\n\n\treturn {\n\t\tversion,\n\t\tmapper,\n\t\tattributeMapper,\n\t};\n}\n\n/**\n * Create element name mapper for a specific QTI version.\n *\n * @param version - QTI version\n * @returns Element name mapper for the version\n *\n * @example\n * ```typescript\n * const qti2Mapper = createMapperForVersion('2.2');\n * const qti3Mapper = createMapperForVersion('3.0');\n * ```\n */\nexport function createMapperForVersion(version: QtiVersion): ElementNameMapper {\n\tswitch (version) {\n\t\tcase '2.0':\n\t\tcase '2.1':\n\t\tcase '2.2':\n\t\t\treturn new Qti2xElementNameMapper();\n\n\t\tcase '3.0':\n\t\t\treturn new Qti3ElementNameMapper();\n\n\t\tcase 'unknown':\n\t\tdefault:\n\t\t\t// Default to QTI 2.x mapper for unknown versions\n\t\t\t// (most existing content is QTI 2.x)\n\t\t\treturn new Qti2xElementNameMapper();\n\t}\n}\n\n/**\n * Create attribute name mapper for a specific QTI version.\n *\n * @param version - QTI version\n * @returns Attribute name mapper for the version\n *\n * @example\n * ```typescript\n * const qti2AttrMapper = createAttributeMapperForVersion('2.2');\n * const qti3AttrMapper = createAttributeMapperForVersion('3.0');\n * ```\n */\nexport function createAttributeMapperForVersion(version: QtiVersion): AttributeNameMapper {\n\tswitch (version) {\n\t\tcase '2.0':\n\t\tcase '2.1':\n\t\tcase '2.2':\n\t\t\treturn new Qti2xAttributeNameMapper();\n\n\t\tcase '3.0':\n\t\t\treturn new Qti3AttributeNameMapper();\n\n\t\tcase 'unknown':\n\t\tdefault:\n\t\t\t// Default to QTI 2.x mapper for unknown versions\n\t\t\treturn new Qti2xAttributeNameMapper();\n\t}\n}\n\n/**\n * Check if XML content is QTI 3.0.\n *\n * Convenience function for quickly checking if content uses QTI 3.0.\n *\n * @param xml - QTI XML content\n * @returns true if QTI 3.0, false otherwise\n *\n * @example\n * ```typescript\n * if (isQti3(xml)) {\n * console.log('This is QTI 3.0 content');\n * }\n * ```\n */\nexport function isQti3(xml: string): boolean {\n\treturn detectQtiVersion(xml) === '3.0';\n}\n\n/**\n * Check if XML content is QTI 2.x (2.0, 2.1, or 2.2).\n *\n * @param xml - QTI XML content\n * @returns true if QTI 2.x, false otherwise\n *\n * @example\n * ```typescript\n * if (isQti2(xml)) {\n * console.log('This is QTI 2.x content');\n * }\n * ```\n */\nexport function isQti2(xml: string): boolean {\n\tconst version = detectQtiVersion(xml);\n\treturn version === '2.0' || version === '2.1' || version === '2.2';\n}\n"]}
@@ -1,23 +0,0 @@
1
- /**
2
- * QTI version identifiers
3
- */
4
- export type QtiVersion = '2.0' | '2.1' | '2.2' | '3.0' | 'unknown';
5
- /**
6
- * Detect the QTI version from XML content.
7
- *
8
- * Detection strategy (in priority order):
9
- * 1. Check XML namespace URI for version indicators (v2p0, v2p1, v2p2, v3p0)
10
- * 2. Check root element name (qti-assessment-item => 3.0, assessmentItem => 2.x)
11
- * 3. Check version attribute on root element
12
- * 4. Fall back to 'unknown'
13
- *
14
- * @param xml - QTI XML content as string
15
- * @returns Detected QTI version or 'unknown'
16
- *
17
- * @example
18
- * ```typescript
19
- * const xml = `<qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0">`;
20
- * detectQtiVersion(xml); // => '3.0'
21
- * ```
22
- */
23
- export declare function detectQtiVersion(xml: string): QtiVersion;
@@ -1,129 +0,0 @@
1
- /**
2
- * Detect the QTI version from XML content.
3
- *
4
- * Detection strategy (in priority order):
5
- * 1. Check XML namespace URI for version indicators (v2p0, v2p1, v2p2, v3p0)
6
- * 2. Check root element name (qti-assessment-item => 3.0, assessmentItem => 2.x)
7
- * 3. Check version attribute on root element
8
- * 4. Fall back to 'unknown'
9
- *
10
- * @param xml - QTI XML content as string
11
- * @returns Detected QTI version or 'unknown'
12
- *
13
- * @example
14
- * ```typescript
15
- * const xml = `<qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0">`;
16
- * detectQtiVersion(xml); // => '3.0'
17
- * ```
18
- */
19
- export function detectQtiVersion(xml) {
20
- try {
21
- // Check if we're in a browser environment
22
- if (typeof window !== 'undefined' && typeof window.DOMParser !== 'undefined') {
23
- const parser = new window.DOMParser();
24
- const doc = parser.parseFromString(xml, 'text/xml');
25
- return detectFromDocument(doc);
26
- }
27
- // In Node.js environment, fall back to regex detection
28
- // (xmldom can be optionally imported by consumers if needed)
29
- return detectFromString(xml);
30
- }
31
- catch {
32
- // If parsing fails, try string-based detection
33
- return detectFromString(xml);
34
- }
35
- }
36
- /**
37
- * Detect QTI version from a parsed Document.
38
- * @param doc - Parsed XML document
39
- * @returns Detected QTI version
40
- * @private
41
- */
42
- function detectFromDocument(doc) {
43
- const root = doc.documentElement;
44
- // Check for parse errors
45
- if (root.tagName === 'parsererror') {
46
- return 'unknown';
47
- }
48
- // Strategy 1: Check namespace URI
49
- 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
- }
62
- }
63
- // Strategy 2: Check root element name (any qti- prefixed element indicates QTI 3.0)
64
- 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';
85
- }
86
- /**
87
- * Detect QTI version using string matching (fallback method).
88
- * @param xml - XML string
89
- * @returns Detected QTI version
90
- * @private
91
- */
92
- 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';
102
- }
103
- if (xml.includes('imsqti_v2p0') || xml.includes('/v2p0/')) {
104
- return '2.0';
105
- }
106
- // Check root element or any QTI 3.0 element (kebab-case with qti- prefix)
107
- if (/<qti-assessment-(item|test)[\s>]/.test(xml) || /<qti-[a-z-]+[\s>]/.test(xml)) {
108
- return '3.0';
109
- }
110
- 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';
123
- }
124
- // Assume 2.2 if no version specified
125
- return '2.2';
126
- }
127
- return 'unknown';
128
- }
129
- //# sourceMappingURL=detectQtiVersion.js.map
@@ -1 +0,0 @@
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;A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K,CAAC,0BAA0B,CAAC,CAAC;QAC3D,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC3C,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC5C,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC5C,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;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,2 +0,0 @@
1
- export { detectQtiVersion } from './detectQtiVersion.js';
2
- export type { QtiVersion } from './detectQtiVersion.js';
@@ -1,2 +0,0 @@
1
- export { detectQtiVersion } from './detectQtiVersion.js';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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,77 +0,0 @@
1
- /**
2
- * Attribute name handling for QTI 2.x and QTI 3.0.
3
- *
4
- * QTI 2.x uses camelCase: identifier, baseType, responseIdentifier
5
- * QTI 3.0 uses kebab-case: identifier, base-type, response-identifier
6
- *
7
- * This module provides utilities to access attributes regardless of version.
8
- */
9
- /**
10
- * Convert camelCase to kebab-case.
11
- * @param name - camelCase attribute name
12
- * @returns kebab-case attribute name
13
- *
14
- * @example
15
- * toKebabCase('baseType') // => 'base-type'
16
- * toKebabCase('responseIdentifier') // => 'response-identifier'
17
- */
18
- export declare function toKebabCase(name: string): string;
19
- /**
20
- * Convert kebab-case to camelCase.
21
- * @param name - kebab-case attribute name
22
- * @returns camelCase attribute name
23
- *
24
- * @example
25
- * toCamelCase('base-type') // => 'baseType'
26
- * toCamelCase('response-identifier') // => 'responseIdentifier'
27
- */
28
- export declare function toCamelCase(name: string): string;
29
- /**
30
- * Get attribute value supporting both QTI 2.x (camelCase) and QTI 3.0 (kebab-case).
31
- *
32
- * This function tries to retrieve the attribute in both formats:
33
- * 1. First tries the exact name as provided
34
- * 2. If not found and name is camelCase, tries kebab-case version
35
- * 3. If not found and name is kebab-case, tries camelCase version
36
- *
37
- * @param element - Element to get attribute from
38
- * @param name - Attribute name (can be camelCase or kebab-case)
39
- * @returns Attribute value or null if not found
40
- *
41
- * @example
42
- * // Works with QTI 2.x:
43
- * getAttribute(el, 'baseType') // => 'float' (from baseType="float")
44
- *
45
- * // Works with QTI 3.0:
46
- * getAttribute(el, 'baseType') // => 'float' (from base-type="float")
47
- * getAttribute(el, 'base-type') // => 'float' (from base-type="float")
48
- */
49
- export declare function getAttribute(element: Element, name: string): string | null;
50
- /**
51
- * Check if element has attribute (supports both camelCase and kebab-case).
52
- *
53
- * @param element - Element to check
54
- * @param name - Attribute name
55
- * @returns true if attribute exists
56
- */
57
- export declare function hasAttribute(element: Element, name: string): boolean;
58
- /**
59
- * Get attribute as number.
60
- *
61
- * @param element - Element to get attribute from
62
- * @param name - Attribute name
63
- * @param defaultValue - Default value if attribute is missing or invalid
64
- * @returns Attribute value as number
65
- */
66
- export declare function getNumberAttribute(element: Element, name: string, defaultValue: number): number;
67
- /**
68
- * Get attribute as boolean.
69
- *
70
- * QTI uses 'true'/'false' or '1'/'0' for boolean attributes.
71
- *
72
- * @param element - Element to get attribute from
73
- * @param name - Attribute name
74
- * @param defaultValue - Default value if attribute is missing
75
- * @returns Attribute value as boolean
76
- */
77
- export declare function getBooleanAttribute(element: Element, name: string, defaultValue?: boolean): boolean;
@@ -1,120 +0,0 @@
1
- /**
2
- * Attribute name handling for QTI 2.x and QTI 3.0.
3
- *
4
- * QTI 2.x uses camelCase: identifier, baseType, responseIdentifier
5
- * QTI 3.0 uses kebab-case: identifier, base-type, response-identifier
6
- *
7
- * This module provides utilities to access attributes regardless of version.
8
- */
9
- /**
10
- * Convert camelCase to kebab-case.
11
- * @param name - camelCase attribute name
12
- * @returns kebab-case attribute name
13
- *
14
- * @example
15
- * toKebabCase('baseType') // => 'base-type'
16
- * toKebabCase('responseIdentifier') // => 'response-identifier'
17
- */
18
- export function toKebabCase(name) {
19
- return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
20
- }
21
- /**
22
- * Convert kebab-case to camelCase.
23
- * @param name - kebab-case attribute name
24
- * @returns camelCase attribute name
25
- *
26
- * @example
27
- * toCamelCase('base-type') // => 'baseType'
28
- * toCamelCase('response-identifier') // => 'responseIdentifier'
29
- */
30
- export function toCamelCase(name) {
31
- return name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
32
- }
33
- /**
34
- * Get attribute value supporting both QTI 2.x (camelCase) and QTI 3.0 (kebab-case).
35
- *
36
- * This function tries to retrieve the attribute in both formats:
37
- * 1. First tries the exact name as provided
38
- * 2. If not found and name is camelCase, tries kebab-case version
39
- * 3. If not found and name is kebab-case, tries camelCase version
40
- *
41
- * @param element - Element to get attribute from
42
- * @param name - Attribute name (can be camelCase or kebab-case)
43
- * @returns Attribute value or null if not found
44
- *
45
- * @example
46
- * // Works with QTI 2.x:
47
- * getAttribute(el, 'baseType') // => 'float' (from baseType="float")
48
- *
49
- * // Works with QTI 3.0:
50
- * getAttribute(el, 'baseType') // => 'float' (from base-type="float")
51
- * getAttribute(el, 'base-type') // => 'float' (from base-type="float")
52
- */
53
- export function getAttribute(element, name) {
54
- // Try exact name first
55
- let value = element.getAttribute(name);
56
- if (value !== null && value !== '')
57
- return value;
58
- // If name contains uppercase (camelCase), try kebab-case
59
- if (/[A-Z]/.test(name)) {
60
- const kebab = toKebabCase(name);
61
- value = element.getAttribute(kebab);
62
- if (value !== null && value !== '')
63
- return value;
64
- }
65
- // If name contains hyphens (kebab-case), try camelCase
66
- if (name.includes('-')) {
67
- const camel = toCamelCase(name);
68
- value = element.getAttribute(camel);
69
- if (value !== null && value !== '')
70
- return value;
71
- }
72
- return null;
73
- }
74
- /**
75
- * Check if element has attribute (supports both camelCase and kebab-case).
76
- *
77
- * @param element - Element to check
78
- * @param name - Attribute name
79
- * @returns true if attribute exists
80
- */
81
- export function hasAttribute(element, name) {
82
- return getAttribute(element, name) !== null;
83
- }
84
- /**
85
- * Get attribute as number.
86
- *
87
- * @param element - Element to get attribute from
88
- * @param name - Attribute name
89
- * @param defaultValue - Default value if attribute is missing or invalid
90
- * @returns Attribute value as number
91
- */
92
- export function getNumberAttribute(element, name, defaultValue) {
93
- const value = getAttribute(element, name);
94
- if (value === null)
95
- return defaultValue;
96
- const num = Number(value);
97
- return Number.isFinite(num) ? num : defaultValue;
98
- }
99
- /**
100
- * Get attribute as boolean.
101
- *
102
- * QTI uses 'true'/'false' or '1'/'0' for boolean attributes.
103
- *
104
- * @param element - Element to get attribute from
105
- * @param name - Attribute name
106
- * @param defaultValue - Default value if attribute is missing
107
- * @returns Attribute value as boolean
108
- */
109
- export function getBooleanAttribute(element, name, defaultValue = false) {
110
- const value = getAttribute(element, name);
111
- if (value === null)
112
- return defaultValue;
113
- const normalized = value.trim().toLowerCase();
114
- if (normalized === 'true' || normalized === '1')
115
- return true;
116
- if (normalized === 'false' || normalized === '0')
117
- return false;
118
- return defaultValue;
119
- }
120
- //# sourceMappingURL=attributes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../src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AC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,IAAY;IAC1D,OAAO,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAgB,EAAE,IAAY,EAAE,YAAoB;IACtF,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC1C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,YAAY,CAAC;IACxC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;AAClD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgB,EAAE,IAAY,EAAE,YAAY,GAAG,KAAK;IACvF,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC1C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,YAAY,CAAC;IACxC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC9C,IAAI,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IAC7D,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IAC/D,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["/**\n * Attribute name handling for QTI 2.x and QTI 3.0.\n *\n * QTI 2.x uses camelCase: identifier, baseType, responseIdentifier\n * QTI 3.0 uses kebab-case: identifier, base-type, response-identifier\n *\n * This module provides utilities to access attributes regardless of version.\n */\n\n/**\n * Convert camelCase to kebab-case.\n * @param name - camelCase attribute name\n * @returns kebab-case attribute name\n *\n * @example\n * toKebabCase('baseType') // => 'base-type'\n * toKebabCase('responseIdentifier') // => 'response-identifier'\n */\nexport function toKebabCase(name: string): string {\n\treturn name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\n/**\n * Convert kebab-case to camelCase.\n * @param name - kebab-case attribute name\n * @returns camelCase attribute name\n *\n * @example\n * toCamelCase('base-type') // => 'baseType'\n * toCamelCase('response-identifier') // => 'responseIdentifier'\n */\nexport function toCamelCase(name: string): string {\n\treturn name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Get attribute value supporting both QTI 2.x (camelCase) and QTI 3.0 (kebab-case).\n *\n * This function tries to retrieve the attribute in both formats:\n * 1. First tries the exact name as provided\n * 2. If not found and name is camelCase, tries kebab-case version\n * 3. If not found and name is kebab-case, tries camelCase version\n *\n * @param element - Element to get attribute from\n * @param name - Attribute name (can be camelCase or kebab-case)\n * @returns Attribute value or null if not found\n *\n * @example\n * // Works with QTI 2.x:\n * getAttribute(el, 'baseType') // => 'float' (from baseType=\"float\")\n *\n * // Works with QTI 3.0:\n * getAttribute(el, 'baseType') // => 'float' (from base-type=\"float\")\n * getAttribute(el, 'base-type') // => 'float' (from base-type=\"float\")\n */\nexport function getAttribute(element: Element, name: string): string | null {\n\t// Try exact name first\n\tlet value = element.getAttribute(name);\n\tif (value !== null && value !== '') return value;\n\n\t// If name contains uppercase (camelCase), try kebab-case\n\tif (/[A-Z]/.test(name)) {\n\t\tconst kebab = toKebabCase(name);\n\t\tvalue = element.getAttribute(kebab);\n\t\tif (value !== null && value !== '') return value;\n\t}\n\n\t// If name contains hyphens (kebab-case), try camelCase\n\tif (name.includes('-')) {\n\t\tconst camel = toCamelCase(name);\n\t\tvalue = element.getAttribute(camel);\n\t\tif (value !== null && value !== '') return value;\n\t}\n\n\treturn null;\n}\n\n/**\n * Check if element has attribute (supports both camelCase and kebab-case).\n *\n * @param element - Element to check\n * @param name - Attribute name\n * @returns true if attribute exists\n */\nexport function hasAttribute(element: Element, name: string): boolean {\n\treturn getAttribute(element, name) !== null;\n}\n\n/**\n * Get attribute as number.\n *\n * @param element - Element to get attribute from\n * @param name - Attribute name\n * @param defaultValue - Default value if attribute is missing or invalid\n * @returns Attribute value as number\n */\nexport function getNumberAttribute(element: Element, name: string, defaultValue: number): number {\n\tconst value = getAttribute(element, name);\n\tif (value === null) return defaultValue;\n\tconst num = Number(value);\n\treturn Number.isFinite(num) ? num : defaultValue;\n}\n\n/**\n * Get attribute as boolean.\n *\n * QTI uses 'true'/'false' or '1'/'0' for boolean attributes.\n *\n * @param element - Element to get attribute from\n * @param name - Attribute name\n * @param defaultValue - Default value if attribute is missing\n * @returns Attribute value as boolean\n */\nexport function getBooleanAttribute(element: Element, name: string, defaultValue = false): boolean {\n\tconst value = getAttribute(element, name);\n\tif (value === null) return defaultValue;\n\tconst normalized = value.trim().toLowerCase();\n\tif (normalized === 'true' || normalized === '1') return true;\n\tif (normalized === 'false' || normalized === '0') return false;\n\treturn defaultValue;\n}\n"]}