@pie-qti/ims-cp-core 1.0.0-beta.0 → 1.0.0-beta.1
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/dist/index.d.ts +14 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/localized-resources.d.ts +308 -0
- package/dist/localized-resources.js +410 -0
- package/dist/localized-resources.js.map +1 -0
- package/dist/manifest-parser.d.ts +82 -0
- package/dist/manifest-parser.js +213 -0
- package/dist/manifest-parser.js.map +1 -0
- package/dist/package-file-resolver.d.ts +48 -0
- package/dist/package-file-resolver.js +312 -0
- package/dist/package-file-resolver.js.map +1 -0
- package/dist/package-graph.d.ts +134 -0
- package/dist/package-graph.js +791 -0
- package/dist/package-graph.js.map +1 -0
- package/dist/package-path.d.ts +13 -0
- package/dist/package-path.js +90 -0
- package/dist/package-path.js.map +1 -0
- package/dist/passage-reusability.d.ts +99 -0
- package/dist/passage-reusability.js +170 -0
- package/dist/passage-reusability.js.map +1 -0
- package/dist/qti-heuristics.d.ts +119 -0
- package/dist/qti-heuristics.js +150 -0
- package/dist/qti-heuristics.js.map +1 -0
- package/dist/qti3-shared-content.d.ts +114 -0
- package/dist/qti3-shared-content.js +422 -0
- package/dist/qti3-shared-content.js.map +1 -0
- package/dist/security-parsing.d.ts +9 -0
- package/dist/security-parsing.js +74 -0
- package/dist/security-parsing.js.map +1 -0
- package/dist/utils/hash.d.ts +20 -0
- package/dist/utils/hash.js +33 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/qti-xml.d.ts +103 -0
- package/dist/utils/qti-xml.js +214 -0
- package/dist/utils/qti-xml.js.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pie-qti/ims-cp-core
|
|
3
|
+
* Core IMS Content Package utilities (browser + Node.js compatible)
|
|
4
|
+
*/
|
|
5
|
+
export * from './manifest-parser.js';
|
|
6
|
+
export * from './package-path.js';
|
|
7
|
+
export * from './package-file-resolver.js';
|
|
8
|
+
export * from './package-graph.js';
|
|
9
|
+
export * from './security-parsing.js';
|
|
10
|
+
export * from './localized-resources.js';
|
|
11
|
+
export * from './passage-reusability.js';
|
|
12
|
+
export * from './qti3-shared-content.js';
|
|
13
|
+
export * from './qti-heuristics.js';
|
|
14
|
+
export * from './utils/qti-xml.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pie-qti/ims-cp-core
|
|
3
|
+
* Core IMS Content Package utilities (browser + Node.js compatible)
|
|
4
|
+
*/
|
|
5
|
+
export * from './manifest-parser.js';
|
|
6
|
+
export * from './package-path.js';
|
|
7
|
+
export * from './package-file-resolver.js';
|
|
8
|
+
export * from './package-graph.js';
|
|
9
|
+
export * from './security-parsing.js';
|
|
10
|
+
export * from './localized-resources.js';
|
|
11
|
+
export * from './passage-reusability.js';
|
|
12
|
+
export * from './qti3-shared-content.js';
|
|
13
|
+
export * from './qti-heuristics.js';
|
|
14
|
+
export * from './utils/qti-xml.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC","sourcesContent":["/**\n * @pie-qti/ims-cp-core\n * Core IMS Content Package utilities (browser + Node.js compatible)\n */\n\nexport * from './manifest-parser.js';\nexport * from './package-path.js';\nexport * from './package-file-resolver.js';\nexport * from './package-graph.js';\nexport * from './security-parsing.js';\nexport * from './localized-resources.js';\nexport * from './passage-reusability.js';\nexport * from './qti3-shared-content.js';\nexport * from './qti-heuristics.js';\nexport * from './utils/qti-xml.js';\n"]}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localized Resource Utilities for IMS Content Packages
|
|
3
|
+
*
|
|
4
|
+
* Provides generic locale-aware utilities for QTI content packages. Resources can optionally
|
|
5
|
+
* use locale-suffixed identifiers (e.g., "item.en-US", "item.es-ES") and IMS LOM language
|
|
6
|
+
* metadata for multilingual support.
|
|
7
|
+
*
|
|
8
|
+
* **Works with both single-locale and multilingual packages:**
|
|
9
|
+
* - Non-localized packages: Resources without locale suffixes are treated as the default locale
|
|
10
|
+
* - Multilingual packages: Resources with locale suffixes enable per-locale selection
|
|
11
|
+
*
|
|
12
|
+
* **Generic fallback system:**
|
|
13
|
+
* When requesting a locale variant, the system tries:
|
|
14
|
+
* 1. Exact match (es-ES)
|
|
15
|
+
* 2. Language-only match (es)
|
|
16
|
+
* 3. Default locale (typically en-US)
|
|
17
|
+
* 4. First available variant
|
|
18
|
+
*
|
|
19
|
+
* This means requesting "es-ES" from a non-localized English package will gracefully
|
|
20
|
+
* fall back to the English content - no special handling needed.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Works with any manifest (single or multilingual)
|
|
25
|
+
* const manifest = parseManifest(xml);
|
|
26
|
+
* const localized = buildLocalizedManifest(manifest, 'en-US');
|
|
27
|
+
*
|
|
28
|
+
* // Get item with automatic fallback
|
|
29
|
+
* const item = getLocalizedItem(localized, 'simple-choice', 'es-ES');
|
|
30
|
+
* // → Returns Spanish variant if available, otherwise falls back to English
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
import type { ManifestResource, ParsedManifest } from './manifest-parser.js';
|
|
34
|
+
/**
|
|
35
|
+
* Base identifier without locale suffix
|
|
36
|
+
* @example "simple-choice", "math-problem-1"
|
|
37
|
+
*/
|
|
38
|
+
export type BaseIdentifier = string;
|
|
39
|
+
/**
|
|
40
|
+
* Locale code (BCP 47 format)
|
|
41
|
+
* @example "en-US", "es-ES", "fr-FR", "en", "es"
|
|
42
|
+
*/
|
|
43
|
+
export type LocaleCode = string;
|
|
44
|
+
/**
|
|
45
|
+
* A manifest resource with parsed locale information
|
|
46
|
+
*/
|
|
47
|
+
export interface LocalizedResource extends ManifestResource {
|
|
48
|
+
/** Base identifier without locale suffix */
|
|
49
|
+
baseId: BaseIdentifier;
|
|
50
|
+
/** Locale code extracted from identifier or metadata */
|
|
51
|
+
locale: LocaleCode;
|
|
52
|
+
/** Original full identifier from manifest */
|
|
53
|
+
identifier: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A group of resource variants for the same base content in different locales
|
|
57
|
+
*/
|
|
58
|
+
export interface LocalizedResourceGroup {
|
|
59
|
+
/** Base identifier shared by all variants */
|
|
60
|
+
baseId: BaseIdentifier;
|
|
61
|
+
/** All available locales for this resource */
|
|
62
|
+
availableLocales: LocaleCode[];
|
|
63
|
+
/** Map of locale to resource variant */
|
|
64
|
+
variants: Map<LocaleCode, LocalizedResource>;
|
|
65
|
+
/** Default/fallback locale for this group */
|
|
66
|
+
defaultLocale: LocaleCode;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A manifest with resources organized by base identifier and locale
|
|
70
|
+
*/
|
|
71
|
+
export interface LocalizedManifest {
|
|
72
|
+
/** Original parsed manifest */
|
|
73
|
+
manifest: ParsedManifest;
|
|
74
|
+
/** Item resources grouped by base ID */
|
|
75
|
+
itemGroups: Map<BaseIdentifier, LocalizedResourceGroup>;
|
|
76
|
+
/** Passage resources grouped by base ID */
|
|
77
|
+
passageGroups: Map<BaseIdentifier, LocalizedResourceGroup>;
|
|
78
|
+
/** Test/assessment resources grouped by base ID */
|
|
79
|
+
testGroups: Map<BaseIdentifier, LocalizedResourceGroup>;
|
|
80
|
+
/** All locales available across all resources */
|
|
81
|
+
availableLocales: Set<LocaleCode>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Extract locale code from a resource identifier.
|
|
85
|
+
*
|
|
86
|
+
* Supports multiple separator styles:
|
|
87
|
+
* - Dot: "item.en-US"
|
|
88
|
+
* - Dash: "item-en-US"
|
|
89
|
+
* - Underscore: "item_en_US"
|
|
90
|
+
*
|
|
91
|
+
* @param identifier Resource identifier (e.g., "simple-choice.en-US")
|
|
92
|
+
* @returns Locale code if found, undefined otherwise
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* extractLocaleFromIdentifier("simple-choice.en-US") // "en-US"
|
|
96
|
+
* extractLocaleFromIdentifier("simple-choice-es-ES") // "es-ES"
|
|
97
|
+
* extractLocaleFromIdentifier("simple-choice_fr_FR") // "fr-FR"
|
|
98
|
+
* extractLocaleFromIdentifier("simple-choice") // undefined
|
|
99
|
+
*/
|
|
100
|
+
export declare function extractLocaleFromIdentifier(identifier: string): LocaleCode | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Extract base identifier by removing locale suffix.
|
|
103
|
+
*
|
|
104
|
+
* @param identifier Resource identifier
|
|
105
|
+
* @returns Base identifier without locale suffix
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* extractBaseIdentifier("simple-choice.en-US") // "simple-choice"
|
|
109
|
+
* extractBaseIdentifier("simple-choice") // "simple-choice"
|
|
110
|
+
*/
|
|
111
|
+
export declare function extractBaseIdentifier(identifier: string): BaseIdentifier;
|
|
112
|
+
/**
|
|
113
|
+
* Extract language code from IMS LOM metadata.
|
|
114
|
+
*
|
|
115
|
+
* Looks for language information in the metadata object, typically
|
|
116
|
+
* from <imsmd:language> elements in the manifest.
|
|
117
|
+
*
|
|
118
|
+
* @param metadata Resource metadata object
|
|
119
|
+
* @returns Locale code if found, undefined otherwise
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* extractLanguageFromMetadata({ language: "en-US" }) // "en-US"
|
|
123
|
+
* extractLanguageFromMetadata({ title: "Test" }) // undefined
|
|
124
|
+
*/
|
|
125
|
+
export declare function extractLanguageFromMetadata(metadata?: {
|
|
126
|
+
language?: string;
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
}): LocaleCode | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Determine the locale for a resource using multiple detection methods.
|
|
131
|
+
*
|
|
132
|
+
* This is the core function that enables the generic locale system to work with both
|
|
133
|
+
* localized and non-localized packages. Resources without locale information are
|
|
134
|
+
* simply assigned the default locale - no special handling needed.
|
|
135
|
+
*
|
|
136
|
+
* Priority order:
|
|
137
|
+
* 1. Identifier suffix (e.g., "item.en-US") - most explicit
|
|
138
|
+
* 2. IMS LOM language metadata - explicit metadata
|
|
139
|
+
* 3. Default locale - implicit for non-localized content
|
|
140
|
+
*
|
|
141
|
+
* @param resource Manifest resource
|
|
142
|
+
* @param defaultLocale Default locale to use as fallback
|
|
143
|
+
* @returns Detected locale code
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* determineResourceLocale({ identifier: "item.es-ES", ... }, "en-US") // "es-ES"
|
|
147
|
+
* determineResourceLocale({ identifier: "item", metadata: { language: "fr" } }, "en-US") // "fr"
|
|
148
|
+
* determineResourceLocale({ identifier: "item" }, "en-US") // "en-US" (non-localized → default)
|
|
149
|
+
*/
|
|
150
|
+
export declare function determineResourceLocale(resource: ManifestResource, defaultLocale: LocaleCode): LocaleCode;
|
|
151
|
+
/**
|
|
152
|
+
* Generate locale fallback chain for resource selection.
|
|
153
|
+
*
|
|
154
|
+
* Creates a prioritized list of locales to try when selecting a resource variant.
|
|
155
|
+
*
|
|
156
|
+
* Fallback logic:
|
|
157
|
+
* 1. Exact match (es-ES)
|
|
158
|
+
* 2. Language-only (es)
|
|
159
|
+
* 3. Default locale (en-US)
|
|
160
|
+
* 4. Default language-only (en)
|
|
161
|
+
*
|
|
162
|
+
* @param requestedLocale User's requested locale
|
|
163
|
+
* @param defaultLocale Default/fallback locale
|
|
164
|
+
* @returns Array of locale codes in priority order
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* getLocaleFallbackChain("es-MX", "en-US")
|
|
168
|
+
* // ["es-MX", "es", "en-US", "en"]
|
|
169
|
+
*
|
|
170
|
+
* getLocaleFallbackChain("fr-CA", "en-US")
|
|
171
|
+
* // ["fr-CA", "fr", "en-US", "en"]
|
|
172
|
+
*/
|
|
173
|
+
export declare function getLocaleFallbackChain(requestedLocale: LocaleCode, defaultLocale: LocaleCode): LocaleCode[];
|
|
174
|
+
/**
|
|
175
|
+
* Select the best matching resource variant from a group.
|
|
176
|
+
*
|
|
177
|
+
* Uses fallback chain to find the most appropriate variant:
|
|
178
|
+
* 1. Try exact locale match
|
|
179
|
+
* 2. Try language-only match
|
|
180
|
+
* 3. Try default locale
|
|
181
|
+
* 4. Use first available variant
|
|
182
|
+
*
|
|
183
|
+
* @param group Resource group with multiple locale variants
|
|
184
|
+
* @param requestedLocale User's requested locale
|
|
185
|
+
* @param defaultLocale Default/fallback locale
|
|
186
|
+
* @returns Best matching resource, or undefined if group is empty
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* const group = {
|
|
190
|
+
* baseId: "simple-choice",
|
|
191
|
+
* availableLocales: ["en-US", "es-ES"],
|
|
192
|
+
* variants: new Map([
|
|
193
|
+
* ["en-US", enResource],
|
|
194
|
+
* ["es-ES", esResource]
|
|
195
|
+
* ]),
|
|
196
|
+
* defaultLocale: "en-US"
|
|
197
|
+
* };
|
|
198
|
+
*
|
|
199
|
+
* selectLocalizedResource(group, "es-MX", "en-US") // esResource (fallback es-ES -> es)
|
|
200
|
+
* selectLocalizedResource(group, "fr-FR", "en-US") // enResource (fallback to default)
|
|
201
|
+
*/
|
|
202
|
+
export declare function selectLocalizedResource(group: LocalizedResourceGroup, requestedLocale: LocaleCode, defaultLocale: LocaleCode): LocalizedResource | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Group resources by base identifier and locale.
|
|
205
|
+
*
|
|
206
|
+
* Takes a flat array of resources and organizes them into groups where
|
|
207
|
+
* each group contains all locale variants of the same base content.
|
|
208
|
+
*
|
|
209
|
+
* @param resources Array of manifest resources
|
|
210
|
+
* @param defaultLocale Default locale to assign to resources without locale info
|
|
211
|
+
* @returns Map of base identifier to resource group
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* const resources = [
|
|
215
|
+
* { identifier: "item.en-US", ... },
|
|
216
|
+
* { identifier: "item.es-ES", ... },
|
|
217
|
+
* { identifier: "other.en-US", ... }
|
|
218
|
+
* ];
|
|
219
|
+
*
|
|
220
|
+
* const groups = groupResourcesByLocale(resources, "en-US");
|
|
221
|
+
* // Map {
|
|
222
|
+
* // "item" => { baseId: "item", availableLocales: ["en-US", "es-ES"], ... },
|
|
223
|
+
* // "other" => { baseId: "other", availableLocales: ["en-US"], ... }
|
|
224
|
+
* // }
|
|
225
|
+
*/
|
|
226
|
+
export declare function groupResourcesByLocale(resources: ManifestResource[], defaultLocale: LocaleCode): Map<BaseIdentifier, LocalizedResourceGroup>;
|
|
227
|
+
/**
|
|
228
|
+
* Build a localized manifest structure from a parsed manifest.
|
|
229
|
+
*
|
|
230
|
+
* Organizes all resources (items, passages, tests) by base identifier and locale,
|
|
231
|
+
* enabling easy lookup and locale-aware resource selection.
|
|
232
|
+
*
|
|
233
|
+
* @param manifest Parsed manifest
|
|
234
|
+
* @param defaultLocale Default locale for resources without locale info
|
|
235
|
+
* @returns Localized manifest with grouped resources
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const manifest = parseManifest(manifestXml);
|
|
239
|
+
* const localized = buildLocalizedManifest(manifest, "en-US");
|
|
240
|
+
*
|
|
241
|
+
* console.log(localized.availableLocales); // Set { "en-US", "es-ES", "fr-FR" }
|
|
242
|
+
* console.log(localized.itemGroups.get("simple-choice")); // Group with all locale variants
|
|
243
|
+
*/
|
|
244
|
+
export declare function buildLocalizedManifest(manifest: ParsedManifest, defaultLocale?: LocaleCode): LocalizedManifest;
|
|
245
|
+
/**
|
|
246
|
+
* Get a specific item resource in the requested locale.
|
|
247
|
+
*
|
|
248
|
+
* Uses fallback chain to find the best matching locale variant.
|
|
249
|
+
*
|
|
250
|
+
* @param localizedManifest Localized manifest
|
|
251
|
+
* @param baseId Base identifier of the item
|
|
252
|
+
* @param requestedLocale User's requested locale
|
|
253
|
+
* @returns Localized resource, or undefined if item not found
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* const item = getLocalizedItem(manifest, "simple-choice", "es-MX");
|
|
257
|
+
* // Returns Spanish variant (es-ES) if available, otherwise falls back
|
|
258
|
+
*/
|
|
259
|
+
export declare function getLocalizedItem(localizedManifest: LocalizedManifest, baseId: BaseIdentifier, requestedLocale: LocaleCode): LocalizedResource | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* Get a specific passage resource in the requested locale.
|
|
262
|
+
*
|
|
263
|
+
* @param localizedManifest Localized manifest
|
|
264
|
+
* @param baseId Base identifier of the passage
|
|
265
|
+
* @param requestedLocale User's requested locale
|
|
266
|
+
* @returns Localized resource, or undefined if passage not found
|
|
267
|
+
*/
|
|
268
|
+
export declare function getLocalizedPassage(localizedManifest: LocalizedManifest, baseId: BaseIdentifier, requestedLocale: LocaleCode): LocalizedResource | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* Get a specific test resource in the requested locale.
|
|
271
|
+
*
|
|
272
|
+
* @param localizedManifest Localized manifest
|
|
273
|
+
* @param baseId Base identifier of the test
|
|
274
|
+
* @param requestedLocale User's requested locale
|
|
275
|
+
* @returns Localized resource, or undefined if test not found
|
|
276
|
+
*/
|
|
277
|
+
export declare function getLocalizedTest(localizedManifest: LocalizedManifest, baseId: BaseIdentifier, requestedLocale: LocaleCode): LocalizedResource | undefined;
|
|
278
|
+
/**
|
|
279
|
+
* Get all items available in the requested locale.
|
|
280
|
+
*
|
|
281
|
+
* Returns all items, using fallback chain to select the best variant
|
|
282
|
+
* for each item when exact locale match is not available.
|
|
283
|
+
*
|
|
284
|
+
* @param localizedManifest Localized manifest
|
|
285
|
+
* @param requestedLocale User's requested locale
|
|
286
|
+
* @returns Array of localized resources
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* const items = getAllItemsForLocale(manifest, "es-ES");
|
|
290
|
+
* // Returns Spanish variants where available, falls back to default for others
|
|
291
|
+
*/
|
|
292
|
+
export declare function getAllItemsForLocale(localizedManifest: LocalizedManifest, requestedLocale: LocaleCode): LocalizedResource[];
|
|
293
|
+
/**
|
|
294
|
+
* Get all passages available in the requested locale.
|
|
295
|
+
*
|
|
296
|
+
* @param localizedManifest Localized manifest
|
|
297
|
+
* @param requestedLocale User's requested locale
|
|
298
|
+
* @returns Array of localized resources
|
|
299
|
+
*/
|
|
300
|
+
export declare function getAllPassagesForLocale(localizedManifest: LocalizedManifest, requestedLocale: LocaleCode): LocalizedResource[];
|
|
301
|
+
/**
|
|
302
|
+
* Get all tests available in the requested locale.
|
|
303
|
+
*
|
|
304
|
+
* @param localizedManifest Localized manifest
|
|
305
|
+
* @param requestedLocale User's requested locale
|
|
306
|
+
* @returns Array of localized resources
|
|
307
|
+
*/
|
|
308
|
+
export declare function getAllTestsForLocale(localizedManifest: LocalizedManifest, requestedLocale: LocaleCode): LocalizedResource[];
|