@lxpack/runtime 0.1.1 → 0.2.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.
- package/README.md +67 -11
- package/dist/client.js +1855 -1519
- package/dist/flow.d.ts +14 -0
- package/dist/flow.d.ts.map +1 -0
- package/dist/runtime.d.ts +5 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +352 -155
- package/dist/scorm2004-api.d.ts +57 -0
- package/dist/scorm2004-api.d.ts.map +1 -0
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/variables.d.ts +7 -0
- package/dist/variables.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/runtime.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var i = (
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
let s = window,
|
|
7
|
-
for (; s &&
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var O = (e, s, t) => s in e ? E(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
|
|
3
|
+
var i = (e, s, t) => O(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
+
const g = "lxpack_scorm12_preview";
|
|
5
|
+
function M(e = 500) {
|
|
6
|
+
let s = window, t = 0;
|
|
7
|
+
for (; s && t < e; ) {
|
|
8
8
|
try {
|
|
9
9
|
const r = s.API;
|
|
10
10
|
if (r && typeof r.LMSInitialize == "function")
|
|
@@ -21,11 +21,11 @@ function _(t = 500) {
|
|
|
21
21
|
} catch {
|
|
22
22
|
break;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
t++;
|
|
25
25
|
}
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
|
-
class
|
|
28
|
+
class A {
|
|
29
29
|
constructor(s) {
|
|
30
30
|
i(this, "api");
|
|
31
31
|
i(this, "initialized", !1);
|
|
@@ -48,8 +48,8 @@ class L {
|
|
|
48
48
|
LMSGetValue(s) {
|
|
49
49
|
return !this.initialized || this.terminated ? (this.lastError = "301", "") : (this.lastError = "0", this.api.LMSGetValue(s));
|
|
50
50
|
}
|
|
51
|
-
LMSSetValue(s,
|
|
52
|
-
return !this.initialized || this.terminated ? (this.lastError = "301", "false") : (this.lastError = "0", this.api.LMSSetValue(s,
|
|
51
|
+
LMSSetValue(s, t) {
|
|
52
|
+
return !this.initialized || this.terminated ? (this.lastError = "301", "false") : (this.lastError = "0", this.api.LMSSetValue(s, t));
|
|
53
53
|
}
|
|
54
54
|
LMSCommit() {
|
|
55
55
|
return !this.initialized || this.terminated ? (this.lastError = "301", "false") : (this.lastError = "0", this.api.LMSCommit(""));
|
|
@@ -58,8 +58,8 @@ class L {
|
|
|
58
58
|
return this.lastError;
|
|
59
59
|
}
|
|
60
60
|
LMSGetErrorString(s) {
|
|
61
|
-
const
|
|
62
|
-
return
|
|
61
|
+
const t = s ?? this.lastError;
|
|
62
|
+
return t === "301" ? "Not initialized" : t === "302" ? "Already terminated" : this.api.LMSGetErrorString(t);
|
|
63
63
|
}
|
|
64
64
|
LMSGetDiagnostic(s) {
|
|
65
65
|
return this.api.LMSGetDiagnostic(s ?? this.lastError);
|
|
@@ -67,18 +67,18 @@ class L {
|
|
|
67
67
|
setLessonStatus(s) {
|
|
68
68
|
this.LMSSetValue("cmi.core.lesson_status", s);
|
|
69
69
|
}
|
|
70
|
-
setScore(s,
|
|
71
|
-
this.LMSSetValue("cmi.core.score.raw", String(s)), this.LMSSetValue("cmi.core.score.max", String(
|
|
70
|
+
setScore(s, t = 100) {
|
|
71
|
+
this.LMSSetValue("cmi.core.score.raw", String(s)), this.LMSSetValue("cmi.core.score.max", String(t)), this.LMSSetValue("cmi.core.score.min", "0");
|
|
72
72
|
}
|
|
73
73
|
setSuspendData(s) {
|
|
74
|
-
const
|
|
75
|
-
this.LMSSetValue("cmi.suspend_data",
|
|
74
|
+
const t = d(s);
|
|
75
|
+
this.LMSSetValue("cmi.suspend_data", t);
|
|
76
76
|
}
|
|
77
77
|
setLessonLocation(s) {
|
|
78
78
|
this.LMSSetValue("cmi.core.lesson_location", s);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
class
|
|
81
|
+
class u {
|
|
82
82
|
constructor(s = {}) {
|
|
83
83
|
i(this, "data", {
|
|
84
84
|
lessonStatus: "not attempted",
|
|
@@ -133,33 +133,33 @@ class h {
|
|
|
133
133
|
return "";
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
-
LMSSetValue(s,
|
|
136
|
+
LMSSetValue(s, t) {
|
|
137
137
|
if (!this.initialized || this.terminated)
|
|
138
138
|
return this.lastError = "301", "false";
|
|
139
139
|
switch (this.lastError = "0", s) {
|
|
140
140
|
case "cmi.core.lesson_status":
|
|
141
|
-
this.data.lessonStatus =
|
|
141
|
+
this.data.lessonStatus = t;
|
|
142
142
|
break;
|
|
143
143
|
case "cmi.core.score.raw":
|
|
144
|
-
this.data.scoreRaw = Number(
|
|
144
|
+
this.data.scoreRaw = Number(t);
|
|
145
145
|
break;
|
|
146
146
|
case "cmi.core.score.min":
|
|
147
|
-
this.data.scoreMin = Number(
|
|
147
|
+
this.data.scoreMin = Number(t);
|
|
148
148
|
break;
|
|
149
149
|
case "cmi.core.score.max":
|
|
150
|
-
this.data.scoreMax = Number(
|
|
150
|
+
this.data.scoreMax = Number(t);
|
|
151
151
|
break;
|
|
152
152
|
case "cmi.suspend_data":
|
|
153
|
-
this.data.suspendData =
|
|
153
|
+
this.data.suspendData = d(t);
|
|
154
154
|
break;
|
|
155
155
|
case "cmi.core.lesson_location":
|
|
156
|
-
this.data.lessonLocation =
|
|
156
|
+
this.data.lessonLocation = t;
|
|
157
157
|
break;
|
|
158
158
|
case "cmi.core.exit":
|
|
159
|
-
this.data.exit =
|
|
159
|
+
this.data.exit = t;
|
|
160
160
|
break;
|
|
161
161
|
case "cmi.core.session_time":
|
|
162
|
-
this.data.sessionTime =
|
|
162
|
+
this.data.sessionTime = t;
|
|
163
163
|
break;
|
|
164
164
|
default:
|
|
165
165
|
return "false";
|
|
@@ -173,8 +173,8 @@ class h {
|
|
|
173
173
|
return this.lastError;
|
|
174
174
|
}
|
|
175
175
|
LMSGetErrorString(s) {
|
|
176
|
-
const
|
|
177
|
-
return
|
|
176
|
+
const t = s ?? this.lastError;
|
|
177
|
+
return t === "301" ? "Not initialized" : t === "302" ? "Already terminated" : "No error";
|
|
178
178
|
}
|
|
179
179
|
LMSGetDiagnostic() {
|
|
180
180
|
return "";
|
|
@@ -182,18 +182,18 @@ class h {
|
|
|
182
182
|
setLessonStatus(s) {
|
|
183
183
|
this.data.lessonStatus = s, this.saveToStorage();
|
|
184
184
|
}
|
|
185
|
-
setScore(s,
|
|
186
|
-
this.data.scoreRaw = s, this.data.scoreMax =
|
|
185
|
+
setScore(s, t = 100) {
|
|
186
|
+
this.data.scoreRaw = s, this.data.scoreMax = t, this.data.scoreMin = 0, this.saveToStorage();
|
|
187
187
|
}
|
|
188
188
|
setSuspendData(s) {
|
|
189
|
-
this.data.suspendData =
|
|
189
|
+
this.data.suspendData = d(s), this.saveToStorage();
|
|
190
190
|
}
|
|
191
191
|
setLessonLocation(s) {
|
|
192
192
|
this.data.lessonLocation = s, this.saveToStorage();
|
|
193
193
|
}
|
|
194
194
|
loadFromStorage() {
|
|
195
195
|
try {
|
|
196
|
-
const s = localStorage.getItem(
|
|
196
|
+
const s = localStorage.getItem(g);
|
|
197
197
|
s && (this.data = { ...this.data, ...JSON.parse(s) });
|
|
198
198
|
} catch {
|
|
199
199
|
}
|
|
@@ -201,139 +201,330 @@ class h {
|
|
|
201
201
|
saveToStorage() {
|
|
202
202
|
if (this.persistToStorage)
|
|
203
203
|
try {
|
|
204
|
-
localStorage.setItem(
|
|
204
|
+
localStorage.setItem(g, JSON.stringify(this.data));
|
|
205
205
|
} catch {
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
class
|
|
209
|
+
class F extends u {
|
|
210
210
|
constructor() {
|
|
211
211
|
super({ persistToStorage: !0 });
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
|
-
function
|
|
215
|
-
return
|
|
214
|
+
function d(e) {
|
|
215
|
+
return e.length <= 4096 ? e : (console.warn(
|
|
216
216
|
"[lxpack] suspend_data exceeds 4096 chars; truncating"
|
|
217
|
-
),
|
|
217
|
+
), e.slice(0, 4096));
|
|
218
218
|
}
|
|
219
|
-
function
|
|
220
|
-
if (
|
|
221
|
-
return new
|
|
222
|
-
if (
|
|
223
|
-
const s =
|
|
224
|
-
return s ? new
|
|
219
|
+
function L(e) {
|
|
220
|
+
if (e === "preview")
|
|
221
|
+
return new u({ persistToStorage: !0 });
|
|
222
|
+
if (e === "scorm12") {
|
|
223
|
+
const s = M();
|
|
224
|
+
return s ? new A(s) : (console.warn(
|
|
225
225
|
"[lxpack] No LMS SCORM API found; using in-memory simulator (progress will not persist to LMS)"
|
|
226
|
-
), new
|
|
226
|
+
), new u({ persistToStorage: !1 }));
|
|
227
227
|
}
|
|
228
|
-
return new
|
|
228
|
+
return new u({ persistToStorage: !1 });
|
|
229
229
|
}
|
|
230
|
-
function
|
|
231
|
-
const s =
|
|
232
|
-
if (
|
|
233
|
-
const
|
|
234
|
-
|
|
230
|
+
function j(e = "preview") {
|
|
231
|
+
const s = L(e);
|
|
232
|
+
if (e === "preview") {
|
|
233
|
+
const t = window;
|
|
234
|
+
t.API = s;
|
|
235
235
|
}
|
|
236
236
|
return s;
|
|
237
237
|
}
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
const I = "0", R = "lxpack_scorm2004_preview";
|
|
239
|
+
function N(e = 500) {
|
|
240
|
+
let s = window, t = 0;
|
|
241
|
+
for (; s && t < e; ) {
|
|
242
|
+
try {
|
|
243
|
+
const r = s.API_1484_11;
|
|
244
|
+
if (r && typeof r.Initialize == "function")
|
|
245
|
+
return r;
|
|
246
|
+
} catch {
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
if (s.parent && s.parent !== s)
|
|
250
|
+
s = s.parent;
|
|
251
|
+
else if (s.opener && !s.opener.closed)
|
|
252
|
+
s = s.opener;
|
|
253
|
+
else
|
|
254
|
+
break;
|
|
255
|
+
} catch {
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
t++;
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
class T {
|
|
263
|
+
constructor(s) {
|
|
264
|
+
i(this, "initialized", !1);
|
|
265
|
+
i(this, "terminated", !1);
|
|
266
|
+
i(this, "data", {
|
|
267
|
+
"cmi.completion_status": "unknown",
|
|
268
|
+
"cmi.success_status": "unknown",
|
|
269
|
+
"cmi.score.scaled": "",
|
|
270
|
+
"cmi.suspend_data": "",
|
|
271
|
+
"cmi.location": "",
|
|
272
|
+
"cmi.entry": "ab-initio"
|
|
273
|
+
});
|
|
274
|
+
i(this, "persistToStorage");
|
|
275
|
+
if (this.persistToStorage = (s == null ? void 0 : s.persistToStorage) ?? !1, this.persistToStorage)
|
|
276
|
+
try {
|
|
277
|
+
const t = localStorage.getItem(R);
|
|
278
|
+
t && (this.data = { ...this.data, ...JSON.parse(t) });
|
|
279
|
+
} catch {
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
save() {
|
|
283
|
+
if (this.persistToStorage)
|
|
284
|
+
try {
|
|
285
|
+
localStorage.setItem(R, JSON.stringify(this.data));
|
|
286
|
+
} catch {
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
Initialize() {
|
|
290
|
+
return this.initialized ? "false" : (this.initialized = !0, this.terminated = !1, "true");
|
|
291
|
+
}
|
|
292
|
+
Terminate() {
|
|
293
|
+
return !this.initialized || this.terminated ? "false" : (this.terminated = !0, this.save(), "true");
|
|
294
|
+
}
|
|
295
|
+
GetValue(s) {
|
|
296
|
+
return !this.initialized || this.terminated ? "" : this.data[s] ?? "";
|
|
297
|
+
}
|
|
298
|
+
SetValue(s, t) {
|
|
299
|
+
return !this.initialized || this.terminated ? "false" : (this.data[s] = t, this.save(), "true");
|
|
300
|
+
}
|
|
301
|
+
Commit() {
|
|
302
|
+
return !this.initialized || this.terminated ? "false" : (this.save(), "true");
|
|
303
|
+
}
|
|
304
|
+
GetLastError() {
|
|
305
|
+
return I;
|
|
306
|
+
}
|
|
307
|
+
GetErrorString() {
|
|
308
|
+
return "No error";
|
|
309
|
+
}
|
|
310
|
+
GetDiagnostic() {
|
|
311
|
+
return "";
|
|
312
|
+
}
|
|
313
|
+
setSuspendData(s) {
|
|
314
|
+
this.data["cmi.suspend_data"] = s;
|
|
315
|
+
}
|
|
316
|
+
setLocation(s) {
|
|
317
|
+
this.data["cmi.location"] = s;
|
|
318
|
+
}
|
|
319
|
+
setCompletionStatus(s) {
|
|
320
|
+
this.data["cmi.completion_status"] = s;
|
|
321
|
+
}
|
|
322
|
+
setSuccessStatus(s) {
|
|
323
|
+
this.data["cmi.success_status"] = s;
|
|
324
|
+
}
|
|
325
|
+
setScoreScaled(s) {
|
|
326
|
+
this.data["cmi.score.scaled"] = String(Math.max(0, Math.min(1, s)));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
class D {
|
|
330
|
+
constructor(s) {
|
|
331
|
+
i(this, "api");
|
|
332
|
+
this.api = s;
|
|
333
|
+
}
|
|
334
|
+
Initialize() {
|
|
335
|
+
return this.api.Initialize("");
|
|
336
|
+
}
|
|
337
|
+
Terminate() {
|
|
338
|
+
return this.api.Terminate("");
|
|
339
|
+
}
|
|
340
|
+
GetValue(s) {
|
|
341
|
+
return this.api.GetValue(s);
|
|
342
|
+
}
|
|
343
|
+
SetValue(s, t) {
|
|
344
|
+
return this.api.SetValue(s, t);
|
|
345
|
+
}
|
|
346
|
+
Commit() {
|
|
347
|
+
return this.api.Commit("");
|
|
348
|
+
}
|
|
349
|
+
GetLastError() {
|
|
350
|
+
return this.api.GetLastError();
|
|
351
|
+
}
|
|
352
|
+
GetErrorString(s) {
|
|
353
|
+
return this.api.GetErrorString(s);
|
|
354
|
+
}
|
|
355
|
+
GetDiagnostic(s) {
|
|
356
|
+
return this.api.GetDiagnostic(s);
|
|
357
|
+
}
|
|
358
|
+
setSuspendData(s) {
|
|
359
|
+
this.api.SetValue("cmi.suspend_data", s);
|
|
360
|
+
}
|
|
361
|
+
setLocation(s) {
|
|
362
|
+
this.api.SetValue("cmi.location", s);
|
|
363
|
+
}
|
|
364
|
+
setCompletionStatus(s) {
|
|
365
|
+
this.api.SetValue("cmi.completion_status", s);
|
|
366
|
+
}
|
|
367
|
+
setSuccessStatus(s) {
|
|
368
|
+
this.api.SetValue("cmi.success_status", s);
|
|
369
|
+
}
|
|
370
|
+
setScoreScaled(s) {
|
|
371
|
+
this.api.SetValue("cmi.score.scaled", String(Math.max(0, Math.min(1, s))));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function C(e) {
|
|
375
|
+
const s = N();
|
|
376
|
+
return s ? new D(s) : (console.warn(
|
|
377
|
+
"[lxpack] No SCORM 2004 API found; using in-memory simulator"
|
|
378
|
+
), new T({ persistToStorage: !1 }));
|
|
379
|
+
}
|
|
380
|
+
function p(e) {
|
|
381
|
+
var t;
|
|
240
382
|
const s = {
|
|
241
|
-
c:
|
|
242
|
-
l:
|
|
243
|
-
a:
|
|
244
|
-
s:
|
|
383
|
+
c: e.currentLessonId,
|
|
384
|
+
l: e.completedLessons,
|
|
385
|
+
a: e.assessmentScores,
|
|
386
|
+
s: e.suspendData
|
|
245
387
|
};
|
|
246
|
-
return (
|
|
388
|
+
return (t = s.l) != null && t.length || delete s.l, (!s.a || !Object.keys(s.a).length) && delete s.a, (!s.s || !Object.keys(s.s).length) && delete s.s, s;
|
|
247
389
|
}
|
|
248
|
-
function
|
|
390
|
+
function y(e, s) {
|
|
249
391
|
return {
|
|
250
|
-
currentLessonId:
|
|
251
|
-
completedLessons: Array.isArray(
|
|
252
|
-
assessmentScores:
|
|
253
|
-
suspendData:
|
|
392
|
+
currentLessonId: e.c ?? s.currentLessonId,
|
|
393
|
+
completedLessons: Array.isArray(e.l) ? e.l : s.completedLessons,
|
|
394
|
+
assessmentScores: e.a && typeof e.a == "object" ? e.a : s.assessmentScores,
|
|
395
|
+
suspendData: e.s && typeof e.s == "object" ? e.s : s.suspendData
|
|
254
396
|
};
|
|
255
397
|
}
|
|
256
|
-
function
|
|
257
|
-
const s = { ...
|
|
258
|
-
for (const r of
|
|
259
|
-
if (delete s[r], JSON.stringify(
|
|
260
|
-
return { ...
|
|
261
|
-
return { ...
|
|
398
|
+
function b(e) {
|
|
399
|
+
const s = { ...e.suspendData }, t = Object.keys(s).filter((r) => r.startsWith("interaction_")).sort();
|
|
400
|
+
for (const r of t)
|
|
401
|
+
if (delete s[r], JSON.stringify(p({ ...e, suspendData: s })).length <= 4096)
|
|
402
|
+
return { ...e, suspendData: s };
|
|
403
|
+
return { ...e, suspendData: s };
|
|
262
404
|
}
|
|
263
|
-
function
|
|
264
|
-
let s = JSON.stringify(
|
|
405
|
+
function P(e) {
|
|
406
|
+
let s = JSON.stringify(p(e));
|
|
265
407
|
if (s.length <= 4096)
|
|
266
408
|
return s;
|
|
267
|
-
const
|
|
268
|
-
return s = JSON.stringify(
|
|
409
|
+
const t = b(e);
|
|
410
|
+
return s = JSON.stringify(p(t)), s.length <= 4096 ? s : (console.warn(
|
|
269
411
|
"[lxpack] suspend_data exceeds 4096 chars; truncating"
|
|
270
412
|
), s.slice(0, 4096));
|
|
271
413
|
}
|
|
272
|
-
function
|
|
273
|
-
if (!
|
|
274
|
-
const s =
|
|
414
|
+
function w(e) {
|
|
415
|
+
if (!e || typeof e != "object") return !1;
|
|
416
|
+
const s = e;
|
|
275
417
|
return "currentLessonId" in s || "completedLessons" in s || "assessmentScores" in s;
|
|
276
418
|
}
|
|
277
|
-
function
|
|
419
|
+
function V(e, s) {
|
|
278
420
|
return {
|
|
279
|
-
currentLessonId:
|
|
280
|
-
completedLessons: Array.isArray(
|
|
281
|
-
assessmentScores:
|
|
282
|
-
suspendData:
|
|
421
|
+
currentLessonId: e.currentLessonId ?? s.currentLessonId,
|
|
422
|
+
completedLessons: Array.isArray(e.completedLessons) ? e.completedLessons : s.completedLessons,
|
|
423
|
+
assessmentScores: e.assessmentScores && typeof e.assessmentScores == "object" ? e.assessmentScores : s.assessmentScores,
|
|
424
|
+
suspendData: e.suspendData && typeof e.suspendData == "object" ? e.suspendData : s.suspendData
|
|
283
425
|
};
|
|
284
426
|
}
|
|
285
|
-
function
|
|
427
|
+
function m(e, s) {
|
|
286
428
|
try {
|
|
287
|
-
const
|
|
288
|
-
return
|
|
289
|
-
progress:
|
|
429
|
+
const t = JSON.parse(e);
|
|
430
|
+
return w(t) ? {
|
|
431
|
+
progress: V(t, s),
|
|
290
432
|
parsed: !0
|
|
291
|
-
} : { progress:
|
|
433
|
+
} : { progress: y(t, s), parsed: !0 };
|
|
292
434
|
} catch {
|
|
293
435
|
return { progress: s, parsed: !1 };
|
|
294
436
|
}
|
|
295
437
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
438
|
+
const z = "v:";
|
|
439
|
+
function f(e) {
|
|
440
|
+
return `${z}${e}`;
|
|
441
|
+
}
|
|
442
|
+
function k(e, s) {
|
|
443
|
+
for (const [t, r] of Object.entries(e.variables ?? {})) {
|
|
444
|
+
const a = f(t);
|
|
445
|
+
s[a] === void 0 && (s[a] = r.default);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function _(e, s) {
|
|
449
|
+
return e[f(s)];
|
|
450
|
+
}
|
|
451
|
+
function x(e, s, t) {
|
|
452
|
+
e[f(s)] = t;
|
|
453
|
+
}
|
|
454
|
+
function S(e, s) {
|
|
455
|
+
var t, r, a;
|
|
456
|
+
if ("variable" in e && ((t = e.variable) != null && t.eq)) {
|
|
457
|
+
const [n, o] = e.variable.eq;
|
|
458
|
+
return s.getVariable(n) === o;
|
|
459
|
+
}
|
|
460
|
+
return "assessment" in e && ((r = e.assessment) != null && r.passed) ? s.isAssessmentPassed(e.assessment.passed) : "interaction" in e && ((a = e.interaction) != null && a.done) ? s.isInteractionDone(e.interaction.done) : "all" in e && e.all ? e.all.every((n) => S(n, s)) : "any" in e && e.any ? e.any.some((n) => S(n, s)) : !1;
|
|
461
|
+
}
|
|
462
|
+
function G(e, s) {
|
|
463
|
+
const t = e.flow;
|
|
464
|
+
if (!(t != null && t.length)) return null;
|
|
465
|
+
for (const r of t)
|
|
466
|
+
if (S(r.when, s))
|
|
467
|
+
return r.goto;
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
function $(e) {
|
|
471
|
+
const s = `${e.title}::${e.version}`;
|
|
472
|
+
let t = 0;
|
|
299
473
|
for (let r = 0; r < s.length; r++)
|
|
300
|
-
|
|
301
|
-
return `lxpack_progress_${Math.abs(
|
|
474
|
+
t = (t << 5) - t + s.charCodeAt(r), t |= 0;
|
|
475
|
+
return `lxpack_progress_${Math.abs(t)}`;
|
|
302
476
|
}
|
|
303
|
-
class
|
|
477
|
+
class U {
|
|
304
478
|
constructor(s) {
|
|
305
479
|
i(this, "manifest");
|
|
306
480
|
i(this, "progress");
|
|
307
481
|
i(this, "scorm", null);
|
|
482
|
+
i(this, "scorm2004", null);
|
|
308
483
|
i(this, "completionThreshold");
|
|
309
484
|
i(this, "storageKey");
|
|
310
485
|
i(this, "mode");
|
|
311
486
|
i(this, "passedAssessments", /* @__PURE__ */ new Set());
|
|
312
487
|
i(this, "defaultPassingScores");
|
|
313
488
|
i(this, "terminated", !1);
|
|
314
|
-
var r, a,
|
|
315
|
-
this.manifest = s.manifest, this.mode = s.mode, this.completionThreshold = ((a = (r = s.manifest.tracking) == null ? void 0 : r.completion) == null ? void 0 : a.threshold) ?? 0.9, this.storageKey =
|
|
316
|
-
for (const [
|
|
317
|
-
this.defaultPassingScores[
|
|
318
|
-
const
|
|
489
|
+
var r, a, n;
|
|
490
|
+
this.manifest = s.manifest, this.mode = s.mode, this.completionThreshold = ((a = (r = s.manifest.tracking) == null ? void 0 : r.completion) == null ? void 0 : a.threshold) ?? 0.9, this.storageKey = $(s.manifest), this.defaultPassingScores = {};
|
|
491
|
+
for (const [o, c] of Object.entries(s.assessments ?? {}))
|
|
492
|
+
this.defaultPassingScores[o] = c.passingScore;
|
|
493
|
+
const t = s.activityId ?? ((n = s.manifest.lessons[0]) == null ? void 0 : n.id) ?? "";
|
|
319
494
|
this.progress = s.progress ?? {
|
|
320
|
-
currentLessonId:
|
|
495
|
+
currentLessonId: t,
|
|
321
496
|
completedLessons: [],
|
|
322
497
|
assessmentScores: {},
|
|
323
498
|
suspendData: {}
|
|
324
|
-
}, s.mode === "scorm12" ? (this.scorm =
|
|
499
|
+
}, k(this.manifest, this.progress.suspendData), s.mode === "scorm12" ? (this.scorm = L("scorm12"), this.scorm.LMSInitialize(), this.restoreScormProgress()) : s.mode === "scorm2004" ? (this.scorm2004 = C(), this.scorm2004.Initialize(), this.restoreScorm2004Progress()) : (s.mode === "preview" || s.mode === "standalone") && this.restoreLocalProgress(), s.activityId && (this.progress.currentLessonId = s.activityId);
|
|
325
500
|
}
|
|
326
501
|
restoreLessonLocation() {
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
502
|
+
if (this.scorm) {
|
|
503
|
+
const s = this.scorm.LMSGetValue("cmi.core.lesson_location");
|
|
504
|
+
s && (this.progress.currentLessonId = s);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (this.scorm2004) {
|
|
508
|
+
const s = this.scorm2004.GetValue("cmi.location");
|
|
509
|
+
s && (this.progress.currentLessonId = s);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
restoreScorm2004Progress() {
|
|
513
|
+
if (!this.scorm2004) return;
|
|
514
|
+
const s = this.scorm2004.GetValue("cmi.suspend_data");
|
|
515
|
+
if (s) {
|
|
516
|
+
const { progress: t, parsed: r } = m(s, this.progress);
|
|
517
|
+
r ? this.progress = t : this.restoreLessonLocation();
|
|
518
|
+
} else
|
|
519
|
+
this.restoreLessonLocation();
|
|
520
|
+
this.syncPassedAssessments();
|
|
330
521
|
}
|
|
331
522
|
restoreScormProgress() {
|
|
332
523
|
if (!this.scorm) return;
|
|
333
524
|
const s = this.scorm.LMSGetValue("cmi.suspend_data");
|
|
334
525
|
if (s) {
|
|
335
|
-
const { progress:
|
|
336
|
-
r ? this.progress =
|
|
526
|
+
const { progress: t, parsed: r } = m(s, this.progress);
|
|
527
|
+
r ? this.progress = t : this.restoreLessonLocation();
|
|
337
528
|
} else
|
|
338
529
|
this.restoreLessonLocation();
|
|
339
530
|
this.syncPassedAssessments();
|
|
@@ -342,8 +533,8 @@ class y {
|
|
|
342
533
|
try {
|
|
343
534
|
const s = localStorage.getItem(this.storageKey);
|
|
344
535
|
if (s) {
|
|
345
|
-
const { progress:
|
|
346
|
-
r && (this.progress =
|
|
536
|
+
const { progress: t, parsed: r } = m(s, this.progress);
|
|
537
|
+
r && (this.progress = t);
|
|
347
538
|
}
|
|
348
539
|
} catch {
|
|
349
540
|
}
|
|
@@ -351,12 +542,12 @@ class y {
|
|
|
351
542
|
}
|
|
352
543
|
syncPassedAssessments() {
|
|
353
544
|
this.passedAssessments.clear();
|
|
354
|
-
for (const [s,
|
|
355
|
-
|
|
545
|
+
for (const [s, t] of Object.entries(this.progress.assessmentScores))
|
|
546
|
+
t >= this.getAssessmentPassingScore(s) && this.passedAssessments.add(s);
|
|
356
547
|
}
|
|
357
548
|
getAssessmentPassingScore(s) {
|
|
358
|
-
const
|
|
359
|
-
return typeof
|
|
549
|
+
const t = this.progress.suspendData[`assessment_passing_${s}`];
|
|
550
|
+
return typeof t == "number" ? t : s in this.defaultPassingScores ? this.defaultPassingScores[s] : 0.7;
|
|
360
551
|
}
|
|
361
552
|
getAPI() {
|
|
362
553
|
return {
|
|
@@ -368,35 +559,35 @@ class y {
|
|
|
368
559
|
assessmentScores: { ...this.progress.assessmentScores },
|
|
369
560
|
suspendData: { ...this.progress.suspendData }
|
|
370
561
|
}),
|
|
371
|
-
setVariable: (s,
|
|
372
|
-
this.progress.suspendData[s] =
|
|
562
|
+
setVariable: (s, t) => {
|
|
563
|
+
this.manifest.variables && s in this.manifest.variables ? x(this.progress.suspendData, s, t) : this.progress.suspendData[s] = t, this.persist();
|
|
373
564
|
},
|
|
374
|
-
getVariable: (s) => this.progress.suspendData[s],
|
|
375
|
-
submitAssessment: (s,
|
|
565
|
+
getVariable: (s) => this.manifest.variables && s in this.manifest.variables ? _(this.progress.suspendData, s) : this.progress.suspendData[s],
|
|
566
|
+
submitAssessment: (s, t, r) => this.submitAssessment(s, t, r)
|
|
376
567
|
};
|
|
377
568
|
}
|
|
378
|
-
track(s,
|
|
569
|
+
track(s, t) {
|
|
379
570
|
var r, a;
|
|
380
571
|
if (s.type === "interaction" && s.id && (this.progress.suspendData[`interaction_${s.id}`] = s.data ?? !0, console.debug("[lxpack] interaction:", s.id, s.data)), s.type === "assessment" && s.id) {
|
|
381
|
-
const
|
|
382
|
-
if (
|
|
383
|
-
this.applyAssessmentResult(s.id,
|
|
572
|
+
const n = typeof ((r = s.data) == null ? void 0 : r.passingScore) == "number" ? Number(s.data.passingScore) : this.getAssessmentPassingScore(s.id), o = ((a = s.data) == null ? void 0 : a.score) != null ? Number(s.data.score) : void 0;
|
|
573
|
+
if (o != null && !Number.isNaN(o)) {
|
|
574
|
+
this.applyAssessmentResult(s.id, o, n), (t == null ? void 0 : t.persist) !== !1 && (this.updateCompletion(), this.persist());
|
|
384
575
|
return;
|
|
385
576
|
}
|
|
386
577
|
}
|
|
387
|
-
(
|
|
578
|
+
(t == null ? void 0 : t.persist) !== !1 && this.persist();
|
|
388
579
|
}
|
|
389
|
-
applyAssessmentResult(s,
|
|
390
|
-
this.progress.assessmentScores[s] =
|
|
580
|
+
applyAssessmentResult(s, t, r) {
|
|
581
|
+
this.progress.assessmentScores[s] = t, this.progress.suspendData[`assessment_passing_${s}`] = r, t >= r ? this.passedAssessments.add(s) : this.passedAssessments.delete(s);
|
|
391
582
|
}
|
|
392
|
-
submitAssessment(s,
|
|
393
|
-
this.applyAssessmentResult(s,
|
|
583
|
+
submitAssessment(s, t, r) {
|
|
584
|
+
this.applyAssessmentResult(s, t, r), this.updateCompletion(), this.persist();
|
|
394
585
|
}
|
|
395
586
|
completeLesson(s) {
|
|
396
587
|
new Set(this.manifest.lessons.map((r) => r.id)).has(s) && (this.progress.completedLessons.includes(s) || this.progress.completedLessons.push(s), this.updateCompletion(), this.persist());
|
|
397
588
|
}
|
|
398
589
|
setCurrentLesson(s) {
|
|
399
|
-
this.progress.currentLessonId = s, this.scorm && this.scorm.setLessonLocation(s), this.persist();
|
|
590
|
+
this.progress.currentLessonId = s, this.scorm && this.scorm.setLessonLocation(s), this.scorm2004 && this.scorm2004.setLocation(s), this.persist();
|
|
400
591
|
}
|
|
401
592
|
getProgress() {
|
|
402
593
|
return this.getAPI().getProgress();
|
|
@@ -411,53 +602,59 @@ class y {
|
|
|
411
602
|
return this.passedAssessments.has(s);
|
|
412
603
|
}
|
|
413
604
|
getTotalUnits() {
|
|
414
|
-
var
|
|
415
|
-
const s = ((
|
|
605
|
+
var t;
|
|
606
|
+
const s = ((t = this.manifest.assessments) == null ? void 0 : t.length) ?? 0;
|
|
416
607
|
return this.manifest.lessons.length + s;
|
|
417
608
|
}
|
|
418
609
|
getCompletionRatio() {
|
|
419
|
-
var
|
|
610
|
+
var o;
|
|
420
611
|
if (this.getTotalUnits() === 0) return 0;
|
|
421
|
-
const
|
|
422
|
-
(
|
|
423
|
-
).length,
|
|
424
|
-
return (a +
|
|
612
|
+
const t = this.manifest.lessons.length, r = ((o = this.manifest.assessments) == null ? void 0 : o.length) ?? 0, a = this.progress.completedLessons.filter(
|
|
613
|
+
(c) => this.manifest.lessons.some((h) => h.id === c)
|
|
614
|
+
).length, n = this.passedAssessments.size;
|
|
615
|
+
return (a + n) / (t + r);
|
|
425
616
|
}
|
|
426
617
|
updateCompletion() {
|
|
427
|
-
var
|
|
428
|
-
const s = this.getCompletionRatio(),
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
((
|
|
435
|
-
|
|
436
|
-
)) ? this.scorm.setLessonStatus("failed") : s >= this.completionThreshold && n && l ? this.scorm.setLessonStatus(
|
|
437
|
-
(((o = this.manifest.assessments) == null ? void 0 : o.length) ?? 0) > 0 ? "passed" : "completed"
|
|
438
|
-
) : e > 0 && this.scorm.setLessonStatus("incomplete");
|
|
439
|
-
}
|
|
618
|
+
var o, c, h;
|
|
619
|
+
const s = this.getCompletionRatio(), t = Math.round(s * 100), r = this.manifest.lessons.every(
|
|
620
|
+
(l) => this.progress.completedLessons.includes(l.id)
|
|
621
|
+
), a = !((o = this.manifest.assessments) != null && o.length) || this.manifest.assessments.every((l) => this.passedAssessments.has(l.id)), n = (c = this.manifest.assessments) == null ? void 0 : c.some(
|
|
622
|
+
(l) => l.id in this.progress.assessmentScores && !this.passedAssessments.has(l.id)
|
|
623
|
+
);
|
|
624
|
+
this.scorm && (this.scorm.setScore(t), n ? this.scorm.setLessonStatus("failed") : s >= this.completionThreshold && r && a ? this.scorm.setLessonStatus(
|
|
625
|
+
(((h = this.manifest.assessments) == null ? void 0 : h.length) ?? 0) > 0 ? "passed" : "completed"
|
|
626
|
+
) : t > 0 && this.scorm.setLessonStatus("incomplete")), this.scorm2004 && (this.scorm2004.setScoreScaled(s), n ? (this.scorm2004.setSuccessStatus("failed"), this.scorm2004.setCompletionStatus("completed")) : s >= this.completionThreshold && r && a ? (this.scorm2004.setSuccessStatus("passed"), this.scorm2004.setCompletionStatus("completed")) : s > 0 && (this.scorm2004.setCompletionStatus("incomplete"), this.scorm2004.setSuccessStatus("unknown")));
|
|
440
627
|
}
|
|
441
628
|
persist() {
|
|
442
|
-
const s =
|
|
629
|
+
const s = P(this.progress);
|
|
443
630
|
if (this.mode === "preview" || this.mode === "standalone")
|
|
444
631
|
try {
|
|
445
632
|
localStorage.setItem(this.storageKey, s);
|
|
446
633
|
} catch {
|
|
447
634
|
}
|
|
448
|
-
this.scorm && (this.scorm.setSuspendData(s), this.scorm.LMSCommit());
|
|
635
|
+
this.scorm && (this.scorm.setSuspendData(s), this.scorm.LMSCommit()), this.scorm2004 && (this.scorm2004.setSuspendData(s), this.scorm2004.Commit());
|
|
636
|
+
}
|
|
637
|
+
getFlowContext() {
|
|
638
|
+
return {
|
|
639
|
+
getVariable: (s) => _(this.progress.suspendData, s),
|
|
640
|
+
isAssessmentPassed: (s) => this.isAssessmentPassed(s),
|
|
641
|
+
isInteractionDone: (s) => this.progress.suspendData[`interaction_${s}`] !== void 0
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
resolveFlowNavigation() {
|
|
645
|
+
return G(this.manifest, this.getFlowContext());
|
|
449
646
|
}
|
|
450
647
|
terminate() {
|
|
451
|
-
this.terminated || (this.terminated = !0, this.scorm && this.scorm.LMSFinish());
|
|
648
|
+
this.terminated || (this.terminated = !0, this.scorm && this.scorm.LMSFinish(), this.scorm2004 && this.scorm2004.Terminate());
|
|
452
649
|
}
|
|
453
650
|
}
|
|
454
651
|
export {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
652
|
+
U as LxpackRuntime,
|
|
653
|
+
F as Scorm12API,
|
|
654
|
+
A as Scorm12Adapter,
|
|
655
|
+
u as Scorm12Simulator,
|
|
656
|
+
L as createScormConnection,
|
|
657
|
+
M as findLmsApi,
|
|
658
|
+
j as installScormAPI,
|
|
659
|
+
d as trimSuspendData
|
|
463
660
|
};
|