@clarusjs/theme-docs 0.2.0 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clarusjs/theme-docs",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
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.11.0"
19
+ "clarusjs": "^0.13.0"
20
20
  },
21
21
  "engines": {
22
22
  "node": "^22.12.0 || ^24.0.0 || >=26.0.0"
@@ -38,15 +38,18 @@
38
38
  "url": "https://github.com/forinda/clarusjs/issues"
39
39
  },
40
40
  "devDependencies": {
41
+ "@tailwindcss/cli": "4.3.5",
41
42
  "@types/node": "^26.6.6",
42
- "clarusjs": "^0.11.0",
43
+ "clarusjs": "^0.13.0",
44
+ "tailwindcss": "4.3.5",
43
45
  "typescript": "^7.0.2",
44
- "vitest": "^5.1.1",
45
- "vite": "^8.3.8"
46
+ "vite": "^8.3.8",
47
+ "vitest": "^5.1.1"
46
48
  },
47
49
  "scripts": {
48
50
  "types": "node scripts/types.mjs",
49
51
  "test": "vitest run",
50
- "typecheck": "pnpm types && tsc --noEmit"
52
+ "typecheck": "pnpm types && tsc --noEmit",
53
+ "css": "node scripts/classes.js && tailwindcss -i src/styles/theme.css -o src/theme.css"
51
54
  }
52
55
  }
package/src/layout.tscl CHANGED
@@ -4,13 +4,14 @@
4
4
  1024px the sidebar is always there, from 1280px "On this page" is a column. Everything site-specific comes from config.
5
5
  Slots: sidebar-top, sidebar-bottom, content-top, content-bottom, footer.
6
6
  --}}
7
- @import themeToggle from './theme-toggle.tscl'
8
- @import pageTransitions from './view-transitions.tscl'
9
- @import siteSearch from './search.tscl'
10
7
  @import pageHead from './page-head.tscl'
11
- @import learnStatus from './learn-status.tscl'
8
+ @import siteHeader from './parts/header.tscl'
9
+ @import docsSidebar from './parts/sidebar.tscl'
10
+ @import contents from './parts/contents.tscl'
11
+ @import pageFooter from './parts/page-footer.tscl'
12
+ @import siteFooter from './parts/footer.tscl'
12
13
  @import type { ThemeConfig, Heading } from './nav.ts'
13
- @import { sectionKey, groupsOf, crumb, pager, editHref, updatedOf, lessonsOf } from './nav.ts'
14
+ @import { sectionKey, crumb } from './nav.ts'
14
15
  @import './theme.css'
15
16
  @input config: ThemeConfig
16
17
  @input title: string
@@ -32,140 +33,29 @@
32
33
  <body>
33
34
  {{-- First in the tab order: keyboard and screen reader users jump past the header and page list. --}}
34
35
  <a class="skip-link" href="#content">Skip to content</a>
35
- <header class="site-header">
36
- @if (!app && sectionKey(config.sections, path)) {
37
- <button type="button" class="menu-button" popovertarget="sidebar" aria-label="Open menu">
38
- <svg
39
- width="22"
40
- height="22"
41
- viewBox="0 0 24 24"
42
- fill="none"
43
- stroke="currentColor"
44
- stroke-width="2.2"
45
- stroke-linecap="round"
46
- aria-hidden="true"
47
- >
48
- <path d="M4 7h16M4 12h16M4 17h16"></path>
49
- </svg>
50
- </button>
51
- }
52
- <a class="brand" href="/"
53
- >@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
54
- >
55
- <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>
56
- <div class="header-end">
57
- {{-- On Learn pages: the XP chip, and the sidebar's lessons marked done, current or locked. --}}
58
- @if (config.learn && sectionKey(config.sections, path) === config.learn.section) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
59
- {{-- Kept across fragment navigations, like the theme toggle: its shortcut listener is added once. --}}
60
- @if (config.search) {<span class="persist" data-cl-persist="search"><siteSearch /></span>}
61
- @if ((config.social ?? []).length) {
62
- <span class="social">
63
- @for (link of config.social ?? []; track link.href) {
64
- <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>
65
- }
66
- </span>
67
- {{-- When the header runs out of room, the social links fold into this menu (native popover). --}}
68
- <button type="button" class="more-button" popovertarget="more" aria-label="More links">
69
- <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
70
- <circle cx="5" cy="12" r="2"></circle>
71
- <circle cx="12" cy="12" r="2"></circle>
72
- <circle cx="19" cy="12" r="2"></circle>
73
- </svg>
74
- </button>
75
- <div id="more" class="more" popover>@for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
76
- }
77
- {{-- Kept across fragment navigations: the same element, with its state. --}}
78
- <span class="persist" data-cl-persist="theme"><themeToggle /></span>
79
- @if (config.viewTransitions) {<span class="persist" data-cl-persist="view-transitions"><pageTransitions /></span>}
80
- </div>
81
- </header>
36
+ <siteHeader [config]="config" [path]="path" [app]="app" />
82
37
  @if (app) {
83
38
  <main class="content app" id="content" tabindex="-1"><slot /></main>
84
39
  } @else if (sectionKey(config.sections, path)) {
85
40
  <div class="docs">
86
41
  {{-- A drawer below 1024px (popover: Escape and a click outside close it), always visible from 1024px. --}}
87
- <nav id="sidebar" class="sidebar" aria-label="Pages" popover>
88
- <div class="sidebar-head">
89
- <span>{{ config.brand.text }}{{ config.brand.accent ?? '' }}</span>
90
- <button type="button" popovertarget="sidebar" popovertargetaction="hide" aria-label="Close the menu">
91
- <svg
92
- width="20"
93
- height="20"
94
- viewBox="0 0 24 24"
95
- fill="none"
96
- stroke="currentColor"
97
- stroke-width="2.2"
98
- stroke-linecap="round"
99
- aria-hidden="true"
100
- >
101
- <path d="M6 6l12 12M18 6L6 18"></path>
102
- </svg>
103
- </button>
104
- </div>
105
- <slot name="sidebar-top"></slot>
106
- @for (group of groupsOf(config.sections, path); track group.title) {
107
- <p class="group">{{ group.title }}</p>
108
- <ul>
109
- @for (item of group.items; track item.href) {
110
- <li>
111
- <a [href]="item.href" [aria-current]="item.href === path ? 'page' : false">{{ item.title }}</a>
112
- </li>
113
- }
114
- </ul>
115
- }
116
- <slot name="sidebar-bottom"></slot>
117
- {{-- On phones, the header's links live here. --}}
118
- <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>
119
- </nav>
42
+ <docsSidebar [config]="config" [path]="path">@slot('top') {<slot name="sidebar-top"></slot>}@slot('bottom') {<slot name="sidebar-bottom"></slot>}</docsSidebar>
120
43
  {{-- tabindex -1: the skip link (and navigation) can move focus here. --}}
121
44
  <main class="content" id="content" tabindex="-1">
122
45
  <p class="crumb">{{ crumb(config.sections, path) }}</p>
123
- @if (headings.length) {
124
- <details class="toc-inline">
125
- <summary>On this page</summary>
126
- <ul>
127
- @for (h of headings; track h.id) {
128
- <li [class]="h.level === 3 ? 'sub' : false">
129
- <a [href]="'#' + h.id">{{ h.text }}</a>
130
- </li>
131
- }
132
- </ul>
133
- </details>
134
- }
46
+ <contents [headings]="headings" [inline]="true" />
135
47
  <slot name="content-top"></slot>
136
48
  <slot />
137
49
  <slot name="content-bottom"></slot>
138
- <footer class="page-footer">
139
- @if (editHref(config, source || path)) {<a class="edit" [href]="editHref(config, source || path)">Edit this page on GitHub</a>}
140
- @if (updatedOf(config, source || path)) {
141
- <p class="updated">
142
- Last updated
143
- <time [datetime]="updatedOf(config, source || path)?.iso">{{
144
- updatedOf(config, source || path)?.text
145
- }}</time>
146
- </p>
147
- }
148
- <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>
149
- </footer>
50
+ <pageFooter [config]="config" [path]="path" [source]="source" />
150
51
  </main>
151
- @if (headings.length) {
152
- <aside class="toc" aria-label="On this page">
153
- <p>On this page</p>
154
- <ul>
155
- @for (h of headings; track h.id) {
156
- <li [class]="h.level === 3 ? 'sub' : false">
157
- <a [href]="'#' + h.id">{{ h.text }}</a>
158
- </li>
159
- }
160
- </ul>
161
- </aside>
162
- }
52
+ <contents [headings]="headings" />
163
53
  </div>
164
54
  } @else {
165
55
  <main class="content home" id="content" tabindex="-1"><slot /></main>
166
56
  }
167
57
  @if (!app) {
168
- <footer class="site-footer"><slot name="footer">@if (config.footer) {<p>{{ config.footer }}</p>}</slot></footer>
58
+ <siteFooter [config]="config"><slot name="footer">@if (config.footer) {<p>{{ config.footer }}</p>}</slot></siteFooter>
169
59
  }
170
60
  </body>
171
61
  </html>
@@ -0,0 +1,134 @@
1
+ {{--
2
+ The Learn path (#371), beside a lesson from 1024px: the course and how far you are, each lesson with the XP it can
3
+ earn (done, the one you're on, the next, then locked: a hint, every lesson stays open), this lesson's steps, and your
4
+ XP and badges. Progress is read from this browser, so without JavaScript only the lessons and steps show.
5
+ The steps follow the lesson bar (learn:step); everything else follows saved progress (learn:progress).
6
+ --}}
7
+ @import type { Heading } from './nav.ts'
8
+ @interface Lesson { title: string; href: string; xp?: number; minutes?: number }
9
+ @input lessons: Lesson[]
10
+ @input path: string
11
+ @input eyebrow: string = 'Learn'
12
+ @input course: string = ''
13
+ @input steps: Heading[] = []
14
+ @input progress: string = ''
15
+
16
+ <script>
17
+ import { load, stats } from './progress.ts'
18
+ let ready = state(false)
19
+ let statuses = state(Object.create(null)) // lesson href → done, current, next or locked
20
+ let done = state(0)
21
+ let xp = state(0)
22
+ let earned = state(0)
23
+ let step = state(0)
24
+ function refresh() {
25
+ const s = stats(
26
+ load(),
27
+ lessons.map((l) => l.href),
28
+ )
29
+ const current = lessons.findIndex((l) => s.status(l.href) === 'current')
30
+ statuses = Object.fromEntries(
31
+ lessons.map((l, i) => [l.href, s.status(l.href) === 'locked' && i === current + 1 ? 'next' : s.status(l.href)]),
32
+ )
33
+ done = s.done
34
+ xp = s.xp
35
+ earned = s.badges.filter((b) => b.earned).length
36
+ ready = true
37
+ }
38
+ const note = (lesson, i) =>
39
+ ready && statuses[lesson.href] === 'done'
40
+ ? 'Done'
41
+ : ready && statuses[lesson.href] === 'locked'
42
+ ? 'Finish lesson ' + i + ' first'
43
+ : lesson.minutes
44
+ ? lesson.minutes + ' min'
45
+ : ''
46
+ if (typeof document !== 'undefined') {
47
+ refresh()
48
+ window.addEventListener('learn:progress', refresh)
49
+ window.addEventListener('learn:step', (event) => {
50
+ if (event instanceof CustomEvent) step = event.detail
51
+ })
52
+ }
53
+ </script>
54
+
55
+ <nav class="learn-path flex flex-col" aria-label="Lessons">
56
+ <div class="border-b border-rule px-4 pt-5 pb-4">
57
+ <p class="m-0 text-[11px] font-bold tracking-wider text-accent uppercase">{{ eyebrow }}</p>
58
+ <p class="m-0 mt-0.5 text-[17px] font-bold text-fg">{{ course }}</p>
59
+ <div class="mt-3 flex items-center gap-2.5">
60
+ <progress
61
+ class="path-progress h-1.5 flex-1"
62
+ [value]="done"
63
+ [max]="lessons.length"
64
+ aria-label="Lessons done"
65
+ ></progress>
66
+ <span class="text-[13px] font-semibold text-fg">{{ done }} of {{ lessons.length }}</span>
67
+ </div>
68
+ </div>
69
+ <ol class="m-0 flex-1 list-none overflow-y-auto p-3">
70
+ @for (lesson of lessons; track lesson.href) {
71
+ <li class="m-0 mb-1" [data-status]="ready ? statuses[lesson.href] : false">
72
+ <a
73
+ class="path-lesson flex items-center gap-3 rounded-xl border-2 border-transparent px-2.5 py-2.5 text-fg no-underline aria-[current=page]:border-accent"
74
+ [href]="lesson.href"
75
+ [aria-current]="lesson.href === path ? 'page' : false"
76
+ >
77
+ <span
78
+ class="path-dot grid size-7 flex-none place-items-center rounded-full text-xs font-bold"
79
+ aria-hidden="true"
80
+ >
81
+ @if (ready && statuses[lesson.href] === 'done') {
82
+ <svg
83
+ width="14"
84
+ height="14"
85
+ viewBox="0 0 24 24"
86
+ fill="none"
87
+ stroke="currentColor"
88
+ stroke-width="3"
89
+ stroke-linecap="round"
90
+ stroke-linejoin="round"
91
+ >
92
+ <path d="m5 12 5 5 9-10"></path>
93
+ </svg>
94
+ } @else if (!(ready && statuses[lesson.href] === 'locked')) {
95
+ {{ $index + 1 }}
96
+ }
97
+ </span>
98
+ <span class="min-w-0 flex-1">
99
+ <span class="path-title block text-sm leading-snug font-semibold">{{ lesson.title }}</span>
100
+ <span class="block text-xs text-muted">{{ note(lesson, $index) }}</span>
101
+ </span>
102
+ @if (lesson.xp) {
103
+ <span class="path-xp text-xs font-bold">+{{ lesson.xp }}</span>
104
+ }
105
+ </a>
106
+ @if (lesson.href === path && steps.length) {
107
+ <ol class="path-steps my-1.5 ml-[46px] list-none p-0" aria-label="Steps">
108
+ @for (s of steps; track s.id) {
109
+ <li class="m-0" [data-step]="$index < step ? 'done' : $index === step ? 'current' : 'next'">
110
+ <a
111
+ class="flex items-center gap-2.5 py-1 text-[13px] text-muted no-underline"
112
+ [href]="'#' + s.id"
113
+ [aria-current]="$index === step ? 'step' : false"
114
+ ><span class="step-dot size-2 flex-none rounded-full" aria-hidden="true"></span>{{ s.text }}</a
115
+ >
116
+ </li>
117
+ }
118
+ </ol>
119
+ }
120
+ </li>
121
+ }
122
+ </ol>
123
+ <a
124
+ class="path-footer m-3 mt-0 flex items-center gap-2 rounded-xl px-3.5 py-3 text-sm font-bold no-underline"
125
+ [href]="progress"
126
+ >
127
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
128
+ <path d="M13 2L4 14h7l-1 8 9-12h-7z"></path>
129
+ </svg>
130
+ <span class="flex-1" [hidden]="!ready">{{ xp }} XP · {{ earned }} {{ earned === 1 ? 'badge' : 'badges' }}</span>
131
+ <span class="flex-1" [hidden]="ready">Your progress</span>
132
+ <span aria-hidden="true">→</span>
133
+ </a>
134
+ </nav>
@@ -40,6 +40,8 @@
40
40
  all.forEach((step, j) => {
41
41
  step.hidden = j !== current
42
42
  })
43
+ // The Learn path's steps follow along.
44
+ window.dispatchEvent(new CustomEvent('learn:step', { detail: current }))
43
45
  checking = !!all[current].querySelector('[data-quiz]:not([data-answered])')
44
46
  verdict('', '', '')
45
47
  const id = all[current].getAttribute('aria-labelledby') ?? ''
package/src/lesson.css CHANGED
@@ -14,9 +14,11 @@
14
14
  /* Segments: one per step; with JavaScript done ones fill in. The names are for screen readers and no-JS jumps. */
15
15
  .segments { display: flex; flex: 1; gap: 6px; max-width: 420px; margin: 0 0 0 auto; padding: 0; list-style: none; }
16
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%); }
17
+ /* Each segment is a 24px tap target (WCAG 2.5.8); the bar is drawn 8px high in its middle, as before. */
18
+ .segments a { position: relative; display: block; height: 24px; color: transparent; font-size: 0; }
19
+ .segments a::before { content: ''; position: absolute; inset: 8px 0; border-radius: 4px; background: var(--rule); }
20
+ .segments li.done a::before { background: var(--accent); }
21
+ .segments li.current a::before { background: linear-gradient(90deg, var(--accent) 50%, var(--rule) 50%); }
20
22
  .segments a:focus-visible { outline-offset: 4px; }
21
23
 
22
24
  .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)); }
@@ -70,3 +72,28 @@
70
72
  .lesson-actions button { padding: 0 16px; }
71
73
  .feedback-title { font-size: 14px; }
72
74
  }
75
+
76
+ /* The Learn path (#371): beside the lesson from 1024px, above the action bar. Below that the header's segments do. */
77
+ .lesson-path { display: none; }
78
+ @media (min-width: 1024px) {
79
+ .lesson-body { display: grid; grid-template-columns: 300px minmax(0, 1fr); }
80
+ .lesson-path { display: block; position: sticky; top: var(--header-height); align-self: start; height: calc(100vh - var(--header-height)); border-right: 1px solid var(--rule); }
81
+ .one-step .lesson-path { height: calc(100vh - var(--header-height) - var(--bar-height)); }
82
+ .lesson-path cl-island, .lesson-path .learn-path { height: 100%; }
83
+ .lesson-body .lesson { width: 100%; }
84
+ }
85
+ .path-progress { appearance: none; border: 0; border-radius: 999px; background: var(--rule); overflow: hidden; }
86
+ .path-progress::-webkit-progress-bar { background: var(--rule); }
87
+ .path-progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
88
+ .path-progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
89
+ .path-dot { background: var(--surface); color: var(--muted); border: 2px solid var(--rule); }
90
+ .path-xp { color: var(--xp); }
91
+ .learn-path [data-status='done'] .path-dot { background: var(--accent); border-color: var(--accent); color: var(--bg); }
92
+ .learn-path a[aria-current='page'] .path-dot { background: var(--bg); border-color: var(--accent); color: var(--accent); }
93
+ .learn-path [data-status='locked'] .path-dot { background: var(--surface); border-color: var(--surface); }
94
+ .learn-path [data-status='locked'] .path-title, .learn-path [data-status='locked'] .path-xp { color: var(--muted); }
95
+ .step-dot { background: var(--rule); }
96
+ .path-steps [data-step='done'] .step-dot { background: var(--accent); }
97
+ .path-steps [data-step='current'] .step-dot { background: transparent; box-shadow: inset 0 0 0 2px var(--accent); }
98
+ .path-steps [data-step='current'] a { color: var(--accent); font-weight: 650; }
99
+ .path-footer { background: var(--xp-soft); color: var(--xp); }
package/src/lesson.tscl CHANGED
@@ -7,6 +7,7 @@
7
7
  --}}
8
8
  @import lessonBar from './lesson-bar.tscl'
9
9
  @import learnStatus from './learn-status.tscl'
10
+ @import learnPath from './learn-path.tscl'
10
11
  @import pageHead from './page-head.tscl'
11
12
  @import type { ThemeConfig, Heading } from './nav.ts'
12
13
  @import { lessonOf, lessonsOf } from './nav.ts'
@@ -56,7 +57,26 @@
56
57
  @if (config.learn) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
57
58
  <slot name="header-end"></slot>
58
59
  </header>
59
- <main class="lesson" id="content" tabindex="-1"><slot /></main>
60
+ <div class="lesson-body">
61
+ {{-- The path (#371): a lesson of config.learn's section, from 1024px. --}}
62
+ @if (config.learn && lessonsOf(config).some((l) => l.href === path)) {
63
+ <aside class="lesson-path">
64
+ <learnPath
65
+ [lessons]="lessonsOf(config)"
66
+ [path]="path"
67
+ [eyebrow]="config.sections.find((s) => s.key === config.learn?.section)?.title ?? 'Learn'"
68
+ [course]="
69
+ config.sections
70
+ .find((s) => s.key === config.learn?.section)
71
+ ?.groups.find((g) => g.items.some((i) => i.href === path))?.title ?? ''
72
+ "
73
+ [steps]="headings.filter((h) => h.level === 2)"
74
+ [progress]="config.learn.progress"
75
+ />
76
+ </aside>
77
+ }
78
+ <main class="lesson" id="content" tabindex="-1"><slot /></main>
79
+ </div>
60
80
  <div class="lesson-bar" role="region" aria-label="Lesson actions" hidden>
61
81
  <lessonBar
62
82
  [lesson]="path"
package/src/nav.ts CHANGED
@@ -2,14 +2,47 @@
2
2
  // readonly, as a template's inputs are: the layout passes its config to these helpers as it gets it.
3
3
 
4
4
  /** A sidebar entry; `order` sorts it within its group (lowest first, then by title). */
5
- export type Item = { title: string; href: string; order?: number }
6
- export type Group = { title: string; items: readonly Item[] }
5
+ /**
6
+ * A sidebar entry. `badge`: a short label beside it ("New"), also from a page's frontmatter. For a lesson (#371): `xp`,
7
+ * what it can earn (from its steps and quizzes), and `minutes` (frontmatter), shown in the Learn path.
8
+ */
9
+ export type Item = { title: string; href: string; order?: number; badge?: string; xp?: number; minutes?: number }
10
+ /** The icons a sidebar group can show (#369). */
11
+ export type GroupIcon = 'info' | 'code' | 'box' | 'shield' | 'download' | 'book' | 'terminal' | 'sparkles' | 'layers' | 'wrench' | 'rocket' | 'file'
12
+ /**
13
+ * A sidebar group. `icon`: shown beside its title. `collapsed`: closed until opened (the group of the current page is
14
+ * always open).
15
+ */
16
+ export type Group = { title: string; icon?: GroupIcon; collapsed?: boolean; items: readonly Item[] }
7
17
  /** A top-level part of the docs (Guide, Reference): its own sidebar groups. */
8
- export type Section = { key: string; title: string; href: string; groups: readonly Group[] }
18
+ /** A top-level section. `switch: false` leaves it out of the phone drawer's switch (#370; link it with `menuLinks`). */
19
+ export type Section = { key: string; title: string; href: string; switch?: boolean; groups: readonly Group[] }
9
20
  export type Social = { label: string; href: string; icon: 'github' | 'npm' | 'link' }
10
21
  /** A heading on the page, for "On this page". */
11
22
  export type Heading = { id: string; text: string; level: number }
12
23
 
24
+ /**
25
+ * What a site's layout passes to a theme's `layout.tscl`: the contract a theme implements (#362). `config` and
26
+ * `title` always; the rest optional, with the defaults the docs theme uses. A theme's layout also has the slots
27
+ * `sidebar-top`, `sidebar-bottom`, `content-top`, `content-bottom` and `footer`, beside its default one.
28
+ * @see https://clarusjs.com/guide/writing-a-theme
29
+ */
30
+ export type LayoutInputs = {
31
+ config: ThemeConfig
32
+ title: string
33
+ description?: string
34
+ /** The page's sidebar entry (default '/'). */
35
+ path?: string
36
+ /** The page's own route, when it differs from its sidebar entry. */
37
+ source?: string
38
+ /** The page's own address, when path names its sidebar entry instead. */
39
+ url?: string
40
+ /** The page's h2 and h3, for "On this page". */
41
+ headings?: Heading[]
42
+ /** A tool rather than a page: no sidebar, crumb or footers. */
43
+ app?: boolean
44
+ }
45
+
13
46
  export type ThemeConfig = {
14
47
  /** The site's name in the header: `{ text: 'clarus', accent: '.js' }` shows the accent in the brand colour. */
15
48
  brand: { text: string; accent?: string; logo?: string }
@@ -18,6 +51,8 @@ export type ThemeConfig = {
18
51
  sections: readonly Section[]
19
52
  /** Icon links at the right of the header (GitHub, npm…). */
20
53
  social?: readonly Social[]
54
+ /** Text links at the bottom of the phone drawer, before the social links (Reference, Releases…) (#370). */
55
+ menuLinks?: readonly { label: string; href: string }[]
21
56
  /**
22
57
  * "Edit this page": a pattern where `:file` is the page's source file under src/pages (`guide/start.md`, found in
23
58
  * `pages`), or a function of the route (the page's source route, for dynamic pages). None without it.
@@ -73,7 +108,7 @@ export function pager(sections: readonly Section[], path: string): { prev: Item;
73
108
  * A page as `themeDocs()` reads it (`import pages from 'virtual:theme-docs/pages'`): its route, source file under
74
109
  * src/pages, last commit time (unix seconds), sidebar entry, and `hidden` when it isn't in the sidebar.
75
110
  */
76
- export type PageInfo = { href: string; title: string; file: string; group?: string; order?: number; updated?: number; hidden?: boolean }
111
+ export type PageInfo = { href: string; title: string; file: string; group?: string; order?: number; badge?: string; xp?: number; minutes?: number; updated?: number; hidden?: boolean }
77
112
 
78
113
  /**
79
114
  * The sections with their sidebar filled from the pages under `/<section key>/`: a page sits in its `group` (else the
@@ -82,7 +117,7 @@ export type PageInfo = { href: string; title: string; file: string; group?: stri
82
117
  */
83
118
  export function pagesNav(sections: readonly Section[], pages: readonly PageInfo[]): Section[] {
84
119
  return sections.map((section) => {
85
- const groups = section.groups.map((g) => ({ title: g.title, items: [...g.items] }))
120
+ const groups: { title: string; icon?: GroupIcon; collapsed?: boolean; items: Item[] }[] = section.groups.map((g) => ({ ...g, items: [...g.items] }))
86
121
  const listed = new Set(groups.flatMap((g) => g.items.map((i) => i.href)))
87
122
  for (const page of pages) {
88
123
  const inSection = page.href === `/${section.key}` || page.href.startsWith(`/${section.key}/`)
@@ -90,7 +125,12 @@ export function pagesNav(sections: readonly Section[], pages: readonly PageInfo[
90
125
  const title = page.group ?? section.title
91
126
  let group = groups.find((g) => g.title === title)
92
127
  if (!group) groups.push(group = { title, items: [] })
93
- group.items.push(page.order === undefined ? { title: page.title, href: page.href } : { title: page.title, href: page.href, order: page.order })
128
+ const item: Item = { title: page.title, href: page.href }
129
+ if (page.order !== undefined) item.order = page.order
130
+ if (page.badge) item.badge = page.badge
131
+ if (page.xp) item.xp = page.xp
132
+ if (page.minutes) item.minutes = page.minutes
133
+ group.items.push(item)
94
134
  }
95
135
  const rank = (i: Item) => i.order ?? Infinity
96
136
  for (const g of groups) g.items.sort((a, b) => rank(a) - rank(b) || a.title.localeCompare(b.title))
@@ -0,0 +1,32 @@
1
+ {{--
2
+ "On this page" (a public part, #360): the page's h2/h3 as a column (an aside, shown from 1280px) or, with inline, a
3
+ collapsible box above the content (below 1280px). Nothing without headings. Replace it with
4
+ themeDocs({ components: { contents } }) (#361).
5
+ --}}
6
+ @import type { Heading } from '../nav.ts'
7
+ @input headings: Heading[] = []
8
+ @input inline: boolean = false
9
+
10
+ @if (headings.length && inline) {
11
+ <details class="toc-inline">
12
+ <summary>On this page</summary>
13
+ <ul>
14
+ @for (h of headings; track h.id) {
15
+ <li [class]="h.level === 3 ? 'sub' : false">
16
+ <a [href]="'#' + h.id">{{ h.text }}</a>
17
+ </li>
18
+ }
19
+ </ul>
20
+ </details>
21
+ } @else if (headings.length) {
22
+ <aside class="toc" aria-label="On this page">
23
+ <p>On this page</p>
24
+ <ul>
25
+ @for (h of headings; track h.id) {
26
+ <li [class]="h.level === 3 ? 'sub' : false">
27
+ <a [href]="'#' + h.id">{{ h.text }}</a>
28
+ </li>
29
+ }
30
+ </ul>
31
+ </aside>
32
+ }
@@ -0,0 +1,8 @@
1
+ {{--
2
+ The site footer (a public part, #360): its default content is config.footer. Replace it with
3
+ themeDocs({ components: { footer } }) (#361).
4
+ --}}
5
+ @import type { ThemeConfig } from '../nav.ts'
6
+ @input config: ThemeConfig
7
+
8
+ <footer class="site-footer"><slot>@if (config.footer) {<p>{{ config.footer }}</p>}</slot></footer>
@@ -0,0 +1,62 @@
1
+ {{--
2
+ The site header (a public part, #360): the menu button, brand, section links, Learn status, search, social links and
3
+ the theme toggle. Replace it with themeDocs({ components: { header } }) (#361).
4
+ --}}
5
+ @import themeToggle from '../theme-toggle.tscl'
6
+ @import pageTransitions from '../view-transitions.tscl'
7
+ @import siteSearch from '../search.tscl'
8
+ @import learnStatus from '../learn-status.tscl'
9
+ @import type { ThemeConfig } from '../nav.ts'
10
+ @import { sectionKey, lessonsOf } from '../nav.ts'
11
+ @input config: ThemeConfig
12
+ @input path: string = '/'
13
+ {{-- An app page (a tool) has no sidebar, so no menu button. --}}
14
+ @input app: boolean = false
15
+
16
+ <header class="site-header">
17
+ @if (!app && sectionKey(config.sections, path)) {
18
+ <button type="button" class="menu-button" popovertarget="sidebar" aria-label="Open menu">
19
+ <svg
20
+ width="22"
21
+ height="22"
22
+ viewBox="0 0 24 24"
23
+ fill="none"
24
+ stroke="currentColor"
25
+ stroke-width="2.2"
26
+ stroke-linecap="round"
27
+ aria-hidden="true"
28
+ >
29
+ <path d="M4 7h16M4 12h16M4 17h16"></path>
30
+ </svg>
31
+ </button>
32
+ }
33
+ <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
35
+ >
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>
37
+ <div class="header-end">
38
+ {{-- 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" />}
40
+ {{-- 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) {
43
+ <span class="social">
44
+ @for (link of config.social ?? []; track link.href) {
45
+ <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
+ }
47
+ </span>
48
+ {{-- When the header runs out of room, the social links fold into this menu (native popover). --}}
49
+ <button type="button" class="more-button" popovertarget="more" aria-label="More links">
50
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
51
+ <circle cx="5" cy="12" r="2"></circle>
52
+ <circle cx="12" cy="12" r="2"></circle>
53
+ <circle cx="19" cy="12" r="2"></circle>
54
+ </svg>
55
+ </button>
56
+ <div id="more" class="more" popover>@for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
57
+ }
58
+ {{-- Kept across fragment navigations: the same element, with its state. --}}
59
+ <span class="persist" data-cl-persist="theme"><themeToggle /></span>
60
+ @if (config.viewTransitions) {<span class="persist" data-cl-persist="view-transitions"><pageTransitions /></span>}
61
+ </div>
62
+ </header>