@allons-y/course-kit 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 (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 +17 -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 +2090 -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 +269 -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 +217 -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 +653 -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 +46 -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 +228 -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 +118 -4
  128. package/schemas/course.schema.json +156 -0
  129. package/schemas/dates.schema.json +165 -0
  130. package/schemas/grading.schema.json +59 -0
  131. package/schemas/instructor.schema.json +68 -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,1482 @@
1
+ <script webc:setup>
2
+ /**
3
+ * The glossary's element: the grouped list it wraps (the slot), which the
4
+ * script at the foot of this file replaces with Review and Flashcards.
5
+ * One stylesheet covers both, since the script renders the same markup the
6
+ * server does.
7
+ * @prop {string} json the terms and tags the script reads, as a JSON string
8
+ * @slot default the static, grouped list inside `[data-static]`
9
+ */
10
+ </script>
11
+ <glossary-app webc:root="override">
12
+ <slot></slot>
13
+ <div data-app hidden></div>
14
+ <script type="application/json" webc:keep @raw="json"></script>
15
+ </glossary-app>
16
+
17
+ <style webc:scoped>
18
+ :host {
19
+ display: block;
20
+ --chip-size: var(--target-min);
21
+ --count-gap: 0.65rem;
22
+
23
+ /* ---- Tag palette: one hue per kind of tag ----
24
+ Test is amber, reading (chapter) is blue, class meeting is green; none is
25
+ the teal or magenta a course accents with. The three hues are theme tokens
26
+ (`tag-test`, `tag-reading`, `tag-meeting`); each kind's tints derive from
27
+ its hue: -bg/-fg/-border colour a label or an unpressed chip, -on-bg/-on-fg
28
+ a pressed chip, -mark the accent on a group heading. */
29
+ [data-kind="test"] {
30
+ --k-mark: var(--color-tag-test);
31
+ }
32
+
33
+ [data-kind="chapter"] {
34
+ --k-mark: var(--color-tag-reading);
35
+ }
36
+
37
+ [data-kind="meeting"] {
38
+ --k-mark: var(--color-tag-meeting);
39
+ }
40
+
41
+ [data-kind] {
42
+ --k-bg: color-mix(in oklab, var(--k-mark) 14%, var(--color-page));
43
+ --k-fg: color-mix(in oklab, var(--k-mark) 25%, var(--color-text));
44
+ --k-border: var(--k-mark);
45
+ --k-on-bg: color-mix(in oklab, var(--k-mark) 40%, var(--color-text));
46
+ --k-on-fg: var(--color-page);
47
+ }
48
+
49
+ /* ---- Controls ---- */
50
+ .bar {
51
+ display: flex;
52
+ flex-wrap: wrap;
53
+ align-items: center;
54
+ justify-content: space-between;
55
+ gap: calc(var(--gutter) * 3) calc(var(--content-space) * 1.5);
56
+ margin-block: calc(var(--content-space) * 1.5) var(--content-space);
57
+ padding-block: var(--content-space);
58
+ border-block: var(--thin-border-width) solid var(--color-border);
59
+
60
+ @media (width <= 600px) {
61
+ flex-direction: column;
62
+ align-items: flex-start;
63
+ }
64
+ }
65
+
66
+ .bar-group {
67
+ display: flex;
68
+ flex-wrap: wrap;
69
+ align-items: center;
70
+ gap: calc(var(--gutter) * 2) var(--content-space);
71
+ }
72
+
73
+ .label {
74
+ font-size: var(--font-size-6);
75
+ font-weight: var(--font-weight--semi-bold);
76
+ letter-spacing: 0.08em;
77
+ text-transform: uppercase;
78
+ color: var(--color-text-muted);
79
+ }
80
+
81
+ button:not(.switch-option) {
82
+ margin: 0;
83
+ min-block-size: var(--chip-size);
84
+ color: var(--color-text);
85
+ background-color: var(--color-surface);
86
+ border: var(--thin-border-width) solid var(--color-border-strong);
87
+ font-weight: var(--font-weight--medium);
88
+ cursor: pointer;
89
+ line-height: var(--font-height--dense);
90
+
91
+
92
+ &:disabled {
93
+ opacity: 0.45;
94
+ cursor: default;
95
+ }
96
+ }
97
+
98
+ .filters[open] summary::before {
99
+ content: "\25BE";
100
+ content: "\25BE" / "";
101
+ }
102
+
103
+ .filters {
104
+ margin: 0;
105
+ padding: 0;
106
+ padding-block-end: calc(var(--gutter) * 2);
107
+ border: 0;
108
+ border-block-end: var(--thin-border-width) solid var(--color-border);
109
+ border-radius: 0;
110
+ background: none;
111
+
112
+ summary {
113
+ cursor: pointer;
114
+ font-weight: var(--font-weight--medium);
115
+ min-block-size: var(--chip-size);
116
+ display: flex;
117
+ align-items: center;
118
+ gap: 0.5em;
119
+
120
+ &::before {
121
+ content: "\25B8";
122
+ content: "\25B8" / "";
123
+ color: var(--color-accent-text);
124
+ }
125
+
126
+ }
127
+ }
128
+
129
+ .filter-rows {
130
+ display: grid;
131
+ gap: var(--content-space);
132
+ padding: calc(var(--gutter) * 2) 0 var(--content-space);
133
+ }
134
+
135
+ .filter-row {
136
+ display: flex;
137
+ flex-wrap: wrap;
138
+ align-items: center;
139
+ gap: calc(var(--gutter) * 2);
140
+
141
+ &[hidden] {
142
+ display: none;
143
+ }
144
+
145
+ > .label {
146
+ inline-size: 6em;
147
+ }
148
+
149
+ .chips {
150
+ display: flex;
151
+ flex-wrap: wrap;
152
+ gap: calc(var(--gutter) * 2);
153
+ }
154
+ }
155
+
156
+ .chip {
157
+ display: inline-flex;
158
+ align-items: center;
159
+ gap: var(--count-gap);
160
+ padding: 0.3em 0.8em;
161
+ border-radius: var(--pill-border-radius);
162
+
163
+ .t {
164
+ display: inline-flex;
165
+ align-items: center;
166
+ gap: 0.4em;
167
+ }
168
+
169
+ .n {
170
+ color: var(--color-text-muted);
171
+ font-size: 0.85em;
172
+ font-weight: var(--font-weight);
173
+ font-variant-numeric: tabular-nums;
174
+ }
175
+
176
+ &[data-kind] {
177
+ background-color: var(--k-bg);
178
+ border-color: var(--k-border);
179
+ color: var(--k-fg);
180
+
181
+ .n {
182
+ color: color-mix(in srgb, var(--k-fg) 78%, var(--k-bg));
183
+ }
184
+ }
185
+
186
+ &[aria-pressed="true"] {
187
+ background-color: var(--color-surface-accent);
188
+ border-color: var(--color-accent-text);
189
+ border-width: var(--border-width);
190
+ font-weight: var(--font-weight--bold);
191
+
192
+ .t::before {
193
+ content: "\2713";
194
+ content: "\2713" / "";
195
+ }
196
+
197
+ .n {
198
+ color: inherit;
199
+ }
200
+
201
+ &[data-kind] {
202
+ background-color: var(--k-on-bg);
203
+ border-color: var(--k-on-bg);
204
+ color: var(--k-on-fg);
205
+
206
+ .n {
207
+ color: color-mix(in srgb, var(--k-on-fg) 85%, var(--k-on-bg));
208
+ }
209
+ }
210
+ }
211
+
212
+ /* The class meeting a link pre-filtered the list to: removable, no row of its own. */
213
+ &.pill {
214
+ font-weight: var(--font-weight--medium);
215
+
216
+ &[data-kind] {
217
+ background-color: var(--k-on-bg);
218
+ border-color: var(--k-on-bg);
219
+ color: var(--k-on-fg);
220
+ }
221
+
222
+ &::after {
223
+ content: "\00D7";
224
+ content: "\00D7" / "";
225
+ font-size: 1.2em;
226
+ line-height: 1;
227
+ }
228
+ }
229
+ }
230
+
231
+ .search {
232
+ display: flex;
233
+ flex-wrap: wrap;
234
+ align-items: center;
235
+ gap: calc(var(--gutter) * 2) var(--content-space);
236
+ padding-block: var(--content-space) 0;
237
+
238
+ .field {
239
+ position: relative;
240
+ display: flex;
241
+ flex: 1 1 18rem;
242
+ max-inline-size: 28rem;
243
+ }
244
+
245
+ input {
246
+ inline-size: 100%;
247
+ min-block-size: var(--chip-size);
248
+ margin: 0;
249
+ padding-inline: 0.8em 4.5em;
250
+ color: var(--color-text);
251
+ background-color: var(--color-page);
252
+ border: var(--thin-border-width) solid var(--color-text-muted);
253
+ border-radius: var(--standard-border-radius);
254
+ font: inherit;
255
+
256
+
257
+ &::-webkit-search-cancel-button {
258
+ display: none;
259
+ }
260
+ }
261
+
262
+ .clear-search {
263
+ position: absolute;
264
+ inset-block: 0;
265
+ inset-inline-end: 0;
266
+ padding-inline: 0.8em;
267
+ border: 0;
268
+ background: none;
269
+ color: var(--color-accent-text);
270
+ text-decoration: underline;
271
+ }
272
+ }
273
+
274
+ .status {
275
+ margin-block: calc(var(--content-space) * 0.75) 0;
276
+ color: var(--color-text-muted);
277
+
278
+ button {
279
+ min-block-size: var(--chip-size);
280
+ padding-inline: 0.5em;
281
+ border: 0;
282
+ background: none;
283
+ color: var(--color-accent-text);
284
+ text-decoration: underline;
285
+ }
286
+ }
287
+
288
+ /* ---- Review ---- */
289
+ .group {
290
+ padding-block-start: calc(var(--content-space) * 1.8);
291
+
292
+ .heading {
293
+ display: flex;
294
+ flex-wrap: wrap;
295
+ align-items: baseline;
296
+ justify-content: space-between;
297
+ gap: calc(var(--gutter) * 2) calc(var(--content-space) * 0.8);
298
+ margin-block: 0;
299
+ font-size: var(--font-size-4);
300
+ font-weight: var(--font-weight--semi-bold);
301
+
302
+ .aside {
303
+ display: flex;
304
+ flex-wrap: wrap;
305
+ align-items: baseline;
306
+ justify-content: flex-end;
307
+ gap: calc(var(--gutter) * 2) calc(var(--content-space) * 0.8);
308
+ }
309
+
310
+ .when,
311
+ .count,
312
+ .deck {
313
+ color: var(--color-text-muted);
314
+ font-size: var(--font-size-5);
315
+ font-weight: var(--font-weight);
316
+ font-variant-numeric: tabular-nums;
317
+ }
318
+ }
319
+
320
+ /* The accent mark names the kind a heading groups by. */
321
+ &[data-kind] .heading {
322
+ padding-inline-start: 0.6em;
323
+ border-inline-start: var(--thick-border-width) solid var(--k-mark);
324
+ }
325
+
326
+ /* Terms sit as cards in a grid that falls to one column on a phone. */
327
+ dl {
328
+ display: grid;
329
+ grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
330
+ gap: var(--content-space);
331
+ margin-block: calc(var(--content-space) * 0.6) 0;
332
+ }
333
+ }
334
+
335
+ .entry {
336
+ display: flex;
337
+ flex-direction: column;
338
+ gap: calc(var(--gutter) * 2);
339
+ padding: calc(var(--content-space) * 1.1) calc(var(--content-space) * 1.2);
340
+ border: var(--thin-border-width) solid var(--color-border);
341
+ border-radius: calc(var(--standard-border-radius) * 3);
342
+ background-color: var(--color-surface);
343
+ break-inside: avoid;
344
+
345
+ dt {
346
+ font-size: var(--font-size-4);
347
+ display: flex;
348
+ flex-wrap: wrap;
349
+ align-content: start;
350
+ align-items: baseline;
351
+ gap: calc(var(--gutter) * 1.5) calc(var(--gutter) * 2);
352
+ color: var(--color-text);
353
+ font-weight: var(--font-weight--bold);
354
+ overflow-wrap: anywhere;
355
+ }
356
+
357
+ dd {
358
+ margin: 0;
359
+ min-inline-size: 0;
360
+
361
+ p {
362
+ margin-block: 0;
363
+ }
364
+
365
+ p + p,
366
+ ul + p,
367
+ p + ul {
368
+ margin-block-start: calc(var(--gutter) * 1.5);
369
+ }
370
+ }
371
+
372
+ .api-group,
373
+ .known {
374
+ font-size: var(--font-size-6);
375
+ font-weight: var(--font-weight);
376
+ color: var(--color-text-muted);
377
+ }
378
+
379
+ .known {
380
+ color: var(--color-success);
381
+ }
382
+
383
+ .sig {
384
+ font-family: var(--mono-font);
385
+ font-size: var(--mono-font-size);
386
+ }
387
+
388
+ .meta,
389
+ .example {
390
+ color: var(--color-text-muted);
391
+ }
392
+
393
+ .example code,
394
+ .sig {
395
+ overflow-wrap: anywhere;
396
+ }
397
+
398
+ .links .label {
399
+ align-self: center;
400
+ color: var(--color-text-muted);
401
+ }
402
+
403
+ .label {
404
+ margin-inline-end: 0.3em;
405
+ font-size: var(--font-size-6);
406
+ letter-spacing: 0.08em;
407
+ text-transform: uppercase;
408
+ }
409
+
410
+ .tags {
411
+ display: flex;
412
+ flex-wrap: wrap;
413
+ gap: calc(var(--gutter) * 1.5);
414
+ margin: 0;
415
+ padding: 0;
416
+ list-style: none;
417
+
418
+ li {
419
+ padding: 0.1em 0.55em;
420
+ border-radius: var(--standard-border-radius);
421
+ background-color: var(--color-surface);
422
+ font-size: var(--font-size-6);
423
+ line-height: var(--font-height);
424
+
425
+ &[data-kind] {
426
+ border: var(--thin-border-width) solid var(--k-border);
427
+ background-color: var(--k-bg);
428
+ color: var(--k-fg);
429
+ }
430
+ }
431
+ }
432
+
433
+ .links {
434
+ display: flex;
435
+ flex-wrap: wrap;
436
+ gap: 0 calc(var(--content-space) * 1.1);
437
+ font-size: var(--font-size-6);
438
+
439
+ a {
440
+ padding-block: 0.25em;
441
+ }
442
+ }
443
+ }
444
+
445
+ .empty {
446
+ display: grid;
447
+ justify-items: center;
448
+ gap: calc(var(--gutter) * 2);
449
+ padding: calc(var(--content-space) * 2.5) var(--content-space);
450
+ text-align: center;
451
+ color: var(--color-text-muted);
452
+
453
+ strong {
454
+ color: var(--color-text);
455
+ font-size: var(--font-size-4);
456
+ }
457
+ }
458
+
459
+ /* ---- Flashcards ---- */
460
+ .study {
461
+ display: grid;
462
+ gap: var(--content-space);
463
+ padding-block-start: var(--content-space);
464
+ }
465
+
466
+ .study[hidden] {
467
+ display: none;
468
+ }
469
+
470
+ .study-top {
471
+ display: flex;
472
+ flex-wrap: wrap;
473
+ align-items: center;
474
+ gap: calc(var(--gutter) * 2) var(--content-space);
475
+ color: var(--color-text-muted);
476
+ font-variant-numeric: tabular-nums;
477
+
478
+ .opts {
479
+ display: flex;
480
+ flex-wrap: wrap;
481
+ gap: calc(var(--gutter) * 2);
482
+ margin-inline-start: auto;
483
+ }
484
+ }
485
+
486
+ .meter {
487
+ block-size: 4px;
488
+ border-radius: 2px;
489
+ background-color: var(--color-surface);
490
+ overflow: hidden;
491
+
492
+ i {
493
+ display: block;
494
+ block-size: 100%;
495
+ background-color: var(--color-accent);
496
+
497
+ @media (prefers-reduced-motion: no-preference) {
498
+ transition: inline-size 0.25s;
499
+ }
500
+ }
501
+ }
502
+
503
+ .card {
504
+ display: grid;
505
+ grid-template-rows: auto 1fr auto;
506
+ gap: calc(var(--content-space) * 0.7);
507
+ min-block-size: 15rem;
508
+ padding: calc(var(--content-space) * 1.5);
509
+ border: var(--thin-border-width) solid var(--color-border);
510
+ border-radius: calc(var(--standard-border-radius) * 3);
511
+ background-color: var(--color-surface);
512
+
513
+
514
+ .top {
515
+ display: flex;
516
+ justify-content: space-between;
517
+ gap: var(--content-space);
518
+ font-size: var(--font-size-6);
519
+ color: var(--color-text-muted);
520
+
521
+ span {
522
+ padding: 0.1em 0.55em;
523
+ border-radius: var(--standard-border-radius);
524
+ line-height: var(--font-height);
525
+ }
526
+
527
+ span[data-kind] {
528
+ border: var(--thin-border-width) solid var(--k-border);
529
+ background-color: var(--k-bg);
530
+ color: var(--k-fg);
531
+ }
532
+ }
533
+
534
+ .content {
535
+ align-self: center;
536
+ display: grid;
537
+ gap: var(--content-space);
538
+ }
539
+
540
+ .front {
541
+ text-align: center;
542
+ font-size: clamp(1.6rem, 5vw, 2.3rem);
543
+ font-weight: var(--font-weight--bold);
544
+ overflow-wrap: anywhere;
545
+
546
+ small {
547
+ display: block;
548
+ margin-block-start: calc(var(--gutter) * 1.5);
549
+ font-size: var(--font-size-5);
550
+ font-weight: var(--font-weight);
551
+ color: var(--color-text-muted);
552
+ }
553
+
554
+ .sig {
555
+ display: block;
556
+ margin-block-start: var(--content-space);
557
+ font-family: var(--mono-font);
558
+ font-size: var(--font-size-5);
559
+ font-weight: var(--font-weight);
560
+ }
561
+ }
562
+
563
+ .back {
564
+ display: grid;
565
+ gap: calc(var(--gutter) * 2);
566
+
567
+ p {
568
+ margin-block: 0;
569
+ }
570
+
571
+ .definition {
572
+ font-size: var(--font-size-4);
573
+ }
574
+
575
+ .sig {
576
+ font-family: var(--mono-font);
577
+ }
578
+
579
+ .meta,
580
+ .example {
581
+ color: var(--color-text-muted);
582
+ }
583
+
584
+ .label {
585
+ margin-inline-end: 0.3em;
586
+ font-size: var(--font-size-6);
587
+ letter-spacing: 0.08em;
588
+ text-transform: uppercase;
589
+ }
590
+
591
+ .links {
592
+ display: flex;
593
+ flex-wrap: wrap;
594
+ gap: 0 var(--content-space);
595
+ font-size: var(--font-size-6);
596
+
597
+ a {
598
+ padding-block: 0.25em;
599
+ }
600
+ }
601
+ }
602
+
603
+ .foot {
604
+ display: flex;
605
+ justify-content: center;
606
+ }
607
+ }
608
+
609
+ .primary {
610
+ padding-inline: 1.4em;
611
+ background-color: var(--color-text);
612
+ border-color: var(--color-text);
613
+ color: var(--color-page);
614
+ font-weight: var(--font-weight--semi-bold);
615
+ }
616
+
617
+ .verdict {
618
+ display: flex;
619
+ flex-wrap: wrap;
620
+ justify-content: center;
621
+ gap: calc(var(--gutter) * 3);
622
+
623
+ button {
624
+ padding-inline: 1.2em;
625
+ min-block-size: 2.75rem;
626
+ }
627
+
628
+ .yes {
629
+ border-color: var(--color-success);
630
+ color: var(--color-success);
631
+ }
632
+ }
633
+
634
+ .nav {
635
+ display: flex;
636
+ align-items: center;
637
+ justify-content: space-between;
638
+ gap: calc(var(--gutter) * 3);
639
+ color: var(--color-text-muted);
640
+
641
+ button {
642
+ border: 0;
643
+ background: none;
644
+ min-block-size: 2.75rem;
645
+ padding-inline: 0.6em;
646
+ text-decoration: underline;
647
+ white-space: nowrap;
648
+ }
649
+
650
+ .hint {
651
+ text-align: center;
652
+ font-size: var(--font-size-6);
653
+ }
654
+ }
655
+
656
+ .done {
657
+ display: grid;
658
+ justify-items: center;
659
+ gap: var(--content-space);
660
+ padding: calc(var(--content-space) * 2) var(--content-space);
661
+ text-align: center;
662
+
663
+ .heading {
664
+ margin: 0;
665
+ font-size: var(--font-size-3);
666
+ font-weight: var(--font-weight--semi-bold);
667
+ }
668
+ }
669
+
670
+ /* ---- Print: a plain glossary, every group open, no controls ---- */
671
+ @media print {
672
+ [data-review][hidden] {
673
+ display: block;
674
+ }
675
+
676
+ .bar,
677
+ .filters,
678
+ .status,
679
+ .study,
680
+ .search,
681
+ .verdict {
682
+ display: none;
683
+ }
684
+
685
+ .tags li,
686
+ .tags li[data-kind] {
687
+ border: var(--thin-border-width) solid var(--color-border);
688
+ background: none;
689
+ color: inherit;
690
+ }
691
+
692
+ .group {
693
+ break-inside: auto;
694
+ }
695
+
696
+ .heading {
697
+ break-after: avoid;
698
+ }
699
+ }
700
+ }
701
+ </style>
702
+
703
+ <script>
704
+ // Bundle scripts share one module scope, so this one keeps its names to itself.
705
+ (() => {
706
+ /**
707
+ * The course glossary: Review and Flashcards over one tagged, filterable list.
708
+ *
709
+ * Enhances the plain list `<glossary-panel>` renders on the server. It
710
+ * reads the terms from the page's JSON, builds the controls, and removes the
711
+ * static list once it has rendered. The page never reads the clock. The query
712
+ * string (`mode`, `group`, `test`, `reading`, `meeting`, `q`) sets the starting
713
+ * state and is kept in step as the reader changes it.
714
+ */
715
+
716
+ /**
717
+ * @typedef {object} Tag
718
+ * @property {string} key
719
+ * @property {string} label
720
+ * @property {number} order
721
+ * @property {string} [when] the date for display
722
+ * @property {string} [deck] deck title (meeting)
723
+ * @property {number} [n] terms carrying the tag under the other row's filter
724
+ *
725
+ * @typedef {object} Place
726
+ * @property {number} week
727
+ * @property {number} slide
728
+ * @property {string} weekday
729
+ * @property {string} href
730
+ *
731
+ * @typedef {object} Term
732
+ * @property {string} id
733
+ * @property {string} term HTML
734
+ * @property {string} plain
735
+ * @property {string} key letters and digits only, lowercased: the sort and search key
736
+ * @property {number} azOrder position in A to Z order, from the loader
737
+ * @property {{ key: string, label: string }} azGroup "0 to 9", a letter or "Symbols"
738
+ * @property {string} group
739
+ * @property {string} definition HTML
740
+ * @property {string} example HTML
741
+ * @property {string} meta HTML
742
+ * @property {string} sig HTML
743
+ * @property {{ label: string, href: string }|null} ref
744
+ * @property {Record<string, Tag[]>} tags
745
+ * @property {Place[]} taught
746
+ */
747
+
748
+ const { t } = window.ckCopy;
749
+
750
+ const KINDS = ["test", "chapter", "meeting", "topic"];
751
+ /** The two kinds with a chip row. */
752
+ const FILTERS = ["test", "chapter"];
753
+ /** Every kind a link can filter by; `meeting` has a removable pill instead of a row. */
754
+ const FILTERED = ["test", "chapter", "meeting"];
755
+ const PARAMS = ["mode", "group", "test", "reading", "meeting", "q"];
756
+
757
+ /** Site root (or the Pages path prefix), taken from where this script is served. */
758
+ const BASE = new URL("../", import.meta.url).pathname;
759
+
760
+ /** @param {unknown} text */
761
+ const esc = (text) => String(text ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
762
+
763
+ /** @param {string} text */
764
+ const slug = (text) => text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
765
+
766
+ /** localStorage that never throws (private windows, blocked storage). */
767
+ const store = {
768
+ /** @param {string} key */
769
+ get(key) {
770
+ try {
771
+ return localStorage.getItem(key);
772
+ } catch {
773
+ return null;
774
+ }
775
+ },
776
+ /**
777
+ * @param {string} key
778
+ * @param {string} value
779
+ */
780
+ set(key, value) {
781
+ try {
782
+ localStorage.setItem(key, value);
783
+ } catch {
784
+ // Progress just won't persist.
785
+ }
786
+ },
787
+ };
788
+
789
+ /**
790
+ * Build the glossary's controls inside its element, and remove the static list.
791
+ * @param {HTMLElement} root the `<glossary-app>` element
792
+ * @param {AbortSignal} signal ends the page-level listeners when the element leaves the page
793
+ */
794
+ function mount(root, signal) {
795
+ const app = /** @type {HTMLElement | null} */ (root.querySelector("[data-app]"));
796
+ const source = root.querySelector('script[type="application/json"]');
797
+ if (!app || !source) return;
798
+
799
+ const data = JSON.parse(source.textContent);
800
+ const label = data.readingLabel;
801
+ /** Two instances on a page never share an id: every id starts with the mount element's. */
802
+ const prefix = root.id || "glossary";
803
+ const dims = [
804
+ ["az", t("glossary", "byAz")],
805
+ ["test", t("glossary", "byTest")],
806
+ ["chapter", label],
807
+ ["meeting", t("glossary", "byMeeting")],
808
+ ];
809
+
810
+ const tagsOf = Object.fromEntries(KINDS.map((kind) => [kind, new Map(data.tags[kind].map((tag) => [tag.key, tag]))]));
811
+
812
+ /** @type {Term[]} */
813
+ const terms = data.terms.map((term) => ({
814
+ ...term,
815
+ tags: Object.fromEntries(KINDS.map((kind) => [kind, term.tags[kind].map((key) => tagsOf[kind].get(key))])),
816
+ }));
817
+
818
+ // ---- The starting state, from the query string (untrusted: matched against known keys only) ----
819
+
820
+ const params = new URLSearchParams(location.search);
821
+ const listOf = (name) => params.getAll(name).flatMap((value) => value.split(",")).map((value) => value.trim().toLowerCase()).filter(Boolean);
822
+ const lastNumber = (text) => text.match(/(\d+)\s*$/)?.[1];
823
+
824
+ /**
825
+ * The tag keys of `kind` that the values name: a key, its slug or label slug, `n` for `test-n`,
826
+ * or a bare number where a label ends in one.
827
+ * @param {string} kind
828
+ * @param {string[]} values
829
+ */
830
+ const resolve = (kind, values) =>
831
+ new Set(
832
+ data.tags[kind]
833
+ .filter((tag) =>
834
+ values.some(
835
+ (value) =>
836
+ tag.key.toLowerCase() === value ||
837
+ slug(tag.key) === slug(value) ||
838
+ slug(tag.label) === slug(value) ||
839
+ (kind === "test" && tag.key === `test-${value}`) ||
840
+ (/^\d+$/.test(value) && lastNumber(tag.label) === value),
841
+ ),
842
+ )
843
+ .map((tag) => tag.key),
844
+ );
845
+
846
+ const startBy = (() => {
847
+ const value = params.get("group")?.trim().toLowerCase();
848
+ if (value === "reading" || value === label.toLowerCase()) return "chapter";
849
+ return dims.some(([dim]) => dim === value) ? value : "az";
850
+ })();
851
+ const startMode = ["study", "flashcards"].includes(params.get("mode")?.toLowerCase()) ? "study" : params.get("mode")?.toLowerCase() === "review" ? "review" : location.hash === "#study" ? "study" : "review";
852
+
853
+ const knownKey = `${data.code.toLowerCase()}-glossary-known`;
854
+ const state = {
855
+ by: startBy,
856
+ mode: startMode,
857
+ q: params.get("q")?.slice(0, 200) ?? "",
858
+ filters: { test: resolve("test", listOf("test")), chapter: resolve("chapter", listOf("reading")), meeting: resolve("meeting", listOf("meeting")) },
859
+ known: new Set(),
860
+ deck: /** @type {Term[]} */ ([]),
861
+ idx: 0,
862
+ revealed: false,
863
+ direction: "term",
864
+ shuffle: false,
865
+ };
866
+
867
+ try {
868
+ state.known = new Set(JSON.parse(store.get(knownKey) ?? "[]"));
869
+ } catch {
870
+ state.known = new Set();
871
+ }
872
+ const saveKnown = () => store.set(knownKey, JSON.stringify([...state.known]));
873
+
874
+ app.innerHTML = `
875
+ <div class="bar">
876
+ <fieldset class="switch" data-switch="radio" data-by>
877
+ <legend class="switch-label">${esc(t("glossary", "groupBy"))}</legend>
878
+ <div class="switch-track">${dims
879
+ .map(([dim, text]) => `<label class="switch-option"><input type="radio" name="${prefix}-by" value="${dim}"> ${esc(text)}</label>`)
880
+ .join("")}</div>
881
+ </fieldset>
882
+ <div class="switch" data-switch="tabs" data-modes>
883
+ <span class="switch-label" id="${prefix}-mode-label">${esc(t("glossary", "mode"))}</span>
884
+ <div class="switch-track" role="tablist" aria-labelledby="${prefix}-mode-label">
885
+ <button type="button" class="switch-option" role="tab" id="${prefix}-tab-review" aria-controls="${prefix}-panel-review" aria-selected="true" tabindex="0" data-mode="review">${esc(t("glossary", "review"))}</button>
886
+ <button type="button" class="switch-option" role="tab" id="${prefix}-tab-study" aria-controls="${prefix}-panel-study" aria-selected="false" tabindex="-1" data-mode="study">${esc(t("glossary", "flashcards"))}</button>
887
+ </div>
888
+ </div>
889
+ </div>
890
+ <div class="search">
891
+ <label class="label" for="${prefix}-q">${esc(t("glossary", "search"))}</label>
892
+ <div class="field">
893
+ <input type="search" id="${prefix}-q" name="q" autocomplete="off" spellcheck="false" data-q>
894
+ <button type="button" class="clear-search" data-clear-q aria-label="${esc(t("glossary", "clearSearch"))}" hidden>${esc(t("glossary", "clear"))}</button>
895
+ </div>
896
+ </div>
897
+ <details class="filters" data-filters>
898
+ <summary data-summary></summary>
899
+ <div class="filter-rows">
900
+ ${FILTERS.map(
901
+ (kind) => `<div class="filter-row">
902
+ <span class="label" id="${prefix}-f-${kind}">${esc(kind === "test" ? t("glossary", "byTest") : label)}</span>
903
+ <div class="chips" role="group" aria-labelledby="${prefix}-f-${kind}" data-chips="${kind}"></div>
904
+ </div>`,
905
+ ).join("")}
906
+ <div class="filter-row" data-pills-row hidden>
907
+ <span class="label" id="${prefix}-f-meeting">${esc(t("glossary", "byMeeting"))}</span>
908
+ <div class="chips" role="group" aria-labelledby="${prefix}-f-meeting" data-pills></div>
909
+ </div>
910
+ </div>
911
+ </details>
912
+ <p class="status" aria-live="polite" data-status></p>
913
+ <div role="tabpanel" id="${prefix}-panel-review" aria-labelledby="${prefix}-tab-review" data-review></div>
914
+ <div role="tabpanel" id="${prefix}-panel-study" aria-labelledby="${prefix}-tab-study" class="study" data-study hidden></div>
915
+ <p class="sr-only" role="status" data-announce></p>`;
916
+
917
+ const q = (selector) => app.querySelector(selector);
918
+ const els = {
919
+ by: q('[data-switch="radio"]'),
920
+ modes: q('[data-switch="tabs"]'),
921
+ tabs: q('[data-switch="tabs"] [role="tablist"]'),
922
+ summary: q("[data-summary]"),
923
+ details: q("[data-filters]"),
924
+ q: q("[data-q]"),
925
+ clearQ: q("[data-clear-q]"),
926
+ pills: q("[data-pills]"),
927
+ pillsRow: q("[data-pills-row]"),
928
+ status: q("[data-status]"),
929
+ review: q("[data-review]"),
930
+ study: q("[data-study]"),
931
+ announce: q("[data-announce]"),
932
+ };
933
+
934
+ /** @param {Term} term @param {string} kind */
935
+ const hasAny = (term, kind) => !state.filters[kind].size || term.tags[kind].some((tag) => state.filters[kind].has(tag.key));
936
+
937
+ // ---- Search: the term first (forgiving), then the definition (plain words) ----
938
+
939
+ /** @param {string} text letters and digits only, lowercased, no accents */
940
+ const alnum = (text) => text.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]/g, "");
941
+
942
+ /** @param {string} html */
943
+ const textOf = (html) => {
944
+ const box = document.createElement("template");
945
+ box.innerHTML = html;
946
+ return box.content.textContent.toLowerCase();
947
+ };
948
+
949
+ const definitions = new Map(terms.map((term) => [term.id, textOf(term.definition)]));
950
+ const names = new Map(terms.map((term) => [term.id, textOf(term.term)]));
951
+
952
+ /** Whether `a` is `b` with one letter added, dropped, changed or two swapped. */
953
+ const near = (a, b) => {
954
+ if (a === b) return true;
955
+ const gap = a.length - b.length;
956
+ if (Math.abs(gap) > 1) return false;
957
+ let i = 0;
958
+ while (i < a.length && i < b.length && a[i] === b[i]) i += 1;
959
+ if (gap === 0) return a.slice(i + 1) === b.slice(i + 1) || (a[i] === b[i + 1] && a[i + 1] === b[i] && a.slice(i + 2) === b.slice(i + 2));
960
+ return gap > 0 ? a.slice(i + 1) === b.slice(i) : b.slice(i + 1) === a.slice(i);
961
+ };
962
+
963
+ const range = (from, length) => new Set(Array.from({ length }, (_, i) => from + i));
964
+
965
+ /**
966
+ * How well a term matches: 0 exact, 1 prefix, 2 inside the name, 3 letters in order
967
+ * ("qsa" finds querySelectorAll), 4 one typo (4+ characters), 5 the definition.
968
+ * `marks` are the positions in the term's key to highlight.
969
+ * @param {Term} term
970
+ * @param {string} raw the query as typed
971
+ * @returns {{ score: number, marks: Set<number>|null }|null}
972
+ */
973
+ const match = (term, raw) => {
974
+ const wanted = alnum(raw);
975
+ const at = term.key.indexOf(wanted);
976
+ if (!wanted) return names.get(term.id).includes(raw.toLowerCase()) ? { score: 2, marks: null } : null;
977
+ if (term.key === wanted) return { score: 0, marks: range(0, wanted.length) };
978
+ if (at === 0) return { score: 1, marks: range(0, wanted.length) };
979
+ if (at > 0) return { score: 2, marks: range(at, wanted.length) };
980
+ if (wanted.length >= 3) {
981
+ const marks = new Set();
982
+ let from = 0;
983
+ for (const char of wanted) {
984
+ from = term.key.indexOf(char, from);
985
+ if (from < 0) break;
986
+ marks.add(from);
987
+ from += 1;
988
+ }
989
+ if (marks.size === wanted.length) return { score: 3, marks };
990
+ }
991
+ if (wanted.length >= 4 && [0, 1, -1].some((extra) => near(wanted, term.key.slice(0, wanted.length + extra)) || near(wanted, term.key))) return { score: 4, marks: null };
992
+ const lower = raw.toLowerCase();
993
+ const text = definitions.get(term.id);
994
+ const found = lower.length >= 3 ? text.includes(lower) : new RegExp(`\\b${lower.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`).test(text);
995
+ return found ? { score: 5, marks: null } : null;
996
+ };
997
+
998
+ /** Matches for the current query, or null with no query. @returns {Map<string, { score: number, marks: Set<number>|null }>|null} */
999
+ const search = () => {
1000
+ const raw = state.q.trim();
1001
+ if (!raw) return null;
1002
+ const hits = new Map();
1003
+ for (const term of terms) {
1004
+ const hit = match(term, raw);
1005
+ if (hit) hits.set(term.id, hit);
1006
+ }
1007
+ return hits;
1008
+ };
1009
+
1010
+ /** @type {Map<string, { score: number, marks: Set<number>|null }>|null} */
1011
+ let hits = null;
1012
+ /** @type {Term[]|null} */
1013
+ let view = null;
1014
+
1015
+ const passes = (term, skip) => (!hits || hits.has(term.id)) && FILTERED.every((kind) => kind === skip || hasAny(term, kind));
1016
+
1017
+ /** The terms in view: filters and search together. */
1018
+ const filtered = () => (view ??= terms.filter((term) => passes(term)));
1019
+
1020
+ /**
1021
+ * Terms per tag of `kind`, under every other selection and the search.
1022
+ * @param {string} kind
1023
+ * @returns {Tag[]}
1024
+ */
1025
+ const countTags = (kind) => {
1026
+ const counts = new Map();
1027
+ for (const term of terms) {
1028
+ if (!passes(term, kind)) continue;
1029
+ for (const tag of term.tags[kind]) counts.set(tag.key, (counts.get(tag.key) ?? 0) + 1);
1030
+ }
1031
+ return data.tags[kind].map((tag) => ({ ...tag, n: counts.get(tag.key) ?? 0 }));
1032
+ };
1033
+
1034
+ /**
1035
+ * Wrap the matched characters of a term's HTML in <mark>; the HTML comes back unchanged if the
1036
+ * characters do not line up with the term's key.
1037
+ * @param {Term} term
1038
+ * @param {Set<number>|null|undefined} marks
1039
+ */
1040
+ const highlight = (term, marks) => {
1041
+ if (!marks) return term.term;
1042
+ const box = document.createElement("template");
1043
+ box.innerHTML = term.term;
1044
+ const walker = document.createTreeWalker(box.content, NodeFilter.SHOW_TEXT);
1045
+ const nodes = [];
1046
+ while (walker.nextNode()) nodes.push(walker.currentNode);
1047
+ let position = 0;
1048
+ const plans = [];
1049
+ for (const node of nodes) {
1050
+ const parts = [];
1051
+ for (const char of node.data) {
1052
+ const folded = alnum(char);
1053
+ if (folded.length > 1) return term.term;
1054
+ const on = folded.length === 1 && marks.has(position);
1055
+ if (folded.length === 1) position += 1;
1056
+ if (parts.at(-1)?.on === on) parts.at(-1).text += char;
1057
+ else parts.push({ text: char, on });
1058
+ }
1059
+ plans.push([node, parts]);
1060
+ }
1061
+ if (position !== term.key.length) return term.term;
1062
+ for (const [node, parts] of plans) {
1063
+ if (!parts.some((part) => part.on)) continue;
1064
+ const fragment = document.createDocumentFragment();
1065
+ for (const part of parts) {
1066
+ if (!part.on) fragment.append(part.text);
1067
+ else fragment.append(Object.assign(document.createElement("mark"), { textContent: part.text }));
1068
+ }
1069
+ node.replaceWith(fragment);
1070
+ }
1071
+ return box.innerHTML;
1072
+ };
1073
+
1074
+ /**
1075
+ * Group terms under the chosen order: A to Z (the loader's rank and groups) or a tag kind.
1076
+ * A term with several tags of a kind appears under each. With a query, a group lists its
1077
+ * best matches first.
1078
+ * @param {Term[]} list
1079
+ */
1080
+ const groups = (list) => {
1081
+ const sets = [];
1082
+ if (state.by === "az") {
1083
+ const byLetter = new Map();
1084
+ for (const term of [...list].sort((a, b) => a.azOrder - b.azOrder)) {
1085
+ if (!byLetter.has(term.azGroup.key)) byLetter.set(term.azGroup.key, { ...term.azGroup, items: [] });
1086
+ byLetter.get(term.azGroup.key).items.push(term);
1087
+ }
1088
+ sets.push(...byLetter.values());
1089
+ } else {
1090
+ const byTag = new Map();
1091
+ for (const term of list) {
1092
+ for (const tag of term.tags[state.by]) {
1093
+ if (!byTag.has(tag.key)) byTag.set(tag.key, { ...tag, items: [] });
1094
+ byTag.get(tag.key).items.push(term);
1095
+ }
1096
+ }
1097
+ sets.push(...[...byTag.values()].sort((a, b) => a.order - b.order));
1098
+ }
1099
+ if (hits) for (const set of sets) set.items.sort((a, b) => hits.get(a.id).score - hits.get(b.id).score);
1100
+ return sets;
1101
+ };
1102
+
1103
+ /**
1104
+ * Arrow keys move through a group of toggles, selecting as they go.
1105
+ * @param {HTMLElement} container
1106
+ * @param {string} selector the toggles
1107
+ * @param {(button: HTMLElement) => void} select
1108
+ * @param {boolean} [wrap] whether the ends loop round
1109
+ */
1110
+ const roving = (container, selector, select, wrap = true) => {
1111
+ container.addEventListener("keydown", (event) => {
1112
+ const buttons = [...container.querySelectorAll(selector)];
1113
+ const at = buttons.indexOf(/** @type {HTMLElement} */ (document.activeElement));
1114
+ if (at < 0) return;
1115
+ const step = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 }[event.key];
1116
+ const moved = at + (step ?? 0);
1117
+ const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : step ? (wrap ? (moved + buttons.length) % buttons.length : moved) : -1;
1118
+ if (next < 0 || next >= buttons.length) return;
1119
+ event.preventDefault();
1120
+ buttons[next].focus();
1121
+ select(buttons[next]);
1122
+ });
1123
+ };
1124
+
1125
+ // ---- Controls, built once and updated in place so focus stays put ----
1126
+
1127
+ // Group by is native radios: the browser does the arrow keys, and `change` follows them.
1128
+ els.by.addEventListener("change", (event) => {
1129
+ if (event.target.matches('input[type="radio"]')) {
1130
+ state.by = event.target.value;
1131
+ render();
1132
+ }
1133
+ });
1134
+ // Review / Flashcards are tabs: a roving tabindex, arrows and Home / End with wrap, activating as they move.
1135
+ els.tabs.addEventListener("click", (event) => {
1136
+ const button = event.target.closest("[data-mode]");
1137
+ if (button) setMode(button.dataset.mode);
1138
+ });
1139
+ roving(els.tabs, "[data-mode]", (button) => setMode(button.dataset.mode));
1140
+
1141
+ /** @type {Map<string, HTMLButtonElement>} */
1142
+ const chips = new Map();
1143
+ for (const kind of FILTERS) {
1144
+ const row = q(`[data-chips="${kind}"]`);
1145
+ for (const tag of data.tags[kind]) {
1146
+ const chip = document.createElement("button");
1147
+ chip.type = "button";
1148
+ chip.className = "chip";
1149
+ chip.dataset.kind = kind;
1150
+ chip.dataset.key = tag.key;
1151
+ chip.innerHTML = `<span class="t">${esc(tag.label)}</span><span class="n"></span>`;
1152
+ chips.set(`${kind}:${tag.key}`, chip);
1153
+ row.append(chip);
1154
+ }
1155
+ row.addEventListener("click", (event) => {
1156
+ const chip = event.target.closest("[data-key]");
1157
+ if (!chip) return;
1158
+ const set = state.filters[kind];
1159
+ if (!set.delete(chip.dataset.key)) set.add(chip.dataset.key);
1160
+ render();
1161
+ });
1162
+ }
1163
+
1164
+ els.status.addEventListener("click", (event) => {
1165
+ if (!event.target.closest("[data-clear]")) return;
1166
+ for (const kind of FILTERED) state.filters[kind].clear();
1167
+ render();
1168
+ els.summary.focus();
1169
+ });
1170
+
1171
+ els.pills.addEventListener("click", (event) => {
1172
+ const pill = event.target.closest("[data-key]");
1173
+ if (!pill) return;
1174
+ state.filters.meeting.delete(pill.dataset.key);
1175
+ render();
1176
+ (els.pillsRow.hidden ? els.summary : els.pills.querySelector("button"))?.focus();
1177
+ });
1178
+
1179
+ let typing = 0;
1180
+ els.q.addEventListener("input", () => {
1181
+ clearTimeout(typing);
1182
+ typing = setTimeout(() => setQuery(els.q.value), 100);
1183
+ });
1184
+ els.q.addEventListener("keydown", (event) => {
1185
+ if (event.key !== "Escape" || !els.q.value) return;
1186
+ event.preventDefault();
1187
+ setQuery("");
1188
+ });
1189
+ els.clearQ.addEventListener("click", () => {
1190
+ setQuery("");
1191
+ els.q.focus();
1192
+ });
1193
+
1194
+ /** @param {string} value */
1195
+ function setQuery(value) {
1196
+ clearTimeout(typing);
1197
+ els.q.value = value;
1198
+ state.q = value;
1199
+ render();
1200
+ }
1201
+
1202
+ function renderControls() {
1203
+ for (const input of els.by.querySelectorAll('input[type="radio"]')) input.checked = input.value === state.by;
1204
+ for (const button of els.tabs.children) {
1205
+ const on = button.dataset.mode === state.mode;
1206
+ button.setAttribute("aria-selected", String(on));
1207
+ button.tabIndex = on ? 0 : -1;
1208
+ }
1209
+ for (const kind of FILTERS) {
1210
+ for (const tag of countTags(kind)) {
1211
+ const chip = chips.get(`${kind}:${tag.key}`);
1212
+ const on = state.filters[kind].has(tag.key);
1213
+ chip.setAttribute("aria-pressed", String(on));
1214
+ chip.disabled = !tag.n && !on;
1215
+ chip.querySelector(".n").textContent = String(tag.n);
1216
+ }
1217
+ }
1218
+ const pills = [...state.filters.meeting].map((key) => tagsOf.meeting.get(key));
1219
+ els.pillsRow.hidden = !pills.length;
1220
+ els.pills.innerHTML = pills
1221
+ .map((tag) => `<button type="button" class="chip pill" data-kind="meeting" data-key="${esc(tag.key)}" aria-label="${esc(t("glossary", "removeFilter", { kind: t("glossary", "byMeeting").toLowerCase(), label: tag.label }))}">${esc(t("glossary", "meetingChip", { label: tag.label }))}</button>`)
1222
+ .join("");
1223
+ els.clearQ.hidden = !state.q;
1224
+ const active = FILTERED.reduce((sum, kind) => sum + state.filters[kind].size, 0);
1225
+ els.summary.textContent = [t("glossary", "filterSummary", { reading: label.toLowerCase() }), active ? t("glossary", "filtersOn", { count: active }) : ""].filter(Boolean).join(" ");
1226
+ els.status.innerHTML = `${esc(active ? t("glossary", "count", { shown: filtered().length, total: terms.length }) : t("glossary", "terms", { count: terms.length }))}${active ? `${esc(t("common", "sep"))}<button type="button" data-clear>${esc(t("glossary", "clearFilters"))}</button>` : ""}`;
1227
+ els.review.hidden = state.mode !== "review";
1228
+ els.study.hidden = state.mode !== "study";
1229
+ }
1230
+
1231
+ // ---- Review ----
1232
+
1233
+ /** @param {Term} term */
1234
+ const slideLinks = (term) =>
1235
+ term.taught.map((place) => `<a href="${esc(BASE + place.href.slice(1))}">${esc(t("glossary", "slideRef", { week: place.week, weekday: place.weekday, slide: place.slide }))}</a>`).join("") +
1236
+ (term.ref ? `<a href="${esc(term.ref.href)}">${esc(term.ref.label)}</a>` : "");
1237
+
1238
+ /** @param {Term} term */
1239
+ const tagList = (term) =>
1240
+ `<ul class="tags" role="list">${KINDS.flatMap((kind) => term.tags[kind].map((tag) => `<li data-kind="${kind}">${esc(tag.label)}</li>`)).join("")}</ul>`;
1241
+
1242
+ function renderReview() {
1243
+ const list = filtered();
1244
+ if (!list.length) {
1245
+ els.review.innerHTML = `<div class="empty"><strong>${esc(t("glossary", "noMatch"))}</strong><span>${esc(t("glossary", "noMatchHint"))}</span></div>`;
1246
+ return;
1247
+ }
1248
+ const sets = groups(list);
1249
+ const id = (set) => `g-${state.by}-${slug(set.key)}`;
1250
+ els.review.innerHTML = sets
1251
+ .map(
1252
+ (set) => `<section class="group" id="${id(set)}"${state.by === "az" ? "" : ` data-kind="${state.by}"`} aria-labelledby="${id(set)}-h">
1253
+ <h2 class="heading" id="${id(set)}-h"><span class="name">${esc(set.label)}</span><span class="aside">${set.when ? `<span class="when">${esc(set.when)}</span>` : ""}${state.by === "meeting" ? `<span class="deck">${esc(set.deck)}</span>` : ""}<span class="count">${esc(t("glossary", "terms", { count: set.items.length }))}</span></span></h2>
1254
+ <dl>${set.items
1255
+ .map(
1256
+ (term) => `<div class="entry">
1257
+ <dt><span class="term">${highlight(term, hits?.get(term.id)?.marks)}</span>${term.group ? `<span class="api-group">${esc(term.group)}</span>` : ""}${state.known.has(term.id) ? `<span class="known">${esc(t("glossary", "known"))}</span>` : ""}</dt>
1258
+ <dd>${term.sig ? `<p class="sig">${term.sig}</p>` : ""}<p class="definition">${term.definition}</p>${term.meta ? `<p class="meta">${term.meta}</p>` : ""}${term.example ? `<p class="example"><span class="label">${esc(t("glossary", "example"))}</span> ${term.example}</p>` : ""}${tagList(term)}<p class="links">${term.taught.length || term.ref ? `<span class="label">${esc(t("glossary", "taughtIn"))}</span>` : ""}${slideLinks(term)}</p></dd>
1259
+ </div>`,
1260
+ )
1261
+ .join("")}</dl>
1262
+ </section>`,
1263
+ )
1264
+ .join("");
1265
+ }
1266
+
1267
+ // ---- Flashcards ----
1268
+
1269
+ /** @param {Term} term */
1270
+ const termPart = (term) =>
1271
+ `<div class="front">${term.term}${term.group ? `<small>${esc(term.group)}</small>` : ""}${term.sig ? `<span class="sig">${term.sig}</span>` : ""}</div>`;
1272
+ /** @param {Term} term */
1273
+ const definitionPart = (term) => `<div class="back"><p class="definition">${term.definition}</p></div>`;
1274
+ /** @param {Term} term */
1275
+ const restPart = (term) =>
1276
+ `<div class="back">${term.meta ? `<p class="meta">${term.meta}</p>` : ""}${term.example ? `<p class="example"><span class="label">${esc(t("glossary", "example"))}</span> ${term.example}</p>` : ""}<p class="links">${slideLinks(term)}</p></div>`;
1277
+
1278
+ /** Visible, in Review order, one card per term, minus the ones known. */
1279
+ function startStudy() {
1280
+ const seen = new Set();
1281
+ const pool = [];
1282
+ for (const set of groups(filtered())) {
1283
+ for (const term of set.items) {
1284
+ if (seen.has(term.id) || state.known.has(term.id)) continue;
1285
+ seen.add(term.id);
1286
+ pool.push(term);
1287
+ }
1288
+ }
1289
+ if (state.shuffle) {
1290
+ for (let i = pool.length - 1; i > 0; i -= 1) {
1291
+ const j = Math.floor(Math.random() * (i + 1));
1292
+ [pool[i], pool[j]] = [pool[j], pool[i]];
1293
+ }
1294
+ }
1295
+ state.deck = pool;
1296
+ state.idx = 0;
1297
+ state.revealed = false;
1298
+ renderStudy(".reveal");
1299
+ }
1300
+
1301
+ /** @param {string} [focus] selector to focus afterward; default, the control that had focus */
1302
+ function renderStudy(focus) {
1303
+ const act = document.activeElement?.closest?.("[data-act]")?.dataset.act;
1304
+ // Move focus only when the reader is already working in the cards.
1305
+ const working = els.study.contains(document.activeElement) || document.activeElement === document.body;
1306
+ const total = filtered().length;
1307
+ const knownCount = filtered().filter((term) => state.known.has(term.id)).length;
1308
+ const card = state.deck[state.idx];
1309
+ const top = `<div class="study-top"><span>${esc([card ? t("glossary", "card", { n: state.idx + 1, total: state.deck.length }) : t("glossary", "toStudy", { count: state.deck.length }), t("glossary", "knownOf", { known: knownCount, total })].join(t("common", "sep")))}</span>
1310
+ <div class="opts">
1311
+ <button type="button" class="chip" data-act="shuffle" aria-pressed="${state.shuffle}">${esc(t("glossary", "shuffle"))}</button>
1312
+ <button type="button" class="chip" data-act="direction" aria-pressed="${state.direction === "def"}">${esc(t("glossary", "defFirst"))}</button>
1313
+ ${knownCount && card ? `<button type="button" class="chip" data-act="reset">${esc(t("glossary", "resetKnown"))}</button>` : ""}
1314
+ </div></div>
1315
+ <div class="meter" role="progressbar" aria-label="${esc(t("glossary", "knownMeter"))}" aria-valuemin="0" aria-valuemax="${total}" aria-valuenow="${knownCount}"><i style="inline-size:${total ? Math.round((knownCount / total) * 100) : 0}%"></i></div>`;
1316
+
1317
+ let html;
1318
+ if (!total) {
1319
+ html = `${top}<div class="empty"><strong>${esc(t("glossary", "noMatch"))}</strong><span>${esc(t("glossary", "noMatchStudy"))}</span></div>`;
1320
+ } else if (!card) {
1321
+ html = `${top}<div class="done"><h2 class="heading">${esc(t("glossary", "allKnown"))}</h2><p>${esc(t("glossary", "markedKnown", { known: knownCount, total }))}</p><div class="verdict"><button type="button" data-act="again" class="primary">${esc(t("glossary", "startOver"))}</button></div></div>`;
1322
+ } else {
1323
+ const termFirst = state.direction === "term";
1324
+ const front = termFirst ? termPart(card) : definitionPart(card);
1325
+ const back = termFirst ? definitionPart(card) : termPart(card);
1326
+ const tests = card.tags.test.map((tag) => esc(tag.label)).join(", ");
1327
+ const chapters = card.tags.chapter.slice(0, 2).map((tag) => esc(tag.label)).join(", ");
1328
+ html = `${top}
1329
+ <div class="card" tabindex="-1">
1330
+ <div class="top"><span data-kind="test">${tests}</span><span data-kind="chapter">${chapters}</span></div>
1331
+ <div class="content">${state.revealed ? front + back + restPart(card) : front}</div>
1332
+ <div class="foot">${state.revealed ? "" : `<button type="button" class="reveal primary" data-act="reveal">${esc(t("glossary", termFirst ? "showDefinition" : "showTerm"))}</button>`}</div>
1333
+ </div>
1334
+ ${state.revealed ? `<div class="verdict"><button type="button" class="yes" data-act="know">${esc(t("glossary", "iKnow"))}</button><button type="button" data-act="later">${esc(t("glossary", "later"))}</button></div>` : ""}
1335
+ <div class="nav"><button type="button" data-act="prev" ${state.idx === 0 ? "disabled" : ""}>${esc(t("glossary", "prev"))}</button><span class="hint">${esc(t("glossary", "hint"))}</span><button type="button" data-act="next" ${state.idx >= state.deck.length - 1 ? "disabled" : ""}>${esc(t("glossary", "next"))}</button></div>`;
1336
+ }
1337
+ els.study.innerHTML = html;
1338
+
1339
+ if (working) {
1340
+ const target = (focus && els.study.querySelector(focus)) || (act && els.study.querySelector(`[data-act="${act}"]:not(:disabled)`));
1341
+ (target || els.study.querySelector(".card") || els.study.querySelector("[data-act]"))?.focus({ preventScroll: true });
1342
+ }
1343
+
1344
+ els.announce.textContent = !card
1345
+ ? ""
1346
+ : state.revealed
1347
+ ? t("glossary", "defShown", { term: card.plain })
1348
+ : t("glossary", "card", { n: state.idx + 1, total: state.deck.length });
1349
+ }
1350
+
1351
+ /** @param {string} act */
1352
+ function studyAction(act) {
1353
+ const card = state.deck[state.idx];
1354
+ if (act === "reveal" && card && !state.revealed) {
1355
+ state.revealed = true;
1356
+ renderStudy(".yes");
1357
+ return;
1358
+ }
1359
+ if (act === "know" && card) {
1360
+ state.known.add(card.id);
1361
+ saveKnown();
1362
+ state.deck.splice(state.idx, 1);
1363
+ state.idx = Math.min(state.idx, Math.max(state.deck.length - 1, 0));
1364
+ } else if (act === "later" && card) {
1365
+ state.deck.push(...state.deck.splice(state.idx, 1));
1366
+ } else if (act === "prev" && state.idx > 0) {
1367
+ state.idx -= 1;
1368
+ } else if (act === "next" && state.idx < state.deck.length - 1) {
1369
+ state.idx += 1;
1370
+ } else if (act === "shuffle") {
1371
+ state.shuffle = !state.shuffle;
1372
+ startStudy();
1373
+ return;
1374
+ } else if (act === "direction") {
1375
+ state.direction = state.direction === "term" ? "def" : "term";
1376
+ } else if (act === "reset" || act === "again") {
1377
+ for (const term of filtered()) state.known.delete(term.id);
1378
+ saveKnown();
1379
+ startStudy();
1380
+ return;
1381
+ } else {
1382
+ return;
1383
+ }
1384
+ state.revealed = false;
1385
+ renderStudy(act === "direction" ? undefined : ".reveal");
1386
+ }
1387
+
1388
+ els.study.addEventListener("click", (event) => {
1389
+ const button = event.target.closest("[data-act]");
1390
+ if (button && !button.disabled) studyAction(button.dataset.act);
1391
+ });
1392
+
1393
+ document.addEventListener("keydown", (event) => {
1394
+ if (state.mode !== "study" || event.altKey || event.ctrlKey || event.metaKey) return;
1395
+ const target = /** @type {HTMLElement} */ (event.target);
1396
+ if (target.closest("input, select, textarea, a, summary, [role=tab], [role=radio]")) return;
1397
+ if (event.key === " " || event.key === "Enter") {
1398
+ // A focused button already activates itself.
1399
+ if (target.closest("button")) return;
1400
+ event.preventDefault();
1401
+ studyAction("reveal");
1402
+ } else if (event.key === "ArrowRight") {
1403
+ studyAction("next");
1404
+ } else if (event.key === "ArrowLeft") {
1405
+ studyAction("prev");
1406
+ }
1407
+ }, { signal });
1408
+
1409
+ // ---- Mode and URL ----
1410
+
1411
+ /**
1412
+ * @param {string} mode "review" or "study"
1413
+ */
1414
+ function setMode(mode) {
1415
+ if (mode === state.mode) return;
1416
+ state.mode = mode;
1417
+ render();
1418
+ }
1419
+
1420
+ /** An old `#study` link still opens Flashcards. */
1421
+ window.addEventListener("hashchange", () => {
1422
+ if (location.hash === "#study") setMode("study");
1423
+ }, { signal });
1424
+
1425
+ /** Keep the link in step with the state: only non-default values, replaced, never pushed. */
1426
+ function writeUrl() {
1427
+ const next = new URLSearchParams(location.search);
1428
+ for (const name of PARAMS) next.delete(name);
1429
+ if (state.mode === "study") next.set("mode", "study");
1430
+ if (state.by !== "az") next.set("group", state.by === "chapter" ? "reading" : state.by);
1431
+ const keys = (kind) => [...state.filters[kind]].map((key) => (kind === "test" ? key.replace(/^test-/, "") : kind === "chapter" ? slug(key) : key));
1432
+ if (state.filters.test.size) next.set("test", keys("test").join(","));
1433
+ if (state.filters.chapter.size) next.set("reading", keys("chapter").join(","));
1434
+ if (state.filters.meeting.size) next.set("meeting", keys("meeting").join(","));
1435
+ if (state.q.trim()) next.set("q", state.q);
1436
+ const query = next.toString().replace(/%2C/g, ",");
1437
+ const hash = location.hash === "#study" ? "" : location.hash;
1438
+ const url = location.pathname + (query ? `?${query}` : "") + hash;
1439
+ if (url !== location.pathname + location.search + location.hash) {
1440
+ try {
1441
+ history.replaceState(null, "", url);
1442
+ } catch {
1443
+ // A sandboxed frame: the link just won't follow the state.
1444
+ }
1445
+ }
1446
+ }
1447
+
1448
+ function render() {
1449
+ hits = search();
1450
+ view = null;
1451
+ renderControls();
1452
+ renderReview();
1453
+ if (state.mode === "study") startStudy();
1454
+ writeUrl();
1455
+ }
1456
+
1457
+ els.q.value = state.q;
1458
+ if (FILTERED.some((kind) => params.has(kind === "chapter" ? "reading" : kind))) els.details.open = true;
1459
+ render();
1460
+ root.querySelector("[data-static]")?.remove();
1461
+ app.hidden = false;
1462
+ }
1463
+
1464
+ /** The glossary's element: mounts once when it joins the page, and lets go when it leaves. */
1465
+ class GlossaryApp extends HTMLElement {
1466
+ #abort = null;
1467
+
1468
+ connectedCallback() {
1469
+ if (this.#abort) return;
1470
+ this.#abort = new AbortController();
1471
+ mount(this, this.#abort.signal);
1472
+ }
1473
+
1474
+ disconnectedCallback() {
1475
+ this.#abort?.abort();
1476
+ this.#abort = null;
1477
+ }
1478
+ }
1479
+
1480
+ if (!customElements.get("glossary-app")) customElements.define("glossary-app", GlossaryApp);
1481
+ })();
1482
+ </script>