@pie-qti/ims-cp-core 0.1.28 → 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 (37) hide show
  1. package/package.json +2 -2
  2. package/dist/index.d.ts +0 -14
  3. package/dist/index.js +0 -15
  4. package/dist/index.js.map +0 -1
  5. package/dist/localized-resources.d.ts +0 -308
  6. package/dist/localized-resources.js +0 -410
  7. package/dist/localized-resources.js.map +0 -1
  8. package/dist/manifest-parser.d.ts +0 -82
  9. package/dist/manifest-parser.js +0 -213
  10. package/dist/manifest-parser.js.map +0 -1
  11. package/dist/package-file-resolver.d.ts +0 -48
  12. package/dist/package-file-resolver.js +0 -312
  13. package/dist/package-file-resolver.js.map +0 -1
  14. package/dist/package-graph.d.ts +0 -134
  15. package/dist/package-graph.js +0 -791
  16. package/dist/package-graph.js.map +0 -1
  17. package/dist/package-path.d.ts +0 -11
  18. package/dist/package-path.js +0 -89
  19. package/dist/package-path.js.map +0 -1
  20. package/dist/passage-reusability.d.ts +0 -99
  21. package/dist/passage-reusability.js +0 -170
  22. package/dist/passage-reusability.js.map +0 -1
  23. package/dist/qti-heuristics.d.ts +0 -119
  24. package/dist/qti-heuristics.js +0 -150
  25. package/dist/qti-heuristics.js.map +0 -1
  26. package/dist/qti3-shared-content.d.ts +0 -82
  27. package/dist/qti3-shared-content.js +0 -383
  28. package/dist/qti3-shared-content.js.map +0 -1
  29. package/dist/security-parsing.d.ts +0 -9
  30. package/dist/security-parsing.js +0 -74
  31. package/dist/security-parsing.js.map +0 -1
  32. package/dist/utils/hash.d.ts +0 -20
  33. package/dist/utils/hash.js +0 -33
  34. package/dist/utils/hash.js.map +0 -1
  35. package/dist/utils/qti-xml.d.ts +0 -103
  36. package/dist/utils/qti-xml.js +0 -214
  37. package/dist/utils/qti-xml.js.map +0 -1
@@ -1,410 +0,0 @@
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
- /**
34
- * Locale identifier pattern - supports dot, dash, or underscore separators
35
- * Matches patterns like:
36
- * - "item.en-US"
37
- * - "item-en-US"
38
- * - "item_en_US"
39
- * - "item.en"
40
- */
41
- const LOCALE_PATTERN = /[._-]([a-z]{2}(?:[_-][A-Z]{2})?)$/;
42
- /**
43
- * Extract locale code from a resource identifier.
44
- *
45
- * Supports multiple separator styles:
46
- * - Dot: "item.en-US"
47
- * - Dash: "item-en-US"
48
- * - Underscore: "item_en_US"
49
- *
50
- * @param identifier Resource identifier (e.g., "simple-choice.en-US")
51
- * @returns Locale code if found, undefined otherwise
52
- *
53
- * @example
54
- * extractLocaleFromIdentifier("simple-choice.en-US") // "en-US"
55
- * extractLocaleFromIdentifier("simple-choice-es-ES") // "es-ES"
56
- * extractLocaleFromIdentifier("simple-choice_fr_FR") // "fr-FR"
57
- * extractLocaleFromIdentifier("simple-choice") // undefined
58
- */
59
- export function extractLocaleFromIdentifier(identifier) {
60
- const match = identifier.match(LOCALE_PATTERN);
61
- if (!match)
62
- return undefined;
63
- // Normalize underscore separators to hyphens (en_US -> en-US)
64
- return match[1].replace('_', '-');
65
- }
66
- /**
67
- * Extract base identifier by removing locale suffix.
68
- *
69
- * @param identifier Resource identifier
70
- * @returns Base identifier without locale suffix
71
- *
72
- * @example
73
- * extractBaseIdentifier("simple-choice.en-US") // "simple-choice"
74
- * extractBaseIdentifier("simple-choice") // "simple-choice"
75
- */
76
- export function extractBaseIdentifier(identifier) {
77
- const match = identifier.match(LOCALE_PATTERN);
78
- if (!match)
79
- return identifier;
80
- return identifier.slice(0, match.index);
81
- }
82
- /**
83
- * Extract language code from IMS LOM metadata.
84
- *
85
- * Looks for language information in the metadata object, typically
86
- * from <imsmd:language> elements in the manifest.
87
- *
88
- * @param metadata Resource metadata object
89
- * @returns Locale code if found, undefined otherwise
90
- *
91
- * @example
92
- * extractLanguageFromMetadata({ language: "en-US" }) // "en-US"
93
- * extractLanguageFromMetadata({ title: "Test" }) // undefined
94
- */
95
- export function extractLanguageFromMetadata(metadata) {
96
- return metadata?.language;
97
- }
98
- /**
99
- * Determine the locale for a resource using multiple detection methods.
100
- *
101
- * This is the core function that enables the generic locale system to work with both
102
- * localized and non-localized packages. Resources without locale information are
103
- * simply assigned the default locale - no special handling needed.
104
- *
105
- * Priority order:
106
- * 1. Identifier suffix (e.g., "item.en-US") - most explicit
107
- * 2. IMS LOM language metadata - explicit metadata
108
- * 3. Default locale - implicit for non-localized content
109
- *
110
- * @param resource Manifest resource
111
- * @param defaultLocale Default locale to use as fallback
112
- * @returns Detected locale code
113
- *
114
- * @example
115
- * determineResourceLocale({ identifier: "item.es-ES", ... }, "en-US") // "es-ES"
116
- * determineResourceLocale({ identifier: "item", metadata: { language: "fr" } }, "en-US") // "fr"
117
- * determineResourceLocale({ identifier: "item" }, "en-US") // "en-US" (non-localized → default)
118
- */
119
- export function determineResourceLocale(resource, defaultLocale) {
120
- // Try identifier first (most explicit)
121
- const fromId = extractLocaleFromIdentifier(resource.identifier);
122
- if (fromId)
123
- return fromId;
124
- // Try metadata
125
- const fromMetadata = extractLanguageFromMetadata(resource.metadata);
126
- if (fromMetadata)
127
- return fromMetadata;
128
- // Fall back to default
129
- return defaultLocale;
130
- }
131
- /**
132
- * Generate locale fallback chain for resource selection.
133
- *
134
- * Creates a prioritized list of locales to try when selecting a resource variant.
135
- *
136
- * Fallback logic:
137
- * 1. Exact match (es-ES)
138
- * 2. Language-only (es)
139
- * 3. Default locale (en-US)
140
- * 4. Default language-only (en)
141
- *
142
- * @param requestedLocale User's requested locale
143
- * @param defaultLocale Default/fallback locale
144
- * @returns Array of locale codes in priority order
145
- *
146
- * @example
147
- * getLocaleFallbackChain("es-MX", "en-US")
148
- * // ["es-MX", "es", "en-US", "en"]
149
- *
150
- * getLocaleFallbackChain("fr-CA", "en-US")
151
- * // ["fr-CA", "fr", "en-US", "en"]
152
- */
153
- export function getLocaleFallbackChain(requestedLocale, defaultLocale) {
154
- const chain = [];
155
- // 1. Exact requested locale
156
- chain.push(requestedLocale);
157
- // 2. Language-only from requested locale (es-ES -> es)
158
- const requestedLang = requestedLocale.split(/[-_]/)[0];
159
- if (requestedLang !== requestedLocale) {
160
- chain.push(requestedLang);
161
- }
162
- // 3. Default locale (if different from requested)
163
- if (defaultLocale !== requestedLocale) {
164
- chain.push(defaultLocale);
165
- }
166
- // 4. Language-only from default locale (en-US -> en)
167
- const defaultLang = defaultLocale.split(/[-_]/)[0];
168
- if (defaultLang !== defaultLocale && defaultLang !== requestedLang) {
169
- chain.push(defaultLang);
170
- }
171
- return chain;
172
- }
173
- /**
174
- * Select the best matching resource variant from a group.
175
- *
176
- * Uses fallback chain to find the most appropriate variant:
177
- * 1. Try exact locale match
178
- * 2. Try language-only match
179
- * 3. Try default locale
180
- * 4. Use first available variant
181
- *
182
- * @param group Resource group with multiple locale variants
183
- * @param requestedLocale User's requested locale
184
- * @param defaultLocale Default/fallback locale
185
- * @returns Best matching resource, or undefined if group is empty
186
- *
187
- * @example
188
- * const group = {
189
- * baseId: "simple-choice",
190
- * availableLocales: ["en-US", "es-ES"],
191
- * variants: new Map([
192
- * ["en-US", enResource],
193
- * ["es-ES", esResource]
194
- * ]),
195
- * defaultLocale: "en-US"
196
- * };
197
- *
198
- * selectLocalizedResource(group, "es-MX", "en-US") // esResource (fallback es-ES -> es)
199
- * selectLocalizedResource(group, "fr-FR", "en-US") // enResource (fallback to default)
200
- */
201
- export function selectLocalizedResource(group, requestedLocale, defaultLocale) {
202
- if (group.variants.size === 0)
203
- return undefined;
204
- const fallbackChain = getLocaleFallbackChain(requestedLocale, defaultLocale);
205
- // Try each locale in fallback chain
206
- for (const locale of fallbackChain) {
207
- const resource = group.variants.get(locale);
208
- if (resource)
209
- return resource;
210
- }
211
- // Last resort: return first available variant
212
- return group.variants.values().next().value;
213
- }
214
- /**
215
- * Group resources by base identifier and locale.
216
- *
217
- * Takes a flat array of resources and organizes them into groups where
218
- * each group contains all locale variants of the same base content.
219
- *
220
- * @param resources Array of manifest resources
221
- * @param defaultLocale Default locale to assign to resources without locale info
222
- * @returns Map of base identifier to resource group
223
- *
224
- * @example
225
- * const resources = [
226
- * { identifier: "item.en-US", ... },
227
- * { identifier: "item.es-ES", ... },
228
- * { identifier: "other.en-US", ... }
229
- * ];
230
- *
231
- * const groups = groupResourcesByLocale(resources, "en-US");
232
- * // Map {
233
- * // "item" => { baseId: "item", availableLocales: ["en-US", "es-ES"], ... },
234
- * // "other" => { baseId: "other", availableLocales: ["en-US"], ... }
235
- * // }
236
- */
237
- export function groupResourcesByLocale(resources, defaultLocale) {
238
- const groups = new Map();
239
- for (const resource of resources) {
240
- const locale = determineResourceLocale(resource, defaultLocale);
241
- const baseId = extractBaseIdentifier(resource.identifier);
242
- const localizedResource = {
243
- ...resource,
244
- baseId,
245
- locale,
246
- };
247
- let group = groups.get(baseId);
248
- if (!group) {
249
- group = {
250
- baseId,
251
- availableLocales: [],
252
- variants: new Map(),
253
- defaultLocale,
254
- };
255
- groups.set(baseId, group);
256
- }
257
- group.variants.set(locale, localizedResource);
258
- if (!group.availableLocales.includes(locale)) {
259
- group.availableLocales.push(locale);
260
- }
261
- }
262
- return groups;
263
- }
264
- /**
265
- * Build a localized manifest structure from a parsed manifest.
266
- *
267
- * Organizes all resources (items, passages, tests) by base identifier and locale,
268
- * enabling easy lookup and locale-aware resource selection.
269
- *
270
- * @param manifest Parsed manifest
271
- * @param defaultLocale Default locale for resources without locale info
272
- * @returns Localized manifest with grouped resources
273
- *
274
- * @example
275
- * const manifest = parseManifest(manifestXml);
276
- * const localized = buildLocalizedManifest(manifest, "en-US");
277
- *
278
- * console.log(localized.availableLocales); // Set { "en-US", "es-ES", "fr-FR" }
279
- * console.log(localized.itemGroups.get("simple-choice")); // Group with all locale variants
280
- */
281
- export function buildLocalizedManifest(manifest, defaultLocale = 'en-US') {
282
- const itemGroups = groupResourcesByLocale(manifest.items, defaultLocale);
283
- const passageGroups = groupResourcesByLocale(manifest.passages, defaultLocale);
284
- const testGroups = groupResourcesByLocale(manifest.tests, defaultLocale);
285
- // Collect all unique locales
286
- const availableLocales = new Set();
287
- for (const group of [
288
- ...itemGroups.values(),
289
- ...passageGroups.values(),
290
- ...testGroups.values(),
291
- ]) {
292
- for (const locale of group.availableLocales) {
293
- availableLocales.add(locale);
294
- }
295
- }
296
- return {
297
- manifest,
298
- itemGroups,
299
- passageGroups,
300
- testGroups,
301
- availableLocales,
302
- };
303
- }
304
- /**
305
- * Get a specific item resource in the requested locale.
306
- *
307
- * Uses fallback chain to find the best matching locale variant.
308
- *
309
- * @param localizedManifest Localized manifest
310
- * @param baseId Base identifier of the item
311
- * @param requestedLocale User's requested locale
312
- * @returns Localized resource, or undefined if item not found
313
- *
314
- * @example
315
- * const item = getLocalizedItem(manifest, "simple-choice", "es-MX");
316
- * // Returns Spanish variant (es-ES) if available, otherwise falls back
317
- */
318
- export function getLocalizedItem(localizedManifest, baseId, requestedLocale) {
319
- const group = localizedManifest.itemGroups.get(baseId);
320
- if (!group)
321
- return undefined;
322
- return selectLocalizedResource(group, requestedLocale, group.defaultLocale);
323
- }
324
- /**
325
- * Get a specific passage resource in the requested locale.
326
- *
327
- * @param localizedManifest Localized manifest
328
- * @param baseId Base identifier of the passage
329
- * @param requestedLocale User's requested locale
330
- * @returns Localized resource, or undefined if passage not found
331
- */
332
- export function getLocalizedPassage(localizedManifest, baseId, requestedLocale) {
333
- const group = localizedManifest.passageGroups.get(baseId);
334
- if (!group)
335
- return undefined;
336
- return selectLocalizedResource(group, requestedLocale, group.defaultLocale);
337
- }
338
- /**
339
- * Get a specific test resource in the requested locale.
340
- *
341
- * @param localizedManifest Localized manifest
342
- * @param baseId Base identifier of the test
343
- * @param requestedLocale User's requested locale
344
- * @returns Localized resource, or undefined if test not found
345
- */
346
- export function getLocalizedTest(localizedManifest, baseId, requestedLocale) {
347
- const group = localizedManifest.testGroups.get(baseId);
348
- if (!group)
349
- return undefined;
350
- return selectLocalizedResource(group, requestedLocale, group.defaultLocale);
351
- }
352
- /**
353
- * Get all items available in the requested locale.
354
- *
355
- * Returns all items, using fallback chain to select the best variant
356
- * for each item when exact locale match is not available.
357
- *
358
- * @param localizedManifest Localized manifest
359
- * @param requestedLocale User's requested locale
360
- * @returns Array of localized resources
361
- *
362
- * @example
363
- * const items = getAllItemsForLocale(manifest, "es-ES");
364
- * // Returns Spanish variants where available, falls back to default for others
365
- */
366
- export function getAllItemsForLocale(localizedManifest, requestedLocale) {
367
- const items = [];
368
- for (const group of localizedManifest.itemGroups.values()) {
369
- const resource = selectLocalizedResource(group, requestedLocale, group.defaultLocale);
370
- if (resource) {
371
- items.push(resource);
372
- }
373
- }
374
- return items;
375
- }
376
- /**
377
- * Get all passages available in the requested locale.
378
- *
379
- * @param localizedManifest Localized manifest
380
- * @param requestedLocale User's requested locale
381
- * @returns Array of localized resources
382
- */
383
- export function getAllPassagesForLocale(localizedManifest, requestedLocale) {
384
- const passages = [];
385
- for (const group of localizedManifest.passageGroups.values()) {
386
- const resource = selectLocalizedResource(group, requestedLocale, group.defaultLocale);
387
- if (resource) {
388
- passages.push(resource);
389
- }
390
- }
391
- return passages;
392
- }
393
- /**
394
- * Get all tests available in the requested locale.
395
- *
396
- * @param localizedManifest Localized manifest
397
- * @param requestedLocale User's requested locale
398
- * @returns Array of localized resources
399
- */
400
- export function getAllTestsForLocale(localizedManifest, requestedLocale) {
401
- const tests = [];
402
- for (const group of localizedManifest.testGroups.values()) {
403
- const resource = selectLocalizedResource(group, requestedLocale, group.defaultLocale);
404
- if (resource) {
405
- tests.push(resource);
406
- }
407
- }
408
- return tests;
409
- }
410
- //# sourceMappingURL=localized-resources.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"localized-resources.js","sourceRoot":"","sources":["../src/localized-resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AA0DH;;;;;;;GAOG;AACH,MAAM,cAAc,GAAG,mCAAmC,CAAC;AAE3D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,2BAA2B,CAAC,UAAkB;IAC5D,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAE7B,8DAA8D;IAC9D,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAAC,UAAkB;IACtD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO,UAAU,CAAC;IAC9B,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,2BAA2B,CACzC,QAAoD;IAEpD,OAAO,QAA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;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,iBAAoC,EACpC,eAA2B;IAE3B,MAAM,QAAQ,GAAwB,EAAE,CAAC;IAEzC,KAAK,MAAM,KAAK,IAAI,iBAAiB,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;QAC7D,MAAM,QAAQ,GAAG,uBAAuB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;QACtF,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,iBAAoC,EACpC,eAA2B;IAE3B,MAAM,KAAK,GAAwB,EAAE,CAAC;IAEtC,KAAK,MAAM,KAAK,IAAI,iBAAiB,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;QAC1D,MAAM,QAAQ,GAAG,uBAAuB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;QACtF,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Localized Resource Utilities for IMS Content Packages\n *\n * Provides generic locale-aware utilities for QTI content packages. Resources can optionally\n * use locale-suffixed identifiers (e.g., \"item.en-US\", \"item.es-ES\") and IMS LOM language\n * metadata for multilingual support.\n *\n * **Works with both single-locale and multilingual packages:**\n * - Non-localized packages: Resources without locale suffixes are treated as the default locale\n * - Multilingual packages: Resources with locale suffixes enable per-locale selection\n *\n * **Generic fallback system:**\n * When requesting a locale variant, the system tries:\n * 1. Exact match (es-ES)\n * 2. Language-only match (es)\n * 3. Default locale (typically en-US)\n * 4. First available variant\n *\n * This means requesting \"es-ES\" from a non-localized English package will gracefully\n * fall back to the English content - no special handling needed.\n *\n * @example\n * ```typescript\n * // Works with any manifest (single or multilingual)\n * const manifest = parseManifest(xml);\n * const localized = buildLocalizedManifest(manifest, 'en-US');\n *\n * // Get item with automatic fallback\n * const item = getLocalizedItem(localized, 'simple-choice', 'es-ES');\n * // → Returns Spanish variant if available, otherwise falls back to English\n * ```\n */\n\nimport type { ManifestResource, ParsedManifest } from './manifest-parser.js';\n\n/**\n * Base identifier without locale suffix\n * @example \"simple-choice\", \"math-problem-1\"\n */\nexport type BaseIdentifier = string;\n\n/**\n * Locale code (BCP 47 format)\n * @example \"en-US\", \"es-ES\", \"fr-FR\", \"en\", \"es\"\n */\nexport type LocaleCode = string;\n\n/**\n * A manifest resource with parsed locale information\n */\nexport interface LocalizedResource extends ManifestResource {\n /** Base identifier without locale suffix */\n baseId: BaseIdentifier;\n /** Locale code extracted from identifier or metadata */\n locale: LocaleCode;\n /** Original full identifier from manifest */\n identifier: string;\n}\n\n/**\n * A group of resource variants for the same base content in different locales\n */\nexport interface LocalizedResourceGroup {\n /** Base identifier shared by all variants */\n baseId: BaseIdentifier;\n /** All available locales for this resource */\n availableLocales: LocaleCode[];\n /** Map of locale to resource variant */\n variants: Map<LocaleCode, LocalizedResource>;\n /** Default/fallback locale for this group */\n defaultLocale: LocaleCode;\n}\n\n/**\n * A manifest with resources organized by base identifier and locale\n */\nexport interface LocalizedManifest {\n /** Original parsed manifest */\n manifest: ParsedManifest;\n /** Item resources grouped by base ID */\n itemGroups: Map<BaseIdentifier, LocalizedResourceGroup>;\n /** Passage resources grouped by base ID */\n passageGroups: Map<BaseIdentifier, LocalizedResourceGroup>;\n /** Test/assessment resources grouped by base ID */\n testGroups: Map<BaseIdentifier, LocalizedResourceGroup>;\n /** All locales available across all resources */\n availableLocales: Set<LocaleCode>;\n}\n\n/**\n * Locale identifier pattern - supports dot, dash, or underscore separators\n * Matches patterns like:\n * - \"item.en-US\"\n * - \"item-en-US\"\n * - \"item_en_US\"\n * - \"item.en\"\n */\nconst LOCALE_PATTERN = /[._-]([a-z]{2}(?:[_-][A-Z]{2})?)$/;\n\n/**\n * Extract locale code from a resource identifier.\n *\n * Supports multiple separator styles:\n * - Dot: \"item.en-US\"\n * - Dash: \"item-en-US\"\n * - Underscore: \"item_en_US\"\n *\n * @param identifier Resource identifier (e.g., \"simple-choice.en-US\")\n * @returns Locale code if found, undefined otherwise\n *\n * @example\n * extractLocaleFromIdentifier(\"simple-choice.en-US\") // \"en-US\"\n * extractLocaleFromIdentifier(\"simple-choice-es-ES\") // \"es-ES\"\n * extractLocaleFromIdentifier(\"simple-choice_fr_FR\") // \"fr-FR\"\n * extractLocaleFromIdentifier(\"simple-choice\") // undefined\n */\nexport function extractLocaleFromIdentifier(identifier: string): LocaleCode | undefined {\n const match = identifier.match(LOCALE_PATTERN);\n if (!match) return undefined;\n\n // Normalize underscore separators to hyphens (en_US -> en-US)\n return match[1].replace('_', '-');\n}\n\n/**\n * Extract base identifier by removing locale suffix.\n *\n * @param identifier Resource identifier\n * @returns Base identifier without locale suffix\n *\n * @example\n * extractBaseIdentifier(\"simple-choice.en-US\") // \"simple-choice\"\n * extractBaseIdentifier(\"simple-choice\") // \"simple-choice\"\n */\nexport function extractBaseIdentifier(identifier: string): BaseIdentifier {\n const match = identifier.match(LOCALE_PATTERN);\n if (!match) return identifier;\n return identifier.slice(0, match.index);\n}\n\n/**\n * Extract language code from IMS LOM metadata.\n *\n * Looks for language information in the metadata object, typically\n * from <imsmd:language> elements in the manifest.\n *\n * @param metadata Resource metadata object\n * @returns Locale code if found, undefined otherwise\n *\n * @example\n * extractLanguageFromMetadata({ language: \"en-US\" }) // \"en-US\"\n * extractLanguageFromMetadata({ title: \"Test\" }) // undefined\n */\nexport function extractLanguageFromMetadata(\n metadata?: { language?: string; [key: string]: any }\n): LocaleCode | undefined {\n return metadata?.language;\n}\n\n/**\n * Determine the locale for a resource using multiple detection methods.\n *\n * This is the core function that enables the generic locale system to work with both\n * localized and non-localized packages. Resources without locale information are\n * simply assigned the default locale - no special handling needed.\n *\n * Priority order:\n * 1. Identifier suffix (e.g., \"item.en-US\") - most explicit\n * 2. IMS LOM language metadata - explicit metadata\n * 3. Default locale - implicit for non-localized content\n *\n * @param resource Manifest resource\n * @param defaultLocale Default locale to use as fallback\n * @returns Detected locale code\n *\n * @example\n * determineResourceLocale({ identifier: \"item.es-ES\", ... }, \"en-US\") // \"es-ES\"\n * determineResourceLocale({ identifier: \"item\", metadata: { language: \"fr\" } }, \"en-US\") // \"fr\"\n * determineResourceLocale({ identifier: \"item\" }, \"en-US\") // \"en-US\" (non-localized → default)\n */\nexport function determineResourceLocale(\n resource: ManifestResource,\n defaultLocale: LocaleCode\n): LocaleCode {\n // Try identifier first (most explicit)\n const fromId = extractLocaleFromIdentifier(resource.identifier);\n if (fromId) return fromId;\n\n // Try metadata\n const fromMetadata = extractLanguageFromMetadata(resource.metadata);\n if (fromMetadata) return fromMetadata;\n\n // Fall back to default\n return defaultLocale;\n}\n\n/**\n * Generate locale fallback chain for resource selection.\n *\n * Creates a prioritized list of locales to try when selecting a resource variant.\n *\n * Fallback logic:\n * 1. Exact match (es-ES)\n * 2. Language-only (es)\n * 3. Default locale (en-US)\n * 4. Default language-only (en)\n *\n * @param requestedLocale User's requested locale\n * @param defaultLocale Default/fallback locale\n * @returns Array of locale codes in priority order\n *\n * @example\n * getLocaleFallbackChain(\"es-MX\", \"en-US\")\n * // [\"es-MX\", \"es\", \"en-US\", \"en\"]\n *\n * getLocaleFallbackChain(\"fr-CA\", \"en-US\")\n * // [\"fr-CA\", \"fr\", \"en-US\", \"en\"]\n */\nexport function getLocaleFallbackChain(\n requestedLocale: LocaleCode,\n defaultLocale: LocaleCode\n): LocaleCode[] {\n const chain: LocaleCode[] = [];\n\n // 1. Exact requested locale\n chain.push(requestedLocale);\n\n // 2. Language-only from requested locale (es-ES -> es)\n const requestedLang = requestedLocale.split(/[-_]/)[0];\n if (requestedLang !== requestedLocale) {\n chain.push(requestedLang);\n }\n\n // 3. Default locale (if different from requested)\n if (defaultLocale !== requestedLocale) {\n chain.push(defaultLocale);\n }\n\n // 4. Language-only from default locale (en-US -> en)\n const defaultLang = defaultLocale.split(/[-_]/)[0];\n if (defaultLang !== defaultLocale && defaultLang !== requestedLang) {\n chain.push(defaultLang);\n }\n\n return chain;\n}\n\n/**\n * Select the best matching resource variant from a group.\n *\n * Uses fallback chain to find the most appropriate variant:\n * 1. Try exact locale match\n * 2. Try language-only match\n * 3. Try default locale\n * 4. Use first available variant\n *\n * @param group Resource group with multiple locale variants\n * @param requestedLocale User's requested locale\n * @param defaultLocale Default/fallback locale\n * @returns Best matching resource, or undefined if group is empty\n *\n * @example\n * const group = {\n * baseId: \"simple-choice\",\n * availableLocales: [\"en-US\", \"es-ES\"],\n * variants: new Map([\n * [\"en-US\", enResource],\n * [\"es-ES\", esResource]\n * ]),\n * defaultLocale: \"en-US\"\n * };\n *\n * selectLocalizedResource(group, \"es-MX\", \"en-US\") // esResource (fallback es-ES -> es)\n * selectLocalizedResource(group, \"fr-FR\", \"en-US\") // enResource (fallback to default)\n */\nexport function selectLocalizedResource(\n group: LocalizedResourceGroup,\n requestedLocale: LocaleCode,\n defaultLocale: LocaleCode\n): LocalizedResource | undefined {\n if (group.variants.size === 0) return undefined;\n\n const fallbackChain = getLocaleFallbackChain(requestedLocale, defaultLocale);\n\n // Try each locale in fallback chain\n for (const locale of fallbackChain) {\n const resource = group.variants.get(locale);\n if (resource) return resource;\n }\n\n // Last resort: return first available variant\n return group.variants.values().next().value;\n}\n\n/**\n * Group resources by base identifier and locale.\n *\n * Takes a flat array of resources and organizes them into groups where\n * each group contains all locale variants of the same base content.\n *\n * @param resources Array of manifest resources\n * @param defaultLocale Default locale to assign to resources without locale info\n * @returns Map of base identifier to resource group\n *\n * @example\n * const resources = [\n * { identifier: \"item.en-US\", ... },\n * { identifier: \"item.es-ES\", ... },\n * { identifier: \"other.en-US\", ... }\n * ];\n *\n * const groups = groupResourcesByLocale(resources, \"en-US\");\n * // Map {\n * // \"item\" => { baseId: \"item\", availableLocales: [\"en-US\", \"es-ES\"], ... },\n * // \"other\" => { baseId: \"other\", availableLocales: [\"en-US\"], ... }\n * // }\n */\nexport function groupResourcesByLocale(\n resources: ManifestResource[],\n defaultLocale: LocaleCode\n): Map<BaseIdentifier, LocalizedResourceGroup> {\n const groups = new Map<BaseIdentifier, LocalizedResourceGroup>();\n\n for (const resource of resources) {\n const locale = determineResourceLocale(resource, defaultLocale);\n const baseId = extractBaseIdentifier(resource.identifier);\n\n const localizedResource: LocalizedResource = {\n ...resource,\n baseId,\n locale,\n };\n\n let group = groups.get(baseId);\n if (!group) {\n group = {\n baseId,\n availableLocales: [],\n variants: new Map(),\n defaultLocale,\n };\n groups.set(baseId, group);\n }\n\n group.variants.set(locale, localizedResource);\n if (!group.availableLocales.includes(locale)) {\n group.availableLocales.push(locale);\n }\n }\n\n return groups;\n}\n\n/**\n * Build a localized manifest structure from a parsed manifest.\n *\n * Organizes all resources (items, passages, tests) by base identifier and locale,\n * enabling easy lookup and locale-aware resource selection.\n *\n * @param manifest Parsed manifest\n * @param defaultLocale Default locale for resources without locale info\n * @returns Localized manifest with grouped resources\n *\n * @example\n * const manifest = parseManifest(manifestXml);\n * const localized = buildLocalizedManifest(manifest, \"en-US\");\n *\n * console.log(localized.availableLocales); // Set { \"en-US\", \"es-ES\", \"fr-FR\" }\n * console.log(localized.itemGroups.get(\"simple-choice\")); // Group with all locale variants\n */\nexport function buildLocalizedManifest(\n manifest: ParsedManifest,\n defaultLocale: LocaleCode = 'en-US'\n): LocalizedManifest {\n const itemGroups = groupResourcesByLocale(manifest.items, defaultLocale);\n const passageGroups = groupResourcesByLocale(manifest.passages, defaultLocale);\n const testGroups = groupResourcesByLocale(manifest.tests, defaultLocale);\n\n // Collect all unique locales\n const availableLocales = new Set<LocaleCode>();\n for (const group of [\n ...itemGroups.values(),\n ...passageGroups.values(),\n ...testGroups.values(),\n ]) {\n for (const locale of group.availableLocales) {\n availableLocales.add(locale);\n }\n }\n\n return {\n manifest,\n itemGroups,\n passageGroups,\n testGroups,\n availableLocales,\n };\n}\n\n/**\n * Get a specific item resource in the requested locale.\n *\n * Uses fallback chain to find the best matching locale variant.\n *\n * @param localizedManifest Localized manifest\n * @param baseId Base identifier of the item\n * @param requestedLocale User's requested locale\n * @returns Localized resource, or undefined if item not found\n *\n * @example\n * const item = getLocalizedItem(manifest, \"simple-choice\", \"es-MX\");\n * // Returns Spanish variant (es-ES) if available, otherwise falls back\n */\nexport function getLocalizedItem(\n localizedManifest: LocalizedManifest,\n baseId: BaseIdentifier,\n requestedLocale: LocaleCode\n): LocalizedResource | undefined {\n const group = localizedManifest.itemGroups.get(baseId);\n if (!group) return undefined;\n\n return selectLocalizedResource(group, requestedLocale, group.defaultLocale);\n}\n\n/**\n * Get a specific passage resource in the requested locale.\n *\n * @param localizedManifest Localized manifest\n * @param baseId Base identifier of the passage\n * @param requestedLocale User's requested locale\n * @returns Localized resource, or undefined if passage not found\n */\nexport function getLocalizedPassage(\n localizedManifest: LocalizedManifest,\n baseId: BaseIdentifier,\n requestedLocale: LocaleCode\n): LocalizedResource | undefined {\n const group = localizedManifest.passageGroups.get(baseId);\n if (!group) return undefined;\n\n return selectLocalizedResource(group, requestedLocale, group.defaultLocale);\n}\n\n/**\n * Get a specific test resource in the requested locale.\n *\n * @param localizedManifest Localized manifest\n * @param baseId Base identifier of the test\n * @param requestedLocale User's requested locale\n * @returns Localized resource, or undefined if test not found\n */\nexport function getLocalizedTest(\n localizedManifest: LocalizedManifest,\n baseId: BaseIdentifier,\n requestedLocale: LocaleCode\n): LocalizedResource | undefined {\n const group = localizedManifest.testGroups.get(baseId);\n if (!group) return undefined;\n\n return selectLocalizedResource(group, requestedLocale, group.defaultLocale);\n}\n\n/**\n * Get all items available in the requested locale.\n *\n * Returns all items, using fallback chain to select the best variant\n * for each item when exact locale match is not available.\n *\n * @param localizedManifest Localized manifest\n * @param requestedLocale User's requested locale\n * @returns Array of localized resources\n *\n * @example\n * const items = getAllItemsForLocale(manifest, \"es-ES\");\n * // Returns Spanish variants where available, falls back to default for others\n */\nexport function getAllItemsForLocale(\n localizedManifest: LocalizedManifest,\n requestedLocale: LocaleCode\n): LocalizedResource[] {\n const items: LocalizedResource[] = [];\n\n for (const group of localizedManifest.itemGroups.values()) {\n const resource = selectLocalizedResource(group, requestedLocale, group.defaultLocale);\n if (resource) {\n items.push(resource);\n }\n }\n\n return items;\n}\n\n/**\n * Get all passages available in the requested locale.\n *\n * @param localizedManifest Localized manifest\n * @param requestedLocale User's requested locale\n * @returns Array of localized resources\n */\nexport function getAllPassagesForLocale(\n localizedManifest: LocalizedManifest,\n requestedLocale: LocaleCode\n): LocalizedResource[] {\n const passages: LocalizedResource[] = [];\n\n for (const group of localizedManifest.passageGroups.values()) {\n const resource = selectLocalizedResource(group, requestedLocale, group.defaultLocale);\n if (resource) {\n passages.push(resource);\n }\n }\n\n return passages;\n}\n\n/**\n * Get all tests available in the requested locale.\n *\n * @param localizedManifest Localized manifest\n * @param requestedLocale User's requested locale\n * @returns Array of localized resources\n */\nexport function getAllTestsForLocale(\n localizedManifest: LocalizedManifest,\n requestedLocale: LocaleCode\n): LocalizedResource[] {\n const tests: LocalizedResource[] = [];\n\n for (const group of localizedManifest.testGroups.values()) {\n const resource = selectLocalizedResource(group, requestedLocale, group.defaultLocale);\n if (resource) {\n tests.push(resource);\n }\n }\n\n return tests;\n}\n"]}
@@ -1,82 +0,0 @@
1
- /**
2
- * QTI Manifest (imsmanifest.xml) parser
3
- *
4
- * Parses IMS Content Package manifests to extract:
5
- * - Resource definitions (items, passages, assessments)
6
- * - Dependencies between resources
7
- * - File locations and types
8
- */
9
- import { PassageRegistry } from './passage-reusability.js';
10
- /**
11
- * QTI resource type
12
- */
13
- export type ResourceType = 'imsqti_item_xmlv2p1' | 'imsqti_item_xmlv2p2' | 'imsqti_test_xmlv2p1' | 'imsqti_test_xmlv2p2' | 'imsqti_assessment_xmlv2p1' | 'imsqti_apip_xmlv2p2' | 'webcontent' | 'associatedcontent/imsqti_item_xmlv2p1' | string;
14
- /**
15
- * Manifest resource entry
16
- */
17
- export interface ManifestResource {
18
- /** Resource identifier */
19
- identifier: string;
20
- /** Resource type */
21
- type: ResourceType;
22
- /**
23
- * Optional xml:base for this resource element.
24
- * Used by IMS CP to resolve relative hrefs when packages use nested bases.
25
- */
26
- xmlBase?: string;
27
- /** Main file href */
28
- href?: string;
29
- /** All files in this resource */
30
- files: string[];
31
- /** Dependencies (identifierrefs) */
32
- dependencies: string[];
33
- /** Metadata */
34
- metadata?: {
35
- title?: string;
36
- description?: string;
37
- /** IMS LOM language code (e.g., "en-US", "es-ES") */
38
- language?: string;
39
- };
40
- }
41
- /**
42
- * Parsed manifest structure
43
- */
44
- export interface ParsedManifest {
45
- /** Manifest identifier */
46
- identifier?: string;
47
- /**
48
- * Optional xml:base at the manifest element level.
49
- * Used by IMS CP to resolve relative hrefs.
50
- */
51
- xmlBase?: string;
52
- /** All resources */
53
- resources: Map<string, ManifestResource>;
54
- /** Item resources */
55
- items: ManifestResource[];
56
- /** Passage/stimulus resources */
57
- passages: ManifestResource[];
58
- /** Test/assessment resources */
59
- tests: ManifestResource[];
60
- /** Base path for resolving relative paths */
61
- basePath?: string;
62
- }
63
- /**
64
- * Parse QTI manifest XML
65
- */
66
- export declare function parseManifest(manifestXml: string, basePath?: string): ParsedManifest;
67
- /**
68
- * Build passage registry from manifest
69
- *
70
- * Analyzes manifest to identify:
71
- * - Which passages are referenced by items
72
- * - Which passages are reusable (multiple items reference them)
73
- */
74
- export declare function buildPassageRegistryFromManifest(manifest: ParsedManifest): PassageRegistry;
75
- /**
76
- * Get passage content file path from manifest
77
- */
78
- export declare function getPassageFilePath(manifest: ParsedManifest, passageId: string): string | undefined;
79
- /**
80
- * Get all items that depend on a passage
81
- */
82
- export declare function getItemsReferencingPassage(manifest: ParsedManifest, passageId: string): ManifestResource[];