@anantagnanam/lms 0.0.0-stage → 0.1.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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +77 -2
  3. package/astro/client.ts +433 -0
  4. package/astro/components/CertificateCard.astro +83 -0
  5. package/astro/components/CourseCard.astro +61 -0
  6. package/astro/components/CourseCatalog.astro +96 -0
  7. package/astro/components/CourseOverview.astro +286 -0
  8. package/astro/components/LearnerDashboard.astro +121 -0
  9. package/astro/components/LearningShell.astro +28 -0
  10. package/astro/components/LessonPlayer.astro +323 -0
  11. package/astro/components/MediaPlayer.astro +60 -0
  12. package/astro/components/index.ts +7 -0
  13. package/astro/layouts/AcademyLayout.astro +84 -0
  14. package/astro/pages/certificate.astro +57 -0
  15. package/astro/pages/cohort.astro +102 -0
  16. package/astro/pages/course.astro +80 -0
  17. package/astro/pages/dashboard.astro +34 -0
  18. package/astro/pages/index.astro +40 -0
  19. package/astro/pages/lesson.astro +100 -0
  20. package/astro/pages/teach.astro +15 -0
  21. package/astro/styles.css +1288 -0
  22. package/dist/admin.d.ts +32 -0
  23. package/dist/admin.js +2762 -0
  24. package/dist/admin.js.map +1 -0
  25. package/dist/astro.d.ts +11 -0
  26. package/dist/astro.js +49 -0
  27. package/dist/astro.js.map +1 -0
  28. package/dist/commerce.d.ts +72 -0
  29. package/dist/commerce.js +0 -0
  30. package/dist/config-BX3beTpM.js +15 -0
  31. package/dist/config-BX3beTpM.js.map +1 -0
  32. package/dist/constants-C0kT94tc.js +139 -0
  33. package/dist/constants-C0kT94tc.js.map +1 -0
  34. package/dist/csv-DKq_4OWU.js +55 -0
  35. package/dist/csv-DKq_4OWU.js.map +1 -0
  36. package/dist/errors-ChzJS9al.js +16 -0
  37. package/dist/errors-ChzJS9al.js.map +1 -0
  38. package/dist/index.d.ts +13 -0
  39. package/dist/index.js +19 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/runtime.d.ts +681 -0
  42. package/dist/runtime.js +2060 -0
  43. package/dist/runtime.js.map +1 -0
  44. package/dist/schemas.d.ts +584 -0
  45. package/dist/schemas.js +315 -0
  46. package/dist/schemas.js.map +1 -0
  47. package/dist/server.d.ts +30 -0
  48. package/dist/server.js +54 -0
  49. package/dist/server.js.map +1 -0
  50. package/dist/types.d.ts +284 -0
  51. package/dist/types.js +0 -0
  52. package/package.json +83 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ananta Gnanam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,78 @@
1
- # Temporary Holding Version
1
+ # @anantagnanam/lms
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A native LMS for EmDash 1.4 with Astro 7 and React 19. Version 0.1.0 provides free courses, flexible enrollment, cohorts, lessons, quizzes, assignments, progress, certificates, discussions, moderation, reporting, and notifications.
4
+
5
+ ## Installation
6
+
7
+ Install the public npm release in an existing EmDash site:
8
+
9
+ ```sh
10
+ npm install @anantagnanam/lms
11
+ ```
12
+
13
+ This is a trusted native dependency configured by the site developer. Local builds can also be installed from their release tarball.
14
+
15
+ ```js
16
+ import { defineConfig } from "astro/config";
17
+ import react from "@astrojs/react";
18
+ import emdash from "emdash/astro";
19
+ import { anantagnanamLmsPlugin } from "@anantagnanam/lms";
20
+ import { lmsAstro } from "@anantagnanam/lms/astro";
21
+
22
+ const learning = { basePath: "/academy", loginPath: "/login" };
23
+
24
+ export default defineConfig({
25
+ output: "server",
26
+ // Keep the site's existing adapter and other options.
27
+ integrations: [
28
+ react(),
29
+ lmsAstro({ ...learning, layout: "./src/layouts/Base.astro" }),
30
+ emdash({
31
+ // Keep the site's existing database, storage, and auth provider.
32
+ plugins: [anantagnanamLmsPlugin(learning)],
33
+ }),
34
+ ],
35
+ });
36
+ ```
37
+
38
+ Keep existing plugin and integration registrations alongside these. Use the same `basePath` and `loginPath` for both registrations. Omit `layout` for the standalone academy layout. A custom layout receives `title`, `description`, and `robots` and must render a slot. The host supplies learner signup and sign-in through its EmDash authentication provider.
39
+
40
+ After rebuilding the site, visit:
41
+
42
+ - `/academy`: course catalog
43
+ - `/academy/my-learning`: learner dashboard
44
+ - `/academy/teach`: instructor course studio
45
+ - `/_emdash/admin/plugins/anantagnanam-lms`: administration
46
+
47
+ The native plugin declares course, enrollment, cohort, certificate, discussion, review, notification, and audit storage. EmDash creates the plugin storage namespace. No LMS SQL migration or separate authentication store is needed.
48
+
49
+ ## Enrollment and access
50
+
51
+ `open` courses enroll learners immediately. `approval` courses create pending requests. `invite` courses require administrator enrollment. Cohort membership always requires an administrator decision. Administrators can reject, suspend, restore, cancel, and date access without deleting progress.
52
+
53
+ An enrollment has separate lifecycle, administrative access, and individual grants. Current cohort membership and dates are authoritative for cohort access. A public free or manual grant can continue independently of a suspended or expired cohort.
54
+
55
+ ## Commerce boundary
56
+
57
+ This release performs no payments. Paid publication and paid enrollment are blocked. `@anantagnanam/lms/commerce` exports only interfaces for money, orders, checkout, verified payment events, refunds, and purchase grants. Future payment providers can add their ledger and purchase grants without replacing enrollment or progress records.
58
+
59
+ ## Exports
60
+
61
+ | Export | Purpose |
62
+ | ------------------- | ------------------------------------------------------- |
63
+ | `@anantagnanam/lms` | Descriptor factory and constants |
64
+ | `/runtime` | Native runtime factory |
65
+ | `/astro` | Astro integration and injected server routes |
66
+ | `/server` | Public/learner read helpers and URL builders |
67
+ | `/admin` | React admin pages, course studio, and widget |
68
+ | `/components` | Astro components for custom site composition |
69
+ | `/styles.css` | Scoped learner styles |
70
+ | `/types` | Course, enrollment, progress, assessment, and API types |
71
+ | `/schemas` | Validated authoring and request schemas |
72
+ | `/commerce` | Future provider-independent commerce interfaces |
73
+
74
+ Private HTTP calls use an EmDash session and `X-EmDash-Request: 1`. API routes begin at `/_emdash/api/plugins/anantagnanam-lms`. Learner rendering helpers accept only the read routes required by the included pages.
75
+
76
+ Notifications always appear in the learner dashboard. Email is optional and disabled by default. Configure an EmDash email transport and working cron scheduler before enabling email or inactivity reminders. Certificates use the browser's print/save-as-PDF flow.
77
+
78
+ Full documentation: [repository](https://github.com/anantagnanam/anantagnanam-emdash-plugins), [installation](https://github.com/anantagnanam/anantagnanam-emdash-plugins/blob/main/docs/installation.md), [architecture](https://github.com/anantagnanam/anantagnanam-emdash-plugins/blob/main/docs/architecture.md), and [release scope](https://github.com/anantagnanam/anantagnanam-emdash-plugins/blob/main/docs/release-scope.md).
@@ -0,0 +1,433 @@
1
+ import { API_BASE } from "@anantagnanam/lms";
2
+ import type {
3
+ Answers,
4
+ Discussion,
5
+ Notification,
6
+ Page,
7
+ PublicQuizAttempt,
8
+ } from "@anantagnanam/lms/types";
9
+
10
+ async function call<T>(route: string, input: Record<string, unknown>, method = "POST"): Promise<T> {
11
+ let url = `${API_BASE}/${route}`;
12
+ const headers: Record<string, string> = { "X-EmDash-Request": "1", Accept: "application/json" };
13
+ if (method === "GET") {
14
+ const query = new URLSearchParams();
15
+ for (const [key, value] of Object.entries(input))
16
+ if (value !== undefined) query.set(key, String(value));
17
+ url += `?${query}`;
18
+ } else headers["Content-Type"] = "application/json";
19
+ const response = await fetch(url, {
20
+ method,
21
+ credentials: "same-origin",
22
+ headers,
23
+ ...(method === "POST" ? { body: JSON.stringify(input) } : {}),
24
+ });
25
+ const result = (await response.json()) as {
26
+ success: boolean;
27
+ data?: T;
28
+ error?: { message?: string };
29
+ };
30
+ if (!response.ok || !result.success)
31
+ throw new Error(result.error?.message ?? "Please try again.");
32
+ return result.data as T;
33
+ }
34
+ function node<K extends keyof HTMLElementTagNameMap>(
35
+ tag: K,
36
+ text?: string,
37
+ className?: string,
38
+ ): HTMLElementTagNameMap[K] {
39
+ const element = document.createElement(tag);
40
+ if (text !== undefined) element.textContent = text;
41
+ if (className) element.className = className;
42
+ return element;
43
+ }
44
+ function feedback(root: Element, message: string, error = false) {
45
+ const target = root.querySelector<HTMLElement>("[data-lms-feedback]");
46
+ if (target) {
47
+ target.textContent = message;
48
+ target.dataset.tone = error ? "error" : "success";
49
+ target.setAttribute("role", error ? "alert" : "status");
50
+ }
51
+ }
52
+ function data(element: HTMLElement): Record<string, string> {
53
+ return { courseId: element.dataset.courseId ?? "", lessonId: element.dataset.lessonId ?? "" };
54
+ }
55
+
56
+ function forms() {
57
+ for (const form of document.querySelectorAll<HTMLFormElement>(
58
+ "form[data-lms-route]:not([data-lms-bound])",
59
+ )) {
60
+ form.dataset.lmsBound = "true";
61
+ form.addEventListener("submit", async (event) => {
62
+ event.preventDefault();
63
+ if (form.dataset.lmsBusy === "true") return;
64
+ if (form.dataset.lmsConfirm && !window.confirm(form.dataset.lmsConfirm)) return;
65
+ const input: Record<string, unknown> = Object.fromEntries(new FormData(form));
66
+ if ("rating" in input) input.rating = Number(input.rating);
67
+ if ("shared" in input) input.shared = input.shared === "true";
68
+ if ("attachmentUrl" in input && input.attachmentUrl === "") input.attachmentUrl = null;
69
+ if ("parentId" in input && input.parentId === "") input.parentId = null;
70
+ const buttons = [...form.querySelectorAll<HTMLButtonElement>('button[type="submit"]')];
71
+ form.dataset.lmsBusy = "true";
72
+ buttons.forEach((button) => (button.disabled = true));
73
+ feedback(form, "Saving…");
74
+ try {
75
+ const route = form.dataset.lmsRoute!;
76
+ const result = await call<{ status?: string }>(route, input);
77
+ feedback(
78
+ form,
79
+ route === "learner/enroll"
80
+ ? result.status === "pending"
81
+ ? "Enrollment requested. An administrator will review it."
82
+ : "You're enrolled. Your learning journey is ready."
83
+ : route === "learner/cohort/request"
84
+ ? "Cohort request received. An administrator will review it."
85
+ : route === "learner/assignment"
86
+ ? "Assignment submitted for grading."
87
+ : route === "learner/review" || route === "learner/discussion"
88
+ ? "Your contribution has been submitted."
89
+ : "Saved.",
90
+ );
91
+ if (route === "learner/discussion") {
92
+ const body = form.elements.namedItem("body");
93
+ if (body instanceof HTMLTextAreaElement) body.value = "";
94
+ const parent = form.elements.namedItem("parentId");
95
+ if (parent instanceof HTMLInputElement) parent.value = "";
96
+ const root = form.closest<HTMLElement>("[data-lms-discussions]");
97
+ if (root) await renderDiscussions(root);
98
+ }
99
+ if (form.hasAttribute("data-lms-reload")) window.location.reload();
100
+ } catch (cause) {
101
+ feedback(
102
+ form,
103
+ cause instanceof Error ? cause.message : "Could not save. Please try again.",
104
+ true,
105
+ );
106
+ } finally {
107
+ form.dataset.lmsBusy = "false";
108
+ buttons.forEach((button) => (button.disabled = false));
109
+ }
110
+ });
111
+ }
112
+ }
113
+
114
+ async function renderDiscussions(root: HTMLElement, cursor?: string, append = false) {
115
+ const list = root.querySelector<HTMLElement>("[data-lms-discussion-list]");
116
+ if (!list) return;
117
+ try {
118
+ const page = await call<Page<Discussion> & { pending: Discussion[] }>(
119
+ "learner/discussions",
120
+ { ...data(root), cursor },
121
+ "GET",
122
+ );
123
+ if (!append) list.replaceChildren();
124
+ root.querySelector("[data-lms-discussion-more]")?.remove();
125
+ if (!page.items.length && !page.pending.length && !append)
126
+ list.append(node("p", "Start a thoughtful conversation.", "lms-muted"));
127
+ for (const item of [...page.items, ...(!append ? page.pending : [])]) {
128
+ const article = node("article", undefined, "lms-discussion");
129
+ if (item.parentId) article.style.marginInlineStart = "1.2rem";
130
+ article.append(
131
+ node("strong", item.authorName),
132
+ node("p", item.body),
133
+ node(
134
+ "small",
135
+ item.status === "pending"
136
+ ? "Awaiting moderation · visible only to you"
137
+ : new Date(item.createdAt).toLocaleString(),
138
+ ),
139
+ );
140
+ if (item.status === "published" && !item.parentId) {
141
+ const reply = node("button", "Reply", "lms-text-button");
142
+ reply.type = "button";
143
+ reply.addEventListener("click", () => {
144
+ const form = root.querySelector<HTMLFormElement>("form");
145
+ if (!form) return;
146
+ let parent = form.elements.namedItem("parentId");
147
+ if (!(parent instanceof HTMLInputElement)) {
148
+ parent = node("input");
149
+ (parent as HTMLInputElement).type = "hidden";
150
+ (parent as HTMLInputElement).name = "parentId";
151
+ form.append(parent as HTMLInputElement);
152
+ }
153
+ (parent as HTMLInputElement).value = item.id;
154
+ feedback(form, `Replying to ${item.authorName}.`);
155
+ form.querySelector("textarea")?.focus();
156
+ });
157
+ article.append(reply);
158
+ }
159
+ list.append(article);
160
+ }
161
+ if (page.hasMore && page.cursor) {
162
+ const more = node("button", "More discussion", "lms-btn lms-btn-outline");
163
+ more.type = "button";
164
+ more.dataset.lmsDiscussionMore = "true";
165
+ more.addEventListener("click", () => void renderDiscussions(root, page.cursor, true));
166
+ root.append(more);
167
+ }
168
+ } catch (cause) {
169
+ list.replaceChildren(
170
+ node("p", cause instanceof Error ? cause.message : "Could not load discussion.", "lms-muted"),
171
+ );
172
+ }
173
+ }
174
+
175
+ function readAnswers(form: HTMLFormElement, attempt: PublicQuizAttempt): Answers {
176
+ const answers: Answers = {};
177
+ const values = new FormData(form);
178
+ for (const question of attempt.questions) {
179
+ const picked = values.getAll(question.id).map(String);
180
+ if (question.type === "multiple") answers[question.id] = picked;
181
+ else if (picked[0]) answers[question.id] = picked[0];
182
+ }
183
+ return answers;
184
+ }
185
+ function renderQuiz(root: HTMLElement, attempt: PublicQuizAttempt) {
186
+ const content = root.querySelector<HTMLElement>("[data-lms-quiz-content]")!;
187
+ content.replaceChildren();
188
+ const form = node("form");
189
+ const timer = node("p", "", "lms-quiz-timer");
190
+ timer.setAttribute("aria-live", "off");
191
+ form.append(timer);
192
+ for (const question of attempt.questions) {
193
+ const fieldset = node("fieldset", undefined, "lms-quiz-question");
194
+ fieldset.append(node("legend", question.prompt));
195
+ if (question.type === "short") {
196
+ const input = node("input");
197
+ input.name = question.id;
198
+ input.type = "text";
199
+ input.maxLength = 2000;
200
+ input.setAttribute("aria-label", "Your answer");
201
+ const saved = attempt.answers?.[question.id];
202
+ if (typeof saved === "string") input.value = saved;
203
+ fieldset.append(input);
204
+ } else
205
+ for (const option of question.options) {
206
+ const label = node("label", undefined, "lms-quiz-option");
207
+ const input = node("input");
208
+ input.name = question.id;
209
+ input.type = question.type === "multiple" ? "checkbox" : "radio";
210
+ input.value = option.id;
211
+ const saved = attempt.answers?.[question.id];
212
+ input.checked = Array.isArray(saved) ? saved.includes(option.id) : saved === option.id;
213
+ label.append(input, node("span", option.text));
214
+ fieldset.append(label);
215
+ }
216
+ form.append(fieldset);
217
+ }
218
+ const button = node("button", "Submit answers", "lms-btn");
219
+ button.type = "submit";
220
+ form.append(button);
221
+ content.append(form);
222
+ let interval: ReturnType<typeof setInterval> | undefined;
223
+ let saving: ReturnType<typeof setTimeout> | undefined;
224
+ let submitting = false;
225
+ const stop = () => {
226
+ if (interval) clearInterval(interval);
227
+ if (saving) clearTimeout(saving);
228
+ };
229
+ form.addEventListener("input", () => {
230
+ if (saving) clearTimeout(saving);
231
+ saving = setTimeout(() => {
232
+ if (!submitting && form.isConnected)
233
+ void call("learner/quiz/draft", {
234
+ ...data(root),
235
+ attemptId: attempt.id,
236
+ answers: readAnswers(form, attempt),
237
+ }).catch(() => {});
238
+ }, 700);
239
+ });
240
+ form.addEventListener("submit", async (event) => {
241
+ event.preventDefault();
242
+ if (submitting) return;
243
+ submitting = true;
244
+ button.disabled = true;
245
+ stop();
246
+ feedback(root, "Checking your answers…");
247
+ try {
248
+ const result = await call<{ attempt: PublicQuizAttempt }>("learner/quiz/submit", {
249
+ ...data(root),
250
+ attemptId: attempt.id,
251
+ answers: readAnswers(form, attempt),
252
+ });
253
+ feedback(
254
+ root,
255
+ `${result.attempt.passed ? "Passed" : "Not passed yet"} · ${result.attempt.percent}%`,
256
+ );
257
+ const outcome = node("div");
258
+ for (const item of result.attempt.feedback) {
259
+ const section = node("div", undefined, "lms-notice");
260
+ const question = attempt.questions.find((entry) => entry.id === item.questionId);
261
+ section.append(
262
+ node("strong", `${item.correct ? "✓" : "○"} ${question?.prompt ?? "Question"}`),
263
+ );
264
+ if (item.explanation) section.append(node("p", item.explanation));
265
+ outcome.append(section);
266
+ }
267
+ content.replaceChildren(outcome);
268
+ const start = root.querySelector<HTMLButtonElement>("[data-lms-quiz-start]");
269
+ if (start) {
270
+ start.hidden = result.attempt.passed;
271
+ start.disabled = false;
272
+ start.textContent = "Try another attempt";
273
+ }
274
+ if (result.attempt.passed) {
275
+ const continueLink = node("a", "Continue learning →", "lms-btn");
276
+ continueLink.href = root.dataset.nextUrl ?? window.location.pathname;
277
+ content.append(continueLink);
278
+ }
279
+ } catch (cause) {
280
+ feedback(
281
+ root,
282
+ cause instanceof Error ? cause.message : "Could not submit your answers.",
283
+ true,
284
+ );
285
+ button.disabled = false;
286
+ submitting = false;
287
+ const start = root.querySelector<HTMLButtonElement>("[data-lms-quiz-start]");
288
+ if (start) {
289
+ start.disabled = false;
290
+ start.hidden = false;
291
+ start.textContent = "Start a new attempt";
292
+ }
293
+ }
294
+ });
295
+ if (attempt.expiresAt) {
296
+ const tick = () => {
297
+ if (!form.isConnected) {
298
+ stop();
299
+ return;
300
+ }
301
+ const remaining = Math.max(
302
+ 0,
303
+ Math.ceil((Date.parse(attempt.expiresAt!) - Date.now()) / 1000),
304
+ );
305
+ timer.textContent = `Time remaining ${Math.floor(remaining / 60)}:${String(remaining % 60).padStart(2, "0")}`;
306
+ if (!remaining) {
307
+ stop();
308
+ form.requestSubmit();
309
+ }
310
+ };
311
+ interval = setInterval(tick, 1000);
312
+ tick();
313
+ } else timer.textContent = "Take your time. This quiz is untimed.";
314
+ }
315
+
316
+ function quizzes() {
317
+ for (const root of document.querySelectorAll<HTMLElement>(
318
+ "[data-lms-quiz]:not([data-lms-bound])",
319
+ )) {
320
+ root.dataset.lmsBound = "true";
321
+ const start = root.querySelector<HTMLButtonElement>("[data-lms-quiz-start]")!;
322
+ start.addEventListener("click", async () => {
323
+ if (start.disabled) return;
324
+ start.disabled = true;
325
+ feedback(root, "Preparing your quiz…");
326
+ try {
327
+ const attempt = await call<PublicQuizAttempt>("learner/quiz/start", data(root));
328
+ start.hidden = true;
329
+ feedback(root, "Your attempt has started.");
330
+ renderQuiz(root, attempt);
331
+ } catch (cause) {
332
+ start.disabled = false;
333
+ feedback(root, cause instanceof Error ? cause.message : "Could not start quiz.", true);
334
+ }
335
+ });
336
+ }
337
+ }
338
+ async function updates(root: HTMLElement, cursor?: string, append = false) {
339
+ try {
340
+ const page = await call<Page<Omit<Notification, "email">>>(
341
+ "learner/notifications",
342
+ { cursor },
343
+ "GET",
344
+ );
345
+ if (!append) root.replaceChildren();
346
+ root.querySelector("[data-lms-more]")?.remove();
347
+ if (!page.items.length && !append)
348
+ root.append(node("p", "Your learning updates will appear here.", "lms-muted"));
349
+ for (const item of page.items) {
350
+ const article = node("article", undefined, "lms-notification");
351
+ article.append(node("strong", item.title), node("p", item.message));
352
+ if (!item.read) {
353
+ const button = node("button", "Mark as read");
354
+ button.type = "button";
355
+ button.addEventListener("click", async () => {
356
+ button.disabled = true;
357
+ try {
358
+ await call("learner/notification/read", { id: item.id });
359
+ button.remove();
360
+ } catch {
361
+ button.disabled = false;
362
+ }
363
+ });
364
+ article.append(button);
365
+ }
366
+ root.append(article);
367
+ }
368
+ if (page.hasMore && page.cursor) {
369
+ const more = node("button", "More updates", "lms-text-button");
370
+ more.type = "button";
371
+ more.dataset.lmsMore = "true";
372
+ more.addEventListener("click", () => void updates(root, page.cursor, true));
373
+ root.append(more);
374
+ }
375
+ } catch (cause) {
376
+ root.replaceChildren(
377
+ node("p", cause instanceof Error ? cause.message : "Could not load updates.", "lms-muted"),
378
+ );
379
+ }
380
+ }
381
+
382
+ function initialize() {
383
+ forms();
384
+ quizzes();
385
+ for (const root of document.querySelectorAll<HTMLElement>(
386
+ "[data-lms-lesson]:not([data-lms-started])",
387
+ )) {
388
+ root.dataset.lmsStarted = "true";
389
+ if (root.dataset.preview !== "true")
390
+ void call("learner/start", data(root)).catch((cause) => {
391
+ const button = root.querySelector<HTMLButtonElement>("[data-lms-complete]");
392
+ if (button) button.disabled = true;
393
+ const form = root.querySelector("form[data-lms-route='learner/complete']");
394
+ if (form)
395
+ feedback(form, cause instanceof Error ? cause.message : "Could not start lesson.", true);
396
+ });
397
+ }
398
+ for (const root of document.querySelectorAll<HTMLElement>(
399
+ "[data-lms-discussions]:not([data-lms-loaded])",
400
+ )) {
401
+ root.dataset.lmsLoaded = "true";
402
+ void renderDiscussions(root);
403
+ }
404
+ for (const root of document.querySelectorAll<HTMLElement>(
405
+ "[data-lms-notifications]:not([data-lms-loaded])",
406
+ )) {
407
+ root.dataset.lmsLoaded = "true";
408
+ void updates(root);
409
+ }
410
+ for (const button of document.querySelectorAll<HTMLButtonElement>(
411
+ "[data-lms-print]:not([data-lms-bound])",
412
+ )) {
413
+ button.dataset.lmsBound = "true";
414
+ button.addEventListener("click", () => window.print());
415
+ }
416
+ for (const button of document.querySelectorAll<HTMLButtonElement>(
417
+ "[data-lms-copy-link]:not([data-lms-bound])",
418
+ )) {
419
+ button.dataset.lmsBound = "true";
420
+ button.addEventListener("click", async () => {
421
+ const status = document.querySelector("[data-lms-copy-status]");
422
+ const url = location.origin + location.pathname;
423
+ try {
424
+ await navigator.clipboard.writeText(url);
425
+ if (status) status.textContent = "Verification link copied.";
426
+ } catch {
427
+ if (status) status.textContent = `Verification link: ${url}`;
428
+ }
429
+ });
430
+ }
431
+ }
432
+ initialize();
433
+ document.addEventListener("astro:page-load", initialize);
@@ -0,0 +1,83 @@
1
+ ---
2
+ import type { Certificate } from "@anantagnanam/lms/types";
3
+ interface Verification {
4
+ id: string;
5
+ valid: boolean;
6
+ shared: boolean;
7
+ learnerName: string | null;
8
+ courseTitle: string;
9
+ issuerName: string;
10
+ issuedAt: string;
11
+ }
12
+ interface Props {
13
+ verification: Verification;
14
+ certificate?: Certificate | null;
15
+ }
16
+ const { verification, certificate } = Astro.props;
17
+ ---
18
+
19
+ <section class="lms-certificate-page">
20
+ <header class="lms-certificate-intro">
21
+ <p class="lms-eyebrow">A MILESTONE WORTH REMEMBERING</p>
22
+ <h1>{certificate ? "Your learning, recognised" : "Certificate verification"}</h1>
23
+ <p class="lms-lead">
24
+ {verification.valid
25
+ ? "This certificate was issued for a completed learning path."
26
+ : "This certificate has been revoked."}
27
+ </p>
28
+ </header>
29
+ <article class:list={["lms-certificate", { "lms-certificate-revoked": !verification.valid }]}>
30
+ <div class="lms-certificate-top">
31
+ <span>{verification.issuerName}</span>
32
+ <span class="lms-certificate-mark" aria-hidden="true">
33
+ ∞
34
+ </span>
35
+ </div>
36
+ <p class="lms-eyebrow">CERTIFICATE OF COMPLETION</p>
37
+ <p>This recognises</p>
38
+ <h2>
39
+ {certificate?.learnerName ??
40
+ verification.learnerName ??
41
+ "A learner who keeps their name private"}
42
+ </h2>
43
+ <p>for successfully completing</p>
44
+ <h3>{verification.courseTitle}</h3>
45
+ <div class="lms-certificate-rule"></div>
46
+ <div class="lms-certificate-bottom">
47
+ <div>
48
+ <span class="lms-eyebrow">ISSUED</span>
49
+ <p>
50
+ {new Date(verification.issuedAt).toLocaleDateString("en-IN", {
51
+ year: "numeric",
52
+ month: "long",
53
+ day: "numeric",
54
+ })}
55
+ </p>
56
+ </div>
57
+ <div>
58
+ <span class="lms-eyebrow">STATUS</span>
59
+ <p>{verification.valid ? "Verified completion ✓" : "Revoked"}</p>
60
+ </div>
61
+ </div>
62
+ <small>Certificate {verification.id}</small>
63
+ </article>
64
+ {certificate && (
65
+ <div class="lms-certificate-controls">
66
+ <button class="lms-btn" type="button" data-lms-print>
67
+ Print or save as PDF
68
+ </button>
69
+ <form data-lms-route="learner/certificate/share" data-lms-reload>
70
+ <input type="hidden" name="courseId" value={certificate.courseId} />
71
+ <input type="hidden" name="shared" value={certificate.shared ? "false" : "true"} />
72
+ <button class="lms-btn lms-btn-outline" type="submit">
73
+ {certificate.shared ? "Keep my name private" : "Share my name on verification"}
74
+ </button>
75
+ <p data-lms-feedback aria-live="polite"></p>
76
+ </form>
77
+ <button class="lms-btn lms-btn-outline" type="button" data-lms-copy-link>
78
+ Copy verification link
79
+ </button>
80
+ <p data-lms-copy-status aria-live="polite"></p>
81
+ </div>
82
+ )}
83
+ </section>
@@ -0,0 +1,61 @@
1
+ ---
2
+ import { Image } from "emdash/ui";
3
+ import { courseUrl } from "@anantagnanam/lms/server";
4
+ import { basePath } from "virtual:anantagnanam-lms/config";
5
+ import type { CourseCard } from "@anantagnanam/lms/types";
6
+ interface Props {
7
+ course: CourseCard;
8
+ }
9
+ const { course } = Astro.props;
10
+ ---
11
+
12
+ <article class="lms-course-card">
13
+ <a
14
+ class="lms-card-art"
15
+ href={courseUrl(basePath, course.slug)}
16
+ aria-label={`Explore ${course.title}`}
17
+ tabindex="-1"
18
+ >
19
+ {course.featuredImage ? (
20
+ <Image image={course.featuredImage} width={760} height={440} loading="lazy" />
21
+ ) : (
22
+ <div class="lms-course-cover">
23
+ <svg viewBox="0 0 120 100" width="140" height="116" aria-hidden="true">
24
+ <path
25
+ d="M60 28C45 17 23 18 13 25v55c14-8 31-8 47 2 16-10 33-10 47-2V25c-10-7-32-8-47 3Z"
26
+ fill="none"
27
+ stroke="currentColor"
28
+ stroke-width="3"
29
+ stroke-linejoin="round"
30
+ />
31
+ <path
32
+ d="M60 29v53M25 35c9-2 16-1 24 3M25 46c9-2 16-1 24 3M25 57c9-2 16-1 24 3M71 38c9-4 16-5 24-3M71 49c9-4 16-5 24-3M71 60c9-4 16-5 24-3"
33
+ fill="none"
34
+ stroke="currentColor"
35
+ stroke-width="2"
36
+ stroke-linecap="round"
37
+ />
38
+ </svg>
39
+ <span>{course.category || "A new perspective"}</span>
40
+ </div>
41
+ )}
42
+ <span class="lms-free-label">FREE</span>
43
+ </a>
44
+ <div class="lms-card-body">
45
+ <div class="lms-card-meta">
46
+ <span>{course.category || "Learning"}</span>
47
+ <span>{course.level === "all" ? "All levels" : course.level}</span>
48
+ </div>
49
+ <h2>
50
+ <a href={courseUrl(basePath, course.slug)}>{course.title}</a>
51
+ </h2>
52
+ <p>{course.summary}</p>
53
+ <div class="lms-card-footer">
54
+ <span>
55
+ {course.lessonCount} lessons · {course.durationMinutes} min
56
+ </span>
57
+ <span aria-hidden="true">↗</span>
58
+ </div>
59
+ {course.instructorName && <small>With {course.instructorName}</small>}
60
+ </div>
61
+ </article>