@clarusjs/theme-docs 0.1.1 → 0.1.3
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 +3 -3
- package/src/callout.tscl +25 -8
- package/src/copy.tscl +9 -5
- package/src/layout.tscl +67 -26
- package/src/learn-status.tscl +6 -3
- package/src/lesson-bar.tscl +27 -9
- package/src/lesson.tscl +31 -5
- package/src/nav.ts +12 -11
- package/src/page-head.tscl +17 -6
- package/src/progress-board.tscl +42 -12
- package/src/progress.ts +1 -1
- package/src/quiz-choices.tscl +8 -3
- package/src/quiz.tscl +5 -1
- package/src/search.d.ts +3 -0
- package/src/search.js +4 -0
- package/src/search.tscl +69 -14
- package/src/theme-toggle.tscl +14 -3
- package/src/view-transitions.tscl +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clarusjs/theme-docs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A docs theme for clarusjs: layout with header, sidebar, content and on-this-page, design tokens, dark mode, copy buttons and callouts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"clarusjs": "^0.
|
|
19
|
+
"clarusjs": "^0.10.0"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": "^22.12.0 || ^24.0.0 || >=26.0.0"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^26.6.6",
|
|
42
|
-
"clarusjs": "^0.
|
|
42
|
+
"clarusjs": "^0.10.0",
|
|
43
43
|
"typescript": "^7.0.2",
|
|
44
44
|
"vitest": "^5.1.1",
|
|
45
45
|
"vite": "^8.3.8"
|
package/src/callout.tscl
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
@
|
|
1
|
+
@type Kind = 'tip' | 'info' | 'warning' | 'danger'
|
|
2
|
+
@input type: Kind = 'info'
|
|
2
3
|
|
|
3
|
-
<aside role="note" class="callout {{ type }}"
|
|
4
|
+
<aside role="note" class="callout {{ type }}">
|
|
5
|
+
<p class="callout-title">
|
|
6
|
+
<slot name="title">{{ type[0].toUpperCase() + type.slice(1) }}</slot>
|
|
7
|
+
</p>
|
|
8
|
+
<slot />
|
|
9
|
+
</aside>
|
|
4
10
|
|
|
5
|
-
<style>
|
|
11
|
+
<style scoped>
|
|
6
12
|
/* Scoped to this component: :scope is the <aside>; slot content inside it is styled too. */
|
|
7
13
|
:scope {
|
|
8
14
|
border-left: 3px solid var(--accent);
|
|
@@ -11,9 +17,20 @@
|
|
|
11
17
|
border-radius: 0 8px 8px 0;
|
|
12
18
|
margin: 24px 0;
|
|
13
19
|
}
|
|
14
|
-
:scope.tip {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
|
|
20
|
+
:scope.tip {
|
|
21
|
+
border-left-color: #2f9e6e;
|
|
22
|
+
}
|
|
23
|
+
:scope.warning {
|
|
24
|
+
border-left-color: #c98a12;
|
|
25
|
+
}
|
|
26
|
+
:scope.danger {
|
|
27
|
+
border-left-color: #d0453b;
|
|
28
|
+
}
|
|
29
|
+
.callout-title {
|
|
30
|
+
margin: 0 0 4px;
|
|
31
|
+
font-weight: 650;
|
|
32
|
+
}
|
|
33
|
+
p:last-child {
|
|
34
|
+
margin-bottom: 0;
|
|
35
|
+
}
|
|
19
36
|
</style>
|
package/src/copy.tscl
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
{{-- A copy button for the code it sits next to: a .sample wrapper, or a highlighted .code-block from Markdown. --}}
|
|
2
|
+
|
|
2
3
|
<script>
|
|
3
4
|
let copied = state(false)
|
|
4
5
|
async function copy(button) {
|
|
5
6
|
const block = button.closest('.sample, .code-block')?.querySelector('code')
|
|
6
7
|
// Removed diff lines aren't part of the code to copy.
|
|
7
8
|
const clone = block?.cloneNode(true)
|
|
8
|
-
clone
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (clone instanceof Element)
|
|
10
|
+
clone.querySelectorAll('.diff.remove').forEach((line) => {
|
|
11
|
+
if (line.nextSibling?.nodeType === 3 && line.nextSibling.textContent === '\n') line.nextSibling.remove() // its newline too
|
|
12
|
+
line.remove()
|
|
13
|
+
})
|
|
12
14
|
const code = clone?.textContent ?? ''
|
|
13
15
|
try {
|
|
14
16
|
await navigator.clipboard.writeText(code)
|
|
15
17
|
copied = true
|
|
16
|
-
setTimeout(() => {
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
copied = false
|
|
20
|
+
}, 1500)
|
|
17
21
|
} catch {}
|
|
18
22
|
}
|
|
19
23
|
</script>
|
package/src/layout.tscl
CHANGED
|
@@ -24,20 +24,33 @@
|
|
|
24
24
|
@input headings: Heading[] = []
|
|
25
25
|
|
|
26
26
|
<html lang="en">
|
|
27
|
-
<head
|
|
27
|
+
<head>
|
|
28
|
+
<pageHead [config]="config" [title]="title" [description]="description" [url]="url || path" />
|
|
29
|
+
</head>
|
|
28
30
|
<body>
|
|
29
31
|
{{-- First in the tab order: keyboard and screen reader users jump past the header and page list. --}}
|
|
30
32
|
<a class="skip-link" href="#content">Skip to content</a>
|
|
31
33
|
<header class="site-header">
|
|
32
34
|
@if (sectionKey(config.sections, path)) {
|
|
33
35
|
<button type="button" class="menu-button" popovertarget="sidebar" aria-label="Open menu">
|
|
34
|
-
<svg
|
|
36
|
+
<svg
|
|
37
|
+
width="22"
|
|
38
|
+
height="22"
|
|
39
|
+
viewBox="0 0 24 24"
|
|
40
|
+
fill="none"
|
|
41
|
+
stroke="currentColor"
|
|
42
|
+
stroke-width="2.2"
|
|
43
|
+
stroke-linecap="round"
|
|
44
|
+
aria-hidden="true"
|
|
45
|
+
>
|
|
46
|
+
<path d="M4 7h16M4 12h16M4 17h16"></path>
|
|
47
|
+
</svg>
|
|
35
48
|
</button>
|
|
36
49
|
}
|
|
37
|
-
<a class="brand" href="/"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
</nav>
|
|
50
|
+
<a class="brand" href="/"
|
|
51
|
+
>@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
|
|
52
|
+
>
|
|
53
|
+
<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>
|
|
41
54
|
<div class="header-end">
|
|
42
55
|
{{-- On Learn pages: the XP chip, and the sidebar's lessons marked done, current or locked. --}}
|
|
43
56
|
@if (config.learn && sectionKey(config.sections, path) === config.learn.section) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
|
|
@@ -46,18 +59,18 @@
|
|
|
46
59
|
@if ((config.social ?? []).length) {
|
|
47
60
|
<span class="social">
|
|
48
61
|
@for (link of config.social ?? []; track link.href) {
|
|
49
|
-
<a [href]="link.href" [aria-label]="link.label" [title]="link.label">
|
|
50
|
-
@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>}
|
|
51
|
-
</a>
|
|
62
|
+
<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>
|
|
52
63
|
}
|
|
53
64
|
</span>
|
|
54
65
|
{{-- When the header runs out of room, the social links fold into this menu (native popover). --}}
|
|
55
66
|
<button type="button" class="more-button" popovertarget="more" aria-label="More links">
|
|
56
|
-
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"
|
|
67
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
68
|
+
<circle cx="5" cy="12" r="2"></circle>
|
|
69
|
+
<circle cx="12" cy="12" r="2"></circle>
|
|
70
|
+
<circle cx="19" cy="12" r="2"></circle>
|
|
71
|
+
</svg>
|
|
57
72
|
</button>
|
|
58
|
-
<div id="more" class="more" popover>
|
|
59
|
-
@for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}
|
|
60
|
-
</div>
|
|
73
|
+
<div id="more" class="more" popover>@for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
|
|
61
74
|
}
|
|
62
75
|
{{-- Kept across fragment navigations: the same element, with its state. --}}
|
|
63
76
|
<span class="persist" data-cl-persist="theme"><themeToggle /></span>
|
|
@@ -71,22 +84,34 @@
|
|
|
71
84
|
<div class="sidebar-head">
|
|
72
85
|
<span>{{ config.brand.text }}{{ config.brand.accent ?? '' }}</span>
|
|
73
86
|
<button type="button" popovertarget="sidebar" popovertargetaction="hide" aria-label="Close the menu">
|
|
74
|
-
<svg
|
|
87
|
+
<svg
|
|
88
|
+
width="20"
|
|
89
|
+
height="20"
|
|
90
|
+
viewBox="0 0 24 24"
|
|
91
|
+
fill="none"
|
|
92
|
+
stroke="currentColor"
|
|
93
|
+
stroke-width="2.2"
|
|
94
|
+
stroke-linecap="round"
|
|
95
|
+
aria-hidden="true"
|
|
96
|
+
>
|
|
97
|
+
<path d="M6 6l12 12M18 6L6 18"></path>
|
|
98
|
+
</svg>
|
|
75
99
|
</button>
|
|
76
100
|
</div>
|
|
77
101
|
<slot name="sidebar-top"></slot>
|
|
78
102
|
@for (group of groupsOf(config.sections, path); track group.title) {
|
|
79
103
|
<p class="group">{{ group.title }}</p>
|
|
80
104
|
<ul>
|
|
81
|
-
@for (item of group.items; track item.href) {
|
|
105
|
+
@for (item of group.items; track item.href) {
|
|
106
|
+
<li>
|
|
107
|
+
<a [href]="item.href" [aria-current]="item.href === path ? 'page' : false">{{ item.title }}</a>
|
|
108
|
+
</li>
|
|
109
|
+
}
|
|
82
110
|
</ul>
|
|
83
111
|
}
|
|
84
112
|
<slot name="sidebar-bottom"></slot>
|
|
85
113
|
{{-- On phones, the header's links live here. --}}
|
|
86
|
-
<div class="sidebar-links">
|
|
87
|
-
@for (s of config.sections; track s.key) {<a [href]="s.href">{{ s.title }}</a>}
|
|
88
|
-
@for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}
|
|
89
|
-
</div>
|
|
114
|
+
<div class="sidebar-links">@for (s of config.sections; track s.key) {<a [href]="s.href">{{ s.title }}</a>} @for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
|
|
90
115
|
</nav>
|
|
91
116
|
{{-- tabindex -1: the skip link (and navigation) can move focus here. --}}
|
|
92
117
|
<main class="content" id="content" tabindex="-1">
|
|
@@ -94,7 +119,13 @@
|
|
|
94
119
|
@if (headings.length) {
|
|
95
120
|
<details class="toc-inline">
|
|
96
121
|
<summary>On this page</summary>
|
|
97
|
-
<ul
|
|
122
|
+
<ul>
|
|
123
|
+
@for (h of headings; track h.id) {
|
|
124
|
+
<li [class]="h.level === 3 ? 'sub' : false">
|
|
125
|
+
<a [href]="'#' + h.id">{{ h.text }}</a>
|
|
126
|
+
</li>
|
|
127
|
+
}
|
|
128
|
+
</ul>
|
|
98
129
|
</details>
|
|
99
130
|
}
|
|
100
131
|
<slot name="content-top"></slot>
|
|
@@ -102,17 +133,27 @@
|
|
|
102
133
|
<slot name="content-bottom"></slot>
|
|
103
134
|
<footer class="page-footer">
|
|
104
135
|
@if (editHref(config, source || path)) {<a class="edit" [href]="editHref(config, source || path)">Edit this page on GitHub</a>}
|
|
105
|
-
@if (updatedOf(config, source || path)) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
136
|
+
@if (updatedOf(config, source || path)) {
|
|
137
|
+
<p class="updated">
|
|
138
|
+
Last updated
|
|
139
|
+
<time [datetime]="updatedOf(config, source || path)?.iso">{{
|
|
140
|
+
updatedOf(config, source || path)?.text
|
|
141
|
+
}}</time>
|
|
142
|
+
</p>
|
|
143
|
+
}
|
|
144
|
+
<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>
|
|
110
145
|
</footer>
|
|
111
146
|
</main>
|
|
112
147
|
@if (headings.length) {
|
|
113
148
|
<aside class="toc" aria-label="On this page">
|
|
114
149
|
<p>On this page</p>
|
|
115
|
-
<ul
|
|
150
|
+
<ul>
|
|
151
|
+
@for (h of headings; track h.id) {
|
|
152
|
+
<li [class]="h.level === 3 ? 'sub' : false">
|
|
153
|
+
<a [href]="'#' + h.id">{{ h.text }}</a>
|
|
154
|
+
</li>
|
|
155
|
+
}
|
|
156
|
+
</ul>
|
|
116
157
|
</aside>
|
|
117
158
|
}
|
|
118
159
|
</div>
|
package/src/learn-status.tscl
CHANGED
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
xp = s.xp
|
|
17
17
|
ready = true
|
|
18
18
|
for (const link of document.querySelectorAll('.sidebar ul a[href]')) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const href = link.getAttribute('href') ?? ''
|
|
20
|
+
if (!(link instanceof HTMLElement) || !lessons.includes(href)) continue
|
|
21
|
+
const status = s.status(href)
|
|
21
22
|
link.dataset.status = status
|
|
22
23
|
let note = link.querySelector('.status-note')
|
|
23
24
|
if (!note) {
|
|
@@ -35,6 +36,8 @@
|
|
|
35
36
|
</script>
|
|
36
37
|
|
|
37
38
|
<a class="xp-chip" [href]="progress" [hidden]="!ready" [aria-label]="xp + ' XP: your progress'">
|
|
38
|
-
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"
|
|
39
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
40
|
+
<path d="M13 2L4 14h7l-1 8 9-12h-7z"></path>
|
|
41
|
+
</svg>
|
|
39
42
|
{{ xp }} XP
|
|
40
43
|
</a>
|
package/src/lesson-bar.tscl
CHANGED
|
@@ -31,16 +31,18 @@
|
|
|
31
31
|
bar()?.classList.toggle('ok', kind === 'ok')
|
|
32
32
|
bar()?.classList.toggle('bad', kind === 'bad')
|
|
33
33
|
}
|
|
34
|
-
const steps = () => [...document.querySelectorAll('main .step')]
|
|
34
|
+
const steps = () => [...document.querySelectorAll('main .step')].filter((el) => el instanceof HTMLElement)
|
|
35
35
|
function show(i, focus) {
|
|
36
36
|
const all = steps()
|
|
37
37
|
if (!all.length) return
|
|
38
38
|
current = Math.max(0, Math.min(i, all.length - 1))
|
|
39
39
|
total = all.length
|
|
40
|
-
all.forEach((step, j) => {
|
|
40
|
+
all.forEach((step, j) => {
|
|
41
|
+
step.hidden = j !== current
|
|
42
|
+
})
|
|
41
43
|
checking = !!all[current].querySelector('[data-quiz]:not([data-answered])')
|
|
42
44
|
verdict('', '', '')
|
|
43
|
-
const id = all[current].getAttribute('aria-labelledby')
|
|
45
|
+
const id = all[current].getAttribute('aria-labelledby') ?? ''
|
|
44
46
|
name = document.getElementById(id)?.textContent?.replace(/#$/, '').trim() ?? ''
|
|
45
47
|
document.querySelectorAll('.segments li').forEach((li, j) => {
|
|
46
48
|
li.className = j < current ? 'done' : j === current ? 'current' : ''
|
|
@@ -57,7 +59,9 @@
|
|
|
57
59
|
// The step a #hash points into: its own heading, or anything inside it.
|
|
58
60
|
const indexOf = (hash) => {
|
|
59
61
|
const id = decodeURIComponent(hash.slice(1))
|
|
60
|
-
return id
|
|
62
|
+
return id
|
|
63
|
+
? steps().findIndex((s) => s.getAttribute('aria-labelledby') === id || s.querySelector('#' + CSS.escape(id)))
|
|
64
|
+
: -1
|
|
61
65
|
}
|
|
62
66
|
function back() {
|
|
63
67
|
if (current > 0) show(current - 1, true)
|
|
@@ -65,7 +69,9 @@
|
|
|
65
69
|
}
|
|
66
70
|
function forward() {
|
|
67
71
|
if (checking) {
|
|
68
|
-
steps()
|
|
72
|
+
steps()
|
|
73
|
+
[current]?.querySelector('[data-quiz]:not([data-answered])')
|
|
74
|
+
?.dispatchEvent(new CustomEvent('quiz:check', { bubbles: true }))
|
|
69
75
|
return
|
|
70
76
|
}
|
|
71
77
|
const id = steps()[current]?.getAttribute('aria-labelledby')
|
|
@@ -92,7 +98,8 @@
|
|
|
92
98
|
if (typeof document !== 'undefined' && steps().length) {
|
|
93
99
|
steps().forEach(split)
|
|
94
100
|
document.body.classList.add('one-step')
|
|
95
|
-
document.querySelector('.lesson-bar')
|
|
101
|
+
const lessonBar = document.querySelector('.lesson-bar')
|
|
102
|
+
if (lessonBar instanceof HTMLElement) lessonBar.hidden = false
|
|
96
103
|
// A #hash opens the step it points into and keeps its target: a step heading takes focus, anything else
|
|
97
104
|
// scrolls into view (Back and Continue go by step headings instead).
|
|
98
105
|
function reveal() {
|
|
@@ -106,10 +113,16 @@
|
|
|
106
113
|
}
|
|
107
114
|
if (!reveal()) show(0, false)
|
|
108
115
|
document.addEventListener('quiz:result', (event) => {
|
|
109
|
-
if (
|
|
116
|
+
if (
|
|
117
|
+
!(event instanceof CustomEvent) ||
|
|
118
|
+
!(event.target instanceof HTMLElement) ||
|
|
119
|
+
!steps()[current]?.contains(event.target)
|
|
120
|
+
)
|
|
121
|
+
return
|
|
110
122
|
const { ok, done, text: detail } = event.detail
|
|
111
123
|
if (!done) return verdict('', 'Pick an answer', detail)
|
|
112
|
-
|
|
124
|
+
const quiz = event.target.dataset.quiz
|
|
125
|
+
record((p) => answer(p, lesson + '#' + quiz, ok))
|
|
113
126
|
checking = !!steps()[current].querySelector('[data-quiz]:not([data-answered])')
|
|
114
127
|
verdict(ok ? 'ok' : 'bad', ok ? 'Correct!' : 'Not quite', detail)
|
|
115
128
|
})
|
|
@@ -120,7 +133,12 @@
|
|
|
120
133
|
<div class="lesson-actions">
|
|
121
134
|
<button type="button" class="back" (click)="back()" [disabled]="current === 0 && !prev">Back</button>
|
|
122
135
|
<div class="feedback" role="status">
|
|
123
|
-
@if (title) {
|
|
136
|
+
@if (title) {
|
|
137
|
+
<p class="feedback-title">{{ title }}</p>
|
|
138
|
+
<p class="feedback-text">{{ text }}</p>
|
|
139
|
+
} @else if (total) {
|
|
140
|
+
<p class="feedback-title">Step {{ current + 1 }} of {{ total }}: {{ name }}</p>
|
|
141
|
+
}
|
|
124
142
|
</div>
|
|
125
143
|
<button type="button" class="primary" (click)="forward()">@if (checking) {Check} @else if (total && current === total - 1) {@if (next) {Next lesson} @else {Finish}} @else {Continue}</button>
|
|
126
144
|
</div>
|
package/src/lesson.tscl
CHANGED
|
@@ -19,25 +19,51 @@
|
|
|
19
19
|
@input headings: Heading[] = []
|
|
20
20
|
|
|
21
21
|
<html lang="en">
|
|
22
|
-
<head
|
|
22
|
+
<head>
|
|
23
|
+
<pageHead [config]="config" [title]="title" [description]="description" [url]="path" />
|
|
24
|
+
</head>
|
|
23
25
|
<body class="lesson-page">
|
|
24
26
|
<a class="skip-link" href="#content">Skip to content</a>
|
|
25
27
|
<header class="lesson-header">
|
|
26
28
|
<a class="leave" [href]="lessonOf(config, path).leave" aria-label="Leave the lesson">
|
|
27
|
-
<svg
|
|
29
|
+
<svg
|
|
30
|
+
width="20"
|
|
31
|
+
height="20"
|
|
32
|
+
viewBox="0 0 24 24"
|
|
33
|
+
fill="none"
|
|
34
|
+
stroke="currentColor"
|
|
35
|
+
stroke-width="2.2"
|
|
36
|
+
stroke-linecap="round"
|
|
37
|
+
aria-hidden="true"
|
|
38
|
+
>
|
|
39
|
+
<path d="M6 6l12 12M18 6L6 18"></path>
|
|
40
|
+
</svg>
|
|
28
41
|
</a>
|
|
29
42
|
<div class="lesson-name">
|
|
30
|
-
@if (lessonOf(config, path).total) {
|
|
43
|
+
@if (lessonOf(config, path).total) {
|
|
44
|
+
<p class="eyebrow">{{ lessonOf(config, path).label }}</p>
|
|
45
|
+
}
|
|
31
46
|
<p class="name">{{ title }}</p>
|
|
32
47
|
</div>
|
|
33
48
|
{{-- Links to each step: jumps without JavaScript, the progress bar with it. --}}
|
|
34
49
|
<ol class="segments" aria-label="Steps">
|
|
35
|
-
@for (h of headings.filter((h) => h.level === 2); track h.id) {
|
|
50
|
+
@for (h of headings.filter((h) => h.level === 2); track h.id) {
|
|
51
|
+
<li>
|
|
52
|
+
<a [href]="'#' + h.id">{{ h.text }}</a>
|
|
53
|
+
</li>
|
|
54
|
+
}
|
|
36
55
|
</ol>
|
|
37
56
|
@if (config.learn) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
|
|
38
57
|
<slot name="header-end"></slot>
|
|
39
58
|
</header>
|
|
40
59
|
<main class="lesson" id="content" tabindex="-1"><slot /></main>
|
|
41
|
-
<div class="lesson-bar" role="region" aria-label="Lesson actions" hidden
|
|
60
|
+
<div class="lesson-bar" role="region" aria-label="Lesson actions" hidden>
|
|
61
|
+
<lessonBar
|
|
62
|
+
[lesson]="path"
|
|
63
|
+
[prev]="lessonOf(config, path).prev"
|
|
64
|
+
[next]="lessonOf(config, path).next"
|
|
65
|
+
[leave]="lessonOf(config, path).leave"
|
|
66
|
+
/>
|
|
67
|
+
</div>
|
|
42
68
|
</body>
|
|
43
69
|
</html>
|
package/src/nav.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// The theme's settings and the navigation helpers the layout uses. Server-only: the layout is static HTML.
|
|
1
|
+
// The theme's settings and the navigation helpers the layout uses. Server-only: the layout is static HTML. Lists are
|
|
2
|
+
// readonly, as a template's inputs are: the layout passes its config to these helpers as it gets it.
|
|
2
3
|
|
|
3
4
|
/** A sidebar entry; `order` sorts it within its group (lowest first, then by title). */
|
|
4
5
|
export type Item = { title: string; href: string; order?: number }
|
|
5
|
-
export type Group = { title: string; items: Item[] }
|
|
6
|
+
export type Group = { title: string; items: readonly Item[] }
|
|
6
7
|
/** A top-level part of the docs (Guide, Reference): its own sidebar groups. */
|
|
7
|
-
export type Section = { key: string; title: string; href: string; groups: Group[] }
|
|
8
|
+
export type Section = { key: string; title: string; href: string; groups: readonly Group[] }
|
|
8
9
|
export type Social = { label: string; href: string; icon: 'github' | 'npm' | 'link' }
|
|
9
10
|
/** A heading on the page, for "On this page". */
|
|
10
11
|
export type Heading = { id: string; text: string; level: number }
|
|
@@ -14,16 +15,16 @@ export type ThemeConfig = {
|
|
|
14
15
|
brand: { text: string; accent?: string; logo?: string }
|
|
15
16
|
/** The site's public address, for structured data (no trailing slash). */
|
|
16
17
|
siteUrl?: string
|
|
17
|
-
sections: Section[]
|
|
18
|
+
sections: readonly Section[]
|
|
18
19
|
/** Icon links at the right of the header (GitHub, npm…). */
|
|
19
|
-
social?: Social[]
|
|
20
|
+
social?: readonly Social[]
|
|
20
21
|
/**
|
|
21
22
|
* "Edit this page": a pattern where `:file` is the page's source file under src/pages (`guide/start.md`, found in
|
|
22
23
|
* `pages`), or a function of the route (the page's source route, for dynamic pages). None without it.
|
|
23
24
|
*/
|
|
24
25
|
editLink?: string | ((path: string) => string)
|
|
25
26
|
/** The pages as themeDocs() reads them: source files for `editLink` patterns, and "Last updated" dates. */
|
|
26
|
-
pages?: PageInfo[]
|
|
27
|
+
pages?: readonly PageInfo[]
|
|
27
28
|
/**
|
|
28
29
|
* Learn: the section whose pages are lessons, and its progress page (not a lesson). Progress, XP and badges are
|
|
29
30
|
* kept in the browser (localStorage); an XP chip shows in lesson headers and on the section's pages.
|
|
@@ -44,24 +45,24 @@ const none: Item = { title: '', href: '' }
|
|
|
44
45
|
const flat = (section: Section) => section.groups.flatMap((g) => g.items)
|
|
45
46
|
|
|
46
47
|
/** The section a page belongs to ('' for pages outside every section, like a home page). */
|
|
47
|
-
export function sectionKey(sections: Section[], path: string): string {
|
|
48
|
+
export function sectionKey(sections: readonly Section[], path: string): string {
|
|
48
49
|
return sections.find((s) => flat(s).some((i) => i.href === path))?.key ?? ''
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/** Sidebar groups for the page's section (none outside the sections). */
|
|
52
|
-
export function groupsOf(sections: Section[], path: string): Group[] {
|
|
53
|
+
export function groupsOf(sections: readonly Section[], path: string): readonly Group[] {
|
|
53
54
|
return sections.find((s) => s.key === sectionKey(sections, path))?.groups ?? []
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/** "Guide › Templates" */
|
|
57
|
-
export function crumb(sections: Section[], path: string): string {
|
|
58
|
+
export function crumb(sections: readonly Section[], path: string): string {
|
|
58
59
|
const section = sections.find((s) => s.key === sectionKey(sections, path))
|
|
59
60
|
const group = section?.groups.find((g) => g.items.some((i) => i.href === path))
|
|
60
61
|
return section && group ? `${section.title} › ${group.title}` : ''
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
/** Previous and next pages in sidebar order; an empty item (href '') when there is none. */
|
|
64
|
-
export function pager(sections: Section[], path: string): { prev: Item; next: Item } {
|
|
65
|
+
export function pager(sections: readonly Section[], path: string): { prev: Item; next: Item } {
|
|
65
66
|
const section = sections.find((s) => s.key === sectionKey(sections, path))
|
|
66
67
|
const items = section ? flat(section) : []
|
|
67
68
|
const i = items.findIndex((item) => item.href === path)
|
|
@@ -79,7 +80,7 @@ export type PageInfo = { href: string; title: string; file: string; group?: stri
|
|
|
79
80
|
* section's title), sorted by `order`, then title. The config wins: its groups come first and its items replace pages
|
|
80
81
|
* with the same href, so it can rename, reorder and add (non-page) entries. An empty section `href` means its first page.
|
|
81
82
|
*/
|
|
82
|
-
export function pagesNav(sections: Section[], pages: PageInfo[]): Section[] {
|
|
83
|
+
export function pagesNav(sections: readonly Section[], pages: readonly PageInfo[]): Section[] {
|
|
83
84
|
return sections.map((section) => {
|
|
84
85
|
const groups = section.groups.map((g) => ({ title: g.title, items: [...g.items] }))
|
|
85
86
|
const listed = new Set(groups.flatMap((g) => g.items.map((i) => i.href)))
|
package/src/page-head.tscl
CHANGED
|
@@ -4,11 +4,22 @@
|
|
|
4
4
|
@input title: string
|
|
5
5
|
@input description: string = ''
|
|
6
6
|
@input url: string = '/'
|
|
7
|
-
|
|
8
7
|
{{-- Runs before the first paint: the saved theme is on <html> before anything shows (no flash). --}}
|
|
9
|
-
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
|
|
9
|
+
<script inline>
|
|
10
|
+
try {
|
|
11
|
+
var t = localStorage.getItem('clarusjs-theme')
|
|
12
|
+
if (t === 'light' || t === 'dark') document.documentElement.setAttribute('data-theme', t)
|
|
13
|
+
} catch (e) {}
|
|
14
|
+
</script>
|
|
15
|
+
<meta charset="utf-8" />
|
|
16
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
17
|
+
@if (description) {
|
|
18
|
+
<meta name="description" content="{{ description }}" />
|
|
19
|
+
}
|
|
13
20
|
<title>{{ title }}</title>
|
|
14
|
-
@if (config.siteUrl) {
|
|
21
|
+
@if (config.siteUrl) {
|
|
22
|
+
<script type="application/ld+json">
|
|
23
|
+
{{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: title, description, url: `${config.siteUrl}${url === '/' ? '' : url}` } }}
|
|
24
|
+
</script>
|
|
25
|
+
}
|
package/src/progress-board.tscl
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
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
|
-
@
|
|
5
|
+
@interface Lesson { title: string; href: string }
|
|
6
|
+
@input lessons: Lesson[]
|
|
6
7
|
|
|
7
8
|
<script>
|
|
8
9
|
import { load, reset, save, stats } from './progress.ts'
|
|
@@ -10,19 +11,27 @@
|
|
|
10
11
|
let done = state(0)
|
|
11
12
|
let accuracy = state('')
|
|
12
13
|
let badges = state([])
|
|
13
|
-
let statuses = state(
|
|
14
|
+
let statuses = state(Object.create(null)) // lesson href → its status
|
|
14
15
|
let mode = state('waiting')
|
|
15
16
|
let confirming = state(false)
|
|
16
17
|
function refresh() {
|
|
17
|
-
const s = stats(
|
|
18
|
+
const s = stats(
|
|
19
|
+
load(),
|
|
20
|
+
lessons.map((l) => l.href),
|
|
21
|
+
)
|
|
18
22
|
xp = s.xp
|
|
19
23
|
done = s.done
|
|
20
|
-
accuracy = s.answered
|
|
24
|
+
accuracy = s.answered
|
|
25
|
+
? Math.round((s.right / s.answered) * 100) + '% (' + s.right + ' of ' + s.answered + ')'
|
|
26
|
+
: 'no quizzes answered yet'
|
|
21
27
|
badges = s.badges
|
|
22
28
|
statuses = Object.fromEntries(lessons.map((l) => [l.href, s.status(l.href)]))
|
|
23
29
|
}
|
|
24
30
|
function wipe() {
|
|
25
|
-
if (!confirming) {
|
|
31
|
+
if (!confirming) {
|
|
32
|
+
confirming = true
|
|
33
|
+
return
|
|
34
|
+
}
|
|
26
35
|
reset()
|
|
27
36
|
confirming = false
|
|
28
37
|
refresh()
|
|
@@ -39,26 +48,47 @@
|
|
|
39
48
|
@if (mode === 'waiting') {
|
|
40
49
|
<p class="progress-note">Your progress is kept in this browser and shows here with JavaScript on.</p>
|
|
41
50
|
} @else {
|
|
42
|
-
@if (mode === 'blocked') {
|
|
51
|
+
@if (mode === 'blocked') {
|
|
52
|
+
<p class="progress-note">
|
|
53
|
+
This browser isn't keeping your progress (storage is blocked), so it lasts until you leave the page.
|
|
54
|
+
</p>
|
|
55
|
+
}
|
|
43
56
|
<dl class="progress-stats">
|
|
44
|
-
<div
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
<div>
|
|
58
|
+
<dt>XP</dt>
|
|
59
|
+
<dd>{{ xp }}</dd>
|
|
60
|
+
</div>
|
|
61
|
+
<div>
|
|
62
|
+
<dt>Lessons</dt>
|
|
63
|
+
<dd>{{ done }} of {{ lessons.length }}</dd>
|
|
64
|
+
</div>
|
|
65
|
+
<div>
|
|
66
|
+
<dt>Quizzes right</dt>
|
|
67
|
+
<dd>{{ accuracy }}</dd>
|
|
68
|
+
</div>
|
|
47
69
|
</dl>
|
|
48
70
|
<h2>Badges</h2>
|
|
49
71
|
<ul class="badges">
|
|
50
72
|
@for (badge of badges; track badge.id) {
|
|
51
|
-
<li [class]="badge.earned ? 'earned' : false"
|
|
73
|
+
<li [class]="badge.earned ? 'earned' : false">
|
|
74
|
+
<strong>{{ badge.title }}</strong> <span>{{ badge.text }}</span>
|
|
75
|
+
<em>{{ badge.earned ? 'Earned' : 'Not yet' }}</em>
|
|
76
|
+
</li>
|
|
52
77
|
}
|
|
53
78
|
</ul>
|
|
54
79
|
}
|
|
55
80
|
<h2>Lessons</h2>
|
|
56
81
|
<ol class="progress-lessons">
|
|
57
82
|
@for (lesson of lessons; track lesson.href) {
|
|
58
|
-
<li [data-status]="statuses[lesson.href] ?? false"
|
|
83
|
+
<li [data-status]="statuses[lesson.href] ?? false">
|
|
84
|
+
<a [href]="lesson.href">{{ lesson.title }}</a
|
|
85
|
+
>@if (statuses[lesson.href]) { <span class="status-note">({{ statuses[lesson.href] === 'current' ? 'up next' : statuses[lesson.href] === 'done' ? 'done' : 'not started' }})</span>}
|
|
86
|
+
</li>
|
|
59
87
|
}
|
|
60
88
|
</ol>
|
|
61
89
|
@if (mode !== 'waiting') {
|
|
62
|
-
<button type="button" class="progress-reset" (click)="wipe()">
|
|
90
|
+
<button type="button" class="progress-reset" (click)="wipe()">
|
|
91
|
+
{{ confirming ? 'Click again to erase your progress' : 'Reset progress' }}
|
|
92
|
+
</button>
|
|
63
93
|
}
|
|
64
94
|
</div>
|
package/src/progress.ts
CHANGED
|
@@ -69,7 +69,7 @@ export type Stats = {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/** XP (10 a step, 50 a lesson, 20 a quiz right the first time), counts and badges, for the lessons of a path. */
|
|
72
|
-
export function stats(p: Progress, lessons: string[]): Stats {
|
|
72
|
+
export function stats(p: Progress, lessons: readonly string[]): Stats {
|
|
73
73
|
const done = lessons.filter((l) => p.done.includes(l)).length
|
|
74
74
|
const steps = lessons.reduce((n, l) => n + (p.steps[l]?.length ?? 0), 0)
|
|
75
75
|
const answers = Object.values(p.quizzes)
|
package/src/quiz-choices.tscl
CHANGED
|
@@ -24,19 +24,24 @@
|
|
|
24
24
|
detail = { ok, done: true, text: ok ? 'Correct.' : 'The answer is: ' + options[answer] + '.' }
|
|
25
25
|
quiz()?.setAttribute('data-answered', ok ? 'right' : 'wrong')
|
|
26
26
|
const details = quiz()?.querySelector('.quiz-answer')
|
|
27
|
-
if (details) details.open = true
|
|
27
|
+
if (details instanceof HTMLDetailsElement) details.open = true
|
|
28
28
|
}
|
|
29
29
|
quiz()?.dispatchEvent(new CustomEvent('quiz:result', { bubbles: true, detail }))
|
|
30
30
|
}
|
|
31
31
|
if (typeof document !== 'undefined') {
|
|
32
|
-
document.addEventListener('quiz:check', (event) => {
|
|
32
|
+
document.addEventListener('quiz:check', (event) => {
|
|
33
|
+
if (event.target === quiz() && !checked) check()
|
|
34
|
+
})
|
|
33
35
|
}
|
|
34
36
|
</script>
|
|
35
37
|
|
|
36
38
|
<div class="quiz-choices">
|
|
37
39
|
<div class="quiz-options" role="radiogroup" [aria-labelledby]="name + '-q'">
|
|
38
40
|
@for (option of options; track $index) {
|
|
39
|
-
<label [class]="!checked ? false : $index === answer ? 'right' : $index === picked ? 'wrong' : false"
|
|
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
|
|
44
|
+
>
|
|
40
45
|
}
|
|
41
46
|
</div>
|
|
42
47
|
<button type="button" class="quiz-check" (click)="check()" [disabled]="checked">Check</button>
|
package/src/quiz.tscl
CHANGED
|
@@ -12,5 +12,9 @@
|
|
|
12
12
|
<div class="quiz" [data-quiz]="name">
|
|
13
13
|
<p class="quiz-question" [id]="name + '-q'">{{ question }}</p>
|
|
14
14
|
<quizChoices [name]="name" [options]="options" [answer]="answer" />
|
|
15
|
-
<details class="quiz-answer"
|
|
15
|
+
<details class="quiz-answer">
|
|
16
|
+
<summary>Show the answer</summary>
|
|
17
|
+
<p class="quiz-correct">Answer: {{ options[answer] }}</p>
|
|
18
|
+
<slot />
|
|
19
|
+
</details>
|
|
16
20
|
</div>
|
package/src/search.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export type Section = {
|
|
|
10
10
|
*/
|
|
11
11
|
/** Sections per `s-<n>.json` file. */
|
|
12
12
|
export declare const CHUNK = 64;
|
|
13
|
+
/** The site's base path ('/' unless Vite's `base` is set), where the search index is fetched from. */
|
|
14
|
+
/** @type {string} */
|
|
15
|
+
export declare const base: string;
|
|
13
16
|
/** @param {string} text @returns {string[]} lowercase words of two or more letters, accents folded */
|
|
14
17
|
export declare function tokens(text: string): string[];
|
|
15
18
|
/** @param {string} word */
|
package/src/search.js
CHANGED
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
/** Sections per `s-<n>.json` file. */
|
|
14
14
|
export const CHUNK = 64
|
|
15
15
|
|
|
16
|
+
/** The site's base path ('/' unless Vite's `base` is set), where the search index is fetched from. */
|
|
17
|
+
/** @type {string} */
|
|
18
|
+
export const base = /** @type {any} */ (import.meta).env?.BASE_URL ?? '/' // Vite's import.meta.env, when there is one
|
|
19
|
+
|
|
16
20
|
/** @param {string} text @returns {string[]} lowercase words of two or more letters, accents folded */
|
|
17
21
|
export function tokens(text) {
|
|
18
22
|
return (text.normalize('NFKD').replace(/[̀-ͯ]/g, '').toLowerCase().match(/[a-z0-9]+/g) ?? []).filter((w) => w.length > 1)
|
package/src/search.tscl
CHANGED
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
Escape closes it and focus goes back. Arrow keys move through the results, Enter opens one. The index is the one
|
|
4
4
|
themeDocs() writes at build time; a query fetches only the files it needs.
|
|
5
5
|
--}}
|
|
6
|
+
|
|
6
7
|
<script>
|
|
7
8
|
import { navigate } from 'clarusjs/navigation'
|
|
8
|
-
import { search } from './search.js'
|
|
9
|
+
import { base, search } from './search.js'
|
|
9
10
|
let query = state('')
|
|
10
11
|
let results = state([])
|
|
11
12
|
let active = state(0)
|
|
12
13
|
let searched = state(false)
|
|
13
|
-
const status = derived(() =>
|
|
14
|
-
|
|
14
|
+
const status = derived(() =>
|
|
15
|
+
!searched
|
|
16
|
+
? ''
|
|
17
|
+
: results.length === 0
|
|
18
|
+
? 'No results for "' + query + '"'
|
|
19
|
+
: results.length === 1
|
|
20
|
+
? '1 result'
|
|
21
|
+
: results.length + ' results',
|
|
22
|
+
)
|
|
15
23
|
const load = (file) => fetch(base + 'search/' + file).then((r) => (r.ok ? r.json() : {}))
|
|
16
24
|
let latest = 0
|
|
17
25
|
async function run(value) {
|
|
@@ -23,12 +31,15 @@
|
|
|
23
31
|
active = 0
|
|
24
32
|
searched = value.trim() !== ''
|
|
25
33
|
}
|
|
26
|
-
const dialog = () =>
|
|
34
|
+
const dialog = () => {
|
|
35
|
+
const d = document.querySelector('.search-dialog')
|
|
36
|
+
return d instanceof HTMLDialogElement ? d : null
|
|
37
|
+
}
|
|
27
38
|
function open() {
|
|
28
39
|
const d = dialog()
|
|
29
40
|
if (!d || d.open) return
|
|
30
41
|
d.showModal()
|
|
31
|
-
d.querySelector('input')
|
|
42
|
+
d.querySelector('input')?.select()
|
|
32
43
|
}
|
|
33
44
|
function move(by) {
|
|
34
45
|
if (!results.length) return
|
|
@@ -36,15 +47,27 @@
|
|
|
36
47
|
document.getElementById('search-result-' + active)?.scrollIntoView({ block: 'nearest' })
|
|
37
48
|
}
|
|
38
49
|
function key(event) {
|
|
39
|
-
if (event.key === 'ArrowDown') {
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
if (event.key === 'ArrowDown') {
|
|
51
|
+
event.preventDefault()
|
|
52
|
+
move(1)
|
|
53
|
+
} else if (event.key === 'ArrowUp') {
|
|
54
|
+
event.preventDefault()
|
|
55
|
+
move(-1)
|
|
56
|
+
} else if (event.key === 'Enter' && results.length) {
|
|
57
|
+
event.preventDefault()
|
|
58
|
+
dialog()?.close()
|
|
59
|
+
navigate(results[active].u)
|
|
60
|
+
}
|
|
42
61
|
// One Escape closes (a search field would only clear itself first).
|
|
43
|
-
else if (event.key === 'Escape') {
|
|
62
|
+
else if (event.key === 'Escape') {
|
|
63
|
+
event.preventDefault()
|
|
64
|
+
dialog()?.close()
|
|
65
|
+
}
|
|
44
66
|
}
|
|
45
67
|
if (typeof document !== 'undefined') {
|
|
46
68
|
document.addEventListener('keydown', (event) => {
|
|
47
|
-
const typing =
|
|
69
|
+
const typing =
|
|
70
|
+
event.target instanceof Element && event.target.closest('input, textarea, select, [contenteditable]')
|
|
48
71
|
if ((event.key === 'k' && (event.metaKey || event.ctrlKey)) || (event.key === '/' && !typing)) {
|
|
49
72
|
event.preventDefault()
|
|
50
73
|
open()
|
|
@@ -55,19 +78,51 @@
|
|
|
55
78
|
|
|
56
79
|
<div class="search">
|
|
57
80
|
<button type="button" class="search-button" aria-haspopup="dialog" (click)="open()">
|
|
58
|
-
<svg
|
|
81
|
+
<svg
|
|
82
|
+
width="16"
|
|
83
|
+
height="16"
|
|
84
|
+
viewBox="0 0 24 24"
|
|
85
|
+
fill="none"
|
|
86
|
+
stroke="currentColor"
|
|
87
|
+
stroke-width="2"
|
|
88
|
+
stroke-linecap="round"
|
|
89
|
+
aria-hidden="true"
|
|
90
|
+
>
|
|
91
|
+
<circle cx="11" cy="11" r="7"></circle>
|
|
92
|
+
<path d="M20 20l-3.5-3.5"></path>
|
|
93
|
+
</svg>
|
|
59
94
|
<span class="search-label">Search</span>
|
|
60
95
|
<kbd aria-hidden="true">⌘K</kbd>
|
|
61
96
|
</button>
|
|
62
97
|
{{-- A click on the backdrop (the dialog itself, outside its box) closes it; so does choosing a result. --}}
|
|
63
|
-
<dialog
|
|
98
|
+
<dialog
|
|
99
|
+
class="search-dialog"
|
|
100
|
+
aria-label="Search the docs"
|
|
101
|
+
(click)="($event.target.matches('dialog') || $event.target.closest('a')) && dialog()?.close()"
|
|
102
|
+
>
|
|
64
103
|
<div class="search-box">
|
|
65
|
-
<input
|
|
104
|
+
<input
|
|
105
|
+
type="search"
|
|
106
|
+
role="combobox"
|
|
107
|
+
aria-label="Search the docs"
|
|
108
|
+
aria-controls="search-results"
|
|
109
|
+
aria-autocomplete="list"
|
|
110
|
+
[aria-expanded]="results.length ? 'true' : 'false'"
|
|
111
|
+
[aria-activedescendant]="results.length ? 'search-result-' + active : false"
|
|
112
|
+
placeholder="Search the docs"
|
|
113
|
+
autocomplete="off"
|
|
114
|
+
spellcheck="false"
|
|
115
|
+
(input)="run($event.target.value)"
|
|
116
|
+
(keydown)="key($event)"
|
|
117
|
+
/>
|
|
66
118
|
<p class="search-status" role="status">{{ status }}</p>
|
|
67
119
|
<ul id="search-results" role="listbox" aria-label="Results">
|
|
68
120
|
@for (r of results; track r.u) {
|
|
69
121
|
<li [id]="'search-result-' + $index" role="option" [aria-selected]="$index === active ? 'true' : 'false'">
|
|
70
|
-
<a [href]="r.u" tabindex="-1"
|
|
122
|
+
<a [href]="r.u" tabindex="-1"
|
|
123
|
+
><span class="search-heading">{{ r.h }}</span
|
|
124
|
+
>@if (r.h !== r.p) {<span class="search-page">{{ r.p }}</span>}<span class="search-text">{{ r.t }}</span></a
|
|
125
|
+
>
|
|
71
126
|
</li>
|
|
72
127
|
}
|
|
73
128
|
</ul>
|
package/src/theme-toggle.tscl
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{{-- Light, dark or the system setting; remembered in localStorage and applied as data-theme on <html>. --}}
|
|
2
|
+
|
|
2
3
|
<script>
|
|
3
4
|
const order = ['system', 'light', 'dark']
|
|
4
5
|
let mode = state('system')
|
|
@@ -8,16 +9,26 @@
|
|
|
8
9
|
}
|
|
9
10
|
function cycle() {
|
|
10
11
|
mode = order[(order.indexOf(mode) + 1) % order.length]
|
|
11
|
-
try {
|
|
12
|
+
try {
|
|
13
|
+
localStorage.setItem('clarusjs-theme', mode)
|
|
14
|
+
} catch {}
|
|
12
15
|
apply()
|
|
13
16
|
}
|
|
14
17
|
// In the browser, start from the saved choice (the server always renders "system").
|
|
15
18
|
if (typeof document !== 'undefined') {
|
|
16
|
-
try {
|
|
19
|
+
try {
|
|
20
|
+
mode = localStorage.getItem('clarusjs-theme') || 'system'
|
|
21
|
+
} catch {}
|
|
17
22
|
apply()
|
|
18
23
|
}
|
|
19
24
|
</script>
|
|
20
25
|
|
|
21
|
-
<button
|
|
26
|
+
<button
|
|
27
|
+
type="button"
|
|
28
|
+
class="theme-toggle"
|
|
29
|
+
(click)="cycle()"
|
|
30
|
+
[aria-label]="'Theme: ' + mode + ' (change)'"
|
|
31
|
+
[title]="'Theme: ' + mode"
|
|
32
|
+
>
|
|
22
33
|
@if (mode === 'dark') {☾} @else if (mode === 'light') {☀} @else {◐}
|
|
23
34
|
</button>
|