@pie-qti/ims-cp-core 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.
- package/package.json +2 -2
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/localized-resources.d.ts +0 -308
- package/dist/localized-resources.js +0 -410
- package/dist/localized-resources.js.map +0 -1
- package/dist/manifest-parser.d.ts +0 -82
- package/dist/manifest-parser.js +0 -213
- package/dist/manifest-parser.js.map +0 -1
- package/dist/package-file-resolver.d.ts +0 -48
- package/dist/package-file-resolver.js +0 -312
- package/dist/package-file-resolver.js.map +0 -1
- package/dist/package-graph.d.ts +0 -134
- package/dist/package-graph.js +0 -791
- package/dist/package-graph.js.map +0 -1
- package/dist/package-path.d.ts +0 -11
- package/dist/package-path.js +0 -89
- package/dist/package-path.js.map +0 -1
- package/dist/passage-reusability.d.ts +0 -99
- package/dist/passage-reusability.js +0 -170
- package/dist/passage-reusability.js.map +0 -1
- package/dist/qti-heuristics.d.ts +0 -119
- package/dist/qti-heuristics.js +0 -150
- package/dist/qti-heuristics.js.map +0 -1
- package/dist/qti3-shared-content.d.ts +0 -82
- package/dist/qti3-shared-content.js +0 -383
- package/dist/qti3-shared-content.js.map +0 -1
- package/dist/security-parsing.d.ts +0 -9
- package/dist/security-parsing.js +0 -74
- package/dist/security-parsing.js.map +0 -1
- package/dist/utils/hash.d.ts +0 -20
- package/dist/utils/hash.js +0 -33
- package/dist/utils/hash.js.map +0 -1
- package/dist/utils/qti-xml.d.ts +0 -103
- package/dist/utils/qti-xml.js +0 -214
- package/dist/utils/qti-xml.js.map +0 -1
package/dist/qti-heuristics.d.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QTI Content Heuristics
|
|
3
|
-
*
|
|
4
|
-
* This module contains heuristics for handling non-standard QTI content commonly
|
|
5
|
-
* found in real-world QTI packages from various authoring tools.
|
|
6
|
-
*
|
|
7
|
-
* ⚠️ IMPORTANT: These are NOT part of the QTI specification. They are pragmatic
|
|
8
|
-
* workarounds for content that doesn't strictly follow QTI standards but is
|
|
9
|
-
* commonly encountered in production.
|
|
10
|
-
*
|
|
11
|
-
* All heuristics:
|
|
12
|
-
* - Are OPTIONAL and can be disabled
|
|
13
|
-
* - Log when they are applied (in debug mode)
|
|
14
|
-
* - Will NEVER hide real QTI errors
|
|
15
|
-
* - Will NEVER break valid QTI content
|
|
16
|
-
*
|
|
17
|
-
* @see https://www.imsglobal.org/question/ for QTI specifications
|
|
18
|
-
*/
|
|
19
|
-
import type { Logger } from '@pie-qti/logger';
|
|
20
|
-
/**
|
|
21
|
-
* Configuration for QTI content heuristics
|
|
22
|
-
*/
|
|
23
|
-
export interface QtiHeuristicsConfig {
|
|
24
|
-
/**
|
|
25
|
-
* Enable all heuristics (default: true)
|
|
26
|
-
* Set to false for strict QTI-only processing
|
|
27
|
-
*/
|
|
28
|
-
enabled?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Apply feedback text formatting fixes
|
|
31
|
-
* Some authoring tools add semicolons after "Correct" and "Incorrect" labels
|
|
32
|
-
* (default: true when enabled)
|
|
33
|
-
*/
|
|
34
|
-
feedbackTextFormatting?: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Apply lenient image path resolution
|
|
37
|
-
* Try multiple path resolution strategies for images that don't follow
|
|
38
|
-
* strict relative path conventions (default: true when enabled)
|
|
39
|
-
*/
|
|
40
|
-
lenientImagePaths?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Apply lenient package resource path resolution
|
|
43
|
-
* Try unambiguous path-segment suffix matches for real-world packages whose
|
|
44
|
-
* media or stylesheet references drift from the strict source-relative path.
|
|
45
|
-
* (default: true when enabled)
|
|
46
|
-
*/
|
|
47
|
-
lenientPackageResourcePaths?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Apply lenient basename-only matching for media asset references.
|
|
50
|
-
* This is narrower than suffix matching and is never used for source XML.
|
|
51
|
-
* (default: true when enabled)
|
|
52
|
-
*/
|
|
53
|
-
lenientAssetBasenames?: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Auto-populate FEEDBACK outcome for simple choice interactions
|
|
56
|
-
* Some templates only set SCORE but not FEEDBACK, even though feedbackInline
|
|
57
|
-
* elements reference the FEEDBACK outcome (default: true when enabled)
|
|
58
|
-
*/
|
|
59
|
-
autoPopulateFeedbackOutcome?: boolean;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Default heuristics configuration
|
|
63
|
-
* Enables common heuristics by default for better real-world compatibility
|
|
64
|
-
*/
|
|
65
|
-
export declare const DEFAULT_HEURISTICS_CONFIG: Required<QtiHeuristicsConfig>;
|
|
66
|
-
/**
|
|
67
|
-
* Strict QTI configuration - disables all heuristics
|
|
68
|
-
*/
|
|
69
|
-
export declare const STRICT_QTI_CONFIG: Required<QtiHeuristicsConfig>;
|
|
70
|
-
/**
|
|
71
|
-
* Merge user config with defaults
|
|
72
|
-
*/
|
|
73
|
-
export declare function normalizeHeuristicsConfig(config?: QtiHeuristicsConfig): Required<QtiHeuristicsConfig>;
|
|
74
|
-
/**
|
|
75
|
-
* Text replacement pattern for vendor-specific formatting
|
|
76
|
-
*/
|
|
77
|
-
export interface TextTransform {
|
|
78
|
-
/** Regular expression to match */
|
|
79
|
-
pattern: RegExp;
|
|
80
|
-
/** Replacement string */
|
|
81
|
-
replacement: string;
|
|
82
|
-
/** Description of what this fixes */
|
|
83
|
-
description: string;
|
|
84
|
-
/** Which vendor/authoring tool produces this pattern (if known) */
|
|
85
|
-
vendor?: string;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Vendor-specific feedback text transforms
|
|
89
|
-
*
|
|
90
|
-
* These fix formatting issues in feedback text from certain authoring tools:
|
|
91
|
-
* - Some tools add semicolons after "Correct" and "Incorrect" labels
|
|
92
|
-
* - This is not required by QTI and looks awkward in display
|
|
93
|
-
*/
|
|
94
|
-
export declare const FEEDBACK_TEXT_TRANSFORMS: TextTransform[];
|
|
95
|
-
/**
|
|
96
|
-
* Apply feedback text formatting heuristics
|
|
97
|
-
*
|
|
98
|
-
* @param content - HTML content to transform
|
|
99
|
-
* @param config - Heuristics configuration
|
|
100
|
-
* @param logger - Optional logger for debug output
|
|
101
|
-
* @returns Transformed content
|
|
102
|
-
*/
|
|
103
|
-
export declare function applyFeedbackTextHeuristics(content: string, config: Required<QtiHeuristicsConfig>, logger?: Logger): string;
|
|
104
|
-
/**
|
|
105
|
-
* Check if lenient image path resolution should be used
|
|
106
|
-
*
|
|
107
|
-
* @param config - Heuristics configuration
|
|
108
|
-
* @param logger - Optional logger
|
|
109
|
-
* @returns True if lenient resolution is enabled
|
|
110
|
-
*/
|
|
111
|
-
export declare function shouldUseLenientImagePaths(config: Required<QtiHeuristicsConfig>, logger?: Logger): boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Check if auto-populating FEEDBACK outcome should be used
|
|
114
|
-
*
|
|
115
|
-
* @param config - Heuristics configuration
|
|
116
|
-
* @param logger - Optional logger
|
|
117
|
-
* @returns True if auto-population is enabled
|
|
118
|
-
*/
|
|
119
|
-
export declare function shouldAutoPopulateFeedbackOutcome(config: Required<QtiHeuristicsConfig>, logger?: Logger): boolean;
|
package/dist/qti-heuristics.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QTI Content Heuristics
|
|
3
|
-
*
|
|
4
|
-
* This module contains heuristics for handling non-standard QTI content commonly
|
|
5
|
-
* found in real-world QTI packages from various authoring tools.
|
|
6
|
-
*
|
|
7
|
-
* ⚠️ IMPORTANT: These are NOT part of the QTI specification. They are pragmatic
|
|
8
|
-
* workarounds for content that doesn't strictly follow QTI standards but is
|
|
9
|
-
* commonly encountered in production.
|
|
10
|
-
*
|
|
11
|
-
* All heuristics:
|
|
12
|
-
* - Are OPTIONAL and can be disabled
|
|
13
|
-
* - Log when they are applied (in debug mode)
|
|
14
|
-
* - Will NEVER hide real QTI errors
|
|
15
|
-
* - Will NEVER break valid QTI content
|
|
16
|
-
*
|
|
17
|
-
* @see https://www.imsglobal.org/question/ for QTI specifications
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* Default heuristics configuration
|
|
21
|
-
* Enables common heuristics by default for better real-world compatibility
|
|
22
|
-
*/
|
|
23
|
-
export const DEFAULT_HEURISTICS_CONFIG = {
|
|
24
|
-
enabled: true,
|
|
25
|
-
feedbackTextFormatting: true,
|
|
26
|
-
lenientImagePaths: true,
|
|
27
|
-
lenientPackageResourcePaths: true,
|
|
28
|
-
lenientAssetBasenames: true,
|
|
29
|
-
autoPopulateFeedbackOutcome: true,
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Strict QTI configuration - disables all heuristics
|
|
33
|
-
*/
|
|
34
|
-
export const STRICT_QTI_CONFIG = {
|
|
35
|
-
enabled: false,
|
|
36
|
-
feedbackTextFormatting: false,
|
|
37
|
-
lenientImagePaths: false,
|
|
38
|
-
lenientPackageResourcePaths: false,
|
|
39
|
-
lenientAssetBasenames: false,
|
|
40
|
-
autoPopulateFeedbackOutcome: false,
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Merge user config with defaults
|
|
44
|
-
*/
|
|
45
|
-
export function normalizeHeuristicsConfig(config) {
|
|
46
|
-
if (config?.enabled === false) {
|
|
47
|
-
return STRICT_QTI_CONFIG;
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
enabled: config?.enabled ?? DEFAULT_HEURISTICS_CONFIG.enabled,
|
|
51
|
-
feedbackTextFormatting: config?.feedbackTextFormatting ?? DEFAULT_HEURISTICS_CONFIG.feedbackTextFormatting,
|
|
52
|
-
lenientImagePaths: config?.lenientImagePaths ?? DEFAULT_HEURISTICS_CONFIG.lenientImagePaths,
|
|
53
|
-
lenientPackageResourcePaths: config?.lenientPackageResourcePaths ?? DEFAULT_HEURISTICS_CONFIG.lenientPackageResourcePaths,
|
|
54
|
-
lenientAssetBasenames: config?.lenientAssetBasenames ?? DEFAULT_HEURISTICS_CONFIG.lenientAssetBasenames,
|
|
55
|
-
autoPopulateFeedbackOutcome: config?.autoPopulateFeedbackOutcome ??
|
|
56
|
-
DEFAULT_HEURISTICS_CONFIG.autoPopulateFeedbackOutcome,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Vendor-specific feedback text transforms
|
|
61
|
-
*
|
|
62
|
-
* These fix formatting issues in feedback text from certain authoring tools:
|
|
63
|
-
* - Some tools add semicolons after "Correct" and "Incorrect" labels
|
|
64
|
-
* - This is not required by QTI and looks awkward in display
|
|
65
|
-
*/
|
|
66
|
-
export const FEEDBACK_TEXT_TRANSFORMS = [
|
|
67
|
-
{
|
|
68
|
-
pattern: /<strong>Incorrect;<\/strong>/gi,
|
|
69
|
-
replacement: '<strong>Incorrect</strong> ',
|
|
70
|
-
description: 'Remove semicolon after "Incorrect" in strong tags',
|
|
71
|
-
vendor: 'Various authoring tools',
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
pattern: /Incorrect;/gi,
|
|
75
|
-
replacement: 'Incorrect ',
|
|
76
|
-
description: 'Remove semicolon after "Incorrect"',
|
|
77
|
-
vendor: 'Various authoring tools',
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
pattern: /<strong>Correct;<\/strong>/gi,
|
|
81
|
-
replacement: '<strong>Correct</strong> ',
|
|
82
|
-
description: 'Remove semicolon after "Correct" in strong tags',
|
|
83
|
-
vendor: 'Various authoring tools',
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
pattern: /Correct;/gi,
|
|
87
|
-
replacement: 'Correct ',
|
|
88
|
-
description: 'Remove semicolon after "Correct"',
|
|
89
|
-
vendor: 'Various authoring tools',
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
/**
|
|
93
|
-
* Apply feedback text formatting heuristics
|
|
94
|
-
*
|
|
95
|
-
* @param content - HTML content to transform
|
|
96
|
-
* @param config - Heuristics configuration
|
|
97
|
-
* @param logger - Optional logger for debug output
|
|
98
|
-
* @returns Transformed content
|
|
99
|
-
*/
|
|
100
|
-
export function applyFeedbackTextHeuristics(content, config, logger) {
|
|
101
|
-
if (!config.enabled || !config.feedbackTextFormatting || !content) {
|
|
102
|
-
return content;
|
|
103
|
-
}
|
|
104
|
-
let result = content;
|
|
105
|
-
let appliedCount = 0;
|
|
106
|
-
for (const transform of FEEDBACK_TEXT_TRANSFORMS) {
|
|
107
|
-
const before = result;
|
|
108
|
-
result = result.replace(transform.pattern, transform.replacement);
|
|
109
|
-
if (result !== before) {
|
|
110
|
-
appliedCount++;
|
|
111
|
-
logger?.debug(`[QTI Heuristic] Applied feedback text transform: ${transform.description}`, { vendor: transform.vendor });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (appliedCount > 0) {
|
|
115
|
-
logger?.debug(`[QTI Heuristic] Applied ${appliedCount} feedback text formatting fix(es). ` +
|
|
116
|
-
`This content uses non-standard formatting common in certain authoring tools.`);
|
|
117
|
-
}
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Check if lenient image path resolution should be used
|
|
122
|
-
*
|
|
123
|
-
* @param config - Heuristics configuration
|
|
124
|
-
* @param logger - Optional logger
|
|
125
|
-
* @returns True if lenient resolution is enabled
|
|
126
|
-
*/
|
|
127
|
-
export function shouldUseLenientImagePaths(config, logger) {
|
|
128
|
-
const enabled = config.enabled && config.lenientImagePaths;
|
|
129
|
-
if (enabled) {
|
|
130
|
-
logger?.debug('[QTI Heuristic] Using lenient image path resolution. ' +
|
|
131
|
-
'Will try multiple path strategies for images that do not follow strict relative path conventions.');
|
|
132
|
-
}
|
|
133
|
-
return enabled;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Check if auto-populating FEEDBACK outcome should be used
|
|
137
|
-
*
|
|
138
|
-
* @param config - Heuristics configuration
|
|
139
|
-
* @param logger - Optional logger
|
|
140
|
-
* @returns True if auto-population is enabled
|
|
141
|
-
*/
|
|
142
|
-
export function shouldAutoPopulateFeedbackOutcome(config, logger) {
|
|
143
|
-
const enabled = config.enabled && config.autoPopulateFeedbackOutcome;
|
|
144
|
-
if (enabled) {
|
|
145
|
-
logger?.debug('[QTI Heuristic] Will auto-populate FEEDBACK outcome if missing. ' +
|
|
146
|
-
'Some QTI templates use feedbackInline but only set SCORE outcome.');
|
|
147
|
-
}
|
|
148
|
-
return enabled;
|
|
149
|
-
}
|
|
150
|
-
//# sourceMappingURL=qti-heuristics.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"qti-heuristics.js","sourceRoot":"","sources":["../src/qti-heuristics.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * QTI Content Heuristics\n *\n * This module contains heuristics for handling non-standard QTI content commonly\n * found in real-world QTI packages from various authoring tools.\n *\n * ⚠️ IMPORTANT: These are NOT part of the QTI specification. They are pragmatic\n * workarounds for content that doesn't strictly follow QTI standards but is\n * commonly encountered in production.\n *\n * All heuristics:\n * - Are OPTIONAL and can be disabled\n * - Log when they are applied (in debug mode)\n * - Will NEVER hide real QTI errors\n * - Will NEVER break valid QTI content\n *\n * @see https://www.imsglobal.org/question/ for QTI specifications\n */\n\nimport type { Logger } from '@pie-qti/logger';\n\n/**\n * Configuration for QTI content heuristics\n */\nexport interface QtiHeuristicsConfig {\n\t/**\n\t * Enable all heuristics (default: true)\n\t * Set to false for strict QTI-only processing\n\t */\n\tenabled?: boolean;\n\n\t/**\n\t * Apply feedback text formatting fixes\n\t * Some authoring tools add semicolons after \"Correct\" and \"Incorrect\" labels\n\t * (default: true when enabled)\n\t */\n\tfeedbackTextFormatting?: boolean;\n\n\t/**\n\t * Apply lenient image path resolution\n\t * Try multiple path resolution strategies for images that don't follow\n\t * strict relative path conventions (default: true when enabled)\n\t */\n\tlenientImagePaths?: boolean;\n\n\t/**\n\t * Apply lenient package resource path resolution\n\t * Try unambiguous path-segment suffix matches for real-world packages whose\n\t * media or stylesheet references drift from the strict source-relative path.\n\t * (default: true when enabled)\n\t */\n\tlenientPackageResourcePaths?: boolean;\n\n\t/**\n\t * Apply lenient basename-only matching for media asset references.\n\t * This is narrower than suffix matching and is never used for source XML.\n\t * (default: true when enabled)\n\t */\n\tlenientAssetBasenames?: boolean;\n\n\t/**\n\t * Auto-populate FEEDBACK outcome for simple choice interactions\n\t * Some templates only set SCORE but not FEEDBACK, even though feedbackInline\n\t * elements reference the FEEDBACK outcome (default: true when enabled)\n\t */\n\tautoPopulateFeedbackOutcome?: boolean;\n}\n\n/**\n * Default heuristics configuration\n * Enables common heuristics by default for better real-world compatibility\n */\nexport const DEFAULT_HEURISTICS_CONFIG: Required<QtiHeuristicsConfig> = {\n\tenabled: true,\n\tfeedbackTextFormatting: true,\n\tlenientImagePaths: true,\n\tlenientPackageResourcePaths: true,\n\tlenientAssetBasenames: true,\n\tautoPopulateFeedbackOutcome: true,\n};\n\n/**\n * Strict QTI configuration - disables all heuristics\n */\nexport const STRICT_QTI_CONFIG: Required<QtiHeuristicsConfig> = {\n\tenabled: false,\n\tfeedbackTextFormatting: false,\n\tlenientImagePaths: false,\n\tlenientPackageResourcePaths: false,\n\tlenientAssetBasenames: false,\n\tautoPopulateFeedbackOutcome: false,\n};\n\n/**\n * Merge user config with defaults\n */\nexport function normalizeHeuristicsConfig(\n\tconfig?: QtiHeuristicsConfig\n): Required<QtiHeuristicsConfig> {\n\tif (config?.enabled === false) {\n\t\treturn STRICT_QTI_CONFIG;\n\t}\n\n\treturn {\n\t\tenabled: config?.enabled ?? DEFAULT_HEURISTICS_CONFIG.enabled,\n\t\tfeedbackTextFormatting:\n\t\t\tconfig?.feedbackTextFormatting ?? DEFAULT_HEURISTICS_CONFIG.feedbackTextFormatting,\n\t\tlenientImagePaths:\n\t\t\tconfig?.lenientImagePaths ?? DEFAULT_HEURISTICS_CONFIG.lenientImagePaths,\n\t\tlenientPackageResourcePaths:\n\t\t\tconfig?.lenientPackageResourcePaths ?? DEFAULT_HEURISTICS_CONFIG.lenientPackageResourcePaths,\n\t\tlenientAssetBasenames:\n\t\t\tconfig?.lenientAssetBasenames ?? DEFAULT_HEURISTICS_CONFIG.lenientAssetBasenames,\n\t\tautoPopulateFeedbackOutcome:\n\t\t\tconfig?.autoPopulateFeedbackOutcome ??\n\t\t\tDEFAULT_HEURISTICS_CONFIG.autoPopulateFeedbackOutcome,\n\t};\n}\n\n/**\n * Text replacement pattern for vendor-specific formatting\n */\nexport interface TextTransform {\n\t/** Regular expression to match */\n\tpattern: RegExp;\n\t/** Replacement string */\n\treplacement: string;\n\t/** Description of what this fixes */\n\tdescription: string;\n\t/** Which vendor/authoring tool produces this pattern (if known) */\n\tvendor?: string;\n}\n\n/**\n * Vendor-specific feedback text transforms\n *\n * These fix formatting issues in feedback text from certain authoring tools:\n * - Some tools add semicolons after \"Correct\" and \"Incorrect\" labels\n * - This is not required by QTI and looks awkward in display\n */\nexport const FEEDBACK_TEXT_TRANSFORMS: TextTransform[] = [\n\t{\n\t\tpattern: /<strong>Incorrect;<\\/strong>/gi,\n\t\treplacement: '<strong>Incorrect</strong> ',\n\t\tdescription: 'Remove semicolon after \"Incorrect\" in strong tags',\n\t\tvendor: 'Various authoring tools',\n\t},\n\t{\n\t\tpattern: /Incorrect;/gi,\n\t\treplacement: 'Incorrect ',\n\t\tdescription: 'Remove semicolon after \"Incorrect\"',\n\t\tvendor: 'Various authoring tools',\n\t},\n\t{\n\t\tpattern: /<strong>Correct;<\\/strong>/gi,\n\t\treplacement: '<strong>Correct</strong> ',\n\t\tdescription: 'Remove semicolon after \"Correct\" in strong tags',\n\t\tvendor: 'Various authoring tools',\n\t},\n\t{\n\t\tpattern: /Correct;/gi,\n\t\treplacement: 'Correct ',\n\t\tdescription: 'Remove semicolon after \"Correct\"',\n\t\tvendor: 'Various authoring tools',\n\t},\n];\n\n/**\n * Apply feedback text formatting heuristics\n *\n * @param content - HTML content to transform\n * @param config - Heuristics configuration\n * @param logger - Optional logger for debug output\n * @returns Transformed content\n */\nexport function applyFeedbackTextHeuristics(\n\tcontent: string,\n\tconfig: Required<QtiHeuristicsConfig>,\n\tlogger?: Logger\n): string {\n\tif (!config.enabled || !config.feedbackTextFormatting || !content) {\n\t\treturn content;\n\t}\n\n\tlet result = content;\n\tlet appliedCount = 0;\n\n\tfor (const transform of FEEDBACK_TEXT_TRANSFORMS) {\n\t\tconst before = result;\n\t\tresult = result.replace(transform.pattern, transform.replacement);\n\n\t\tif (result !== before) {\n\t\t\tappliedCount++;\n\t\t\tlogger?.debug(\n\t\t\t\t`[QTI Heuristic] Applied feedback text transform: ${transform.description}`,\n\t\t\t\t{ vendor: transform.vendor }\n\t\t\t);\n\t\t}\n\t}\n\n\tif (appliedCount > 0) {\n\t\tlogger?.debug(\n\t\t\t`[QTI Heuristic] Applied ${appliedCount} feedback text formatting fix(es). ` +\n\t\t\t\t`This content uses non-standard formatting common in certain authoring tools.`\n\t\t);\n\t}\n\n\treturn result;\n}\n\n/**\n * Check if lenient image path resolution should be used\n *\n * @param config - Heuristics configuration\n * @param logger - Optional logger\n * @returns True if lenient resolution is enabled\n */\nexport function shouldUseLenientImagePaths(\n\tconfig: Required<QtiHeuristicsConfig>,\n\tlogger?: Logger\n): boolean {\n\tconst enabled = config.enabled && config.lenientImagePaths;\n\n\tif (enabled) {\n\t\tlogger?.debug(\n\t\t\t'[QTI Heuristic] Using lenient image path resolution. ' +\n\t\t\t\t'Will try multiple path strategies for images that do not follow strict relative path conventions.'\n\t\t);\n\t}\n\n\treturn enabled;\n}\n\n/**\n * Check if auto-populating FEEDBACK outcome should be used\n *\n * @param config - Heuristics configuration\n * @param logger - Optional logger\n * @returns True if auto-population is enabled\n */\nexport function shouldAutoPopulateFeedbackOutcome(\n\tconfig: Required<QtiHeuristicsConfig>,\n\tlogger?: Logger\n): boolean {\n\tconst enabled = config.enabled && config.autoPopulateFeedbackOutcome;\n\n\tif (enabled) {\n\t\tlogger?.debug(\n\t\t\t'[QTI Heuristic] Will auto-populate FEEDBACK outcome if missing. ' +\n\t\t\t\t'Some QTI templates use feedbackInline but only set SCORE outcome.'\n\t\t);\n\t}\n\n\treturn enabled;\n}\n"]}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { type PackageFileIndex } from './package-file-resolver.js';
|
|
2
|
-
import type { QtiHeuristicsConfig } from './qti-heuristics.js';
|
|
3
|
-
export interface AssessmentStimulusRef {
|
|
4
|
-
identifier: string;
|
|
5
|
-
href: string;
|
|
6
|
-
title?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface QtiStylesheetRef {
|
|
9
|
-
href: string;
|
|
10
|
-
type?: string;
|
|
11
|
-
media?: string;
|
|
12
|
-
xml: string;
|
|
13
|
-
}
|
|
14
|
-
export interface AssessmentStimulusDocument {
|
|
15
|
-
identifier?: string;
|
|
16
|
-
title?: string;
|
|
17
|
-
lang?: string;
|
|
18
|
-
bodyHtml: string;
|
|
19
|
-
stylesheets: QtiStylesheetRef[];
|
|
20
|
-
catalogInfoXml?: string;
|
|
21
|
-
validationMessages: string[];
|
|
22
|
-
}
|
|
23
|
-
export interface ResolvedQtiStylesheetRef extends QtiStylesheetRef {
|
|
24
|
-
/** Package-relative path resolved against the item or stimulus XML path. */
|
|
25
|
-
resolvedHref: string;
|
|
26
|
-
/** Source scope for precedence and diagnostics. */
|
|
27
|
-
source: 'item' | 'stimulus';
|
|
28
|
-
stimulusIdentifier?: string;
|
|
29
|
-
/** Sanitized stylesheet text when the package stylesheet was readable and safe. */
|
|
30
|
-
cssText?: string;
|
|
31
|
-
}
|
|
32
|
-
export interface ResolvedQtiCatalogSource {
|
|
33
|
-
scope: 'item' | 'stimulus';
|
|
34
|
-
xml: string;
|
|
35
|
-
baseHref: string;
|
|
36
|
-
stimulusIdentifier?: string;
|
|
37
|
-
}
|
|
38
|
-
export interface ResolvedAssessmentStimulus {
|
|
39
|
-
identifier: string;
|
|
40
|
-
href: string;
|
|
41
|
-
resolvedHref: string;
|
|
42
|
-
title?: string;
|
|
43
|
-
lang?: string;
|
|
44
|
-
bodyHtml: string;
|
|
45
|
-
stylesheets: ResolvedQtiStylesheetRef[];
|
|
46
|
-
catalogSource?: ResolvedQtiCatalogSource;
|
|
47
|
-
validationMessages: string[];
|
|
48
|
-
}
|
|
49
|
-
export interface ResolvedItemDeliveryContext {
|
|
50
|
-
itemHref?: string;
|
|
51
|
-
stimuli: Record<string, ResolvedAssessmentStimulus>;
|
|
52
|
-
stylesheets: ResolvedQtiStylesheetRef[];
|
|
53
|
-
catalogSources: ResolvedQtiCatalogSource[];
|
|
54
|
-
validationMessages: string[];
|
|
55
|
-
}
|
|
56
|
-
export interface ResolveItemDeliveryContextOptions {
|
|
57
|
-
itemXml: string;
|
|
58
|
-
itemHref?: string;
|
|
59
|
-
/**
|
|
60
|
-
* Read a package-relative text file. The utility stays package-agnostic by
|
|
61
|
-
* depending on this callback rather than traversing IMS package structures.
|
|
62
|
-
*/
|
|
63
|
-
readText: (path: string) => string | null | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* Optional package-relative asset URL resolver. When provided, simple HTML
|
|
66
|
-
* media references in stimulus bodies are rewritten before rendering.
|
|
67
|
-
*/
|
|
68
|
-
resolveAssetUrl?: (path: string) => string | null | undefined;
|
|
69
|
-
/** Optional package file index used for explicit, diagnosable lenient resolution. */
|
|
70
|
-
fileIndex?: PackageFileIndex;
|
|
71
|
-
/** Manifest-backed source XML candidates for suffix resolution. */
|
|
72
|
-
manifestEvidencePaths?: ReadonlySet<string>;
|
|
73
|
-
/** Controls optional real-world package path heuristics. */
|
|
74
|
-
heuristicsConfig?: QtiHeuristicsConfig;
|
|
75
|
-
}
|
|
76
|
-
export declare function extractAssessmentStimulusRefs(itemXml: string): AssessmentStimulusRef[];
|
|
77
|
-
export declare function parseAssessmentStimulusXml(stimulusXml: string): AssessmentStimulusDocument;
|
|
78
|
-
export declare function extractStimulusBodyHtml(stimulusXml: string): string;
|
|
79
|
-
export declare function createResolvedItemDeliveryContext(options: ResolveItemDeliveryContextOptions): ResolvedItemDeliveryContext;
|
|
80
|
-
export declare function extractQtiStylesheets(xml: string): QtiStylesheetRef[];
|
|
81
|
-
export declare function extractCatalogInfoXml(xml: string): string[];
|
|
82
|
-
export declare function resolveRelativePath(baseHref: string, relativePath: string): string;
|