@clarusjs/theme-docs 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Felix Orinda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,25 @@
1
1
  # @clarusjs/theme-docs
2
2
 
3
- Name reserved. clarusjs is in early development and not ready for use yet. See https://clarusjs.com.
3
+ A docs theme for [clarusjs](https://clarusjs.com). It gives every page:
4
+ - a **header**: brand, section links, social icons, a ⋯ overflow menu and a theme toggle;
5
+ - a **sidebar**, listed in `config` or generated from `src/pages` (`themeDocs()` Vite plugin + `pagesNav`): a drawer on small screens, with no JavaScript;
6
+ - the **content**, with a crumb, an edit link and previous/next links;
7
+ - **On this page**: a column on wide screens, a collapsible box on narrow ones.
8
+
9
+ It also has search (a build-time index split into small files, and a Ctrl/⌘K dialog), light and dark modes without a flash, copy buttons and callouts.
10
+
11
+ ```sh
12
+ pnpm add -D @clarusjs/theme-docs
13
+ ```
14
+
15
+ ```tscl
16
+ {{-- src/layouts/docs.tscl --}}
17
+ @import theme from '@clarusjs/theme-docs/layout.tscl'
18
+ @import { config } from '../theme.config.ts'
19
+ @input title: string
20
+ @input path: string = '/'
21
+
22
+ <theme [config]="config" [title]="title" [path]="path"><slot /></theme>
23
+ ```
24
+
25
+ Customize through `config`, slots (`sidebar-top`, `sidebar-bottom`, `content-top`, `content-bottom`, `footer`) and CSS custom properties. See the [docs theme guide](https://clarusjs.com/guide/docs-theme).
package/package.json CHANGED
@@ -1,8 +1,52 @@
1
1
  {
2
2
  "name": "@clarusjs/theme-docs",
3
- "version": "0.0.1",
4
- "description": "Docs theme for clarusjs (name reserved; early development).",
3
+ "version": "0.1.0",
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
+ "type": "module",
5
6
  "license": "MIT",
6
- "repository": { "type": "git", "url": "git+https://github.com/forinda/clarusjs.git", "directory": "packages/theme-docs" },
7
- "homepage": "https://clarusjs.com"
8
- }
7
+ "files": [
8
+ "src",
9
+ "LICENSE",
10
+ "README.md"
11
+ ],
12
+ "exports": {
13
+ "./*": "./src/*"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "peerDependencies": {
19
+ "clarusjs": "^0.8.0"
20
+ },
21
+ "engines": {
22
+ "node": "^22.12.0 || ^24.0.0 || >=26.0.0"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/forinda/clarusjs.git",
27
+ "directory": "packages/theme-docs"
28
+ },
29
+ "keywords": [
30
+ "clarusjs",
31
+ "theme",
32
+ "docs",
33
+ "ssg",
34
+ "vite"
35
+ ],
36
+ "homepage": "https://clarusjs.com",
37
+ "bugs": {
38
+ "url": "https://github.com/forinda/clarusjs/issues"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^26.6.6",
42
+ "clarusjs": "^0.8.0",
43
+ "typescript": "^7.0.2",
44
+ "vitest": "^5.1.1",
45
+ "vite": "^8.3.8"
46
+ },
47
+ "scripts": {
48
+ "types": "node scripts/types.mjs",
49
+ "test": "vitest run",
50
+ "typecheck": "pnpm types && tsc --noEmit"
51
+ }
52
+ }
@@ -0,0 +1,19 @@
1
+ @input type: 'tip' | 'info' | 'warning' | 'danger' = 'info'
2
+
3
+ <aside role="note" class="callout {{ type }}"><p class="callout-title"><slot name="title">{{ type[0].toUpperCase() + type.slice(1) }}</slot></p><slot /></aside>
4
+
5
+ <style>
6
+ /* Scoped to this component: :scope is the <aside>; slot content inside it is styled too. */
7
+ :scope {
8
+ border-left: 3px solid var(--accent);
9
+ background: var(--accent-soft);
10
+ padding: 12px 16px;
11
+ border-radius: 0 8px 8px 0;
12
+ margin: 24px 0;
13
+ }
14
+ :scope.tip { border-left-color: #2f9e6e; }
15
+ :scope.warning { border-left-color: #c98a12; }
16
+ :scope.danger { border-left-color: #d0453b; }
17
+ .callout-title { margin: 0 0 4px; font-weight: 650; }
18
+ p:last-child { margin-bottom: 0; }
19
+ </style>
package/src/copy.tscl ADDED
@@ -0,0 +1,21 @@
1
+ {{-- A copy button for the code it sits next to: a .sample wrapper, or a highlighted .code-block from Markdown. --}}
2
+ <script>
3
+ let copied = state(false)
4
+ async function copy(button) {
5
+ const block = button.closest('.sample, .code-block')?.querySelector('code')
6
+ // Removed diff lines aren't part of the code to copy.
7
+ const clone = block?.cloneNode(true)
8
+ clone?.querySelectorAll('.diff.remove').forEach((line) => {
9
+ if (line.nextSibling?.nodeType === 3 && line.nextSibling.textContent === '\n') line.nextSibling.remove() // its newline too
10
+ line.remove()
11
+ })
12
+ const code = clone?.textContent ?? ''
13
+ try {
14
+ await navigator.clipboard.writeText(code)
15
+ copied = true
16
+ setTimeout(() => { copied = false }, 1500)
17
+ } catch {}
18
+ }
19
+ </script>
20
+
21
+ <button type="button" class="copy" (click)="copy($event.currentTarget ?? $event.target)">@if (copied) {Copied} @else {Copy}</button>
@@ -0,0 +1,122 @@
1
+ {{--
2
+ The docs layout. Four regions at every width (header, sidebar, content, on this page); only how they show changes:
3
+ below 1024px the sidebar is a drawer (native popover: no JavaScript) and "On this page" a collapsible box, from
4
+ 1024px the sidebar is always there, from 1280px "On this page" is a column. Everything site-specific comes from config.
5
+ Slots: sidebar-top, sidebar-bottom, content-top, content-bottom, footer.
6
+ --}}
7
+ @import themeToggle from './theme-toggle.tscl'
8
+ @import siteSearch from './search.tscl'
9
+ @import pageHead from './page-head.tscl'
10
+ @import learnStatus from './learn-status.tscl'
11
+ @import type { ThemeConfig, Heading } from './nav.ts'
12
+ @import { sectionKey, groupsOf, crumb, pager, editHref, updatedOf, lessonsOf } from './nav.ts'
13
+ @import './theme.css'
14
+ @input config: ThemeConfig
15
+ @input title: string
16
+ @input description: string = ''
17
+ @input path: string = '/'
18
+ {{-- The page's own route, when it differs from the sidebar entry it belongs to (e.g. /releases/[version]). --}}
19
+ @input source: string = ''
20
+ {{-- The page's own address, when path names its sidebar entry instead (e.g. /releases/0.7.0 under /releases). --}}
21
+ @input url: string = ''
22
+ {{-- The page's h2/h3 for "On this page" (Markdown pages pass them; none: the region is left out). --}}
23
+ @input headings: Heading[] = []
24
+
25
+ <html lang="en">
26
+ <head><pageHead [config]="config" [title]="title" [description]="description" [url]="url || path" /></head>
27
+ <body>
28
+ {{-- First in the tab order: keyboard and screen reader users jump past the header and page list. --}}
29
+ <a class="skip-link" href="#content">Skip to content</a>
30
+ <header class="site-header">
31
+ @if (sectionKey(config.sections, path)) {
32
+ <button type="button" class="menu-button" popovertarget="sidebar" aria-label="Open menu">
33
+ <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"></path></svg>
34
+ </button>
35
+ }
36
+ <a class="brand" href="/">@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>
37
+ <nav class="top-nav" aria-label="Main">
38
+ @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>}
39
+ </nav>
40
+ <div class="header-end">
41
+ {{-- On Learn pages: the XP chip, and the sidebar's lessons marked done, current or locked. --}}
42
+ @if (config.learn && sectionKey(config.sections, path) === config.learn.section) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
43
+ {{-- Kept across fragment navigations, like the theme toggle: its shortcut listener is added once. --}}
44
+ @if (config.search) {<span class="persist" data-cl-persist="search"><siteSearch /></span>}
45
+ @if ((config.social ?? []).length) {
46
+ <span class="social">
47
+ @for (link of config.social ?? []; track link.href) {
48
+ <a [href]="link.href" [aria-label]="link.label" [title]="link.label">
49
+ @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>}
50
+ </a>
51
+ }
52
+ </span>
53
+ {{-- When the header runs out of room, the social links fold into this menu (native popover). --}}
54
+ <button type="button" class="more-button" popovertarget="more" aria-label="More links">
55
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="5" cy="12" r="2"></circle><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle></svg>
56
+ </button>
57
+ <div id="more" class="more" popover>
58
+ @for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}
59
+ </div>
60
+ }
61
+ {{-- Kept across fragment navigations: the same element, with its state. --}}
62
+ <span class="persist" data-cl-persist="theme"><themeToggle /></span>
63
+ </div>
64
+ </header>
65
+ @if (sectionKey(config.sections, path)) {
66
+ <div class="docs">
67
+ {{-- A drawer below 1024px (popover: Escape and a click outside close it), always visible from 1024px. --}}
68
+ <nav id="sidebar" class="sidebar" aria-label="Pages" popover>
69
+ <div class="sidebar-head">
70
+ <span>{{ config.brand.text }}{{ config.brand.accent ?? '' }}</span>
71
+ <button type="button" popovertarget="sidebar" popovertargetaction="hide" aria-label="Close the menu">
72
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"></path></svg>
73
+ </button>
74
+ </div>
75
+ <slot name="sidebar-top"></slot>
76
+ @for (group of groupsOf(config.sections, path); track group.title) {
77
+ <p class="group">{{ group.title }}</p>
78
+ <ul>
79
+ @for (item of group.items; track item.href) {<li><a [href]="item.href" [aria-current]="item.href === path ? 'page' : false">{{ item.title }}</a></li>}
80
+ </ul>
81
+ }
82
+ <slot name="sidebar-bottom"></slot>
83
+ {{-- On phones, the header's links live here. --}}
84
+ <div class="sidebar-links">
85
+ @for (s of config.sections; track s.key) {<a [href]="s.href">{{ s.title }}</a>}
86
+ @for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}
87
+ </div>
88
+ </nav>
89
+ {{-- tabindex -1: the skip link (and navigation) can move focus here. --}}
90
+ <main class="content" id="content" tabindex="-1">
91
+ <p class="crumb">{{ crumb(config.sections, path) }}</p>
92
+ @if (headings.length) {
93
+ <details class="toc-inline">
94
+ <summary>On this page</summary>
95
+ <ul>@for (h of headings; track h.id) {<li [class]="h.level === 3 ? 'sub' : false"><a [href]="'#' + h.id">{{ h.text }}</a></li>}</ul>
96
+ </details>
97
+ }
98
+ <slot name="content-top"></slot>
99
+ <slot />
100
+ <slot name="content-bottom"></slot>
101
+ <footer class="page-footer">
102
+ @if (editHref(config, source || path)) {<a class="edit" [href]="editHref(config, source || path)">Edit this page on GitHub</a>}
103
+ @if (updatedOf(config, source || path)) {<p class="updated">Last updated <time [datetime]="updatedOf(config, source || path)?.iso">{{ updatedOf(config, source || path)?.text }}</time></p>}
104
+ <nav class="pager" aria-label="Previous and next">
105
+ @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>}
106
+ @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>}
107
+ </nav>
108
+ </footer>
109
+ </main>
110
+ @if (headings.length) {
111
+ <aside class="toc" aria-label="On this page">
112
+ <p>On this page</p>
113
+ <ul>@for (h of headings; track h.id) {<li [class]="h.level === 3 ? 'sub' : false"><a [href]="'#' + h.id">{{ h.text }}</a></li>}</ul>
114
+ </aside>
115
+ }
116
+ </div>
117
+ } @else {
118
+ <main class="content home" id="content" tabindex="-1"><slot /></main>
119
+ }
120
+ <footer class="site-footer"><slot name="footer">@if (config.footer) {<p>{{ config.footer }}</p>}</slot></footer>
121
+ </body>
122
+ </html>
@@ -0,0 +1,7 @@
1
+ {{-- The progress page's board (put it on the page at config.learn.progress): XP, lessons, quiz accuracy, badges, Reset. --}}
2
+ @import progressBoard from './progress-board.tscl'
3
+ @import type { ThemeConfig } from './nav.ts'
4
+ @import { lessonsOf } from './nav.ts'
5
+ @input config: ThemeConfig
6
+
7
+ <progressBoard [lessons]="lessonsOf(config)" />
@@ -0,0 +1,40 @@
1
+ {{--
2
+ Learning status, from the progress kept in this browser: an XP chip (a link to the progress page), and on pages with
3
+ the Learn sidebar each lesson marked done, current or locked (a hint: every lesson stays open). Hidden until it has
4
+ read the progress, so pages without JavaScript show no "0 XP". Updates when the lesson bar saves (learn:progress).
5
+ --}}
6
+ @input lessons: string[]
7
+ @input progress: string
8
+
9
+ <script>
10
+ import { load, stats } from './progress.ts'
11
+ let xp = state(0)
12
+ let ready = state(false)
13
+ const words = { done: 'done', current: 'up next', locked: 'not started' }
14
+ function refresh() {
15
+ const s = stats(load(), lessons)
16
+ xp = s.xp
17
+ ready = true
18
+ for (const link of document.querySelectorAll('.sidebar ul a[href]')) {
19
+ if (!lessons.includes(link.getAttribute('href'))) continue
20
+ const status = s.status(link.getAttribute('href'))
21
+ link.dataset.status = status
22
+ let note = link.querySelector('.status-note')
23
+ if (!note) {
24
+ note = document.createElement('span')
25
+ note.className = 'status-note'
26
+ link.append(note)
27
+ }
28
+ note.textContent = ' (' + words[status] + ')'
29
+ }
30
+ }
31
+ if (typeof document !== 'undefined') {
32
+ refresh()
33
+ window.addEventListener('learn:progress', refresh)
34
+ }
35
+ </script>
36
+
37
+ <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"><path d="M13 2L4 14h7l-1 8 9-12h-7z"></path></svg>
39
+ {{ xp }} XP
40
+ </a>
@@ -0,0 +1,126 @@
1
+ {{--
2
+ The lesson's action bar: Back, what step this is, Continue. It shows one step (<section class="step">) at a time,
3
+ follows the URL's #step (the header's segments link there), and after the last step goes to the next lesson.
4
+ It reveals itself (and the one-step view) when it attaches: without JavaScript the lesson is a plain page.
5
+ --}}
6
+ @input lesson: string = ''
7
+ @input prev: string = ''
8
+ @input next: string = ''
9
+ @input leave: string = '/'
10
+
11
+ <script>
12
+ import { answer, finish, load, save, step } from './progress.ts'
13
+ // Progress lives in this browser; the XP chip and the progress page listen for learn:progress.
14
+ function record(update) {
15
+ save(update(load()))
16
+ window.dispatchEvent(new Event('learn:progress'))
17
+ }
18
+ let current = state(0)
19
+ let total = state(0)
20
+ let name = state('')
21
+ // On a step with an unanswered quiz the main button is Check; the quiz's answer shows here, green or red.
22
+ let checking = state(false)
23
+ let result = state('')
24
+ let title = state('')
25
+ let text = state('')
26
+ const bar = () => document.querySelector('.lesson-bar')
27
+ function verdict(kind, heading, detail) {
28
+ result = kind
29
+ title = heading
30
+ text = detail
31
+ bar()?.classList.toggle('ok', kind === 'ok')
32
+ bar()?.classList.toggle('bad', kind === 'bad')
33
+ }
34
+ const steps = () => [...document.querySelectorAll('main .step')]
35
+ function show(i, focus) {
36
+ const all = steps()
37
+ if (!all.length) return
38
+ current = Math.max(0, Math.min(i, all.length - 1))
39
+ total = all.length
40
+ all.forEach((step, j) => { step.hidden = j !== current })
41
+ checking = !!all[current].querySelector('[data-quiz]:not([data-answered])')
42
+ verdict('', '', '')
43
+ const id = all[current].getAttribute('aria-labelledby')
44
+ name = document.getElementById(id)?.textContent?.replace(/#$/, '').trim() ?? ''
45
+ document.querySelectorAll('.segments li').forEach((li, j) => {
46
+ li.className = j < current ? 'done' : j === current ? 'current' : ''
47
+ const link = li.querySelector('a')
48
+ if (j === current) link?.setAttribute('aria-current', 'step')
49
+ else link?.removeAttribute('aria-current')
50
+ })
51
+ if (focus) {
52
+ history.replaceState(null, '', '#' + id)
53
+ document.getElementById(id)?.focus()
54
+ window.scrollTo({ top: 0 })
55
+ }
56
+ }
57
+ // The step a #hash points into: its own heading, or anything inside it.
58
+ const indexOf = (hash) => {
59
+ const id = decodeURIComponent(hash.slice(1))
60
+ return id ? steps().findIndex((s) => s.getAttribute('aria-labelledby') === id || s.querySelector('#' + CSS.escape(id))) : -1
61
+ }
62
+ function back() {
63
+ if (current > 0) show(current - 1, true)
64
+ else if (prev) location.href = prev
65
+ }
66
+ function forward() {
67
+ if (checking) {
68
+ steps()[current]?.querySelector('[data-quiz]:not([data-answered])')?.dispatchEvent(new CustomEvent('quiz:check', { bubbles: true }))
69
+ return
70
+ }
71
+ const id = steps()[current]?.getAttribute('aria-labelledby')
72
+ if (current < total - 1) {
73
+ if (id) record((p) => step(p, lesson, id))
74
+ show(current + 1, true)
75
+ } else {
76
+ record((p) => finish(id ? step(p, lesson, id) : p, lesson))
77
+ location.href = next || leave
78
+ }
79
+ }
80
+ // Each step's code and results (code blocks, .result) go in a side column, its text in the main one.
81
+ function split(step) {
82
+ const side = [...step.children].filter((el) => el.matches('.code-block, .sample, pre, .result'))
83
+ if (!side.length || step.classList.contains('split')) return
84
+ const text = document.createElement('div')
85
+ text.className = 'step-text'
86
+ const aside = document.createElement('div')
87
+ aside.className = 'step-side'
88
+ for (const el of [...step.children]) (side.includes(el) ? aside : text).append(el)
89
+ step.append(text, aside)
90
+ step.classList.add('split')
91
+ }
92
+ if (typeof document !== 'undefined' && steps().length) {
93
+ steps().forEach(split)
94
+ document.body.classList.add('one-step')
95
+ document.querySelector('.lesson-bar').hidden = false
96
+ // A #hash opens the step it points into and keeps its target: a step heading takes focus, anything else
97
+ // scrolls into view (Back and Continue go by step headings instead).
98
+ function reveal() {
99
+ const i = indexOf(location.hash)
100
+ if (i === -1) return false
101
+ show(i, false)
102
+ const target = document.getElementById(decodeURIComponent(location.hash.slice(1)))
103
+ if (target?.matches('.step > h2, .step-text > h2')) target.focus()
104
+ target?.scrollIntoView()
105
+ return true
106
+ }
107
+ if (!reveal()) show(0, false)
108
+ document.addEventListener('quiz:result', (event) => {
109
+ if (!steps()[current]?.contains(event.target)) return
110
+ const { ok, done, text: detail } = event.detail
111
+ if (!done) return verdict('', 'Pick an answer', detail)
112
+ record((p) => answer(p, lesson + '#' + event.target.dataset.quiz, ok))
113
+ checking = !!steps()[current].querySelector('[data-quiz]:not([data-answered])')
114
+ verdict(ok ? 'ok' : 'bad', ok ? 'Correct!' : 'Not quite', detail)
115
+ })
116
+ window.addEventListener('hashchange', reveal)
117
+ }
118
+ </script>
119
+
120
+ <div class="lesson-actions">
121
+ <button type="button" class="back" (click)="back()" [disabled]="current === 0 && !prev">Back</button>
122
+ <div class="feedback" role="status">
123
+ @if (title) {<p class="feedback-title">{{ title }}</p><p class="feedback-text">{{ text }}</p>} @else if (total) {<p class="feedback-title">Step {{ current + 1 }} of {{ total }}: {{ name }}</p>}
124
+ </div>
125
+ <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
+ </div>
package/src/lesson.css ADDED
@@ -0,0 +1,72 @@
1
+ /* Lessons: a focused header, the lesson (from 1024px instructions left, code and result right), a fixed action bar. */
2
+ .lesson-page { --bar-height: 76px; }
3
+ /* In a lesson, the bar checks quizzes and says how it went: their own button and announcement step aside. */
4
+ .one-step .quiz-check, .one-step .quiz-status { display: none; }
5
+
6
+ .lesson-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; min-height: var(--header-height); padding: 0 max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--rule); background: var(--bg); }
7
+ .leave { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 10px; color: var(--muted); }
8
+ .leave:hover { color: var(--fg); background: var(--accent-soft); }
9
+ .lesson-name { min-width: 0; }
10
+ .lesson-name p { margin: 0; }
11
+ .lesson-name .eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.02em; color: var(--muted); }
12
+ .lesson-name .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
13
+
14
+ /* Segments: one per step; with JavaScript done ones fill in. The names are for screen readers and no-JS jumps. */
15
+ .segments { display: flex; flex: 1; gap: 6px; max-width: 420px; margin: 0 0 0 auto; padding: 0; list-style: none; }
16
+ .segments li { flex: 1; margin: 0; }
17
+ .segments a { display: block; height: 8px; border-radius: 4px; background: var(--rule); overflow: hidden; color: transparent; font-size: 0; }
18
+ .segments li.done a { background: var(--accent); }
19
+ .segments li.current a { background: linear-gradient(90deg, var(--accent) 50%, var(--rule) 50%); }
20
+ .segments a:focus-visible { outline-offset: 4px; }
21
+
22
+ .lesson { max-width: 1200px; margin: 0 auto; padding: 28px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px)); }
23
+ .one-step .lesson { padding-bottom: calc(var(--bar-height) + 32px); }
24
+ .lesson .step { scroll-margin-top: calc(var(--header-height) + 16px); }
25
+ /* The one-step view hides the others: hidden wins over any display a step gets (grid when split). */
26
+ .lesson .step[hidden] { display: none !important; }
27
+ .lesson .step h2 { margin-top: 24px; }
28
+ /* Headings take focus when a step opens (for screen readers). After a click the ring would only mark the title;
29
+ keyboard users keep it, so they can see where focus went. */
30
+ .lesson .step h2:focus:not(:focus-visible) { outline: none; }
31
+ /* A step's title needs no permalink: the header's segments link to each step. */
32
+ .lesson .step .header-anchor { display: none; }
33
+ .result { padding: 16px; border: 1px solid var(--rule); border-radius: 12px; background: var(--surface); }
34
+
35
+ /* Wide screens: what the step says on the left, its code and results on the right (the bar island groups them into
36
+ .step-text and .step-side; without JavaScript a step is one column). */
37
+ @media (min-width: 1024px) {
38
+ .lesson .step.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 40px; align-items: start; }
39
+ .step-side { position: sticky; top: calc(var(--header-height) + 16px); padding-top: 24px; }
40
+ }
41
+
42
+ @media (prefers-reduced-motion: no-preference) {
43
+ .one-step .step:not([hidden]) { animation: step-in 0.2s ease-out; }
44
+ @keyframes step-in { from { opacity: 0; transform: translateY(6px); } }
45
+ }
46
+
47
+ /* The action bar: fixed to the bottom; its status turns green (.ok) or red (.bad) after a check. */
48
+ .lesson-bar { position: fixed; inset: auto 0 0 0; z-index: 10; border-top: 1px solid var(--rule); background: var(--bg); box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.06); }
49
+ .lesson-bar[hidden] { display: none; }
50
+ .lesson-actions { display: flex; align-items: center; gap: 16px; max-width: 1200px; min-height: var(--bar-height); margin: 0 auto; padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
51
+ .lesson-actions button { min-height: 48px; padding: 0 22px; border-radius: 12px; font: inherit; font-weight: 700; cursor: pointer; }
52
+ .lesson-actions .back { border: 1px solid var(--rule); background: var(--bg); color: var(--fg); }
53
+ .lesson-actions .back:disabled { opacity: 0.45; cursor: default; }
54
+ .lesson-actions .primary { border: 0; background: var(--accent); color: var(--bg); }
55
+ .feedback { flex: 1; min-width: 0; }
56
+ .feedback p { margin: 0; }
57
+ .feedback-title { font-weight: 650; }
58
+ .feedback-text { font-size: 14px; color: var(--muted); }
59
+ .lesson-bar.ok { background: var(--ok-soft); border-top-color: var(--ok); }
60
+ .lesson-bar.ok .feedback-title { color: var(--ok); }
61
+ .lesson-bar.ok .primary { background: var(--ok); color: var(--bg); }
62
+ .lesson-bar.bad { background: var(--bad-soft); border-top-color: var(--bad); }
63
+ .lesson-bar.bad .feedback-title { color: var(--bad); }
64
+ .lesson-bar.bad .primary { background: var(--bad); color: var(--bg); }
65
+
66
+ @media (max-width: 699px) {
67
+ .lesson-header { gap: 10px; }
68
+ .segments { position: absolute; inset: auto 16px 0 16px; max-width: none; transform: translateY(50%); }
69
+ .lesson-actions { gap: 10px; }
70
+ .lesson-actions button { padding: 0 16px; }
71
+ .feedback-title { font-size: 14px; }
72
+ }
@@ -0,0 +1,43 @@
1
+ {{--
2
+ A lesson: a focused header (leave, "Lesson n of N", one segment per step, a slot for XP), the lesson, and a fixed
3
+ action bar. Steps are the page's <section class="step"> (Markdown frontmatter `steps: true`), named by its h2
4
+ headings. Without JavaScript the lesson is a plain page and the bar stays hidden; with it, one step shows at a time.
5
+ Lessons are the items of the config section the page is in, in sidebar order.
6
+ Slots: header-end (XP, …).
7
+ --}}
8
+ @import lessonBar from './lesson-bar.tscl'
9
+ @import learnStatus from './learn-status.tscl'
10
+ @import pageHead from './page-head.tscl'
11
+ @import type { ThemeConfig, Heading } from './nav.ts'
12
+ @import { lessonOf, lessonsOf } from './nav.ts'
13
+ @import './theme.css'
14
+ @import './lesson.css'
15
+ @input config: ThemeConfig
16
+ @input title: string
17
+ @input description: string = ''
18
+ @input path: string = '/'
19
+ @input headings: Heading[] = []
20
+
21
+ <html lang="en">
22
+ <head><pageHead [config]="config" [title]="title" [description]="description" [url]="path" /></head>
23
+ <body class="lesson-page">
24
+ <a class="skip-link" href="#content">Skip to content</a>
25
+ <header class="lesson-header">
26
+ <a class="leave" [href]="lessonOf(config, path).leave" aria-label="Leave the lesson">
27
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"></path></svg>
28
+ </a>
29
+ <div class="lesson-name">
30
+ @if (lessonOf(config, path).total) {<p class="eyebrow">{{ lessonOf(config, path).label }}</p>}
31
+ <p class="name">{{ title }}</p>
32
+ </div>
33
+ {{-- Links to each step: jumps without JavaScript, the progress bar with it. --}}
34
+ <ol class="segments" aria-label="Steps">
35
+ @for (h of headings.filter((h) => h.level === 2); track h.id) {<li><a [href]="'#' + h.id">{{ h.text }}</a></li>}
36
+ </ol>
37
+ @if (config.learn) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
38
+ <slot name="header-end"></slot>
39
+ </header>
40
+ <main class="lesson" id="content" tabindex="-1"><slot /></main>
41
+ <div class="lesson-bar" role="region" aria-label="Lesson actions" hidden><lessonBar [lesson]="path" [prev]="lessonOf(config, path).prev" [next]="lessonOf(config, path).next" [leave]="lessonOf(config, path).leave" /></div>
42
+ </body>
43
+ </html>