@allons-y/course-kit 0.0.0-stage → 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.
Files changed (137) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +90 -2
  3. package/assets/fonts/instrument-sans-italic-var.woff2 +0 -0
  4. package/assets/fonts/instrument-sans-var.woff2 +0 -0
  5. package/assets/fonts/pt-mono.woff2 +0 -0
  6. package/assets/scripts/copy.js +99 -0
  7. package/assets/scripts/deck.js +161 -0
  8. package/assets/scripts/email.js +19 -0
  9. package/assets/scripts/practice.js +545 -0
  10. package/assets/scripts/theme-panel.js +647 -0
  11. package/assets/scripts/theme-restore.js +17 -0
  12. package/assets/styles/base.css +2091 -0
  13. package/assets/styles/deck.css +968 -0
  14. package/assets/styles/font.css +36 -0
  15. package/assets/styles/notes.css +137 -0
  16. package/assets/styles/print.css +428 -0
  17. package/assets/styles/semantics.css +101 -0
  18. package/components/practice/check-controls.webc +50 -0
  19. package/components/practice/choice-list.webc +86 -0
  20. package/components/practice/cite-panel.webc +108 -0
  21. package/components/practice/practice-figure.webc +47 -0
  22. package/components/practice/practice-fill.webc +154 -0
  23. package/components/practice/practice-grid.webc +82 -0
  24. package/components/practice/practice-judge.webc +165 -0
  25. package/components/practice/practice-match.webc +178 -0
  26. package/components/practice/practice-question.webc +141 -0
  27. package/components/practice/practice-selfcheck.webc +40 -0
  28. package/components/practice/practice-terms.webc +95 -0
  29. package/components/practice/practice-tree.webc +91 -0
  30. package/components/practice/practice-worksheet.webc +369 -0
  31. package/components/site/copyright.webc +13 -0
  32. package/components/site/course-documents.webc +27 -0
  33. package/components/site/course-now.webc +393 -0
  34. package/components/site/course-summary.webc +136 -0
  35. package/components/site/demo-weeks.webc +91 -0
  36. package/components/site/glossary-entry.webc +31 -0
  37. package/components/site/glossary-panel.webc +1482 -0
  38. package/components/site/glossary.webc +45 -0
  39. package/components/site/grading.webc +50 -0
  40. package/components/site/instructor.webc +432 -0
  41. package/components/site/masthead.webc +147 -0
  42. package/components/site/nav-links.webc +174 -0
  43. package/components/site/policies.webc +17 -0
  44. package/components/site/practice-index.webc +31 -0
  45. package/components/site/schedule-overview.webc +145 -0
  46. package/components/site/schedule-weeks.webc +589 -0
  47. package/components/site/site-footer.webc +119 -0
  48. package/components/site/slide-timetable.webc +152 -0
  49. package/components/site/syllabus.webc +370 -0
  50. package/components/ui/arrow-link.webc +19 -0
  51. package/components/ui/assigned-list.webc +101 -0
  52. package/components/ui/callout.webc +11 -0
  53. package/components/ui/card-list.webc +124 -0
  54. package/components/ui/codepen-embed.webc +123 -0
  55. package/components/ui/download-button.webc +49 -0
  56. package/components/ui/eyebrow.webc +18 -0
  57. package/components/ui/icons/github.webc +6 -0
  58. package/components/ui/icons/google.webc +9 -0
  59. package/components/ui/link-list.webc +130 -0
  60. package/components/ui/link-section.webc +40 -0
  61. package/components/ui/meeting-card.webc +73 -0
  62. package/components/ui/meeting-decks.webc +38 -0
  63. package/components/ui/table-rubric.webc +251 -0
  64. package/components/ui/today-link.webc +43 -0
  65. package/components/ui/today-marker.webc +149 -0
  66. package/components/ui/week-block.webc +53 -0
  67. package/examples/starter/_data/course.json +20 -0
  68. package/examples/starter/_data/dates.json +16 -0
  69. package/examples/starter/_data/grading.json +6 -0
  70. package/examples/starter/_data/instructor.json +7 -0
  71. package/examples/starter/_data/policies.json +9 -0
  72. package/examples/starter/_data/scale.json +8 -0
  73. package/examples/starter/_data/schedule.json +22 -0
  74. package/examples/starter/_data/theme.json +17 -0
  75. package/examples/starter/content/index.webc +12 -0
  76. package/examples/starter/content/schedule.webc +12 -0
  77. package/examples/starter/content/slides/index.11tydata.js +5 -0
  78. package/examples/starter/content/slides/index.webc +12 -0
  79. package/examples/starter/content/slides/week-1-day-1.md +40 -0
  80. package/examples/starter/eleventy.config.js +8 -0
  81. package/glue/deck-notes.data.js +41 -0
  82. package/glue/deck-notes.webc +32 -0
  83. package/glue/lesson-day.data.js +17 -0
  84. package/glue/lesson-day.webc +0 -0
  85. package/glue/lesson-plans.data.js +13 -0
  86. package/glue/lesson-plans.webc +2 -0
  87. package/index.js +6 -0
  88. package/layouts/base.webc +79 -0
  89. package/layouts/deck.webc +46 -0
  90. package/layouts/demo.webc +16 -0
  91. package/layouts/document.webc +10 -0
  92. package/layouts/lesson-detail.webc +109 -0
  93. package/layouts/lesson.webc +71 -0
  94. package/layouts/notes.webc +23 -0
  95. package/layouts/worksheet.webc +52 -0
  96. package/lib/assets.js +42 -0
  97. package/lib/bundles.js +79 -0
  98. package/lib/check.js +110 -0
  99. package/lib/components.js +19 -0
  100. package/lib/copy.js +656 -0
  101. package/lib/data/build.js +22 -0
  102. package/lib/data/fonts.js +16 -0
  103. package/lib/data/glossary.js +304 -0
  104. package/lib/data/index.js +8 -0
  105. package/lib/data/lessons.js +173 -0
  106. package/lib/data/project.js +22 -0
  107. package/lib/data/read.js +61 -0
  108. package/lib/data/site.js +70 -0
  109. package/lib/data/term.js +80 -0
  110. package/lib/extensions.js +70 -0
  111. package/lib/files.js +14 -0
  112. package/lib/filters.js +584 -0
  113. package/lib/fit.js +106 -0
  114. package/lib/glue.js +26 -0
  115. package/lib/lesson-materials.js +66 -0
  116. package/lib/markdown.js +568 -0
  117. package/lib/minify.js +53 -0
  118. package/lib/paths.js +5 -0
  119. package/lib/pdf.js +134 -0
  120. package/lib/plugin.js +231 -0
  121. package/lib/plugins.js +34 -0
  122. package/lib/postcss.js +93 -0
  123. package/lib/theme-server.js +88 -0
  124. package/lib/theme.js +185 -0
  125. package/lib/worksheet-dialect.js +415 -0
  126. package/lib/worksheets.js +276 -0
  127. package/package.json +119 -4
  128. package/schemas/course.schema.json +161 -0
  129. package/schemas/dates.schema.json +165 -0
  130. package/schemas/grading.schema.json +59 -0
  131. package/schemas/instructor.schema.json +76 -0
  132. package/schemas/policies.schema.json +90 -0
  133. package/schemas/project.schema.json +209 -0
  134. package/schemas/scale.schema.json +68 -0
  135. package/schemas/schedule.schema.json +260 -0
  136. package/schemas/theme.schema.json +704 -0
  137. package/schemas/worksheet.schema.json +449 -0
@@ -0,0 +1,52 @@
1
+ <!DOCTYPE html>
2
+ <html :lang="site.language ?? 'en-US'" :data-timezone="site.timezone">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta name="color-scheme" content="light dark">
8
+
9
+ <title @text="[$data.title, site.title].filter(Boolean).join(' | ')"></title>
10
+ <meta name="description" :content="$data.description ?? site?.description">
11
+ <meta name="author" :content="site?.author">
12
+ <meta name="generator" :content="eleventy?.generator">
13
+ <meta name="robots" content="noindex, nofollow"
14
+ webc:if="$data.indexed == false || $data.draft == true || $data.instructorOnly == true || $data.site.preview">
15
+
16
+ <link rel="icon" href="/favicon.svg" type="image/svg+xml">
17
+
18
+
19
+ <template webc:nokeep @raw="bundleFile('css', 'content/styles/base.css', $data, 'site')"></template>
20
+ <style webc:keep @raw="getBundle('css', 'site')"></style>
21
+ <style webc:keep @raw="getBundle('css')"></style>
22
+ </head>
23
+
24
+ <body>
25
+ <main id="main-content" tabindex="-1" @raw="content"></main>
26
+
27
+ <script>
28
+ // Print every disclosure expanded, then restore the reader's own state
29
+ // (tracked per element — bundle scripts share one module scope).
30
+ window.addEventListener("beforeprint", () => {
31
+ for (const details of document.querySelectorAll("details:not([open])")) {
32
+ details.open = true;
33
+ details.dataset.printOpened = "";
34
+ }
35
+ });
36
+ window.addEventListener("afterprint", () => {
37
+ for (const details of document.querySelectorAll("details[data-print-opened]")) {
38
+ details.open = false;
39
+ delete details.dataset.printOpened;
40
+ }
41
+ });
42
+ </script>
43
+
44
+ <template webc:nokeep @raw="bundleFile('js', 'content/scripts/practice.js', $data)"></template>
45
+ <script type="application/json" id="copy-data" webc:keep @raw="copyJson($data)"></script>
46
+ <script webc:keep @raw="copyReader()"></script>
47
+ <script type="module" webc:keep @raw="getBundle('js')"></script>
48
+ <theme-panel webc:if="$data.themePanel" context="site"></theme-panel>
49
+ <script type="module" src="/js/theme-panel.js" webc:keep webc:if="$data.themePanel"></script>
50
+ </body>
51
+
52
+ </html>
package/lib/assets.js ADDED
@@ -0,0 +1,42 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ import { packageRoot } from "./paths.js";
5
+
6
+ const root = path.join(packageRoot, "assets");
7
+
8
+ /**
9
+ * Resolve an asset: the course repo's copy wins, else the package's.
10
+ * @param {string} rel path under the input dir, e.g. "styles/deck.css"
11
+ * @param {string} [inputDir] the course repo's input directory
12
+ * @returns {string | null} absolute path, or null when neither has it
13
+ */
14
+ export function assetPath(rel, inputDir = "content") {
15
+ const local = path.resolve(inputDir, rel);
16
+ if (fs.existsSync(local)) return local;
17
+ const shared = path.join(root, rel);
18
+ return fs.existsSync(shared) ? shared : null;
19
+ }
20
+
21
+ /**
22
+ * @param {string} dir
23
+ * @returns {string[]} file names directly in dir; [] when it is missing
24
+ */
25
+ const list = (dir) => (fs.existsSync(dir) ? fs.readdirSync(dir).filter((file) => fs.statSync(path.join(dir, file)).isFile()) : []);
26
+
27
+ /**
28
+ * Publish the package's stylesheets and scripts as virtual templates and its
29
+ * fonts as passthrough copies. Files the course repo also has are skipped.
30
+ * @param {import('@11ty/eleventy').UserConfig} config
31
+ * @param {{ inputDir?: string, exclude?: string[] }} [options] `exclude` lists assets to skip, e.g. ["styles/semantics.css"]
32
+ */
33
+ export function registerAssets(config, { inputDir = "content", exclude = [] } = {}) {
34
+ for (const kind of ["styles", "scripts"]) {
35
+ for (const file of list(path.join(root, kind))) {
36
+ if (exclude.includes(`${kind}/${file}`) || fs.existsSync(path.join(inputDir, kind, file))) continue;
37
+ config.addTemplate(`${kind}/${file}`, fs.readFileSync(path.join(root, kind, file), "utf8"));
38
+ }
39
+ }
40
+ const fonts = list(path.join(root, "fonts")).filter((file) => !fs.existsSync(path.join(inputDir, "fonts", file)));
41
+ config.addPassthroughCopy(Object.fromEntries(fonts.map((file) => [path.join(root, "fonts", file), `/${config.directoryAssignments.fonts}/${file}`])));
42
+ }
package/lib/bundles.js ADDED
@@ -0,0 +1,79 @@
1
+ import { createRequire } from "node:module";
2
+ import { readFile } from "node:fs/promises";
3
+
4
+ import { RenderPlugin } from "@11ty/eleventy";
5
+
6
+ import { assetPath } from "./assets.js";
7
+
8
+ const requireResolve = createRequire(import.meta.url).resolve;
9
+
10
+ /**
11
+ * Register 11ty bundles here for import into eleventy.config.js.
12
+ * @param {import('@11ty/eleventy').TemplateConfig} config
13
+ * @param {{ inputDir?: string }} [options]
14
+ */
15
+ export default function registerBundles(config, { inputDir = "content" } = {}) {
16
+ config.addBundle("css", {
17
+ toFileDirectory: config.directoryAssignments.css,
18
+ });
19
+
20
+ config.addBundle("js", {
21
+ toFileDirectory: config.directoryAssignments.js,
22
+ });
23
+
24
+ let templateConfig;
25
+ let extensionMap;
26
+ config.on("eleventy.config", (instance) => {
27
+ templateConfig = instance;
28
+ });
29
+ config.on("eleventy.extensionmap", (map) => {
30
+ extensionMap = map;
31
+ });
32
+
33
+ /**
34
+ * Render a template file into a page's `css` or `js` bundle, for
35
+ * `getBundle(type)` to inline; strips front matter and swaps `deck.css`'s
36
+ * font import for the inlined data URIs on an embedded render, so a deck
37
+ * saved to disk still has its fonts.
38
+ * @param {"css"|"js"} type bundle name
39
+ * @param {string} inputPath project-relative, e.g. "content/styles/deck.css"
40
+ * @param {object} data the calling page's data cascade (`$data`)
41
+ * @param {string} [bucket] bundle bucket; a page emits buckets in the order
42
+ * it needs them, which is how site CSS stays ahead of component CSS
43
+ * @returns {Promise<string>} always empty — the code lands in the bundle
44
+ */
45
+ config.addJavaScriptFunction("bundleFile", async (type, inputPath, data, bucket = "default") => {
46
+ const options = { templateConfig, extensionMap };
47
+ const context = { page: data.page, eleventy: data.eleventy };
48
+ const located = inputPath.startsWith(`${inputDir}/`) ? assetPath(inputPath.slice(inputDir.length + 1), inputDir) : null;
49
+ const source = await readFile(located ?? inputPath, "utf8");
50
+ const body = source.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, "");
51
+ const render =
52
+ body === source
53
+ ? await RenderPlugin.File.call(context, located ?? inputPath, options)
54
+ : await RenderPlugin.String.call(context, body, extensionMap.getKey(inputPath), options);
55
+ let code = await render({ ...data, embed: true });
56
+ if (type === "css" && data.fontFaces) {
57
+ // Regex, not a literal string match: cssnano may reformat the
58
+ // import's quotes/whitespace in production before this runs.
59
+ code = code.replace(/@import\s*(?:url\()?["']?font\.css["']?\)?\s*;/, data.fontFaces);
60
+ }
61
+ return config.getPairedShortcode(type).call(context, code, bucket, data.page.url);
62
+ });
63
+
64
+ /**
65
+ * Add a vendored stylesheet or script to a page's bundle, verbatim.
66
+ * Resolved through `require.resolve`, never an assembled `node_modules`
67
+ * path, so it survives a linker change.
68
+ * @param {"css"|"js"} type bundle name
69
+ * @param {string} spec module specifier, e.g. "prism-themes/themes/prism-coldark-cold.css"
70
+ * @param {object} data the calling page's data cascade (`$data`)
71
+ * @param {string} [bucket] bundle bucket, as for `bundleFile`
72
+ * @returns {Promise<string>} always empty — the code lands in the bundle
73
+ */
74
+ config.addJavaScriptFunction("bundleVendor", async (type, spec, data, bucket = "default") => {
75
+ const context = { page: data.page, eleventy: data.eleventy };
76
+ const code = await readFile(requireResolve(spec), "utf8");
77
+ return config.getPairedShortcode(type).call(context, code, bucket, data.page.url);
78
+ });
79
+ }
package/lib/check.js ADDED
@@ -0,0 +1,110 @@
1
+ /** The options `courseKit` accepts. A group lists its own keys; `null` means a plain value. */
2
+ const OPTIONS = {
3
+ inputDir: null,
4
+ outputDir: null,
5
+ dataDir: null,
6
+ components: null,
7
+ theme: null,
8
+ copy: null,
9
+ clientCopy: null,
10
+ institution: ["name", "timezone", "lms"],
11
+ site: ["description", "keywords", "language"],
12
+ lessons: ["segments", "defaultDays"],
13
+ demos: ["runtime", "dir"],
14
+ slides: ["decks"],
15
+ pdf: ["course", "term", "dataDir"],
16
+ prism: ["theme", "plugins"],
17
+ worksheets: ["checkMode"],
18
+ };
19
+
20
+ const RUNTIMES = ["none", "codepen", "pyscript"];
21
+
22
+ /** How many single-character edits turn one word into another. */
23
+ const distance = (a, b) => {
24
+ const row = Array.from({ length: b.length + 1 }, (_, index) => index);
25
+ for (let i = 1; i <= a.length; i++) {
26
+ let previous = row[0];
27
+ row[0] = i;
28
+ for (let j = 1; j <= b.length; j++) {
29
+ const above = row[j];
30
+ row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
31
+ previous = above;
32
+ }
33
+ }
34
+ return row[b.length];
35
+ };
36
+
37
+ /**
38
+ * " Did you mean `demos`?" for a near miss, else the full list.
39
+ * @param {string} name
40
+ * @param {string[]} valid
41
+ * @returns {string}
42
+ */
43
+ const hint = (name, valid) => {
44
+ const close = valid.find((candidate) => distance(name.toLowerCase(), candidate.toLowerCase()) <= 2);
45
+ return close ? ` Did you mean \`${close}\`?` : ` The options are: ${valid.join(", ")}.`;
46
+ };
47
+
48
+ /**
49
+ * Fail at startup, in plain language, on an option that would otherwise be
50
+ * ignored: a misspelled name, a runtime that does not exist, a time zone no
51
+ * computer knows.
52
+ * @param {object} [options] what the course passed to `courseKit`
53
+ * @throws {Error}
54
+ */
55
+ export function checkOptions(options = {}) {
56
+ if (options === null || typeof options !== "object" || Array.isArray(options)) {
57
+ throw new Error("courseKit(config, options): options must be an object, such as { institution: { name: \"My College\" } }.");
58
+ }
59
+ for (const [name, value] of Object.entries(options)) {
60
+ if (!(name in OPTIONS)) throw new Error(`courseKit: unknown option \`${name}\`.${hint(name, Object.keys(OPTIONS))}`);
61
+ const keys = OPTIONS[name];
62
+ if (!keys || value === undefined || (name === "pdf" && value === false)) continue;
63
+ if (value === null || typeof value !== "object") throw new Error(`courseKit: \`${name}\` must be an object with ${keys.map((key) => `\`${key}\``).join(", ")}.`);
64
+ for (const key of Object.keys(value)) {
65
+ if (!keys.includes(key)) throw new Error(`courseKit: unknown option \`${name}.${key}\`.${hint(key, keys)}`);
66
+ }
67
+ }
68
+ const runtime = options.demos?.runtime;
69
+ if (runtime !== undefined && !RUNTIMES.includes(runtime)) {
70
+ throw new Error(`courseKit: \`demos.runtime\` is "${runtime}", but it must be one of ${RUNTIMES.map((name) => `"${name}"`).join(", ")}.`);
71
+ }
72
+ const timeZone = options.institution?.timezone;
73
+ if (timeZone !== undefined) {
74
+ try {
75
+ new Intl.DateTimeFormat("en-US", { timeZone });
76
+ } catch {
77
+ throw new Error(`courseKit: \`institution.timezone\` is "${timeZone}", which is not a time zone name. Use one like "America/New_York".`);
78
+ }
79
+ }
80
+ const checkMode = options.worksheets?.checkMode;
81
+ if (checkMode !== undefined && !["question", "end"].includes(checkMode)) {
82
+ throw new Error(`courseKit: \`worksheets.checkMode\` is "${checkMode}", but it must be "question" or "end".`);
83
+ }
84
+ if (options.components !== undefined && !Array.isArray(options.components)) {
85
+ throw new Error("courseKit: `components` must be a list of file patterns, such as [\"components/*.webc\"].");
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Problems in the course's data that do not stop the build but would give a
91
+ * wrong page: grade weights that do not total 100%, project pieces that do not
92
+ * total the project's points.
93
+ * @param {{ grading?: object, project?: object }} data
94
+ * @returns {string[]}
95
+ */
96
+ export function courseWarnings({ grading, project } = {}) {
97
+ const warnings = [];
98
+ const weights = Object.entries(grading ?? {})
99
+ .filter(([key]) => key !== "$schema")
100
+ .map(([, category]) => parseFloat(category?.weight));
101
+ if (weights.length && weights.every((weight) => !Number.isNaN(weight))) {
102
+ const total = weights.reduce((sum, weight) => sum + weight, 0);
103
+ if (Math.round(total * 100) !== 10000) warnings.push(`grading.json: the weights add up to ${total}%, not 100%.`);
104
+ }
105
+ if (Array.isArray(project?.components) && typeof project.scale === "number") {
106
+ const points = project.components.reduce((sum, piece) => sum + (piece.points ?? 0), 0);
107
+ if (points !== project.scale) warnings.push(`project.json: the components add up to ${points} points, but the project's scale is ${project.scale}.`);
108
+ }
109
+ return warnings;
110
+ }
@@ -0,0 +1,19 @@
1
+ import path from "node:path";
2
+
3
+ import { walk } from "./files.js";
4
+ import { packageRoot } from "./paths.js";
5
+
6
+ const isComponent = (name) => name.endsWith(".webc");
7
+
8
+ /**
9
+ * Package components minus any the course repo also defines (WebC throws on a
10
+ * duplicate name), then the course's own.
11
+ * @param {string} [localDir] the course repo's component directory
12
+ * @returns {string[]} file paths for the WebC plugin's `components` option
13
+ */
14
+ export function componentFiles(localDir = "_includes") {
15
+ const local = walk(localDir, isComponent);
16
+ const taken = new Set(local.map((file) => path.basename(file, ".webc")));
17
+ const shared = walk(path.join(packageRoot, "components"), isComponent).filter((file) => !taken.has(path.basename(file, ".webc")));
18
+ return [...shared, ...local];
19
+ }