@pie-qti/ims-cp-core 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest-parser.js","sourceRoot":"","sources":["../src/manifest-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAmE3D;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,WAAmB,EAAE,QAAiB;IAClE,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,EAAE;QAC7B,gBAAgB,EAAE,KAAK;QACvB,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,GAAG,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1F,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IACvD,MAAM,eAAe,GAAG,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC;IAEvE,sBAAsB;IACtB,MAAM,gBAAgB,GAAG,QAAQ,CAAC,aAAa,CAAC,WAAW,CAAC;QACpC,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAEtE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO;YACL,UAAU,EAAE,UAAU;YACtB,SAAS,EAAE,IAAI,GAAG,EAAE;YACpB,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,EAAE;YACZ,KAAK,EAAE,EAAE;YACT,QAAQ;SACT,CAAC;I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C7C,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;YAClC,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;gBACnD,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,UAAU,EAAE;oBAC1C,EAAE,EAAE,OAAO,CAAC,UAAU,EAAG,8BAA8B;oBACvD,MAAM,EAAE,UAAU;oBAClB,aAAa,EAAE,OAAO,CAAC,UAAU;oBACjC,QAAQ,EAAE,OAAO,CAAC,IAAI;oBACtB,UAAU,EAAE,KAAK,EAAG,8BAA8B;iBACnD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAwB,EACxB,SAAiB;IAEjB,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAClD,OAAO,OAAO,EAAE,IAAI,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACxC,QAAwB,EACxB,SAAiB;IAEjB,OAAO,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAClC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,CACtC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Passage reusability detection and stable ID management
3
+ *
4
+ * QTI provides several mechanisms for reusable content:
5
+ * 1. Manifest <dependency> elements - explicit reusability declaration
6
+ * 2. Object <object data="..."> references - shared file paths
7
+ * 3. assessmentStimulus/assessmentPassage identifiers - stable IDs
8
+ *
9
+ * This module provides stable ID generation and reusability detection.
10
+ */
11
+ /**
12
+ * Generate stable ID for passage content
13
+ *
14
+ * Strategy (in priority order):
15
+ * 1. Use QTI identifier directly - QTI identifiers are designed to be globally unique
16
+ * across vendors and packages (e.g., "urn:example.com:passage:12345")
17
+ * 2. Use file path for object references - stable within a package
18
+ * 3. Use content hash for inline stimulus - ensures same content = same ID
19
+ *
20
+ * @param options Options for ID generation
21
+ * @returns Stable passage ID (async for content hashing)
22
+ */
23
+ export declare function generateStablePassageId(options: {
24
+ /** QTI identifier from assessmentStimulus or assessmentPassage - USE DIRECTLY */
25
+ qtiIdentifier?: string;
26
+ /** File path from object data attribute */
27
+ filePath?: string;
28
+ /** Content hash for inline stimulus */
29
+ content?: string;
30
+ /** Prefix for generated IDs (only used for hashed IDs) */
31
+ prefix?: string;
32
+ }): Promise<string>;
33
+ /**
34
+ * Passage reference information
35
+ */
36
+ export interface PassageReference {
37
+ /** Stable passage ID */
38
+ id: string;
39
+ /** Source of the passage */
40
+ source: 'inline' | 'file' | 'manifest' | 'qti-element';
41
+ /** Original QTI identifier if available */
42
+ qtiIdentifier?: string;
43
+ /** File path if from object reference */
44
+ filePath?: string;
45
+ /** Whether this passage is referenced by multiple items */
46
+ isReusable: boolean;
47
+ }
48
+ /**
49
+ * Track passage references across a package
50
+ * Used during batch transformation to detect reusable passages
51
+ */
52
+ export declare class PassageRegistry {
53
+ private passages;
54
+ /**
55
+ * Register a passage reference
56
+ * @param itemId ID of the item referencing this passage
57
+ * @param reference Passage reference information
58
+ */
59
+ registerReference(itemId: string, reference: PassageReference): void;
60
+ /**
61
+ * Store passage content for deduplication
62
+ * @param passageId Passage ID
63
+ * @param content Passage content
64
+ */
65
+ storeContent(passageId: string, content: string): void;
66
+ /**
67
+ * Get passage reference by ID
68
+ * @param passageId Passage ID
69
+ * @returns Passage reference with updated reusability flag
70
+ */
71
+ getReference(passageId: string): PassageReference | undefined;
72
+ /**
73
+ * Get all items that reference a passage
74
+ * @param passageId Passage ID
75
+ * @returns Set of item IDs
76
+ */
77
+ getReferencingItems(passageId: string): Set<string>;
78
+ /**
79
+ * Get all registered passages
80
+ * @returns Array of passage references
81
+ */
82
+ getAllPassages(): PassageReference[];
83
+ /**
84
+ * Get reusable passages (referenced by multiple items)
85
+ * @returns Array of reusable passage references
86
+ */
87
+ getReusablePassages(): PassageReference[];
88
+ /**
89
+ * Detect duplicate content and merge passages
90
+ * This handles cases where same content appears with different IDs
91
+ */
92
+ detectAndMergeDuplicates(): Promise<Map<string, string>>;
93
+ }
94
+ /**
95
+ * Parse object tag to extract passage reference
96
+ * @param objectElement Object element from QTI
97
+ * @returns Passage reference or null
98
+ */
99
+ export declare function parseObjectReference(objectElement: any): Promise<PassageReference | null>;
100
+ //# sourceMappingURL=passage-reusability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passage-reusability.d.ts","sourceRoot":"","sources":["../src/passage-reusability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;;;;;;;;GAWG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BlB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wBAAwB;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,4BAA4B;IAC5B,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,aAAa,CAAC;IACvD,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAIX;IAEL;;;;OAIG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,IAAI;IAgBpE;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAOtD;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAI7D;;;;OAIG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAInD;;;OAGG;IACH,cAAc,IAAI,gBAAgB,EAAE;IAIpC;;;OAGG;IACH,mBAAmB,IAAI,gBAAgB,EAAE;IAIzC;;;OAGG;IACG,wBAAwB,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CA4B/D;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,aAAa,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAuB/F"}
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Passage reusability detection and stable ID management
3
+ *
4
+ * QTI provides several mechanisms for reusable content:
5
+ * 1. Manifest <dependency> elements - explicit reusability declaration
6
+ * 2. Object <object data="..."> references - shared file paths
7
+ * 3. assessmentStimulus/assessmentPassage identifiers - stable IDs
8
+ *
9
+ * This module provides stable ID generation and reusability detection.
10
+ */
11
+ import { sha256 } from './utils/hash.js';
12
+ /**
13
+ * Generate stable ID for passage content
14
+ *
15
+ * Strategy (in priority order):
16
+ * 1. Use QTI identifier directly - QTI identifiers are designed to be globally unique
17
+ * across vendors and packages (e.g., "urn:example.com:passage:12345")
18
+ * 2. Use file path for object references - stable within a package
19
+ * 3. Use content hash for inline stimulus - ensures same content = same ID
20
+ *
21
+ * @param options Options for ID generation
22
+ * @returns Stable passage ID (async for content hashing)
23
+ */
24
+ export async function generateStablePassageId(options) {
25
+ const prefix = options.prefix || 'passage';
26
+ // Priority 1: Use QTI identifier DIRECTLY (no prefix)
27
+ // QTI identifiers are designed to be globally unique across vendors
28
+ // Examples: "urn:example.com:passage:12345", "stim-industrial-revolution"
29
+ if (options.qtiIdentifier) {
30
+ return options.qtiIdentifier;
31
+ }
32
+ // Priority 2: Use file path for object references
33
+ // Normalize path (remove leading ./ and ../) and use as-is with prefix
34
+ if (options.filePath) {
35
+ const normalizedPath = options.filePath
36
+ .replace(/^\.\//, '')
37
+ .replace(/\.\.\//g, '')
38
+ .replace(/\//g, '-')
39
+ .replace(/\.(xml|html|txt)$/, '');
40
+ return `${prefix}-${normalizedPath}`;
41
+ }
42
+ // Priority 3: Use content hash for inline stimulus (stable for same content)
43
+ if (options.content) {
44
+ const contentHash = await sha256(options.content.trim());
45
+ return `${prefix}-content-${contentHash.substring(0, 12)}`;
46
+ }
47
+ throw new Error('Must provide at least one of: qtiIdentifier, filePath, or content');
48
+ }
49
+ /**
50
+ * Track passage references across a package
51
+ * Used during batch transformation to detect reusable passages
52
+ */
53
+ export class PassageRegistry {
54
+ passages = new Map();
55
+ /**
56
+ * Register a passage reference
57
+ * @param itemId ID of the item referencing this passage
58
+ * @param reference Passage reference information
59
+ */
60
+ registerReference(itemId, reference) {
61
+ const existing = this.passages.get(reference.id);
62
+ if (existing) {
63
+ // Passage already registered, add this item as a reference
64
+ existing.referencedBy.add(itemId);
65
+ existing.reference.isReusable = existing.referencedBy.size > 1;
66
+ }
67
+ else {
68
+ // First reference to this passage
69
+ this.passages.set(reference.id, {
70
+ reference: { ...reference, isReusable: false },
71
+ referencedBy: new Set([itemId]),
72
+ });
73
+ }
74
+ }
75
+ /**
76
+ * Store passage content for deduplication
77
+ * @param passageId Passage ID
78
+ * @param content Passage content
79
+ */
80
+ storeContent(passageId, content) {
81
+ const entry = this.passages.get(passageId);
82
+ if (entry) {
83
+ entry.content = content;
84
+ }
85
+ }
86
+ /**
87
+ * Get passage reference by ID
88
+ * @param passageId Passage ID
89
+ * @returns Passage reference with updated reusability flag
90
+ */
91
+ getReference(passageId) {
92
+ return this.passages.get(passageId)?.reference;
93
+ }
94
+ /**
95
+ * Get all items that reference a passage
96
+ * @param passageId Passage ID
97
+ * @returns Set of item IDs
98
+ */
99
+ getReferencingItems(passageId) {
100
+ return this.passages.get(passageId)?.referencedBy || new Set();
101
+ }
102
+ /**
103
+ * Get all registered passages
104
+ * @returns Array of passage references
105
+ */
106
+ getAllPassages() {
107
+ return Array.from(this.passages.values()).map(entry => entry.reference);
108
+ }
109
+ /**
110
+ * Get reusable passages (referenced by multiple items)
111
+ * @returns Array of reusable passage references
112
+ */
113
+ getReusablePassages() {
114
+ return this.getAllPassages().filter(ref => ref.isReusable);
115
+ }
116
+ /**
117
+ * Detect duplicate content and merge passages
118
+ * This handles cases where same content appears with different IDs
119
+ */
120
+ async detectAndMergeDuplicates() {
121
+ const contentMap = new Map(); // content hash -> primary ID
122
+ const mergeMap = new Map(); // old ID -> new ID
123
+ for (const [id, entry] of this.passages.entries()) {
124
+ if (!entry.content)
125
+ continue;
126
+ const contentHash = await sha256(entry.content.trim());
127
+ const existingId = contentMap.get(contentHash);
128
+ if (existingId && existingId !== id) {
129
+ // Duplicate content found - merge into existing
130
+ mergeMap.set(id, existingId);
131
+ const existingEntry = this.passages.get(existingId);
132
+ for (const itemId of entry.referencedBy) {
133
+ existingEntry.referencedBy.add(itemId);
134
+ }
135
+ existingEntry.reference.isReusable = existingEntry.referencedBy.size > 1;
136
+ this.passages.delete(id);
137
+ }
138
+ else {
139
+ contentMap.set(contentHash, id);
140
+ }
141
+ }
142
+ return mergeMap;
143
+ }
144
+ }
145
+ /**
146
+ * Parse object tag to extract passage reference
147
+ * @param objectElement Object element from QTI
148
+ * @returns Passage reference or null
149
+ */
150
+ export async function parseObjectReference(objectElement) {
151
+ const dataAttr = objectElement.getAttribute?.('data');
152
+ const typeAttr = objectElement.getAttribute?.('type');
153
+ // Check if it's a passage reference (text/html, text/plain, or no type)
154
+ const isPassageType = !typeAttr ||
155
+ typeAttr === 'text/html' ||
156
+ typeAttr === 'text/plain' ||
157
+ typeAttr.startsWith('text/');
158
+ if (!dataAttr || !isPassageType) {
159
+ return null;
160
+ }
161
+ // Generate stable ID from file path
162
+ const id = await generateStablePassageId({ filePath: dataAttr });
163
+ return {
164
+ id,
165
+ source: 'file',
166
+ filePath: dataAttr,
167
+ isReusable: false, // Will be updated by registry
168
+ };
169
+ }
170
+ //# sourceMappingURL=passage-reusability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passage-reusability.js","sourceRoot":"","sources":["../src/passage-reusability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAS7C;IACC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC;IAE3C,sDAAsD;IACtD,oEAAoE;IACpE,0EAA0E;IAC1E,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC,aAAa,CAAC;IAC/B,CAAC;IAED,kDAAkD;IAClD,uEAAuE;IACvE,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ;aACpC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;aACpB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;aACtB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;aACnB,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;QACpC,OAAO,GAAG,MAAM,IAAI,cAAc,EAAE,CAAC;IACvC,CAAC;IAED,6EAA6E;IAC7E,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACzD,OAAO,GAAG,MAAM,YAAY,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,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C,CAAC;gBACD,aAAa,CAAC,SAAS,CAAC,UAAU,GAAG,aAAa,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,CAAC;gBAEzE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,aAAkB;IAC3D,MAAM,QAAQ,GAAG,aAAa,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,aAAa,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;IAEtD,wEAAwE;IACxE,MAAM,aAAa,GAAG,CAAC,QAAQ;QACT,QAAQ,KAAK,WAAW;QACxB,QAAQ,KAAK,YAAY;QACzB,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAEnD,IAAI,CAAC,QAAQ,IAAI,CAAC,aAAa,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oCAAoC;IACpC,MAAM,EAAE,GAAG,MAAM,uBAAuB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IAEjE,OAAO;QACL,EAAE;QACF,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,KAAK,EAAE,8BAA8B;KAClD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Universal SHA-256 hashing utility
3
+ * Works in both browser (Web Crypto API) and Node.js (crypto module)
4
+ */
5
+ /**
6
+ * Generate SHA-256 hash of content
7
+ *
8
+ * In browsers, uses the Web Crypto API (crypto.subtle.digest).
9
+ * In Node.js, uses the crypto module (createHash).
10
+ *
11
+ * @param content String content to hash
12
+ * @returns Hex-encoded hash string (64 characters)
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const hash = await sha256('hello world');
17
+ * console.log(hash); // "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
18
+ * ```
19
+ */
20
+ export declare function sha256(content: string): Promise<string>;
21
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa7D"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Universal SHA-256 hashing utility
3
+ * Works in both browser (Web Crypto API) and Node.js (crypto module)
4
+ */
5
+ /**
6
+ * Generate SHA-256 hash of content
7
+ *
8
+ * In browsers, uses the Web Crypto API (crypto.subtle.digest).
9
+ * In Node.js, uses the crypto module (createHash).
10
+ *
11
+ * @param content String content to hash
12
+ * @returns Hex-encoded hash string (64 characters)
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const hash = await sha256('hello world');
17
+ * console.log(hash); // "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
18
+ * ```
19
+ */
20
+ export async function sha256(content) {
21
+ // Browser environment: Use Web Crypto API
22
+ if (typeof crypto !== 'undefined' && crypto.subtle) {
23
+ const encoder = new TextEncoder();
24
+ const data = encoder.encode(content);
25
+ const hashBuffer = await crypto.subtle.digest('SHA-256', data);
26
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
27
+ return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
28
+ }
29
+ // Node.js environment: Use crypto module
30
+ const { createHash } = await import('crypto');
31
+ return createHash('sha256').update(content).digest('hex');
32
+ }
33
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAe;IAC3C,0CAA0C;IAC1C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACpD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;QACzD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,yCAAyC;IACzC,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC9C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@pie-qti/ims-cp-core",
3
+ "version": "0.1.0",
4
+ "description": "Core IMS Content Package manifest parsing utilities (browser + Node.js)",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./manifest-parser": {
14
+ "types": "./dist/manifest-parser.d.ts",
15
+ "import": "./dist/manifest-parser.js"
16
+ },
17
+ "./localized-resources": {
18
+ "types": "./dist/localized-resources.d.ts",
19
+ "import": "./dist/localized-resources.js"
20
+ },
21
+ "./passage-reusability": {
22
+ "types": "./dist/passage-reusability.d.ts",
23
+ "import": "./dist/passage-reusability.js"
24
+ }
25
+ },
26
+ "dependencies": {
27
+ "node-html-parser": "^6.1.13"
28
+ },
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "typecheck": "tsc --noEmit"
32
+ }
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @pie-qti/ims-cp-core
3
+ * Core IMS Content Package utilities (browser + Node.js compatible)
4
+ */
5
+
6
+ export * from './manifest-parser.js';
7
+ export * from './localized-resources.js';
8
+ export * from './passage-reusability.js';