scorm-again 2.6.0 → 2.6.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/aicc.js +9 -4
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +1 -1
- package/dist/aicc.min.js.map +1 -1
- package/dist/esm/aicc.js +10 -5
- package/dist/esm/aicc.js.map +1 -1
- package/dist/esm/aicc.min.js +1 -1
- package/dist/esm/aicc.min.js.map +1 -1
- package/dist/esm/scorm-again.js +12 -10
- package/dist/esm/scorm-again.js.map +1 -1
- package/dist/esm/scorm-again.min.js +1 -1
- package/dist/esm/scorm-again.min.js.map +1 -1
- package/dist/esm/scorm12.js +8 -3
- package/dist/esm/scorm12.js.map +1 -1
- package/dist/esm/scorm12.min.js +1 -1
- package/dist/esm/scorm12.min.js.map +1 -1
- package/dist/esm/scorm2004.js +8 -3
- package/dist/esm/scorm2004.js.map +1 -1
- package/dist/esm/scorm2004.min.js +1 -1
- package/dist/esm/scorm2004.min.js.map +1 -1
- package/dist/scorm-again.js +13 -11
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +1 -1
- package/dist/scorm-again.min.js.map +1 -1
- package/dist/scorm12.js +7 -2
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +1 -1
- package/dist/scorm12.min.js.map +1 -1
- package/dist/scorm2004.js +7 -2
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +1 -1
- package/dist/scorm2004.min.js.map +1 -1
- package/dist_test.html +208 -0
- package/package.json +1 -1
- package/src/AICC.ts +3 -3
- package/src/BaseAPI.ts +10 -7
- package/src/Scorm12API.ts +3 -9
- package/src/Scorm2004API.ts +4 -13
- package/src/ScormAgain.ts +3 -7
- package/test/Scorm12API.spec.ts +23 -0
- package/webpack.config.js +1 -1
package/dist_test.html
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>SCORM-Again Distribution Test</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
margin: 20px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
h1 {
|
|
14
|
+
color: #333;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.test-container {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-wrap: wrap;
|
|
20
|
+
gap: 20px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.test-frame {
|
|
24
|
+
border: 1px solid #ccc;
|
|
25
|
+
padding: 15px;
|
|
26
|
+
width: 300px;
|
|
27
|
+
margin-bottom: 20px;
|
|
28
|
+
border-radius: 5px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.test-frame h3 {
|
|
32
|
+
margin-top: 0;
|
|
33
|
+
border-bottom: 1px solid #eee;
|
|
34
|
+
padding-bottom: 10px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.success {
|
|
38
|
+
background-color: #d4edda;
|
|
39
|
+
color: #155724;
|
|
40
|
+
padding: 10px;
|
|
41
|
+
border-radius: 4px;
|
|
42
|
+
margin-top: 10px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.error {
|
|
46
|
+
background-color: #f8d7da;
|
|
47
|
+
color: #721c24;
|
|
48
|
+
padding: 10px;
|
|
49
|
+
border-radius: 4px;
|
|
50
|
+
margin-top: 10px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.section {
|
|
54
|
+
margin-bottom: 30px;
|
|
55
|
+
}
|
|
56
|
+
</style>
|
|
57
|
+
</head>
|
|
58
|
+
<body>
|
|
59
|
+
<h1>SCORM-Again Distribution Test</h1>
|
|
60
|
+
|
|
61
|
+
<div class="section">
|
|
62
|
+
<h2>Regular JavaScript Files</h2>
|
|
63
|
+
<div class="test-container" id="regular-container"></div>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<div class="section">
|
|
67
|
+
<h2>ESM Module Files</h2>
|
|
68
|
+
<div class="test-container" id="esm-container"></div>
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<script>
|
|
72
|
+
const dists = [
|
|
73
|
+
{
|
|
74
|
+
file: 'aicc.js',
|
|
75
|
+
api: ['AICC']
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
file: 'aicc.min.js',
|
|
79
|
+
api: ['AICC']
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
file: 'scorm12.js',
|
|
83
|
+
api: ['Scorm12API']
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
file: 'scorm12.min.js',
|
|
87
|
+
api: ['Scorm12API']
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
file: 'scorm2004.js',
|
|
91
|
+
api: ['Scorm2004API']
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
file: 'scorm2004.min.js',
|
|
95
|
+
api: ['Scorm2004API']
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
file: 'scorm-again.js',
|
|
99
|
+
api: ['Scorm12API', 'Scorm2004API', 'AICC']
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
file: 'scorm-again.min.js',
|
|
103
|
+
api: ['Scorm12API', 'Scorm2004API', 'AICC']
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
// Create test frames for regular JS files
|
|
108
|
+
const regularContainer = document.getElementById('regular-container');
|
|
109
|
+
dists.forEach(dist => {
|
|
110
|
+
const frame = document.createElement('div');
|
|
111
|
+
frame.className = 'test-frame';
|
|
112
|
+
frame.innerHTML = `
|
|
113
|
+
<h3>${dist.file}</h3>
|
|
114
|
+
<div id="dist-${dist.file.replace(/\//g, '-').replace(/\./g, '-')}-result"></div>
|
|
115
|
+
`;
|
|
116
|
+
regularContainer.appendChild(frame);
|
|
117
|
+
|
|
118
|
+
// Create iframe to load the script
|
|
119
|
+
const iframe = document.createElement('iframe');
|
|
120
|
+
iframe.style.display = 'none';
|
|
121
|
+
document.body.appendChild(iframe);
|
|
122
|
+
|
|
123
|
+
// Create HTML content for the iframe with script
|
|
124
|
+
const html = `
|
|
125
|
+
<!DOCTYPE html>
|
|
126
|
+
<html>
|
|
127
|
+
<head>
|
|
128
|
+
<script src="dist/${dist.file}"><\/script>
|
|
129
|
+
<script>
|
|
130
|
+
try {
|
|
131
|
+
window.parent.postMessage({
|
|
132
|
+
file: "dist-${dist.file}",
|
|
133
|
+
success: !!(${dist.api.map(api => `window.${api}`).join(' || ')})
|
|
134
|
+
}, "*");
|
|
135
|
+
} catch (error) {
|
|
136
|
+
window.parent.postMessage({
|
|
137
|
+
file: "dist-${dist.file}",
|
|
138
|
+
success: false,
|
|
139
|
+
error: error.message
|
|
140
|
+
}, "*");
|
|
141
|
+
}
|
|
142
|
+
<\/script>
|
|
143
|
+
</head>
|
|
144
|
+
<body></body>
|
|
145
|
+
</html>
|
|
146
|
+
`;
|
|
147
|
+
|
|
148
|
+
iframe.srcdoc = html;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Create test frames for ESM module files
|
|
152
|
+
const esmContainer = document.getElementById('esm-container');
|
|
153
|
+
dists.forEach(dist => {
|
|
154
|
+
const frame = document.createElement('div');
|
|
155
|
+
frame.className = 'test-frame';
|
|
156
|
+
frame.innerHTML = `
|
|
157
|
+
<h3>${dist.file}</h3>
|
|
158
|
+
<div id="dist-esm-${dist.file.replace(/\//g, '-').replace(/\./g, '-')}-result"></div>
|
|
159
|
+
`;
|
|
160
|
+
esmContainer.appendChild(frame);
|
|
161
|
+
|
|
162
|
+
// Create iframe to load the module
|
|
163
|
+
const iframe = document.createElement('iframe');
|
|
164
|
+
iframe.style.display = 'none';
|
|
165
|
+
document.body.appendChild(iframe);
|
|
166
|
+
|
|
167
|
+
// Create HTML content for the iframe with module import
|
|
168
|
+
const html = `
|
|
169
|
+
<!DOCTYPE html>
|
|
170
|
+
<html>
|
|
171
|
+
<head>
|
|
172
|
+
<script type="module">
|
|
173
|
+
try {
|
|
174
|
+
const module = await import('/dist/esm/${dist.file}');
|
|
175
|
+
window.parent.postMessage({
|
|
176
|
+
file: "dist-esm-${dist.file}",
|
|
177
|
+
success: !!(${dist.api.map(api => `module.${api}`).join(' || ')})
|
|
178
|
+
}, "*");
|
|
179
|
+
} catch (error) {
|
|
180
|
+
window.parent.postMessage({
|
|
181
|
+
file: "dist-esm-${dist.file}",
|
|
182
|
+
success: false,
|
|
183
|
+
error: error.message
|
|
184
|
+
}, "*");
|
|
185
|
+
}
|
|
186
|
+
<\/script>
|
|
187
|
+
</head>
|
|
188
|
+
<body></body>
|
|
189
|
+
</html>
|
|
190
|
+
`;
|
|
191
|
+
|
|
192
|
+
iframe.srcdoc = html;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Listen for messages from iframes
|
|
196
|
+
window.addEventListener('message', (event) => {
|
|
197
|
+
const {file, success, error} = event.data;
|
|
198
|
+
const resultElement = document.getElementById(`${file.replace(/\//g, '-').replace(/\./g, '-')}-result`);
|
|
199
|
+
|
|
200
|
+
if (success) {
|
|
201
|
+
resultElement.innerHTML = `<div class="success">Successfully loaded</div>`;
|
|
202
|
+
} else {
|
|
203
|
+
resultElement.innerHTML = `<div class="error">Failed to load: ${error || 'Library objects not found'}</div>`;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
</script>
|
|
207
|
+
</body>
|
|
208
|
+
</html>
|
package/package.json
CHANGED
package/src/AICC.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Scorm12API } from "./Scorm12API";
|
|
2
2
|
import { CMI } from "./cmi/aicc/cmi";
|
|
3
3
|
|
|
4
4
|
import { BaseCMI } from "./cmi/common/base_cmi";
|
|
@@ -13,7 +13,7 @@ import { stringMatches } from "./utilities";
|
|
|
13
13
|
/**
|
|
14
14
|
* The AICC API class
|
|
15
15
|
*/
|
|
16
|
-
class AICCImpl extends
|
|
16
|
+
class AICCImpl extends Scorm12API {
|
|
17
17
|
/**
|
|
18
18
|
* Constructor to create AICC API object
|
|
19
19
|
* @param {Settings} settings
|
|
@@ -74,4 +74,4 @@ class AICCImpl extends Scorm12Impl {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
export { AICCImpl };
|
|
77
|
+
export { AICCImpl as AICC };
|
package/src/BaseAPI.ts
CHANGED
|
@@ -4,13 +4,7 @@ import { ErrorCode } from "./constants/error_codes";
|
|
|
4
4
|
import { global_constants } from "./constants/api_constants";
|
|
5
5
|
import { formatMessage, stringMatches, unflatten } from "./utilities";
|
|
6
6
|
import { BaseCMI } from "./cmi/common/base_cmi";
|
|
7
|
-
import {
|
|
8
|
-
CommitObject,
|
|
9
|
-
LogLevel,
|
|
10
|
-
RefObject,
|
|
11
|
-
ResultObject,
|
|
12
|
-
Settings,
|
|
13
|
-
} from "./types/api_types";
|
|
7
|
+
import { CommitObject, LogLevel, RefObject, ResultObject, Settings } from "./types/api_types";
|
|
14
8
|
import { DefaultSettings } from "./constants/default_settings";
|
|
15
9
|
import { IBaseAPI } from "./interfaces/IBaseAPI";
|
|
16
10
|
import { ScheduledCommit } from "./helpers/scheduled_commit";
|
|
@@ -1048,6 +1042,15 @@ export default abstract class BaseAPI implements IBaseAPI {
|
|
|
1048
1042
|
* @param {string} CMIElement
|
|
1049
1043
|
*/
|
|
1050
1044
|
loadFromJSON(json: RefObject, CMIElement: string = "") {
|
|
1045
|
+
if (
|
|
1046
|
+
(!CMIElement || CMIElement === "") &&
|
|
1047
|
+
!Object.hasOwnProperty.call(json, "cmi") &&
|
|
1048
|
+
!Object.hasOwnProperty.call(json, "adl")
|
|
1049
|
+
) {
|
|
1050
|
+
// providing a backward compatibility for the old v1 API
|
|
1051
|
+
CMIElement = "cmi";
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1051
1054
|
if (!this.isNotInitialized()) {
|
|
1052
1055
|
console.error(
|
|
1053
1056
|
"loadFromJSON can only be called before the call to lmsInitialize.",
|
package/src/Scorm12API.ts
CHANGED
|
@@ -9,16 +9,10 @@ import { CMIObjectivesObject } from "./cmi/scorm12/objectives";
|
|
|
9
9
|
import {
|
|
10
10
|
CMIInteractionsCorrectResponsesObject,
|
|
11
11
|
CMIInteractionsObject,
|
|
12
|
-
CMIInteractionsObjectivesObject
|
|
12
|
+
CMIInteractionsObjectivesObject
|
|
13
13
|
} from "./cmi/scorm12/interactions";
|
|
14
14
|
import { NAV } from "./cmi/scorm12/nav";
|
|
15
|
-
import {
|
|
16
|
-
CommitObject,
|
|
17
|
-
RefObject,
|
|
18
|
-
ResultObject,
|
|
19
|
-
ScoreObject,
|
|
20
|
-
Settings,
|
|
21
|
-
} from "./types/api_types";
|
|
15
|
+
import { CommitObject, RefObject, ResultObject, ScoreObject, Settings } from "./types/api_types";
|
|
22
16
|
import { CompletionStatus, SuccessStatus } from "./constants/enums";
|
|
23
17
|
import BaseAPI from "./BaseAPI";
|
|
24
18
|
import { scorm12_regex } from "./constants/regex";
|
|
@@ -444,4 +438,4 @@ class Scorm12Impl extends BaseAPI {
|
|
|
444
438
|
}
|
|
445
439
|
}
|
|
446
440
|
|
|
447
|
-
export { Scorm12Impl };
|
|
441
|
+
export { Scorm12Impl as Scorm12API };
|
package/src/Scorm2004API.ts
CHANGED
|
@@ -2,10 +2,7 @@ import BaseAPI from "./BaseAPI";
|
|
|
2
2
|
import { CMI } from "./cmi/scorm2004/cmi";
|
|
3
3
|
import * as Utilities from "./utilities";
|
|
4
4
|
import { stringMatches } from "./utilities";
|
|
5
|
-
import {
|
|
6
|
-
global_constants,
|
|
7
|
-
scorm2004_constants,
|
|
8
|
-
} from "./constants/api_constants";
|
|
5
|
+
import { global_constants, scorm2004_constants } from "./constants/api_constants";
|
|
9
6
|
import { scorm2004_errors } from "./constants/error_codes";
|
|
10
7
|
import { CorrectResponses, ResponseType } from "./constants/response_constants";
|
|
11
8
|
import ValidLanguages from "./constants/language_constants";
|
|
@@ -14,18 +11,12 @@ import { BaseCMI } from "./cmi/common/base_cmi";
|
|
|
14
11
|
import {
|
|
15
12
|
CMIInteractionsCorrectResponsesObject,
|
|
16
13
|
CMIInteractionsObject,
|
|
17
|
-
CMIInteractionsObjectivesObject
|
|
14
|
+
CMIInteractionsObjectivesObject
|
|
18
15
|
} from "./cmi/scorm2004/interactions";
|
|
19
16
|
import { CMICommentsObject } from "./cmi/scorm2004/comments";
|
|
20
17
|
import { CMIObjectivesObject } from "./cmi/scorm2004/objectives";
|
|
21
18
|
import { ADL, ADLDataObject } from "./cmi/scorm2004/adl";
|
|
22
|
-
import {
|
|
23
|
-
CommitObject,
|
|
24
|
-
RefObject,
|
|
25
|
-
ResultObject,
|
|
26
|
-
ScoreObject,
|
|
27
|
-
Settings,
|
|
28
|
-
} from "./types/api_types";
|
|
19
|
+
import { CommitObject, RefObject, ResultObject, ScoreObject, Settings } from "./types/api_types";
|
|
29
20
|
import { CompletionStatus, SuccessStatus } from "./constants/enums";
|
|
30
21
|
import { scorm2004_regex } from "./constants/regex";
|
|
31
22
|
|
|
@@ -820,4 +811,4 @@ class Scorm2004Impl extends BaseAPI {
|
|
|
820
811
|
}
|
|
821
812
|
}
|
|
822
813
|
|
|
823
|
-
export { Scorm2004Impl };
|
|
814
|
+
export { Scorm2004Impl as Scorm2004API };
|
package/src/ScormAgain.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const Scorm12API = Scorm12Impl;
|
|
6
|
-
const Scorm2004API = Scorm2004Impl;
|
|
7
|
-
const AICC = AICCImpl;
|
|
1
|
+
import { AICC } from "./AICC";
|
|
2
|
+
import { Scorm12API } from "./Scorm12API";
|
|
3
|
+
import { Scorm2004API } from "./Scorm2004API";
|
|
8
4
|
|
|
9
5
|
export { Scorm12API, Scorm2004API, AICC };
|
package/test/Scorm12API.spec.ts
CHANGED
|
@@ -118,6 +118,29 @@ describe("SCORM 1.2 API Tests", () => {
|
|
|
118
118
|
expect(scorm12API.cmi.objectives.childArray[0].score.max).toEqual("100");
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
+
it("should load nested JSON data into the CMI object in a backwards compatible way with v1", () => {
|
|
122
|
+
const scorm12API = api();
|
|
123
|
+
const jsonData = {
|
|
124
|
+
objectives: {
|
|
125
|
+
"0": {
|
|
126
|
+
id: "obj_1",
|
|
127
|
+
score: {
|
|
128
|
+
raw: "85",
|
|
129
|
+
min: "0",
|
|
130
|
+
max: "100",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
scorm12API.loadFromJSON(jsonData);
|
|
137
|
+
|
|
138
|
+
expect(scorm12API.cmi.objectives.childArray[0].id).toEqual("obj_1");
|
|
139
|
+
expect(scorm12API.cmi.objectives.childArray[0].score.raw).toEqual("85");
|
|
140
|
+
expect(scorm12API.cmi.objectives.childArray[0].score.min).toEqual("0");
|
|
141
|
+
expect(scorm12API.cmi.objectives.childArray[0].score.max).toEqual("100");
|
|
142
|
+
});
|
|
143
|
+
|
|
121
144
|
it("should handle empty JSON data", () => {
|
|
122
145
|
const scorm12API = api();
|
|
123
146
|
const jsonData = {};
|