@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 CHANGED
@@ -5,15 +5,16 @@
5
5
  [![License](https://img.shields.io/github/license/eddiethedean/lxpack)](https://github.com/eddiethedean/lxpack/blob/main/LICENSE)
6
6
  [![Node.js](https://img.shields.io/badge/node-%3E%3D20-brightgreen)](https://nodejs.org/)
7
7
 
8
- Browser runtime for LXPack courses — lesson navigation, markdown rendering, HTML interactions, assessments, progress tracking, and SCORM 1.2 integration.
8
+ Browser runtime for LXPack courses — lesson navigation, markdown and HTML lessons, component widgets, branching flow, quiz engine, progress tracking, and SCORM 1.2 / 2004 integration.
9
9
 
10
- Part of [LXPack](https://github.com/eddiethedean/lxpack) — an AI-native learning experience compiler and runtime.
10
+ Part of [LXPack](https://github.com/eddiethedean/lxpack) — an AI-native learning experience compiler and runtime (**v0.2.0**).
11
11
 
12
12
  | Related | Package |
13
13
  |---------|---------|
14
14
  | CLI / preview | [`@lxpack/cli`](../cli/README.md) |
15
15
  | Validation & bundles | [`@lxpack/validators`](../validators/README.md) |
16
16
  | Export shell | [`@lxpack/scorm`](../scorm/README.md) |
17
+ | UI widgets | [`@lxpack/components`](../components/README.md) |
17
18
 
18
19
  ## Install
19
20
 
@@ -27,7 +28,7 @@ Requires Node.js 20+ for the build toolchain. Published bundles run in modern br
27
28
 
28
29
  | Import | Description |
29
30
  |--------|-------------|
30
- | `@lxpack/runtime` | Node/build-time API (`LxpackRuntime`, SCORM helpers, progress serialization, types) |
31
+ | `@lxpack/runtime` | Node/build-time API (`LxpackRuntime`, flow, variables, SCORM helpers, progress serialization, types) |
31
32
  | `@lxpack/runtime/client` | Self-contained browser bundle (`dist/client.js`) |
32
33
  | `dist/styles.css` | Bundled with the client in SCORM/standalone exports |
33
34
 
@@ -35,14 +36,49 @@ Requires Node.js 20+ for the build toolchain. Published bundles run in modern br
35
36
 
36
37
  The CLI and SCORM packager embed `@lxpack/runtime/client` into exported courses. The client:
37
38
 
38
- - Renders markdown lessons and HTML interaction folders
39
- - Loads assessments from the embedded config (`assessments` + `answerKeys`); does not fetch author YAML in production exports
40
- - Scores MCQ submissions with `scoreAssessment()`
41
- - Tracks lesson completion and assessment scores
42
- - Persists progress via SCORM `suspend_data` (compact JSON, 4096-char safe) or `localStorage` in preview mode
39
+ - Renders markdown lessons, HTML interaction folders, and `type: component` lessons (via `window.__LXPACK_COMPONENTS__`)
40
+ - Resolves **next/previous** navigation with the flow engine when `course.yaml` defines `flow`; otherwise linear lesson order
41
+ - Loads assessments from embedded config (`assessments`, `answerKeys`, `configs`, `feedback`); does not fetch author YAML in production exports
42
+ - Renders quizzes with `renderAssessment()` — retakes, choice shuffle, and feedback modes from per-assessment config
43
+ - Tracks lesson completion, manifest variables (`v:` prefix in suspend data), and assessment scores
44
+ - Persists progress via SCORM `suspend_data` / CMI (compact JSON, size-safe) or `localStorage` in preview mode
43
45
 
44
46
  Config is injected by the packager using [`safeJsonForHtml`](../scorm/README.md) from `@lxpack/scorm`.
45
47
 
48
+ ## Flow and variables
49
+
50
+ ```ts
51
+ import {
52
+ evaluateCondition,
53
+ resolveFlowGoto,
54
+ resolveNextActivityId,
55
+ initManifestVariables,
56
+ readManifestVariable,
57
+ writeManifestVariable,
58
+ } from "@lxpack/runtime";
59
+ ```
60
+
61
+ | Module | Role |
62
+ |--------|------|
63
+ | `flow.ts` | Condition evaluation (`variable.eq`, `assessment.passed`, `interaction.done`, `all` / `any`) and `goto` resolution |
64
+ | `variables.ts` | Manifest variable defaults and `v:` namespaced storage in progress |
65
+
66
+ `LxpackRuntime` exposes `setVariable()` / `getVariable()` on the learner API when the manifest declares `variables`.
67
+
68
+ ## Quiz module
69
+
70
+ ```ts
71
+ import {
72
+ renderAssessment,
73
+ scoreAssessmentForm,
74
+ getAttemptCount,
75
+ shuffleQuestions,
76
+ } from "@lxpack/runtime";
77
+ // Re-exported from client as scoreAssessment
78
+ ```
79
+
80
+ Supports `maxAttempts`, `shuffleChoices`, and `showFeedback` (`immediate` | `end` | `never`) from the build-time assessment bundle.
81
+
46
82
  ## SCORM 1.2
47
83
 
48
84
  ```ts
@@ -63,7 +99,24 @@ import {
63
99
  | `installScormAPI()` | Expose the simulator API on `window` for preview servers |
64
100
  | `trimSuspendData(data)` | Truncate suspend data to `SCORM_SUSPEND_DATA_MAX` (4096) |
65
101
 
66
- Progress uses a compact suspend-data format with legacy fallback parsing. Assessment submission updates completion status before persisting to the LMS.
102
+ ## SCORM 2004
103
+
104
+ ```ts
105
+ import {
106
+ findScorm2004Api,
107
+ createScorm2004Connection,
108
+ Scorm2004Adapter,
109
+ Scorm2004Simulator,
110
+ } from "@lxpack/runtime";
111
+ ```
112
+
113
+ | API | Description |
114
+ |-----|-------------|
115
+ | `findScorm2004Api()` | Locate `API_1484_11` in parent/opener frames |
116
+ | `createScorm2004Connection(mode)` | LMS adapter (`scorm2004`) or preview simulator |
117
+ | CMI mapping | Progress and completion mapped for multi-SCO packages |
118
+
119
+ Use `mode: "scorm2004"` in `RuntimeConfig` when embedding the runtime in SCORM 2004 launch pages.
67
120
 
68
121
  ## Runtime class
69
122
 
@@ -72,16 +125,17 @@ import { LxpackRuntime, type RuntimeConfig } from "@lxpack/runtime";
72
125
 
73
126
  const runtime = new LxpackRuntime({
74
127
  manifest,
75
- mode: "scorm12", // or "preview"
128
+ mode: "scorm12", // "scorm2004" | "preview"
76
129
  defaultPassingScores: { quiz: 0.7 },
77
130
  });
78
131
 
79
132
  runtime.completeLesson("intro");
133
+ runtime.getAPI().setVariable("track", "advanced");
80
134
  runtime.getAPI().submitAssessment("quiz", 0.85, 0.7);
81
135
  runtime.getProgress();
82
136
  ```
83
137
 
84
- `LxpackAPI` methods include `track()`, `submitAssessment()`, `getProgress()`, and `terminate()` (guarded against double `LMSFinish`).
138
+ `LxpackAPI` methods include `track()`, `submitAssessment()`, `getProgress()`, `setVariable()` / `getVariable()`, and `terminate()` (guarded against double finish).
85
139
 
86
140
  ## Build output
87
141
 
@@ -105,6 +159,8 @@ pnpm --filter @lxpack/runtime typecheck
105
159
  ## Links
106
160
 
107
161
  - [LXPack repository](https://github.com/eddiethedean/lxpack)
162
+ - [Documentation index](https://github.com/eddiethedean/lxpack/blob/main/docs/README.md)
163
+ - [Technical specification](https://github.com/eddiethedean/lxpack/blob/main/docs/SPEC.md)
108
164
  - [Changelog](https://github.com/eddiethedean/lxpack/blob/main/CHANGELOG.md)
109
165
 
110
166
  ## License