@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/dist/runtime.js CHANGED
@@ -1,33 +1,37 @@
1
- var F = Object.defineProperty;
2
- var T = (t, s, e) => s in t ? F(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
3
- var a = (t, s, e) => T(t, typeof s != "symbol" ? s + "" : s, e);
4
- import { p as f, s as N } from "./size-policy-BE1zjEBP.js";
5
- import { S as Y } from "./size-policy-BE1zjEBP.js";
6
- import { createScormConnection as V } from "./scorm12.js";
7
- import { Scorm12API as ss, Scorm12Adapter as es, Scorm12Simulator as ts, findLmsApi as ns, installScormAPI as is, trimSuspendData as rs } from "./scorm12.js";
8
- import { createScorm2004Connection as v } from "./scorm2004.js";
9
- const I = "v:";
10
- function g(t) {
11
- return `${I}${t}`;
12
- }
13
- function y(t, s) {
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 = g(e);
16
+ const i = C(e);
16
17
  s[i] === void 0 && (s[i] = n.default);
17
18
  }
18
19
  }
19
- function _(t, s) {
20
- return t[g(s)];
20
+ function T(t, s) {
21
+ return t[C(s)];
21
22
  }
22
- function $(t, s, e) {
23
- t[g(s)] = e;
23
+ function X(t, s, e) {
24
+ t[C(s)] = e;
24
25
  }
25
- const G = [
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 [n, i] = t.variable.eq;
30
- return s.getVariable(n) === i;
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) => d(e, s)) : null,
43
- (t, s) => "any" in t && t.any ? t.any.some((e) => d(e, s)) : null
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 d(t, s) {
46
- for (const e of G) {
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 k(t, s) {
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 (d(n.when, s))
61
+ if (v(n.when, s))
58
62
  return n.goto;
59
63
  return null;
60
64
  }
61
- const R = {
65
+ const W = {
62
66
  maxAttempts: 1
63
67
  };
64
- class B {
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: c } = f(e, s);
75
- if (c) return i;
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 E {
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: c } = f(e, s);
108
- if (c) return i;
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 D {
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 } = f(e, s);
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 K(t, s) {
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 O(t, s) {
166
- return t === "scorm12" ? new B(V("scorm12")) : t === "scorm2004" ? new E(v("scorm2004")) : t === "preview" || t === "standalone" ? new D(s) : new D(s);
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 A(t, s) {
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 z(t, s) {
174
- const e = A(t, s) + 1;
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 j {
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 z(this.progress.suspendData, s);
200
+ return Y(this.progress.suspendData, s);
197
201
  }
198
202
  getAssessmentAttemptCount(s) {
199
- return A(this.progress.suspendData, s);
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 x(t, s) {
218
- var S, L, C, P;
219
- const { manifest: e, completionThreshold: n, passedAssessments: i } = s, c = e.lessons.length, r = ((S = e.assessments) == null ? void 0 : S.length) ?? 0, m = c + r, l = t.completedLessons.filter(
220
- (o) => e.lessons.some((h) => h.id === o)
221
- ).length, u = m === 0 ? 0 : (l + i.size) / m, p = e.lessons.every(
222
- (o) => t.completedLessons.includes(o.id)
223
- ), M = !((L = e.assessments) != null && L.length) || e.assessments.every((o) => i.has(o.id)), w = (C = e.assessments) == null ? void 0 : C.some((o) => {
224
- var b;
225
- if (!(o.id in t.assessmentScores) || i.has(o.id)) return !1;
226
- const h = ((b = s.assessmentConfigs[o.id]) == null ? void 0 : b.maxAttempts) ?? 1;
227
- return A(t.suspendData, o.id) >= h;
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: u,
231
- scorePercent: Math.round(u * 100),
232
- allLessonsComplete: p,
233
- allAssessmentsPassed: M,
234
- anyAssessmentFailed: !!w,
235
- hasAssessments: (((P = e.assessments) == null ? void 0 : P.length) ?? 0) > 0,
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 J {
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, m, l;
249
- this.manifest = s.manifest, this.completionThreshold = ((m = (r = s.manifest.tracking) == null ? void 0 : r.completion) == null ? void 0 : m.threshold) ?? 0.9;
250
- const e = K(
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 = O(s.mode, e), this.defaultPassingScores = {};
255
- for (const [u, p] of Object.entries(s.assessments ?? {}))
256
- this.defaultPassingScores[u] = p.passingScore;
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 ?? ((l = s.manifest.lessons[0]) == null ? void 0 : l.id) ?? "", i = s.progress ?? {
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
- y(this.manifest, i.suspendData), this.bridge.init();
265
- const c = this.bridge.restoreProgress(i);
266
- this.state = new j(
267
- c,
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
- ), y(this.manifest, this.state.progress.suspendData), this.state.syncPassedAssessments(), s.activityId && this.state.setCurrentLesson(s.activityId);
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 ? $(this.state.progress.suspendData, s, e) : this.state.progress.suspendData[s] = e, this.persist();
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 ? _(this.state.progress.suspendData, s) : this.state.progress.suspendData[s],
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)), s.type === "assessment" && s.id) {
287
- const c = 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;
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, c);
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
- this.canAcceptAssessmentSubmission(s) && (this.state.recordAssessmentAttempt(s), this.state.applyAssessmentResult(s, e, n), this.updateCompletion(), this.persist());
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) ?? R.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 x(this.state.progress, {
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 = x(this.state.progress, {
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 = N(this.state.progress);
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) => _(this.state.progress.suspendData, 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) => this.state.progress.suspendData[`interaction_${s}`] !== void 0
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 k(this.manifest, this.getFlowContext());
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
- J as LxpackRuntime,
382
- Y as SCORM_SUSPEND_DATA_MAX,
383
- ss as Scorm12API,
384
- es as Scorm12Adapter,
385
- ts as Scorm12Simulator,
386
- V as createScormConnection,
387
- ns as findLmsApi,
388
- is as installScormAPI,
389
- rs as trimSuspendData
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
  };