@lxpack/runtime 0.2.2 → 0.3.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 +1 -1
- package/dist/analytics/factory.d.ts +4 -0
- package/dist/analytics/factory.d.ts.map +1 -0
- package/dist/analytics/noop.d.ts +10 -0
- package/dist/analytics/noop.d.ts.map +1 -0
- package/dist/analytics/reporter.d.ts +9 -0
- package/dist/analytics/reporter.d.ts.map +1 -0
- package/dist/analytics/xapi-reporter.d.ts +23 -0
- package/dist/analytics/xapi-reporter.d.ts.map +1 -0
- package/dist/client.js +2722 -1698
- package/dist/flow-conditions.d.ts +1 -0
- package/dist/flow-conditions.d.ts.map +1 -1
- package/dist/flow.d.ts +1 -0
- package/dist/flow.d.ts.map +1 -1
- package/dist/lms/factory.d.ts +2 -2
- package/dist/lms/factory.d.ts.map +1 -1
- package/dist/progress/size-policy.d.ts.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +429 -101
- package/dist/scorm-api.d.ts +4 -1
- package/dist/scorm-api.d.ts.map +1 -1
- package/dist/scorm12.js +2 -2
- package/dist/scorm2004-api.d.ts +1 -0
- package/dist/scorm2004-api.d.ts.map +1 -1
- package/dist/scorm2004.d.ts +1 -1
- package/dist/scorm2004.d.ts.map +1 -1
- package/dist/scorm2004.js +18 -7
- package/dist/{size-policy-BE1zjEBP.js → size-policy-DIyTdXTZ.js} +45 -39
- package/dist/types.d.ts +10 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -2
package/dist/runtime.js
CHANGED
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var a = (t, s, e) =>
|
|
4
|
-
import { p as
|
|
5
|
-
import { S as
|
|
6
|
-
import { createScormConnection as
|
|
7
|
-
import { Scorm12API as
|
|
8
|
-
import { createScorm2004Connection as
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
1
|
+
var V = Object.defineProperty;
|
|
2
|
+
var M = (t, s, e) => s in t ? V(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
|
|
3
|
+
var a = (t, s, e) => M(t, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
import { p as P, s as U } from "./size-policy-DIyTdXTZ.js";
|
|
5
|
+
import { S as ks } from "./size-policy-DIyTdXTZ.js";
|
|
6
|
+
import { createScormConnection as F, installScormAPI as B } from "./scorm12.js";
|
|
7
|
+
import { Scorm12API as $s, Scorm12Adapter as Rs, Scorm12Simulator as Vs, findLmsApi as Ms, trimSuspendData as Us } from "./scorm12.js";
|
|
8
|
+
import { createScorm2004Connection as j, installScorm2004API as O } from "./scorm2004.js";
|
|
9
|
+
import { enumerateActivities as q } from "@lxpack/validators";
|
|
10
|
+
const G = "v:";
|
|
11
|
+
function C(t) {
|
|
12
|
+
return `${G}${t}`;
|
|
13
|
+
}
|
|
14
|
+
function x(t, s) {
|
|
14
15
|
for (const [e, n] of Object.entries(t.variables ?? {})) {
|
|
15
|
-
const i =
|
|
16
|
+
const i = C(e);
|
|
16
17
|
s[i] === void 0 && (s[i] = n.default);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
return t[
|
|
20
|
+
function T(t, s) {
|
|
21
|
+
return t[C(s)];
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
-
t[
|
|
23
|
+
function X(t, s, e) {
|
|
24
|
+
t[C(s)] = e;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
function z(t, s, e) {
|
|
27
|
+
return e === "number" ? Number(t) === Number(s) : e === "boolean" ? !!t == !!s : e === "string" ? String(t) === String(s) : t === s;
|
|
28
|
+
}
|
|
29
|
+
const J = [
|
|
26
30
|
(t, s) => {
|
|
27
|
-
var e;
|
|
31
|
+
var e, n;
|
|
28
32
|
if ("variable" in t && ((e = t.variable) != null && e.eq)) {
|
|
29
|
-
const [
|
|
30
|
-
return s.getVariable(
|
|
33
|
+
const [i, o] = t.variable.eq, r = (n = s.getVariableType) == null ? void 0 : n.call(s, i);
|
|
34
|
+
return z(s.getVariable(i), o, r);
|
|
31
35
|
}
|
|
32
36
|
return null;
|
|
33
37
|
},
|
|
@@ -39,29 +43,29 @@ const G = [
|
|
|
39
43
|
var e;
|
|
40
44
|
return "interaction" in t && ((e = t.interaction) != null && e.done) ? s.isInteractionDone(t.interaction.done) : null;
|
|
41
45
|
},
|
|
42
|
-
(t, s) => "all" in t && t.all ? t.all.every((e) =>
|
|
43
|
-
(t, s) => "any" in t && t.any ? t.any.some((e) =>
|
|
46
|
+
(t, s) => "all" in t && t.all ? t.all.every((e) => v(e, s)) : null,
|
|
47
|
+
(t, s) => "any" in t && t.any ? t.any.some((e) => v(e, s)) : null
|
|
44
48
|
];
|
|
45
|
-
function
|
|
46
|
-
for (const e of
|
|
49
|
+
function v(t, s) {
|
|
50
|
+
for (const e of J) {
|
|
47
51
|
const n = e(t, s);
|
|
48
52
|
if (n !== null)
|
|
49
53
|
return n;
|
|
50
54
|
}
|
|
51
55
|
return !1;
|
|
52
56
|
}
|
|
53
|
-
function
|
|
57
|
+
function K(t, s) {
|
|
54
58
|
const e = t.flow;
|
|
55
59
|
if (!(e != null && e.length)) return null;
|
|
56
60
|
for (const n of e)
|
|
57
|
-
if (
|
|
61
|
+
if (v(n.when, s))
|
|
58
62
|
return n.goto;
|
|
59
63
|
return null;
|
|
60
64
|
}
|
|
61
|
-
const
|
|
65
|
+
const W = {
|
|
62
66
|
maxAttempts: 1
|
|
63
67
|
};
|
|
64
|
-
class
|
|
68
|
+
class D {
|
|
65
69
|
constructor(s) {
|
|
66
70
|
this.connection = s;
|
|
67
71
|
}
|
|
@@ -71,8 +75,8 @@ class B {
|
|
|
71
75
|
restoreProgress(s) {
|
|
72
76
|
const e = this.connection.LMSGetValue("cmi.suspend_data");
|
|
73
77
|
if (e) {
|
|
74
|
-
const { progress: i, parsed:
|
|
75
|
-
if (
|
|
78
|
+
const { progress: i, parsed: o } = P(e, s);
|
|
79
|
+
if (o) return i;
|
|
76
80
|
const r = this.connection.LMSGetValue("cmi.core.lesson_location");
|
|
77
81
|
return r ? { ...s, currentLessonId: r } : s;
|
|
78
82
|
}
|
|
@@ -94,7 +98,7 @@ class B {
|
|
|
94
98
|
this.connection.LMSFinish();
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
|
-
class
|
|
101
|
+
class k {
|
|
98
102
|
constructor(s) {
|
|
99
103
|
this.connection = s;
|
|
100
104
|
}
|
|
@@ -104,8 +108,8 @@ class E {
|
|
|
104
108
|
restoreProgress(s) {
|
|
105
109
|
const e = this.connection.GetValue("cmi.suspend_data");
|
|
106
110
|
if (e) {
|
|
107
|
-
const { progress: i, parsed:
|
|
108
|
-
if (
|
|
111
|
+
const { progress: i, parsed: o } = P(e, s);
|
|
112
|
+
if (o) return i;
|
|
109
113
|
const r = this.connection.GetValue("cmi.location");
|
|
110
114
|
return r ? { ...s, currentLessonId: r } : s;
|
|
111
115
|
}
|
|
@@ -125,7 +129,7 @@ class E {
|
|
|
125
129
|
this.connection.Terminate();
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
|
-
class
|
|
132
|
+
class L {
|
|
129
133
|
constructor(s) {
|
|
130
134
|
this.storageKey = s;
|
|
131
135
|
}
|
|
@@ -135,7 +139,7 @@ class D {
|
|
|
135
139
|
try {
|
|
136
140
|
const e = localStorage.getItem(this.storageKey);
|
|
137
141
|
if (e) {
|
|
138
|
-
const { progress: n, parsed: i } =
|
|
142
|
+
const { progress: n, parsed: i } = P(e, s);
|
|
139
143
|
if (i) return n;
|
|
140
144
|
}
|
|
141
145
|
} catch {
|
|
@@ -155,26 +159,26 @@ class D {
|
|
|
155
159
|
terminate() {
|
|
156
160
|
}
|
|
157
161
|
}
|
|
158
|
-
function
|
|
162
|
+
function H(t, s) {
|
|
159
163
|
const e = `${t}::${s}`;
|
|
160
164
|
let n = 0;
|
|
161
165
|
for (let i = 0; i < e.length; i++)
|
|
162
166
|
n = (n << 5) - n + e.charCodeAt(i), n |= 0;
|
|
163
167
|
return `lxpack_progress_${Math.abs(n)}`;
|
|
164
168
|
}
|
|
165
|
-
function
|
|
166
|
-
return t === "scorm12" ? new
|
|
169
|
+
function Q(t, s, e = "local") {
|
|
170
|
+
return t === "scorm12" ? new D(F("scorm12")) : t === "scorm2004" ? new k(j("scorm2004")) : t === "preview" ? e === "scorm12" ? new D(B("preview")) : e === "scorm2004" ? new k(O("preview")) : new L(s) : t === "standalone" || t === "xapi" || t === "cmi5" ? new L(s) : new L(s);
|
|
167
171
|
}
|
|
168
|
-
function
|
|
172
|
+
function w(t, s) {
|
|
169
173
|
const e = t[`assessment_attempts_${s}`];
|
|
170
174
|
let n = 0;
|
|
171
175
|
return typeof e == "number" ? n = e : typeof e == "string" && e !== "" && !Number.isNaN(Number(e)) && (n = Number(e)), !Number.isFinite(n) || n < 0 ? 0 : Math.floor(n);
|
|
172
176
|
}
|
|
173
|
-
function
|
|
174
|
-
const e =
|
|
177
|
+
function Y(t, s) {
|
|
178
|
+
const e = w(t, s) + 1;
|
|
175
179
|
return t[`assessment_attempts_${s}`] = e, e;
|
|
176
180
|
}
|
|
177
|
-
class
|
|
181
|
+
class Z {
|
|
178
182
|
constructor(s, e, n) {
|
|
179
183
|
a(this, "progress");
|
|
180
184
|
a(this, "passedAssessments", /* @__PURE__ */ new Set());
|
|
@@ -193,10 +197,10 @@ class j {
|
|
|
193
197
|
this.progress.assessmentScores[s] = e, this.progress.suspendData[`assessment_passing_${s}`] = n, e >= n ? this.passedAssessments.add(s) : this.passedAssessments.delete(s);
|
|
194
198
|
}
|
|
195
199
|
recordAssessmentAttempt(s) {
|
|
196
|
-
return
|
|
200
|
+
return Y(this.progress.suspendData, s);
|
|
197
201
|
}
|
|
198
202
|
getAssessmentAttemptCount(s) {
|
|
199
|
-
return
|
|
203
|
+
return w(this.progress.suspendData, s);
|
|
200
204
|
}
|
|
201
205
|
completeLesson(s) {
|
|
202
206
|
new Set(this.manifest.lessons.map((n) => n.id)).has(s) && (this.progress.completedLessons.includes(s) || this.progress.completedLessons.push(s));
|
|
@@ -214,60 +218,367 @@ class j {
|
|
|
214
218
|
return this.getAssessmentPassingScore(s);
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
|
-
function
|
|
218
|
-
var
|
|
219
|
-
const { manifest: e, completionThreshold: n, passedAssessments: i } = s,
|
|
220
|
-
(
|
|
221
|
-
).length,
|
|
222
|
-
(
|
|
223
|
-
),
|
|
224
|
-
var
|
|
225
|
-
if (!(
|
|
226
|
-
const
|
|
227
|
-
return
|
|
221
|
+
function N(t, s) {
|
|
222
|
+
var h, d, _, E;
|
|
223
|
+
const { manifest: e, completionThreshold: n, passedAssessments: i } = s, o = e.lessons.length, r = ((h = e.assessments) == null ? void 0 : h.length) ?? 0, l = o + r, c = t.completedLessons.filter(
|
|
224
|
+
(p) => e.lessons.some((b) => b.id === p)
|
|
225
|
+
).length, m = l === 0 ? 0 : (c + i.size) / l, g = e.lessons.every(
|
|
226
|
+
(p) => t.completedLessons.includes(p.id)
|
|
227
|
+
), y = !((d = e.assessments) != null && d.length) || e.assessments.every((p) => i.has(p.id)), u = (_ = e.assessments) == null ? void 0 : _.some((p) => {
|
|
228
|
+
var I;
|
|
229
|
+
if (!(p.id in t.assessmentScores) || i.has(p.id)) return !1;
|
|
230
|
+
const b = ((I = s.assessmentConfigs[p.id]) == null ? void 0 : I.maxAttempts) ?? 1;
|
|
231
|
+
return w(t.suspendData, p.id) >= b;
|
|
228
232
|
});
|
|
229
233
|
return {
|
|
230
|
-
ratio:
|
|
231
|
-
scorePercent: Math.round(
|
|
232
|
-
allLessonsComplete:
|
|
233
|
-
allAssessmentsPassed:
|
|
234
|
-
anyAssessmentFailed: !!
|
|
235
|
-
hasAssessments: (((
|
|
234
|
+
ratio: m,
|
|
235
|
+
scorePercent: Math.round(m * 100),
|
|
236
|
+
allLessonsComplete: g,
|
|
237
|
+
allAssessmentsPassed: y,
|
|
238
|
+
anyAssessmentFailed: !!u,
|
|
239
|
+
hasAssessments: (((E = e.assessments) == null ? void 0 : E.length) ?? 0) > 0,
|
|
236
240
|
completionThreshold: n
|
|
237
241
|
};
|
|
238
242
|
}
|
|
239
|
-
class
|
|
243
|
+
class ss {
|
|
244
|
+
onLaunched() {
|
|
245
|
+
}
|
|
246
|
+
onExperienced(s) {
|
|
247
|
+
}
|
|
248
|
+
onInteraction(s, e) {
|
|
249
|
+
}
|
|
250
|
+
onAssessmentSubmitted(s, e, n) {
|
|
251
|
+
}
|
|
252
|
+
onLessonCompleted(s) {
|
|
253
|
+
}
|
|
254
|
+
onTerminated() {
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
var f = "http://adlnet.gov/expapi/verbs", es = {
|
|
258
|
+
id: `${f}/launched`,
|
|
259
|
+
display: { "en-US": "launched" }
|
|
260
|
+
}, ts = {
|
|
261
|
+
id: `${f}/experienced`,
|
|
262
|
+
display: { "en-US": "experienced" }
|
|
263
|
+
}, ns = {
|
|
264
|
+
id: `${f}/answered`,
|
|
265
|
+
display: { "en-US": "answered" }
|
|
266
|
+
}, is = {
|
|
267
|
+
id: `${f}/completed`,
|
|
268
|
+
display: { "en-US": "completed" }
|
|
269
|
+
}, os = {
|
|
270
|
+
id: `${f}/passed`,
|
|
271
|
+
display: { "en-US": "passed" }
|
|
272
|
+
}, rs = {
|
|
273
|
+
id: `${f}/failed`,
|
|
274
|
+
display: { "en-US": "failed" }
|
|
275
|
+
}, as = {
|
|
276
|
+
id: `${f}/interacted`,
|
|
277
|
+
display: { "en-US": "interacted" }
|
|
278
|
+
};
|
|
279
|
+
function cs(t, s) {
|
|
280
|
+
return `${t.replace(/\/$/, "")}/activities/${s}`;
|
|
281
|
+
}
|
|
282
|
+
function R(t, s) {
|
|
283
|
+
return {
|
|
284
|
+
objectType: "Activity",
|
|
285
|
+
id: t,
|
|
286
|
+
definition: {
|
|
287
|
+
name: { "en-US": s },
|
|
288
|
+
type: "http://adlnet.gov/expapi/activities/course"
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function A(t, s) {
|
|
293
|
+
const e = s.kind === "assessment" ? "http://adlnet.gov/expapi/activities/assessment" : "http://adlnet.gov/expapi/activities/module";
|
|
294
|
+
return {
|
|
295
|
+
objectType: "Activity",
|
|
296
|
+
id: cs(t, s.id),
|
|
297
|
+
definition: {
|
|
298
|
+
name: { "en-US": s.title },
|
|
299
|
+
type: e
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function ls() {
|
|
304
|
+
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `urn:uuid:${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
305
|
+
}
|
|
306
|
+
function S(t, s, e, n) {
|
|
307
|
+
const i = {
|
|
308
|
+
registration: t.registration,
|
|
309
|
+
contextActivities: {
|
|
310
|
+
parent: [R(t.courseIri, t.courseTitle)]
|
|
311
|
+
},
|
|
312
|
+
...n == null ? void 0 : n.context
|
|
313
|
+
};
|
|
314
|
+
return {
|
|
315
|
+
id: ls(),
|
|
316
|
+
actor: t.actor,
|
|
317
|
+
verb: s,
|
|
318
|
+
object: e,
|
|
319
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
320
|
+
...n,
|
|
321
|
+
context: i
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function us(t) {
|
|
325
|
+
return S(
|
|
326
|
+
t,
|
|
327
|
+
es,
|
|
328
|
+
R(t.courseIri, t.courseTitle)
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
function ms(t, s) {
|
|
332
|
+
return S(t, ts, A(t.courseIri, s));
|
|
333
|
+
}
|
|
334
|
+
function ps(t, s) {
|
|
335
|
+
return S(t, is, A(t.courseIri, s), {
|
|
336
|
+
result: { completion: !0 }
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
function hs(t, s, e, n) {
|
|
340
|
+
return S(t, ns, A(t.courseIri, s), {
|
|
341
|
+
result: {
|
|
342
|
+
score: { scaled: Math.max(0, Math.min(1, e)) },
|
|
343
|
+
success: n,
|
|
344
|
+
completion: !0
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
function ds(t, s, e) {
|
|
349
|
+
return S(
|
|
350
|
+
t,
|
|
351
|
+
e ? os : rs,
|
|
352
|
+
A(t.courseIri, s),
|
|
353
|
+
{ result: { success: e, completion: !0 } }
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
function $(t, s, e) {
|
|
357
|
+
const n = {
|
|
358
|
+
id: s,
|
|
359
|
+
title: s,
|
|
360
|
+
kind: "lesson"
|
|
361
|
+
}, i = {};
|
|
362
|
+
if ((e == null ? void 0 : e.simulation) != null && typeof e.simulation == "object")
|
|
363
|
+
i["https://lxpack.dev/xapi/extensions/simulation"] = e.simulation;
|
|
364
|
+
else if (e != null)
|
|
365
|
+
for (const [o, r] of Object.entries(e))
|
|
366
|
+
o !== "type" && o !== "simulation" && (i[o] = r);
|
|
367
|
+
return S(t, as, A(t.courseIri, n), {
|
|
368
|
+
result: Object.keys(i).length ? { extensions: i } : void 0
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
function fs(t) {
|
|
372
|
+
try {
|
|
373
|
+
const s = decodeURIComponent(t), e = JSON.parse(s);
|
|
374
|
+
if (e && typeof e == "object") return e;
|
|
375
|
+
} catch {
|
|
376
|
+
try {
|
|
377
|
+
const s = atob(t.replace(/-/g, "+").replace(/_/g, "/")), e = JSON.parse(s);
|
|
378
|
+
if (e && typeof e == "object") return e;
|
|
379
|
+
} catch {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function gs(t, s = "") {
|
|
385
|
+
const e = new URLSearchParams(t || s.replace(/^#/, "")), n = e.get("endpoint") ?? void 0, i = e.get("auth") ?? void 0, o = e.get("registration") ?? void 0, r = e.get("activityId") ?? void 0, l = e.get("fetch") ?? void 0;
|
|
386
|
+
let c;
|
|
387
|
+
const m = e.get("actor");
|
|
388
|
+
return m && (c = fs(m)), {
|
|
389
|
+
endpoint: n ?? void 0,
|
|
390
|
+
auth: i ?? void 0,
|
|
391
|
+
actor: c,
|
|
392
|
+
registration: o ?? void 0,
|
|
393
|
+
activityId: r ?? void 0,
|
|
394
|
+
fetch: l ?? void 0
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
function Ss() {
|
|
398
|
+
const t = globalThis.location;
|
|
399
|
+
return t ? gs(t.search, t.hash) : {};
|
|
400
|
+
}
|
|
401
|
+
function As() {
|
|
402
|
+
return {
|
|
403
|
+
objectType: "Agent",
|
|
404
|
+
name: "LXPack Preview Learner",
|
|
405
|
+
mbox: "mailto:preview@lxpack.local"
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
var ys = class {
|
|
409
|
+
constructor(t) {
|
|
410
|
+
a(this, "options");
|
|
411
|
+
a(this, "queue", []);
|
|
412
|
+
a(this, "flushing", !1);
|
|
413
|
+
this.options = t;
|
|
414
|
+
}
|
|
415
|
+
enqueue(t) {
|
|
416
|
+
var s, e, n;
|
|
417
|
+
(e = (s = this.options).onStatement) == null || e.call(s, t), !(this.options.mock || !((n = this.options.credentials) != null && n.endpoint)) && (this.queue.push(t), this.flush());
|
|
418
|
+
}
|
|
419
|
+
async flush() {
|
|
420
|
+
var s, e, n;
|
|
421
|
+
if (this.flushing || !((s = this.options.credentials) != null && s.endpoint)) return;
|
|
422
|
+
this.flushing = !0;
|
|
423
|
+
const t = bs(this.options.credentials.endpoint);
|
|
424
|
+
for (; this.queue.length > 0; ) {
|
|
425
|
+
const i = this.queue.shift();
|
|
426
|
+
try {
|
|
427
|
+
await Ls(t, this.options.credentials.auth, i);
|
|
428
|
+
} catch (o) {
|
|
429
|
+
this.queue.unshift(i), (n = (e = this.options).onError) == null || n.call(e, o, i);
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
this.flushing = !1;
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
function bs(t) {
|
|
437
|
+
const s = t.replace(/\/$/, "");
|
|
438
|
+
return s.endsWith("/statements") ? s : `${s}/statements`;
|
|
439
|
+
}
|
|
440
|
+
async function Ls(t, s, e) {
|
|
441
|
+
const n = {
|
|
442
|
+
"Content-Type": "application/json",
|
|
443
|
+
"X-Experience-API-Version": "1.0.3"
|
|
444
|
+
};
|
|
445
|
+
s && (n.Authorization = s.startsWith("Basic ") ? s : `Basic ${s}`);
|
|
446
|
+
const i = await fetch(t, {
|
|
447
|
+
method: "POST",
|
|
448
|
+
headers: n,
|
|
449
|
+
body: JSON.stringify(e)
|
|
450
|
+
});
|
|
451
|
+
if (!i.ok)
|
|
452
|
+
throw new Error(`LRS returned ${i.status}: ${await i.text()}`);
|
|
453
|
+
}
|
|
454
|
+
class vs {
|
|
455
|
+
constructor(s, e, n) {
|
|
456
|
+
a(this, "session");
|
|
457
|
+
a(this, "activities");
|
|
458
|
+
a(this, "queue");
|
|
459
|
+
a(this, "options");
|
|
460
|
+
a(this, "lastExperienced");
|
|
461
|
+
var r, l;
|
|
462
|
+
this.options = n;
|
|
463
|
+
const i = globalThis.location != null ? Ss() : {}, o = i.actor ?? As();
|
|
464
|
+
i.fetch && console.warn(
|
|
465
|
+
"[lxpack cmi5] Launch fetch URL is present but cmi5 session bootstrap via fetch is not implemented in v0.3.0"
|
|
466
|
+
), this.session = {
|
|
467
|
+
actor: o,
|
|
468
|
+
registration: i.registration,
|
|
469
|
+
courseIri: e,
|
|
470
|
+
courseTitle: ((l = (r = s.tracking) == null ? void 0 : r.xapi) == null ? void 0 : l.displayName) ?? s.title
|
|
471
|
+
}, this.activities = new Map(
|
|
472
|
+
q(s).map((c) => [c.id, c])
|
|
473
|
+
), this.queue = new ys({
|
|
474
|
+
mock: (n == null ? void 0 : n.mockLrs) ?? !i.endpoint,
|
|
475
|
+
credentials: i.endpoint ? { endpoint: i.endpoint, auth: i.auth } : void 0,
|
|
476
|
+
onError: (c) => {
|
|
477
|
+
console.warn("[lxpack xAPI] LRS error:", c);
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
emit(s) {
|
|
482
|
+
var e, n;
|
|
483
|
+
(n = (e = this.options) == null ? void 0 : e.onStatement) == null || n.call(e, s), this.queue.enqueue(s);
|
|
484
|
+
}
|
|
485
|
+
onLaunched() {
|
|
486
|
+
this.emit(us(this.session));
|
|
487
|
+
}
|
|
488
|
+
onExperienced(s) {
|
|
489
|
+
if (this.lastExperienced === s) return;
|
|
490
|
+
this.lastExperienced = s;
|
|
491
|
+
const e = this.activities.get(s);
|
|
492
|
+
e && this.emit(ms(this.session, e));
|
|
493
|
+
}
|
|
494
|
+
onInteraction(s, e) {
|
|
495
|
+
if (((e == null ? void 0 : e.simulation) != null || typeof (e == null ? void 0 : e.type) == "string" && e.type === "simulation") && (e != null && e.simulation) && typeof e.simulation == "object") {
|
|
496
|
+
this.emit(
|
|
497
|
+
$(this.session, s, {
|
|
498
|
+
simulation: e.simulation
|
|
499
|
+
})
|
|
500
|
+
);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
this.emit($(this.session, s, e));
|
|
504
|
+
}
|
|
505
|
+
onAssessmentSubmitted(s, e, n) {
|
|
506
|
+
const i = this.activities.get(s);
|
|
507
|
+
i && (this.emit(hs(this.session, i, e, n)), this.emit(ds(this.session, i, n)));
|
|
508
|
+
}
|
|
509
|
+
onLessonCompleted(s) {
|
|
510
|
+
const e = this.activities.get(s);
|
|
511
|
+
e && this.emit(ps(this.session, e));
|
|
512
|
+
}
|
|
513
|
+
onTerminated() {
|
|
514
|
+
this.queue.flush();
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function Ps(t) {
|
|
518
|
+
var l, c, m, g, y;
|
|
519
|
+
const s = t.activityIri ?? ((c = (l = t.manifest.tracking) == null ? void 0 : l.xapi) == null ? void 0 : c.activityIri);
|
|
520
|
+
if (!(t.mode === "xapi" || t.mode === "cmi5" || t.mode === "preview" && !!((m = t.xapi) != null && m.previewLog && s)) || !s)
|
|
521
|
+
return new ss();
|
|
522
|
+
const i = ((g = t.xapi) == null ? void 0 : g.previewLog) ?? t.mode === "preview" ? (u) => {
|
|
523
|
+
if (typeof console < "u" && console.debug && console.debug("[lxpack xAPI]", u.verb.id, u.object.id), typeof localStorage < "u")
|
|
524
|
+
try {
|
|
525
|
+
const h = "lxpack_xapi_preview_statements", d = JSON.parse(localStorage.getItem(h) ?? "[]");
|
|
526
|
+
d.push(u), localStorage.setItem(h, JSON.stringify(d.slice(-200)));
|
|
527
|
+
} catch {
|
|
528
|
+
}
|
|
529
|
+
} : void 0, o = new vs(t.manifest, s, {
|
|
530
|
+
mockLrs: ((y = t.xapi) == null ? void 0 : y.mockLrs) ?? t.mode === "preview",
|
|
531
|
+
onStatement: i
|
|
532
|
+
});
|
|
533
|
+
let r = !1;
|
|
534
|
+
return {
|
|
535
|
+
onLaunched: () => {
|
|
536
|
+
r || (r = !0, o.onLaunched());
|
|
537
|
+
},
|
|
538
|
+
onExperienced: (u) => o.onExperienced(u),
|
|
539
|
+
onInteraction: (u, h) => o.onInteraction(u, h),
|
|
540
|
+
onAssessmentSubmitted: (u, h, d) => o.onAssessmentSubmitted(u, h, d),
|
|
541
|
+
onLessonCompleted: (u) => o.onLessonCompleted(u),
|
|
542
|
+
onTerminated: () => o.onTerminated()
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
class xs {
|
|
240
546
|
constructor(s) {
|
|
241
547
|
a(this, "manifest");
|
|
242
548
|
a(this, "state");
|
|
243
549
|
a(this, "bridge");
|
|
550
|
+
a(this, "analytics");
|
|
244
551
|
a(this, "completionThreshold");
|
|
245
552
|
a(this, "assessmentConfigs");
|
|
246
553
|
a(this, "defaultPassingScores");
|
|
247
554
|
a(this, "terminated", !1);
|
|
248
|
-
var r,
|
|
249
|
-
this.manifest = s.manifest, this.completionThreshold = ((
|
|
250
|
-
const e =
|
|
555
|
+
var r, l, c;
|
|
556
|
+
this.manifest = s.manifest, this.completionThreshold = ((l = (r = s.manifest.tracking) == null ? void 0 : r.completion) == null ? void 0 : l.threshold) ?? 0.9;
|
|
557
|
+
const e = H(
|
|
251
558
|
s.manifest.title,
|
|
252
559
|
s.manifest.version
|
|
253
560
|
);
|
|
254
|
-
this.bridge =
|
|
255
|
-
|
|
256
|
-
|
|
561
|
+
this.bridge = Q(
|
|
562
|
+
s.mode,
|
|
563
|
+
e,
|
|
564
|
+
s.previewScormMode ?? "local"
|
|
565
|
+
), this.analytics = Ps(s), this.defaultPassingScores = {};
|
|
566
|
+
for (const [m, g] of Object.entries(s.assessments ?? {}))
|
|
567
|
+
this.defaultPassingScores[m] = g.passingScore;
|
|
257
568
|
this.assessmentConfigs = s.assessmentConfigs ?? {};
|
|
258
|
-
const n = s.activityId ?? ((
|
|
569
|
+
const n = s.activityId ?? ((c = s.manifest.lessons[0]) == null ? void 0 : c.id) ?? "", i = s.progress ?? {
|
|
259
570
|
currentLessonId: n,
|
|
260
571
|
completedLessons: [],
|
|
261
572
|
assessmentScores: {},
|
|
262
573
|
suspendData: {}
|
|
263
574
|
};
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
this.state = new
|
|
267
|
-
|
|
575
|
+
x(this.manifest, i.suspendData), this.bridge.init();
|
|
576
|
+
const o = this.bridge.restoreProgress(i);
|
|
577
|
+
this.state = new Z(
|
|
578
|
+
o,
|
|
268
579
|
this.manifest,
|
|
269
580
|
this.defaultPassingScores
|
|
270
|
-
),
|
|
581
|
+
), x(this.manifest, this.state.progress.suspendData), this.state.syncPassedAssessments(), s.activityId && this.state.setCurrentLesson(s.activityId), this.analytics.onLaunched(), this.analytics.onExperienced(this.state.progress.currentLessonId);
|
|
271
582
|
}
|
|
272
583
|
getAPI() {
|
|
273
584
|
return {
|
|
@@ -275,18 +586,24 @@ class J {
|
|
|
275
586
|
completeLesson: (s) => this.completeLesson(s),
|
|
276
587
|
getProgress: () => this.getProgress(),
|
|
277
588
|
setVariable: (s, e) => {
|
|
278
|
-
this.manifest.variables && s in this.manifest.variables ?
|
|
589
|
+
this.manifest.variables && s in this.manifest.variables ? X(this.state.progress.suspendData, s, e) : this.state.progress.suspendData[s] = e, this.persist();
|
|
279
590
|
},
|
|
280
|
-
getVariable: (s) => this.manifest.variables && s in this.manifest.variables ?
|
|
591
|
+
getVariable: (s) => this.manifest.variables && s in this.manifest.variables ? T(this.state.progress.suspendData, s) : this.state.progress.suspendData[s],
|
|
281
592
|
submitAssessment: (s, e, n) => this.submitAssessment(s, e, n)
|
|
282
593
|
};
|
|
283
594
|
}
|
|
284
595
|
track(s, e) {
|
|
285
596
|
var n, i;
|
|
286
|
-
if (s.type === "interaction" && s.id && (this.state.progress.suspendData[`interaction_${s.id}`] = s.data ?? !0, console.debug("[lxpack] interaction:", s.id, s.data)
|
|
287
|
-
|
|
597
|
+
if (s.type === "interaction" && s.id && (this.state.progress.suspendData[`interaction_${s.id}`] = s.data ?? !0, console.debug("[lxpack] interaction:", s.id, s.data), this.analytics.onInteraction(
|
|
598
|
+
s.id,
|
|
599
|
+
s.data
|
|
600
|
+
)), s.type === "simulation" && s.id && this.analytics.onInteraction(s.id, {
|
|
601
|
+
type: "simulation",
|
|
602
|
+
simulation: s.data ?? {}
|
|
603
|
+
}), s.type === "assessment" && s.id) {
|
|
604
|
+
const o = typeof ((n = s.data) == null ? void 0 : n.passingScore) == "number" ? Number(s.data.passingScore) : this.state.getAssessmentPassingScoreForTrack(s.id), r = ((i = s.data) == null ? void 0 : i.score) != null ? Number(s.data.score) : void 0;
|
|
288
605
|
if (r != null && !Number.isNaN(r)) {
|
|
289
|
-
this.submitAssessment(s.id, r,
|
|
606
|
+
this.submitAssessment(s.id, r, o);
|
|
290
607
|
return;
|
|
291
608
|
}
|
|
292
609
|
}
|
|
@@ -299,11 +616,15 @@ class J {
|
|
|
299
616
|
return this.state.getAssessmentAttemptCount(s);
|
|
300
617
|
}
|
|
301
618
|
submitAssessment(s, e, n) {
|
|
302
|
-
|
|
619
|
+
if (!this.canAcceptAssessmentSubmission(s))
|
|
620
|
+
return;
|
|
621
|
+
this.state.recordAssessmentAttempt(s), this.state.applyAssessmentResult(s, e, n);
|
|
622
|
+
const i = this.isAssessmentPassed(s);
|
|
623
|
+
this.analytics.onAssessmentSubmitted(s, e, i), this.updateCompletion(), this.persist();
|
|
303
624
|
}
|
|
304
625
|
getMaxAttempts(s) {
|
|
305
626
|
const e = this.assessmentConfigs[s];
|
|
306
|
-
return (e == null ? void 0 : e.maxAttempts) ??
|
|
627
|
+
return (e == null ? void 0 : e.maxAttempts) ?? W.maxAttempts;
|
|
307
628
|
}
|
|
308
629
|
canAcceptAssessmentSubmission(s) {
|
|
309
630
|
if (this.isAssessmentPassed(s))
|
|
@@ -312,10 +633,10 @@ class J {
|
|
|
312
633
|
return this.getAssessmentAttemptCount(s) < e;
|
|
313
634
|
}
|
|
314
635
|
completeLesson(s) {
|
|
315
|
-
this.state.completeLesson(s), this.updateCompletion(), this.persist();
|
|
636
|
+
this.state.completeLesson(s), this.analytics.onLessonCompleted(s), this.updateCompletion(), this.persist();
|
|
316
637
|
}
|
|
317
638
|
setCurrentLesson(s) {
|
|
318
|
-
this.state.setCurrentLesson(s), this.bridge.setLocation(s), this.persist();
|
|
639
|
+
this.state.setCurrentLesson(s), this.bridge.setLocation(s), this.analytics.onExperienced(s), this.persist();
|
|
319
640
|
}
|
|
320
641
|
getProgress() {
|
|
321
642
|
const s = this.state.progress;
|
|
@@ -341,7 +662,7 @@ class J {
|
|
|
341
662
|
return this.manifest.lessons.length + s;
|
|
342
663
|
}
|
|
343
664
|
getCompletionRatio() {
|
|
344
|
-
return
|
|
665
|
+
return N(this.state.progress, {
|
|
345
666
|
manifest: this.manifest,
|
|
346
667
|
completionThreshold: this.completionThreshold,
|
|
347
668
|
assessmentConfigs: this.assessmentConfigs,
|
|
@@ -350,7 +671,7 @@ class J {
|
|
|
350
671
|
}).ratio;
|
|
351
672
|
}
|
|
352
673
|
updateCompletion() {
|
|
353
|
-
const s =
|
|
674
|
+
const s = N(this.state.progress, {
|
|
354
675
|
manifest: this.manifest,
|
|
355
676
|
completionThreshold: this.completionThreshold,
|
|
356
677
|
assessmentConfigs: this.assessmentConfigs,
|
|
@@ -360,31 +681,38 @@ class J {
|
|
|
360
681
|
this.bridge.applyCompletion(s);
|
|
361
682
|
}
|
|
362
683
|
persist() {
|
|
363
|
-
const s =
|
|
684
|
+
const s = U(this.state.progress);
|
|
364
685
|
this.bridge.persist(this.state.progress, s);
|
|
365
686
|
}
|
|
366
687
|
getFlowContext() {
|
|
367
688
|
return {
|
|
368
|
-
getVariable: (s) =>
|
|
689
|
+
getVariable: (s) => T(this.state.progress.suspendData, s),
|
|
690
|
+
getVariableType: (s) => {
|
|
691
|
+
var e, n;
|
|
692
|
+
return (n = (e = this.manifest.variables) == null ? void 0 : e[s]) == null ? void 0 : n.type;
|
|
693
|
+
},
|
|
369
694
|
isAssessmentPassed: (s) => this.isAssessmentPassed(s),
|
|
370
|
-
isInteractionDone: (s) =>
|
|
695
|
+
isInteractionDone: (s) => {
|
|
696
|
+
const e = this.state.progress.suspendData[`interaction_${s}`];
|
|
697
|
+
return e !== void 0 && e !== !1 && e !== null;
|
|
698
|
+
}
|
|
371
699
|
};
|
|
372
700
|
}
|
|
373
701
|
resolveFlowNavigation() {
|
|
374
|
-
return
|
|
702
|
+
return K(this.manifest, this.getFlowContext());
|
|
375
703
|
}
|
|
376
704
|
terminate() {
|
|
377
|
-
this.terminated || (this.terminated = !0, this.bridge.terminate());
|
|
705
|
+
this.terminated || (this.terminated = !0, this.analytics.onTerminated(), this.bridge.terminate());
|
|
378
706
|
}
|
|
379
707
|
}
|
|
380
708
|
export {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
709
|
+
xs as LxpackRuntime,
|
|
710
|
+
ks as SCORM_SUSPEND_DATA_MAX,
|
|
711
|
+
$s as Scorm12API,
|
|
712
|
+
Rs as Scorm12Adapter,
|
|
713
|
+
Vs as Scorm12Simulator,
|
|
714
|
+
F as createScormConnection,
|
|
715
|
+
Ms as findLmsApi,
|
|
716
|
+
B as installScormAPI,
|
|
717
|
+
Us as trimSuspendData
|
|
390
718
|
};
|