@lxpack/runtime 0.1.0 → 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 ADDED
@@ -0,0 +1,168 @@
1
+ # @lxpack/runtime
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@lxpack/runtime)](https://www.npmjs.com/package/@lxpack/runtime)
4
+ [![CI](https://github.com/eddiethedean/lxpack/actions/workflows/ci.yml/badge.svg)](https://github.com/eddiethedean/lxpack/actions/workflows/ci.yml)
5
+ [![License](https://img.shields.io/github/license/eddiethedean/lxpack)](https://github.com/eddiethedean/lxpack/blob/main/LICENSE)
6
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D20-brightgreen)](https://nodejs.org/)
7
+
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
+
10
+ Part of [LXPack](https://github.com/eddiethedean/lxpack) — an AI-native learning experience compiler and runtime (**v0.2.0**).
11
+
12
+ | Related | Package |
13
+ |---------|---------|
14
+ | CLI / preview | [`@lxpack/cli`](../cli/README.md) |
15
+ | Validation & bundles | [`@lxpack/validators`](../validators/README.md) |
16
+ | Export shell | [`@lxpack/scorm`](../scorm/README.md) |
17
+ | UI widgets | [`@lxpack/components`](../components/README.md) |
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install @lxpack/runtime
23
+ ```
24
+
25
+ Requires Node.js 20+ for the build toolchain. Published bundles run in modern browsers (ESM `client.js`).
26
+
27
+ ## Package exports
28
+
29
+ | Import | Description |
30
+ |--------|-------------|
31
+ | `@lxpack/runtime` | Node/build-time API (`LxpackRuntime`, flow, variables, SCORM helpers, progress serialization, types) |
32
+ | `@lxpack/runtime/client` | Self-contained browser bundle (`dist/client.js`) |
33
+ | `dist/styles.css` | Bundled with the client in SCORM/standalone exports |
34
+
35
+ ## Browser client
36
+
37
+ The CLI and SCORM packager embed `@lxpack/runtime/client` into exported courses. The client:
38
+
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
45
+
46
+ Config is injected by the packager using [`safeJsonForHtml`](../scorm/README.md) from `@lxpack/scorm`.
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
+
82
+ ## SCORM 1.2
83
+
84
+ ```ts
85
+ import {
86
+ findLmsApi,
87
+ createScormConnection,
88
+ installScormAPI,
89
+ Scorm12Adapter,
90
+ Scorm12Simulator,
91
+ SCORM_SUSPEND_DATA_MAX,
92
+ } from "@lxpack/runtime";
93
+ ```
94
+
95
+ | API | Description |
96
+ |-----|-------------|
97
+ | `findLmsApi()` | Walk parent/opener frames to locate the LMS SCORM 1.2 API |
98
+ | `createScormConnection(mode)` | LMS adapter (`scorm12`) or local simulator (`preview`) |
99
+ | `installScormAPI()` | Expose the simulator API on `window` for preview servers |
100
+ | `trimSuspendData(data)` | Truncate suspend data to `SCORM_SUSPEND_DATA_MAX` (4096) |
101
+
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.
120
+
121
+ ## Runtime class
122
+
123
+ ```ts
124
+ import { LxpackRuntime, type RuntimeConfig } from "@lxpack/runtime";
125
+
126
+ const runtime = new LxpackRuntime({
127
+ manifest,
128
+ mode: "scorm12", // "scorm2004" | "preview"
129
+ defaultPassingScores: { quiz: 0.7 },
130
+ });
131
+
132
+ runtime.completeLesson("intro");
133
+ runtime.getAPI().setVariable("track", "advanced");
134
+ runtime.getAPI().submitAssessment("quiz", 0.85, 0.7);
135
+ runtime.getProgress();
136
+ ```
137
+
138
+ `LxpackAPI` methods include `track()`, `submitAssessment()`, `getProgress()`, `setVariable()` / `getVariable()`, and `terminate()` (guarded against double finish).
139
+
140
+ ## Build output
141
+
142
+ | Artifact | Role |
143
+ |----------|------|
144
+ | `dist/client.js` | Vite browser bundle (embedded in packages) |
145
+ | `dist/runtime.js` | Node/library entry |
146
+ | `dist/styles.css` | Runtime styles |
147
+ | `dist/*.d.ts` | Type declarations |
148
+
149
+ ## Development
150
+
151
+ From the monorepo root:
152
+
153
+ ```bash
154
+ pnpm --filter @lxpack/runtime build
155
+ pnpm --filter @lxpack/runtime test
156
+ pnpm --filter @lxpack/runtime typecheck
157
+ ```
158
+
159
+ ## Links
160
+
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)
164
+ - [Changelog](https://github.com/eddiethedean/lxpack/blob/main/CHANGELOG.md)
165
+
166
+ ## License
167
+
168
+ Apache-2.0