@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/dist/runtime.js CHANGED
@@ -1,10 +1,10 @@
1
- var f = Object.defineProperty;
2
- var g = (t, s, e) => s in t ? f(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
3
- var i = (t, s, e) => g(t, typeof s != "symbol" ? s + "" : s, e);
4
- const S = "lxpack_scorm12_preview";
5
- function _(t = 500) {
6
- let s = window, e = 0;
7
- for (; s && e < t; ) {
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
- e++;
24
+ t++;
25
25
  }
26
26
  return null;
27
27
  }
28
- class L {
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, e) {
52
- return !this.initialized || this.terminated ? (this.lastError = "301", "false") : (this.lastError = "0", this.api.LMSSetValue(s, e));
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 e = s ?? this.lastError;
62
- return e === "301" ? "Not initialized" : e === "302" ? "Already terminated" : this.api.LMSGetErrorString(e);
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, e = 100) {
71
- this.LMSSetValue("cmi.core.score.raw", String(s)), this.LMSSetValue("cmi.core.score.max", String(e)), this.LMSSetValue("cmi.core.score.min", "0");
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 e = m(s);
75
- this.LMSSetValue("cmi.suspend_data", e);
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 h {
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, e) {
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 = e;
141
+ this.data.lessonStatus = t;
142
142
  break;
143
143
  case "cmi.core.score.raw":
144
- this.data.scoreRaw = Number(e);
144
+ this.data.scoreRaw = Number(t);
145
145
  break;
146
146
  case "cmi.core.score.min":
147
- this.data.scoreMin = Number(e);
147
+ this.data.scoreMin = Number(t);
148
148
  break;
149
149
  case "cmi.core.score.max":
150
- this.data.scoreMax = Number(e);
150
+ this.data.scoreMax = Number(t);
151
151
  break;
152
152
  case "cmi.suspend_data":
153
- this.data.suspendData = m(e);
153
+ this.data.suspendData = d(t);
154
154
  break;
155
155
  case "cmi.core.lesson_location":
156
- this.data.lessonLocation = e;
156
+ this.data.lessonLocation = t;
157
157
  break;
158
158
  case "cmi.core.exit":
159
- this.data.exit = e;
159
+ this.data.exit = t;
160
160
  break;
161
161
  case "cmi.core.session_time":
162
- this.data.sessionTime = e;
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 e = s ?? this.lastError;
177
- return e === "301" ? "Not initialized" : e === "302" ? "Already terminated" : "No error";
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, e = 100) {
186
- this.data.scoreRaw = s, this.data.scoreMax = e, this.data.scoreMin = 0, this.saveToStorage();
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 = m(s), this.saveToStorage();
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(S);
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(S, JSON.stringify(this.data));
204
+ localStorage.setItem(g, JSON.stringify(this.data));
205
205
  } catch {
206
206
  }
207
207
  }
208
208
  }
209
- class D extends h {
209
+ class F extends u {
210
210
  constructor() {
211
211
  super({ persistToStorage: !0 });
212
212
  }
213
213
  }
214
- function m(t) {
215
- return t.length <= 4096 ? t : (console.warn(
214
+ function d(e) {
215
+ return e.length <= 4096 ? e : (console.warn(
216
216
  "[lxpack] suspend_data exceeds 4096 chars; truncating"
217
- ), t.slice(0, 4096));
217
+ ), e.slice(0, 4096));
218
218
  }
219
- function R(t) {
220
- if (t === "preview")
221
- return new h({ persistToStorage: !0 });
222
- if (t === "scorm12") {
223
- const s = _();
224
- return s ? new L(s) : (console.warn(
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 h({ persistToStorage: !1 }));
226
+ ), new u({ persistToStorage: !1 }));
227
227
  }
228
- return new h({ persistToStorage: !1 });
228
+ return new u({ persistToStorage: !1 });
229
229
  }
230
- function C(t = "preview") {
231
- const s = R(t);
232
- if (t === "preview") {
233
- const e = window;
234
- e.API = s;
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
- function d(t) {
239
- var e;
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: t.currentLessonId,
242
- l: t.completedLessons,
243
- a: t.assessmentScores,
244
- s: t.suspendData
383
+ c: e.currentLessonId,
384
+ l: e.completedLessons,
385
+ a: e.assessmentScores,
386
+ s: e.suspendData
245
387
  };
246
- return (e = s.l) != null && e.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;
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 E(t, s) {
390
+ function y(e, s) {
249
391
  return {
250
- currentLessonId: t.c ?? s.currentLessonId,
251
- completedLessons: Array.isArray(t.l) ? t.l : s.completedLessons,
252
- assessmentScores: t.a && typeof t.a == "object" ? t.a : s.assessmentScores,
253
- suspendData: t.s && typeof t.s == "object" ? t.s : s.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 O(t) {
257
- const s = { ...t.suspendData }, e = Object.keys(s).filter((r) => r.startsWith("interaction_")).sort();
258
- for (const r of e)
259
- if (delete s[r], JSON.stringify(d({ ...t, suspendData: s })).length <= 4096)
260
- return { ...t, suspendData: s };
261
- return { ...t, suspendData: s };
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 M(t) {
264
- let s = JSON.stringify(d(t));
405
+ function P(e) {
406
+ let s = JSON.stringify(p(e));
265
407
  if (s.length <= 4096)
266
408
  return s;
267
- const e = O(t);
268
- return s = JSON.stringify(d(e)), s.length <= 4096 ? s : (console.warn(
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 A(t) {
273
- if (!t || typeof t != "object") return !1;
274
- const s = t;
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 N(t, s) {
419
+ function V(e, s) {
278
420
  return {
279
- currentLessonId: t.currentLessonId ?? s.currentLessonId,
280
- completedLessons: Array.isArray(t.completedLessons) ? t.completedLessons : s.completedLessons,
281
- assessmentScores: t.assessmentScores && typeof t.assessmentScores == "object" ? t.assessmentScores : s.assessmentScores,
282
- suspendData: t.suspendData && typeof t.suspendData == "object" ? t.suspendData : s.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 p(t, s) {
427
+ function m(e, s) {
286
428
  try {
287
- const e = JSON.parse(t);
288
- return A(e) ? {
289
- progress: N(e, s),
429
+ const t = JSON.parse(e);
430
+ return w(t) ? {
431
+ progress: V(t, s),
290
432
  parsed: !0
291
- } : { progress: E(e, s), parsed: !0 };
433
+ } : { progress: y(t, s), parsed: !0 };
292
434
  } catch {
293
435
  return { progress: s, parsed: !1 };
294
436
  }
295
437
  }
296
- function I(t) {
297
- const s = `${t.title}::${t.version}`;
298
- let e = 0;
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
- e = (e << 5) - e + s.charCodeAt(r), e |= 0;
301
- return `lxpack_progress_${Math.abs(e)}`;
474
+ t = (t << 5) - t + s.charCodeAt(r), t |= 0;
475
+ return `lxpack_progress_${Math.abs(t)}`;
302
476
  }
303
- class y {
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, o;
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 = I(s.manifest), this.defaultPassingScores = {};
316
- for (const [n, l] of Object.entries(s.assessments ?? {}))
317
- this.defaultPassingScores[n] = l.passingScore;
318
- const e = ((o = s.manifest.lessons[0]) == null ? void 0 : o.id) ?? "";
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: e,
495
+ currentLessonId: t,
321
496
  completedLessons: [],
322
497
  assessmentScores: {},
323
498
  suspendData: {}
324
- }, s.mode === "scorm12" ? (this.scorm = R("scorm12"), this.scorm.LMSInitialize(), this.restoreScormProgress()) : (s.mode === "preview" || s.mode === "standalone") && this.restoreLocalProgress();
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 (!this.scorm) return;
328
- const s = this.scorm.LMSGetValue("cmi.core.lesson_location");
329
- s && (this.progress.currentLessonId = s);
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: e, parsed: r } = p(s, this.progress);
336
- r ? this.progress = e : this.restoreLessonLocation();
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: e, parsed: r } = p(s, this.progress);
346
- r && (this.progress = e);
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, e] of Object.entries(this.progress.assessmentScores))
355
- e >= this.getAssessmentPassingScore(s) && this.passedAssessments.add(s);
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 e = this.progress.suspendData[`assessment_passing_${s}`];
359
- return typeof e == "number" ? e : s in this.defaultPassingScores ? this.defaultPassingScores[s] : 0.7;
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, e) => {
372
- this.progress.suspendData[s] = e, this.persist();
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, e, r) => this.submitAssessment(s, e, r)
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, e) {
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 o = typeof ((r = s.data) == null ? void 0 : r.passingScore) == "number" ? Number(s.data.passingScore) : this.getAssessmentPassingScore(s.id), n = ((a = s.data) == null ? void 0 : a.score) != null ? Number(s.data.score) : void 0;
382
- if (n != null && !Number.isNaN(n)) {
383
- this.applyAssessmentResult(s.id, n, o), (e == null ? void 0 : e.persist) !== !1 && (this.updateCompletion(), this.persist());
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
- (e == null ? void 0 : e.persist) !== !1 && this.persist();
578
+ (t == null ? void 0 : t.persist) !== !1 && this.persist();
388
579
  }
389
- applyAssessmentResult(s, e, r) {
390
- this.progress.assessmentScores[s] = e, this.progress.suspendData[`assessment_passing_${s}`] = r, e >= r ? this.passedAssessments.add(s) : this.passedAssessments.delete(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, e, r) {
393
- this.applyAssessmentResult(s, e, r), this.updateCompletion(), this.persist();
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 e;
415
- const s = ((e = this.manifest.assessments) == null ? void 0 : e.length) ?? 0;
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 n;
610
+ var o;
420
611
  if (this.getTotalUnits() === 0) return 0;
421
- const e = this.manifest.lessons.length, r = ((n = this.manifest.assessments) == null ? void 0 : n.length) ?? 0, a = this.progress.completedLessons.filter(
422
- (l) => this.manifest.lessons.some((u) => u.id === l)
423
- ).length, o = this.passedAssessments.size;
424
- return (a + o) / (e + r);
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 r, a, o;
428
- const s = this.getCompletionRatio(), e = Math.round(s * 100);
429
- if (this.scorm) {
430
- this.scorm.setScore(e);
431
- const n = this.manifest.lessons.every(
432
- (c) => this.progress.completedLessons.includes(c.id)
433
- ), l = !((r = this.manifest.assessments) != null && r.length) || this.manifest.assessments.every((c) => this.passedAssessments.has(c.id));
434
- ((a = this.manifest.assessments) == null ? void 0 : a.some(
435
- (c) => c.id in this.progress.assessmentScores && !this.passedAssessments.has(c.id)
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 = M(this.progress);
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
- y as LxpackRuntime,
456
- D as Scorm12API,
457
- L as Scorm12Adapter,
458
- h as Scorm12Simulator,
459
- R as createScormConnection,
460
- _ as findLmsApi,
461
- C as installScormAPI,
462
- m as trimSuspendData
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
  };