tessera-learn 0.0.2 → 0.0.4
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/AGENTS.md +110 -4
- package/dist/plugin/index.js +88 -11
- package/dist/plugin/index.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +1 -0
- package/src/plugin/index.ts +13 -2
- package/src/plugin/manifest.ts +5 -3
- package/src/plugin/validation.ts +137 -7
- package/src/runtime/App.svelte +66 -2
- package/src/runtime/adapters/cmi5.ts +120 -0
- package/src/runtime/adapters/scorm-base.ts +24 -0
- package/src/runtime/adapters/scorm12.ts +2 -0
- package/src/runtime/adapters/scorm2004.ts +2 -0
- package/src/runtime/hooks.svelte.ts +39 -0
- package/src/runtime/persistence.ts +2 -0
- package/src/runtime/progress.svelte.ts +25 -0
- package/src/runtime/types.ts +23 -4
|
@@ -24,6 +24,21 @@ export class ProgressState {
|
|
|
24
24
|
completionStatus = $state<'incomplete' | 'complete'>('incomplete');
|
|
25
25
|
successStatus = $state<'unknown' | 'passed' | 'failed'>('unknown');
|
|
26
26
|
|
|
27
|
+
// Latch for manual completion. Monotonic; recalc methods bail when set.
|
|
28
|
+
#manuallyCompleted = $state(false);
|
|
29
|
+
|
|
30
|
+
get manuallyCompleted(): boolean {
|
|
31
|
+
return this.#manuallyCompleted;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Idempotent — only the first call per session has an effect. */
|
|
35
|
+
markCompleteManually(): void {
|
|
36
|
+
if (this.#manuallyCompleted) return;
|
|
37
|
+
this.#manuallyCompleted = true;
|
|
38
|
+
this.completionStatus = 'complete';
|
|
39
|
+
this.version++;
|
|
40
|
+
}
|
|
41
|
+
|
|
27
42
|
/**
|
|
28
43
|
* Monotonic counter incremented on every persistable state mutation
|
|
29
44
|
* (visited/scores/chunks/standalone). Callers that need to react to *any*
|
|
@@ -100,6 +115,8 @@ export class ProgressState {
|
|
|
100
115
|
}
|
|
101
116
|
|
|
102
117
|
recalculateCompletion(manifest: Manifest, config: CourseConfig) {
|
|
118
|
+
if (this.#manuallyCompleted) return;
|
|
119
|
+
if (config.completion.mode === 'manual') return;
|
|
103
120
|
if (config.completion.mode === 'percentage') {
|
|
104
121
|
const threshold = config.completion.percentageThreshold ?? 100;
|
|
105
122
|
const percent = manifest.totalPages > 0
|
|
@@ -118,6 +135,14 @@ export class ProgressState {
|
|
|
118
135
|
}
|
|
119
136
|
|
|
120
137
|
recalculateSuccess(manifest: Manifest, config: CourseConfig) {
|
|
138
|
+
if (config.completion.mode === 'manual') {
|
|
139
|
+
const want = config.completion.requireSuccessStatus;
|
|
140
|
+
// Stay 'unknown' until manual mark fires, so a learner who never
|
|
141
|
+
// finishes isn't reported as passed.
|
|
142
|
+
this.successStatus = this.#manuallyCompleted && want !== undefined ? want : 'unknown';
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
121
146
|
const { indices, attempted } = this.#gradedPages(manifest);
|
|
122
147
|
|
|
123
148
|
if (indices.length === 0) {
|
package/src/runtime/types.ts
CHANGED
|
@@ -29,10 +29,8 @@ export interface CourseConfig {
|
|
|
29
29
|
mode: 'free' | 'sequential';
|
|
30
30
|
canAccess?: AccessFn;
|
|
31
31
|
};
|
|
32
|
-
completion:
|
|
33
|
-
|
|
34
|
-
percentageThreshold?: number;
|
|
35
|
-
};
|
|
32
|
+
completion: ManualCompletion | QuizCompletion | PercentageCompletion;
|
|
33
|
+
/** Optional under "manual"; required under "quiz". */
|
|
36
34
|
scoring: {
|
|
37
35
|
passingScore: number;
|
|
38
36
|
};
|
|
@@ -48,6 +46,27 @@ export interface CourseConfig {
|
|
|
48
46
|
xapi?: XAPIConfig | XAPIConfig[];
|
|
49
47
|
}
|
|
50
48
|
|
|
49
|
+
export interface ManualCompletion {
|
|
50
|
+
mode: 'manual';
|
|
51
|
+
/**
|
|
52
|
+
* Set to "page" to opt into a build-time check that at least one page
|
|
53
|
+
* declares `completesOn: "view"`. Omit to skip the check; both completion
|
|
54
|
+
* paths still work at runtime.
|
|
55
|
+
*/
|
|
56
|
+
trigger?: 'page';
|
|
57
|
+
/** When set, markComplete() also flips successStatus. Omit for unknown. */
|
|
58
|
+
requireSuccessStatus?: 'passed' | 'failed';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface QuizCompletion {
|
|
62
|
+
mode: 'quiz';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface PercentageCompletion {
|
|
66
|
+
mode: 'percentage';
|
|
67
|
+
percentageThreshold?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
51
70
|
/**
|
|
52
71
|
* cmi5 launch-inherited destination. Only valid under `export.standard:
|
|
53
72
|
* 'cmi5'`. Auth, actor, activityId, and registration are taken from the
|