@longsightgroup/qti3-core 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -11
- package/dist/adaptive-turn-materializer.d.ts +2 -0
- package/dist/adaptive-turn-materializer.d.ts.map +1 -1
- package/dist/adaptive-turn-materializer.js +25 -19
- package/dist/adaptive-turn-materializer.js.map +1 -1
- package/dist/adaptive-turn.d.ts +8 -1
- package/dist/adaptive-turn.d.ts.map +1 -1
- package/dist/adaptive-turn.js +15 -5
- package/dist/adaptive-turn.js.map +1 -1
- package/dist/assert-never.d.ts +3 -0
- package/dist/assert-never.d.ts.map +1 -0
- package/dist/assert-never.js +5 -0
- package/dist/assert-never.js.map +1 -0
- package/dist/attempt-state-constants.d.ts +6 -0
- package/dist/attempt-state-constants.d.ts.map +1 -0
- package/dist/attempt-state-constants.js +6 -0
- package/dist/attempt-state-constants.js.map +1 -0
- package/dist/attempt-state.d.ts +5 -0
- package/dist/attempt-state.d.ts.map +1 -0
- package/dist/attempt-state.js +190 -0
- package/dist/attempt-state.js.map +1 -0
- package/dist/catalog.js +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/content-text.d.ts.map +1 -1
- package/dist/content-text.js +3 -0
- package/dist/content-text.js.map +1 -1
- package/dist/custom-operators.d.ts +13 -0
- package/dist/custom-operators.d.ts.map +1 -0
- package/dist/custom-operators.js +2 -0
- package/dist/custom-operators.js.map +1 -0
- package/dist/delivery-preparation.d.ts +20 -0
- package/dist/delivery-preparation.d.ts.map +1 -0
- package/dist/delivery-preparation.js +71 -0
- package/dist/delivery-preparation.js.map +1 -0
- package/dist/delivery-redaction.d.ts +5 -0
- package/dist/delivery-redaction.d.ts.map +1 -1
- package/dist/delivery-redaction.js +27 -6
- package/dist/delivery-redaction.js.map +1 -1
- package/dist/delivery-security.js +2 -2
- package/dist/delivery-security.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/item-scoring-expectation.d.ts +4 -0
- package/dist/item-scoring-expectation.d.ts.map +1 -0
- package/dist/item-scoring-expectation.js +6 -0
- package/dist/item-scoring-expectation.js.map +1 -0
- package/dist/item-submission-materialization.d.ts +25 -0
- package/dist/item-submission-materialization.d.ts.map +1 -0
- package/dist/item-submission-materialization.js +68 -0
- package/dist/item-submission-materialization.js.map +1 -0
- package/dist/parser-custom-interactions.js +1 -1
- package/dist/parser-custom-interactions.js.map +1 -1
- package/dist/parser-declarations.d.ts.map +1 -1
- package/dist/parser-declarations.js +4 -4
- package/dist/parser-declarations.js.map +1 -1
- package/dist/parser-item-metadata.d.ts.map +1 -1
- package/dist/parser-item-metadata.js +8 -7
- package/dist/parser-item-metadata.js.map +1 -1
- package/dist/parser-processing.js +2 -2
- package/dist/parser-processing.js.map +1 -1
- package/dist/parser-values.d.ts +5 -1
- package/dist/parser-values.d.ts.map +1 -1
- package/dist/parser-values.js +33 -0
- package/dist/parser-values.js.map +1 -1
- package/dist/processing-evaluator-boolean.d.ts +8 -0
- package/dist/processing-evaluator-boolean.d.ts.map +1 -0
- package/dist/processing-evaluator-boolean.js +47 -0
- package/dist/processing-evaluator-boolean.js.map +1 -0
- package/dist/processing-evaluator-collection.d.ts +12 -0
- package/dist/processing-evaluator-collection.d.ts.map +1 -0
- package/dist/processing-evaluator-collection.js +35 -0
- package/dist/processing-evaluator-collection.js.map +1 -0
- package/dist/processing-evaluator-comparison.d.ts +8 -0
- package/dist/processing-evaluator-comparison.d.ts.map +1 -0
- package/dist/processing-evaluator-comparison.js +88 -0
- package/dist/processing-evaluator-comparison.js.map +1 -0
- package/dist/processing-evaluator-custom.d.ts +8 -0
- package/dist/processing-evaluator-custom.d.ts.map +1 -0
- package/dist/processing-evaluator-custom.js +14 -0
- package/dist/processing-evaluator-custom.js.map +1 -0
- package/dist/processing-evaluator-geometry.d.ts +8 -0
- package/dist/processing-evaluator-geometry.d.ts.map +1 -0
- package/dist/processing-evaluator-geometry.js +21 -0
- package/dist/processing-evaluator-geometry.js.map +1 -0
- package/dist/processing-evaluator-numeric.d.ts +8 -0
- package/dist/processing-evaluator-numeric.d.ts.map +1 -0
- package/dist/processing-evaluator-numeric.js +112 -0
- package/dist/processing-evaluator-numeric.js.map +1 -0
- package/dist/processing-evaluator-string.d.ts +8 -0
- package/dist/processing-evaluator-string.d.ts.map +1 -0
- package/dist/processing-evaluator-string.js +33 -0
- package/dist/processing-evaluator-string.js.map +1 -0
- package/dist/processing-evaluator-variable.d.ts +8 -0
- package/dist/processing-evaluator-variable.d.ts.map +1 -0
- package/dist/processing-evaluator-variable.js +39 -0
- package/dist/processing-evaluator-variable.js.map +1 -0
- package/dist/processing-evaluator.d.ts +22 -0
- package/dist/processing-evaluator.d.ts.map +1 -0
- package/dist/processing-evaluator.js +137 -0
- package/dist/processing-evaluator.js.map +1 -0
- package/dist/processing-expression-children.d.ts +3 -0
- package/dist/processing-expression-children.d.ts.map +1 -0
- package/dist/processing-expression-children.js +68 -0
- package/dist/processing-expression-children.js.map +1 -0
- package/dist/processing-mapping.d.ts +13 -0
- package/dist/processing-mapping.d.ts.map +1 -0
- package/dist/processing-mapping.js +120 -0
- package/dist/processing-mapping.js.map +1 -0
- package/dist/processing-operators.d.ts +11 -0
- package/dist/processing-operators.d.ts.map +1 -0
- package/dist/processing-operators.js +178 -0
- package/dist/processing-operators.js.map +1 -0
- package/dist/processing-random.d.ts +2 -0
- package/dist/processing-random.d.ts.map +1 -0
- package/dist/processing-random.js +16 -0
- package/dist/processing-random.js.map +1 -0
- package/dist/processing-state.d.ts +8 -0
- package/dist/processing-state.d.ts.map +1 -0
- package/dist/processing-state.js +44 -0
- package/dist/processing-state.js.map +1 -0
- package/dist/processing-templates.d.ts +3 -0
- package/dist/processing-templates.d.ts.map +1 -0
- package/dist/processing-templates.js +12 -0
- package/dist/processing-templates.js.map +1 -0
- package/dist/processing-values.d.ts +15 -0
- package/dist/processing-values.d.ts.map +1 -0
- package/dist/processing-values.js +150 -0
- package/dist/processing-values.js.map +1 -0
- package/dist/processing-variables.d.ts +7 -0
- package/dist/processing-variables.d.ts.map +1 -0
- package/dist/processing-variables.js +40 -0
- package/dist/processing-variables.js.map +1 -0
- package/dist/qti-package-assets.d.ts +8 -0
- package/dist/qti-package-assets.d.ts.map +1 -0
- package/dist/qti-package-assets.js +173 -0
- package/dist/qti-package-assets.js.map +1 -0
- package/dist/qti-package-items.d.ts +14 -0
- package/dist/qti-package-items.d.ts.map +1 -0
- package/dist/qti-package-items.js +138 -0
- package/dist/qti-package-items.js.map +1 -0
- package/dist/qti-package-manifest.d.ts +13 -0
- package/dist/qti-package-manifest.d.ts.map +1 -0
- package/dist/qti-package-manifest.js +109 -0
- package/dist/qti-package-manifest.js.map +1 -0
- package/dist/qti-package-metadata.d.ts +8 -0
- package/dist/qti-package-metadata.d.ts.map +1 -0
- package/dist/qti-package-metadata.js +115 -0
- package/dist/qti-package-metadata.js.map +1 -0
- package/dist/qti-package-paths.d.ts +6 -0
- package/dist/qti-package-paths.d.ts.map +1 -0
- package/dist/qti-package-paths.js +32 -0
- package/dist/qti-package-paths.js.map +1 -0
- package/dist/qti-package-types.d.ts +98 -0
- package/dist/qti-package-types.d.ts.map +1 -0
- package/dist/qti-package-types.js +2 -0
- package/dist/qti-package-types.js.map +1 -0
- package/dist/qti-package-xml.d.ts +21 -0
- package/dist/qti-package-xml.d.ts.map +1 -0
- package/dist/qti-package-xml.js +68 -0
- package/dist/qti-package-xml.js.map +1 -0
- package/dist/qti-package-zip.d.ts +24 -0
- package/dist/qti-package-zip.d.ts.map +1 -0
- package/dist/qti-package-zip.js +185 -0
- package/dist/qti-package-zip.js.map +1 -0
- package/dist/qti-package.d.ts +7 -0
- package/dist/qti-package.d.ts.map +1 -0
- package/dist/qti-package.js +76 -0
- package/dist/qti-package.js.map +1 -0
- package/dist/response-input.d.ts +9 -0
- package/dist/response-input.d.ts.map +1 -0
- package/dist/response-input.js +9 -0
- package/dist/response-input.js.map +1 -0
- package/dist/response-validation-policy.d.ts +31 -0
- package/dist/response-validation-policy.d.ts.map +1 -0
- package/dist/response-validation-policy.js +158 -0
- package/dist/response-validation-policy.js.map +1 -0
- package/dist/response-validation.d.ts +23 -0
- package/dist/response-validation.d.ts.map +1 -0
- package/dist/response-validation.js +157 -0
- package/dist/response-validation.js.map +1 -0
- package/dist/scoring-disposition-policy.d.ts +8 -0
- package/dist/scoring-disposition-policy.d.ts.map +1 -0
- package/dist/scoring-disposition-policy.js +24 -0
- package/dist/scoring-disposition-policy.js.map +1 -0
- package/dist/serializer-processing-expressions.d.ts.map +1 -1
- package/dist/serializer-processing-expressions.js +2 -8
- package/dist/serializer-processing-expressions.js.map +1 -1
- package/dist/serializer-processing-xml.js +2 -2
- package/dist/serializer-processing-xml.js.map +1 -1
- package/dist/serializer-processing.d.ts.map +1 -1
- package/dist/serializer-processing.js +3 -0
- package/dist/serializer-processing.js.map +1 -1
- package/dist/session.d.ts +5 -14
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +76 -1158
- package/dist/session.js.map +1 -1
- package/dist/shared-vocabulary-coverage-policy.js +1 -1
- package/dist/shared-vocabulary-coverage-policy.js.map +1 -1
- package/dist/shared-vocabulary-generated-families.js +1 -1
- package/dist/shared-vocabulary-generated-families.js.map +1 -1
- package/dist/shared-vocabulary-support.js +3 -3
- package/dist/shared-vocabulary-support.js.map +1 -1
- package/dist/shared-vocabulary.d.ts.map +1 -1
- package/dist/shared-vocabulary.js +4 -3
- package/dist/shared-vocabulary.js.map +1 -1
- package/dist/support-evidence.d.ts +22 -0
- package/dist/support-evidence.d.ts.map +1 -0
- package/dist/support-evidence.js +93 -0
- package/dist/support-evidence.js.map +1 -0
- package/dist/support.d.ts.map +1 -1
- package/dist/support.js +30 -43
- package/dist/support.js.map +1 -1
- package/dist/template-presentation-materializer.d.ts +14 -0
- package/dist/template-presentation-materializer.d.ts.map +1 -0
- package/dist/template-presentation-materializer.js +143 -0
- package/dist/template-presentation-materializer.js.map +1 -0
- package/dist/trusted-item-session.d.ts +25 -8
- package/dist/trusted-item-session.d.ts.map +1 -1
- package/dist/trusted-item-session.js +57 -51
- package/dist/trusted-item-session.js.map +1 -1
- package/dist/trusted-session-materialization.d.ts +33 -0
- package/dist/trusted-session-materialization.d.ts.map +1 -0
- package/dist/trusted-session-materialization.js +26 -0
- package/dist/trusted-session-materialization.js.map +1 -0
- package/dist/tts.d.ts.map +1 -1
- package/dist/tts.js +16 -2
- package/dist/tts.js.map +1 -1
- package/dist/validation-geometry.d.ts +8 -0
- package/dist/validation-geometry.d.ts.map +1 -0
- package/dist/validation-geometry.js +187 -0
- package/dist/validation-geometry.js.map +1 -0
- package/dist/validation-interactions.d.ts +3 -0
- package/dist/validation-interactions.d.ts.map +1 -0
- package/dist/validation-interactions.js +644 -0
- package/dist/validation-interactions.js.map +1 -0
- package/dist/validation-primitives.d.ts +12 -0
- package/dist/validation-primitives.d.ts.map +1 -0
- package/dist/validation-primitives.js +53 -0
- package/dist/validation-primitives.js.map +1 -0
- package/dist/validation-processing.d.ts +4 -0
- package/dist/validation-processing.d.ts.map +1 -0
- package/dist/validation-processing.js +569 -0
- package/dist/validation-processing.js.map +1 -0
- package/dist/validation-shared-vocabulary-layout.d.ts +10 -0
- package/dist/validation-shared-vocabulary-layout.d.ts.map +1 -0
- package/dist/validation-shared-vocabulary-layout.js +102 -0
- package/dist/validation-shared-vocabulary-layout.js.map +1 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +27 -1641
- package/dist/validation.js.map +1 -1
- package/dist/variable-snapshot.d.ts +9 -0
- package/dist/variable-snapshot.d.ts.map +1 -0
- package/dist/variable-snapshot.js +9 -0
- package/dist/variable-snapshot.js.map +1 -0
- package/dist/xml.js +1 -1
- package/dist/xml.js.map +1 -1
- package/package.json +1 -1
- package/src/adaptive-turn-materializer.ts +29 -16
- package/src/adaptive-turn.ts +29 -6
- package/src/assert-never.ts +4 -0
- package/src/attempt-state-constants.ts +5 -0
- package/src/attempt-state.ts +245 -0
- package/src/catalog.ts +1 -1
- package/src/content-text.ts +3 -0
- package/src/custom-operators.ts +12 -0
- package/src/delivery-preparation.ts +121 -0
- package/src/delivery-redaction.ts +37 -6
- package/src/delivery-security.ts +2 -2
- package/src/index.ts +67 -0
- package/src/item-scoring-expectation.ts +9 -0
- package/src/item-submission-materialization.ts +120 -0
- package/src/parser-custom-interactions.ts +1 -1
- package/src/parser-declarations.ts +4 -3
- package/src/parser-item-metadata.ts +8 -7
- package/src/parser-processing.ts +2 -2
- package/src/parser-values.ts +36 -0
- package/src/processing-evaluator-boolean.ts +48 -0
- package/src/processing-evaluator-collection.ts +50 -0
- package/src/processing-evaluator-comparison.ts +106 -0
- package/src/processing-evaluator-custom.ts +20 -0
- package/src/processing-evaluator-geometry.ts +26 -0
- package/src/processing-evaluator-numeric.ts +155 -0
- package/src/processing-evaluator-string.ts +60 -0
- package/src/processing-evaluator-variable.ts +81 -0
- package/src/processing-evaluator.ts +173 -0
- package/src/processing-expression-children.ts +69 -0
- package/src/processing-mapping.ts +153 -0
- package/src/processing-operators.ts +184 -0
- package/src/processing-random.ts +16 -0
- package/src/processing-state.ts +69 -0
- package/src/processing-templates.ts +12 -0
- package/src/processing-values.ts +162 -0
- package/src/processing-variables.ts +83 -0
- package/src/qti-package-assets.ts +256 -0
- package/src/qti-package-items.ts +240 -0
- package/src/qti-package-manifest.ts +210 -0
- package/src/qti-package-metadata.ts +143 -0
- package/src/qti-package-paths.ts +56 -0
- package/src/qti-package-types.ts +117 -0
- package/src/qti-package-xml.ts +97 -0
- package/src/qti-package-zip.ts +325 -0
- package/src/qti-package.ts +176 -0
- package/src/response-input.ts +19 -0
- package/src/response-validation-policy.ts +218 -0
- package/src/response-validation.ts +282 -0
- package/src/scoring-disposition-policy.ts +37 -0
- package/src/serializer-processing-expressions.ts +2 -12
- package/src/serializer-processing-xml.ts +2 -2
- package/src/serializer-processing.ts +3 -0
- package/src/session.ts +128 -2006
- package/src/shared-vocabulary-coverage-policy.ts +1 -1
- package/src/shared-vocabulary-generated-families.ts +1 -1
- package/src/shared-vocabulary-support.ts +3 -3
- package/src/shared-vocabulary.ts +3 -2
- package/src/support-evidence.ts +107 -0
- package/src/support.ts +59 -50
- package/src/template-presentation-materializer.ts +219 -0
- package/src/trusted-item-session.ts +86 -78
- package/src/trusted-session-materialization.ts +67 -0
- package/src/tts.ts +29 -15
- package/src/validation-geometry.ts +204 -0
- package/src/validation-interactions.ts +831 -0
- package/src/validation-primitives.ts +68 -0
- package/src/validation-processing.ts +785 -0
- package/src/validation-shared-vocabulary-layout.ts +117 -0
- package/src/validation.ts +44 -2077
- package/src/variable-snapshot.ts +20 -0
- package/src/xml.ts +1 -1
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { normalizePackagePath, pushPackageDiagnostic } from "./qti-package-paths.js";
|
|
2
|
+
import type { QtiDiagnostic } from "./types.js";
|
|
3
|
+
|
|
4
|
+
/** Context passed to a caller-owned raw DEFLATE inflater. */
|
|
5
|
+
export interface QtiPackageInflateContext {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly compressedSize: number;
|
|
8
|
+
readonly uncompressedSize: number;
|
|
9
|
+
readonly compressionMethod: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Optional raw DEFLATE inflater for ZIP entries compressed with method 8. */
|
|
13
|
+
export type QtiPackageInflateRaw = (
|
|
14
|
+
bytes: Uint8Array,
|
|
15
|
+
context: QtiPackageInflateContext,
|
|
16
|
+
) => Uint8Array;
|
|
17
|
+
|
|
18
|
+
/** Options for parsing a QTI ZIP package. */
|
|
19
|
+
export interface QtiPackageParseOptions {
|
|
20
|
+
readonly inflateRaw?: QtiPackageInflateRaw | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Decoded ZIP entry from a QTI package. */
|
|
24
|
+
export interface QtiPackageEntry {
|
|
25
|
+
readonly path: string;
|
|
26
|
+
readonly bytes: Uint8Array;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Read stored ZIP entries and optionally inflate raw DEFLATE entries through caller code. */
|
|
30
|
+
export function readQtiPackageZipEntries(
|
|
31
|
+
bytes: Uint8Array,
|
|
32
|
+
options: QtiPackageParseOptions,
|
|
33
|
+
diagnostics: QtiDiagnostic[],
|
|
34
|
+
): QtiPackageEntry[] {
|
|
35
|
+
try {
|
|
36
|
+
return readZipEntriesUnsafe(bytes, options, diagnostics);
|
|
37
|
+
} catch {
|
|
38
|
+
pushPackageDiagnostic(
|
|
39
|
+
diagnostics,
|
|
40
|
+
"package.zip.invalid",
|
|
41
|
+
"error",
|
|
42
|
+
"QTI package ZIP central directory is malformed.",
|
|
43
|
+
);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Intentionally manual: core's TS lib is ES2023-only (no DOM/Node globals).
|
|
49
|
+
// TextDecoder is available on all supported runtimes, but using it would require
|
|
50
|
+
// widening lib, ambient types, or globalThis casts in this zero-runtime-dependency package.
|
|
51
|
+
/** Decode UTF-8 package entry names and XML payloads. */
|
|
52
|
+
export function decodeUtf8(bytes: Uint8Array): string {
|
|
53
|
+
const input =
|
|
54
|
+
bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf ? bytes.subarray(3) : bytes;
|
|
55
|
+
let text = "";
|
|
56
|
+
|
|
57
|
+
for (let index = 0; index < input.length; ) {
|
|
58
|
+
const first = input[index];
|
|
59
|
+
if (first === undefined) break;
|
|
60
|
+
if (first < 0x80) {
|
|
61
|
+
text += String.fromCharCode(first);
|
|
62
|
+
index += 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const decoded = decodeUtf8CodePoint(input, index);
|
|
67
|
+
text += String.fromCodePoint(decoded.codePoint);
|
|
68
|
+
index += decoded.length;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return text;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function readZipEntriesUnsafe(
|
|
75
|
+
bytes: Uint8Array,
|
|
76
|
+
options: QtiPackageParseOptions,
|
|
77
|
+
diagnostics: QtiDiagnostic[],
|
|
78
|
+
): QtiPackageEntry[] {
|
|
79
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
80
|
+
const eocdOffset = findEndOfCentralDirectory(view);
|
|
81
|
+
if (eocdOffset < 0) {
|
|
82
|
+
pushPackageDiagnostic(
|
|
83
|
+
diagnostics,
|
|
84
|
+
"package.zip.centralDirectory.missing",
|
|
85
|
+
"error",
|
|
86
|
+
"No ZIP central directory was found.",
|
|
87
|
+
);
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const entryCount = view.getUint16(eocdOffset + 10, true);
|
|
92
|
+
let offset = view.getUint32(eocdOffset + 16, true);
|
|
93
|
+
const entries: QtiPackageEntry[] = [];
|
|
94
|
+
|
|
95
|
+
for (let index = 0; index < entryCount; index += 1) {
|
|
96
|
+
if (offset + 46 > view.byteLength) {
|
|
97
|
+
pushPackageDiagnostic(
|
|
98
|
+
diagnostics,
|
|
99
|
+
"package.zip.centralDirectory.truncated",
|
|
100
|
+
"error",
|
|
101
|
+
"ZIP central directory ended before all entries could be read.",
|
|
102
|
+
);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (view.getUint32(offset, true) !== 0x02014b50) {
|
|
107
|
+
pushPackageDiagnostic(
|
|
108
|
+
diagnostics,
|
|
109
|
+
"package.zip.centralDirectory.entry",
|
|
110
|
+
"error",
|
|
111
|
+
"ZIP central directory entry header is invalid.",
|
|
112
|
+
);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const compressionMethod = view.getUint16(offset + 10, true);
|
|
117
|
+
const compressedSize = view.getUint32(offset + 20, true);
|
|
118
|
+
const uncompressedSize = view.getUint32(offset + 24, true);
|
|
119
|
+
const nameLength = view.getUint16(offset + 28, true);
|
|
120
|
+
const extraLength = view.getUint16(offset + 30, true);
|
|
121
|
+
const commentLength = view.getUint16(offset + 32, true);
|
|
122
|
+
const localHeaderOffset = view.getUint32(offset + 42, true);
|
|
123
|
+
const nameStart = offset + 46;
|
|
124
|
+
const nameEnd = nameStart + nameLength;
|
|
125
|
+
if (nameEnd > view.byteLength) {
|
|
126
|
+
pushPackageDiagnostic(
|
|
127
|
+
diagnostics,
|
|
128
|
+
"package.zip.centralDirectory.name",
|
|
129
|
+
"error",
|
|
130
|
+
"ZIP central directory entry name is truncated.",
|
|
131
|
+
);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const rawName = bytes.slice(nameStart, nameEnd);
|
|
136
|
+
const decodedName = decodeUtf8(rawName).replaceAll("\\", "/");
|
|
137
|
+
offset += 46 + nameLength + extraLength + commentLength;
|
|
138
|
+
if (decodedName.endsWith("/")) continue;
|
|
139
|
+
|
|
140
|
+
const path = normalizePackagePath(decodedName, "ZIP entry", diagnostics);
|
|
141
|
+
if (!path) continue;
|
|
142
|
+
|
|
143
|
+
const content = zipEntryBytes(
|
|
144
|
+
bytes,
|
|
145
|
+
view,
|
|
146
|
+
{
|
|
147
|
+
path,
|
|
148
|
+
compressedSize,
|
|
149
|
+
uncompressedSize,
|
|
150
|
+
compressionMethod,
|
|
151
|
+
localHeaderOffset,
|
|
152
|
+
},
|
|
153
|
+
options,
|
|
154
|
+
diagnostics,
|
|
155
|
+
);
|
|
156
|
+
if (content) entries.push({ path, bytes: content });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return entries;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function zipEntryBytes(
|
|
163
|
+
bytes: Uint8Array,
|
|
164
|
+
view: DataView,
|
|
165
|
+
entry: {
|
|
166
|
+
readonly path: string;
|
|
167
|
+
readonly compressedSize: number;
|
|
168
|
+
readonly uncompressedSize: number;
|
|
169
|
+
readonly compressionMethod: number;
|
|
170
|
+
readonly localHeaderOffset: number;
|
|
171
|
+
},
|
|
172
|
+
options: QtiPackageParseOptions,
|
|
173
|
+
diagnostics: QtiDiagnostic[],
|
|
174
|
+
): Uint8Array | undefined {
|
|
175
|
+
if (entry.localHeaderOffset + 30 > view.byteLength) {
|
|
176
|
+
pushPackageDiagnostic(
|
|
177
|
+
diagnostics,
|
|
178
|
+
"package.zip.localHeader.truncated",
|
|
179
|
+
"error",
|
|
180
|
+
`ZIP local header for ${entry.path} is truncated.`,
|
|
181
|
+
entry.path,
|
|
182
|
+
);
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (view.getUint32(entry.localHeaderOffset, true) !== 0x04034b50) {
|
|
187
|
+
pushPackageDiagnostic(
|
|
188
|
+
diagnostics,
|
|
189
|
+
"package.zip.localHeader",
|
|
190
|
+
"error",
|
|
191
|
+
`ZIP local header for ${entry.path} is invalid.`,
|
|
192
|
+
entry.path,
|
|
193
|
+
);
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const nameLength = view.getUint16(entry.localHeaderOffset + 26, true);
|
|
198
|
+
const extraLength = view.getUint16(entry.localHeaderOffset + 28, true);
|
|
199
|
+
const dataOffset = entry.localHeaderOffset + 30 + nameLength + extraLength;
|
|
200
|
+
const dataEnd = dataOffset + entry.compressedSize;
|
|
201
|
+
if (dataEnd > view.byteLength) {
|
|
202
|
+
pushPackageDiagnostic(
|
|
203
|
+
diagnostics,
|
|
204
|
+
"package.zip.entry.truncated",
|
|
205
|
+
"error",
|
|
206
|
+
`ZIP entry ${entry.path} content is truncated.`,
|
|
207
|
+
entry.path,
|
|
208
|
+
);
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const compressed = bytes.slice(dataOffset, dataEnd);
|
|
213
|
+
if (entry.compressionMethod === 0) return compressed;
|
|
214
|
+
|
|
215
|
+
if (entry.compressionMethod === 8) {
|
|
216
|
+
const inflateRaw = options.inflateRaw;
|
|
217
|
+
if (!inflateRaw) {
|
|
218
|
+
pushPackageDiagnostic(
|
|
219
|
+
diagnostics,
|
|
220
|
+
"package.zip.entry.compression.unsupported",
|
|
221
|
+
"error",
|
|
222
|
+
`ZIP entry ${entry.path} uses DEFLATE compression, but no inflateRaw option was provided.`,
|
|
223
|
+
entry.path,
|
|
224
|
+
);
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
return inflateRaw(compressed, {
|
|
230
|
+
path: entry.path,
|
|
231
|
+
compressedSize: entry.compressedSize,
|
|
232
|
+
uncompressedSize: entry.uncompressedSize,
|
|
233
|
+
compressionMethod: entry.compressionMethod,
|
|
234
|
+
});
|
|
235
|
+
} catch {
|
|
236
|
+
pushPackageDiagnostic(
|
|
237
|
+
diagnostics,
|
|
238
|
+
"package.zip.entry.inflate",
|
|
239
|
+
"error",
|
|
240
|
+
`ZIP entry ${entry.path} could not be inflated.`,
|
|
241
|
+
entry.path,
|
|
242
|
+
);
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
pushPackageDiagnostic(
|
|
248
|
+
diagnostics,
|
|
249
|
+
"package.zip.entry.compression.unsupported",
|
|
250
|
+
"error",
|
|
251
|
+
`ZIP entry ${entry.path} uses unsupported compression method ${entry.compressionMethod}.`,
|
|
252
|
+
entry.path,
|
|
253
|
+
);
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function findEndOfCentralDirectory(view: DataView): number {
|
|
258
|
+
const minimumOffset = Math.max(0, view.byteLength - 65557);
|
|
259
|
+
for (let offset = view.byteLength - 22; offset >= minimumOffset; offset -= 1) {
|
|
260
|
+
if (view.getUint32(offset, true) === 0x06054b50) return offset;
|
|
261
|
+
}
|
|
262
|
+
return -1;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function decodeUtf8CodePoint(
|
|
266
|
+
bytes: Uint8Array,
|
|
267
|
+
index: number,
|
|
268
|
+
): { readonly codePoint: number; readonly length: number } {
|
|
269
|
+
const first = bytes[index];
|
|
270
|
+
if (first === undefined) return { codePoint: 0xfffd, length: 1 };
|
|
271
|
+
|
|
272
|
+
if (first >= 0xc2 && first <= 0xdf) {
|
|
273
|
+
const second = bytes[index + 1];
|
|
274
|
+
if (isUtf8Continuation(second)) {
|
|
275
|
+
return {
|
|
276
|
+
codePoint: ((first & 0x1f) << 6) | (second & 0x3f),
|
|
277
|
+
length: 2,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (first >= 0xe0 && first <= 0xef) {
|
|
283
|
+
const second = bytes[index + 1];
|
|
284
|
+
const third = bytes[index + 2];
|
|
285
|
+
if (
|
|
286
|
+
isUtf8Continuation(second) &&
|
|
287
|
+
isUtf8Continuation(third) &&
|
|
288
|
+
!(first === 0xe0 && second < 0xa0) &&
|
|
289
|
+
!(first === 0xed && second >= 0xa0)
|
|
290
|
+
) {
|
|
291
|
+
return {
|
|
292
|
+
codePoint: ((first & 0x0f) << 12) | ((second & 0x3f) << 6) | (third & 0x3f),
|
|
293
|
+
length: 3,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (first >= 0xf0 && first <= 0xf4) {
|
|
299
|
+
const second = bytes[index + 1];
|
|
300
|
+
const third = bytes[index + 2];
|
|
301
|
+
const fourth = bytes[index + 3];
|
|
302
|
+
if (
|
|
303
|
+
isUtf8Continuation(second) &&
|
|
304
|
+
isUtf8Continuation(third) &&
|
|
305
|
+
isUtf8Continuation(fourth) &&
|
|
306
|
+
!(first === 0xf0 && second < 0x90) &&
|
|
307
|
+
!(first === 0xf4 && second >= 0x90)
|
|
308
|
+
) {
|
|
309
|
+
return {
|
|
310
|
+
codePoint:
|
|
311
|
+
((first & 0x07) << 18) |
|
|
312
|
+
((second & 0x3f) << 12) |
|
|
313
|
+
((third & 0x3f) << 6) |
|
|
314
|
+
(fourth & 0x3f),
|
|
315
|
+
length: 4,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return { codePoint: 0xfffd, length: 1 };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function isUtf8Continuation(value: number | undefined): value is number {
|
|
324
|
+
return value !== undefined && value >= 0x80 && value <= 0xbf;
|
|
325
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { pushPackageDiagnostic } from "./qti-package-paths.js";
|
|
2
|
+
import { collectPackageAssets } from "./qti-package-assets.js";
|
|
3
|
+
import {
|
|
4
|
+
detectPackageShape,
|
|
5
|
+
diagnoseManifestDependencyReferences,
|
|
6
|
+
diagnosePrimaryResourceHrefs,
|
|
7
|
+
indexManifestResources,
|
|
8
|
+
isQtiAssessmentTestResource,
|
|
9
|
+
isQtiItemResource,
|
|
10
|
+
parseManifestResources,
|
|
11
|
+
QTI_PACKAGE_MANIFEST_PATH,
|
|
12
|
+
} from "./qti-package-manifest.js";
|
|
13
|
+
import {
|
|
14
|
+
itemReferencesForPackageShape,
|
|
15
|
+
parseAssessmentTestPackageModel,
|
|
16
|
+
parsePackageItems,
|
|
17
|
+
} from "./qti-package-items.js";
|
|
18
|
+
import {
|
|
19
|
+
packageTitle,
|
|
20
|
+
parseStandardAlignments,
|
|
21
|
+
primaryTiming,
|
|
22
|
+
uniqueStandards,
|
|
23
|
+
} from "./qti-package-metadata.js";
|
|
24
|
+
import type { QtiPackageParseResult } from "./qti-package-types.js";
|
|
25
|
+
import { parseXmlFiles, pushXmlDiagnostics } from "./qti-package-xml.js";
|
|
26
|
+
import {
|
|
27
|
+
readQtiPackageZipEntries,
|
|
28
|
+
type QtiPackageEntry,
|
|
29
|
+
type QtiPackageParseOptions,
|
|
30
|
+
} from "./qti-package-zip.js";
|
|
31
|
+
import type { QtiDiagnostic } from "./types.js";
|
|
32
|
+
|
|
33
|
+
export type {
|
|
34
|
+
QtiAssessmentTestItemRef,
|
|
35
|
+
QtiAssessmentTestPackageModel,
|
|
36
|
+
QtiManifestFile,
|
|
37
|
+
QtiManifestResource,
|
|
38
|
+
QtiPackageAsset,
|
|
39
|
+
QtiPackageAssetSource,
|
|
40
|
+
QtiPackageItem,
|
|
41
|
+
QtiPackageItemSource,
|
|
42
|
+
QtiPackageParseResult,
|
|
43
|
+
QtiPackageShape,
|
|
44
|
+
QtiStandardAlignment,
|
|
45
|
+
QtiTimingMetadata,
|
|
46
|
+
} from "./qti-package-types.js";
|
|
47
|
+
|
|
48
|
+
export type {
|
|
49
|
+
QtiPackageInflateContext,
|
|
50
|
+
QtiPackageInflateRaw,
|
|
51
|
+
QtiPackageParseOptions,
|
|
52
|
+
} from "./qti-package-zip.js";
|
|
53
|
+
|
|
54
|
+
/** Parse a QTI ZIP package into a neutral manifest, item, asset, and diagnostic model. */
|
|
55
|
+
export function parseQtiPackage(
|
|
56
|
+
bytes: Uint8Array,
|
|
57
|
+
options: QtiPackageParseOptions = {},
|
|
58
|
+
): QtiPackageParseResult {
|
|
59
|
+
const diagnostics: QtiDiagnostic[] = [];
|
|
60
|
+
const entries = readQtiPackageZipEntries(bytes, options, diagnostics);
|
|
61
|
+
return parseQtiPackageEntries(entries, diagnostics);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function parseQtiPackageEntries(
|
|
65
|
+
entries: readonly QtiPackageEntry[],
|
|
66
|
+
diagnostics: QtiDiagnostic[],
|
|
67
|
+
): QtiPackageParseResult {
|
|
68
|
+
const entriesByPath = indexEntries(entries, diagnostics);
|
|
69
|
+
const xmlFilesByPath = parseXmlFiles(entriesByPath);
|
|
70
|
+
const manifestXml = xmlFilesByPath.get(QTI_PACKAGE_MANIFEST_PATH);
|
|
71
|
+
|
|
72
|
+
if (!manifestXml) {
|
|
73
|
+
pushPackageDiagnostic(
|
|
74
|
+
diagnostics,
|
|
75
|
+
"package.manifest.missing",
|
|
76
|
+
"error",
|
|
77
|
+
"QTI package does not contain imsmanifest.xml.",
|
|
78
|
+
QTI_PACKAGE_MANIFEST_PATH,
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
pushXmlDiagnostics(manifestXml, diagnostics);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const manifestRoot = manifestXml?.root?.localName === "manifest" ? manifestXml.root : undefined;
|
|
85
|
+
if (manifestXml?.root && !manifestRoot) {
|
|
86
|
+
pushPackageDiagnostic(
|
|
87
|
+
diagnostics,
|
|
88
|
+
"package.manifest.root",
|
|
89
|
+
"error",
|
|
90
|
+
`Expected imsmanifest.xml root manifest, found ${manifestXml.root.localName}.`,
|
|
91
|
+
QTI_PACKAGE_MANIFEST_PATH,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const manifestResourceRecords = manifestRoot
|
|
96
|
+
? parseManifestResources(manifestRoot, entriesByPath, diagnostics)
|
|
97
|
+
: [];
|
|
98
|
+
const manifestResources = manifestResourceRecords;
|
|
99
|
+
const resourcesByIdentifier = indexManifestResources(manifestResourceRecords, diagnostics);
|
|
100
|
+
diagnoseManifestDependencyReferences(manifestResourceRecords, resourcesByIdentifier, diagnostics);
|
|
101
|
+
|
|
102
|
+
const itemResources = manifestResourceRecords.filter((resource) =>
|
|
103
|
+
isQtiItemResource(resource.type),
|
|
104
|
+
);
|
|
105
|
+
const assessmentTestResources = manifestResourceRecords.filter((resource) =>
|
|
106
|
+
isQtiAssessmentTestResource(resource.type),
|
|
107
|
+
);
|
|
108
|
+
diagnosePrimaryResourceHrefs([...itemResources, ...assessmentTestResources], diagnostics);
|
|
109
|
+
|
|
110
|
+
const packageShape = detectPackageShape(itemResources, assessmentTestResources, diagnostics);
|
|
111
|
+
const assessmentTest = parseAssessmentTestPackageModel(
|
|
112
|
+
packageShape,
|
|
113
|
+
assessmentTestResources,
|
|
114
|
+
entriesByPath,
|
|
115
|
+
xmlFilesByPath,
|
|
116
|
+
diagnostics,
|
|
117
|
+
);
|
|
118
|
+
const itemReferences = itemReferencesForPackageShape(
|
|
119
|
+
packageShape,
|
|
120
|
+
itemResources,
|
|
121
|
+
assessmentTest,
|
|
122
|
+
diagnostics,
|
|
123
|
+
);
|
|
124
|
+
const items = parsePackageItems(itemReferences, entriesByPath, xmlFilesByPath, diagnostics);
|
|
125
|
+
const assets = collectPackageAssets(
|
|
126
|
+
resourcesByIdentifier,
|
|
127
|
+
assessmentTest,
|
|
128
|
+
items,
|
|
129
|
+
entriesByPath,
|
|
130
|
+
diagnostics,
|
|
131
|
+
);
|
|
132
|
+
const manifestStandards = manifestRoot
|
|
133
|
+
? parseStandardAlignments(manifestRoot, QTI_PACKAGE_MANIFEST_PATH)
|
|
134
|
+
: [];
|
|
135
|
+
const standards = uniqueStandards([
|
|
136
|
+
...manifestStandards,
|
|
137
|
+
...(assessmentTest?.standards ?? []),
|
|
138
|
+
...items.flatMap((item) => item.standards),
|
|
139
|
+
]);
|
|
140
|
+
const timing = primaryTiming(assessmentTest, items);
|
|
141
|
+
const title = packageTitle(manifestRoot, assessmentTest, items);
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
ok: diagnostics.every((diagnostic) => diagnostic.severity !== "error"),
|
|
145
|
+
title,
|
|
146
|
+
packageShape,
|
|
147
|
+
items,
|
|
148
|
+
assets,
|
|
149
|
+
manifestResources,
|
|
150
|
+
assessmentTest,
|
|
151
|
+
timing,
|
|
152
|
+
standards,
|
|
153
|
+
diagnostics,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function indexEntries(
|
|
158
|
+
entries: readonly QtiPackageEntry[],
|
|
159
|
+
diagnostics: QtiDiagnostic[],
|
|
160
|
+
): Map<string, QtiPackageEntry> {
|
|
161
|
+
const entriesByPath = new Map<string, QtiPackageEntry>();
|
|
162
|
+
for (const entry of entries) {
|
|
163
|
+
if (entriesByPath.has(entry.path)) {
|
|
164
|
+
pushPackageDiagnostic(
|
|
165
|
+
diagnostics,
|
|
166
|
+
"package.entry.duplicate",
|
|
167
|
+
"error",
|
|
168
|
+
`QTI package contains duplicate entry ${entry.path}.`,
|
|
169
|
+
entry.path,
|
|
170
|
+
);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
entriesByPath.set(entry.path, entry);
|
|
174
|
+
}
|
|
175
|
+
return entriesByPath;
|
|
176
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** One named response variable in record or array wire form. */
|
|
2
|
+
export interface QtiNamedResponseInput {
|
|
3
|
+
identifier: string;
|
|
4
|
+
value: unknown;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type QtiNamedResponsesInput =
|
|
8
|
+
| Record<string, unknown>
|
|
9
|
+
| readonly QtiNamedResponseInput[]
|
|
10
|
+
| undefined;
|
|
11
|
+
|
|
12
|
+
/** Normalize record or array response payloads into a stable entry list. */
|
|
13
|
+
export function listNamedResponseInputs(
|
|
14
|
+
responses: QtiNamedResponsesInput,
|
|
15
|
+
): readonly QtiNamedResponseInput[] {
|
|
16
|
+
if (!responses) return [];
|
|
17
|
+
if (Array.isArray(responses)) return responses;
|
|
18
|
+
return Object.entries(responses).map(([identifier, value]) => ({ identifier, value }));
|
|
19
|
+
}
|