@clarusjs/theme-docs 0.5.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -6
- package/src/callout.tscl +8 -4
- package/src/code-tabs.tscl +69 -0
- package/src/layout.tscl +31 -26
- package/src/learn-path.tscl +26 -23
- package/src/learn-progress.tscl +8 -4
- package/src/learn-status.tscl +13 -8
- package/src/lesson-bar.tscl +36 -22
- package/src/lesson.css +5 -2
- package/src/lesson.tscl +36 -28
- package/src/mermaid.tscl +60 -0
- package/src/nav.ts +20 -2
- package/src/page-head.tscl +15 -10
- package/src/parts/contents.tscl +11 -7
- package/src/parts/footer.tscl +7 -3
- package/src/parts/header.tscl +19 -15
- package/src/parts/icon.tscl +9 -5
- package/src/parts/page-footer.tscl +14 -10
- package/src/parts/sidebar.tscl +15 -11
- package/src/progress-board.tscl +11 -8
- package/src/quiz-choices.tscl +18 -14
- package/src/quiz.tscl +12 -8
- package/src/search.tscl +2 -1
- package/src/styles/theme.css +16 -0
- package/src/theme.css +41 -0
- package/src/vite.js +2 -1
package/src/mermaid.tscl
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{{--
|
|
2
|
+
Draws the ```mermaid diagram it sits next to: markdown({ mermaid: { tag: 'diagram', from: '@clarusjs/theme-docs/mermaid.tscl' } })
|
|
3
|
+
puts it after each block's <pre class="mermaid">, inside .mermaid-diagram. Loads mermaid (a peer dependency: install
|
|
4
|
+
it beside the theme) when the diagram scrolls into view, draws it in the page's theme, and draws it again when the
|
|
5
|
+
theme changes. Each diagram is its own island, so a page swapped in by navigation draws its own. Until it's drawn, or
|
|
6
|
+
if drawing fails, the source stays readable. The box's data-state is drawn or failed.
|
|
7
|
+
--}}
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
function wire(el) {
|
|
11
|
+
const box = el.closest('.mermaid-diagram')
|
|
12
|
+
const pre = box?.querySelector('pre.mermaid')
|
|
13
|
+
if (!box || !pre) return
|
|
14
|
+
const source = pre.textContent ?? ''
|
|
15
|
+
const root = document.documentElement
|
|
16
|
+
const media = matchMedia('(prefers-color-scheme: dark)')
|
|
17
|
+
const dark = () => root.dataset.theme === 'dark' || (root.dataset.theme !== 'light' && media.matches)
|
|
18
|
+
let latest = 0
|
|
19
|
+
let gone = false
|
|
20
|
+
async function draw() {
|
|
21
|
+
const run = ++latest
|
|
22
|
+
try {
|
|
23
|
+
const { default: mermaid } = await import('mermaid')
|
|
24
|
+
mermaid.initialize({ startOnLoad: false, securityLevel: 'strict', theme: dark() ? 'dark' : 'default' })
|
|
25
|
+
const { svg } = await mermaid.render('cl-mermaid-' + Math.random().toString(36).slice(2), source)
|
|
26
|
+
if (gone || run !== latest) return
|
|
27
|
+
let out = box.querySelector('.mermaid-svg')
|
|
28
|
+
if (!out) {
|
|
29
|
+
out = document.createElement('div')
|
|
30
|
+
out.className = 'mermaid-svg'
|
|
31
|
+
out.tabIndex = 0 // it scrolls sideways on a narrow screen: reachable by keyboard
|
|
32
|
+
box.insertBefore(out, pre)
|
|
33
|
+
}
|
|
34
|
+
// securityLevel 'strict': mermaid sanitizes its SVG (DOMPurify), and labels' HTML is escaped
|
|
35
|
+
out.innerHTML = svg
|
|
36
|
+
// Full size (mermaid's max-width), not shrunk to the column: on a phone the text stays readable and the box scrolls.
|
|
37
|
+
const drawing = out.querySelector('svg')
|
|
38
|
+
const natural = parseFloat(drawing?.style.maxWidth ?? '')
|
|
39
|
+
if (drawing && natural) drawing.style.minWidth = natural + 'px'
|
|
40
|
+
pre.hidden = true
|
|
41
|
+
box.dataset.state = 'drawn'
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (gone || run !== latest) return
|
|
44
|
+
box.dataset.state = 'failed'
|
|
45
|
+
console.warn('[theme-docs] a mermaid diagram could not be drawn:', error)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const watch = new MutationObserver(draw)
|
|
49
|
+
watch.observe(root, { attributes: true, attributeFilter: ['data-theme'] })
|
|
50
|
+
media.addEventListener('change', draw)
|
|
51
|
+
draw()
|
|
52
|
+
return () => {
|
|
53
|
+
gone = true
|
|
54
|
+
watch.disconnect()
|
|
55
|
+
media.removeEventListener('change', draw)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<span class="mermaid-draw" [use]="wire"></span>
|
package/src/nav.ts
CHANGED
|
@@ -62,11 +62,19 @@ export type ThemeConfig = {
|
|
|
62
62
|
pages?: readonly PageInfo[]
|
|
63
63
|
/**
|
|
64
64
|
* Learn: the section whose pages are lessons, and its progress page (not a lesson). Progress, XP and badges are
|
|
65
|
-
* kept in the browser (localStorage); an XP chip shows in lesson headers and on the section's pages.
|
|
65
|
+
* kept in the browser (localStorage); an XP chip shows in lesson headers and on the section's pages. `layout`: from
|
|
66
|
+
* 1024px a step's code goes in a side column beside its text (`'split'`, the default; `'split-reverse'` puts it on
|
|
67
|
+
* the left); `'stacked'` keeps it inline; `'stacked-reverse'` puts it under the step's heading, above the text. A
|
|
68
|
+
* lesson can pick its own with frontmatter `lessonLayout:`.
|
|
66
69
|
*/
|
|
67
|
-
learn?: { section: string; progress: string }
|
|
70
|
+
learn?: { section: string; progress: string; layout?: LessonLayout }
|
|
68
71
|
/** A search button (and Ctrl/⌘K, /) in the header; the index comes from the themeDocs() Vite plugin. */
|
|
69
72
|
search?: boolean
|
|
73
|
+
/**
|
|
74
|
+
* How a `::: code-group`'s tabs lay out when they don't fit: `'wrap'` onto more rows (the default), or `'scroll'`, one
|
|
75
|
+
* row that scrolls sideways with the code staying in place. A group's own `:scroll` or `:wrap` wins.
|
|
76
|
+
*/
|
|
77
|
+
codeGroups?: 'wrap' | 'scroll'
|
|
70
78
|
/**
|
|
71
79
|
* Page changes animate as view transitions where the browser has them (a cross-fade; `::view-transition-*` rules in
|
|
72
80
|
* the site's CSS change it). Needs fragment navigation or client routes; no animation with reduced motion.
|
|
@@ -181,3 +189,13 @@ export function lessonOf(config: ThemeConfig, path: string): { leave: string; pr
|
|
|
181
189
|
total: items.length,
|
|
182
190
|
}
|
|
183
191
|
}
|
|
192
|
+
|
|
193
|
+
/** How a lesson places each step's code: beside the text (split) or in line with it (stacked), either way round. */
|
|
194
|
+
export type LessonLayout = 'split' | 'split-reverse' | 'stacked' | 'stacked-reverse'
|
|
195
|
+
const LESSON_LAYOUTS: readonly string[] = ['split', 'split-reverse', 'stacked', 'stacked-reverse']
|
|
196
|
+
|
|
197
|
+
/** A lesson's layout: its frontmatter's `lessonLayout` when valid, else the site's `learn.layout`, else 'split'. */
|
|
198
|
+
export function lessonLayoutOf(config: ThemeConfig, frontmatter?: Record<string, unknown>): LessonLayout {
|
|
199
|
+
const own = frontmatter?.lessonLayout
|
|
200
|
+
return typeof own === 'string' && LESSON_LAYOUTS.includes(own) ? (own as LessonLayout) : config.learn?.layout ?? 'split'
|
|
201
|
+
}
|
package/src/page-head.tscl
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{{-- The <head> of every theme page: the saved theme before the first paint, the title and description, JSON-LD. --}}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
import type { ThemeConfig } from './nav.ts'
|
|
4
|
+
const props = props<{
|
|
5
|
+
config: ThemeConfig
|
|
6
|
+
title: string
|
|
7
|
+
description?: string
|
|
8
|
+
url?: string
|
|
9
|
+
}>(() => ({ description: '', url: '/' }))
|
|
10
|
+
</script>
|
|
11
|
+
|
|
7
12
|
{{-- Runs before the first paint: the saved theme is on <html> before anything shows (no flash). --}}
|
|
8
13
|
|
|
9
14
|
<script inline>
|
|
@@ -15,13 +20,13 @@
|
|
|
15
20
|
<fragment>
|
|
16
21
|
<meta charset="utf-8" />
|
|
17
22
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
18
|
-
@if (description) {
|
|
19
|
-
<meta name="description" content="{{ description }}" />
|
|
23
|
+
@if (props.description) {
|
|
24
|
+
<meta name="description" content="{{ props.description }}" />
|
|
20
25
|
}
|
|
21
|
-
<title>{{ title }}</title>
|
|
22
|
-
@if (config.siteUrl) {
|
|
26
|
+
<title>{{ props.title }}</title>
|
|
27
|
+
@if (props.config.siteUrl) {
|
|
23
28
|
<script type="application/ld+json">
|
|
24
|
-
{{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: title, description, url: `${config.siteUrl}${url === '/' ? '' : url}` } }}
|
|
29
|
+
{{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: props.title, description: props.description, url: `${props.config.siteUrl}${props.url === '/' ? '' : props.url}` } }}
|
|
25
30
|
</script>
|
|
26
31
|
}
|
|
27
32
|
</fragment>
|
package/src/parts/contents.tscl
CHANGED
|
@@ -3,27 +3,31 @@
|
|
|
3
3
|
collapsible box above the content (below 1280px). Nothing without headings. Replace it with
|
|
4
4
|
themeDocs({ components: { contents } }) (#361).
|
|
5
5
|
--}}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { Heading } from '../nav.ts'
|
|
8
|
+
const props = props<{
|
|
9
|
+
headings?: Heading[]
|
|
10
|
+
inline?: boolean
|
|
11
|
+
}>(() => ({ headings: [], inline: false }))
|
|
12
|
+
</script>
|
|
9
13
|
|
|
10
14
|
<fragment>
|
|
11
|
-
@if (headings.length && inline) {
|
|
15
|
+
@if (props.headings.length && props.inline) {
|
|
12
16
|
<details class="toc-inline">
|
|
13
17
|
<summary>On this page</summary>
|
|
14
18
|
<ul>
|
|
15
|
-
@for (h of headings; track h.id) {
|
|
19
|
+
@for (h of props.headings; track h.id) {
|
|
16
20
|
<li [class]="h.level === 3 ? 'sub' : false">
|
|
17
21
|
<a [href]="'#' + h.id">{{ h.text }}</a>
|
|
18
22
|
</li>
|
|
19
23
|
}
|
|
20
24
|
</ul>
|
|
21
25
|
</details>
|
|
22
|
-
} @else if (headings.length) {
|
|
26
|
+
} @else if (props.headings.length) {
|
|
23
27
|
<aside class="toc" aria-label="On this page">
|
|
24
28
|
<p>On this page</p>
|
|
25
29
|
<ul>
|
|
26
|
-
@for (h of headings; track h.id) {
|
|
30
|
+
@for (h of props.headings; track h.id) {
|
|
27
31
|
<li [class]="h.level === 3 ? 'sub' : false">
|
|
28
32
|
<a [href]="'#' + h.id">{{ h.text }}</a>
|
|
29
33
|
</li>
|
package/src/parts/footer.tscl
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
The site footer (a public part, #360): its default content is config.footer. Replace it with
|
|
3
3
|
themeDocs({ components: { footer } }) (#361).
|
|
4
4
|
--}}
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import type { ThemeConfig } from '../nav.ts'
|
|
7
|
+
const props = props<{
|
|
8
|
+
config: ThemeConfig
|
|
9
|
+
}>()
|
|
10
|
+
</script>
|
|
7
11
|
|
|
8
|
-
<footer class="site-footer"><slot>@if (config.footer) {<p>{{ config.footer }}</p>}</slot></footer>
|
|
12
|
+
<footer class="site-footer"><slot>@if (props.config.footer) {<p>{{ props.config.footer }}</p>}</slot></footer>
|
package/src/parts/header.tscl
CHANGED
|
@@ -6,15 +6,19 @@
|
|
|
6
6
|
@import pageTransitions from '../view-transitions.tscl'
|
|
7
7
|
@import siteSearch from '../search.tscl'
|
|
8
8
|
@import learnStatus from '../learn-status.tscl'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { sectionKey, lessonsOf } from '../nav.ts'
|
|
11
|
+
import type { ThemeConfig } from '../nav.ts'
|
|
12
|
+
const props = props<{
|
|
13
|
+
config: ThemeConfig
|
|
14
|
+
path?: string
|
|
15
|
+
/** An app page (a tool) has no sidebar, so no menu button. */
|
|
16
|
+
app?: boolean
|
|
17
|
+
}>(() => ({ path: '/', app: false }))
|
|
18
|
+
</script>
|
|
15
19
|
|
|
16
20
|
<header class="site-header">
|
|
17
|
-
@if (!app && sectionKey(config.sections, path)) {
|
|
21
|
+
@if (!props.app && sectionKey(props.config.sections, props.path)) {
|
|
18
22
|
<button type="button" class="menu-button" popovertarget="sidebar" aria-label="Open menu">
|
|
19
23
|
<svg
|
|
20
24
|
width="22"
|
|
@@ -31,17 +35,17 @@
|
|
|
31
35
|
</button>
|
|
32
36
|
}
|
|
33
37
|
<a class="brand" href="/"
|
|
34
|
-
>@if (config.brand.logo) {<img [src]="config.brand.logo" alt="" width="28" height="28">}<span>{{ config.brand.text }}@if (config.brand.accent) {<span class="js">{{ config.brand.accent }}</span>}</span></a
|
|
38
|
+
>@if (props.config.brand.logo) {<img [src]="props.config.brand.logo" alt="" width="28" height="28">}<span>{{ props.config.brand.text }}@if (props.config.brand.accent) {<span class="js">{{ props.config.brand.accent }}</span>}</span></a
|
|
35
39
|
>
|
|
36
|
-
<nav class="top-nav" aria-label="Main">@for (s of config.sections; track s.key) {<a [href]="s.href" [aria-current]="sectionKey(config.sections, path) === s.key ? 'true' : false">{{ s.title }}</a>}</nav>
|
|
40
|
+
<nav class="top-nav" aria-label="Main">@for (s of props.config.sections; track s.key) {<a [href]="s.href" [aria-current]="sectionKey(props.config.sections, props.path) === s.key ? 'true' : false">{{ s.title }}</a>}</nav>
|
|
37
41
|
<div class="header-end">
|
|
38
42
|
{{-- On Learn pages: the XP chip, and the sidebar's lessons marked done, current or locked. --}}
|
|
39
|
-
@if (config.learn && sectionKey(config.sections, path) === config.learn.section) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
|
|
43
|
+
@if (props.config.learn && sectionKey(props.config.sections, props.path) === props.config.learn.section) {<learnStatus [lessons]="lessonsOf(props.config).map((l) => l.href)" [progress]="props.config.learn.progress" />}
|
|
40
44
|
{{-- Kept across fragment navigations, like the theme toggle: its shortcut listener is added once. --}}
|
|
41
|
-
@if (config.search) {<span class="persist" data-cl-persist="search"><siteSearch /></span>}
|
|
42
|
-
@if ((config.social ?? []).length) {
|
|
45
|
+
@if (props.config.search) {<span class="persist" data-cl-persist="search"><siteSearch /></span>}
|
|
46
|
+
@if ((props.config.social ?? []).length) {
|
|
43
47
|
<span class="social">
|
|
44
|
-
@for (link of config.social ?? []; track link.href) {
|
|
48
|
+
@for (link of props.config.social ?? []; track link.href) {
|
|
45
49
|
<a [href]="link.href" [aria-label]="link.label" [title]="link.label"> @if (link.icon === 'github') {<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 19c-4 1.5-4-2-6-2.5m12 5v-3.5c0-1 .1-1.4-.5-2 2.8-.3 5.5-1.4 5.5-6a4.6 4.6 0 0 0-1.3-3.2 4.2 4.2 0 0 0-.1-3.2s-1.1-.3-3.5 1.3a12.3 12.3 0 0 0-6.2 0C6.5 2.8 5.4 3.1 5.4 3.1a4.2 4.2 0 0 0-.1 3.2A4.6 4.6 0 0 0 4 9.5c0 4.6 2.7 5.7 5.5 6-.6.6-.6 1.2-.5 2V21"></path></svg>} @else if (link.icon === 'npm') {<span class="npm" aria-hidden="true">npm</span>} @else {<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"></path></svg>} </a>
|
|
46
50
|
}
|
|
47
51
|
</span>
|
|
@@ -53,12 +57,12 @@
|
|
|
53
57
|
<circle cx="19" cy="12" r="2"></circle>
|
|
54
58
|
</svg>
|
|
55
59
|
</button>
|
|
56
|
-
<div id="more" class="more" popover>@for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
|
|
60
|
+
<div id="more" class="more" popover>@for (link of props.config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
|
|
57
61
|
}
|
|
58
62
|
{{-- What a site adds (slot "end"; the layout's "header-end"), kept across fragment navigations too. --}}
|
|
59
63
|
<span class="persist" data-cl-persist="header-end"><slot name="end"></slot></span>
|
|
60
64
|
{{-- Kept across fragment navigations: the same element, with its state. --}}
|
|
61
65
|
<span class="persist" data-cl-persist="theme"><themeToggle /></span>
|
|
62
|
-
@if (config.viewTransitions) {<span class="persist" data-cl-persist="view-transitions"><pageTransitions /></span>}
|
|
66
|
+
@if (props.config.viewTransitions) {<span class="persist" data-cl-persist="view-transitions"><pageTransitions /></span>}
|
|
63
67
|
</div>
|
|
64
68
|
</header>
|
package/src/parts/icon.tscl
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{{-- A sidebar group's icon (#369), by name: see parts/icons.ts. Decorative: the group's title says what it is. --}}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
import { ICONS } from './icons.ts'
|
|
4
|
+
import type { GroupIcon } from '../nav.ts'
|
|
5
|
+
const props = props<{
|
|
6
|
+
name: GroupIcon
|
|
7
|
+
}>()
|
|
8
|
+
</script>
|
|
5
9
|
|
|
6
10
|
<svg
|
|
7
|
-
[data-icon]="name"
|
|
11
|
+
[data-icon]="props.name"
|
|
8
12
|
width="14"
|
|
9
13
|
height="14"
|
|
10
14
|
viewBox="0 0 24 24"
|
|
@@ -15,7 +19,7 @@
|
|
|
15
19
|
stroke-linejoin="round"
|
|
16
20
|
aria-hidden="true"
|
|
17
21
|
>
|
|
18
|
-
@for (d of ICONS[name] ?? []; track d) {
|
|
22
|
+
@for (d of ICONS[props.name] ?? []; track d) {
|
|
19
23
|
<path [d]="d"></path>
|
|
20
24
|
}
|
|
21
25
|
</svg>
|
|
@@ -2,20 +2,24 @@
|
|
|
2
2
|
Under the content (a public part, #360): the edit link, when the page was last updated, and the previous and next
|
|
3
3
|
pages. Replace it with themeDocs({ components: { pageFooter } }) (#361).
|
|
4
4
|
--}}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { editHref, updatedOf, pager } from '../nav.ts'
|
|
7
|
+
import type { ThemeConfig } from '../nav.ts'
|
|
8
|
+
const props = props<{
|
|
9
|
+
config: ThemeConfig
|
|
10
|
+
path?: string
|
|
11
|
+
/** The page's own route, when it differs from its sidebar entry (see the layout's source input). */
|
|
12
|
+
source?: string
|
|
13
|
+
}>(() => ({ path: '/', source: '' }))
|
|
14
|
+
</script>
|
|
11
15
|
|
|
12
16
|
<footer class="page-footer">
|
|
13
|
-
@if (editHref(config, source || path)) {<a class="edit" [href]="editHref(config, source || path)">Edit this page on GitHub</a>}
|
|
14
|
-
@if (updatedOf(config, source || path)) {
|
|
17
|
+
@if (editHref(props.config, props.source || props.path)) {<a class="edit" [href]="editHref(props.config, props.source || props.path)">Edit this page on GitHub</a>}
|
|
18
|
+
@if (updatedOf(props.config, props.source || props.path)) {
|
|
15
19
|
<p class="updated">
|
|
16
20
|
Last updated
|
|
17
|
-
<time [datetime]="updatedOf(config, source || path)?.iso">{{ updatedOf(config, source || path)?.text }}</time>
|
|
21
|
+
<time [datetime]="updatedOf(props.config, props.source || props.path)?.iso">{{ updatedOf(props.config, props.source || props.path)?.text }}</time>
|
|
18
22
|
</p>
|
|
19
23
|
}
|
|
20
|
-
<nav class="pager" aria-label="Previous and next">@if (pager(config.sections, path).prev.href) {<a class="prev" [href]="pager(config.sections, path).prev.href"><small>Previous</small>{{ pager(config.sections, path).prev.title }}</a>} @if (pager(config.sections, path).next.href) {<a class="next" [href]="pager(config.sections, path).next.href"><small>Next</small>{{ pager(config.sections, path).next.title }}</a>}</nav>
|
|
24
|
+
<nav class="pager" aria-label="Previous and next">@if (pager(props.config.sections, props.path).prev.href) {<a class="prev" [href]="pager(props.config.sections, props.path).prev.href"><small>Previous</small>{{ pager(props.config.sections, props.path).prev.title }}</a>} @if (pager(props.config.sections, props.path).next.href) {<a class="next" [href]="pager(props.config.sections, props.path).next.href"><small>Next</small>{{ pager(props.config.sections, props.path).next.title }}</a>}</nav>
|
|
21
25
|
</footer>
|
package/src/parts/sidebar.tscl
CHANGED
|
@@ -9,10 +9,14 @@
|
|
|
9
9
|
or the search box: the header has one on phones), and a row of links at the bottom.
|
|
10
10
|
--}}
|
|
11
11
|
@import groupIcon from './icon.tscl'
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { groupsOf, sectionKey } from '../nav.ts'
|
|
14
|
+
import type { ThemeConfig } from '../nav.ts'
|
|
15
|
+
const props = props<{
|
|
16
|
+
config: ThemeConfig
|
|
17
|
+
path?: string
|
|
18
|
+
}>(() => ({ path: '/' }))
|
|
19
|
+
</script>
|
|
16
20
|
|
|
17
21
|
<nav id="sidebar" class="sidebar" aria-label="Pages" popover>
|
|
18
22
|
<div class="sidebar-head">
|
|
@@ -33,16 +37,16 @@
|
|
|
33
37
|
</button>
|
|
34
38
|
</div>
|
|
35
39
|
<div class="sidebar-switch mb-3 auto-cols-fr grid-flow-col gap-1 rounded-xl bg-surface p-1">
|
|
36
|
-
@for (s of config.sections.filter((s) => s.switch !== false); track s.key) {
|
|
40
|
+
@for (s of props.config.sections.filter((s) => s.switch !== false); track s.key) {
|
|
37
41
|
<a
|
|
38
42
|
[href]="s.href"
|
|
39
|
-
[aria-current]="s.key === sectionKey(config.sections, path) ? 'true' : false"
|
|
43
|
+
[aria-current]="s.key === sectionKey(props.config.sections, props.path) ? 'true' : false"
|
|
40
44
|
class="rounded-lg py-2 text-center text-sm font-semibold text-muted no-underline aria-[current=true]:bg-bg aria-[current=true]:text-accent aria-[current=true]:shadow-sm"
|
|
41
45
|
>{{ s.title }}</a
|
|
42
46
|
>
|
|
43
47
|
}
|
|
44
48
|
</div>
|
|
45
|
-
@if (config.search) {
|
|
49
|
+
@if (props.config.search) {
|
|
46
50
|
{{-- Opens the search dialog, as the header's button and Ctrl/⌘K do (search.tscl listens for data-search-open). --}}
|
|
47
51
|
<button
|
|
48
52
|
type="button"
|
|
@@ -70,11 +74,11 @@
|
|
|
70
74
|
</button>
|
|
71
75
|
}
|
|
72
76
|
<slot name="top"></slot>
|
|
73
|
-
@for (group of groupsOf(config.sections, path); track group.title) {
|
|
77
|
+
@for (group of groupsOf(props.config.sections, props.path); track group.title) {
|
|
74
78
|
<details
|
|
75
79
|
class="group mb-1.5"
|
|
76
80
|
[data-group]="group.title"
|
|
77
|
-
[open]="!group.collapsed || group.items.some((i) => i.href === path)"
|
|
81
|
+
[open]="!group.collapsed || group.items.some((i) => i.href === props.path)"
|
|
78
82
|
>
|
|
79
83
|
<summary
|
|
80
84
|
class="flex cursor-pointer list-none items-center gap-2.5 rounded-md py-1.5 pr-1 text-[13px] font-semibold text-fg select-none [&::-webkit-details-marker]:hidden"
|
|
@@ -103,7 +107,7 @@
|
|
|
103
107
|
<li class="m-0">
|
|
104
108
|
<a
|
|
105
109
|
[href]="item.href"
|
|
106
|
-
[aria-current]="item.href === path ? 'page' : false"
|
|
110
|
+
[aria-current]="item.href === props.path ? 'page' : false"
|
|
107
111
|
class="-ml-px flex items-center gap-2 rounded-r-md border-l-2 border-transparent py-[5px] pr-2 pl-3 text-[13px] text-fg/80 no-underline transition-colors hover:text-fg aria-[current=page]:border-accent aria-[current=page]:bg-accent-soft aria-[current=page]:font-semibold aria-[current=page]:text-accent"
|
|
108
112
|
>
|
|
109
113
|
<span class="flex-1">{{ item.title }}</span>
|
|
@@ -123,7 +127,7 @@
|
|
|
123
127
|
<div
|
|
124
128
|
class="sidebar-links mt-auto justify-between gap-x-3 gap-y-1 border-t border-rule pt-3 text-[13px] font-medium [&_a]:text-accent [&_a]:no-underline"
|
|
125
129
|
>
|
|
126
|
-
@for (link of [...(config.menuLinks ?? []), ...(config.social ?? [])]; track link.href) {
|
|
130
|
+
@for (link of [...(props.config.menuLinks ?? []), ...(props.config.social ?? [])]; track link.href) {
|
|
127
131
|
<a [href]="link.href">{{ link.label }}</a>
|
|
128
132
|
}
|
|
129
133
|
</div>
|
package/src/progress-board.tscl
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
Your progress, read from this browser: XP, lessons done, quiz accuracy, badges and each lesson's state, with Reset.
|
|
3
3
|
Without JavaScript (or with storage blocked) it says so; the lessons are still links.
|
|
4
4
|
--}}
|
|
5
|
-
@interface Lesson { title: string; href: string }
|
|
6
|
-
@input lessons: Lesson[]
|
|
7
5
|
|
|
8
|
-
<script>
|
|
6
|
+
<script lang="ts">
|
|
9
7
|
import { load, reset, save, stats } from './progress.ts'
|
|
8
|
+
import { browser } from 'clarusjs/runtime'
|
|
9
|
+
interface Lesson { title: string; href: string }
|
|
10
|
+
const props = props<{
|
|
11
|
+
lessons: Lesson[]
|
|
12
|
+
}>()
|
|
10
13
|
let xp = state(0)
|
|
11
14
|
let done = state(0)
|
|
12
15
|
let accuracy = state('')
|
|
@@ -17,7 +20,7 @@
|
|
|
17
20
|
function refresh() {
|
|
18
21
|
const s = stats(
|
|
19
22
|
load(),
|
|
20
|
-
lessons.map((l) => l.href),
|
|
23
|
+
props.lessons.map((l) => l.href),
|
|
21
24
|
)
|
|
22
25
|
xp = s.xp
|
|
23
26
|
done = s.done
|
|
@@ -25,7 +28,7 @@
|
|
|
25
28
|
? Math.round((s.right / s.answered) * 100) + '% (' + s.right + ' of ' + s.answered + ')'
|
|
26
29
|
: 'no quizzes answered yet'
|
|
27
30
|
badges = s.badges
|
|
28
|
-
statuses = Object.fromEntries(lessons.map((l) => [l.href, s.status(l.href)]))
|
|
31
|
+
statuses = Object.fromEntries(props.lessons.map((l) => [l.href, s.status(l.href)]))
|
|
29
32
|
}
|
|
30
33
|
function wipe() {
|
|
31
34
|
if (!confirming) {
|
|
@@ -37,7 +40,7 @@
|
|
|
37
40
|
refresh()
|
|
38
41
|
window.dispatchEvent(new Event('learn:progress'))
|
|
39
42
|
}
|
|
40
|
-
if (
|
|
43
|
+
if (browser) {
|
|
41
44
|
// Saving what is there tells us whether this browser keeps it.
|
|
42
45
|
mode = save(load()) ? 'saved' : 'blocked'
|
|
43
46
|
refresh()
|
|
@@ -60,7 +63,7 @@
|
|
|
60
63
|
</div>
|
|
61
64
|
<div>
|
|
62
65
|
<dt>Lessons</dt>
|
|
63
|
-
<dd>{{ done }} of {{ lessons.length }}</dd>
|
|
66
|
+
<dd>{{ done }} of {{ props.lessons.length }}</dd>
|
|
64
67
|
</div>
|
|
65
68
|
<div>
|
|
66
69
|
<dt>Quizzes right</dt>
|
|
@@ -79,7 +82,7 @@
|
|
|
79
82
|
}
|
|
80
83
|
<h2>Lessons</h2>
|
|
81
84
|
<ol class="progress-lessons">
|
|
82
|
-
@for (lesson of lessons; track lesson.href) {
|
|
85
|
+
@for (lesson of props.lessons; track lesson.href) {
|
|
83
86
|
<li [data-status]="statuses[lesson.href] ?? false">
|
|
84
87
|
<a [href]="lesson.href">{{ lesson.title }}</a
|
|
85
88
|
>@if (statuses[lesson.href]) { <span class="status-note">({{ statuses[lesson.href] === 'current' ? 'up next' : statuses[lesson.href] === 'done' ? 'done' : 'not started' }})</span>}
|
package/src/quiz-choices.tscl
CHANGED
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
the quiz's answer and marks the options. In a lesson, the action bar's Check sends a quiz:check event to the quiz;
|
|
4
4
|
the result goes back as a bubbling quiz:result event ({ ok, done, text }), so the bar can turn green or red.
|
|
5
5
|
--}}
|
|
6
|
-
@input name: string
|
|
7
|
-
@input options: string[]
|
|
8
|
-
@input answer: number
|
|
9
6
|
|
|
10
|
-
<script>
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { browser } from 'clarusjs/runtime'
|
|
9
|
+
const props = props<{
|
|
10
|
+
name: string
|
|
11
|
+
options: string[]
|
|
12
|
+
answer: number
|
|
13
|
+
}>()
|
|
14
|
+
|
|
11
15
|
let picked = state(-1)
|
|
12
16
|
let checked = state(false)
|
|
13
17
|
let status = state('')
|
|
14
|
-
const quiz = () => document.querySelector('[data-quiz="' + name + '"]')
|
|
18
|
+
const quiz = () => document.querySelector('[data-quiz="' + props.name + '"]')
|
|
15
19
|
function check() {
|
|
16
20
|
let detail
|
|
17
21
|
if (picked < 0) {
|
|
@@ -19,16 +23,16 @@
|
|
|
19
23
|
detail = { ok: false, done: false, text: status }
|
|
20
24
|
} else {
|
|
21
25
|
checked = true
|
|
22
|
-
const ok = picked === answer
|
|
23
|
-
status = ok ? 'Correct.' : 'Not quite. The answer is: ' + options[answer] + '.'
|
|
24
|
-
detail = { ok, done: true, text: ok ? 'Correct.' : 'The answer is: ' + options[answer] + '.' }
|
|
26
|
+
const ok = picked === props.answer
|
|
27
|
+
status = ok ? 'Correct.' : 'Not quite. The answer is: ' + props.options[props.answer] + '.'
|
|
28
|
+
detail = { ok, done: true, text: ok ? 'Correct.' : 'The answer is: ' + props.options[props.answer] + '.' }
|
|
25
29
|
quiz()?.setAttribute('data-answered', ok ? 'right' : 'wrong')
|
|
26
30
|
const details = quiz()?.querySelector('.quiz-answer')
|
|
27
31
|
if (details instanceof HTMLDetailsElement) details.open = true
|
|
28
32
|
}
|
|
29
33
|
quiz()?.dispatchEvent(new CustomEvent('quiz:result', { bubbles: true, detail }))
|
|
30
34
|
}
|
|
31
|
-
if (
|
|
35
|
+
if (browser) {
|
|
32
36
|
document.addEventListener('quiz:check', (event) => {
|
|
33
37
|
if (event.target === quiz() && !checked) check()
|
|
34
38
|
})
|
|
@@ -36,11 +40,11 @@
|
|
|
36
40
|
</script>
|
|
37
41
|
|
|
38
42
|
<div class="quiz-choices">
|
|
39
|
-
<div class="quiz-options" role="radiogroup" [aria-labelledby]="name + '-q'">
|
|
40
|
-
@for (option of options; track $index) {
|
|
41
|
-
<label [class]="!checked ? false : $index === answer ? 'right' : $index === picked ? 'wrong' : false"
|
|
42
|
-
><input type="radio" [name]="name" [value]="$index" [disabled]="checked" (change)="picked = $index" />
|
|
43
|
-
{{ option }}@if (checked && $index === answer) {<span class="mark">✓ Right answer</span>} @else if (checked && $index === picked) {<span class="mark">✗ Your pick</span>}</label
|
|
43
|
+
<div class="quiz-options" role="radiogroup" [aria-labelledby]="props.name + '-q'">
|
|
44
|
+
@for (option of props.options; track $index) {
|
|
45
|
+
<label [class]="!checked ? false : $index === props.answer ? 'right' : $index === picked ? 'wrong' : false"
|
|
46
|
+
><input type="radio" [name]="props.name" [value]="$index" [disabled]="checked" (change)="picked = $index" />
|
|
47
|
+
{{ option }}@if (checked && $index === props.answer) {<span class="mark">✓ Right answer</span>} @else if (checked && $index === picked) {<span class="mark">✗ Your pick</span>}</label
|
|
44
48
|
>
|
|
45
49
|
}
|
|
46
50
|
</div>
|
package/src/quiz.tscl
CHANGED
|
@@ -4,17 +4,21 @@
|
|
|
4
4
|
<details> shows the answer.
|
|
5
5
|
--}}
|
|
6
6
|
@import quizChoices from './quiz-choices.tscl'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
const props = props<{
|
|
9
|
+
name: string
|
|
10
|
+
question: string
|
|
11
|
+
options: string[]
|
|
12
|
+
answer: number
|
|
13
|
+
}>()
|
|
14
|
+
</script>
|
|
11
15
|
|
|
12
|
-
<div class="quiz" [data-quiz]="name">
|
|
13
|
-
<p class="quiz-question" [id]="name + '-q'">{{ question }}</p>
|
|
14
|
-
<quizChoices [name]="name" [options]="options" [answer]="answer" />
|
|
16
|
+
<div class="quiz" [data-quiz]="props.name">
|
|
17
|
+
<p class="quiz-question" [id]="props.name + '-q'">{{ props.question }}</p>
|
|
18
|
+
<quizChoices [name]="props.name" [options]="props.options" [answer]="props.answer" />
|
|
15
19
|
<details class="quiz-answer">
|
|
16
20
|
<summary>Show the answer</summary>
|
|
17
|
-
<p class="quiz-correct">Answer: {{ options[answer] }}</p>
|
|
21
|
+
<p class="quiz-correct">Answer: {{ props.options[props.answer] }}</p>
|
|
18
22
|
<slot />
|
|
19
23
|
</details>
|
|
20
24
|
</div>
|
package/src/search.tscl
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
<script>
|
|
8
8
|
import { navigate } from 'clarusjs/navigation'
|
|
9
9
|
import { base, search } from './search.js'
|
|
10
|
+
import { browser } from 'clarusjs/runtime'
|
|
10
11
|
let query = state('')
|
|
11
12
|
let results = state([])
|
|
12
13
|
let active = state(0)
|
|
@@ -64,7 +65,7 @@
|
|
|
64
65
|
dialog()?.close()
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
if (
|
|
68
|
+
if (browser) {
|
|
68
69
|
document.addEventListener('keydown', (event) => {
|
|
69
70
|
const typing =
|
|
70
71
|
event.target instanceof Element && event.target.closest('input, textarea, select, [contenteditable]')
|
package/src/styles/theme.css
CHANGED
|
@@ -334,9 +334,25 @@ details.custom-block[open] > summary { margin-bottom: 8px; }
|
|
|
334
334
|
.code-group > label { order: 0; font: 600 13px var(--mono); padding: 6px 12px; border: 1px solid var(--rule); border-bottom: 0; border-radius: 8px 8px 0 0; color: var(--muted); cursor: pointer; }
|
|
335
335
|
.code-group > input:checked + label { color: var(--accent); background: var(--code-bg); }
|
|
336
336
|
.code-group > input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
337
|
+
/* ```mermaid diagrams (mermaid.tscl): the source until drawn, then the SVG at full size, scrolling sideways when wider than the column */
|
|
338
|
+
.mermaid-diagram { margin: 0 0 20px; }
|
|
339
|
+
.mermaid-svg { display: flex; overflow-x: auto; }
|
|
340
|
+
.mermaid-svg svg { margin: 0 auto; height: auto; } /* centred; wider than the column, it scrolls (flex centring would cut off its start) */
|
|
337
341
|
.code-group > .code-block { order: 1; width: 100%; display: none; margin: 0; }
|
|
338
342
|
.code-group > input:checked + label + .code-block { display: block; }
|
|
339
343
|
.code-group > .code-block pre { border-top-left-radius: 0; }
|
|
344
|
+
/* ::: code-group :scroll (or codeGroups: 'scroll' in the theme config, unless the group says :wrap): the tabs on one row
|
|
345
|
+
that scrolls sideways, the code staying in place. A grid of --tabs pairs: each radio in a zero-width column before its
|
|
346
|
+
label, so focusing it (arrow keys) scrolls its tab into view; the code spans the row below at the group's own width
|
|
347
|
+
(100cqi), sticky at its left edge. */
|
|
348
|
+
:is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) {
|
|
349
|
+
display: grid; grid-template-columns: repeat(var(--tabs, 1), 0 max-content); position: relative;
|
|
350
|
+
overflow-x: auto; scrollbar-width: thin; container-type: inline-size;
|
|
351
|
+
}
|
|
352
|
+
:is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > input { position: static; grid-row: 1; width: 0; height: 0; margin: 0; scroll-margin-inline-end: 16rem; }
|
|
353
|
+
/* A label is at most as wide as its radio's scroll margin, so focusing the radio brings the whole tab into view. */
|
|
354
|
+
:is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > label { grid-row: 1; white-space: nowrap; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; }
|
|
355
|
+
:is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > .code-block { grid-row: 2; grid-column: 1 / -1; width: 100cqi; position: sticky; left: 0; }
|
|
340
356
|
|
|
341
357
|
/* Visitors who ask for less motion get none: transitions and animations end at once, scrolling jumps. */
|
|
342
358
|
@media (prefers-reduced-motion: reduce) {
|