@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-qti/ims-cp-core",
3
- "version": "0.1.28",
3
+ "version": "1.0.0-beta.0",
4
4
  "description": "Core IMS Content Package manifest parsing utilities (browser + Node.js)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -36,7 +36,7 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@pie-qti/logger": "0.1.28",
39
+ "@pie-qti/logger": "1.0.0-beta.0",
40
40
  "node-html-parser": "^9.0.4"
41
41
  },
42
42
  "devDependencies": {
package/dist/index.d.ts DELETED
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,15 +0,0 @@
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
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
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"]}
@@ -1,308 +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
- 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[];