@clarusjs/theme-docs 0.6.0 → 0.8.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 +10 -7
- package/src/callout.tscl +8 -4
- 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 +10 -7
- package/src/lesson-bar.tscl +36 -23
- package/src/lesson.css +5 -2
- package/src/lesson.tscl +36 -29
- package/src/mermaid.tscl +5 -2
- package/src/nav.ts +40 -3
- package/src/page-head.tscl +24 -10
- package/src/pages.d.ts +6 -0
- 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 +17 -11
- package/src/parts/version-menu.tscl +33 -0
- 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 +12 -0
- package/src/theme.css +68 -0
- package/src/version-list.tscl +25 -0
- package/src/versions-cli.js +229 -0
- package/src/versions.d.ts +163 -0
- package/src/versions.js +209 -0
- package/src/vite.d.ts +27 -0
- package/src/vite.js +40 -1
package/src/nav.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type Heading = { id: string; text: string; level: number }
|
|
|
25
25
|
* What a site's layout passes to a theme's `layout.tscl`: the contract a theme implements (#362). `config` and
|
|
26
26
|
* `title` always; the rest optional, with the defaults the docs theme uses. A theme's layout also has the slots
|
|
27
27
|
* `sidebar-top`, `sidebar-bottom`, `content-top`, `content-bottom` and `footer`, beside its default one.
|
|
28
|
-
* @see https://clarusjs.com/
|
|
28
|
+
* @see https://clarusjs.com/docs-sites/writing-a-theme
|
|
29
29
|
*/
|
|
30
30
|
export type LayoutInputs = {
|
|
31
31
|
config: ThemeConfig
|
|
@@ -63,11 +63,18 @@ export type ThemeConfig = {
|
|
|
63
63
|
/**
|
|
64
64
|
* Learn: the section whose pages are lessons, and its progress page (not a lesson). Progress, XP and badges are
|
|
65
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
|
|
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:`.
|
|
67
69
|
*/
|
|
68
|
-
learn?: { section: string; progress: string; layout?:
|
|
70
|
+
learn?: { section: string; progress: string; layout?: LessonLayout }
|
|
69
71
|
/** A search button (and Ctrl/⌘K, /) in the header; the index comes from the themeDocs() Vite plugin. */
|
|
70
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'
|
|
71
78
|
/**
|
|
72
79
|
* Page changes animate as view transitions where the browser has them (a cross-fade; `::view-transition-*` rules in
|
|
73
80
|
* the site's CSS change it). Needs fragment navigation or client routes; no animation with reduced motion.
|
|
@@ -75,6 +82,26 @@ export type ThemeConfig = {
|
|
|
75
82
|
viewTransitions?: boolean
|
|
76
83
|
/** The site footer's text. */
|
|
77
84
|
footer?: string
|
|
85
|
+
/**
|
|
86
|
+
* Versioned docs: a version menu at the top of the sidebar, and links into archived versions load their pages. Pass
|
|
87
|
+
* `import versions from 'virtual:theme-docs/versions'` (themeDocs({ versions }) serves it; null without the option).
|
|
88
|
+
* @see https://clarusjs.com/docs-sites/versioned-docs
|
|
89
|
+
*/
|
|
90
|
+
versions?: Versions | null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The version menu's data, as themeDocs({ versions }) serves it. */
|
|
94
|
+
export type Versions = {
|
|
95
|
+
/** The live docs' version, as shown ('v0.20.0'). */
|
|
96
|
+
current: string
|
|
97
|
+
/** The archived versions served, newest first (version '0.19' is at /v0.19/), with the tag each was built from. */
|
|
98
|
+
archived: readonly { version: string; tag: string }[]
|
|
99
|
+
/** More rows at the end of the menu. */
|
|
100
|
+
links: readonly { label: string; href: string }[]
|
|
101
|
+
/** At most this many archived versions in the menu; the rest through `all`. */
|
|
102
|
+
menu?: number
|
|
103
|
+
/** A page listing every version: an "All versions" row in the menu. */
|
|
104
|
+
all?: string
|
|
78
105
|
}
|
|
79
106
|
|
|
80
107
|
const none: Item = { title: '', href: '' }
|
|
@@ -182,3 +209,13 @@ export function lessonOf(config: ThemeConfig, path: string): { leave: string; pr
|
|
|
182
209
|
total: items.length,
|
|
183
210
|
}
|
|
184
211
|
}
|
|
212
|
+
|
|
213
|
+
/** How a lesson places each step's code: beside the text (split) or in line with it (stacked), either way round. */
|
|
214
|
+
export type LessonLayout = 'split' | 'split-reverse' | 'stacked' | 'stacked-reverse'
|
|
215
|
+
const LESSON_LAYOUTS: readonly string[] = ['split', 'split-reverse', 'stacked', 'stacked-reverse']
|
|
216
|
+
|
|
217
|
+
/** A lesson's layout: its frontmatter's `lessonLayout` when valid, else the site's `learn.layout`, else 'split'. */
|
|
218
|
+
export function lessonLayoutOf(config: ThemeConfig, frontmatter?: Record<string, unknown>): LessonLayout {
|
|
219
|
+
const own = frontmatter?.lessonLayout
|
|
220
|
+
return typeof own === 'string' && LESSON_LAYOUTS.includes(own) ? (own as LessonLayout) : config.learn?.layout ?? 'split'
|
|
221
|
+
}
|
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>
|
|
@@ -14,14 +19,23 @@
|
|
|
14
19
|
</script>
|
|
15
20
|
<fragment>
|
|
16
21
|
<meta charset="utf-8" />
|
|
22
|
+
{{--
|
|
23
|
+
Versioned docs: each version is its own build, so a link into another version loads the page instead of the
|
|
24
|
+
site's navigator swapping it in (LATEST_GUARD in versions.js; a test keeps the two the same). Before the module scripts.
|
|
25
|
+
--}}
|
|
26
|
+
@if (props.config.versions) {
|
|
27
|
+
<script inline>
|
|
28
|
+
window.navigation&&navigation.addEventListener('navigate',function(e){var p=new URL(e.destination.url).pathname;var v=function(x){var r=/\/(v\d+(?:\.\d+)?)(?:\/|$)/.exec(x);return r?r[1]:''};if(v(p)!==v(location.pathname))e.stopImmediatePropagation()})
|
|
29
|
+
</script>
|
|
30
|
+
}
|
|
17
31
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
18
|
-
@if (description) {
|
|
19
|
-
<meta name="description" content="{{ description }}" />
|
|
32
|
+
@if (props.description) {
|
|
33
|
+
<meta name="description" content="{{ props.description }}" />
|
|
20
34
|
}
|
|
21
|
-
<title>{{ title }}</title>
|
|
22
|
-
@if (config.siteUrl) {
|
|
35
|
+
<title>{{ props.title }}</title>
|
|
36
|
+
@if (props.config.siteUrl) {
|
|
23
37
|
<script type="application/ld+json">
|
|
24
|
-
{{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: title, description, url: `${config.siteUrl}${url === '/' ? '' : url}` } }}
|
|
38
|
+
{{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: props.title, description: props.description, url: `${props.config.siteUrl}${props.url === '/' ? '' : props.url}` } }}
|
|
25
39
|
</script>
|
|
26
40
|
}
|
|
27
41
|
</fragment>
|
package/src/pages.d.ts
CHANGED
|
@@ -4,3 +4,9 @@ declare module 'virtual:theme-docs/pages' {
|
|
|
4
4
|
const pages: import('./nav.ts').PageInfo[]
|
|
5
5
|
export default pages
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
// Versioned docs: the version menu's data (themeDocs({ versions })), for the theme config's `versions`.
|
|
9
|
+
declare module 'virtual:theme-docs/versions' {
|
|
10
|
+
const versions: import('./nav.ts').Versions | null
|
|
11
|
+
export default versions
|
|
12
|
+
}
|
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,15 @@
|
|
|
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
|
-
@import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
@import versionMenu from './version-menu.tscl'
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import { groupsOf, sectionKey } from '../nav.ts'
|
|
15
|
+
import type { ThemeConfig } from '../nav.ts'
|
|
16
|
+
const props = props<{
|
|
17
|
+
config: ThemeConfig
|
|
18
|
+
path?: string
|
|
19
|
+
}>(() => ({ path: '/' }))
|
|
20
|
+
</script>
|
|
16
21
|
|
|
17
22
|
<nav id="sidebar" class="sidebar" aria-label="Pages" popover>
|
|
18
23
|
<div class="sidebar-head">
|
|
@@ -33,16 +38,16 @@
|
|
|
33
38
|
</button>
|
|
34
39
|
</div>
|
|
35
40
|
<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) {
|
|
41
|
+
@for (s of props.config.sections.filter((s) => s.switch !== false); track s.key) {
|
|
37
42
|
<a
|
|
38
43
|
[href]="s.href"
|
|
39
|
-
[aria-current]="s.key === sectionKey(config.sections, path) ? 'true' : false"
|
|
44
|
+
[aria-current]="s.key === sectionKey(props.config.sections, props.path) ? 'true' : false"
|
|
40
45
|
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
46
|
>{{ s.title }}</a
|
|
42
47
|
>
|
|
43
48
|
}
|
|
44
49
|
</div>
|
|
45
|
-
@if (config.search) {
|
|
50
|
+
@if (props.config.search) {
|
|
46
51
|
{{-- Opens the search dialog, as the header's button and Ctrl/⌘K do (search.tscl listens for data-search-open). --}}
|
|
47
52
|
<button
|
|
48
53
|
type="button"
|
|
@@ -69,12 +74,13 @@
|
|
|
69
74
|
>
|
|
70
75
|
</button>
|
|
71
76
|
}
|
|
77
|
+
@if (props.config.versions) {<versionMenu [versions]="props.config.versions" [path]="props.path" />}
|
|
72
78
|
<slot name="top"></slot>
|
|
73
|
-
@for (group of groupsOf(config.sections, path); track group.title) {
|
|
79
|
+
@for (group of groupsOf(props.config.sections, props.path); track group.title) {
|
|
74
80
|
<details
|
|
75
81
|
class="group mb-1.5"
|
|
76
82
|
[data-group]="group.title"
|
|
77
|
-
[open]="!group.collapsed || group.items.some((i) => i.href === path)"
|
|
83
|
+
[open]="!group.collapsed || group.items.some((i) => i.href === props.path)"
|
|
78
84
|
>
|
|
79
85
|
<summary
|
|
80
86
|
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 +109,7 @@
|
|
|
103
109
|
<li class="m-0">
|
|
104
110
|
<a
|
|
105
111
|
[href]="item.href"
|
|
106
|
-
[aria-current]="item.href === path ? 'page' : false"
|
|
112
|
+
[aria-current]="item.href === props.path ? 'page' : false"
|
|
107
113
|
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
114
|
>
|
|
109
115
|
<span class="flex-1">{{ item.title }}</span>
|
|
@@ -123,7 +129,7 @@
|
|
|
123
129
|
<div
|
|
124
130
|
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
131
|
>
|
|
126
|
-
@for (link of [...(config.menuLinks ?? []), ...(config.social ?? [])]; track link.href) {
|
|
132
|
+
@for (link of [...(props.config.menuLinks ?? []), ...(props.config.social ?? [])]; track link.href) {
|
|
127
133
|
<a [href]="link.href">{{ link.label }}</a>
|
|
128
134
|
}
|
|
129
135
|
</div>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{{--
|
|
2
|
+
The version menu (versioned docs), at the top of the sidebar when the theme config has `versions`: the live docs'
|
|
3
|
+
version, the same page in each archived one, and the site's own links. A <details>: it opens without JavaScript.
|
|
4
|
+
Archived versions are other builds: a link to one loads the page (the guard in page-head.tscl).
|
|
5
|
+
--}}
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { Versions } from '../nav.ts'
|
|
8
|
+
const { versions, path = '/' } = props<{
|
|
9
|
+
/** The menu's data: themeDocs({ versions }) serves it as virtual:theme-docs/versions. */
|
|
10
|
+
versions: Versions
|
|
11
|
+
/** The page being read: each version's link goes to it. */
|
|
12
|
+
path?: string
|
|
13
|
+
}>()
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<details class="version-menu group relative mb-3 text-[13px]">
|
|
17
|
+
<summary
|
|
18
|
+
class="inline-flex cursor-pointer list-none items-center gap-1.5 rounded-full border border-rule px-2.5 py-1 font-semibold text-muted hover:border-accent hover:text-fg group-open:border-accent group-open:text-fg after:text-[10px] after:content-['▾'] [&::-webkit-details-marker]:hidden"
|
|
19
|
+
>{{ versions.current }}</summary
|
|
20
|
+
>
|
|
21
|
+
<ul class="m-0 mt-1.5 list-none rounded-lg border border-rule bg-bg p-1">
|
|
22
|
+
<li><a [href]="path" aria-current="true" class="block rounded-md px-2 py-1.5 font-semibold text-accent no-underline hover:bg-surface">{{ versions.current }} (latest)</a></li>
|
|
23
|
+
@for (v of versions.archived.slice(0, versions.menu ?? Infinity); track v.version) {
|
|
24
|
+
<li><a [href]="`/v${v.version}${path === '/' ? '/' : path}`" class="block rounded-md px-2 py-1.5 text-fg no-underline hover:bg-surface">v{{ v.version }}</a></li>
|
|
25
|
+
}
|
|
26
|
+
@if (versions.all) {
|
|
27
|
+
<li><a [href]="versions.all" class="block rounded-md px-2 py-1.5 text-fg no-underline hover:bg-surface">All versions</a></li>
|
|
28
|
+
}
|
|
29
|
+
@for (l of versions.links; track l.href) {
|
|
30
|
+
<li><a [href]="l.href" class="block rounded-md px-2 py-1.5 text-fg no-underline hover:bg-surface">{{ l.label }}</a></li>
|
|
31
|
+
}
|
|
32
|
+
</ul>
|
|
33
|
+
</details>
|
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
|
@@ -341,6 +341,18 @@ details.custom-block[open] > summary { margin-bottom: 8px; }
|
|
|
341
341
|
.code-group > .code-block { order: 1; width: 100%; display: none; margin: 0; }
|
|
342
342
|
.code-group > input:checked + label + .code-block { display: block; }
|
|
343
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; }
|
|
344
356
|
|
|
345
357
|
/* Visitors who ask for less motion get none: transitions and animations end at once, scrolling jumps. */
|
|
346
358
|
@media (prefers-reduced-motion: reduce) {
|